babylon.gui.js 93 KB

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