babylon.gui.js 92 KB

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