babylon.gui.js 102 KB

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