babylon.gui.js 154 KB

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