babylon.gui.js 228 KB

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