babylon.gui.js 348 KB

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