babylon.gui.js 155 KB

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