babylon.gui.js 206 KB

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