babylon.gui.js 166 KB

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