babylon.gui.js 228 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152
  1. (function universalModuleDefinition(root, factory) {
  2. var amdDependencies = [];
  3. var BABYLON = root.BABYLON || this.BABYLON;
  4. if(typeof exports === 'object' && typeof module === 'object') {
  5. BABYLON = BABYLON || require("babylonjs");
  6. module.exports = factory(BABYLON);
  7. } else if(typeof define === 'function' && define.amd) {
  8. amdDependencies.push("babylonjs");
  9. define("babylonjs-gui", amdDependencies, factory);
  10. } else if(typeof exports === 'object') {
  11. BABYLON = BABYLON || require("babylonjs");
  12. exports["babylonjs-gui"] = factory(BABYLON);
  13. } else {
  14. root["BABYLON"]["GUI"] = factory(BABYLON);
  15. }
  16. })(this, function(BABYLON) {
  17. BABYLON = BABYLON || this.BABYLON;
  18. var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};
  19. var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
  20. "use strict";
  21. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  22. var BABYLON;
  23. (function (BABYLON) {
  24. var GUI;
  25. (function (GUI) {
  26. var AdvancedDynamicTexture = /** @class */ (function (_super) {
  27. __extends(AdvancedDynamicTexture, _super);
  28. function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode) {
  29. if (width === void 0) { width = 0; }
  30. if (height === void 0) { height = 0; }
  31. if (generateMipMaps === void 0) { generateMipMaps = false; }
  32. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE; }
  33. var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, BABYLON.Engine.TEXTUREFORMAT_RGBA) || this;
  34. _this._isDirty = false;
  35. _this._rootContainer = new GUI.Container("root");
  36. _this._lastControlOver = {};
  37. _this._lastControlDown = {};
  38. _this._capturingControl = {};
  39. _this._linkedControls = new Array();
  40. _this._isFullscreen = false;
  41. _this._fullscreenViewport = new BABYLON.Viewport(0, 0, 1, 1);
  42. _this._idealWidth = 0;
  43. _this._idealHeight = 0;
  44. _this._useSmallestIdeal = false;
  45. _this._renderAtIdealSize = false;
  46. _this._blockNextFocusCheck = false;
  47. _this._renderScale = 1;
  48. scene = _this.getScene();
  49. if (!scene || !_this._texture) {
  50. return _this;
  51. }
  52. _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
  53. _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
  54. if (!_this._focusedControl) {
  55. return;
  56. }
  57. if (info.type === BABYLON.KeyboardEventTypes.KEYDOWN) {
  58. _this._focusedControl.processKeyboard(info.event);
  59. }
  60. info.skipOnPointerObservable = true;
  61. });
  62. _this._rootContainer._link(null, _this);
  63. _this.hasAlpha = true;
  64. if (!width || !height) {
  65. _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
  66. _this._onResize();
  67. }
  68. _this._texture.isReady = true;
  69. return _this;
  70. }
  71. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
  72. get: function () {
  73. return this._renderScale;
  74. },
  75. set: function (value) {
  76. if (value === this._renderScale) {
  77. return;
  78. }
  79. this._renderScale = value;
  80. this._onResize();
  81. },
  82. enumerable: true,
  83. configurable: true
  84. });
  85. Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
  86. get: function () {
  87. return this._background;
  88. },
  89. set: function (value) {
  90. if (this._background === value) {
  91. return;
  92. }
  93. this._background = value;
  94. this.markAsDirty();
  95. },
  96. enumerable: true,
  97. configurable: true
  98. });
  99. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
  100. get: function () {
  101. return this._idealWidth;
  102. },
  103. set: function (value) {
  104. if (this._idealWidth === value) {
  105. return;
  106. }
  107. this._idealWidth = value;
  108. this.markAsDirty();
  109. this._rootContainer._markAllAsDirty();
  110. },
  111. enumerable: true,
  112. configurable: true
  113. });
  114. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
  115. get: function () {
  116. return this._idealHeight;
  117. },
  118. set: function (value) {
  119. if (this._idealHeight === value) {
  120. return;
  121. }
  122. this._idealHeight = value;
  123. this.markAsDirty();
  124. this._rootContainer._markAllAsDirty();
  125. },
  126. enumerable: true,
  127. configurable: true
  128. });
  129. Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
  130. get: function () {
  131. return this._useSmallestIdeal;
  132. },
  133. set: function (value) {
  134. if (this._useSmallestIdeal === value) {
  135. return;
  136. }
  137. this._useSmallestIdeal = value;
  138. this.markAsDirty();
  139. this._rootContainer._markAllAsDirty();
  140. },
  141. enumerable: true,
  142. configurable: true
  143. });
  144. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
  145. get: function () {
  146. return this._renderAtIdealSize;
  147. },
  148. set: function (value) {
  149. if (this._renderAtIdealSize === value) {
  150. return;
  151. }
  152. this._renderAtIdealSize = value;
  153. this._onResize();
  154. },
  155. enumerable: true,
  156. configurable: true
  157. });
  158. Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
  159. get: function () {
  160. return this._layerToDispose;
  161. },
  162. enumerable: true,
  163. configurable: true
  164. });
  165. Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
  166. get: function () {
  167. return this._rootContainer;
  168. },
  169. enumerable: true,
  170. configurable: true
  171. });
  172. Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
  173. get: function () {
  174. return this._focusedControl;
  175. },
  176. set: function (control) {
  177. if (this._focusedControl == control) {
  178. return;
  179. }
  180. if (this._focusedControl) {
  181. this._focusedControl.onBlur();
  182. }
  183. if (control) {
  184. control.onFocus();
  185. }
  186. this._focusedControl = control;
  187. },
  188. enumerable: true,
  189. configurable: true
  190. });
  191. Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
  192. get: function () {
  193. if (!this.layer) {
  194. return true;
  195. }
  196. return (!this.layer.isBackground);
  197. },
  198. set: function (value) {
  199. if (!this.layer) {
  200. return;
  201. }
  202. if (this.layer.isBackground === !value) {
  203. return;
  204. }
  205. this.layer.isBackground = !value;
  206. },
  207. enumerable: true,
  208. configurable: true
  209. });
  210. AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
  211. if (!container) {
  212. container = this._rootContainer;
  213. }
  214. for (var _i = 0, _a = container.children; _i < _a.length; _i++) {
  215. var child = _a[_i];
  216. if (child.children) {
  217. this.executeOnAllControls(func, child);
  218. continue;
  219. }
  220. func(child);
  221. }
  222. };
  223. AdvancedDynamicTexture.prototype.markAsDirty = function () {
  224. this._isDirty = true;
  225. this.executeOnAllControls(function (control) {
  226. if (control._isFontSizeInPercentage) {
  227. control._resetFontCache();
  228. }
  229. });
  230. };
  231. AdvancedDynamicTexture.prototype.addControl = function (control) {
  232. this._rootContainer.addControl(control);
  233. return this;
  234. };
  235. AdvancedDynamicTexture.prototype.removeControl = function (control) {
  236. this._rootContainer.removeControl(control);
  237. return this;
  238. };
  239. AdvancedDynamicTexture.prototype.dispose = function () {
  240. var scene = this.getScene();
  241. if (!scene) {
  242. return;
  243. }
  244. scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
  245. if (this._resizeObserver) {
  246. scene.getEngine().onResizeObservable.remove(this._resizeObserver);
  247. }
  248. if (this._pointerMoveObserver) {
  249. scene.onPrePointerObservable.remove(this._pointerMoveObserver);
  250. }
  251. if (this._pointerObserver) {
  252. scene.onPointerObservable.remove(this._pointerObserver);
  253. }
  254. if (this._preKeyboardObserver) {
  255. scene.onPreKeyboardObservable.remove(this._preKeyboardObserver);
  256. }
  257. if (this._canvasPointerOutObserver) {
  258. scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
  259. }
  260. if (this._layerToDispose) {
  261. this._layerToDispose.texture = null;
  262. this._layerToDispose.dispose();
  263. this._layerToDispose = null;
  264. }
  265. this._rootContainer.dispose();
  266. _super.prototype.dispose.call(this);
  267. };
  268. AdvancedDynamicTexture.prototype._onResize = function () {
  269. var scene = this.getScene();
  270. if (!scene) {
  271. return;
  272. }
  273. // Check size
  274. var engine = scene.getEngine();
  275. var textureSize = this.getSize();
  276. var renderWidth = engine.getRenderWidth() * this._renderScale;
  277. var renderHeight = engine.getRenderHeight() * this._renderScale;
  278. if (this._renderAtIdealSize) {
  279. if (this._idealWidth) {
  280. renderHeight = (renderHeight * this._idealWidth) / renderWidth;
  281. renderWidth = this._idealWidth;
  282. }
  283. else if (this._idealHeight) {
  284. renderWidth = (renderWidth * this._idealHeight) / renderHeight;
  285. renderHeight = this._idealHeight;
  286. }
  287. }
  288. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  289. this.scaleTo(renderWidth, renderHeight);
  290. this.markAsDirty();
  291. if (this._idealWidth || this._idealHeight) {
  292. this._rootContainer._markAllAsDirty();
  293. }
  294. }
  295. };
  296. AdvancedDynamicTexture.prototype._getGlobalViewport = function (scene) {
  297. var engine = scene.getEngine();
  298. return this._fullscreenViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  299. };
  300. AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
  301. if (this._layerToDispose) {
  302. if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
  303. return;
  304. }
  305. }
  306. if (this._isFullscreen && this._linkedControls.length) {
  307. var scene = this.getScene();
  308. if (!scene) {
  309. return;
  310. }
  311. var globalViewport = this._getGlobalViewport(scene);
  312. for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
  313. var control = _a[_i];
  314. if (!control.isVisible) {
  315. continue;
  316. }
  317. var mesh = control._linkedMesh;
  318. if (!mesh || mesh.isDisposed()) {
  319. BABYLON.Tools.SetImmediate(function () {
  320. control.linkWithMesh(null);
  321. });
  322. continue;
  323. }
  324. var position = mesh.getBoundingInfo().boundingSphere.center;
  325. var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
  326. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  327. control.notRenderable = true;
  328. continue;
  329. }
  330. control.notRenderable = false;
  331. // Account for RenderScale.
  332. projectedPosition.scaleInPlace(this.renderScale);
  333. control._moveToProjectedPosition(projectedPosition);
  334. }
  335. }
  336. if (!this._isDirty && !this._rootContainer.isDirty) {
  337. return;
  338. }
  339. this._isDirty = false;
  340. this._render();
  341. this.update();
  342. };
  343. AdvancedDynamicTexture.prototype._render = function () {
  344. var textureSize = this.getSize();
  345. var renderWidth = textureSize.width;
  346. var renderHeight = textureSize.height;
  347. // Clear
  348. var context = this.getContext();
  349. context.clearRect(0, 0, renderWidth, renderHeight);
  350. if (this._background) {
  351. context.save();
  352. context.fillStyle = this._background;
  353. context.fillRect(0, 0, renderWidth, renderHeight);
  354. context.restore();
  355. }
  356. // Render
  357. context.font = "18px Arial";
  358. context.strokeStyle = "white";
  359. var measure = new GUI.Measure(0, 0, renderWidth, renderHeight);
  360. this._rootContainer._draw(measure, context);
  361. };
  362. AdvancedDynamicTexture.prototype._doPicking = function (x, y, type, pointerId, buttonIndex) {
  363. var scene = this.getScene();
  364. if (!scene) {
  365. return;
  366. }
  367. var engine = scene.getEngine();
  368. var textureSize = this.getSize();
  369. if (this._isFullscreen) {
  370. x = x * (textureSize.width / engine.getRenderWidth());
  371. y = y * (textureSize.height / engine.getRenderHeight());
  372. }
  373. if (this._capturingControl[pointerId]) {
  374. this._capturingControl[pointerId]._processObservables(type, x, y, pointerId, buttonIndex);
  375. return;
  376. }
  377. if (!this._rootContainer._processPicking(x, y, type, pointerId, buttonIndex)) {
  378. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  379. if (this._lastControlOver[pointerId]) {
  380. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  381. }
  382. delete this._lastControlOver[pointerId];
  383. }
  384. }
  385. this._manageFocus();
  386. };
  387. AdvancedDynamicTexture.prototype._cleanControlAfterRemovalFromList = function (list, control) {
  388. for (var pointerId in list) {
  389. if (!list.hasOwnProperty(pointerId)) {
  390. continue;
  391. }
  392. var lastControlOver = list[pointerId];
  393. if (lastControlOver === control) {
  394. delete list[pointerId];
  395. }
  396. }
  397. };
  398. AdvancedDynamicTexture.prototype._cleanControlAfterRemoval = function (control) {
  399. this._cleanControlAfterRemovalFromList(this._lastControlDown, control);
  400. this._cleanControlAfterRemovalFromList(this._lastControlOver, control);
  401. };
  402. AdvancedDynamicTexture.prototype.attach = function () {
  403. var _this = this;
  404. var scene = this.getScene();
  405. if (!scene) {
  406. return;
  407. }
  408. this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
  409. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  410. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  411. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  412. return;
  413. }
  414. if (!scene) {
  415. return;
  416. }
  417. var camera = scene.cameraToUseForPointers || scene.activeCamera;
  418. if (!camera) {
  419. return;
  420. }
  421. var engine = scene.getEngine();
  422. var viewport = camera.viewport;
  423. var x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
  424. var y = (scene.pointerY / engine.getHardwareScalingLevel() - viewport.y * engine.getRenderHeight()) / viewport.height;
  425. _this._shouldBlockPointer = false;
  426. _this._doPicking(x, y, pi.type, pi.event.pointerId || 0, pi.event.button);
  427. pi.skipOnPointerObservable = _this._shouldBlockPointer;
  428. });
  429. this._attachToOnPointerOut(scene);
  430. };
  431. AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
  432. var _this = this;
  433. if (supportPointerMove === void 0) { supportPointerMove = true; }
  434. var scene = this.getScene();
  435. if (!scene) {
  436. return;
  437. }
  438. this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
  439. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  440. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  441. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  442. return;
  443. }
  444. var pointerId = pi.event.pointerId || 0;
  445. if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
  446. var uv = pi.pickInfo.getTextureCoordinates();
  447. if (uv) {
  448. var size = _this.getSize();
  449. _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pointerId, pi.event.button);
  450. }
  451. }
  452. else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
  453. if (_this._lastControlDown[pointerId]) {
  454. _this._lastControlDown[pointerId].forcePointerUp(pointerId);
  455. }
  456. delete _this._lastControlDown[pointerId];
  457. _this.focusedControl = null;
  458. }
  459. else if (pi.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  460. if (_this._lastControlOver[pointerId]) {
  461. _this._lastControlOver[pointerId]._onPointerOut(_this._lastControlOver[pointerId]);
  462. }
  463. delete _this._lastControlOver[pointerId];
  464. }
  465. });
  466. mesh.enablePointerMoveEvents = supportPointerMove;
  467. this._attachToOnPointerOut(scene);
  468. };
  469. AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
  470. this.focusedControl = control;
  471. this._lastPickedControl = control;
  472. this._blockNextFocusCheck = true;
  473. };
  474. AdvancedDynamicTexture.prototype._manageFocus = function () {
  475. if (this._blockNextFocusCheck) {
  476. this._blockNextFocusCheck = false;
  477. this._lastPickedControl = this._focusedControl;
  478. return;
  479. }
  480. // Focus management
  481. if (this._focusedControl) {
  482. if (this._focusedControl !== this._lastPickedControl) {
  483. if (this._lastPickedControl.isFocusInvisible) {
  484. return;
  485. }
  486. this.focusedControl = null;
  487. }
  488. }
  489. };
  490. AdvancedDynamicTexture.prototype._attachToOnPointerOut = function (scene) {
  491. var _this = this;
  492. this._canvasPointerOutObserver = scene.getEngine().onCanvasPointerOutObservable.add(function (pointerEvent) {
  493. if (_this._lastControlOver[pointerEvent.pointerId]) {
  494. _this._lastControlOver[pointerEvent.pointerId]._onPointerOut(_this._lastControlOver[pointerEvent.pointerId]);
  495. }
  496. delete _this._lastControlOver[pointerEvent.pointerId];
  497. if (_this._lastControlDown[pointerEvent.pointerId]) {
  498. _this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  499. }
  500. delete _this._lastControlDown[pointerEvent.pointerId];
  501. });
  502. };
  503. // Statics
  504. AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height, supportPointerMove) {
  505. if (width === void 0) { width = 1024; }
  506. if (height === void 0) { height = 1024; }
  507. if (supportPointerMove === void 0) { supportPointerMove = true; }
  508. var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  509. var material = new BABYLON.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
  510. material.backFaceCulling = false;
  511. material.diffuseColor = BABYLON.Color3.Black();
  512. material.specularColor = BABYLON.Color3.Black();
  513. material.emissiveTexture = result;
  514. material.opacityTexture = result;
  515. mesh.material = material;
  516. result.attachToMesh(mesh, supportPointerMove);
  517. return result;
  518. };
  519. /**
  520. * FullScreenUI is created in a layer. This allows it to be treated like any other layer.
  521. * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
  522. * When the GUI is not Created as FullscreenUI it does not respect the layerMask.
  523. * layerMask is set through advancedTexture.layer.layerMask
  524. * @param name name for the Texture
  525. * @param foreground render in foreground (default is true)
  526. * @param scene scene to be rendered in
  527. * @param sampling method for scaling to fit screen
  528. * @returns AdvancedDynamicTexture
  529. */
  530. AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling) {
  531. if (foreground === void 0) { foreground = true; }
  532. if (scene === void 0) { scene = null; }
  533. if (sampling === void 0) { sampling = BABYLON.Texture.BILINEAR_SAMPLINGMODE; }
  534. var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, sampling);
  535. // Display
  536. var layer = new BABYLON.Layer(name + "_layer", null, scene, !foreground);
  537. layer.texture = result;
  538. result._layerToDispose = layer;
  539. result._isFullscreen = true;
  540. // Attach
  541. result.attach();
  542. return result;
  543. };
  544. return AdvancedDynamicTexture;
  545. }(BABYLON.DynamicTexture));
  546. GUI.AdvancedDynamicTexture = AdvancedDynamicTexture;
  547. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  548. })(BABYLON || (BABYLON = {}));
  549. //# sourceMappingURL=advancedDynamicTexture.js.map
  550. "use strict";
  551. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  552. var BABYLON;
  553. (function (BABYLON) {
  554. var GUI;
  555. (function (GUI) {
  556. var Measure = /** @class */ (function () {
  557. function Measure(left, top, width, height) {
  558. this.left = left;
  559. this.top = top;
  560. this.width = width;
  561. this.height = height;
  562. }
  563. Measure.prototype.copyFrom = function (other) {
  564. this.left = other.left;
  565. this.top = other.top;
  566. this.width = other.width;
  567. this.height = other.height;
  568. };
  569. Measure.prototype.isEqualsTo = function (other) {
  570. if (this.left !== other.left) {
  571. return false;
  572. }
  573. if (this.top !== other.top) {
  574. return false;
  575. }
  576. if (this.width !== other.width) {
  577. return false;
  578. }
  579. if (this.height !== other.height) {
  580. return false;
  581. }
  582. return true;
  583. };
  584. Measure.Empty = function () {
  585. return new Measure(0, 0, 0, 0);
  586. };
  587. return Measure;
  588. }());
  589. GUI.Measure = Measure;
  590. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  591. })(BABYLON || (BABYLON = {}));
  592. //# sourceMappingURL=measure.js.map
  593. "use strict";
  594. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  595. var BABYLON;
  596. (function (BABYLON) {
  597. var GUI;
  598. (function (GUI) {
  599. var Vector2WithInfo = /** @class */ (function (_super) {
  600. __extends(Vector2WithInfo, _super);
  601. function Vector2WithInfo(source, buttonIndex) {
  602. if (buttonIndex === void 0) { buttonIndex = 0; }
  603. var _this = _super.call(this, source.x, source.y) || this;
  604. _this.buttonIndex = buttonIndex;
  605. return _this;
  606. }
  607. return Vector2WithInfo;
  608. }(BABYLON.Vector2));
  609. GUI.Vector2WithInfo = Vector2WithInfo;
  610. var Matrix2D = /** @class */ (function () {
  611. function Matrix2D(m00, m01, m10, m11, m20, m21) {
  612. this.m = new Float32Array(6);
  613. this.fromValues(m00, m01, m10, m11, m20, m21);
  614. }
  615. Matrix2D.prototype.fromValues = function (m00, m01, m10, m11, m20, m21) {
  616. this.m[0] = m00;
  617. this.m[1] = m01;
  618. this.m[2] = m10;
  619. this.m[3] = m11;
  620. this.m[4] = m20;
  621. this.m[5] = m21;
  622. return this;
  623. };
  624. Matrix2D.prototype.determinant = function () {
  625. return this.m[0] * this.m[3] - this.m[1] * this.m[2];
  626. };
  627. Matrix2D.prototype.invertToRef = function (result) {
  628. var l0 = this.m[0];
  629. var l1 = this.m[1];
  630. var l2 = this.m[2];
  631. var l3 = this.m[3];
  632. var l4 = this.m[4];
  633. var l5 = this.m[5];
  634. var det = this.determinant();
  635. if (det < (BABYLON.Epsilon * BABYLON.Epsilon)) {
  636. result.m[0] = 0;
  637. result.m[1] = 0;
  638. result.m[2] = 0;
  639. result.m[3] = 0;
  640. result.m[4] = 0;
  641. result.m[5] = 0;
  642. return this;
  643. }
  644. var detDiv = 1 / det;
  645. var det4 = l2 * l5 - l3 * l4;
  646. var det5 = l1 * l4 - l0 * l5;
  647. result.m[0] = l3 * detDiv;
  648. result.m[1] = -l1 * detDiv;
  649. result.m[2] = -l2 * detDiv;
  650. result.m[3] = l0 * detDiv;
  651. result.m[4] = det4 * detDiv;
  652. result.m[5] = det5 * detDiv;
  653. return this;
  654. };
  655. Matrix2D.prototype.multiplyToRef = function (other, result) {
  656. var l0 = this.m[0];
  657. var l1 = this.m[1];
  658. var l2 = this.m[2];
  659. var l3 = this.m[3];
  660. var l4 = this.m[4];
  661. var l5 = this.m[5];
  662. var r0 = other.m[0];
  663. var r1 = other.m[1];
  664. var r2 = other.m[2];
  665. var r3 = other.m[3];
  666. var r4 = other.m[4];
  667. var r5 = other.m[5];
  668. result.m[0] = l0 * r0 + l1 * r2;
  669. result.m[1] = l0 * r1 + l1 * r3;
  670. result.m[2] = l2 * r0 + l3 * r2;
  671. result.m[3] = l2 * r1 + l3 * r3;
  672. result.m[4] = l4 * r0 + l5 * r2 + r4;
  673. result.m[5] = l4 * r1 + l5 * r3 + r5;
  674. return this;
  675. };
  676. Matrix2D.prototype.transformCoordinates = function (x, y, result) {
  677. result.x = x * this.m[0] + y * this.m[2] + this.m[4];
  678. result.y = x * this.m[1] + y * this.m[3] + this.m[5];
  679. return this;
  680. };
  681. // Statics
  682. Matrix2D.Identity = function () {
  683. return new Matrix2D(1, 0, 0, 1, 0, 0);
  684. };
  685. Matrix2D.TranslationToRef = function (x, y, result) {
  686. result.fromValues(1, 0, 0, 1, x, y);
  687. };
  688. Matrix2D.ScalingToRef = function (x, y, result) {
  689. result.fromValues(x, 0, 0, y, 0, 0);
  690. };
  691. Matrix2D.RotationToRef = function (angle, result) {
  692. var s = Math.sin(angle);
  693. var c = Math.cos(angle);
  694. result.fromValues(c, s, -s, c, 0, 0);
  695. };
  696. Matrix2D.ComposeToRef = function (tx, ty, angle, scaleX, scaleY, parentMatrix, result) {
  697. Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
  698. Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);
  699. Matrix2D.RotationToRef(angle, Matrix2D._TempRotationMatrix);
  700. Matrix2D.TranslationToRef(-tx, -ty, Matrix2D._TempPostTranslationMatrix);
  701. Matrix2D._TempPreTranslationMatrix.multiplyToRef(Matrix2D._TempScalingMatrix, Matrix2D._TempCompose0);
  702. Matrix2D._TempCompose0.multiplyToRef(Matrix2D._TempRotationMatrix, Matrix2D._TempCompose1);
  703. if (parentMatrix) {
  704. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, Matrix2D._TempCompose2);
  705. Matrix2D._TempCompose2.multiplyToRef(parentMatrix, result);
  706. }
  707. else {
  708. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, result);
  709. }
  710. };
  711. Matrix2D._TempPreTranslationMatrix = Matrix2D.Identity();
  712. Matrix2D._TempPostTranslationMatrix = Matrix2D.Identity();
  713. Matrix2D._TempRotationMatrix = Matrix2D.Identity();
  714. Matrix2D._TempScalingMatrix = Matrix2D.Identity();
  715. Matrix2D._TempCompose0 = Matrix2D.Identity();
  716. Matrix2D._TempCompose1 = Matrix2D.Identity();
  717. Matrix2D._TempCompose2 = Matrix2D.Identity();
  718. return Matrix2D;
  719. }());
  720. GUI.Matrix2D = Matrix2D;
  721. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  722. })(BABYLON || (BABYLON = {}));
  723. //# sourceMappingURL=math2D.js.map
  724. "use strict";
  725. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  726. var BABYLON;
  727. (function (BABYLON) {
  728. var GUI;
  729. (function (GUI) {
  730. var ValueAndUnit = /** @class */ (function () {
  731. function ValueAndUnit(value, unit, negativeValueAllowed) {
  732. if (unit === void 0) { unit = ValueAndUnit.UNITMODE_PIXEL; }
  733. if (negativeValueAllowed === void 0) { negativeValueAllowed = true; }
  734. this.unit = unit;
  735. this.negativeValueAllowed = negativeValueAllowed;
  736. this._value = 1;
  737. this.ignoreAdaptiveScaling = false;
  738. this._value = value;
  739. }
  740. Object.defineProperty(ValueAndUnit.prototype, "isPercentage", {
  741. get: function () {
  742. return this.unit === ValueAndUnit.UNITMODE_PERCENTAGE;
  743. },
  744. enumerable: true,
  745. configurable: true
  746. });
  747. Object.defineProperty(ValueAndUnit.prototype, "isPixel", {
  748. get: function () {
  749. return this.unit === ValueAndUnit.UNITMODE_PIXEL;
  750. },
  751. enumerable: true,
  752. configurable: true
  753. });
  754. Object.defineProperty(ValueAndUnit.prototype, "internalValue", {
  755. get: function () {
  756. return this._value;
  757. },
  758. enumerable: true,
  759. configurable: true
  760. });
  761. ValueAndUnit.prototype.getValueInPixel = function (host, refValue) {
  762. if (this.isPixel) {
  763. return this.getValue(host);
  764. }
  765. return this.getValue(host) * refValue;
  766. };
  767. ValueAndUnit.prototype.getValue = function (host) {
  768. if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
  769. var width = 0;
  770. var height = 0;
  771. if (host.idealWidth) {
  772. width = (this._value * host.getSize().width) / host.idealWidth;
  773. }
  774. if (host.idealHeight) {
  775. height = (this._value * host.getSize().height) / host.idealHeight;
  776. }
  777. if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) {
  778. return window.innerWidth < window.innerHeight ? width : height;
  779. }
  780. if (host.idealWidth) {
  781. return width;
  782. }
  783. if (host.idealHeight) {
  784. return height;
  785. }
  786. }
  787. return this._value;
  788. };
  789. ValueAndUnit.prototype.toString = function (host) {
  790. switch (this.unit) {
  791. case ValueAndUnit.UNITMODE_PERCENTAGE:
  792. return (this.getValue(host) * 100) + "%";
  793. case ValueAndUnit.UNITMODE_PIXEL:
  794. return this.getValue(host) + "px";
  795. }
  796. return this.unit.toString();
  797. };
  798. ValueAndUnit.prototype.fromString = function (source) {
  799. var match = ValueAndUnit._Regex.exec(source.toString());
  800. if (!match || match.length === 0) {
  801. return false;
  802. }
  803. var sourceValue = parseFloat(match[1]);
  804. var sourceUnit = this.unit;
  805. if (!this.negativeValueAllowed) {
  806. if (sourceValue < 0) {
  807. sourceValue = 0;
  808. }
  809. }
  810. if (match.length === 4) {
  811. switch (match[3]) {
  812. case "px":
  813. sourceUnit = ValueAndUnit.UNITMODE_PIXEL;
  814. break;
  815. case "%":
  816. sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;
  817. sourceValue /= 100.0;
  818. break;
  819. }
  820. }
  821. if (sourceValue === this._value && sourceUnit === this.unit) {
  822. return false;
  823. }
  824. this._value = sourceValue;
  825. this.unit = sourceUnit;
  826. return true;
  827. };
  828. Object.defineProperty(ValueAndUnit, "UNITMODE_PERCENTAGE", {
  829. get: function () {
  830. return ValueAndUnit._UNITMODE_PERCENTAGE;
  831. },
  832. enumerable: true,
  833. configurable: true
  834. });
  835. Object.defineProperty(ValueAndUnit, "UNITMODE_PIXEL", {
  836. get: function () {
  837. return ValueAndUnit._UNITMODE_PIXEL;
  838. },
  839. enumerable: true,
  840. configurable: true
  841. });
  842. // Static
  843. ValueAndUnit._Regex = /(^-?\d*(\.\d+)?)(%|px)?/;
  844. ValueAndUnit._UNITMODE_PERCENTAGE = 0;
  845. ValueAndUnit._UNITMODE_PIXEL = 1;
  846. return ValueAndUnit;
  847. }());
  848. GUI.ValueAndUnit = ValueAndUnit;
  849. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  850. })(BABYLON || (BABYLON = {}));
  851. //# sourceMappingURL=valueAndUnit.js.map
  852. "use strict";
  853. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  854. var BABYLON;
  855. (function (BABYLON) {
  856. var GUI;
  857. (function (GUI) {
  858. var Control = /** @class */ (function () {
  859. // Functions
  860. function Control(name) {
  861. this.name = name;
  862. this._alpha = 1;
  863. this._alphaSet = false;
  864. this._zIndex = 0;
  865. this._currentMeasure = GUI.Measure.Empty();
  866. this._fontFamily = "Arial";
  867. this._fontStyle = "";
  868. this._fontSize = new GUI.ValueAndUnit(18, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  869. this._width = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  870. this._height = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  871. this._color = "";
  872. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  873. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  874. this._isDirty = true;
  875. this._tempParentMeasure = GUI.Measure.Empty();
  876. this._cachedParentMeasure = GUI.Measure.Empty();
  877. this._paddingLeft = new GUI.ValueAndUnit(0);
  878. this._paddingRight = new GUI.ValueAndUnit(0);
  879. this._paddingTop = new GUI.ValueAndUnit(0);
  880. this._paddingBottom = new GUI.ValueAndUnit(0);
  881. this._left = new GUI.ValueAndUnit(0);
  882. this._top = new GUI.ValueAndUnit(0);
  883. this._scaleX = 1.0;
  884. this._scaleY = 1.0;
  885. this._rotation = 0;
  886. this._transformCenterX = 0.5;
  887. this._transformCenterY = 0.5;
  888. this._transformMatrix = GUI.Matrix2D.Identity();
  889. this._invertTransformMatrix = GUI.Matrix2D.Identity();
  890. this._transformedPosition = BABYLON.Vector2.Zero();
  891. this._onlyMeasureMode = false;
  892. this._isMatrixDirty = true;
  893. this._isVisible = true;
  894. this._fontSet = false;
  895. this._dummyVector2 = BABYLON.Vector2.Zero();
  896. this._downCount = 0;
  897. this._enterCount = 0;
  898. this._doNotRender = false;
  899. this._downPointerIds = {};
  900. this.isHitTestVisible = true;
  901. this.isPointerBlocker = false;
  902. this.isFocusInvisible = false;
  903. this.shadowOffsetX = 0;
  904. this.shadowOffsetY = 0;
  905. this.shadowBlur = 0;
  906. this.shadowColor = '#000';
  907. this._linkOffsetX = new GUI.ValueAndUnit(0);
  908. this._linkOffsetY = new GUI.ValueAndUnit(0);
  909. /**
  910. * An event triggered when the pointer move over the control.
  911. */
  912. this.onPointerMoveObservable = new BABYLON.Observable();
  913. /**
  914. * An event triggered when the pointer move out of the control.
  915. */
  916. this.onPointerOutObservable = new BABYLON.Observable();
  917. /**
  918. * An event triggered when the pointer taps the control
  919. */
  920. this.onPointerDownObservable = new BABYLON.Observable();
  921. /**
  922. * An event triggered when pointer up
  923. */
  924. this.onPointerUpObservable = new BABYLON.Observable();
  925. /**
  926. * An event triggered when a control is clicked on
  927. */
  928. this.onPointerClickObservable = new BABYLON.Observable();
  929. /**
  930. * An event triggered when pointer enters the control
  931. */
  932. this.onPointerEnterObservable = new BABYLON.Observable();
  933. /**
  934. * An event triggered when the control is marked as dirty
  935. */
  936. this.onDirtyObservable = new BABYLON.Observable();
  937. /**
  938. * An event triggered after the control is drawn
  939. */
  940. this.onAfterDrawObservable = new BABYLON.Observable();
  941. }
  942. Object.defineProperty(Control.prototype, "typeName", {
  943. // Properties
  944. get: function () {
  945. return this._getTypeName();
  946. },
  947. enumerable: true,
  948. configurable: true
  949. });
  950. Object.defineProperty(Control.prototype, "alpha", {
  951. get: function () {
  952. return this._alpha;
  953. },
  954. set: function (value) {
  955. if (this._alpha === value) {
  956. return;
  957. }
  958. this._alphaSet = true;
  959. this._alpha = value;
  960. this._markAsDirty();
  961. },
  962. enumerable: true,
  963. configurable: true
  964. });
  965. Object.defineProperty(Control.prototype, "scaleX", {
  966. get: function () {
  967. return this._scaleX;
  968. },
  969. set: function (value) {
  970. if (this._scaleX === value) {
  971. return;
  972. }
  973. this._scaleX = value;
  974. this._markAsDirty();
  975. this._markMatrixAsDirty();
  976. },
  977. enumerable: true,
  978. configurable: true
  979. });
  980. Object.defineProperty(Control.prototype, "scaleY", {
  981. get: function () {
  982. return this._scaleY;
  983. },
  984. set: function (value) {
  985. if (this._scaleY === value) {
  986. return;
  987. }
  988. this._scaleY = value;
  989. this._markAsDirty();
  990. this._markMatrixAsDirty();
  991. },
  992. enumerable: true,
  993. configurable: true
  994. });
  995. Object.defineProperty(Control.prototype, "rotation", {
  996. get: function () {
  997. return this._rotation;
  998. },
  999. set: function (value) {
  1000. if (this._rotation === value) {
  1001. return;
  1002. }
  1003. this._rotation = value;
  1004. this._markAsDirty();
  1005. this._markMatrixAsDirty();
  1006. },
  1007. enumerable: true,
  1008. configurable: true
  1009. });
  1010. Object.defineProperty(Control.prototype, "transformCenterY", {
  1011. get: function () {
  1012. return this._transformCenterY;
  1013. },
  1014. set: function (value) {
  1015. if (this._transformCenterY === value) {
  1016. return;
  1017. }
  1018. this._transformCenterY = value;
  1019. this._markAsDirty();
  1020. this._markMatrixAsDirty();
  1021. },
  1022. enumerable: true,
  1023. configurable: true
  1024. });
  1025. Object.defineProperty(Control.prototype, "transformCenterX", {
  1026. get: function () {
  1027. return this._transformCenterX;
  1028. },
  1029. set: function (value) {
  1030. if (this._transformCenterX === value) {
  1031. return;
  1032. }
  1033. this._transformCenterX = value;
  1034. this._markAsDirty();
  1035. this._markMatrixAsDirty();
  1036. },
  1037. enumerable: true,
  1038. configurable: true
  1039. });
  1040. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  1041. get: function () {
  1042. return this._horizontalAlignment;
  1043. },
  1044. set: function (value) {
  1045. if (this._horizontalAlignment === value) {
  1046. return;
  1047. }
  1048. this._horizontalAlignment = value;
  1049. this._markAsDirty();
  1050. },
  1051. enumerable: true,
  1052. configurable: true
  1053. });
  1054. Object.defineProperty(Control.prototype, "verticalAlignment", {
  1055. get: function () {
  1056. return this._verticalAlignment;
  1057. },
  1058. set: function (value) {
  1059. if (this._verticalAlignment === value) {
  1060. return;
  1061. }
  1062. this._verticalAlignment = value;
  1063. this._markAsDirty();
  1064. },
  1065. enumerable: true,
  1066. configurable: true
  1067. });
  1068. Object.defineProperty(Control.prototype, "width", {
  1069. get: function () {
  1070. return this._width.toString(this._host);
  1071. },
  1072. set: function (value) {
  1073. if (this._width.toString(this._host) === value) {
  1074. return;
  1075. }
  1076. if (this._width.fromString(value)) {
  1077. this._markAsDirty();
  1078. }
  1079. },
  1080. enumerable: true,
  1081. configurable: true
  1082. });
  1083. Object.defineProperty(Control.prototype, "widthInPixels", {
  1084. get: function () {
  1085. return this._width.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1086. },
  1087. enumerable: true,
  1088. configurable: true
  1089. });
  1090. Object.defineProperty(Control.prototype, "height", {
  1091. get: function () {
  1092. return this._height.toString(this._host);
  1093. },
  1094. set: function (value) {
  1095. if (this._height.toString(this._host) === value) {
  1096. return;
  1097. }
  1098. if (this._height.fromString(value)) {
  1099. this._markAsDirty();
  1100. }
  1101. },
  1102. enumerable: true,
  1103. configurable: true
  1104. });
  1105. Object.defineProperty(Control.prototype, "heightInPixels", {
  1106. get: function () {
  1107. return this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1108. },
  1109. enumerable: true,
  1110. configurable: true
  1111. });
  1112. Object.defineProperty(Control.prototype, "fontFamily", {
  1113. get: function () {
  1114. return this._fontFamily;
  1115. },
  1116. set: function (value) {
  1117. if (this._fontFamily === value) {
  1118. return;
  1119. }
  1120. this._fontFamily = value;
  1121. this._fontSet = true;
  1122. },
  1123. enumerable: true,
  1124. configurable: true
  1125. });
  1126. Object.defineProperty(Control.prototype, "fontStyle", {
  1127. get: function () {
  1128. return this._fontStyle;
  1129. },
  1130. set: function (value) {
  1131. if (this._fontStyle === value) {
  1132. return;
  1133. }
  1134. this._fontStyle = value;
  1135. this._fontSet = true;
  1136. },
  1137. enumerable: true,
  1138. configurable: true
  1139. });
  1140. Object.defineProperty(Control.prototype, "_isFontSizeInPercentage", {
  1141. /** @ignore */
  1142. get: function () {
  1143. return this._fontSize.isPercentage;
  1144. },
  1145. enumerable: true,
  1146. configurable: true
  1147. });
  1148. Object.defineProperty(Control.prototype, "fontSizeInPixels", {
  1149. get: function () {
  1150. if (this._fontSize.isPixel) {
  1151. return this._fontSize.getValue(this._host);
  1152. }
  1153. return this._fontSize.getValueInPixel(this._host, this._tempParentMeasure.height || this._cachedParentMeasure.height);
  1154. },
  1155. enumerable: true,
  1156. configurable: true
  1157. });
  1158. Object.defineProperty(Control.prototype, "fontSize", {
  1159. get: function () {
  1160. return this._fontSize.toString(this._host);
  1161. },
  1162. set: function (value) {
  1163. if (this._fontSize.toString(this._host) === value) {
  1164. return;
  1165. }
  1166. if (this._fontSize.fromString(value)) {
  1167. this._markAsDirty();
  1168. this._fontSet = true;
  1169. }
  1170. },
  1171. enumerable: true,
  1172. configurable: true
  1173. });
  1174. Object.defineProperty(Control.prototype, "color", {
  1175. get: function () {
  1176. return this._color;
  1177. },
  1178. set: function (value) {
  1179. if (this._color === value) {
  1180. return;
  1181. }
  1182. this._color = value;
  1183. this._markAsDirty();
  1184. },
  1185. enumerable: true,
  1186. configurable: true
  1187. });
  1188. Object.defineProperty(Control.prototype, "zIndex", {
  1189. get: function () {
  1190. return this._zIndex;
  1191. },
  1192. set: function (value) {
  1193. if (this.zIndex === value) {
  1194. return;
  1195. }
  1196. this._zIndex = value;
  1197. if (this._root) {
  1198. this._root._reOrderControl(this);
  1199. }
  1200. },
  1201. enumerable: true,
  1202. configurable: true
  1203. });
  1204. Object.defineProperty(Control.prototype, "notRenderable", {
  1205. get: function () {
  1206. return this._doNotRender;
  1207. },
  1208. set: function (value) {
  1209. if (this._doNotRender === value) {
  1210. return;
  1211. }
  1212. this._doNotRender = value;
  1213. this._markAsDirty();
  1214. },
  1215. enumerable: true,
  1216. configurable: true
  1217. });
  1218. Object.defineProperty(Control.prototype, "isVisible", {
  1219. get: function () {
  1220. return this._isVisible;
  1221. },
  1222. set: function (value) {
  1223. if (this._isVisible === value) {
  1224. return;
  1225. }
  1226. this._isVisible = value;
  1227. this._markAsDirty();
  1228. },
  1229. enumerable: true,
  1230. configurable: true
  1231. });
  1232. Object.defineProperty(Control.prototype, "isDirty", {
  1233. get: function () {
  1234. return this._isDirty;
  1235. },
  1236. enumerable: true,
  1237. configurable: true
  1238. });
  1239. Object.defineProperty(Control.prototype, "paddingLeft", {
  1240. get: function () {
  1241. return this._paddingLeft.toString(this._host);
  1242. },
  1243. set: function (value) {
  1244. if (this._paddingLeft.fromString(value)) {
  1245. this._markAsDirty();
  1246. }
  1247. },
  1248. enumerable: true,
  1249. configurable: true
  1250. });
  1251. Object.defineProperty(Control.prototype, "paddingLeftInPixels", {
  1252. get: function () {
  1253. return this._paddingLeft.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1254. },
  1255. enumerable: true,
  1256. configurable: true
  1257. });
  1258. Object.defineProperty(Control.prototype, "paddingRight", {
  1259. get: function () {
  1260. return this._paddingRight.toString(this._host);
  1261. },
  1262. set: function (value) {
  1263. if (this._paddingRight.fromString(value)) {
  1264. this._markAsDirty();
  1265. }
  1266. },
  1267. enumerable: true,
  1268. configurable: true
  1269. });
  1270. Object.defineProperty(Control.prototype, "paddingRightInPixels", {
  1271. get: function () {
  1272. return this._paddingRight.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1273. },
  1274. enumerable: true,
  1275. configurable: true
  1276. });
  1277. Object.defineProperty(Control.prototype, "paddingTop", {
  1278. get: function () {
  1279. return this._paddingTop.toString(this._host);
  1280. },
  1281. set: function (value) {
  1282. if (this._paddingTop.fromString(value)) {
  1283. this._markAsDirty();
  1284. }
  1285. },
  1286. enumerable: true,
  1287. configurable: true
  1288. });
  1289. Object.defineProperty(Control.prototype, "paddingTopInPixels", {
  1290. get: function () {
  1291. return this._paddingTop.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1292. },
  1293. enumerable: true,
  1294. configurable: true
  1295. });
  1296. Object.defineProperty(Control.prototype, "paddingBottom", {
  1297. get: function () {
  1298. return this._paddingBottom.toString(this._host);
  1299. },
  1300. set: function (value) {
  1301. if (this._paddingBottom.fromString(value)) {
  1302. this._markAsDirty();
  1303. }
  1304. },
  1305. enumerable: true,
  1306. configurable: true
  1307. });
  1308. Object.defineProperty(Control.prototype, "paddingBottomInPixels", {
  1309. get: function () {
  1310. return this._paddingBottom.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1311. },
  1312. enumerable: true,
  1313. configurable: true
  1314. });
  1315. Object.defineProperty(Control.prototype, "left", {
  1316. get: function () {
  1317. return this._left.toString(this._host);
  1318. },
  1319. set: function (value) {
  1320. if (this._left.fromString(value)) {
  1321. this._markAsDirty();
  1322. }
  1323. },
  1324. enumerable: true,
  1325. configurable: true
  1326. });
  1327. Object.defineProperty(Control.prototype, "leftInPixels", {
  1328. get: function () {
  1329. return this._left.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1330. },
  1331. enumerable: true,
  1332. configurable: true
  1333. });
  1334. Object.defineProperty(Control.prototype, "top", {
  1335. get: function () {
  1336. return this._top.toString(this._host);
  1337. },
  1338. set: function (value) {
  1339. if (this._top.fromString(value)) {
  1340. this._markAsDirty();
  1341. }
  1342. },
  1343. enumerable: true,
  1344. configurable: true
  1345. });
  1346. Object.defineProperty(Control.prototype, "topInPixels", {
  1347. get: function () {
  1348. return this._top.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1349. },
  1350. enumerable: true,
  1351. configurable: true
  1352. });
  1353. Object.defineProperty(Control.prototype, "linkOffsetX", {
  1354. get: function () {
  1355. return this._linkOffsetX.toString(this._host);
  1356. },
  1357. set: function (value) {
  1358. if (this._linkOffsetX.fromString(value)) {
  1359. this._markAsDirty();
  1360. }
  1361. },
  1362. enumerable: true,
  1363. configurable: true
  1364. });
  1365. Object.defineProperty(Control.prototype, "linkOffsetXInPixels", {
  1366. get: function () {
  1367. return this._linkOffsetX.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1368. },
  1369. enumerable: true,
  1370. configurable: true
  1371. });
  1372. Object.defineProperty(Control.prototype, "linkOffsetY", {
  1373. get: function () {
  1374. return this._linkOffsetY.toString(this._host);
  1375. },
  1376. set: function (value) {
  1377. if (this._linkOffsetY.fromString(value)) {
  1378. this._markAsDirty();
  1379. }
  1380. },
  1381. enumerable: true,
  1382. configurable: true
  1383. });
  1384. Object.defineProperty(Control.prototype, "linkOffsetYInPixels", {
  1385. get: function () {
  1386. return this._linkOffsetY.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1387. },
  1388. enumerable: true,
  1389. configurable: true
  1390. });
  1391. Object.defineProperty(Control.prototype, "centerX", {
  1392. get: function () {
  1393. return this._currentMeasure.left + this._currentMeasure.width / 2;
  1394. },
  1395. enumerable: true,
  1396. configurable: true
  1397. });
  1398. Object.defineProperty(Control.prototype, "centerY", {
  1399. get: function () {
  1400. return this._currentMeasure.top + this._currentMeasure.height / 2;
  1401. },
  1402. enumerable: true,
  1403. configurable: true
  1404. });
  1405. Control.prototype._getTypeName = function () {
  1406. return "Control";
  1407. };
  1408. /** @ignore */
  1409. Control.prototype._resetFontCache = function () {
  1410. this._fontSet = true;
  1411. };
  1412. Control.prototype.getLocalCoordinates = function (globalCoordinates) {
  1413. var result = BABYLON.Vector2.Zero();
  1414. this.getLocalCoordinatesToRef(globalCoordinates, result);
  1415. return result;
  1416. };
  1417. Control.prototype.getLocalCoordinatesToRef = function (globalCoordinates, result) {
  1418. result.x = globalCoordinates.x - this._currentMeasure.left;
  1419. result.y = globalCoordinates.y - this._currentMeasure.top;
  1420. return this;
  1421. };
  1422. Control.prototype.getParentLocalCoordinates = function (globalCoordinates) {
  1423. var result = BABYLON.Vector2.Zero();
  1424. result.x = globalCoordinates.x - this._cachedParentMeasure.left;
  1425. result.y = globalCoordinates.y - this._cachedParentMeasure.top;
  1426. return result;
  1427. };
  1428. Control.prototype.moveToVector3 = function (position, scene) {
  1429. if (!this._host || this._root !== this._host._rootContainer) {
  1430. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  1431. return;
  1432. }
  1433. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1434. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1435. var globalViewport = this._host._getGlobalViewport(scene);
  1436. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  1437. this._moveToProjectedPosition(projectedPosition);
  1438. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  1439. this.notRenderable = true;
  1440. return;
  1441. }
  1442. this.notRenderable = false;
  1443. };
  1444. Control.prototype.linkWithMesh = function (mesh) {
  1445. if (!this._host || this._root && this._root !== this._host._rootContainer) {
  1446. if (mesh) {
  1447. BABYLON.Tools.Error("Cannot link a control to a mesh if the control is not at root level");
  1448. }
  1449. return;
  1450. }
  1451. var index = this._host._linkedControls.indexOf(this);
  1452. if (index !== -1) {
  1453. this._linkedMesh = mesh;
  1454. if (!mesh) {
  1455. this._host._linkedControls.splice(index, 1);
  1456. }
  1457. return;
  1458. }
  1459. else if (!mesh) {
  1460. return;
  1461. }
  1462. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1463. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1464. this._linkedMesh = mesh;
  1465. this._onlyMeasureMode = true;
  1466. this._host._linkedControls.push(this);
  1467. };
  1468. Control.prototype._moveToProjectedPosition = function (projectedPosition) {
  1469. var oldLeft = this._left.getValue(this._host);
  1470. var oldTop = this._top.getValue(this._host);
  1471. var newLeft = ((projectedPosition.x + this._linkOffsetX.getValue(this._host)) - this._currentMeasure.width / 2);
  1472. var newTop = ((projectedPosition.y + this._linkOffsetY.getValue(this._host)) - this._currentMeasure.height / 2);
  1473. if (this._left.ignoreAdaptiveScaling && this._top.ignoreAdaptiveScaling) {
  1474. if (Math.abs(newLeft - oldLeft) < 0.5) {
  1475. newLeft = oldLeft;
  1476. }
  1477. if (Math.abs(newTop - oldTop) < 0.5) {
  1478. newTop = oldTop;
  1479. }
  1480. }
  1481. this.left = newLeft + "px";
  1482. this.top = newTop + "px";
  1483. this._left.ignoreAdaptiveScaling = true;
  1484. this._top.ignoreAdaptiveScaling = true;
  1485. };
  1486. Control.prototype._markMatrixAsDirty = function () {
  1487. this._isMatrixDirty = true;
  1488. this._markAsDirty();
  1489. };
  1490. Control.prototype._markAsDirty = function () {
  1491. this._isDirty = true;
  1492. if (!this._host) {
  1493. return; // Not yet connected
  1494. }
  1495. this._host.markAsDirty();
  1496. };
  1497. Control.prototype._markAllAsDirty = function () {
  1498. this._markAsDirty();
  1499. if (this._font) {
  1500. this._prepareFont();
  1501. }
  1502. };
  1503. Control.prototype._link = function (root, host) {
  1504. this._root = root;
  1505. this._host = host;
  1506. };
  1507. Control.prototype._transform = function (context) {
  1508. if (!this._isMatrixDirty && this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  1509. return;
  1510. }
  1511. // postTranslate
  1512. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  1513. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  1514. context.translate(offsetX, offsetY);
  1515. // rotate
  1516. context.rotate(this._rotation);
  1517. // scale
  1518. context.scale(this._scaleX, this._scaleY);
  1519. // preTranslate
  1520. context.translate(-offsetX, -offsetY);
  1521. // Need to update matrices?
  1522. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  1523. this._cachedOffsetX = offsetX;
  1524. this._cachedOffsetY = offsetY;
  1525. this._isMatrixDirty = false;
  1526. GUI.Matrix2D.ComposeToRef(-offsetX, -offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  1527. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  1528. }
  1529. };
  1530. Control.prototype._applyStates = function (context) {
  1531. if (this._fontSet) {
  1532. this._prepareFont();
  1533. this._fontSet = false;
  1534. }
  1535. if (this._font) {
  1536. context.font = this._font;
  1537. }
  1538. if (this._color) {
  1539. context.fillStyle = this._color;
  1540. }
  1541. if (this._alphaSet) {
  1542. context.globalAlpha = this._alpha;
  1543. }
  1544. };
  1545. Control.prototype._processMeasures = function (parentMeasure, context) {
  1546. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  1547. this._isDirty = false;
  1548. this._currentMeasure.copyFrom(parentMeasure);
  1549. // Let children take some pre-measurement actions
  1550. this._preMeasure(parentMeasure, context);
  1551. this._measure();
  1552. this._computeAlignment(parentMeasure, context);
  1553. // Convert to int values
  1554. this._currentMeasure.left = this._currentMeasure.left | 0;
  1555. this._currentMeasure.top = this._currentMeasure.top | 0;
  1556. this._currentMeasure.width = this._currentMeasure.width | 0;
  1557. this._currentMeasure.height = this._currentMeasure.height | 0;
  1558. // Let children add more features
  1559. this._additionalProcessing(parentMeasure, context);
  1560. this._cachedParentMeasure.copyFrom(parentMeasure);
  1561. if (this.onDirtyObservable.hasObservers()) {
  1562. this.onDirtyObservable.notifyObservers(this);
  1563. }
  1564. }
  1565. if (this._currentMeasure.left > parentMeasure.left + parentMeasure.width) {
  1566. return false;
  1567. }
  1568. if (this._currentMeasure.left + this._currentMeasure.width < parentMeasure.left) {
  1569. return false;
  1570. }
  1571. if (this._currentMeasure.top > parentMeasure.top + parentMeasure.height) {
  1572. return false;
  1573. }
  1574. if (this._currentMeasure.top + this._currentMeasure.height < parentMeasure.top) {
  1575. return false;
  1576. }
  1577. // Transform
  1578. this._transform(context);
  1579. if (this._onlyMeasureMode) {
  1580. this._onlyMeasureMode = false;
  1581. return false; // We do not want rendering for this frame as they are measure dependant information that need to be gathered
  1582. }
  1583. // Clip
  1584. this._clip(context);
  1585. context.clip();
  1586. return true;
  1587. };
  1588. Control.prototype._clip = function (context) {
  1589. context.beginPath();
  1590. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1591. var shadowOffsetX = this.shadowOffsetX;
  1592. var shadowOffsetY = this.shadowOffsetY;
  1593. var shadowBlur = this.shadowBlur;
  1594. var leftShadowOffset = Math.min(Math.min(shadowOffsetX, 0) - shadowBlur * 2, 0);
  1595. var rightShadowOffset = Math.max(Math.max(shadowOffsetX, 0) + shadowBlur * 2, 0);
  1596. var topShadowOffset = Math.min(Math.min(shadowOffsetY, 0) - shadowBlur * 2, 0);
  1597. var bottomShadowOffset = Math.max(Math.max(shadowOffsetY, 0) + shadowBlur * 2, 0);
  1598. context.rect(this._currentMeasure.left + leftShadowOffset, this._currentMeasure.top + topShadowOffset, this._currentMeasure.width + rightShadowOffset - leftShadowOffset, this._currentMeasure.height + bottomShadowOffset - topShadowOffset);
  1599. }
  1600. else {
  1601. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1602. }
  1603. };
  1604. Control.prototype._measure = function () {
  1605. // Width / Height
  1606. if (this._width.isPixel) {
  1607. this._currentMeasure.width = this._width.getValue(this._host);
  1608. }
  1609. else {
  1610. this._currentMeasure.width *= this._width.getValue(this._host);
  1611. }
  1612. if (this._height.isPixel) {
  1613. this._currentMeasure.height = this._height.getValue(this._host);
  1614. }
  1615. else {
  1616. this._currentMeasure.height *= this._height.getValue(this._host);
  1617. }
  1618. };
  1619. Control.prototype._computeAlignment = function (parentMeasure, context) {
  1620. var width = this._currentMeasure.width;
  1621. var height = this._currentMeasure.height;
  1622. var parentWidth = parentMeasure.width;
  1623. var parentHeight = parentMeasure.height;
  1624. // Left / top
  1625. var x = 0;
  1626. var y = 0;
  1627. switch (this.horizontalAlignment) {
  1628. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  1629. x = 0;
  1630. break;
  1631. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  1632. x = parentWidth - width;
  1633. break;
  1634. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  1635. x = (parentWidth - width) / 2;
  1636. break;
  1637. }
  1638. switch (this.verticalAlignment) {
  1639. case Control.VERTICAL_ALIGNMENT_TOP:
  1640. y = 0;
  1641. break;
  1642. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  1643. y = parentHeight - height;
  1644. break;
  1645. case Control.VERTICAL_ALIGNMENT_CENTER:
  1646. y = (parentHeight - height) / 2;
  1647. break;
  1648. }
  1649. if (this._paddingLeft.isPixel) {
  1650. this._currentMeasure.left += this._paddingLeft.getValue(this._host);
  1651. this._currentMeasure.width -= this._paddingLeft.getValue(this._host);
  1652. }
  1653. else {
  1654. this._currentMeasure.left += parentWidth * this._paddingLeft.getValue(this._host);
  1655. this._currentMeasure.width -= parentWidth * this._paddingLeft.getValue(this._host);
  1656. }
  1657. if (this._paddingRight.isPixel) {
  1658. this._currentMeasure.width -= this._paddingRight.getValue(this._host);
  1659. }
  1660. else {
  1661. this._currentMeasure.width -= parentWidth * this._paddingRight.getValue(this._host);
  1662. }
  1663. if (this._paddingTop.isPixel) {
  1664. this._currentMeasure.top += this._paddingTop.getValue(this._host);
  1665. this._currentMeasure.height -= this._paddingTop.getValue(this._host);
  1666. }
  1667. else {
  1668. this._currentMeasure.top += parentHeight * this._paddingTop.getValue(this._host);
  1669. this._currentMeasure.height -= parentHeight * this._paddingTop.getValue(this._host);
  1670. }
  1671. if (this._paddingBottom.isPixel) {
  1672. this._currentMeasure.height -= this._paddingBottom.getValue(this._host);
  1673. }
  1674. else {
  1675. this._currentMeasure.height -= parentHeight * this._paddingBottom.getValue(this._host);
  1676. }
  1677. if (this._left.isPixel) {
  1678. this._currentMeasure.left += this._left.getValue(this._host);
  1679. }
  1680. else {
  1681. this._currentMeasure.left += parentWidth * this._left.getValue(this._host);
  1682. }
  1683. if (this._top.isPixel) {
  1684. this._currentMeasure.top += this._top.getValue(this._host);
  1685. }
  1686. else {
  1687. this._currentMeasure.top += parentHeight * this._top.getValue(this._host);
  1688. }
  1689. this._currentMeasure.left += x;
  1690. this._currentMeasure.top += y;
  1691. };
  1692. Control.prototype._preMeasure = function (parentMeasure, context) {
  1693. // Do nothing
  1694. };
  1695. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  1696. // Do nothing
  1697. };
  1698. Control.prototype._draw = function (parentMeasure, context) {
  1699. // Do nothing
  1700. };
  1701. Control.prototype.contains = function (x, y) {
  1702. // Invert transform
  1703. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  1704. x = this._transformedPosition.x;
  1705. y = this._transformedPosition.y;
  1706. // Check
  1707. if (x < this._currentMeasure.left) {
  1708. return false;
  1709. }
  1710. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  1711. return false;
  1712. }
  1713. if (y < this._currentMeasure.top) {
  1714. return false;
  1715. }
  1716. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  1717. return false;
  1718. }
  1719. if (this.isPointerBlocker) {
  1720. this._host._shouldBlockPointer = true;
  1721. }
  1722. return true;
  1723. };
  1724. Control.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  1725. if (!this.isHitTestVisible || !this.isVisible || this._doNotRender) {
  1726. return false;
  1727. }
  1728. if (!this.contains(x, y)) {
  1729. return false;
  1730. }
  1731. this._processObservables(type, x, y, pointerId, buttonIndex);
  1732. return true;
  1733. };
  1734. Control.prototype._onPointerMove = function (target, coordinates) {
  1735. var canNotify = this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  1736. if (canNotify && this.parent != null)
  1737. this.parent._onPointerMove(target, coordinates);
  1738. };
  1739. Control.prototype._onPointerEnter = function (target) {
  1740. if (this._enterCount !== 0) {
  1741. return false;
  1742. }
  1743. this._enterCount++;
  1744. var canNotify = this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  1745. if (canNotify && this.parent != null)
  1746. this.parent._onPointerEnter(target);
  1747. return true;
  1748. };
  1749. Control.prototype._onPointerOut = function (target) {
  1750. this._enterCount = 0;
  1751. var canNotify = this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  1752. if (canNotify && this.parent != null)
  1753. this.parent._onPointerOut(target);
  1754. };
  1755. Control.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  1756. if (this._downCount !== 0) {
  1757. return false;
  1758. }
  1759. this._downCount++;
  1760. this._downPointerIds[pointerId] = true;
  1761. var canNotify = this.onPointerDownObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  1762. if (canNotify && this.parent != null)
  1763. this.parent._onPointerDown(target, coordinates, pointerId, buttonIndex);
  1764. return true;
  1765. };
  1766. Control.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  1767. this._downCount = 0;
  1768. delete this._downPointerIds[pointerId];
  1769. var canNotifyClick = notifyClick;
  1770. if (notifyClick && this._enterCount > 0) {
  1771. canNotifyClick = this.onPointerClickObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  1772. }
  1773. var canNotify = this.onPointerUpObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  1774. if (canNotify && this.parent != null)
  1775. this.parent._onPointerUp(target, coordinates, pointerId, buttonIndex, canNotifyClick);
  1776. };
  1777. Control.prototype.forcePointerUp = function (pointerId) {
  1778. if (pointerId === void 0) { pointerId = null; }
  1779. if (pointerId !== null) {
  1780. this._onPointerUp(this, BABYLON.Vector2.Zero(), pointerId, 0, true);
  1781. }
  1782. else {
  1783. for (var key in this._downPointerIds) {
  1784. this._onPointerUp(this, BABYLON.Vector2.Zero(), +key, 0, true);
  1785. }
  1786. }
  1787. };
  1788. Control.prototype._processObservables = function (type, x, y, pointerId, buttonIndex) {
  1789. this._dummyVector2.copyFromFloats(x, y);
  1790. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  1791. this._onPointerMove(this, this._dummyVector2);
  1792. var previousControlOver = this._host._lastControlOver[pointerId];
  1793. if (previousControlOver && previousControlOver !== this) {
  1794. previousControlOver._onPointerOut(this);
  1795. }
  1796. if (previousControlOver !== this) {
  1797. this._onPointerEnter(this);
  1798. }
  1799. this._host._lastControlOver[pointerId] = this;
  1800. return true;
  1801. }
  1802. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  1803. this._onPointerDown(this, this._dummyVector2, pointerId, buttonIndex);
  1804. this._host._lastControlDown[pointerId] = this;
  1805. this._host._lastPickedControl = this;
  1806. return true;
  1807. }
  1808. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  1809. if (this._host._lastControlDown[pointerId]) {
  1810. this._host._lastControlDown[pointerId]._onPointerUp(this, this._dummyVector2, pointerId, buttonIndex, true);
  1811. }
  1812. delete this._host._lastControlDown[pointerId];
  1813. return true;
  1814. }
  1815. return false;
  1816. };
  1817. Control.prototype._prepareFont = function () {
  1818. if (!this._font && !this._fontSet) {
  1819. return;
  1820. }
  1821. this._font = this._fontStyle + " " + this.fontSizeInPixels + "px " + this._fontFamily;
  1822. this._fontOffset = Control._GetFontOffset(this._font);
  1823. };
  1824. Control.prototype.dispose = function () {
  1825. this.onDirtyObservable.clear();
  1826. this.onAfterDrawObservable.clear();
  1827. this.onPointerDownObservable.clear();
  1828. this.onPointerEnterObservable.clear();
  1829. this.onPointerMoveObservable.clear();
  1830. this.onPointerOutObservable.clear();
  1831. this.onPointerUpObservable.clear();
  1832. this.onPointerClickObservable.clear();
  1833. if (this._root) {
  1834. this._root.removeControl(this);
  1835. this._root = null;
  1836. }
  1837. var index = this._host._linkedControls.indexOf(this);
  1838. if (index > -1) {
  1839. this.linkWithMesh(null);
  1840. }
  1841. };
  1842. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  1843. get: function () {
  1844. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  1845. },
  1846. enumerable: true,
  1847. configurable: true
  1848. });
  1849. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  1850. get: function () {
  1851. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  1852. },
  1853. enumerable: true,
  1854. configurable: true
  1855. });
  1856. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  1857. get: function () {
  1858. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  1859. },
  1860. enumerable: true,
  1861. configurable: true
  1862. });
  1863. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  1864. get: function () {
  1865. return Control._VERTICAL_ALIGNMENT_TOP;
  1866. },
  1867. enumerable: true,
  1868. configurable: true
  1869. });
  1870. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  1871. get: function () {
  1872. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  1873. },
  1874. enumerable: true,
  1875. configurable: true
  1876. });
  1877. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  1878. get: function () {
  1879. return Control._VERTICAL_ALIGNMENT_CENTER;
  1880. },
  1881. enumerable: true,
  1882. configurable: true
  1883. });
  1884. Control._GetFontOffset = function (font) {
  1885. if (Control._FontHeightSizes[font]) {
  1886. return Control._FontHeightSizes[font];
  1887. }
  1888. var text = document.createElement("span");
  1889. text.innerHTML = "Hg";
  1890. text.style.font = font;
  1891. var block = document.createElement("div");
  1892. block.style.display = "inline-block";
  1893. block.style.width = "1px";
  1894. block.style.height = "0px";
  1895. block.style.verticalAlign = "bottom";
  1896. var div = document.createElement("div");
  1897. div.appendChild(text);
  1898. div.appendChild(block);
  1899. document.body.appendChild(div);
  1900. var fontAscent = 0;
  1901. var fontHeight = 0;
  1902. try {
  1903. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1904. block.style.verticalAlign = "baseline";
  1905. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  1906. }
  1907. finally {
  1908. document.body.removeChild(div);
  1909. }
  1910. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  1911. Control._FontHeightSizes[font] = result;
  1912. return result;
  1913. };
  1914. ;
  1915. Control.AddHeader = function (control, text, size, options) {
  1916. var panel = new BABYLON.GUI.StackPanel("panel");
  1917. var isHorizontal = options ? options.isHorizontal : true;
  1918. var controlFirst = options ? options.controlFirst : true;
  1919. panel.isVertical = !isHorizontal;
  1920. var header = new BABYLON.GUI.TextBlock("header");
  1921. header.text = text;
  1922. header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  1923. if (isHorizontal) {
  1924. header.width = size;
  1925. }
  1926. else {
  1927. header.height = size;
  1928. }
  1929. if (controlFirst) {
  1930. panel.addControl(control);
  1931. panel.addControl(header);
  1932. header.paddingLeft = "5px";
  1933. }
  1934. else {
  1935. panel.addControl(header);
  1936. panel.addControl(control);
  1937. header.paddingRight = "5px";
  1938. }
  1939. header.shadowBlur = control.shadowBlur;
  1940. header.shadowColor = control.shadowColor;
  1941. header.shadowOffsetX = control.shadowOffsetX;
  1942. header.shadowOffsetY = control.shadowOffsetY;
  1943. return panel;
  1944. };
  1945. Control.drawEllipse = function (x, y, width, height, context) {
  1946. context.translate(x, y);
  1947. context.scale(width, height);
  1948. context.beginPath();
  1949. context.arc(0, 0, 1, 0, 2 * Math.PI);
  1950. context.closePath();
  1951. context.scale(1 / width, 1 / height);
  1952. context.translate(-x, -y);
  1953. };
  1954. // Statics
  1955. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  1956. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  1957. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  1958. Control._VERTICAL_ALIGNMENT_TOP = 0;
  1959. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  1960. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  1961. Control._FontHeightSizes = {};
  1962. return Control;
  1963. }());
  1964. GUI.Control = Control;
  1965. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1966. })(BABYLON || (BABYLON = {}));
  1967. //# sourceMappingURL=control.js.map
  1968. "use strict";
  1969. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1970. var BABYLON;
  1971. (function (BABYLON) {
  1972. var GUI;
  1973. (function (GUI) {
  1974. var Container = /** @class */ (function (_super) {
  1975. __extends(Container, _super);
  1976. function Container(name) {
  1977. var _this = _super.call(this, name) || this;
  1978. _this.name = name;
  1979. _this._children = new Array();
  1980. _this._measureForChildren = GUI.Measure.Empty();
  1981. _this._adaptWidthToChildren = false;
  1982. _this._adaptHeightToChildren = false;
  1983. return _this;
  1984. }
  1985. Object.defineProperty(Container.prototype, "adaptHeightToChildren", {
  1986. get: function () {
  1987. return this._adaptHeightToChildren;
  1988. },
  1989. set: function (value) {
  1990. if (this._adaptHeightToChildren === value) {
  1991. return;
  1992. }
  1993. this._adaptHeightToChildren = value;
  1994. if (value) {
  1995. this.height = "100%";
  1996. }
  1997. this._markAsDirty();
  1998. },
  1999. enumerable: true,
  2000. configurable: true
  2001. });
  2002. Object.defineProperty(Container.prototype, "adaptWidthToChildren", {
  2003. get: function () {
  2004. return this._adaptWidthToChildren;
  2005. },
  2006. set: function (value) {
  2007. if (this._adaptWidthToChildren === value) {
  2008. return;
  2009. }
  2010. this._adaptWidthToChildren = value;
  2011. if (value) {
  2012. this.width = "100%";
  2013. }
  2014. this._markAsDirty();
  2015. },
  2016. enumerable: true,
  2017. configurable: true
  2018. });
  2019. Object.defineProperty(Container.prototype, "background", {
  2020. get: function () {
  2021. return this._background;
  2022. },
  2023. set: function (value) {
  2024. if (this._background === value) {
  2025. return;
  2026. }
  2027. this._background = value;
  2028. this._markAsDirty();
  2029. },
  2030. enumerable: true,
  2031. configurable: true
  2032. });
  2033. Object.defineProperty(Container.prototype, "children", {
  2034. get: function () {
  2035. return this._children;
  2036. },
  2037. enumerable: true,
  2038. configurable: true
  2039. });
  2040. Container.prototype._getTypeName = function () {
  2041. return "Container";
  2042. };
  2043. Container.prototype.getChildByName = function (name) {
  2044. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2045. var child = _a[_i];
  2046. if (child.name === name) {
  2047. return child;
  2048. }
  2049. }
  2050. return null;
  2051. };
  2052. Container.prototype.getChildByType = function (name, type) {
  2053. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2054. var child = _a[_i];
  2055. if (child.typeName === type) {
  2056. return child;
  2057. }
  2058. }
  2059. return null;
  2060. };
  2061. Container.prototype.containsControl = function (control) {
  2062. return this._children.indexOf(control) !== -1;
  2063. };
  2064. Container.prototype.addControl = function (control) {
  2065. var index = this._children.indexOf(control);
  2066. if (index !== -1) {
  2067. return this;
  2068. }
  2069. control._link(this, this._host);
  2070. control._markAllAsDirty();
  2071. this._reOrderControl(control);
  2072. this._markAsDirty();
  2073. return this;
  2074. };
  2075. Container.prototype.removeControl = function (control) {
  2076. var index = this._children.indexOf(control);
  2077. if (index !== -1) {
  2078. this._children.splice(index, 1);
  2079. control.parent = null;
  2080. }
  2081. control.linkWithMesh(null);
  2082. if (this._host) {
  2083. this._host._cleanControlAfterRemoval(control);
  2084. }
  2085. this._markAsDirty();
  2086. return this;
  2087. };
  2088. Container.prototype._reOrderControl = function (control) {
  2089. this.removeControl(control);
  2090. for (var index = 0; index < this._children.length; index++) {
  2091. if (this._children[index].zIndex > control.zIndex) {
  2092. this._children.splice(index, 0, control);
  2093. return;
  2094. }
  2095. }
  2096. this._children.push(control);
  2097. control.parent = this;
  2098. this._markAsDirty();
  2099. };
  2100. Container.prototype._markMatrixAsDirty = function () {
  2101. _super.prototype._markMatrixAsDirty.call(this);
  2102. for (var index = 0; index < this._children.length; index++) {
  2103. this._children[index]._markMatrixAsDirty();
  2104. }
  2105. };
  2106. Container.prototype._markAllAsDirty = function () {
  2107. _super.prototype._markAllAsDirty.call(this);
  2108. for (var index = 0; index < this._children.length; index++) {
  2109. this._children[index]._markAllAsDirty();
  2110. }
  2111. };
  2112. Container.prototype._localDraw = function (context) {
  2113. if (this._background) {
  2114. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2115. context.shadowColor = this.shadowColor;
  2116. context.shadowBlur = this.shadowBlur;
  2117. context.shadowOffsetX = this.shadowOffsetX;
  2118. context.shadowOffsetY = this.shadowOffsetY;
  2119. }
  2120. context.fillStyle = this._background;
  2121. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2122. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2123. context.shadowBlur = 0;
  2124. context.shadowOffsetX = 0;
  2125. context.shadowOffsetY = 0;
  2126. }
  2127. }
  2128. };
  2129. Container.prototype._link = function (root, host) {
  2130. _super.prototype._link.call(this, root, host);
  2131. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2132. var child = _a[_i];
  2133. child._link(root, host);
  2134. }
  2135. };
  2136. Container.prototype._draw = function (parentMeasure, context) {
  2137. if (!this.isVisible || this.notRenderable) {
  2138. return;
  2139. }
  2140. context.save();
  2141. this._applyStates(context);
  2142. if (this._processMeasures(parentMeasure, context)) {
  2143. this._localDraw(context);
  2144. this._clipForChildren(context);
  2145. var computedWidth = -1;
  2146. var computedHeight = -1;
  2147. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2148. var child = _a[_i];
  2149. if (child.isVisible && !child.notRenderable) {
  2150. child._tempParentMeasure.copyFrom(this._measureForChildren);
  2151. child._draw(this._measureForChildren, context);
  2152. if (child.onAfterDrawObservable.hasObservers()) {
  2153. child.onAfterDrawObservable.notifyObservers(child);
  2154. }
  2155. if (this.adaptWidthToChildren && child._width.isPixel) {
  2156. computedWidth = Math.max(computedWidth, child._currentMeasure.width);
  2157. }
  2158. if (this.adaptHeightToChildren && child._height.isPixel) {
  2159. computedHeight = Math.max(computedHeight, child._currentMeasure.height);
  2160. }
  2161. }
  2162. }
  2163. if (this.adaptWidthToChildren && computedWidth >= 0) {
  2164. this.width = computedWidth + "px";
  2165. }
  2166. if (this.adaptHeightToChildren && computedHeight >= 0) {
  2167. this.height = computedHeight + "px";
  2168. }
  2169. }
  2170. context.restore();
  2171. if (this.onAfterDrawObservable.hasObservers()) {
  2172. this.onAfterDrawObservable.notifyObservers(this);
  2173. }
  2174. };
  2175. Container.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  2176. if (!this.isVisible || this.notRenderable) {
  2177. return false;
  2178. }
  2179. if (!_super.prototype.contains.call(this, x, y)) {
  2180. return false;
  2181. }
  2182. // Checking backwards to pick closest first
  2183. for (var index = this._children.length - 1; index >= 0; index--) {
  2184. var child = this._children[index];
  2185. if (child._processPicking(x, y, type, pointerId, buttonIndex)) {
  2186. return true;
  2187. }
  2188. }
  2189. if (!this.isHitTestVisible) {
  2190. return false;
  2191. }
  2192. return this._processObservables(type, x, y, pointerId, buttonIndex);
  2193. };
  2194. Container.prototype._clipForChildren = function (context) {
  2195. // DO nothing
  2196. };
  2197. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  2198. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2199. this._measureForChildren.copyFrom(this._currentMeasure);
  2200. };
  2201. Container.prototype.dispose = function () {
  2202. _super.prototype.dispose.call(this);
  2203. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2204. var control = _a[_i];
  2205. control.dispose();
  2206. }
  2207. };
  2208. return Container;
  2209. }(GUI.Control));
  2210. GUI.Container = Container;
  2211. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2212. })(BABYLON || (BABYLON = {}));
  2213. //# sourceMappingURL=container.js.map
  2214. "use strict";
  2215. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2216. var BABYLON;
  2217. (function (BABYLON) {
  2218. var GUI;
  2219. (function (GUI) {
  2220. var StackPanel = /** @class */ (function (_super) {
  2221. __extends(StackPanel, _super);
  2222. function StackPanel(name) {
  2223. var _this = _super.call(this, name) || this;
  2224. _this.name = name;
  2225. _this._isVertical = true;
  2226. _this._manualWidth = false;
  2227. _this._manualHeight = false;
  2228. _this._doNotTrackManualChanges = false;
  2229. _this._tempMeasureStore = GUI.Measure.Empty();
  2230. return _this;
  2231. }
  2232. Object.defineProperty(StackPanel.prototype, "isVertical", {
  2233. get: function () {
  2234. return this._isVertical;
  2235. },
  2236. set: function (value) {
  2237. if (this._isVertical === value) {
  2238. return;
  2239. }
  2240. this._isVertical = value;
  2241. this._markAsDirty();
  2242. },
  2243. enumerable: true,
  2244. configurable: true
  2245. });
  2246. Object.defineProperty(StackPanel.prototype, "width", {
  2247. get: function () {
  2248. return this._width.toString(this._host);
  2249. },
  2250. set: function (value) {
  2251. if (!this._doNotTrackManualChanges) {
  2252. this._manualWidth = true;
  2253. }
  2254. if (this._width.toString(this._host) === value) {
  2255. return;
  2256. }
  2257. if (this._width.fromString(value)) {
  2258. this._markAsDirty();
  2259. }
  2260. },
  2261. enumerable: true,
  2262. configurable: true
  2263. });
  2264. Object.defineProperty(StackPanel.prototype, "height", {
  2265. get: function () {
  2266. return this._height.toString(this._host);
  2267. },
  2268. set: function (value) {
  2269. if (!this._doNotTrackManualChanges) {
  2270. this._manualHeight = true;
  2271. }
  2272. if (this._height.toString(this._host) === value) {
  2273. return;
  2274. }
  2275. if (this._height.fromString(value)) {
  2276. this._markAsDirty();
  2277. }
  2278. },
  2279. enumerable: true,
  2280. configurable: true
  2281. });
  2282. StackPanel.prototype._getTypeName = function () {
  2283. return "StackPanel";
  2284. };
  2285. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  2286. var stackWidth = 0;
  2287. var stackHeight = 0;
  2288. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2289. var child = _a[_i];
  2290. this._tempMeasureStore.copyFrom(child._currentMeasure);
  2291. child._currentMeasure.copyFrom(parentMeasure);
  2292. child._measure();
  2293. if (this._isVertical) {
  2294. child.top = stackHeight + "px";
  2295. if (!child._top.ignoreAdaptiveScaling) {
  2296. child._markAsDirty();
  2297. }
  2298. child._top.ignoreAdaptiveScaling = true;
  2299. stackHeight += child._currentMeasure.height;
  2300. if (child._currentMeasure.width > stackWidth) {
  2301. stackWidth = child._currentMeasure.width;
  2302. }
  2303. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2304. }
  2305. else {
  2306. child.left = stackWidth + "px";
  2307. if (!child._left.ignoreAdaptiveScaling) {
  2308. child._markAsDirty();
  2309. }
  2310. child._left.ignoreAdaptiveScaling = true;
  2311. stackWidth += child._currentMeasure.width;
  2312. if (child._currentMeasure.height > stackHeight) {
  2313. stackHeight = child._currentMeasure.height;
  2314. }
  2315. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2316. }
  2317. child._currentMeasure.copyFrom(this._tempMeasureStore);
  2318. }
  2319. this._doNotTrackManualChanges = true;
  2320. // Let stack panel width and height default to stackHeight and stackWidth if dimensions are not specified.
  2321. // User can now define their own height and width for stack panel.
  2322. var panelWidthChanged = false;
  2323. var panelHeightChanged = false;
  2324. var previousHeight = this.height;
  2325. var previousWidth = this.width;
  2326. if (!this._manualHeight) {
  2327. // do not specify height if strictly defined by user
  2328. this.height = stackHeight + "px";
  2329. }
  2330. if (!this._manualWidth) {
  2331. // do not specify width if strictly defined by user
  2332. this.width = stackWidth + "px";
  2333. }
  2334. panelWidthChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  2335. panelHeightChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  2336. if (panelHeightChanged) {
  2337. this._height.ignoreAdaptiveScaling = true;
  2338. }
  2339. if (panelWidthChanged) {
  2340. this._width.ignoreAdaptiveScaling = true;
  2341. }
  2342. this._doNotTrackManualChanges = false;
  2343. if (panelWidthChanged || panelHeightChanged) {
  2344. this._markAllAsDirty();
  2345. }
  2346. _super.prototype._preMeasure.call(this, parentMeasure, context);
  2347. };
  2348. return StackPanel;
  2349. }(GUI.Container));
  2350. GUI.StackPanel = StackPanel;
  2351. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2352. })(BABYLON || (BABYLON = {}));
  2353. //# sourceMappingURL=stackPanel.js.map
  2354. "use strict";
  2355. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2356. var BABYLON;
  2357. (function (BABYLON) {
  2358. var GUI;
  2359. (function (GUI) {
  2360. var Rectangle = /** @class */ (function (_super) {
  2361. __extends(Rectangle, _super);
  2362. function Rectangle(name) {
  2363. var _this = _super.call(this, name) || this;
  2364. _this.name = name;
  2365. _this._thickness = 1;
  2366. _this._cornerRadius = 0;
  2367. return _this;
  2368. }
  2369. Object.defineProperty(Rectangle.prototype, "thickness", {
  2370. get: function () {
  2371. return this._thickness;
  2372. },
  2373. set: function (value) {
  2374. if (this._thickness === value) {
  2375. return;
  2376. }
  2377. this._thickness = value;
  2378. this._markAsDirty();
  2379. },
  2380. enumerable: true,
  2381. configurable: true
  2382. });
  2383. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  2384. get: function () {
  2385. return this._cornerRadius;
  2386. },
  2387. set: function (value) {
  2388. if (value < 0) {
  2389. value = 0;
  2390. }
  2391. if (this._cornerRadius === value) {
  2392. return;
  2393. }
  2394. this._cornerRadius = value;
  2395. this._markAsDirty();
  2396. },
  2397. enumerable: true,
  2398. configurable: true
  2399. });
  2400. Rectangle.prototype._getTypeName = function () {
  2401. return "Rectangle";
  2402. };
  2403. Rectangle.prototype._localDraw = function (context) {
  2404. context.save();
  2405. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2406. context.shadowColor = this.shadowColor;
  2407. context.shadowBlur = this.shadowBlur;
  2408. context.shadowOffsetX = this.shadowOffsetX;
  2409. context.shadowOffsetY = this.shadowOffsetY;
  2410. }
  2411. if (this._background) {
  2412. context.fillStyle = this._background;
  2413. if (this._cornerRadius) {
  2414. this._drawRoundedRect(context, this._thickness / 2);
  2415. context.fill();
  2416. }
  2417. else {
  2418. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2419. }
  2420. }
  2421. if (this._thickness) {
  2422. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2423. context.shadowBlur = 0;
  2424. context.shadowOffsetX = 0;
  2425. context.shadowOffsetY = 0;
  2426. }
  2427. if (this.color) {
  2428. context.strokeStyle = this.color;
  2429. }
  2430. context.lineWidth = this._thickness;
  2431. if (this._cornerRadius) {
  2432. this._drawRoundedRect(context, this._thickness / 2);
  2433. context.stroke();
  2434. }
  2435. else {
  2436. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  2437. }
  2438. }
  2439. context.restore();
  2440. };
  2441. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  2442. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2443. this._measureForChildren.width -= 2 * this._thickness;
  2444. this._measureForChildren.height -= 2 * this._thickness;
  2445. this._measureForChildren.left += this._thickness;
  2446. this._measureForChildren.top += this._thickness;
  2447. };
  2448. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  2449. if (offset === void 0) { offset = 0; }
  2450. var x = this._currentMeasure.left + offset;
  2451. var y = this._currentMeasure.top + offset;
  2452. var width = this._currentMeasure.width - offset * 2;
  2453. var height = this._currentMeasure.height - offset * 2;
  2454. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  2455. context.beginPath();
  2456. context.moveTo(x + radius, y);
  2457. context.lineTo(x + width - radius, y);
  2458. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  2459. context.lineTo(x + width, y + height - radius);
  2460. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  2461. context.lineTo(x + radius, y + height);
  2462. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  2463. context.lineTo(x, y + radius);
  2464. context.quadraticCurveTo(x, y, x + radius, y);
  2465. context.closePath();
  2466. };
  2467. Rectangle.prototype._clipForChildren = function (context) {
  2468. if (this._cornerRadius) {
  2469. this._drawRoundedRect(context, this._thickness);
  2470. context.clip();
  2471. }
  2472. };
  2473. return Rectangle;
  2474. }(GUI.Container));
  2475. GUI.Rectangle = Rectangle;
  2476. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2477. })(BABYLON || (BABYLON = {}));
  2478. //# sourceMappingURL=rectangle.js.map
  2479. "use strict";
  2480. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2481. var BABYLON;
  2482. (function (BABYLON) {
  2483. var GUI;
  2484. (function (GUI) {
  2485. var Ellipse = /** @class */ (function (_super) {
  2486. __extends(Ellipse, _super);
  2487. function Ellipse(name) {
  2488. var _this = _super.call(this, name) || this;
  2489. _this.name = name;
  2490. _this._thickness = 1;
  2491. return _this;
  2492. }
  2493. Object.defineProperty(Ellipse.prototype, "thickness", {
  2494. get: function () {
  2495. return this._thickness;
  2496. },
  2497. set: function (value) {
  2498. if (this._thickness === value) {
  2499. return;
  2500. }
  2501. this._thickness = value;
  2502. this._markAsDirty();
  2503. },
  2504. enumerable: true,
  2505. configurable: true
  2506. });
  2507. Ellipse.prototype._getTypeName = function () {
  2508. return "Ellipse";
  2509. };
  2510. Ellipse.prototype._localDraw = function (context) {
  2511. context.save();
  2512. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2513. context.shadowColor = this.shadowColor;
  2514. context.shadowBlur = this.shadowBlur;
  2515. context.shadowOffsetX = this.shadowOffsetX;
  2516. context.shadowOffsetY = this.shadowOffsetY;
  2517. }
  2518. 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);
  2519. if (this._background) {
  2520. context.fillStyle = this._background;
  2521. context.fill();
  2522. }
  2523. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2524. context.shadowBlur = 0;
  2525. context.shadowOffsetX = 0;
  2526. context.shadowOffsetY = 0;
  2527. }
  2528. if (this._thickness) {
  2529. if (this.color) {
  2530. context.strokeStyle = this.color;
  2531. }
  2532. context.lineWidth = this._thickness;
  2533. context.stroke();
  2534. }
  2535. context.restore();
  2536. };
  2537. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  2538. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2539. this._measureForChildren.width -= 2 * this._thickness;
  2540. this._measureForChildren.height -= 2 * this._thickness;
  2541. this._measureForChildren.left += this._thickness;
  2542. this._measureForChildren.top += this._thickness;
  2543. };
  2544. Ellipse.prototype._clipForChildren = function (context) {
  2545. 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);
  2546. context.clip();
  2547. };
  2548. return Ellipse;
  2549. }(GUI.Container));
  2550. GUI.Ellipse = Ellipse;
  2551. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2552. })(BABYLON || (BABYLON = {}));
  2553. //# sourceMappingURL=ellipse.js.map
  2554. "use strict";
  2555. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2556. var BABYLON;
  2557. (function (BABYLON) {
  2558. var GUI;
  2559. (function (GUI) {
  2560. var Line = /** @class */ (function (_super) {
  2561. __extends(Line, _super);
  2562. function Line(name) {
  2563. var _this = _super.call(this, name) || this;
  2564. _this.name = name;
  2565. _this._lineWidth = 1;
  2566. _this._x1 = new GUI.ValueAndUnit(0);
  2567. _this._y1 = new GUI.ValueAndUnit(0);
  2568. _this._x2 = new GUI.ValueAndUnit(0);
  2569. _this._y2 = new GUI.ValueAndUnit(0);
  2570. _this._dash = new Array();
  2571. _this.isHitTestVisible = false;
  2572. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2573. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2574. return _this;
  2575. }
  2576. Object.defineProperty(Line.prototype, "dash", {
  2577. get: function () {
  2578. return this._dash;
  2579. },
  2580. set: function (value) {
  2581. if (this._dash === value) {
  2582. return;
  2583. }
  2584. this._dash = value;
  2585. this._markAsDirty();
  2586. },
  2587. enumerable: true,
  2588. configurable: true
  2589. });
  2590. Object.defineProperty(Line.prototype, "connectedControl", {
  2591. get: function () {
  2592. return this._connectedControl;
  2593. },
  2594. set: function (value) {
  2595. var _this = this;
  2596. if (this._connectedControl === value) {
  2597. return;
  2598. }
  2599. if (this._connectedControlDirtyObserver && this._connectedControl) {
  2600. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  2601. this._connectedControlDirtyObserver = null;
  2602. }
  2603. if (value) {
  2604. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  2605. }
  2606. this._connectedControl = value;
  2607. this._markAsDirty();
  2608. },
  2609. enumerable: true,
  2610. configurable: true
  2611. });
  2612. Object.defineProperty(Line.prototype, "x1", {
  2613. get: function () {
  2614. return this._x1.toString(this._host);
  2615. },
  2616. set: function (value) {
  2617. if (this._x1.toString(this._host) === value) {
  2618. return;
  2619. }
  2620. if (this._x1.fromString(value)) {
  2621. this._markAsDirty();
  2622. }
  2623. },
  2624. enumerable: true,
  2625. configurable: true
  2626. });
  2627. Object.defineProperty(Line.prototype, "y1", {
  2628. get: function () {
  2629. return this._y1.toString(this._host);
  2630. },
  2631. set: function (value) {
  2632. if (this._y1.toString(this._host) === value) {
  2633. return;
  2634. }
  2635. if (this._y1.fromString(value)) {
  2636. this._markAsDirty();
  2637. }
  2638. },
  2639. enumerable: true,
  2640. configurable: true
  2641. });
  2642. Object.defineProperty(Line.prototype, "x2", {
  2643. get: function () {
  2644. return this._x2.toString(this._host);
  2645. },
  2646. set: function (value) {
  2647. if (this._x2.toString(this._host) === value) {
  2648. return;
  2649. }
  2650. if (this._x2.fromString(value)) {
  2651. this._markAsDirty();
  2652. }
  2653. },
  2654. enumerable: true,
  2655. configurable: true
  2656. });
  2657. Object.defineProperty(Line.prototype, "y2", {
  2658. get: function () {
  2659. return this._y2.toString(this._host);
  2660. },
  2661. set: function (value) {
  2662. if (this._y2.toString(this._host) === value) {
  2663. return;
  2664. }
  2665. if (this._y2.fromString(value)) {
  2666. this._markAsDirty();
  2667. }
  2668. },
  2669. enumerable: true,
  2670. configurable: true
  2671. });
  2672. Object.defineProperty(Line.prototype, "lineWidth", {
  2673. get: function () {
  2674. return this._lineWidth;
  2675. },
  2676. set: function (value) {
  2677. if (this._lineWidth === value) {
  2678. return;
  2679. }
  2680. this._lineWidth = value;
  2681. this._markAsDirty();
  2682. },
  2683. enumerable: true,
  2684. configurable: true
  2685. });
  2686. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  2687. set: function (value) {
  2688. return;
  2689. },
  2690. enumerable: true,
  2691. configurable: true
  2692. });
  2693. Object.defineProperty(Line.prototype, "verticalAlignment", {
  2694. set: function (value) {
  2695. return;
  2696. },
  2697. enumerable: true,
  2698. configurable: true
  2699. });
  2700. Object.defineProperty(Line.prototype, "_effectiveX2", {
  2701. get: function () {
  2702. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  2703. },
  2704. enumerable: true,
  2705. configurable: true
  2706. });
  2707. Object.defineProperty(Line.prototype, "_effectiveY2", {
  2708. get: function () {
  2709. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  2710. },
  2711. enumerable: true,
  2712. configurable: true
  2713. });
  2714. Line.prototype._getTypeName = function () {
  2715. return "Line";
  2716. };
  2717. Line.prototype._draw = function (parentMeasure, context) {
  2718. context.save();
  2719. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2720. context.shadowColor = this.shadowColor;
  2721. context.shadowBlur = this.shadowBlur;
  2722. context.shadowOffsetX = this.shadowOffsetX;
  2723. context.shadowOffsetY = this.shadowOffsetY;
  2724. }
  2725. this._applyStates(context);
  2726. if (this._processMeasures(parentMeasure, context)) {
  2727. context.strokeStyle = this.color;
  2728. context.lineWidth = this._lineWidth;
  2729. context.setLineDash(this._dash);
  2730. context.beginPath();
  2731. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  2732. context.lineTo(this._effectiveX2, this._effectiveY2);
  2733. context.stroke();
  2734. }
  2735. context.restore();
  2736. };
  2737. Line.prototype._measure = function () {
  2738. // Width / Height
  2739. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  2740. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  2741. };
  2742. Line.prototype._computeAlignment = function (parentMeasure, context) {
  2743. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  2744. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  2745. };
  2746. /**
  2747. * Move one end of the line given 3D cartesian coordinates.
  2748. * @param position Targeted world position
  2749. * @param scene Scene
  2750. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  2751. */
  2752. Line.prototype.moveToVector3 = function (position, scene, end) {
  2753. if (end === void 0) { end = false; }
  2754. if (!this._host || this._root !== this._host._rootContainer) {
  2755. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  2756. return;
  2757. }
  2758. var globalViewport = this._host._getGlobalViewport(scene);
  2759. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  2760. this._moveToProjectedPosition(projectedPosition, end);
  2761. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  2762. this.notRenderable = true;
  2763. return;
  2764. }
  2765. this.notRenderable = false;
  2766. };
  2767. /**
  2768. * Move one end of the line to a position in screen absolute space.
  2769. * @param projectedPosition Position in screen absolute space (X, Y)
  2770. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  2771. */
  2772. Line.prototype._moveToProjectedPosition = function (projectedPosition, end) {
  2773. if (end === void 0) { end = false; }
  2774. var x = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  2775. var y = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  2776. if (end) {
  2777. this.x2 = x;
  2778. this.y2 = y;
  2779. this._x2.ignoreAdaptiveScaling = true;
  2780. this._y2.ignoreAdaptiveScaling = true;
  2781. }
  2782. else {
  2783. this.x1 = x;
  2784. this.y1 = y;
  2785. this._x1.ignoreAdaptiveScaling = true;
  2786. this._y1.ignoreAdaptiveScaling = true;
  2787. }
  2788. };
  2789. return Line;
  2790. }(GUI.Control));
  2791. GUI.Line = Line;
  2792. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2793. })(BABYLON || (BABYLON = {}));
  2794. //# sourceMappingURL=line.js.map
  2795. "use strict";
  2796. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2797. var BABYLON;
  2798. (function (BABYLON) {
  2799. var GUI;
  2800. (function (GUI) {
  2801. var Slider = /** @class */ (function (_super) {
  2802. __extends(Slider, _super);
  2803. function Slider(name) {
  2804. var _this = _super.call(this, name) || this;
  2805. _this.name = name;
  2806. _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2807. _this._minimum = 0;
  2808. _this._maximum = 100;
  2809. _this._value = 50;
  2810. _this._background = "black";
  2811. _this._borderColor = "white";
  2812. _this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  2813. _this._isThumbCircle = false;
  2814. _this._isThumbClamped = false;
  2815. _this.onValueChangedObservable = new BABYLON.Observable();
  2816. // Events
  2817. _this._pointerIsDown = false;
  2818. _this.isPointerBlocker = true;
  2819. return _this;
  2820. }
  2821. Object.defineProperty(Slider.prototype, "borderColor", {
  2822. get: function () {
  2823. return this._borderColor;
  2824. },
  2825. set: function (value) {
  2826. if (this._borderColor === value) {
  2827. return;
  2828. }
  2829. this._borderColor = value;
  2830. this._markAsDirty();
  2831. },
  2832. enumerable: true,
  2833. configurable: true
  2834. });
  2835. Object.defineProperty(Slider.prototype, "background", {
  2836. get: function () {
  2837. return this._background;
  2838. },
  2839. set: function (value) {
  2840. if (this._background === value) {
  2841. return;
  2842. }
  2843. this._background = value;
  2844. this._markAsDirty();
  2845. },
  2846. enumerable: true,
  2847. configurable: true
  2848. });
  2849. Object.defineProperty(Slider.prototype, "barOffset", {
  2850. get: function () {
  2851. return this._barOffset.toString(this._host);
  2852. },
  2853. set: function (value) {
  2854. if (this._barOffset.toString(this._host) === value) {
  2855. return;
  2856. }
  2857. if (this._barOffset.fromString(value)) {
  2858. this._markAsDirty();
  2859. }
  2860. },
  2861. enumerable: true,
  2862. configurable: true
  2863. });
  2864. Object.defineProperty(Slider.prototype, "barOffsetInPixels", {
  2865. get: function () {
  2866. return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2867. },
  2868. enumerable: true,
  2869. configurable: true
  2870. });
  2871. Object.defineProperty(Slider.prototype, "thumbWidth", {
  2872. get: function () {
  2873. return this._thumbWidth.toString(this._host);
  2874. },
  2875. set: function (value) {
  2876. if (this._thumbWidth.toString(this._host) === value) {
  2877. return;
  2878. }
  2879. if (this._thumbWidth.fromString(value)) {
  2880. this._markAsDirty();
  2881. }
  2882. },
  2883. enumerable: true,
  2884. configurable: true
  2885. });
  2886. Object.defineProperty(Slider.prototype, "thumbWidthInPixels", {
  2887. get: function () {
  2888. return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2889. },
  2890. enumerable: true,
  2891. configurable: true
  2892. });
  2893. Object.defineProperty(Slider.prototype, "minimum", {
  2894. get: function () {
  2895. return this._minimum;
  2896. },
  2897. set: function (value) {
  2898. if (this._minimum === value) {
  2899. return;
  2900. }
  2901. this._minimum = value;
  2902. this._markAsDirty();
  2903. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2904. },
  2905. enumerable: true,
  2906. configurable: true
  2907. });
  2908. Object.defineProperty(Slider.prototype, "maximum", {
  2909. get: function () {
  2910. return this._maximum;
  2911. },
  2912. set: function (value) {
  2913. if (this._maximum === value) {
  2914. return;
  2915. }
  2916. this._maximum = value;
  2917. this._markAsDirty();
  2918. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  2919. },
  2920. enumerable: true,
  2921. configurable: true
  2922. });
  2923. Object.defineProperty(Slider.prototype, "value", {
  2924. get: function () {
  2925. return this._value;
  2926. },
  2927. set: function (value) {
  2928. value = Math.max(Math.min(value, this._maximum), this._minimum);
  2929. if (this._value === value) {
  2930. return;
  2931. }
  2932. this._value = value;
  2933. this._markAsDirty();
  2934. this.onValueChangedObservable.notifyObservers(this._value);
  2935. },
  2936. enumerable: true,
  2937. configurable: true
  2938. });
  2939. Object.defineProperty(Slider.prototype, "isThumbCircle", {
  2940. get: function () {
  2941. return this._isThumbCircle;
  2942. },
  2943. set: function (value) {
  2944. if (this._isThumbCircle === value) {
  2945. return;
  2946. }
  2947. this._isThumbCircle = value;
  2948. this._markAsDirty();
  2949. },
  2950. enumerable: true,
  2951. configurable: true
  2952. });
  2953. Object.defineProperty(Slider.prototype, "isThumbClamped", {
  2954. get: function () {
  2955. return this._isThumbClamped;
  2956. },
  2957. set: function (value) {
  2958. if (this._isThumbClamped === value) {
  2959. return;
  2960. }
  2961. this._isThumbClamped = value;
  2962. this._markAsDirty();
  2963. },
  2964. enumerable: true,
  2965. configurable: true
  2966. });
  2967. Slider.prototype._getTypeName = function () {
  2968. return "Slider";
  2969. };
  2970. Slider.prototype._draw = function (parentMeasure, context) {
  2971. context.save();
  2972. this._applyStates(context);
  2973. if (this._processMeasures(parentMeasure, context)) {
  2974. // Main bar
  2975. var effectiveThumbWidth;
  2976. var effectiveBarOffset;
  2977. if (this._thumbWidth.isPixel) {
  2978. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.width);
  2979. }
  2980. else {
  2981. effectiveThumbWidth = this._currentMeasure.width * this._thumbWidth.getValue(this._host);
  2982. }
  2983. if (this._barOffset.isPixel) {
  2984. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  2985. }
  2986. else {
  2987. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  2988. }
  2989. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2990. context.shadowColor = this.shadowColor;
  2991. context.shadowBlur = this.shadowBlur;
  2992. context.shadowOffsetX = this.shadowOffsetX;
  2993. context.shadowOffsetY = this.shadowOffsetY;
  2994. }
  2995. var left = this._currentMeasure.left;
  2996. var width = this._currentMeasure.width - effectiveThumbWidth;
  2997. var thumbPosition = ((this._value - this._minimum) / (this._maximum - this._minimum)) * width;
  2998. context.fillStyle = this._background;
  2999. if (this.isThumbClamped) {
  3000. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width + effectiveThumbWidth, this._currentMeasure.height - effectiveBarOffset * 2);
  3001. }
  3002. else {
  3003. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  3004. }
  3005. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3006. context.shadowBlur = 0;
  3007. context.shadowOffsetX = 0;
  3008. context.shadowOffsetY = 0;
  3009. }
  3010. context.fillStyle = this.color;
  3011. if (this.isThumbClamped) {
  3012. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3013. }
  3014. else {
  3015. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3016. }
  3017. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3018. context.shadowColor = this.shadowColor;
  3019. context.shadowBlur = this.shadowBlur;
  3020. context.shadowOffsetX = this.shadowOffsetX;
  3021. context.shadowOffsetY = this.shadowOffsetY;
  3022. }
  3023. if (this._isThumbCircle) {
  3024. context.beginPath();
  3025. context.arc(left + thumbPosition + (effectiveThumbWidth / 2), this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
  3026. context.fill();
  3027. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3028. context.shadowBlur = 0;
  3029. context.shadowOffsetX = 0;
  3030. context.shadowOffsetY = 0;
  3031. }
  3032. context.strokeStyle = this._borderColor;
  3033. context.stroke();
  3034. }
  3035. else {
  3036. context.fillRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3037. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3038. context.shadowBlur = 0;
  3039. context.shadowOffsetX = 0;
  3040. context.shadowOffsetY = 0;
  3041. }
  3042. context.strokeStyle = this._borderColor;
  3043. context.strokeRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3044. }
  3045. }
  3046. context.restore();
  3047. };
  3048. Slider.prototype._updateValueFromPointer = function (x, y) {
  3049. if (this.rotation != 0) {
  3050. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  3051. x = this._transformedPosition.x;
  3052. }
  3053. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  3054. };
  3055. Slider.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3056. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3057. return false;
  3058. }
  3059. this._pointerIsDown = true;
  3060. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3061. this._host._capturingControl[pointerId] = this;
  3062. return true;
  3063. };
  3064. Slider.prototype._onPointerMove = function (target, coordinates) {
  3065. if (this._pointerIsDown) {
  3066. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3067. }
  3068. _super.prototype._onPointerMove.call(this, target, coordinates);
  3069. };
  3070. Slider.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  3071. this._pointerIsDown = false;
  3072. delete this._host._capturingControl[pointerId];
  3073. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  3074. };
  3075. return Slider;
  3076. }(GUI.Control));
  3077. GUI.Slider = Slider;
  3078. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3079. })(BABYLON || (BABYLON = {}));
  3080. //# sourceMappingURL=slider.js.map
  3081. "use strict";
  3082. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3083. var BABYLON;
  3084. (function (BABYLON) {
  3085. var GUI;
  3086. (function (GUI) {
  3087. var Checkbox = /** @class */ (function (_super) {
  3088. __extends(Checkbox, _super);
  3089. function Checkbox(name) {
  3090. var _this = _super.call(this, name) || this;
  3091. _this.name = name;
  3092. _this._isChecked = false;
  3093. _this._background = "black";
  3094. _this._checkSizeRatio = 0.8;
  3095. _this._thickness = 1;
  3096. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  3097. _this.isPointerBlocker = true;
  3098. return _this;
  3099. }
  3100. Object.defineProperty(Checkbox.prototype, "thickness", {
  3101. get: function () {
  3102. return this._thickness;
  3103. },
  3104. set: function (value) {
  3105. if (this._thickness === value) {
  3106. return;
  3107. }
  3108. this._thickness = value;
  3109. this._markAsDirty();
  3110. },
  3111. enumerable: true,
  3112. configurable: true
  3113. });
  3114. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  3115. get: function () {
  3116. return this._checkSizeRatio;
  3117. },
  3118. set: function (value) {
  3119. value = Math.max(Math.min(1, value), 0);
  3120. if (this._checkSizeRatio === value) {
  3121. return;
  3122. }
  3123. this._checkSizeRatio = value;
  3124. this._markAsDirty();
  3125. },
  3126. enumerable: true,
  3127. configurable: true
  3128. });
  3129. Object.defineProperty(Checkbox.prototype, "background", {
  3130. get: function () {
  3131. return this._background;
  3132. },
  3133. set: function (value) {
  3134. if (this._background === value) {
  3135. return;
  3136. }
  3137. this._background = value;
  3138. this._markAsDirty();
  3139. },
  3140. enumerable: true,
  3141. configurable: true
  3142. });
  3143. Object.defineProperty(Checkbox.prototype, "isChecked", {
  3144. get: function () {
  3145. return this._isChecked;
  3146. },
  3147. set: function (value) {
  3148. if (this._isChecked === value) {
  3149. return;
  3150. }
  3151. this._isChecked = value;
  3152. this._markAsDirty();
  3153. this.onIsCheckedChangedObservable.notifyObservers(value);
  3154. },
  3155. enumerable: true,
  3156. configurable: true
  3157. });
  3158. Checkbox.prototype._getTypeName = function () {
  3159. return "CheckBox";
  3160. };
  3161. Checkbox.prototype._draw = function (parentMeasure, context) {
  3162. context.save();
  3163. this._applyStates(context);
  3164. if (this._processMeasures(parentMeasure, context)) {
  3165. var actualWidth = this._currentMeasure.width - this._thickness;
  3166. var actualHeight = this._currentMeasure.height - this._thickness;
  3167. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3168. context.shadowColor = this.shadowColor;
  3169. context.shadowBlur = this.shadowBlur;
  3170. context.shadowOffsetX = this.shadowOffsetX;
  3171. context.shadowOffsetY = this.shadowOffsetY;
  3172. }
  3173. context.fillStyle = this._background;
  3174. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  3175. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3176. context.shadowBlur = 0;
  3177. context.shadowOffsetX = 0;
  3178. context.shadowOffsetY = 0;
  3179. }
  3180. if (this._isChecked) {
  3181. context.fillStyle = this.color;
  3182. var offsetWidth = actualWidth * this._checkSizeRatio;
  3183. var offseHeight = actualHeight * this._checkSizeRatio;
  3184. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  3185. }
  3186. context.strokeStyle = this.color;
  3187. context.lineWidth = this._thickness;
  3188. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  3189. }
  3190. context.restore();
  3191. };
  3192. // Events
  3193. Checkbox.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3194. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3195. return false;
  3196. }
  3197. this.isChecked = !this.isChecked;
  3198. return true;
  3199. };
  3200. return Checkbox;
  3201. }(GUI.Control));
  3202. GUI.Checkbox = Checkbox;
  3203. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3204. })(BABYLON || (BABYLON = {}));
  3205. //# sourceMappingURL=checkbox.js.map
  3206. "use strict";
  3207. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3208. var BABYLON;
  3209. (function (BABYLON) {
  3210. var GUI;
  3211. (function (GUI) {
  3212. var RadioButton = /** @class */ (function (_super) {
  3213. __extends(RadioButton, _super);
  3214. function RadioButton(name) {
  3215. var _this = _super.call(this, name) || this;
  3216. _this.name = name;
  3217. _this._isChecked = false;
  3218. _this._background = "black";
  3219. _this._checkSizeRatio = 0.8;
  3220. _this._thickness = 1;
  3221. _this.group = "";
  3222. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  3223. _this.isPointerBlocker = true;
  3224. return _this;
  3225. }
  3226. Object.defineProperty(RadioButton.prototype, "thickness", {
  3227. get: function () {
  3228. return this._thickness;
  3229. },
  3230. set: function (value) {
  3231. if (this._thickness === value) {
  3232. return;
  3233. }
  3234. this._thickness = value;
  3235. this._markAsDirty();
  3236. },
  3237. enumerable: true,
  3238. configurable: true
  3239. });
  3240. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  3241. get: function () {
  3242. return this._checkSizeRatio;
  3243. },
  3244. set: function (value) {
  3245. value = Math.max(Math.min(1, value), 0);
  3246. if (this._checkSizeRatio === value) {
  3247. return;
  3248. }
  3249. this._checkSizeRatio = value;
  3250. this._markAsDirty();
  3251. },
  3252. enumerable: true,
  3253. configurable: true
  3254. });
  3255. Object.defineProperty(RadioButton.prototype, "background", {
  3256. get: function () {
  3257. return this._background;
  3258. },
  3259. set: function (value) {
  3260. if (this._background === value) {
  3261. return;
  3262. }
  3263. this._background = value;
  3264. this._markAsDirty();
  3265. },
  3266. enumerable: true,
  3267. configurable: true
  3268. });
  3269. Object.defineProperty(RadioButton.prototype, "isChecked", {
  3270. get: function () {
  3271. return this._isChecked;
  3272. },
  3273. set: function (value) {
  3274. var _this = this;
  3275. if (this._isChecked === value) {
  3276. return;
  3277. }
  3278. this._isChecked = value;
  3279. this._markAsDirty();
  3280. this.onIsCheckedChangedObservable.notifyObservers(value);
  3281. if (this._isChecked) {
  3282. // Update all controls from same group
  3283. this._host.executeOnAllControls(function (control) {
  3284. if (control === _this) {
  3285. return;
  3286. }
  3287. if (control.group === undefined) {
  3288. return;
  3289. }
  3290. var childRadio = control;
  3291. if (childRadio.group === _this.group) {
  3292. childRadio.isChecked = false;
  3293. }
  3294. });
  3295. }
  3296. },
  3297. enumerable: true,
  3298. configurable: true
  3299. });
  3300. RadioButton.prototype._getTypeName = function () {
  3301. return "RadioButton";
  3302. };
  3303. RadioButton.prototype._draw = function (parentMeasure, context) {
  3304. context.save();
  3305. this._applyStates(context);
  3306. if (this._processMeasures(parentMeasure, context)) {
  3307. var actualWidth = this._currentMeasure.width - this._thickness;
  3308. var actualHeight = this._currentMeasure.height - this._thickness;
  3309. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3310. context.shadowColor = this.shadowColor;
  3311. context.shadowBlur = this.shadowBlur;
  3312. context.shadowOffsetX = this.shadowOffsetX;
  3313. context.shadowOffsetY = this.shadowOffsetY;
  3314. }
  3315. // Outer
  3316. 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);
  3317. context.fillStyle = this._background;
  3318. context.fill();
  3319. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3320. context.shadowBlur = 0;
  3321. context.shadowOffsetX = 0;
  3322. context.shadowOffsetY = 0;
  3323. }
  3324. context.strokeStyle = this.color;
  3325. context.lineWidth = this._thickness;
  3326. context.stroke();
  3327. // Inner
  3328. if (this._isChecked) {
  3329. context.fillStyle = this.color;
  3330. var offsetWidth = actualWidth * this._checkSizeRatio;
  3331. var offseHeight = actualHeight * this._checkSizeRatio;
  3332. 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);
  3333. context.fill();
  3334. }
  3335. }
  3336. context.restore();
  3337. };
  3338. // Events
  3339. RadioButton.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3340. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3341. return false;
  3342. }
  3343. this.isChecked = !this.isChecked;
  3344. return true;
  3345. };
  3346. return RadioButton;
  3347. }(GUI.Control));
  3348. GUI.RadioButton = RadioButton;
  3349. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3350. })(BABYLON || (BABYLON = {}));
  3351. //# sourceMappingURL=radioButton.js.map
  3352. "use strict";
  3353. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3354. var BABYLON;
  3355. (function (BABYLON) {
  3356. var GUI;
  3357. (function (GUI) {
  3358. var TextBlock = /** @class */ (function (_super) {
  3359. __extends(TextBlock, _super);
  3360. /**
  3361. * Creates a new TextBlock object
  3362. * @param name defines the name of the control
  3363. * @param text defines the text to display (emptry string by default)
  3364. */
  3365. function TextBlock(
  3366. /**
  3367. * Defines the name of the control
  3368. */
  3369. name, text) {
  3370. if (text === void 0) { text = ""; }
  3371. var _this = _super.call(this, name) || this;
  3372. _this.name = name;
  3373. _this._text = "";
  3374. _this._textWrapping = false;
  3375. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3376. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  3377. _this._resizeToFit = false;
  3378. _this._lineSpacing = new GUI.ValueAndUnit(0);
  3379. _this._outlineWidth = 0;
  3380. _this._outlineColor = "white";
  3381. /**
  3382. * An event triggered after the text is changed
  3383. */
  3384. _this.onTextChangedObservable = new BABYLON.Observable();
  3385. /**
  3386. * An event triggered after the text was broken up into lines
  3387. */
  3388. _this.onLinesReadyObservable = new BABYLON.Observable();
  3389. _this.text = text;
  3390. return _this;
  3391. }
  3392. Object.defineProperty(TextBlock.prototype, "lines", {
  3393. /**
  3394. * Return the line list (you may need to use the onLinesReadyObservable to make sure the list is ready)
  3395. */
  3396. get: function () {
  3397. return this._lines;
  3398. },
  3399. enumerable: true,
  3400. configurable: true
  3401. });
  3402. Object.defineProperty(TextBlock.prototype, "resizeToFit", {
  3403. /**
  3404. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  3405. */
  3406. get: function () {
  3407. return this._resizeToFit;
  3408. },
  3409. /**
  3410. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  3411. */
  3412. set: function (value) {
  3413. this._resizeToFit = value;
  3414. if (this._resizeToFit) {
  3415. this._width.ignoreAdaptiveScaling = true;
  3416. this._height.ignoreAdaptiveScaling = true;
  3417. }
  3418. },
  3419. enumerable: true,
  3420. configurable: true
  3421. });
  3422. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  3423. /**
  3424. * Gets or sets a boolean indicating if text must be wrapped
  3425. */
  3426. get: function () {
  3427. return this._textWrapping;
  3428. },
  3429. /**
  3430. * Gets or sets a boolean indicating if text must be wrapped
  3431. */
  3432. set: function (value) {
  3433. if (this._textWrapping === value) {
  3434. return;
  3435. }
  3436. this._textWrapping = value;
  3437. this._markAsDirty();
  3438. },
  3439. enumerable: true,
  3440. configurable: true
  3441. });
  3442. Object.defineProperty(TextBlock.prototype, "text", {
  3443. /**
  3444. * Gets or sets text to display
  3445. */
  3446. get: function () {
  3447. return this._text;
  3448. },
  3449. /**
  3450. * Gets or sets text to display
  3451. */
  3452. set: function (value) {
  3453. if (this._text === value) {
  3454. return;
  3455. }
  3456. this._text = value;
  3457. this._markAsDirty();
  3458. this.onTextChangedObservable.notifyObservers(this);
  3459. },
  3460. enumerable: true,
  3461. configurable: true
  3462. });
  3463. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  3464. /**
  3465. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  3466. */
  3467. get: function () {
  3468. return this._textHorizontalAlignment;
  3469. },
  3470. /**
  3471. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  3472. */
  3473. set: function (value) {
  3474. if (this._textHorizontalAlignment === value) {
  3475. return;
  3476. }
  3477. this._textHorizontalAlignment = value;
  3478. this._markAsDirty();
  3479. },
  3480. enumerable: true,
  3481. configurable: true
  3482. });
  3483. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  3484. /**
  3485. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  3486. */
  3487. get: function () {
  3488. return this._textVerticalAlignment;
  3489. },
  3490. /**
  3491. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  3492. */
  3493. set: function (value) {
  3494. if (this._textVerticalAlignment === value) {
  3495. return;
  3496. }
  3497. this._textVerticalAlignment = value;
  3498. this._markAsDirty();
  3499. },
  3500. enumerable: true,
  3501. configurable: true
  3502. });
  3503. Object.defineProperty(TextBlock.prototype, "lineSpacing", {
  3504. /**
  3505. * Gets or sets line spacing value
  3506. */
  3507. get: function () {
  3508. return this._lineSpacing.toString(this._host);
  3509. },
  3510. /**
  3511. * Gets or sets line spacing value
  3512. */
  3513. set: function (value) {
  3514. if (this._lineSpacing.fromString(value)) {
  3515. this._markAsDirty();
  3516. }
  3517. },
  3518. enumerable: true,
  3519. configurable: true
  3520. });
  3521. Object.defineProperty(TextBlock.prototype, "outlineWidth", {
  3522. /**
  3523. * Gets or sets outlineWidth of the text to display
  3524. */
  3525. get: function () {
  3526. return this._outlineWidth;
  3527. },
  3528. /**
  3529. * Gets or sets outlineWidth of the text to display
  3530. */
  3531. set: function (value) {
  3532. if (this._outlineWidth === value) {
  3533. return;
  3534. }
  3535. this._outlineWidth = value;
  3536. this._markAsDirty();
  3537. },
  3538. enumerable: true,
  3539. configurable: true
  3540. });
  3541. Object.defineProperty(TextBlock.prototype, "outlineColor", {
  3542. /**
  3543. * Gets or sets outlineColor of the text to display
  3544. */
  3545. get: function () {
  3546. return this._outlineColor;
  3547. },
  3548. /**
  3549. * Gets or sets outlineColor of the text to display
  3550. */
  3551. set: function (value) {
  3552. if (this._outlineColor === value) {
  3553. return;
  3554. }
  3555. this._outlineColor = value;
  3556. this._markAsDirty();
  3557. },
  3558. enumerable: true,
  3559. configurable: true
  3560. });
  3561. TextBlock.prototype._getTypeName = function () {
  3562. return "TextBlock";
  3563. };
  3564. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  3565. var width = this._currentMeasure.width;
  3566. var x = 0;
  3567. switch (this._textHorizontalAlignment) {
  3568. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  3569. x = 0;
  3570. break;
  3571. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  3572. x = width - textWidth;
  3573. break;
  3574. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  3575. x = (width - textWidth) / 2;
  3576. break;
  3577. }
  3578. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3579. context.shadowColor = this.shadowColor;
  3580. context.shadowBlur = this.shadowBlur;
  3581. context.shadowOffsetX = this.shadowOffsetX;
  3582. context.shadowOffsetY = this.shadowOffsetY;
  3583. }
  3584. if (this.outlineWidth) {
  3585. context.strokeText(text, this._currentMeasure.left + x, y);
  3586. }
  3587. context.fillText(text, this._currentMeasure.left + x, y);
  3588. };
  3589. /** @ignore */
  3590. TextBlock.prototype._draw = function (parentMeasure, context) {
  3591. context.save();
  3592. this._applyStates(context);
  3593. if (this._processMeasures(parentMeasure, context)) {
  3594. // Render lines
  3595. this._renderLines(context);
  3596. }
  3597. context.restore();
  3598. };
  3599. TextBlock.prototype._applyStates = function (context) {
  3600. _super.prototype._applyStates.call(this, context);
  3601. if (this.outlineWidth) {
  3602. context.lineWidth = this.outlineWidth;
  3603. context.strokeStyle = this.outlineColor;
  3604. }
  3605. };
  3606. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  3607. this._lines = [];
  3608. var _lines = this.text.split("\n");
  3609. if (this._textWrapping && !this._resizeToFit) {
  3610. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  3611. var _line = _lines_1[_i];
  3612. this._lines.push(this._parseLineWithTextWrapping(_line, context));
  3613. }
  3614. }
  3615. else {
  3616. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  3617. var _line = _lines_2[_a];
  3618. this._lines.push(this._parseLine(_line, context));
  3619. }
  3620. }
  3621. this.onLinesReadyObservable.notifyObservers(this);
  3622. };
  3623. TextBlock.prototype._parseLine = function (line, context) {
  3624. if (line === void 0) { line = ''; }
  3625. return { text: line, width: context.measureText(line).width };
  3626. };
  3627. TextBlock.prototype._parseLineWithTextWrapping = function (line, context) {
  3628. if (line === void 0) { line = ''; }
  3629. var words = line.split(' ');
  3630. var width = this._currentMeasure.width;
  3631. var lineWidth = 0;
  3632. for (var n = 0; n < words.length; n++) {
  3633. var testLine = n > 0 ? line + " " + words[n] : words[0];
  3634. var metrics = context.measureText(testLine);
  3635. var testWidth = metrics.width;
  3636. if (testWidth > width && n > 0) {
  3637. this._lines.push({ text: line, width: lineWidth });
  3638. line = words[n];
  3639. lineWidth = context.measureText(line).width;
  3640. }
  3641. else {
  3642. lineWidth = testWidth;
  3643. line = testLine;
  3644. }
  3645. }
  3646. return { text: line, width: lineWidth };
  3647. };
  3648. TextBlock.prototype._renderLines = function (context) {
  3649. var height = this._currentMeasure.height;
  3650. if (!this._fontOffset) {
  3651. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  3652. }
  3653. var rootY = 0;
  3654. switch (this._textVerticalAlignment) {
  3655. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  3656. rootY = this._fontOffset.ascent;
  3657. break;
  3658. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  3659. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  3660. break;
  3661. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  3662. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  3663. break;
  3664. }
  3665. rootY += this._currentMeasure.top;
  3666. var maxLineWidth = 0;
  3667. for (var i = 0; i < this._lines.length; i++) {
  3668. var line = this._lines[i];
  3669. if (i !== 0 && this._lineSpacing.internalValue !== 0) {
  3670. if (this._lineSpacing.isPixel) {
  3671. rootY += this._lineSpacing.getValue(this._host);
  3672. }
  3673. else {
  3674. rootY = rootY + (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
  3675. }
  3676. }
  3677. this._drawText(line.text, line.width, rootY, context);
  3678. rootY += this._fontOffset.height;
  3679. if (line.width > maxLineWidth)
  3680. maxLineWidth = line.width;
  3681. }
  3682. if (this._resizeToFit) {
  3683. this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
  3684. this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
  3685. }
  3686. };
  3687. TextBlock.prototype.dispose = function () {
  3688. _super.prototype.dispose.call(this);
  3689. this.onTextChangedObservable.clear();
  3690. };
  3691. return TextBlock;
  3692. }(GUI.Control));
  3693. GUI.TextBlock = TextBlock;
  3694. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3695. })(BABYLON || (BABYLON = {}));
  3696. //# sourceMappingURL=textBlock.js.map
  3697. "use strict";
  3698. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3699. var DOMImage = Image;
  3700. var BABYLON;
  3701. (function (BABYLON) {
  3702. var GUI;
  3703. (function (GUI) {
  3704. var Image = /** @class */ (function (_super) {
  3705. __extends(Image, _super);
  3706. function Image(name, url) {
  3707. if (url === void 0) { url = null; }
  3708. var _this = _super.call(this, name) || this;
  3709. _this.name = name;
  3710. _this._loaded = false;
  3711. _this._stretch = Image.STRETCH_FILL;
  3712. _this._autoScale = false;
  3713. _this._sourceLeft = 0;
  3714. _this._sourceTop = 0;
  3715. _this._sourceWidth = 0;
  3716. _this._sourceHeight = 0;
  3717. _this._cellWidth = 0;
  3718. _this._cellHeight = 0;
  3719. _this._cellId = -1;
  3720. _this.source = url;
  3721. return _this;
  3722. }
  3723. Object.defineProperty(Image.prototype, "sourceLeft", {
  3724. get: function () {
  3725. return this._sourceLeft;
  3726. },
  3727. set: function (value) {
  3728. if (this._sourceLeft === value) {
  3729. return;
  3730. }
  3731. this._sourceLeft = value;
  3732. this._markAsDirty();
  3733. },
  3734. enumerable: true,
  3735. configurable: true
  3736. });
  3737. Object.defineProperty(Image.prototype, "sourceTop", {
  3738. get: function () {
  3739. return this._sourceTop;
  3740. },
  3741. set: function (value) {
  3742. if (this._sourceTop === value) {
  3743. return;
  3744. }
  3745. this._sourceTop = value;
  3746. this._markAsDirty();
  3747. },
  3748. enumerable: true,
  3749. configurable: true
  3750. });
  3751. Object.defineProperty(Image.prototype, "sourceWidth", {
  3752. get: function () {
  3753. return this._sourceWidth;
  3754. },
  3755. set: function (value) {
  3756. if (this._sourceWidth === value) {
  3757. return;
  3758. }
  3759. this._sourceWidth = value;
  3760. this._markAsDirty();
  3761. },
  3762. enumerable: true,
  3763. configurable: true
  3764. });
  3765. Object.defineProperty(Image.prototype, "sourceHeight", {
  3766. get: function () {
  3767. return this._sourceHeight;
  3768. },
  3769. set: function (value) {
  3770. if (this._sourceHeight === value) {
  3771. return;
  3772. }
  3773. this._sourceHeight = value;
  3774. this._markAsDirty();
  3775. },
  3776. enumerable: true,
  3777. configurable: true
  3778. });
  3779. Object.defineProperty(Image.prototype, "autoScale", {
  3780. get: function () {
  3781. return this._autoScale;
  3782. },
  3783. set: function (value) {
  3784. if (this._autoScale === value) {
  3785. return;
  3786. }
  3787. this._autoScale = value;
  3788. if (value && this._loaded) {
  3789. this.synchronizeSizeWithContent();
  3790. }
  3791. },
  3792. enumerable: true,
  3793. configurable: true
  3794. });
  3795. Object.defineProperty(Image.prototype, "stretch", {
  3796. get: function () {
  3797. return this._stretch;
  3798. },
  3799. set: function (value) {
  3800. if (this._stretch === value) {
  3801. return;
  3802. }
  3803. this._stretch = value;
  3804. this._markAsDirty();
  3805. },
  3806. enumerable: true,
  3807. configurable: true
  3808. });
  3809. Object.defineProperty(Image.prototype, "domImage", {
  3810. get: function () {
  3811. return this._domImage;
  3812. },
  3813. set: function (value) {
  3814. var _this = this;
  3815. this._domImage = value;
  3816. this._loaded = false;
  3817. if (this._domImage.width) {
  3818. this._onImageLoaded();
  3819. }
  3820. else {
  3821. this._domImage.onload = function () {
  3822. _this._onImageLoaded();
  3823. };
  3824. }
  3825. },
  3826. enumerable: true,
  3827. configurable: true
  3828. });
  3829. Image.prototype._onImageLoaded = function () {
  3830. this._imageWidth = this._domImage.width;
  3831. this._imageHeight = this._domImage.height;
  3832. this._loaded = true;
  3833. if (this._autoScale) {
  3834. this.synchronizeSizeWithContent();
  3835. }
  3836. this._markAsDirty();
  3837. };
  3838. Object.defineProperty(Image.prototype, "source", {
  3839. set: function (value) {
  3840. var _this = this;
  3841. if (this._source === value) {
  3842. return;
  3843. }
  3844. this._loaded = false;
  3845. this._source = value;
  3846. this._domImage = new DOMImage();
  3847. this._domImage.onload = function () {
  3848. _this._onImageLoaded();
  3849. };
  3850. if (value) {
  3851. BABYLON.Tools.SetCorsBehavior(value, this._domImage);
  3852. this._domImage.src = value;
  3853. }
  3854. },
  3855. enumerable: true,
  3856. configurable: true
  3857. });
  3858. Object.defineProperty(Image.prototype, "cellWidth", {
  3859. get: function () {
  3860. return this._cellWidth;
  3861. },
  3862. set: function (value) {
  3863. if (this._cellWidth === value) {
  3864. return;
  3865. }
  3866. this._cellWidth = value;
  3867. this._markAsDirty();
  3868. },
  3869. enumerable: true,
  3870. configurable: true
  3871. });
  3872. Object.defineProperty(Image.prototype, "cellHeight", {
  3873. get: function () {
  3874. return this._cellHeight;
  3875. },
  3876. set: function (value) {
  3877. if (this._cellHeight === value) {
  3878. return;
  3879. }
  3880. this._cellHeight = value;
  3881. this._markAsDirty();
  3882. },
  3883. enumerable: true,
  3884. configurable: true
  3885. });
  3886. Object.defineProperty(Image.prototype, "cellId", {
  3887. get: function () {
  3888. return this._cellId;
  3889. },
  3890. set: function (value) {
  3891. if (this._cellId === value) {
  3892. return;
  3893. }
  3894. this._cellId = value;
  3895. this._markAsDirty();
  3896. },
  3897. enumerable: true,
  3898. configurable: true
  3899. });
  3900. Image.prototype._getTypeName = function () {
  3901. return "Image";
  3902. };
  3903. Image.prototype.synchronizeSizeWithContent = function () {
  3904. if (!this._loaded) {
  3905. return;
  3906. }
  3907. this.width = this._domImage.width + "px";
  3908. this.height = this._domImage.height + "px";
  3909. };
  3910. Image.prototype._draw = function (parentMeasure, context) {
  3911. context.save();
  3912. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3913. context.shadowColor = this.shadowColor;
  3914. context.shadowBlur = this.shadowBlur;
  3915. context.shadowOffsetX = this.shadowOffsetX;
  3916. context.shadowOffsetY = this.shadowOffsetY;
  3917. }
  3918. var x, y, width, height;
  3919. if (this.cellId == -1) {
  3920. x = this._sourceLeft;
  3921. y = this._sourceTop;
  3922. width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  3923. height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  3924. }
  3925. else {
  3926. var rowCount = this._domImage.naturalWidth / this.cellWidth;
  3927. var column = (this.cellId / rowCount) >> 0;
  3928. var row = this.cellId % rowCount;
  3929. x = this.cellWidth * row;
  3930. y = this.cellHeight * column;
  3931. width = this.cellWidth;
  3932. height = this.cellHeight;
  3933. }
  3934. this._applyStates(context);
  3935. if (this._processMeasures(parentMeasure, context)) {
  3936. if (this._loaded) {
  3937. switch (this._stretch) {
  3938. case Image.STRETCH_NONE:
  3939. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3940. break;
  3941. case Image.STRETCH_FILL:
  3942. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3943. break;
  3944. case Image.STRETCH_UNIFORM:
  3945. var hRatio = this._currentMeasure.width / width;
  3946. var vRatio = this._currentMeasure.height / height;
  3947. var ratio = Math.min(hRatio, vRatio);
  3948. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  3949. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  3950. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  3951. break;
  3952. case Image.STRETCH_EXTEND:
  3953. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3954. if (this._autoScale) {
  3955. this.synchronizeSizeWithContent();
  3956. }
  3957. if (this._root && this._root.parent) {
  3958. this._root.width = this.width;
  3959. this._root.height = this.height;
  3960. }
  3961. break;
  3962. }
  3963. }
  3964. }
  3965. context.restore();
  3966. };
  3967. Object.defineProperty(Image, "STRETCH_NONE", {
  3968. get: function () {
  3969. return Image._STRETCH_NONE;
  3970. },
  3971. enumerable: true,
  3972. configurable: true
  3973. });
  3974. Object.defineProperty(Image, "STRETCH_FILL", {
  3975. get: function () {
  3976. return Image._STRETCH_FILL;
  3977. },
  3978. enumerable: true,
  3979. configurable: true
  3980. });
  3981. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  3982. get: function () {
  3983. return Image._STRETCH_UNIFORM;
  3984. },
  3985. enumerable: true,
  3986. configurable: true
  3987. });
  3988. Object.defineProperty(Image, "STRETCH_EXTEND", {
  3989. get: function () {
  3990. return Image._STRETCH_EXTEND;
  3991. },
  3992. enumerable: true,
  3993. configurable: true
  3994. });
  3995. // Static
  3996. Image._STRETCH_NONE = 0;
  3997. Image._STRETCH_FILL = 1;
  3998. Image._STRETCH_UNIFORM = 2;
  3999. Image._STRETCH_EXTEND = 3;
  4000. return Image;
  4001. }(GUI.Control));
  4002. GUI.Image = Image;
  4003. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4004. })(BABYLON || (BABYLON = {}));
  4005. //# sourceMappingURL=image.js.map
  4006. "use strict";
  4007. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4008. var BABYLON;
  4009. (function (BABYLON) {
  4010. var GUI;
  4011. (function (GUI) {
  4012. var Button = /** @class */ (function (_super) {
  4013. __extends(Button, _super);
  4014. function Button(name) {
  4015. var _this = _super.call(this, name) || this;
  4016. _this.name = name;
  4017. _this.thickness = 1;
  4018. _this.isPointerBlocker = true;
  4019. _this.pointerEnterAnimation = function () {
  4020. _this.alpha -= 0.1;
  4021. };
  4022. _this.pointerOutAnimation = function () {
  4023. _this.alpha += 0.1;
  4024. };
  4025. _this.pointerDownAnimation = function () {
  4026. _this.scaleX -= 0.05;
  4027. _this.scaleY -= 0.05;
  4028. };
  4029. _this.pointerUpAnimation = function () {
  4030. _this.scaleX += 0.05;
  4031. _this.scaleY += 0.05;
  4032. };
  4033. return _this;
  4034. }
  4035. Button.prototype._getTypeName = function () {
  4036. return "Button";
  4037. };
  4038. // While being a container, the button behaves like a control.
  4039. Button.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  4040. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  4041. return false;
  4042. }
  4043. if (!_super.prototype.contains.call(this, x, y)) {
  4044. return false;
  4045. }
  4046. this._processObservables(type, x, y, pointerId, buttonIndex);
  4047. return true;
  4048. };
  4049. Button.prototype._onPointerEnter = function (target) {
  4050. if (!_super.prototype._onPointerEnter.call(this, target)) {
  4051. return false;
  4052. }
  4053. if (this.pointerEnterAnimation) {
  4054. this.pointerEnterAnimation();
  4055. }
  4056. return true;
  4057. };
  4058. Button.prototype._onPointerOut = function (target) {
  4059. if (this.pointerOutAnimation) {
  4060. this.pointerOutAnimation();
  4061. }
  4062. _super.prototype._onPointerOut.call(this, target);
  4063. };
  4064. Button.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4065. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4066. return false;
  4067. }
  4068. if (this.pointerDownAnimation) {
  4069. this.pointerDownAnimation();
  4070. }
  4071. return true;
  4072. };
  4073. Button.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  4074. if (this.pointerUpAnimation) {
  4075. this.pointerUpAnimation();
  4076. }
  4077. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  4078. };
  4079. // Statics
  4080. Button.CreateImageButton = function (name, text, imageUrl) {
  4081. var result = new Button(name);
  4082. // Adding text
  4083. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  4084. textBlock.textWrapping = true;
  4085. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4086. textBlock.paddingLeft = "20%";
  4087. result.addControl(textBlock);
  4088. // Adding image
  4089. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  4090. iconImage.width = "20%";
  4091. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  4092. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  4093. result.addControl(iconImage);
  4094. return result;
  4095. };
  4096. Button.CreateImageOnlyButton = function (name, imageUrl) {
  4097. var result = new Button(name);
  4098. // Adding image
  4099. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  4100. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  4101. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  4102. result.addControl(iconImage);
  4103. return result;
  4104. };
  4105. Button.CreateSimpleButton = function (name, text) {
  4106. var result = new Button(name);
  4107. // Adding text
  4108. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  4109. textBlock.textWrapping = true;
  4110. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4111. result.addControl(textBlock);
  4112. return result;
  4113. };
  4114. Button.CreateImageWithCenterTextButton = function (name, text, imageUrl) {
  4115. var result = new Button(name);
  4116. // Adding image
  4117. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  4118. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  4119. result.addControl(iconImage);
  4120. // Adding text
  4121. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  4122. textBlock.textWrapping = true;
  4123. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4124. result.addControl(textBlock);
  4125. return result;
  4126. };
  4127. return Button;
  4128. }(GUI.Rectangle));
  4129. GUI.Button = Button;
  4130. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4131. })(BABYLON || (BABYLON = {}));
  4132. //# sourceMappingURL=button.js.map
  4133. "use strict";
  4134. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4135. var BABYLON;
  4136. (function (BABYLON) {
  4137. var GUI;
  4138. (function (GUI) {
  4139. var ColorPicker = /** @class */ (function (_super) {
  4140. __extends(ColorPicker, _super);
  4141. function ColorPicker(name) {
  4142. var _this = _super.call(this, name) || this;
  4143. _this.name = name;
  4144. _this._value = BABYLON.Color3.Red();
  4145. _this._tmpColor = new BABYLON.Color3();
  4146. _this._pointerStartedOnSquare = false;
  4147. _this._pointerStartedOnWheel = false;
  4148. _this._squareLeft = 0;
  4149. _this._squareTop = 0;
  4150. _this._squareSize = 0;
  4151. _this._h = 360;
  4152. _this._s = 1;
  4153. _this._v = 1;
  4154. _this.onValueChangedObservable = new BABYLON.Observable();
  4155. // Events
  4156. _this._pointerIsDown = false;
  4157. _this.value = new BABYLON.Color3(.88, .1, .1);
  4158. _this.size = "200px";
  4159. _this.isPointerBlocker = true;
  4160. return _this;
  4161. }
  4162. Object.defineProperty(ColorPicker.prototype, "value", {
  4163. get: function () {
  4164. return this._value;
  4165. },
  4166. set: function (value) {
  4167. if (this._value.equals(value)) {
  4168. return;
  4169. }
  4170. this._value.copyFrom(value);
  4171. this._RGBtoHSV(this._value, this._tmpColor);
  4172. this._h = this._tmpColor.r;
  4173. this._s = Math.max(this._tmpColor.g, 0.00001);
  4174. this._v = Math.max(this._tmpColor.b, 0.00001);
  4175. this._markAsDirty();
  4176. this.onValueChangedObservable.notifyObservers(this._value);
  4177. },
  4178. enumerable: true,
  4179. configurable: true
  4180. });
  4181. Object.defineProperty(ColorPicker.prototype, "width", {
  4182. set: function (value) {
  4183. if (this._width.toString(this._host) === value) {
  4184. return;
  4185. }
  4186. if (this._width.fromString(value)) {
  4187. this._height.fromString(value);
  4188. this._markAsDirty();
  4189. }
  4190. },
  4191. enumerable: true,
  4192. configurable: true
  4193. });
  4194. Object.defineProperty(ColorPicker.prototype, "height", {
  4195. set: function (value) {
  4196. if (this._height.toString(this._host) === value) {
  4197. return;
  4198. }
  4199. if (this._height.fromString(value)) {
  4200. this._width.fromString(value);
  4201. this._markAsDirty();
  4202. }
  4203. },
  4204. enumerable: true,
  4205. configurable: true
  4206. });
  4207. Object.defineProperty(ColorPicker.prototype, "size", {
  4208. get: function () {
  4209. return this.width;
  4210. },
  4211. set: function (value) {
  4212. this.width = value;
  4213. },
  4214. enumerable: true,
  4215. configurable: true
  4216. });
  4217. ColorPicker.prototype._getTypeName = function () {
  4218. return "ColorPicker";
  4219. };
  4220. ColorPicker.prototype._updateSquareProps = function () {
  4221. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4222. var wheelThickness = radius * .2;
  4223. var innerDiameter = (radius - wheelThickness) * 2;
  4224. var squareSize = innerDiameter / (Math.sqrt(2));
  4225. var offset = radius - squareSize * .5;
  4226. this._squareLeft = this._currentMeasure.left + offset;
  4227. this._squareTop = this._currentMeasure.top + offset;
  4228. this._squareSize = squareSize;
  4229. };
  4230. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  4231. var lgh = context.createLinearGradient(left, top, width + left, top);
  4232. lgh.addColorStop(0, '#fff');
  4233. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  4234. context.fillStyle = lgh;
  4235. context.fillRect(left, top, width, height);
  4236. var lgv = context.createLinearGradient(left, top, left, height + top);
  4237. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  4238. lgv.addColorStop(1, '#000');
  4239. context.fillStyle = lgv;
  4240. context.fillRect(left, top, width, height);
  4241. };
  4242. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  4243. context.beginPath();
  4244. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  4245. context.lineWidth = 3;
  4246. context.strokeStyle = '#333333';
  4247. context.stroke();
  4248. context.beginPath();
  4249. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  4250. context.lineWidth = 3;
  4251. context.strokeStyle = '#ffffff';
  4252. context.stroke();
  4253. };
  4254. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  4255. var canvas = document.createElement("canvas");
  4256. canvas.width = radius * 2;
  4257. canvas.height = radius * 2;
  4258. var context = canvas.getContext("2d");
  4259. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  4260. var data = image.data;
  4261. var color = this._tmpColor;
  4262. var maxDistSq = radius * radius;
  4263. var innerRadius = radius - thickness;
  4264. var minDistSq = innerRadius * innerRadius;
  4265. for (var x = -radius; x < radius; x++) {
  4266. for (var y = -radius; y < radius; y++) {
  4267. var distSq = x * x + y * y;
  4268. if (distSq > maxDistSq || distSq < minDistSq) {
  4269. continue;
  4270. }
  4271. var dist = Math.sqrt(distSq);
  4272. var ang = Math.atan2(y, x);
  4273. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  4274. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  4275. data[index] = color.r * 255;
  4276. data[index + 1] = color.g * 255;
  4277. data[index + 2] = color.b * 255;
  4278. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  4279. //apply less alpha to bigger color pickers
  4280. var alphaAmount = .2;
  4281. var maxAlpha = .2;
  4282. var minAlpha = .04;
  4283. var lowerRadius = 50;
  4284. var upperRadius = 150;
  4285. if (radius < lowerRadius) {
  4286. alphaAmount = maxAlpha;
  4287. }
  4288. else if (radius > upperRadius) {
  4289. alphaAmount = minAlpha;
  4290. }
  4291. else {
  4292. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  4293. }
  4294. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  4295. if (alphaRatio < alphaAmount) {
  4296. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  4297. }
  4298. else if (alphaRatio > 1 - alphaAmount) {
  4299. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  4300. }
  4301. else {
  4302. data[index + 3] = 255;
  4303. }
  4304. }
  4305. }
  4306. context.putImageData(image, 0, 0);
  4307. return canvas;
  4308. };
  4309. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  4310. var r = color.r;
  4311. var g = color.g;
  4312. var b = color.b;
  4313. var max = Math.max(r, g, b);
  4314. var min = Math.min(r, g, b);
  4315. var h = 0;
  4316. var s = 0;
  4317. var v = max;
  4318. var dm = max - min;
  4319. if (max !== 0) {
  4320. s = dm / max;
  4321. }
  4322. if (max != min) {
  4323. if (max == r) {
  4324. h = (g - b) / dm;
  4325. if (g < b) {
  4326. h += 6;
  4327. }
  4328. }
  4329. else if (max == g) {
  4330. h = (b - r) / dm + 2;
  4331. }
  4332. else if (max == b) {
  4333. h = (r - g) / dm + 4;
  4334. }
  4335. h *= 60;
  4336. }
  4337. result.r = h;
  4338. result.g = s;
  4339. result.b = v;
  4340. };
  4341. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  4342. var chroma = value * saturation;
  4343. var h = hue / 60;
  4344. var x = chroma * (1 - Math.abs((h % 2) - 1));
  4345. var r = 0;
  4346. var g = 0;
  4347. var b = 0;
  4348. if (h >= 0 && h <= 1) {
  4349. r = chroma;
  4350. g = x;
  4351. }
  4352. else if (h >= 1 && h <= 2) {
  4353. r = x;
  4354. g = chroma;
  4355. }
  4356. else if (h >= 2 && h <= 3) {
  4357. g = chroma;
  4358. b = x;
  4359. }
  4360. else if (h >= 3 && h <= 4) {
  4361. g = x;
  4362. b = chroma;
  4363. }
  4364. else if (h >= 4 && h <= 5) {
  4365. r = x;
  4366. b = chroma;
  4367. }
  4368. else if (h >= 5 && h <= 6) {
  4369. r = chroma;
  4370. b = x;
  4371. }
  4372. var m = value - chroma;
  4373. result.set((r + m), (g + m), (b + m));
  4374. };
  4375. ColorPicker.prototype._draw = function (parentMeasure, context) {
  4376. context.save();
  4377. this._applyStates(context);
  4378. if (this._processMeasures(parentMeasure, context)) {
  4379. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4380. var wheelThickness = radius * .2;
  4381. var left = this._currentMeasure.left;
  4382. var top = this._currentMeasure.top;
  4383. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  4384. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  4385. }
  4386. this._updateSquareProps();
  4387. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4388. context.shadowColor = this.shadowColor;
  4389. context.shadowBlur = this.shadowBlur;
  4390. context.shadowOffsetX = this.shadowOffsetX;
  4391. context.shadowOffsetY = this.shadowOffsetY;
  4392. context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
  4393. }
  4394. context.drawImage(this._colorWheelCanvas, left, top);
  4395. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4396. context.shadowBlur = 0;
  4397. context.shadowOffsetX = 0;
  4398. context.shadowOffsetY = 0;
  4399. }
  4400. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  4401. var cx = this._squareLeft + this._squareSize * this._s;
  4402. var cy = this._squareTop + this._squareSize * (1 - this._v);
  4403. this._drawCircle(cx, cy, radius * .04, context);
  4404. var dist = radius - wheelThickness * .5;
  4405. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  4406. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  4407. this._drawCircle(cx, cy, wheelThickness * .35, context);
  4408. }
  4409. context.restore();
  4410. };
  4411. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  4412. if (this._pointerStartedOnWheel) {
  4413. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4414. var centerX = radius + this._currentMeasure.left;
  4415. var centerY = radius + this._currentMeasure.top;
  4416. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  4417. }
  4418. else if (this._pointerStartedOnSquare) {
  4419. this._updateSquareProps();
  4420. this._s = (x - this._squareLeft) / this._squareSize;
  4421. this._v = 1 - (y - this._squareTop) / this._squareSize;
  4422. this._s = Math.min(this._s, 1);
  4423. this._s = Math.max(this._s, 0.00001);
  4424. this._v = Math.min(this._v, 1);
  4425. this._v = Math.max(this._v, 0.00001);
  4426. }
  4427. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  4428. this.value = this._tmpColor;
  4429. };
  4430. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  4431. this._updateSquareProps();
  4432. var left = this._squareLeft;
  4433. var top = this._squareTop;
  4434. var size = this._squareSize;
  4435. if (coordinates.x >= left && coordinates.x <= left + size &&
  4436. coordinates.y >= top && coordinates.y <= top + size) {
  4437. return true;
  4438. }
  4439. return false;
  4440. };
  4441. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  4442. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4443. var centerX = radius + this._currentMeasure.left;
  4444. var centerY = radius + this._currentMeasure.top;
  4445. var wheelThickness = radius * .2;
  4446. var innerRadius = radius - wheelThickness;
  4447. var radiusSq = radius * radius;
  4448. var innerRadiusSq = innerRadius * innerRadius;
  4449. var dx = coordinates.x - centerX;
  4450. var dy = coordinates.y - centerY;
  4451. var distSq = dx * dx + dy * dy;
  4452. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  4453. return true;
  4454. }
  4455. return false;
  4456. };
  4457. ColorPicker.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4458. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4459. return false;
  4460. }
  4461. this._pointerIsDown = true;
  4462. this._pointerStartedOnSquare = false;
  4463. this._pointerStartedOnWheel = false;
  4464. if (this._isPointOnSquare(coordinates)) {
  4465. this._pointerStartedOnSquare = true;
  4466. }
  4467. else if (this._isPointOnWheel(coordinates)) {
  4468. this._pointerStartedOnWheel = true;
  4469. }
  4470. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4471. this._host._capturingControl[pointerId] = this;
  4472. return true;
  4473. };
  4474. ColorPicker.prototype._onPointerMove = function (target, coordinates) {
  4475. if (this._pointerIsDown) {
  4476. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4477. }
  4478. _super.prototype._onPointerMove.call(this, target, coordinates);
  4479. };
  4480. ColorPicker.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  4481. this._pointerIsDown = false;
  4482. delete this._host._capturingControl[pointerId];
  4483. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  4484. };
  4485. return ColorPicker;
  4486. }(GUI.Control));
  4487. GUI.ColorPicker = ColorPicker;
  4488. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4489. })(BABYLON || (BABYLON = {}));
  4490. "use strict";
  4491. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4492. var BABYLON;
  4493. (function (BABYLON) {
  4494. var GUI;
  4495. (function (GUI) {
  4496. var InputText = /** @class */ (function (_super) {
  4497. __extends(InputText, _super);
  4498. function InputText(name, text) {
  4499. if (text === void 0) { text = ""; }
  4500. var _this = _super.call(this, name) || this;
  4501. _this.name = name;
  4502. _this._text = "";
  4503. _this._placeholderText = "";
  4504. _this._background = "#222222";
  4505. _this._focusedBackground = "#000000";
  4506. _this._placeholderColor = "gray";
  4507. _this._thickness = 1;
  4508. _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
  4509. _this._autoStretchWidth = true;
  4510. _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  4511. _this._isFocused = false;
  4512. _this._blinkIsEven = false;
  4513. _this._cursorOffset = 0;
  4514. _this.promptMessage = "Please enter text:";
  4515. _this.onTextChangedObservable = new BABYLON.Observable();
  4516. _this.onFocusObservable = new BABYLON.Observable();
  4517. _this.onBlurObservable = new BABYLON.Observable();
  4518. _this.text = text;
  4519. return _this;
  4520. }
  4521. Object.defineProperty(InputText.prototype, "maxWidth", {
  4522. get: function () {
  4523. return this._maxWidth.toString(this._host);
  4524. },
  4525. set: function (value) {
  4526. if (this._maxWidth.toString(this._host) === value) {
  4527. return;
  4528. }
  4529. if (this._maxWidth.fromString(value)) {
  4530. this._markAsDirty();
  4531. }
  4532. },
  4533. enumerable: true,
  4534. configurable: true
  4535. });
  4536. Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
  4537. get: function () {
  4538. return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4539. },
  4540. enumerable: true,
  4541. configurable: true
  4542. });
  4543. Object.defineProperty(InputText.prototype, "margin", {
  4544. get: function () {
  4545. return this._margin.toString(this._host);
  4546. },
  4547. set: function (value) {
  4548. if (this._margin.toString(this._host) === value) {
  4549. return;
  4550. }
  4551. if (this._margin.fromString(value)) {
  4552. this._markAsDirty();
  4553. }
  4554. },
  4555. enumerable: true,
  4556. configurable: true
  4557. });
  4558. Object.defineProperty(InputText.prototype, "marginInPixels", {
  4559. get: function () {
  4560. return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4561. },
  4562. enumerable: true,
  4563. configurable: true
  4564. });
  4565. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  4566. get: function () {
  4567. return this._autoStretchWidth;
  4568. },
  4569. set: function (value) {
  4570. if (this._autoStretchWidth === value) {
  4571. return;
  4572. }
  4573. this._autoStretchWidth = value;
  4574. this._markAsDirty();
  4575. },
  4576. enumerable: true,
  4577. configurable: true
  4578. });
  4579. Object.defineProperty(InputText.prototype, "thickness", {
  4580. get: function () {
  4581. return this._thickness;
  4582. },
  4583. set: function (value) {
  4584. if (this._thickness === value) {
  4585. return;
  4586. }
  4587. this._thickness = value;
  4588. this._markAsDirty();
  4589. },
  4590. enumerable: true,
  4591. configurable: true
  4592. });
  4593. Object.defineProperty(InputText.prototype, "focusedBackground", {
  4594. get: function () {
  4595. return this._focusedBackground;
  4596. },
  4597. set: function (value) {
  4598. if (this._focusedBackground === value) {
  4599. return;
  4600. }
  4601. this._focusedBackground = value;
  4602. this._markAsDirty();
  4603. },
  4604. enumerable: true,
  4605. configurable: true
  4606. });
  4607. Object.defineProperty(InputText.prototype, "background", {
  4608. get: function () {
  4609. return this._background;
  4610. },
  4611. set: function (value) {
  4612. if (this._background === value) {
  4613. return;
  4614. }
  4615. this._background = value;
  4616. this._markAsDirty();
  4617. },
  4618. enumerable: true,
  4619. configurable: true
  4620. });
  4621. Object.defineProperty(InputText.prototype, "placeholderColor", {
  4622. get: function () {
  4623. return this._placeholderColor;
  4624. },
  4625. set: function (value) {
  4626. if (this._placeholderColor === value) {
  4627. return;
  4628. }
  4629. this._placeholderColor = value;
  4630. this._markAsDirty();
  4631. },
  4632. enumerable: true,
  4633. configurable: true
  4634. });
  4635. Object.defineProperty(InputText.prototype, "placeholderText", {
  4636. get: function () {
  4637. return this._placeholderText;
  4638. },
  4639. set: function (value) {
  4640. if (this._placeholderText === value) {
  4641. return;
  4642. }
  4643. this._placeholderText = value;
  4644. this._markAsDirty();
  4645. },
  4646. enumerable: true,
  4647. configurable: true
  4648. });
  4649. Object.defineProperty(InputText.prototype, "text", {
  4650. get: function () {
  4651. return this._text;
  4652. },
  4653. set: function (value) {
  4654. if (this._text === value) {
  4655. return;
  4656. }
  4657. this._text = value;
  4658. this._markAsDirty();
  4659. this.onTextChangedObservable.notifyObservers(this);
  4660. },
  4661. enumerable: true,
  4662. configurable: true
  4663. });
  4664. Object.defineProperty(InputText.prototype, "width", {
  4665. get: function () {
  4666. return this._width.toString(this._host);
  4667. },
  4668. set: function (value) {
  4669. if (this._width.toString(this._host) === value) {
  4670. return;
  4671. }
  4672. if (this._width.fromString(value)) {
  4673. this._markAsDirty();
  4674. }
  4675. this.autoStretchWidth = false;
  4676. },
  4677. enumerable: true,
  4678. configurable: true
  4679. });
  4680. InputText.prototype.onBlur = function () {
  4681. this._isFocused = false;
  4682. this._scrollLeft = null;
  4683. this._cursorOffset = 0;
  4684. clearTimeout(this._blinkTimeout);
  4685. this._markAsDirty();
  4686. this.onBlurObservable.notifyObservers(this);
  4687. };
  4688. InputText.prototype.onFocus = function () {
  4689. this._scrollLeft = null;
  4690. this._isFocused = true;
  4691. this._blinkIsEven = false;
  4692. this._cursorOffset = 0;
  4693. this._markAsDirty();
  4694. this.onFocusObservable.notifyObservers(this);
  4695. if (navigator.userAgent.indexOf("Mobile") !== -1) {
  4696. var value = prompt(this.promptMessage);
  4697. if (value !== null) {
  4698. this.text = value;
  4699. }
  4700. this._host.focusedControl = null;
  4701. return;
  4702. }
  4703. };
  4704. InputText.prototype._getTypeName = function () {
  4705. return "InputText";
  4706. };
  4707. InputText.prototype.processKey = function (keyCode, key) {
  4708. // Specific cases
  4709. switch (keyCode) {
  4710. case 32://SPACE
  4711. key = " "; //ie11 key for space is "Spacebar"
  4712. break;
  4713. case 8:// BACKSPACE
  4714. if (this._text && this._text.length > 0) {
  4715. if (this._cursorOffset === 0) {
  4716. this.text = this._text.substr(0, this._text.length - 1);
  4717. }
  4718. else {
  4719. var deletePosition = this._text.length - this._cursorOffset;
  4720. if (deletePosition > 0) {
  4721. this.text = this._text.slice(0, deletePosition - 1) + this._text.slice(deletePosition);
  4722. }
  4723. }
  4724. }
  4725. return;
  4726. case 46:// DELETE
  4727. if (this._text && this._text.length > 0) {
  4728. var deletePosition = this._text.length - this._cursorOffset;
  4729. this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
  4730. this._cursorOffset--;
  4731. }
  4732. return;
  4733. case 13:// RETURN
  4734. this._host.focusedControl = null;
  4735. return;
  4736. case 35:// END
  4737. this._cursorOffset = 0;
  4738. this._blinkIsEven = false;
  4739. this._markAsDirty();
  4740. return;
  4741. case 36:// HOME
  4742. this._cursorOffset = this._text.length;
  4743. this._blinkIsEven = false;
  4744. this._markAsDirty();
  4745. return;
  4746. case 37:// LEFT
  4747. this._cursorOffset++;
  4748. if (this._cursorOffset > this._text.length) {
  4749. this._cursorOffset = this._text.length;
  4750. }
  4751. this._blinkIsEven = false;
  4752. this._markAsDirty();
  4753. return;
  4754. case 39:// RIGHT
  4755. this._cursorOffset--;
  4756. if (this._cursorOffset < 0) {
  4757. this._cursorOffset = 0;
  4758. }
  4759. this._blinkIsEven = false;
  4760. this._markAsDirty();
  4761. return;
  4762. }
  4763. // Printable characters
  4764. if ((keyCode === -1) || // Direct access
  4765. (keyCode === 32) || // Space
  4766. (keyCode > 47 && keyCode < 58) || // Numbers
  4767. (keyCode > 64 && keyCode < 91) || // Letters
  4768. (keyCode > 185 && keyCode < 193) || // Special characters
  4769. (keyCode > 218 && keyCode < 223) || // Special characters
  4770. (keyCode > 95 && keyCode < 112)) {
  4771. if (this._cursorOffset === 0) {
  4772. this.text += key;
  4773. }
  4774. else {
  4775. var insertPosition = this._text.length - this._cursorOffset;
  4776. this.text = this._text.slice(0, insertPosition) + key + this._text.slice(insertPosition);
  4777. }
  4778. }
  4779. };
  4780. InputText.prototype.processKeyboard = function (evt) {
  4781. this.processKey(evt.keyCode, evt.key);
  4782. };
  4783. InputText.prototype._draw = function (parentMeasure, context) {
  4784. var _this = this;
  4785. context.save();
  4786. this._applyStates(context);
  4787. if (this._processMeasures(parentMeasure, context)) {
  4788. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4789. context.shadowColor = this.shadowColor;
  4790. context.shadowBlur = this.shadowBlur;
  4791. context.shadowOffsetX = this.shadowOffsetX;
  4792. context.shadowOffsetY = this.shadowOffsetY;
  4793. }
  4794. // Background
  4795. if (this._isFocused) {
  4796. if (this._focusedBackground) {
  4797. context.fillStyle = this._focusedBackground;
  4798. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4799. }
  4800. }
  4801. else if (this._background) {
  4802. context.fillStyle = this._background;
  4803. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4804. }
  4805. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4806. context.shadowBlur = 0;
  4807. context.shadowOffsetX = 0;
  4808. context.shadowOffsetY = 0;
  4809. }
  4810. if (!this._fontOffset) {
  4811. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  4812. }
  4813. // Text
  4814. var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width);
  4815. if (this.color) {
  4816. context.fillStyle = this.color;
  4817. }
  4818. var text = this._text;
  4819. if (!this._isFocused && !this._text && this._placeholderText) {
  4820. text = this._placeholderText;
  4821. if (this._placeholderColor) {
  4822. context.fillStyle = this._placeholderColor;
  4823. }
  4824. }
  4825. this._textWidth = context.measureText(text).width;
  4826. var marginWidth = this._margin.getValueInPixel(this._host, parentMeasure.width) * 2;
  4827. if (this._autoStretchWidth) {
  4828. this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), this._textWidth + marginWidth) + "px";
  4829. }
  4830. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  4831. var availableWidth = this._width.getValueInPixel(this._host, parentMeasure.width) - marginWidth;
  4832. context.save();
  4833. context.beginPath();
  4834. context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
  4835. context.clip();
  4836. if (this._isFocused && this._textWidth > availableWidth) {
  4837. var textLeft = clipTextLeft - this._textWidth + availableWidth;
  4838. if (!this._scrollLeft) {
  4839. this._scrollLeft = textLeft;
  4840. }
  4841. }
  4842. else {
  4843. this._scrollLeft = clipTextLeft;
  4844. }
  4845. context.fillText(text, this._scrollLeft, this._currentMeasure.top + rootY);
  4846. // Cursor
  4847. if (this._isFocused) {
  4848. // Need to move cursor
  4849. if (this._clickedCoordinate) {
  4850. var rightPosition = this._scrollLeft + this._textWidth;
  4851. var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
  4852. var currentSize = 0;
  4853. this._cursorOffset = 0;
  4854. var previousDist = 0;
  4855. do {
  4856. if (this._cursorOffset) {
  4857. previousDist = Math.abs(absoluteCursorPosition - currentSize);
  4858. }
  4859. this._cursorOffset++;
  4860. currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
  4861. } while (currentSize < absoluteCursorPosition && (text.length >= this._cursorOffset));
  4862. // Find closest move
  4863. if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
  4864. this._cursorOffset--;
  4865. }
  4866. this._blinkIsEven = false;
  4867. this._clickedCoordinate = null;
  4868. }
  4869. // Render cursor
  4870. if (!this._blinkIsEven) {
  4871. var cursorOffsetText = this.text.substr(this._text.length - this._cursorOffset);
  4872. var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
  4873. var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
  4874. if (cursorLeft < clipTextLeft) {
  4875. this._scrollLeft += (clipTextLeft - cursorLeft);
  4876. cursorLeft = clipTextLeft;
  4877. this._markAsDirty();
  4878. }
  4879. else if (cursorLeft > clipTextLeft + availableWidth) {
  4880. this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
  4881. cursorLeft = clipTextLeft + availableWidth;
  4882. this._markAsDirty();
  4883. }
  4884. context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
  4885. }
  4886. clearTimeout(this._blinkTimeout);
  4887. this._blinkTimeout = setTimeout(function () {
  4888. _this._blinkIsEven = !_this._blinkIsEven;
  4889. _this._markAsDirty();
  4890. }, 500);
  4891. }
  4892. context.restore();
  4893. // Border
  4894. if (this._thickness) {
  4895. if (this.color) {
  4896. context.strokeStyle = this.color;
  4897. }
  4898. context.lineWidth = this._thickness;
  4899. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  4900. }
  4901. }
  4902. context.restore();
  4903. };
  4904. InputText.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4905. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4906. return false;
  4907. }
  4908. this._clickedCoordinate = coordinates.x;
  4909. if (this._host.focusedControl === this) {
  4910. // Move cursor
  4911. clearTimeout(this._blinkTimeout);
  4912. this._markAsDirty();
  4913. return true;
  4914. }
  4915. this._host.focusedControl = this;
  4916. return true;
  4917. };
  4918. InputText.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  4919. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  4920. };
  4921. InputText.prototype.dispose = function () {
  4922. _super.prototype.dispose.call(this);
  4923. this.onBlurObservable.clear();
  4924. this.onFocusObservable.clear();
  4925. this.onTextChangedObservable.clear();
  4926. };
  4927. return InputText;
  4928. }(GUI.Control));
  4929. GUI.InputText = InputText;
  4930. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4931. })(BABYLON || (BABYLON = {}));
  4932. "use strict";
  4933. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  4934. var BABYLON;
  4935. (function (BABYLON) {
  4936. var GUI;
  4937. (function (GUI) {
  4938. var KeyPropertySet = /** @class */ (function () {
  4939. function KeyPropertySet() {
  4940. }
  4941. return KeyPropertySet;
  4942. }());
  4943. GUI.KeyPropertySet = KeyPropertySet;
  4944. var VirtualKeyboard = /** @class */ (function (_super) {
  4945. __extends(VirtualKeyboard, _super);
  4946. function VirtualKeyboard() {
  4947. var _this = _super !== null && _super.apply(this, arguments) || this;
  4948. _this.onKeyPressObservable = new BABYLON.Observable();
  4949. _this.defaultButtonWidth = "40px";
  4950. _this.defaultButtonHeight = "40px";
  4951. _this.defaultButtonPaddingLeft = "2px";
  4952. _this.defaultButtonPaddingRight = "2px";
  4953. _this.defaultButtonPaddingTop = "2px";
  4954. _this.defaultButtonPaddingBottom = "2px";
  4955. _this.defaultButtonColor = "#DDD";
  4956. _this.defaultButtonBackground = "#070707";
  4957. _this.shiftButtonColor = "#7799FF";
  4958. _this.selectedShiftThickness = 1;
  4959. _this.shiftState = 0;
  4960. return _this;
  4961. }
  4962. VirtualKeyboard.prototype._getTypeName = function () {
  4963. return "VirtualKeyboard";
  4964. };
  4965. VirtualKeyboard.prototype._createKey = function (key, propertySet) {
  4966. var _this = this;
  4967. var button = GUI.Button.CreateSimpleButton(key, key);
  4968. button.width = propertySet && propertySet.width ? propertySet.width : this.defaultButtonWidth;
  4969. button.height = propertySet && propertySet.height ? propertySet.height : this.defaultButtonHeight;
  4970. button.color = propertySet && propertySet.color ? propertySet.color : this.defaultButtonColor;
  4971. button.background = propertySet && propertySet.background ? propertySet.background : this.defaultButtonBackground;
  4972. button.paddingLeft = propertySet && propertySet.paddingLeft ? propertySet.paddingLeft : this.defaultButtonPaddingLeft;
  4973. button.paddingRight = propertySet && propertySet.paddingRight ? propertySet.paddingRight : this.defaultButtonPaddingRight;
  4974. button.paddingTop = propertySet && propertySet.paddingTop ? propertySet.paddingTop : this.defaultButtonPaddingTop;
  4975. button.paddingBottom = propertySet && propertySet.paddingBottom ? propertySet.paddingBottom : this.defaultButtonPaddingBottom;
  4976. button.thickness = 0;
  4977. button.isFocusInvisible = true;
  4978. button.shadowColor = this.shadowColor;
  4979. button.shadowBlur = this.shadowBlur;
  4980. button.shadowOffsetX = this.shadowOffsetX;
  4981. button.shadowOffsetY = this.shadowOffsetY;
  4982. button.onPointerUpObservable.add(function () {
  4983. _this.onKeyPressObservable.notifyObservers(key);
  4984. });
  4985. return button;
  4986. };
  4987. VirtualKeyboard.prototype.addKeysRow = function (keys, propertySets) {
  4988. var panel = new GUI.StackPanel();
  4989. panel.isVertical = false;
  4990. panel.isFocusInvisible = true;
  4991. for (var i = 0; i < keys.length; i++) {
  4992. var properties = null;
  4993. if (propertySets && propertySets.length === keys.length) {
  4994. properties = propertySets[i];
  4995. }
  4996. panel.addControl(this._createKey(keys[i], properties));
  4997. }
  4998. this.addControl(panel);
  4999. };
  5000. VirtualKeyboard.prototype.applyShiftState = function (shiftState) {
  5001. if (!this.children) {
  5002. return;
  5003. }
  5004. for (var i = 0; i < this.children.length; i++) {
  5005. var row = this.children[i];
  5006. if (!row || !row.children) {
  5007. continue;
  5008. }
  5009. var rowContainer = row;
  5010. for (var j = 0; j < rowContainer.children.length; j++) {
  5011. var button = rowContainer.children[j];
  5012. if (!button || !button.children[0]) {
  5013. continue;
  5014. }
  5015. var button_tblock = button.children[0];
  5016. if (button_tblock.text === "\u21E7") {
  5017. button.color = (shiftState ? this.shiftButtonColor : this.defaultButtonColor);
  5018. button.thickness = (shiftState > 1 ? this.selectedShiftThickness : 0);
  5019. }
  5020. button_tblock.text = (shiftState > 0 ? button_tblock.text.toUpperCase() : button_tblock.text.toLowerCase());
  5021. }
  5022. }
  5023. };
  5024. Object.defineProperty(VirtualKeyboard.prototype, "connectedInputText", {
  5025. get: function () {
  5026. return this._connectedInputText;
  5027. },
  5028. enumerable: true,
  5029. configurable: true
  5030. });
  5031. VirtualKeyboard.prototype.connect = function (input) {
  5032. var _this = this;
  5033. this.isVisible = false;
  5034. this._connectedInputText = input;
  5035. // Events hooking
  5036. this._onFocusObserver = input.onFocusObservable.add(function () {
  5037. _this.isVisible = true;
  5038. });
  5039. this._onBlurObserver = input.onBlurObservable.add(function () {
  5040. _this.isVisible = false;
  5041. });
  5042. this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
  5043. if (!_this._connectedInputText) {
  5044. return;
  5045. }
  5046. switch (key) {
  5047. case "\u21E7":
  5048. _this.shiftState++;
  5049. if (_this.shiftState > 2) {
  5050. _this.shiftState = 0;
  5051. }
  5052. _this.applyShiftState(_this.shiftState);
  5053. return;
  5054. case "\u2190":
  5055. _this._connectedInputText.processKey(8);
  5056. return;
  5057. case "\u21B5":
  5058. _this._connectedInputText.processKey(13);
  5059. return;
  5060. }
  5061. _this._connectedInputText.processKey(-1, (_this.shiftState ? key.toUpperCase() : key));
  5062. if (_this.shiftState === 1) {
  5063. _this.shiftState = 0;
  5064. _this.applyShiftState(_this.shiftState);
  5065. }
  5066. });
  5067. };
  5068. VirtualKeyboard.prototype.disconnect = function () {
  5069. if (!this._connectedInputText) {
  5070. return;
  5071. }
  5072. this._connectedInputText.onFocusObservable.remove(this._onFocusObserver);
  5073. this._connectedInputText.onBlurObservable.remove(this._onBlurObserver);
  5074. this.onKeyPressObservable.remove(this._onKeyPressObserver);
  5075. this._connectedInputText = null;
  5076. };
  5077. // Statics
  5078. VirtualKeyboard.CreateDefaultLayout = function () {
  5079. var returnValue = new VirtualKeyboard();
  5080. returnValue.addKeysRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u2190"]);
  5081. returnValue.addKeysRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]);
  5082. returnValue.addKeysRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\u21B5"]);
  5083. returnValue.addKeysRow(["\u21E7", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]);
  5084. returnValue.addKeysRow([" "], [{ width: "200px" }]);
  5085. return returnValue;
  5086. };
  5087. return VirtualKeyboard;
  5088. }(GUI.StackPanel));
  5089. GUI.VirtualKeyboard = VirtualKeyboard;
  5090. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5091. })(BABYLON || (BABYLON = {}));
  5092. return BABYLON.GUI;
  5093. });