babylon.gui.js 289 KB

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