babylon.gui.js 154 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568
  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. return;
  1063. }
  1064. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1065. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1066. this._linkedMesh = mesh;
  1067. this._host._linkedControls.push(this);
  1068. };
  1069. Control.prototype._moveToProjectedPosition = function (projectedPosition) {
  1070. this.left = ((projectedPosition.x + this._linkOffsetX.getValue(this._host)) - this._currentMeasure.width / 2) + "px";
  1071. this.top = ((projectedPosition.y + this._linkOffsetY.getValue(this._host)) - this._currentMeasure.height / 2) + "px";
  1072. this._left.ignoreAdaptiveScaling = true;
  1073. this._top.ignoreAdaptiveScaling = true;
  1074. };
  1075. Control.prototype._markMatrixAsDirty = function () {
  1076. this._isMatrixDirty = true;
  1077. this._markAsDirty();
  1078. };
  1079. Control.prototype._markAsDirty = function () {
  1080. this._isDirty = true;
  1081. if (!this._host) {
  1082. return; // Not yet connected
  1083. }
  1084. this._host.markAsDirty();
  1085. };
  1086. Control.prototype._markAllAsDirty = function () {
  1087. this._markAsDirty();
  1088. if (this._font) {
  1089. this._prepareFont();
  1090. }
  1091. };
  1092. Control.prototype._link = function (root, host) {
  1093. this._root = root;
  1094. this._host = host;
  1095. };
  1096. Control.prototype._transform = function (context) {
  1097. if (!this._isMatrixDirty && this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  1098. return;
  1099. }
  1100. // postTranslate
  1101. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  1102. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  1103. context.translate(offsetX, offsetY);
  1104. // rotate
  1105. context.rotate(this._rotation);
  1106. // scale
  1107. context.scale(this._scaleX, this._scaleY);
  1108. // preTranslate
  1109. context.translate(-offsetX, -offsetY);
  1110. // Need to update matrices?
  1111. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  1112. this._cachedOffsetX = offsetX;
  1113. this._cachedOffsetY = offsetY;
  1114. this._isMatrixDirty = false;
  1115. GUI.Matrix2D.ComposeToRef(-offsetX, -offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  1116. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  1117. }
  1118. };
  1119. Control.prototype._applyStates = function (context) {
  1120. if (this._fontSet) {
  1121. this._fontSet = false;
  1122. this._prepareFont();
  1123. }
  1124. if (this._font) {
  1125. context.font = this._font;
  1126. }
  1127. if (this._color) {
  1128. context.fillStyle = this._color;
  1129. }
  1130. if (this._alphaSet) {
  1131. context.globalAlpha = this._alpha;
  1132. }
  1133. };
  1134. Control.prototype._processMeasures = function (parentMeasure, context) {
  1135. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  1136. this._isDirty = false;
  1137. this._currentMeasure.copyFrom(parentMeasure);
  1138. // Let children take some pre-measurement actions
  1139. this._preMeasure(parentMeasure, context);
  1140. this._measure();
  1141. this._computeAlignment(parentMeasure, context);
  1142. // Convert to int values
  1143. this._currentMeasure.left = this._currentMeasure.left | 0;
  1144. this._currentMeasure.top = this._currentMeasure.top | 0;
  1145. this._currentMeasure.width = this._currentMeasure.width | 0;
  1146. this._currentMeasure.height = this._currentMeasure.height | 0;
  1147. // Let children add more features
  1148. this._additionalProcessing(parentMeasure, context);
  1149. this._cachedParentMeasure.copyFrom(parentMeasure);
  1150. if (this.onDirtyObservable.hasObservers()) {
  1151. this.onDirtyObservable.notifyObservers(this);
  1152. }
  1153. }
  1154. if (this._currentMeasure.left > parentMeasure.left + parentMeasure.width) {
  1155. return false;
  1156. }
  1157. if (this._currentMeasure.left + this._currentMeasure.width < parentMeasure.left) {
  1158. return false;
  1159. }
  1160. if (this._currentMeasure.top > parentMeasure.top + parentMeasure.height) {
  1161. return false;
  1162. }
  1163. if (this._currentMeasure.top + this._currentMeasure.height < parentMeasure.top) {
  1164. return false;
  1165. }
  1166. // Transform
  1167. this._transform(context);
  1168. // Clip
  1169. this._clip(context);
  1170. context.clip();
  1171. return true;
  1172. };
  1173. Control.prototype._clip = function (context) {
  1174. context.beginPath();
  1175. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1176. };
  1177. Control.prototype._measure = function () {
  1178. // Width / Height
  1179. if (this._width.isPixel) {
  1180. this._currentMeasure.width = this._width.getValue(this._host);
  1181. }
  1182. else {
  1183. this._currentMeasure.width *= this._width.getValue(this._host);
  1184. }
  1185. if (this._height.isPixel) {
  1186. this._currentMeasure.height = this._height.getValue(this._host);
  1187. }
  1188. else {
  1189. this._currentMeasure.height *= this._height.getValue(this._host);
  1190. }
  1191. };
  1192. Control.prototype._computeAlignment = function (parentMeasure, context) {
  1193. var width = this._currentMeasure.width;
  1194. var height = this._currentMeasure.height;
  1195. var parentWidth = parentMeasure.width;
  1196. var parentHeight = parentMeasure.height;
  1197. // Left / top
  1198. var x = 0;
  1199. var y = 0;
  1200. switch (this.horizontalAlignment) {
  1201. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  1202. x = 0;
  1203. break;
  1204. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  1205. x = parentWidth - width;
  1206. break;
  1207. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  1208. x = (parentWidth - width) / 2;
  1209. break;
  1210. }
  1211. switch (this.verticalAlignment) {
  1212. case Control.VERTICAL_ALIGNMENT_TOP:
  1213. y = 0;
  1214. break;
  1215. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  1216. y = parentHeight - height;
  1217. break;
  1218. case Control.VERTICAL_ALIGNMENT_CENTER:
  1219. y = (parentHeight - height) / 2;
  1220. break;
  1221. }
  1222. if (this._paddingLeft.isPixel) {
  1223. this._currentMeasure.left += this._paddingLeft.getValue(this._host);
  1224. this._currentMeasure.width -= this._paddingLeft.getValue(this._host);
  1225. }
  1226. else {
  1227. this._currentMeasure.left += parentWidth * this._paddingLeft.getValue(this._host);
  1228. this._currentMeasure.width -= parentWidth * this._paddingLeft.getValue(this._host);
  1229. }
  1230. if (this._paddingRight.isPixel) {
  1231. this._currentMeasure.width -= this._paddingRight.getValue(this._host);
  1232. }
  1233. else {
  1234. this._currentMeasure.width -= parentWidth * this._paddingRight.getValue(this._host);
  1235. }
  1236. if (this._paddingTop.isPixel) {
  1237. this._currentMeasure.top += this._paddingTop.getValue(this._host);
  1238. this._currentMeasure.height -= this._paddingTop.getValue(this._host);
  1239. }
  1240. else {
  1241. this._currentMeasure.top += parentHeight * this._paddingTop.getValue(this._host);
  1242. this._currentMeasure.height -= parentHeight * this._paddingTop.getValue(this._host);
  1243. }
  1244. if (this._paddingBottom.isPixel) {
  1245. this._currentMeasure.height -= this._paddingBottom.getValue(this._host);
  1246. }
  1247. else {
  1248. this._currentMeasure.height -= parentHeight * this._paddingBottom.getValue(this._host);
  1249. }
  1250. if (this._left.isPixel) {
  1251. this._currentMeasure.left += this._left.getValue(this._host);
  1252. }
  1253. else {
  1254. this._currentMeasure.left += parentWidth * this._left.getValue(this._host);
  1255. }
  1256. if (this._top.isPixel) {
  1257. this._currentMeasure.top += this._top.getValue(this._host);
  1258. }
  1259. else {
  1260. this._currentMeasure.top += parentHeight * this._top.getValue(this._host);
  1261. }
  1262. this._currentMeasure.left += x;
  1263. this._currentMeasure.top += y;
  1264. };
  1265. Control.prototype._preMeasure = function (parentMeasure, context) {
  1266. // Do nothing
  1267. };
  1268. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  1269. // Do nothing
  1270. };
  1271. Control.prototype._draw = function (parentMeasure, context) {
  1272. // Do nothing
  1273. };
  1274. Control.prototype.contains = function (x, y) {
  1275. // Invert transform
  1276. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  1277. x = this._transformedPosition.x;
  1278. y = this._transformedPosition.y;
  1279. // Check
  1280. if (x < this._currentMeasure.left) {
  1281. return false;
  1282. }
  1283. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  1284. return false;
  1285. }
  1286. if (y < this._currentMeasure.top) {
  1287. return false;
  1288. }
  1289. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  1290. return false;
  1291. }
  1292. if (this.isPointerBlocker) {
  1293. this._host._shouldBlockPointer = true;
  1294. }
  1295. return true;
  1296. };
  1297. Control.prototype._processPicking = function (x, y, type) {
  1298. if (!this.isHitTestVisible || !this.isVisible) {
  1299. return false;
  1300. }
  1301. if (!this.contains(x, y)) {
  1302. return false;
  1303. }
  1304. this._processObservables(type, x, y);
  1305. return true;
  1306. };
  1307. Control.prototype._onPointerMove = function (coordinates) {
  1308. if (this.onPointerMoveObservable.hasObservers()) {
  1309. this.onPointerMoveObservable.notifyObservers(coordinates);
  1310. }
  1311. };
  1312. Control.prototype._onPointerEnter = function () {
  1313. if (this._enterCount !== 0) {
  1314. return false;
  1315. }
  1316. this._enterCount++;
  1317. if (this.onPointerEnterObservable.hasObservers()) {
  1318. this.onPointerEnterObservable.notifyObservers(this);
  1319. }
  1320. return true;
  1321. };
  1322. Control.prototype._onPointerOut = function () {
  1323. this._enterCount = 0;
  1324. if (this.onPointerOutObservable.hasObservers()) {
  1325. this.onPointerOutObservable.notifyObservers(this);
  1326. }
  1327. };
  1328. Control.prototype._onPointerDown = function (coordinates) {
  1329. if (this._downCount !== 0) {
  1330. return false;
  1331. }
  1332. this._downCount++;
  1333. if (this.onPointerDownObservable.hasObservers()) {
  1334. this.onPointerDownObservable.notifyObservers(coordinates);
  1335. }
  1336. return true;
  1337. };
  1338. Control.prototype._onPointerUp = function (coordinates) {
  1339. this._downCount = 0;
  1340. if (this.onPointerUpObservable.hasObservers()) {
  1341. this.onPointerUpObservable.notifyObservers(coordinates);
  1342. }
  1343. };
  1344. Control.prototype.forcePointerUp = function () {
  1345. this._onPointerUp(BABYLON.Vector2.Zero());
  1346. };
  1347. Control.prototype._processObservables = function (type, x, y) {
  1348. this._dummyVector2.copyFromFloats(x, y);
  1349. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  1350. this._onPointerMove(this._dummyVector2);
  1351. var previousControlOver = this._host._lastControlOver;
  1352. if (previousControlOver && previousControlOver !== this) {
  1353. previousControlOver._onPointerOut();
  1354. }
  1355. if (previousControlOver !== this) {
  1356. this._onPointerEnter();
  1357. }
  1358. this._host._lastControlOver = this;
  1359. return true;
  1360. }
  1361. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  1362. this._onPointerDown(this._dummyVector2);
  1363. this._host._lastControlDown = this;
  1364. return true;
  1365. }
  1366. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  1367. if (this._host._lastControlDown) {
  1368. this._host._lastControlDown._onPointerUp(this._dummyVector2);
  1369. }
  1370. this._host._lastControlDown = null;
  1371. return true;
  1372. }
  1373. return false;
  1374. };
  1375. Control.prototype._prepareFont = function () {
  1376. if (!this._fontFamily) {
  1377. return;
  1378. }
  1379. this._font = this._fontSize.getValue(this._host) + "px " + this._fontFamily;
  1380. this._fontOffset = Control._GetFontOffset(this._font);
  1381. };
  1382. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  1383. get: function () {
  1384. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  1385. },
  1386. enumerable: true,
  1387. configurable: true
  1388. });
  1389. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  1390. get: function () {
  1391. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  1392. },
  1393. enumerable: true,
  1394. configurable: true
  1395. });
  1396. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  1397. get: function () {
  1398. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  1399. },
  1400. enumerable: true,
  1401. configurable: true
  1402. });
  1403. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  1404. get: function () {
  1405. return Control._VERTICAL_ALIGNMENT_TOP;
  1406. },
  1407. enumerable: true,
  1408. configurable: true
  1409. });
  1410. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  1411. get: function () {
  1412. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  1413. },
  1414. enumerable: true,
  1415. configurable: true
  1416. });
  1417. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  1418. get: function () {
  1419. return Control._VERTICAL_ALIGNMENT_CENTER;
  1420. },
  1421. enumerable: true,
  1422. configurable: true
  1423. });
  1424. Control._GetFontOffset = function (font) {
  1425. if (Control._FontHeightSizes[font]) {
  1426. return Control._FontHeightSizes[font];
  1427. }
  1428. var text = document.createElement("span");
  1429. text.innerHTML = "Hg";
  1430. text.style.font = font;
  1431. var block = document.createElement("div");
  1432. block.style.display = "inline-block";
  1433. block.style.width = "1px";
  1434. block.style.height = "0px";
  1435. block.style.verticalAlign = "bottom";
  1436. var div = document.createElement("div");
  1437. div.appendChild(text);
  1438. div.appendChild(block);
  1439. document.body.appendChild(div);
  1440. var fontAscent = 0;
  1441. var fontHeight = 0;
  1442. try {
  1443. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1444. block.style.verticalAlign = "baseline";
  1445. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1446. }
  1447. finally {
  1448. document.body.removeChild(div);
  1449. }
  1450. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  1451. Control._FontHeightSizes[font] = result;
  1452. return result;
  1453. };
  1454. ;
  1455. Control.AddHeader = function (control, text, size, options) {
  1456. var panel = new BABYLON.GUI.StackPanel("panel");
  1457. var isHorizontal = options ? options.isHorizontal : true;
  1458. var controlFirst = options ? options.controlFirst : true;
  1459. panel.isVertical = !isHorizontal;
  1460. var header = new BABYLON.GUI.TextBlock("header");
  1461. header.text = text;
  1462. header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  1463. if (isHorizontal) {
  1464. header.width = size;
  1465. }
  1466. else {
  1467. header.height = size;
  1468. }
  1469. if (controlFirst) {
  1470. panel.addControl(control);
  1471. panel.addControl(header);
  1472. header.paddingLeft = "5px";
  1473. }
  1474. else {
  1475. panel.addControl(header);
  1476. panel.addControl(control);
  1477. header.paddingRight = "5px";
  1478. }
  1479. return panel;
  1480. };
  1481. Control.drawEllipse = function (x, y, width, height, context) {
  1482. context.translate(x, y);
  1483. context.scale(width, height);
  1484. context.beginPath();
  1485. context.arc(0, 0, 1, 0, 2 * Math.PI);
  1486. context.closePath();
  1487. context.scale(1 / width, 1 / height);
  1488. context.translate(-x, -y);
  1489. };
  1490. return Control;
  1491. }());
  1492. // Statics
  1493. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  1494. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  1495. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  1496. Control._VERTICAL_ALIGNMENT_TOP = 0;
  1497. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  1498. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  1499. Control._FontHeightSizes = {};
  1500. GUI.Control = Control;
  1501. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1502. })(BABYLON || (BABYLON = {}));
  1503. //# sourceMappingURL=control.js.map
  1504. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1505. var __extends = (this && this.__extends) || (function () {
  1506. var extendStatics = Object.setPrototypeOf ||
  1507. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1508. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1509. return function (d, b) {
  1510. extendStatics(d, b);
  1511. function __() { this.constructor = d; }
  1512. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1513. };
  1514. })();
  1515. var BABYLON;
  1516. (function (BABYLON) {
  1517. var GUI;
  1518. (function (GUI) {
  1519. var Container = (function (_super) {
  1520. __extends(Container, _super);
  1521. function Container(name) {
  1522. var _this = _super.call(this, name) || this;
  1523. _this.name = name;
  1524. _this._children = new Array();
  1525. _this._measureForChildren = GUI.Measure.Empty();
  1526. return _this;
  1527. }
  1528. Object.defineProperty(Container.prototype, "background", {
  1529. get: function () {
  1530. return this._background;
  1531. },
  1532. set: function (value) {
  1533. if (this._background === value) {
  1534. return;
  1535. }
  1536. this._background = value;
  1537. this._markAsDirty();
  1538. },
  1539. enumerable: true,
  1540. configurable: true
  1541. });
  1542. Object.defineProperty(Container.prototype, "children", {
  1543. get: function () {
  1544. return this._children;
  1545. },
  1546. enumerable: true,
  1547. configurable: true
  1548. });
  1549. Container.prototype._getTypeName = function () {
  1550. return "Container";
  1551. };
  1552. Container.prototype.getChildByName = function (name) {
  1553. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1554. var child = _a[_i];
  1555. if (child.name === name) {
  1556. return child;
  1557. }
  1558. }
  1559. return null;
  1560. };
  1561. Container.prototype.getChildByType = function (name, type) {
  1562. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1563. var child = _a[_i];
  1564. if (child.typeName === type) {
  1565. return child;
  1566. }
  1567. }
  1568. return null;
  1569. };
  1570. Container.prototype.containsControl = function (control) {
  1571. return this._children.indexOf(control) !== -1;
  1572. };
  1573. Container.prototype.addControl = function (control) {
  1574. var index = this._children.indexOf(control);
  1575. if (index !== -1) {
  1576. return this;
  1577. }
  1578. control._link(this, this._host);
  1579. this._reOrderControl(control);
  1580. this._markAsDirty();
  1581. return this;
  1582. };
  1583. Container.prototype.removeControl = function (control) {
  1584. var index = this._children.indexOf(control);
  1585. if (index !== -1) {
  1586. this._children.splice(index, 1);
  1587. }
  1588. this._markAsDirty();
  1589. return this;
  1590. };
  1591. Container.prototype._reOrderControl = function (control) {
  1592. this.removeControl(control);
  1593. for (var index = 0; index < this._children.length; index++) {
  1594. if (this._children[index].zIndex > control.zIndex) {
  1595. this._children.splice(index, 0, control);
  1596. return;
  1597. }
  1598. }
  1599. this._children.push(control);
  1600. this._markAsDirty();
  1601. };
  1602. Container.prototype._markMatrixAsDirty = function () {
  1603. _super.prototype._markMatrixAsDirty.call(this);
  1604. for (var index = 0; index < this._children.length; index++) {
  1605. this._children[index]._markMatrixAsDirty();
  1606. }
  1607. };
  1608. Container.prototype._markAllAsDirty = function () {
  1609. _super.prototype._markAllAsDirty.call(this);
  1610. for (var index = 0; index < this._children.length; index++) {
  1611. this._children[index]._markAllAsDirty();
  1612. }
  1613. };
  1614. Container.prototype._localDraw = function (context) {
  1615. if (this._background) {
  1616. context.fillStyle = this._background;
  1617. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1618. }
  1619. };
  1620. Container.prototype._link = function (root, host) {
  1621. _super.prototype._link.call(this, root, host);
  1622. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1623. var child = _a[_i];
  1624. child._link(root, host);
  1625. }
  1626. };
  1627. Container.prototype._draw = function (parentMeasure, context) {
  1628. if (!this.isVisible) {
  1629. return;
  1630. }
  1631. context.save();
  1632. this._applyStates(context);
  1633. if (this._processMeasures(parentMeasure, context)) {
  1634. this._localDraw(context);
  1635. this._clipForChildren(context);
  1636. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1637. var child = _a[_i];
  1638. if (child.isVisible) {
  1639. child._draw(this._measureForChildren, context);
  1640. }
  1641. }
  1642. }
  1643. context.restore();
  1644. };
  1645. Container.prototype._processPicking = function (x, y, type) {
  1646. if (!this.isHitTestVisible || !this.isVisible) {
  1647. return false;
  1648. }
  1649. if (!_super.prototype.contains.call(this, x, y)) {
  1650. return false;
  1651. }
  1652. // Checking backwards to pick closest first
  1653. for (var index = this._children.length - 1; index >= 0; index--) {
  1654. var child = this._children[index];
  1655. if (child._processPicking(x, y, type)) {
  1656. return true;
  1657. }
  1658. }
  1659. return this._processObservables(type, x, y);
  1660. };
  1661. Container.prototype._clipForChildren = function (context) {
  1662. // DO nothing
  1663. };
  1664. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  1665. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1666. this._measureForChildren.copyFrom(this._currentMeasure);
  1667. };
  1668. return Container;
  1669. }(GUI.Control));
  1670. GUI.Container = Container;
  1671. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1672. })(BABYLON || (BABYLON = {}));
  1673. //# sourceMappingURL=container.js.map
  1674. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1675. var __extends = (this && this.__extends) || (function () {
  1676. var extendStatics = Object.setPrototypeOf ||
  1677. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1678. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1679. return function (d, b) {
  1680. extendStatics(d, b);
  1681. function __() { this.constructor = d; }
  1682. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1683. };
  1684. })();
  1685. var BABYLON;
  1686. (function (BABYLON) {
  1687. var GUI;
  1688. (function (GUI) {
  1689. var StackPanel = (function (_super) {
  1690. __extends(StackPanel, _super);
  1691. function StackPanel(name) {
  1692. var _this = _super.call(this, name) || this;
  1693. _this.name = name;
  1694. _this._isVertical = true;
  1695. _this._tempMeasureStore = GUI.Measure.Empty();
  1696. return _this;
  1697. }
  1698. Object.defineProperty(StackPanel.prototype, "isVertical", {
  1699. get: function () {
  1700. return this._isVertical;
  1701. },
  1702. set: function (value) {
  1703. if (this._isVertical === value) {
  1704. return;
  1705. }
  1706. this._isVertical = value;
  1707. this._markAsDirty();
  1708. },
  1709. enumerable: true,
  1710. configurable: true
  1711. });
  1712. StackPanel.prototype._getTypeName = function () {
  1713. return "StackPanel";
  1714. };
  1715. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  1716. var stack = 0;
  1717. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1718. var child = _a[_i];
  1719. this._tempMeasureStore.copyFrom(child._currentMeasure);
  1720. child._currentMeasure.copyFrom(parentMeasure);
  1721. child._measure();
  1722. if (this._isVertical) {
  1723. child.top = stack + "px";
  1724. if (!child._top.ignoreAdaptiveScaling) {
  1725. child._markAsDirty();
  1726. }
  1727. child._top.ignoreAdaptiveScaling = true;
  1728. stack += child._currentMeasure.height;
  1729. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1730. }
  1731. else {
  1732. child.left = stack + "px";
  1733. if (!child._left.ignoreAdaptiveScaling) {
  1734. child._markAsDirty();
  1735. }
  1736. child._left.ignoreAdaptiveScaling = true;
  1737. stack += child._currentMeasure.width;
  1738. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1739. }
  1740. child._currentMeasure.copyFrom(this._tempMeasureStore);
  1741. }
  1742. var panelChanged = false;
  1743. if (this._isVertical) {
  1744. var previousHeight = this.height;
  1745. this.height = stack + "px";
  1746. panelChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  1747. this._height.ignoreAdaptiveScaling = true;
  1748. }
  1749. else {
  1750. var previousWidth = this.width;
  1751. this.width = stack + "px";
  1752. panelChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  1753. this._width.ignoreAdaptiveScaling = true;
  1754. }
  1755. if (panelChanged) {
  1756. this._markAllAsDirty();
  1757. }
  1758. _super.prototype._preMeasure.call(this, parentMeasure, context);
  1759. };
  1760. return StackPanel;
  1761. }(GUI.Container));
  1762. GUI.StackPanel = StackPanel;
  1763. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1764. })(BABYLON || (BABYLON = {}));
  1765. //# sourceMappingURL=stackPanel.js.map
  1766. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1767. var __extends = (this && this.__extends) || (function () {
  1768. var extendStatics = Object.setPrototypeOf ||
  1769. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1770. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1771. return function (d, b) {
  1772. extendStatics(d, b);
  1773. function __() { this.constructor = d; }
  1774. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1775. };
  1776. })();
  1777. var BABYLON;
  1778. (function (BABYLON) {
  1779. var GUI;
  1780. (function (GUI) {
  1781. var Rectangle = (function (_super) {
  1782. __extends(Rectangle, _super);
  1783. function Rectangle(name) {
  1784. var _this = _super.call(this, name) || this;
  1785. _this.name = name;
  1786. _this._thickness = 1;
  1787. _this._cornerRadius = 0;
  1788. return _this;
  1789. }
  1790. Object.defineProperty(Rectangle.prototype, "thickness", {
  1791. get: function () {
  1792. return this._thickness;
  1793. },
  1794. set: function (value) {
  1795. if (this._thickness === value) {
  1796. return;
  1797. }
  1798. this._thickness = value;
  1799. this._markAsDirty();
  1800. },
  1801. enumerable: true,
  1802. configurable: true
  1803. });
  1804. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  1805. get: function () {
  1806. return this._cornerRadius;
  1807. },
  1808. set: function (value) {
  1809. if (value < 0) {
  1810. value = 0;
  1811. }
  1812. if (this._cornerRadius === value) {
  1813. return;
  1814. }
  1815. this._cornerRadius = value;
  1816. this._markAsDirty();
  1817. },
  1818. enumerable: true,
  1819. configurable: true
  1820. });
  1821. Rectangle.prototype._getTypeName = function () {
  1822. return "Rectangle";
  1823. };
  1824. Rectangle.prototype._localDraw = function (context) {
  1825. context.save();
  1826. if (this._background) {
  1827. context.fillStyle = this._background;
  1828. if (this._cornerRadius) {
  1829. this._drawRoundedRect(context, this._thickness / 2);
  1830. context.fill();
  1831. }
  1832. else {
  1833. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1834. }
  1835. }
  1836. if (this._thickness) {
  1837. if (this.color) {
  1838. context.strokeStyle = this.color;
  1839. }
  1840. context.lineWidth = this._thickness;
  1841. if (this._cornerRadius) {
  1842. this._drawRoundedRect(context, this._thickness / 2);
  1843. context.stroke();
  1844. }
  1845. else {
  1846. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  1847. }
  1848. }
  1849. context.restore();
  1850. };
  1851. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  1852. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1853. this._measureForChildren.width -= 2 * this._thickness;
  1854. this._measureForChildren.height -= 2 * this._thickness;
  1855. this._measureForChildren.left += this._thickness;
  1856. this._measureForChildren.top += this._thickness;
  1857. };
  1858. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  1859. if (offset === void 0) { offset = 0; }
  1860. var x = this._currentMeasure.left + offset;
  1861. var y = this._currentMeasure.top + offset;
  1862. var width = this._currentMeasure.width - offset * 2;
  1863. var height = this._currentMeasure.height - offset * 2;
  1864. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  1865. context.beginPath();
  1866. context.moveTo(x + radius, y);
  1867. context.lineTo(x + width - radius, y);
  1868. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  1869. context.lineTo(x + width, y + height - radius);
  1870. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  1871. context.lineTo(x + radius, y + height);
  1872. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  1873. context.lineTo(x, y + radius);
  1874. context.quadraticCurveTo(x, y, x + radius, y);
  1875. context.closePath();
  1876. };
  1877. Rectangle.prototype._clipForChildren = function (context) {
  1878. if (this._cornerRadius) {
  1879. this._drawRoundedRect(context, this._thickness);
  1880. context.clip();
  1881. }
  1882. };
  1883. return Rectangle;
  1884. }(GUI.Container));
  1885. GUI.Rectangle = Rectangle;
  1886. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1887. })(BABYLON || (BABYLON = {}));
  1888. //# sourceMappingURL=rectangle.js.map
  1889. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1890. var __extends = (this && this.__extends) || (function () {
  1891. var extendStatics = Object.setPrototypeOf ||
  1892. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1893. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1894. return function (d, b) {
  1895. extendStatics(d, b);
  1896. function __() { this.constructor = d; }
  1897. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1898. };
  1899. })();
  1900. var BABYLON;
  1901. (function (BABYLON) {
  1902. var GUI;
  1903. (function (GUI) {
  1904. var Ellipse = (function (_super) {
  1905. __extends(Ellipse, _super);
  1906. function Ellipse(name) {
  1907. var _this = _super.call(this, name) || this;
  1908. _this.name = name;
  1909. _this._thickness = 1;
  1910. return _this;
  1911. }
  1912. Object.defineProperty(Ellipse.prototype, "thickness", {
  1913. get: function () {
  1914. return this._thickness;
  1915. },
  1916. set: function (value) {
  1917. if (this._thickness === value) {
  1918. return;
  1919. }
  1920. this._thickness = value;
  1921. this._markAsDirty();
  1922. },
  1923. enumerable: true,
  1924. configurable: true
  1925. });
  1926. Ellipse.prototype._getTypeName = function () {
  1927. return "Ellipse";
  1928. };
  1929. Ellipse.prototype._localDraw = function (context) {
  1930. context.save();
  1931. 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);
  1932. if (this._background) {
  1933. context.fillStyle = this._background;
  1934. context.fill();
  1935. }
  1936. if (this._thickness) {
  1937. if (this.color) {
  1938. context.strokeStyle = this.color;
  1939. }
  1940. context.lineWidth = this._thickness;
  1941. context.stroke();
  1942. }
  1943. context.restore();
  1944. };
  1945. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  1946. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1947. this._measureForChildren.width -= 2 * this._thickness;
  1948. this._measureForChildren.height -= 2 * this._thickness;
  1949. this._measureForChildren.left += this._thickness;
  1950. this._measureForChildren.top += this._thickness;
  1951. };
  1952. Ellipse.prototype._clipForChildren = function (context) {
  1953. 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);
  1954. context.clip();
  1955. };
  1956. return Ellipse;
  1957. }(GUI.Container));
  1958. GUI.Ellipse = Ellipse;
  1959. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1960. })(BABYLON || (BABYLON = {}));
  1961. //# sourceMappingURL=ellipse.js.map
  1962. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1963. var __extends = (this && this.__extends) || (function () {
  1964. var extendStatics = Object.setPrototypeOf ||
  1965. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1966. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1967. return function (d, b) {
  1968. extendStatics(d, b);
  1969. function __() { this.constructor = d; }
  1970. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1971. };
  1972. })();
  1973. var DOMImage = Image;
  1974. var BABYLON;
  1975. (function (BABYLON) {
  1976. var GUI;
  1977. (function (GUI) {
  1978. var Line = (function (_super) {
  1979. __extends(Line, _super);
  1980. function Line(name) {
  1981. var _this = _super.call(this, name) || this;
  1982. _this.name = name;
  1983. _this._lineWidth = 1;
  1984. _this._x1 = new GUI.ValueAndUnit(0);
  1985. _this._y1 = new GUI.ValueAndUnit(0);
  1986. _this._x2 = new GUI.ValueAndUnit(0);
  1987. _this._y2 = new GUI.ValueAndUnit(0);
  1988. _this._dash = new Array();
  1989. _this.isHitTestVisible = false;
  1990. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1991. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1992. return _this;
  1993. }
  1994. Object.defineProperty(Line.prototype, "dash", {
  1995. get: function () {
  1996. return this._dash;
  1997. },
  1998. set: function (value) {
  1999. if (this._dash === value) {
  2000. return;
  2001. }
  2002. this._dash = value;
  2003. this._markAsDirty();
  2004. },
  2005. enumerable: true,
  2006. configurable: true
  2007. });
  2008. Object.defineProperty(Line.prototype, "connectedControl", {
  2009. get: function () {
  2010. return this._connectedControl;
  2011. },
  2012. set: function (value) {
  2013. var _this = this;
  2014. if (this._connectedControl === value) {
  2015. return;
  2016. }
  2017. if (this._connectedControlDirtyObserver && this._connectedControl) {
  2018. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  2019. this._connectedControlDirtyObserver = null;
  2020. }
  2021. if (value) {
  2022. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  2023. }
  2024. this._connectedControl = value;
  2025. this._markAsDirty();
  2026. },
  2027. enumerable: true,
  2028. configurable: true
  2029. });
  2030. Object.defineProperty(Line.prototype, "x1", {
  2031. get: function () {
  2032. return this._x1.toString(this._host);
  2033. },
  2034. set: function (value) {
  2035. if (this._x1.toString(this._host) === value) {
  2036. return;
  2037. }
  2038. if (this._x1.fromString(value)) {
  2039. this._markAsDirty();
  2040. }
  2041. },
  2042. enumerable: true,
  2043. configurable: true
  2044. });
  2045. Object.defineProperty(Line.prototype, "y1", {
  2046. get: function () {
  2047. return this._y1.toString(this._host);
  2048. },
  2049. set: function (value) {
  2050. if (this._y1.toString(this._host) === value) {
  2051. return;
  2052. }
  2053. if (this._y1.fromString(value)) {
  2054. this._markAsDirty();
  2055. }
  2056. },
  2057. enumerable: true,
  2058. configurable: true
  2059. });
  2060. Object.defineProperty(Line.prototype, "x2", {
  2061. get: function () {
  2062. return this._x2.toString(this._host);
  2063. },
  2064. set: function (value) {
  2065. if (this._x2.toString(this._host) === value) {
  2066. return;
  2067. }
  2068. if (this._x2.fromString(value)) {
  2069. this._markAsDirty();
  2070. }
  2071. },
  2072. enumerable: true,
  2073. configurable: true
  2074. });
  2075. Object.defineProperty(Line.prototype, "y2", {
  2076. get: function () {
  2077. return this._y2.toString(this._host);
  2078. },
  2079. set: function (value) {
  2080. if (this._y2.toString(this._host) === value) {
  2081. return;
  2082. }
  2083. if (this._y2.fromString(value)) {
  2084. this._markAsDirty();
  2085. }
  2086. },
  2087. enumerable: true,
  2088. configurable: true
  2089. });
  2090. Object.defineProperty(Line.prototype, "lineWidth", {
  2091. get: function () {
  2092. return this._lineWidth;
  2093. },
  2094. set: function (value) {
  2095. if (this._lineWidth === value) {
  2096. return;
  2097. }
  2098. this._lineWidth = value;
  2099. this._markAsDirty();
  2100. },
  2101. enumerable: true,
  2102. configurable: true
  2103. });
  2104. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  2105. set: function (value) {
  2106. return;
  2107. },
  2108. enumerable: true,
  2109. configurable: true
  2110. });
  2111. Object.defineProperty(Line.prototype, "verticalAlignment", {
  2112. set: function (value) {
  2113. return;
  2114. },
  2115. enumerable: true,
  2116. configurable: true
  2117. });
  2118. Object.defineProperty(Line.prototype, "_effectiveX2", {
  2119. get: function () {
  2120. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  2121. },
  2122. enumerable: true,
  2123. configurable: true
  2124. });
  2125. Object.defineProperty(Line.prototype, "_effectiveY2", {
  2126. get: function () {
  2127. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  2128. },
  2129. enumerable: true,
  2130. configurable: true
  2131. });
  2132. Line.prototype._getTypeName = function () {
  2133. return "Line";
  2134. };
  2135. Line.prototype._draw = function (parentMeasure, context) {
  2136. context.save();
  2137. this._applyStates(context);
  2138. if (this._processMeasures(parentMeasure, context)) {
  2139. context.strokeStyle = this.color;
  2140. context.lineWidth = this._lineWidth;
  2141. context.setLineDash(this._dash);
  2142. context.beginPath();
  2143. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  2144. context.lineTo(this._effectiveX2, this._effectiveY2);
  2145. context.stroke();
  2146. }
  2147. context.restore();
  2148. };
  2149. Line.prototype._measure = function () {
  2150. // Width / Height
  2151. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  2152. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  2153. };
  2154. Line.prototype._computeAlignment = function (parentMeasure, context) {
  2155. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  2156. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  2157. };
  2158. Line.prototype._moveToProjectedPosition = function (projectedPosition) {
  2159. this.x1 = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  2160. this.y1 = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  2161. this._x1.ignoreAdaptiveScaling = true;
  2162. this._y1.ignoreAdaptiveScaling = true;
  2163. };
  2164. return Line;
  2165. }(GUI.Control));
  2166. GUI.Line = Line;
  2167. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2168. })(BABYLON || (BABYLON = {}));
  2169. //# sourceMappingURL=line.js.map
  2170. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2171. var __extends = (this && this.__extends) || (function () {
  2172. var extendStatics = Object.setPrototypeOf ||
  2173. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2174. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2175. return function (d, b) {
  2176. extendStatics(d, b);
  2177. function __() { this.constructor = d; }
  2178. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2179. };
  2180. })();
  2181. var DOMImage = Image;
  2182. var BABYLON;
  2183. (function (BABYLON) {
  2184. var GUI;
  2185. (function (GUI) {
  2186. var Slider = (function (_super) {
  2187. __extends(Slider, _super);
  2188. function Slider(name) {
  2189. var _this = _super.call(this, name) || this;
  2190. _this.name = name;
  2191. _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2192. _this._minimum = 0;
  2193. _this._maximum = 100;
  2194. _this._value = 50;
  2195. _this._background = "black";
  2196. _this._borderColor = "white";
  2197. _this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2198. _this.onValueChangedObservable = new BABYLON.Observable();
  2199. // Events
  2200. _this._pointerIsDown = false;
  2201. _this.isPointerBlocker = true;
  2202. return _this;
  2203. }
  2204. Object.defineProperty(Slider.prototype, "borderColor", {
  2205. get: function () {
  2206. return this._borderColor;
  2207. },
  2208. set: function (value) {
  2209. if (this._borderColor === value) {
  2210. return;
  2211. }
  2212. this._borderColor = value;
  2213. this._markAsDirty();
  2214. },
  2215. enumerable: true,
  2216. configurable: true
  2217. });
  2218. Object.defineProperty(Slider.prototype, "background", {
  2219. get: function () {
  2220. return this._background;
  2221. },
  2222. set: function (value) {
  2223. if (this._background === value) {
  2224. return;
  2225. }
  2226. this._background = value;
  2227. this._markAsDirty();
  2228. },
  2229. enumerable: true,
  2230. configurable: true
  2231. });
  2232. Object.defineProperty(Slider.prototype, "barOffset", {
  2233. get: function () {
  2234. return this._barOffset.toString(this._host);
  2235. },
  2236. set: function (value) {
  2237. if (this._barOffset.toString(this._host) === value) {
  2238. return;
  2239. }
  2240. if (this._barOffset.fromString(value)) {
  2241. this._markAsDirty();
  2242. }
  2243. },
  2244. enumerable: true,
  2245. configurable: true
  2246. });
  2247. Object.defineProperty(Slider.prototype, "thumbWidth", {
  2248. get: function () {
  2249. return this._thumbWidth.toString(this._host);
  2250. },
  2251. set: function (value) {
  2252. if (this._thumbWidth.toString(this._host) === value) {
  2253. return;
  2254. }
  2255. if (this._thumbWidth.fromString(value)) {
  2256. this._markAsDirty();
  2257. }
  2258. },
  2259. enumerable: true,
  2260. configurable: true
  2261. });
  2262. Object.defineProperty(Slider.prototype, "minimum", {
  2263. get: function () {
  2264. return this._minimum;
  2265. },
  2266. set: function (value) {
  2267. if (this._minimum === value) {
  2268. return;
  2269. }
  2270. this._minimum = value;
  2271. this._markAsDirty();
  2272. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2273. },
  2274. enumerable: true,
  2275. configurable: true
  2276. });
  2277. Object.defineProperty(Slider.prototype, "maximum", {
  2278. get: function () {
  2279. return this._maximum;
  2280. },
  2281. set: function (value) {
  2282. if (this._maximum === value) {
  2283. return;
  2284. }
  2285. this._maximum = value;
  2286. this._markAsDirty();
  2287. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2288. },
  2289. enumerable: true,
  2290. configurable: true
  2291. });
  2292. Object.defineProperty(Slider.prototype, "value", {
  2293. get: function () {
  2294. return this._value;
  2295. },
  2296. set: function (value) {
  2297. value = Math.max(Math.min(value, this._maximum), this._minimum);
  2298. if (this._value === value) {
  2299. return;
  2300. }
  2301. this._value = value;
  2302. this._markAsDirty();
  2303. this.onValueChangedObservable.notifyObservers(this._value);
  2304. },
  2305. enumerable: true,
  2306. configurable: true
  2307. });
  2308. Slider.prototype._getTypeName = function () {
  2309. return "Slider";
  2310. };
  2311. Slider.prototype._draw = function (parentMeasure, context) {
  2312. context.save();
  2313. this._applyStates(context);
  2314. if (this._processMeasures(parentMeasure, context)) {
  2315. // Main bar
  2316. var effectiveThumbWidth;
  2317. var effectiveBarOffset;
  2318. if (this._thumbWidth.isPixel) {
  2319. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.height);
  2320. }
  2321. else {
  2322. effectiveThumbWidth = this._currentMeasure.height * this._thumbWidth.getValue(this._host);
  2323. }
  2324. if (this._barOffset.isPixel) {
  2325. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  2326. }
  2327. else {
  2328. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  2329. }
  2330. var left = this._currentMeasure.left + effectiveThumbWidth / 2;
  2331. var width = this._currentMeasure.width - effectiveThumbWidth;
  2332. var thumbPosition = (this._value - this._minimum) / (this._maximum - this._minimum) * width;
  2333. // Bar
  2334. context.fillStyle = this._background;
  2335. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  2336. context.fillStyle = this.color;
  2337. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  2338. // Thumb
  2339. context.fillRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2340. context.strokeStyle = this._borderColor;
  2341. context.strokeRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2342. }
  2343. context.restore();
  2344. };
  2345. Slider.prototype._updateValueFromPointer = function (x) {
  2346. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  2347. };
  2348. Slider.prototype._onPointerDown = function (coordinates) {
  2349. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  2350. return false;
  2351. }
  2352. this._pointerIsDown = true;
  2353. this._updateValueFromPointer(coordinates.x);
  2354. this._host._capturingControl = this;
  2355. return true;
  2356. };
  2357. Slider.prototype._onPointerMove = function (coordinates) {
  2358. if (this._pointerIsDown) {
  2359. this._updateValueFromPointer(coordinates.x);
  2360. }
  2361. };
  2362. Slider.prototype._onPointerUp = function (coordinates) {
  2363. this._pointerIsDown = false;
  2364. this._host._capturingControl = null;
  2365. _super.prototype._onPointerUp.call(this, coordinates);
  2366. };
  2367. return Slider;
  2368. }(GUI.Control));
  2369. GUI.Slider = Slider;
  2370. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2371. })(BABYLON || (BABYLON = {}));
  2372. //# sourceMappingURL=slider.js.map
  2373. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2374. var __extends = (this && this.__extends) || (function () {
  2375. var extendStatics = Object.setPrototypeOf ||
  2376. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2377. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2378. return function (d, b) {
  2379. extendStatics(d, b);
  2380. function __() { this.constructor = d; }
  2381. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2382. };
  2383. })();
  2384. var DOMImage = Image;
  2385. var BABYLON;
  2386. (function (BABYLON) {
  2387. var GUI;
  2388. (function (GUI) {
  2389. var Checkbox = (function (_super) {
  2390. __extends(Checkbox, _super);
  2391. function Checkbox(name) {
  2392. var _this = _super.call(this, name) || this;
  2393. _this.name = name;
  2394. _this._isChecked = false;
  2395. _this._background = "black";
  2396. _this._checkSizeRatio = 0.8;
  2397. _this._thickness = 1;
  2398. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  2399. _this.isPointerBlocker = true;
  2400. return _this;
  2401. }
  2402. Object.defineProperty(Checkbox.prototype, "thickness", {
  2403. get: function () {
  2404. return this._thickness;
  2405. },
  2406. set: function (value) {
  2407. if (this._thickness === value) {
  2408. return;
  2409. }
  2410. this._thickness = value;
  2411. this._markAsDirty();
  2412. },
  2413. enumerable: true,
  2414. configurable: true
  2415. });
  2416. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  2417. get: function () {
  2418. return this._checkSizeRatio;
  2419. },
  2420. set: function (value) {
  2421. value = Math.max(Math.min(1, value), 0);
  2422. if (this._checkSizeRatio === value) {
  2423. return;
  2424. }
  2425. this._checkSizeRatio = value;
  2426. this._markAsDirty();
  2427. },
  2428. enumerable: true,
  2429. configurable: true
  2430. });
  2431. Object.defineProperty(Checkbox.prototype, "background", {
  2432. get: function () {
  2433. return this._background;
  2434. },
  2435. set: function (value) {
  2436. if (this._background === value) {
  2437. return;
  2438. }
  2439. this._background = value;
  2440. this._markAsDirty();
  2441. },
  2442. enumerable: true,
  2443. configurable: true
  2444. });
  2445. Object.defineProperty(Checkbox.prototype, "isChecked", {
  2446. get: function () {
  2447. return this._isChecked;
  2448. },
  2449. set: function (value) {
  2450. if (this._isChecked === value) {
  2451. return;
  2452. }
  2453. this._isChecked = value;
  2454. this._markAsDirty();
  2455. this.onIsCheckedChangedObservable.notifyObservers(value);
  2456. },
  2457. enumerable: true,
  2458. configurable: true
  2459. });
  2460. Checkbox.prototype._getTypeName = function () {
  2461. return "CheckBox";
  2462. };
  2463. Checkbox.prototype._draw = function (parentMeasure, context) {
  2464. context.save();
  2465. this._applyStates(context);
  2466. if (this._processMeasures(parentMeasure, context)) {
  2467. var actualWidth = this._currentMeasure.width - this._thickness;
  2468. var actualHeight = this._currentMeasure.height - this._thickness;
  2469. context.fillStyle = this._background;
  2470. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2471. if (this._isChecked) {
  2472. context.fillStyle = this.color;
  2473. var offsetWidth = actualWidth * this._checkSizeRatio;
  2474. var offseHeight = actualHeight * this._checkSizeRatio;
  2475. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  2476. }
  2477. context.strokeStyle = this.color;
  2478. context.lineWidth = this._thickness;
  2479. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2480. }
  2481. context.restore();
  2482. };
  2483. // Events
  2484. Checkbox.prototype._onPointerDown = function (coordinates) {
  2485. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  2486. return false;
  2487. }
  2488. this.isChecked = !this.isChecked;
  2489. return true;
  2490. };
  2491. return Checkbox;
  2492. }(GUI.Control));
  2493. GUI.Checkbox = Checkbox;
  2494. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2495. })(BABYLON || (BABYLON = {}));
  2496. //# sourceMappingURL=checkBox.js.map
  2497. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2498. var __extends = (this && this.__extends) || (function () {
  2499. var extendStatics = Object.setPrototypeOf ||
  2500. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2501. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2502. return function (d, b) {
  2503. extendStatics(d, b);
  2504. function __() { this.constructor = d; }
  2505. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2506. };
  2507. })();
  2508. var DOMImage = Image;
  2509. var BABYLON;
  2510. (function (BABYLON) {
  2511. var GUI;
  2512. (function (GUI) {
  2513. var RadioButton = (function (_super) {
  2514. __extends(RadioButton, _super);
  2515. function RadioButton(name) {
  2516. var _this = _super.call(this, name) || this;
  2517. _this.name = name;
  2518. _this._isChecked = false;
  2519. _this._background = "black";
  2520. _this._checkSizeRatio = 0.8;
  2521. _this._thickness = 1;
  2522. _this.group = "";
  2523. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  2524. _this.isPointerBlocker = true;
  2525. return _this;
  2526. }
  2527. Object.defineProperty(RadioButton.prototype, "thickness", {
  2528. get: function () {
  2529. return this._thickness;
  2530. },
  2531. set: function (value) {
  2532. if (this._thickness === value) {
  2533. return;
  2534. }
  2535. this._thickness = value;
  2536. this._markAsDirty();
  2537. },
  2538. enumerable: true,
  2539. configurable: true
  2540. });
  2541. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  2542. get: function () {
  2543. return this._checkSizeRatio;
  2544. },
  2545. set: function (value) {
  2546. value = Math.max(Math.min(1, value), 0);
  2547. if (this._checkSizeRatio === value) {
  2548. return;
  2549. }
  2550. this._checkSizeRatio = value;
  2551. this._markAsDirty();
  2552. },
  2553. enumerable: true,
  2554. configurable: true
  2555. });
  2556. Object.defineProperty(RadioButton.prototype, "background", {
  2557. get: function () {
  2558. return this._background;
  2559. },
  2560. set: function (value) {
  2561. if (this._background === value) {
  2562. return;
  2563. }
  2564. this._background = value;
  2565. this._markAsDirty();
  2566. },
  2567. enumerable: true,
  2568. configurable: true
  2569. });
  2570. Object.defineProperty(RadioButton.prototype, "isChecked", {
  2571. get: function () {
  2572. return this._isChecked;
  2573. },
  2574. set: function (value) {
  2575. var _this = this;
  2576. if (this._isChecked === value) {
  2577. return;
  2578. }
  2579. this._isChecked = value;
  2580. this._markAsDirty();
  2581. this.onIsCheckedChangedObservable.notifyObservers(value);
  2582. if (this._isChecked) {
  2583. // Update all controls from same group
  2584. this._host.executeOnAllControls(function (control) {
  2585. if (control === _this) {
  2586. return;
  2587. }
  2588. if (control.group === undefined) {
  2589. return;
  2590. }
  2591. var childRadio = control;
  2592. if (childRadio.group === _this.group) {
  2593. childRadio.isChecked = false;
  2594. }
  2595. });
  2596. }
  2597. },
  2598. enumerable: true,
  2599. configurable: true
  2600. });
  2601. RadioButton.prototype._getTypeName = function () {
  2602. return "RadioButton";
  2603. };
  2604. RadioButton.prototype._draw = function (parentMeasure, context) {
  2605. context.save();
  2606. this._applyStates(context);
  2607. if (this._processMeasures(parentMeasure, context)) {
  2608. var actualWidth = this._currentMeasure.width - this._thickness;
  2609. var actualHeight = this._currentMeasure.height - this._thickness;
  2610. // Outer
  2611. 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);
  2612. context.fillStyle = this._background;
  2613. context.fill();
  2614. context.strokeStyle = this.color;
  2615. context.lineWidth = this._thickness;
  2616. context.stroke();
  2617. // Inner
  2618. if (this._isChecked) {
  2619. context.fillStyle = this.color;
  2620. var offsetWidth = actualWidth * this._checkSizeRatio;
  2621. var offseHeight = actualHeight * this._checkSizeRatio;
  2622. 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);
  2623. context.fill();
  2624. }
  2625. }
  2626. context.restore();
  2627. };
  2628. // Events
  2629. RadioButton.prototype._onPointerDown = function (coordinates) {
  2630. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  2631. return false;
  2632. }
  2633. this.isChecked = !this.isChecked;
  2634. return true;
  2635. };
  2636. return RadioButton;
  2637. }(GUI.Control));
  2638. GUI.RadioButton = RadioButton;
  2639. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2640. })(BABYLON || (BABYLON = {}));
  2641. //# sourceMappingURL=radioButton.js.map
  2642. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2643. var __extends = (this && this.__extends) || (function () {
  2644. var extendStatics = Object.setPrototypeOf ||
  2645. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2646. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2647. return function (d, b) {
  2648. extendStatics(d, b);
  2649. function __() { this.constructor = d; }
  2650. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2651. };
  2652. })();
  2653. var BABYLON;
  2654. (function (BABYLON) {
  2655. var GUI;
  2656. (function (GUI) {
  2657. var TextBlock = (function (_super) {
  2658. __extends(TextBlock, _super);
  2659. function TextBlock(name, text) {
  2660. if (text === void 0) { text = ""; }
  2661. var _this = _super.call(this, name) || this;
  2662. _this.name = name;
  2663. _this._text = "";
  2664. _this._textWrapping = false;
  2665. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  2666. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  2667. _this.text = text;
  2668. return _this;
  2669. }
  2670. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  2671. get: function () {
  2672. return this._textWrapping;
  2673. },
  2674. set: function (value) {
  2675. if (this._textWrapping === value) {
  2676. return;
  2677. }
  2678. this._textWrapping = value;
  2679. this._markAsDirty();
  2680. },
  2681. enumerable: true,
  2682. configurable: true
  2683. });
  2684. Object.defineProperty(TextBlock.prototype, "text", {
  2685. get: function () {
  2686. return this._text;
  2687. },
  2688. set: function (value) {
  2689. if (this._text === value) {
  2690. return;
  2691. }
  2692. this._text = value;
  2693. this._markAsDirty();
  2694. },
  2695. enumerable: true,
  2696. configurable: true
  2697. });
  2698. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  2699. get: function () {
  2700. return this._textHorizontalAlignment;
  2701. },
  2702. set: function (value) {
  2703. if (this._textHorizontalAlignment === value) {
  2704. return;
  2705. }
  2706. this._textHorizontalAlignment = value;
  2707. this._markAsDirty();
  2708. },
  2709. enumerable: true,
  2710. configurable: true
  2711. });
  2712. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  2713. get: function () {
  2714. return this._textVerticalAlignment;
  2715. },
  2716. set: function (value) {
  2717. if (this._textVerticalAlignment === value) {
  2718. return;
  2719. }
  2720. this._textVerticalAlignment = value;
  2721. this._markAsDirty();
  2722. },
  2723. enumerable: true,
  2724. configurable: true
  2725. });
  2726. TextBlock.prototype._getTypeName = function () {
  2727. return "TextBlock";
  2728. };
  2729. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  2730. var width = this._currentMeasure.width;
  2731. var x = 0;
  2732. switch (this._textHorizontalAlignment) {
  2733. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  2734. x = 0;
  2735. break;
  2736. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  2737. x = width - textWidth;
  2738. break;
  2739. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  2740. x = (width - textWidth) / 2;
  2741. break;
  2742. }
  2743. context.fillText(text, this._currentMeasure.left + x, y);
  2744. };
  2745. TextBlock.prototype._draw = function (parentMeasure, context) {
  2746. context.save();
  2747. this._applyStates(context);
  2748. if (this._processMeasures(parentMeasure, context)) {
  2749. // Render lines
  2750. this._renderLines(context);
  2751. }
  2752. context.restore();
  2753. };
  2754. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  2755. this._lines = [];
  2756. if (this._textWrapping) {
  2757. var words = this.text.split(' ');
  2758. var line = '';
  2759. var width = this._currentMeasure.width;
  2760. var lineWidth = 0;
  2761. for (var n = 0; n < words.length; n++) {
  2762. var testLine = n > 0 ? line + " " + words[n] : words[0];
  2763. var metrics = context.measureText(testLine);
  2764. var testWidth = metrics.width;
  2765. if (testWidth > width && n > 0) {
  2766. this._lines.push({ text: line, width: lineWidth });
  2767. line = words[n];
  2768. lineWidth = context.measureText(line).width;
  2769. }
  2770. else {
  2771. lineWidth = testWidth;
  2772. line = testLine;
  2773. }
  2774. }
  2775. this._lines.push({ text: line, width: lineWidth });
  2776. }
  2777. else {
  2778. this._lines.push({ text: this.text, width: context.measureText(this.text).width });
  2779. }
  2780. };
  2781. TextBlock.prototype._renderLines = function (context) {
  2782. var width = this._currentMeasure.width;
  2783. var height = this._currentMeasure.height;
  2784. if (!this._fontOffset) {
  2785. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  2786. }
  2787. var rootY = 0;
  2788. switch (this._textVerticalAlignment) {
  2789. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  2790. rootY = this._fontOffset.ascent;
  2791. break;
  2792. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  2793. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  2794. break;
  2795. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  2796. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  2797. break;
  2798. }
  2799. rootY += this._currentMeasure.top;
  2800. for (var _i = 0, _a = this._lines; _i < _a.length; _i++) {
  2801. var line = _a[_i];
  2802. this._drawText(line.text, line.width, rootY, context);
  2803. rootY += this._fontOffset.height;
  2804. }
  2805. };
  2806. return TextBlock;
  2807. }(GUI.Control));
  2808. GUI.TextBlock = TextBlock;
  2809. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2810. })(BABYLON || (BABYLON = {}));
  2811. //# sourceMappingURL=textBlock.js.map
  2812. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2813. var __extends = (this && this.__extends) || (function () {
  2814. var extendStatics = Object.setPrototypeOf ||
  2815. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2816. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2817. return function (d, b) {
  2818. extendStatics(d, b);
  2819. function __() { this.constructor = d; }
  2820. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2821. };
  2822. })();
  2823. var DOMImage = Image;
  2824. var BABYLON;
  2825. (function (BABYLON) {
  2826. var GUI;
  2827. (function (GUI) {
  2828. var Image = (function (_super) {
  2829. __extends(Image, _super);
  2830. function Image(name, url) {
  2831. var _this = _super.call(this, name) || this;
  2832. _this.name = name;
  2833. _this._loaded = false;
  2834. _this._stretch = Image.STRETCH_FILL;
  2835. _this._autoScale = false;
  2836. _this._sourceLeft = 0;
  2837. _this._sourceTop = 0;
  2838. _this._sourceWidth = 0;
  2839. _this._sourceHeight = 0;
  2840. _this.source = url;
  2841. return _this;
  2842. }
  2843. Object.defineProperty(Image.prototype, "sourceLeft", {
  2844. get: function () {
  2845. return this._sourceLeft;
  2846. },
  2847. set: function (value) {
  2848. if (this._sourceLeft === value) {
  2849. return;
  2850. }
  2851. this._sourceLeft = value;
  2852. this._markAsDirty();
  2853. },
  2854. enumerable: true,
  2855. configurable: true
  2856. });
  2857. Object.defineProperty(Image.prototype, "sourceTop", {
  2858. get: function () {
  2859. return this._sourceTop;
  2860. },
  2861. set: function (value) {
  2862. if (this._sourceTop === value) {
  2863. return;
  2864. }
  2865. this._sourceTop = value;
  2866. this._markAsDirty();
  2867. },
  2868. enumerable: true,
  2869. configurable: true
  2870. });
  2871. Object.defineProperty(Image.prototype, "sourceWidth", {
  2872. get: function () {
  2873. return this._sourceWidth;
  2874. },
  2875. set: function (value) {
  2876. if (this._sourceWidth === value) {
  2877. return;
  2878. }
  2879. this._sourceWidth = value;
  2880. this._markAsDirty();
  2881. },
  2882. enumerable: true,
  2883. configurable: true
  2884. });
  2885. Object.defineProperty(Image.prototype, "sourceHeight", {
  2886. get: function () {
  2887. return this._sourceHeight;
  2888. },
  2889. set: function (value) {
  2890. if (this._sourceHeight === value) {
  2891. return;
  2892. }
  2893. this._sourceHeight = value;
  2894. this._markAsDirty();
  2895. },
  2896. enumerable: true,
  2897. configurable: true
  2898. });
  2899. Object.defineProperty(Image.prototype, "autoScale", {
  2900. get: function () {
  2901. return this._autoScale;
  2902. },
  2903. set: function (value) {
  2904. if (this._autoScale === value) {
  2905. return;
  2906. }
  2907. this._autoScale = value;
  2908. if (value && this._loaded) {
  2909. this.synchronizeSizeWithContent();
  2910. }
  2911. },
  2912. enumerable: true,
  2913. configurable: true
  2914. });
  2915. Object.defineProperty(Image.prototype, "stretch", {
  2916. get: function () {
  2917. return this._stretch;
  2918. },
  2919. set: function (value) {
  2920. if (this._stretch === value) {
  2921. return;
  2922. }
  2923. this._stretch = value;
  2924. this._markAsDirty();
  2925. },
  2926. enumerable: true,
  2927. configurable: true
  2928. });
  2929. Object.defineProperty(Image.prototype, "domImage", {
  2930. get: function () {
  2931. return this._domImage;
  2932. },
  2933. set: function (value) {
  2934. var _this = this;
  2935. this._domImage = value;
  2936. this._loaded = false;
  2937. if (this._domImage.width) {
  2938. this._onImageLoaded();
  2939. }
  2940. else {
  2941. this._domImage.onload = function () {
  2942. _this._onImageLoaded();
  2943. };
  2944. }
  2945. },
  2946. enumerable: true,
  2947. configurable: true
  2948. });
  2949. Image.prototype._onImageLoaded = function () {
  2950. this._imageWidth = this._domImage.width;
  2951. this._imageHeight = this._domImage.height;
  2952. this._loaded = true;
  2953. if (this._autoScale) {
  2954. this.synchronizeSizeWithContent();
  2955. }
  2956. this._markAsDirty();
  2957. };
  2958. Object.defineProperty(Image.prototype, "source", {
  2959. set: function (value) {
  2960. var _this = this;
  2961. if (this._source === value) {
  2962. return;
  2963. }
  2964. this._loaded = false;
  2965. this._source = value;
  2966. this._domImage = new DOMImage();
  2967. this._domImage.onload = function () {
  2968. _this._onImageLoaded();
  2969. };
  2970. this._domImage.crossOrigin = "anonymous";
  2971. this._domImage.src = value;
  2972. },
  2973. enumerable: true,
  2974. configurable: true
  2975. });
  2976. Image.prototype._getTypeName = function () {
  2977. return "Image";
  2978. };
  2979. Image.prototype.synchronizeSizeWithContent = function () {
  2980. if (!this._loaded) {
  2981. return;
  2982. }
  2983. this.width = this._domImage.width + "px";
  2984. this.height = this._domImage.height + "px";
  2985. };
  2986. Image.prototype._draw = function (parentMeasure, context) {
  2987. context.save();
  2988. var x = this._sourceLeft;
  2989. var y = this._sourceTop;
  2990. var width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  2991. var height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  2992. this._applyStates(context);
  2993. if (this._processMeasures(parentMeasure, context)) {
  2994. if (this._loaded) {
  2995. switch (this._stretch) {
  2996. case Image.STRETCH_NONE:
  2997. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2998. break;
  2999. case Image.STRETCH_FILL:
  3000. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3001. break;
  3002. case Image.STRETCH_UNIFORM:
  3003. var hRatio = this._currentMeasure.width / width;
  3004. var vRatio = this._currentMeasure.height / height;
  3005. var ratio = Math.min(hRatio, vRatio);
  3006. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  3007. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  3008. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  3009. break;
  3010. case Image.STRETCH_EXTEND:
  3011. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3012. if (this._autoScale) {
  3013. this.synchronizeSizeWithContent();
  3014. }
  3015. this._root.width = this.width;
  3016. this._root.height = this.height;
  3017. break;
  3018. }
  3019. }
  3020. }
  3021. context.restore();
  3022. };
  3023. Object.defineProperty(Image, "STRETCH_NONE", {
  3024. get: function () {
  3025. return Image._STRETCH_NONE;
  3026. },
  3027. enumerable: true,
  3028. configurable: true
  3029. });
  3030. Object.defineProperty(Image, "STRETCH_FILL", {
  3031. get: function () {
  3032. return Image._STRETCH_FILL;
  3033. },
  3034. enumerable: true,
  3035. configurable: true
  3036. });
  3037. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  3038. get: function () {
  3039. return Image._STRETCH_UNIFORM;
  3040. },
  3041. enumerable: true,
  3042. configurable: true
  3043. });
  3044. Object.defineProperty(Image, "STRETCH_EXTEND", {
  3045. get: function () {
  3046. return Image._STRETCH_EXTEND;
  3047. },
  3048. enumerable: true,
  3049. configurable: true
  3050. });
  3051. return Image;
  3052. }(GUI.Control));
  3053. // Static
  3054. Image._STRETCH_NONE = 0;
  3055. Image._STRETCH_FILL = 1;
  3056. Image._STRETCH_UNIFORM = 2;
  3057. Image._STRETCH_EXTEND = 3;
  3058. GUI.Image = Image;
  3059. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3060. })(BABYLON || (BABYLON = {}));
  3061. //# sourceMappingURL=image.js.map
  3062. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3063. var __extends = (this && this.__extends) || (function () {
  3064. var extendStatics = Object.setPrototypeOf ||
  3065. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3066. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3067. return function (d, b) {
  3068. extendStatics(d, b);
  3069. function __() { this.constructor = d; }
  3070. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3071. };
  3072. })();
  3073. var BABYLON;
  3074. (function (BABYLON) {
  3075. var GUI;
  3076. (function (GUI) {
  3077. var Button = (function (_super) {
  3078. __extends(Button, _super);
  3079. function Button(name) {
  3080. var _this = _super.call(this, name) || this;
  3081. _this.name = name;
  3082. _this.thickness = 1;
  3083. _this.isPointerBlocker = true;
  3084. _this.pointerEnterAnimation = function () {
  3085. _this.alpha -= 0.1;
  3086. };
  3087. _this.pointerOutAnimation = function () {
  3088. _this.alpha += 0.1;
  3089. };
  3090. _this.pointerDownAnimation = function () {
  3091. _this.scaleX -= 0.05;
  3092. _this.scaleY -= 0.05;
  3093. };
  3094. _this.pointerUpAnimation = function () {
  3095. _this.scaleX += 0.05;
  3096. _this.scaleY += 0.05;
  3097. };
  3098. return _this;
  3099. }
  3100. Button.prototype._getTypeName = function () {
  3101. return "Button";
  3102. };
  3103. // While being a container, the button behaves like a control.
  3104. Button.prototype._processPicking = function (x, y, type) {
  3105. if (!this.contains(x, y)) {
  3106. return false;
  3107. }
  3108. this._processObservables(type, x, y);
  3109. return true;
  3110. };
  3111. Button.prototype._onPointerEnter = function () {
  3112. if (!_super.prototype._onPointerEnter.call(this)) {
  3113. return false;
  3114. }
  3115. if (this.pointerEnterAnimation) {
  3116. this.pointerEnterAnimation();
  3117. }
  3118. return true;
  3119. };
  3120. Button.prototype._onPointerOut = function () {
  3121. if (this.pointerOutAnimation) {
  3122. this.pointerOutAnimation();
  3123. }
  3124. _super.prototype._onPointerOut.call(this);
  3125. };
  3126. Button.prototype._onPointerDown = function (coordinates) {
  3127. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  3128. return false;
  3129. }
  3130. if (this.pointerDownAnimation) {
  3131. this.pointerDownAnimation();
  3132. }
  3133. return true;
  3134. };
  3135. Button.prototype._onPointerUp = function (coordinates) {
  3136. if (this.pointerUpAnimation) {
  3137. this.pointerUpAnimation();
  3138. }
  3139. _super.prototype._onPointerUp.call(this, coordinates);
  3140. };
  3141. // Statics
  3142. Button.CreateImageButton = function (name, text, imageUrl) {
  3143. var result = new Button(name);
  3144. // Adding text
  3145. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3146. textBlock.textWrapping = true;
  3147. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3148. textBlock.paddingLeft = "20%";
  3149. result.addControl(textBlock);
  3150. // Adding image
  3151. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3152. iconImage.width = "20%";
  3153. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  3154. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3155. result.addControl(iconImage);
  3156. return result;
  3157. };
  3158. Button.CreateImageOnlyButton = function (name, imageUrl) {
  3159. var result = new Button(name);
  3160. // Adding image
  3161. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  3162. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  3163. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3164. result.addControl(iconImage);
  3165. return result;
  3166. };
  3167. Button.CreateSimpleButton = function (name, text) {
  3168. var result = new Button(name);
  3169. // Adding text
  3170. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  3171. textBlock.textWrapping = true;
  3172. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3173. result.addControl(textBlock);
  3174. return result;
  3175. };
  3176. return Button;
  3177. }(GUI.Rectangle));
  3178. GUI.Button = Button;
  3179. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3180. })(BABYLON || (BABYLON = {}));
  3181. //# sourceMappingURL=button.js.map
  3182. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3183. var __extends = (this && this.__extends) || (function () {
  3184. var extendStatics = Object.setPrototypeOf ||
  3185. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3186. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3187. return function (d, b) {
  3188. extendStatics(d, b);
  3189. function __() { this.constructor = d; }
  3190. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3191. };
  3192. })();
  3193. var DOMImage = Image;
  3194. var BABYLON;
  3195. (function (BABYLON) {
  3196. var GUI;
  3197. (function (GUI) {
  3198. var ColorPicker = (function (_super) {
  3199. __extends(ColorPicker, _super);
  3200. function ColorPicker(name) {
  3201. var _this = _super.call(this, name) || this;
  3202. _this.name = name;
  3203. _this._value = BABYLON.Color3.Red();
  3204. _this._tmpColor = new BABYLON.Color3();
  3205. _this._pointerStartedOnSquare = false;
  3206. _this._pointerStartedOnWheel = false;
  3207. _this._squareLeft = 0;
  3208. _this._squareTop = 0;
  3209. _this._squareSize = 0;
  3210. _this._h = 360;
  3211. _this._s = 1;
  3212. _this._v = 1;
  3213. _this.onValueChangedObservable = new BABYLON.Observable();
  3214. // Events
  3215. _this._pointerIsDown = false;
  3216. _this.value = new BABYLON.Color3(.88, .1, .1);
  3217. _this.size = "200px";
  3218. _this.isPointerBlocker = true;
  3219. return _this;
  3220. }
  3221. Object.defineProperty(ColorPicker.prototype, "value", {
  3222. get: function () {
  3223. return this._value;
  3224. },
  3225. set: function (value) {
  3226. if (this._value.equals(value)) {
  3227. return;
  3228. }
  3229. this._value.copyFrom(value);
  3230. this._RGBtoHSV(this._value, this._tmpColor);
  3231. this._h = this._tmpColor.r;
  3232. this._s = Math.max(this._tmpColor.g, 0.00001);
  3233. this._v = Math.max(this._tmpColor.b, 0.00001);
  3234. this._markAsDirty();
  3235. this.onValueChangedObservable.notifyObservers(this._value);
  3236. },
  3237. enumerable: true,
  3238. configurable: true
  3239. });
  3240. Object.defineProperty(ColorPicker.prototype, "width", {
  3241. set: function (value) {
  3242. if (this._width.toString(this._host) === value) {
  3243. return;
  3244. }
  3245. if (this._width.fromString(value)) {
  3246. this._height.fromString(value);
  3247. this._markAsDirty();
  3248. }
  3249. },
  3250. enumerable: true,
  3251. configurable: true
  3252. });
  3253. Object.defineProperty(ColorPicker.prototype, "height", {
  3254. set: function (value) {
  3255. if (this._height.toString(this._host) === value) {
  3256. return;
  3257. }
  3258. if (this._height.fromString(value)) {
  3259. this._width.fromString(value);
  3260. this._markAsDirty();
  3261. }
  3262. },
  3263. enumerable: true,
  3264. configurable: true
  3265. });
  3266. Object.defineProperty(ColorPicker.prototype, "size", {
  3267. get: function () {
  3268. return this.width;
  3269. },
  3270. set: function (value) {
  3271. this.width = value;
  3272. },
  3273. enumerable: true,
  3274. configurable: true
  3275. });
  3276. ColorPicker.prototype._getTypeName = function () {
  3277. return "ColorPicker";
  3278. };
  3279. ColorPicker.prototype._updateSquareProps = function () {
  3280. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3281. var wheelThickness = radius * .2;
  3282. var innerDiameter = (radius - wheelThickness) * 2;
  3283. var squareSize = innerDiameter / (Math.sqrt(2));
  3284. var offset = radius - squareSize * .5;
  3285. this._squareLeft = this._currentMeasure.left + offset;
  3286. this._squareTop = this._currentMeasure.top + offset;
  3287. this._squareSize = squareSize;
  3288. };
  3289. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  3290. var lgh = context.createLinearGradient(left, top, width + left, top);
  3291. lgh.addColorStop(0, '#fff');
  3292. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  3293. context.fillStyle = lgh;
  3294. context.fillRect(left, top, width, height);
  3295. var lgv = context.createLinearGradient(left, top, left, height + top);
  3296. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  3297. lgv.addColorStop(1, '#000');
  3298. context.fillStyle = lgv;
  3299. context.fillRect(left, top, width, height);
  3300. };
  3301. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  3302. context.beginPath();
  3303. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  3304. context.lineWidth = 3;
  3305. context.strokeStyle = '#333333';
  3306. context.stroke();
  3307. context.beginPath();
  3308. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  3309. context.lineWidth = 3;
  3310. context.strokeStyle = '#ffffff';
  3311. context.stroke();
  3312. };
  3313. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  3314. var canvas = document.createElement("canvas");
  3315. canvas.width = radius * 2;
  3316. canvas.height = radius * 2;
  3317. var context = canvas.getContext("2d");
  3318. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  3319. var data = image.data;
  3320. var color = this._tmpColor;
  3321. var maxDistSq = radius * radius;
  3322. var innerRadius = radius - thickness;
  3323. var minDistSq = innerRadius * innerRadius;
  3324. for (var x = -radius; x < radius; x++) {
  3325. for (var y = -radius; y < radius; y++) {
  3326. var distSq = x * x + y * y;
  3327. if (distSq > maxDistSq || distSq < minDistSq) {
  3328. continue;
  3329. }
  3330. var dist = Math.sqrt(distSq);
  3331. var ang = Math.atan2(y, x);
  3332. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  3333. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  3334. data[index] = color.r * 255;
  3335. data[index + 1] = color.g * 255;
  3336. data[index + 2] = color.b * 255;
  3337. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  3338. //apply less alpha to bigger color pickers
  3339. var alphaAmount = .2;
  3340. var maxAlpha = .2;
  3341. var minAlpha = .04;
  3342. var lowerRadius = 50;
  3343. var upperRadius = 150;
  3344. if (radius < lowerRadius) {
  3345. alphaAmount = maxAlpha;
  3346. }
  3347. else if (radius > upperRadius) {
  3348. alphaAmount = minAlpha;
  3349. }
  3350. else {
  3351. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  3352. }
  3353. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  3354. if (alphaRatio < alphaAmount) {
  3355. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  3356. }
  3357. else if (alphaRatio > 1 - alphaAmount) {
  3358. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  3359. }
  3360. else {
  3361. data[index + 3] = 255;
  3362. }
  3363. }
  3364. }
  3365. context.putImageData(image, 0, 0);
  3366. return canvas;
  3367. };
  3368. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  3369. var r = color.r;
  3370. var g = color.g;
  3371. var b = color.b;
  3372. var max = Math.max(r, g, b);
  3373. var min = Math.min(r, g, b);
  3374. var h = 0;
  3375. var s = 0;
  3376. var v = max;
  3377. var dm = max - min;
  3378. if (max !== 0) {
  3379. s = dm / max;
  3380. }
  3381. if (max != min) {
  3382. if (max == r) {
  3383. h = (g - b) / dm;
  3384. if (g < b) {
  3385. h += 6;
  3386. }
  3387. }
  3388. else if (max == g) {
  3389. h = (b - r) / dm + 2;
  3390. }
  3391. else if (max == b) {
  3392. h = (r - g) / dm + 4;
  3393. }
  3394. h *= 60;
  3395. }
  3396. result.r = h;
  3397. result.g = s;
  3398. result.b = v;
  3399. };
  3400. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  3401. var chroma = value * saturation;
  3402. var h = hue / 60;
  3403. var x = chroma * (1 - Math.abs((h % 2) - 1));
  3404. var r = 0;
  3405. var g = 0;
  3406. var b = 0;
  3407. if (h >= 0 && h <= 1) {
  3408. r = chroma;
  3409. g = x;
  3410. }
  3411. else if (h >= 1 && h <= 2) {
  3412. r = x;
  3413. g = chroma;
  3414. }
  3415. else if (h >= 2 && h <= 3) {
  3416. g = chroma;
  3417. b = x;
  3418. }
  3419. else if (h >= 3 && h <= 4) {
  3420. g = x;
  3421. b = chroma;
  3422. }
  3423. else if (h >= 4 && h <= 5) {
  3424. r = x;
  3425. b = chroma;
  3426. }
  3427. else if (h >= 5 && h <= 6) {
  3428. r = chroma;
  3429. b = x;
  3430. }
  3431. var m = value - chroma;
  3432. result.set((r + m), (g + m), (b + m));
  3433. };
  3434. ColorPicker.prototype._draw = function (parentMeasure, context) {
  3435. context.save();
  3436. this._applyStates(context);
  3437. if (this._processMeasures(parentMeasure, context)) {
  3438. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3439. var wheelThickness = radius * .2;
  3440. var left = this._currentMeasure.left;
  3441. var top = this._currentMeasure.top;
  3442. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  3443. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  3444. }
  3445. context.drawImage(this._colorWheelCanvas, left, top);
  3446. this._updateSquareProps();
  3447. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  3448. var cx = this._squareLeft + this._squareSize * this._s;
  3449. var cy = this._squareTop + this._squareSize * (1 - this._v);
  3450. this._drawCircle(cx, cy, radius * .04, context);
  3451. var dist = radius - wheelThickness * .5;
  3452. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  3453. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  3454. this._drawCircle(cx, cy, wheelThickness * .35, context);
  3455. }
  3456. context.restore();
  3457. };
  3458. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  3459. if (this._pointerStartedOnWheel) {
  3460. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3461. var centerX = radius + this._currentMeasure.left;
  3462. var centerY = radius + this._currentMeasure.top;
  3463. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  3464. }
  3465. else if (this._pointerStartedOnSquare) {
  3466. this._updateSquareProps();
  3467. this._s = (x - this._squareLeft) / this._squareSize;
  3468. this._v = 1 - (y - this._squareTop) / this._squareSize;
  3469. this._s = Math.min(this._s, 1);
  3470. this._s = Math.max(this._s, 0.00001);
  3471. this._v = Math.min(this._v, 1);
  3472. this._v = Math.max(this._v, 0.00001);
  3473. }
  3474. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  3475. this.value = this._tmpColor;
  3476. };
  3477. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  3478. this._updateSquareProps();
  3479. var left = this._squareLeft;
  3480. var top = this._squareTop;
  3481. var size = this._squareSize;
  3482. if (coordinates.x >= left && coordinates.x <= left + size &&
  3483. coordinates.y >= top && coordinates.y <= top + size) {
  3484. return true;
  3485. }
  3486. return false;
  3487. };
  3488. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  3489. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  3490. var centerX = radius + this._currentMeasure.left;
  3491. var centerY = radius + this._currentMeasure.top;
  3492. var wheelThickness = radius * .2;
  3493. var innerRadius = radius - wheelThickness;
  3494. var radiusSq = radius * radius;
  3495. var innerRadiusSq = innerRadius * innerRadius;
  3496. var dx = coordinates.x - centerX;
  3497. var dy = coordinates.y - centerY;
  3498. var distSq = dx * dx + dy * dy;
  3499. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  3500. return true;
  3501. }
  3502. return false;
  3503. };
  3504. ColorPicker.prototype._onPointerDown = function (coordinates) {
  3505. if (!_super.prototype._onPointerDown.call(this, coordinates)) {
  3506. return false;
  3507. }
  3508. this._pointerIsDown = true;
  3509. this._pointerStartedOnSquare = false;
  3510. this._pointerStartedOnWheel = false;
  3511. if (this._isPointOnSquare(coordinates)) {
  3512. this._pointerStartedOnSquare = true;
  3513. }
  3514. else if (this._isPointOnWheel(coordinates)) {
  3515. this._pointerStartedOnWheel = true;
  3516. }
  3517. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3518. this._host._capturingControl = this;
  3519. return true;
  3520. };
  3521. ColorPicker.prototype._onPointerMove = function (coordinates) {
  3522. if (this._pointerIsDown) {
  3523. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3524. }
  3525. _super.prototype._onPointerMove.call(this, coordinates);
  3526. };
  3527. ColorPicker.prototype._onPointerUp = function (coordinates) {
  3528. this._pointerIsDown = false;
  3529. this._host._capturingControl = null;
  3530. _super.prototype._onPointerUp.call(this, coordinates);
  3531. };
  3532. return ColorPicker;
  3533. }(GUI.Control));
  3534. GUI.ColorPicker = ColorPicker;
  3535. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3536. })(BABYLON || (BABYLON = {}));