babylon.gui.js 183 KB

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