babylon.gui.js 269 KB

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