babylon.gui.js 284 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487
  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;\nuniform mat4 emissiveMatrix;\nvarying vec2 vEmissiveUV;\nvoid main(void) {\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\ngl_Position=viewProjection*world*vec4(position,1.0);\n}\n";
  21. BABYLON.Effect.ShadersStore['fluentPixelShader'] = "precision highp float;\nvarying vec2 vEmissiveUV;\nuniform sampler2D emissiveSampler;\nvoid main(void) {\nvec3 emissiveColor=texture2D(emissiveSampler,vEmissiveUV).rgb;\ngl_FragColor=vec4(emissiveColor,1.0);\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. /** @hidden */
  40. this._fontSize = new GUI.ValueAndUnit(18, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  41. /**
  42. * Observable raised when the style values are changed
  43. */
  44. this.onChangedObservable = new BABYLON.Observable();
  45. this._host = host;
  46. }
  47. Object.defineProperty(Style.prototype, "fontSize", {
  48. /**
  49. * Gets or sets the font size
  50. */
  51. get: function () {
  52. return this._fontSize.toString(this._host);
  53. },
  54. set: function (value) {
  55. if (this._fontSize.toString(this._host) === value) {
  56. return;
  57. }
  58. if (this._fontSize.fromString(value)) {
  59. this.onChangedObservable.notifyObservers(this);
  60. }
  61. },
  62. enumerable: true,
  63. configurable: true
  64. });
  65. Object.defineProperty(Style.prototype, "fontFamily", {
  66. /**
  67. * Gets or sets the font family
  68. */
  69. get: function () {
  70. return this._fontFamily;
  71. },
  72. set: function (value) {
  73. if (this._fontFamily === value) {
  74. return;
  75. }
  76. this._fontFamily = value;
  77. this.onChangedObservable.notifyObservers(this);
  78. },
  79. enumerable: true,
  80. configurable: true
  81. });
  82. Object.defineProperty(Style.prototype, "fontStyle", {
  83. /**
  84. * Gets or sets the font style
  85. */
  86. get: function () {
  87. return this._fontStyle;
  88. },
  89. set: function (value) {
  90. if (this._fontStyle === value) {
  91. return;
  92. }
  93. this._fontStyle = value;
  94. this.onChangedObservable.notifyObservers(this);
  95. },
  96. enumerable: true,
  97. configurable: true
  98. });
  99. /** Dispose all associated resources */
  100. Style.prototype.dispose = function () {
  101. this.onChangedObservable.clear();
  102. };
  103. return Style;
  104. }());
  105. GUI.Style = Style;
  106. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  107. })(BABYLON || (BABYLON = {}));
  108. //# sourceMappingURL=style.js.map
  109. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  110. var BABYLON;
  111. (function (BABYLON) {
  112. var GUI;
  113. (function (GUI) {
  114. var ValueAndUnit = /** @class */ (function () {
  115. function ValueAndUnit(value, unit, negativeValueAllowed) {
  116. if (unit === void 0) { unit = ValueAndUnit.UNITMODE_PIXEL; }
  117. if (negativeValueAllowed === void 0) { negativeValueAllowed = true; }
  118. this.unit = unit;
  119. this.negativeValueAllowed = negativeValueAllowed;
  120. this._value = 1;
  121. this.ignoreAdaptiveScaling = false;
  122. this._value = value;
  123. }
  124. Object.defineProperty(ValueAndUnit.prototype, "isPercentage", {
  125. get: function () {
  126. return this.unit === ValueAndUnit.UNITMODE_PERCENTAGE;
  127. },
  128. enumerable: true,
  129. configurable: true
  130. });
  131. Object.defineProperty(ValueAndUnit.prototype, "isPixel", {
  132. get: function () {
  133. return this.unit === ValueAndUnit.UNITMODE_PIXEL;
  134. },
  135. enumerable: true,
  136. configurable: true
  137. });
  138. Object.defineProperty(ValueAndUnit.prototype, "internalValue", {
  139. get: function () {
  140. return this._value;
  141. },
  142. enumerable: true,
  143. configurable: true
  144. });
  145. ValueAndUnit.prototype.getValueInPixel = function (host, refValue) {
  146. if (this.isPixel) {
  147. return this.getValue(host);
  148. }
  149. return this.getValue(host) * refValue;
  150. };
  151. ValueAndUnit.prototype.getValue = function (host) {
  152. if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
  153. var width = 0;
  154. var height = 0;
  155. if (host.idealWidth) {
  156. width = (this._value * host.getSize().width) / host.idealWidth;
  157. }
  158. if (host.idealHeight) {
  159. height = (this._value * host.getSize().height) / host.idealHeight;
  160. }
  161. if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) {
  162. return window.innerWidth < window.innerHeight ? width : height;
  163. }
  164. if (host.idealWidth) { // horizontal
  165. return width;
  166. }
  167. if (host.idealHeight) { // vertical
  168. return height;
  169. }
  170. }
  171. return this._value;
  172. };
  173. ValueAndUnit.prototype.toString = function (host) {
  174. switch (this.unit) {
  175. case ValueAndUnit.UNITMODE_PERCENTAGE:
  176. return (this.getValue(host) * 100) + "%";
  177. case ValueAndUnit.UNITMODE_PIXEL:
  178. return this.getValue(host) + "px";
  179. }
  180. return this.unit.toString();
  181. };
  182. ValueAndUnit.prototype.fromString = function (source) {
  183. var match = ValueAndUnit._Regex.exec(source.toString());
  184. if (!match || match.length === 0) {
  185. return false;
  186. }
  187. var sourceValue = parseFloat(match[1]);
  188. var sourceUnit = this.unit;
  189. if (!this.negativeValueAllowed) {
  190. if (sourceValue < 0) {
  191. sourceValue = 0;
  192. }
  193. }
  194. if (match.length === 4) {
  195. switch (match[3]) {
  196. case "px":
  197. sourceUnit = ValueAndUnit.UNITMODE_PIXEL;
  198. break;
  199. case "%":
  200. sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;
  201. sourceValue /= 100.0;
  202. break;
  203. }
  204. }
  205. if (sourceValue === this._value && sourceUnit === this.unit) {
  206. return false;
  207. }
  208. this._value = sourceValue;
  209. this.unit = sourceUnit;
  210. return true;
  211. };
  212. Object.defineProperty(ValueAndUnit, "UNITMODE_PERCENTAGE", {
  213. get: function () {
  214. return ValueAndUnit._UNITMODE_PERCENTAGE;
  215. },
  216. enumerable: true,
  217. configurable: true
  218. });
  219. Object.defineProperty(ValueAndUnit, "UNITMODE_PIXEL", {
  220. get: function () {
  221. return ValueAndUnit._UNITMODE_PIXEL;
  222. },
  223. enumerable: true,
  224. configurable: true
  225. });
  226. // Static
  227. ValueAndUnit._Regex = /(^-?\d*(\.\d+)?)(%|px)?/;
  228. ValueAndUnit._UNITMODE_PERCENTAGE = 0;
  229. ValueAndUnit._UNITMODE_PIXEL = 1;
  230. return ValueAndUnit;
  231. }());
  232. GUI.ValueAndUnit = ValueAndUnit;
  233. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  234. })(BABYLON || (BABYLON = {}));
  235. //# sourceMappingURL=valueAndUnit.js.map
  236. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  237. var BABYLON;
  238. (function (BABYLON) {
  239. var GUI;
  240. (function (GUI) {
  241. var AdvancedDynamicTexture = /** @class */ (function (_super) {
  242. __extends(AdvancedDynamicTexture, _super);
  243. function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode) {
  244. if (width === void 0) { width = 0; }
  245. if (height === void 0) { height = 0; }
  246. if (generateMipMaps === void 0) { generateMipMaps = false; }
  247. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE; }
  248. var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, BABYLON.Engine.TEXTUREFORMAT_RGBA) || this;
  249. _this._isDirty = false;
  250. _this._rootContainer = new GUI.Container("root");
  251. _this._lastControlOver = {};
  252. _this._lastControlDown = {};
  253. _this._capturingControl = {};
  254. _this._linkedControls = new Array();
  255. _this._isFullscreen = false;
  256. _this._fullscreenViewport = new BABYLON.Viewport(0, 0, 1, 1);
  257. _this._idealWidth = 0;
  258. _this._idealHeight = 0;
  259. _this._useSmallestIdeal = false;
  260. _this._renderAtIdealSize = false;
  261. _this._blockNextFocusCheck = false;
  262. _this._renderScale = 1;
  263. /**
  264. * Gets or sets a boolean defining if alpha is stored as premultiplied
  265. */
  266. _this.premulAlpha = false;
  267. scene = _this.getScene();
  268. if (!scene || !_this._texture) {
  269. return _this;
  270. }
  271. _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
  272. _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
  273. if (!_this._focusedControl) {
  274. return;
  275. }
  276. if (info.type === BABYLON.KeyboardEventTypes.KEYDOWN) {
  277. _this._focusedControl.processKeyboard(info.event);
  278. }
  279. info.skipOnPointerObservable = true;
  280. });
  281. _this._rootContainer._link(null, _this);
  282. _this.hasAlpha = true;
  283. if (!width || !height) {
  284. _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
  285. _this._onResize();
  286. }
  287. _this._texture.isReady = true;
  288. return _this;
  289. }
  290. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
  291. get: function () {
  292. return this._renderScale;
  293. },
  294. set: function (value) {
  295. if (value === this._renderScale) {
  296. return;
  297. }
  298. this._renderScale = value;
  299. this._onResize();
  300. },
  301. enumerable: true,
  302. configurable: true
  303. });
  304. Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
  305. get: function () {
  306. return this._background;
  307. },
  308. set: function (value) {
  309. if (this._background === value) {
  310. return;
  311. }
  312. this._background = value;
  313. this.markAsDirty();
  314. },
  315. enumerable: true,
  316. configurable: true
  317. });
  318. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
  319. get: function () {
  320. return this._idealWidth;
  321. },
  322. set: function (value) {
  323. if (this._idealWidth === value) {
  324. return;
  325. }
  326. this._idealWidth = value;
  327. this.markAsDirty();
  328. this._rootContainer._markAllAsDirty();
  329. },
  330. enumerable: true,
  331. configurable: true
  332. });
  333. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
  334. get: function () {
  335. return this._idealHeight;
  336. },
  337. set: function (value) {
  338. if (this._idealHeight === value) {
  339. return;
  340. }
  341. this._idealHeight = value;
  342. this.markAsDirty();
  343. this._rootContainer._markAllAsDirty();
  344. },
  345. enumerable: true,
  346. configurable: true
  347. });
  348. Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
  349. get: function () {
  350. return this._useSmallestIdeal;
  351. },
  352. set: function (value) {
  353. if (this._useSmallestIdeal === value) {
  354. return;
  355. }
  356. this._useSmallestIdeal = value;
  357. this.markAsDirty();
  358. this._rootContainer._markAllAsDirty();
  359. },
  360. enumerable: true,
  361. configurable: true
  362. });
  363. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
  364. get: function () {
  365. return this._renderAtIdealSize;
  366. },
  367. set: function (value) {
  368. if (this._renderAtIdealSize === value) {
  369. return;
  370. }
  371. this._renderAtIdealSize = value;
  372. this._onResize();
  373. },
  374. enumerable: true,
  375. configurable: true
  376. });
  377. Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
  378. get: function () {
  379. return this._layerToDispose;
  380. },
  381. enumerable: true,
  382. configurable: true
  383. });
  384. Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
  385. get: function () {
  386. return this._rootContainer;
  387. },
  388. enumerable: true,
  389. configurable: true
  390. });
  391. Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
  392. get: function () {
  393. return this._focusedControl;
  394. },
  395. set: function (control) {
  396. if (this._focusedControl == control) {
  397. return;
  398. }
  399. if (this._focusedControl) {
  400. this._focusedControl.onBlur();
  401. }
  402. if (control) {
  403. control.onFocus();
  404. }
  405. this._focusedControl = control;
  406. },
  407. enumerable: true,
  408. configurable: true
  409. });
  410. Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
  411. get: function () {
  412. if (!this.layer) {
  413. return true;
  414. }
  415. return (!this.layer.isBackground);
  416. },
  417. set: function (value) {
  418. if (!this.layer) {
  419. return;
  420. }
  421. if (this.layer.isBackground === !value) {
  422. return;
  423. }
  424. this.layer.isBackground = !value;
  425. },
  426. enumerable: true,
  427. configurable: true
  428. });
  429. AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
  430. if (!container) {
  431. container = this._rootContainer;
  432. }
  433. for (var _i = 0, _a = container.children; _i < _a.length; _i++) {
  434. var child = _a[_i];
  435. if (child.children) {
  436. this.executeOnAllControls(func, child);
  437. continue;
  438. }
  439. func(child);
  440. }
  441. };
  442. AdvancedDynamicTexture.prototype.markAsDirty = function () {
  443. this._isDirty = true;
  444. this.executeOnAllControls(function (control) {
  445. if (control._isFontSizeInPercentage) {
  446. control._resetFontCache();
  447. }
  448. });
  449. };
  450. /**
  451. * Helper function used to create a new style
  452. */
  453. AdvancedDynamicTexture.prototype.createStyle = function () {
  454. return new GUI.Style(this);
  455. };
  456. AdvancedDynamicTexture.prototype.addControl = function (control) {
  457. this._rootContainer.addControl(control);
  458. return this;
  459. };
  460. AdvancedDynamicTexture.prototype.removeControl = function (control) {
  461. this._rootContainer.removeControl(control);
  462. return this;
  463. };
  464. AdvancedDynamicTexture.prototype.dispose = function () {
  465. var scene = this.getScene();
  466. if (!scene) {
  467. return;
  468. }
  469. scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
  470. if (this._resizeObserver) {
  471. scene.getEngine().onResizeObservable.remove(this._resizeObserver);
  472. }
  473. if (this._pointerMoveObserver) {
  474. scene.onPrePointerObservable.remove(this._pointerMoveObserver);
  475. }
  476. if (this._pointerObserver) {
  477. scene.onPointerObservable.remove(this._pointerObserver);
  478. }
  479. if (this._preKeyboardObserver) {
  480. scene.onPreKeyboardObservable.remove(this._preKeyboardObserver);
  481. }
  482. if (this._canvasPointerOutObserver) {
  483. scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
  484. }
  485. if (this._layerToDispose) {
  486. this._layerToDispose.texture = null;
  487. this._layerToDispose.dispose();
  488. this._layerToDispose = null;
  489. }
  490. this._rootContainer.dispose();
  491. _super.prototype.dispose.call(this);
  492. };
  493. AdvancedDynamicTexture.prototype._onResize = function () {
  494. var scene = this.getScene();
  495. if (!scene) {
  496. return;
  497. }
  498. // Check size
  499. var engine = scene.getEngine();
  500. var textureSize = this.getSize();
  501. var renderWidth = engine.getRenderWidth() * this._renderScale;
  502. var renderHeight = engine.getRenderHeight() * this._renderScale;
  503. if (this._renderAtIdealSize) {
  504. if (this._idealWidth) {
  505. renderHeight = (renderHeight * this._idealWidth) / renderWidth;
  506. renderWidth = this._idealWidth;
  507. }
  508. else if (this._idealHeight) {
  509. renderWidth = (renderWidth * this._idealHeight) / renderHeight;
  510. renderHeight = this._idealHeight;
  511. }
  512. }
  513. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  514. this.scaleTo(renderWidth, renderHeight);
  515. this.markAsDirty();
  516. if (this._idealWidth || this._idealHeight) {
  517. this._rootContainer._markAllAsDirty();
  518. }
  519. }
  520. };
  521. AdvancedDynamicTexture.prototype._getGlobalViewport = function (scene) {
  522. var engine = scene.getEngine();
  523. return this._fullscreenViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  524. };
  525. AdvancedDynamicTexture.prototype.getProjectedPosition = function (position, worldMatrix) {
  526. var scene = this.getScene();
  527. if (!scene) {
  528. return BABYLON.Vector2.Zero();
  529. }
  530. var globalViewport = this._getGlobalViewport(scene);
  531. var projectedPosition = BABYLON.Vector3.Project(position, worldMatrix, scene.getTransformMatrix(), globalViewport);
  532. projectedPosition.scaleInPlace(this.renderScale);
  533. return new BABYLON.Vector2(projectedPosition.x, projectedPosition.y);
  534. };
  535. AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
  536. if (this._layerToDispose) {
  537. if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
  538. return;
  539. }
  540. }
  541. if (this._isFullscreen && this._linkedControls.length) {
  542. var scene = this.getScene();
  543. if (!scene) {
  544. return;
  545. }
  546. var globalViewport = this._getGlobalViewport(scene);
  547. for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
  548. var control = _a[_i];
  549. if (!control.isVisible) {
  550. continue;
  551. }
  552. var mesh = control._linkedMesh;
  553. if (!mesh || mesh.isDisposed()) {
  554. BABYLON.Tools.SetImmediate(function () {
  555. control.linkWithMesh(null);
  556. });
  557. continue;
  558. }
  559. var position = mesh.getBoundingInfo().boundingSphere.center;
  560. var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
  561. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  562. control.notRenderable = true;
  563. continue;
  564. }
  565. control.notRenderable = false;
  566. // Account for RenderScale.
  567. projectedPosition.scaleInPlace(this.renderScale);
  568. control._moveToProjectedPosition(projectedPosition);
  569. }
  570. }
  571. if (!this._isDirty && !this._rootContainer.isDirty) {
  572. return;
  573. }
  574. this._isDirty = false;
  575. this._render();
  576. this.update(true, this.premulAlpha);
  577. };
  578. AdvancedDynamicTexture.prototype._render = function () {
  579. var textureSize = this.getSize();
  580. var renderWidth = textureSize.width;
  581. var renderHeight = textureSize.height;
  582. // Clear
  583. var context = this.getContext();
  584. context.clearRect(0, 0, renderWidth, renderHeight);
  585. if (this._background) {
  586. context.save();
  587. context.fillStyle = this._background;
  588. context.fillRect(0, 0, renderWidth, renderHeight);
  589. context.restore();
  590. }
  591. // Render
  592. context.font = "18px Arial";
  593. context.strokeStyle = "white";
  594. var measure = new GUI.Measure(0, 0, renderWidth, renderHeight);
  595. this._rootContainer._draw(measure, context);
  596. };
  597. AdvancedDynamicTexture.prototype._doPicking = function (x, y, type, pointerId, buttonIndex) {
  598. var scene = this.getScene();
  599. if (!scene) {
  600. return;
  601. }
  602. var engine = scene.getEngine();
  603. var textureSize = this.getSize();
  604. if (this._isFullscreen) {
  605. x = x * (textureSize.width / engine.getRenderWidth());
  606. y = y * (textureSize.height / engine.getRenderHeight());
  607. }
  608. if (this._capturingControl[pointerId]) {
  609. this._capturingControl[pointerId]._processObservables(type, x, y, pointerId, buttonIndex);
  610. return;
  611. }
  612. if (!this._rootContainer._processPicking(x, y, type, pointerId, buttonIndex)) {
  613. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  614. if (this._lastControlOver[pointerId]) {
  615. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  616. }
  617. delete this._lastControlOver[pointerId];
  618. }
  619. }
  620. this._manageFocus();
  621. };
  622. AdvancedDynamicTexture.prototype._cleanControlAfterRemovalFromList = function (list, control) {
  623. for (var pointerId in list) {
  624. if (!list.hasOwnProperty(pointerId)) {
  625. continue;
  626. }
  627. var lastControlOver = list[pointerId];
  628. if (lastControlOver === control) {
  629. delete list[pointerId];
  630. }
  631. }
  632. };
  633. AdvancedDynamicTexture.prototype._cleanControlAfterRemoval = function (control) {
  634. this._cleanControlAfterRemovalFromList(this._lastControlDown, control);
  635. this._cleanControlAfterRemovalFromList(this._lastControlOver, control);
  636. };
  637. AdvancedDynamicTexture.prototype.attach = function () {
  638. var _this = this;
  639. var scene = this.getScene();
  640. if (!scene) {
  641. return;
  642. }
  643. this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
  644. if (scene.isPointerCaptured((pi.event).pointerId)) {
  645. return;
  646. }
  647. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  648. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  649. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  650. return;
  651. }
  652. if (!scene) {
  653. return;
  654. }
  655. var camera = scene.cameraToUseForPointers || scene.activeCamera;
  656. if (!camera) {
  657. return;
  658. }
  659. var engine = scene.getEngine();
  660. var viewport = camera.viewport;
  661. var x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
  662. var y = (scene.pointerY / engine.getHardwareScalingLevel() - viewport.y * engine.getRenderHeight()) / viewport.height;
  663. _this._shouldBlockPointer = false;
  664. _this._doPicking(x, y, pi.type, pi.event.pointerId || 0, pi.event.button);
  665. pi.skipOnPointerObservable = _this._shouldBlockPointer;
  666. });
  667. this._attachToOnPointerOut(scene);
  668. };
  669. AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
  670. var _this = this;
  671. if (supportPointerMove === void 0) { supportPointerMove = true; }
  672. var scene = this.getScene();
  673. if (!scene) {
  674. return;
  675. }
  676. this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
  677. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  678. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  679. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  680. return;
  681. }
  682. var pointerId = pi.event.pointerId || 0;
  683. if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
  684. var uv = pi.pickInfo.getTextureCoordinates();
  685. if (uv) {
  686. var size = _this.getSize();
  687. _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pointerId, pi.event.button);
  688. }
  689. }
  690. else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
  691. if (_this._lastControlDown[pointerId]) {
  692. _this._lastControlDown[pointerId].forcePointerUp(pointerId);
  693. }
  694. delete _this._lastControlDown[pointerId];
  695. _this.focusedControl = null;
  696. }
  697. else if (pi.type === BABYLON.PointerEventTypes.POINTERMOVE) {
  698. if (_this._lastControlOver[pointerId]) {
  699. _this._lastControlOver[pointerId]._onPointerOut(_this._lastControlOver[pointerId]);
  700. }
  701. delete _this._lastControlOver[pointerId];
  702. }
  703. });
  704. mesh.enablePointerMoveEvents = supportPointerMove;
  705. this._attachToOnPointerOut(scene);
  706. };
  707. AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
  708. this.focusedControl = control;
  709. this._lastPickedControl = control;
  710. this._blockNextFocusCheck = true;
  711. };
  712. AdvancedDynamicTexture.prototype._manageFocus = function () {
  713. if (this._blockNextFocusCheck) {
  714. this._blockNextFocusCheck = false;
  715. this._lastPickedControl = this._focusedControl;
  716. return;
  717. }
  718. // Focus management
  719. if (this._focusedControl) {
  720. if (this._focusedControl !== this._lastPickedControl) {
  721. if (this._lastPickedControl.isFocusInvisible) {
  722. return;
  723. }
  724. this.focusedControl = null;
  725. }
  726. }
  727. };
  728. AdvancedDynamicTexture.prototype._attachToOnPointerOut = function (scene) {
  729. var _this = this;
  730. this._canvasPointerOutObserver = scene.getEngine().onCanvasPointerOutObservable.add(function (pointerEvent) {
  731. if (_this._lastControlOver[pointerEvent.pointerId]) {
  732. _this._lastControlOver[pointerEvent.pointerId]._onPointerOut(_this._lastControlOver[pointerEvent.pointerId]);
  733. }
  734. delete _this._lastControlOver[pointerEvent.pointerId];
  735. if (_this._lastControlDown[pointerEvent.pointerId]) {
  736. _this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  737. }
  738. delete _this._lastControlDown[pointerEvent.pointerId];
  739. });
  740. };
  741. // Statics
  742. AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height, supportPointerMove) {
  743. if (width === void 0) { width = 1024; }
  744. if (height === void 0) { height = 1024; }
  745. if (supportPointerMove === void 0) { supportPointerMove = true; }
  746. var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  747. var material = new BABYLON.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
  748. material.backFaceCulling = false;
  749. material.diffuseColor = BABYLON.Color3.Black();
  750. material.specularColor = BABYLON.Color3.Black();
  751. material.emissiveTexture = result;
  752. material.opacityTexture = result;
  753. mesh.material = material;
  754. result.attachToMesh(mesh, supportPointerMove);
  755. return result;
  756. };
  757. /**
  758. * FullScreenUI is created in a layer. This allows it to be treated like any other layer.
  759. * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
  760. * When the GUI is not Created as FullscreenUI it does not respect the layerMask.
  761. * layerMask is set through advancedTexture.layer.layerMask
  762. * @param name name for the Texture
  763. * @param foreground render in foreground (default is true)
  764. * @param scene scene to be rendered in
  765. * @param sampling method for scaling to fit screen
  766. * @returns AdvancedDynamicTexture
  767. */
  768. AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling) {
  769. if (foreground === void 0) { foreground = true; }
  770. if (scene === void 0) { scene = null; }
  771. if (sampling === void 0) { sampling = BABYLON.Texture.BILINEAR_SAMPLINGMODE; }
  772. var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, sampling);
  773. // Display
  774. var layer = new BABYLON.Layer(name + "_layer", null, scene, !foreground);
  775. layer.texture = result;
  776. result._layerToDispose = layer;
  777. result._isFullscreen = true;
  778. // Attach
  779. result.attach();
  780. return result;
  781. };
  782. return AdvancedDynamicTexture;
  783. }(BABYLON.DynamicTexture));
  784. GUI.AdvancedDynamicTexture = AdvancedDynamicTexture;
  785. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  786. })(BABYLON || (BABYLON = {}));
  787. //# sourceMappingURL=advancedDynamicTexture.js.map
  788. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  789. var BABYLON;
  790. (function (BABYLON) {
  791. var GUI;
  792. (function (GUI) {
  793. var Measure = /** @class */ (function () {
  794. function Measure(left, top, width, height) {
  795. this.left = left;
  796. this.top = top;
  797. this.width = width;
  798. this.height = height;
  799. }
  800. Measure.prototype.copyFrom = function (other) {
  801. this.left = other.left;
  802. this.top = other.top;
  803. this.width = other.width;
  804. this.height = other.height;
  805. };
  806. Measure.prototype.isEqualsTo = function (other) {
  807. if (this.left !== other.left) {
  808. return false;
  809. }
  810. if (this.top !== other.top) {
  811. return false;
  812. }
  813. if (this.width !== other.width) {
  814. return false;
  815. }
  816. if (this.height !== other.height) {
  817. return false;
  818. }
  819. return true;
  820. };
  821. Measure.Empty = function () {
  822. return new Measure(0, 0, 0, 0);
  823. };
  824. return Measure;
  825. }());
  826. GUI.Measure = Measure;
  827. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  828. })(BABYLON || (BABYLON = {}));
  829. //# sourceMappingURL=measure.js.map
  830. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  831. var BABYLON;
  832. (function (BABYLON) {
  833. var GUI;
  834. (function (GUI) {
  835. var Vector2WithInfo = /** @class */ (function (_super) {
  836. __extends(Vector2WithInfo, _super);
  837. function Vector2WithInfo(source, buttonIndex) {
  838. if (buttonIndex === void 0) { buttonIndex = 0; }
  839. var _this = _super.call(this, source.x, source.y) || this;
  840. _this.buttonIndex = buttonIndex;
  841. return _this;
  842. }
  843. return Vector2WithInfo;
  844. }(BABYLON.Vector2));
  845. GUI.Vector2WithInfo = Vector2WithInfo;
  846. var Matrix2D = /** @class */ (function () {
  847. function Matrix2D(m00, m01, m10, m11, m20, m21) {
  848. this.m = new Float32Array(6);
  849. this.fromValues(m00, m01, m10, m11, m20, m21);
  850. }
  851. Matrix2D.prototype.fromValues = function (m00, m01, m10, m11, m20, m21) {
  852. this.m[0] = m00;
  853. this.m[1] = m01;
  854. this.m[2] = m10;
  855. this.m[3] = m11;
  856. this.m[4] = m20;
  857. this.m[5] = m21;
  858. return this;
  859. };
  860. Matrix2D.prototype.determinant = function () {
  861. return this.m[0] * this.m[3] - this.m[1] * this.m[2];
  862. };
  863. Matrix2D.prototype.invertToRef = function (result) {
  864. var l0 = this.m[0];
  865. var l1 = this.m[1];
  866. var l2 = this.m[2];
  867. var l3 = this.m[3];
  868. var l4 = this.m[4];
  869. var l5 = this.m[5];
  870. var det = this.determinant();
  871. if (det < (BABYLON.Epsilon * BABYLON.Epsilon)) {
  872. result.m[0] = 0;
  873. result.m[1] = 0;
  874. result.m[2] = 0;
  875. result.m[3] = 0;
  876. result.m[4] = 0;
  877. result.m[5] = 0;
  878. return this;
  879. }
  880. var detDiv = 1 / det;
  881. var det4 = l2 * l5 - l3 * l4;
  882. var det5 = l1 * l4 - l0 * l5;
  883. result.m[0] = l3 * detDiv;
  884. result.m[1] = -l1 * detDiv;
  885. result.m[2] = -l2 * detDiv;
  886. result.m[3] = l0 * detDiv;
  887. result.m[4] = det4 * detDiv;
  888. result.m[5] = det5 * detDiv;
  889. return this;
  890. };
  891. Matrix2D.prototype.multiplyToRef = function (other, result) {
  892. var l0 = this.m[0];
  893. var l1 = this.m[1];
  894. var l2 = this.m[2];
  895. var l3 = this.m[3];
  896. var l4 = this.m[4];
  897. var l5 = this.m[5];
  898. var r0 = other.m[0];
  899. var r1 = other.m[1];
  900. var r2 = other.m[2];
  901. var r3 = other.m[3];
  902. var r4 = other.m[4];
  903. var r5 = other.m[5];
  904. result.m[0] = l0 * r0 + l1 * r2;
  905. result.m[1] = l0 * r1 + l1 * r3;
  906. result.m[2] = l2 * r0 + l3 * r2;
  907. result.m[3] = l2 * r1 + l3 * r3;
  908. result.m[4] = l4 * r0 + l5 * r2 + r4;
  909. result.m[5] = l4 * r1 + l5 * r3 + r5;
  910. return this;
  911. };
  912. Matrix2D.prototype.transformCoordinates = function (x, y, result) {
  913. result.x = x * this.m[0] + y * this.m[2] + this.m[4];
  914. result.y = x * this.m[1] + y * this.m[3] + this.m[5];
  915. return this;
  916. };
  917. // Statics
  918. Matrix2D.Identity = function () {
  919. return new Matrix2D(1, 0, 0, 1, 0, 0);
  920. };
  921. Matrix2D.TranslationToRef = function (x, y, result) {
  922. result.fromValues(1, 0, 0, 1, x, y);
  923. };
  924. Matrix2D.ScalingToRef = function (x, y, result) {
  925. result.fromValues(x, 0, 0, y, 0, 0);
  926. };
  927. Matrix2D.RotationToRef = function (angle, result) {
  928. var s = Math.sin(angle);
  929. var c = Math.cos(angle);
  930. result.fromValues(c, s, -s, c, 0, 0);
  931. };
  932. Matrix2D.ComposeToRef = function (tx, ty, angle, scaleX, scaleY, parentMatrix, result) {
  933. Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
  934. Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);
  935. Matrix2D.RotationToRef(angle, Matrix2D._TempRotationMatrix);
  936. Matrix2D.TranslationToRef(-tx, -ty, Matrix2D._TempPostTranslationMatrix);
  937. Matrix2D._TempPreTranslationMatrix.multiplyToRef(Matrix2D._TempScalingMatrix, Matrix2D._TempCompose0);
  938. Matrix2D._TempCompose0.multiplyToRef(Matrix2D._TempRotationMatrix, Matrix2D._TempCompose1);
  939. if (parentMatrix) {
  940. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, Matrix2D._TempCompose2);
  941. Matrix2D._TempCompose2.multiplyToRef(parentMatrix, result);
  942. }
  943. else {
  944. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, result);
  945. }
  946. };
  947. Matrix2D._TempPreTranslationMatrix = Matrix2D.Identity();
  948. Matrix2D._TempPostTranslationMatrix = Matrix2D.Identity();
  949. Matrix2D._TempRotationMatrix = Matrix2D.Identity();
  950. Matrix2D._TempScalingMatrix = Matrix2D.Identity();
  951. Matrix2D._TempCompose0 = Matrix2D.Identity();
  952. Matrix2D._TempCompose1 = Matrix2D.Identity();
  953. Matrix2D._TempCompose2 = Matrix2D.Identity();
  954. return Matrix2D;
  955. }());
  956. GUI.Matrix2D = Matrix2D;
  957. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  958. })(BABYLON || (BABYLON = {}));
  959. //# sourceMappingURL=math2D.js.map
  960. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  961. var BABYLON;
  962. (function (BABYLON) {
  963. var GUI;
  964. (function (GUI) {
  965. var MultiLinePoint = /** @class */ (function () {
  966. function MultiLinePoint(multiLine) {
  967. this._multiLine = multiLine;
  968. this._x = new GUI.ValueAndUnit(0);
  969. this._y = new GUI.ValueAndUnit(0);
  970. this._point = new BABYLON.Vector2(0, 0);
  971. }
  972. Object.defineProperty(MultiLinePoint.prototype, "x", {
  973. get: function () {
  974. return this._x.toString(this._multiLine._host);
  975. },
  976. set: function (value) {
  977. if (this._x.toString(this._multiLine._host) === value) {
  978. return;
  979. }
  980. if (this._x.fromString(value)) {
  981. this._multiLine._markAsDirty();
  982. }
  983. },
  984. enumerable: true,
  985. configurable: true
  986. });
  987. Object.defineProperty(MultiLinePoint.prototype, "y", {
  988. get: function () {
  989. return this._y.toString(this._multiLine._host);
  990. },
  991. set: function (value) {
  992. if (this._y.toString(this._multiLine._host) === value) {
  993. return;
  994. }
  995. if (this._y.fromString(value)) {
  996. this._multiLine._markAsDirty();
  997. }
  998. },
  999. enumerable: true,
  1000. configurable: true
  1001. });
  1002. Object.defineProperty(MultiLinePoint.prototype, "control", {
  1003. get: function () {
  1004. return this._control;
  1005. },
  1006. set: function (value) {
  1007. if (this._control === value) {
  1008. return;
  1009. }
  1010. if (this._control && this._controlObserver) {
  1011. this._control.onDirtyObservable.remove(this._controlObserver);
  1012. this._controlObserver = null;
  1013. }
  1014. this._control = value;
  1015. if (this._control) {
  1016. this._controlObserver = this._control.onDirtyObservable.add(this._multiLine.onPointUpdate);
  1017. }
  1018. this._multiLine._markAsDirty();
  1019. },
  1020. enumerable: true,
  1021. configurable: true
  1022. });
  1023. Object.defineProperty(MultiLinePoint.prototype, "mesh", {
  1024. get: function () {
  1025. return this._mesh;
  1026. },
  1027. set: function (value) {
  1028. if (this._mesh === value) {
  1029. return;
  1030. }
  1031. if (this._mesh && this._meshObserver) {
  1032. this._mesh.getScene().onAfterCameraRenderObservable.remove(this._meshObserver);
  1033. }
  1034. this._mesh = value;
  1035. if (this._mesh) {
  1036. this._meshObserver = this._mesh.getScene().onAfterCameraRenderObservable.add(this._multiLine.onPointUpdate);
  1037. }
  1038. this._multiLine._markAsDirty();
  1039. },
  1040. enumerable: true,
  1041. configurable: true
  1042. });
  1043. MultiLinePoint.prototype.translate = function () {
  1044. this._point = this._translatePoint();
  1045. return this._point;
  1046. };
  1047. MultiLinePoint.prototype._translatePoint = function () {
  1048. if (this._mesh != null) {
  1049. return this._multiLine._host.getProjectedPosition(this._mesh.getBoundingInfo().boundingSphere.center, this._mesh.getWorldMatrix());
  1050. }
  1051. else if (this._control != null) {
  1052. return new BABYLON.Vector2(this._control.centerX, this._control.centerY);
  1053. }
  1054. else {
  1055. var host = this._multiLine._host;
  1056. var xValue = this._x.getValueInPixel(host, Number(host._canvas.width));
  1057. var yValue = this._y.getValueInPixel(host, Number(host._canvas.height));
  1058. return new BABYLON.Vector2(xValue, yValue);
  1059. }
  1060. };
  1061. MultiLinePoint.prototype.dispose = function () {
  1062. this.control = null;
  1063. this.mesh = null;
  1064. };
  1065. return MultiLinePoint;
  1066. }());
  1067. GUI.MultiLinePoint = MultiLinePoint;
  1068. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  1069. })(BABYLON || (BABYLON = {}));
  1070. //# sourceMappingURL=multiLinePoint.js.map
  1071. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1072. var BABYLON;
  1073. (function (BABYLON) {
  1074. var GUI;
  1075. (function (GUI) {
  1076. var Control = /** @class */ (function () {
  1077. // Functions
  1078. function Control(name) {
  1079. this.name = name;
  1080. this._alpha = 1;
  1081. this._alphaSet = false;
  1082. this._zIndex = 0;
  1083. this._currentMeasure = GUI.Measure.Empty();
  1084. this._fontFamily = "Arial";
  1085. this._fontStyle = "";
  1086. this._fontSize = new GUI.ValueAndUnit(18, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  1087. this._width = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  1088. this._height = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  1089. this._color = "";
  1090. this._style = null;
  1091. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  1092. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  1093. this._isDirty = true;
  1094. this._tempParentMeasure = GUI.Measure.Empty();
  1095. this._cachedParentMeasure = GUI.Measure.Empty();
  1096. this._paddingLeft = new GUI.ValueAndUnit(0);
  1097. this._paddingRight = new GUI.ValueAndUnit(0);
  1098. this._paddingTop = new GUI.ValueAndUnit(0);
  1099. this._paddingBottom = new GUI.ValueAndUnit(0);
  1100. this._left = new GUI.ValueAndUnit(0);
  1101. this._top = new GUI.ValueAndUnit(0);
  1102. this._scaleX = 1.0;
  1103. this._scaleY = 1.0;
  1104. this._rotation = 0;
  1105. this._transformCenterX = 0.5;
  1106. this._transformCenterY = 0.5;
  1107. this._transformMatrix = GUI.Matrix2D.Identity();
  1108. this._invertTransformMatrix = GUI.Matrix2D.Identity();
  1109. this._transformedPosition = BABYLON.Vector2.Zero();
  1110. this._onlyMeasureMode = false;
  1111. this._isMatrixDirty = true;
  1112. this._isVisible = true;
  1113. this._fontSet = false;
  1114. this._dummyVector2 = BABYLON.Vector2.Zero();
  1115. this._downCount = 0;
  1116. this._enterCount = 0;
  1117. this._doNotRender = false;
  1118. this._downPointerIds = {};
  1119. this.isHitTestVisible = true;
  1120. this.isPointerBlocker = false;
  1121. this.isFocusInvisible = false;
  1122. this.shadowOffsetX = 0;
  1123. this.shadowOffsetY = 0;
  1124. this.shadowBlur = 0;
  1125. this.shadowColor = '#000';
  1126. this._linkOffsetX = new GUI.ValueAndUnit(0);
  1127. this._linkOffsetY = new GUI.ValueAndUnit(0);
  1128. /**
  1129. * An event triggered when the pointer move over the control.
  1130. */
  1131. this.onPointerMoveObservable = new BABYLON.Observable();
  1132. /**
  1133. * An event triggered when the pointer move out of the control.
  1134. */
  1135. this.onPointerOutObservable = new BABYLON.Observable();
  1136. /**
  1137. * An event triggered when the pointer taps the control
  1138. */
  1139. this.onPointerDownObservable = new BABYLON.Observable();
  1140. /**
  1141. * An event triggered when pointer up
  1142. */
  1143. this.onPointerUpObservable = new BABYLON.Observable();
  1144. /**
  1145. * An event triggered when a control is clicked on
  1146. */
  1147. this.onPointerClickObservable = new BABYLON.Observable();
  1148. /**
  1149. * An event triggered when pointer enters the control
  1150. */
  1151. this.onPointerEnterObservable = new BABYLON.Observable();
  1152. /**
  1153. * An event triggered when the control is marked as dirty
  1154. */
  1155. this.onDirtyObservable = new BABYLON.Observable();
  1156. /**
  1157. * An event triggered after the control is drawn
  1158. */
  1159. this.onAfterDrawObservable = new BABYLON.Observable();
  1160. }
  1161. Object.defineProperty(Control.prototype, "typeName", {
  1162. // Properties
  1163. get: function () {
  1164. return this._getTypeName();
  1165. },
  1166. enumerable: true,
  1167. configurable: true
  1168. });
  1169. Object.defineProperty(Control.prototype, "fontOffset", {
  1170. /** Gets or set information about font offsets (used to render and align text) */
  1171. get: function () {
  1172. return this._fontOffset;
  1173. },
  1174. set: function (offset) {
  1175. this._fontOffset = offset;
  1176. },
  1177. enumerable: true,
  1178. configurable: true
  1179. });
  1180. Object.defineProperty(Control.prototype, "alpha", {
  1181. get: function () {
  1182. return this._alpha;
  1183. },
  1184. set: function (value) {
  1185. if (this._alpha === value) {
  1186. return;
  1187. }
  1188. this._alphaSet = true;
  1189. this._alpha = value;
  1190. this._markAsDirty();
  1191. },
  1192. enumerable: true,
  1193. configurable: true
  1194. });
  1195. Object.defineProperty(Control.prototype, "scaleX", {
  1196. get: function () {
  1197. return this._scaleX;
  1198. },
  1199. set: function (value) {
  1200. if (this._scaleX === value) {
  1201. return;
  1202. }
  1203. this._scaleX = value;
  1204. this._markAsDirty();
  1205. this._markMatrixAsDirty();
  1206. },
  1207. enumerable: true,
  1208. configurable: true
  1209. });
  1210. Object.defineProperty(Control.prototype, "scaleY", {
  1211. get: function () {
  1212. return this._scaleY;
  1213. },
  1214. set: function (value) {
  1215. if (this._scaleY === value) {
  1216. return;
  1217. }
  1218. this._scaleY = value;
  1219. this._markAsDirty();
  1220. this._markMatrixAsDirty();
  1221. },
  1222. enumerable: true,
  1223. configurable: true
  1224. });
  1225. Object.defineProperty(Control.prototype, "rotation", {
  1226. get: function () {
  1227. return this._rotation;
  1228. },
  1229. set: function (value) {
  1230. if (this._rotation === value) {
  1231. return;
  1232. }
  1233. this._rotation = value;
  1234. this._markAsDirty();
  1235. this._markMatrixAsDirty();
  1236. },
  1237. enumerable: true,
  1238. configurable: true
  1239. });
  1240. Object.defineProperty(Control.prototype, "transformCenterY", {
  1241. get: function () {
  1242. return this._transformCenterY;
  1243. },
  1244. set: function (value) {
  1245. if (this._transformCenterY === value) {
  1246. return;
  1247. }
  1248. this._transformCenterY = value;
  1249. this._markAsDirty();
  1250. this._markMatrixAsDirty();
  1251. },
  1252. enumerable: true,
  1253. configurable: true
  1254. });
  1255. Object.defineProperty(Control.prototype, "transformCenterX", {
  1256. get: function () {
  1257. return this._transformCenterX;
  1258. },
  1259. set: function (value) {
  1260. if (this._transformCenterX === value) {
  1261. return;
  1262. }
  1263. this._transformCenterX = value;
  1264. this._markAsDirty();
  1265. this._markMatrixAsDirty();
  1266. },
  1267. enumerable: true,
  1268. configurable: true
  1269. });
  1270. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  1271. get: function () {
  1272. return this._horizontalAlignment;
  1273. },
  1274. set: function (value) {
  1275. if (this._horizontalAlignment === value) {
  1276. return;
  1277. }
  1278. this._horizontalAlignment = value;
  1279. this._markAsDirty();
  1280. },
  1281. enumerable: true,
  1282. configurable: true
  1283. });
  1284. Object.defineProperty(Control.prototype, "verticalAlignment", {
  1285. get: function () {
  1286. return this._verticalAlignment;
  1287. },
  1288. set: function (value) {
  1289. if (this._verticalAlignment === value) {
  1290. return;
  1291. }
  1292. this._verticalAlignment = value;
  1293. this._markAsDirty();
  1294. },
  1295. enumerable: true,
  1296. configurable: true
  1297. });
  1298. Object.defineProperty(Control.prototype, "width", {
  1299. get: function () {
  1300. return this._width.toString(this._host);
  1301. },
  1302. set: function (value) {
  1303. if (this._width.toString(this._host) === value) {
  1304. return;
  1305. }
  1306. if (this._width.fromString(value)) {
  1307. this._markAsDirty();
  1308. }
  1309. },
  1310. enumerable: true,
  1311. configurable: true
  1312. });
  1313. Object.defineProperty(Control.prototype, "widthInPixels", {
  1314. get: function () {
  1315. return this._width.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1316. },
  1317. enumerable: true,
  1318. configurable: true
  1319. });
  1320. Object.defineProperty(Control.prototype, "height", {
  1321. get: function () {
  1322. return this._height.toString(this._host);
  1323. },
  1324. set: function (value) {
  1325. if (this._height.toString(this._host) === value) {
  1326. return;
  1327. }
  1328. if (this._height.fromString(value)) {
  1329. this._markAsDirty();
  1330. }
  1331. },
  1332. enumerable: true,
  1333. configurable: true
  1334. });
  1335. Object.defineProperty(Control.prototype, "heightInPixels", {
  1336. get: function () {
  1337. return this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1338. },
  1339. enumerable: true,
  1340. configurable: true
  1341. });
  1342. Object.defineProperty(Control.prototype, "fontFamily", {
  1343. get: function () {
  1344. return this._fontFamily;
  1345. },
  1346. set: function (value) {
  1347. if (this._fontFamily === value) {
  1348. return;
  1349. }
  1350. this._fontFamily = value;
  1351. this._resetFontCache();
  1352. },
  1353. enumerable: true,
  1354. configurable: true
  1355. });
  1356. Object.defineProperty(Control.prototype, "fontStyle", {
  1357. get: function () {
  1358. return this._fontStyle;
  1359. },
  1360. set: function (value) {
  1361. if (this._fontStyle === value) {
  1362. return;
  1363. }
  1364. this._fontStyle = value;
  1365. this._resetFontCache();
  1366. },
  1367. enumerable: true,
  1368. configurable: true
  1369. });
  1370. Object.defineProperty(Control.prototype, "style", {
  1371. get: function () {
  1372. return this._style;
  1373. },
  1374. set: function (value) {
  1375. var _this = this;
  1376. if (this._style) {
  1377. this._style.onChangedObservable.remove(this._styleObserver);
  1378. this._styleObserver = null;
  1379. }
  1380. this._style = value;
  1381. if (this._style) {
  1382. this._styleObserver = this._style.onChangedObservable.add(function () {
  1383. _this._markAsDirty();
  1384. _this._resetFontCache();
  1385. });
  1386. }
  1387. this._markAsDirty();
  1388. this._resetFontCache();
  1389. },
  1390. enumerable: true,
  1391. configurable: true
  1392. });
  1393. Object.defineProperty(Control.prototype, "_isFontSizeInPercentage", {
  1394. /** @hidden */
  1395. get: function () {
  1396. return this._fontSize.isPercentage;
  1397. },
  1398. enumerable: true,
  1399. configurable: true
  1400. });
  1401. Object.defineProperty(Control.prototype, "fontSizeInPixels", {
  1402. get: function () {
  1403. var fontSizeToUse = this._style ? this._style._fontSize : this._fontSize;
  1404. if (fontSizeToUse.isPixel) {
  1405. return fontSizeToUse.getValue(this._host);
  1406. }
  1407. return fontSizeToUse.getValueInPixel(this._host, this._tempParentMeasure.height || this._cachedParentMeasure.height);
  1408. },
  1409. enumerable: true,
  1410. configurable: true
  1411. });
  1412. Object.defineProperty(Control.prototype, "fontSize", {
  1413. get: function () {
  1414. return this._fontSize.toString(this._host);
  1415. },
  1416. set: function (value) {
  1417. if (this._fontSize.toString(this._host) === value) {
  1418. return;
  1419. }
  1420. if (this._fontSize.fromString(value)) {
  1421. this._markAsDirty();
  1422. this._resetFontCache();
  1423. }
  1424. },
  1425. enumerable: true,
  1426. configurable: true
  1427. });
  1428. Object.defineProperty(Control.prototype, "color", {
  1429. get: function () {
  1430. return this._color;
  1431. },
  1432. set: function (value) {
  1433. if (this._color === value) {
  1434. return;
  1435. }
  1436. this._color = value;
  1437. this._markAsDirty();
  1438. },
  1439. enumerable: true,
  1440. configurable: true
  1441. });
  1442. Object.defineProperty(Control.prototype, "zIndex", {
  1443. get: function () {
  1444. return this._zIndex;
  1445. },
  1446. set: function (value) {
  1447. if (this.zIndex === value) {
  1448. return;
  1449. }
  1450. this._zIndex = value;
  1451. if (this._root) {
  1452. this._root._reOrderControl(this);
  1453. }
  1454. },
  1455. enumerable: true,
  1456. configurable: true
  1457. });
  1458. Object.defineProperty(Control.prototype, "notRenderable", {
  1459. get: function () {
  1460. return this._doNotRender;
  1461. },
  1462. set: function (value) {
  1463. if (this._doNotRender === value) {
  1464. return;
  1465. }
  1466. this._doNotRender = value;
  1467. this._markAsDirty();
  1468. },
  1469. enumerable: true,
  1470. configurable: true
  1471. });
  1472. Object.defineProperty(Control.prototype, "isVisible", {
  1473. get: function () {
  1474. return this._isVisible;
  1475. },
  1476. set: function (value) {
  1477. if (this._isVisible === value) {
  1478. return;
  1479. }
  1480. this._isVisible = value;
  1481. this._markAsDirty();
  1482. },
  1483. enumerable: true,
  1484. configurable: true
  1485. });
  1486. Object.defineProperty(Control.prototype, "isDirty", {
  1487. get: function () {
  1488. return this._isDirty;
  1489. },
  1490. enumerable: true,
  1491. configurable: true
  1492. });
  1493. Object.defineProperty(Control.prototype, "paddingLeft", {
  1494. get: function () {
  1495. return this._paddingLeft.toString(this._host);
  1496. },
  1497. set: function (value) {
  1498. if (this._paddingLeft.fromString(value)) {
  1499. this._markAsDirty();
  1500. }
  1501. },
  1502. enumerable: true,
  1503. configurable: true
  1504. });
  1505. Object.defineProperty(Control.prototype, "paddingLeftInPixels", {
  1506. get: function () {
  1507. return this._paddingLeft.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1508. },
  1509. enumerable: true,
  1510. configurable: true
  1511. });
  1512. Object.defineProperty(Control.prototype, "paddingRight", {
  1513. get: function () {
  1514. return this._paddingRight.toString(this._host);
  1515. },
  1516. set: function (value) {
  1517. if (this._paddingRight.fromString(value)) {
  1518. this._markAsDirty();
  1519. }
  1520. },
  1521. enumerable: true,
  1522. configurable: true
  1523. });
  1524. Object.defineProperty(Control.prototype, "paddingRightInPixels", {
  1525. get: function () {
  1526. return this._paddingRight.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1527. },
  1528. enumerable: true,
  1529. configurable: true
  1530. });
  1531. Object.defineProperty(Control.prototype, "paddingTop", {
  1532. get: function () {
  1533. return this._paddingTop.toString(this._host);
  1534. },
  1535. set: function (value) {
  1536. if (this._paddingTop.fromString(value)) {
  1537. this._markAsDirty();
  1538. }
  1539. },
  1540. enumerable: true,
  1541. configurable: true
  1542. });
  1543. Object.defineProperty(Control.prototype, "paddingTopInPixels", {
  1544. get: function () {
  1545. return this._paddingTop.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1546. },
  1547. enumerable: true,
  1548. configurable: true
  1549. });
  1550. Object.defineProperty(Control.prototype, "paddingBottom", {
  1551. get: function () {
  1552. return this._paddingBottom.toString(this._host);
  1553. },
  1554. set: function (value) {
  1555. if (this._paddingBottom.fromString(value)) {
  1556. this._markAsDirty();
  1557. }
  1558. },
  1559. enumerable: true,
  1560. configurable: true
  1561. });
  1562. Object.defineProperty(Control.prototype, "paddingBottomInPixels", {
  1563. get: function () {
  1564. return this._paddingBottom.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1565. },
  1566. enumerable: true,
  1567. configurable: true
  1568. });
  1569. Object.defineProperty(Control.prototype, "left", {
  1570. get: function () {
  1571. return this._left.toString(this._host);
  1572. },
  1573. set: function (value) {
  1574. if (this._left.fromString(value)) {
  1575. this._markAsDirty();
  1576. }
  1577. },
  1578. enumerable: true,
  1579. configurable: true
  1580. });
  1581. Object.defineProperty(Control.prototype, "leftInPixels", {
  1582. get: function () {
  1583. return this._left.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1584. },
  1585. enumerable: true,
  1586. configurable: true
  1587. });
  1588. Object.defineProperty(Control.prototype, "top", {
  1589. get: function () {
  1590. return this._top.toString(this._host);
  1591. },
  1592. set: function (value) {
  1593. if (this._top.fromString(value)) {
  1594. this._markAsDirty();
  1595. }
  1596. },
  1597. enumerable: true,
  1598. configurable: true
  1599. });
  1600. Object.defineProperty(Control.prototype, "topInPixels", {
  1601. get: function () {
  1602. return this._top.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1603. },
  1604. enumerable: true,
  1605. configurable: true
  1606. });
  1607. Object.defineProperty(Control.prototype, "linkOffsetX", {
  1608. get: function () {
  1609. return this._linkOffsetX.toString(this._host);
  1610. },
  1611. set: function (value) {
  1612. if (this._linkOffsetX.fromString(value)) {
  1613. this._markAsDirty();
  1614. }
  1615. },
  1616. enumerable: true,
  1617. configurable: true
  1618. });
  1619. Object.defineProperty(Control.prototype, "linkOffsetXInPixels", {
  1620. get: function () {
  1621. return this._linkOffsetX.getValueInPixel(this._host, this._cachedParentMeasure.width);
  1622. },
  1623. enumerable: true,
  1624. configurable: true
  1625. });
  1626. Object.defineProperty(Control.prototype, "linkOffsetY", {
  1627. get: function () {
  1628. return this._linkOffsetY.toString(this._host);
  1629. },
  1630. set: function (value) {
  1631. if (this._linkOffsetY.fromString(value)) {
  1632. this._markAsDirty();
  1633. }
  1634. },
  1635. enumerable: true,
  1636. configurable: true
  1637. });
  1638. Object.defineProperty(Control.prototype, "linkOffsetYInPixels", {
  1639. get: function () {
  1640. return this._linkOffsetY.getValueInPixel(this._host, this._cachedParentMeasure.height);
  1641. },
  1642. enumerable: true,
  1643. configurable: true
  1644. });
  1645. Object.defineProperty(Control.prototype, "centerX", {
  1646. get: function () {
  1647. return this._currentMeasure.left + this._currentMeasure.width / 2;
  1648. },
  1649. enumerable: true,
  1650. configurable: true
  1651. });
  1652. Object.defineProperty(Control.prototype, "centerY", {
  1653. get: function () {
  1654. return this._currentMeasure.top + this._currentMeasure.height / 2;
  1655. },
  1656. enumerable: true,
  1657. configurable: true
  1658. });
  1659. Control.prototype._getTypeName = function () {
  1660. return "Control";
  1661. };
  1662. /** @hidden */
  1663. Control.prototype._resetFontCache = function () {
  1664. this._fontSet = true;
  1665. };
  1666. Control.prototype.getLocalCoordinates = function (globalCoordinates) {
  1667. var result = BABYLON.Vector2.Zero();
  1668. this.getLocalCoordinatesToRef(globalCoordinates, result);
  1669. return result;
  1670. };
  1671. Control.prototype.getLocalCoordinatesToRef = function (globalCoordinates, result) {
  1672. result.x = globalCoordinates.x - this._currentMeasure.left;
  1673. result.y = globalCoordinates.y - this._currentMeasure.top;
  1674. return this;
  1675. };
  1676. Control.prototype.getParentLocalCoordinates = function (globalCoordinates) {
  1677. var result = BABYLON.Vector2.Zero();
  1678. result.x = globalCoordinates.x - this._cachedParentMeasure.left;
  1679. result.y = globalCoordinates.y - this._cachedParentMeasure.top;
  1680. return result;
  1681. };
  1682. Control.prototype.moveToVector3 = function (position, scene) {
  1683. if (!this._host || this._root !== this._host._rootContainer) {
  1684. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  1685. return;
  1686. }
  1687. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1688. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1689. var globalViewport = this._host._getGlobalViewport(scene);
  1690. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  1691. this._moveToProjectedPosition(projectedPosition);
  1692. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  1693. this.notRenderable = true;
  1694. return;
  1695. }
  1696. this.notRenderable = false;
  1697. };
  1698. Control.prototype.linkWithMesh = function (mesh) {
  1699. if (!this._host || this._root && this._root !== this._host._rootContainer) {
  1700. if (mesh) {
  1701. BABYLON.Tools.Error("Cannot link a control to a mesh if the control is not at root level");
  1702. }
  1703. return;
  1704. }
  1705. var index = this._host._linkedControls.indexOf(this);
  1706. if (index !== -1) {
  1707. this._linkedMesh = mesh;
  1708. if (!mesh) {
  1709. this._host._linkedControls.splice(index, 1);
  1710. }
  1711. return;
  1712. }
  1713. else if (!mesh) {
  1714. return;
  1715. }
  1716. this.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1717. this.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  1718. this._linkedMesh = mesh;
  1719. this._onlyMeasureMode = true;
  1720. this._host._linkedControls.push(this);
  1721. };
  1722. Control.prototype._moveToProjectedPosition = function (projectedPosition) {
  1723. var oldLeft = this._left.getValue(this._host);
  1724. var oldTop = this._top.getValue(this._host);
  1725. var newLeft = ((projectedPosition.x + this._linkOffsetX.getValue(this._host)) - this._currentMeasure.width / 2);
  1726. var newTop = ((projectedPosition.y + this._linkOffsetY.getValue(this._host)) - this._currentMeasure.height / 2);
  1727. if (this._left.ignoreAdaptiveScaling && this._top.ignoreAdaptiveScaling) {
  1728. if (Math.abs(newLeft - oldLeft) < 0.5) {
  1729. newLeft = oldLeft;
  1730. }
  1731. if (Math.abs(newTop - oldTop) < 0.5) {
  1732. newTop = oldTop;
  1733. }
  1734. }
  1735. this.left = newLeft + "px";
  1736. this.top = newTop + "px";
  1737. this._left.ignoreAdaptiveScaling = true;
  1738. this._top.ignoreAdaptiveScaling = true;
  1739. };
  1740. Control.prototype._markMatrixAsDirty = function () {
  1741. this._isMatrixDirty = true;
  1742. this._markAsDirty();
  1743. };
  1744. Control.prototype._markAsDirty = function () {
  1745. this._isDirty = true;
  1746. if (!this._host) {
  1747. return; // Not yet connected
  1748. }
  1749. this._host.markAsDirty();
  1750. };
  1751. Control.prototype._markAllAsDirty = function () {
  1752. this._markAsDirty();
  1753. if (this._font) {
  1754. this._prepareFont();
  1755. }
  1756. };
  1757. Control.prototype._link = function (root, host) {
  1758. this._root = root;
  1759. this._host = host;
  1760. };
  1761. Control.prototype._transform = function (context) {
  1762. if (!this._isMatrixDirty && this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  1763. return;
  1764. }
  1765. // postTranslate
  1766. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  1767. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  1768. context.translate(offsetX, offsetY);
  1769. // rotate
  1770. context.rotate(this._rotation);
  1771. // scale
  1772. context.scale(this._scaleX, this._scaleY);
  1773. // preTranslate
  1774. context.translate(-offsetX, -offsetY);
  1775. // Need to update matrices?
  1776. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  1777. this._cachedOffsetX = offsetX;
  1778. this._cachedOffsetY = offsetY;
  1779. this._isMatrixDirty = false;
  1780. GUI.Matrix2D.ComposeToRef(-offsetX, -offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  1781. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  1782. }
  1783. };
  1784. Control.prototype._applyStates = function (context) {
  1785. if (this._fontSet) {
  1786. this._prepareFont();
  1787. this._fontSet = false;
  1788. }
  1789. if (this._font) {
  1790. context.font = this._font;
  1791. }
  1792. if (this._color) {
  1793. context.fillStyle = this._color;
  1794. }
  1795. if (this._alphaSet) {
  1796. context.globalAlpha = this._alpha;
  1797. }
  1798. };
  1799. Control.prototype._processMeasures = function (parentMeasure, context) {
  1800. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  1801. this._isDirty = false;
  1802. this._currentMeasure.copyFrom(parentMeasure);
  1803. // Let children take some pre-measurement actions
  1804. this._preMeasure(parentMeasure, context);
  1805. this._measure();
  1806. this._computeAlignment(parentMeasure, context);
  1807. // Convert to int values
  1808. this._currentMeasure.left = this._currentMeasure.left | 0;
  1809. this._currentMeasure.top = this._currentMeasure.top | 0;
  1810. this._currentMeasure.width = this._currentMeasure.width | 0;
  1811. this._currentMeasure.height = this._currentMeasure.height | 0;
  1812. // Let children add more features
  1813. this._additionalProcessing(parentMeasure, context);
  1814. this._cachedParentMeasure.copyFrom(parentMeasure);
  1815. if (this.onDirtyObservable.hasObservers()) {
  1816. this.onDirtyObservable.notifyObservers(this);
  1817. }
  1818. }
  1819. if (this._currentMeasure.left > parentMeasure.left + parentMeasure.width) {
  1820. return false;
  1821. }
  1822. if (this._currentMeasure.left + this._currentMeasure.width < parentMeasure.left) {
  1823. return false;
  1824. }
  1825. if (this._currentMeasure.top > parentMeasure.top + parentMeasure.height) {
  1826. return false;
  1827. }
  1828. if (this._currentMeasure.top + this._currentMeasure.height < parentMeasure.top) {
  1829. return false;
  1830. }
  1831. // Transform
  1832. this._transform(context);
  1833. if (this._onlyMeasureMode) {
  1834. this._onlyMeasureMode = false;
  1835. return false; // We do not want rendering for this frame as they are measure dependant information that need to be gathered
  1836. }
  1837. // Clip
  1838. this._clip(context);
  1839. context.clip();
  1840. return true;
  1841. };
  1842. Control.prototype._clip = function (context) {
  1843. context.beginPath();
  1844. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1845. var shadowOffsetX = this.shadowOffsetX;
  1846. var shadowOffsetY = this.shadowOffsetY;
  1847. var shadowBlur = this.shadowBlur;
  1848. var leftShadowOffset = Math.min(Math.min(shadowOffsetX, 0) - shadowBlur * 2, 0);
  1849. var rightShadowOffset = Math.max(Math.max(shadowOffsetX, 0) + shadowBlur * 2, 0);
  1850. var topShadowOffset = Math.min(Math.min(shadowOffsetY, 0) - shadowBlur * 2, 0);
  1851. var bottomShadowOffset = Math.max(Math.max(shadowOffsetY, 0) + shadowBlur * 2, 0);
  1852. context.rect(this._currentMeasure.left + leftShadowOffset, this._currentMeasure.top + topShadowOffset, this._currentMeasure.width + rightShadowOffset - leftShadowOffset, this._currentMeasure.height + bottomShadowOffset - topShadowOffset);
  1853. }
  1854. else {
  1855. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1856. }
  1857. };
  1858. Control.prototype._measure = function () {
  1859. // Width / Height
  1860. if (this._width.isPixel) {
  1861. this._currentMeasure.width = this._width.getValue(this._host);
  1862. }
  1863. else {
  1864. this._currentMeasure.width *= this._width.getValue(this._host);
  1865. }
  1866. if (this._height.isPixel) {
  1867. this._currentMeasure.height = this._height.getValue(this._host);
  1868. }
  1869. else {
  1870. this._currentMeasure.height *= this._height.getValue(this._host);
  1871. }
  1872. };
  1873. Control.prototype._computeAlignment = function (parentMeasure, context) {
  1874. var width = this._currentMeasure.width;
  1875. var height = this._currentMeasure.height;
  1876. var parentWidth = parentMeasure.width;
  1877. var parentHeight = parentMeasure.height;
  1878. // Left / top
  1879. var x = 0;
  1880. var y = 0;
  1881. switch (this.horizontalAlignment) {
  1882. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  1883. x = 0;
  1884. break;
  1885. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  1886. x = parentWidth - width;
  1887. break;
  1888. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  1889. x = (parentWidth - width) / 2;
  1890. break;
  1891. }
  1892. switch (this.verticalAlignment) {
  1893. case Control.VERTICAL_ALIGNMENT_TOP:
  1894. y = 0;
  1895. break;
  1896. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  1897. y = parentHeight - height;
  1898. break;
  1899. case Control.VERTICAL_ALIGNMENT_CENTER:
  1900. y = (parentHeight - height) / 2;
  1901. break;
  1902. }
  1903. if (this._paddingLeft.isPixel) {
  1904. this._currentMeasure.left += this._paddingLeft.getValue(this._host);
  1905. this._currentMeasure.width -= this._paddingLeft.getValue(this._host);
  1906. }
  1907. else {
  1908. this._currentMeasure.left += parentWidth * this._paddingLeft.getValue(this._host);
  1909. this._currentMeasure.width -= parentWidth * this._paddingLeft.getValue(this._host);
  1910. }
  1911. if (this._paddingRight.isPixel) {
  1912. this._currentMeasure.width -= this._paddingRight.getValue(this._host);
  1913. }
  1914. else {
  1915. this._currentMeasure.width -= parentWidth * this._paddingRight.getValue(this._host);
  1916. }
  1917. if (this._paddingTop.isPixel) {
  1918. this._currentMeasure.top += this._paddingTop.getValue(this._host);
  1919. this._currentMeasure.height -= this._paddingTop.getValue(this._host);
  1920. }
  1921. else {
  1922. this._currentMeasure.top += parentHeight * this._paddingTop.getValue(this._host);
  1923. this._currentMeasure.height -= parentHeight * this._paddingTop.getValue(this._host);
  1924. }
  1925. if (this._paddingBottom.isPixel) {
  1926. this._currentMeasure.height -= this._paddingBottom.getValue(this._host);
  1927. }
  1928. else {
  1929. this._currentMeasure.height -= parentHeight * this._paddingBottom.getValue(this._host);
  1930. }
  1931. if (this._left.isPixel) {
  1932. this._currentMeasure.left += this._left.getValue(this._host);
  1933. }
  1934. else {
  1935. this._currentMeasure.left += parentWidth * this._left.getValue(this._host);
  1936. }
  1937. if (this._top.isPixel) {
  1938. this._currentMeasure.top += this._top.getValue(this._host);
  1939. }
  1940. else {
  1941. this._currentMeasure.top += parentHeight * this._top.getValue(this._host);
  1942. }
  1943. this._currentMeasure.left += x;
  1944. this._currentMeasure.top += y;
  1945. };
  1946. Control.prototype._preMeasure = function (parentMeasure, context) {
  1947. // Do nothing
  1948. };
  1949. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  1950. // Do nothing
  1951. };
  1952. Control.prototype._draw = function (parentMeasure, context) {
  1953. // Do nothing
  1954. };
  1955. Control.prototype.contains = function (x, y) {
  1956. // Invert transform
  1957. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  1958. x = this._transformedPosition.x;
  1959. y = this._transformedPosition.y;
  1960. // Check
  1961. if (x < this._currentMeasure.left) {
  1962. return false;
  1963. }
  1964. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  1965. return false;
  1966. }
  1967. if (y < this._currentMeasure.top) {
  1968. return false;
  1969. }
  1970. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  1971. return false;
  1972. }
  1973. if (this.isPointerBlocker) {
  1974. this._host._shouldBlockPointer = true;
  1975. }
  1976. return true;
  1977. };
  1978. Control.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  1979. if (!this.isHitTestVisible || !this.isVisible || this._doNotRender) {
  1980. return false;
  1981. }
  1982. if (!this.contains(x, y)) {
  1983. return false;
  1984. }
  1985. this._processObservables(type, x, y, pointerId, buttonIndex);
  1986. return true;
  1987. };
  1988. Control.prototype._onPointerMove = function (target, coordinates) {
  1989. var canNotify = this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  1990. if (canNotify && this.parent != null)
  1991. this.parent._onPointerMove(target, coordinates);
  1992. };
  1993. Control.prototype._onPointerEnter = function (target) {
  1994. if (this._enterCount !== 0) {
  1995. return false;
  1996. }
  1997. this._enterCount++;
  1998. var canNotify = this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  1999. if (canNotify && this.parent != null)
  2000. this.parent._onPointerEnter(target);
  2001. return true;
  2002. };
  2003. Control.prototype._onPointerOut = function (target) {
  2004. this._enterCount = 0;
  2005. var canNotify = this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  2006. if (canNotify && this.parent != null)
  2007. this.parent._onPointerOut(target);
  2008. };
  2009. Control.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  2010. if (this._downCount !== 0) {
  2011. return false;
  2012. }
  2013. this._downCount++;
  2014. this._downPointerIds[pointerId] = true;
  2015. var canNotify = this.onPointerDownObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  2016. if (canNotify && this.parent != null)
  2017. this.parent._onPointerDown(target, coordinates, pointerId, buttonIndex);
  2018. return true;
  2019. };
  2020. Control.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  2021. this._downCount = 0;
  2022. delete this._downPointerIds[pointerId];
  2023. var canNotifyClick = notifyClick;
  2024. if (notifyClick && this._enterCount > 0) {
  2025. canNotifyClick = this.onPointerClickObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  2026. }
  2027. var canNotify = this.onPointerUpObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  2028. if (canNotify && this.parent != null)
  2029. this.parent._onPointerUp(target, coordinates, pointerId, buttonIndex, canNotifyClick);
  2030. };
  2031. Control.prototype.forcePointerUp = function (pointerId) {
  2032. if (pointerId === void 0) { pointerId = null; }
  2033. if (pointerId !== null) {
  2034. this._onPointerUp(this, BABYLON.Vector2.Zero(), pointerId, 0, true);
  2035. }
  2036. else {
  2037. for (var key in this._downPointerIds) {
  2038. this._onPointerUp(this, BABYLON.Vector2.Zero(), +key, 0, true);
  2039. }
  2040. }
  2041. };
  2042. Control.prototype._processObservables = function (type, x, y, pointerId, buttonIndex) {
  2043. this._dummyVector2.copyFromFloats(x, y);
  2044. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  2045. this._onPointerMove(this, this._dummyVector2);
  2046. var previousControlOver = this._host._lastControlOver[pointerId];
  2047. if (previousControlOver && previousControlOver !== this) {
  2048. previousControlOver._onPointerOut(this);
  2049. }
  2050. if (previousControlOver !== this) {
  2051. this._onPointerEnter(this);
  2052. }
  2053. this._host._lastControlOver[pointerId] = this;
  2054. return true;
  2055. }
  2056. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  2057. this._onPointerDown(this, this._dummyVector2, pointerId, buttonIndex);
  2058. this._host._lastControlDown[pointerId] = this;
  2059. this._host._lastPickedControl = this;
  2060. return true;
  2061. }
  2062. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  2063. if (this._host._lastControlDown[pointerId]) {
  2064. this._host._lastControlDown[pointerId]._onPointerUp(this, this._dummyVector2, pointerId, buttonIndex, true);
  2065. }
  2066. delete this._host._lastControlDown[pointerId];
  2067. return true;
  2068. }
  2069. return false;
  2070. };
  2071. Control.prototype._prepareFont = function () {
  2072. if (!this._font && !this._fontSet) {
  2073. return;
  2074. }
  2075. if (this._style) {
  2076. this._font = this._style.fontStyle + " " + this.fontSizeInPixels + "px " + this._style.fontFamily;
  2077. }
  2078. else {
  2079. this._font = this._fontStyle + " " + this.fontSizeInPixels + "px " + this._fontFamily;
  2080. }
  2081. this._fontOffset = Control._GetFontOffset(this._font);
  2082. };
  2083. Control.prototype.dispose = function () {
  2084. this.onDirtyObservable.clear();
  2085. this.onAfterDrawObservable.clear();
  2086. this.onPointerDownObservable.clear();
  2087. this.onPointerEnterObservable.clear();
  2088. this.onPointerMoveObservable.clear();
  2089. this.onPointerOutObservable.clear();
  2090. this.onPointerUpObservable.clear();
  2091. this.onPointerClickObservable.clear();
  2092. if (this._styleObserver && this._style) {
  2093. this._style.onChangedObservable.remove(this._styleObserver);
  2094. this._styleObserver = null;
  2095. }
  2096. if (this._root) {
  2097. this._root.removeControl(this);
  2098. this._root = null;
  2099. }
  2100. var index = this._host._linkedControls.indexOf(this);
  2101. if (index > -1) {
  2102. this.linkWithMesh(null);
  2103. }
  2104. };
  2105. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  2106. get: function () {
  2107. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  2108. },
  2109. enumerable: true,
  2110. configurable: true
  2111. });
  2112. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  2113. get: function () {
  2114. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  2115. },
  2116. enumerable: true,
  2117. configurable: true
  2118. });
  2119. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  2120. get: function () {
  2121. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  2122. },
  2123. enumerable: true,
  2124. configurable: true
  2125. });
  2126. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  2127. get: function () {
  2128. return Control._VERTICAL_ALIGNMENT_TOP;
  2129. },
  2130. enumerable: true,
  2131. configurable: true
  2132. });
  2133. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  2134. get: function () {
  2135. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  2136. },
  2137. enumerable: true,
  2138. configurable: true
  2139. });
  2140. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  2141. get: function () {
  2142. return Control._VERTICAL_ALIGNMENT_CENTER;
  2143. },
  2144. enumerable: true,
  2145. configurable: true
  2146. });
  2147. Control._GetFontOffset = function (font) {
  2148. if (Control._FontHeightSizes[font]) {
  2149. return Control._FontHeightSizes[font];
  2150. }
  2151. var text = document.createElement("span");
  2152. text.innerHTML = "Hg";
  2153. text.style.font = font;
  2154. var block = document.createElement("div");
  2155. block.style.display = "inline-block";
  2156. block.style.width = "1px";
  2157. block.style.height = "0px";
  2158. block.style.verticalAlign = "bottom";
  2159. var div = document.createElement("div");
  2160. div.appendChild(text);
  2161. div.appendChild(block);
  2162. document.body.appendChild(div);
  2163. var fontAscent = 0;
  2164. var fontHeight = 0;
  2165. try {
  2166. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  2167. block.style.verticalAlign = "baseline";
  2168. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  2169. }
  2170. finally {
  2171. document.body.removeChild(div);
  2172. }
  2173. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  2174. Control._FontHeightSizes[font] = result;
  2175. return result;
  2176. };
  2177. ;
  2178. Control.AddHeader = function (control, text, size, options) {
  2179. var panel = new BABYLON.GUI.StackPanel("panel");
  2180. var isHorizontal = options ? options.isHorizontal : true;
  2181. var controlFirst = options ? options.controlFirst : true;
  2182. panel.isVertical = !isHorizontal;
  2183. var header = new BABYLON.GUI.TextBlock("header");
  2184. header.text = text;
  2185. header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  2186. if (isHorizontal) {
  2187. header.width = size;
  2188. }
  2189. else {
  2190. header.height = size;
  2191. }
  2192. if (controlFirst) {
  2193. panel.addControl(control);
  2194. panel.addControl(header);
  2195. header.paddingLeft = "5px";
  2196. }
  2197. else {
  2198. panel.addControl(header);
  2199. panel.addControl(control);
  2200. header.paddingRight = "5px";
  2201. }
  2202. header.shadowBlur = control.shadowBlur;
  2203. header.shadowColor = control.shadowColor;
  2204. header.shadowOffsetX = control.shadowOffsetX;
  2205. header.shadowOffsetY = control.shadowOffsetY;
  2206. return panel;
  2207. };
  2208. Control.drawEllipse = function (x, y, width, height, context) {
  2209. context.translate(x, y);
  2210. context.scale(width, height);
  2211. context.beginPath();
  2212. context.arc(0, 0, 1, 0, 2 * Math.PI);
  2213. context.closePath();
  2214. context.scale(1 / width, 1 / height);
  2215. context.translate(-x, -y);
  2216. };
  2217. // Statics
  2218. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  2219. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  2220. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  2221. Control._VERTICAL_ALIGNMENT_TOP = 0;
  2222. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  2223. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  2224. Control._FontHeightSizes = {};
  2225. return Control;
  2226. }());
  2227. GUI.Control = Control;
  2228. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2229. })(BABYLON || (BABYLON = {}));
  2230. //# sourceMappingURL=control.js.map
  2231. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2232. var BABYLON;
  2233. (function (BABYLON) {
  2234. var GUI;
  2235. (function (GUI) {
  2236. var Container = /** @class */ (function (_super) {
  2237. __extends(Container, _super);
  2238. function Container(name) {
  2239. var _this = _super.call(this, name) || this;
  2240. _this.name = name;
  2241. _this._children = new Array();
  2242. _this._measureForChildren = GUI.Measure.Empty();
  2243. _this._adaptWidthToChildren = false;
  2244. _this._adaptHeightToChildren = false;
  2245. return _this;
  2246. }
  2247. Object.defineProperty(Container.prototype, "adaptHeightToChildren", {
  2248. get: function () {
  2249. return this._adaptHeightToChildren;
  2250. },
  2251. set: function (value) {
  2252. if (this._adaptHeightToChildren === value) {
  2253. return;
  2254. }
  2255. this._adaptHeightToChildren = value;
  2256. if (value) {
  2257. this.height = "100%";
  2258. }
  2259. this._markAsDirty();
  2260. },
  2261. enumerable: true,
  2262. configurable: true
  2263. });
  2264. Object.defineProperty(Container.prototype, "adaptWidthToChildren", {
  2265. get: function () {
  2266. return this._adaptWidthToChildren;
  2267. },
  2268. set: function (value) {
  2269. if (this._adaptWidthToChildren === value) {
  2270. return;
  2271. }
  2272. this._adaptWidthToChildren = value;
  2273. if (value) {
  2274. this.width = "100%";
  2275. }
  2276. this._markAsDirty();
  2277. },
  2278. enumerable: true,
  2279. configurable: true
  2280. });
  2281. Object.defineProperty(Container.prototype, "background", {
  2282. get: function () {
  2283. return this._background;
  2284. },
  2285. set: function (value) {
  2286. if (this._background === value) {
  2287. return;
  2288. }
  2289. this._background = value;
  2290. this._markAsDirty();
  2291. },
  2292. enumerable: true,
  2293. configurable: true
  2294. });
  2295. Object.defineProperty(Container.prototype, "children", {
  2296. get: function () {
  2297. return this._children;
  2298. },
  2299. enumerable: true,
  2300. configurable: true
  2301. });
  2302. Container.prototype._getTypeName = function () {
  2303. return "Container";
  2304. };
  2305. Container.prototype.getChildByName = function (name) {
  2306. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2307. var child = _a[_i];
  2308. if (child.name === name) {
  2309. return child;
  2310. }
  2311. }
  2312. return null;
  2313. };
  2314. Container.prototype.getChildByType = function (name, type) {
  2315. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2316. var child = _a[_i];
  2317. if (child.typeName === type) {
  2318. return child;
  2319. }
  2320. }
  2321. return null;
  2322. };
  2323. Container.prototype.containsControl = function (control) {
  2324. return this._children.indexOf(control) !== -1;
  2325. };
  2326. Container.prototype.addControl = function (control) {
  2327. var index = this._children.indexOf(control);
  2328. if (index !== -1) {
  2329. return this;
  2330. }
  2331. control._link(this, this._host);
  2332. control._markAllAsDirty();
  2333. this._reOrderControl(control);
  2334. this._markAsDirty();
  2335. return this;
  2336. };
  2337. Container.prototype.removeControl = function (control) {
  2338. var index = this._children.indexOf(control);
  2339. if (index !== -1) {
  2340. this._children.splice(index, 1);
  2341. control.parent = null;
  2342. }
  2343. control.linkWithMesh(null);
  2344. if (this._host) {
  2345. this._host._cleanControlAfterRemoval(control);
  2346. }
  2347. this._markAsDirty();
  2348. return this;
  2349. };
  2350. Container.prototype._reOrderControl = function (control) {
  2351. this.removeControl(control);
  2352. for (var index = 0; index < this._children.length; index++) {
  2353. if (this._children[index].zIndex > control.zIndex) {
  2354. this._children.splice(index, 0, control);
  2355. return;
  2356. }
  2357. }
  2358. this._children.push(control);
  2359. control.parent = this;
  2360. this._markAsDirty();
  2361. };
  2362. Container.prototype._markMatrixAsDirty = function () {
  2363. _super.prototype._markMatrixAsDirty.call(this);
  2364. for (var index = 0; index < this._children.length; index++) {
  2365. this._children[index]._markMatrixAsDirty();
  2366. }
  2367. };
  2368. Container.prototype._markAllAsDirty = function () {
  2369. _super.prototype._markAllAsDirty.call(this);
  2370. for (var index = 0; index < this._children.length; index++) {
  2371. this._children[index]._markAllAsDirty();
  2372. }
  2373. };
  2374. Container.prototype._localDraw = function (context) {
  2375. if (this._background) {
  2376. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2377. context.shadowColor = this.shadowColor;
  2378. context.shadowBlur = this.shadowBlur;
  2379. context.shadowOffsetX = this.shadowOffsetX;
  2380. context.shadowOffsetY = this.shadowOffsetY;
  2381. }
  2382. context.fillStyle = this._background;
  2383. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2384. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2385. context.shadowBlur = 0;
  2386. context.shadowOffsetX = 0;
  2387. context.shadowOffsetY = 0;
  2388. }
  2389. }
  2390. };
  2391. Container.prototype._link = function (root, host) {
  2392. _super.prototype._link.call(this, root, host);
  2393. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2394. var child = _a[_i];
  2395. child._link(root, host);
  2396. }
  2397. };
  2398. Container.prototype._draw = function (parentMeasure, context) {
  2399. if (!this.isVisible || this.notRenderable) {
  2400. return;
  2401. }
  2402. context.save();
  2403. this._applyStates(context);
  2404. if (this._processMeasures(parentMeasure, context)) {
  2405. this._localDraw(context);
  2406. this._clipForChildren(context);
  2407. var computedWidth = -1;
  2408. var computedHeight = -1;
  2409. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2410. var child = _a[_i];
  2411. if (child.isVisible && !child.notRenderable) {
  2412. child._tempParentMeasure.copyFrom(this._measureForChildren);
  2413. child._draw(this._measureForChildren, context);
  2414. if (child.onAfterDrawObservable.hasObservers()) {
  2415. child.onAfterDrawObservable.notifyObservers(child);
  2416. }
  2417. if (this.adaptWidthToChildren && child._width.isPixel) {
  2418. computedWidth = Math.max(computedWidth, child._currentMeasure.width);
  2419. }
  2420. if (this.adaptHeightToChildren && child._height.isPixel) {
  2421. computedHeight = Math.max(computedHeight, child._currentMeasure.height);
  2422. }
  2423. }
  2424. }
  2425. if (this.adaptWidthToChildren && computedWidth >= 0) {
  2426. this.width = computedWidth + "px";
  2427. }
  2428. if (this.adaptHeightToChildren && computedHeight >= 0) {
  2429. this.height = computedHeight + "px";
  2430. }
  2431. }
  2432. context.restore();
  2433. if (this.onAfterDrawObservable.hasObservers()) {
  2434. this.onAfterDrawObservable.notifyObservers(this);
  2435. }
  2436. };
  2437. Container.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  2438. if (!this.isVisible || this.notRenderable) {
  2439. return false;
  2440. }
  2441. if (!_super.prototype.contains.call(this, x, y)) {
  2442. return false;
  2443. }
  2444. // Checking backwards to pick closest first
  2445. for (var index = this._children.length - 1; index >= 0; index--) {
  2446. var child = this._children[index];
  2447. if (child._processPicking(x, y, type, pointerId, buttonIndex)) {
  2448. return true;
  2449. }
  2450. }
  2451. if (!this.isHitTestVisible) {
  2452. return false;
  2453. }
  2454. return this._processObservables(type, x, y, pointerId, buttonIndex);
  2455. };
  2456. Container.prototype._clipForChildren = function (context) {
  2457. // DO nothing
  2458. };
  2459. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  2460. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2461. this._measureForChildren.copyFrom(this._currentMeasure);
  2462. };
  2463. Container.prototype.dispose = function () {
  2464. _super.prototype.dispose.call(this);
  2465. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2466. var control = _a[_i];
  2467. control.dispose();
  2468. }
  2469. };
  2470. return Container;
  2471. }(GUI.Control));
  2472. GUI.Container = Container;
  2473. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2474. })(BABYLON || (BABYLON = {}));
  2475. //# sourceMappingURL=container.js.map
  2476. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2477. var BABYLON;
  2478. (function (BABYLON) {
  2479. var GUI;
  2480. (function (GUI) {
  2481. var StackPanel = /** @class */ (function (_super) {
  2482. __extends(StackPanel, _super);
  2483. function StackPanel(name) {
  2484. var _this = _super.call(this, name) || this;
  2485. _this.name = name;
  2486. _this._isVertical = true;
  2487. _this._manualWidth = false;
  2488. _this._manualHeight = false;
  2489. _this._doNotTrackManualChanges = false;
  2490. _this._tempMeasureStore = GUI.Measure.Empty();
  2491. return _this;
  2492. }
  2493. Object.defineProperty(StackPanel.prototype, "isVertical", {
  2494. get: function () {
  2495. return this._isVertical;
  2496. },
  2497. set: function (value) {
  2498. if (this._isVertical === value) {
  2499. return;
  2500. }
  2501. this._isVertical = value;
  2502. this._markAsDirty();
  2503. },
  2504. enumerable: true,
  2505. configurable: true
  2506. });
  2507. Object.defineProperty(StackPanel.prototype, "width", {
  2508. get: function () {
  2509. return this._width.toString(this._host);
  2510. },
  2511. set: function (value) {
  2512. if (!this._doNotTrackManualChanges) {
  2513. this._manualWidth = true;
  2514. }
  2515. if (this._width.toString(this._host) === value) {
  2516. return;
  2517. }
  2518. if (this._width.fromString(value)) {
  2519. this._markAsDirty();
  2520. }
  2521. },
  2522. enumerable: true,
  2523. configurable: true
  2524. });
  2525. Object.defineProperty(StackPanel.prototype, "height", {
  2526. get: function () {
  2527. return this._height.toString(this._host);
  2528. },
  2529. set: function (value) {
  2530. if (!this._doNotTrackManualChanges) {
  2531. this._manualHeight = true;
  2532. }
  2533. if (this._height.toString(this._host) === value) {
  2534. return;
  2535. }
  2536. if (this._height.fromString(value)) {
  2537. this._markAsDirty();
  2538. }
  2539. },
  2540. enumerable: true,
  2541. configurable: true
  2542. });
  2543. StackPanel.prototype._getTypeName = function () {
  2544. return "StackPanel";
  2545. };
  2546. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  2547. var stackWidth = 0;
  2548. var stackHeight = 0;
  2549. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2550. var child = _a[_i];
  2551. this._tempMeasureStore.copyFrom(child._currentMeasure);
  2552. child._currentMeasure.copyFrom(parentMeasure);
  2553. child._measure();
  2554. if (this._isVertical) {
  2555. child.top = stackHeight + "px";
  2556. if (!child._top.ignoreAdaptiveScaling) {
  2557. child._markAsDirty();
  2558. }
  2559. child._top.ignoreAdaptiveScaling = true;
  2560. stackHeight += child._currentMeasure.height;
  2561. if (child._currentMeasure.width > stackWidth) {
  2562. stackWidth = child._currentMeasure.width;
  2563. }
  2564. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2565. }
  2566. else {
  2567. child.left = stackWidth + "px";
  2568. if (!child._left.ignoreAdaptiveScaling) {
  2569. child._markAsDirty();
  2570. }
  2571. child._left.ignoreAdaptiveScaling = true;
  2572. stackWidth += child._currentMeasure.width;
  2573. if (child._currentMeasure.height > stackHeight) {
  2574. stackHeight = child._currentMeasure.height;
  2575. }
  2576. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2577. }
  2578. child._currentMeasure.copyFrom(this._tempMeasureStore);
  2579. }
  2580. this._doNotTrackManualChanges = true;
  2581. // Let stack panel width and height default to stackHeight and stackWidth if dimensions are not specified.
  2582. // User can now define their own height and width for stack panel.
  2583. var panelWidthChanged = false;
  2584. var panelHeightChanged = false;
  2585. var previousHeight = this.height;
  2586. var previousWidth = this.width;
  2587. if (!this._manualHeight) {
  2588. // do not specify height if strictly defined by user
  2589. this.height = stackHeight + "px";
  2590. }
  2591. if (!this._manualWidth) {
  2592. // do not specify width if strictly defined by user
  2593. this.width = stackWidth + "px";
  2594. }
  2595. panelWidthChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  2596. panelHeightChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  2597. if (panelHeightChanged) {
  2598. this._height.ignoreAdaptiveScaling = true;
  2599. }
  2600. if (panelWidthChanged) {
  2601. this._width.ignoreAdaptiveScaling = true;
  2602. }
  2603. this._doNotTrackManualChanges = false;
  2604. if (panelWidthChanged || panelHeightChanged) {
  2605. this._markAllAsDirty();
  2606. }
  2607. _super.prototype._preMeasure.call(this, parentMeasure, context);
  2608. };
  2609. return StackPanel;
  2610. }(GUI.Container));
  2611. GUI.StackPanel = StackPanel;
  2612. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2613. })(BABYLON || (BABYLON = {}));
  2614. //# sourceMappingURL=stackPanel.js.map
  2615. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2616. var BABYLON;
  2617. (function (BABYLON) {
  2618. var GUI;
  2619. (function (GUI) {
  2620. var Rectangle = /** @class */ (function (_super) {
  2621. __extends(Rectangle, _super);
  2622. function Rectangle(name) {
  2623. var _this = _super.call(this, name) || this;
  2624. _this.name = name;
  2625. _this._thickness = 1;
  2626. _this._cornerRadius = 0;
  2627. return _this;
  2628. }
  2629. Object.defineProperty(Rectangle.prototype, "thickness", {
  2630. get: function () {
  2631. return this._thickness;
  2632. },
  2633. set: function (value) {
  2634. if (this._thickness === value) {
  2635. return;
  2636. }
  2637. this._thickness = value;
  2638. this._markAsDirty();
  2639. },
  2640. enumerable: true,
  2641. configurable: true
  2642. });
  2643. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  2644. get: function () {
  2645. return this._cornerRadius;
  2646. },
  2647. set: function (value) {
  2648. if (value < 0) {
  2649. value = 0;
  2650. }
  2651. if (this._cornerRadius === value) {
  2652. return;
  2653. }
  2654. this._cornerRadius = value;
  2655. this._markAsDirty();
  2656. },
  2657. enumerable: true,
  2658. configurable: true
  2659. });
  2660. Rectangle.prototype._getTypeName = function () {
  2661. return "Rectangle";
  2662. };
  2663. Rectangle.prototype._localDraw = function (context) {
  2664. context.save();
  2665. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2666. context.shadowColor = this.shadowColor;
  2667. context.shadowBlur = this.shadowBlur;
  2668. context.shadowOffsetX = this.shadowOffsetX;
  2669. context.shadowOffsetY = this.shadowOffsetY;
  2670. }
  2671. if (this._background) {
  2672. context.fillStyle = this._background;
  2673. if (this._cornerRadius) {
  2674. this._drawRoundedRect(context, this._thickness / 2);
  2675. context.fill();
  2676. }
  2677. else {
  2678. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2679. }
  2680. }
  2681. if (this._thickness) {
  2682. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2683. context.shadowBlur = 0;
  2684. context.shadowOffsetX = 0;
  2685. context.shadowOffsetY = 0;
  2686. }
  2687. if (this.color) {
  2688. context.strokeStyle = this.color;
  2689. }
  2690. context.lineWidth = this._thickness;
  2691. if (this._cornerRadius) {
  2692. this._drawRoundedRect(context, this._thickness / 2);
  2693. context.stroke();
  2694. }
  2695. else {
  2696. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  2697. }
  2698. }
  2699. context.restore();
  2700. };
  2701. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  2702. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2703. this._measureForChildren.width -= 2 * this._thickness;
  2704. this._measureForChildren.height -= 2 * this._thickness;
  2705. this._measureForChildren.left += this._thickness;
  2706. this._measureForChildren.top += this._thickness;
  2707. };
  2708. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  2709. if (offset === void 0) { offset = 0; }
  2710. var x = this._currentMeasure.left + offset;
  2711. var y = this._currentMeasure.top + offset;
  2712. var width = this._currentMeasure.width - offset * 2;
  2713. var height = this._currentMeasure.height - offset * 2;
  2714. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  2715. context.beginPath();
  2716. context.moveTo(x + radius, y);
  2717. context.lineTo(x + width - radius, y);
  2718. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  2719. context.lineTo(x + width, y + height - radius);
  2720. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  2721. context.lineTo(x + radius, y + height);
  2722. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  2723. context.lineTo(x, y + radius);
  2724. context.quadraticCurveTo(x, y, x + radius, y);
  2725. context.closePath();
  2726. };
  2727. Rectangle.prototype._clipForChildren = function (context) {
  2728. if (this._cornerRadius) {
  2729. this._drawRoundedRect(context, this._thickness);
  2730. context.clip();
  2731. }
  2732. };
  2733. return Rectangle;
  2734. }(GUI.Container));
  2735. GUI.Rectangle = Rectangle;
  2736. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2737. })(BABYLON || (BABYLON = {}));
  2738. //# sourceMappingURL=rectangle.js.map
  2739. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2740. var BABYLON;
  2741. (function (BABYLON) {
  2742. var GUI;
  2743. (function (GUI) {
  2744. var Ellipse = /** @class */ (function (_super) {
  2745. __extends(Ellipse, _super);
  2746. function Ellipse(name) {
  2747. var _this = _super.call(this, name) || this;
  2748. _this.name = name;
  2749. _this._thickness = 1;
  2750. return _this;
  2751. }
  2752. Object.defineProperty(Ellipse.prototype, "thickness", {
  2753. get: function () {
  2754. return this._thickness;
  2755. },
  2756. set: function (value) {
  2757. if (this._thickness === value) {
  2758. return;
  2759. }
  2760. this._thickness = value;
  2761. this._markAsDirty();
  2762. },
  2763. enumerable: true,
  2764. configurable: true
  2765. });
  2766. Ellipse.prototype._getTypeName = function () {
  2767. return "Ellipse";
  2768. };
  2769. Ellipse.prototype._localDraw = function (context) {
  2770. context.save();
  2771. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2772. context.shadowColor = this.shadowColor;
  2773. context.shadowBlur = this.shadowBlur;
  2774. context.shadowOffsetX = this.shadowOffsetX;
  2775. context.shadowOffsetY = this.shadowOffsetY;
  2776. }
  2777. 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);
  2778. if (this._background) {
  2779. context.fillStyle = this._background;
  2780. context.fill();
  2781. }
  2782. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2783. context.shadowBlur = 0;
  2784. context.shadowOffsetX = 0;
  2785. context.shadowOffsetY = 0;
  2786. }
  2787. if (this._thickness) {
  2788. if (this.color) {
  2789. context.strokeStyle = this.color;
  2790. }
  2791. context.lineWidth = this._thickness;
  2792. context.stroke();
  2793. }
  2794. context.restore();
  2795. };
  2796. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  2797. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2798. this._measureForChildren.width -= 2 * this._thickness;
  2799. this._measureForChildren.height -= 2 * this._thickness;
  2800. this._measureForChildren.left += this._thickness;
  2801. this._measureForChildren.top += this._thickness;
  2802. };
  2803. Ellipse.prototype._clipForChildren = function (context) {
  2804. 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);
  2805. context.clip();
  2806. };
  2807. return Ellipse;
  2808. }(GUI.Container));
  2809. GUI.Ellipse = Ellipse;
  2810. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2811. })(BABYLON || (BABYLON = {}));
  2812. //# sourceMappingURL=ellipse.js.map
  2813. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2814. var BABYLON;
  2815. (function (BABYLON) {
  2816. var GUI;
  2817. (function (GUI) {
  2818. var Line = /** @class */ (function (_super) {
  2819. __extends(Line, _super);
  2820. function Line(name) {
  2821. var _this = _super.call(this, name) || this;
  2822. _this.name = name;
  2823. _this._lineWidth = 1;
  2824. _this._x1 = new GUI.ValueAndUnit(0);
  2825. _this._y1 = new GUI.ValueAndUnit(0);
  2826. _this._x2 = new GUI.ValueAndUnit(0);
  2827. _this._y2 = new GUI.ValueAndUnit(0);
  2828. _this._dash = new Array();
  2829. _this.isHitTestVisible = false;
  2830. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  2831. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  2832. return _this;
  2833. }
  2834. Object.defineProperty(Line.prototype, "dash", {
  2835. get: function () {
  2836. return this._dash;
  2837. },
  2838. set: function (value) {
  2839. if (this._dash === value) {
  2840. return;
  2841. }
  2842. this._dash = value;
  2843. this._markAsDirty();
  2844. },
  2845. enumerable: true,
  2846. configurable: true
  2847. });
  2848. Object.defineProperty(Line.prototype, "connectedControl", {
  2849. get: function () {
  2850. return this._connectedControl;
  2851. },
  2852. set: function (value) {
  2853. var _this = this;
  2854. if (this._connectedControl === value) {
  2855. return;
  2856. }
  2857. if (this._connectedControlDirtyObserver && this._connectedControl) {
  2858. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  2859. this._connectedControlDirtyObserver = null;
  2860. }
  2861. if (value) {
  2862. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  2863. }
  2864. this._connectedControl = value;
  2865. this._markAsDirty();
  2866. },
  2867. enumerable: true,
  2868. configurable: true
  2869. });
  2870. Object.defineProperty(Line.prototype, "x1", {
  2871. get: function () {
  2872. return this._x1.toString(this._host);
  2873. },
  2874. set: function (value) {
  2875. if (this._x1.toString(this._host) === value) {
  2876. return;
  2877. }
  2878. if (this._x1.fromString(value)) {
  2879. this._markAsDirty();
  2880. }
  2881. },
  2882. enumerable: true,
  2883. configurable: true
  2884. });
  2885. Object.defineProperty(Line.prototype, "y1", {
  2886. get: function () {
  2887. return this._y1.toString(this._host);
  2888. },
  2889. set: function (value) {
  2890. if (this._y1.toString(this._host) === value) {
  2891. return;
  2892. }
  2893. if (this._y1.fromString(value)) {
  2894. this._markAsDirty();
  2895. }
  2896. },
  2897. enumerable: true,
  2898. configurable: true
  2899. });
  2900. Object.defineProperty(Line.prototype, "x2", {
  2901. get: function () {
  2902. return this._x2.toString(this._host);
  2903. },
  2904. set: function (value) {
  2905. if (this._x2.toString(this._host) === value) {
  2906. return;
  2907. }
  2908. if (this._x2.fromString(value)) {
  2909. this._markAsDirty();
  2910. }
  2911. },
  2912. enumerable: true,
  2913. configurable: true
  2914. });
  2915. Object.defineProperty(Line.prototype, "y2", {
  2916. get: function () {
  2917. return this._y2.toString(this._host);
  2918. },
  2919. set: function (value) {
  2920. if (this._y2.toString(this._host) === value) {
  2921. return;
  2922. }
  2923. if (this._y2.fromString(value)) {
  2924. this._markAsDirty();
  2925. }
  2926. },
  2927. enumerable: true,
  2928. configurable: true
  2929. });
  2930. Object.defineProperty(Line.prototype, "lineWidth", {
  2931. get: function () {
  2932. return this._lineWidth;
  2933. },
  2934. set: function (value) {
  2935. if (this._lineWidth === value) {
  2936. return;
  2937. }
  2938. this._lineWidth = value;
  2939. this._markAsDirty();
  2940. },
  2941. enumerable: true,
  2942. configurable: true
  2943. });
  2944. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  2945. set: function (value) {
  2946. return;
  2947. },
  2948. enumerable: true,
  2949. configurable: true
  2950. });
  2951. Object.defineProperty(Line.prototype, "verticalAlignment", {
  2952. set: function (value) {
  2953. return;
  2954. },
  2955. enumerable: true,
  2956. configurable: true
  2957. });
  2958. Object.defineProperty(Line.prototype, "_effectiveX2", {
  2959. get: function () {
  2960. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  2961. },
  2962. enumerable: true,
  2963. configurable: true
  2964. });
  2965. Object.defineProperty(Line.prototype, "_effectiveY2", {
  2966. get: function () {
  2967. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  2968. },
  2969. enumerable: true,
  2970. configurable: true
  2971. });
  2972. Line.prototype._getTypeName = function () {
  2973. return "Line";
  2974. };
  2975. Line.prototype._draw = function (parentMeasure, context) {
  2976. context.save();
  2977. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2978. context.shadowColor = this.shadowColor;
  2979. context.shadowBlur = this.shadowBlur;
  2980. context.shadowOffsetX = this.shadowOffsetX;
  2981. context.shadowOffsetY = this.shadowOffsetY;
  2982. }
  2983. this._applyStates(context);
  2984. if (this._processMeasures(parentMeasure, context)) {
  2985. context.strokeStyle = this.color;
  2986. context.lineWidth = this._lineWidth;
  2987. context.setLineDash(this._dash);
  2988. context.beginPath();
  2989. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  2990. context.lineTo(this._effectiveX2, this._effectiveY2);
  2991. context.stroke();
  2992. }
  2993. context.restore();
  2994. };
  2995. Line.prototype._measure = function () {
  2996. // Width / Height
  2997. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  2998. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  2999. };
  3000. Line.prototype._computeAlignment = function (parentMeasure, context) {
  3001. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  3002. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  3003. };
  3004. /**
  3005. * Move one end of the line given 3D cartesian coordinates.
  3006. * @param position Targeted world position
  3007. * @param scene Scene
  3008. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  3009. */
  3010. Line.prototype.moveToVector3 = function (position, scene, end) {
  3011. if (end === void 0) { end = false; }
  3012. if (!this._host || this._root !== this._host._rootContainer) {
  3013. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  3014. return;
  3015. }
  3016. var globalViewport = this._host._getGlobalViewport(scene);
  3017. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  3018. this._moveToProjectedPosition(projectedPosition, end);
  3019. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  3020. this.notRenderable = true;
  3021. return;
  3022. }
  3023. this.notRenderable = false;
  3024. };
  3025. /**
  3026. * Move one end of the line to a position in screen absolute space.
  3027. * @param projectedPosition Position in screen absolute space (X, Y)
  3028. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  3029. */
  3030. Line.prototype._moveToProjectedPosition = function (projectedPosition, end) {
  3031. if (end === void 0) { end = false; }
  3032. var x = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  3033. var y = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  3034. if (end) {
  3035. this.x2 = x;
  3036. this.y2 = y;
  3037. this._x2.ignoreAdaptiveScaling = true;
  3038. this._y2.ignoreAdaptiveScaling = true;
  3039. }
  3040. else {
  3041. this.x1 = x;
  3042. this.y1 = y;
  3043. this._x1.ignoreAdaptiveScaling = true;
  3044. this._y1.ignoreAdaptiveScaling = true;
  3045. }
  3046. };
  3047. return Line;
  3048. }(GUI.Control));
  3049. GUI.Line = Line;
  3050. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3051. })(BABYLON || (BABYLON = {}));
  3052. //# sourceMappingURL=line.js.map
  3053. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3054. var BABYLON;
  3055. (function (BABYLON) {
  3056. var GUI;
  3057. (function (GUI) {
  3058. var Slider = /** @class */ (function (_super) {
  3059. __extends(Slider, _super);
  3060. function Slider(name) {
  3061. var _this = _super.call(this, name) || this;
  3062. _this.name = name;
  3063. _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  3064. _this._minimum = 0;
  3065. _this._maximum = 100;
  3066. _this._value = 50;
  3067. _this._background = "black";
  3068. _this._borderColor = "white";
  3069. _this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  3070. _this._isThumbCircle = false;
  3071. _this._isThumbClamped = false;
  3072. _this.onValueChangedObservable = new BABYLON.Observable();
  3073. // Events
  3074. _this._pointerIsDown = false;
  3075. _this.isPointerBlocker = true;
  3076. return _this;
  3077. }
  3078. Object.defineProperty(Slider.prototype, "borderColor", {
  3079. get: function () {
  3080. return this._borderColor;
  3081. },
  3082. set: function (value) {
  3083. if (this._borderColor === value) {
  3084. return;
  3085. }
  3086. this._borderColor = value;
  3087. this._markAsDirty();
  3088. },
  3089. enumerable: true,
  3090. configurable: true
  3091. });
  3092. Object.defineProperty(Slider.prototype, "background", {
  3093. get: function () {
  3094. return this._background;
  3095. },
  3096. set: function (value) {
  3097. if (this._background === value) {
  3098. return;
  3099. }
  3100. this._background = value;
  3101. this._markAsDirty();
  3102. },
  3103. enumerable: true,
  3104. configurable: true
  3105. });
  3106. Object.defineProperty(Slider.prototype, "barOffset", {
  3107. get: function () {
  3108. return this._barOffset.toString(this._host);
  3109. },
  3110. set: function (value) {
  3111. if (this._barOffset.toString(this._host) === value) {
  3112. return;
  3113. }
  3114. if (this._barOffset.fromString(value)) {
  3115. this._markAsDirty();
  3116. }
  3117. },
  3118. enumerable: true,
  3119. configurable: true
  3120. });
  3121. Object.defineProperty(Slider.prototype, "barOffsetInPixels", {
  3122. get: function () {
  3123. return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
  3124. },
  3125. enumerable: true,
  3126. configurable: true
  3127. });
  3128. Object.defineProperty(Slider.prototype, "thumbWidth", {
  3129. get: function () {
  3130. return this._thumbWidth.toString(this._host);
  3131. },
  3132. set: function (value) {
  3133. if (this._thumbWidth.toString(this._host) === value) {
  3134. return;
  3135. }
  3136. if (this._thumbWidth.fromString(value)) {
  3137. this._markAsDirty();
  3138. }
  3139. },
  3140. enumerable: true,
  3141. configurable: true
  3142. });
  3143. Object.defineProperty(Slider.prototype, "thumbWidthInPixels", {
  3144. get: function () {
  3145. return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  3146. },
  3147. enumerable: true,
  3148. configurable: true
  3149. });
  3150. Object.defineProperty(Slider.prototype, "minimum", {
  3151. get: function () {
  3152. return this._minimum;
  3153. },
  3154. set: function (value) {
  3155. if (this._minimum === value) {
  3156. return;
  3157. }
  3158. this._minimum = value;
  3159. this._markAsDirty();
  3160. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  3161. },
  3162. enumerable: true,
  3163. configurable: true
  3164. });
  3165. Object.defineProperty(Slider.prototype, "maximum", {
  3166. get: function () {
  3167. return this._maximum;
  3168. },
  3169. set: function (value) {
  3170. if (this._maximum === value) {
  3171. return;
  3172. }
  3173. this._maximum = value;
  3174. this._markAsDirty();
  3175. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  3176. },
  3177. enumerable: true,
  3178. configurable: true
  3179. });
  3180. Object.defineProperty(Slider.prototype, "value", {
  3181. get: function () {
  3182. return this._value;
  3183. },
  3184. set: function (value) {
  3185. value = Math.max(Math.min(value, this._maximum), this._minimum);
  3186. if (this._value === value) {
  3187. return;
  3188. }
  3189. this._value = value;
  3190. this._markAsDirty();
  3191. this.onValueChangedObservable.notifyObservers(this._value);
  3192. },
  3193. enumerable: true,
  3194. configurable: true
  3195. });
  3196. Object.defineProperty(Slider.prototype, "isThumbCircle", {
  3197. get: function () {
  3198. return this._isThumbCircle;
  3199. },
  3200. set: function (value) {
  3201. if (this._isThumbCircle === value) {
  3202. return;
  3203. }
  3204. this._isThumbCircle = value;
  3205. this._markAsDirty();
  3206. },
  3207. enumerable: true,
  3208. configurable: true
  3209. });
  3210. Object.defineProperty(Slider.prototype, "isThumbClamped", {
  3211. get: function () {
  3212. return this._isThumbClamped;
  3213. },
  3214. set: function (value) {
  3215. if (this._isThumbClamped === value) {
  3216. return;
  3217. }
  3218. this._isThumbClamped = value;
  3219. this._markAsDirty();
  3220. },
  3221. enumerable: true,
  3222. configurable: true
  3223. });
  3224. Slider.prototype._getTypeName = function () {
  3225. return "Slider";
  3226. };
  3227. Slider.prototype._draw = function (parentMeasure, context) {
  3228. context.save();
  3229. this._applyStates(context);
  3230. if (this._processMeasures(parentMeasure, context)) {
  3231. // Main bar
  3232. var effectiveThumbWidth;
  3233. var effectiveBarOffset;
  3234. if (this._thumbWidth.isPixel) {
  3235. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.width);
  3236. }
  3237. else {
  3238. effectiveThumbWidth = this._currentMeasure.width * this._thumbWidth.getValue(this._host);
  3239. }
  3240. if (this._barOffset.isPixel) {
  3241. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  3242. }
  3243. else {
  3244. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  3245. }
  3246. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3247. context.shadowColor = this.shadowColor;
  3248. context.shadowBlur = this.shadowBlur;
  3249. context.shadowOffsetX = this.shadowOffsetX;
  3250. context.shadowOffsetY = this.shadowOffsetY;
  3251. }
  3252. var left = this._currentMeasure.left;
  3253. var width = this._currentMeasure.width - effectiveThumbWidth;
  3254. var thumbPosition = ((this._value - this._minimum) / (this._maximum - this._minimum)) * width;
  3255. context.fillStyle = this._background;
  3256. if (this.isThumbClamped) {
  3257. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width + effectiveThumbWidth, this._currentMeasure.height - effectiveBarOffset * 2);
  3258. }
  3259. else {
  3260. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  3261. }
  3262. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3263. context.shadowBlur = 0;
  3264. context.shadowOffsetX = 0;
  3265. context.shadowOffsetY = 0;
  3266. }
  3267. context.fillStyle = this.color;
  3268. if (this.isThumbClamped) {
  3269. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3270. }
  3271. else {
  3272. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3273. }
  3274. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3275. context.shadowColor = this.shadowColor;
  3276. context.shadowBlur = this.shadowBlur;
  3277. context.shadowOffsetX = this.shadowOffsetX;
  3278. context.shadowOffsetY = this.shadowOffsetY;
  3279. }
  3280. if (this._isThumbCircle) {
  3281. context.beginPath();
  3282. context.arc(left + thumbPosition + (effectiveThumbWidth / 2), this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
  3283. context.fill();
  3284. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3285. context.shadowBlur = 0;
  3286. context.shadowOffsetX = 0;
  3287. context.shadowOffsetY = 0;
  3288. }
  3289. context.strokeStyle = this._borderColor;
  3290. context.stroke();
  3291. }
  3292. else {
  3293. context.fillRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3294. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3295. context.shadowBlur = 0;
  3296. context.shadowOffsetX = 0;
  3297. context.shadowOffsetY = 0;
  3298. }
  3299. context.strokeStyle = this._borderColor;
  3300. context.strokeRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3301. }
  3302. }
  3303. context.restore();
  3304. };
  3305. Slider.prototype._updateValueFromPointer = function (x, y) {
  3306. if (this.rotation != 0) {
  3307. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  3308. x = this._transformedPosition.x;
  3309. }
  3310. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  3311. };
  3312. Slider.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3313. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3314. return false;
  3315. }
  3316. this._pointerIsDown = true;
  3317. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3318. this._host._capturingControl[pointerId] = this;
  3319. return true;
  3320. };
  3321. Slider.prototype._onPointerMove = function (target, coordinates) {
  3322. if (this._pointerIsDown) {
  3323. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3324. }
  3325. _super.prototype._onPointerMove.call(this, target, coordinates);
  3326. };
  3327. Slider.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  3328. this._pointerIsDown = false;
  3329. delete this._host._capturingControl[pointerId];
  3330. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  3331. };
  3332. return Slider;
  3333. }(GUI.Control));
  3334. GUI.Slider = Slider;
  3335. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3336. })(BABYLON || (BABYLON = {}));
  3337. //# sourceMappingURL=slider.js.map
  3338. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3339. var BABYLON;
  3340. (function (BABYLON) {
  3341. var GUI;
  3342. (function (GUI) {
  3343. var Checkbox = /** @class */ (function (_super) {
  3344. __extends(Checkbox, _super);
  3345. function Checkbox(name) {
  3346. var _this = _super.call(this, name) || this;
  3347. _this.name = name;
  3348. _this._isChecked = false;
  3349. _this._background = "black";
  3350. _this._checkSizeRatio = 0.8;
  3351. _this._thickness = 1;
  3352. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  3353. _this.isPointerBlocker = true;
  3354. return _this;
  3355. }
  3356. Object.defineProperty(Checkbox.prototype, "thickness", {
  3357. get: function () {
  3358. return this._thickness;
  3359. },
  3360. set: function (value) {
  3361. if (this._thickness === value) {
  3362. return;
  3363. }
  3364. this._thickness = value;
  3365. this._markAsDirty();
  3366. },
  3367. enumerable: true,
  3368. configurable: true
  3369. });
  3370. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  3371. get: function () {
  3372. return this._checkSizeRatio;
  3373. },
  3374. set: function (value) {
  3375. value = Math.max(Math.min(1, value), 0);
  3376. if (this._checkSizeRatio === value) {
  3377. return;
  3378. }
  3379. this._checkSizeRatio = value;
  3380. this._markAsDirty();
  3381. },
  3382. enumerable: true,
  3383. configurable: true
  3384. });
  3385. Object.defineProperty(Checkbox.prototype, "background", {
  3386. get: function () {
  3387. return this._background;
  3388. },
  3389. set: function (value) {
  3390. if (this._background === value) {
  3391. return;
  3392. }
  3393. this._background = value;
  3394. this._markAsDirty();
  3395. },
  3396. enumerable: true,
  3397. configurable: true
  3398. });
  3399. Object.defineProperty(Checkbox.prototype, "isChecked", {
  3400. get: function () {
  3401. return this._isChecked;
  3402. },
  3403. set: function (value) {
  3404. if (this._isChecked === value) {
  3405. return;
  3406. }
  3407. this._isChecked = value;
  3408. this._markAsDirty();
  3409. this.onIsCheckedChangedObservable.notifyObservers(value);
  3410. },
  3411. enumerable: true,
  3412. configurable: true
  3413. });
  3414. Checkbox.prototype._getTypeName = function () {
  3415. return "CheckBox";
  3416. };
  3417. Checkbox.prototype._draw = function (parentMeasure, context) {
  3418. context.save();
  3419. this._applyStates(context);
  3420. if (this._processMeasures(parentMeasure, context)) {
  3421. var actualWidth = this._currentMeasure.width - this._thickness;
  3422. var actualHeight = this._currentMeasure.height - this._thickness;
  3423. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3424. context.shadowColor = this.shadowColor;
  3425. context.shadowBlur = this.shadowBlur;
  3426. context.shadowOffsetX = this.shadowOffsetX;
  3427. context.shadowOffsetY = this.shadowOffsetY;
  3428. }
  3429. context.fillStyle = this._background;
  3430. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  3431. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3432. context.shadowBlur = 0;
  3433. context.shadowOffsetX = 0;
  3434. context.shadowOffsetY = 0;
  3435. }
  3436. if (this._isChecked) {
  3437. context.fillStyle = this.color;
  3438. var offsetWidth = actualWidth * this._checkSizeRatio;
  3439. var offseHeight = actualHeight * this._checkSizeRatio;
  3440. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  3441. }
  3442. context.strokeStyle = this.color;
  3443. context.lineWidth = this._thickness;
  3444. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  3445. }
  3446. context.restore();
  3447. };
  3448. // Events
  3449. Checkbox.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3450. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3451. return false;
  3452. }
  3453. this.isChecked = !this.isChecked;
  3454. return true;
  3455. };
  3456. return Checkbox;
  3457. }(GUI.Control));
  3458. GUI.Checkbox = Checkbox;
  3459. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3460. })(BABYLON || (BABYLON = {}));
  3461. //# sourceMappingURL=checkbox.js.map
  3462. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3463. var BABYLON;
  3464. (function (BABYLON) {
  3465. var GUI;
  3466. (function (GUI) {
  3467. var RadioButton = /** @class */ (function (_super) {
  3468. __extends(RadioButton, _super);
  3469. function RadioButton(name) {
  3470. var _this = _super.call(this, name) || this;
  3471. _this.name = name;
  3472. _this._isChecked = false;
  3473. _this._background = "black";
  3474. _this._checkSizeRatio = 0.8;
  3475. _this._thickness = 1;
  3476. _this.group = "";
  3477. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  3478. _this.isPointerBlocker = true;
  3479. return _this;
  3480. }
  3481. Object.defineProperty(RadioButton.prototype, "thickness", {
  3482. get: function () {
  3483. return this._thickness;
  3484. },
  3485. set: function (value) {
  3486. if (this._thickness === value) {
  3487. return;
  3488. }
  3489. this._thickness = value;
  3490. this._markAsDirty();
  3491. },
  3492. enumerable: true,
  3493. configurable: true
  3494. });
  3495. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  3496. get: function () {
  3497. return this._checkSizeRatio;
  3498. },
  3499. set: function (value) {
  3500. value = Math.max(Math.min(1, value), 0);
  3501. if (this._checkSizeRatio === value) {
  3502. return;
  3503. }
  3504. this._checkSizeRatio = value;
  3505. this._markAsDirty();
  3506. },
  3507. enumerable: true,
  3508. configurable: true
  3509. });
  3510. Object.defineProperty(RadioButton.prototype, "background", {
  3511. get: function () {
  3512. return this._background;
  3513. },
  3514. set: function (value) {
  3515. if (this._background === value) {
  3516. return;
  3517. }
  3518. this._background = value;
  3519. this._markAsDirty();
  3520. },
  3521. enumerable: true,
  3522. configurable: true
  3523. });
  3524. Object.defineProperty(RadioButton.prototype, "isChecked", {
  3525. get: function () {
  3526. return this._isChecked;
  3527. },
  3528. set: function (value) {
  3529. var _this = this;
  3530. if (this._isChecked === value) {
  3531. return;
  3532. }
  3533. this._isChecked = value;
  3534. this._markAsDirty();
  3535. this.onIsCheckedChangedObservable.notifyObservers(value);
  3536. if (this._isChecked) {
  3537. // Update all controls from same group
  3538. this._host.executeOnAllControls(function (control) {
  3539. if (control === _this) {
  3540. return;
  3541. }
  3542. if (control.group === undefined) {
  3543. return;
  3544. }
  3545. var childRadio = control;
  3546. if (childRadio.group === _this.group) {
  3547. childRadio.isChecked = false;
  3548. }
  3549. });
  3550. }
  3551. },
  3552. enumerable: true,
  3553. configurable: true
  3554. });
  3555. RadioButton.prototype._getTypeName = function () {
  3556. return "RadioButton";
  3557. };
  3558. RadioButton.prototype._draw = function (parentMeasure, context) {
  3559. context.save();
  3560. this._applyStates(context);
  3561. if (this._processMeasures(parentMeasure, context)) {
  3562. var actualWidth = this._currentMeasure.width - this._thickness;
  3563. var actualHeight = this._currentMeasure.height - this._thickness;
  3564. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3565. context.shadowColor = this.shadowColor;
  3566. context.shadowBlur = this.shadowBlur;
  3567. context.shadowOffsetX = this.shadowOffsetX;
  3568. context.shadowOffsetY = this.shadowOffsetY;
  3569. }
  3570. // Outer
  3571. 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);
  3572. context.fillStyle = this._background;
  3573. context.fill();
  3574. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3575. context.shadowBlur = 0;
  3576. context.shadowOffsetX = 0;
  3577. context.shadowOffsetY = 0;
  3578. }
  3579. context.strokeStyle = this.color;
  3580. context.lineWidth = this._thickness;
  3581. context.stroke();
  3582. // Inner
  3583. if (this._isChecked) {
  3584. context.fillStyle = this.color;
  3585. var offsetWidth = actualWidth * this._checkSizeRatio;
  3586. var offseHeight = actualHeight * this._checkSizeRatio;
  3587. 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);
  3588. context.fill();
  3589. }
  3590. }
  3591. context.restore();
  3592. };
  3593. // Events
  3594. RadioButton.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3595. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3596. return false;
  3597. }
  3598. if (!this.isChecked) {
  3599. this.isChecked = true;
  3600. }
  3601. return true;
  3602. };
  3603. return RadioButton;
  3604. }(GUI.Control));
  3605. GUI.RadioButton = RadioButton;
  3606. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3607. })(BABYLON || (BABYLON = {}));
  3608. //# sourceMappingURL=radioButton.js.map
  3609. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3610. var BABYLON;
  3611. (function (BABYLON) {
  3612. var GUI;
  3613. (function (GUI) {
  3614. var TextBlock = /** @class */ (function (_super) {
  3615. __extends(TextBlock, _super);
  3616. /**
  3617. * Creates a new TextBlock object
  3618. * @param name defines the name of the control
  3619. * @param text defines the text to display (emptry string by default)
  3620. */
  3621. function TextBlock(
  3622. /**
  3623. * Defines the name of the control
  3624. */
  3625. name, text) {
  3626. if (text === void 0) { text = ""; }
  3627. var _this = _super.call(this, name) || this;
  3628. _this.name = name;
  3629. _this._text = "";
  3630. _this._textWrapping = false;
  3631. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  3632. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  3633. _this._resizeToFit = false;
  3634. _this._lineSpacing = new GUI.ValueAndUnit(0);
  3635. _this._outlineWidth = 0;
  3636. _this._outlineColor = "white";
  3637. /**
  3638. * An event triggered after the text is changed
  3639. */
  3640. _this.onTextChangedObservable = new BABYLON.Observable();
  3641. /**
  3642. * An event triggered after the text was broken up into lines
  3643. */
  3644. _this.onLinesReadyObservable = new BABYLON.Observable();
  3645. _this.text = text;
  3646. return _this;
  3647. }
  3648. Object.defineProperty(TextBlock.prototype, "lines", {
  3649. /**
  3650. * Return the line list (you may need to use the onLinesReadyObservable to make sure the list is ready)
  3651. */
  3652. get: function () {
  3653. return this._lines;
  3654. },
  3655. enumerable: true,
  3656. configurable: true
  3657. });
  3658. Object.defineProperty(TextBlock.prototype, "resizeToFit", {
  3659. /**
  3660. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  3661. */
  3662. get: function () {
  3663. return this._resizeToFit;
  3664. },
  3665. /**
  3666. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  3667. */
  3668. set: function (value) {
  3669. this._resizeToFit = value;
  3670. if (this._resizeToFit) {
  3671. this._width.ignoreAdaptiveScaling = true;
  3672. this._height.ignoreAdaptiveScaling = true;
  3673. }
  3674. },
  3675. enumerable: true,
  3676. configurable: true
  3677. });
  3678. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  3679. /**
  3680. * Gets or sets a boolean indicating if text must be wrapped
  3681. */
  3682. get: function () {
  3683. return this._textWrapping;
  3684. },
  3685. /**
  3686. * Gets or sets a boolean indicating if text must be wrapped
  3687. */
  3688. set: function (value) {
  3689. if (this._textWrapping === value) {
  3690. return;
  3691. }
  3692. this._textWrapping = value;
  3693. this._markAsDirty();
  3694. },
  3695. enumerable: true,
  3696. configurable: true
  3697. });
  3698. Object.defineProperty(TextBlock.prototype, "text", {
  3699. /**
  3700. * Gets or sets text to display
  3701. */
  3702. get: function () {
  3703. return this._text;
  3704. },
  3705. /**
  3706. * Gets or sets text to display
  3707. */
  3708. set: function (value) {
  3709. if (this._text === value) {
  3710. return;
  3711. }
  3712. this._text = value;
  3713. this._markAsDirty();
  3714. this.onTextChangedObservable.notifyObservers(this);
  3715. },
  3716. enumerable: true,
  3717. configurable: true
  3718. });
  3719. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  3720. /**
  3721. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  3722. */
  3723. get: function () {
  3724. return this._textHorizontalAlignment;
  3725. },
  3726. /**
  3727. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  3728. */
  3729. set: function (value) {
  3730. if (this._textHorizontalAlignment === value) {
  3731. return;
  3732. }
  3733. this._textHorizontalAlignment = value;
  3734. this._markAsDirty();
  3735. },
  3736. enumerable: true,
  3737. configurable: true
  3738. });
  3739. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  3740. /**
  3741. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  3742. */
  3743. get: function () {
  3744. return this._textVerticalAlignment;
  3745. },
  3746. /**
  3747. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  3748. */
  3749. set: function (value) {
  3750. if (this._textVerticalAlignment === value) {
  3751. return;
  3752. }
  3753. this._textVerticalAlignment = value;
  3754. this._markAsDirty();
  3755. },
  3756. enumerable: true,
  3757. configurable: true
  3758. });
  3759. Object.defineProperty(TextBlock.prototype, "lineSpacing", {
  3760. /**
  3761. * Gets or sets line spacing value
  3762. */
  3763. get: function () {
  3764. return this._lineSpacing.toString(this._host);
  3765. },
  3766. /**
  3767. * Gets or sets line spacing value
  3768. */
  3769. set: function (value) {
  3770. if (this._lineSpacing.fromString(value)) {
  3771. this._markAsDirty();
  3772. }
  3773. },
  3774. enumerable: true,
  3775. configurable: true
  3776. });
  3777. Object.defineProperty(TextBlock.prototype, "outlineWidth", {
  3778. /**
  3779. * Gets or sets outlineWidth of the text to display
  3780. */
  3781. get: function () {
  3782. return this._outlineWidth;
  3783. },
  3784. /**
  3785. * Gets or sets outlineWidth of the text to display
  3786. */
  3787. set: function (value) {
  3788. if (this._outlineWidth === value) {
  3789. return;
  3790. }
  3791. this._outlineWidth = value;
  3792. this._markAsDirty();
  3793. },
  3794. enumerable: true,
  3795. configurable: true
  3796. });
  3797. Object.defineProperty(TextBlock.prototype, "outlineColor", {
  3798. /**
  3799. * Gets or sets outlineColor of the text to display
  3800. */
  3801. get: function () {
  3802. return this._outlineColor;
  3803. },
  3804. /**
  3805. * Gets or sets outlineColor of the text to display
  3806. */
  3807. set: function (value) {
  3808. if (this._outlineColor === value) {
  3809. return;
  3810. }
  3811. this._outlineColor = value;
  3812. this._markAsDirty();
  3813. },
  3814. enumerable: true,
  3815. configurable: true
  3816. });
  3817. TextBlock.prototype._getTypeName = function () {
  3818. return "TextBlock";
  3819. };
  3820. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  3821. var width = this._currentMeasure.width;
  3822. var x = 0;
  3823. switch (this._textHorizontalAlignment) {
  3824. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  3825. x = 0;
  3826. break;
  3827. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  3828. x = width - textWidth;
  3829. break;
  3830. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  3831. x = (width - textWidth) / 2;
  3832. break;
  3833. }
  3834. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3835. context.shadowColor = this.shadowColor;
  3836. context.shadowBlur = this.shadowBlur;
  3837. context.shadowOffsetX = this.shadowOffsetX;
  3838. context.shadowOffsetY = this.shadowOffsetY;
  3839. }
  3840. if (this.outlineWidth) {
  3841. context.strokeText(text, this._currentMeasure.left + x, y);
  3842. }
  3843. context.fillText(text, this._currentMeasure.left + x, y);
  3844. };
  3845. /** @hidden */
  3846. TextBlock.prototype._draw = function (parentMeasure, context) {
  3847. context.save();
  3848. this._applyStates(context);
  3849. if (this._processMeasures(parentMeasure, context)) {
  3850. // Render lines
  3851. this._renderLines(context);
  3852. }
  3853. context.restore();
  3854. };
  3855. TextBlock.prototype._applyStates = function (context) {
  3856. _super.prototype._applyStates.call(this, context);
  3857. if (this.outlineWidth) {
  3858. context.lineWidth = this.outlineWidth;
  3859. context.strokeStyle = this.outlineColor;
  3860. }
  3861. };
  3862. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  3863. this._lines = [];
  3864. var _lines = this.text.split("\n");
  3865. if (this._textWrapping && !this._resizeToFit) {
  3866. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  3867. var _line = _lines_1[_i];
  3868. this._lines.push(this._parseLineWithTextWrapping(_line, context));
  3869. }
  3870. }
  3871. else {
  3872. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  3873. var _line = _lines_2[_a];
  3874. this._lines.push(this._parseLine(_line, context));
  3875. }
  3876. }
  3877. this.onLinesReadyObservable.notifyObservers(this);
  3878. };
  3879. TextBlock.prototype._parseLine = function (line, context) {
  3880. if (line === void 0) { line = ''; }
  3881. return { text: line, width: context.measureText(line).width };
  3882. };
  3883. TextBlock.prototype._parseLineWithTextWrapping = function (line, context) {
  3884. if (line === void 0) { line = ''; }
  3885. var words = line.split(' ');
  3886. var width = this._currentMeasure.width;
  3887. var lineWidth = 0;
  3888. for (var n = 0; n < words.length; n++) {
  3889. var testLine = n > 0 ? line + " " + words[n] : words[0];
  3890. var metrics = context.measureText(testLine);
  3891. var testWidth = metrics.width;
  3892. if (testWidth > width && n > 0) {
  3893. this._lines.push({ text: line, width: lineWidth });
  3894. line = words[n];
  3895. lineWidth = context.measureText(line).width;
  3896. }
  3897. else {
  3898. lineWidth = testWidth;
  3899. line = testLine;
  3900. }
  3901. }
  3902. return { text: line, width: lineWidth };
  3903. };
  3904. TextBlock.prototype._renderLines = function (context) {
  3905. var height = this._currentMeasure.height;
  3906. if (!this._fontOffset) {
  3907. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  3908. }
  3909. var rootY = 0;
  3910. switch (this._textVerticalAlignment) {
  3911. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  3912. rootY = this._fontOffset.ascent;
  3913. break;
  3914. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  3915. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  3916. break;
  3917. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  3918. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  3919. break;
  3920. }
  3921. rootY += this._currentMeasure.top;
  3922. var maxLineWidth = 0;
  3923. for (var i = 0; i < this._lines.length; i++) {
  3924. var line = this._lines[i];
  3925. if (i !== 0 && this._lineSpacing.internalValue !== 0) {
  3926. if (this._lineSpacing.isPixel) {
  3927. rootY += this._lineSpacing.getValue(this._host);
  3928. }
  3929. else {
  3930. rootY = rootY + (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
  3931. }
  3932. }
  3933. this._drawText(line.text, line.width, rootY, context);
  3934. rootY += this._fontOffset.height;
  3935. if (line.width > maxLineWidth)
  3936. maxLineWidth = line.width;
  3937. }
  3938. if (this._resizeToFit) {
  3939. this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
  3940. this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
  3941. }
  3942. };
  3943. TextBlock.prototype.dispose = function () {
  3944. _super.prototype.dispose.call(this);
  3945. this.onTextChangedObservable.clear();
  3946. };
  3947. return TextBlock;
  3948. }(GUI.Control));
  3949. GUI.TextBlock = TextBlock;
  3950. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3951. })(BABYLON || (BABYLON = {}));
  3952. //# sourceMappingURL=textBlock.js.map
  3953. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3954. var DOMImage = Image;
  3955. var BABYLON;
  3956. (function (BABYLON) {
  3957. var GUI;
  3958. (function (GUI) {
  3959. var Image = /** @class */ (function (_super) {
  3960. __extends(Image, _super);
  3961. function Image(name, url) {
  3962. if (url === void 0) { url = null; }
  3963. var _this = _super.call(this, name) || this;
  3964. _this.name = name;
  3965. _this._loaded = false;
  3966. _this._stretch = Image.STRETCH_FILL;
  3967. _this._autoScale = false;
  3968. _this._sourceLeft = 0;
  3969. _this._sourceTop = 0;
  3970. _this._sourceWidth = 0;
  3971. _this._sourceHeight = 0;
  3972. _this._cellWidth = 0;
  3973. _this._cellHeight = 0;
  3974. _this._cellId = -1;
  3975. _this.source = url;
  3976. return _this;
  3977. }
  3978. Object.defineProperty(Image.prototype, "sourceLeft", {
  3979. get: function () {
  3980. return this._sourceLeft;
  3981. },
  3982. set: function (value) {
  3983. if (this._sourceLeft === value) {
  3984. return;
  3985. }
  3986. this._sourceLeft = value;
  3987. this._markAsDirty();
  3988. },
  3989. enumerable: true,
  3990. configurable: true
  3991. });
  3992. Object.defineProperty(Image.prototype, "sourceTop", {
  3993. get: function () {
  3994. return this._sourceTop;
  3995. },
  3996. set: function (value) {
  3997. if (this._sourceTop === value) {
  3998. return;
  3999. }
  4000. this._sourceTop = value;
  4001. this._markAsDirty();
  4002. },
  4003. enumerable: true,
  4004. configurable: true
  4005. });
  4006. Object.defineProperty(Image.prototype, "sourceWidth", {
  4007. get: function () {
  4008. return this._sourceWidth;
  4009. },
  4010. set: function (value) {
  4011. if (this._sourceWidth === value) {
  4012. return;
  4013. }
  4014. this._sourceWidth = value;
  4015. this._markAsDirty();
  4016. },
  4017. enumerable: true,
  4018. configurable: true
  4019. });
  4020. Object.defineProperty(Image.prototype, "sourceHeight", {
  4021. get: function () {
  4022. return this._sourceHeight;
  4023. },
  4024. set: function (value) {
  4025. if (this._sourceHeight === value) {
  4026. return;
  4027. }
  4028. this._sourceHeight = value;
  4029. this._markAsDirty();
  4030. },
  4031. enumerable: true,
  4032. configurable: true
  4033. });
  4034. Object.defineProperty(Image.prototype, "autoScale", {
  4035. get: function () {
  4036. return this._autoScale;
  4037. },
  4038. set: function (value) {
  4039. if (this._autoScale === value) {
  4040. return;
  4041. }
  4042. this._autoScale = value;
  4043. if (value && this._loaded) {
  4044. this.synchronizeSizeWithContent();
  4045. }
  4046. },
  4047. enumerable: true,
  4048. configurable: true
  4049. });
  4050. Object.defineProperty(Image.prototype, "stretch", {
  4051. get: function () {
  4052. return this._stretch;
  4053. },
  4054. set: function (value) {
  4055. if (this._stretch === value) {
  4056. return;
  4057. }
  4058. this._stretch = value;
  4059. this._markAsDirty();
  4060. },
  4061. enumerable: true,
  4062. configurable: true
  4063. });
  4064. Object.defineProperty(Image.prototype, "domImage", {
  4065. get: function () {
  4066. return this._domImage;
  4067. },
  4068. set: function (value) {
  4069. var _this = this;
  4070. this._domImage = value;
  4071. this._loaded = false;
  4072. if (this._domImage.width) {
  4073. this._onImageLoaded();
  4074. }
  4075. else {
  4076. this._domImage.onload = function () {
  4077. _this._onImageLoaded();
  4078. };
  4079. }
  4080. },
  4081. enumerable: true,
  4082. configurable: true
  4083. });
  4084. Image.prototype._onImageLoaded = function () {
  4085. this._imageWidth = this._domImage.width;
  4086. this._imageHeight = this._domImage.height;
  4087. this._loaded = true;
  4088. if (this._autoScale) {
  4089. this.synchronizeSizeWithContent();
  4090. }
  4091. this._markAsDirty();
  4092. };
  4093. Object.defineProperty(Image.prototype, "source", {
  4094. set: function (value) {
  4095. var _this = this;
  4096. if (this._source === value) {
  4097. return;
  4098. }
  4099. this._loaded = false;
  4100. this._source = value;
  4101. this._domImage = new DOMImage();
  4102. this._domImage.onload = function () {
  4103. _this._onImageLoaded();
  4104. };
  4105. if (value) {
  4106. BABYLON.Tools.SetCorsBehavior(value, this._domImage);
  4107. this._domImage.src = value;
  4108. }
  4109. },
  4110. enumerable: true,
  4111. configurable: true
  4112. });
  4113. Object.defineProperty(Image.prototype, "cellWidth", {
  4114. get: function () {
  4115. return this._cellWidth;
  4116. },
  4117. set: function (value) {
  4118. if (this._cellWidth === value) {
  4119. return;
  4120. }
  4121. this._cellWidth = value;
  4122. this._markAsDirty();
  4123. },
  4124. enumerable: true,
  4125. configurable: true
  4126. });
  4127. Object.defineProperty(Image.prototype, "cellHeight", {
  4128. get: function () {
  4129. return this._cellHeight;
  4130. },
  4131. set: function (value) {
  4132. if (this._cellHeight === value) {
  4133. return;
  4134. }
  4135. this._cellHeight = value;
  4136. this._markAsDirty();
  4137. },
  4138. enumerable: true,
  4139. configurable: true
  4140. });
  4141. Object.defineProperty(Image.prototype, "cellId", {
  4142. get: function () {
  4143. return this._cellId;
  4144. },
  4145. set: function (value) {
  4146. if (this._cellId === value) {
  4147. return;
  4148. }
  4149. this._cellId = value;
  4150. this._markAsDirty();
  4151. },
  4152. enumerable: true,
  4153. configurable: true
  4154. });
  4155. Image.prototype._getTypeName = function () {
  4156. return "Image";
  4157. };
  4158. Image.prototype.synchronizeSizeWithContent = function () {
  4159. if (!this._loaded) {
  4160. return;
  4161. }
  4162. this.width = this._domImage.width + "px";
  4163. this.height = this._domImage.height + "px";
  4164. };
  4165. Image.prototype._draw = function (parentMeasure, context) {
  4166. context.save();
  4167. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4168. context.shadowColor = this.shadowColor;
  4169. context.shadowBlur = this.shadowBlur;
  4170. context.shadowOffsetX = this.shadowOffsetX;
  4171. context.shadowOffsetY = this.shadowOffsetY;
  4172. }
  4173. var x, y, width, height;
  4174. if (this.cellId == -1) {
  4175. x = this._sourceLeft;
  4176. y = this._sourceTop;
  4177. width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  4178. height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  4179. }
  4180. else {
  4181. var rowCount = this._domImage.naturalWidth / this.cellWidth;
  4182. var column = (this.cellId / rowCount) >> 0;
  4183. var row = this.cellId % rowCount;
  4184. x = this.cellWidth * row;
  4185. y = this.cellHeight * column;
  4186. width = this.cellWidth;
  4187. height = this.cellHeight;
  4188. }
  4189. this._applyStates(context);
  4190. if (this._processMeasures(parentMeasure, context)) {
  4191. if (this._loaded) {
  4192. switch (this._stretch) {
  4193. case Image.STRETCH_NONE:
  4194. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4195. break;
  4196. case Image.STRETCH_FILL:
  4197. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4198. break;
  4199. case Image.STRETCH_UNIFORM:
  4200. var hRatio = this._currentMeasure.width / width;
  4201. var vRatio = this._currentMeasure.height / height;
  4202. var ratio = Math.min(hRatio, vRatio);
  4203. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  4204. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  4205. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  4206. break;
  4207. case Image.STRETCH_EXTEND:
  4208. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4209. if (this._autoScale) {
  4210. this.synchronizeSizeWithContent();
  4211. }
  4212. if (this._root && this._root.parent) { // Will update root size if root is not the top root
  4213. this._root.width = this.width;
  4214. this._root.height = this.height;
  4215. }
  4216. break;
  4217. }
  4218. }
  4219. }
  4220. context.restore();
  4221. };
  4222. Object.defineProperty(Image, "STRETCH_NONE", {
  4223. get: function () {
  4224. return Image._STRETCH_NONE;
  4225. },
  4226. enumerable: true,
  4227. configurable: true
  4228. });
  4229. Object.defineProperty(Image, "STRETCH_FILL", {
  4230. get: function () {
  4231. return Image._STRETCH_FILL;
  4232. },
  4233. enumerable: true,
  4234. configurable: true
  4235. });
  4236. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  4237. get: function () {
  4238. return Image._STRETCH_UNIFORM;
  4239. },
  4240. enumerable: true,
  4241. configurable: true
  4242. });
  4243. Object.defineProperty(Image, "STRETCH_EXTEND", {
  4244. get: function () {
  4245. return Image._STRETCH_EXTEND;
  4246. },
  4247. enumerable: true,
  4248. configurable: true
  4249. });
  4250. // Static
  4251. Image._STRETCH_NONE = 0;
  4252. Image._STRETCH_FILL = 1;
  4253. Image._STRETCH_UNIFORM = 2;
  4254. Image._STRETCH_EXTEND = 3;
  4255. return Image;
  4256. }(GUI.Control));
  4257. GUI.Image = Image;
  4258. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4259. })(BABYLON || (BABYLON = {}));
  4260. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4261. var BABYLON;
  4262. (function (BABYLON) {
  4263. var GUI;
  4264. (function (GUI) {
  4265. var Button = /** @class */ (function (_super) {
  4266. __extends(Button, _super);
  4267. function Button(name) {
  4268. var _this = _super.call(this, name) || this;
  4269. _this.name = name;
  4270. _this.thickness = 1;
  4271. _this.isPointerBlocker = true;
  4272. _this.pointerEnterAnimation = function () {
  4273. _this.alpha -= 0.1;
  4274. };
  4275. _this.pointerOutAnimation = function () {
  4276. _this.alpha += 0.1;
  4277. };
  4278. _this.pointerDownAnimation = function () {
  4279. _this.scaleX -= 0.05;
  4280. _this.scaleY -= 0.05;
  4281. };
  4282. _this.pointerUpAnimation = function () {
  4283. _this.scaleX += 0.05;
  4284. _this.scaleY += 0.05;
  4285. };
  4286. return _this;
  4287. }
  4288. Button.prototype._getTypeName = function () {
  4289. return "Button";
  4290. };
  4291. // While being a container, the button behaves like a control.
  4292. Button.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  4293. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  4294. return false;
  4295. }
  4296. if (!_super.prototype.contains.call(this, x, y)) {
  4297. return false;
  4298. }
  4299. this._processObservables(type, x, y, pointerId, buttonIndex);
  4300. return true;
  4301. };
  4302. Button.prototype._onPointerEnter = function (target) {
  4303. if (!_super.prototype._onPointerEnter.call(this, target)) {
  4304. return false;
  4305. }
  4306. if (this.pointerEnterAnimation) {
  4307. this.pointerEnterAnimation();
  4308. }
  4309. return true;
  4310. };
  4311. Button.prototype._onPointerOut = function (target) {
  4312. if (this.pointerOutAnimation) {
  4313. this.pointerOutAnimation();
  4314. }
  4315. _super.prototype._onPointerOut.call(this, target);
  4316. };
  4317. Button.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4318. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4319. return false;
  4320. }
  4321. if (this.pointerDownAnimation) {
  4322. this.pointerDownAnimation();
  4323. }
  4324. return true;
  4325. };
  4326. Button.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  4327. if (this.pointerUpAnimation) {
  4328. this.pointerUpAnimation();
  4329. }
  4330. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  4331. };
  4332. // Statics
  4333. Button.CreateImageButton = function (name, text, imageUrl) {
  4334. var result = new Button(name);
  4335. // Adding text
  4336. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  4337. textBlock.textWrapping = true;
  4338. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4339. textBlock.paddingLeft = "20%";
  4340. result.addControl(textBlock);
  4341. // Adding image
  4342. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  4343. iconImage.width = "20%";
  4344. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  4345. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  4346. result.addControl(iconImage);
  4347. return result;
  4348. };
  4349. Button.CreateImageOnlyButton = function (name, imageUrl) {
  4350. var result = new Button(name);
  4351. // Adding image
  4352. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  4353. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  4354. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  4355. result.addControl(iconImage);
  4356. return result;
  4357. };
  4358. Button.CreateSimpleButton = function (name, text) {
  4359. var result = new Button(name);
  4360. // Adding text
  4361. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  4362. textBlock.textWrapping = true;
  4363. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4364. result.addControl(textBlock);
  4365. return result;
  4366. };
  4367. Button.CreateImageWithCenterTextButton = function (name, text, imageUrl) {
  4368. var result = new Button(name);
  4369. // Adding image
  4370. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  4371. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  4372. result.addControl(iconImage);
  4373. // Adding text
  4374. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  4375. textBlock.textWrapping = true;
  4376. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4377. result.addControl(textBlock);
  4378. return result;
  4379. };
  4380. return Button;
  4381. }(GUI.Rectangle));
  4382. GUI.Button = Button;
  4383. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4384. })(BABYLON || (BABYLON = {}));
  4385. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4386. var BABYLON;
  4387. (function (BABYLON) {
  4388. var GUI;
  4389. (function (GUI) {
  4390. var ColorPicker = /** @class */ (function (_super) {
  4391. __extends(ColorPicker, _super);
  4392. function ColorPicker(name) {
  4393. var _this = _super.call(this, name) || this;
  4394. _this.name = name;
  4395. _this._value = BABYLON.Color3.Red();
  4396. _this._tmpColor = new BABYLON.Color3();
  4397. _this._pointerStartedOnSquare = false;
  4398. _this._pointerStartedOnWheel = false;
  4399. _this._squareLeft = 0;
  4400. _this._squareTop = 0;
  4401. _this._squareSize = 0;
  4402. _this._h = 360;
  4403. _this._s = 1;
  4404. _this._v = 1;
  4405. _this.onValueChangedObservable = new BABYLON.Observable();
  4406. // Events
  4407. _this._pointerIsDown = false;
  4408. _this.value = new BABYLON.Color3(.88, .1, .1);
  4409. _this.size = "200px";
  4410. _this.isPointerBlocker = true;
  4411. return _this;
  4412. }
  4413. Object.defineProperty(ColorPicker.prototype, "value", {
  4414. get: function () {
  4415. return this._value;
  4416. },
  4417. set: function (value) {
  4418. if (this._value.equals(value)) {
  4419. return;
  4420. }
  4421. this._value.copyFrom(value);
  4422. this._RGBtoHSV(this._value, this._tmpColor);
  4423. this._h = this._tmpColor.r;
  4424. this._s = Math.max(this._tmpColor.g, 0.00001);
  4425. this._v = Math.max(this._tmpColor.b, 0.00001);
  4426. this._markAsDirty();
  4427. this.onValueChangedObservable.notifyObservers(this._value);
  4428. },
  4429. enumerable: true,
  4430. configurable: true
  4431. });
  4432. Object.defineProperty(ColorPicker.prototype, "width", {
  4433. set: function (value) {
  4434. if (this._width.toString(this._host) === value) {
  4435. return;
  4436. }
  4437. if (this._width.fromString(value)) {
  4438. this._height.fromString(value);
  4439. this._markAsDirty();
  4440. }
  4441. },
  4442. enumerable: true,
  4443. configurable: true
  4444. });
  4445. Object.defineProperty(ColorPicker.prototype, "height", {
  4446. set: function (value) {
  4447. if (this._height.toString(this._host) === value) {
  4448. return;
  4449. }
  4450. if (this._height.fromString(value)) {
  4451. this._width.fromString(value);
  4452. this._markAsDirty();
  4453. }
  4454. },
  4455. enumerable: true,
  4456. configurable: true
  4457. });
  4458. Object.defineProperty(ColorPicker.prototype, "size", {
  4459. get: function () {
  4460. return this.width;
  4461. },
  4462. set: function (value) {
  4463. this.width = value;
  4464. },
  4465. enumerable: true,
  4466. configurable: true
  4467. });
  4468. ColorPicker.prototype._getTypeName = function () {
  4469. return "ColorPicker";
  4470. };
  4471. ColorPicker.prototype._updateSquareProps = function () {
  4472. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4473. var wheelThickness = radius * .2;
  4474. var innerDiameter = (radius - wheelThickness) * 2;
  4475. var squareSize = innerDiameter / (Math.sqrt(2));
  4476. var offset = radius - squareSize * .5;
  4477. this._squareLeft = this._currentMeasure.left + offset;
  4478. this._squareTop = this._currentMeasure.top + offset;
  4479. this._squareSize = squareSize;
  4480. };
  4481. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  4482. var lgh = context.createLinearGradient(left, top, width + left, top);
  4483. lgh.addColorStop(0, '#fff');
  4484. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  4485. context.fillStyle = lgh;
  4486. context.fillRect(left, top, width, height);
  4487. var lgv = context.createLinearGradient(left, top, left, height + top);
  4488. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  4489. lgv.addColorStop(1, '#000');
  4490. context.fillStyle = lgv;
  4491. context.fillRect(left, top, width, height);
  4492. };
  4493. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  4494. context.beginPath();
  4495. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  4496. context.lineWidth = 3;
  4497. context.strokeStyle = '#333333';
  4498. context.stroke();
  4499. context.beginPath();
  4500. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  4501. context.lineWidth = 3;
  4502. context.strokeStyle = '#ffffff';
  4503. context.stroke();
  4504. };
  4505. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  4506. var canvas = document.createElement("canvas");
  4507. canvas.width = radius * 2;
  4508. canvas.height = radius * 2;
  4509. var context = canvas.getContext("2d");
  4510. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  4511. var data = image.data;
  4512. var color = this._tmpColor;
  4513. var maxDistSq = radius * radius;
  4514. var innerRadius = radius - thickness;
  4515. var minDistSq = innerRadius * innerRadius;
  4516. for (var x = -radius; x < radius; x++) {
  4517. for (var y = -radius; y < radius; y++) {
  4518. var distSq = x * x + y * y;
  4519. if (distSq > maxDistSq || distSq < minDistSq) {
  4520. continue;
  4521. }
  4522. var dist = Math.sqrt(distSq);
  4523. var ang = Math.atan2(y, x);
  4524. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  4525. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  4526. data[index] = color.r * 255;
  4527. data[index + 1] = color.g * 255;
  4528. data[index + 2] = color.b * 255;
  4529. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  4530. //apply less alpha to bigger color pickers
  4531. var alphaAmount = .2;
  4532. var maxAlpha = .2;
  4533. var minAlpha = .04;
  4534. var lowerRadius = 50;
  4535. var upperRadius = 150;
  4536. if (radius < lowerRadius) {
  4537. alphaAmount = maxAlpha;
  4538. }
  4539. else if (radius > upperRadius) {
  4540. alphaAmount = minAlpha;
  4541. }
  4542. else {
  4543. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  4544. }
  4545. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  4546. if (alphaRatio < alphaAmount) {
  4547. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  4548. }
  4549. else if (alphaRatio > 1 - alphaAmount) {
  4550. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  4551. }
  4552. else {
  4553. data[index + 3] = 255;
  4554. }
  4555. }
  4556. }
  4557. context.putImageData(image, 0, 0);
  4558. return canvas;
  4559. };
  4560. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  4561. var r = color.r;
  4562. var g = color.g;
  4563. var b = color.b;
  4564. var max = Math.max(r, g, b);
  4565. var min = Math.min(r, g, b);
  4566. var h = 0;
  4567. var s = 0;
  4568. var v = max;
  4569. var dm = max - min;
  4570. if (max !== 0) {
  4571. s = dm / max;
  4572. }
  4573. if (max != min) {
  4574. if (max == r) {
  4575. h = (g - b) / dm;
  4576. if (g < b) {
  4577. h += 6;
  4578. }
  4579. }
  4580. else if (max == g) {
  4581. h = (b - r) / dm + 2;
  4582. }
  4583. else if (max == b) {
  4584. h = (r - g) / dm + 4;
  4585. }
  4586. h *= 60;
  4587. }
  4588. result.r = h;
  4589. result.g = s;
  4590. result.b = v;
  4591. };
  4592. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  4593. var chroma = value * saturation;
  4594. var h = hue / 60;
  4595. var x = chroma * (1 - Math.abs((h % 2) - 1));
  4596. var r = 0;
  4597. var g = 0;
  4598. var b = 0;
  4599. if (h >= 0 && h <= 1) {
  4600. r = chroma;
  4601. g = x;
  4602. }
  4603. else if (h >= 1 && h <= 2) {
  4604. r = x;
  4605. g = chroma;
  4606. }
  4607. else if (h >= 2 && h <= 3) {
  4608. g = chroma;
  4609. b = x;
  4610. }
  4611. else if (h >= 3 && h <= 4) {
  4612. g = x;
  4613. b = chroma;
  4614. }
  4615. else if (h >= 4 && h <= 5) {
  4616. r = x;
  4617. b = chroma;
  4618. }
  4619. else if (h >= 5 && h <= 6) {
  4620. r = chroma;
  4621. b = x;
  4622. }
  4623. var m = value - chroma;
  4624. result.set((r + m), (g + m), (b + m));
  4625. };
  4626. ColorPicker.prototype._draw = function (parentMeasure, context) {
  4627. context.save();
  4628. this._applyStates(context);
  4629. if (this._processMeasures(parentMeasure, context)) {
  4630. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4631. var wheelThickness = radius * .2;
  4632. var left = this._currentMeasure.left;
  4633. var top = this._currentMeasure.top;
  4634. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  4635. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  4636. }
  4637. this._updateSquareProps();
  4638. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4639. context.shadowColor = this.shadowColor;
  4640. context.shadowBlur = this.shadowBlur;
  4641. context.shadowOffsetX = this.shadowOffsetX;
  4642. context.shadowOffsetY = this.shadowOffsetY;
  4643. context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
  4644. }
  4645. context.drawImage(this._colorWheelCanvas, left, top);
  4646. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4647. context.shadowBlur = 0;
  4648. context.shadowOffsetX = 0;
  4649. context.shadowOffsetY = 0;
  4650. }
  4651. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  4652. var cx = this._squareLeft + this._squareSize * this._s;
  4653. var cy = this._squareTop + this._squareSize * (1 - this._v);
  4654. this._drawCircle(cx, cy, radius * .04, context);
  4655. var dist = radius - wheelThickness * .5;
  4656. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  4657. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  4658. this._drawCircle(cx, cy, wheelThickness * .35, context);
  4659. }
  4660. context.restore();
  4661. };
  4662. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  4663. if (this._pointerStartedOnWheel) {
  4664. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4665. var centerX = radius + this._currentMeasure.left;
  4666. var centerY = radius + this._currentMeasure.top;
  4667. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  4668. }
  4669. else if (this._pointerStartedOnSquare) {
  4670. this._updateSquareProps();
  4671. this._s = (x - this._squareLeft) / this._squareSize;
  4672. this._v = 1 - (y - this._squareTop) / this._squareSize;
  4673. this._s = Math.min(this._s, 1);
  4674. this._s = Math.max(this._s, 0.00001);
  4675. this._v = Math.min(this._v, 1);
  4676. this._v = Math.max(this._v, 0.00001);
  4677. }
  4678. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  4679. this.value = this._tmpColor;
  4680. };
  4681. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  4682. this._updateSquareProps();
  4683. var left = this._squareLeft;
  4684. var top = this._squareTop;
  4685. var size = this._squareSize;
  4686. if (coordinates.x >= left && coordinates.x <= left + size &&
  4687. coordinates.y >= top && coordinates.y <= top + size) {
  4688. return true;
  4689. }
  4690. return false;
  4691. };
  4692. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  4693. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  4694. var centerX = radius + this._currentMeasure.left;
  4695. var centerY = radius + this._currentMeasure.top;
  4696. var wheelThickness = radius * .2;
  4697. var innerRadius = radius - wheelThickness;
  4698. var radiusSq = radius * radius;
  4699. var innerRadiusSq = innerRadius * innerRadius;
  4700. var dx = coordinates.x - centerX;
  4701. var dy = coordinates.y - centerY;
  4702. var distSq = dx * dx + dy * dy;
  4703. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  4704. return true;
  4705. }
  4706. return false;
  4707. };
  4708. ColorPicker.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4709. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4710. return false;
  4711. }
  4712. this._pointerIsDown = true;
  4713. this._pointerStartedOnSquare = false;
  4714. this._pointerStartedOnWheel = false;
  4715. if (this._isPointOnSquare(coordinates)) {
  4716. this._pointerStartedOnSquare = true;
  4717. }
  4718. else if (this._isPointOnWheel(coordinates)) {
  4719. this._pointerStartedOnWheel = true;
  4720. }
  4721. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4722. this._host._capturingControl[pointerId] = this;
  4723. return true;
  4724. };
  4725. ColorPicker.prototype._onPointerMove = function (target, coordinates) {
  4726. if (this._pointerIsDown) {
  4727. this._updateValueFromPointer(coordinates.x, coordinates.y);
  4728. }
  4729. _super.prototype._onPointerMove.call(this, target, coordinates);
  4730. };
  4731. ColorPicker.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  4732. this._pointerIsDown = false;
  4733. delete this._host._capturingControl[pointerId];
  4734. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  4735. };
  4736. return ColorPicker;
  4737. }(GUI.Control));
  4738. GUI.ColorPicker = ColorPicker;
  4739. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4740. })(BABYLON || (BABYLON = {}));
  4741. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4742. var BABYLON;
  4743. (function (BABYLON) {
  4744. var GUI;
  4745. (function (GUI) {
  4746. var InputText = /** @class */ (function (_super) {
  4747. __extends(InputText, _super);
  4748. function InputText(name, text) {
  4749. if (text === void 0) { text = ""; }
  4750. var _this = _super.call(this, name) || this;
  4751. _this.name = name;
  4752. _this._text = "";
  4753. _this._placeholderText = "";
  4754. _this._background = "#222222";
  4755. _this._focusedBackground = "#000000";
  4756. _this._placeholderColor = "gray";
  4757. _this._thickness = 1;
  4758. _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
  4759. _this._autoStretchWidth = true;
  4760. _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  4761. _this._isFocused = false;
  4762. _this._blinkIsEven = false;
  4763. _this._cursorOffset = 0;
  4764. _this.promptMessage = "Please enter text:";
  4765. _this.onTextChangedObservable = new BABYLON.Observable();
  4766. _this.onFocusObservable = new BABYLON.Observable();
  4767. _this.onBlurObservable = new BABYLON.Observable();
  4768. _this.text = text;
  4769. return _this;
  4770. }
  4771. Object.defineProperty(InputText.prototype, "maxWidth", {
  4772. get: function () {
  4773. return this._maxWidth.toString(this._host);
  4774. },
  4775. set: function (value) {
  4776. if (this._maxWidth.toString(this._host) === value) {
  4777. return;
  4778. }
  4779. if (this._maxWidth.fromString(value)) {
  4780. this._markAsDirty();
  4781. }
  4782. },
  4783. enumerable: true,
  4784. configurable: true
  4785. });
  4786. Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
  4787. get: function () {
  4788. return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4789. },
  4790. enumerable: true,
  4791. configurable: true
  4792. });
  4793. Object.defineProperty(InputText.prototype, "margin", {
  4794. get: function () {
  4795. return this._margin.toString(this._host);
  4796. },
  4797. set: function (value) {
  4798. if (this._margin.toString(this._host) === value) {
  4799. return;
  4800. }
  4801. if (this._margin.fromString(value)) {
  4802. this._markAsDirty();
  4803. }
  4804. },
  4805. enumerable: true,
  4806. configurable: true
  4807. });
  4808. Object.defineProperty(InputText.prototype, "marginInPixels", {
  4809. get: function () {
  4810. return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4811. },
  4812. enumerable: true,
  4813. configurable: true
  4814. });
  4815. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  4816. get: function () {
  4817. return this._autoStretchWidth;
  4818. },
  4819. set: function (value) {
  4820. if (this._autoStretchWidth === value) {
  4821. return;
  4822. }
  4823. this._autoStretchWidth = value;
  4824. this._markAsDirty();
  4825. },
  4826. enumerable: true,
  4827. configurable: true
  4828. });
  4829. Object.defineProperty(InputText.prototype, "thickness", {
  4830. get: function () {
  4831. return this._thickness;
  4832. },
  4833. set: function (value) {
  4834. if (this._thickness === value) {
  4835. return;
  4836. }
  4837. this._thickness = value;
  4838. this._markAsDirty();
  4839. },
  4840. enumerable: true,
  4841. configurable: true
  4842. });
  4843. Object.defineProperty(InputText.prototype, "focusedBackground", {
  4844. get: function () {
  4845. return this._focusedBackground;
  4846. },
  4847. set: function (value) {
  4848. if (this._focusedBackground === value) {
  4849. return;
  4850. }
  4851. this._focusedBackground = value;
  4852. this._markAsDirty();
  4853. },
  4854. enumerable: true,
  4855. configurable: true
  4856. });
  4857. Object.defineProperty(InputText.prototype, "background", {
  4858. get: function () {
  4859. return this._background;
  4860. },
  4861. set: function (value) {
  4862. if (this._background === value) {
  4863. return;
  4864. }
  4865. this._background = value;
  4866. this._markAsDirty();
  4867. },
  4868. enumerable: true,
  4869. configurable: true
  4870. });
  4871. Object.defineProperty(InputText.prototype, "placeholderColor", {
  4872. get: function () {
  4873. return this._placeholderColor;
  4874. },
  4875. set: function (value) {
  4876. if (this._placeholderColor === value) {
  4877. return;
  4878. }
  4879. this._placeholderColor = value;
  4880. this._markAsDirty();
  4881. },
  4882. enumerable: true,
  4883. configurable: true
  4884. });
  4885. Object.defineProperty(InputText.prototype, "placeholderText", {
  4886. get: function () {
  4887. return this._placeholderText;
  4888. },
  4889. set: function (value) {
  4890. if (this._placeholderText === value) {
  4891. return;
  4892. }
  4893. this._placeholderText = value;
  4894. this._markAsDirty();
  4895. },
  4896. enumerable: true,
  4897. configurable: true
  4898. });
  4899. Object.defineProperty(InputText.prototype, "text", {
  4900. get: function () {
  4901. return this._text;
  4902. },
  4903. set: function (value) {
  4904. if (this._text === value) {
  4905. return;
  4906. }
  4907. this._text = value;
  4908. this._markAsDirty();
  4909. this.onTextChangedObservable.notifyObservers(this);
  4910. },
  4911. enumerable: true,
  4912. configurable: true
  4913. });
  4914. Object.defineProperty(InputText.prototype, "width", {
  4915. get: function () {
  4916. return this._width.toString(this._host);
  4917. },
  4918. set: function (value) {
  4919. if (this._width.toString(this._host) === value) {
  4920. return;
  4921. }
  4922. if (this._width.fromString(value)) {
  4923. this._markAsDirty();
  4924. }
  4925. this.autoStretchWidth = false;
  4926. },
  4927. enumerable: true,
  4928. configurable: true
  4929. });
  4930. InputText.prototype.onBlur = function () {
  4931. this._isFocused = false;
  4932. this._scrollLeft = null;
  4933. this._cursorOffset = 0;
  4934. clearTimeout(this._blinkTimeout);
  4935. this._markAsDirty();
  4936. this.onBlurObservable.notifyObservers(this);
  4937. };
  4938. InputText.prototype.onFocus = function () {
  4939. this._scrollLeft = null;
  4940. this._isFocused = true;
  4941. this._blinkIsEven = false;
  4942. this._cursorOffset = 0;
  4943. this._markAsDirty();
  4944. this.onFocusObservable.notifyObservers(this);
  4945. if (navigator.userAgent.indexOf("Mobile") !== -1) {
  4946. var value = prompt(this.promptMessage);
  4947. if (value !== null) {
  4948. this.text = value;
  4949. }
  4950. this._host.focusedControl = null;
  4951. return;
  4952. }
  4953. };
  4954. InputText.prototype._getTypeName = function () {
  4955. return "InputText";
  4956. };
  4957. InputText.prototype.processKey = function (keyCode, key) {
  4958. // Specific cases
  4959. switch (keyCode) {
  4960. case 32: //SPACE
  4961. key = " "; //ie11 key for space is "Spacebar"
  4962. break;
  4963. case 8: // BACKSPACE
  4964. if (this._text && this._text.length > 0) {
  4965. if (this._cursorOffset === 0) {
  4966. this.text = this._text.substr(0, this._text.length - 1);
  4967. }
  4968. else {
  4969. var deletePosition = this._text.length - this._cursorOffset;
  4970. if (deletePosition > 0) {
  4971. this.text = this._text.slice(0, deletePosition - 1) + this._text.slice(deletePosition);
  4972. }
  4973. }
  4974. }
  4975. return;
  4976. case 46: // DELETE
  4977. if (this._text && this._text.length > 0) {
  4978. var deletePosition = this._text.length - this._cursorOffset;
  4979. this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
  4980. this._cursorOffset--;
  4981. }
  4982. return;
  4983. case 13: // RETURN
  4984. this._host.focusedControl = null;
  4985. return;
  4986. case 35: // END
  4987. this._cursorOffset = 0;
  4988. this._blinkIsEven = false;
  4989. this._markAsDirty();
  4990. return;
  4991. case 36: // HOME
  4992. this._cursorOffset = this._text.length;
  4993. this._blinkIsEven = false;
  4994. this._markAsDirty();
  4995. return;
  4996. case 37: // LEFT
  4997. this._cursorOffset++;
  4998. if (this._cursorOffset > this._text.length) {
  4999. this._cursorOffset = this._text.length;
  5000. }
  5001. this._blinkIsEven = false;
  5002. this._markAsDirty();
  5003. return;
  5004. case 39: // RIGHT
  5005. this._cursorOffset--;
  5006. if (this._cursorOffset < 0) {
  5007. this._cursorOffset = 0;
  5008. }
  5009. this._blinkIsEven = false;
  5010. this._markAsDirty();
  5011. return;
  5012. }
  5013. // Printable characters
  5014. if ((keyCode === -1) || // Direct access
  5015. (keyCode === 32) || // Space
  5016. (keyCode > 47 && keyCode < 58) || // Numbers
  5017. (keyCode > 64 && keyCode < 91) || // Letters
  5018. (keyCode > 185 && keyCode < 193) || // Special characters
  5019. (keyCode > 218 && keyCode < 223) || // Special characters
  5020. (keyCode > 95 && keyCode < 112)) { // Numpad
  5021. if (this._cursorOffset === 0) {
  5022. this.text += key;
  5023. }
  5024. else {
  5025. var insertPosition = this._text.length - this._cursorOffset;
  5026. this.text = this._text.slice(0, insertPosition) + key + this._text.slice(insertPosition);
  5027. }
  5028. }
  5029. };
  5030. InputText.prototype.processKeyboard = function (evt) {
  5031. this.processKey(evt.keyCode, evt.key);
  5032. };
  5033. InputText.prototype._draw = function (parentMeasure, context) {
  5034. var _this = this;
  5035. context.save();
  5036. this._applyStates(context);
  5037. if (this._processMeasures(parentMeasure, context)) {
  5038. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5039. context.shadowColor = this.shadowColor;
  5040. context.shadowBlur = this.shadowBlur;
  5041. context.shadowOffsetX = this.shadowOffsetX;
  5042. context.shadowOffsetY = this.shadowOffsetY;
  5043. }
  5044. // Background
  5045. if (this._isFocused) {
  5046. if (this._focusedBackground) {
  5047. context.fillStyle = this._focusedBackground;
  5048. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  5049. }
  5050. }
  5051. else if (this._background) {
  5052. context.fillStyle = this._background;
  5053. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  5054. }
  5055. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5056. context.shadowBlur = 0;
  5057. context.shadowOffsetX = 0;
  5058. context.shadowOffsetY = 0;
  5059. }
  5060. if (!this._fontOffset) {
  5061. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  5062. }
  5063. // Text
  5064. var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width);
  5065. if (this.color) {
  5066. context.fillStyle = this.color;
  5067. }
  5068. var text = this._text;
  5069. if (!this._isFocused && !this._text && this._placeholderText) {
  5070. text = this._placeholderText;
  5071. if (this._placeholderColor) {
  5072. context.fillStyle = this._placeholderColor;
  5073. }
  5074. }
  5075. this._textWidth = context.measureText(text).width;
  5076. var marginWidth = this._margin.getValueInPixel(this._host, parentMeasure.width) * 2;
  5077. if (this._autoStretchWidth) {
  5078. this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), this._textWidth + marginWidth) + "px";
  5079. }
  5080. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  5081. var availableWidth = this._width.getValueInPixel(this._host, parentMeasure.width) - marginWidth;
  5082. context.save();
  5083. context.beginPath();
  5084. context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
  5085. context.clip();
  5086. if (this._isFocused && this._textWidth > availableWidth) {
  5087. var textLeft = clipTextLeft - this._textWidth + availableWidth;
  5088. if (!this._scrollLeft) {
  5089. this._scrollLeft = textLeft;
  5090. }
  5091. }
  5092. else {
  5093. this._scrollLeft = clipTextLeft;
  5094. }
  5095. context.fillText(text, this._scrollLeft, this._currentMeasure.top + rootY);
  5096. // Cursor
  5097. if (this._isFocused) {
  5098. // Need to move cursor
  5099. if (this._clickedCoordinate) {
  5100. var rightPosition = this._scrollLeft + this._textWidth;
  5101. var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
  5102. var currentSize = 0;
  5103. this._cursorOffset = 0;
  5104. var previousDist = 0;
  5105. do {
  5106. if (this._cursorOffset) {
  5107. previousDist = Math.abs(absoluteCursorPosition - currentSize);
  5108. }
  5109. this._cursorOffset++;
  5110. currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
  5111. } while (currentSize < absoluteCursorPosition && (text.length >= this._cursorOffset));
  5112. // Find closest move
  5113. if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
  5114. this._cursorOffset--;
  5115. }
  5116. this._blinkIsEven = false;
  5117. this._clickedCoordinate = null;
  5118. }
  5119. // Render cursor
  5120. if (!this._blinkIsEven) {
  5121. var cursorOffsetText = this.text.substr(this._text.length - this._cursorOffset);
  5122. var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
  5123. var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
  5124. if (cursorLeft < clipTextLeft) {
  5125. this._scrollLeft += (clipTextLeft - cursorLeft);
  5126. cursorLeft = clipTextLeft;
  5127. this._markAsDirty();
  5128. }
  5129. else if (cursorLeft > clipTextLeft + availableWidth) {
  5130. this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
  5131. cursorLeft = clipTextLeft + availableWidth;
  5132. this._markAsDirty();
  5133. }
  5134. context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
  5135. }
  5136. clearTimeout(this._blinkTimeout);
  5137. this._blinkTimeout = setTimeout(function () {
  5138. _this._blinkIsEven = !_this._blinkIsEven;
  5139. _this._markAsDirty();
  5140. }, 500);
  5141. }
  5142. context.restore();
  5143. // Border
  5144. if (this._thickness) {
  5145. if (this.color) {
  5146. context.strokeStyle = this.color;
  5147. }
  5148. context.lineWidth = this._thickness;
  5149. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  5150. }
  5151. }
  5152. context.restore();
  5153. };
  5154. InputText.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5155. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5156. return false;
  5157. }
  5158. this._clickedCoordinate = coordinates.x;
  5159. if (this._host.focusedControl === this) {
  5160. // Move cursor
  5161. clearTimeout(this._blinkTimeout);
  5162. this._markAsDirty();
  5163. return true;
  5164. }
  5165. this._host.focusedControl = this;
  5166. return true;
  5167. };
  5168. InputText.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5169. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5170. };
  5171. InputText.prototype.dispose = function () {
  5172. _super.prototype.dispose.call(this);
  5173. this.onBlurObservable.clear();
  5174. this.onFocusObservable.clear();
  5175. this.onTextChangedObservable.clear();
  5176. };
  5177. return InputText;
  5178. }(GUI.Control));
  5179. GUI.InputText = InputText;
  5180. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5181. })(BABYLON || (BABYLON = {}));
  5182. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5183. var BABYLON;
  5184. (function (BABYLON) {
  5185. var GUI;
  5186. (function (GUI) {
  5187. var KeyPropertySet = /** @class */ (function () {
  5188. function KeyPropertySet() {
  5189. }
  5190. return KeyPropertySet;
  5191. }());
  5192. GUI.KeyPropertySet = KeyPropertySet;
  5193. var VirtualKeyboard = /** @class */ (function (_super) {
  5194. __extends(VirtualKeyboard, _super);
  5195. function VirtualKeyboard() {
  5196. var _this = _super !== null && _super.apply(this, arguments) || this;
  5197. _this.onKeyPressObservable = new BABYLON.Observable();
  5198. _this.defaultButtonWidth = "40px";
  5199. _this.defaultButtonHeight = "40px";
  5200. _this.defaultButtonPaddingLeft = "2px";
  5201. _this.defaultButtonPaddingRight = "2px";
  5202. _this.defaultButtonPaddingTop = "2px";
  5203. _this.defaultButtonPaddingBottom = "2px";
  5204. _this.defaultButtonColor = "#DDD";
  5205. _this.defaultButtonBackground = "#070707";
  5206. _this.shiftButtonColor = "#7799FF";
  5207. _this.selectedShiftThickness = 1;
  5208. _this.shiftState = 0;
  5209. return _this;
  5210. }
  5211. VirtualKeyboard.prototype._getTypeName = function () {
  5212. return "VirtualKeyboard";
  5213. };
  5214. VirtualKeyboard.prototype._createKey = function (key, propertySet) {
  5215. var _this = this;
  5216. var button = GUI.Button.CreateSimpleButton(key, key);
  5217. button.width = propertySet && propertySet.width ? propertySet.width : this.defaultButtonWidth;
  5218. button.height = propertySet && propertySet.height ? propertySet.height : this.defaultButtonHeight;
  5219. button.color = propertySet && propertySet.color ? propertySet.color : this.defaultButtonColor;
  5220. button.background = propertySet && propertySet.background ? propertySet.background : this.defaultButtonBackground;
  5221. button.paddingLeft = propertySet && propertySet.paddingLeft ? propertySet.paddingLeft : this.defaultButtonPaddingLeft;
  5222. button.paddingRight = propertySet && propertySet.paddingRight ? propertySet.paddingRight : this.defaultButtonPaddingRight;
  5223. button.paddingTop = propertySet && propertySet.paddingTop ? propertySet.paddingTop : this.defaultButtonPaddingTop;
  5224. button.paddingBottom = propertySet && propertySet.paddingBottom ? propertySet.paddingBottom : this.defaultButtonPaddingBottom;
  5225. button.thickness = 0;
  5226. button.isFocusInvisible = true;
  5227. button.shadowColor = this.shadowColor;
  5228. button.shadowBlur = this.shadowBlur;
  5229. button.shadowOffsetX = this.shadowOffsetX;
  5230. button.shadowOffsetY = this.shadowOffsetY;
  5231. button.onPointerUpObservable.add(function () {
  5232. _this.onKeyPressObservable.notifyObservers(key);
  5233. });
  5234. return button;
  5235. };
  5236. VirtualKeyboard.prototype.addKeysRow = function (keys, propertySets) {
  5237. var panel = new GUI.StackPanel();
  5238. panel.isVertical = false;
  5239. panel.isFocusInvisible = true;
  5240. for (var i = 0; i < keys.length; i++) {
  5241. var properties = null;
  5242. if (propertySets && propertySets.length === keys.length) {
  5243. properties = propertySets[i];
  5244. }
  5245. panel.addControl(this._createKey(keys[i], properties));
  5246. }
  5247. this.addControl(panel);
  5248. };
  5249. VirtualKeyboard.prototype.applyShiftState = function (shiftState) {
  5250. if (!this.children) {
  5251. return;
  5252. }
  5253. for (var i = 0; i < this.children.length; i++) {
  5254. var row = this.children[i];
  5255. if (!row || !row.children) {
  5256. continue;
  5257. }
  5258. var rowContainer = row;
  5259. for (var j = 0; j < rowContainer.children.length; j++) {
  5260. var button = rowContainer.children[j];
  5261. if (!button || !button.children[0]) {
  5262. continue;
  5263. }
  5264. var button_tblock = button.children[0];
  5265. if (button_tblock.text === "\u21E7") {
  5266. button.color = (shiftState ? this.shiftButtonColor : this.defaultButtonColor);
  5267. button.thickness = (shiftState > 1 ? this.selectedShiftThickness : 0);
  5268. }
  5269. button_tblock.text = (shiftState > 0 ? button_tblock.text.toUpperCase() : button_tblock.text.toLowerCase());
  5270. }
  5271. }
  5272. };
  5273. Object.defineProperty(VirtualKeyboard.prototype, "connectedInputText", {
  5274. get: function () {
  5275. return this._connectedInputText;
  5276. },
  5277. enumerable: true,
  5278. configurable: true
  5279. });
  5280. VirtualKeyboard.prototype.connect = function (input) {
  5281. var _this = this;
  5282. this.isVisible = false;
  5283. this._connectedInputText = input;
  5284. // Events hooking
  5285. this._onFocusObserver = input.onFocusObservable.add(function () {
  5286. _this.isVisible = true;
  5287. });
  5288. this._onBlurObserver = input.onBlurObservable.add(function () {
  5289. _this.isVisible = false;
  5290. });
  5291. this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
  5292. if (!_this._connectedInputText) {
  5293. return;
  5294. }
  5295. switch (key) {
  5296. case "\u21E7":
  5297. _this.shiftState++;
  5298. if (_this.shiftState > 2) {
  5299. _this.shiftState = 0;
  5300. }
  5301. _this.applyShiftState(_this.shiftState);
  5302. return;
  5303. case "\u2190":
  5304. _this._connectedInputText.processKey(8);
  5305. return;
  5306. case "\u21B5":
  5307. _this._connectedInputText.processKey(13);
  5308. return;
  5309. }
  5310. _this._connectedInputText.processKey(-1, (_this.shiftState ? key.toUpperCase() : key));
  5311. if (_this.shiftState === 1) {
  5312. _this.shiftState = 0;
  5313. _this.applyShiftState(_this.shiftState);
  5314. }
  5315. });
  5316. };
  5317. VirtualKeyboard.prototype.disconnect = function () {
  5318. if (!this._connectedInputText) {
  5319. return;
  5320. }
  5321. this._connectedInputText.onFocusObservable.remove(this._onFocusObserver);
  5322. this._connectedInputText.onBlurObservable.remove(this._onBlurObserver);
  5323. this.onKeyPressObservable.remove(this._onKeyPressObserver);
  5324. this._connectedInputText = null;
  5325. };
  5326. // Statics
  5327. VirtualKeyboard.CreateDefaultLayout = function () {
  5328. var returnValue = new VirtualKeyboard();
  5329. returnValue.addKeysRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u2190"]);
  5330. returnValue.addKeysRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]);
  5331. returnValue.addKeysRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\u21B5"]);
  5332. returnValue.addKeysRow(["\u21E7", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]);
  5333. returnValue.addKeysRow([" "], [{ width: "200px" }]);
  5334. return returnValue;
  5335. };
  5336. return VirtualKeyboard;
  5337. }(GUI.StackPanel));
  5338. GUI.VirtualKeyboard = VirtualKeyboard;
  5339. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5340. })(BABYLON || (BABYLON = {}));
  5341. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5342. var BABYLON;
  5343. (function (BABYLON) {
  5344. var GUI;
  5345. (function (GUI) {
  5346. var MultiLine = /** @class */ (function (_super) {
  5347. __extends(MultiLine, _super);
  5348. function MultiLine(name) {
  5349. var _this = _super.call(this, name) || this;
  5350. _this.name = name;
  5351. _this._lineWidth = 1;
  5352. _this.onPointUpdate = function () {
  5353. _this._markAsDirty();
  5354. };
  5355. _this.isHitTestVisible = false;
  5356. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5357. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  5358. _this._dash = [];
  5359. _this._points = [];
  5360. return _this;
  5361. }
  5362. Object.defineProperty(MultiLine.prototype, "dash", {
  5363. get: function () {
  5364. return this._dash;
  5365. },
  5366. set: function (value) {
  5367. if (this._dash === value) {
  5368. return;
  5369. }
  5370. this._dash = value;
  5371. this._markAsDirty();
  5372. },
  5373. enumerable: true,
  5374. configurable: true
  5375. });
  5376. MultiLine.prototype.getAt = function (index) {
  5377. if (!this._points[index]) {
  5378. this._points[index] = new GUI.MultiLinePoint(this);
  5379. }
  5380. return this._points[index];
  5381. };
  5382. MultiLine.prototype.add = function () {
  5383. var _this = this;
  5384. var items = [];
  5385. for (var _i = 0; _i < arguments.length; _i++) {
  5386. items[_i] = arguments[_i];
  5387. }
  5388. return items.map(function (item) { return _this.push(item); });
  5389. };
  5390. MultiLine.prototype.push = function (item) {
  5391. var point = this.getAt(this._points.length);
  5392. if (item == null)
  5393. return point;
  5394. if (item instanceof BABYLON.AbstractMesh) {
  5395. point.mesh = item;
  5396. }
  5397. else if (item instanceof GUI.Control) {
  5398. point.control = item;
  5399. }
  5400. else if (item.x != null && item.y != null) {
  5401. point.x = item.x;
  5402. point.y = item.y;
  5403. }
  5404. return point;
  5405. };
  5406. MultiLine.prototype.remove = function (value) {
  5407. var index;
  5408. if (value instanceof GUI.MultiLinePoint) {
  5409. index = this._points.indexOf(value);
  5410. if (index === -1) {
  5411. return;
  5412. }
  5413. }
  5414. else {
  5415. index = value;
  5416. }
  5417. var point = this._points[index];
  5418. if (!point) {
  5419. return;
  5420. }
  5421. point.dispose();
  5422. this._points.splice(index, 1);
  5423. };
  5424. Object.defineProperty(MultiLine.prototype, "lineWidth", {
  5425. get: function () {
  5426. return this._lineWidth;
  5427. },
  5428. set: function (value) {
  5429. if (this._lineWidth === value) {
  5430. return;
  5431. }
  5432. this._lineWidth = value;
  5433. this._markAsDirty();
  5434. },
  5435. enumerable: true,
  5436. configurable: true
  5437. });
  5438. Object.defineProperty(MultiLine.prototype, "horizontalAlignment", {
  5439. set: function (value) {
  5440. return;
  5441. },
  5442. enumerable: true,
  5443. configurable: true
  5444. });
  5445. Object.defineProperty(MultiLine.prototype, "verticalAlignment", {
  5446. set: function (value) {
  5447. return;
  5448. },
  5449. enumerable: true,
  5450. configurable: true
  5451. });
  5452. MultiLine.prototype._getTypeName = function () {
  5453. return "MultiLine";
  5454. };
  5455. MultiLine.prototype._draw = function (parentMeasure, context) {
  5456. context.save();
  5457. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5458. context.shadowColor = this.shadowColor;
  5459. context.shadowBlur = this.shadowBlur;
  5460. context.shadowOffsetX = this.shadowOffsetX;
  5461. context.shadowOffsetY = this.shadowOffsetY;
  5462. }
  5463. this._applyStates(context);
  5464. if (this._processMeasures(parentMeasure, context)) {
  5465. context.strokeStyle = this.color;
  5466. context.lineWidth = this._lineWidth;
  5467. context.setLineDash(this._dash);
  5468. context.beginPath();
  5469. var first = true; //first index is not necessarily 0
  5470. this._points.forEach(function (point) {
  5471. if (!point) {
  5472. return;
  5473. }
  5474. if (first) {
  5475. context.moveTo(point._point.x, point._point.y);
  5476. first = false;
  5477. }
  5478. else {
  5479. context.lineTo(point._point.x, point._point.y);
  5480. }
  5481. });
  5482. context.stroke();
  5483. }
  5484. context.restore();
  5485. };
  5486. MultiLine.prototype._additionalProcessing = function (parentMeasure, context) {
  5487. var _this = this;
  5488. this._minX = null;
  5489. this._minY = null;
  5490. this._maxX = null;
  5491. this._maxY = null;
  5492. this._points.forEach(function (point, index) {
  5493. if (!point) {
  5494. return;
  5495. }
  5496. point.translate();
  5497. if (_this._minX == null || point._point.x < _this._minX)
  5498. _this._minX = point._point.x;
  5499. if (_this._minY == null || point._point.y < _this._minY)
  5500. _this._minY = point._point.y;
  5501. if (_this._maxX == null || point._point.x > _this._maxX)
  5502. _this._maxX = point._point.x;
  5503. if (_this._maxY == null || point._point.y > _this._maxY)
  5504. _this._maxY = point._point.y;
  5505. });
  5506. if (this._minX == null)
  5507. this._minX = 0;
  5508. if (this._minY == null)
  5509. this._minY = 0;
  5510. if (this._maxX == null)
  5511. this._maxX = 0;
  5512. if (this._maxY == null)
  5513. this._maxY = 0;
  5514. };
  5515. MultiLine.prototype._measure = function () {
  5516. if (this._minX == null || this._maxX == null || this._minY == null || this._maxY == null) {
  5517. return;
  5518. }
  5519. this._currentMeasure.width = Math.abs(this._maxX - this._minX) + this._lineWidth;
  5520. this._currentMeasure.height = Math.abs(this._maxY - this._minY) + this._lineWidth;
  5521. };
  5522. MultiLine.prototype._computeAlignment = function (parentMeasure, context) {
  5523. if (this._minX == null || this._minY == null) {
  5524. return;
  5525. }
  5526. this._currentMeasure.left = this._minX - this._lineWidth / 2;
  5527. this._currentMeasure.top = this._minY - this._lineWidth / 2;
  5528. };
  5529. MultiLine.prototype.dispose = function () {
  5530. while (this._points.length > 0) {
  5531. this.remove(this._points.length - 1);
  5532. }
  5533. _super.prototype.dispose.call(this);
  5534. };
  5535. return MultiLine;
  5536. }(GUI.Control));
  5537. GUI.MultiLine = MultiLine;
  5538. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5539. })(BABYLON || (BABYLON = {}));
  5540. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  5541. var BABYLON;
  5542. (function (BABYLON) {
  5543. var GUI;
  5544. (function (GUI) {
  5545. /**
  5546. * Class used to manage 3D user interface
  5547. */
  5548. var GUI3DManager = /** @class */ (function () {
  5549. /**
  5550. * Creates a new GUI3DManager
  5551. * @param scene
  5552. */
  5553. function GUI3DManager(scene) {
  5554. var _this = this;
  5555. /** @hidden */
  5556. this._lastControlOver = {};
  5557. /** @hidden */
  5558. this._lastControlDown = {};
  5559. this._scene = scene || BABYLON.Engine.LastCreatedScene;
  5560. this._sceneDisposeObserver = this._scene.onDisposeObservable.add(function () {
  5561. _this._sceneDisposeObserver = null;
  5562. _this._utilityLayer = null;
  5563. _this.dispose();
  5564. });
  5565. this._utilityLayer = new BABYLON.UtilityLayerRenderer(this._scene);
  5566. // Root
  5567. this._rootContainer = new GUI.Container3D("RootContainer");
  5568. this._rootContainer._host = this;
  5569. // Events
  5570. this._pointerObserver = this._scene.onPrePointerObservable.add(function (pi, state) {
  5571. var pointerEvent = (pi.event);
  5572. if (_this._scene.isPointerCaptured(pointerEvent.pointerId)) {
  5573. return;
  5574. }
  5575. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  5576. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  5577. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  5578. return;
  5579. }
  5580. var camera = _this._scene.cameraToUseForPointers || _this._scene.activeCamera;
  5581. if (!camera) {
  5582. return;
  5583. }
  5584. pi.skipOnPointerObservable = _this._doPicking(pi.type, pointerEvent);
  5585. });
  5586. // Scene
  5587. this._utilityLayer.utilityLayerScene.autoClear = false;
  5588. this._utilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
  5589. new BABYLON.HemisphericLight("hemi", BABYLON.Vector3.Up(), this._utilityLayer.utilityLayerScene);
  5590. }
  5591. Object.defineProperty(GUI3DManager.prototype, "scene", {
  5592. /** Gets the hosting scene */
  5593. get: function () {
  5594. return this._scene;
  5595. },
  5596. enumerable: true,
  5597. configurable: true
  5598. });
  5599. Object.defineProperty(GUI3DManager.prototype, "utilityLayer", {
  5600. get: function () {
  5601. return this._utilityLayer;
  5602. },
  5603. enumerable: true,
  5604. configurable: true
  5605. });
  5606. GUI3DManager.prototype._doPicking = function (type, pointerEvent) {
  5607. if (!this._utilityLayer || !this._utilityLayer.utilityLayerScene.activeCamera) {
  5608. return false;
  5609. }
  5610. var pointerId = pointerEvent.pointerId || 0;
  5611. var buttonIndex = pointerEvent.button;
  5612. var utilityScene = this._utilityLayer.utilityLayerScene;
  5613. var pickingInfo = utilityScene.pick(this._scene.pointerX, this._scene.pointerY);
  5614. if (!pickingInfo || !pickingInfo.hit) {
  5615. var previousControlOver = this._lastControlOver[pointerId];
  5616. if (previousControlOver) {
  5617. previousControlOver._onPointerOut(previousControlOver);
  5618. delete this._lastControlOver[pointerId];
  5619. }
  5620. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  5621. if (this._lastControlDown[pointerEvent.pointerId]) {
  5622. this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  5623. delete this._lastControlDown[pointerEvent.pointerId];
  5624. }
  5625. }
  5626. return false;
  5627. }
  5628. var control = (pickingInfo.pickedMesh.metadata);
  5629. if (!control._processObservables(type, pickingInfo.pickedPoint, pointerId, buttonIndex)) {
  5630. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  5631. if (this._lastControlOver[pointerId]) {
  5632. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  5633. }
  5634. delete this._lastControlOver[pointerId];
  5635. }
  5636. }
  5637. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  5638. if (this._lastControlDown[pointerEvent.pointerId]) {
  5639. this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  5640. delete this._lastControlDown[pointerEvent.pointerId];
  5641. }
  5642. }
  5643. return true;
  5644. };
  5645. Object.defineProperty(GUI3DManager.prototype, "rootContainer", {
  5646. /**
  5647. * Gets the root container
  5648. */
  5649. get: function () {
  5650. return this._rootContainer;
  5651. },
  5652. enumerable: true,
  5653. configurable: true
  5654. });
  5655. /**
  5656. * Gets a boolean indicating if the given control is in the root child list
  5657. * @param control defines the control to check
  5658. * @returns true if the control is in the root child list
  5659. */
  5660. GUI3DManager.prototype.containsControl = function (control) {
  5661. return this._rootContainer.containsControl(control);
  5662. };
  5663. /**
  5664. * Adds a control to the root child list
  5665. * @param control defines the control to add
  5666. * @returns the current manager
  5667. */
  5668. GUI3DManager.prototype.addControl = function (control) {
  5669. this._rootContainer.addControl(control);
  5670. return this;
  5671. };
  5672. /**
  5673. * Removes the control from the root child list
  5674. * @param control defines the control to remove
  5675. * @returns the current container
  5676. */
  5677. GUI3DManager.prototype.removeControl = function (control) {
  5678. this._rootContainer.removeControl(control);
  5679. return this;
  5680. };
  5681. /**
  5682. * Releases all associated resources
  5683. */
  5684. GUI3DManager.prototype.dispose = function () {
  5685. this._rootContainer.dispose();
  5686. if (this._scene) {
  5687. if (this._pointerObserver) {
  5688. this._scene.onPrePointerObservable.remove(this._pointerObserver);
  5689. this._pointerObserver = null;
  5690. }
  5691. if (this._sceneDisposeObserver) {
  5692. this._scene.onDisposeObservable.remove(this._sceneDisposeObserver);
  5693. this._sceneDisposeObserver = null;
  5694. }
  5695. }
  5696. if (this._utilityLayer) {
  5697. this._utilityLayer.dispose();
  5698. }
  5699. };
  5700. return GUI3DManager;
  5701. }());
  5702. GUI.GUI3DManager = GUI3DManager;
  5703. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5704. })(BABYLON || (BABYLON = {}));
  5705. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5706. var BABYLON;
  5707. (function (BABYLON) {
  5708. var GUI;
  5709. (function (GUI) {
  5710. /**
  5711. * Class used to render controls with fluent desgin
  5712. */
  5713. var FluentMaterial = /** @class */ (function (_super) {
  5714. __extends(FluentMaterial, _super);
  5715. function FluentMaterial(name, scene) {
  5716. return _super.call(this, name, scene) || this;
  5717. }
  5718. FluentMaterial.prototype.needAlphaBlending = function () {
  5719. return false;
  5720. };
  5721. FluentMaterial.prototype.needAlphaTesting = function () {
  5722. return false;
  5723. };
  5724. FluentMaterial.prototype.getAlphaTestTexture = function () {
  5725. return null;
  5726. };
  5727. FluentMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  5728. if (this.isFrozen) {
  5729. if (this._wasPreviouslyReady && subMesh.effect) {
  5730. return true;
  5731. }
  5732. }
  5733. var scene = this.getScene();
  5734. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  5735. if (this._renderId === scene.getRenderId()) {
  5736. return true;
  5737. }
  5738. }
  5739. var engine = scene.getEngine();
  5740. scene.resetCachedMaterial();
  5741. //Attributes
  5742. var attribs = [BABYLON.VertexBuffer.PositionKind];
  5743. attribs.push(BABYLON.VertexBuffer.NormalKind);
  5744. attribs.push(BABYLON.VertexBuffer.UVKind);
  5745. var shaderName = "fluent";
  5746. var uniforms = ["world", "viewProjection", "emissiveMatrix"];
  5747. var samplers = ["emissiveSampler"];
  5748. var uniformBuffers = new Array();
  5749. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  5750. uniformsNames: uniforms,
  5751. uniformBuffersNames: uniformBuffers,
  5752. samplers: samplers,
  5753. defines: "",
  5754. maxSimultaneousLights: 4
  5755. });
  5756. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  5757. attributes: attribs,
  5758. uniformsNames: uniforms,
  5759. uniformBuffersNames: uniformBuffers,
  5760. samplers: samplers,
  5761. defines: "",
  5762. fallbacks: null,
  5763. onCompiled: this.onCompiled,
  5764. onError: this.onError,
  5765. indexParameters: { maxSimultaneousLights: 4 }
  5766. }, engine));
  5767. if (!subMesh.effect || !subMesh.effect.isReady()) {
  5768. return false;
  5769. }
  5770. this._renderId = scene.getRenderId();
  5771. this._wasPreviouslyReady = true;
  5772. return true;
  5773. };
  5774. FluentMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  5775. var scene = this.getScene();
  5776. var effect = subMesh.effect;
  5777. if (!effect) {
  5778. return;
  5779. }
  5780. this._activeEffect = effect;
  5781. // Matrices
  5782. this.bindOnlyWorldMatrix(world);
  5783. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  5784. if (this._mustRebind(scene, effect)) {
  5785. // Textures
  5786. if (this._emissiveTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  5787. this._activeEffect.setTexture("emissiveSampler", this._emissiveTexture);
  5788. this._activeEffect.setMatrix("emissiveMatrix", this._emissiveTexture.getTextureMatrix());
  5789. }
  5790. }
  5791. this._afterBind(mesh, this._activeEffect);
  5792. };
  5793. FluentMaterial.prototype.getActiveTextures = function () {
  5794. var activeTextures = _super.prototype.getActiveTextures.call(this);
  5795. if (this._emissiveTexture) {
  5796. activeTextures.push(this._emissiveTexture);
  5797. }
  5798. return activeTextures;
  5799. };
  5800. FluentMaterial.prototype.hasTexture = function (texture) {
  5801. if (_super.prototype.hasTexture.call(this, texture)) {
  5802. return true;
  5803. }
  5804. if (this._emissiveTexture === texture) {
  5805. return true;
  5806. }
  5807. return false;
  5808. };
  5809. FluentMaterial.prototype.dispose = function (forceDisposeEffect) {
  5810. if (this._emissiveTexture) {
  5811. this._emissiveTexture.dispose();
  5812. }
  5813. _super.prototype.dispose.call(this, forceDisposeEffect);
  5814. };
  5815. FluentMaterial.prototype.clone = function (name) {
  5816. var _this = this;
  5817. return BABYLON.SerializationHelper.Clone(function () { return new FluentMaterial(name, _this.getScene()); }, this);
  5818. };
  5819. FluentMaterial.prototype.serialize = function () {
  5820. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  5821. serializationObject.customType = "BABYLON.GUI.FluentMaterial";
  5822. return serializationObject;
  5823. };
  5824. FluentMaterial.prototype.getClassName = function () {
  5825. return "FluentMaterial";
  5826. };
  5827. // Statics
  5828. FluentMaterial.Parse = function (source, scene, rootUrl) {
  5829. return BABYLON.SerializationHelper.Parse(function () { return new FluentMaterial(source.name, scene); }, source, scene, rootUrl);
  5830. };
  5831. __decorate([
  5832. BABYLON.serializeAsTexture("emissiveTexture")
  5833. ], FluentMaterial.prototype, "_emissiveTexture", void 0);
  5834. __decorate([
  5835. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5836. ], FluentMaterial.prototype, "emissiveTexture", void 0);
  5837. return FluentMaterial;
  5838. }(BABYLON.PushMaterial));
  5839. GUI.FluentMaterial = FluentMaterial;
  5840. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5841. })(BABYLON || (BABYLON = {}));
  5842. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  5843. var BABYLON;
  5844. (function (BABYLON) {
  5845. var GUI;
  5846. (function (GUI) {
  5847. var Vector3WithInfo = /** @class */ (function (_super) {
  5848. __extends(Vector3WithInfo, _super);
  5849. function Vector3WithInfo(source, buttonIndex) {
  5850. if (buttonIndex === void 0) { buttonIndex = 0; }
  5851. var _this = _super.call(this, source.x, source.y, source.z) || this;
  5852. _this.buttonIndex = buttonIndex;
  5853. return _this;
  5854. }
  5855. return Vector3WithInfo;
  5856. }(BABYLON.Vector3));
  5857. GUI.Vector3WithInfo = Vector3WithInfo;
  5858. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5859. })(BABYLON || (BABYLON = {}));
  5860. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5861. var BABYLON;
  5862. (function (BABYLON) {
  5863. var GUI;
  5864. (function (GUI) {
  5865. /**
  5866. * Class used as base class for controls
  5867. */
  5868. var Control3D = /** @class */ (function () {
  5869. /**
  5870. * Creates a new control
  5871. * @param name defines the control name
  5872. */
  5873. function Control3D(
  5874. /** Defines the control name */
  5875. name) {
  5876. this.name = name;
  5877. this._downCount = 0;
  5878. this._enterCount = 0;
  5879. this._downPointerIds = {};
  5880. this._isVisible = true;
  5881. /**
  5882. * An event triggered when the pointer move over the control.
  5883. */
  5884. this.onPointerMoveObservable = new BABYLON.Observable();
  5885. /**
  5886. * An event triggered when the pointer move out of the control.
  5887. */
  5888. this.onPointerOutObservable = new BABYLON.Observable();
  5889. /**
  5890. * An event triggered when the pointer taps the control
  5891. */
  5892. this.onPointerDownObservable = new BABYLON.Observable();
  5893. /**
  5894. * An event triggered when pointer up
  5895. */
  5896. this.onPointerUpObservable = new BABYLON.Observable();
  5897. /**
  5898. * An event triggered when a control is clicked on
  5899. */
  5900. this.onPointerClickObservable = new BABYLON.Observable();
  5901. /**
  5902. * An event triggered when pointer enters the control
  5903. */
  5904. this.onPointerEnterObservable = new BABYLON.Observable();
  5905. // Behaviors
  5906. this._behaviors = new Array();
  5907. }
  5908. Object.defineProperty(Control3D.prototype, "behaviors", {
  5909. /**
  5910. * Gets the list of attached behaviors
  5911. * @see http://doc.babylonjs.com/features/behaviour
  5912. */
  5913. get: function () {
  5914. return this._behaviors;
  5915. },
  5916. enumerable: true,
  5917. configurable: true
  5918. });
  5919. /**
  5920. * Attach a behavior to the control
  5921. * @see http://doc.babylonjs.com/features/behaviour
  5922. * @param behavior defines the behavior to attach
  5923. * @returns the current control
  5924. */
  5925. Control3D.prototype.addBehavior = function (behavior) {
  5926. var _this = this;
  5927. var index = this._behaviors.indexOf(behavior);
  5928. if (index !== -1) {
  5929. return this;
  5930. }
  5931. behavior.init();
  5932. var scene = this._host.scene;
  5933. if (scene.isLoading) {
  5934. // We defer the attach when the scene will be loaded
  5935. scene.onDataLoadedObservable.addOnce(function () {
  5936. behavior.attach(_this);
  5937. });
  5938. }
  5939. else {
  5940. behavior.attach(this);
  5941. }
  5942. this._behaviors.push(behavior);
  5943. return this;
  5944. };
  5945. /**
  5946. * Remove an attached behavior
  5947. * @see http://doc.babylonjs.com/features/behaviour
  5948. * @param behavior defines the behavior to attach
  5949. * @returns the current control
  5950. */
  5951. Control3D.prototype.removeBehavior = function (behavior) {
  5952. var index = this._behaviors.indexOf(behavior);
  5953. if (index === -1) {
  5954. return this;
  5955. }
  5956. this._behaviors[index].detach();
  5957. this._behaviors.splice(index, 1);
  5958. return this;
  5959. };
  5960. /**
  5961. * Gets an attached behavior by name
  5962. * @param name defines the name of the behavior to look for
  5963. * @see http://doc.babylonjs.com/features/behaviour
  5964. * @returns null if behavior was not found else the requested behavior
  5965. */
  5966. Control3D.prototype.getBehaviorByName = function (name) {
  5967. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  5968. var behavior = _a[_i];
  5969. if (behavior.name === name) {
  5970. return behavior;
  5971. }
  5972. }
  5973. return null;
  5974. };
  5975. Object.defineProperty(Control3D.prototype, "isVisible", {
  5976. /** Gets or sets a boolean indicating if the control is visible */
  5977. get: function () {
  5978. return this._isVisible;
  5979. },
  5980. set: function (value) {
  5981. if (this._isVisible === value) {
  5982. return;
  5983. }
  5984. this._isVisible = value;
  5985. if (this._mesh) {
  5986. this._mesh.isVisible = value;
  5987. }
  5988. },
  5989. enumerable: true,
  5990. configurable: true
  5991. });
  5992. Object.defineProperty(Control3D.prototype, "position", {
  5993. /** Gets or sets the control position */
  5994. get: function () {
  5995. if (this._mesh) {
  5996. return this._mesh.position;
  5997. }
  5998. return BABYLON.Vector3.Zero();
  5999. },
  6000. set: function (value) {
  6001. if (this._mesh) {
  6002. this._mesh.position = value;
  6003. }
  6004. },
  6005. enumerable: true,
  6006. configurable: true
  6007. });
  6008. Object.defineProperty(Control3D.prototype, "typeName", {
  6009. /**
  6010. * Gets a string representing the class name
  6011. */
  6012. get: function () {
  6013. return this._getTypeName();
  6014. },
  6015. enumerable: true,
  6016. configurable: true
  6017. });
  6018. Control3D.prototype._getTypeName = function () {
  6019. return "Control3D";
  6020. };
  6021. Object.defineProperty(Control3D.prototype, "mesh", {
  6022. /**
  6023. * Gets the mesh used to render this control
  6024. */
  6025. get: function () {
  6026. return this._mesh;
  6027. },
  6028. enumerable: true,
  6029. configurable: true
  6030. });
  6031. /**
  6032. * Link the control as child of the given mesh
  6033. * @param mesh defines the mesh to link to. Use null to unlink the control
  6034. * @returns the current control
  6035. */
  6036. Control3D.prototype.linkToMesh = function (mesh) {
  6037. if (this._mesh) {
  6038. this._mesh.parent = mesh;
  6039. }
  6040. return this;
  6041. };
  6042. /**
  6043. * Get the attached mesh used to render the control
  6044. * @param scene defines the scene where the mesh must be attached
  6045. * @returns the attached mesh or null if none
  6046. */
  6047. Control3D.prototype.prepareMesh = function (scene) {
  6048. if (!this._mesh) {
  6049. this._mesh = this._createMesh(scene);
  6050. this._mesh.isPickable = true;
  6051. this._mesh.metadata = this; // Store the control on the metadata field in order to get it when picking
  6052. this._affectMaterial(this._mesh);
  6053. }
  6054. return this._mesh;
  6055. };
  6056. /**
  6057. * Mesh creation.
  6058. * Can be overriden by children
  6059. * @param scene defines the scene where the mesh must be attached
  6060. * @returns the attached mesh or null if none
  6061. */
  6062. Control3D.prototype._createMesh = function (scene) {
  6063. // Do nothing by default
  6064. return null;
  6065. };
  6066. /**
  6067. * Affect a material to the given mesh
  6068. * @param mesh defines the mesh which will represent the control
  6069. */
  6070. Control3D.prototype._affectMaterial = function (mesh) {
  6071. mesh.material = null;
  6072. };
  6073. // Pointers
  6074. /** @hidden */
  6075. Control3D.prototype._onPointerMove = function (target, coordinates) {
  6076. this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  6077. };
  6078. /** @hidden */
  6079. Control3D.prototype._onPointerEnter = function (target) {
  6080. if (this._enterCount !== 0) {
  6081. return false;
  6082. }
  6083. this._enterCount++;
  6084. this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  6085. if (this.pointerEnterAnimation) {
  6086. this.pointerEnterAnimation();
  6087. }
  6088. return true;
  6089. };
  6090. /** @hidden */
  6091. Control3D.prototype._onPointerOut = function (target) {
  6092. this._enterCount = 0;
  6093. this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  6094. if (this.pointerOutAnimation) {
  6095. this.pointerOutAnimation();
  6096. }
  6097. };
  6098. /** @hidden */
  6099. Control3D.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  6100. if (this._downCount !== 0) {
  6101. return false;
  6102. }
  6103. this._downCount++;
  6104. this._downPointerIds[pointerId] = true;
  6105. this.onPointerDownObservable.notifyObservers(new GUI.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  6106. if (this.pointerDownAnimation) {
  6107. this.pointerDownAnimation();
  6108. }
  6109. return true;
  6110. };
  6111. /** @hidden */
  6112. Control3D.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  6113. this._downCount = 0;
  6114. delete this._downPointerIds[pointerId];
  6115. if (notifyClick && this._enterCount > 0) {
  6116. this.onPointerClickObservable.notifyObservers(new GUI.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  6117. }
  6118. this.onPointerUpObservable.notifyObservers(new GUI.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  6119. if (this.pointerUpAnimation) {
  6120. this.pointerUpAnimation();
  6121. }
  6122. };
  6123. /** @hidden */
  6124. Control3D.prototype.forcePointerUp = function (pointerId) {
  6125. if (pointerId === void 0) { pointerId = null; }
  6126. if (pointerId !== null) {
  6127. this._onPointerUp(this, BABYLON.Vector3.Zero(), pointerId, 0, true);
  6128. }
  6129. else {
  6130. for (var key in this._downPointerIds) {
  6131. this._onPointerUp(this, BABYLON.Vector3.Zero(), +key, 0, true);
  6132. }
  6133. }
  6134. };
  6135. /** @hidden */
  6136. Control3D.prototype._processObservables = function (type, pickedPoint, pointerId, buttonIndex) {
  6137. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  6138. this._onPointerMove(this, pickedPoint);
  6139. var previousControlOver = this._host._lastControlOver[pointerId];
  6140. if (previousControlOver && previousControlOver !== this) {
  6141. previousControlOver._onPointerOut(this);
  6142. }
  6143. if (previousControlOver !== this) {
  6144. this._onPointerEnter(this);
  6145. }
  6146. this._host._lastControlOver[pointerId] = this;
  6147. return true;
  6148. }
  6149. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  6150. this._onPointerDown(this, pickedPoint, pointerId, buttonIndex);
  6151. this._host._lastControlDown[pointerId] = this;
  6152. this._host._lastPickedControl = this;
  6153. return true;
  6154. }
  6155. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  6156. if (this._host._lastControlDown[pointerId]) {
  6157. this._host._lastControlDown[pointerId]._onPointerUp(this, pickedPoint, pointerId, buttonIndex, true);
  6158. }
  6159. delete this._host._lastControlDown[pointerId];
  6160. return true;
  6161. }
  6162. return false;
  6163. };
  6164. /**
  6165. * Releases all associated resources
  6166. */
  6167. Control3D.prototype.dispose = function () {
  6168. this.onPointerDownObservable.clear();
  6169. this.onPointerEnterObservable.clear();
  6170. this.onPointerMoveObservable.clear();
  6171. this.onPointerOutObservable.clear();
  6172. this.onPointerUpObservable.clear();
  6173. this.onPointerClickObservable.clear();
  6174. if (this._mesh) {
  6175. this._mesh.dispose(false, true);
  6176. this._mesh = null;
  6177. }
  6178. // Behaviors
  6179. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  6180. var behavior = _a[_i];
  6181. behavior.detach();
  6182. }
  6183. };
  6184. return Control3D;
  6185. }());
  6186. GUI.Control3D = Control3D;
  6187. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6188. })(BABYLON || (BABYLON = {}));
  6189. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  6190. var BABYLON;
  6191. (function (BABYLON) {
  6192. var GUI;
  6193. (function (GUI) {
  6194. /**
  6195. * Class used to create containers for controls
  6196. */
  6197. var Container3D = /** @class */ (function (_super) {
  6198. __extends(Container3D, _super);
  6199. /**
  6200. * Creates a new container
  6201. * @param name defines the container name
  6202. */
  6203. function Container3D(name) {
  6204. var _this = _super.call(this, name) || this;
  6205. _this._children = new Array();
  6206. return _this;
  6207. }
  6208. /**
  6209. * Gets a boolean indicating if the given control is in the children of this control
  6210. * @param control defines the control to check
  6211. * @returns true if the control is in the child list
  6212. */
  6213. Container3D.prototype.containsControl = function (control) {
  6214. return this._children.indexOf(control) !== -1;
  6215. };
  6216. /**
  6217. * Adds a control to the children of this control
  6218. * @param control defines the control to add
  6219. * @returns the current container
  6220. */
  6221. Container3D.prototype.addControl = function (control) {
  6222. var index = this._children.indexOf(control);
  6223. if (index !== -1) {
  6224. return this;
  6225. }
  6226. control.parent = this;
  6227. control._host = this._host;
  6228. if (this._host.utilityLayer) {
  6229. control.prepareMesh(this._host.utilityLayer.utilityLayerScene);
  6230. }
  6231. return this;
  6232. };
  6233. /**
  6234. * Removes the control from the children of this control
  6235. * @param control defines the control to remove
  6236. * @returns the current container
  6237. */
  6238. Container3D.prototype.removeControl = function (control) {
  6239. var index = this._children.indexOf(control);
  6240. if (index !== -1) {
  6241. this._children.splice(index, 1);
  6242. control.parent = null;
  6243. }
  6244. return this;
  6245. };
  6246. Container3D.prototype._getTypeName = function () {
  6247. return "Container3D";
  6248. };
  6249. /**
  6250. * Releases all associated resources
  6251. */
  6252. Container3D.prototype.dispose = function () {
  6253. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  6254. var control = _a[_i];
  6255. control.dispose();
  6256. }
  6257. this._children = [];
  6258. _super.prototype.dispose.call(this);
  6259. };
  6260. return Container3D;
  6261. }(GUI.Control3D));
  6262. GUI.Container3D = Container3D;
  6263. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6264. })(BABYLON || (BABYLON = {}));
  6265. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  6266. var BABYLON;
  6267. (function (BABYLON) {
  6268. var GUI;
  6269. (function (GUI) {
  6270. /**
  6271. * Class used to create a button in 3D
  6272. */
  6273. var Button3D = /** @class */ (function (_super) {
  6274. __extends(Button3D, _super);
  6275. /**
  6276. * Creates a new button
  6277. * @param name defines the control name
  6278. */
  6279. function Button3D(name) {
  6280. var _this = _super.call(this, name) || this;
  6281. // Default animations
  6282. _this.pointerEnterAnimation = function () {
  6283. if (!_this.mesh) {
  6284. return;
  6285. }
  6286. _this._currentMaterial.emissiveColor = BABYLON.Color3.Red();
  6287. };
  6288. _this.pointerOutAnimation = function () {
  6289. _this._currentMaterial.emissiveColor = BABYLON.Color3.Black();
  6290. };
  6291. _this.pointerDownAnimation = function () {
  6292. if (!_this.mesh) {
  6293. return;
  6294. }
  6295. _this.mesh.scaling.scaleInPlace(0.95);
  6296. };
  6297. _this.pointerUpAnimation = function () {
  6298. if (!_this.mesh) {
  6299. return;
  6300. }
  6301. _this.mesh.scaling.scaleInPlace(1.0 / 0.95);
  6302. };
  6303. return _this;
  6304. }
  6305. Object.defineProperty(Button3D.prototype, "content", {
  6306. /**
  6307. * Gets or sets the GUI 2D content used to display the button's facade
  6308. */
  6309. get: function () {
  6310. return this._content;
  6311. },
  6312. set: function (value) {
  6313. if (!this._host || !this._host.utilityLayer) {
  6314. return;
  6315. }
  6316. if (!this._facadeTexture) {
  6317. this._facadeTexture = new BABYLON.GUI.AdvancedDynamicTexture("Facade", 512, 512, this._host.utilityLayer.utilityLayerScene, true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  6318. this._facadeTexture.rootContainer.scaleX = 2;
  6319. this._facadeTexture.rootContainer.scaleY = 2;
  6320. this._facadeTexture.premulAlpha = true;
  6321. }
  6322. this._facadeTexture.addControl(value);
  6323. this._currentMaterial.emissiveTexture = this._facadeTexture;
  6324. },
  6325. enumerable: true,
  6326. configurable: true
  6327. });
  6328. Button3D.prototype._getTypeName = function () {
  6329. return "Button3D";
  6330. };
  6331. // Mesh association
  6332. Button3D.prototype._createMesh = function (scene) {
  6333. var faceUV = new Array(6);
  6334. for (var i = 0; i < 6; i++) {
  6335. faceUV[i] = new BABYLON.Vector4(0, 0, 0, 0);
  6336. }
  6337. faceUV[1] = new BABYLON.Vector4(0, 0, 1, 1);
  6338. var mesh = BABYLON.MeshBuilder.CreateBox(this.name + "Mesh", {
  6339. width: 1.0,
  6340. height: 1.0,
  6341. depth: 0.1,
  6342. faceUV: faceUV
  6343. }, scene);
  6344. return mesh;
  6345. };
  6346. Button3D.prototype._affectMaterial = function (mesh) {
  6347. var material = new BABYLON.StandardMaterial(this.name + "Material", mesh.getScene());
  6348. material.specularColor = BABYLON.Color3.Black();
  6349. mesh.material = material;
  6350. this._currentMaterial = material;
  6351. };
  6352. return Button3D;
  6353. }(GUI.Control3D));
  6354. GUI.Button3D = Button3D;
  6355. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6356. })(BABYLON || (BABYLON = {}));
  6357. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  6358. var BABYLON;
  6359. (function (BABYLON) {
  6360. var GUI;
  6361. (function (GUI) {
  6362. /**
  6363. * Class used to create a button in 3D
  6364. */
  6365. var HolographicButton = /** @class */ (function (_super) {
  6366. __extends(HolographicButton, _super);
  6367. /**
  6368. * Creates a new button
  6369. * @param name defines the control name
  6370. */
  6371. function HolographicButton(name) {
  6372. var _this = _super.call(this, name) || this;
  6373. // Default animations
  6374. _this.pointerEnterAnimation = function () {
  6375. if (!_this.mesh) {
  6376. return;
  6377. }
  6378. _this.mesh.edgesRenderer.isEnabled = true;
  6379. };
  6380. _this.pointerOutAnimation = function () {
  6381. if (!_this.mesh) {
  6382. return;
  6383. }
  6384. _this.mesh.edgesRenderer.isEnabled = false;
  6385. };
  6386. return _this;
  6387. }
  6388. HolographicButton.prototype._getTypeName = function () {
  6389. return "HolographicButton";
  6390. };
  6391. // Mesh association
  6392. HolographicButton.prototype._createMesh = function (scene) {
  6393. var mesh = _super.prototype._createMesh.call(this, scene);
  6394. mesh.edgesWidth = 0.5;
  6395. mesh.edgesColor = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
  6396. mesh.enableEdgesRendering();
  6397. mesh.edgesRenderer.isEnabled = false;
  6398. return mesh;
  6399. };
  6400. HolographicButton.prototype._affectMaterial = function (mesh) {
  6401. this._currentMaterial = new GUI.FluentMaterial(this.name + "Material", mesh.getScene());
  6402. mesh.material = this._currentMaterial;
  6403. };
  6404. return HolographicButton;
  6405. }(GUI.Button3D));
  6406. GUI.HolographicButton = HolographicButton;
  6407. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6408. })(BABYLON || (BABYLON = {}));
  6409. return BABYLON.GUI;
  6410. });