babylon.gui.js 225 KB

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