babylon.gui.js 443 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-gui", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-gui"] = factory(require("babylonjs"));
  8. else
  9. root["BABYLON"] = root["BABYLON"] || {}, root["BABYLON"]["GUI"] = factory(root["BABYLON"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./src/legacy.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../node_modules/webpack/buildin/global.js":
  99. /*!*************************************************!*\
  100. !*** ../node_modules/webpack/buildin/global.js ***!
  101. \*************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || Function("return this")() || (1, eval)("this");
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./src/2D/advancedDynamicTexture.ts":
  122. /*!******************************************!*\
  123. !*** ./src/2D/advancedDynamicTexture.ts ***!
  124. \******************************************/
  125. /*! no static exports found */
  126. /***/ (function(module, exports, __webpack_require__) {
  127. "use strict";
  128. var __extends = (this && this.__extends) || (function () {
  129. var extendStatics = function (d, b) {
  130. extendStatics = Object.setPrototypeOf ||
  131. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  132. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  133. return extendStatics(d, b);
  134. }
  135. return function (d, b) {
  136. extendStatics(d, b);
  137. function __() { this.constructor = d; }
  138. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  139. };
  140. })();
  141. Object.defineProperty(exports, "__esModule", { value: true });
  142. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  143. var container_1 = __webpack_require__(/*! ./controls/container */ "./src/2D/controls/container.ts");
  144. var style_1 = __webpack_require__(/*! ./style */ "./src/2D/style.ts");
  145. var measure_1 = __webpack_require__(/*! ./measure */ "./src/2D/measure.ts");
  146. /**
  147. * Class used to create texture to support 2D GUI elements
  148. * @see http://doc.babylonjs.com/how_to/gui
  149. */
  150. var AdvancedDynamicTexture = /** @class */ (function (_super) {
  151. __extends(AdvancedDynamicTexture, _super);
  152. /**
  153. * Creates a new AdvancedDynamicTexture
  154. * @param name defines the name of the texture
  155. * @param width defines the width of the texture
  156. * @param height defines the height of the texture
  157. * @param scene defines the hosting scene
  158. * @param generateMipMaps defines a boolean indicating if mipmaps must be generated (false by default)
  159. * @param samplingMode defines the texture sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
  160. */
  161. function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode) {
  162. if (width === void 0) { width = 0; }
  163. if (height === void 0) { height = 0; }
  164. if (generateMipMaps === void 0) { generateMipMaps = false; }
  165. if (samplingMode === void 0) { samplingMode = babylonjs_1.Texture.NEAREST_SAMPLINGMODE; }
  166. var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, babylonjs_1.Engine.TEXTUREFORMAT_RGBA) || this;
  167. _this._isDirty = false;
  168. /** @hidden */
  169. _this._rootContainer = new container_1.Container("root");
  170. /** @hidden */
  171. _this._lastControlOver = {};
  172. /** @hidden */
  173. _this._lastControlDown = {};
  174. /** @hidden */
  175. _this._capturingControl = {};
  176. /** @hidden */
  177. _this._linkedControls = new Array();
  178. _this._isFullscreen = false;
  179. _this._fullscreenViewport = new babylonjs_1.Viewport(0, 0, 1, 1);
  180. _this._idealWidth = 0;
  181. _this._idealHeight = 0;
  182. _this._useSmallestIdeal = false;
  183. _this._renderAtIdealSize = false;
  184. _this._blockNextFocusCheck = false;
  185. _this._renderScale = 1;
  186. /**
  187. * Gets or sets a boolean defining if alpha is stored as premultiplied
  188. */
  189. _this.premulAlpha = false;
  190. scene = _this.getScene();
  191. if (!scene || !_this._texture) {
  192. return _this;
  193. }
  194. _this._rootCanvas = scene.getEngine().getRenderingCanvas();
  195. _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
  196. _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
  197. if (!_this._focusedControl) {
  198. return;
  199. }
  200. if (info.type === babylonjs_1.KeyboardEventTypes.KEYDOWN) {
  201. _this._focusedControl.processKeyboard(info.event);
  202. }
  203. info.skipOnPointerObservable = true;
  204. });
  205. _this._rootContainer._link(null, _this);
  206. _this.hasAlpha = true;
  207. if (!width || !height) {
  208. _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
  209. _this._onResize();
  210. }
  211. _this._texture.isReady = true;
  212. return _this;
  213. }
  214. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
  215. /**
  216. * Gets or sets a number used to scale rendering size (2 means that the texture will be twice bigger).
  217. * Useful when you want more antialiasing
  218. */
  219. get: function () {
  220. return this._renderScale;
  221. },
  222. set: function (value) {
  223. if (value === this._renderScale) {
  224. return;
  225. }
  226. this._renderScale = value;
  227. this._onResize();
  228. },
  229. enumerable: true,
  230. configurable: true
  231. });
  232. Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
  233. /** Gets or sets the background color */
  234. get: function () {
  235. return this._background;
  236. },
  237. set: function (value) {
  238. if (this._background === value) {
  239. return;
  240. }
  241. this._background = value;
  242. this.markAsDirty();
  243. },
  244. enumerable: true,
  245. configurable: true
  246. });
  247. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
  248. /**
  249. * Gets or sets the ideal width used to design controls.
  250. * The GUI will then rescale everything accordingly
  251. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  252. */
  253. get: function () {
  254. return this._idealWidth;
  255. },
  256. set: function (value) {
  257. if (this._idealWidth === value) {
  258. return;
  259. }
  260. this._idealWidth = value;
  261. this.markAsDirty();
  262. this._rootContainer._markAllAsDirty();
  263. },
  264. enumerable: true,
  265. configurable: true
  266. });
  267. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
  268. /**
  269. * Gets or sets the ideal height used to design controls.
  270. * The GUI will then rescale everything accordingly
  271. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  272. */
  273. get: function () {
  274. return this._idealHeight;
  275. },
  276. set: function (value) {
  277. if (this._idealHeight === value) {
  278. return;
  279. }
  280. this._idealHeight = value;
  281. this.markAsDirty();
  282. this._rootContainer._markAllAsDirty();
  283. },
  284. enumerable: true,
  285. configurable: true
  286. });
  287. Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
  288. /**
  289. * Gets or sets a boolean indicating if the smallest ideal value must be used if idealWidth and idealHeight are both set
  290. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  291. */
  292. get: function () {
  293. return this._useSmallestIdeal;
  294. },
  295. set: function (value) {
  296. if (this._useSmallestIdeal === value) {
  297. return;
  298. }
  299. this._useSmallestIdeal = value;
  300. this.markAsDirty();
  301. this._rootContainer._markAllAsDirty();
  302. },
  303. enumerable: true,
  304. configurable: true
  305. });
  306. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
  307. /**
  308. * Gets or sets a boolean indicating if adaptive scaling must be used
  309. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  310. */
  311. get: function () {
  312. return this._renderAtIdealSize;
  313. },
  314. set: function (value) {
  315. if (this._renderAtIdealSize === value) {
  316. return;
  317. }
  318. this._renderAtIdealSize = value;
  319. this._onResize();
  320. },
  321. enumerable: true,
  322. configurable: true
  323. });
  324. Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
  325. /**
  326. * Gets the underlying layer used to render the texture when in fullscreen mode
  327. */
  328. get: function () {
  329. return this._layerToDispose;
  330. },
  331. enumerable: true,
  332. configurable: true
  333. });
  334. Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
  335. /**
  336. * Gets the root container control
  337. */
  338. get: function () {
  339. return this._rootContainer;
  340. },
  341. enumerable: true,
  342. configurable: true
  343. });
  344. Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
  345. /**
  346. * Gets or sets the current focused control
  347. */
  348. get: function () {
  349. return this._focusedControl;
  350. },
  351. set: function (control) {
  352. if (this._focusedControl == control) {
  353. return;
  354. }
  355. if (this._focusedControl) {
  356. this._focusedControl.onBlur();
  357. }
  358. if (control) {
  359. control.onFocus();
  360. }
  361. this._focusedControl = control;
  362. },
  363. enumerable: true,
  364. configurable: true
  365. });
  366. Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
  367. /**
  368. * Gets or sets a boolean indicating if the texture must be rendered in background or foreground when in fullscreen mode
  369. */
  370. get: function () {
  371. if (!this.layer) {
  372. return true;
  373. }
  374. return (!this.layer.isBackground);
  375. },
  376. set: function (value) {
  377. if (!this.layer) {
  378. return;
  379. }
  380. if (this.layer.isBackground === !value) {
  381. return;
  382. }
  383. this.layer.isBackground = !value;
  384. },
  385. enumerable: true,
  386. configurable: true
  387. });
  388. /**
  389. * Function used to execute a function on all controls
  390. * @param func defines the function to execute
  391. * @param container defines the container where controls belong. If null the root container will be used
  392. */
  393. AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
  394. if (!container) {
  395. container = this._rootContainer;
  396. }
  397. func(container);
  398. for (var _i = 0, _a = container.children; _i < _a.length; _i++) {
  399. var child = _a[_i];
  400. if (child.children) {
  401. this.executeOnAllControls(func, child);
  402. continue;
  403. }
  404. func(child);
  405. }
  406. };
  407. /**
  408. * Marks the texture as dirty forcing a complete update
  409. */
  410. AdvancedDynamicTexture.prototype.markAsDirty = function () {
  411. this._isDirty = true;
  412. };
  413. /**
  414. * Helper function used to create a new style
  415. * @returns a new style
  416. * @see http://doc.babylonjs.com/how_to/gui#styles
  417. */
  418. AdvancedDynamicTexture.prototype.createStyle = function () {
  419. return new style_1.Style(this);
  420. };
  421. /**
  422. * Adds a new control to the root container
  423. * @param control defines the control to add
  424. * @returns the current texture
  425. */
  426. AdvancedDynamicTexture.prototype.addControl = function (control) {
  427. this._rootContainer.addControl(control);
  428. return this;
  429. };
  430. /**
  431. * Removes a control from the root container
  432. * @param control defines the control to remove
  433. * @returns the current texture
  434. */
  435. AdvancedDynamicTexture.prototype.removeControl = function (control) {
  436. this._rootContainer.removeControl(control);
  437. return this;
  438. };
  439. /**
  440. * Release all resources
  441. */
  442. AdvancedDynamicTexture.prototype.dispose = function () {
  443. var scene = this.getScene();
  444. if (!scene) {
  445. return;
  446. }
  447. this._rootCanvas = null;
  448. scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
  449. if (this._resizeObserver) {
  450. scene.getEngine().onResizeObservable.remove(this._resizeObserver);
  451. }
  452. if (this._pointerMoveObserver) {
  453. scene.onPrePointerObservable.remove(this._pointerMoveObserver);
  454. }
  455. if (this._pointerObserver) {
  456. scene.onPointerObservable.remove(this._pointerObserver);
  457. }
  458. if (this._preKeyboardObserver) {
  459. scene.onPreKeyboardObservable.remove(this._preKeyboardObserver);
  460. }
  461. if (this._canvasPointerOutObserver) {
  462. scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
  463. }
  464. if (this._layerToDispose) {
  465. this._layerToDispose.texture = null;
  466. this._layerToDispose.dispose();
  467. this._layerToDispose = null;
  468. }
  469. this._rootContainer.dispose();
  470. _super.prototype.dispose.call(this);
  471. };
  472. AdvancedDynamicTexture.prototype._onResize = function () {
  473. var scene = this.getScene();
  474. if (!scene) {
  475. return;
  476. }
  477. // Check size
  478. var engine = scene.getEngine();
  479. var textureSize = this.getSize();
  480. var renderWidth = engine.getRenderWidth() * this._renderScale;
  481. var renderHeight = engine.getRenderHeight() * this._renderScale;
  482. if (this._renderAtIdealSize) {
  483. if (this._idealWidth) {
  484. renderHeight = (renderHeight * this._idealWidth) / renderWidth;
  485. renderWidth = this._idealWidth;
  486. }
  487. else if (this._idealHeight) {
  488. renderWidth = (renderWidth * this._idealHeight) / renderHeight;
  489. renderHeight = this._idealHeight;
  490. }
  491. }
  492. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  493. this.scaleTo(renderWidth, renderHeight);
  494. this.markAsDirty();
  495. if (this._idealWidth || this._idealHeight) {
  496. this._rootContainer._markAllAsDirty();
  497. }
  498. }
  499. };
  500. /** @hidden */
  501. AdvancedDynamicTexture.prototype._getGlobalViewport = function (scene) {
  502. var engine = scene.getEngine();
  503. return this._fullscreenViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  504. };
  505. /**
  506. * Get screen coordinates for a vector3
  507. * @param position defines the position to project
  508. * @param worldMatrix defines the world matrix to use
  509. * @returns the projected position
  510. */
  511. AdvancedDynamicTexture.prototype.getProjectedPosition = function (position, worldMatrix) {
  512. var scene = this.getScene();
  513. if (!scene) {
  514. return babylonjs_1.Vector2.Zero();
  515. }
  516. var globalViewport = this._getGlobalViewport(scene);
  517. var projectedPosition = babylonjs_1.Vector3.Project(position, worldMatrix, scene.getTransformMatrix(), globalViewport);
  518. projectedPosition.scaleInPlace(this.renderScale);
  519. return new babylonjs_1.Vector2(projectedPosition.x, projectedPosition.y);
  520. };
  521. AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
  522. if (this._layerToDispose) {
  523. if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
  524. return;
  525. }
  526. }
  527. if (this._isFullscreen && this._linkedControls.length) {
  528. var scene = this.getScene();
  529. if (!scene) {
  530. return;
  531. }
  532. var globalViewport = this._getGlobalViewport(scene);
  533. for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
  534. var control = _a[_i];
  535. if (!control.isVisible) {
  536. continue;
  537. }
  538. var mesh = control._linkedMesh;
  539. if (!mesh || mesh.isDisposed()) {
  540. babylonjs_1.Tools.SetImmediate(function () {
  541. control.linkWithMesh(null);
  542. });
  543. continue;
  544. }
  545. var position = mesh.getBoundingInfo().boundingSphere.center;
  546. var projectedPosition = babylonjs_1.Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
  547. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  548. control.notRenderable = true;
  549. continue;
  550. }
  551. control.notRenderable = false;
  552. // Account for RenderScale.
  553. projectedPosition.scaleInPlace(this.renderScale);
  554. control._moveToProjectedPosition(projectedPosition);
  555. }
  556. }
  557. if (!this._isDirty && !this._rootContainer.isDirty) {
  558. return;
  559. }
  560. this._isDirty = false;
  561. this._render();
  562. this.update(true, this.premulAlpha);
  563. };
  564. AdvancedDynamicTexture.prototype._render = function () {
  565. var textureSize = this.getSize();
  566. var renderWidth = textureSize.width;
  567. var renderHeight = textureSize.height;
  568. // Clear
  569. var context = this.getContext();
  570. context.clearRect(0, 0, renderWidth, renderHeight);
  571. if (this._background) {
  572. context.save();
  573. context.fillStyle = this._background;
  574. context.fillRect(0, 0, renderWidth, renderHeight);
  575. context.restore();
  576. }
  577. // Render
  578. context.font = "18px Arial";
  579. context.strokeStyle = "white";
  580. var measure = new measure_1.Measure(0, 0, renderWidth, renderHeight);
  581. this._rootContainer._draw(measure, context);
  582. };
  583. /** @hidden */
  584. AdvancedDynamicTexture.prototype._changeCursor = function (cursor) {
  585. if (this._rootCanvas) {
  586. this._rootCanvas.style.cursor = cursor;
  587. }
  588. };
  589. AdvancedDynamicTexture.prototype._doPicking = function (x, y, type, pointerId, buttonIndex) {
  590. var scene = this.getScene();
  591. if (!scene) {
  592. return;
  593. }
  594. var engine = scene.getEngine();
  595. var textureSize = this.getSize();
  596. if (this._isFullscreen) {
  597. x = x * (textureSize.width / engine.getRenderWidth());
  598. y = y * (textureSize.height / engine.getRenderHeight());
  599. }
  600. if (this._capturingControl[pointerId]) {
  601. this._capturingControl[pointerId]._processObservables(type, x, y, pointerId, buttonIndex);
  602. return;
  603. }
  604. if (!this._rootContainer._processPicking(x, y, type, pointerId, buttonIndex)) {
  605. this._changeCursor("");
  606. if (type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  607. if (this._lastControlOver[pointerId]) {
  608. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  609. }
  610. delete this._lastControlOver[pointerId];
  611. }
  612. }
  613. this._manageFocus();
  614. };
  615. /** @hidden */
  616. AdvancedDynamicTexture.prototype._cleanControlAfterRemovalFromList = function (list, control) {
  617. for (var pointerId in list) {
  618. if (!list.hasOwnProperty(pointerId)) {
  619. continue;
  620. }
  621. var lastControlOver = list[pointerId];
  622. if (lastControlOver === control) {
  623. delete list[pointerId];
  624. }
  625. }
  626. };
  627. /** @hidden */
  628. AdvancedDynamicTexture.prototype._cleanControlAfterRemoval = function (control) {
  629. this._cleanControlAfterRemovalFromList(this._lastControlDown, control);
  630. this._cleanControlAfterRemovalFromList(this._lastControlOver, control);
  631. };
  632. /** Attach to all scene events required to support pointer events */
  633. AdvancedDynamicTexture.prototype.attach = function () {
  634. var _this = this;
  635. var scene = this.getScene();
  636. if (!scene) {
  637. return;
  638. }
  639. this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
  640. if (scene.isPointerCaptured((pi.event).pointerId)) {
  641. return;
  642. }
  643. if (pi.type !== babylonjs_1.PointerEventTypes.POINTERMOVE
  644. && pi.type !== babylonjs_1.PointerEventTypes.POINTERUP
  645. && pi.type !== babylonjs_1.PointerEventTypes.POINTERDOWN) {
  646. return;
  647. }
  648. if (!scene) {
  649. return;
  650. }
  651. var camera = scene.cameraToUseForPointers || scene.activeCamera;
  652. if (!camera) {
  653. return;
  654. }
  655. var engine = scene.getEngine();
  656. var viewport = camera.viewport;
  657. var x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
  658. var y = (scene.pointerY / engine.getHardwareScalingLevel() - viewport.y * engine.getRenderHeight()) / viewport.height;
  659. _this._shouldBlockPointer = false;
  660. // Do picking modifies _shouldBlockPointer
  661. _this._doPicking(x, y, pi.type, pi.event.pointerId || 0, pi.event.button);
  662. // Avoid overwriting a true skipOnPointerObservable to false
  663. if (_this._shouldBlockPointer) {
  664. pi.skipOnPointerObservable = _this._shouldBlockPointer;
  665. }
  666. });
  667. this._attachToOnPointerOut(scene);
  668. };
  669. /**
  670. * Connect the texture to a hosting mesh to enable interactions
  671. * @param mesh defines the mesh to attach to
  672. * @param supportPointerMove defines a boolean indicating if pointer move events must be catched as well
  673. */
  674. AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
  675. var _this = this;
  676. if (supportPointerMove === void 0) { supportPointerMove = true; }
  677. var scene = this.getScene();
  678. if (!scene) {
  679. return;
  680. }
  681. this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
  682. if (pi.type !== babylonjs_1.PointerEventTypes.POINTERMOVE
  683. && pi.type !== babylonjs_1.PointerEventTypes.POINTERUP
  684. && pi.type !== babylonjs_1.PointerEventTypes.POINTERDOWN) {
  685. return;
  686. }
  687. var pointerId = pi.event.pointerId || 0;
  688. if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
  689. var uv = pi.pickInfo.getTextureCoordinates();
  690. if (uv) {
  691. var size = _this.getSize();
  692. _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pointerId, pi.event.button);
  693. }
  694. }
  695. else if (pi.type === babylonjs_1.PointerEventTypes.POINTERUP) {
  696. if (_this._lastControlDown[pointerId]) {
  697. _this._lastControlDown[pointerId]._forcePointerUp(pointerId);
  698. }
  699. delete _this._lastControlDown[pointerId];
  700. if (_this.focusedControl) {
  701. var friendlyControls = _this.focusedControl.keepsFocusWith();
  702. var canMoveFocus = true;
  703. if (friendlyControls) {
  704. for (var _i = 0, friendlyControls_1 = friendlyControls; _i < friendlyControls_1.length; _i++) {
  705. var control = friendlyControls_1[_i];
  706. // Same host, no need to keep the focus
  707. if (_this === control._host) {
  708. continue;
  709. }
  710. // Different hosts
  711. var otherHost = control._host;
  712. if (otherHost._lastControlOver[pointerId] && otherHost._lastControlOver[pointerId].isAscendant(control)) {
  713. canMoveFocus = false;
  714. break;
  715. }
  716. }
  717. }
  718. if (canMoveFocus) {
  719. _this.focusedControl = null;
  720. }
  721. }
  722. }
  723. else if (pi.type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  724. if (_this._lastControlOver[pointerId]) {
  725. _this._lastControlOver[pointerId]._onPointerOut(_this._lastControlOver[pointerId]);
  726. }
  727. delete _this._lastControlOver[pointerId];
  728. }
  729. });
  730. mesh.enablePointerMoveEvents = supportPointerMove;
  731. this._attachToOnPointerOut(scene);
  732. };
  733. /**
  734. * Move the focus to a specific control
  735. * @param control defines the control which will receive the focus
  736. */
  737. AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
  738. this.focusedControl = control;
  739. this._lastPickedControl = control;
  740. this._blockNextFocusCheck = true;
  741. };
  742. AdvancedDynamicTexture.prototype._manageFocus = function () {
  743. if (this._blockNextFocusCheck) {
  744. this._blockNextFocusCheck = false;
  745. this._lastPickedControl = this._focusedControl;
  746. return;
  747. }
  748. // Focus management
  749. if (this._focusedControl) {
  750. if (this._focusedControl !== this._lastPickedControl) {
  751. if (this._lastPickedControl.isFocusInvisible) {
  752. return;
  753. }
  754. this.focusedControl = null;
  755. }
  756. }
  757. };
  758. AdvancedDynamicTexture.prototype._attachToOnPointerOut = function (scene) {
  759. var _this = this;
  760. this._canvasPointerOutObserver = scene.getEngine().onCanvasPointerOutObservable.add(function (pointerEvent) {
  761. if (_this._lastControlOver[pointerEvent.pointerId]) {
  762. _this._lastControlOver[pointerEvent.pointerId]._onPointerOut(_this._lastControlOver[pointerEvent.pointerId]);
  763. }
  764. delete _this._lastControlOver[pointerEvent.pointerId];
  765. if (_this._lastControlDown[pointerEvent.pointerId]) {
  766. _this._lastControlDown[pointerEvent.pointerId]._forcePointerUp();
  767. }
  768. delete _this._lastControlDown[pointerEvent.pointerId];
  769. });
  770. };
  771. // Statics
  772. /**
  773. * Creates a new AdvancedDynamicTexture in projected mode (ie. attached to a mesh)
  774. * @param mesh defines the mesh which will receive the texture
  775. * @param width defines the texture width (1024 by default)
  776. * @param height defines the texture height (1024 by default)
  777. * @param supportPointerMove defines a boolean indicating if the texture must capture move events (true by default)
  778. * @param onlyAlphaTesting defines a boolean indicating that alpha blending will not be used (only alpha testing) (false by default)
  779. * @returns a new AdvancedDynamicTexture
  780. */
  781. AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height, supportPointerMove, onlyAlphaTesting) {
  782. if (width === void 0) { width = 1024; }
  783. if (height === void 0) { height = 1024; }
  784. if (supportPointerMove === void 0) { supportPointerMove = true; }
  785. if (onlyAlphaTesting === void 0) { onlyAlphaTesting = false; }
  786. var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, babylonjs_1.Texture.TRILINEAR_SAMPLINGMODE);
  787. var material = new babylonjs_1.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
  788. material.backFaceCulling = false;
  789. material.diffuseColor = babylonjs_1.Color3.Black();
  790. material.specularColor = babylonjs_1.Color3.Black();
  791. if (onlyAlphaTesting) {
  792. material.diffuseTexture = result;
  793. material.emissiveTexture = result;
  794. result.hasAlpha = true;
  795. }
  796. else {
  797. material.emissiveTexture = result;
  798. material.opacityTexture = result;
  799. }
  800. mesh.material = material;
  801. result.attachToMesh(mesh, supportPointerMove);
  802. return result;
  803. };
  804. /**
  805. * Creates a new AdvancedDynamicTexture in fullscreen mode.
  806. * In this mode the texture will rely on a layer for its rendering.
  807. * This allows it to be treated like any other layer.
  808. * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
  809. * LayerMask is set through advancedTexture.layer.layerMask
  810. * @param name defines name for the texture
  811. * @param foreground defines a boolean indicating if the texture must be rendered in foreground (default is true)
  812. * @param scene defines the hsoting scene
  813. * @param sampling defines the texture sampling mode (Texture.BILINEAR_SAMPLINGMODE by default)
  814. * @returns a new AdvancedDynamicTexture
  815. */
  816. AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling) {
  817. if (foreground === void 0) { foreground = true; }
  818. if (scene === void 0) { scene = null; }
  819. if (sampling === void 0) { sampling = babylonjs_1.Texture.BILINEAR_SAMPLINGMODE; }
  820. var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, sampling);
  821. // Display
  822. var layer = new babylonjs_1.Layer(name + "_layer", null, scene, !foreground);
  823. layer.texture = result;
  824. result._layerToDispose = layer;
  825. result._isFullscreen = true;
  826. // Attach
  827. result.attach();
  828. return result;
  829. };
  830. return AdvancedDynamicTexture;
  831. }(babylonjs_1.DynamicTexture));
  832. exports.AdvancedDynamicTexture = AdvancedDynamicTexture;
  833. /***/ }),
  834. /***/ "./src/2D/controls/button.ts":
  835. /*!***********************************!*\
  836. !*** ./src/2D/controls/button.ts ***!
  837. \***********************************/
  838. /*! no static exports found */
  839. /***/ (function(module, exports, __webpack_require__) {
  840. "use strict";
  841. var __extends = (this && this.__extends) || (function () {
  842. var extendStatics = function (d, b) {
  843. extendStatics = Object.setPrototypeOf ||
  844. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  845. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  846. return extendStatics(d, b);
  847. }
  848. return function (d, b) {
  849. extendStatics(d, b);
  850. function __() { this.constructor = d; }
  851. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  852. };
  853. })();
  854. Object.defineProperty(exports, "__esModule", { value: true });
  855. var rectangle_1 = __webpack_require__(/*! ./rectangle */ "./src/2D/controls/rectangle.ts");
  856. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  857. var textBlock_1 = __webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts");
  858. var image_1 = __webpack_require__(/*! ./image */ "./src/2D/controls/image.ts");
  859. /**
  860. * Class used to create 2D buttons
  861. */
  862. var Button = /** @class */ (function (_super) {
  863. __extends(Button, _super);
  864. /**
  865. * Creates a new Button
  866. * @param name defines the name of the button
  867. */
  868. function Button(name) {
  869. var _this = _super.call(this, name) || this;
  870. _this.name = name;
  871. _this.thickness = 1;
  872. _this.isPointerBlocker = true;
  873. _this.pointerEnterAnimation = function () {
  874. _this.alpha -= 0.1;
  875. };
  876. _this.pointerOutAnimation = function () {
  877. _this.alpha += 0.1;
  878. };
  879. _this.pointerDownAnimation = function () {
  880. _this.scaleX -= 0.05;
  881. _this.scaleY -= 0.05;
  882. };
  883. _this.pointerUpAnimation = function () {
  884. _this.scaleX += 0.05;
  885. _this.scaleY += 0.05;
  886. };
  887. return _this;
  888. }
  889. Object.defineProperty(Button.prototype, "image", {
  890. /**
  891. * Returns the image part of the button (if any)
  892. */
  893. get: function () {
  894. return this._image;
  895. },
  896. enumerable: true,
  897. configurable: true
  898. });
  899. Object.defineProperty(Button.prototype, "textBlock", {
  900. /**
  901. * Returns the image part of the button (if any)
  902. */
  903. get: function () {
  904. return this._textBlock;
  905. },
  906. enumerable: true,
  907. configurable: true
  908. });
  909. Button.prototype._getTypeName = function () {
  910. return "Button";
  911. };
  912. // While being a container, the button behaves like a control.
  913. /** @hidden */
  914. Button.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  915. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  916. return false;
  917. }
  918. if (!_super.prototype.contains.call(this, x, y)) {
  919. return false;
  920. }
  921. this._processObservables(type, x, y, pointerId, buttonIndex);
  922. return true;
  923. };
  924. /** @hidden */
  925. Button.prototype._onPointerEnter = function (target) {
  926. if (!_super.prototype._onPointerEnter.call(this, target)) {
  927. return false;
  928. }
  929. if (this.pointerEnterAnimation) {
  930. this.pointerEnterAnimation();
  931. }
  932. return true;
  933. };
  934. /** @hidden */
  935. Button.prototype._onPointerOut = function (target) {
  936. if (this.pointerOutAnimation) {
  937. this.pointerOutAnimation();
  938. }
  939. _super.prototype._onPointerOut.call(this, target);
  940. };
  941. /** @hidden */
  942. Button.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  943. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  944. return false;
  945. }
  946. if (this.pointerDownAnimation) {
  947. this.pointerDownAnimation();
  948. }
  949. return true;
  950. };
  951. /** @hidden */
  952. Button.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  953. if (this.pointerUpAnimation) {
  954. this.pointerUpAnimation();
  955. }
  956. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  957. };
  958. // Statics
  959. /**
  960. * Creates a new button made with an image and a text
  961. * @param name defines the name of the button
  962. * @param text defines the text of the button
  963. * @param imageUrl defines the url of the image
  964. * @returns a new Button
  965. */
  966. Button.CreateImageButton = function (name, text, imageUrl) {
  967. var result = new Button(name);
  968. // Adding text
  969. var textBlock = new textBlock_1.TextBlock(name + "_button", text);
  970. textBlock.textWrapping = true;
  971. textBlock.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_CENTER;
  972. textBlock.paddingLeft = "20%";
  973. result.addControl(textBlock);
  974. // Adding image
  975. var iconImage = new image_1.Image(name + "_icon", imageUrl);
  976. iconImage.width = "20%";
  977. iconImage.stretch = image_1.Image.STRETCH_UNIFORM;
  978. iconImage.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  979. result.addControl(iconImage);
  980. // Store
  981. result._image = iconImage;
  982. result._textBlock = textBlock;
  983. return result;
  984. };
  985. /**
  986. * Creates a new button made with an image
  987. * @param name defines the name of the button
  988. * @param imageUrl defines the url of the image
  989. * @returns a new Button
  990. */
  991. Button.CreateImageOnlyButton = function (name, imageUrl) {
  992. var result = new Button(name);
  993. // Adding image
  994. var iconImage = new image_1.Image(name + "_icon", imageUrl);
  995. iconImage.stretch = image_1.Image.STRETCH_FILL;
  996. iconImage.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  997. result.addControl(iconImage);
  998. // Store
  999. result._image = iconImage;
  1000. return result;
  1001. };
  1002. /**
  1003. * Creates a new button made with a text
  1004. * @param name defines the name of the button
  1005. * @param text defines the text of the button
  1006. * @returns a new Button
  1007. */
  1008. Button.CreateSimpleButton = function (name, text) {
  1009. var result = new Button(name);
  1010. // Adding text
  1011. var textBlock = new textBlock_1.TextBlock(name + "_button", text);
  1012. textBlock.textWrapping = true;
  1013. textBlock.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1014. result.addControl(textBlock);
  1015. // Store
  1016. result._textBlock = textBlock;
  1017. return result;
  1018. };
  1019. /**
  1020. * Creates a new button made with an image and a centered text
  1021. * @param name defines the name of the button
  1022. * @param text defines the text of the button
  1023. * @param imageUrl defines the url of the image
  1024. * @returns a new Button
  1025. */
  1026. Button.CreateImageWithCenterTextButton = function (name, text, imageUrl) {
  1027. var result = new Button(name);
  1028. // Adding image
  1029. var iconImage = new image_1.Image(name + "_icon", imageUrl);
  1030. iconImage.stretch = image_1.Image.STRETCH_FILL;
  1031. result.addControl(iconImage);
  1032. // Adding text
  1033. var textBlock = new textBlock_1.TextBlock(name + "_button", text);
  1034. textBlock.textWrapping = true;
  1035. textBlock.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1036. result.addControl(textBlock);
  1037. // Store
  1038. result._image = iconImage;
  1039. result._textBlock = textBlock;
  1040. return result;
  1041. };
  1042. return Button;
  1043. }(rectangle_1.Rectangle));
  1044. exports.Button = Button;
  1045. /***/ }),
  1046. /***/ "./src/2D/controls/checkbox.ts":
  1047. /*!*************************************!*\
  1048. !*** ./src/2D/controls/checkbox.ts ***!
  1049. \*************************************/
  1050. /*! no static exports found */
  1051. /***/ (function(module, exports, __webpack_require__) {
  1052. "use strict";
  1053. var __extends = (this && this.__extends) || (function () {
  1054. var extendStatics = function (d, b) {
  1055. extendStatics = Object.setPrototypeOf ||
  1056. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1057. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1058. return extendStatics(d, b);
  1059. }
  1060. return function (d, b) {
  1061. extendStatics(d, b);
  1062. function __() { this.constructor = d; }
  1063. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1064. };
  1065. })();
  1066. Object.defineProperty(exports, "__esModule", { value: true });
  1067. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  1068. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  1069. var stackPanel_1 = __webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts");
  1070. var textBlock_1 = __webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts");
  1071. /**
  1072. * Class used to represent a 2D checkbox
  1073. */
  1074. var Checkbox = /** @class */ (function (_super) {
  1075. __extends(Checkbox, _super);
  1076. /**
  1077. * Creates a new CheckBox
  1078. * @param name defines the control name
  1079. */
  1080. function Checkbox(name) {
  1081. var _this = _super.call(this, name) || this;
  1082. _this.name = name;
  1083. _this._isChecked = false;
  1084. _this._background = "black";
  1085. _this._checkSizeRatio = 0.8;
  1086. _this._thickness = 1;
  1087. /**
  1088. * Observable raised when isChecked property changes
  1089. */
  1090. _this.onIsCheckedChangedObservable = new babylonjs_1.Observable();
  1091. _this.isPointerBlocker = true;
  1092. return _this;
  1093. }
  1094. Object.defineProperty(Checkbox.prototype, "thickness", {
  1095. /** Gets or sets border thickness */
  1096. get: function () {
  1097. return this._thickness;
  1098. },
  1099. set: function (value) {
  1100. if (this._thickness === value) {
  1101. return;
  1102. }
  1103. this._thickness = value;
  1104. this._markAsDirty();
  1105. },
  1106. enumerable: true,
  1107. configurable: true
  1108. });
  1109. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  1110. /** Gets or sets a value indicating the ratio between overall size and check size */
  1111. get: function () {
  1112. return this._checkSizeRatio;
  1113. },
  1114. set: function (value) {
  1115. value = Math.max(Math.min(1, value), 0);
  1116. if (this._checkSizeRatio === value) {
  1117. return;
  1118. }
  1119. this._checkSizeRatio = value;
  1120. this._markAsDirty();
  1121. },
  1122. enumerable: true,
  1123. configurable: true
  1124. });
  1125. Object.defineProperty(Checkbox.prototype, "background", {
  1126. /** Gets or sets background color */
  1127. get: function () {
  1128. return this._background;
  1129. },
  1130. set: function (value) {
  1131. if (this._background === value) {
  1132. return;
  1133. }
  1134. this._background = value;
  1135. this._markAsDirty();
  1136. },
  1137. enumerable: true,
  1138. configurable: true
  1139. });
  1140. Object.defineProperty(Checkbox.prototype, "isChecked", {
  1141. /** Gets or sets a boolean indicating if the checkbox is checked or not */
  1142. get: function () {
  1143. return this._isChecked;
  1144. },
  1145. set: function (value) {
  1146. if (this._isChecked === value) {
  1147. return;
  1148. }
  1149. this._isChecked = value;
  1150. this._markAsDirty();
  1151. this.onIsCheckedChangedObservable.notifyObservers(value);
  1152. },
  1153. enumerable: true,
  1154. configurable: true
  1155. });
  1156. Checkbox.prototype._getTypeName = function () {
  1157. return "CheckBox";
  1158. };
  1159. /** @hidden */
  1160. Checkbox.prototype._draw = function (parentMeasure, context) {
  1161. context.save();
  1162. this._applyStates(context);
  1163. if (this._processMeasures(parentMeasure, context)) {
  1164. var actualWidth = this._currentMeasure.width - this._thickness;
  1165. var actualHeight = this._currentMeasure.height - this._thickness;
  1166. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1167. context.shadowColor = this.shadowColor;
  1168. context.shadowBlur = this.shadowBlur;
  1169. context.shadowOffsetX = this.shadowOffsetX;
  1170. context.shadowOffsetY = this.shadowOffsetY;
  1171. }
  1172. context.fillStyle = this._isEnabled ? this._background : this._disabledColor;
  1173. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  1174. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1175. context.shadowBlur = 0;
  1176. context.shadowOffsetX = 0;
  1177. context.shadowOffsetY = 0;
  1178. }
  1179. if (this._isChecked) {
  1180. context.fillStyle = this._isEnabled ? this.color : this._disabledColor;
  1181. var offsetWidth = actualWidth * this._checkSizeRatio;
  1182. var offseHeight = actualHeight * this._checkSizeRatio;
  1183. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  1184. }
  1185. context.strokeStyle = this.color;
  1186. context.lineWidth = this._thickness;
  1187. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  1188. }
  1189. context.restore();
  1190. };
  1191. // Events
  1192. /** @hidden */
  1193. Checkbox.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  1194. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  1195. return false;
  1196. }
  1197. this.isChecked = !this.isChecked;
  1198. return true;
  1199. };
  1200. /**
  1201. * Utility function to easily create a checkbox with a header
  1202. * @param title defines the label to use for the header
  1203. * @param onValueChanged defines the callback to call when value changes
  1204. * @returns a StackPanel containing the checkbox and a textBlock
  1205. */
  1206. Checkbox.AddCheckBoxWithHeader = function (title, onValueChanged) {
  1207. var panel = new stackPanel_1.StackPanel();
  1208. panel.isVertical = false;
  1209. panel.height = "30px";
  1210. var checkbox = new Checkbox();
  1211. checkbox.width = "20px";
  1212. checkbox.height = "20px";
  1213. checkbox.isChecked = true;
  1214. checkbox.color = "green";
  1215. checkbox.onIsCheckedChangedObservable.add(onValueChanged);
  1216. panel.addControl(checkbox);
  1217. var header = new textBlock_1.TextBlock();
  1218. header.text = title;
  1219. header.width = "180px";
  1220. header.paddingLeft = "5px";
  1221. header.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1222. header.color = "white";
  1223. panel.addControl(header);
  1224. return panel;
  1225. };
  1226. return Checkbox;
  1227. }(control_1.Control));
  1228. exports.Checkbox = Checkbox;
  1229. /***/ }),
  1230. /***/ "./src/2D/controls/colorpicker.ts":
  1231. /*!****************************************!*\
  1232. !*** ./src/2D/controls/colorpicker.ts ***!
  1233. \****************************************/
  1234. /*! no static exports found */
  1235. /***/ (function(module, exports, __webpack_require__) {
  1236. "use strict";
  1237. var __extends = (this && this.__extends) || (function () {
  1238. var extendStatics = function (d, b) {
  1239. extendStatics = Object.setPrototypeOf ||
  1240. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1241. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1242. return extendStatics(d, b);
  1243. }
  1244. return function (d, b) {
  1245. extendStatics(d, b);
  1246. function __() { this.constructor = d; }
  1247. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1248. };
  1249. })();
  1250. Object.defineProperty(exports, "__esModule", { value: true });
  1251. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  1252. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  1253. /** Class used to create color pickers */
  1254. var ColorPicker = /** @class */ (function (_super) {
  1255. __extends(ColorPicker, _super);
  1256. /**
  1257. * Creates a new ColorPicker
  1258. * @param name defines the control name
  1259. */
  1260. function ColorPicker(name) {
  1261. var _this = _super.call(this, name) || this;
  1262. _this.name = name;
  1263. _this._value = babylonjs_1.Color3.Red();
  1264. _this._tmpColor = new babylonjs_1.Color3();
  1265. _this._pointerStartedOnSquare = false;
  1266. _this._pointerStartedOnWheel = false;
  1267. _this._squareLeft = 0;
  1268. _this._squareTop = 0;
  1269. _this._squareSize = 0;
  1270. _this._h = 360;
  1271. _this._s = 1;
  1272. _this._v = 1;
  1273. /**
  1274. * Observable raised when the value changes
  1275. */
  1276. _this.onValueChangedObservable = new babylonjs_1.Observable();
  1277. // Events
  1278. _this._pointerIsDown = false;
  1279. _this.value = new babylonjs_1.Color3(.88, .1, .1);
  1280. _this.size = "200px";
  1281. _this.isPointerBlocker = true;
  1282. return _this;
  1283. }
  1284. Object.defineProperty(ColorPicker.prototype, "value", {
  1285. /** Gets or sets the color of the color picker */
  1286. get: function () {
  1287. return this._value;
  1288. },
  1289. set: function (value) {
  1290. if (this._value.equals(value)) {
  1291. return;
  1292. }
  1293. this._value.copyFrom(value);
  1294. this._RGBtoHSV(this._value, this._tmpColor);
  1295. this._h = this._tmpColor.r;
  1296. this._s = Math.max(this._tmpColor.g, 0.00001);
  1297. this._v = Math.max(this._tmpColor.b, 0.00001);
  1298. this._markAsDirty();
  1299. this.onValueChangedObservable.notifyObservers(this._value);
  1300. },
  1301. enumerable: true,
  1302. configurable: true
  1303. });
  1304. Object.defineProperty(ColorPicker.prototype, "width", {
  1305. /** Gets or sets control width */
  1306. set: function (value) {
  1307. if (this._width.toString(this._host) === value) {
  1308. return;
  1309. }
  1310. if (this._width.fromString(value)) {
  1311. this._height.fromString(value);
  1312. this._markAsDirty();
  1313. }
  1314. },
  1315. enumerable: true,
  1316. configurable: true
  1317. });
  1318. Object.defineProperty(ColorPicker.prototype, "height", {
  1319. /** Gets or sets control height */
  1320. set: function (value) {
  1321. if (this._height.toString(this._host) === value) {
  1322. return;
  1323. }
  1324. if (this._height.fromString(value)) {
  1325. this._width.fromString(value);
  1326. this._markAsDirty();
  1327. }
  1328. },
  1329. enumerable: true,
  1330. configurable: true
  1331. });
  1332. Object.defineProperty(ColorPicker.prototype, "size", {
  1333. /** Gets or sets control size */
  1334. get: function () {
  1335. return this.width;
  1336. },
  1337. set: function (value) {
  1338. this.width = value;
  1339. },
  1340. enumerable: true,
  1341. configurable: true
  1342. });
  1343. ColorPicker.prototype._getTypeName = function () {
  1344. return "ColorPicker";
  1345. };
  1346. ColorPicker.prototype._updateSquareProps = function () {
  1347. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  1348. var wheelThickness = radius * .2;
  1349. var innerDiameter = (radius - wheelThickness) * 2;
  1350. var squareSize = innerDiameter / (Math.sqrt(2));
  1351. var offset = radius - squareSize * .5;
  1352. this._squareLeft = this._currentMeasure.left + offset;
  1353. this._squareTop = this._currentMeasure.top + offset;
  1354. this._squareSize = squareSize;
  1355. };
  1356. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  1357. var lgh = context.createLinearGradient(left, top, width + left, top);
  1358. lgh.addColorStop(0, '#fff');
  1359. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  1360. context.fillStyle = lgh;
  1361. context.fillRect(left, top, width, height);
  1362. var lgv = context.createLinearGradient(left, top, left, height + top);
  1363. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  1364. lgv.addColorStop(1, '#000');
  1365. context.fillStyle = lgv;
  1366. context.fillRect(left, top, width, height);
  1367. };
  1368. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  1369. context.beginPath();
  1370. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  1371. context.lineWidth = 3;
  1372. context.strokeStyle = '#333333';
  1373. context.stroke();
  1374. context.beginPath();
  1375. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  1376. context.lineWidth = 3;
  1377. context.strokeStyle = '#ffffff';
  1378. context.stroke();
  1379. };
  1380. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  1381. var canvas = document.createElement("canvas");
  1382. canvas.width = radius * 2;
  1383. canvas.height = radius * 2;
  1384. var context = canvas.getContext("2d");
  1385. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  1386. var data = image.data;
  1387. var color = this._tmpColor;
  1388. var maxDistSq = radius * radius;
  1389. var innerRadius = radius - thickness;
  1390. var minDistSq = innerRadius * innerRadius;
  1391. for (var x = -radius; x < radius; x++) {
  1392. for (var y = -radius; y < radius; y++) {
  1393. var distSq = x * x + y * y;
  1394. if (distSq > maxDistSq || distSq < minDistSq) {
  1395. continue;
  1396. }
  1397. var dist = Math.sqrt(distSq);
  1398. var ang = Math.atan2(y, x);
  1399. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  1400. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  1401. data[index] = color.r * 255;
  1402. data[index + 1] = color.g * 255;
  1403. data[index + 2] = color.b * 255;
  1404. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  1405. //apply less alpha to bigger color pickers
  1406. var alphaAmount = .2;
  1407. var maxAlpha = .2;
  1408. var minAlpha = .04;
  1409. var lowerRadius = 50;
  1410. var upperRadius = 150;
  1411. if (radius < lowerRadius) {
  1412. alphaAmount = maxAlpha;
  1413. }
  1414. else if (radius > upperRadius) {
  1415. alphaAmount = minAlpha;
  1416. }
  1417. else {
  1418. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  1419. }
  1420. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  1421. if (alphaRatio < alphaAmount) {
  1422. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  1423. }
  1424. else if (alphaRatio > 1 - alphaAmount) {
  1425. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  1426. }
  1427. else {
  1428. data[index + 3] = 255;
  1429. }
  1430. }
  1431. }
  1432. context.putImageData(image, 0, 0);
  1433. return canvas;
  1434. };
  1435. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  1436. var r = color.r;
  1437. var g = color.g;
  1438. var b = color.b;
  1439. var max = Math.max(r, g, b);
  1440. var min = Math.min(r, g, b);
  1441. var h = 0;
  1442. var s = 0;
  1443. var v = max;
  1444. var dm = max - min;
  1445. if (max !== 0) {
  1446. s = dm / max;
  1447. }
  1448. if (max != min) {
  1449. if (max == r) {
  1450. h = (g - b) / dm;
  1451. if (g < b) {
  1452. h += 6;
  1453. }
  1454. }
  1455. else if (max == g) {
  1456. h = (b - r) / dm + 2;
  1457. }
  1458. else if (max == b) {
  1459. h = (r - g) / dm + 4;
  1460. }
  1461. h *= 60;
  1462. }
  1463. result.r = h;
  1464. result.g = s;
  1465. result.b = v;
  1466. };
  1467. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  1468. var chroma = value * saturation;
  1469. var h = hue / 60;
  1470. var x = chroma * (1 - Math.abs((h % 2) - 1));
  1471. var r = 0;
  1472. var g = 0;
  1473. var b = 0;
  1474. if (h >= 0 && h <= 1) {
  1475. r = chroma;
  1476. g = x;
  1477. }
  1478. else if (h >= 1 && h <= 2) {
  1479. r = x;
  1480. g = chroma;
  1481. }
  1482. else if (h >= 2 && h <= 3) {
  1483. g = chroma;
  1484. b = x;
  1485. }
  1486. else if (h >= 3 && h <= 4) {
  1487. g = x;
  1488. b = chroma;
  1489. }
  1490. else if (h >= 4 && h <= 5) {
  1491. r = x;
  1492. b = chroma;
  1493. }
  1494. else if (h >= 5 && h <= 6) {
  1495. r = chroma;
  1496. b = x;
  1497. }
  1498. var m = value - chroma;
  1499. result.set((r + m), (g + m), (b + m));
  1500. };
  1501. /** @hidden */
  1502. ColorPicker.prototype._draw = function (parentMeasure, context) {
  1503. context.save();
  1504. this._applyStates(context);
  1505. if (this._processMeasures(parentMeasure, context)) {
  1506. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  1507. var wheelThickness = radius * .2;
  1508. var left = this._currentMeasure.left;
  1509. var top = this._currentMeasure.top;
  1510. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  1511. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  1512. }
  1513. this._updateSquareProps();
  1514. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1515. context.shadowColor = this.shadowColor;
  1516. context.shadowBlur = this.shadowBlur;
  1517. context.shadowOffsetX = this.shadowOffsetX;
  1518. context.shadowOffsetY = this.shadowOffsetY;
  1519. context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
  1520. }
  1521. context.drawImage(this._colorWheelCanvas, left, top);
  1522. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1523. context.shadowBlur = 0;
  1524. context.shadowOffsetX = 0;
  1525. context.shadowOffsetY = 0;
  1526. }
  1527. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  1528. var cx = this._squareLeft + this._squareSize * this._s;
  1529. var cy = this._squareTop + this._squareSize * (1 - this._v);
  1530. this._drawCircle(cx, cy, radius * .04, context);
  1531. var dist = radius - wheelThickness * .5;
  1532. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  1533. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  1534. this._drawCircle(cx, cy, wheelThickness * .35, context);
  1535. }
  1536. context.restore();
  1537. };
  1538. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  1539. if (this._pointerStartedOnWheel) {
  1540. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  1541. var centerX = radius + this._currentMeasure.left;
  1542. var centerY = radius + this._currentMeasure.top;
  1543. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  1544. }
  1545. else if (this._pointerStartedOnSquare) {
  1546. this._updateSquareProps();
  1547. this._s = (x - this._squareLeft) / this._squareSize;
  1548. this._v = 1 - (y - this._squareTop) / this._squareSize;
  1549. this._s = Math.min(this._s, 1);
  1550. this._s = Math.max(this._s, 0.00001);
  1551. this._v = Math.min(this._v, 1);
  1552. this._v = Math.max(this._v, 0.00001);
  1553. }
  1554. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  1555. this.value = this._tmpColor;
  1556. };
  1557. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  1558. this._updateSquareProps();
  1559. var left = this._squareLeft;
  1560. var top = this._squareTop;
  1561. var size = this._squareSize;
  1562. if (coordinates.x >= left && coordinates.x <= left + size &&
  1563. coordinates.y >= top && coordinates.y <= top + size) {
  1564. return true;
  1565. }
  1566. return false;
  1567. };
  1568. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  1569. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  1570. var centerX = radius + this._currentMeasure.left;
  1571. var centerY = radius + this._currentMeasure.top;
  1572. var wheelThickness = radius * .2;
  1573. var innerRadius = radius - wheelThickness;
  1574. var radiusSq = radius * radius;
  1575. var innerRadiusSq = innerRadius * innerRadius;
  1576. var dx = coordinates.x - centerX;
  1577. var dy = coordinates.y - centerY;
  1578. var distSq = dx * dx + dy * dy;
  1579. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  1580. return true;
  1581. }
  1582. return false;
  1583. };
  1584. ColorPicker.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  1585. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  1586. return false;
  1587. }
  1588. this._pointerIsDown = true;
  1589. this._pointerStartedOnSquare = false;
  1590. this._pointerStartedOnWheel = false;
  1591. if (this._isPointOnSquare(coordinates)) {
  1592. this._pointerStartedOnSquare = true;
  1593. }
  1594. else if (this._isPointOnWheel(coordinates)) {
  1595. this._pointerStartedOnWheel = true;
  1596. }
  1597. this._updateValueFromPointer(coordinates.x, coordinates.y);
  1598. this._host._capturingControl[pointerId] = this;
  1599. return true;
  1600. };
  1601. ColorPicker.prototype._onPointerMove = function (target, coordinates) {
  1602. if (this._pointerIsDown) {
  1603. this._updateValueFromPointer(coordinates.x, coordinates.y);
  1604. }
  1605. _super.prototype._onPointerMove.call(this, target, coordinates);
  1606. };
  1607. ColorPicker.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  1608. this._pointerIsDown = false;
  1609. delete this._host._capturingControl[pointerId];
  1610. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  1611. };
  1612. return ColorPicker;
  1613. }(control_1.Control));
  1614. exports.ColorPicker = ColorPicker;
  1615. /***/ }),
  1616. /***/ "./src/2D/controls/container.ts":
  1617. /*!**************************************!*\
  1618. !*** ./src/2D/controls/container.ts ***!
  1619. \**************************************/
  1620. /*! no static exports found */
  1621. /***/ (function(module, exports, __webpack_require__) {
  1622. "use strict";
  1623. var __extends = (this && this.__extends) || (function () {
  1624. var extendStatics = function (d, b) {
  1625. extendStatics = Object.setPrototypeOf ||
  1626. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1627. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1628. return extendStatics(d, b);
  1629. }
  1630. return function (d, b) {
  1631. extendStatics(d, b);
  1632. function __() { this.constructor = d; }
  1633. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1634. };
  1635. })();
  1636. Object.defineProperty(exports, "__esModule", { value: true });
  1637. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  1638. var measure_1 = __webpack_require__(/*! ../measure */ "./src/2D/measure.ts");
  1639. /**
  1640. * Root class for 2D containers
  1641. * @see http://doc.babylonjs.com/how_to/gui#containers
  1642. */
  1643. var Container = /** @class */ (function (_super) {
  1644. __extends(Container, _super);
  1645. /**
  1646. * Creates a new Container
  1647. * @param name defines the name of the container
  1648. */
  1649. function Container(name) {
  1650. var _this = _super.call(this, name) || this;
  1651. _this.name = name;
  1652. /** @hidden */
  1653. _this._children = new Array();
  1654. /** @hidden */
  1655. _this._measureForChildren = measure_1.Measure.Empty();
  1656. /** @hidden */
  1657. _this._adaptWidthToChildren = false;
  1658. /** @hidden */
  1659. _this._adaptHeightToChildren = false;
  1660. return _this;
  1661. }
  1662. Object.defineProperty(Container.prototype, "adaptHeightToChildren", {
  1663. /** Gets or sets a boolean indicating if the container should try to adapt to its children height */
  1664. get: function () {
  1665. return this._adaptHeightToChildren;
  1666. },
  1667. set: function (value) {
  1668. if (this._adaptHeightToChildren === value) {
  1669. return;
  1670. }
  1671. this._adaptHeightToChildren = value;
  1672. if (value) {
  1673. this.height = "100%";
  1674. }
  1675. this._markAsDirty();
  1676. },
  1677. enumerable: true,
  1678. configurable: true
  1679. });
  1680. Object.defineProperty(Container.prototype, "adaptWidthToChildren", {
  1681. /** Gets or sets a boolean indicating if the container should try to adapt to its children width */
  1682. get: function () {
  1683. return this._adaptWidthToChildren;
  1684. },
  1685. set: function (value) {
  1686. if (this._adaptWidthToChildren === value) {
  1687. return;
  1688. }
  1689. this._adaptWidthToChildren = value;
  1690. if (value) {
  1691. this.width = "100%";
  1692. }
  1693. this._markAsDirty();
  1694. },
  1695. enumerable: true,
  1696. configurable: true
  1697. });
  1698. Object.defineProperty(Container.prototype, "background", {
  1699. /** Gets or sets background color */
  1700. get: function () {
  1701. return this._background;
  1702. },
  1703. set: function (value) {
  1704. if (this._background === value) {
  1705. return;
  1706. }
  1707. this._background = value;
  1708. this._markAsDirty();
  1709. },
  1710. enumerable: true,
  1711. configurable: true
  1712. });
  1713. Object.defineProperty(Container.prototype, "children", {
  1714. /** Gets the list of children */
  1715. get: function () {
  1716. return this._children;
  1717. },
  1718. enumerable: true,
  1719. configurable: true
  1720. });
  1721. Container.prototype._getTypeName = function () {
  1722. return "Container";
  1723. };
  1724. Container.prototype._flagDescendantsAsMatrixDirty = function () {
  1725. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  1726. var child = _a[_i];
  1727. child._markMatrixAsDirty();
  1728. }
  1729. };
  1730. /**
  1731. * Gets a child using its name
  1732. * @param name defines the child name to look for
  1733. * @returns the child control if found
  1734. */
  1735. Container.prototype.getChildByName = function (name) {
  1736. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  1737. var child = _a[_i];
  1738. if (child.name === name) {
  1739. return child;
  1740. }
  1741. }
  1742. return null;
  1743. };
  1744. /**
  1745. * Gets a child using its type and its name
  1746. * @param name defines the child name to look for
  1747. * @param type defines the child type to look for
  1748. * @returns the child control if found
  1749. */
  1750. Container.prototype.getChildByType = function (name, type) {
  1751. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  1752. var child = _a[_i];
  1753. if (child.typeName === type) {
  1754. return child;
  1755. }
  1756. }
  1757. return null;
  1758. };
  1759. /**
  1760. * Search for a specific control in children
  1761. * @param control defines the control to look for
  1762. * @returns true if the control is in child list
  1763. */
  1764. Container.prototype.containsControl = function (control) {
  1765. return this.children.indexOf(control) !== -1;
  1766. };
  1767. /**
  1768. * Adds a new control to the current container
  1769. * @param control defines the control to add
  1770. * @returns the current container
  1771. */
  1772. Container.prototype.addControl = function (control) {
  1773. if (!control) {
  1774. return this;
  1775. }
  1776. var index = this._children.indexOf(control);
  1777. if (index !== -1) {
  1778. return this;
  1779. }
  1780. control._link(this, this._host);
  1781. control._markAllAsDirty();
  1782. this._reOrderControl(control);
  1783. this._markAsDirty();
  1784. return this;
  1785. };
  1786. /**
  1787. * Removes all controls from the current container
  1788. * @returns the current container
  1789. */
  1790. Container.prototype.clearControls = function () {
  1791. var children = this._children.slice();
  1792. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  1793. var child = children_1[_i];
  1794. this.removeControl(child);
  1795. }
  1796. return this;
  1797. };
  1798. /**
  1799. * Removes a control from the current container
  1800. * @param control defines the control to remove
  1801. * @returns the current container
  1802. */
  1803. Container.prototype.removeControl = function (control) {
  1804. var index = this._children.indexOf(control);
  1805. if (index !== -1) {
  1806. this._children.splice(index, 1);
  1807. control.parent = null;
  1808. }
  1809. control.linkWithMesh(null);
  1810. if (this._host) {
  1811. this._host._cleanControlAfterRemoval(control);
  1812. }
  1813. this._markAsDirty();
  1814. return this;
  1815. };
  1816. /** @hidden */
  1817. Container.prototype._reOrderControl = function (control) {
  1818. this.removeControl(control);
  1819. for (var index = 0; index < this._children.length; index++) {
  1820. if (this._children[index].zIndex > control.zIndex) {
  1821. this._children.splice(index, 0, control);
  1822. return;
  1823. }
  1824. }
  1825. this._children.push(control);
  1826. control.parent = this;
  1827. this._markAsDirty();
  1828. };
  1829. /** @hidden */
  1830. Container.prototype._markAllAsDirty = function () {
  1831. _super.prototype._markAllAsDirty.call(this);
  1832. for (var index = 0; index < this._children.length; index++) {
  1833. this._children[index]._markAllAsDirty();
  1834. }
  1835. };
  1836. /** @hidden */
  1837. Container.prototype._localDraw = function (context) {
  1838. if (this._background) {
  1839. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1840. context.shadowColor = this.shadowColor;
  1841. context.shadowBlur = this.shadowBlur;
  1842. context.shadowOffsetX = this.shadowOffsetX;
  1843. context.shadowOffsetY = this.shadowOffsetY;
  1844. }
  1845. context.fillStyle = this._background;
  1846. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  1847. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1848. context.shadowBlur = 0;
  1849. context.shadowOffsetX = 0;
  1850. context.shadowOffsetY = 0;
  1851. }
  1852. }
  1853. };
  1854. /** @hidden */
  1855. Container.prototype._link = function (root, host) {
  1856. _super.prototype._link.call(this, root, host);
  1857. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1858. var child = _a[_i];
  1859. child._link(this, host);
  1860. }
  1861. };
  1862. /** @hidden */
  1863. Container.prototype._draw = function (parentMeasure, context) {
  1864. if (!this.isVisible || this.notRenderable) {
  1865. return;
  1866. }
  1867. context.save();
  1868. this._applyStates(context);
  1869. if (this._processMeasures(parentMeasure, context)) {
  1870. this._localDraw(context);
  1871. if (this.clipChildren) {
  1872. this._clipForChildren(context);
  1873. }
  1874. var computedWidth = -1;
  1875. var computedHeight = -1;
  1876. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1877. var child = _a[_i];
  1878. if (child.isVisible && !child.notRenderable) {
  1879. child._tempParentMeasure.copyFrom(this._measureForChildren);
  1880. child._draw(this._measureForChildren, context);
  1881. if (child.onAfterDrawObservable.hasObservers()) {
  1882. child.onAfterDrawObservable.notifyObservers(child);
  1883. }
  1884. if (this.adaptWidthToChildren && child._width.isPixel) {
  1885. computedWidth = Math.max(computedWidth, child._currentMeasure.width);
  1886. }
  1887. if (this.adaptHeightToChildren && child._height.isPixel) {
  1888. computedHeight = Math.max(computedHeight, child._currentMeasure.height);
  1889. }
  1890. }
  1891. }
  1892. if (this.adaptWidthToChildren && computedWidth >= 0) {
  1893. this.width = computedWidth + "px";
  1894. }
  1895. if (this.adaptHeightToChildren && computedHeight >= 0) {
  1896. this.height = computedHeight + "px";
  1897. }
  1898. }
  1899. context.restore();
  1900. if (this.onAfterDrawObservable.hasObservers()) {
  1901. this.onAfterDrawObservable.notifyObservers(this);
  1902. }
  1903. };
  1904. /** @hidden */
  1905. Container.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  1906. if (!this.isVisible || this.notRenderable) {
  1907. return false;
  1908. }
  1909. if (!_super.prototype.contains.call(this, x, y)) {
  1910. return false;
  1911. }
  1912. // Checking backwards to pick closest first
  1913. for (var index = this._children.length - 1; index >= 0; index--) {
  1914. var child = this._children[index];
  1915. if (child._processPicking(x, y, type, pointerId, buttonIndex)) {
  1916. if (child.hoverCursor) {
  1917. this._host._changeCursor(child.hoverCursor);
  1918. }
  1919. return true;
  1920. }
  1921. }
  1922. if (!this.isHitTestVisible) {
  1923. return false;
  1924. }
  1925. return this._processObservables(type, x, y, pointerId, buttonIndex);
  1926. };
  1927. /** @hidden */
  1928. Container.prototype._clipForChildren = function (context) {
  1929. // DO nothing
  1930. };
  1931. /** @hidden */
  1932. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  1933. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  1934. this._measureForChildren.copyFrom(this._currentMeasure);
  1935. };
  1936. /** Releases associated resources */
  1937. Container.prototype.dispose = function () {
  1938. _super.prototype.dispose.call(this);
  1939. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  1940. var control = _a[_i];
  1941. control.dispose();
  1942. }
  1943. };
  1944. return Container;
  1945. }(control_1.Control));
  1946. exports.Container = Container;
  1947. /***/ }),
  1948. /***/ "./src/2D/controls/control.ts":
  1949. /*!************************************!*\
  1950. !*** ./src/2D/controls/control.ts ***!
  1951. \************************************/
  1952. /*! no static exports found */
  1953. /***/ (function(module, exports, __webpack_require__) {
  1954. "use strict";
  1955. Object.defineProperty(exports, "__esModule", { value: true });
  1956. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  1957. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  1958. var measure_1 = __webpack_require__(/*! ../measure */ "./src/2D/measure.ts");
  1959. var math2D_1 = __webpack_require__(/*! ../math2D */ "./src/2D/math2D.ts");
  1960. /**
  1961. * Root class used for all 2D controls
  1962. * @see http://doc.babylonjs.com/how_to/gui#controls
  1963. */
  1964. var Control = /** @class */ (function () {
  1965. // Functions
  1966. /**
  1967. * Creates a new control
  1968. * @param name defines the name of the control
  1969. */
  1970. function Control(
  1971. /** defines the name of the control */
  1972. name) {
  1973. this.name = name;
  1974. this._alpha = 1;
  1975. this._alphaSet = false;
  1976. this._zIndex = 0;
  1977. /** @hidden */
  1978. this._currentMeasure = measure_1.Measure.Empty();
  1979. this._fontFamily = "Arial";
  1980. this._fontStyle = "";
  1981. this._fontWeight = "";
  1982. this._fontSize = new valueAndUnit_1.ValueAndUnit(18, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL, false);
  1983. /** @hidden */
  1984. this._width = new valueAndUnit_1.ValueAndUnit(1, valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  1985. /** @hidden */
  1986. this._height = new valueAndUnit_1.ValueAndUnit(1, valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  1987. this._color = "";
  1988. this._style = null;
  1989. /** @hidden */
  1990. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  1991. /** @hidden */
  1992. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  1993. this._isDirty = true;
  1994. /** @hidden */
  1995. this._tempParentMeasure = measure_1.Measure.Empty();
  1996. /** @hidden */
  1997. this._cachedParentMeasure = measure_1.Measure.Empty();
  1998. this._paddingLeft = new valueAndUnit_1.ValueAndUnit(0);
  1999. this._paddingRight = new valueAndUnit_1.ValueAndUnit(0);
  2000. this._paddingTop = new valueAndUnit_1.ValueAndUnit(0);
  2001. this._paddingBottom = new valueAndUnit_1.ValueAndUnit(0);
  2002. /** @hidden */
  2003. this._left = new valueAndUnit_1.ValueAndUnit(0);
  2004. /** @hidden */
  2005. this._top = new valueAndUnit_1.ValueAndUnit(0);
  2006. this._scaleX = 1.0;
  2007. this._scaleY = 1.0;
  2008. this._rotation = 0;
  2009. this._transformCenterX = 0.5;
  2010. this._transformCenterY = 0.5;
  2011. this._transformMatrix = math2D_1.Matrix2D.Identity();
  2012. /** @hidden */
  2013. this._invertTransformMatrix = math2D_1.Matrix2D.Identity();
  2014. /** @hidden */
  2015. this._transformedPosition = babylonjs_1.Vector2.Zero();
  2016. this._onlyMeasureMode = false;
  2017. this._isMatrixDirty = true;
  2018. this._isVisible = true;
  2019. this._fontSet = false;
  2020. this._dummyVector2 = babylonjs_1.Vector2.Zero();
  2021. this._downCount = 0;
  2022. this._enterCount = -1;
  2023. this._doNotRender = false;
  2024. this._downPointerIds = {};
  2025. this._isEnabled = true;
  2026. this._disabledColor = "#9a9a9a";
  2027. /** Gets or sets a boolean indicating if the control can be hit with pointer events */
  2028. this.isHitTestVisible = true;
  2029. /** Gets or sets a boolean indicating if the control can block pointer events */
  2030. this.isPointerBlocker = false;
  2031. /** Gets or sets a boolean indicating if the control can be focusable */
  2032. this.isFocusInvisible = false;
  2033. /** Gets or sets a boolean indicating if the children are clipped to the current control bounds */
  2034. this.clipChildren = true;
  2035. /** Gets or sets a value indicating the offset to apply on X axis to render the shadow */
  2036. this.shadowOffsetX = 0;
  2037. /** Gets or sets a value indicating the offset to apply on Y axis to render the shadow */
  2038. this.shadowOffsetY = 0;
  2039. /** Gets or sets a value indicating the amount of blur to use to render the shadow */
  2040. this.shadowBlur = 0;
  2041. /** Gets or sets a value indicating the color of the shadow (black by default ie. "#000") */
  2042. this.shadowColor = '#000';
  2043. /** Gets or sets the cursor to use when the control is hovered */
  2044. this.hoverCursor = "";
  2045. /** @hidden */
  2046. this._linkOffsetX = new valueAndUnit_1.ValueAndUnit(0);
  2047. /** @hidden */
  2048. this._linkOffsetY = new valueAndUnit_1.ValueAndUnit(0);
  2049. /**
  2050. * An event triggered when the pointer move over the control.
  2051. */
  2052. this.onPointerMoveObservable = new babylonjs_1.Observable();
  2053. /**
  2054. * An event triggered when the pointer move out of the control.
  2055. */
  2056. this.onPointerOutObservable = new babylonjs_1.Observable();
  2057. /**
  2058. * An event triggered when the pointer taps the control
  2059. */
  2060. this.onPointerDownObservable = new babylonjs_1.Observable();
  2061. /**
  2062. * An event triggered when pointer up
  2063. */
  2064. this.onPointerUpObservable = new babylonjs_1.Observable();
  2065. /**
  2066. * An event triggered when a control is clicked on
  2067. */
  2068. this.onPointerClickObservable = new babylonjs_1.Observable();
  2069. /**
  2070. * An event triggered when pointer enters the control
  2071. */
  2072. this.onPointerEnterObservable = new babylonjs_1.Observable();
  2073. /**
  2074. * An event triggered when the control is marked as dirty
  2075. */
  2076. this.onDirtyObservable = new babylonjs_1.Observable();
  2077. /**
  2078. * An event triggered after the control is drawn
  2079. */
  2080. this.onAfterDrawObservable = new babylonjs_1.Observable();
  2081. }
  2082. Object.defineProperty(Control.prototype, "typeName", {
  2083. // Properties
  2084. /** Gets the control type name */
  2085. get: function () {
  2086. return this._getTypeName();
  2087. },
  2088. enumerable: true,
  2089. configurable: true
  2090. });
  2091. Object.defineProperty(Control.prototype, "fontOffset", {
  2092. /** Gets or set information about font offsets (used to render and align text) */
  2093. get: function () {
  2094. return this._fontOffset;
  2095. },
  2096. set: function (offset) {
  2097. this._fontOffset = offset;
  2098. },
  2099. enumerable: true,
  2100. configurable: true
  2101. });
  2102. Object.defineProperty(Control.prototype, "alpha", {
  2103. /** Gets or sets alpha value for the control (1 means opaque and 0 means entirely transparent) */
  2104. get: function () {
  2105. return this._alpha;
  2106. },
  2107. set: function (value) {
  2108. if (this._alpha === value) {
  2109. return;
  2110. }
  2111. this._alphaSet = true;
  2112. this._alpha = value;
  2113. this._markAsDirty();
  2114. },
  2115. enumerable: true,
  2116. configurable: true
  2117. });
  2118. Object.defineProperty(Control.prototype, "scaleX", {
  2119. /** Gets or sets a value indicating the scale factor on X axis (1 by default)
  2120. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2121. */
  2122. get: function () {
  2123. return this._scaleX;
  2124. },
  2125. set: function (value) {
  2126. if (this._scaleX === value) {
  2127. return;
  2128. }
  2129. this._scaleX = value;
  2130. this._markAsDirty();
  2131. this._markMatrixAsDirty();
  2132. },
  2133. enumerable: true,
  2134. configurable: true
  2135. });
  2136. Object.defineProperty(Control.prototype, "scaleY", {
  2137. /** Gets or sets a value indicating the scale factor on Y axis (1 by default)
  2138. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2139. */
  2140. get: function () {
  2141. return this._scaleY;
  2142. },
  2143. set: function (value) {
  2144. if (this._scaleY === value) {
  2145. return;
  2146. }
  2147. this._scaleY = value;
  2148. this._markAsDirty();
  2149. this._markMatrixAsDirty();
  2150. },
  2151. enumerable: true,
  2152. configurable: true
  2153. });
  2154. Object.defineProperty(Control.prototype, "rotation", {
  2155. /** Gets or sets the rotation angle (0 by default)
  2156. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2157. */
  2158. get: function () {
  2159. return this._rotation;
  2160. },
  2161. set: function (value) {
  2162. if (this._rotation === value) {
  2163. return;
  2164. }
  2165. this._rotation = value;
  2166. this._markAsDirty();
  2167. this._markMatrixAsDirty();
  2168. },
  2169. enumerable: true,
  2170. configurable: true
  2171. });
  2172. Object.defineProperty(Control.prototype, "transformCenterY", {
  2173. /** Gets or sets the transformation center on Y axis (0 by default)
  2174. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2175. */
  2176. get: function () {
  2177. return this._transformCenterY;
  2178. },
  2179. set: function (value) {
  2180. if (this._transformCenterY === value) {
  2181. return;
  2182. }
  2183. this._transformCenterY = value;
  2184. this._markAsDirty();
  2185. this._markMatrixAsDirty();
  2186. },
  2187. enumerable: true,
  2188. configurable: true
  2189. });
  2190. Object.defineProperty(Control.prototype, "transformCenterX", {
  2191. /** Gets or sets the transformation center on X axis (0 by default)
  2192. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2193. */
  2194. get: function () {
  2195. return this._transformCenterX;
  2196. },
  2197. set: function (value) {
  2198. if (this._transformCenterX === value) {
  2199. return;
  2200. }
  2201. this._transformCenterX = value;
  2202. this._markAsDirty();
  2203. this._markMatrixAsDirty();
  2204. },
  2205. enumerable: true,
  2206. configurable: true
  2207. });
  2208. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  2209. /**
  2210. * Gets or sets the horizontal alignment
  2211. * @see http://doc.babylonjs.com/how_to/gui#alignments
  2212. */
  2213. get: function () {
  2214. return this._horizontalAlignment;
  2215. },
  2216. set: function (value) {
  2217. if (this._horizontalAlignment === value) {
  2218. return;
  2219. }
  2220. this._horizontalAlignment = value;
  2221. this._markAsDirty();
  2222. },
  2223. enumerable: true,
  2224. configurable: true
  2225. });
  2226. Object.defineProperty(Control.prototype, "verticalAlignment", {
  2227. /**
  2228. * Gets or sets the vertical alignment
  2229. * @see http://doc.babylonjs.com/how_to/gui#alignments
  2230. */
  2231. get: function () {
  2232. return this._verticalAlignment;
  2233. },
  2234. set: function (value) {
  2235. if (this._verticalAlignment === value) {
  2236. return;
  2237. }
  2238. this._verticalAlignment = value;
  2239. this._markAsDirty();
  2240. },
  2241. enumerable: true,
  2242. configurable: true
  2243. });
  2244. Object.defineProperty(Control.prototype, "width", {
  2245. /**
  2246. * Gets or sets control width
  2247. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2248. */
  2249. get: function () {
  2250. return this._width.toString(this._host);
  2251. },
  2252. set: function (value) {
  2253. if (this._width.toString(this._host) === value) {
  2254. return;
  2255. }
  2256. if (this._width.fromString(value)) {
  2257. this._markAsDirty();
  2258. }
  2259. },
  2260. enumerable: true,
  2261. configurable: true
  2262. });
  2263. Object.defineProperty(Control.prototype, "widthInPixels", {
  2264. /**
  2265. * Gets control width in pixel
  2266. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2267. */
  2268. get: function () {
  2269. return this._width.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2270. },
  2271. enumerable: true,
  2272. configurable: true
  2273. });
  2274. Object.defineProperty(Control.prototype, "height", {
  2275. /**
  2276. * Gets or sets control height
  2277. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2278. */
  2279. get: function () {
  2280. return this._height.toString(this._host);
  2281. },
  2282. set: function (value) {
  2283. if (this._height.toString(this._host) === value) {
  2284. return;
  2285. }
  2286. if (this._height.fromString(value)) {
  2287. this._markAsDirty();
  2288. }
  2289. },
  2290. enumerable: true,
  2291. configurable: true
  2292. });
  2293. Object.defineProperty(Control.prototype, "heightInPixels", {
  2294. /**
  2295. * Gets control height in pixel
  2296. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2297. */
  2298. get: function () {
  2299. return this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2300. },
  2301. enumerable: true,
  2302. configurable: true
  2303. });
  2304. Object.defineProperty(Control.prototype, "fontFamily", {
  2305. /** Gets or set font family */
  2306. get: function () {
  2307. return this._fontFamily;
  2308. },
  2309. set: function (value) {
  2310. if (this._fontFamily === value) {
  2311. return;
  2312. }
  2313. this._fontFamily = value;
  2314. this._resetFontCache();
  2315. },
  2316. enumerable: true,
  2317. configurable: true
  2318. });
  2319. Object.defineProperty(Control.prototype, "fontStyle", {
  2320. /** Gets or sets font style */
  2321. get: function () {
  2322. return this._fontStyle;
  2323. },
  2324. set: function (value) {
  2325. if (this._fontStyle === value) {
  2326. return;
  2327. }
  2328. this._fontStyle = value;
  2329. this._resetFontCache();
  2330. },
  2331. enumerable: true,
  2332. configurable: true
  2333. });
  2334. Object.defineProperty(Control.prototype, "fontWeight", {
  2335. /** Gets or sets font weight */
  2336. get: function () {
  2337. return this._fontWeight;
  2338. },
  2339. set: function (value) {
  2340. if (this._fontWeight === value) {
  2341. return;
  2342. }
  2343. this._fontWeight = value;
  2344. this._resetFontCache();
  2345. },
  2346. enumerable: true,
  2347. configurable: true
  2348. });
  2349. Object.defineProperty(Control.prototype, "style", {
  2350. /**
  2351. * Gets or sets style
  2352. * @see http://doc.babylonjs.com/how_to/gui#styles
  2353. */
  2354. get: function () {
  2355. return this._style;
  2356. },
  2357. set: function (value) {
  2358. var _this = this;
  2359. if (this._style) {
  2360. this._style.onChangedObservable.remove(this._styleObserver);
  2361. this._styleObserver = null;
  2362. }
  2363. this._style = value;
  2364. if (this._style) {
  2365. this._styleObserver = this._style.onChangedObservable.add(function () {
  2366. _this._markAsDirty();
  2367. _this._resetFontCache();
  2368. });
  2369. }
  2370. this._markAsDirty();
  2371. this._resetFontCache();
  2372. },
  2373. enumerable: true,
  2374. configurable: true
  2375. });
  2376. Object.defineProperty(Control.prototype, "_isFontSizeInPercentage", {
  2377. /** @hidden */
  2378. get: function () {
  2379. return this._fontSize.isPercentage;
  2380. },
  2381. enumerable: true,
  2382. configurable: true
  2383. });
  2384. Object.defineProperty(Control.prototype, "fontSizeInPixels", {
  2385. /** Gets font size in pixels */
  2386. get: function () {
  2387. var fontSizeToUse = this._style ? this._style._fontSize : this._fontSize;
  2388. if (fontSizeToUse.isPixel) {
  2389. return fontSizeToUse.getValue(this._host);
  2390. }
  2391. return fontSizeToUse.getValueInPixel(this._host, this._tempParentMeasure.height || this._cachedParentMeasure.height);
  2392. },
  2393. enumerable: true,
  2394. configurable: true
  2395. });
  2396. Object.defineProperty(Control.prototype, "fontSize", {
  2397. /** Gets or sets font size */
  2398. get: function () {
  2399. return this._fontSize.toString(this._host);
  2400. },
  2401. set: function (value) {
  2402. if (this._fontSize.toString(this._host) === value) {
  2403. return;
  2404. }
  2405. if (this._fontSize.fromString(value)) {
  2406. this._markAsDirty();
  2407. this._resetFontCache();
  2408. }
  2409. },
  2410. enumerable: true,
  2411. configurable: true
  2412. });
  2413. Object.defineProperty(Control.prototype, "color", {
  2414. /** Gets or sets foreground color */
  2415. get: function () {
  2416. return this._color;
  2417. },
  2418. set: function (value) {
  2419. if (this._color === value) {
  2420. return;
  2421. }
  2422. this._color = value;
  2423. this._markAsDirty();
  2424. },
  2425. enumerable: true,
  2426. configurable: true
  2427. });
  2428. Object.defineProperty(Control.prototype, "zIndex", {
  2429. /** Gets or sets z index which is used to reorder controls on the z axis */
  2430. get: function () {
  2431. return this._zIndex;
  2432. },
  2433. set: function (value) {
  2434. if (this.zIndex === value) {
  2435. return;
  2436. }
  2437. this._zIndex = value;
  2438. if (this._root) {
  2439. this._root._reOrderControl(this);
  2440. }
  2441. },
  2442. enumerable: true,
  2443. configurable: true
  2444. });
  2445. Object.defineProperty(Control.prototype, "notRenderable", {
  2446. /** Gets or sets a boolean indicating if the control can be rendered */
  2447. get: function () {
  2448. return this._doNotRender;
  2449. },
  2450. set: function (value) {
  2451. if (this._doNotRender === value) {
  2452. return;
  2453. }
  2454. this._doNotRender = value;
  2455. this._markAsDirty();
  2456. },
  2457. enumerable: true,
  2458. configurable: true
  2459. });
  2460. Object.defineProperty(Control.prototype, "isVisible", {
  2461. /** Gets or sets a boolean indicating if the control is visible */
  2462. get: function () {
  2463. return this._isVisible;
  2464. },
  2465. set: function (value) {
  2466. if (this._isVisible === value) {
  2467. return;
  2468. }
  2469. this._isVisible = value;
  2470. this._markAsDirty(true);
  2471. },
  2472. enumerable: true,
  2473. configurable: true
  2474. });
  2475. Object.defineProperty(Control.prototype, "isDirty", {
  2476. /** Gets a boolean indicating that the control needs to update its rendering */
  2477. get: function () {
  2478. return this._isDirty;
  2479. },
  2480. enumerable: true,
  2481. configurable: true
  2482. });
  2483. Object.defineProperty(Control.prototype, "linkedMesh", {
  2484. /**
  2485. * Gets the current linked mesh (or null if none)
  2486. */
  2487. get: function () {
  2488. return this._linkedMesh;
  2489. },
  2490. enumerable: true,
  2491. configurable: true
  2492. });
  2493. Object.defineProperty(Control.prototype, "paddingLeft", {
  2494. /**
  2495. * Gets or sets a value indicating the padding to use on the left of the control
  2496. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2497. */
  2498. get: function () {
  2499. return this._paddingLeft.toString(this._host);
  2500. },
  2501. set: function (value) {
  2502. if (this._paddingLeft.fromString(value)) {
  2503. this._markAsDirty();
  2504. }
  2505. },
  2506. enumerable: true,
  2507. configurable: true
  2508. });
  2509. Object.defineProperty(Control.prototype, "paddingLeftInPixels", {
  2510. /**
  2511. * Gets a value indicating the padding in pixels to use on the left of the control
  2512. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2513. */
  2514. get: function () {
  2515. return this._paddingLeft.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2516. },
  2517. enumerable: true,
  2518. configurable: true
  2519. });
  2520. Object.defineProperty(Control.prototype, "paddingRight", {
  2521. /**
  2522. * Gets or sets a value indicating the padding to use on the right of the control
  2523. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2524. */
  2525. get: function () {
  2526. return this._paddingRight.toString(this._host);
  2527. },
  2528. set: function (value) {
  2529. if (this._paddingRight.fromString(value)) {
  2530. this._markAsDirty();
  2531. }
  2532. },
  2533. enumerable: true,
  2534. configurable: true
  2535. });
  2536. Object.defineProperty(Control.prototype, "paddingRightInPixels", {
  2537. /**
  2538. * Gets a value indicating the padding in pixels to use on the right of the control
  2539. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2540. */
  2541. get: function () {
  2542. return this._paddingRight.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2543. },
  2544. enumerable: true,
  2545. configurable: true
  2546. });
  2547. Object.defineProperty(Control.prototype, "paddingTop", {
  2548. /**
  2549. * Gets or sets a value indicating the padding to use on the top of the control
  2550. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2551. */
  2552. get: function () {
  2553. return this._paddingTop.toString(this._host);
  2554. },
  2555. set: function (value) {
  2556. if (this._paddingTop.fromString(value)) {
  2557. this._markAsDirty();
  2558. }
  2559. },
  2560. enumerable: true,
  2561. configurable: true
  2562. });
  2563. Object.defineProperty(Control.prototype, "paddingTopInPixels", {
  2564. /**
  2565. * Gets a value indicating the padding in pixels to use on the top of the control
  2566. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2567. */
  2568. get: function () {
  2569. return this._paddingTop.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2570. },
  2571. enumerable: true,
  2572. configurable: true
  2573. });
  2574. Object.defineProperty(Control.prototype, "paddingBottom", {
  2575. /**
  2576. * Gets or sets a value indicating the padding to use on the bottom of the control
  2577. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2578. */
  2579. get: function () {
  2580. return this._paddingBottom.toString(this._host);
  2581. },
  2582. set: function (value) {
  2583. if (this._paddingBottom.fromString(value)) {
  2584. this._markAsDirty();
  2585. }
  2586. },
  2587. enumerable: true,
  2588. configurable: true
  2589. });
  2590. Object.defineProperty(Control.prototype, "paddingBottomInPixels", {
  2591. /**
  2592. * Gets a value indicating the padding in pixels to use on the bottom of the control
  2593. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2594. */
  2595. get: function () {
  2596. return this._paddingBottom.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2597. },
  2598. enumerable: true,
  2599. configurable: true
  2600. });
  2601. Object.defineProperty(Control.prototype, "left", {
  2602. /**
  2603. * Gets or sets a value indicating the left coordinate of the control
  2604. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2605. */
  2606. get: function () {
  2607. return this._left.toString(this._host);
  2608. },
  2609. set: function (value) {
  2610. if (this._left.fromString(value)) {
  2611. this._markAsDirty();
  2612. }
  2613. },
  2614. enumerable: true,
  2615. configurable: true
  2616. });
  2617. Object.defineProperty(Control.prototype, "leftInPixels", {
  2618. /**
  2619. * Gets a value indicating the left coordinate in pixels of the control
  2620. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2621. */
  2622. get: function () {
  2623. return this._left.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2624. },
  2625. enumerable: true,
  2626. configurable: true
  2627. });
  2628. Object.defineProperty(Control.prototype, "top", {
  2629. /**
  2630. * Gets or sets a value indicating the top coordinate of the control
  2631. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2632. */
  2633. get: function () {
  2634. return this._top.toString(this._host);
  2635. },
  2636. set: function (value) {
  2637. if (this._top.fromString(value)) {
  2638. this._markAsDirty();
  2639. }
  2640. },
  2641. enumerable: true,
  2642. configurable: true
  2643. });
  2644. Object.defineProperty(Control.prototype, "topInPixels", {
  2645. /**
  2646. * Gets a value indicating the top coordinate in pixels of the control
  2647. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2648. */
  2649. get: function () {
  2650. return this._top.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2651. },
  2652. enumerable: true,
  2653. configurable: true
  2654. });
  2655. Object.defineProperty(Control.prototype, "linkOffsetX", {
  2656. /**
  2657. * Gets or sets a value indicating the offset on X axis to the linked mesh
  2658. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2659. */
  2660. get: function () {
  2661. return this._linkOffsetX.toString(this._host);
  2662. },
  2663. set: function (value) {
  2664. if (this._linkOffsetX.fromString(value)) {
  2665. this._markAsDirty();
  2666. }
  2667. },
  2668. enumerable: true,
  2669. configurable: true
  2670. });
  2671. Object.defineProperty(Control.prototype, "linkOffsetXInPixels", {
  2672. /**
  2673. * Gets a value indicating the offset in pixels on X axis to the linked mesh
  2674. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2675. */
  2676. get: function () {
  2677. return this._linkOffsetX.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2678. },
  2679. enumerable: true,
  2680. configurable: true
  2681. });
  2682. Object.defineProperty(Control.prototype, "linkOffsetY", {
  2683. /**
  2684. * Gets or sets a value indicating the offset on Y axis to the linked mesh
  2685. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2686. */
  2687. get: function () {
  2688. return this._linkOffsetY.toString(this._host);
  2689. },
  2690. set: function (value) {
  2691. if (this._linkOffsetY.fromString(value)) {
  2692. this._markAsDirty();
  2693. }
  2694. },
  2695. enumerable: true,
  2696. configurable: true
  2697. });
  2698. Object.defineProperty(Control.prototype, "linkOffsetYInPixels", {
  2699. /**
  2700. * Gets a value indicating the offset in pixels on Y axis to the linked mesh
  2701. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2702. */
  2703. get: function () {
  2704. return this._linkOffsetY.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2705. },
  2706. enumerable: true,
  2707. configurable: true
  2708. });
  2709. Object.defineProperty(Control.prototype, "centerX", {
  2710. /** Gets the center coordinate on X axis */
  2711. get: function () {
  2712. return this._currentMeasure.left + this._currentMeasure.width / 2;
  2713. },
  2714. enumerable: true,
  2715. configurable: true
  2716. });
  2717. Object.defineProperty(Control.prototype, "centerY", {
  2718. /** Gets the center coordinate on Y axis */
  2719. get: function () {
  2720. return this._currentMeasure.top + this._currentMeasure.height / 2;
  2721. },
  2722. enumerable: true,
  2723. configurable: true
  2724. });
  2725. Object.defineProperty(Control.prototype, "isEnabled", {
  2726. /** Gets or sets if control is Enabled*/
  2727. get: function () {
  2728. return this._isEnabled;
  2729. },
  2730. set: function (value) {
  2731. if (this._isEnabled === value) {
  2732. return;
  2733. }
  2734. this._isEnabled = value;
  2735. this._markAsDirty();
  2736. },
  2737. enumerable: true,
  2738. configurable: true
  2739. });
  2740. Object.defineProperty(Control.prototype, "disabledColor", {
  2741. /** Gets or sets background color of control if it's disabled*/
  2742. get: function () {
  2743. return this._disabledColor;
  2744. },
  2745. set: function (value) {
  2746. if (this._disabledColor === value) {
  2747. return;
  2748. }
  2749. this._disabledColor = value;
  2750. this._markAsDirty();
  2751. },
  2752. enumerable: true,
  2753. configurable: true
  2754. });
  2755. /** @hidden */
  2756. Control.prototype._getTypeName = function () {
  2757. return "Control";
  2758. };
  2759. /** @hidden */
  2760. Control.prototype._resetFontCache = function () {
  2761. this._fontSet = true;
  2762. this._markAsDirty();
  2763. };
  2764. /**
  2765. * Determines if a container is an ascendant of the current control
  2766. * @param container defines the container to look for
  2767. * @returns true if the container is one of the ascendant of the control
  2768. */
  2769. Control.prototype.isAscendant = function (container) {
  2770. if (!this.parent) {
  2771. return false;
  2772. }
  2773. if (this.parent === container) {
  2774. return true;
  2775. }
  2776. return this.parent.isAscendant(container);
  2777. };
  2778. /**
  2779. * Gets coordinates in local control space
  2780. * @param globalCoordinates defines the coordinates to transform
  2781. * @returns the new coordinates in local space
  2782. */
  2783. Control.prototype.getLocalCoordinates = function (globalCoordinates) {
  2784. var result = babylonjs_1.Vector2.Zero();
  2785. this.getLocalCoordinatesToRef(globalCoordinates, result);
  2786. return result;
  2787. };
  2788. /**
  2789. * Gets coordinates in local control space
  2790. * @param globalCoordinates defines the coordinates to transform
  2791. * @param result defines the target vector2 where to store the result
  2792. * @returns the current control
  2793. */
  2794. Control.prototype.getLocalCoordinatesToRef = function (globalCoordinates, result) {
  2795. result.x = globalCoordinates.x - this._currentMeasure.left;
  2796. result.y = globalCoordinates.y - this._currentMeasure.top;
  2797. return this;
  2798. };
  2799. /**
  2800. * Gets coordinates in parent local control space
  2801. * @param globalCoordinates defines the coordinates to transform
  2802. * @returns the new coordinates in parent local space
  2803. */
  2804. Control.prototype.getParentLocalCoordinates = function (globalCoordinates) {
  2805. var result = babylonjs_1.Vector2.Zero();
  2806. result.x = globalCoordinates.x - this._cachedParentMeasure.left;
  2807. result.y = globalCoordinates.y - this._cachedParentMeasure.top;
  2808. return result;
  2809. };
  2810. /**
  2811. * Move the current control to a vector3 position projected onto the screen.
  2812. * @param position defines the target position
  2813. * @param scene defines the hosting scene
  2814. */
  2815. Control.prototype.moveToVector3 = function (position, scene) {
  2816. if (!this._host || this._root !== this._host._rootContainer) {
  2817. babylonjs_1.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  2818. return;
  2819. }
  2820. this.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  2821. this.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
  2822. var globalViewport = this._host._getGlobalViewport(scene);
  2823. var projectedPosition = babylonjs_1.Vector3.Project(position, babylonjs_1.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  2824. this._moveToProjectedPosition(projectedPosition);
  2825. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  2826. this.notRenderable = true;
  2827. return;
  2828. }
  2829. this.notRenderable = false;
  2830. };
  2831. /**
  2832. * Link current control with a target mesh
  2833. * @param mesh defines the mesh to link with
  2834. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2835. */
  2836. Control.prototype.linkWithMesh = function (mesh) {
  2837. if (!this._host || this._root && this._root !== this._host._rootContainer) {
  2838. if (mesh) {
  2839. babylonjs_1.Tools.Error("Cannot link a control to a mesh if the control is not at root level");
  2840. }
  2841. return;
  2842. }
  2843. var index = this._host._linkedControls.indexOf(this);
  2844. if (index !== -1) {
  2845. this._linkedMesh = mesh;
  2846. if (!mesh) {
  2847. this._host._linkedControls.splice(index, 1);
  2848. }
  2849. return;
  2850. }
  2851. else if (!mesh) {
  2852. return;
  2853. }
  2854. this.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  2855. this.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
  2856. this._linkedMesh = mesh;
  2857. this._onlyMeasureMode = this._currentMeasure.width === 0 || this._currentMeasure.height === 0;
  2858. this._host._linkedControls.push(this);
  2859. };
  2860. /** @hidden */
  2861. Control.prototype._moveToProjectedPosition = function (projectedPosition) {
  2862. var oldLeft = this._left.getValue(this._host);
  2863. var oldTop = this._top.getValue(this._host);
  2864. var newLeft = ((projectedPosition.x + this._linkOffsetX.getValue(this._host)) - this._currentMeasure.width / 2);
  2865. var newTop = ((projectedPosition.y + this._linkOffsetY.getValue(this._host)) - this._currentMeasure.height / 2);
  2866. if (this._left.ignoreAdaptiveScaling && this._top.ignoreAdaptiveScaling) {
  2867. if (Math.abs(newLeft - oldLeft) < 0.5) {
  2868. newLeft = oldLeft;
  2869. }
  2870. if (Math.abs(newTop - oldTop) < 0.5) {
  2871. newTop = oldTop;
  2872. }
  2873. }
  2874. this.left = newLeft + "px";
  2875. this.top = newTop + "px";
  2876. this._left.ignoreAdaptiveScaling = true;
  2877. this._top.ignoreAdaptiveScaling = true;
  2878. };
  2879. /** @hidden */
  2880. Control.prototype._markMatrixAsDirty = function () {
  2881. this._isMatrixDirty = true;
  2882. this._flagDescendantsAsMatrixDirty();
  2883. };
  2884. /** @hidden */
  2885. Control.prototype._flagDescendantsAsMatrixDirty = function () {
  2886. // No child
  2887. };
  2888. /** @hidden */
  2889. Control.prototype._markAsDirty = function (force) {
  2890. if (force === void 0) { force = false; }
  2891. if (!this._isVisible && !force) {
  2892. return;
  2893. }
  2894. this._isDirty = true;
  2895. if (!this._host) {
  2896. return; // Not yet connected
  2897. }
  2898. this._host.markAsDirty();
  2899. };
  2900. /** @hidden */
  2901. Control.prototype._markAllAsDirty = function () {
  2902. this._markAsDirty();
  2903. if (this._font) {
  2904. this._prepareFont();
  2905. }
  2906. };
  2907. /** @hidden */
  2908. Control.prototype._link = function (root, host) {
  2909. this._root = root;
  2910. this._host = host;
  2911. };
  2912. /** @hidden */
  2913. Control.prototype._transform = function (context) {
  2914. if (!this._isMatrixDirty && this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  2915. return;
  2916. }
  2917. // postTranslate
  2918. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  2919. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  2920. context.translate(offsetX, offsetY);
  2921. // rotate
  2922. context.rotate(this._rotation);
  2923. // scale
  2924. context.scale(this._scaleX, this._scaleY);
  2925. // preTranslate
  2926. context.translate(-offsetX, -offsetY);
  2927. // Need to update matrices?
  2928. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  2929. this._cachedOffsetX = offsetX;
  2930. this._cachedOffsetY = offsetY;
  2931. this._isMatrixDirty = false;
  2932. this._flagDescendantsAsMatrixDirty();
  2933. math2D_1.Matrix2D.ComposeToRef(-offsetX, -offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  2934. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  2935. }
  2936. };
  2937. /** @hidden */
  2938. Control.prototype._applyStates = function (context) {
  2939. if (this._isFontSizeInPercentage) {
  2940. this._fontSet = true;
  2941. }
  2942. if (this._fontSet) {
  2943. this._prepareFont();
  2944. this._fontSet = false;
  2945. }
  2946. if (this._font) {
  2947. context.font = this._font;
  2948. }
  2949. if (this._color) {
  2950. context.fillStyle = this._color;
  2951. }
  2952. if (this._alphaSet) {
  2953. context.globalAlpha = this.parent ? this.parent.alpha * this._alpha : this._alpha;
  2954. }
  2955. };
  2956. /** @hidden */
  2957. Control.prototype._processMeasures = function (parentMeasure, context) {
  2958. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  2959. this._isDirty = false;
  2960. this._currentMeasure.copyFrom(parentMeasure);
  2961. // Let children take some pre-measurement actions
  2962. this._preMeasure(parentMeasure, context);
  2963. this._measure();
  2964. this._computeAlignment(parentMeasure, context);
  2965. // Convert to int values
  2966. this._currentMeasure.left = this._currentMeasure.left | 0;
  2967. this._currentMeasure.top = this._currentMeasure.top | 0;
  2968. this._currentMeasure.width = this._currentMeasure.width | 0;
  2969. this._currentMeasure.height = this._currentMeasure.height | 0;
  2970. // Let children add more features
  2971. this._additionalProcessing(parentMeasure, context);
  2972. this._cachedParentMeasure.copyFrom(parentMeasure);
  2973. if (this.onDirtyObservable.hasObservers()) {
  2974. this.onDirtyObservable.notifyObservers(this);
  2975. }
  2976. }
  2977. if (this._currentMeasure.left > parentMeasure.left + parentMeasure.width) {
  2978. return false;
  2979. }
  2980. if (this._currentMeasure.left + this._currentMeasure.width < parentMeasure.left) {
  2981. return false;
  2982. }
  2983. if (this._currentMeasure.top > parentMeasure.top + parentMeasure.height) {
  2984. return false;
  2985. }
  2986. if (this._currentMeasure.top + this._currentMeasure.height < parentMeasure.top) {
  2987. return false;
  2988. }
  2989. // Transform
  2990. this._transform(context);
  2991. if (this._onlyMeasureMode) {
  2992. this._onlyMeasureMode = false;
  2993. return false; // We do not want rendering for this frame as they are measure dependant information that need to be gathered
  2994. }
  2995. // Clip
  2996. if (this.clipChildren) {
  2997. this._clip(context);
  2998. context.clip();
  2999. }
  3000. return true;
  3001. };
  3002. /** @hidden */
  3003. Control.prototype._clip = function (context) {
  3004. context.beginPath();
  3005. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3006. var shadowOffsetX = this.shadowOffsetX;
  3007. var shadowOffsetY = this.shadowOffsetY;
  3008. var shadowBlur = this.shadowBlur;
  3009. var leftShadowOffset = Math.min(Math.min(shadowOffsetX, 0) - shadowBlur * 2, 0);
  3010. var rightShadowOffset = Math.max(Math.max(shadowOffsetX, 0) + shadowBlur * 2, 0);
  3011. var topShadowOffset = Math.min(Math.min(shadowOffsetY, 0) - shadowBlur * 2, 0);
  3012. var bottomShadowOffset = Math.max(Math.max(shadowOffsetY, 0) + shadowBlur * 2, 0);
  3013. context.rect(this._currentMeasure.left + leftShadowOffset, this._currentMeasure.top + topShadowOffset, this._currentMeasure.width + rightShadowOffset - leftShadowOffset, this._currentMeasure.height + bottomShadowOffset - topShadowOffset);
  3014. }
  3015. else {
  3016. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3017. }
  3018. };
  3019. /** @hidden */
  3020. Control.prototype._measure = function () {
  3021. // Width / Height
  3022. if (this._width.isPixel) {
  3023. this._currentMeasure.width = this._width.getValue(this._host);
  3024. }
  3025. else {
  3026. this._currentMeasure.width *= this._width.getValue(this._host);
  3027. }
  3028. if (this._height.isPixel) {
  3029. this._currentMeasure.height = this._height.getValue(this._host);
  3030. }
  3031. else {
  3032. this._currentMeasure.height *= this._height.getValue(this._host);
  3033. }
  3034. };
  3035. /** @hidden */
  3036. Control.prototype._computeAlignment = function (parentMeasure, context) {
  3037. var width = this._currentMeasure.width;
  3038. var height = this._currentMeasure.height;
  3039. var parentWidth = parentMeasure.width;
  3040. var parentHeight = parentMeasure.height;
  3041. // Left / top
  3042. var x = 0;
  3043. var y = 0;
  3044. switch (this.horizontalAlignment) {
  3045. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  3046. x = 0;
  3047. break;
  3048. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  3049. x = parentWidth - width;
  3050. break;
  3051. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  3052. x = (parentWidth - width) / 2;
  3053. break;
  3054. }
  3055. switch (this.verticalAlignment) {
  3056. case Control.VERTICAL_ALIGNMENT_TOP:
  3057. y = 0;
  3058. break;
  3059. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  3060. y = parentHeight - height;
  3061. break;
  3062. case Control.VERTICAL_ALIGNMENT_CENTER:
  3063. y = (parentHeight - height) / 2;
  3064. break;
  3065. }
  3066. if (this._paddingLeft.isPixel) {
  3067. this._currentMeasure.left += this._paddingLeft.getValue(this._host);
  3068. this._currentMeasure.width -= this._paddingLeft.getValue(this._host);
  3069. }
  3070. else {
  3071. this._currentMeasure.left += parentWidth * this._paddingLeft.getValue(this._host);
  3072. this._currentMeasure.width -= parentWidth * this._paddingLeft.getValue(this._host);
  3073. }
  3074. if (this._paddingRight.isPixel) {
  3075. this._currentMeasure.width -= this._paddingRight.getValue(this._host);
  3076. }
  3077. else {
  3078. this._currentMeasure.width -= parentWidth * this._paddingRight.getValue(this._host);
  3079. }
  3080. if (this._paddingTop.isPixel) {
  3081. this._currentMeasure.top += this._paddingTop.getValue(this._host);
  3082. this._currentMeasure.height -= this._paddingTop.getValue(this._host);
  3083. }
  3084. else {
  3085. this._currentMeasure.top += parentHeight * this._paddingTop.getValue(this._host);
  3086. this._currentMeasure.height -= parentHeight * this._paddingTop.getValue(this._host);
  3087. }
  3088. if (this._paddingBottom.isPixel) {
  3089. this._currentMeasure.height -= this._paddingBottom.getValue(this._host);
  3090. }
  3091. else {
  3092. this._currentMeasure.height -= parentHeight * this._paddingBottom.getValue(this._host);
  3093. }
  3094. if (this._left.isPixel) {
  3095. this._currentMeasure.left += this._left.getValue(this._host);
  3096. }
  3097. else {
  3098. this._currentMeasure.left += parentWidth * this._left.getValue(this._host);
  3099. }
  3100. if (this._top.isPixel) {
  3101. this._currentMeasure.top += this._top.getValue(this._host);
  3102. }
  3103. else {
  3104. this._currentMeasure.top += parentHeight * this._top.getValue(this._host);
  3105. }
  3106. this._currentMeasure.left += x;
  3107. this._currentMeasure.top += y;
  3108. };
  3109. /** @hidden */
  3110. Control.prototype._preMeasure = function (parentMeasure, context) {
  3111. // Do nothing
  3112. };
  3113. /** @hidden */
  3114. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  3115. // Do nothing
  3116. };
  3117. /** @hidden */
  3118. Control.prototype._draw = function (parentMeasure, context) {
  3119. // Do nothing
  3120. };
  3121. /**
  3122. * Tests if a given coordinates belong to the current control
  3123. * @param x defines x coordinate to test
  3124. * @param y defines y coordinate to test
  3125. * @returns true if the coordinates are inside the control
  3126. */
  3127. Control.prototype.contains = function (x, y) {
  3128. // Invert transform
  3129. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  3130. x = this._transformedPosition.x;
  3131. y = this._transformedPosition.y;
  3132. // Check
  3133. if (x < this._currentMeasure.left) {
  3134. return false;
  3135. }
  3136. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  3137. return false;
  3138. }
  3139. if (y < this._currentMeasure.top) {
  3140. return false;
  3141. }
  3142. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  3143. return false;
  3144. }
  3145. if (this.isPointerBlocker) {
  3146. this._host._shouldBlockPointer = true;
  3147. }
  3148. return true;
  3149. };
  3150. /** @hidden */
  3151. Control.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  3152. if (!this._isEnabled) {
  3153. return false;
  3154. }
  3155. if (!this.isHitTestVisible || !this.isVisible || this._doNotRender) {
  3156. return false;
  3157. }
  3158. if (!this.contains(x, y)) {
  3159. return false;
  3160. }
  3161. this._processObservables(type, x, y, pointerId, buttonIndex);
  3162. return true;
  3163. };
  3164. /** @hidden */
  3165. Control.prototype._onPointerMove = function (target, coordinates) {
  3166. var canNotify = this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  3167. if (canNotify && this.parent != null) {
  3168. this.parent._onPointerMove(target, coordinates);
  3169. }
  3170. };
  3171. /** @hidden */
  3172. Control.prototype._onPointerEnter = function (target) {
  3173. if (!this._isEnabled) {
  3174. return false;
  3175. }
  3176. if (this._enterCount > 0) {
  3177. return false;
  3178. }
  3179. if (this._enterCount === -1) { // -1 is for touch input, we are now sure we are with a mouse or pencil
  3180. this._enterCount = 0;
  3181. }
  3182. this._enterCount++;
  3183. var canNotify = this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  3184. if (canNotify && this.parent != null) {
  3185. this.parent._onPointerEnter(target);
  3186. }
  3187. return true;
  3188. };
  3189. /** @hidden */
  3190. Control.prototype._onPointerOut = function (target) {
  3191. if (!this._isEnabled) {
  3192. return;
  3193. }
  3194. this._enterCount = 0;
  3195. var canNotify = this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  3196. if (canNotify && this.parent != null) {
  3197. this.parent._onPointerOut(target);
  3198. }
  3199. };
  3200. /** @hidden */
  3201. Control.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3202. // Prevent pointerout to lose control context.
  3203. // Event redundancy is checked inside the function.
  3204. this._onPointerEnter(this);
  3205. if (this._downCount !== 0) {
  3206. return false;
  3207. }
  3208. this._downCount++;
  3209. this._downPointerIds[pointerId] = true;
  3210. var canNotify = this.onPointerDownObservable.notifyObservers(new math2D_1.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  3211. if (canNotify && this.parent != null) {
  3212. this.parent._onPointerDown(target, coordinates, pointerId, buttonIndex);
  3213. }
  3214. return true;
  3215. };
  3216. /** @hidden */
  3217. Control.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  3218. if (!this._isEnabled) {
  3219. return;
  3220. }
  3221. this._downCount = 0;
  3222. delete this._downPointerIds[pointerId];
  3223. var canNotifyClick = notifyClick;
  3224. if (notifyClick && (this._enterCount > 0 || this._enterCount === -1)) {
  3225. canNotifyClick = this.onPointerClickObservable.notifyObservers(new math2D_1.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  3226. }
  3227. var canNotify = this.onPointerUpObservable.notifyObservers(new math2D_1.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  3228. if (canNotify && this.parent != null) {
  3229. this.parent._onPointerUp(target, coordinates, pointerId, buttonIndex, canNotifyClick);
  3230. }
  3231. };
  3232. /** @hidden */
  3233. Control.prototype._forcePointerUp = function (pointerId) {
  3234. if (pointerId === void 0) { pointerId = null; }
  3235. if (pointerId !== null) {
  3236. this._onPointerUp(this, babylonjs_1.Vector2.Zero(), pointerId, 0, true);
  3237. }
  3238. else {
  3239. for (var key in this._downPointerIds) {
  3240. this._onPointerUp(this, babylonjs_1.Vector2.Zero(), +key, 0, true);
  3241. }
  3242. }
  3243. };
  3244. /** @hidden */
  3245. Control.prototype._processObservables = function (type, x, y, pointerId, buttonIndex) {
  3246. if (!this._isEnabled) {
  3247. return false;
  3248. }
  3249. this._dummyVector2.copyFromFloats(x, y);
  3250. if (type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  3251. this._onPointerMove(this, this._dummyVector2);
  3252. var previousControlOver = this._host._lastControlOver[pointerId];
  3253. if (previousControlOver && previousControlOver !== this) {
  3254. previousControlOver._onPointerOut(this);
  3255. }
  3256. if (previousControlOver !== this) {
  3257. this._onPointerEnter(this);
  3258. }
  3259. this._host._lastControlOver[pointerId] = this;
  3260. return true;
  3261. }
  3262. if (type === babylonjs_1.PointerEventTypes.POINTERDOWN) {
  3263. this._onPointerDown(this, this._dummyVector2, pointerId, buttonIndex);
  3264. this._host._lastControlDown[pointerId] = this;
  3265. this._host._lastPickedControl = this;
  3266. return true;
  3267. }
  3268. if (type === babylonjs_1.PointerEventTypes.POINTERUP) {
  3269. if (this._host._lastControlDown[pointerId]) {
  3270. this._host._lastControlDown[pointerId]._onPointerUp(this, this._dummyVector2, pointerId, buttonIndex, true);
  3271. }
  3272. delete this._host._lastControlDown[pointerId];
  3273. return true;
  3274. }
  3275. return false;
  3276. };
  3277. Control.prototype._prepareFont = function () {
  3278. if (!this._font && !this._fontSet) {
  3279. return;
  3280. }
  3281. if (this._style) {
  3282. this._font = this._style.fontStyle + " " + this._style.fontWeight + " " + this.fontSizeInPixels + "px " + this._style.fontFamily;
  3283. }
  3284. else {
  3285. this._font = this._fontStyle + " " + this._fontWeight + " " + this.fontSizeInPixels + "px " + this._fontFamily;
  3286. }
  3287. this._fontOffset = Control._GetFontOffset(this._font);
  3288. };
  3289. /** Releases associated resources */
  3290. Control.prototype.dispose = function () {
  3291. this.onDirtyObservable.clear();
  3292. this.onAfterDrawObservable.clear();
  3293. this.onPointerDownObservable.clear();
  3294. this.onPointerEnterObservable.clear();
  3295. this.onPointerMoveObservable.clear();
  3296. this.onPointerOutObservable.clear();
  3297. this.onPointerUpObservable.clear();
  3298. this.onPointerClickObservable.clear();
  3299. if (this._styleObserver && this._style) {
  3300. this._style.onChangedObservable.remove(this._styleObserver);
  3301. this._styleObserver = null;
  3302. }
  3303. if (this._root) {
  3304. this._root.removeControl(this);
  3305. this._root = null;
  3306. }
  3307. if (this._host) {
  3308. var index = this._host._linkedControls.indexOf(this);
  3309. if (index > -1) {
  3310. this.linkWithMesh(null);
  3311. }
  3312. }
  3313. };
  3314. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  3315. /** HORIZONTAL_ALIGNMENT_LEFT */
  3316. get: function () {
  3317. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  3318. },
  3319. enumerable: true,
  3320. configurable: true
  3321. });
  3322. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  3323. /** HORIZONTAL_ALIGNMENT_RIGHT */
  3324. get: function () {
  3325. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  3326. },
  3327. enumerable: true,
  3328. configurable: true
  3329. });
  3330. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  3331. /** HORIZONTAL_ALIGNMENT_CENTER */
  3332. get: function () {
  3333. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  3334. },
  3335. enumerable: true,
  3336. configurable: true
  3337. });
  3338. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  3339. /** VERTICAL_ALIGNMENT_TOP */
  3340. get: function () {
  3341. return Control._VERTICAL_ALIGNMENT_TOP;
  3342. },
  3343. enumerable: true,
  3344. configurable: true
  3345. });
  3346. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  3347. /** VERTICAL_ALIGNMENT_BOTTOM */
  3348. get: function () {
  3349. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  3350. },
  3351. enumerable: true,
  3352. configurable: true
  3353. });
  3354. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  3355. /** VERTICAL_ALIGNMENT_CENTER */
  3356. get: function () {
  3357. return Control._VERTICAL_ALIGNMENT_CENTER;
  3358. },
  3359. enumerable: true,
  3360. configurable: true
  3361. });
  3362. /** @hidden */
  3363. Control._GetFontOffset = function (font) {
  3364. if (Control._FontHeightSizes[font]) {
  3365. return Control._FontHeightSizes[font];
  3366. }
  3367. var text = document.createElement("span");
  3368. text.innerHTML = "Hg";
  3369. text.style.font = font;
  3370. var block = document.createElement("div");
  3371. block.style.display = "inline-block";
  3372. block.style.width = "1px";
  3373. block.style.height = "0px";
  3374. block.style.verticalAlign = "bottom";
  3375. var div = document.createElement("div");
  3376. div.appendChild(text);
  3377. div.appendChild(block);
  3378. document.body.appendChild(div);
  3379. var fontAscent = 0;
  3380. var fontHeight = 0;
  3381. try {
  3382. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  3383. block.style.verticalAlign = "baseline";
  3384. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  3385. }
  3386. finally {
  3387. document.body.removeChild(div);
  3388. }
  3389. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  3390. Control._FontHeightSizes[font] = result;
  3391. return result;
  3392. };
  3393. /** @hidden */
  3394. Control.drawEllipse = function (x, y, width, height, context) {
  3395. context.translate(x, y);
  3396. context.scale(width, height);
  3397. context.beginPath();
  3398. context.arc(0, 0, 1, 0, 2 * Math.PI);
  3399. context.closePath();
  3400. context.scale(1 / width, 1 / height);
  3401. context.translate(-x, -y);
  3402. };
  3403. // Statics
  3404. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  3405. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  3406. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  3407. Control._VERTICAL_ALIGNMENT_TOP = 0;
  3408. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  3409. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  3410. Control._FontHeightSizes = {};
  3411. /**
  3412. * Creates a stack panel that can be used to render headers
  3413. * @param control defines the control to associate with the header
  3414. * @param text defines the text of the header
  3415. * @param size defines the size of the header
  3416. * @param options defines options used to configure the header
  3417. * @returns a new StackPanel
  3418. * @ignore
  3419. * @hidden
  3420. */
  3421. Control.AddHeader = function () { };
  3422. return Control;
  3423. }());
  3424. exports.Control = Control;
  3425. /***/ }),
  3426. /***/ "./src/2D/controls/displayGrid.ts":
  3427. /*!****************************************!*\
  3428. !*** ./src/2D/controls/displayGrid.ts ***!
  3429. \****************************************/
  3430. /*! no static exports found */
  3431. /***/ (function(module, exports, __webpack_require__) {
  3432. "use strict";
  3433. var __extends = (this && this.__extends) || (function () {
  3434. var extendStatics = function (d, b) {
  3435. extendStatics = Object.setPrototypeOf ||
  3436. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3437. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3438. return extendStatics(d, b);
  3439. }
  3440. return function (d, b) {
  3441. extendStatics(d, b);
  3442. function __() { this.constructor = d; }
  3443. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3444. };
  3445. })();
  3446. Object.defineProperty(exports, "__esModule", { value: true });
  3447. var _1 = __webpack_require__(/*! . */ "./src/2D/controls/index.ts");
  3448. /** Class used to render a grid */
  3449. var DisplayGrid = /** @class */ (function (_super) {
  3450. __extends(DisplayGrid, _super);
  3451. /**
  3452. * Creates a new GridDisplayRectangle
  3453. * @param name defines the control name
  3454. */
  3455. function DisplayGrid(name) {
  3456. var _this = _super.call(this, name) || this;
  3457. _this.name = name;
  3458. _this._cellWidth = 20;
  3459. _this._cellHeight = 20;
  3460. _this._minorLineTickness = 1;
  3461. _this._minorLineColor = "DarkGray";
  3462. _this._majorLineTickness = 2;
  3463. _this._majorLineColor = "White";
  3464. _this._majorLineFrequency = 5;
  3465. _this._background = "Black";
  3466. _this._displayMajorLines = true;
  3467. _this._displayMinorLines = true;
  3468. return _this;
  3469. }
  3470. Object.defineProperty(DisplayGrid.prototype, "displayMinorLines", {
  3471. /** Gets or sets a boolean indicating if minor lines must be rendered (true by default)) */
  3472. get: function () {
  3473. return this._displayMinorLines;
  3474. },
  3475. set: function (value) {
  3476. if (this._displayMinorLines === value) {
  3477. return;
  3478. }
  3479. this._displayMinorLines = value;
  3480. this._markAsDirty();
  3481. },
  3482. enumerable: true,
  3483. configurable: true
  3484. });
  3485. Object.defineProperty(DisplayGrid.prototype, "displayMajorLines", {
  3486. /** Gets or sets a boolean indicating if major lines must be rendered (true by default)) */
  3487. get: function () {
  3488. return this._displayMajorLines;
  3489. },
  3490. set: function (value) {
  3491. if (this._displayMajorLines === value) {
  3492. return;
  3493. }
  3494. this._displayMajorLines = value;
  3495. this._markAsDirty();
  3496. },
  3497. enumerable: true,
  3498. configurable: true
  3499. });
  3500. Object.defineProperty(DisplayGrid.prototype, "background", {
  3501. /** Gets or sets background color (Black by default) */
  3502. get: function () {
  3503. return this._background;
  3504. },
  3505. set: function (value) {
  3506. if (this._background === value) {
  3507. return;
  3508. }
  3509. this._background = value;
  3510. this._markAsDirty();
  3511. },
  3512. enumerable: true,
  3513. configurable: true
  3514. });
  3515. Object.defineProperty(DisplayGrid.prototype, "cellWidth", {
  3516. /** Gets or sets the width of each cell (20 by default) */
  3517. get: function () {
  3518. return this._cellWidth;
  3519. },
  3520. set: function (value) {
  3521. this._cellWidth = value;
  3522. this._markAsDirty();
  3523. },
  3524. enumerable: true,
  3525. configurable: true
  3526. });
  3527. Object.defineProperty(DisplayGrid.prototype, "cellHeight", {
  3528. /** Gets or sets the height of each cell (20 by default) */
  3529. get: function () {
  3530. return this._cellHeight;
  3531. },
  3532. set: function (value) {
  3533. this._cellHeight = value;
  3534. this._markAsDirty();
  3535. },
  3536. enumerable: true,
  3537. configurable: true
  3538. });
  3539. Object.defineProperty(DisplayGrid.prototype, "minorLineTickness", {
  3540. /** Gets or sets the tickness of minor lines (1 by default) */
  3541. get: function () {
  3542. return this._minorLineTickness;
  3543. },
  3544. set: function (value) {
  3545. this._minorLineTickness = value;
  3546. this._markAsDirty();
  3547. },
  3548. enumerable: true,
  3549. configurable: true
  3550. });
  3551. Object.defineProperty(DisplayGrid.prototype, "minorLineColor", {
  3552. /** Gets or sets the color of minor lines (DarkGray by default) */
  3553. get: function () {
  3554. return this._minorLineColor;
  3555. },
  3556. set: function (value) {
  3557. this._minorLineColor = value;
  3558. this._markAsDirty();
  3559. },
  3560. enumerable: true,
  3561. configurable: true
  3562. });
  3563. Object.defineProperty(DisplayGrid.prototype, "majorLineTickness", {
  3564. /** Gets or sets the tickness of major lines (2 by default) */
  3565. get: function () {
  3566. return this._majorLineTickness;
  3567. },
  3568. set: function (value) {
  3569. this._majorLineTickness = value;
  3570. this._markAsDirty();
  3571. },
  3572. enumerable: true,
  3573. configurable: true
  3574. });
  3575. Object.defineProperty(DisplayGrid.prototype, "majorLineColor", {
  3576. /** Gets or sets the color of major lines (White by default) */
  3577. get: function () {
  3578. return this._majorLineColor;
  3579. },
  3580. set: function (value) {
  3581. this._majorLineColor = value;
  3582. this._markAsDirty();
  3583. },
  3584. enumerable: true,
  3585. configurable: true
  3586. });
  3587. Object.defineProperty(DisplayGrid.prototype, "majorLineFrequency", {
  3588. /** Gets or sets the frequency of major lines (default is 1 every 5 minor lines)*/
  3589. get: function () {
  3590. return this._majorLineFrequency;
  3591. },
  3592. set: function (value) {
  3593. this._majorLineFrequency = value;
  3594. this._markAsDirty();
  3595. },
  3596. enumerable: true,
  3597. configurable: true
  3598. });
  3599. DisplayGrid.prototype._draw = function (parentMeasure, context) {
  3600. context.save();
  3601. this._applyStates(context);
  3602. if (this._isEnabled && this._processMeasures(parentMeasure, context)) {
  3603. if (this._background) {
  3604. context.fillStyle = this._background;
  3605. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3606. }
  3607. var cellCountX = this._currentMeasure.width / this._cellWidth;
  3608. var cellCountY = this._currentMeasure.height / this._cellHeight;
  3609. // Minor lines
  3610. var left = this._currentMeasure.left + this._currentMeasure.width / 2;
  3611. var top_1 = this._currentMeasure.top + this._currentMeasure.height / 2;
  3612. if (this._displayMinorLines) {
  3613. context.strokeStyle = this._minorLineColor;
  3614. context.lineWidth = this._minorLineTickness;
  3615. for (var x = -cellCountX / 2; x < cellCountX / 2; x++) {
  3616. var cellX = left + x * this.cellWidth;
  3617. context.beginPath();
  3618. context.moveTo(cellX, this._currentMeasure.top);
  3619. context.lineTo(cellX, this._currentMeasure.top + this._currentMeasure.height);
  3620. context.stroke();
  3621. }
  3622. for (var y = -cellCountY / 2; y < cellCountY / 2; y++) {
  3623. var cellY = top_1 + y * this.cellHeight;
  3624. context.beginPath();
  3625. context.moveTo(this._currentMeasure.left, cellY);
  3626. context.lineTo(this._currentMeasure.left + this._currentMeasure.width, cellY);
  3627. context.stroke();
  3628. }
  3629. }
  3630. // Major lines
  3631. if (this._displayMajorLines) {
  3632. context.strokeStyle = this._majorLineColor;
  3633. context.lineWidth = this._majorLineTickness;
  3634. for (var x = -cellCountX / 2 + this._majorLineFrequency; x < cellCountX / 2; x += this._majorLineFrequency) {
  3635. var cellX = left + x * this.cellWidth;
  3636. context.beginPath();
  3637. context.moveTo(cellX, this._currentMeasure.top);
  3638. context.lineTo(cellX, this._currentMeasure.top + this._currentMeasure.height);
  3639. context.stroke();
  3640. }
  3641. for (var y = -cellCountY / 2 + this._majorLineFrequency; y < cellCountY / 2; y += this._majorLineFrequency) {
  3642. var cellY = top_1 + y * this.cellHeight;
  3643. context.moveTo(this._currentMeasure.left, cellY);
  3644. context.lineTo(this._currentMeasure.left + this._currentMeasure.width, cellY);
  3645. context.closePath();
  3646. context.stroke();
  3647. }
  3648. }
  3649. }
  3650. context.restore();
  3651. };
  3652. DisplayGrid.prototype._getTypeName = function () {
  3653. return "DisplayGrid";
  3654. };
  3655. return DisplayGrid;
  3656. }(_1.Control));
  3657. exports.DisplayGrid = DisplayGrid;
  3658. /***/ }),
  3659. /***/ "./src/2D/controls/ellipse.ts":
  3660. /*!************************************!*\
  3661. !*** ./src/2D/controls/ellipse.ts ***!
  3662. \************************************/
  3663. /*! no static exports found */
  3664. /***/ (function(module, exports, __webpack_require__) {
  3665. "use strict";
  3666. var __extends = (this && this.__extends) || (function () {
  3667. var extendStatics = function (d, b) {
  3668. extendStatics = Object.setPrototypeOf ||
  3669. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3670. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3671. return extendStatics(d, b);
  3672. }
  3673. return function (d, b) {
  3674. extendStatics(d, b);
  3675. function __() { this.constructor = d; }
  3676. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3677. };
  3678. })();
  3679. Object.defineProperty(exports, "__esModule", { value: true });
  3680. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  3681. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  3682. /** Class used to create 2D ellipse containers */
  3683. var Ellipse = /** @class */ (function (_super) {
  3684. __extends(Ellipse, _super);
  3685. /**
  3686. * Creates a new Ellipse
  3687. * @param name defines the control name
  3688. */
  3689. function Ellipse(name) {
  3690. var _this = _super.call(this, name) || this;
  3691. _this.name = name;
  3692. _this._thickness = 1;
  3693. return _this;
  3694. }
  3695. Object.defineProperty(Ellipse.prototype, "thickness", {
  3696. /** Gets or sets border thickness */
  3697. get: function () {
  3698. return this._thickness;
  3699. },
  3700. set: function (value) {
  3701. if (this._thickness === value) {
  3702. return;
  3703. }
  3704. this._thickness = value;
  3705. this._markAsDirty();
  3706. },
  3707. enumerable: true,
  3708. configurable: true
  3709. });
  3710. Ellipse.prototype._getTypeName = function () {
  3711. return "Ellipse";
  3712. };
  3713. Ellipse.prototype._localDraw = function (context) {
  3714. context.save();
  3715. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3716. context.shadowColor = this.shadowColor;
  3717. context.shadowBlur = this.shadowBlur;
  3718. context.shadowOffsetX = this.shadowOffsetX;
  3719. context.shadowOffsetY = this.shadowOffsetY;
  3720. }
  3721. control_1.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);
  3722. if (this._background) {
  3723. context.fillStyle = this._background;
  3724. context.fill();
  3725. }
  3726. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3727. context.shadowBlur = 0;
  3728. context.shadowOffsetX = 0;
  3729. context.shadowOffsetY = 0;
  3730. }
  3731. if (this._thickness) {
  3732. if (this.color) {
  3733. context.strokeStyle = this.color;
  3734. }
  3735. context.lineWidth = this._thickness;
  3736. context.stroke();
  3737. }
  3738. context.restore();
  3739. };
  3740. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  3741. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  3742. this._measureForChildren.width -= 2 * this._thickness;
  3743. this._measureForChildren.height -= 2 * this._thickness;
  3744. this._measureForChildren.left += this._thickness;
  3745. this._measureForChildren.top += this._thickness;
  3746. };
  3747. Ellipse.prototype._clipForChildren = function (context) {
  3748. control_1.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);
  3749. context.clip();
  3750. };
  3751. return Ellipse;
  3752. }(container_1.Container));
  3753. exports.Ellipse = Ellipse;
  3754. /***/ }),
  3755. /***/ "./src/2D/controls/grid.ts":
  3756. /*!*********************************!*\
  3757. !*** ./src/2D/controls/grid.ts ***!
  3758. \*********************************/
  3759. /*! no static exports found */
  3760. /***/ (function(module, exports, __webpack_require__) {
  3761. "use strict";
  3762. var __extends = (this && this.__extends) || (function () {
  3763. var extendStatics = function (d, b) {
  3764. extendStatics = Object.setPrototypeOf ||
  3765. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3766. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3767. return extendStatics(d, b);
  3768. }
  3769. return function (d, b) {
  3770. extendStatics(d, b);
  3771. function __() { this.constructor = d; }
  3772. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3773. };
  3774. })();
  3775. Object.defineProperty(exports, "__esModule", { value: true });
  3776. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  3777. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  3778. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  3779. /**
  3780. * Class used to create a 2D grid container
  3781. */
  3782. var Grid = /** @class */ (function (_super) {
  3783. __extends(Grid, _super);
  3784. /**
  3785. * Creates a new Grid
  3786. * @param name defines control name
  3787. */
  3788. function Grid(name) {
  3789. var _this = _super.call(this, name) || this;
  3790. _this.name = name;
  3791. _this._rowDefinitions = new Array();
  3792. _this._columnDefinitions = new Array();
  3793. _this._cells = {};
  3794. _this._childControls = new Array();
  3795. return _this;
  3796. }
  3797. Object.defineProperty(Grid.prototype, "children", {
  3798. /** Gets the list of children */
  3799. get: function () {
  3800. return this._childControls;
  3801. },
  3802. enumerable: true,
  3803. configurable: true
  3804. });
  3805. /**
  3806. * Adds a new row to the grid
  3807. * @param height defines the height of the row (either in pixel or a value between 0 and 1)
  3808. * @param isPixel defines if the height is expressed in pixel (or in percentage)
  3809. * @returns the current grid
  3810. */
  3811. Grid.prototype.addRowDefinition = function (height, isPixel) {
  3812. if (isPixel === void 0) { isPixel = false; }
  3813. this._rowDefinitions.push(new valueAndUnit_1.ValueAndUnit(height, isPixel ? valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL : valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE));
  3814. this._markAsDirty();
  3815. return this;
  3816. };
  3817. /**
  3818. * Adds a new column to the grid
  3819. * @param width defines the width of the column (either in pixel or a value between 0 and 1)
  3820. * @param isPixel defines if the width is expressed in pixel (or in percentage)
  3821. * @returns the current grid
  3822. */
  3823. Grid.prototype.addColumnDefinition = function (width, isPixel) {
  3824. if (isPixel === void 0) { isPixel = false; }
  3825. this._columnDefinitions.push(new valueAndUnit_1.ValueAndUnit(width, isPixel ? valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL : valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE));
  3826. this._markAsDirty();
  3827. return this;
  3828. };
  3829. /**
  3830. * Update a row definition
  3831. * @param index defines the index of the row to update
  3832. * @param height defines the height of the row (either in pixel or a value between 0 and 1)
  3833. * @param isPixel defines if the weight is expressed in pixel (or in percentage)
  3834. * @returns the current grid
  3835. */
  3836. Grid.prototype.setRowDefinition = function (index, height, isPixel) {
  3837. if (isPixel === void 0) { isPixel = false; }
  3838. if (index < 0 || index >= this._rowDefinitions.length) {
  3839. return this;
  3840. }
  3841. this._rowDefinitions[index] = new valueAndUnit_1.ValueAndUnit(height, isPixel ? valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL : valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE);
  3842. this._markAsDirty();
  3843. return this;
  3844. };
  3845. /**
  3846. * Update a column definition
  3847. * @param index defines the index of the column to update
  3848. * @param width defines the width of the column (either in pixel or a value between 0 and 1)
  3849. * @param isPixel defines if the width is expressed in pixel (or in percentage)
  3850. * @returns the current grid
  3851. */
  3852. Grid.prototype.setColumnDefinition = function (index, width, isPixel) {
  3853. if (isPixel === void 0) { isPixel = false; }
  3854. if (index < 0 || index >= this._columnDefinitions.length) {
  3855. return this;
  3856. }
  3857. this._columnDefinitions[index] = new valueAndUnit_1.ValueAndUnit(width, isPixel ? valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL : valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE);
  3858. this._markAsDirty();
  3859. return this;
  3860. };
  3861. Grid.prototype._removeCell = function (cell, key) {
  3862. if (!cell) {
  3863. return;
  3864. }
  3865. _super.prototype.removeControl.call(this, cell);
  3866. for (var _i = 0, _a = cell.children; _i < _a.length; _i++) {
  3867. var control = _a[_i];
  3868. var childIndex = this._childControls.indexOf(control);
  3869. if (childIndex !== -1) {
  3870. this._childControls.splice(childIndex, 1);
  3871. }
  3872. }
  3873. delete this._cells[key];
  3874. };
  3875. Grid.prototype._offsetCell = function (previousKey, key) {
  3876. if (!this._cells[key]) {
  3877. return;
  3878. }
  3879. this._cells[previousKey] = this._cells[key];
  3880. for (var _i = 0, _a = this._cells[previousKey].children; _i < _a.length; _i++) {
  3881. var control = _a[_i];
  3882. control._tag = previousKey;
  3883. }
  3884. delete this._cells[key];
  3885. };
  3886. /**
  3887. * Remove a column definition at specified index
  3888. * @param index defines the index of the column to remove
  3889. * @returns the current grid
  3890. */
  3891. Grid.prototype.removeColumnDefinition = function (index) {
  3892. if (index < 0 || index >= this._columnDefinitions.length) {
  3893. return this;
  3894. }
  3895. for (var x = 0; x < this._rowDefinitions.length; x++) {
  3896. var key = x + ":" + index;
  3897. var cell = this._cells[key];
  3898. this._removeCell(cell, key);
  3899. }
  3900. for (var x = 0; x < this._rowDefinitions.length; x++) {
  3901. for (var y = index + 1; y < this._columnDefinitions.length; y++) {
  3902. var previousKey = x + ":" + (y - 1);
  3903. var key = x + ":" + y;
  3904. this._offsetCell(previousKey, key);
  3905. }
  3906. }
  3907. this._columnDefinitions.splice(index, 1);
  3908. this._markAsDirty();
  3909. return this;
  3910. };
  3911. /**
  3912. * Remove a row definition at specified index
  3913. * @param index defines the index of the row to remove
  3914. * @returns the current grid
  3915. */
  3916. Grid.prototype.removeRowDefinition = function (index) {
  3917. if (index < 0 || index >= this._rowDefinitions.length) {
  3918. return this;
  3919. }
  3920. for (var y = 0; y < this._columnDefinitions.length; y++) {
  3921. var key = index + ":" + y;
  3922. var cell = this._cells[key];
  3923. this._removeCell(cell, key);
  3924. }
  3925. for (var y = 0; y < this._columnDefinitions.length; y++) {
  3926. for (var x = index + 1; x < this._rowDefinitions.length; x++) {
  3927. var previousKey = x - 1 + ":" + y;
  3928. var key = x + ":" + y;
  3929. this._offsetCell(previousKey, key);
  3930. }
  3931. }
  3932. this._rowDefinitions.splice(index, 1);
  3933. this._markAsDirty();
  3934. return this;
  3935. };
  3936. /**
  3937. * Adds a new control to the current grid
  3938. * @param control defines the control to add
  3939. * @param row defines the row where to add the control (0 by default)
  3940. * @param column defines the column where to add the control (0 by default)
  3941. * @returns the current grid
  3942. */
  3943. Grid.prototype.addControl = function (control, row, column) {
  3944. if (row === void 0) { row = 0; }
  3945. if (column === void 0) { column = 0; }
  3946. if (this._rowDefinitions.length === 0) {
  3947. // Add default row definition
  3948. this.addRowDefinition(1, false);
  3949. }
  3950. if (this._columnDefinitions.length === 0) {
  3951. // Add default column definition
  3952. this.addColumnDefinition(1, false);
  3953. }
  3954. var x = Math.min(row, this._rowDefinitions.length - 1);
  3955. var y = Math.min(column, this._columnDefinitions.length - 1);
  3956. var key = x + ":" + y;
  3957. var goodContainer = this._cells[key];
  3958. if (!goodContainer) {
  3959. goodContainer = new container_1.Container(key);
  3960. this._cells[key] = goodContainer;
  3961. goodContainer.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3962. goodContainer.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  3963. _super.prototype.addControl.call(this, goodContainer);
  3964. }
  3965. goodContainer.addControl(control);
  3966. this._childControls.push(control);
  3967. control._tag = key;
  3968. this._markAsDirty();
  3969. return this;
  3970. };
  3971. /**
  3972. * Removes a control from the current container
  3973. * @param control defines the control to remove
  3974. * @returns the current container
  3975. */
  3976. Grid.prototype.removeControl = function (control) {
  3977. var index = this._childControls.indexOf(control);
  3978. if (index !== -1) {
  3979. this._childControls.splice(index, 1);
  3980. }
  3981. var cell = this._cells[control._tag];
  3982. if (cell) {
  3983. cell.removeControl(control);
  3984. }
  3985. this._markAsDirty();
  3986. return this;
  3987. };
  3988. Grid.prototype._getTypeName = function () {
  3989. return "Grid";
  3990. };
  3991. Grid.prototype._additionalProcessing = function (parentMeasure, context) {
  3992. var widths = [];
  3993. var heights = [];
  3994. var lefts = [];
  3995. var tops = [];
  3996. var availableWidth = this._currentMeasure.width;
  3997. var globalWidthPercentage = 0;
  3998. var availableHeight = this._currentMeasure.height;
  3999. var globalHeightPercentage = 0;
  4000. // Heights
  4001. var index = 0;
  4002. for (var _i = 0, _a = this._rowDefinitions; _i < _a.length; _i++) {
  4003. var value = _a[_i];
  4004. if (value.isPixel) {
  4005. var height = value.getValue(this._host);
  4006. availableHeight -= height;
  4007. heights[index] = height;
  4008. }
  4009. else {
  4010. globalHeightPercentage += value.internalValue;
  4011. }
  4012. index++;
  4013. }
  4014. var top = 0;
  4015. index = 0;
  4016. for (var _b = 0, _c = this._rowDefinitions; _b < _c.length; _b++) {
  4017. var value = _c[_b];
  4018. tops.push(top);
  4019. if (!value.isPixel) {
  4020. var height = (value.internalValue / globalHeightPercentage) * availableHeight;
  4021. top += height;
  4022. heights[index] = height;
  4023. }
  4024. else {
  4025. top += value.getValue(this._host);
  4026. }
  4027. index++;
  4028. }
  4029. // Widths
  4030. index = 0;
  4031. for (var _d = 0, _e = this._columnDefinitions; _d < _e.length; _d++) {
  4032. var value = _e[_d];
  4033. if (value.isPixel) {
  4034. var width = value.getValue(this._host);
  4035. availableWidth -= width;
  4036. widths[index] = width;
  4037. }
  4038. else {
  4039. globalWidthPercentage += value.internalValue;
  4040. }
  4041. index++;
  4042. }
  4043. var left = 0;
  4044. index = 0;
  4045. for (var _f = 0, _g = this._columnDefinitions; _f < _g.length; _f++) {
  4046. var value = _g[_f];
  4047. lefts.push(left);
  4048. if (!value.isPixel) {
  4049. var width = (value.internalValue / globalWidthPercentage) * availableWidth;
  4050. left += width;
  4051. widths[index] = width;
  4052. }
  4053. else {
  4054. left += value.getValue(this._host);
  4055. }
  4056. index++;
  4057. }
  4058. // Setting child sizes
  4059. for (var key in this._cells) {
  4060. if (!this._cells.hasOwnProperty(key)) {
  4061. continue;
  4062. }
  4063. var split = key.split(":");
  4064. var x = parseInt(split[0]);
  4065. var y = parseInt(split[1]);
  4066. var cell = this._cells[key];
  4067. cell.left = lefts[y] + "px";
  4068. cell.top = tops[x] + "px";
  4069. cell.width = widths[y] + "px";
  4070. cell.height = heights[x] + "px";
  4071. }
  4072. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  4073. };
  4074. /** Releases associated resources */
  4075. Grid.prototype.dispose = function () {
  4076. _super.prototype.dispose.call(this);
  4077. for (var _i = 0, _a = this._childControls; _i < _a.length; _i++) {
  4078. var control = _a[_i];
  4079. control.dispose();
  4080. }
  4081. };
  4082. return Grid;
  4083. }(container_1.Container));
  4084. exports.Grid = Grid;
  4085. /***/ }),
  4086. /***/ "./src/2D/controls/image.ts":
  4087. /*!**********************************!*\
  4088. !*** ./src/2D/controls/image.ts ***!
  4089. \**********************************/
  4090. /*! no static exports found */
  4091. /***/ (function(module, exports, __webpack_require__) {
  4092. "use strict";
  4093. var __extends = (this && this.__extends) || (function () {
  4094. var extendStatics = function (d, b) {
  4095. extendStatics = Object.setPrototypeOf ||
  4096. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4097. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4098. return extendStatics(d, b);
  4099. }
  4100. return function (d, b) {
  4101. extendStatics(d, b);
  4102. function __() { this.constructor = d; }
  4103. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4104. };
  4105. })();
  4106. Object.defineProperty(exports, "__esModule", { value: true });
  4107. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  4108. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  4109. /**
  4110. * Class used to create 2D images
  4111. */
  4112. var Image = /** @class */ (function (_super) {
  4113. __extends(Image, _super);
  4114. /**
  4115. * Creates a new Image
  4116. * @param name defines the control name
  4117. * @param url defines the image url
  4118. */
  4119. function Image(name, url) {
  4120. if (url === void 0) { url = null; }
  4121. var _this = _super.call(this, name) || this;
  4122. _this.name = name;
  4123. _this._loaded = false;
  4124. _this._stretch = Image.STRETCH_FILL;
  4125. _this._autoScale = false;
  4126. _this._sourceLeft = 0;
  4127. _this._sourceTop = 0;
  4128. _this._sourceWidth = 0;
  4129. _this._sourceHeight = 0;
  4130. _this._cellWidth = 0;
  4131. _this._cellHeight = 0;
  4132. _this._cellId = -1;
  4133. _this.source = url;
  4134. return _this;
  4135. }
  4136. Object.defineProperty(Image.prototype, "sourceLeft", {
  4137. /**
  4138. * Gets or sets the left coordinate in the source image
  4139. */
  4140. get: function () {
  4141. return this._sourceLeft;
  4142. },
  4143. set: function (value) {
  4144. if (this._sourceLeft === value) {
  4145. return;
  4146. }
  4147. this._sourceLeft = value;
  4148. this._markAsDirty();
  4149. },
  4150. enumerable: true,
  4151. configurable: true
  4152. });
  4153. Object.defineProperty(Image.prototype, "sourceTop", {
  4154. /**
  4155. * Gets or sets the top coordinate in the source image
  4156. */
  4157. get: function () {
  4158. return this._sourceTop;
  4159. },
  4160. set: function (value) {
  4161. if (this._sourceTop === value) {
  4162. return;
  4163. }
  4164. this._sourceTop = value;
  4165. this._markAsDirty();
  4166. },
  4167. enumerable: true,
  4168. configurable: true
  4169. });
  4170. Object.defineProperty(Image.prototype, "sourceWidth", {
  4171. /**
  4172. * Gets or sets the width to capture in the source image
  4173. */
  4174. get: function () {
  4175. return this._sourceWidth;
  4176. },
  4177. set: function (value) {
  4178. if (this._sourceWidth === value) {
  4179. return;
  4180. }
  4181. this._sourceWidth = value;
  4182. this._markAsDirty();
  4183. },
  4184. enumerable: true,
  4185. configurable: true
  4186. });
  4187. Object.defineProperty(Image.prototype, "sourceHeight", {
  4188. /**
  4189. * Gets or sets the height to capture in the source image
  4190. */
  4191. get: function () {
  4192. return this._sourceHeight;
  4193. },
  4194. set: function (value) {
  4195. if (this._sourceHeight === value) {
  4196. return;
  4197. }
  4198. this._sourceHeight = value;
  4199. this._markAsDirty();
  4200. },
  4201. enumerable: true,
  4202. configurable: true
  4203. });
  4204. Object.defineProperty(Image.prototype, "autoScale", {
  4205. /**
  4206. * Gets or sets a boolean indicating if the image can force its container to adapt its size
  4207. * @see http://doc.babylonjs.com/how_to/gui#image
  4208. */
  4209. get: function () {
  4210. return this._autoScale;
  4211. },
  4212. set: function (value) {
  4213. if (this._autoScale === value) {
  4214. return;
  4215. }
  4216. this._autoScale = value;
  4217. if (value && this._loaded) {
  4218. this.synchronizeSizeWithContent();
  4219. }
  4220. },
  4221. enumerable: true,
  4222. configurable: true
  4223. });
  4224. Object.defineProperty(Image.prototype, "stretch", {
  4225. /** Gets or sets the streching mode used by the image */
  4226. get: function () {
  4227. return this._stretch;
  4228. },
  4229. set: function (value) {
  4230. if (this._stretch === value) {
  4231. return;
  4232. }
  4233. this._stretch = value;
  4234. this._markAsDirty();
  4235. },
  4236. enumerable: true,
  4237. configurable: true
  4238. });
  4239. Object.defineProperty(Image.prototype, "domImage", {
  4240. get: function () {
  4241. return this._domImage;
  4242. },
  4243. /**
  4244. * Gets or sets the internal DOM image used to render the control
  4245. */
  4246. set: function (value) {
  4247. var _this = this;
  4248. this._domImage = value;
  4249. this._loaded = false;
  4250. if (this._domImage.width) {
  4251. this._onImageLoaded();
  4252. }
  4253. else {
  4254. this._domImage.onload = function () {
  4255. _this._onImageLoaded();
  4256. };
  4257. }
  4258. },
  4259. enumerable: true,
  4260. configurable: true
  4261. });
  4262. Image.prototype._onImageLoaded = function () {
  4263. this._imageWidth = this._domImage.width;
  4264. this._imageHeight = this._domImage.height;
  4265. this._loaded = true;
  4266. if (this._autoScale) {
  4267. this.synchronizeSizeWithContent();
  4268. }
  4269. this._markAsDirty();
  4270. };
  4271. Object.defineProperty(Image.prototype, "source", {
  4272. /**
  4273. * Gets or sets image source url
  4274. */
  4275. set: function (value) {
  4276. var _this = this;
  4277. if (this._source === value) {
  4278. return;
  4279. }
  4280. this._loaded = false;
  4281. this._source = value;
  4282. this._domImage = document.createElement("img");
  4283. this._domImage.onload = function () {
  4284. _this._onImageLoaded();
  4285. };
  4286. if (value) {
  4287. babylonjs_1.Tools.SetCorsBehavior(value, this._domImage);
  4288. this._domImage.src = value;
  4289. }
  4290. },
  4291. enumerable: true,
  4292. configurable: true
  4293. });
  4294. Object.defineProperty(Image.prototype, "cellWidth", {
  4295. /**
  4296. * Gets or sets the cell width to use when animation sheet is enabled
  4297. * @see http://doc.babylonjs.com/how_to/gui#image
  4298. */
  4299. get: function () {
  4300. return this._cellWidth;
  4301. },
  4302. set: function (value) {
  4303. if (this._cellWidth === value) {
  4304. return;
  4305. }
  4306. this._cellWidth = value;
  4307. this._markAsDirty();
  4308. },
  4309. enumerable: true,
  4310. configurable: true
  4311. });
  4312. Object.defineProperty(Image.prototype, "cellHeight", {
  4313. /**
  4314. * Gets or sets the cell height to use when animation sheet is enabled
  4315. * @see http://doc.babylonjs.com/how_to/gui#image
  4316. */
  4317. get: function () {
  4318. return this._cellHeight;
  4319. },
  4320. set: function (value) {
  4321. if (this._cellHeight === value) {
  4322. return;
  4323. }
  4324. this._cellHeight = value;
  4325. this._markAsDirty();
  4326. },
  4327. enumerable: true,
  4328. configurable: true
  4329. });
  4330. Object.defineProperty(Image.prototype, "cellId", {
  4331. /**
  4332. * Gets or sets the cell id to use (this will turn on the animation sheet mode)
  4333. * @see http://doc.babylonjs.com/how_to/gui#image
  4334. */
  4335. get: function () {
  4336. return this._cellId;
  4337. },
  4338. set: function (value) {
  4339. if (this._cellId === value) {
  4340. return;
  4341. }
  4342. this._cellId = value;
  4343. this._markAsDirty();
  4344. },
  4345. enumerable: true,
  4346. configurable: true
  4347. });
  4348. Image.prototype._getTypeName = function () {
  4349. return "Image";
  4350. };
  4351. /** Force the control to synchronize with its content */
  4352. Image.prototype.synchronizeSizeWithContent = function () {
  4353. if (!this._loaded) {
  4354. return;
  4355. }
  4356. this.width = this._domImage.width + "px";
  4357. this.height = this._domImage.height + "px";
  4358. };
  4359. Image.prototype._draw = function (parentMeasure, context) {
  4360. context.save();
  4361. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4362. context.shadowColor = this.shadowColor;
  4363. context.shadowBlur = this.shadowBlur;
  4364. context.shadowOffsetX = this.shadowOffsetX;
  4365. context.shadowOffsetY = this.shadowOffsetY;
  4366. }
  4367. var x, y, width, height;
  4368. if (this.cellId == -1) {
  4369. x = this._sourceLeft;
  4370. y = this._sourceTop;
  4371. width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  4372. height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  4373. }
  4374. else {
  4375. var rowCount = this._domImage.naturalWidth / this.cellWidth;
  4376. var column = (this.cellId / rowCount) >> 0;
  4377. var row = this.cellId % rowCount;
  4378. x = this.cellWidth * row;
  4379. y = this.cellHeight * column;
  4380. width = this.cellWidth;
  4381. height = this.cellHeight;
  4382. }
  4383. this._applyStates(context);
  4384. if (this._processMeasures(parentMeasure, context)) {
  4385. if (this._loaded) {
  4386. switch (this._stretch) {
  4387. case Image.STRETCH_NONE:
  4388. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4389. break;
  4390. case Image.STRETCH_FILL:
  4391. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4392. break;
  4393. case Image.STRETCH_UNIFORM:
  4394. var hRatio = this._currentMeasure.width / width;
  4395. var vRatio = this._currentMeasure.height / height;
  4396. var ratio = Math.min(hRatio, vRatio);
  4397. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  4398. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  4399. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  4400. break;
  4401. case Image.STRETCH_EXTEND:
  4402. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4403. if (this._autoScale) {
  4404. this.synchronizeSizeWithContent();
  4405. }
  4406. if (this._root && this._root.parent) { // Will update root size if root is not the top root
  4407. this._root.width = this.width;
  4408. this._root.height = this.height;
  4409. }
  4410. break;
  4411. }
  4412. }
  4413. }
  4414. context.restore();
  4415. };
  4416. // Static
  4417. /** STRETCH_NONE */
  4418. Image.STRETCH_NONE = 0;
  4419. /** STRETCH_FILL */
  4420. Image.STRETCH_FILL = 1;
  4421. /** STRETCH_UNIFORM */
  4422. Image.STRETCH_UNIFORM = 2;
  4423. /** STRETCH_EXTEND */
  4424. Image.STRETCH_EXTEND = 3;
  4425. return Image;
  4426. }(control_1.Control));
  4427. exports.Image = Image;
  4428. /***/ }),
  4429. /***/ "./src/2D/controls/index.ts":
  4430. /*!**********************************!*\
  4431. !*** ./src/2D/controls/index.ts ***!
  4432. \**********************************/
  4433. /*! no static exports found */
  4434. /***/ (function(module, exports, __webpack_require__) {
  4435. "use strict";
  4436. function __export(m) {
  4437. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  4438. }
  4439. Object.defineProperty(exports, "__esModule", { value: true });
  4440. __export(__webpack_require__(/*! ./button */ "./src/2D/controls/button.ts"));
  4441. __export(__webpack_require__(/*! ./checkbox */ "./src/2D/controls/checkbox.ts"));
  4442. __export(__webpack_require__(/*! ./colorpicker */ "./src/2D/controls/colorpicker.ts"));
  4443. __export(__webpack_require__(/*! ./container */ "./src/2D/controls/container.ts"));
  4444. __export(__webpack_require__(/*! ./control */ "./src/2D/controls/control.ts"));
  4445. __export(__webpack_require__(/*! ./ellipse */ "./src/2D/controls/ellipse.ts"));
  4446. __export(__webpack_require__(/*! ./grid */ "./src/2D/controls/grid.ts"));
  4447. __export(__webpack_require__(/*! ./image */ "./src/2D/controls/image.ts"));
  4448. __export(__webpack_require__(/*! ./inputText */ "./src/2D/controls/inputText.ts"));
  4449. __export(__webpack_require__(/*! ./inputPassword */ "./src/2D/controls/inputPassword.ts"));
  4450. __export(__webpack_require__(/*! ./line */ "./src/2D/controls/line.ts"));
  4451. __export(__webpack_require__(/*! ./multiLine */ "./src/2D/controls/multiLine.ts"));
  4452. __export(__webpack_require__(/*! ./radioButton */ "./src/2D/controls/radioButton.ts"));
  4453. __export(__webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts"));
  4454. __export(__webpack_require__(/*! ./selector */ "./src/2D/controls/selector.ts"));
  4455. __export(__webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts"));
  4456. __export(__webpack_require__(/*! ./virtualKeyboard */ "./src/2D/controls/virtualKeyboard.ts"));
  4457. __export(__webpack_require__(/*! ./slider */ "./src/2D/controls/slider.ts"));
  4458. __export(__webpack_require__(/*! ./rectangle */ "./src/2D/controls/rectangle.ts"));
  4459. __export(__webpack_require__(/*! ./displayGrid */ "./src/2D/controls/displayGrid.ts"));
  4460. __export(__webpack_require__(/*! ./statics */ "./src/2D/controls/statics.ts"));
  4461. /***/ }),
  4462. /***/ "./src/2D/controls/inputPassword.ts":
  4463. /*!******************************************!*\
  4464. !*** ./src/2D/controls/inputPassword.ts ***!
  4465. \******************************************/
  4466. /*! no static exports found */
  4467. /***/ (function(module, exports, __webpack_require__) {
  4468. "use strict";
  4469. var __extends = (this && this.__extends) || (function () {
  4470. var extendStatics = function (d, b) {
  4471. extendStatics = Object.setPrototypeOf ||
  4472. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4473. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4474. return extendStatics(d, b);
  4475. }
  4476. return function (d, b) {
  4477. extendStatics(d, b);
  4478. function __() { this.constructor = d; }
  4479. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4480. };
  4481. })();
  4482. Object.defineProperty(exports, "__esModule", { value: true });
  4483. var inputText_1 = __webpack_require__(/*! ./inputText */ "./src/2D/controls/inputText.ts");
  4484. /**
  4485. * Class used to create a password control
  4486. */
  4487. var InputPassword = /** @class */ (function (_super) {
  4488. __extends(InputPassword, _super);
  4489. function InputPassword() {
  4490. return _super !== null && _super.apply(this, arguments) || this;
  4491. }
  4492. InputPassword.prototype._beforeRenderText = function (text) {
  4493. var txt = "";
  4494. for (var i = 0; i < text.length; i++) {
  4495. txt += "\u2022";
  4496. }
  4497. return txt;
  4498. };
  4499. return InputPassword;
  4500. }(inputText_1.InputText));
  4501. exports.InputPassword = InputPassword;
  4502. /***/ }),
  4503. /***/ "./src/2D/controls/inputText.ts":
  4504. /*!**************************************!*\
  4505. !*** ./src/2D/controls/inputText.ts ***!
  4506. \**************************************/
  4507. /*! no static exports found */
  4508. /***/ (function(module, exports, __webpack_require__) {
  4509. "use strict";
  4510. var __extends = (this && this.__extends) || (function () {
  4511. var extendStatics = function (d, b) {
  4512. extendStatics = Object.setPrototypeOf ||
  4513. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4514. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4515. return extendStatics(d, b);
  4516. }
  4517. return function (d, b) {
  4518. extendStatics(d, b);
  4519. function __() { this.constructor = d; }
  4520. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4521. };
  4522. })();
  4523. Object.defineProperty(exports, "__esModule", { value: true });
  4524. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  4525. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  4526. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  4527. /**
  4528. * Class used to create input text control
  4529. */
  4530. var InputText = /** @class */ (function (_super) {
  4531. __extends(InputText, _super);
  4532. /**
  4533. * Creates a new InputText
  4534. * @param name defines the control name
  4535. * @param text defines the text of the control
  4536. */
  4537. function InputText(name, text) {
  4538. if (text === void 0) { text = ""; }
  4539. var _this = _super.call(this, name) || this;
  4540. _this.name = name;
  4541. _this._text = "";
  4542. _this._placeholderText = "";
  4543. _this._background = "#222222";
  4544. _this._focusedBackground = "#000000";
  4545. _this._placeholderColor = "gray";
  4546. _this._thickness = 1;
  4547. _this._margin = new valueAndUnit_1.ValueAndUnit(10, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL);
  4548. _this._autoStretchWidth = true;
  4549. _this._maxWidth = new valueAndUnit_1.ValueAndUnit(1, valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  4550. _this._isFocused = false;
  4551. _this._blinkIsEven = false;
  4552. _this._cursorOffset = 0;
  4553. _this._deadKey = false;
  4554. _this._addKey = true;
  4555. _this._currentKey = "";
  4556. /** Gets or sets a string representing the message displayed on mobile when the control gets the focus */
  4557. _this.promptMessage = "Please enter text:";
  4558. /** Observable raised when the text changes */
  4559. _this.onTextChangedObservable = new babylonjs_1.Observable();
  4560. /** Observable raised just before an entered character is to be added */
  4561. _this.onBeforeKeyAddObservable = new babylonjs_1.Observable();
  4562. /** Observable raised when the control gets the focus */
  4563. _this.onFocusObservable = new babylonjs_1.Observable();
  4564. /** Observable raised when the control loses the focus */
  4565. _this.onBlurObservable = new babylonjs_1.Observable();
  4566. _this.text = text;
  4567. return _this;
  4568. }
  4569. Object.defineProperty(InputText.prototype, "maxWidth", {
  4570. /** Gets or sets the maximum width allowed by the control */
  4571. get: function () {
  4572. return this._maxWidth.toString(this._host);
  4573. },
  4574. set: function (value) {
  4575. if (this._maxWidth.toString(this._host) === value) {
  4576. return;
  4577. }
  4578. if (this._maxWidth.fromString(value)) {
  4579. this._markAsDirty();
  4580. }
  4581. },
  4582. enumerable: true,
  4583. configurable: true
  4584. });
  4585. Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
  4586. /** Gets the maximum width allowed by the control in pixels */
  4587. get: function () {
  4588. return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4589. },
  4590. enumerable: true,
  4591. configurable: true
  4592. });
  4593. Object.defineProperty(InputText.prototype, "margin", {
  4594. /** Gets or sets control margin */
  4595. get: function () {
  4596. return this._margin.toString(this._host);
  4597. },
  4598. set: function (value) {
  4599. if (this._margin.toString(this._host) === value) {
  4600. return;
  4601. }
  4602. if (this._margin.fromString(value)) {
  4603. this._markAsDirty();
  4604. }
  4605. },
  4606. enumerable: true,
  4607. configurable: true
  4608. });
  4609. Object.defineProperty(InputText.prototype, "marginInPixels", {
  4610. /** Gets control margin in pixels */
  4611. get: function () {
  4612. return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
  4613. },
  4614. enumerable: true,
  4615. configurable: true
  4616. });
  4617. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  4618. /** Gets or sets a boolean indicating if the control can auto stretch its width to adapt to the text */
  4619. get: function () {
  4620. return this._autoStretchWidth;
  4621. },
  4622. set: function (value) {
  4623. if (this._autoStretchWidth === value) {
  4624. return;
  4625. }
  4626. this._autoStretchWidth = value;
  4627. this._markAsDirty();
  4628. },
  4629. enumerable: true,
  4630. configurable: true
  4631. });
  4632. Object.defineProperty(InputText.prototype, "thickness", {
  4633. /** Gets or sets border thickness */
  4634. get: function () {
  4635. return this._thickness;
  4636. },
  4637. set: function (value) {
  4638. if (this._thickness === value) {
  4639. return;
  4640. }
  4641. this._thickness = value;
  4642. this._markAsDirty();
  4643. },
  4644. enumerable: true,
  4645. configurable: true
  4646. });
  4647. Object.defineProperty(InputText.prototype, "focusedBackground", {
  4648. /** Gets or sets the background color when focused */
  4649. get: function () {
  4650. return this._focusedBackground;
  4651. },
  4652. set: function (value) {
  4653. if (this._focusedBackground === value) {
  4654. return;
  4655. }
  4656. this._focusedBackground = value;
  4657. this._markAsDirty();
  4658. },
  4659. enumerable: true,
  4660. configurable: true
  4661. });
  4662. Object.defineProperty(InputText.prototype, "background", {
  4663. /** Gets or sets the background color */
  4664. get: function () {
  4665. return this._background;
  4666. },
  4667. set: function (value) {
  4668. if (this._background === value) {
  4669. return;
  4670. }
  4671. this._background = value;
  4672. this._markAsDirty();
  4673. },
  4674. enumerable: true,
  4675. configurable: true
  4676. });
  4677. Object.defineProperty(InputText.prototype, "placeholderColor", {
  4678. /** Gets or sets the placeholder color */
  4679. get: function () {
  4680. return this._placeholderColor;
  4681. },
  4682. set: function (value) {
  4683. if (this._placeholderColor === value) {
  4684. return;
  4685. }
  4686. this._placeholderColor = value;
  4687. this._markAsDirty();
  4688. },
  4689. enumerable: true,
  4690. configurable: true
  4691. });
  4692. Object.defineProperty(InputText.prototype, "placeholderText", {
  4693. /** Gets or sets the text displayed when the control is empty */
  4694. get: function () {
  4695. return this._placeholderText;
  4696. },
  4697. set: function (value) {
  4698. if (this._placeholderText === value) {
  4699. return;
  4700. }
  4701. this._placeholderText = value;
  4702. this._markAsDirty();
  4703. },
  4704. enumerable: true,
  4705. configurable: true
  4706. });
  4707. Object.defineProperty(InputText.prototype, "deadKey", {
  4708. /** Gets or sets the dead key flag */
  4709. get: function () {
  4710. return this._deadKey;
  4711. },
  4712. set: function (flag) {
  4713. this._deadKey = flag;
  4714. },
  4715. enumerable: true,
  4716. configurable: true
  4717. });
  4718. Object.defineProperty(InputText.prototype, "addKey", {
  4719. /** Gets or sets if the current key should be added */
  4720. get: function () {
  4721. return this._addKey;
  4722. },
  4723. set: function (flag) {
  4724. this._addKey = flag;
  4725. },
  4726. enumerable: true,
  4727. configurable: true
  4728. });
  4729. Object.defineProperty(InputText.prototype, "currentKey", {
  4730. /** Gets or sets the value of the current key being entered */
  4731. get: function () {
  4732. return this._currentKey;
  4733. },
  4734. set: function (key) {
  4735. this._currentKey = key;
  4736. },
  4737. enumerable: true,
  4738. configurable: true
  4739. });
  4740. Object.defineProperty(InputText.prototype, "text", {
  4741. /** Gets or sets the text displayed in the control */
  4742. get: function () {
  4743. return this._text;
  4744. },
  4745. set: function (value) {
  4746. if (this._text === value) {
  4747. return;
  4748. }
  4749. this._text = value;
  4750. this._markAsDirty();
  4751. this.onTextChangedObservable.notifyObservers(this);
  4752. },
  4753. enumerable: true,
  4754. configurable: true
  4755. });
  4756. Object.defineProperty(InputText.prototype, "width", {
  4757. /** Gets or sets control width */
  4758. get: function () {
  4759. return this._width.toString(this._host);
  4760. },
  4761. set: function (value) {
  4762. if (this._width.toString(this._host) === value) {
  4763. return;
  4764. }
  4765. if (this._width.fromString(value)) {
  4766. this._markAsDirty();
  4767. }
  4768. this.autoStretchWidth = false;
  4769. },
  4770. enumerable: true,
  4771. configurable: true
  4772. });
  4773. /** @hidden */
  4774. InputText.prototype.onBlur = function () {
  4775. this._isFocused = false;
  4776. this._scrollLeft = null;
  4777. this._cursorOffset = 0;
  4778. clearTimeout(this._blinkTimeout);
  4779. this._markAsDirty();
  4780. this.onBlurObservable.notifyObservers(this);
  4781. };
  4782. /** @hidden */
  4783. InputText.prototype.onFocus = function () {
  4784. if (!this._isEnabled) {
  4785. return;
  4786. }
  4787. this._scrollLeft = null;
  4788. this._isFocused = true;
  4789. this._blinkIsEven = false;
  4790. this._cursorOffset = 0;
  4791. this._markAsDirty();
  4792. this.onFocusObservable.notifyObservers(this);
  4793. if (navigator.userAgent.indexOf("Mobile") !== -1) {
  4794. var value = prompt(this.promptMessage);
  4795. if (value !== null) {
  4796. this.text = value;
  4797. }
  4798. this._host.focusedControl = null;
  4799. return;
  4800. }
  4801. };
  4802. InputText.prototype._getTypeName = function () {
  4803. return "InputText";
  4804. };
  4805. /**
  4806. * Function called to get the list of controls that should not steal the focus from this control
  4807. * @returns an array of controls
  4808. */
  4809. InputText.prototype.keepsFocusWith = function () {
  4810. if (!this._connectedVirtualKeyboard) {
  4811. return null;
  4812. }
  4813. return [this._connectedVirtualKeyboard];
  4814. };
  4815. /** @hidden */
  4816. InputText.prototype.processKey = function (keyCode, key) {
  4817. // Specific cases
  4818. switch (keyCode) {
  4819. case 32: //SPACE
  4820. key = " "; //ie11 key for space is "Spacebar"
  4821. break;
  4822. case 8: // BACKSPACE
  4823. if (this._text && this._text.length > 0) {
  4824. if (this._cursorOffset === 0) {
  4825. this.text = this._text.substr(0, this._text.length - 1);
  4826. }
  4827. else {
  4828. var deletePosition = this._text.length - this._cursorOffset;
  4829. if (deletePosition > 0) {
  4830. this.text = this._text.slice(0, deletePosition - 1) + this._text.slice(deletePosition);
  4831. }
  4832. }
  4833. }
  4834. return;
  4835. case 46: // DELETE
  4836. if (this._text && this._text.length > 0) {
  4837. var deletePosition = this._text.length - this._cursorOffset;
  4838. this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
  4839. this._cursorOffset--;
  4840. }
  4841. return;
  4842. case 13: // RETURN
  4843. this._host.focusedControl = null;
  4844. return;
  4845. case 35: // END
  4846. this._cursorOffset = 0;
  4847. this._blinkIsEven = false;
  4848. this._markAsDirty();
  4849. return;
  4850. case 36: // HOME
  4851. this._cursorOffset = this._text.length;
  4852. this._blinkIsEven = false;
  4853. this._markAsDirty();
  4854. return;
  4855. case 37: // LEFT
  4856. this._cursorOffset++;
  4857. if (this._cursorOffset > this._text.length) {
  4858. this._cursorOffset = this._text.length;
  4859. }
  4860. this._blinkIsEven = false;
  4861. this._markAsDirty();
  4862. return;
  4863. case 39: // RIGHT
  4864. this._cursorOffset--;
  4865. if (this._cursorOffset < 0) {
  4866. this._cursorOffset = 0;
  4867. }
  4868. this._blinkIsEven = false;
  4869. this._markAsDirty();
  4870. return;
  4871. case 222: // Dead
  4872. this.deadKey = true;
  4873. return;
  4874. }
  4875. // Printable characters
  4876. if (key &&
  4877. ((keyCode === -1) || // Direct access
  4878. (keyCode === 32) || // Space
  4879. (keyCode > 47 && keyCode < 58) || // Numbers
  4880. (keyCode > 64 && keyCode < 91) || // Letters
  4881. (keyCode > 185 && keyCode < 193) || // Special characters
  4882. (keyCode > 218 && keyCode < 223) || // Special characters
  4883. (keyCode > 95 && keyCode < 112))) { // Numpad
  4884. this._currentKey = key;
  4885. this.onBeforeKeyAddObservable.notifyObservers(this);
  4886. key = this._currentKey;
  4887. if (this._addKey) {
  4888. if (this._cursorOffset === 0) {
  4889. this.text += key;
  4890. }
  4891. else {
  4892. var insertPosition = this._text.length - this._cursorOffset;
  4893. this.text = this._text.slice(0, insertPosition) + key + this._text.slice(insertPosition);
  4894. }
  4895. }
  4896. }
  4897. };
  4898. /** @hidden */
  4899. InputText.prototype.processKeyboard = function (evt) {
  4900. this.processKey(evt.keyCode, evt.key);
  4901. };
  4902. InputText.prototype._draw = function (parentMeasure, context) {
  4903. var _this = this;
  4904. context.save();
  4905. this._applyStates(context);
  4906. if (this._processMeasures(parentMeasure, context)) {
  4907. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4908. context.shadowColor = this.shadowColor;
  4909. context.shadowBlur = this.shadowBlur;
  4910. context.shadowOffsetX = this.shadowOffsetX;
  4911. context.shadowOffsetY = this.shadowOffsetY;
  4912. }
  4913. // Background
  4914. if (this._isFocused) {
  4915. if (this._focusedBackground) {
  4916. context.fillStyle = this._isEnabled ? this._focusedBackground : this._disabledColor;
  4917. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4918. }
  4919. }
  4920. else if (this._background) {
  4921. context.fillStyle = this._isEnabled ? this._background : this._disabledColor;
  4922. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4923. }
  4924. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4925. context.shadowBlur = 0;
  4926. context.shadowOffsetX = 0;
  4927. context.shadowOffsetY = 0;
  4928. }
  4929. if (!this._fontOffset) {
  4930. this._fontOffset = control_1.Control._GetFontOffset(context.font);
  4931. }
  4932. // Text
  4933. var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width);
  4934. if (this.color) {
  4935. context.fillStyle = this.color;
  4936. }
  4937. var text = this._beforeRenderText(this._text);
  4938. if (!this._isFocused && !this._text && this._placeholderText) {
  4939. text = this._placeholderText;
  4940. if (this._placeholderColor) {
  4941. context.fillStyle = this._placeholderColor;
  4942. }
  4943. }
  4944. this._textWidth = context.measureText(text).width;
  4945. var marginWidth = this._margin.getValueInPixel(this._host, parentMeasure.width) * 2;
  4946. if (this._autoStretchWidth) {
  4947. this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), this._textWidth + marginWidth) + "px";
  4948. }
  4949. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  4950. var availableWidth = this._width.getValueInPixel(this._host, parentMeasure.width) - marginWidth;
  4951. context.save();
  4952. context.beginPath();
  4953. context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
  4954. context.clip();
  4955. if (this._isFocused && this._textWidth > availableWidth) {
  4956. var textLeft = clipTextLeft - this._textWidth + availableWidth;
  4957. if (!this._scrollLeft) {
  4958. this._scrollLeft = textLeft;
  4959. }
  4960. }
  4961. else {
  4962. this._scrollLeft = clipTextLeft;
  4963. }
  4964. context.fillText(text, this._scrollLeft, this._currentMeasure.top + rootY);
  4965. // Cursor
  4966. if (this._isFocused) {
  4967. // Need to move cursor
  4968. if (this._clickedCoordinate) {
  4969. var rightPosition = this._scrollLeft + this._textWidth;
  4970. var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
  4971. var currentSize = 0;
  4972. this._cursorOffset = 0;
  4973. var previousDist = 0;
  4974. do {
  4975. if (this._cursorOffset) {
  4976. previousDist = Math.abs(absoluteCursorPosition - currentSize);
  4977. }
  4978. this._cursorOffset++;
  4979. currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
  4980. } while (currentSize < absoluteCursorPosition && (text.length >= this._cursorOffset));
  4981. // Find closest move
  4982. if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
  4983. this._cursorOffset--;
  4984. }
  4985. this._blinkIsEven = false;
  4986. this._clickedCoordinate = null;
  4987. }
  4988. // Render cursor
  4989. if (!this._blinkIsEven) {
  4990. var cursorOffsetText = this.text.substr(this._text.length - this._cursorOffset);
  4991. var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
  4992. var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
  4993. if (cursorLeft < clipTextLeft) {
  4994. this._scrollLeft += (clipTextLeft - cursorLeft);
  4995. cursorLeft = clipTextLeft;
  4996. this._markAsDirty();
  4997. }
  4998. else if (cursorLeft > clipTextLeft + availableWidth) {
  4999. this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
  5000. cursorLeft = clipTextLeft + availableWidth;
  5001. this._markAsDirty();
  5002. }
  5003. context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
  5004. }
  5005. clearTimeout(this._blinkTimeout);
  5006. this._blinkTimeout = setTimeout(function () {
  5007. _this._blinkIsEven = !_this._blinkIsEven;
  5008. _this._markAsDirty();
  5009. }, 500);
  5010. }
  5011. context.restore();
  5012. // Border
  5013. if (this._thickness) {
  5014. if (this.color) {
  5015. context.strokeStyle = this.color;
  5016. }
  5017. context.lineWidth = this._thickness;
  5018. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  5019. }
  5020. }
  5021. context.restore();
  5022. };
  5023. InputText.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5024. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5025. return false;
  5026. }
  5027. this._clickedCoordinate = coordinates.x;
  5028. if (this._host.focusedControl === this) {
  5029. // Move cursor
  5030. clearTimeout(this._blinkTimeout);
  5031. this._markAsDirty();
  5032. return true;
  5033. }
  5034. if (!this._isEnabled) {
  5035. return false;
  5036. }
  5037. this._host.focusedControl = this;
  5038. return true;
  5039. };
  5040. InputText.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5041. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5042. };
  5043. InputText.prototype._beforeRenderText = function (text) {
  5044. return text;
  5045. };
  5046. InputText.prototype.dispose = function () {
  5047. _super.prototype.dispose.call(this);
  5048. this.onBlurObservable.clear();
  5049. this.onFocusObservable.clear();
  5050. this.onTextChangedObservable.clear();
  5051. };
  5052. return InputText;
  5053. }(control_1.Control));
  5054. exports.InputText = InputText;
  5055. /***/ }),
  5056. /***/ "./src/2D/controls/line.ts":
  5057. /*!*********************************!*\
  5058. !*** ./src/2D/controls/line.ts ***!
  5059. \*********************************/
  5060. /*! no static exports found */
  5061. /***/ (function(module, exports, __webpack_require__) {
  5062. "use strict";
  5063. var __extends = (this && this.__extends) || (function () {
  5064. var extendStatics = function (d, b) {
  5065. extendStatics = Object.setPrototypeOf ||
  5066. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5067. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5068. return extendStatics(d, b);
  5069. }
  5070. return function (d, b) {
  5071. extendStatics(d, b);
  5072. function __() { this.constructor = d; }
  5073. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5074. };
  5075. })();
  5076. Object.defineProperty(exports, "__esModule", { value: true });
  5077. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  5078. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  5079. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  5080. /** Class used to render 2D lines */
  5081. var Line = /** @class */ (function (_super) {
  5082. __extends(Line, _super);
  5083. /**
  5084. * Creates a new Line
  5085. * @param name defines the control name
  5086. */
  5087. function Line(name) {
  5088. var _this = _super.call(this, name) || this;
  5089. _this.name = name;
  5090. _this._lineWidth = 1;
  5091. _this._x1 = new valueAndUnit_1.ValueAndUnit(0);
  5092. _this._y1 = new valueAndUnit_1.ValueAndUnit(0);
  5093. _this._x2 = new valueAndUnit_1.ValueAndUnit(0);
  5094. _this._y2 = new valueAndUnit_1.ValueAndUnit(0);
  5095. _this._dash = new Array();
  5096. _this.isHitTestVisible = false;
  5097. _this._horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5098. _this._verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  5099. return _this;
  5100. }
  5101. Object.defineProperty(Line.prototype, "dash", {
  5102. /** Gets or sets the dash pattern */
  5103. get: function () {
  5104. return this._dash;
  5105. },
  5106. set: function (value) {
  5107. if (this._dash === value) {
  5108. return;
  5109. }
  5110. this._dash = value;
  5111. this._markAsDirty();
  5112. },
  5113. enumerable: true,
  5114. configurable: true
  5115. });
  5116. Object.defineProperty(Line.prototype, "connectedControl", {
  5117. /** Gets or sets the control connected with the line end */
  5118. get: function () {
  5119. return this._connectedControl;
  5120. },
  5121. set: function (value) {
  5122. var _this = this;
  5123. if (this._connectedControl === value) {
  5124. return;
  5125. }
  5126. if (this._connectedControlDirtyObserver && this._connectedControl) {
  5127. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  5128. this._connectedControlDirtyObserver = null;
  5129. }
  5130. if (value) {
  5131. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  5132. }
  5133. this._connectedControl = value;
  5134. this._markAsDirty();
  5135. },
  5136. enumerable: true,
  5137. configurable: true
  5138. });
  5139. Object.defineProperty(Line.prototype, "x1", {
  5140. /** Gets or sets start coordinates on X axis */
  5141. get: function () {
  5142. return this._x1.toString(this._host);
  5143. },
  5144. set: function (value) {
  5145. if (this._x1.toString(this._host) === value) {
  5146. return;
  5147. }
  5148. if (this._x1.fromString(value)) {
  5149. this._markAsDirty();
  5150. }
  5151. },
  5152. enumerable: true,
  5153. configurable: true
  5154. });
  5155. Object.defineProperty(Line.prototype, "y1", {
  5156. /** Gets or sets start coordinates on Y axis */
  5157. get: function () {
  5158. return this._y1.toString(this._host);
  5159. },
  5160. set: function (value) {
  5161. if (this._y1.toString(this._host) === value) {
  5162. return;
  5163. }
  5164. if (this._y1.fromString(value)) {
  5165. this._markAsDirty();
  5166. }
  5167. },
  5168. enumerable: true,
  5169. configurable: true
  5170. });
  5171. Object.defineProperty(Line.prototype, "x2", {
  5172. /** Gets or sets end coordinates on X axis */
  5173. get: function () {
  5174. return this._x2.toString(this._host);
  5175. },
  5176. set: function (value) {
  5177. if (this._x2.toString(this._host) === value) {
  5178. return;
  5179. }
  5180. if (this._x2.fromString(value)) {
  5181. this._markAsDirty();
  5182. }
  5183. },
  5184. enumerable: true,
  5185. configurable: true
  5186. });
  5187. Object.defineProperty(Line.prototype, "y2", {
  5188. /** Gets or sets end coordinates on Y axis */
  5189. get: function () {
  5190. return this._y2.toString(this._host);
  5191. },
  5192. set: function (value) {
  5193. if (this._y2.toString(this._host) === value) {
  5194. return;
  5195. }
  5196. if (this._y2.fromString(value)) {
  5197. this._markAsDirty();
  5198. }
  5199. },
  5200. enumerable: true,
  5201. configurable: true
  5202. });
  5203. Object.defineProperty(Line.prototype, "lineWidth", {
  5204. /** Gets or sets line width */
  5205. get: function () {
  5206. return this._lineWidth;
  5207. },
  5208. set: function (value) {
  5209. if (this._lineWidth === value) {
  5210. return;
  5211. }
  5212. this._lineWidth = value;
  5213. this._markAsDirty();
  5214. },
  5215. enumerable: true,
  5216. configurable: true
  5217. });
  5218. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  5219. /** Gets or sets horizontal alignment */
  5220. set: function (value) {
  5221. return;
  5222. },
  5223. enumerable: true,
  5224. configurable: true
  5225. });
  5226. Object.defineProperty(Line.prototype, "verticalAlignment", {
  5227. /** Gets or sets vertical alignment */
  5228. set: function (value) {
  5229. return;
  5230. },
  5231. enumerable: true,
  5232. configurable: true
  5233. });
  5234. Object.defineProperty(Line.prototype, "_effectiveX2", {
  5235. get: function () {
  5236. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  5237. },
  5238. enumerable: true,
  5239. configurable: true
  5240. });
  5241. Object.defineProperty(Line.prototype, "_effectiveY2", {
  5242. get: function () {
  5243. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  5244. },
  5245. enumerable: true,
  5246. configurable: true
  5247. });
  5248. Line.prototype._getTypeName = function () {
  5249. return "Line";
  5250. };
  5251. Line.prototype._draw = function (parentMeasure, context) {
  5252. context.save();
  5253. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5254. context.shadowColor = this.shadowColor;
  5255. context.shadowBlur = this.shadowBlur;
  5256. context.shadowOffsetX = this.shadowOffsetX;
  5257. context.shadowOffsetY = this.shadowOffsetY;
  5258. }
  5259. this._applyStates(context);
  5260. if (this._processMeasures(parentMeasure, context)) {
  5261. context.strokeStyle = this.color;
  5262. context.lineWidth = this._lineWidth;
  5263. context.setLineDash(this._dash);
  5264. context.beginPath();
  5265. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  5266. context.lineTo(this._effectiveX2, this._effectiveY2);
  5267. context.stroke();
  5268. }
  5269. context.restore();
  5270. };
  5271. Line.prototype._measure = function () {
  5272. // Width / Height
  5273. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  5274. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  5275. };
  5276. Line.prototype._computeAlignment = function (parentMeasure, context) {
  5277. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  5278. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  5279. };
  5280. /**
  5281. * Move one end of the line given 3D cartesian coordinates.
  5282. * @param position Targeted world position
  5283. * @param scene Scene
  5284. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  5285. */
  5286. Line.prototype.moveToVector3 = function (position, scene, end) {
  5287. if (end === void 0) { end = false; }
  5288. if (!this._host || this._root !== this._host._rootContainer) {
  5289. babylonjs_1.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  5290. return;
  5291. }
  5292. var globalViewport = this._host._getGlobalViewport(scene);
  5293. var projectedPosition = babylonjs_1.Vector3.Project(position, babylonjs_1.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  5294. this._moveToProjectedPosition(projectedPosition, end);
  5295. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  5296. this.notRenderable = true;
  5297. return;
  5298. }
  5299. this.notRenderable = false;
  5300. };
  5301. /**
  5302. * Move one end of the line to a position in screen absolute space.
  5303. * @param projectedPosition Position in screen absolute space (X, Y)
  5304. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  5305. */
  5306. Line.prototype._moveToProjectedPosition = function (projectedPosition, end) {
  5307. if (end === void 0) { end = false; }
  5308. var x = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  5309. var y = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  5310. if (end) {
  5311. this.x2 = x;
  5312. this.y2 = y;
  5313. this._x2.ignoreAdaptiveScaling = true;
  5314. this._y2.ignoreAdaptiveScaling = true;
  5315. }
  5316. else {
  5317. this.x1 = x;
  5318. this.y1 = y;
  5319. this._x1.ignoreAdaptiveScaling = true;
  5320. this._y1.ignoreAdaptiveScaling = true;
  5321. }
  5322. };
  5323. return Line;
  5324. }(control_1.Control));
  5325. exports.Line = Line;
  5326. /***/ }),
  5327. /***/ "./src/2D/controls/multiLine.ts":
  5328. /*!**************************************!*\
  5329. !*** ./src/2D/controls/multiLine.ts ***!
  5330. \**************************************/
  5331. /*! no static exports found */
  5332. /***/ (function(module, exports, __webpack_require__) {
  5333. "use strict";
  5334. var __extends = (this && this.__extends) || (function () {
  5335. var extendStatics = function (d, b) {
  5336. extendStatics = Object.setPrototypeOf ||
  5337. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5338. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5339. return extendStatics(d, b);
  5340. }
  5341. return function (d, b) {
  5342. extendStatics(d, b);
  5343. function __() { this.constructor = d; }
  5344. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5345. };
  5346. })();
  5347. Object.defineProperty(exports, "__esModule", { value: true });
  5348. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  5349. var multiLinePoint_1 = __webpack_require__(/*! ../multiLinePoint */ "./src/2D/multiLinePoint.ts");
  5350. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  5351. /**
  5352. * Class used to create multi line control
  5353. */
  5354. var MultiLine = /** @class */ (function (_super) {
  5355. __extends(MultiLine, _super);
  5356. /**
  5357. * Creates a new MultiLine
  5358. * @param name defines the control name
  5359. */
  5360. function MultiLine(name) {
  5361. var _this = _super.call(this, name) || this;
  5362. _this.name = name;
  5363. _this._lineWidth = 1;
  5364. /** Function called when a point is updated */
  5365. _this.onPointUpdate = function () {
  5366. _this._markAsDirty();
  5367. };
  5368. _this.isHitTestVisible = false;
  5369. _this._horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5370. _this._verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  5371. _this._dash = [];
  5372. _this._points = [];
  5373. return _this;
  5374. }
  5375. Object.defineProperty(MultiLine.prototype, "dash", {
  5376. /** Gets or sets dash pattern */
  5377. get: function () {
  5378. return this._dash;
  5379. },
  5380. set: function (value) {
  5381. if (this._dash === value) {
  5382. return;
  5383. }
  5384. this._dash = value;
  5385. this._markAsDirty();
  5386. },
  5387. enumerable: true,
  5388. configurable: true
  5389. });
  5390. /**
  5391. * Gets point stored at specified index
  5392. * @param index defines the index to look for
  5393. * @returns the requested point if found
  5394. */
  5395. MultiLine.prototype.getAt = function (index) {
  5396. if (!this._points[index]) {
  5397. this._points[index] = new multiLinePoint_1.MultiLinePoint(this);
  5398. }
  5399. return this._points[index];
  5400. };
  5401. /**
  5402. * Adds new points to the point collection
  5403. * @param items defines the list of items (mesh, control or 2d coordiantes) to add
  5404. * @returns the list of created MultiLinePoint
  5405. */
  5406. MultiLine.prototype.add = function () {
  5407. var _this = this;
  5408. var items = [];
  5409. for (var _i = 0; _i < arguments.length; _i++) {
  5410. items[_i] = arguments[_i];
  5411. }
  5412. return items.map(function (item) { return _this.push(item); });
  5413. };
  5414. /**
  5415. * Adds a new point to the point collection
  5416. * @param item defines the item (mesh, control or 2d coordiantes) to add
  5417. * @returns the created MultiLinePoint
  5418. */
  5419. MultiLine.prototype.push = function (item) {
  5420. var point = this.getAt(this._points.length);
  5421. if (item == null) {
  5422. return point;
  5423. }
  5424. if (item instanceof babylonjs_1.AbstractMesh) {
  5425. point.mesh = item;
  5426. }
  5427. else if (item instanceof control_1.Control) {
  5428. point.control = item;
  5429. }
  5430. else if (item.x != null && item.y != null) {
  5431. point.x = item.x;
  5432. point.y = item.y;
  5433. }
  5434. return point;
  5435. };
  5436. /**
  5437. * Remove a specific value or point from the active point collection
  5438. * @param value defines the value or point to remove
  5439. */
  5440. MultiLine.prototype.remove = function (value) {
  5441. var index;
  5442. if (value instanceof multiLinePoint_1.MultiLinePoint) {
  5443. index = this._points.indexOf(value);
  5444. if (index === -1) {
  5445. return;
  5446. }
  5447. }
  5448. else {
  5449. index = value;
  5450. }
  5451. var point = this._points[index];
  5452. if (!point) {
  5453. return;
  5454. }
  5455. point.dispose();
  5456. this._points.splice(index, 1);
  5457. };
  5458. /**
  5459. * Resets this object to initial state (no point)
  5460. */
  5461. MultiLine.prototype.reset = function () {
  5462. while (this._points.length > 0) {
  5463. this.remove(this._points.length - 1);
  5464. }
  5465. };
  5466. /**
  5467. * Resets all links
  5468. */
  5469. MultiLine.prototype.resetLinks = function () {
  5470. this._points.forEach(function (point) {
  5471. if (point != null) {
  5472. point.resetLinks();
  5473. }
  5474. });
  5475. };
  5476. Object.defineProperty(MultiLine.prototype, "lineWidth", {
  5477. /** Gets or sets line width */
  5478. get: function () {
  5479. return this._lineWidth;
  5480. },
  5481. set: function (value) {
  5482. if (this._lineWidth === value) {
  5483. return;
  5484. }
  5485. this._lineWidth = value;
  5486. this._markAsDirty();
  5487. },
  5488. enumerable: true,
  5489. configurable: true
  5490. });
  5491. Object.defineProperty(MultiLine.prototype, "horizontalAlignment", {
  5492. set: function (value) {
  5493. return;
  5494. },
  5495. enumerable: true,
  5496. configurable: true
  5497. });
  5498. Object.defineProperty(MultiLine.prototype, "verticalAlignment", {
  5499. set: function (value) {
  5500. return;
  5501. },
  5502. enumerable: true,
  5503. configurable: true
  5504. });
  5505. MultiLine.prototype._getTypeName = function () {
  5506. return "MultiLine";
  5507. };
  5508. MultiLine.prototype._draw = function (parentMeasure, context) {
  5509. context.save();
  5510. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5511. context.shadowColor = this.shadowColor;
  5512. context.shadowBlur = this.shadowBlur;
  5513. context.shadowOffsetX = this.shadowOffsetX;
  5514. context.shadowOffsetY = this.shadowOffsetY;
  5515. }
  5516. this._applyStates(context);
  5517. if (this._processMeasures(parentMeasure, context)) {
  5518. context.strokeStyle = this.color;
  5519. context.lineWidth = this._lineWidth;
  5520. context.setLineDash(this._dash);
  5521. context.beginPath();
  5522. var first = true; //first index is not necessarily 0
  5523. this._points.forEach(function (point) {
  5524. if (!point) {
  5525. return;
  5526. }
  5527. if (first) {
  5528. context.moveTo(point._point.x, point._point.y);
  5529. first = false;
  5530. }
  5531. else {
  5532. context.lineTo(point._point.x, point._point.y);
  5533. }
  5534. });
  5535. context.stroke();
  5536. }
  5537. context.restore();
  5538. };
  5539. MultiLine.prototype._additionalProcessing = function (parentMeasure, context) {
  5540. var _this = this;
  5541. this._minX = null;
  5542. this._minY = null;
  5543. this._maxX = null;
  5544. this._maxY = null;
  5545. this._points.forEach(function (point, index) {
  5546. if (!point) {
  5547. return;
  5548. }
  5549. point.translate();
  5550. if (_this._minX == null || point._point.x < _this._minX) {
  5551. _this._minX = point._point.x;
  5552. }
  5553. if (_this._minY == null || point._point.y < _this._minY) {
  5554. _this._minY = point._point.y;
  5555. }
  5556. if (_this._maxX == null || point._point.x > _this._maxX) {
  5557. _this._maxX = point._point.x;
  5558. }
  5559. if (_this._maxY == null || point._point.y > _this._maxY) {
  5560. _this._maxY = point._point.y;
  5561. }
  5562. });
  5563. if (this._minX == null) {
  5564. this._minX = 0;
  5565. }
  5566. if (this._minY == null) {
  5567. this._minY = 0;
  5568. }
  5569. if (this._maxX == null) {
  5570. this._maxX = 0;
  5571. }
  5572. if (this._maxY == null) {
  5573. this._maxY = 0;
  5574. }
  5575. };
  5576. MultiLine.prototype._measure = function () {
  5577. if (this._minX == null || this._maxX == null || this._minY == null || this._maxY == null) {
  5578. return;
  5579. }
  5580. this._currentMeasure.width = Math.abs(this._maxX - this._minX) + this._lineWidth;
  5581. this._currentMeasure.height = Math.abs(this._maxY - this._minY) + this._lineWidth;
  5582. };
  5583. MultiLine.prototype._computeAlignment = function (parentMeasure, context) {
  5584. if (this._minX == null || this._minY == null) {
  5585. return;
  5586. }
  5587. this._currentMeasure.left = this._minX - this._lineWidth / 2;
  5588. this._currentMeasure.top = this._minY - this._lineWidth / 2;
  5589. };
  5590. MultiLine.prototype.dispose = function () {
  5591. this.reset();
  5592. _super.prototype.dispose.call(this);
  5593. };
  5594. return MultiLine;
  5595. }(control_1.Control));
  5596. exports.MultiLine = MultiLine;
  5597. /***/ }),
  5598. /***/ "./src/2D/controls/radioButton.ts":
  5599. /*!****************************************!*\
  5600. !*** ./src/2D/controls/radioButton.ts ***!
  5601. \****************************************/
  5602. /*! no static exports found */
  5603. /***/ (function(module, exports, __webpack_require__) {
  5604. "use strict";
  5605. var __extends = (this && this.__extends) || (function () {
  5606. var extendStatics = function (d, b) {
  5607. extendStatics = Object.setPrototypeOf ||
  5608. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5609. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5610. return extendStatics(d, b);
  5611. }
  5612. return function (d, b) {
  5613. extendStatics(d, b);
  5614. function __() { this.constructor = d; }
  5615. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5616. };
  5617. })();
  5618. Object.defineProperty(exports, "__esModule", { value: true });
  5619. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  5620. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  5621. var _1 = __webpack_require__(/*! . */ "./src/2D/controls/index.ts");
  5622. /**
  5623. * Class used to create radio button controls
  5624. */
  5625. var RadioButton = /** @class */ (function (_super) {
  5626. __extends(RadioButton, _super);
  5627. /**
  5628. * Creates a new RadioButton
  5629. * @param name defines the control name
  5630. */
  5631. function RadioButton(name) {
  5632. var _this = _super.call(this, name) || this;
  5633. _this.name = name;
  5634. _this._isChecked = false;
  5635. _this._background = "black";
  5636. _this._checkSizeRatio = 0.8;
  5637. _this._thickness = 1;
  5638. /** Gets or sets group name */
  5639. _this.group = "";
  5640. /** Observable raised when isChecked is changed */
  5641. _this.onIsCheckedChangedObservable = new babylonjs_1.Observable();
  5642. _this.isPointerBlocker = true;
  5643. return _this;
  5644. }
  5645. Object.defineProperty(RadioButton.prototype, "thickness", {
  5646. /** Gets or sets border thickness */
  5647. get: function () {
  5648. return this._thickness;
  5649. },
  5650. set: function (value) {
  5651. if (this._thickness === value) {
  5652. return;
  5653. }
  5654. this._thickness = value;
  5655. this._markAsDirty();
  5656. },
  5657. enumerable: true,
  5658. configurable: true
  5659. });
  5660. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  5661. /** Gets or sets a value indicating the ratio between overall size and check size */
  5662. get: function () {
  5663. return this._checkSizeRatio;
  5664. },
  5665. set: function (value) {
  5666. value = Math.max(Math.min(1, value), 0);
  5667. if (this._checkSizeRatio === value) {
  5668. return;
  5669. }
  5670. this._checkSizeRatio = value;
  5671. this._markAsDirty();
  5672. },
  5673. enumerable: true,
  5674. configurable: true
  5675. });
  5676. Object.defineProperty(RadioButton.prototype, "background", {
  5677. /** Gets or sets background color */
  5678. get: function () {
  5679. return this._background;
  5680. },
  5681. set: function (value) {
  5682. if (this._background === value) {
  5683. return;
  5684. }
  5685. this._background = value;
  5686. this._markAsDirty();
  5687. },
  5688. enumerable: true,
  5689. configurable: true
  5690. });
  5691. Object.defineProperty(RadioButton.prototype, "isChecked", {
  5692. /** Gets or sets a boolean indicating if the checkbox is checked or not */
  5693. get: function () {
  5694. return this._isChecked;
  5695. },
  5696. set: function (value) {
  5697. var _this = this;
  5698. if (this._isChecked === value) {
  5699. return;
  5700. }
  5701. this._isChecked = value;
  5702. this._markAsDirty();
  5703. this.onIsCheckedChangedObservable.notifyObservers(value);
  5704. if (this._isChecked && this._host) {
  5705. // Update all controls from same group
  5706. this._host.executeOnAllControls(function (control) {
  5707. if (control === _this) {
  5708. return;
  5709. }
  5710. if (control.group === undefined) {
  5711. return;
  5712. }
  5713. var childRadio = control;
  5714. if (childRadio.group === _this.group) {
  5715. childRadio.isChecked = false;
  5716. }
  5717. });
  5718. }
  5719. },
  5720. enumerable: true,
  5721. configurable: true
  5722. });
  5723. RadioButton.prototype._getTypeName = function () {
  5724. return "RadioButton";
  5725. };
  5726. RadioButton.prototype._draw = function (parentMeasure, context) {
  5727. context.save();
  5728. this._applyStates(context);
  5729. if (this._processMeasures(parentMeasure, context)) {
  5730. var actualWidth = this._currentMeasure.width - this._thickness;
  5731. var actualHeight = this._currentMeasure.height - this._thickness;
  5732. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5733. context.shadowColor = this.shadowColor;
  5734. context.shadowBlur = this.shadowBlur;
  5735. context.shadowOffsetX = this.shadowOffsetX;
  5736. context.shadowOffsetY = this.shadowOffsetY;
  5737. }
  5738. // Outer
  5739. control_1.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);
  5740. context.fillStyle = this._isEnabled ? this._background : this._disabledColor;
  5741. context.fill();
  5742. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5743. context.shadowBlur = 0;
  5744. context.shadowOffsetX = 0;
  5745. context.shadowOffsetY = 0;
  5746. }
  5747. context.strokeStyle = this.color;
  5748. context.lineWidth = this._thickness;
  5749. context.stroke();
  5750. // Inner
  5751. if (this._isChecked) {
  5752. context.fillStyle = this._isEnabled ? this.color : this._disabledColor;
  5753. var offsetWidth = actualWidth * this._checkSizeRatio;
  5754. var offseHeight = actualHeight * this._checkSizeRatio;
  5755. control_1.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);
  5756. context.fill();
  5757. }
  5758. }
  5759. context.restore();
  5760. };
  5761. // Events
  5762. RadioButton.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5763. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5764. return false;
  5765. }
  5766. if (!this.isChecked) {
  5767. this.isChecked = true;
  5768. }
  5769. return true;
  5770. };
  5771. /**
  5772. * Utility function to easily create a radio button with a header
  5773. * @param title defines the label to use for the header
  5774. * @param group defines the group to use for the radio button
  5775. * @param isChecked defines the initial state of the radio button
  5776. * @param onValueChanged defines the callback to call when value changes
  5777. * @returns a StackPanel containing the radio button and a textBlock
  5778. */
  5779. RadioButton.AddRadioButtonWithHeader = function (title, group, isChecked, onValueChanged) {
  5780. var panel = new _1.StackPanel();
  5781. panel.isVertical = false;
  5782. panel.height = "30px";
  5783. var radio = new RadioButton();
  5784. radio.width = "20px";
  5785. radio.height = "20px";
  5786. radio.isChecked = isChecked;
  5787. radio.color = "green";
  5788. radio.group = group;
  5789. radio.onIsCheckedChangedObservable.add(function (value) { return onValueChanged(radio, value); });
  5790. panel.addControl(radio);
  5791. var header = new _1.TextBlock();
  5792. header.text = title;
  5793. header.width = "180px";
  5794. header.paddingLeft = "5px";
  5795. header.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5796. header.color = "white";
  5797. panel.addControl(header);
  5798. return panel;
  5799. };
  5800. return RadioButton;
  5801. }(control_1.Control));
  5802. exports.RadioButton = RadioButton;
  5803. /***/ }),
  5804. /***/ "./src/2D/controls/rectangle.ts":
  5805. /*!**************************************!*\
  5806. !*** ./src/2D/controls/rectangle.ts ***!
  5807. \**************************************/
  5808. /*! no static exports found */
  5809. /***/ (function(module, exports, __webpack_require__) {
  5810. "use strict";
  5811. var __extends = (this && this.__extends) || (function () {
  5812. var extendStatics = function (d, b) {
  5813. extendStatics = Object.setPrototypeOf ||
  5814. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5815. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5816. return extendStatics(d, b);
  5817. }
  5818. return function (d, b) {
  5819. extendStatics(d, b);
  5820. function __() { this.constructor = d; }
  5821. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5822. };
  5823. })();
  5824. Object.defineProperty(exports, "__esModule", { value: true });
  5825. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  5826. /** Class used to create rectangle container */
  5827. var Rectangle = /** @class */ (function (_super) {
  5828. __extends(Rectangle, _super);
  5829. /**
  5830. * Creates a new Rectangle
  5831. * @param name defines the control name
  5832. */
  5833. function Rectangle(name) {
  5834. var _this = _super.call(this, name) || this;
  5835. _this.name = name;
  5836. _this._thickness = 1;
  5837. _this._cornerRadius = 0;
  5838. return _this;
  5839. }
  5840. Object.defineProperty(Rectangle.prototype, "thickness", {
  5841. /** Gets or sets border thickness */
  5842. get: function () {
  5843. return this._thickness;
  5844. },
  5845. set: function (value) {
  5846. if (this._thickness === value) {
  5847. return;
  5848. }
  5849. this._thickness = value;
  5850. this._markAsDirty();
  5851. },
  5852. enumerable: true,
  5853. configurable: true
  5854. });
  5855. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  5856. /** Gets or sets the corner radius angle */
  5857. get: function () {
  5858. return this._cornerRadius;
  5859. },
  5860. set: function (value) {
  5861. if (value < 0) {
  5862. value = 0;
  5863. }
  5864. if (this._cornerRadius === value) {
  5865. return;
  5866. }
  5867. this._cornerRadius = value;
  5868. this._markAsDirty();
  5869. },
  5870. enumerable: true,
  5871. configurable: true
  5872. });
  5873. Rectangle.prototype._getTypeName = function () {
  5874. return "Rectangle";
  5875. };
  5876. Rectangle.prototype._localDraw = function (context) {
  5877. context.save();
  5878. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5879. context.shadowColor = this.shadowColor;
  5880. context.shadowBlur = this.shadowBlur;
  5881. context.shadowOffsetX = this.shadowOffsetX;
  5882. context.shadowOffsetY = this.shadowOffsetY;
  5883. }
  5884. if (this._background) {
  5885. context.fillStyle = this._background;
  5886. if (this._cornerRadius) {
  5887. this._drawRoundedRect(context, this._thickness / 2);
  5888. context.fill();
  5889. }
  5890. else {
  5891. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  5892. }
  5893. }
  5894. if (this._thickness) {
  5895. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5896. context.shadowBlur = 0;
  5897. context.shadowOffsetX = 0;
  5898. context.shadowOffsetY = 0;
  5899. }
  5900. if (this.color) {
  5901. context.strokeStyle = this.color;
  5902. }
  5903. context.lineWidth = this._thickness;
  5904. if (this._cornerRadius) {
  5905. this._drawRoundedRect(context, this._thickness / 2);
  5906. context.stroke();
  5907. }
  5908. else {
  5909. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  5910. }
  5911. }
  5912. context.restore();
  5913. };
  5914. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  5915. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  5916. this._measureForChildren.width -= 2 * this._thickness;
  5917. this._measureForChildren.height -= 2 * this._thickness;
  5918. this._measureForChildren.left += this._thickness;
  5919. this._measureForChildren.top += this._thickness;
  5920. };
  5921. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  5922. if (offset === void 0) { offset = 0; }
  5923. var x = this._currentMeasure.left + offset;
  5924. var y = this._currentMeasure.top + offset;
  5925. var width = this._currentMeasure.width - offset * 2;
  5926. var height = this._currentMeasure.height - offset * 2;
  5927. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  5928. context.beginPath();
  5929. context.moveTo(x + radius, y);
  5930. context.lineTo(x + width - radius, y);
  5931. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  5932. context.lineTo(x + width, y + height - radius);
  5933. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  5934. context.lineTo(x + radius, y + height);
  5935. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  5936. context.lineTo(x, y + radius);
  5937. context.quadraticCurveTo(x, y, x + radius, y);
  5938. context.closePath();
  5939. };
  5940. Rectangle.prototype._clipForChildren = function (context) {
  5941. if (this._cornerRadius) {
  5942. this._drawRoundedRect(context, this._thickness);
  5943. context.clip();
  5944. }
  5945. };
  5946. return Rectangle;
  5947. }(container_1.Container));
  5948. exports.Rectangle = Rectangle;
  5949. /***/ }),
  5950. /***/ "./src/2D/controls/selector.ts":
  5951. /*!*************************************!*\
  5952. !*** ./src/2D/controls/selector.ts ***!
  5953. \*************************************/
  5954. /*! no static exports found */
  5955. /***/ (function(module, exports, __webpack_require__) {
  5956. "use strict";
  5957. var __extends = (this && this.__extends) || (function () {
  5958. var extendStatics = function (d, b) {
  5959. extendStatics = Object.setPrototypeOf ||
  5960. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5961. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5962. return extendStatics(d, b);
  5963. }
  5964. return function (d, b) {
  5965. extendStatics(d, b);
  5966. function __() { this.constructor = d; }
  5967. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5968. };
  5969. })();
  5970. Object.defineProperty(exports, "__esModule", { value: true });
  5971. var rectangle_1 = __webpack_require__(/*! ./rectangle */ "./src/2D/controls/rectangle.ts");
  5972. var stackPanel_1 = __webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts");
  5973. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  5974. var textBlock_1 = __webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts");
  5975. var checkbox_1 = __webpack_require__(/*! ./checkbox */ "./src/2D/controls/checkbox.ts");
  5976. var radioButton_1 = __webpack_require__(/*! ./radioButton */ "./src/2D/controls/radioButton.ts");
  5977. var slider_1 = __webpack_require__(/*! ./slider */ "./src/2D/controls/slider.ts");
  5978. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  5979. /** Class used to create a RadioGroup
  5980. * which contains groups of radio buttons
  5981. */
  5982. var SelectorGroup = /** @class */ (function () {
  5983. /**
  5984. * Creates a new SelectorGroup
  5985. * @param name of group, used as a group heading
  5986. */
  5987. function SelectorGroup(
  5988. /** name of SelectorGroup */
  5989. name) {
  5990. this.name = name;
  5991. this._groupPanel = new stackPanel_1.StackPanel();
  5992. this._selectors = new Array();
  5993. this._groupPanel.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  5994. this._groupPanel.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5995. this._groupHeader = this._addGroupHeader(name);
  5996. }
  5997. Object.defineProperty(SelectorGroup.prototype, "groupPanel", {
  5998. /** Gets the groupPanel of the SelectorGroup */
  5999. get: function () {
  6000. return this._groupPanel;
  6001. },
  6002. enumerable: true,
  6003. configurable: true
  6004. });
  6005. Object.defineProperty(SelectorGroup.prototype, "selectors", {
  6006. /** Gets the selectors array */
  6007. get: function () {
  6008. return this._selectors;
  6009. },
  6010. enumerable: true,
  6011. configurable: true
  6012. });
  6013. Object.defineProperty(SelectorGroup.prototype, "header", {
  6014. /** Gets and sets the group header */
  6015. get: function () {
  6016. return this._groupHeader.text;
  6017. },
  6018. set: function (label) {
  6019. if (this._groupHeader.text === "label") {
  6020. return;
  6021. }
  6022. this._groupHeader.text = label;
  6023. },
  6024. enumerable: true,
  6025. configurable: true
  6026. });
  6027. /** @hidden */
  6028. SelectorGroup.prototype._addGroupHeader = function (text) {
  6029. var groupHeading = new textBlock_1.TextBlock("groupHead", text);
  6030. groupHeading.width = 0.9;
  6031. groupHeading.height = "30px";
  6032. groupHeading.textWrapping = true;
  6033. groupHeading.color = "black";
  6034. groupHeading.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6035. groupHeading.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6036. groupHeading.left = "2px";
  6037. this._groupPanel.addControl(groupHeading);
  6038. return groupHeading;
  6039. };
  6040. /** @hidden*/
  6041. SelectorGroup.prototype._getSelector = function (selectorNb) {
  6042. if (selectorNb < 0 || selectorNb >= this._selectors.length) {
  6043. return;
  6044. }
  6045. return this._selectors[selectorNb];
  6046. };
  6047. /** Removes the selector at the given position
  6048. * @param selectorNb the position of the selector within the group
  6049. */
  6050. SelectorGroup.prototype.removeSelector = function (selectorNb) {
  6051. if (selectorNb < 0 || selectorNb >= this._selectors.length) {
  6052. return;
  6053. }
  6054. this._groupPanel.removeControl(this._selectors[selectorNb]);
  6055. this._selectors.splice(selectorNb, 1);
  6056. };
  6057. return SelectorGroup;
  6058. }());
  6059. exports.SelectorGroup = SelectorGroup;
  6060. /** Class used to create a CheckboxGroup
  6061. * which contains groups of checkbox buttons
  6062. */
  6063. var CheckboxGroup = /** @class */ (function (_super) {
  6064. __extends(CheckboxGroup, _super);
  6065. function CheckboxGroup() {
  6066. return _super !== null && _super.apply(this, arguments) || this;
  6067. }
  6068. /** Adds a checkbox as a control
  6069. * @param text is the label for the selector
  6070. * @param func is the function called when the Selector is checked
  6071. * @param checked is true when Selector is checked
  6072. */
  6073. CheckboxGroup.prototype.addCheckbox = function (text, func, checked) {
  6074. if (func === void 0) { func = function (s) { }; }
  6075. if (checked === void 0) { checked = false; }
  6076. var checked = checked || false;
  6077. var button = new checkbox_1.Checkbox();
  6078. button.width = "20px";
  6079. button.height = "20px";
  6080. button.color = "#364249";
  6081. button.background = "#CCCCCC";
  6082. button.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6083. button.onIsCheckedChangedObservable.add(function (state) {
  6084. func(state);
  6085. });
  6086. var _selector = control_1.Control.AddHeader(button, text, "200px", { isHorizontal: true, controlFirst: true });
  6087. _selector.height = "30px";
  6088. _selector.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6089. _selector.left = "4px";
  6090. this.groupPanel.addControl(_selector);
  6091. this.selectors.push(_selector);
  6092. button.isChecked = checked;
  6093. if (this.groupPanel.parent && this.groupPanel.parent.parent) {
  6094. button.color = this.groupPanel.parent.parent.buttonColor;
  6095. button.background = this.groupPanel.parent.parent.buttonBackground;
  6096. }
  6097. };
  6098. /** @hidden */
  6099. CheckboxGroup.prototype._setSelectorLabel = function (selectorNb, label) {
  6100. this.selectors[selectorNb].children[1].text = label;
  6101. };
  6102. /** @hidden */
  6103. CheckboxGroup.prototype._setSelectorLabelColor = function (selectorNb, color) {
  6104. this.selectors[selectorNb].children[1].color = color;
  6105. };
  6106. /** @hidden */
  6107. CheckboxGroup.prototype._setSelectorButtonColor = function (selectorNb, color) {
  6108. this.selectors[selectorNb].children[0].color = color;
  6109. };
  6110. /** @hidden */
  6111. CheckboxGroup.prototype._setSelectorButtonBackground = function (selectorNb, color) {
  6112. this.selectors[selectorNb].children[0].background = color;
  6113. };
  6114. return CheckboxGroup;
  6115. }(SelectorGroup));
  6116. exports.CheckboxGroup = CheckboxGroup;
  6117. /** Class used to create a RadioGroup
  6118. * which contains groups of radio buttons
  6119. */
  6120. var RadioGroup = /** @class */ (function (_super) {
  6121. __extends(RadioGroup, _super);
  6122. function RadioGroup() {
  6123. var _this = _super !== null && _super.apply(this, arguments) || this;
  6124. _this._selectNb = 0;
  6125. return _this;
  6126. }
  6127. /** Adds a radio button as a control
  6128. * @param label is the label for the selector
  6129. * @param func is the function called when the Selector is checked
  6130. * @param checked is true when Selector is checked
  6131. */
  6132. RadioGroup.prototype.addRadio = function (label, func, checked) {
  6133. if (func === void 0) { func = function (n) { }; }
  6134. if (checked === void 0) { checked = false; }
  6135. var nb = this._selectNb++;
  6136. var button = new radioButton_1.RadioButton();
  6137. button.name = label;
  6138. button.width = "20px";
  6139. button.height = "20px";
  6140. button.color = "#364249";
  6141. button.background = "#CCCCCC";
  6142. button.group = this.name;
  6143. button.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6144. button.onIsCheckedChangedObservable.add(function (state) {
  6145. if (state) {
  6146. func(nb);
  6147. }
  6148. });
  6149. var _selector = control_1.Control.AddHeader(button, label, "200px", { isHorizontal: true, controlFirst: true });
  6150. _selector.height = "30px";
  6151. _selector.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6152. _selector.left = "4px";
  6153. this.groupPanel.addControl(_selector);
  6154. this.selectors.push(_selector);
  6155. button.isChecked = checked;
  6156. if (this.groupPanel.parent && this.groupPanel.parent.parent) {
  6157. button.color = this.groupPanel.parent.parent.buttonColor;
  6158. button.background = this.groupPanel.parent.parent.buttonBackground;
  6159. }
  6160. };
  6161. /** @hidden */
  6162. RadioGroup.prototype._setSelectorLabel = function (selectorNb, label) {
  6163. this.selectors[selectorNb].children[1].text = label;
  6164. };
  6165. /** @hidden */
  6166. RadioGroup.prototype._setSelectorLabelColor = function (selectorNb, color) {
  6167. this.selectors[selectorNb].children[1].color = color;
  6168. };
  6169. /** @hidden */
  6170. RadioGroup.prototype._setSelectorButtonColor = function (selectorNb, color) {
  6171. this.selectors[selectorNb].children[0].color = color;
  6172. };
  6173. /** @hidden */
  6174. RadioGroup.prototype._setSelectorButtonBackground = function (selectorNb, color) {
  6175. this.selectors[selectorNb].children[0].background = color;
  6176. };
  6177. return RadioGroup;
  6178. }(SelectorGroup));
  6179. exports.RadioGroup = RadioGroup;
  6180. /** Class used to create a SliderGroup
  6181. * which contains groups of slider buttons
  6182. */
  6183. var SliderGroup = /** @class */ (function (_super) {
  6184. __extends(SliderGroup, _super);
  6185. function SliderGroup() {
  6186. return _super !== null && _super.apply(this, arguments) || this;
  6187. }
  6188. /**
  6189. * Adds a slider to the SelectorGroup
  6190. * @param label is the label for the SliderBar
  6191. * @param func is the function called when the Slider moves
  6192. * @param unit is a string describing the units used, eg degrees or metres
  6193. * @param min is the minimum value for the Slider
  6194. * @param max is the maximum value for the Slider
  6195. * @param value is the start value for the Slider between min and max
  6196. * @param onValueChange is the function used to format the value displayed, eg radians to degrees
  6197. */
  6198. SliderGroup.prototype.addSlider = function (label, func, unit, min, max, value, onValueChange) {
  6199. if (func === void 0) { func = function (v) { }; }
  6200. if (unit === void 0) { unit = "Units"; }
  6201. if (min === void 0) { min = 0; }
  6202. if (max === void 0) { max = 0; }
  6203. if (value === void 0) { value = 0; }
  6204. if (onValueChange === void 0) { onValueChange = function (v) { return v | 0; }; }
  6205. var button = new slider_1.Slider();
  6206. button.name = unit;
  6207. button.value = value;
  6208. button.minimum = min;
  6209. button.maximum = max;
  6210. button.width = 0.9;
  6211. button.height = "20px";
  6212. button.color = "#364249";
  6213. button.background = "#CCCCCC";
  6214. button.borderColor = "black";
  6215. button.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6216. button.left = "4px";
  6217. button.paddingBottom = "4px";
  6218. button.onValueChangedObservable.add(function (value) {
  6219. button.parent.children[0].text = button.parent.children[0].name + ": " + onValueChange(value) + " " + button.name;
  6220. func(value);
  6221. });
  6222. var _selector = control_1.Control.AddHeader(button, label + ": " + onValueChange(value) + " " + unit, "30px", { isHorizontal: false, controlFirst: false });
  6223. _selector.height = "60px";
  6224. _selector.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6225. _selector.left = "4px";
  6226. _selector.children[0].name = label;
  6227. this.groupPanel.addControl(_selector);
  6228. this.selectors.push(_selector);
  6229. if (this.groupPanel.parent && this.groupPanel.parent.parent) {
  6230. button.color = this.groupPanel.parent.parent.buttonColor;
  6231. button.background = this.groupPanel.parent.parent.buttonBackground;
  6232. }
  6233. };
  6234. /** @hidden */
  6235. SliderGroup.prototype._setSelectorLabel = function (selectorNb, label) {
  6236. this.selectors[selectorNb].children[0].name = label;
  6237. this.selectors[selectorNb].children[0].text = label + ": " + this.selectors[selectorNb].children[1].value + " " + this.selectors[selectorNb].children[1].name;
  6238. };
  6239. /** @hidden */
  6240. SliderGroup.prototype._setSelectorLabelColor = function (selectorNb, color) {
  6241. this.selectors[selectorNb].children[0].color = color;
  6242. };
  6243. /** @hidden */
  6244. SliderGroup.prototype._setSelectorButtonColor = function (selectorNb, color) {
  6245. this.selectors[selectorNb].children[1].color = color;
  6246. };
  6247. /** @hidden */
  6248. SliderGroup.prototype._setSelectorButtonBackground = function (selectorNb, color) {
  6249. this.selectors[selectorNb].children[1].background = color;
  6250. };
  6251. return SliderGroup;
  6252. }(SelectorGroup));
  6253. exports.SliderGroup = SliderGroup;
  6254. /** Class used to hold the controls for the checkboxes, radio buttons and sliders
  6255. * @see http://doc.babylonjs.com/how_to/selector
  6256. */
  6257. var SelectionPanel = /** @class */ (function (_super) {
  6258. __extends(SelectionPanel, _super);
  6259. /**
  6260. * Creates a new SelectionPanel
  6261. * @param name of SelectionPanel
  6262. * @param groups is an array of SelectionGroups
  6263. */
  6264. function SelectionPanel(
  6265. /** name of SelectionPanel */
  6266. name,
  6267. /** an array of SelectionGroups */
  6268. groups) {
  6269. if (groups === void 0) { groups = []; }
  6270. var _this = _super.call(this, name) || this;
  6271. _this.name = name;
  6272. _this.groups = groups;
  6273. _this._buttonColor = "#364249";
  6274. _this._buttonBackground = "#CCCCCC";
  6275. _this._headerColor = "black";
  6276. _this._barColor = "white";
  6277. _this._barHeight = "2px";
  6278. _this._spacerHeight = "20px";
  6279. _this._bars = new Array();
  6280. _this._groups = groups;
  6281. _this.thickness = 2;
  6282. _this._panel = new stackPanel_1.StackPanel();
  6283. _this._panel.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  6284. _this._panel.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6285. _this._panel.top = 5;
  6286. _this._panel.left = 5;
  6287. _this._panel.width = 0.95;
  6288. if (groups.length > 0) {
  6289. for (var i = 0; i < groups.length - 1; i++) {
  6290. _this._panel.addControl(groups[i].groupPanel);
  6291. _this._addSpacer();
  6292. }
  6293. _this._panel.addControl(groups[groups.length - 1].groupPanel);
  6294. }
  6295. _this.addControl(_this._panel);
  6296. return _this;
  6297. }
  6298. SelectionPanel.prototype._getTypeName = function () {
  6299. return "SelectionPanel";
  6300. };
  6301. Object.defineProperty(SelectionPanel.prototype, "headerColor", {
  6302. /** Gets or sets the headerColor */
  6303. get: function () {
  6304. return this._headerColor;
  6305. },
  6306. set: function (color) {
  6307. if (this._headerColor === color) {
  6308. return;
  6309. }
  6310. this._headerColor = color;
  6311. this._setHeaderColor();
  6312. },
  6313. enumerable: true,
  6314. configurable: true
  6315. });
  6316. SelectionPanel.prototype._setHeaderColor = function () {
  6317. for (var i = 0; i < this._groups.length; i++) {
  6318. this._groups[i].groupPanel.children[0].color = this._headerColor;
  6319. }
  6320. };
  6321. Object.defineProperty(SelectionPanel.prototype, "buttonColor", {
  6322. /** Gets or sets the button color */
  6323. get: function () {
  6324. return this._buttonColor;
  6325. },
  6326. set: function (color) {
  6327. if (this._buttonColor === color) {
  6328. return;
  6329. }
  6330. this._buttonColor = color;
  6331. this._setbuttonColor();
  6332. },
  6333. enumerable: true,
  6334. configurable: true
  6335. });
  6336. SelectionPanel.prototype._setbuttonColor = function () {
  6337. for (var i = 0; i < this._groups.length; i++) {
  6338. for (var j = 0; j < this._groups[i].selectors.length; j++) {
  6339. this._groups[i]._setSelectorButtonColor(j, this._buttonColor);
  6340. }
  6341. }
  6342. };
  6343. Object.defineProperty(SelectionPanel.prototype, "labelColor", {
  6344. /** Gets or sets the label color */
  6345. get: function () {
  6346. return this._labelColor;
  6347. },
  6348. set: function (color) {
  6349. if (this._labelColor === color) {
  6350. return;
  6351. }
  6352. this._labelColor = color;
  6353. this._setLabelColor();
  6354. },
  6355. enumerable: true,
  6356. configurable: true
  6357. });
  6358. SelectionPanel.prototype._setLabelColor = function () {
  6359. for (var i = 0; i < this._groups.length; i++) {
  6360. for (var j = 0; j < this._groups[i].selectors.length; j++) {
  6361. this._groups[i]._setSelectorLabelColor(j, this._labelColor);
  6362. }
  6363. }
  6364. };
  6365. Object.defineProperty(SelectionPanel.prototype, "buttonBackground", {
  6366. /** Gets or sets the button background */
  6367. get: function () {
  6368. return this._buttonBackground;
  6369. },
  6370. set: function (color) {
  6371. if (this._buttonBackground === color) {
  6372. return;
  6373. }
  6374. this._buttonBackground = color;
  6375. this._setButtonBackground();
  6376. },
  6377. enumerable: true,
  6378. configurable: true
  6379. });
  6380. SelectionPanel.prototype._setButtonBackground = function () {
  6381. for (var i = 0; i < this._groups.length; i++) {
  6382. for (var j = 0; j < this._groups[i].selectors.length; j++) {
  6383. this._groups[i]._setSelectorButtonBackground(j, this._buttonBackground);
  6384. }
  6385. }
  6386. };
  6387. Object.defineProperty(SelectionPanel.prototype, "barColor", {
  6388. /** Gets or sets the color of separator bar */
  6389. get: function () {
  6390. return this._barColor;
  6391. },
  6392. set: function (color) {
  6393. if (this._barColor === color) {
  6394. return;
  6395. }
  6396. this._barColor = color;
  6397. this._setBarColor();
  6398. },
  6399. enumerable: true,
  6400. configurable: true
  6401. });
  6402. SelectionPanel.prototype._setBarColor = function () {
  6403. for (var i = 0; i < this._bars.length; i++) {
  6404. this._bars[i].children[0].background = this._barColor;
  6405. }
  6406. };
  6407. Object.defineProperty(SelectionPanel.prototype, "barHeight", {
  6408. /** Gets or sets the height of separator bar */
  6409. get: function () {
  6410. return this._barHeight;
  6411. },
  6412. set: function (value) {
  6413. if (this._barHeight === value) {
  6414. return;
  6415. }
  6416. this._barHeight = value;
  6417. this._setBarHeight();
  6418. },
  6419. enumerable: true,
  6420. configurable: true
  6421. });
  6422. SelectionPanel.prototype._setBarHeight = function () {
  6423. for (var i = 0; i < this._bars.length; i++) {
  6424. this._bars[i].children[0].height = this._barHeight;
  6425. }
  6426. };
  6427. Object.defineProperty(SelectionPanel.prototype, "spacerHeight", {
  6428. /** Gets or sets the height of spacers*/
  6429. get: function () {
  6430. return this._spacerHeight;
  6431. },
  6432. set: function (value) {
  6433. if (this._spacerHeight === value) {
  6434. return;
  6435. }
  6436. this._spacerHeight = value;
  6437. this._setSpacerHeight();
  6438. },
  6439. enumerable: true,
  6440. configurable: true
  6441. });
  6442. SelectionPanel.prototype._setSpacerHeight = function () {
  6443. for (var i = 0; i < this._bars.length; i++) {
  6444. this._bars[i].height = this._spacerHeight;
  6445. }
  6446. };
  6447. /** Adds a bar between groups */
  6448. SelectionPanel.prototype._addSpacer = function () {
  6449. var separator = new container_1.Container();
  6450. separator.width = 1;
  6451. separator.height = this._spacerHeight;
  6452. separator.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6453. var bar = new rectangle_1.Rectangle();
  6454. bar.width = 1;
  6455. bar.height = this._barHeight;
  6456. bar.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6457. bar.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_CENTER;
  6458. bar.background = this._barColor;
  6459. bar.color = "transparent";
  6460. separator.addControl(bar);
  6461. this._panel.addControl(separator);
  6462. this._bars.push(separator);
  6463. };
  6464. /** Add a group to the selection panel
  6465. * @param group is the selector group to add
  6466. */
  6467. SelectionPanel.prototype.addGroup = function (group) {
  6468. if (this._groups.length > 0) {
  6469. this._addSpacer();
  6470. }
  6471. this._panel.addControl(group.groupPanel);
  6472. this._groups.push(group);
  6473. group.groupPanel.children[0].color = this._headerColor;
  6474. for (var j = 0; j < group.selectors.length; j++) {
  6475. group._setSelectorButtonColor(j, this._buttonColor);
  6476. group._setSelectorButtonBackground(j, this._buttonBackground);
  6477. }
  6478. };
  6479. /** Remove the group from the given position
  6480. * @param groupNb is the position of the group in the list
  6481. */
  6482. SelectionPanel.prototype.removeGroup = function (groupNb) {
  6483. if (groupNb < 0 || groupNb >= this._groups.length) {
  6484. return;
  6485. }
  6486. var group = this._groups[groupNb];
  6487. this._panel.removeControl(group.groupPanel);
  6488. this._groups.splice(groupNb, 1);
  6489. if (groupNb < this._bars.length) {
  6490. this._panel.removeControl(this._bars[groupNb]);
  6491. this._bars.splice(groupNb, 1);
  6492. }
  6493. };
  6494. /** Change a group header label
  6495. * @param label is the new group header label
  6496. * @param groupNb is the number of the group to relabel
  6497. * */
  6498. SelectionPanel.prototype.setHeaderName = function (label, groupNb) {
  6499. if (groupNb < 0 || groupNb >= this._groups.length) {
  6500. return;
  6501. }
  6502. var group = this._groups[groupNb];
  6503. group.groupPanel.children[0].text = label;
  6504. };
  6505. /** Change selector label to the one given
  6506. * @param label is the new selector label
  6507. * @param groupNb is the number of the groupcontaining the selector
  6508. * @param selectorNb is the number of the selector within a group to relabel
  6509. * */
  6510. SelectionPanel.prototype.relabel = function (label, groupNb, selectorNb) {
  6511. if (groupNb < 0 || groupNb >= this._groups.length) {
  6512. return;
  6513. }
  6514. var group = this._groups[groupNb];
  6515. if (selectorNb < 0 || selectorNb >= group.selectors.length) {
  6516. return;
  6517. }
  6518. group._setSelectorLabel(selectorNb, label);
  6519. };
  6520. /** For a given group position remove the selector at the given position
  6521. * @param groupNb is the number of the group to remove the selector from
  6522. * @param selectorNb is the number of the selector within the group
  6523. */
  6524. SelectionPanel.prototype.removeFromGroupSelector = function (groupNb, selectorNb) {
  6525. if (groupNb < 0 || groupNb >= this._groups.length) {
  6526. return;
  6527. }
  6528. var group = this._groups[groupNb];
  6529. if (selectorNb < 0 || selectorNb >= group.selectors.length) {
  6530. return;
  6531. }
  6532. group.removeSelector(selectorNb);
  6533. };
  6534. /** For a given group position of correct type add a checkbox button
  6535. * @param groupNb is the number of the group to remove the selector from
  6536. * @param label is the label for the selector
  6537. * @param func is the function called when the Selector is checked
  6538. * @param checked is true when Selector is checked
  6539. */
  6540. SelectionPanel.prototype.addToGroupCheckbox = function (groupNb, label, func, checked) {
  6541. if (func === void 0) { func = function () { }; }
  6542. if (checked === void 0) { checked = false; }
  6543. if (groupNb < 0 || groupNb >= this._groups.length) {
  6544. return;
  6545. }
  6546. var group = this._groups[groupNb];
  6547. group.addCheckbox(label, func, checked);
  6548. };
  6549. /** For a given group position of correct type add a radio button
  6550. * @param groupNb is the number of the group to remove the selector from
  6551. * @param label is the label for the selector
  6552. * @param func is the function called when the Selector is checked
  6553. * @param checked is true when Selector is checked
  6554. */
  6555. SelectionPanel.prototype.addToGroupRadio = function (groupNb, label, func, checked) {
  6556. if (func === void 0) { func = function () { }; }
  6557. if (checked === void 0) { checked = false; }
  6558. if (groupNb < 0 || groupNb >= this._groups.length) {
  6559. return;
  6560. }
  6561. var group = this._groups[groupNb];
  6562. group.addRadio(label, func, checked);
  6563. };
  6564. /**
  6565. * For a given slider group add a slider
  6566. * @param groupNb is the number of the group to add the slider to
  6567. * @param label is the label for the Slider
  6568. * @param func is the function called when the Slider moves
  6569. * @param unit is a string describing the units used, eg degrees or metres
  6570. * @param min is the minimum value for the Slider
  6571. * @param max is the maximum value for the Slider
  6572. * @param value is the start value for the Slider between min and max
  6573. * @param onVal is the function used to format the value displayed, eg radians to degrees
  6574. */
  6575. SelectionPanel.prototype.addToGroupSlider = function (groupNb, label, func, unit, min, max, value, onVal) {
  6576. if (func === void 0) { func = function () { }; }
  6577. if (unit === void 0) { unit = "Units"; }
  6578. if (min === void 0) { min = 0; }
  6579. if (max === void 0) { max = 0; }
  6580. if (value === void 0) { value = 0; }
  6581. if (onVal === void 0) { onVal = function (v) { return v | 0; }; }
  6582. if (groupNb < 0 || groupNb >= this._groups.length) {
  6583. return;
  6584. }
  6585. var group = this._groups[groupNb];
  6586. group.addSlider(label, func, unit, min, max, value, onVal);
  6587. };
  6588. return SelectionPanel;
  6589. }(rectangle_1.Rectangle));
  6590. exports.SelectionPanel = SelectionPanel;
  6591. /***/ }),
  6592. /***/ "./src/2D/controls/slider.ts":
  6593. /*!***********************************!*\
  6594. !*** ./src/2D/controls/slider.ts ***!
  6595. \***********************************/
  6596. /*! no static exports found */
  6597. /***/ (function(module, exports, __webpack_require__) {
  6598. "use strict";
  6599. var __extends = (this && this.__extends) || (function () {
  6600. var extendStatics = function (d, b) {
  6601. extendStatics = Object.setPrototypeOf ||
  6602. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6603. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6604. return extendStatics(d, b);
  6605. }
  6606. return function (d, b) {
  6607. extendStatics(d, b);
  6608. function __() { this.constructor = d; }
  6609. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6610. };
  6611. })();
  6612. Object.defineProperty(exports, "__esModule", { value: true });
  6613. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  6614. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  6615. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  6616. /**
  6617. * Class used to create slider controls
  6618. */
  6619. var Slider = /** @class */ (function (_super) {
  6620. __extends(Slider, _super);
  6621. /**
  6622. * Creates a new Slider
  6623. * @param name defines the control name
  6624. */
  6625. function Slider(name) {
  6626. var _this = _super.call(this, name) || this;
  6627. _this.name = name;
  6628. _this._thumbWidth = new valueAndUnit_1.ValueAndUnit(20, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL, false);
  6629. _this._minimum = 0;
  6630. _this._maximum = 100;
  6631. _this._value = 50;
  6632. _this._isVertical = false;
  6633. _this._background = "black";
  6634. _this._borderColor = "white";
  6635. _this._barOffset = new valueAndUnit_1.ValueAndUnit(5, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL, false);
  6636. _this._isThumbCircle = false;
  6637. _this._isThumbClamped = false;
  6638. /** Observable raised when the sldier value changes */
  6639. _this.onValueChangedObservable = new babylonjs_1.Observable();
  6640. // Events
  6641. _this._pointerIsDown = false;
  6642. _this.isPointerBlocker = true;
  6643. return _this;
  6644. }
  6645. Object.defineProperty(Slider.prototype, "borderColor", {
  6646. /** Gets or sets border color */
  6647. get: function () {
  6648. return this._borderColor;
  6649. },
  6650. set: function (value) {
  6651. if (this._borderColor === value) {
  6652. return;
  6653. }
  6654. this._borderColor = value;
  6655. this._markAsDirty();
  6656. },
  6657. enumerable: true,
  6658. configurable: true
  6659. });
  6660. Object.defineProperty(Slider.prototype, "background", {
  6661. /** Gets or sets background color */
  6662. get: function () {
  6663. return this._background;
  6664. },
  6665. set: function (value) {
  6666. if (this._background === value) {
  6667. return;
  6668. }
  6669. this._background = value;
  6670. this._markAsDirty();
  6671. },
  6672. enumerable: true,
  6673. configurable: true
  6674. });
  6675. Object.defineProperty(Slider.prototype, "barOffset", {
  6676. /** Gets or sets main bar offset */
  6677. get: function () {
  6678. return this._barOffset.toString(this._host);
  6679. },
  6680. set: function (value) {
  6681. if (this._barOffset.toString(this._host) === value) {
  6682. return;
  6683. }
  6684. if (this._barOffset.fromString(value)) {
  6685. this._markAsDirty();
  6686. }
  6687. },
  6688. enumerable: true,
  6689. configurable: true
  6690. });
  6691. Object.defineProperty(Slider.prototype, "barOffsetInPixels", {
  6692. /** Gets main bar offset in pixels*/
  6693. get: function () {
  6694. return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
  6695. },
  6696. enumerable: true,
  6697. configurable: true
  6698. });
  6699. Object.defineProperty(Slider.prototype, "thumbWidth", {
  6700. /** Gets or sets thumb width */
  6701. get: function () {
  6702. return this._thumbWidth.toString(this._host);
  6703. },
  6704. set: function (value) {
  6705. if (this._thumbWidth.toString(this._host) === value) {
  6706. return;
  6707. }
  6708. if (this._thumbWidth.fromString(value)) {
  6709. this._markAsDirty();
  6710. }
  6711. },
  6712. enumerable: true,
  6713. configurable: true
  6714. });
  6715. Object.defineProperty(Slider.prototype, "thumbWidthInPixels", {
  6716. /** Gets thumb width in pixels */
  6717. get: function () {
  6718. return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  6719. },
  6720. enumerable: true,
  6721. configurable: true
  6722. });
  6723. Object.defineProperty(Slider.prototype, "minimum", {
  6724. /** Gets or sets minimum value */
  6725. get: function () {
  6726. return this._minimum;
  6727. },
  6728. set: function (value) {
  6729. if (this._minimum === value) {
  6730. return;
  6731. }
  6732. this._minimum = value;
  6733. this._markAsDirty();
  6734. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  6735. },
  6736. enumerable: true,
  6737. configurable: true
  6738. });
  6739. Object.defineProperty(Slider.prototype, "maximum", {
  6740. /** Gets or sets maximum value */
  6741. get: function () {
  6742. return this._maximum;
  6743. },
  6744. set: function (value) {
  6745. if (this._maximum === value) {
  6746. return;
  6747. }
  6748. this._maximum = value;
  6749. this._markAsDirty();
  6750. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  6751. },
  6752. enumerable: true,
  6753. configurable: true
  6754. });
  6755. Object.defineProperty(Slider.prototype, "value", {
  6756. /** Gets or sets current value */
  6757. get: function () {
  6758. return this._value;
  6759. },
  6760. set: function (value) {
  6761. value = Math.max(Math.min(value, this._maximum), this._minimum);
  6762. if (this._value === value) {
  6763. return;
  6764. }
  6765. this._value = value;
  6766. this._markAsDirty();
  6767. this.onValueChangedObservable.notifyObservers(this._value);
  6768. },
  6769. enumerable: true,
  6770. configurable: true
  6771. });
  6772. Object.defineProperty(Slider.prototype, "isVertical", {
  6773. /**Gets or sets a boolean indicating if the slider should be vertical or horizontal */
  6774. get: function () {
  6775. return this._isVertical;
  6776. },
  6777. set: function (value) {
  6778. if (this._isVertical === value) {
  6779. return;
  6780. }
  6781. this._isVertical = value;
  6782. this._markAsDirty();
  6783. },
  6784. enumerable: true,
  6785. configurable: true
  6786. });
  6787. Object.defineProperty(Slider.prototype, "isThumbCircle", {
  6788. /** Gets or sets a boolean indicating if the thumb should be round or square */
  6789. get: function () {
  6790. return this._isThumbCircle;
  6791. },
  6792. set: function (value) {
  6793. if (this._isThumbCircle === value) {
  6794. return;
  6795. }
  6796. this._isThumbCircle = value;
  6797. this._markAsDirty();
  6798. },
  6799. enumerable: true,
  6800. configurable: true
  6801. });
  6802. Object.defineProperty(Slider.prototype, "isThumbClamped", {
  6803. /** Gets or sets a value indicating if the thumb can go over main bar extends */
  6804. get: function () {
  6805. return this._isThumbClamped;
  6806. },
  6807. set: function (value) {
  6808. if (this._isThumbClamped === value) {
  6809. return;
  6810. }
  6811. this._isThumbClamped = value;
  6812. this._markAsDirty();
  6813. },
  6814. enumerable: true,
  6815. configurable: true
  6816. });
  6817. Slider.prototype._getTypeName = function () {
  6818. return "Slider";
  6819. };
  6820. Slider.prototype._getThumbThickness = function (type, backgroundLength) {
  6821. var thumbThickness = 0;
  6822. switch (type) {
  6823. case "circle":
  6824. if (this._thumbWidth.isPixel) {
  6825. thumbThickness = Math.max(this._thumbWidth.getValue(this._host), backgroundLength);
  6826. }
  6827. else {
  6828. thumbThickness = backgroundLength * this._thumbWidth.getValue(this._host);
  6829. }
  6830. break;
  6831. case "rectangle":
  6832. if (this._thumbWidth.isPixel) {
  6833. thumbThickness = Math.min(this._thumbWidth.getValue(this._host), backgroundLength);
  6834. }
  6835. else {
  6836. thumbThickness = backgroundLength * this._thumbWidth.getValue(this._host);
  6837. }
  6838. }
  6839. return thumbThickness;
  6840. };
  6841. Slider.prototype._draw = function (parentMeasure, context) {
  6842. context.save();
  6843. this._applyStates(context);
  6844. if (this._processMeasures(parentMeasure, context)) {
  6845. // Main bar
  6846. var effectiveBarOffset = 0;
  6847. var type = this.isThumbCircle ? "circle" : "rectangle";
  6848. var left = this._currentMeasure.left;
  6849. var top = this._currentMeasure.top;
  6850. var width = this._currentMeasure.width;
  6851. var height = this._currentMeasure.height;
  6852. var backgroundBoxLength = Math.max(this._currentMeasure.width, this._currentMeasure.height);
  6853. var backgroundBoxThickness = Math.min(this._currentMeasure.width, this._currentMeasure.height);
  6854. var effectiveThumbThickness = this._getThumbThickness(type, backgroundBoxThickness);
  6855. backgroundBoxLength -= effectiveThumbThickness;
  6856. var radius = 0;
  6857. //throw error when height is less than width for vertical slider
  6858. if ((this._isVertical && this._currentMeasure.height < this._currentMeasure.width)) {
  6859. console.error("Height should be greater than width");
  6860. return;
  6861. }
  6862. if (this._barOffset.isPixel) {
  6863. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), backgroundBoxThickness);
  6864. }
  6865. else {
  6866. effectiveBarOffset = backgroundBoxThickness * this._barOffset.getValue(this._host);
  6867. }
  6868. backgroundBoxThickness -= (effectiveBarOffset * 2);
  6869. if (this._isVertical) {
  6870. left += effectiveBarOffset;
  6871. if (!this.isThumbClamped) {
  6872. top += (effectiveThumbThickness / 2);
  6873. }
  6874. height = backgroundBoxLength;
  6875. width = backgroundBoxThickness;
  6876. }
  6877. else {
  6878. top += effectiveBarOffset;
  6879. if (!this.isThumbClamped) {
  6880. left += (effectiveThumbThickness / 2);
  6881. }
  6882. height = backgroundBoxThickness;
  6883. width = backgroundBoxLength;
  6884. }
  6885. if (this.isThumbClamped && this.isThumbCircle) {
  6886. if (this._isVertical) {
  6887. top += (effectiveThumbThickness / 2);
  6888. }
  6889. else {
  6890. left += (effectiveThumbThickness / 2);
  6891. }
  6892. radius = backgroundBoxThickness / 2;
  6893. }
  6894. else {
  6895. radius = (effectiveThumbThickness - effectiveBarOffset) / 2;
  6896. }
  6897. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6898. context.shadowColor = this.shadowColor;
  6899. context.shadowBlur = this.shadowBlur;
  6900. context.shadowOffsetX = this.shadowOffsetX;
  6901. context.shadowOffsetY = this.shadowOffsetY;
  6902. }
  6903. var thumbPosition = (this._isVertical) ? ((this._maximum - this._value) / (this._maximum - this._minimum)) * backgroundBoxLength : ((this._value - this._minimum) / (this._maximum - this._minimum)) * backgroundBoxLength;
  6904. context.fillStyle = this._background;
  6905. if (this._isVertical) {
  6906. if (this.isThumbClamped) {
  6907. if (this.isThumbCircle) {
  6908. context.beginPath();
  6909. context.arc(left + backgroundBoxThickness / 2, top, radius, Math.PI, 2 * Math.PI);
  6910. context.fill();
  6911. context.fillRect(left, top, width, height);
  6912. }
  6913. else {
  6914. context.fillRect(left, top, width, height + effectiveThumbThickness);
  6915. }
  6916. }
  6917. else {
  6918. context.fillRect(left, top, width, height);
  6919. }
  6920. }
  6921. else {
  6922. if (this.isThumbClamped) {
  6923. if (this.isThumbCircle) {
  6924. context.beginPath();
  6925. context.arc(left + backgroundBoxLength, top + (backgroundBoxThickness / 2), radius, 0, 2 * Math.PI);
  6926. context.fill();
  6927. context.fillRect(left, top, width, height);
  6928. }
  6929. else {
  6930. context.fillRect(left, top, width + effectiveThumbThickness, height);
  6931. }
  6932. }
  6933. else {
  6934. context.fillRect(left, top, width, height);
  6935. }
  6936. }
  6937. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6938. context.shadowBlur = 0;
  6939. context.shadowOffsetX = 0;
  6940. context.shadowOffsetY = 0;
  6941. }
  6942. context.fillStyle = this.color;
  6943. if (this._isVertical) {
  6944. if (this.isThumbClamped) {
  6945. if (this.isThumbCircle) {
  6946. context.beginPath();
  6947. context.arc(left + backgroundBoxThickness / 2, top + backgroundBoxLength, radius, 0, 2 * Math.PI);
  6948. context.fill();
  6949. context.fillRect(left, top + thumbPosition, width, height - thumbPosition);
  6950. }
  6951. else {
  6952. context.fillRect(left, top + thumbPosition, width, this._currentMeasure.height - thumbPosition);
  6953. }
  6954. }
  6955. else {
  6956. context.fillRect(left, top + thumbPosition, width, height - thumbPosition);
  6957. }
  6958. }
  6959. else {
  6960. if (this.isThumbClamped) {
  6961. if (this.isThumbCircle) {
  6962. context.beginPath();
  6963. context.arc(left, top + backgroundBoxThickness / 2, radius, 0, 2 * Math.PI);
  6964. context.fill();
  6965. context.fillRect(left, top, thumbPosition, height);
  6966. }
  6967. else {
  6968. context.fillRect(left, top, thumbPosition, height);
  6969. }
  6970. }
  6971. else {
  6972. context.fillRect(left, top, thumbPosition, height);
  6973. }
  6974. }
  6975. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6976. context.shadowColor = this.shadowColor;
  6977. context.shadowBlur = this.shadowBlur;
  6978. context.shadowOffsetX = this.shadowOffsetX;
  6979. context.shadowOffsetY = this.shadowOffsetY;
  6980. }
  6981. if (this._isThumbCircle) {
  6982. context.beginPath();
  6983. if (this._isVertical) {
  6984. context.arc(left + backgroundBoxThickness / 2, top + thumbPosition, radius, 0, 2 * Math.PI);
  6985. }
  6986. else {
  6987. context.arc(left + thumbPosition, top + (backgroundBoxThickness / 2), radius, 0, 2 * Math.PI);
  6988. }
  6989. context.fill();
  6990. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6991. context.shadowBlur = 0;
  6992. context.shadowOffsetX = 0;
  6993. context.shadowOffsetY = 0;
  6994. }
  6995. context.strokeStyle = this._borderColor;
  6996. context.stroke();
  6997. }
  6998. else {
  6999. if (this._isVertical) {
  7000. context.fillRect(left - effectiveBarOffset, this._currentMeasure.top + thumbPosition, this._currentMeasure.width, effectiveThumbThickness);
  7001. }
  7002. else {
  7003. context.fillRect(this._currentMeasure.left + thumbPosition, this._currentMeasure.top, effectiveThumbThickness, this._currentMeasure.height);
  7004. }
  7005. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  7006. context.shadowBlur = 0;
  7007. context.shadowOffsetX = 0;
  7008. context.shadowOffsetY = 0;
  7009. }
  7010. context.strokeStyle = this._borderColor;
  7011. if (this._isVertical) {
  7012. context.strokeRect(left - effectiveBarOffset, this._currentMeasure.top + thumbPosition, this._currentMeasure.width, effectiveThumbThickness);
  7013. }
  7014. else {
  7015. context.strokeRect(this._currentMeasure.left + thumbPosition, this._currentMeasure.top, effectiveThumbThickness, this._currentMeasure.height);
  7016. }
  7017. }
  7018. }
  7019. context.restore();
  7020. };
  7021. Slider.prototype._updateValueFromPointer = function (x, y) {
  7022. if (this.rotation != 0) {
  7023. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  7024. x = this._transformedPosition.x;
  7025. y = this._transformedPosition.y;
  7026. }
  7027. if (this._isVertical) {
  7028. this.value = this._minimum + (1 - ((y - this._currentMeasure.top) / this._currentMeasure.height)) * (this._maximum - this._minimum);
  7029. }
  7030. else {
  7031. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  7032. }
  7033. };
  7034. Slider.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  7035. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  7036. return false;
  7037. }
  7038. this._pointerIsDown = true;
  7039. this._updateValueFromPointer(coordinates.x, coordinates.y);
  7040. this._host._capturingControl[pointerId] = this;
  7041. return true;
  7042. };
  7043. Slider.prototype._onPointerMove = function (target, coordinates) {
  7044. if (this._pointerIsDown) {
  7045. this._updateValueFromPointer(coordinates.x, coordinates.y);
  7046. }
  7047. _super.prototype._onPointerMove.call(this, target, coordinates);
  7048. };
  7049. Slider.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  7050. this._pointerIsDown = false;
  7051. delete this._host._capturingControl[pointerId];
  7052. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  7053. };
  7054. return Slider;
  7055. }(control_1.Control));
  7056. exports.Slider = Slider;
  7057. /***/ }),
  7058. /***/ "./src/2D/controls/stackPanel.ts":
  7059. /*!***************************************!*\
  7060. !*** ./src/2D/controls/stackPanel.ts ***!
  7061. \***************************************/
  7062. /*! no static exports found */
  7063. /***/ (function(module, exports, __webpack_require__) {
  7064. "use strict";
  7065. var __extends = (this && this.__extends) || (function () {
  7066. var extendStatics = function (d, b) {
  7067. extendStatics = Object.setPrototypeOf ||
  7068. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  7069. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7070. return extendStatics(d, b);
  7071. }
  7072. return function (d, b) {
  7073. extendStatics(d, b);
  7074. function __() { this.constructor = d; }
  7075. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7076. };
  7077. })();
  7078. Object.defineProperty(exports, "__esModule", { value: true });
  7079. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  7080. var measure_1 = __webpack_require__(/*! ../measure */ "./src/2D/measure.ts");
  7081. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  7082. /**
  7083. * Class used to create a 2D stack panel container
  7084. */
  7085. var StackPanel = /** @class */ (function (_super) {
  7086. __extends(StackPanel, _super);
  7087. /**
  7088. * Creates a new StackPanel
  7089. * @param name defines control name
  7090. */
  7091. function StackPanel(name) {
  7092. var _this = _super.call(this, name) || this;
  7093. _this.name = name;
  7094. _this._isVertical = true;
  7095. _this._manualWidth = false;
  7096. _this._manualHeight = false;
  7097. _this._doNotTrackManualChanges = false;
  7098. _this._tempMeasureStore = measure_1.Measure.Empty();
  7099. return _this;
  7100. }
  7101. Object.defineProperty(StackPanel.prototype, "isVertical", {
  7102. /** Gets or sets a boolean indicating if the stack panel is vertical or horizontal*/
  7103. get: function () {
  7104. return this._isVertical;
  7105. },
  7106. set: function (value) {
  7107. if (this._isVertical === value) {
  7108. return;
  7109. }
  7110. this._isVertical = value;
  7111. this._markAsDirty();
  7112. },
  7113. enumerable: true,
  7114. configurable: true
  7115. });
  7116. Object.defineProperty(StackPanel.prototype, "width", {
  7117. get: function () {
  7118. return this._width.toString(this._host);
  7119. },
  7120. /**
  7121. * Gets or sets panel width.
  7122. * This value should not be set when in horizontal mode as it will be computed automatically
  7123. */
  7124. set: function (value) {
  7125. if (!this._doNotTrackManualChanges) {
  7126. this._manualWidth = true;
  7127. }
  7128. if (this._width.toString(this._host) === value) {
  7129. return;
  7130. }
  7131. if (this._width.fromString(value)) {
  7132. this._markAsDirty();
  7133. }
  7134. },
  7135. enumerable: true,
  7136. configurable: true
  7137. });
  7138. Object.defineProperty(StackPanel.prototype, "height", {
  7139. get: function () {
  7140. return this._height.toString(this._host);
  7141. },
  7142. /**
  7143. * Gets or sets panel height.
  7144. * This value should not be set when in vertical mode as it will be computed automatically
  7145. */
  7146. set: function (value) {
  7147. if (!this._doNotTrackManualChanges) {
  7148. this._manualHeight = true;
  7149. }
  7150. if (this._height.toString(this._host) === value) {
  7151. return;
  7152. }
  7153. if (this._height.fromString(value)) {
  7154. this._markAsDirty();
  7155. }
  7156. },
  7157. enumerable: true,
  7158. configurable: true
  7159. });
  7160. StackPanel.prototype._getTypeName = function () {
  7161. return "StackPanel";
  7162. };
  7163. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  7164. var stackWidth = 0;
  7165. var stackHeight = 0;
  7166. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  7167. var child = _a[_i];
  7168. this._tempMeasureStore.copyFrom(child._currentMeasure);
  7169. child._currentMeasure.copyFrom(parentMeasure);
  7170. child._measure();
  7171. if (this._isVertical) {
  7172. child.top = stackHeight + "px";
  7173. if (!child._top.ignoreAdaptiveScaling) {
  7174. child._markAsDirty();
  7175. }
  7176. child._top.ignoreAdaptiveScaling = true;
  7177. stackHeight += child._currentMeasure.height;
  7178. if (child._currentMeasure.width > stackWidth) {
  7179. stackWidth = child._currentMeasure.width;
  7180. }
  7181. child.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  7182. }
  7183. else {
  7184. child.left = stackWidth + "px";
  7185. if (!child._left.ignoreAdaptiveScaling) {
  7186. child._markAsDirty();
  7187. }
  7188. child._left.ignoreAdaptiveScaling = true;
  7189. stackWidth += child._currentMeasure.width;
  7190. if (child._currentMeasure.height > stackHeight) {
  7191. stackHeight = child._currentMeasure.height;
  7192. }
  7193. child.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  7194. }
  7195. child._currentMeasure.copyFrom(this._tempMeasureStore);
  7196. }
  7197. this._doNotTrackManualChanges = true;
  7198. // Let stack panel width and height default to stackHeight and stackWidth if dimensions are not specified.
  7199. // User can now define their own height and width for stack panel.
  7200. var panelWidthChanged = false;
  7201. var panelHeightChanged = false;
  7202. var previousHeight = this.height;
  7203. var previousWidth = this.width;
  7204. if (!this._manualHeight) {
  7205. // do not specify height if strictly defined by user
  7206. this.height = stackHeight + "px";
  7207. }
  7208. if (!this._manualWidth) {
  7209. // do not specify width if strictly defined by user
  7210. this.width = stackWidth + "px";
  7211. }
  7212. panelWidthChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  7213. panelHeightChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  7214. if (panelHeightChanged) {
  7215. this._height.ignoreAdaptiveScaling = true;
  7216. }
  7217. if (panelWidthChanged) {
  7218. this._width.ignoreAdaptiveScaling = true;
  7219. }
  7220. this._doNotTrackManualChanges = false;
  7221. if (panelWidthChanged || panelHeightChanged) {
  7222. this._markAllAsDirty();
  7223. }
  7224. _super.prototype._preMeasure.call(this, parentMeasure, context);
  7225. };
  7226. return StackPanel;
  7227. }(container_1.Container));
  7228. exports.StackPanel = StackPanel;
  7229. /***/ }),
  7230. /***/ "./src/2D/controls/statics.ts":
  7231. /*!************************************!*\
  7232. !*** ./src/2D/controls/statics.ts ***!
  7233. \************************************/
  7234. /*! no static exports found */
  7235. /***/ (function(module, exports, __webpack_require__) {
  7236. "use strict";
  7237. Object.defineProperty(exports, "__esModule", { value: true });
  7238. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  7239. var stackPanel_1 = __webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts");
  7240. var textBlock_1 = __webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts");
  7241. /**
  7242. * Forcing an export so that this code will execute
  7243. * @hidden
  7244. */
  7245. var name = "Statics";
  7246. exports.name = name;
  7247. /**
  7248. * Creates a stack panel that can be used to render headers
  7249. * @param control defines the control to associate with the header
  7250. * @param text defines the text of the header
  7251. * @param size defines the size of the header
  7252. * @param options defines options used to configure the header
  7253. * @returns a new StackPanel
  7254. */
  7255. control_1.Control.AddHeader = function (control, text, size, options) {
  7256. var panel = new stackPanel_1.StackPanel("panel");
  7257. var isHorizontal = options ? options.isHorizontal : true;
  7258. var controlFirst = options ? options.controlFirst : true;
  7259. panel.isVertical = !isHorizontal;
  7260. var header = new textBlock_1.TextBlock("header");
  7261. header.text = text;
  7262. header.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  7263. if (isHorizontal) {
  7264. header.width = size;
  7265. }
  7266. else {
  7267. header.height = size;
  7268. }
  7269. if (controlFirst) {
  7270. panel.addControl(control);
  7271. panel.addControl(header);
  7272. header.paddingLeft = "5px";
  7273. }
  7274. else {
  7275. panel.addControl(header);
  7276. panel.addControl(control);
  7277. header.paddingRight = "5px";
  7278. }
  7279. header.shadowBlur = control.shadowBlur;
  7280. header.shadowColor = control.shadowColor;
  7281. header.shadowOffsetX = control.shadowOffsetX;
  7282. header.shadowOffsetY = control.shadowOffsetY;
  7283. return panel;
  7284. };
  7285. /***/ }),
  7286. /***/ "./src/2D/controls/textBlock.ts":
  7287. /*!**************************************!*\
  7288. !*** ./src/2D/controls/textBlock.ts ***!
  7289. \**************************************/
  7290. /*! no static exports found */
  7291. /***/ (function(module, exports, __webpack_require__) {
  7292. "use strict";
  7293. var __extends = (this && this.__extends) || (function () {
  7294. var extendStatics = function (d, b) {
  7295. extendStatics = Object.setPrototypeOf ||
  7296. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  7297. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7298. return extendStatics(d, b);
  7299. }
  7300. return function (d, b) {
  7301. extendStatics(d, b);
  7302. function __() { this.constructor = d; }
  7303. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7304. };
  7305. })();
  7306. Object.defineProperty(exports, "__esModule", { value: true });
  7307. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  7308. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  7309. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  7310. /**
  7311. * Enum that determines the text-wrapping mode to use.
  7312. */
  7313. var TextWrapping;
  7314. (function (TextWrapping) {
  7315. /**
  7316. * Clip the text when it's larger than Control.width; this is the default mode.
  7317. */
  7318. TextWrapping[TextWrapping["Clip"] = 0] = "Clip";
  7319. /**
  7320. * Wrap the text word-wise, i.e. try to add line-breaks at word boundary to fit within Control.width.
  7321. */
  7322. TextWrapping[TextWrapping["WordWrap"] = 1] = "WordWrap";
  7323. /**
  7324. * Ellipsize the text, i.e. shrink with trailing … when text is larger than Control.width.
  7325. */
  7326. TextWrapping[TextWrapping["Ellipsis"] = 2] = "Ellipsis";
  7327. })(TextWrapping = exports.TextWrapping || (exports.TextWrapping = {}));
  7328. /**
  7329. * Class used to create text block control
  7330. */
  7331. var TextBlock = /** @class */ (function (_super) {
  7332. __extends(TextBlock, _super);
  7333. /**
  7334. * Creates a new TextBlock object
  7335. * @param name defines the name of the control
  7336. * @param text defines the text to display (emptry string by default)
  7337. */
  7338. function TextBlock(
  7339. /**
  7340. * Defines the name of the control
  7341. */
  7342. name, text) {
  7343. if (text === void 0) { text = ""; }
  7344. var _this = _super.call(this, name) || this;
  7345. _this.name = name;
  7346. _this._text = "";
  7347. _this._textWrapping = TextWrapping.Clip;
  7348. _this._textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_CENTER;
  7349. _this._textVerticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_CENTER;
  7350. _this._resizeToFit = false;
  7351. _this._lineSpacing = new valueAndUnit_1.ValueAndUnit(0);
  7352. _this._outlineWidth = 0;
  7353. _this._outlineColor = "white";
  7354. /**
  7355. * An event triggered after the text is changed
  7356. */
  7357. _this.onTextChangedObservable = new babylonjs_1.Observable();
  7358. /**
  7359. * An event triggered after the text was broken up into lines
  7360. */
  7361. _this.onLinesReadyObservable = new babylonjs_1.Observable();
  7362. _this.text = text;
  7363. return _this;
  7364. }
  7365. Object.defineProperty(TextBlock.prototype, "lines", {
  7366. /**
  7367. * Return the line list (you may need to use the onLinesReadyObservable to make sure the list is ready)
  7368. */
  7369. get: function () {
  7370. return this._lines;
  7371. },
  7372. enumerable: true,
  7373. configurable: true
  7374. });
  7375. Object.defineProperty(TextBlock.prototype, "resizeToFit", {
  7376. /**
  7377. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  7378. */
  7379. get: function () {
  7380. return this._resizeToFit;
  7381. },
  7382. /**
  7383. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  7384. */
  7385. set: function (value) {
  7386. this._resizeToFit = value;
  7387. if (this._resizeToFit) {
  7388. this._width.ignoreAdaptiveScaling = true;
  7389. this._height.ignoreAdaptiveScaling = true;
  7390. }
  7391. },
  7392. enumerable: true,
  7393. configurable: true
  7394. });
  7395. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  7396. /**
  7397. * Gets or sets a boolean indicating if text must be wrapped
  7398. */
  7399. get: function () {
  7400. return this._textWrapping;
  7401. },
  7402. /**
  7403. * Gets or sets a boolean indicating if text must be wrapped
  7404. */
  7405. set: function (value) {
  7406. if (this._textWrapping === value) {
  7407. return;
  7408. }
  7409. this._textWrapping = +value;
  7410. this._markAsDirty();
  7411. },
  7412. enumerable: true,
  7413. configurable: true
  7414. });
  7415. Object.defineProperty(TextBlock.prototype, "text", {
  7416. /**
  7417. * Gets or sets text to display
  7418. */
  7419. get: function () {
  7420. return this._text;
  7421. },
  7422. /**
  7423. * Gets or sets text to display
  7424. */
  7425. set: function (value) {
  7426. if (this._text === value) {
  7427. return;
  7428. }
  7429. this._text = value;
  7430. this._markAsDirty();
  7431. this.onTextChangedObservable.notifyObservers(this);
  7432. },
  7433. enumerable: true,
  7434. configurable: true
  7435. });
  7436. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  7437. /**
  7438. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  7439. */
  7440. get: function () {
  7441. return this._textHorizontalAlignment;
  7442. },
  7443. /**
  7444. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  7445. */
  7446. set: function (value) {
  7447. if (this._textHorizontalAlignment === value) {
  7448. return;
  7449. }
  7450. this._textHorizontalAlignment = value;
  7451. this._markAsDirty();
  7452. },
  7453. enumerable: true,
  7454. configurable: true
  7455. });
  7456. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  7457. /**
  7458. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  7459. */
  7460. get: function () {
  7461. return this._textVerticalAlignment;
  7462. },
  7463. /**
  7464. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  7465. */
  7466. set: function (value) {
  7467. if (this._textVerticalAlignment === value) {
  7468. return;
  7469. }
  7470. this._textVerticalAlignment = value;
  7471. this._markAsDirty();
  7472. },
  7473. enumerable: true,
  7474. configurable: true
  7475. });
  7476. Object.defineProperty(TextBlock.prototype, "lineSpacing", {
  7477. /**
  7478. * Gets or sets line spacing value
  7479. */
  7480. get: function () {
  7481. return this._lineSpacing.toString(this._host);
  7482. },
  7483. /**
  7484. * Gets or sets line spacing value
  7485. */
  7486. set: function (value) {
  7487. if (this._lineSpacing.fromString(value)) {
  7488. this._markAsDirty();
  7489. }
  7490. },
  7491. enumerable: true,
  7492. configurable: true
  7493. });
  7494. Object.defineProperty(TextBlock.prototype, "outlineWidth", {
  7495. /**
  7496. * Gets or sets outlineWidth of the text to display
  7497. */
  7498. get: function () {
  7499. return this._outlineWidth;
  7500. },
  7501. /**
  7502. * Gets or sets outlineWidth of the text to display
  7503. */
  7504. set: function (value) {
  7505. if (this._outlineWidth === value) {
  7506. return;
  7507. }
  7508. this._outlineWidth = value;
  7509. this._markAsDirty();
  7510. },
  7511. enumerable: true,
  7512. configurable: true
  7513. });
  7514. Object.defineProperty(TextBlock.prototype, "outlineColor", {
  7515. /**
  7516. * Gets or sets outlineColor of the text to display
  7517. */
  7518. get: function () {
  7519. return this._outlineColor;
  7520. },
  7521. /**
  7522. * Gets or sets outlineColor of the text to display
  7523. */
  7524. set: function (value) {
  7525. if (this._outlineColor === value) {
  7526. return;
  7527. }
  7528. this._outlineColor = value;
  7529. this._markAsDirty();
  7530. },
  7531. enumerable: true,
  7532. configurable: true
  7533. });
  7534. TextBlock.prototype._getTypeName = function () {
  7535. return "TextBlock";
  7536. };
  7537. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  7538. var width = this._currentMeasure.width;
  7539. var x = 0;
  7540. switch (this._textHorizontalAlignment) {
  7541. case control_1.Control.HORIZONTAL_ALIGNMENT_LEFT:
  7542. x = 0;
  7543. break;
  7544. case control_1.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  7545. x = width - textWidth;
  7546. break;
  7547. case control_1.Control.HORIZONTAL_ALIGNMENT_CENTER:
  7548. x = (width - textWidth) / 2;
  7549. break;
  7550. }
  7551. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  7552. context.shadowColor = this.shadowColor;
  7553. context.shadowBlur = this.shadowBlur;
  7554. context.shadowOffsetX = this.shadowOffsetX;
  7555. context.shadowOffsetY = this.shadowOffsetY;
  7556. }
  7557. if (this.outlineWidth) {
  7558. context.strokeText(text, this._currentMeasure.left + x, y);
  7559. }
  7560. context.fillText(text, this._currentMeasure.left + x, y);
  7561. };
  7562. /** @hidden */
  7563. TextBlock.prototype._draw = function (parentMeasure, context) {
  7564. context.save();
  7565. this._applyStates(context);
  7566. if (this._processMeasures(parentMeasure, context)) {
  7567. // Render lines
  7568. this._renderLines(context);
  7569. }
  7570. context.restore();
  7571. };
  7572. TextBlock.prototype._applyStates = function (context) {
  7573. _super.prototype._applyStates.call(this, context);
  7574. if (this.outlineWidth) {
  7575. context.lineWidth = this.outlineWidth;
  7576. context.strokeStyle = this.outlineColor;
  7577. }
  7578. };
  7579. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  7580. this._lines = this._breakLines(this._currentMeasure.width, context);
  7581. this.onLinesReadyObservable.notifyObservers(this);
  7582. };
  7583. TextBlock.prototype._breakLines = function (refWidth, context) {
  7584. var lines = [];
  7585. var _lines = this.text.split("\n");
  7586. if (this._textWrapping === TextWrapping.Ellipsis && !this._resizeToFit) {
  7587. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  7588. var _line = _lines_1[_i];
  7589. lines.push(this._parseLineEllipsis(_line, refWidth, context));
  7590. }
  7591. }
  7592. else if (this._textWrapping === TextWrapping.WordWrap && !this._resizeToFit) {
  7593. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  7594. var _line = _lines_2[_a];
  7595. lines.push.apply(lines, this._parseLineWordWrap(_line, refWidth, context));
  7596. }
  7597. }
  7598. else {
  7599. for (var _b = 0, _lines_3 = _lines; _b < _lines_3.length; _b++) {
  7600. var _line = _lines_3[_b];
  7601. lines.push(this._parseLine(_line, context));
  7602. }
  7603. }
  7604. return lines;
  7605. };
  7606. TextBlock.prototype._parseLine = function (line, context) {
  7607. if (line === void 0) { line = ''; }
  7608. return { text: line, width: context.measureText(line).width };
  7609. };
  7610. TextBlock.prototype._parseLineEllipsis = function (line, width, context) {
  7611. if (line === void 0) { line = ''; }
  7612. var lineWidth = context.measureText(line).width;
  7613. if (lineWidth > width) {
  7614. line += '…';
  7615. }
  7616. while (line.length > 2 && lineWidth > width) {
  7617. line = line.slice(0, -2) + '…';
  7618. lineWidth = context.measureText(line).width;
  7619. }
  7620. return { text: line, width: lineWidth };
  7621. };
  7622. TextBlock.prototype._parseLineWordWrap = function (line, width, context) {
  7623. if (line === void 0) { line = ''; }
  7624. var lines = [];
  7625. var words = line.split(' ');
  7626. var lineWidth = 0;
  7627. for (var n = 0; n < words.length; n++) {
  7628. var testLine = n > 0 ? line + " " + words[n] : words[0];
  7629. var metrics = context.measureText(testLine);
  7630. var testWidth = metrics.width;
  7631. if (testWidth > width && n > 0) {
  7632. lines.push({ text: line, width: lineWidth });
  7633. line = words[n];
  7634. lineWidth = context.measureText(line).width;
  7635. }
  7636. else {
  7637. lineWidth = testWidth;
  7638. line = testLine;
  7639. }
  7640. }
  7641. lines.push({ text: line, width: lineWidth });
  7642. return lines;
  7643. };
  7644. TextBlock.prototype._renderLines = function (context) {
  7645. var height = this._currentMeasure.height;
  7646. if (!this._fontOffset) {
  7647. this._fontOffset = control_1.Control._GetFontOffset(context.font);
  7648. }
  7649. var rootY = 0;
  7650. switch (this._textVerticalAlignment) {
  7651. case control_1.Control.VERTICAL_ALIGNMENT_TOP:
  7652. rootY = this._fontOffset.ascent;
  7653. break;
  7654. case control_1.Control.VERTICAL_ALIGNMENT_BOTTOM:
  7655. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  7656. break;
  7657. case control_1.Control.VERTICAL_ALIGNMENT_CENTER:
  7658. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  7659. break;
  7660. }
  7661. rootY += this._currentMeasure.top;
  7662. var maxLineWidth = 0;
  7663. for (var i = 0; i < this._lines.length; i++) {
  7664. var line = this._lines[i];
  7665. if (i !== 0 && this._lineSpacing.internalValue !== 0) {
  7666. if (this._lineSpacing.isPixel) {
  7667. rootY += this._lineSpacing.getValue(this._host);
  7668. }
  7669. else {
  7670. rootY = rootY + (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
  7671. }
  7672. }
  7673. this._drawText(line.text, line.width, rootY, context);
  7674. rootY += this._fontOffset.height;
  7675. if (line.width > maxLineWidth) {
  7676. maxLineWidth = line.width;
  7677. }
  7678. }
  7679. if (this._resizeToFit) {
  7680. this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
  7681. this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
  7682. }
  7683. };
  7684. /**
  7685. * Given a width constraint applied on the text block, find the expected height
  7686. * @returns expected height
  7687. */
  7688. TextBlock.prototype.computeExpectedHeight = function () {
  7689. if (this.text && this.widthInPixels) {
  7690. var context_1 = document.createElement('canvas').getContext('2d');
  7691. if (context_1) {
  7692. this._applyStates(context_1);
  7693. if (!this._fontOffset) {
  7694. this._fontOffset = control_1.Control._GetFontOffset(context_1.font);
  7695. }
  7696. var lines = this._lines ? this._lines : this._breakLines(this.widthInPixels - this.paddingLeftInPixels - this.paddingRightInPixels, context_1);
  7697. return this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * lines.length;
  7698. }
  7699. }
  7700. return 0;
  7701. };
  7702. TextBlock.prototype.dispose = function () {
  7703. _super.prototype.dispose.call(this);
  7704. this.onTextChangedObservable.clear();
  7705. };
  7706. return TextBlock;
  7707. }(control_1.Control));
  7708. exports.TextBlock = TextBlock;
  7709. /***/ }),
  7710. /***/ "./src/2D/controls/virtualKeyboard.ts":
  7711. /*!********************************************!*\
  7712. !*** ./src/2D/controls/virtualKeyboard.ts ***!
  7713. \********************************************/
  7714. /*! no static exports found */
  7715. /***/ (function(module, exports, __webpack_require__) {
  7716. "use strict";
  7717. var __extends = (this && this.__extends) || (function () {
  7718. var extendStatics = function (d, b) {
  7719. extendStatics = Object.setPrototypeOf ||
  7720. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  7721. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7722. return extendStatics(d, b);
  7723. }
  7724. return function (d, b) {
  7725. extendStatics(d, b);
  7726. function __() { this.constructor = d; }
  7727. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7728. };
  7729. })();
  7730. Object.defineProperty(exports, "__esModule", { value: true });
  7731. var stackPanel_1 = __webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts");
  7732. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  7733. var button_1 = __webpack_require__(/*! ./button */ "./src/2D/controls/button.ts");
  7734. /**
  7735. * Class used to store key control properties
  7736. */
  7737. var KeyPropertySet = /** @class */ (function () {
  7738. function KeyPropertySet() {
  7739. }
  7740. return KeyPropertySet;
  7741. }());
  7742. exports.KeyPropertySet = KeyPropertySet;
  7743. /**
  7744. * Class used to create virtual keyboard
  7745. */
  7746. var VirtualKeyboard = /** @class */ (function (_super) {
  7747. __extends(VirtualKeyboard, _super);
  7748. function VirtualKeyboard() {
  7749. var _this = _super !== null && _super.apply(this, arguments) || this;
  7750. /** Observable raised when a key is pressed */
  7751. _this.onKeyPressObservable = new babylonjs_1.Observable();
  7752. /** Gets or sets default key button width */
  7753. _this.defaultButtonWidth = "40px";
  7754. /** Gets or sets default key button height */
  7755. _this.defaultButtonHeight = "40px";
  7756. /** Gets or sets default key button left padding */
  7757. _this.defaultButtonPaddingLeft = "2px";
  7758. /** Gets or sets default key button right padding */
  7759. _this.defaultButtonPaddingRight = "2px";
  7760. /** Gets or sets default key button top padding */
  7761. _this.defaultButtonPaddingTop = "2px";
  7762. /** Gets or sets default key button bottom padding */
  7763. _this.defaultButtonPaddingBottom = "2px";
  7764. /** Gets or sets default key button foreground color */
  7765. _this.defaultButtonColor = "#DDD";
  7766. /** Gets or sets default key button background color */
  7767. _this.defaultButtonBackground = "#070707";
  7768. /** Gets or sets shift button foreground color */
  7769. _this.shiftButtonColor = "#7799FF";
  7770. /** Gets or sets shift button thickness*/
  7771. _this.selectedShiftThickness = 1;
  7772. /** Gets shift key state */
  7773. _this.shiftState = 0;
  7774. _this._currentlyConnectedInputText = null;
  7775. _this._connectedInputTexts = [];
  7776. _this._onKeyPressObserver = null;
  7777. return _this;
  7778. }
  7779. VirtualKeyboard.prototype._getTypeName = function () {
  7780. return "VirtualKeyboard";
  7781. };
  7782. VirtualKeyboard.prototype._createKey = function (key, propertySet) {
  7783. var _this = this;
  7784. var button = button_1.Button.CreateSimpleButton(key, key);
  7785. button.width = propertySet && propertySet.width ? propertySet.width : this.defaultButtonWidth;
  7786. button.height = propertySet && propertySet.height ? propertySet.height : this.defaultButtonHeight;
  7787. button.color = propertySet && propertySet.color ? propertySet.color : this.defaultButtonColor;
  7788. button.background = propertySet && propertySet.background ? propertySet.background : this.defaultButtonBackground;
  7789. button.paddingLeft = propertySet && propertySet.paddingLeft ? propertySet.paddingLeft : this.defaultButtonPaddingLeft;
  7790. button.paddingRight = propertySet && propertySet.paddingRight ? propertySet.paddingRight : this.defaultButtonPaddingRight;
  7791. button.paddingTop = propertySet && propertySet.paddingTop ? propertySet.paddingTop : this.defaultButtonPaddingTop;
  7792. button.paddingBottom = propertySet && propertySet.paddingBottom ? propertySet.paddingBottom : this.defaultButtonPaddingBottom;
  7793. button.thickness = 0;
  7794. button.isFocusInvisible = true;
  7795. button.shadowColor = this.shadowColor;
  7796. button.shadowBlur = this.shadowBlur;
  7797. button.shadowOffsetX = this.shadowOffsetX;
  7798. button.shadowOffsetY = this.shadowOffsetY;
  7799. button.onPointerUpObservable.add(function () {
  7800. _this.onKeyPressObservable.notifyObservers(key);
  7801. });
  7802. return button;
  7803. };
  7804. /**
  7805. * Adds a new row of keys
  7806. * @param keys defines the list of keys to add
  7807. * @param propertySets defines the associated property sets
  7808. */
  7809. VirtualKeyboard.prototype.addKeysRow = function (keys, propertySets) {
  7810. var panel = new stackPanel_1.StackPanel();
  7811. panel.isVertical = false;
  7812. panel.isFocusInvisible = true;
  7813. for (var i = 0; i < keys.length; i++) {
  7814. var properties = null;
  7815. if (propertySets && propertySets.length === keys.length) {
  7816. properties = propertySets[i];
  7817. }
  7818. panel.addControl(this._createKey(keys[i], properties));
  7819. }
  7820. this.addControl(panel);
  7821. };
  7822. /**
  7823. * Set the shift key to a specific state
  7824. * @param shiftState defines the new shift state
  7825. */
  7826. VirtualKeyboard.prototype.applyShiftState = function (shiftState) {
  7827. if (!this.children) {
  7828. return;
  7829. }
  7830. for (var i = 0; i < this.children.length; i++) {
  7831. var row = this.children[i];
  7832. if (!row || !row.children) {
  7833. continue;
  7834. }
  7835. var rowContainer = row;
  7836. for (var j = 0; j < rowContainer.children.length; j++) {
  7837. var button = rowContainer.children[j];
  7838. if (!button || !button.children[0]) {
  7839. continue;
  7840. }
  7841. var button_tblock = button.children[0];
  7842. if (button_tblock.text === "\u21E7") {
  7843. button.color = (shiftState ? this.shiftButtonColor : this.defaultButtonColor);
  7844. button.thickness = (shiftState > 1 ? this.selectedShiftThickness : 0);
  7845. }
  7846. button_tblock.text = (shiftState > 0 ? button_tblock.text.toUpperCase() : button_tblock.text.toLowerCase());
  7847. }
  7848. }
  7849. };
  7850. Object.defineProperty(VirtualKeyboard.prototype, "connectedInputText", {
  7851. /** Gets the input text control currently attached to the keyboard */
  7852. get: function () {
  7853. return this._currentlyConnectedInputText;
  7854. },
  7855. enumerable: true,
  7856. configurable: true
  7857. });
  7858. /**
  7859. * Connects the keyboard with an input text control
  7860. *
  7861. * @param input defines the target control
  7862. */
  7863. VirtualKeyboard.prototype.connect = function (input) {
  7864. var _this = this;
  7865. var inputTextAlreadyConnected = this._connectedInputTexts.some(function (a) { return a.input === input; });
  7866. if (inputTextAlreadyConnected) {
  7867. return;
  7868. }
  7869. if (this._onKeyPressObserver === null) {
  7870. this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
  7871. if (!_this._currentlyConnectedInputText) {
  7872. return;
  7873. }
  7874. _this._currentlyConnectedInputText._host.focusedControl = _this._currentlyConnectedInputText;
  7875. switch (key) {
  7876. case "\u21E7":
  7877. _this.shiftState++;
  7878. if (_this.shiftState > 2) {
  7879. _this.shiftState = 0;
  7880. }
  7881. _this.applyShiftState(_this.shiftState);
  7882. return;
  7883. case "\u2190":
  7884. _this._currentlyConnectedInputText.processKey(8);
  7885. return;
  7886. case "\u21B5":
  7887. _this._currentlyConnectedInputText.processKey(13);
  7888. return;
  7889. }
  7890. _this._currentlyConnectedInputText.processKey(-1, (_this.shiftState ? key.toUpperCase() : key));
  7891. if (_this.shiftState === 1) {
  7892. _this.shiftState = 0;
  7893. _this.applyShiftState(_this.shiftState);
  7894. }
  7895. });
  7896. }
  7897. this.isVisible = false;
  7898. this._currentlyConnectedInputText = input;
  7899. input._connectedVirtualKeyboard = this;
  7900. // Events hooking
  7901. var onFocusObserver = input.onFocusObservable.add(function () {
  7902. _this._currentlyConnectedInputText = input;
  7903. input._connectedVirtualKeyboard = _this;
  7904. _this.isVisible = true;
  7905. });
  7906. var onBlurObserver = input.onBlurObservable.add(function () {
  7907. input._connectedVirtualKeyboard = null;
  7908. _this._currentlyConnectedInputText = null;
  7909. _this.isVisible = false;
  7910. });
  7911. this._connectedInputTexts.push({
  7912. input: input,
  7913. onBlurObserver: onBlurObserver,
  7914. onFocusObserver: onFocusObserver
  7915. });
  7916. };
  7917. /**
  7918. * Disconnects the keyboard from connected InputText controls
  7919. *
  7920. * @param input optionally defines a target control, otherwise all are disconnected
  7921. */
  7922. VirtualKeyboard.prototype.disconnect = function (input) {
  7923. var _this = this;
  7924. if (input) {
  7925. // .find not available on IE
  7926. var filtered = this._connectedInputTexts.filter(function (a) { return a.input === input; });
  7927. if (filtered.length === 1) {
  7928. this._removeConnectedInputObservables(filtered[0]);
  7929. this._connectedInputTexts = this._connectedInputTexts.filter(function (a) { return a.input !== input; });
  7930. if (this._currentlyConnectedInputText === input) {
  7931. this._currentlyConnectedInputText = null;
  7932. }
  7933. }
  7934. }
  7935. else {
  7936. this._connectedInputTexts.forEach(function (connectedInputText) {
  7937. _this._removeConnectedInputObservables(connectedInputText);
  7938. });
  7939. this._connectedInputTexts = [];
  7940. }
  7941. if (this._connectedInputTexts.length === 0) {
  7942. this._currentlyConnectedInputText = null;
  7943. this.onKeyPressObservable.remove(this._onKeyPressObserver);
  7944. this._onKeyPressObserver = null;
  7945. }
  7946. };
  7947. VirtualKeyboard.prototype._removeConnectedInputObservables = function (connectedInputText) {
  7948. connectedInputText.input._connectedVirtualKeyboard = null;
  7949. connectedInputText.input.onFocusObservable.remove(connectedInputText.onFocusObserver);
  7950. connectedInputText.input.onBlurObservable.remove(connectedInputText.onBlurObserver);
  7951. };
  7952. /**
  7953. * Release all resources
  7954. */
  7955. VirtualKeyboard.prototype.dispose = function () {
  7956. _super.prototype.dispose.call(this);
  7957. this.disconnect();
  7958. };
  7959. // Statics
  7960. /**
  7961. * Creates a new keyboard using a default layout
  7962. *
  7963. * @param name defines control name
  7964. * @returns a new VirtualKeyboard
  7965. */
  7966. VirtualKeyboard.CreateDefaultLayout = function (name) {
  7967. var returnValue = new VirtualKeyboard(name);
  7968. returnValue.addKeysRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u2190"]);
  7969. returnValue.addKeysRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]);
  7970. returnValue.addKeysRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\u21B5"]);
  7971. returnValue.addKeysRow(["\u21E7", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]);
  7972. returnValue.addKeysRow([" "], [{ width: "200px" }]);
  7973. return returnValue;
  7974. };
  7975. return VirtualKeyboard;
  7976. }(stackPanel_1.StackPanel));
  7977. exports.VirtualKeyboard = VirtualKeyboard;
  7978. /***/ }),
  7979. /***/ "./src/2D/index.ts":
  7980. /*!*************************!*\
  7981. !*** ./src/2D/index.ts ***!
  7982. \*************************/
  7983. /*! no static exports found */
  7984. /***/ (function(module, exports, __webpack_require__) {
  7985. "use strict";
  7986. function __export(m) {
  7987. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  7988. }
  7989. Object.defineProperty(exports, "__esModule", { value: true });
  7990. __export(__webpack_require__(/*! ./controls */ "./src/2D/controls/index.ts"));
  7991. __export(__webpack_require__(/*! ./advancedDynamicTexture */ "./src/2D/advancedDynamicTexture.ts"));
  7992. __export(__webpack_require__(/*! ./math2D */ "./src/2D/math2D.ts"));
  7993. __export(__webpack_require__(/*! ./measure */ "./src/2D/measure.ts"));
  7994. __export(__webpack_require__(/*! ./multiLinePoint */ "./src/2D/multiLinePoint.ts"));
  7995. __export(__webpack_require__(/*! ./style */ "./src/2D/style.ts"));
  7996. __export(__webpack_require__(/*! ./valueAndUnit */ "./src/2D/valueAndUnit.ts"));
  7997. /***/ }),
  7998. /***/ "./src/2D/math2D.ts":
  7999. /*!**************************!*\
  8000. !*** ./src/2D/math2D.ts ***!
  8001. \**************************/
  8002. /*! no static exports found */
  8003. /***/ (function(module, exports, __webpack_require__) {
  8004. "use strict";
  8005. var __extends = (this && this.__extends) || (function () {
  8006. var extendStatics = function (d, b) {
  8007. extendStatics = Object.setPrototypeOf ||
  8008. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  8009. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  8010. return extendStatics(d, b);
  8011. }
  8012. return function (d, b) {
  8013. extendStatics(d, b);
  8014. function __() { this.constructor = d; }
  8015. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8016. };
  8017. })();
  8018. Object.defineProperty(exports, "__esModule", { value: true });
  8019. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8020. /**
  8021. * Class used to transport Vector2 information for pointer events
  8022. */
  8023. var Vector2WithInfo = /** @class */ (function (_super) {
  8024. __extends(Vector2WithInfo, _super);
  8025. /**
  8026. * Creates a new Vector2WithInfo
  8027. * @param source defines the vector2 data to transport
  8028. * @param buttonIndex defines the current mouse button index
  8029. */
  8030. function Vector2WithInfo(source,
  8031. /** defines the current mouse button index */
  8032. buttonIndex) {
  8033. if (buttonIndex === void 0) { buttonIndex = 0; }
  8034. var _this = _super.call(this, source.x, source.y) || this;
  8035. _this.buttonIndex = buttonIndex;
  8036. return _this;
  8037. }
  8038. return Vector2WithInfo;
  8039. }(babylonjs_1.Vector2));
  8040. exports.Vector2WithInfo = Vector2WithInfo;
  8041. /** Class used to provide 2D matrix features */
  8042. var Matrix2D = /** @class */ (function () {
  8043. /**
  8044. * Creates a new matrix
  8045. * @param m00 defines value for (0, 0)
  8046. * @param m01 defines value for (0, 1)
  8047. * @param m10 defines value for (1, 0)
  8048. * @param m11 defines value for (1, 1)
  8049. * @param m20 defines value for (2, 0)
  8050. * @param m21 defines value for (2, 1)
  8051. */
  8052. function Matrix2D(m00, m01, m10, m11, m20, m21) {
  8053. /** Gets the internal array of 6 floats used to store matrix data */
  8054. this.m = new Float32Array(6);
  8055. this.fromValues(m00, m01, m10, m11, m20, m21);
  8056. }
  8057. /**
  8058. * Fills the matrix from direct values
  8059. * @param m00 defines value for (0, 0)
  8060. * @param m01 defines value for (0, 1)
  8061. * @param m10 defines value for (1, 0)
  8062. * @param m11 defines value for (1, 1)
  8063. * @param m20 defines value for (2, 0)
  8064. * @param m21 defines value for (2, 1)
  8065. * @returns the current modified matrix
  8066. */
  8067. Matrix2D.prototype.fromValues = function (m00, m01, m10, m11, m20, m21) {
  8068. this.m[0] = m00;
  8069. this.m[1] = m01;
  8070. this.m[2] = m10;
  8071. this.m[3] = m11;
  8072. this.m[4] = m20;
  8073. this.m[5] = m21;
  8074. return this;
  8075. };
  8076. /**
  8077. * Gets matrix determinant
  8078. * @returns the determinant
  8079. */
  8080. Matrix2D.prototype.determinant = function () {
  8081. return this.m[0] * this.m[3] - this.m[1] * this.m[2];
  8082. };
  8083. /**
  8084. * Inverses the matrix and stores it in a target matrix
  8085. * @param result defines the target matrix
  8086. * @returns the current matrix
  8087. */
  8088. Matrix2D.prototype.invertToRef = function (result) {
  8089. var l0 = this.m[0];
  8090. var l1 = this.m[1];
  8091. var l2 = this.m[2];
  8092. var l3 = this.m[3];
  8093. var l4 = this.m[4];
  8094. var l5 = this.m[5];
  8095. var det = this.determinant();
  8096. if (det < (babylonjs_1.Epsilon * babylonjs_1.Epsilon)) {
  8097. result.m[0] = 0;
  8098. result.m[1] = 0;
  8099. result.m[2] = 0;
  8100. result.m[3] = 0;
  8101. result.m[4] = 0;
  8102. result.m[5] = 0;
  8103. return this;
  8104. }
  8105. var detDiv = 1 / det;
  8106. var det4 = l2 * l5 - l3 * l4;
  8107. var det5 = l1 * l4 - l0 * l5;
  8108. result.m[0] = l3 * detDiv;
  8109. result.m[1] = -l1 * detDiv;
  8110. result.m[2] = -l2 * detDiv;
  8111. result.m[3] = l0 * detDiv;
  8112. result.m[4] = det4 * detDiv;
  8113. result.m[5] = det5 * detDiv;
  8114. return this;
  8115. };
  8116. /**
  8117. * Multiplies the current matrix with another one
  8118. * @param other defines the second operand
  8119. * @param result defines the target matrix
  8120. * @returns the current matrix
  8121. */
  8122. Matrix2D.prototype.multiplyToRef = function (other, result) {
  8123. var l0 = this.m[0];
  8124. var l1 = this.m[1];
  8125. var l2 = this.m[2];
  8126. var l3 = this.m[3];
  8127. var l4 = this.m[4];
  8128. var l5 = this.m[5];
  8129. var r0 = other.m[0];
  8130. var r1 = other.m[1];
  8131. var r2 = other.m[2];
  8132. var r3 = other.m[3];
  8133. var r4 = other.m[4];
  8134. var r5 = other.m[5];
  8135. result.m[0] = l0 * r0 + l1 * r2;
  8136. result.m[1] = l0 * r1 + l1 * r3;
  8137. result.m[2] = l2 * r0 + l3 * r2;
  8138. result.m[3] = l2 * r1 + l3 * r3;
  8139. result.m[4] = l4 * r0 + l5 * r2 + r4;
  8140. result.m[5] = l4 * r1 + l5 * r3 + r5;
  8141. return this;
  8142. };
  8143. /**
  8144. * Applies the current matrix to a set of 2 floats and stores the result in a vector2
  8145. * @param x defines the x coordinate to transform
  8146. * @param y defines the x coordinate to transform
  8147. * @param result defines the target vector2
  8148. * @returns the current matrix
  8149. */
  8150. Matrix2D.prototype.transformCoordinates = function (x, y, result) {
  8151. result.x = x * this.m[0] + y * this.m[2] + this.m[4];
  8152. result.y = x * this.m[1] + y * this.m[3] + this.m[5];
  8153. return this;
  8154. };
  8155. // Statics
  8156. /**
  8157. * Creates an identity matrix
  8158. * @returns a new matrix
  8159. */
  8160. Matrix2D.Identity = function () {
  8161. return new Matrix2D(1, 0, 0, 1, 0, 0);
  8162. };
  8163. /**
  8164. * Creates a translation matrix and stores it in a target matrix
  8165. * @param x defines the x coordinate of the translation
  8166. * @param y defines the y coordinate of the translation
  8167. * @param result defines the target matrix
  8168. */
  8169. Matrix2D.TranslationToRef = function (x, y, result) {
  8170. result.fromValues(1, 0, 0, 1, x, y);
  8171. };
  8172. /**
  8173. * Creates a scaling matrix and stores it in a target matrix
  8174. * @param x defines the x coordinate of the scaling
  8175. * @param y defines the y coordinate of the scaling
  8176. * @param result defines the target matrix
  8177. */
  8178. Matrix2D.ScalingToRef = function (x, y, result) {
  8179. result.fromValues(x, 0, 0, y, 0, 0);
  8180. };
  8181. /**
  8182. * Creates a rotation matrix and stores it in a target matrix
  8183. * @param angle defines the rotation angle
  8184. * @param result defines the target matrix
  8185. */
  8186. Matrix2D.RotationToRef = function (angle, result) {
  8187. var s = Math.sin(angle);
  8188. var c = Math.cos(angle);
  8189. result.fromValues(c, s, -s, c, 0, 0);
  8190. };
  8191. /**
  8192. * Composes a matrix from translation, rotation, scaling and parent matrix and stores it in a target matrix
  8193. * @param tx defines the x coordinate of the translation
  8194. * @param ty defines the y coordinate of the translation
  8195. * @param angle defines the rotation angle
  8196. * @param scaleX defines the x coordinate of the scaling
  8197. * @param scaleY defines the y coordinate of the scaling
  8198. * @param parentMatrix defines the parent matrix to multiply by (can be null)
  8199. * @param result defines the target matrix
  8200. */
  8201. Matrix2D.ComposeToRef = function (tx, ty, angle, scaleX, scaleY, parentMatrix, result) {
  8202. Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
  8203. Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);
  8204. Matrix2D.RotationToRef(angle, Matrix2D._TempRotationMatrix);
  8205. Matrix2D.TranslationToRef(-tx, -ty, Matrix2D._TempPostTranslationMatrix);
  8206. Matrix2D._TempPreTranslationMatrix.multiplyToRef(Matrix2D._TempScalingMatrix, Matrix2D._TempCompose0);
  8207. Matrix2D._TempCompose0.multiplyToRef(Matrix2D._TempRotationMatrix, Matrix2D._TempCompose1);
  8208. if (parentMatrix) {
  8209. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, Matrix2D._TempCompose2);
  8210. Matrix2D._TempCompose2.multiplyToRef(parentMatrix, result);
  8211. }
  8212. else {
  8213. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, result);
  8214. }
  8215. };
  8216. Matrix2D._TempPreTranslationMatrix = Matrix2D.Identity();
  8217. Matrix2D._TempPostTranslationMatrix = Matrix2D.Identity();
  8218. Matrix2D._TempRotationMatrix = Matrix2D.Identity();
  8219. Matrix2D._TempScalingMatrix = Matrix2D.Identity();
  8220. Matrix2D._TempCompose0 = Matrix2D.Identity();
  8221. Matrix2D._TempCompose1 = Matrix2D.Identity();
  8222. Matrix2D._TempCompose2 = Matrix2D.Identity();
  8223. return Matrix2D;
  8224. }());
  8225. exports.Matrix2D = Matrix2D;
  8226. /***/ }),
  8227. /***/ "./src/2D/measure.ts":
  8228. /*!***************************!*\
  8229. !*** ./src/2D/measure.ts ***!
  8230. \***************************/
  8231. /*! no static exports found */
  8232. /***/ (function(module, exports, __webpack_require__) {
  8233. "use strict";
  8234. Object.defineProperty(exports, "__esModule", { value: true });
  8235. /**
  8236. * Class used to store 2D control sizes
  8237. */
  8238. var Measure = /** @class */ (function () {
  8239. /**
  8240. * Creates a new measure
  8241. * @param left defines left coordinate
  8242. * @param top defines top coordinate
  8243. * @param width defines width dimension
  8244. * @param height defines height dimension
  8245. */
  8246. function Measure(
  8247. /** defines left coordinate */
  8248. left,
  8249. /** defines top coordinate */
  8250. top,
  8251. /** defines width dimension */
  8252. width,
  8253. /** defines height dimension */
  8254. height) {
  8255. this.left = left;
  8256. this.top = top;
  8257. this.width = width;
  8258. this.height = height;
  8259. }
  8260. /**
  8261. * Copy from another measure
  8262. * @param other defines the other measure to copy from
  8263. */
  8264. Measure.prototype.copyFrom = function (other) {
  8265. this.left = other.left;
  8266. this.top = other.top;
  8267. this.width = other.width;
  8268. this.height = other.height;
  8269. };
  8270. /**
  8271. * Check equality between this measure and another one
  8272. * @param other defines the other measures
  8273. * @returns true if both measures are equals
  8274. */
  8275. Measure.prototype.isEqualsTo = function (other) {
  8276. if (this.left !== other.left) {
  8277. return false;
  8278. }
  8279. if (this.top !== other.top) {
  8280. return false;
  8281. }
  8282. if (this.width !== other.width) {
  8283. return false;
  8284. }
  8285. if (this.height !== other.height) {
  8286. return false;
  8287. }
  8288. return true;
  8289. };
  8290. /**
  8291. * Creates an empty measure
  8292. * @returns a new measure
  8293. */
  8294. Measure.Empty = function () {
  8295. return new Measure(0, 0, 0, 0);
  8296. };
  8297. return Measure;
  8298. }());
  8299. exports.Measure = Measure;
  8300. /***/ }),
  8301. /***/ "./src/2D/multiLinePoint.ts":
  8302. /*!**********************************!*\
  8303. !*** ./src/2D/multiLinePoint.ts ***!
  8304. \**********************************/
  8305. /*! no static exports found */
  8306. /***/ (function(module, exports, __webpack_require__) {
  8307. "use strict";
  8308. Object.defineProperty(exports, "__esModule", { value: true });
  8309. var valueAndUnit_1 = __webpack_require__(/*! ./valueAndUnit */ "./src/2D/valueAndUnit.ts");
  8310. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8311. /**
  8312. * Class used to store a point for a MultiLine object.
  8313. * The point can be pure 2D coordinates, a mesh or a control
  8314. */
  8315. var MultiLinePoint = /** @class */ (function () {
  8316. /**
  8317. * Creates a new MultiLinePoint
  8318. * @param multiLine defines the source MultiLine object
  8319. */
  8320. function MultiLinePoint(multiLine) {
  8321. this._multiLine = multiLine;
  8322. this._x = new valueAndUnit_1.ValueAndUnit(0);
  8323. this._y = new valueAndUnit_1.ValueAndUnit(0);
  8324. this._point = new babylonjs_1.Vector2(0, 0);
  8325. }
  8326. Object.defineProperty(MultiLinePoint.prototype, "x", {
  8327. /** Gets or sets x coordinate */
  8328. get: function () {
  8329. return this._x.toString(this._multiLine._host);
  8330. },
  8331. set: function (value) {
  8332. if (this._x.toString(this._multiLine._host) === value) {
  8333. return;
  8334. }
  8335. if (this._x.fromString(value)) {
  8336. this._multiLine._markAsDirty();
  8337. }
  8338. },
  8339. enumerable: true,
  8340. configurable: true
  8341. });
  8342. Object.defineProperty(MultiLinePoint.prototype, "y", {
  8343. /** Gets or sets y coordinate */
  8344. get: function () {
  8345. return this._y.toString(this._multiLine._host);
  8346. },
  8347. set: function (value) {
  8348. if (this._y.toString(this._multiLine._host) === value) {
  8349. return;
  8350. }
  8351. if (this._y.fromString(value)) {
  8352. this._multiLine._markAsDirty();
  8353. }
  8354. },
  8355. enumerable: true,
  8356. configurable: true
  8357. });
  8358. Object.defineProperty(MultiLinePoint.prototype, "control", {
  8359. /** Gets or sets the control associated with this point */
  8360. get: function () {
  8361. return this._control;
  8362. },
  8363. set: function (value) {
  8364. if (this._control === value) {
  8365. return;
  8366. }
  8367. if (this._control && this._controlObserver) {
  8368. this._control.onDirtyObservable.remove(this._controlObserver);
  8369. this._controlObserver = null;
  8370. }
  8371. this._control = value;
  8372. if (this._control) {
  8373. this._controlObserver = this._control.onDirtyObservable.add(this._multiLine.onPointUpdate);
  8374. }
  8375. this._multiLine._markAsDirty();
  8376. },
  8377. enumerable: true,
  8378. configurable: true
  8379. });
  8380. Object.defineProperty(MultiLinePoint.prototype, "mesh", {
  8381. /** Gets or sets the mesh associated with this point */
  8382. get: function () {
  8383. return this._mesh;
  8384. },
  8385. set: function (value) {
  8386. if (this._mesh === value) {
  8387. return;
  8388. }
  8389. if (this._mesh && this._meshObserver) {
  8390. this._mesh.getScene().onAfterCameraRenderObservable.remove(this._meshObserver);
  8391. }
  8392. this._mesh = value;
  8393. if (this._mesh) {
  8394. this._meshObserver = this._mesh.getScene().onAfterCameraRenderObservable.add(this._multiLine.onPointUpdate);
  8395. }
  8396. this._multiLine._markAsDirty();
  8397. },
  8398. enumerable: true,
  8399. configurable: true
  8400. });
  8401. /** Resets links */
  8402. MultiLinePoint.prototype.resetLinks = function () {
  8403. this.control = null;
  8404. this.mesh = null;
  8405. };
  8406. /**
  8407. * Gets a translation vector
  8408. * @returns the translation vector
  8409. */
  8410. MultiLinePoint.prototype.translate = function () {
  8411. this._point = this._translatePoint();
  8412. return this._point;
  8413. };
  8414. MultiLinePoint.prototype._translatePoint = function () {
  8415. if (this._mesh != null) {
  8416. return this._multiLine._host.getProjectedPosition(this._mesh.getBoundingInfo().boundingSphere.center, this._mesh.getWorldMatrix());
  8417. }
  8418. else if (this._control != null) {
  8419. return new babylonjs_1.Vector2(this._control.centerX, this._control.centerY);
  8420. }
  8421. else {
  8422. var host = this._multiLine._host;
  8423. var xValue = this._x.getValueInPixel(host, Number(host._canvas.width));
  8424. var yValue = this._y.getValueInPixel(host, Number(host._canvas.height));
  8425. return new babylonjs_1.Vector2(xValue, yValue);
  8426. }
  8427. };
  8428. /** Release associated resources */
  8429. MultiLinePoint.prototype.dispose = function () {
  8430. this.resetLinks();
  8431. };
  8432. return MultiLinePoint;
  8433. }());
  8434. exports.MultiLinePoint = MultiLinePoint;
  8435. /***/ }),
  8436. /***/ "./src/2D/style.ts":
  8437. /*!*************************!*\
  8438. !*** ./src/2D/style.ts ***!
  8439. \*************************/
  8440. /*! no static exports found */
  8441. /***/ (function(module, exports, __webpack_require__) {
  8442. "use strict";
  8443. Object.defineProperty(exports, "__esModule", { value: true });
  8444. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8445. var valueAndUnit_1 = __webpack_require__(/*! ./valueAndUnit */ "./src/2D/valueAndUnit.ts");
  8446. /**
  8447. * Define a style used by control to automatically setup properties based on a template.
  8448. * Only support font related properties so far
  8449. */
  8450. var Style = /** @class */ (function () {
  8451. /**
  8452. * Creates a new style object
  8453. * @param host defines the AdvancedDynamicTexture which hosts this style
  8454. */
  8455. function Style(host) {
  8456. this._fontFamily = "Arial";
  8457. this._fontStyle = "";
  8458. this._fontWeight = "";
  8459. /** @hidden */
  8460. this._fontSize = new valueAndUnit_1.ValueAndUnit(18, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL, false);
  8461. /**
  8462. * Observable raised when the style values are changed
  8463. */
  8464. this.onChangedObservable = new babylonjs_1.Observable();
  8465. this._host = host;
  8466. }
  8467. Object.defineProperty(Style.prototype, "fontSize", {
  8468. /**
  8469. * Gets or sets the font size
  8470. */
  8471. get: function () {
  8472. return this._fontSize.toString(this._host);
  8473. },
  8474. set: function (value) {
  8475. if (this._fontSize.toString(this._host) === value) {
  8476. return;
  8477. }
  8478. if (this._fontSize.fromString(value)) {
  8479. this.onChangedObservable.notifyObservers(this);
  8480. }
  8481. },
  8482. enumerable: true,
  8483. configurable: true
  8484. });
  8485. Object.defineProperty(Style.prototype, "fontFamily", {
  8486. /**
  8487. * Gets or sets the font family
  8488. */
  8489. get: function () {
  8490. return this._fontFamily;
  8491. },
  8492. set: function (value) {
  8493. if (this._fontFamily === value) {
  8494. return;
  8495. }
  8496. this._fontFamily = value;
  8497. this.onChangedObservable.notifyObservers(this);
  8498. },
  8499. enumerable: true,
  8500. configurable: true
  8501. });
  8502. Object.defineProperty(Style.prototype, "fontStyle", {
  8503. /**
  8504. * Gets or sets the font style
  8505. */
  8506. get: function () {
  8507. return this._fontStyle;
  8508. },
  8509. set: function (value) {
  8510. if (this._fontStyle === value) {
  8511. return;
  8512. }
  8513. this._fontStyle = value;
  8514. this.onChangedObservable.notifyObservers(this);
  8515. },
  8516. enumerable: true,
  8517. configurable: true
  8518. });
  8519. Object.defineProperty(Style.prototype, "fontWeight", {
  8520. /** Gets or sets font weight */
  8521. get: function () {
  8522. return this._fontWeight;
  8523. },
  8524. set: function (value) {
  8525. if (this._fontWeight === value) {
  8526. return;
  8527. }
  8528. this._fontWeight = value;
  8529. this.onChangedObservable.notifyObservers(this);
  8530. },
  8531. enumerable: true,
  8532. configurable: true
  8533. });
  8534. /** Dispose all associated resources */
  8535. Style.prototype.dispose = function () {
  8536. this.onChangedObservable.clear();
  8537. };
  8538. return Style;
  8539. }());
  8540. exports.Style = Style;
  8541. /***/ }),
  8542. /***/ "./src/2D/valueAndUnit.ts":
  8543. /*!********************************!*\
  8544. !*** ./src/2D/valueAndUnit.ts ***!
  8545. \********************************/
  8546. /*! no static exports found */
  8547. /***/ (function(module, exports, __webpack_require__) {
  8548. "use strict";
  8549. Object.defineProperty(exports, "__esModule", { value: true });
  8550. /**
  8551. * Class used to specific a value and its associated unit
  8552. */
  8553. var ValueAndUnit = /** @class */ (function () {
  8554. /**
  8555. * Creates a new ValueAndUnit
  8556. * @param value defines the value to store
  8557. * @param unit defines the unit to store
  8558. * @param negativeValueAllowed defines a boolean indicating if the value can be negative
  8559. */
  8560. function ValueAndUnit(value,
  8561. /** defines the unit to store */
  8562. unit,
  8563. /** defines a boolean indicating if the value can be negative */
  8564. negativeValueAllowed) {
  8565. if (unit === void 0) { unit = ValueAndUnit.UNITMODE_PIXEL; }
  8566. if (negativeValueAllowed === void 0) { negativeValueAllowed = true; }
  8567. this.unit = unit;
  8568. this.negativeValueAllowed = negativeValueAllowed;
  8569. this._value = 1;
  8570. /**
  8571. * Gets or sets a value indicating that this value will not scale accordingly with adaptive scaling property
  8572. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  8573. */
  8574. this.ignoreAdaptiveScaling = false;
  8575. this._value = value;
  8576. }
  8577. Object.defineProperty(ValueAndUnit.prototype, "isPercentage", {
  8578. /** Gets a boolean indicating if the value is a percentage */
  8579. get: function () {
  8580. return this.unit === ValueAndUnit.UNITMODE_PERCENTAGE;
  8581. },
  8582. enumerable: true,
  8583. configurable: true
  8584. });
  8585. Object.defineProperty(ValueAndUnit.prototype, "isPixel", {
  8586. /** Gets a boolean indicating if the value is store as pixel */
  8587. get: function () {
  8588. return this.unit === ValueAndUnit.UNITMODE_PIXEL;
  8589. },
  8590. enumerable: true,
  8591. configurable: true
  8592. });
  8593. Object.defineProperty(ValueAndUnit.prototype, "internalValue", {
  8594. /** Gets direct internal value */
  8595. get: function () {
  8596. return this._value;
  8597. },
  8598. enumerable: true,
  8599. configurable: true
  8600. });
  8601. /**
  8602. * Gets value as pixel
  8603. * @param host defines the root host
  8604. * @param refValue defines the reference value for percentages
  8605. * @returns the value as pixel
  8606. */
  8607. ValueAndUnit.prototype.getValueInPixel = function (host, refValue) {
  8608. if (this.isPixel) {
  8609. return this.getValue(host);
  8610. }
  8611. return this.getValue(host) * refValue;
  8612. };
  8613. /**
  8614. * Gets the value accordingly to its unit
  8615. * @param host defines the root host
  8616. * @returns the value
  8617. */
  8618. ValueAndUnit.prototype.getValue = function (host) {
  8619. if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
  8620. var width = 0;
  8621. var height = 0;
  8622. if (host.idealWidth) {
  8623. width = (this._value * host.getSize().width) / host.idealWidth;
  8624. }
  8625. if (host.idealHeight) {
  8626. height = (this._value * host.getSize().height) / host.idealHeight;
  8627. }
  8628. if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) {
  8629. return window.innerWidth < window.innerHeight ? width : height;
  8630. }
  8631. if (host.idealWidth) { // horizontal
  8632. return width;
  8633. }
  8634. if (host.idealHeight) { // vertical
  8635. return height;
  8636. }
  8637. }
  8638. return this._value;
  8639. };
  8640. /**
  8641. * Gets a string representation of the value
  8642. * @param host defines the root host
  8643. * @returns a string
  8644. */
  8645. ValueAndUnit.prototype.toString = function (host) {
  8646. switch (this.unit) {
  8647. case ValueAndUnit.UNITMODE_PERCENTAGE:
  8648. return (this.getValue(host) * 100) + "%";
  8649. case ValueAndUnit.UNITMODE_PIXEL:
  8650. return this.getValue(host) + "px";
  8651. }
  8652. return this.unit.toString();
  8653. };
  8654. /**
  8655. * Store a value parsed from a string
  8656. * @param source defines the source string
  8657. * @returns true if the value was successfully parsed
  8658. */
  8659. ValueAndUnit.prototype.fromString = function (source) {
  8660. var match = ValueAndUnit._Regex.exec(source.toString());
  8661. if (!match || match.length === 0) {
  8662. return false;
  8663. }
  8664. var sourceValue = parseFloat(match[1]);
  8665. var sourceUnit = this.unit;
  8666. if (!this.negativeValueAllowed) {
  8667. if (sourceValue < 0) {
  8668. sourceValue = 0;
  8669. }
  8670. }
  8671. if (match.length === 4) {
  8672. switch (match[3]) {
  8673. case "px":
  8674. sourceUnit = ValueAndUnit.UNITMODE_PIXEL;
  8675. break;
  8676. case "%":
  8677. sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;
  8678. sourceValue /= 100.0;
  8679. break;
  8680. }
  8681. }
  8682. if (sourceValue === this._value && sourceUnit === this.unit) {
  8683. return false;
  8684. }
  8685. this._value = sourceValue;
  8686. this.unit = sourceUnit;
  8687. return true;
  8688. };
  8689. Object.defineProperty(ValueAndUnit, "UNITMODE_PERCENTAGE", {
  8690. /** UNITMODE_PERCENTAGE */
  8691. get: function () {
  8692. return ValueAndUnit._UNITMODE_PERCENTAGE;
  8693. },
  8694. enumerable: true,
  8695. configurable: true
  8696. });
  8697. Object.defineProperty(ValueAndUnit, "UNITMODE_PIXEL", {
  8698. /** UNITMODE_PIXEL */
  8699. get: function () {
  8700. return ValueAndUnit._UNITMODE_PIXEL;
  8701. },
  8702. enumerable: true,
  8703. configurable: true
  8704. });
  8705. // Static
  8706. ValueAndUnit._Regex = /(^-?\d*(\.\d+)?)(%|px)?/;
  8707. ValueAndUnit._UNITMODE_PERCENTAGE = 0;
  8708. ValueAndUnit._UNITMODE_PIXEL = 1;
  8709. return ValueAndUnit;
  8710. }());
  8711. exports.ValueAndUnit = ValueAndUnit;
  8712. /***/ }),
  8713. /***/ "./src/3D/controls/abstractButton3D.ts":
  8714. /*!*********************************************!*\
  8715. !*** ./src/3D/controls/abstractButton3D.ts ***!
  8716. \*********************************************/
  8717. /*! no static exports found */
  8718. /***/ (function(module, exports, __webpack_require__) {
  8719. "use strict";
  8720. var __extends = (this && this.__extends) || (function () {
  8721. var extendStatics = function (d, b) {
  8722. extendStatics = Object.setPrototypeOf ||
  8723. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  8724. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  8725. return extendStatics(d, b);
  8726. }
  8727. return function (d, b) {
  8728. extendStatics(d, b);
  8729. function __() { this.constructor = d; }
  8730. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8731. };
  8732. })();
  8733. Object.defineProperty(exports, "__esModule", { value: true });
  8734. var control3D_1 = __webpack_require__(/*! ./control3D */ "./src/3D/controls/control3D.ts");
  8735. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8736. /**
  8737. * Class used as a root to all buttons
  8738. */
  8739. var AbstractButton3D = /** @class */ (function (_super) {
  8740. __extends(AbstractButton3D, _super);
  8741. /**
  8742. * Creates a new button
  8743. * @param name defines the control name
  8744. */
  8745. function AbstractButton3D(name) {
  8746. return _super.call(this, name) || this;
  8747. }
  8748. AbstractButton3D.prototype._getTypeName = function () {
  8749. return "AbstractButton3D";
  8750. };
  8751. // Mesh association
  8752. AbstractButton3D.prototype._createNode = function (scene) {
  8753. return new babylonjs_1.TransformNode("button" + this.name);
  8754. };
  8755. return AbstractButton3D;
  8756. }(control3D_1.Control3D));
  8757. exports.AbstractButton3D = AbstractButton3D;
  8758. /***/ }),
  8759. /***/ "./src/3D/controls/button3D.ts":
  8760. /*!*************************************!*\
  8761. !*** ./src/3D/controls/button3D.ts ***!
  8762. \*************************************/
  8763. /*! no static exports found */
  8764. /***/ (function(module, exports, __webpack_require__) {
  8765. "use strict";
  8766. var __extends = (this && this.__extends) || (function () {
  8767. var extendStatics = function (d, b) {
  8768. extendStatics = Object.setPrototypeOf ||
  8769. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  8770. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  8771. return extendStatics(d, b);
  8772. }
  8773. return function (d, b) {
  8774. extendStatics(d, b);
  8775. function __() { this.constructor = d; }
  8776. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8777. };
  8778. })();
  8779. Object.defineProperty(exports, "__esModule", { value: true });
  8780. var abstractButton3D_1 = __webpack_require__(/*! ./abstractButton3D */ "./src/3D/controls/abstractButton3D.ts");
  8781. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8782. var advancedDynamicTexture_1 = __webpack_require__(/*! ../../2D/advancedDynamicTexture */ "./src/2D/advancedDynamicTexture.ts");
  8783. /**
  8784. * Class used to create a button in 3D
  8785. */
  8786. var Button3D = /** @class */ (function (_super) {
  8787. __extends(Button3D, _super);
  8788. /**
  8789. * Creates a new button
  8790. * @param name defines the control name
  8791. */
  8792. function Button3D(name) {
  8793. var _this = _super.call(this, name) || this;
  8794. _this._contentResolution = 512;
  8795. _this._contentScaleRatio = 2;
  8796. // Default animations
  8797. _this.pointerEnterAnimation = function () {
  8798. if (!_this.mesh) {
  8799. return;
  8800. }
  8801. _this._currentMaterial.emissiveColor = babylonjs_1.Color3.Red();
  8802. };
  8803. _this.pointerOutAnimation = function () {
  8804. _this._currentMaterial.emissiveColor = babylonjs_1.Color3.Black();
  8805. };
  8806. _this.pointerDownAnimation = function () {
  8807. if (!_this.mesh) {
  8808. return;
  8809. }
  8810. _this.mesh.scaling.scaleInPlace(0.95);
  8811. };
  8812. _this.pointerUpAnimation = function () {
  8813. if (!_this.mesh) {
  8814. return;
  8815. }
  8816. _this.mesh.scaling.scaleInPlace(1.0 / 0.95);
  8817. };
  8818. return _this;
  8819. }
  8820. Object.defineProperty(Button3D.prototype, "contentResolution", {
  8821. /**
  8822. * Gets or sets the texture resolution used to render content (512 by default)
  8823. */
  8824. get: function () {
  8825. return this._contentResolution;
  8826. },
  8827. set: function (value) {
  8828. if (this._contentResolution === value) {
  8829. return;
  8830. }
  8831. this._contentResolution = value;
  8832. this._resetContent();
  8833. },
  8834. enumerable: true,
  8835. configurable: true
  8836. });
  8837. Object.defineProperty(Button3D.prototype, "contentScaleRatio", {
  8838. /**
  8839. * Gets or sets the texture scale ratio used to render content (2 by default)
  8840. */
  8841. get: function () {
  8842. return this._contentScaleRatio;
  8843. },
  8844. set: function (value) {
  8845. if (this._contentScaleRatio === value) {
  8846. return;
  8847. }
  8848. this._contentScaleRatio = value;
  8849. this._resetContent();
  8850. },
  8851. enumerable: true,
  8852. configurable: true
  8853. });
  8854. Button3D.prototype._disposeFacadeTexture = function () {
  8855. if (this._facadeTexture) {
  8856. this._facadeTexture.dispose();
  8857. this._facadeTexture = null;
  8858. }
  8859. };
  8860. Button3D.prototype._resetContent = function () {
  8861. this._disposeFacadeTexture();
  8862. this.content = this._content;
  8863. };
  8864. Object.defineProperty(Button3D.prototype, "content", {
  8865. /**
  8866. * Gets or sets the GUI 2D content used to display the button's facade
  8867. */
  8868. get: function () {
  8869. return this._content;
  8870. },
  8871. set: function (value) {
  8872. this._content = value;
  8873. if (!this._host || !this._host.utilityLayer) {
  8874. return;
  8875. }
  8876. if (!this._facadeTexture) {
  8877. this._facadeTexture = new advancedDynamicTexture_1.AdvancedDynamicTexture("Facade", this._contentResolution, this._contentResolution, this._host.utilityLayer.utilityLayerScene, true, babylonjs_1.Texture.TRILINEAR_SAMPLINGMODE);
  8878. this._facadeTexture.rootContainer.scaleX = this._contentScaleRatio;
  8879. this._facadeTexture.rootContainer.scaleY = this._contentScaleRatio;
  8880. this._facadeTexture.premulAlpha = true;
  8881. }
  8882. this._facadeTexture.addControl(value);
  8883. this._applyFacade(this._facadeTexture);
  8884. },
  8885. enumerable: true,
  8886. configurable: true
  8887. });
  8888. /**
  8889. * Apply the facade texture (created from the content property).
  8890. * This function can be overloaded by child classes
  8891. * @param facadeTexture defines the AdvancedDynamicTexture to use
  8892. */
  8893. Button3D.prototype._applyFacade = function (facadeTexture) {
  8894. this._currentMaterial.emissiveTexture = facadeTexture;
  8895. };
  8896. Button3D.prototype._getTypeName = function () {
  8897. return "Button3D";
  8898. };
  8899. // Mesh association
  8900. Button3D.prototype._createNode = function (scene) {
  8901. var faceUV = new Array(6);
  8902. for (var i = 0; i < 6; i++) {
  8903. faceUV[i] = new babylonjs_1.Vector4(0, 0, 0, 0);
  8904. }
  8905. faceUV[1] = new babylonjs_1.Vector4(0, 0, 1, 1);
  8906. var mesh = babylonjs_1.MeshBuilder.CreateBox(this.name + "_rootMesh", {
  8907. width: 1.0,
  8908. height: 1.0,
  8909. depth: 0.08,
  8910. faceUV: faceUV
  8911. }, scene);
  8912. return mesh;
  8913. };
  8914. Button3D.prototype._affectMaterial = function (mesh) {
  8915. var material = new babylonjs_1.StandardMaterial(this.name + "Material", mesh.getScene());
  8916. material.specularColor = babylonjs_1.Color3.Black();
  8917. mesh.material = material;
  8918. this._currentMaterial = material;
  8919. this._resetContent();
  8920. };
  8921. /**
  8922. * Releases all associated resources
  8923. */
  8924. Button3D.prototype.dispose = function () {
  8925. _super.prototype.dispose.call(this);
  8926. this._disposeFacadeTexture();
  8927. if (this._currentMaterial) {
  8928. this._currentMaterial.dispose();
  8929. }
  8930. };
  8931. return Button3D;
  8932. }(abstractButton3D_1.AbstractButton3D));
  8933. exports.Button3D = Button3D;
  8934. /***/ }),
  8935. /***/ "./src/3D/controls/container3D.ts":
  8936. /*!****************************************!*\
  8937. !*** ./src/3D/controls/container3D.ts ***!
  8938. \****************************************/
  8939. /*! no static exports found */
  8940. /***/ (function(module, exports, __webpack_require__) {
  8941. "use strict";
  8942. var __extends = (this && this.__extends) || (function () {
  8943. var extendStatics = function (d, b) {
  8944. extendStatics = Object.setPrototypeOf ||
  8945. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  8946. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  8947. return extendStatics(d, b);
  8948. }
  8949. return function (d, b) {
  8950. extendStatics(d, b);
  8951. function __() { this.constructor = d; }
  8952. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8953. };
  8954. })();
  8955. Object.defineProperty(exports, "__esModule", { value: true });
  8956. var control3D_1 = __webpack_require__(/*! ./control3D */ "./src/3D/controls/control3D.ts");
  8957. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8958. /**
  8959. * Class used to create containers for controls
  8960. */
  8961. var Container3D = /** @class */ (function (_super) {
  8962. __extends(Container3D, _super);
  8963. /**
  8964. * Creates a new container
  8965. * @param name defines the container name
  8966. */
  8967. function Container3D(name) {
  8968. var _this = _super.call(this, name) || this;
  8969. _this._blockLayout = false;
  8970. /**
  8971. * Gets the list of child controls
  8972. */
  8973. _this._children = new Array();
  8974. return _this;
  8975. }
  8976. Object.defineProperty(Container3D.prototype, "children", {
  8977. /**
  8978. * Gets the list of child controls
  8979. */
  8980. get: function () {
  8981. return this._children;
  8982. },
  8983. enumerable: true,
  8984. configurable: true
  8985. });
  8986. Object.defineProperty(Container3D.prototype, "blockLayout", {
  8987. /**
  8988. * Gets or sets a boolean indicating if the layout must be blocked (default is false).
  8989. * This is helpful to optimize layout operation when adding multiple children in a row
  8990. */
  8991. get: function () {
  8992. return this._blockLayout;
  8993. },
  8994. set: function (value) {
  8995. if (this._blockLayout === value) {
  8996. return;
  8997. }
  8998. this._blockLayout = value;
  8999. if (!this._blockLayout) {
  9000. this._arrangeChildren();
  9001. }
  9002. },
  9003. enumerable: true,
  9004. configurable: true
  9005. });
  9006. /**
  9007. * Force the container to update the layout. Please note that it will not take blockLayout property in account
  9008. * @returns the current container
  9009. */
  9010. Container3D.prototype.updateLayout = function () {
  9011. this._arrangeChildren();
  9012. return this;
  9013. };
  9014. /**
  9015. * Gets a boolean indicating if the given control is in the children of this control
  9016. * @param control defines the control to check
  9017. * @returns true if the control is in the child list
  9018. */
  9019. Container3D.prototype.containsControl = function (control) {
  9020. return this._children.indexOf(control) !== -1;
  9021. };
  9022. /**
  9023. * Adds a control to the children of this control
  9024. * @param control defines the control to add
  9025. * @returns the current container
  9026. */
  9027. Container3D.prototype.addControl = function (control) {
  9028. var index = this._children.indexOf(control);
  9029. if (index !== -1) {
  9030. return this;
  9031. }
  9032. control.parent = this;
  9033. control._host = this._host;
  9034. this._children.push(control);
  9035. if (this._host.utilityLayer) {
  9036. control._prepareNode(this._host.utilityLayer.utilityLayerScene);
  9037. if (control.node) {
  9038. control.node.parent = this.node;
  9039. }
  9040. if (!this.blockLayout) {
  9041. this._arrangeChildren();
  9042. }
  9043. }
  9044. return this;
  9045. };
  9046. /**
  9047. * This function will be called everytime a new control is added
  9048. */
  9049. Container3D.prototype._arrangeChildren = function () {
  9050. };
  9051. Container3D.prototype._createNode = function (scene) {
  9052. return new babylonjs_1.TransformNode("ContainerNode", scene);
  9053. };
  9054. /**
  9055. * Removes a control from the children of this control
  9056. * @param control defines the control to remove
  9057. * @returns the current container
  9058. */
  9059. Container3D.prototype.removeControl = function (control) {
  9060. var index = this._children.indexOf(control);
  9061. if (index !== -1) {
  9062. this._children.splice(index, 1);
  9063. control.parent = null;
  9064. control._disposeNode();
  9065. }
  9066. return this;
  9067. };
  9068. Container3D.prototype._getTypeName = function () {
  9069. return "Container3D";
  9070. };
  9071. /**
  9072. * Releases all associated resources
  9073. */
  9074. Container3D.prototype.dispose = function () {
  9075. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  9076. var control = _a[_i];
  9077. control.dispose();
  9078. }
  9079. this._children = [];
  9080. _super.prototype.dispose.call(this);
  9081. };
  9082. /** Control rotation will remain unchanged */
  9083. Container3D.UNSET_ORIENTATION = 0;
  9084. /** Control will rotate to make it look at sphere central axis */
  9085. Container3D.FACEORIGIN_ORIENTATION = 1;
  9086. /** Control will rotate to make it look back at sphere central axis */
  9087. Container3D.FACEORIGINREVERSED_ORIENTATION = 2;
  9088. /** Control will rotate to look at z axis (0, 0, 1) */
  9089. Container3D.FACEFORWARD_ORIENTATION = 3;
  9090. /** Control will rotate to look at negative z axis (0, 0, -1) */
  9091. Container3D.FACEFORWARDREVERSED_ORIENTATION = 4;
  9092. return Container3D;
  9093. }(control3D_1.Control3D));
  9094. exports.Container3D = Container3D;
  9095. /***/ }),
  9096. /***/ "./src/3D/controls/control3D.ts":
  9097. /*!**************************************!*\
  9098. !*** ./src/3D/controls/control3D.ts ***!
  9099. \**************************************/
  9100. /*! no static exports found */
  9101. /***/ (function(module, exports, __webpack_require__) {
  9102. "use strict";
  9103. Object.defineProperty(exports, "__esModule", { value: true });
  9104. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  9105. var vector3WithInfo_1 = __webpack_require__(/*! ../vector3WithInfo */ "./src/3D/vector3WithInfo.ts");
  9106. /**
  9107. * Class used as base class for controls
  9108. */
  9109. var Control3D = /** @class */ (function () {
  9110. /**
  9111. * Creates a new control
  9112. * @param name defines the control name
  9113. */
  9114. function Control3D(
  9115. /** Defines the control name */
  9116. name) {
  9117. this.name = name;
  9118. this._downCount = 0;
  9119. this._enterCount = -1;
  9120. this._downPointerIds = {};
  9121. this._isVisible = true;
  9122. /**
  9123. * An event triggered when the pointer move over the control
  9124. */
  9125. this.onPointerMoveObservable = new babylonjs_1.Observable();
  9126. /**
  9127. * An event triggered when the pointer move out of the control
  9128. */
  9129. this.onPointerOutObservable = new babylonjs_1.Observable();
  9130. /**
  9131. * An event triggered when the pointer taps the control
  9132. */
  9133. this.onPointerDownObservable = new babylonjs_1.Observable();
  9134. /**
  9135. * An event triggered when pointer is up
  9136. */
  9137. this.onPointerUpObservable = new babylonjs_1.Observable();
  9138. /**
  9139. * An event triggered when a control is clicked on (with a mouse)
  9140. */
  9141. this.onPointerClickObservable = new babylonjs_1.Observable();
  9142. /**
  9143. * An event triggered when pointer enters the control
  9144. */
  9145. this.onPointerEnterObservable = new babylonjs_1.Observable();
  9146. // Behaviors
  9147. this._behaviors = new Array();
  9148. }
  9149. Object.defineProperty(Control3D.prototype, "position", {
  9150. /** Gets or sets the control position in world space */
  9151. get: function () {
  9152. if (!this._node) {
  9153. return babylonjs_1.Vector3.Zero();
  9154. }
  9155. return this._node.position;
  9156. },
  9157. set: function (value) {
  9158. if (!this._node) {
  9159. return;
  9160. }
  9161. this._node.position = value;
  9162. },
  9163. enumerable: true,
  9164. configurable: true
  9165. });
  9166. Object.defineProperty(Control3D.prototype, "scaling", {
  9167. /** Gets or sets the control scaling in world space */
  9168. get: function () {
  9169. if (!this._node) {
  9170. return new babylonjs_1.Vector3(1, 1, 1);
  9171. }
  9172. return this._node.scaling;
  9173. },
  9174. set: function (value) {
  9175. if (!this._node) {
  9176. return;
  9177. }
  9178. this._node.scaling = value;
  9179. },
  9180. enumerable: true,
  9181. configurable: true
  9182. });
  9183. Object.defineProperty(Control3D.prototype, "behaviors", {
  9184. /**
  9185. * Gets the list of attached behaviors
  9186. * @see http://doc.babylonjs.com/features/behaviour
  9187. */
  9188. get: function () {
  9189. return this._behaviors;
  9190. },
  9191. enumerable: true,
  9192. configurable: true
  9193. });
  9194. /**
  9195. * Attach a behavior to the control
  9196. * @see http://doc.babylonjs.com/features/behaviour
  9197. * @param behavior defines the behavior to attach
  9198. * @returns the current control
  9199. */
  9200. Control3D.prototype.addBehavior = function (behavior) {
  9201. var _this = this;
  9202. var index = this._behaviors.indexOf(behavior);
  9203. if (index !== -1) {
  9204. return this;
  9205. }
  9206. behavior.init();
  9207. var scene = this._host.scene;
  9208. if (scene.isLoading) {
  9209. // We defer the attach when the scene will be loaded
  9210. scene.onDataLoadedObservable.addOnce(function () {
  9211. behavior.attach(_this);
  9212. });
  9213. }
  9214. else {
  9215. behavior.attach(this);
  9216. }
  9217. this._behaviors.push(behavior);
  9218. return this;
  9219. };
  9220. /**
  9221. * Remove an attached behavior
  9222. * @see http://doc.babylonjs.com/features/behaviour
  9223. * @param behavior defines the behavior to attach
  9224. * @returns the current control
  9225. */
  9226. Control3D.prototype.removeBehavior = function (behavior) {
  9227. var index = this._behaviors.indexOf(behavior);
  9228. if (index === -1) {
  9229. return this;
  9230. }
  9231. this._behaviors[index].detach();
  9232. this._behaviors.splice(index, 1);
  9233. return this;
  9234. };
  9235. /**
  9236. * Gets an attached behavior by name
  9237. * @param name defines the name of the behavior to look for
  9238. * @see http://doc.babylonjs.com/features/behaviour
  9239. * @returns null if behavior was not found else the requested behavior
  9240. */
  9241. Control3D.prototype.getBehaviorByName = function (name) {
  9242. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  9243. var behavior = _a[_i];
  9244. if (behavior.name === name) {
  9245. return behavior;
  9246. }
  9247. }
  9248. return null;
  9249. };
  9250. Object.defineProperty(Control3D.prototype, "isVisible", {
  9251. /** Gets or sets a boolean indicating if the control is visible */
  9252. get: function () {
  9253. return this._isVisible;
  9254. },
  9255. set: function (value) {
  9256. if (this._isVisible === value) {
  9257. return;
  9258. }
  9259. this._isVisible = value;
  9260. var mesh = this.mesh;
  9261. if (mesh) {
  9262. mesh.setEnabled(value);
  9263. }
  9264. },
  9265. enumerable: true,
  9266. configurable: true
  9267. });
  9268. Object.defineProperty(Control3D.prototype, "typeName", {
  9269. /**
  9270. * Gets a string representing the class name
  9271. */
  9272. get: function () {
  9273. return this._getTypeName();
  9274. },
  9275. enumerable: true,
  9276. configurable: true
  9277. });
  9278. Control3D.prototype._getTypeName = function () {
  9279. return "Control3D";
  9280. };
  9281. Object.defineProperty(Control3D.prototype, "node", {
  9282. /**
  9283. * Gets the transform node used by this control
  9284. */
  9285. get: function () {
  9286. return this._node;
  9287. },
  9288. enumerable: true,
  9289. configurable: true
  9290. });
  9291. Object.defineProperty(Control3D.prototype, "mesh", {
  9292. /**
  9293. * Gets the mesh used to render this control
  9294. */
  9295. get: function () {
  9296. if (this._node instanceof babylonjs_1.AbstractMesh) {
  9297. return this._node;
  9298. }
  9299. return null;
  9300. },
  9301. enumerable: true,
  9302. configurable: true
  9303. });
  9304. /**
  9305. * Link the control as child of the given node
  9306. * @param node defines the node to link to. Use null to unlink the control
  9307. * @returns the current control
  9308. */
  9309. Control3D.prototype.linkToTransformNode = function (node) {
  9310. if (this._node) {
  9311. this._node.parent = node;
  9312. }
  9313. return this;
  9314. };
  9315. /** @hidden **/
  9316. Control3D.prototype._prepareNode = function (scene) {
  9317. if (!this._node) {
  9318. this._node = this._createNode(scene);
  9319. if (!this.node) {
  9320. return;
  9321. }
  9322. this._node.metadata = this; // Store the control on the metadata field in order to get it when picking
  9323. this._node.position = this.position;
  9324. this._node.scaling = this.scaling;
  9325. var mesh = this.mesh;
  9326. if (mesh) {
  9327. mesh.isPickable = true;
  9328. this._affectMaterial(mesh);
  9329. }
  9330. }
  9331. };
  9332. /**
  9333. * Node creation.
  9334. * Can be overriden by children
  9335. * @param scene defines the scene where the node must be attached
  9336. * @returns the attached node or null if none. Must return a Mesh or AbstractMesh if there is an atttached visible object
  9337. */
  9338. Control3D.prototype._createNode = function (scene) {
  9339. // Do nothing by default
  9340. return null;
  9341. };
  9342. /**
  9343. * Affect a material to the given mesh
  9344. * @param mesh defines the mesh which will represent the control
  9345. */
  9346. Control3D.prototype._affectMaterial = function (mesh) {
  9347. mesh.material = null;
  9348. };
  9349. // Pointers
  9350. /** @hidden */
  9351. Control3D.prototype._onPointerMove = function (target, coordinates) {
  9352. this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  9353. };
  9354. /** @hidden */
  9355. Control3D.prototype._onPointerEnter = function (target) {
  9356. if (this._enterCount > 0) {
  9357. return false;
  9358. }
  9359. if (this._enterCount === -1) { // -1 is for touch input, we are now sure we are with a mouse or pencil
  9360. this._enterCount = 0;
  9361. }
  9362. this._enterCount++;
  9363. this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  9364. if (this.pointerEnterAnimation) {
  9365. this.pointerEnterAnimation();
  9366. }
  9367. return true;
  9368. };
  9369. /** @hidden */
  9370. Control3D.prototype._onPointerOut = function (target) {
  9371. this._enterCount = 0;
  9372. this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  9373. if (this.pointerOutAnimation) {
  9374. this.pointerOutAnimation();
  9375. }
  9376. };
  9377. /** @hidden */
  9378. Control3D.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  9379. if (this._downCount !== 0) {
  9380. return false;
  9381. }
  9382. this._downCount++;
  9383. this._downPointerIds[pointerId] = true;
  9384. this.onPointerDownObservable.notifyObservers(new vector3WithInfo_1.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  9385. if (this.pointerDownAnimation) {
  9386. this.pointerDownAnimation();
  9387. }
  9388. return true;
  9389. };
  9390. /** @hidden */
  9391. Control3D.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  9392. this._downCount = 0;
  9393. delete this._downPointerIds[pointerId];
  9394. if (notifyClick && (this._enterCount > 0 || this._enterCount === -1)) {
  9395. this.onPointerClickObservable.notifyObservers(new vector3WithInfo_1.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  9396. }
  9397. this.onPointerUpObservable.notifyObservers(new vector3WithInfo_1.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  9398. if (this.pointerUpAnimation) {
  9399. this.pointerUpAnimation();
  9400. }
  9401. };
  9402. /** @hidden */
  9403. Control3D.prototype.forcePointerUp = function (pointerId) {
  9404. if (pointerId === void 0) { pointerId = null; }
  9405. if (pointerId !== null) {
  9406. this._onPointerUp(this, babylonjs_1.Vector3.Zero(), pointerId, 0, true);
  9407. }
  9408. else {
  9409. for (var key in this._downPointerIds) {
  9410. this._onPointerUp(this, babylonjs_1.Vector3.Zero(), +key, 0, true);
  9411. }
  9412. }
  9413. };
  9414. /** @hidden */
  9415. Control3D.prototype._processObservables = function (type, pickedPoint, pointerId, buttonIndex) {
  9416. if (type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  9417. this._onPointerMove(this, pickedPoint);
  9418. var previousControlOver = this._host._lastControlOver[pointerId];
  9419. if (previousControlOver && previousControlOver !== this) {
  9420. previousControlOver._onPointerOut(this);
  9421. }
  9422. if (previousControlOver !== this) {
  9423. this._onPointerEnter(this);
  9424. }
  9425. this._host._lastControlOver[pointerId] = this;
  9426. return true;
  9427. }
  9428. if (type === babylonjs_1.PointerEventTypes.POINTERDOWN) {
  9429. this._onPointerDown(this, pickedPoint, pointerId, buttonIndex);
  9430. this._host._lastControlDown[pointerId] = this;
  9431. this._host._lastPickedControl = this;
  9432. return true;
  9433. }
  9434. if (type === babylonjs_1.PointerEventTypes.POINTERUP) {
  9435. if (this._host._lastControlDown[pointerId]) {
  9436. this._host._lastControlDown[pointerId]._onPointerUp(this, pickedPoint, pointerId, buttonIndex, true);
  9437. }
  9438. delete this._host._lastControlDown[pointerId];
  9439. return true;
  9440. }
  9441. return false;
  9442. };
  9443. /** @hidden */
  9444. Control3D.prototype._disposeNode = function () {
  9445. if (this._node) {
  9446. this._node.dispose();
  9447. this._node = null;
  9448. }
  9449. };
  9450. /**
  9451. * Releases all associated resources
  9452. */
  9453. Control3D.prototype.dispose = function () {
  9454. this.onPointerDownObservable.clear();
  9455. this.onPointerEnterObservable.clear();
  9456. this.onPointerMoveObservable.clear();
  9457. this.onPointerOutObservable.clear();
  9458. this.onPointerUpObservable.clear();
  9459. this.onPointerClickObservable.clear();
  9460. this._disposeNode();
  9461. // Behaviors
  9462. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  9463. var behavior = _a[_i];
  9464. behavior.detach();
  9465. }
  9466. };
  9467. return Control3D;
  9468. }());
  9469. exports.Control3D = Control3D;
  9470. /***/ }),
  9471. /***/ "./src/3D/controls/cylinderPanel.ts":
  9472. /*!******************************************!*\
  9473. !*** ./src/3D/controls/cylinderPanel.ts ***!
  9474. \******************************************/
  9475. /*! no static exports found */
  9476. /***/ (function(module, exports, __webpack_require__) {
  9477. "use strict";
  9478. var __extends = (this && this.__extends) || (function () {
  9479. var extendStatics = function (d, b) {
  9480. extendStatics = Object.setPrototypeOf ||
  9481. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9482. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  9483. return extendStatics(d, b);
  9484. }
  9485. return function (d, b) {
  9486. extendStatics(d, b);
  9487. function __() { this.constructor = d; }
  9488. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9489. };
  9490. })();
  9491. Object.defineProperty(exports, "__esModule", { value: true });
  9492. var volumeBasedPanel_1 = __webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts");
  9493. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  9494. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  9495. /**
  9496. * Class used to create a container panel deployed on the surface of a cylinder
  9497. */
  9498. var CylinderPanel = /** @class */ (function (_super) {
  9499. __extends(CylinderPanel, _super);
  9500. function CylinderPanel() {
  9501. var _this = _super !== null && _super.apply(this, arguments) || this;
  9502. _this._radius = 5.0;
  9503. return _this;
  9504. }
  9505. Object.defineProperty(CylinderPanel.prototype, "radius", {
  9506. /**
  9507. * Gets or sets the radius of the cylinder where to project controls (5 by default)
  9508. */
  9509. get: function () {
  9510. return this._radius;
  9511. },
  9512. set: function (value) {
  9513. var _this = this;
  9514. if (this._radius === value) {
  9515. return;
  9516. }
  9517. this._radius = value;
  9518. babylonjs_1.Tools.SetImmediate(function () {
  9519. _this._arrangeChildren();
  9520. });
  9521. },
  9522. enumerable: true,
  9523. configurable: true
  9524. });
  9525. CylinderPanel.prototype._mapGridNode = function (control, nodePosition) {
  9526. var mesh = control.mesh;
  9527. if (!mesh) {
  9528. return;
  9529. }
  9530. var newPos = this._cylindricalMapping(nodePosition);
  9531. control.position = newPos;
  9532. switch (this.orientation) {
  9533. case container3D_1.Container3D.FACEORIGIN_ORIENTATION:
  9534. mesh.lookAt(new BABYLON.Vector3(-newPos.x, newPos.y, -newPos.z));
  9535. break;
  9536. case container3D_1.Container3D.FACEORIGINREVERSED_ORIENTATION:
  9537. mesh.lookAt(new BABYLON.Vector3(2 * newPos.x, newPos.y, 2 * newPos.z));
  9538. break;
  9539. case container3D_1.Container3D.FACEFORWARD_ORIENTATION:
  9540. break;
  9541. case container3D_1.Container3D.FACEFORWARDREVERSED_ORIENTATION:
  9542. mesh.rotate(BABYLON.Axis.Y, Math.PI, BABYLON.Space.LOCAL);
  9543. break;
  9544. }
  9545. };
  9546. CylinderPanel.prototype._cylindricalMapping = function (source) {
  9547. var newPos = new babylonjs_1.Vector3(0, source.y, this._radius);
  9548. var yAngle = (source.x / this._radius);
  9549. babylonjs_1.Matrix.RotationYawPitchRollToRef(yAngle, 0, 0, babylonjs_1.Tmp.Matrix[0]);
  9550. return babylonjs_1.Vector3.TransformNormal(newPos, babylonjs_1.Tmp.Matrix[0]);
  9551. };
  9552. return CylinderPanel;
  9553. }(volumeBasedPanel_1.VolumeBasedPanel));
  9554. exports.CylinderPanel = CylinderPanel;
  9555. /***/ }),
  9556. /***/ "./src/3D/controls/holographicButton.ts":
  9557. /*!**********************************************!*\
  9558. !*** ./src/3D/controls/holographicButton.ts ***!
  9559. \**********************************************/
  9560. /*! no static exports found */
  9561. /***/ (function(module, exports, __webpack_require__) {
  9562. "use strict";
  9563. var __extends = (this && this.__extends) || (function () {
  9564. var extendStatics = function (d, b) {
  9565. extendStatics = Object.setPrototypeOf ||
  9566. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9567. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  9568. return extendStatics(d, b);
  9569. }
  9570. return function (d, b) {
  9571. extendStatics(d, b);
  9572. function __() { this.constructor = d; }
  9573. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9574. };
  9575. })();
  9576. Object.defineProperty(exports, "__esModule", { value: true });
  9577. var button3D_1 = __webpack_require__(/*! ./button3D */ "./src/3D/controls/button3D.ts");
  9578. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  9579. var fluentMaterial_1 = __webpack_require__(/*! ../materials/fluentMaterial */ "./src/3D/materials/fluentMaterial.ts");
  9580. var stackPanel_1 = __webpack_require__(/*! ../../2D/controls/stackPanel */ "./src/2D/controls/stackPanel.ts");
  9581. var image_1 = __webpack_require__(/*! ../../2D/controls/image */ "./src/2D/controls/image.ts");
  9582. var textBlock_1 = __webpack_require__(/*! ../../2D/controls/textBlock */ "./src/2D/controls/textBlock.ts");
  9583. var advancedDynamicTexture_1 = __webpack_require__(/*! ../../2D/advancedDynamicTexture */ "./src/2D/advancedDynamicTexture.ts");
  9584. /**
  9585. * Class used to create a holographic button in 3D
  9586. */
  9587. var HolographicButton = /** @class */ (function (_super) {
  9588. __extends(HolographicButton, _super);
  9589. /**
  9590. * Creates a new button
  9591. * @param name defines the control name
  9592. */
  9593. function HolographicButton(name, shareMaterials) {
  9594. if (shareMaterials === void 0) { shareMaterials = true; }
  9595. var _this = _super.call(this, name) || this;
  9596. _this._shareMaterials = true;
  9597. _this._shareMaterials = shareMaterials;
  9598. // Default animations
  9599. _this.pointerEnterAnimation = function () {
  9600. if (!_this.mesh) {
  9601. return;
  9602. }
  9603. _this._frontPlate.setEnabled(true);
  9604. };
  9605. _this.pointerOutAnimation = function () {
  9606. if (!_this.mesh) {
  9607. return;
  9608. }
  9609. _this._frontPlate.setEnabled(false);
  9610. };
  9611. return _this;
  9612. }
  9613. HolographicButton.prototype._disposeTooltip = function () {
  9614. this._tooltipFade = null;
  9615. if (this._tooltipTextBlock) {
  9616. this._tooltipTextBlock.dispose();
  9617. }
  9618. if (this._tooltipTexture) {
  9619. this._tooltipTexture.dispose();
  9620. }
  9621. if (this._tooltipMesh) {
  9622. this._tooltipMesh.dispose();
  9623. }
  9624. this.onPointerEnterObservable.remove(this._tooltipHoverObserver);
  9625. this.onPointerOutObservable.remove(this._tooltipOutObserver);
  9626. };
  9627. Object.defineProperty(HolographicButton.prototype, "tooltipText", {
  9628. get: function () {
  9629. if (this._tooltipTextBlock) {
  9630. return this._tooltipTextBlock.text;
  9631. }
  9632. return null;
  9633. },
  9634. /**
  9635. * Text to be displayed on the tooltip shown when hovering on the button. When set to null tooltip is disabled. (Default: null)
  9636. */
  9637. set: function (text) {
  9638. var _this = this;
  9639. if (!text) {
  9640. this._disposeTooltip();
  9641. return;
  9642. }
  9643. if (!this._tooltipFade) {
  9644. // Create tooltip with mesh and text
  9645. this._tooltipMesh = BABYLON.MeshBuilder.CreatePlane("", { size: 1 }, this._backPlate._scene);
  9646. var tooltipBackground = BABYLON.MeshBuilder.CreatePlane("", { size: 1, sideOrientation: BABYLON.Mesh.DOUBLESIDE }, this._backPlate._scene);
  9647. var mat = new babylonjs_1.StandardMaterial("", this._backPlate._scene);
  9648. mat.diffuseColor = BABYLON.Color3.FromHexString("#212121");
  9649. tooltipBackground.material = mat;
  9650. tooltipBackground.isPickable = false;
  9651. this._tooltipMesh.addChild(tooltipBackground);
  9652. tooltipBackground.position.z = 0.05;
  9653. this._tooltipMesh.scaling.y = 1 / 3;
  9654. this._tooltipMesh.position.y = 0.7;
  9655. this._tooltipMesh.position.z = -0.15;
  9656. this._tooltipMesh.isPickable = false;
  9657. this._tooltipMesh.parent = this._backPlate;
  9658. // Create text texture for the tooltip
  9659. this._tooltipTexture = advancedDynamicTexture_1.AdvancedDynamicTexture.CreateForMesh(this._tooltipMesh);
  9660. this._tooltipTextBlock = new textBlock_1.TextBlock();
  9661. this._tooltipTextBlock.scaleY = 3;
  9662. this._tooltipTextBlock.color = "white";
  9663. this._tooltipTextBlock.fontSize = 130;
  9664. this._tooltipTexture.addControl(this._tooltipTextBlock);
  9665. // Add hover action to tooltip
  9666. this._tooltipFade = new BABYLON.FadeInOutBehavior();
  9667. this._tooltipFade.delay = 500;
  9668. this._tooltipMesh.addBehavior(this._tooltipFade);
  9669. this._tooltipHoverObserver = this.onPointerEnterObservable.add(function () {
  9670. if (_this._tooltipFade) {
  9671. _this._tooltipFade.fadeIn(true);
  9672. }
  9673. });
  9674. this._tooltipOutObserver = this.onPointerOutObservable.add(function () {
  9675. if (_this._tooltipFade) {
  9676. _this._tooltipFade.fadeIn(false);
  9677. }
  9678. });
  9679. }
  9680. if (this._tooltipTextBlock) {
  9681. this._tooltipTextBlock.text = text;
  9682. }
  9683. },
  9684. enumerable: true,
  9685. configurable: true
  9686. });
  9687. Object.defineProperty(HolographicButton.prototype, "text", {
  9688. /**
  9689. * Gets or sets text for the button
  9690. */
  9691. get: function () {
  9692. return this._text;
  9693. },
  9694. set: function (value) {
  9695. if (this._text === value) {
  9696. return;
  9697. }
  9698. this._text = value;
  9699. this._rebuildContent();
  9700. },
  9701. enumerable: true,
  9702. configurable: true
  9703. });
  9704. Object.defineProperty(HolographicButton.prototype, "imageUrl", {
  9705. /**
  9706. * Gets or sets the image url for the button
  9707. */
  9708. get: function () {
  9709. return this._imageUrl;
  9710. },
  9711. set: function (value) {
  9712. if (this._imageUrl === value) {
  9713. return;
  9714. }
  9715. this._imageUrl = value;
  9716. this._rebuildContent();
  9717. },
  9718. enumerable: true,
  9719. configurable: true
  9720. });
  9721. Object.defineProperty(HolographicButton.prototype, "backMaterial", {
  9722. /**
  9723. * Gets the back material used by this button
  9724. */
  9725. get: function () {
  9726. return this._backMaterial;
  9727. },
  9728. enumerable: true,
  9729. configurable: true
  9730. });
  9731. Object.defineProperty(HolographicButton.prototype, "frontMaterial", {
  9732. /**
  9733. * Gets the front material used by this button
  9734. */
  9735. get: function () {
  9736. return this._frontMaterial;
  9737. },
  9738. enumerable: true,
  9739. configurable: true
  9740. });
  9741. Object.defineProperty(HolographicButton.prototype, "plateMaterial", {
  9742. /**
  9743. * Gets the plate material used by this button
  9744. */
  9745. get: function () {
  9746. return this._plateMaterial;
  9747. },
  9748. enumerable: true,
  9749. configurable: true
  9750. });
  9751. Object.defineProperty(HolographicButton.prototype, "shareMaterials", {
  9752. /**
  9753. * Gets a boolean indicating if this button shares its material with other HolographicButtons
  9754. */
  9755. get: function () {
  9756. return this._shareMaterials;
  9757. },
  9758. enumerable: true,
  9759. configurable: true
  9760. });
  9761. HolographicButton.prototype._getTypeName = function () {
  9762. return "HolographicButton";
  9763. };
  9764. HolographicButton.prototype._rebuildContent = function () {
  9765. this._disposeFacadeTexture();
  9766. var panel = new stackPanel_1.StackPanel();
  9767. panel.isVertical = true;
  9768. if (this._imageUrl) {
  9769. var image = new image_1.Image();
  9770. image.source = this._imageUrl;
  9771. image.paddingTop = "40px";
  9772. image.height = "180px";
  9773. image.width = "100px";
  9774. image.paddingBottom = "40px";
  9775. panel.addControl(image);
  9776. }
  9777. if (this._text) {
  9778. var text = new textBlock_1.TextBlock();
  9779. text.text = this._text;
  9780. text.color = "white";
  9781. text.height = "30px";
  9782. text.fontSize = 24;
  9783. panel.addControl(text);
  9784. }
  9785. if (this._frontPlate) {
  9786. this.content = panel;
  9787. }
  9788. };
  9789. // Mesh association
  9790. HolographicButton.prototype._createNode = function (scene) {
  9791. this._backPlate = babylonjs_1.MeshBuilder.CreateBox(this.name + "BackMesh", {
  9792. width: 1.0,
  9793. height: 1.0,
  9794. depth: 0.08
  9795. }, scene);
  9796. this._frontPlate = babylonjs_1.MeshBuilder.CreateBox(this.name + "FrontMesh", {
  9797. width: 1.0,
  9798. height: 1.0,
  9799. depth: 0.08
  9800. }, scene);
  9801. this._frontPlate.parent = this._backPlate;
  9802. this._frontPlate.position.z = -0.08;
  9803. this._frontPlate.isPickable = false;
  9804. this._frontPlate.setEnabled(false);
  9805. this._textPlate = _super.prototype._createNode.call(this, scene);
  9806. this._textPlate.parent = this._backPlate;
  9807. this._textPlate.position.z = -0.08;
  9808. this._textPlate.isPickable = false;
  9809. return this._backPlate;
  9810. };
  9811. HolographicButton.prototype._applyFacade = function (facadeTexture) {
  9812. this._plateMaterial.emissiveTexture = facadeTexture;
  9813. this._plateMaterial.opacityTexture = facadeTexture;
  9814. };
  9815. HolographicButton.prototype._createBackMaterial = function (mesh) {
  9816. var _this = this;
  9817. this._backMaterial = new fluentMaterial_1.FluentMaterial(this.name + "Back Material", mesh.getScene());
  9818. this._backMaterial.renderHoverLight = true;
  9819. this._pickedPointObserver = this._host.onPickedPointChangedObservable.add(function (pickedPoint) {
  9820. if (pickedPoint) {
  9821. _this._backMaterial.hoverPosition = pickedPoint;
  9822. _this._backMaterial.hoverColor.a = 1.0;
  9823. }
  9824. else {
  9825. _this._backMaterial.hoverColor.a = 0;
  9826. }
  9827. });
  9828. };
  9829. HolographicButton.prototype._createFrontMaterial = function (mesh) {
  9830. this._frontMaterial = new fluentMaterial_1.FluentMaterial(this.name + "Front Material", mesh.getScene());
  9831. this._frontMaterial.innerGlowColorIntensity = 0; // No inner glow
  9832. this._frontMaterial.alpha = 0.5; // Additive
  9833. this._frontMaterial.renderBorders = true;
  9834. };
  9835. HolographicButton.prototype._createPlateMaterial = function (mesh) {
  9836. this._plateMaterial = new babylonjs_1.StandardMaterial(this.name + "Plate Material", mesh.getScene());
  9837. this._plateMaterial.specularColor = babylonjs_1.Color3.Black();
  9838. };
  9839. HolographicButton.prototype._affectMaterial = function (mesh) {
  9840. // Back
  9841. if (this._shareMaterials) {
  9842. if (!this._host._sharedMaterials["backFluentMaterial"]) {
  9843. this._createBackMaterial(mesh);
  9844. this._host._sharedMaterials["backFluentMaterial"] = this._backMaterial;
  9845. }
  9846. else {
  9847. this._backMaterial = this._host._sharedMaterials["backFluentMaterial"];
  9848. }
  9849. // Front
  9850. if (!this._host._sharedMaterials["frontFluentMaterial"]) {
  9851. this._createFrontMaterial(mesh);
  9852. this._host._sharedMaterials["frontFluentMaterial"] = this._frontMaterial;
  9853. }
  9854. else {
  9855. this._frontMaterial = this._host._sharedMaterials["frontFluentMaterial"];
  9856. }
  9857. }
  9858. else {
  9859. this._createBackMaterial(mesh);
  9860. this._createFrontMaterial(mesh);
  9861. }
  9862. this._createPlateMaterial(mesh);
  9863. this._backPlate.material = this._backMaterial;
  9864. this._frontPlate.material = this._frontMaterial;
  9865. this._textPlate.material = this._plateMaterial;
  9866. this._rebuildContent();
  9867. };
  9868. /**
  9869. * Releases all associated resources
  9870. */
  9871. HolographicButton.prototype.dispose = function () {
  9872. _super.prototype.dispose.call(this); // will dispose main mesh ie. back plate
  9873. this._disposeTooltip();
  9874. if (!this.shareMaterials) {
  9875. this._backMaterial.dispose();
  9876. this._frontMaterial.dispose();
  9877. this._plateMaterial.dispose();
  9878. if (this._pickedPointObserver) {
  9879. this._host.onPickedPointChangedObservable.remove(this._pickedPointObserver);
  9880. this._pickedPointObserver = null;
  9881. }
  9882. }
  9883. };
  9884. return HolographicButton;
  9885. }(button3D_1.Button3D));
  9886. exports.HolographicButton = HolographicButton;
  9887. /***/ }),
  9888. /***/ "./src/3D/controls/index.ts":
  9889. /*!**********************************!*\
  9890. !*** ./src/3D/controls/index.ts ***!
  9891. \**********************************/
  9892. /*! no static exports found */
  9893. /***/ (function(module, exports, __webpack_require__) {
  9894. "use strict";
  9895. function __export(m) {
  9896. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  9897. }
  9898. Object.defineProperty(exports, "__esModule", { value: true });
  9899. __export(__webpack_require__(/*! ./abstractButton3D */ "./src/3D/controls/abstractButton3D.ts"));
  9900. __export(__webpack_require__(/*! ./button3D */ "./src/3D/controls/button3D.ts"));
  9901. __export(__webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts"));
  9902. __export(__webpack_require__(/*! ./control3D */ "./src/3D/controls/control3D.ts"));
  9903. __export(__webpack_require__(/*! ./cylinderPanel */ "./src/3D/controls/cylinderPanel.ts"));
  9904. __export(__webpack_require__(/*! ./holographicButton */ "./src/3D/controls/holographicButton.ts"));
  9905. __export(__webpack_require__(/*! ./meshButton3D */ "./src/3D/controls/meshButton3D.ts"));
  9906. __export(__webpack_require__(/*! ./planePanel */ "./src/3D/controls/planePanel.ts"));
  9907. __export(__webpack_require__(/*! ./scatterPanel */ "./src/3D/controls/scatterPanel.ts"));
  9908. __export(__webpack_require__(/*! ./spherePanel */ "./src/3D/controls/spherePanel.ts"));
  9909. __export(__webpack_require__(/*! ./stackPanel3D */ "./src/3D/controls/stackPanel3D.ts"));
  9910. __export(__webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts"));
  9911. /***/ }),
  9912. /***/ "./src/3D/controls/meshButton3D.ts":
  9913. /*!*****************************************!*\
  9914. !*** ./src/3D/controls/meshButton3D.ts ***!
  9915. \*****************************************/
  9916. /*! no static exports found */
  9917. /***/ (function(module, exports, __webpack_require__) {
  9918. "use strict";
  9919. var __extends = (this && this.__extends) || (function () {
  9920. var extendStatics = function (d, b) {
  9921. extendStatics = Object.setPrototypeOf ||
  9922. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9923. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  9924. return extendStatics(d, b);
  9925. }
  9926. return function (d, b) {
  9927. extendStatics(d, b);
  9928. function __() { this.constructor = d; }
  9929. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9930. };
  9931. })();
  9932. Object.defineProperty(exports, "__esModule", { value: true });
  9933. var button3D_1 = __webpack_require__(/*! ./button3D */ "./src/3D/controls/button3D.ts");
  9934. /**
  9935. * Class used to create an interactable object. It's a 3D button using a mesh coming from the current scene
  9936. */
  9937. var MeshButton3D = /** @class */ (function (_super) {
  9938. __extends(MeshButton3D, _super);
  9939. /**
  9940. * Creates a new 3D button based on a mesh
  9941. * @param mesh mesh to become a 3D button
  9942. * @param name defines the control name
  9943. */
  9944. function MeshButton3D(mesh, name) {
  9945. var _this = _super.call(this, name) || this;
  9946. _this._currentMesh = mesh;
  9947. /**
  9948. * Provides a default behavior on hover/out & up/down
  9949. * Override those function to create your own desired behavior specific to your mesh
  9950. */
  9951. _this.pointerEnterAnimation = function () {
  9952. if (!_this.mesh) {
  9953. return;
  9954. }
  9955. _this.mesh.scaling.scaleInPlace(1.1);
  9956. };
  9957. _this.pointerOutAnimation = function () {
  9958. if (!_this.mesh) {
  9959. return;
  9960. }
  9961. _this.mesh.scaling.scaleInPlace(1.0 / 1.1);
  9962. };
  9963. _this.pointerDownAnimation = function () {
  9964. if (!_this.mesh) {
  9965. return;
  9966. }
  9967. _this.mesh.scaling.scaleInPlace(0.95);
  9968. };
  9969. _this.pointerUpAnimation = function () {
  9970. if (!_this.mesh) {
  9971. return;
  9972. }
  9973. _this.mesh.scaling.scaleInPlace(1.0 / 0.95);
  9974. };
  9975. return _this;
  9976. }
  9977. MeshButton3D.prototype._getTypeName = function () {
  9978. return "MeshButton3D";
  9979. };
  9980. // Mesh association
  9981. MeshButton3D.prototype._createNode = function (scene) {
  9982. var _this = this;
  9983. this._currentMesh.getChildMeshes().forEach(function (mesh) {
  9984. mesh.metadata = _this;
  9985. });
  9986. return this._currentMesh;
  9987. };
  9988. MeshButton3D.prototype._affectMaterial = function (mesh) {
  9989. };
  9990. return MeshButton3D;
  9991. }(button3D_1.Button3D));
  9992. exports.MeshButton3D = MeshButton3D;
  9993. /***/ }),
  9994. /***/ "./src/3D/controls/planePanel.ts":
  9995. /*!***************************************!*\
  9996. !*** ./src/3D/controls/planePanel.ts ***!
  9997. \***************************************/
  9998. /*! no static exports found */
  9999. /***/ (function(module, exports, __webpack_require__) {
  10000. "use strict";
  10001. var __extends = (this && this.__extends) || (function () {
  10002. var extendStatics = function (d, b) {
  10003. extendStatics = Object.setPrototypeOf ||
  10004. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10005. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10006. return extendStatics(d, b);
  10007. }
  10008. return function (d, b) {
  10009. extendStatics(d, b);
  10010. function __() { this.constructor = d; }
  10011. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10012. };
  10013. })();
  10014. Object.defineProperty(exports, "__esModule", { value: true });
  10015. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10016. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10017. var volumeBasedPanel_1 = __webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts");
  10018. /**
  10019. * Class used to create a container panel deployed on the surface of a plane
  10020. */
  10021. var PlanePanel = /** @class */ (function (_super) {
  10022. __extends(PlanePanel, _super);
  10023. function PlanePanel() {
  10024. return _super !== null && _super.apply(this, arguments) || this;
  10025. }
  10026. PlanePanel.prototype._mapGridNode = function (control, nodePosition) {
  10027. var mesh = control.mesh;
  10028. if (!mesh) {
  10029. return;
  10030. }
  10031. control.position = nodePosition.clone();
  10032. var target = babylonjs_1.Tmp.Vector3[0];
  10033. target.copyFrom(nodePosition);
  10034. switch (this.orientation) {
  10035. case container3D_1.Container3D.FACEORIGIN_ORIENTATION:
  10036. case container3D_1.Container3D.FACEFORWARD_ORIENTATION:
  10037. target.addInPlace(new BABYLON.Vector3(0, 0, -1));
  10038. mesh.lookAt(target);
  10039. break;
  10040. case container3D_1.Container3D.FACEFORWARDREVERSED_ORIENTATION:
  10041. case container3D_1.Container3D.FACEORIGINREVERSED_ORIENTATION:
  10042. target.addInPlace(new BABYLON.Vector3(0, 0, 1));
  10043. mesh.lookAt(target);
  10044. break;
  10045. }
  10046. };
  10047. return PlanePanel;
  10048. }(volumeBasedPanel_1.VolumeBasedPanel));
  10049. exports.PlanePanel = PlanePanel;
  10050. /***/ }),
  10051. /***/ "./src/3D/controls/scatterPanel.ts":
  10052. /*!*****************************************!*\
  10053. !*** ./src/3D/controls/scatterPanel.ts ***!
  10054. \*****************************************/
  10055. /*! no static exports found */
  10056. /***/ (function(module, exports, __webpack_require__) {
  10057. "use strict";
  10058. var __extends = (this && this.__extends) || (function () {
  10059. var extendStatics = function (d, b) {
  10060. extendStatics = Object.setPrototypeOf ||
  10061. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10062. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10063. return extendStatics(d, b);
  10064. }
  10065. return function (d, b) {
  10066. extendStatics(d, b);
  10067. function __() { this.constructor = d; }
  10068. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10069. };
  10070. })();
  10071. Object.defineProperty(exports, "__esModule", { value: true });
  10072. var volumeBasedPanel_1 = __webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts");
  10073. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10074. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10075. /**
  10076. * Class used to create a container panel where items get randomized planar mapping
  10077. */
  10078. var ScatterPanel = /** @class */ (function (_super) {
  10079. __extends(ScatterPanel, _super);
  10080. function ScatterPanel() {
  10081. var _this = _super !== null && _super.apply(this, arguments) || this;
  10082. _this._iteration = 100.0;
  10083. return _this;
  10084. }
  10085. Object.defineProperty(ScatterPanel.prototype, "iteration", {
  10086. /**
  10087. * Gets or sets the number of iteration to use to scatter the controls (100 by default)
  10088. */
  10089. get: function () {
  10090. return this._iteration;
  10091. },
  10092. set: function (value) {
  10093. var _this = this;
  10094. if (this._iteration === value) {
  10095. return;
  10096. }
  10097. this._iteration = value;
  10098. babylonjs_1.Tools.SetImmediate(function () {
  10099. _this._arrangeChildren();
  10100. });
  10101. },
  10102. enumerable: true,
  10103. configurable: true
  10104. });
  10105. ScatterPanel.prototype._mapGridNode = function (control, nodePosition) {
  10106. var mesh = control.mesh;
  10107. var newPos = this._scatterMapping(nodePosition);
  10108. if (!mesh) {
  10109. return;
  10110. }
  10111. switch (this.orientation) {
  10112. case container3D_1.Container3D.FACEORIGIN_ORIENTATION:
  10113. case container3D_1.Container3D.FACEFORWARD_ORIENTATION:
  10114. mesh.lookAt(new babylonjs_1.Vector3(0, 0, -1));
  10115. break;
  10116. case container3D_1.Container3D.FACEFORWARDREVERSED_ORIENTATION:
  10117. case container3D_1.Container3D.FACEORIGINREVERSED_ORIENTATION:
  10118. mesh.lookAt(new babylonjs_1.Vector3(0, 0, 1));
  10119. break;
  10120. }
  10121. control.position = newPos;
  10122. };
  10123. ScatterPanel.prototype._scatterMapping = function (source) {
  10124. source.x = (1.0 - Math.random() * 2.0) * this._cellWidth;
  10125. source.y = (1.0 - Math.random() * 2.0) * this._cellHeight;
  10126. return source;
  10127. };
  10128. ScatterPanel.prototype._finalProcessing = function () {
  10129. var meshes = [];
  10130. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  10131. var child = _a[_i];
  10132. if (!child.mesh) {
  10133. continue;
  10134. }
  10135. meshes.push(child.mesh);
  10136. }
  10137. for (var count = 0; count < this._iteration; count++) {
  10138. meshes.sort(function (a, b) {
  10139. var distance1 = a.position.lengthSquared();
  10140. var distance2 = b.position.lengthSquared();
  10141. if (distance1 < distance2) {
  10142. return 1;
  10143. }
  10144. else if (distance1 > distance2) {
  10145. return -1;
  10146. }
  10147. return 0;
  10148. });
  10149. var radiusPaddingSquared = Math.pow(this.margin, 2.0);
  10150. var cellSize = Math.max(this._cellWidth, this._cellHeight);
  10151. var difference2D = babylonjs_1.Tmp.Vector2[0];
  10152. var difference = babylonjs_1.Tmp.Vector3[0];
  10153. for (var i = 0; i < meshes.length - 1; i++) {
  10154. for (var j = i + 1; j < meshes.length; j++) {
  10155. if (i != j) {
  10156. meshes[j].position.subtractToRef(meshes[i].position, difference);
  10157. // Ignore Z axis
  10158. difference2D.x = difference.x;
  10159. difference2D.y = difference.y;
  10160. var combinedRadius = cellSize;
  10161. var distance = difference2D.lengthSquared() - radiusPaddingSquared;
  10162. var minSeparation = Math.min(distance, radiusPaddingSquared);
  10163. distance -= minSeparation;
  10164. if (distance < (Math.pow(combinedRadius, 2.0))) {
  10165. difference2D.normalize();
  10166. difference.scaleInPlace((combinedRadius - Math.sqrt(distance)) * 0.5);
  10167. meshes[j].position.addInPlace(difference);
  10168. meshes[i].position.subtractInPlace(difference);
  10169. }
  10170. }
  10171. }
  10172. }
  10173. }
  10174. };
  10175. return ScatterPanel;
  10176. }(volumeBasedPanel_1.VolumeBasedPanel));
  10177. exports.ScatterPanel = ScatterPanel;
  10178. /***/ }),
  10179. /***/ "./src/3D/controls/spherePanel.ts":
  10180. /*!****************************************!*\
  10181. !*** ./src/3D/controls/spherePanel.ts ***!
  10182. \****************************************/
  10183. /*! no static exports found */
  10184. /***/ (function(module, exports, __webpack_require__) {
  10185. "use strict";
  10186. var __extends = (this && this.__extends) || (function () {
  10187. var extendStatics = function (d, b) {
  10188. extendStatics = Object.setPrototypeOf ||
  10189. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10190. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10191. return extendStatics(d, b);
  10192. }
  10193. return function (d, b) {
  10194. extendStatics(d, b);
  10195. function __() { this.constructor = d; }
  10196. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10197. };
  10198. })();
  10199. Object.defineProperty(exports, "__esModule", { value: true });
  10200. var volumeBasedPanel_1 = __webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts");
  10201. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10202. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10203. /**
  10204. * Class used to create a container panel deployed on the surface of a sphere
  10205. */
  10206. var SpherePanel = /** @class */ (function (_super) {
  10207. __extends(SpherePanel, _super);
  10208. function SpherePanel() {
  10209. var _this = _super !== null && _super.apply(this, arguments) || this;
  10210. _this._radius = 5.0;
  10211. return _this;
  10212. }
  10213. Object.defineProperty(SpherePanel.prototype, "radius", {
  10214. /**
  10215. * Gets or sets the radius of the sphere where to project controls (5 by default)
  10216. */
  10217. get: function () {
  10218. return this._radius;
  10219. },
  10220. set: function (value) {
  10221. var _this = this;
  10222. if (this._radius === value) {
  10223. return;
  10224. }
  10225. this._radius = value;
  10226. babylonjs_1.Tools.SetImmediate(function () {
  10227. _this._arrangeChildren();
  10228. });
  10229. },
  10230. enumerable: true,
  10231. configurable: true
  10232. });
  10233. SpherePanel.prototype._mapGridNode = function (control, nodePosition) {
  10234. var mesh = control.mesh;
  10235. if (!mesh) {
  10236. return;
  10237. }
  10238. var newPos = this._sphericalMapping(nodePosition);
  10239. control.position = newPos;
  10240. switch (this.orientation) {
  10241. case container3D_1.Container3D.FACEORIGIN_ORIENTATION:
  10242. mesh.lookAt(new BABYLON.Vector3(-newPos.x, -newPos.y, -newPos.z));
  10243. break;
  10244. case container3D_1.Container3D.FACEORIGINREVERSED_ORIENTATION:
  10245. mesh.lookAt(new BABYLON.Vector3(2 * newPos.x, 2 * newPos.y, 2 * newPos.z));
  10246. break;
  10247. case container3D_1.Container3D.FACEFORWARD_ORIENTATION:
  10248. break;
  10249. case container3D_1.Container3D.FACEFORWARDREVERSED_ORIENTATION:
  10250. mesh.rotate(BABYLON.Axis.Y, Math.PI, BABYLON.Space.LOCAL);
  10251. break;
  10252. }
  10253. };
  10254. SpherePanel.prototype._sphericalMapping = function (source) {
  10255. var newPos = new babylonjs_1.Vector3(0, 0, this._radius);
  10256. var xAngle = (source.y / this._radius);
  10257. var yAngle = -(source.x / this._radius);
  10258. babylonjs_1.Matrix.RotationYawPitchRollToRef(yAngle, xAngle, 0, babylonjs_1.Tmp.Matrix[0]);
  10259. return babylonjs_1.Vector3.TransformNormal(newPos, babylonjs_1.Tmp.Matrix[0]);
  10260. };
  10261. return SpherePanel;
  10262. }(volumeBasedPanel_1.VolumeBasedPanel));
  10263. exports.SpherePanel = SpherePanel;
  10264. /***/ }),
  10265. /***/ "./src/3D/controls/stackPanel3D.ts":
  10266. /*!*****************************************!*\
  10267. !*** ./src/3D/controls/stackPanel3D.ts ***!
  10268. \*****************************************/
  10269. /*! no static exports found */
  10270. /***/ (function(module, exports, __webpack_require__) {
  10271. "use strict";
  10272. var __extends = (this && this.__extends) || (function () {
  10273. var extendStatics = function (d, b) {
  10274. extendStatics = Object.setPrototypeOf ||
  10275. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10276. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10277. return extendStatics(d, b);
  10278. }
  10279. return function (d, b) {
  10280. extendStatics(d, b);
  10281. function __() { this.constructor = d; }
  10282. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10283. };
  10284. })();
  10285. Object.defineProperty(exports, "__esModule", { value: true });
  10286. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10287. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10288. /**
  10289. * Class used to create a stack panel in 3D on XY plane
  10290. */
  10291. var StackPanel3D = /** @class */ (function (_super) {
  10292. __extends(StackPanel3D, _super);
  10293. /**
  10294. * Creates new StackPanel
  10295. * @param isVertical
  10296. */
  10297. function StackPanel3D(isVertical) {
  10298. if (isVertical === void 0) { isVertical = false; }
  10299. var _this = _super.call(this) || this;
  10300. _this._isVertical = false;
  10301. /**
  10302. * Gets or sets the distance between elements
  10303. */
  10304. _this.margin = 0.1;
  10305. _this._isVertical = isVertical;
  10306. return _this;
  10307. }
  10308. Object.defineProperty(StackPanel3D.prototype, "isVertical", {
  10309. /**
  10310. * Gets or sets a boolean indicating if the stack panel is vertical or horizontal (horizontal by default)
  10311. */
  10312. get: function () {
  10313. return this._isVertical;
  10314. },
  10315. set: function (value) {
  10316. var _this = this;
  10317. if (this._isVertical === value) {
  10318. return;
  10319. }
  10320. this._isVertical = value;
  10321. babylonjs_1.Tools.SetImmediate(function () {
  10322. _this._arrangeChildren();
  10323. });
  10324. },
  10325. enumerable: true,
  10326. configurable: true
  10327. });
  10328. StackPanel3D.prototype._arrangeChildren = function () {
  10329. var width = 0;
  10330. var height = 0;
  10331. var controlCount = 0;
  10332. var extendSizes = [];
  10333. var currentInverseWorld = babylonjs_1.Matrix.Invert(this.node.computeWorldMatrix(true));
  10334. // Measure
  10335. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  10336. var child = _a[_i];
  10337. if (!child.mesh) {
  10338. continue;
  10339. }
  10340. controlCount++;
  10341. child.mesh.computeWorldMatrix(true);
  10342. child.mesh.getWorldMatrix().multiplyToRef(currentInverseWorld, babylonjs_1.Tmp.Matrix[0]);
  10343. var boundingBox = child.mesh.getBoundingInfo().boundingBox;
  10344. var extendSize = babylonjs_1.Vector3.TransformNormal(boundingBox.extendSize, babylonjs_1.Tmp.Matrix[0]);
  10345. extendSizes.push(extendSize);
  10346. if (this._isVertical) {
  10347. height += extendSize.y;
  10348. }
  10349. else {
  10350. width += extendSize.x;
  10351. }
  10352. }
  10353. if (this._isVertical) {
  10354. height += (controlCount - 1) * this.margin / 2;
  10355. }
  10356. else {
  10357. width += (controlCount - 1) * this.margin / 2;
  10358. }
  10359. // Arrange
  10360. var offset;
  10361. if (this._isVertical) {
  10362. offset = -height;
  10363. }
  10364. else {
  10365. offset = -width;
  10366. }
  10367. var index = 0;
  10368. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  10369. var child = _c[_b];
  10370. if (!child.mesh) {
  10371. continue;
  10372. }
  10373. controlCount--;
  10374. var extendSize = extendSizes[index++];
  10375. if (this._isVertical) {
  10376. child.position.y = offset + extendSize.y;
  10377. child.position.x = 0;
  10378. offset += extendSize.y * 2;
  10379. }
  10380. else {
  10381. child.position.x = offset + extendSize.x;
  10382. child.position.y = 0;
  10383. offset += extendSize.x * 2;
  10384. }
  10385. offset += (controlCount > 0 ? this.margin : 0);
  10386. }
  10387. };
  10388. return StackPanel3D;
  10389. }(container3D_1.Container3D));
  10390. exports.StackPanel3D = StackPanel3D;
  10391. /***/ }),
  10392. /***/ "./src/3D/controls/volumeBasedPanel.ts":
  10393. /*!*********************************************!*\
  10394. !*** ./src/3D/controls/volumeBasedPanel.ts ***!
  10395. \*********************************************/
  10396. /*! no static exports found */
  10397. /***/ (function(module, exports, __webpack_require__) {
  10398. "use strict";
  10399. var __extends = (this && this.__extends) || (function () {
  10400. var extendStatics = function (d, b) {
  10401. extendStatics = Object.setPrototypeOf ||
  10402. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10403. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10404. return extendStatics(d, b);
  10405. }
  10406. return function (d, b) {
  10407. extendStatics(d, b);
  10408. function __() { this.constructor = d; }
  10409. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10410. };
  10411. })();
  10412. Object.defineProperty(exports, "__esModule", { value: true });
  10413. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10414. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10415. /**
  10416. * Abstract class used to create a container panel deployed on the surface of a volume
  10417. */
  10418. var VolumeBasedPanel = /** @class */ (function (_super) {
  10419. __extends(VolumeBasedPanel, _super);
  10420. /**
  10421. * Creates new VolumeBasedPanel
  10422. */
  10423. function VolumeBasedPanel() {
  10424. var _this = _super.call(this) || this;
  10425. _this._columns = 10;
  10426. _this._rows = 0;
  10427. _this._rowThenColum = true;
  10428. _this._orientation = container3D_1.Container3D.FACEORIGIN_ORIENTATION;
  10429. /**
  10430. * Gets or sets the distance between elements
  10431. */
  10432. _this.margin = 0;
  10433. return _this;
  10434. }
  10435. Object.defineProperty(VolumeBasedPanel.prototype, "orientation", {
  10436. /**
  10437. * Gets or sets the orientation to apply to all controls (BABYLON.Container3D.FaceOriginReversedOrientation by default)
  10438. * | Value | Type | Description |
  10439. * | ----- | ----------------------------------- | ----------- |
  10440. * | 0 | UNSET_ORIENTATION | Control rotation will remain unchanged |
  10441. * | 1 | FACEORIGIN_ORIENTATION | Control will rotate to make it look at sphere central axis |
  10442. * | 2 | FACEORIGINREVERSED_ORIENTATION | Control will rotate to make it look back at sphere central axis |
  10443. * | 3 | FACEFORWARD_ORIENTATION | Control will rotate to look at z axis (0, 0, 1) |
  10444. * | 4 | FACEFORWARDREVERSED_ORIENTATION | Control will rotate to look at negative z axis (0, 0, -1) |
  10445. */
  10446. get: function () {
  10447. return this._orientation;
  10448. },
  10449. set: function (value) {
  10450. var _this = this;
  10451. if (this._orientation === value) {
  10452. return;
  10453. }
  10454. this._orientation = value;
  10455. babylonjs_1.Tools.SetImmediate(function () {
  10456. _this._arrangeChildren();
  10457. });
  10458. },
  10459. enumerable: true,
  10460. configurable: true
  10461. });
  10462. Object.defineProperty(VolumeBasedPanel.prototype, "columns", {
  10463. /**
  10464. * Gets or sets the number of columns requested (10 by default).
  10465. * The panel will automatically compute the number of rows based on number of child controls.
  10466. */
  10467. get: function () {
  10468. return this._columns;
  10469. },
  10470. set: function (value) {
  10471. var _this = this;
  10472. if (this._columns === value) {
  10473. return;
  10474. }
  10475. this._columns = value;
  10476. this._rowThenColum = true;
  10477. babylonjs_1.Tools.SetImmediate(function () {
  10478. _this._arrangeChildren();
  10479. });
  10480. },
  10481. enumerable: true,
  10482. configurable: true
  10483. });
  10484. Object.defineProperty(VolumeBasedPanel.prototype, "rows", {
  10485. /**
  10486. * Gets or sets a the number of rows requested.
  10487. * The panel will automatically compute the number of columns based on number of child controls.
  10488. */
  10489. get: function () {
  10490. return this._rows;
  10491. },
  10492. set: function (value) {
  10493. var _this = this;
  10494. if (this._rows === value) {
  10495. return;
  10496. }
  10497. this._rows = value;
  10498. this._rowThenColum = false;
  10499. babylonjs_1.Tools.SetImmediate(function () {
  10500. _this._arrangeChildren();
  10501. });
  10502. },
  10503. enumerable: true,
  10504. configurable: true
  10505. });
  10506. VolumeBasedPanel.prototype._arrangeChildren = function () {
  10507. this._cellWidth = 0;
  10508. this._cellHeight = 0;
  10509. var rows = 0;
  10510. var columns = 0;
  10511. var controlCount = 0;
  10512. var currentInverseWorld = babylonjs_1.Matrix.Invert(this.node.computeWorldMatrix(true));
  10513. // Measure
  10514. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  10515. var child = _a[_i];
  10516. if (!child.mesh) {
  10517. continue;
  10518. }
  10519. controlCount++;
  10520. child.mesh.computeWorldMatrix(true);
  10521. // child.mesh.getWorldMatrix().multiplyToRef(currentInverseWorld, Tmp.Matrix[0]);
  10522. var boundingBox = child.mesh.getHierarchyBoundingVectors();
  10523. var extendSize = babylonjs_1.Tmp.Vector3[0];
  10524. var diff = babylonjs_1.Tmp.Vector3[1];
  10525. boundingBox.max.subtractToRef(boundingBox.min, diff);
  10526. diff.scaleInPlace(0.5);
  10527. babylonjs_1.Vector3.TransformNormalToRef(diff, currentInverseWorld, extendSize);
  10528. this._cellWidth = Math.max(this._cellWidth, extendSize.x * 2);
  10529. this._cellHeight = Math.max(this._cellHeight, extendSize.y * 2);
  10530. }
  10531. this._cellWidth += this.margin * 2;
  10532. this._cellHeight += this.margin * 2;
  10533. // Arrange
  10534. if (this._rowThenColum) {
  10535. columns = this._columns;
  10536. rows = Math.ceil(controlCount / this._columns);
  10537. }
  10538. else {
  10539. rows = this._rows;
  10540. columns = Math.ceil(controlCount / this._rows);
  10541. }
  10542. var startOffsetX = (columns * 0.5) * this._cellWidth;
  10543. var startOffsetY = (rows * 0.5) * this._cellHeight;
  10544. var nodeGrid = [];
  10545. var cellCounter = 0;
  10546. if (this._rowThenColum) {
  10547. for (var r = 0; r < rows; r++) {
  10548. for (var c = 0; c < columns; c++) {
  10549. nodeGrid.push(new babylonjs_1.Vector3((c * this._cellWidth) - startOffsetX + this._cellWidth / 2, (r * this._cellHeight) - startOffsetY + this._cellHeight / 2, 0));
  10550. cellCounter++;
  10551. if (cellCounter > controlCount) {
  10552. break;
  10553. }
  10554. }
  10555. }
  10556. }
  10557. else {
  10558. for (var c = 0; c < columns; c++) {
  10559. for (var r = 0; r < rows; r++) {
  10560. nodeGrid.push(new babylonjs_1.Vector3((c * this._cellWidth) - startOffsetX + this._cellWidth / 2, (r * this._cellHeight) - startOffsetY + this._cellHeight / 2, 0));
  10561. cellCounter++;
  10562. if (cellCounter > controlCount) {
  10563. break;
  10564. }
  10565. }
  10566. }
  10567. }
  10568. cellCounter = 0;
  10569. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  10570. var child = _c[_b];
  10571. if (!child.mesh) {
  10572. continue;
  10573. }
  10574. this._mapGridNode(child, nodeGrid[cellCounter]);
  10575. cellCounter++;
  10576. }
  10577. this._finalProcessing();
  10578. };
  10579. /** Child classes can implement this function to provide additional processing */
  10580. VolumeBasedPanel.prototype._finalProcessing = function () {
  10581. };
  10582. return VolumeBasedPanel;
  10583. }(container3D_1.Container3D));
  10584. exports.VolumeBasedPanel = VolumeBasedPanel;
  10585. /***/ }),
  10586. /***/ "./src/3D/gui3DManager.ts":
  10587. /*!********************************!*\
  10588. !*** ./src/3D/gui3DManager.ts ***!
  10589. \********************************/
  10590. /*! no static exports found */
  10591. /***/ (function(module, exports, __webpack_require__) {
  10592. "use strict";
  10593. Object.defineProperty(exports, "__esModule", { value: true });
  10594. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10595. var container3D_1 = __webpack_require__(/*! ./controls/container3D */ "./src/3D/controls/container3D.ts");
  10596. /**
  10597. * Class used to manage 3D user interface
  10598. * @see http://doc.babylonjs.com/how_to/gui3d
  10599. */
  10600. var GUI3DManager = /** @class */ (function () {
  10601. /**
  10602. * Creates a new GUI3DManager
  10603. * @param scene
  10604. */
  10605. function GUI3DManager(scene) {
  10606. var _this = this;
  10607. /** @hidden */
  10608. this._lastControlOver = {};
  10609. /** @hidden */
  10610. this._lastControlDown = {};
  10611. /**
  10612. * Observable raised when the point picked by the pointer events changed
  10613. */
  10614. this.onPickedPointChangedObservable = new babylonjs_1.Observable();
  10615. // Shared resources
  10616. /** @hidden */
  10617. this._sharedMaterials = {};
  10618. this._scene = scene || babylonjs_1.Engine.LastCreatedScene;
  10619. this._sceneDisposeObserver = this._scene.onDisposeObservable.add(function () {
  10620. _this._sceneDisposeObserver = null;
  10621. _this._utilityLayer = null;
  10622. _this.dispose();
  10623. });
  10624. this._utilityLayer = new babylonjs_1.UtilityLayerRenderer(this._scene);
  10625. this._utilityLayer.onlyCheckPointerDownEvents = false;
  10626. this._utilityLayer.mainSceneTrackerPredicate = function (mesh) {
  10627. return mesh && mesh.metadata && mesh.metadata._node;
  10628. };
  10629. // Root
  10630. this._rootContainer = new container3D_1.Container3D("RootContainer");
  10631. this._rootContainer._host = this;
  10632. var utilityLayerScene = this._utilityLayer.utilityLayerScene;
  10633. // Events
  10634. this._pointerOutObserver = this._utilityLayer.onPointerOutObservable.add(function (pointerId) {
  10635. _this._handlePointerOut(pointerId, true);
  10636. });
  10637. this._pointerObserver = utilityLayerScene.onPointerObservable.add(function (pi, state) {
  10638. _this._doPicking(pi);
  10639. });
  10640. // Scene
  10641. this._utilityLayer.utilityLayerScene.autoClear = false;
  10642. this._utilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
  10643. new babylonjs_1.HemisphericLight("hemi", babylonjs_1.Vector3.Up(), this._utilityLayer.utilityLayerScene);
  10644. }
  10645. Object.defineProperty(GUI3DManager.prototype, "scene", {
  10646. /** Gets the hosting scene */
  10647. get: function () {
  10648. return this._scene;
  10649. },
  10650. enumerable: true,
  10651. configurable: true
  10652. });
  10653. Object.defineProperty(GUI3DManager.prototype, "utilityLayer", {
  10654. /** Gets associated utility layer */
  10655. get: function () {
  10656. return this._utilityLayer;
  10657. },
  10658. enumerable: true,
  10659. configurable: true
  10660. });
  10661. GUI3DManager.prototype._handlePointerOut = function (pointerId, isPointerUp) {
  10662. var previousControlOver = this._lastControlOver[pointerId];
  10663. if (previousControlOver) {
  10664. previousControlOver._onPointerOut(previousControlOver);
  10665. delete this._lastControlOver[pointerId];
  10666. }
  10667. if (isPointerUp) {
  10668. if (this._lastControlDown[pointerId]) {
  10669. this._lastControlDown[pointerId].forcePointerUp();
  10670. delete this._lastControlDown[pointerId];
  10671. }
  10672. }
  10673. this.onPickedPointChangedObservable.notifyObservers(null);
  10674. };
  10675. GUI3DManager.prototype._doPicking = function (pi) {
  10676. if (!this._utilityLayer || !this._utilityLayer.utilityLayerScene.activeCamera) {
  10677. return false;
  10678. }
  10679. var pointerEvent = (pi.event);
  10680. var pointerId = pointerEvent.pointerId || 0;
  10681. var buttonIndex = pointerEvent.button;
  10682. var pickingInfo = pi.pickInfo;
  10683. if (!pickingInfo || !pickingInfo.hit) {
  10684. this._handlePointerOut(pointerId, pi.type === babylonjs_1.PointerEventTypes.POINTERUP);
  10685. return false;
  10686. }
  10687. var control = (pickingInfo.pickedMesh.metadata);
  10688. if (pickingInfo.pickedPoint) {
  10689. this.onPickedPointChangedObservable.notifyObservers(pickingInfo.pickedPoint);
  10690. }
  10691. if (!control._processObservables(pi.type, pickingInfo.pickedPoint, pointerId, buttonIndex)) {
  10692. if (pi.type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  10693. if (this._lastControlOver[pointerId]) {
  10694. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  10695. }
  10696. delete this._lastControlOver[pointerId];
  10697. }
  10698. }
  10699. if (pi.type === babylonjs_1.PointerEventTypes.POINTERUP) {
  10700. if (this._lastControlDown[pointerEvent.pointerId]) {
  10701. this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  10702. delete this._lastControlDown[pointerEvent.pointerId];
  10703. }
  10704. if (pointerEvent.pointerType === "touch") {
  10705. this._handlePointerOut(pointerId, false);
  10706. }
  10707. }
  10708. return true;
  10709. };
  10710. Object.defineProperty(GUI3DManager.prototype, "rootContainer", {
  10711. /**
  10712. * Gets the root container
  10713. */
  10714. get: function () {
  10715. return this._rootContainer;
  10716. },
  10717. enumerable: true,
  10718. configurable: true
  10719. });
  10720. /**
  10721. * Gets a boolean indicating if the given control is in the root child list
  10722. * @param control defines the control to check
  10723. * @returns true if the control is in the root child list
  10724. */
  10725. GUI3DManager.prototype.containsControl = function (control) {
  10726. return this._rootContainer.containsControl(control);
  10727. };
  10728. /**
  10729. * Adds a control to the root child list
  10730. * @param control defines the control to add
  10731. * @returns the current manager
  10732. */
  10733. GUI3DManager.prototype.addControl = function (control) {
  10734. this._rootContainer.addControl(control);
  10735. return this;
  10736. };
  10737. /**
  10738. * Removes a control from the root child list
  10739. * @param control defines the control to remove
  10740. * @returns the current container
  10741. */
  10742. GUI3DManager.prototype.removeControl = function (control) {
  10743. this._rootContainer.removeControl(control);
  10744. return this;
  10745. };
  10746. /**
  10747. * Releases all associated resources
  10748. */
  10749. GUI3DManager.prototype.dispose = function () {
  10750. this._rootContainer.dispose();
  10751. for (var materialName in this._sharedMaterials) {
  10752. if (!this._sharedMaterials.hasOwnProperty(materialName)) {
  10753. continue;
  10754. }
  10755. this._sharedMaterials[materialName].dispose();
  10756. }
  10757. this._sharedMaterials = {};
  10758. if (this._pointerOutObserver && this._utilityLayer) {
  10759. this._utilityLayer.onPointerOutObservable.remove(this._pointerOutObserver);
  10760. this._pointerOutObserver = null;
  10761. }
  10762. this.onPickedPointChangedObservable.clear();
  10763. var utilityLayerScene = this._utilityLayer ? this._utilityLayer.utilityLayerScene : null;
  10764. if (utilityLayerScene) {
  10765. if (this._pointerObserver) {
  10766. utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
  10767. this._pointerObserver = null;
  10768. }
  10769. }
  10770. if (this._scene) {
  10771. if (this._sceneDisposeObserver) {
  10772. this._scene.onDisposeObservable.remove(this._sceneDisposeObserver);
  10773. this._sceneDisposeObserver = null;
  10774. }
  10775. }
  10776. if (this._utilityLayer) {
  10777. this._utilityLayer.dispose();
  10778. }
  10779. };
  10780. return GUI3DManager;
  10781. }());
  10782. exports.GUI3DManager = GUI3DManager;
  10783. /***/ }),
  10784. /***/ "./src/3D/index.ts":
  10785. /*!*************************!*\
  10786. !*** ./src/3D/index.ts ***!
  10787. \*************************/
  10788. /*! no static exports found */
  10789. /***/ (function(module, exports, __webpack_require__) {
  10790. "use strict";
  10791. function __export(m) {
  10792. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  10793. }
  10794. Object.defineProperty(exports, "__esModule", { value: true });
  10795. __export(__webpack_require__(/*! ./controls */ "./src/3D/controls/index.ts"));
  10796. __export(__webpack_require__(/*! ./materials */ "./src/3D/materials/index.ts"));
  10797. __export(__webpack_require__(/*! ./gui3DManager */ "./src/3D/gui3DManager.ts"));
  10798. __export(__webpack_require__(/*! ./vector3WithInfo */ "./src/3D/vector3WithInfo.ts"));
  10799. /***/ }),
  10800. /***/ "./src/3D/materials/fluentMaterial.ts":
  10801. /*!********************************************!*\
  10802. !*** ./src/3D/materials/fluentMaterial.ts ***!
  10803. \********************************************/
  10804. /*! no static exports found */
  10805. /***/ (function(module, exports, __webpack_require__) {
  10806. "use strict";
  10807. var __extends = (this && this.__extends) || (function () {
  10808. var extendStatics = function (d, b) {
  10809. extendStatics = Object.setPrototypeOf ||
  10810. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10811. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10812. return extendStatics(d, b);
  10813. }
  10814. return function (d, b) {
  10815. extendStatics(d, b);
  10816. function __() { this.constructor = d; }
  10817. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10818. };
  10819. })();
  10820. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  10821. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  10822. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  10823. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  10824. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10825. };
  10826. Object.defineProperty(exports, "__esModule", { value: true });
  10827. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10828. var fluent_1 = __webpack_require__(/*! ./shaders/fluent */ "./src/3D/materials/shaders/fluent.ts");
  10829. // register shaders
  10830. fluent_1.registerShader();
  10831. /** @hidden */
  10832. var FluentMaterialDefines = /** @class */ (function (_super) {
  10833. __extends(FluentMaterialDefines, _super);
  10834. function FluentMaterialDefines() {
  10835. var _this = _super.call(this) || this;
  10836. _this.INNERGLOW = false;
  10837. _this.BORDER = false;
  10838. _this.HOVERLIGHT = false;
  10839. _this.TEXTURE = false;
  10840. _this.rebuild();
  10841. return _this;
  10842. }
  10843. return FluentMaterialDefines;
  10844. }(babylonjs_1.MaterialDefines));
  10845. exports.FluentMaterialDefines = FluentMaterialDefines;
  10846. /**
  10847. * Class used to render controls with fluent desgin
  10848. */
  10849. var FluentMaterial = /** @class */ (function (_super) {
  10850. __extends(FluentMaterial, _super);
  10851. /**
  10852. * Creates a new Fluent material
  10853. * @param name defines the name of the material
  10854. * @param scene defines the hosting scene
  10855. */
  10856. function FluentMaterial(name, scene) {
  10857. var _this = _super.call(this, name, scene) || this;
  10858. /**
  10859. * Gets or sets inner glow intensity. A value of 0 means no glow (default is 0.5)
  10860. */
  10861. _this.innerGlowColorIntensity = 0.5;
  10862. /**
  10863. * Gets or sets the inner glow color (white by default)
  10864. */
  10865. _this.innerGlowColor = new babylonjs_1.Color3(1.0, 1.0, 1.0);
  10866. /**
  10867. * Gets or sets alpha value (default is 1.0)
  10868. */
  10869. _this.alpha = 1.0;
  10870. /**
  10871. * Gets or sets the albedo color (Default is Color3(0.3, 0.35, 0.4))
  10872. */
  10873. _this.albedoColor = new babylonjs_1.Color3(0.3, 0.35, 0.4);
  10874. /**
  10875. * Gets or sets a boolean indicating if borders must be rendered (default is false)
  10876. */
  10877. _this.renderBorders = false;
  10878. /**
  10879. * Gets or sets border width (default is 0.5)
  10880. */
  10881. _this.borderWidth = 0.5;
  10882. /**
  10883. * Gets or sets a value indicating the smoothing value applied to border edges (0.02 by default)
  10884. */
  10885. _this.edgeSmoothingValue = 0.02;
  10886. /**
  10887. * Gets or sets the minimum value that can be applied to border width (default is 0.1)
  10888. */
  10889. _this.borderMinValue = 0.1;
  10890. /**
  10891. * Gets or sets a boolean indicating if hover light must be rendered (default is false)
  10892. */
  10893. _this.renderHoverLight = false;
  10894. /**
  10895. * Gets or sets the radius used to render the hover light (default is 1.0)
  10896. */
  10897. _this.hoverRadius = 1.0;
  10898. /**
  10899. * Gets or sets the color used to render the hover light (default is Color4(0.3, 0.3, 0.3, 1.0))
  10900. */
  10901. _this.hoverColor = new babylonjs_1.Color4(0.3, 0.3, 0.3, 1.0);
  10902. /**
  10903. * Gets or sets the hover light position in world space (default is Vector3.Zero())
  10904. */
  10905. _this.hoverPosition = babylonjs_1.Vector3.Zero();
  10906. return _this;
  10907. }
  10908. FluentMaterial.prototype.needAlphaBlending = function () {
  10909. return this.alpha !== 1.0;
  10910. };
  10911. FluentMaterial.prototype.needAlphaTesting = function () {
  10912. return false;
  10913. };
  10914. FluentMaterial.prototype.getAlphaTestTexture = function () {
  10915. return null;
  10916. };
  10917. FluentMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  10918. if (this.isFrozen) {
  10919. if (this._wasPreviouslyReady && subMesh.effect) {
  10920. return true;
  10921. }
  10922. }
  10923. if (!subMesh._materialDefines) {
  10924. subMesh._materialDefines = new FluentMaterialDefines();
  10925. }
  10926. var scene = this.getScene();
  10927. var defines = subMesh._materialDefines;
  10928. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  10929. if (defines._renderId === scene.getRenderId()) {
  10930. return true;
  10931. }
  10932. }
  10933. if (defines._areTexturesDirty) {
  10934. defines.INNERGLOW = this.innerGlowColorIntensity > 0;
  10935. defines.BORDER = this.renderBorders;
  10936. defines.HOVERLIGHT = this.renderHoverLight;
  10937. if (this._albedoTexture) {
  10938. if (!this._albedoTexture.isReadyOrNotBlocking()) {
  10939. return false;
  10940. }
  10941. else {
  10942. defines.TEXTURE = true;
  10943. }
  10944. }
  10945. else {
  10946. defines.TEXTURE = false;
  10947. }
  10948. }
  10949. var engine = scene.getEngine();
  10950. // Get correct effect
  10951. if (defines.isDirty) {
  10952. defines.markAsProcessed();
  10953. scene.resetCachedMaterial();
  10954. //Attributes
  10955. var attribs = [babylonjs_1.VertexBuffer.PositionKind];
  10956. attribs.push(babylonjs_1.VertexBuffer.NormalKind);
  10957. attribs.push(babylonjs_1.VertexBuffer.UVKind);
  10958. var shaderName = "fluent";
  10959. var uniforms = ["world", "viewProjection", "innerGlowColor", "albedoColor", "borderWidth", "edgeSmoothingValue", "scaleFactor", "borderMinValue",
  10960. "hoverColor", "hoverPosition", "hoverRadius"
  10961. ];
  10962. var samplers = ["albedoSampler"];
  10963. var uniformBuffers = new Array();
  10964. babylonjs_1.MaterialHelper.PrepareUniformsAndSamplersList({
  10965. uniformsNames: uniforms,
  10966. uniformBuffersNames: uniformBuffers,
  10967. samplers: samplers,
  10968. defines: defines,
  10969. maxSimultaneousLights: 4
  10970. });
  10971. var join = defines.toString();
  10972. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  10973. attributes: attribs,
  10974. uniformsNames: uniforms,
  10975. uniformBuffersNames: uniformBuffers,
  10976. samplers: samplers,
  10977. defines: join,
  10978. fallbacks: null,
  10979. onCompiled: this.onCompiled,
  10980. onError: this.onError,
  10981. indexParameters: { maxSimultaneousLights: 4 }
  10982. }, engine));
  10983. }
  10984. if (!subMesh.effect || !subMesh.effect.isReady()) {
  10985. return false;
  10986. }
  10987. defines._renderId = scene.getRenderId();
  10988. this._wasPreviouslyReady = true;
  10989. return true;
  10990. };
  10991. FluentMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  10992. var scene = this.getScene();
  10993. var defines = subMesh._materialDefines;
  10994. if (!defines) {
  10995. return;
  10996. }
  10997. var effect = subMesh.effect;
  10998. if (!effect) {
  10999. return;
  11000. }
  11001. this._activeEffect = effect;
  11002. // Matrices
  11003. this.bindOnlyWorldMatrix(world);
  11004. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  11005. if (this._mustRebind(scene, effect)) {
  11006. this._activeEffect.setColor4("albedoColor", this.albedoColor, this.alpha);
  11007. if (defines.INNERGLOW) {
  11008. this._activeEffect.setColor4("innerGlowColor", this.innerGlowColor, this.innerGlowColorIntensity);
  11009. }
  11010. if (defines.BORDER) {
  11011. this._activeEffect.setFloat("borderWidth", this.borderWidth);
  11012. this._activeEffect.setFloat("edgeSmoothingValue", this.edgeSmoothingValue);
  11013. this._activeEffect.setFloat("borderMinValue", this.borderMinValue);
  11014. mesh.getBoundingInfo().boundingBox.extendSize.multiplyToRef(mesh.scaling, babylonjs_1.Tmp.Vector3[0]);
  11015. this._activeEffect.setVector3("scaleFactor", babylonjs_1.Tmp.Vector3[0]);
  11016. }
  11017. if (defines.HOVERLIGHT) {
  11018. this._activeEffect.setDirectColor4("hoverColor", this.hoverColor);
  11019. this._activeEffect.setFloat("hoverRadius", this.hoverRadius);
  11020. this._activeEffect.setVector3("hoverPosition", this.hoverPosition);
  11021. }
  11022. if (defines.TEXTURE) {
  11023. this._activeEffect.setTexture("albedoSampler", this._albedoTexture);
  11024. }
  11025. }
  11026. this._afterBind(mesh, this._activeEffect);
  11027. };
  11028. FluentMaterial.prototype.getActiveTextures = function () {
  11029. var activeTextures = _super.prototype.getActiveTextures.call(this);
  11030. return activeTextures;
  11031. };
  11032. FluentMaterial.prototype.hasTexture = function (texture) {
  11033. if (_super.prototype.hasTexture.call(this, texture)) {
  11034. return true;
  11035. }
  11036. return false;
  11037. };
  11038. FluentMaterial.prototype.dispose = function (forceDisposeEffect) {
  11039. _super.prototype.dispose.call(this, forceDisposeEffect);
  11040. };
  11041. FluentMaterial.prototype.clone = function (name) {
  11042. var _this = this;
  11043. return babylonjs_1.SerializationHelper.Clone(function () { return new FluentMaterial(name, _this.getScene()); }, this);
  11044. };
  11045. FluentMaterial.prototype.serialize = function () {
  11046. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this);
  11047. serializationObject.customType = "BABYLON.GUI.FluentMaterial";
  11048. return serializationObject;
  11049. };
  11050. FluentMaterial.prototype.getClassName = function () {
  11051. return "FluentMaterial";
  11052. };
  11053. // Statics
  11054. FluentMaterial.Parse = function (source, scene, rootUrl) {
  11055. return babylonjs_1.SerializationHelper.Parse(function () { return new FluentMaterial(source.name, scene); }, source, scene, rootUrl);
  11056. };
  11057. __decorate([
  11058. babylonjs_1.serialize(),
  11059. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  11060. ], FluentMaterial.prototype, "innerGlowColorIntensity", void 0);
  11061. __decorate([
  11062. babylonjs_1.serializeAsColor3()
  11063. ], FluentMaterial.prototype, "innerGlowColor", void 0);
  11064. __decorate([
  11065. babylonjs_1.serialize()
  11066. ], FluentMaterial.prototype, "alpha", void 0);
  11067. __decorate([
  11068. babylonjs_1.serializeAsColor3()
  11069. ], FluentMaterial.prototype, "albedoColor", void 0);
  11070. __decorate([
  11071. babylonjs_1.serialize(),
  11072. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  11073. ], FluentMaterial.prototype, "renderBorders", void 0);
  11074. __decorate([
  11075. babylonjs_1.serialize()
  11076. ], FluentMaterial.prototype, "borderWidth", void 0);
  11077. __decorate([
  11078. babylonjs_1.serialize()
  11079. ], FluentMaterial.prototype, "edgeSmoothingValue", void 0);
  11080. __decorate([
  11081. babylonjs_1.serialize()
  11082. ], FluentMaterial.prototype, "borderMinValue", void 0);
  11083. __decorate([
  11084. babylonjs_1.serialize(),
  11085. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  11086. ], FluentMaterial.prototype, "renderHoverLight", void 0);
  11087. __decorate([
  11088. babylonjs_1.serialize()
  11089. ], FluentMaterial.prototype, "hoverRadius", void 0);
  11090. __decorate([
  11091. babylonjs_1.serializeAsColor4()
  11092. ], FluentMaterial.prototype, "hoverColor", void 0);
  11093. __decorate([
  11094. babylonjs_1.serializeAsVector3()
  11095. ], FluentMaterial.prototype, "hoverPosition", void 0);
  11096. __decorate([
  11097. babylonjs_1.serializeAsTexture("albedoTexture")
  11098. ], FluentMaterial.prototype, "_albedoTexture", void 0);
  11099. __decorate([
  11100. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")
  11101. ], FluentMaterial.prototype, "albedoTexture", void 0);
  11102. return FluentMaterial;
  11103. }(babylonjs_1.PushMaterial));
  11104. exports.FluentMaterial = FluentMaterial;
  11105. /***/ }),
  11106. /***/ "./src/3D/materials/index.ts":
  11107. /*!***********************************!*\
  11108. !*** ./src/3D/materials/index.ts ***!
  11109. \***********************************/
  11110. /*! no static exports found */
  11111. /***/ (function(module, exports, __webpack_require__) {
  11112. "use strict";
  11113. function __export(m) {
  11114. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  11115. }
  11116. Object.defineProperty(exports, "__esModule", { value: true });
  11117. __export(__webpack_require__(/*! ./fluentMaterial */ "./src/3D/materials/fluentMaterial.ts"));
  11118. /***/ }),
  11119. /***/ "./src/3D/materials/shaders/fluent.fragment.fx":
  11120. /*!*****************************************************!*\
  11121. !*** ./src/3D/materials/shaders/fluent.fragment.fx ***!
  11122. \*****************************************************/
  11123. /*! no static exports found */
  11124. /***/ (function(module, exports) {
  11125. module.exports = "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\n#ifdef TEXTURE\nuniform sampler2D albedoSampler;\n#endif\nvoid main(void) {\nvec3 albedo=albedoColor.rgb;\nfloat alpha=albedoColor.a;\n#ifdef TEXTURE\nalbedo=texture2D(albedoSampler,vUV).rgb;\n#endif\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}"
  11126. /***/ }),
  11127. /***/ "./src/3D/materials/shaders/fluent.ts":
  11128. /*!********************************************!*\
  11129. !*** ./src/3D/materials/shaders/fluent.ts ***!
  11130. \********************************************/
  11131. /*! no static exports found */
  11132. /***/ (function(module, exports, __webpack_require__) {
  11133. "use strict";
  11134. Object.defineProperty(exports, "__esModule", { value: true });
  11135. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  11136. var fShader = __webpack_require__(/*! ./fluent.fragment.fx */ "./src/3D/materials/shaders/fluent.fragment.fx");
  11137. exports.fShader = fShader;
  11138. var vShader = __webpack_require__(/*! ./fluent.vertex.fx */ "./src/3D/materials/shaders/fluent.vertex.fx");
  11139. exports.vShader = vShader;
  11140. function registerShader() {
  11141. // register shaders
  11142. babylonjs_1.Effect.ShadersStore["fluentVertexShader"] = vShader;
  11143. babylonjs_1.Effect.ShadersStore["fluentPixelShader"] = fShader;
  11144. }
  11145. exports.registerShader = registerShader;
  11146. /***/ }),
  11147. /***/ "./src/3D/materials/shaders/fluent.vertex.fx":
  11148. /*!***************************************************!*\
  11149. !*** ./src/3D/materials/shaders/fluent.vertex.fx ***!
  11150. \***************************************************/
  11151. /*! no static exports found */
  11152. /***/ (function(module, exports) {
  11153. module.exports = "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"
  11154. /***/ }),
  11155. /***/ "./src/3D/vector3WithInfo.ts":
  11156. /*!***********************************!*\
  11157. !*** ./src/3D/vector3WithInfo.ts ***!
  11158. \***********************************/
  11159. /*! no static exports found */
  11160. /***/ (function(module, exports, __webpack_require__) {
  11161. "use strict";
  11162. var __extends = (this && this.__extends) || (function () {
  11163. var extendStatics = function (d, b) {
  11164. extendStatics = Object.setPrototypeOf ||
  11165. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  11166. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  11167. return extendStatics(d, b);
  11168. }
  11169. return function (d, b) {
  11170. extendStatics(d, b);
  11171. function __() { this.constructor = d; }
  11172. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11173. };
  11174. })();
  11175. Object.defineProperty(exports, "__esModule", { value: true });
  11176. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  11177. /**
  11178. * Class used to transport Vector3 information for pointer events
  11179. */
  11180. var Vector3WithInfo = /** @class */ (function (_super) {
  11181. __extends(Vector3WithInfo, _super);
  11182. /**
  11183. * Creates a new Vector3WithInfo
  11184. * @param source defines the vector3 data to transport
  11185. * @param buttonIndex defines the current mouse button index
  11186. */
  11187. function Vector3WithInfo(source,
  11188. /** defines the current mouse button index */
  11189. buttonIndex) {
  11190. if (buttonIndex === void 0) { buttonIndex = 0; }
  11191. var _this = _super.call(this, source.x, source.y, source.z) || this;
  11192. _this.buttonIndex = buttonIndex;
  11193. return _this;
  11194. }
  11195. return Vector3WithInfo;
  11196. }(babylonjs_1.Vector3));
  11197. exports.Vector3WithInfo = Vector3WithInfo;
  11198. /***/ }),
  11199. /***/ "./src/index.ts":
  11200. /*!**********************!*\
  11201. !*** ./src/index.ts ***!
  11202. \**********************/
  11203. /*! no static exports found */
  11204. /***/ (function(module, exports, __webpack_require__) {
  11205. "use strict";
  11206. function __export(m) {
  11207. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  11208. }
  11209. Object.defineProperty(exports, "__esModule", { value: true });
  11210. __export(__webpack_require__(/*! ./2D */ "./src/2D/index.ts"));
  11211. __export(__webpack_require__(/*! ./3D */ "./src/3D/index.ts"));
  11212. /***/ }),
  11213. /***/ "./src/legacy.ts":
  11214. /*!***********************!*\
  11215. !*** ./src/legacy.ts ***!
  11216. \***********************/
  11217. /*! no static exports found */
  11218. /***/ (function(module, exports, __webpack_require__) {
  11219. "use strict";
  11220. /* WEBPACK VAR INJECTION */(function(global) {
  11221. function __export(m) {
  11222. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  11223. }
  11224. Object.defineProperty(exports, "__esModule", { value: true });
  11225. var GUI = __webpack_require__(/*! ./index */ "./src/index.ts");
  11226. /**
  11227. * Legacy support, defining window.BABYLON.GUI (global variable).
  11228. *
  11229. * This is the entry point for the UMD module.
  11230. * The entry point for a future ESM package should be index.ts
  11231. */
  11232. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  11233. if (typeof globalObject !== "undefined") {
  11234. globalObject.BABYLON = globalObject.BABYLON || {};
  11235. globalObject.BABYLON.GUI = GUI;
  11236. }
  11237. __export(__webpack_require__(/*! ./index */ "./src/index.ts"));
  11238. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/webpack/buildin/global.js */ "../node_modules/webpack/buildin/global.js")))
  11239. /***/ }),
  11240. /***/ "babylonjs":
  11241. /*!****************************************************************************************************!*\
  11242. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  11243. \****************************************************************************************************/
  11244. /*! no static exports found */
  11245. /***/ (function(module, exports) {
  11246. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  11247. /***/ })
  11248. /******/ });
  11249. });
  11250. //# sourceMappingURL=babylon.gui.js.map