babylon.gui.js 144 KB

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