babylon.gui.js 121 KB

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