babylon.gui.js 162 KB

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