babylon.gui.js 207 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686
  1. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
  2. var babylonDependency = (globalObject && globalObject.BABYLON) || BABYLON || (typeof require !== 'undefined' && require("babylonjs"));
  3. var BABYLON = babylonDependency;
  4. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  5. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  6. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  7. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  8. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9. };
  10. var __extends = (this && this.__extends) || (function () {
  11. var extendStatics = Object.setPrototypeOf ||
  12. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  13. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  14. return function (d, b) {
  15. extendStatics(d, b);
  16. function __() { this.constructor = d; }
  17. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  18. };
  19. })();
  20. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  21. var BABYLON;
  22. (function (BABYLON) {
  23. var GUI;
  24. (function (GUI) {
  25. var AdvancedDynamicTexture = /** @class */ (function (_super) {
  26. __extends(AdvancedDynamicTexture, _super);
  27. function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode) {
  28. if (width === void 0) { width = 0; }
  29. if (height === void 0) { height = 0; }
  30. if (generateMipMaps === void 0) { generateMipMaps = false; }
  31. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE; }
  32. var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, BABYLON.Engine.TEXTUREFORMAT_RGBA) || this;
  33. _this._isDirty = false;
  34. _this._rootContainer = new GUI.Container("root");
  35. _this._linkedControls = new Array();
  36. _this._isFullscreen = false;
  37. _this._fullscreenViewport = new BABYLON.Viewport(0, 0, 1, 1);
  38. _this._idealWidth = 0;
  39. _this._idealHeight = 0;
  40. _this._renderAtIdealSize = false;
  41. _this._blockNextFocusCheck = false;
  42. scene = _this.getScene();
  43. if (!scene || !_this._texture) {
  44. return _this;
  45. }
  46. _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
  47. _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
  48. if (!_this._focusedControl) {
  49. return;
  50. }
  51. if (info.type === BABYLON.KeyboardEventTypes.KEYDOWN) {
  52. _this._focusedControl.processKeyboard(info.event);
  53. }
  54. info.skipOnPointerObservable = true;
  55. });
  56. _this._rootContainer._link(null, _this);
  57. _this.hasAlpha = true;
  58. if (!width || !height) {
  59. _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
  60. _this._onResize();
  61. }
  62. _this._texture.isReady = true;
  63. return _this;
  64. }
  65. Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
  66. get: function () {
  67. return this._background;
  68. },
  69. set: function (value) {
  70. if (this._background === value) {
  71. return;
  72. }
  73. this._background = value;
  74. this.markAsDirty();
  75. },
  76. enumerable: true,
  77. configurable: true
  78. });
  79. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
  80. get: function () {
  81. return this._idealWidth;
  82. },
  83. set: function (value) {
  84. if (this._idealWidth === value) {
  85. return;
  86. }
  87. this._idealWidth = value;
  88. this.markAsDirty();
  89. this._rootContainer._markAllAsDirty();
  90. },
  91. enumerable: true,
  92. configurable: true
  93. });
  94. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
  95. get: function () {
  96. return this._idealHeight;
  97. },
  98. set: function (value) {
  99. if (this._idealHeight === value) {
  100. return;
  101. }
  102. this._idealHeight = value;
  103. this.markAsDirty();
  104. this._rootContainer._markAllAsDirty();
  105. },
  106. enumerable: true,
  107. configurable: true
  108. });
  109. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
  110. get: function () {
  111. return this._renderAtIdealSize;
  112. },
  113. set: function (value) {
  114. if (this._renderAtIdealSize === value) {
  115. return;
  116. }
  117. this._renderAtIdealSize = value;
  118. this._onResize();
  119. },
  120. enumerable: true,
  121. configurable: true
  122. });
  123. Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
  124. get: function () {
  125. return this._layerToDispose;
  126. },
  127. enumerable: true,
  128. configurable: true
  129. });
  130. Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
  131. get: function () {
  132. return this._rootContainer;
  133. },
  134. enumerable: true,
  135. configurable: true
  136. });
  137. Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
  138. get: function () {
  139. return this._focusedControl;
  140. },
  141. set: function (control) {
  142. if (this._focusedControl == control) {
  143. return;
  144. }
  145. if (this._focusedControl) {
  146. this._focusedControl.onBlur();
  147. }
  148. if (control) {
  149. control.onFocus();
  150. }
  151. this._focusedControl = control;
  152. },
  153. enumerable: true,
  154. configurable: true
  155. });
  156. Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
  157. get: function () {
  158. if (!this.layer) {
  159. return true;
  160. }
  161. return (!this.layer.isBackground);
  162. },
  163. set: function (value) {
  164. if (!this.layer) {
  165. return;
  166. }
  167. if (this.layer.isBackground === !value) {
  168. return;
  169. }
  170. this.layer.isBackground = !value;
  171. },
  172. enumerable: true,
  173. configurable: true
  174. });
  175. AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
  176. if (!container) {
  177. container = this._rootContainer;
  178. }
  179. for (var _i = 0, _a = container.children; _i < _a.length; _i++) {
  180. var child = _a[_i];
  181. if (child.children) {
  182. this.executeOnAllControls(func, child);
  183. continue;
  184. }
  185. func(child);
  186. }
  187. };
  188. AdvancedDynamicTexture.prototype.markAsDirty = function () {
  189. this._isDirty = true;
  190. };
  191. AdvancedDynamicTexture.prototype.addControl = function (control) {
  192. this._rootContainer.addControl(control);
  193. return this;
  194. };
  195. AdvancedDynamicTexture.prototype.removeControl = function (control) {
  196. this._rootContainer.removeControl(control);
  197. return this;
  198. };
  199. AdvancedDynamicTexture.prototype.dispose = function () {
  200. var scene = this.getScene();
  201. if (!scene) {
  202. return;
  203. }
  204. scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
  205. if (this._resizeObserver) {
  206. scene.getEngine().onResizeObservable.remove(this._resizeObserver);
  207. }
  208. if (this._pointerMoveObserver) {
  209. scene.onPrePointerObservable.remove(this._pointerMoveObserver);
  210. }
  211. if (this._pointerObserver) {
  212. scene.onPointerObservable.remove(this._pointerObserver);
  213. }
  214. if (this._preKeyboardObserver) {
  215. scene.onPreKeyboardObservable.remove(this._preKeyboardObserver);
  216. }
  217. if (this._canvasPointerOutObserver) {
  218. scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
  219. }
  220. if (this._layerToDispose) {
  221. this._layerToDispose.texture = null;
  222. this._layerToDispose.dispose();
  223. this._layerToDispose = null;
  224. }
  225. this._rootContainer.dispose();
  226. _super.prototype.dispose.call(this);
  227. };
  228. AdvancedDynamicTexture.prototype._onResize = function () {
  229. var scene = this.getScene();
  230. if (!scene) {
  231. return;
  232. }
  233. // Check size
  234. var engine = scene.getEngine();
  235. var textureSize = this.getSize();
  236. var renderWidth = engine.getRenderWidth();
  237. var renderHeight = engine.getRenderHeight();
  238. if (this._renderAtIdealSize) {
  239. if (this._idealWidth) {
  240. renderHeight = (renderHeight * this._idealWidth) / renderWidth;
  241. renderWidth = this._idealWidth;
  242. }
  243. else if (this._idealHeight) {
  244. renderWidth = (renderWidth * this._idealHeight) / renderHeight;
  245. renderHeight = this._idealHeight;
  246. }
  247. }
  248. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  249. this.scaleTo(renderWidth, renderHeight);
  250. this.markAsDirty();
  251. if (this._idealWidth || this._idealHeight) {
  252. this._rootContainer._markAllAsDirty();
  253. }
  254. }
  255. };
  256. AdvancedDynamicTexture.prototype._getGlobalViewport = function (scene) {
  257. var engine = scene.getEngine();
  258. return this._fullscreenViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  259. };
  260. AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
  261. if (this._layerToDispose) {
  262. if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
  263. return;
  264. }
  265. }
  266. if (this._isFullscreen && this._linkedControls.length) {
  267. var scene = this.getScene();
  268. if (!scene) {
  269. return;
  270. }
  271. var globalViewport = this._getGlobalViewport(scene);
  272. for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
  273. var control = _a[_i];
  274. if (!control.isVisible) {
  275. continue;
  276. }
  277. var mesh = control._linkedMesh;
  278. if (!mesh || mesh.isDisposed()) {
  279. BABYLON.Tools.SetImmediate(function () {
  280. control.linkWithMesh(null);
  281. });
  282. continue;
  283. }
  284. var position = mesh.getBoundingInfo().boundingSphere.center;
  285. var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
  286. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  287. control.notRenderable = true;
  288. continue;
  289. }
  290. control.notRenderable = false;
  291. control._moveToProjectedPosition(projectedPosition);
  292. }
  293. }
  294. if (!this._isDirty && !this._rootContainer.isDirty) {
  295. return;
  296. }
  297. this._isDirty = false;
  298. this._render();
  299. this.update();
  300. };
  301. AdvancedDynamicTexture.prototype._render = function () {
  302. var textureSize = this.getSize();
  303. var renderWidth = textureSize.width;
  304. var renderHeight = textureSize.height;
  305. // Clear
  306. var context = this.getContext();
  307. context.clearRect(0, 0, renderWidth, renderHeight);
  308. if (this._background) {
  309. context.save();
  310. context.fillStyle = this._background;
  311. context.fillRect(0, 0, renderWidth, renderHeight);
  312. context.restore();
  313. }
  314. // Render
  315. context.font = "18px Arial";
  316. context.strokeStyle = "white";
  317. var measure = new GUI.Measure(0, 0, renderWidth, renderHeight);
  318. this._rootContainer._draw(measure, context);
  319. };
  320. AdvancedDynamicTexture.prototype._doPicking = function (x, y, type, buttonIndex) {
  321. var scene = this.getScene();
  322. if (!scene) {
  323. return;
  324. }
  325. var engine = scene.getEngine();
  326. var textureSize = this.getSize();
  327. if (this._isFullscreen) {
  328. x = x * (textureSize.width / engine.getRenderWidth());
  329. y = y * (textureSize.height / engine.getRenderHeight());
  330. }
  331. if (this._capturingControl) {
  332. this._capturingControl._processObservables(type, x, y, buttonIndex);
  333. return;
  334. }
  335. if (!this._rootContainer._processPicking(x, y, type, buttonIndex)) {
  336. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  337. if (this._lastControlOver) {
  338. this._lastControlOver._onPointerOut(this._lastControlOver);
  339. }
  340. this._lastControlOver = null;
  341. }
  342. }
  343. this._manageFocus();
  344. };
  345. AdvancedDynamicTexture.prototype.attach = function () {
  346. var _this = this;
  347. var scene = this.getScene();
  348. if (!scene) {
  349. return;
  350. }
  351. this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
  352. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  353. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  354. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  355. return;
  356. }
  357. if (!scene) {
  358. return;
  359. }
  360. var camera = scene.cameraToUseForPointers || scene.activeCamera;
  361. if (!camera) {
  362. return;
  363. }
  364. var engine = scene.getEngine();
  365. var viewport = camera.viewport;
  366. var x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
  367. var y = (scene.pointerY / engine.getHardwareScalingLevel() - viewport.y * engine.getRenderHeight()) / viewport.height;
  368. _this._shouldBlockPointer = false;
  369. _this._doPicking(x, y, pi.type, pi.event.button);
  370. pi.skipOnPointerObservable = _this._shouldBlockPointer;
  371. });
  372. this._attachToOnPointerOut(scene);
  373. };
  374. AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
  375. var _this = this;
  376. if (supportPointerMove === void 0) { supportPointerMove = true; }
  377. var scene = this.getScene();
  378. if (!scene) {
  379. return;
  380. }
  381. this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
  382. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  383. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  384. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  385. return;
  386. }
  387. if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
  388. var uv = pi.pickInfo.getTextureCoordinates();
  389. if (uv) {
  390. var size = _this.getSize();
  391. _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pi.event.button);
  392. }
  393. }
  394. else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
  395. if (_this._lastControlDown) {
  396. _this._lastControlDown.forcePointerUp();
  397. }
  398. _this._lastControlDown = null;
  399. _this.focusedControl = null;
  400. }
  401. else if (pi.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  402. if (_this._lastControlOver) {
  403. _this._lastControlOver._onPointerOut(_this._lastControlOver);
  404. }
  405. _this._lastControlOver = null;
  406. }
  407. });
  408. mesh.enablePointerMoveEvents = supportPointerMove;
  409. this._attachToOnPointerOut(scene);
  410. };
  411. AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
  412. this.focusedControl = control;
  413. this._lastPickedControl = control;
  414. this._blockNextFocusCheck = true;
  415. };
  416. AdvancedDynamicTexture.prototype._manageFocus = function () {
  417. if (this._blockNextFocusCheck) {
  418. this._blockNextFocusCheck = false;
  419. this._lastPickedControl = this._focusedControl;
  420. return;
  421. }
  422. // Focus management
  423. if (this._focusedControl) {
  424. if (this._focusedControl !== this._lastPickedControl) {
  425. if (this._lastPickedControl.isFocusInvisible) {
  426. return;
  427. }
  428. this.focusedControl = null;
  429. }
  430. }
  431. };
  432. AdvancedDynamicTexture.prototype._attachToOnPointerOut = function (scene) {
  433. var _this = this;
  434. this._canvasPointerOutObserver = scene.getEngine().onCanvasPointerOutObservable.add(function () {
  435. if (_this._lastControlOver) {
  436. _this._lastControlOver._onPointerOut(_this._lastControlOver);
  437. }
  438. _this._lastControlOver = null;
  439. if (_this._lastControlDown) {
  440. _this._lastControlDown.forcePointerUp();
  441. }
  442. _this._lastControlDown = null;
  443. });
  444. };
  445. // Statics
  446. AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height, supportPointerMove) {
  447. if (width === void 0) { width = 1024; }
  448. if (height === void 0) { height = 1024; }
  449. if (supportPointerMove === void 0) { supportPointerMove = true; }
  450. var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  451. var material = new BABYLON.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
  452. material.backFaceCulling = false;
  453. material.diffuseColor = BABYLON.Color3.Black();
  454. material.specularColor = BABYLON.Color3.Black();
  455. material.emissiveTexture = result;
  456. material.opacityTexture = result;
  457. mesh.material = material;
  458. result.attachToMesh(mesh, supportPointerMove);
  459. return result;
  460. };
  461. AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene) {
  462. if (foreground === void 0) { foreground = true; }
  463. if (scene === void 0) { scene = null; }
  464. var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
  465. // Display
  466. var layer = new BABYLON.Layer(name + "_layer", null, scene, !foreground);
  467. layer.texture = result;
  468. result._layerToDispose = layer;
  469. result._isFullscreen = true;
  470. // Attach
  471. result.attach();
  472. return result;
  473. };
  474. return AdvancedDynamicTexture;
  475. }(BABYLON.DynamicTexture));
  476. GUI.AdvancedDynamicTexture = AdvancedDynamicTexture;
  477. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  478. })(BABYLON || (BABYLON = {}));
  479. //# sourceMappingURL=advancedDynamicTexture.js.map
  480. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  481. var BABYLON;
  482. (function (BABYLON) {
  483. var GUI;
  484. (function (GUI) {
  485. var Measure = /** @class */ (function () {
  486. function Measure(left, top, width, height) {
  487. this.left = left;
  488. this.top = top;
  489. this.width = width;
  490. this.height = height;
  491. }
  492. Measure.prototype.copyFrom = function (other) {
  493. this.left = other.left;
  494. this.top = other.top;
  495. this.width = other.width;
  496. this.height = other.height;
  497. };
  498. Measure.prototype.isEqualsTo = function (other) {
  499. if (this.left !== other.left) {
  500. return false;
  501. }
  502. if (this.top !== other.top) {
  503. return false;
  504. }
  505. if (this.width !== other.width) {
  506. return false;
  507. }
  508. if (this.height !== other.height) {
  509. return false;
  510. }
  511. return true;
  512. };
  513. Measure.Empty = function () {
  514. return new Measure(0, 0, 0, 0);
  515. };
  516. return Measure;
  517. }());
  518. GUI.Measure = Measure;
  519. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  520. })(BABYLON || (BABYLON = {}));
  521. //# sourceMappingURL=measure.js.map
  522. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  523. var BABYLON;
  524. (function (BABYLON) {
  525. var GUI;
  526. (function (GUI) {
  527. var Vector2WithInfo = /** @class */ (function (_super) {
  528. __extends(Vector2WithInfo, _super);
  529. function Vector2WithInfo(source, buttonIndex) {
  530. if (buttonIndex === void 0) { buttonIndex = 0; }
  531. var _this = _super.call(this, source.x, source.y) || this;
  532. _this.buttonIndex = buttonIndex;
  533. return _this;
  534. }
  535. return Vector2WithInfo;
  536. }(BABYLON.Vector2));
  537. GUI.Vector2WithInfo = Vector2WithInfo;
  538. var Matrix2D = /** @class */ (function () {
  539. function Matrix2D(m00, m01, m10, m11, m20, m21) {
  540. this.m = new Float32Array(6);
  541. this.fromValues(m00, m01, m10, m11, m20, m21);
  542. }
  543. Matrix2D.prototype.fromValues = function (m00, m01, m10, m11, m20, m21) {
  544. this.m[0] = m00;
  545. this.m[1] = m01;
  546. this.m[2] = m10;
  547. this.m[3] = m11;
  548. this.m[4] = m20;
  549. this.m[5] = m21;
  550. return this;
  551. };
  552. Matrix2D.prototype.determinant = function () {
  553. return this.m[0] * this.m[3] - this.m[1] * this.m[2];
  554. };
  555. Matrix2D.prototype.invertToRef = function (result) {
  556. var l0 = this.m[0];
  557. var l1 = this.m[1];
  558. var l2 = this.m[2];
  559. var l3 = this.m[3];
  560. var l4 = this.m[4];
  561. var l5 = this.m[5];
  562. var det = this.determinant();
  563. if (det < (BABYLON.Epsilon * BABYLON.Epsilon)) {
  564. result.m[0] = 0;
  565. result.m[1] = 0;
  566. result.m[2] = 0;
  567. result.m[3] = 0;
  568. result.m[4] = 0;
  569. result.m[5] = 0;
  570. return this;
  571. }
  572. var detDiv = 1 / det;
  573. var det4 = l2 * l5 - l3 * l4;
  574. var det5 = l1 * l4 - l0 * l5;
  575. result.m[0] = l3 * detDiv;
  576. result.m[1] = -l1 * detDiv;
  577. result.m[2] = -l2 * detDiv;
  578. result.m[3] = l0 * detDiv;
  579. result.m[4] = det4 * detDiv;
  580. result.m[5] = det5 * detDiv;
  581. return this;
  582. };
  583. Matrix2D.prototype.multiplyToRef = function (other, result) {
  584. var l0 = this.m[0];
  585. var l1 = this.m[1];
  586. var l2 = this.m[2];
  587. var l3 = this.m[3];
  588. var l4 = this.m[4];
  589. var l5 = this.m[5];
  590. var r0 = other.m[0];
  591. var r1 = other.m[1];
  592. var r2 = other.m[2];
  593. var r3 = other.m[3];
  594. var r4 = other.m[4];
  595. var r5 = other.m[5];
  596. result.m[0] = l0 * r0 + l1 * r2;
  597. result.m[1] = l0 * r1 + l1 * r3;
  598. result.m[2] = l2 * r0 + l3 * r2;
  599. result.m[3] = l2 * r1 + l3 * r3;
  600. result.m[4] = l4 * r0 + l5 * r2 + r4;
  601. result.m[5] = l4 * r1 + l5 * r3 + r5;
  602. return this;
  603. };
  604. Matrix2D.prototype.transformCoordinates = function (x, y, result) {
  605. result.x = x * this.m[0] + y * this.m[2] + this.m[4];
  606. result.y = x * this.m[1] + y * this.m[3] + this.m[5];
  607. return this;
  608. };
  609. // Statics
  610. Matrix2D.Identity = function () {
  611. return new Matrix2D(1, 0, 0, 1, 0, 0);
  612. };
  613. Matrix2D.TranslationToRef = function (x, y, result) {
  614. result.fromValues(1, 0, 0, 1, x, y);
  615. };
  616. Matrix2D.ScalingToRef = function (x, y, result) {
  617. result.fromValues(x, 0, 0, y, 0, 0);
  618. };
  619. Matrix2D.RotationToRef = function (angle, result) {
  620. var s = Math.sin(angle);
  621. var c = Math.cos(angle);
  622. result.fromValues(c, s, -s, c, 0, 0);
  623. };
  624. Matrix2D.ComposeToRef = function (tx, ty, angle, scaleX, scaleY, parentMatrix, result) {
  625. Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
  626. Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);
  627. Matrix2D.RotationToRef(angle, Matrix2D._TempRotationMatrix);
  628. Matrix2D.TranslationToRef(-tx, -ty, Matrix2D._TempPostTranslationMatrix);
  629. Matrix2D._TempPreTranslationMatrix.multiplyToRef(Matrix2D._TempScalingMatrix, Matrix2D._TempCompose0);
  630. Matrix2D._TempCompose0.multiplyToRef(Matrix2D._TempRotationMatrix, Matrix2D._TempCompose1);
  631. if (parentMatrix) {
  632. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, Matrix2D._TempCompose2);
  633. Matrix2D._TempCompose2.multiplyToRef(parentMatrix, result);
  634. }
  635. else {
  636. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, result);
  637. }
  638. };
  639. Matrix2D._TempPreTranslationMatrix = Matrix2D.Identity();
  640. Matrix2D._TempPostTranslationMatrix = Matrix2D.Identity();
  641. Matrix2D._TempRotationMatrix = Matrix2D.Identity();
  642. Matrix2D._TempScalingMatrix = Matrix2D.Identity();
  643. Matrix2D._TempCompose0 = Matrix2D.Identity();
  644. Matrix2D._TempCompose1 = Matrix2D.Identity();
  645. Matrix2D._TempCompose2 = Matrix2D.Identity();
  646. return Matrix2D;
  647. }());
  648. GUI.Matrix2D = Matrix2D;
  649. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  650. })(BABYLON || (BABYLON = {}));
  651. //# sourceMappingURL=math2D.js.map
  652. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  653. var BABYLON;
  654. (function (BABYLON) {
  655. var GUI;
  656. (function (GUI) {
  657. var ValueAndUnit = /** @class */ (function () {
  658. function ValueAndUnit(value, unit, negativeValueAllowed) {
  659. if (unit === void 0) { unit = ValueAndUnit.UNITMODE_PIXEL; }
  660. if (negativeValueAllowed === void 0) { negativeValueAllowed = true; }
  661. this.unit = unit;
  662. this.negativeValueAllowed = negativeValueAllowed;
  663. this._value = 1;
  664. this.ignoreAdaptiveScaling = false;
  665. this._value = value;
  666. }
  667. Object.defineProperty(ValueAndUnit.prototype, "isPercentage", {
  668. get: function () {
  669. return this.unit === ValueAndUnit.UNITMODE_PERCENTAGE;
  670. },
  671. enumerable: true,
  672. configurable: true
  673. });
  674. Object.defineProperty(ValueAndUnit.prototype, "isPixel", {
  675. get: function () {
  676. return this.unit === ValueAndUnit.UNITMODE_PIXEL;
  677. },
  678. enumerable: true,
  679. configurable: true
  680. });
  681. Object.defineProperty(ValueAndUnit.prototype, "internalValue", {
  682. get: function () {
  683. return this._value;
  684. },
  685. enumerable: true,
  686. configurable: true
  687. });
  688. ValueAndUnit.prototype.getValueInPixel = function (host, refValue) {
  689. if (this.isPixel) {
  690. return this.getValue(host);
  691. }
  692. return this.getValue(host) * refValue;
  693. };
  694. ValueAndUnit.prototype.getValue = function (host) {
  695. if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
  696. if (host.idealWidth) {
  697. return (this._value * host.getSize().width) / host.idealWidth;
  698. }
  699. if (host.idealHeight) {
  700. return (this._value * host.getSize().height) / host.idealHeight;
  701. }
  702. }
  703. return this._value;
  704. };
  705. ValueAndUnit.prototype.toString = function (host) {
  706. switch (this.unit) {
  707. case ValueAndUnit.UNITMODE_PERCENTAGE:
  708. return (this.getValue(host) * 100) + "%";
  709. case ValueAndUnit.UNITMODE_PIXEL:
  710. return this.getValue(host) + "px";
  711. }
  712. return this.unit.toString();
  713. };
  714. ValueAndUnit.prototype.fromString = function (source) {
  715. var match = ValueAndUnit._Regex.exec(source.toString());
  716. if (!match || match.length === 0) {
  717. return false;
  718. }
  719. var sourceValue = parseFloat(match[1]);
  720. var sourceUnit = this.unit;
  721. if (!this.negativeValueAllowed) {
  722. if (sourceValue < 0) {
  723. sourceValue = 0;
  724. }
  725. }
  726. if (match.length === 4) {
  727. switch (match[3]) {
  728. case "px":
  729. sourceUnit = ValueAndUnit.UNITMODE_PIXEL;
  730. break;
  731. case "%":
  732. sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;
  733. sourceValue /= 100.0;
  734. break;
  735. }
  736. }
  737. if (sourceValue === this._value && sourceUnit === this.unit) {
  738. return false;
  739. }
  740. this._value = sourceValue;
  741. this.unit = sourceUnit;
  742. return true;
  743. };
  744. Object.defineProperty(ValueAndUnit, "UNITMODE_PERCENTAGE", {
  745. get: function () {
  746. return ValueAndUnit._UNITMODE_PERCENTAGE;
  747. },
  748. enumerable: true,
  749. configurable: true
  750. });
  751. Object.defineProperty(ValueAndUnit, "UNITMODE_PIXEL", {
  752. get: function () {
  753. return ValueAndUnit._UNITMODE_PIXEL;
  754. },
  755. enumerable: true,
  756. configurable: true
  757. });
  758. // Static
  759. ValueAndUnit._Regex = /(^-?\d*(\.\d+)?)(%|px)?/;
  760. ValueAndUnit._UNITMODE_PERCENTAGE = 0;
  761. ValueAndUnit._UNITMODE_PIXEL = 1;
  762. return ValueAndUnit;
  763. }());
  764. GUI.ValueAndUnit = ValueAndUnit;
  765. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  766. })(BABYLON || (BABYLON = {}));
  767. //# sourceMappingURL=valueAndUnit.js.map
  768. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  769. var BABYLON;
  770. (function (BABYLON) {
  771. var GUI;
  772. (function (GUI) {
  773. var Control = /** @class */ (function () {
  774. // Functions
  775. function Control(name) {
  776. this.name = name;
  777. this._alpha = 1;
  778. this._alphaSet = false;
  779. this._zIndex = 0;
  780. this._currentMeasure = GUI.Measure.Empty();
  781. this._fontFamily = "Arial";
  782. this._fontStyle = "";
  783. this._fontSize = new GUI.ValueAndUnit(18, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  784. this._width = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  785. this._height = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  786. this._color = "";
  787. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  788. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  789. this._isDirty = true;
  790. this._cachedParentMeasure = GUI.Measure.Empty();
  791. this._paddingLeft = new GUI.ValueAndUnit(0);
  792. this._paddingRight = new GUI.ValueAndUnit(0);
  793. this._paddingTop = new GUI.ValueAndUnit(0);
  794. this._paddingBottom = new GUI.ValueAndUnit(0);
  795. this._left = new GUI.ValueAndUnit(0);
  796. this._top = new GUI.ValueAndUnit(0);
  797. this._scaleX = 1.0;
  798. this._scaleY = 1.0;
  799. this._rotation = 0;
  800. this._transformCenterX = 0.5;
  801. this._transformCenterY = 0.5;
  802. this._transformMatrix = GUI.Matrix2D.Identity();
  803. this._invertTransformMatrix = GUI.Matrix2D.Identity();
  804. this._transformedPosition = BABYLON.Vector2.Zero();
  805. this._isMatrixDirty = true;
  806. this._isVisible = true;
  807. this._fontSet = false;
  808. this._dummyVector2 = BABYLON.Vector2.Zero();
  809. this._downCount = 0;
  810. this._enterCount = 0;
  811. this._doNotRender = false;
  812. this.isHitTestVisible = true;
  813. this.isPointerBlocker = false;
  814. this.isFocusInvisible = false;
  815. this.shadowOffsetX = 0;
  816. this.shadowOffsetY = 0;
  817. this.shadowBlur = 0;
  818. this.shadowColor = '#000';
  819. this._linkOffsetX = new GUI.ValueAndUnit(0);
  820. this._linkOffsetY = new GUI.ValueAndUnit(0);
  821. /**
  822. * An event triggered when the pointer move over the control.
  823. * @type {BABYLON.Observable}
  824. */
  825. this.onPointerMoveObservable = new BABYLON.Observable();
  826. /**
  827. * An event triggered when the pointer move out of the control.
  828. * @type {BABYLON.Observable}
  829. */
  830. this.onPointerOutObservable = new BABYLON.Observable();
  831. /**
  832. * An event triggered when the pointer taps the control
  833. * @type {BABYLON.Observable}
  834. */
  835. this.onPointerDownObservable = new BABYLON.Observable();
  836. /**
  837. * An event triggered when pointer up
  838. * @type {BABYLON.Observable}
  839. */
  840. this.onPointerUpObservable = new BABYLON.Observable();
  841. /**
  842. * An event triggered when pointer enters the control
  843. * @type {BABYLON.Observable}
  844. */
  845. this.onPointerEnterObservable = new BABYLON.Observable();
  846. /**
  847. * An event triggered when the control is marked as dirty
  848. * @type {BABYLON.Observable}
  849. */
  850. this.onDirtyObservable = new BABYLON.Observable();
  851. /**
  852. * An event triggered after the control is drawn
  853. * @type {BABYLON.Observable}
  854. */
  855. this.onAfterDrawObservable = new BABYLON.Observable();
  856. }
  857. Object.defineProperty(Control.prototype, "typeName", {
  858. // Properties
  859. get: function () {
  860. return this._getTypeName();
  861. },
  862. enumerable: true,
  863. configurable: true
  864. });
  865. Object.defineProperty(Control.prototype, "alpha", {
  866. get: function () {
  867. return this._alpha;
  868. },
  869. set: function (value) {
  870. if (this._alpha === value) {
  871. return;
  872. }
  873. this._alphaSet = true;
  874. this._alpha = value;
  875. this._markAsDirty();
  876. },
  877. enumerable: true,
  878. configurable: true
  879. });
  880. Object.defineProperty(Control.prototype, "scaleX", {
  881. get: function () {
  882. return this._scaleX;
  883. },
  884. set: function (value) {
  885. if (this._scaleX === value) {
  886. return;
  887. }
  888. this._scaleX = value;
  889. this._markAsDirty();
  890. this._markMatrixAsDirty();
  891. },
  892. enumerable: true,
  893. configurable: true
  894. });
  895. Object.defineProperty(Control.prototype, "scaleY", {
  896. get: function () {
  897. return this._scaleY;
  898. },
  899. set: function (value) {
  900. if (this._scaleY === value) {
  901. return;
  902. }
  903. this._scaleY = value;
  904. this._markAsDirty();
  905. this._markMatrixAsDirty();
  906. },
  907. enumerable: true,
  908. configurable: true
  909. });
  910. Object.defineProperty(Control.prototype, "rotation", {
  911. get: function () {
  912. return this._rotation;
  913. },
  914. set: function (value) {
  915. if (this._rotation === value) {
  916. return;
  917. }
  918. this._rotation = value;
  919. this._markAsDirty();
  920. this._markMatrixAsDirty();
  921. },
  922. enumerable: true,
  923. configurable: true
  924. });
  925. Object.defineProperty(Control.prototype, "transformCenterY", {
  926. get: function () {
  927. return this._transformCenterY;
  928. },
  929. set: function (value) {
  930. if (this._transformCenterY === value) {
  931. return;
  932. }
  933. this._transformCenterY = value;
  934. this._markAsDirty();
  935. this._markMatrixAsDirty();
  936. },
  937. enumerable: true,
  938. configurable: true
  939. });
  940. Object.defineProperty(Control.prototype, "transformCenterX", {
  941. get: function () {
  942. return this._transformCenterX;
  943. },
  944. set: function (value) {
  945. if (this._transformCenterX === value) {
  946. return;
  947. }
  948. this._transformCenterX = value;
  949. this._markAsDirty();
  950. this._markMatrixAsDirty();
  951. },
  952. enumerable: true,
  953. configurable: true
  954. });
  955. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  956. get: function () {
  957. return this._horizontalAlignment;
  958. },
  959. set: function (value) {
  960. if (this._horizontalAlignment === value) {
  961. return;
  962. }
  963. this._horizontalAlignment = value;
  964. this._markAsDirty();
  965. },
  966. enumerable: true,
  967. configurable: true
  968. });
  969. Object.defineProperty(Control.prototype, "verticalAlignment", {
  970. get: function () {
  971. return this._verticalAlignment;
  972. },
  973. set: function (value) {
  974. if (this._verticalAlignment === value) {
  975. return;
  976. }
  977. this._verticalAlignment = value;
  978. this._markAsDirty();
  979. },
  980. enumerable: true,
  981. configurable: true
  982. });
  983. Object.defineProperty(Control.prototype, "width", {
  984. get: function () {
  985. return this._width.toString(this._host);
  986. },
  987. set: function (value) {
  988. if (this._width.toString(this._host) === value) {
  989. return;
  990. }
  991. if (this._width.fromString(value)) {
  992. this._markAsDirty();
  993. }
  994. },
  995. enumerable: true,
  996. configurable: true
  997. });
  998. Object.defineProperty(Control.prototype, "widthInPixels", {
  999. get: function () {
  1000. return this._width.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1001. },
  1002. enumerable: true,
  1003. configurable: true
  1004. });
  1005. Object.defineProperty(Control.prototype, "height", {
  1006. get: function () {
  1007. return this._height.toString(this._host);
  1008. },
  1009. set: function (value) {
  1010. if (this._height.toString(this._host) === value) {
  1011. return;
  1012. }
  1013. if (this._height.fromString(value)) {
  1014. this._markAsDirty();
  1015. }
  1016. },
  1017. enumerable: true,
  1018. configurable: true
  1019. });
  1020. Object.defineProperty(Control.prototype, "heightInPixels", {
  1021. get: function () {
  1022. return this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1023. },
  1024. enumerable: true,
  1025. configurable: true
  1026. });
  1027. Object.defineProperty(Control.prototype, "fontFamily", {
  1028. get: function () {
  1029. return this._fontFamily;
  1030. },
  1031. set: function (value) {
  1032. if (this._fontFamily === value) {
  1033. return;
  1034. }
  1035. this._fontFamily = value;
  1036. this._fontSet = true;
  1037. },
  1038. enumerable: true,
  1039. configurable: true
  1040. });
  1041. Object.defineProperty(Control.prototype, "fontStyle", {
  1042. get: function () {
  1043. return this._fontStyle;
  1044. },
  1045. set: function (value) {
  1046. if (this._fontStyle === value) {
  1047. return;
  1048. }
  1049. this._fontStyle = value;
  1050. this._fontSet = true;
  1051. },
  1052. enumerable: true,
  1053. configurable: true
  1054. });
  1055. Object.defineProperty(Control.prototype, "fontSizeInPixels", {
  1056. get: function () {
  1057. return this._fontSize.getValueInPixel(this._host, 100);
  1058. },
  1059. enumerable: true,
  1060. configurable: true
  1061. });
  1062. Object.defineProperty(Control.prototype, "fontSize", {
  1063. get: function () {
  1064. return this._fontSize.toString(this._host);
  1065. },
  1066. set: function (value) {
  1067. if (this._fontSize.toString(this._host) === value) {
  1068. return;
  1069. }
  1070. if (this._fontSize.fromString(value)) {
  1071. this._markAsDirty();
  1072. this._fontSet = true;
  1073. }
  1074. },
  1075. enumerable: true,
  1076. configurable: true
  1077. });
  1078. Object.defineProperty(Control.prototype, "color", {
  1079. get: function () {
  1080. return this._color;
  1081. },
  1082. set: function (value) {
  1083. if (this._color === value) {
  1084. return;
  1085. }
  1086. this._color = value;
  1087. this._markAsDirty();
  1088. },
  1089. enumerable: true,
  1090. configurable: true
  1091. });
  1092. Object.defineProperty(Control.prototype, "zIndex", {
  1093. get: function () {
  1094. return this._zIndex;
  1095. },
  1096. set: function (value) {
  1097. if (this.zIndex === value) {
  1098. return;
  1099. }
  1100. this._zIndex = value;
  1101. if (this._root) {
  1102. this._root._reOrderControl(this);
  1103. }
  1104. },
  1105. enumerable: true,
  1106. configurable: true
  1107. });
  1108. Object.defineProperty(Control.prototype, "notRenderable", {
  1109. get: function () {
  1110. return this._doNotRender;
  1111. },
  1112. set: function (value) {
  1113. if (this._doNotRender === value) {
  1114. return;
  1115. }
  1116. this._doNotRender = value;
  1117. this._markAsDirty();
  1118. },
  1119. enumerable: true,
  1120. configurable: true
  1121. });
  1122. Object.defineProperty(Control.prototype, "isVisible", {
  1123. get: function () {
  1124. return this._isVisible;
  1125. },
  1126. set: function (value) {
  1127. if (this._isVisible === value) {
  1128. return;
  1129. }
  1130. this._isVisible = value;
  1131. this._markAsDirty();
  1132. },
  1133. enumerable: true,
  1134. configurable: true
  1135. });
  1136. Object.defineProperty(Control.prototype, "isDirty", {
  1137. get: function () {
  1138. return this._isDirty;
  1139. },
  1140. enumerable: true,
  1141. configurable: true
  1142. });
  1143. Object.defineProperty(Control.prototype, "paddingLeft", {
  1144. get: function () {
  1145. return this._paddingLeft.toString(this._host);
  1146. },
  1147. set: function (value) {
  1148. if (this._paddingLeft.fromString(value)) {
  1149. this._markAsDirty();
  1150. }
  1151. },
  1152. enumerable: true,
  1153. configurable: true
  1154. });
  1155. Object.defineProperty(Control.prototype, "paddingLeftInPixels", {
  1156. get: function () {
  1157. return this._paddingLeft.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1158. },
  1159. enumerable: true,
  1160. configurable: true
  1161. });
  1162. Object.defineProperty(Control.prototype, "paddingRight", {
  1163. get: function () {
  1164. return this._paddingRight.toString(this._host);
  1165. },
  1166. set: function (value) {
  1167. if (this._paddingRight.fromString(value)) {
  1168. this._markAsDirty();
  1169. }
  1170. },
  1171. enumerable: true,
  1172. configurable: true
  1173. });
  1174. Object.defineProperty(Control.prototype, "paddingRightInPixels", {
  1175. get: function () {
  1176. return this._paddingRight.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1177. },
  1178. enumerable: true,
  1179. configurable: true
  1180. });
  1181. Object.defineProperty(Control.prototype, "paddingTop", {
  1182. get: function () {
  1183. return this._paddingTop.toString(this._host);
  1184. },
  1185. set: function (value) {
  1186. if (this._paddingTop.fromString(value)) {
  1187. this._markAsDirty();
  1188. }
  1189. },
  1190. enumerable: true,
  1191. configurable: true
  1192. });
  1193. Object.defineProperty(Control.prototype, "paddingTopInPixels", {
  1194. get: function () {
  1195. return this._paddingTop.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1196. },
  1197. enumerable: true,
  1198. configurable: true
  1199. });
  1200. Object.defineProperty(Control.prototype, "paddingBottom", {
  1201. get: function () {
  1202. return this._paddingBottom.toString(this._host);
  1203. },
  1204. set: function (value) {
  1205. if (this._paddingBottom.fromString(value)) {
  1206. this._markAsDirty();
  1207. }
  1208. },
  1209. enumerable: true,
  1210. configurable: true
  1211. });
  1212. Object.defineProperty(Control.prototype, "paddingBottomInPixels", {
  1213. get: function () {
  1214. return this._paddingBottom.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1215. },
  1216. enumerable: true,
  1217. configurable: true
  1218. });
  1219. Object.defineProperty(Control.prototype, "left", {
  1220. get: function () {
  1221. return this._left.toString(this._host);
  1222. },
  1223. set: function (value) {
  1224. if (this._left.fromString(value)) {
  1225. this._markAsDirty();
  1226. }
  1227. },
  1228. enumerable: true,
  1229. configurable: true
  1230. });
  1231. Object.defineProperty(Control.prototype, "leftInPixels", {
  1232. get: function () {
  1233. return this._left.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1234. },
  1235. enumerable: true,
  1236. configurable: true
  1237. });
  1238. Object.defineProperty(Control.prototype, "top", {
  1239. get: function () {
  1240. return this._top.toString(this._host);
  1241. },
  1242. set: function (value) {
  1243. if (this._top.fromString(value)) {
  1244. this._markAsDirty();
  1245. }
  1246. },
  1247. enumerable: true,
  1248. configurable: true
  1249. });
  1250. Object.defineProperty(Control.prototype, "topInPixels", {
  1251. get: function () {
  1252. return this._top.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1253. },
  1254. enumerable: true,
  1255. configurable: true
  1256. });
  1257. Object.defineProperty(Control.prototype, "linkOffsetX", {
  1258. get: function () {
  1259. return this._linkOffsetX.toString(this._host);
  1260. },
  1261. set: function (value) {
  1262. if (this._linkOffsetX.fromString(value)) {
  1263. this._markAsDirty();
  1264. }
  1265. },
  1266. enumerable: true,
  1267. configurable: true
  1268. });
  1269. Object.defineProperty(Control.prototype, "linkOffsetXInPixels", {
  1270. get: function () {
  1271. return this._linkOffsetX.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1272. },
  1273. enumerable: true,
  1274. configurable: true
  1275. });
  1276. Object.defineProperty(Control.prototype, "linkOffsetY", {
  1277. get: function () {
  1278. return this._linkOffsetY.toString(this._host);
  1279. },
  1280. set: function (value) {
  1281. if (this._linkOffsetY.fromString(value)) {
  1282. this._markAsDirty();
  1283. }
  1284. },
  1285. enumerable: true,
  1286. configurable: true
  1287. });
  1288. Object.defineProperty(Control.prototype, "linkOffsetYInPixels", {
  1289. get: function () {
  1290. return this._linkOffsetY.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1291. },
  1292. enumerable: true,
  1293. configurable: true
  1294. });
  1295. Object.defineProperty(Control.prototype, "centerX", {
  1296. get: function () {
  1297. return this._currentMeasure.left + this._currentMeasure.width / 2;
  1298. },
  1299. enumerable: true,
  1300. configurable: true
  1301. });
  1302. Object.defineProperty(Control.prototype, "centerY", {
  1303. get: function () {
  1304. return this._currentMeasure.top + this._currentMeasure.height / 2;
  1305. },
  1306. enumerable: true,
  1307. configurable: true
  1308. });
  1309. Control.prototype._getTypeName = function () {
  1310. return "Control";
  1311. };
  1312. Control.prototype.getLocalCoordinates = function (globalCoordinates) {
  1313. var result = BABYLON.Vector2.Zero();
  1314. this.getLocalCoordinatesToRef(globalCoordinates, result);
  1315. return result;
  1316. };
  1317. Control.prototype.getLocalCoordinatesToRef = function (globalCoordinates, result) {
  1318. result.x = globalCoordinates.x - this._currentMeasure.left;
  1319. result.y = globalCoordinates.y - this._currentMeasure.top;
  1320. return this;
  1321. };
  1322. Control.prototype.getParentLocalCoordinates = function (globalCoordinates) {
  1323. var result = BABYLON.Vector2.Zero();
  1324. result.x = globalCoordinates.x - this._cachedParentMeasure.left;
  1325. result.y = globalCoordinates.y - this._cachedParentMeasure.top;
  1326. return result;
  1327. };
  1328. Control.prototype.moveToVector3 = function (position, scene) {
  1329. if (!this._host || this._root !== this._host._rootContainer) {
  1330. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  1331. return;
  1332. }
  1333. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1334. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1335. var globalViewport = this._host._getGlobalViewport(scene);
  1336. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  1337. this._moveToProjectedPosition(projectedPosition);
  1338. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  1339. this.notRenderable = true;
  1340. return;
  1341. }
  1342. this.notRenderable = false;
  1343. };
  1344. Control.prototype.linkWithMesh = function (mesh) {
  1345. if (!this._host || this._root !== this._host._rootContainer) {
  1346. BABYLON.Tools.Error("Cannot link a control to a mesh if the control is not at root level");
  1347. return;
  1348. }
  1349. var index = this._host._linkedControls.indexOf(this);
  1350. if (index !== -1) {
  1351. this._linkedMesh = mesh;
  1352. if (!mesh) {
  1353. this._host._linkedControls.splice(index, 1);
  1354. }
  1355. return;
  1356. }
  1357. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1358. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1359. this._linkedMesh = mesh;
  1360. this._host._linkedControls.push(this);
  1361. };
  1362. Control.prototype._moveToProjectedPosition = function (projectedPosition) {
  1363. this.left = ((projectedPosition.x + this._linkOffsetX.getValue(this._host)) - this._currentMeasure.width / 2) + "px";
  1364. this.top = ((projectedPosition.y + this._linkOffsetY.getValue(this._host)) - this._currentMeasure.height / 2) + "px";
  1365. this._left.ignoreAdaptiveScaling = true;
  1366. this._top.ignoreAdaptiveScaling = true;
  1367. };
  1368. Control.prototype._markMatrixAsDirty = function () {
  1369. this._isMatrixDirty = true;
  1370. this._markAsDirty();
  1371. };
  1372. Control.prototype._markAsDirty = function () {
  1373. this._isDirty = true;
  1374. if (!this._host) {
  1375. return; // Not yet connected
  1376. }
  1377. this._host.markAsDirty();
  1378. };
  1379. Control.prototype._markAllAsDirty = function () {
  1380. this._markAsDirty();
  1381. if (this._font) {
  1382. this._prepareFont();
  1383. }
  1384. };
  1385. Control.prototype._link = function (root, host) {
  1386. this._root = root;
  1387. this._host = host;
  1388. };
  1389. Control.prototype._transform = function (context) {
  1390. if (!this._isMatrixDirty && this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  1391. return;
  1392. }
  1393. // postTranslate
  1394. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  1395. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  1396. context.translate(offsetX, offsetY);
  1397. // rotate
  1398. context.rotate(this._rotation);
  1399. // scale
  1400. context.scale(this._scaleX, this._scaleY);
  1401. // preTranslate
  1402. context.translate(-offsetX, -offsetY);
  1403. // Need to update matrices?
  1404. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  1405. this._cachedOffsetX = offsetX;
  1406. this._cachedOffsetY = offsetY;
  1407. this._isMatrixDirty = false;
  1408. GUI.Matrix2D.ComposeToRef(-offsetX, -offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  1409. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  1410. }
  1411. };
  1412. Control.prototype._applyStates = function (context) {
  1413. if (this._fontSet) {
  1414. this._prepareFont();
  1415. this._fontSet = false;
  1416. }
  1417. if (this._font) {
  1418. context.font = this._font;
  1419. }
  1420. if (this._color) {
  1421. context.fillStyle = this._color;
  1422. }
  1423. if (this._alphaSet) {
  1424. context.globalAlpha = this._alpha;
  1425. }
  1426. };
  1427. Control.prototype._processMeasures = function (parentMeasure, context) {
  1428. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  1429. this._isDirty = false;
  1430. this._currentMeasure.copyFrom(parentMeasure);
  1431. // Let children take some pre-measurement actions
  1432. this._preMeasure(parentMeasure, context);
  1433. this._measure();
  1434. this._computeAlignment(parentMeasure, context);
  1435. // Convert to int values
  1436. this._currentMeasure.left = this._currentMeasure.left | 0;
  1437. this._currentMeasure.top = this._currentMeasure.top | 0;
  1438. this._currentMeasure.width = this._currentMeasure.width | 0;
  1439. this._currentMeasure.height = this._currentMeasure.height | 0;
  1440. // Let children add more features
  1441. this._additionalProcessing(parentMeasure, context);
  1442. this._cachedParentMeasure.copyFrom(parentMeasure);
  1443. if (this.onDirtyObservable.hasObservers()) {
  1444. this.onDirtyObservable.notifyObservers(this);
  1445. }
  1446. }
  1447. if (this._currentMeasure.left > parentMeasure.left + parentMeasure.width) {
  1448. return false;
  1449. }
  1450. if (this._currentMeasure.left + this._currentMeasure.width < parentMeasure.left) {
  1451. return false;
  1452. }
  1453. if (this._currentMeasure.top > parentMeasure.top + parentMeasure.height) {
  1454. return false;
  1455. }
  1456. if (this._currentMeasure.top + this._currentMeasure.height < parentMeasure.top) {
  1457. return false;
  1458. }
  1459. // Transform
  1460. this._transform(context);
  1461. // Clip
  1462. this._clip(context);
  1463. context.clip();
  1464. return true;
  1465. };
  1466. Control.prototype._clip = function (context) {
  1467. context.beginPath();
  1468. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1469. var shadowOffsetX = this.shadowOffsetX;
  1470. var shadowOffsetY = this.shadowOffsetY;
  1471. var shadowBlur = this.shadowBlur;
  1472. var leftShadowOffset = Math.min(Math.min(shadowOffsetX, 0) - shadowBlur * 2, 0);
  1473. var rightShadowOffset = Math.max(Math.max(shadowOffsetX, 0) + shadowBlur * 2, 0);
  1474. var topShadowOffset = Math.min(Math.min(shadowOffsetY, 0) - shadowBlur * 2, 0);
  1475. var bottomShadowOffset = Math.max(Math.max(shadowOffsetY, 0) + shadowBlur * 2, 0);
  1476. context.rect(this._currentMeasure.left + leftShadowOffset, this._currentMeasure.top + topShadowOffset, this._currentMeasure.width + rightShadowOffset - leftShadowOffset, this._currentMeasure.height + bottomShadowOffset - topShadowOffset);
  1477. }
  1478. else {
  1479. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1480. }
  1481. };
  1482. Control.prototype._measure = function () {
  1483. // Width / Height
  1484. if (this._width.isPixel) {
  1485. this._currentMeasure.width = this._width.getValue(this._host);
  1486. }
  1487. else {
  1488. this._currentMeasure.width *= this._width.getValue(this._host);
  1489. }
  1490. if (this._height.isPixel) {
  1491. this._currentMeasure.height = this._height.getValue(this._host);
  1492. }
  1493. else {
  1494. this._currentMeasure.height *= this._height.getValue(this._host);
  1495. }
  1496. };
  1497. Control.prototype._computeAlignment = function (parentMeasure, context) {
  1498. var width = this._currentMeasure.width;
  1499. var height = this._currentMeasure.height;
  1500. var parentWidth = parentMeasure.width;
  1501. var parentHeight = parentMeasure.height;
  1502. // Left / top
  1503. var x = 0;
  1504. var y = 0;
  1505. switch (this.horizontalAlignment) {
  1506. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  1507. x = 0;
  1508. break;
  1509. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  1510. x = parentWidth - width;
  1511. break;
  1512. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  1513. x = (parentWidth - width) / 2;
  1514. break;
  1515. }
  1516. switch (this.verticalAlignment) {
  1517. case Control.VERTICAL_ALIGNMENT_TOP:
  1518. y = 0;
  1519. break;
  1520. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  1521. y = parentHeight - height;
  1522. break;
  1523. case Control.VERTICAL_ALIGNMENT_CENTER:
  1524. y = (parentHeight - height) / 2;
  1525. break;
  1526. }
  1527. if (this._paddingLeft.isPixel) {
  1528. this._currentMeasure.left += this._paddingLeft.getValue(this._host);
  1529. this._currentMeasure.width -= this._paddingLeft.getValue(this._host);
  1530. }
  1531. else {
  1532. this._currentMeasure.left += parentWidth * this._paddingLeft.getValue(this._host);
  1533. this._currentMeasure.width -= parentWidth * this._paddingLeft.getValue(this._host);
  1534. }
  1535. if (this._paddingRight.isPixel) {
  1536. this._currentMeasure.width -= this._paddingRight.getValue(this._host);
  1537. }
  1538. else {
  1539. this._currentMeasure.width -= parentWidth * this._paddingRight.getValue(this._host);
  1540. }
  1541. if (this._paddingTop.isPixel) {
  1542. this._currentMeasure.top += this._paddingTop.getValue(this._host);
  1543. this._currentMeasure.height -= this._paddingTop.getValue(this._host);
  1544. }
  1545. else {
  1546. this._currentMeasure.top += parentHeight * this._paddingTop.getValue(this._host);
  1547. this._currentMeasure.height -= parentHeight * this._paddingTop.getValue(this._host);
  1548. }
  1549. if (this._paddingBottom.isPixel) {
  1550. this._currentMeasure.height -= this._paddingBottom.getValue(this._host);
  1551. }
  1552. else {
  1553. this._currentMeasure.height -= parentHeight * this._paddingBottom.getValue(this._host);
  1554. }
  1555. if (this._left.isPixel) {
  1556. this._currentMeasure.left += this._left.getValue(this._host);
  1557. }
  1558. else {
  1559. this._currentMeasure.left += parentWidth * this._left.getValue(this._host);
  1560. }
  1561. if (this._top.isPixel) {
  1562. this._currentMeasure.top += this._top.getValue(this._host);
  1563. }
  1564. else {
  1565. this._currentMeasure.top += parentHeight * this._top.getValue(this._host);
  1566. }
  1567. this._currentMeasure.left += x;
  1568. this._currentMeasure.top += y;
  1569. };
  1570. Control.prototype._preMeasure = function (parentMeasure, context) {
  1571. // Do nothing
  1572. };
  1573. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  1574. // Do nothing
  1575. };
  1576. Control.prototype._draw = function (parentMeasure, context) {
  1577. // Do nothing
  1578. };
  1579. Control.prototype.contains = function (x, y) {
  1580. // Invert transform
  1581. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  1582. x = this._transformedPosition.x;
  1583. y = this._transformedPosition.y;
  1584. // Check
  1585. if (x < this._currentMeasure.left) {
  1586. return false;
  1587. }
  1588. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  1589. return false;
  1590. }
  1591. if (y < this._currentMeasure.top) {
  1592. return false;
  1593. }
  1594. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  1595. return false;
  1596. }
  1597. if (this.isPointerBlocker) {
  1598. this._host._shouldBlockPointer = true;
  1599. }
  1600. return true;
  1601. };
  1602. Control.prototype._processPicking = function (x, y, type, buttonIndex) {
  1603. if (!this.isHitTestVisible || !this.isVisible || this._doNotRender) {
  1604. return false;
  1605. }
  1606. if (!this.contains(x, y)) {
  1607. return false;
  1608. }
  1609. this._processObservables(type, x, y, buttonIndex);
  1610. return true;
  1611. };
  1612. Control.prototype._onPointerMove = function (target, coordinates) {
  1613. var canNotify = this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  1614. if (canNotify && this.parent != null)
  1615. this.parent._onPointerMove(target, coordinates);
  1616. };
  1617. Control.prototype._onPointerEnter = function (target) {
  1618. if (this._enterCount !== 0) {
  1619. return false;
  1620. }
  1621. this._enterCount++;
  1622. var canNotify = this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  1623. if (canNotify && this.parent != null)
  1624. this.parent._onPointerEnter(target);
  1625. return true;
  1626. };
  1627. Control.prototype._onPointerOut = function (target) {
  1628. this._enterCount = 0;
  1629. var canNotify = this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  1630. if (canNotify && this.parent != null)
  1631. this.parent._onPointerOut(target);
  1632. };
  1633. Control.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  1634. if (this._downCount !== 0) {
  1635. return false;
  1636. }
  1637. this._downCount++;
  1638. var canNotify = this.onPointerDownObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  1639. if (canNotify && this.parent != null)
  1640. this.parent._onPointerDown(target, coordinates, buttonIndex);
  1641. return true;
  1642. };
  1643. Control.prototype._onPointerUp = function (target, coordinates, buttonIndex) {
  1644. this._downCount = 0;
  1645. var canNotify = this.onPointerUpObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  1646. if (canNotify && this.parent != null)
  1647. this.parent._onPointerUp(target, coordinates, buttonIndex);
  1648. };
  1649. Control.prototype.forcePointerUp = function () {
  1650. this._onPointerUp(this, BABYLON.Vector2.Zero(), 0);
  1651. };
  1652. Control.prototype._processObservables = function (type, x, y, buttonIndex) {
  1653. this._dummyVector2.copyFromFloats(x, y);
  1654. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  1655. this._onPointerMove(this, this._dummyVector2);
  1656. var previousControlOver = this._host._lastControlOver;
  1657. if (previousControlOver && previousControlOver !== this) {
  1658. previousControlOver._onPointerOut(this);
  1659. }
  1660. if (previousControlOver !== this) {
  1661. this._onPointerEnter(this);
  1662. }
  1663. this._host._lastControlOver = this;
  1664. return true;
  1665. }
  1666. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  1667. this._onPointerDown(this, this._dummyVector2, buttonIndex);
  1668. this._host._lastControlDown = this;
  1669. this._host._lastPickedControl = this;
  1670. return true;
  1671. }
  1672. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  1673. if (this._host._lastControlDown) {
  1674. this._host._lastControlDown._onPointerUp(this, this._dummyVector2, buttonIndex);
  1675. }
  1676. this._host._lastControlDown = null;
  1677. return true;
  1678. }
  1679. return false;
  1680. };
  1681. Control.prototype._prepareFont = function () {
  1682. if (!this._font && !this._fontSet) {
  1683. return;
  1684. }
  1685. this._font = this._fontStyle + " " + this._fontSize.getValue(this._host) + "px " + this._fontFamily;
  1686. this._fontOffset = Control._GetFontOffset(this._font);
  1687. };
  1688. Control.prototype.dispose = function () {
  1689. this.onDirtyObservable.clear();
  1690. this.onAfterDrawObservable.clear();
  1691. this.onPointerDownObservable.clear();
  1692. this.onPointerEnterObservable.clear();
  1693. this.onPointerMoveObservable.clear();
  1694. this.onPointerOutObservable.clear();
  1695. this.onPointerUpObservable.clear();
  1696. if (this._root) {
  1697. this._root.removeControl(this);
  1698. this._root = null;
  1699. }
  1700. var index = this._host._linkedControls.indexOf(this);
  1701. if (index > -1) {
  1702. this.linkWithMesh(null);
  1703. }
  1704. };
  1705. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  1706. get: function () {
  1707. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  1708. },
  1709. enumerable: true,
  1710. configurable: true
  1711. });
  1712. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  1713. get: function () {
  1714. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  1715. },
  1716. enumerable: true,
  1717. configurable: true
  1718. });
  1719. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  1720. get: function () {
  1721. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  1722. },
  1723. enumerable: true,
  1724. configurable: true
  1725. });
  1726. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  1727. get: function () {
  1728. return Control._VERTICAL_ALIGNMENT_TOP;
  1729. },
  1730. enumerable: true,
  1731. configurable: true
  1732. });
  1733. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  1734. get: function () {
  1735. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  1736. },
  1737. enumerable: true,
  1738. configurable: true
  1739. });
  1740. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  1741. get: function () {
  1742. return Control._VERTICAL_ALIGNMENT_CENTER;
  1743. },
  1744. enumerable: true,
  1745. configurable: true
  1746. });
  1747. Control._GetFontOffset = function (font) {
  1748. if (Control._FontHeightSizes[font]) {
  1749. return Control._FontHeightSizes[font];
  1750. }
  1751. var text = document.createElement("span");
  1752. text.innerHTML = "Hg";
  1753. text.style.font = font;
  1754. var block = document.createElement("div");
  1755. block.style.display = "inline-block";
  1756. block.style.width = "1px";
  1757. block.style.height = "0px";
  1758. block.style.verticalAlign = "bottom";
  1759. var div = document.createElement("div");
  1760. div.appendChild(text);
  1761. div.appendChild(block);
  1762. document.body.appendChild(div);
  1763. var fontAscent = 0;
  1764. var fontHeight = 0;
  1765. try {
  1766. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1767. block.style.verticalAlign = "baseline";
  1768. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1769. }
  1770. finally {
  1771. document.body.removeChild(div);
  1772. }
  1773. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  1774. Control._FontHeightSizes[font] = result;
  1775. return result;
  1776. };
  1777. ;
  1778. Control.AddHeader = function (control, text, size, options) {
  1779. var panel = new BABYLON.GUI.StackPanel("panel");
  1780. var isHorizontal = options ? options.isHorizontal : true;
  1781. var controlFirst = options ? options.controlFirst : true;
  1782. panel.isVertical = !isHorizontal;
  1783. var header = new BABYLON.GUI.TextBlock("header");
  1784. header.text = text;
  1785. header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  1786. if (isHorizontal) {
  1787. header.width = size;
  1788. }
  1789. else {
  1790. header.height = size;
  1791. }
  1792. if (controlFirst) {
  1793. panel.addControl(control);
  1794. panel.addControl(header);
  1795. header.paddingLeft = "5px";
  1796. }
  1797. else {
  1798. panel.addControl(header);
  1799. panel.addControl(control);
  1800. header.paddingRight = "5px";
  1801. }
  1802. header.shadowBlur = control.shadowBlur;
  1803. header.shadowColor = control.shadowColor;
  1804. header.shadowOffsetX = control.shadowOffsetX;
  1805. header.shadowOffsetY = control.shadowOffsetY;
  1806. return panel;
  1807. };
  1808. Control.drawEllipse = function (x, y, width, height, context) {
  1809. context.translate(x, y);
  1810. context.scale(width, height);
  1811. context.beginPath();
  1812. context.arc(0, 0, 1, 0, 2 * Math.PI);
  1813. context.closePath();
  1814. context.scale(1 / width, 1 / height);
  1815. context.translate(-x, -y);
  1816. };
  1817. // Statics
  1818. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  1819. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  1820. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  1821. Control._VERTICAL_ALIGNMENT_TOP = 0;
  1822. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  1823. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  1824. Control._FontHeightSizes = {};
  1825. return Control;
  1826. }());
  1827. GUI.Control = Control;
  1828. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1829. })(BABYLON || (BABYLON = {}));
  1830. //# sourceMappingURL=control.js.map
  1831. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1832. var BABYLON;
  1833. (function (BABYLON) {
  1834. var GUI;
  1835. (function (GUI) {
  1836. var Container = /** @class */ (function (_super) {
  1837. __extends(Container, _super);
  1838. function Container(name) {
  1839. var _this = _super.call(this, name) || this;
  1840. _this.name = name;
  1841. _this._children = new Array();
  1842. _this._measureForChildren = GUI.Measure.Empty();
  1843. return _this;
  1844. }
  1845. Object.defineProperty(Container.prototype, "background", {
  1846. get: function () {
  1847. return this._background;
  1848. },
  1849. set: function (value) {
  1850. if (this._background === value) {
  1851. return;
  1852. }
  1853. this._background = value;
  1854. this._markAsDirty();
  1855. },
  1856. enumerable: true,
  1857. configurable: true
  1858. });
  1859. Object.defineProperty(Container.prototype, "children", {
  1860. get: function () {
  1861. return this._children;
  1862. },
  1863. enumerable: true,
  1864. configurable: true
  1865. });
  1866. Container.prototype._getTypeName = function () {
  1867. return "Container";
  1868. };
  1869. Container.prototype.getChildByName = function (name) {
  1870. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1871. var child = _a[_i];
  1872. if (child.name === name) {
  1873. return child;
  1874. }
  1875. }
  1876. return null;
  1877. };
  1878. Container.prototype.getChildByType = function (name, type) {
  1879. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1880. var child = _a[_i];
  1881. if (child.typeName === type) {
  1882. return child;
  1883. }
  1884. }
  1885. return null;
  1886. };
  1887. Container.prototype.containsControl = function (control) {
  1888. return this._children.indexOf(control) !== -1;
  1889. };
  1890. Container.prototype.addControl = function (control) {
  1891. var index = this._children.indexOf(control);
  1892. if (index !== -1) {
  1893. return this;
  1894. }
  1895. control._link(this, this._host);
  1896. control._markAllAsDirty();
  1897. this._reOrderControl(control);
  1898. this._markAsDirty();
  1899. return this;
  1900. };
  1901. Container.prototype.removeControl = function (control) {
  1902. var index = this._children.indexOf(control);
  1903. if (index !== -1) {
  1904. this._children.splice(index, 1);
  1905. control.parent = null;
  1906. }
  1907. this._markAsDirty();
  1908. return this;
  1909. };
  1910. Container.prototype._reOrderControl = function (control) {
  1911. this.removeControl(control);
  1912. for (var index = 0; index < this._children.length; index++) {
  1913. if (this._children[index].zIndex > control.zIndex) {
  1914. this._children.splice(index, 0, control);
  1915. return;
  1916. }
  1917. }
  1918. this._children.push(control);
  1919. control.parent = this;
  1920. this._markAsDirty();
  1921. };
  1922. Container.prototype._markMatrixAsDirty = function () {
  1923. _super.prototype._markMatrixAsDirty.call(this);
  1924. for (var index = 0; index < this._children.length; index++) {
  1925. this._children[index]._markMatrixAsDirty();
  1926. }
  1927. };
  1928. Container.prototype._markAllAsDirty = function () {
  1929. _super.prototype._markAllAsDirty.call(this);
  1930. for (var index = 0; index < this._children.length; index++) {
  1931. this._children[index]._markAllAsDirty();
  1932. }
  1933. };
  1934. Container.prototype._localDraw = function (context) {
  1935. if (this._background) {
  1936. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1937. context.shadowColor = this.shadowColor;
  1938. context.shadowBlur = this.shadowBlur;
  1939. context.shadowOffsetX = this.shadowOffsetX;
  1940. context.shadowOffsetY = this.shadowOffsetY;
  1941. }
  1942. context.fillStyle = this._background;
  1943. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1944. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1945. context.shadowBlur = 0;
  1946. context.shadowOffsetX = 0;
  1947. context.shadowOffsetY = 0;
  1948. }
  1949. }
  1950. };
  1951. Container.prototype._link = function (root, host) {
  1952. _super.prototype._link.call(this, root, host);
  1953. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1954. var child = _a[_i];
  1955. child._link(root, host);
  1956. }
  1957. };
  1958. Container.prototype._draw = function (parentMeasure, context) {
  1959. if (!this.isVisible || this.notRenderable) {
  1960. return;
  1961. }
  1962. context.save();
  1963. this._applyStates(context);
  1964. if (this._processMeasures(parentMeasure, context)) {
  1965. this._localDraw(context);
  1966. this._clipForChildren(context);
  1967. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1968. var child = _a[_i];
  1969. if (child.isVisible && !child.notRenderable) {
  1970. child._draw(this._measureForChildren, context);
  1971. if (child.onAfterDrawObservable.hasObservers()) {
  1972. child.onAfterDrawObservable.notifyObservers(child);
  1973. }
  1974. }
  1975. }
  1976. }
  1977. context.restore();
  1978. if (this.onAfterDrawObservable.hasObservers()) {
  1979. this.onAfterDrawObservable.notifyObservers(this);
  1980. }
  1981. };
  1982. Container.prototype._processPicking = function (x, y, type, buttonIndex) {
  1983. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  1984. return false;
  1985. }
  1986. if (!_super.prototype.contains.call(this, x, y)) {
  1987. return false;
  1988. }
  1989. // Checking backwards to pick closest first
  1990. for (var index = this._children.length - 1; index >= 0; index--) {
  1991. var child = this._children[index];
  1992. if (child._processPicking(x, y, type, buttonIndex)) {
  1993. return true;
  1994. }
  1995. }
  1996. return this._processObservables(type, x, y, buttonIndex);
  1997. };
  1998. Container.prototype._clipForChildren = function (context) {
  1999. // DO nothing
  2000. };
  2001. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  2002. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2003. this._measureForChildren.copyFrom(this._currentMeasure);
  2004. };
  2005. Container.prototype.dispose = function () {
  2006. _super.prototype.dispose.call(this);
  2007. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2008. var control = _a[_i];
  2009. control.dispose();
  2010. }
  2011. };
  2012. return Container;
  2013. }(GUI.Control));
  2014. GUI.Container = Container;
  2015. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2016. })(BABYLON || (BABYLON = {}));
  2017. //# sourceMappingURL=container.js.map
  2018. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2019. var BABYLON;
  2020. (function (BABYLON) {
  2021. var GUI;
  2022. (function (GUI) {
  2023. var StackPanel = /** @class */ (function (_super) {
  2024. __extends(StackPanel, _super);
  2025. function StackPanel(name) {
  2026. var _this = _super.call(this, name) || this;
  2027. _this.name = name;
  2028. _this._isVertical = true;
  2029. _this._manualWidth = false;
  2030. _this._manualHeight = false;
  2031. _this._doNotTrackManualChanges = false;
  2032. _this._tempMeasureStore = GUI.Measure.Empty();
  2033. return _this;
  2034. }
  2035. Object.defineProperty(StackPanel.prototype, "isVertical", {
  2036. get: function () {
  2037. return this._isVertical;
  2038. },
  2039. set: function (value) {
  2040. if (this._isVertical === value) {
  2041. return;
  2042. }
  2043. this._isVertical = value;
  2044. this._markAsDirty();
  2045. },
  2046. enumerable: true,
  2047. configurable: true
  2048. });
  2049. Object.defineProperty(StackPanel.prototype, "width", {
  2050. get: function () {
  2051. return this._width.toString(this._host);
  2052. },
  2053. set: function (value) {
  2054. if (!this._doNotTrackManualChanges) {
  2055. this._manualWidth = true;
  2056. }
  2057. if (this._width.toString(this._host) === value) {
  2058. return;
  2059. }
  2060. if (this._width.fromString(value)) {
  2061. this._markAsDirty();
  2062. }
  2063. },
  2064. enumerable: true,
  2065. configurable: true
  2066. });
  2067. Object.defineProperty(StackPanel.prototype, "height", {
  2068. get: function () {
  2069. return this._height.toString(this._host);
  2070. },
  2071. set: function (value) {
  2072. if (!this._doNotTrackManualChanges) {
  2073. this._manualHeight = true;
  2074. }
  2075. if (this._height.toString(this._host) === value) {
  2076. return;
  2077. }
  2078. if (this._height.fromString(value)) {
  2079. this._markAsDirty();
  2080. }
  2081. },
  2082. enumerable: true,
  2083. configurable: true
  2084. });
  2085. StackPanel.prototype._getTypeName = function () {
  2086. return "StackPanel";
  2087. };
  2088. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  2089. var stackWidth = 0;
  2090. var stackHeight = 0;
  2091. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2092. var child = _a[_i];
  2093. this._tempMeasureStore.copyFrom(child._currentMeasure);
  2094. child._currentMeasure.copyFrom(parentMeasure);
  2095. child._measure();
  2096. if (this._isVertical) {
  2097. child.top = stackHeight + "px";
  2098. if (!child._top.ignoreAdaptiveScaling) {
  2099. child._markAsDirty();
  2100. }
  2101. child._top.ignoreAdaptiveScaling = true;
  2102. stackHeight += child._currentMeasure.height;
  2103. if (child._currentMeasure.width > stackWidth) {
  2104. stackWidth = child._currentMeasure.width;
  2105. }
  2106. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2107. }
  2108. else {
  2109. child.left = stackWidth + "px";
  2110. if (!child._left.ignoreAdaptiveScaling) {
  2111. child._markAsDirty();
  2112. }
  2113. child._left.ignoreAdaptiveScaling = true;
  2114. stackWidth += child._currentMeasure.width;
  2115. if (child._currentMeasure.height > stackHeight) {
  2116. stackHeight = child._currentMeasure.height;
  2117. }
  2118. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2119. }
  2120. child._currentMeasure.copyFrom(this._tempMeasureStore);
  2121. }
  2122. this._doNotTrackManualChanges = true;
  2123. // Let stack panel width and height default to stackHeight and stackWidth if dimensions are not specified.
  2124. // User can now define their own height and width for stack panel.
  2125. var panelWidthChanged = false;
  2126. var panelHeightChanged = false;
  2127. var previousHeight = this.height;
  2128. var previousWidth = this.width;
  2129. if (!this._manualHeight) {
  2130. // do not specify height if strictly defined by user
  2131. this.height = stackHeight + "px";
  2132. }
  2133. if (!this._manualWidth) {
  2134. // do not specify width if strictly defined by user
  2135. this.width = stackWidth + "px";
  2136. }
  2137. panelWidthChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  2138. panelHeightChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  2139. if (panelHeightChanged) {
  2140. this._height.ignoreAdaptiveScaling = true;
  2141. }
  2142. if (panelWidthChanged) {
  2143. this._width.ignoreAdaptiveScaling = true;
  2144. }
  2145. this._doNotTrackManualChanges = false;
  2146. if (panelWidthChanged || panelHeightChanged) {
  2147. this._markAllAsDirty();
  2148. }
  2149. _super.prototype._preMeasure.call(this, parentMeasure, context);
  2150. };
  2151. return StackPanel;
  2152. }(GUI.Container));
  2153. GUI.StackPanel = StackPanel;
  2154. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2155. })(BABYLON || (BABYLON = {}));
  2156. //# sourceMappingURL=stackPanel.js.map
  2157. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2158. var BABYLON;
  2159. (function (BABYLON) {
  2160. var GUI;
  2161. (function (GUI) {
  2162. var Rectangle = /** @class */ (function (_super) {
  2163. __extends(Rectangle, _super);
  2164. function Rectangle(name) {
  2165. var _this = _super.call(this, name) || this;
  2166. _this.name = name;
  2167. _this._thickness = 1;
  2168. _this._cornerRadius = 0;
  2169. return _this;
  2170. }
  2171. Object.defineProperty(Rectangle.prototype, "thickness", {
  2172. get: function () {
  2173. return this._thickness;
  2174. },
  2175. set: function (value) {
  2176. if (this._thickness === value) {
  2177. return;
  2178. }
  2179. this._thickness = value;
  2180. this._markAsDirty();
  2181. },
  2182. enumerable: true,
  2183. configurable: true
  2184. });
  2185. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  2186. get: function () {
  2187. return this._cornerRadius;
  2188. },
  2189. set: function (value) {
  2190. if (value < 0) {
  2191. value = 0;
  2192. }
  2193. if (this._cornerRadius === value) {
  2194. return;
  2195. }
  2196. this._cornerRadius = value;
  2197. this._markAsDirty();
  2198. },
  2199. enumerable: true,
  2200. configurable: true
  2201. });
  2202. Rectangle.prototype._getTypeName = function () {
  2203. return "Rectangle";
  2204. };
  2205. Rectangle.prototype._localDraw = function (context) {
  2206. context.save();
  2207. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2208. context.shadowColor = this.shadowColor;
  2209. context.shadowBlur = this.shadowBlur;
  2210. context.shadowOffsetX = this.shadowOffsetX;
  2211. context.shadowOffsetY = this.shadowOffsetY;
  2212. }
  2213. if (this._background) {
  2214. context.fillStyle = this._background;
  2215. if (this._cornerRadius) {
  2216. this._drawRoundedRect(context, this._thickness / 2);
  2217. context.fill();
  2218. }
  2219. else {
  2220. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2221. }
  2222. }
  2223. if (this._thickness) {
  2224. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2225. context.shadowBlur = 0;
  2226. context.shadowOffsetX = 0;
  2227. context.shadowOffsetY = 0;
  2228. }
  2229. if (this.color) {
  2230. context.strokeStyle = this.color;
  2231. }
  2232. context.lineWidth = this._thickness;
  2233. if (this._cornerRadius) {
  2234. this._drawRoundedRect(context, this._thickness / 2);
  2235. context.stroke();
  2236. }
  2237. else {
  2238. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  2239. }
  2240. }
  2241. context.restore();
  2242. };
  2243. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  2244. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2245. this._measureForChildren.width -= 2 * this._thickness;
  2246. this._measureForChildren.height -= 2 * this._thickness;
  2247. this._measureForChildren.left += this._thickness;
  2248. this._measureForChildren.top += this._thickness;
  2249. };
  2250. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  2251. if (offset === void 0) { offset = 0; }
  2252. var x = this._currentMeasure.left + offset;
  2253. var y = this._currentMeasure.top + offset;
  2254. var width = this._currentMeasure.width - offset * 2;
  2255. var height = this._currentMeasure.height - offset * 2;
  2256. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  2257. context.beginPath();
  2258. context.moveTo(x + radius, y);
  2259. context.lineTo(x + width - radius, y);
  2260. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  2261. context.lineTo(x + width, y + height - radius);
  2262. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  2263. context.lineTo(x + radius, y + height);
  2264. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  2265. context.lineTo(x, y + radius);
  2266. context.quadraticCurveTo(x, y, x + radius, y);
  2267. context.closePath();
  2268. };
  2269. Rectangle.prototype._clipForChildren = function (context) {
  2270. if (this._cornerRadius) {
  2271. this._drawRoundedRect(context, this._thickness);
  2272. context.clip();
  2273. }
  2274. };
  2275. return Rectangle;
  2276. }(GUI.Container));
  2277. GUI.Rectangle = Rectangle;
  2278. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2279. })(BABYLON || (BABYLON = {}));
  2280. //# sourceMappingURL=rectangle.js.map
  2281. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2282. var BABYLON;
  2283. (function (BABYLON) {
  2284. var GUI;
  2285. (function (GUI) {
  2286. var Ellipse = /** @class */ (function (_super) {
  2287. __extends(Ellipse, _super);
  2288. function Ellipse(name) {
  2289. var _this = _super.call(this, name) || this;
  2290. _this.name = name;
  2291. _this._thickness = 1;
  2292. return _this;
  2293. }
  2294. Object.defineProperty(Ellipse.prototype, "thickness", {
  2295. get: function () {
  2296. return this._thickness;
  2297. },
  2298. set: function (value) {
  2299. if (this._thickness === value) {
  2300. return;
  2301. }
  2302. this._thickness = value;
  2303. this._markAsDirty();
  2304. },
  2305. enumerable: true,
  2306. configurable: true
  2307. });
  2308. Ellipse.prototype._getTypeName = function () {
  2309. return "Ellipse";
  2310. };
  2311. Ellipse.prototype._localDraw = function (context) {
  2312. context.save();
  2313. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2314. context.shadowColor = this.shadowColor;
  2315. context.shadowBlur = this.shadowBlur;
  2316. context.shadowOffsetX = this.shadowOffsetX;
  2317. context.shadowOffsetY = this.shadowOffsetY;
  2318. }
  2319. GUI.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2 - this._thickness / 2, this._currentMeasure.height / 2 - this._thickness / 2, context);
  2320. if (this._background) {
  2321. context.fillStyle = this._background;
  2322. context.fill();
  2323. }
  2324. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2325. context.shadowBlur = 0;
  2326. context.shadowOffsetX = 0;
  2327. context.shadowOffsetY = 0;
  2328. }
  2329. if (this._thickness) {
  2330. if (this.color) {
  2331. context.strokeStyle = this.color;
  2332. }
  2333. context.lineWidth = this._thickness;
  2334. context.stroke();
  2335. }
  2336. context.restore();
  2337. };
  2338. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  2339. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2340. this._measureForChildren.width -= 2 * this._thickness;
  2341. this._measureForChildren.height -= 2 * this._thickness;
  2342. this._measureForChildren.left += this._thickness;
  2343. this._measureForChildren.top += this._thickness;
  2344. };
  2345. Ellipse.prototype._clipForChildren = function (context) {
  2346. GUI.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2, this._currentMeasure.height / 2, context);
  2347. context.clip();
  2348. };
  2349. return Ellipse;
  2350. }(GUI.Container));
  2351. GUI.Ellipse = Ellipse;
  2352. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2353. })(BABYLON || (BABYLON = {}));
  2354. //# sourceMappingURL=ellipse.js.map
  2355. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2356. var BABYLON;
  2357. (function (BABYLON) {
  2358. var GUI;
  2359. (function (GUI) {
  2360. var Line = /** @class */ (function (_super) {
  2361. __extends(Line, _super);
  2362. function Line(name) {
  2363. var _this = _super.call(this, name) || this;
  2364. _this.name = name;
  2365. _this._lineWidth = 1;
  2366. _this._x1 = new GUI.ValueAndUnit(0);
  2367. _this._y1 = new GUI.ValueAndUnit(0);
  2368. _this._x2 = new GUI.ValueAndUnit(0);
  2369. _this._y2 = new GUI.ValueAndUnit(0);
  2370. _this._dash = new Array();
  2371. _this.isHitTestVisible = false;
  2372. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2373. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2374. return _this;
  2375. }
  2376. Object.defineProperty(Line.prototype, "dash", {
  2377. get: function () {
  2378. return this._dash;
  2379. },
  2380. set: function (value) {
  2381. if (this._dash === value) {
  2382. return;
  2383. }
  2384. this._dash = value;
  2385. this._markAsDirty();
  2386. },
  2387. enumerable: true,
  2388. configurable: true
  2389. });
  2390. Object.defineProperty(Line.prototype, "connectedControl", {
  2391. get: function () {
  2392. return this._connectedControl;
  2393. },
  2394. set: function (value) {
  2395. var _this = this;
  2396. if (this._connectedControl === value) {
  2397. return;
  2398. }
  2399. if (this._connectedControlDirtyObserver && this._connectedControl) {
  2400. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  2401. this._connectedControlDirtyObserver = null;
  2402. }
  2403. if (value) {
  2404. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  2405. }
  2406. this._connectedControl = value;
  2407. this._markAsDirty();
  2408. },
  2409. enumerable: true,
  2410. configurable: true
  2411. });
  2412. Object.defineProperty(Line.prototype, "x1", {
  2413. get: function () {
  2414. return this._x1.toString(this._host);
  2415. },
  2416. set: function (value) {
  2417. if (this._x1.toString(this._host) === value) {
  2418. return;
  2419. }
  2420. if (this._x1.fromString(value)) {
  2421. this._markAsDirty();
  2422. }
  2423. },
  2424. enumerable: true,
  2425. configurable: true
  2426. });
  2427. Object.defineProperty(Line.prototype, "y1", {
  2428. get: function () {
  2429. return this._y1.toString(this._host);
  2430. },
  2431. set: function (value) {
  2432. if (this._y1.toString(this._host) === value) {
  2433. return;
  2434. }
  2435. if (this._y1.fromString(value)) {
  2436. this._markAsDirty();
  2437. }
  2438. },
  2439. enumerable: true,
  2440. configurable: true
  2441. });
  2442. Object.defineProperty(Line.prototype, "x2", {
  2443. get: function () {
  2444. return this._x2.toString(this._host);
  2445. },
  2446. set: function (value) {
  2447. if (this._x2.toString(this._host) === value) {
  2448. return;
  2449. }
  2450. if (this._x2.fromString(value)) {
  2451. this._markAsDirty();
  2452. }
  2453. },
  2454. enumerable: true,
  2455. configurable: true
  2456. });
  2457. Object.defineProperty(Line.prototype, "y2", {
  2458. get: function () {
  2459. return this._y2.toString(this._host);
  2460. },
  2461. set: function (value) {
  2462. if (this._y2.toString(this._host) === value) {
  2463. return;
  2464. }
  2465. if (this._y2.fromString(value)) {
  2466. this._markAsDirty();
  2467. }
  2468. },
  2469. enumerable: true,
  2470. configurable: true
  2471. });
  2472. Object.defineProperty(Line.prototype, "lineWidth", {
  2473. get: function () {
  2474. return this._lineWidth;
  2475. },
  2476. set: function (value) {
  2477. if (this._lineWidth === value) {
  2478. return;
  2479. }
  2480. this._lineWidth = value;
  2481. this._markAsDirty();
  2482. },
  2483. enumerable: true,
  2484. configurable: true
  2485. });
  2486. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  2487. set: function (value) {
  2488. return;
  2489. },
  2490. enumerable: true,
  2491. configurable: true
  2492. });
  2493. Object.defineProperty(Line.prototype, "verticalAlignment", {
  2494. set: function (value) {
  2495. return;
  2496. },
  2497. enumerable: true,
  2498. configurable: true
  2499. });
  2500. Object.defineProperty(Line.prototype, "_effectiveX2", {
  2501. get: function () {
  2502. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  2503. },
  2504. enumerable: true,
  2505. configurable: true
  2506. });
  2507. Object.defineProperty(Line.prototype, "_effectiveY2", {
  2508. get: function () {
  2509. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  2510. },
  2511. enumerable: true,
  2512. configurable: true
  2513. });
  2514. Line.prototype._getTypeName = function () {
  2515. return "Line";
  2516. };
  2517. Line.prototype._draw = function (parentMeasure, context) {
  2518. context.save();
  2519. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2520. context.shadowColor = this.shadowColor;
  2521. context.shadowBlur = this.shadowBlur;
  2522. context.shadowOffsetX = this.shadowOffsetX;
  2523. context.shadowOffsetY = this.shadowOffsetY;
  2524. }
  2525. this._applyStates(context);
  2526. if (this._processMeasures(parentMeasure, context)) {
  2527. context.strokeStyle = this.color;
  2528. context.lineWidth = this._lineWidth;
  2529. context.setLineDash(this._dash);
  2530. context.beginPath();
  2531. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  2532. context.lineTo(this._effectiveX2, this._effectiveY2);
  2533. context.stroke();
  2534. }
  2535. context.restore();
  2536. };
  2537. Line.prototype._measure = function () {
  2538. // Width / Height
  2539. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  2540. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  2541. };
  2542. Line.prototype._computeAlignment = function (parentMeasure, context) {
  2543. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  2544. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  2545. };
  2546. Line.prototype._moveToProjectedPosition = function (projectedPosition) {
  2547. this.x1 = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  2548. this.y1 = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  2549. this._x1.ignoreAdaptiveScaling = true;
  2550. this._y1.ignoreAdaptiveScaling = true;
  2551. };
  2552. return Line;
  2553. }(GUI.Control));
  2554. GUI.Line = Line;
  2555. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2556. })(BABYLON || (BABYLON = {}));
  2557. //# sourceMappingURL=line.js.map
  2558. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2559. var BABYLON;
  2560. (function (BABYLON) {
  2561. var GUI;
  2562. (function (GUI) {
  2563. var Slider = /** @class */ (function (_super) {
  2564. __extends(Slider, _super);
  2565. function Slider(name) {
  2566. var _this = _super.call(this, name) || this;
  2567. _this.name = name;
  2568. _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2569. _this._minimum = 0;
  2570. _this._maximum = 100;
  2571. _this._value = 50;
  2572. _this._background = "black";
  2573. _this._borderColor = "white";
  2574. _this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2575. _this._isThumbCircle = false;
  2576. _this.onValueChangedObservable = new BABYLON.Observable();
  2577. // Events
  2578. _this._pointerIsDown = false;
  2579. _this.isPointerBlocker = true;
  2580. return _this;
  2581. }
  2582. Object.defineProperty(Slider.prototype, "borderColor", {
  2583. get: function () {
  2584. return this._borderColor;
  2585. },
  2586. set: function (value) {
  2587. if (this._borderColor === value) {
  2588. return;
  2589. }
  2590. this._borderColor = value;
  2591. this._markAsDirty();
  2592. },
  2593. enumerable: true,
  2594. configurable: true
  2595. });
  2596. Object.defineProperty(Slider.prototype, "background", {
  2597. get: function () {
  2598. return this._background;
  2599. },
  2600. set: function (value) {
  2601. if (this._background === value) {
  2602. return;
  2603. }
  2604. this._background = value;
  2605. this._markAsDirty();
  2606. },
  2607. enumerable: true,
  2608. configurable: true
  2609. });
  2610. Object.defineProperty(Slider.prototype, "barOffset", {
  2611. get: function () {
  2612. return this._barOffset.toString(this._host);
  2613. },
  2614. set: function (value) {
  2615. if (this._barOffset.toString(this._host) === value) {
  2616. return;
  2617. }
  2618. if (this._barOffset.fromString(value)) {
  2619. this._markAsDirty();
  2620. }
  2621. },
  2622. enumerable: true,
  2623. configurable: true
  2624. });
  2625. Object.defineProperty(Slider.prototype, "barOffsetInPixels", {
  2626. get: function () {
  2627. return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2628. },
  2629. enumerable: true,
  2630. configurable: true
  2631. });
  2632. Object.defineProperty(Slider.prototype, "thumbWidth", {
  2633. get: function () {
  2634. return this._thumbWidth.toString(this._host);
  2635. },
  2636. set: function (value) {
  2637. if (this._thumbWidth.toString(this._host) === value) {
  2638. return;
  2639. }
  2640. if (this._thumbWidth.fromString(value)) {
  2641. this._markAsDirty();
  2642. }
  2643. },
  2644. enumerable: true,
  2645. configurable: true
  2646. });
  2647. Object.defineProperty(Slider.prototype, "thumbWidthInPixels", {
  2648. get: function () {
  2649. return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2650. },
  2651. enumerable: true,
  2652. configurable: true
  2653. });
  2654. Object.defineProperty(Slider.prototype, "minimum", {
  2655. get: function () {
  2656. return this._minimum;
  2657. },
  2658. set: function (value) {
  2659. if (this._minimum === value) {
  2660. return;
  2661. }
  2662. this._minimum = value;
  2663. this._markAsDirty();
  2664. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2665. },
  2666. enumerable: true,
  2667. configurable: true
  2668. });
  2669. Object.defineProperty(Slider.prototype, "maximum", {
  2670. get: function () {
  2671. return this._maximum;
  2672. },
  2673. set: function (value) {
  2674. if (this._maximum === value) {
  2675. return;
  2676. }
  2677. this._maximum = value;
  2678. this._markAsDirty();
  2679. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2680. },
  2681. enumerable: true,
  2682. configurable: true
  2683. });
  2684. Object.defineProperty(Slider.prototype, "value", {
  2685. get: function () {
  2686. return this._value;
  2687. },
  2688. set: function (value) {
  2689. value = Math.max(Math.min(value, this._maximum), this._minimum);
  2690. if (this._value === value) {
  2691. return;
  2692. }
  2693. this._value = value;
  2694. this._markAsDirty();
  2695. this.onValueChangedObservable.notifyObservers(this._value);
  2696. },
  2697. enumerable: true,
  2698. configurable: true
  2699. });
  2700. Object.defineProperty(Slider.prototype, "isThumbCircle", {
  2701. get: function () {
  2702. return this._isThumbCircle;
  2703. },
  2704. set: function (value) {
  2705. if (this._isThumbCircle === value) {
  2706. return;
  2707. }
  2708. this._isThumbCircle = value;
  2709. this._markAsDirty();
  2710. },
  2711. enumerable: true,
  2712. configurable: true
  2713. });
  2714. Slider.prototype._getTypeName = function () {
  2715. return "Slider";
  2716. };
  2717. Slider.prototype._draw = function (parentMeasure, context) {
  2718. context.save();
  2719. this._applyStates(context);
  2720. if (this._processMeasures(parentMeasure, context)) {
  2721. // Main bar
  2722. var effectiveThumbWidth;
  2723. var effectiveBarOffset;
  2724. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2725. context.shadowColor = this.shadowColor;
  2726. context.shadowBlur = this.shadowBlur;
  2727. context.shadowOffsetX = this.shadowOffsetX;
  2728. context.shadowOffsetY = this.shadowOffsetY;
  2729. }
  2730. if (this._thumbWidth.isPixel) {
  2731. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.height);
  2732. }
  2733. else {
  2734. effectiveThumbWidth = this._currentMeasure.height * this._thumbWidth.getValue(this._host);
  2735. }
  2736. if (this._barOffset.isPixel) {
  2737. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  2738. }
  2739. else {
  2740. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  2741. }
  2742. var left = this._currentMeasure.left + effectiveThumbWidth / 2;
  2743. var width = this._currentMeasure.width - effectiveThumbWidth;
  2744. var thumbPosition = (this._value - this._minimum) / (this._maximum - this._minimum) * width;
  2745. // Bar
  2746. context.fillStyle = this._background;
  2747. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  2748. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2749. context.shadowBlur = 0;
  2750. context.shadowOffsetX = 0;
  2751. context.shadowOffsetY = 0;
  2752. }
  2753. context.fillStyle = this.color;
  2754. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  2755. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2756. context.shadowColor = this.shadowColor;
  2757. context.shadowBlur = this.shadowBlur;
  2758. context.shadowOffsetX = this.shadowOffsetX;
  2759. context.shadowOffsetY = this.shadowOffsetY;
  2760. }
  2761. // Thumb
  2762. if (this._isThumbCircle) {
  2763. context.beginPath();
  2764. context.arc(left + thumbPosition, this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
  2765. context.fill();
  2766. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2767. context.shadowBlur = 0;
  2768. context.shadowOffsetX = 0;
  2769. context.shadowOffsetY = 0;
  2770. }
  2771. context.strokeStyle = this._borderColor;
  2772. context.stroke();
  2773. }
  2774. else {
  2775. context.fillRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2776. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2777. context.shadowBlur = 0;
  2778. context.shadowOffsetX = 0;
  2779. context.shadowOffsetY = 0;
  2780. }
  2781. context.strokeStyle = this._borderColor;
  2782. context.strokeRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2783. }
  2784. }
  2785. context.restore();
  2786. };
  2787. Slider.prototype._updateValueFromPointer = function (x) {
  2788. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  2789. };
  2790. Slider.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  2791. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  2792. return false;
  2793. }
  2794. this._pointerIsDown = true;
  2795. this._updateValueFromPointer(coordinates.x);
  2796. this._host._capturingControl = this;
  2797. return true;
  2798. };
  2799. Slider.prototype._onPointerMove = function (target, coordinates) {
  2800. if (this._pointerIsDown) {
  2801. this._updateValueFromPointer(coordinates.x);
  2802. }
  2803. _super.prototype._onPointerMove.call(this, target, coordinates);
  2804. };
  2805. Slider.prototype._onPointerUp = function (target, coordinates, buttonIndex) {
  2806. this._pointerIsDown = false;
  2807. this._host._capturingControl = null;
  2808. _super.prototype._onPointerUp.call(this, target, coordinates, buttonIndex);
  2809. };
  2810. return Slider;
  2811. }(GUI.Control));
  2812. GUI.Slider = Slider;
  2813. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2814. })(BABYLON || (BABYLON = {}));
  2815. //# sourceMappingURL=slider.js.map
  2816. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2817. var BABYLON;
  2818. (function (BABYLON) {
  2819. var GUI;
  2820. (function (GUI) {
  2821. var Checkbox = /** @class */ (function (_super) {
  2822. __extends(Checkbox, _super);
  2823. function Checkbox(name) {
  2824. var _this = _super.call(this, name) || this;
  2825. _this.name = name;
  2826. _this._isChecked = false;
  2827. _this._background = "black";
  2828. _this._checkSizeRatio = 0.8;
  2829. _this._thickness = 1;
  2830. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  2831. _this.isPointerBlocker = true;
  2832. return _this;
  2833. }
  2834. Object.defineProperty(Checkbox.prototype, "thickness", {
  2835. get: function () {
  2836. return this._thickness;
  2837. },
  2838. set: function (value) {
  2839. if (this._thickness === value) {
  2840. return;
  2841. }
  2842. this._thickness = value;
  2843. this._markAsDirty();
  2844. },
  2845. enumerable: true,
  2846. configurable: true
  2847. });
  2848. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  2849. get: function () {
  2850. return this._checkSizeRatio;
  2851. },
  2852. set: function (value) {
  2853. value = Math.max(Math.min(1, value), 0);
  2854. if (this._checkSizeRatio === value) {
  2855. return;
  2856. }
  2857. this._checkSizeRatio = value;
  2858. this._markAsDirty();
  2859. },
  2860. enumerable: true,
  2861. configurable: true
  2862. });
  2863. Object.defineProperty(Checkbox.prototype, "background", {
  2864. get: function () {
  2865. return this._background;
  2866. },
  2867. set: function (value) {
  2868. if (this._background === value) {
  2869. return;
  2870. }
  2871. this._background = value;
  2872. this._markAsDirty();
  2873. },
  2874. enumerable: true,
  2875. configurable: true
  2876. });
  2877. Object.defineProperty(Checkbox.prototype, "isChecked", {
  2878. get: function () {
  2879. return this._isChecked;
  2880. },
  2881. set: function (value) {
  2882. if (this._isChecked === value) {
  2883. return;
  2884. }
  2885. this._isChecked = value;
  2886. this._markAsDirty();
  2887. this.onIsCheckedChangedObservable.notifyObservers(value);
  2888. },
  2889. enumerable: true,
  2890. configurable: true
  2891. });
  2892. Checkbox.prototype._getTypeName = function () {
  2893. return "CheckBox";
  2894. };
  2895. Checkbox.prototype._draw = function (parentMeasure, context) {
  2896. context.save();
  2897. this._applyStates(context);
  2898. if (this._processMeasures(parentMeasure, context)) {
  2899. var actualWidth = this._currentMeasure.width - this._thickness;
  2900. var actualHeight = this._currentMeasure.height - this._thickness;
  2901. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2902. context.shadowColor = this.shadowColor;
  2903. context.shadowBlur = this.shadowBlur;
  2904. context.shadowOffsetX = this.shadowOffsetX;
  2905. context.shadowOffsetY = this.shadowOffsetY;
  2906. }
  2907. context.fillStyle = this._background;
  2908. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2909. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2910. context.shadowBlur = 0;
  2911. context.shadowOffsetX = 0;
  2912. context.shadowOffsetY = 0;
  2913. }
  2914. if (this._isChecked) {
  2915. context.fillStyle = this.color;
  2916. var offsetWidth = actualWidth * this._checkSizeRatio;
  2917. var offseHeight = actualHeight * this._checkSizeRatio;
  2918. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  2919. }
  2920. context.strokeStyle = this.color;
  2921. context.lineWidth = this._thickness;
  2922. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2923. }
  2924. context.restore();
  2925. };
  2926. // Events
  2927. Checkbox.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  2928. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  2929. return false;
  2930. }
  2931. this.isChecked = !this.isChecked;
  2932. return true;
  2933. };
  2934. return Checkbox;
  2935. }(GUI.Control));
  2936. GUI.Checkbox = Checkbox;
  2937. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2938. })(BABYLON || (BABYLON = {}));
  2939. //# sourceMappingURL=checkBox.js.map
  2940. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2941. var BABYLON;
  2942. (function (BABYLON) {
  2943. var GUI;
  2944. (function (GUI) {
  2945. var RadioButton = /** @class */ (function (_super) {
  2946. __extends(RadioButton, _super);
  2947. function RadioButton(name) {
  2948. var _this = _super.call(this, name) || this;
  2949. _this.name = name;
  2950. _this._isChecked = false;
  2951. _this._background = "black";
  2952. _this._checkSizeRatio = 0.8;
  2953. _this._thickness = 1;
  2954. _this.group = "";
  2955. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  2956. _this.isPointerBlocker = true;
  2957. return _this;
  2958. }
  2959. Object.defineProperty(RadioButton.prototype, "thickness", {
  2960. get: function () {
  2961. return this._thickness;
  2962. },
  2963. set: function (value) {
  2964. if (this._thickness === value) {
  2965. return;
  2966. }
  2967. this._thickness = value;
  2968. this._markAsDirty();
  2969. },
  2970. enumerable: true,
  2971. configurable: true
  2972. });
  2973. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  2974. get: function () {
  2975. return this._checkSizeRatio;
  2976. },
  2977. set: function (value) {
  2978. value = Math.max(Math.min(1, value), 0);
  2979. if (this._checkSizeRatio === value) {
  2980. return;
  2981. }
  2982. this._checkSizeRatio = value;
  2983. this._markAsDirty();
  2984. },
  2985. enumerable: true,
  2986. configurable: true
  2987. });
  2988. Object.defineProperty(RadioButton.prototype, "background", {
  2989. get: function () {
  2990. return this._background;
  2991. },
  2992. set: function (value) {
  2993. if (this._background === value) {
  2994. return;
  2995. }
  2996. this._background = value;
  2997. this._markAsDirty();
  2998. },
  2999. enumerable: true,
  3000. configurable: true
  3001. });
  3002. Object.defineProperty(RadioButton.prototype, "isChecked", {
  3003. get: function () {
  3004. return this._isChecked;
  3005. },
  3006. set: function (value) {
  3007. var _this = this;
  3008. if (this._isChecked === value) {
  3009. return;
  3010. }
  3011. this._isChecked = value;
  3012. this._markAsDirty();
  3013. this.onIsCheckedChangedObservable.notifyObservers(value);
  3014. if (this._isChecked) {
  3015. // Update all controls from same group
  3016. this._host.executeOnAllControls(function (control) {
  3017. if (control === _this) {
  3018. return;
  3019. }
  3020. if (control.group === undefined) {
  3021. return;
  3022. }
  3023. var childRadio = control;
  3024. if (childRadio.group === _this.group) {
  3025. childRadio.isChecked = false;
  3026. }
  3027. });
  3028. }
  3029. },
  3030. enumerable: true,
  3031. configurable: true
  3032. });
  3033. RadioButton.prototype._getTypeName = function () {
  3034. return "RadioButton";
  3035. };
  3036. RadioButton.prototype._draw = function (parentMeasure, context) {
  3037. context.save();
  3038. this._applyStates(context);
  3039. if (this._processMeasures(parentMeasure, context)) {
  3040. var actualWidth = this._currentMeasure.width - this._thickness;
  3041. var actualHeight = this._currentMeasure.height - this._thickness;
  3042. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3043. context.shadowColor = this.shadowColor;
  3044. context.shadowBlur = this.shadowBlur;
  3045. context.shadowOffsetX = this.shadowOffsetX;
  3046. context.shadowOffsetY = this.shadowOffsetY;
  3047. }
  3048. // Outer
  3049. GUI.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2 - this._thickness / 2, this._currentMeasure.height / 2 - this._thickness / 2, context);
  3050. context.fillStyle = this._background;
  3051. context.fill();
  3052. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3053. context.shadowBlur = 0;
  3054. context.shadowOffsetX = 0;
  3055. context.shadowOffsetY = 0;
  3056. }
  3057. context.strokeStyle = this.color;
  3058. context.lineWidth = this._thickness;
  3059. context.stroke();
  3060. // Inner
  3061. if (this._isChecked) {
  3062. context.fillStyle = this.color;
  3063. var offsetWidth = actualWidth * this._checkSizeRatio;
  3064. var offseHeight = actualHeight * this._checkSizeRatio;
  3065. GUI.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, offsetWidth / 2 - this._thickness / 2, offseHeight / 2 - this._thickness / 2, context);
  3066. context.fill();
  3067. }
  3068. }
  3069. context.restore();
  3070. };
  3071. // Events
  3072. RadioButton.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  3073. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  3074. return false;
  3075. }
  3076. this.isChecked = !this.isChecked;
  3077. return true;
  3078. };
  3079. return RadioButton;
  3080. }(GUI.Control));
  3081. GUI.RadioButton = RadioButton;
  3082. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3083. })(BABYLON || (BABYLON = {}));
  3084. //# sourceMappingURL=radioButton.js.map
  3085. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3086. var BABYLON;
  3087. (function (BABYLON) {
  3088. var GUI;
  3089. (function (GUI) {
  3090. var TextBlock = /** @class */ (function (_super) {
  3091. __extends(TextBlock, _super);
  3092. function TextBlock(name, text) {
  3093. if (text === void 0) { text = ""; }
  3094. var _this = _super.call(this, name) || this;
  3095. _this.name = name;
  3096. _this._text = "";
  3097. _this._textWrapping = false;
  3098. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3099. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  3100. _this._resizeToFit = false;
  3101. /**
  3102. * An event triggered after the text is changed
  3103. * @type {BABYLON.Observable}
  3104. */
  3105. _this.onTextChangedObservable = new BABYLON.Observable();
  3106. _this.text = text;
  3107. return _this;
  3108. }
  3109. Object.defineProperty(TextBlock.prototype, "resizeToFit", {
  3110. get: function () {
  3111. return this._resizeToFit;
  3112. },
  3113. set: function (value) {
  3114. this._resizeToFit = value;
  3115. if (this._resizeToFit) {
  3116. this._width.ignoreAdaptiveScaling = true;
  3117. this._height.ignoreAdaptiveScaling = true;
  3118. }
  3119. },
  3120. enumerable: true,
  3121. configurable: true
  3122. });
  3123. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  3124. get: function () {
  3125. return this._textWrapping;
  3126. },
  3127. set: function (value) {
  3128. if (this._textWrapping === value) {
  3129. return;
  3130. }
  3131. this._textWrapping = value;
  3132. this._markAsDirty();
  3133. },
  3134. enumerable: true,
  3135. configurable: true
  3136. });
  3137. Object.defineProperty(TextBlock.prototype, "text", {
  3138. get: function () {
  3139. return this._text;
  3140. },
  3141. set: function (value) {
  3142. if (this._text === value) {
  3143. return;
  3144. }
  3145. this._text = value;
  3146. this._markAsDirty();
  3147. this.onTextChangedObservable.notifyObservers(this);
  3148. },
  3149. enumerable: true,
  3150. configurable: true
  3151. });
  3152. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  3153. get: function () {
  3154. return this._textHorizontalAlignment;
  3155. },
  3156. set: function (value) {
  3157. if (this._textHorizontalAlignment === value) {
  3158. return;
  3159. }
  3160. this._textHorizontalAlignment = value;
  3161. this._markAsDirty();
  3162. },
  3163. enumerable: true,
  3164. configurable: true
  3165. });
  3166. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  3167. get: function () {
  3168. return this._textVerticalAlignment;
  3169. },
  3170. set: function (value) {
  3171. if (this._textVerticalAlignment === value) {
  3172. return;
  3173. }
  3174. this._textVerticalAlignment = value;
  3175. this._markAsDirty();
  3176. },
  3177. enumerable: true,
  3178. configurable: true
  3179. });
  3180. TextBlock.prototype._getTypeName = function () {
  3181. return "TextBlock";
  3182. };
  3183. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  3184. var width = this._currentMeasure.width;
  3185. var x = 0;
  3186. switch (this._textHorizontalAlignment) {
  3187. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  3188. x = 0;
  3189. break;
  3190. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  3191. x = width - textWidth;
  3192. break;
  3193. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  3194. x = (width - textWidth) / 2;
  3195. break;
  3196. }
  3197. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3198. context.shadowColor = this.shadowColor;
  3199. context.shadowBlur = this.shadowBlur;
  3200. context.shadowOffsetX = this.shadowOffsetX;
  3201. context.shadowOffsetY = this.shadowOffsetY;
  3202. }
  3203. context.fillText(text, this._currentMeasure.left + x, y);
  3204. };
  3205. TextBlock.prototype._draw = function (parentMeasure, context) {
  3206. context.save();
  3207. this._applyStates(context);
  3208. if (this._processMeasures(parentMeasure, context)) {
  3209. // Render lines
  3210. this._renderLines(context);
  3211. }
  3212. context.restore();
  3213. };
  3214. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  3215. this._lines = [];
  3216. var _lines = this.text.split("\n");
  3217. if (this._textWrapping && !this._resizeToFit) {
  3218. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  3219. var _line = _lines_1[_i];
  3220. this._lines.push(this._parseLineWithTextWrapping(_line, context));
  3221. }
  3222. }
  3223. else {
  3224. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  3225. var _line = _lines_2[_a];
  3226. this._lines.push(this._parseLine(_line, context));
  3227. }
  3228. }
  3229. };
  3230. TextBlock.prototype._parseLine = function (line, context) {
  3231. if (line === void 0) { line = ''; }
  3232. return { text: line, width: context.measureText(line).width };
  3233. };
  3234. TextBlock.prototype._parseLineWithTextWrapping = function (line, context) {
  3235. if (line === void 0) { line = ''; }
  3236. var words = line.split(' ');
  3237. var width = this._currentMeasure.width;
  3238. var lineWidth = 0;
  3239. for (var n = 0; n < words.length; n++) {
  3240. var testLine = n > 0 ? line + " " + words[n] : words[0];
  3241. var metrics = context.measureText(testLine);
  3242. var testWidth = metrics.width;
  3243. if (testWidth > width && n > 0) {
  3244. this._lines.push({ text: line, width: lineWidth });
  3245. line = words[n];
  3246. lineWidth = context.measureText(line).width;
  3247. }
  3248. else {
  3249. lineWidth = testWidth;
  3250. line = testLine;
  3251. }
  3252. }
  3253. return { text: line, width: lineWidth };
  3254. };
  3255. TextBlock.prototype._renderLines = function (context) {
  3256. var height = this._currentMeasure.height;
  3257. if (!this._fontOffset) {
  3258. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  3259. }
  3260. var rootY = 0;
  3261. switch (this._textVerticalAlignment) {
  3262. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  3263. rootY = this._fontOffset.ascent;
  3264. break;
  3265. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  3266. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  3267. break;
  3268. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  3269. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  3270. break;
  3271. }
  3272. rootY += this._currentMeasure.top;
  3273. var maxLineWidth = 0;
  3274. for (var _i = 0, _a = this._lines; _i < _a.length; _i++) {
  3275. var line = _a[_i];
  3276. this._drawText(line.text, line.width, rootY, context);
  3277. rootY += this._fontOffset.height;
  3278. if (line.width > maxLineWidth)
  3279. maxLineWidth = line.width;
  3280. }
  3281. if (this._resizeToFit) {
  3282. this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
  3283. this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
  3284. }
  3285. };
  3286. TextBlock.prototype.dispose = function () {
  3287. _super.prototype.dispose.call(this);
  3288. this.onTextChangedObservable.clear();
  3289. };
  3290. return TextBlock;
  3291. }(GUI.Control));
  3292. GUI.TextBlock = TextBlock;
  3293. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3294. })(BABYLON || (BABYLON = {}));
  3295. //# sourceMappingURL=textBlock.js.map
  3296. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3297. var DOMImage = Image;
  3298. var BABYLON;
  3299. (function (BABYLON) {
  3300. var GUI;
  3301. (function (GUI) {
  3302. var Image = /** @class */ (function (_super) {
  3303. __extends(Image, _super);
  3304. function Image(name, url) {
  3305. if (url === void 0) { url = null; }
  3306. var _this = _super.call(this, name) || this;
  3307. _this.name = name;
  3308. _this._loaded = false;
  3309. _this._stretch = Image.STRETCH_FILL;
  3310. _this._autoScale = false;
  3311. _this._sourceLeft = 0;
  3312. _this._sourceTop = 0;
  3313. _this._sourceWidth = 0;
  3314. _this._sourceHeight = 0;
  3315. _this._cellWidth = 0;
  3316. _this._cellHeight = 0;
  3317. _this._cellId = -1;
  3318. _this.source = url;
  3319. return _this;
  3320. }
  3321. Object.defineProperty(Image.prototype, "sourceLeft", {
  3322. get: function () {
  3323. return this._sourceLeft;
  3324. },
  3325. set: function (value) {
  3326. if (this._sourceLeft === value) {
  3327. return;
  3328. }
  3329. this._sourceLeft = value;
  3330. this._markAsDirty();
  3331. },
  3332. enumerable: true,
  3333. configurable: true
  3334. });
  3335. Object.defineProperty(Image.prototype, "sourceTop", {
  3336. get: function () {
  3337. return this._sourceTop;
  3338. },
  3339. set: function (value) {
  3340. if (this._sourceTop === value) {
  3341. return;
  3342. }
  3343. this._sourceTop = value;
  3344. this._markAsDirty();
  3345. },
  3346. enumerable: true,
  3347. configurable: true
  3348. });
  3349. Object.defineProperty(Image.prototype, "sourceWidth", {
  3350. get: function () {
  3351. return this._sourceWidth;
  3352. },
  3353. set: function (value) {
  3354. if (this._sourceWidth === value) {
  3355. return;
  3356. }
  3357. this._sourceWidth = value;
  3358. this._markAsDirty();
  3359. },
  3360. enumerable: true,
  3361. configurable: true
  3362. });
  3363. Object.defineProperty(Image.prototype, "sourceHeight", {
  3364. get: function () {
  3365. return this._sourceHeight;
  3366. },
  3367. set: function (value) {
  3368. if (this._sourceHeight === value) {
  3369. return;
  3370. }
  3371. this._sourceHeight = value;
  3372. this._markAsDirty();
  3373. },
  3374. enumerable: true,
  3375. configurable: true
  3376. });
  3377. Object.defineProperty(Image.prototype, "autoScale", {
  3378. get: function () {
  3379. return this._autoScale;
  3380. },
  3381. set: function (value) {
  3382. if (this._autoScale === value) {
  3383. return;
  3384. }
  3385. this._autoScale = value;
  3386. if (value && this._loaded) {
  3387. this.synchronizeSizeWithContent();
  3388. }
  3389. },
  3390. enumerable: true,
  3391. configurable: true
  3392. });
  3393. Object.defineProperty(Image.prototype, "stretch", {
  3394. get: function () {
  3395. return this._stretch;
  3396. },
  3397. set: function (value) {
  3398. if (this._stretch === value) {
  3399. return;
  3400. }
  3401. this._stretch = value;
  3402. this._markAsDirty();
  3403. },
  3404. enumerable: true,
  3405. configurable: true
  3406. });
  3407. Object.defineProperty(Image.prototype, "domImage", {
  3408. get: function () {
  3409. return this._domImage;
  3410. },
  3411. set: function (value) {
  3412. var _this = this;
  3413. this._domImage = value;
  3414. this._loaded = false;
  3415. if (this._domImage.width) {
  3416. this._onImageLoaded();
  3417. }
  3418. else {
  3419. this._domImage.onload = function () {
  3420. _this._onImageLoaded();
  3421. };
  3422. }
  3423. },
  3424. enumerable: true,
  3425. configurable: true
  3426. });
  3427. Image.prototype._onImageLoaded = function () {
  3428. this._imageWidth = this._domImage.width;
  3429. this._imageHeight = this._domImage.height;
  3430. this._loaded = true;
  3431. if (this._autoScale) {
  3432. this.synchronizeSizeWithContent();
  3433. }
  3434. this._markAsDirty();
  3435. };
  3436. Object.defineProperty(Image.prototype, "source", {
  3437. set: function (value) {
  3438. var _this = this;
  3439. if (this._source === value) {
  3440. return;
  3441. }
  3442. this._loaded = false;
  3443. this._source = value;
  3444. this._domImage = new DOMImage();
  3445. this._domImage.onload = function () {
  3446. _this._onImageLoaded();
  3447. };
  3448. if (value) {
  3449. this._domImage.crossOrigin = "anonymous";
  3450. this._domImage.src = value;
  3451. }
  3452. },
  3453. enumerable: true,
  3454. configurable: true
  3455. });
  3456. Object.defineProperty(Image.prototype, "cellWidth", {
  3457. get: function () {
  3458. return this._cellWidth;
  3459. },
  3460. set: function (value) {
  3461. this._cellWidth = value;
  3462. },
  3463. enumerable: true,
  3464. configurable: true
  3465. });
  3466. Object.defineProperty(Image.prototype, "cellHeight", {
  3467. get: function () {
  3468. return this._cellHeight;
  3469. },
  3470. set: function (value) {
  3471. this._cellHeight = value;
  3472. },
  3473. enumerable: true,
  3474. configurable: true
  3475. });
  3476. Object.defineProperty(Image.prototype, "cellId", {
  3477. get: function () {
  3478. return this._cellId;
  3479. },
  3480. set: function (value) {
  3481. this._cellId = value;
  3482. },
  3483. enumerable: true,
  3484. configurable: true
  3485. });
  3486. Image.prototype._getTypeName = function () {
  3487. return "Image";
  3488. };
  3489. Image.prototype.synchronizeSizeWithContent = function () {
  3490. if (!this._loaded) {
  3491. return;
  3492. }
  3493. this.width = this._domImage.width + "px";
  3494. this.height = this._domImage.height + "px";
  3495. };
  3496. Image.prototype._draw = function (parentMeasure, context) {
  3497. context.save();
  3498. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3499. context.shadowColor = this.shadowColor;
  3500. context.shadowBlur = this.shadowBlur;
  3501. context.shadowOffsetX = this.shadowOffsetX;
  3502. context.shadowOffsetY = this.shadowOffsetY;
  3503. }
  3504. var x, y, width, height;
  3505. if (this.cellId == -1) {
  3506. x = this._sourceLeft;
  3507. y = this._sourceTop;
  3508. width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  3509. height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  3510. }
  3511. else {
  3512. var rowCount = this._domImage.naturalWidth / this.cellWidth;
  3513. var column = (this.cellId / rowCount) >> 0;
  3514. var row = this.cellId % rowCount;
  3515. x = this.cellWidth * row;
  3516. y = this.cellHeight * column;
  3517. width = this.cellWidth;
  3518. height = this.cellHeight;
  3519. }
  3520. this._applyStates(context);
  3521. if (this._processMeasures(parentMeasure, context)) {
  3522. if (this._loaded) {
  3523. switch (this._stretch) {
  3524. case Image.STRETCH_NONE:
  3525. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3526. break;
  3527. case Image.STRETCH_FILL:
  3528. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3529. break;
  3530. case Image.STRETCH_UNIFORM:
  3531. var hRatio = this._currentMeasure.width / width;
  3532. var vRatio = this._currentMeasure.height / height;
  3533. var ratio = Math.min(hRatio, vRatio);
  3534. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  3535. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  3536. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  3537. break;
  3538. case Image.STRETCH_EXTEND:
  3539. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3540. if (this._autoScale) {
  3541. this.synchronizeSizeWithContent();
  3542. }
  3543. if (this._root && this._root.parent) {
  3544. this._root.width = this.width;
  3545. this._root.height = this.height;
  3546. }
  3547. break;
  3548. }
  3549. }
  3550. }
  3551. context.restore();
  3552. };
  3553. Object.defineProperty(Image, "STRETCH_NONE", {
  3554. get: function () {
  3555. return Image._STRETCH_NONE;
  3556. },
  3557. enumerable: true,
  3558. configurable: true
  3559. });
  3560. Object.defineProperty(Image, "STRETCH_FILL", {
  3561. get: function () {
  3562. return Image._STRETCH_FILL;
  3563. },
  3564. enumerable: true,
  3565. configurable: true
  3566. });
  3567. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  3568. get: function () {
  3569. return Image._STRETCH_UNIFORM;
  3570. },
  3571. enumerable: true,
  3572. configurable: true
  3573. });
  3574. Object.defineProperty(Image, "STRETCH_EXTEND", {
  3575. get: function () {
  3576. return Image._STRETCH_EXTEND;
  3577. },
  3578. enumerable: true,
  3579. configurable: true
  3580. });
  3581. // Static
  3582. Image._STRETCH_NONE = 0;
  3583. Image._STRETCH_FILL = 1;
  3584. Image._STRETCH_UNIFORM = 2;
  3585. Image._STRETCH_EXTEND = 3;
  3586. return Image;
  3587. }(GUI.Control));
  3588. GUI.Image = Image;
  3589. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3590. })(BABYLON || (BABYLON = {}));
  3591. //# sourceMappingURL=image.js.map
  3592. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3593. var BABYLON;
  3594. (function (BABYLON) {
  3595. var GUI;
  3596. (function (GUI) {
  3597. var Button = /** @class */ (function (_super) {
  3598. __extends(Button, _super);
  3599. function Button(name) {
  3600. var _this = _super.call(this, name) || this;
  3601. _this.name = name;
  3602. _this.thickness = 1;
  3603. _this.isPointerBlocker = true;
  3604. _this.pointerEnterAnimation = function () {
  3605. _this.alpha -= 0.1;
  3606. };
  3607. _this.pointerOutAnimation = function () {
  3608. _this.alpha += 0.1;
  3609. };
  3610. _this.pointerDownAnimation = function () {
  3611. _this.scaleX -= 0.05;
  3612. _this.scaleY -= 0.05;
  3613. };
  3614. _this.pointerUpAnimation = function () {
  3615. _this.scaleX += 0.05;
  3616. _this.scaleY += 0.05;
  3617. };
  3618. return _this;
  3619. }
  3620. Button.prototype._getTypeName = function () {
  3621. return "Button";
  3622. };
  3623. // While being a container, the button behaves like a control.
  3624. Button.prototype._processPicking = function (x, y, type, buttonIndex) {
  3625. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  3626. return false;
  3627. }
  3628. if (!_super.prototype.contains.call(this, x, y)) {
  3629. return false;
  3630. }
  3631. this._processObservables(type, x, y, buttonIndex);
  3632. return true;
  3633. };
  3634. Button.prototype._onPointerEnter = function (target) {
  3635. if (!_super.prototype._onPointerEnter.call(this, target)) {
  3636. return false;
  3637. }
  3638. if (this.pointerEnterAnimation) {
  3639. this.pointerEnterAnimation();
  3640. }
  3641. return true;
  3642. };
  3643. Button.prototype._onPointerOut = function (target) {
  3644. if (this.pointerOutAnimation) {
  3645. this.pointerOutAnimation();
  3646. }
  3647. _super.prototype._onPointerOut.call(this, target);
  3648. };
  3649. Button.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  3650. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  3651. return false;
  3652. }
  3653. if (this.pointerDownAnimation) {
  3654. this.pointerDownAnimation();
  3655. }
  3656. return true;
  3657. };
  3658. Button.prototype._onPointerUp = function (target, coordinates, buttonIndex) {
  3659. if (this.pointerUpAnimation) {
  3660. this.pointerUpAnimation();
  3661. }
  3662. _super.prototype._onPointerUp.call(this, target, coordinates, buttonIndex);
  3663. };
  3664. // Statics
  3665. Button.CreateImageButton = function (name, text, imageUrl) {
  3666. var result = new Button(name);
  3667. // Adding text
  3668. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3669. textBlock.textWrapping = true;
  3670. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3671. textBlock.paddingLeft = "20%";
  3672. result.addControl(textBlock);
  3673. // Adding image
  3674. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3675. iconImage.width = "20%";
  3676. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  3677. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3678. result.addControl(iconImage);
  3679. return result;
  3680. };
  3681. Button.CreateImageOnlyButton = function (name, imageUrl) {
  3682. var result = new Button(name);
  3683. // Adding image
  3684. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3685. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  3686. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3687. result.addControl(iconImage);
  3688. return result;
  3689. };
  3690. Button.CreateSimpleButton = function (name, text) {
  3691. var result = new Button(name);
  3692. // Adding text
  3693. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3694. textBlock.textWrapping = true;
  3695. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3696. result.addControl(textBlock);
  3697. return result;
  3698. };
  3699. Button.CreateImageWithCenterTextButton = function (name, text, imageUrl) {
  3700. var result = new Button(name);
  3701. // Adding image
  3702. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3703. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  3704. result.addControl(iconImage);
  3705. // Adding text
  3706. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3707. textBlock.textWrapping = true;
  3708. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3709. result.addControl(textBlock);
  3710. return result;
  3711. };
  3712. return Button;
  3713. }(GUI.Rectangle));
  3714. GUI.Button = Button;
  3715. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3716. })(BABYLON || (BABYLON = {}));
  3717. //# sourceMappingURL=button.js.map
  3718. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3719. var BABYLON;
  3720. (function (BABYLON) {
  3721. var GUI;
  3722. (function (GUI) {
  3723. var ColorPicker = /** @class */ (function (_super) {
  3724. __extends(ColorPicker, _super);
  3725. function ColorPicker(name) {
  3726. var _this = _super.call(this, name) || this;
  3727. _this.name = name;
  3728. _this._value = BABYLON.Color3.Red();
  3729. _this._tmpColor = new BABYLON.Color3();
  3730. _this._pointerStartedOnSquare = false;
  3731. _this._pointerStartedOnWheel = false;
  3732. _this._squareLeft = 0;
  3733. _this._squareTop = 0;
  3734. _this._squareSize = 0;
  3735. _this._h = 360;
  3736. _this._s = 1;
  3737. _this._v = 1;
  3738. _this.onValueChangedObservable = new BABYLON.Observable();
  3739. // Events
  3740. _this._pointerIsDown = false;
  3741. _this.value = new BABYLON.Color3(.88, .1, .1);
  3742. _this.size = "200px";
  3743. _this.isPointerBlocker = true;
  3744. return _this;
  3745. }
  3746. Object.defineProperty(ColorPicker.prototype, "value", {
  3747. get: function () {
  3748. return this._value;
  3749. },
  3750. set: function (value) {
  3751. if (this._value.equals(value)) {
  3752. return;
  3753. }
  3754. this._value.copyFrom(value);
  3755. this._RGBtoHSV(this._value, this._tmpColor);
  3756. this._h = this._tmpColor.r;
  3757. this._s = Math.max(this._tmpColor.g, 0.00001);
  3758. this._v = Math.max(this._tmpColor.b, 0.00001);
  3759. this._markAsDirty();
  3760. this.onValueChangedObservable.notifyObservers(this._value);
  3761. },
  3762. enumerable: true,
  3763. configurable: true
  3764. });
  3765. Object.defineProperty(ColorPicker.prototype, "width", {
  3766. set: function (value) {
  3767. if (this._width.toString(this._host) === value) {
  3768. return;
  3769. }
  3770. if (this._width.fromString(value)) {
  3771. this._height.fromString(value);
  3772. this._markAsDirty();
  3773. }
  3774. },
  3775. enumerable: true,
  3776. configurable: true
  3777. });
  3778. Object.defineProperty(ColorPicker.prototype, "height", {
  3779. set: function (value) {
  3780. if (this._height.toString(this._host) === value) {
  3781. return;
  3782. }
  3783. if (this._height.fromString(value)) {
  3784. this._width.fromString(value);
  3785. this._markAsDirty();
  3786. }
  3787. },
  3788. enumerable: true,
  3789. configurable: true
  3790. });
  3791. Object.defineProperty(ColorPicker.prototype, "size", {
  3792. get: function () {
  3793. return this.width;
  3794. },
  3795. set: function (value) {
  3796. this.width = value;
  3797. },
  3798. enumerable: true,
  3799. configurable: true
  3800. });
  3801. ColorPicker.prototype._getTypeName = function () {
  3802. return "ColorPicker";
  3803. };
  3804. ColorPicker.prototype._updateSquareProps = function () {
  3805. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3806. var wheelThickness = radius * .2;
  3807. var innerDiameter = (radius - wheelThickness) * 2;
  3808. var squareSize = innerDiameter / (Math.sqrt(2));
  3809. var offset = radius - squareSize * .5;
  3810. this._squareLeft = this._currentMeasure.left + offset;
  3811. this._squareTop = this._currentMeasure.top + offset;
  3812. this._squareSize = squareSize;
  3813. };
  3814. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  3815. var lgh = context.createLinearGradient(left, top, width + left, top);
  3816. lgh.addColorStop(0, '#fff');
  3817. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  3818. context.fillStyle = lgh;
  3819. context.fillRect(left, top, width, height);
  3820. var lgv = context.createLinearGradient(left, top, left, height + top);
  3821. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  3822. lgv.addColorStop(1, '#000');
  3823. context.fillStyle = lgv;
  3824. context.fillRect(left, top, width, height);
  3825. };
  3826. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  3827. context.beginPath();
  3828. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  3829. context.lineWidth = 3;
  3830. context.strokeStyle = '#333333';
  3831. context.stroke();
  3832. context.beginPath();
  3833. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  3834. context.lineWidth = 3;
  3835. context.strokeStyle = '#ffffff';
  3836. context.stroke();
  3837. };
  3838. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  3839. var canvas = document.createElement("canvas");
  3840. canvas.width = radius * 2;
  3841. canvas.height = radius * 2;
  3842. var context = canvas.getContext("2d");
  3843. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  3844. var data = image.data;
  3845. var color = this._tmpColor;
  3846. var maxDistSq = radius * radius;
  3847. var innerRadius = radius - thickness;
  3848. var minDistSq = innerRadius * innerRadius;
  3849. for (var x = -radius; x < radius; x++) {
  3850. for (var y = -radius; y < radius; y++) {
  3851. var distSq = x * x + y * y;
  3852. if (distSq > maxDistSq || distSq < minDistSq) {
  3853. continue;
  3854. }
  3855. var dist = Math.sqrt(distSq);
  3856. var ang = Math.atan2(y, x);
  3857. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  3858. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  3859. data[index] = color.r * 255;
  3860. data[index + 1] = color.g * 255;
  3861. data[index + 2] = color.b * 255;
  3862. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  3863. //apply less alpha to bigger color pickers
  3864. var alphaAmount = .2;
  3865. var maxAlpha = .2;
  3866. var minAlpha = .04;
  3867. var lowerRadius = 50;
  3868. var upperRadius = 150;
  3869. if (radius < lowerRadius) {
  3870. alphaAmount = maxAlpha;
  3871. }
  3872. else if (radius > upperRadius) {
  3873. alphaAmount = minAlpha;
  3874. }
  3875. else {
  3876. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  3877. }
  3878. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  3879. if (alphaRatio < alphaAmount) {
  3880. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  3881. }
  3882. else if (alphaRatio > 1 - alphaAmount) {
  3883. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  3884. }
  3885. else {
  3886. data[index + 3] = 255;
  3887. }
  3888. }
  3889. }
  3890. context.putImageData(image, 0, 0);
  3891. return canvas;
  3892. };
  3893. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  3894. var r = color.r;
  3895. var g = color.g;
  3896. var b = color.b;
  3897. var max = Math.max(r, g, b);
  3898. var min = Math.min(r, g, b);
  3899. var h = 0;
  3900. var s = 0;
  3901. var v = max;
  3902. var dm = max - min;
  3903. if (max !== 0) {
  3904. s = dm / max;
  3905. }
  3906. if (max != min) {
  3907. if (max == r) {
  3908. h = (g - b) / dm;
  3909. if (g < b) {
  3910. h += 6;
  3911. }
  3912. }
  3913. else if (max == g) {
  3914. h = (b - r) / dm + 2;
  3915. }
  3916. else if (max == b) {
  3917. h = (r - g) / dm + 4;
  3918. }
  3919. h *= 60;
  3920. }
  3921. result.r = h;
  3922. result.g = s;
  3923. result.b = v;
  3924. };
  3925. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  3926. var chroma = value * saturation;
  3927. var h = hue / 60;
  3928. var x = chroma * (1 - Math.abs((h % 2) - 1));
  3929. var r = 0;
  3930. var g = 0;
  3931. var b = 0;
  3932. if (h >= 0 && h <= 1) {
  3933. r = chroma;
  3934. g = x;
  3935. }
  3936. else if (h >= 1 && h <= 2) {
  3937. r = x;
  3938. g = chroma;
  3939. }
  3940. else if (h >= 2 && h <= 3) {
  3941. g = chroma;
  3942. b = x;
  3943. }
  3944. else if (h >= 3 && h <= 4) {
  3945. g = x;
  3946. b = chroma;
  3947. }
  3948. else if (h >= 4 && h <= 5) {
  3949. r = x;
  3950. b = chroma;
  3951. }
  3952. else if (h >= 5 && h <= 6) {
  3953. r = chroma;
  3954. b = x;
  3955. }
  3956. var m = value - chroma;
  3957. result.set((r + m), (g + m), (b + m));
  3958. };
  3959. ColorPicker.prototype._draw = function (parentMeasure, context) {
  3960. context.save();
  3961. this._applyStates(context);
  3962. if (this._processMeasures(parentMeasure, context)) {
  3963. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3964. var wheelThickness = radius * .2;
  3965. var left = this._currentMeasure.left;
  3966. var top = this._currentMeasure.top;
  3967. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  3968. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  3969. }
  3970. this._updateSquareProps();
  3971. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3972. context.shadowColor = this.shadowColor;
  3973. context.shadowBlur = this.shadowBlur;
  3974. context.shadowOffsetX = this.shadowOffsetX;
  3975. context.shadowOffsetY = this.shadowOffsetY;
  3976. context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
  3977. }
  3978. context.drawImage(this._colorWheelCanvas, left, top);
  3979. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3980. context.shadowBlur = 0;
  3981. context.shadowOffsetX = 0;
  3982. context.shadowOffsetY = 0;
  3983. }
  3984. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  3985. var cx = this._squareLeft + this._squareSize * this._s;
  3986. var cy = this._squareTop + this._squareSize * (1 - this._v);
  3987. this._drawCircle(cx, cy, radius * .04, context);
  3988. var dist = radius - wheelThickness * .5;
  3989. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  3990. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  3991. this._drawCircle(cx, cy, wheelThickness * .35, context);
  3992. }
  3993. context.restore();
  3994. };
  3995. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  3996. if (this._pointerStartedOnWheel) {
  3997. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3998. var centerX = radius + this._currentMeasure.left;
  3999. var centerY = radius + this._currentMeasure.top;
  4000. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  4001. }
  4002. else if (this._pointerStartedOnSquare) {
  4003. this._updateSquareProps();
  4004. this._s = (x - this._squareLeft) / this._squareSize;
  4005. this._v = 1 - (y - this._squareTop) / this._squareSize;
  4006. this._s = Math.min(this._s, 1);
  4007. this._s = Math.max(this._s, 0.00001);
  4008. this._v = Math.min(this._v, 1);
  4009. this._v = Math.max(this._v, 0.00001);
  4010. }
  4011. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  4012. this.value = this._tmpColor;
  4013. };
  4014. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  4015. this._updateSquareProps();
  4016. var left = this._squareLeft;
  4017. var top = this._squareTop;
  4018. var size = this._squareSize;
  4019. if (coordinates.x >= left && coordinates.x <= left + size &&
  4020. coordinates.y >= top && coordinates.y <= top + size) {
  4021. return true;
  4022. }
  4023. return false;
  4024. };
  4025. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  4026. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4027. var centerX = radius + this._currentMeasure.left;
  4028. var centerY = radius + this._currentMeasure.top;
  4029. var wheelThickness = radius * .2;
  4030. var innerRadius = radius - wheelThickness;
  4031. var radiusSq = radius * radius;
  4032. var innerRadiusSq = innerRadius * innerRadius;
  4033. var dx = coordinates.x - centerX;
  4034. var dy = coordinates.y - centerY;
  4035. var distSq = dx * dx + dy * dy;
  4036. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  4037. return true;
  4038. }
  4039. return false;
  4040. };
  4041. ColorPicker.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  4042. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  4043. return false;
  4044. }
  4045. this._pointerIsDown = true;
  4046. this._pointerStartedOnSquare = false;
  4047. this._pointerStartedOnWheel = false;
  4048. if (this._isPointOnSquare(coordinates)) {
  4049. this._pointerStartedOnSquare = true;
  4050. }
  4051. else if (this._isPointOnWheel(coordinates)) {
  4052. this._pointerStartedOnWheel = true;
  4053. }
  4054. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4055. this._host._capturingControl = this;
  4056. return true;
  4057. };
  4058. ColorPicker.prototype._onPointerMove = function (target, coordinates) {
  4059. if (this._pointerIsDown) {
  4060. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4061. }
  4062. _super.prototype._onPointerMove.call(this, target, coordinates);
  4063. };
  4064. ColorPicker.prototype._onPointerUp = function (target, coordinates, buttonIndex) {
  4065. this._pointerIsDown = false;
  4066. this._host._capturingControl = null;
  4067. _super.prototype._onPointerUp.call(this, target, coordinates, buttonIndex);
  4068. };
  4069. return ColorPicker;
  4070. }(GUI.Control));
  4071. GUI.ColorPicker = ColorPicker;
  4072. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4073. })(BABYLON || (BABYLON = {}));
  4074. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4075. var BABYLON;
  4076. (function (BABYLON) {
  4077. var GUI;
  4078. (function (GUI) {
  4079. var InputText = /** @class */ (function (_super) {
  4080. __extends(InputText, _super);
  4081. function InputText(name, text) {
  4082. if (text === void 0) { text = ""; }
  4083. var _this = _super.call(this, name) || this;
  4084. _this.name = name;
  4085. _this._text = "";
  4086. _this._placeholderText = "";
  4087. _this._background = "#222222";
  4088. _this._focusedBackground = "#000000";
  4089. _this._placeholderColor = "gray";
  4090. _this._thickness = 1;
  4091. _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
  4092. _this._autoStretchWidth = true;
  4093. _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  4094. _this._isFocused = false;
  4095. _this._blinkIsEven = false;
  4096. _this._cursorOffset = 0;
  4097. _this.promptMessage = "Please enter text:";
  4098. _this.onTextChangedObservable = new BABYLON.Observable();
  4099. _this.onFocusObservable = new BABYLON.Observable();
  4100. _this.onBlurObservable = new BABYLON.Observable();
  4101. _this.text = text;
  4102. return _this;
  4103. }
  4104. Object.defineProperty(InputText.prototype, "maxWidth", {
  4105. get: function () {
  4106. return this._maxWidth.toString(this._host);
  4107. },
  4108. set: function (value) {
  4109. if (this._maxWidth.toString(this._host) === value) {
  4110. return;
  4111. }
  4112. if (this._maxWidth.fromString(value)) {
  4113. this._markAsDirty();
  4114. }
  4115. },
  4116. enumerable: true,
  4117. configurable: true
  4118. });
  4119. Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
  4120. get: function () {
  4121. return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4122. },
  4123. enumerable: true,
  4124. configurable: true
  4125. });
  4126. Object.defineProperty(InputText.prototype, "margin", {
  4127. get: function () {
  4128. return this._margin.toString(this._host);
  4129. },
  4130. set: function (value) {
  4131. if (this._margin.toString(this._host) === value) {
  4132. return;
  4133. }
  4134. if (this._margin.fromString(value)) {
  4135. this._markAsDirty();
  4136. }
  4137. },
  4138. enumerable: true,
  4139. configurable: true
  4140. });
  4141. Object.defineProperty(InputText.prototype, "marginInPixels", {
  4142. get: function () {
  4143. return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4144. },
  4145. enumerable: true,
  4146. configurable: true
  4147. });
  4148. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  4149. get: function () {
  4150. return this._autoStretchWidth;
  4151. },
  4152. set: function (value) {
  4153. if (this._autoStretchWidth === value) {
  4154. return;
  4155. }
  4156. this._autoStretchWidth = value;
  4157. this._markAsDirty();
  4158. },
  4159. enumerable: true,
  4160. configurable: true
  4161. });
  4162. Object.defineProperty(InputText.prototype, "thickness", {
  4163. get: function () {
  4164. return this._thickness;
  4165. },
  4166. set: function (value) {
  4167. if (this._thickness === value) {
  4168. return;
  4169. }
  4170. this._thickness = value;
  4171. this._markAsDirty();
  4172. },
  4173. enumerable: true,
  4174. configurable: true
  4175. });
  4176. Object.defineProperty(InputText.prototype, "focusedBackground", {
  4177. get: function () {
  4178. return this._focusedBackground;
  4179. },
  4180. set: function (value) {
  4181. if (this._focusedBackground === value) {
  4182. return;
  4183. }
  4184. this._focusedBackground = value;
  4185. this._markAsDirty();
  4186. },
  4187. enumerable: true,
  4188. configurable: true
  4189. });
  4190. Object.defineProperty(InputText.prototype, "background", {
  4191. get: function () {
  4192. return this._background;
  4193. },
  4194. set: function (value) {
  4195. if (this._background === value) {
  4196. return;
  4197. }
  4198. this._background = value;
  4199. this._markAsDirty();
  4200. },
  4201. enumerable: true,
  4202. configurable: true
  4203. });
  4204. Object.defineProperty(InputText.prototype, "placeholderColor", {
  4205. get: function () {
  4206. return this._placeholderColor;
  4207. },
  4208. set: function (value) {
  4209. if (this._placeholderColor === value) {
  4210. return;
  4211. }
  4212. this._placeholderColor = value;
  4213. this._markAsDirty();
  4214. },
  4215. enumerable: true,
  4216. configurable: true
  4217. });
  4218. Object.defineProperty(InputText.prototype, "placeholderText", {
  4219. get: function () {
  4220. return this._placeholderText;
  4221. },
  4222. set: function (value) {
  4223. if (this._placeholderText === value) {
  4224. return;
  4225. }
  4226. this._placeholderText = value;
  4227. this._markAsDirty();
  4228. },
  4229. enumerable: true,
  4230. configurable: true
  4231. });
  4232. Object.defineProperty(InputText.prototype, "text", {
  4233. get: function () {
  4234. return this._text;
  4235. },
  4236. set: function (value) {
  4237. if (this._text === value) {
  4238. return;
  4239. }
  4240. this._text = value;
  4241. this._markAsDirty();
  4242. this.onTextChangedObservable.notifyObservers(this);
  4243. },
  4244. enumerable: true,
  4245. configurable: true
  4246. });
  4247. InputText.prototype.onBlur = function () {
  4248. this._isFocused = false;
  4249. this._scrollLeft = null;
  4250. this._cursorOffset = 0;
  4251. clearTimeout(this._blinkTimeout);
  4252. this._markAsDirty();
  4253. this.onBlurObservable.notifyObservers(this);
  4254. };
  4255. InputText.prototype.onFocus = function () {
  4256. this._scrollLeft = null;
  4257. this._isFocused = true;
  4258. this._blinkIsEven = false;
  4259. this._cursorOffset = 0;
  4260. this._markAsDirty();
  4261. this.onFocusObservable.notifyObservers(this);
  4262. if (navigator.userAgent.indexOf("Mobile") !== -1) {
  4263. var value = prompt(this.promptMessage);
  4264. if (value !== null) {
  4265. this.text = value;
  4266. }
  4267. this._host.focusedControl = null;
  4268. return;
  4269. }
  4270. };
  4271. InputText.prototype._getTypeName = function () {
  4272. return "InputText";
  4273. };
  4274. InputText.prototype.processKey = function (keyCode, key) {
  4275. // Specific cases
  4276. switch (keyCode) {
  4277. case 8:// BACKSPACE
  4278. if (this._text && this._text.length > 0) {
  4279. if (this._cursorOffset === 0) {
  4280. this.text = this._text.substr(0, this._text.length - 1);
  4281. }
  4282. else {
  4283. var deletePosition = this._text.length - this._cursorOffset;
  4284. if (deletePosition > 0) {
  4285. this.text = this._text.slice(0, deletePosition - 1) + this._text.slice(deletePosition);
  4286. }
  4287. }
  4288. }
  4289. return;
  4290. case 46:// DELETE
  4291. if (this._text && this._text.length > 0) {
  4292. var deletePosition = this._text.length - this._cursorOffset;
  4293. this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
  4294. this._cursorOffset--;
  4295. }
  4296. return;
  4297. case 13:// RETURN
  4298. this._host.focusedControl = null;
  4299. return;
  4300. case 35:// END
  4301. this._cursorOffset = 0;
  4302. this._blinkIsEven = false;
  4303. this._markAsDirty();
  4304. return;
  4305. case 36:// HOME
  4306. this._cursorOffset = this._text.length;
  4307. this._blinkIsEven = false;
  4308. this._markAsDirty();
  4309. return;
  4310. case 37:// LEFT
  4311. this._cursorOffset++;
  4312. if (this._cursorOffset > this._text.length) {
  4313. this._cursorOffset = this._text.length;
  4314. }
  4315. this._blinkIsEven = false;
  4316. this._markAsDirty();
  4317. return;
  4318. case 39:// RIGHT
  4319. this._cursorOffset--;
  4320. if (this._cursorOffset < 0) {
  4321. this._cursorOffset = 0;
  4322. }
  4323. this._blinkIsEven = false;
  4324. this._markAsDirty();
  4325. return;
  4326. }
  4327. // Printable characters
  4328. if ((keyCode === -1) || // Direct access
  4329. (keyCode === 32) || // Space
  4330. (keyCode > 47 && keyCode < 58) || // Numbers
  4331. (keyCode > 64 && keyCode < 91) || // Letters
  4332. (keyCode > 185 && keyCode < 193) || // Special characters
  4333. (keyCode > 218 && keyCode < 223) || // Special characters
  4334. (keyCode > 95 && keyCode < 112)) {
  4335. if (this._cursorOffset === 0) {
  4336. this.text += key;
  4337. }
  4338. else {
  4339. var insertPosition = this._text.length - this._cursorOffset;
  4340. this.text = this._text.slice(0, insertPosition) + key + this._text.slice(insertPosition);
  4341. }
  4342. }
  4343. };
  4344. InputText.prototype.processKeyboard = function (evt) {
  4345. this.processKey(evt.keyCode, evt.key);
  4346. };
  4347. InputText.prototype._draw = function (parentMeasure, context) {
  4348. var _this = this;
  4349. context.save();
  4350. this._applyStates(context);
  4351. if (this._processMeasures(parentMeasure, context)) {
  4352. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4353. context.shadowColor = this.shadowColor;
  4354. context.shadowBlur = this.shadowBlur;
  4355. context.shadowOffsetX = this.shadowOffsetX;
  4356. context.shadowOffsetY = this.shadowOffsetY;
  4357. }
  4358. // Background
  4359. if (this._isFocused) {
  4360. if (this._focusedBackground) {
  4361. context.fillStyle = this._focusedBackground;
  4362. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4363. }
  4364. }
  4365. else if (this._background) {
  4366. context.fillStyle = this._background;
  4367. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4368. }
  4369. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4370. context.shadowBlur = 0;
  4371. context.shadowOffsetX = 0;
  4372. context.shadowOffsetY = 0;
  4373. }
  4374. if (!this._fontOffset) {
  4375. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  4376. }
  4377. // Text
  4378. var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width);
  4379. if (this.color) {
  4380. context.fillStyle = this.color;
  4381. }
  4382. var text = this._text;
  4383. if (!this._isFocused && !this._text && this._placeholderText) {
  4384. text = this._placeholderText;
  4385. if (this._placeholderColor) {
  4386. context.fillStyle = this._placeholderColor;
  4387. }
  4388. }
  4389. this._textWidth = context.measureText(text).width;
  4390. var marginWidth = this._margin.getValueInPixel(this._host, parentMeasure.width) * 2;
  4391. if (this._autoStretchWidth) {
  4392. this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), this._textWidth + marginWidth) + "px";
  4393. }
  4394. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  4395. var availableWidth = this._width.getValueInPixel(this._host, parentMeasure.width) - marginWidth;
  4396. context.save();
  4397. context.beginPath();
  4398. context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
  4399. context.clip();
  4400. if (this._isFocused && this._textWidth > availableWidth) {
  4401. var textLeft = clipTextLeft - this._textWidth + availableWidth;
  4402. if (!this._scrollLeft) {
  4403. this._scrollLeft = textLeft;
  4404. }
  4405. }
  4406. else {
  4407. this._scrollLeft = clipTextLeft;
  4408. }
  4409. context.fillText(text, this._scrollLeft, this._currentMeasure.top + rootY);
  4410. // Cursor
  4411. if (this._isFocused) {
  4412. // Need to move cursor
  4413. if (this._clickedCoordinate) {
  4414. var rightPosition = this._scrollLeft + this._textWidth;
  4415. var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
  4416. var currentSize = 0;
  4417. this._cursorOffset = 0;
  4418. var previousDist = 0;
  4419. do {
  4420. if (this._cursorOffset) {
  4421. previousDist = Math.abs(absoluteCursorPosition - currentSize);
  4422. }
  4423. this._cursorOffset++;
  4424. currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
  4425. } while (currentSize < absoluteCursorPosition);
  4426. // Find closest move
  4427. if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
  4428. this._cursorOffset--;
  4429. }
  4430. this._blinkIsEven = false;
  4431. this._clickedCoordinate = null;
  4432. }
  4433. // Render cursor
  4434. if (!this._blinkIsEven) {
  4435. var cursorOffsetText = this.text.substr(this._text.length - this._cursorOffset);
  4436. var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
  4437. var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
  4438. if (cursorLeft < clipTextLeft) {
  4439. this._scrollLeft += (clipTextLeft - cursorLeft);
  4440. cursorLeft = clipTextLeft;
  4441. this._markAsDirty();
  4442. }
  4443. else if (cursorLeft > clipTextLeft + availableWidth) {
  4444. this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
  4445. cursorLeft = clipTextLeft + availableWidth;
  4446. this._markAsDirty();
  4447. }
  4448. context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
  4449. }
  4450. clearTimeout(this._blinkTimeout);
  4451. this._blinkTimeout = setTimeout(function () {
  4452. _this._blinkIsEven = !_this._blinkIsEven;
  4453. _this._markAsDirty();
  4454. }, 500);
  4455. }
  4456. context.restore();
  4457. // Border
  4458. if (this._thickness) {
  4459. if (this.color) {
  4460. context.strokeStyle = this.color;
  4461. }
  4462. context.lineWidth = this._thickness;
  4463. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  4464. }
  4465. }
  4466. context.restore();
  4467. };
  4468. InputText.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  4469. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  4470. return false;
  4471. }
  4472. this._clickedCoordinate = coordinates.x;
  4473. if (this._host.focusedControl === this) {
  4474. // Move cursor
  4475. clearTimeout(this._blinkTimeout);
  4476. this._markAsDirty();
  4477. return true;
  4478. }
  4479. this._host.focusedControl = this;
  4480. return true;
  4481. };
  4482. InputText.prototype._onPointerUp = function (target, coordinates, buttonIndex) {
  4483. _super.prototype._onPointerUp.call(this, target, coordinates, buttonIndex);
  4484. };
  4485. InputText.prototype.dispose = function () {
  4486. _super.prototype.dispose.call(this);
  4487. this.onBlurObservable.clear();
  4488. this.onFocusObservable.clear();
  4489. this.onTextChangedObservable.clear();
  4490. };
  4491. return InputText;
  4492. }(GUI.Control));
  4493. GUI.InputText = InputText;
  4494. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4495. })(BABYLON || (BABYLON = {}));
  4496. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4497. var BABYLON;
  4498. (function (BABYLON) {
  4499. var GUI;
  4500. (function (GUI) {
  4501. var KeyPropertySet = /** @class */ (function () {
  4502. function KeyPropertySet() {
  4503. }
  4504. return KeyPropertySet;
  4505. }());
  4506. GUI.KeyPropertySet = KeyPropertySet;
  4507. var VirtualKeyboard = /** @class */ (function (_super) {
  4508. __extends(VirtualKeyboard, _super);
  4509. function VirtualKeyboard() {
  4510. var _this = _super !== null && _super.apply(this, arguments) || this;
  4511. _this.onKeyPressObservable = new BABYLON.Observable();
  4512. _this.defaultButtonWidth = "40px";
  4513. _this.defaultButtonHeight = "40px";
  4514. _this.defaultButtonPaddingLeft = "2px";
  4515. _this.defaultButtonPaddingRight = "2px";
  4516. _this.defaultButtonPaddingTop = "2px";
  4517. _this.defaultButtonPaddingBottom = "2px";
  4518. _this.defaultButtonColor = "#DDD";
  4519. _this.defaultButtonBackground = "#070707";
  4520. return _this;
  4521. }
  4522. VirtualKeyboard.prototype._getTypeName = function () {
  4523. return "VirtualKeyboard";
  4524. };
  4525. VirtualKeyboard.prototype._createKey = function (key, propertySet) {
  4526. var _this = this;
  4527. var button = GUI.Button.CreateSimpleButton(key, key);
  4528. button.width = propertySet && propertySet.width ? propertySet.width : this.defaultButtonWidth;
  4529. button.height = propertySet && propertySet.height ? propertySet.height : this.defaultButtonHeight;
  4530. button.color = propertySet && propertySet.color ? propertySet.color : this.defaultButtonColor;
  4531. button.background = propertySet && propertySet.background ? propertySet.background : this.defaultButtonBackground;
  4532. button.paddingLeft = propertySet && propertySet.paddingLeft ? propertySet.paddingLeft : this.defaultButtonPaddingLeft;
  4533. button.paddingRight = propertySet && propertySet.paddingRight ? propertySet.paddingRight : this.defaultButtonPaddingRight;
  4534. button.paddingTop = propertySet && propertySet.paddingTop ? propertySet.paddingTop : this.defaultButtonPaddingTop;
  4535. button.paddingBottom = propertySet && propertySet.paddingBottom ? propertySet.paddingBottom : this.defaultButtonPaddingBottom;
  4536. button.thickness = 0;
  4537. button.isFocusInvisible = true;
  4538. button.shadowColor = this.shadowColor;
  4539. button.shadowBlur = this.shadowBlur;
  4540. button.shadowOffsetX = this.shadowOffsetX;
  4541. button.shadowOffsetY = this.shadowOffsetY;
  4542. button.onPointerUpObservable.add(function () {
  4543. _this.onKeyPressObservable.notifyObservers(key);
  4544. });
  4545. return button;
  4546. };
  4547. VirtualKeyboard.prototype.addKeysRow = function (keys, propertySets) {
  4548. var panel = new GUI.StackPanel();
  4549. panel.isVertical = false;
  4550. panel.isFocusInvisible = true;
  4551. for (var i = 0; i < keys.length; i++) {
  4552. var properties = null;
  4553. if (propertySets && propertySets.length === keys.length) {
  4554. properties = propertySets[i];
  4555. }
  4556. panel.addControl(this._createKey(keys[i], properties));
  4557. }
  4558. this.addControl(panel);
  4559. };
  4560. Object.defineProperty(VirtualKeyboard.prototype, "connectedInputText", {
  4561. get: function () {
  4562. return this._connectedInputText;
  4563. },
  4564. enumerable: true,
  4565. configurable: true
  4566. });
  4567. VirtualKeyboard.prototype.connect = function (input) {
  4568. var _this = this;
  4569. this.isVisible = false;
  4570. this._connectedInputText = input;
  4571. // Events hooking
  4572. this._onFocusObserver = input.onFocusObservable.add(function () {
  4573. _this.isVisible = true;
  4574. });
  4575. this._onBlurObserver = input.onBlurObservable.add(function () {
  4576. _this.isVisible = false;
  4577. });
  4578. this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
  4579. if (!_this._connectedInputText) {
  4580. return;
  4581. }
  4582. switch (key) {
  4583. case "\u2190":
  4584. _this._connectedInputText.processKey(8);
  4585. return;
  4586. case "\u21B5":
  4587. _this._connectedInputText.processKey(13);
  4588. return;
  4589. }
  4590. _this._connectedInputText.processKey(-1, key);
  4591. });
  4592. };
  4593. VirtualKeyboard.prototype.disconnect = function () {
  4594. if (!this._connectedInputText) {
  4595. return;
  4596. }
  4597. this._connectedInputText.onFocusObservable.remove(this._onFocusObserver);
  4598. this._connectedInputText.onBlurObservable.remove(this._onBlurObserver);
  4599. this.onKeyPressObservable.remove(this._onKeyPressObserver);
  4600. this._connectedInputText = null;
  4601. };
  4602. // Statics
  4603. VirtualKeyboard.CreateDefaultLayout = function () {
  4604. var returnValue = new VirtualKeyboard();
  4605. returnValue.addKeysRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u2190"]);
  4606. returnValue.addKeysRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]);
  4607. returnValue.addKeysRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\u21B5"]);
  4608. returnValue.addKeysRow(["z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]);
  4609. returnValue.addKeysRow([" "], [{ width: "200px" }]);
  4610. return returnValue;
  4611. };
  4612. return VirtualKeyboard;
  4613. }(GUI.StackPanel));
  4614. GUI.VirtualKeyboard = VirtualKeyboard;
  4615. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4616. })(BABYLON || (BABYLON = {}));
  4617. (function universalModuleDefinition(root, factory) {
  4618. var f = factory();
  4619. if (root && root["BABYLON"]) {
  4620. return;
  4621. }
  4622. if(typeof exports === 'object' && typeof module === 'object')
  4623. module.exports = f;
  4624. else if(typeof define === 'function' && define.amd)
  4625. define(["GUI"], factory);
  4626. else if(typeof exports === 'object')
  4627. exports["GUI"] = f;
  4628. else {
  4629. root["BABYLON"]["GUI"] = f;
  4630. }
  4631. })(this, function() {
  4632. return BABYLON.GUI;
  4633. });