babylon.gui.js 154 KB

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