babylon.gui.js 207 KB

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