babylon.gui.js 354 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032
  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. BABYLON.Effect.ShadersStore['fluentVertexShader'] = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n\nuniform mat4 world;\nuniform mat4 viewProjection;\nvarying vec2 vUV;\n#ifdef BORDER\nvarying vec2 scaleInfo;\nuniform float borderWidth;\nuniform vec3 scaleFactor;\n#endif\n#ifdef HOVERLIGHT\nvarying vec3 worldPosition;\n#endif\nvoid main(void) {\nvUV=uv;\n#ifdef BORDER\nvec3 scale=scaleFactor;\nfloat minScale=min(min(scale.x,scale.y),scale.z);\nfloat maxScale=max(max(scale.x,scale.y),scale.z);\nfloat minOverMiddleScale=minScale/(scale.x+scale.y+scale.z-minScale-maxScale);\nfloat areaYZ=scale.y*scale.z;\nfloat areaXZ=scale.x*scale.z;\nfloat areaXY=scale.x*scale.y;\nfloat scaledBorderWidth=borderWidth; \nif (abs(normal.x) == 1.0) \n{\nscale.x=scale.y;\nscale.y=scale.z;\nif (areaYZ>areaXZ && areaYZ>areaXY)\n{\nscaledBorderWidth*=minOverMiddleScale;\n}\n}\nelse if (abs(normal.y) == 1.0) \n{\nscale.x=scale.z;\nif (areaXZ>areaXY && areaXZ>areaYZ)\n{\nscaledBorderWidth*=minOverMiddleScale;\n}\n}\nelse \n{\nif (areaXY>areaYZ && areaXY>areaXZ)\n{\nscaledBorderWidth*=minOverMiddleScale;\n}\n}\nfloat scaleRatio=min(scale.x,scale.y)/max(scale.x,scale.y);\nif (scale.x>scale.y)\n{\nscaleInfo.x=1.0-(scaledBorderWidth*scaleRatio);\nscaleInfo.y=1.0-scaledBorderWidth;\n}\nelse\n{\nscaleInfo.x=1.0-scaledBorderWidth;\nscaleInfo.y=1.0-(scaledBorderWidth*scaleRatio);\n} \n#endif \nvec4 worldPos=world*vec4(position,1.0);\n#ifdef HOVERLIGHT\nworldPosition=worldPos.xyz;\n#endif\ngl_Position=viewProjection*worldPos;\n}\n";
  21. BABYLON.Effect.ShadersStore['fluentPixelShader'] = "precision highp float;\nvarying vec2 vUV;\nuniform vec4 albedoColor;\n#ifdef INNERGLOW\nuniform vec4 innerGlowColor;\n#endif\n#ifdef BORDER\nvarying vec2 scaleInfo;\nuniform float edgeSmoothingValue;\nuniform float borderMinValue;\n#endif\n#ifdef HOVERLIGHT\nvarying vec3 worldPosition;\nuniform vec3 hoverPosition;\nuniform vec4 hoverColor;\nuniform float hoverRadius;\n#endif\nvoid main(void) {\nvec3 albedo=albedoColor.rgb;\nfloat alpha=albedoColor.a;\n#ifdef HOVERLIGHT\nfloat pointToHover=(1.0-clamp(length(hoverPosition-worldPosition)/hoverRadius,0.,1.))*hoverColor.a;\nalbedo=clamp(albedo+hoverColor.rgb*pointToHover,0.,1.);\n#else\nfloat pointToHover=1.0;\n#endif\n#ifdef BORDER \nfloat borderPower=10.0;\nfloat inverseBorderPower=1.0/borderPower;\nvec3 borderColor=albedo*borderPower;\nvec2 distanceToEdge;\ndistanceToEdge.x=abs(vUV.x-0.5)*2.0;\ndistanceToEdge.y=abs(vUV.y-0.5)*2.0;\nfloat borderValue=max(smoothstep(scaleInfo.x-edgeSmoothingValue,scaleInfo.x+edgeSmoothingValue,distanceToEdge.x),\nsmoothstep(scaleInfo.y-edgeSmoothingValue,scaleInfo.y+edgeSmoothingValue,distanceToEdge.y));\nborderColor=borderColor*borderValue*max(borderMinValue*inverseBorderPower,pointToHover); \nalbedo+=borderColor;\nalpha=max(alpha,borderValue);\n#endif\n#ifdef INNERGLOW\n\nvec2 uvGlow=(vUV-vec2(0.5,0.5))*(innerGlowColor.a*2.0);\nuvGlow=uvGlow*uvGlow;\nuvGlow=uvGlow*uvGlow;\nalbedo+=mix(vec3(0.0,0.0,0.0),innerGlowColor.rgb,uvGlow.x+uvGlow.y); \n#endif\ngl_FragColor=vec4(albedo,alpha);\n}";
  22. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  23. var BABYLON;
  24. (function (BABYLON) {
  25. var GUI;
  26. (function (GUI) {
  27. /**
  28. * Define a style used by control to automatically setup properties based on a template.
  29. * Only support font related properties so far
  30. */
  31. var Style = /** @class */ (function () {
  32. /**
  33. * Creates a new style object
  34. * @param host defines the AdvancedDynamicTexture which hosts this style
  35. */
  36. function Style(host) {
  37. this._fontFamily = "Arial";
  38. this._fontStyle = "";
  39. this._fontWeight = "";
  40. /** @hidden */
  41. this._fontSize = new GUI.ValueAndUnit(18, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  42. /**
  43. * Observable raised when the style values are changed
  44. */
  45. this.onChangedObservable = new BABYLON.Observable();
  46. this._host = host;
  47. }
  48. Object.defineProperty(Style.prototype, "fontSize", {
  49. /**
  50. * Gets or sets the font size
  51. */
  52. get: function () {
  53. return this._fontSize.toString(this._host);
  54. },
  55. set: function (value) {
  56. if (this._fontSize.toString(this._host) === value) {
  57. return;
  58. }
  59. if (this._fontSize.fromString(value)) {
  60. this.onChangedObservable.notifyObservers(this);
  61. }
  62. },
  63. enumerable: true,
  64. configurable: true
  65. });
  66. Object.defineProperty(Style.prototype, "fontFamily", {
  67. /**
  68. * Gets or sets the font family
  69. */
  70. get: function () {
  71. return this._fontFamily;
  72. },
  73. set: function (value) {
  74. if (this._fontFamily === value) {
  75. return;
  76. }
  77. this._fontFamily = value;
  78. this.onChangedObservable.notifyObservers(this);
  79. },
  80. enumerable: true,
  81. configurable: true
  82. });
  83. Object.defineProperty(Style.prototype, "fontStyle", {
  84. /**
  85. * Gets or sets the font style
  86. */
  87. get: function () {
  88. return this._fontStyle;
  89. },
  90. set: function (value) {
  91. if (this._fontStyle === value) {
  92. return;
  93. }
  94. this._fontStyle = value;
  95. this.onChangedObservable.notifyObservers(this);
  96. },
  97. enumerable: true,
  98. configurable: true
  99. });
  100. Object.defineProperty(Style.prototype, "fontWeight", {
  101. /** Gets or sets font weight */
  102. get: function () {
  103. return this._fontWeight;
  104. },
  105. set: function (value) {
  106. if (this._fontWeight === value) {
  107. return;
  108. }
  109. this._fontWeight = value;
  110. this.onChangedObservable.notifyObservers(this);
  111. },
  112. enumerable: true,
  113. configurable: true
  114. });
  115. /** Dispose all associated resources */
  116. Style.prototype.dispose = function () {
  117. this.onChangedObservable.clear();
  118. };
  119. return Style;
  120. }());
  121. GUI.Style = Style;
  122. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  123. })(BABYLON || (BABYLON = {}));
  124. //# sourceMappingURL=style.js.map
  125. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  126. var BABYLON;
  127. (function (BABYLON) {
  128. var GUI;
  129. (function (GUI) {
  130. /**
  131. * Class used to specific a value and its associated unit
  132. */
  133. var ValueAndUnit = /** @class */ (function () {
  134. /**
  135. * Creates a new ValueAndUnit
  136. * @param value defines the value to store
  137. * @param unit defines the unit to store
  138. * @param negativeValueAllowed defines a boolean indicating if the value can be negative
  139. */
  140. function ValueAndUnit(value,
  141. /** defines the unit to store */
  142. unit,
  143. /** defines a boolean indicating if the value can be negative */
  144. negativeValueAllowed) {
  145. if (unit === void 0) { unit = ValueAndUnit.UNITMODE_PIXEL; }
  146. if (negativeValueAllowed === void 0) { negativeValueAllowed = true; }
  147. this.unit = unit;
  148. this.negativeValueAllowed = negativeValueAllowed;
  149. this._value = 1;
  150. /**
  151. * Gets or sets a value indicating that this value will not scale accordingly with adaptive scaling property
  152. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  153. */
  154. this.ignoreAdaptiveScaling = false;
  155. this._value = value;
  156. }
  157. Object.defineProperty(ValueAndUnit.prototype, "isPercentage", {
  158. /** Gets a boolean indicating if the value is a percentage */
  159. get: function () {
  160. return this.unit === ValueAndUnit.UNITMODE_PERCENTAGE;
  161. },
  162. enumerable: true,
  163. configurable: true
  164. });
  165. Object.defineProperty(ValueAndUnit.prototype, "isPixel", {
  166. /** Gets a boolean indicating if the value is store as pixel */
  167. get: function () {
  168. return this.unit === ValueAndUnit.UNITMODE_PIXEL;
  169. },
  170. enumerable: true,
  171. configurable: true
  172. });
  173. Object.defineProperty(ValueAndUnit.prototype, "internalValue", {
  174. /** Gets direct internal value */
  175. get: function () {
  176. return this._value;
  177. },
  178. enumerable: true,
  179. configurable: true
  180. });
  181. /**
  182. * Gets value as pixel
  183. * @param host defines the root host
  184. * @param refValue defines the reference value for percentages
  185. * @returns the value as pixel
  186. */
  187. ValueAndUnit.prototype.getValueInPixel = function (host, refValue) {
  188. if (this.isPixel) {
  189. return this.getValue(host);
  190. }
  191. return this.getValue(host) * refValue;
  192. };
  193. /**
  194. * Gets the value accordingly to its unit
  195. * @param host defines the root host
  196. * @returns the value
  197. */
  198. ValueAndUnit.prototype.getValue = function (host) {
  199. if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
  200. var width = 0;
  201. var height = 0;
  202. if (host.idealWidth) {
  203. width = (this._value * host.getSize().width) / host.idealWidth;
  204. }
  205. if (host.idealHeight) {
  206. height = (this._value * host.getSize().height) / host.idealHeight;
  207. }
  208. if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) {
  209. return window.innerWidth < window.innerHeight ? width : height;
  210. }
  211. if (host.idealWidth) { // horizontal
  212. return width;
  213. }
  214. if (host.idealHeight) { // vertical
  215. return height;
  216. }
  217. }
  218. return this._value;
  219. };
  220. /**
  221. * Gets a string representation of the value
  222. * @param host defines the root host
  223. * @returns a string
  224. */
  225. ValueAndUnit.prototype.toString = function (host) {
  226. switch (this.unit) {
  227. case ValueAndUnit.UNITMODE_PERCENTAGE:
  228. return (this.getValue(host) * 100) + "%";
  229. case ValueAndUnit.UNITMODE_PIXEL:
  230. return this.getValue(host) + "px";
  231. }
  232. return this.unit.toString();
  233. };
  234. /**
  235. * Store a value parsed from a string
  236. * @param source defines the source string
  237. * @returns true if the value was successfully parsed
  238. */
  239. ValueAndUnit.prototype.fromString = function (source) {
  240. var match = ValueAndUnit._Regex.exec(source.toString());
  241. if (!match || match.length === 0) {
  242. return false;
  243. }
  244. var sourceValue = parseFloat(match[1]);
  245. var sourceUnit = this.unit;
  246. if (!this.negativeValueAllowed) {
  247. if (sourceValue < 0) {
  248. sourceValue = 0;
  249. }
  250. }
  251. if (match.length === 4) {
  252. switch (match[3]) {
  253. case "px":
  254. sourceUnit = ValueAndUnit.UNITMODE_PIXEL;
  255. break;
  256. case "%":
  257. sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;
  258. sourceValue /= 100.0;
  259. break;
  260. }
  261. }
  262. if (sourceValue === this._value && sourceUnit === this.unit) {
  263. return false;
  264. }
  265. this._value = sourceValue;
  266. this.unit = sourceUnit;
  267. return true;
  268. };
  269. Object.defineProperty(ValueAndUnit, "UNITMODE_PERCENTAGE", {
  270. /** UNITMODE_PERCENTAGE */
  271. get: function () {
  272. return ValueAndUnit._UNITMODE_PERCENTAGE;
  273. },
  274. enumerable: true,
  275. configurable: true
  276. });
  277. Object.defineProperty(ValueAndUnit, "UNITMODE_PIXEL", {
  278. /** UNITMODE_PIXEL */
  279. get: function () {
  280. return ValueAndUnit._UNITMODE_PIXEL;
  281. },
  282. enumerable: true,
  283. configurable: true
  284. });
  285. // Static
  286. ValueAndUnit._Regex = /(^-?\d*(\.\d+)?)(%|px)?/;
  287. ValueAndUnit._UNITMODE_PERCENTAGE = 0;
  288. ValueAndUnit._UNITMODE_PIXEL = 1;
  289. return ValueAndUnit;
  290. }());
  291. GUI.ValueAndUnit = ValueAndUnit;
  292. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  293. })(BABYLON || (BABYLON = {}));
  294. //# sourceMappingURL=valueAndUnit.js.map
  295. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  296. /**
  297. * This module hosts all controls for 2D and 3D GUIs
  298. * @see http://doc.babylonjs.com/how_to/gui
  299. */
  300. var BABYLON;
  301. (function (BABYLON) {
  302. var GUI;
  303. (function (GUI) {
  304. /**
  305. * Class used to create texture to support 2D GUI elements
  306. * @see http://doc.babylonjs.com/how_to/gui
  307. */
  308. var AdvancedDynamicTexture = /** @class */ (function (_super) {
  309. __extends(AdvancedDynamicTexture, _super);
  310. /**
  311. * Creates a new AdvancedDynamicTexture
  312. * @param name defines the name of the texture
  313. * @param width defines the width of the texture
  314. * @param height defines the height of the texture
  315. * @param scene defines the hosting scene
  316. * @param generateMipMaps defines a boolean indicating if mipmaps must be generated (false by default)
  317. * @param samplingMode defines the texture sampling mode (BABYLON.Texture.NEAREST_SAMPLINGMODE by default)
  318. */
  319. function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode) {
  320. if (width === void 0) { width = 0; }
  321. if (height === void 0) { height = 0; }
  322. if (generateMipMaps === void 0) { generateMipMaps = false; }
  323. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE; }
  324. var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, BABYLON.Engine.TEXTUREFORMAT_RGBA) || this;
  325. _this._isDirty = false;
  326. /** @hidden */
  327. _this._rootContainer = new GUI.Container("root");
  328. /** @hidden */
  329. _this._lastControlOver = {};
  330. /** @hidden */
  331. _this._lastControlDown = {};
  332. /** @hidden */
  333. _this._capturingControl = {};
  334. /** @hidden */
  335. _this._linkedControls = new Array();
  336. _this._isFullscreen = false;
  337. _this._fullscreenViewport = new BABYLON.Viewport(0, 0, 1, 1);
  338. _this._idealWidth = 0;
  339. _this._idealHeight = 0;
  340. _this._useSmallestIdeal = false;
  341. _this._renderAtIdealSize = false;
  342. _this._blockNextFocusCheck = false;
  343. _this._renderScale = 1;
  344. /**
  345. * Gets or sets a boolean defining if alpha is stored as premultiplied
  346. */
  347. _this.premulAlpha = false;
  348. scene = _this.getScene();
  349. if (!scene || !_this._texture) {
  350. return _this;
  351. }
  352. _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
  353. _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
  354. if (!_this._focusedControl) {
  355. return;
  356. }
  357. if (info.type === BABYLON.KeyboardEventTypes.KEYDOWN) {
  358. _this._focusedControl.processKeyboard(info.event);
  359. }
  360. info.skipOnPointerObservable = true;
  361. });
  362. _this._rootContainer._link(null, _this);
  363. _this.hasAlpha = true;
  364. if (!width || !height) {
  365. _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
  366. _this._onResize();
  367. }
  368. _this._texture.isReady = true;
  369. return _this;
  370. }
  371. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
  372. /**
  373. * Gets or sets a number used to scale rendering size (2 means that the texture will be twice bigger).
  374. * Useful when you want more antialiasing
  375. */
  376. get: function () {
  377. return this._renderScale;
  378. },
  379. set: function (value) {
  380. if (value === this._renderScale) {
  381. return;
  382. }
  383. this._renderScale = value;
  384. this._onResize();
  385. },
  386. enumerable: true,
  387. configurable: true
  388. });
  389. Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
  390. /** Gets or sets the background color */
  391. get: function () {
  392. return this._background;
  393. },
  394. set: function (value) {
  395. if (this._background === value) {
  396. return;
  397. }
  398. this._background = value;
  399. this.markAsDirty();
  400. },
  401. enumerable: true,
  402. configurable: true
  403. });
  404. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
  405. /**
  406. * Gets or sets the ideal width used to design controls.
  407. * The GUI will then rescale everything accordingly
  408. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  409. */
  410. get: function () {
  411. return this._idealWidth;
  412. },
  413. set: function (value) {
  414. if (this._idealWidth === value) {
  415. return;
  416. }
  417. this._idealWidth = value;
  418. this.markAsDirty();
  419. this._rootContainer._markAllAsDirty();
  420. },
  421. enumerable: true,
  422. configurable: true
  423. });
  424. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
  425. /**
  426. * Gets or sets the ideal height used to design controls.
  427. * The GUI will then rescale everything accordingly
  428. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  429. */
  430. get: function () {
  431. return this._idealHeight;
  432. },
  433. set: function (value) {
  434. if (this._idealHeight === value) {
  435. return;
  436. }
  437. this._idealHeight = value;
  438. this.markAsDirty();
  439. this._rootContainer._markAllAsDirty();
  440. },
  441. enumerable: true,
  442. configurable: true
  443. });
  444. Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
  445. /**
  446. * Gets or sets a boolean indicating if the smallest ideal value must be used if idealWidth and idealHeight are both set
  447. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  448. */
  449. get: function () {
  450. return this._useSmallestIdeal;
  451. },
  452. set: function (value) {
  453. if (this._useSmallestIdeal === value) {
  454. return;
  455. }
  456. this._useSmallestIdeal = value;
  457. this.markAsDirty();
  458. this._rootContainer._markAllAsDirty();
  459. },
  460. enumerable: true,
  461. configurable: true
  462. });
  463. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
  464. /**
  465. * Gets or sets a boolean indicating if adaptive scaling must be used
  466. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  467. */
  468. get: function () {
  469. return this._renderAtIdealSize;
  470. },
  471. set: function (value) {
  472. if (this._renderAtIdealSize === value) {
  473. return;
  474. }
  475. this._renderAtIdealSize = value;
  476. this._onResize();
  477. },
  478. enumerable: true,
  479. configurable: true
  480. });
  481. Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
  482. /**
  483. * Gets the underlying layer used to render the texture when in fullscreen mode
  484. */
  485. get: function () {
  486. return this._layerToDispose;
  487. },
  488. enumerable: true,
  489. configurable: true
  490. });
  491. Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
  492. /**
  493. * Gets the root container control
  494. */
  495. get: function () {
  496. return this._rootContainer;
  497. },
  498. enumerable: true,
  499. configurable: true
  500. });
  501. Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
  502. /**
  503. * Gets or sets the current focused control
  504. */
  505. get: function () {
  506. return this._focusedControl;
  507. },
  508. set: function (control) {
  509. if (this._focusedControl == control) {
  510. return;
  511. }
  512. if (this._focusedControl) {
  513. this._focusedControl.onBlur();
  514. }
  515. if (control) {
  516. control.onFocus();
  517. }
  518. this._focusedControl = control;
  519. },
  520. enumerable: true,
  521. configurable: true
  522. });
  523. Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
  524. /**
  525. * Gets or sets a boolean indicating if the texture must be rendered in background or foreground when in fullscreen mode
  526. */
  527. get: function () {
  528. if (!this.layer) {
  529. return true;
  530. }
  531. return (!this.layer.isBackground);
  532. },
  533. set: function (value) {
  534. if (!this.layer) {
  535. return;
  536. }
  537. if (this.layer.isBackground === !value) {
  538. return;
  539. }
  540. this.layer.isBackground = !value;
  541. },
  542. enumerable: true,
  543. configurable: true
  544. });
  545. /**
  546. * Function used to execute a function on all controls
  547. * @param func defines the function to execute
  548. * @param container defines the container where controls belong. If null the root container will be used
  549. */
  550. AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
  551. if (!container) {
  552. container = this._rootContainer;
  553. }
  554. for (var _i = 0, _a = container.children; _i < _a.length; _i++) {
  555. var child = _a[_i];
  556. if (child.children) {
  557. this.executeOnAllControls(func, child);
  558. continue;
  559. }
  560. func(child);
  561. }
  562. };
  563. /**
  564. * Marks the texture as dirty forcing a complete update
  565. */
  566. AdvancedDynamicTexture.prototype.markAsDirty = function () {
  567. this._isDirty = true;
  568. this.executeOnAllControls(function (control) {
  569. if (control._isFontSizeInPercentage) {
  570. control._resetFontCache();
  571. }
  572. });
  573. };
  574. /**
  575. * Helper function used to create a new style
  576. * @returns a new style
  577. * @see http://doc.babylonjs.com/how_to/gui#styles
  578. */
  579. AdvancedDynamicTexture.prototype.createStyle = function () {
  580. return new GUI.Style(this);
  581. };
  582. /**
  583. * Adds a new control to the root container
  584. * @param control defines the control to add
  585. * @returns the current texture
  586. */
  587. AdvancedDynamicTexture.prototype.addControl = function (control) {
  588. this._rootContainer.addControl(control);
  589. return this;
  590. };
  591. /**
  592. * Removes a control from the root container
  593. * @param control defines the control to remove
  594. * @returns the current texture
  595. */
  596. AdvancedDynamicTexture.prototype.removeControl = function (control) {
  597. this._rootContainer.removeControl(control);
  598. return this;
  599. };
  600. /**
  601. * Release all resources
  602. */
  603. AdvancedDynamicTexture.prototype.dispose = function () {
  604. var scene = this.getScene();
  605. if (!scene) {
  606. return;
  607. }
  608. scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
  609. if (this._resizeObserver) {
  610. scene.getEngine().onResizeObservable.remove(this._resizeObserver);
  611. }
  612. if (this._pointerMoveObserver) {
  613. scene.onPrePointerObservable.remove(this._pointerMoveObserver);
  614. }
  615. if (this._pointerObserver) {
  616. scene.onPointerObservable.remove(this._pointerObserver);
  617. }
  618. if (this._preKeyboardObserver) {
  619. scene.onPreKeyboardObservable.remove(this._preKeyboardObserver);
  620. }
  621. if (this._canvasPointerOutObserver) {
  622. scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
  623. }
  624. if (this._layerToDispose) {
  625. this._layerToDispose.texture = null;
  626. this._layerToDispose.dispose();
  627. this._layerToDispose = null;
  628. }
  629. this._rootContainer.dispose();
  630. _super.prototype.dispose.call(this);
  631. };
  632. AdvancedDynamicTexture.prototype._onResize = function () {
  633. var scene = this.getScene();
  634. if (!scene) {
  635. return;
  636. }
  637. // Check size
  638. var engine = scene.getEngine();
  639. var textureSize = this.getSize();
  640. var renderWidth = engine.getRenderWidth() * this._renderScale;
  641. var renderHeight = engine.getRenderHeight() * this._renderScale;
  642. if (this._renderAtIdealSize) {
  643. if (this._idealWidth) {
  644. renderHeight = (renderHeight * this._idealWidth) / renderWidth;
  645. renderWidth = this._idealWidth;
  646. }
  647. else if (this._idealHeight) {
  648. renderWidth = (renderWidth * this._idealHeight) / renderHeight;
  649. renderHeight = this._idealHeight;
  650. }
  651. }
  652. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  653. this.scaleTo(renderWidth, renderHeight);
  654. this.markAsDirty();
  655. if (this._idealWidth || this._idealHeight) {
  656. this._rootContainer._markAllAsDirty();
  657. }
  658. }
  659. };
  660. /** @hidden */
  661. AdvancedDynamicTexture.prototype._getGlobalViewport = function (scene) {
  662. var engine = scene.getEngine();
  663. return this._fullscreenViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  664. };
  665. /**
  666. * Get screen coordinates for a vector3
  667. * @param position defines the position to project
  668. * @param worldMatrix defines the world matrix to use
  669. * @returns the projected position
  670. */
  671. AdvancedDynamicTexture.prototype.getProjectedPosition = function (position, worldMatrix) {
  672. var scene = this.getScene();
  673. if (!scene) {
  674. return BABYLON.Vector2.Zero();
  675. }
  676. var globalViewport = this._getGlobalViewport(scene);
  677. var projectedPosition = BABYLON.Vector3.Project(position, worldMatrix, scene.getTransformMatrix(), globalViewport);
  678. projectedPosition.scaleInPlace(this.renderScale);
  679. return new BABYLON.Vector2(projectedPosition.x, projectedPosition.y);
  680. };
  681. AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
  682. if (this._layerToDispose) {
  683. if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
  684. return;
  685. }
  686. }
  687. if (this._isFullscreen && this._linkedControls.length) {
  688. var scene = this.getScene();
  689. if (!scene) {
  690. return;
  691. }
  692. var globalViewport = this._getGlobalViewport(scene);
  693. for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
  694. var control = _a[_i];
  695. if (!control.isVisible) {
  696. continue;
  697. }
  698. var mesh = control._linkedMesh;
  699. if (!mesh || mesh.isDisposed()) {
  700. BABYLON.Tools.SetImmediate(function () {
  701. control.linkWithMesh(null);
  702. });
  703. continue;
  704. }
  705. var position = mesh.getBoundingInfo().boundingSphere.center;
  706. var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
  707. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  708. control.notRenderable = true;
  709. continue;
  710. }
  711. control.notRenderable = false;
  712. // Account for RenderScale.
  713. projectedPosition.scaleInPlace(this.renderScale);
  714. control._moveToProjectedPosition(projectedPosition);
  715. }
  716. }
  717. if (!this._isDirty && !this._rootContainer.isDirty) {
  718. return;
  719. }
  720. this._isDirty = false;
  721. this._render();
  722. this.update(true, this.premulAlpha);
  723. };
  724. AdvancedDynamicTexture.prototype._render = function () {
  725. var textureSize = this.getSize();
  726. var renderWidth = textureSize.width;
  727. var renderHeight = textureSize.height;
  728. // Clear
  729. var context = this.getContext();
  730. context.clearRect(0, 0, renderWidth, renderHeight);
  731. if (this._background) {
  732. context.save();
  733. context.fillStyle = this._background;
  734. context.fillRect(0, 0, renderWidth, renderHeight);
  735. context.restore();
  736. }
  737. // Render
  738. context.font = "18px Arial";
  739. context.strokeStyle = "white";
  740. var measure = new GUI.Measure(0, 0, renderWidth, renderHeight);
  741. this._rootContainer._draw(measure, context);
  742. };
  743. AdvancedDynamicTexture.prototype._doPicking = function (x, y, type, pointerId, buttonIndex) {
  744. var scene = this.getScene();
  745. if (!scene) {
  746. return;
  747. }
  748. var engine = scene.getEngine();
  749. var textureSize = this.getSize();
  750. if (this._isFullscreen) {
  751. x = x * (textureSize.width / engine.getRenderWidth());
  752. y = y * (textureSize.height / engine.getRenderHeight());
  753. }
  754. if (this._capturingControl[pointerId]) {
  755. this._capturingControl[pointerId]._processObservables(type, x, y, pointerId, buttonIndex);
  756. return;
  757. }
  758. if (!this._rootContainer._processPicking(x, y, type, pointerId, buttonIndex)) {
  759. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  760. if (this._lastControlOver[pointerId]) {
  761. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  762. }
  763. delete this._lastControlOver[pointerId];
  764. }
  765. }
  766. this._manageFocus();
  767. };
  768. /** @hidden */
  769. AdvancedDynamicTexture.prototype._cleanControlAfterRemovalFromList = function (list, control) {
  770. for (var pointerId in list) {
  771. if (!list.hasOwnProperty(pointerId)) {
  772. continue;
  773. }
  774. var lastControlOver = list[pointerId];
  775. if (lastControlOver === control) {
  776. delete list[pointerId];
  777. }
  778. }
  779. };
  780. /** @hidden */
  781. AdvancedDynamicTexture.prototype._cleanControlAfterRemoval = function (control) {
  782. this._cleanControlAfterRemovalFromList(this._lastControlDown, control);
  783. this._cleanControlAfterRemovalFromList(this._lastControlOver, control);
  784. };
  785. /** Attach to all scene events required to support pointer events */
  786. AdvancedDynamicTexture.prototype.attach = function () {
  787. var _this = this;
  788. var scene = this.getScene();
  789. if (!scene) {
  790. return;
  791. }
  792. this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
  793. if (scene.isPointerCaptured((pi.event).pointerId)) {
  794. return;
  795. }
  796. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  797. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  798. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  799. return;
  800. }
  801. if (!scene) {
  802. return;
  803. }
  804. var camera = scene.cameraToUseForPointers || scene.activeCamera;
  805. if (!camera) {
  806. return;
  807. }
  808. var engine = scene.getEngine();
  809. var viewport = camera.viewport;
  810. var x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
  811. var y = (scene.pointerY / engine.getHardwareScalingLevel() - viewport.y * engine.getRenderHeight()) / viewport.height;
  812. _this._shouldBlockPointer = false;
  813. _this._doPicking(x, y, pi.type, pi.event.pointerId || 0, pi.event.button);
  814. pi.skipOnPointerObservable = _this._shouldBlockPointer;
  815. });
  816. this._attachToOnPointerOut(scene);
  817. };
  818. /**
  819. * Connect the texture to a hosting mesh to enable interactions
  820. * @param mesh defines the mesh to attach to
  821. * @param supportPointerMove defines a boolean indicating if pointer move events must be catched as well
  822. */
  823. AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
  824. var _this = this;
  825. if (supportPointerMove === void 0) { supportPointerMove = true; }
  826. var scene = this.getScene();
  827. if (!scene) {
  828. return;
  829. }
  830. this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
  831. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  832. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  833. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  834. return;
  835. }
  836. var pointerId = pi.event.pointerId || 0;
  837. if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
  838. var uv = pi.pickInfo.getTextureCoordinates();
  839. if (uv) {
  840. var size = _this.getSize();
  841. _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pointerId, pi.event.button);
  842. }
  843. }
  844. else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
  845. if (_this._lastControlDown[pointerId]) {
  846. _this._lastControlDown[pointerId]._forcePointerUp(pointerId);
  847. }
  848. delete _this._lastControlDown[pointerId];
  849. _this.focusedControl = null;
  850. }
  851. else if (pi.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  852. if (_this._lastControlOver[pointerId]) {
  853. _this._lastControlOver[pointerId]._onPointerOut(_this._lastControlOver[pointerId]);
  854. }
  855. delete _this._lastControlOver[pointerId];
  856. }
  857. });
  858. mesh.enablePointerMoveEvents = supportPointerMove;
  859. this._attachToOnPointerOut(scene);
  860. };
  861. /**
  862. * Move the focus to a specific control
  863. * @param control defines the control which will receive the focus
  864. */
  865. AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
  866. this.focusedControl = control;
  867. this._lastPickedControl = control;
  868. this._blockNextFocusCheck = true;
  869. };
  870. AdvancedDynamicTexture.prototype._manageFocus = function () {
  871. if (this._blockNextFocusCheck) {
  872. this._blockNextFocusCheck = false;
  873. this._lastPickedControl = this._focusedControl;
  874. return;
  875. }
  876. // Focus management
  877. if (this._focusedControl) {
  878. if (this._focusedControl !== this._lastPickedControl) {
  879. if (this._lastPickedControl.isFocusInvisible) {
  880. return;
  881. }
  882. this.focusedControl = null;
  883. }
  884. }
  885. };
  886. AdvancedDynamicTexture.prototype._attachToOnPointerOut = function (scene) {
  887. var _this = this;
  888. this._canvasPointerOutObserver = scene.getEngine().onCanvasPointerOutObservable.add(function (pointerEvent) {
  889. if (_this._lastControlOver[pointerEvent.pointerId]) {
  890. _this._lastControlOver[pointerEvent.pointerId]._onPointerOut(_this._lastControlOver[pointerEvent.pointerId]);
  891. }
  892. delete _this._lastControlOver[pointerEvent.pointerId];
  893. if (_this._lastControlDown[pointerEvent.pointerId]) {
  894. _this._lastControlDown[pointerEvent.pointerId]._forcePointerUp();
  895. }
  896. delete _this._lastControlDown[pointerEvent.pointerId];
  897. });
  898. };
  899. // Statics
  900. /**
  901. * Creates a new AdvancedDynamicTexture in projected mode (ie. attached to a mesh)
  902. * @param mesh defines the mesh which will receive the texture
  903. * @param width defines the texture width (1024 by default)
  904. * @param height defines the texture height (1024 by default)
  905. * @param supportPointerMove defines a boolean indicating if the texture must capture move events (true by default)
  906. * @returns a new AdvancedDynamicTexture
  907. */
  908. AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height, supportPointerMove) {
  909. if (width === void 0) { width = 1024; }
  910. if (height === void 0) { height = 1024; }
  911. if (supportPointerMove === void 0) { supportPointerMove = true; }
  912. var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  913. var material = new BABYLON.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
  914. material.backFaceCulling = false;
  915. material.diffuseColor = BABYLON.Color3.Black();
  916. material.specularColor = BABYLON.Color3.Black();
  917. material.emissiveTexture = result;
  918. material.opacityTexture = result;
  919. mesh.material = material;
  920. result.attachToMesh(mesh, supportPointerMove);
  921. return result;
  922. };
  923. /**
  924. * Creates a new AdvancedDynamicTexture in fullscreen mode.
  925. * In this mode the texture will rely on a layer for its rendering.
  926. * This allows it to be treated like any other layer.
  927. * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
  928. * LayerMask is set through advancedTexture.layer.layerMask
  929. * @param name defines name for the texture
  930. * @param foreground defines a boolean indicating if the texture must be rendered in foreground (default is true)
  931. * @param scene defines the hsoting scene
  932. * @param sampling defines the texture sampling mode (BABYLON.Texture.BILINEAR_SAMPLINGMODE by default)
  933. * @returns a new AdvancedDynamicTexture
  934. */
  935. AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling) {
  936. if (foreground === void 0) { foreground = true; }
  937. if (scene === void 0) { scene = null; }
  938. if (sampling === void 0) { sampling = BABYLON.Texture.BILINEAR_SAMPLINGMODE; }
  939. var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, sampling);
  940. // Display
  941. var layer = new BABYLON.Layer(name + "_layer", null, scene, !foreground);
  942. layer.texture = result;
  943. result._layerToDispose = layer;
  944. result._isFullscreen = true;
  945. // Attach
  946. result.attach();
  947. return result;
  948. };
  949. return AdvancedDynamicTexture;
  950. }(BABYLON.DynamicTexture));
  951. GUI.AdvancedDynamicTexture = AdvancedDynamicTexture;
  952. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  953. })(BABYLON || (BABYLON = {}));
  954. //# sourceMappingURL=advancedDynamicTexture.js.map
  955. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  956. var BABYLON;
  957. (function (BABYLON) {
  958. var GUI;
  959. (function (GUI) {
  960. /**
  961. * Class used to store 2D control sizes
  962. */
  963. var Measure = /** @class */ (function () {
  964. /**
  965. * Creates a new measure
  966. * @param left defines left coordinate
  967. * @param top defines top coordinate
  968. * @param width defines width dimension
  969. * @param height defines height dimension
  970. */
  971. function Measure(
  972. /** defines left coordinate */
  973. left,
  974. /** defines top coordinate */
  975. top,
  976. /** defines width dimension */
  977. width,
  978. /** defines height dimension */
  979. height) {
  980. this.left = left;
  981. this.top = top;
  982. this.width = width;
  983. this.height = height;
  984. }
  985. /**
  986. * Copy from another measure
  987. * @param other defines the other measure to copy from
  988. */
  989. Measure.prototype.copyFrom = function (other) {
  990. this.left = other.left;
  991. this.top = other.top;
  992. this.width = other.width;
  993. this.height = other.height;
  994. };
  995. /**
  996. * Check equality between this measure and another one
  997. * @param other defines the other measures
  998. * @returns true if both measures are equals
  999. */
  1000. Measure.prototype.isEqualsTo = function (other) {
  1001. if (this.left !== other.left) {
  1002. return false;
  1003. }
  1004. if (this.top !== other.top) {
  1005. return false;
  1006. }
  1007. if (this.width !== other.width) {
  1008. return false;
  1009. }
  1010. if (this.height !== other.height) {
  1011. return false;
  1012. }
  1013. return true;
  1014. };
  1015. /**
  1016. * Creates an empty measure
  1017. * @returns a new measure
  1018. */
  1019. Measure.Empty = function () {
  1020. return new Measure(0, 0, 0, 0);
  1021. };
  1022. return Measure;
  1023. }());
  1024. GUI.Measure = Measure;
  1025. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1026. })(BABYLON || (BABYLON = {}));
  1027. //# sourceMappingURL=measure.js.map
  1028. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1029. var BABYLON;
  1030. (function (BABYLON) {
  1031. var GUI;
  1032. (function (GUI) {
  1033. /**
  1034. * Class used to transport Vector2 information for pointer events
  1035. */
  1036. var Vector2WithInfo = /** @class */ (function (_super) {
  1037. __extends(Vector2WithInfo, _super);
  1038. /**
  1039. * Creates a new Vector2WithInfo
  1040. * @param source defines the vector2 data to transport
  1041. * @param buttonIndex defines the current mouse button index
  1042. */
  1043. function Vector2WithInfo(source,
  1044. /** defines the current mouse button index */
  1045. buttonIndex) {
  1046. if (buttonIndex === void 0) { buttonIndex = 0; }
  1047. var _this = _super.call(this, source.x, source.y) || this;
  1048. _this.buttonIndex = buttonIndex;
  1049. return _this;
  1050. }
  1051. return Vector2WithInfo;
  1052. }(BABYLON.Vector2));
  1053. GUI.Vector2WithInfo = Vector2WithInfo;
  1054. /** Class used to provide 2D matrix features */
  1055. var Matrix2D = /** @class */ (function () {
  1056. /**
  1057. * Creates a new matrix
  1058. * @param m00 defines value for (0, 0)
  1059. * @param m01 defines value for (0, 1)
  1060. * @param m10 defines value for (1, 0)
  1061. * @param m11 defines value for (1, 1)
  1062. * @param m20 defines value for (2, 0)
  1063. * @param m21 defines value for (2, 1)
  1064. */
  1065. function Matrix2D(m00, m01, m10, m11, m20, m21) {
  1066. /** Gets the internal array of 6 floats used to store matrix data */
  1067. this.m = new Float32Array(6);
  1068. this.fromValues(m00, m01, m10, m11, m20, m21);
  1069. }
  1070. /**
  1071. * Fills the matrix from direct values
  1072. * @param m00 defines value for (0, 0)
  1073. * @param m01 defines value for (0, 1)
  1074. * @param m10 defines value for (1, 0)
  1075. * @param m11 defines value for (1, 1)
  1076. * @param m20 defines value for (2, 0)
  1077. * @param m21 defines value for (2, 1)
  1078. * @returns the current modified matrix
  1079. */
  1080. Matrix2D.prototype.fromValues = function (m00, m01, m10, m11, m20, m21) {
  1081. this.m[0] = m00;
  1082. this.m[1] = m01;
  1083. this.m[2] = m10;
  1084. this.m[3] = m11;
  1085. this.m[4] = m20;
  1086. this.m[5] = m21;
  1087. return this;
  1088. };
  1089. /**
  1090. * Gets matrix determinant
  1091. * @returns the determinant
  1092. */
  1093. Matrix2D.prototype.determinant = function () {
  1094. return this.m[0] * this.m[3] - this.m[1] * this.m[2];
  1095. };
  1096. /**
  1097. * Inverses the matrix and stores it in a target matrix
  1098. * @param result defines the target matrix
  1099. * @returns the current matrix
  1100. */
  1101. Matrix2D.prototype.invertToRef = function (result) {
  1102. var l0 = this.m[0];
  1103. var l1 = this.m[1];
  1104. var l2 = this.m[2];
  1105. var l3 = this.m[3];
  1106. var l4 = this.m[4];
  1107. var l5 = this.m[5];
  1108. var det = this.determinant();
  1109. if (det < (BABYLON.Epsilon * BABYLON.Epsilon)) {
  1110. result.m[0] = 0;
  1111. result.m[1] = 0;
  1112. result.m[2] = 0;
  1113. result.m[3] = 0;
  1114. result.m[4] = 0;
  1115. result.m[5] = 0;
  1116. return this;
  1117. }
  1118. var detDiv = 1 / det;
  1119. var det4 = l2 * l5 - l3 * l4;
  1120. var det5 = l1 * l4 - l0 * l5;
  1121. result.m[0] = l3 * detDiv;
  1122. result.m[1] = -l1 * detDiv;
  1123. result.m[2] = -l2 * detDiv;
  1124. result.m[3] = l0 * detDiv;
  1125. result.m[4] = det4 * detDiv;
  1126. result.m[5] = det5 * detDiv;
  1127. return this;
  1128. };
  1129. /**
  1130. * Multiplies the current matrix with another one
  1131. * @param other defines the second operand
  1132. * @param result defines the target matrix
  1133. * @returns the current matrix
  1134. */
  1135. Matrix2D.prototype.multiplyToRef = function (other, result) {
  1136. var l0 = this.m[0];
  1137. var l1 = this.m[1];
  1138. var l2 = this.m[2];
  1139. var l3 = this.m[3];
  1140. var l4 = this.m[4];
  1141. var l5 = this.m[5];
  1142. var r0 = other.m[0];
  1143. var r1 = other.m[1];
  1144. var r2 = other.m[2];
  1145. var r3 = other.m[3];
  1146. var r4 = other.m[4];
  1147. var r5 = other.m[5];
  1148. result.m[0] = l0 * r0 + l1 * r2;
  1149. result.m[1] = l0 * r1 + l1 * r3;
  1150. result.m[2] = l2 * r0 + l3 * r2;
  1151. result.m[3] = l2 * r1 + l3 * r3;
  1152. result.m[4] = l4 * r0 + l5 * r2 + r4;
  1153. result.m[5] = l4 * r1 + l5 * r3 + r5;
  1154. return this;
  1155. };
  1156. /**
  1157. * Applies the current matrix to a set of 2 floats and stores the result in a vector2
  1158. * @param x defines the x coordinate to transform
  1159. * @param y defines the x coordinate to transform
  1160. * @param result defines the target vector2
  1161. * @returns the current matrix
  1162. */
  1163. Matrix2D.prototype.transformCoordinates = function (x, y, result) {
  1164. result.x = x * this.m[0] + y * this.m[2] + this.m[4];
  1165. result.y = x * this.m[1] + y * this.m[3] + this.m[5];
  1166. return this;
  1167. };
  1168. // Statics
  1169. /**
  1170. * Creates an identity matrix
  1171. * @returns a new matrix
  1172. */
  1173. Matrix2D.Identity = function () {
  1174. return new Matrix2D(1, 0, 0, 1, 0, 0);
  1175. };
  1176. /**
  1177. * Creates a translation matrix and stores it in a target matrix
  1178. * @param x defines the x coordinate of the translation
  1179. * @param y defines the y coordinate of the translation
  1180. * @param result defines the target matrix
  1181. */
  1182. Matrix2D.TranslationToRef = function (x, y, result) {
  1183. result.fromValues(1, 0, 0, 1, x, y);
  1184. };
  1185. /**
  1186. * Creates a scaling matrix and stores it in a target matrix
  1187. * @param x defines the x coordinate of the scaling
  1188. * @param y defines the y coordinate of the scaling
  1189. * @param result defines the target matrix
  1190. */
  1191. Matrix2D.ScalingToRef = function (x, y, result) {
  1192. result.fromValues(x, 0, 0, y, 0, 0);
  1193. };
  1194. /**
  1195. * Creates a rotation matrix and stores it in a target matrix
  1196. * @param angle defines the rotation angle
  1197. * @param result defines the target matrix
  1198. */
  1199. Matrix2D.RotationToRef = function (angle, result) {
  1200. var s = Math.sin(angle);
  1201. var c = Math.cos(angle);
  1202. result.fromValues(c, s, -s, c, 0, 0);
  1203. };
  1204. /**
  1205. * Composes a matrix from translation, rotation, scaling and parent matrix and stores it in a target matrix
  1206. * @param tx defines the x coordinate of the translation
  1207. * @param ty defines the y coordinate of the translation
  1208. * @param angle defines the rotation angle
  1209. * @param scaleX defines the x coordinate of the scaling
  1210. * @param scaleY defines the y coordinate of the scaling
  1211. * @param parentMatrix defines the parent matrix to multiply by (can be null)
  1212. * @param result defines the target matrix
  1213. */
  1214. Matrix2D.ComposeToRef = function (tx, ty, angle, scaleX, scaleY, parentMatrix, result) {
  1215. Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
  1216. Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);
  1217. Matrix2D.RotationToRef(angle, Matrix2D._TempRotationMatrix);
  1218. Matrix2D.TranslationToRef(-tx, -ty, Matrix2D._TempPostTranslationMatrix);
  1219. Matrix2D._TempPreTranslationMatrix.multiplyToRef(Matrix2D._TempScalingMatrix, Matrix2D._TempCompose0);
  1220. Matrix2D._TempCompose0.multiplyToRef(Matrix2D._TempRotationMatrix, Matrix2D._TempCompose1);
  1221. if (parentMatrix) {
  1222. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, Matrix2D._TempCompose2);
  1223. Matrix2D._TempCompose2.multiplyToRef(parentMatrix, result);
  1224. }
  1225. else {
  1226. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, result);
  1227. }
  1228. };
  1229. Matrix2D._TempPreTranslationMatrix = Matrix2D.Identity();
  1230. Matrix2D._TempPostTranslationMatrix = Matrix2D.Identity();
  1231. Matrix2D._TempRotationMatrix = Matrix2D.Identity();
  1232. Matrix2D._TempScalingMatrix = Matrix2D.Identity();
  1233. Matrix2D._TempCompose0 = Matrix2D.Identity();
  1234. Matrix2D._TempCompose1 = Matrix2D.Identity();
  1235. Matrix2D._TempCompose2 = Matrix2D.Identity();
  1236. return Matrix2D;
  1237. }());
  1238. GUI.Matrix2D = Matrix2D;
  1239. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1240. })(BABYLON || (BABYLON = {}));
  1241. //# sourceMappingURL=math2D.js.map
  1242. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  1243. var BABYLON;
  1244. (function (BABYLON) {
  1245. var GUI;
  1246. (function (GUI) {
  1247. /**
  1248. * Class used to store a point for a MultiLine object.
  1249. * The point can be pure 2D coordinates, a mesh or a control
  1250. */
  1251. var MultiLinePoint = /** @class */ (function () {
  1252. /**
  1253. * Creates a new MultiLinePoint
  1254. * @param multiLine defines the source MultiLine object
  1255. */
  1256. function MultiLinePoint(multiLine) {
  1257. this._multiLine = multiLine;
  1258. this._x = new GUI.ValueAndUnit(0);
  1259. this._y = new GUI.ValueAndUnit(0);
  1260. this._point = new BABYLON.Vector2(0, 0);
  1261. }
  1262. Object.defineProperty(MultiLinePoint.prototype, "x", {
  1263. /** Gets or sets x coordinate */
  1264. get: function () {
  1265. return this._x.toString(this._multiLine._host);
  1266. },
  1267. set: function (value) {
  1268. if (this._x.toString(this._multiLine._host) === value) {
  1269. return;
  1270. }
  1271. if (this._x.fromString(value)) {
  1272. this._multiLine._markAsDirty();
  1273. }
  1274. },
  1275. enumerable: true,
  1276. configurable: true
  1277. });
  1278. Object.defineProperty(MultiLinePoint.prototype, "y", {
  1279. /** Gets or sets y coordinate */
  1280. get: function () {
  1281. return this._y.toString(this._multiLine._host);
  1282. },
  1283. set: function (value) {
  1284. if (this._y.toString(this._multiLine._host) === value) {
  1285. return;
  1286. }
  1287. if (this._y.fromString(value)) {
  1288. this._multiLine._markAsDirty();
  1289. }
  1290. },
  1291. enumerable: true,
  1292. configurable: true
  1293. });
  1294. Object.defineProperty(MultiLinePoint.prototype, "control", {
  1295. /** Gets or sets the control associated with this point */
  1296. get: function () {
  1297. return this._control;
  1298. },
  1299. set: function (value) {
  1300. if (this._control === value) {
  1301. return;
  1302. }
  1303. if (this._control && this._controlObserver) {
  1304. this._control.onDirtyObservable.remove(this._controlObserver);
  1305. this._controlObserver = null;
  1306. }
  1307. this._control = value;
  1308. if (this._control) {
  1309. this._controlObserver = this._control.onDirtyObservable.add(this._multiLine.onPointUpdate);
  1310. }
  1311. this._multiLine._markAsDirty();
  1312. },
  1313. enumerable: true,
  1314. configurable: true
  1315. });
  1316. Object.defineProperty(MultiLinePoint.prototype, "mesh", {
  1317. /** Gets or sets the mesh associated with this point */
  1318. get: function () {
  1319. return this._mesh;
  1320. },
  1321. set: function (value) {
  1322. if (this._mesh === value) {
  1323. return;
  1324. }
  1325. if (this._mesh && this._meshObserver) {
  1326. this._mesh.getScene().onAfterCameraRenderObservable.remove(this._meshObserver);
  1327. }
  1328. this._mesh = value;
  1329. if (this._mesh) {
  1330. this._meshObserver = this._mesh.getScene().onAfterCameraRenderObservable.add(this._multiLine.onPointUpdate);
  1331. }
  1332. this._multiLine._markAsDirty();
  1333. },
  1334. enumerable: true,
  1335. configurable: true
  1336. });
  1337. /**
  1338. * Gets a translation vector
  1339. * @returns the translation vector
  1340. */
  1341. MultiLinePoint.prototype.translate = function () {
  1342. this._point = this._translatePoint();
  1343. return this._point;
  1344. };
  1345. MultiLinePoint.prototype._translatePoint = function () {
  1346. if (this._mesh != null) {
  1347. return this._multiLine._host.getProjectedPosition(this._mesh.getBoundingInfo().boundingSphere.center, this._mesh.getWorldMatrix());
  1348. }
  1349. else if (this._control != null) {
  1350. return new BABYLON.Vector2(this._control.centerX, this._control.centerY);
  1351. }
  1352. else {
  1353. var host = this._multiLine._host;
  1354. var xValue = this._x.getValueInPixel(host, Number(host._canvas.width));
  1355. var yValue = this._y.getValueInPixel(host, Number(host._canvas.height));
  1356. return new BABYLON.Vector2(xValue, yValue);
  1357. }
  1358. };
  1359. /** Release associated resources */
  1360. MultiLinePoint.prototype.dispose = function () {
  1361. this.control = null;
  1362. this.mesh = null;
  1363. };
  1364. return MultiLinePoint;
  1365. }());
  1366. GUI.MultiLinePoint = MultiLinePoint;
  1367. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1368. })(BABYLON || (BABYLON = {}));
  1369. //# sourceMappingURL=multiLinePoint.js.map
  1370. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1371. var BABYLON;
  1372. (function (BABYLON) {
  1373. var GUI;
  1374. (function (GUI) {
  1375. /**
  1376. * Root class used for all 2D controls
  1377. * @see http://doc.babylonjs.com/how_to/gui#controls
  1378. */
  1379. var Control = /** @class */ (function () {
  1380. // Functions
  1381. /**
  1382. * Creates a new control
  1383. * @param name defines the name of the control
  1384. */
  1385. function Control(
  1386. /** defines the name of the control */
  1387. name) {
  1388. this.name = name;
  1389. this._alpha = 1;
  1390. this._alphaSet = false;
  1391. this._zIndex = 0;
  1392. /** @hidden */
  1393. this._currentMeasure = GUI.Measure.Empty();
  1394. this._fontFamily = "Arial";
  1395. this._fontStyle = "";
  1396. this._fontWeight = "";
  1397. this._fontSize = new GUI.ValueAndUnit(18, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  1398. /** @hidden */
  1399. this._width = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  1400. /** @hidden */
  1401. this._height = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  1402. this._color = "";
  1403. this._style = null;
  1404. /** @hidden */
  1405. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  1406. /** @hidden */
  1407. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  1408. this._isDirty = true;
  1409. /** @hidden */
  1410. this._tempParentMeasure = GUI.Measure.Empty();
  1411. /** @hidden */
  1412. this._cachedParentMeasure = GUI.Measure.Empty();
  1413. this._paddingLeft = new GUI.ValueAndUnit(0);
  1414. this._paddingRight = new GUI.ValueAndUnit(0);
  1415. this._paddingTop = new GUI.ValueAndUnit(0);
  1416. this._paddingBottom = new GUI.ValueAndUnit(0);
  1417. /** @hidden */
  1418. this._left = new GUI.ValueAndUnit(0);
  1419. /** @hidden */
  1420. this._top = new GUI.ValueAndUnit(0);
  1421. this._scaleX = 1.0;
  1422. this._scaleY = 1.0;
  1423. this._rotation = 0;
  1424. this._transformCenterX = 0.5;
  1425. this._transformCenterY = 0.5;
  1426. this._transformMatrix = GUI.Matrix2D.Identity();
  1427. /** @hidden */
  1428. this._invertTransformMatrix = GUI.Matrix2D.Identity();
  1429. /** @hidden */
  1430. this._transformedPosition = BABYLON.Vector2.Zero();
  1431. this._onlyMeasureMode = false;
  1432. this._isMatrixDirty = true;
  1433. this._isVisible = true;
  1434. this._fontSet = false;
  1435. this._dummyVector2 = BABYLON.Vector2.Zero();
  1436. this._downCount = 0;
  1437. this._enterCount = -1;
  1438. this._doNotRender = false;
  1439. this._downPointerIds = {};
  1440. /** Gets or sets a boolean indicating if the control can be hit with pointer events */
  1441. this.isHitTestVisible = true;
  1442. /** Gets or sets a boolean indicating if the control can block pointer events */
  1443. this.isPointerBlocker = false;
  1444. /** Gets or sets a boolean indicating if the control can be focusable */
  1445. this.isFocusInvisible = false;
  1446. /** Gets or sets a value indicating the offset to apply on X axis to render the shadow */
  1447. this.shadowOffsetX = 0;
  1448. /** Gets or sets a value indicating the offset to apply on Y axis to render the shadow */
  1449. this.shadowOffsetY = 0;
  1450. /** Gets or sets a value indicating the amount of blur to use to render the shadow */
  1451. this.shadowBlur = 0;
  1452. /** Gets or sets a value indicating the color of the shadow (black by default ie. "#000") */
  1453. this.shadowColor = '#000';
  1454. /** @hidden */
  1455. this._linkOffsetX = new GUI.ValueAndUnit(0);
  1456. /** @hidden */
  1457. this._linkOffsetY = new GUI.ValueAndUnit(0);
  1458. /**
  1459. * An event triggered when the pointer move over the control.
  1460. */
  1461. this.onPointerMoveObservable = new BABYLON.Observable();
  1462. /**
  1463. * An event triggered when the pointer move out of the control.
  1464. */
  1465. this.onPointerOutObservable = new BABYLON.Observable();
  1466. /**
  1467. * An event triggered when the pointer taps the control
  1468. */
  1469. this.onPointerDownObservable = new BABYLON.Observable();
  1470. /**
  1471. * An event triggered when pointer up
  1472. */
  1473. this.onPointerUpObservable = new BABYLON.Observable();
  1474. /**
  1475. * An event triggered when a control is clicked on
  1476. */
  1477. this.onPointerClickObservable = new BABYLON.Observable();
  1478. /**
  1479. * An event triggered when pointer enters the control
  1480. */
  1481. this.onPointerEnterObservable = new BABYLON.Observable();
  1482. /**
  1483. * An event triggered when the control is marked as dirty
  1484. */
  1485. this.onDirtyObservable = new BABYLON.Observable();
  1486. /**
  1487. * An event triggered after the control is drawn
  1488. */
  1489. this.onAfterDrawObservable = new BABYLON.Observable();
  1490. }
  1491. Object.defineProperty(Control.prototype, "typeName", {
  1492. // Properties
  1493. /** Gets the control type name */
  1494. get: function () {
  1495. return this._getTypeName();
  1496. },
  1497. enumerable: true,
  1498. configurable: true
  1499. });
  1500. Object.defineProperty(Control.prototype, "fontOffset", {
  1501. /** Gets or set information about font offsets (used to render and align text) */
  1502. get: function () {
  1503. return this._fontOffset;
  1504. },
  1505. set: function (offset) {
  1506. this._fontOffset = offset;
  1507. },
  1508. enumerable: true,
  1509. configurable: true
  1510. });
  1511. Object.defineProperty(Control.prototype, "alpha", {
  1512. /** Gets or sets alpha value for the control (1 means opaque and 0 means entirely transparent) */
  1513. get: function () {
  1514. return this._alpha;
  1515. },
  1516. set: function (value) {
  1517. if (this._alpha === value) {
  1518. return;
  1519. }
  1520. this._alphaSet = true;
  1521. this._alpha = value;
  1522. this._markAsDirty();
  1523. },
  1524. enumerable: true,
  1525. configurable: true
  1526. });
  1527. Object.defineProperty(Control.prototype, "scaleX", {
  1528. /** Gets or sets a value indicating the scale factor on X axis (1 by default)
  1529. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  1530. */
  1531. get: function () {
  1532. return this._scaleX;
  1533. },
  1534. set: function (value) {
  1535. if (this._scaleX === value) {
  1536. return;
  1537. }
  1538. this._scaleX = value;
  1539. this._markAsDirty();
  1540. this._markMatrixAsDirty();
  1541. },
  1542. enumerable: true,
  1543. configurable: true
  1544. });
  1545. Object.defineProperty(Control.prototype, "scaleY", {
  1546. /** Gets or sets a value indicating the scale factor on Y axis (1 by default)
  1547. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  1548. */
  1549. get: function () {
  1550. return this._scaleY;
  1551. },
  1552. set: function (value) {
  1553. if (this._scaleY === value) {
  1554. return;
  1555. }
  1556. this._scaleY = value;
  1557. this._markAsDirty();
  1558. this._markMatrixAsDirty();
  1559. },
  1560. enumerable: true,
  1561. configurable: true
  1562. });
  1563. Object.defineProperty(Control.prototype, "rotation", {
  1564. /** Gets or sets the rotation angle (0 by default)
  1565. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  1566. */
  1567. get: function () {
  1568. return this._rotation;
  1569. },
  1570. set: function (value) {
  1571. if (this._rotation === value) {
  1572. return;
  1573. }
  1574. this._rotation = value;
  1575. this._markAsDirty();
  1576. this._markMatrixAsDirty();
  1577. },
  1578. enumerable: true,
  1579. configurable: true
  1580. });
  1581. Object.defineProperty(Control.prototype, "transformCenterY", {
  1582. /** Gets or sets the transformation center on Y axis (0 by default)
  1583. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  1584. */
  1585. get: function () {
  1586. return this._transformCenterY;
  1587. },
  1588. set: function (value) {
  1589. if (this._transformCenterY === value) {
  1590. return;
  1591. }
  1592. this._transformCenterY = value;
  1593. this._markAsDirty();
  1594. this._markMatrixAsDirty();
  1595. },
  1596. enumerable: true,
  1597. configurable: true
  1598. });
  1599. Object.defineProperty(Control.prototype, "transformCenterX", {
  1600. /** Gets or sets the transformation center on X axis (0 by default)
  1601. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  1602. */
  1603. get: function () {
  1604. return this._transformCenterX;
  1605. },
  1606. set: function (value) {
  1607. if (this._transformCenterX === value) {
  1608. return;
  1609. }
  1610. this._transformCenterX = value;
  1611. this._markAsDirty();
  1612. this._markMatrixAsDirty();
  1613. },
  1614. enumerable: true,
  1615. configurable: true
  1616. });
  1617. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  1618. /**
  1619. * Gets or sets the horizontal alignment
  1620. * @see http://doc.babylonjs.com/how_to/gui#alignments
  1621. */
  1622. get: function () {
  1623. return this._horizontalAlignment;
  1624. },
  1625. set: function (value) {
  1626. if (this._horizontalAlignment === value) {
  1627. return;
  1628. }
  1629. this._horizontalAlignment = value;
  1630. this._markAsDirty();
  1631. },
  1632. enumerable: true,
  1633. configurable: true
  1634. });
  1635. Object.defineProperty(Control.prototype, "verticalAlignment", {
  1636. /**
  1637. * Gets or sets the vertical alignment
  1638. * @see http://doc.babylonjs.com/how_to/gui#alignments
  1639. */
  1640. get: function () {
  1641. return this._verticalAlignment;
  1642. },
  1643. set: function (value) {
  1644. if (this._verticalAlignment === value) {
  1645. return;
  1646. }
  1647. this._verticalAlignment = value;
  1648. this._markAsDirty();
  1649. },
  1650. enumerable: true,
  1651. configurable: true
  1652. });
  1653. Object.defineProperty(Control.prototype, "width", {
  1654. /**
  1655. * Gets or sets control width
  1656. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1657. */
  1658. get: function () {
  1659. return this._width.toString(this._host);
  1660. },
  1661. set: function (value) {
  1662. if (this._width.toString(this._host) === value) {
  1663. return;
  1664. }
  1665. if (this._width.fromString(value)) {
  1666. this._markAsDirty();
  1667. }
  1668. },
  1669. enumerable: true,
  1670. configurable: true
  1671. });
  1672. Object.defineProperty(Control.prototype, "widthInPixels", {
  1673. /**
  1674. * Gets control width in pixel
  1675. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1676. */
  1677. get: function () {
  1678. return this._width.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1679. },
  1680. enumerable: true,
  1681. configurable: true
  1682. });
  1683. Object.defineProperty(Control.prototype, "height", {
  1684. /**
  1685. * Gets or sets control height
  1686. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1687. */
  1688. get: function () {
  1689. return this._height.toString(this._host);
  1690. },
  1691. set: function (value) {
  1692. if (this._height.toString(this._host) === value) {
  1693. return;
  1694. }
  1695. if (this._height.fromString(value)) {
  1696. this._markAsDirty();
  1697. }
  1698. },
  1699. enumerable: true,
  1700. configurable: true
  1701. });
  1702. Object.defineProperty(Control.prototype, "heightInPixels", {
  1703. /**
  1704. * Gets control height in pixel
  1705. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1706. */
  1707. get: function () {
  1708. return this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1709. },
  1710. enumerable: true,
  1711. configurable: true
  1712. });
  1713. Object.defineProperty(Control.prototype, "fontFamily", {
  1714. /** Gets or set font family */
  1715. get: function () {
  1716. return this._fontFamily;
  1717. },
  1718. set: function (value) {
  1719. if (this._fontFamily === value) {
  1720. return;
  1721. }
  1722. this._fontFamily = value;
  1723. this._resetFontCache();
  1724. },
  1725. enumerable: true,
  1726. configurable: true
  1727. });
  1728. Object.defineProperty(Control.prototype, "fontStyle", {
  1729. /** Gets or sets font style */
  1730. get: function () {
  1731. return this._fontStyle;
  1732. },
  1733. set: function (value) {
  1734. if (this._fontStyle === value) {
  1735. return;
  1736. }
  1737. this._fontStyle = value;
  1738. this._resetFontCache();
  1739. },
  1740. enumerable: true,
  1741. configurable: true
  1742. });
  1743. Object.defineProperty(Control.prototype, "fontWeight", {
  1744. /** Gets or sets font weight */
  1745. get: function () {
  1746. return this._fontWeight;
  1747. },
  1748. set: function (value) {
  1749. if (this._fontWeight === value) {
  1750. return;
  1751. }
  1752. this._fontWeight = value;
  1753. this._resetFontCache();
  1754. },
  1755. enumerable: true,
  1756. configurable: true
  1757. });
  1758. Object.defineProperty(Control.prototype, "style", {
  1759. /**
  1760. * Gets or sets style
  1761. * @see http://doc.babylonjs.com/how_to/gui#styles
  1762. */
  1763. get: function () {
  1764. return this._style;
  1765. },
  1766. set: function (value) {
  1767. var _this = this;
  1768. if (this._style) {
  1769. this._style.onChangedObservable.remove(this._styleObserver);
  1770. this._styleObserver = null;
  1771. }
  1772. this._style = value;
  1773. if (this._style) {
  1774. this._styleObserver = this._style.onChangedObservable.add(function () {
  1775. _this._markAsDirty();
  1776. _this._resetFontCache();
  1777. });
  1778. }
  1779. this._markAsDirty();
  1780. this._resetFontCache();
  1781. },
  1782. enumerable: true,
  1783. configurable: true
  1784. });
  1785. Object.defineProperty(Control.prototype, "_isFontSizeInPercentage", {
  1786. /** @hidden */
  1787. get: function () {
  1788. return this._fontSize.isPercentage;
  1789. },
  1790. enumerable: true,
  1791. configurable: true
  1792. });
  1793. Object.defineProperty(Control.prototype, "fontSizeInPixels", {
  1794. /** Gets font size in pixels */
  1795. get: function () {
  1796. var fontSizeToUse = this._style ? this._style._fontSize : this._fontSize;
  1797. if (fontSizeToUse.isPixel) {
  1798. return fontSizeToUse.getValue(this._host);
  1799. }
  1800. return fontSizeToUse.getValueInPixel(this._host, this._tempParentMeasure.height || this._cachedParentMeasure.height);
  1801. },
  1802. enumerable: true,
  1803. configurable: true
  1804. });
  1805. Object.defineProperty(Control.prototype, "fontSize", {
  1806. /** Gets or sets font size */
  1807. get: function () {
  1808. return this._fontSize.toString(this._host);
  1809. },
  1810. set: function (value) {
  1811. if (this._fontSize.toString(this._host) === value) {
  1812. return;
  1813. }
  1814. if (this._fontSize.fromString(value)) {
  1815. this._markAsDirty();
  1816. this._resetFontCache();
  1817. }
  1818. },
  1819. enumerable: true,
  1820. configurable: true
  1821. });
  1822. Object.defineProperty(Control.prototype, "color", {
  1823. /** Gets or sets foreground color */
  1824. get: function () {
  1825. return this._color;
  1826. },
  1827. set: function (value) {
  1828. if (this._color === value) {
  1829. return;
  1830. }
  1831. this._color = value;
  1832. this._markAsDirty();
  1833. },
  1834. enumerable: true,
  1835. configurable: true
  1836. });
  1837. Object.defineProperty(Control.prototype, "zIndex", {
  1838. /** Gets or sets z index which is used to reorder controls on the z axis */
  1839. get: function () {
  1840. return this._zIndex;
  1841. },
  1842. set: function (value) {
  1843. if (this.zIndex === value) {
  1844. return;
  1845. }
  1846. this._zIndex = value;
  1847. if (this._root) {
  1848. this._root._reOrderControl(this);
  1849. }
  1850. },
  1851. enumerable: true,
  1852. configurable: true
  1853. });
  1854. Object.defineProperty(Control.prototype, "notRenderable", {
  1855. /** Gets or sets a boolean indicating if the control can be rendered */
  1856. get: function () {
  1857. return this._doNotRender;
  1858. },
  1859. set: function (value) {
  1860. if (this._doNotRender === value) {
  1861. return;
  1862. }
  1863. this._doNotRender = value;
  1864. this._markAsDirty();
  1865. },
  1866. enumerable: true,
  1867. configurable: true
  1868. });
  1869. Object.defineProperty(Control.prototype, "isVisible", {
  1870. /** Gets or sets a boolean indicating if the control is visible */
  1871. get: function () {
  1872. return this._isVisible;
  1873. },
  1874. set: function (value) {
  1875. if (this._isVisible === value) {
  1876. return;
  1877. }
  1878. this._isVisible = value;
  1879. this._markAsDirty();
  1880. },
  1881. enumerable: true,
  1882. configurable: true
  1883. });
  1884. Object.defineProperty(Control.prototype, "isDirty", {
  1885. /** Gets a boolean indicating that the control needs to update its rendering */
  1886. get: function () {
  1887. return this._isDirty;
  1888. },
  1889. enumerable: true,
  1890. configurable: true
  1891. });
  1892. Object.defineProperty(Control.prototype, "paddingLeft", {
  1893. /**
  1894. * Gets or sets a value indicating the padding to use on the left of the control
  1895. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1896. */
  1897. get: function () {
  1898. return this._paddingLeft.toString(this._host);
  1899. },
  1900. set: function (value) {
  1901. if (this._paddingLeft.fromString(value)) {
  1902. this._markAsDirty();
  1903. }
  1904. },
  1905. enumerable: true,
  1906. configurable: true
  1907. });
  1908. Object.defineProperty(Control.prototype, "paddingLeftInPixels", {
  1909. /**
  1910. * Gets a value indicating the padding in pixels to use on the left of the control
  1911. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1912. */
  1913. get: function () {
  1914. return this._paddingLeft.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1915. },
  1916. enumerable: true,
  1917. configurable: true
  1918. });
  1919. Object.defineProperty(Control.prototype, "paddingRight", {
  1920. /**
  1921. * Gets or sets a value indicating the padding to use on the right of the control
  1922. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1923. */
  1924. get: function () {
  1925. return this._paddingRight.toString(this._host);
  1926. },
  1927. set: function (value) {
  1928. if (this._paddingRight.fromString(value)) {
  1929. this._markAsDirty();
  1930. }
  1931. },
  1932. enumerable: true,
  1933. configurable: true
  1934. });
  1935. Object.defineProperty(Control.prototype, "paddingRightInPixels", {
  1936. /**
  1937. * Gets a value indicating the padding in pixels to use on the right of the control
  1938. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1939. */
  1940. get: function () {
  1941. return this._paddingRight.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1942. },
  1943. enumerable: true,
  1944. configurable: true
  1945. });
  1946. Object.defineProperty(Control.prototype, "paddingTop", {
  1947. /**
  1948. * Gets or sets a value indicating the padding to use on the top of the control
  1949. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1950. */
  1951. get: function () {
  1952. return this._paddingTop.toString(this._host);
  1953. },
  1954. set: function (value) {
  1955. if (this._paddingTop.fromString(value)) {
  1956. this._markAsDirty();
  1957. }
  1958. },
  1959. enumerable: true,
  1960. configurable: true
  1961. });
  1962. Object.defineProperty(Control.prototype, "paddingTopInPixels", {
  1963. /**
  1964. * Gets a value indicating the padding in pixels to use on the top of the control
  1965. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1966. */
  1967. get: function () {
  1968. return this._paddingTop.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1969. },
  1970. enumerable: true,
  1971. configurable: true
  1972. });
  1973. Object.defineProperty(Control.prototype, "paddingBottom", {
  1974. /**
  1975. * Gets or sets a value indicating the padding to use on the bottom of the control
  1976. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1977. */
  1978. get: function () {
  1979. return this._paddingBottom.toString(this._host);
  1980. },
  1981. set: function (value) {
  1982. if (this._paddingBottom.fromString(value)) {
  1983. this._markAsDirty();
  1984. }
  1985. },
  1986. enumerable: true,
  1987. configurable: true
  1988. });
  1989. Object.defineProperty(Control.prototype, "paddingBottomInPixels", {
  1990. /**
  1991. * Gets a value indicating the padding in pixels to use on the bottom of the control
  1992. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  1993. */
  1994. get: function () {
  1995. return this._paddingBottom.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1996. },
  1997. enumerable: true,
  1998. configurable: true
  1999. });
  2000. Object.defineProperty(Control.prototype, "left", {
  2001. /**
  2002. * Gets or sets a value indicating the left coordinate of the control
  2003. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2004. */
  2005. get: function () {
  2006. return this._left.toString(this._host);
  2007. },
  2008. set: function (value) {
  2009. if (this._left.fromString(value)) {
  2010. this._markAsDirty();
  2011. }
  2012. },
  2013. enumerable: true,
  2014. configurable: true
  2015. });
  2016. Object.defineProperty(Control.prototype, "leftInPixels", {
  2017. /**
  2018. * Gets a value indicating the left coordinate in pixels of the control
  2019. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2020. */
  2021. get: function () {
  2022. return this._left.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2023. },
  2024. enumerable: true,
  2025. configurable: true
  2026. });
  2027. Object.defineProperty(Control.prototype, "top", {
  2028. /**
  2029. * Gets or sets a value indicating the top coordinate of the control
  2030. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2031. */
  2032. get: function () {
  2033. return this._top.toString(this._host);
  2034. },
  2035. set: function (value) {
  2036. if (this._top.fromString(value)) {
  2037. this._markAsDirty();
  2038. }
  2039. },
  2040. enumerable: true,
  2041. configurable: true
  2042. });
  2043. Object.defineProperty(Control.prototype, "topInPixels", {
  2044. /**
  2045. * Gets a value indicating the top coordinate in pixels of the control
  2046. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2047. */
  2048. get: function () {
  2049. return this._top.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2050. },
  2051. enumerable: true,
  2052. configurable: true
  2053. });
  2054. Object.defineProperty(Control.prototype, "linkOffsetX", {
  2055. /**
  2056. * Gets or sets a value indicating the offset on X axis to the linked mesh
  2057. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2058. */
  2059. get: function () {
  2060. return this._linkOffsetX.toString(this._host);
  2061. },
  2062. set: function (value) {
  2063. if (this._linkOffsetX.fromString(value)) {
  2064. this._markAsDirty();
  2065. }
  2066. },
  2067. enumerable: true,
  2068. configurable: true
  2069. });
  2070. Object.defineProperty(Control.prototype, "linkOffsetXInPixels", {
  2071. /**
  2072. * Gets a value indicating the offset in pixels on X axis to the linked mesh
  2073. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2074. */
  2075. get: function () {
  2076. return this._linkOffsetX.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2077. },
  2078. enumerable: true,
  2079. configurable: true
  2080. });
  2081. Object.defineProperty(Control.prototype, "linkOffsetY", {
  2082. /**
  2083. * Gets or sets a value indicating the offset on Y axis to the linked mesh
  2084. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2085. */
  2086. get: function () {
  2087. return this._linkOffsetY.toString(this._host);
  2088. },
  2089. set: function (value) {
  2090. if (this._linkOffsetY.fromString(value)) {
  2091. this._markAsDirty();
  2092. }
  2093. },
  2094. enumerable: true,
  2095. configurable: true
  2096. });
  2097. Object.defineProperty(Control.prototype, "linkOffsetYInPixels", {
  2098. /**
  2099. * Gets a value indicating the offset in pixels on Y axis to the linked mesh
  2100. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2101. */
  2102. get: function () {
  2103. return this._linkOffsetY.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2104. },
  2105. enumerable: true,
  2106. configurable: true
  2107. });
  2108. Object.defineProperty(Control.prototype, "centerX", {
  2109. /** Gets the center coordinate on X axis */
  2110. get: function () {
  2111. return this._currentMeasure.left + this._currentMeasure.width / 2;
  2112. },
  2113. enumerable: true,
  2114. configurable: true
  2115. });
  2116. Object.defineProperty(Control.prototype, "centerY", {
  2117. /** Gets the center coordinate on Y axis */
  2118. get: function () {
  2119. return this._currentMeasure.top + this._currentMeasure.height / 2;
  2120. },
  2121. enumerable: true,
  2122. configurable: true
  2123. });
  2124. /** @hidden */
  2125. Control.prototype._getTypeName = function () {
  2126. return "Control";
  2127. };
  2128. /** @hidden */
  2129. Control.prototype._resetFontCache = function () {
  2130. this._fontSet = true;
  2131. };
  2132. /**
  2133. * Gets coordinates in local control space
  2134. * @param globalCoordinates defines the coordinates to transform
  2135. * @returns the new coordinates in local space
  2136. */
  2137. Control.prototype.getLocalCoordinates = function (globalCoordinates) {
  2138. var result = BABYLON.Vector2.Zero();
  2139. this.getLocalCoordinatesToRef(globalCoordinates, result);
  2140. return result;
  2141. };
  2142. /**
  2143. * Gets coordinates in local control space
  2144. * @param globalCoordinates defines the coordinates to transform
  2145. * @param result defines the target vector2 where to store the result
  2146. * @returns the current control
  2147. */
  2148. Control.prototype.getLocalCoordinatesToRef = function (globalCoordinates, result) {
  2149. result.x = globalCoordinates.x - this._currentMeasure.left;
  2150. result.y = globalCoordinates.y - this._currentMeasure.top;
  2151. return this;
  2152. };
  2153. /**
  2154. * Gets coordinates in parent local control space
  2155. * @param globalCoordinates defines the coordinates to transform
  2156. * @returns the new coordinates in parent local space
  2157. */
  2158. Control.prototype.getParentLocalCoordinates = function (globalCoordinates) {
  2159. var result = BABYLON.Vector2.Zero();
  2160. result.x = globalCoordinates.x - this._cachedParentMeasure.left;
  2161. result.y = globalCoordinates.y - this._cachedParentMeasure.top;
  2162. return result;
  2163. };
  2164. /**
  2165. * Move the current control to a vector3 position projected onto the screen.
  2166. * @param position defines the target position
  2167. * @param scene defines the hosting scene
  2168. */
  2169. Control.prototype.moveToVector3 = function (position, scene) {
  2170. if (!this._host || this._root !== this._host._rootContainer) {
  2171. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  2172. return;
  2173. }
  2174. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2175. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2176. var globalViewport = this._host._getGlobalViewport(scene);
  2177. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  2178. this._moveToProjectedPosition(projectedPosition);
  2179. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  2180. this.notRenderable = true;
  2181. return;
  2182. }
  2183. this.notRenderable = false;
  2184. };
  2185. /**
  2186. * Link current control with a target mesh
  2187. * @param mesh defines the mesh to link with
  2188. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2189. */
  2190. Control.prototype.linkWithMesh = function (mesh) {
  2191. if (!this._host || this._root && this._root !== this._host._rootContainer) {
  2192. if (mesh) {
  2193. BABYLON.Tools.Error("Cannot link a control to a mesh if the control is not at root level");
  2194. }
  2195. return;
  2196. }
  2197. var index = this._host._linkedControls.indexOf(this);
  2198. if (index !== -1) {
  2199. this._linkedMesh = mesh;
  2200. if (!mesh) {
  2201. this._host._linkedControls.splice(index, 1);
  2202. }
  2203. return;
  2204. }
  2205. else if (!mesh) {
  2206. return;
  2207. }
  2208. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2209. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2210. this._linkedMesh = mesh;
  2211. this._onlyMeasureMode = true;
  2212. this._host._linkedControls.push(this);
  2213. };
  2214. /** @hidden */
  2215. Control.prototype._moveToProjectedPosition = function (projectedPosition) {
  2216. var oldLeft = this._left.getValue(this._host);
  2217. var oldTop = this._top.getValue(this._host);
  2218. var newLeft = ((projectedPosition.x + this._linkOffsetX.getValue(this._host)) - this._currentMeasure.width / 2);
  2219. var newTop = ((projectedPosition.y + this._linkOffsetY.getValue(this._host)) - this._currentMeasure.height / 2);
  2220. if (this._left.ignoreAdaptiveScaling && this._top.ignoreAdaptiveScaling) {
  2221. if (Math.abs(newLeft - oldLeft) < 0.5) {
  2222. newLeft = oldLeft;
  2223. }
  2224. if (Math.abs(newTop - oldTop) < 0.5) {
  2225. newTop = oldTop;
  2226. }
  2227. }
  2228. this.left = newLeft + "px";
  2229. this.top = newTop + "px";
  2230. this._left.ignoreAdaptiveScaling = true;
  2231. this._top.ignoreAdaptiveScaling = true;
  2232. };
  2233. /** @hidden */
  2234. Control.prototype._markMatrixAsDirty = function () {
  2235. this._isMatrixDirty = true;
  2236. this._markAsDirty();
  2237. };
  2238. /** @hidden */
  2239. Control.prototype._markAsDirty = function () {
  2240. this._isDirty = true;
  2241. if (!this._host) {
  2242. return; // Not yet connected
  2243. }
  2244. this._host.markAsDirty();
  2245. };
  2246. /** @hidden */
  2247. Control.prototype._markAllAsDirty = function () {
  2248. this._markAsDirty();
  2249. if (this._font) {
  2250. this._prepareFont();
  2251. }
  2252. };
  2253. /** @hidden */
  2254. Control.prototype._link = function (root, host) {
  2255. this._root = root;
  2256. this._host = host;
  2257. };
  2258. /** @hidden */
  2259. Control.prototype._transform = function (context) {
  2260. if (!this._isMatrixDirty && this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  2261. return;
  2262. }
  2263. // postTranslate
  2264. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  2265. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  2266. context.translate(offsetX, offsetY);
  2267. // rotate
  2268. context.rotate(this._rotation);
  2269. // scale
  2270. context.scale(this._scaleX, this._scaleY);
  2271. // preTranslate
  2272. context.translate(-offsetX, -offsetY);
  2273. // Need to update matrices?
  2274. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  2275. this._cachedOffsetX = offsetX;
  2276. this._cachedOffsetY = offsetY;
  2277. this._isMatrixDirty = false;
  2278. GUI.Matrix2D.ComposeToRef(-offsetX, -offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  2279. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  2280. }
  2281. };
  2282. /** @hidden */
  2283. Control.prototype._applyStates = function (context) {
  2284. if (this._fontSet) {
  2285. this._prepareFont();
  2286. this._fontSet = false;
  2287. }
  2288. if (this._font) {
  2289. context.font = this._font;
  2290. }
  2291. if (this._color) {
  2292. context.fillStyle = this._color;
  2293. }
  2294. if (this._alphaSet) {
  2295. context.globalAlpha = this._alpha;
  2296. }
  2297. };
  2298. /** @hidden */
  2299. Control.prototype._processMeasures = function (parentMeasure, context) {
  2300. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  2301. this._isDirty = false;
  2302. this._currentMeasure.copyFrom(parentMeasure);
  2303. // Let children take some pre-measurement actions
  2304. this._preMeasure(parentMeasure, context);
  2305. this._measure();
  2306. this._computeAlignment(parentMeasure, context);
  2307. // Convert to int values
  2308. this._currentMeasure.left = this._currentMeasure.left | 0;
  2309. this._currentMeasure.top = this._currentMeasure.top | 0;
  2310. this._currentMeasure.width = this._currentMeasure.width | 0;
  2311. this._currentMeasure.height = this._currentMeasure.height | 0;
  2312. // Let children add more features
  2313. this._additionalProcessing(parentMeasure, context);
  2314. this._cachedParentMeasure.copyFrom(parentMeasure);
  2315. if (this.onDirtyObservable.hasObservers()) {
  2316. this.onDirtyObservable.notifyObservers(this);
  2317. }
  2318. }
  2319. if (this._currentMeasure.left > parentMeasure.left + parentMeasure.width) {
  2320. return false;
  2321. }
  2322. if (this._currentMeasure.left + this._currentMeasure.width < parentMeasure.left) {
  2323. return false;
  2324. }
  2325. if (this._currentMeasure.top > parentMeasure.top + parentMeasure.height) {
  2326. return false;
  2327. }
  2328. if (this._currentMeasure.top + this._currentMeasure.height < parentMeasure.top) {
  2329. return false;
  2330. }
  2331. // Transform
  2332. this._transform(context);
  2333. if (this._onlyMeasureMode) {
  2334. this._onlyMeasureMode = false;
  2335. return false; // We do not want rendering for this frame as they are measure dependant information that need to be gathered
  2336. }
  2337. // Clip
  2338. this._clip(context);
  2339. context.clip();
  2340. return true;
  2341. };
  2342. /** @hidden */
  2343. Control.prototype._clip = function (context) {
  2344. context.beginPath();
  2345. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2346. var shadowOffsetX = this.shadowOffsetX;
  2347. var shadowOffsetY = this.shadowOffsetY;
  2348. var shadowBlur = this.shadowBlur;
  2349. var leftShadowOffset = Math.min(Math.min(shadowOffsetX, 0) - shadowBlur * 2, 0);
  2350. var rightShadowOffset = Math.max(Math.max(shadowOffsetX, 0) + shadowBlur * 2, 0);
  2351. var topShadowOffset = Math.min(Math.min(shadowOffsetY, 0) - shadowBlur * 2, 0);
  2352. var bottomShadowOffset = Math.max(Math.max(shadowOffsetY, 0) + shadowBlur * 2, 0);
  2353. context.rect(this._currentMeasure.left + leftShadowOffset, this._currentMeasure.top + topShadowOffset, this._currentMeasure.width + rightShadowOffset - leftShadowOffset, this._currentMeasure.height + bottomShadowOffset - topShadowOffset);
  2354. }
  2355. else {
  2356. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2357. }
  2358. };
  2359. /** @hidden */
  2360. Control.prototype._measure = function () {
  2361. // Width / Height
  2362. if (this._width.isPixel) {
  2363. this._currentMeasure.width = this._width.getValue(this._host);
  2364. }
  2365. else {
  2366. this._currentMeasure.width *= this._width.getValue(this._host);
  2367. }
  2368. if (this._height.isPixel) {
  2369. this._currentMeasure.height = this._height.getValue(this._host);
  2370. }
  2371. else {
  2372. this._currentMeasure.height *= this._height.getValue(this._host);
  2373. }
  2374. };
  2375. /** @hidden */
  2376. Control.prototype._computeAlignment = function (parentMeasure, context) {
  2377. var width = this._currentMeasure.width;
  2378. var height = this._currentMeasure.height;
  2379. var parentWidth = parentMeasure.width;
  2380. var parentHeight = parentMeasure.height;
  2381. // Left / top
  2382. var x = 0;
  2383. var y = 0;
  2384. switch (this.horizontalAlignment) {
  2385. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  2386. x = 0;
  2387. break;
  2388. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  2389. x = parentWidth - width;
  2390. break;
  2391. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  2392. x = (parentWidth - width) / 2;
  2393. break;
  2394. }
  2395. switch (this.verticalAlignment) {
  2396. case Control.VERTICAL_ALIGNMENT_TOP:
  2397. y = 0;
  2398. break;
  2399. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  2400. y = parentHeight - height;
  2401. break;
  2402. case Control.VERTICAL_ALIGNMENT_CENTER:
  2403. y = (parentHeight - height) / 2;
  2404. break;
  2405. }
  2406. if (this._paddingLeft.isPixel) {
  2407. this._currentMeasure.left += this._paddingLeft.getValue(this._host);
  2408. this._currentMeasure.width -= this._paddingLeft.getValue(this._host);
  2409. }
  2410. else {
  2411. this._currentMeasure.left += parentWidth * this._paddingLeft.getValue(this._host);
  2412. this._currentMeasure.width -= parentWidth * this._paddingLeft.getValue(this._host);
  2413. }
  2414. if (this._paddingRight.isPixel) {
  2415. this._currentMeasure.width -= this._paddingRight.getValue(this._host);
  2416. }
  2417. else {
  2418. this._currentMeasure.width -= parentWidth * this._paddingRight.getValue(this._host);
  2419. }
  2420. if (this._paddingTop.isPixel) {
  2421. this._currentMeasure.top += this._paddingTop.getValue(this._host);
  2422. this._currentMeasure.height -= this._paddingTop.getValue(this._host);
  2423. }
  2424. else {
  2425. this._currentMeasure.top += parentHeight * this._paddingTop.getValue(this._host);
  2426. this._currentMeasure.height -= parentHeight * this._paddingTop.getValue(this._host);
  2427. }
  2428. if (this._paddingBottom.isPixel) {
  2429. this._currentMeasure.height -= this._paddingBottom.getValue(this._host);
  2430. }
  2431. else {
  2432. this._currentMeasure.height -= parentHeight * this._paddingBottom.getValue(this._host);
  2433. }
  2434. if (this._left.isPixel) {
  2435. this._currentMeasure.left += this._left.getValue(this._host);
  2436. }
  2437. else {
  2438. this._currentMeasure.left += parentWidth * this._left.getValue(this._host);
  2439. }
  2440. if (this._top.isPixel) {
  2441. this._currentMeasure.top += this._top.getValue(this._host);
  2442. }
  2443. else {
  2444. this._currentMeasure.top += parentHeight * this._top.getValue(this._host);
  2445. }
  2446. this._currentMeasure.left += x;
  2447. this._currentMeasure.top += y;
  2448. };
  2449. /** @hidden */
  2450. Control.prototype._preMeasure = function (parentMeasure, context) {
  2451. // Do nothing
  2452. };
  2453. /** @hidden */
  2454. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  2455. // Do nothing
  2456. };
  2457. /** @hidden */
  2458. Control.prototype._draw = function (parentMeasure, context) {
  2459. // Do nothing
  2460. };
  2461. /**
  2462. * Tests if a given coordinates belong to the current control
  2463. * @param x defines x coordinate to test
  2464. * @param y defines y coordinate to test
  2465. * @returns true if the coordinates are inside the control
  2466. */
  2467. Control.prototype.contains = function (x, y) {
  2468. // Invert transform
  2469. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  2470. x = this._transformedPosition.x;
  2471. y = this._transformedPosition.y;
  2472. // Check
  2473. if (x < this._currentMeasure.left) {
  2474. return false;
  2475. }
  2476. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  2477. return false;
  2478. }
  2479. if (y < this._currentMeasure.top) {
  2480. return false;
  2481. }
  2482. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  2483. return false;
  2484. }
  2485. if (this.isPointerBlocker) {
  2486. this._host._shouldBlockPointer = true;
  2487. }
  2488. return true;
  2489. };
  2490. /** @hidden */
  2491. Control.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  2492. if (!this.isHitTestVisible || !this.isVisible || this._doNotRender) {
  2493. return false;
  2494. }
  2495. if (!this.contains(x, y)) {
  2496. return false;
  2497. }
  2498. this._processObservables(type, x, y, pointerId, buttonIndex);
  2499. return true;
  2500. };
  2501. /** @hidden */
  2502. Control.prototype._onPointerMove = function (target, coordinates) {
  2503. var canNotify = this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  2504. if (canNotify && this.parent != null)
  2505. this.parent._onPointerMove(target, coordinates);
  2506. };
  2507. /** @hidden */
  2508. Control.prototype._onPointerEnter = function (target) {
  2509. if (this._enterCount > 0) {
  2510. return false;
  2511. }
  2512. if (this._enterCount === -1) { // -1 is for touch input, we are now sure we are with a mouse or pencil
  2513. this._enterCount = 0;
  2514. }
  2515. this._enterCount++;
  2516. var canNotify = this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  2517. if (canNotify && this.parent != null)
  2518. this.parent._onPointerEnter(target);
  2519. return true;
  2520. };
  2521. /** @hidden */
  2522. Control.prototype._onPointerOut = function (target) {
  2523. this._enterCount = 0;
  2524. var canNotify = this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  2525. if (canNotify && this.parent != null)
  2526. this.parent._onPointerOut(target);
  2527. };
  2528. /** @hidden */
  2529. Control.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  2530. if (this._downCount !== 0) {
  2531. return false;
  2532. }
  2533. this._downCount++;
  2534. this._downPointerIds[pointerId] = true;
  2535. var canNotify = this.onPointerDownObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  2536. if (canNotify && this.parent != null)
  2537. this.parent._onPointerDown(target, coordinates, pointerId, buttonIndex);
  2538. return true;
  2539. };
  2540. /** @hidden */
  2541. Control.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  2542. this._downCount = 0;
  2543. delete this._downPointerIds[pointerId];
  2544. var canNotifyClick = notifyClick;
  2545. if (notifyClick && (this._enterCount > 0 || this._enterCount === -1)) {
  2546. canNotifyClick = this.onPointerClickObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  2547. }
  2548. var canNotify = this.onPointerUpObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  2549. if (canNotify && this.parent != null)
  2550. this.parent._onPointerUp(target, coordinates, pointerId, buttonIndex, canNotifyClick);
  2551. };
  2552. /** @hidden */
  2553. Control.prototype._forcePointerUp = function (pointerId) {
  2554. if (pointerId === void 0) { pointerId = null; }
  2555. if (pointerId !== null) {
  2556. this._onPointerUp(this, BABYLON.Vector2.Zero(), pointerId, 0, true);
  2557. }
  2558. else {
  2559. for (var key in this._downPointerIds) {
  2560. this._onPointerUp(this, BABYLON.Vector2.Zero(), +key, 0, true);
  2561. }
  2562. }
  2563. };
  2564. /** @hidden */
  2565. Control.prototype._processObservables = function (type, x, y, pointerId, buttonIndex) {
  2566. this._dummyVector2.copyFromFloats(x, y);
  2567. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  2568. this._onPointerMove(this, this._dummyVector2);
  2569. var previousControlOver = this._host._lastControlOver[pointerId];
  2570. if (previousControlOver && previousControlOver !== this) {
  2571. previousControlOver._onPointerOut(this);
  2572. }
  2573. if (previousControlOver !== this) {
  2574. this._onPointerEnter(this);
  2575. }
  2576. this._host._lastControlOver[pointerId] = this;
  2577. return true;
  2578. }
  2579. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  2580. this._onPointerDown(this, this._dummyVector2, pointerId, buttonIndex);
  2581. this._host._lastControlDown[pointerId] = this;
  2582. this._host._lastPickedControl = this;
  2583. return true;
  2584. }
  2585. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  2586. if (this._host._lastControlDown[pointerId]) {
  2587. this._host._lastControlDown[pointerId]._onPointerUp(this, this._dummyVector2, pointerId, buttonIndex, true);
  2588. }
  2589. delete this._host._lastControlDown[pointerId];
  2590. return true;
  2591. }
  2592. return false;
  2593. };
  2594. Control.prototype._prepareFont = function () {
  2595. if (!this._font && !this._fontSet) {
  2596. return;
  2597. }
  2598. if (this._style) {
  2599. this._font = (this._style.fontWeight ? this._style.fontWeight : this._style.fontStyle) + " " + this.fontSizeInPixels + "px " + this._style.fontFamily;
  2600. }
  2601. else {
  2602. this._font = (this._fontWeight ? this._fontWeight : this._fontStyle) + " " + this.fontSizeInPixels + "px " + this._fontFamily;
  2603. }
  2604. this._fontOffset = Control._GetFontOffset(this._font);
  2605. };
  2606. /** Releases associated resources */
  2607. Control.prototype.dispose = function () {
  2608. this.onDirtyObservable.clear();
  2609. this.onAfterDrawObservable.clear();
  2610. this.onPointerDownObservable.clear();
  2611. this.onPointerEnterObservable.clear();
  2612. this.onPointerMoveObservable.clear();
  2613. this.onPointerOutObservable.clear();
  2614. this.onPointerUpObservable.clear();
  2615. this.onPointerClickObservable.clear();
  2616. if (this._styleObserver && this._style) {
  2617. this._style.onChangedObservable.remove(this._styleObserver);
  2618. this._styleObserver = null;
  2619. }
  2620. if (this._root) {
  2621. this._root.removeControl(this);
  2622. this._root = null;
  2623. }
  2624. var index = this._host._linkedControls.indexOf(this);
  2625. if (index > -1) {
  2626. this.linkWithMesh(null);
  2627. }
  2628. };
  2629. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  2630. /** HORIZONTAL_ALIGNMENT_LEFT */
  2631. get: function () {
  2632. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  2633. },
  2634. enumerable: true,
  2635. configurable: true
  2636. });
  2637. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  2638. /** HORIZONTAL_ALIGNMENT_RIGHT */
  2639. get: function () {
  2640. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  2641. },
  2642. enumerable: true,
  2643. configurable: true
  2644. });
  2645. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  2646. /** HORIZONTAL_ALIGNMENT_CENTER */
  2647. get: function () {
  2648. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  2649. },
  2650. enumerable: true,
  2651. configurable: true
  2652. });
  2653. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  2654. /** VERTICAL_ALIGNMENT_TOP */
  2655. get: function () {
  2656. return Control._VERTICAL_ALIGNMENT_TOP;
  2657. },
  2658. enumerable: true,
  2659. configurable: true
  2660. });
  2661. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  2662. /** VERTICAL_ALIGNMENT_BOTTOM */
  2663. get: function () {
  2664. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  2665. },
  2666. enumerable: true,
  2667. configurable: true
  2668. });
  2669. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  2670. /** VERTICAL_ALIGNMENT_CENTER */
  2671. get: function () {
  2672. return Control._VERTICAL_ALIGNMENT_CENTER;
  2673. },
  2674. enumerable: true,
  2675. configurable: true
  2676. });
  2677. /** @hidden */
  2678. Control._GetFontOffset = function (font) {
  2679. if (Control._FontHeightSizes[font]) {
  2680. return Control._FontHeightSizes[font];
  2681. }
  2682. var text = document.createElement("span");
  2683. text.innerHTML = "Hg";
  2684. text.style.font = font;
  2685. var block = document.createElement("div");
  2686. block.style.display = "inline-block";
  2687. block.style.width = "1px";
  2688. block.style.height = "0px";
  2689. block.style.verticalAlign = "bottom";
  2690. var div = document.createElement("div");
  2691. div.appendChild(text);
  2692. div.appendChild(block);
  2693. document.body.appendChild(div);
  2694. var fontAscent = 0;
  2695. var fontHeight = 0;
  2696. try {
  2697. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  2698. block.style.verticalAlign = "baseline";
  2699. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  2700. }
  2701. finally {
  2702. document.body.removeChild(div);
  2703. }
  2704. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  2705. Control._FontHeightSizes[font] = result;
  2706. return result;
  2707. };
  2708. ;
  2709. /**
  2710. * Creates a stack panel that can be used to render headers
  2711. * @param control defines the control to associate with the header
  2712. * @param text defines the text of the header
  2713. * @param size defines the size of the header
  2714. * @param options defines options used to configure the header
  2715. * @returns a new StackPanel
  2716. */
  2717. Control.AddHeader = function (control, text, size, options) {
  2718. var panel = new BABYLON.GUI.StackPanel("panel");
  2719. var isHorizontal = options ? options.isHorizontal : true;
  2720. var controlFirst = options ? options.controlFirst : true;
  2721. panel.isVertical = !isHorizontal;
  2722. var header = new BABYLON.GUI.TextBlock("header");
  2723. header.text = text;
  2724. header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  2725. if (isHorizontal) {
  2726. header.width = size;
  2727. }
  2728. else {
  2729. header.height = size;
  2730. }
  2731. if (controlFirst) {
  2732. panel.addControl(control);
  2733. panel.addControl(header);
  2734. header.paddingLeft = "5px";
  2735. }
  2736. else {
  2737. panel.addControl(header);
  2738. panel.addControl(control);
  2739. header.paddingRight = "5px";
  2740. }
  2741. header.shadowBlur = control.shadowBlur;
  2742. header.shadowColor = control.shadowColor;
  2743. header.shadowOffsetX = control.shadowOffsetX;
  2744. header.shadowOffsetY = control.shadowOffsetY;
  2745. return panel;
  2746. };
  2747. /** @hidden */
  2748. Control.drawEllipse = function (x, y, width, height, context) {
  2749. context.translate(x, y);
  2750. context.scale(width, height);
  2751. context.beginPath();
  2752. context.arc(0, 0, 1, 0, 2 * Math.PI);
  2753. context.closePath();
  2754. context.scale(1 / width, 1 / height);
  2755. context.translate(-x, -y);
  2756. };
  2757. // Statics
  2758. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  2759. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  2760. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  2761. Control._VERTICAL_ALIGNMENT_TOP = 0;
  2762. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  2763. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  2764. Control._FontHeightSizes = {};
  2765. return Control;
  2766. }());
  2767. GUI.Control = Control;
  2768. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2769. })(BABYLON || (BABYLON = {}));
  2770. //# sourceMappingURL=control.js.map
  2771. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2772. var BABYLON;
  2773. (function (BABYLON) {
  2774. var GUI;
  2775. (function (GUI) {
  2776. /**
  2777. * Root class for 2D containers
  2778. * @see http://doc.babylonjs.com/how_to/gui#containers
  2779. */
  2780. var Container = /** @class */ (function (_super) {
  2781. __extends(Container, _super);
  2782. /**
  2783. * Creates a new Container
  2784. * @param name defines the name of the container
  2785. */
  2786. function Container(name) {
  2787. var _this = _super.call(this, name) || this;
  2788. _this.name = name;
  2789. /** @hidden */
  2790. _this._children = new Array();
  2791. /** @hidden */
  2792. _this._measureForChildren = GUI.Measure.Empty();
  2793. /** @hidden */
  2794. _this._adaptWidthToChildren = false;
  2795. /** @hidden */
  2796. _this._adaptHeightToChildren = false;
  2797. return _this;
  2798. }
  2799. Object.defineProperty(Container.prototype, "adaptHeightToChildren", {
  2800. /** Gets or sets a boolean indicating if the container should try to adapt to its children height */
  2801. get: function () {
  2802. return this._adaptHeightToChildren;
  2803. },
  2804. set: function (value) {
  2805. if (this._adaptHeightToChildren === value) {
  2806. return;
  2807. }
  2808. this._adaptHeightToChildren = value;
  2809. if (value) {
  2810. this.height = "100%";
  2811. }
  2812. this._markAsDirty();
  2813. },
  2814. enumerable: true,
  2815. configurable: true
  2816. });
  2817. Object.defineProperty(Container.prototype, "adaptWidthToChildren", {
  2818. /** Gets or sets a boolean indicating if the container should try to adapt to its children width */
  2819. get: function () {
  2820. return this._adaptWidthToChildren;
  2821. },
  2822. set: function (value) {
  2823. if (this._adaptWidthToChildren === value) {
  2824. return;
  2825. }
  2826. this._adaptWidthToChildren = value;
  2827. if (value) {
  2828. this.width = "100%";
  2829. }
  2830. this._markAsDirty();
  2831. },
  2832. enumerable: true,
  2833. configurable: true
  2834. });
  2835. Object.defineProperty(Container.prototype, "background", {
  2836. /** Gets or sets background color */
  2837. get: function () {
  2838. return this._background;
  2839. },
  2840. set: function (value) {
  2841. if (this._background === value) {
  2842. return;
  2843. }
  2844. this._background = value;
  2845. this._markAsDirty();
  2846. },
  2847. enumerable: true,
  2848. configurable: true
  2849. });
  2850. Object.defineProperty(Container.prototype, "children", {
  2851. /** Gets the list of children */
  2852. get: function () {
  2853. return this._children;
  2854. },
  2855. enumerable: true,
  2856. configurable: true
  2857. });
  2858. Container.prototype._getTypeName = function () {
  2859. return "Container";
  2860. };
  2861. /**
  2862. * Gets a child using its name
  2863. * @param name defines the child name to look for
  2864. * @returns the child control if found
  2865. */
  2866. Container.prototype.getChildByName = function (name) {
  2867. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2868. var child = _a[_i];
  2869. if (child.name === name) {
  2870. return child;
  2871. }
  2872. }
  2873. return null;
  2874. };
  2875. /**
  2876. * Gets a child using its type and its name
  2877. * @param name defines the child name to look for
  2878. * @param type defines the child type to look for
  2879. * @returns the child control if found
  2880. */
  2881. Container.prototype.getChildByType = function (name, type) {
  2882. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2883. var child = _a[_i];
  2884. if (child.typeName === type) {
  2885. return child;
  2886. }
  2887. }
  2888. return null;
  2889. };
  2890. /**
  2891. * Search for a specific control in children
  2892. * @param control defines the control to look for
  2893. * @returns true if the control is in child list
  2894. */
  2895. Container.prototype.containsControl = function (control) {
  2896. return this._children.indexOf(control) !== -1;
  2897. };
  2898. /**
  2899. * Adds a new control to the current container
  2900. * @param control defines the control to add
  2901. * @returns the current container
  2902. */
  2903. Container.prototype.addControl = function (control) {
  2904. if (!control) {
  2905. return this;
  2906. }
  2907. var index = this._children.indexOf(control);
  2908. if (index !== -1) {
  2909. return this;
  2910. }
  2911. control._link(this, this._host);
  2912. control._markAllAsDirty();
  2913. this._reOrderControl(control);
  2914. this._markAsDirty();
  2915. return this;
  2916. };
  2917. /**
  2918. * Removes a control from the current container
  2919. * @param control defines the control to remove
  2920. * @returns the current container
  2921. */
  2922. Container.prototype.removeControl = function (control) {
  2923. var index = this._children.indexOf(control);
  2924. if (index !== -1) {
  2925. this._children.splice(index, 1);
  2926. control.parent = null;
  2927. }
  2928. control.linkWithMesh(null);
  2929. if (this._host) {
  2930. this._host._cleanControlAfterRemoval(control);
  2931. }
  2932. this._markAsDirty();
  2933. return this;
  2934. };
  2935. /** @hidden */
  2936. Container.prototype._reOrderControl = function (control) {
  2937. this.removeControl(control);
  2938. for (var index = 0; index < this._children.length; index++) {
  2939. if (this._children[index].zIndex > control.zIndex) {
  2940. this._children.splice(index, 0, control);
  2941. return;
  2942. }
  2943. }
  2944. this._children.push(control);
  2945. control.parent = this;
  2946. this._markAsDirty();
  2947. };
  2948. /** @hidden */
  2949. Container.prototype._markMatrixAsDirty = function () {
  2950. _super.prototype._markMatrixAsDirty.call(this);
  2951. for (var index = 0; index < this._children.length; index++) {
  2952. this._children[index]._markMatrixAsDirty();
  2953. }
  2954. };
  2955. /** @hidden */
  2956. Container.prototype._markAllAsDirty = function () {
  2957. _super.prototype._markAllAsDirty.call(this);
  2958. for (var index = 0; index < this._children.length; index++) {
  2959. this._children[index]._markAllAsDirty();
  2960. }
  2961. };
  2962. /** @hidden */
  2963. Container.prototype._localDraw = function (context) {
  2964. if (this._background) {
  2965. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2966. context.shadowColor = this.shadowColor;
  2967. context.shadowBlur = this.shadowBlur;
  2968. context.shadowOffsetX = this.shadowOffsetX;
  2969. context.shadowOffsetY = this.shadowOffsetY;
  2970. }
  2971. context.fillStyle = this._background;
  2972. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2973. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2974. context.shadowBlur = 0;
  2975. context.shadowOffsetX = 0;
  2976. context.shadowOffsetY = 0;
  2977. }
  2978. }
  2979. };
  2980. /** @hidden */
  2981. Container.prototype._link = function (root, host) {
  2982. _super.prototype._link.call(this, root, host);
  2983. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2984. var child = _a[_i];
  2985. child._link(root, host);
  2986. }
  2987. };
  2988. /** @hidden */
  2989. Container.prototype._draw = function (parentMeasure, context) {
  2990. if (!this.isVisible || this.notRenderable) {
  2991. return;
  2992. }
  2993. context.save();
  2994. this._applyStates(context);
  2995. if (this._processMeasures(parentMeasure, context)) {
  2996. this._localDraw(context);
  2997. this._clipForChildren(context);
  2998. var computedWidth = -1;
  2999. var computedHeight = -1;
  3000. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  3001. var child = _a[_i];
  3002. if (child.isVisible && !child.notRenderable) {
  3003. child._tempParentMeasure.copyFrom(this._measureForChildren);
  3004. child._draw(this._measureForChildren, context);
  3005. if (child.onAfterDrawObservable.hasObservers()) {
  3006. child.onAfterDrawObservable.notifyObservers(child);
  3007. }
  3008. if (this.adaptWidthToChildren && child._width.isPixel) {
  3009. computedWidth = Math.max(computedWidth, child._currentMeasure.width);
  3010. }
  3011. if (this.adaptHeightToChildren && child._height.isPixel) {
  3012. computedHeight = Math.max(computedHeight, child._currentMeasure.height);
  3013. }
  3014. }
  3015. }
  3016. if (this.adaptWidthToChildren && computedWidth >= 0) {
  3017. this.width = computedWidth + "px";
  3018. }
  3019. if (this.adaptHeightToChildren && computedHeight >= 0) {
  3020. this.height = computedHeight + "px";
  3021. }
  3022. }
  3023. context.restore();
  3024. if (this.onAfterDrawObservable.hasObservers()) {
  3025. this.onAfterDrawObservable.notifyObservers(this);
  3026. }
  3027. };
  3028. /** @hidden */
  3029. Container.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  3030. if (!this.isVisible || this.notRenderable) {
  3031. return false;
  3032. }
  3033. if (!_super.prototype.contains.call(this, x, y)) {
  3034. return false;
  3035. }
  3036. // Checking backwards to pick closest first
  3037. for (var index = this._children.length - 1; index >= 0; index--) {
  3038. var child = this._children[index];
  3039. if (child._processPicking(x, y, type, pointerId, buttonIndex)) {
  3040. return true;
  3041. }
  3042. }
  3043. if (!this.isHitTestVisible) {
  3044. return false;
  3045. }
  3046. return this._processObservables(type, x, y, pointerId, buttonIndex);
  3047. };
  3048. /** @hidden */
  3049. Container.prototype._clipForChildren = function (context) {
  3050. // DO nothing
  3051. };
  3052. /** @hidden */
  3053. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  3054. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  3055. this._measureForChildren.copyFrom(this._currentMeasure);
  3056. };
  3057. /** Releases associated resources */
  3058. Container.prototype.dispose = function () {
  3059. _super.prototype.dispose.call(this);
  3060. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  3061. var control = _a[_i];
  3062. control.dispose();
  3063. }
  3064. };
  3065. return Container;
  3066. }(GUI.Control));
  3067. GUI.Container = Container;
  3068. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3069. })(BABYLON || (BABYLON = {}));
  3070. //# sourceMappingURL=container.js.map
  3071. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3072. var BABYLON;
  3073. (function (BABYLON) {
  3074. var GUI;
  3075. (function (GUI) {
  3076. /**
  3077. * Class used to create a 2D stack panel container
  3078. */
  3079. var StackPanel = /** @class */ (function (_super) {
  3080. __extends(StackPanel, _super);
  3081. /**
  3082. * Creates a new StackPanel
  3083. * @param name defines control name
  3084. */
  3085. function StackPanel(name) {
  3086. var _this = _super.call(this, name) || this;
  3087. _this.name = name;
  3088. _this._isVertical = true;
  3089. _this._manualWidth = false;
  3090. _this._manualHeight = false;
  3091. _this._doNotTrackManualChanges = false;
  3092. _this._tempMeasureStore = GUI.Measure.Empty();
  3093. return _this;
  3094. }
  3095. Object.defineProperty(StackPanel.prototype, "isVertical", {
  3096. /** Gets or sets a boolean indicating if the stack panel is vertical or horizontal*/
  3097. get: function () {
  3098. return this._isVertical;
  3099. },
  3100. set: function (value) {
  3101. if (this._isVertical === value) {
  3102. return;
  3103. }
  3104. this._isVertical = value;
  3105. this._markAsDirty();
  3106. },
  3107. enumerable: true,
  3108. configurable: true
  3109. });
  3110. Object.defineProperty(StackPanel.prototype, "width", {
  3111. get: function () {
  3112. return this._width.toString(this._host);
  3113. },
  3114. /** Gets or sets panel width */
  3115. set: function (value) {
  3116. if (!this._doNotTrackManualChanges) {
  3117. this._manualWidth = true;
  3118. }
  3119. if (this._width.toString(this._host) === value) {
  3120. return;
  3121. }
  3122. if (this._width.fromString(value)) {
  3123. this._markAsDirty();
  3124. }
  3125. },
  3126. enumerable: true,
  3127. configurable: true
  3128. });
  3129. Object.defineProperty(StackPanel.prototype, "height", {
  3130. get: function () {
  3131. return this._height.toString(this._host);
  3132. },
  3133. /** Gets or sets panel height */
  3134. set: function (value) {
  3135. if (!this._doNotTrackManualChanges) {
  3136. this._manualHeight = true;
  3137. }
  3138. if (this._height.toString(this._host) === value) {
  3139. return;
  3140. }
  3141. if (this._height.fromString(value)) {
  3142. this._markAsDirty();
  3143. }
  3144. },
  3145. enumerable: true,
  3146. configurable: true
  3147. });
  3148. StackPanel.prototype._getTypeName = function () {
  3149. return "StackPanel";
  3150. };
  3151. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  3152. var stackWidth = 0;
  3153. var stackHeight = 0;
  3154. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  3155. var child = _a[_i];
  3156. this._tempMeasureStore.copyFrom(child._currentMeasure);
  3157. child._currentMeasure.copyFrom(parentMeasure);
  3158. child._measure();
  3159. if (this._isVertical) {
  3160. child.top = stackHeight + "px";
  3161. if (!child._top.ignoreAdaptiveScaling) {
  3162. child._markAsDirty();
  3163. }
  3164. child._top.ignoreAdaptiveScaling = true;
  3165. stackHeight += child._currentMeasure.height;
  3166. if (child._currentMeasure.width > stackWidth) {
  3167. stackWidth = child._currentMeasure.width;
  3168. }
  3169. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  3170. }
  3171. else {
  3172. child.left = stackWidth + "px";
  3173. if (!child._left.ignoreAdaptiveScaling) {
  3174. child._markAsDirty();
  3175. }
  3176. child._left.ignoreAdaptiveScaling = true;
  3177. stackWidth += child._currentMeasure.width;
  3178. if (child._currentMeasure.height > stackHeight) {
  3179. stackHeight = child._currentMeasure.height;
  3180. }
  3181. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3182. }
  3183. child._currentMeasure.copyFrom(this._tempMeasureStore);
  3184. }
  3185. this._doNotTrackManualChanges = true;
  3186. // Let stack panel width and height default to stackHeight and stackWidth if dimensions are not specified.
  3187. // User can now define their own height and width for stack panel.
  3188. var panelWidthChanged = false;
  3189. var panelHeightChanged = false;
  3190. var previousHeight = this.height;
  3191. var previousWidth = this.width;
  3192. if (!this._manualHeight) {
  3193. // do not specify height if strictly defined by user
  3194. this.height = stackHeight + "px";
  3195. }
  3196. if (!this._manualWidth) {
  3197. // do not specify width if strictly defined by user
  3198. this.width = stackWidth + "px";
  3199. }
  3200. panelWidthChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  3201. panelHeightChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  3202. if (panelHeightChanged) {
  3203. this._height.ignoreAdaptiveScaling = true;
  3204. }
  3205. if (panelWidthChanged) {
  3206. this._width.ignoreAdaptiveScaling = true;
  3207. }
  3208. this._doNotTrackManualChanges = false;
  3209. if (panelWidthChanged || panelHeightChanged) {
  3210. this._markAllAsDirty();
  3211. }
  3212. _super.prototype._preMeasure.call(this, parentMeasure, context);
  3213. };
  3214. return StackPanel;
  3215. }(GUI.Container));
  3216. GUI.StackPanel = StackPanel;
  3217. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3218. })(BABYLON || (BABYLON = {}));
  3219. //# sourceMappingURL=stackPanel.js.map
  3220. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3221. var BABYLON;
  3222. (function (BABYLON) {
  3223. var GUI;
  3224. (function (GUI) {
  3225. /** Class used to create rectangle container */
  3226. var Rectangle = /** @class */ (function (_super) {
  3227. __extends(Rectangle, _super);
  3228. /**
  3229. * Creates a new Rectangle
  3230. * @param name defines the control name
  3231. */
  3232. function Rectangle(name) {
  3233. var _this = _super.call(this, name) || this;
  3234. _this.name = name;
  3235. _this._thickness = 1;
  3236. _this._cornerRadius = 0;
  3237. return _this;
  3238. }
  3239. Object.defineProperty(Rectangle.prototype, "thickness", {
  3240. /** Gets or sets border thickness */
  3241. get: function () {
  3242. return this._thickness;
  3243. },
  3244. set: function (value) {
  3245. if (this._thickness === value) {
  3246. return;
  3247. }
  3248. this._thickness = value;
  3249. this._markAsDirty();
  3250. },
  3251. enumerable: true,
  3252. configurable: true
  3253. });
  3254. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  3255. /** Gets or sets the corner radius angle */
  3256. get: function () {
  3257. return this._cornerRadius;
  3258. },
  3259. set: function (value) {
  3260. if (value < 0) {
  3261. value = 0;
  3262. }
  3263. if (this._cornerRadius === value) {
  3264. return;
  3265. }
  3266. this._cornerRadius = value;
  3267. this._markAsDirty();
  3268. },
  3269. enumerable: true,
  3270. configurable: true
  3271. });
  3272. Rectangle.prototype._getTypeName = function () {
  3273. return "Rectangle";
  3274. };
  3275. Rectangle.prototype._localDraw = function (context) {
  3276. context.save();
  3277. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3278. context.shadowColor = this.shadowColor;
  3279. context.shadowBlur = this.shadowBlur;
  3280. context.shadowOffsetX = this.shadowOffsetX;
  3281. context.shadowOffsetY = this.shadowOffsetY;
  3282. }
  3283. if (this._background) {
  3284. context.fillStyle = this._background;
  3285. if (this._cornerRadius) {
  3286. this._drawRoundedRect(context, this._thickness / 2);
  3287. context.fill();
  3288. }
  3289. else {
  3290. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3291. }
  3292. }
  3293. if (this._thickness) {
  3294. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3295. context.shadowBlur = 0;
  3296. context.shadowOffsetX = 0;
  3297. context.shadowOffsetY = 0;
  3298. }
  3299. if (this.color) {
  3300. context.strokeStyle = this.color;
  3301. }
  3302. context.lineWidth = this._thickness;
  3303. if (this._cornerRadius) {
  3304. this._drawRoundedRect(context, this._thickness / 2);
  3305. context.stroke();
  3306. }
  3307. else {
  3308. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  3309. }
  3310. }
  3311. context.restore();
  3312. };
  3313. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  3314. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  3315. this._measureForChildren.width -= 2 * this._thickness;
  3316. this._measureForChildren.height -= 2 * this._thickness;
  3317. this._measureForChildren.left += this._thickness;
  3318. this._measureForChildren.top += this._thickness;
  3319. };
  3320. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  3321. if (offset === void 0) { offset = 0; }
  3322. var x = this._currentMeasure.left + offset;
  3323. var y = this._currentMeasure.top + offset;
  3324. var width = this._currentMeasure.width - offset * 2;
  3325. var height = this._currentMeasure.height - offset * 2;
  3326. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  3327. context.beginPath();
  3328. context.moveTo(x + radius, y);
  3329. context.lineTo(x + width - radius, y);
  3330. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  3331. context.lineTo(x + width, y + height - radius);
  3332. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  3333. context.lineTo(x + radius, y + height);
  3334. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  3335. context.lineTo(x, y + radius);
  3336. context.quadraticCurveTo(x, y, x + radius, y);
  3337. context.closePath();
  3338. };
  3339. Rectangle.prototype._clipForChildren = function (context) {
  3340. if (this._cornerRadius) {
  3341. this._drawRoundedRect(context, this._thickness);
  3342. context.clip();
  3343. }
  3344. };
  3345. return Rectangle;
  3346. }(GUI.Container));
  3347. GUI.Rectangle = Rectangle;
  3348. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3349. })(BABYLON || (BABYLON = {}));
  3350. //# sourceMappingURL=rectangle.js.map
  3351. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3352. var BABYLON;
  3353. (function (BABYLON) {
  3354. var GUI;
  3355. (function (GUI) {
  3356. /** Class used to create 2D ellipse containers */
  3357. var Ellipse = /** @class */ (function (_super) {
  3358. __extends(Ellipse, _super);
  3359. /**
  3360. * Creates a new Ellipse
  3361. * @param name defines the control name
  3362. */
  3363. function Ellipse(name) {
  3364. var _this = _super.call(this, name) || this;
  3365. _this.name = name;
  3366. _this._thickness = 1;
  3367. return _this;
  3368. }
  3369. Object.defineProperty(Ellipse.prototype, "thickness", {
  3370. /** Gets or sets border thickness */
  3371. get: function () {
  3372. return this._thickness;
  3373. },
  3374. set: function (value) {
  3375. if (this._thickness === value) {
  3376. return;
  3377. }
  3378. this._thickness = value;
  3379. this._markAsDirty();
  3380. },
  3381. enumerable: true,
  3382. configurable: true
  3383. });
  3384. Ellipse.prototype._getTypeName = function () {
  3385. return "Ellipse";
  3386. };
  3387. Ellipse.prototype._localDraw = function (context) {
  3388. context.save();
  3389. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3390. context.shadowColor = this.shadowColor;
  3391. context.shadowBlur = this.shadowBlur;
  3392. context.shadowOffsetX = this.shadowOffsetX;
  3393. context.shadowOffsetY = this.shadowOffsetY;
  3394. }
  3395. 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);
  3396. if (this._background) {
  3397. context.fillStyle = this._background;
  3398. context.fill();
  3399. }
  3400. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3401. context.shadowBlur = 0;
  3402. context.shadowOffsetX = 0;
  3403. context.shadowOffsetY = 0;
  3404. }
  3405. if (this._thickness) {
  3406. if (this.color) {
  3407. context.strokeStyle = this.color;
  3408. }
  3409. context.lineWidth = this._thickness;
  3410. context.stroke();
  3411. }
  3412. context.restore();
  3413. };
  3414. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  3415. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  3416. this._measureForChildren.width -= 2 * this._thickness;
  3417. this._measureForChildren.height -= 2 * this._thickness;
  3418. this._measureForChildren.left += this._thickness;
  3419. this._measureForChildren.top += this._thickness;
  3420. };
  3421. Ellipse.prototype._clipForChildren = function (context) {
  3422. 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);
  3423. context.clip();
  3424. };
  3425. return Ellipse;
  3426. }(GUI.Container));
  3427. GUI.Ellipse = Ellipse;
  3428. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3429. })(BABYLON || (BABYLON = {}));
  3430. //# sourceMappingURL=ellipse.js.map
  3431. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3432. var BABYLON;
  3433. (function (BABYLON) {
  3434. var GUI;
  3435. (function (GUI) {
  3436. /** Class used to render 2D lines */
  3437. var Line = /** @class */ (function (_super) {
  3438. __extends(Line, _super);
  3439. /**
  3440. * Creates a new Line
  3441. * @param name defines the control name
  3442. */
  3443. function Line(name) {
  3444. var _this = _super.call(this, name) || this;
  3445. _this.name = name;
  3446. _this._lineWidth = 1;
  3447. _this._x1 = new GUI.ValueAndUnit(0);
  3448. _this._y1 = new GUI.ValueAndUnit(0);
  3449. _this._x2 = new GUI.ValueAndUnit(0);
  3450. _this._y2 = new GUI.ValueAndUnit(0);
  3451. _this._dash = new Array();
  3452. _this.isHitTestVisible = false;
  3453. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3454. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  3455. return _this;
  3456. }
  3457. Object.defineProperty(Line.prototype, "dash", {
  3458. /** Gets or sets the dash pattern */
  3459. get: function () {
  3460. return this._dash;
  3461. },
  3462. set: function (value) {
  3463. if (this._dash === value) {
  3464. return;
  3465. }
  3466. this._dash = value;
  3467. this._markAsDirty();
  3468. },
  3469. enumerable: true,
  3470. configurable: true
  3471. });
  3472. Object.defineProperty(Line.prototype, "connectedControl", {
  3473. /** Gets or sets the control connected with the line end */
  3474. get: function () {
  3475. return this._connectedControl;
  3476. },
  3477. set: function (value) {
  3478. var _this = this;
  3479. if (this._connectedControl === value) {
  3480. return;
  3481. }
  3482. if (this._connectedControlDirtyObserver && this._connectedControl) {
  3483. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  3484. this._connectedControlDirtyObserver = null;
  3485. }
  3486. if (value) {
  3487. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  3488. }
  3489. this._connectedControl = value;
  3490. this._markAsDirty();
  3491. },
  3492. enumerable: true,
  3493. configurable: true
  3494. });
  3495. Object.defineProperty(Line.prototype, "x1", {
  3496. /** Gets or sets start coordinates on X axis */
  3497. get: function () {
  3498. return this._x1.toString(this._host);
  3499. },
  3500. set: function (value) {
  3501. if (this._x1.toString(this._host) === value) {
  3502. return;
  3503. }
  3504. if (this._x1.fromString(value)) {
  3505. this._markAsDirty();
  3506. }
  3507. },
  3508. enumerable: true,
  3509. configurable: true
  3510. });
  3511. Object.defineProperty(Line.prototype, "y1", {
  3512. /** Gets or sets start coordinates on Y axis */
  3513. get: function () {
  3514. return this._y1.toString(this._host);
  3515. },
  3516. set: function (value) {
  3517. if (this._y1.toString(this._host) === value) {
  3518. return;
  3519. }
  3520. if (this._y1.fromString(value)) {
  3521. this._markAsDirty();
  3522. }
  3523. },
  3524. enumerable: true,
  3525. configurable: true
  3526. });
  3527. Object.defineProperty(Line.prototype, "x2", {
  3528. /** Gets or sets end coordinates on X axis */
  3529. get: function () {
  3530. return this._x2.toString(this._host);
  3531. },
  3532. set: function (value) {
  3533. if (this._x2.toString(this._host) === value) {
  3534. return;
  3535. }
  3536. if (this._x2.fromString(value)) {
  3537. this._markAsDirty();
  3538. }
  3539. },
  3540. enumerable: true,
  3541. configurable: true
  3542. });
  3543. Object.defineProperty(Line.prototype, "y2", {
  3544. /** Gets or sets end coordinates on Y axis */
  3545. get: function () {
  3546. return this._y2.toString(this._host);
  3547. },
  3548. set: function (value) {
  3549. if (this._y2.toString(this._host) === value) {
  3550. return;
  3551. }
  3552. if (this._y2.fromString(value)) {
  3553. this._markAsDirty();
  3554. }
  3555. },
  3556. enumerable: true,
  3557. configurable: true
  3558. });
  3559. Object.defineProperty(Line.prototype, "lineWidth", {
  3560. /** Gets or sets line width */
  3561. get: function () {
  3562. return this._lineWidth;
  3563. },
  3564. set: function (value) {
  3565. if (this._lineWidth === value) {
  3566. return;
  3567. }
  3568. this._lineWidth = value;
  3569. this._markAsDirty();
  3570. },
  3571. enumerable: true,
  3572. configurable: true
  3573. });
  3574. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  3575. /** Gets or sets horizontal alignment */
  3576. set: function (value) {
  3577. return;
  3578. },
  3579. enumerable: true,
  3580. configurable: true
  3581. });
  3582. Object.defineProperty(Line.prototype, "verticalAlignment", {
  3583. /** Gets or sets vertical alignment */
  3584. set: function (value) {
  3585. return;
  3586. },
  3587. enumerable: true,
  3588. configurable: true
  3589. });
  3590. Object.defineProperty(Line.prototype, "_effectiveX2", {
  3591. get: function () {
  3592. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  3593. },
  3594. enumerable: true,
  3595. configurable: true
  3596. });
  3597. Object.defineProperty(Line.prototype, "_effectiveY2", {
  3598. get: function () {
  3599. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  3600. },
  3601. enumerable: true,
  3602. configurable: true
  3603. });
  3604. Line.prototype._getTypeName = function () {
  3605. return "Line";
  3606. };
  3607. Line.prototype._draw = function (parentMeasure, context) {
  3608. context.save();
  3609. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3610. context.shadowColor = this.shadowColor;
  3611. context.shadowBlur = this.shadowBlur;
  3612. context.shadowOffsetX = this.shadowOffsetX;
  3613. context.shadowOffsetY = this.shadowOffsetY;
  3614. }
  3615. this._applyStates(context);
  3616. if (this._processMeasures(parentMeasure, context)) {
  3617. context.strokeStyle = this.color;
  3618. context.lineWidth = this._lineWidth;
  3619. context.setLineDash(this._dash);
  3620. context.beginPath();
  3621. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  3622. context.lineTo(this._effectiveX2, this._effectiveY2);
  3623. context.stroke();
  3624. }
  3625. context.restore();
  3626. };
  3627. Line.prototype._measure = function () {
  3628. // Width / Height
  3629. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  3630. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  3631. };
  3632. Line.prototype._computeAlignment = function (parentMeasure, context) {
  3633. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  3634. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  3635. };
  3636. /**
  3637. * Move one end of the line given 3D cartesian coordinates.
  3638. * @param position Targeted world position
  3639. * @param scene Scene
  3640. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  3641. */
  3642. Line.prototype.moveToVector3 = function (position, scene, end) {
  3643. if (end === void 0) { end = false; }
  3644. if (!this._host || this._root !== this._host._rootContainer) {
  3645. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  3646. return;
  3647. }
  3648. var globalViewport = this._host._getGlobalViewport(scene);
  3649. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  3650. this._moveToProjectedPosition(projectedPosition, end);
  3651. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  3652. this.notRenderable = true;
  3653. return;
  3654. }
  3655. this.notRenderable = false;
  3656. };
  3657. /**
  3658. * Move one end of the line to a position in screen absolute space.
  3659. * @param projectedPosition Position in screen absolute space (X, Y)
  3660. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  3661. */
  3662. Line.prototype._moveToProjectedPosition = function (projectedPosition, end) {
  3663. if (end === void 0) { end = false; }
  3664. var x = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  3665. var y = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  3666. if (end) {
  3667. this.x2 = x;
  3668. this.y2 = y;
  3669. this._x2.ignoreAdaptiveScaling = true;
  3670. this._y2.ignoreAdaptiveScaling = true;
  3671. }
  3672. else {
  3673. this.x1 = x;
  3674. this.y1 = y;
  3675. this._x1.ignoreAdaptiveScaling = true;
  3676. this._y1.ignoreAdaptiveScaling = true;
  3677. }
  3678. };
  3679. return Line;
  3680. }(GUI.Control));
  3681. GUI.Line = Line;
  3682. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3683. })(BABYLON || (BABYLON = {}));
  3684. //# sourceMappingURL=line.js.map
  3685. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3686. var BABYLON;
  3687. (function (BABYLON) {
  3688. var GUI;
  3689. (function (GUI) {
  3690. /**
  3691. * Class used to create slider controls
  3692. */
  3693. var Slider = /** @class */ (function (_super) {
  3694. __extends(Slider, _super);
  3695. /**
  3696. * Creates a new Slider
  3697. * @param name defines the control name
  3698. */
  3699. function Slider(name) {
  3700. var _this = _super.call(this, name) || this;
  3701. _this.name = name;
  3702. _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  3703. _this._minimum = 0;
  3704. _this._maximum = 100;
  3705. _this._value = 50;
  3706. _this._background = "black";
  3707. _this._borderColor = "white";
  3708. _this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  3709. _this._isThumbCircle = false;
  3710. _this._isThumbClamped = false;
  3711. /** Observable raised when the sldier value changes */
  3712. _this.onValueChangedObservable = new BABYLON.Observable();
  3713. // Events
  3714. _this._pointerIsDown = false;
  3715. _this.isPointerBlocker = true;
  3716. return _this;
  3717. }
  3718. Object.defineProperty(Slider.prototype, "borderColor", {
  3719. /** Gets or sets border color */
  3720. get: function () {
  3721. return this._borderColor;
  3722. },
  3723. set: function (value) {
  3724. if (this._borderColor === value) {
  3725. return;
  3726. }
  3727. this._borderColor = value;
  3728. this._markAsDirty();
  3729. },
  3730. enumerable: true,
  3731. configurable: true
  3732. });
  3733. Object.defineProperty(Slider.prototype, "background", {
  3734. /** Gets or sets background color */
  3735. get: function () {
  3736. return this._background;
  3737. },
  3738. set: function (value) {
  3739. if (this._background === value) {
  3740. return;
  3741. }
  3742. this._background = value;
  3743. this._markAsDirty();
  3744. },
  3745. enumerable: true,
  3746. configurable: true
  3747. });
  3748. Object.defineProperty(Slider.prototype, "barOffset", {
  3749. /** Gets or sets main bar offset */
  3750. get: function () {
  3751. return this._barOffset.toString(this._host);
  3752. },
  3753. set: function (value) {
  3754. if (this._barOffset.toString(this._host) === value) {
  3755. return;
  3756. }
  3757. if (this._barOffset.fromString(value)) {
  3758. this._markAsDirty();
  3759. }
  3760. },
  3761. enumerable: true,
  3762. configurable: true
  3763. });
  3764. Object.defineProperty(Slider.prototype, "barOffsetInPixels", {
  3765. /** Gets main bar offset in pixels*/
  3766. get: function () {
  3767. return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
  3768. },
  3769. enumerable: true,
  3770. configurable: true
  3771. });
  3772. Object.defineProperty(Slider.prototype, "thumbWidth", {
  3773. /** Gets or sets thumb width */
  3774. get: function () {
  3775. return this._thumbWidth.toString(this._host);
  3776. },
  3777. set: function (value) {
  3778. if (this._thumbWidth.toString(this._host) === value) {
  3779. return;
  3780. }
  3781. if (this._thumbWidth.fromString(value)) {
  3782. this._markAsDirty();
  3783. }
  3784. },
  3785. enumerable: true,
  3786. configurable: true
  3787. });
  3788. Object.defineProperty(Slider.prototype, "thumbWidthInPixels", {
  3789. /** Gets thumb width in pixels */
  3790. get: function () {
  3791. return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  3792. },
  3793. enumerable: true,
  3794. configurable: true
  3795. });
  3796. Object.defineProperty(Slider.prototype, "minimum", {
  3797. /** Gets or sets minimum value */
  3798. get: function () {
  3799. return this._minimum;
  3800. },
  3801. set: function (value) {
  3802. if (this._minimum === value) {
  3803. return;
  3804. }
  3805. this._minimum = value;
  3806. this._markAsDirty();
  3807. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  3808. },
  3809. enumerable: true,
  3810. configurable: true
  3811. });
  3812. Object.defineProperty(Slider.prototype, "maximum", {
  3813. /** Gets or sets maximum value */
  3814. get: function () {
  3815. return this._maximum;
  3816. },
  3817. set: function (value) {
  3818. if (this._maximum === value) {
  3819. return;
  3820. }
  3821. this._maximum = value;
  3822. this._markAsDirty();
  3823. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  3824. },
  3825. enumerable: true,
  3826. configurable: true
  3827. });
  3828. Object.defineProperty(Slider.prototype, "value", {
  3829. /** Gets or sets current value */
  3830. get: function () {
  3831. return this._value;
  3832. },
  3833. set: function (value) {
  3834. value = Math.max(Math.min(value, this._maximum), this._minimum);
  3835. if (this._value === value) {
  3836. return;
  3837. }
  3838. this._value = value;
  3839. this._markAsDirty();
  3840. this.onValueChangedObservable.notifyObservers(this._value);
  3841. },
  3842. enumerable: true,
  3843. configurable: true
  3844. });
  3845. Object.defineProperty(Slider.prototype, "isThumbCircle", {
  3846. /** Gets or sets a boolean indicating if the thumb should be round or square */
  3847. get: function () {
  3848. return this._isThumbCircle;
  3849. },
  3850. set: function (value) {
  3851. if (this._isThumbCircle === value) {
  3852. return;
  3853. }
  3854. this._isThumbCircle = value;
  3855. this._markAsDirty();
  3856. },
  3857. enumerable: true,
  3858. configurable: true
  3859. });
  3860. Object.defineProperty(Slider.prototype, "isThumbClamped", {
  3861. /** Gets or sets a value indicating if the thumb can go over main bar extends */
  3862. get: function () {
  3863. return this._isThumbClamped;
  3864. },
  3865. set: function (value) {
  3866. if (this._isThumbClamped === value) {
  3867. return;
  3868. }
  3869. this._isThumbClamped = value;
  3870. this._markAsDirty();
  3871. },
  3872. enumerable: true,
  3873. configurable: true
  3874. });
  3875. Slider.prototype._getTypeName = function () {
  3876. return "Slider";
  3877. };
  3878. Slider.prototype._draw = function (parentMeasure, context) {
  3879. context.save();
  3880. this._applyStates(context);
  3881. if (this._processMeasures(parentMeasure, context)) {
  3882. // Main bar
  3883. var effectiveThumbWidth;
  3884. var effectiveBarOffset;
  3885. if (this._thumbWidth.isPixel) {
  3886. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.width);
  3887. }
  3888. else {
  3889. effectiveThumbWidth = this._currentMeasure.width * this._thumbWidth.getValue(this._host);
  3890. }
  3891. if (this._barOffset.isPixel) {
  3892. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  3893. }
  3894. else {
  3895. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  3896. }
  3897. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3898. context.shadowColor = this.shadowColor;
  3899. context.shadowBlur = this.shadowBlur;
  3900. context.shadowOffsetX = this.shadowOffsetX;
  3901. context.shadowOffsetY = this.shadowOffsetY;
  3902. }
  3903. var left = this._currentMeasure.left;
  3904. var width = this._currentMeasure.width - effectiveThumbWidth;
  3905. var thumbPosition = ((this._value - this._minimum) / (this._maximum - this._minimum)) * width;
  3906. context.fillStyle = this._background;
  3907. if (this.isThumbClamped) {
  3908. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width + effectiveThumbWidth, this._currentMeasure.height - effectiveBarOffset * 2);
  3909. }
  3910. else {
  3911. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  3912. }
  3913. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3914. context.shadowBlur = 0;
  3915. context.shadowOffsetX = 0;
  3916. context.shadowOffsetY = 0;
  3917. }
  3918. context.fillStyle = this.color;
  3919. if (this.isThumbClamped) {
  3920. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3921. }
  3922. else {
  3923. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3924. }
  3925. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3926. context.shadowColor = this.shadowColor;
  3927. context.shadowBlur = this.shadowBlur;
  3928. context.shadowOffsetX = this.shadowOffsetX;
  3929. context.shadowOffsetY = this.shadowOffsetY;
  3930. }
  3931. if (this._isThumbCircle) {
  3932. context.beginPath();
  3933. context.arc(left + thumbPosition + (effectiveThumbWidth / 2), this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
  3934. context.fill();
  3935. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3936. context.shadowBlur = 0;
  3937. context.shadowOffsetX = 0;
  3938. context.shadowOffsetY = 0;
  3939. }
  3940. context.strokeStyle = this._borderColor;
  3941. context.stroke();
  3942. }
  3943. else {
  3944. context.fillRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3945. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3946. context.shadowBlur = 0;
  3947. context.shadowOffsetX = 0;
  3948. context.shadowOffsetY = 0;
  3949. }
  3950. context.strokeStyle = this._borderColor;
  3951. context.strokeRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3952. }
  3953. }
  3954. context.restore();
  3955. };
  3956. Slider.prototype._updateValueFromPointer = function (x, y) {
  3957. if (this.rotation != 0) {
  3958. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  3959. x = this._transformedPosition.x;
  3960. }
  3961. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  3962. };
  3963. Slider.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3964. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3965. return false;
  3966. }
  3967. this._pointerIsDown = true;
  3968. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3969. this._host._capturingControl[pointerId] = this;
  3970. return true;
  3971. };
  3972. Slider.prototype._onPointerMove = function (target, coordinates) {
  3973. if (this._pointerIsDown) {
  3974. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3975. }
  3976. _super.prototype._onPointerMove.call(this, target, coordinates);
  3977. };
  3978. Slider.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  3979. this._pointerIsDown = false;
  3980. delete this._host._capturingControl[pointerId];
  3981. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  3982. };
  3983. return Slider;
  3984. }(GUI.Control));
  3985. GUI.Slider = Slider;
  3986. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3987. })(BABYLON || (BABYLON = {}));
  3988. //# sourceMappingURL=slider.js.map
  3989. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3990. var BABYLON;
  3991. (function (BABYLON) {
  3992. var GUI;
  3993. (function (GUI) {
  3994. /**
  3995. * Class used to represent a 2D checkbox
  3996. */
  3997. var Checkbox = /** @class */ (function (_super) {
  3998. __extends(Checkbox, _super);
  3999. /**
  4000. * Creates a new CheckBox
  4001. * @param name defines the control name
  4002. */
  4003. function Checkbox(name) {
  4004. var _this = _super.call(this, name) || this;
  4005. _this.name = name;
  4006. _this._isChecked = false;
  4007. _this._background = "black";
  4008. _this._checkSizeRatio = 0.8;
  4009. _this._thickness = 1;
  4010. /**
  4011. * Observable raised when isChecked property changes
  4012. */
  4013. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  4014. _this.isPointerBlocker = true;
  4015. return _this;
  4016. }
  4017. Object.defineProperty(Checkbox.prototype, "thickness", {
  4018. /** Gets or sets border thickness */
  4019. get: function () {
  4020. return this._thickness;
  4021. },
  4022. set: function (value) {
  4023. if (this._thickness === value) {
  4024. return;
  4025. }
  4026. this._thickness = value;
  4027. this._markAsDirty();
  4028. },
  4029. enumerable: true,
  4030. configurable: true
  4031. });
  4032. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  4033. /** Gets or sets a value indicating the ratio between overall size and check size */
  4034. get: function () {
  4035. return this._checkSizeRatio;
  4036. },
  4037. set: function (value) {
  4038. value = Math.max(Math.min(1, value), 0);
  4039. if (this._checkSizeRatio === value) {
  4040. return;
  4041. }
  4042. this._checkSizeRatio = value;
  4043. this._markAsDirty();
  4044. },
  4045. enumerable: true,
  4046. configurable: true
  4047. });
  4048. Object.defineProperty(Checkbox.prototype, "background", {
  4049. /** Gets or sets background color */
  4050. get: function () {
  4051. return this._background;
  4052. },
  4053. set: function (value) {
  4054. if (this._background === value) {
  4055. return;
  4056. }
  4057. this._background = value;
  4058. this._markAsDirty();
  4059. },
  4060. enumerable: true,
  4061. configurable: true
  4062. });
  4063. Object.defineProperty(Checkbox.prototype, "isChecked", {
  4064. /** Gets or sets a boolean indicating if the checkbox is checked or not */
  4065. get: function () {
  4066. return this._isChecked;
  4067. },
  4068. set: function (value) {
  4069. if (this._isChecked === value) {
  4070. return;
  4071. }
  4072. this._isChecked = value;
  4073. this._markAsDirty();
  4074. this.onIsCheckedChangedObservable.notifyObservers(value);
  4075. },
  4076. enumerable: true,
  4077. configurable: true
  4078. });
  4079. Checkbox.prototype._getTypeName = function () {
  4080. return "CheckBox";
  4081. };
  4082. /** @hidden */
  4083. Checkbox.prototype._draw = function (parentMeasure, context) {
  4084. context.save();
  4085. this._applyStates(context);
  4086. if (this._processMeasures(parentMeasure, context)) {
  4087. var actualWidth = this._currentMeasure.width - this._thickness;
  4088. var actualHeight = this._currentMeasure.height - this._thickness;
  4089. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4090. context.shadowColor = this.shadowColor;
  4091. context.shadowBlur = this.shadowBlur;
  4092. context.shadowOffsetX = this.shadowOffsetX;
  4093. context.shadowOffsetY = this.shadowOffsetY;
  4094. }
  4095. context.fillStyle = this._background;
  4096. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  4097. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4098. context.shadowBlur = 0;
  4099. context.shadowOffsetX = 0;
  4100. context.shadowOffsetY = 0;
  4101. }
  4102. if (this._isChecked) {
  4103. context.fillStyle = this.color;
  4104. var offsetWidth = actualWidth * this._checkSizeRatio;
  4105. var offseHeight = actualHeight * this._checkSizeRatio;
  4106. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  4107. }
  4108. context.strokeStyle = this.color;
  4109. context.lineWidth = this._thickness;
  4110. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  4111. }
  4112. context.restore();
  4113. };
  4114. // Events
  4115. /** @hidden */
  4116. Checkbox.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4117. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4118. return false;
  4119. }
  4120. this.isChecked = !this.isChecked;
  4121. return true;
  4122. };
  4123. return Checkbox;
  4124. }(GUI.Control));
  4125. GUI.Checkbox = Checkbox;
  4126. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4127. })(BABYLON || (BABYLON = {}));
  4128. //# sourceMappingURL=checkbox.js.map
  4129. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4130. var BABYLON;
  4131. (function (BABYLON) {
  4132. var GUI;
  4133. (function (GUI) {
  4134. /**
  4135. * Class used to create radio button controls
  4136. */
  4137. var RadioButton = /** @class */ (function (_super) {
  4138. __extends(RadioButton, _super);
  4139. /**
  4140. * Creates a new RadioButton
  4141. * @param name defines the control name
  4142. */
  4143. function RadioButton(name) {
  4144. var _this = _super.call(this, name) || this;
  4145. _this.name = name;
  4146. _this._isChecked = false;
  4147. _this._background = "black";
  4148. _this._checkSizeRatio = 0.8;
  4149. _this._thickness = 1;
  4150. /** Gets or sets group name */
  4151. _this.group = "";
  4152. /** Observable raised when isChecked is changed */
  4153. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  4154. _this.isPointerBlocker = true;
  4155. return _this;
  4156. }
  4157. Object.defineProperty(RadioButton.prototype, "thickness", {
  4158. /** Gets or sets border thickness */
  4159. get: function () {
  4160. return this._thickness;
  4161. },
  4162. set: function (value) {
  4163. if (this._thickness === value) {
  4164. return;
  4165. }
  4166. this._thickness = value;
  4167. this._markAsDirty();
  4168. },
  4169. enumerable: true,
  4170. configurable: true
  4171. });
  4172. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  4173. /** Gets or sets a value indicating the ratio between overall size and check size */
  4174. get: function () {
  4175. return this._checkSizeRatio;
  4176. },
  4177. set: function (value) {
  4178. value = Math.max(Math.min(1, value), 0);
  4179. if (this._checkSizeRatio === value) {
  4180. return;
  4181. }
  4182. this._checkSizeRatio = value;
  4183. this._markAsDirty();
  4184. },
  4185. enumerable: true,
  4186. configurable: true
  4187. });
  4188. Object.defineProperty(RadioButton.prototype, "background", {
  4189. /** Gets or sets background color */
  4190. get: function () {
  4191. return this._background;
  4192. },
  4193. set: function (value) {
  4194. if (this._background === value) {
  4195. return;
  4196. }
  4197. this._background = value;
  4198. this._markAsDirty();
  4199. },
  4200. enumerable: true,
  4201. configurable: true
  4202. });
  4203. Object.defineProperty(RadioButton.prototype, "isChecked", {
  4204. /** Gets or sets a boolean indicating if the checkbox is checked or not */
  4205. get: function () {
  4206. return this._isChecked;
  4207. },
  4208. set: function (value) {
  4209. var _this = this;
  4210. if (this._isChecked === value) {
  4211. return;
  4212. }
  4213. this._isChecked = value;
  4214. this._markAsDirty();
  4215. this.onIsCheckedChangedObservable.notifyObservers(value);
  4216. if (this._isChecked) {
  4217. // Update all controls from same group
  4218. this._host.executeOnAllControls(function (control) {
  4219. if (control === _this) {
  4220. return;
  4221. }
  4222. if (control.group === undefined) {
  4223. return;
  4224. }
  4225. var childRadio = control;
  4226. if (childRadio.group === _this.group) {
  4227. childRadio.isChecked = false;
  4228. }
  4229. });
  4230. }
  4231. },
  4232. enumerable: true,
  4233. configurable: true
  4234. });
  4235. RadioButton.prototype._getTypeName = function () {
  4236. return "RadioButton";
  4237. };
  4238. RadioButton.prototype._draw = function (parentMeasure, context) {
  4239. context.save();
  4240. this._applyStates(context);
  4241. if (this._processMeasures(parentMeasure, context)) {
  4242. var actualWidth = this._currentMeasure.width - this._thickness;
  4243. var actualHeight = this._currentMeasure.height - this._thickness;
  4244. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4245. context.shadowColor = this.shadowColor;
  4246. context.shadowBlur = this.shadowBlur;
  4247. context.shadowOffsetX = this.shadowOffsetX;
  4248. context.shadowOffsetY = this.shadowOffsetY;
  4249. }
  4250. // Outer
  4251. 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);
  4252. context.fillStyle = this._background;
  4253. context.fill();
  4254. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4255. context.shadowBlur = 0;
  4256. context.shadowOffsetX = 0;
  4257. context.shadowOffsetY = 0;
  4258. }
  4259. context.strokeStyle = this.color;
  4260. context.lineWidth = this._thickness;
  4261. context.stroke();
  4262. // Inner
  4263. if (this._isChecked) {
  4264. context.fillStyle = this.color;
  4265. var offsetWidth = actualWidth * this._checkSizeRatio;
  4266. var offseHeight = actualHeight * this._checkSizeRatio;
  4267. 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);
  4268. context.fill();
  4269. }
  4270. }
  4271. context.restore();
  4272. };
  4273. // Events
  4274. RadioButton.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4275. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4276. return false;
  4277. }
  4278. if (!this.isChecked) {
  4279. this.isChecked = true;
  4280. }
  4281. return true;
  4282. };
  4283. return RadioButton;
  4284. }(GUI.Control));
  4285. GUI.RadioButton = RadioButton;
  4286. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4287. })(BABYLON || (BABYLON = {}));
  4288. //# sourceMappingURL=radioButton.js.map
  4289. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4290. var BABYLON;
  4291. (function (BABYLON) {
  4292. var GUI;
  4293. (function (GUI) {
  4294. /**
  4295. * Class used to create text block control
  4296. */
  4297. var TextBlock = /** @class */ (function (_super) {
  4298. __extends(TextBlock, _super);
  4299. /**
  4300. * Creates a new TextBlock object
  4301. * @param name defines the name of the control
  4302. * @param text defines the text to display (emptry string by default)
  4303. */
  4304. function TextBlock(
  4305. /**
  4306. * Defines the name of the control
  4307. */
  4308. name, text) {
  4309. if (text === void 0) { text = ""; }
  4310. var _this = _super.call(this, name) || this;
  4311. _this.name = name;
  4312. _this._text = "";
  4313. _this._textWrapping = false;
  4314. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4315. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  4316. _this._resizeToFit = false;
  4317. _this._lineSpacing = new GUI.ValueAndUnit(0);
  4318. _this._outlineWidth = 0;
  4319. _this._outlineColor = "white";
  4320. /**
  4321. * An event triggered after the text is changed
  4322. */
  4323. _this.onTextChangedObservable = new BABYLON.Observable();
  4324. /**
  4325. * An event triggered after the text was broken up into lines
  4326. */
  4327. _this.onLinesReadyObservable = new BABYLON.Observable();
  4328. _this.text = text;
  4329. return _this;
  4330. }
  4331. Object.defineProperty(TextBlock.prototype, "lines", {
  4332. /**
  4333. * Return the line list (you may need to use the onLinesReadyObservable to make sure the list is ready)
  4334. */
  4335. get: function () {
  4336. return this._lines;
  4337. },
  4338. enumerable: true,
  4339. configurable: true
  4340. });
  4341. Object.defineProperty(TextBlock.prototype, "resizeToFit", {
  4342. /**
  4343. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  4344. */
  4345. get: function () {
  4346. return this._resizeToFit;
  4347. },
  4348. /**
  4349. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  4350. */
  4351. set: function (value) {
  4352. this._resizeToFit = value;
  4353. if (this._resizeToFit) {
  4354. this._width.ignoreAdaptiveScaling = true;
  4355. this._height.ignoreAdaptiveScaling = true;
  4356. }
  4357. },
  4358. enumerable: true,
  4359. configurable: true
  4360. });
  4361. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  4362. /**
  4363. * Gets or sets a boolean indicating if text must be wrapped
  4364. */
  4365. get: function () {
  4366. return this._textWrapping;
  4367. },
  4368. /**
  4369. * Gets or sets a boolean indicating if text must be wrapped
  4370. */
  4371. set: function (value) {
  4372. if (this._textWrapping === value) {
  4373. return;
  4374. }
  4375. this._textWrapping = value;
  4376. this._markAsDirty();
  4377. },
  4378. enumerable: true,
  4379. configurable: true
  4380. });
  4381. Object.defineProperty(TextBlock.prototype, "text", {
  4382. /**
  4383. * Gets or sets text to display
  4384. */
  4385. get: function () {
  4386. return this._text;
  4387. },
  4388. /**
  4389. * Gets or sets text to display
  4390. */
  4391. set: function (value) {
  4392. if (this._text === value) {
  4393. return;
  4394. }
  4395. this._text = value;
  4396. this._markAsDirty();
  4397. this.onTextChangedObservable.notifyObservers(this);
  4398. },
  4399. enumerable: true,
  4400. configurable: true
  4401. });
  4402. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  4403. /**
  4404. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  4405. */
  4406. get: function () {
  4407. return this._textHorizontalAlignment;
  4408. },
  4409. /**
  4410. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  4411. */
  4412. set: function (value) {
  4413. if (this._textHorizontalAlignment === value) {
  4414. return;
  4415. }
  4416. this._textHorizontalAlignment = value;
  4417. this._markAsDirty();
  4418. },
  4419. enumerable: true,
  4420. configurable: true
  4421. });
  4422. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  4423. /**
  4424. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  4425. */
  4426. get: function () {
  4427. return this._textVerticalAlignment;
  4428. },
  4429. /**
  4430. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  4431. */
  4432. set: function (value) {
  4433. if (this._textVerticalAlignment === value) {
  4434. return;
  4435. }
  4436. this._textVerticalAlignment = value;
  4437. this._markAsDirty();
  4438. },
  4439. enumerable: true,
  4440. configurable: true
  4441. });
  4442. Object.defineProperty(TextBlock.prototype, "lineSpacing", {
  4443. /**
  4444. * Gets or sets line spacing value
  4445. */
  4446. get: function () {
  4447. return this._lineSpacing.toString(this._host);
  4448. },
  4449. /**
  4450. * Gets or sets line spacing value
  4451. */
  4452. set: function (value) {
  4453. if (this._lineSpacing.fromString(value)) {
  4454. this._markAsDirty();
  4455. }
  4456. },
  4457. enumerable: true,
  4458. configurable: true
  4459. });
  4460. Object.defineProperty(TextBlock.prototype, "outlineWidth", {
  4461. /**
  4462. * Gets or sets outlineWidth of the text to display
  4463. */
  4464. get: function () {
  4465. return this._outlineWidth;
  4466. },
  4467. /**
  4468. * Gets or sets outlineWidth of the text to display
  4469. */
  4470. set: function (value) {
  4471. if (this._outlineWidth === value) {
  4472. return;
  4473. }
  4474. this._outlineWidth = value;
  4475. this._markAsDirty();
  4476. },
  4477. enumerable: true,
  4478. configurable: true
  4479. });
  4480. Object.defineProperty(TextBlock.prototype, "outlineColor", {
  4481. /**
  4482. * Gets or sets outlineColor of the text to display
  4483. */
  4484. get: function () {
  4485. return this._outlineColor;
  4486. },
  4487. /**
  4488. * Gets or sets outlineColor of the text to display
  4489. */
  4490. set: function (value) {
  4491. if (this._outlineColor === value) {
  4492. return;
  4493. }
  4494. this._outlineColor = value;
  4495. this._markAsDirty();
  4496. },
  4497. enumerable: true,
  4498. configurable: true
  4499. });
  4500. TextBlock.prototype._getTypeName = function () {
  4501. return "TextBlock";
  4502. };
  4503. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  4504. var width = this._currentMeasure.width;
  4505. var x = 0;
  4506. switch (this._textHorizontalAlignment) {
  4507. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  4508. x = 0;
  4509. break;
  4510. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  4511. x = width - textWidth;
  4512. break;
  4513. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  4514. x = (width - textWidth) / 2;
  4515. break;
  4516. }
  4517. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4518. context.shadowColor = this.shadowColor;
  4519. context.shadowBlur = this.shadowBlur;
  4520. context.shadowOffsetX = this.shadowOffsetX;
  4521. context.shadowOffsetY = this.shadowOffsetY;
  4522. }
  4523. if (this.outlineWidth) {
  4524. context.strokeText(text, this._currentMeasure.left + x, y);
  4525. }
  4526. context.fillText(text, this._currentMeasure.left + x, y);
  4527. };
  4528. /** @hidden */
  4529. TextBlock.prototype._draw = function (parentMeasure, context) {
  4530. context.save();
  4531. this._applyStates(context);
  4532. if (this._processMeasures(parentMeasure, context)) {
  4533. // Render lines
  4534. this._renderLines(context);
  4535. }
  4536. context.restore();
  4537. };
  4538. TextBlock.prototype._applyStates = function (context) {
  4539. _super.prototype._applyStates.call(this, context);
  4540. if (this.outlineWidth) {
  4541. context.lineWidth = this.outlineWidth;
  4542. context.strokeStyle = this.outlineColor;
  4543. }
  4544. };
  4545. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  4546. this._lines = [];
  4547. var _lines = this.text.split("\n");
  4548. if (this._textWrapping && !this._resizeToFit) {
  4549. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  4550. var _line = _lines_1[_i];
  4551. this._lines.push(this._parseLineWithTextWrapping(_line, context));
  4552. }
  4553. }
  4554. else {
  4555. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  4556. var _line = _lines_2[_a];
  4557. this._lines.push(this._parseLine(_line, context));
  4558. }
  4559. }
  4560. this.onLinesReadyObservable.notifyObservers(this);
  4561. };
  4562. TextBlock.prototype._parseLine = function (line, context) {
  4563. if (line === void 0) { line = ''; }
  4564. return { text: line, width: context.measureText(line).width };
  4565. };
  4566. TextBlock.prototype._parseLineWithTextWrapping = function (line, context) {
  4567. if (line === void 0) { line = ''; }
  4568. var words = line.split(' ');
  4569. var width = this._currentMeasure.width;
  4570. var lineWidth = 0;
  4571. for (var n = 0; n < words.length; n++) {
  4572. var testLine = n > 0 ? line + " " + words[n] : words[0];
  4573. var metrics = context.measureText(testLine);
  4574. var testWidth = metrics.width;
  4575. if (testWidth > width && n > 0) {
  4576. this._lines.push({ text: line, width: lineWidth });
  4577. line = words[n];
  4578. lineWidth = context.measureText(line).width;
  4579. }
  4580. else {
  4581. lineWidth = testWidth;
  4582. line = testLine;
  4583. }
  4584. }
  4585. return { text: line, width: lineWidth };
  4586. };
  4587. TextBlock.prototype._renderLines = function (context) {
  4588. var height = this._currentMeasure.height;
  4589. if (!this._fontOffset) {
  4590. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  4591. }
  4592. var rootY = 0;
  4593. switch (this._textVerticalAlignment) {
  4594. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  4595. rootY = this._fontOffset.ascent;
  4596. break;
  4597. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  4598. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  4599. break;
  4600. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  4601. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  4602. break;
  4603. }
  4604. rootY += this._currentMeasure.top;
  4605. var maxLineWidth = 0;
  4606. for (var i = 0; i < this._lines.length; i++) {
  4607. var line = this._lines[i];
  4608. if (i !== 0 && this._lineSpacing.internalValue !== 0) {
  4609. if (this._lineSpacing.isPixel) {
  4610. rootY += this._lineSpacing.getValue(this._host);
  4611. }
  4612. else {
  4613. rootY = rootY + (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
  4614. }
  4615. }
  4616. this._drawText(line.text, line.width, rootY, context);
  4617. rootY += this._fontOffset.height;
  4618. if (line.width > maxLineWidth)
  4619. maxLineWidth = line.width;
  4620. }
  4621. if (this._resizeToFit) {
  4622. this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
  4623. this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
  4624. }
  4625. };
  4626. TextBlock.prototype.dispose = function () {
  4627. _super.prototype.dispose.call(this);
  4628. this.onTextChangedObservable.clear();
  4629. };
  4630. return TextBlock;
  4631. }(GUI.Control));
  4632. GUI.TextBlock = TextBlock;
  4633. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4634. })(BABYLON || (BABYLON = {}));
  4635. //# sourceMappingURL=textBlock.js.map
  4636. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4637. var DOMImage = Image;
  4638. var BABYLON;
  4639. (function (BABYLON) {
  4640. var GUI;
  4641. (function (GUI) {
  4642. /**
  4643. * Class used to create 2D images
  4644. */
  4645. var Image = /** @class */ (function (_super) {
  4646. __extends(Image, _super);
  4647. /**
  4648. * Creates a new Image
  4649. * @param name defines the control name
  4650. * @param url defines the image url
  4651. */
  4652. function Image(name, url) {
  4653. if (url === void 0) { url = null; }
  4654. var _this = _super.call(this, name) || this;
  4655. _this.name = name;
  4656. _this._loaded = false;
  4657. _this._stretch = Image.STRETCH_FILL;
  4658. _this._autoScale = false;
  4659. _this._sourceLeft = 0;
  4660. _this._sourceTop = 0;
  4661. _this._sourceWidth = 0;
  4662. _this._sourceHeight = 0;
  4663. _this._cellWidth = 0;
  4664. _this._cellHeight = 0;
  4665. _this._cellId = -1;
  4666. _this.source = url;
  4667. return _this;
  4668. }
  4669. Object.defineProperty(Image.prototype, "sourceLeft", {
  4670. /**
  4671. * Gets or sets the left coordinate in the source image
  4672. */
  4673. get: function () {
  4674. return this._sourceLeft;
  4675. },
  4676. set: function (value) {
  4677. if (this._sourceLeft === value) {
  4678. return;
  4679. }
  4680. this._sourceLeft = value;
  4681. this._markAsDirty();
  4682. },
  4683. enumerable: true,
  4684. configurable: true
  4685. });
  4686. Object.defineProperty(Image.prototype, "sourceTop", {
  4687. /**
  4688. * Gets or sets the top coordinate in the source image
  4689. */
  4690. get: function () {
  4691. return this._sourceTop;
  4692. },
  4693. set: function (value) {
  4694. if (this._sourceTop === value) {
  4695. return;
  4696. }
  4697. this._sourceTop = value;
  4698. this._markAsDirty();
  4699. },
  4700. enumerable: true,
  4701. configurable: true
  4702. });
  4703. Object.defineProperty(Image.prototype, "sourceWidth", {
  4704. /**
  4705. * Gets or sets the width to capture in the source image
  4706. */
  4707. get: function () {
  4708. return this._sourceWidth;
  4709. },
  4710. set: function (value) {
  4711. if (this._sourceWidth === value) {
  4712. return;
  4713. }
  4714. this._sourceWidth = value;
  4715. this._markAsDirty();
  4716. },
  4717. enumerable: true,
  4718. configurable: true
  4719. });
  4720. Object.defineProperty(Image.prototype, "sourceHeight", {
  4721. /**
  4722. * Gets or sets the height to capture in the source image
  4723. */
  4724. get: function () {
  4725. return this._sourceHeight;
  4726. },
  4727. set: function (value) {
  4728. if (this._sourceHeight === value) {
  4729. return;
  4730. }
  4731. this._sourceHeight = value;
  4732. this._markAsDirty();
  4733. },
  4734. enumerable: true,
  4735. configurable: true
  4736. });
  4737. Object.defineProperty(Image.prototype, "autoScale", {
  4738. /**
  4739. * Gets or sets a boolean indicating if the image can force its container to adapt its size
  4740. * @see http://doc.babylonjs.com/how_to/gui#image
  4741. */
  4742. get: function () {
  4743. return this._autoScale;
  4744. },
  4745. set: function (value) {
  4746. if (this._autoScale === value) {
  4747. return;
  4748. }
  4749. this._autoScale = value;
  4750. if (value && this._loaded) {
  4751. this.synchronizeSizeWithContent();
  4752. }
  4753. },
  4754. enumerable: true,
  4755. configurable: true
  4756. });
  4757. Object.defineProperty(Image.prototype, "stretch", {
  4758. /** Gets or sets the streching mode used by the image */
  4759. get: function () {
  4760. return this._stretch;
  4761. },
  4762. set: function (value) {
  4763. if (this._stretch === value) {
  4764. return;
  4765. }
  4766. this._stretch = value;
  4767. this._markAsDirty();
  4768. },
  4769. enumerable: true,
  4770. configurable: true
  4771. });
  4772. Object.defineProperty(Image.prototype, "domImage", {
  4773. get: function () {
  4774. return this._domImage;
  4775. },
  4776. /**
  4777. * Gets or sets the internal DOM image used to render the control
  4778. */
  4779. set: function (value) {
  4780. var _this = this;
  4781. this._domImage = value;
  4782. this._loaded = false;
  4783. if (this._domImage.width) {
  4784. this._onImageLoaded();
  4785. }
  4786. else {
  4787. this._domImage.onload = function () {
  4788. _this._onImageLoaded();
  4789. };
  4790. }
  4791. },
  4792. enumerable: true,
  4793. configurable: true
  4794. });
  4795. Image.prototype._onImageLoaded = function () {
  4796. this._imageWidth = this._domImage.width;
  4797. this._imageHeight = this._domImage.height;
  4798. this._loaded = true;
  4799. if (this._autoScale) {
  4800. this.synchronizeSizeWithContent();
  4801. }
  4802. this._markAsDirty();
  4803. };
  4804. Object.defineProperty(Image.prototype, "source", {
  4805. /**
  4806. * Gets or sets image source url
  4807. */
  4808. set: function (value) {
  4809. var _this = this;
  4810. if (this._source === value) {
  4811. return;
  4812. }
  4813. this._loaded = false;
  4814. this._source = value;
  4815. this._domImage = new DOMImage();
  4816. this._domImage.onload = function () {
  4817. _this._onImageLoaded();
  4818. };
  4819. if (value) {
  4820. BABYLON.Tools.SetCorsBehavior(value, this._domImage);
  4821. this._domImage.src = value;
  4822. }
  4823. },
  4824. enumerable: true,
  4825. configurable: true
  4826. });
  4827. Object.defineProperty(Image.prototype, "cellWidth", {
  4828. /**
  4829. * Gets or sets the cell width to use when animation sheet is enabled
  4830. * @see http://doc.babylonjs.com/how_to/gui#image
  4831. */
  4832. get: function () {
  4833. return this._cellWidth;
  4834. },
  4835. set: function (value) {
  4836. if (this._cellWidth === value) {
  4837. return;
  4838. }
  4839. this._cellWidth = value;
  4840. this._markAsDirty();
  4841. },
  4842. enumerable: true,
  4843. configurable: true
  4844. });
  4845. Object.defineProperty(Image.prototype, "cellHeight", {
  4846. /**
  4847. * Gets or sets the cell height to use when animation sheet is enabled
  4848. * @see http://doc.babylonjs.com/how_to/gui#image
  4849. */
  4850. get: function () {
  4851. return this._cellHeight;
  4852. },
  4853. set: function (value) {
  4854. if (this._cellHeight === value) {
  4855. return;
  4856. }
  4857. this._cellHeight = value;
  4858. this._markAsDirty();
  4859. },
  4860. enumerable: true,
  4861. configurable: true
  4862. });
  4863. Object.defineProperty(Image.prototype, "cellId", {
  4864. /**
  4865. * Gets or sets the cell id to use (this will turn on the animation sheet mode)
  4866. * @see http://doc.babylonjs.com/how_to/gui#image
  4867. */
  4868. get: function () {
  4869. return this._cellId;
  4870. },
  4871. set: function (value) {
  4872. if (this._cellId === value) {
  4873. return;
  4874. }
  4875. this._cellId = value;
  4876. this._markAsDirty();
  4877. },
  4878. enumerable: true,
  4879. configurable: true
  4880. });
  4881. Image.prototype._getTypeName = function () {
  4882. return "Image";
  4883. };
  4884. /** Force the control to synchronize with its content */
  4885. Image.prototype.synchronizeSizeWithContent = function () {
  4886. if (!this._loaded) {
  4887. return;
  4888. }
  4889. this.width = this._domImage.width + "px";
  4890. this.height = this._domImage.height + "px";
  4891. };
  4892. Image.prototype._draw = function (parentMeasure, context) {
  4893. context.save();
  4894. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4895. context.shadowColor = this.shadowColor;
  4896. context.shadowBlur = this.shadowBlur;
  4897. context.shadowOffsetX = this.shadowOffsetX;
  4898. context.shadowOffsetY = this.shadowOffsetY;
  4899. }
  4900. var x, y, width, height;
  4901. if (this.cellId == -1) {
  4902. x = this._sourceLeft;
  4903. y = this._sourceTop;
  4904. width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  4905. height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  4906. }
  4907. else {
  4908. var rowCount = this._domImage.naturalWidth / this.cellWidth;
  4909. var column = (this.cellId / rowCount) >> 0;
  4910. var row = this.cellId % rowCount;
  4911. x = this.cellWidth * row;
  4912. y = this.cellHeight * column;
  4913. width = this.cellWidth;
  4914. height = this.cellHeight;
  4915. }
  4916. this._applyStates(context);
  4917. if (this._processMeasures(parentMeasure, context)) {
  4918. if (this._loaded) {
  4919. switch (this._stretch) {
  4920. case Image.STRETCH_NONE:
  4921. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4922. break;
  4923. case Image.STRETCH_FILL:
  4924. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4925. break;
  4926. case Image.STRETCH_UNIFORM:
  4927. var hRatio = this._currentMeasure.width / width;
  4928. var vRatio = this._currentMeasure.height / height;
  4929. var ratio = Math.min(hRatio, vRatio);
  4930. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  4931. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  4932. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  4933. break;
  4934. case Image.STRETCH_EXTEND:
  4935. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4936. if (this._autoScale) {
  4937. this.synchronizeSizeWithContent();
  4938. }
  4939. if (this._root && this._root.parent) { // Will update root size if root is not the top root
  4940. this._root.width = this.width;
  4941. this._root.height = this.height;
  4942. }
  4943. break;
  4944. }
  4945. }
  4946. }
  4947. context.restore();
  4948. };
  4949. Object.defineProperty(Image, "STRETCH_NONE", {
  4950. /** STRETCH_NONE */
  4951. get: function () {
  4952. return Image._STRETCH_NONE;
  4953. },
  4954. enumerable: true,
  4955. configurable: true
  4956. });
  4957. Object.defineProperty(Image, "STRETCH_FILL", {
  4958. /** STRETCH_FILL */
  4959. get: function () {
  4960. return Image._STRETCH_FILL;
  4961. },
  4962. enumerable: true,
  4963. configurable: true
  4964. });
  4965. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  4966. /** STRETCH_UNIFORM */
  4967. get: function () {
  4968. return Image._STRETCH_UNIFORM;
  4969. },
  4970. enumerable: true,
  4971. configurable: true
  4972. });
  4973. Object.defineProperty(Image, "STRETCH_EXTEND", {
  4974. /** STRETCH_EXTEND */
  4975. get: function () {
  4976. return Image._STRETCH_EXTEND;
  4977. },
  4978. enumerable: true,
  4979. configurable: true
  4980. });
  4981. // Static
  4982. Image._STRETCH_NONE = 0;
  4983. Image._STRETCH_FILL = 1;
  4984. Image._STRETCH_UNIFORM = 2;
  4985. Image._STRETCH_EXTEND = 3;
  4986. return Image;
  4987. }(GUI.Control));
  4988. GUI.Image = Image;
  4989. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4990. })(BABYLON || (BABYLON = {}));
  4991. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4992. var BABYLON;
  4993. (function (BABYLON) {
  4994. var GUI;
  4995. (function (GUI) {
  4996. /**
  4997. * Class used to create 2D buttons
  4998. */
  4999. var Button = /** @class */ (function (_super) {
  5000. __extends(Button, _super);
  5001. /**
  5002. * Creates a new Button
  5003. * @param name defines the name of the button
  5004. */
  5005. function Button(name) {
  5006. var _this = _super.call(this, name) || this;
  5007. _this.name = name;
  5008. _this.thickness = 1;
  5009. _this.isPointerBlocker = true;
  5010. _this.pointerEnterAnimation = function () {
  5011. _this.alpha -= 0.1;
  5012. };
  5013. _this.pointerOutAnimation = function () {
  5014. _this.alpha += 0.1;
  5015. };
  5016. _this.pointerDownAnimation = function () {
  5017. _this.scaleX -= 0.05;
  5018. _this.scaleY -= 0.05;
  5019. };
  5020. _this.pointerUpAnimation = function () {
  5021. _this.scaleX += 0.05;
  5022. _this.scaleY += 0.05;
  5023. };
  5024. return _this;
  5025. }
  5026. Button.prototype._getTypeName = function () {
  5027. return "Button";
  5028. };
  5029. // While being a container, the button behaves like a control.
  5030. /** @hidden */
  5031. Button.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  5032. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  5033. return false;
  5034. }
  5035. if (!_super.prototype.contains.call(this, x, y)) {
  5036. return false;
  5037. }
  5038. this._processObservables(type, x, y, pointerId, buttonIndex);
  5039. return true;
  5040. };
  5041. /** @hidden */
  5042. Button.prototype._onPointerEnter = function (target) {
  5043. if (!_super.prototype._onPointerEnter.call(this, target)) {
  5044. return false;
  5045. }
  5046. if (this.pointerEnterAnimation) {
  5047. this.pointerEnterAnimation();
  5048. }
  5049. return true;
  5050. };
  5051. /** @hidden */
  5052. Button.prototype._onPointerOut = function (target) {
  5053. if (this.pointerOutAnimation) {
  5054. this.pointerOutAnimation();
  5055. }
  5056. _super.prototype._onPointerOut.call(this, target);
  5057. };
  5058. /** @hidden */
  5059. Button.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5060. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5061. return false;
  5062. }
  5063. if (this.pointerDownAnimation) {
  5064. this.pointerDownAnimation();
  5065. }
  5066. return true;
  5067. };
  5068. /** @hidden */
  5069. Button.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5070. if (this.pointerUpAnimation) {
  5071. this.pointerUpAnimation();
  5072. }
  5073. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5074. };
  5075. // Statics
  5076. /**
  5077. * Creates a new button made with an image and a text
  5078. * @param name defines the name of the button
  5079. * @param text defines the text of the button
  5080. * @param imageUrl defines the url of the image
  5081. * @returns a new Button
  5082. */
  5083. Button.CreateImageButton = function (name, text, imageUrl) {
  5084. var result = new Button(name);
  5085. // Adding text
  5086. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  5087. textBlock.textWrapping = true;
  5088. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  5089. textBlock.paddingLeft = "20%";
  5090. result.addControl(textBlock);
  5091. // Adding image
  5092. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  5093. iconImage.width = "20%";
  5094. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  5095. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5096. result.addControl(iconImage);
  5097. return result;
  5098. };
  5099. /**
  5100. * Creates a new button made with an image
  5101. * @param name defines the name of the button
  5102. * @param imageUrl defines the url of the image
  5103. * @returns a new Button
  5104. */
  5105. Button.CreateImageOnlyButton = function (name, imageUrl) {
  5106. var result = new Button(name);
  5107. // Adding image
  5108. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  5109. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  5110. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5111. result.addControl(iconImage);
  5112. return result;
  5113. };
  5114. /**
  5115. * Creates a new button made with a text
  5116. * @param name defines the name of the button
  5117. * @param text defines the text of the button
  5118. * @returns a new Button
  5119. */
  5120. Button.CreateSimpleButton = function (name, text) {
  5121. var result = new Button(name);
  5122. // Adding text
  5123. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  5124. textBlock.textWrapping = true;
  5125. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  5126. result.addControl(textBlock);
  5127. return result;
  5128. };
  5129. /**
  5130. * Creates a new button made with an image and a centered text
  5131. * @param name defines the name of the button
  5132. * @param text defines the text of the button
  5133. * @param imageUrl defines the url of the image
  5134. * @returns a new Button
  5135. */
  5136. Button.CreateImageWithCenterTextButton = function (name, text, imageUrl) {
  5137. var result = new Button(name);
  5138. // Adding image
  5139. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  5140. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  5141. result.addControl(iconImage);
  5142. // Adding text
  5143. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  5144. textBlock.textWrapping = true;
  5145. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  5146. result.addControl(textBlock);
  5147. return result;
  5148. };
  5149. return Button;
  5150. }(GUI.Rectangle));
  5151. GUI.Button = Button;
  5152. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5153. })(BABYLON || (BABYLON = {}));
  5154. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5155. var BABYLON;
  5156. (function (BABYLON) {
  5157. var GUI;
  5158. (function (GUI) {
  5159. /** Class used to create color pickers */
  5160. var ColorPicker = /** @class */ (function (_super) {
  5161. __extends(ColorPicker, _super);
  5162. /**
  5163. * Creates a new ColorPicker
  5164. * @param name defines the control name
  5165. */
  5166. function ColorPicker(name) {
  5167. var _this = _super.call(this, name) || this;
  5168. _this.name = name;
  5169. _this._value = BABYLON.Color3.Red();
  5170. _this._tmpColor = new BABYLON.Color3();
  5171. _this._pointerStartedOnSquare = false;
  5172. _this._pointerStartedOnWheel = false;
  5173. _this._squareLeft = 0;
  5174. _this._squareTop = 0;
  5175. _this._squareSize = 0;
  5176. _this._h = 360;
  5177. _this._s = 1;
  5178. _this._v = 1;
  5179. /**
  5180. * Observable raised when the value changes
  5181. */
  5182. _this.onValueChangedObservable = new BABYLON.Observable();
  5183. // Events
  5184. _this._pointerIsDown = false;
  5185. _this.value = new BABYLON.Color3(.88, .1, .1);
  5186. _this.size = "200px";
  5187. _this.isPointerBlocker = true;
  5188. return _this;
  5189. }
  5190. Object.defineProperty(ColorPicker.prototype, "value", {
  5191. /** Gets or sets the color of the color picker */
  5192. get: function () {
  5193. return this._value;
  5194. },
  5195. set: function (value) {
  5196. if (this._value.equals(value)) {
  5197. return;
  5198. }
  5199. this._value.copyFrom(value);
  5200. this._RGBtoHSV(this._value, this._tmpColor);
  5201. this._h = this._tmpColor.r;
  5202. this._s = Math.max(this._tmpColor.g, 0.00001);
  5203. this._v = Math.max(this._tmpColor.b, 0.00001);
  5204. this._markAsDirty();
  5205. this.onValueChangedObservable.notifyObservers(this._value);
  5206. },
  5207. enumerable: true,
  5208. configurable: true
  5209. });
  5210. Object.defineProperty(ColorPicker.prototype, "width", {
  5211. /** Gets or sets control width */
  5212. set: function (value) {
  5213. if (this._width.toString(this._host) === value) {
  5214. return;
  5215. }
  5216. if (this._width.fromString(value)) {
  5217. this._height.fromString(value);
  5218. this._markAsDirty();
  5219. }
  5220. },
  5221. enumerable: true,
  5222. configurable: true
  5223. });
  5224. Object.defineProperty(ColorPicker.prototype, "height", {
  5225. /** Gets or sets control height */
  5226. set: function (value) {
  5227. if (this._height.toString(this._host) === value) {
  5228. return;
  5229. }
  5230. if (this._height.fromString(value)) {
  5231. this._width.fromString(value);
  5232. this._markAsDirty();
  5233. }
  5234. },
  5235. enumerable: true,
  5236. configurable: true
  5237. });
  5238. Object.defineProperty(ColorPicker.prototype, "size", {
  5239. /** Gets or sets control size */
  5240. get: function () {
  5241. return this.width;
  5242. },
  5243. set: function (value) {
  5244. this.width = value;
  5245. },
  5246. enumerable: true,
  5247. configurable: true
  5248. });
  5249. ColorPicker.prototype._getTypeName = function () {
  5250. return "ColorPicker";
  5251. };
  5252. ColorPicker.prototype._updateSquareProps = function () {
  5253. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  5254. var wheelThickness = radius * .2;
  5255. var innerDiameter = (radius - wheelThickness) * 2;
  5256. var squareSize = innerDiameter / (Math.sqrt(2));
  5257. var offset = radius - squareSize * .5;
  5258. this._squareLeft = this._currentMeasure.left + offset;
  5259. this._squareTop = this._currentMeasure.top + offset;
  5260. this._squareSize = squareSize;
  5261. };
  5262. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  5263. var lgh = context.createLinearGradient(left, top, width + left, top);
  5264. lgh.addColorStop(0, '#fff');
  5265. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  5266. context.fillStyle = lgh;
  5267. context.fillRect(left, top, width, height);
  5268. var lgv = context.createLinearGradient(left, top, left, height + top);
  5269. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  5270. lgv.addColorStop(1, '#000');
  5271. context.fillStyle = lgv;
  5272. context.fillRect(left, top, width, height);
  5273. };
  5274. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  5275. context.beginPath();
  5276. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  5277. context.lineWidth = 3;
  5278. context.strokeStyle = '#333333';
  5279. context.stroke();
  5280. context.beginPath();
  5281. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  5282. context.lineWidth = 3;
  5283. context.strokeStyle = '#ffffff';
  5284. context.stroke();
  5285. };
  5286. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  5287. var canvas = document.createElement("canvas");
  5288. canvas.width = radius * 2;
  5289. canvas.height = radius * 2;
  5290. var context = canvas.getContext("2d");
  5291. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  5292. var data = image.data;
  5293. var color = this._tmpColor;
  5294. var maxDistSq = radius * radius;
  5295. var innerRadius = radius - thickness;
  5296. var minDistSq = innerRadius * innerRadius;
  5297. for (var x = -radius; x < radius; x++) {
  5298. for (var y = -radius; y < radius; y++) {
  5299. var distSq = x * x + y * y;
  5300. if (distSq > maxDistSq || distSq < minDistSq) {
  5301. continue;
  5302. }
  5303. var dist = Math.sqrt(distSq);
  5304. var ang = Math.atan2(y, x);
  5305. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  5306. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  5307. data[index] = color.r * 255;
  5308. data[index + 1] = color.g * 255;
  5309. data[index + 2] = color.b * 255;
  5310. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  5311. //apply less alpha to bigger color pickers
  5312. var alphaAmount = .2;
  5313. var maxAlpha = .2;
  5314. var minAlpha = .04;
  5315. var lowerRadius = 50;
  5316. var upperRadius = 150;
  5317. if (radius < lowerRadius) {
  5318. alphaAmount = maxAlpha;
  5319. }
  5320. else if (radius > upperRadius) {
  5321. alphaAmount = minAlpha;
  5322. }
  5323. else {
  5324. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  5325. }
  5326. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  5327. if (alphaRatio < alphaAmount) {
  5328. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  5329. }
  5330. else if (alphaRatio > 1 - alphaAmount) {
  5331. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  5332. }
  5333. else {
  5334. data[index + 3] = 255;
  5335. }
  5336. }
  5337. }
  5338. context.putImageData(image, 0, 0);
  5339. return canvas;
  5340. };
  5341. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  5342. var r = color.r;
  5343. var g = color.g;
  5344. var b = color.b;
  5345. var max = Math.max(r, g, b);
  5346. var min = Math.min(r, g, b);
  5347. var h = 0;
  5348. var s = 0;
  5349. var v = max;
  5350. var dm = max - min;
  5351. if (max !== 0) {
  5352. s = dm / max;
  5353. }
  5354. if (max != min) {
  5355. if (max == r) {
  5356. h = (g - b) / dm;
  5357. if (g < b) {
  5358. h += 6;
  5359. }
  5360. }
  5361. else if (max == g) {
  5362. h = (b - r) / dm + 2;
  5363. }
  5364. else if (max == b) {
  5365. h = (r - g) / dm + 4;
  5366. }
  5367. h *= 60;
  5368. }
  5369. result.r = h;
  5370. result.g = s;
  5371. result.b = v;
  5372. };
  5373. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  5374. var chroma = value * saturation;
  5375. var h = hue / 60;
  5376. var x = chroma * (1 - Math.abs((h % 2) - 1));
  5377. var r = 0;
  5378. var g = 0;
  5379. var b = 0;
  5380. if (h >= 0 && h <= 1) {
  5381. r = chroma;
  5382. g = x;
  5383. }
  5384. else if (h >= 1 && h <= 2) {
  5385. r = x;
  5386. g = chroma;
  5387. }
  5388. else if (h >= 2 && h <= 3) {
  5389. g = chroma;
  5390. b = x;
  5391. }
  5392. else if (h >= 3 && h <= 4) {
  5393. g = x;
  5394. b = chroma;
  5395. }
  5396. else if (h >= 4 && h <= 5) {
  5397. r = x;
  5398. b = chroma;
  5399. }
  5400. else if (h >= 5 && h <= 6) {
  5401. r = chroma;
  5402. b = x;
  5403. }
  5404. var m = value - chroma;
  5405. result.set((r + m), (g + m), (b + m));
  5406. };
  5407. /** @hidden */
  5408. ColorPicker.prototype._draw = function (parentMeasure, context) {
  5409. context.save();
  5410. this._applyStates(context);
  5411. if (this._processMeasures(parentMeasure, context)) {
  5412. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  5413. var wheelThickness = radius * .2;
  5414. var left = this._currentMeasure.left;
  5415. var top = this._currentMeasure.top;
  5416. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  5417. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  5418. }
  5419. this._updateSquareProps();
  5420. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5421. context.shadowColor = this.shadowColor;
  5422. context.shadowBlur = this.shadowBlur;
  5423. context.shadowOffsetX = this.shadowOffsetX;
  5424. context.shadowOffsetY = this.shadowOffsetY;
  5425. context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
  5426. }
  5427. context.drawImage(this._colorWheelCanvas, left, top);
  5428. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5429. context.shadowBlur = 0;
  5430. context.shadowOffsetX = 0;
  5431. context.shadowOffsetY = 0;
  5432. }
  5433. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  5434. var cx = this._squareLeft + this._squareSize * this._s;
  5435. var cy = this._squareTop + this._squareSize * (1 - this._v);
  5436. this._drawCircle(cx, cy, radius * .04, context);
  5437. var dist = radius - wheelThickness * .5;
  5438. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  5439. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  5440. this._drawCircle(cx, cy, wheelThickness * .35, context);
  5441. }
  5442. context.restore();
  5443. };
  5444. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  5445. if (this._pointerStartedOnWheel) {
  5446. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  5447. var centerX = radius + this._currentMeasure.left;
  5448. var centerY = radius + this._currentMeasure.top;
  5449. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  5450. }
  5451. else if (this._pointerStartedOnSquare) {
  5452. this._updateSquareProps();
  5453. this._s = (x - this._squareLeft) / this._squareSize;
  5454. this._v = 1 - (y - this._squareTop) / this._squareSize;
  5455. this._s = Math.min(this._s, 1);
  5456. this._s = Math.max(this._s, 0.00001);
  5457. this._v = Math.min(this._v, 1);
  5458. this._v = Math.max(this._v, 0.00001);
  5459. }
  5460. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  5461. this.value = this._tmpColor;
  5462. };
  5463. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  5464. this._updateSquareProps();
  5465. var left = this._squareLeft;
  5466. var top = this._squareTop;
  5467. var size = this._squareSize;
  5468. if (coordinates.x >= left && coordinates.x <= left + size &&
  5469. coordinates.y >= top && coordinates.y <= top + size) {
  5470. return true;
  5471. }
  5472. return false;
  5473. };
  5474. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  5475. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  5476. var centerX = radius + this._currentMeasure.left;
  5477. var centerY = radius + this._currentMeasure.top;
  5478. var wheelThickness = radius * .2;
  5479. var innerRadius = radius - wheelThickness;
  5480. var radiusSq = radius * radius;
  5481. var innerRadiusSq = innerRadius * innerRadius;
  5482. var dx = coordinates.x - centerX;
  5483. var dy = coordinates.y - centerY;
  5484. var distSq = dx * dx + dy * dy;
  5485. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  5486. return true;
  5487. }
  5488. return false;
  5489. };
  5490. ColorPicker.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5491. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5492. return false;
  5493. }
  5494. this._pointerIsDown = true;
  5495. this._pointerStartedOnSquare = false;
  5496. this._pointerStartedOnWheel = false;
  5497. if (this._isPointOnSquare(coordinates)) {
  5498. this._pointerStartedOnSquare = true;
  5499. }
  5500. else if (this._isPointOnWheel(coordinates)) {
  5501. this._pointerStartedOnWheel = true;
  5502. }
  5503. this._updateValueFromPointer(coordinates.x, coordinates.y);
  5504. this._host._capturingControl[pointerId] = this;
  5505. return true;
  5506. };
  5507. ColorPicker.prototype._onPointerMove = function (target, coordinates) {
  5508. if (this._pointerIsDown) {
  5509. this._updateValueFromPointer(coordinates.x, coordinates.y);
  5510. }
  5511. _super.prototype._onPointerMove.call(this, target, coordinates);
  5512. };
  5513. ColorPicker.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5514. this._pointerIsDown = false;
  5515. delete this._host._capturingControl[pointerId];
  5516. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5517. };
  5518. return ColorPicker;
  5519. }(GUI.Control));
  5520. GUI.ColorPicker = ColorPicker;
  5521. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5522. })(BABYLON || (BABYLON = {}));
  5523. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5524. var BABYLON;
  5525. (function (BABYLON) {
  5526. var GUI;
  5527. (function (GUI) {
  5528. /**
  5529. * Class used to create input text control
  5530. */
  5531. var InputText = /** @class */ (function (_super) {
  5532. __extends(InputText, _super);
  5533. /**
  5534. * Creates a new InputText
  5535. * @param name defines the control name
  5536. * @param text defines the text of the control
  5537. */
  5538. function InputText(name, text) {
  5539. if (text === void 0) { text = ""; }
  5540. var _this = _super.call(this, name) || this;
  5541. _this.name = name;
  5542. _this._text = "";
  5543. _this._placeholderText = "";
  5544. _this._background = "#222222";
  5545. _this._focusedBackground = "#000000";
  5546. _this._placeholderColor = "gray";
  5547. _this._thickness = 1;
  5548. _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
  5549. _this._autoStretchWidth = true;
  5550. _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  5551. _this._isFocused = false;
  5552. _this._blinkIsEven = false;
  5553. _this._cursorOffset = 0;
  5554. /** Gets or sets a string representing the message displayed on mobile when the control gets the focus */
  5555. _this.promptMessage = "Please enter text:";
  5556. /** Observable raised when the text changes */
  5557. _this.onTextChangedObservable = new BABYLON.Observable();
  5558. /** Observable raised when the control gets the focus */
  5559. _this.onFocusObservable = new BABYLON.Observable();
  5560. /** Observable raised when the control loses the focus */
  5561. _this.onBlurObservable = new BABYLON.Observable();
  5562. _this.text = text;
  5563. return _this;
  5564. }
  5565. Object.defineProperty(InputText.prototype, "maxWidth", {
  5566. /** Gets or sets the maximum width allowed by the control */
  5567. get: function () {
  5568. return this._maxWidth.toString(this._host);
  5569. },
  5570. set: function (value) {
  5571. if (this._maxWidth.toString(this._host) === value) {
  5572. return;
  5573. }
  5574. if (this._maxWidth.fromString(value)) {
  5575. this._markAsDirty();
  5576. }
  5577. },
  5578. enumerable: true,
  5579. configurable: true
  5580. });
  5581. Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
  5582. /** Gets the maximum width allowed by the control in pixels */
  5583. get: function () {
  5584. return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  5585. },
  5586. enumerable: true,
  5587. configurable: true
  5588. });
  5589. Object.defineProperty(InputText.prototype, "margin", {
  5590. /** Gets or sets control margin */
  5591. get: function () {
  5592. return this._margin.toString(this._host);
  5593. },
  5594. set: function (value) {
  5595. if (this._margin.toString(this._host) === value) {
  5596. return;
  5597. }
  5598. if (this._margin.fromString(value)) {
  5599. this._markAsDirty();
  5600. }
  5601. },
  5602. enumerable: true,
  5603. configurable: true
  5604. });
  5605. Object.defineProperty(InputText.prototype, "marginInPixels", {
  5606. /** Gets control margin in pixels */
  5607. get: function () {
  5608. return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
  5609. },
  5610. enumerable: true,
  5611. configurable: true
  5612. });
  5613. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  5614. /** Gets or sets a boolean indicating if the control can auto stretch its width to adapt to the text */
  5615. get: function () {
  5616. return this._autoStretchWidth;
  5617. },
  5618. set: function (value) {
  5619. if (this._autoStretchWidth === value) {
  5620. return;
  5621. }
  5622. this._autoStretchWidth = value;
  5623. this._markAsDirty();
  5624. },
  5625. enumerable: true,
  5626. configurable: true
  5627. });
  5628. Object.defineProperty(InputText.prototype, "thickness", {
  5629. /** Gets or sets border thickness */
  5630. get: function () {
  5631. return this._thickness;
  5632. },
  5633. set: function (value) {
  5634. if (this._thickness === value) {
  5635. return;
  5636. }
  5637. this._thickness = value;
  5638. this._markAsDirty();
  5639. },
  5640. enumerable: true,
  5641. configurable: true
  5642. });
  5643. Object.defineProperty(InputText.prototype, "focusedBackground", {
  5644. /** Gets or sets the background color when focused */
  5645. get: function () {
  5646. return this._focusedBackground;
  5647. },
  5648. set: function (value) {
  5649. if (this._focusedBackground === value) {
  5650. return;
  5651. }
  5652. this._focusedBackground = value;
  5653. this._markAsDirty();
  5654. },
  5655. enumerable: true,
  5656. configurable: true
  5657. });
  5658. Object.defineProperty(InputText.prototype, "background", {
  5659. /** Gets or sets the background color */
  5660. get: function () {
  5661. return this._background;
  5662. },
  5663. set: function (value) {
  5664. if (this._background === value) {
  5665. return;
  5666. }
  5667. this._background = value;
  5668. this._markAsDirty();
  5669. },
  5670. enumerable: true,
  5671. configurable: true
  5672. });
  5673. Object.defineProperty(InputText.prototype, "placeholderColor", {
  5674. /** Gets or sets the placeholder color */
  5675. get: function () {
  5676. return this._placeholderColor;
  5677. },
  5678. set: function (value) {
  5679. if (this._placeholderColor === value) {
  5680. return;
  5681. }
  5682. this._placeholderColor = value;
  5683. this._markAsDirty();
  5684. },
  5685. enumerable: true,
  5686. configurable: true
  5687. });
  5688. Object.defineProperty(InputText.prototype, "placeholderText", {
  5689. /** Gets or sets the text displayed when the control is empty */
  5690. get: function () {
  5691. return this._placeholderText;
  5692. },
  5693. set: function (value) {
  5694. if (this._placeholderText === value) {
  5695. return;
  5696. }
  5697. this._placeholderText = value;
  5698. this._markAsDirty();
  5699. },
  5700. enumerable: true,
  5701. configurable: true
  5702. });
  5703. Object.defineProperty(InputText.prototype, "text", {
  5704. /** Gets or sets the text displayed in the control */
  5705. get: function () {
  5706. return this._text;
  5707. },
  5708. set: function (value) {
  5709. if (this._text === value) {
  5710. return;
  5711. }
  5712. this._text = value;
  5713. this._markAsDirty();
  5714. this.onTextChangedObservable.notifyObservers(this);
  5715. },
  5716. enumerable: true,
  5717. configurable: true
  5718. });
  5719. Object.defineProperty(InputText.prototype, "width", {
  5720. /** Gets or sets control width */
  5721. get: function () {
  5722. return this._width.toString(this._host);
  5723. },
  5724. set: function (value) {
  5725. if (this._width.toString(this._host) === value) {
  5726. return;
  5727. }
  5728. if (this._width.fromString(value)) {
  5729. this._markAsDirty();
  5730. }
  5731. this.autoStretchWidth = false;
  5732. },
  5733. enumerable: true,
  5734. configurable: true
  5735. });
  5736. /** @hidden */
  5737. InputText.prototype.onBlur = function () {
  5738. this._isFocused = false;
  5739. this._scrollLeft = null;
  5740. this._cursorOffset = 0;
  5741. clearTimeout(this._blinkTimeout);
  5742. this._markAsDirty();
  5743. this.onBlurObservable.notifyObservers(this);
  5744. };
  5745. /** @hidden */
  5746. InputText.prototype.onFocus = function () {
  5747. this._scrollLeft = null;
  5748. this._isFocused = true;
  5749. this._blinkIsEven = false;
  5750. this._cursorOffset = 0;
  5751. this._markAsDirty();
  5752. this.onFocusObservable.notifyObservers(this);
  5753. if (navigator.userAgent.indexOf("Mobile") !== -1) {
  5754. var value = prompt(this.promptMessage);
  5755. if (value !== null) {
  5756. this.text = value;
  5757. }
  5758. this._host.focusedControl = null;
  5759. return;
  5760. }
  5761. };
  5762. InputText.prototype._getTypeName = function () {
  5763. return "InputText";
  5764. };
  5765. /** @hidden */
  5766. InputText.prototype.processKey = function (keyCode, key) {
  5767. // Specific cases
  5768. switch (keyCode) {
  5769. case 32: //SPACE
  5770. key = " "; //ie11 key for space is "Spacebar"
  5771. break;
  5772. case 8: // BACKSPACE
  5773. if (this._text && this._text.length > 0) {
  5774. if (this._cursorOffset === 0) {
  5775. this.text = this._text.substr(0, this._text.length - 1);
  5776. }
  5777. else {
  5778. var deletePosition = this._text.length - this._cursorOffset;
  5779. if (deletePosition > 0) {
  5780. this.text = this._text.slice(0, deletePosition - 1) + this._text.slice(deletePosition);
  5781. }
  5782. }
  5783. }
  5784. return;
  5785. case 46: // DELETE
  5786. if (this._text && this._text.length > 0) {
  5787. var deletePosition = this._text.length - this._cursorOffset;
  5788. this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
  5789. this._cursorOffset--;
  5790. }
  5791. return;
  5792. case 13: // RETURN
  5793. this._host.focusedControl = null;
  5794. return;
  5795. case 35: // END
  5796. this._cursorOffset = 0;
  5797. this._blinkIsEven = false;
  5798. this._markAsDirty();
  5799. return;
  5800. case 36: // HOME
  5801. this._cursorOffset = this._text.length;
  5802. this._blinkIsEven = false;
  5803. this._markAsDirty();
  5804. return;
  5805. case 37: // LEFT
  5806. this._cursorOffset++;
  5807. if (this._cursorOffset > this._text.length) {
  5808. this._cursorOffset = this._text.length;
  5809. }
  5810. this._blinkIsEven = false;
  5811. this._markAsDirty();
  5812. return;
  5813. case 39: // RIGHT
  5814. this._cursorOffset--;
  5815. if (this._cursorOffset < 0) {
  5816. this._cursorOffset = 0;
  5817. }
  5818. this._blinkIsEven = false;
  5819. this._markAsDirty();
  5820. return;
  5821. }
  5822. // Printable characters
  5823. if ((keyCode === -1) || // Direct access
  5824. (keyCode === 32) || // Space
  5825. (keyCode > 47 && keyCode < 58) || // Numbers
  5826. (keyCode > 64 && keyCode < 91) || // Letters
  5827. (keyCode > 185 && keyCode < 193) || // Special characters
  5828. (keyCode > 218 && keyCode < 223) || // Special characters
  5829. (keyCode > 95 && keyCode < 112)) { // Numpad
  5830. if (this._cursorOffset === 0) {
  5831. this.text += key;
  5832. }
  5833. else {
  5834. var insertPosition = this._text.length - this._cursorOffset;
  5835. this.text = this._text.slice(0, insertPosition) + key + this._text.slice(insertPosition);
  5836. }
  5837. }
  5838. };
  5839. /** @hidden */
  5840. InputText.prototype.processKeyboard = function (evt) {
  5841. this.processKey(evt.keyCode, evt.key);
  5842. };
  5843. InputText.prototype._draw = function (parentMeasure, context) {
  5844. var _this = this;
  5845. context.save();
  5846. this._applyStates(context);
  5847. if (this._processMeasures(parentMeasure, context)) {
  5848. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5849. context.shadowColor = this.shadowColor;
  5850. context.shadowBlur = this.shadowBlur;
  5851. context.shadowOffsetX = this.shadowOffsetX;
  5852. context.shadowOffsetY = this.shadowOffsetY;
  5853. }
  5854. // Background
  5855. if (this._isFocused) {
  5856. if (this._focusedBackground) {
  5857. context.fillStyle = this._focusedBackground;
  5858. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  5859. }
  5860. }
  5861. else if (this._background) {
  5862. context.fillStyle = this._background;
  5863. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  5864. }
  5865. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5866. context.shadowBlur = 0;
  5867. context.shadowOffsetX = 0;
  5868. context.shadowOffsetY = 0;
  5869. }
  5870. if (!this._fontOffset) {
  5871. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  5872. }
  5873. // Text
  5874. var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width);
  5875. if (this.color) {
  5876. context.fillStyle = this.color;
  5877. }
  5878. var text = this._text;
  5879. if (!this._isFocused && !this._text && this._placeholderText) {
  5880. text = this._placeholderText;
  5881. if (this._placeholderColor) {
  5882. context.fillStyle = this._placeholderColor;
  5883. }
  5884. }
  5885. this._textWidth = context.measureText(text).width;
  5886. var marginWidth = this._margin.getValueInPixel(this._host, parentMeasure.width) * 2;
  5887. if (this._autoStretchWidth) {
  5888. this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), this._textWidth + marginWidth) + "px";
  5889. }
  5890. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  5891. var availableWidth = this._width.getValueInPixel(this._host, parentMeasure.width) - marginWidth;
  5892. context.save();
  5893. context.beginPath();
  5894. context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
  5895. context.clip();
  5896. if (this._isFocused && this._textWidth > availableWidth) {
  5897. var textLeft = clipTextLeft - this._textWidth + availableWidth;
  5898. if (!this._scrollLeft) {
  5899. this._scrollLeft = textLeft;
  5900. }
  5901. }
  5902. else {
  5903. this._scrollLeft = clipTextLeft;
  5904. }
  5905. context.fillText(text, this._scrollLeft, this._currentMeasure.top + rootY);
  5906. // Cursor
  5907. if (this._isFocused) {
  5908. // Need to move cursor
  5909. if (this._clickedCoordinate) {
  5910. var rightPosition = this._scrollLeft + this._textWidth;
  5911. var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
  5912. var currentSize = 0;
  5913. this._cursorOffset = 0;
  5914. var previousDist = 0;
  5915. do {
  5916. if (this._cursorOffset) {
  5917. previousDist = Math.abs(absoluteCursorPosition - currentSize);
  5918. }
  5919. this._cursorOffset++;
  5920. currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
  5921. } while (currentSize < absoluteCursorPosition && (text.length >= this._cursorOffset));
  5922. // Find closest move
  5923. if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
  5924. this._cursorOffset--;
  5925. }
  5926. this._blinkIsEven = false;
  5927. this._clickedCoordinate = null;
  5928. }
  5929. // Render cursor
  5930. if (!this._blinkIsEven) {
  5931. var cursorOffsetText = this.text.substr(this._text.length - this._cursorOffset);
  5932. var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
  5933. var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
  5934. if (cursorLeft < clipTextLeft) {
  5935. this._scrollLeft += (clipTextLeft - cursorLeft);
  5936. cursorLeft = clipTextLeft;
  5937. this._markAsDirty();
  5938. }
  5939. else if (cursorLeft > clipTextLeft + availableWidth) {
  5940. this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
  5941. cursorLeft = clipTextLeft + availableWidth;
  5942. this._markAsDirty();
  5943. }
  5944. context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
  5945. }
  5946. clearTimeout(this._blinkTimeout);
  5947. this._blinkTimeout = setTimeout(function () {
  5948. _this._blinkIsEven = !_this._blinkIsEven;
  5949. _this._markAsDirty();
  5950. }, 500);
  5951. }
  5952. context.restore();
  5953. // Border
  5954. if (this._thickness) {
  5955. if (this.color) {
  5956. context.strokeStyle = this.color;
  5957. }
  5958. context.lineWidth = this._thickness;
  5959. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  5960. }
  5961. }
  5962. context.restore();
  5963. };
  5964. InputText.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5965. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5966. return false;
  5967. }
  5968. this._clickedCoordinate = coordinates.x;
  5969. if (this._host.focusedControl === this) {
  5970. // Move cursor
  5971. clearTimeout(this._blinkTimeout);
  5972. this._markAsDirty();
  5973. return true;
  5974. }
  5975. this._host.focusedControl = this;
  5976. return true;
  5977. };
  5978. InputText.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5979. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5980. };
  5981. InputText.prototype.dispose = function () {
  5982. _super.prototype.dispose.call(this);
  5983. this.onBlurObservable.clear();
  5984. this.onFocusObservable.clear();
  5985. this.onTextChangedObservable.clear();
  5986. };
  5987. return InputText;
  5988. }(GUI.Control));
  5989. GUI.InputText = InputText;
  5990. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5991. })(BABYLON || (BABYLON = {}));
  5992. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5993. var BABYLON;
  5994. (function (BABYLON) {
  5995. var GUI;
  5996. (function (GUI) {
  5997. /**
  5998. * Class used to store key control properties
  5999. */
  6000. var KeyPropertySet = /** @class */ (function () {
  6001. function KeyPropertySet() {
  6002. }
  6003. return KeyPropertySet;
  6004. }());
  6005. GUI.KeyPropertySet = KeyPropertySet;
  6006. /**
  6007. * Class used to create virtual keyboard
  6008. */
  6009. var VirtualKeyboard = /** @class */ (function (_super) {
  6010. __extends(VirtualKeyboard, _super);
  6011. function VirtualKeyboard() {
  6012. var _this = _super !== null && _super.apply(this, arguments) || this;
  6013. /** Observable raised when a key is pressed */
  6014. _this.onKeyPressObservable = new BABYLON.Observable();
  6015. /** Gets or sets default key button width */
  6016. _this.defaultButtonWidth = "40px";
  6017. /** Gets or sets default key button height */
  6018. _this.defaultButtonHeight = "40px";
  6019. /** Gets or sets default key button left padding */
  6020. _this.defaultButtonPaddingLeft = "2px";
  6021. /** Gets or sets default key button right padding */
  6022. _this.defaultButtonPaddingRight = "2px";
  6023. /** Gets or sets default key button top padding */
  6024. _this.defaultButtonPaddingTop = "2px";
  6025. /** Gets or sets default key button bottom padding */
  6026. _this.defaultButtonPaddingBottom = "2px";
  6027. /** Gets or sets default key button foreground color */
  6028. _this.defaultButtonColor = "#DDD";
  6029. /** Gets or sets default key button background color */
  6030. _this.defaultButtonBackground = "#070707";
  6031. /** Gets or sets shift button foreground color */
  6032. _this.shiftButtonColor = "#7799FF";
  6033. /** Gets or sets shift button thickness*/
  6034. _this.selectedShiftThickness = 1;
  6035. /** Gets shift key state */
  6036. _this.shiftState = 0;
  6037. return _this;
  6038. }
  6039. VirtualKeyboard.prototype._getTypeName = function () {
  6040. return "VirtualKeyboard";
  6041. };
  6042. VirtualKeyboard.prototype._createKey = function (key, propertySet) {
  6043. var _this = this;
  6044. var button = GUI.Button.CreateSimpleButton(key, key);
  6045. button.width = propertySet && propertySet.width ? propertySet.width : this.defaultButtonWidth;
  6046. button.height = propertySet && propertySet.height ? propertySet.height : this.defaultButtonHeight;
  6047. button.color = propertySet && propertySet.color ? propertySet.color : this.defaultButtonColor;
  6048. button.background = propertySet && propertySet.background ? propertySet.background : this.defaultButtonBackground;
  6049. button.paddingLeft = propertySet && propertySet.paddingLeft ? propertySet.paddingLeft : this.defaultButtonPaddingLeft;
  6050. button.paddingRight = propertySet && propertySet.paddingRight ? propertySet.paddingRight : this.defaultButtonPaddingRight;
  6051. button.paddingTop = propertySet && propertySet.paddingTop ? propertySet.paddingTop : this.defaultButtonPaddingTop;
  6052. button.paddingBottom = propertySet && propertySet.paddingBottom ? propertySet.paddingBottom : this.defaultButtonPaddingBottom;
  6053. button.thickness = 0;
  6054. button.isFocusInvisible = true;
  6055. button.shadowColor = this.shadowColor;
  6056. button.shadowBlur = this.shadowBlur;
  6057. button.shadowOffsetX = this.shadowOffsetX;
  6058. button.shadowOffsetY = this.shadowOffsetY;
  6059. button.onPointerUpObservable.add(function () {
  6060. _this.onKeyPressObservable.notifyObservers(key);
  6061. });
  6062. return button;
  6063. };
  6064. /**
  6065. * Adds a new row of keys
  6066. * @param keys defines the list of keys to add
  6067. * @param propertySets defines the associated property sets
  6068. */
  6069. VirtualKeyboard.prototype.addKeysRow = function (keys, propertySets) {
  6070. var panel = new GUI.StackPanel();
  6071. panel.isVertical = false;
  6072. panel.isFocusInvisible = true;
  6073. for (var i = 0; i < keys.length; i++) {
  6074. var properties = null;
  6075. if (propertySets && propertySets.length === keys.length) {
  6076. properties = propertySets[i];
  6077. }
  6078. panel.addControl(this._createKey(keys[i], properties));
  6079. }
  6080. this.addControl(panel);
  6081. };
  6082. /**
  6083. * Set the shift key to a specific state
  6084. * @param shiftState defines the new shift state
  6085. */
  6086. VirtualKeyboard.prototype.applyShiftState = function (shiftState) {
  6087. if (!this.children) {
  6088. return;
  6089. }
  6090. for (var i = 0; i < this.children.length; i++) {
  6091. var row = this.children[i];
  6092. if (!row || !row.children) {
  6093. continue;
  6094. }
  6095. var rowContainer = row;
  6096. for (var j = 0; j < rowContainer.children.length; j++) {
  6097. var button = rowContainer.children[j];
  6098. if (!button || !button.children[0]) {
  6099. continue;
  6100. }
  6101. var button_tblock = button.children[0];
  6102. if (button_tblock.text === "\u21E7") {
  6103. button.color = (shiftState ? this.shiftButtonColor : this.defaultButtonColor);
  6104. button.thickness = (shiftState > 1 ? this.selectedShiftThickness : 0);
  6105. }
  6106. button_tblock.text = (shiftState > 0 ? button_tblock.text.toUpperCase() : button_tblock.text.toLowerCase());
  6107. }
  6108. }
  6109. };
  6110. Object.defineProperty(VirtualKeyboard.prototype, "connectedInputText", {
  6111. /** Gets the input text control attached with the keyboard */
  6112. get: function () {
  6113. return this._connectedInputText;
  6114. },
  6115. enumerable: true,
  6116. configurable: true
  6117. });
  6118. /**
  6119. * Connects the keyboard with an input text control
  6120. * @param input defines the target control
  6121. */
  6122. VirtualKeyboard.prototype.connect = function (input) {
  6123. var _this = this;
  6124. this.isVisible = false;
  6125. this._connectedInputText = input;
  6126. // Events hooking
  6127. this._onFocusObserver = input.onFocusObservable.add(function () {
  6128. _this.isVisible = true;
  6129. });
  6130. this._onBlurObserver = input.onBlurObservable.add(function () {
  6131. _this.isVisible = false;
  6132. });
  6133. this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
  6134. if (!_this._connectedInputText) {
  6135. return;
  6136. }
  6137. switch (key) {
  6138. case "\u21E7":
  6139. _this.shiftState++;
  6140. if (_this.shiftState > 2) {
  6141. _this.shiftState = 0;
  6142. }
  6143. _this.applyShiftState(_this.shiftState);
  6144. return;
  6145. case "\u2190":
  6146. _this._connectedInputText.processKey(8);
  6147. return;
  6148. case "\u21B5":
  6149. _this._connectedInputText.processKey(13);
  6150. return;
  6151. }
  6152. _this._connectedInputText.processKey(-1, (_this.shiftState ? key.toUpperCase() : key));
  6153. if (_this.shiftState === 1) {
  6154. _this.shiftState = 0;
  6155. _this.applyShiftState(_this.shiftState);
  6156. }
  6157. });
  6158. };
  6159. /**
  6160. * Disconnects the keyboard from an input text control
  6161. */
  6162. VirtualKeyboard.prototype.disconnect = function () {
  6163. if (!this._connectedInputText) {
  6164. return;
  6165. }
  6166. this._connectedInputText.onFocusObservable.remove(this._onFocusObserver);
  6167. this._connectedInputText.onBlurObservable.remove(this._onBlurObserver);
  6168. this.onKeyPressObservable.remove(this._onKeyPressObserver);
  6169. this._connectedInputText = null;
  6170. };
  6171. // Statics
  6172. /**
  6173. * Creates a new keyboard using a default layout
  6174. * @returns a new VirtualKeyboard
  6175. */
  6176. VirtualKeyboard.CreateDefaultLayout = function () {
  6177. var returnValue = new VirtualKeyboard();
  6178. returnValue.addKeysRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u2190"]);
  6179. returnValue.addKeysRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]);
  6180. returnValue.addKeysRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\u21B5"]);
  6181. returnValue.addKeysRow(["\u21E7", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]);
  6182. returnValue.addKeysRow([" "], [{ width: "200px" }]);
  6183. return returnValue;
  6184. };
  6185. return VirtualKeyboard;
  6186. }(GUI.StackPanel));
  6187. GUI.VirtualKeyboard = VirtualKeyboard;
  6188. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6189. })(BABYLON || (BABYLON = {}));
  6190. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  6191. var BABYLON;
  6192. (function (BABYLON) {
  6193. var GUI;
  6194. (function (GUI) {
  6195. /**
  6196. * Class used to create multi line control
  6197. */
  6198. var MultiLine = /** @class */ (function (_super) {
  6199. __extends(MultiLine, _super);
  6200. /**
  6201. * Creates a new MultiLine
  6202. * @param name defines the control name
  6203. */
  6204. function MultiLine(name) {
  6205. var _this = _super.call(this, name) || this;
  6206. _this.name = name;
  6207. _this._lineWidth = 1;
  6208. /** Function called when a point is updated */
  6209. _this.onPointUpdate = function () {
  6210. _this._markAsDirty();
  6211. };
  6212. _this.isHitTestVisible = false;
  6213. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6214. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  6215. _this._dash = [];
  6216. _this._points = [];
  6217. return _this;
  6218. }
  6219. Object.defineProperty(MultiLine.prototype, "dash", {
  6220. /** Gets or sets dash pattern */
  6221. get: function () {
  6222. return this._dash;
  6223. },
  6224. set: function (value) {
  6225. if (this._dash === value) {
  6226. return;
  6227. }
  6228. this._dash = value;
  6229. this._markAsDirty();
  6230. },
  6231. enumerable: true,
  6232. configurable: true
  6233. });
  6234. /**
  6235. * Gets point stored at specified index
  6236. * @param index defines the index to look for
  6237. * @returns the requested point if found
  6238. */
  6239. MultiLine.prototype.getAt = function (index) {
  6240. if (!this._points[index]) {
  6241. this._points[index] = new GUI.MultiLinePoint(this);
  6242. }
  6243. return this._points[index];
  6244. };
  6245. /**
  6246. * Adds new points to the point collection
  6247. * @param items defines the list of items (mesh, control or 2d coordiantes) to add
  6248. * @returns the list of created MultiLinePoint
  6249. */
  6250. MultiLine.prototype.add = function () {
  6251. var _this = this;
  6252. var items = [];
  6253. for (var _i = 0; _i < arguments.length; _i++) {
  6254. items[_i] = arguments[_i];
  6255. }
  6256. return items.map(function (item) { return _this.push(item); });
  6257. };
  6258. /**
  6259. * Adds a new point to the point collection
  6260. * @param item defines the item (mesh, control or 2d coordiantes) to add
  6261. * @returns the created MultiLinePoint
  6262. */
  6263. MultiLine.prototype.push = function (item) {
  6264. var point = this.getAt(this._points.length);
  6265. if (item == null)
  6266. return point;
  6267. if (item instanceof BABYLON.AbstractMesh) {
  6268. point.mesh = item;
  6269. }
  6270. else if (item instanceof GUI.Control) {
  6271. point.control = item;
  6272. }
  6273. else if (item.x != null && item.y != null) {
  6274. point.x = item.x;
  6275. point.y = item.y;
  6276. }
  6277. return point;
  6278. };
  6279. /**
  6280. * Remove a specific value or point from the active point collection
  6281. * @param value defines the value or point to remove
  6282. */
  6283. MultiLine.prototype.remove = function (value) {
  6284. var index;
  6285. if (value instanceof GUI.MultiLinePoint) {
  6286. index = this._points.indexOf(value);
  6287. if (index === -1) {
  6288. return;
  6289. }
  6290. }
  6291. else {
  6292. index = value;
  6293. }
  6294. var point = this._points[index];
  6295. if (!point) {
  6296. return;
  6297. }
  6298. point.dispose();
  6299. this._points.splice(index, 1);
  6300. };
  6301. Object.defineProperty(MultiLine.prototype, "lineWidth", {
  6302. /** Gets or sets line width */
  6303. get: function () {
  6304. return this._lineWidth;
  6305. },
  6306. set: function (value) {
  6307. if (this._lineWidth === value) {
  6308. return;
  6309. }
  6310. this._lineWidth = value;
  6311. this._markAsDirty();
  6312. },
  6313. enumerable: true,
  6314. configurable: true
  6315. });
  6316. Object.defineProperty(MultiLine.prototype, "horizontalAlignment", {
  6317. set: function (value) {
  6318. return;
  6319. },
  6320. enumerable: true,
  6321. configurable: true
  6322. });
  6323. Object.defineProperty(MultiLine.prototype, "verticalAlignment", {
  6324. set: function (value) {
  6325. return;
  6326. },
  6327. enumerable: true,
  6328. configurable: true
  6329. });
  6330. MultiLine.prototype._getTypeName = function () {
  6331. return "MultiLine";
  6332. };
  6333. MultiLine.prototype._draw = function (parentMeasure, context) {
  6334. context.save();
  6335. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6336. context.shadowColor = this.shadowColor;
  6337. context.shadowBlur = this.shadowBlur;
  6338. context.shadowOffsetX = this.shadowOffsetX;
  6339. context.shadowOffsetY = this.shadowOffsetY;
  6340. }
  6341. this._applyStates(context);
  6342. if (this._processMeasures(parentMeasure, context)) {
  6343. context.strokeStyle = this.color;
  6344. context.lineWidth = this._lineWidth;
  6345. context.setLineDash(this._dash);
  6346. context.beginPath();
  6347. var first = true; //first index is not necessarily 0
  6348. this._points.forEach(function (point) {
  6349. if (!point) {
  6350. return;
  6351. }
  6352. if (first) {
  6353. context.moveTo(point._point.x, point._point.y);
  6354. first = false;
  6355. }
  6356. else {
  6357. context.lineTo(point._point.x, point._point.y);
  6358. }
  6359. });
  6360. context.stroke();
  6361. }
  6362. context.restore();
  6363. };
  6364. MultiLine.prototype._additionalProcessing = function (parentMeasure, context) {
  6365. var _this = this;
  6366. this._minX = null;
  6367. this._minY = null;
  6368. this._maxX = null;
  6369. this._maxY = null;
  6370. this._points.forEach(function (point, index) {
  6371. if (!point) {
  6372. return;
  6373. }
  6374. point.translate();
  6375. if (_this._minX == null || point._point.x < _this._minX)
  6376. _this._minX = point._point.x;
  6377. if (_this._minY == null || point._point.y < _this._minY)
  6378. _this._minY = point._point.y;
  6379. if (_this._maxX == null || point._point.x > _this._maxX)
  6380. _this._maxX = point._point.x;
  6381. if (_this._maxY == null || point._point.y > _this._maxY)
  6382. _this._maxY = point._point.y;
  6383. });
  6384. if (this._minX == null)
  6385. this._minX = 0;
  6386. if (this._minY == null)
  6387. this._minY = 0;
  6388. if (this._maxX == null)
  6389. this._maxX = 0;
  6390. if (this._maxY == null)
  6391. this._maxY = 0;
  6392. };
  6393. MultiLine.prototype._measure = function () {
  6394. if (this._minX == null || this._maxX == null || this._minY == null || this._maxY == null) {
  6395. return;
  6396. }
  6397. this._currentMeasure.width = Math.abs(this._maxX - this._minX) + this._lineWidth;
  6398. this._currentMeasure.height = Math.abs(this._maxY - this._minY) + this._lineWidth;
  6399. };
  6400. MultiLine.prototype._computeAlignment = function (parentMeasure, context) {
  6401. if (this._minX == null || this._minY == null) {
  6402. return;
  6403. }
  6404. this._currentMeasure.left = this._minX - this._lineWidth / 2;
  6405. this._currentMeasure.top = this._minY - this._lineWidth / 2;
  6406. };
  6407. MultiLine.prototype.dispose = function () {
  6408. while (this._points.length > 0) {
  6409. this.remove(this._points.length - 1);
  6410. }
  6411. _super.prototype.dispose.call(this);
  6412. };
  6413. return MultiLine;
  6414. }(GUI.Control));
  6415. GUI.MultiLine = MultiLine;
  6416. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6417. })(BABYLON || (BABYLON = {}));
  6418. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  6419. var BABYLON;
  6420. (function (BABYLON) {
  6421. var GUI;
  6422. (function (GUI) {
  6423. /**
  6424. * Class used to manage 3D user interface
  6425. * @see http://doc.babylonjs.com/how_to/gui3d
  6426. */
  6427. var GUI3DManager = /** @class */ (function () {
  6428. /**
  6429. * Creates a new GUI3DManager
  6430. * @param scene
  6431. */
  6432. function GUI3DManager(scene) {
  6433. var _this = this;
  6434. /** @hidden */
  6435. this._lastControlOver = {};
  6436. /** @hidden */
  6437. this._lastControlDown = {};
  6438. /**
  6439. * Observable raised when the point picked by the pointer events changed
  6440. */
  6441. this.onPickedPointChangedObservable = new BABYLON.Observable();
  6442. // Shared resources
  6443. /** @hidden */
  6444. this._sharedMaterials = {};
  6445. this._scene = scene || BABYLON.Engine.LastCreatedScene;
  6446. this._sceneDisposeObserver = this._scene.onDisposeObservable.add(function () {
  6447. _this._sceneDisposeObserver = null;
  6448. _this._utilityLayer = null;
  6449. _this.dispose();
  6450. });
  6451. this._utilityLayer = new BABYLON.UtilityLayerRenderer(this._scene);
  6452. // Root
  6453. this._rootContainer = new GUI.Container3D("RootContainer");
  6454. this._rootContainer._host = this;
  6455. // Events
  6456. this._pointerObserver = this._scene.onPrePointerObservable.add(function (pi, state) {
  6457. if (pi.skipOnPointerObservable) {
  6458. return;
  6459. }
  6460. var pointerEvent = (pi.event);
  6461. if (_this._scene.isPointerCaptured(pointerEvent.pointerId)) {
  6462. return;
  6463. }
  6464. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  6465. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  6466. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  6467. return;
  6468. }
  6469. var camera = _this._scene.cameraToUseForPointers || _this._scene.activeCamera;
  6470. if (!camera) {
  6471. return;
  6472. }
  6473. pi.skipOnPointerObservable = _this._doPicking(pi.type, pointerEvent, pi.ray);
  6474. });
  6475. // Scene
  6476. this._utilityLayer.utilityLayerScene.autoClear = false;
  6477. this._utilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
  6478. new BABYLON.HemisphericLight("hemi", BABYLON.Vector3.Up(), this._utilityLayer.utilityLayerScene);
  6479. }
  6480. Object.defineProperty(GUI3DManager.prototype, "scene", {
  6481. /** Gets the hosting scene */
  6482. get: function () {
  6483. return this._scene;
  6484. },
  6485. enumerable: true,
  6486. configurable: true
  6487. });
  6488. Object.defineProperty(GUI3DManager.prototype, "utilityLayer", {
  6489. /** Gets associated utility layer */
  6490. get: function () {
  6491. return this._utilityLayer;
  6492. },
  6493. enumerable: true,
  6494. configurable: true
  6495. });
  6496. GUI3DManager.prototype._doPicking = function (type, pointerEvent, ray) {
  6497. if (!this._utilityLayer || !this._utilityLayer.utilityLayerScene.activeCamera) {
  6498. return false;
  6499. }
  6500. var pointerId = pointerEvent.pointerId || 0;
  6501. var buttonIndex = pointerEvent.button;
  6502. var utilityScene = this._utilityLayer.utilityLayerScene;
  6503. var pickingInfo = ray ? utilityScene.pickWithRay(ray) : utilityScene.pick(this._scene.pointerX, this._scene.pointerY);
  6504. if (!pickingInfo || !pickingInfo.hit) {
  6505. var previousControlOver = this._lastControlOver[pointerId];
  6506. if (previousControlOver) {
  6507. previousControlOver._onPointerOut(previousControlOver);
  6508. delete this._lastControlOver[pointerId];
  6509. }
  6510. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  6511. if (this._lastControlDown[pointerEvent.pointerId]) {
  6512. this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  6513. delete this._lastControlDown[pointerEvent.pointerId];
  6514. }
  6515. }
  6516. this.onPickedPointChangedObservable.notifyObservers(null);
  6517. return false;
  6518. }
  6519. var control = (pickingInfo.pickedMesh.metadata);
  6520. if (pickingInfo.pickedPoint) {
  6521. this.onPickedPointChangedObservable.notifyObservers(pickingInfo.pickedPoint);
  6522. }
  6523. if (!control._processObservables(type, pickingInfo.pickedPoint, pointerId, buttonIndex)) {
  6524. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  6525. if (this._lastControlOver[pointerId]) {
  6526. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  6527. }
  6528. delete this._lastControlOver[pointerId];
  6529. }
  6530. }
  6531. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  6532. if (this._lastControlDown[pointerEvent.pointerId]) {
  6533. this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  6534. delete this._lastControlDown[pointerEvent.pointerId];
  6535. }
  6536. }
  6537. return true;
  6538. };
  6539. Object.defineProperty(GUI3DManager.prototype, "rootContainer", {
  6540. /**
  6541. * Gets the root container
  6542. */
  6543. get: function () {
  6544. return this._rootContainer;
  6545. },
  6546. enumerable: true,
  6547. configurable: true
  6548. });
  6549. /**
  6550. * Gets a boolean indicating if the given control is in the root child list
  6551. * @param control defines the control to check
  6552. * @returns true if the control is in the root child list
  6553. */
  6554. GUI3DManager.prototype.containsControl = function (control) {
  6555. return this._rootContainer.containsControl(control);
  6556. };
  6557. /**
  6558. * Adds a control to the root child list
  6559. * @param control defines the control to add
  6560. * @returns the current manager
  6561. */
  6562. GUI3DManager.prototype.addControl = function (control) {
  6563. this._rootContainer.addControl(control);
  6564. return this;
  6565. };
  6566. /**
  6567. * Removes a control from the root child list
  6568. * @param control defines the control to remove
  6569. * @returns the current container
  6570. */
  6571. GUI3DManager.prototype.removeControl = function (control) {
  6572. this._rootContainer.removeControl(control);
  6573. return this;
  6574. };
  6575. /**
  6576. * Releases all associated resources
  6577. */
  6578. GUI3DManager.prototype.dispose = function () {
  6579. this._rootContainer.dispose();
  6580. for (var materialName in this._sharedMaterials) {
  6581. if (!this._sharedMaterials.hasOwnProperty(materialName)) {
  6582. continue;
  6583. }
  6584. this._sharedMaterials[materialName].dispose();
  6585. }
  6586. this._sharedMaterials = {};
  6587. this.onPickedPointChangedObservable.clear();
  6588. if (this._scene) {
  6589. if (this._pointerObserver) {
  6590. this._scene.onPrePointerObservable.remove(this._pointerObserver);
  6591. this._pointerObserver = null;
  6592. }
  6593. if (this._sceneDisposeObserver) {
  6594. this._scene.onDisposeObservable.remove(this._sceneDisposeObserver);
  6595. this._sceneDisposeObserver = null;
  6596. }
  6597. }
  6598. if (this._utilityLayer) {
  6599. this._utilityLayer.dispose();
  6600. }
  6601. };
  6602. return GUI3DManager;
  6603. }());
  6604. GUI.GUI3DManager = GUI3DManager;
  6605. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6606. })(BABYLON || (BABYLON = {}));
  6607. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  6608. var BABYLON;
  6609. (function (BABYLON) {
  6610. var GUI;
  6611. (function (GUI) {
  6612. /** @hidden */
  6613. var FluentMaterialDefines = /** @class */ (function (_super) {
  6614. __extends(FluentMaterialDefines, _super);
  6615. function FluentMaterialDefines() {
  6616. var _this = _super.call(this) || this;
  6617. _this.INNERGLOW = false;
  6618. _this.BORDER = false;
  6619. _this.HOVERLIGHT = false;
  6620. _this.rebuild();
  6621. return _this;
  6622. }
  6623. return FluentMaterialDefines;
  6624. }(BABYLON.MaterialDefines));
  6625. GUI.FluentMaterialDefines = FluentMaterialDefines;
  6626. /**
  6627. * Class used to render controls with fluent desgin
  6628. */
  6629. var FluentMaterial = /** @class */ (function (_super) {
  6630. __extends(FluentMaterial, _super);
  6631. /**
  6632. * Creates a new Fluent material
  6633. * @param name defines the name of the material
  6634. * @param scene defines the hosting scene
  6635. */
  6636. function FluentMaterial(name, scene) {
  6637. var _this = _super.call(this, name, scene) || this;
  6638. /**
  6639. * Gets or sets inner glow intensity. A value of 0 means no glow (default is 0.5)
  6640. */
  6641. _this.innerGlowColorIntensity = 0.5;
  6642. /**
  6643. * Gets or sets the inner glow color (white by default)
  6644. */
  6645. _this.innerGlowColor = new BABYLON.Color3(1.0, 1.0, 1.0);
  6646. /**
  6647. * Gets or sets alpha value (default is 1.0)
  6648. */
  6649. _this.alpha = 1.0;
  6650. /**
  6651. * Gets or sets the albedo color (Default is Color3(0.3, 0.35, 0.4))
  6652. */
  6653. _this.albedoColor = new BABYLON.Color3(0.3, 0.35, 0.4);
  6654. /**
  6655. * Gets or sets a boolean indicating if borders must be rendered (default is false)
  6656. */
  6657. _this.renderBorders = false;
  6658. /**
  6659. * Gets or sets border width (default is 0.5)
  6660. */
  6661. _this.borderWidth = 0.5;
  6662. /**
  6663. * Gets or sets a value indicating the smoothing value applied to border edges (0.02 by default)
  6664. */
  6665. _this.edgeSmoothingValue = 0.02;
  6666. /**
  6667. * Gets or sets the minimum value that can be applied to border width (default is 0.1)
  6668. */
  6669. _this.borderMinValue = 0.1;
  6670. /**
  6671. * Gets or sets a boolean indicating if hover light must be rendered (default is false)
  6672. */
  6673. _this.renderHoverLight = false;
  6674. /**
  6675. * Gets or sets the radius used to render the hover light (default is 0.15)
  6676. */
  6677. _this.hoverRadius = 1.0;
  6678. /**
  6679. * Gets or sets the color used to render the hover light (default is Color4(0.3, 0.3, 0.3, 1.0))
  6680. */
  6681. _this.hoverColor = new BABYLON.Color4(0.3, 0.3, 0.3, 1.0);
  6682. /**
  6683. * Gets or sets the hover light position in world space (default is Vector3.Zero())
  6684. */
  6685. _this.hoverPosition = BABYLON.Vector3.Zero();
  6686. return _this;
  6687. }
  6688. FluentMaterial.prototype.needAlphaBlending = function () {
  6689. return this.alpha !== 1.0;
  6690. };
  6691. FluentMaterial.prototype.needAlphaTesting = function () {
  6692. return false;
  6693. };
  6694. FluentMaterial.prototype.getAlphaTestTexture = function () {
  6695. return null;
  6696. };
  6697. FluentMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  6698. if (this.isFrozen) {
  6699. if (this._wasPreviouslyReady && subMesh.effect) {
  6700. return true;
  6701. }
  6702. }
  6703. if (!subMesh._materialDefines) {
  6704. subMesh._materialDefines = new FluentMaterialDefines();
  6705. }
  6706. var scene = this.getScene();
  6707. var defines = subMesh._materialDefines;
  6708. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  6709. if (defines._renderId === scene.getRenderId()) {
  6710. return true;
  6711. }
  6712. }
  6713. if (defines._areTexturesDirty) {
  6714. defines.INNERGLOW = this.innerGlowColorIntensity > 0;
  6715. defines.BORDER = this.renderBorders;
  6716. defines.HOVERLIGHT = this.renderHoverLight;
  6717. }
  6718. var engine = scene.getEngine();
  6719. // Get correct effect
  6720. if (defines.isDirty) {
  6721. defines.markAsProcessed();
  6722. scene.resetCachedMaterial();
  6723. //Attributes
  6724. var attribs = [BABYLON.VertexBuffer.PositionKind];
  6725. attribs.push(BABYLON.VertexBuffer.NormalKind);
  6726. attribs.push(BABYLON.VertexBuffer.UVKind);
  6727. var shaderName = "fluent";
  6728. var uniforms = ["world", "viewProjection", "innerGlowColor", "albedoColor", "borderWidth", "edgeSmoothingValue", "scaleFactor", "borderMinValue",
  6729. "hoverColor", "hoverPosition", "hoverRadius"
  6730. ];
  6731. var samplers = new Array();
  6732. var uniformBuffers = new Array();
  6733. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  6734. uniformsNames: uniforms,
  6735. uniformBuffersNames: uniformBuffers,
  6736. samplers: samplers,
  6737. defines: defines,
  6738. maxSimultaneousLights: 4
  6739. });
  6740. var join = defines.toString();
  6741. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  6742. attributes: attribs,
  6743. uniformsNames: uniforms,
  6744. uniformBuffersNames: uniformBuffers,
  6745. samplers: samplers,
  6746. defines: join,
  6747. fallbacks: null,
  6748. onCompiled: this.onCompiled,
  6749. onError: this.onError,
  6750. indexParameters: { maxSimultaneousLights: 4 }
  6751. }, engine));
  6752. }
  6753. if (!subMesh.effect || !subMesh.effect.isReady()) {
  6754. return false;
  6755. }
  6756. defines._renderId = scene.getRenderId();
  6757. this._wasPreviouslyReady = true;
  6758. return true;
  6759. };
  6760. FluentMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  6761. var scene = this.getScene();
  6762. var defines = subMesh._materialDefines;
  6763. if (!defines) {
  6764. return;
  6765. }
  6766. var effect = subMesh.effect;
  6767. if (!effect) {
  6768. return;
  6769. }
  6770. this._activeEffect = effect;
  6771. // Matrices
  6772. this.bindOnlyWorldMatrix(world);
  6773. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  6774. if (this._mustRebind(scene, effect)) {
  6775. this._activeEffect.setColor4("albedoColor", this.albedoColor, this.alpha);
  6776. if (defines.INNERGLOW) {
  6777. this._activeEffect.setColor4("innerGlowColor", this.innerGlowColor, this.innerGlowColorIntensity);
  6778. }
  6779. if (defines.BORDER) {
  6780. this._activeEffect.setFloat("borderWidth", this.borderWidth);
  6781. this._activeEffect.setFloat("edgeSmoothingValue", this.edgeSmoothingValue);
  6782. this._activeEffect.setFloat("borderMinValue", this.borderMinValue);
  6783. mesh.getBoundingInfo().boundingBox.extendSize.multiplyToRef(mesh.scaling, BABYLON.Tmp.Vector3[0]);
  6784. this._activeEffect.setVector3("scaleFactor", BABYLON.Tmp.Vector3[0]);
  6785. }
  6786. if (defines.HOVERLIGHT) {
  6787. this._activeEffect.setDirectColor4("hoverColor", this.hoverColor);
  6788. this._activeEffect.setFloat("hoverRadius", this.hoverRadius);
  6789. this._activeEffect.setVector3("hoverPosition", this.hoverPosition);
  6790. }
  6791. }
  6792. this._afterBind(mesh, this._activeEffect);
  6793. };
  6794. FluentMaterial.prototype.getActiveTextures = function () {
  6795. var activeTextures = _super.prototype.getActiveTextures.call(this);
  6796. return activeTextures;
  6797. };
  6798. FluentMaterial.prototype.hasTexture = function (texture) {
  6799. if (_super.prototype.hasTexture.call(this, texture)) {
  6800. return true;
  6801. }
  6802. return false;
  6803. };
  6804. FluentMaterial.prototype.dispose = function (forceDisposeEffect) {
  6805. _super.prototype.dispose.call(this, forceDisposeEffect);
  6806. };
  6807. FluentMaterial.prototype.clone = function (name) {
  6808. var _this = this;
  6809. return BABYLON.SerializationHelper.Clone(function () { return new FluentMaterial(name, _this.getScene()); }, this);
  6810. };
  6811. FluentMaterial.prototype.serialize = function () {
  6812. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  6813. serializationObject.customType = "BABYLON.GUI.FluentMaterial";
  6814. return serializationObject;
  6815. };
  6816. FluentMaterial.prototype.getClassName = function () {
  6817. return "FluentMaterial";
  6818. };
  6819. // Statics
  6820. FluentMaterial.Parse = function (source, scene, rootUrl) {
  6821. return BABYLON.SerializationHelper.Parse(function () { return new FluentMaterial(source.name, scene); }, source, scene, rootUrl);
  6822. };
  6823. __decorate([
  6824. BABYLON.serialize(),
  6825. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6826. ], FluentMaterial.prototype, "innerGlowColorIntensity", void 0);
  6827. __decorate([
  6828. BABYLON.serializeAsColor3()
  6829. ], FluentMaterial.prototype, "innerGlowColor", void 0);
  6830. __decorate([
  6831. BABYLON.serialize()
  6832. ], FluentMaterial.prototype, "alpha", void 0);
  6833. __decorate([
  6834. BABYLON.serializeAsColor3()
  6835. ], FluentMaterial.prototype, "albedoColor", void 0);
  6836. __decorate([
  6837. BABYLON.serialize(),
  6838. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6839. ], FluentMaterial.prototype, "renderBorders", void 0);
  6840. __decorate([
  6841. BABYLON.serialize()
  6842. ], FluentMaterial.prototype, "borderWidth", void 0);
  6843. __decorate([
  6844. BABYLON.serialize()
  6845. ], FluentMaterial.prototype, "edgeSmoothingValue", void 0);
  6846. __decorate([
  6847. BABYLON.serialize()
  6848. ], FluentMaterial.prototype, "borderMinValue", void 0);
  6849. __decorate([
  6850. BABYLON.serialize(),
  6851. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6852. ], FluentMaterial.prototype, "renderHoverLight", void 0);
  6853. __decorate([
  6854. BABYLON.serialize()
  6855. ], FluentMaterial.prototype, "hoverRadius", void 0);
  6856. __decorate([
  6857. BABYLON.serializeAsColor4()
  6858. ], FluentMaterial.prototype, "hoverColor", void 0);
  6859. __decorate([
  6860. BABYLON.serializeAsVector3()
  6861. ], FluentMaterial.prototype, "hoverPosition", void 0);
  6862. return FluentMaterial;
  6863. }(BABYLON.PushMaterial));
  6864. GUI.FluentMaterial = FluentMaterial;
  6865. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6866. })(BABYLON || (BABYLON = {}));
  6867. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  6868. var BABYLON;
  6869. (function (BABYLON) {
  6870. var GUI;
  6871. (function (GUI) {
  6872. /**
  6873. * Class used to transport Vector3 information for pointer events
  6874. */
  6875. var Vector3WithInfo = /** @class */ (function (_super) {
  6876. __extends(Vector3WithInfo, _super);
  6877. /**
  6878. * Creates a new Vector3WithInfo
  6879. * @param source defines the vector3 data to transport
  6880. * @param buttonIndex defines the current mouse button index
  6881. */
  6882. function Vector3WithInfo(source,
  6883. /** defines the current mouse button index */
  6884. buttonIndex) {
  6885. if (buttonIndex === void 0) { buttonIndex = 0; }
  6886. var _this = _super.call(this, source.x, source.y, source.z) || this;
  6887. _this.buttonIndex = buttonIndex;
  6888. return _this;
  6889. }
  6890. return Vector3WithInfo;
  6891. }(BABYLON.Vector3));
  6892. GUI.Vector3WithInfo = Vector3WithInfo;
  6893. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6894. })(BABYLON || (BABYLON = {}));
  6895. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  6896. var BABYLON;
  6897. (function (BABYLON) {
  6898. var GUI;
  6899. (function (GUI) {
  6900. /**
  6901. * Class used as base class for controls
  6902. */
  6903. var Control3D = /** @class */ (function () {
  6904. /**
  6905. * Creates a new control
  6906. * @param name defines the control name
  6907. */
  6908. function Control3D(
  6909. /** Defines the control name */
  6910. name) {
  6911. this.name = name;
  6912. this._downCount = 0;
  6913. this._enterCount = -1;
  6914. this._downPointerIds = {};
  6915. this._isVisible = true;
  6916. /** Gets or sets the control position in world space */
  6917. this.position = new BABYLON.Vector3(0, 0, 0);
  6918. /** Gets or sets the control scaling in world space */
  6919. this.scaling = new BABYLON.Vector3(1, 1, 1);
  6920. /**
  6921. * An event triggered when the pointer move over the control
  6922. */
  6923. this.onPointerMoveObservable = new BABYLON.Observable();
  6924. /**
  6925. * An event triggered when the pointer move out of the control
  6926. */
  6927. this.onPointerOutObservable = new BABYLON.Observable();
  6928. /**
  6929. * An event triggered when the pointer taps the control
  6930. */
  6931. this.onPointerDownObservable = new BABYLON.Observable();
  6932. /**
  6933. * An event triggered when pointer is up
  6934. */
  6935. this.onPointerUpObservable = new BABYLON.Observable();
  6936. /**
  6937. * An event triggered when a control is clicked on (with a mouse)
  6938. */
  6939. this.onPointerClickObservable = new BABYLON.Observable();
  6940. /**
  6941. * An event triggered when pointer enters the control
  6942. */
  6943. this.onPointerEnterObservable = new BABYLON.Observable();
  6944. // Behaviors
  6945. this._behaviors = new Array();
  6946. }
  6947. Object.defineProperty(Control3D.prototype, "behaviors", {
  6948. /**
  6949. * Gets the list of attached behaviors
  6950. * @see http://doc.babylonjs.com/features/behaviour
  6951. */
  6952. get: function () {
  6953. return this._behaviors;
  6954. },
  6955. enumerable: true,
  6956. configurable: true
  6957. });
  6958. /**
  6959. * Attach a behavior to the control
  6960. * @see http://doc.babylonjs.com/features/behaviour
  6961. * @param behavior defines the behavior to attach
  6962. * @returns the current control
  6963. */
  6964. Control3D.prototype.addBehavior = function (behavior) {
  6965. var _this = this;
  6966. var index = this._behaviors.indexOf(behavior);
  6967. if (index !== -1) {
  6968. return this;
  6969. }
  6970. behavior.init();
  6971. var scene = this._host.scene;
  6972. if (scene.isLoading) {
  6973. // We defer the attach when the scene will be loaded
  6974. scene.onDataLoadedObservable.addOnce(function () {
  6975. behavior.attach(_this);
  6976. });
  6977. }
  6978. else {
  6979. behavior.attach(this);
  6980. }
  6981. this._behaviors.push(behavior);
  6982. return this;
  6983. };
  6984. /**
  6985. * Remove an attached behavior
  6986. * @see http://doc.babylonjs.com/features/behaviour
  6987. * @param behavior defines the behavior to attach
  6988. * @returns the current control
  6989. */
  6990. Control3D.prototype.removeBehavior = function (behavior) {
  6991. var index = this._behaviors.indexOf(behavior);
  6992. if (index === -1) {
  6993. return this;
  6994. }
  6995. this._behaviors[index].detach();
  6996. this._behaviors.splice(index, 1);
  6997. return this;
  6998. };
  6999. /**
  7000. * Gets an attached behavior by name
  7001. * @param name defines the name of the behavior to look for
  7002. * @see http://doc.babylonjs.com/features/behaviour
  7003. * @returns null if behavior was not found else the requested behavior
  7004. */
  7005. Control3D.prototype.getBehaviorByName = function (name) {
  7006. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  7007. var behavior = _a[_i];
  7008. if (behavior.name === name) {
  7009. return behavior;
  7010. }
  7011. }
  7012. return null;
  7013. };
  7014. Object.defineProperty(Control3D.prototype, "isVisible", {
  7015. /** Gets or sets a boolean indicating if the control is visible */
  7016. get: function () {
  7017. return this._isVisible;
  7018. },
  7019. set: function (value) {
  7020. if (this._isVisible === value) {
  7021. return;
  7022. }
  7023. this._isVisible = value;
  7024. var mesh = this.mesh;
  7025. if (mesh) {
  7026. mesh.isVisible = value;
  7027. }
  7028. },
  7029. enumerable: true,
  7030. configurable: true
  7031. });
  7032. Object.defineProperty(Control3D.prototype, "typeName", {
  7033. /**
  7034. * Gets a string representing the class name
  7035. */
  7036. get: function () {
  7037. return this._getTypeName();
  7038. },
  7039. enumerable: true,
  7040. configurable: true
  7041. });
  7042. Control3D.prototype._getTypeName = function () {
  7043. return "Control3D";
  7044. };
  7045. Object.defineProperty(Control3D.prototype, "node", {
  7046. /**
  7047. * Gets the transform node used by this control
  7048. */
  7049. get: function () {
  7050. return this._node;
  7051. },
  7052. enumerable: true,
  7053. configurable: true
  7054. });
  7055. Object.defineProperty(Control3D.prototype, "mesh", {
  7056. /**
  7057. * Gets the mesh used to render this control
  7058. */
  7059. get: function () {
  7060. if (this._node instanceof BABYLON.AbstractMesh) {
  7061. return this._node;
  7062. }
  7063. return null;
  7064. },
  7065. enumerable: true,
  7066. configurable: true
  7067. });
  7068. /**
  7069. * Link the control as child of the given node
  7070. * @param node defines the node to link to. Use null to unlink the control
  7071. * @returns the current control
  7072. */
  7073. Control3D.prototype.linkToTransformNode = function (node) {
  7074. if (this._node) {
  7075. this._node.parent = node;
  7076. }
  7077. return this;
  7078. };
  7079. /** @hidden **/
  7080. Control3D.prototype._prepareNode = function (scene) {
  7081. if (!this._node) {
  7082. this._node = this._createNode(scene);
  7083. if (!this.node) {
  7084. return;
  7085. }
  7086. this._node.metadata = this; // Store the control on the metadata field in order to get it when picking
  7087. this._node.position = this.position;
  7088. this._node.scaling = this.scaling;
  7089. var mesh = this.mesh;
  7090. if (mesh) {
  7091. mesh.isPickable = true;
  7092. this._affectMaterial(mesh);
  7093. }
  7094. }
  7095. };
  7096. /**
  7097. * Node creation.
  7098. * Can be overriden by children
  7099. * @param scene defines the scene where the node must be attached
  7100. * @returns the attached node or null if none. Must return a Mesh or AbstractMesh if there is an atttached visible object
  7101. */
  7102. Control3D.prototype._createNode = function (scene) {
  7103. // Do nothing by default
  7104. return null;
  7105. };
  7106. /**
  7107. * Affect a material to the given mesh
  7108. * @param mesh defines the mesh which will represent the control
  7109. */
  7110. Control3D.prototype._affectMaterial = function (mesh) {
  7111. mesh.material = null;
  7112. };
  7113. // Pointers
  7114. /** @hidden */
  7115. Control3D.prototype._onPointerMove = function (target, coordinates) {
  7116. this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  7117. };
  7118. /** @hidden */
  7119. Control3D.prototype._onPointerEnter = function (target) {
  7120. if (this._enterCount > 0) {
  7121. return false;
  7122. }
  7123. if (this._enterCount === -1) { // -1 is for touch input, we are now sure we are with a mouse or pencil
  7124. this._enterCount = 0;
  7125. }
  7126. this._enterCount++;
  7127. this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  7128. if (this.pointerEnterAnimation) {
  7129. this.pointerEnterAnimation();
  7130. }
  7131. return true;
  7132. };
  7133. /** @hidden */
  7134. Control3D.prototype._onPointerOut = function (target) {
  7135. this._enterCount = 0;
  7136. this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  7137. if (this.pointerOutAnimation) {
  7138. this.pointerOutAnimation();
  7139. }
  7140. };
  7141. /** @hidden */
  7142. Control3D.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  7143. if (this._downCount !== 0) {
  7144. return false;
  7145. }
  7146. this._downCount++;
  7147. this._downPointerIds[pointerId] = true;
  7148. this.onPointerDownObservable.notifyObservers(new GUI.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  7149. if (this.pointerDownAnimation) {
  7150. this.pointerDownAnimation();
  7151. }
  7152. return true;
  7153. };
  7154. /** @hidden */
  7155. Control3D.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  7156. this._downCount = 0;
  7157. delete this._downPointerIds[pointerId];
  7158. if (notifyClick && (this._enterCount > 0 || this._enterCount === -1)) {
  7159. this.onPointerClickObservable.notifyObservers(new GUI.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  7160. }
  7161. this.onPointerUpObservable.notifyObservers(new GUI.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  7162. if (this.pointerUpAnimation) {
  7163. this.pointerUpAnimation();
  7164. }
  7165. };
  7166. /** @hidden */
  7167. Control3D.prototype.forcePointerUp = function (pointerId) {
  7168. if (pointerId === void 0) { pointerId = null; }
  7169. if (pointerId !== null) {
  7170. this._onPointerUp(this, BABYLON.Vector3.Zero(), pointerId, 0, true);
  7171. }
  7172. else {
  7173. for (var key in this._downPointerIds) {
  7174. this._onPointerUp(this, BABYLON.Vector3.Zero(), +key, 0, true);
  7175. }
  7176. }
  7177. };
  7178. /** @hidden */
  7179. Control3D.prototype._processObservables = function (type, pickedPoint, pointerId, buttonIndex) {
  7180. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  7181. this._onPointerMove(this, pickedPoint);
  7182. var previousControlOver = this._host._lastControlOver[pointerId];
  7183. if (previousControlOver && previousControlOver !== this) {
  7184. previousControlOver._onPointerOut(this);
  7185. }
  7186. if (previousControlOver !== this) {
  7187. this._onPointerEnter(this);
  7188. }
  7189. this._host._lastControlOver[pointerId] = this;
  7190. return true;
  7191. }
  7192. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  7193. this._onPointerDown(this, pickedPoint, pointerId, buttonIndex);
  7194. this._host._lastControlDown[pointerId] = this;
  7195. this._host._lastPickedControl = this;
  7196. return true;
  7197. }
  7198. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  7199. if (this._host._lastControlDown[pointerId]) {
  7200. this._host._lastControlDown[pointerId]._onPointerUp(this, pickedPoint, pointerId, buttonIndex, true);
  7201. }
  7202. delete this._host._lastControlDown[pointerId];
  7203. return true;
  7204. }
  7205. return false;
  7206. };
  7207. /** @hidden */
  7208. Control3D.prototype._disposeNode = function () {
  7209. if (this._node) {
  7210. this._node.dispose();
  7211. this._node = null;
  7212. }
  7213. };
  7214. /**
  7215. * Releases all associated resources
  7216. */
  7217. Control3D.prototype.dispose = function () {
  7218. this.onPointerDownObservable.clear();
  7219. this.onPointerEnterObservable.clear();
  7220. this.onPointerMoveObservable.clear();
  7221. this.onPointerOutObservable.clear();
  7222. this.onPointerUpObservable.clear();
  7223. this.onPointerClickObservable.clear();
  7224. this._disposeNode();
  7225. // Behaviors
  7226. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  7227. var behavior = _a[_i];
  7228. behavior.detach();
  7229. }
  7230. };
  7231. return Control3D;
  7232. }());
  7233. GUI.Control3D = Control3D;
  7234. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7235. })(BABYLON || (BABYLON = {}));
  7236. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  7237. var BABYLON;
  7238. (function (BABYLON) {
  7239. var GUI;
  7240. (function (GUI) {
  7241. /**
  7242. * Class used to create containers for controls
  7243. */
  7244. var Container3D = /** @class */ (function (_super) {
  7245. __extends(Container3D, _super);
  7246. /**
  7247. * Creates a new container
  7248. * @param name defines the container name
  7249. */
  7250. function Container3D(name) {
  7251. var _this = _super.call(this, name) || this;
  7252. /**
  7253. * Gets the list of child controls
  7254. */
  7255. _this._children = new Array();
  7256. return _this;
  7257. }
  7258. /**
  7259. * Gets a boolean indicating if the given control is in the children of this control
  7260. * @param control defines the control to check
  7261. * @returns true if the control is in the child list
  7262. */
  7263. Container3D.prototype.containsControl = function (control) {
  7264. return this._children.indexOf(control) !== -1;
  7265. };
  7266. /**
  7267. * Adds a control to the children of this control
  7268. * @param control defines the control to add
  7269. * @returns the current container
  7270. */
  7271. Container3D.prototype.addControl = function (control) {
  7272. var index = this._children.indexOf(control);
  7273. if (index !== -1) {
  7274. return this;
  7275. }
  7276. control.parent = this;
  7277. control._host = this._host;
  7278. this._children.push(control);
  7279. if (this._host.utilityLayer) {
  7280. control._prepareNode(this._host.utilityLayer.utilityLayerScene);
  7281. if (control.node) {
  7282. control.node.parent = this.node;
  7283. }
  7284. this._arrangeChildren();
  7285. }
  7286. return this;
  7287. };
  7288. /**
  7289. * This function will be called everytime a new control is added
  7290. */
  7291. Container3D.prototype._arrangeChildren = function () {
  7292. };
  7293. Container3D.prototype._createNode = function (scene) {
  7294. return new BABYLON.TransformNode("ContainerNode", scene);
  7295. };
  7296. /**
  7297. * Removes a control from the children of this control
  7298. * @param control defines the control to remove
  7299. * @returns the current container
  7300. */
  7301. Container3D.prototype.removeControl = function (control) {
  7302. var index = this._children.indexOf(control);
  7303. if (index !== -1) {
  7304. this._children.splice(index, 1);
  7305. control.parent = null;
  7306. control._disposeNode();
  7307. }
  7308. return this;
  7309. };
  7310. Container3D.prototype._getTypeName = function () {
  7311. return "Container3D";
  7312. };
  7313. /**
  7314. * Releases all associated resources
  7315. */
  7316. Container3D.prototype.dispose = function () {
  7317. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  7318. var control = _a[_i];
  7319. control.dispose();
  7320. }
  7321. this._children = [];
  7322. _super.prototype.dispose.call(this);
  7323. };
  7324. return Container3D;
  7325. }(GUI.Control3D));
  7326. GUI.Container3D = Container3D;
  7327. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7328. })(BABYLON || (BABYLON = {}));
  7329. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  7330. var BABYLON;
  7331. (function (BABYLON) {
  7332. var GUI;
  7333. (function (GUI) {
  7334. /**
  7335. * Class used to create a button in 3D
  7336. */
  7337. var Button3D = /** @class */ (function (_super) {
  7338. __extends(Button3D, _super);
  7339. /**
  7340. * Creates a new button
  7341. * @param name defines the control name
  7342. */
  7343. function Button3D(name) {
  7344. var _this = _super.call(this, name) || this;
  7345. _this._contentResolution = 512;
  7346. _this._contentScaleRatio = 2;
  7347. // Default animations
  7348. _this.pointerEnterAnimation = function () {
  7349. if (!_this.mesh) {
  7350. return;
  7351. }
  7352. _this._currentMaterial.emissiveColor = BABYLON.Color3.Red();
  7353. };
  7354. _this.pointerOutAnimation = function () {
  7355. _this._currentMaterial.emissiveColor = BABYLON.Color3.Black();
  7356. };
  7357. _this.pointerDownAnimation = function () {
  7358. if (!_this.mesh) {
  7359. return;
  7360. }
  7361. _this.mesh.scaling.scaleInPlace(0.95);
  7362. };
  7363. _this.pointerUpAnimation = function () {
  7364. if (!_this.mesh) {
  7365. return;
  7366. }
  7367. _this.mesh.scaling.scaleInPlace(1.0 / 0.95);
  7368. };
  7369. return _this;
  7370. }
  7371. Object.defineProperty(Button3D.prototype, "contentResolution", {
  7372. /**
  7373. * Gets or sets the texture resolution used to render content (512 by default)
  7374. */
  7375. get: function () {
  7376. return this._contentResolution;
  7377. },
  7378. set: function (value) {
  7379. if (this._contentResolution === value) {
  7380. return;
  7381. }
  7382. this._contentResolution = value;
  7383. this._resetContent();
  7384. },
  7385. enumerable: true,
  7386. configurable: true
  7387. });
  7388. Object.defineProperty(Button3D.prototype, "contentScaleRatio", {
  7389. /**
  7390. * Gets or sets the texture scale ratio used to render content (2 by default)
  7391. */
  7392. get: function () {
  7393. return this._contentScaleRatio;
  7394. },
  7395. set: function (value) {
  7396. if (this._contentScaleRatio === value) {
  7397. return;
  7398. }
  7399. this._contentScaleRatio = value;
  7400. this._resetContent();
  7401. },
  7402. enumerable: true,
  7403. configurable: true
  7404. });
  7405. Button3D.prototype._disposeFacadeTexture = function () {
  7406. if (this._facadeTexture) {
  7407. this._facadeTexture.dispose();
  7408. this._facadeTexture = null;
  7409. }
  7410. };
  7411. Button3D.prototype._resetContent = function () {
  7412. this._disposeFacadeTexture();
  7413. this.content = this._content;
  7414. };
  7415. Object.defineProperty(Button3D.prototype, "content", {
  7416. /**
  7417. * Gets or sets the GUI 2D content used to display the button's facade
  7418. */
  7419. get: function () {
  7420. return this._content;
  7421. },
  7422. set: function (value) {
  7423. this._content = value;
  7424. if (!this._host || !this._host.utilityLayer) {
  7425. return;
  7426. }
  7427. if (!this._facadeTexture) {
  7428. this._facadeTexture = new BABYLON.GUI.AdvancedDynamicTexture("Facade", this._contentResolution, this._contentResolution, this._host.utilityLayer.utilityLayerScene, true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  7429. this._facadeTexture.rootContainer.scaleX = this._contentScaleRatio;
  7430. this._facadeTexture.rootContainer.scaleY = this._contentScaleRatio;
  7431. this._facadeTexture.premulAlpha = true;
  7432. }
  7433. this._facadeTexture.addControl(value);
  7434. this._applyFacade(this._facadeTexture);
  7435. },
  7436. enumerable: true,
  7437. configurable: true
  7438. });
  7439. /**
  7440. * Apply the facade texture (created from the content property).
  7441. * This function can be overloaded by child classes
  7442. * @param facadeTexture defines the AdvancedDynamicTexture to use
  7443. */
  7444. Button3D.prototype._applyFacade = function (facadeTexture) {
  7445. this._currentMaterial.emissiveTexture = facadeTexture;
  7446. };
  7447. Button3D.prototype._getTypeName = function () {
  7448. return "Button3D";
  7449. };
  7450. // Mesh association
  7451. Button3D.prototype._createNode = function (scene) {
  7452. var faceUV = new Array(6);
  7453. for (var i = 0; i < 6; i++) {
  7454. faceUV[i] = new BABYLON.Vector4(0, 0, 0, 0);
  7455. }
  7456. faceUV[1] = new BABYLON.Vector4(0, 0, 1, 1);
  7457. var mesh = BABYLON.MeshBuilder.CreateBox(this.name + "_rootMesh", {
  7458. width: 1.0,
  7459. height: 1.0,
  7460. depth: 0.08,
  7461. faceUV: faceUV
  7462. }, scene);
  7463. return mesh;
  7464. };
  7465. Button3D.prototype._affectMaterial = function (mesh) {
  7466. var material = new BABYLON.StandardMaterial(this.name + "Material", mesh.getScene());
  7467. material.specularColor = BABYLON.Color3.Black();
  7468. mesh.material = material;
  7469. this._currentMaterial = material;
  7470. this._resetContent();
  7471. };
  7472. /**
  7473. * Releases all associated resources
  7474. */
  7475. Button3D.prototype.dispose = function () {
  7476. _super.prototype.dispose.call(this);
  7477. this._disposeFacadeTexture();
  7478. if (this._currentMaterial) {
  7479. this._currentMaterial.dispose();
  7480. }
  7481. };
  7482. return Button3D;
  7483. }(GUI.Control3D));
  7484. GUI.Button3D = Button3D;
  7485. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7486. })(BABYLON || (BABYLON = {}));
  7487. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  7488. var BABYLON;
  7489. (function (BABYLON) {
  7490. var GUI;
  7491. (function (GUI) {
  7492. /**
  7493. * Class used to create a holographic button in 3D
  7494. */
  7495. var HolographicButton = /** @class */ (function (_super) {
  7496. __extends(HolographicButton, _super);
  7497. /**
  7498. * Creates a new button
  7499. * @param name defines the control name
  7500. */
  7501. function HolographicButton(name, shareMaterials) {
  7502. if (shareMaterials === void 0) { shareMaterials = true; }
  7503. var _this = _super.call(this, name) || this;
  7504. _this._shareMaterials = true;
  7505. _this._shareMaterials = shareMaterials;
  7506. // Default animations
  7507. _this.pointerEnterAnimation = function () {
  7508. if (!_this.mesh) {
  7509. return;
  7510. }
  7511. _this._frontPlate.setEnabled(true);
  7512. };
  7513. _this.pointerOutAnimation = function () {
  7514. if (!_this.mesh) {
  7515. return;
  7516. }
  7517. _this._frontPlate.setEnabled(false);
  7518. };
  7519. return _this;
  7520. }
  7521. Object.defineProperty(HolographicButton.prototype, "text", {
  7522. /**
  7523. * Gets or sets text for the button
  7524. */
  7525. get: function () {
  7526. return this._text;
  7527. },
  7528. set: function (value) {
  7529. if (this._text === value) {
  7530. return;
  7531. }
  7532. this._text = value;
  7533. this._rebuildContent();
  7534. },
  7535. enumerable: true,
  7536. configurable: true
  7537. });
  7538. Object.defineProperty(HolographicButton.prototype, "imageUrl", {
  7539. /**
  7540. * Gets or sets the image url for the button
  7541. */
  7542. get: function () {
  7543. return this._imageUrl;
  7544. },
  7545. set: function (value) {
  7546. if (this._imageUrl === value) {
  7547. return;
  7548. }
  7549. this._imageUrl = value;
  7550. this._rebuildContent();
  7551. },
  7552. enumerable: true,
  7553. configurable: true
  7554. });
  7555. Object.defineProperty(HolographicButton.prototype, "backMaterial", {
  7556. /**
  7557. * Gets the back material used by this button
  7558. */
  7559. get: function () {
  7560. return this._backMaterial;
  7561. },
  7562. enumerable: true,
  7563. configurable: true
  7564. });
  7565. Object.defineProperty(HolographicButton.prototype, "frontMaterial", {
  7566. /**
  7567. * Gets the front material used by this button
  7568. */
  7569. get: function () {
  7570. return this._frontMaterial;
  7571. },
  7572. enumerable: true,
  7573. configurable: true
  7574. });
  7575. Object.defineProperty(HolographicButton.prototype, "plateMaterial", {
  7576. /**
  7577. * Gets the plate material used by this button
  7578. */
  7579. get: function () {
  7580. return this._plateMaterial;
  7581. },
  7582. enumerable: true,
  7583. configurable: true
  7584. });
  7585. Object.defineProperty(HolographicButton.prototype, "shareMaterials", {
  7586. /**
  7587. * Gets a boolean indicating if this button shares its material with other HolographicButtons
  7588. */
  7589. get: function () {
  7590. return this._shareMaterials;
  7591. },
  7592. enumerable: true,
  7593. configurable: true
  7594. });
  7595. HolographicButton.prototype._getTypeName = function () {
  7596. return "HolographicButton";
  7597. };
  7598. HolographicButton.prototype._rebuildContent = function () {
  7599. this._disposeFacadeTexture();
  7600. var panel = new GUI.StackPanel();
  7601. panel.isVertical = true;
  7602. if (this._imageUrl) {
  7603. var image = new BABYLON.GUI.Image();
  7604. image.source = this._imageUrl;
  7605. image.paddingTop = "40px";
  7606. image.height = "180px";
  7607. image.width = "100px";
  7608. image.paddingBottom = "40px";
  7609. panel.addControl(image);
  7610. }
  7611. if (this._text) {
  7612. var text = new BABYLON.GUI.TextBlock();
  7613. text.text = this._text;
  7614. text.color = "white";
  7615. text.height = "30px";
  7616. text.fontSize = 24;
  7617. panel.addControl(text);
  7618. }
  7619. if (this._frontPlate) {
  7620. this.content = panel;
  7621. }
  7622. };
  7623. // Mesh association
  7624. HolographicButton.prototype._createNode = function (scene) {
  7625. this._backPlate = BABYLON.MeshBuilder.CreateBox(this.name + "BackMesh", {
  7626. width: 1.0,
  7627. height: 1.0,
  7628. depth: 0.08
  7629. }, scene);
  7630. this._frontPlate = BABYLON.MeshBuilder.CreateBox(this.name + "FrontMesh", {
  7631. width: 1.0,
  7632. height: 1.0,
  7633. depth: 0.08
  7634. }, scene);
  7635. this._frontPlate.parent = this._backPlate;
  7636. this._frontPlate.position.z = -0.08;
  7637. this._frontPlate.isPickable = false;
  7638. this._frontPlate.setEnabled(false);
  7639. this._textPlate = _super.prototype._createNode.call(this, scene);
  7640. this._textPlate.parent = this._backPlate;
  7641. this._textPlate.position.z = -0.08;
  7642. this._textPlate.isPickable = false;
  7643. return this._backPlate;
  7644. };
  7645. HolographicButton.prototype._applyFacade = function (facadeTexture) {
  7646. this._plateMaterial.emissiveTexture = facadeTexture;
  7647. this._plateMaterial.opacityTexture = facadeTexture;
  7648. };
  7649. HolographicButton.prototype._createBackMaterial = function (mesh) {
  7650. var _this = this;
  7651. this._backMaterial = new GUI.FluentMaterial(this.name + "Back Material", mesh.getScene());
  7652. this._backMaterial.renderHoverLight = true;
  7653. this._pickedPointObserver = this._host.onPickedPointChangedObservable.add(function (pickedPoint) {
  7654. if (pickedPoint) {
  7655. _this._backMaterial.hoverPosition = pickedPoint;
  7656. _this._backMaterial.hoverColor.a = 1.0;
  7657. }
  7658. else {
  7659. _this._backMaterial.hoverColor.a = 0;
  7660. }
  7661. });
  7662. };
  7663. HolographicButton.prototype._createFrontMaterial = function (mesh) {
  7664. this._frontMaterial = new GUI.FluentMaterial(this.name + "Front Material", mesh.getScene());
  7665. this._frontMaterial.innerGlowColorIntensity = 0; // No inner glow
  7666. this._frontMaterial.alpha = 0.5; // Additive
  7667. this._frontMaterial.renderBorders = true;
  7668. };
  7669. HolographicButton.prototype._createPlateMaterial = function (mesh) {
  7670. this._plateMaterial = new BABYLON.StandardMaterial(this.name + "Plate Material", mesh.getScene());
  7671. this._plateMaterial.specularColor = BABYLON.Color3.Black();
  7672. };
  7673. HolographicButton.prototype._affectMaterial = function (mesh) {
  7674. // Back
  7675. if (this._shareMaterials) {
  7676. if (!this._host._sharedMaterials["backFluentMaterial"]) {
  7677. this._createBackMaterial(mesh);
  7678. this._host._sharedMaterials["backFluentMaterial"] = this._backMaterial;
  7679. }
  7680. else {
  7681. this._backMaterial = this._host._sharedMaterials["backFluentMaterial"];
  7682. }
  7683. // Front
  7684. if (!this._host._sharedMaterials["frontFluentMaterial"]) {
  7685. this._createFrontMaterial(mesh);
  7686. this._host._sharedMaterials["frontFluentMaterial"] = this._frontMaterial;
  7687. }
  7688. else {
  7689. this._frontMaterial = this._host._sharedMaterials["frontFluentMaterial"];
  7690. }
  7691. }
  7692. else {
  7693. this._createBackMaterial(mesh);
  7694. this._createFrontMaterial(mesh);
  7695. }
  7696. this._createPlateMaterial(mesh);
  7697. this._backPlate.material = this._backMaterial;
  7698. this._frontPlate.material = this._frontMaterial;
  7699. this._textPlate.material = this._plateMaterial;
  7700. this._rebuildContent();
  7701. };
  7702. /**
  7703. * Releases all associated resources
  7704. */
  7705. HolographicButton.prototype.dispose = function () {
  7706. _super.prototype.dispose.call(this); // will dispose main mesh ie. back plate
  7707. if (!this.shareMaterials) {
  7708. this._backMaterial.dispose();
  7709. this._frontMaterial.dispose();
  7710. this._plateMaterial.dispose();
  7711. if (this._pickedPointObserver) {
  7712. this._host.onPickedPointChangedObservable.remove(this._pickedPointObserver);
  7713. this._pickedPointObserver = null;
  7714. }
  7715. }
  7716. };
  7717. return HolographicButton;
  7718. }(GUI.Button3D));
  7719. GUI.HolographicButton = HolographicButton;
  7720. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7721. })(BABYLON || (BABYLON = {}));
  7722. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  7723. var BABYLON;
  7724. (function (BABYLON) {
  7725. var GUI;
  7726. (function (GUI) {
  7727. /**
  7728. * Class used to create a stack panel in 3D on XY plane
  7729. */
  7730. var StackPanel3D = /** @class */ (function (_super) {
  7731. __extends(StackPanel3D, _super);
  7732. /**
  7733. * Creates new StackPanel
  7734. * @param isVertical
  7735. */
  7736. function StackPanel3D(isVertical) {
  7737. if (isVertical === void 0) { isVertical = false; }
  7738. var _this = _super.call(this) || this;
  7739. _this._isVertical = false;
  7740. /**
  7741. * Gets or sets the distance between elements
  7742. */
  7743. _this.margin = 0.1;
  7744. _this._isVertical = isVertical;
  7745. return _this;
  7746. }
  7747. Object.defineProperty(StackPanel3D.prototype, "isVertical", {
  7748. /**
  7749. * Gets or sets a boolean indicating if the stack panel is vertical or horizontal (horizontal by default)
  7750. */
  7751. get: function () {
  7752. return this._isVertical;
  7753. },
  7754. set: function (value) {
  7755. var _this = this;
  7756. if (this._isVertical === value) {
  7757. return;
  7758. }
  7759. this._isVertical = value;
  7760. BABYLON.Tools.SetImmediate(function () {
  7761. _this._arrangeChildren();
  7762. });
  7763. },
  7764. enumerable: true,
  7765. configurable: true
  7766. });
  7767. StackPanel3D.prototype._arrangeChildren = function () {
  7768. var width = 0;
  7769. var height = 0;
  7770. var controlCount = 0;
  7771. var extendSizes = [];
  7772. var currentInverseWorld = BABYLON.Matrix.Invert(this.node.computeWorldMatrix(true));
  7773. // Measure
  7774. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  7775. var child = _a[_i];
  7776. if (!child.mesh) {
  7777. continue;
  7778. }
  7779. controlCount++;
  7780. child.mesh.computeWorldMatrix(true);
  7781. child.mesh.getWorldMatrix().multiplyToRef(currentInverseWorld, BABYLON.Tmp.Matrix[0]);
  7782. var boundingBox = child.mesh.getBoundingInfo().boundingBox;
  7783. var extendSize = BABYLON.Vector3.TransformNormal(boundingBox.extendSize, BABYLON.Tmp.Matrix[0]);
  7784. extendSizes.push(extendSize);
  7785. if (this._isVertical) {
  7786. height += extendSize.y;
  7787. }
  7788. else {
  7789. width += extendSize.x;
  7790. }
  7791. }
  7792. if (this._isVertical) {
  7793. height += (controlCount - 1) * this.margin / 2;
  7794. }
  7795. else {
  7796. width += (controlCount - 1) * this.margin / 2;
  7797. }
  7798. // Arrange
  7799. var offset;
  7800. if (this._isVertical) {
  7801. offset = -height;
  7802. }
  7803. else {
  7804. offset = -width;
  7805. }
  7806. var index = 0;
  7807. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  7808. var child = _c[_b];
  7809. if (!child.mesh) {
  7810. continue;
  7811. }
  7812. controlCount--;
  7813. var extendSize = extendSizes[index++];
  7814. if (this._isVertical) {
  7815. child.position.y = offset + extendSize.y;
  7816. child.position.x = 0;
  7817. offset += extendSize.y * 2;
  7818. }
  7819. else {
  7820. child.position.x = offset + extendSize.x;
  7821. child.position.y = 0;
  7822. offset += extendSize.x * 2;
  7823. }
  7824. offset += (controlCount > 0 ? this.margin : 0);
  7825. }
  7826. };
  7827. return StackPanel3D;
  7828. }(GUI.Container3D));
  7829. GUI.StackPanel3D = StackPanel3D;
  7830. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7831. })(BABYLON || (BABYLON = {}));
  7832. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  7833. var BABYLON;
  7834. (function (BABYLON) {
  7835. var GUI;
  7836. (function (GUI) {
  7837. /**
  7838. * Class used to create a conainter panel deployed on the surface of a sphere
  7839. */
  7840. var SpherePanel = /** @class */ (function (_super) {
  7841. __extends(SpherePanel, _super);
  7842. /**
  7843. * Creates new SpherePanel
  7844. */
  7845. function SpherePanel() {
  7846. var _this = _super.call(this) || this;
  7847. _this._radius = 5.0;
  7848. _this._columns = 10;
  7849. return _this;
  7850. }
  7851. Object.defineProperty(SpherePanel.prototype, "radius", {
  7852. /**
  7853. * Gets or sets a the radius of the sphere where to project controls (5 by default)
  7854. */
  7855. get: function () {
  7856. return this._radius;
  7857. },
  7858. set: function (value) {
  7859. var _this = this;
  7860. if (this._radius === value) {
  7861. return;
  7862. }
  7863. this._radius = value;
  7864. BABYLON.Tools.SetImmediate(function () {
  7865. _this._arrangeChildren();
  7866. });
  7867. },
  7868. enumerable: true,
  7869. configurable: true
  7870. });
  7871. Object.defineProperty(SpherePanel.prototype, "columns", {
  7872. /**
  7873. * Gets or sets a the number of columns requested (10 by default).
  7874. * The panel will automatically compute the number of rows based on number of child controls
  7875. */
  7876. get: function () {
  7877. return this._columns;
  7878. },
  7879. set: function (value) {
  7880. var _this = this;
  7881. if (this._columns === value) {
  7882. return;
  7883. }
  7884. this._columns = value;
  7885. BABYLON.Tools.SetImmediate(function () {
  7886. _this._arrangeChildren();
  7887. });
  7888. },
  7889. enumerable: true,
  7890. configurable: true
  7891. });
  7892. SpherePanel.prototype._arrangeChildren = function () {
  7893. var cellWidth = 0;
  7894. var cellHeight = 0;
  7895. var rows = 0;
  7896. var controlCount = 0;
  7897. var currentInverseWorld = BABYLON.Matrix.Invert(this.node.computeWorldMatrix(true));
  7898. // Measure
  7899. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  7900. var child = _a[_i];
  7901. if (!child.mesh) {
  7902. continue;
  7903. }
  7904. controlCount++;
  7905. child.mesh.computeWorldMatrix(true);
  7906. child.mesh.getWorldMatrix().multiplyToRef(currentInverseWorld, BABYLON.Tmp.Matrix[0]);
  7907. var boundingBox = child.mesh.getBoundingInfo().boundingBox;
  7908. var extendSize = BABYLON.Vector3.TransformNormal(boundingBox.extendSize, BABYLON.Tmp.Matrix[0]);
  7909. cellWidth = Math.max(cellWidth, extendSize.x * 2);
  7910. cellHeight = Math.max(cellHeight, extendSize.y * 2);
  7911. }
  7912. // Arrange
  7913. rows = Math.ceil(controlCount / this._columns);
  7914. var startOffsetX = (this._columns * 0.5) * cellWidth;
  7915. var startOffsetY = (rows * 0.5) * cellHeight;
  7916. var nodeGrid = [];
  7917. var cellCounter = 0;
  7918. for (var c = 0; c < this._columns; c++) {
  7919. for (var r = 0; r < rows; r++) {
  7920. nodeGrid.push(new BABYLON.Vector3((c * cellWidth) - startOffsetX + cellWidth / 2, -(r * cellHeight) + startOffsetY - cellHeight / 2, 0));
  7921. cellCounter++;
  7922. if (cellCounter > controlCount) {
  7923. break;
  7924. }
  7925. }
  7926. }
  7927. cellCounter = 0;
  7928. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  7929. var child = _c[_b];
  7930. if (!child.mesh) {
  7931. continue;
  7932. }
  7933. var newPos = this._sphericalMapping(nodeGrid[cellCounter]);
  7934. child.position = newPos;
  7935. cellCounter++;
  7936. }
  7937. };
  7938. SpherePanel.prototype._sphericalMapping = function (source) {
  7939. var newPos = new BABYLON.Vector3(0, 0, this._radius);
  7940. var xAngle = (source.x / this._radius);
  7941. var yAngle = -(source.y / this._radius);
  7942. BABYLON.Matrix.RotationYawPitchRollToRef(yAngle, xAngle, 0, BABYLON.Tmp.Matrix[0]);
  7943. return GUI.Vector3WithInfo.TransformCoordinates(newPos, BABYLON.Tmp.Matrix[0]);
  7944. };
  7945. return SpherePanel;
  7946. }(GUI.Container3D));
  7947. GUI.SpherePanel = SpherePanel;
  7948. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7949. })(BABYLON || (BABYLON = {}));
  7950. return BABYLON.GUI;
  7951. });