babylon.gui.js 163 KB

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