babylon.gui.js 191 KB

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