babylon.gui.js 456 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-gui", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-gui"] = factory(require("babylonjs"));
  8. else
  9. root["BABYLON"] = root["BABYLON"] || {}, root["BABYLON"]["GUI"] = factory(root["BABYLON"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../node_modules/webpack/buildin/global.js":
  99. /*!*************************************************!*\
  100. !*** ../node_modules/webpack/buildin/global.js ***!
  101. \*************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || Function("return this")() || (1, eval)("this");
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./legacy/legacy.ts":
  122. /*!**************************!*\
  123. !*** ./legacy/legacy.ts ***!
  124. \**************************/
  125. /*! no static exports found */
  126. /***/ (function(module, exports, __webpack_require__) {
  127. "use strict";
  128. /* WEBPACK VAR INJECTION */(function(global) {
  129. function __export(m) {
  130. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  131. }
  132. Object.defineProperty(exports, "__esModule", { value: true });
  133. var GUI = __webpack_require__(/*! ../src/index */ "./src/index.ts");
  134. /**
  135. * Legacy support, defining window.BABYLON.GUI (global variable).
  136. *
  137. * This is the entry point for the UMD module.
  138. * The entry point for a future ESM package should be index.ts
  139. */
  140. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  141. if (typeof globalObject !== "undefined") {
  142. globalObject.BABYLON = globalObject.BABYLON || {};
  143. globalObject.BABYLON.GUI = GUI;
  144. }
  145. __export(__webpack_require__(/*! ../src/index */ "./src/index.ts"));
  146. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/webpack/buildin/global.js */ "../node_modules/webpack/buildin/global.js")))
  147. /***/ }),
  148. /***/ "./src/2D/advancedDynamicTexture.ts":
  149. /*!******************************************!*\
  150. !*** ./src/2D/advancedDynamicTexture.ts ***!
  151. \******************************************/
  152. /*! no static exports found */
  153. /***/ (function(module, exports, __webpack_require__) {
  154. "use strict";
  155. var __extends = (this && this.__extends) || (function () {
  156. var extendStatics = function (d, b) {
  157. extendStatics = Object.setPrototypeOf ||
  158. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  159. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  160. return extendStatics(d, b);
  161. }
  162. return function (d, b) {
  163. extendStatics(d, b);
  164. function __() { this.constructor = d; }
  165. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  166. };
  167. })();
  168. Object.defineProperty(exports, "__esModule", { value: true });
  169. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  170. var container_1 = __webpack_require__(/*! ./controls/container */ "./src/2D/controls/container.ts");
  171. var style_1 = __webpack_require__(/*! ./style */ "./src/2D/style.ts");
  172. var measure_1 = __webpack_require__(/*! ./measure */ "./src/2D/measure.ts");
  173. /**
  174. * Class used to create texture to support 2D GUI elements
  175. * @see http://doc.babylonjs.com/how_to/gui
  176. */
  177. var AdvancedDynamicTexture = /** @class */ (function (_super) {
  178. __extends(AdvancedDynamicTexture, _super);
  179. /**
  180. * Creates a new AdvancedDynamicTexture
  181. * @param name defines the name of the texture
  182. * @param width defines the width of the texture
  183. * @param height defines the height of the texture
  184. * @param scene defines the hosting scene
  185. * @param generateMipMaps defines a boolean indicating if mipmaps must be generated (false by default)
  186. * @param samplingMode defines the texture sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
  187. */
  188. function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode) {
  189. if (width === void 0) { width = 0; }
  190. if (height === void 0) { height = 0; }
  191. if (generateMipMaps === void 0) { generateMipMaps = false; }
  192. if (samplingMode === void 0) { samplingMode = babylonjs_1.Texture.NEAREST_SAMPLINGMODE; }
  193. var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, babylonjs_1.Engine.TEXTUREFORMAT_RGBA) || this;
  194. _this._isDirty = false;
  195. /** @hidden */
  196. _this._rootContainer = new container_1.Container("root");
  197. /** @hidden */
  198. _this._lastControlOver = {};
  199. /** @hidden */
  200. _this._lastControlDown = {};
  201. /** @hidden */
  202. _this._capturingControl = {};
  203. /** @hidden */
  204. _this._linkedControls = new Array();
  205. _this._isFullscreen = false;
  206. _this._fullscreenViewport = new babylonjs_1.Viewport(0, 0, 1, 1);
  207. _this._idealWidth = 0;
  208. _this._idealHeight = 0;
  209. _this._useSmallestIdeal = false;
  210. _this._renderAtIdealSize = false;
  211. _this._blockNextFocusCheck = false;
  212. _this._renderScale = 1;
  213. /**
  214. * Gets or sets a boolean defining if alpha is stored as premultiplied
  215. */
  216. _this.premulAlpha = false;
  217. scene = _this.getScene();
  218. if (!scene || !_this._texture) {
  219. return _this;
  220. }
  221. _this._rootCanvas = scene.getEngine().getRenderingCanvas();
  222. _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
  223. _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
  224. if (!_this._focusedControl) {
  225. return;
  226. }
  227. if (info.type === babylonjs_1.KeyboardEventTypes.KEYDOWN) {
  228. _this._focusedControl.processKeyboard(info.event);
  229. }
  230. info.skipOnPointerObservable = true;
  231. });
  232. _this._rootContainer._link(null, _this);
  233. _this.hasAlpha = true;
  234. if (!width || !height) {
  235. _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
  236. _this._onResize();
  237. }
  238. _this._texture.isReady = true;
  239. return _this;
  240. }
  241. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
  242. /**
  243. * Gets or sets a number used to scale rendering size (2 means that the texture will be twice bigger).
  244. * Useful when you want more antialiasing
  245. */
  246. get: function () {
  247. return this._renderScale;
  248. },
  249. set: function (value) {
  250. if (value === this._renderScale) {
  251. return;
  252. }
  253. this._renderScale = value;
  254. this._onResize();
  255. },
  256. enumerable: true,
  257. configurable: true
  258. });
  259. Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
  260. /** Gets or sets the background color */
  261. get: function () {
  262. return this._background;
  263. },
  264. set: function (value) {
  265. if (this._background === value) {
  266. return;
  267. }
  268. this._background = value;
  269. this.markAsDirty();
  270. },
  271. enumerable: true,
  272. configurable: true
  273. });
  274. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
  275. /**
  276. * Gets or sets the ideal width used to design controls.
  277. * The GUI will then rescale everything accordingly
  278. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  279. */
  280. get: function () {
  281. return this._idealWidth;
  282. },
  283. set: function (value) {
  284. if (this._idealWidth === value) {
  285. return;
  286. }
  287. this._idealWidth = value;
  288. this.markAsDirty();
  289. this._rootContainer._markAllAsDirty();
  290. },
  291. enumerable: true,
  292. configurable: true
  293. });
  294. Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
  295. /**
  296. * Gets or sets the ideal height used to design controls.
  297. * The GUI will then rescale everything accordingly
  298. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  299. */
  300. get: function () {
  301. return this._idealHeight;
  302. },
  303. set: function (value) {
  304. if (this._idealHeight === value) {
  305. return;
  306. }
  307. this._idealHeight = value;
  308. this.markAsDirty();
  309. this._rootContainer._markAllAsDirty();
  310. },
  311. enumerable: true,
  312. configurable: true
  313. });
  314. Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
  315. /**
  316. * Gets or sets a boolean indicating if the smallest ideal value must be used if idealWidth and idealHeight are both set
  317. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  318. */
  319. get: function () {
  320. return this._useSmallestIdeal;
  321. },
  322. set: function (value) {
  323. if (this._useSmallestIdeal === value) {
  324. return;
  325. }
  326. this._useSmallestIdeal = value;
  327. this.markAsDirty();
  328. this._rootContainer._markAllAsDirty();
  329. },
  330. enumerable: true,
  331. configurable: true
  332. });
  333. Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
  334. /**
  335. * Gets or sets a boolean indicating if adaptive scaling must be used
  336. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  337. */
  338. get: function () {
  339. return this._renderAtIdealSize;
  340. },
  341. set: function (value) {
  342. if (this._renderAtIdealSize === value) {
  343. return;
  344. }
  345. this._renderAtIdealSize = value;
  346. this._onResize();
  347. },
  348. enumerable: true,
  349. configurable: true
  350. });
  351. Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
  352. /**
  353. * Gets the underlying layer used to render the texture when in fullscreen mode
  354. */
  355. get: function () {
  356. return this._layerToDispose;
  357. },
  358. enumerable: true,
  359. configurable: true
  360. });
  361. Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
  362. /**
  363. * Gets the root container control
  364. */
  365. get: function () {
  366. return this._rootContainer;
  367. },
  368. enumerable: true,
  369. configurable: true
  370. });
  371. Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
  372. /**
  373. * Gets or sets the current focused control
  374. */
  375. get: function () {
  376. return this._focusedControl;
  377. },
  378. set: function (control) {
  379. if (this._focusedControl == control) {
  380. return;
  381. }
  382. if (this._focusedControl) {
  383. this._focusedControl.onBlur();
  384. }
  385. if (control) {
  386. control.onFocus();
  387. }
  388. this._focusedControl = control;
  389. },
  390. enumerable: true,
  391. configurable: true
  392. });
  393. Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
  394. /**
  395. * Gets or sets a boolean indicating if the texture must be rendered in background or foreground when in fullscreen mode
  396. */
  397. get: function () {
  398. if (!this.layer) {
  399. return true;
  400. }
  401. return (!this.layer.isBackground);
  402. },
  403. set: function (value) {
  404. if (!this.layer) {
  405. return;
  406. }
  407. if (this.layer.isBackground === !value) {
  408. return;
  409. }
  410. this.layer.isBackground = !value;
  411. },
  412. enumerable: true,
  413. configurable: true
  414. });
  415. /**
  416. * Function used to execute a function on all controls
  417. * @param func defines the function to execute
  418. * @param container defines the container where controls belong. If null the root container will be used
  419. */
  420. AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
  421. if (!container) {
  422. container = this._rootContainer;
  423. }
  424. func(container);
  425. for (var _i = 0, _a = container.children; _i < _a.length; _i++) {
  426. var child = _a[_i];
  427. if (child.children) {
  428. this.executeOnAllControls(func, child);
  429. continue;
  430. }
  431. func(child);
  432. }
  433. };
  434. /**
  435. * Marks the texture as dirty forcing a complete update
  436. */
  437. AdvancedDynamicTexture.prototype.markAsDirty = function () {
  438. this._isDirty = true;
  439. };
  440. /**
  441. * Helper function used to create a new style
  442. * @returns a new style
  443. * @see http://doc.babylonjs.com/how_to/gui#styles
  444. */
  445. AdvancedDynamicTexture.prototype.createStyle = function () {
  446. return new style_1.Style(this);
  447. };
  448. /**
  449. * Adds a new control to the root container
  450. * @param control defines the control to add
  451. * @returns the current texture
  452. */
  453. AdvancedDynamicTexture.prototype.addControl = function (control) {
  454. this._rootContainer.addControl(control);
  455. return this;
  456. };
  457. /**
  458. * Removes a control from the root container
  459. * @param control defines the control to remove
  460. * @returns the current texture
  461. */
  462. AdvancedDynamicTexture.prototype.removeControl = function (control) {
  463. this._rootContainer.removeControl(control);
  464. return this;
  465. };
  466. /**
  467. * Release all resources
  468. */
  469. AdvancedDynamicTexture.prototype.dispose = function () {
  470. var scene = this.getScene();
  471. if (!scene) {
  472. return;
  473. }
  474. this._rootCanvas = null;
  475. scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
  476. if (this._resizeObserver) {
  477. scene.getEngine().onResizeObservable.remove(this._resizeObserver);
  478. }
  479. if (this._pointerMoveObserver) {
  480. scene.onPrePointerObservable.remove(this._pointerMoveObserver);
  481. }
  482. if (this._pointerObserver) {
  483. scene.onPointerObservable.remove(this._pointerObserver);
  484. }
  485. if (this._preKeyboardObserver) {
  486. scene.onPreKeyboardObservable.remove(this._preKeyboardObserver);
  487. }
  488. if (this._canvasPointerOutObserver) {
  489. scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
  490. }
  491. if (this._layerToDispose) {
  492. this._layerToDispose.texture = null;
  493. this._layerToDispose.dispose();
  494. this._layerToDispose = null;
  495. }
  496. this._rootContainer.dispose();
  497. _super.prototype.dispose.call(this);
  498. };
  499. AdvancedDynamicTexture.prototype._onResize = function () {
  500. var scene = this.getScene();
  501. if (!scene) {
  502. return;
  503. }
  504. // Check size
  505. var engine = scene.getEngine();
  506. var textureSize = this.getSize();
  507. var renderWidth = engine.getRenderWidth() * this._renderScale;
  508. var renderHeight = engine.getRenderHeight() * this._renderScale;
  509. if (this._renderAtIdealSize) {
  510. if (this._idealWidth) {
  511. renderHeight = (renderHeight * this._idealWidth) / renderWidth;
  512. renderWidth = this._idealWidth;
  513. }
  514. else if (this._idealHeight) {
  515. renderWidth = (renderWidth * this._idealHeight) / renderHeight;
  516. renderHeight = this._idealHeight;
  517. }
  518. }
  519. if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
  520. this.scaleTo(renderWidth, renderHeight);
  521. this.markAsDirty();
  522. if (this._idealWidth || this._idealHeight) {
  523. this._rootContainer._markAllAsDirty();
  524. }
  525. }
  526. };
  527. /** @hidden */
  528. AdvancedDynamicTexture.prototype._getGlobalViewport = function (scene) {
  529. var engine = scene.getEngine();
  530. return this._fullscreenViewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight());
  531. };
  532. /**
  533. * Get screen coordinates for a vector3
  534. * @param position defines the position to project
  535. * @param worldMatrix defines the world matrix to use
  536. * @returns the projected position
  537. */
  538. AdvancedDynamicTexture.prototype.getProjectedPosition = function (position, worldMatrix) {
  539. var scene = this.getScene();
  540. if (!scene) {
  541. return babylonjs_1.Vector2.Zero();
  542. }
  543. var globalViewport = this._getGlobalViewport(scene);
  544. var projectedPosition = babylonjs_1.Vector3.Project(position, worldMatrix, scene.getTransformMatrix(), globalViewport);
  545. projectedPosition.scaleInPlace(this.renderScale);
  546. return new babylonjs_1.Vector2(projectedPosition.x, projectedPosition.y);
  547. };
  548. AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
  549. if (this._layerToDispose) {
  550. if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
  551. return;
  552. }
  553. }
  554. if (this._isFullscreen && this._linkedControls.length) {
  555. var scene = this.getScene();
  556. if (!scene) {
  557. return;
  558. }
  559. var globalViewport = this._getGlobalViewport(scene);
  560. for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
  561. var control = _a[_i];
  562. if (!control.isVisible) {
  563. continue;
  564. }
  565. var mesh = control._linkedMesh;
  566. if (!mesh || mesh.isDisposed()) {
  567. babylonjs_1.Tools.SetImmediate(function () {
  568. control.linkWithMesh(null);
  569. });
  570. continue;
  571. }
  572. var position = mesh.getBoundingInfo().boundingSphere.center;
  573. var projectedPosition = babylonjs_1.Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
  574. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  575. control.notRenderable = true;
  576. continue;
  577. }
  578. control.notRenderable = false;
  579. // Account for RenderScale.
  580. projectedPosition.scaleInPlace(this.renderScale);
  581. control._moveToProjectedPosition(projectedPosition);
  582. }
  583. }
  584. if (!this._isDirty && !this._rootContainer.isDirty) {
  585. return;
  586. }
  587. this._isDirty = false;
  588. this._render();
  589. this.update(true, this.premulAlpha);
  590. };
  591. AdvancedDynamicTexture.prototype._render = function () {
  592. var textureSize = this.getSize();
  593. var renderWidth = textureSize.width;
  594. var renderHeight = textureSize.height;
  595. // Clear
  596. var context = this.getContext();
  597. context.clearRect(0, 0, renderWidth, renderHeight);
  598. if (this._background) {
  599. context.save();
  600. context.fillStyle = this._background;
  601. context.fillRect(0, 0, renderWidth, renderHeight);
  602. context.restore();
  603. }
  604. // Render
  605. context.font = "18px Arial";
  606. context.strokeStyle = "white";
  607. var measure = new measure_1.Measure(0, 0, renderWidth, renderHeight);
  608. this._rootContainer._draw(measure, context);
  609. };
  610. /** @hidden */
  611. AdvancedDynamicTexture.prototype._changeCursor = function (cursor) {
  612. if (this._rootCanvas) {
  613. this._rootCanvas.style.cursor = cursor;
  614. }
  615. };
  616. AdvancedDynamicTexture.prototype._doPicking = function (x, y, type, pointerId, buttonIndex) {
  617. var scene = this.getScene();
  618. if (!scene) {
  619. return;
  620. }
  621. var engine = scene.getEngine();
  622. var textureSize = this.getSize();
  623. if (this._isFullscreen) {
  624. x = x * (textureSize.width / engine.getRenderWidth());
  625. y = y * (textureSize.height / engine.getRenderHeight());
  626. }
  627. if (this._capturingControl[pointerId]) {
  628. this._capturingControl[pointerId]._processObservables(type, x, y, pointerId, buttonIndex);
  629. return;
  630. }
  631. if (!this._rootContainer._processPicking(x, y, type, pointerId, buttonIndex)) {
  632. this._changeCursor("");
  633. if (type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  634. if (this._lastControlOver[pointerId]) {
  635. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  636. }
  637. delete this._lastControlOver[pointerId];
  638. }
  639. }
  640. this._manageFocus();
  641. };
  642. /** @hidden */
  643. AdvancedDynamicTexture.prototype._cleanControlAfterRemovalFromList = function (list, control) {
  644. for (var pointerId in list) {
  645. if (!list.hasOwnProperty(pointerId)) {
  646. continue;
  647. }
  648. var lastControlOver = list[pointerId];
  649. if (lastControlOver === control) {
  650. delete list[pointerId];
  651. }
  652. }
  653. };
  654. /** @hidden */
  655. AdvancedDynamicTexture.prototype._cleanControlAfterRemoval = function (control) {
  656. this._cleanControlAfterRemovalFromList(this._lastControlDown, control);
  657. this._cleanControlAfterRemovalFromList(this._lastControlOver, control);
  658. };
  659. /** Attach to all scene events required to support pointer events */
  660. AdvancedDynamicTexture.prototype.attach = function () {
  661. var _this = this;
  662. var scene = this.getScene();
  663. if (!scene) {
  664. return;
  665. }
  666. this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
  667. if (scene.isPointerCaptured((pi.event).pointerId)) {
  668. return;
  669. }
  670. if (pi.type !== babylonjs_1.PointerEventTypes.POINTERMOVE
  671. && pi.type !== babylonjs_1.PointerEventTypes.POINTERUP
  672. && pi.type !== babylonjs_1.PointerEventTypes.POINTERDOWN) {
  673. return;
  674. }
  675. if (!scene) {
  676. return;
  677. }
  678. var camera = scene.cameraToUseForPointers || scene.activeCamera;
  679. if (!camera) {
  680. return;
  681. }
  682. var engine = scene.getEngine();
  683. var viewport = camera.viewport;
  684. var x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
  685. var y = (scene.pointerY / engine.getHardwareScalingLevel() - viewport.y * engine.getRenderHeight()) / viewport.height;
  686. _this._shouldBlockPointer = false;
  687. // Do picking modifies _shouldBlockPointer
  688. _this._doPicking(x, y, pi.type, pi.event.pointerId || 0, pi.event.button);
  689. // Avoid overwriting a true skipOnPointerObservable to false
  690. if (_this._shouldBlockPointer) {
  691. pi.skipOnPointerObservable = _this._shouldBlockPointer;
  692. }
  693. });
  694. this._attachToOnPointerOut(scene);
  695. };
  696. /**
  697. * Connect the texture to a hosting mesh to enable interactions
  698. * @param mesh defines the mesh to attach to
  699. * @param supportPointerMove defines a boolean indicating if pointer move events must be catched as well
  700. */
  701. AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
  702. var _this = this;
  703. if (supportPointerMove === void 0) { supportPointerMove = true; }
  704. var scene = this.getScene();
  705. if (!scene) {
  706. return;
  707. }
  708. this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
  709. if (pi.type !== babylonjs_1.PointerEventTypes.POINTERMOVE
  710. && pi.type !== babylonjs_1.PointerEventTypes.POINTERUP
  711. && pi.type !== babylonjs_1.PointerEventTypes.POINTERDOWN) {
  712. return;
  713. }
  714. var pointerId = pi.event.pointerId || 0;
  715. if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
  716. var uv = pi.pickInfo.getTextureCoordinates();
  717. if (uv) {
  718. var size = _this.getSize();
  719. _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pointerId, pi.event.button);
  720. }
  721. }
  722. else if (pi.type === babylonjs_1.PointerEventTypes.POINTERUP) {
  723. if (_this._lastControlDown[pointerId]) {
  724. _this._lastControlDown[pointerId]._forcePointerUp(pointerId);
  725. }
  726. delete _this._lastControlDown[pointerId];
  727. if (_this.focusedControl) {
  728. var friendlyControls = _this.focusedControl.keepsFocusWith();
  729. var canMoveFocus = true;
  730. if (friendlyControls) {
  731. for (var _i = 0, friendlyControls_1 = friendlyControls; _i < friendlyControls_1.length; _i++) {
  732. var control = friendlyControls_1[_i];
  733. // Same host, no need to keep the focus
  734. if (_this === control._host) {
  735. continue;
  736. }
  737. // Different hosts
  738. var otherHost = control._host;
  739. if (otherHost._lastControlOver[pointerId] && otherHost._lastControlOver[pointerId].isAscendant(control)) {
  740. canMoveFocus = false;
  741. break;
  742. }
  743. }
  744. }
  745. if (canMoveFocus) {
  746. _this.focusedControl = null;
  747. }
  748. }
  749. }
  750. else if (pi.type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  751. if (_this._lastControlOver[pointerId]) {
  752. _this._lastControlOver[pointerId]._onPointerOut(_this._lastControlOver[pointerId]);
  753. }
  754. delete _this._lastControlOver[pointerId];
  755. }
  756. });
  757. mesh.enablePointerMoveEvents = supportPointerMove;
  758. this._attachToOnPointerOut(scene);
  759. };
  760. /**
  761. * Move the focus to a specific control
  762. * @param control defines the control which will receive the focus
  763. */
  764. AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
  765. this.focusedControl = control;
  766. this._lastPickedControl = control;
  767. this._blockNextFocusCheck = true;
  768. };
  769. AdvancedDynamicTexture.prototype._manageFocus = function () {
  770. if (this._blockNextFocusCheck) {
  771. this._blockNextFocusCheck = false;
  772. this._lastPickedControl = this._focusedControl;
  773. return;
  774. }
  775. // Focus management
  776. if (this._focusedControl) {
  777. if (this._focusedControl !== this._lastPickedControl) {
  778. if (this._lastPickedControl.isFocusInvisible) {
  779. return;
  780. }
  781. this.focusedControl = null;
  782. }
  783. }
  784. };
  785. AdvancedDynamicTexture.prototype._attachToOnPointerOut = function (scene) {
  786. var _this = this;
  787. this._canvasPointerOutObserver = scene.getEngine().onCanvasPointerOutObservable.add(function (pointerEvent) {
  788. if (_this._lastControlOver[pointerEvent.pointerId]) {
  789. _this._lastControlOver[pointerEvent.pointerId]._onPointerOut(_this._lastControlOver[pointerEvent.pointerId]);
  790. }
  791. delete _this._lastControlOver[pointerEvent.pointerId];
  792. if (_this._lastControlDown[pointerEvent.pointerId]) {
  793. _this._lastControlDown[pointerEvent.pointerId]._forcePointerUp();
  794. }
  795. delete _this._lastControlDown[pointerEvent.pointerId];
  796. });
  797. };
  798. // Statics
  799. /**
  800. * Creates a new AdvancedDynamicTexture in projected mode (ie. attached to a mesh)
  801. * @param mesh defines the mesh which will receive the texture
  802. * @param width defines the texture width (1024 by default)
  803. * @param height defines the texture height (1024 by default)
  804. * @param supportPointerMove defines a boolean indicating if the texture must capture move events (true by default)
  805. * @param onlyAlphaTesting defines a boolean indicating that alpha blending will not be used (only alpha testing) (false by default)
  806. * @returns a new AdvancedDynamicTexture
  807. */
  808. AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height, supportPointerMove, onlyAlphaTesting) {
  809. if (width === void 0) { width = 1024; }
  810. if (height === void 0) { height = 1024; }
  811. if (supportPointerMove === void 0) { supportPointerMove = true; }
  812. if (onlyAlphaTesting === void 0) { onlyAlphaTesting = false; }
  813. var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, babylonjs_1.Texture.TRILINEAR_SAMPLINGMODE);
  814. var material = new babylonjs_1.StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene());
  815. material.backFaceCulling = false;
  816. material.diffuseColor = babylonjs_1.Color3.Black();
  817. material.specularColor = babylonjs_1.Color3.Black();
  818. if (onlyAlphaTesting) {
  819. material.diffuseTexture = result;
  820. material.emissiveTexture = result;
  821. result.hasAlpha = true;
  822. }
  823. else {
  824. material.emissiveTexture = result;
  825. material.opacityTexture = result;
  826. }
  827. mesh.material = material;
  828. result.attachToMesh(mesh, supportPointerMove);
  829. return result;
  830. };
  831. /**
  832. * Creates a new AdvancedDynamicTexture in fullscreen mode.
  833. * In this mode the texture will rely on a layer for its rendering.
  834. * This allows it to be treated like any other layer.
  835. * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
  836. * LayerMask is set through advancedTexture.layer.layerMask
  837. * @param name defines name for the texture
  838. * @param foreground defines a boolean indicating if the texture must be rendered in foreground (default is true)
  839. * @param scene defines the hsoting scene
  840. * @param sampling defines the texture sampling mode (Texture.BILINEAR_SAMPLINGMODE by default)
  841. * @returns a new AdvancedDynamicTexture
  842. */
  843. AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling) {
  844. if (foreground === void 0) { foreground = true; }
  845. if (scene === void 0) { scene = null; }
  846. if (sampling === void 0) { sampling = babylonjs_1.Texture.BILINEAR_SAMPLINGMODE; }
  847. var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, sampling);
  848. // Display
  849. var layer = new babylonjs_1.Layer(name + "_layer", null, scene, !foreground);
  850. layer.texture = result;
  851. result._layerToDispose = layer;
  852. result._isFullscreen = true;
  853. // Attach
  854. result.attach();
  855. return result;
  856. };
  857. return AdvancedDynamicTexture;
  858. }(babylonjs_1.DynamicTexture));
  859. exports.AdvancedDynamicTexture = AdvancedDynamicTexture;
  860. /***/ }),
  861. /***/ "./src/2D/controls/baseSlider.ts":
  862. /*!***************************************!*\
  863. !*** ./src/2D/controls/baseSlider.ts ***!
  864. \***************************************/
  865. /*! no static exports found */
  866. /***/ (function(module, exports, __webpack_require__) {
  867. "use strict";
  868. var __extends = (this && this.__extends) || (function () {
  869. var extendStatics = function (d, b) {
  870. extendStatics = Object.setPrototypeOf ||
  871. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  872. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  873. return extendStatics(d, b);
  874. }
  875. return function (d, b) {
  876. extendStatics(d, b);
  877. function __() { this.constructor = d; }
  878. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  879. };
  880. })();
  881. Object.defineProperty(exports, "__esModule", { value: true });
  882. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  883. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  884. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  885. /**
  886. * Class used to create slider controls
  887. */
  888. var BaseSlider = /** @class */ (function (_super) {
  889. __extends(BaseSlider, _super);
  890. /**
  891. * Creates a new BaseSlider
  892. * @param name defines the control name
  893. */
  894. function BaseSlider(name) {
  895. var _this = _super.call(this, name) || this;
  896. _this.name = name;
  897. _this._thumbWidth = new valueAndUnit_1.ValueAndUnit(20, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL, false);
  898. _this._minimum = 0;
  899. _this._maximum = 100;
  900. _this._value = 50;
  901. _this._isVertical = false;
  902. _this._barOffset = new valueAndUnit_1.ValueAndUnit(5, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL, false);
  903. _this._isThumbClamped = false;
  904. _this._displayThumb = true;
  905. // Shared rendering info
  906. _this._effectiveBarOffset = 0;
  907. /** Observable raised when the sldier value changes */
  908. _this.onValueChangedObservable = new babylonjs_1.Observable();
  909. // Events
  910. _this._pointerIsDown = false;
  911. _this.isPointerBlocker = true;
  912. return _this;
  913. }
  914. Object.defineProperty(BaseSlider.prototype, "displayThumb", {
  915. /** Gets or sets a boolean indicating if the thumb must be rendered */
  916. get: function () {
  917. return this._displayThumb;
  918. },
  919. set: function (value) {
  920. if (this._displayThumb === value) {
  921. return;
  922. }
  923. this._displayThumb = value;
  924. this._markAsDirty();
  925. },
  926. enumerable: true,
  927. configurable: true
  928. });
  929. Object.defineProperty(BaseSlider.prototype, "barOffset", {
  930. /** Gets or sets main bar offset (ie. the margin applied to the value bar) */
  931. get: function () {
  932. return this._barOffset.toString(this._host);
  933. },
  934. set: function (value) {
  935. if (this._barOffset.toString(this._host) === value) {
  936. return;
  937. }
  938. if (this._barOffset.fromString(value)) {
  939. this._markAsDirty();
  940. }
  941. },
  942. enumerable: true,
  943. configurable: true
  944. });
  945. Object.defineProperty(BaseSlider.prototype, "barOffsetInPixels", {
  946. /** Gets main bar offset in pixels*/
  947. get: function () {
  948. return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
  949. },
  950. enumerable: true,
  951. configurable: true
  952. });
  953. Object.defineProperty(BaseSlider.prototype, "thumbWidth", {
  954. /** Gets or sets thumb width */
  955. get: function () {
  956. return this._thumbWidth.toString(this._host);
  957. },
  958. set: function (value) {
  959. if (this._thumbWidth.toString(this._host) === value) {
  960. return;
  961. }
  962. if (this._thumbWidth.fromString(value)) {
  963. this._markAsDirty();
  964. }
  965. },
  966. enumerable: true,
  967. configurable: true
  968. });
  969. Object.defineProperty(BaseSlider.prototype, "thumbWidthInPixels", {
  970. /** Gets thumb width in pixels */
  971. get: function () {
  972. return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  973. },
  974. enumerable: true,
  975. configurable: true
  976. });
  977. Object.defineProperty(BaseSlider.prototype, "minimum", {
  978. /** Gets or sets minimum value */
  979. get: function () {
  980. return this._minimum;
  981. },
  982. set: function (value) {
  983. if (this._minimum === value) {
  984. return;
  985. }
  986. this._minimum = value;
  987. this._markAsDirty();
  988. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  989. },
  990. enumerable: true,
  991. configurable: true
  992. });
  993. Object.defineProperty(BaseSlider.prototype, "maximum", {
  994. /** Gets or sets maximum value */
  995. get: function () {
  996. return this._maximum;
  997. },
  998. set: function (value) {
  999. if (this._maximum === value) {
  1000. return;
  1001. }
  1002. this._maximum = value;
  1003. this._markAsDirty();
  1004. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  1005. },
  1006. enumerable: true,
  1007. configurable: true
  1008. });
  1009. Object.defineProperty(BaseSlider.prototype, "value", {
  1010. /** Gets or sets current value */
  1011. get: function () {
  1012. return this._value;
  1013. },
  1014. set: function (value) {
  1015. value = Math.max(Math.min(value, this._maximum), this._minimum);
  1016. if (this._value === value) {
  1017. return;
  1018. }
  1019. this._value = value;
  1020. this._markAsDirty();
  1021. this.onValueChangedObservable.notifyObservers(this._value);
  1022. },
  1023. enumerable: true,
  1024. configurable: true
  1025. });
  1026. Object.defineProperty(BaseSlider.prototype, "isVertical", {
  1027. /**Gets or sets a boolean indicating if the slider should be vertical or horizontal */
  1028. get: function () {
  1029. return this._isVertical;
  1030. },
  1031. set: function (value) {
  1032. if (this._isVertical === value) {
  1033. return;
  1034. }
  1035. this._isVertical = value;
  1036. this._markAsDirty();
  1037. },
  1038. enumerable: true,
  1039. configurable: true
  1040. });
  1041. Object.defineProperty(BaseSlider.prototype, "isThumbClamped", {
  1042. /** Gets or sets a value indicating if the thumb can go over main bar extends */
  1043. get: function () {
  1044. return this._isThumbClamped;
  1045. },
  1046. set: function (value) {
  1047. if (this._isThumbClamped === value) {
  1048. return;
  1049. }
  1050. this._isThumbClamped = value;
  1051. this._markAsDirty();
  1052. },
  1053. enumerable: true,
  1054. configurable: true
  1055. });
  1056. BaseSlider.prototype._getTypeName = function () {
  1057. return "BaseSlider";
  1058. };
  1059. BaseSlider.prototype._getThumbPosition = function () {
  1060. if (this.isVertical) {
  1061. return ((this.maximum - this.value) / (this.maximum - this.minimum)) * this._backgroundBoxLength;
  1062. }
  1063. return ((this.value - this.minimum) / (this.maximum - this.minimum)) * this._backgroundBoxLength;
  1064. };
  1065. BaseSlider.prototype._getThumbThickness = function (type) {
  1066. var thumbThickness = 0;
  1067. switch (type) {
  1068. case "circle":
  1069. if (this._thumbWidth.isPixel) {
  1070. thumbThickness = Math.max(this._thumbWidth.getValue(this._host), this._backgroundBoxThickness);
  1071. }
  1072. else {
  1073. thumbThickness = this._backgroundBoxThickness * this._thumbWidth.getValue(this._host);
  1074. }
  1075. break;
  1076. case "rectangle":
  1077. if (this._thumbWidth.isPixel) {
  1078. thumbThickness = Math.min(this._thumbWidth.getValue(this._host), this._backgroundBoxThickness);
  1079. }
  1080. else {
  1081. thumbThickness = this._backgroundBoxThickness * this._thumbWidth.getValue(this._host);
  1082. }
  1083. }
  1084. return thumbThickness;
  1085. };
  1086. BaseSlider.prototype._prepareRenderingData = function (type) {
  1087. // Main bar
  1088. this._effectiveBarOffset = 0;
  1089. this._renderLeft = this._currentMeasure.left;
  1090. this._renderTop = this._currentMeasure.top;
  1091. this._renderWidth = this._currentMeasure.width;
  1092. this._renderHeight = this._currentMeasure.height;
  1093. this._backgroundBoxLength = Math.max(this._currentMeasure.width, this._currentMeasure.height);
  1094. this._backgroundBoxThickness = Math.min(this._currentMeasure.width, this._currentMeasure.height);
  1095. this._effectiveThumbThickness = this._getThumbThickness(type);
  1096. if (this.displayThumb) {
  1097. this._backgroundBoxLength -= this._effectiveThumbThickness;
  1098. }
  1099. //throw error when height is less than width for vertical slider
  1100. if ((this.isVertical && this._currentMeasure.height < this._currentMeasure.width)) {
  1101. console.error("Height should be greater than width");
  1102. return;
  1103. }
  1104. if (this._barOffset.isPixel) {
  1105. this._effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._backgroundBoxThickness);
  1106. }
  1107. else {
  1108. this._effectiveBarOffset = this._backgroundBoxThickness * this._barOffset.getValue(this._host);
  1109. }
  1110. this._backgroundBoxThickness -= (this._effectiveBarOffset * 2);
  1111. if (this.isVertical) {
  1112. this._renderLeft += this._effectiveBarOffset;
  1113. if (!this.isThumbClamped && this.displayThumb) {
  1114. this._renderTop += (this._effectiveThumbThickness / 2);
  1115. }
  1116. this._renderHeight = this._backgroundBoxLength;
  1117. this._renderWidth = this._backgroundBoxThickness;
  1118. }
  1119. else {
  1120. this._renderTop += this._effectiveBarOffset;
  1121. if (!this.isThumbClamped && this.displayThumb) {
  1122. this._renderLeft += (this._effectiveThumbThickness / 2);
  1123. }
  1124. this._renderHeight = this._backgroundBoxThickness;
  1125. this._renderWidth = this._backgroundBoxLength;
  1126. }
  1127. };
  1128. BaseSlider.prototype._updateValueFromPointer = function (x, y) {
  1129. if (this.rotation != 0) {
  1130. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  1131. x = this._transformedPosition.x;
  1132. y = this._transformedPosition.y;
  1133. }
  1134. if (this._isVertical) {
  1135. this.value = this._minimum + (1 - ((y - this._currentMeasure.top) / this._currentMeasure.height)) * (this._maximum - this._minimum);
  1136. }
  1137. else {
  1138. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  1139. }
  1140. };
  1141. BaseSlider.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  1142. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  1143. return false;
  1144. }
  1145. this._pointerIsDown = true;
  1146. this._updateValueFromPointer(coordinates.x, coordinates.y);
  1147. this._host._capturingControl[pointerId] = this;
  1148. return true;
  1149. };
  1150. BaseSlider.prototype._onPointerMove = function (target, coordinates) {
  1151. if (this._pointerIsDown) {
  1152. this._updateValueFromPointer(coordinates.x, coordinates.y);
  1153. }
  1154. _super.prototype._onPointerMove.call(this, target, coordinates);
  1155. };
  1156. BaseSlider.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  1157. this._pointerIsDown = false;
  1158. delete this._host._capturingControl[pointerId];
  1159. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  1160. };
  1161. return BaseSlider;
  1162. }(control_1.Control));
  1163. exports.BaseSlider = BaseSlider;
  1164. /***/ }),
  1165. /***/ "./src/2D/controls/button.ts":
  1166. /*!***********************************!*\
  1167. !*** ./src/2D/controls/button.ts ***!
  1168. \***********************************/
  1169. /*! no static exports found */
  1170. /***/ (function(module, exports, __webpack_require__) {
  1171. "use strict";
  1172. var __extends = (this && this.__extends) || (function () {
  1173. var extendStatics = function (d, b) {
  1174. extendStatics = Object.setPrototypeOf ||
  1175. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1176. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1177. return extendStatics(d, b);
  1178. }
  1179. return function (d, b) {
  1180. extendStatics(d, b);
  1181. function __() { this.constructor = d; }
  1182. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1183. };
  1184. })();
  1185. Object.defineProperty(exports, "__esModule", { value: true });
  1186. var rectangle_1 = __webpack_require__(/*! ./rectangle */ "./src/2D/controls/rectangle.ts");
  1187. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  1188. var textBlock_1 = __webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts");
  1189. var image_1 = __webpack_require__(/*! ./image */ "./src/2D/controls/image.ts");
  1190. /**
  1191. * Class used to create 2D buttons
  1192. */
  1193. var Button = /** @class */ (function (_super) {
  1194. __extends(Button, _super);
  1195. /**
  1196. * Creates a new Button
  1197. * @param name defines the name of the button
  1198. */
  1199. function Button(name) {
  1200. var _this = _super.call(this, name) || this;
  1201. _this.name = name;
  1202. _this.thickness = 1;
  1203. _this.isPointerBlocker = true;
  1204. _this.pointerEnterAnimation = function () {
  1205. _this.alpha -= 0.1;
  1206. };
  1207. _this.pointerOutAnimation = function () {
  1208. _this.alpha += 0.1;
  1209. };
  1210. _this.pointerDownAnimation = function () {
  1211. _this.scaleX -= 0.05;
  1212. _this.scaleY -= 0.05;
  1213. };
  1214. _this.pointerUpAnimation = function () {
  1215. _this.scaleX += 0.05;
  1216. _this.scaleY += 0.05;
  1217. };
  1218. return _this;
  1219. }
  1220. Object.defineProperty(Button.prototype, "image", {
  1221. /**
  1222. * Returns the image part of the button (if any)
  1223. */
  1224. get: function () {
  1225. return this._image;
  1226. },
  1227. enumerable: true,
  1228. configurable: true
  1229. });
  1230. Object.defineProperty(Button.prototype, "textBlock", {
  1231. /**
  1232. * Returns the image part of the button (if any)
  1233. */
  1234. get: function () {
  1235. return this._textBlock;
  1236. },
  1237. enumerable: true,
  1238. configurable: true
  1239. });
  1240. Button.prototype._getTypeName = function () {
  1241. return "Button";
  1242. };
  1243. // While being a container, the button behaves like a control.
  1244. /** @hidden */
  1245. Button.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  1246. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  1247. return false;
  1248. }
  1249. if (!_super.prototype.contains.call(this, x, y)) {
  1250. return false;
  1251. }
  1252. this._processObservables(type, x, y, pointerId, buttonIndex);
  1253. return true;
  1254. };
  1255. /** @hidden */
  1256. Button.prototype._onPointerEnter = function (target) {
  1257. if (!_super.prototype._onPointerEnter.call(this, target)) {
  1258. return false;
  1259. }
  1260. if (this.pointerEnterAnimation) {
  1261. this.pointerEnterAnimation();
  1262. }
  1263. return true;
  1264. };
  1265. /** @hidden */
  1266. Button.prototype._onPointerOut = function (target) {
  1267. if (this.pointerOutAnimation) {
  1268. this.pointerOutAnimation();
  1269. }
  1270. _super.prototype._onPointerOut.call(this, target);
  1271. };
  1272. /** @hidden */
  1273. Button.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  1274. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  1275. return false;
  1276. }
  1277. if (this.pointerDownAnimation) {
  1278. this.pointerDownAnimation();
  1279. }
  1280. return true;
  1281. };
  1282. /** @hidden */
  1283. Button.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  1284. if (this.pointerUpAnimation) {
  1285. this.pointerUpAnimation();
  1286. }
  1287. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  1288. };
  1289. // Statics
  1290. /**
  1291. * Creates a new button made with an image and a text
  1292. * @param name defines the name of the button
  1293. * @param text defines the text of the button
  1294. * @param imageUrl defines the url of the image
  1295. * @returns a new Button
  1296. */
  1297. Button.CreateImageButton = function (name, text, imageUrl) {
  1298. var result = new Button(name);
  1299. // Adding text
  1300. var textBlock = new textBlock_1.TextBlock(name + "_button", text);
  1301. textBlock.textWrapping = true;
  1302. textBlock.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1303. textBlock.paddingLeft = "20%";
  1304. result.addControl(textBlock);
  1305. // Adding image
  1306. var iconImage = new image_1.Image(name + "_icon", imageUrl);
  1307. iconImage.width = "20%";
  1308. iconImage.stretch = image_1.Image.STRETCH_UNIFORM;
  1309. iconImage.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1310. result.addControl(iconImage);
  1311. // Store
  1312. result._image = iconImage;
  1313. result._textBlock = textBlock;
  1314. return result;
  1315. };
  1316. /**
  1317. * Creates a new button made with an image
  1318. * @param name defines the name of the button
  1319. * @param imageUrl defines the url of the image
  1320. * @returns a new Button
  1321. */
  1322. Button.CreateImageOnlyButton = function (name, imageUrl) {
  1323. var result = new Button(name);
  1324. // Adding image
  1325. var iconImage = new image_1.Image(name + "_icon", imageUrl);
  1326. iconImage.stretch = image_1.Image.STRETCH_FILL;
  1327. iconImage.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1328. result.addControl(iconImage);
  1329. // Store
  1330. result._image = iconImage;
  1331. return result;
  1332. };
  1333. /**
  1334. * Creates a new button made with a text
  1335. * @param name defines the name of the button
  1336. * @param text defines the text of the button
  1337. * @returns a new Button
  1338. */
  1339. Button.CreateSimpleButton = function (name, text) {
  1340. var result = new Button(name);
  1341. // Adding text
  1342. var textBlock = new textBlock_1.TextBlock(name + "_button", text);
  1343. textBlock.textWrapping = true;
  1344. textBlock.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1345. result.addControl(textBlock);
  1346. // Store
  1347. result._textBlock = textBlock;
  1348. return result;
  1349. };
  1350. /**
  1351. * Creates a new button made with an image and a centered text
  1352. * @param name defines the name of the button
  1353. * @param text defines the text of the button
  1354. * @param imageUrl defines the url of the image
  1355. * @returns a new Button
  1356. */
  1357. Button.CreateImageWithCenterTextButton = function (name, text, imageUrl) {
  1358. var result = new Button(name);
  1359. // Adding image
  1360. var iconImage = new image_1.Image(name + "_icon", imageUrl);
  1361. iconImage.stretch = image_1.Image.STRETCH_FILL;
  1362. result.addControl(iconImage);
  1363. // Adding text
  1364. var textBlock = new textBlock_1.TextBlock(name + "_button", text);
  1365. textBlock.textWrapping = true;
  1366. textBlock.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_CENTER;
  1367. result.addControl(textBlock);
  1368. // Store
  1369. result._image = iconImage;
  1370. result._textBlock = textBlock;
  1371. return result;
  1372. };
  1373. return Button;
  1374. }(rectangle_1.Rectangle));
  1375. exports.Button = Button;
  1376. /***/ }),
  1377. /***/ "./src/2D/controls/checkbox.ts":
  1378. /*!*************************************!*\
  1379. !*** ./src/2D/controls/checkbox.ts ***!
  1380. \*************************************/
  1381. /*! no static exports found */
  1382. /***/ (function(module, exports, __webpack_require__) {
  1383. "use strict";
  1384. var __extends = (this && this.__extends) || (function () {
  1385. var extendStatics = function (d, b) {
  1386. extendStatics = Object.setPrototypeOf ||
  1387. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1388. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1389. return extendStatics(d, b);
  1390. }
  1391. return function (d, b) {
  1392. extendStatics(d, b);
  1393. function __() { this.constructor = d; }
  1394. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1395. };
  1396. })();
  1397. Object.defineProperty(exports, "__esModule", { value: true });
  1398. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  1399. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  1400. var stackPanel_1 = __webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts");
  1401. var textBlock_1 = __webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts");
  1402. /**
  1403. * Class used to represent a 2D checkbox
  1404. */
  1405. var Checkbox = /** @class */ (function (_super) {
  1406. __extends(Checkbox, _super);
  1407. /**
  1408. * Creates a new CheckBox
  1409. * @param name defines the control name
  1410. */
  1411. function Checkbox(name) {
  1412. var _this = _super.call(this, name) || this;
  1413. _this.name = name;
  1414. _this._isChecked = false;
  1415. _this._background = "black";
  1416. _this._checkSizeRatio = 0.8;
  1417. _this._thickness = 1;
  1418. /**
  1419. * Observable raised when isChecked property changes
  1420. */
  1421. _this.onIsCheckedChangedObservable = new babylonjs_1.Observable();
  1422. _this.isPointerBlocker = true;
  1423. return _this;
  1424. }
  1425. Object.defineProperty(Checkbox.prototype, "thickness", {
  1426. /** Gets or sets border thickness */
  1427. get: function () {
  1428. return this._thickness;
  1429. },
  1430. set: function (value) {
  1431. if (this._thickness === value) {
  1432. return;
  1433. }
  1434. this._thickness = value;
  1435. this._markAsDirty();
  1436. },
  1437. enumerable: true,
  1438. configurable: true
  1439. });
  1440. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  1441. /** Gets or sets a value indicating the ratio between overall size and check size */
  1442. get: function () {
  1443. return this._checkSizeRatio;
  1444. },
  1445. set: function (value) {
  1446. value = Math.max(Math.min(1, value), 0);
  1447. if (this._checkSizeRatio === value) {
  1448. return;
  1449. }
  1450. this._checkSizeRatio = value;
  1451. this._markAsDirty();
  1452. },
  1453. enumerable: true,
  1454. configurable: true
  1455. });
  1456. Object.defineProperty(Checkbox.prototype, "background", {
  1457. /** Gets or sets background color */
  1458. get: function () {
  1459. return this._background;
  1460. },
  1461. set: function (value) {
  1462. if (this._background === value) {
  1463. return;
  1464. }
  1465. this._background = value;
  1466. this._markAsDirty();
  1467. },
  1468. enumerable: true,
  1469. configurable: true
  1470. });
  1471. Object.defineProperty(Checkbox.prototype, "isChecked", {
  1472. /** Gets or sets a boolean indicating if the checkbox is checked or not */
  1473. get: function () {
  1474. return this._isChecked;
  1475. },
  1476. set: function (value) {
  1477. if (this._isChecked === value) {
  1478. return;
  1479. }
  1480. this._isChecked = value;
  1481. this._markAsDirty();
  1482. this.onIsCheckedChangedObservable.notifyObservers(value);
  1483. },
  1484. enumerable: true,
  1485. configurable: true
  1486. });
  1487. Checkbox.prototype._getTypeName = function () {
  1488. return "CheckBox";
  1489. };
  1490. /** @hidden */
  1491. Checkbox.prototype._draw = function (parentMeasure, context) {
  1492. context.save();
  1493. this._applyStates(context);
  1494. if (this._processMeasures(parentMeasure, context)) {
  1495. var actualWidth = this._currentMeasure.width - this._thickness;
  1496. var actualHeight = this._currentMeasure.height - this._thickness;
  1497. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1498. context.shadowColor = this.shadowColor;
  1499. context.shadowBlur = this.shadowBlur;
  1500. context.shadowOffsetX = this.shadowOffsetX;
  1501. context.shadowOffsetY = this.shadowOffsetY;
  1502. }
  1503. context.fillStyle = this._isEnabled ? this._background : this._disabledColor;
  1504. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  1505. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1506. context.shadowBlur = 0;
  1507. context.shadowOffsetX = 0;
  1508. context.shadowOffsetY = 0;
  1509. }
  1510. if (this._isChecked) {
  1511. context.fillStyle = this._isEnabled ? this.color : this._disabledColor;
  1512. var offsetWidth = actualWidth * this._checkSizeRatio;
  1513. var offseHeight = actualHeight * this._checkSizeRatio;
  1514. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  1515. }
  1516. context.strokeStyle = this.color;
  1517. context.lineWidth = this._thickness;
  1518. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  1519. }
  1520. context.restore();
  1521. };
  1522. // Events
  1523. /** @hidden */
  1524. Checkbox.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  1525. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  1526. return false;
  1527. }
  1528. this.isChecked = !this.isChecked;
  1529. return true;
  1530. };
  1531. /**
  1532. * Utility function to easily create a checkbox with a header
  1533. * @param title defines the label to use for the header
  1534. * @param onValueChanged defines the callback to call when value changes
  1535. * @returns a StackPanel containing the checkbox and a textBlock
  1536. */
  1537. Checkbox.AddCheckBoxWithHeader = function (title, onValueChanged) {
  1538. var panel = new stackPanel_1.StackPanel();
  1539. panel.isVertical = false;
  1540. panel.height = "30px";
  1541. var checkbox = new Checkbox();
  1542. checkbox.width = "20px";
  1543. checkbox.height = "20px";
  1544. checkbox.isChecked = true;
  1545. checkbox.color = "green";
  1546. checkbox.onIsCheckedChangedObservable.add(onValueChanged);
  1547. panel.addControl(checkbox);
  1548. var header = new textBlock_1.TextBlock();
  1549. header.text = title;
  1550. header.width = "180px";
  1551. header.paddingLeft = "5px";
  1552. header.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  1553. header.color = "white";
  1554. panel.addControl(header);
  1555. return panel;
  1556. };
  1557. return Checkbox;
  1558. }(control_1.Control));
  1559. exports.Checkbox = Checkbox;
  1560. /***/ }),
  1561. /***/ "./src/2D/controls/colorpicker.ts":
  1562. /*!****************************************!*\
  1563. !*** ./src/2D/controls/colorpicker.ts ***!
  1564. \****************************************/
  1565. /*! no static exports found */
  1566. /***/ (function(module, exports, __webpack_require__) {
  1567. "use strict";
  1568. var __extends = (this && this.__extends) || (function () {
  1569. var extendStatics = function (d, b) {
  1570. extendStatics = Object.setPrototypeOf ||
  1571. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1572. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1573. return extendStatics(d, b);
  1574. }
  1575. return function (d, b) {
  1576. extendStatics(d, b);
  1577. function __() { this.constructor = d; }
  1578. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1579. };
  1580. })();
  1581. Object.defineProperty(exports, "__esModule", { value: true });
  1582. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  1583. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  1584. /** Class used to create color pickers */
  1585. var ColorPicker = /** @class */ (function (_super) {
  1586. __extends(ColorPicker, _super);
  1587. /**
  1588. * Creates a new ColorPicker
  1589. * @param name defines the control name
  1590. */
  1591. function ColorPicker(name) {
  1592. var _this = _super.call(this, name) || this;
  1593. _this.name = name;
  1594. _this._value = babylonjs_1.Color3.Red();
  1595. _this._tmpColor = new babylonjs_1.Color3();
  1596. _this._pointerStartedOnSquare = false;
  1597. _this._pointerStartedOnWheel = false;
  1598. _this._squareLeft = 0;
  1599. _this._squareTop = 0;
  1600. _this._squareSize = 0;
  1601. _this._h = 360;
  1602. _this._s = 1;
  1603. _this._v = 1;
  1604. /**
  1605. * Observable raised when the value changes
  1606. */
  1607. _this.onValueChangedObservable = new babylonjs_1.Observable();
  1608. // Events
  1609. _this._pointerIsDown = false;
  1610. _this.value = new babylonjs_1.Color3(.88, .1, .1);
  1611. _this.size = "200px";
  1612. _this.isPointerBlocker = true;
  1613. return _this;
  1614. }
  1615. Object.defineProperty(ColorPicker.prototype, "value", {
  1616. /** Gets or sets the color of the color picker */
  1617. get: function () {
  1618. return this._value;
  1619. },
  1620. set: function (value) {
  1621. if (this._value.equals(value)) {
  1622. return;
  1623. }
  1624. this._value.copyFrom(value);
  1625. this._RGBtoHSV(this._value, this._tmpColor);
  1626. this._h = this._tmpColor.r;
  1627. this._s = Math.max(this._tmpColor.g, 0.00001);
  1628. this._v = Math.max(this._tmpColor.b, 0.00001);
  1629. this._markAsDirty();
  1630. this.onValueChangedObservable.notifyObservers(this._value);
  1631. },
  1632. enumerable: true,
  1633. configurable: true
  1634. });
  1635. Object.defineProperty(ColorPicker.prototype, "width", {
  1636. /** Gets or sets control width */
  1637. set: function (value) {
  1638. if (this._width.toString(this._host) === value) {
  1639. return;
  1640. }
  1641. if (this._width.fromString(value)) {
  1642. this._height.fromString(value);
  1643. this._markAsDirty();
  1644. }
  1645. },
  1646. enumerable: true,
  1647. configurable: true
  1648. });
  1649. Object.defineProperty(ColorPicker.prototype, "height", {
  1650. /** Gets or sets control height */
  1651. set: function (value) {
  1652. if (this._height.toString(this._host) === value) {
  1653. return;
  1654. }
  1655. if (this._height.fromString(value)) {
  1656. this._width.fromString(value);
  1657. this._markAsDirty();
  1658. }
  1659. },
  1660. enumerable: true,
  1661. configurable: true
  1662. });
  1663. Object.defineProperty(ColorPicker.prototype, "size", {
  1664. /** Gets or sets control size */
  1665. get: function () {
  1666. return this.width;
  1667. },
  1668. set: function (value) {
  1669. this.width = value;
  1670. },
  1671. enumerable: true,
  1672. configurable: true
  1673. });
  1674. ColorPicker.prototype._getTypeName = function () {
  1675. return "ColorPicker";
  1676. };
  1677. ColorPicker.prototype._updateSquareProps = function () {
  1678. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  1679. var wheelThickness = radius * .2;
  1680. var innerDiameter = (radius - wheelThickness) * 2;
  1681. var squareSize = innerDiameter / (Math.sqrt(2));
  1682. var offset = radius - squareSize * .5;
  1683. this._squareLeft = this._currentMeasure.left + offset;
  1684. this._squareTop = this._currentMeasure.top + offset;
  1685. this._squareSize = squareSize;
  1686. };
  1687. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  1688. var lgh = context.createLinearGradient(left, top, width + left, top);
  1689. lgh.addColorStop(0, '#fff');
  1690. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  1691. context.fillStyle = lgh;
  1692. context.fillRect(left, top, width, height);
  1693. var lgv = context.createLinearGradient(left, top, left, height + top);
  1694. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  1695. lgv.addColorStop(1, '#000');
  1696. context.fillStyle = lgv;
  1697. context.fillRect(left, top, width, height);
  1698. };
  1699. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  1700. context.beginPath();
  1701. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  1702. context.lineWidth = 3;
  1703. context.strokeStyle = '#333333';
  1704. context.stroke();
  1705. context.beginPath();
  1706. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  1707. context.lineWidth = 3;
  1708. context.strokeStyle = '#ffffff';
  1709. context.stroke();
  1710. };
  1711. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  1712. var canvas = document.createElement("canvas");
  1713. canvas.width = radius * 2;
  1714. canvas.height = radius * 2;
  1715. var context = canvas.getContext("2d");
  1716. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  1717. var data = image.data;
  1718. var color = this._tmpColor;
  1719. var maxDistSq = radius * radius;
  1720. var innerRadius = radius - thickness;
  1721. var minDistSq = innerRadius * innerRadius;
  1722. for (var x = -radius; x < radius; x++) {
  1723. for (var y = -radius; y < radius; y++) {
  1724. var distSq = x * x + y * y;
  1725. if (distSq > maxDistSq || distSq < minDistSq) {
  1726. continue;
  1727. }
  1728. var dist = Math.sqrt(distSq);
  1729. var ang = Math.atan2(y, x);
  1730. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  1731. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  1732. data[index] = color.r * 255;
  1733. data[index + 1] = color.g * 255;
  1734. data[index + 2] = color.b * 255;
  1735. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  1736. //apply less alpha to bigger color pickers
  1737. var alphaAmount = .2;
  1738. var maxAlpha = .2;
  1739. var minAlpha = .04;
  1740. var lowerRadius = 50;
  1741. var upperRadius = 150;
  1742. if (radius < lowerRadius) {
  1743. alphaAmount = maxAlpha;
  1744. }
  1745. else if (radius > upperRadius) {
  1746. alphaAmount = minAlpha;
  1747. }
  1748. else {
  1749. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  1750. }
  1751. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  1752. if (alphaRatio < alphaAmount) {
  1753. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  1754. }
  1755. else if (alphaRatio > 1 - alphaAmount) {
  1756. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  1757. }
  1758. else {
  1759. data[index + 3] = 255;
  1760. }
  1761. }
  1762. }
  1763. context.putImageData(image, 0, 0);
  1764. return canvas;
  1765. };
  1766. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  1767. var r = color.r;
  1768. var g = color.g;
  1769. var b = color.b;
  1770. var max = Math.max(r, g, b);
  1771. var min = Math.min(r, g, b);
  1772. var h = 0;
  1773. var s = 0;
  1774. var v = max;
  1775. var dm = max - min;
  1776. if (max !== 0) {
  1777. s = dm / max;
  1778. }
  1779. if (max != min) {
  1780. if (max == r) {
  1781. h = (g - b) / dm;
  1782. if (g < b) {
  1783. h += 6;
  1784. }
  1785. }
  1786. else if (max == g) {
  1787. h = (b - r) / dm + 2;
  1788. }
  1789. else if (max == b) {
  1790. h = (r - g) / dm + 4;
  1791. }
  1792. h *= 60;
  1793. }
  1794. result.r = h;
  1795. result.g = s;
  1796. result.b = v;
  1797. };
  1798. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  1799. var chroma = value * saturation;
  1800. var h = hue / 60;
  1801. var x = chroma * (1 - Math.abs((h % 2) - 1));
  1802. var r = 0;
  1803. var g = 0;
  1804. var b = 0;
  1805. if (h >= 0 && h <= 1) {
  1806. r = chroma;
  1807. g = x;
  1808. }
  1809. else if (h >= 1 && h <= 2) {
  1810. r = x;
  1811. g = chroma;
  1812. }
  1813. else if (h >= 2 && h <= 3) {
  1814. g = chroma;
  1815. b = x;
  1816. }
  1817. else if (h >= 3 && h <= 4) {
  1818. g = x;
  1819. b = chroma;
  1820. }
  1821. else if (h >= 4 && h <= 5) {
  1822. r = x;
  1823. b = chroma;
  1824. }
  1825. else if (h >= 5 && h <= 6) {
  1826. r = chroma;
  1827. b = x;
  1828. }
  1829. var m = value - chroma;
  1830. result.set((r + m), (g + m), (b + m));
  1831. };
  1832. /** @hidden */
  1833. ColorPicker.prototype._draw = function (parentMeasure, context) {
  1834. context.save();
  1835. this._applyStates(context);
  1836. if (this._processMeasures(parentMeasure, context)) {
  1837. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  1838. var wheelThickness = radius * .2;
  1839. var left = this._currentMeasure.left;
  1840. var top = this._currentMeasure.top;
  1841. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  1842. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  1843. }
  1844. this._updateSquareProps();
  1845. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1846. context.shadowColor = this.shadowColor;
  1847. context.shadowBlur = this.shadowBlur;
  1848. context.shadowOffsetX = this.shadowOffsetX;
  1849. context.shadowOffsetY = this.shadowOffsetY;
  1850. context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
  1851. }
  1852. context.drawImage(this._colorWheelCanvas, left, top);
  1853. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  1854. context.shadowBlur = 0;
  1855. context.shadowOffsetX = 0;
  1856. context.shadowOffsetY = 0;
  1857. }
  1858. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  1859. var cx = this._squareLeft + this._squareSize * this._s;
  1860. var cy = this._squareTop + this._squareSize * (1 - this._v);
  1861. this._drawCircle(cx, cy, radius * .04, context);
  1862. var dist = radius - wheelThickness * .5;
  1863. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  1864. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  1865. this._drawCircle(cx, cy, wheelThickness * .35, context);
  1866. }
  1867. context.restore();
  1868. };
  1869. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  1870. if (this._pointerStartedOnWheel) {
  1871. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  1872. var centerX = radius + this._currentMeasure.left;
  1873. var centerY = radius + this._currentMeasure.top;
  1874. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  1875. }
  1876. else if (this._pointerStartedOnSquare) {
  1877. this._updateSquareProps();
  1878. this._s = (x - this._squareLeft) / this._squareSize;
  1879. this._v = 1 - (y - this._squareTop) / this._squareSize;
  1880. this._s = Math.min(this._s, 1);
  1881. this._s = Math.max(this._s, 0.00001);
  1882. this._v = Math.min(this._v, 1);
  1883. this._v = Math.max(this._v, 0.00001);
  1884. }
  1885. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  1886. this.value = this._tmpColor;
  1887. };
  1888. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  1889. this._updateSquareProps();
  1890. var left = this._squareLeft;
  1891. var top = this._squareTop;
  1892. var size = this._squareSize;
  1893. if (coordinates.x >= left && coordinates.x <= left + size &&
  1894. coordinates.y >= top && coordinates.y <= top + size) {
  1895. return true;
  1896. }
  1897. return false;
  1898. };
  1899. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  1900. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  1901. var centerX = radius + this._currentMeasure.left;
  1902. var centerY = radius + this._currentMeasure.top;
  1903. var wheelThickness = radius * .2;
  1904. var innerRadius = radius - wheelThickness;
  1905. var radiusSq = radius * radius;
  1906. var innerRadiusSq = innerRadius * innerRadius;
  1907. var dx = coordinates.x - centerX;
  1908. var dy = coordinates.y - centerY;
  1909. var distSq = dx * dx + dy * dy;
  1910. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  1911. return true;
  1912. }
  1913. return false;
  1914. };
  1915. ColorPicker.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  1916. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  1917. return false;
  1918. }
  1919. this._pointerIsDown = true;
  1920. this._pointerStartedOnSquare = false;
  1921. this._pointerStartedOnWheel = false;
  1922. if (this._isPointOnSquare(coordinates)) {
  1923. this._pointerStartedOnSquare = true;
  1924. }
  1925. else if (this._isPointOnWheel(coordinates)) {
  1926. this._pointerStartedOnWheel = true;
  1927. }
  1928. this._updateValueFromPointer(coordinates.x, coordinates.y);
  1929. this._host._capturingControl[pointerId] = this;
  1930. return true;
  1931. };
  1932. ColorPicker.prototype._onPointerMove = function (target, coordinates) {
  1933. if (this._pointerIsDown) {
  1934. this._updateValueFromPointer(coordinates.x, coordinates.y);
  1935. }
  1936. _super.prototype._onPointerMove.call(this, target, coordinates);
  1937. };
  1938. ColorPicker.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  1939. this._pointerIsDown = false;
  1940. delete this._host._capturingControl[pointerId];
  1941. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  1942. };
  1943. return ColorPicker;
  1944. }(control_1.Control));
  1945. exports.ColorPicker = ColorPicker;
  1946. /***/ }),
  1947. /***/ "./src/2D/controls/container.ts":
  1948. /*!**************************************!*\
  1949. !*** ./src/2D/controls/container.ts ***!
  1950. \**************************************/
  1951. /*! no static exports found */
  1952. /***/ (function(module, exports, __webpack_require__) {
  1953. "use strict";
  1954. var __extends = (this && this.__extends) || (function () {
  1955. var extendStatics = function (d, b) {
  1956. extendStatics = Object.setPrototypeOf ||
  1957. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1958. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1959. return extendStatics(d, b);
  1960. }
  1961. return function (d, b) {
  1962. extendStatics(d, b);
  1963. function __() { this.constructor = d; }
  1964. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1965. };
  1966. })();
  1967. Object.defineProperty(exports, "__esModule", { value: true });
  1968. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  1969. var measure_1 = __webpack_require__(/*! ../measure */ "./src/2D/measure.ts");
  1970. /**
  1971. * Root class for 2D containers
  1972. * @see http://doc.babylonjs.com/how_to/gui#containers
  1973. */
  1974. var Container = /** @class */ (function (_super) {
  1975. __extends(Container, _super);
  1976. /**
  1977. * Creates a new Container
  1978. * @param name defines the name of the container
  1979. */
  1980. function Container(name) {
  1981. var _this = _super.call(this, name) || this;
  1982. _this.name = name;
  1983. /** @hidden */
  1984. _this._children = new Array();
  1985. /** @hidden */
  1986. _this._measureForChildren = measure_1.Measure.Empty();
  1987. /** @hidden */
  1988. _this._adaptWidthToChildren = false;
  1989. /** @hidden */
  1990. _this._adaptHeightToChildren = false;
  1991. return _this;
  1992. }
  1993. Object.defineProperty(Container.prototype, "adaptHeightToChildren", {
  1994. /** Gets or sets a boolean indicating if the container should try to adapt to its children height */
  1995. get: function () {
  1996. return this._adaptHeightToChildren;
  1997. },
  1998. set: function (value) {
  1999. if (this._adaptHeightToChildren === value) {
  2000. return;
  2001. }
  2002. this._adaptHeightToChildren = value;
  2003. if (value) {
  2004. this.height = "100%";
  2005. }
  2006. this._markAsDirty();
  2007. },
  2008. enumerable: true,
  2009. configurable: true
  2010. });
  2011. Object.defineProperty(Container.prototype, "adaptWidthToChildren", {
  2012. /** Gets or sets a boolean indicating if the container should try to adapt to its children width */
  2013. get: function () {
  2014. return this._adaptWidthToChildren;
  2015. },
  2016. set: function (value) {
  2017. if (this._adaptWidthToChildren === value) {
  2018. return;
  2019. }
  2020. this._adaptWidthToChildren = value;
  2021. if (value) {
  2022. this.width = "100%";
  2023. }
  2024. this._markAsDirty();
  2025. },
  2026. enumerable: true,
  2027. configurable: true
  2028. });
  2029. Object.defineProperty(Container.prototype, "background", {
  2030. /** Gets or sets background color */
  2031. get: function () {
  2032. return this._background;
  2033. },
  2034. set: function (value) {
  2035. if (this._background === value) {
  2036. return;
  2037. }
  2038. this._background = value;
  2039. this._markAsDirty();
  2040. },
  2041. enumerable: true,
  2042. configurable: true
  2043. });
  2044. Object.defineProperty(Container.prototype, "children", {
  2045. /** Gets the list of children */
  2046. get: function () {
  2047. return this._children;
  2048. },
  2049. enumerable: true,
  2050. configurable: true
  2051. });
  2052. Container.prototype._getTypeName = function () {
  2053. return "Container";
  2054. };
  2055. Container.prototype._flagDescendantsAsMatrixDirty = function () {
  2056. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  2057. var child = _a[_i];
  2058. child._markMatrixAsDirty();
  2059. }
  2060. };
  2061. /**
  2062. * Gets a child using its name
  2063. * @param name defines the child name to look for
  2064. * @returns the child control if found
  2065. */
  2066. Container.prototype.getChildByName = function (name) {
  2067. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  2068. var child = _a[_i];
  2069. if (child.name === name) {
  2070. return child;
  2071. }
  2072. }
  2073. return null;
  2074. };
  2075. /**
  2076. * Gets a child using its type and its name
  2077. * @param name defines the child name to look for
  2078. * @param type defines the child type to look for
  2079. * @returns the child control if found
  2080. */
  2081. Container.prototype.getChildByType = function (name, type) {
  2082. for (var _i = 0, _a = this.children; _i < _a.length; _i++) {
  2083. var child = _a[_i];
  2084. if (child.typeName === type) {
  2085. return child;
  2086. }
  2087. }
  2088. return null;
  2089. };
  2090. /**
  2091. * Search for a specific control in children
  2092. * @param control defines the control to look for
  2093. * @returns true if the control is in child list
  2094. */
  2095. Container.prototype.containsControl = function (control) {
  2096. return this.children.indexOf(control) !== -1;
  2097. };
  2098. /**
  2099. * Adds a new control to the current container
  2100. * @param control defines the control to add
  2101. * @returns the current container
  2102. */
  2103. Container.prototype.addControl = function (control) {
  2104. if (!control) {
  2105. return this;
  2106. }
  2107. var index = this._children.indexOf(control);
  2108. if (index !== -1) {
  2109. return this;
  2110. }
  2111. control._link(this, this._host);
  2112. control._markAllAsDirty();
  2113. this._reOrderControl(control);
  2114. this._markAsDirty();
  2115. return this;
  2116. };
  2117. /**
  2118. * Removes all controls from the current container
  2119. * @returns the current container
  2120. */
  2121. Container.prototype.clearControls = function () {
  2122. var children = this._children.slice();
  2123. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  2124. var child = children_1[_i];
  2125. this.removeControl(child);
  2126. }
  2127. return this;
  2128. };
  2129. /**
  2130. * Removes a control from the current container
  2131. * @param control defines the control to remove
  2132. * @returns the current container
  2133. */
  2134. Container.prototype.removeControl = function (control) {
  2135. var index = this._children.indexOf(control);
  2136. if (index !== -1) {
  2137. this._children.splice(index, 1);
  2138. control.parent = null;
  2139. }
  2140. control.linkWithMesh(null);
  2141. if (this._host) {
  2142. this._host._cleanControlAfterRemoval(control);
  2143. }
  2144. this._markAsDirty();
  2145. return this;
  2146. };
  2147. /** @hidden */
  2148. Container.prototype._reOrderControl = function (control) {
  2149. this.removeControl(control);
  2150. for (var index = 0; index < this._children.length; index++) {
  2151. if (this._children[index].zIndex > control.zIndex) {
  2152. this._children.splice(index, 0, control);
  2153. return;
  2154. }
  2155. }
  2156. this._children.push(control);
  2157. control.parent = this;
  2158. this._markAsDirty();
  2159. };
  2160. /** @hidden */
  2161. Container.prototype._markAllAsDirty = function () {
  2162. _super.prototype._markAllAsDirty.call(this);
  2163. for (var index = 0; index < this._children.length; index++) {
  2164. this._children[index]._markAllAsDirty();
  2165. }
  2166. };
  2167. /** @hidden */
  2168. Container.prototype._localDraw = function (context) {
  2169. if (this._background) {
  2170. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2171. context.shadowColor = this.shadowColor;
  2172. context.shadowBlur = this.shadowBlur;
  2173. context.shadowOffsetX = this.shadowOffsetX;
  2174. context.shadowOffsetY = this.shadowOffsetY;
  2175. }
  2176. context.fillStyle = this._background;
  2177. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2178. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2179. context.shadowBlur = 0;
  2180. context.shadowOffsetX = 0;
  2181. context.shadowOffsetY = 0;
  2182. }
  2183. }
  2184. };
  2185. /** @hidden */
  2186. Container.prototype._link = function (root, host) {
  2187. _super.prototype._link.call(this, root, host);
  2188. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2189. var child = _a[_i];
  2190. child._link(this, host);
  2191. }
  2192. };
  2193. /** @hidden */
  2194. Container.prototype._draw = function (parentMeasure, context) {
  2195. if (!this.isVisible || this.notRenderable) {
  2196. return;
  2197. }
  2198. context.save();
  2199. this._applyStates(context);
  2200. if (this._processMeasures(parentMeasure, context)) {
  2201. this._localDraw(context);
  2202. if (this.clipChildren) {
  2203. this._clipForChildren(context);
  2204. }
  2205. var computedWidth = -1;
  2206. var computedHeight = -1;
  2207. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2208. var child = _a[_i];
  2209. if (child.isVisible && !child.notRenderable) {
  2210. child._tempParentMeasure.copyFrom(this._measureForChildren);
  2211. child._draw(this._measureForChildren, context);
  2212. if (child.onAfterDrawObservable.hasObservers()) {
  2213. child.onAfterDrawObservable.notifyObservers(child);
  2214. }
  2215. if (this.adaptWidthToChildren && child._width.isPixel) {
  2216. computedWidth = Math.max(computedWidth, child._currentMeasure.width);
  2217. }
  2218. if (this.adaptHeightToChildren && child._height.isPixel) {
  2219. computedHeight = Math.max(computedHeight, child._currentMeasure.height);
  2220. }
  2221. }
  2222. }
  2223. if (this.adaptWidthToChildren && computedWidth >= 0) {
  2224. this.width = computedWidth + "px";
  2225. }
  2226. if (this.adaptHeightToChildren && computedHeight >= 0) {
  2227. this.height = computedHeight + "px";
  2228. }
  2229. }
  2230. context.restore();
  2231. if (this.onAfterDrawObservable.hasObservers()) {
  2232. this.onAfterDrawObservable.notifyObservers(this);
  2233. }
  2234. };
  2235. /** @hidden */
  2236. Container.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  2237. if (!this.isVisible || this.notRenderable) {
  2238. return false;
  2239. }
  2240. if (!_super.prototype.contains.call(this, x, y)) {
  2241. return false;
  2242. }
  2243. // Checking backwards to pick closest first
  2244. for (var index = this._children.length - 1; index >= 0; index--) {
  2245. var child = this._children[index];
  2246. if (child._processPicking(x, y, type, pointerId, buttonIndex)) {
  2247. if (child.hoverCursor) {
  2248. this._host._changeCursor(child.hoverCursor);
  2249. }
  2250. return true;
  2251. }
  2252. }
  2253. if (!this.isHitTestVisible) {
  2254. return false;
  2255. }
  2256. return this._processObservables(type, x, y, pointerId, buttonIndex);
  2257. };
  2258. /** @hidden */
  2259. Container.prototype._clipForChildren = function (context) {
  2260. // DO nothing
  2261. };
  2262. /** @hidden */
  2263. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  2264. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  2265. this._measureForChildren.copyFrom(this._currentMeasure);
  2266. };
  2267. /** Releases associated resources */
  2268. Container.prototype.dispose = function () {
  2269. _super.prototype.dispose.call(this);
  2270. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2271. var control = _a[_i];
  2272. control.dispose();
  2273. }
  2274. };
  2275. return Container;
  2276. }(control_1.Control));
  2277. exports.Container = Container;
  2278. /***/ }),
  2279. /***/ "./src/2D/controls/control.ts":
  2280. /*!************************************!*\
  2281. !*** ./src/2D/controls/control.ts ***!
  2282. \************************************/
  2283. /*! no static exports found */
  2284. /***/ (function(module, exports, __webpack_require__) {
  2285. "use strict";
  2286. Object.defineProperty(exports, "__esModule", { value: true });
  2287. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  2288. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  2289. var measure_1 = __webpack_require__(/*! ../measure */ "./src/2D/measure.ts");
  2290. var math2D_1 = __webpack_require__(/*! ../math2D */ "./src/2D/math2D.ts");
  2291. /**
  2292. * Root class used for all 2D controls
  2293. * @see http://doc.babylonjs.com/how_to/gui#controls
  2294. */
  2295. var Control = /** @class */ (function () {
  2296. // Functions
  2297. /**
  2298. * Creates a new control
  2299. * @param name defines the name of the control
  2300. */
  2301. function Control(
  2302. /** defines the name of the control */
  2303. name) {
  2304. this.name = name;
  2305. this._alpha = 1;
  2306. this._alphaSet = false;
  2307. this._zIndex = 0;
  2308. /** @hidden */
  2309. this._currentMeasure = measure_1.Measure.Empty();
  2310. this._fontFamily = "Arial";
  2311. this._fontStyle = "";
  2312. this._fontWeight = "";
  2313. this._fontSize = new valueAndUnit_1.ValueAndUnit(18, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL, false);
  2314. /** @hidden */
  2315. this._width = new valueAndUnit_1.ValueAndUnit(1, valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  2316. /** @hidden */
  2317. this._height = new valueAndUnit_1.ValueAndUnit(1, valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  2318. this._color = "";
  2319. this._style = null;
  2320. /** @hidden */
  2321. this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
  2322. /** @hidden */
  2323. this._verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
  2324. this._isDirty = true;
  2325. /** @hidden */
  2326. this._tempParentMeasure = measure_1.Measure.Empty();
  2327. /** @hidden */
  2328. this._cachedParentMeasure = measure_1.Measure.Empty();
  2329. this._paddingLeft = new valueAndUnit_1.ValueAndUnit(0);
  2330. this._paddingRight = new valueAndUnit_1.ValueAndUnit(0);
  2331. this._paddingTop = new valueAndUnit_1.ValueAndUnit(0);
  2332. this._paddingBottom = new valueAndUnit_1.ValueAndUnit(0);
  2333. /** @hidden */
  2334. this._left = new valueAndUnit_1.ValueAndUnit(0);
  2335. /** @hidden */
  2336. this._top = new valueAndUnit_1.ValueAndUnit(0);
  2337. this._scaleX = 1.0;
  2338. this._scaleY = 1.0;
  2339. this._rotation = 0;
  2340. this._transformCenterX = 0.5;
  2341. this._transformCenterY = 0.5;
  2342. this._transformMatrix = math2D_1.Matrix2D.Identity();
  2343. /** @hidden */
  2344. this._invertTransformMatrix = math2D_1.Matrix2D.Identity();
  2345. /** @hidden */
  2346. this._transformedPosition = babylonjs_1.Vector2.Zero();
  2347. this._onlyMeasureMode = false;
  2348. this._isMatrixDirty = true;
  2349. this._isVisible = true;
  2350. this._fontSet = false;
  2351. this._dummyVector2 = babylonjs_1.Vector2.Zero();
  2352. this._downCount = 0;
  2353. this._enterCount = -1;
  2354. this._doNotRender = false;
  2355. this._downPointerIds = {};
  2356. this._isEnabled = true;
  2357. this._disabledColor = "#9a9a9a";
  2358. /** Gets or sets a boolean indicating if the control can be hit with pointer events */
  2359. this.isHitTestVisible = true;
  2360. /** Gets or sets a boolean indicating if the control can block pointer events */
  2361. this.isPointerBlocker = false;
  2362. /** Gets or sets a boolean indicating if the control can be focusable */
  2363. this.isFocusInvisible = false;
  2364. /** Gets or sets a boolean indicating if the children are clipped to the current control bounds */
  2365. this.clipChildren = true;
  2366. /** Gets or sets a value indicating the offset to apply on X axis to render the shadow */
  2367. this.shadowOffsetX = 0;
  2368. /** Gets or sets a value indicating the offset to apply on Y axis to render the shadow */
  2369. this.shadowOffsetY = 0;
  2370. /** Gets or sets a value indicating the amount of blur to use to render the shadow */
  2371. this.shadowBlur = 0;
  2372. /** Gets or sets a value indicating the color of the shadow (black by default ie. "#000") */
  2373. this.shadowColor = '#000';
  2374. /** Gets or sets the cursor to use when the control is hovered */
  2375. this.hoverCursor = "";
  2376. /** @hidden */
  2377. this._linkOffsetX = new valueAndUnit_1.ValueAndUnit(0);
  2378. /** @hidden */
  2379. this._linkOffsetY = new valueAndUnit_1.ValueAndUnit(0);
  2380. /**
  2381. * An event triggered when the pointer move over the control.
  2382. */
  2383. this.onPointerMoveObservable = new babylonjs_1.Observable();
  2384. /**
  2385. * An event triggered when the pointer move out of the control.
  2386. */
  2387. this.onPointerOutObservable = new babylonjs_1.Observable();
  2388. /**
  2389. * An event triggered when the pointer taps the control
  2390. */
  2391. this.onPointerDownObservable = new babylonjs_1.Observable();
  2392. /**
  2393. * An event triggered when pointer up
  2394. */
  2395. this.onPointerUpObservable = new babylonjs_1.Observable();
  2396. /**
  2397. * An event triggered when a control is clicked on
  2398. */
  2399. this.onPointerClickObservable = new babylonjs_1.Observable();
  2400. /**
  2401. * An event triggered when pointer enters the control
  2402. */
  2403. this.onPointerEnterObservable = new babylonjs_1.Observable();
  2404. /**
  2405. * An event triggered when the control is marked as dirty
  2406. */
  2407. this.onDirtyObservable = new babylonjs_1.Observable();
  2408. /**
  2409. * An event triggered after the control is drawn
  2410. */
  2411. this.onAfterDrawObservable = new babylonjs_1.Observable();
  2412. }
  2413. Object.defineProperty(Control.prototype, "typeName", {
  2414. // Properties
  2415. /** Gets the control type name */
  2416. get: function () {
  2417. return this._getTypeName();
  2418. },
  2419. enumerable: true,
  2420. configurable: true
  2421. });
  2422. Object.defineProperty(Control.prototype, "fontOffset", {
  2423. /** Gets or set information about font offsets (used to render and align text) */
  2424. get: function () {
  2425. return this._fontOffset;
  2426. },
  2427. set: function (offset) {
  2428. this._fontOffset = offset;
  2429. },
  2430. enumerable: true,
  2431. configurable: true
  2432. });
  2433. Object.defineProperty(Control.prototype, "alpha", {
  2434. /** Gets or sets alpha value for the control (1 means opaque and 0 means entirely transparent) */
  2435. get: function () {
  2436. return this._alpha;
  2437. },
  2438. set: function (value) {
  2439. if (this._alpha === value) {
  2440. return;
  2441. }
  2442. this._alphaSet = true;
  2443. this._alpha = value;
  2444. this._markAsDirty();
  2445. },
  2446. enumerable: true,
  2447. configurable: true
  2448. });
  2449. Object.defineProperty(Control.prototype, "scaleX", {
  2450. /** Gets or sets a value indicating the scale factor on X axis (1 by default)
  2451. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2452. */
  2453. get: function () {
  2454. return this._scaleX;
  2455. },
  2456. set: function (value) {
  2457. if (this._scaleX === value) {
  2458. return;
  2459. }
  2460. this._scaleX = value;
  2461. this._markAsDirty();
  2462. this._markMatrixAsDirty();
  2463. },
  2464. enumerable: true,
  2465. configurable: true
  2466. });
  2467. Object.defineProperty(Control.prototype, "scaleY", {
  2468. /** Gets or sets a value indicating the scale factor on Y axis (1 by default)
  2469. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2470. */
  2471. get: function () {
  2472. return this._scaleY;
  2473. },
  2474. set: function (value) {
  2475. if (this._scaleY === value) {
  2476. return;
  2477. }
  2478. this._scaleY = value;
  2479. this._markAsDirty();
  2480. this._markMatrixAsDirty();
  2481. },
  2482. enumerable: true,
  2483. configurable: true
  2484. });
  2485. Object.defineProperty(Control.prototype, "rotation", {
  2486. /** Gets or sets the rotation angle (0 by default)
  2487. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2488. */
  2489. get: function () {
  2490. return this._rotation;
  2491. },
  2492. set: function (value) {
  2493. if (this._rotation === value) {
  2494. return;
  2495. }
  2496. this._rotation = value;
  2497. this._markAsDirty();
  2498. this._markMatrixAsDirty();
  2499. },
  2500. enumerable: true,
  2501. configurable: true
  2502. });
  2503. Object.defineProperty(Control.prototype, "transformCenterY", {
  2504. /** Gets or sets the transformation center on Y axis (0 by default)
  2505. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2506. */
  2507. get: function () {
  2508. return this._transformCenterY;
  2509. },
  2510. set: function (value) {
  2511. if (this._transformCenterY === value) {
  2512. return;
  2513. }
  2514. this._transformCenterY = value;
  2515. this._markAsDirty();
  2516. this._markMatrixAsDirty();
  2517. },
  2518. enumerable: true,
  2519. configurable: true
  2520. });
  2521. Object.defineProperty(Control.prototype, "transformCenterX", {
  2522. /** Gets or sets the transformation center on X axis (0 by default)
  2523. * @see http://doc.babylonjs.com/how_to/gui#rotation-and-scaling
  2524. */
  2525. get: function () {
  2526. return this._transformCenterX;
  2527. },
  2528. set: function (value) {
  2529. if (this._transformCenterX === value) {
  2530. return;
  2531. }
  2532. this._transformCenterX = value;
  2533. this._markAsDirty();
  2534. this._markMatrixAsDirty();
  2535. },
  2536. enumerable: true,
  2537. configurable: true
  2538. });
  2539. Object.defineProperty(Control.prototype, "horizontalAlignment", {
  2540. /**
  2541. * Gets or sets the horizontal alignment
  2542. * @see http://doc.babylonjs.com/how_to/gui#alignments
  2543. */
  2544. get: function () {
  2545. return this._horizontalAlignment;
  2546. },
  2547. set: function (value) {
  2548. if (this._horizontalAlignment === value) {
  2549. return;
  2550. }
  2551. this._horizontalAlignment = value;
  2552. this._markAsDirty();
  2553. },
  2554. enumerable: true,
  2555. configurable: true
  2556. });
  2557. Object.defineProperty(Control.prototype, "verticalAlignment", {
  2558. /**
  2559. * Gets or sets the vertical alignment
  2560. * @see http://doc.babylonjs.com/how_to/gui#alignments
  2561. */
  2562. get: function () {
  2563. return this._verticalAlignment;
  2564. },
  2565. set: function (value) {
  2566. if (this._verticalAlignment === value) {
  2567. return;
  2568. }
  2569. this._verticalAlignment = value;
  2570. this._markAsDirty();
  2571. },
  2572. enumerable: true,
  2573. configurable: true
  2574. });
  2575. Object.defineProperty(Control.prototype, "width", {
  2576. /**
  2577. * Gets or sets control width
  2578. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2579. */
  2580. get: function () {
  2581. return this._width.toString(this._host);
  2582. },
  2583. set: function (value) {
  2584. if (this._width.toString(this._host) === value) {
  2585. return;
  2586. }
  2587. if (this._width.fromString(value)) {
  2588. this._markAsDirty();
  2589. }
  2590. },
  2591. enumerable: true,
  2592. configurable: true
  2593. });
  2594. Object.defineProperty(Control.prototype, "widthInPixels", {
  2595. /**
  2596. * Gets control width in pixel
  2597. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2598. */
  2599. get: function () {
  2600. return this._width.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2601. },
  2602. enumerable: true,
  2603. configurable: true
  2604. });
  2605. Object.defineProperty(Control.prototype, "height", {
  2606. /**
  2607. * Gets or sets control height
  2608. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2609. */
  2610. get: function () {
  2611. return this._height.toString(this._host);
  2612. },
  2613. set: function (value) {
  2614. if (this._height.toString(this._host) === value) {
  2615. return;
  2616. }
  2617. if (this._height.fromString(value)) {
  2618. this._markAsDirty();
  2619. }
  2620. },
  2621. enumerable: true,
  2622. configurable: true
  2623. });
  2624. Object.defineProperty(Control.prototype, "heightInPixels", {
  2625. /**
  2626. * Gets control height in pixel
  2627. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2628. */
  2629. get: function () {
  2630. return this._height.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2631. },
  2632. enumerable: true,
  2633. configurable: true
  2634. });
  2635. Object.defineProperty(Control.prototype, "fontFamily", {
  2636. /** Gets or set font family */
  2637. get: function () {
  2638. return this._fontFamily;
  2639. },
  2640. set: function (value) {
  2641. if (this._fontFamily === value) {
  2642. return;
  2643. }
  2644. this._fontFamily = value;
  2645. this._resetFontCache();
  2646. },
  2647. enumerable: true,
  2648. configurable: true
  2649. });
  2650. Object.defineProperty(Control.prototype, "fontStyle", {
  2651. /** Gets or sets font style */
  2652. get: function () {
  2653. return this._fontStyle;
  2654. },
  2655. set: function (value) {
  2656. if (this._fontStyle === value) {
  2657. return;
  2658. }
  2659. this._fontStyle = value;
  2660. this._resetFontCache();
  2661. },
  2662. enumerable: true,
  2663. configurable: true
  2664. });
  2665. Object.defineProperty(Control.prototype, "fontWeight", {
  2666. /** Gets or sets font weight */
  2667. get: function () {
  2668. return this._fontWeight;
  2669. },
  2670. set: function (value) {
  2671. if (this._fontWeight === value) {
  2672. return;
  2673. }
  2674. this._fontWeight = value;
  2675. this._resetFontCache();
  2676. },
  2677. enumerable: true,
  2678. configurable: true
  2679. });
  2680. Object.defineProperty(Control.prototype, "style", {
  2681. /**
  2682. * Gets or sets style
  2683. * @see http://doc.babylonjs.com/how_to/gui#styles
  2684. */
  2685. get: function () {
  2686. return this._style;
  2687. },
  2688. set: function (value) {
  2689. var _this = this;
  2690. if (this._style) {
  2691. this._style.onChangedObservable.remove(this._styleObserver);
  2692. this._styleObserver = null;
  2693. }
  2694. this._style = value;
  2695. if (this._style) {
  2696. this._styleObserver = this._style.onChangedObservable.add(function () {
  2697. _this._markAsDirty();
  2698. _this._resetFontCache();
  2699. });
  2700. }
  2701. this._markAsDirty();
  2702. this._resetFontCache();
  2703. },
  2704. enumerable: true,
  2705. configurable: true
  2706. });
  2707. Object.defineProperty(Control.prototype, "_isFontSizeInPercentage", {
  2708. /** @hidden */
  2709. get: function () {
  2710. return this._fontSize.isPercentage;
  2711. },
  2712. enumerable: true,
  2713. configurable: true
  2714. });
  2715. Object.defineProperty(Control.prototype, "fontSizeInPixels", {
  2716. /** Gets font size in pixels */
  2717. get: function () {
  2718. var fontSizeToUse = this._style ? this._style._fontSize : this._fontSize;
  2719. if (fontSizeToUse.isPixel) {
  2720. return fontSizeToUse.getValue(this._host);
  2721. }
  2722. return fontSizeToUse.getValueInPixel(this._host, this._tempParentMeasure.height || this._cachedParentMeasure.height);
  2723. },
  2724. enumerable: true,
  2725. configurable: true
  2726. });
  2727. Object.defineProperty(Control.prototype, "fontSize", {
  2728. /** Gets or sets font size */
  2729. get: function () {
  2730. return this._fontSize.toString(this._host);
  2731. },
  2732. set: function (value) {
  2733. if (this._fontSize.toString(this._host) === value) {
  2734. return;
  2735. }
  2736. if (this._fontSize.fromString(value)) {
  2737. this._markAsDirty();
  2738. this._resetFontCache();
  2739. }
  2740. },
  2741. enumerable: true,
  2742. configurable: true
  2743. });
  2744. Object.defineProperty(Control.prototype, "color", {
  2745. /** Gets or sets foreground color */
  2746. get: function () {
  2747. return this._color;
  2748. },
  2749. set: function (value) {
  2750. if (this._color === value) {
  2751. return;
  2752. }
  2753. this._color = value;
  2754. this._markAsDirty();
  2755. },
  2756. enumerable: true,
  2757. configurable: true
  2758. });
  2759. Object.defineProperty(Control.prototype, "zIndex", {
  2760. /** Gets or sets z index which is used to reorder controls on the z axis */
  2761. get: function () {
  2762. return this._zIndex;
  2763. },
  2764. set: function (value) {
  2765. if (this.zIndex === value) {
  2766. return;
  2767. }
  2768. this._zIndex = value;
  2769. if (this._root) {
  2770. this._root._reOrderControl(this);
  2771. }
  2772. },
  2773. enumerable: true,
  2774. configurable: true
  2775. });
  2776. Object.defineProperty(Control.prototype, "notRenderable", {
  2777. /** Gets or sets a boolean indicating if the control can be rendered */
  2778. get: function () {
  2779. return this._doNotRender;
  2780. },
  2781. set: function (value) {
  2782. if (this._doNotRender === value) {
  2783. return;
  2784. }
  2785. this._doNotRender = value;
  2786. this._markAsDirty();
  2787. },
  2788. enumerable: true,
  2789. configurable: true
  2790. });
  2791. Object.defineProperty(Control.prototype, "isVisible", {
  2792. /** Gets or sets a boolean indicating if the control is visible */
  2793. get: function () {
  2794. return this._isVisible;
  2795. },
  2796. set: function (value) {
  2797. if (this._isVisible === value) {
  2798. return;
  2799. }
  2800. this._isVisible = value;
  2801. this._markAsDirty(true);
  2802. },
  2803. enumerable: true,
  2804. configurable: true
  2805. });
  2806. Object.defineProperty(Control.prototype, "isDirty", {
  2807. /** Gets a boolean indicating that the control needs to update its rendering */
  2808. get: function () {
  2809. return this._isDirty;
  2810. },
  2811. enumerable: true,
  2812. configurable: true
  2813. });
  2814. Object.defineProperty(Control.prototype, "linkedMesh", {
  2815. /**
  2816. * Gets the current linked mesh (or null if none)
  2817. */
  2818. get: function () {
  2819. return this._linkedMesh;
  2820. },
  2821. enumerable: true,
  2822. configurable: true
  2823. });
  2824. Object.defineProperty(Control.prototype, "paddingLeft", {
  2825. /**
  2826. * Gets or sets a value indicating the padding to use on the left of the control
  2827. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2828. */
  2829. get: function () {
  2830. return this._paddingLeft.toString(this._host);
  2831. },
  2832. set: function (value) {
  2833. if (this._paddingLeft.fromString(value)) {
  2834. this._markAsDirty();
  2835. }
  2836. },
  2837. enumerable: true,
  2838. configurable: true
  2839. });
  2840. Object.defineProperty(Control.prototype, "paddingLeftInPixels", {
  2841. /**
  2842. * Gets a value indicating the padding in pixels to use on the left of the control
  2843. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2844. */
  2845. get: function () {
  2846. return this._paddingLeft.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2847. },
  2848. enumerable: true,
  2849. configurable: true
  2850. });
  2851. Object.defineProperty(Control.prototype, "paddingRight", {
  2852. /**
  2853. * Gets or sets a value indicating the padding to use on the right of the control
  2854. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2855. */
  2856. get: function () {
  2857. return this._paddingRight.toString(this._host);
  2858. },
  2859. set: function (value) {
  2860. if (this._paddingRight.fromString(value)) {
  2861. this._markAsDirty();
  2862. }
  2863. },
  2864. enumerable: true,
  2865. configurable: true
  2866. });
  2867. Object.defineProperty(Control.prototype, "paddingRightInPixels", {
  2868. /**
  2869. * Gets a value indicating the padding in pixels to use on the right of the control
  2870. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2871. */
  2872. get: function () {
  2873. return this._paddingRight.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2874. },
  2875. enumerable: true,
  2876. configurable: true
  2877. });
  2878. Object.defineProperty(Control.prototype, "paddingTop", {
  2879. /**
  2880. * Gets or sets a value indicating the padding to use on the top of the control
  2881. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2882. */
  2883. get: function () {
  2884. return this._paddingTop.toString(this._host);
  2885. },
  2886. set: function (value) {
  2887. if (this._paddingTop.fromString(value)) {
  2888. this._markAsDirty();
  2889. }
  2890. },
  2891. enumerable: true,
  2892. configurable: true
  2893. });
  2894. Object.defineProperty(Control.prototype, "paddingTopInPixels", {
  2895. /**
  2896. * Gets a value indicating the padding in pixels to use on the top of the control
  2897. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2898. */
  2899. get: function () {
  2900. return this._paddingTop.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2901. },
  2902. enumerable: true,
  2903. configurable: true
  2904. });
  2905. Object.defineProperty(Control.prototype, "paddingBottom", {
  2906. /**
  2907. * Gets or sets a value indicating the padding to use on the bottom of the control
  2908. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2909. */
  2910. get: function () {
  2911. return this._paddingBottom.toString(this._host);
  2912. },
  2913. set: function (value) {
  2914. if (this._paddingBottom.fromString(value)) {
  2915. this._markAsDirty();
  2916. }
  2917. },
  2918. enumerable: true,
  2919. configurable: true
  2920. });
  2921. Object.defineProperty(Control.prototype, "paddingBottomInPixels", {
  2922. /**
  2923. * Gets a value indicating the padding in pixels to use on the bottom of the control
  2924. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2925. */
  2926. get: function () {
  2927. return this._paddingBottom.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2928. },
  2929. enumerable: true,
  2930. configurable: true
  2931. });
  2932. Object.defineProperty(Control.prototype, "left", {
  2933. /**
  2934. * Gets or sets a value indicating the left coordinate of the control
  2935. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2936. */
  2937. get: function () {
  2938. return this._left.toString(this._host);
  2939. },
  2940. set: function (value) {
  2941. if (this._left.fromString(value)) {
  2942. this._markAsDirty();
  2943. }
  2944. },
  2945. enumerable: true,
  2946. configurable: true
  2947. });
  2948. Object.defineProperty(Control.prototype, "leftInPixels", {
  2949. /**
  2950. * Gets a value indicating the left coordinate in pixels of the control
  2951. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2952. */
  2953. get: function () {
  2954. return this._left.getValueInPixel(this._host, this._cachedParentMeasure.width);
  2955. },
  2956. enumerable: true,
  2957. configurable: true
  2958. });
  2959. Object.defineProperty(Control.prototype, "top", {
  2960. /**
  2961. * Gets or sets a value indicating the top coordinate of the control
  2962. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2963. */
  2964. get: function () {
  2965. return this._top.toString(this._host);
  2966. },
  2967. set: function (value) {
  2968. if (this._top.fromString(value)) {
  2969. this._markAsDirty();
  2970. }
  2971. },
  2972. enumerable: true,
  2973. configurable: true
  2974. });
  2975. Object.defineProperty(Control.prototype, "topInPixels", {
  2976. /**
  2977. * Gets a value indicating the top coordinate in pixels of the control
  2978. * @see http://doc.babylonjs.com/how_to/gui#position-and-size
  2979. */
  2980. get: function () {
  2981. return this._top.getValueInPixel(this._host, this._cachedParentMeasure.height);
  2982. },
  2983. enumerable: true,
  2984. configurable: true
  2985. });
  2986. Object.defineProperty(Control.prototype, "linkOffsetX", {
  2987. /**
  2988. * Gets or sets a value indicating the offset on X axis to the linked mesh
  2989. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  2990. */
  2991. get: function () {
  2992. return this._linkOffsetX.toString(this._host);
  2993. },
  2994. set: function (value) {
  2995. if (this._linkOffsetX.fromString(value)) {
  2996. this._markAsDirty();
  2997. }
  2998. },
  2999. enumerable: true,
  3000. configurable: true
  3001. });
  3002. Object.defineProperty(Control.prototype, "linkOffsetXInPixels", {
  3003. /**
  3004. * Gets a value indicating the offset in pixels on X axis to the linked mesh
  3005. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  3006. */
  3007. get: function () {
  3008. return this._linkOffsetX.getValueInPixel(this._host, this._cachedParentMeasure.width);
  3009. },
  3010. enumerable: true,
  3011. configurable: true
  3012. });
  3013. Object.defineProperty(Control.prototype, "linkOffsetY", {
  3014. /**
  3015. * Gets or sets a value indicating the offset on Y axis to the linked mesh
  3016. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  3017. */
  3018. get: function () {
  3019. return this._linkOffsetY.toString(this._host);
  3020. },
  3021. set: function (value) {
  3022. if (this._linkOffsetY.fromString(value)) {
  3023. this._markAsDirty();
  3024. }
  3025. },
  3026. enumerable: true,
  3027. configurable: true
  3028. });
  3029. Object.defineProperty(Control.prototype, "linkOffsetYInPixels", {
  3030. /**
  3031. * Gets a value indicating the offset in pixels on Y axis to the linked mesh
  3032. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  3033. */
  3034. get: function () {
  3035. return this._linkOffsetY.getValueInPixel(this._host, this._cachedParentMeasure.height);
  3036. },
  3037. enumerable: true,
  3038. configurable: true
  3039. });
  3040. Object.defineProperty(Control.prototype, "centerX", {
  3041. /** Gets the center coordinate on X axis */
  3042. get: function () {
  3043. return this._currentMeasure.left + this._currentMeasure.width / 2;
  3044. },
  3045. enumerable: true,
  3046. configurable: true
  3047. });
  3048. Object.defineProperty(Control.prototype, "centerY", {
  3049. /** Gets the center coordinate on Y axis */
  3050. get: function () {
  3051. return this._currentMeasure.top + this._currentMeasure.height / 2;
  3052. },
  3053. enumerable: true,
  3054. configurable: true
  3055. });
  3056. Object.defineProperty(Control.prototype, "isEnabled", {
  3057. /** Gets or sets if control is Enabled*/
  3058. get: function () {
  3059. return this._isEnabled;
  3060. },
  3061. set: function (value) {
  3062. if (this._isEnabled === value) {
  3063. return;
  3064. }
  3065. this._isEnabled = value;
  3066. this._markAsDirty();
  3067. },
  3068. enumerable: true,
  3069. configurable: true
  3070. });
  3071. Object.defineProperty(Control.prototype, "disabledColor", {
  3072. /** Gets or sets background color of control if it's disabled*/
  3073. get: function () {
  3074. return this._disabledColor;
  3075. },
  3076. set: function (value) {
  3077. if (this._disabledColor === value) {
  3078. return;
  3079. }
  3080. this._disabledColor = value;
  3081. this._markAsDirty();
  3082. },
  3083. enumerable: true,
  3084. configurable: true
  3085. });
  3086. /** @hidden */
  3087. Control.prototype._getTypeName = function () {
  3088. return "Control";
  3089. };
  3090. /** @hidden */
  3091. Control.prototype._resetFontCache = function () {
  3092. this._fontSet = true;
  3093. this._markAsDirty();
  3094. };
  3095. /**
  3096. * Determines if a container is an ascendant of the current control
  3097. * @param container defines the container to look for
  3098. * @returns true if the container is one of the ascendant of the control
  3099. */
  3100. Control.prototype.isAscendant = function (container) {
  3101. if (!this.parent) {
  3102. return false;
  3103. }
  3104. if (this.parent === container) {
  3105. return true;
  3106. }
  3107. return this.parent.isAscendant(container);
  3108. };
  3109. /**
  3110. * Gets coordinates in local control space
  3111. * @param globalCoordinates defines the coordinates to transform
  3112. * @returns the new coordinates in local space
  3113. */
  3114. Control.prototype.getLocalCoordinates = function (globalCoordinates) {
  3115. var result = babylonjs_1.Vector2.Zero();
  3116. this.getLocalCoordinatesToRef(globalCoordinates, result);
  3117. return result;
  3118. };
  3119. /**
  3120. * Gets coordinates in local control space
  3121. * @param globalCoordinates defines the coordinates to transform
  3122. * @param result defines the target vector2 where to store the result
  3123. * @returns the current control
  3124. */
  3125. Control.prototype.getLocalCoordinatesToRef = function (globalCoordinates, result) {
  3126. result.x = globalCoordinates.x - this._currentMeasure.left;
  3127. result.y = globalCoordinates.y - this._currentMeasure.top;
  3128. return this;
  3129. };
  3130. /**
  3131. * Gets coordinates in parent local control space
  3132. * @param globalCoordinates defines the coordinates to transform
  3133. * @returns the new coordinates in parent local space
  3134. */
  3135. Control.prototype.getParentLocalCoordinates = function (globalCoordinates) {
  3136. var result = babylonjs_1.Vector2.Zero();
  3137. result.x = globalCoordinates.x - this._cachedParentMeasure.left;
  3138. result.y = globalCoordinates.y - this._cachedParentMeasure.top;
  3139. return result;
  3140. };
  3141. /**
  3142. * Move the current control to a vector3 position projected onto the screen.
  3143. * @param position defines the target position
  3144. * @param scene defines the hosting scene
  3145. */
  3146. Control.prototype.moveToVector3 = function (position, scene) {
  3147. if (!this._host || this._root !== this._host._rootContainer) {
  3148. babylonjs_1.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  3149. return;
  3150. }
  3151. this.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  3152. this.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
  3153. var globalViewport = this._host._getGlobalViewport(scene);
  3154. var projectedPosition = babylonjs_1.Vector3.Project(position, babylonjs_1.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  3155. this._moveToProjectedPosition(projectedPosition);
  3156. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  3157. this.notRenderable = true;
  3158. return;
  3159. }
  3160. this.notRenderable = false;
  3161. };
  3162. /**
  3163. * Link current control with a target mesh
  3164. * @param mesh defines the mesh to link with
  3165. * @see http://doc.babylonjs.com/how_to/gui#tracking-positions
  3166. */
  3167. Control.prototype.linkWithMesh = function (mesh) {
  3168. if (!this._host || this._root && this._root !== this._host._rootContainer) {
  3169. if (mesh) {
  3170. babylonjs_1.Tools.Error("Cannot link a control to a mesh if the control is not at root level");
  3171. }
  3172. return;
  3173. }
  3174. var index = this._host._linkedControls.indexOf(this);
  3175. if (index !== -1) {
  3176. this._linkedMesh = mesh;
  3177. if (!mesh) {
  3178. this._host._linkedControls.splice(index, 1);
  3179. }
  3180. return;
  3181. }
  3182. else if (!mesh) {
  3183. return;
  3184. }
  3185. this.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  3186. this.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
  3187. this._linkedMesh = mesh;
  3188. this._onlyMeasureMode = this._currentMeasure.width === 0 || this._currentMeasure.height === 0;
  3189. this._host._linkedControls.push(this);
  3190. };
  3191. /** @hidden */
  3192. Control.prototype._moveToProjectedPosition = function (projectedPosition) {
  3193. var oldLeft = this._left.getValue(this._host);
  3194. var oldTop = this._top.getValue(this._host);
  3195. var newLeft = ((projectedPosition.x + this._linkOffsetX.getValue(this._host)) - this._currentMeasure.width / 2);
  3196. var newTop = ((projectedPosition.y + this._linkOffsetY.getValue(this._host)) - this._currentMeasure.height / 2);
  3197. if (this._left.ignoreAdaptiveScaling && this._top.ignoreAdaptiveScaling) {
  3198. if (Math.abs(newLeft - oldLeft) < 0.5) {
  3199. newLeft = oldLeft;
  3200. }
  3201. if (Math.abs(newTop - oldTop) < 0.5) {
  3202. newTop = oldTop;
  3203. }
  3204. }
  3205. this.left = newLeft + "px";
  3206. this.top = newTop + "px";
  3207. this._left.ignoreAdaptiveScaling = true;
  3208. this._top.ignoreAdaptiveScaling = true;
  3209. };
  3210. /** @hidden */
  3211. Control.prototype._markMatrixAsDirty = function () {
  3212. this._isMatrixDirty = true;
  3213. this._flagDescendantsAsMatrixDirty();
  3214. };
  3215. /** @hidden */
  3216. Control.prototype._flagDescendantsAsMatrixDirty = function () {
  3217. // No child
  3218. };
  3219. /** @hidden */
  3220. Control.prototype._markAsDirty = function (force) {
  3221. if (force === void 0) { force = false; }
  3222. if (!this._isVisible && !force) {
  3223. return;
  3224. }
  3225. this._isDirty = true;
  3226. if (!this._host) {
  3227. return; // Not yet connected
  3228. }
  3229. this._host.markAsDirty();
  3230. };
  3231. /** @hidden */
  3232. Control.prototype._markAllAsDirty = function () {
  3233. this._markAsDirty();
  3234. if (this._font) {
  3235. this._prepareFont();
  3236. }
  3237. };
  3238. /** @hidden */
  3239. Control.prototype._link = function (root, host) {
  3240. this._root = root;
  3241. this._host = host;
  3242. };
  3243. /** @hidden */
  3244. Control.prototype._transform = function (context) {
  3245. if (!this._isMatrixDirty && this._scaleX === 1 && this._scaleY === 1 && this._rotation === 0) {
  3246. return;
  3247. }
  3248. // postTranslate
  3249. var offsetX = this._currentMeasure.width * this._transformCenterX + this._currentMeasure.left;
  3250. var offsetY = this._currentMeasure.height * this._transformCenterY + this._currentMeasure.top;
  3251. context.translate(offsetX, offsetY);
  3252. // rotate
  3253. context.rotate(this._rotation);
  3254. // scale
  3255. context.scale(this._scaleX, this._scaleY);
  3256. // preTranslate
  3257. context.translate(-offsetX, -offsetY);
  3258. // Need to update matrices?
  3259. if (this._isMatrixDirty || this._cachedOffsetX !== offsetX || this._cachedOffsetY !== offsetY) {
  3260. this._cachedOffsetX = offsetX;
  3261. this._cachedOffsetY = offsetY;
  3262. this._isMatrixDirty = false;
  3263. this._flagDescendantsAsMatrixDirty();
  3264. math2D_1.Matrix2D.ComposeToRef(-offsetX, -offsetY, this._rotation, this._scaleX, this._scaleY, this._root ? this._root._transformMatrix : null, this._transformMatrix);
  3265. this._transformMatrix.invertToRef(this._invertTransformMatrix);
  3266. }
  3267. };
  3268. /** @hidden */
  3269. Control.prototype._applyStates = function (context) {
  3270. if (this._isFontSizeInPercentage) {
  3271. this._fontSet = true;
  3272. }
  3273. if (this._fontSet) {
  3274. this._prepareFont();
  3275. this._fontSet = false;
  3276. }
  3277. if (this._font) {
  3278. context.font = this._font;
  3279. }
  3280. if (this._color) {
  3281. context.fillStyle = this._color;
  3282. }
  3283. if (this._alphaSet) {
  3284. context.globalAlpha = this.parent ? this.parent.alpha * this._alpha : this._alpha;
  3285. }
  3286. };
  3287. /** @hidden */
  3288. Control.prototype._processMeasures = function (parentMeasure, context) {
  3289. if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
  3290. this._isDirty = false;
  3291. this._currentMeasure.copyFrom(parentMeasure);
  3292. // Let children take some pre-measurement actions
  3293. this._preMeasure(parentMeasure, context);
  3294. this._measure();
  3295. this._computeAlignment(parentMeasure, context);
  3296. // Convert to int values
  3297. this._currentMeasure.left = this._currentMeasure.left | 0;
  3298. this._currentMeasure.top = this._currentMeasure.top | 0;
  3299. this._currentMeasure.width = this._currentMeasure.width | 0;
  3300. this._currentMeasure.height = this._currentMeasure.height | 0;
  3301. // Let children add more features
  3302. this._additionalProcessing(parentMeasure, context);
  3303. this._cachedParentMeasure.copyFrom(parentMeasure);
  3304. if (this.onDirtyObservable.hasObservers()) {
  3305. this.onDirtyObservable.notifyObservers(this);
  3306. }
  3307. }
  3308. if (this._currentMeasure.left > parentMeasure.left + parentMeasure.width) {
  3309. return false;
  3310. }
  3311. if (this._currentMeasure.left + this._currentMeasure.width < parentMeasure.left) {
  3312. return false;
  3313. }
  3314. if (this._currentMeasure.top > parentMeasure.top + parentMeasure.height) {
  3315. return false;
  3316. }
  3317. if (this._currentMeasure.top + this._currentMeasure.height < parentMeasure.top) {
  3318. return false;
  3319. }
  3320. // Transform
  3321. this._transform(context);
  3322. if (this._onlyMeasureMode) {
  3323. this._onlyMeasureMode = false;
  3324. return false; // We do not want rendering for this frame as they are measure dependant information that need to be gathered
  3325. }
  3326. // Clip
  3327. if (this.clipChildren) {
  3328. this._clip(context);
  3329. context.clip();
  3330. }
  3331. return true;
  3332. };
  3333. /** @hidden */
  3334. Control.prototype._clip = function (context) {
  3335. context.beginPath();
  3336. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3337. var shadowOffsetX = this.shadowOffsetX;
  3338. var shadowOffsetY = this.shadowOffsetY;
  3339. var shadowBlur = this.shadowBlur;
  3340. var leftShadowOffset = Math.min(Math.min(shadowOffsetX, 0) - shadowBlur * 2, 0);
  3341. var rightShadowOffset = Math.max(Math.max(shadowOffsetX, 0) + shadowBlur * 2, 0);
  3342. var topShadowOffset = Math.min(Math.min(shadowOffsetY, 0) - shadowBlur * 2, 0);
  3343. var bottomShadowOffset = Math.max(Math.max(shadowOffsetY, 0) + shadowBlur * 2, 0);
  3344. context.rect(this._currentMeasure.left + leftShadowOffset, this._currentMeasure.top + topShadowOffset, this._currentMeasure.width + rightShadowOffset - leftShadowOffset, this._currentMeasure.height + bottomShadowOffset - topShadowOffset);
  3345. }
  3346. else {
  3347. context.rect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3348. }
  3349. };
  3350. /** @hidden */
  3351. Control.prototype._measure = function () {
  3352. // Width / Height
  3353. if (this._width.isPixel) {
  3354. this._currentMeasure.width = this._width.getValue(this._host);
  3355. }
  3356. else {
  3357. this._currentMeasure.width *= this._width.getValue(this._host);
  3358. }
  3359. if (this._height.isPixel) {
  3360. this._currentMeasure.height = this._height.getValue(this._host);
  3361. }
  3362. else {
  3363. this._currentMeasure.height *= this._height.getValue(this._host);
  3364. }
  3365. };
  3366. /** @hidden */
  3367. Control.prototype._computeAlignment = function (parentMeasure, context) {
  3368. var width = this._currentMeasure.width;
  3369. var height = this._currentMeasure.height;
  3370. var parentWidth = parentMeasure.width;
  3371. var parentHeight = parentMeasure.height;
  3372. // Left / top
  3373. var x = 0;
  3374. var y = 0;
  3375. switch (this.horizontalAlignment) {
  3376. case Control.HORIZONTAL_ALIGNMENT_LEFT:
  3377. x = 0;
  3378. break;
  3379. case Control.HORIZONTAL_ALIGNMENT_RIGHT:
  3380. x = parentWidth - width;
  3381. break;
  3382. case Control.HORIZONTAL_ALIGNMENT_CENTER:
  3383. x = (parentWidth - width) / 2;
  3384. break;
  3385. }
  3386. switch (this.verticalAlignment) {
  3387. case Control.VERTICAL_ALIGNMENT_TOP:
  3388. y = 0;
  3389. break;
  3390. case Control.VERTICAL_ALIGNMENT_BOTTOM:
  3391. y = parentHeight - height;
  3392. break;
  3393. case Control.VERTICAL_ALIGNMENT_CENTER:
  3394. y = (parentHeight - height) / 2;
  3395. break;
  3396. }
  3397. if (this._paddingLeft.isPixel) {
  3398. this._currentMeasure.left += this._paddingLeft.getValue(this._host);
  3399. this._currentMeasure.width -= this._paddingLeft.getValue(this._host);
  3400. }
  3401. else {
  3402. this._currentMeasure.left += parentWidth * this._paddingLeft.getValue(this._host);
  3403. this._currentMeasure.width -= parentWidth * this._paddingLeft.getValue(this._host);
  3404. }
  3405. if (this._paddingRight.isPixel) {
  3406. this._currentMeasure.width -= this._paddingRight.getValue(this._host);
  3407. }
  3408. else {
  3409. this._currentMeasure.width -= parentWidth * this._paddingRight.getValue(this._host);
  3410. }
  3411. if (this._paddingTop.isPixel) {
  3412. this._currentMeasure.top += this._paddingTop.getValue(this._host);
  3413. this._currentMeasure.height -= this._paddingTop.getValue(this._host);
  3414. }
  3415. else {
  3416. this._currentMeasure.top += parentHeight * this._paddingTop.getValue(this._host);
  3417. this._currentMeasure.height -= parentHeight * this._paddingTop.getValue(this._host);
  3418. }
  3419. if (this._paddingBottom.isPixel) {
  3420. this._currentMeasure.height -= this._paddingBottom.getValue(this._host);
  3421. }
  3422. else {
  3423. this._currentMeasure.height -= parentHeight * this._paddingBottom.getValue(this._host);
  3424. }
  3425. if (this._left.isPixel) {
  3426. this._currentMeasure.left += this._left.getValue(this._host);
  3427. }
  3428. else {
  3429. this._currentMeasure.left += parentWidth * this._left.getValue(this._host);
  3430. }
  3431. if (this._top.isPixel) {
  3432. this._currentMeasure.top += this._top.getValue(this._host);
  3433. }
  3434. else {
  3435. this._currentMeasure.top += parentHeight * this._top.getValue(this._host);
  3436. }
  3437. this._currentMeasure.left += x;
  3438. this._currentMeasure.top += y;
  3439. };
  3440. /** @hidden */
  3441. Control.prototype._preMeasure = function (parentMeasure, context) {
  3442. // Do nothing
  3443. };
  3444. /** @hidden */
  3445. Control.prototype._additionalProcessing = function (parentMeasure, context) {
  3446. // Do nothing
  3447. };
  3448. /** @hidden */
  3449. Control.prototype._draw = function (parentMeasure, context) {
  3450. // Do nothing
  3451. };
  3452. /**
  3453. * Tests if a given coordinates belong to the current control
  3454. * @param x defines x coordinate to test
  3455. * @param y defines y coordinate to test
  3456. * @returns true if the coordinates are inside the control
  3457. */
  3458. Control.prototype.contains = function (x, y) {
  3459. // Invert transform
  3460. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  3461. x = this._transformedPosition.x;
  3462. y = this._transformedPosition.y;
  3463. // Check
  3464. if (x < this._currentMeasure.left) {
  3465. return false;
  3466. }
  3467. if (x > this._currentMeasure.left + this._currentMeasure.width) {
  3468. return false;
  3469. }
  3470. if (y < this._currentMeasure.top) {
  3471. return false;
  3472. }
  3473. if (y > this._currentMeasure.top + this._currentMeasure.height) {
  3474. return false;
  3475. }
  3476. if (this.isPointerBlocker) {
  3477. this._host._shouldBlockPointer = true;
  3478. }
  3479. return true;
  3480. };
  3481. /** @hidden */
  3482. Control.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  3483. if (!this._isEnabled) {
  3484. return false;
  3485. }
  3486. if (!this.isHitTestVisible || !this.isVisible || this._doNotRender) {
  3487. return false;
  3488. }
  3489. if (!this.contains(x, y)) {
  3490. return false;
  3491. }
  3492. this._processObservables(type, x, y, pointerId, buttonIndex);
  3493. return true;
  3494. };
  3495. /** @hidden */
  3496. Control.prototype._onPointerMove = function (target, coordinates) {
  3497. var canNotify = this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  3498. if (canNotify && this.parent != null) {
  3499. this.parent._onPointerMove(target, coordinates);
  3500. }
  3501. };
  3502. /** @hidden */
  3503. Control.prototype._onPointerEnter = function (target) {
  3504. if (!this._isEnabled) {
  3505. return false;
  3506. }
  3507. if (this._enterCount > 0) {
  3508. return false;
  3509. }
  3510. if (this._enterCount === -1) { // -1 is for touch input, we are now sure we are with a mouse or pencil
  3511. this._enterCount = 0;
  3512. }
  3513. this._enterCount++;
  3514. var canNotify = this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  3515. if (canNotify && this.parent != null) {
  3516. this.parent._onPointerEnter(target);
  3517. }
  3518. return true;
  3519. };
  3520. /** @hidden */
  3521. Control.prototype._onPointerOut = function (target) {
  3522. if (!this._isEnabled) {
  3523. return;
  3524. }
  3525. this._enterCount = 0;
  3526. var canNotify = this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  3527. if (canNotify && this.parent != null) {
  3528. this.parent._onPointerOut(target);
  3529. }
  3530. };
  3531. /** @hidden */
  3532. Control.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3533. // Prevent pointerout to lose control context.
  3534. // Event redundancy is checked inside the function.
  3535. this._onPointerEnter(this);
  3536. if (this._downCount !== 0) {
  3537. return false;
  3538. }
  3539. this._downCount++;
  3540. this._downPointerIds[pointerId] = true;
  3541. var canNotify = this.onPointerDownObservable.notifyObservers(new math2D_1.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  3542. if (canNotify && this.parent != null) {
  3543. this.parent._onPointerDown(target, coordinates, pointerId, buttonIndex);
  3544. }
  3545. return true;
  3546. };
  3547. /** @hidden */
  3548. Control.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  3549. if (!this._isEnabled) {
  3550. return;
  3551. }
  3552. this._downCount = 0;
  3553. delete this._downPointerIds[pointerId];
  3554. var canNotifyClick = notifyClick;
  3555. if (notifyClick && (this._enterCount > 0 || this._enterCount === -1)) {
  3556. canNotifyClick = this.onPointerClickObservable.notifyObservers(new math2D_1.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  3557. }
  3558. var canNotify = this.onPointerUpObservable.notifyObservers(new math2D_1.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  3559. if (canNotify && this.parent != null) {
  3560. this.parent._onPointerUp(target, coordinates, pointerId, buttonIndex, canNotifyClick);
  3561. }
  3562. };
  3563. /** @hidden */
  3564. Control.prototype._forcePointerUp = function (pointerId) {
  3565. if (pointerId === void 0) { pointerId = null; }
  3566. if (pointerId !== null) {
  3567. this._onPointerUp(this, babylonjs_1.Vector2.Zero(), pointerId, 0, true);
  3568. }
  3569. else {
  3570. for (var key in this._downPointerIds) {
  3571. this._onPointerUp(this, babylonjs_1.Vector2.Zero(), +key, 0, true);
  3572. }
  3573. }
  3574. };
  3575. /** @hidden */
  3576. Control.prototype._processObservables = function (type, x, y, pointerId, buttonIndex) {
  3577. if (!this._isEnabled) {
  3578. return false;
  3579. }
  3580. this._dummyVector2.copyFromFloats(x, y);
  3581. if (type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  3582. this._onPointerMove(this, this._dummyVector2);
  3583. var previousControlOver = this._host._lastControlOver[pointerId];
  3584. if (previousControlOver && previousControlOver !== this) {
  3585. previousControlOver._onPointerOut(this);
  3586. }
  3587. if (previousControlOver !== this) {
  3588. this._onPointerEnter(this);
  3589. }
  3590. this._host._lastControlOver[pointerId] = this;
  3591. return true;
  3592. }
  3593. if (type === babylonjs_1.PointerEventTypes.POINTERDOWN) {
  3594. this._onPointerDown(this, this._dummyVector2, pointerId, buttonIndex);
  3595. this._host._lastControlDown[pointerId] = this;
  3596. this._host._lastPickedControl = this;
  3597. return true;
  3598. }
  3599. if (type === babylonjs_1.PointerEventTypes.POINTERUP) {
  3600. if (this._host._lastControlDown[pointerId]) {
  3601. this._host._lastControlDown[pointerId]._onPointerUp(this, this._dummyVector2, pointerId, buttonIndex, true);
  3602. }
  3603. delete this._host._lastControlDown[pointerId];
  3604. return true;
  3605. }
  3606. return false;
  3607. };
  3608. Control.prototype._prepareFont = function () {
  3609. if (!this._font && !this._fontSet) {
  3610. return;
  3611. }
  3612. if (this._style) {
  3613. this._font = this._style.fontStyle + " " + this._style.fontWeight + " " + this.fontSizeInPixels + "px " + this._style.fontFamily;
  3614. }
  3615. else {
  3616. this._font = this._fontStyle + " " + this._fontWeight + " " + this.fontSizeInPixels + "px " + this._fontFamily;
  3617. }
  3618. this._fontOffset = Control._GetFontOffset(this._font);
  3619. };
  3620. /** Releases associated resources */
  3621. Control.prototype.dispose = function () {
  3622. this.onDirtyObservable.clear();
  3623. this.onAfterDrawObservable.clear();
  3624. this.onPointerDownObservable.clear();
  3625. this.onPointerEnterObservable.clear();
  3626. this.onPointerMoveObservable.clear();
  3627. this.onPointerOutObservable.clear();
  3628. this.onPointerUpObservable.clear();
  3629. this.onPointerClickObservable.clear();
  3630. if (this._styleObserver && this._style) {
  3631. this._style.onChangedObservable.remove(this._styleObserver);
  3632. this._styleObserver = null;
  3633. }
  3634. if (this._root) {
  3635. this._root.removeControl(this);
  3636. this._root = null;
  3637. }
  3638. if (this._host) {
  3639. var index = this._host._linkedControls.indexOf(this);
  3640. if (index > -1) {
  3641. this.linkWithMesh(null);
  3642. }
  3643. }
  3644. };
  3645. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  3646. /** HORIZONTAL_ALIGNMENT_LEFT */
  3647. get: function () {
  3648. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  3649. },
  3650. enumerable: true,
  3651. configurable: true
  3652. });
  3653. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  3654. /** HORIZONTAL_ALIGNMENT_RIGHT */
  3655. get: function () {
  3656. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  3657. },
  3658. enumerable: true,
  3659. configurable: true
  3660. });
  3661. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  3662. /** HORIZONTAL_ALIGNMENT_CENTER */
  3663. get: function () {
  3664. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  3665. },
  3666. enumerable: true,
  3667. configurable: true
  3668. });
  3669. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  3670. /** VERTICAL_ALIGNMENT_TOP */
  3671. get: function () {
  3672. return Control._VERTICAL_ALIGNMENT_TOP;
  3673. },
  3674. enumerable: true,
  3675. configurable: true
  3676. });
  3677. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  3678. /** VERTICAL_ALIGNMENT_BOTTOM */
  3679. get: function () {
  3680. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  3681. },
  3682. enumerable: true,
  3683. configurable: true
  3684. });
  3685. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  3686. /** VERTICAL_ALIGNMENT_CENTER */
  3687. get: function () {
  3688. return Control._VERTICAL_ALIGNMENT_CENTER;
  3689. },
  3690. enumerable: true,
  3691. configurable: true
  3692. });
  3693. /** @hidden */
  3694. Control._GetFontOffset = function (font) {
  3695. if (Control._FontHeightSizes[font]) {
  3696. return Control._FontHeightSizes[font];
  3697. }
  3698. var text = document.createElement("span");
  3699. text.innerHTML = "Hg";
  3700. text.style.font = font;
  3701. var block = document.createElement("div");
  3702. block.style.display = "inline-block";
  3703. block.style.width = "1px";
  3704. block.style.height = "0px";
  3705. block.style.verticalAlign = "bottom";
  3706. var div = document.createElement("div");
  3707. div.appendChild(text);
  3708. div.appendChild(block);
  3709. document.body.appendChild(div);
  3710. var fontAscent = 0;
  3711. var fontHeight = 0;
  3712. try {
  3713. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  3714. block.style.verticalAlign = "baseline";
  3715. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  3716. }
  3717. finally {
  3718. document.body.removeChild(div);
  3719. }
  3720. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  3721. Control._FontHeightSizes[font] = result;
  3722. return result;
  3723. };
  3724. /** @hidden */
  3725. Control.drawEllipse = function (x, y, width, height, context) {
  3726. context.translate(x, y);
  3727. context.scale(width, height);
  3728. context.beginPath();
  3729. context.arc(0, 0, 1, 0, 2 * Math.PI);
  3730. context.closePath();
  3731. context.scale(1 / width, 1 / height);
  3732. context.translate(-x, -y);
  3733. };
  3734. // Statics
  3735. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  3736. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  3737. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  3738. Control._VERTICAL_ALIGNMENT_TOP = 0;
  3739. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  3740. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  3741. Control._FontHeightSizes = {};
  3742. /**
  3743. * Creates a stack panel that can be used to render headers
  3744. * @param control defines the control to associate with the header
  3745. * @param text defines the text of the header
  3746. * @param size defines the size of the header
  3747. * @param options defines options used to configure the header
  3748. * @returns a new StackPanel
  3749. * @ignore
  3750. * @hidden
  3751. */
  3752. Control.AddHeader = function () { };
  3753. return Control;
  3754. }());
  3755. exports.Control = Control;
  3756. /***/ }),
  3757. /***/ "./src/2D/controls/displayGrid.ts":
  3758. /*!****************************************!*\
  3759. !*** ./src/2D/controls/displayGrid.ts ***!
  3760. \****************************************/
  3761. /*! no static exports found */
  3762. /***/ (function(module, exports, __webpack_require__) {
  3763. "use strict";
  3764. var __extends = (this && this.__extends) || (function () {
  3765. var extendStatics = function (d, b) {
  3766. extendStatics = Object.setPrototypeOf ||
  3767. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3768. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3769. return extendStatics(d, b);
  3770. }
  3771. return function (d, b) {
  3772. extendStatics(d, b);
  3773. function __() { this.constructor = d; }
  3774. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3775. };
  3776. })();
  3777. Object.defineProperty(exports, "__esModule", { value: true });
  3778. var _1 = __webpack_require__(/*! . */ "./src/2D/controls/index.ts");
  3779. /** Class used to render a grid */
  3780. var DisplayGrid = /** @class */ (function (_super) {
  3781. __extends(DisplayGrid, _super);
  3782. /**
  3783. * Creates a new GridDisplayRectangle
  3784. * @param name defines the control name
  3785. */
  3786. function DisplayGrid(name) {
  3787. var _this = _super.call(this, name) || this;
  3788. _this.name = name;
  3789. _this._cellWidth = 20;
  3790. _this._cellHeight = 20;
  3791. _this._minorLineTickness = 1;
  3792. _this._minorLineColor = "DarkGray";
  3793. _this._majorLineTickness = 2;
  3794. _this._majorLineColor = "White";
  3795. _this._majorLineFrequency = 5;
  3796. _this._background = "Black";
  3797. _this._displayMajorLines = true;
  3798. _this._displayMinorLines = true;
  3799. return _this;
  3800. }
  3801. Object.defineProperty(DisplayGrid.prototype, "displayMinorLines", {
  3802. /** Gets or sets a boolean indicating if minor lines must be rendered (true by default)) */
  3803. get: function () {
  3804. return this._displayMinorLines;
  3805. },
  3806. set: function (value) {
  3807. if (this._displayMinorLines === value) {
  3808. return;
  3809. }
  3810. this._displayMinorLines = value;
  3811. this._markAsDirty();
  3812. },
  3813. enumerable: true,
  3814. configurable: true
  3815. });
  3816. Object.defineProperty(DisplayGrid.prototype, "displayMajorLines", {
  3817. /** Gets or sets a boolean indicating if major lines must be rendered (true by default)) */
  3818. get: function () {
  3819. return this._displayMajorLines;
  3820. },
  3821. set: function (value) {
  3822. if (this._displayMajorLines === value) {
  3823. return;
  3824. }
  3825. this._displayMajorLines = value;
  3826. this._markAsDirty();
  3827. },
  3828. enumerable: true,
  3829. configurable: true
  3830. });
  3831. Object.defineProperty(DisplayGrid.prototype, "background", {
  3832. /** Gets or sets background color (Black by default) */
  3833. get: function () {
  3834. return this._background;
  3835. },
  3836. set: function (value) {
  3837. if (this._background === value) {
  3838. return;
  3839. }
  3840. this._background = value;
  3841. this._markAsDirty();
  3842. },
  3843. enumerable: true,
  3844. configurable: true
  3845. });
  3846. Object.defineProperty(DisplayGrid.prototype, "cellWidth", {
  3847. /** Gets or sets the width of each cell (20 by default) */
  3848. get: function () {
  3849. return this._cellWidth;
  3850. },
  3851. set: function (value) {
  3852. this._cellWidth = value;
  3853. this._markAsDirty();
  3854. },
  3855. enumerable: true,
  3856. configurable: true
  3857. });
  3858. Object.defineProperty(DisplayGrid.prototype, "cellHeight", {
  3859. /** Gets or sets the height of each cell (20 by default) */
  3860. get: function () {
  3861. return this._cellHeight;
  3862. },
  3863. set: function (value) {
  3864. this._cellHeight = value;
  3865. this._markAsDirty();
  3866. },
  3867. enumerable: true,
  3868. configurable: true
  3869. });
  3870. Object.defineProperty(DisplayGrid.prototype, "minorLineTickness", {
  3871. /** Gets or sets the tickness of minor lines (1 by default) */
  3872. get: function () {
  3873. return this._minorLineTickness;
  3874. },
  3875. set: function (value) {
  3876. this._minorLineTickness = value;
  3877. this._markAsDirty();
  3878. },
  3879. enumerable: true,
  3880. configurable: true
  3881. });
  3882. Object.defineProperty(DisplayGrid.prototype, "minorLineColor", {
  3883. /** Gets or sets the color of minor lines (DarkGray by default) */
  3884. get: function () {
  3885. return this._minorLineColor;
  3886. },
  3887. set: function (value) {
  3888. this._minorLineColor = value;
  3889. this._markAsDirty();
  3890. },
  3891. enumerable: true,
  3892. configurable: true
  3893. });
  3894. Object.defineProperty(DisplayGrid.prototype, "majorLineTickness", {
  3895. /** Gets or sets the tickness of major lines (2 by default) */
  3896. get: function () {
  3897. return this._majorLineTickness;
  3898. },
  3899. set: function (value) {
  3900. this._majorLineTickness = value;
  3901. this._markAsDirty();
  3902. },
  3903. enumerable: true,
  3904. configurable: true
  3905. });
  3906. Object.defineProperty(DisplayGrid.prototype, "majorLineColor", {
  3907. /** Gets or sets the color of major lines (White by default) */
  3908. get: function () {
  3909. return this._majorLineColor;
  3910. },
  3911. set: function (value) {
  3912. this._majorLineColor = value;
  3913. this._markAsDirty();
  3914. },
  3915. enumerable: true,
  3916. configurable: true
  3917. });
  3918. Object.defineProperty(DisplayGrid.prototype, "majorLineFrequency", {
  3919. /** Gets or sets the frequency of major lines (default is 1 every 5 minor lines)*/
  3920. get: function () {
  3921. return this._majorLineFrequency;
  3922. },
  3923. set: function (value) {
  3924. this._majorLineFrequency = value;
  3925. this._markAsDirty();
  3926. },
  3927. enumerable: true,
  3928. configurable: true
  3929. });
  3930. DisplayGrid.prototype._draw = function (parentMeasure, context) {
  3931. context.save();
  3932. this._applyStates(context);
  3933. if (this._isEnabled && this._processMeasures(parentMeasure, context)) {
  3934. if (this._background) {
  3935. context.fillStyle = this._background;
  3936. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3937. }
  3938. var cellCountX = this._currentMeasure.width / this._cellWidth;
  3939. var cellCountY = this._currentMeasure.height / this._cellHeight;
  3940. // Minor lines
  3941. var left = this._currentMeasure.left + this._currentMeasure.width / 2;
  3942. var top_1 = this._currentMeasure.top + this._currentMeasure.height / 2;
  3943. if (this._displayMinorLines) {
  3944. context.strokeStyle = this._minorLineColor;
  3945. context.lineWidth = this._minorLineTickness;
  3946. for (var x = -cellCountX / 2; x < cellCountX / 2; x++) {
  3947. var cellX = left + x * this.cellWidth;
  3948. context.beginPath();
  3949. context.moveTo(cellX, this._currentMeasure.top);
  3950. context.lineTo(cellX, this._currentMeasure.top + this._currentMeasure.height);
  3951. context.stroke();
  3952. }
  3953. for (var y = -cellCountY / 2; y < cellCountY / 2; y++) {
  3954. var cellY = top_1 + y * this.cellHeight;
  3955. context.beginPath();
  3956. context.moveTo(this._currentMeasure.left, cellY);
  3957. context.lineTo(this._currentMeasure.left + this._currentMeasure.width, cellY);
  3958. context.stroke();
  3959. }
  3960. }
  3961. // Major lines
  3962. if (this._displayMajorLines) {
  3963. context.strokeStyle = this._majorLineColor;
  3964. context.lineWidth = this._majorLineTickness;
  3965. for (var x = -cellCountX / 2 + this._majorLineFrequency; x < cellCountX / 2; x += this._majorLineFrequency) {
  3966. var cellX = left + x * this.cellWidth;
  3967. context.beginPath();
  3968. context.moveTo(cellX, this._currentMeasure.top);
  3969. context.lineTo(cellX, this._currentMeasure.top + this._currentMeasure.height);
  3970. context.stroke();
  3971. }
  3972. for (var y = -cellCountY / 2 + this._majorLineFrequency; y < cellCountY / 2; y += this._majorLineFrequency) {
  3973. var cellY = top_1 + y * this.cellHeight;
  3974. context.moveTo(this._currentMeasure.left, cellY);
  3975. context.lineTo(this._currentMeasure.left + this._currentMeasure.width, cellY);
  3976. context.closePath();
  3977. context.stroke();
  3978. }
  3979. }
  3980. }
  3981. context.restore();
  3982. };
  3983. DisplayGrid.prototype._getTypeName = function () {
  3984. return "DisplayGrid";
  3985. };
  3986. return DisplayGrid;
  3987. }(_1.Control));
  3988. exports.DisplayGrid = DisplayGrid;
  3989. /***/ }),
  3990. /***/ "./src/2D/controls/ellipse.ts":
  3991. /*!************************************!*\
  3992. !*** ./src/2D/controls/ellipse.ts ***!
  3993. \************************************/
  3994. /*! no static exports found */
  3995. /***/ (function(module, exports, __webpack_require__) {
  3996. "use strict";
  3997. var __extends = (this && this.__extends) || (function () {
  3998. var extendStatics = function (d, b) {
  3999. extendStatics = Object.setPrototypeOf ||
  4000. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4001. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4002. return extendStatics(d, b);
  4003. }
  4004. return function (d, b) {
  4005. extendStatics(d, b);
  4006. function __() { this.constructor = d; }
  4007. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4008. };
  4009. })();
  4010. Object.defineProperty(exports, "__esModule", { value: true });
  4011. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  4012. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  4013. /** Class used to create 2D ellipse containers */
  4014. var Ellipse = /** @class */ (function (_super) {
  4015. __extends(Ellipse, _super);
  4016. /**
  4017. * Creates a new Ellipse
  4018. * @param name defines the control name
  4019. */
  4020. function Ellipse(name) {
  4021. var _this = _super.call(this, name) || this;
  4022. _this.name = name;
  4023. _this._thickness = 1;
  4024. return _this;
  4025. }
  4026. Object.defineProperty(Ellipse.prototype, "thickness", {
  4027. /** Gets or sets border thickness */
  4028. get: function () {
  4029. return this._thickness;
  4030. },
  4031. set: function (value) {
  4032. if (this._thickness === value) {
  4033. return;
  4034. }
  4035. this._thickness = value;
  4036. this._markAsDirty();
  4037. },
  4038. enumerable: true,
  4039. configurable: true
  4040. });
  4041. Ellipse.prototype._getTypeName = function () {
  4042. return "Ellipse";
  4043. };
  4044. Ellipse.prototype._localDraw = function (context) {
  4045. context.save();
  4046. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4047. context.shadowColor = this.shadowColor;
  4048. context.shadowBlur = this.shadowBlur;
  4049. context.shadowOffsetX = this.shadowOffsetX;
  4050. context.shadowOffsetY = this.shadowOffsetY;
  4051. }
  4052. control_1.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2 - this._thickness / 2, this._currentMeasure.height / 2 - this._thickness / 2, context);
  4053. if (this._background) {
  4054. context.fillStyle = this._background;
  4055. context.fill();
  4056. }
  4057. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4058. context.shadowBlur = 0;
  4059. context.shadowOffsetX = 0;
  4060. context.shadowOffsetY = 0;
  4061. }
  4062. if (this._thickness) {
  4063. if (this.color) {
  4064. context.strokeStyle = this.color;
  4065. }
  4066. context.lineWidth = this._thickness;
  4067. context.stroke();
  4068. }
  4069. context.restore();
  4070. };
  4071. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  4072. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  4073. this._measureForChildren.width -= 2 * this._thickness;
  4074. this._measureForChildren.height -= 2 * this._thickness;
  4075. this._measureForChildren.left += this._thickness;
  4076. this._measureForChildren.top += this._thickness;
  4077. };
  4078. Ellipse.prototype._clipForChildren = function (context) {
  4079. control_1.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2, this._currentMeasure.height / 2, context);
  4080. context.clip();
  4081. };
  4082. return Ellipse;
  4083. }(container_1.Container));
  4084. exports.Ellipse = Ellipse;
  4085. /***/ }),
  4086. /***/ "./src/2D/controls/grid.ts":
  4087. /*!*********************************!*\
  4088. !*** ./src/2D/controls/grid.ts ***!
  4089. \*********************************/
  4090. /*! no static exports found */
  4091. /***/ (function(module, exports, __webpack_require__) {
  4092. "use strict";
  4093. var __extends = (this && this.__extends) || (function () {
  4094. var extendStatics = function (d, b) {
  4095. extendStatics = Object.setPrototypeOf ||
  4096. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4097. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4098. return extendStatics(d, b);
  4099. }
  4100. return function (d, b) {
  4101. extendStatics(d, b);
  4102. function __() { this.constructor = d; }
  4103. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4104. };
  4105. })();
  4106. Object.defineProperty(exports, "__esModule", { value: true });
  4107. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  4108. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  4109. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  4110. /**
  4111. * Class used to create a 2D grid container
  4112. */
  4113. var Grid = /** @class */ (function (_super) {
  4114. __extends(Grid, _super);
  4115. /**
  4116. * Creates a new Grid
  4117. * @param name defines control name
  4118. */
  4119. function Grid(name) {
  4120. var _this = _super.call(this, name) || this;
  4121. _this.name = name;
  4122. _this._rowDefinitions = new Array();
  4123. _this._columnDefinitions = new Array();
  4124. _this._cells = {};
  4125. _this._childControls = new Array();
  4126. return _this;
  4127. }
  4128. Object.defineProperty(Grid.prototype, "columnCount", {
  4129. /**
  4130. * Gets the number of columns
  4131. */
  4132. get: function () {
  4133. return this._columnDefinitions.length;
  4134. },
  4135. enumerable: true,
  4136. configurable: true
  4137. });
  4138. Object.defineProperty(Grid.prototype, "rowCount", {
  4139. /**
  4140. * Gets the number of rows
  4141. */
  4142. get: function () {
  4143. return this._rowDefinitions.length;
  4144. },
  4145. enumerable: true,
  4146. configurable: true
  4147. });
  4148. Object.defineProperty(Grid.prototype, "children", {
  4149. /** Gets the list of children */
  4150. get: function () {
  4151. return this._childControls;
  4152. },
  4153. enumerable: true,
  4154. configurable: true
  4155. });
  4156. /**
  4157. * Adds a new row to the grid
  4158. * @param height defines the height of the row (either in pixel or a value between 0 and 1)
  4159. * @param isPixel defines if the height is expressed in pixel (or in percentage)
  4160. * @returns the current grid
  4161. */
  4162. Grid.prototype.addRowDefinition = function (height, isPixel) {
  4163. if (isPixel === void 0) { isPixel = false; }
  4164. this._rowDefinitions.push(new valueAndUnit_1.ValueAndUnit(height, isPixel ? valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL : valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE));
  4165. this._markAsDirty();
  4166. return this;
  4167. };
  4168. /**
  4169. * Adds a new column to the grid
  4170. * @param width defines the width of the column (either in pixel or a value between 0 and 1)
  4171. * @param isPixel defines if the width is expressed in pixel (or in percentage)
  4172. * @returns the current grid
  4173. */
  4174. Grid.prototype.addColumnDefinition = function (width, isPixel) {
  4175. if (isPixel === void 0) { isPixel = false; }
  4176. this._columnDefinitions.push(new valueAndUnit_1.ValueAndUnit(width, isPixel ? valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL : valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE));
  4177. this._markAsDirty();
  4178. return this;
  4179. };
  4180. /**
  4181. * Update a row definition
  4182. * @param index defines the index of the row to update
  4183. * @param height defines the height of the row (either in pixel or a value between 0 and 1)
  4184. * @param isPixel defines if the weight is expressed in pixel (or in percentage)
  4185. * @returns the current grid
  4186. */
  4187. Grid.prototype.setRowDefinition = function (index, height, isPixel) {
  4188. if (isPixel === void 0) { isPixel = false; }
  4189. if (index < 0 || index >= this._rowDefinitions.length) {
  4190. return this;
  4191. }
  4192. this._rowDefinitions[index] = new valueAndUnit_1.ValueAndUnit(height, isPixel ? valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL : valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE);
  4193. this._markAsDirty();
  4194. return this;
  4195. };
  4196. /**
  4197. * Update a column definition
  4198. * @param index defines the index of the column to update
  4199. * @param width defines the width of the column (either in pixel or a value between 0 and 1)
  4200. * @param isPixel defines if the width is expressed in pixel (or in percentage)
  4201. * @returns the current grid
  4202. */
  4203. Grid.prototype.setColumnDefinition = function (index, width, isPixel) {
  4204. if (isPixel === void 0) { isPixel = false; }
  4205. if (index < 0 || index >= this._columnDefinitions.length) {
  4206. return this;
  4207. }
  4208. this._columnDefinitions[index] = new valueAndUnit_1.ValueAndUnit(width, isPixel ? valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL : valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE);
  4209. this._markAsDirty();
  4210. return this;
  4211. };
  4212. /**
  4213. * Gets the list of children stored in a specific cell
  4214. * @param row defines the row to check
  4215. * @param column defines the column to check
  4216. * @returns the list of controls
  4217. */
  4218. Grid.prototype.getChildrenAt = function (row, column) {
  4219. var cell = this._cells[row + ":" + column];
  4220. if (!cell) {
  4221. return null;
  4222. }
  4223. return cell.children;
  4224. };
  4225. Grid.prototype._removeCell = function (cell, key) {
  4226. if (!cell) {
  4227. return;
  4228. }
  4229. _super.prototype.removeControl.call(this, cell);
  4230. for (var _i = 0, _a = cell.children; _i < _a.length; _i++) {
  4231. var control = _a[_i];
  4232. var childIndex = this._childControls.indexOf(control);
  4233. if (childIndex !== -1) {
  4234. this._childControls.splice(childIndex, 1);
  4235. }
  4236. }
  4237. delete this._cells[key];
  4238. };
  4239. Grid.prototype._offsetCell = function (previousKey, key) {
  4240. if (!this._cells[key]) {
  4241. return;
  4242. }
  4243. this._cells[previousKey] = this._cells[key];
  4244. for (var _i = 0, _a = this._cells[previousKey].children; _i < _a.length; _i++) {
  4245. var control = _a[_i];
  4246. control._tag = previousKey;
  4247. }
  4248. delete this._cells[key];
  4249. };
  4250. /**
  4251. * Remove a column definition at specified index
  4252. * @param index defines the index of the column to remove
  4253. * @returns the current grid
  4254. */
  4255. Grid.prototype.removeColumnDefinition = function (index) {
  4256. if (index < 0 || index >= this._columnDefinitions.length) {
  4257. return this;
  4258. }
  4259. for (var x = 0; x < this._rowDefinitions.length; x++) {
  4260. var key = x + ":" + index;
  4261. var cell = this._cells[key];
  4262. this._removeCell(cell, key);
  4263. }
  4264. for (var x = 0; x < this._rowDefinitions.length; x++) {
  4265. for (var y = index + 1; y < this._columnDefinitions.length; y++) {
  4266. var previousKey = x + ":" + (y - 1);
  4267. var key = x + ":" + y;
  4268. this._offsetCell(previousKey, key);
  4269. }
  4270. }
  4271. this._columnDefinitions.splice(index, 1);
  4272. this._markAsDirty();
  4273. return this;
  4274. };
  4275. /**
  4276. * Remove a row definition at specified index
  4277. * @param index defines the index of the row to remove
  4278. * @returns the current grid
  4279. */
  4280. Grid.prototype.removeRowDefinition = function (index) {
  4281. if (index < 0 || index >= this._rowDefinitions.length) {
  4282. return this;
  4283. }
  4284. for (var y = 0; y < this._columnDefinitions.length; y++) {
  4285. var key = index + ":" + y;
  4286. var cell = this._cells[key];
  4287. this._removeCell(cell, key);
  4288. }
  4289. for (var y = 0; y < this._columnDefinitions.length; y++) {
  4290. for (var x = index + 1; x < this._rowDefinitions.length; x++) {
  4291. var previousKey = x - 1 + ":" + y;
  4292. var key = x + ":" + y;
  4293. this._offsetCell(previousKey, key);
  4294. }
  4295. }
  4296. this._rowDefinitions.splice(index, 1);
  4297. this._markAsDirty();
  4298. return this;
  4299. };
  4300. /**
  4301. * Adds a new control to the current grid
  4302. * @param control defines the control to add
  4303. * @param row defines the row where to add the control (0 by default)
  4304. * @param column defines the column where to add the control (0 by default)
  4305. * @returns the current grid
  4306. */
  4307. Grid.prototype.addControl = function (control, row, column) {
  4308. if (row === void 0) { row = 0; }
  4309. if (column === void 0) { column = 0; }
  4310. if (this._rowDefinitions.length === 0) {
  4311. // Add default row definition
  4312. this.addRowDefinition(1, false);
  4313. }
  4314. if (this._columnDefinitions.length === 0) {
  4315. // Add default column definition
  4316. this.addColumnDefinition(1, false);
  4317. }
  4318. var x = Math.min(row, this._rowDefinitions.length - 1);
  4319. var y = Math.min(column, this._columnDefinitions.length - 1);
  4320. var key = x + ":" + y;
  4321. var goodContainer = this._cells[key];
  4322. if (!goodContainer) {
  4323. goodContainer = new container_1.Container(key);
  4324. this._cells[key] = goodContainer;
  4325. goodContainer.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  4326. goodContainer.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  4327. _super.prototype.addControl.call(this, goodContainer);
  4328. }
  4329. goodContainer.addControl(control);
  4330. this._childControls.push(control);
  4331. control._tag = key;
  4332. this._markAsDirty();
  4333. return this;
  4334. };
  4335. /**
  4336. * Removes a control from the current container
  4337. * @param control defines the control to remove
  4338. * @returns the current container
  4339. */
  4340. Grid.prototype.removeControl = function (control) {
  4341. var index = this._childControls.indexOf(control);
  4342. if (index !== -1) {
  4343. this._childControls.splice(index, 1);
  4344. }
  4345. var cell = this._cells[control._tag];
  4346. if (cell) {
  4347. cell.removeControl(control);
  4348. }
  4349. this._markAsDirty();
  4350. return this;
  4351. };
  4352. Grid.prototype._getTypeName = function () {
  4353. return "Grid";
  4354. };
  4355. Grid.prototype._additionalProcessing = function (parentMeasure, context) {
  4356. var widths = [];
  4357. var heights = [];
  4358. var lefts = [];
  4359. var tops = [];
  4360. var availableWidth = this._currentMeasure.width;
  4361. var globalWidthPercentage = 0;
  4362. var availableHeight = this._currentMeasure.height;
  4363. var globalHeightPercentage = 0;
  4364. // Heights
  4365. var index = 0;
  4366. for (var _i = 0, _a = this._rowDefinitions; _i < _a.length; _i++) {
  4367. var value = _a[_i];
  4368. if (value.isPixel) {
  4369. var height = value.getValue(this._host);
  4370. availableHeight -= height;
  4371. heights[index] = height;
  4372. }
  4373. else {
  4374. globalHeightPercentage += value.internalValue;
  4375. }
  4376. index++;
  4377. }
  4378. var top = 0;
  4379. index = 0;
  4380. for (var _b = 0, _c = this._rowDefinitions; _b < _c.length; _b++) {
  4381. var value = _c[_b];
  4382. tops.push(top);
  4383. if (!value.isPixel) {
  4384. var height = (value.internalValue / globalHeightPercentage) * availableHeight;
  4385. top += height;
  4386. heights[index] = height;
  4387. }
  4388. else {
  4389. top += value.getValue(this._host);
  4390. }
  4391. index++;
  4392. }
  4393. // Widths
  4394. index = 0;
  4395. for (var _d = 0, _e = this._columnDefinitions; _d < _e.length; _d++) {
  4396. var value = _e[_d];
  4397. if (value.isPixel) {
  4398. var width = value.getValue(this._host);
  4399. availableWidth -= width;
  4400. widths[index] = width;
  4401. }
  4402. else {
  4403. globalWidthPercentage += value.internalValue;
  4404. }
  4405. index++;
  4406. }
  4407. var left = 0;
  4408. index = 0;
  4409. for (var _f = 0, _g = this._columnDefinitions; _f < _g.length; _f++) {
  4410. var value = _g[_f];
  4411. lefts.push(left);
  4412. if (!value.isPixel) {
  4413. var width = (value.internalValue / globalWidthPercentage) * availableWidth;
  4414. left += width;
  4415. widths[index] = width;
  4416. }
  4417. else {
  4418. left += value.getValue(this._host);
  4419. }
  4420. index++;
  4421. }
  4422. // Setting child sizes
  4423. for (var key in this._cells) {
  4424. if (!this._cells.hasOwnProperty(key)) {
  4425. continue;
  4426. }
  4427. var split = key.split(":");
  4428. var x = parseInt(split[0]);
  4429. var y = parseInt(split[1]);
  4430. var cell = this._cells[key];
  4431. cell.left = lefts[y] + "px";
  4432. cell.top = tops[x] + "px";
  4433. cell.width = widths[y] + "px";
  4434. cell.height = heights[x] + "px";
  4435. }
  4436. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  4437. };
  4438. /** Releases associated resources */
  4439. Grid.prototype.dispose = function () {
  4440. _super.prototype.dispose.call(this);
  4441. for (var _i = 0, _a = this._childControls; _i < _a.length; _i++) {
  4442. var control = _a[_i];
  4443. control.dispose();
  4444. }
  4445. };
  4446. return Grid;
  4447. }(container_1.Container));
  4448. exports.Grid = Grid;
  4449. /***/ }),
  4450. /***/ "./src/2D/controls/image.ts":
  4451. /*!**********************************!*\
  4452. !*** ./src/2D/controls/image.ts ***!
  4453. \**********************************/
  4454. /*! no static exports found */
  4455. /***/ (function(module, exports, __webpack_require__) {
  4456. "use strict";
  4457. var __extends = (this && this.__extends) || (function () {
  4458. var extendStatics = function (d, b) {
  4459. extendStatics = Object.setPrototypeOf ||
  4460. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4461. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4462. return extendStatics(d, b);
  4463. }
  4464. return function (d, b) {
  4465. extendStatics(d, b);
  4466. function __() { this.constructor = d; }
  4467. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4468. };
  4469. })();
  4470. Object.defineProperty(exports, "__esModule", { value: true });
  4471. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  4472. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  4473. /**
  4474. * Class used to create 2D images
  4475. */
  4476. var Image = /** @class */ (function (_super) {
  4477. __extends(Image, _super);
  4478. /**
  4479. * Creates a new Image
  4480. * @param name defines the control name
  4481. * @param url defines the image url
  4482. */
  4483. function Image(name, url) {
  4484. if (url === void 0) { url = null; }
  4485. var _this = _super.call(this, name) || this;
  4486. _this.name = name;
  4487. _this._loaded = false;
  4488. _this._stretch = Image.STRETCH_FILL;
  4489. _this._autoScale = false;
  4490. _this._sourceLeft = 0;
  4491. _this._sourceTop = 0;
  4492. _this._sourceWidth = 0;
  4493. _this._sourceHeight = 0;
  4494. _this._cellWidth = 0;
  4495. _this._cellHeight = 0;
  4496. _this._cellId = -1;
  4497. /**
  4498. * Observable notified when the content is loaded
  4499. */
  4500. _this.onImageLoadedObservable = new babylonjs_1.Observable();
  4501. _this.source = url;
  4502. return _this;
  4503. }
  4504. Object.defineProperty(Image.prototype, "isLoaded", {
  4505. /**
  4506. * Gets a boolean indicating that the content is loaded
  4507. */
  4508. get: function () {
  4509. return this._loaded;
  4510. },
  4511. enumerable: true,
  4512. configurable: true
  4513. });
  4514. Object.defineProperty(Image.prototype, "sourceLeft", {
  4515. /**
  4516. * Gets or sets the left coordinate in the source image
  4517. */
  4518. get: function () {
  4519. return this._sourceLeft;
  4520. },
  4521. set: function (value) {
  4522. if (this._sourceLeft === value) {
  4523. return;
  4524. }
  4525. this._sourceLeft = value;
  4526. this._markAsDirty();
  4527. },
  4528. enumerable: true,
  4529. configurable: true
  4530. });
  4531. Object.defineProperty(Image.prototype, "sourceTop", {
  4532. /**
  4533. * Gets or sets the top coordinate in the source image
  4534. */
  4535. get: function () {
  4536. return this._sourceTop;
  4537. },
  4538. set: function (value) {
  4539. if (this._sourceTop === value) {
  4540. return;
  4541. }
  4542. this._sourceTop = value;
  4543. this._markAsDirty();
  4544. },
  4545. enumerable: true,
  4546. configurable: true
  4547. });
  4548. Object.defineProperty(Image.prototype, "sourceWidth", {
  4549. /**
  4550. * Gets or sets the width to capture in the source image
  4551. */
  4552. get: function () {
  4553. return this._sourceWidth;
  4554. },
  4555. set: function (value) {
  4556. if (this._sourceWidth === value) {
  4557. return;
  4558. }
  4559. this._sourceWidth = value;
  4560. this._markAsDirty();
  4561. },
  4562. enumerable: true,
  4563. configurable: true
  4564. });
  4565. Object.defineProperty(Image.prototype, "sourceHeight", {
  4566. /**
  4567. * Gets or sets the height to capture in the source image
  4568. */
  4569. get: function () {
  4570. return this._sourceHeight;
  4571. },
  4572. set: function (value) {
  4573. if (this._sourceHeight === value) {
  4574. return;
  4575. }
  4576. this._sourceHeight = value;
  4577. this._markAsDirty();
  4578. },
  4579. enumerable: true,
  4580. configurable: true
  4581. });
  4582. Object.defineProperty(Image.prototype, "autoScale", {
  4583. /**
  4584. * Gets or sets a boolean indicating if the image can force its container to adapt its size
  4585. * @see http://doc.babylonjs.com/how_to/gui#image
  4586. */
  4587. get: function () {
  4588. return this._autoScale;
  4589. },
  4590. set: function (value) {
  4591. if (this._autoScale === value) {
  4592. return;
  4593. }
  4594. this._autoScale = value;
  4595. if (value && this._loaded) {
  4596. this.synchronizeSizeWithContent();
  4597. }
  4598. },
  4599. enumerable: true,
  4600. configurable: true
  4601. });
  4602. Object.defineProperty(Image.prototype, "stretch", {
  4603. /** Gets or sets the streching mode used by the image */
  4604. get: function () {
  4605. return this._stretch;
  4606. },
  4607. set: function (value) {
  4608. if (this._stretch === value) {
  4609. return;
  4610. }
  4611. this._stretch = value;
  4612. this._markAsDirty();
  4613. },
  4614. enumerable: true,
  4615. configurable: true
  4616. });
  4617. Object.defineProperty(Image.prototype, "domImage", {
  4618. get: function () {
  4619. return this._domImage;
  4620. },
  4621. /**
  4622. * Gets or sets the internal DOM image used to render the control
  4623. */
  4624. set: function (value) {
  4625. var _this = this;
  4626. this._domImage = value;
  4627. this._loaded = false;
  4628. if (this._domImage.width) {
  4629. this._onImageLoaded();
  4630. }
  4631. else {
  4632. this._domImage.onload = function () {
  4633. _this._onImageLoaded();
  4634. };
  4635. }
  4636. },
  4637. enumerable: true,
  4638. configurable: true
  4639. });
  4640. Image.prototype._onImageLoaded = function () {
  4641. this._imageWidth = this._domImage.width;
  4642. this._imageHeight = this._domImage.height;
  4643. this._loaded = true;
  4644. if (this._autoScale) {
  4645. this.synchronizeSizeWithContent();
  4646. }
  4647. this.onImageLoadedObservable.notifyObservers(this);
  4648. this._markAsDirty();
  4649. };
  4650. Object.defineProperty(Image.prototype, "source", {
  4651. /**
  4652. * Gets or sets image source url
  4653. */
  4654. set: function (value) {
  4655. var _this = this;
  4656. if (this._source === value) {
  4657. return;
  4658. }
  4659. this._loaded = false;
  4660. this._source = value;
  4661. this._domImage = document.createElement("img");
  4662. this._domImage.onload = function () {
  4663. _this._onImageLoaded();
  4664. };
  4665. if (value) {
  4666. babylonjs_1.Tools.SetCorsBehavior(value, this._domImage);
  4667. this._domImage.src = value;
  4668. }
  4669. },
  4670. enumerable: true,
  4671. configurable: true
  4672. });
  4673. Object.defineProperty(Image.prototype, "cellWidth", {
  4674. /**
  4675. * Gets or sets the cell width to use when animation sheet is enabled
  4676. * @see http://doc.babylonjs.com/how_to/gui#image
  4677. */
  4678. get: function () {
  4679. return this._cellWidth;
  4680. },
  4681. set: function (value) {
  4682. if (this._cellWidth === value) {
  4683. return;
  4684. }
  4685. this._cellWidth = value;
  4686. this._markAsDirty();
  4687. },
  4688. enumerable: true,
  4689. configurable: true
  4690. });
  4691. Object.defineProperty(Image.prototype, "cellHeight", {
  4692. /**
  4693. * Gets or sets the cell height to use when animation sheet is enabled
  4694. * @see http://doc.babylonjs.com/how_to/gui#image
  4695. */
  4696. get: function () {
  4697. return this._cellHeight;
  4698. },
  4699. set: function (value) {
  4700. if (this._cellHeight === value) {
  4701. return;
  4702. }
  4703. this._cellHeight = value;
  4704. this._markAsDirty();
  4705. },
  4706. enumerable: true,
  4707. configurable: true
  4708. });
  4709. Object.defineProperty(Image.prototype, "cellId", {
  4710. /**
  4711. * Gets or sets the cell id to use (this will turn on the animation sheet mode)
  4712. * @see http://doc.babylonjs.com/how_to/gui#image
  4713. */
  4714. get: function () {
  4715. return this._cellId;
  4716. },
  4717. set: function (value) {
  4718. if (this._cellId === value) {
  4719. return;
  4720. }
  4721. this._cellId = value;
  4722. this._markAsDirty();
  4723. },
  4724. enumerable: true,
  4725. configurable: true
  4726. });
  4727. Image.prototype._getTypeName = function () {
  4728. return "Image";
  4729. };
  4730. /** Force the control to synchronize with its content */
  4731. Image.prototype.synchronizeSizeWithContent = function () {
  4732. if (!this._loaded) {
  4733. return;
  4734. }
  4735. this.width = this._domImage.width + "px";
  4736. this.height = this._domImage.height + "px";
  4737. };
  4738. Image.prototype._draw = function (parentMeasure, context) {
  4739. context.save();
  4740. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4741. context.shadowColor = this.shadowColor;
  4742. context.shadowBlur = this.shadowBlur;
  4743. context.shadowOffsetX = this.shadowOffsetX;
  4744. context.shadowOffsetY = this.shadowOffsetY;
  4745. }
  4746. var x, y, width, height;
  4747. if (this.cellId == -1) {
  4748. x = this._sourceLeft;
  4749. y = this._sourceTop;
  4750. width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  4751. height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  4752. }
  4753. else {
  4754. var rowCount = this._domImage.naturalWidth / this.cellWidth;
  4755. var column = (this.cellId / rowCount) >> 0;
  4756. var row = this.cellId % rowCount;
  4757. x = this.cellWidth * row;
  4758. y = this.cellHeight * column;
  4759. width = this.cellWidth;
  4760. height = this.cellHeight;
  4761. }
  4762. this._applyStates(context);
  4763. if (this._processMeasures(parentMeasure, context)) {
  4764. if (this._loaded) {
  4765. switch (this._stretch) {
  4766. case Image.STRETCH_NONE:
  4767. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4768. break;
  4769. case Image.STRETCH_FILL:
  4770. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4771. break;
  4772. case Image.STRETCH_UNIFORM:
  4773. var hRatio = this._currentMeasure.width / width;
  4774. var vRatio = this._currentMeasure.height / height;
  4775. var ratio = Math.min(hRatio, vRatio);
  4776. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  4777. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  4778. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  4779. break;
  4780. case Image.STRETCH_EXTEND:
  4781. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4782. if (this._autoScale) {
  4783. this.synchronizeSizeWithContent();
  4784. }
  4785. if (this._root && this._root.parent) { // Will update root size if root is not the top root
  4786. this._root.width = this.width;
  4787. this._root.height = this.height;
  4788. }
  4789. break;
  4790. }
  4791. }
  4792. }
  4793. context.restore();
  4794. };
  4795. Image.prototype.dispose = function () {
  4796. _super.prototype.dispose.call(this);
  4797. this.onImageLoadedObservable.clear();
  4798. };
  4799. // Static
  4800. /** STRETCH_NONE */
  4801. Image.STRETCH_NONE = 0;
  4802. /** STRETCH_FILL */
  4803. Image.STRETCH_FILL = 1;
  4804. /** STRETCH_UNIFORM */
  4805. Image.STRETCH_UNIFORM = 2;
  4806. /** STRETCH_EXTEND */
  4807. Image.STRETCH_EXTEND = 3;
  4808. return Image;
  4809. }(control_1.Control));
  4810. exports.Image = Image;
  4811. /***/ }),
  4812. /***/ "./src/2D/controls/imageBasedSlider.ts":
  4813. /*!*********************************************!*\
  4814. !*** ./src/2D/controls/imageBasedSlider.ts ***!
  4815. \*********************************************/
  4816. /*! no static exports found */
  4817. /***/ (function(module, exports, __webpack_require__) {
  4818. "use strict";
  4819. var __extends = (this && this.__extends) || (function () {
  4820. var extendStatics = function (d, b) {
  4821. extendStatics = Object.setPrototypeOf ||
  4822. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4823. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4824. return extendStatics(d, b);
  4825. }
  4826. return function (d, b) {
  4827. extendStatics(d, b);
  4828. function __() { this.constructor = d; }
  4829. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4830. };
  4831. })();
  4832. Object.defineProperty(exports, "__esModule", { value: true });
  4833. var baseSlider_1 = __webpack_require__(/*! ./baseSlider */ "./src/2D/controls/baseSlider.ts");
  4834. var measure_1 = __webpack_require__(/*! ../measure */ "./src/2D/measure.ts");
  4835. /**
  4836. * Class used to create slider controls based on images
  4837. */
  4838. var ImageBasedSlider = /** @class */ (function (_super) {
  4839. __extends(ImageBasedSlider, _super);
  4840. /**
  4841. * Creates a new ImageBasedSlider
  4842. * @param name defines the control name
  4843. */
  4844. function ImageBasedSlider(name) {
  4845. var _this = _super.call(this, name) || this;
  4846. _this.name = name;
  4847. _this._tempMeasure = new measure_1.Measure(0, 0, 0, 0);
  4848. return _this;
  4849. }
  4850. Object.defineProperty(ImageBasedSlider.prototype, "displayThumb", {
  4851. get: function () {
  4852. return this._displayThumb && this.thumbImage != null;
  4853. },
  4854. set: function (value) {
  4855. if (this._displayThumb === value) {
  4856. return;
  4857. }
  4858. this._displayThumb = value;
  4859. this._markAsDirty();
  4860. },
  4861. enumerable: true,
  4862. configurable: true
  4863. });
  4864. Object.defineProperty(ImageBasedSlider.prototype, "backgroundImage", {
  4865. /**
  4866. * Gets or sets the image used to render the background
  4867. */
  4868. get: function () {
  4869. return this._backgroundImage;
  4870. },
  4871. set: function (value) {
  4872. var _this = this;
  4873. if (this._backgroundImage === value) {
  4874. return;
  4875. }
  4876. this._backgroundImage = value;
  4877. if (value && !value.isLoaded) {
  4878. value.onImageLoadedObservable.addOnce(function () { return _this._markAsDirty(); });
  4879. }
  4880. this._markAsDirty();
  4881. },
  4882. enumerable: true,
  4883. configurable: true
  4884. });
  4885. Object.defineProperty(ImageBasedSlider.prototype, "valueBarImage", {
  4886. /**
  4887. * Gets or sets the image used to render the value bar
  4888. */
  4889. get: function () {
  4890. return this._valueBarImage;
  4891. },
  4892. set: function (value) {
  4893. var _this = this;
  4894. if (this._valueBarImage === value) {
  4895. return;
  4896. }
  4897. this._valueBarImage = value;
  4898. if (value && !value.isLoaded) {
  4899. value.onImageLoadedObservable.addOnce(function () { return _this._markAsDirty(); });
  4900. }
  4901. this._markAsDirty();
  4902. },
  4903. enumerable: true,
  4904. configurable: true
  4905. });
  4906. Object.defineProperty(ImageBasedSlider.prototype, "thumbImage", {
  4907. /**
  4908. * Gets or sets the image used to render the thumb
  4909. */
  4910. get: function () {
  4911. return this._thumbImage;
  4912. },
  4913. set: function (value) {
  4914. var _this = this;
  4915. if (this._thumbImage === value) {
  4916. return;
  4917. }
  4918. this._thumbImage = value;
  4919. if (value && !value.isLoaded) {
  4920. value.onImageLoadedObservable.addOnce(function () { return _this._markAsDirty(); });
  4921. }
  4922. this._markAsDirty();
  4923. },
  4924. enumerable: true,
  4925. configurable: true
  4926. });
  4927. ImageBasedSlider.prototype._getTypeName = function () {
  4928. return "ImageBasedSlider";
  4929. };
  4930. ImageBasedSlider.prototype._draw = function (parentMeasure, context) {
  4931. context.save();
  4932. this._applyStates(context);
  4933. if (this._processMeasures(parentMeasure, context)) {
  4934. this._prepareRenderingData("rectangle");
  4935. var thumbPosition = this._getThumbPosition();
  4936. var left = this._renderLeft;
  4937. var top = this._renderTop;
  4938. var width = this._renderWidth;
  4939. var height = this._renderHeight;
  4940. // Background
  4941. if (this._backgroundImage) {
  4942. this._tempMeasure.copyFromFloats(left, top, width, height);
  4943. if (this.isThumbClamped && this.displayThumb) {
  4944. if (this.isVertical) {
  4945. this._tempMeasure.height += this._effectiveThumbThickness;
  4946. }
  4947. else {
  4948. this._tempMeasure.width += this._effectiveThumbThickness;
  4949. }
  4950. }
  4951. this._backgroundImage._draw(this._tempMeasure, context);
  4952. }
  4953. // Bar
  4954. if (this._valueBarImage) {
  4955. if (this.isVertical) {
  4956. if (this.isThumbClamped && this.displayThumb) {
  4957. this._tempMeasure.copyFromFloats(left, top + thumbPosition, width, height - thumbPosition + this._effectiveThumbThickness);
  4958. }
  4959. else {
  4960. this._tempMeasure.copyFromFloats(left, top + thumbPosition, width, height - thumbPosition);
  4961. }
  4962. }
  4963. else {
  4964. if (this.isThumbClamped && this.displayThumb) {
  4965. this._tempMeasure.copyFromFloats(left, top, thumbPosition + this._effectiveThumbThickness / 2, height);
  4966. }
  4967. else {
  4968. this._tempMeasure.copyFromFloats(left, top, thumbPosition, height);
  4969. }
  4970. }
  4971. this._valueBarImage._draw(this._tempMeasure, context);
  4972. }
  4973. // Thumb
  4974. if (this.displayThumb) {
  4975. if (this.isVertical) {
  4976. this._tempMeasure.copyFromFloats(left - this._effectiveBarOffset, this._currentMeasure.top + thumbPosition, this._currentMeasure.width, this._effectiveThumbThickness);
  4977. }
  4978. else {
  4979. this._tempMeasure.copyFromFloats(this._currentMeasure.left + thumbPosition, this._currentMeasure.top, this._effectiveThumbThickness, this._currentMeasure.height);
  4980. }
  4981. this._thumbImage._draw(this._tempMeasure, context);
  4982. }
  4983. }
  4984. context.restore();
  4985. };
  4986. return ImageBasedSlider;
  4987. }(baseSlider_1.BaseSlider));
  4988. exports.ImageBasedSlider = ImageBasedSlider;
  4989. /***/ }),
  4990. /***/ "./src/2D/controls/index.ts":
  4991. /*!**********************************!*\
  4992. !*** ./src/2D/controls/index.ts ***!
  4993. \**********************************/
  4994. /*! no static exports found */
  4995. /***/ (function(module, exports, __webpack_require__) {
  4996. "use strict";
  4997. function __export(m) {
  4998. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  4999. }
  5000. Object.defineProperty(exports, "__esModule", { value: true });
  5001. __export(__webpack_require__(/*! ./button */ "./src/2D/controls/button.ts"));
  5002. __export(__webpack_require__(/*! ./checkbox */ "./src/2D/controls/checkbox.ts"));
  5003. __export(__webpack_require__(/*! ./colorpicker */ "./src/2D/controls/colorpicker.ts"));
  5004. __export(__webpack_require__(/*! ./container */ "./src/2D/controls/container.ts"));
  5005. __export(__webpack_require__(/*! ./control */ "./src/2D/controls/control.ts"));
  5006. __export(__webpack_require__(/*! ./ellipse */ "./src/2D/controls/ellipse.ts"));
  5007. __export(__webpack_require__(/*! ./grid */ "./src/2D/controls/grid.ts"));
  5008. __export(__webpack_require__(/*! ./image */ "./src/2D/controls/image.ts"));
  5009. __export(__webpack_require__(/*! ./inputText */ "./src/2D/controls/inputText.ts"));
  5010. __export(__webpack_require__(/*! ./inputPassword */ "./src/2D/controls/inputPassword.ts"));
  5011. __export(__webpack_require__(/*! ./line */ "./src/2D/controls/line.ts"));
  5012. __export(__webpack_require__(/*! ./multiLine */ "./src/2D/controls/multiLine.ts"));
  5013. __export(__webpack_require__(/*! ./radioButton */ "./src/2D/controls/radioButton.ts"));
  5014. __export(__webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts"));
  5015. __export(__webpack_require__(/*! ./selector */ "./src/2D/controls/selector.ts"));
  5016. __export(__webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts"));
  5017. __export(__webpack_require__(/*! ./virtualKeyboard */ "./src/2D/controls/virtualKeyboard.ts"));
  5018. __export(__webpack_require__(/*! ./rectangle */ "./src/2D/controls/rectangle.ts"));
  5019. __export(__webpack_require__(/*! ./displayGrid */ "./src/2D/controls/displayGrid.ts"));
  5020. __export(__webpack_require__(/*! ./baseSlider */ "./src/2D/controls/baseSlider.ts"));
  5021. __export(__webpack_require__(/*! ./slider */ "./src/2D/controls/slider.ts"));
  5022. __export(__webpack_require__(/*! ./imageBasedSlider */ "./src/2D/controls/imageBasedSlider.ts"));
  5023. __export(__webpack_require__(/*! ./statics */ "./src/2D/controls/statics.ts"));
  5024. /***/ }),
  5025. /***/ "./src/2D/controls/inputPassword.ts":
  5026. /*!******************************************!*\
  5027. !*** ./src/2D/controls/inputPassword.ts ***!
  5028. \******************************************/
  5029. /*! no static exports found */
  5030. /***/ (function(module, exports, __webpack_require__) {
  5031. "use strict";
  5032. var __extends = (this && this.__extends) || (function () {
  5033. var extendStatics = function (d, b) {
  5034. extendStatics = Object.setPrototypeOf ||
  5035. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5036. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5037. return extendStatics(d, b);
  5038. }
  5039. return function (d, b) {
  5040. extendStatics(d, b);
  5041. function __() { this.constructor = d; }
  5042. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5043. };
  5044. })();
  5045. Object.defineProperty(exports, "__esModule", { value: true });
  5046. var inputText_1 = __webpack_require__(/*! ./inputText */ "./src/2D/controls/inputText.ts");
  5047. /**
  5048. * Class used to create a password control
  5049. */
  5050. var InputPassword = /** @class */ (function (_super) {
  5051. __extends(InputPassword, _super);
  5052. function InputPassword() {
  5053. return _super !== null && _super.apply(this, arguments) || this;
  5054. }
  5055. InputPassword.prototype._beforeRenderText = function (text) {
  5056. var txt = "";
  5057. for (var i = 0; i < text.length; i++) {
  5058. txt += "\u2022";
  5059. }
  5060. return txt;
  5061. };
  5062. return InputPassword;
  5063. }(inputText_1.InputText));
  5064. exports.InputPassword = InputPassword;
  5065. /***/ }),
  5066. /***/ "./src/2D/controls/inputText.ts":
  5067. /*!**************************************!*\
  5068. !*** ./src/2D/controls/inputText.ts ***!
  5069. \**************************************/
  5070. /*! no static exports found */
  5071. /***/ (function(module, exports, __webpack_require__) {
  5072. "use strict";
  5073. var __extends = (this && this.__extends) || (function () {
  5074. var extendStatics = function (d, b) {
  5075. extendStatics = Object.setPrototypeOf ||
  5076. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5077. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5078. return extendStatics(d, b);
  5079. }
  5080. return function (d, b) {
  5081. extendStatics(d, b);
  5082. function __() { this.constructor = d; }
  5083. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5084. };
  5085. })();
  5086. Object.defineProperty(exports, "__esModule", { value: true });
  5087. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  5088. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  5089. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  5090. /**
  5091. * Class used to create input text control
  5092. */
  5093. var InputText = /** @class */ (function (_super) {
  5094. __extends(InputText, _super);
  5095. /**
  5096. * Creates a new InputText
  5097. * @param name defines the control name
  5098. * @param text defines the text of the control
  5099. */
  5100. function InputText(name, text) {
  5101. if (text === void 0) { text = ""; }
  5102. var _this = _super.call(this, name) || this;
  5103. _this.name = name;
  5104. _this._text = "";
  5105. _this._placeholderText = "";
  5106. _this._background = "#222222";
  5107. _this._focusedBackground = "#000000";
  5108. _this._placeholderColor = "gray";
  5109. _this._thickness = 1;
  5110. _this._margin = new valueAndUnit_1.ValueAndUnit(10, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL);
  5111. _this._autoStretchWidth = true;
  5112. _this._maxWidth = new valueAndUnit_1.ValueAndUnit(1, valueAndUnit_1.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  5113. _this._isFocused = false;
  5114. _this._blinkIsEven = false;
  5115. _this._cursorOffset = 0;
  5116. _this._deadKey = false;
  5117. _this._addKey = true;
  5118. _this._currentKey = "";
  5119. /** Gets or sets a string representing the message displayed on mobile when the control gets the focus */
  5120. _this.promptMessage = "Please enter text:";
  5121. /** Observable raised when the text changes */
  5122. _this.onTextChangedObservable = new babylonjs_1.Observable();
  5123. /** Observable raised just before an entered character is to be added */
  5124. _this.onBeforeKeyAddObservable = new babylonjs_1.Observable();
  5125. /** Observable raised when the control gets the focus */
  5126. _this.onFocusObservable = new babylonjs_1.Observable();
  5127. /** Observable raised when the control loses the focus */
  5128. _this.onBlurObservable = new babylonjs_1.Observable();
  5129. _this.text = text;
  5130. return _this;
  5131. }
  5132. Object.defineProperty(InputText.prototype, "maxWidth", {
  5133. /** Gets or sets the maximum width allowed by the control */
  5134. get: function () {
  5135. return this._maxWidth.toString(this._host);
  5136. },
  5137. set: function (value) {
  5138. if (this._maxWidth.toString(this._host) === value) {
  5139. return;
  5140. }
  5141. if (this._maxWidth.fromString(value)) {
  5142. this._markAsDirty();
  5143. }
  5144. },
  5145. enumerable: true,
  5146. configurable: true
  5147. });
  5148. Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
  5149. /** Gets the maximum width allowed by the control in pixels */
  5150. get: function () {
  5151. return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  5152. },
  5153. enumerable: true,
  5154. configurable: true
  5155. });
  5156. Object.defineProperty(InputText.prototype, "margin", {
  5157. /** Gets or sets control margin */
  5158. get: function () {
  5159. return this._margin.toString(this._host);
  5160. },
  5161. set: function (value) {
  5162. if (this._margin.toString(this._host) === value) {
  5163. return;
  5164. }
  5165. if (this._margin.fromString(value)) {
  5166. this._markAsDirty();
  5167. }
  5168. },
  5169. enumerable: true,
  5170. configurable: true
  5171. });
  5172. Object.defineProperty(InputText.prototype, "marginInPixels", {
  5173. /** Gets control margin in pixels */
  5174. get: function () {
  5175. return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
  5176. },
  5177. enumerable: true,
  5178. configurable: true
  5179. });
  5180. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  5181. /** Gets or sets a boolean indicating if the control can auto stretch its width to adapt to the text */
  5182. get: function () {
  5183. return this._autoStretchWidth;
  5184. },
  5185. set: function (value) {
  5186. if (this._autoStretchWidth === value) {
  5187. return;
  5188. }
  5189. this._autoStretchWidth = value;
  5190. this._markAsDirty();
  5191. },
  5192. enumerable: true,
  5193. configurable: true
  5194. });
  5195. Object.defineProperty(InputText.prototype, "thickness", {
  5196. /** Gets or sets border thickness */
  5197. get: function () {
  5198. return this._thickness;
  5199. },
  5200. set: function (value) {
  5201. if (this._thickness === value) {
  5202. return;
  5203. }
  5204. this._thickness = value;
  5205. this._markAsDirty();
  5206. },
  5207. enumerable: true,
  5208. configurable: true
  5209. });
  5210. Object.defineProperty(InputText.prototype, "focusedBackground", {
  5211. /** Gets or sets the background color when focused */
  5212. get: function () {
  5213. return this._focusedBackground;
  5214. },
  5215. set: function (value) {
  5216. if (this._focusedBackground === value) {
  5217. return;
  5218. }
  5219. this._focusedBackground = value;
  5220. this._markAsDirty();
  5221. },
  5222. enumerable: true,
  5223. configurable: true
  5224. });
  5225. Object.defineProperty(InputText.prototype, "background", {
  5226. /** Gets or sets the background color */
  5227. get: function () {
  5228. return this._background;
  5229. },
  5230. set: function (value) {
  5231. if (this._background === value) {
  5232. return;
  5233. }
  5234. this._background = value;
  5235. this._markAsDirty();
  5236. },
  5237. enumerable: true,
  5238. configurable: true
  5239. });
  5240. Object.defineProperty(InputText.prototype, "placeholderColor", {
  5241. /** Gets or sets the placeholder color */
  5242. get: function () {
  5243. return this._placeholderColor;
  5244. },
  5245. set: function (value) {
  5246. if (this._placeholderColor === value) {
  5247. return;
  5248. }
  5249. this._placeholderColor = value;
  5250. this._markAsDirty();
  5251. },
  5252. enumerable: true,
  5253. configurable: true
  5254. });
  5255. Object.defineProperty(InputText.prototype, "placeholderText", {
  5256. /** Gets or sets the text displayed when the control is empty */
  5257. get: function () {
  5258. return this._placeholderText;
  5259. },
  5260. set: function (value) {
  5261. if (this._placeholderText === value) {
  5262. return;
  5263. }
  5264. this._placeholderText = value;
  5265. this._markAsDirty();
  5266. },
  5267. enumerable: true,
  5268. configurable: true
  5269. });
  5270. Object.defineProperty(InputText.prototype, "deadKey", {
  5271. /** Gets or sets the dead key flag */
  5272. get: function () {
  5273. return this._deadKey;
  5274. },
  5275. set: function (flag) {
  5276. this._deadKey = flag;
  5277. },
  5278. enumerable: true,
  5279. configurable: true
  5280. });
  5281. Object.defineProperty(InputText.prototype, "addKey", {
  5282. /** Gets or sets if the current key should be added */
  5283. get: function () {
  5284. return this._addKey;
  5285. },
  5286. set: function (flag) {
  5287. this._addKey = flag;
  5288. },
  5289. enumerable: true,
  5290. configurable: true
  5291. });
  5292. Object.defineProperty(InputText.prototype, "currentKey", {
  5293. /** Gets or sets the value of the current key being entered */
  5294. get: function () {
  5295. return this._currentKey;
  5296. },
  5297. set: function (key) {
  5298. this._currentKey = key;
  5299. },
  5300. enumerable: true,
  5301. configurable: true
  5302. });
  5303. Object.defineProperty(InputText.prototype, "text", {
  5304. /** Gets or sets the text displayed in the control */
  5305. get: function () {
  5306. return this._text;
  5307. },
  5308. set: function (value) {
  5309. if (this._text === value) {
  5310. return;
  5311. }
  5312. this._text = value;
  5313. this._markAsDirty();
  5314. this.onTextChangedObservable.notifyObservers(this);
  5315. },
  5316. enumerable: true,
  5317. configurable: true
  5318. });
  5319. Object.defineProperty(InputText.prototype, "width", {
  5320. /** Gets or sets control width */
  5321. get: function () {
  5322. return this._width.toString(this._host);
  5323. },
  5324. set: function (value) {
  5325. if (this._width.toString(this._host) === value) {
  5326. return;
  5327. }
  5328. if (this._width.fromString(value)) {
  5329. this._markAsDirty();
  5330. }
  5331. this.autoStretchWidth = false;
  5332. },
  5333. enumerable: true,
  5334. configurable: true
  5335. });
  5336. /** @hidden */
  5337. InputText.prototype.onBlur = function () {
  5338. this._isFocused = false;
  5339. this._scrollLeft = null;
  5340. this._cursorOffset = 0;
  5341. clearTimeout(this._blinkTimeout);
  5342. this._markAsDirty();
  5343. this.onBlurObservable.notifyObservers(this);
  5344. };
  5345. /** @hidden */
  5346. InputText.prototype.onFocus = function () {
  5347. if (!this._isEnabled) {
  5348. return;
  5349. }
  5350. this._scrollLeft = null;
  5351. this._isFocused = true;
  5352. this._blinkIsEven = false;
  5353. this._cursorOffset = 0;
  5354. this._markAsDirty();
  5355. this.onFocusObservable.notifyObservers(this);
  5356. if (navigator.userAgent.indexOf("Mobile") !== -1) {
  5357. var value = prompt(this.promptMessage);
  5358. if (value !== null) {
  5359. this.text = value;
  5360. }
  5361. this._host.focusedControl = null;
  5362. return;
  5363. }
  5364. };
  5365. InputText.prototype._getTypeName = function () {
  5366. return "InputText";
  5367. };
  5368. /**
  5369. * Function called to get the list of controls that should not steal the focus from this control
  5370. * @returns an array of controls
  5371. */
  5372. InputText.prototype.keepsFocusWith = function () {
  5373. if (!this._connectedVirtualKeyboard) {
  5374. return null;
  5375. }
  5376. return [this._connectedVirtualKeyboard];
  5377. };
  5378. /** @hidden */
  5379. InputText.prototype.processKey = function (keyCode, key, evt) {
  5380. // Specific cases
  5381. switch (keyCode) {
  5382. case 32: //SPACE
  5383. key = " "; //ie11 key for space is "Spacebar"
  5384. break;
  5385. case 191: //SLASH
  5386. if (evt) {
  5387. evt.preventDefault();
  5388. }
  5389. break;
  5390. case 8: // BACKSPACE
  5391. if (this._text && this._text.length > 0) {
  5392. if (this._cursorOffset === 0) {
  5393. this.text = this._text.substr(0, this._text.length - 1);
  5394. }
  5395. else {
  5396. var deletePosition = this._text.length - this._cursorOffset;
  5397. if (deletePosition > 0) {
  5398. this.text = this._text.slice(0, deletePosition - 1) + this._text.slice(deletePosition);
  5399. }
  5400. }
  5401. }
  5402. if (evt) {
  5403. evt.preventDefault();
  5404. }
  5405. return;
  5406. case 46: // DELETE
  5407. if (this._text && this._text.length > 0 && this._cursorOffset > 0) {
  5408. var deletePosition = this._text.length - this._cursorOffset;
  5409. this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
  5410. this._cursorOffset--;
  5411. }
  5412. return;
  5413. case 13: // RETURN
  5414. this._host.focusedControl = null;
  5415. return;
  5416. case 35: // END
  5417. this._cursorOffset = 0;
  5418. this._blinkIsEven = false;
  5419. this._markAsDirty();
  5420. return;
  5421. case 36: // HOME
  5422. this._cursorOffset = this._text.length;
  5423. this._blinkIsEven = false;
  5424. this._markAsDirty();
  5425. return;
  5426. case 37: // LEFT
  5427. this._cursorOffset++;
  5428. if (this._cursorOffset > this._text.length) {
  5429. this._cursorOffset = this._text.length;
  5430. }
  5431. this._blinkIsEven = false;
  5432. this._markAsDirty();
  5433. return;
  5434. case 39: // RIGHT
  5435. this._cursorOffset--;
  5436. if (this._cursorOffset < 0) {
  5437. this._cursorOffset = 0;
  5438. }
  5439. this._blinkIsEven = false;
  5440. this._markAsDirty();
  5441. return;
  5442. case 222: // Dead
  5443. if (evt) {
  5444. evt.preventDefault();
  5445. }
  5446. this.deadKey = true;
  5447. break;
  5448. }
  5449. // Printable characters
  5450. if (key &&
  5451. ((keyCode === -1) || // Direct access
  5452. (keyCode === 32) || // Space
  5453. (keyCode > 47 && keyCode < 64) || // Numbers
  5454. (keyCode > 64 && keyCode < 91) || // Letters
  5455. (keyCode > 159 && keyCode < 193) || // Special characters
  5456. (keyCode > 218 && keyCode < 223) || // Special characters
  5457. (keyCode > 95 && keyCode < 112))) { // Numpad
  5458. this._currentKey = key;
  5459. this.onBeforeKeyAddObservable.notifyObservers(this);
  5460. key = this._currentKey;
  5461. if (this._addKey) {
  5462. if (this._cursorOffset === 0) {
  5463. this.text += key;
  5464. }
  5465. else {
  5466. var insertPosition = this._text.length - this._cursorOffset;
  5467. this.text = this._text.slice(0, insertPosition) + key + this._text.slice(insertPosition);
  5468. }
  5469. }
  5470. }
  5471. };
  5472. /** @hidden */
  5473. InputText.prototype.processKeyboard = function (evt) {
  5474. this.processKey(evt.keyCode, evt.key, evt);
  5475. };
  5476. InputText.prototype._draw = function (parentMeasure, context) {
  5477. var _this = this;
  5478. context.save();
  5479. this._applyStates(context);
  5480. if (this._processMeasures(parentMeasure, context)) {
  5481. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5482. context.shadowColor = this.shadowColor;
  5483. context.shadowBlur = this.shadowBlur;
  5484. context.shadowOffsetX = this.shadowOffsetX;
  5485. context.shadowOffsetY = this.shadowOffsetY;
  5486. }
  5487. // Background
  5488. if (this._isFocused) {
  5489. if (this._focusedBackground) {
  5490. context.fillStyle = this._isEnabled ? this._focusedBackground : this._disabledColor;
  5491. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  5492. }
  5493. }
  5494. else if (this._background) {
  5495. context.fillStyle = this._isEnabled ? this._background : this._disabledColor;
  5496. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  5497. }
  5498. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5499. context.shadowBlur = 0;
  5500. context.shadowOffsetX = 0;
  5501. context.shadowOffsetY = 0;
  5502. }
  5503. if (!this._fontOffset) {
  5504. this._fontOffset = control_1.Control._GetFontOffset(context.font);
  5505. }
  5506. // Text
  5507. var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width);
  5508. if (this.color) {
  5509. context.fillStyle = this.color;
  5510. }
  5511. var text = this._beforeRenderText(this._text);
  5512. if (!this._isFocused && !this._text && this._placeholderText) {
  5513. text = this._placeholderText;
  5514. if (this._placeholderColor) {
  5515. context.fillStyle = this._placeholderColor;
  5516. }
  5517. }
  5518. this._textWidth = context.measureText(text).width;
  5519. var marginWidth = this._margin.getValueInPixel(this._host, parentMeasure.width) * 2;
  5520. if (this._autoStretchWidth) {
  5521. this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), this._textWidth + marginWidth) + "px";
  5522. }
  5523. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  5524. var availableWidth = this._width.getValueInPixel(this._host, parentMeasure.width) - marginWidth;
  5525. context.save();
  5526. context.beginPath();
  5527. context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
  5528. context.clip();
  5529. if (this._isFocused && this._textWidth > availableWidth) {
  5530. var textLeft = clipTextLeft - this._textWidth + availableWidth;
  5531. if (!this._scrollLeft) {
  5532. this._scrollLeft = textLeft;
  5533. }
  5534. }
  5535. else {
  5536. this._scrollLeft = clipTextLeft;
  5537. }
  5538. context.fillText(text, this._scrollLeft, this._currentMeasure.top + rootY);
  5539. // Cursor
  5540. if (this._isFocused) {
  5541. // Need to move cursor
  5542. if (this._clickedCoordinate) {
  5543. var rightPosition = this._scrollLeft + this._textWidth;
  5544. var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
  5545. var currentSize = 0;
  5546. this._cursorOffset = 0;
  5547. var previousDist = 0;
  5548. do {
  5549. if (this._cursorOffset) {
  5550. previousDist = Math.abs(absoluteCursorPosition - currentSize);
  5551. }
  5552. this._cursorOffset++;
  5553. currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
  5554. } while (currentSize < absoluteCursorPosition && (text.length >= this._cursorOffset));
  5555. // Find closest move
  5556. if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
  5557. this._cursorOffset--;
  5558. }
  5559. this._blinkIsEven = false;
  5560. this._clickedCoordinate = null;
  5561. }
  5562. // Render cursor
  5563. if (!this._blinkIsEven) {
  5564. var cursorOffsetText = this.text.substr(this._text.length - this._cursorOffset);
  5565. var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
  5566. var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
  5567. if (cursorLeft < clipTextLeft) {
  5568. this._scrollLeft += (clipTextLeft - cursorLeft);
  5569. cursorLeft = clipTextLeft;
  5570. this._markAsDirty();
  5571. }
  5572. else if (cursorLeft > clipTextLeft + availableWidth) {
  5573. this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
  5574. cursorLeft = clipTextLeft + availableWidth;
  5575. this._markAsDirty();
  5576. }
  5577. context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
  5578. }
  5579. clearTimeout(this._blinkTimeout);
  5580. this._blinkTimeout = setTimeout(function () {
  5581. _this._blinkIsEven = !_this._blinkIsEven;
  5582. _this._markAsDirty();
  5583. }, 500);
  5584. }
  5585. context.restore();
  5586. // Border
  5587. if (this._thickness) {
  5588. if (this.color) {
  5589. context.strokeStyle = this.color;
  5590. }
  5591. context.lineWidth = this._thickness;
  5592. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  5593. }
  5594. }
  5595. context.restore();
  5596. };
  5597. InputText.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5598. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5599. return false;
  5600. }
  5601. this._clickedCoordinate = coordinates.x;
  5602. if (this._host.focusedControl === this) {
  5603. // Move cursor
  5604. clearTimeout(this._blinkTimeout);
  5605. this._markAsDirty();
  5606. return true;
  5607. }
  5608. if (!this._isEnabled) {
  5609. return false;
  5610. }
  5611. this._host.focusedControl = this;
  5612. return true;
  5613. };
  5614. InputText.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5615. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5616. };
  5617. InputText.prototype._beforeRenderText = function (text) {
  5618. return text;
  5619. };
  5620. InputText.prototype.dispose = function () {
  5621. _super.prototype.dispose.call(this);
  5622. this.onBlurObservable.clear();
  5623. this.onFocusObservable.clear();
  5624. this.onTextChangedObservable.clear();
  5625. };
  5626. return InputText;
  5627. }(control_1.Control));
  5628. exports.InputText = InputText;
  5629. /***/ }),
  5630. /***/ "./src/2D/controls/line.ts":
  5631. /*!*********************************!*\
  5632. !*** ./src/2D/controls/line.ts ***!
  5633. \*********************************/
  5634. /*! no static exports found */
  5635. /***/ (function(module, exports, __webpack_require__) {
  5636. "use strict";
  5637. var __extends = (this && this.__extends) || (function () {
  5638. var extendStatics = function (d, b) {
  5639. extendStatics = Object.setPrototypeOf ||
  5640. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5641. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5642. return extendStatics(d, b);
  5643. }
  5644. return function (d, b) {
  5645. extendStatics(d, b);
  5646. function __() { this.constructor = d; }
  5647. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5648. };
  5649. })();
  5650. Object.defineProperty(exports, "__esModule", { value: true });
  5651. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  5652. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  5653. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  5654. /** Class used to render 2D lines */
  5655. var Line = /** @class */ (function (_super) {
  5656. __extends(Line, _super);
  5657. /**
  5658. * Creates a new Line
  5659. * @param name defines the control name
  5660. */
  5661. function Line(name) {
  5662. var _this = _super.call(this, name) || this;
  5663. _this.name = name;
  5664. _this._lineWidth = 1;
  5665. _this._x1 = new valueAndUnit_1.ValueAndUnit(0);
  5666. _this._y1 = new valueAndUnit_1.ValueAndUnit(0);
  5667. _this._x2 = new valueAndUnit_1.ValueAndUnit(0);
  5668. _this._y2 = new valueAndUnit_1.ValueAndUnit(0);
  5669. _this._dash = new Array();
  5670. _this.isHitTestVisible = false;
  5671. _this._horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5672. _this._verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  5673. return _this;
  5674. }
  5675. Object.defineProperty(Line.prototype, "dash", {
  5676. /** Gets or sets the dash pattern */
  5677. get: function () {
  5678. return this._dash;
  5679. },
  5680. set: function (value) {
  5681. if (this._dash === value) {
  5682. return;
  5683. }
  5684. this._dash = value;
  5685. this._markAsDirty();
  5686. },
  5687. enumerable: true,
  5688. configurable: true
  5689. });
  5690. Object.defineProperty(Line.prototype, "connectedControl", {
  5691. /** Gets or sets the control connected with the line end */
  5692. get: function () {
  5693. return this._connectedControl;
  5694. },
  5695. set: function (value) {
  5696. var _this = this;
  5697. if (this._connectedControl === value) {
  5698. return;
  5699. }
  5700. if (this._connectedControlDirtyObserver && this._connectedControl) {
  5701. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  5702. this._connectedControlDirtyObserver = null;
  5703. }
  5704. if (value) {
  5705. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  5706. }
  5707. this._connectedControl = value;
  5708. this._markAsDirty();
  5709. },
  5710. enumerable: true,
  5711. configurable: true
  5712. });
  5713. Object.defineProperty(Line.prototype, "x1", {
  5714. /** Gets or sets start coordinates on X axis */
  5715. get: function () {
  5716. return this._x1.toString(this._host);
  5717. },
  5718. set: function (value) {
  5719. if (this._x1.toString(this._host) === value) {
  5720. return;
  5721. }
  5722. if (this._x1.fromString(value)) {
  5723. this._markAsDirty();
  5724. }
  5725. },
  5726. enumerable: true,
  5727. configurable: true
  5728. });
  5729. Object.defineProperty(Line.prototype, "y1", {
  5730. /** Gets or sets start coordinates on Y axis */
  5731. get: function () {
  5732. return this._y1.toString(this._host);
  5733. },
  5734. set: function (value) {
  5735. if (this._y1.toString(this._host) === value) {
  5736. return;
  5737. }
  5738. if (this._y1.fromString(value)) {
  5739. this._markAsDirty();
  5740. }
  5741. },
  5742. enumerable: true,
  5743. configurable: true
  5744. });
  5745. Object.defineProperty(Line.prototype, "x2", {
  5746. /** Gets or sets end coordinates on X axis */
  5747. get: function () {
  5748. return this._x2.toString(this._host);
  5749. },
  5750. set: function (value) {
  5751. if (this._x2.toString(this._host) === value) {
  5752. return;
  5753. }
  5754. if (this._x2.fromString(value)) {
  5755. this._markAsDirty();
  5756. }
  5757. },
  5758. enumerable: true,
  5759. configurable: true
  5760. });
  5761. Object.defineProperty(Line.prototype, "y2", {
  5762. /** Gets or sets end coordinates on Y axis */
  5763. get: function () {
  5764. return this._y2.toString(this._host);
  5765. },
  5766. set: function (value) {
  5767. if (this._y2.toString(this._host) === value) {
  5768. return;
  5769. }
  5770. if (this._y2.fromString(value)) {
  5771. this._markAsDirty();
  5772. }
  5773. },
  5774. enumerable: true,
  5775. configurable: true
  5776. });
  5777. Object.defineProperty(Line.prototype, "lineWidth", {
  5778. /** Gets or sets line width */
  5779. get: function () {
  5780. return this._lineWidth;
  5781. },
  5782. set: function (value) {
  5783. if (this._lineWidth === value) {
  5784. return;
  5785. }
  5786. this._lineWidth = value;
  5787. this._markAsDirty();
  5788. },
  5789. enumerable: true,
  5790. configurable: true
  5791. });
  5792. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  5793. /** Gets or sets horizontal alignment */
  5794. set: function (value) {
  5795. return;
  5796. },
  5797. enumerable: true,
  5798. configurable: true
  5799. });
  5800. Object.defineProperty(Line.prototype, "verticalAlignment", {
  5801. /** Gets or sets vertical alignment */
  5802. set: function (value) {
  5803. return;
  5804. },
  5805. enumerable: true,
  5806. configurable: true
  5807. });
  5808. Object.defineProperty(Line.prototype, "_effectiveX2", {
  5809. get: function () {
  5810. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  5811. },
  5812. enumerable: true,
  5813. configurable: true
  5814. });
  5815. Object.defineProperty(Line.prototype, "_effectiveY2", {
  5816. get: function () {
  5817. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  5818. },
  5819. enumerable: true,
  5820. configurable: true
  5821. });
  5822. Line.prototype._getTypeName = function () {
  5823. return "Line";
  5824. };
  5825. Line.prototype._draw = function (parentMeasure, context) {
  5826. context.save();
  5827. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5828. context.shadowColor = this.shadowColor;
  5829. context.shadowBlur = this.shadowBlur;
  5830. context.shadowOffsetX = this.shadowOffsetX;
  5831. context.shadowOffsetY = this.shadowOffsetY;
  5832. }
  5833. this._applyStates(context);
  5834. if (this._processMeasures(parentMeasure, context)) {
  5835. context.strokeStyle = this.color;
  5836. context.lineWidth = this._lineWidth;
  5837. context.setLineDash(this._dash);
  5838. context.beginPath();
  5839. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  5840. context.lineTo(this._effectiveX2, this._effectiveY2);
  5841. context.stroke();
  5842. }
  5843. context.restore();
  5844. };
  5845. Line.prototype._measure = function () {
  5846. // Width / Height
  5847. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  5848. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  5849. };
  5850. Line.prototype._computeAlignment = function (parentMeasure, context) {
  5851. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  5852. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  5853. };
  5854. /**
  5855. * Move one end of the line given 3D cartesian coordinates.
  5856. * @param position Targeted world position
  5857. * @param scene Scene
  5858. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  5859. */
  5860. Line.prototype.moveToVector3 = function (position, scene, end) {
  5861. if (end === void 0) { end = false; }
  5862. if (!this._host || this._root !== this._host._rootContainer) {
  5863. babylonjs_1.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  5864. return;
  5865. }
  5866. var globalViewport = this._host._getGlobalViewport(scene);
  5867. var projectedPosition = babylonjs_1.Vector3.Project(position, babylonjs_1.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  5868. this._moveToProjectedPosition(projectedPosition, end);
  5869. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  5870. this.notRenderable = true;
  5871. return;
  5872. }
  5873. this.notRenderable = false;
  5874. };
  5875. /**
  5876. * Move one end of the line to a position in screen absolute space.
  5877. * @param projectedPosition Position in screen absolute space (X, Y)
  5878. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  5879. */
  5880. Line.prototype._moveToProjectedPosition = function (projectedPosition, end) {
  5881. if (end === void 0) { end = false; }
  5882. var x = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  5883. var y = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  5884. if (end) {
  5885. this.x2 = x;
  5886. this.y2 = y;
  5887. this._x2.ignoreAdaptiveScaling = true;
  5888. this._y2.ignoreAdaptiveScaling = true;
  5889. }
  5890. else {
  5891. this.x1 = x;
  5892. this.y1 = y;
  5893. this._x1.ignoreAdaptiveScaling = true;
  5894. this._y1.ignoreAdaptiveScaling = true;
  5895. }
  5896. };
  5897. return Line;
  5898. }(control_1.Control));
  5899. exports.Line = Line;
  5900. /***/ }),
  5901. /***/ "./src/2D/controls/multiLine.ts":
  5902. /*!**************************************!*\
  5903. !*** ./src/2D/controls/multiLine.ts ***!
  5904. \**************************************/
  5905. /*! no static exports found */
  5906. /***/ (function(module, exports, __webpack_require__) {
  5907. "use strict";
  5908. var __extends = (this && this.__extends) || (function () {
  5909. var extendStatics = function (d, b) {
  5910. extendStatics = Object.setPrototypeOf ||
  5911. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5912. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5913. return extendStatics(d, b);
  5914. }
  5915. return function (d, b) {
  5916. extendStatics(d, b);
  5917. function __() { this.constructor = d; }
  5918. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5919. };
  5920. })();
  5921. Object.defineProperty(exports, "__esModule", { value: true });
  5922. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  5923. var multiLinePoint_1 = __webpack_require__(/*! ../multiLinePoint */ "./src/2D/multiLinePoint.ts");
  5924. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  5925. /**
  5926. * Class used to create multi line control
  5927. */
  5928. var MultiLine = /** @class */ (function (_super) {
  5929. __extends(MultiLine, _super);
  5930. /**
  5931. * Creates a new MultiLine
  5932. * @param name defines the control name
  5933. */
  5934. function MultiLine(name) {
  5935. var _this = _super.call(this, name) || this;
  5936. _this.name = name;
  5937. _this._lineWidth = 1;
  5938. /** Function called when a point is updated */
  5939. _this.onPointUpdate = function () {
  5940. _this._markAsDirty();
  5941. };
  5942. _this.isHitTestVisible = false;
  5943. _this._horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5944. _this._verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  5945. _this._dash = [];
  5946. _this._points = [];
  5947. return _this;
  5948. }
  5949. Object.defineProperty(MultiLine.prototype, "dash", {
  5950. /** Gets or sets dash pattern */
  5951. get: function () {
  5952. return this._dash;
  5953. },
  5954. set: function (value) {
  5955. if (this._dash === value) {
  5956. return;
  5957. }
  5958. this._dash = value;
  5959. this._markAsDirty();
  5960. },
  5961. enumerable: true,
  5962. configurable: true
  5963. });
  5964. /**
  5965. * Gets point stored at specified index
  5966. * @param index defines the index to look for
  5967. * @returns the requested point if found
  5968. */
  5969. MultiLine.prototype.getAt = function (index) {
  5970. if (!this._points[index]) {
  5971. this._points[index] = new multiLinePoint_1.MultiLinePoint(this);
  5972. }
  5973. return this._points[index];
  5974. };
  5975. /**
  5976. * Adds new points to the point collection
  5977. * @param items defines the list of items (mesh, control or 2d coordiantes) to add
  5978. * @returns the list of created MultiLinePoint
  5979. */
  5980. MultiLine.prototype.add = function () {
  5981. var _this = this;
  5982. var items = [];
  5983. for (var _i = 0; _i < arguments.length; _i++) {
  5984. items[_i] = arguments[_i];
  5985. }
  5986. return items.map(function (item) { return _this.push(item); });
  5987. };
  5988. /**
  5989. * Adds a new point to the point collection
  5990. * @param item defines the item (mesh, control or 2d coordiantes) to add
  5991. * @returns the created MultiLinePoint
  5992. */
  5993. MultiLine.prototype.push = function (item) {
  5994. var point = this.getAt(this._points.length);
  5995. if (item == null) {
  5996. return point;
  5997. }
  5998. if (item instanceof babylonjs_1.AbstractMesh) {
  5999. point.mesh = item;
  6000. }
  6001. else if (item instanceof control_1.Control) {
  6002. point.control = item;
  6003. }
  6004. else if (item.x != null && item.y != null) {
  6005. point.x = item.x;
  6006. point.y = item.y;
  6007. }
  6008. return point;
  6009. };
  6010. /**
  6011. * Remove a specific value or point from the active point collection
  6012. * @param value defines the value or point to remove
  6013. */
  6014. MultiLine.prototype.remove = function (value) {
  6015. var index;
  6016. if (value instanceof multiLinePoint_1.MultiLinePoint) {
  6017. index = this._points.indexOf(value);
  6018. if (index === -1) {
  6019. return;
  6020. }
  6021. }
  6022. else {
  6023. index = value;
  6024. }
  6025. var point = this._points[index];
  6026. if (!point) {
  6027. return;
  6028. }
  6029. point.dispose();
  6030. this._points.splice(index, 1);
  6031. };
  6032. /**
  6033. * Resets this object to initial state (no point)
  6034. */
  6035. MultiLine.prototype.reset = function () {
  6036. while (this._points.length > 0) {
  6037. this.remove(this._points.length - 1);
  6038. }
  6039. };
  6040. /**
  6041. * Resets all links
  6042. */
  6043. MultiLine.prototype.resetLinks = function () {
  6044. this._points.forEach(function (point) {
  6045. if (point != null) {
  6046. point.resetLinks();
  6047. }
  6048. });
  6049. };
  6050. Object.defineProperty(MultiLine.prototype, "lineWidth", {
  6051. /** Gets or sets line width */
  6052. get: function () {
  6053. return this._lineWidth;
  6054. },
  6055. set: function (value) {
  6056. if (this._lineWidth === value) {
  6057. return;
  6058. }
  6059. this._lineWidth = value;
  6060. this._markAsDirty();
  6061. },
  6062. enumerable: true,
  6063. configurable: true
  6064. });
  6065. Object.defineProperty(MultiLine.prototype, "horizontalAlignment", {
  6066. set: function (value) {
  6067. return;
  6068. },
  6069. enumerable: true,
  6070. configurable: true
  6071. });
  6072. Object.defineProperty(MultiLine.prototype, "verticalAlignment", {
  6073. set: function (value) {
  6074. return;
  6075. },
  6076. enumerable: true,
  6077. configurable: true
  6078. });
  6079. MultiLine.prototype._getTypeName = function () {
  6080. return "MultiLine";
  6081. };
  6082. MultiLine.prototype._draw = function (parentMeasure, context) {
  6083. context.save();
  6084. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6085. context.shadowColor = this.shadowColor;
  6086. context.shadowBlur = this.shadowBlur;
  6087. context.shadowOffsetX = this.shadowOffsetX;
  6088. context.shadowOffsetY = this.shadowOffsetY;
  6089. }
  6090. this._applyStates(context);
  6091. if (this._processMeasures(parentMeasure, context)) {
  6092. context.strokeStyle = this.color;
  6093. context.lineWidth = this._lineWidth;
  6094. context.setLineDash(this._dash);
  6095. context.beginPath();
  6096. var first = true; //first index is not necessarily 0
  6097. this._points.forEach(function (point) {
  6098. if (!point) {
  6099. return;
  6100. }
  6101. if (first) {
  6102. context.moveTo(point._point.x, point._point.y);
  6103. first = false;
  6104. }
  6105. else {
  6106. context.lineTo(point._point.x, point._point.y);
  6107. }
  6108. });
  6109. context.stroke();
  6110. }
  6111. context.restore();
  6112. };
  6113. MultiLine.prototype._additionalProcessing = function (parentMeasure, context) {
  6114. var _this = this;
  6115. this._minX = null;
  6116. this._minY = null;
  6117. this._maxX = null;
  6118. this._maxY = null;
  6119. this._points.forEach(function (point, index) {
  6120. if (!point) {
  6121. return;
  6122. }
  6123. point.translate();
  6124. if (_this._minX == null || point._point.x < _this._minX) {
  6125. _this._minX = point._point.x;
  6126. }
  6127. if (_this._minY == null || point._point.y < _this._minY) {
  6128. _this._minY = point._point.y;
  6129. }
  6130. if (_this._maxX == null || point._point.x > _this._maxX) {
  6131. _this._maxX = point._point.x;
  6132. }
  6133. if (_this._maxY == null || point._point.y > _this._maxY) {
  6134. _this._maxY = point._point.y;
  6135. }
  6136. });
  6137. if (this._minX == null) {
  6138. this._minX = 0;
  6139. }
  6140. if (this._minY == null) {
  6141. this._minY = 0;
  6142. }
  6143. if (this._maxX == null) {
  6144. this._maxX = 0;
  6145. }
  6146. if (this._maxY == null) {
  6147. this._maxY = 0;
  6148. }
  6149. };
  6150. MultiLine.prototype._measure = function () {
  6151. if (this._minX == null || this._maxX == null || this._minY == null || this._maxY == null) {
  6152. return;
  6153. }
  6154. this._currentMeasure.width = Math.abs(this._maxX - this._minX) + this._lineWidth;
  6155. this._currentMeasure.height = Math.abs(this._maxY - this._minY) + this._lineWidth;
  6156. };
  6157. MultiLine.prototype._computeAlignment = function (parentMeasure, context) {
  6158. if (this._minX == null || this._minY == null) {
  6159. return;
  6160. }
  6161. this._currentMeasure.left = this._minX - this._lineWidth / 2;
  6162. this._currentMeasure.top = this._minY - this._lineWidth / 2;
  6163. };
  6164. MultiLine.prototype.dispose = function () {
  6165. this.reset();
  6166. _super.prototype.dispose.call(this);
  6167. };
  6168. return MultiLine;
  6169. }(control_1.Control));
  6170. exports.MultiLine = MultiLine;
  6171. /***/ }),
  6172. /***/ "./src/2D/controls/radioButton.ts":
  6173. /*!****************************************!*\
  6174. !*** ./src/2D/controls/radioButton.ts ***!
  6175. \****************************************/
  6176. /*! no static exports found */
  6177. /***/ (function(module, exports, __webpack_require__) {
  6178. "use strict";
  6179. var __extends = (this && this.__extends) || (function () {
  6180. var extendStatics = function (d, b) {
  6181. extendStatics = Object.setPrototypeOf ||
  6182. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6183. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6184. return extendStatics(d, b);
  6185. }
  6186. return function (d, b) {
  6187. extendStatics(d, b);
  6188. function __() { this.constructor = d; }
  6189. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6190. };
  6191. })();
  6192. Object.defineProperty(exports, "__esModule", { value: true });
  6193. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  6194. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  6195. var _1 = __webpack_require__(/*! . */ "./src/2D/controls/index.ts");
  6196. /**
  6197. * Class used to create radio button controls
  6198. */
  6199. var RadioButton = /** @class */ (function (_super) {
  6200. __extends(RadioButton, _super);
  6201. /**
  6202. * Creates a new RadioButton
  6203. * @param name defines the control name
  6204. */
  6205. function RadioButton(name) {
  6206. var _this = _super.call(this, name) || this;
  6207. _this.name = name;
  6208. _this._isChecked = false;
  6209. _this._background = "black";
  6210. _this._checkSizeRatio = 0.8;
  6211. _this._thickness = 1;
  6212. /** Gets or sets group name */
  6213. _this.group = "";
  6214. /** Observable raised when isChecked is changed */
  6215. _this.onIsCheckedChangedObservable = new babylonjs_1.Observable();
  6216. _this.isPointerBlocker = true;
  6217. return _this;
  6218. }
  6219. Object.defineProperty(RadioButton.prototype, "thickness", {
  6220. /** Gets or sets border thickness */
  6221. get: function () {
  6222. return this._thickness;
  6223. },
  6224. set: function (value) {
  6225. if (this._thickness === value) {
  6226. return;
  6227. }
  6228. this._thickness = value;
  6229. this._markAsDirty();
  6230. },
  6231. enumerable: true,
  6232. configurable: true
  6233. });
  6234. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  6235. /** Gets or sets a value indicating the ratio between overall size and check size */
  6236. get: function () {
  6237. return this._checkSizeRatio;
  6238. },
  6239. set: function (value) {
  6240. value = Math.max(Math.min(1, value), 0);
  6241. if (this._checkSizeRatio === value) {
  6242. return;
  6243. }
  6244. this._checkSizeRatio = value;
  6245. this._markAsDirty();
  6246. },
  6247. enumerable: true,
  6248. configurable: true
  6249. });
  6250. Object.defineProperty(RadioButton.prototype, "background", {
  6251. /** Gets or sets background color */
  6252. get: function () {
  6253. return this._background;
  6254. },
  6255. set: function (value) {
  6256. if (this._background === value) {
  6257. return;
  6258. }
  6259. this._background = value;
  6260. this._markAsDirty();
  6261. },
  6262. enumerable: true,
  6263. configurable: true
  6264. });
  6265. Object.defineProperty(RadioButton.prototype, "isChecked", {
  6266. /** Gets or sets a boolean indicating if the checkbox is checked or not */
  6267. get: function () {
  6268. return this._isChecked;
  6269. },
  6270. set: function (value) {
  6271. var _this = this;
  6272. if (this._isChecked === value) {
  6273. return;
  6274. }
  6275. this._isChecked = value;
  6276. this._markAsDirty();
  6277. this.onIsCheckedChangedObservable.notifyObservers(value);
  6278. if (this._isChecked && this._host) {
  6279. // Update all controls from same group
  6280. this._host.executeOnAllControls(function (control) {
  6281. if (control === _this) {
  6282. return;
  6283. }
  6284. if (control.group === undefined) {
  6285. return;
  6286. }
  6287. var childRadio = control;
  6288. if (childRadio.group === _this.group) {
  6289. childRadio.isChecked = false;
  6290. }
  6291. });
  6292. }
  6293. },
  6294. enumerable: true,
  6295. configurable: true
  6296. });
  6297. RadioButton.prototype._getTypeName = function () {
  6298. return "RadioButton";
  6299. };
  6300. RadioButton.prototype._draw = function (parentMeasure, context) {
  6301. context.save();
  6302. this._applyStates(context);
  6303. if (this._processMeasures(parentMeasure, context)) {
  6304. var actualWidth = this._currentMeasure.width - this._thickness;
  6305. var actualHeight = this._currentMeasure.height - this._thickness;
  6306. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6307. context.shadowColor = this.shadowColor;
  6308. context.shadowBlur = this.shadowBlur;
  6309. context.shadowOffsetX = this.shadowOffsetX;
  6310. context.shadowOffsetY = this.shadowOffsetY;
  6311. }
  6312. // Outer
  6313. control_1.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2 - this._thickness / 2, this._currentMeasure.height / 2 - this._thickness / 2, context);
  6314. context.fillStyle = this._isEnabled ? this._background : this._disabledColor;
  6315. context.fill();
  6316. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6317. context.shadowBlur = 0;
  6318. context.shadowOffsetX = 0;
  6319. context.shadowOffsetY = 0;
  6320. }
  6321. context.strokeStyle = this.color;
  6322. context.lineWidth = this._thickness;
  6323. context.stroke();
  6324. // Inner
  6325. if (this._isChecked) {
  6326. context.fillStyle = this._isEnabled ? this.color : this._disabledColor;
  6327. var offsetWidth = actualWidth * this._checkSizeRatio;
  6328. var offseHeight = actualHeight * this._checkSizeRatio;
  6329. control_1.Control.drawEllipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, offsetWidth / 2 - this._thickness / 2, offseHeight / 2 - this._thickness / 2, context);
  6330. context.fill();
  6331. }
  6332. }
  6333. context.restore();
  6334. };
  6335. // Events
  6336. RadioButton.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  6337. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  6338. return false;
  6339. }
  6340. if (!this.isChecked) {
  6341. this.isChecked = true;
  6342. }
  6343. return true;
  6344. };
  6345. /**
  6346. * Utility function to easily create a radio button with a header
  6347. * @param title defines the label to use for the header
  6348. * @param group defines the group to use for the radio button
  6349. * @param isChecked defines the initial state of the radio button
  6350. * @param onValueChanged defines the callback to call when value changes
  6351. * @returns a StackPanel containing the radio button and a textBlock
  6352. */
  6353. RadioButton.AddRadioButtonWithHeader = function (title, group, isChecked, onValueChanged) {
  6354. var panel = new _1.StackPanel();
  6355. panel.isVertical = false;
  6356. panel.height = "30px";
  6357. var radio = new RadioButton();
  6358. radio.width = "20px";
  6359. radio.height = "20px";
  6360. radio.isChecked = isChecked;
  6361. radio.color = "green";
  6362. radio.group = group;
  6363. radio.onIsCheckedChangedObservable.add(function (value) { return onValueChanged(radio, value); });
  6364. panel.addControl(radio);
  6365. var header = new _1.TextBlock();
  6366. header.text = title;
  6367. header.width = "180px";
  6368. header.paddingLeft = "5px";
  6369. header.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6370. header.color = "white";
  6371. panel.addControl(header);
  6372. return panel;
  6373. };
  6374. return RadioButton;
  6375. }(control_1.Control));
  6376. exports.RadioButton = RadioButton;
  6377. /***/ }),
  6378. /***/ "./src/2D/controls/rectangle.ts":
  6379. /*!**************************************!*\
  6380. !*** ./src/2D/controls/rectangle.ts ***!
  6381. \**************************************/
  6382. /*! no static exports found */
  6383. /***/ (function(module, exports, __webpack_require__) {
  6384. "use strict";
  6385. var __extends = (this && this.__extends) || (function () {
  6386. var extendStatics = function (d, b) {
  6387. extendStatics = Object.setPrototypeOf ||
  6388. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6389. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6390. return extendStatics(d, b);
  6391. }
  6392. return function (d, b) {
  6393. extendStatics(d, b);
  6394. function __() { this.constructor = d; }
  6395. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6396. };
  6397. })();
  6398. Object.defineProperty(exports, "__esModule", { value: true });
  6399. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  6400. /** Class used to create rectangle container */
  6401. var Rectangle = /** @class */ (function (_super) {
  6402. __extends(Rectangle, _super);
  6403. /**
  6404. * Creates a new Rectangle
  6405. * @param name defines the control name
  6406. */
  6407. function Rectangle(name) {
  6408. var _this = _super.call(this, name) || this;
  6409. _this.name = name;
  6410. _this._thickness = 1;
  6411. _this._cornerRadius = 0;
  6412. return _this;
  6413. }
  6414. Object.defineProperty(Rectangle.prototype, "thickness", {
  6415. /** Gets or sets border thickness */
  6416. get: function () {
  6417. return this._thickness;
  6418. },
  6419. set: function (value) {
  6420. if (this._thickness === value) {
  6421. return;
  6422. }
  6423. this._thickness = value;
  6424. this._markAsDirty();
  6425. },
  6426. enumerable: true,
  6427. configurable: true
  6428. });
  6429. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  6430. /** Gets or sets the corner radius angle */
  6431. get: function () {
  6432. return this._cornerRadius;
  6433. },
  6434. set: function (value) {
  6435. if (value < 0) {
  6436. value = 0;
  6437. }
  6438. if (this._cornerRadius === value) {
  6439. return;
  6440. }
  6441. this._cornerRadius = value;
  6442. this._markAsDirty();
  6443. },
  6444. enumerable: true,
  6445. configurable: true
  6446. });
  6447. Rectangle.prototype._getTypeName = function () {
  6448. return "Rectangle";
  6449. };
  6450. Rectangle.prototype._localDraw = function (context) {
  6451. context.save();
  6452. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6453. context.shadowColor = this.shadowColor;
  6454. context.shadowBlur = this.shadowBlur;
  6455. context.shadowOffsetX = this.shadowOffsetX;
  6456. context.shadowOffsetY = this.shadowOffsetY;
  6457. }
  6458. if (this._background) {
  6459. context.fillStyle = this._background;
  6460. if (this._cornerRadius) {
  6461. this._drawRoundedRect(context, this._thickness / 2);
  6462. context.fill();
  6463. }
  6464. else {
  6465. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  6466. }
  6467. }
  6468. if (this._thickness) {
  6469. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6470. context.shadowBlur = 0;
  6471. context.shadowOffsetX = 0;
  6472. context.shadowOffsetY = 0;
  6473. }
  6474. if (this.color) {
  6475. context.strokeStyle = this.color;
  6476. }
  6477. context.lineWidth = this._thickness;
  6478. if (this._cornerRadius) {
  6479. this._drawRoundedRect(context, this._thickness / 2);
  6480. context.stroke();
  6481. }
  6482. else {
  6483. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  6484. }
  6485. }
  6486. context.restore();
  6487. };
  6488. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  6489. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  6490. this._measureForChildren.width -= 2 * this._thickness;
  6491. this._measureForChildren.height -= 2 * this._thickness;
  6492. this._measureForChildren.left += this._thickness;
  6493. this._measureForChildren.top += this._thickness;
  6494. };
  6495. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  6496. if (offset === void 0) { offset = 0; }
  6497. var x = this._currentMeasure.left + offset;
  6498. var y = this._currentMeasure.top + offset;
  6499. var width = this._currentMeasure.width - offset * 2;
  6500. var height = this._currentMeasure.height - offset * 2;
  6501. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  6502. context.beginPath();
  6503. context.moveTo(x + radius, y);
  6504. context.lineTo(x + width - radius, y);
  6505. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  6506. context.lineTo(x + width, y + height - radius);
  6507. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  6508. context.lineTo(x + radius, y + height);
  6509. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  6510. context.lineTo(x, y + radius);
  6511. context.quadraticCurveTo(x, y, x + radius, y);
  6512. context.closePath();
  6513. };
  6514. Rectangle.prototype._clipForChildren = function (context) {
  6515. if (this._cornerRadius) {
  6516. this._drawRoundedRect(context, this._thickness);
  6517. context.clip();
  6518. }
  6519. };
  6520. return Rectangle;
  6521. }(container_1.Container));
  6522. exports.Rectangle = Rectangle;
  6523. /***/ }),
  6524. /***/ "./src/2D/controls/selector.ts":
  6525. /*!*************************************!*\
  6526. !*** ./src/2D/controls/selector.ts ***!
  6527. \*************************************/
  6528. /*! no static exports found */
  6529. /***/ (function(module, exports, __webpack_require__) {
  6530. "use strict";
  6531. var __extends = (this && this.__extends) || (function () {
  6532. var extendStatics = function (d, b) {
  6533. extendStatics = Object.setPrototypeOf ||
  6534. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6535. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6536. return extendStatics(d, b);
  6537. }
  6538. return function (d, b) {
  6539. extendStatics(d, b);
  6540. function __() { this.constructor = d; }
  6541. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6542. };
  6543. })();
  6544. Object.defineProperty(exports, "__esModule", { value: true });
  6545. var rectangle_1 = __webpack_require__(/*! ./rectangle */ "./src/2D/controls/rectangle.ts");
  6546. var stackPanel_1 = __webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts");
  6547. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  6548. var textBlock_1 = __webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts");
  6549. var checkbox_1 = __webpack_require__(/*! ./checkbox */ "./src/2D/controls/checkbox.ts");
  6550. var radioButton_1 = __webpack_require__(/*! ./radioButton */ "./src/2D/controls/radioButton.ts");
  6551. var slider_1 = __webpack_require__(/*! ./slider */ "./src/2D/controls/slider.ts");
  6552. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  6553. /** Class used to create a RadioGroup
  6554. * which contains groups of radio buttons
  6555. */
  6556. var SelectorGroup = /** @class */ (function () {
  6557. /**
  6558. * Creates a new SelectorGroup
  6559. * @param name of group, used as a group heading
  6560. */
  6561. function SelectorGroup(
  6562. /** name of SelectorGroup */
  6563. name) {
  6564. this.name = name;
  6565. this._groupPanel = new stackPanel_1.StackPanel();
  6566. this._selectors = new Array();
  6567. this._groupPanel.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  6568. this._groupPanel.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6569. this._groupHeader = this._addGroupHeader(name);
  6570. }
  6571. Object.defineProperty(SelectorGroup.prototype, "groupPanel", {
  6572. /** Gets the groupPanel of the SelectorGroup */
  6573. get: function () {
  6574. return this._groupPanel;
  6575. },
  6576. enumerable: true,
  6577. configurable: true
  6578. });
  6579. Object.defineProperty(SelectorGroup.prototype, "selectors", {
  6580. /** Gets the selectors array */
  6581. get: function () {
  6582. return this._selectors;
  6583. },
  6584. enumerable: true,
  6585. configurable: true
  6586. });
  6587. Object.defineProperty(SelectorGroup.prototype, "header", {
  6588. /** Gets and sets the group header */
  6589. get: function () {
  6590. return this._groupHeader.text;
  6591. },
  6592. set: function (label) {
  6593. if (this._groupHeader.text === "label") {
  6594. return;
  6595. }
  6596. this._groupHeader.text = label;
  6597. },
  6598. enumerable: true,
  6599. configurable: true
  6600. });
  6601. /** @hidden */
  6602. SelectorGroup.prototype._addGroupHeader = function (text) {
  6603. var groupHeading = new textBlock_1.TextBlock("groupHead", text);
  6604. groupHeading.width = 0.9;
  6605. groupHeading.height = "30px";
  6606. groupHeading.textWrapping = true;
  6607. groupHeading.color = "black";
  6608. groupHeading.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6609. groupHeading.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6610. groupHeading.left = "2px";
  6611. this._groupPanel.addControl(groupHeading);
  6612. return groupHeading;
  6613. };
  6614. /** @hidden*/
  6615. SelectorGroup.prototype._getSelector = function (selectorNb) {
  6616. if (selectorNb < 0 || selectorNb >= this._selectors.length) {
  6617. return;
  6618. }
  6619. return this._selectors[selectorNb];
  6620. };
  6621. /** Removes the selector at the given position
  6622. * @param selectorNb the position of the selector within the group
  6623. */
  6624. SelectorGroup.prototype.removeSelector = function (selectorNb) {
  6625. if (selectorNb < 0 || selectorNb >= this._selectors.length) {
  6626. return;
  6627. }
  6628. this._groupPanel.removeControl(this._selectors[selectorNb]);
  6629. this._selectors.splice(selectorNb, 1);
  6630. };
  6631. return SelectorGroup;
  6632. }());
  6633. exports.SelectorGroup = SelectorGroup;
  6634. /** Class used to create a CheckboxGroup
  6635. * which contains groups of checkbox buttons
  6636. */
  6637. var CheckboxGroup = /** @class */ (function (_super) {
  6638. __extends(CheckboxGroup, _super);
  6639. function CheckboxGroup() {
  6640. return _super !== null && _super.apply(this, arguments) || this;
  6641. }
  6642. /** Adds a checkbox as a control
  6643. * @param text is the label for the selector
  6644. * @param func is the function called when the Selector is checked
  6645. * @param checked is true when Selector is checked
  6646. */
  6647. CheckboxGroup.prototype.addCheckbox = function (text, func, checked) {
  6648. if (func === void 0) { func = function (s) { }; }
  6649. if (checked === void 0) { checked = false; }
  6650. var checked = checked || false;
  6651. var button = new checkbox_1.Checkbox();
  6652. button.width = "20px";
  6653. button.height = "20px";
  6654. button.color = "#364249";
  6655. button.background = "#CCCCCC";
  6656. button.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6657. button.onIsCheckedChangedObservable.add(function (state) {
  6658. func(state);
  6659. });
  6660. var _selector = control_1.Control.AddHeader(button, text, "200px", { isHorizontal: true, controlFirst: true });
  6661. _selector.height = "30px";
  6662. _selector.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6663. _selector.left = "4px";
  6664. this.groupPanel.addControl(_selector);
  6665. this.selectors.push(_selector);
  6666. button.isChecked = checked;
  6667. if (this.groupPanel.parent && this.groupPanel.parent.parent) {
  6668. button.color = this.groupPanel.parent.parent.buttonColor;
  6669. button.background = this.groupPanel.parent.parent.buttonBackground;
  6670. }
  6671. };
  6672. /** @hidden */
  6673. CheckboxGroup.prototype._setSelectorLabel = function (selectorNb, label) {
  6674. this.selectors[selectorNb].children[1].text = label;
  6675. };
  6676. /** @hidden */
  6677. CheckboxGroup.prototype._setSelectorLabelColor = function (selectorNb, color) {
  6678. this.selectors[selectorNb].children[1].color = color;
  6679. };
  6680. /** @hidden */
  6681. CheckboxGroup.prototype._setSelectorButtonColor = function (selectorNb, color) {
  6682. this.selectors[selectorNb].children[0].color = color;
  6683. };
  6684. /** @hidden */
  6685. CheckboxGroup.prototype._setSelectorButtonBackground = function (selectorNb, color) {
  6686. this.selectors[selectorNb].children[0].background = color;
  6687. };
  6688. return CheckboxGroup;
  6689. }(SelectorGroup));
  6690. exports.CheckboxGroup = CheckboxGroup;
  6691. /** Class used to create a RadioGroup
  6692. * which contains groups of radio buttons
  6693. */
  6694. var RadioGroup = /** @class */ (function (_super) {
  6695. __extends(RadioGroup, _super);
  6696. function RadioGroup() {
  6697. var _this = _super !== null && _super.apply(this, arguments) || this;
  6698. _this._selectNb = 0;
  6699. return _this;
  6700. }
  6701. /** Adds a radio button as a control
  6702. * @param label is the label for the selector
  6703. * @param func is the function called when the Selector is checked
  6704. * @param checked is true when Selector is checked
  6705. */
  6706. RadioGroup.prototype.addRadio = function (label, func, checked) {
  6707. if (func === void 0) { func = function (n) { }; }
  6708. if (checked === void 0) { checked = false; }
  6709. var nb = this._selectNb++;
  6710. var button = new radioButton_1.RadioButton();
  6711. button.name = label;
  6712. button.width = "20px";
  6713. button.height = "20px";
  6714. button.color = "#364249";
  6715. button.background = "#CCCCCC";
  6716. button.group = this.name;
  6717. button.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6718. button.onIsCheckedChangedObservable.add(function (state) {
  6719. if (state) {
  6720. func(nb);
  6721. }
  6722. });
  6723. var _selector = control_1.Control.AddHeader(button, label, "200px", { isHorizontal: true, controlFirst: true });
  6724. _selector.height = "30px";
  6725. _selector.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6726. _selector.left = "4px";
  6727. this.groupPanel.addControl(_selector);
  6728. this.selectors.push(_selector);
  6729. button.isChecked = checked;
  6730. if (this.groupPanel.parent && this.groupPanel.parent.parent) {
  6731. button.color = this.groupPanel.parent.parent.buttonColor;
  6732. button.background = this.groupPanel.parent.parent.buttonBackground;
  6733. }
  6734. };
  6735. /** @hidden */
  6736. RadioGroup.prototype._setSelectorLabel = function (selectorNb, label) {
  6737. this.selectors[selectorNb].children[1].text = label;
  6738. };
  6739. /** @hidden */
  6740. RadioGroup.prototype._setSelectorLabelColor = function (selectorNb, color) {
  6741. this.selectors[selectorNb].children[1].color = color;
  6742. };
  6743. /** @hidden */
  6744. RadioGroup.prototype._setSelectorButtonColor = function (selectorNb, color) {
  6745. this.selectors[selectorNb].children[0].color = color;
  6746. };
  6747. /** @hidden */
  6748. RadioGroup.prototype._setSelectorButtonBackground = function (selectorNb, color) {
  6749. this.selectors[selectorNb].children[0].background = color;
  6750. };
  6751. return RadioGroup;
  6752. }(SelectorGroup));
  6753. exports.RadioGroup = RadioGroup;
  6754. /** Class used to create a SliderGroup
  6755. * which contains groups of slider buttons
  6756. */
  6757. var SliderGroup = /** @class */ (function (_super) {
  6758. __extends(SliderGroup, _super);
  6759. function SliderGroup() {
  6760. return _super !== null && _super.apply(this, arguments) || this;
  6761. }
  6762. /**
  6763. * Adds a slider to the SelectorGroup
  6764. * @param label is the label for the SliderBar
  6765. * @param func is the function called when the Slider moves
  6766. * @param unit is a string describing the units used, eg degrees or metres
  6767. * @param min is the minimum value for the Slider
  6768. * @param max is the maximum value for the Slider
  6769. * @param value is the start value for the Slider between min and max
  6770. * @param onValueChange is the function used to format the value displayed, eg radians to degrees
  6771. */
  6772. SliderGroup.prototype.addSlider = function (label, func, unit, min, max, value, onValueChange) {
  6773. if (func === void 0) { func = function (v) { }; }
  6774. if (unit === void 0) { unit = "Units"; }
  6775. if (min === void 0) { min = 0; }
  6776. if (max === void 0) { max = 0; }
  6777. if (value === void 0) { value = 0; }
  6778. if (onValueChange === void 0) { onValueChange = function (v) { return v | 0; }; }
  6779. var button = new slider_1.Slider();
  6780. button.name = unit;
  6781. button.value = value;
  6782. button.minimum = min;
  6783. button.maximum = max;
  6784. button.width = 0.9;
  6785. button.height = "20px";
  6786. button.color = "#364249";
  6787. button.background = "#CCCCCC";
  6788. button.borderColor = "black";
  6789. button.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6790. button.left = "4px";
  6791. button.paddingBottom = "4px";
  6792. button.onValueChangedObservable.add(function (value) {
  6793. button.parent.children[0].text = button.parent.children[0].name + ": " + onValueChange(value) + " " + button.name;
  6794. func(value);
  6795. });
  6796. var _selector = control_1.Control.AddHeader(button, label + ": " + onValueChange(value) + " " + unit, "30px", { isHorizontal: false, controlFirst: false });
  6797. _selector.height = "60px";
  6798. _selector.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6799. _selector.left = "4px";
  6800. _selector.children[0].name = label;
  6801. this.groupPanel.addControl(_selector);
  6802. this.selectors.push(_selector);
  6803. if (this.groupPanel.parent && this.groupPanel.parent.parent) {
  6804. button.color = this.groupPanel.parent.parent.buttonColor;
  6805. button.background = this.groupPanel.parent.parent.buttonBackground;
  6806. }
  6807. };
  6808. /** @hidden */
  6809. SliderGroup.prototype._setSelectorLabel = function (selectorNb, label) {
  6810. this.selectors[selectorNb].children[0].name = label;
  6811. this.selectors[selectorNb].children[0].text = label + ": " + this.selectors[selectorNb].children[1].value + " " + this.selectors[selectorNb].children[1].name;
  6812. };
  6813. /** @hidden */
  6814. SliderGroup.prototype._setSelectorLabelColor = function (selectorNb, color) {
  6815. this.selectors[selectorNb].children[0].color = color;
  6816. };
  6817. /** @hidden */
  6818. SliderGroup.prototype._setSelectorButtonColor = function (selectorNb, color) {
  6819. this.selectors[selectorNb].children[1].color = color;
  6820. };
  6821. /** @hidden */
  6822. SliderGroup.prototype._setSelectorButtonBackground = function (selectorNb, color) {
  6823. this.selectors[selectorNb].children[1].background = color;
  6824. };
  6825. return SliderGroup;
  6826. }(SelectorGroup));
  6827. exports.SliderGroup = SliderGroup;
  6828. /** Class used to hold the controls for the checkboxes, radio buttons and sliders
  6829. * @see http://doc.babylonjs.com/how_to/selector
  6830. */
  6831. var SelectionPanel = /** @class */ (function (_super) {
  6832. __extends(SelectionPanel, _super);
  6833. /**
  6834. * Creates a new SelectionPanel
  6835. * @param name of SelectionPanel
  6836. * @param groups is an array of SelectionGroups
  6837. */
  6838. function SelectionPanel(
  6839. /** name of SelectionPanel */
  6840. name,
  6841. /** an array of SelectionGroups */
  6842. groups) {
  6843. if (groups === void 0) { groups = []; }
  6844. var _this = _super.call(this, name) || this;
  6845. _this.name = name;
  6846. _this.groups = groups;
  6847. _this._buttonColor = "#364249";
  6848. _this._buttonBackground = "#CCCCCC";
  6849. _this._headerColor = "black";
  6850. _this._barColor = "white";
  6851. _this._barHeight = "2px";
  6852. _this._spacerHeight = "20px";
  6853. _this._bars = new Array();
  6854. _this._groups = groups;
  6855. _this.thickness = 2;
  6856. _this._panel = new stackPanel_1.StackPanel();
  6857. _this._panel.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  6858. _this._panel.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6859. _this._panel.top = 5;
  6860. _this._panel.left = 5;
  6861. _this._panel.width = 0.95;
  6862. if (groups.length > 0) {
  6863. for (var i = 0; i < groups.length - 1; i++) {
  6864. _this._panel.addControl(groups[i].groupPanel);
  6865. _this._addSpacer();
  6866. }
  6867. _this._panel.addControl(groups[groups.length - 1].groupPanel);
  6868. }
  6869. _this.addControl(_this._panel);
  6870. return _this;
  6871. }
  6872. SelectionPanel.prototype._getTypeName = function () {
  6873. return "SelectionPanel";
  6874. };
  6875. Object.defineProperty(SelectionPanel.prototype, "headerColor", {
  6876. /** Gets or sets the headerColor */
  6877. get: function () {
  6878. return this._headerColor;
  6879. },
  6880. set: function (color) {
  6881. if (this._headerColor === color) {
  6882. return;
  6883. }
  6884. this._headerColor = color;
  6885. this._setHeaderColor();
  6886. },
  6887. enumerable: true,
  6888. configurable: true
  6889. });
  6890. SelectionPanel.prototype._setHeaderColor = function () {
  6891. for (var i = 0; i < this._groups.length; i++) {
  6892. this._groups[i].groupPanel.children[0].color = this._headerColor;
  6893. }
  6894. };
  6895. Object.defineProperty(SelectionPanel.prototype, "buttonColor", {
  6896. /** Gets or sets the button color */
  6897. get: function () {
  6898. return this._buttonColor;
  6899. },
  6900. set: function (color) {
  6901. if (this._buttonColor === color) {
  6902. return;
  6903. }
  6904. this._buttonColor = color;
  6905. this._setbuttonColor();
  6906. },
  6907. enumerable: true,
  6908. configurable: true
  6909. });
  6910. SelectionPanel.prototype._setbuttonColor = function () {
  6911. for (var i = 0; i < this._groups.length; i++) {
  6912. for (var j = 0; j < this._groups[i].selectors.length; j++) {
  6913. this._groups[i]._setSelectorButtonColor(j, this._buttonColor);
  6914. }
  6915. }
  6916. };
  6917. Object.defineProperty(SelectionPanel.prototype, "labelColor", {
  6918. /** Gets or sets the label color */
  6919. get: function () {
  6920. return this._labelColor;
  6921. },
  6922. set: function (color) {
  6923. if (this._labelColor === color) {
  6924. return;
  6925. }
  6926. this._labelColor = color;
  6927. this._setLabelColor();
  6928. },
  6929. enumerable: true,
  6930. configurable: true
  6931. });
  6932. SelectionPanel.prototype._setLabelColor = function () {
  6933. for (var i = 0; i < this._groups.length; i++) {
  6934. for (var j = 0; j < this._groups[i].selectors.length; j++) {
  6935. this._groups[i]._setSelectorLabelColor(j, this._labelColor);
  6936. }
  6937. }
  6938. };
  6939. Object.defineProperty(SelectionPanel.prototype, "buttonBackground", {
  6940. /** Gets or sets the button background */
  6941. get: function () {
  6942. return this._buttonBackground;
  6943. },
  6944. set: function (color) {
  6945. if (this._buttonBackground === color) {
  6946. return;
  6947. }
  6948. this._buttonBackground = color;
  6949. this._setButtonBackground();
  6950. },
  6951. enumerable: true,
  6952. configurable: true
  6953. });
  6954. SelectionPanel.prototype._setButtonBackground = function () {
  6955. for (var i = 0; i < this._groups.length; i++) {
  6956. for (var j = 0; j < this._groups[i].selectors.length; j++) {
  6957. this._groups[i]._setSelectorButtonBackground(j, this._buttonBackground);
  6958. }
  6959. }
  6960. };
  6961. Object.defineProperty(SelectionPanel.prototype, "barColor", {
  6962. /** Gets or sets the color of separator bar */
  6963. get: function () {
  6964. return this._barColor;
  6965. },
  6966. set: function (color) {
  6967. if (this._barColor === color) {
  6968. return;
  6969. }
  6970. this._barColor = color;
  6971. this._setBarColor();
  6972. },
  6973. enumerable: true,
  6974. configurable: true
  6975. });
  6976. SelectionPanel.prototype._setBarColor = function () {
  6977. for (var i = 0; i < this._bars.length; i++) {
  6978. this._bars[i].children[0].background = this._barColor;
  6979. }
  6980. };
  6981. Object.defineProperty(SelectionPanel.prototype, "barHeight", {
  6982. /** Gets or sets the height of separator bar */
  6983. get: function () {
  6984. return this._barHeight;
  6985. },
  6986. set: function (value) {
  6987. if (this._barHeight === value) {
  6988. return;
  6989. }
  6990. this._barHeight = value;
  6991. this._setBarHeight();
  6992. },
  6993. enumerable: true,
  6994. configurable: true
  6995. });
  6996. SelectionPanel.prototype._setBarHeight = function () {
  6997. for (var i = 0; i < this._bars.length; i++) {
  6998. this._bars[i].children[0].height = this._barHeight;
  6999. }
  7000. };
  7001. Object.defineProperty(SelectionPanel.prototype, "spacerHeight", {
  7002. /** Gets or sets the height of spacers*/
  7003. get: function () {
  7004. return this._spacerHeight;
  7005. },
  7006. set: function (value) {
  7007. if (this._spacerHeight === value) {
  7008. return;
  7009. }
  7010. this._spacerHeight = value;
  7011. this._setSpacerHeight();
  7012. },
  7013. enumerable: true,
  7014. configurable: true
  7015. });
  7016. SelectionPanel.prototype._setSpacerHeight = function () {
  7017. for (var i = 0; i < this._bars.length; i++) {
  7018. this._bars[i].height = this._spacerHeight;
  7019. }
  7020. };
  7021. /** Adds a bar between groups */
  7022. SelectionPanel.prototype._addSpacer = function () {
  7023. var separator = new container_1.Container();
  7024. separator.width = 1;
  7025. separator.height = this._spacerHeight;
  7026. separator.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  7027. var bar = new rectangle_1.Rectangle();
  7028. bar.width = 1;
  7029. bar.height = this._barHeight;
  7030. bar.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  7031. bar.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_CENTER;
  7032. bar.background = this._barColor;
  7033. bar.color = "transparent";
  7034. separator.addControl(bar);
  7035. this._panel.addControl(separator);
  7036. this._bars.push(separator);
  7037. };
  7038. /** Add a group to the selection panel
  7039. * @param group is the selector group to add
  7040. */
  7041. SelectionPanel.prototype.addGroup = function (group) {
  7042. if (this._groups.length > 0) {
  7043. this._addSpacer();
  7044. }
  7045. this._panel.addControl(group.groupPanel);
  7046. this._groups.push(group);
  7047. group.groupPanel.children[0].color = this._headerColor;
  7048. for (var j = 0; j < group.selectors.length; j++) {
  7049. group._setSelectorButtonColor(j, this._buttonColor);
  7050. group._setSelectorButtonBackground(j, this._buttonBackground);
  7051. }
  7052. };
  7053. /** Remove the group from the given position
  7054. * @param groupNb is the position of the group in the list
  7055. */
  7056. SelectionPanel.prototype.removeGroup = function (groupNb) {
  7057. if (groupNb < 0 || groupNb >= this._groups.length) {
  7058. return;
  7059. }
  7060. var group = this._groups[groupNb];
  7061. this._panel.removeControl(group.groupPanel);
  7062. this._groups.splice(groupNb, 1);
  7063. if (groupNb < this._bars.length) {
  7064. this._panel.removeControl(this._bars[groupNb]);
  7065. this._bars.splice(groupNb, 1);
  7066. }
  7067. };
  7068. /** Change a group header label
  7069. * @param label is the new group header label
  7070. * @param groupNb is the number of the group to relabel
  7071. * */
  7072. SelectionPanel.prototype.setHeaderName = function (label, groupNb) {
  7073. if (groupNb < 0 || groupNb >= this._groups.length) {
  7074. return;
  7075. }
  7076. var group = this._groups[groupNb];
  7077. group.groupPanel.children[0].text = label;
  7078. };
  7079. /** Change selector label to the one given
  7080. * @param label is the new selector label
  7081. * @param groupNb is the number of the groupcontaining the selector
  7082. * @param selectorNb is the number of the selector within a group to relabel
  7083. * */
  7084. SelectionPanel.prototype.relabel = function (label, groupNb, selectorNb) {
  7085. if (groupNb < 0 || groupNb >= this._groups.length) {
  7086. return;
  7087. }
  7088. var group = this._groups[groupNb];
  7089. if (selectorNb < 0 || selectorNb >= group.selectors.length) {
  7090. return;
  7091. }
  7092. group._setSelectorLabel(selectorNb, label);
  7093. };
  7094. /** For a given group position remove the selector at the given position
  7095. * @param groupNb is the number of the group to remove the selector from
  7096. * @param selectorNb is the number of the selector within the group
  7097. */
  7098. SelectionPanel.prototype.removeFromGroupSelector = function (groupNb, selectorNb) {
  7099. if (groupNb < 0 || groupNb >= this._groups.length) {
  7100. return;
  7101. }
  7102. var group = this._groups[groupNb];
  7103. if (selectorNb < 0 || selectorNb >= group.selectors.length) {
  7104. return;
  7105. }
  7106. group.removeSelector(selectorNb);
  7107. };
  7108. /** For a given group position of correct type add a checkbox button
  7109. * @param groupNb is the number of the group to remove the selector from
  7110. * @param label is the label for the selector
  7111. * @param func is the function called when the Selector is checked
  7112. * @param checked is true when Selector is checked
  7113. */
  7114. SelectionPanel.prototype.addToGroupCheckbox = function (groupNb, label, func, checked) {
  7115. if (func === void 0) { func = function () { }; }
  7116. if (checked === void 0) { checked = false; }
  7117. if (groupNb < 0 || groupNb >= this._groups.length) {
  7118. return;
  7119. }
  7120. var group = this._groups[groupNb];
  7121. group.addCheckbox(label, func, checked);
  7122. };
  7123. /** For a given group position of correct type add a radio button
  7124. * @param groupNb is the number of the group to remove the selector from
  7125. * @param label is the label for the selector
  7126. * @param func is the function called when the Selector is checked
  7127. * @param checked is true when Selector is checked
  7128. */
  7129. SelectionPanel.prototype.addToGroupRadio = function (groupNb, label, func, checked) {
  7130. if (func === void 0) { func = function () { }; }
  7131. if (checked === void 0) { checked = false; }
  7132. if (groupNb < 0 || groupNb >= this._groups.length) {
  7133. return;
  7134. }
  7135. var group = this._groups[groupNb];
  7136. group.addRadio(label, func, checked);
  7137. };
  7138. /**
  7139. * For a given slider group add a slider
  7140. * @param groupNb is the number of the group to add the slider to
  7141. * @param label is the label for the Slider
  7142. * @param func is the function called when the Slider moves
  7143. * @param unit is a string describing the units used, eg degrees or metres
  7144. * @param min is the minimum value for the Slider
  7145. * @param max is the maximum value for the Slider
  7146. * @param value is the start value for the Slider between min and max
  7147. * @param onVal is the function used to format the value displayed, eg radians to degrees
  7148. */
  7149. SelectionPanel.prototype.addToGroupSlider = function (groupNb, label, func, unit, min, max, value, onVal) {
  7150. if (func === void 0) { func = function () { }; }
  7151. if (unit === void 0) { unit = "Units"; }
  7152. if (min === void 0) { min = 0; }
  7153. if (max === void 0) { max = 0; }
  7154. if (value === void 0) { value = 0; }
  7155. if (onVal === void 0) { onVal = function (v) { return v | 0; }; }
  7156. if (groupNb < 0 || groupNb >= this._groups.length) {
  7157. return;
  7158. }
  7159. var group = this._groups[groupNb];
  7160. group.addSlider(label, func, unit, min, max, value, onVal);
  7161. };
  7162. return SelectionPanel;
  7163. }(rectangle_1.Rectangle));
  7164. exports.SelectionPanel = SelectionPanel;
  7165. /***/ }),
  7166. /***/ "./src/2D/controls/slider.ts":
  7167. /*!***********************************!*\
  7168. !*** ./src/2D/controls/slider.ts ***!
  7169. \***********************************/
  7170. /*! no static exports found */
  7171. /***/ (function(module, exports, __webpack_require__) {
  7172. "use strict";
  7173. var __extends = (this && this.__extends) || (function () {
  7174. var extendStatics = function (d, b) {
  7175. extendStatics = Object.setPrototypeOf ||
  7176. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  7177. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7178. return extendStatics(d, b);
  7179. }
  7180. return function (d, b) {
  7181. extendStatics(d, b);
  7182. function __() { this.constructor = d; }
  7183. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7184. };
  7185. })();
  7186. Object.defineProperty(exports, "__esModule", { value: true });
  7187. var baseSlider_1 = __webpack_require__(/*! ./baseSlider */ "./src/2D/controls/baseSlider.ts");
  7188. /**
  7189. * Class used to create slider controls
  7190. */
  7191. var Slider = /** @class */ (function (_super) {
  7192. __extends(Slider, _super);
  7193. /**
  7194. * Creates a new Slider
  7195. * @param name defines the control name
  7196. */
  7197. function Slider(name) {
  7198. var _this = _super.call(this, name) || this;
  7199. _this.name = name;
  7200. _this._background = "black";
  7201. _this._borderColor = "white";
  7202. _this._isThumbCircle = false;
  7203. return _this;
  7204. }
  7205. Object.defineProperty(Slider.prototype, "borderColor", {
  7206. /** Gets or sets border color */
  7207. get: function () {
  7208. return this._borderColor;
  7209. },
  7210. set: function (value) {
  7211. if (this._borderColor === value) {
  7212. return;
  7213. }
  7214. this._borderColor = value;
  7215. this._markAsDirty();
  7216. },
  7217. enumerable: true,
  7218. configurable: true
  7219. });
  7220. Object.defineProperty(Slider.prototype, "background", {
  7221. /** Gets or sets background color */
  7222. get: function () {
  7223. return this._background;
  7224. },
  7225. set: function (value) {
  7226. if (this._background === value) {
  7227. return;
  7228. }
  7229. this._background = value;
  7230. this._markAsDirty();
  7231. },
  7232. enumerable: true,
  7233. configurable: true
  7234. });
  7235. Object.defineProperty(Slider.prototype, "isThumbCircle", {
  7236. /** Gets or sets a boolean indicating if the thumb should be round or square */
  7237. get: function () {
  7238. return this._isThumbCircle;
  7239. },
  7240. set: function (value) {
  7241. if (this._isThumbCircle === value) {
  7242. return;
  7243. }
  7244. this._isThumbCircle = value;
  7245. this._markAsDirty();
  7246. },
  7247. enumerable: true,
  7248. configurable: true
  7249. });
  7250. Slider.prototype._getTypeName = function () {
  7251. return "Slider";
  7252. };
  7253. Slider.prototype._draw = function (parentMeasure, context) {
  7254. context.save();
  7255. this._applyStates(context);
  7256. if (this._processMeasures(parentMeasure, context)) {
  7257. this._prepareRenderingData(this.isThumbCircle ? "circle" : "rectangle");
  7258. var left = this._renderLeft;
  7259. var top = this._renderTop;
  7260. var width = this._renderWidth;
  7261. var height = this._renderHeight;
  7262. var radius = 0;
  7263. if (this.isThumbClamped && this.isThumbCircle) {
  7264. if (this.isVertical) {
  7265. top += (this._effectiveThumbThickness / 2);
  7266. }
  7267. else {
  7268. left += (this._effectiveThumbThickness / 2);
  7269. }
  7270. radius = this._backgroundBoxThickness / 2;
  7271. }
  7272. else {
  7273. radius = (this._effectiveThumbThickness - this._effectiveBarOffset) / 2;
  7274. }
  7275. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  7276. context.shadowColor = this.shadowColor;
  7277. context.shadowBlur = this.shadowBlur;
  7278. context.shadowOffsetX = this.shadowOffsetX;
  7279. context.shadowOffsetY = this.shadowOffsetY;
  7280. }
  7281. var thumbPosition = this._getThumbPosition();
  7282. context.fillStyle = this._background;
  7283. if (this.isVertical) {
  7284. if (this.isThumbClamped) {
  7285. if (this.isThumbCircle) {
  7286. context.beginPath();
  7287. context.arc(left + this._backgroundBoxThickness / 2, top, radius, Math.PI, 2 * Math.PI);
  7288. context.fill();
  7289. context.fillRect(left, top, width, height);
  7290. }
  7291. else {
  7292. context.fillRect(left, top, width, height + this._effectiveThumbThickness);
  7293. }
  7294. }
  7295. else {
  7296. context.fillRect(left, top, width, height);
  7297. }
  7298. }
  7299. else {
  7300. if (this.isThumbClamped) {
  7301. if (this.isThumbCircle) {
  7302. context.beginPath();
  7303. context.arc(left + this._backgroundBoxLength, top + (this._backgroundBoxThickness / 2), radius, 0, 2 * Math.PI);
  7304. context.fill();
  7305. context.fillRect(left, top, width, height);
  7306. }
  7307. else {
  7308. context.fillRect(left, top, width + this._effectiveThumbThickness, height);
  7309. }
  7310. }
  7311. else {
  7312. context.fillRect(left, top, width, height);
  7313. }
  7314. }
  7315. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  7316. context.shadowBlur = 0;
  7317. context.shadowOffsetX = 0;
  7318. context.shadowOffsetY = 0;
  7319. }
  7320. // Value bar
  7321. context.fillStyle = this.color;
  7322. if (this.isVertical) {
  7323. if (this.isThumbClamped) {
  7324. if (this.isThumbCircle) {
  7325. context.beginPath();
  7326. context.arc(left + this._backgroundBoxThickness / 2, top + this._backgroundBoxLength, radius, 0, 2 * Math.PI);
  7327. context.fill();
  7328. context.fillRect(left, top + thumbPosition, width, height - thumbPosition);
  7329. }
  7330. else {
  7331. context.fillRect(left, top + thumbPosition, width, height - thumbPosition + this._effectiveThumbThickness);
  7332. }
  7333. }
  7334. else {
  7335. context.fillRect(left, top + thumbPosition, width, height - thumbPosition);
  7336. }
  7337. }
  7338. else {
  7339. if (this.isThumbClamped) {
  7340. if (this.isThumbCircle) {
  7341. context.beginPath();
  7342. context.arc(left, top + this._backgroundBoxThickness / 2, radius, 0, 2 * Math.PI);
  7343. context.fill();
  7344. context.fillRect(left, top, thumbPosition, height);
  7345. }
  7346. else {
  7347. context.fillRect(left, top, thumbPosition, height);
  7348. }
  7349. }
  7350. else {
  7351. context.fillRect(left, top, thumbPosition, height);
  7352. }
  7353. }
  7354. // Thumb
  7355. if (this.displayThumb) {
  7356. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  7357. context.shadowColor = this.shadowColor;
  7358. context.shadowBlur = this.shadowBlur;
  7359. context.shadowOffsetX = this.shadowOffsetX;
  7360. context.shadowOffsetY = this.shadowOffsetY;
  7361. }
  7362. if (this._isThumbCircle) {
  7363. context.beginPath();
  7364. if (this.isVertical) {
  7365. context.arc(left + this._backgroundBoxThickness / 2, top + thumbPosition, radius, 0, 2 * Math.PI);
  7366. }
  7367. else {
  7368. context.arc(left + thumbPosition, top + (this._backgroundBoxThickness / 2), radius, 0, 2 * Math.PI);
  7369. }
  7370. context.fill();
  7371. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  7372. context.shadowBlur = 0;
  7373. context.shadowOffsetX = 0;
  7374. context.shadowOffsetY = 0;
  7375. }
  7376. context.strokeStyle = this._borderColor;
  7377. context.stroke();
  7378. }
  7379. else {
  7380. if (this.isVertical) {
  7381. context.fillRect(left - this._effectiveBarOffset, this._currentMeasure.top + thumbPosition, this._currentMeasure.width, this._effectiveThumbThickness);
  7382. }
  7383. else {
  7384. context.fillRect(this._currentMeasure.left + thumbPosition, this._currentMeasure.top, this._effectiveThumbThickness, this._currentMeasure.height);
  7385. }
  7386. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  7387. context.shadowBlur = 0;
  7388. context.shadowOffsetX = 0;
  7389. context.shadowOffsetY = 0;
  7390. }
  7391. context.strokeStyle = this._borderColor;
  7392. if (this.isVertical) {
  7393. context.strokeRect(left - this._effectiveBarOffset, this._currentMeasure.top + thumbPosition, this._currentMeasure.width, this._effectiveThumbThickness);
  7394. }
  7395. else {
  7396. context.strokeRect(this._currentMeasure.left + thumbPosition, this._currentMeasure.top, this._effectiveThumbThickness, this._currentMeasure.height);
  7397. }
  7398. }
  7399. }
  7400. }
  7401. context.restore();
  7402. };
  7403. return Slider;
  7404. }(baseSlider_1.BaseSlider));
  7405. exports.Slider = Slider;
  7406. /***/ }),
  7407. /***/ "./src/2D/controls/stackPanel.ts":
  7408. /*!***************************************!*\
  7409. !*** ./src/2D/controls/stackPanel.ts ***!
  7410. \***************************************/
  7411. /*! no static exports found */
  7412. /***/ (function(module, exports, __webpack_require__) {
  7413. "use strict";
  7414. var __extends = (this && this.__extends) || (function () {
  7415. var extendStatics = function (d, b) {
  7416. extendStatics = Object.setPrototypeOf ||
  7417. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  7418. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7419. return extendStatics(d, b);
  7420. }
  7421. return function (d, b) {
  7422. extendStatics(d, b);
  7423. function __() { this.constructor = d; }
  7424. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7425. };
  7426. })();
  7427. Object.defineProperty(exports, "__esModule", { value: true });
  7428. var container_1 = __webpack_require__(/*! ./container */ "./src/2D/controls/container.ts");
  7429. var measure_1 = __webpack_require__(/*! ../measure */ "./src/2D/measure.ts");
  7430. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  7431. /**
  7432. * Class used to create a 2D stack panel container
  7433. */
  7434. var StackPanel = /** @class */ (function (_super) {
  7435. __extends(StackPanel, _super);
  7436. /**
  7437. * Creates a new StackPanel
  7438. * @param name defines control name
  7439. */
  7440. function StackPanel(name) {
  7441. var _this = _super.call(this, name) || this;
  7442. _this.name = name;
  7443. _this._isVertical = true;
  7444. _this._manualWidth = false;
  7445. _this._manualHeight = false;
  7446. _this._doNotTrackManualChanges = false;
  7447. _this._tempMeasureStore = measure_1.Measure.Empty();
  7448. return _this;
  7449. }
  7450. Object.defineProperty(StackPanel.prototype, "isVertical", {
  7451. /** Gets or sets a boolean indicating if the stack panel is vertical or horizontal*/
  7452. get: function () {
  7453. return this._isVertical;
  7454. },
  7455. set: function (value) {
  7456. if (this._isVertical === value) {
  7457. return;
  7458. }
  7459. this._isVertical = value;
  7460. this._markAsDirty();
  7461. },
  7462. enumerable: true,
  7463. configurable: true
  7464. });
  7465. Object.defineProperty(StackPanel.prototype, "width", {
  7466. get: function () {
  7467. return this._width.toString(this._host);
  7468. },
  7469. /**
  7470. * Gets or sets panel width.
  7471. * This value should not be set when in horizontal mode as it will be computed automatically
  7472. */
  7473. set: function (value) {
  7474. if (!this._doNotTrackManualChanges) {
  7475. this._manualWidth = true;
  7476. }
  7477. if (this._width.toString(this._host) === value) {
  7478. return;
  7479. }
  7480. if (this._width.fromString(value)) {
  7481. this._markAsDirty();
  7482. }
  7483. },
  7484. enumerable: true,
  7485. configurable: true
  7486. });
  7487. Object.defineProperty(StackPanel.prototype, "height", {
  7488. get: function () {
  7489. return this._height.toString(this._host);
  7490. },
  7491. /**
  7492. * Gets or sets panel height.
  7493. * This value should not be set when in vertical mode as it will be computed automatically
  7494. */
  7495. set: function (value) {
  7496. if (!this._doNotTrackManualChanges) {
  7497. this._manualHeight = true;
  7498. }
  7499. if (this._height.toString(this._host) === value) {
  7500. return;
  7501. }
  7502. if (this._height.fromString(value)) {
  7503. this._markAsDirty();
  7504. }
  7505. },
  7506. enumerable: true,
  7507. configurable: true
  7508. });
  7509. StackPanel.prototype._getTypeName = function () {
  7510. return "StackPanel";
  7511. };
  7512. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  7513. var stackWidth = 0;
  7514. var stackHeight = 0;
  7515. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  7516. var child = _a[_i];
  7517. this._tempMeasureStore.copyFrom(child._currentMeasure);
  7518. child._currentMeasure.copyFrom(parentMeasure);
  7519. child._measure();
  7520. if (this._isVertical) {
  7521. child.top = stackHeight + "px";
  7522. if (!child._top.ignoreAdaptiveScaling) {
  7523. child._markAsDirty();
  7524. }
  7525. child._top.ignoreAdaptiveScaling = true;
  7526. stackHeight += child._currentMeasure.height;
  7527. if (child._currentMeasure.width > stackWidth) {
  7528. stackWidth = child._currentMeasure.width;
  7529. }
  7530. child.verticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_TOP;
  7531. }
  7532. else {
  7533. child.left = stackWidth + "px";
  7534. if (!child._left.ignoreAdaptiveScaling) {
  7535. child._markAsDirty();
  7536. }
  7537. child._left.ignoreAdaptiveScaling = true;
  7538. stackWidth += child._currentMeasure.width;
  7539. if (child._currentMeasure.height > stackHeight) {
  7540. stackHeight = child._currentMeasure.height;
  7541. }
  7542. child.horizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  7543. }
  7544. child._currentMeasure.copyFrom(this._tempMeasureStore);
  7545. }
  7546. this._doNotTrackManualChanges = true;
  7547. // Let stack panel width and height default to stackHeight and stackWidth if dimensions are not specified.
  7548. // User can now define their own height and width for stack panel.
  7549. var panelWidthChanged = false;
  7550. var panelHeightChanged = false;
  7551. var previousHeight = this.height;
  7552. var previousWidth = this.width;
  7553. if (!this._manualHeight) {
  7554. // do not specify height if strictly defined by user
  7555. this.height = stackHeight + "px";
  7556. }
  7557. if (!this._manualWidth) {
  7558. // do not specify width if strictly defined by user
  7559. this.width = stackWidth + "px";
  7560. }
  7561. panelWidthChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  7562. panelHeightChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  7563. if (panelHeightChanged) {
  7564. this._height.ignoreAdaptiveScaling = true;
  7565. }
  7566. if (panelWidthChanged) {
  7567. this._width.ignoreAdaptiveScaling = true;
  7568. }
  7569. this._doNotTrackManualChanges = false;
  7570. if (panelWidthChanged || panelHeightChanged) {
  7571. this._markAllAsDirty();
  7572. }
  7573. _super.prototype._preMeasure.call(this, parentMeasure, context);
  7574. };
  7575. return StackPanel;
  7576. }(container_1.Container));
  7577. exports.StackPanel = StackPanel;
  7578. /***/ }),
  7579. /***/ "./src/2D/controls/statics.ts":
  7580. /*!************************************!*\
  7581. !*** ./src/2D/controls/statics.ts ***!
  7582. \************************************/
  7583. /*! no static exports found */
  7584. /***/ (function(module, exports, __webpack_require__) {
  7585. "use strict";
  7586. Object.defineProperty(exports, "__esModule", { value: true });
  7587. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  7588. var stackPanel_1 = __webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts");
  7589. var textBlock_1 = __webpack_require__(/*! ./textBlock */ "./src/2D/controls/textBlock.ts");
  7590. /**
  7591. * Forcing an export so that this code will execute
  7592. * @hidden
  7593. */
  7594. var name = "Statics";
  7595. exports.name = name;
  7596. /**
  7597. * Creates a stack panel that can be used to render headers
  7598. * @param control defines the control to associate with the header
  7599. * @param text defines the text of the header
  7600. * @param size defines the size of the header
  7601. * @param options defines options used to configure the header
  7602. * @returns a new StackPanel
  7603. */
  7604. control_1.Control.AddHeader = function (control, text, size, options) {
  7605. var panel = new stackPanel_1.StackPanel("panel");
  7606. var isHorizontal = options ? options.isHorizontal : true;
  7607. var controlFirst = options ? options.controlFirst : true;
  7608. panel.isVertical = !isHorizontal;
  7609. var header = new textBlock_1.TextBlock("header");
  7610. header.text = text;
  7611. header.textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_LEFT;
  7612. if (isHorizontal) {
  7613. header.width = size;
  7614. }
  7615. else {
  7616. header.height = size;
  7617. }
  7618. if (controlFirst) {
  7619. panel.addControl(control);
  7620. panel.addControl(header);
  7621. header.paddingLeft = "5px";
  7622. }
  7623. else {
  7624. panel.addControl(header);
  7625. panel.addControl(control);
  7626. header.paddingRight = "5px";
  7627. }
  7628. header.shadowBlur = control.shadowBlur;
  7629. header.shadowColor = control.shadowColor;
  7630. header.shadowOffsetX = control.shadowOffsetX;
  7631. header.shadowOffsetY = control.shadowOffsetY;
  7632. return panel;
  7633. };
  7634. /***/ }),
  7635. /***/ "./src/2D/controls/textBlock.ts":
  7636. /*!**************************************!*\
  7637. !*** ./src/2D/controls/textBlock.ts ***!
  7638. \**************************************/
  7639. /*! no static exports found */
  7640. /***/ (function(module, exports, __webpack_require__) {
  7641. "use strict";
  7642. var __extends = (this && this.__extends) || (function () {
  7643. var extendStatics = function (d, b) {
  7644. extendStatics = Object.setPrototypeOf ||
  7645. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  7646. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7647. return extendStatics(d, b);
  7648. }
  7649. return function (d, b) {
  7650. extendStatics(d, b);
  7651. function __() { this.constructor = d; }
  7652. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7653. };
  7654. })();
  7655. Object.defineProperty(exports, "__esModule", { value: true });
  7656. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  7657. var valueAndUnit_1 = __webpack_require__(/*! ../valueAndUnit */ "./src/2D/valueAndUnit.ts");
  7658. var control_1 = __webpack_require__(/*! ./control */ "./src/2D/controls/control.ts");
  7659. /**
  7660. * Enum that determines the text-wrapping mode to use.
  7661. */
  7662. var TextWrapping;
  7663. (function (TextWrapping) {
  7664. /**
  7665. * Clip the text when it's larger than Control.width; this is the default mode.
  7666. */
  7667. TextWrapping[TextWrapping["Clip"] = 0] = "Clip";
  7668. /**
  7669. * Wrap the text word-wise, i.e. try to add line-breaks at word boundary to fit within Control.width.
  7670. */
  7671. TextWrapping[TextWrapping["WordWrap"] = 1] = "WordWrap";
  7672. /**
  7673. * Ellipsize the text, i.e. shrink with trailing … when text is larger than Control.width.
  7674. */
  7675. TextWrapping[TextWrapping["Ellipsis"] = 2] = "Ellipsis";
  7676. })(TextWrapping = exports.TextWrapping || (exports.TextWrapping = {}));
  7677. /**
  7678. * Class used to create text block control
  7679. */
  7680. var TextBlock = /** @class */ (function (_super) {
  7681. __extends(TextBlock, _super);
  7682. /**
  7683. * Creates a new TextBlock object
  7684. * @param name defines the name of the control
  7685. * @param text defines the text to display (emptry string by default)
  7686. */
  7687. function TextBlock(
  7688. /**
  7689. * Defines the name of the control
  7690. */
  7691. name, text) {
  7692. if (text === void 0) { text = ""; }
  7693. var _this = _super.call(this, name) || this;
  7694. _this.name = name;
  7695. _this._text = "";
  7696. _this._textWrapping = TextWrapping.Clip;
  7697. _this._textHorizontalAlignment = control_1.Control.HORIZONTAL_ALIGNMENT_CENTER;
  7698. _this._textVerticalAlignment = control_1.Control.VERTICAL_ALIGNMENT_CENTER;
  7699. _this._resizeToFit = false;
  7700. _this._lineSpacing = new valueAndUnit_1.ValueAndUnit(0);
  7701. _this._outlineWidth = 0;
  7702. _this._outlineColor = "white";
  7703. /**
  7704. * An event triggered after the text is changed
  7705. */
  7706. _this.onTextChangedObservable = new babylonjs_1.Observable();
  7707. /**
  7708. * An event triggered after the text was broken up into lines
  7709. */
  7710. _this.onLinesReadyObservable = new babylonjs_1.Observable();
  7711. _this.text = text;
  7712. return _this;
  7713. }
  7714. Object.defineProperty(TextBlock.prototype, "lines", {
  7715. /**
  7716. * Return the line list (you may need to use the onLinesReadyObservable to make sure the list is ready)
  7717. */
  7718. get: function () {
  7719. return this._lines;
  7720. },
  7721. enumerable: true,
  7722. configurable: true
  7723. });
  7724. Object.defineProperty(TextBlock.prototype, "resizeToFit", {
  7725. /**
  7726. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  7727. */
  7728. get: function () {
  7729. return this._resizeToFit;
  7730. },
  7731. /**
  7732. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  7733. */
  7734. set: function (value) {
  7735. this._resizeToFit = value;
  7736. if (this._resizeToFit) {
  7737. this._width.ignoreAdaptiveScaling = true;
  7738. this._height.ignoreAdaptiveScaling = true;
  7739. }
  7740. },
  7741. enumerable: true,
  7742. configurable: true
  7743. });
  7744. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  7745. /**
  7746. * Gets or sets a boolean indicating if text must be wrapped
  7747. */
  7748. get: function () {
  7749. return this._textWrapping;
  7750. },
  7751. /**
  7752. * Gets or sets a boolean indicating if text must be wrapped
  7753. */
  7754. set: function (value) {
  7755. if (this._textWrapping === value) {
  7756. return;
  7757. }
  7758. this._textWrapping = +value;
  7759. this._markAsDirty();
  7760. },
  7761. enumerable: true,
  7762. configurable: true
  7763. });
  7764. Object.defineProperty(TextBlock.prototype, "text", {
  7765. /**
  7766. * Gets or sets text to display
  7767. */
  7768. get: function () {
  7769. return this._text;
  7770. },
  7771. /**
  7772. * Gets or sets text to display
  7773. */
  7774. set: function (value) {
  7775. if (this._text === value) {
  7776. return;
  7777. }
  7778. this._text = value;
  7779. this._markAsDirty();
  7780. this.onTextChangedObservable.notifyObservers(this);
  7781. },
  7782. enumerable: true,
  7783. configurable: true
  7784. });
  7785. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  7786. /**
  7787. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  7788. */
  7789. get: function () {
  7790. return this._textHorizontalAlignment;
  7791. },
  7792. /**
  7793. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  7794. */
  7795. set: function (value) {
  7796. if (this._textHorizontalAlignment === value) {
  7797. return;
  7798. }
  7799. this._textHorizontalAlignment = value;
  7800. this._markAsDirty();
  7801. },
  7802. enumerable: true,
  7803. configurable: true
  7804. });
  7805. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  7806. /**
  7807. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  7808. */
  7809. get: function () {
  7810. return this._textVerticalAlignment;
  7811. },
  7812. /**
  7813. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  7814. */
  7815. set: function (value) {
  7816. if (this._textVerticalAlignment === value) {
  7817. return;
  7818. }
  7819. this._textVerticalAlignment = value;
  7820. this._markAsDirty();
  7821. },
  7822. enumerable: true,
  7823. configurable: true
  7824. });
  7825. Object.defineProperty(TextBlock.prototype, "lineSpacing", {
  7826. /**
  7827. * Gets or sets line spacing value
  7828. */
  7829. get: function () {
  7830. return this._lineSpacing.toString(this._host);
  7831. },
  7832. /**
  7833. * Gets or sets line spacing value
  7834. */
  7835. set: function (value) {
  7836. if (this._lineSpacing.fromString(value)) {
  7837. this._markAsDirty();
  7838. }
  7839. },
  7840. enumerable: true,
  7841. configurable: true
  7842. });
  7843. Object.defineProperty(TextBlock.prototype, "outlineWidth", {
  7844. /**
  7845. * Gets or sets outlineWidth of the text to display
  7846. */
  7847. get: function () {
  7848. return this._outlineWidth;
  7849. },
  7850. /**
  7851. * Gets or sets outlineWidth of the text to display
  7852. */
  7853. set: function (value) {
  7854. if (this._outlineWidth === value) {
  7855. return;
  7856. }
  7857. this._outlineWidth = value;
  7858. this._markAsDirty();
  7859. },
  7860. enumerable: true,
  7861. configurable: true
  7862. });
  7863. Object.defineProperty(TextBlock.prototype, "outlineColor", {
  7864. /**
  7865. * Gets or sets outlineColor of the text to display
  7866. */
  7867. get: function () {
  7868. return this._outlineColor;
  7869. },
  7870. /**
  7871. * Gets or sets outlineColor of the text to display
  7872. */
  7873. set: function (value) {
  7874. if (this._outlineColor === value) {
  7875. return;
  7876. }
  7877. this._outlineColor = value;
  7878. this._markAsDirty();
  7879. },
  7880. enumerable: true,
  7881. configurable: true
  7882. });
  7883. TextBlock.prototype._getTypeName = function () {
  7884. return "TextBlock";
  7885. };
  7886. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  7887. var width = this._currentMeasure.width;
  7888. var x = 0;
  7889. switch (this._textHorizontalAlignment) {
  7890. case control_1.Control.HORIZONTAL_ALIGNMENT_LEFT:
  7891. x = 0;
  7892. break;
  7893. case control_1.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  7894. x = width - textWidth;
  7895. break;
  7896. case control_1.Control.HORIZONTAL_ALIGNMENT_CENTER:
  7897. x = (width - textWidth) / 2;
  7898. break;
  7899. }
  7900. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  7901. context.shadowColor = this.shadowColor;
  7902. context.shadowBlur = this.shadowBlur;
  7903. context.shadowOffsetX = this.shadowOffsetX;
  7904. context.shadowOffsetY = this.shadowOffsetY;
  7905. }
  7906. if (this.outlineWidth) {
  7907. context.strokeText(text, this._currentMeasure.left + x, y);
  7908. }
  7909. context.fillText(text, this._currentMeasure.left + x, y);
  7910. };
  7911. /** @hidden */
  7912. TextBlock.prototype._draw = function (parentMeasure, context) {
  7913. context.save();
  7914. this._applyStates(context);
  7915. if (this._processMeasures(parentMeasure, context)) {
  7916. // Render lines
  7917. this._renderLines(context);
  7918. }
  7919. context.restore();
  7920. };
  7921. TextBlock.prototype._applyStates = function (context) {
  7922. _super.prototype._applyStates.call(this, context);
  7923. if (this.outlineWidth) {
  7924. context.lineWidth = this.outlineWidth;
  7925. context.strokeStyle = this.outlineColor;
  7926. }
  7927. };
  7928. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  7929. this._lines = this._breakLines(this._currentMeasure.width, context);
  7930. this.onLinesReadyObservable.notifyObservers(this);
  7931. };
  7932. TextBlock.prototype._breakLines = function (refWidth, context) {
  7933. var lines = [];
  7934. var _lines = this.text.split("\n");
  7935. if (this._textWrapping === TextWrapping.Ellipsis && !this._resizeToFit) {
  7936. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  7937. var _line = _lines_1[_i];
  7938. lines.push(this._parseLineEllipsis(_line, refWidth, context));
  7939. }
  7940. }
  7941. else if (this._textWrapping === TextWrapping.WordWrap && !this._resizeToFit) {
  7942. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  7943. var _line = _lines_2[_a];
  7944. lines.push.apply(lines, this._parseLineWordWrap(_line, refWidth, context));
  7945. }
  7946. }
  7947. else {
  7948. for (var _b = 0, _lines_3 = _lines; _b < _lines_3.length; _b++) {
  7949. var _line = _lines_3[_b];
  7950. lines.push(this._parseLine(_line, context));
  7951. }
  7952. }
  7953. return lines;
  7954. };
  7955. TextBlock.prototype._parseLine = function (line, context) {
  7956. if (line === void 0) { line = ''; }
  7957. return { text: line, width: context.measureText(line).width };
  7958. };
  7959. TextBlock.prototype._parseLineEllipsis = function (line, width, context) {
  7960. if (line === void 0) { line = ''; }
  7961. var lineWidth = context.measureText(line).width;
  7962. if (lineWidth > width) {
  7963. line += '…';
  7964. }
  7965. while (line.length > 2 && lineWidth > width) {
  7966. line = line.slice(0, -2) + '…';
  7967. lineWidth = context.measureText(line).width;
  7968. }
  7969. return { text: line, width: lineWidth };
  7970. };
  7971. TextBlock.prototype._parseLineWordWrap = function (line, width, context) {
  7972. if (line === void 0) { line = ''; }
  7973. var lines = [];
  7974. var words = line.split(' ');
  7975. var lineWidth = 0;
  7976. for (var n = 0; n < words.length; n++) {
  7977. var testLine = n > 0 ? line + " " + words[n] : words[0];
  7978. var metrics = context.measureText(testLine);
  7979. var testWidth = metrics.width;
  7980. if (testWidth > width && n > 0) {
  7981. lines.push({ text: line, width: lineWidth });
  7982. line = words[n];
  7983. lineWidth = context.measureText(line).width;
  7984. }
  7985. else {
  7986. lineWidth = testWidth;
  7987. line = testLine;
  7988. }
  7989. }
  7990. lines.push({ text: line, width: lineWidth });
  7991. return lines;
  7992. };
  7993. TextBlock.prototype._renderLines = function (context) {
  7994. var height = this._currentMeasure.height;
  7995. if (!this._fontOffset) {
  7996. this._fontOffset = control_1.Control._GetFontOffset(context.font);
  7997. }
  7998. var rootY = 0;
  7999. switch (this._textVerticalAlignment) {
  8000. case control_1.Control.VERTICAL_ALIGNMENT_TOP:
  8001. rootY = this._fontOffset.ascent;
  8002. break;
  8003. case control_1.Control.VERTICAL_ALIGNMENT_BOTTOM:
  8004. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  8005. break;
  8006. case control_1.Control.VERTICAL_ALIGNMENT_CENTER:
  8007. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  8008. break;
  8009. }
  8010. rootY += this._currentMeasure.top;
  8011. var maxLineWidth = 0;
  8012. for (var i = 0; i < this._lines.length; i++) {
  8013. var line = this._lines[i];
  8014. if (i !== 0 && this._lineSpacing.internalValue !== 0) {
  8015. if (this._lineSpacing.isPixel) {
  8016. rootY += this._lineSpacing.getValue(this._host);
  8017. }
  8018. else {
  8019. rootY = rootY + (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
  8020. }
  8021. }
  8022. this._drawText(line.text, line.width, rootY, context);
  8023. rootY += this._fontOffset.height;
  8024. if (line.width > maxLineWidth) {
  8025. maxLineWidth = line.width;
  8026. }
  8027. }
  8028. if (this._resizeToFit) {
  8029. this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
  8030. this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
  8031. }
  8032. };
  8033. /**
  8034. * Given a width constraint applied on the text block, find the expected height
  8035. * @returns expected height
  8036. */
  8037. TextBlock.prototype.computeExpectedHeight = function () {
  8038. if (this.text && this.widthInPixels) {
  8039. var context_1 = document.createElement('canvas').getContext('2d');
  8040. if (context_1) {
  8041. this._applyStates(context_1);
  8042. if (!this._fontOffset) {
  8043. this._fontOffset = control_1.Control._GetFontOffset(context_1.font);
  8044. }
  8045. var lines = this._lines ? this._lines : this._breakLines(this.widthInPixels - this.paddingLeftInPixels - this.paddingRightInPixels, context_1);
  8046. return this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * lines.length;
  8047. }
  8048. }
  8049. return 0;
  8050. };
  8051. TextBlock.prototype.dispose = function () {
  8052. _super.prototype.dispose.call(this);
  8053. this.onTextChangedObservable.clear();
  8054. };
  8055. return TextBlock;
  8056. }(control_1.Control));
  8057. exports.TextBlock = TextBlock;
  8058. /***/ }),
  8059. /***/ "./src/2D/controls/virtualKeyboard.ts":
  8060. /*!********************************************!*\
  8061. !*** ./src/2D/controls/virtualKeyboard.ts ***!
  8062. \********************************************/
  8063. /*! no static exports found */
  8064. /***/ (function(module, exports, __webpack_require__) {
  8065. "use strict";
  8066. var __extends = (this && this.__extends) || (function () {
  8067. var extendStatics = function (d, b) {
  8068. extendStatics = Object.setPrototypeOf ||
  8069. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  8070. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  8071. return extendStatics(d, b);
  8072. }
  8073. return function (d, b) {
  8074. extendStatics(d, b);
  8075. function __() { this.constructor = d; }
  8076. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8077. };
  8078. })();
  8079. Object.defineProperty(exports, "__esModule", { value: true });
  8080. var stackPanel_1 = __webpack_require__(/*! ./stackPanel */ "./src/2D/controls/stackPanel.ts");
  8081. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8082. var button_1 = __webpack_require__(/*! ./button */ "./src/2D/controls/button.ts");
  8083. /**
  8084. * Class used to store key control properties
  8085. */
  8086. var KeyPropertySet = /** @class */ (function () {
  8087. function KeyPropertySet() {
  8088. }
  8089. return KeyPropertySet;
  8090. }());
  8091. exports.KeyPropertySet = KeyPropertySet;
  8092. /**
  8093. * Class used to create virtual keyboard
  8094. */
  8095. var VirtualKeyboard = /** @class */ (function (_super) {
  8096. __extends(VirtualKeyboard, _super);
  8097. function VirtualKeyboard() {
  8098. var _this = _super !== null && _super.apply(this, arguments) || this;
  8099. /** Observable raised when a key is pressed */
  8100. _this.onKeyPressObservable = new babylonjs_1.Observable();
  8101. /** Gets or sets default key button width */
  8102. _this.defaultButtonWidth = "40px";
  8103. /** Gets or sets default key button height */
  8104. _this.defaultButtonHeight = "40px";
  8105. /** Gets or sets default key button left padding */
  8106. _this.defaultButtonPaddingLeft = "2px";
  8107. /** Gets or sets default key button right padding */
  8108. _this.defaultButtonPaddingRight = "2px";
  8109. /** Gets or sets default key button top padding */
  8110. _this.defaultButtonPaddingTop = "2px";
  8111. /** Gets or sets default key button bottom padding */
  8112. _this.defaultButtonPaddingBottom = "2px";
  8113. /** Gets or sets default key button foreground color */
  8114. _this.defaultButtonColor = "#DDD";
  8115. /** Gets or sets default key button background color */
  8116. _this.defaultButtonBackground = "#070707";
  8117. /** Gets or sets shift button foreground color */
  8118. _this.shiftButtonColor = "#7799FF";
  8119. /** Gets or sets shift button thickness*/
  8120. _this.selectedShiftThickness = 1;
  8121. /** Gets shift key state */
  8122. _this.shiftState = 0;
  8123. _this._currentlyConnectedInputText = null;
  8124. _this._connectedInputTexts = [];
  8125. _this._onKeyPressObserver = null;
  8126. return _this;
  8127. }
  8128. VirtualKeyboard.prototype._getTypeName = function () {
  8129. return "VirtualKeyboard";
  8130. };
  8131. VirtualKeyboard.prototype._createKey = function (key, propertySet) {
  8132. var _this = this;
  8133. var button = button_1.Button.CreateSimpleButton(key, key);
  8134. button.width = propertySet && propertySet.width ? propertySet.width : this.defaultButtonWidth;
  8135. button.height = propertySet && propertySet.height ? propertySet.height : this.defaultButtonHeight;
  8136. button.color = propertySet && propertySet.color ? propertySet.color : this.defaultButtonColor;
  8137. button.background = propertySet && propertySet.background ? propertySet.background : this.defaultButtonBackground;
  8138. button.paddingLeft = propertySet && propertySet.paddingLeft ? propertySet.paddingLeft : this.defaultButtonPaddingLeft;
  8139. button.paddingRight = propertySet && propertySet.paddingRight ? propertySet.paddingRight : this.defaultButtonPaddingRight;
  8140. button.paddingTop = propertySet && propertySet.paddingTop ? propertySet.paddingTop : this.defaultButtonPaddingTop;
  8141. button.paddingBottom = propertySet && propertySet.paddingBottom ? propertySet.paddingBottom : this.defaultButtonPaddingBottom;
  8142. button.thickness = 0;
  8143. button.isFocusInvisible = true;
  8144. button.shadowColor = this.shadowColor;
  8145. button.shadowBlur = this.shadowBlur;
  8146. button.shadowOffsetX = this.shadowOffsetX;
  8147. button.shadowOffsetY = this.shadowOffsetY;
  8148. button.onPointerUpObservable.add(function () {
  8149. _this.onKeyPressObservable.notifyObservers(key);
  8150. });
  8151. return button;
  8152. };
  8153. /**
  8154. * Adds a new row of keys
  8155. * @param keys defines the list of keys to add
  8156. * @param propertySets defines the associated property sets
  8157. */
  8158. VirtualKeyboard.prototype.addKeysRow = function (keys, propertySets) {
  8159. var panel = new stackPanel_1.StackPanel();
  8160. panel.isVertical = false;
  8161. panel.isFocusInvisible = true;
  8162. for (var i = 0; i < keys.length; i++) {
  8163. var properties = null;
  8164. if (propertySets && propertySets.length === keys.length) {
  8165. properties = propertySets[i];
  8166. }
  8167. panel.addControl(this._createKey(keys[i], properties));
  8168. }
  8169. this.addControl(panel);
  8170. };
  8171. /**
  8172. * Set the shift key to a specific state
  8173. * @param shiftState defines the new shift state
  8174. */
  8175. VirtualKeyboard.prototype.applyShiftState = function (shiftState) {
  8176. if (!this.children) {
  8177. return;
  8178. }
  8179. for (var i = 0; i < this.children.length; i++) {
  8180. var row = this.children[i];
  8181. if (!row || !row.children) {
  8182. continue;
  8183. }
  8184. var rowContainer = row;
  8185. for (var j = 0; j < rowContainer.children.length; j++) {
  8186. var button = rowContainer.children[j];
  8187. if (!button || !button.children[0]) {
  8188. continue;
  8189. }
  8190. var button_tblock = button.children[0];
  8191. if (button_tblock.text === "\u21E7") {
  8192. button.color = (shiftState ? this.shiftButtonColor : this.defaultButtonColor);
  8193. button.thickness = (shiftState > 1 ? this.selectedShiftThickness : 0);
  8194. }
  8195. button_tblock.text = (shiftState > 0 ? button_tblock.text.toUpperCase() : button_tblock.text.toLowerCase());
  8196. }
  8197. }
  8198. };
  8199. Object.defineProperty(VirtualKeyboard.prototype, "connectedInputText", {
  8200. /** Gets the input text control currently attached to the keyboard */
  8201. get: function () {
  8202. return this._currentlyConnectedInputText;
  8203. },
  8204. enumerable: true,
  8205. configurable: true
  8206. });
  8207. /**
  8208. * Connects the keyboard with an input text control
  8209. *
  8210. * @param input defines the target control
  8211. */
  8212. VirtualKeyboard.prototype.connect = function (input) {
  8213. var _this = this;
  8214. var inputTextAlreadyConnected = this._connectedInputTexts.some(function (a) { return a.input === input; });
  8215. if (inputTextAlreadyConnected) {
  8216. return;
  8217. }
  8218. if (this._onKeyPressObserver === null) {
  8219. this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
  8220. if (!_this._currentlyConnectedInputText) {
  8221. return;
  8222. }
  8223. _this._currentlyConnectedInputText._host.focusedControl = _this._currentlyConnectedInputText;
  8224. switch (key) {
  8225. case "\u21E7":
  8226. _this.shiftState++;
  8227. if (_this.shiftState > 2) {
  8228. _this.shiftState = 0;
  8229. }
  8230. _this.applyShiftState(_this.shiftState);
  8231. return;
  8232. case "\u2190":
  8233. _this._currentlyConnectedInputText.processKey(8);
  8234. return;
  8235. case "\u21B5":
  8236. _this._currentlyConnectedInputText.processKey(13);
  8237. return;
  8238. }
  8239. _this._currentlyConnectedInputText.processKey(-1, (_this.shiftState ? key.toUpperCase() : key));
  8240. if (_this.shiftState === 1) {
  8241. _this.shiftState = 0;
  8242. _this.applyShiftState(_this.shiftState);
  8243. }
  8244. });
  8245. }
  8246. this.isVisible = false;
  8247. this._currentlyConnectedInputText = input;
  8248. input._connectedVirtualKeyboard = this;
  8249. // Events hooking
  8250. var onFocusObserver = input.onFocusObservable.add(function () {
  8251. _this._currentlyConnectedInputText = input;
  8252. input._connectedVirtualKeyboard = _this;
  8253. _this.isVisible = true;
  8254. });
  8255. var onBlurObserver = input.onBlurObservable.add(function () {
  8256. input._connectedVirtualKeyboard = null;
  8257. _this._currentlyConnectedInputText = null;
  8258. _this.isVisible = false;
  8259. });
  8260. this._connectedInputTexts.push({
  8261. input: input,
  8262. onBlurObserver: onBlurObserver,
  8263. onFocusObserver: onFocusObserver
  8264. });
  8265. };
  8266. /**
  8267. * Disconnects the keyboard from connected InputText controls
  8268. *
  8269. * @param input optionally defines a target control, otherwise all are disconnected
  8270. */
  8271. VirtualKeyboard.prototype.disconnect = function (input) {
  8272. var _this = this;
  8273. if (input) {
  8274. // .find not available on IE
  8275. var filtered = this._connectedInputTexts.filter(function (a) { return a.input === input; });
  8276. if (filtered.length === 1) {
  8277. this._removeConnectedInputObservables(filtered[0]);
  8278. this._connectedInputTexts = this._connectedInputTexts.filter(function (a) { return a.input !== input; });
  8279. if (this._currentlyConnectedInputText === input) {
  8280. this._currentlyConnectedInputText = null;
  8281. }
  8282. }
  8283. }
  8284. else {
  8285. this._connectedInputTexts.forEach(function (connectedInputText) {
  8286. _this._removeConnectedInputObservables(connectedInputText);
  8287. });
  8288. this._connectedInputTexts = [];
  8289. }
  8290. if (this._connectedInputTexts.length === 0) {
  8291. this._currentlyConnectedInputText = null;
  8292. this.onKeyPressObservable.remove(this._onKeyPressObserver);
  8293. this._onKeyPressObserver = null;
  8294. }
  8295. };
  8296. VirtualKeyboard.prototype._removeConnectedInputObservables = function (connectedInputText) {
  8297. connectedInputText.input._connectedVirtualKeyboard = null;
  8298. connectedInputText.input.onFocusObservable.remove(connectedInputText.onFocusObserver);
  8299. connectedInputText.input.onBlurObservable.remove(connectedInputText.onBlurObserver);
  8300. };
  8301. /**
  8302. * Release all resources
  8303. */
  8304. VirtualKeyboard.prototype.dispose = function () {
  8305. _super.prototype.dispose.call(this);
  8306. this.disconnect();
  8307. };
  8308. // Statics
  8309. /**
  8310. * Creates a new keyboard using a default layout
  8311. *
  8312. * @param name defines control name
  8313. * @returns a new VirtualKeyboard
  8314. */
  8315. VirtualKeyboard.CreateDefaultLayout = function (name) {
  8316. var returnValue = new VirtualKeyboard(name);
  8317. returnValue.addKeysRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u2190"]);
  8318. returnValue.addKeysRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]);
  8319. returnValue.addKeysRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\u21B5"]);
  8320. returnValue.addKeysRow(["\u21E7", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]);
  8321. returnValue.addKeysRow([" "], [{ width: "200px" }]);
  8322. return returnValue;
  8323. };
  8324. return VirtualKeyboard;
  8325. }(stackPanel_1.StackPanel));
  8326. exports.VirtualKeyboard = VirtualKeyboard;
  8327. /***/ }),
  8328. /***/ "./src/2D/index.ts":
  8329. /*!*************************!*\
  8330. !*** ./src/2D/index.ts ***!
  8331. \*************************/
  8332. /*! no static exports found */
  8333. /***/ (function(module, exports, __webpack_require__) {
  8334. "use strict";
  8335. function __export(m) {
  8336. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  8337. }
  8338. Object.defineProperty(exports, "__esModule", { value: true });
  8339. __export(__webpack_require__(/*! ./controls */ "./src/2D/controls/index.ts"));
  8340. __export(__webpack_require__(/*! ./advancedDynamicTexture */ "./src/2D/advancedDynamicTexture.ts"));
  8341. __export(__webpack_require__(/*! ./math2D */ "./src/2D/math2D.ts"));
  8342. __export(__webpack_require__(/*! ./measure */ "./src/2D/measure.ts"));
  8343. __export(__webpack_require__(/*! ./multiLinePoint */ "./src/2D/multiLinePoint.ts"));
  8344. __export(__webpack_require__(/*! ./style */ "./src/2D/style.ts"));
  8345. __export(__webpack_require__(/*! ./valueAndUnit */ "./src/2D/valueAndUnit.ts"));
  8346. /***/ }),
  8347. /***/ "./src/2D/math2D.ts":
  8348. /*!**************************!*\
  8349. !*** ./src/2D/math2D.ts ***!
  8350. \**************************/
  8351. /*! no static exports found */
  8352. /***/ (function(module, exports, __webpack_require__) {
  8353. "use strict";
  8354. var __extends = (this && this.__extends) || (function () {
  8355. var extendStatics = function (d, b) {
  8356. extendStatics = Object.setPrototypeOf ||
  8357. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  8358. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  8359. return extendStatics(d, b);
  8360. }
  8361. return function (d, b) {
  8362. extendStatics(d, b);
  8363. function __() { this.constructor = d; }
  8364. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8365. };
  8366. })();
  8367. Object.defineProperty(exports, "__esModule", { value: true });
  8368. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8369. /**
  8370. * Class used to transport Vector2 information for pointer events
  8371. */
  8372. var Vector2WithInfo = /** @class */ (function (_super) {
  8373. __extends(Vector2WithInfo, _super);
  8374. /**
  8375. * Creates a new Vector2WithInfo
  8376. * @param source defines the vector2 data to transport
  8377. * @param buttonIndex defines the current mouse button index
  8378. */
  8379. function Vector2WithInfo(source,
  8380. /** defines the current mouse button index */
  8381. buttonIndex) {
  8382. if (buttonIndex === void 0) { buttonIndex = 0; }
  8383. var _this = _super.call(this, source.x, source.y) || this;
  8384. _this.buttonIndex = buttonIndex;
  8385. return _this;
  8386. }
  8387. return Vector2WithInfo;
  8388. }(babylonjs_1.Vector2));
  8389. exports.Vector2WithInfo = Vector2WithInfo;
  8390. /** Class used to provide 2D matrix features */
  8391. var Matrix2D = /** @class */ (function () {
  8392. /**
  8393. * Creates a new matrix
  8394. * @param m00 defines value for (0, 0)
  8395. * @param m01 defines value for (0, 1)
  8396. * @param m10 defines value for (1, 0)
  8397. * @param m11 defines value for (1, 1)
  8398. * @param m20 defines value for (2, 0)
  8399. * @param m21 defines value for (2, 1)
  8400. */
  8401. function Matrix2D(m00, m01, m10, m11, m20, m21) {
  8402. /** Gets the internal array of 6 floats used to store matrix data */
  8403. this.m = new Float32Array(6);
  8404. this.fromValues(m00, m01, m10, m11, m20, m21);
  8405. }
  8406. /**
  8407. * Fills the matrix from direct values
  8408. * @param m00 defines value for (0, 0)
  8409. * @param m01 defines value for (0, 1)
  8410. * @param m10 defines value for (1, 0)
  8411. * @param m11 defines value for (1, 1)
  8412. * @param m20 defines value for (2, 0)
  8413. * @param m21 defines value for (2, 1)
  8414. * @returns the current modified matrix
  8415. */
  8416. Matrix2D.prototype.fromValues = function (m00, m01, m10, m11, m20, m21) {
  8417. this.m[0] = m00;
  8418. this.m[1] = m01;
  8419. this.m[2] = m10;
  8420. this.m[3] = m11;
  8421. this.m[4] = m20;
  8422. this.m[5] = m21;
  8423. return this;
  8424. };
  8425. /**
  8426. * Gets matrix determinant
  8427. * @returns the determinant
  8428. */
  8429. Matrix2D.prototype.determinant = function () {
  8430. return this.m[0] * this.m[3] - this.m[1] * this.m[2];
  8431. };
  8432. /**
  8433. * Inverses the matrix and stores it in a target matrix
  8434. * @param result defines the target matrix
  8435. * @returns the current matrix
  8436. */
  8437. Matrix2D.prototype.invertToRef = function (result) {
  8438. var l0 = this.m[0];
  8439. var l1 = this.m[1];
  8440. var l2 = this.m[2];
  8441. var l3 = this.m[3];
  8442. var l4 = this.m[4];
  8443. var l5 = this.m[5];
  8444. var det = this.determinant();
  8445. if (det < (babylonjs_1.Epsilon * babylonjs_1.Epsilon)) {
  8446. result.m[0] = 0;
  8447. result.m[1] = 0;
  8448. result.m[2] = 0;
  8449. result.m[3] = 0;
  8450. result.m[4] = 0;
  8451. result.m[5] = 0;
  8452. return this;
  8453. }
  8454. var detDiv = 1 / det;
  8455. var det4 = l2 * l5 - l3 * l4;
  8456. var det5 = l1 * l4 - l0 * l5;
  8457. result.m[0] = l3 * detDiv;
  8458. result.m[1] = -l1 * detDiv;
  8459. result.m[2] = -l2 * detDiv;
  8460. result.m[3] = l0 * detDiv;
  8461. result.m[4] = det4 * detDiv;
  8462. result.m[5] = det5 * detDiv;
  8463. return this;
  8464. };
  8465. /**
  8466. * Multiplies the current matrix with another one
  8467. * @param other defines the second operand
  8468. * @param result defines the target matrix
  8469. * @returns the current matrix
  8470. */
  8471. Matrix2D.prototype.multiplyToRef = function (other, result) {
  8472. var l0 = this.m[0];
  8473. var l1 = this.m[1];
  8474. var l2 = this.m[2];
  8475. var l3 = this.m[3];
  8476. var l4 = this.m[4];
  8477. var l5 = this.m[5];
  8478. var r0 = other.m[0];
  8479. var r1 = other.m[1];
  8480. var r2 = other.m[2];
  8481. var r3 = other.m[3];
  8482. var r4 = other.m[4];
  8483. var r5 = other.m[5];
  8484. result.m[0] = l0 * r0 + l1 * r2;
  8485. result.m[1] = l0 * r1 + l1 * r3;
  8486. result.m[2] = l2 * r0 + l3 * r2;
  8487. result.m[3] = l2 * r1 + l3 * r3;
  8488. result.m[4] = l4 * r0 + l5 * r2 + r4;
  8489. result.m[5] = l4 * r1 + l5 * r3 + r5;
  8490. return this;
  8491. };
  8492. /**
  8493. * Applies the current matrix to a set of 2 floats and stores the result in a vector2
  8494. * @param x defines the x coordinate to transform
  8495. * @param y defines the x coordinate to transform
  8496. * @param result defines the target vector2
  8497. * @returns the current matrix
  8498. */
  8499. Matrix2D.prototype.transformCoordinates = function (x, y, result) {
  8500. result.x = x * this.m[0] + y * this.m[2] + this.m[4];
  8501. result.y = x * this.m[1] + y * this.m[3] + this.m[5];
  8502. return this;
  8503. };
  8504. // Statics
  8505. /**
  8506. * Creates an identity matrix
  8507. * @returns a new matrix
  8508. */
  8509. Matrix2D.Identity = function () {
  8510. return new Matrix2D(1, 0, 0, 1, 0, 0);
  8511. };
  8512. /**
  8513. * Creates a translation matrix and stores it in a target matrix
  8514. * @param x defines the x coordinate of the translation
  8515. * @param y defines the y coordinate of the translation
  8516. * @param result defines the target matrix
  8517. */
  8518. Matrix2D.TranslationToRef = function (x, y, result) {
  8519. result.fromValues(1, 0, 0, 1, x, y);
  8520. };
  8521. /**
  8522. * Creates a scaling matrix and stores it in a target matrix
  8523. * @param x defines the x coordinate of the scaling
  8524. * @param y defines the y coordinate of the scaling
  8525. * @param result defines the target matrix
  8526. */
  8527. Matrix2D.ScalingToRef = function (x, y, result) {
  8528. result.fromValues(x, 0, 0, y, 0, 0);
  8529. };
  8530. /**
  8531. * Creates a rotation matrix and stores it in a target matrix
  8532. * @param angle defines the rotation angle
  8533. * @param result defines the target matrix
  8534. */
  8535. Matrix2D.RotationToRef = function (angle, result) {
  8536. var s = Math.sin(angle);
  8537. var c = Math.cos(angle);
  8538. result.fromValues(c, s, -s, c, 0, 0);
  8539. };
  8540. /**
  8541. * Composes a matrix from translation, rotation, scaling and parent matrix and stores it in a target matrix
  8542. * @param tx defines the x coordinate of the translation
  8543. * @param ty defines the y coordinate of the translation
  8544. * @param angle defines the rotation angle
  8545. * @param scaleX defines the x coordinate of the scaling
  8546. * @param scaleY defines the y coordinate of the scaling
  8547. * @param parentMatrix defines the parent matrix to multiply by (can be null)
  8548. * @param result defines the target matrix
  8549. */
  8550. Matrix2D.ComposeToRef = function (tx, ty, angle, scaleX, scaleY, parentMatrix, result) {
  8551. Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
  8552. Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);
  8553. Matrix2D.RotationToRef(angle, Matrix2D._TempRotationMatrix);
  8554. Matrix2D.TranslationToRef(-tx, -ty, Matrix2D._TempPostTranslationMatrix);
  8555. Matrix2D._TempPreTranslationMatrix.multiplyToRef(Matrix2D._TempScalingMatrix, Matrix2D._TempCompose0);
  8556. Matrix2D._TempCompose0.multiplyToRef(Matrix2D._TempRotationMatrix, Matrix2D._TempCompose1);
  8557. if (parentMatrix) {
  8558. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, Matrix2D._TempCompose2);
  8559. Matrix2D._TempCompose2.multiplyToRef(parentMatrix, result);
  8560. }
  8561. else {
  8562. Matrix2D._TempCompose1.multiplyToRef(Matrix2D._TempPostTranslationMatrix, result);
  8563. }
  8564. };
  8565. Matrix2D._TempPreTranslationMatrix = Matrix2D.Identity();
  8566. Matrix2D._TempPostTranslationMatrix = Matrix2D.Identity();
  8567. Matrix2D._TempRotationMatrix = Matrix2D.Identity();
  8568. Matrix2D._TempScalingMatrix = Matrix2D.Identity();
  8569. Matrix2D._TempCompose0 = Matrix2D.Identity();
  8570. Matrix2D._TempCompose1 = Matrix2D.Identity();
  8571. Matrix2D._TempCompose2 = Matrix2D.Identity();
  8572. return Matrix2D;
  8573. }());
  8574. exports.Matrix2D = Matrix2D;
  8575. /***/ }),
  8576. /***/ "./src/2D/measure.ts":
  8577. /*!***************************!*\
  8578. !*** ./src/2D/measure.ts ***!
  8579. \***************************/
  8580. /*! no static exports found */
  8581. /***/ (function(module, exports, __webpack_require__) {
  8582. "use strict";
  8583. Object.defineProperty(exports, "__esModule", { value: true });
  8584. /**
  8585. * Class used to store 2D control sizes
  8586. */
  8587. var Measure = /** @class */ (function () {
  8588. /**
  8589. * Creates a new measure
  8590. * @param left defines left coordinate
  8591. * @param top defines top coordinate
  8592. * @param width defines width dimension
  8593. * @param height defines height dimension
  8594. */
  8595. function Measure(
  8596. /** defines left coordinate */
  8597. left,
  8598. /** defines top coordinate */
  8599. top,
  8600. /** defines width dimension */
  8601. width,
  8602. /** defines height dimension */
  8603. height) {
  8604. this.left = left;
  8605. this.top = top;
  8606. this.width = width;
  8607. this.height = height;
  8608. }
  8609. /**
  8610. * Copy from another measure
  8611. * @param other defines the other measure to copy from
  8612. */
  8613. Measure.prototype.copyFrom = function (other) {
  8614. this.left = other.left;
  8615. this.top = other.top;
  8616. this.width = other.width;
  8617. this.height = other.height;
  8618. };
  8619. /**
  8620. * Copy from a group of 4 floats
  8621. * @param left defines left coordinate
  8622. * @param top defines top coordinate
  8623. * @param width defines width dimension
  8624. * @param height defines height dimension
  8625. */
  8626. Measure.prototype.copyFromFloats = function (left, top, width, height) {
  8627. this.left = left;
  8628. this.top = top;
  8629. this.width = width;
  8630. this.height = height;
  8631. };
  8632. /**
  8633. * Check equality between this measure and another one
  8634. * @param other defines the other measures
  8635. * @returns true if both measures are equals
  8636. */
  8637. Measure.prototype.isEqualsTo = function (other) {
  8638. if (this.left !== other.left) {
  8639. return false;
  8640. }
  8641. if (this.top !== other.top) {
  8642. return false;
  8643. }
  8644. if (this.width !== other.width) {
  8645. return false;
  8646. }
  8647. if (this.height !== other.height) {
  8648. return false;
  8649. }
  8650. return true;
  8651. };
  8652. /**
  8653. * Creates an empty measure
  8654. * @returns a new measure
  8655. */
  8656. Measure.Empty = function () {
  8657. return new Measure(0, 0, 0, 0);
  8658. };
  8659. return Measure;
  8660. }());
  8661. exports.Measure = Measure;
  8662. /***/ }),
  8663. /***/ "./src/2D/multiLinePoint.ts":
  8664. /*!**********************************!*\
  8665. !*** ./src/2D/multiLinePoint.ts ***!
  8666. \**********************************/
  8667. /*! no static exports found */
  8668. /***/ (function(module, exports, __webpack_require__) {
  8669. "use strict";
  8670. Object.defineProperty(exports, "__esModule", { value: true });
  8671. var valueAndUnit_1 = __webpack_require__(/*! ./valueAndUnit */ "./src/2D/valueAndUnit.ts");
  8672. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8673. /**
  8674. * Class used to store a point for a MultiLine object.
  8675. * The point can be pure 2D coordinates, a mesh or a control
  8676. */
  8677. var MultiLinePoint = /** @class */ (function () {
  8678. /**
  8679. * Creates a new MultiLinePoint
  8680. * @param multiLine defines the source MultiLine object
  8681. */
  8682. function MultiLinePoint(multiLine) {
  8683. this._multiLine = multiLine;
  8684. this._x = new valueAndUnit_1.ValueAndUnit(0);
  8685. this._y = new valueAndUnit_1.ValueAndUnit(0);
  8686. this._point = new babylonjs_1.Vector2(0, 0);
  8687. }
  8688. Object.defineProperty(MultiLinePoint.prototype, "x", {
  8689. /** Gets or sets x coordinate */
  8690. get: function () {
  8691. return this._x.toString(this._multiLine._host);
  8692. },
  8693. set: function (value) {
  8694. if (this._x.toString(this._multiLine._host) === value) {
  8695. return;
  8696. }
  8697. if (this._x.fromString(value)) {
  8698. this._multiLine._markAsDirty();
  8699. }
  8700. },
  8701. enumerable: true,
  8702. configurable: true
  8703. });
  8704. Object.defineProperty(MultiLinePoint.prototype, "y", {
  8705. /** Gets or sets y coordinate */
  8706. get: function () {
  8707. return this._y.toString(this._multiLine._host);
  8708. },
  8709. set: function (value) {
  8710. if (this._y.toString(this._multiLine._host) === value) {
  8711. return;
  8712. }
  8713. if (this._y.fromString(value)) {
  8714. this._multiLine._markAsDirty();
  8715. }
  8716. },
  8717. enumerable: true,
  8718. configurable: true
  8719. });
  8720. Object.defineProperty(MultiLinePoint.prototype, "control", {
  8721. /** Gets or sets the control associated with this point */
  8722. get: function () {
  8723. return this._control;
  8724. },
  8725. set: function (value) {
  8726. if (this._control === value) {
  8727. return;
  8728. }
  8729. if (this._control && this._controlObserver) {
  8730. this._control.onDirtyObservable.remove(this._controlObserver);
  8731. this._controlObserver = null;
  8732. }
  8733. this._control = value;
  8734. if (this._control) {
  8735. this._controlObserver = this._control.onDirtyObservable.add(this._multiLine.onPointUpdate);
  8736. }
  8737. this._multiLine._markAsDirty();
  8738. },
  8739. enumerable: true,
  8740. configurable: true
  8741. });
  8742. Object.defineProperty(MultiLinePoint.prototype, "mesh", {
  8743. /** Gets or sets the mesh associated with this point */
  8744. get: function () {
  8745. return this._mesh;
  8746. },
  8747. set: function (value) {
  8748. if (this._mesh === value) {
  8749. return;
  8750. }
  8751. if (this._mesh && this._meshObserver) {
  8752. this._mesh.getScene().onAfterCameraRenderObservable.remove(this._meshObserver);
  8753. }
  8754. this._mesh = value;
  8755. if (this._mesh) {
  8756. this._meshObserver = this._mesh.getScene().onAfterCameraRenderObservable.add(this._multiLine.onPointUpdate);
  8757. }
  8758. this._multiLine._markAsDirty();
  8759. },
  8760. enumerable: true,
  8761. configurable: true
  8762. });
  8763. /** Resets links */
  8764. MultiLinePoint.prototype.resetLinks = function () {
  8765. this.control = null;
  8766. this.mesh = null;
  8767. };
  8768. /**
  8769. * Gets a translation vector
  8770. * @returns the translation vector
  8771. */
  8772. MultiLinePoint.prototype.translate = function () {
  8773. this._point = this._translatePoint();
  8774. return this._point;
  8775. };
  8776. MultiLinePoint.prototype._translatePoint = function () {
  8777. if (this._mesh != null) {
  8778. return this._multiLine._host.getProjectedPosition(this._mesh.getBoundingInfo().boundingSphere.center, this._mesh.getWorldMatrix());
  8779. }
  8780. else if (this._control != null) {
  8781. return new babylonjs_1.Vector2(this._control.centerX, this._control.centerY);
  8782. }
  8783. else {
  8784. var host = this._multiLine._host;
  8785. var xValue = this._x.getValueInPixel(host, Number(host._canvas.width));
  8786. var yValue = this._y.getValueInPixel(host, Number(host._canvas.height));
  8787. return new babylonjs_1.Vector2(xValue, yValue);
  8788. }
  8789. };
  8790. /** Release associated resources */
  8791. MultiLinePoint.prototype.dispose = function () {
  8792. this.resetLinks();
  8793. };
  8794. return MultiLinePoint;
  8795. }());
  8796. exports.MultiLinePoint = MultiLinePoint;
  8797. /***/ }),
  8798. /***/ "./src/2D/style.ts":
  8799. /*!*************************!*\
  8800. !*** ./src/2D/style.ts ***!
  8801. \*************************/
  8802. /*! no static exports found */
  8803. /***/ (function(module, exports, __webpack_require__) {
  8804. "use strict";
  8805. Object.defineProperty(exports, "__esModule", { value: true });
  8806. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  8807. var valueAndUnit_1 = __webpack_require__(/*! ./valueAndUnit */ "./src/2D/valueAndUnit.ts");
  8808. /**
  8809. * Define a style used by control to automatically setup properties based on a template.
  8810. * Only support font related properties so far
  8811. */
  8812. var Style = /** @class */ (function () {
  8813. /**
  8814. * Creates a new style object
  8815. * @param host defines the AdvancedDynamicTexture which hosts this style
  8816. */
  8817. function Style(host) {
  8818. this._fontFamily = "Arial";
  8819. this._fontStyle = "";
  8820. this._fontWeight = "";
  8821. /** @hidden */
  8822. this._fontSize = new valueAndUnit_1.ValueAndUnit(18, valueAndUnit_1.ValueAndUnit.UNITMODE_PIXEL, false);
  8823. /**
  8824. * Observable raised when the style values are changed
  8825. */
  8826. this.onChangedObservable = new babylonjs_1.Observable();
  8827. this._host = host;
  8828. }
  8829. Object.defineProperty(Style.prototype, "fontSize", {
  8830. /**
  8831. * Gets or sets the font size
  8832. */
  8833. get: function () {
  8834. return this._fontSize.toString(this._host);
  8835. },
  8836. set: function (value) {
  8837. if (this._fontSize.toString(this._host) === value) {
  8838. return;
  8839. }
  8840. if (this._fontSize.fromString(value)) {
  8841. this.onChangedObservable.notifyObservers(this);
  8842. }
  8843. },
  8844. enumerable: true,
  8845. configurable: true
  8846. });
  8847. Object.defineProperty(Style.prototype, "fontFamily", {
  8848. /**
  8849. * Gets or sets the font family
  8850. */
  8851. get: function () {
  8852. return this._fontFamily;
  8853. },
  8854. set: function (value) {
  8855. if (this._fontFamily === value) {
  8856. return;
  8857. }
  8858. this._fontFamily = value;
  8859. this.onChangedObservable.notifyObservers(this);
  8860. },
  8861. enumerable: true,
  8862. configurable: true
  8863. });
  8864. Object.defineProperty(Style.prototype, "fontStyle", {
  8865. /**
  8866. * Gets or sets the font style
  8867. */
  8868. get: function () {
  8869. return this._fontStyle;
  8870. },
  8871. set: function (value) {
  8872. if (this._fontStyle === value) {
  8873. return;
  8874. }
  8875. this._fontStyle = value;
  8876. this.onChangedObservable.notifyObservers(this);
  8877. },
  8878. enumerable: true,
  8879. configurable: true
  8880. });
  8881. Object.defineProperty(Style.prototype, "fontWeight", {
  8882. /** Gets or sets font weight */
  8883. get: function () {
  8884. return this._fontWeight;
  8885. },
  8886. set: function (value) {
  8887. if (this._fontWeight === value) {
  8888. return;
  8889. }
  8890. this._fontWeight = value;
  8891. this.onChangedObservable.notifyObservers(this);
  8892. },
  8893. enumerable: true,
  8894. configurable: true
  8895. });
  8896. /** Dispose all associated resources */
  8897. Style.prototype.dispose = function () {
  8898. this.onChangedObservable.clear();
  8899. };
  8900. return Style;
  8901. }());
  8902. exports.Style = Style;
  8903. /***/ }),
  8904. /***/ "./src/2D/valueAndUnit.ts":
  8905. /*!********************************!*\
  8906. !*** ./src/2D/valueAndUnit.ts ***!
  8907. \********************************/
  8908. /*! no static exports found */
  8909. /***/ (function(module, exports, __webpack_require__) {
  8910. "use strict";
  8911. Object.defineProperty(exports, "__esModule", { value: true });
  8912. /**
  8913. * Class used to specific a value and its associated unit
  8914. */
  8915. var ValueAndUnit = /** @class */ (function () {
  8916. /**
  8917. * Creates a new ValueAndUnit
  8918. * @param value defines the value to store
  8919. * @param unit defines the unit to store
  8920. * @param negativeValueAllowed defines a boolean indicating if the value can be negative
  8921. */
  8922. function ValueAndUnit(value,
  8923. /** defines the unit to store */
  8924. unit,
  8925. /** defines a boolean indicating if the value can be negative */
  8926. negativeValueAllowed) {
  8927. if (unit === void 0) { unit = ValueAndUnit.UNITMODE_PIXEL; }
  8928. if (negativeValueAllowed === void 0) { negativeValueAllowed = true; }
  8929. this.unit = unit;
  8930. this.negativeValueAllowed = negativeValueAllowed;
  8931. this._value = 1;
  8932. /**
  8933. * Gets or sets a value indicating that this value will not scale accordingly with adaptive scaling property
  8934. * @see http://doc.babylonjs.com/how_to/gui#adaptive-scaling
  8935. */
  8936. this.ignoreAdaptiveScaling = false;
  8937. this._value = value;
  8938. }
  8939. Object.defineProperty(ValueAndUnit.prototype, "isPercentage", {
  8940. /** Gets a boolean indicating if the value is a percentage */
  8941. get: function () {
  8942. return this.unit === ValueAndUnit.UNITMODE_PERCENTAGE;
  8943. },
  8944. enumerable: true,
  8945. configurable: true
  8946. });
  8947. Object.defineProperty(ValueAndUnit.prototype, "isPixel", {
  8948. /** Gets a boolean indicating if the value is store as pixel */
  8949. get: function () {
  8950. return this.unit === ValueAndUnit.UNITMODE_PIXEL;
  8951. },
  8952. enumerable: true,
  8953. configurable: true
  8954. });
  8955. Object.defineProperty(ValueAndUnit.prototype, "internalValue", {
  8956. /** Gets direct internal value */
  8957. get: function () {
  8958. return this._value;
  8959. },
  8960. enumerable: true,
  8961. configurable: true
  8962. });
  8963. /**
  8964. * Gets value as pixel
  8965. * @param host defines the root host
  8966. * @param refValue defines the reference value for percentages
  8967. * @returns the value as pixel
  8968. */
  8969. ValueAndUnit.prototype.getValueInPixel = function (host, refValue) {
  8970. if (this.isPixel) {
  8971. return this.getValue(host);
  8972. }
  8973. return this.getValue(host) * refValue;
  8974. };
  8975. /**
  8976. * Gets the value accordingly to its unit
  8977. * @param host defines the root host
  8978. * @returns the value
  8979. */
  8980. ValueAndUnit.prototype.getValue = function (host) {
  8981. if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
  8982. var width = 0;
  8983. var height = 0;
  8984. if (host.idealWidth) {
  8985. width = (this._value * host.getSize().width) / host.idealWidth;
  8986. }
  8987. if (host.idealHeight) {
  8988. height = (this._value * host.getSize().height) / host.idealHeight;
  8989. }
  8990. if (host.useSmallestIdeal && host.idealWidth && host.idealHeight) {
  8991. return window.innerWidth < window.innerHeight ? width : height;
  8992. }
  8993. if (host.idealWidth) { // horizontal
  8994. return width;
  8995. }
  8996. if (host.idealHeight) { // vertical
  8997. return height;
  8998. }
  8999. }
  9000. return this._value;
  9001. };
  9002. /**
  9003. * Gets a string representation of the value
  9004. * @param host defines the root host
  9005. * @returns a string
  9006. */
  9007. ValueAndUnit.prototype.toString = function (host) {
  9008. switch (this.unit) {
  9009. case ValueAndUnit.UNITMODE_PERCENTAGE:
  9010. return (this.getValue(host) * 100) + "%";
  9011. case ValueAndUnit.UNITMODE_PIXEL:
  9012. return this.getValue(host) + "px";
  9013. }
  9014. return this.unit.toString();
  9015. };
  9016. /**
  9017. * Store a value parsed from a string
  9018. * @param source defines the source string
  9019. * @returns true if the value was successfully parsed
  9020. */
  9021. ValueAndUnit.prototype.fromString = function (source) {
  9022. var match = ValueAndUnit._Regex.exec(source.toString());
  9023. if (!match || match.length === 0) {
  9024. return false;
  9025. }
  9026. var sourceValue = parseFloat(match[1]);
  9027. var sourceUnit = this.unit;
  9028. if (!this.negativeValueAllowed) {
  9029. if (sourceValue < 0) {
  9030. sourceValue = 0;
  9031. }
  9032. }
  9033. if (match.length === 4) {
  9034. switch (match[3]) {
  9035. case "px":
  9036. sourceUnit = ValueAndUnit.UNITMODE_PIXEL;
  9037. break;
  9038. case "%":
  9039. sourceUnit = ValueAndUnit.UNITMODE_PERCENTAGE;
  9040. sourceValue /= 100.0;
  9041. break;
  9042. }
  9043. }
  9044. if (sourceValue === this._value && sourceUnit === this.unit) {
  9045. return false;
  9046. }
  9047. this._value = sourceValue;
  9048. this.unit = sourceUnit;
  9049. return true;
  9050. };
  9051. Object.defineProperty(ValueAndUnit, "UNITMODE_PERCENTAGE", {
  9052. /** UNITMODE_PERCENTAGE */
  9053. get: function () {
  9054. return ValueAndUnit._UNITMODE_PERCENTAGE;
  9055. },
  9056. enumerable: true,
  9057. configurable: true
  9058. });
  9059. Object.defineProperty(ValueAndUnit, "UNITMODE_PIXEL", {
  9060. /** UNITMODE_PIXEL */
  9061. get: function () {
  9062. return ValueAndUnit._UNITMODE_PIXEL;
  9063. },
  9064. enumerable: true,
  9065. configurable: true
  9066. });
  9067. // Static
  9068. ValueAndUnit._Regex = /(^-?\d*(\.\d+)?)(%|px)?/;
  9069. ValueAndUnit._UNITMODE_PERCENTAGE = 0;
  9070. ValueAndUnit._UNITMODE_PIXEL = 1;
  9071. return ValueAndUnit;
  9072. }());
  9073. exports.ValueAndUnit = ValueAndUnit;
  9074. /***/ }),
  9075. /***/ "./src/3D/controls/abstractButton3D.ts":
  9076. /*!*********************************************!*\
  9077. !*** ./src/3D/controls/abstractButton3D.ts ***!
  9078. \*********************************************/
  9079. /*! no static exports found */
  9080. /***/ (function(module, exports, __webpack_require__) {
  9081. "use strict";
  9082. var __extends = (this && this.__extends) || (function () {
  9083. var extendStatics = function (d, b) {
  9084. extendStatics = Object.setPrototypeOf ||
  9085. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9086. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  9087. return extendStatics(d, b);
  9088. }
  9089. return function (d, b) {
  9090. extendStatics(d, b);
  9091. function __() { this.constructor = d; }
  9092. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9093. };
  9094. })();
  9095. Object.defineProperty(exports, "__esModule", { value: true });
  9096. var control3D_1 = __webpack_require__(/*! ./control3D */ "./src/3D/controls/control3D.ts");
  9097. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  9098. /**
  9099. * Class used as a root to all buttons
  9100. */
  9101. var AbstractButton3D = /** @class */ (function (_super) {
  9102. __extends(AbstractButton3D, _super);
  9103. /**
  9104. * Creates a new button
  9105. * @param name defines the control name
  9106. */
  9107. function AbstractButton3D(name) {
  9108. return _super.call(this, name) || this;
  9109. }
  9110. AbstractButton3D.prototype._getTypeName = function () {
  9111. return "AbstractButton3D";
  9112. };
  9113. // Mesh association
  9114. AbstractButton3D.prototype._createNode = function (scene) {
  9115. return new babylonjs_1.TransformNode("button" + this.name);
  9116. };
  9117. return AbstractButton3D;
  9118. }(control3D_1.Control3D));
  9119. exports.AbstractButton3D = AbstractButton3D;
  9120. /***/ }),
  9121. /***/ "./src/3D/controls/button3D.ts":
  9122. /*!*************************************!*\
  9123. !*** ./src/3D/controls/button3D.ts ***!
  9124. \*************************************/
  9125. /*! no static exports found */
  9126. /***/ (function(module, exports, __webpack_require__) {
  9127. "use strict";
  9128. var __extends = (this && this.__extends) || (function () {
  9129. var extendStatics = function (d, b) {
  9130. extendStatics = Object.setPrototypeOf ||
  9131. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9132. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  9133. return extendStatics(d, b);
  9134. }
  9135. return function (d, b) {
  9136. extendStatics(d, b);
  9137. function __() { this.constructor = d; }
  9138. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9139. };
  9140. })();
  9141. Object.defineProperty(exports, "__esModule", { value: true });
  9142. var abstractButton3D_1 = __webpack_require__(/*! ./abstractButton3D */ "./src/3D/controls/abstractButton3D.ts");
  9143. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  9144. var advancedDynamicTexture_1 = __webpack_require__(/*! ../../2D/advancedDynamicTexture */ "./src/2D/advancedDynamicTexture.ts");
  9145. /**
  9146. * Class used to create a button in 3D
  9147. */
  9148. var Button3D = /** @class */ (function (_super) {
  9149. __extends(Button3D, _super);
  9150. /**
  9151. * Creates a new button
  9152. * @param name defines the control name
  9153. */
  9154. function Button3D(name) {
  9155. var _this = _super.call(this, name) || this;
  9156. _this._contentResolution = 512;
  9157. _this._contentScaleRatio = 2;
  9158. // Default animations
  9159. _this.pointerEnterAnimation = function () {
  9160. if (!_this.mesh) {
  9161. return;
  9162. }
  9163. _this._currentMaterial.emissiveColor = babylonjs_1.Color3.Red();
  9164. };
  9165. _this.pointerOutAnimation = function () {
  9166. _this._currentMaterial.emissiveColor = babylonjs_1.Color3.Black();
  9167. };
  9168. _this.pointerDownAnimation = function () {
  9169. if (!_this.mesh) {
  9170. return;
  9171. }
  9172. _this.mesh.scaling.scaleInPlace(0.95);
  9173. };
  9174. _this.pointerUpAnimation = function () {
  9175. if (!_this.mesh) {
  9176. return;
  9177. }
  9178. _this.mesh.scaling.scaleInPlace(1.0 / 0.95);
  9179. };
  9180. return _this;
  9181. }
  9182. Object.defineProperty(Button3D.prototype, "contentResolution", {
  9183. /**
  9184. * Gets or sets the texture resolution used to render content (512 by default)
  9185. */
  9186. get: function () {
  9187. return this._contentResolution;
  9188. },
  9189. set: function (value) {
  9190. if (this._contentResolution === value) {
  9191. return;
  9192. }
  9193. this._contentResolution = value;
  9194. this._resetContent();
  9195. },
  9196. enumerable: true,
  9197. configurable: true
  9198. });
  9199. Object.defineProperty(Button3D.prototype, "contentScaleRatio", {
  9200. /**
  9201. * Gets or sets the texture scale ratio used to render content (2 by default)
  9202. */
  9203. get: function () {
  9204. return this._contentScaleRatio;
  9205. },
  9206. set: function (value) {
  9207. if (this._contentScaleRatio === value) {
  9208. return;
  9209. }
  9210. this._contentScaleRatio = value;
  9211. this._resetContent();
  9212. },
  9213. enumerable: true,
  9214. configurable: true
  9215. });
  9216. Button3D.prototype._disposeFacadeTexture = function () {
  9217. if (this._facadeTexture) {
  9218. this._facadeTexture.dispose();
  9219. this._facadeTexture = null;
  9220. }
  9221. };
  9222. Button3D.prototype._resetContent = function () {
  9223. this._disposeFacadeTexture();
  9224. this.content = this._content;
  9225. };
  9226. Object.defineProperty(Button3D.prototype, "content", {
  9227. /**
  9228. * Gets or sets the GUI 2D content used to display the button's facade
  9229. */
  9230. get: function () {
  9231. return this._content;
  9232. },
  9233. set: function (value) {
  9234. this._content = value;
  9235. if (!this._host || !this._host.utilityLayer) {
  9236. return;
  9237. }
  9238. if (!this._facadeTexture) {
  9239. this._facadeTexture = new advancedDynamicTexture_1.AdvancedDynamicTexture("Facade", this._contentResolution, this._contentResolution, this._host.utilityLayer.utilityLayerScene, true, babylonjs_1.Texture.TRILINEAR_SAMPLINGMODE);
  9240. this._facadeTexture.rootContainer.scaleX = this._contentScaleRatio;
  9241. this._facadeTexture.rootContainer.scaleY = this._contentScaleRatio;
  9242. this._facadeTexture.premulAlpha = true;
  9243. }
  9244. this._facadeTexture.addControl(value);
  9245. this._applyFacade(this._facadeTexture);
  9246. },
  9247. enumerable: true,
  9248. configurable: true
  9249. });
  9250. /**
  9251. * Apply the facade texture (created from the content property).
  9252. * This function can be overloaded by child classes
  9253. * @param facadeTexture defines the AdvancedDynamicTexture to use
  9254. */
  9255. Button3D.prototype._applyFacade = function (facadeTexture) {
  9256. this._currentMaterial.emissiveTexture = facadeTexture;
  9257. };
  9258. Button3D.prototype._getTypeName = function () {
  9259. return "Button3D";
  9260. };
  9261. // Mesh association
  9262. Button3D.prototype._createNode = function (scene) {
  9263. var faceUV = new Array(6);
  9264. for (var i = 0; i < 6; i++) {
  9265. faceUV[i] = new babylonjs_1.Vector4(0, 0, 0, 0);
  9266. }
  9267. faceUV[1] = new babylonjs_1.Vector4(0, 0, 1, 1);
  9268. var mesh = babylonjs_1.MeshBuilder.CreateBox(this.name + "_rootMesh", {
  9269. width: 1.0,
  9270. height: 1.0,
  9271. depth: 0.08,
  9272. faceUV: faceUV
  9273. }, scene);
  9274. return mesh;
  9275. };
  9276. Button3D.prototype._affectMaterial = function (mesh) {
  9277. var material = new babylonjs_1.StandardMaterial(this.name + "Material", mesh.getScene());
  9278. material.specularColor = babylonjs_1.Color3.Black();
  9279. mesh.material = material;
  9280. this._currentMaterial = material;
  9281. this._resetContent();
  9282. };
  9283. /**
  9284. * Releases all associated resources
  9285. */
  9286. Button3D.prototype.dispose = function () {
  9287. _super.prototype.dispose.call(this);
  9288. this._disposeFacadeTexture();
  9289. if (this._currentMaterial) {
  9290. this._currentMaterial.dispose();
  9291. }
  9292. };
  9293. return Button3D;
  9294. }(abstractButton3D_1.AbstractButton3D));
  9295. exports.Button3D = Button3D;
  9296. /***/ }),
  9297. /***/ "./src/3D/controls/container3D.ts":
  9298. /*!****************************************!*\
  9299. !*** ./src/3D/controls/container3D.ts ***!
  9300. \****************************************/
  9301. /*! no static exports found */
  9302. /***/ (function(module, exports, __webpack_require__) {
  9303. "use strict";
  9304. var __extends = (this && this.__extends) || (function () {
  9305. var extendStatics = function (d, b) {
  9306. extendStatics = Object.setPrototypeOf ||
  9307. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9308. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  9309. return extendStatics(d, b);
  9310. }
  9311. return function (d, b) {
  9312. extendStatics(d, b);
  9313. function __() { this.constructor = d; }
  9314. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9315. };
  9316. })();
  9317. Object.defineProperty(exports, "__esModule", { value: true });
  9318. var control3D_1 = __webpack_require__(/*! ./control3D */ "./src/3D/controls/control3D.ts");
  9319. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  9320. /**
  9321. * Class used to create containers for controls
  9322. */
  9323. var Container3D = /** @class */ (function (_super) {
  9324. __extends(Container3D, _super);
  9325. /**
  9326. * Creates a new container
  9327. * @param name defines the container name
  9328. */
  9329. function Container3D(name) {
  9330. var _this = _super.call(this, name) || this;
  9331. _this._blockLayout = false;
  9332. /**
  9333. * Gets the list of child controls
  9334. */
  9335. _this._children = new Array();
  9336. return _this;
  9337. }
  9338. Object.defineProperty(Container3D.prototype, "children", {
  9339. /**
  9340. * Gets the list of child controls
  9341. */
  9342. get: function () {
  9343. return this._children;
  9344. },
  9345. enumerable: true,
  9346. configurable: true
  9347. });
  9348. Object.defineProperty(Container3D.prototype, "blockLayout", {
  9349. /**
  9350. * Gets or sets a boolean indicating if the layout must be blocked (default is false).
  9351. * This is helpful to optimize layout operation when adding multiple children in a row
  9352. */
  9353. get: function () {
  9354. return this._blockLayout;
  9355. },
  9356. set: function (value) {
  9357. if (this._blockLayout === value) {
  9358. return;
  9359. }
  9360. this._blockLayout = value;
  9361. if (!this._blockLayout) {
  9362. this._arrangeChildren();
  9363. }
  9364. },
  9365. enumerable: true,
  9366. configurable: true
  9367. });
  9368. /**
  9369. * Force the container to update the layout. Please note that it will not take blockLayout property in account
  9370. * @returns the current container
  9371. */
  9372. Container3D.prototype.updateLayout = function () {
  9373. this._arrangeChildren();
  9374. return this;
  9375. };
  9376. /**
  9377. * Gets a boolean indicating if the given control is in the children of this control
  9378. * @param control defines the control to check
  9379. * @returns true if the control is in the child list
  9380. */
  9381. Container3D.prototype.containsControl = function (control) {
  9382. return this._children.indexOf(control) !== -1;
  9383. };
  9384. /**
  9385. * Adds a control to the children of this control
  9386. * @param control defines the control to add
  9387. * @returns the current container
  9388. */
  9389. Container3D.prototype.addControl = function (control) {
  9390. var index = this._children.indexOf(control);
  9391. if (index !== -1) {
  9392. return this;
  9393. }
  9394. control.parent = this;
  9395. control._host = this._host;
  9396. this._children.push(control);
  9397. if (this._host.utilityLayer) {
  9398. control._prepareNode(this._host.utilityLayer.utilityLayerScene);
  9399. if (control.node) {
  9400. control.node.parent = this.node;
  9401. }
  9402. if (!this.blockLayout) {
  9403. this._arrangeChildren();
  9404. }
  9405. }
  9406. return this;
  9407. };
  9408. /**
  9409. * This function will be called everytime a new control is added
  9410. */
  9411. Container3D.prototype._arrangeChildren = function () {
  9412. };
  9413. Container3D.prototype._createNode = function (scene) {
  9414. return new babylonjs_1.TransformNode("ContainerNode", scene);
  9415. };
  9416. /**
  9417. * Removes a control from the children of this control
  9418. * @param control defines the control to remove
  9419. * @returns the current container
  9420. */
  9421. Container3D.prototype.removeControl = function (control) {
  9422. var index = this._children.indexOf(control);
  9423. if (index !== -1) {
  9424. this._children.splice(index, 1);
  9425. control.parent = null;
  9426. control._disposeNode();
  9427. }
  9428. return this;
  9429. };
  9430. Container3D.prototype._getTypeName = function () {
  9431. return "Container3D";
  9432. };
  9433. /**
  9434. * Releases all associated resources
  9435. */
  9436. Container3D.prototype.dispose = function () {
  9437. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  9438. var control = _a[_i];
  9439. control.dispose();
  9440. }
  9441. this._children = [];
  9442. _super.prototype.dispose.call(this);
  9443. };
  9444. /** Control rotation will remain unchanged */
  9445. Container3D.UNSET_ORIENTATION = 0;
  9446. /** Control will rotate to make it look at sphere central axis */
  9447. Container3D.FACEORIGIN_ORIENTATION = 1;
  9448. /** Control will rotate to make it look back at sphere central axis */
  9449. Container3D.FACEORIGINREVERSED_ORIENTATION = 2;
  9450. /** Control will rotate to look at z axis (0, 0, 1) */
  9451. Container3D.FACEFORWARD_ORIENTATION = 3;
  9452. /** Control will rotate to look at negative z axis (0, 0, -1) */
  9453. Container3D.FACEFORWARDREVERSED_ORIENTATION = 4;
  9454. return Container3D;
  9455. }(control3D_1.Control3D));
  9456. exports.Container3D = Container3D;
  9457. /***/ }),
  9458. /***/ "./src/3D/controls/control3D.ts":
  9459. /*!**************************************!*\
  9460. !*** ./src/3D/controls/control3D.ts ***!
  9461. \**************************************/
  9462. /*! no static exports found */
  9463. /***/ (function(module, exports, __webpack_require__) {
  9464. "use strict";
  9465. Object.defineProperty(exports, "__esModule", { value: true });
  9466. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  9467. var vector3WithInfo_1 = __webpack_require__(/*! ../vector3WithInfo */ "./src/3D/vector3WithInfo.ts");
  9468. /**
  9469. * Class used as base class for controls
  9470. */
  9471. var Control3D = /** @class */ (function () {
  9472. /**
  9473. * Creates a new control
  9474. * @param name defines the control name
  9475. */
  9476. function Control3D(
  9477. /** Defines the control name */
  9478. name) {
  9479. this.name = name;
  9480. this._downCount = 0;
  9481. this._enterCount = -1;
  9482. this._downPointerIds = {};
  9483. this._isVisible = true;
  9484. /**
  9485. * An event triggered when the pointer move over the control
  9486. */
  9487. this.onPointerMoveObservable = new babylonjs_1.Observable();
  9488. /**
  9489. * An event triggered when the pointer move out of the control
  9490. */
  9491. this.onPointerOutObservable = new babylonjs_1.Observable();
  9492. /**
  9493. * An event triggered when the pointer taps the control
  9494. */
  9495. this.onPointerDownObservable = new babylonjs_1.Observable();
  9496. /**
  9497. * An event triggered when pointer is up
  9498. */
  9499. this.onPointerUpObservable = new babylonjs_1.Observable();
  9500. /**
  9501. * An event triggered when a control is clicked on (with a mouse)
  9502. */
  9503. this.onPointerClickObservable = new babylonjs_1.Observable();
  9504. /**
  9505. * An event triggered when pointer enters the control
  9506. */
  9507. this.onPointerEnterObservable = new babylonjs_1.Observable();
  9508. // Behaviors
  9509. this._behaviors = new Array();
  9510. }
  9511. Object.defineProperty(Control3D.prototype, "position", {
  9512. /** Gets or sets the control position in world space */
  9513. get: function () {
  9514. if (!this._node) {
  9515. return babylonjs_1.Vector3.Zero();
  9516. }
  9517. return this._node.position;
  9518. },
  9519. set: function (value) {
  9520. if (!this._node) {
  9521. return;
  9522. }
  9523. this._node.position = value;
  9524. },
  9525. enumerable: true,
  9526. configurable: true
  9527. });
  9528. Object.defineProperty(Control3D.prototype, "scaling", {
  9529. /** Gets or sets the control scaling in world space */
  9530. get: function () {
  9531. if (!this._node) {
  9532. return new babylonjs_1.Vector3(1, 1, 1);
  9533. }
  9534. return this._node.scaling;
  9535. },
  9536. set: function (value) {
  9537. if (!this._node) {
  9538. return;
  9539. }
  9540. this._node.scaling = value;
  9541. },
  9542. enumerable: true,
  9543. configurable: true
  9544. });
  9545. Object.defineProperty(Control3D.prototype, "behaviors", {
  9546. /**
  9547. * Gets the list of attached behaviors
  9548. * @see http://doc.babylonjs.com/features/behaviour
  9549. */
  9550. get: function () {
  9551. return this._behaviors;
  9552. },
  9553. enumerable: true,
  9554. configurable: true
  9555. });
  9556. /**
  9557. * Attach a behavior to the control
  9558. * @see http://doc.babylonjs.com/features/behaviour
  9559. * @param behavior defines the behavior to attach
  9560. * @returns the current control
  9561. */
  9562. Control3D.prototype.addBehavior = function (behavior) {
  9563. var _this = this;
  9564. var index = this._behaviors.indexOf(behavior);
  9565. if (index !== -1) {
  9566. return this;
  9567. }
  9568. behavior.init();
  9569. var scene = this._host.scene;
  9570. if (scene.isLoading) {
  9571. // We defer the attach when the scene will be loaded
  9572. scene.onDataLoadedObservable.addOnce(function () {
  9573. behavior.attach(_this);
  9574. });
  9575. }
  9576. else {
  9577. behavior.attach(this);
  9578. }
  9579. this._behaviors.push(behavior);
  9580. return this;
  9581. };
  9582. /**
  9583. * Remove an attached behavior
  9584. * @see http://doc.babylonjs.com/features/behaviour
  9585. * @param behavior defines the behavior to attach
  9586. * @returns the current control
  9587. */
  9588. Control3D.prototype.removeBehavior = function (behavior) {
  9589. var index = this._behaviors.indexOf(behavior);
  9590. if (index === -1) {
  9591. return this;
  9592. }
  9593. this._behaviors[index].detach();
  9594. this._behaviors.splice(index, 1);
  9595. return this;
  9596. };
  9597. /**
  9598. * Gets an attached behavior by name
  9599. * @param name defines the name of the behavior to look for
  9600. * @see http://doc.babylonjs.com/features/behaviour
  9601. * @returns null if behavior was not found else the requested behavior
  9602. */
  9603. Control3D.prototype.getBehaviorByName = function (name) {
  9604. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  9605. var behavior = _a[_i];
  9606. if (behavior.name === name) {
  9607. return behavior;
  9608. }
  9609. }
  9610. return null;
  9611. };
  9612. Object.defineProperty(Control3D.prototype, "isVisible", {
  9613. /** Gets or sets a boolean indicating if the control is visible */
  9614. get: function () {
  9615. return this._isVisible;
  9616. },
  9617. set: function (value) {
  9618. if (this._isVisible === value) {
  9619. return;
  9620. }
  9621. this._isVisible = value;
  9622. var mesh = this.mesh;
  9623. if (mesh) {
  9624. mesh.setEnabled(value);
  9625. }
  9626. },
  9627. enumerable: true,
  9628. configurable: true
  9629. });
  9630. Object.defineProperty(Control3D.prototype, "typeName", {
  9631. /**
  9632. * Gets a string representing the class name
  9633. */
  9634. get: function () {
  9635. return this._getTypeName();
  9636. },
  9637. enumerable: true,
  9638. configurable: true
  9639. });
  9640. Control3D.prototype._getTypeName = function () {
  9641. return "Control3D";
  9642. };
  9643. Object.defineProperty(Control3D.prototype, "node", {
  9644. /**
  9645. * Gets the transform node used by this control
  9646. */
  9647. get: function () {
  9648. return this._node;
  9649. },
  9650. enumerable: true,
  9651. configurable: true
  9652. });
  9653. Object.defineProperty(Control3D.prototype, "mesh", {
  9654. /**
  9655. * Gets the mesh used to render this control
  9656. */
  9657. get: function () {
  9658. if (this._node instanceof babylonjs_1.AbstractMesh) {
  9659. return this._node;
  9660. }
  9661. return null;
  9662. },
  9663. enumerable: true,
  9664. configurable: true
  9665. });
  9666. /**
  9667. * Link the control as child of the given node
  9668. * @param node defines the node to link to. Use null to unlink the control
  9669. * @returns the current control
  9670. */
  9671. Control3D.prototype.linkToTransformNode = function (node) {
  9672. if (this._node) {
  9673. this._node.parent = node;
  9674. }
  9675. return this;
  9676. };
  9677. /** @hidden **/
  9678. Control3D.prototype._prepareNode = function (scene) {
  9679. if (!this._node) {
  9680. this._node = this._createNode(scene);
  9681. if (!this.node) {
  9682. return;
  9683. }
  9684. this._node.metadata = this; // Store the control on the metadata field in order to get it when picking
  9685. this._node.position = this.position;
  9686. this._node.scaling = this.scaling;
  9687. var mesh = this.mesh;
  9688. if (mesh) {
  9689. mesh.isPickable = true;
  9690. this._affectMaterial(mesh);
  9691. }
  9692. }
  9693. };
  9694. /**
  9695. * Node creation.
  9696. * Can be overriden by children
  9697. * @param scene defines the scene where the node must be attached
  9698. * @returns the attached node or null if none. Must return a Mesh or AbstractMesh if there is an atttached visible object
  9699. */
  9700. Control3D.prototype._createNode = function (scene) {
  9701. // Do nothing by default
  9702. return null;
  9703. };
  9704. /**
  9705. * Affect a material to the given mesh
  9706. * @param mesh defines the mesh which will represent the control
  9707. */
  9708. Control3D.prototype._affectMaterial = function (mesh) {
  9709. mesh.material = null;
  9710. };
  9711. // Pointers
  9712. /** @hidden */
  9713. Control3D.prototype._onPointerMove = function (target, coordinates) {
  9714. this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  9715. };
  9716. /** @hidden */
  9717. Control3D.prototype._onPointerEnter = function (target) {
  9718. if (this._enterCount > 0) {
  9719. return false;
  9720. }
  9721. if (this._enterCount === -1) { // -1 is for touch input, we are now sure we are with a mouse or pencil
  9722. this._enterCount = 0;
  9723. }
  9724. this._enterCount++;
  9725. this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  9726. if (this.pointerEnterAnimation) {
  9727. this.pointerEnterAnimation();
  9728. }
  9729. return true;
  9730. };
  9731. /** @hidden */
  9732. Control3D.prototype._onPointerOut = function (target) {
  9733. this._enterCount = 0;
  9734. this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  9735. if (this.pointerOutAnimation) {
  9736. this.pointerOutAnimation();
  9737. }
  9738. };
  9739. /** @hidden */
  9740. Control3D.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  9741. if (this._downCount !== 0) {
  9742. return false;
  9743. }
  9744. this._downCount++;
  9745. this._downPointerIds[pointerId] = true;
  9746. this.onPointerDownObservable.notifyObservers(new vector3WithInfo_1.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  9747. if (this.pointerDownAnimation) {
  9748. this.pointerDownAnimation();
  9749. }
  9750. return true;
  9751. };
  9752. /** @hidden */
  9753. Control3D.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  9754. this._downCount = 0;
  9755. delete this._downPointerIds[pointerId];
  9756. if (notifyClick && (this._enterCount > 0 || this._enterCount === -1)) {
  9757. this.onPointerClickObservable.notifyObservers(new vector3WithInfo_1.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  9758. }
  9759. this.onPointerUpObservable.notifyObservers(new vector3WithInfo_1.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  9760. if (this.pointerUpAnimation) {
  9761. this.pointerUpAnimation();
  9762. }
  9763. };
  9764. /** @hidden */
  9765. Control3D.prototype.forcePointerUp = function (pointerId) {
  9766. if (pointerId === void 0) { pointerId = null; }
  9767. if (pointerId !== null) {
  9768. this._onPointerUp(this, babylonjs_1.Vector3.Zero(), pointerId, 0, true);
  9769. }
  9770. else {
  9771. for (var key in this._downPointerIds) {
  9772. this._onPointerUp(this, babylonjs_1.Vector3.Zero(), +key, 0, true);
  9773. }
  9774. }
  9775. };
  9776. /** @hidden */
  9777. Control3D.prototype._processObservables = function (type, pickedPoint, pointerId, buttonIndex) {
  9778. if (type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  9779. this._onPointerMove(this, pickedPoint);
  9780. var previousControlOver = this._host._lastControlOver[pointerId];
  9781. if (previousControlOver && previousControlOver !== this) {
  9782. previousControlOver._onPointerOut(this);
  9783. }
  9784. if (previousControlOver !== this) {
  9785. this._onPointerEnter(this);
  9786. }
  9787. this._host._lastControlOver[pointerId] = this;
  9788. return true;
  9789. }
  9790. if (type === babylonjs_1.PointerEventTypes.POINTERDOWN) {
  9791. this._onPointerDown(this, pickedPoint, pointerId, buttonIndex);
  9792. this._host._lastControlDown[pointerId] = this;
  9793. this._host._lastPickedControl = this;
  9794. return true;
  9795. }
  9796. if (type === babylonjs_1.PointerEventTypes.POINTERUP) {
  9797. if (this._host._lastControlDown[pointerId]) {
  9798. this._host._lastControlDown[pointerId]._onPointerUp(this, pickedPoint, pointerId, buttonIndex, true);
  9799. }
  9800. delete this._host._lastControlDown[pointerId];
  9801. return true;
  9802. }
  9803. return false;
  9804. };
  9805. /** @hidden */
  9806. Control3D.prototype._disposeNode = function () {
  9807. if (this._node) {
  9808. this._node.dispose();
  9809. this._node = null;
  9810. }
  9811. };
  9812. /**
  9813. * Releases all associated resources
  9814. */
  9815. Control3D.prototype.dispose = function () {
  9816. this.onPointerDownObservable.clear();
  9817. this.onPointerEnterObservable.clear();
  9818. this.onPointerMoveObservable.clear();
  9819. this.onPointerOutObservable.clear();
  9820. this.onPointerUpObservable.clear();
  9821. this.onPointerClickObservable.clear();
  9822. this._disposeNode();
  9823. // Behaviors
  9824. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  9825. var behavior = _a[_i];
  9826. behavior.detach();
  9827. }
  9828. };
  9829. return Control3D;
  9830. }());
  9831. exports.Control3D = Control3D;
  9832. /***/ }),
  9833. /***/ "./src/3D/controls/cylinderPanel.ts":
  9834. /*!******************************************!*\
  9835. !*** ./src/3D/controls/cylinderPanel.ts ***!
  9836. \******************************************/
  9837. /*! no static exports found */
  9838. /***/ (function(module, exports, __webpack_require__) {
  9839. "use strict";
  9840. var __extends = (this && this.__extends) || (function () {
  9841. var extendStatics = function (d, b) {
  9842. extendStatics = Object.setPrototypeOf ||
  9843. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9844. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  9845. return extendStatics(d, b);
  9846. }
  9847. return function (d, b) {
  9848. extendStatics(d, b);
  9849. function __() { this.constructor = d; }
  9850. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9851. };
  9852. })();
  9853. Object.defineProperty(exports, "__esModule", { value: true });
  9854. var volumeBasedPanel_1 = __webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts");
  9855. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  9856. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  9857. /**
  9858. * Class used to create a container panel deployed on the surface of a cylinder
  9859. */
  9860. var CylinderPanel = /** @class */ (function (_super) {
  9861. __extends(CylinderPanel, _super);
  9862. function CylinderPanel() {
  9863. var _this = _super !== null && _super.apply(this, arguments) || this;
  9864. _this._radius = 5.0;
  9865. return _this;
  9866. }
  9867. Object.defineProperty(CylinderPanel.prototype, "radius", {
  9868. /**
  9869. * Gets or sets the radius of the cylinder where to project controls (5 by default)
  9870. */
  9871. get: function () {
  9872. return this._radius;
  9873. },
  9874. set: function (value) {
  9875. var _this = this;
  9876. if (this._radius === value) {
  9877. return;
  9878. }
  9879. this._radius = value;
  9880. babylonjs_1.Tools.SetImmediate(function () {
  9881. _this._arrangeChildren();
  9882. });
  9883. },
  9884. enumerable: true,
  9885. configurable: true
  9886. });
  9887. CylinderPanel.prototype._mapGridNode = function (control, nodePosition) {
  9888. var mesh = control.mesh;
  9889. if (!mesh) {
  9890. return;
  9891. }
  9892. var newPos = this._cylindricalMapping(nodePosition);
  9893. control.position = newPos;
  9894. switch (this.orientation) {
  9895. case container3D_1.Container3D.FACEORIGIN_ORIENTATION:
  9896. mesh.lookAt(new BABYLON.Vector3(-newPos.x, newPos.y, -newPos.z));
  9897. break;
  9898. case container3D_1.Container3D.FACEORIGINREVERSED_ORIENTATION:
  9899. mesh.lookAt(new BABYLON.Vector3(2 * newPos.x, newPos.y, 2 * newPos.z));
  9900. break;
  9901. case container3D_1.Container3D.FACEFORWARD_ORIENTATION:
  9902. break;
  9903. case container3D_1.Container3D.FACEFORWARDREVERSED_ORIENTATION:
  9904. mesh.rotate(BABYLON.Axis.Y, Math.PI, BABYLON.Space.LOCAL);
  9905. break;
  9906. }
  9907. };
  9908. CylinderPanel.prototype._cylindricalMapping = function (source) {
  9909. var newPos = new babylonjs_1.Vector3(0, source.y, this._radius);
  9910. var yAngle = (source.x / this._radius);
  9911. babylonjs_1.Matrix.RotationYawPitchRollToRef(yAngle, 0, 0, babylonjs_1.Tmp.Matrix[0]);
  9912. return babylonjs_1.Vector3.TransformNormal(newPos, babylonjs_1.Tmp.Matrix[0]);
  9913. };
  9914. return CylinderPanel;
  9915. }(volumeBasedPanel_1.VolumeBasedPanel));
  9916. exports.CylinderPanel = CylinderPanel;
  9917. /***/ }),
  9918. /***/ "./src/3D/controls/holographicButton.ts":
  9919. /*!**********************************************!*\
  9920. !*** ./src/3D/controls/holographicButton.ts ***!
  9921. \**********************************************/
  9922. /*! no static exports found */
  9923. /***/ (function(module, exports, __webpack_require__) {
  9924. "use strict";
  9925. var __extends = (this && this.__extends) || (function () {
  9926. var extendStatics = function (d, b) {
  9927. extendStatics = Object.setPrototypeOf ||
  9928. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9929. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  9930. return extendStatics(d, b);
  9931. }
  9932. return function (d, b) {
  9933. extendStatics(d, b);
  9934. function __() { this.constructor = d; }
  9935. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9936. };
  9937. })();
  9938. Object.defineProperty(exports, "__esModule", { value: true });
  9939. var button3D_1 = __webpack_require__(/*! ./button3D */ "./src/3D/controls/button3D.ts");
  9940. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  9941. var fluentMaterial_1 = __webpack_require__(/*! ../materials/fluentMaterial */ "./src/3D/materials/fluentMaterial.ts");
  9942. var stackPanel_1 = __webpack_require__(/*! ../../2D/controls/stackPanel */ "./src/2D/controls/stackPanel.ts");
  9943. var image_1 = __webpack_require__(/*! ../../2D/controls/image */ "./src/2D/controls/image.ts");
  9944. var textBlock_1 = __webpack_require__(/*! ../../2D/controls/textBlock */ "./src/2D/controls/textBlock.ts");
  9945. var advancedDynamicTexture_1 = __webpack_require__(/*! ../../2D/advancedDynamicTexture */ "./src/2D/advancedDynamicTexture.ts");
  9946. /**
  9947. * Class used to create a holographic button in 3D
  9948. */
  9949. var HolographicButton = /** @class */ (function (_super) {
  9950. __extends(HolographicButton, _super);
  9951. /**
  9952. * Creates a new button
  9953. * @param name defines the control name
  9954. */
  9955. function HolographicButton(name, shareMaterials) {
  9956. if (shareMaterials === void 0) { shareMaterials = true; }
  9957. var _this = _super.call(this, name) || this;
  9958. _this._shareMaterials = true;
  9959. _this._shareMaterials = shareMaterials;
  9960. // Default animations
  9961. _this.pointerEnterAnimation = function () {
  9962. if (!_this.mesh) {
  9963. return;
  9964. }
  9965. _this._frontPlate.setEnabled(true);
  9966. };
  9967. _this.pointerOutAnimation = function () {
  9968. if (!_this.mesh) {
  9969. return;
  9970. }
  9971. _this._frontPlate.setEnabled(false);
  9972. };
  9973. return _this;
  9974. }
  9975. HolographicButton.prototype._disposeTooltip = function () {
  9976. this._tooltipFade = null;
  9977. if (this._tooltipTextBlock) {
  9978. this._tooltipTextBlock.dispose();
  9979. }
  9980. if (this._tooltipTexture) {
  9981. this._tooltipTexture.dispose();
  9982. }
  9983. if (this._tooltipMesh) {
  9984. this._tooltipMesh.dispose();
  9985. }
  9986. this.onPointerEnterObservable.remove(this._tooltipHoverObserver);
  9987. this.onPointerOutObservable.remove(this._tooltipOutObserver);
  9988. };
  9989. Object.defineProperty(HolographicButton.prototype, "tooltipText", {
  9990. get: function () {
  9991. if (this._tooltipTextBlock) {
  9992. return this._tooltipTextBlock.text;
  9993. }
  9994. return null;
  9995. },
  9996. /**
  9997. * Text to be displayed on the tooltip shown when hovering on the button. When set to null tooltip is disabled. (Default: null)
  9998. */
  9999. set: function (text) {
  10000. var _this = this;
  10001. if (!text) {
  10002. this._disposeTooltip();
  10003. return;
  10004. }
  10005. if (!this._tooltipFade) {
  10006. // Create tooltip with mesh and text
  10007. this._tooltipMesh = BABYLON.MeshBuilder.CreatePlane("", { size: 1 }, this._backPlate._scene);
  10008. var tooltipBackground = BABYLON.MeshBuilder.CreatePlane("", { size: 1, sideOrientation: BABYLON.Mesh.DOUBLESIDE }, this._backPlate._scene);
  10009. var mat = new babylonjs_1.StandardMaterial("", this._backPlate._scene);
  10010. mat.diffuseColor = BABYLON.Color3.FromHexString("#212121");
  10011. tooltipBackground.material = mat;
  10012. tooltipBackground.isPickable = false;
  10013. this._tooltipMesh.addChild(tooltipBackground);
  10014. tooltipBackground.position.z = 0.05;
  10015. this._tooltipMesh.scaling.y = 1 / 3;
  10016. this._tooltipMesh.position.y = 0.7;
  10017. this._tooltipMesh.position.z = -0.15;
  10018. this._tooltipMesh.isPickable = false;
  10019. this._tooltipMesh.parent = this._backPlate;
  10020. // Create text texture for the tooltip
  10021. this._tooltipTexture = advancedDynamicTexture_1.AdvancedDynamicTexture.CreateForMesh(this._tooltipMesh);
  10022. this._tooltipTextBlock = new textBlock_1.TextBlock();
  10023. this._tooltipTextBlock.scaleY = 3;
  10024. this._tooltipTextBlock.color = "white";
  10025. this._tooltipTextBlock.fontSize = 130;
  10026. this._tooltipTexture.addControl(this._tooltipTextBlock);
  10027. // Add hover action to tooltip
  10028. this._tooltipFade = new BABYLON.FadeInOutBehavior();
  10029. this._tooltipFade.delay = 500;
  10030. this._tooltipMesh.addBehavior(this._tooltipFade);
  10031. this._tooltipHoverObserver = this.onPointerEnterObservable.add(function () {
  10032. if (_this._tooltipFade) {
  10033. _this._tooltipFade.fadeIn(true);
  10034. }
  10035. });
  10036. this._tooltipOutObserver = this.onPointerOutObservable.add(function () {
  10037. if (_this._tooltipFade) {
  10038. _this._tooltipFade.fadeIn(false);
  10039. }
  10040. });
  10041. }
  10042. if (this._tooltipTextBlock) {
  10043. this._tooltipTextBlock.text = text;
  10044. }
  10045. },
  10046. enumerable: true,
  10047. configurable: true
  10048. });
  10049. Object.defineProperty(HolographicButton.prototype, "text", {
  10050. /**
  10051. * Gets or sets text for the button
  10052. */
  10053. get: function () {
  10054. return this._text;
  10055. },
  10056. set: function (value) {
  10057. if (this._text === value) {
  10058. return;
  10059. }
  10060. this._text = value;
  10061. this._rebuildContent();
  10062. },
  10063. enumerable: true,
  10064. configurable: true
  10065. });
  10066. Object.defineProperty(HolographicButton.prototype, "imageUrl", {
  10067. /**
  10068. * Gets or sets the image url for the button
  10069. */
  10070. get: function () {
  10071. return this._imageUrl;
  10072. },
  10073. set: function (value) {
  10074. if (this._imageUrl === value) {
  10075. return;
  10076. }
  10077. this._imageUrl = value;
  10078. this._rebuildContent();
  10079. },
  10080. enumerable: true,
  10081. configurable: true
  10082. });
  10083. Object.defineProperty(HolographicButton.prototype, "backMaterial", {
  10084. /**
  10085. * Gets the back material used by this button
  10086. */
  10087. get: function () {
  10088. return this._backMaterial;
  10089. },
  10090. enumerable: true,
  10091. configurable: true
  10092. });
  10093. Object.defineProperty(HolographicButton.prototype, "frontMaterial", {
  10094. /**
  10095. * Gets the front material used by this button
  10096. */
  10097. get: function () {
  10098. return this._frontMaterial;
  10099. },
  10100. enumerable: true,
  10101. configurable: true
  10102. });
  10103. Object.defineProperty(HolographicButton.prototype, "plateMaterial", {
  10104. /**
  10105. * Gets the plate material used by this button
  10106. */
  10107. get: function () {
  10108. return this._plateMaterial;
  10109. },
  10110. enumerable: true,
  10111. configurable: true
  10112. });
  10113. Object.defineProperty(HolographicButton.prototype, "shareMaterials", {
  10114. /**
  10115. * Gets a boolean indicating if this button shares its material with other HolographicButtons
  10116. */
  10117. get: function () {
  10118. return this._shareMaterials;
  10119. },
  10120. enumerable: true,
  10121. configurable: true
  10122. });
  10123. HolographicButton.prototype._getTypeName = function () {
  10124. return "HolographicButton";
  10125. };
  10126. HolographicButton.prototype._rebuildContent = function () {
  10127. this._disposeFacadeTexture();
  10128. var panel = new stackPanel_1.StackPanel();
  10129. panel.isVertical = true;
  10130. if (this._imageUrl) {
  10131. var image = new image_1.Image();
  10132. image.source = this._imageUrl;
  10133. image.paddingTop = "40px";
  10134. image.height = "180px";
  10135. image.width = "100px";
  10136. image.paddingBottom = "40px";
  10137. panel.addControl(image);
  10138. }
  10139. if (this._text) {
  10140. var text = new textBlock_1.TextBlock();
  10141. text.text = this._text;
  10142. text.color = "white";
  10143. text.height = "30px";
  10144. text.fontSize = 24;
  10145. panel.addControl(text);
  10146. }
  10147. if (this._frontPlate) {
  10148. this.content = panel;
  10149. }
  10150. };
  10151. // Mesh association
  10152. HolographicButton.prototype._createNode = function (scene) {
  10153. this._backPlate = babylonjs_1.MeshBuilder.CreateBox(this.name + "BackMesh", {
  10154. width: 1.0,
  10155. height: 1.0,
  10156. depth: 0.08
  10157. }, scene);
  10158. this._frontPlate = babylonjs_1.MeshBuilder.CreateBox(this.name + "FrontMesh", {
  10159. width: 1.0,
  10160. height: 1.0,
  10161. depth: 0.08
  10162. }, scene);
  10163. this._frontPlate.parent = this._backPlate;
  10164. this._frontPlate.position.z = -0.08;
  10165. this._frontPlate.isPickable = false;
  10166. this._frontPlate.setEnabled(false);
  10167. this._textPlate = _super.prototype._createNode.call(this, scene);
  10168. this._textPlate.parent = this._backPlate;
  10169. this._textPlate.position.z = -0.08;
  10170. this._textPlate.isPickable = false;
  10171. return this._backPlate;
  10172. };
  10173. HolographicButton.prototype._applyFacade = function (facadeTexture) {
  10174. this._plateMaterial.emissiveTexture = facadeTexture;
  10175. this._plateMaterial.opacityTexture = facadeTexture;
  10176. };
  10177. HolographicButton.prototype._createBackMaterial = function (mesh) {
  10178. var _this = this;
  10179. this._backMaterial = new fluentMaterial_1.FluentMaterial(this.name + "Back Material", mesh.getScene());
  10180. this._backMaterial.renderHoverLight = true;
  10181. this._pickedPointObserver = this._host.onPickedPointChangedObservable.add(function (pickedPoint) {
  10182. if (pickedPoint) {
  10183. _this._backMaterial.hoverPosition = pickedPoint;
  10184. _this._backMaterial.hoverColor.a = 1.0;
  10185. }
  10186. else {
  10187. _this._backMaterial.hoverColor.a = 0;
  10188. }
  10189. });
  10190. };
  10191. HolographicButton.prototype._createFrontMaterial = function (mesh) {
  10192. this._frontMaterial = new fluentMaterial_1.FluentMaterial(this.name + "Front Material", mesh.getScene());
  10193. this._frontMaterial.innerGlowColorIntensity = 0; // No inner glow
  10194. this._frontMaterial.alpha = 0.5; // Additive
  10195. this._frontMaterial.renderBorders = true;
  10196. };
  10197. HolographicButton.prototype._createPlateMaterial = function (mesh) {
  10198. this._plateMaterial = new babylonjs_1.StandardMaterial(this.name + "Plate Material", mesh.getScene());
  10199. this._plateMaterial.specularColor = babylonjs_1.Color3.Black();
  10200. };
  10201. HolographicButton.prototype._affectMaterial = function (mesh) {
  10202. // Back
  10203. if (this._shareMaterials) {
  10204. if (!this._host._sharedMaterials["backFluentMaterial"]) {
  10205. this._createBackMaterial(mesh);
  10206. this._host._sharedMaterials["backFluentMaterial"] = this._backMaterial;
  10207. }
  10208. else {
  10209. this._backMaterial = this._host._sharedMaterials["backFluentMaterial"];
  10210. }
  10211. // Front
  10212. if (!this._host._sharedMaterials["frontFluentMaterial"]) {
  10213. this._createFrontMaterial(mesh);
  10214. this._host._sharedMaterials["frontFluentMaterial"] = this._frontMaterial;
  10215. }
  10216. else {
  10217. this._frontMaterial = this._host._sharedMaterials["frontFluentMaterial"];
  10218. }
  10219. }
  10220. else {
  10221. this._createBackMaterial(mesh);
  10222. this._createFrontMaterial(mesh);
  10223. }
  10224. this._createPlateMaterial(mesh);
  10225. this._backPlate.material = this._backMaterial;
  10226. this._frontPlate.material = this._frontMaterial;
  10227. this._textPlate.material = this._plateMaterial;
  10228. this._rebuildContent();
  10229. };
  10230. /**
  10231. * Releases all associated resources
  10232. */
  10233. HolographicButton.prototype.dispose = function () {
  10234. _super.prototype.dispose.call(this); // will dispose main mesh ie. back plate
  10235. this._disposeTooltip();
  10236. if (!this.shareMaterials) {
  10237. this._backMaterial.dispose();
  10238. this._frontMaterial.dispose();
  10239. this._plateMaterial.dispose();
  10240. if (this._pickedPointObserver) {
  10241. this._host.onPickedPointChangedObservable.remove(this._pickedPointObserver);
  10242. this._pickedPointObserver = null;
  10243. }
  10244. }
  10245. };
  10246. return HolographicButton;
  10247. }(button3D_1.Button3D));
  10248. exports.HolographicButton = HolographicButton;
  10249. /***/ }),
  10250. /***/ "./src/3D/controls/index.ts":
  10251. /*!**********************************!*\
  10252. !*** ./src/3D/controls/index.ts ***!
  10253. \**********************************/
  10254. /*! no static exports found */
  10255. /***/ (function(module, exports, __webpack_require__) {
  10256. "use strict";
  10257. function __export(m) {
  10258. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  10259. }
  10260. Object.defineProperty(exports, "__esModule", { value: true });
  10261. __export(__webpack_require__(/*! ./abstractButton3D */ "./src/3D/controls/abstractButton3D.ts"));
  10262. __export(__webpack_require__(/*! ./button3D */ "./src/3D/controls/button3D.ts"));
  10263. __export(__webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts"));
  10264. __export(__webpack_require__(/*! ./control3D */ "./src/3D/controls/control3D.ts"));
  10265. __export(__webpack_require__(/*! ./cylinderPanel */ "./src/3D/controls/cylinderPanel.ts"));
  10266. __export(__webpack_require__(/*! ./holographicButton */ "./src/3D/controls/holographicButton.ts"));
  10267. __export(__webpack_require__(/*! ./meshButton3D */ "./src/3D/controls/meshButton3D.ts"));
  10268. __export(__webpack_require__(/*! ./planePanel */ "./src/3D/controls/planePanel.ts"));
  10269. __export(__webpack_require__(/*! ./scatterPanel */ "./src/3D/controls/scatterPanel.ts"));
  10270. __export(__webpack_require__(/*! ./spherePanel */ "./src/3D/controls/spherePanel.ts"));
  10271. __export(__webpack_require__(/*! ./stackPanel3D */ "./src/3D/controls/stackPanel3D.ts"));
  10272. __export(__webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts"));
  10273. /***/ }),
  10274. /***/ "./src/3D/controls/meshButton3D.ts":
  10275. /*!*****************************************!*\
  10276. !*** ./src/3D/controls/meshButton3D.ts ***!
  10277. \*****************************************/
  10278. /*! no static exports found */
  10279. /***/ (function(module, exports, __webpack_require__) {
  10280. "use strict";
  10281. var __extends = (this && this.__extends) || (function () {
  10282. var extendStatics = function (d, b) {
  10283. extendStatics = Object.setPrototypeOf ||
  10284. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10285. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10286. return extendStatics(d, b);
  10287. }
  10288. return function (d, b) {
  10289. extendStatics(d, b);
  10290. function __() { this.constructor = d; }
  10291. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10292. };
  10293. })();
  10294. Object.defineProperty(exports, "__esModule", { value: true });
  10295. var button3D_1 = __webpack_require__(/*! ./button3D */ "./src/3D/controls/button3D.ts");
  10296. /**
  10297. * Class used to create an interactable object. It's a 3D button using a mesh coming from the current scene
  10298. */
  10299. var MeshButton3D = /** @class */ (function (_super) {
  10300. __extends(MeshButton3D, _super);
  10301. /**
  10302. * Creates a new 3D button based on a mesh
  10303. * @param mesh mesh to become a 3D button
  10304. * @param name defines the control name
  10305. */
  10306. function MeshButton3D(mesh, name) {
  10307. var _this = _super.call(this, name) || this;
  10308. _this._currentMesh = mesh;
  10309. /**
  10310. * Provides a default behavior on hover/out & up/down
  10311. * Override those function to create your own desired behavior specific to your mesh
  10312. */
  10313. _this.pointerEnterAnimation = function () {
  10314. if (!_this.mesh) {
  10315. return;
  10316. }
  10317. _this.mesh.scaling.scaleInPlace(1.1);
  10318. };
  10319. _this.pointerOutAnimation = function () {
  10320. if (!_this.mesh) {
  10321. return;
  10322. }
  10323. _this.mesh.scaling.scaleInPlace(1.0 / 1.1);
  10324. };
  10325. _this.pointerDownAnimation = function () {
  10326. if (!_this.mesh) {
  10327. return;
  10328. }
  10329. _this.mesh.scaling.scaleInPlace(0.95);
  10330. };
  10331. _this.pointerUpAnimation = function () {
  10332. if (!_this.mesh) {
  10333. return;
  10334. }
  10335. _this.mesh.scaling.scaleInPlace(1.0 / 0.95);
  10336. };
  10337. return _this;
  10338. }
  10339. MeshButton3D.prototype._getTypeName = function () {
  10340. return "MeshButton3D";
  10341. };
  10342. // Mesh association
  10343. MeshButton3D.prototype._createNode = function (scene) {
  10344. var _this = this;
  10345. this._currentMesh.getChildMeshes().forEach(function (mesh) {
  10346. mesh.metadata = _this;
  10347. });
  10348. return this._currentMesh;
  10349. };
  10350. MeshButton3D.prototype._affectMaterial = function (mesh) {
  10351. };
  10352. return MeshButton3D;
  10353. }(button3D_1.Button3D));
  10354. exports.MeshButton3D = MeshButton3D;
  10355. /***/ }),
  10356. /***/ "./src/3D/controls/planePanel.ts":
  10357. /*!***************************************!*\
  10358. !*** ./src/3D/controls/planePanel.ts ***!
  10359. \***************************************/
  10360. /*! no static exports found */
  10361. /***/ (function(module, exports, __webpack_require__) {
  10362. "use strict";
  10363. var __extends = (this && this.__extends) || (function () {
  10364. var extendStatics = function (d, b) {
  10365. extendStatics = Object.setPrototypeOf ||
  10366. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10367. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10368. return extendStatics(d, b);
  10369. }
  10370. return function (d, b) {
  10371. extendStatics(d, b);
  10372. function __() { this.constructor = d; }
  10373. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10374. };
  10375. })();
  10376. Object.defineProperty(exports, "__esModule", { value: true });
  10377. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10378. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10379. var volumeBasedPanel_1 = __webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts");
  10380. /**
  10381. * Class used to create a container panel deployed on the surface of a plane
  10382. */
  10383. var PlanePanel = /** @class */ (function (_super) {
  10384. __extends(PlanePanel, _super);
  10385. function PlanePanel() {
  10386. return _super !== null && _super.apply(this, arguments) || this;
  10387. }
  10388. PlanePanel.prototype._mapGridNode = function (control, nodePosition) {
  10389. var mesh = control.mesh;
  10390. if (!mesh) {
  10391. return;
  10392. }
  10393. control.position = nodePosition.clone();
  10394. var target = babylonjs_1.Tmp.Vector3[0];
  10395. target.copyFrom(nodePosition);
  10396. switch (this.orientation) {
  10397. case container3D_1.Container3D.FACEORIGIN_ORIENTATION:
  10398. case container3D_1.Container3D.FACEFORWARD_ORIENTATION:
  10399. target.addInPlace(new BABYLON.Vector3(0, 0, -1));
  10400. mesh.lookAt(target);
  10401. break;
  10402. case container3D_1.Container3D.FACEFORWARDREVERSED_ORIENTATION:
  10403. case container3D_1.Container3D.FACEORIGINREVERSED_ORIENTATION:
  10404. target.addInPlace(new BABYLON.Vector3(0, 0, 1));
  10405. mesh.lookAt(target);
  10406. break;
  10407. }
  10408. };
  10409. return PlanePanel;
  10410. }(volumeBasedPanel_1.VolumeBasedPanel));
  10411. exports.PlanePanel = PlanePanel;
  10412. /***/ }),
  10413. /***/ "./src/3D/controls/scatterPanel.ts":
  10414. /*!*****************************************!*\
  10415. !*** ./src/3D/controls/scatterPanel.ts ***!
  10416. \*****************************************/
  10417. /*! no static exports found */
  10418. /***/ (function(module, exports, __webpack_require__) {
  10419. "use strict";
  10420. var __extends = (this && this.__extends) || (function () {
  10421. var extendStatics = function (d, b) {
  10422. extendStatics = Object.setPrototypeOf ||
  10423. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10424. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10425. return extendStatics(d, b);
  10426. }
  10427. return function (d, b) {
  10428. extendStatics(d, b);
  10429. function __() { this.constructor = d; }
  10430. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10431. };
  10432. })();
  10433. Object.defineProperty(exports, "__esModule", { value: true });
  10434. var volumeBasedPanel_1 = __webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts");
  10435. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10436. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10437. /**
  10438. * Class used to create a container panel where items get randomized planar mapping
  10439. */
  10440. var ScatterPanel = /** @class */ (function (_super) {
  10441. __extends(ScatterPanel, _super);
  10442. function ScatterPanel() {
  10443. var _this = _super !== null && _super.apply(this, arguments) || this;
  10444. _this._iteration = 100.0;
  10445. return _this;
  10446. }
  10447. Object.defineProperty(ScatterPanel.prototype, "iteration", {
  10448. /**
  10449. * Gets or sets the number of iteration to use to scatter the controls (100 by default)
  10450. */
  10451. get: function () {
  10452. return this._iteration;
  10453. },
  10454. set: function (value) {
  10455. var _this = this;
  10456. if (this._iteration === value) {
  10457. return;
  10458. }
  10459. this._iteration = value;
  10460. babylonjs_1.Tools.SetImmediate(function () {
  10461. _this._arrangeChildren();
  10462. });
  10463. },
  10464. enumerable: true,
  10465. configurable: true
  10466. });
  10467. ScatterPanel.prototype._mapGridNode = function (control, nodePosition) {
  10468. var mesh = control.mesh;
  10469. var newPos = this._scatterMapping(nodePosition);
  10470. if (!mesh) {
  10471. return;
  10472. }
  10473. switch (this.orientation) {
  10474. case container3D_1.Container3D.FACEORIGIN_ORIENTATION:
  10475. case container3D_1.Container3D.FACEFORWARD_ORIENTATION:
  10476. mesh.lookAt(new babylonjs_1.Vector3(0, 0, -1));
  10477. break;
  10478. case container3D_1.Container3D.FACEFORWARDREVERSED_ORIENTATION:
  10479. case container3D_1.Container3D.FACEORIGINREVERSED_ORIENTATION:
  10480. mesh.lookAt(new babylonjs_1.Vector3(0, 0, 1));
  10481. break;
  10482. }
  10483. control.position = newPos;
  10484. };
  10485. ScatterPanel.prototype._scatterMapping = function (source) {
  10486. source.x = (1.0 - Math.random() * 2.0) * this._cellWidth;
  10487. source.y = (1.0 - Math.random() * 2.0) * this._cellHeight;
  10488. return source;
  10489. };
  10490. ScatterPanel.prototype._finalProcessing = function () {
  10491. var meshes = [];
  10492. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  10493. var child = _a[_i];
  10494. if (!child.mesh) {
  10495. continue;
  10496. }
  10497. meshes.push(child.mesh);
  10498. }
  10499. for (var count = 0; count < this._iteration; count++) {
  10500. meshes.sort(function (a, b) {
  10501. var distance1 = a.position.lengthSquared();
  10502. var distance2 = b.position.lengthSquared();
  10503. if (distance1 < distance2) {
  10504. return 1;
  10505. }
  10506. else if (distance1 > distance2) {
  10507. return -1;
  10508. }
  10509. return 0;
  10510. });
  10511. var radiusPaddingSquared = Math.pow(this.margin, 2.0);
  10512. var cellSize = Math.max(this._cellWidth, this._cellHeight);
  10513. var difference2D = babylonjs_1.Tmp.Vector2[0];
  10514. var difference = babylonjs_1.Tmp.Vector3[0];
  10515. for (var i = 0; i < meshes.length - 1; i++) {
  10516. for (var j = i + 1; j < meshes.length; j++) {
  10517. if (i != j) {
  10518. meshes[j].position.subtractToRef(meshes[i].position, difference);
  10519. // Ignore Z axis
  10520. difference2D.x = difference.x;
  10521. difference2D.y = difference.y;
  10522. var combinedRadius = cellSize;
  10523. var distance = difference2D.lengthSquared() - radiusPaddingSquared;
  10524. var minSeparation = Math.min(distance, radiusPaddingSquared);
  10525. distance -= minSeparation;
  10526. if (distance < (Math.pow(combinedRadius, 2.0))) {
  10527. difference2D.normalize();
  10528. difference.scaleInPlace((combinedRadius - Math.sqrt(distance)) * 0.5);
  10529. meshes[j].position.addInPlace(difference);
  10530. meshes[i].position.subtractInPlace(difference);
  10531. }
  10532. }
  10533. }
  10534. }
  10535. }
  10536. };
  10537. return ScatterPanel;
  10538. }(volumeBasedPanel_1.VolumeBasedPanel));
  10539. exports.ScatterPanel = ScatterPanel;
  10540. /***/ }),
  10541. /***/ "./src/3D/controls/spherePanel.ts":
  10542. /*!****************************************!*\
  10543. !*** ./src/3D/controls/spherePanel.ts ***!
  10544. \****************************************/
  10545. /*! no static exports found */
  10546. /***/ (function(module, exports, __webpack_require__) {
  10547. "use strict";
  10548. var __extends = (this && this.__extends) || (function () {
  10549. var extendStatics = function (d, b) {
  10550. extendStatics = Object.setPrototypeOf ||
  10551. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10552. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10553. return extendStatics(d, b);
  10554. }
  10555. return function (d, b) {
  10556. extendStatics(d, b);
  10557. function __() { this.constructor = d; }
  10558. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10559. };
  10560. })();
  10561. Object.defineProperty(exports, "__esModule", { value: true });
  10562. var volumeBasedPanel_1 = __webpack_require__(/*! ./volumeBasedPanel */ "./src/3D/controls/volumeBasedPanel.ts");
  10563. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10564. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10565. /**
  10566. * Class used to create a container panel deployed on the surface of a sphere
  10567. */
  10568. var SpherePanel = /** @class */ (function (_super) {
  10569. __extends(SpherePanel, _super);
  10570. function SpherePanel() {
  10571. var _this = _super !== null && _super.apply(this, arguments) || this;
  10572. _this._radius = 5.0;
  10573. return _this;
  10574. }
  10575. Object.defineProperty(SpherePanel.prototype, "radius", {
  10576. /**
  10577. * Gets or sets the radius of the sphere where to project controls (5 by default)
  10578. */
  10579. get: function () {
  10580. return this._radius;
  10581. },
  10582. set: function (value) {
  10583. var _this = this;
  10584. if (this._radius === value) {
  10585. return;
  10586. }
  10587. this._radius = value;
  10588. babylonjs_1.Tools.SetImmediate(function () {
  10589. _this._arrangeChildren();
  10590. });
  10591. },
  10592. enumerable: true,
  10593. configurable: true
  10594. });
  10595. SpherePanel.prototype._mapGridNode = function (control, nodePosition) {
  10596. var mesh = control.mesh;
  10597. if (!mesh) {
  10598. return;
  10599. }
  10600. var newPos = this._sphericalMapping(nodePosition);
  10601. control.position = newPos;
  10602. switch (this.orientation) {
  10603. case container3D_1.Container3D.FACEORIGIN_ORIENTATION:
  10604. mesh.lookAt(new BABYLON.Vector3(-newPos.x, -newPos.y, -newPos.z));
  10605. break;
  10606. case container3D_1.Container3D.FACEORIGINREVERSED_ORIENTATION:
  10607. mesh.lookAt(new BABYLON.Vector3(2 * newPos.x, 2 * newPos.y, 2 * newPos.z));
  10608. break;
  10609. case container3D_1.Container3D.FACEFORWARD_ORIENTATION:
  10610. break;
  10611. case container3D_1.Container3D.FACEFORWARDREVERSED_ORIENTATION:
  10612. mesh.rotate(BABYLON.Axis.Y, Math.PI, BABYLON.Space.LOCAL);
  10613. break;
  10614. }
  10615. };
  10616. SpherePanel.prototype._sphericalMapping = function (source) {
  10617. var newPos = new babylonjs_1.Vector3(0, 0, this._radius);
  10618. var xAngle = (source.y / this._radius);
  10619. var yAngle = -(source.x / this._radius);
  10620. babylonjs_1.Matrix.RotationYawPitchRollToRef(yAngle, xAngle, 0, babylonjs_1.Tmp.Matrix[0]);
  10621. return babylonjs_1.Vector3.TransformNormal(newPos, babylonjs_1.Tmp.Matrix[0]);
  10622. };
  10623. return SpherePanel;
  10624. }(volumeBasedPanel_1.VolumeBasedPanel));
  10625. exports.SpherePanel = SpherePanel;
  10626. /***/ }),
  10627. /***/ "./src/3D/controls/stackPanel3D.ts":
  10628. /*!*****************************************!*\
  10629. !*** ./src/3D/controls/stackPanel3D.ts ***!
  10630. \*****************************************/
  10631. /*! no static exports found */
  10632. /***/ (function(module, exports, __webpack_require__) {
  10633. "use strict";
  10634. var __extends = (this && this.__extends) || (function () {
  10635. var extendStatics = function (d, b) {
  10636. extendStatics = Object.setPrototypeOf ||
  10637. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10638. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10639. return extendStatics(d, b);
  10640. }
  10641. return function (d, b) {
  10642. extendStatics(d, b);
  10643. function __() { this.constructor = d; }
  10644. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10645. };
  10646. })();
  10647. Object.defineProperty(exports, "__esModule", { value: true });
  10648. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10649. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10650. /**
  10651. * Class used to create a stack panel in 3D on XY plane
  10652. */
  10653. var StackPanel3D = /** @class */ (function (_super) {
  10654. __extends(StackPanel3D, _super);
  10655. /**
  10656. * Creates new StackPanel
  10657. * @param isVertical
  10658. */
  10659. function StackPanel3D(isVertical) {
  10660. if (isVertical === void 0) { isVertical = false; }
  10661. var _this = _super.call(this) || this;
  10662. _this._isVertical = false;
  10663. /**
  10664. * Gets or sets the distance between elements
  10665. */
  10666. _this.margin = 0.1;
  10667. _this._isVertical = isVertical;
  10668. return _this;
  10669. }
  10670. Object.defineProperty(StackPanel3D.prototype, "isVertical", {
  10671. /**
  10672. * Gets or sets a boolean indicating if the stack panel is vertical or horizontal (horizontal by default)
  10673. */
  10674. get: function () {
  10675. return this._isVertical;
  10676. },
  10677. set: function (value) {
  10678. var _this = this;
  10679. if (this._isVertical === value) {
  10680. return;
  10681. }
  10682. this._isVertical = value;
  10683. babylonjs_1.Tools.SetImmediate(function () {
  10684. _this._arrangeChildren();
  10685. });
  10686. },
  10687. enumerable: true,
  10688. configurable: true
  10689. });
  10690. StackPanel3D.prototype._arrangeChildren = function () {
  10691. var width = 0;
  10692. var height = 0;
  10693. var controlCount = 0;
  10694. var extendSizes = [];
  10695. var currentInverseWorld = babylonjs_1.Matrix.Invert(this.node.computeWorldMatrix(true));
  10696. // Measure
  10697. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  10698. var child = _a[_i];
  10699. if (!child.mesh) {
  10700. continue;
  10701. }
  10702. controlCount++;
  10703. child.mesh.computeWorldMatrix(true);
  10704. child.mesh.getWorldMatrix().multiplyToRef(currentInverseWorld, babylonjs_1.Tmp.Matrix[0]);
  10705. var boundingBox = child.mesh.getBoundingInfo().boundingBox;
  10706. var extendSize = babylonjs_1.Vector3.TransformNormal(boundingBox.extendSize, babylonjs_1.Tmp.Matrix[0]);
  10707. extendSizes.push(extendSize);
  10708. if (this._isVertical) {
  10709. height += extendSize.y;
  10710. }
  10711. else {
  10712. width += extendSize.x;
  10713. }
  10714. }
  10715. if (this._isVertical) {
  10716. height += (controlCount - 1) * this.margin / 2;
  10717. }
  10718. else {
  10719. width += (controlCount - 1) * this.margin / 2;
  10720. }
  10721. // Arrange
  10722. var offset;
  10723. if (this._isVertical) {
  10724. offset = -height;
  10725. }
  10726. else {
  10727. offset = -width;
  10728. }
  10729. var index = 0;
  10730. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  10731. var child = _c[_b];
  10732. if (!child.mesh) {
  10733. continue;
  10734. }
  10735. controlCount--;
  10736. var extendSize = extendSizes[index++];
  10737. if (this._isVertical) {
  10738. child.position.y = offset + extendSize.y;
  10739. child.position.x = 0;
  10740. offset += extendSize.y * 2;
  10741. }
  10742. else {
  10743. child.position.x = offset + extendSize.x;
  10744. child.position.y = 0;
  10745. offset += extendSize.x * 2;
  10746. }
  10747. offset += (controlCount > 0 ? this.margin : 0);
  10748. }
  10749. };
  10750. return StackPanel3D;
  10751. }(container3D_1.Container3D));
  10752. exports.StackPanel3D = StackPanel3D;
  10753. /***/ }),
  10754. /***/ "./src/3D/controls/volumeBasedPanel.ts":
  10755. /*!*********************************************!*\
  10756. !*** ./src/3D/controls/volumeBasedPanel.ts ***!
  10757. \*********************************************/
  10758. /*! no static exports found */
  10759. /***/ (function(module, exports, __webpack_require__) {
  10760. "use strict";
  10761. var __extends = (this && this.__extends) || (function () {
  10762. var extendStatics = function (d, b) {
  10763. extendStatics = Object.setPrototypeOf ||
  10764. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  10765. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10766. return extendStatics(d, b);
  10767. }
  10768. return function (d, b) {
  10769. extendStatics(d, b);
  10770. function __() { this.constructor = d; }
  10771. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10772. };
  10773. })();
  10774. Object.defineProperty(exports, "__esModule", { value: true });
  10775. var container3D_1 = __webpack_require__(/*! ./container3D */ "./src/3D/controls/container3D.ts");
  10776. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10777. /**
  10778. * Abstract class used to create a container panel deployed on the surface of a volume
  10779. */
  10780. var VolumeBasedPanel = /** @class */ (function (_super) {
  10781. __extends(VolumeBasedPanel, _super);
  10782. /**
  10783. * Creates new VolumeBasedPanel
  10784. */
  10785. function VolumeBasedPanel() {
  10786. var _this = _super.call(this) || this;
  10787. _this._columns = 10;
  10788. _this._rows = 0;
  10789. _this._rowThenColum = true;
  10790. _this._orientation = container3D_1.Container3D.FACEORIGIN_ORIENTATION;
  10791. /**
  10792. * Gets or sets the distance between elements
  10793. */
  10794. _this.margin = 0;
  10795. return _this;
  10796. }
  10797. Object.defineProperty(VolumeBasedPanel.prototype, "orientation", {
  10798. /**
  10799. * Gets or sets the orientation to apply to all controls (BABYLON.Container3D.FaceOriginReversedOrientation by default)
  10800. * | Value | Type | Description |
  10801. * | ----- | ----------------------------------- | ----------- |
  10802. * | 0 | UNSET_ORIENTATION | Control rotation will remain unchanged |
  10803. * | 1 | FACEORIGIN_ORIENTATION | Control will rotate to make it look at sphere central axis |
  10804. * | 2 | FACEORIGINREVERSED_ORIENTATION | Control will rotate to make it look back at sphere central axis |
  10805. * | 3 | FACEFORWARD_ORIENTATION | Control will rotate to look at z axis (0, 0, 1) |
  10806. * | 4 | FACEFORWARDREVERSED_ORIENTATION | Control will rotate to look at negative z axis (0, 0, -1) |
  10807. */
  10808. get: function () {
  10809. return this._orientation;
  10810. },
  10811. set: function (value) {
  10812. var _this = this;
  10813. if (this._orientation === value) {
  10814. return;
  10815. }
  10816. this._orientation = value;
  10817. babylonjs_1.Tools.SetImmediate(function () {
  10818. _this._arrangeChildren();
  10819. });
  10820. },
  10821. enumerable: true,
  10822. configurable: true
  10823. });
  10824. Object.defineProperty(VolumeBasedPanel.prototype, "columns", {
  10825. /**
  10826. * Gets or sets the number of columns requested (10 by default).
  10827. * The panel will automatically compute the number of rows based on number of child controls.
  10828. */
  10829. get: function () {
  10830. return this._columns;
  10831. },
  10832. set: function (value) {
  10833. var _this = this;
  10834. if (this._columns === value) {
  10835. return;
  10836. }
  10837. this._columns = value;
  10838. this._rowThenColum = true;
  10839. babylonjs_1.Tools.SetImmediate(function () {
  10840. _this._arrangeChildren();
  10841. });
  10842. },
  10843. enumerable: true,
  10844. configurable: true
  10845. });
  10846. Object.defineProperty(VolumeBasedPanel.prototype, "rows", {
  10847. /**
  10848. * Gets or sets a the number of rows requested.
  10849. * The panel will automatically compute the number of columns based on number of child controls.
  10850. */
  10851. get: function () {
  10852. return this._rows;
  10853. },
  10854. set: function (value) {
  10855. var _this = this;
  10856. if (this._rows === value) {
  10857. return;
  10858. }
  10859. this._rows = value;
  10860. this._rowThenColum = false;
  10861. babylonjs_1.Tools.SetImmediate(function () {
  10862. _this._arrangeChildren();
  10863. });
  10864. },
  10865. enumerable: true,
  10866. configurable: true
  10867. });
  10868. VolumeBasedPanel.prototype._arrangeChildren = function () {
  10869. this._cellWidth = 0;
  10870. this._cellHeight = 0;
  10871. var rows = 0;
  10872. var columns = 0;
  10873. var controlCount = 0;
  10874. var currentInverseWorld = babylonjs_1.Matrix.Invert(this.node.computeWorldMatrix(true));
  10875. // Measure
  10876. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  10877. var child = _a[_i];
  10878. if (!child.mesh) {
  10879. continue;
  10880. }
  10881. controlCount++;
  10882. child.mesh.computeWorldMatrix(true);
  10883. // child.mesh.getWorldMatrix().multiplyToRef(currentInverseWorld, Tmp.Matrix[0]);
  10884. var boundingBox = child.mesh.getHierarchyBoundingVectors();
  10885. var extendSize = babylonjs_1.Tmp.Vector3[0];
  10886. var diff = babylonjs_1.Tmp.Vector3[1];
  10887. boundingBox.max.subtractToRef(boundingBox.min, diff);
  10888. diff.scaleInPlace(0.5);
  10889. babylonjs_1.Vector3.TransformNormalToRef(diff, currentInverseWorld, extendSize);
  10890. this._cellWidth = Math.max(this._cellWidth, extendSize.x * 2);
  10891. this._cellHeight = Math.max(this._cellHeight, extendSize.y * 2);
  10892. }
  10893. this._cellWidth += this.margin * 2;
  10894. this._cellHeight += this.margin * 2;
  10895. // Arrange
  10896. if (this._rowThenColum) {
  10897. columns = this._columns;
  10898. rows = Math.ceil(controlCount / this._columns);
  10899. }
  10900. else {
  10901. rows = this._rows;
  10902. columns = Math.ceil(controlCount / this._rows);
  10903. }
  10904. var startOffsetX = (columns * 0.5) * this._cellWidth;
  10905. var startOffsetY = (rows * 0.5) * this._cellHeight;
  10906. var nodeGrid = [];
  10907. var cellCounter = 0;
  10908. if (this._rowThenColum) {
  10909. for (var r = 0; r < rows; r++) {
  10910. for (var c = 0; c < columns; c++) {
  10911. nodeGrid.push(new babylonjs_1.Vector3((c * this._cellWidth) - startOffsetX + this._cellWidth / 2, (r * this._cellHeight) - startOffsetY + this._cellHeight / 2, 0));
  10912. cellCounter++;
  10913. if (cellCounter > controlCount) {
  10914. break;
  10915. }
  10916. }
  10917. }
  10918. }
  10919. else {
  10920. for (var c = 0; c < columns; c++) {
  10921. for (var r = 0; r < rows; r++) {
  10922. nodeGrid.push(new babylonjs_1.Vector3((c * this._cellWidth) - startOffsetX + this._cellWidth / 2, (r * this._cellHeight) - startOffsetY + this._cellHeight / 2, 0));
  10923. cellCounter++;
  10924. if (cellCounter > controlCount) {
  10925. break;
  10926. }
  10927. }
  10928. }
  10929. }
  10930. cellCounter = 0;
  10931. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  10932. var child = _c[_b];
  10933. if (!child.mesh) {
  10934. continue;
  10935. }
  10936. this._mapGridNode(child, nodeGrid[cellCounter]);
  10937. cellCounter++;
  10938. }
  10939. this._finalProcessing();
  10940. };
  10941. /** Child classes can implement this function to provide additional processing */
  10942. VolumeBasedPanel.prototype._finalProcessing = function () {
  10943. };
  10944. return VolumeBasedPanel;
  10945. }(container3D_1.Container3D));
  10946. exports.VolumeBasedPanel = VolumeBasedPanel;
  10947. /***/ }),
  10948. /***/ "./src/3D/gui3DManager.ts":
  10949. /*!********************************!*\
  10950. !*** ./src/3D/gui3DManager.ts ***!
  10951. \********************************/
  10952. /*! no static exports found */
  10953. /***/ (function(module, exports, __webpack_require__) {
  10954. "use strict";
  10955. Object.defineProperty(exports, "__esModule", { value: true });
  10956. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  10957. var container3D_1 = __webpack_require__(/*! ./controls/container3D */ "./src/3D/controls/container3D.ts");
  10958. /**
  10959. * Class used to manage 3D user interface
  10960. * @see http://doc.babylonjs.com/how_to/gui3d
  10961. */
  10962. var GUI3DManager = /** @class */ (function () {
  10963. /**
  10964. * Creates a new GUI3DManager
  10965. * @param scene
  10966. */
  10967. function GUI3DManager(scene) {
  10968. var _this = this;
  10969. /** @hidden */
  10970. this._lastControlOver = {};
  10971. /** @hidden */
  10972. this._lastControlDown = {};
  10973. /**
  10974. * Observable raised when the point picked by the pointer events changed
  10975. */
  10976. this.onPickedPointChangedObservable = new babylonjs_1.Observable();
  10977. // Shared resources
  10978. /** @hidden */
  10979. this._sharedMaterials = {};
  10980. this._scene = scene || babylonjs_1.Engine.LastCreatedScene;
  10981. this._sceneDisposeObserver = this._scene.onDisposeObservable.add(function () {
  10982. _this._sceneDisposeObserver = null;
  10983. _this._utilityLayer = null;
  10984. _this.dispose();
  10985. });
  10986. this._utilityLayer = new babylonjs_1.UtilityLayerRenderer(this._scene);
  10987. this._utilityLayer.onlyCheckPointerDownEvents = false;
  10988. this._utilityLayer.mainSceneTrackerPredicate = function (mesh) {
  10989. return mesh && mesh.metadata && mesh.metadata._node;
  10990. };
  10991. // Root
  10992. this._rootContainer = new container3D_1.Container3D("RootContainer");
  10993. this._rootContainer._host = this;
  10994. var utilityLayerScene = this._utilityLayer.utilityLayerScene;
  10995. // Events
  10996. this._pointerOutObserver = this._utilityLayer.onPointerOutObservable.add(function (pointerId) {
  10997. _this._handlePointerOut(pointerId, true);
  10998. });
  10999. this._pointerObserver = utilityLayerScene.onPointerObservable.add(function (pi, state) {
  11000. _this._doPicking(pi);
  11001. });
  11002. // Scene
  11003. this._utilityLayer.utilityLayerScene.autoClear = false;
  11004. this._utilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
  11005. new babylonjs_1.HemisphericLight("hemi", babylonjs_1.Vector3.Up(), this._utilityLayer.utilityLayerScene);
  11006. }
  11007. Object.defineProperty(GUI3DManager.prototype, "scene", {
  11008. /** Gets the hosting scene */
  11009. get: function () {
  11010. return this._scene;
  11011. },
  11012. enumerable: true,
  11013. configurable: true
  11014. });
  11015. Object.defineProperty(GUI3DManager.prototype, "utilityLayer", {
  11016. /** Gets associated utility layer */
  11017. get: function () {
  11018. return this._utilityLayer;
  11019. },
  11020. enumerable: true,
  11021. configurable: true
  11022. });
  11023. GUI3DManager.prototype._handlePointerOut = function (pointerId, isPointerUp) {
  11024. var previousControlOver = this._lastControlOver[pointerId];
  11025. if (previousControlOver) {
  11026. previousControlOver._onPointerOut(previousControlOver);
  11027. delete this._lastControlOver[pointerId];
  11028. }
  11029. if (isPointerUp) {
  11030. if (this._lastControlDown[pointerId]) {
  11031. this._lastControlDown[pointerId].forcePointerUp();
  11032. delete this._lastControlDown[pointerId];
  11033. }
  11034. }
  11035. this.onPickedPointChangedObservable.notifyObservers(null);
  11036. };
  11037. GUI3DManager.prototype._doPicking = function (pi) {
  11038. if (!this._utilityLayer || !this._utilityLayer.utilityLayerScene.activeCamera) {
  11039. return false;
  11040. }
  11041. var pointerEvent = (pi.event);
  11042. var pointerId = pointerEvent.pointerId || 0;
  11043. var buttonIndex = pointerEvent.button;
  11044. var pickingInfo = pi.pickInfo;
  11045. if (!pickingInfo || !pickingInfo.hit) {
  11046. this._handlePointerOut(pointerId, pi.type === babylonjs_1.PointerEventTypes.POINTERUP);
  11047. return false;
  11048. }
  11049. var control = (pickingInfo.pickedMesh.metadata);
  11050. if (pickingInfo.pickedPoint) {
  11051. this.onPickedPointChangedObservable.notifyObservers(pickingInfo.pickedPoint);
  11052. }
  11053. if (!control._processObservables(pi.type, pickingInfo.pickedPoint, pointerId, buttonIndex)) {
  11054. if (pi.type === babylonjs_1.PointerEventTypes.POINTERMOVE) {
  11055. if (this._lastControlOver[pointerId]) {
  11056. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  11057. }
  11058. delete this._lastControlOver[pointerId];
  11059. }
  11060. }
  11061. if (pi.type === babylonjs_1.PointerEventTypes.POINTERUP) {
  11062. if (this._lastControlDown[pointerEvent.pointerId]) {
  11063. this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  11064. delete this._lastControlDown[pointerEvent.pointerId];
  11065. }
  11066. if (pointerEvent.pointerType === "touch") {
  11067. this._handlePointerOut(pointerId, false);
  11068. }
  11069. }
  11070. return true;
  11071. };
  11072. Object.defineProperty(GUI3DManager.prototype, "rootContainer", {
  11073. /**
  11074. * Gets the root container
  11075. */
  11076. get: function () {
  11077. return this._rootContainer;
  11078. },
  11079. enumerable: true,
  11080. configurable: true
  11081. });
  11082. /**
  11083. * Gets a boolean indicating if the given control is in the root child list
  11084. * @param control defines the control to check
  11085. * @returns true if the control is in the root child list
  11086. */
  11087. GUI3DManager.prototype.containsControl = function (control) {
  11088. return this._rootContainer.containsControl(control);
  11089. };
  11090. /**
  11091. * Adds a control to the root child list
  11092. * @param control defines the control to add
  11093. * @returns the current manager
  11094. */
  11095. GUI3DManager.prototype.addControl = function (control) {
  11096. this._rootContainer.addControl(control);
  11097. return this;
  11098. };
  11099. /**
  11100. * Removes a control from the root child list
  11101. * @param control defines the control to remove
  11102. * @returns the current container
  11103. */
  11104. GUI3DManager.prototype.removeControl = function (control) {
  11105. this._rootContainer.removeControl(control);
  11106. return this;
  11107. };
  11108. /**
  11109. * Releases all associated resources
  11110. */
  11111. GUI3DManager.prototype.dispose = function () {
  11112. this._rootContainer.dispose();
  11113. for (var materialName in this._sharedMaterials) {
  11114. if (!this._sharedMaterials.hasOwnProperty(materialName)) {
  11115. continue;
  11116. }
  11117. this._sharedMaterials[materialName].dispose();
  11118. }
  11119. this._sharedMaterials = {};
  11120. if (this._pointerOutObserver && this._utilityLayer) {
  11121. this._utilityLayer.onPointerOutObservable.remove(this._pointerOutObserver);
  11122. this._pointerOutObserver = null;
  11123. }
  11124. this.onPickedPointChangedObservable.clear();
  11125. var utilityLayerScene = this._utilityLayer ? this._utilityLayer.utilityLayerScene : null;
  11126. if (utilityLayerScene) {
  11127. if (this._pointerObserver) {
  11128. utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
  11129. this._pointerObserver = null;
  11130. }
  11131. }
  11132. if (this._scene) {
  11133. if (this._sceneDisposeObserver) {
  11134. this._scene.onDisposeObservable.remove(this._sceneDisposeObserver);
  11135. this._sceneDisposeObserver = null;
  11136. }
  11137. }
  11138. if (this._utilityLayer) {
  11139. this._utilityLayer.dispose();
  11140. }
  11141. };
  11142. return GUI3DManager;
  11143. }());
  11144. exports.GUI3DManager = GUI3DManager;
  11145. /***/ }),
  11146. /***/ "./src/3D/index.ts":
  11147. /*!*************************!*\
  11148. !*** ./src/3D/index.ts ***!
  11149. \*************************/
  11150. /*! no static exports found */
  11151. /***/ (function(module, exports, __webpack_require__) {
  11152. "use strict";
  11153. function __export(m) {
  11154. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  11155. }
  11156. Object.defineProperty(exports, "__esModule", { value: true });
  11157. __export(__webpack_require__(/*! ./controls */ "./src/3D/controls/index.ts"));
  11158. __export(__webpack_require__(/*! ./materials */ "./src/3D/materials/index.ts"));
  11159. __export(__webpack_require__(/*! ./gui3DManager */ "./src/3D/gui3DManager.ts"));
  11160. __export(__webpack_require__(/*! ./vector3WithInfo */ "./src/3D/vector3WithInfo.ts"));
  11161. /***/ }),
  11162. /***/ "./src/3D/materials/fluentMaterial.ts":
  11163. /*!********************************************!*\
  11164. !*** ./src/3D/materials/fluentMaterial.ts ***!
  11165. \********************************************/
  11166. /*! no static exports found */
  11167. /***/ (function(module, exports, __webpack_require__) {
  11168. "use strict";
  11169. var __extends = (this && this.__extends) || (function () {
  11170. var extendStatics = function (d, b) {
  11171. extendStatics = Object.setPrototypeOf ||
  11172. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  11173. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  11174. return extendStatics(d, b);
  11175. }
  11176. return function (d, b) {
  11177. extendStatics(d, b);
  11178. function __() { this.constructor = d; }
  11179. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11180. };
  11181. })();
  11182. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  11183. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  11184. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  11185. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  11186. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11187. };
  11188. Object.defineProperty(exports, "__esModule", { value: true });
  11189. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  11190. __webpack_require__(/*! ./shaders/fluent.vertex */ "./src/3D/materials/shaders/fluent.vertex.ts");
  11191. __webpack_require__(/*! ./shaders/fluent.fragment */ "./src/3D/materials/shaders/fluent.fragment.ts");
  11192. /** @hidden */
  11193. var FluentMaterialDefines = /** @class */ (function (_super) {
  11194. __extends(FluentMaterialDefines, _super);
  11195. function FluentMaterialDefines() {
  11196. var _this = _super.call(this) || this;
  11197. _this.INNERGLOW = false;
  11198. _this.BORDER = false;
  11199. _this.HOVERLIGHT = false;
  11200. _this.TEXTURE = false;
  11201. _this.rebuild();
  11202. return _this;
  11203. }
  11204. return FluentMaterialDefines;
  11205. }(babylonjs_1.MaterialDefines));
  11206. exports.FluentMaterialDefines = FluentMaterialDefines;
  11207. /**
  11208. * Class used to render controls with fluent desgin
  11209. */
  11210. var FluentMaterial = /** @class */ (function (_super) {
  11211. __extends(FluentMaterial, _super);
  11212. /**
  11213. * Creates a new Fluent material
  11214. * @param name defines the name of the material
  11215. * @param scene defines the hosting scene
  11216. */
  11217. function FluentMaterial(name, scene) {
  11218. var _this = _super.call(this, name, scene) || this;
  11219. /**
  11220. * Gets or sets inner glow intensity. A value of 0 means no glow (default is 0.5)
  11221. */
  11222. _this.innerGlowColorIntensity = 0.5;
  11223. /**
  11224. * Gets or sets the inner glow color (white by default)
  11225. */
  11226. _this.innerGlowColor = new babylonjs_1.Color3(1.0, 1.0, 1.0);
  11227. /**
  11228. * Gets or sets alpha value (default is 1.0)
  11229. */
  11230. _this.alpha = 1.0;
  11231. /**
  11232. * Gets or sets the albedo color (Default is Color3(0.3, 0.35, 0.4))
  11233. */
  11234. _this.albedoColor = new babylonjs_1.Color3(0.3, 0.35, 0.4);
  11235. /**
  11236. * Gets or sets a boolean indicating if borders must be rendered (default is false)
  11237. */
  11238. _this.renderBorders = false;
  11239. /**
  11240. * Gets or sets border width (default is 0.5)
  11241. */
  11242. _this.borderWidth = 0.5;
  11243. /**
  11244. * Gets or sets a value indicating the smoothing value applied to border edges (0.02 by default)
  11245. */
  11246. _this.edgeSmoothingValue = 0.02;
  11247. /**
  11248. * Gets or sets the minimum value that can be applied to border width (default is 0.1)
  11249. */
  11250. _this.borderMinValue = 0.1;
  11251. /**
  11252. * Gets or sets a boolean indicating if hover light must be rendered (default is false)
  11253. */
  11254. _this.renderHoverLight = false;
  11255. /**
  11256. * Gets or sets the radius used to render the hover light (default is 1.0)
  11257. */
  11258. _this.hoverRadius = 1.0;
  11259. /**
  11260. * Gets or sets the color used to render the hover light (default is Color4(0.3, 0.3, 0.3, 1.0))
  11261. */
  11262. _this.hoverColor = new babylonjs_1.Color4(0.3, 0.3, 0.3, 1.0);
  11263. /**
  11264. * Gets or sets the hover light position in world space (default is Vector3.Zero())
  11265. */
  11266. _this.hoverPosition = babylonjs_1.Vector3.Zero();
  11267. return _this;
  11268. }
  11269. FluentMaterial.prototype.needAlphaBlending = function () {
  11270. return this.alpha !== 1.0;
  11271. };
  11272. FluentMaterial.prototype.needAlphaTesting = function () {
  11273. return false;
  11274. };
  11275. FluentMaterial.prototype.getAlphaTestTexture = function () {
  11276. return null;
  11277. };
  11278. FluentMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  11279. if (this.isFrozen) {
  11280. if (this._wasPreviouslyReady && subMesh.effect) {
  11281. return true;
  11282. }
  11283. }
  11284. if (!subMesh._materialDefines) {
  11285. subMesh._materialDefines = new FluentMaterialDefines();
  11286. }
  11287. var scene = this.getScene();
  11288. var defines = subMesh._materialDefines;
  11289. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  11290. if (defines._renderId === scene.getRenderId()) {
  11291. return true;
  11292. }
  11293. }
  11294. if (defines._areTexturesDirty) {
  11295. defines.INNERGLOW = this.innerGlowColorIntensity > 0;
  11296. defines.BORDER = this.renderBorders;
  11297. defines.HOVERLIGHT = this.renderHoverLight;
  11298. if (this._albedoTexture) {
  11299. if (!this._albedoTexture.isReadyOrNotBlocking()) {
  11300. return false;
  11301. }
  11302. else {
  11303. defines.TEXTURE = true;
  11304. }
  11305. }
  11306. else {
  11307. defines.TEXTURE = false;
  11308. }
  11309. }
  11310. var engine = scene.getEngine();
  11311. // Get correct effect
  11312. if (defines.isDirty) {
  11313. defines.markAsProcessed();
  11314. scene.resetCachedMaterial();
  11315. //Attributes
  11316. var attribs = [babylonjs_1.VertexBuffer.PositionKind];
  11317. attribs.push(babylonjs_1.VertexBuffer.NormalKind);
  11318. attribs.push(babylonjs_1.VertexBuffer.UVKind);
  11319. var shaderName = "fluent";
  11320. var uniforms = ["world", "viewProjection", "innerGlowColor", "albedoColor", "borderWidth", "edgeSmoothingValue", "scaleFactor", "borderMinValue",
  11321. "hoverColor", "hoverPosition", "hoverRadius"
  11322. ];
  11323. var samplers = ["albedoSampler"];
  11324. var uniformBuffers = new Array();
  11325. babylonjs_1.MaterialHelper.PrepareUniformsAndSamplersList({
  11326. uniformsNames: uniforms,
  11327. uniformBuffersNames: uniformBuffers,
  11328. samplers: samplers,
  11329. defines: defines,
  11330. maxSimultaneousLights: 4
  11331. });
  11332. var join = defines.toString();
  11333. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  11334. attributes: attribs,
  11335. uniformsNames: uniforms,
  11336. uniformBuffersNames: uniformBuffers,
  11337. samplers: samplers,
  11338. defines: join,
  11339. fallbacks: null,
  11340. onCompiled: this.onCompiled,
  11341. onError: this.onError,
  11342. indexParameters: { maxSimultaneousLights: 4 }
  11343. }, engine));
  11344. }
  11345. if (!subMesh.effect || !subMesh.effect.isReady()) {
  11346. return false;
  11347. }
  11348. defines._renderId = scene.getRenderId();
  11349. this._wasPreviouslyReady = true;
  11350. return true;
  11351. };
  11352. FluentMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  11353. var scene = this.getScene();
  11354. var defines = subMesh._materialDefines;
  11355. if (!defines) {
  11356. return;
  11357. }
  11358. var effect = subMesh.effect;
  11359. if (!effect) {
  11360. return;
  11361. }
  11362. this._activeEffect = effect;
  11363. // Matrices
  11364. this.bindOnlyWorldMatrix(world);
  11365. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  11366. if (this._mustRebind(scene, effect)) {
  11367. this._activeEffect.setColor4("albedoColor", this.albedoColor, this.alpha);
  11368. if (defines.INNERGLOW) {
  11369. this._activeEffect.setColor4("innerGlowColor", this.innerGlowColor, this.innerGlowColorIntensity);
  11370. }
  11371. if (defines.BORDER) {
  11372. this._activeEffect.setFloat("borderWidth", this.borderWidth);
  11373. this._activeEffect.setFloat("edgeSmoothingValue", this.edgeSmoothingValue);
  11374. this._activeEffect.setFloat("borderMinValue", this.borderMinValue);
  11375. mesh.getBoundingInfo().boundingBox.extendSize.multiplyToRef(mesh.scaling, babylonjs_1.Tmp.Vector3[0]);
  11376. this._activeEffect.setVector3("scaleFactor", babylonjs_1.Tmp.Vector3[0]);
  11377. }
  11378. if (defines.HOVERLIGHT) {
  11379. this._activeEffect.setDirectColor4("hoverColor", this.hoverColor);
  11380. this._activeEffect.setFloat("hoverRadius", this.hoverRadius);
  11381. this._activeEffect.setVector3("hoverPosition", this.hoverPosition);
  11382. }
  11383. if (defines.TEXTURE) {
  11384. this._activeEffect.setTexture("albedoSampler", this._albedoTexture);
  11385. }
  11386. }
  11387. this._afterBind(mesh, this._activeEffect);
  11388. };
  11389. FluentMaterial.prototype.getActiveTextures = function () {
  11390. var activeTextures = _super.prototype.getActiveTextures.call(this);
  11391. return activeTextures;
  11392. };
  11393. FluentMaterial.prototype.hasTexture = function (texture) {
  11394. if (_super.prototype.hasTexture.call(this, texture)) {
  11395. return true;
  11396. }
  11397. return false;
  11398. };
  11399. FluentMaterial.prototype.dispose = function (forceDisposeEffect) {
  11400. _super.prototype.dispose.call(this, forceDisposeEffect);
  11401. };
  11402. FluentMaterial.prototype.clone = function (name) {
  11403. var _this = this;
  11404. return babylonjs_1.SerializationHelper.Clone(function () { return new FluentMaterial(name, _this.getScene()); }, this);
  11405. };
  11406. FluentMaterial.prototype.serialize = function () {
  11407. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this);
  11408. serializationObject.customType = "BABYLON.GUI.FluentMaterial";
  11409. return serializationObject;
  11410. };
  11411. FluentMaterial.prototype.getClassName = function () {
  11412. return "FluentMaterial";
  11413. };
  11414. // Statics
  11415. FluentMaterial.Parse = function (source, scene, rootUrl) {
  11416. return babylonjs_1.SerializationHelper.Parse(function () { return new FluentMaterial(source.name, scene); }, source, scene, rootUrl);
  11417. };
  11418. __decorate([
  11419. babylonjs_1.serialize(),
  11420. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  11421. ], FluentMaterial.prototype, "innerGlowColorIntensity", void 0);
  11422. __decorate([
  11423. babylonjs_1.serializeAsColor3()
  11424. ], FluentMaterial.prototype, "innerGlowColor", void 0);
  11425. __decorate([
  11426. babylonjs_1.serialize()
  11427. ], FluentMaterial.prototype, "alpha", void 0);
  11428. __decorate([
  11429. babylonjs_1.serializeAsColor3()
  11430. ], FluentMaterial.prototype, "albedoColor", void 0);
  11431. __decorate([
  11432. babylonjs_1.serialize(),
  11433. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  11434. ], FluentMaterial.prototype, "renderBorders", void 0);
  11435. __decorate([
  11436. babylonjs_1.serialize()
  11437. ], FluentMaterial.prototype, "borderWidth", void 0);
  11438. __decorate([
  11439. babylonjs_1.serialize()
  11440. ], FluentMaterial.prototype, "edgeSmoothingValue", void 0);
  11441. __decorate([
  11442. babylonjs_1.serialize()
  11443. ], FluentMaterial.prototype, "borderMinValue", void 0);
  11444. __decorate([
  11445. babylonjs_1.serialize(),
  11446. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  11447. ], FluentMaterial.prototype, "renderHoverLight", void 0);
  11448. __decorate([
  11449. babylonjs_1.serialize()
  11450. ], FluentMaterial.prototype, "hoverRadius", void 0);
  11451. __decorate([
  11452. babylonjs_1.serializeAsColor4()
  11453. ], FluentMaterial.prototype, "hoverColor", void 0);
  11454. __decorate([
  11455. babylonjs_1.serializeAsVector3()
  11456. ], FluentMaterial.prototype, "hoverPosition", void 0);
  11457. __decorate([
  11458. babylonjs_1.serializeAsTexture("albedoTexture")
  11459. ], FluentMaterial.prototype, "_albedoTexture", void 0);
  11460. __decorate([
  11461. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")
  11462. ], FluentMaterial.prototype, "albedoTexture", void 0);
  11463. return FluentMaterial;
  11464. }(babylonjs_1.PushMaterial));
  11465. exports.FluentMaterial = FluentMaterial;
  11466. /***/ }),
  11467. /***/ "./src/3D/materials/index.ts":
  11468. /*!***********************************!*\
  11469. !*** ./src/3D/materials/index.ts ***!
  11470. \***********************************/
  11471. /*! no static exports found */
  11472. /***/ (function(module, exports, __webpack_require__) {
  11473. "use strict";
  11474. function __export(m) {
  11475. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  11476. }
  11477. Object.defineProperty(exports, "__esModule", { value: true });
  11478. __export(__webpack_require__(/*! ./fluentMaterial */ "./src/3D/materials/fluentMaterial.ts"));
  11479. /***/ }),
  11480. /***/ "./src/3D/materials/shaders/fluent.fragment.ts":
  11481. /*!*****************************************************!*\
  11482. !*** ./src/3D/materials/shaders/fluent.fragment.ts ***!
  11483. \*****************************************************/
  11484. /*! no static exports found */
  11485. /***/ (function(module, exports, __webpack_require__) {
  11486. "use strict";
  11487. Object.defineProperty(exports, "__esModule", { value: true });
  11488. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  11489. var name = 'fluentPixelShader';
  11490. exports.name = name;
  11491. var shader = "precision highp float;\nvarying vec2 vUV;\nuniform vec4 albedoColor;\n#ifdef INNERGLOW\nuniform vec4 innerGlowColor;\n#endif\n#ifdef BORDER\nvarying vec2 scaleInfo;\nuniform float edgeSmoothingValue;\nuniform float borderMinValue;\n#endif\n#ifdef HOVERLIGHT\nvarying vec3 worldPosition;\nuniform vec3 hoverPosition;\nuniform vec4 hoverColor;\nuniform float hoverRadius;\n#endif\n#ifdef TEXTURE\nuniform sampler2D albedoSampler;\n#endif\nvoid main(void) {\nvec3 albedo=albedoColor.rgb;\nfloat alpha=albedoColor.a;\n#ifdef TEXTURE\nalbedo=texture2D(albedoSampler,vUV).rgb;\n#endif\n#ifdef HOVERLIGHT\nfloat pointToHover=(1.0-clamp(length(hoverPosition-worldPosition)/hoverRadius,0.,1.))*hoverColor.a;\nalbedo=clamp(albedo+hoverColor.rgb*pointToHover,0.,1.);\n#else\nfloat pointToHover=1.0;\n#endif\n#ifdef BORDER\nfloat borderPower=10.0;\nfloat inverseBorderPower=1.0/borderPower;\nvec3 borderColor=albedo*borderPower;\nvec2 distanceToEdge;\ndistanceToEdge.x=abs(vUV.x-0.5)*2.0;\ndistanceToEdge.y=abs(vUV.y-0.5)*2.0;\nfloat borderValue=max(smoothstep(scaleInfo.x-edgeSmoothingValue,scaleInfo.x+edgeSmoothingValue,distanceToEdge.x),\nsmoothstep(scaleInfo.y-edgeSmoothingValue,scaleInfo.y+edgeSmoothingValue,distanceToEdge.y));\nborderColor=borderColor*borderValue*max(borderMinValue*inverseBorderPower,pointToHover);\nalbedo+=borderColor;\nalpha=max(alpha,borderValue);\n#endif\n#ifdef INNERGLOW\n\nvec2 uvGlow=(vUV-vec2(0.5,0.5))*(innerGlowColor.a*2.0);\nuvGlow=uvGlow*uvGlow;\nuvGlow=uvGlow*uvGlow;\nalbedo+=mix(vec3(0.0,0.0,0.0),innerGlowColor.rgb,uvGlow.x+uvGlow.y);\n#endif\ngl_FragColor=vec4(albedo,alpha);\n}";
  11492. exports.shader = shader;
  11493. babylonjs_1.Effect.ShadersStore[name] = shader;
  11494. /***/ }),
  11495. /***/ "./src/3D/materials/shaders/fluent.vertex.ts":
  11496. /*!***************************************************!*\
  11497. !*** ./src/3D/materials/shaders/fluent.vertex.ts ***!
  11498. \***************************************************/
  11499. /*! no static exports found */
  11500. /***/ (function(module, exports, __webpack_require__) {
  11501. "use strict";
  11502. Object.defineProperty(exports, "__esModule", { value: true });
  11503. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  11504. var name = 'fluentVertexShader';
  11505. exports.name = name;
  11506. var shader = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n\nuniform mat4 world;\nuniform mat4 viewProjection;\nvarying vec2 vUV;\n#ifdef BORDER\nvarying vec2 scaleInfo;\nuniform float borderWidth;\nuniform vec3 scaleFactor;\n#endif\n#ifdef HOVERLIGHT\nvarying vec3 worldPosition;\n#endif\nvoid main(void) {\nvUV=uv;\n#ifdef BORDER\nvec3 scale=scaleFactor;\nfloat minScale=min(min(scale.x,scale.y),scale.z);\nfloat maxScale=max(max(scale.x,scale.y),scale.z);\nfloat minOverMiddleScale=minScale/(scale.x+scale.y+scale.z-minScale-maxScale);\nfloat areaYZ=scale.y*scale.z;\nfloat areaXZ=scale.x*scale.z;\nfloat areaXY=scale.x*scale.y;\nfloat scaledBorderWidth=borderWidth;\nif (abs(normal.x) == 1.0)\n{\nscale.x=scale.y;\nscale.y=scale.z;\nif (areaYZ>areaXZ && areaYZ>areaXY)\n{\nscaledBorderWidth*=minOverMiddleScale;\n}\n}\nelse if (abs(normal.y) == 1.0)\n{\nscale.x=scale.z;\nif (areaXZ>areaXY && areaXZ>areaYZ)\n{\nscaledBorderWidth*=minOverMiddleScale;\n}\n}\nelse\n{\nif (areaXY>areaYZ && areaXY>areaXZ)\n{\nscaledBorderWidth*=minOverMiddleScale;\n}\n}\nfloat scaleRatio=min(scale.x,scale.y)/max(scale.x,scale.y);\nif (scale.x>scale.y)\n{\nscaleInfo.x=1.0-(scaledBorderWidth*scaleRatio);\nscaleInfo.y=1.0-scaledBorderWidth;\n}\nelse\n{\nscaleInfo.x=1.0-scaledBorderWidth;\nscaleInfo.y=1.0-(scaledBorderWidth*scaleRatio);\n}\n#endif\nvec4 worldPos=world*vec4(position,1.0);\n#ifdef HOVERLIGHT\nworldPosition=worldPos.xyz;\n#endif\ngl_Position=viewProjection*worldPos;\n}\n";
  11507. exports.shader = shader;
  11508. babylonjs_1.Effect.ShadersStore[name] = shader;
  11509. /***/ }),
  11510. /***/ "./src/3D/vector3WithInfo.ts":
  11511. /*!***********************************!*\
  11512. !*** ./src/3D/vector3WithInfo.ts ***!
  11513. \***********************************/
  11514. /*! no static exports found */
  11515. /***/ (function(module, exports, __webpack_require__) {
  11516. "use strict";
  11517. var __extends = (this && this.__extends) || (function () {
  11518. var extendStatics = function (d, b) {
  11519. extendStatics = Object.setPrototypeOf ||
  11520. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  11521. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  11522. return extendStatics(d, b);
  11523. }
  11524. return function (d, b) {
  11525. extendStatics(d, b);
  11526. function __() { this.constructor = d; }
  11527. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11528. };
  11529. })();
  11530. Object.defineProperty(exports, "__esModule", { value: true });
  11531. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  11532. /**
  11533. * Class used to transport Vector3 information for pointer events
  11534. */
  11535. var Vector3WithInfo = /** @class */ (function (_super) {
  11536. __extends(Vector3WithInfo, _super);
  11537. /**
  11538. * Creates a new Vector3WithInfo
  11539. * @param source defines the vector3 data to transport
  11540. * @param buttonIndex defines the current mouse button index
  11541. */
  11542. function Vector3WithInfo(source,
  11543. /** defines the current mouse button index */
  11544. buttonIndex) {
  11545. if (buttonIndex === void 0) { buttonIndex = 0; }
  11546. var _this = _super.call(this, source.x, source.y, source.z) || this;
  11547. _this.buttonIndex = buttonIndex;
  11548. return _this;
  11549. }
  11550. return Vector3WithInfo;
  11551. }(babylonjs_1.Vector3));
  11552. exports.Vector3WithInfo = Vector3WithInfo;
  11553. /***/ }),
  11554. /***/ "./src/index.ts":
  11555. /*!**********************!*\
  11556. !*** ./src/index.ts ***!
  11557. \**********************/
  11558. /*! no static exports found */
  11559. /***/ (function(module, exports, __webpack_require__) {
  11560. "use strict";
  11561. function __export(m) {
  11562. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  11563. }
  11564. Object.defineProperty(exports, "__esModule", { value: true });
  11565. __export(__webpack_require__(/*! ./2D */ "./src/2D/index.ts"));
  11566. __export(__webpack_require__(/*! ./3D */ "./src/3D/index.ts"));
  11567. /***/ }),
  11568. /***/ "babylonjs":
  11569. /*!****************************************************************************************************!*\
  11570. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  11571. \****************************************************************************************************/
  11572. /*! no static exports found */
  11573. /***/ (function(module, exports) {
  11574. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  11575. /***/ })
  11576. /******/ });
  11577. });
  11578. //# sourceMappingURL=babylon.gui.js.map