babylon.gui.js 397 KB

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