babylon.gui.js 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136
  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._pointerObserver) {
  71. this.getScene().onPointerObservable.remove(this._pointerObserver);
  72. }
  73. if (this._layerToDispose) {
  74. this._layerToDispose.texture = null;
  75. this._layerToDispose.dispose();
  76. this._layerToDispose = null;
  77. }
  78. _super.prototype.dispose.call(this);
  79. };
  80. AdvancedDynamicTexture.prototype._onResize = function () {
  81. // Check size
  82. var engine = this.getScene().getEngine();
  83. var textureSize = this.getSize();
  84. var renderWidth = engine.getRenderWidth();
  85. var renderHeight = engine.getRenderHeight();
  86. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  87. this.scaleTo(renderWidth, renderHeight);
  88. this.markAsDirty();
  89. }
  90. };
  91. AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
  92. if (this._isFullscreen && this._linkedControls.length) {
  93. var scene = this.getScene();
  94. var engine = scene.getEngine();
  95. var viewport = camera.viewport;
  96. var globalViewport = viewport.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. };
  835. Control.prototype._markAsDirty = function () {
  836. this._isDirty = true;
  837. if (!this._host) {
  838. return; // Not yet connected
  839. }
  840. this._host.markAsDirty();
  841. };
  842. Control.prototype._link = function (root, host) {
  843. this._root = root;
  844. this._host = host;
  845. };
  846. Control.prototype._transform = function (context) {
  847. if (!this._isMatrixDirty && this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  848. return;
  849. }
  850. // preTranslate
  851. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  852. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  853. context.translate(offsetX, offsetY);
  854. // scale
  855. context.scale(this._scaleX, this._scaleY);
  856. // rotate
  857. context.rotate(this._rotation);
  858. // postTranslate
  859. context.translate(-offsetX, -offsetY);
  860. // Need to update matrices?
  861. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  862. this._cachedOffsetX = offsetX;
  863. this._cachedOffsetY = offsetY;
  864. this._isMatrixDirty = false;
  865. GUI.Matrix2D.ComposeToRef(-offsetX, -offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  866. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  867. }
  868. };
  869. Control.prototype._applyStates = function (context) {
  870. if (this._font) {
  871. context.font = this._font;
  872. }
  873. if (this._color) {
  874. context.fillStyle = this._color;
  875. }
  876. context.globalAlpha = this._alpha;
  877. };
  878. Control.prototype._processMeasures = function (parentMeasure, context) {
  879. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  880. this._isDirty = false;
  881. this._currentMeasure.copyFrom(parentMeasure);
  882. this._measure();
  883. this._computeAlignment(parentMeasure, context);
  884. // Convert to int values
  885. this._currentMeasure.left = this._currentMeasure.left | 0;
  886. this._currentMeasure.top = this._currentMeasure.top | 0;
  887. this._currentMeasure.width = this._currentMeasure.width | 0;
  888. this._currentMeasure.height = this._currentMeasure.height | 0;
  889. // Let children add more features
  890. this._additionalProcessing(parentMeasure, context);
  891. this._cachedParentMeasure.copyFrom(parentMeasure);
  892. if (this.onDirtyObservable.hasObservers()) {
  893. this.onDirtyObservable.notifyObservers(this);
  894. }
  895. }
  896. // Transform
  897. this._transform(context);
  898. // Clip
  899. this._clip(context);
  900. context.clip();
  901. };
  902. Control.prototype._clip = function (context) {
  903. context.beginPath();
  904. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  905. };
  906. Control.prototype._measure = function () {
  907. // Width / Height
  908. if (this._width.isPixel) {
  909. this._currentMeasure.width = this._width.value;
  910. }
  911. else {
  912. this._currentMeasure.width *= this._width.value;
  913. }
  914. if (this._height.isPixel) {
  915. this._currentMeasure.height = this._height.value;
  916. }
  917. else {
  918. this._currentMeasure.height *= this._height.value;
  919. }
  920. };
  921. Control.prototype._computeAlignment = function (parentMeasure, context) {
  922. var width = this._currentMeasure.width;
  923. var height = this._currentMeasure.height;
  924. var parentWidth = parentMeasure.width;
  925. var parentHeight = parentMeasure.height;
  926. // Left / top
  927. var x = 0;
  928. var y = 0;
  929. switch (this.horizontalAlignment) {
  930. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  931. x = 0;
  932. break;
  933. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  934. x = parentWidth - width;
  935. break;
  936. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  937. x = (parentWidth - width) / 2;
  938. break;
  939. }
  940. switch (this.verticalAlignment) {
  941. case Control.VERTICAL_ALIGNMENT_TOP:
  942. y = 0;
  943. break;
  944. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  945. y = parentHeight - height;
  946. break;
  947. case Control.VERTICAL_ALIGNMENT_CENTER:
  948. y = (parentHeight - height) / 2;
  949. break;
  950. }
  951. if (this._marginLeft.isPixel) {
  952. this._currentMeasure.left += this._marginLeft.value;
  953. this._currentMeasure.width -= this._marginRight.value;
  954. }
  955. else {
  956. this._currentMeasure.left += parentWidth * this._marginLeft.value;
  957. this._currentMeasure.width -= parentWidth * this._marginLeft.value;
  958. }
  959. if (this._marginRight.isPixel) {
  960. this._currentMeasure.width -= this._marginRight.value;
  961. }
  962. else {
  963. this._currentMeasure.width -= parentWidth * this._marginRight.value;
  964. }
  965. if (this._marginTop.isPixel) {
  966. this._currentMeasure.top += this._marginTop.value;
  967. this._currentMeasure.height -= this._marginTop.value;
  968. }
  969. else {
  970. this._currentMeasure.top += parentHeight * this._marginTop.value;
  971. this._currentMeasure.height -= parentHeight * this._marginTop.value;
  972. }
  973. if (this._marginBottom.isPixel) {
  974. this._currentMeasure.height -= this._marginBottom.value;
  975. }
  976. else {
  977. this._currentMeasure.height -= parentHeight * this._marginBottom.value;
  978. }
  979. if (this._left.isPixel) {
  980. this._currentMeasure.left += this._left.value;
  981. }
  982. else {
  983. this._currentMeasure.left += parentWidth * this._left.value;
  984. }
  985. if (this._top.isPixel) {
  986. this._currentMeasure.top += this._top.value;
  987. }
  988. else {
  989. this._currentMeasure.top += parentHeight * this._top.value;
  990. }
  991. this._currentMeasure.left += x;
  992. this._currentMeasure.top += y;
  993. };
  994. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  995. // Do nothing
  996. };
  997. Control.prototype._draw = function (parentMeasure, context) {
  998. // Do nothing
  999. };
  1000. Control.prototype.contains = function (x, y) {
  1001. // Invert transform
  1002. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  1003. x = this._transformedPosition.x;
  1004. y = this._transformedPosition.y;
  1005. // Check
  1006. if (x < this._currentMeasure.left) {
  1007. return false;
  1008. }
  1009. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  1010. return false;
  1011. }
  1012. if (y < this._currentMeasure.top) {
  1013. return false;
  1014. }
  1015. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  1016. return false;
  1017. }
  1018. if (this.isPointerBlocker) {
  1019. this._host._shouldBlockPointer = true;
  1020. }
  1021. return true;
  1022. };
  1023. Control.prototype._processPicking = function (x, y, type) {
  1024. if (!this.isHitTestVisible) {
  1025. return false;
  1026. }
  1027. if (!this.contains(x, y)) {
  1028. return false;
  1029. }
  1030. this._processObservables(type);
  1031. return true;
  1032. };
  1033. Control.prototype._onPointerMove = function () {
  1034. if (this.onPointerMoveObservable.hasObservers()) {
  1035. this.onPointerMoveObservable.notifyObservers(this);
  1036. }
  1037. };
  1038. Control.prototype._onPointerEnter = function () {
  1039. if (this.onPointerEnterObservable.hasObservers()) {
  1040. this.onPointerEnterObservable.notifyObservers(this);
  1041. }
  1042. };
  1043. Control.prototype._onPointerOut = function () {
  1044. if (this.onPointerOutObservable.hasObservers()) {
  1045. this.onPointerOutObservable.notifyObservers(this);
  1046. }
  1047. };
  1048. Control.prototype._onPointerDown = function () {
  1049. if (this.onPointerDownObservable.hasObservers()) {
  1050. this.onPointerDownObservable.notifyObservers(this);
  1051. }
  1052. };
  1053. Control.prototype._onPointerUp = function () {
  1054. if (this.onPointerUpObservable.hasObservers()) {
  1055. this.onPointerUpObservable.notifyObservers(this);
  1056. }
  1057. };
  1058. Control.prototype._processObservables = function (type) {
  1059. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  1060. this._onPointerMove();
  1061. var previousControlOver = this._host._lastControlOver;
  1062. if (previousControlOver && previousControlOver !== this) {
  1063. previousControlOver._onPointerOut();
  1064. }
  1065. if (previousControlOver !== this) {
  1066. this._onPointerEnter();
  1067. }
  1068. this._host._lastControlOver = this;
  1069. return true;
  1070. }
  1071. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  1072. this._onPointerDown();
  1073. this._host._lastControlDown = this;
  1074. return true;
  1075. }
  1076. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  1077. if (this._host._lastControlDown) {
  1078. this._host._lastControlDown._onPointerUp();
  1079. }
  1080. this._host._lastControlDown = null;
  1081. return true;
  1082. }
  1083. return false;
  1084. };
  1085. Control.prototype._prepareFont = function () {
  1086. if (!this._fontFamily) {
  1087. return;
  1088. }
  1089. this._font = this._fontSize + "px " + this._fontFamily;
  1090. this._fontOffset = Control._GetFontOffset(this._font);
  1091. this._markAsDirty();
  1092. };
  1093. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  1094. get: function () {
  1095. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  1096. },
  1097. enumerable: true,
  1098. configurable: true
  1099. });
  1100. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  1101. get: function () {
  1102. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  1103. },
  1104. enumerable: true,
  1105. configurable: true
  1106. });
  1107. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  1108. get: function () {
  1109. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  1110. },
  1111. enumerable: true,
  1112. configurable: true
  1113. });
  1114. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  1115. get: function () {
  1116. return Control._VERTICAL_ALIGNMENT_TOP;
  1117. },
  1118. enumerable: true,
  1119. configurable: true
  1120. });
  1121. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  1122. get: function () {
  1123. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  1124. },
  1125. enumerable: true,
  1126. configurable: true
  1127. });
  1128. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  1129. get: function () {
  1130. return Control._VERTICAL_ALIGNMENT_CENTER;
  1131. },
  1132. enumerable: true,
  1133. configurable: true
  1134. });
  1135. Control._GetFontOffset = function (font) {
  1136. if (Control._FontHeightSizes[font]) {
  1137. return Control._FontHeightSizes[font];
  1138. }
  1139. var text = document.createElement("span");
  1140. text.innerHTML = "Hg";
  1141. text.style.font = font;
  1142. var block = document.createElement("div");
  1143. block.style.display = "inline-block";
  1144. block.style.width = "1px";
  1145. block.style.height = "0px";
  1146. block.style.verticalAlign = "bottom";
  1147. var div = document.createElement("div");
  1148. div.appendChild(text);
  1149. div.appendChild(block);
  1150. document.body.appendChild(div);
  1151. var fontAscent = 0;
  1152. var fontHeight = 0;
  1153. try {
  1154. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1155. block.style.verticalAlign = "baseline";
  1156. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1157. }
  1158. finally {
  1159. div.remove();
  1160. }
  1161. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  1162. Control._FontHeightSizes[font] = result;
  1163. return result;
  1164. };
  1165. ;
  1166. return Control;
  1167. }());
  1168. // Statics
  1169. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  1170. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  1171. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  1172. Control._VERTICAL_ALIGNMENT_TOP = 0;
  1173. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  1174. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  1175. Control._FontHeightSizes = {};
  1176. GUI.Control = Control;
  1177. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1178. })(BABYLON || (BABYLON = {}));
  1179. //# sourceMappingURL=control.js.map
  1180. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1181. var __extends = (this && this.__extends) || (function () {
  1182. var extendStatics = Object.setPrototypeOf ||
  1183. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1184. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1185. return function (d, b) {
  1186. extendStatics(d, b);
  1187. function __() { this.constructor = d; }
  1188. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1189. };
  1190. })();
  1191. var BABYLON;
  1192. (function (BABYLON) {
  1193. var GUI;
  1194. (function (GUI) {
  1195. var Container = (function (_super) {
  1196. __extends(Container, _super);
  1197. function Container(name) {
  1198. var _this = _super.call(this, name) || this;
  1199. _this.name = name;
  1200. _this._children = new Array();
  1201. _this._measureForChildren = GUI.Measure.Empty();
  1202. return _this;
  1203. }
  1204. Object.defineProperty(Container.prototype, "background", {
  1205. get: function () {
  1206. return this._background;
  1207. },
  1208. set: function (value) {
  1209. if (this._background === value) {
  1210. return;
  1211. }
  1212. this._background = value;
  1213. this._markAsDirty();
  1214. },
  1215. enumerable: true,
  1216. configurable: true
  1217. });
  1218. Container.prototype.containsControl = function (control) {
  1219. return this._children.indexOf(control) !== -1;
  1220. };
  1221. Container.prototype.addControl = function (control) {
  1222. var index = this._children.indexOf(control);
  1223. if (index !== -1) {
  1224. return this;
  1225. }
  1226. control._link(this, this._host);
  1227. this._reOrderControl(control);
  1228. this._markAsDirty();
  1229. return this;
  1230. };
  1231. Container.prototype.removeControl = function (control) {
  1232. var index = this._children.indexOf(control);
  1233. if (index !== -1) {
  1234. this._children.splice(index, 1);
  1235. }
  1236. this._markAsDirty();
  1237. return this;
  1238. };
  1239. Container.prototype._reOrderControl = function (control) {
  1240. this.removeControl(control);
  1241. for (var index = 0; index < this._children.length; index++) {
  1242. if (this._children[index].zIndex > control.zIndex) {
  1243. this._children.splice(index, 0, control);
  1244. return;
  1245. }
  1246. }
  1247. this._children.push(control);
  1248. this._markAsDirty();
  1249. };
  1250. Container.prototype._markMatrixAsDirty = function () {
  1251. _super.prototype._markMatrixAsDirty.call(this);
  1252. for (var index = 0; index < this._children.length; index++) {
  1253. this._children[index]._markMatrixAsDirty();
  1254. }
  1255. };
  1256. Container.prototype._localDraw = function (context) {
  1257. if (this._background) {
  1258. context.fillStyle = this._background;
  1259. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1260. }
  1261. };
  1262. Container.prototype._link = function (root, host) {
  1263. _super.prototype._link.call(this, root, host);
  1264. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1265. var child = _a[_i];
  1266. child._link(root, host);
  1267. }
  1268. };
  1269. Container.prototype._draw = function (parentMeasure, context) {
  1270. context.save();
  1271. _super.prototype._processMeasures.call(this, parentMeasure, context);
  1272. this._applyStates(context);
  1273. this._localDraw(context);
  1274. this._clipForChildren(context);
  1275. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1276. var child = _a[_i];
  1277. child._draw(this._measureForChildren, context);
  1278. }
  1279. context.restore();
  1280. };
  1281. Container.prototype._processPicking = function (x, y, type) {
  1282. if (!_super.prototype.contains.call(this, x, y)) {
  1283. return false;
  1284. }
  1285. // Checking backwards to pick closest first
  1286. for (var index = this._children.length - 1; index >= 0; index--) {
  1287. var child = this._children[index];
  1288. if (child._processPicking(x, y, type)) {
  1289. return true;
  1290. }
  1291. }
  1292. return this._processObservables(type);
  1293. };
  1294. Container.prototype._clipForChildren = function (context) {
  1295. // DO nothing
  1296. };
  1297. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  1298. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1299. this._measureForChildren.copyFrom(this._currentMeasure);
  1300. };
  1301. return Container;
  1302. }(GUI.Control));
  1303. GUI.Container = Container;
  1304. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1305. })(BABYLON || (BABYLON = {}));
  1306. //# sourceMappingURL=container.js.map
  1307. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1308. var __extends = (this && this.__extends) || (function () {
  1309. var extendStatics = Object.setPrototypeOf ||
  1310. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1311. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1312. return function (d, b) {
  1313. extendStatics(d, b);
  1314. function __() { this.constructor = d; }
  1315. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1316. };
  1317. })();
  1318. var BABYLON;
  1319. (function (BABYLON) {
  1320. var GUI;
  1321. (function (GUI) {
  1322. var StackPanel = (function (_super) {
  1323. __extends(StackPanel, _super);
  1324. function StackPanel(name) {
  1325. var _this = _super.call(this, name) || this;
  1326. _this.name = name;
  1327. _this._isVertical = true;
  1328. return _this;
  1329. }
  1330. Object.defineProperty(StackPanel.prototype, "isVertical", {
  1331. get: function () {
  1332. return this._isVertical;
  1333. },
  1334. set: function (value) {
  1335. if (this._isVertical === value) {
  1336. return;
  1337. }
  1338. this._isVertical = value;
  1339. this._markAsDirty();
  1340. },
  1341. enumerable: true,
  1342. configurable: true
  1343. });
  1344. StackPanel.prototype._additionalProcessing = function (parentMeasure, context) {
  1345. var stack = 0;
  1346. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1347. var child = _a[_i];
  1348. child._currentMeasure.copyFrom(parentMeasure);
  1349. child._measure();
  1350. if (this._isVertical) {
  1351. child.top = stack + "px";
  1352. stack += child._currentMeasure.height;
  1353. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1354. }
  1355. else {
  1356. child.left = stack + "px";
  1357. stack += child._currentMeasure.width;
  1358. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1359. }
  1360. }
  1361. if (this._isVertical) {
  1362. this.height = stack + "px";
  1363. }
  1364. else {
  1365. this.width = stack + "px";
  1366. }
  1367. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1368. };
  1369. return StackPanel;
  1370. }(GUI.Container));
  1371. GUI.StackPanel = StackPanel;
  1372. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1373. })(BABYLON || (BABYLON = {}));
  1374. //# sourceMappingURL=stackPanel.js.map
  1375. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1376. var __extends = (this && this.__extends) || (function () {
  1377. var extendStatics = Object.setPrototypeOf ||
  1378. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1379. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1380. return function (d, b) {
  1381. extendStatics(d, b);
  1382. function __() { this.constructor = d; }
  1383. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1384. };
  1385. })();
  1386. var BABYLON;
  1387. (function (BABYLON) {
  1388. var GUI;
  1389. (function (GUI) {
  1390. var Rectangle = (function (_super) {
  1391. __extends(Rectangle, _super);
  1392. function Rectangle(name) {
  1393. var _this = _super.call(this, name) || this;
  1394. _this.name = name;
  1395. _this._thickness = 1;
  1396. _this._cornerRadius = 0;
  1397. return _this;
  1398. }
  1399. Object.defineProperty(Rectangle.prototype, "thickness", {
  1400. get: function () {
  1401. return this._thickness;
  1402. },
  1403. set: function (value) {
  1404. if (this._thickness === value) {
  1405. return;
  1406. }
  1407. this._thickness = value;
  1408. this._markAsDirty();
  1409. },
  1410. enumerable: true,
  1411. configurable: true
  1412. });
  1413. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  1414. get: function () {
  1415. return this._cornerRadius;
  1416. },
  1417. set: function (value) {
  1418. if (value < 0) {
  1419. value = 0;
  1420. }
  1421. if (this._cornerRadius === value) {
  1422. return;
  1423. }
  1424. this._cornerRadius = value;
  1425. this._markAsDirty();
  1426. },
  1427. enumerable: true,
  1428. configurable: true
  1429. });
  1430. Object.defineProperty(Rectangle.prototype, "background", {
  1431. get: function () {
  1432. return this._background;
  1433. },
  1434. set: function (value) {
  1435. if (this._background === value) {
  1436. return;
  1437. }
  1438. this._background = value;
  1439. this._markAsDirty();
  1440. },
  1441. enumerable: true,
  1442. configurable: true
  1443. });
  1444. Rectangle.prototype._localDraw = function (context) {
  1445. context.save();
  1446. if (this._background) {
  1447. context.fillStyle = this._background;
  1448. if (this._cornerRadius) {
  1449. this._drawRoundedRect(context, this._thickness / 2);
  1450. context.fill();
  1451. }
  1452. else {
  1453. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1454. }
  1455. }
  1456. if (this._thickness) {
  1457. if (this.color) {
  1458. context.strokeStyle = this.color;
  1459. }
  1460. context.lineWidth = this._thickness;
  1461. if (this._cornerRadius) {
  1462. this._drawRoundedRect(context, this._thickness / 2);
  1463. context.stroke();
  1464. }
  1465. else {
  1466. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  1467. }
  1468. }
  1469. context.restore();
  1470. };
  1471. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  1472. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1473. this._measureForChildren.width -= 2 * this._thickness;
  1474. this._measureForChildren.height -= 2 * this._thickness;
  1475. this._measureForChildren.left += this._thickness;
  1476. this._measureForChildren.top += this._thickness;
  1477. };
  1478. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  1479. if (offset === void 0) { offset = 0; }
  1480. var x = this._currentMeasure.left + offset;
  1481. var y = this._currentMeasure.top + offset;
  1482. var width = this._currentMeasure.width - offset * 2;
  1483. var height = this._currentMeasure.height - offset * 2;
  1484. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  1485. context.beginPath();
  1486. context.moveTo(x + radius, y);
  1487. context.lineTo(x + width - radius, y);
  1488. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  1489. context.lineTo(x + width, y + height - radius);
  1490. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  1491. context.lineTo(x + radius, y + height);
  1492. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  1493. context.lineTo(x, y + radius);
  1494. context.quadraticCurveTo(x, y, x + radius, y);
  1495. context.closePath();
  1496. };
  1497. Rectangle.prototype._clipForChildren = function (context) {
  1498. if (this._cornerRadius) {
  1499. this._drawRoundedRect(context, this._thickness);
  1500. context.clip();
  1501. }
  1502. };
  1503. return Rectangle;
  1504. }(GUI.Container));
  1505. GUI.Rectangle = Rectangle;
  1506. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1507. })(BABYLON || (BABYLON = {}));
  1508. //# sourceMappingURL=rectangle.js.map
  1509. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1510. var __extends = (this && this.__extends) || (function () {
  1511. var extendStatics = Object.setPrototypeOf ||
  1512. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1513. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1514. return function (d, b) {
  1515. extendStatics(d, b);
  1516. function __() { this.constructor = d; }
  1517. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1518. };
  1519. })();
  1520. var BABYLON;
  1521. (function (BABYLON) {
  1522. var GUI;
  1523. (function (GUI) {
  1524. var Ellipse = (function (_super) {
  1525. __extends(Ellipse, _super);
  1526. function Ellipse(name) {
  1527. var _this = _super.call(this, name) || this;
  1528. _this.name = name;
  1529. _this._thickness = 1;
  1530. return _this;
  1531. }
  1532. Object.defineProperty(Ellipse.prototype, "thickness", {
  1533. get: function () {
  1534. return this._thickness;
  1535. },
  1536. set: function (value) {
  1537. if (this._thickness === value) {
  1538. return;
  1539. }
  1540. this._thickness = value;
  1541. this._markAsDirty();
  1542. },
  1543. enumerable: true,
  1544. configurable: true
  1545. });
  1546. Ellipse.prototype._localDraw = function (context) {
  1547. context.save();
  1548. context.beginPath();
  1549. 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);
  1550. context.closePath();
  1551. if (this._background) {
  1552. context.fillStyle = this._background;
  1553. context.fill();
  1554. }
  1555. if (this._thickness) {
  1556. if (this.color) {
  1557. context.strokeStyle = this.color;
  1558. }
  1559. context.lineWidth = this._thickness;
  1560. context.stroke();
  1561. }
  1562. context.restore();
  1563. };
  1564. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  1565. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1566. this._measureForChildren.width -= 2 * this._thickness;
  1567. this._measureForChildren.height -= 2 * this._thickness;
  1568. this._measureForChildren.left += this._thickness;
  1569. this._measureForChildren.top += this._thickness;
  1570. };
  1571. Ellipse.prototype._clipForChildren = function (context) {
  1572. context.beginPath();
  1573. 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);
  1574. context.clip();
  1575. };
  1576. return Ellipse;
  1577. }(GUI.Container));
  1578. GUI.Ellipse = Ellipse;
  1579. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1580. })(BABYLON || (BABYLON = {}));
  1581. //# sourceMappingURL=ellipse.js.map
  1582. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1583. var __extends = (this && this.__extends) || (function () {
  1584. var extendStatics = Object.setPrototypeOf ||
  1585. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1586. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1587. return function (d, b) {
  1588. extendStatics(d, b);
  1589. function __() { this.constructor = d; }
  1590. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1591. };
  1592. })();
  1593. var DOMImage = Image;
  1594. var BABYLON;
  1595. (function (BABYLON) {
  1596. var GUI;
  1597. (function (GUI) {
  1598. var Line = (function (_super) {
  1599. __extends(Line, _super);
  1600. function Line(name) {
  1601. var _this = _super.call(this, name) || this;
  1602. _this.name = name;
  1603. _this._lineWidth = 1;
  1604. _this._x1 = 0;
  1605. _this._y1 = 0;
  1606. _this._x2 = 0;
  1607. _this._y2 = 0;
  1608. _this._dash = new Array();
  1609. _this.isHitTestVisible = false;
  1610. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1611. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1612. return _this;
  1613. }
  1614. Object.defineProperty(Line.prototype, "dash", {
  1615. get: function () {
  1616. return this._dash;
  1617. },
  1618. set: function (value) {
  1619. if (this._dash === value) {
  1620. return;
  1621. }
  1622. this._dash = value;
  1623. this._markAsDirty();
  1624. },
  1625. enumerable: true,
  1626. configurable: true
  1627. });
  1628. Object.defineProperty(Line.prototype, "connectedControl", {
  1629. get: function () {
  1630. return this._connectedControl;
  1631. },
  1632. set: function (value) {
  1633. if (this._connectedControl === value) {
  1634. return;
  1635. }
  1636. this._connectedControl = value;
  1637. this._markAsDirty();
  1638. },
  1639. enumerable: true,
  1640. configurable: true
  1641. });
  1642. Object.defineProperty(Line.prototype, "x1", {
  1643. get: function () {
  1644. return this._x1;
  1645. },
  1646. set: function (value) {
  1647. if (this._x1 === value) {
  1648. return;
  1649. }
  1650. this._x1 = value;
  1651. this._markAsDirty();
  1652. },
  1653. enumerable: true,
  1654. configurable: true
  1655. });
  1656. Object.defineProperty(Line.prototype, "y1", {
  1657. get: function () {
  1658. return this._y1;
  1659. },
  1660. set: function (value) {
  1661. if (this._y1 === value) {
  1662. return;
  1663. }
  1664. this._y1 = value;
  1665. this._markAsDirty();
  1666. },
  1667. enumerable: true,
  1668. configurable: true
  1669. });
  1670. Object.defineProperty(Line.prototype, "x2", {
  1671. get: function () {
  1672. if (this._connectedControl) {
  1673. return this._connectedControl.centerX;
  1674. }
  1675. return this._x2;
  1676. },
  1677. set: function (value) {
  1678. if (this._x2 === value) {
  1679. return;
  1680. }
  1681. this._x2 = value;
  1682. this._markAsDirty();
  1683. },
  1684. enumerable: true,
  1685. configurable: true
  1686. });
  1687. Object.defineProperty(Line.prototype, "y2", {
  1688. get: function () {
  1689. if (this._connectedControl) {
  1690. return this._connectedControl.centerY;
  1691. }
  1692. return this._y2;
  1693. },
  1694. set: function (value) {
  1695. if (this._y2 === value) {
  1696. return;
  1697. }
  1698. this._y2 = value;
  1699. this._markAsDirty();
  1700. },
  1701. enumerable: true,
  1702. configurable: true
  1703. });
  1704. Object.defineProperty(Line.prototype, "lineWidth", {
  1705. get: function () {
  1706. return this._lineWidth;
  1707. },
  1708. set: function (value) {
  1709. if (this._lineWidth === value) {
  1710. return;
  1711. }
  1712. this._lineWidth = value;
  1713. this._markAsDirty();
  1714. },
  1715. enumerable: true,
  1716. configurable: true
  1717. });
  1718. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  1719. set: function (value) {
  1720. return;
  1721. },
  1722. enumerable: true,
  1723. configurable: true
  1724. });
  1725. Object.defineProperty(Line.prototype, "verticalAlignment", {
  1726. set: function (value) {
  1727. return;
  1728. },
  1729. enumerable: true,
  1730. configurable: true
  1731. });
  1732. Line.prototype._draw = function (parentMeasure, context) {
  1733. context.save();
  1734. this._applyStates(context);
  1735. _super.prototype._processMeasures.call(this, parentMeasure, context);
  1736. context.strokeStyle = this.color;
  1737. context.lineWidth = this._lineWidth;
  1738. context.setLineDash(this._dash);
  1739. context.beginPath();
  1740. context.moveTo(this._x1, this._y1);
  1741. context.lineTo(this.x2, this.y2);
  1742. context.stroke();
  1743. context.restore();
  1744. };
  1745. Line.prototype._measure = function () {
  1746. // Width / Height
  1747. this._currentMeasure.width = Math.abs(this._x1 - this.x2);
  1748. this._currentMeasure.height = Math.abs(this._y1 - this.y2);
  1749. };
  1750. Line.prototype._computeAlignment = function (parentMeasure, context) {
  1751. this._currentMeasure.left = Math.min(this._x1, this.x2);
  1752. this._currentMeasure.top = Math.min(this._y1, this.y2);
  1753. };
  1754. Line.prototype._moveToProjectedPosition = function (projectedPosition) {
  1755. this.x1 = projectedPosition.x + this.linkOffsetX;
  1756. this.y1 = projectedPosition.y + this.linkOffsetY;
  1757. };
  1758. return Line;
  1759. }(GUI.Control));
  1760. GUI.Line = Line;
  1761. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1762. })(BABYLON || (BABYLON = {}));
  1763. //# sourceMappingURL=line.js.map
  1764. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1765. var __extends = (this && this.__extends) || (function () {
  1766. var extendStatics = Object.setPrototypeOf ||
  1767. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1768. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1769. return function (d, b) {
  1770. extendStatics(d, b);
  1771. function __() { this.constructor = d; }
  1772. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1773. };
  1774. })();
  1775. var BABYLON;
  1776. (function (BABYLON) {
  1777. var GUI;
  1778. (function (GUI) {
  1779. var TextBlock = (function (_super) {
  1780. __extends(TextBlock, _super);
  1781. function TextBlock(name, text) {
  1782. var _this = _super.call(this, name) || this;
  1783. _this.name = name;
  1784. _this._textWrapping = false;
  1785. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1786. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  1787. _this.text = text;
  1788. return _this;
  1789. }
  1790. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  1791. get: function () {
  1792. return this._textWrapping;
  1793. },
  1794. set: function (value) {
  1795. if (this._textWrapping === value) {
  1796. return;
  1797. }
  1798. this._textWrapping = value;
  1799. this._markAsDirty();
  1800. },
  1801. enumerable: true,
  1802. configurable: true
  1803. });
  1804. Object.defineProperty(TextBlock.prototype, "text", {
  1805. get: function () {
  1806. return this._text;
  1807. },
  1808. set: function (value) {
  1809. if (this._text === value) {
  1810. return;
  1811. }
  1812. this._text = value;
  1813. this._markAsDirty();
  1814. },
  1815. enumerable: true,
  1816. configurable: true
  1817. });
  1818. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  1819. get: function () {
  1820. return this._textHorizontalAlignment;
  1821. },
  1822. set: function (value) {
  1823. if (this._textHorizontalAlignment === value) {
  1824. return;
  1825. }
  1826. this._textHorizontalAlignment = value;
  1827. this._markAsDirty();
  1828. },
  1829. enumerable: true,
  1830. configurable: true
  1831. });
  1832. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  1833. get: function () {
  1834. return this._textVerticalAlignment;
  1835. },
  1836. set: function (value) {
  1837. if (this._textVerticalAlignment === value) {
  1838. return;
  1839. }
  1840. this._textVerticalAlignment = value;
  1841. this._markAsDirty();
  1842. },
  1843. enumerable: true,
  1844. configurable: true
  1845. });
  1846. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  1847. var width = this._currentMeasure.width;
  1848. var x = 0;
  1849. switch (this._textHorizontalAlignment) {
  1850. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  1851. x = 0;
  1852. break;
  1853. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  1854. x = width - textWidth;
  1855. break;
  1856. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  1857. x = (width - textWidth) / 2;
  1858. break;
  1859. }
  1860. context.fillText(text, this._currentMeasure.left + x, y);
  1861. };
  1862. TextBlock.prototype._draw = function (parentMeasure, context) {
  1863. context.save();
  1864. this._applyStates(context);
  1865. _super.prototype._processMeasures.call(this, parentMeasure, context);
  1866. // Render lines
  1867. this._renderLines(context);
  1868. context.restore();
  1869. };
  1870. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  1871. this._lines = [];
  1872. if (this._textWrapping) {
  1873. var words = this.text.split(' ');
  1874. var line = '';
  1875. var width = this._currentMeasure.width;
  1876. var lineWidth = 0;
  1877. for (var n = 0; n < words.length; n++) {
  1878. var testLine = line + words[n] + ' ';
  1879. var metrics = context.measureText(testLine);
  1880. var testWidth = metrics.width;
  1881. if (testWidth > width && n > 0) {
  1882. this._lines.push({ text: line, width: lineWidth });
  1883. line = words[n] + ' ';
  1884. lineWidth = context.measureText(line).width;
  1885. }
  1886. else {
  1887. lineWidth = testWidth;
  1888. line = testLine;
  1889. }
  1890. }
  1891. this._lines.push({ text: line, width: lineWidth });
  1892. }
  1893. else {
  1894. this._lines.push({ text: this.text, width: context.measureText(this.text).width });
  1895. }
  1896. };
  1897. TextBlock.prototype._renderLines = function (context) {
  1898. var width = this._currentMeasure.width;
  1899. var height = this._currentMeasure.height;
  1900. if (!this._fontOffset) {
  1901. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  1902. }
  1903. var rootY = 0;
  1904. switch (this._textVerticalAlignment) {
  1905. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  1906. rootY = this._fontOffset.ascent;
  1907. break;
  1908. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  1909. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  1910. break;
  1911. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  1912. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  1913. break;
  1914. }
  1915. rootY += this._currentMeasure.top;
  1916. for (var _i = 0, _a = this._lines; _i < _a.length; _i++) {
  1917. var line = _a[_i];
  1918. this._drawText(line.text, line.width, rootY, context);
  1919. rootY += this._fontOffset.height;
  1920. }
  1921. };
  1922. return TextBlock;
  1923. }(GUI.Control));
  1924. GUI.TextBlock = TextBlock;
  1925. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1926. })(BABYLON || (BABYLON = {}));
  1927. //# sourceMappingURL=textBlock.js.map
  1928. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1929. var __extends = (this && this.__extends) || (function () {
  1930. var extendStatics = Object.setPrototypeOf ||
  1931. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1932. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1933. return function (d, b) {
  1934. extendStatics(d, b);
  1935. function __() { this.constructor = d; }
  1936. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1937. };
  1938. })();
  1939. var DOMImage = Image;
  1940. var BABYLON;
  1941. (function (BABYLON) {
  1942. var GUI;
  1943. (function (GUI) {
  1944. var Image = (function (_super) {
  1945. __extends(Image, _super);
  1946. function Image(name, url) {
  1947. var _this = _super.call(this, name) || this;
  1948. _this.name = name;
  1949. _this._loaded = false;
  1950. _this._stretch = Image.STRETCH_FILL;
  1951. _this._domImage = new DOMImage();
  1952. _this._domImage.onload = function () {
  1953. _this._imageWidth = _this._domImage.width;
  1954. _this._imageHeight = _this._domImage.height;
  1955. _this._loaded = true;
  1956. _this._markAsDirty();
  1957. };
  1958. _this._domImage.src = url;
  1959. return _this;
  1960. }
  1961. Object.defineProperty(Image.prototype, "stretch", {
  1962. get: function () {
  1963. return this._stretch;
  1964. },
  1965. set: function (value) {
  1966. if (this._stretch === value) {
  1967. return;
  1968. }
  1969. this._stretch = value;
  1970. this._markAsDirty();
  1971. },
  1972. enumerable: true,
  1973. configurable: true
  1974. });
  1975. Image.prototype._draw = function (parentMeasure, context) {
  1976. context.save();
  1977. this._applyStates(context);
  1978. _super.prototype._processMeasures.call(this, parentMeasure, context);
  1979. if (this._loaded) {
  1980. switch (this._stretch) {
  1981. case Image.STRETCH_NONE:
  1982. context.drawImage(this._domImage, this._currentMeasure.left, this._currentMeasure.top);
  1983. break;
  1984. case Image.STRETCH_FILL:
  1985. context.drawImage(this._domImage, 0, 0, this._imageWidth, this._imageHeight, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1986. break;
  1987. case Image.STRETCH_UNIFORM:
  1988. var hRatio = this._currentMeasure.width / this._imageWidth;
  1989. var vRatio = this._currentMeasure.height / this._imageHeight;
  1990. var ratio = Math.min(hRatio, vRatio);
  1991. var centerX = (this._currentMeasure.width - this._imageWidth * ratio) / 2;
  1992. var centerY = (this._currentMeasure.height - this._imageHeight * ratio) / 2;
  1993. context.drawImage(this._domImage, 0, 0, this._imageWidth, this._imageHeight, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, this._imageWidth * ratio, this._imageHeight * ratio);
  1994. break;
  1995. }
  1996. }
  1997. context.restore();
  1998. };
  1999. Object.defineProperty(Image, "STRETCH_NONE", {
  2000. get: function () {
  2001. return Image._STRETCH_NONE;
  2002. },
  2003. enumerable: true,
  2004. configurable: true
  2005. });
  2006. Object.defineProperty(Image, "STRETCH_FILL", {
  2007. get: function () {
  2008. return Image._STRETCH_FILL;
  2009. },
  2010. enumerable: true,
  2011. configurable: true
  2012. });
  2013. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  2014. get: function () {
  2015. return Image._STRETCH_UNIFORM;
  2016. },
  2017. enumerable: true,
  2018. configurable: true
  2019. });
  2020. return Image;
  2021. }(GUI.Control));
  2022. // Static
  2023. Image._STRETCH_NONE = 0;
  2024. Image._STRETCH_FILL = 1;
  2025. Image._STRETCH_UNIFORM = 2;
  2026. GUI.Image = Image;
  2027. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2028. })(BABYLON || (BABYLON = {}));
  2029. //# sourceMappingURL=image.js.map
  2030. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2031. var __extends = (this && this.__extends) || (function () {
  2032. var extendStatics = Object.setPrototypeOf ||
  2033. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2034. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2035. return function (d, b) {
  2036. extendStatics(d, b);
  2037. function __() { this.constructor = d; }
  2038. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2039. };
  2040. })();
  2041. var BABYLON;
  2042. (function (BABYLON) {
  2043. var GUI;
  2044. (function (GUI) {
  2045. var Button = (function (_super) {
  2046. __extends(Button, _super);
  2047. function Button(name) {
  2048. var _this = _super.call(this, name) || this;
  2049. _this.name = name;
  2050. _this.thickness = 1;
  2051. _this.isPointerBlocker = true;
  2052. return _this;
  2053. }
  2054. // While being a container, the button behaves like a control.
  2055. Button.prototype._processPicking = function (x, y, type) {
  2056. if (!this.contains(x, y)) {
  2057. return false;
  2058. }
  2059. this._processObservables(type);
  2060. return true;
  2061. };
  2062. Button.prototype._onPointerEnter = function () {
  2063. this.alpha -= 0.1;
  2064. _super.prototype._onPointerEnter.call(this);
  2065. };
  2066. Button.prototype._onPointerOut = function () {
  2067. this.alpha += 0.1;
  2068. _super.prototype._onPointerOut.call(this);
  2069. };
  2070. Button.prototype._onPointerDown = function () {
  2071. this.scaleX -= 0.05;
  2072. this.scaleY -= 0.05;
  2073. _super.prototype._onPointerDown.call(this);
  2074. };
  2075. Button.prototype._onPointerUp = function () {
  2076. this.scaleX += 0.05;
  2077. this.scaleY += 0.05;
  2078. _super.prototype._onPointerUp.call(this);
  2079. };
  2080. // Statics
  2081. Button.CreateImageButton = function (name, text, imageUrl) {
  2082. var result = new Button(name);
  2083. // Adding text
  2084. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  2085. textBlock.textWrapping = true;
  2086. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  2087. textBlock.marginLeft = "20%";
  2088. result.addControl(textBlock);
  2089. // Adding image
  2090. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  2091. iconImage.width = "20%";
  2092. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  2093. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2094. result.addControl(iconImage);
  2095. return result;
  2096. };
  2097. Button.CreateSimpleButton = function (name, text) {
  2098. var result = new Button(name);
  2099. // Adding text
  2100. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  2101. textBlock.textWrapping = true;
  2102. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  2103. result.addControl(textBlock);
  2104. return result;
  2105. };
  2106. return Button;
  2107. }(GUI.Rectangle));
  2108. GUI.Button = Button;
  2109. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2110. })(BABYLON || (BABYLON = {}));
  2111. //# sourceMappingURL=button.js.map