babylon.gui.js 228 KB

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