babylon.gui.js 128 KB

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