babylon.gui.js 148 KB

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