babylon.gui.js 88 KB

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