babylon.gui.js 177 KB

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