babylon.gui.js 176 KB

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