babylon.gui.js 207 KB

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