babylon.gui.js 181 KB

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