babylon.gui.js 148 KB

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