babylon.gui.js 155 KB

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