babylon.gui.js 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  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().onPointerObservable.remove(this._pointerMoveObserver);
  67. }
  68. _super.prototype.dispose.call(this);
  69. };
  70. AdvancedDynamicTexture.prototype._onResize = function () {
  71. // Check size
  72. var engine = this.getScene().getEngine();
  73. var textureSize = this.getSize();
  74. var renderWidth = engine.getRenderWidth();
  75. var renderHeight = engine.getRenderHeight();
  76. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  77. this.scaleTo(renderWidth, renderHeight);
  78. this.markAsDirty();
  79. }
  80. };
  81. AdvancedDynamicTexture.prototype._checkUpdate = function () {
  82. if (!this._isDirty && !this._rootContainer.isDirty) {
  83. return;
  84. }
  85. this._isDirty = false;
  86. this._render();
  87. this.update();
  88. };
  89. AdvancedDynamicTexture.prototype._render = function () {
  90. var textureSize = this.getSize();
  91. var renderWidth = textureSize.width;
  92. var renderHeight = textureSize.height;
  93. // Clear
  94. var context = this.getContext();
  95. context.clearRect(0, 0, renderWidth, renderHeight);
  96. if (this._background) {
  97. context.save();
  98. context.fillStyle = this._background;
  99. context.fillRect(0, 0, renderWidth, renderHeight);
  100. context.restore();
  101. }
  102. // Render
  103. var measure = new GUI.Measure(0, 0, renderWidth, renderHeight);
  104. this._rootContainer._draw(measure, context);
  105. };
  106. AdvancedDynamicTexture.prototype._doPicking = function (x, y, type) {
  107. if (!this._rootContainer._processPicking(x, y, type)) {
  108. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  109. if (this._lastControlOver && this._lastControlOver.onPointerOutObservable.hasObservers()) {
  110. this._lastControlOver.onPointerOutObservable.notifyObservers(this._lastControlOver);
  111. }
  112. this._lastControlOver = null;
  113. }
  114. }
  115. };
  116. AdvancedDynamicTexture.prototype.attach = function () {
  117. var _this = this;
  118. var scene = this.getScene();
  119. this._pointerMoveObserver = scene.onPointerObservable.add(function (pi, state) {
  120. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  121. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  122. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  123. return;
  124. }
  125. _this._doPicking(scene.pointerX, scene.pointerY, pi.type);
  126. });
  127. };
  128. // Statics
  129. AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height) {
  130. if (width === void 0) { width = 1024; }
  131. if (height === void 0) { height = 1024; }
  132. var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  133. var material = new BABYLON.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
  134. material.backFaceCulling = false;
  135. material.emissiveTexture = result;
  136. material.opacityTexture = result;
  137. mesh.material = material;
  138. return result;
  139. };
  140. AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene) {
  141. if (foreground === void 0) { foreground = true; }
  142. var result = new AdvancedDynamicTexture(name, 0, 0, scene);
  143. // Display
  144. var layer = new BABYLON.Layer(name + "_layer", null, scene, !foreground);
  145. layer.texture = result;
  146. // Attach
  147. result.attach();
  148. return result;
  149. };
  150. return AdvancedDynamicTexture;
  151. }(BABYLON.DynamicTexture));
  152. GUI.AdvancedDynamicTexture = AdvancedDynamicTexture;
  153. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  154. })(BABYLON || (BABYLON = {}));
  155. //# sourceMappingURL=advancedDynamicTexture.js.map
  156. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  157. var BABYLON;
  158. (function (BABYLON) {
  159. var GUI;
  160. (function (GUI) {
  161. var Measure = (function () {
  162. function Measure(left, top, width, height) {
  163. this.left = left;
  164. this.top = top;
  165. this.width = width;
  166. this.height = height;
  167. }
  168. Measure.prototype.copyFrom = function (other) {
  169. this.left = other.left;
  170. this.top = other.top;
  171. this.width = other.width;
  172. this.height = other.height;
  173. };
  174. Measure.prototype.isEqualsTo = function (other) {
  175. if (this.left !== other.left) {
  176. return false;
  177. }
  178. if (this.top !== other.top) {
  179. return false;
  180. }
  181. if (this.width !== other.width) {
  182. return false;
  183. }
  184. if (this.height !== other.height) {
  185. return false;
  186. }
  187. return true;
  188. };
  189. Measure.Empty = function () {
  190. return new Measure(0, 0, 0, 0);
  191. };
  192. return Measure;
  193. }());
  194. GUI.Measure = Measure;
  195. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  196. })(BABYLON || (BABYLON = {}));
  197. //# sourceMappingURL=measure.js.map
  198. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  199. var BABYLON;
  200. (function (BABYLON) {
  201. var GUI;
  202. (function (GUI) {
  203. var ValueAndUnit = (function () {
  204. function ValueAndUnit(value, unit, negativeValueAllowed) {
  205. if (value === void 0) { value = 1; }
  206. if (unit === void 0) { unit = ValueAndUnit.UNITMODE_PERCENTAGE; }
  207. if (negativeValueAllowed === void 0) { negativeValueAllowed = true; }
  208. this.value = value;
  209. this.unit = unit;
  210. this.negativeValueAllowed = negativeValueAllowed;
  211. }
  212. Object.defineProperty(ValueAndUnit.prototype, "isPercentage", {
  213. get: function () {
  214. return this.unit === ValueAndUnit.UNITMODE_PERCENTAGE;
  215. },
  216. enumerable: true,
  217. configurable: true
  218. });
  219. Object.defineProperty(ValueAndUnit.prototype, "isPixel", {
  220. get: function () {
  221. return this.unit === ValueAndUnit.UNITMODE_PIXEL;
  222. },
  223. enumerable: true,
  224. configurable: true
  225. });
  226. ValueAndUnit.prototype.toString = function () {
  227. switch (this.unit) {
  228. case ValueAndUnit.UNITMODE_PERCENTAGE:
  229. return this.unit + "%";
  230. case ValueAndUnit.UNITMODE_PIXEL:
  231. return this.unit + "px";
  232. }
  233. return this.unit.toString();
  234. };
  235. ValueAndUnit.prototype.fromString = function (source) {
  236. var match = ValueAndUnit._Regex.exec(source);
  237. if (!match || match.length === 0) {
  238. return false;
  239. }
  240. var sourceValue = parseFloat(match[1]);
  241. var sourceUnit = this.unit;
  242. if (!this.negativeValueAllowed) {
  243. if (sourceValue < 0) {
  244. sourceValue = 0;
  245. }
  246. }
  247. if (match.length === 4) {
  248. switch (match[3]) {
  249. case "px":
  250. sourceUnit = ValueAndUnit.UNITMODE_PIXEL;
  251. break;
  252. case "%":
  253. sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;
  254. sourceValue /= 100.0;
  255. break;
  256. }
  257. }
  258. if (sourceValue === this.value && sourceUnit === this.unit) {
  259. return false;
  260. }
  261. this.value = sourceValue;
  262. this.unit = sourceUnit;
  263. return true;
  264. };
  265. Object.defineProperty(ValueAndUnit, "UNITMODE_PERCENTAGE", {
  266. get: function () {
  267. return ValueAndUnit._UNITMODE_PERCENTAGE;
  268. },
  269. enumerable: true,
  270. configurable: true
  271. });
  272. Object.defineProperty(ValueAndUnit, "UNITMODE_PIXEL", {
  273. get: function () {
  274. return ValueAndUnit._UNITMODE_PIXEL;
  275. },
  276. enumerable: true,
  277. configurable: true
  278. });
  279. return ValueAndUnit;
  280. }());
  281. // Static
  282. ValueAndUnit._Regex = /(^-?\d*(\.\d+)?)(%|px)?/;
  283. ValueAndUnit._UNITMODE_PERCENTAGE = 0;
  284. ValueAndUnit._UNITMODE_PIXEL = 1;
  285. GUI.ValueAndUnit = ValueAndUnit;
  286. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  287. })(BABYLON || (BABYLON = {}));
  288. //# sourceMappingURL=valueAndUnit.js.map
  289. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  290. var BABYLON;
  291. (function (BABYLON) {
  292. var GUI;
  293. (function (GUI) {
  294. var Control = (function () {
  295. // Functions
  296. function Control(name) {
  297. this.name = name;
  298. this._zIndex = 0;
  299. this._currentMeasure = GUI.Measure.Empty();
  300. this._fontSize = 18;
  301. this._width = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  302. this._height = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  303. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  304. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  305. this._isDirty = true;
  306. this._cachedParentMeasure = GUI.Measure.Empty();
  307. this._marginLeft = new GUI.ValueAndUnit(0);
  308. this._marginRight = new GUI.ValueAndUnit(0);
  309. this._marginTop = new GUI.ValueAndUnit(0);
  310. this._marginBottom = new GUI.ValueAndUnit(0);
  311. this._left = new GUI.ValueAndUnit(0);
  312. this._top = new GUI.ValueAndUnit(0);
  313. // Properties
  314. /**
  315. * An event triggered when the pointer move over the control.
  316. * @type {BABYLON.Observable}
  317. */
  318. this.onPointerMoveObservable = new BABYLON.Observable();
  319. /**
  320. * An event triggered when the pointer move out of the control.
  321. * @type {BABYLON.Observable}
  322. */
  323. this.onPointerOutObservable = new BABYLON.Observable();
  324. /**
  325. * An event triggered when the pointer taps the control
  326. * @type {BABYLON.Observable}
  327. */
  328. this.onPointerDownObservable = new BABYLON.Observable();
  329. /**
  330. * An event triggered when pointer up
  331. * @type {BABYLON.Observable}
  332. */
  333. this.onPointerUpObservable = new BABYLON.Observable();
  334. this.fontFamily = "Arial";
  335. }
  336. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  337. get: function () {
  338. return this._horizontalAlignment;
  339. },
  340. set: function (value) {
  341. if (this._horizontalAlignment === value) {
  342. return;
  343. }
  344. this._horizontalAlignment = value;
  345. this._markAsDirty();
  346. },
  347. enumerable: true,
  348. configurable: true
  349. });
  350. Object.defineProperty(Control.prototype, "verticalAlignment", {
  351. get: function () {
  352. return this._verticalAlignment;
  353. },
  354. set: function (value) {
  355. if (this._verticalAlignment === value) {
  356. return;
  357. }
  358. this._verticalAlignment = value;
  359. this._markAsDirty();
  360. },
  361. enumerable: true,
  362. configurable: true
  363. });
  364. Object.defineProperty(Control.prototype, "width", {
  365. get: function () {
  366. return this._width.toString();
  367. },
  368. set: function (value) {
  369. if (this._width.toString() === value) {
  370. return;
  371. }
  372. if (this._width.fromString(value)) {
  373. this._markAsDirty();
  374. }
  375. },
  376. enumerable: true,
  377. configurable: true
  378. });
  379. Object.defineProperty(Control.prototype, "height", {
  380. get: function () {
  381. return this._height.toString();
  382. },
  383. set: function (value) {
  384. if (this._height.toString() === value) {
  385. return;
  386. }
  387. if (this._height.fromString(value)) {
  388. this._markAsDirty();
  389. }
  390. },
  391. enumerable: true,
  392. configurable: true
  393. });
  394. Object.defineProperty(Control.prototype, "fontFamily", {
  395. get: function () {
  396. return this._fontFamily;
  397. },
  398. set: function (value) {
  399. if (this._fontFamily === value) {
  400. return;
  401. }
  402. this._fontFamily = value;
  403. this._prepareFont();
  404. },
  405. enumerable: true,
  406. configurable: true
  407. });
  408. Object.defineProperty(Control.prototype, "fontSize", {
  409. get: function () {
  410. return this._fontSize;
  411. },
  412. set: function (value) {
  413. if (this._fontSize === value) {
  414. return;
  415. }
  416. this._fontSize = value;
  417. this._prepareFont();
  418. },
  419. enumerable: true,
  420. configurable: true
  421. });
  422. Object.defineProperty(Control.prototype, "color", {
  423. get: function () {
  424. return this._color;
  425. },
  426. set: function (value) {
  427. if (this._color === value) {
  428. return;
  429. }
  430. this._color = value;
  431. this._markAsDirty();
  432. },
  433. enumerable: true,
  434. configurable: true
  435. });
  436. Object.defineProperty(Control.prototype, "zIndex", {
  437. get: function () {
  438. return this._zIndex;
  439. },
  440. set: function (value) {
  441. if (this.zIndex === value) {
  442. return;
  443. }
  444. this._zIndex = value;
  445. this._root._reOrderControl(this);
  446. },
  447. enumerable: true,
  448. configurable: true
  449. });
  450. Object.defineProperty(Control.prototype, "isDirty", {
  451. get: function () {
  452. return this._isDirty;
  453. },
  454. enumerable: true,
  455. configurable: true
  456. });
  457. Object.defineProperty(Control.prototype, "marginLeft", {
  458. get: function () {
  459. return this._marginLeft.toString();
  460. },
  461. set: function (value) {
  462. if (this._marginLeft.fromString(value)) {
  463. this._markAsDirty();
  464. }
  465. },
  466. enumerable: true,
  467. configurable: true
  468. });
  469. Object.defineProperty(Control.prototype, "marginRight", {
  470. get: function () {
  471. return this._marginRight.toString();
  472. },
  473. set: function (value) {
  474. if (this._marginRight.fromString(value)) {
  475. this._markAsDirty();
  476. }
  477. },
  478. enumerable: true,
  479. configurable: true
  480. });
  481. Object.defineProperty(Control.prototype, "marginTop", {
  482. get: function () {
  483. return this._marginTop.toString();
  484. },
  485. set: function (value) {
  486. if (this._marginTop.fromString(value)) {
  487. this._markAsDirty();
  488. }
  489. },
  490. enumerable: true,
  491. configurable: true
  492. });
  493. Object.defineProperty(Control.prototype, "marginBottom", {
  494. get: function () {
  495. return this._marginBottom.toString();
  496. },
  497. set: function (value) {
  498. if (this._marginBottom.fromString(value)) {
  499. this._markAsDirty();
  500. }
  501. },
  502. enumerable: true,
  503. configurable: true
  504. });
  505. Object.defineProperty(Control.prototype, "left", {
  506. get: function () {
  507. return this._left.toString();
  508. },
  509. set: function (value) {
  510. if (this._left.fromString(value)) {
  511. this._markAsDirty();
  512. }
  513. },
  514. enumerable: true,
  515. configurable: true
  516. });
  517. Object.defineProperty(Control.prototype, "top", {
  518. get: function () {
  519. return this._top.toString();
  520. },
  521. set: function (value) {
  522. if (this._top.fromString(value)) {
  523. this._markAsDirty();
  524. }
  525. },
  526. enumerable: true,
  527. configurable: true
  528. });
  529. Control.prototype._markAsDirty = function () {
  530. this._isDirty = true;
  531. if (!this._host) {
  532. return; // Not yet connected
  533. }
  534. this._host.markAsDirty();
  535. };
  536. Control.prototype._link = function (root, host) {
  537. this._root = root;
  538. this._host = host;
  539. };
  540. Control.prototype.applyStates = function (context) {
  541. if (this._font) {
  542. context.font = this._font;
  543. }
  544. if (this._color) {
  545. context.fillStyle = this._color;
  546. }
  547. };
  548. Control.prototype._processMeasures = function (parentMeasure, context) {
  549. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  550. this._currentMeasure.copyFrom(parentMeasure);
  551. this._measure(parentMeasure, context);
  552. this._computeAlignment(parentMeasure, context);
  553. // Convert to int values
  554. this._currentMeasure.left = this._currentMeasure.left | 0;
  555. this._currentMeasure.top = this._currentMeasure.top | 0;
  556. this._currentMeasure.width = this._currentMeasure.width | 0;
  557. this._currentMeasure.height = this._currentMeasure.height | 0;
  558. // Let children add more features
  559. this._additionalProcessing(parentMeasure, context);
  560. this._isDirty = false;
  561. this._cachedParentMeasure.copyFrom(parentMeasure);
  562. }
  563. // Clip
  564. this._clip(context);
  565. context.clip();
  566. };
  567. Control.prototype._clip = function (context) {
  568. context.beginPath();
  569. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  570. };
  571. Control.prototype._measure = function (parentMeasure, context) {
  572. // Width / Height
  573. if (this._width.isPixel) {
  574. this._currentMeasure.width = this._width.value;
  575. }
  576. else {
  577. this._currentMeasure.width *= this._width.value;
  578. }
  579. if (this._height.isPixel) {
  580. this._currentMeasure.height = this._height.value;
  581. }
  582. else {
  583. this._currentMeasure.height *= this._height.value;
  584. }
  585. };
  586. Control.prototype._computeAlignment = function (parentMeasure, context) {
  587. var width = this._currentMeasure.width;
  588. var height = this._currentMeasure.height;
  589. var parentWidth = parentMeasure.width;
  590. var parentHeight = parentMeasure.height;
  591. // Left / top
  592. var x = 0;
  593. var y = 0;
  594. switch (this.horizontalAlignment) {
  595. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  596. x = 0;
  597. break;
  598. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  599. x = parentWidth - width;
  600. break;
  601. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  602. x = (parentWidth - width) / 2;
  603. break;
  604. }
  605. switch (this.verticalAlignment) {
  606. case Control.VERTICAL_ALIGNMENT_TOP:
  607. y = 0;
  608. break;
  609. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  610. y = parentHeight - height;
  611. break;
  612. case Control.VERTICAL_ALIGNMENT_CENTER:
  613. y = (parentHeight - height) / 2;
  614. break;
  615. }
  616. if (this._marginLeft.isPixel) {
  617. this._currentMeasure.left += this._marginLeft.value;
  618. this._currentMeasure.width -= this._marginRight.value;
  619. }
  620. else {
  621. this._currentMeasure.left += parentWidth * this._marginLeft.value;
  622. this._currentMeasure.width -= parentWidth * this._marginLeft.value;
  623. }
  624. if (this._marginRight.isPixel) {
  625. this._currentMeasure.width -= this._marginRight.value;
  626. }
  627. else {
  628. this._currentMeasure.width -= parentWidth * this._marginRight.value;
  629. }
  630. if (this._marginTop.isPixel) {
  631. this._currentMeasure.top += this._marginTop.value;
  632. this._currentMeasure.height -= this._marginTop.value;
  633. }
  634. else {
  635. this._currentMeasure.top += parentHeight * this._marginTop.value;
  636. this._currentMeasure.height -= parentHeight * this._marginTop.value;
  637. }
  638. if (this._marginBottom.isPixel) {
  639. this._currentMeasure.height -= this._marginBottom.value;
  640. }
  641. else {
  642. this._currentMeasure.height -= parentHeight * this._marginBottom.value;
  643. }
  644. if (this._left.isPixel) {
  645. this._currentMeasure.left += this._left.value;
  646. }
  647. else {
  648. this._currentMeasure.left += parentWidth * this._left.value;
  649. }
  650. if (this._top.isPixel) {
  651. this._currentMeasure.top += this._top.value;
  652. }
  653. else {
  654. this._currentMeasure.top += parentHeight * this._top.value;
  655. }
  656. this._currentMeasure.left += x;
  657. this._currentMeasure.top += y;
  658. };
  659. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  660. // Do nothing
  661. };
  662. Control.prototype._draw = function (parentMeasure, context) {
  663. // Do nothing
  664. };
  665. Control.prototype._contains = function (x, y) {
  666. if (x < this._currentMeasure.left) {
  667. return false;
  668. }
  669. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  670. return false;
  671. }
  672. if (y < this._currentMeasure.top) {
  673. return false;
  674. }
  675. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  676. return false;
  677. }
  678. return true;
  679. };
  680. Control.prototype._processPicking = function (x, y, type) {
  681. if (!this._contains(x, y)) {
  682. return false;
  683. }
  684. this._processObservables(type);
  685. return true;
  686. };
  687. Control.prototype._processObservables = function (type) {
  688. if (type === BABYLON.PointerEventTypes.POINTERMOVE && this.onPointerMoveObservable.hasObservers()) {
  689. this.onPointerMoveObservable.notifyObservers(this);
  690. var previousControlOver = this._host._lastControlOver;
  691. if (previousControlOver && previousControlOver !== this && previousControlOver.onPointerOutObservable.hasObservers()) {
  692. previousControlOver.onPointerOutObservable.notifyObservers(previousControlOver);
  693. }
  694. this._host._lastControlOver = this;
  695. return true;
  696. }
  697. if (type === BABYLON.PointerEventTypes.POINTERDOWN && this.onPointerDownObservable.hasObservers()) {
  698. this.onPointerDownObservable.notifyObservers(this);
  699. return true;
  700. }
  701. if (type === BABYLON.PointerEventTypes.POINTERUP && this.onPointerUpObservable.hasObservers()) {
  702. this.onPointerUpObservable.notifyObservers(this);
  703. return true;
  704. }
  705. return false;
  706. };
  707. Control.prototype._prepareFont = function () {
  708. if (!this._fontFamily) {
  709. return;
  710. }
  711. this._font = this._fontSize + "px " + this._fontFamily;
  712. this._fontOffset = Control._GetFontOffset(this._font);
  713. this._markAsDirty();
  714. };
  715. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  716. get: function () {
  717. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  718. },
  719. enumerable: true,
  720. configurable: true
  721. });
  722. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  723. get: function () {
  724. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  725. },
  726. enumerable: true,
  727. configurable: true
  728. });
  729. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  730. get: function () {
  731. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  732. },
  733. enumerable: true,
  734. configurable: true
  735. });
  736. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  737. get: function () {
  738. return Control._VERTICAL_ALIGNMENT_TOP;
  739. },
  740. enumerable: true,
  741. configurable: true
  742. });
  743. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  744. get: function () {
  745. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  746. },
  747. enumerable: true,
  748. configurable: true
  749. });
  750. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  751. get: function () {
  752. return Control._VERTICAL_ALIGNMENT_CENTER;
  753. },
  754. enumerable: true,
  755. configurable: true
  756. });
  757. Control._GetFontOffset = function (font) {
  758. if (Control._FontHeightSizes[font]) {
  759. return Control._FontHeightSizes[font];
  760. }
  761. var text = document.createElement("span");
  762. text.innerHTML = "Hg";
  763. text.style.font = font;
  764. var block = document.createElement("div");
  765. block.style.display = "inline-block";
  766. block.style.width = "1px";
  767. block.style.height = "0px";
  768. block.style.verticalAlign = "bottom";
  769. var div = document.createElement("div");
  770. div.appendChild(text);
  771. div.appendChild(block);
  772. document.body.appendChild(div);
  773. var fontAscent = 0;
  774. var fontHeight = 0;
  775. try {
  776. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  777. block.style.verticalAlign = "baseline";
  778. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  779. }
  780. finally {
  781. div.remove();
  782. }
  783. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  784. Control._FontHeightSizes[font] = result;
  785. return result;
  786. };
  787. ;
  788. return Control;
  789. }());
  790. // Statics
  791. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  792. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  793. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  794. Control._VERTICAL_ALIGNMENT_TOP = 0;
  795. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  796. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  797. Control._FontHeightSizes = {};
  798. GUI.Control = Control;
  799. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  800. })(BABYLON || (BABYLON = {}));
  801. //# sourceMappingURL=control.js.map
  802. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  803. var __extends = (this && this.__extends) || (function () {
  804. var extendStatics = Object.setPrototypeOf ||
  805. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  806. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  807. return function (d, b) {
  808. extendStatics(d, b);
  809. function __() { this.constructor = d; }
  810. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  811. };
  812. })();
  813. var BABYLON;
  814. (function (BABYLON) {
  815. var GUI;
  816. (function (GUI) {
  817. var Container = (function (_super) {
  818. __extends(Container, _super);
  819. function Container(name) {
  820. var _this = _super.call(this, name) || this;
  821. _this.name = name;
  822. _this._children = new Array();
  823. _this._measureForChildren = GUI.Measure.Empty();
  824. return _this;
  825. }
  826. Container.prototype.addControl = function (control) {
  827. var index = this._children.indexOf(control);
  828. if (index !== -1) {
  829. return this;
  830. }
  831. control._link(this, this._host);
  832. this._reOrderControl(control);
  833. this._markAsDirty();
  834. return this;
  835. };
  836. Container.prototype.removeControl = function (control) {
  837. var index = this._children.indexOf(control);
  838. if (index !== -1) {
  839. this._children.splice(index, 1);
  840. }
  841. this._markAsDirty();
  842. return this;
  843. };
  844. Container.prototype._reOrderControl = function (control) {
  845. this.removeControl(control);
  846. for (var index = 0; index < this._children.length; index++) {
  847. if (this._children[index].zIndex > control.zIndex) {
  848. this._children.splice(index, 0, control);
  849. return;
  850. }
  851. }
  852. this._children.push(control);
  853. this._markAsDirty();
  854. };
  855. Container.prototype._localDraw = function (context) {
  856. // Implemented by child to be injected inside main draw
  857. };
  858. Container.prototype._draw = function (parentMeasure, context) {
  859. context.save();
  860. _super.prototype._processMeasures.call(this, parentMeasure, context);
  861. this.applyStates(context);
  862. this._localDraw(context);
  863. this._clipForChildren(context);
  864. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  865. var child = _a[_i];
  866. child._draw(this._measureForChildren, context);
  867. }
  868. context.restore();
  869. };
  870. Container.prototype._processPicking = function (x, y, type) {
  871. if (!_super.prototype._contains.call(this, x, y)) {
  872. return false;
  873. }
  874. // Checking backwards to pick closest first
  875. for (var index = this._children.length - 1; index >= 0; index--) {
  876. var child = this._children[index];
  877. if (child._processPicking(x, y, type)) {
  878. return true;
  879. }
  880. }
  881. return this._processObservables(type);
  882. };
  883. Container.prototype._clipForChildren = function (context) {
  884. // DO nothing
  885. };
  886. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  887. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  888. this._measureForChildren.copyFrom(this._currentMeasure);
  889. };
  890. return Container;
  891. }(GUI.Control));
  892. GUI.Container = Container;
  893. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  894. })(BABYLON || (BABYLON = {}));
  895. //# sourceMappingURL=container.js.map
  896. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  897. var __extends = (this && this.__extends) || (function () {
  898. var extendStatics = Object.setPrototypeOf ||
  899. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  900. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  901. return function (d, b) {
  902. extendStatics(d, b);
  903. function __() { this.constructor = d; }
  904. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  905. };
  906. })();
  907. var BABYLON;
  908. (function (BABYLON) {
  909. var GUI;
  910. (function (GUI) {
  911. var Rectangle = (function (_super) {
  912. __extends(Rectangle, _super);
  913. function Rectangle(name) {
  914. var _this = _super.call(this, name) || this;
  915. _this.name = name;
  916. _this._thickness = 1;
  917. _this._cornerRadius = 0;
  918. return _this;
  919. }
  920. Object.defineProperty(Rectangle.prototype, "thickness", {
  921. get: function () {
  922. return this._thickness;
  923. },
  924. set: function (value) {
  925. if (this._thickness === value) {
  926. return;
  927. }
  928. this._thickness = value;
  929. this._markAsDirty();
  930. },
  931. enumerable: true,
  932. configurable: true
  933. });
  934. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  935. get: function () {
  936. return this._cornerRadius;
  937. },
  938. set: function (value) {
  939. if (value < 0) {
  940. value = 0;
  941. }
  942. if (this._cornerRadius === value) {
  943. return;
  944. }
  945. this._cornerRadius = value;
  946. this._markAsDirty();
  947. },
  948. enumerable: true,
  949. configurable: true
  950. });
  951. Object.defineProperty(Rectangle.prototype, "background", {
  952. get: function () {
  953. return this._background;
  954. },
  955. set: function (value) {
  956. if (this._background === value) {
  957. return;
  958. }
  959. this._background = value;
  960. this._markAsDirty();
  961. },
  962. enumerable: true,
  963. configurable: true
  964. });
  965. Rectangle.prototype._localDraw = function (context) {
  966. context.save();
  967. if (this._background) {
  968. context.fillStyle = this._background;
  969. if (this._cornerRadius) {
  970. this._drawRoundedRect(context, this._thickness / 2);
  971. context.fill();
  972. }
  973. else {
  974. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  975. }
  976. }
  977. if (this._thickness) {
  978. if (this.color) {
  979. context.strokeStyle = this.color;
  980. }
  981. context.lineWidth = this._thickness;
  982. if (this._cornerRadius) {
  983. this._drawRoundedRect(context, this._thickness / 2);
  984. context.stroke();
  985. }
  986. else {
  987. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  988. }
  989. }
  990. context.restore();
  991. };
  992. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  993. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  994. this._measureForChildren.width -= 2 * this._thickness;
  995. this._measureForChildren.height -= 2 * this._thickness;
  996. this._measureForChildren.left += this._thickness;
  997. this._measureForChildren.top += this._thickness;
  998. };
  999. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  1000. if (offset === void 0) { offset = 0; }
  1001. var x = this._currentMeasure.left + offset;
  1002. var y = this._currentMeasure.top + offset;
  1003. var width = this._currentMeasure.width - offset * 2;
  1004. var height = this._currentMeasure.height - offset * 2;
  1005. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  1006. context.beginPath();
  1007. context.moveTo(x + radius, y);
  1008. context.lineTo(x + width - radius, y);
  1009. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  1010. context.lineTo(x + width, y + height - radius);
  1011. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  1012. context.lineTo(x + radius, y + height);
  1013. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  1014. context.lineTo(x, y + radius);
  1015. context.quadraticCurveTo(x, y, x + radius, y);
  1016. context.closePath();
  1017. };
  1018. Rectangle.prototype._clipForChildren = function (context) {
  1019. if (this._cornerRadius) {
  1020. this._drawRoundedRect(context, this._thickness);
  1021. context.clip();
  1022. }
  1023. };
  1024. return Rectangle;
  1025. }(GUI.Container));
  1026. GUI.Rectangle = Rectangle;
  1027. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1028. })(BABYLON || (BABYLON = {}));
  1029. //# sourceMappingURL=rectangle.js.map
  1030. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1031. var __extends = (this && this.__extends) || (function () {
  1032. var extendStatics = Object.setPrototypeOf ||
  1033. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1034. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1035. return function (d, b) {
  1036. extendStatics(d, b);
  1037. function __() { this.constructor = d; }
  1038. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1039. };
  1040. })();
  1041. var BABYLON;
  1042. (function (BABYLON) {
  1043. var GUI;
  1044. (function (GUI) {
  1045. var TextBlock = (function (_super) {
  1046. __extends(TextBlock, _super);
  1047. function TextBlock(name, text) {
  1048. var _this = _super.call(this, name) || this;
  1049. _this.name = name;
  1050. _this._textWrapping = false;
  1051. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1052. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  1053. _this.text = text;
  1054. return _this;
  1055. }
  1056. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  1057. get: function () {
  1058. return this._textWrapping;
  1059. },
  1060. set: function (value) {
  1061. if (this._textWrapping === value) {
  1062. return;
  1063. }
  1064. this._textWrapping = value;
  1065. this._markAsDirty();
  1066. },
  1067. enumerable: true,
  1068. configurable: true
  1069. });
  1070. Object.defineProperty(TextBlock.prototype, "text", {
  1071. get: function () {
  1072. return this._text;
  1073. },
  1074. set: function (value) {
  1075. if (this._text === value) {
  1076. return;
  1077. }
  1078. this._text = value;
  1079. this._markAsDirty();
  1080. },
  1081. enumerable: true,
  1082. configurable: true
  1083. });
  1084. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  1085. get: function () {
  1086. return this._textHorizontalAlignment;
  1087. },
  1088. set: function (value) {
  1089. if (this._textHorizontalAlignment === value) {
  1090. return;
  1091. }
  1092. this._textHorizontalAlignment = value;
  1093. this._markAsDirty();
  1094. },
  1095. enumerable: true,
  1096. configurable: true
  1097. });
  1098. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  1099. get: function () {
  1100. return this._textVerticalAlignment;
  1101. },
  1102. set: function (value) {
  1103. if (this._textVerticalAlignment === value) {
  1104. return;
  1105. }
  1106. this._textVerticalAlignment = value;
  1107. this._markAsDirty();
  1108. },
  1109. enumerable: true,
  1110. configurable: true
  1111. });
  1112. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  1113. var width = this._currentMeasure.width;
  1114. var x = 0;
  1115. switch (this._textHorizontalAlignment) {
  1116. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  1117. x = 0;
  1118. break;
  1119. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  1120. x = width - textWidth;
  1121. break;
  1122. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  1123. x = (width - textWidth) / 2;
  1124. break;
  1125. }
  1126. context.fillText(text, this._currentMeasure.left + x, y);
  1127. };
  1128. TextBlock.prototype._draw = function (parentMeasure, context) {
  1129. context.save();
  1130. this.applyStates(context);
  1131. _super.prototype._processMeasures.call(this, parentMeasure, context);
  1132. // Render lines
  1133. this._renderLines(context);
  1134. context.restore();
  1135. };
  1136. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  1137. this._lines = [];
  1138. if (this._textWrapping) {
  1139. var words = this.text.split(' ');
  1140. var line = '';
  1141. var width = this._currentMeasure.width;
  1142. var lineWidth = 0;
  1143. for (var n = 0; n < words.length; n++) {
  1144. var testLine = line + words[n] + ' ';
  1145. var metrics = context.measureText(testLine);
  1146. var testWidth = metrics.width;
  1147. if (testWidth > width && n > 0) {
  1148. this._lines.push({ text: line, width: lineWidth });
  1149. line = words[n] + ' ';
  1150. lineWidth = context.measureText(line).width;
  1151. }
  1152. else {
  1153. lineWidth = testWidth;
  1154. line = testLine;
  1155. }
  1156. }
  1157. this._lines.push({ text: line, width: lineWidth });
  1158. }
  1159. else {
  1160. this._lines.push({ text: this.text, width: context.measureText(this.text).width });
  1161. }
  1162. };
  1163. TextBlock.prototype._renderLines = function (context) {
  1164. var width = this._currentMeasure.width;
  1165. var height = this._currentMeasure.height;
  1166. if (!this._fontOffset) {
  1167. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  1168. }
  1169. var rootY = 0;
  1170. switch (this._textVerticalAlignment) {
  1171. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  1172. rootY = this._fontOffset.ascent;
  1173. break;
  1174. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  1175. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  1176. break;
  1177. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  1178. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  1179. break;
  1180. }
  1181. rootY += this._currentMeasure.top;
  1182. for (var _i = 0, _a = this._lines; _i < _a.length; _i++) {
  1183. var line = _a[_i];
  1184. this._drawText(line.text, line.width, rootY, context);
  1185. rootY += this._fontOffset.height;
  1186. }
  1187. };
  1188. return TextBlock;
  1189. }(GUI.Control));
  1190. GUI.TextBlock = TextBlock;
  1191. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1192. })(BABYLON || (BABYLON = {}));
  1193. //# sourceMappingURL=textBlock.js.map
  1194. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1195. var __extends = (this && this.__extends) || (function () {
  1196. var extendStatics = Object.setPrototypeOf ||
  1197. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1198. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1199. return function (d, b) {
  1200. extendStatics(d, b);
  1201. function __() { this.constructor = d; }
  1202. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1203. };
  1204. })();
  1205. var DOMImage = Image;
  1206. var BABYLON;
  1207. (function (BABYLON) {
  1208. var GUI;
  1209. (function (GUI) {
  1210. var Image = (function (_super) {
  1211. __extends(Image, _super);
  1212. function Image(name, url) {
  1213. var _this = _super.call(this, name) || this;
  1214. _this.name = name;
  1215. _this._loaded = false;
  1216. _this._stretch = Image.STRETCH_FILL;
  1217. _this._domImage = new DOMImage();
  1218. _this._domImage.onload = function () {
  1219. _this._imageWidth = _this._domImage.width;
  1220. _this._imageHeight = _this._domImage.height;
  1221. _this._loaded = true;
  1222. _this._markAsDirty();
  1223. };
  1224. _this._domImage.src = url;
  1225. return _this;
  1226. }
  1227. Object.defineProperty(Image.prototype, "stretch", {
  1228. get: function () {
  1229. return this._stretch;
  1230. },
  1231. set: function (value) {
  1232. if (this._stretch === value) {
  1233. return;
  1234. }
  1235. this._stretch = value;
  1236. this._markAsDirty();
  1237. },
  1238. enumerable: true,
  1239. configurable: true
  1240. });
  1241. Image.prototype._draw = function (parentMeasure, context) {
  1242. context.save();
  1243. this.applyStates(context);
  1244. _super.prototype._processMeasures.call(this, parentMeasure, context);
  1245. if (this._loaded) {
  1246. switch (this._stretch) {
  1247. case Image.STRETCH_NONE:
  1248. context.drawImage(this._domImage, this._currentMeasure.left, this._currentMeasure.top);
  1249. break;
  1250. case Image.STRETCH_FILL:
  1251. context.drawImage(this._domImage, 0, 0, this._imageWidth, this._imageHeight, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1252. break;
  1253. case Image.STRETCH_UNIFORM:
  1254. var hRatio = this._currentMeasure.width / this._imageWidth;
  1255. var vRatio = this._currentMeasure.height / this._imageHeight;
  1256. var ratio = Math.min(hRatio, vRatio);
  1257. var centerX = (this._currentMeasure.width - this._imageWidth * ratio) / 2;
  1258. var centerY = (this._currentMeasure.height - this._imageHeight * ratio) / 2;
  1259. context.drawImage(this._domImage, 0, 0, this._imageWidth, this._imageHeight, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, this._imageWidth * ratio, this._imageHeight * ratio);
  1260. break;
  1261. }
  1262. }
  1263. context.restore();
  1264. };
  1265. Object.defineProperty(Image, "STRETCH_NONE", {
  1266. get: function () {
  1267. return Image._STRETCH_NONE;
  1268. },
  1269. enumerable: true,
  1270. configurable: true
  1271. });
  1272. Object.defineProperty(Image, "STRETCH_FILL", {
  1273. get: function () {
  1274. return Image._STRETCH_FILL;
  1275. },
  1276. enumerable: true,
  1277. configurable: true
  1278. });
  1279. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  1280. get: function () {
  1281. return Image._STRETCH_UNIFORM;
  1282. },
  1283. enumerable: true,
  1284. configurable: true
  1285. });
  1286. return Image;
  1287. }(GUI.Control));
  1288. // Static
  1289. Image._STRETCH_NONE = 0;
  1290. Image._STRETCH_FILL = 1;
  1291. Image._STRETCH_UNIFORM = 2;
  1292. GUI.Image = Image;
  1293. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1294. })(BABYLON || (BABYLON = {}));
  1295. //# sourceMappingURL=image.js.map
  1296. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1297. var __extends = (this && this.__extends) || (function () {
  1298. var extendStatics = Object.setPrototypeOf ||
  1299. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1300. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1301. return function (d, b) {
  1302. extendStatics(d, b);
  1303. function __() { this.constructor = d; }
  1304. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1305. };
  1306. })();
  1307. var BABYLON;
  1308. (function (BABYLON) {
  1309. var GUI;
  1310. (function (GUI) {
  1311. var Button = (function (_super) {
  1312. __extends(Button, _super);
  1313. function Button(name) {
  1314. var _this = _super.call(this, name) || this;
  1315. _this.name = name;
  1316. return _this;
  1317. }
  1318. // While being a container, the button behaves like a control.
  1319. Button.prototype._processPicking = function (x, y, type) {
  1320. if (!this._contains(x, y)) {
  1321. return false;
  1322. }
  1323. this._processObservables(type);
  1324. return true;
  1325. };
  1326. // Statics
  1327. Button.CreateImageButton = function (name, text, imageUrl) {
  1328. var result = new Button(name);
  1329. // Adding text
  1330. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  1331. textBlock.textWrapping = true;
  1332. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1333. textBlock.marginLeft = "20%";
  1334. result.addControl(textBlock);
  1335. // Adding image
  1336. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  1337. iconImage.width = "20%";
  1338. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  1339. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1340. result.addControl(iconImage);
  1341. return result;
  1342. };
  1343. return Button;
  1344. }(GUI.Rectangle));
  1345. GUI.Button = Button;
  1346. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1347. })(BABYLON || (BABYLON = {}));
  1348. //# sourceMappingURL=button.js.map