babylon.gui.js 105 KB

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