babylon.gui.js 121 KB

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