babylon.gui.js 112 KB

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