babylon.gui.js 166 KB

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