babylon.gui.js 181 KB

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