babylon.gui.js 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  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._renderObserver = _this.getScene().onBeforeRenderObservable.add(function () { return _this._checkUpdate(); });
  27. _this._rootContainer._link(null, _this);
  28. _this.hasAlpha = true;
  29. if (!width || !height) {
  30. _this._resizeObserver = _this.getScene().getEngine().onResizeObservable.add(function () { return _this._onResize(); });
  31. _this._onResize();
  32. }
  33. return _this;
  34. }
  35. Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
  36. get: function () {
  37. return this._background;
  38. },
  39. set: function (value) {
  40. if (this._background === value) {
  41. return;
  42. }
  43. this._background = value;
  44. this.markAsDirty();
  45. },
  46. enumerable: true,
  47. configurable: true
  48. });
  49. AdvancedDynamicTexture.prototype.markAsDirty = function () {
  50. this._isDirty = true;
  51. };
  52. AdvancedDynamicTexture.prototype.addControl = function (control) {
  53. this._rootContainer.addControl(control);
  54. return this;
  55. };
  56. AdvancedDynamicTexture.prototype.removeControl = function (control) {
  57. this._rootContainer.removeControl(control);
  58. return this;
  59. };
  60. AdvancedDynamicTexture.prototype.dispose = function () {
  61. this.getScene().onBeforeRenderObservable.remove(this._renderObserver);
  62. if (this._resizeObserver) {
  63. this.getScene().getEngine().onResizeObservable.remove(this._resizeObserver);
  64. }
  65. if (this._pointerMoveObserver) {
  66. this.getScene().onPrePointerObservable.remove(this._pointerMoveObserver);
  67. }
  68. if (this._toDispose) {
  69. this._toDispose.dispose();
  70. this._toDispose = null;
  71. }
  72. _super.prototype.dispose.call(this);
  73. };
  74. AdvancedDynamicTexture.prototype._onResize = function () {
  75. // Check size
  76. var engine = this.getScene().getEngine();
  77. var textureSize = this.getSize();
  78. var renderWidth = engine.getRenderWidth();
  79. var renderHeight = engine.getRenderHeight();
  80. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  81. this.scaleTo(renderWidth, renderHeight);
  82. this.markAsDirty();
  83. }
  84. };
  85. AdvancedDynamicTexture.prototype._checkUpdate = function () {
  86. if (!this._isDirty && !this._rootContainer.isDirty) {
  87. return;
  88. }
  89. this._isDirty = false;
  90. this._render();
  91. this.update();
  92. };
  93. AdvancedDynamicTexture.prototype._render = function () {
  94. var textureSize = this.getSize();
  95. var renderWidth = textureSize.width;
  96. var renderHeight = textureSize.height;
  97. // Clear
  98. var context = this.getContext();
  99. context.clearRect(0, 0, renderWidth, renderHeight);
  100. if (this._background) {
  101. context.save();
  102. context.fillStyle = this._background;
  103. context.fillRect(0, 0, renderWidth, renderHeight);
  104. context.restore();
  105. }
  106. // Render
  107. var measure = new GUI.Measure(0, 0, renderWidth, renderHeight);
  108. this._rootContainer._draw(measure, context);
  109. };
  110. AdvancedDynamicTexture.prototype._doPicking = function (x, y, type) {
  111. if (!this._rootContainer._processPicking(x, y, type)) {
  112. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  113. if (this._lastControlOver && this._lastControlOver.onPointerOutObservable.hasObservers()) {
  114. this._lastControlOver.onPointerOutObservable.notifyObservers(this._lastControlOver);
  115. }
  116. this._lastControlOver = null;
  117. }
  118. }
  119. };
  120. AdvancedDynamicTexture.prototype.attach = function () {
  121. var _this = this;
  122. var scene = this.getScene();
  123. this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
  124. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  125. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  126. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  127. return;
  128. }
  129. _this._shouldBlockPointer = false;
  130. _this._doPicking(scene.pointerX, scene.pointerY, pi.type);
  131. pi.skipOnPointerObservable = _this._shouldBlockPointer;
  132. });
  133. };
  134. // Statics
  135. AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height) {
  136. if (width === void 0) { width = 1024; }
  137. if (height === void 0) { height = 1024; }
  138. var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  139. var material = new BABYLON.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
  140. material.backFaceCulling = false;
  141. material.emissiveTexture = result;
  142. material.opacityTexture = result;
  143. mesh.material = material;
  144. return result;
  145. };
  146. AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene) {
  147. if (foreground === void 0) { foreground = true; }
  148. var result = new AdvancedDynamicTexture(name, 0, 0, scene);
  149. // Display
  150. var layer = new BABYLON.Layer(name + "_layer", null, scene, !foreground);
  151. layer.texture = result;
  152. result._toDispose = layer;
  153. // Attach
  154. result.attach();
  155. return result;
  156. };
  157. return AdvancedDynamicTexture;
  158. }(BABYLON.DynamicTexture));
  159. GUI.AdvancedDynamicTexture = AdvancedDynamicTexture;
  160. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  161. })(BABYLON || (BABYLON = {}));
  162. //# sourceMappingURL=advancedDynamicTexture.js.map
  163. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  164. var BABYLON;
  165. (function (BABYLON) {
  166. var GUI;
  167. (function (GUI) {
  168. var Measure = (function () {
  169. function Measure(left, top, width, height) {
  170. this.left = left;
  171. this.top = top;
  172. this.width = width;
  173. this.height = height;
  174. }
  175. Measure.prototype.copyFrom = function (other) {
  176. this.left = other.left;
  177. this.top = other.top;
  178. this.width = other.width;
  179. this.height = other.height;
  180. };
  181. Measure.prototype.isEqualsTo = function (other) {
  182. if (this.left !== other.left) {
  183. return false;
  184. }
  185. if (this.top !== other.top) {
  186. return false;
  187. }
  188. if (this.width !== other.width) {
  189. return false;
  190. }
  191. if (this.height !== other.height) {
  192. return false;
  193. }
  194. return true;
  195. };
  196. Measure.Empty = function () {
  197. return new Measure(0, 0, 0, 0);
  198. };
  199. return Measure;
  200. }());
  201. GUI.Measure = Measure;
  202. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  203. })(BABYLON || (BABYLON = {}));
  204. //# sourceMappingURL=measure.js.map
  205. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  206. var BABYLON;
  207. (function (BABYLON) {
  208. var GUI;
  209. (function (GUI) {
  210. var Matrix2D = (function () {
  211. function Matrix2D(m00, m01, m10, m11, m20, m21) {
  212. this.m = new Float32Array(6);
  213. this.fromValues(m00, m01, m10, m11, m20, m21);
  214. }
  215. Matrix2D.prototype.fromValues = function (m00, m01, m10, m11, m20, m21) {
  216. this.m[0] = m00;
  217. this.m[1] = m01;
  218. this.m[2] = m10;
  219. this.m[3] = m11;
  220. this.m[4] = m20;
  221. this.m[5] = m21;
  222. return this;
  223. };
  224. Matrix2D.prototype.determinant = function () {
  225. return this.m[0] * this.m[3] - this.m[1] * this.m[2];
  226. };
  227. Matrix2D.prototype.invertToRef = function (result) {
  228. var l0 = this.m[0];
  229. var l1 = this.m[1];
  230. var l2 = this.m[2];
  231. var l3 = this.m[3];
  232. var l4 = this.m[4];
  233. var l5 = this.m[5];
  234. var det = this.determinant();
  235. if (det < (BABYLON.Epsilon * BABYLON.Epsilon)) {
  236. throw new Error("Can't invert matrix, near null determinant");
  237. }
  238. var detDiv = 1 / det;
  239. var det4 = l2 * l5 - l3 * l4;
  240. var det5 = l1 * l4 - l0 * l5;
  241. result.m[0] = l3 * detDiv;
  242. result.m[1] = -l1 * detDiv;
  243. result.m[2] = -l2 * detDiv;
  244. result.m[3] = l0 * detDiv;
  245. result.m[4] = det4 * detDiv;
  246. result.m[5] = det5 * detDiv;
  247. return this;
  248. };
  249. Matrix2D.prototype.multiplyToRef = function (other, result) {
  250. var l0 = this.m[0];
  251. var l1 = this.m[1];
  252. var l2 = this.m[2];
  253. var l3 = this.m[3];
  254. var l4 = this.m[4];
  255. var l5 = this.m[5];
  256. var r0 = other.m[0];
  257. var r1 = other.m[1];
  258. var r2 = other.m[2];
  259. var r3 = other.m[3];
  260. var r4 = other.m[4];
  261. var r5 = other.m[5];
  262. result.m[0] = l0 * r0 + l1 * r2;
  263. result.m[1] = l0 * r1 + l1 * r3;
  264. result.m[2] = l2 * r0 + l3 * r2;
  265. result.m[3] = l2 * r1 + l3 * r3;
  266. result.m[4] = l4 * r0 + l5 * r2 + r4;
  267. result.m[5] = l4 * r1 + l5 * r3 + r5;
  268. return this;
  269. };
  270. // Statics
  271. Matrix2D.Identity = function () {
  272. return new Matrix2D(1, 0, 0, 1, 0, 0);
  273. };
  274. Matrix2D.TranslationToRef = function (x, y, result) {
  275. result.fromValues(1, 0, 0, 1, x, y);
  276. };
  277. Matrix2D.ScalingToRef = function (x, y, result) {
  278. result.fromValues(x, 0, 0, y, 0, 0);
  279. };
  280. Matrix2D.RotationToRef = function (angle, result) {
  281. var s = Math.sin(angle);
  282. var c = Math.cos(angle);
  283. result.fromValues(c, s, -s, c, 0, 0);
  284. };
  285. Matrix2D.ComposeToRef = function (tx, ty, angle, scaleX, scaleY, parentMatrix, result) {
  286. Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
  287. Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);
  288. Matrix2D.RotationToRef(angle, Matrix2D._TempRotationMatrix);
  289. Matrix2D.TranslationToRef(-tx, -ty, Matrix2D._TempPostTranslationMatrix);
  290. };
  291. return Matrix2D;
  292. }());
  293. Matrix2D._TempPreTranslationMatrix = Matrix2D.Identity();
  294. Matrix2D._TempPostTranslationMatrix = Matrix2D.Identity();
  295. Matrix2D._TempRotationMatrix = Matrix2D.Identity();
  296. Matrix2D._TempScalingMatrix = Matrix2D.Identity();
  297. GUI.Matrix2D = Matrix2D;
  298. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  299. })(BABYLON || (BABYLON = {}));
  300. //# sourceMappingURL=math2D.js.map
  301. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  302. var BABYLON;
  303. (function (BABYLON) {
  304. var GUI;
  305. (function (GUI) {
  306. var ValueAndUnit = (function () {
  307. function ValueAndUnit(value, unit, negativeValueAllowed) {
  308. if (value === void 0) { value = 1; }
  309. if (unit === void 0) { unit = ValueAndUnit.UNITMODE_PERCENTAGE; }
  310. if (negativeValueAllowed === void 0) { negativeValueAllowed = true; }
  311. this.value = value;
  312. this.unit = unit;
  313. this.negativeValueAllowed = negativeValueAllowed;
  314. }
  315. Object.defineProperty(ValueAndUnit.prototype, "isPercentage", {
  316. get: function () {
  317. return this.unit === ValueAndUnit.UNITMODE_PERCENTAGE;
  318. },
  319. enumerable: true,
  320. configurable: true
  321. });
  322. Object.defineProperty(ValueAndUnit.prototype, "isPixel", {
  323. get: function () {
  324. return this.unit === ValueAndUnit.UNITMODE_PIXEL;
  325. },
  326. enumerable: true,
  327. configurable: true
  328. });
  329. ValueAndUnit.prototype.toString = function () {
  330. switch (this.unit) {
  331. case ValueAndUnit.UNITMODE_PERCENTAGE:
  332. return this.unit + "%";
  333. case ValueAndUnit.UNITMODE_PIXEL:
  334. return this.unit + "px";
  335. }
  336. return this.unit.toString();
  337. };
  338. ValueAndUnit.prototype.fromString = function (source) {
  339. var match = ValueAndUnit._Regex.exec(source);
  340. if (!match || match.length === 0) {
  341. return false;
  342. }
  343. var sourceValue = parseFloat(match[1]);
  344. var sourceUnit = this.unit;
  345. if (!this.negativeValueAllowed) {
  346. if (sourceValue < 0) {
  347. sourceValue = 0;
  348. }
  349. }
  350. if (match.length === 4) {
  351. switch (match[3]) {
  352. case "px":
  353. sourceUnit = ValueAndUnit.UNITMODE_PIXEL;
  354. break;
  355. case "%":
  356. sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;
  357. sourceValue /= 100.0;
  358. break;
  359. }
  360. }
  361. if (sourceValue === this.value && sourceUnit === this.unit) {
  362. return false;
  363. }
  364. this.value = sourceValue;
  365. this.unit = sourceUnit;
  366. return true;
  367. };
  368. Object.defineProperty(ValueAndUnit, "UNITMODE_PERCENTAGE", {
  369. get: function () {
  370. return ValueAndUnit._UNITMODE_PERCENTAGE;
  371. },
  372. enumerable: true,
  373. configurable: true
  374. });
  375. Object.defineProperty(ValueAndUnit, "UNITMODE_PIXEL", {
  376. get: function () {
  377. return ValueAndUnit._UNITMODE_PIXEL;
  378. },
  379. enumerable: true,
  380. configurable: true
  381. });
  382. return ValueAndUnit;
  383. }());
  384. // Static
  385. ValueAndUnit._Regex = /(^-?\d*(\.\d+)?)(%|px)?/;
  386. ValueAndUnit._UNITMODE_PERCENTAGE = 0;
  387. ValueAndUnit._UNITMODE_PIXEL = 1;
  388. GUI.ValueAndUnit = ValueAndUnit;
  389. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  390. })(BABYLON || (BABYLON = {}));
  391. //# sourceMappingURL=valueAndUnit.js.map
  392. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  393. var BABYLON;
  394. (function (BABYLON) {
  395. var GUI;
  396. (function (GUI) {
  397. var Control = (function () {
  398. // Functions
  399. function Control(name) {
  400. this.name = name;
  401. this._zIndex = 0;
  402. this._currentMeasure = GUI.Measure.Empty();
  403. this._fontSize = 18;
  404. this._width = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  405. this._height = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  406. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  407. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  408. this._isDirty = true;
  409. this._cachedParentMeasure = GUI.Measure.Empty();
  410. this._marginLeft = new GUI.ValueAndUnit(0);
  411. this._marginRight = new GUI.ValueAndUnit(0);
  412. this._marginTop = new GUI.ValueAndUnit(0);
  413. this._marginBottom = new GUI.ValueAndUnit(0);
  414. this._left = new GUI.ValueAndUnit(0);
  415. this._top = new GUI.ValueAndUnit(0);
  416. this._scaleX = 1.0;
  417. this._scaleY = 1.0;
  418. this._rotation = 0;
  419. this._transformCenterX = 0.5;
  420. this._transformCenterY = 0.5;
  421. this._transformMatrix = GUI.Matrix2D.Identity();
  422. this._invertTransformMatrix = GUI.Matrix2D.Identity();
  423. this._isMatrixDirty = true;
  424. this.isHitTestVisible = true;
  425. this.isPointerBlocker = false;
  426. // Properties
  427. /**
  428. * An event triggered when the pointer move over the control.
  429. * @type {BABYLON.Observable}
  430. */
  431. this.onPointerMoveObservable = new BABYLON.Observable();
  432. /**
  433. * An event triggered when the pointer move out of the control.
  434. * @type {BABYLON.Observable}
  435. */
  436. this.onPointerOutObservable = new BABYLON.Observable();
  437. /**
  438. * An event triggered when the pointer taps the control
  439. * @type {BABYLON.Observable}
  440. */
  441. this.onPointerDownObservable = new BABYLON.Observable();
  442. /**
  443. * An event triggered when pointer up
  444. * @type {BABYLON.Observable}
  445. */
  446. this.onPointerUpObservable = new BABYLON.Observable();
  447. /**
  448. * An event triggered when pointer enters the control
  449. * @type {BABYLON.Observable}
  450. */
  451. this.onPointerEnterObservable = new BABYLON.Observable();
  452. this.fontFamily = "Arial";
  453. }
  454. Object.defineProperty(Control.prototype, "scaleX", {
  455. get: function () {
  456. return this._scaleX;
  457. },
  458. set: function (value) {
  459. if (this._scaleX === value) {
  460. return;
  461. }
  462. this._scaleX = value;
  463. this._markAsDirty();
  464. this._isMatrixDirty = true;
  465. },
  466. enumerable: true,
  467. configurable: true
  468. });
  469. Object.defineProperty(Control.prototype, "scaleY", {
  470. get: function () {
  471. return this._scaleY;
  472. },
  473. set: function (value) {
  474. if (this._scaleY === value) {
  475. return;
  476. }
  477. this._scaleY = value;
  478. this._markAsDirty();
  479. this._isMatrixDirty = true;
  480. },
  481. enumerable: true,
  482. configurable: true
  483. });
  484. Object.defineProperty(Control.prototype, "rotation", {
  485. get: function () {
  486. return this._rotation;
  487. },
  488. set: function (value) {
  489. if (this._rotation === value) {
  490. return;
  491. }
  492. this._rotation = value;
  493. this._markAsDirty();
  494. this._isMatrixDirty = true;
  495. },
  496. enumerable: true,
  497. configurable: true
  498. });
  499. Object.defineProperty(Control.prototype, "transformCenterY", {
  500. get: function () {
  501. return this._transformCenterY;
  502. },
  503. set: function (value) {
  504. if (this._transformCenterY === value) {
  505. return;
  506. }
  507. this._transformCenterY = value;
  508. this._markAsDirty();
  509. this._isMatrixDirty = true;
  510. },
  511. enumerable: true,
  512. configurable: true
  513. });
  514. Object.defineProperty(Control.prototype, "transformCenterX", {
  515. get: function () {
  516. return this._transformCenterX;
  517. },
  518. set: function (value) {
  519. if (this._transformCenterX === value) {
  520. return;
  521. }
  522. this._transformCenterX = value;
  523. this._markAsDirty();
  524. this._isMatrixDirty = true;
  525. },
  526. enumerable: true,
  527. configurable: true
  528. });
  529. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  530. get: function () {
  531. return this._horizontalAlignment;
  532. },
  533. set: function (value) {
  534. if (this._horizontalAlignment === value) {
  535. return;
  536. }
  537. this._horizontalAlignment = value;
  538. this._markAsDirty();
  539. },
  540. enumerable: true,
  541. configurable: true
  542. });
  543. Object.defineProperty(Control.prototype, "verticalAlignment", {
  544. get: function () {
  545. return this._verticalAlignment;
  546. },
  547. set: function (value) {
  548. if (this._verticalAlignment === value) {
  549. return;
  550. }
  551. this._verticalAlignment = value;
  552. this._markAsDirty();
  553. },
  554. enumerable: true,
  555. configurable: true
  556. });
  557. Object.defineProperty(Control.prototype, "width", {
  558. get: function () {
  559. return this._width.toString();
  560. },
  561. set: function (value) {
  562. if (this._width.toString() === value) {
  563. return;
  564. }
  565. if (this._width.fromString(value)) {
  566. this._markAsDirty();
  567. }
  568. },
  569. enumerable: true,
  570. configurable: true
  571. });
  572. Object.defineProperty(Control.prototype, "height", {
  573. get: function () {
  574. return this._height.toString();
  575. },
  576. set: function (value) {
  577. if (this._height.toString() === value) {
  578. return;
  579. }
  580. if (this._height.fromString(value)) {
  581. this._markAsDirty();
  582. }
  583. },
  584. enumerable: true,
  585. configurable: true
  586. });
  587. Object.defineProperty(Control.prototype, "fontFamily", {
  588. get: function () {
  589. return this._fontFamily;
  590. },
  591. set: function (value) {
  592. if (this._fontFamily === value) {
  593. return;
  594. }
  595. this._fontFamily = value;
  596. this._prepareFont();
  597. },
  598. enumerable: true,
  599. configurable: true
  600. });
  601. Object.defineProperty(Control.prototype, "fontSize", {
  602. get: function () {
  603. return this._fontSize;
  604. },
  605. set: function (value) {
  606. if (this._fontSize === value) {
  607. return;
  608. }
  609. this._fontSize = value;
  610. this._prepareFont();
  611. },
  612. enumerable: true,
  613. configurable: true
  614. });
  615. Object.defineProperty(Control.prototype, "color", {
  616. get: function () {
  617. return this._color;
  618. },
  619. set: function (value) {
  620. if (this._color === value) {
  621. return;
  622. }
  623. this._color = value;
  624. this._markAsDirty();
  625. },
  626. enumerable: true,
  627. configurable: true
  628. });
  629. Object.defineProperty(Control.prototype, "zIndex", {
  630. get: function () {
  631. return this._zIndex;
  632. },
  633. set: function (value) {
  634. if (this.zIndex === value) {
  635. return;
  636. }
  637. this._zIndex = value;
  638. this._root._reOrderControl(this);
  639. },
  640. enumerable: true,
  641. configurable: true
  642. });
  643. Object.defineProperty(Control.prototype, "isDirty", {
  644. get: function () {
  645. return this._isDirty;
  646. },
  647. enumerable: true,
  648. configurable: true
  649. });
  650. Object.defineProperty(Control.prototype, "marginLeft", {
  651. get: function () {
  652. return this._marginLeft.toString();
  653. },
  654. set: function (value) {
  655. if (this._marginLeft.fromString(value)) {
  656. this._markAsDirty();
  657. }
  658. },
  659. enumerable: true,
  660. configurable: true
  661. });
  662. Object.defineProperty(Control.prototype, "marginRight", {
  663. get: function () {
  664. return this._marginRight.toString();
  665. },
  666. set: function (value) {
  667. if (this._marginRight.fromString(value)) {
  668. this._markAsDirty();
  669. }
  670. },
  671. enumerable: true,
  672. configurable: true
  673. });
  674. Object.defineProperty(Control.prototype, "marginTop", {
  675. get: function () {
  676. return this._marginTop.toString();
  677. },
  678. set: function (value) {
  679. if (this._marginTop.fromString(value)) {
  680. this._markAsDirty();
  681. }
  682. },
  683. enumerable: true,
  684. configurable: true
  685. });
  686. Object.defineProperty(Control.prototype, "marginBottom", {
  687. get: function () {
  688. return this._marginBottom.toString();
  689. },
  690. set: function (value) {
  691. if (this._marginBottom.fromString(value)) {
  692. this._markAsDirty();
  693. }
  694. },
  695. enumerable: true,
  696. configurable: true
  697. });
  698. Object.defineProperty(Control.prototype, "left", {
  699. get: function () {
  700. return this._left.toString();
  701. },
  702. set: function (value) {
  703. if (this._left.fromString(value)) {
  704. this._markAsDirty();
  705. }
  706. },
  707. enumerable: true,
  708. configurable: true
  709. });
  710. Object.defineProperty(Control.prototype, "top", {
  711. get: function () {
  712. return this._top.toString();
  713. },
  714. set: function (value) {
  715. if (this._top.fromString(value)) {
  716. this._markAsDirty();
  717. }
  718. },
  719. enumerable: true,
  720. configurable: true
  721. });
  722. Control.prototype._markAsDirty = function () {
  723. this._isDirty = true;
  724. if (!this._host) {
  725. return; // Not yet connected
  726. }
  727. this._host.markAsDirty();
  728. };
  729. Control.prototype._link = function (root, host) {
  730. this._root = root;
  731. this._host = host;
  732. };
  733. Control.prototype._transform = function (context) {
  734. if (this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  735. return;
  736. }
  737. // preTranslate
  738. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  739. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  740. context.translate(offsetX, offsetY);
  741. // scale
  742. context.scale(this._scaleX, this._scaleY);
  743. // rotate
  744. context.rotate(this._rotation);
  745. // postTranslate
  746. context.translate(-offsetX, -offsetY);
  747. // Need to update matrices?
  748. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  749. this._cachedOffsetX = offsetX;
  750. this._cachedOffsetY = offsetY;
  751. this._isMatrixDirty = false;
  752. GUI.Matrix2D.ComposeToRef(offsetX, offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  753. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  754. }
  755. };
  756. Control.prototype._applyStates = function (context) {
  757. if (this._font) {
  758. context.font = this._font;
  759. }
  760. if (this._color) {
  761. context.fillStyle = this._color;
  762. }
  763. };
  764. Control.prototype._processMeasures = function (parentMeasure, context) {
  765. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  766. this._currentMeasure.copyFrom(parentMeasure);
  767. this._measure(parentMeasure, context);
  768. this._computeAlignment(parentMeasure, context);
  769. // Convert to int values
  770. this._currentMeasure.left = this._currentMeasure.left | 0;
  771. this._currentMeasure.top = this._currentMeasure.top | 0;
  772. this._currentMeasure.width = this._currentMeasure.width | 0;
  773. this._currentMeasure.height = this._currentMeasure.height | 0;
  774. // Let children add more features
  775. this._additionalProcessing(parentMeasure, context);
  776. this._isDirty = false;
  777. this._cachedParentMeasure.copyFrom(parentMeasure);
  778. }
  779. // Transform
  780. this._transform(context);
  781. // Clip
  782. this._clip(context);
  783. context.clip();
  784. };
  785. Control.prototype._clip = function (context) {
  786. context.beginPath();
  787. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  788. };
  789. Control.prototype._measure = function (parentMeasure, context) {
  790. // Width / Height
  791. if (this._width.isPixel) {
  792. this._currentMeasure.width = this._width.value;
  793. }
  794. else {
  795. this._currentMeasure.width *= this._width.value;
  796. }
  797. if (this._height.isPixel) {
  798. this._currentMeasure.height = this._height.value;
  799. }
  800. else {
  801. this._currentMeasure.height *= this._height.value;
  802. }
  803. };
  804. Control.prototype._computeAlignment = function (parentMeasure, context) {
  805. var width = this._currentMeasure.width;
  806. var height = this._currentMeasure.height;
  807. var parentWidth = parentMeasure.width;
  808. var parentHeight = parentMeasure.height;
  809. // Left / top
  810. var x = 0;
  811. var y = 0;
  812. switch (this.horizontalAlignment) {
  813. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  814. x = 0;
  815. break;
  816. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  817. x = parentWidth - width;
  818. break;
  819. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  820. x = (parentWidth - width) / 2;
  821. break;
  822. }
  823. switch (this.verticalAlignment) {
  824. case Control.VERTICAL_ALIGNMENT_TOP:
  825. y = 0;
  826. break;
  827. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  828. y = parentHeight - height;
  829. break;
  830. case Control.VERTICAL_ALIGNMENT_CENTER:
  831. y = (parentHeight - height) / 2;
  832. break;
  833. }
  834. if (this._marginLeft.isPixel) {
  835. this._currentMeasure.left += this._marginLeft.value;
  836. this._currentMeasure.width -= this._marginRight.value;
  837. }
  838. else {
  839. this._currentMeasure.left += parentWidth * this._marginLeft.value;
  840. this._currentMeasure.width -= parentWidth * this._marginLeft.value;
  841. }
  842. if (this._marginRight.isPixel) {
  843. this._currentMeasure.width -= this._marginRight.value;
  844. }
  845. else {
  846. this._currentMeasure.width -= parentWidth * this._marginRight.value;
  847. }
  848. if (this._marginTop.isPixel) {
  849. this._currentMeasure.top += this._marginTop.value;
  850. this._currentMeasure.height -= this._marginTop.value;
  851. }
  852. else {
  853. this._currentMeasure.top += parentHeight * this._marginTop.value;
  854. this._currentMeasure.height -= parentHeight * this._marginTop.value;
  855. }
  856. if (this._marginBottom.isPixel) {
  857. this._currentMeasure.height -= this._marginBottom.value;
  858. }
  859. else {
  860. this._currentMeasure.height -= parentHeight * this._marginBottom.value;
  861. }
  862. if (this._left.isPixel) {
  863. this._currentMeasure.left += this._left.value;
  864. }
  865. else {
  866. this._currentMeasure.left += parentWidth * this._left.value;
  867. }
  868. if (this._top.isPixel) {
  869. this._currentMeasure.top += this._top.value;
  870. }
  871. else {
  872. this._currentMeasure.top += parentHeight * this._top.value;
  873. }
  874. this._currentMeasure.left += x;
  875. this._currentMeasure.top += y;
  876. };
  877. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  878. // Do nothing
  879. };
  880. Control.prototype._draw = function (parentMeasure, context) {
  881. // Do nothing
  882. };
  883. Control.prototype.contains = function (x, y) {
  884. // Invert transform
  885. if (this._scaleX !== 1 || this._scaleY !== 1 || this.rotation !== 0) {
  886. }
  887. // Check
  888. if (x < this._currentMeasure.left) {
  889. return false;
  890. }
  891. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  892. return false;
  893. }
  894. if (y < this._currentMeasure.top) {
  895. return false;
  896. }
  897. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  898. return false;
  899. }
  900. if (this.isPointerBlocker) {
  901. this._host._shouldBlockPointer = true;
  902. }
  903. return true;
  904. };
  905. Control.prototype._processPicking = function (x, y, type) {
  906. if (!this.contains(x, y)) {
  907. return false;
  908. }
  909. this._processObservables(type);
  910. return true;
  911. };
  912. Control.prototype._onPointerMove = function () {
  913. if (this.onPointerMoveObservable.hasObservers()) {
  914. this.onPointerMoveObservable.notifyObservers(this);
  915. }
  916. };
  917. Control.prototype._onPointerEnter = function () {
  918. if (this.onPointerEnterObservable.hasObservers()) {
  919. this.onPointerEnterObservable.notifyObservers(this);
  920. }
  921. };
  922. Control.prototype._onPointerOut = function () {
  923. if (this.onPointerOutObservable.hasObservers()) {
  924. this.onPointerOutObservable.notifyObservers(this);
  925. }
  926. };
  927. Control.prototype._onPointerDown = function () {
  928. if (this.onPointerDownObservable.hasObservers()) {
  929. this.onPointerDownObservable.notifyObservers(this);
  930. }
  931. };
  932. Control.prototype._onPointerUp = function () {
  933. if (this.onPointerUpObservable.hasObservers()) {
  934. this.onPointerUpObservable.notifyObservers(this);
  935. }
  936. };
  937. Control.prototype._processObservables = function (type) {
  938. if (!this.isHitTestVisible) {
  939. return false;
  940. }
  941. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  942. this._onPointerMove();
  943. var previousControlOver = this._host._lastControlOver;
  944. if (previousControlOver && previousControlOver !== this) {
  945. previousControlOver._onPointerOut();
  946. }
  947. if (previousControlOver !== this) {
  948. this._onPointerEnter();
  949. }
  950. this._host._lastControlOver = this;
  951. return true;
  952. }
  953. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  954. this._onPointerDown();
  955. this._host._lastControlDown = this;
  956. return true;
  957. }
  958. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  959. this._onPointerUp();
  960. if (this._host._lastControlDown !== this) {
  961. this._host._lastControlDown._onPointerUp();
  962. this._host._lastControlDown = null;
  963. }
  964. return true;
  965. }
  966. return false;
  967. };
  968. Control.prototype._prepareFont = function () {
  969. if (!this._fontFamily) {
  970. return;
  971. }
  972. this._font = this._fontSize + "px " + this._fontFamily;
  973. this._fontOffset = Control._GetFontOffset(this._font);
  974. this._markAsDirty();
  975. };
  976. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  977. get: function () {
  978. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  979. },
  980. enumerable: true,
  981. configurable: true
  982. });
  983. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  984. get: function () {
  985. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  986. },
  987. enumerable: true,
  988. configurable: true
  989. });
  990. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  991. get: function () {
  992. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  993. },
  994. enumerable: true,
  995. configurable: true
  996. });
  997. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  998. get: function () {
  999. return Control._VERTICAL_ALIGNMENT_TOP;
  1000. },
  1001. enumerable: true,
  1002. configurable: true
  1003. });
  1004. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  1005. get: function () {
  1006. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  1007. },
  1008. enumerable: true,
  1009. configurable: true
  1010. });
  1011. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  1012. get: function () {
  1013. return Control._VERTICAL_ALIGNMENT_CENTER;
  1014. },
  1015. enumerable: true,
  1016. configurable: true
  1017. });
  1018. Control._GetFontOffset = function (font) {
  1019. if (Control._FontHeightSizes[font]) {
  1020. return Control._FontHeightSizes[font];
  1021. }
  1022. var text = document.createElement("span");
  1023. text.innerHTML = "Hg";
  1024. text.style.font = font;
  1025. var block = document.createElement("div");
  1026. block.style.display = "inline-block";
  1027. block.style.width = "1px";
  1028. block.style.height = "0px";
  1029. block.style.verticalAlign = "bottom";
  1030. var div = document.createElement("div");
  1031. div.appendChild(text);
  1032. div.appendChild(block);
  1033. document.body.appendChild(div);
  1034. var fontAscent = 0;
  1035. var fontHeight = 0;
  1036. try {
  1037. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1038. block.style.verticalAlign = "baseline";
  1039. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1040. }
  1041. finally {
  1042. div.remove();
  1043. }
  1044. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  1045. Control._FontHeightSizes[font] = result;
  1046. return result;
  1047. };
  1048. ;
  1049. return Control;
  1050. }());
  1051. // Statics
  1052. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  1053. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  1054. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  1055. Control._VERTICAL_ALIGNMENT_TOP = 0;
  1056. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  1057. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  1058. Control._FontHeightSizes = {};
  1059. GUI.Control = Control;
  1060. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1061. })(BABYLON || (BABYLON = {}));
  1062. //# sourceMappingURL=control.js.map
  1063. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1064. var __extends = (this && this.__extends) || (function () {
  1065. var extendStatics = Object.setPrototypeOf ||
  1066. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1067. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1068. return function (d, b) {
  1069. extendStatics(d, b);
  1070. function __() { this.constructor = d; }
  1071. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1072. };
  1073. })();
  1074. var BABYLON;
  1075. (function (BABYLON) {
  1076. var GUI;
  1077. (function (GUI) {
  1078. var Container = (function (_super) {
  1079. __extends(Container, _super);
  1080. function Container(name) {
  1081. var _this = _super.call(this, name) || this;
  1082. _this.name = name;
  1083. _this._children = new Array();
  1084. _this._measureForChildren = GUI.Measure.Empty();
  1085. return _this;
  1086. }
  1087. Container.prototype.addControl = function (control) {
  1088. var index = this._children.indexOf(control);
  1089. if (index !== -1) {
  1090. return this;
  1091. }
  1092. control._link(this, this._host);
  1093. this._reOrderControl(control);
  1094. this._markAsDirty();
  1095. return this;
  1096. };
  1097. Container.prototype.removeControl = function (control) {
  1098. var index = this._children.indexOf(control);
  1099. if (index !== -1) {
  1100. this._children.splice(index, 1);
  1101. }
  1102. this._markAsDirty();
  1103. return this;
  1104. };
  1105. Container.prototype._reOrderControl = function (control) {
  1106. this.removeControl(control);
  1107. for (var index = 0; index < this._children.length; index++) {
  1108. if (this._children[index].zIndex > control.zIndex) {
  1109. this._children.splice(index, 0, control);
  1110. return;
  1111. }
  1112. }
  1113. this._children.push(control);
  1114. this._markAsDirty();
  1115. };
  1116. Container.prototype._localDraw = function (context) {
  1117. // Implemented by child to be injected inside main draw
  1118. };
  1119. Container.prototype._link = function (root, host) {
  1120. _super.prototype._link.call(this, root, host);
  1121. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1122. var child = _a[_i];
  1123. child._link(root, host);
  1124. }
  1125. };
  1126. Container.prototype._draw = function (parentMeasure, context) {
  1127. context.save();
  1128. _super.prototype._processMeasures.call(this, parentMeasure, context);
  1129. this._applyStates(context);
  1130. this._localDraw(context);
  1131. this._clipForChildren(context);
  1132. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1133. var child = _a[_i];
  1134. child._draw(this._measureForChildren, context);
  1135. }
  1136. context.restore();
  1137. };
  1138. Container.prototype._processPicking = function (x, y, type) {
  1139. if (!_super.prototype.contains.call(this, x, y)) {
  1140. return false;
  1141. }
  1142. // Checking backwards to pick closest first
  1143. for (var index = this._children.length - 1; index >= 0; index--) {
  1144. var child = this._children[index];
  1145. if (child._processPicking(x, y, type)) {
  1146. return true;
  1147. }
  1148. }
  1149. return this._processObservables(type);
  1150. };
  1151. Container.prototype._clipForChildren = function (context) {
  1152. // DO nothing
  1153. };
  1154. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  1155. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1156. this._measureForChildren.copyFrom(this._currentMeasure);
  1157. };
  1158. return Container;
  1159. }(GUI.Control));
  1160. GUI.Container = Container;
  1161. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1162. })(BABYLON || (BABYLON = {}));
  1163. //# sourceMappingURL=container.js.map
  1164. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1165. var __extends = (this && this.__extends) || (function () {
  1166. var extendStatics = Object.setPrototypeOf ||
  1167. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1168. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1169. return function (d, b) {
  1170. extendStatics(d, b);
  1171. function __() { this.constructor = d; }
  1172. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1173. };
  1174. })();
  1175. var BABYLON;
  1176. (function (BABYLON) {
  1177. var GUI;
  1178. (function (GUI) {
  1179. var Rectangle = (function (_super) {
  1180. __extends(Rectangle, _super);
  1181. function Rectangle(name) {
  1182. var _this = _super.call(this, name) || this;
  1183. _this.name = name;
  1184. _this._thickness = 1;
  1185. _this._cornerRadius = 0;
  1186. return _this;
  1187. }
  1188. Object.defineProperty(Rectangle.prototype, "thickness", {
  1189. get: function () {
  1190. return this._thickness;
  1191. },
  1192. set: function (value) {
  1193. if (this._thickness === value) {
  1194. return;
  1195. }
  1196. this._thickness = value;
  1197. this._markAsDirty();
  1198. },
  1199. enumerable: true,
  1200. configurable: true
  1201. });
  1202. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  1203. get: function () {
  1204. return this._cornerRadius;
  1205. },
  1206. set: function (value) {
  1207. if (value < 0) {
  1208. value = 0;
  1209. }
  1210. if (this._cornerRadius === value) {
  1211. return;
  1212. }
  1213. this._cornerRadius = value;
  1214. this._markAsDirty();
  1215. },
  1216. enumerable: true,
  1217. configurable: true
  1218. });
  1219. Object.defineProperty(Rectangle.prototype, "background", {
  1220. get: function () {
  1221. return this._background;
  1222. },
  1223. set: function (value) {
  1224. if (this._background === value) {
  1225. return;
  1226. }
  1227. this._background = value;
  1228. this._markAsDirty();
  1229. },
  1230. enumerable: true,
  1231. configurable: true
  1232. });
  1233. Rectangle.prototype._localDraw = function (context) {
  1234. context.save();
  1235. if (this._background) {
  1236. context.fillStyle = this._background;
  1237. if (this._cornerRadius) {
  1238. this._drawRoundedRect(context, this._thickness / 2);
  1239. context.fill();
  1240. }
  1241. else {
  1242. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1243. }
  1244. }
  1245. if (this._thickness) {
  1246. if (this.color) {
  1247. context.strokeStyle = this.color;
  1248. }
  1249. context.lineWidth = this._thickness;
  1250. if (this._cornerRadius) {
  1251. this._drawRoundedRect(context, this._thickness / 2);
  1252. context.stroke();
  1253. }
  1254. else {
  1255. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  1256. }
  1257. }
  1258. context.restore();
  1259. };
  1260. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  1261. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1262. this._measureForChildren.width -= 2 * this._thickness;
  1263. this._measureForChildren.height -= 2 * this._thickness;
  1264. this._measureForChildren.left += this._thickness;
  1265. this._measureForChildren.top += this._thickness;
  1266. };
  1267. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  1268. if (offset === void 0) { offset = 0; }
  1269. var x = this._currentMeasure.left + offset;
  1270. var y = this._currentMeasure.top + offset;
  1271. var width = this._currentMeasure.width - offset * 2;
  1272. var height = this._currentMeasure.height - offset * 2;
  1273. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  1274. context.beginPath();
  1275. context.moveTo(x + radius, y);
  1276. context.lineTo(x + width - radius, y);
  1277. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  1278. context.lineTo(x + width, y + height - radius);
  1279. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  1280. context.lineTo(x + radius, y + height);
  1281. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  1282. context.lineTo(x, y + radius);
  1283. context.quadraticCurveTo(x, y, x + radius, y);
  1284. context.closePath();
  1285. };
  1286. Rectangle.prototype._clipForChildren = function (context) {
  1287. if (this._cornerRadius) {
  1288. this._drawRoundedRect(context, this._thickness);
  1289. context.clip();
  1290. }
  1291. };
  1292. return Rectangle;
  1293. }(GUI.Container));
  1294. GUI.Rectangle = Rectangle;
  1295. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1296. })(BABYLON || (BABYLON = {}));
  1297. //# sourceMappingURL=rectangle.js.map
  1298. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1299. var __extends = (this && this.__extends) || (function () {
  1300. var extendStatics = Object.setPrototypeOf ||
  1301. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1302. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1303. return function (d, b) {
  1304. extendStatics(d, b);
  1305. function __() { this.constructor = d; }
  1306. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1307. };
  1308. })();
  1309. var BABYLON;
  1310. (function (BABYLON) {
  1311. var GUI;
  1312. (function (GUI) {
  1313. var TextBlock = (function (_super) {
  1314. __extends(TextBlock, _super);
  1315. function TextBlock(name, text) {
  1316. var _this = _super.call(this, name) || this;
  1317. _this.name = name;
  1318. _this._textWrapping = false;
  1319. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1320. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  1321. _this.text = text;
  1322. return _this;
  1323. }
  1324. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  1325. get: function () {
  1326. return this._textWrapping;
  1327. },
  1328. set: function (value) {
  1329. if (this._textWrapping === value) {
  1330. return;
  1331. }
  1332. this._textWrapping = value;
  1333. this._markAsDirty();
  1334. },
  1335. enumerable: true,
  1336. configurable: true
  1337. });
  1338. Object.defineProperty(TextBlock.prototype, "text", {
  1339. get: function () {
  1340. return this._text;
  1341. },
  1342. set: function (value) {
  1343. if (this._text === value) {
  1344. return;
  1345. }
  1346. this._text = value;
  1347. this._markAsDirty();
  1348. },
  1349. enumerable: true,
  1350. configurable: true
  1351. });
  1352. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  1353. get: function () {
  1354. return this._textHorizontalAlignment;
  1355. },
  1356. set: function (value) {
  1357. if (this._textHorizontalAlignment === value) {
  1358. return;
  1359. }
  1360. this._textHorizontalAlignment = value;
  1361. this._markAsDirty();
  1362. },
  1363. enumerable: true,
  1364. configurable: true
  1365. });
  1366. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  1367. get: function () {
  1368. return this._textVerticalAlignment;
  1369. },
  1370. set: function (value) {
  1371. if (this._textVerticalAlignment === value) {
  1372. return;
  1373. }
  1374. this._textVerticalAlignment = value;
  1375. this._markAsDirty();
  1376. },
  1377. enumerable: true,
  1378. configurable: true
  1379. });
  1380. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  1381. var width = this._currentMeasure.width;
  1382. var x = 0;
  1383. switch (this._textHorizontalAlignment) {
  1384. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  1385. x = 0;
  1386. break;
  1387. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  1388. x = width - textWidth;
  1389. break;
  1390. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  1391. x = (width - textWidth) / 2;
  1392. break;
  1393. }
  1394. context.fillText(text, this._currentMeasure.left + x, y);
  1395. };
  1396. TextBlock.prototype._draw = function (parentMeasure, context) {
  1397. context.save();
  1398. this._applyStates(context);
  1399. _super.prototype._processMeasures.call(this, parentMeasure, context);
  1400. // Render lines
  1401. this._renderLines(context);
  1402. context.restore();
  1403. };
  1404. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  1405. this._lines = [];
  1406. if (this._textWrapping) {
  1407. var words = this.text.split(' ');
  1408. var line = '';
  1409. var width = this._currentMeasure.width;
  1410. var lineWidth = 0;
  1411. for (var n = 0; n < words.length; n++) {
  1412. var testLine = line + words[n] + ' ';
  1413. var metrics = context.measureText(testLine);
  1414. var testWidth = metrics.width;
  1415. if (testWidth > width && n > 0) {
  1416. this._lines.push({ text: line, width: lineWidth });
  1417. line = words[n] + ' ';
  1418. lineWidth = context.measureText(line).width;
  1419. }
  1420. else {
  1421. lineWidth = testWidth;
  1422. line = testLine;
  1423. }
  1424. }
  1425. this._lines.push({ text: line, width: lineWidth });
  1426. }
  1427. else {
  1428. this._lines.push({ text: this.text, width: context.measureText(this.text).width });
  1429. }
  1430. };
  1431. TextBlock.prototype._renderLines = function (context) {
  1432. var width = this._currentMeasure.width;
  1433. var height = this._currentMeasure.height;
  1434. if (!this._fontOffset) {
  1435. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  1436. }
  1437. var rootY = 0;
  1438. switch (this._textVerticalAlignment) {
  1439. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  1440. rootY = this._fontOffset.ascent;
  1441. break;
  1442. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  1443. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  1444. break;
  1445. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  1446. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  1447. break;
  1448. }
  1449. rootY += this._currentMeasure.top;
  1450. for (var _i = 0, _a = this._lines; _i < _a.length; _i++) {
  1451. var line = _a[_i];
  1452. this._drawText(line.text, line.width, rootY, context);
  1453. rootY += this._fontOffset.height;
  1454. }
  1455. };
  1456. return TextBlock;
  1457. }(GUI.Control));
  1458. GUI.TextBlock = TextBlock;
  1459. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1460. })(BABYLON || (BABYLON = {}));
  1461. //# sourceMappingURL=textBlock.js.map
  1462. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1463. var __extends = (this && this.__extends) || (function () {
  1464. var extendStatics = Object.setPrototypeOf ||
  1465. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1466. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1467. return function (d, b) {
  1468. extendStatics(d, b);
  1469. function __() { this.constructor = d; }
  1470. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1471. };
  1472. })();
  1473. var DOMImage = Image;
  1474. var BABYLON;
  1475. (function (BABYLON) {
  1476. var GUI;
  1477. (function (GUI) {
  1478. var Image = (function (_super) {
  1479. __extends(Image, _super);
  1480. function Image(name, url) {
  1481. var _this = _super.call(this, name) || this;
  1482. _this.name = name;
  1483. _this._loaded = false;
  1484. _this._stretch = Image.STRETCH_FILL;
  1485. _this._domImage = new DOMImage();
  1486. _this._domImage.onload = function () {
  1487. _this._imageWidth = _this._domImage.width;
  1488. _this._imageHeight = _this._domImage.height;
  1489. _this._loaded = true;
  1490. _this._markAsDirty();
  1491. };
  1492. _this._domImage.src = url;
  1493. return _this;
  1494. }
  1495. Object.defineProperty(Image.prototype, "stretch", {
  1496. get: function () {
  1497. return this._stretch;
  1498. },
  1499. set: function (value) {
  1500. if (this._stretch === value) {
  1501. return;
  1502. }
  1503. this._stretch = value;
  1504. this._markAsDirty();
  1505. },
  1506. enumerable: true,
  1507. configurable: true
  1508. });
  1509. Image.prototype._draw = function (parentMeasure, context) {
  1510. context.save();
  1511. this._applyStates(context);
  1512. _super.prototype._processMeasures.call(this, parentMeasure, context);
  1513. if (this._loaded) {
  1514. switch (this._stretch) {
  1515. case Image.STRETCH_NONE:
  1516. context.drawImage(this._domImage, this._currentMeasure.left, this._currentMeasure.top);
  1517. break;
  1518. case Image.STRETCH_FILL:
  1519. context.drawImage(this._domImage, 0, 0, this._imageWidth, this._imageHeight, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1520. break;
  1521. case Image.STRETCH_UNIFORM:
  1522. var hRatio = this._currentMeasure.width / this._imageWidth;
  1523. var vRatio = this._currentMeasure.height / this._imageHeight;
  1524. var ratio = Math.min(hRatio, vRatio);
  1525. var centerX = (this._currentMeasure.width - this._imageWidth * ratio) / 2;
  1526. var centerY = (this._currentMeasure.height - this._imageHeight * ratio) / 2;
  1527. context.drawImage(this._domImage, 0, 0, this._imageWidth, this._imageHeight, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, this._imageWidth * ratio, this._imageHeight * ratio);
  1528. break;
  1529. }
  1530. }
  1531. context.restore();
  1532. };
  1533. Object.defineProperty(Image, "STRETCH_NONE", {
  1534. get: function () {
  1535. return Image._STRETCH_NONE;
  1536. },
  1537. enumerable: true,
  1538. configurable: true
  1539. });
  1540. Object.defineProperty(Image, "STRETCH_FILL", {
  1541. get: function () {
  1542. return Image._STRETCH_FILL;
  1543. },
  1544. enumerable: true,
  1545. configurable: true
  1546. });
  1547. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  1548. get: function () {
  1549. return Image._STRETCH_UNIFORM;
  1550. },
  1551. enumerable: true,
  1552. configurable: true
  1553. });
  1554. return Image;
  1555. }(GUI.Control));
  1556. // Static
  1557. Image._STRETCH_NONE = 0;
  1558. Image._STRETCH_FILL = 1;
  1559. Image._STRETCH_UNIFORM = 2;
  1560. GUI.Image = Image;
  1561. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1562. })(BABYLON || (BABYLON = {}));
  1563. //# sourceMappingURL=image.js.map
  1564. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1565. var __extends = (this && this.__extends) || (function () {
  1566. var extendStatics = Object.setPrototypeOf ||
  1567. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1568. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1569. return function (d, b) {
  1570. extendStatics(d, b);
  1571. function __() { this.constructor = d; }
  1572. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1573. };
  1574. })();
  1575. var BABYLON;
  1576. (function (BABYLON) {
  1577. var GUI;
  1578. (function (GUI) {
  1579. var Button = (function (_super) {
  1580. __extends(Button, _super);
  1581. function Button(name) {
  1582. var _this = _super.call(this, name) || this;
  1583. _this.name = name;
  1584. _this.thickness = 1;
  1585. _this.isPointerBlocker = true;
  1586. return _this;
  1587. }
  1588. // While being a container, the button behaves like a control.
  1589. Button.prototype._processPicking = function (x, y, type) {
  1590. if (!this.contains(x, y)) {
  1591. return false;
  1592. }
  1593. this._processObservables(type);
  1594. return true;
  1595. };
  1596. Button.prototype._onPointerEnter = function () {
  1597. this.scaleX += 0.01;
  1598. this.scaleY += 0.01;
  1599. _super.prototype._onPointerEnter.call(this);
  1600. };
  1601. Button.prototype._onPointerOut = function () {
  1602. this.scaleX -= 0.01;
  1603. this.scaleY -= 0.01;
  1604. _super.prototype._onPointerOut.call(this);
  1605. };
  1606. Button.prototype._onPointerDown = function () {
  1607. this.scaleX -= 0.05;
  1608. this.scaleY -= 0.05;
  1609. _super.prototype._onPointerDown.call(this);
  1610. };
  1611. Button.prototype._onPointerUp = function () {
  1612. this.scaleX += 0.05;
  1613. this.scaleY += 0.05;
  1614. _super.prototype._onPointerUp.call(this);
  1615. };
  1616. // Statics
  1617. Button.CreateImageButton = function (name, text, imageUrl) {
  1618. var result = new Button(name);
  1619. // Adding text
  1620. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  1621. textBlock.textWrapping = true;
  1622. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1623. textBlock.marginLeft = "20%";
  1624. result.addControl(textBlock);
  1625. // Adding image
  1626. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  1627. iconImage.width = "20%";
  1628. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  1629. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1630. result.addControl(iconImage);
  1631. return result;
  1632. };
  1633. Button.CreateSimpleButton = function (name, text) {
  1634. var result = new Button(name);
  1635. // Adding text
  1636. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  1637. textBlock.textWrapping = true;
  1638. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1639. result.addControl(textBlock);
  1640. return result;
  1641. };
  1642. return Button;
  1643. }(GUI.Rectangle));
  1644. GUI.Button = Button;
  1645. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1646. })(BABYLON || (BABYLON = {}));
  1647. //# sourceMappingURL=button.js.map