babylon.gui.js 101 KB

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