babylon.gui.js 220 KB

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