babylon.gui.js 121 KB

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