babylon.gui.js 213 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824
  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._isThumbClamped = false;
  2598. _this.onValueChangedObservable = new BABYLON.Observable();
  2599. // Events
  2600. _this._pointerIsDown = false;
  2601. _this.isPointerBlocker = true;
  2602. return _this;
  2603. }
  2604. Object.defineProperty(Slider.prototype, "borderColor", {
  2605. get: function () {
  2606. return this._borderColor;
  2607. },
  2608. set: function (value) {
  2609. if (this._borderColor === value) {
  2610. return;
  2611. }
  2612. this._borderColor = value;
  2613. this._markAsDirty();
  2614. },
  2615. enumerable: true,
  2616. configurable: true
  2617. });
  2618. Object.defineProperty(Slider.prototype, "background", {
  2619. get: function () {
  2620. return this._background;
  2621. },
  2622. set: function (value) {
  2623. if (this._background === value) {
  2624. return;
  2625. }
  2626. this._background = value;
  2627. this._markAsDirty();
  2628. },
  2629. enumerable: true,
  2630. configurable: true
  2631. });
  2632. Object.defineProperty(Slider.prototype, "barOffset", {
  2633. get: function () {
  2634. return this._barOffset.toString(this._host);
  2635. },
  2636. set: function (value) {
  2637. if (this._barOffset.toString(this._host) === value) {
  2638. return;
  2639. }
  2640. if (this._barOffset.fromString(value)) {
  2641. this._markAsDirty();
  2642. }
  2643. },
  2644. enumerable: true,
  2645. configurable: true
  2646. });
  2647. Object.defineProperty(Slider.prototype, "barOffsetInPixels", {
  2648. get: function () {
  2649. return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2650. },
  2651. enumerable: true,
  2652. configurable: true
  2653. });
  2654. Object.defineProperty(Slider.prototype, "thumbWidth", {
  2655. get: function () {
  2656. return this._thumbWidth.toString(this._host);
  2657. },
  2658. set: function (value) {
  2659. if (this._thumbWidth.toString(this._host) === value) {
  2660. return;
  2661. }
  2662. if (this._thumbWidth.fromString(value)) {
  2663. this._markAsDirty();
  2664. }
  2665. },
  2666. enumerable: true,
  2667. configurable: true
  2668. });
  2669. Object.defineProperty(Slider.prototype, "thumbWidthInPixels", {
  2670. get: function () {
  2671. return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2672. },
  2673. enumerable: true,
  2674. configurable: true
  2675. });
  2676. Object.defineProperty(Slider.prototype, "minimum", {
  2677. get: function () {
  2678. return this._minimum;
  2679. },
  2680. set: function (value) {
  2681. if (this._minimum === value) {
  2682. return;
  2683. }
  2684. this._minimum = value;
  2685. this._markAsDirty();
  2686. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2687. },
  2688. enumerable: true,
  2689. configurable: true
  2690. });
  2691. Object.defineProperty(Slider.prototype, "maximum", {
  2692. get: function () {
  2693. return this._maximum;
  2694. },
  2695. set: function (value) {
  2696. if (this._maximum === value) {
  2697. return;
  2698. }
  2699. this._maximum = value;
  2700. this._markAsDirty();
  2701. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2702. },
  2703. enumerable: true,
  2704. configurable: true
  2705. });
  2706. Object.defineProperty(Slider.prototype, "value", {
  2707. get: function () {
  2708. return this._value;
  2709. },
  2710. set: function (value) {
  2711. value = Math.max(Math.min(value, this._maximum), this._minimum);
  2712. if (this._value === value) {
  2713. return;
  2714. }
  2715. this._value = value;
  2716. this._markAsDirty();
  2717. this.onValueChangedObservable.notifyObservers(this._value);
  2718. },
  2719. enumerable: true,
  2720. configurable: true
  2721. });
  2722. Object.defineProperty(Slider.prototype, "isThumbCircle", {
  2723. get: function () {
  2724. return this._isThumbCircle;
  2725. },
  2726. set: function (value) {
  2727. if (this._isThumbCircle === value) {
  2728. return;
  2729. }
  2730. this._isThumbCircle = value;
  2731. this._markAsDirty();
  2732. },
  2733. enumerable: true,
  2734. configurable: true
  2735. });
  2736. Object.defineProperty(Slider.prototype, "isThumbClamped", {
  2737. get: function () {
  2738. return this._isThumbClamped;
  2739. },
  2740. set: function (value) {
  2741. if (this._isThumbClamped === value) {
  2742. return;
  2743. }
  2744. this._isThumbClamped = value;
  2745. this._markAsDirty();
  2746. },
  2747. enumerable: true,
  2748. configurable: true
  2749. });
  2750. Slider.prototype._getTypeName = function () {
  2751. return "Slider";
  2752. };
  2753. Slider.prototype._draw = function (parentMeasure, context) {
  2754. context.save();
  2755. this._applyStates(context);
  2756. if (this._processMeasures(parentMeasure, context)) {
  2757. // Main bar
  2758. var effectiveThumbWidth;
  2759. var effectiveBarOffset;
  2760. if (this._thumbWidth.isPixel) {
  2761. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.width);
  2762. }
  2763. else {
  2764. effectiveThumbWidth = this._currentMeasure.width * this._thumbWidth.getValue(this._host);
  2765. }
  2766. if (this._barOffset.isPixel) {
  2767. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  2768. }
  2769. else {
  2770. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  2771. }
  2772. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2773. context.shadowColor = this.shadowColor;
  2774. context.shadowBlur = this.shadowBlur;
  2775. context.shadowOffsetX = this.shadowOffsetX;
  2776. context.shadowOffsetY = this.shadowOffsetY;
  2777. }
  2778. var left = this._currentMeasure.left;
  2779. var width = this._currentMeasure.width - effectiveThumbWidth;
  2780. var thumbPosition = ((this._value - this._minimum) / (this._maximum - this._minimum)) * width;
  2781. context.fillStyle = this._background;
  2782. if (this.isThumbClamped) {
  2783. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width + effectiveThumbWidth, this._currentMeasure.height - effectiveBarOffset * 2);
  2784. }
  2785. else {
  2786. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  2787. }
  2788. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2789. context.shadowBlur = 0;
  2790. context.shadowOffsetX = 0;
  2791. context.shadowOffsetY = 0;
  2792. }
  2793. context.fillStyle = this.color;
  2794. if (this.isThumbClamped) {
  2795. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width + effectiveThumbWidth, this._currentMeasure.height - effectiveBarOffset * 2);
  2796. }
  2797. else {
  2798. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  2799. }
  2800. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2801. context.shadowColor = this.shadowColor;
  2802. context.shadowBlur = this.shadowBlur;
  2803. context.shadowOffsetX = this.shadowOffsetX;
  2804. context.shadowOffsetY = this.shadowOffsetY;
  2805. }
  2806. if (this._isThumbCircle) {
  2807. context.beginPath();
  2808. context.arc(left + thumbPosition + (effectiveThumbWidth / 2), this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
  2809. context.fill();
  2810. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2811. context.shadowBlur = 0;
  2812. context.shadowOffsetX = 0;
  2813. context.shadowOffsetY = 0;
  2814. }
  2815. context.strokeStyle = this._borderColor;
  2816. context.stroke();
  2817. }
  2818. else {
  2819. context.fillRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2820. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2821. context.shadowBlur = 0;
  2822. context.shadowOffsetX = 0;
  2823. context.shadowOffsetY = 0;
  2824. }
  2825. context.strokeStyle = this._borderColor;
  2826. context.strokeRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2827. }
  2828. }
  2829. context.restore();
  2830. };
  2831. Slider.prototype._updateValueFromPointer = function (x, y) {
  2832. if (this.rotation != 0) {
  2833. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  2834. x = this._transformedPosition.x;
  2835. }
  2836. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  2837. };
  2838. Slider.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  2839. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  2840. return false;
  2841. }
  2842. this._pointerIsDown = true;
  2843. this._updateValueFromPointer(coordinates.x, coordinates.y);
  2844. this._host._capturingControl = this;
  2845. return true;
  2846. };
  2847. Slider.prototype._onPointerMove = function (target, coordinates) {
  2848. if (this._pointerIsDown) {
  2849. this._updateValueFromPointer(coordinates.x, coordinates.y);
  2850. }
  2851. _super.prototype._onPointerMove.call(this, target, coordinates);
  2852. };
  2853. Slider.prototype._onPointerUp = function (target, coordinates, buttonIndex) {
  2854. this._pointerIsDown = false;
  2855. this._host._capturingControl = null;
  2856. _super.prototype._onPointerUp.call(this, target, coordinates, buttonIndex);
  2857. };
  2858. return Slider;
  2859. }(GUI.Control));
  2860. GUI.Slider = Slider;
  2861. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2862. })(BABYLON || (BABYLON = {}));
  2863. //# sourceMappingURL=slider.js.map
  2864. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2865. var BABYLON;
  2866. (function (BABYLON) {
  2867. var GUI;
  2868. (function (GUI) {
  2869. var Checkbox = /** @class */ (function (_super) {
  2870. __extends(Checkbox, _super);
  2871. function Checkbox(name) {
  2872. var _this = _super.call(this, name) || this;
  2873. _this.name = name;
  2874. _this._isChecked = false;
  2875. _this._background = "black";
  2876. _this._checkSizeRatio = 0.8;
  2877. _this._thickness = 1;
  2878. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  2879. _this.isPointerBlocker = true;
  2880. return _this;
  2881. }
  2882. Object.defineProperty(Checkbox.prototype, "thickness", {
  2883. get: function () {
  2884. return this._thickness;
  2885. },
  2886. set: function (value) {
  2887. if (this._thickness === value) {
  2888. return;
  2889. }
  2890. this._thickness = value;
  2891. this._markAsDirty();
  2892. },
  2893. enumerable: true,
  2894. configurable: true
  2895. });
  2896. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  2897. get: function () {
  2898. return this._checkSizeRatio;
  2899. },
  2900. set: function (value) {
  2901. value = Math.max(Math.min(1, value), 0);
  2902. if (this._checkSizeRatio === value) {
  2903. return;
  2904. }
  2905. this._checkSizeRatio = value;
  2906. this._markAsDirty();
  2907. },
  2908. enumerable: true,
  2909. configurable: true
  2910. });
  2911. Object.defineProperty(Checkbox.prototype, "background", {
  2912. get: function () {
  2913. return this._background;
  2914. },
  2915. set: function (value) {
  2916. if (this._background === value) {
  2917. return;
  2918. }
  2919. this._background = value;
  2920. this._markAsDirty();
  2921. },
  2922. enumerable: true,
  2923. configurable: true
  2924. });
  2925. Object.defineProperty(Checkbox.prototype, "isChecked", {
  2926. get: function () {
  2927. return this._isChecked;
  2928. },
  2929. set: function (value) {
  2930. if (this._isChecked === value) {
  2931. return;
  2932. }
  2933. this._isChecked = value;
  2934. this._markAsDirty();
  2935. this.onIsCheckedChangedObservable.notifyObservers(value);
  2936. },
  2937. enumerable: true,
  2938. configurable: true
  2939. });
  2940. Checkbox.prototype._getTypeName = function () {
  2941. return "CheckBox";
  2942. };
  2943. Checkbox.prototype._draw = function (parentMeasure, context) {
  2944. context.save();
  2945. this._applyStates(context);
  2946. if (this._processMeasures(parentMeasure, context)) {
  2947. var actualWidth = this._currentMeasure.width - this._thickness;
  2948. var actualHeight = this._currentMeasure.height - this._thickness;
  2949. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2950. context.shadowColor = this.shadowColor;
  2951. context.shadowBlur = this.shadowBlur;
  2952. context.shadowOffsetX = this.shadowOffsetX;
  2953. context.shadowOffsetY = this.shadowOffsetY;
  2954. }
  2955. context.fillStyle = this._background;
  2956. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2957. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2958. context.shadowBlur = 0;
  2959. context.shadowOffsetX = 0;
  2960. context.shadowOffsetY = 0;
  2961. }
  2962. if (this._isChecked) {
  2963. context.fillStyle = this.color;
  2964. var offsetWidth = actualWidth * this._checkSizeRatio;
  2965. var offseHeight = actualHeight * this._checkSizeRatio;
  2966. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  2967. }
  2968. context.strokeStyle = this.color;
  2969. context.lineWidth = this._thickness;
  2970. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2971. }
  2972. context.restore();
  2973. };
  2974. // Events
  2975. Checkbox.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  2976. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  2977. return false;
  2978. }
  2979. this.isChecked = !this.isChecked;
  2980. return true;
  2981. };
  2982. return Checkbox;
  2983. }(GUI.Control));
  2984. GUI.Checkbox = Checkbox;
  2985. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2986. })(BABYLON || (BABYLON = {}));
  2987. //# sourceMappingURL=checkbox.js.map
  2988. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2989. var BABYLON;
  2990. (function (BABYLON) {
  2991. var GUI;
  2992. (function (GUI) {
  2993. var RadioButton = /** @class */ (function (_super) {
  2994. __extends(RadioButton, _super);
  2995. function RadioButton(name) {
  2996. var _this = _super.call(this, name) || this;
  2997. _this.name = name;
  2998. _this._isChecked = false;
  2999. _this._background = "black";
  3000. _this._checkSizeRatio = 0.8;
  3001. _this._thickness = 1;
  3002. _this.group = "";
  3003. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  3004. _this.isPointerBlocker = true;
  3005. return _this;
  3006. }
  3007. Object.defineProperty(RadioButton.prototype, "thickness", {
  3008. get: function () {
  3009. return this._thickness;
  3010. },
  3011. set: function (value) {
  3012. if (this._thickness === value) {
  3013. return;
  3014. }
  3015. this._thickness = value;
  3016. this._markAsDirty();
  3017. },
  3018. enumerable: true,
  3019. configurable: true
  3020. });
  3021. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  3022. get: function () {
  3023. return this._checkSizeRatio;
  3024. },
  3025. set: function (value) {
  3026. value = Math.max(Math.min(1, value), 0);
  3027. if (this._checkSizeRatio === value) {
  3028. return;
  3029. }
  3030. this._checkSizeRatio = value;
  3031. this._markAsDirty();
  3032. },
  3033. enumerable: true,
  3034. configurable: true
  3035. });
  3036. Object.defineProperty(RadioButton.prototype, "background", {
  3037. get: function () {
  3038. return this._background;
  3039. },
  3040. set: function (value) {
  3041. if (this._background === value) {
  3042. return;
  3043. }
  3044. this._background = value;
  3045. this._markAsDirty();
  3046. },
  3047. enumerable: true,
  3048. configurable: true
  3049. });
  3050. Object.defineProperty(RadioButton.prototype, "isChecked", {
  3051. get: function () {
  3052. return this._isChecked;
  3053. },
  3054. set: function (value) {
  3055. var _this = this;
  3056. if (this._isChecked === value) {
  3057. return;
  3058. }
  3059. this._isChecked = value;
  3060. this._markAsDirty();
  3061. this.onIsCheckedChangedObservable.notifyObservers(value);
  3062. if (this._isChecked) {
  3063. // Update all controls from same group
  3064. this._host.executeOnAllControls(function (control) {
  3065. if (control === _this) {
  3066. return;
  3067. }
  3068. if (control.group === undefined) {
  3069. return;
  3070. }
  3071. var childRadio = control;
  3072. if (childRadio.group === _this.group) {
  3073. childRadio.isChecked = false;
  3074. }
  3075. });
  3076. }
  3077. },
  3078. enumerable: true,
  3079. configurable: true
  3080. });
  3081. RadioButton.prototype._getTypeName = function () {
  3082. return "RadioButton";
  3083. };
  3084. RadioButton.prototype._draw = function (parentMeasure, context) {
  3085. context.save();
  3086. this._applyStates(context);
  3087. if (this._processMeasures(parentMeasure, context)) {
  3088. var actualWidth = this._currentMeasure.width - this._thickness;
  3089. var actualHeight = this._currentMeasure.height - this._thickness;
  3090. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3091. context.shadowColor = this.shadowColor;
  3092. context.shadowBlur = this.shadowBlur;
  3093. context.shadowOffsetX = this.shadowOffsetX;
  3094. context.shadowOffsetY = this.shadowOffsetY;
  3095. }
  3096. // Outer
  3097. 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);
  3098. context.fillStyle = this._background;
  3099. context.fill();
  3100. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3101. context.shadowBlur = 0;
  3102. context.shadowOffsetX = 0;
  3103. context.shadowOffsetY = 0;
  3104. }
  3105. context.strokeStyle = this.color;
  3106. context.lineWidth = this._thickness;
  3107. context.stroke();
  3108. // Inner
  3109. if (this._isChecked) {
  3110. context.fillStyle = this.color;
  3111. var offsetWidth = actualWidth * this._checkSizeRatio;
  3112. var offseHeight = actualHeight * this._checkSizeRatio;
  3113. 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);
  3114. context.fill();
  3115. }
  3116. }
  3117. context.restore();
  3118. };
  3119. // Events
  3120. RadioButton.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  3121. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  3122. return false;
  3123. }
  3124. this.isChecked = !this.isChecked;
  3125. return true;
  3126. };
  3127. return RadioButton;
  3128. }(GUI.Control));
  3129. GUI.RadioButton = RadioButton;
  3130. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3131. })(BABYLON || (BABYLON = {}));
  3132. //# sourceMappingURL=radioButton.js.map
  3133. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3134. var BABYLON;
  3135. (function (BABYLON) {
  3136. var GUI;
  3137. (function (GUI) {
  3138. var TextBlock = /** @class */ (function (_super) {
  3139. __extends(TextBlock, _super);
  3140. function TextBlock(name, text) {
  3141. if (text === void 0) { text = ""; }
  3142. var _this = _super.call(this, name) || this;
  3143. _this.name = name;
  3144. _this._text = "";
  3145. _this._textWrapping = false;
  3146. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3147. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  3148. _this._resizeToFit = false;
  3149. _this._lineSpacing = new GUI.ValueAndUnit(0);
  3150. /**
  3151. * An event triggered after the text is changed
  3152. * @type {BABYLON.Observable}
  3153. */
  3154. _this.onTextChangedObservable = new BABYLON.Observable();
  3155. _this.text = text;
  3156. return _this;
  3157. }
  3158. Object.defineProperty(TextBlock.prototype, "resizeToFit", {
  3159. get: function () {
  3160. return this._resizeToFit;
  3161. },
  3162. set: function (value) {
  3163. this._resizeToFit = value;
  3164. if (this._resizeToFit) {
  3165. this._width.ignoreAdaptiveScaling = true;
  3166. this._height.ignoreAdaptiveScaling = true;
  3167. }
  3168. },
  3169. enumerable: true,
  3170. configurable: true
  3171. });
  3172. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  3173. get: function () {
  3174. return this._textWrapping;
  3175. },
  3176. set: function (value) {
  3177. if (this._textWrapping === value) {
  3178. return;
  3179. }
  3180. this._textWrapping = value;
  3181. this._markAsDirty();
  3182. },
  3183. enumerable: true,
  3184. configurable: true
  3185. });
  3186. Object.defineProperty(TextBlock.prototype, "text", {
  3187. get: function () {
  3188. return this._text;
  3189. },
  3190. set: function (value) {
  3191. if (this._text === value) {
  3192. return;
  3193. }
  3194. this._text = value;
  3195. this._markAsDirty();
  3196. this.onTextChangedObservable.notifyObservers(this);
  3197. },
  3198. enumerable: true,
  3199. configurable: true
  3200. });
  3201. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  3202. get: function () {
  3203. return this._textHorizontalAlignment;
  3204. },
  3205. set: function (value) {
  3206. if (this._textHorizontalAlignment === value) {
  3207. return;
  3208. }
  3209. this._textHorizontalAlignment = value;
  3210. this._markAsDirty();
  3211. },
  3212. enumerable: true,
  3213. configurable: true
  3214. });
  3215. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  3216. get: function () {
  3217. return this._textVerticalAlignment;
  3218. },
  3219. set: function (value) {
  3220. if (this._textVerticalAlignment === value) {
  3221. return;
  3222. }
  3223. this._textVerticalAlignment = value;
  3224. this._markAsDirty();
  3225. },
  3226. enumerable: true,
  3227. configurable: true
  3228. });
  3229. Object.defineProperty(TextBlock.prototype, "lineSpacing", {
  3230. get: function () {
  3231. return this._lineSpacing.toString(this._host);
  3232. },
  3233. set: function (value) {
  3234. if (this._lineSpacing.fromString(value)) {
  3235. this._markAsDirty();
  3236. }
  3237. },
  3238. enumerable: true,
  3239. configurable: true
  3240. });
  3241. TextBlock.prototype._getTypeName = function () {
  3242. return "TextBlock";
  3243. };
  3244. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  3245. var width = this._currentMeasure.width;
  3246. var x = 0;
  3247. switch (this._textHorizontalAlignment) {
  3248. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  3249. x = 0;
  3250. break;
  3251. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  3252. x = width - textWidth;
  3253. break;
  3254. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  3255. x = (width - textWidth) / 2;
  3256. break;
  3257. }
  3258. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3259. context.shadowColor = this.shadowColor;
  3260. context.shadowBlur = this.shadowBlur;
  3261. context.shadowOffsetX = this.shadowOffsetX;
  3262. context.shadowOffsetY = this.shadowOffsetY;
  3263. }
  3264. context.fillText(text, this._currentMeasure.left + x, y);
  3265. };
  3266. TextBlock.prototype._draw = function (parentMeasure, context) {
  3267. context.save();
  3268. this._applyStates(context);
  3269. if (this._processMeasures(parentMeasure, context)) {
  3270. // Render lines
  3271. this._renderLines(context);
  3272. }
  3273. context.restore();
  3274. };
  3275. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  3276. this._lines = [];
  3277. var _lines = this.text.split("\n");
  3278. if (this._textWrapping && !this._resizeToFit) {
  3279. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  3280. var _line = _lines_1[_i];
  3281. this._lines.push(this._parseLineWithTextWrapping(_line, context));
  3282. }
  3283. }
  3284. else {
  3285. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  3286. var _line = _lines_2[_a];
  3287. this._lines.push(this._parseLine(_line, context));
  3288. }
  3289. }
  3290. };
  3291. TextBlock.prototype._parseLine = function (line, context) {
  3292. if (line === void 0) { line = ''; }
  3293. return { text: line, width: context.measureText(line).width };
  3294. };
  3295. TextBlock.prototype._parseLineWithTextWrapping = function (line, context) {
  3296. if (line === void 0) { line = ''; }
  3297. var words = line.split(' ');
  3298. var width = this._currentMeasure.width;
  3299. var lineWidth = 0;
  3300. for (var n = 0; n < words.length; n++) {
  3301. var testLine = n > 0 ? line + " " + words[n] : words[0];
  3302. var metrics = context.measureText(testLine);
  3303. var testWidth = metrics.width;
  3304. if (testWidth > width && n > 0) {
  3305. this._lines.push({ text: line, width: lineWidth });
  3306. line = words[n];
  3307. lineWidth = context.measureText(line).width;
  3308. }
  3309. else {
  3310. lineWidth = testWidth;
  3311. line = testLine;
  3312. }
  3313. }
  3314. return { text: line, width: lineWidth };
  3315. };
  3316. TextBlock.prototype._renderLines = function (context) {
  3317. var height = this._currentMeasure.height;
  3318. if (!this._fontOffset) {
  3319. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  3320. }
  3321. var rootY = 0;
  3322. switch (this._textVerticalAlignment) {
  3323. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  3324. rootY = this._fontOffset.ascent;
  3325. break;
  3326. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  3327. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  3328. break;
  3329. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  3330. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  3331. break;
  3332. }
  3333. rootY += this._currentMeasure.top;
  3334. var maxLineWidth = 0;
  3335. for (var i = 0; i < this._lines.length; i++) {
  3336. var line = this._lines[i];
  3337. if (i !== 0 && this._lineSpacing.internalValue !== 0) {
  3338. if (this._lineSpacing.isPixel) {
  3339. rootY += this._lineSpacing.getValue(this._host);
  3340. }
  3341. else {
  3342. rootY = rootY + (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
  3343. }
  3344. }
  3345. this._drawText(line.text, line.width, rootY, context);
  3346. rootY += this._fontOffset.height;
  3347. if (line.width > maxLineWidth)
  3348. maxLineWidth = line.width;
  3349. }
  3350. if (this._resizeToFit) {
  3351. this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
  3352. this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
  3353. }
  3354. };
  3355. TextBlock.prototype.dispose = function () {
  3356. _super.prototype.dispose.call(this);
  3357. this.onTextChangedObservable.clear();
  3358. };
  3359. return TextBlock;
  3360. }(GUI.Control));
  3361. GUI.TextBlock = TextBlock;
  3362. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3363. })(BABYLON || (BABYLON = {}));
  3364. //# sourceMappingURL=textBlock.js.map
  3365. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3366. var DOMImage = Image;
  3367. var BABYLON;
  3368. (function (BABYLON) {
  3369. var GUI;
  3370. (function (GUI) {
  3371. var Image = /** @class */ (function (_super) {
  3372. __extends(Image, _super);
  3373. function Image(name, url) {
  3374. if (url === void 0) { url = null; }
  3375. var _this = _super.call(this, name) || this;
  3376. _this.name = name;
  3377. _this._loaded = false;
  3378. _this._stretch = Image.STRETCH_FILL;
  3379. _this._autoScale = false;
  3380. _this._sourceLeft = 0;
  3381. _this._sourceTop = 0;
  3382. _this._sourceWidth = 0;
  3383. _this._sourceHeight = 0;
  3384. _this._cellWidth = 0;
  3385. _this._cellHeight = 0;
  3386. _this._cellId = -1;
  3387. _this.source = url;
  3388. return _this;
  3389. }
  3390. Object.defineProperty(Image.prototype, "sourceLeft", {
  3391. get: function () {
  3392. return this._sourceLeft;
  3393. },
  3394. set: function (value) {
  3395. if (this._sourceLeft === value) {
  3396. return;
  3397. }
  3398. this._sourceLeft = value;
  3399. this._markAsDirty();
  3400. },
  3401. enumerable: true,
  3402. configurable: true
  3403. });
  3404. Object.defineProperty(Image.prototype, "sourceTop", {
  3405. get: function () {
  3406. return this._sourceTop;
  3407. },
  3408. set: function (value) {
  3409. if (this._sourceTop === value) {
  3410. return;
  3411. }
  3412. this._sourceTop = value;
  3413. this._markAsDirty();
  3414. },
  3415. enumerable: true,
  3416. configurable: true
  3417. });
  3418. Object.defineProperty(Image.prototype, "sourceWidth", {
  3419. get: function () {
  3420. return this._sourceWidth;
  3421. },
  3422. set: function (value) {
  3423. if (this._sourceWidth === value) {
  3424. return;
  3425. }
  3426. this._sourceWidth = value;
  3427. this._markAsDirty();
  3428. },
  3429. enumerable: true,
  3430. configurable: true
  3431. });
  3432. Object.defineProperty(Image.prototype, "sourceHeight", {
  3433. get: function () {
  3434. return this._sourceHeight;
  3435. },
  3436. set: function (value) {
  3437. if (this._sourceHeight === value) {
  3438. return;
  3439. }
  3440. this._sourceHeight = value;
  3441. this._markAsDirty();
  3442. },
  3443. enumerable: true,
  3444. configurable: true
  3445. });
  3446. Object.defineProperty(Image.prototype, "autoScale", {
  3447. get: function () {
  3448. return this._autoScale;
  3449. },
  3450. set: function (value) {
  3451. if (this._autoScale === value) {
  3452. return;
  3453. }
  3454. this._autoScale = value;
  3455. if (value && this._loaded) {
  3456. this.synchronizeSizeWithContent();
  3457. }
  3458. },
  3459. enumerable: true,
  3460. configurable: true
  3461. });
  3462. Object.defineProperty(Image.prototype, "stretch", {
  3463. get: function () {
  3464. return this._stretch;
  3465. },
  3466. set: function (value) {
  3467. if (this._stretch === value) {
  3468. return;
  3469. }
  3470. this._stretch = value;
  3471. this._markAsDirty();
  3472. },
  3473. enumerable: true,
  3474. configurable: true
  3475. });
  3476. Object.defineProperty(Image.prototype, "domImage", {
  3477. get: function () {
  3478. return this._domImage;
  3479. },
  3480. set: function (value) {
  3481. var _this = this;
  3482. this._domImage = value;
  3483. this._loaded = false;
  3484. if (this._domImage.width) {
  3485. this._onImageLoaded();
  3486. }
  3487. else {
  3488. this._domImage.onload = function () {
  3489. _this._onImageLoaded();
  3490. };
  3491. }
  3492. },
  3493. enumerable: true,
  3494. configurable: true
  3495. });
  3496. Image.prototype._onImageLoaded = function () {
  3497. this._imageWidth = this._domImage.width;
  3498. this._imageHeight = this._domImage.height;
  3499. this._loaded = true;
  3500. if (this._autoScale) {
  3501. this.synchronizeSizeWithContent();
  3502. }
  3503. this._markAsDirty();
  3504. };
  3505. Object.defineProperty(Image.prototype, "source", {
  3506. set: function (value) {
  3507. var _this = this;
  3508. if (this._source === value) {
  3509. return;
  3510. }
  3511. this._loaded = false;
  3512. this._source = value;
  3513. this._domImage = new DOMImage();
  3514. this._domImage.onload = function () {
  3515. _this._onImageLoaded();
  3516. };
  3517. if (value) {
  3518. BABYLON.Tools.SetCorsBehavior(value, this._domImage);
  3519. this._domImage.src = value;
  3520. }
  3521. },
  3522. enumerable: true,
  3523. configurable: true
  3524. });
  3525. Object.defineProperty(Image.prototype, "cellWidth", {
  3526. get: function () {
  3527. return this._cellWidth;
  3528. },
  3529. set: function (value) {
  3530. if (this._cellWidth === value) {
  3531. return;
  3532. }
  3533. this._cellWidth = value;
  3534. this._markAsDirty();
  3535. },
  3536. enumerable: true,
  3537. configurable: true
  3538. });
  3539. Object.defineProperty(Image.prototype, "cellHeight", {
  3540. get: function () {
  3541. return this._cellHeight;
  3542. },
  3543. set: function (value) {
  3544. if (this._cellHeight === value) {
  3545. return;
  3546. }
  3547. this._cellHeight = value;
  3548. this._markAsDirty();
  3549. },
  3550. enumerable: true,
  3551. configurable: true
  3552. });
  3553. Object.defineProperty(Image.prototype, "cellId", {
  3554. get: function () {
  3555. return this._cellId;
  3556. },
  3557. set: function (value) {
  3558. if (this._cellId === value) {
  3559. return;
  3560. }
  3561. this._cellId = value;
  3562. this._markAsDirty();
  3563. },
  3564. enumerable: true,
  3565. configurable: true
  3566. });
  3567. Image.prototype._getTypeName = function () {
  3568. return "Image";
  3569. };
  3570. Image.prototype.synchronizeSizeWithContent = function () {
  3571. if (!this._loaded) {
  3572. return;
  3573. }
  3574. this.width = this._domImage.width + "px";
  3575. this.height = this._domImage.height + "px";
  3576. };
  3577. Image.prototype._draw = function (parentMeasure, context) {
  3578. context.save();
  3579. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3580. context.shadowColor = this.shadowColor;
  3581. context.shadowBlur = this.shadowBlur;
  3582. context.shadowOffsetX = this.shadowOffsetX;
  3583. context.shadowOffsetY = this.shadowOffsetY;
  3584. }
  3585. var x, y, width, height;
  3586. if (this.cellId == -1) {
  3587. x = this._sourceLeft;
  3588. y = this._sourceTop;
  3589. width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  3590. height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  3591. }
  3592. else {
  3593. var rowCount = this._domImage.naturalWidth / this.cellWidth;
  3594. var column = (this.cellId / rowCount) >> 0;
  3595. var row = this.cellId % rowCount;
  3596. x = this.cellWidth * row;
  3597. y = this.cellHeight * column;
  3598. width = this.cellWidth;
  3599. height = this.cellHeight;
  3600. }
  3601. this._applyStates(context);
  3602. if (this._processMeasures(parentMeasure, context)) {
  3603. if (this._loaded) {
  3604. switch (this._stretch) {
  3605. case Image.STRETCH_NONE:
  3606. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3607. break;
  3608. case Image.STRETCH_FILL:
  3609. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3610. break;
  3611. case Image.STRETCH_UNIFORM:
  3612. var hRatio = this._currentMeasure.width / width;
  3613. var vRatio = this._currentMeasure.height / height;
  3614. var ratio = Math.min(hRatio, vRatio);
  3615. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  3616. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  3617. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  3618. break;
  3619. case Image.STRETCH_EXTEND:
  3620. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3621. if (this._autoScale) {
  3622. this.synchronizeSizeWithContent();
  3623. }
  3624. if (this._root && this._root.parent) {
  3625. this._root.width = this.width;
  3626. this._root.height = this.height;
  3627. }
  3628. break;
  3629. }
  3630. }
  3631. }
  3632. context.restore();
  3633. };
  3634. Object.defineProperty(Image, "STRETCH_NONE", {
  3635. get: function () {
  3636. return Image._STRETCH_NONE;
  3637. },
  3638. enumerable: true,
  3639. configurable: true
  3640. });
  3641. Object.defineProperty(Image, "STRETCH_FILL", {
  3642. get: function () {
  3643. return Image._STRETCH_FILL;
  3644. },
  3645. enumerable: true,
  3646. configurable: true
  3647. });
  3648. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  3649. get: function () {
  3650. return Image._STRETCH_UNIFORM;
  3651. },
  3652. enumerable: true,
  3653. configurable: true
  3654. });
  3655. Object.defineProperty(Image, "STRETCH_EXTEND", {
  3656. get: function () {
  3657. return Image._STRETCH_EXTEND;
  3658. },
  3659. enumerable: true,
  3660. configurable: true
  3661. });
  3662. // Static
  3663. Image._STRETCH_NONE = 0;
  3664. Image._STRETCH_FILL = 1;
  3665. Image._STRETCH_UNIFORM = 2;
  3666. Image._STRETCH_EXTEND = 3;
  3667. return Image;
  3668. }(GUI.Control));
  3669. GUI.Image = Image;
  3670. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3671. })(BABYLON || (BABYLON = {}));
  3672. //# sourceMappingURL=image.js.map
  3673. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3674. var BABYLON;
  3675. (function (BABYLON) {
  3676. var GUI;
  3677. (function (GUI) {
  3678. var Button = /** @class */ (function (_super) {
  3679. __extends(Button, _super);
  3680. function Button(name) {
  3681. var _this = _super.call(this, name) || this;
  3682. _this.name = name;
  3683. _this.thickness = 1;
  3684. _this.isPointerBlocker = true;
  3685. _this.pointerEnterAnimation = function () {
  3686. _this.alpha -= 0.1;
  3687. };
  3688. _this.pointerOutAnimation = function () {
  3689. _this.alpha += 0.1;
  3690. };
  3691. _this.pointerDownAnimation = function () {
  3692. _this.scaleX -= 0.05;
  3693. _this.scaleY -= 0.05;
  3694. };
  3695. _this.pointerUpAnimation = function () {
  3696. _this.scaleX += 0.05;
  3697. _this.scaleY += 0.05;
  3698. };
  3699. return _this;
  3700. }
  3701. Button.prototype._getTypeName = function () {
  3702. return "Button";
  3703. };
  3704. // While being a container, the button behaves like a control.
  3705. Button.prototype._processPicking = function (x, y, type, buttonIndex) {
  3706. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  3707. return false;
  3708. }
  3709. if (!_super.prototype.contains.call(this, x, y)) {
  3710. return false;
  3711. }
  3712. this._processObservables(type, x, y, buttonIndex);
  3713. return true;
  3714. };
  3715. Button.prototype._onPointerEnter = function (target) {
  3716. if (!_super.prototype._onPointerEnter.call(this, target)) {
  3717. return false;
  3718. }
  3719. if (this.pointerEnterAnimation) {
  3720. this.pointerEnterAnimation();
  3721. }
  3722. return true;
  3723. };
  3724. Button.prototype._onPointerOut = function (target) {
  3725. if (this.pointerOutAnimation) {
  3726. this.pointerOutAnimation();
  3727. }
  3728. _super.prototype._onPointerOut.call(this, target);
  3729. };
  3730. Button.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  3731. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  3732. return false;
  3733. }
  3734. if (this.pointerDownAnimation) {
  3735. this.pointerDownAnimation();
  3736. }
  3737. return true;
  3738. };
  3739. Button.prototype._onPointerUp = function (target, coordinates, buttonIndex) {
  3740. if (this.pointerUpAnimation) {
  3741. this.pointerUpAnimation();
  3742. }
  3743. _super.prototype._onPointerUp.call(this, target, coordinates, buttonIndex);
  3744. };
  3745. // Statics
  3746. Button.CreateImageButton = function (name, text, imageUrl) {
  3747. var result = new Button(name);
  3748. // Adding text
  3749. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3750. textBlock.textWrapping = true;
  3751. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3752. textBlock.paddingLeft = "20%";
  3753. result.addControl(textBlock);
  3754. // Adding image
  3755. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3756. iconImage.width = "20%";
  3757. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  3758. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3759. result.addControl(iconImage);
  3760. return result;
  3761. };
  3762. Button.CreateImageOnlyButton = function (name, imageUrl) {
  3763. var result = new Button(name);
  3764. // Adding image
  3765. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3766. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  3767. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3768. result.addControl(iconImage);
  3769. return result;
  3770. };
  3771. Button.CreateSimpleButton = function (name, text) {
  3772. var result = new Button(name);
  3773. // Adding text
  3774. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3775. textBlock.textWrapping = true;
  3776. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3777. result.addControl(textBlock);
  3778. return result;
  3779. };
  3780. Button.CreateImageWithCenterTextButton = function (name, text, imageUrl) {
  3781. var result = new Button(name);
  3782. // Adding image
  3783. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3784. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  3785. result.addControl(iconImage);
  3786. // Adding text
  3787. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3788. textBlock.textWrapping = true;
  3789. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3790. result.addControl(textBlock);
  3791. return result;
  3792. };
  3793. return Button;
  3794. }(GUI.Rectangle));
  3795. GUI.Button = Button;
  3796. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3797. })(BABYLON || (BABYLON = {}));
  3798. //# sourceMappingURL=button.js.map
  3799. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3800. var BABYLON;
  3801. (function (BABYLON) {
  3802. var GUI;
  3803. (function (GUI) {
  3804. var ColorPicker = /** @class */ (function (_super) {
  3805. __extends(ColorPicker, _super);
  3806. function ColorPicker(name) {
  3807. var _this = _super.call(this, name) || this;
  3808. _this.name = name;
  3809. _this._value = BABYLON.Color3.Red();
  3810. _this._tmpColor = new BABYLON.Color3();
  3811. _this._pointerStartedOnSquare = false;
  3812. _this._pointerStartedOnWheel = false;
  3813. _this._squareLeft = 0;
  3814. _this._squareTop = 0;
  3815. _this._squareSize = 0;
  3816. _this._h = 360;
  3817. _this._s = 1;
  3818. _this._v = 1;
  3819. _this.onValueChangedObservable = new BABYLON.Observable();
  3820. // Events
  3821. _this._pointerIsDown = false;
  3822. _this.value = new BABYLON.Color3(.88, .1, .1);
  3823. _this.size = "200px";
  3824. _this.isPointerBlocker = true;
  3825. return _this;
  3826. }
  3827. Object.defineProperty(ColorPicker.prototype, "value", {
  3828. get: function () {
  3829. return this._value;
  3830. },
  3831. set: function (value) {
  3832. if (this._value.equals(value)) {
  3833. return;
  3834. }
  3835. this._value.copyFrom(value);
  3836. this._RGBtoHSV(this._value, this._tmpColor);
  3837. this._h = this._tmpColor.r;
  3838. this._s = Math.max(this._tmpColor.g, 0.00001);
  3839. this._v = Math.max(this._tmpColor.b, 0.00001);
  3840. this._markAsDirty();
  3841. this.onValueChangedObservable.notifyObservers(this._value);
  3842. },
  3843. enumerable: true,
  3844. configurable: true
  3845. });
  3846. Object.defineProperty(ColorPicker.prototype, "width", {
  3847. set: function (value) {
  3848. if (this._width.toString(this._host) === value) {
  3849. return;
  3850. }
  3851. if (this._width.fromString(value)) {
  3852. this._height.fromString(value);
  3853. this._markAsDirty();
  3854. }
  3855. },
  3856. enumerable: true,
  3857. configurable: true
  3858. });
  3859. Object.defineProperty(ColorPicker.prototype, "height", {
  3860. set: function (value) {
  3861. if (this._height.toString(this._host) === value) {
  3862. return;
  3863. }
  3864. if (this._height.fromString(value)) {
  3865. this._width.fromString(value);
  3866. this._markAsDirty();
  3867. }
  3868. },
  3869. enumerable: true,
  3870. configurable: true
  3871. });
  3872. Object.defineProperty(ColorPicker.prototype, "size", {
  3873. get: function () {
  3874. return this.width;
  3875. },
  3876. set: function (value) {
  3877. this.width = value;
  3878. },
  3879. enumerable: true,
  3880. configurable: true
  3881. });
  3882. ColorPicker.prototype._getTypeName = function () {
  3883. return "ColorPicker";
  3884. };
  3885. ColorPicker.prototype._updateSquareProps = function () {
  3886. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3887. var wheelThickness = radius * .2;
  3888. var innerDiameter = (radius - wheelThickness) * 2;
  3889. var squareSize = innerDiameter / (Math.sqrt(2));
  3890. var offset = radius - squareSize * .5;
  3891. this._squareLeft = this._currentMeasure.left + offset;
  3892. this._squareTop = this._currentMeasure.top + offset;
  3893. this._squareSize = squareSize;
  3894. };
  3895. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  3896. var lgh = context.createLinearGradient(left, top, width + left, top);
  3897. lgh.addColorStop(0, '#fff');
  3898. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  3899. context.fillStyle = lgh;
  3900. context.fillRect(left, top, width, height);
  3901. var lgv = context.createLinearGradient(left, top, left, height + top);
  3902. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  3903. lgv.addColorStop(1, '#000');
  3904. context.fillStyle = lgv;
  3905. context.fillRect(left, top, width, height);
  3906. };
  3907. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  3908. context.beginPath();
  3909. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  3910. context.lineWidth = 3;
  3911. context.strokeStyle = '#333333';
  3912. context.stroke();
  3913. context.beginPath();
  3914. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  3915. context.lineWidth = 3;
  3916. context.strokeStyle = '#ffffff';
  3917. context.stroke();
  3918. };
  3919. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  3920. var canvas = document.createElement("canvas");
  3921. canvas.width = radius * 2;
  3922. canvas.height = radius * 2;
  3923. var context = canvas.getContext("2d");
  3924. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  3925. var data = image.data;
  3926. var color = this._tmpColor;
  3927. var maxDistSq = radius * radius;
  3928. var innerRadius = radius - thickness;
  3929. var minDistSq = innerRadius * innerRadius;
  3930. for (var x = -radius; x < radius; x++) {
  3931. for (var y = -radius; y < radius; y++) {
  3932. var distSq = x * x + y * y;
  3933. if (distSq > maxDistSq || distSq < minDistSq) {
  3934. continue;
  3935. }
  3936. var dist = Math.sqrt(distSq);
  3937. var ang = Math.atan2(y, x);
  3938. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  3939. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  3940. data[index] = color.r * 255;
  3941. data[index + 1] = color.g * 255;
  3942. data[index + 2] = color.b * 255;
  3943. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  3944. //apply less alpha to bigger color pickers
  3945. var alphaAmount = .2;
  3946. var maxAlpha = .2;
  3947. var minAlpha = .04;
  3948. var lowerRadius = 50;
  3949. var upperRadius = 150;
  3950. if (radius < lowerRadius) {
  3951. alphaAmount = maxAlpha;
  3952. }
  3953. else if (radius > upperRadius) {
  3954. alphaAmount = minAlpha;
  3955. }
  3956. else {
  3957. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  3958. }
  3959. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  3960. if (alphaRatio < alphaAmount) {
  3961. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  3962. }
  3963. else if (alphaRatio > 1 - alphaAmount) {
  3964. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  3965. }
  3966. else {
  3967. data[index + 3] = 255;
  3968. }
  3969. }
  3970. }
  3971. context.putImageData(image, 0, 0);
  3972. return canvas;
  3973. };
  3974. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  3975. var r = color.r;
  3976. var g = color.g;
  3977. var b = color.b;
  3978. var max = Math.max(r, g, b);
  3979. var min = Math.min(r, g, b);
  3980. var h = 0;
  3981. var s = 0;
  3982. var v = max;
  3983. var dm = max - min;
  3984. if (max !== 0) {
  3985. s = dm / max;
  3986. }
  3987. if (max != min) {
  3988. if (max == r) {
  3989. h = (g - b) / dm;
  3990. if (g < b) {
  3991. h += 6;
  3992. }
  3993. }
  3994. else if (max == g) {
  3995. h = (b - r) / dm + 2;
  3996. }
  3997. else if (max == b) {
  3998. h = (r - g) / dm + 4;
  3999. }
  4000. h *= 60;
  4001. }
  4002. result.r = h;
  4003. result.g = s;
  4004. result.b = v;
  4005. };
  4006. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  4007. var chroma = value * saturation;
  4008. var h = hue / 60;
  4009. var x = chroma * (1 - Math.abs((h % 2) - 1));
  4010. var r = 0;
  4011. var g = 0;
  4012. var b = 0;
  4013. if (h >= 0 && h <= 1) {
  4014. r = chroma;
  4015. g = x;
  4016. }
  4017. else if (h >= 1 && h <= 2) {
  4018. r = x;
  4019. g = chroma;
  4020. }
  4021. else if (h >= 2 && h <= 3) {
  4022. g = chroma;
  4023. b = x;
  4024. }
  4025. else if (h >= 3 && h <= 4) {
  4026. g = x;
  4027. b = chroma;
  4028. }
  4029. else if (h >= 4 && h <= 5) {
  4030. r = x;
  4031. b = chroma;
  4032. }
  4033. else if (h >= 5 && h <= 6) {
  4034. r = chroma;
  4035. b = x;
  4036. }
  4037. var m = value - chroma;
  4038. result.set((r + m), (g + m), (b + m));
  4039. };
  4040. ColorPicker.prototype._draw = function (parentMeasure, context) {
  4041. context.save();
  4042. this._applyStates(context);
  4043. if (this._processMeasures(parentMeasure, context)) {
  4044. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4045. var wheelThickness = radius * .2;
  4046. var left = this._currentMeasure.left;
  4047. var top = this._currentMeasure.top;
  4048. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  4049. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  4050. }
  4051. this._updateSquareProps();
  4052. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4053. context.shadowColor = this.shadowColor;
  4054. context.shadowBlur = this.shadowBlur;
  4055. context.shadowOffsetX = this.shadowOffsetX;
  4056. context.shadowOffsetY = this.shadowOffsetY;
  4057. context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
  4058. }
  4059. context.drawImage(this._colorWheelCanvas, left, top);
  4060. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4061. context.shadowBlur = 0;
  4062. context.shadowOffsetX = 0;
  4063. context.shadowOffsetY = 0;
  4064. }
  4065. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  4066. var cx = this._squareLeft + this._squareSize * this._s;
  4067. var cy = this._squareTop + this._squareSize * (1 - this._v);
  4068. this._drawCircle(cx, cy, radius * .04, context);
  4069. var dist = radius - wheelThickness * .5;
  4070. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  4071. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  4072. this._drawCircle(cx, cy, wheelThickness * .35, context);
  4073. }
  4074. context.restore();
  4075. };
  4076. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  4077. if (this._pointerStartedOnWheel) {
  4078. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4079. var centerX = radius + this._currentMeasure.left;
  4080. var centerY = radius + this._currentMeasure.top;
  4081. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  4082. }
  4083. else if (this._pointerStartedOnSquare) {
  4084. this._updateSquareProps();
  4085. this._s = (x - this._squareLeft) / this._squareSize;
  4086. this._v = 1 - (y - this._squareTop) / this._squareSize;
  4087. this._s = Math.min(this._s, 1);
  4088. this._s = Math.max(this._s, 0.00001);
  4089. this._v = Math.min(this._v, 1);
  4090. this._v = Math.max(this._v, 0.00001);
  4091. }
  4092. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  4093. this.value = this._tmpColor;
  4094. };
  4095. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  4096. this._updateSquareProps();
  4097. var left = this._squareLeft;
  4098. var top = this._squareTop;
  4099. var size = this._squareSize;
  4100. if (coordinates.x >= left && coordinates.x <= left + size &&
  4101. coordinates.y >= top && coordinates.y <= top + size) {
  4102. return true;
  4103. }
  4104. return false;
  4105. };
  4106. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  4107. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4108. var centerX = radius + this._currentMeasure.left;
  4109. var centerY = radius + this._currentMeasure.top;
  4110. var wheelThickness = radius * .2;
  4111. var innerRadius = radius - wheelThickness;
  4112. var radiusSq = radius * radius;
  4113. var innerRadiusSq = innerRadius * innerRadius;
  4114. var dx = coordinates.x - centerX;
  4115. var dy = coordinates.y - centerY;
  4116. var distSq = dx * dx + dy * dy;
  4117. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  4118. return true;
  4119. }
  4120. return false;
  4121. };
  4122. ColorPicker.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  4123. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  4124. return false;
  4125. }
  4126. this._pointerIsDown = true;
  4127. this._pointerStartedOnSquare = false;
  4128. this._pointerStartedOnWheel = false;
  4129. if (this._isPointOnSquare(coordinates)) {
  4130. this._pointerStartedOnSquare = true;
  4131. }
  4132. else if (this._isPointOnWheel(coordinates)) {
  4133. this._pointerStartedOnWheel = true;
  4134. }
  4135. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4136. this._host._capturingControl = this;
  4137. return true;
  4138. };
  4139. ColorPicker.prototype._onPointerMove = function (target, coordinates) {
  4140. if (this._pointerIsDown) {
  4141. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4142. }
  4143. _super.prototype._onPointerMove.call(this, target, coordinates);
  4144. };
  4145. ColorPicker.prototype._onPointerUp = function (target, coordinates, buttonIndex) {
  4146. this._pointerIsDown = false;
  4147. this._host._capturingControl = null;
  4148. _super.prototype._onPointerUp.call(this, target, coordinates, buttonIndex);
  4149. };
  4150. return ColorPicker;
  4151. }(GUI.Control));
  4152. GUI.ColorPicker = ColorPicker;
  4153. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4154. })(BABYLON || (BABYLON = {}));
  4155. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4156. var BABYLON;
  4157. (function (BABYLON) {
  4158. var GUI;
  4159. (function (GUI) {
  4160. var InputText = /** @class */ (function (_super) {
  4161. __extends(InputText, _super);
  4162. function InputText(name, text) {
  4163. if (text === void 0) { text = ""; }
  4164. var _this = _super.call(this, name) || this;
  4165. _this.name = name;
  4166. _this._text = "";
  4167. _this._placeholderText = "";
  4168. _this._background = "#222222";
  4169. _this._focusedBackground = "#000000";
  4170. _this._placeholderColor = "gray";
  4171. _this._thickness = 1;
  4172. _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
  4173. _this._autoStretchWidth = true;
  4174. _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  4175. _this._isFocused = false;
  4176. _this._blinkIsEven = false;
  4177. _this._cursorOffset = 0;
  4178. _this.promptMessage = "Please enter text:";
  4179. _this.onTextChangedObservable = new BABYLON.Observable();
  4180. _this.onFocusObservable = new BABYLON.Observable();
  4181. _this.onBlurObservable = new BABYLON.Observable();
  4182. _this.text = text;
  4183. return _this;
  4184. }
  4185. Object.defineProperty(InputText.prototype, "maxWidth", {
  4186. get: function () {
  4187. return this._maxWidth.toString(this._host);
  4188. },
  4189. set: function (value) {
  4190. if (this._maxWidth.toString(this._host) === value) {
  4191. return;
  4192. }
  4193. if (this._maxWidth.fromString(value)) {
  4194. this._markAsDirty();
  4195. }
  4196. },
  4197. enumerable: true,
  4198. configurable: true
  4199. });
  4200. Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
  4201. get: function () {
  4202. return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4203. },
  4204. enumerable: true,
  4205. configurable: true
  4206. });
  4207. Object.defineProperty(InputText.prototype, "margin", {
  4208. get: function () {
  4209. return this._margin.toString(this._host);
  4210. },
  4211. set: function (value) {
  4212. if (this._margin.toString(this._host) === value) {
  4213. return;
  4214. }
  4215. if (this._margin.fromString(value)) {
  4216. this._markAsDirty();
  4217. }
  4218. },
  4219. enumerable: true,
  4220. configurable: true
  4221. });
  4222. Object.defineProperty(InputText.prototype, "marginInPixels", {
  4223. get: function () {
  4224. return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4225. },
  4226. enumerable: true,
  4227. configurable: true
  4228. });
  4229. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  4230. get: function () {
  4231. return this._autoStretchWidth;
  4232. },
  4233. set: function (value) {
  4234. if (this._autoStretchWidth === value) {
  4235. return;
  4236. }
  4237. this._autoStretchWidth = value;
  4238. this._markAsDirty();
  4239. },
  4240. enumerable: true,
  4241. configurable: true
  4242. });
  4243. Object.defineProperty(InputText.prototype, "thickness", {
  4244. get: function () {
  4245. return this._thickness;
  4246. },
  4247. set: function (value) {
  4248. if (this._thickness === value) {
  4249. return;
  4250. }
  4251. this._thickness = value;
  4252. this._markAsDirty();
  4253. },
  4254. enumerable: true,
  4255. configurable: true
  4256. });
  4257. Object.defineProperty(InputText.prototype, "focusedBackground", {
  4258. get: function () {
  4259. return this._focusedBackground;
  4260. },
  4261. set: function (value) {
  4262. if (this._focusedBackground === value) {
  4263. return;
  4264. }
  4265. this._focusedBackground = value;
  4266. this._markAsDirty();
  4267. },
  4268. enumerable: true,
  4269. configurable: true
  4270. });
  4271. Object.defineProperty(InputText.prototype, "background", {
  4272. get: function () {
  4273. return this._background;
  4274. },
  4275. set: function (value) {
  4276. if (this._background === value) {
  4277. return;
  4278. }
  4279. this._background = value;
  4280. this._markAsDirty();
  4281. },
  4282. enumerable: true,
  4283. configurable: true
  4284. });
  4285. Object.defineProperty(InputText.prototype, "placeholderColor", {
  4286. get: function () {
  4287. return this._placeholderColor;
  4288. },
  4289. set: function (value) {
  4290. if (this._placeholderColor === value) {
  4291. return;
  4292. }
  4293. this._placeholderColor = value;
  4294. this._markAsDirty();
  4295. },
  4296. enumerable: true,
  4297. configurable: true
  4298. });
  4299. Object.defineProperty(InputText.prototype, "placeholderText", {
  4300. get: function () {
  4301. return this._placeholderText;
  4302. },
  4303. set: function (value) {
  4304. if (this._placeholderText === value) {
  4305. return;
  4306. }
  4307. this._placeholderText = value;
  4308. this._markAsDirty();
  4309. },
  4310. enumerable: true,
  4311. configurable: true
  4312. });
  4313. Object.defineProperty(InputText.prototype, "text", {
  4314. get: function () {
  4315. return this._text;
  4316. },
  4317. set: function (value) {
  4318. if (this._text === value) {
  4319. return;
  4320. }
  4321. this._text = value;
  4322. this._markAsDirty();
  4323. this.onTextChangedObservable.notifyObservers(this);
  4324. },
  4325. enumerable: true,
  4326. configurable: true
  4327. });
  4328. Object.defineProperty(InputText.prototype, "width", {
  4329. get: function () {
  4330. return this._width.toString(this._host);
  4331. },
  4332. set: function (value) {
  4333. if (this._width.toString(this._host) === value) {
  4334. return;
  4335. }
  4336. if (this._width.fromString(value)) {
  4337. this._markAsDirty();
  4338. }
  4339. this.autoStretchWidth = false;
  4340. },
  4341. enumerable: true,
  4342. configurable: true
  4343. });
  4344. InputText.prototype.onBlur = function () {
  4345. this._isFocused = false;
  4346. this._scrollLeft = null;
  4347. this._cursorOffset = 0;
  4348. clearTimeout(this._blinkTimeout);
  4349. this._markAsDirty();
  4350. this.onBlurObservable.notifyObservers(this);
  4351. };
  4352. InputText.prototype.onFocus = function () {
  4353. this._scrollLeft = null;
  4354. this._isFocused = true;
  4355. this._blinkIsEven = false;
  4356. this._cursorOffset = 0;
  4357. this._markAsDirty();
  4358. this.onFocusObservable.notifyObservers(this);
  4359. if (navigator.userAgent.indexOf("Mobile") !== -1) {
  4360. var value = prompt(this.promptMessage);
  4361. if (value !== null) {
  4362. this.text = value;
  4363. }
  4364. this._host.focusedControl = null;
  4365. return;
  4366. }
  4367. };
  4368. InputText.prototype._getTypeName = function () {
  4369. return "InputText";
  4370. };
  4371. InputText.prototype.processKey = function (keyCode, key) {
  4372. // Specific cases
  4373. switch (keyCode) {
  4374. case 32://SPACE
  4375. key = " "; //ie11 key for space is "Spacebar"
  4376. break;
  4377. case 8:// BACKSPACE
  4378. if (this._text && this._text.length > 0) {
  4379. if (this._cursorOffset === 0) {
  4380. this.text = this._text.substr(0, this._text.length - 1);
  4381. }
  4382. else {
  4383. var deletePosition = this._text.length - this._cursorOffset;
  4384. if (deletePosition > 0) {
  4385. this.text = this._text.slice(0, deletePosition - 1) + this._text.slice(deletePosition);
  4386. }
  4387. }
  4388. }
  4389. return;
  4390. case 46:// DELETE
  4391. if (this._text && this._text.length > 0) {
  4392. var deletePosition = this._text.length - this._cursorOffset;
  4393. this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
  4394. this._cursorOffset--;
  4395. }
  4396. return;
  4397. case 13:// RETURN
  4398. this._host.focusedControl = null;
  4399. return;
  4400. case 35:// END
  4401. this._cursorOffset = 0;
  4402. this._blinkIsEven = false;
  4403. this._markAsDirty();
  4404. return;
  4405. case 36:// HOME
  4406. this._cursorOffset = this._text.length;
  4407. this._blinkIsEven = false;
  4408. this._markAsDirty();
  4409. return;
  4410. case 37:// LEFT
  4411. this._cursorOffset++;
  4412. if (this._cursorOffset > this._text.length) {
  4413. this._cursorOffset = this._text.length;
  4414. }
  4415. this._blinkIsEven = false;
  4416. this._markAsDirty();
  4417. return;
  4418. case 39:// RIGHT
  4419. this._cursorOffset--;
  4420. if (this._cursorOffset < 0) {
  4421. this._cursorOffset = 0;
  4422. }
  4423. this._blinkIsEven = false;
  4424. this._markAsDirty();
  4425. return;
  4426. }
  4427. // Printable characters
  4428. if ((keyCode === -1) || // Direct access
  4429. (keyCode === 32) || // Space
  4430. (keyCode > 47 && keyCode < 58) || // Numbers
  4431. (keyCode > 64 && keyCode < 91) || // Letters
  4432. (keyCode > 185 && keyCode < 193) || // Special characters
  4433. (keyCode > 218 && keyCode < 223) || // Special characters
  4434. (keyCode > 95 && keyCode < 112)) {
  4435. if (this._cursorOffset === 0) {
  4436. this.text += key;
  4437. }
  4438. else {
  4439. var insertPosition = this._text.length - this._cursorOffset;
  4440. this.text = this._text.slice(0, insertPosition) + key + this._text.slice(insertPosition);
  4441. }
  4442. }
  4443. };
  4444. InputText.prototype.processKeyboard = function (evt) {
  4445. this.processKey(evt.keyCode, evt.key);
  4446. };
  4447. InputText.prototype._draw = function (parentMeasure, context) {
  4448. var _this = this;
  4449. context.save();
  4450. this._applyStates(context);
  4451. if (this._processMeasures(parentMeasure, context)) {
  4452. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4453. context.shadowColor = this.shadowColor;
  4454. context.shadowBlur = this.shadowBlur;
  4455. context.shadowOffsetX = this.shadowOffsetX;
  4456. context.shadowOffsetY = this.shadowOffsetY;
  4457. }
  4458. // Background
  4459. if (this._isFocused) {
  4460. if (this._focusedBackground) {
  4461. context.fillStyle = this._focusedBackground;
  4462. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4463. }
  4464. }
  4465. else if (this._background) {
  4466. context.fillStyle = this._background;
  4467. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4468. }
  4469. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4470. context.shadowBlur = 0;
  4471. context.shadowOffsetX = 0;
  4472. context.shadowOffsetY = 0;
  4473. }
  4474. if (!this._fontOffset) {
  4475. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  4476. }
  4477. // Text
  4478. var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width);
  4479. if (this.color) {
  4480. context.fillStyle = this.color;
  4481. }
  4482. var text = this._text;
  4483. if (!this._isFocused && !this._text && this._placeholderText) {
  4484. text = this._placeholderText;
  4485. if (this._placeholderColor) {
  4486. context.fillStyle = this._placeholderColor;
  4487. }
  4488. }
  4489. this._textWidth = context.measureText(text).width;
  4490. var marginWidth = this._margin.getValueInPixel(this._host, parentMeasure.width) * 2;
  4491. if (this._autoStretchWidth) {
  4492. this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), this._textWidth + marginWidth) + "px";
  4493. }
  4494. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  4495. var availableWidth = this._width.getValueInPixel(this._host, parentMeasure.width) - marginWidth;
  4496. context.save();
  4497. context.beginPath();
  4498. context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
  4499. context.clip();
  4500. if (this._isFocused && this._textWidth > availableWidth) {
  4501. var textLeft = clipTextLeft - this._textWidth + availableWidth;
  4502. if (!this._scrollLeft) {
  4503. this._scrollLeft = textLeft;
  4504. }
  4505. }
  4506. else {
  4507. this._scrollLeft = clipTextLeft;
  4508. }
  4509. context.fillText(text, this._scrollLeft, this._currentMeasure.top + rootY);
  4510. // Cursor
  4511. if (this._isFocused) {
  4512. // Need to move cursor
  4513. if (this._clickedCoordinate) {
  4514. var rightPosition = this._scrollLeft + this._textWidth;
  4515. var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
  4516. var currentSize = 0;
  4517. this._cursorOffset = 0;
  4518. var previousDist = 0;
  4519. do {
  4520. if (this._cursorOffset) {
  4521. previousDist = Math.abs(absoluteCursorPosition - currentSize);
  4522. }
  4523. this._cursorOffset++;
  4524. currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
  4525. } while (currentSize < absoluteCursorPosition && (text.length >= this._cursorOffset));
  4526. // Find closest move
  4527. if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
  4528. this._cursorOffset--;
  4529. }
  4530. this._blinkIsEven = false;
  4531. this._clickedCoordinate = null;
  4532. }
  4533. // Render cursor
  4534. if (!this._blinkIsEven) {
  4535. var cursorOffsetText = this.text.substr(this._text.length - this._cursorOffset);
  4536. var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
  4537. var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
  4538. if (cursorLeft < clipTextLeft) {
  4539. this._scrollLeft += (clipTextLeft - cursorLeft);
  4540. cursorLeft = clipTextLeft;
  4541. this._markAsDirty();
  4542. }
  4543. else if (cursorLeft > clipTextLeft + availableWidth) {
  4544. this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
  4545. cursorLeft = clipTextLeft + availableWidth;
  4546. this._markAsDirty();
  4547. }
  4548. context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
  4549. }
  4550. clearTimeout(this._blinkTimeout);
  4551. this._blinkTimeout = setTimeout(function () {
  4552. _this._blinkIsEven = !_this._blinkIsEven;
  4553. _this._markAsDirty();
  4554. }, 500);
  4555. }
  4556. context.restore();
  4557. // Border
  4558. if (this._thickness) {
  4559. if (this.color) {
  4560. context.strokeStyle = this.color;
  4561. }
  4562. context.lineWidth = this._thickness;
  4563. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  4564. }
  4565. }
  4566. context.restore();
  4567. };
  4568. InputText.prototype._onPointerDown = function (target, coordinates, buttonIndex) {
  4569. if (!_super.prototype._onPointerDown.call(this, target, coordinates, buttonIndex)) {
  4570. return false;
  4571. }
  4572. this._clickedCoordinate = coordinates.x;
  4573. if (this._host.focusedControl === this) {
  4574. // Move cursor
  4575. clearTimeout(this._blinkTimeout);
  4576. this._markAsDirty();
  4577. return true;
  4578. }
  4579. this._host.focusedControl = this;
  4580. return true;
  4581. };
  4582. InputText.prototype._onPointerUp = function (target, coordinates, buttonIndex) {
  4583. _super.prototype._onPointerUp.call(this, target, coordinates, buttonIndex);
  4584. };
  4585. InputText.prototype.dispose = function () {
  4586. _super.prototype.dispose.call(this);
  4587. this.onBlurObservable.clear();
  4588. this.onFocusObservable.clear();
  4589. this.onTextChangedObservable.clear();
  4590. };
  4591. return InputText;
  4592. }(GUI.Control));
  4593. GUI.InputText = InputText;
  4594. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4595. })(BABYLON || (BABYLON = {}));
  4596. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4597. var BABYLON;
  4598. (function (BABYLON) {
  4599. var GUI;
  4600. (function (GUI) {
  4601. var KeyPropertySet = /** @class */ (function () {
  4602. function KeyPropertySet() {
  4603. }
  4604. return KeyPropertySet;
  4605. }());
  4606. GUI.KeyPropertySet = KeyPropertySet;
  4607. var VirtualKeyboard = /** @class */ (function (_super) {
  4608. __extends(VirtualKeyboard, _super);
  4609. function VirtualKeyboard() {
  4610. var _this = _super !== null && _super.apply(this, arguments) || this;
  4611. _this.onKeyPressObservable = new BABYLON.Observable();
  4612. _this.defaultButtonWidth = "40px";
  4613. _this.defaultButtonHeight = "40px";
  4614. _this.defaultButtonPaddingLeft = "2px";
  4615. _this.defaultButtonPaddingRight = "2px";
  4616. _this.defaultButtonPaddingTop = "2px";
  4617. _this.defaultButtonPaddingBottom = "2px";
  4618. _this.defaultButtonColor = "#DDD";
  4619. _this.defaultButtonBackground = "#070707";
  4620. _this.shiftButtonColor = "#7799FF";
  4621. _this.selectedShiftThickness = 1;
  4622. _this.shiftState = 0;
  4623. return _this;
  4624. }
  4625. VirtualKeyboard.prototype._getTypeName = function () {
  4626. return "VirtualKeyboard";
  4627. };
  4628. VirtualKeyboard.prototype._createKey = function (key, propertySet) {
  4629. var _this = this;
  4630. var button = GUI.Button.CreateSimpleButton(key, key);
  4631. button.width = propertySet && propertySet.width ? propertySet.width : this.defaultButtonWidth;
  4632. button.height = propertySet && propertySet.height ? propertySet.height : this.defaultButtonHeight;
  4633. button.color = propertySet && propertySet.color ? propertySet.color : this.defaultButtonColor;
  4634. button.background = propertySet && propertySet.background ? propertySet.background : this.defaultButtonBackground;
  4635. button.paddingLeft = propertySet && propertySet.paddingLeft ? propertySet.paddingLeft : this.defaultButtonPaddingLeft;
  4636. button.paddingRight = propertySet && propertySet.paddingRight ? propertySet.paddingRight : this.defaultButtonPaddingRight;
  4637. button.paddingTop = propertySet && propertySet.paddingTop ? propertySet.paddingTop : this.defaultButtonPaddingTop;
  4638. button.paddingBottom = propertySet && propertySet.paddingBottom ? propertySet.paddingBottom : this.defaultButtonPaddingBottom;
  4639. button.thickness = 0;
  4640. button.isFocusInvisible = true;
  4641. button.shadowColor = this.shadowColor;
  4642. button.shadowBlur = this.shadowBlur;
  4643. button.shadowOffsetX = this.shadowOffsetX;
  4644. button.shadowOffsetY = this.shadowOffsetY;
  4645. button.onPointerUpObservable.add(function () {
  4646. _this.onKeyPressObservable.notifyObservers(key);
  4647. });
  4648. return button;
  4649. };
  4650. VirtualKeyboard.prototype.addKeysRow = function (keys, propertySets) {
  4651. var panel = new GUI.StackPanel();
  4652. panel.isVertical = false;
  4653. panel.isFocusInvisible = true;
  4654. for (var i = 0; i < keys.length; i++) {
  4655. var properties = null;
  4656. if (propertySets && propertySets.length === keys.length) {
  4657. properties = propertySets[i];
  4658. }
  4659. panel.addControl(this._createKey(keys[i], properties));
  4660. }
  4661. this.addControl(panel);
  4662. };
  4663. VirtualKeyboard.prototype.applyShiftState = function (shiftState) {
  4664. if (!this.children) {
  4665. return;
  4666. }
  4667. for (var i = 0; i < this.children.length; i++) {
  4668. var row = this.children[i];
  4669. if (!row || !row.children) {
  4670. continue;
  4671. }
  4672. var rowContainer = row;
  4673. for (var j = 0; j < rowContainer.children.length; j++) {
  4674. var button = rowContainer.children[j];
  4675. if (!button || !button.children[0]) {
  4676. continue;
  4677. }
  4678. var button_tblock = button.children[0];
  4679. if (button_tblock.text === "\u21E7") {
  4680. button.color = (shiftState ? this.shiftButtonColor : this.defaultButtonColor);
  4681. button.thickness = (shiftState > 1 ? this.selectedShiftThickness : 0);
  4682. }
  4683. button_tblock.text = (shiftState > 0 ? button_tblock.text.toUpperCase() : button_tblock.text.toLowerCase());
  4684. }
  4685. }
  4686. };
  4687. Object.defineProperty(VirtualKeyboard.prototype, "connectedInputText", {
  4688. get: function () {
  4689. return this._connectedInputText;
  4690. },
  4691. enumerable: true,
  4692. configurable: true
  4693. });
  4694. VirtualKeyboard.prototype.connect = function (input) {
  4695. var _this = this;
  4696. this.isVisible = false;
  4697. this._connectedInputText = input;
  4698. // Events hooking
  4699. this._onFocusObserver = input.onFocusObservable.add(function () {
  4700. _this.isVisible = true;
  4701. });
  4702. this._onBlurObserver = input.onBlurObservable.add(function () {
  4703. _this.isVisible = false;
  4704. });
  4705. this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
  4706. if (!_this._connectedInputText) {
  4707. return;
  4708. }
  4709. switch (key) {
  4710. case "\u21E7":
  4711. _this.shiftState++;
  4712. if (_this.shiftState > 2) {
  4713. _this.shiftState = 0;
  4714. }
  4715. _this.applyShiftState(_this.shiftState);
  4716. return;
  4717. case "\u2190":
  4718. _this._connectedInputText.processKey(8);
  4719. return;
  4720. case "\u21B5":
  4721. _this._connectedInputText.processKey(13);
  4722. return;
  4723. }
  4724. _this._connectedInputText.processKey(-1, (_this.shiftState ? key.toUpperCase() : key));
  4725. if (_this.shiftState === 1) {
  4726. _this.shiftState = 0;
  4727. _this.applyShiftState(_this.shiftState);
  4728. }
  4729. });
  4730. };
  4731. VirtualKeyboard.prototype.disconnect = function () {
  4732. if (!this._connectedInputText) {
  4733. return;
  4734. }
  4735. this._connectedInputText.onFocusObservable.remove(this._onFocusObserver);
  4736. this._connectedInputText.onBlurObservable.remove(this._onBlurObserver);
  4737. this.onKeyPressObservable.remove(this._onKeyPressObserver);
  4738. this._connectedInputText = null;
  4739. };
  4740. // Statics
  4741. VirtualKeyboard.CreateDefaultLayout = function () {
  4742. var returnValue = new VirtualKeyboard();
  4743. returnValue.addKeysRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u2190"]);
  4744. returnValue.addKeysRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]);
  4745. returnValue.addKeysRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\u21B5"]);
  4746. returnValue.addKeysRow(["\u21E7", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]);
  4747. returnValue.addKeysRow([" "], [{ width: "200px" }]);
  4748. return returnValue;
  4749. };
  4750. return VirtualKeyboard;
  4751. }(GUI.StackPanel));
  4752. GUI.VirtualKeyboard = VirtualKeyboard;
  4753. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4754. })(BABYLON || (BABYLON = {}));
  4755. (function universalModuleDefinition(root, factory) {
  4756. var f = factory();
  4757. if (root && root["BABYLON"]) {
  4758. return;
  4759. }
  4760. if(typeof exports === 'object' && typeof module === 'object')
  4761. module.exports = f;
  4762. else if(typeof define === 'function' && define.amd)
  4763. define(["GUI"], factory);
  4764. else if(typeof exports === 'object')
  4765. exports["GUI"] = f;
  4766. else {
  4767. root["BABYLON"]["GUI"] = f;
  4768. }
  4769. })(this, function() {
  4770. return BABYLON.GUI;
  4771. });