babylon.gui.js 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788
  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._color = "white";
  549. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  550. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  551. this._isDirty = true;
  552. this._cachedParentMeasure = GUI.Measure.Empty();
  553. this._marginLeft = new GUI.ValueAndUnit(0);
  554. this._marginRight = new GUI.ValueAndUnit(0);
  555. this._marginTop = new GUI.ValueAndUnit(0);
  556. this._marginBottom = new GUI.ValueAndUnit(0);
  557. this._left = new GUI.ValueAndUnit(0);
  558. this._top = new GUI.ValueAndUnit(0);
  559. this._scaleX = 1.0;
  560. this._scaleY = 1.0;
  561. this._rotation = 0;
  562. this._transformCenterX = 0.5;
  563. this._transformCenterY = 0.5;
  564. this._transformMatrix = GUI.Matrix2D.Identity();
  565. this._invertTransformMatrix = GUI.Matrix2D.Identity();
  566. this._transformedPosition = BABYLON.Vector2.Zero();
  567. this._isMatrixDirty = true;
  568. this._isVisible = true;
  569. this._fontSet = false;
  570. this._dummyVector2 = BABYLON.Vector2.Zero();
  571. this.isHitTestVisible = true;
  572. this.isPointerBlocker = false;
  573. this._linkOffsetX = new GUI.ValueAndUnit(0);
  574. this._linkOffsetY = new GUI.ValueAndUnit(0);
  575. // Properties
  576. /**
  577. * An event triggered when the pointer move over the control.
  578. * @type {BABYLON.Observable}
  579. */
  580. this.onPointerMoveObservable = new BABYLON.Observable();
  581. /**
  582. * An event triggered when the pointer move out of the control.
  583. * @type {BABYLON.Observable}
  584. */
  585. this.onPointerOutObservable = new BABYLON.Observable();
  586. /**
  587. * An event triggered when the pointer taps the control
  588. * @type {BABYLON.Observable}
  589. */
  590. this.onPointerDownObservable = new BABYLON.Observable();
  591. /**
  592. * An event triggered when pointer up
  593. * @type {BABYLON.Observable}
  594. */
  595. this.onPointerUpObservable = new BABYLON.Observable();
  596. /**
  597. * An event triggered when pointer enters the control
  598. * @type {BABYLON.Observable}
  599. */
  600. this.onPointerEnterObservable = new BABYLON.Observable();
  601. /**
  602. * An event triggered when the control is marked as dirty
  603. * @type {BABYLON.Observable}
  604. */
  605. this.onDirtyObservable = new BABYLON.Observable();
  606. }
  607. Object.defineProperty(Control.prototype, "alpha", {
  608. get: function () {
  609. return this._alpha;
  610. },
  611. set: function (value) {
  612. if (this._alpha === value) {
  613. return;
  614. }
  615. this._alpha = value;
  616. this._markAsDirty();
  617. },
  618. enumerable: true,
  619. configurable: true
  620. });
  621. Object.defineProperty(Control.prototype, "scaleX", {
  622. get: function () {
  623. return this._scaleX;
  624. },
  625. set: function (value) {
  626. if (this._scaleX === value) {
  627. return;
  628. }
  629. this._scaleX = value;
  630. this._markAsDirty();
  631. this._markMatrixAsDirty();
  632. },
  633. enumerable: true,
  634. configurable: true
  635. });
  636. Object.defineProperty(Control.prototype, "scaleY", {
  637. get: function () {
  638. return this._scaleY;
  639. },
  640. set: function (value) {
  641. if (this._scaleY === value) {
  642. return;
  643. }
  644. this._scaleY = value;
  645. this._markAsDirty();
  646. this._markMatrixAsDirty();
  647. },
  648. enumerable: true,
  649. configurable: true
  650. });
  651. Object.defineProperty(Control.prototype, "rotation", {
  652. get: function () {
  653. return this._rotation;
  654. },
  655. set: function (value) {
  656. if (this._rotation === value) {
  657. return;
  658. }
  659. this._rotation = value;
  660. this._markAsDirty();
  661. this._markMatrixAsDirty();
  662. },
  663. enumerable: true,
  664. configurable: true
  665. });
  666. Object.defineProperty(Control.prototype, "transformCenterY", {
  667. get: function () {
  668. return this._transformCenterY;
  669. },
  670. set: function (value) {
  671. if (this._transformCenterY === value) {
  672. return;
  673. }
  674. this._transformCenterY = value;
  675. this._markAsDirty();
  676. this._markMatrixAsDirty();
  677. },
  678. enumerable: true,
  679. configurable: true
  680. });
  681. Object.defineProperty(Control.prototype, "transformCenterX", {
  682. get: function () {
  683. return this._transformCenterX;
  684. },
  685. set: function (value) {
  686. if (this._transformCenterX === value) {
  687. return;
  688. }
  689. this._transformCenterX = value;
  690. this._markAsDirty();
  691. this._markMatrixAsDirty();
  692. },
  693. enumerable: true,
  694. configurable: true
  695. });
  696. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  697. get: function () {
  698. return this._horizontalAlignment;
  699. },
  700. set: function (value) {
  701. if (this._horizontalAlignment === value) {
  702. return;
  703. }
  704. this._horizontalAlignment = value;
  705. this._markAsDirty();
  706. },
  707. enumerable: true,
  708. configurable: true
  709. });
  710. Object.defineProperty(Control.prototype, "verticalAlignment", {
  711. get: function () {
  712. return this._verticalAlignment;
  713. },
  714. set: function (value) {
  715. if (this._verticalAlignment === value) {
  716. return;
  717. }
  718. this._verticalAlignment = value;
  719. this._markAsDirty();
  720. },
  721. enumerable: true,
  722. configurable: true
  723. });
  724. Object.defineProperty(Control.prototype, "width", {
  725. get: function () {
  726. return this._width.toString(this._host);
  727. },
  728. set: function (value) {
  729. if (this._width.toString(this._host) === value) {
  730. return;
  731. }
  732. if (this._width.fromString(value)) {
  733. this._markAsDirty();
  734. }
  735. },
  736. enumerable: true,
  737. configurable: true
  738. });
  739. Object.defineProperty(Control.prototype, "height", {
  740. get: function () {
  741. return this._height.toString(this._host);
  742. },
  743. set: function (value) {
  744. if (this._height.toString(this._host) === value) {
  745. return;
  746. }
  747. if (this._height.fromString(value)) {
  748. this._markAsDirty();
  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. Control.AddHeader = function (control, text, size, options) {
  1326. var panel = new BABYLON.GUI.StackPanel("panel");
  1327. var isHorizontal = options ? options.isHorizontal : true;
  1328. var controlFirst = options ? options.controlFirst : false;
  1329. panel.isVertical = !isHorizontal;
  1330. var header = new BABYLON.GUI.TextBlock("header");
  1331. header.text = text;
  1332. header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  1333. if (isHorizontal) {
  1334. header.width = size;
  1335. }
  1336. else {
  1337. header.height = size;
  1338. }
  1339. if (controlFirst) {
  1340. panel.addControl(control);
  1341. panel.addControl(header);
  1342. header.marginLeft = "5px";
  1343. }
  1344. else {
  1345. panel.addControl(header);
  1346. panel.addControl(control);
  1347. header.marginRight = "5px";
  1348. }
  1349. return panel;
  1350. };
  1351. return Control;
  1352. }());
  1353. // Statics
  1354. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  1355. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  1356. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  1357. Control._VERTICAL_ALIGNMENT_TOP = 0;
  1358. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  1359. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  1360. Control._FontHeightSizes = {};
  1361. GUI.Control = Control;
  1362. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1363. })(BABYLON || (BABYLON = {}));
  1364. //# sourceMappingURL=control.js.map
  1365. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1366. var __extends = (this && this.__extends) || (function () {
  1367. var extendStatics = Object.setPrototypeOf ||
  1368. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1369. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1370. return function (d, b) {
  1371. extendStatics(d, b);
  1372. function __() { this.constructor = d; }
  1373. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1374. };
  1375. })();
  1376. var BABYLON;
  1377. (function (BABYLON) {
  1378. var GUI;
  1379. (function (GUI) {
  1380. var Container = (function (_super) {
  1381. __extends(Container, _super);
  1382. function Container(name) {
  1383. var _this = _super.call(this, name) || this;
  1384. _this.name = name;
  1385. _this._children = new Array();
  1386. _this._measureForChildren = GUI.Measure.Empty();
  1387. return _this;
  1388. }
  1389. Object.defineProperty(Container.prototype, "background", {
  1390. get: function () {
  1391. return this._background;
  1392. },
  1393. set: function (value) {
  1394. if (this._background === value) {
  1395. return;
  1396. }
  1397. this._background = value;
  1398. this._markAsDirty();
  1399. },
  1400. enumerable: true,
  1401. configurable: true
  1402. });
  1403. Object.defineProperty(Container.prototype, "children", {
  1404. get: function () {
  1405. return this._children;
  1406. },
  1407. enumerable: true,
  1408. configurable: true
  1409. });
  1410. Container.prototype.getChildByName = function (name) {
  1411. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1412. var child = _a[_i];
  1413. if (child.name === name) {
  1414. return child;
  1415. }
  1416. }
  1417. return null;
  1418. };
  1419. Container.prototype.containsControl = function (control) {
  1420. return this._children.indexOf(control) !== -1;
  1421. };
  1422. Container.prototype.addControl = function (control) {
  1423. var index = this._children.indexOf(control);
  1424. if (index !== -1) {
  1425. return this;
  1426. }
  1427. control._link(this, this._host);
  1428. this._reOrderControl(control);
  1429. this._markAsDirty();
  1430. return this;
  1431. };
  1432. Container.prototype.removeControl = function (control) {
  1433. var index = this._children.indexOf(control);
  1434. if (index !== -1) {
  1435. this._children.splice(index, 1);
  1436. }
  1437. this._markAsDirty();
  1438. return this;
  1439. };
  1440. Container.prototype._reOrderControl = function (control) {
  1441. this.removeControl(control);
  1442. for (var index = 0; index < this._children.length; index++) {
  1443. if (this._children[index].zIndex > control.zIndex) {
  1444. this._children.splice(index, 0, control);
  1445. return;
  1446. }
  1447. }
  1448. this._children.push(control);
  1449. this._markAsDirty();
  1450. };
  1451. Container.prototype._markMatrixAsDirty = function () {
  1452. _super.prototype._markMatrixAsDirty.call(this);
  1453. for (var index = 0; index < this._children.length; index++) {
  1454. this._children[index]._markMatrixAsDirty();
  1455. }
  1456. };
  1457. Container.prototype._markAllAsDirty = function () {
  1458. _super.prototype._markAllAsDirty.call(this);
  1459. for (var index = 0; index < this._children.length; index++) {
  1460. this._children[index]._markAllAsDirty();
  1461. }
  1462. };
  1463. Container.prototype._localDraw = function (context) {
  1464. if (this._background) {
  1465. context.fillStyle = this._background;
  1466. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1467. }
  1468. };
  1469. Container.prototype._link = function (root, host) {
  1470. _super.prototype._link.call(this, root, host);
  1471. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1472. var child = _a[_i];
  1473. child._link(root, host);
  1474. }
  1475. };
  1476. Container.prototype._draw = function (parentMeasure, context) {
  1477. context.save();
  1478. this._applyStates(context);
  1479. if (this._processMeasures(parentMeasure, context)) {
  1480. this._localDraw(context);
  1481. this._clipForChildren(context);
  1482. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1483. var child = _a[_i];
  1484. if (child.isVisible) {
  1485. child._draw(this._measureForChildren, context);
  1486. }
  1487. }
  1488. }
  1489. context.restore();
  1490. };
  1491. Container.prototype._processPicking = function (x, y, type) {
  1492. if (!_super.prototype.contains.call(this, x, y)) {
  1493. return false;
  1494. }
  1495. // Checking backwards to pick closest first
  1496. for (var index = this._children.length - 1; index >= 0; index--) {
  1497. var child = this._children[index];
  1498. if (child._processPicking(x, y, type)) {
  1499. return true;
  1500. }
  1501. }
  1502. return this._processObservables(type, x, y);
  1503. };
  1504. Container.prototype._clipForChildren = function (context) {
  1505. // DO nothing
  1506. };
  1507. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  1508. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1509. this._measureForChildren.copyFrom(this._currentMeasure);
  1510. };
  1511. return Container;
  1512. }(GUI.Control));
  1513. GUI.Container = Container;
  1514. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1515. })(BABYLON || (BABYLON = {}));
  1516. //# sourceMappingURL=container.js.map
  1517. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1518. var __extends = (this && this.__extends) || (function () {
  1519. var extendStatics = Object.setPrototypeOf ||
  1520. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1521. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1522. return function (d, b) {
  1523. extendStatics(d, b);
  1524. function __() { this.constructor = d; }
  1525. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1526. };
  1527. })();
  1528. var BABYLON;
  1529. (function (BABYLON) {
  1530. var GUI;
  1531. (function (GUI) {
  1532. var StackPanel = (function (_super) {
  1533. __extends(StackPanel, _super);
  1534. function StackPanel(name) {
  1535. var _this = _super.call(this, name) || this;
  1536. _this.name = name;
  1537. _this._isVertical = true;
  1538. return _this;
  1539. }
  1540. Object.defineProperty(StackPanel.prototype, "isVertical", {
  1541. get: function () {
  1542. return this._isVertical;
  1543. },
  1544. set: function (value) {
  1545. if (this._isVertical === value) {
  1546. return;
  1547. }
  1548. this._isVertical = value;
  1549. this._markAsDirty();
  1550. },
  1551. enumerable: true,
  1552. configurable: true
  1553. });
  1554. StackPanel.prototype._additionalProcessing = function (parentMeasure, context) {
  1555. var stack = 0;
  1556. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1557. var child = _a[_i];
  1558. child._currentMeasure.copyFrom(parentMeasure);
  1559. child._measure();
  1560. if (this._isVertical) {
  1561. child.top = stack + "px";
  1562. stack += child._currentMeasure.height;
  1563. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1564. }
  1565. else {
  1566. child.left = stack + "px";
  1567. stack += child._currentMeasure.width;
  1568. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1569. }
  1570. }
  1571. if (this._isVertical) {
  1572. this.height = stack + "px";
  1573. this._height.ignoreAdaptiveScaling = true;
  1574. }
  1575. else {
  1576. this.width = stack + "px";
  1577. this._width.ignoreAdaptiveScaling = true;
  1578. }
  1579. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1580. };
  1581. return StackPanel;
  1582. }(GUI.Container));
  1583. GUI.StackPanel = StackPanel;
  1584. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1585. })(BABYLON || (BABYLON = {}));
  1586. //# sourceMappingURL=stackPanel.js.map
  1587. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1588. var __extends = (this && this.__extends) || (function () {
  1589. var extendStatics = Object.setPrototypeOf ||
  1590. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1591. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1592. return function (d, b) {
  1593. extendStatics(d, b);
  1594. function __() { this.constructor = d; }
  1595. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1596. };
  1597. })();
  1598. var BABYLON;
  1599. (function (BABYLON) {
  1600. var GUI;
  1601. (function (GUI) {
  1602. var Rectangle = (function (_super) {
  1603. __extends(Rectangle, _super);
  1604. function Rectangle(name) {
  1605. var _this = _super.call(this, name) || this;
  1606. _this.name = name;
  1607. _this._thickness = 1;
  1608. _this._cornerRadius = 0;
  1609. return _this;
  1610. }
  1611. Object.defineProperty(Rectangle.prototype, "thickness", {
  1612. get: function () {
  1613. return this._thickness;
  1614. },
  1615. set: function (value) {
  1616. if (this._thickness === value) {
  1617. return;
  1618. }
  1619. this._thickness = value;
  1620. this._markAsDirty();
  1621. },
  1622. enumerable: true,
  1623. configurable: true
  1624. });
  1625. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  1626. get: function () {
  1627. return this._cornerRadius;
  1628. },
  1629. set: function (value) {
  1630. if (value < 0) {
  1631. value = 0;
  1632. }
  1633. if (this._cornerRadius === value) {
  1634. return;
  1635. }
  1636. this._cornerRadius = value;
  1637. this._markAsDirty();
  1638. },
  1639. enumerable: true,
  1640. configurable: true
  1641. });
  1642. Rectangle.prototype._localDraw = function (context) {
  1643. context.save();
  1644. if (this._background) {
  1645. context.fillStyle = this._background;
  1646. if (this._cornerRadius) {
  1647. this._drawRoundedRect(context, this._thickness / 2);
  1648. context.fill();
  1649. }
  1650. else {
  1651. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1652. }
  1653. }
  1654. if (this._thickness) {
  1655. if (this.color) {
  1656. context.strokeStyle = this.color;
  1657. }
  1658. context.lineWidth = this._thickness;
  1659. if (this._cornerRadius) {
  1660. this._drawRoundedRect(context, this._thickness / 2);
  1661. context.stroke();
  1662. }
  1663. else {
  1664. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  1665. }
  1666. }
  1667. context.restore();
  1668. };
  1669. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  1670. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1671. this._measureForChildren.width -= 2 * this._thickness;
  1672. this._measureForChildren.height -= 2 * this._thickness;
  1673. this._measureForChildren.left += this._thickness;
  1674. this._measureForChildren.top += this._thickness;
  1675. };
  1676. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  1677. if (offset === void 0) { offset = 0; }
  1678. var x = this._currentMeasure.left + offset;
  1679. var y = this._currentMeasure.top + offset;
  1680. var width = this._currentMeasure.width - offset * 2;
  1681. var height = this._currentMeasure.height - offset * 2;
  1682. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  1683. context.beginPath();
  1684. context.moveTo(x + radius, y);
  1685. context.lineTo(x + width - radius, y);
  1686. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  1687. context.lineTo(x + width, y + height - radius);
  1688. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  1689. context.lineTo(x + radius, y + height);
  1690. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  1691. context.lineTo(x, y + radius);
  1692. context.quadraticCurveTo(x, y, x + radius, y);
  1693. context.closePath();
  1694. };
  1695. Rectangle.prototype._clipForChildren = function (context) {
  1696. if (this._cornerRadius) {
  1697. this._drawRoundedRect(context, this._thickness);
  1698. context.clip();
  1699. }
  1700. };
  1701. return Rectangle;
  1702. }(GUI.Container));
  1703. GUI.Rectangle = Rectangle;
  1704. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1705. })(BABYLON || (BABYLON = {}));
  1706. //# sourceMappingURL=rectangle.js.map
  1707. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1708. var __extends = (this && this.__extends) || (function () {
  1709. var extendStatics = Object.setPrototypeOf ||
  1710. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1711. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1712. return function (d, b) {
  1713. extendStatics(d, b);
  1714. function __() { this.constructor = d; }
  1715. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1716. };
  1717. })();
  1718. var BABYLON;
  1719. (function (BABYLON) {
  1720. var GUI;
  1721. (function (GUI) {
  1722. var Ellipse = (function (_super) {
  1723. __extends(Ellipse, _super);
  1724. function Ellipse(name) {
  1725. var _this = _super.call(this, name) || this;
  1726. _this.name = name;
  1727. _this._thickness = 1;
  1728. return _this;
  1729. }
  1730. Object.defineProperty(Ellipse.prototype, "thickness", {
  1731. get: function () {
  1732. return this._thickness;
  1733. },
  1734. set: function (value) {
  1735. if (this._thickness === value) {
  1736. return;
  1737. }
  1738. this._thickness = value;
  1739. this._markAsDirty();
  1740. },
  1741. enumerable: true,
  1742. configurable: true
  1743. });
  1744. Ellipse.prototype._localDraw = function (context) {
  1745. context.save();
  1746. context.beginPath();
  1747. 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);
  1748. context.closePath();
  1749. if (this._background) {
  1750. context.fillStyle = this._background;
  1751. context.fill();
  1752. }
  1753. if (this._thickness) {
  1754. if (this.color) {
  1755. context.strokeStyle = this.color;
  1756. }
  1757. context.lineWidth = this._thickness;
  1758. context.stroke();
  1759. }
  1760. context.restore();
  1761. };
  1762. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  1763. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1764. this._measureForChildren.width -= 2 * this._thickness;
  1765. this._measureForChildren.height -= 2 * this._thickness;
  1766. this._measureForChildren.left += this._thickness;
  1767. this._measureForChildren.top += this._thickness;
  1768. };
  1769. Ellipse.prototype._clipForChildren = function (context) {
  1770. context.beginPath();
  1771. 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);
  1772. context.clip();
  1773. };
  1774. return Ellipse;
  1775. }(GUI.Container));
  1776. GUI.Ellipse = Ellipse;
  1777. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1778. })(BABYLON || (BABYLON = {}));
  1779. //# sourceMappingURL=ellipse.js.map
  1780. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1781. var __extends = (this && this.__extends) || (function () {
  1782. var extendStatics = Object.setPrototypeOf ||
  1783. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1784. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1785. return function (d, b) {
  1786. extendStatics(d, b);
  1787. function __() { this.constructor = d; }
  1788. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1789. };
  1790. })();
  1791. var DOMImage = Image;
  1792. var BABYLON;
  1793. (function (BABYLON) {
  1794. var GUI;
  1795. (function (GUI) {
  1796. var Line = (function (_super) {
  1797. __extends(Line, _super);
  1798. function Line(name) {
  1799. var _this = _super.call(this, name) || this;
  1800. _this.name = name;
  1801. _this._lineWidth = 1;
  1802. _this._x1 = new GUI.ValueAndUnit(0);
  1803. _this._y1 = new GUI.ValueAndUnit(0);
  1804. _this._x2 = new GUI.ValueAndUnit(0);
  1805. _this._y2 = new GUI.ValueAndUnit(0);
  1806. _this._dash = new Array();
  1807. _this.isHitTestVisible = false;
  1808. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1809. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1810. return _this;
  1811. }
  1812. Object.defineProperty(Line.prototype, "dash", {
  1813. get: function () {
  1814. return this._dash;
  1815. },
  1816. set: function (value) {
  1817. if (this._dash === value) {
  1818. return;
  1819. }
  1820. this._dash = value;
  1821. this._markAsDirty();
  1822. },
  1823. enumerable: true,
  1824. configurable: true
  1825. });
  1826. Object.defineProperty(Line.prototype, "connectedControl", {
  1827. get: function () {
  1828. return this._connectedControl;
  1829. },
  1830. set: function (value) {
  1831. var _this = this;
  1832. if (this._connectedControl === value) {
  1833. return;
  1834. }
  1835. if (this._connectedControlDirtyObserver && this._connectedControl) {
  1836. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  1837. this._connectedControlDirtyObserver = null;
  1838. }
  1839. if (value) {
  1840. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  1841. }
  1842. this._connectedControl = value;
  1843. this._markAsDirty();
  1844. },
  1845. enumerable: true,
  1846. configurable: true
  1847. });
  1848. Object.defineProperty(Line.prototype, "x1", {
  1849. get: function () {
  1850. return this._x1.toString(this._host);
  1851. },
  1852. set: function (value) {
  1853. if (this._x1.toString(this._host) === value) {
  1854. return;
  1855. }
  1856. if (this._x1.fromString(value)) {
  1857. this._markAsDirty();
  1858. }
  1859. },
  1860. enumerable: true,
  1861. configurable: true
  1862. });
  1863. Object.defineProperty(Line.prototype, "y1", {
  1864. get: function () {
  1865. return this._y1.toString(this._host);
  1866. },
  1867. set: function (value) {
  1868. if (this._y1.toString(this._host) === value) {
  1869. return;
  1870. }
  1871. if (this._y1.fromString(value)) {
  1872. this._markAsDirty();
  1873. }
  1874. },
  1875. enumerable: true,
  1876. configurable: true
  1877. });
  1878. Object.defineProperty(Line.prototype, "x2", {
  1879. get: function () {
  1880. return this._x2.toString(this._host);
  1881. },
  1882. set: function (value) {
  1883. if (this._x2.toString(this._host) === value) {
  1884. return;
  1885. }
  1886. if (this._x2.fromString(value)) {
  1887. this._markAsDirty();
  1888. }
  1889. },
  1890. enumerable: true,
  1891. configurable: true
  1892. });
  1893. Object.defineProperty(Line.prototype, "y2", {
  1894. get: function () {
  1895. return this._y2.toString(this._host);
  1896. },
  1897. set: function (value) {
  1898. if (this._y2.toString(this._host) === value) {
  1899. return;
  1900. }
  1901. if (this._y2.fromString(value)) {
  1902. this._markAsDirty();
  1903. }
  1904. },
  1905. enumerable: true,
  1906. configurable: true
  1907. });
  1908. Object.defineProperty(Line.prototype, "lineWidth", {
  1909. get: function () {
  1910. return this._lineWidth;
  1911. },
  1912. set: function (value) {
  1913. if (this._lineWidth === value) {
  1914. return;
  1915. }
  1916. this._lineWidth = value;
  1917. this._markAsDirty();
  1918. },
  1919. enumerable: true,
  1920. configurable: true
  1921. });
  1922. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  1923. set: function (value) {
  1924. return;
  1925. },
  1926. enumerable: true,
  1927. configurable: true
  1928. });
  1929. Object.defineProperty(Line.prototype, "verticalAlignment", {
  1930. set: function (value) {
  1931. return;
  1932. },
  1933. enumerable: true,
  1934. configurable: true
  1935. });
  1936. Object.defineProperty(Line.prototype, "_effectiveX2", {
  1937. get: function () {
  1938. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  1939. },
  1940. enumerable: true,
  1941. configurable: true
  1942. });
  1943. Object.defineProperty(Line.prototype, "_effectiveY2", {
  1944. get: function () {
  1945. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  1946. },
  1947. enumerable: true,
  1948. configurable: true
  1949. });
  1950. Line.prototype._draw = function (parentMeasure, context) {
  1951. context.save();
  1952. this._applyStates(context);
  1953. if (this._processMeasures(parentMeasure, context)) {
  1954. context.strokeStyle = this.color;
  1955. context.lineWidth = this._lineWidth;
  1956. context.setLineDash(this._dash);
  1957. context.beginPath();
  1958. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  1959. context.lineTo(this._effectiveX2, this._effectiveY2);
  1960. context.stroke();
  1961. }
  1962. context.restore();
  1963. };
  1964. Line.prototype._measure = function () {
  1965. // Width / Height
  1966. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  1967. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  1968. };
  1969. Line.prototype._computeAlignment = function (parentMeasure, context) {
  1970. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  1971. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  1972. };
  1973. Line.prototype._moveToProjectedPosition = function (projectedPosition) {
  1974. this.x1 = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  1975. this.y1 = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  1976. this._x1.ignoreAdaptiveScaling = true;
  1977. this._y1.ignoreAdaptiveScaling = true;
  1978. };
  1979. return Line;
  1980. }(GUI.Control));
  1981. GUI.Line = Line;
  1982. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1983. })(BABYLON || (BABYLON = {}));
  1984. //# sourceMappingURL=line.js.map
  1985. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1986. var __extends = (this && this.__extends) || (function () {
  1987. var extendStatics = Object.setPrototypeOf ||
  1988. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1989. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1990. return function (d, b) {
  1991. extendStatics(d, b);
  1992. function __() { this.constructor = d; }
  1993. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1994. };
  1995. })();
  1996. var DOMImage = Image;
  1997. var BABYLON;
  1998. (function (BABYLON) {
  1999. var GUI;
  2000. (function (GUI) {
  2001. var Slider = (function (_super) {
  2002. __extends(Slider, _super);
  2003. function Slider(name) {
  2004. var _this = _super.call(this, name) || this;
  2005. _this.name = name;
  2006. _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2007. _this._minimum = 0;
  2008. _this._maximum = 100;
  2009. _this._value = 50;
  2010. _this._background = "black";
  2011. _this._borderColor = "white";
  2012. _this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2013. _this.onValueChangedObservable = new BABYLON.Observable();
  2014. // Events
  2015. _this._pointerIsDown = false;
  2016. _this.isPointerBlocker = true;
  2017. return _this;
  2018. }
  2019. Object.defineProperty(Slider.prototype, "borderColor", {
  2020. get: function () {
  2021. return this._borderColor;
  2022. },
  2023. set: function (value) {
  2024. if (this._borderColor === value) {
  2025. return;
  2026. }
  2027. this._borderColor = value;
  2028. this._markAsDirty();
  2029. },
  2030. enumerable: true,
  2031. configurable: true
  2032. });
  2033. Object.defineProperty(Slider.prototype, "background", {
  2034. get: function () {
  2035. return this._background;
  2036. },
  2037. set: function (value) {
  2038. if (this._background === value) {
  2039. return;
  2040. }
  2041. this._background = value;
  2042. this._markAsDirty();
  2043. },
  2044. enumerable: true,
  2045. configurable: true
  2046. });
  2047. Object.defineProperty(Slider.prototype, "barOffset", {
  2048. get: function () {
  2049. return this._barOffset.toString(this._host);
  2050. },
  2051. set: function (value) {
  2052. if (this._barOffset.toString(this._host) === value) {
  2053. return;
  2054. }
  2055. if (this._barOffset.fromString(value)) {
  2056. this._markAsDirty();
  2057. }
  2058. },
  2059. enumerable: true,
  2060. configurable: true
  2061. });
  2062. Object.defineProperty(Slider.prototype, "thumbWidth", {
  2063. get: function () {
  2064. return this._thumbWidth.toString(this._host);
  2065. },
  2066. set: function (value) {
  2067. if (this._thumbWidth.toString(this._host) === value) {
  2068. return;
  2069. }
  2070. if (this._thumbWidth.fromString(value)) {
  2071. this._markAsDirty();
  2072. }
  2073. },
  2074. enumerable: true,
  2075. configurable: true
  2076. });
  2077. Object.defineProperty(Slider.prototype, "minimum", {
  2078. get: function () {
  2079. return this._minimum;
  2080. },
  2081. set: function (value) {
  2082. if (this._minimum === value) {
  2083. return;
  2084. }
  2085. this._minimum = value;
  2086. this._markAsDirty();
  2087. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2088. },
  2089. enumerable: true,
  2090. configurable: true
  2091. });
  2092. Object.defineProperty(Slider.prototype, "maximum", {
  2093. get: function () {
  2094. return this._maximum;
  2095. },
  2096. set: function (value) {
  2097. if (this._maximum === value) {
  2098. return;
  2099. }
  2100. this._maximum = value;
  2101. this._markAsDirty();
  2102. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2103. },
  2104. enumerable: true,
  2105. configurable: true
  2106. });
  2107. Object.defineProperty(Slider.prototype, "value", {
  2108. get: function () {
  2109. return this._value;
  2110. },
  2111. set: function (value) {
  2112. value = Math.max(Math.min(value, this._maximum), this._minimum);
  2113. if (this._value === value) {
  2114. return;
  2115. }
  2116. this._value = value;
  2117. this._markAsDirty();
  2118. this.onValueChangedObservable.notifyObservers(this._value);
  2119. },
  2120. enumerable: true,
  2121. configurable: true
  2122. });
  2123. Slider.prototype._draw = function (parentMeasure, context) {
  2124. context.save();
  2125. this._applyStates(context);
  2126. if (this._processMeasures(parentMeasure, context)) {
  2127. // Main bar
  2128. var effectiveThumbWidth;
  2129. var effectiveBarOffset;
  2130. if (this._thumbWidth.isPixel) {
  2131. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.height);
  2132. }
  2133. else {
  2134. effectiveThumbWidth = this._currentMeasure.height * this._thumbWidth.getValue(this._host);
  2135. }
  2136. if (this._barOffset.isPixel) {
  2137. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  2138. }
  2139. else {
  2140. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  2141. }
  2142. var left = this._currentMeasure.left + effectiveThumbWidth / 2;
  2143. var width = this._currentMeasure.width - effectiveThumbWidth;
  2144. var thumbPosition = (this._value - this._minimum) / (this._maximum - this._minimum) * width;
  2145. // Bar
  2146. context.fillStyle = this._background;
  2147. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  2148. context.fillStyle = this.color;
  2149. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  2150. // Thumb
  2151. context.fillRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2152. context.strokeStyle = this._borderColor;
  2153. context.strokeRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  2154. }
  2155. context.restore();
  2156. };
  2157. Slider.prototype._updateValueFromPointer = function (x) {
  2158. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  2159. };
  2160. Slider.prototype._onPointerDown = function (coordinates) {
  2161. this._pointerIsDown = true;
  2162. this._updateValueFromPointer(coordinates.x);
  2163. this._host._capturingControl = this;
  2164. _super.prototype._onPointerDown.call(this, coordinates);
  2165. };
  2166. Slider.prototype._onPointerMove = function (coordinates) {
  2167. if (this._pointerIsDown) {
  2168. this._updateValueFromPointer(coordinates.x);
  2169. }
  2170. };
  2171. Slider.prototype._onPointerUp = function (coordinates) {
  2172. this._pointerIsDown = false;
  2173. this._host._capturingControl = null;
  2174. _super.prototype._onPointerUp.call(this, coordinates);
  2175. };
  2176. return Slider;
  2177. }(GUI.Control));
  2178. GUI.Slider = Slider;
  2179. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2180. })(BABYLON || (BABYLON = {}));
  2181. //# sourceMappingURL=slider.js.map
  2182. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2183. var __extends = (this && this.__extends) || (function () {
  2184. var extendStatics = Object.setPrototypeOf ||
  2185. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2186. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2187. return function (d, b) {
  2188. extendStatics(d, b);
  2189. function __() { this.constructor = d; }
  2190. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2191. };
  2192. })();
  2193. var DOMImage = Image;
  2194. var BABYLON;
  2195. (function (BABYLON) {
  2196. var GUI;
  2197. (function (GUI) {
  2198. var Checkbox = (function (_super) {
  2199. __extends(Checkbox, _super);
  2200. function Checkbox(name) {
  2201. var _this = _super.call(this, name) || this;
  2202. _this.name = name;
  2203. _this._isChecked = false;
  2204. _this._background = "black";
  2205. _this._checkSizeRatio = 0.8;
  2206. _this._thickness = 1;
  2207. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  2208. _this.isPointerBlocker = true;
  2209. return _this;
  2210. }
  2211. Object.defineProperty(Checkbox.prototype, "thickness", {
  2212. get: function () {
  2213. return this._thickness;
  2214. },
  2215. set: function (value) {
  2216. if (this._thickness === value) {
  2217. return;
  2218. }
  2219. this._thickness = value;
  2220. this._markAsDirty();
  2221. },
  2222. enumerable: true,
  2223. configurable: true
  2224. });
  2225. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  2226. get: function () {
  2227. return this._checkSizeRatio;
  2228. },
  2229. set: function (value) {
  2230. value = Math.max(Math.min(1, value), 0);
  2231. if (this._checkSizeRatio === value) {
  2232. return;
  2233. }
  2234. this._checkSizeRatio = value;
  2235. this._markAsDirty();
  2236. },
  2237. enumerable: true,
  2238. configurable: true
  2239. });
  2240. Object.defineProperty(Checkbox.prototype, "background", {
  2241. get: function () {
  2242. return this._background;
  2243. },
  2244. set: function (value) {
  2245. if (this._background === value) {
  2246. return;
  2247. }
  2248. this._background = value;
  2249. this._markAsDirty();
  2250. },
  2251. enumerable: true,
  2252. configurable: true
  2253. });
  2254. Object.defineProperty(Checkbox.prototype, "isChecked", {
  2255. get: function () {
  2256. return this._isChecked;
  2257. },
  2258. set: function (value) {
  2259. if (this._isChecked === value) {
  2260. return;
  2261. }
  2262. this._isChecked = value;
  2263. this._markAsDirty();
  2264. this.onIsCheckedChangedObservable.notifyObservers(value);
  2265. },
  2266. enumerable: true,
  2267. configurable: true
  2268. });
  2269. Checkbox.prototype._draw = function (parentMeasure, context) {
  2270. context.save();
  2271. this._applyStates(context);
  2272. if (this._processMeasures(parentMeasure, context)) {
  2273. var actualWidth = this._currentMeasure.width - this._thickness;
  2274. var actualHeight = this._currentMeasure.height - this._thickness;
  2275. context.fillStyle = this._background;
  2276. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2277. if (this._isChecked) {
  2278. context.fillStyle = this.color;
  2279. var offsetWidth = actualWidth * this._checkSizeRatio;
  2280. var offseHeight = actualHeight * this._checkSizeRatio;
  2281. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  2282. }
  2283. context.strokeStyle = this.color;
  2284. context.lineWidth = this._thickness;
  2285. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  2286. }
  2287. context.restore();
  2288. };
  2289. // Events
  2290. Checkbox.prototype._onPointerDown = function (coordinates) {
  2291. this.isChecked = !this.isChecked;
  2292. _super.prototype._onPointerDown.call(this, coordinates);
  2293. };
  2294. return Checkbox;
  2295. }(GUI.Control));
  2296. GUI.Checkbox = Checkbox;
  2297. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2298. })(BABYLON || (BABYLON = {}));
  2299. //# sourceMappingURL=checkbox.js.map
  2300. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2301. var __extends = (this && this.__extends) || (function () {
  2302. var extendStatics = Object.setPrototypeOf ||
  2303. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2304. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2305. return function (d, b) {
  2306. extendStatics(d, b);
  2307. function __() { this.constructor = d; }
  2308. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2309. };
  2310. })();
  2311. var BABYLON;
  2312. (function (BABYLON) {
  2313. var GUI;
  2314. (function (GUI) {
  2315. var TextBlock = (function (_super) {
  2316. __extends(TextBlock, _super);
  2317. function TextBlock(name, text) {
  2318. if (text === void 0) { text = ""; }
  2319. var _this = _super.call(this, name) || this;
  2320. _this.name = name;
  2321. _this._text = "";
  2322. _this._textWrapping = false;
  2323. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  2324. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  2325. _this.text = text;
  2326. return _this;
  2327. }
  2328. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  2329. get: function () {
  2330. return this._textWrapping;
  2331. },
  2332. set: function (value) {
  2333. if (this._textWrapping === value) {
  2334. return;
  2335. }
  2336. this._textWrapping = value;
  2337. this._markAsDirty();
  2338. },
  2339. enumerable: true,
  2340. configurable: true
  2341. });
  2342. Object.defineProperty(TextBlock.prototype, "text", {
  2343. get: function () {
  2344. return this._text;
  2345. },
  2346. set: function (value) {
  2347. if (this._text === value) {
  2348. return;
  2349. }
  2350. this._text = value;
  2351. this._markAsDirty();
  2352. },
  2353. enumerable: true,
  2354. configurable: true
  2355. });
  2356. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  2357. get: function () {
  2358. return this._textHorizontalAlignment;
  2359. },
  2360. set: function (value) {
  2361. if (this._textHorizontalAlignment === value) {
  2362. return;
  2363. }
  2364. this._textHorizontalAlignment = value;
  2365. this._markAsDirty();
  2366. },
  2367. enumerable: true,
  2368. configurable: true
  2369. });
  2370. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  2371. get: function () {
  2372. return this._textVerticalAlignment;
  2373. },
  2374. set: function (value) {
  2375. if (this._textVerticalAlignment === value) {
  2376. return;
  2377. }
  2378. this._textVerticalAlignment = value;
  2379. this._markAsDirty();
  2380. },
  2381. enumerable: true,
  2382. configurable: true
  2383. });
  2384. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  2385. var width = this._currentMeasure.width;
  2386. var x = 0;
  2387. switch (this._textHorizontalAlignment) {
  2388. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  2389. x = 0;
  2390. break;
  2391. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  2392. x = width - textWidth;
  2393. break;
  2394. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  2395. x = (width - textWidth) / 2;
  2396. break;
  2397. }
  2398. context.fillText(text, this._currentMeasure.left + x, y);
  2399. };
  2400. TextBlock.prototype._draw = function (parentMeasure, context) {
  2401. context.save();
  2402. this._applyStates(context);
  2403. if (this._processMeasures(parentMeasure, context)) {
  2404. // Render lines
  2405. this._renderLines(context);
  2406. }
  2407. context.restore();
  2408. };
  2409. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  2410. this._lines = [];
  2411. if (this._textWrapping) {
  2412. var words = this.text.split(' ');
  2413. var line = '';
  2414. var width = this._currentMeasure.width;
  2415. var lineWidth = 0;
  2416. for (var n = 0; n < words.length; n++) {
  2417. var testLine = line + words[n] + ' ';
  2418. var metrics = context.measureText(testLine);
  2419. var testWidth = metrics.width;
  2420. if (testWidth > width && n > 0) {
  2421. this._lines.push({ text: line, width: lineWidth });
  2422. line = words[n] + ' ';
  2423. lineWidth = context.measureText(line).width;
  2424. }
  2425. else {
  2426. lineWidth = testWidth;
  2427. line = testLine;
  2428. }
  2429. }
  2430. this._lines.push({ text: line, width: lineWidth });
  2431. }
  2432. else {
  2433. this._lines.push({ text: this.text, width: context.measureText(this.text).width });
  2434. }
  2435. };
  2436. TextBlock.prototype._renderLines = function (context) {
  2437. var width = this._currentMeasure.width;
  2438. var height = this._currentMeasure.height;
  2439. if (!this._fontOffset) {
  2440. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  2441. }
  2442. var rootY = 0;
  2443. switch (this._textVerticalAlignment) {
  2444. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  2445. rootY = this._fontOffset.ascent;
  2446. break;
  2447. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  2448. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  2449. break;
  2450. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  2451. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  2452. break;
  2453. }
  2454. rootY += this._currentMeasure.top;
  2455. for (var _i = 0, _a = this._lines; _i < _a.length; _i++) {
  2456. var line = _a[_i];
  2457. this._drawText(line.text, line.width, rootY, context);
  2458. rootY += this._fontOffset.height;
  2459. }
  2460. };
  2461. return TextBlock;
  2462. }(GUI.Control));
  2463. GUI.TextBlock = TextBlock;
  2464. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2465. })(BABYLON || (BABYLON = {}));
  2466. //# sourceMappingURL=textBlock.js.map
  2467. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2468. var __extends = (this && this.__extends) || (function () {
  2469. var extendStatics = Object.setPrototypeOf ||
  2470. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2471. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2472. return function (d, b) {
  2473. extendStatics(d, b);
  2474. function __() { this.constructor = d; }
  2475. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2476. };
  2477. })();
  2478. var DOMImage = Image;
  2479. var BABYLON;
  2480. (function (BABYLON) {
  2481. var GUI;
  2482. (function (GUI) {
  2483. var Image = (function (_super) {
  2484. __extends(Image, _super);
  2485. function Image(name, url) {
  2486. var _this = _super.call(this, name) || this;
  2487. _this.name = name;
  2488. _this._loaded = false;
  2489. _this._stretch = Image.STRETCH_FILL;
  2490. _this._autoScale = false;
  2491. _this.source = url;
  2492. return _this;
  2493. }
  2494. Object.defineProperty(Image.prototype, "autoScale", {
  2495. get: function () {
  2496. return this._autoScale;
  2497. },
  2498. set: function (value) {
  2499. if (this._autoScale === value) {
  2500. return;
  2501. }
  2502. this._autoScale = value;
  2503. if (value && this._loaded) {
  2504. this.synchronizeSizeWithContent();
  2505. }
  2506. },
  2507. enumerable: true,
  2508. configurable: true
  2509. });
  2510. Object.defineProperty(Image.prototype, "stretch", {
  2511. get: function () {
  2512. return this._stretch;
  2513. },
  2514. set: function (value) {
  2515. if (this._stretch === value) {
  2516. return;
  2517. }
  2518. this._stretch = value;
  2519. this._markAsDirty();
  2520. },
  2521. enumerable: true,
  2522. configurable: true
  2523. });
  2524. Object.defineProperty(Image.prototype, "domImage", {
  2525. get: function () {
  2526. return this._domImage;
  2527. },
  2528. set: function (value) {
  2529. var _this = this;
  2530. this._domImage = value;
  2531. this._loaded = false;
  2532. if (this._domImage.width) {
  2533. this._onImageLoaded();
  2534. }
  2535. else {
  2536. this._domImage.onload = function () {
  2537. _this._onImageLoaded();
  2538. };
  2539. }
  2540. },
  2541. enumerable: true,
  2542. configurable: true
  2543. });
  2544. Image.prototype._onImageLoaded = function () {
  2545. this._imageWidth = this._domImage.width;
  2546. this._imageHeight = this._domImage.height;
  2547. this._loaded = true;
  2548. if (this._autoScale) {
  2549. this.synchronizeSizeWithContent();
  2550. }
  2551. this._markAsDirty();
  2552. };
  2553. Object.defineProperty(Image.prototype, "source", {
  2554. set: function (value) {
  2555. var _this = this;
  2556. if (this._source === value) {
  2557. return;
  2558. }
  2559. this._loaded = false;
  2560. this._source = value;
  2561. this._domImage = new DOMImage();
  2562. this._domImage.onload = function () {
  2563. _this._onImageLoaded();
  2564. };
  2565. this._domImage.src = value;
  2566. },
  2567. enumerable: true,
  2568. configurable: true
  2569. });
  2570. Image.prototype.synchronizeSizeWithContent = function () {
  2571. if (!this._loaded) {
  2572. return;
  2573. }
  2574. this.width = this._domImage.width + "px";
  2575. this.height = this._domImage.height + "px";
  2576. };
  2577. Image.prototype._draw = function (parentMeasure, context) {
  2578. context.save();
  2579. this._applyStates(context);
  2580. if (this._processMeasures(parentMeasure, context)) {
  2581. if (this._loaded) {
  2582. switch (this._stretch) {
  2583. case Image.STRETCH_NONE:
  2584. context.drawImage(this._domImage, this._currentMeasure.left, this._currentMeasure.top);
  2585. break;
  2586. case Image.STRETCH_FILL:
  2587. context.drawImage(this._domImage, 0, 0, this._imageWidth, this._imageHeight, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2588. break;
  2589. case Image.STRETCH_UNIFORM:
  2590. var hRatio = this._currentMeasure.width / this._imageWidth;
  2591. var vRatio = this._currentMeasure.height / this._imageHeight;
  2592. var ratio = Math.min(hRatio, vRatio);
  2593. var centerX = (this._currentMeasure.width - this._imageWidth * ratio) / 2;
  2594. var centerY = (this._currentMeasure.height - this._imageHeight * ratio) / 2;
  2595. context.drawImage(this._domImage, 0, 0, this._imageWidth, this._imageHeight, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, this._imageWidth * ratio, this._imageHeight * ratio);
  2596. break;
  2597. case Image.STRETCH_EXTEND:
  2598. context.drawImage(this._domImage, this._currentMeasure.left, this._currentMeasure.top);
  2599. if (this._autoScale) {
  2600. this.synchronizeSizeWithContent();
  2601. }
  2602. this._root.width = this.width;
  2603. this._root.height = this.height;
  2604. break;
  2605. }
  2606. }
  2607. }
  2608. context.restore();
  2609. };
  2610. Object.defineProperty(Image, "STRETCH_NONE", {
  2611. get: function () {
  2612. return Image._STRETCH_NONE;
  2613. },
  2614. enumerable: true,
  2615. configurable: true
  2616. });
  2617. Object.defineProperty(Image, "STRETCH_FILL", {
  2618. get: function () {
  2619. return Image._STRETCH_FILL;
  2620. },
  2621. enumerable: true,
  2622. configurable: true
  2623. });
  2624. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  2625. get: function () {
  2626. return Image._STRETCH_UNIFORM;
  2627. },
  2628. enumerable: true,
  2629. configurable: true
  2630. });
  2631. Object.defineProperty(Image, "STRETCH_EXTEND", {
  2632. get: function () {
  2633. return Image._STRETCH_EXTEND;
  2634. },
  2635. enumerable: true,
  2636. configurable: true
  2637. });
  2638. return Image;
  2639. }(GUI.Control));
  2640. // Static
  2641. Image._STRETCH_NONE = 0;
  2642. Image._STRETCH_FILL = 1;
  2643. Image._STRETCH_UNIFORM = 2;
  2644. Image._STRETCH_EXTEND = 3;
  2645. GUI.Image = Image;
  2646. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2647. })(BABYLON || (BABYLON = {}));
  2648. //# sourceMappingURL=image.js.map
  2649. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2650. var __extends = (this && this.__extends) || (function () {
  2651. var extendStatics = Object.setPrototypeOf ||
  2652. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2653. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2654. return function (d, b) {
  2655. extendStatics(d, b);
  2656. function __() { this.constructor = d; }
  2657. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2658. };
  2659. })();
  2660. var BABYLON;
  2661. (function (BABYLON) {
  2662. var GUI;
  2663. (function (GUI) {
  2664. var Button = (function (_super) {
  2665. __extends(Button, _super);
  2666. function Button(name) {
  2667. var _this = _super.call(this, name) || this;
  2668. _this.name = name;
  2669. _this.thickness = 1;
  2670. _this.isPointerBlocker = true;
  2671. _this.pointerEnterAnimation = function () {
  2672. _this.alpha -= 0.1;
  2673. };
  2674. _this.pointerOutAnimation = function () {
  2675. _this.alpha += 0.1;
  2676. };
  2677. _this.pointerDownAnimation = function () {
  2678. _this.scaleX -= 0.05;
  2679. _this.scaleY -= 0.05;
  2680. };
  2681. _this.pointerUpAnimation = function () {
  2682. _this.scaleX += 0.05;
  2683. _this.scaleY += 0.05;
  2684. };
  2685. return _this;
  2686. }
  2687. // While being a container, the button behaves like a control.
  2688. Button.prototype._processPicking = function (x, y, type) {
  2689. if (!this.contains(x, y)) {
  2690. return false;
  2691. }
  2692. this._processObservables(type, x, y);
  2693. return true;
  2694. };
  2695. Button.prototype._onPointerEnter = function () {
  2696. if (this.pointerEnterAnimation) {
  2697. this.pointerEnterAnimation();
  2698. }
  2699. _super.prototype._onPointerEnter.call(this);
  2700. };
  2701. Button.prototype._onPointerOut = function () {
  2702. if (this.pointerOutAnimation) {
  2703. this.pointerOutAnimation();
  2704. }
  2705. _super.prototype._onPointerOut.call(this);
  2706. };
  2707. Button.prototype._onPointerDown = function (coordinates) {
  2708. if (this.pointerDownAnimation) {
  2709. this.pointerDownAnimation();
  2710. }
  2711. _super.prototype._onPointerDown.call(this, coordinates);
  2712. };
  2713. Button.prototype._onPointerUp = function (coordinates) {
  2714. if (this.pointerUpAnimation) {
  2715. this.pointerUpAnimation();
  2716. }
  2717. _super.prototype._onPointerUp.call(this, coordinates);
  2718. };
  2719. // Statics
  2720. Button.CreateImageButton = function (name, text, imageUrl) {
  2721. var result = new Button(name);
  2722. // Adding text
  2723. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  2724. textBlock.textWrapping = true;
  2725. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  2726. textBlock.marginLeft = "20%";
  2727. result.addControl(textBlock);
  2728. // Adding image
  2729. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  2730. iconImage.width = "20%";
  2731. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  2732. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2733. result.addControl(iconImage);
  2734. return result;
  2735. };
  2736. Button.CreateImageOnlyButton = function (name, imageUrl) {
  2737. var result = new Button(name);
  2738. // Adding image
  2739. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  2740. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  2741. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2742. result.addControl(iconImage);
  2743. return result;
  2744. };
  2745. Button.CreateSimpleButton = function (name, text) {
  2746. var result = new Button(name);
  2747. // Adding text
  2748. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  2749. textBlock.textWrapping = true;
  2750. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  2751. result.addControl(textBlock);
  2752. return result;
  2753. };
  2754. return Button;
  2755. }(GUI.Rectangle));
  2756. GUI.Button = Button;
  2757. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2758. })(BABYLON || (BABYLON = {}));
  2759. //# sourceMappingURL=button.js.map