babylon.gui.js 187 KB

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