babylon.gui.js 156 KB

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