babylon.gui.js 212 KB

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