babylon.gui.js 347 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886
  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 = 0;
  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. this._enterCount++;
  2513. var canNotify = this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  2514. if (canNotify && this.parent != null)
  2515. this.parent._onPointerEnter(target);
  2516. return true;
  2517. };
  2518. /** @hidden */
  2519. Control.prototype._onPointerOut = function (target) {
  2520. this._enterCount = 0;
  2521. var canNotify = this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  2522. if (canNotify && this.parent != null)
  2523. this.parent._onPointerOut(target);
  2524. };
  2525. /** @hidden */
  2526. Control.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  2527. if (this._downCount !== 0) {
  2528. return false;
  2529. }
  2530. this._downCount++;
  2531. this._downPointerIds[pointerId] = true;
  2532. var canNotify = this.onPointerDownObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  2533. if (canNotify && this.parent != null)
  2534. this.parent._onPointerDown(target, coordinates, pointerId, buttonIndex);
  2535. return true;
  2536. };
  2537. /** @hidden */
  2538. Control.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  2539. this._downCount = 0;
  2540. delete this._downPointerIds[pointerId];
  2541. var canNotifyClick = notifyClick;
  2542. if (notifyClick && this._enterCount > 0) {
  2543. canNotifyClick = this.onPointerClickObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  2544. }
  2545. var canNotify = this.onPointerUpObservable.notifyObservers(new GUI.Vector2WithInfo(coordinates, buttonIndex), -1, target, this);
  2546. if (canNotify && this.parent != null)
  2547. this.parent._onPointerUp(target, coordinates, pointerId, buttonIndex, canNotifyClick);
  2548. };
  2549. /** @hidden */
  2550. Control.prototype._forcePointerUp = function (pointerId) {
  2551. if (pointerId === void 0) { pointerId = null; }
  2552. if (pointerId !== null) {
  2553. this._onPointerUp(this, BABYLON.Vector2.Zero(), pointerId, 0, true);
  2554. }
  2555. else {
  2556. for (var key in this._downPointerIds) {
  2557. this._onPointerUp(this, BABYLON.Vector2.Zero(), +key, 0, true);
  2558. }
  2559. }
  2560. };
  2561. /** @hidden */
  2562. Control.prototype._processObservables = function (type, x, y, pointerId, buttonIndex) {
  2563. this._dummyVector2.copyFromFloats(x, y);
  2564. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  2565. this._onPointerMove(this, this._dummyVector2);
  2566. var previousControlOver = this._host._lastControlOver[pointerId];
  2567. if (previousControlOver && previousControlOver !== this) {
  2568. previousControlOver._onPointerOut(this);
  2569. }
  2570. if (previousControlOver !== this) {
  2571. this._onPointerEnter(this);
  2572. }
  2573. this._host._lastControlOver[pointerId] = this;
  2574. return true;
  2575. }
  2576. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  2577. this._onPointerDown(this, this._dummyVector2, pointerId, buttonIndex);
  2578. this._host._lastControlDown[pointerId] = this;
  2579. this._host._lastPickedControl = this;
  2580. return true;
  2581. }
  2582. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  2583. if (this._host._lastControlDown[pointerId]) {
  2584. this._host._lastControlDown[pointerId]._onPointerUp(this, this._dummyVector2, pointerId, buttonIndex, true);
  2585. }
  2586. delete this._host._lastControlDown[pointerId];
  2587. return true;
  2588. }
  2589. return false;
  2590. };
  2591. Control.prototype._prepareFont = function () {
  2592. if (!this._font && !this._fontSet) {
  2593. return;
  2594. }
  2595. if (this._style) {
  2596. this._font = (this._style.fontWeight ? this._style.fontWeight : this._style.fontStyle) + " " + this.fontSizeInPixels + "px " + this._style.fontFamily;
  2597. }
  2598. else {
  2599. this._font = (this._fontWeight ? this._fontWeight : this._fontStyle) + " " + this.fontSizeInPixels + "px " + this._fontFamily;
  2600. }
  2601. this._fontOffset = Control._GetFontOffset(this._font);
  2602. };
  2603. /** Releases associated resources */
  2604. Control.prototype.dispose = function () {
  2605. this.onDirtyObservable.clear();
  2606. this.onAfterDrawObservable.clear();
  2607. this.onPointerDownObservable.clear();
  2608. this.onPointerEnterObservable.clear();
  2609. this.onPointerMoveObservable.clear();
  2610. this.onPointerOutObservable.clear();
  2611. this.onPointerUpObservable.clear();
  2612. this.onPointerClickObservable.clear();
  2613. if (this._styleObserver && this._style) {
  2614. this._style.onChangedObservable.remove(this._styleObserver);
  2615. this._styleObserver = null;
  2616. }
  2617. if (this._root) {
  2618. this._root.removeControl(this);
  2619. this._root = null;
  2620. }
  2621. var index = this._host._linkedControls.indexOf(this);
  2622. if (index > -1) {
  2623. this.linkWithMesh(null);
  2624. }
  2625. };
  2626. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_LEFT", {
  2627. /** HORIZONTAL_ALIGNMENT_LEFT */
  2628. get: function () {
  2629. return Control._HORIZONTAL_ALIGNMENT_LEFT;
  2630. },
  2631. enumerable: true,
  2632. configurable: true
  2633. });
  2634. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_RIGHT", {
  2635. /** HORIZONTAL_ALIGNMENT_RIGHT */
  2636. get: function () {
  2637. return Control._HORIZONTAL_ALIGNMENT_RIGHT;
  2638. },
  2639. enumerable: true,
  2640. configurable: true
  2641. });
  2642. Object.defineProperty(Control, "HORIZONTAL_ALIGNMENT_CENTER", {
  2643. /** HORIZONTAL_ALIGNMENT_CENTER */
  2644. get: function () {
  2645. return Control._HORIZONTAL_ALIGNMENT_CENTER;
  2646. },
  2647. enumerable: true,
  2648. configurable: true
  2649. });
  2650. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_TOP", {
  2651. /** VERTICAL_ALIGNMENT_TOP */
  2652. get: function () {
  2653. return Control._VERTICAL_ALIGNMENT_TOP;
  2654. },
  2655. enumerable: true,
  2656. configurable: true
  2657. });
  2658. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_BOTTOM", {
  2659. /** VERTICAL_ALIGNMENT_BOTTOM */
  2660. get: function () {
  2661. return Control._VERTICAL_ALIGNMENT_BOTTOM;
  2662. },
  2663. enumerable: true,
  2664. configurable: true
  2665. });
  2666. Object.defineProperty(Control, "VERTICAL_ALIGNMENT_CENTER", {
  2667. /** VERTICAL_ALIGNMENT_CENTER */
  2668. get: function () {
  2669. return Control._VERTICAL_ALIGNMENT_CENTER;
  2670. },
  2671. enumerable: true,
  2672. configurable: true
  2673. });
  2674. /** @hidden */
  2675. Control._GetFontOffset = function (font) {
  2676. if (Control._FontHeightSizes[font]) {
  2677. return Control._FontHeightSizes[font];
  2678. }
  2679. var text = document.createElement("span");
  2680. text.innerHTML = "Hg";
  2681. text.style.font = font;
  2682. var block = document.createElement("div");
  2683. block.style.display = "inline-block";
  2684. block.style.width = "1px";
  2685. block.style.height = "0px";
  2686. block.style.verticalAlign = "bottom";
  2687. var div = document.createElement("div");
  2688. div.appendChild(text);
  2689. div.appendChild(block);
  2690. document.body.appendChild(div);
  2691. var fontAscent = 0;
  2692. var fontHeight = 0;
  2693. try {
  2694. fontHeight = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  2695. block.style.verticalAlign = "baseline";
  2696. fontAscent = block.getBoundingClientRect().top - text.getBoundingClientRect().top;
  2697. }
  2698. finally {
  2699. document.body.removeChild(div);
  2700. }
  2701. var result = { ascent: fontAscent, height: fontHeight, descent: fontHeight - fontAscent };
  2702. Control._FontHeightSizes[font] = result;
  2703. return result;
  2704. };
  2705. ;
  2706. /**
  2707. * Creates a stack panel that can be used to render headers
  2708. * @param control defines the control to associate with the header
  2709. * @param text defines the text of the header
  2710. * @param size defines the size of the header
  2711. * @param options defines options used to configure the header
  2712. * @returns a new StackPanel
  2713. */
  2714. Control.AddHeader = function (control, text, size, options) {
  2715. var panel = new BABYLON.GUI.StackPanel("panel");
  2716. var isHorizontal = options ? options.isHorizontal : true;
  2717. var controlFirst = options ? options.controlFirst : true;
  2718. panel.isVertical = !isHorizontal;
  2719. var header = new BABYLON.GUI.TextBlock("header");
  2720. header.text = text;
  2721. header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  2722. if (isHorizontal) {
  2723. header.width = size;
  2724. }
  2725. else {
  2726. header.height = size;
  2727. }
  2728. if (controlFirst) {
  2729. panel.addControl(control);
  2730. panel.addControl(header);
  2731. header.paddingLeft = "5px";
  2732. }
  2733. else {
  2734. panel.addControl(header);
  2735. panel.addControl(control);
  2736. header.paddingRight = "5px";
  2737. }
  2738. header.shadowBlur = control.shadowBlur;
  2739. header.shadowColor = control.shadowColor;
  2740. header.shadowOffsetX = control.shadowOffsetX;
  2741. header.shadowOffsetY = control.shadowOffsetY;
  2742. return panel;
  2743. };
  2744. /** @hidden */
  2745. Control.drawEllipse = function (x, y, width, height, context) {
  2746. context.translate(x, y);
  2747. context.scale(width, height);
  2748. context.beginPath();
  2749. context.arc(0, 0, 1, 0, 2 * Math.PI);
  2750. context.closePath();
  2751. context.scale(1 / width, 1 / height);
  2752. context.translate(-x, -y);
  2753. };
  2754. // Statics
  2755. Control._HORIZONTAL_ALIGNMENT_LEFT = 0;
  2756. Control._HORIZONTAL_ALIGNMENT_RIGHT = 1;
  2757. Control._HORIZONTAL_ALIGNMENT_CENTER = 2;
  2758. Control._VERTICAL_ALIGNMENT_TOP = 0;
  2759. Control._VERTICAL_ALIGNMENT_BOTTOM = 1;
  2760. Control._VERTICAL_ALIGNMENT_CENTER = 2;
  2761. Control._FontHeightSizes = {};
  2762. return Control;
  2763. }());
  2764. GUI.Control = Control;
  2765. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  2766. })(BABYLON || (BABYLON = {}));
  2767. //# sourceMappingURL=control.js.map
  2768. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2769. var BABYLON;
  2770. (function (BABYLON) {
  2771. var GUI;
  2772. (function (GUI) {
  2773. /**
  2774. * Root class for 2D containers
  2775. * @see http://doc.babylonjs.com/how_to/gui#containers
  2776. */
  2777. var Container = /** @class */ (function (_super) {
  2778. __extends(Container, _super);
  2779. /**
  2780. * Creates a new Container
  2781. * @param name defines the name of the container
  2782. */
  2783. function Container(name) {
  2784. var _this = _super.call(this, name) || this;
  2785. _this.name = name;
  2786. /** @hidden */
  2787. _this._children = new Array();
  2788. /** @hidden */
  2789. _this._measureForChildren = GUI.Measure.Empty();
  2790. /** @hidden */
  2791. _this._adaptWidthToChildren = false;
  2792. /** @hidden */
  2793. _this._adaptHeightToChildren = false;
  2794. return _this;
  2795. }
  2796. Object.defineProperty(Container.prototype, "adaptHeightToChildren", {
  2797. /** Gets or sets a boolean indicating if the container should try to adapt to its children height */
  2798. get: function () {
  2799. return this._adaptHeightToChildren;
  2800. },
  2801. set: function (value) {
  2802. if (this._adaptHeightToChildren === value) {
  2803. return;
  2804. }
  2805. this._adaptHeightToChildren = value;
  2806. if (value) {
  2807. this.height = "100%";
  2808. }
  2809. this._markAsDirty();
  2810. },
  2811. enumerable: true,
  2812. configurable: true
  2813. });
  2814. Object.defineProperty(Container.prototype, "adaptWidthToChildren", {
  2815. /** Gets or sets a boolean indicating if the container should try to adapt to its children width */
  2816. get: function () {
  2817. return this._adaptWidthToChildren;
  2818. },
  2819. set: function (value) {
  2820. if (this._adaptWidthToChildren === value) {
  2821. return;
  2822. }
  2823. this._adaptWidthToChildren = value;
  2824. if (value) {
  2825. this.width = "100%";
  2826. }
  2827. this._markAsDirty();
  2828. },
  2829. enumerable: true,
  2830. configurable: true
  2831. });
  2832. Object.defineProperty(Container.prototype, "background", {
  2833. /** Gets or sets background color */
  2834. get: function () {
  2835. return this._background;
  2836. },
  2837. set: function (value) {
  2838. if (this._background === value) {
  2839. return;
  2840. }
  2841. this._background = value;
  2842. this._markAsDirty();
  2843. },
  2844. enumerable: true,
  2845. configurable: true
  2846. });
  2847. Object.defineProperty(Container.prototype, "children", {
  2848. /** Gets the list of children */
  2849. get: function () {
  2850. return this._children;
  2851. },
  2852. enumerable: true,
  2853. configurable: true
  2854. });
  2855. Container.prototype._getTypeName = function () {
  2856. return "Container";
  2857. };
  2858. /**
  2859. * Gets a child using its name
  2860. * @param name defines the child name to look for
  2861. * @returns the child control if found
  2862. */
  2863. Container.prototype.getChildByName = function (name) {
  2864. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2865. var child = _a[_i];
  2866. if (child.name === name) {
  2867. return child;
  2868. }
  2869. }
  2870. return null;
  2871. };
  2872. /**
  2873. * Gets a child using its type and its name
  2874. * @param name defines the child name to look for
  2875. * @param type defines the child type to look for
  2876. * @returns the child control if found
  2877. */
  2878. Container.prototype.getChildByType = function (name, type) {
  2879. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2880. var child = _a[_i];
  2881. if (child.typeName === type) {
  2882. return child;
  2883. }
  2884. }
  2885. return null;
  2886. };
  2887. /**
  2888. * Search for a specific control in children
  2889. * @param control defines the control to look for
  2890. * @returns true if the control is in child list
  2891. */
  2892. Container.prototype.containsControl = function (control) {
  2893. return this._children.indexOf(control) !== -1;
  2894. };
  2895. /**
  2896. * Adds a new control to the current container
  2897. * @param control defines the control to add
  2898. * @returns the current container
  2899. */
  2900. Container.prototype.addControl = function (control) {
  2901. var index = this._children.indexOf(control);
  2902. if (index !== -1) {
  2903. return this;
  2904. }
  2905. control._link(this, this._host);
  2906. control._markAllAsDirty();
  2907. this._reOrderControl(control);
  2908. this._markAsDirty();
  2909. return this;
  2910. };
  2911. /**
  2912. * Removes a control from the current container
  2913. * @param control defines the control to remove
  2914. * @returns the current container
  2915. */
  2916. Container.prototype.removeControl = function (control) {
  2917. var index = this._children.indexOf(control);
  2918. if (index !== -1) {
  2919. this._children.splice(index, 1);
  2920. control.parent = null;
  2921. }
  2922. control.linkWithMesh(null);
  2923. if (this._host) {
  2924. this._host._cleanControlAfterRemoval(control);
  2925. }
  2926. this._markAsDirty();
  2927. return this;
  2928. };
  2929. /** @hidden */
  2930. Container.prototype._reOrderControl = function (control) {
  2931. this.removeControl(control);
  2932. for (var index = 0; index < this._children.length; index++) {
  2933. if (this._children[index].zIndex > control.zIndex) {
  2934. this._children.splice(index, 0, control);
  2935. return;
  2936. }
  2937. }
  2938. this._children.push(control);
  2939. control.parent = this;
  2940. this._markAsDirty();
  2941. };
  2942. /** @hidden */
  2943. Container.prototype._markMatrixAsDirty = function () {
  2944. _super.prototype._markMatrixAsDirty.call(this);
  2945. for (var index = 0; index < this._children.length; index++) {
  2946. this._children[index]._markMatrixAsDirty();
  2947. }
  2948. };
  2949. /** @hidden */
  2950. Container.prototype._markAllAsDirty = function () {
  2951. _super.prototype._markAllAsDirty.call(this);
  2952. for (var index = 0; index < this._children.length; index++) {
  2953. this._children[index]._markAllAsDirty();
  2954. }
  2955. };
  2956. /** @hidden */
  2957. Container.prototype._localDraw = function (context) {
  2958. if (this._background) {
  2959. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2960. context.shadowColor = this.shadowColor;
  2961. context.shadowBlur = this.shadowBlur;
  2962. context.shadowOffsetX = this.shadowOffsetX;
  2963. context.shadowOffsetY = this.shadowOffsetY;
  2964. }
  2965. context.fillStyle = this._background;
  2966. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  2967. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  2968. context.shadowBlur = 0;
  2969. context.shadowOffsetX = 0;
  2970. context.shadowOffsetY = 0;
  2971. }
  2972. }
  2973. };
  2974. /** @hidden */
  2975. Container.prototype._link = function (root, host) {
  2976. _super.prototype._link.call(this, root, host);
  2977. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2978. var child = _a[_i];
  2979. child._link(root, host);
  2980. }
  2981. };
  2982. /** @hidden */
  2983. Container.prototype._draw = function (parentMeasure, context) {
  2984. if (!this.isVisible || this.notRenderable) {
  2985. return;
  2986. }
  2987. context.save();
  2988. this._applyStates(context);
  2989. if (this._processMeasures(parentMeasure, context)) {
  2990. this._localDraw(context);
  2991. this._clipForChildren(context);
  2992. var computedWidth = -1;
  2993. var computedHeight = -1;
  2994. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2995. var child = _a[_i];
  2996. if (child.isVisible && !child.notRenderable) {
  2997. child._tempParentMeasure.copyFrom(this._measureForChildren);
  2998. child._draw(this._measureForChildren, context);
  2999. if (child.onAfterDrawObservable.hasObservers()) {
  3000. child.onAfterDrawObservable.notifyObservers(child);
  3001. }
  3002. if (this.adaptWidthToChildren && child._width.isPixel) {
  3003. computedWidth = Math.max(computedWidth, child._currentMeasure.width);
  3004. }
  3005. if (this.adaptHeightToChildren && child._height.isPixel) {
  3006. computedHeight = Math.max(computedHeight, child._currentMeasure.height);
  3007. }
  3008. }
  3009. }
  3010. if (this.adaptWidthToChildren && computedWidth >= 0) {
  3011. this.width = computedWidth + "px";
  3012. }
  3013. if (this.adaptHeightToChildren && computedHeight >= 0) {
  3014. this.height = computedHeight + "px";
  3015. }
  3016. }
  3017. context.restore();
  3018. if (this.onAfterDrawObservable.hasObservers()) {
  3019. this.onAfterDrawObservable.notifyObservers(this);
  3020. }
  3021. };
  3022. /** @hidden */
  3023. Container.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  3024. if (!this.isVisible || this.notRenderable) {
  3025. return false;
  3026. }
  3027. if (!_super.prototype.contains.call(this, x, y)) {
  3028. return false;
  3029. }
  3030. // Checking backwards to pick closest first
  3031. for (var index = this._children.length - 1; index >= 0; index--) {
  3032. var child = this._children[index];
  3033. if (child._processPicking(x, y, type, pointerId, buttonIndex)) {
  3034. return true;
  3035. }
  3036. }
  3037. if (!this.isHitTestVisible) {
  3038. return false;
  3039. }
  3040. return this._processObservables(type, x, y, pointerId, buttonIndex);
  3041. };
  3042. /** @hidden */
  3043. Container.prototype._clipForChildren = function (context) {
  3044. // DO nothing
  3045. };
  3046. /** @hidden */
  3047. Container.prototype._additionalProcessing = function (parentMeasure, context) {
  3048. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  3049. this._measureForChildren.copyFrom(this._currentMeasure);
  3050. };
  3051. /** Releases associated resources */
  3052. Container.prototype.dispose = function () {
  3053. _super.prototype.dispose.call(this);
  3054. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  3055. var control = _a[_i];
  3056. control.dispose();
  3057. }
  3058. };
  3059. return Container;
  3060. }(GUI.Control));
  3061. GUI.Container = Container;
  3062. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3063. })(BABYLON || (BABYLON = {}));
  3064. //# sourceMappingURL=container.js.map
  3065. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3066. var BABYLON;
  3067. (function (BABYLON) {
  3068. var GUI;
  3069. (function (GUI) {
  3070. /**
  3071. * Class used to create a 2D stack panel container
  3072. */
  3073. var StackPanel = /** @class */ (function (_super) {
  3074. __extends(StackPanel, _super);
  3075. /**
  3076. * Creates a new StackPanel
  3077. * @param name defines control name
  3078. */
  3079. function StackPanel(name) {
  3080. var _this = _super.call(this, name) || this;
  3081. _this.name = name;
  3082. _this._isVertical = true;
  3083. _this._manualWidth = false;
  3084. _this._manualHeight = false;
  3085. _this._doNotTrackManualChanges = false;
  3086. _this._tempMeasureStore = GUI.Measure.Empty();
  3087. return _this;
  3088. }
  3089. Object.defineProperty(StackPanel.prototype, "isVertical", {
  3090. /** Gets or sets a boolean indicating if the stack panel is vertical or horizontal*/
  3091. get: function () {
  3092. return this._isVertical;
  3093. },
  3094. set: function (value) {
  3095. if (this._isVertical === value) {
  3096. return;
  3097. }
  3098. this._isVertical = value;
  3099. this._markAsDirty();
  3100. },
  3101. enumerable: true,
  3102. configurable: true
  3103. });
  3104. Object.defineProperty(StackPanel.prototype, "width", {
  3105. get: function () {
  3106. return this._width.toString(this._host);
  3107. },
  3108. /** Gets or sets panel width */
  3109. set: function (value) {
  3110. if (!this._doNotTrackManualChanges) {
  3111. this._manualWidth = true;
  3112. }
  3113. if (this._width.toString(this._host) === value) {
  3114. return;
  3115. }
  3116. if (this._width.fromString(value)) {
  3117. this._markAsDirty();
  3118. }
  3119. },
  3120. enumerable: true,
  3121. configurable: true
  3122. });
  3123. Object.defineProperty(StackPanel.prototype, "height", {
  3124. get: function () {
  3125. return this._height.toString(this._host);
  3126. },
  3127. /** Gets or sets panel height */
  3128. set: function (value) {
  3129. if (!this._doNotTrackManualChanges) {
  3130. this._manualHeight = true;
  3131. }
  3132. if (this._height.toString(this._host) === value) {
  3133. return;
  3134. }
  3135. if (this._height.fromString(value)) {
  3136. this._markAsDirty();
  3137. }
  3138. },
  3139. enumerable: true,
  3140. configurable: true
  3141. });
  3142. StackPanel.prototype._getTypeName = function () {
  3143. return "StackPanel";
  3144. };
  3145. StackPanel.prototype._preMeasure = function (parentMeasure, context) {
  3146. var stackWidth = 0;
  3147. var stackHeight = 0;
  3148. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  3149. var child = _a[_i];
  3150. this._tempMeasureStore.copyFrom(child._currentMeasure);
  3151. child._currentMeasure.copyFrom(parentMeasure);
  3152. child._measure();
  3153. if (this._isVertical) {
  3154. child.top = stackHeight + "px";
  3155. if (!child._top.ignoreAdaptiveScaling) {
  3156. child._markAsDirty();
  3157. }
  3158. child._top.ignoreAdaptiveScaling = true;
  3159. stackHeight += child._currentMeasure.height;
  3160. if (child._currentMeasure.width > stackWidth) {
  3161. stackWidth = child._currentMeasure.width;
  3162. }
  3163. child.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  3164. }
  3165. else {
  3166. child.left = stackWidth + "px";
  3167. if (!child._left.ignoreAdaptiveScaling) {
  3168. child._markAsDirty();
  3169. }
  3170. child._left.ignoreAdaptiveScaling = true;
  3171. stackWidth += child._currentMeasure.width;
  3172. if (child._currentMeasure.height > stackHeight) {
  3173. stackHeight = child._currentMeasure.height;
  3174. }
  3175. child.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3176. }
  3177. child._currentMeasure.copyFrom(this._tempMeasureStore);
  3178. }
  3179. this._doNotTrackManualChanges = true;
  3180. // Let stack panel width and height default to stackHeight and stackWidth if dimensions are not specified.
  3181. // User can now define their own height and width for stack panel.
  3182. var panelWidthChanged = false;
  3183. var panelHeightChanged = false;
  3184. var previousHeight = this.height;
  3185. var previousWidth = this.width;
  3186. if (!this._manualHeight) {
  3187. // do not specify height if strictly defined by user
  3188. this.height = stackHeight + "px";
  3189. }
  3190. if (!this._manualWidth) {
  3191. // do not specify width if strictly defined by user
  3192. this.width = stackWidth + "px";
  3193. }
  3194. panelWidthChanged = previousWidth !== this.width || !this._width.ignoreAdaptiveScaling;
  3195. panelHeightChanged = previousHeight !== this.height || !this._height.ignoreAdaptiveScaling;
  3196. if (panelHeightChanged) {
  3197. this._height.ignoreAdaptiveScaling = true;
  3198. }
  3199. if (panelWidthChanged) {
  3200. this._width.ignoreAdaptiveScaling = true;
  3201. }
  3202. this._doNotTrackManualChanges = false;
  3203. if (panelWidthChanged || panelHeightChanged) {
  3204. this._markAllAsDirty();
  3205. }
  3206. _super.prototype._preMeasure.call(this, parentMeasure, context);
  3207. };
  3208. return StackPanel;
  3209. }(GUI.Container));
  3210. GUI.StackPanel = StackPanel;
  3211. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3212. })(BABYLON || (BABYLON = {}));
  3213. //# sourceMappingURL=stackPanel.js.map
  3214. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3215. var BABYLON;
  3216. (function (BABYLON) {
  3217. var GUI;
  3218. (function (GUI) {
  3219. /** Class used to create rectangle container */
  3220. var Rectangle = /** @class */ (function (_super) {
  3221. __extends(Rectangle, _super);
  3222. /**
  3223. * Creates a new Rectangle
  3224. * @param name defines the control name
  3225. */
  3226. function Rectangle(name) {
  3227. var _this = _super.call(this, name) || this;
  3228. _this.name = name;
  3229. _this._thickness = 1;
  3230. _this._cornerRadius = 0;
  3231. return _this;
  3232. }
  3233. Object.defineProperty(Rectangle.prototype, "thickness", {
  3234. /** Gets or sets border thickness */
  3235. get: function () {
  3236. return this._thickness;
  3237. },
  3238. set: function (value) {
  3239. if (this._thickness === value) {
  3240. return;
  3241. }
  3242. this._thickness = value;
  3243. this._markAsDirty();
  3244. },
  3245. enumerable: true,
  3246. configurable: true
  3247. });
  3248. Object.defineProperty(Rectangle.prototype, "cornerRadius", {
  3249. /** Gets or sets the corner radius angle */
  3250. get: function () {
  3251. return this._cornerRadius;
  3252. },
  3253. set: function (value) {
  3254. if (value < 0) {
  3255. value = 0;
  3256. }
  3257. if (this._cornerRadius === value) {
  3258. return;
  3259. }
  3260. this._cornerRadius = value;
  3261. this._markAsDirty();
  3262. },
  3263. enumerable: true,
  3264. configurable: true
  3265. });
  3266. Rectangle.prototype._getTypeName = function () {
  3267. return "Rectangle";
  3268. };
  3269. Rectangle.prototype._localDraw = function (context) {
  3270. context.save();
  3271. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3272. context.shadowColor = this.shadowColor;
  3273. context.shadowBlur = this.shadowBlur;
  3274. context.shadowOffsetX = this.shadowOffsetX;
  3275. context.shadowOffsetY = this.shadowOffsetY;
  3276. }
  3277. if (this._background) {
  3278. context.fillStyle = this._background;
  3279. if (this._cornerRadius) {
  3280. this._drawRoundedRect(context, this._thickness / 2);
  3281. context.fill();
  3282. }
  3283. else {
  3284. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  3285. }
  3286. }
  3287. if (this._thickness) {
  3288. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3289. context.shadowBlur = 0;
  3290. context.shadowOffsetX = 0;
  3291. context.shadowOffsetY = 0;
  3292. }
  3293. if (this.color) {
  3294. context.strokeStyle = this.color;
  3295. }
  3296. context.lineWidth = this._thickness;
  3297. if (this._cornerRadius) {
  3298. this._drawRoundedRect(context, this._thickness / 2);
  3299. context.stroke();
  3300. }
  3301. else {
  3302. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  3303. }
  3304. }
  3305. context.restore();
  3306. };
  3307. Rectangle.prototype._additionalProcessing = function (parentMeasure, context) {
  3308. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  3309. this._measureForChildren.width -= 2 * this._thickness;
  3310. this._measureForChildren.height -= 2 * this._thickness;
  3311. this._measureForChildren.left += this._thickness;
  3312. this._measureForChildren.top += this._thickness;
  3313. };
  3314. Rectangle.prototype._drawRoundedRect = function (context, offset) {
  3315. if (offset === void 0) { offset = 0; }
  3316. var x = this._currentMeasure.left + offset;
  3317. var y = this._currentMeasure.top + offset;
  3318. var width = this._currentMeasure.width - offset * 2;
  3319. var height = this._currentMeasure.height - offset * 2;
  3320. var radius = Math.min(height / 2 - 2, Math.min(width / 2 - 2, this._cornerRadius));
  3321. context.beginPath();
  3322. context.moveTo(x + radius, y);
  3323. context.lineTo(x + width - radius, y);
  3324. context.quadraticCurveTo(x + width, y, x + width, y + radius);
  3325. context.lineTo(x + width, y + height - radius);
  3326. context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  3327. context.lineTo(x + radius, y + height);
  3328. context.quadraticCurveTo(x, y + height, x, y + height - radius);
  3329. context.lineTo(x, y + radius);
  3330. context.quadraticCurveTo(x, y, x + radius, y);
  3331. context.closePath();
  3332. };
  3333. Rectangle.prototype._clipForChildren = function (context) {
  3334. if (this._cornerRadius) {
  3335. this._drawRoundedRect(context, this._thickness);
  3336. context.clip();
  3337. }
  3338. };
  3339. return Rectangle;
  3340. }(GUI.Container));
  3341. GUI.Rectangle = Rectangle;
  3342. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3343. })(BABYLON || (BABYLON = {}));
  3344. //# sourceMappingURL=rectangle.js.map
  3345. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3346. var BABYLON;
  3347. (function (BABYLON) {
  3348. var GUI;
  3349. (function (GUI) {
  3350. /** Class used to create 2D ellipse containers */
  3351. var Ellipse = /** @class */ (function (_super) {
  3352. __extends(Ellipse, _super);
  3353. /**
  3354. * Creates a new Ellipse
  3355. * @param name defines the control name
  3356. */
  3357. function Ellipse(name) {
  3358. var _this = _super.call(this, name) || this;
  3359. _this.name = name;
  3360. _this._thickness = 1;
  3361. return _this;
  3362. }
  3363. Object.defineProperty(Ellipse.prototype, "thickness", {
  3364. /** Gets or sets border thickness */
  3365. get: function () {
  3366. return this._thickness;
  3367. },
  3368. set: function (value) {
  3369. if (this._thickness === value) {
  3370. return;
  3371. }
  3372. this._thickness = value;
  3373. this._markAsDirty();
  3374. },
  3375. enumerable: true,
  3376. configurable: true
  3377. });
  3378. Ellipse.prototype._getTypeName = function () {
  3379. return "Ellipse";
  3380. };
  3381. Ellipse.prototype._localDraw = function (context) {
  3382. context.save();
  3383. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3384. context.shadowColor = this.shadowColor;
  3385. context.shadowBlur = this.shadowBlur;
  3386. context.shadowOffsetX = this.shadowOffsetX;
  3387. context.shadowOffsetY = this.shadowOffsetY;
  3388. }
  3389. 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);
  3390. if (this._background) {
  3391. context.fillStyle = this._background;
  3392. context.fill();
  3393. }
  3394. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3395. context.shadowBlur = 0;
  3396. context.shadowOffsetX = 0;
  3397. context.shadowOffsetY = 0;
  3398. }
  3399. if (this._thickness) {
  3400. if (this.color) {
  3401. context.strokeStyle = this.color;
  3402. }
  3403. context.lineWidth = this._thickness;
  3404. context.stroke();
  3405. }
  3406. context.restore();
  3407. };
  3408. Ellipse.prototype._additionalProcessing = function (parentMeasure, context) {
  3409. _super.prototype._additionalProcessing.call(this, parentMeasure, context);
  3410. this._measureForChildren.width -= 2 * this._thickness;
  3411. this._measureForChildren.height -= 2 * this._thickness;
  3412. this._measureForChildren.left += this._thickness;
  3413. this._measureForChildren.top += this._thickness;
  3414. };
  3415. Ellipse.prototype._clipForChildren = function (context) {
  3416. 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);
  3417. context.clip();
  3418. };
  3419. return Ellipse;
  3420. }(GUI.Container));
  3421. GUI.Ellipse = Ellipse;
  3422. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3423. })(BABYLON || (BABYLON = {}));
  3424. //# sourceMappingURL=ellipse.js.map
  3425. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3426. var BABYLON;
  3427. (function (BABYLON) {
  3428. var GUI;
  3429. (function (GUI) {
  3430. /** Class used to render 2D lines */
  3431. var Line = /** @class */ (function (_super) {
  3432. __extends(Line, _super);
  3433. /**
  3434. * Creates a new Line
  3435. * @param name defines the control name
  3436. */
  3437. function Line(name) {
  3438. var _this = _super.call(this, name) || this;
  3439. _this.name = name;
  3440. _this._lineWidth = 1;
  3441. _this._x1 = new GUI.ValueAndUnit(0);
  3442. _this._y1 = new GUI.ValueAndUnit(0);
  3443. _this._x2 = new GUI.ValueAndUnit(0);
  3444. _this._y2 = new GUI.ValueAndUnit(0);
  3445. _this._dash = new Array();
  3446. _this.isHitTestVisible = false;
  3447. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  3448. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  3449. return _this;
  3450. }
  3451. Object.defineProperty(Line.prototype, "dash", {
  3452. /** Gets or sets the dash pattern */
  3453. get: function () {
  3454. return this._dash;
  3455. },
  3456. set: function (value) {
  3457. if (this._dash === value) {
  3458. return;
  3459. }
  3460. this._dash = value;
  3461. this._markAsDirty();
  3462. },
  3463. enumerable: true,
  3464. configurable: true
  3465. });
  3466. Object.defineProperty(Line.prototype, "connectedControl", {
  3467. /** Gets or sets the control connected with the line end */
  3468. get: function () {
  3469. return this._connectedControl;
  3470. },
  3471. set: function (value) {
  3472. var _this = this;
  3473. if (this._connectedControl === value) {
  3474. return;
  3475. }
  3476. if (this._connectedControlDirtyObserver && this._connectedControl) {
  3477. this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
  3478. this._connectedControlDirtyObserver = null;
  3479. }
  3480. if (value) {
  3481. this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
  3482. }
  3483. this._connectedControl = value;
  3484. this._markAsDirty();
  3485. },
  3486. enumerable: true,
  3487. configurable: true
  3488. });
  3489. Object.defineProperty(Line.prototype, "x1", {
  3490. /** Gets or sets start coordinates on X axis */
  3491. get: function () {
  3492. return this._x1.toString(this._host);
  3493. },
  3494. set: function (value) {
  3495. if (this._x1.toString(this._host) === value) {
  3496. return;
  3497. }
  3498. if (this._x1.fromString(value)) {
  3499. this._markAsDirty();
  3500. }
  3501. },
  3502. enumerable: true,
  3503. configurable: true
  3504. });
  3505. Object.defineProperty(Line.prototype, "y1", {
  3506. /** Gets or sets start coordinates on Y axis */
  3507. get: function () {
  3508. return this._y1.toString(this._host);
  3509. },
  3510. set: function (value) {
  3511. if (this._y1.toString(this._host) === value) {
  3512. return;
  3513. }
  3514. if (this._y1.fromString(value)) {
  3515. this._markAsDirty();
  3516. }
  3517. },
  3518. enumerable: true,
  3519. configurable: true
  3520. });
  3521. Object.defineProperty(Line.prototype, "x2", {
  3522. /** Gets or sets end coordinates on X axis */
  3523. get: function () {
  3524. return this._x2.toString(this._host);
  3525. },
  3526. set: function (value) {
  3527. if (this._x2.toString(this._host) === value) {
  3528. return;
  3529. }
  3530. if (this._x2.fromString(value)) {
  3531. this._markAsDirty();
  3532. }
  3533. },
  3534. enumerable: true,
  3535. configurable: true
  3536. });
  3537. Object.defineProperty(Line.prototype, "y2", {
  3538. /** Gets or sets end coordinates on Y axis */
  3539. get: function () {
  3540. return this._y2.toString(this._host);
  3541. },
  3542. set: function (value) {
  3543. if (this._y2.toString(this._host) === value) {
  3544. return;
  3545. }
  3546. if (this._y2.fromString(value)) {
  3547. this._markAsDirty();
  3548. }
  3549. },
  3550. enumerable: true,
  3551. configurable: true
  3552. });
  3553. Object.defineProperty(Line.prototype, "lineWidth", {
  3554. /** Gets or sets line width */
  3555. get: function () {
  3556. return this._lineWidth;
  3557. },
  3558. set: function (value) {
  3559. if (this._lineWidth === value) {
  3560. return;
  3561. }
  3562. this._lineWidth = value;
  3563. this._markAsDirty();
  3564. },
  3565. enumerable: true,
  3566. configurable: true
  3567. });
  3568. Object.defineProperty(Line.prototype, "horizontalAlignment", {
  3569. /** Gets or sets horizontal alignment */
  3570. set: function (value) {
  3571. return;
  3572. },
  3573. enumerable: true,
  3574. configurable: true
  3575. });
  3576. Object.defineProperty(Line.prototype, "verticalAlignment", {
  3577. /** Gets or sets vertical alignment */
  3578. set: function (value) {
  3579. return;
  3580. },
  3581. enumerable: true,
  3582. configurable: true
  3583. });
  3584. Object.defineProperty(Line.prototype, "_effectiveX2", {
  3585. get: function () {
  3586. return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
  3587. },
  3588. enumerable: true,
  3589. configurable: true
  3590. });
  3591. Object.defineProperty(Line.prototype, "_effectiveY2", {
  3592. get: function () {
  3593. return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
  3594. },
  3595. enumerable: true,
  3596. configurable: true
  3597. });
  3598. Line.prototype._getTypeName = function () {
  3599. return "Line";
  3600. };
  3601. Line.prototype._draw = function (parentMeasure, context) {
  3602. context.save();
  3603. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3604. context.shadowColor = this.shadowColor;
  3605. context.shadowBlur = this.shadowBlur;
  3606. context.shadowOffsetX = this.shadowOffsetX;
  3607. context.shadowOffsetY = this.shadowOffsetY;
  3608. }
  3609. this._applyStates(context);
  3610. if (this._processMeasures(parentMeasure, context)) {
  3611. context.strokeStyle = this.color;
  3612. context.lineWidth = this._lineWidth;
  3613. context.setLineDash(this._dash);
  3614. context.beginPath();
  3615. context.moveTo(this._x1.getValue(this._host), this._y1.getValue(this._host));
  3616. context.lineTo(this._effectiveX2, this._effectiveY2);
  3617. context.stroke();
  3618. }
  3619. context.restore();
  3620. };
  3621. Line.prototype._measure = function () {
  3622. // Width / Height
  3623. this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
  3624. this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
  3625. };
  3626. Line.prototype._computeAlignment = function (parentMeasure, context) {
  3627. this._currentMeasure.left = Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
  3628. this._currentMeasure.top = Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
  3629. };
  3630. /**
  3631. * Move one end of the line given 3D cartesian coordinates.
  3632. * @param position Targeted world position
  3633. * @param scene Scene
  3634. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  3635. */
  3636. Line.prototype.moveToVector3 = function (position, scene, end) {
  3637. if (end === void 0) { end = false; }
  3638. if (!this._host || this._root !== this._host._rootContainer) {
  3639. BABYLON.Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
  3640. return;
  3641. }
  3642. var globalViewport = this._host._getGlobalViewport(scene);
  3643. var projectedPosition = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
  3644. this._moveToProjectedPosition(projectedPosition, end);
  3645. if (projectedPosition.z < 0 || projectedPosition.z > 1) {
  3646. this.notRenderable = true;
  3647. return;
  3648. }
  3649. this.notRenderable = false;
  3650. };
  3651. /**
  3652. * Move one end of the line to a position in screen absolute space.
  3653. * @param projectedPosition Position in screen absolute space (X, Y)
  3654. * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
  3655. */
  3656. Line.prototype._moveToProjectedPosition = function (projectedPosition, end) {
  3657. if (end === void 0) { end = false; }
  3658. var x = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
  3659. var y = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
  3660. if (end) {
  3661. this.x2 = x;
  3662. this.y2 = y;
  3663. this._x2.ignoreAdaptiveScaling = true;
  3664. this._y2.ignoreAdaptiveScaling = true;
  3665. }
  3666. else {
  3667. this.x1 = x;
  3668. this.y1 = y;
  3669. this._x1.ignoreAdaptiveScaling = true;
  3670. this._y1.ignoreAdaptiveScaling = true;
  3671. }
  3672. };
  3673. return Line;
  3674. }(GUI.Control));
  3675. GUI.Line = Line;
  3676. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3677. })(BABYLON || (BABYLON = {}));
  3678. //# sourceMappingURL=line.js.map
  3679. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3680. var BABYLON;
  3681. (function (BABYLON) {
  3682. var GUI;
  3683. (function (GUI) {
  3684. /**
  3685. * Class used to create slider controls
  3686. */
  3687. var Slider = /** @class */ (function (_super) {
  3688. __extends(Slider, _super);
  3689. /**
  3690. * Creates a new Slider
  3691. * @param name defines the control name
  3692. */
  3693. function Slider(name) {
  3694. var _this = _super.call(this, name) || this;
  3695. _this.name = name;
  3696. _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  3697. _this._minimum = 0;
  3698. _this._maximum = 100;
  3699. _this._value = 50;
  3700. _this._background = "black";
  3701. _this._borderColor = "white";
  3702. _this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
  3703. _this._isThumbCircle = false;
  3704. _this._isThumbClamped = false;
  3705. /** Observable raised when the sldier value changes */
  3706. _this.onValueChangedObservable = new BABYLON.Observable();
  3707. // Events
  3708. _this._pointerIsDown = false;
  3709. _this.isPointerBlocker = true;
  3710. return _this;
  3711. }
  3712. Object.defineProperty(Slider.prototype, "borderColor", {
  3713. /** Gets or sets border color */
  3714. get: function () {
  3715. return this._borderColor;
  3716. },
  3717. set: function (value) {
  3718. if (this._borderColor === value) {
  3719. return;
  3720. }
  3721. this._borderColor = value;
  3722. this._markAsDirty();
  3723. },
  3724. enumerable: true,
  3725. configurable: true
  3726. });
  3727. Object.defineProperty(Slider.prototype, "background", {
  3728. /** Gets or sets background color */
  3729. get: function () {
  3730. return this._background;
  3731. },
  3732. set: function (value) {
  3733. if (this._background === value) {
  3734. return;
  3735. }
  3736. this._background = value;
  3737. this._markAsDirty();
  3738. },
  3739. enumerable: true,
  3740. configurable: true
  3741. });
  3742. Object.defineProperty(Slider.prototype, "barOffset", {
  3743. /** Gets or sets main bar offset */
  3744. get: function () {
  3745. return this._barOffset.toString(this._host);
  3746. },
  3747. set: function (value) {
  3748. if (this._barOffset.toString(this._host) === value) {
  3749. return;
  3750. }
  3751. if (this._barOffset.fromString(value)) {
  3752. this._markAsDirty();
  3753. }
  3754. },
  3755. enumerable: true,
  3756. configurable: true
  3757. });
  3758. Object.defineProperty(Slider.prototype, "barOffsetInPixels", {
  3759. /** Gets main bar offset in pixels*/
  3760. get: function () {
  3761. return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
  3762. },
  3763. enumerable: true,
  3764. configurable: true
  3765. });
  3766. Object.defineProperty(Slider.prototype, "thumbWidth", {
  3767. /** Gets or sets thumb width */
  3768. get: function () {
  3769. return this._thumbWidth.toString(this._host);
  3770. },
  3771. set: function (value) {
  3772. if (this._thumbWidth.toString(this._host) === value) {
  3773. return;
  3774. }
  3775. if (this._thumbWidth.fromString(value)) {
  3776. this._markAsDirty();
  3777. }
  3778. },
  3779. enumerable: true,
  3780. configurable: true
  3781. });
  3782. Object.defineProperty(Slider.prototype, "thumbWidthInPixels", {
  3783. /** Gets thumb width in pixels */
  3784. get: function () {
  3785. return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  3786. },
  3787. enumerable: true,
  3788. configurable: true
  3789. });
  3790. Object.defineProperty(Slider.prototype, "minimum", {
  3791. /** Gets or sets minimum value */
  3792. get: function () {
  3793. return this._minimum;
  3794. },
  3795. set: function (value) {
  3796. if (this._minimum === value) {
  3797. return;
  3798. }
  3799. this._minimum = value;
  3800. this._markAsDirty();
  3801. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  3802. },
  3803. enumerable: true,
  3804. configurable: true
  3805. });
  3806. Object.defineProperty(Slider.prototype, "maximum", {
  3807. /** Gets or sets maximum value */
  3808. get: function () {
  3809. return this._maximum;
  3810. },
  3811. set: function (value) {
  3812. if (this._maximum === value) {
  3813. return;
  3814. }
  3815. this._maximum = value;
  3816. this._markAsDirty();
  3817. this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
  3818. },
  3819. enumerable: true,
  3820. configurable: true
  3821. });
  3822. Object.defineProperty(Slider.prototype, "value", {
  3823. /** Gets or sets current value */
  3824. get: function () {
  3825. return this._value;
  3826. },
  3827. set: function (value) {
  3828. value = Math.max(Math.min(value, this._maximum), this._minimum);
  3829. if (this._value === value) {
  3830. return;
  3831. }
  3832. this._value = value;
  3833. this._markAsDirty();
  3834. this.onValueChangedObservable.notifyObservers(this._value);
  3835. },
  3836. enumerable: true,
  3837. configurable: true
  3838. });
  3839. Object.defineProperty(Slider.prototype, "isThumbCircle", {
  3840. /** Gets or sets a boolean indicating if the thumb should be round or square */
  3841. get: function () {
  3842. return this._isThumbCircle;
  3843. },
  3844. set: function (value) {
  3845. if (this._isThumbCircle === value) {
  3846. return;
  3847. }
  3848. this._isThumbCircle = value;
  3849. this._markAsDirty();
  3850. },
  3851. enumerable: true,
  3852. configurable: true
  3853. });
  3854. Object.defineProperty(Slider.prototype, "isThumbClamped", {
  3855. /** Gets or sets a value indicating if the thumb can go over main bar extends */
  3856. get: function () {
  3857. return this._isThumbClamped;
  3858. },
  3859. set: function (value) {
  3860. if (this._isThumbClamped === value) {
  3861. return;
  3862. }
  3863. this._isThumbClamped = value;
  3864. this._markAsDirty();
  3865. },
  3866. enumerable: true,
  3867. configurable: true
  3868. });
  3869. Slider.prototype._getTypeName = function () {
  3870. return "Slider";
  3871. };
  3872. Slider.prototype._draw = function (parentMeasure, context) {
  3873. context.save();
  3874. this._applyStates(context);
  3875. if (this._processMeasures(parentMeasure, context)) {
  3876. // Main bar
  3877. var effectiveThumbWidth;
  3878. var effectiveBarOffset;
  3879. if (this._thumbWidth.isPixel) {
  3880. effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.width);
  3881. }
  3882. else {
  3883. effectiveThumbWidth = this._currentMeasure.width * this._thumbWidth.getValue(this._host);
  3884. }
  3885. if (this._barOffset.isPixel) {
  3886. effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
  3887. }
  3888. else {
  3889. effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
  3890. }
  3891. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3892. context.shadowColor = this.shadowColor;
  3893. context.shadowBlur = this.shadowBlur;
  3894. context.shadowOffsetX = this.shadowOffsetX;
  3895. context.shadowOffsetY = this.shadowOffsetY;
  3896. }
  3897. var left = this._currentMeasure.left;
  3898. var width = this._currentMeasure.width - effectiveThumbWidth;
  3899. var thumbPosition = ((this._value - this._minimum) / (this._maximum - this._minimum)) * width;
  3900. context.fillStyle = this._background;
  3901. if (this.isThumbClamped) {
  3902. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width + effectiveThumbWidth, this._currentMeasure.height - effectiveBarOffset * 2);
  3903. }
  3904. else {
  3905. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
  3906. }
  3907. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3908. context.shadowBlur = 0;
  3909. context.shadowOffsetX = 0;
  3910. context.shadowOffsetY = 0;
  3911. }
  3912. context.fillStyle = this.color;
  3913. if (this.isThumbClamped) {
  3914. context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3915. }
  3916. else {
  3917. context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
  3918. }
  3919. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3920. context.shadowColor = this.shadowColor;
  3921. context.shadowBlur = this.shadowBlur;
  3922. context.shadowOffsetX = this.shadowOffsetX;
  3923. context.shadowOffsetY = this.shadowOffsetY;
  3924. }
  3925. if (this._isThumbCircle) {
  3926. context.beginPath();
  3927. context.arc(left + thumbPosition + (effectiveThumbWidth / 2), this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
  3928. context.fill();
  3929. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3930. context.shadowBlur = 0;
  3931. context.shadowOffsetX = 0;
  3932. context.shadowOffsetY = 0;
  3933. }
  3934. context.strokeStyle = this._borderColor;
  3935. context.stroke();
  3936. }
  3937. else {
  3938. context.fillRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3939. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  3940. context.shadowBlur = 0;
  3941. context.shadowOffsetX = 0;
  3942. context.shadowOffsetY = 0;
  3943. }
  3944. context.strokeStyle = this._borderColor;
  3945. context.strokeRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
  3946. }
  3947. }
  3948. context.restore();
  3949. };
  3950. Slider.prototype._updateValueFromPointer = function (x, y) {
  3951. if (this.rotation != 0) {
  3952. this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
  3953. x = this._transformedPosition.x;
  3954. }
  3955. this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
  3956. };
  3957. Slider.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  3958. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  3959. return false;
  3960. }
  3961. this._pointerIsDown = true;
  3962. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3963. this._host._capturingControl[pointerId] = this;
  3964. return true;
  3965. };
  3966. Slider.prototype._onPointerMove = function (target, coordinates) {
  3967. if (this._pointerIsDown) {
  3968. this._updateValueFromPointer(coordinates.x, coordinates.y);
  3969. }
  3970. _super.prototype._onPointerMove.call(this, target, coordinates);
  3971. };
  3972. Slider.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  3973. this._pointerIsDown = false;
  3974. delete this._host._capturingControl[pointerId];
  3975. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  3976. };
  3977. return Slider;
  3978. }(GUI.Control));
  3979. GUI.Slider = Slider;
  3980. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  3981. })(BABYLON || (BABYLON = {}));
  3982. //# sourceMappingURL=slider.js.map
  3983. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3984. var BABYLON;
  3985. (function (BABYLON) {
  3986. var GUI;
  3987. (function (GUI) {
  3988. /**
  3989. * Class used to represent a 2D checkbox
  3990. */
  3991. var Checkbox = /** @class */ (function (_super) {
  3992. __extends(Checkbox, _super);
  3993. /**
  3994. * Creates a new CheckBox
  3995. * @param name defines the control name
  3996. */
  3997. function Checkbox(name) {
  3998. var _this = _super.call(this, name) || this;
  3999. _this.name = name;
  4000. _this._isChecked = false;
  4001. _this._background = "black";
  4002. _this._checkSizeRatio = 0.8;
  4003. _this._thickness = 1;
  4004. /**
  4005. * Observable raised when isChecked property changes
  4006. */
  4007. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  4008. _this.isPointerBlocker = true;
  4009. return _this;
  4010. }
  4011. Object.defineProperty(Checkbox.prototype, "thickness", {
  4012. /** Gets or sets border thickness */
  4013. get: function () {
  4014. return this._thickness;
  4015. },
  4016. set: function (value) {
  4017. if (this._thickness === value) {
  4018. return;
  4019. }
  4020. this._thickness = value;
  4021. this._markAsDirty();
  4022. },
  4023. enumerable: true,
  4024. configurable: true
  4025. });
  4026. Object.defineProperty(Checkbox.prototype, "checkSizeRatio", {
  4027. /** Gets or sets a value indicating the ratio between overall size and check size */
  4028. get: function () {
  4029. return this._checkSizeRatio;
  4030. },
  4031. set: function (value) {
  4032. value = Math.max(Math.min(1, value), 0);
  4033. if (this._checkSizeRatio === value) {
  4034. return;
  4035. }
  4036. this._checkSizeRatio = value;
  4037. this._markAsDirty();
  4038. },
  4039. enumerable: true,
  4040. configurable: true
  4041. });
  4042. Object.defineProperty(Checkbox.prototype, "background", {
  4043. /** Gets or sets background color */
  4044. get: function () {
  4045. return this._background;
  4046. },
  4047. set: function (value) {
  4048. if (this._background === value) {
  4049. return;
  4050. }
  4051. this._background = value;
  4052. this._markAsDirty();
  4053. },
  4054. enumerable: true,
  4055. configurable: true
  4056. });
  4057. Object.defineProperty(Checkbox.prototype, "isChecked", {
  4058. /** Gets or sets a boolean indicating if the checkbox is checked or not */
  4059. get: function () {
  4060. return this._isChecked;
  4061. },
  4062. set: function (value) {
  4063. if (this._isChecked === value) {
  4064. return;
  4065. }
  4066. this._isChecked = value;
  4067. this._markAsDirty();
  4068. this.onIsCheckedChangedObservable.notifyObservers(value);
  4069. },
  4070. enumerable: true,
  4071. configurable: true
  4072. });
  4073. Checkbox.prototype._getTypeName = function () {
  4074. return "CheckBox";
  4075. };
  4076. /** @hidden */
  4077. Checkbox.prototype._draw = function (parentMeasure, context) {
  4078. context.save();
  4079. this._applyStates(context);
  4080. if (this._processMeasures(parentMeasure, context)) {
  4081. var actualWidth = this._currentMeasure.width - this._thickness;
  4082. var actualHeight = this._currentMeasure.height - this._thickness;
  4083. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4084. context.shadowColor = this.shadowColor;
  4085. context.shadowBlur = this.shadowBlur;
  4086. context.shadowOffsetX = this.shadowOffsetX;
  4087. context.shadowOffsetY = this.shadowOffsetY;
  4088. }
  4089. context.fillStyle = this._background;
  4090. context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  4091. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4092. context.shadowBlur = 0;
  4093. context.shadowOffsetX = 0;
  4094. context.shadowOffsetY = 0;
  4095. }
  4096. if (this._isChecked) {
  4097. context.fillStyle = this.color;
  4098. var offsetWidth = actualWidth * this._checkSizeRatio;
  4099. var offseHeight = actualHeight * this._checkSizeRatio;
  4100. context.fillRect(this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2, this._currentMeasure.top + this._thickness / 2 + (actualHeight - offseHeight) / 2, offsetWidth, offseHeight);
  4101. }
  4102. context.strokeStyle = this.color;
  4103. context.lineWidth = this._thickness;
  4104. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);
  4105. }
  4106. context.restore();
  4107. };
  4108. // Events
  4109. /** @hidden */
  4110. Checkbox.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4111. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4112. return false;
  4113. }
  4114. this.isChecked = !this.isChecked;
  4115. return true;
  4116. };
  4117. return Checkbox;
  4118. }(GUI.Control));
  4119. GUI.Checkbox = Checkbox;
  4120. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4121. })(BABYLON || (BABYLON = {}));
  4122. //# sourceMappingURL=checkbox.js.map
  4123. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4124. var BABYLON;
  4125. (function (BABYLON) {
  4126. var GUI;
  4127. (function (GUI) {
  4128. /**
  4129. * Class used to create radio button controls
  4130. */
  4131. var RadioButton = /** @class */ (function (_super) {
  4132. __extends(RadioButton, _super);
  4133. /**
  4134. * Creates a new RadioButton
  4135. * @param name defines the control name
  4136. */
  4137. function RadioButton(name) {
  4138. var _this = _super.call(this, name) || this;
  4139. _this.name = name;
  4140. _this._isChecked = false;
  4141. _this._background = "black";
  4142. _this._checkSizeRatio = 0.8;
  4143. _this._thickness = 1;
  4144. /** Gets or sets group name */
  4145. _this.group = "";
  4146. /** Observable raised when isChecked is changed */
  4147. _this.onIsCheckedChangedObservable = new BABYLON.Observable();
  4148. _this.isPointerBlocker = true;
  4149. return _this;
  4150. }
  4151. Object.defineProperty(RadioButton.prototype, "thickness", {
  4152. /** Gets or sets border thickness */
  4153. get: function () {
  4154. return this._thickness;
  4155. },
  4156. set: function (value) {
  4157. if (this._thickness === value) {
  4158. return;
  4159. }
  4160. this._thickness = value;
  4161. this._markAsDirty();
  4162. },
  4163. enumerable: true,
  4164. configurable: true
  4165. });
  4166. Object.defineProperty(RadioButton.prototype, "checkSizeRatio", {
  4167. /** Gets or sets a value indicating the ratio between overall size and check size */
  4168. get: function () {
  4169. return this._checkSizeRatio;
  4170. },
  4171. set: function (value) {
  4172. value = Math.max(Math.min(1, value), 0);
  4173. if (this._checkSizeRatio === value) {
  4174. return;
  4175. }
  4176. this._checkSizeRatio = value;
  4177. this._markAsDirty();
  4178. },
  4179. enumerable: true,
  4180. configurable: true
  4181. });
  4182. Object.defineProperty(RadioButton.prototype, "background", {
  4183. /** Gets or sets background color */
  4184. get: function () {
  4185. return this._background;
  4186. },
  4187. set: function (value) {
  4188. if (this._background === value) {
  4189. return;
  4190. }
  4191. this._background = value;
  4192. this._markAsDirty();
  4193. },
  4194. enumerable: true,
  4195. configurable: true
  4196. });
  4197. Object.defineProperty(RadioButton.prototype, "isChecked", {
  4198. /** Gets or sets a boolean indicating if the checkbox is checked or not */
  4199. get: function () {
  4200. return this._isChecked;
  4201. },
  4202. set: function (value) {
  4203. var _this = this;
  4204. if (this._isChecked === value) {
  4205. return;
  4206. }
  4207. this._isChecked = value;
  4208. this._markAsDirty();
  4209. this.onIsCheckedChangedObservable.notifyObservers(value);
  4210. if (this._isChecked) {
  4211. // Update all controls from same group
  4212. this._host.executeOnAllControls(function (control) {
  4213. if (control === _this) {
  4214. return;
  4215. }
  4216. if (control.group === undefined) {
  4217. return;
  4218. }
  4219. var childRadio = control;
  4220. if (childRadio.group === _this.group) {
  4221. childRadio.isChecked = false;
  4222. }
  4223. });
  4224. }
  4225. },
  4226. enumerable: true,
  4227. configurable: true
  4228. });
  4229. RadioButton.prototype._getTypeName = function () {
  4230. return "RadioButton";
  4231. };
  4232. RadioButton.prototype._draw = function (parentMeasure, context) {
  4233. context.save();
  4234. this._applyStates(context);
  4235. if (this._processMeasures(parentMeasure, context)) {
  4236. var actualWidth = this._currentMeasure.width - this._thickness;
  4237. var actualHeight = this._currentMeasure.height - this._thickness;
  4238. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4239. context.shadowColor = this.shadowColor;
  4240. context.shadowBlur = this.shadowBlur;
  4241. context.shadowOffsetX = this.shadowOffsetX;
  4242. context.shadowOffsetY = this.shadowOffsetY;
  4243. }
  4244. // Outer
  4245. 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);
  4246. context.fillStyle = this._background;
  4247. context.fill();
  4248. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4249. context.shadowBlur = 0;
  4250. context.shadowOffsetX = 0;
  4251. context.shadowOffsetY = 0;
  4252. }
  4253. context.strokeStyle = this.color;
  4254. context.lineWidth = this._thickness;
  4255. context.stroke();
  4256. // Inner
  4257. if (this._isChecked) {
  4258. context.fillStyle = this.color;
  4259. var offsetWidth = actualWidth * this._checkSizeRatio;
  4260. var offseHeight = actualHeight * this._checkSizeRatio;
  4261. 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);
  4262. context.fill();
  4263. }
  4264. }
  4265. context.restore();
  4266. };
  4267. // Events
  4268. RadioButton.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  4269. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  4270. return false;
  4271. }
  4272. if (!this.isChecked) {
  4273. this.isChecked = true;
  4274. }
  4275. return true;
  4276. };
  4277. return RadioButton;
  4278. }(GUI.Control));
  4279. GUI.RadioButton = RadioButton;
  4280. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4281. })(BABYLON || (BABYLON = {}));
  4282. //# sourceMappingURL=radioButton.js.map
  4283. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4284. var BABYLON;
  4285. (function (BABYLON) {
  4286. var GUI;
  4287. (function (GUI) {
  4288. /**
  4289. * Class used to create text block control
  4290. */
  4291. var TextBlock = /** @class */ (function (_super) {
  4292. __extends(TextBlock, _super);
  4293. /**
  4294. * Creates a new TextBlock object
  4295. * @param name defines the name of the control
  4296. * @param text defines the text to display (emptry string by default)
  4297. */
  4298. function TextBlock(
  4299. /**
  4300. * Defines the name of the control
  4301. */
  4302. name, text) {
  4303. if (text === void 0) { text = ""; }
  4304. var _this = _super.call(this, name) || this;
  4305. _this.name = name;
  4306. _this._text = "";
  4307. _this._textWrapping = false;
  4308. _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  4309. _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  4310. _this._resizeToFit = false;
  4311. _this._lineSpacing = new GUI.ValueAndUnit(0);
  4312. _this._outlineWidth = 0;
  4313. _this._outlineColor = "white";
  4314. /**
  4315. * An event triggered after the text is changed
  4316. */
  4317. _this.onTextChangedObservable = new BABYLON.Observable();
  4318. /**
  4319. * An event triggered after the text was broken up into lines
  4320. */
  4321. _this.onLinesReadyObservable = new BABYLON.Observable();
  4322. _this.text = text;
  4323. return _this;
  4324. }
  4325. Object.defineProperty(TextBlock.prototype, "lines", {
  4326. /**
  4327. * Return the line list (you may need to use the onLinesReadyObservable to make sure the list is ready)
  4328. */
  4329. get: function () {
  4330. return this._lines;
  4331. },
  4332. enumerable: true,
  4333. configurable: true
  4334. });
  4335. Object.defineProperty(TextBlock.prototype, "resizeToFit", {
  4336. /**
  4337. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  4338. */
  4339. get: function () {
  4340. return this._resizeToFit;
  4341. },
  4342. /**
  4343. * Gets or sets an boolean indicating that the TextBlock will be resized to fit container
  4344. */
  4345. set: function (value) {
  4346. this._resizeToFit = value;
  4347. if (this._resizeToFit) {
  4348. this._width.ignoreAdaptiveScaling = true;
  4349. this._height.ignoreAdaptiveScaling = true;
  4350. }
  4351. },
  4352. enumerable: true,
  4353. configurable: true
  4354. });
  4355. Object.defineProperty(TextBlock.prototype, "textWrapping", {
  4356. /**
  4357. * Gets or sets a boolean indicating if text must be wrapped
  4358. */
  4359. get: function () {
  4360. return this._textWrapping;
  4361. },
  4362. /**
  4363. * Gets or sets a boolean indicating if text must be wrapped
  4364. */
  4365. set: function (value) {
  4366. if (this._textWrapping === value) {
  4367. return;
  4368. }
  4369. this._textWrapping = value;
  4370. this._markAsDirty();
  4371. },
  4372. enumerable: true,
  4373. configurable: true
  4374. });
  4375. Object.defineProperty(TextBlock.prototype, "text", {
  4376. /**
  4377. * Gets or sets text to display
  4378. */
  4379. get: function () {
  4380. return this._text;
  4381. },
  4382. /**
  4383. * Gets or sets text to display
  4384. */
  4385. set: function (value) {
  4386. if (this._text === value) {
  4387. return;
  4388. }
  4389. this._text = value;
  4390. this._markAsDirty();
  4391. this.onTextChangedObservable.notifyObservers(this);
  4392. },
  4393. enumerable: true,
  4394. configurable: true
  4395. });
  4396. Object.defineProperty(TextBlock.prototype, "textHorizontalAlignment", {
  4397. /**
  4398. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  4399. */
  4400. get: function () {
  4401. return this._textHorizontalAlignment;
  4402. },
  4403. /**
  4404. * Gets or sets text horizontal alignment (BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER by default)
  4405. */
  4406. set: function (value) {
  4407. if (this._textHorizontalAlignment === value) {
  4408. return;
  4409. }
  4410. this._textHorizontalAlignment = value;
  4411. this._markAsDirty();
  4412. },
  4413. enumerable: true,
  4414. configurable: true
  4415. });
  4416. Object.defineProperty(TextBlock.prototype, "textVerticalAlignment", {
  4417. /**
  4418. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  4419. */
  4420. get: function () {
  4421. return this._textVerticalAlignment;
  4422. },
  4423. /**
  4424. * Gets or sets text vertical alignment (BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER by default)
  4425. */
  4426. set: function (value) {
  4427. if (this._textVerticalAlignment === value) {
  4428. return;
  4429. }
  4430. this._textVerticalAlignment = value;
  4431. this._markAsDirty();
  4432. },
  4433. enumerable: true,
  4434. configurable: true
  4435. });
  4436. Object.defineProperty(TextBlock.prototype, "lineSpacing", {
  4437. /**
  4438. * Gets or sets line spacing value
  4439. */
  4440. get: function () {
  4441. return this._lineSpacing.toString(this._host);
  4442. },
  4443. /**
  4444. * Gets or sets line spacing value
  4445. */
  4446. set: function (value) {
  4447. if (this._lineSpacing.fromString(value)) {
  4448. this._markAsDirty();
  4449. }
  4450. },
  4451. enumerable: true,
  4452. configurable: true
  4453. });
  4454. Object.defineProperty(TextBlock.prototype, "outlineWidth", {
  4455. /**
  4456. * Gets or sets outlineWidth of the text to display
  4457. */
  4458. get: function () {
  4459. return this._outlineWidth;
  4460. },
  4461. /**
  4462. * Gets or sets outlineWidth of the text to display
  4463. */
  4464. set: function (value) {
  4465. if (this._outlineWidth === value) {
  4466. return;
  4467. }
  4468. this._outlineWidth = value;
  4469. this._markAsDirty();
  4470. },
  4471. enumerable: true,
  4472. configurable: true
  4473. });
  4474. Object.defineProperty(TextBlock.prototype, "outlineColor", {
  4475. /**
  4476. * Gets or sets outlineColor of the text to display
  4477. */
  4478. get: function () {
  4479. return this._outlineColor;
  4480. },
  4481. /**
  4482. * Gets or sets outlineColor of the text to display
  4483. */
  4484. set: function (value) {
  4485. if (this._outlineColor === value) {
  4486. return;
  4487. }
  4488. this._outlineColor = value;
  4489. this._markAsDirty();
  4490. },
  4491. enumerable: true,
  4492. configurable: true
  4493. });
  4494. TextBlock.prototype._getTypeName = function () {
  4495. return "TextBlock";
  4496. };
  4497. TextBlock.prototype._drawText = function (text, textWidth, y, context) {
  4498. var width = this._currentMeasure.width;
  4499. var x = 0;
  4500. switch (this._textHorizontalAlignment) {
  4501. case GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
  4502. x = 0;
  4503. break;
  4504. case GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
  4505. x = width - textWidth;
  4506. break;
  4507. case GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
  4508. x = (width - textWidth) / 2;
  4509. break;
  4510. }
  4511. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4512. context.shadowColor = this.shadowColor;
  4513. context.shadowBlur = this.shadowBlur;
  4514. context.shadowOffsetX = this.shadowOffsetX;
  4515. context.shadowOffsetY = this.shadowOffsetY;
  4516. }
  4517. if (this.outlineWidth) {
  4518. context.strokeText(text, this._currentMeasure.left + x, y);
  4519. }
  4520. context.fillText(text, this._currentMeasure.left + x, y);
  4521. };
  4522. /** @hidden */
  4523. TextBlock.prototype._draw = function (parentMeasure, context) {
  4524. context.save();
  4525. this._applyStates(context);
  4526. if (this._processMeasures(parentMeasure, context)) {
  4527. // Render lines
  4528. this._renderLines(context);
  4529. }
  4530. context.restore();
  4531. };
  4532. TextBlock.prototype._applyStates = function (context) {
  4533. _super.prototype._applyStates.call(this, context);
  4534. if (this.outlineWidth) {
  4535. context.lineWidth = this.outlineWidth;
  4536. context.strokeStyle = this.outlineColor;
  4537. }
  4538. };
  4539. TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
  4540. this._lines = [];
  4541. var _lines = this.text.split("\n");
  4542. if (this._textWrapping && !this._resizeToFit) {
  4543. for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
  4544. var _line = _lines_1[_i];
  4545. this._lines.push(this._parseLineWithTextWrapping(_line, context));
  4546. }
  4547. }
  4548. else {
  4549. for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
  4550. var _line = _lines_2[_a];
  4551. this._lines.push(this._parseLine(_line, context));
  4552. }
  4553. }
  4554. this.onLinesReadyObservable.notifyObservers(this);
  4555. };
  4556. TextBlock.prototype._parseLine = function (line, context) {
  4557. if (line === void 0) { line = ''; }
  4558. return { text: line, width: context.measureText(line).width };
  4559. };
  4560. TextBlock.prototype._parseLineWithTextWrapping = function (line, context) {
  4561. if (line === void 0) { line = ''; }
  4562. var words = line.split(' ');
  4563. var width = this._currentMeasure.width;
  4564. var lineWidth = 0;
  4565. for (var n = 0; n < words.length; n++) {
  4566. var testLine = n > 0 ? line + " " + words[n] : words[0];
  4567. var metrics = context.measureText(testLine);
  4568. var testWidth = metrics.width;
  4569. if (testWidth > width && n > 0) {
  4570. this._lines.push({ text: line, width: lineWidth });
  4571. line = words[n];
  4572. lineWidth = context.measureText(line).width;
  4573. }
  4574. else {
  4575. lineWidth = testWidth;
  4576. line = testLine;
  4577. }
  4578. }
  4579. return { text: line, width: lineWidth };
  4580. };
  4581. TextBlock.prototype._renderLines = function (context) {
  4582. var height = this._currentMeasure.height;
  4583. if (!this._fontOffset) {
  4584. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  4585. }
  4586. var rootY = 0;
  4587. switch (this._textVerticalAlignment) {
  4588. case GUI.Control.VERTICAL_ALIGNMENT_TOP:
  4589. rootY = this._fontOffset.ascent;
  4590. break;
  4591. case GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
  4592. rootY = height - this._fontOffset.height * (this._lines.length - 1) - this._fontOffset.descent;
  4593. break;
  4594. case GUI.Control.VERTICAL_ALIGNMENT_CENTER:
  4595. rootY = this._fontOffset.ascent + (height - this._fontOffset.height * this._lines.length) / 2;
  4596. break;
  4597. }
  4598. rootY += this._currentMeasure.top;
  4599. var maxLineWidth = 0;
  4600. for (var i = 0; i < this._lines.length; i++) {
  4601. var line = this._lines[i];
  4602. if (i !== 0 && this._lineSpacing.internalValue !== 0) {
  4603. if (this._lineSpacing.isPixel) {
  4604. rootY += this._lineSpacing.getValue(this._host);
  4605. }
  4606. else {
  4607. rootY = rootY + (this._lineSpacing.getValue(this._host) * this._height.getValueInPixel(this._host, this._cachedParentMeasure.height));
  4608. }
  4609. }
  4610. this._drawText(line.text, line.width, rootY, context);
  4611. rootY += this._fontOffset.height;
  4612. if (line.width > maxLineWidth)
  4613. maxLineWidth = line.width;
  4614. }
  4615. if (this._resizeToFit) {
  4616. this.width = this.paddingLeftInPixels + this.paddingRightInPixels + maxLineWidth + 'px';
  4617. this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
  4618. }
  4619. };
  4620. TextBlock.prototype.dispose = function () {
  4621. _super.prototype.dispose.call(this);
  4622. this.onTextChangedObservable.clear();
  4623. };
  4624. return TextBlock;
  4625. }(GUI.Control));
  4626. GUI.TextBlock = TextBlock;
  4627. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4628. })(BABYLON || (BABYLON = {}));
  4629. //# sourceMappingURL=textBlock.js.map
  4630. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4631. var DOMImage = Image;
  4632. var BABYLON;
  4633. (function (BABYLON) {
  4634. var GUI;
  4635. (function (GUI) {
  4636. /**
  4637. * Class used to create 2D images
  4638. */
  4639. var Image = /** @class */ (function (_super) {
  4640. __extends(Image, _super);
  4641. /**
  4642. * Creates a new Image
  4643. * @param name defines the control name
  4644. * @param url defines the image url
  4645. */
  4646. function Image(name, url) {
  4647. if (url === void 0) { url = null; }
  4648. var _this = _super.call(this, name) || this;
  4649. _this.name = name;
  4650. _this._loaded = false;
  4651. _this._stretch = Image.STRETCH_FILL;
  4652. _this._autoScale = false;
  4653. _this._sourceLeft = 0;
  4654. _this._sourceTop = 0;
  4655. _this._sourceWidth = 0;
  4656. _this._sourceHeight = 0;
  4657. _this._cellWidth = 0;
  4658. _this._cellHeight = 0;
  4659. _this._cellId = -1;
  4660. _this.source = url;
  4661. return _this;
  4662. }
  4663. Object.defineProperty(Image.prototype, "sourceLeft", {
  4664. /**
  4665. * Gets or sets the left coordinate in the source image
  4666. */
  4667. get: function () {
  4668. return this._sourceLeft;
  4669. },
  4670. set: function (value) {
  4671. if (this._sourceLeft === value) {
  4672. return;
  4673. }
  4674. this._sourceLeft = value;
  4675. this._markAsDirty();
  4676. },
  4677. enumerable: true,
  4678. configurable: true
  4679. });
  4680. Object.defineProperty(Image.prototype, "sourceTop", {
  4681. /**
  4682. * Gets or sets the top coordinate in the source image
  4683. */
  4684. get: function () {
  4685. return this._sourceTop;
  4686. },
  4687. set: function (value) {
  4688. if (this._sourceTop === value) {
  4689. return;
  4690. }
  4691. this._sourceTop = value;
  4692. this._markAsDirty();
  4693. },
  4694. enumerable: true,
  4695. configurable: true
  4696. });
  4697. Object.defineProperty(Image.prototype, "sourceWidth", {
  4698. /**
  4699. * Gets or sets the width to capture in the source image
  4700. */
  4701. get: function () {
  4702. return this._sourceWidth;
  4703. },
  4704. set: function (value) {
  4705. if (this._sourceWidth === value) {
  4706. return;
  4707. }
  4708. this._sourceWidth = value;
  4709. this._markAsDirty();
  4710. },
  4711. enumerable: true,
  4712. configurable: true
  4713. });
  4714. Object.defineProperty(Image.prototype, "sourceHeight", {
  4715. /**
  4716. * Gets or sets the height to capture in the source image
  4717. */
  4718. get: function () {
  4719. return this._sourceHeight;
  4720. },
  4721. set: function (value) {
  4722. if (this._sourceHeight === value) {
  4723. return;
  4724. }
  4725. this._sourceHeight = value;
  4726. this._markAsDirty();
  4727. },
  4728. enumerable: true,
  4729. configurable: true
  4730. });
  4731. Object.defineProperty(Image.prototype, "autoScale", {
  4732. /**
  4733. * Gets or sets a boolean indicating if the image can force its container to adapt its size
  4734. * @see http://doc.babylonjs.com/how_to/gui#image
  4735. */
  4736. get: function () {
  4737. return this._autoScale;
  4738. },
  4739. set: function (value) {
  4740. if (this._autoScale === value) {
  4741. return;
  4742. }
  4743. this._autoScale = value;
  4744. if (value && this._loaded) {
  4745. this.synchronizeSizeWithContent();
  4746. }
  4747. },
  4748. enumerable: true,
  4749. configurable: true
  4750. });
  4751. Object.defineProperty(Image.prototype, "stretch", {
  4752. /** Gets or sets the streching mode used by the image */
  4753. get: function () {
  4754. return this._stretch;
  4755. },
  4756. set: function (value) {
  4757. if (this._stretch === value) {
  4758. return;
  4759. }
  4760. this._stretch = value;
  4761. this._markAsDirty();
  4762. },
  4763. enumerable: true,
  4764. configurable: true
  4765. });
  4766. Object.defineProperty(Image.prototype, "domImage", {
  4767. get: function () {
  4768. return this._domImage;
  4769. },
  4770. /**
  4771. * Gets or sets the internal DOM image used to render the control
  4772. */
  4773. set: function (value) {
  4774. var _this = this;
  4775. this._domImage = value;
  4776. this._loaded = false;
  4777. if (this._domImage.width) {
  4778. this._onImageLoaded();
  4779. }
  4780. else {
  4781. this._domImage.onload = function () {
  4782. _this._onImageLoaded();
  4783. };
  4784. }
  4785. },
  4786. enumerable: true,
  4787. configurable: true
  4788. });
  4789. Image.prototype._onImageLoaded = function () {
  4790. this._imageWidth = this._domImage.width;
  4791. this._imageHeight = this._domImage.height;
  4792. this._loaded = true;
  4793. if (this._autoScale) {
  4794. this.synchronizeSizeWithContent();
  4795. }
  4796. this._markAsDirty();
  4797. };
  4798. Object.defineProperty(Image.prototype, "source", {
  4799. /**
  4800. * Gets or sets image source url
  4801. */
  4802. set: function (value) {
  4803. var _this = this;
  4804. if (this._source === value) {
  4805. return;
  4806. }
  4807. this._loaded = false;
  4808. this._source = value;
  4809. this._domImage = new DOMImage();
  4810. this._domImage.onload = function () {
  4811. _this._onImageLoaded();
  4812. };
  4813. if (value) {
  4814. BABYLON.Tools.SetCorsBehavior(value, this._domImage);
  4815. this._domImage.src = value;
  4816. }
  4817. },
  4818. enumerable: true,
  4819. configurable: true
  4820. });
  4821. Object.defineProperty(Image.prototype, "cellWidth", {
  4822. /**
  4823. * Gets or sets the cell width to use when animation sheet is enabled
  4824. * @see http://doc.babylonjs.com/how_to/gui#image
  4825. */
  4826. get: function () {
  4827. return this._cellWidth;
  4828. },
  4829. set: function (value) {
  4830. if (this._cellWidth === value) {
  4831. return;
  4832. }
  4833. this._cellWidth = value;
  4834. this._markAsDirty();
  4835. },
  4836. enumerable: true,
  4837. configurable: true
  4838. });
  4839. Object.defineProperty(Image.prototype, "cellHeight", {
  4840. /**
  4841. * Gets or sets the cell height to use when animation sheet is enabled
  4842. * @see http://doc.babylonjs.com/how_to/gui#image
  4843. */
  4844. get: function () {
  4845. return this._cellHeight;
  4846. },
  4847. set: function (value) {
  4848. if (this._cellHeight === value) {
  4849. return;
  4850. }
  4851. this._cellHeight = value;
  4852. this._markAsDirty();
  4853. },
  4854. enumerable: true,
  4855. configurable: true
  4856. });
  4857. Object.defineProperty(Image.prototype, "cellId", {
  4858. /**
  4859. * Gets or sets the cell id to use (this will turn on the animation sheet mode)
  4860. * @see http://doc.babylonjs.com/how_to/gui#image
  4861. */
  4862. get: function () {
  4863. return this._cellId;
  4864. },
  4865. set: function (value) {
  4866. if (this._cellId === value) {
  4867. return;
  4868. }
  4869. this._cellId = value;
  4870. this._markAsDirty();
  4871. },
  4872. enumerable: true,
  4873. configurable: true
  4874. });
  4875. Image.prototype._getTypeName = function () {
  4876. return "Image";
  4877. };
  4878. /** Force the control to synchronize with its content */
  4879. Image.prototype.synchronizeSizeWithContent = function () {
  4880. if (!this._loaded) {
  4881. return;
  4882. }
  4883. this.width = this._domImage.width + "px";
  4884. this.height = this._domImage.height + "px";
  4885. };
  4886. Image.prototype._draw = function (parentMeasure, context) {
  4887. context.save();
  4888. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  4889. context.shadowColor = this.shadowColor;
  4890. context.shadowBlur = this.shadowBlur;
  4891. context.shadowOffsetX = this.shadowOffsetX;
  4892. context.shadowOffsetY = this.shadowOffsetY;
  4893. }
  4894. var x, y, width, height;
  4895. if (this.cellId == -1) {
  4896. x = this._sourceLeft;
  4897. y = this._sourceTop;
  4898. width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
  4899. height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
  4900. }
  4901. else {
  4902. var rowCount = this._domImage.naturalWidth / this.cellWidth;
  4903. var column = (this.cellId / rowCount) >> 0;
  4904. var row = this.cellId % rowCount;
  4905. x = this.cellWidth * row;
  4906. y = this.cellHeight * column;
  4907. width = this.cellWidth;
  4908. height = this.cellHeight;
  4909. }
  4910. this._applyStates(context);
  4911. if (this._processMeasures(parentMeasure, context)) {
  4912. if (this._loaded) {
  4913. switch (this._stretch) {
  4914. case Image.STRETCH_NONE:
  4915. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4916. break;
  4917. case Image.STRETCH_FILL:
  4918. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4919. break;
  4920. case Image.STRETCH_UNIFORM:
  4921. var hRatio = this._currentMeasure.width / width;
  4922. var vRatio = this._currentMeasure.height / height;
  4923. var ratio = Math.min(hRatio, vRatio);
  4924. var centerX = (this._currentMeasure.width - width * ratio) / 2;
  4925. var centerY = (this._currentMeasure.height - height * ratio) / 2;
  4926. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
  4927. break;
  4928. case Image.STRETCH_EXTEND:
  4929. context.drawImage(this._domImage, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  4930. if (this._autoScale) {
  4931. this.synchronizeSizeWithContent();
  4932. }
  4933. if (this._root && this._root.parent) { // Will update root size if root is not the top root
  4934. this._root.width = this.width;
  4935. this._root.height = this.height;
  4936. }
  4937. break;
  4938. }
  4939. }
  4940. }
  4941. context.restore();
  4942. };
  4943. Object.defineProperty(Image, "STRETCH_NONE", {
  4944. /** STRETCH_NONE */
  4945. get: function () {
  4946. return Image._STRETCH_NONE;
  4947. },
  4948. enumerable: true,
  4949. configurable: true
  4950. });
  4951. Object.defineProperty(Image, "STRETCH_FILL", {
  4952. /** STRETCH_FILL */
  4953. get: function () {
  4954. return Image._STRETCH_FILL;
  4955. },
  4956. enumerable: true,
  4957. configurable: true
  4958. });
  4959. Object.defineProperty(Image, "STRETCH_UNIFORM", {
  4960. /** STRETCH_UNIFORM */
  4961. get: function () {
  4962. return Image._STRETCH_UNIFORM;
  4963. },
  4964. enumerable: true,
  4965. configurable: true
  4966. });
  4967. Object.defineProperty(Image, "STRETCH_EXTEND", {
  4968. /** STRETCH_EXTEND */
  4969. get: function () {
  4970. return Image._STRETCH_EXTEND;
  4971. },
  4972. enumerable: true,
  4973. configurable: true
  4974. });
  4975. // Static
  4976. Image._STRETCH_NONE = 0;
  4977. Image._STRETCH_FILL = 1;
  4978. Image._STRETCH_UNIFORM = 2;
  4979. Image._STRETCH_EXTEND = 3;
  4980. return Image;
  4981. }(GUI.Control));
  4982. GUI.Image = Image;
  4983. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  4984. })(BABYLON || (BABYLON = {}));
  4985. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4986. var BABYLON;
  4987. (function (BABYLON) {
  4988. var GUI;
  4989. (function (GUI) {
  4990. /**
  4991. * Class used to create 2D buttons
  4992. */
  4993. var Button = /** @class */ (function (_super) {
  4994. __extends(Button, _super);
  4995. /**
  4996. * Creates a new Button
  4997. * @param name defines the name of the button
  4998. */
  4999. function Button(name) {
  5000. var _this = _super.call(this, name) || this;
  5001. _this.name = name;
  5002. _this.thickness = 1;
  5003. _this.isPointerBlocker = true;
  5004. _this.pointerEnterAnimation = function () {
  5005. _this.alpha -= 0.1;
  5006. };
  5007. _this.pointerOutAnimation = function () {
  5008. _this.alpha += 0.1;
  5009. };
  5010. _this.pointerDownAnimation = function () {
  5011. _this.scaleX -= 0.05;
  5012. _this.scaleY -= 0.05;
  5013. };
  5014. _this.pointerUpAnimation = function () {
  5015. _this.scaleX += 0.05;
  5016. _this.scaleY += 0.05;
  5017. };
  5018. return _this;
  5019. }
  5020. Button.prototype._getTypeName = function () {
  5021. return "Button";
  5022. };
  5023. // While being a container, the button behaves like a control.
  5024. /** @hidden */
  5025. Button.prototype._processPicking = function (x, y, type, pointerId, buttonIndex) {
  5026. if (!this.isHitTestVisible || !this.isVisible || this.notRenderable) {
  5027. return false;
  5028. }
  5029. if (!_super.prototype.contains.call(this, x, y)) {
  5030. return false;
  5031. }
  5032. this._processObservables(type, x, y, pointerId, buttonIndex);
  5033. return true;
  5034. };
  5035. /** @hidden */
  5036. Button.prototype._onPointerEnter = function (target) {
  5037. if (!_super.prototype._onPointerEnter.call(this, target)) {
  5038. return false;
  5039. }
  5040. if (this.pointerEnterAnimation) {
  5041. this.pointerEnterAnimation();
  5042. }
  5043. return true;
  5044. };
  5045. /** @hidden */
  5046. Button.prototype._onPointerOut = function (target) {
  5047. if (this.pointerOutAnimation) {
  5048. this.pointerOutAnimation();
  5049. }
  5050. _super.prototype._onPointerOut.call(this, target);
  5051. };
  5052. /** @hidden */
  5053. Button.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5054. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5055. return false;
  5056. }
  5057. if (this.pointerDownAnimation) {
  5058. this.pointerDownAnimation();
  5059. }
  5060. return true;
  5061. };
  5062. /** @hidden */
  5063. Button.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5064. if (this.pointerUpAnimation) {
  5065. this.pointerUpAnimation();
  5066. }
  5067. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5068. };
  5069. // Statics
  5070. /**
  5071. * Creates a new button made with an image and a text
  5072. * @param name defines the name of the button
  5073. * @param text defines the text of the button
  5074. * @param imageUrl defines the url of the image
  5075. * @returns a new Button
  5076. */
  5077. Button.CreateImageButton = function (name, text, imageUrl) {
  5078. var result = new Button(name);
  5079. // Adding text
  5080. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  5081. textBlock.textWrapping = true;
  5082. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  5083. textBlock.paddingLeft = "20%";
  5084. result.addControl(textBlock);
  5085. // Adding image
  5086. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  5087. iconImage.width = "20%";
  5088. iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
  5089. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5090. result.addControl(iconImage);
  5091. return result;
  5092. };
  5093. /**
  5094. * Creates a new button made with an image
  5095. * @param name defines the name of the button
  5096. * @param imageUrl defines the url of the image
  5097. * @returns a new Button
  5098. */
  5099. Button.CreateImageOnlyButton = function (name, imageUrl) {
  5100. var result = new Button(name);
  5101. // Adding image
  5102. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  5103. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  5104. iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  5105. result.addControl(iconImage);
  5106. return result;
  5107. };
  5108. /**
  5109. * Creates a new button made with a text
  5110. * @param name defines the name of the button
  5111. * @param text defines the text of the button
  5112. * @returns a new Button
  5113. */
  5114. Button.CreateSimpleButton = function (name, text) {
  5115. var result = new Button(name);
  5116. // Adding text
  5117. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  5118. textBlock.textWrapping = true;
  5119. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  5120. result.addControl(textBlock);
  5121. return result;
  5122. };
  5123. /**
  5124. * Creates a new button made with an image and a centered text
  5125. * @param name defines the name of the button
  5126. * @param text defines the text of the button
  5127. * @param imageUrl defines the url of the image
  5128. * @returns a new Button
  5129. */
  5130. Button.CreateImageWithCenterTextButton = function (name, text, imageUrl) {
  5131. var result = new Button(name);
  5132. // Adding image
  5133. var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
  5134. iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
  5135. result.addControl(iconImage);
  5136. // Adding text
  5137. var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
  5138. textBlock.textWrapping = true;
  5139. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  5140. result.addControl(textBlock);
  5141. return result;
  5142. };
  5143. return Button;
  5144. }(GUI.Rectangle));
  5145. GUI.Button = Button;
  5146. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5147. })(BABYLON || (BABYLON = {}));
  5148. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5149. var BABYLON;
  5150. (function (BABYLON) {
  5151. var GUI;
  5152. (function (GUI) {
  5153. /** Class used to create color pickers */
  5154. var ColorPicker = /** @class */ (function (_super) {
  5155. __extends(ColorPicker, _super);
  5156. /**
  5157. * Creates a new ColorPicker
  5158. * @param name defines the control name
  5159. */
  5160. function ColorPicker(name) {
  5161. var _this = _super.call(this, name) || this;
  5162. _this.name = name;
  5163. _this._value = BABYLON.Color3.Red();
  5164. _this._tmpColor = new BABYLON.Color3();
  5165. _this._pointerStartedOnSquare = false;
  5166. _this._pointerStartedOnWheel = false;
  5167. _this._squareLeft = 0;
  5168. _this._squareTop = 0;
  5169. _this._squareSize = 0;
  5170. _this._h = 360;
  5171. _this._s = 1;
  5172. _this._v = 1;
  5173. /**
  5174. * Observable raised when the value changes
  5175. */
  5176. _this.onValueChangedObservable = new BABYLON.Observable();
  5177. // Events
  5178. _this._pointerIsDown = false;
  5179. _this.value = new BABYLON.Color3(.88, .1, .1);
  5180. _this.size = "200px";
  5181. _this.isPointerBlocker = true;
  5182. return _this;
  5183. }
  5184. Object.defineProperty(ColorPicker.prototype, "value", {
  5185. /** Gets or sets the color of the color picker */
  5186. get: function () {
  5187. return this._value;
  5188. },
  5189. set: function (value) {
  5190. if (this._value.equals(value)) {
  5191. return;
  5192. }
  5193. this._value.copyFrom(value);
  5194. this._RGBtoHSV(this._value, this._tmpColor);
  5195. this._h = this._tmpColor.r;
  5196. this._s = Math.max(this._tmpColor.g, 0.00001);
  5197. this._v = Math.max(this._tmpColor.b, 0.00001);
  5198. this._markAsDirty();
  5199. this.onValueChangedObservable.notifyObservers(this._value);
  5200. },
  5201. enumerable: true,
  5202. configurable: true
  5203. });
  5204. Object.defineProperty(ColorPicker.prototype, "width", {
  5205. /** Gets or sets control width */
  5206. set: function (value) {
  5207. if (this._width.toString(this._host) === value) {
  5208. return;
  5209. }
  5210. if (this._width.fromString(value)) {
  5211. this._height.fromString(value);
  5212. this._markAsDirty();
  5213. }
  5214. },
  5215. enumerable: true,
  5216. configurable: true
  5217. });
  5218. Object.defineProperty(ColorPicker.prototype, "height", {
  5219. /** Gets or sets control height */
  5220. set: function (value) {
  5221. if (this._height.toString(this._host) === value) {
  5222. return;
  5223. }
  5224. if (this._height.fromString(value)) {
  5225. this._width.fromString(value);
  5226. this._markAsDirty();
  5227. }
  5228. },
  5229. enumerable: true,
  5230. configurable: true
  5231. });
  5232. Object.defineProperty(ColorPicker.prototype, "size", {
  5233. /** Gets or sets control size */
  5234. get: function () {
  5235. return this.width;
  5236. },
  5237. set: function (value) {
  5238. this.width = value;
  5239. },
  5240. enumerable: true,
  5241. configurable: true
  5242. });
  5243. ColorPicker.prototype._getTypeName = function () {
  5244. return "ColorPicker";
  5245. };
  5246. ColorPicker.prototype._updateSquareProps = function () {
  5247. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  5248. var wheelThickness = radius * .2;
  5249. var innerDiameter = (radius - wheelThickness) * 2;
  5250. var squareSize = innerDiameter / (Math.sqrt(2));
  5251. var offset = radius - squareSize * .5;
  5252. this._squareLeft = this._currentMeasure.left + offset;
  5253. this._squareTop = this._currentMeasure.top + offset;
  5254. this._squareSize = squareSize;
  5255. };
  5256. ColorPicker.prototype._drawGradientSquare = function (hueValue, left, top, width, height, context) {
  5257. var lgh = context.createLinearGradient(left, top, width + left, top);
  5258. lgh.addColorStop(0, '#fff');
  5259. lgh.addColorStop(1, 'hsl(' + hueValue + ', 100%, 50%)');
  5260. context.fillStyle = lgh;
  5261. context.fillRect(left, top, width, height);
  5262. var lgv = context.createLinearGradient(left, top, left, height + top);
  5263. lgv.addColorStop(0, 'rgba(0,0,0,0)');
  5264. lgv.addColorStop(1, '#000');
  5265. context.fillStyle = lgv;
  5266. context.fillRect(left, top, width, height);
  5267. };
  5268. ColorPicker.prototype._drawCircle = function (centerX, centerY, radius, context) {
  5269. context.beginPath();
  5270. context.arc(centerX, centerY, radius + 1, 0, 2 * Math.PI, false);
  5271. context.lineWidth = 3;
  5272. context.strokeStyle = '#333333';
  5273. context.stroke();
  5274. context.beginPath();
  5275. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  5276. context.lineWidth = 3;
  5277. context.strokeStyle = '#ffffff';
  5278. context.stroke();
  5279. };
  5280. ColorPicker.prototype._createColorWheelCanvas = function (radius, thickness) {
  5281. var canvas = document.createElement("canvas");
  5282. canvas.width = radius * 2;
  5283. canvas.height = radius * 2;
  5284. var context = canvas.getContext("2d");
  5285. var image = context.getImageData(0, 0, radius * 2, radius * 2);
  5286. var data = image.data;
  5287. var color = this._tmpColor;
  5288. var maxDistSq = radius * radius;
  5289. var innerRadius = radius - thickness;
  5290. var minDistSq = innerRadius * innerRadius;
  5291. for (var x = -radius; x < radius; x++) {
  5292. for (var y = -radius; y < radius; y++) {
  5293. var distSq = x * x + y * y;
  5294. if (distSq > maxDistSq || distSq < minDistSq) {
  5295. continue;
  5296. }
  5297. var dist = Math.sqrt(distSq);
  5298. var ang = Math.atan2(y, x);
  5299. this._HSVtoRGB(ang * 180 / Math.PI + 180, dist / radius, 1, color);
  5300. var index = ((x + radius) + ((y + radius) * 2 * radius)) * 4;
  5301. data[index] = color.r * 255;
  5302. data[index + 1] = color.g * 255;
  5303. data[index + 2] = color.b * 255;
  5304. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  5305. //apply less alpha to bigger color pickers
  5306. var alphaAmount = .2;
  5307. var maxAlpha = .2;
  5308. var minAlpha = .04;
  5309. var lowerRadius = 50;
  5310. var upperRadius = 150;
  5311. if (radius < lowerRadius) {
  5312. alphaAmount = maxAlpha;
  5313. }
  5314. else if (radius > upperRadius) {
  5315. alphaAmount = minAlpha;
  5316. }
  5317. else {
  5318. alphaAmount = (minAlpha - maxAlpha) * (radius - lowerRadius) / (upperRadius - lowerRadius) + maxAlpha;
  5319. }
  5320. var alphaRatio = (dist - innerRadius) / (radius - innerRadius);
  5321. if (alphaRatio < alphaAmount) {
  5322. data[index + 3] = 255 * (alphaRatio / alphaAmount);
  5323. }
  5324. else if (alphaRatio > 1 - alphaAmount) {
  5325. data[index + 3] = 255 * (1.0 - ((alphaRatio - (1 - alphaAmount)) / alphaAmount));
  5326. }
  5327. else {
  5328. data[index + 3] = 255;
  5329. }
  5330. }
  5331. }
  5332. context.putImageData(image, 0, 0);
  5333. return canvas;
  5334. };
  5335. ColorPicker.prototype._RGBtoHSV = function (color, result) {
  5336. var r = color.r;
  5337. var g = color.g;
  5338. var b = color.b;
  5339. var max = Math.max(r, g, b);
  5340. var min = Math.min(r, g, b);
  5341. var h = 0;
  5342. var s = 0;
  5343. var v = max;
  5344. var dm = max - min;
  5345. if (max !== 0) {
  5346. s = dm / max;
  5347. }
  5348. if (max != min) {
  5349. if (max == r) {
  5350. h = (g - b) / dm;
  5351. if (g < b) {
  5352. h += 6;
  5353. }
  5354. }
  5355. else if (max == g) {
  5356. h = (b - r) / dm + 2;
  5357. }
  5358. else if (max == b) {
  5359. h = (r - g) / dm + 4;
  5360. }
  5361. h *= 60;
  5362. }
  5363. result.r = h;
  5364. result.g = s;
  5365. result.b = v;
  5366. };
  5367. ColorPicker.prototype._HSVtoRGB = function (hue, saturation, value, result) {
  5368. var chroma = value * saturation;
  5369. var h = hue / 60;
  5370. var x = chroma * (1 - Math.abs((h % 2) - 1));
  5371. var r = 0;
  5372. var g = 0;
  5373. var b = 0;
  5374. if (h >= 0 && h <= 1) {
  5375. r = chroma;
  5376. g = x;
  5377. }
  5378. else if (h >= 1 && h <= 2) {
  5379. r = x;
  5380. g = chroma;
  5381. }
  5382. else if (h >= 2 && h <= 3) {
  5383. g = chroma;
  5384. b = x;
  5385. }
  5386. else if (h >= 3 && h <= 4) {
  5387. g = x;
  5388. b = chroma;
  5389. }
  5390. else if (h >= 4 && h <= 5) {
  5391. r = x;
  5392. b = chroma;
  5393. }
  5394. else if (h >= 5 && h <= 6) {
  5395. r = chroma;
  5396. b = x;
  5397. }
  5398. var m = value - chroma;
  5399. result.set((r + m), (g + m), (b + m));
  5400. };
  5401. /** @hidden */
  5402. ColorPicker.prototype._draw = function (parentMeasure, context) {
  5403. context.save();
  5404. this._applyStates(context);
  5405. if (this._processMeasures(parentMeasure, context)) {
  5406. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  5407. var wheelThickness = radius * .2;
  5408. var left = this._currentMeasure.left;
  5409. var top = this._currentMeasure.top;
  5410. if (!this._colorWheelCanvas || this._colorWheelCanvas.width != radius * 2) {
  5411. this._colorWheelCanvas = this._createColorWheelCanvas(radius, wheelThickness);
  5412. }
  5413. this._updateSquareProps();
  5414. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5415. context.shadowColor = this.shadowColor;
  5416. context.shadowBlur = this.shadowBlur;
  5417. context.shadowOffsetX = this.shadowOffsetX;
  5418. context.shadowOffsetY = this.shadowOffsetY;
  5419. context.fillRect(this._squareLeft, this._squareTop, this._squareSize, this._squareSize);
  5420. }
  5421. context.drawImage(this._colorWheelCanvas, left, top);
  5422. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5423. context.shadowBlur = 0;
  5424. context.shadowOffsetX = 0;
  5425. context.shadowOffsetY = 0;
  5426. }
  5427. this._drawGradientSquare(this._h, this._squareLeft, this._squareTop, this._squareSize, this._squareSize, context);
  5428. var cx = this._squareLeft + this._squareSize * this._s;
  5429. var cy = this._squareTop + this._squareSize * (1 - this._v);
  5430. this._drawCircle(cx, cy, radius * .04, context);
  5431. var dist = radius - wheelThickness * .5;
  5432. cx = left + radius + Math.cos((this._h - 180) * Math.PI / 180) * dist;
  5433. cy = top + radius + Math.sin((this._h - 180) * Math.PI / 180) * dist;
  5434. this._drawCircle(cx, cy, wheelThickness * .35, context);
  5435. }
  5436. context.restore();
  5437. };
  5438. ColorPicker.prototype._updateValueFromPointer = function (x, y) {
  5439. if (this._pointerStartedOnWheel) {
  5440. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  5441. var centerX = radius + this._currentMeasure.left;
  5442. var centerY = radius + this._currentMeasure.top;
  5443. this._h = Math.atan2(y - centerY, x - centerX) * 180 / Math.PI + 180;
  5444. }
  5445. else if (this._pointerStartedOnSquare) {
  5446. this._updateSquareProps();
  5447. this._s = (x - this._squareLeft) / this._squareSize;
  5448. this._v = 1 - (y - this._squareTop) / this._squareSize;
  5449. this._s = Math.min(this._s, 1);
  5450. this._s = Math.max(this._s, 0.00001);
  5451. this._v = Math.min(this._v, 1);
  5452. this._v = Math.max(this._v, 0.00001);
  5453. }
  5454. this._HSVtoRGB(this._h, this._s, this._v, this._tmpColor);
  5455. this.value = this._tmpColor;
  5456. };
  5457. ColorPicker.prototype._isPointOnSquare = function (coordinates) {
  5458. this._updateSquareProps();
  5459. var left = this._squareLeft;
  5460. var top = this._squareTop;
  5461. var size = this._squareSize;
  5462. if (coordinates.x >= left && coordinates.x <= left + size &&
  5463. coordinates.y >= top && coordinates.y <= top + size) {
  5464. return true;
  5465. }
  5466. return false;
  5467. };
  5468. ColorPicker.prototype._isPointOnWheel = function (coordinates) {
  5469. var radius = Math.min(this._currentMeasure.width, this._currentMeasure.height) * .5;
  5470. var centerX = radius + this._currentMeasure.left;
  5471. var centerY = radius + this._currentMeasure.top;
  5472. var wheelThickness = radius * .2;
  5473. var innerRadius = radius - wheelThickness;
  5474. var radiusSq = radius * radius;
  5475. var innerRadiusSq = innerRadius * innerRadius;
  5476. var dx = coordinates.x - centerX;
  5477. var dy = coordinates.y - centerY;
  5478. var distSq = dx * dx + dy * dy;
  5479. if (distSq <= radiusSq && distSq >= innerRadiusSq) {
  5480. return true;
  5481. }
  5482. return false;
  5483. };
  5484. ColorPicker.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5485. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5486. return false;
  5487. }
  5488. this._pointerIsDown = true;
  5489. this._pointerStartedOnSquare = false;
  5490. this._pointerStartedOnWheel = false;
  5491. if (this._isPointOnSquare(coordinates)) {
  5492. this._pointerStartedOnSquare = true;
  5493. }
  5494. else if (this._isPointOnWheel(coordinates)) {
  5495. this._pointerStartedOnWheel = true;
  5496. }
  5497. this._updateValueFromPointer(coordinates.x, coordinates.y);
  5498. this._host._capturingControl[pointerId] = this;
  5499. return true;
  5500. };
  5501. ColorPicker.prototype._onPointerMove = function (target, coordinates) {
  5502. if (this._pointerIsDown) {
  5503. this._updateValueFromPointer(coordinates.x, coordinates.y);
  5504. }
  5505. _super.prototype._onPointerMove.call(this, target, coordinates);
  5506. };
  5507. ColorPicker.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5508. this._pointerIsDown = false;
  5509. delete this._host._capturingControl[pointerId];
  5510. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5511. };
  5512. return ColorPicker;
  5513. }(GUI.Control));
  5514. GUI.ColorPicker = ColorPicker;
  5515. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5516. })(BABYLON || (BABYLON = {}));
  5517. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5518. var BABYLON;
  5519. (function (BABYLON) {
  5520. var GUI;
  5521. (function (GUI) {
  5522. /**
  5523. * Class used to create input text control
  5524. */
  5525. var InputText = /** @class */ (function (_super) {
  5526. __extends(InputText, _super);
  5527. /**
  5528. * Creates a new InputText
  5529. * @param name defines the control name
  5530. * @param text defines the text of the control
  5531. */
  5532. function InputText(name, text) {
  5533. if (text === void 0) { text = ""; }
  5534. var _this = _super.call(this, name) || this;
  5535. _this.name = name;
  5536. _this._text = "";
  5537. _this._placeholderText = "";
  5538. _this._background = "#222222";
  5539. _this._focusedBackground = "#000000";
  5540. _this._placeholderColor = "gray";
  5541. _this._thickness = 1;
  5542. _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
  5543. _this._autoStretchWidth = true;
  5544. _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
  5545. _this._isFocused = false;
  5546. _this._blinkIsEven = false;
  5547. _this._cursorOffset = 0;
  5548. /** Gets or sets a string representing the message displayed on mobile when the control gets the focus */
  5549. _this.promptMessage = "Please enter text:";
  5550. /** Observable raised when the text changes */
  5551. _this.onTextChangedObservable = new BABYLON.Observable();
  5552. /** Observable raised when the control gets the focus */
  5553. _this.onFocusObservable = new BABYLON.Observable();
  5554. /** Observable raised when the control loses the focus */
  5555. _this.onBlurObservable = new BABYLON.Observable();
  5556. _this.text = text;
  5557. return _this;
  5558. }
  5559. Object.defineProperty(InputText.prototype, "maxWidth", {
  5560. /** Gets or sets the maximum width allowed by the control */
  5561. get: function () {
  5562. return this._maxWidth.toString(this._host);
  5563. },
  5564. set: function (value) {
  5565. if (this._maxWidth.toString(this._host) === value) {
  5566. return;
  5567. }
  5568. if (this._maxWidth.fromString(value)) {
  5569. this._markAsDirty();
  5570. }
  5571. },
  5572. enumerable: true,
  5573. configurable: true
  5574. });
  5575. Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
  5576. /** Gets the maximum width allowed by the control in pixels */
  5577. get: function () {
  5578. return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
  5579. },
  5580. enumerable: true,
  5581. configurable: true
  5582. });
  5583. Object.defineProperty(InputText.prototype, "margin", {
  5584. /** Gets or sets control margin */
  5585. get: function () {
  5586. return this._margin.toString(this._host);
  5587. },
  5588. set: function (value) {
  5589. if (this._margin.toString(this._host) === value) {
  5590. return;
  5591. }
  5592. if (this._margin.fromString(value)) {
  5593. this._markAsDirty();
  5594. }
  5595. },
  5596. enumerable: true,
  5597. configurable: true
  5598. });
  5599. Object.defineProperty(InputText.prototype, "marginInPixels", {
  5600. /** Gets control margin in pixels */
  5601. get: function () {
  5602. return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
  5603. },
  5604. enumerable: true,
  5605. configurable: true
  5606. });
  5607. Object.defineProperty(InputText.prototype, "autoStretchWidth", {
  5608. /** Gets or sets a boolean indicating if the control can auto stretch its width to adapt to the text */
  5609. get: function () {
  5610. return this._autoStretchWidth;
  5611. },
  5612. set: function (value) {
  5613. if (this._autoStretchWidth === value) {
  5614. return;
  5615. }
  5616. this._autoStretchWidth = value;
  5617. this._markAsDirty();
  5618. },
  5619. enumerable: true,
  5620. configurable: true
  5621. });
  5622. Object.defineProperty(InputText.prototype, "thickness", {
  5623. /** Gets or sets border thickness */
  5624. get: function () {
  5625. return this._thickness;
  5626. },
  5627. set: function (value) {
  5628. if (this._thickness === value) {
  5629. return;
  5630. }
  5631. this._thickness = value;
  5632. this._markAsDirty();
  5633. },
  5634. enumerable: true,
  5635. configurable: true
  5636. });
  5637. Object.defineProperty(InputText.prototype, "focusedBackground", {
  5638. /** Gets or sets the background color when focused */
  5639. get: function () {
  5640. return this._focusedBackground;
  5641. },
  5642. set: function (value) {
  5643. if (this._focusedBackground === value) {
  5644. return;
  5645. }
  5646. this._focusedBackground = value;
  5647. this._markAsDirty();
  5648. },
  5649. enumerable: true,
  5650. configurable: true
  5651. });
  5652. Object.defineProperty(InputText.prototype, "background", {
  5653. /** Gets or sets the background color */
  5654. get: function () {
  5655. return this._background;
  5656. },
  5657. set: function (value) {
  5658. if (this._background === value) {
  5659. return;
  5660. }
  5661. this._background = value;
  5662. this._markAsDirty();
  5663. },
  5664. enumerable: true,
  5665. configurable: true
  5666. });
  5667. Object.defineProperty(InputText.prototype, "placeholderColor", {
  5668. /** Gets or sets the placeholder color */
  5669. get: function () {
  5670. return this._placeholderColor;
  5671. },
  5672. set: function (value) {
  5673. if (this._placeholderColor === value) {
  5674. return;
  5675. }
  5676. this._placeholderColor = value;
  5677. this._markAsDirty();
  5678. },
  5679. enumerable: true,
  5680. configurable: true
  5681. });
  5682. Object.defineProperty(InputText.prototype, "placeholderText", {
  5683. /** Gets or sets the text displayed when the control is empty */
  5684. get: function () {
  5685. return this._placeholderText;
  5686. },
  5687. set: function (value) {
  5688. if (this._placeholderText === value) {
  5689. return;
  5690. }
  5691. this._placeholderText = value;
  5692. this._markAsDirty();
  5693. },
  5694. enumerable: true,
  5695. configurable: true
  5696. });
  5697. Object.defineProperty(InputText.prototype, "text", {
  5698. /** Gets or sets the text displayed in the control */
  5699. get: function () {
  5700. return this._text;
  5701. },
  5702. set: function (value) {
  5703. if (this._text === value) {
  5704. return;
  5705. }
  5706. this._text = value;
  5707. this._markAsDirty();
  5708. this.onTextChangedObservable.notifyObservers(this);
  5709. },
  5710. enumerable: true,
  5711. configurable: true
  5712. });
  5713. Object.defineProperty(InputText.prototype, "width", {
  5714. /** Gets or sets control width */
  5715. get: function () {
  5716. return this._width.toString(this._host);
  5717. },
  5718. set: function (value) {
  5719. if (this._width.toString(this._host) === value) {
  5720. return;
  5721. }
  5722. if (this._width.fromString(value)) {
  5723. this._markAsDirty();
  5724. }
  5725. this.autoStretchWidth = false;
  5726. },
  5727. enumerable: true,
  5728. configurable: true
  5729. });
  5730. /** @hidden */
  5731. InputText.prototype.onBlur = function () {
  5732. this._isFocused = false;
  5733. this._scrollLeft = null;
  5734. this._cursorOffset = 0;
  5735. clearTimeout(this._blinkTimeout);
  5736. this._markAsDirty();
  5737. this.onBlurObservable.notifyObservers(this);
  5738. };
  5739. /** @hidden */
  5740. InputText.prototype.onFocus = function () {
  5741. this._scrollLeft = null;
  5742. this._isFocused = true;
  5743. this._blinkIsEven = false;
  5744. this._cursorOffset = 0;
  5745. this._markAsDirty();
  5746. this.onFocusObservable.notifyObservers(this);
  5747. if (navigator.userAgent.indexOf("Mobile") !== -1) {
  5748. var value = prompt(this.promptMessage);
  5749. if (value !== null) {
  5750. this.text = value;
  5751. }
  5752. this._host.focusedControl = null;
  5753. return;
  5754. }
  5755. };
  5756. InputText.prototype._getTypeName = function () {
  5757. return "InputText";
  5758. };
  5759. /** @hidden */
  5760. InputText.prototype.processKey = function (keyCode, key) {
  5761. // Specific cases
  5762. switch (keyCode) {
  5763. case 32: //SPACE
  5764. key = " "; //ie11 key for space is "Spacebar"
  5765. break;
  5766. case 8: // BACKSPACE
  5767. if (this._text && this._text.length > 0) {
  5768. if (this._cursorOffset === 0) {
  5769. this.text = this._text.substr(0, this._text.length - 1);
  5770. }
  5771. else {
  5772. var deletePosition = this._text.length - this._cursorOffset;
  5773. if (deletePosition > 0) {
  5774. this.text = this._text.slice(0, deletePosition - 1) + this._text.slice(deletePosition);
  5775. }
  5776. }
  5777. }
  5778. return;
  5779. case 46: // DELETE
  5780. if (this._text && this._text.length > 0) {
  5781. var deletePosition = this._text.length - this._cursorOffset;
  5782. this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
  5783. this._cursorOffset--;
  5784. }
  5785. return;
  5786. case 13: // RETURN
  5787. this._host.focusedControl = null;
  5788. return;
  5789. case 35: // END
  5790. this._cursorOffset = 0;
  5791. this._blinkIsEven = false;
  5792. this._markAsDirty();
  5793. return;
  5794. case 36: // HOME
  5795. this._cursorOffset = this._text.length;
  5796. this._blinkIsEven = false;
  5797. this._markAsDirty();
  5798. return;
  5799. case 37: // LEFT
  5800. this._cursorOffset++;
  5801. if (this._cursorOffset > this._text.length) {
  5802. this._cursorOffset = this._text.length;
  5803. }
  5804. this._blinkIsEven = false;
  5805. this._markAsDirty();
  5806. return;
  5807. case 39: // RIGHT
  5808. this._cursorOffset--;
  5809. if (this._cursorOffset < 0) {
  5810. this._cursorOffset = 0;
  5811. }
  5812. this._blinkIsEven = false;
  5813. this._markAsDirty();
  5814. return;
  5815. }
  5816. // Printable characters
  5817. if ((keyCode === -1) || // Direct access
  5818. (keyCode === 32) || // Space
  5819. (keyCode > 47 && keyCode < 58) || // Numbers
  5820. (keyCode > 64 && keyCode < 91) || // Letters
  5821. (keyCode > 185 && keyCode < 193) || // Special characters
  5822. (keyCode > 218 && keyCode < 223) || // Special characters
  5823. (keyCode > 95 && keyCode < 112)) { // Numpad
  5824. if (this._cursorOffset === 0) {
  5825. this.text += key;
  5826. }
  5827. else {
  5828. var insertPosition = this._text.length - this._cursorOffset;
  5829. this.text = this._text.slice(0, insertPosition) + key + this._text.slice(insertPosition);
  5830. }
  5831. }
  5832. };
  5833. /** @hidden */
  5834. InputText.prototype.processKeyboard = function (evt) {
  5835. this.processKey(evt.keyCode, evt.key);
  5836. };
  5837. InputText.prototype._draw = function (parentMeasure, context) {
  5838. var _this = this;
  5839. context.save();
  5840. this._applyStates(context);
  5841. if (this._processMeasures(parentMeasure, context)) {
  5842. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5843. context.shadowColor = this.shadowColor;
  5844. context.shadowBlur = this.shadowBlur;
  5845. context.shadowOffsetX = this.shadowOffsetX;
  5846. context.shadowOffsetY = this.shadowOffsetY;
  5847. }
  5848. // Background
  5849. if (this._isFocused) {
  5850. if (this._focusedBackground) {
  5851. context.fillStyle = this._focusedBackground;
  5852. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  5853. }
  5854. }
  5855. else if (this._background) {
  5856. context.fillStyle = this._background;
  5857. context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
  5858. }
  5859. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  5860. context.shadowBlur = 0;
  5861. context.shadowOffsetX = 0;
  5862. context.shadowOffsetY = 0;
  5863. }
  5864. if (!this._fontOffset) {
  5865. this._fontOffset = GUI.Control._GetFontOffset(context.font);
  5866. }
  5867. // Text
  5868. var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width);
  5869. if (this.color) {
  5870. context.fillStyle = this.color;
  5871. }
  5872. var text = this._text;
  5873. if (!this._isFocused && !this._text && this._placeholderText) {
  5874. text = this._placeholderText;
  5875. if (this._placeholderColor) {
  5876. context.fillStyle = this._placeholderColor;
  5877. }
  5878. }
  5879. this._textWidth = context.measureText(text).width;
  5880. var marginWidth = this._margin.getValueInPixel(this._host, parentMeasure.width) * 2;
  5881. if (this._autoStretchWidth) {
  5882. this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), this._textWidth + marginWidth) + "px";
  5883. }
  5884. var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
  5885. var availableWidth = this._width.getValueInPixel(this._host, parentMeasure.width) - marginWidth;
  5886. context.save();
  5887. context.beginPath();
  5888. context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
  5889. context.clip();
  5890. if (this._isFocused && this._textWidth > availableWidth) {
  5891. var textLeft = clipTextLeft - this._textWidth + availableWidth;
  5892. if (!this._scrollLeft) {
  5893. this._scrollLeft = textLeft;
  5894. }
  5895. }
  5896. else {
  5897. this._scrollLeft = clipTextLeft;
  5898. }
  5899. context.fillText(text, this._scrollLeft, this._currentMeasure.top + rootY);
  5900. // Cursor
  5901. if (this._isFocused) {
  5902. // Need to move cursor
  5903. if (this._clickedCoordinate) {
  5904. var rightPosition = this._scrollLeft + this._textWidth;
  5905. var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
  5906. var currentSize = 0;
  5907. this._cursorOffset = 0;
  5908. var previousDist = 0;
  5909. do {
  5910. if (this._cursorOffset) {
  5911. previousDist = Math.abs(absoluteCursorPosition - currentSize);
  5912. }
  5913. this._cursorOffset++;
  5914. currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
  5915. } while (currentSize < absoluteCursorPosition && (text.length >= this._cursorOffset));
  5916. // Find closest move
  5917. if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
  5918. this._cursorOffset--;
  5919. }
  5920. this._blinkIsEven = false;
  5921. this._clickedCoordinate = null;
  5922. }
  5923. // Render cursor
  5924. if (!this._blinkIsEven) {
  5925. var cursorOffsetText = this.text.substr(this._text.length - this._cursorOffset);
  5926. var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
  5927. var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
  5928. if (cursorLeft < clipTextLeft) {
  5929. this._scrollLeft += (clipTextLeft - cursorLeft);
  5930. cursorLeft = clipTextLeft;
  5931. this._markAsDirty();
  5932. }
  5933. else if (cursorLeft > clipTextLeft + availableWidth) {
  5934. this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
  5935. cursorLeft = clipTextLeft + availableWidth;
  5936. this._markAsDirty();
  5937. }
  5938. context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
  5939. }
  5940. clearTimeout(this._blinkTimeout);
  5941. this._blinkTimeout = setTimeout(function () {
  5942. _this._blinkIsEven = !_this._blinkIsEven;
  5943. _this._markAsDirty();
  5944. }, 500);
  5945. }
  5946. context.restore();
  5947. // Border
  5948. if (this._thickness) {
  5949. if (this.color) {
  5950. context.strokeStyle = this.color;
  5951. }
  5952. context.lineWidth = this._thickness;
  5953. context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
  5954. }
  5955. }
  5956. context.restore();
  5957. };
  5958. InputText.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  5959. if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
  5960. return false;
  5961. }
  5962. this._clickedCoordinate = coordinates.x;
  5963. if (this._host.focusedControl === this) {
  5964. // Move cursor
  5965. clearTimeout(this._blinkTimeout);
  5966. this._markAsDirty();
  5967. return true;
  5968. }
  5969. this._host.focusedControl = this;
  5970. return true;
  5971. };
  5972. InputText.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  5973. _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
  5974. };
  5975. InputText.prototype.dispose = function () {
  5976. _super.prototype.dispose.call(this);
  5977. this.onBlurObservable.clear();
  5978. this.onFocusObservable.clear();
  5979. this.onTextChangedObservable.clear();
  5980. };
  5981. return InputText;
  5982. }(GUI.Control));
  5983. GUI.InputText = InputText;
  5984. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  5985. })(BABYLON || (BABYLON = {}));
  5986. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  5987. var BABYLON;
  5988. (function (BABYLON) {
  5989. var GUI;
  5990. (function (GUI) {
  5991. /**
  5992. * Class used to store key control properties
  5993. */
  5994. var KeyPropertySet = /** @class */ (function () {
  5995. function KeyPropertySet() {
  5996. }
  5997. return KeyPropertySet;
  5998. }());
  5999. GUI.KeyPropertySet = KeyPropertySet;
  6000. /**
  6001. * Class used to create virtual keyboard
  6002. */
  6003. var VirtualKeyboard = /** @class */ (function (_super) {
  6004. __extends(VirtualKeyboard, _super);
  6005. function VirtualKeyboard() {
  6006. var _this = _super !== null && _super.apply(this, arguments) || this;
  6007. /** Observable raised when a key is pressed */
  6008. _this.onKeyPressObservable = new BABYLON.Observable();
  6009. /** Gets or sets default key button width */
  6010. _this.defaultButtonWidth = "40px";
  6011. /** Gets or sets default key button height */
  6012. _this.defaultButtonHeight = "40px";
  6013. /** Gets or sets default key button left padding */
  6014. _this.defaultButtonPaddingLeft = "2px";
  6015. /** Gets or sets default key button right padding */
  6016. _this.defaultButtonPaddingRight = "2px";
  6017. /** Gets or sets default key button top padding */
  6018. _this.defaultButtonPaddingTop = "2px";
  6019. /** Gets or sets default key button bottom padding */
  6020. _this.defaultButtonPaddingBottom = "2px";
  6021. /** Gets or sets default key button foreground color */
  6022. _this.defaultButtonColor = "#DDD";
  6023. /** Gets or sets default key button background color */
  6024. _this.defaultButtonBackground = "#070707";
  6025. /** Gets or sets shift button foreground color */
  6026. _this.shiftButtonColor = "#7799FF";
  6027. /** Gets or sets shift button thickness*/
  6028. _this.selectedShiftThickness = 1;
  6029. /** Gets shift key state */
  6030. _this.shiftState = 0;
  6031. return _this;
  6032. }
  6033. VirtualKeyboard.prototype._getTypeName = function () {
  6034. return "VirtualKeyboard";
  6035. };
  6036. VirtualKeyboard.prototype._createKey = function (key, propertySet) {
  6037. var _this = this;
  6038. var button = GUI.Button.CreateSimpleButton(key, key);
  6039. button.width = propertySet && propertySet.width ? propertySet.width : this.defaultButtonWidth;
  6040. button.height = propertySet && propertySet.height ? propertySet.height : this.defaultButtonHeight;
  6041. button.color = propertySet && propertySet.color ? propertySet.color : this.defaultButtonColor;
  6042. button.background = propertySet && propertySet.background ? propertySet.background : this.defaultButtonBackground;
  6043. button.paddingLeft = propertySet && propertySet.paddingLeft ? propertySet.paddingLeft : this.defaultButtonPaddingLeft;
  6044. button.paddingRight = propertySet && propertySet.paddingRight ? propertySet.paddingRight : this.defaultButtonPaddingRight;
  6045. button.paddingTop = propertySet && propertySet.paddingTop ? propertySet.paddingTop : this.defaultButtonPaddingTop;
  6046. button.paddingBottom = propertySet && propertySet.paddingBottom ? propertySet.paddingBottom : this.defaultButtonPaddingBottom;
  6047. button.thickness = 0;
  6048. button.isFocusInvisible = true;
  6049. button.shadowColor = this.shadowColor;
  6050. button.shadowBlur = this.shadowBlur;
  6051. button.shadowOffsetX = this.shadowOffsetX;
  6052. button.shadowOffsetY = this.shadowOffsetY;
  6053. button.onPointerUpObservable.add(function () {
  6054. _this.onKeyPressObservable.notifyObservers(key);
  6055. });
  6056. return button;
  6057. };
  6058. /**
  6059. * Adds a new row of keys
  6060. * @param keys defines the list of keys to add
  6061. * @param propertySets defines the associated property sets
  6062. */
  6063. VirtualKeyboard.prototype.addKeysRow = function (keys, propertySets) {
  6064. var panel = new GUI.StackPanel();
  6065. panel.isVertical = false;
  6066. panel.isFocusInvisible = true;
  6067. for (var i = 0; i < keys.length; i++) {
  6068. var properties = null;
  6069. if (propertySets && propertySets.length === keys.length) {
  6070. properties = propertySets[i];
  6071. }
  6072. panel.addControl(this._createKey(keys[i], properties));
  6073. }
  6074. this.addControl(panel);
  6075. };
  6076. /**
  6077. * Set the shift key to a specific state
  6078. * @param shiftState defines the new shift state
  6079. */
  6080. VirtualKeyboard.prototype.applyShiftState = function (shiftState) {
  6081. if (!this.children) {
  6082. return;
  6083. }
  6084. for (var i = 0; i < this.children.length; i++) {
  6085. var row = this.children[i];
  6086. if (!row || !row.children) {
  6087. continue;
  6088. }
  6089. var rowContainer = row;
  6090. for (var j = 0; j < rowContainer.children.length; j++) {
  6091. var button = rowContainer.children[j];
  6092. if (!button || !button.children[0]) {
  6093. continue;
  6094. }
  6095. var button_tblock = button.children[0];
  6096. if (button_tblock.text === "\u21E7") {
  6097. button.color = (shiftState ? this.shiftButtonColor : this.defaultButtonColor);
  6098. button.thickness = (shiftState > 1 ? this.selectedShiftThickness : 0);
  6099. }
  6100. button_tblock.text = (shiftState > 0 ? button_tblock.text.toUpperCase() : button_tblock.text.toLowerCase());
  6101. }
  6102. }
  6103. };
  6104. Object.defineProperty(VirtualKeyboard.prototype, "connectedInputText", {
  6105. /** Gets the input text control attached with the keyboard */
  6106. get: function () {
  6107. return this._connectedInputText;
  6108. },
  6109. enumerable: true,
  6110. configurable: true
  6111. });
  6112. /**
  6113. * Connects the keyboard with an input text control
  6114. * @param input defines the target control
  6115. */
  6116. VirtualKeyboard.prototype.connect = function (input) {
  6117. var _this = this;
  6118. this.isVisible = false;
  6119. this._connectedInputText = input;
  6120. // Events hooking
  6121. this._onFocusObserver = input.onFocusObservable.add(function () {
  6122. _this.isVisible = true;
  6123. });
  6124. this._onBlurObserver = input.onBlurObservable.add(function () {
  6125. _this.isVisible = false;
  6126. });
  6127. this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
  6128. if (!_this._connectedInputText) {
  6129. return;
  6130. }
  6131. switch (key) {
  6132. case "\u21E7":
  6133. _this.shiftState++;
  6134. if (_this.shiftState > 2) {
  6135. _this.shiftState = 0;
  6136. }
  6137. _this.applyShiftState(_this.shiftState);
  6138. return;
  6139. case "\u2190":
  6140. _this._connectedInputText.processKey(8);
  6141. return;
  6142. case "\u21B5":
  6143. _this._connectedInputText.processKey(13);
  6144. return;
  6145. }
  6146. _this._connectedInputText.processKey(-1, (_this.shiftState ? key.toUpperCase() : key));
  6147. if (_this.shiftState === 1) {
  6148. _this.shiftState = 0;
  6149. _this.applyShiftState(_this.shiftState);
  6150. }
  6151. });
  6152. };
  6153. /**
  6154. * Disconnects the keyboard from an input text control
  6155. */
  6156. VirtualKeyboard.prototype.disconnect = function () {
  6157. if (!this._connectedInputText) {
  6158. return;
  6159. }
  6160. this._connectedInputText.onFocusObservable.remove(this._onFocusObserver);
  6161. this._connectedInputText.onBlurObservable.remove(this._onBlurObserver);
  6162. this.onKeyPressObservable.remove(this._onKeyPressObserver);
  6163. this._connectedInputText = null;
  6164. };
  6165. // Statics
  6166. /**
  6167. * Creates a new keyboard using a default layout
  6168. * @returns a new VirtualKeyboard
  6169. */
  6170. VirtualKeyboard.CreateDefaultLayout = function () {
  6171. var returnValue = new VirtualKeyboard();
  6172. returnValue.addKeysRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u2190"]);
  6173. returnValue.addKeysRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"]);
  6174. returnValue.addKeysRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\u21B5"]);
  6175. returnValue.addKeysRow(["\u21E7", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]);
  6176. returnValue.addKeysRow([" "], [{ width: "200px" }]);
  6177. return returnValue;
  6178. };
  6179. return VirtualKeyboard;
  6180. }(GUI.StackPanel));
  6181. GUI.VirtualKeyboard = VirtualKeyboard;
  6182. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6183. })(BABYLON || (BABYLON = {}));
  6184. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  6185. var BABYLON;
  6186. (function (BABYLON) {
  6187. var GUI;
  6188. (function (GUI) {
  6189. /**
  6190. * Class used to create multi line control
  6191. */
  6192. var MultiLine = /** @class */ (function (_super) {
  6193. __extends(MultiLine, _super);
  6194. /**
  6195. * Creates a new MultiLine
  6196. * @param name defines the control name
  6197. */
  6198. function MultiLine(name) {
  6199. var _this = _super.call(this, name) || this;
  6200. _this.name = name;
  6201. _this._lineWidth = 1;
  6202. /** Function called when a point is updated */
  6203. _this.onPointUpdate = function () {
  6204. _this._markAsDirty();
  6205. };
  6206. _this.isHitTestVisible = false;
  6207. _this._horizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  6208. _this._verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
  6209. _this._dash = [];
  6210. _this._points = [];
  6211. return _this;
  6212. }
  6213. Object.defineProperty(MultiLine.prototype, "dash", {
  6214. /** Gets or sets dash pattern */
  6215. get: function () {
  6216. return this._dash;
  6217. },
  6218. set: function (value) {
  6219. if (this._dash === value) {
  6220. return;
  6221. }
  6222. this._dash = value;
  6223. this._markAsDirty();
  6224. },
  6225. enumerable: true,
  6226. configurable: true
  6227. });
  6228. /**
  6229. * Gets point stored at specified index
  6230. * @param index defines the index to look for
  6231. * @returns the requested point if found
  6232. */
  6233. MultiLine.prototype.getAt = function (index) {
  6234. if (!this._points[index]) {
  6235. this._points[index] = new GUI.MultiLinePoint(this);
  6236. }
  6237. return this._points[index];
  6238. };
  6239. /**
  6240. * Adds new points to the point collection
  6241. * @param items defines the list of items (mesh, control or 2d coordiantes) to add
  6242. * @returns the list of created MultiLinePoint
  6243. */
  6244. MultiLine.prototype.add = function () {
  6245. var _this = this;
  6246. var items = [];
  6247. for (var _i = 0; _i < arguments.length; _i++) {
  6248. items[_i] = arguments[_i];
  6249. }
  6250. return items.map(function (item) { return _this.push(item); });
  6251. };
  6252. /**
  6253. * Adds a new point to the point collection
  6254. * @param item defines the item (mesh, control or 2d coordiantes) to add
  6255. * @returns the created MultiLinePoint
  6256. */
  6257. MultiLine.prototype.push = function (item) {
  6258. var point = this.getAt(this._points.length);
  6259. if (item == null)
  6260. return point;
  6261. if (item instanceof BABYLON.AbstractMesh) {
  6262. point.mesh = item;
  6263. }
  6264. else if (item instanceof GUI.Control) {
  6265. point.control = item;
  6266. }
  6267. else if (item.x != null && item.y != null) {
  6268. point.x = item.x;
  6269. point.y = item.y;
  6270. }
  6271. return point;
  6272. };
  6273. /**
  6274. * Remove a specific value or point from the active point collection
  6275. * @param value defines the value or point to remove
  6276. */
  6277. MultiLine.prototype.remove = function (value) {
  6278. var index;
  6279. if (value instanceof GUI.MultiLinePoint) {
  6280. index = this._points.indexOf(value);
  6281. if (index === -1) {
  6282. return;
  6283. }
  6284. }
  6285. else {
  6286. index = value;
  6287. }
  6288. var point = this._points[index];
  6289. if (!point) {
  6290. return;
  6291. }
  6292. point.dispose();
  6293. this._points.splice(index, 1);
  6294. };
  6295. Object.defineProperty(MultiLine.prototype, "lineWidth", {
  6296. /** Gets or sets line width */
  6297. get: function () {
  6298. return this._lineWidth;
  6299. },
  6300. set: function (value) {
  6301. if (this._lineWidth === value) {
  6302. return;
  6303. }
  6304. this._lineWidth = value;
  6305. this._markAsDirty();
  6306. },
  6307. enumerable: true,
  6308. configurable: true
  6309. });
  6310. Object.defineProperty(MultiLine.prototype, "horizontalAlignment", {
  6311. set: function (value) {
  6312. return;
  6313. },
  6314. enumerable: true,
  6315. configurable: true
  6316. });
  6317. Object.defineProperty(MultiLine.prototype, "verticalAlignment", {
  6318. set: function (value) {
  6319. return;
  6320. },
  6321. enumerable: true,
  6322. configurable: true
  6323. });
  6324. MultiLine.prototype._getTypeName = function () {
  6325. return "MultiLine";
  6326. };
  6327. MultiLine.prototype._draw = function (parentMeasure, context) {
  6328. context.save();
  6329. if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
  6330. context.shadowColor = this.shadowColor;
  6331. context.shadowBlur = this.shadowBlur;
  6332. context.shadowOffsetX = this.shadowOffsetX;
  6333. context.shadowOffsetY = this.shadowOffsetY;
  6334. }
  6335. this._applyStates(context);
  6336. if (this._processMeasures(parentMeasure, context)) {
  6337. context.strokeStyle = this.color;
  6338. context.lineWidth = this._lineWidth;
  6339. context.setLineDash(this._dash);
  6340. context.beginPath();
  6341. var first = true; //first index is not necessarily 0
  6342. this._points.forEach(function (point) {
  6343. if (!point) {
  6344. return;
  6345. }
  6346. if (first) {
  6347. context.moveTo(point._point.x, point._point.y);
  6348. first = false;
  6349. }
  6350. else {
  6351. context.lineTo(point._point.x, point._point.y);
  6352. }
  6353. });
  6354. context.stroke();
  6355. }
  6356. context.restore();
  6357. };
  6358. MultiLine.prototype._additionalProcessing = function (parentMeasure, context) {
  6359. var _this = this;
  6360. this._minX = null;
  6361. this._minY = null;
  6362. this._maxX = null;
  6363. this._maxY = null;
  6364. this._points.forEach(function (point, index) {
  6365. if (!point) {
  6366. return;
  6367. }
  6368. point.translate();
  6369. if (_this._minX == null || point._point.x < _this._minX)
  6370. _this._minX = point._point.x;
  6371. if (_this._minY == null || point._point.y < _this._minY)
  6372. _this._minY = point._point.y;
  6373. if (_this._maxX == null || point._point.x > _this._maxX)
  6374. _this._maxX = point._point.x;
  6375. if (_this._maxY == null || point._point.y > _this._maxY)
  6376. _this._maxY = point._point.y;
  6377. });
  6378. if (this._minX == null)
  6379. this._minX = 0;
  6380. if (this._minY == null)
  6381. this._minY = 0;
  6382. if (this._maxX == null)
  6383. this._maxX = 0;
  6384. if (this._maxY == null)
  6385. this._maxY = 0;
  6386. };
  6387. MultiLine.prototype._measure = function () {
  6388. if (this._minX == null || this._maxX == null || this._minY == null || this._maxY == null) {
  6389. return;
  6390. }
  6391. this._currentMeasure.width = Math.abs(this._maxX - this._minX) + this._lineWidth;
  6392. this._currentMeasure.height = Math.abs(this._maxY - this._minY) + this._lineWidth;
  6393. };
  6394. MultiLine.prototype._computeAlignment = function (parentMeasure, context) {
  6395. if (this._minX == null || this._minY == null) {
  6396. return;
  6397. }
  6398. this._currentMeasure.left = this._minX - this._lineWidth / 2;
  6399. this._currentMeasure.top = this._minY - this._lineWidth / 2;
  6400. };
  6401. MultiLine.prototype.dispose = function () {
  6402. while (this._points.length > 0) {
  6403. this.remove(this._points.length - 1);
  6404. }
  6405. _super.prototype.dispose.call(this);
  6406. };
  6407. return MultiLine;
  6408. }(GUI.Control));
  6409. GUI.MultiLine = MultiLine;
  6410. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6411. })(BABYLON || (BABYLON = {}));
  6412. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  6413. var BABYLON;
  6414. (function (BABYLON) {
  6415. var GUI;
  6416. (function (GUI) {
  6417. /**
  6418. * Class used to manage 3D user interface
  6419. * @see http://doc.babylonjs.com/how_to/gui3d
  6420. */
  6421. var GUI3DManager = /** @class */ (function () {
  6422. /**
  6423. * Creates a new GUI3DManager
  6424. * @param scene
  6425. */
  6426. function GUI3DManager(scene) {
  6427. var _this = this;
  6428. /** @hidden */
  6429. this._lastControlOver = {};
  6430. /** @hidden */
  6431. this._lastControlDown = {};
  6432. /**
  6433. * Observable raised when the point picked by the pointer events changed
  6434. */
  6435. this.onPickedPointChangedObservable = new BABYLON.Observable();
  6436. // Shared resources
  6437. /** @hidden */
  6438. this._sharedMaterials = {};
  6439. this._scene = scene || BABYLON.Engine.LastCreatedScene;
  6440. this._sceneDisposeObserver = this._scene.onDisposeObservable.add(function () {
  6441. _this._sceneDisposeObserver = null;
  6442. _this._utilityLayer = null;
  6443. _this.dispose();
  6444. });
  6445. this._utilityLayer = new BABYLON.UtilityLayerRenderer(this._scene);
  6446. // Root
  6447. this._rootContainer = new GUI.Container3D("RootContainer");
  6448. this._rootContainer._host = this;
  6449. // Events
  6450. this._pointerObserver = this._scene.onPrePointerObservable.add(function (pi, state) {
  6451. var pointerEvent = (pi.event);
  6452. if (_this._scene.isPointerCaptured(pointerEvent.pointerId)) {
  6453. return;
  6454. }
  6455. if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
  6456. && pi.type !== BABYLON.PointerEventTypes.POINTERUP
  6457. && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
  6458. return;
  6459. }
  6460. var camera = _this._scene.cameraToUseForPointers || _this._scene.activeCamera;
  6461. if (!camera) {
  6462. return;
  6463. }
  6464. pi.skipOnPointerObservable = _this._doPicking(pi.type, pointerEvent, pi.ray);
  6465. });
  6466. // Scene
  6467. this._utilityLayer.utilityLayerScene.autoClear = false;
  6468. this._utilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
  6469. new BABYLON.HemisphericLight("hemi", BABYLON.Vector3.Up(), this._utilityLayer.utilityLayerScene);
  6470. }
  6471. Object.defineProperty(GUI3DManager.prototype, "scene", {
  6472. /** Gets the hosting scene */
  6473. get: function () {
  6474. return this._scene;
  6475. },
  6476. enumerable: true,
  6477. configurable: true
  6478. });
  6479. Object.defineProperty(GUI3DManager.prototype, "utilityLayer", {
  6480. /** Gets associated utility layer */
  6481. get: function () {
  6482. return this._utilityLayer;
  6483. },
  6484. enumerable: true,
  6485. configurable: true
  6486. });
  6487. GUI3DManager.prototype._doPicking = function (type, pointerEvent, ray) {
  6488. if (!this._utilityLayer || !this._utilityLayer.utilityLayerScene.activeCamera) {
  6489. return false;
  6490. }
  6491. var pointerId = pointerEvent.pointerId || 0;
  6492. var buttonIndex = pointerEvent.button;
  6493. var utilityScene = this._utilityLayer.utilityLayerScene;
  6494. var pickingInfo = ray ? utilityScene.pickWithRay(ray) : utilityScene.pick(this._scene.pointerX, this._scene.pointerY);
  6495. if (!pickingInfo || !pickingInfo.hit) {
  6496. var previousControlOver = this._lastControlOver[pointerId];
  6497. if (previousControlOver) {
  6498. previousControlOver._onPointerOut(previousControlOver);
  6499. delete this._lastControlOver[pointerId];
  6500. }
  6501. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  6502. if (this._lastControlDown[pointerEvent.pointerId]) {
  6503. this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  6504. delete this._lastControlDown[pointerEvent.pointerId];
  6505. }
  6506. }
  6507. this.onPickedPointChangedObservable.notifyObservers(null);
  6508. return false;
  6509. }
  6510. var control = (pickingInfo.pickedMesh.metadata);
  6511. if (pickingInfo.pickedPoint) {
  6512. this.onPickedPointChangedObservable.notifyObservers(pickingInfo.pickedPoint);
  6513. }
  6514. if (!control._processObservables(type, pickingInfo.pickedPoint, pointerId, buttonIndex)) {
  6515. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  6516. if (this._lastControlOver[pointerId]) {
  6517. this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId]);
  6518. }
  6519. delete this._lastControlOver[pointerId];
  6520. }
  6521. }
  6522. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  6523. if (this._lastControlDown[pointerEvent.pointerId]) {
  6524. this._lastControlDown[pointerEvent.pointerId].forcePointerUp();
  6525. delete this._lastControlDown[pointerEvent.pointerId];
  6526. }
  6527. }
  6528. return true;
  6529. };
  6530. Object.defineProperty(GUI3DManager.prototype, "rootContainer", {
  6531. /**
  6532. * Gets the root container
  6533. */
  6534. get: function () {
  6535. return this._rootContainer;
  6536. },
  6537. enumerable: true,
  6538. configurable: true
  6539. });
  6540. /**
  6541. * Gets a boolean indicating if the given control is in the root child list
  6542. * @param control defines the control to check
  6543. * @returns true if the control is in the root child list
  6544. */
  6545. GUI3DManager.prototype.containsControl = function (control) {
  6546. return this._rootContainer.containsControl(control);
  6547. };
  6548. /**
  6549. * Adds a control to the root child list
  6550. * @param control defines the control to add
  6551. * @returns the current manager
  6552. */
  6553. GUI3DManager.prototype.addControl = function (control) {
  6554. this._rootContainer.addControl(control);
  6555. return this;
  6556. };
  6557. /**
  6558. * Removes a control from the root child list
  6559. * @param control defines the control to remove
  6560. * @returns the current container
  6561. */
  6562. GUI3DManager.prototype.removeControl = function (control) {
  6563. this._rootContainer.removeControl(control);
  6564. return this;
  6565. };
  6566. /**
  6567. * Releases all associated resources
  6568. */
  6569. GUI3DManager.prototype.dispose = function () {
  6570. this._rootContainer.dispose();
  6571. for (var materialName in this._sharedMaterials) {
  6572. if (!this._sharedMaterials.hasOwnProperty(materialName)) {
  6573. continue;
  6574. }
  6575. this._sharedMaterials[materialName].dispose();
  6576. }
  6577. this._sharedMaterials = {};
  6578. this.onPickedPointChangedObservable.clear();
  6579. if (this._scene) {
  6580. if (this._pointerObserver) {
  6581. this._scene.onPrePointerObservable.remove(this._pointerObserver);
  6582. this._pointerObserver = null;
  6583. }
  6584. if (this._sceneDisposeObserver) {
  6585. this._scene.onDisposeObservable.remove(this._sceneDisposeObserver);
  6586. this._sceneDisposeObserver = null;
  6587. }
  6588. }
  6589. if (this._utilityLayer) {
  6590. this._utilityLayer.dispose();
  6591. }
  6592. };
  6593. return GUI3DManager;
  6594. }());
  6595. GUI.GUI3DManager = GUI3DManager;
  6596. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6597. })(BABYLON || (BABYLON = {}));
  6598. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  6599. var BABYLON;
  6600. (function (BABYLON) {
  6601. var GUI;
  6602. (function (GUI) {
  6603. /** @hidden */
  6604. var FluentMaterialDefines = /** @class */ (function (_super) {
  6605. __extends(FluentMaterialDefines, _super);
  6606. function FluentMaterialDefines() {
  6607. var _this = _super.call(this) || this;
  6608. _this.INNERGLOW = false;
  6609. _this.BORDER = false;
  6610. _this.HOVERLIGHT = false;
  6611. _this.rebuild();
  6612. return _this;
  6613. }
  6614. return FluentMaterialDefines;
  6615. }(BABYLON.MaterialDefines));
  6616. GUI.FluentMaterialDefines = FluentMaterialDefines;
  6617. /**
  6618. * Class used to render controls with fluent desgin
  6619. */
  6620. var FluentMaterial = /** @class */ (function (_super) {
  6621. __extends(FluentMaterial, _super);
  6622. /**
  6623. * Creates a new Fluent material
  6624. * @param name defines the name of the material
  6625. * @param scene defines the hosting scene
  6626. */
  6627. function FluentMaterial(name, scene) {
  6628. var _this = _super.call(this, name, scene) || this;
  6629. /**
  6630. * Gets or sets inner glow intensity. A value of 0 means no glow (default is 0.5)
  6631. */
  6632. _this.innerGlowColorIntensity = 0.5;
  6633. /**
  6634. * Gets or sets the inner glow color (white by default)
  6635. */
  6636. _this.innerGlowColor = new BABYLON.Color3(1.0, 1.0, 1.0);
  6637. /**
  6638. * Gets or sets alpha value (default is 1.0)
  6639. */
  6640. _this.alpha = 1.0;
  6641. /**
  6642. * Gets or sets the albedo color (Default is Color3(0.3, 0.35, 0.4))
  6643. */
  6644. _this.albedoColor = new BABYLON.Color3(0.3, 0.35, 0.4);
  6645. /**
  6646. * Gets or sets a boolean indicating if borders must be rendered (default is false)
  6647. */
  6648. _this.renderBorders = false;
  6649. /**
  6650. * Gets or sets border width (default is 0.5)
  6651. */
  6652. _this.borderWidth = 0.5;
  6653. /**
  6654. * Gets or sets a value indicating the smoothing value applied to border edges (0.02 by default)
  6655. */
  6656. _this.edgeSmoothingValue = 0.02;
  6657. /**
  6658. * Gets or sets the minimum value that can be applied to border width (default is 0.1)
  6659. */
  6660. _this.borderMinValue = 0.1;
  6661. /**
  6662. * Gets or sets a boolean indicating if hover light must be rendered (default is false)
  6663. */
  6664. _this.renderHoverLight = false;
  6665. /**
  6666. * Gets or sets the radius used to render the hover light (default is 0.15)
  6667. */
  6668. _this.hoverRadius = 1.0;
  6669. /**
  6670. * Gets or sets the color used to render the hover light (default is Color4(0.3, 0.3, 0.3, 1.0))
  6671. */
  6672. _this.hoverColor = new BABYLON.Color4(0.3, 0.3, 0.3, 1.0);
  6673. /**
  6674. * Gets or sets the hover light position in world space (default is Vector3.Zero())
  6675. */
  6676. _this.hoverPosition = BABYLON.Vector3.Zero();
  6677. return _this;
  6678. }
  6679. FluentMaterial.prototype.needAlphaBlending = function () {
  6680. return this.alpha !== 1.0;
  6681. };
  6682. FluentMaterial.prototype.needAlphaTesting = function () {
  6683. return false;
  6684. };
  6685. FluentMaterial.prototype.getAlphaTestTexture = function () {
  6686. return null;
  6687. };
  6688. FluentMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  6689. if (this.isFrozen) {
  6690. if (this._wasPreviouslyReady && subMesh.effect) {
  6691. return true;
  6692. }
  6693. }
  6694. if (!subMesh._materialDefines) {
  6695. subMesh._materialDefines = new FluentMaterialDefines();
  6696. }
  6697. var scene = this.getScene();
  6698. var defines = subMesh._materialDefines;
  6699. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  6700. if (defines._renderId === scene.getRenderId()) {
  6701. return true;
  6702. }
  6703. }
  6704. if (defines._areTexturesDirty) {
  6705. defines.INNERGLOW = this.innerGlowColorIntensity > 0;
  6706. defines.BORDER = this.renderBorders;
  6707. defines.HOVERLIGHT = this.renderHoverLight;
  6708. }
  6709. var engine = scene.getEngine();
  6710. // Get correct effect
  6711. if (defines.isDirty) {
  6712. defines.markAsProcessed();
  6713. scene.resetCachedMaterial();
  6714. //Attributes
  6715. var attribs = [BABYLON.VertexBuffer.PositionKind];
  6716. attribs.push(BABYLON.VertexBuffer.NormalKind);
  6717. attribs.push(BABYLON.VertexBuffer.UVKind);
  6718. var shaderName = "fluent";
  6719. var uniforms = ["world", "viewProjection", "innerGlowColor", "albedoColor", "borderWidth", "edgeSmoothingValue", "scaleFactor", "borderMinValue",
  6720. "hoverColor", "hoverPosition", "hoverRadius"
  6721. ];
  6722. var samplers = new Array();
  6723. var uniformBuffers = new Array();
  6724. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  6725. uniformsNames: uniforms,
  6726. uniformBuffersNames: uniformBuffers,
  6727. samplers: samplers,
  6728. defines: defines,
  6729. maxSimultaneousLights: 4
  6730. });
  6731. var join = defines.toString();
  6732. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  6733. attributes: attribs,
  6734. uniformsNames: uniforms,
  6735. uniformBuffersNames: uniformBuffers,
  6736. samplers: samplers,
  6737. defines: join,
  6738. fallbacks: null,
  6739. onCompiled: this.onCompiled,
  6740. onError: this.onError,
  6741. indexParameters: { maxSimultaneousLights: 4 }
  6742. }, engine));
  6743. }
  6744. if (!subMesh.effect || !subMesh.effect.isReady()) {
  6745. return false;
  6746. }
  6747. defines._renderId = scene.getRenderId();
  6748. this._wasPreviouslyReady = true;
  6749. return true;
  6750. };
  6751. FluentMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  6752. var scene = this.getScene();
  6753. var defines = subMesh._materialDefines;
  6754. if (!defines) {
  6755. return;
  6756. }
  6757. var effect = subMesh.effect;
  6758. if (!effect) {
  6759. return;
  6760. }
  6761. this._activeEffect = effect;
  6762. // Matrices
  6763. this.bindOnlyWorldMatrix(world);
  6764. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  6765. if (this._mustRebind(scene, effect)) {
  6766. this._activeEffect.setColor4("albedoColor", this.albedoColor, this.alpha);
  6767. if (defines.INNERGLOW) {
  6768. this._activeEffect.setColor4("innerGlowColor", this.innerGlowColor, this.innerGlowColorIntensity);
  6769. }
  6770. if (defines.BORDER) {
  6771. this._activeEffect.setFloat("borderWidth", this.borderWidth);
  6772. this._activeEffect.setFloat("edgeSmoothingValue", this.edgeSmoothingValue);
  6773. this._activeEffect.setFloat("borderMinValue", this.borderMinValue);
  6774. this._activeEffect.setVector3("scaleFactor", mesh.getBoundingInfo().boundingBox.extendSizeWorld);
  6775. }
  6776. if (defines.HOVERLIGHT) {
  6777. this._activeEffect.setDirectColor4("hoverColor", this.hoverColor);
  6778. this._activeEffect.setFloat("hoverRadius", this.hoverRadius);
  6779. this._activeEffect.setVector3("hoverPosition", this.hoverPosition);
  6780. }
  6781. }
  6782. this._afterBind(mesh, this._activeEffect);
  6783. };
  6784. FluentMaterial.prototype.getActiveTextures = function () {
  6785. var activeTextures = _super.prototype.getActiveTextures.call(this);
  6786. return activeTextures;
  6787. };
  6788. FluentMaterial.prototype.hasTexture = function (texture) {
  6789. if (_super.prototype.hasTexture.call(this, texture)) {
  6790. return true;
  6791. }
  6792. return false;
  6793. };
  6794. FluentMaterial.prototype.dispose = function (forceDisposeEffect) {
  6795. _super.prototype.dispose.call(this, forceDisposeEffect);
  6796. };
  6797. FluentMaterial.prototype.clone = function (name) {
  6798. var _this = this;
  6799. return BABYLON.SerializationHelper.Clone(function () { return new FluentMaterial(name, _this.getScene()); }, this);
  6800. };
  6801. FluentMaterial.prototype.serialize = function () {
  6802. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  6803. serializationObject.customType = "BABYLON.GUI.FluentMaterial";
  6804. return serializationObject;
  6805. };
  6806. FluentMaterial.prototype.getClassName = function () {
  6807. return "FluentMaterial";
  6808. };
  6809. // Statics
  6810. FluentMaterial.Parse = function (source, scene, rootUrl) {
  6811. return BABYLON.SerializationHelper.Parse(function () { return new FluentMaterial(source.name, scene); }, source, scene, rootUrl);
  6812. };
  6813. __decorate([
  6814. BABYLON.serialize(),
  6815. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6816. ], FluentMaterial.prototype, "innerGlowColorIntensity", void 0);
  6817. __decorate([
  6818. BABYLON.serializeAsColor3()
  6819. ], FluentMaterial.prototype, "innerGlowColor", void 0);
  6820. __decorate([
  6821. BABYLON.serialize()
  6822. ], FluentMaterial.prototype, "alpha", void 0);
  6823. __decorate([
  6824. BABYLON.serializeAsColor3()
  6825. ], FluentMaterial.prototype, "albedoColor", void 0);
  6826. __decorate([
  6827. BABYLON.serialize(),
  6828. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6829. ], FluentMaterial.prototype, "renderBorders", void 0);
  6830. __decorate([
  6831. BABYLON.serialize()
  6832. ], FluentMaterial.prototype, "borderWidth", void 0);
  6833. __decorate([
  6834. BABYLON.serialize()
  6835. ], FluentMaterial.prototype, "edgeSmoothingValue", void 0);
  6836. __decorate([
  6837. BABYLON.serialize()
  6838. ], FluentMaterial.prototype, "borderMinValue", void 0);
  6839. __decorate([
  6840. BABYLON.serialize(),
  6841. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6842. ], FluentMaterial.prototype, "renderHoverLight", void 0);
  6843. __decorate([
  6844. BABYLON.serialize()
  6845. ], FluentMaterial.prototype, "hoverRadius", void 0);
  6846. __decorate([
  6847. BABYLON.serializeAsColor4()
  6848. ], FluentMaterial.prototype, "hoverColor", void 0);
  6849. __decorate([
  6850. BABYLON.serializeAsVector3()
  6851. ], FluentMaterial.prototype, "hoverPosition", void 0);
  6852. return FluentMaterial;
  6853. }(BABYLON.PushMaterial));
  6854. GUI.FluentMaterial = FluentMaterial;
  6855. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6856. })(BABYLON || (BABYLON = {}));
  6857. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  6858. var BABYLON;
  6859. (function (BABYLON) {
  6860. var GUI;
  6861. (function (GUI) {
  6862. /**
  6863. * Class used to transport Vector3 information for pointer events
  6864. */
  6865. var Vector3WithInfo = /** @class */ (function (_super) {
  6866. __extends(Vector3WithInfo, _super);
  6867. /**
  6868. * Creates a new Vector3WithInfo
  6869. * @param source defines the vector3 data to transport
  6870. * @param buttonIndex defines the current mouse button index
  6871. */
  6872. function Vector3WithInfo(source,
  6873. /** defines the current mouse button index */
  6874. buttonIndex) {
  6875. if (buttonIndex === void 0) { buttonIndex = 0; }
  6876. var _this = _super.call(this, source.x, source.y, source.z) || this;
  6877. _this.buttonIndex = buttonIndex;
  6878. return _this;
  6879. }
  6880. return Vector3WithInfo;
  6881. }(BABYLON.Vector3));
  6882. GUI.Vector3WithInfo = Vector3WithInfo;
  6883. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  6884. })(BABYLON || (BABYLON = {}));
  6885. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  6886. var BABYLON;
  6887. (function (BABYLON) {
  6888. var GUI;
  6889. (function (GUI) {
  6890. /**
  6891. * Class used as base class for controls
  6892. */
  6893. var Control3D = /** @class */ (function () {
  6894. /**
  6895. * Creates a new control
  6896. * @param name defines the control name
  6897. */
  6898. function Control3D(
  6899. /** Defines the control name */
  6900. name) {
  6901. this.name = name;
  6902. this._downCount = 0;
  6903. this._enterCount = 0;
  6904. this._downPointerIds = {};
  6905. this._isVisible = true;
  6906. /** Gets or sets the control position in world space */
  6907. this.position = new BABYLON.Vector3(0, 0, 0);
  6908. /** Gets or sets the control scaling in world space */
  6909. this.scaling = new BABYLON.Vector3(1, 1, 1);
  6910. /**
  6911. * An event triggered when the pointer move over the control
  6912. */
  6913. this.onPointerMoveObservable = new BABYLON.Observable();
  6914. /**
  6915. * An event triggered when the pointer move out of the control
  6916. */
  6917. this.onPointerOutObservable = new BABYLON.Observable();
  6918. /**
  6919. * An event triggered when the pointer taps the control
  6920. */
  6921. this.onPointerDownObservable = new BABYLON.Observable();
  6922. /**
  6923. * An event triggered when pointer is up
  6924. */
  6925. this.onPointerUpObservable = new BABYLON.Observable();
  6926. /**
  6927. * An event triggered when a control is clicked on (with a mouse)
  6928. */
  6929. this.onPointerClickObservable = new BABYLON.Observable();
  6930. /**
  6931. * An event triggered when pointer enters the control
  6932. */
  6933. this.onPointerEnterObservable = new BABYLON.Observable();
  6934. // Behaviors
  6935. this._behaviors = new Array();
  6936. }
  6937. Object.defineProperty(Control3D.prototype, "behaviors", {
  6938. /**
  6939. * Gets the list of attached behaviors
  6940. * @see http://doc.babylonjs.com/features/behaviour
  6941. */
  6942. get: function () {
  6943. return this._behaviors;
  6944. },
  6945. enumerable: true,
  6946. configurable: true
  6947. });
  6948. /**
  6949. * Attach a behavior to the control
  6950. * @see http://doc.babylonjs.com/features/behaviour
  6951. * @param behavior defines the behavior to attach
  6952. * @returns the current control
  6953. */
  6954. Control3D.prototype.addBehavior = function (behavior) {
  6955. var _this = this;
  6956. var index = this._behaviors.indexOf(behavior);
  6957. if (index !== -1) {
  6958. return this;
  6959. }
  6960. behavior.init();
  6961. var scene = this._host.scene;
  6962. if (scene.isLoading) {
  6963. // We defer the attach when the scene will be loaded
  6964. scene.onDataLoadedObservable.addOnce(function () {
  6965. behavior.attach(_this);
  6966. });
  6967. }
  6968. else {
  6969. behavior.attach(this);
  6970. }
  6971. this._behaviors.push(behavior);
  6972. return this;
  6973. };
  6974. /**
  6975. * Remove an attached behavior
  6976. * @see http://doc.babylonjs.com/features/behaviour
  6977. * @param behavior defines the behavior to attach
  6978. * @returns the current control
  6979. */
  6980. Control3D.prototype.removeBehavior = function (behavior) {
  6981. var index = this._behaviors.indexOf(behavior);
  6982. if (index === -1) {
  6983. return this;
  6984. }
  6985. this._behaviors[index].detach();
  6986. this._behaviors.splice(index, 1);
  6987. return this;
  6988. };
  6989. /**
  6990. * Gets an attached behavior by name
  6991. * @param name defines the name of the behavior to look for
  6992. * @see http://doc.babylonjs.com/features/behaviour
  6993. * @returns null if behavior was not found else the requested behavior
  6994. */
  6995. Control3D.prototype.getBehaviorByName = function (name) {
  6996. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  6997. var behavior = _a[_i];
  6998. if (behavior.name === name) {
  6999. return behavior;
  7000. }
  7001. }
  7002. return null;
  7003. };
  7004. Object.defineProperty(Control3D.prototype, "isVisible", {
  7005. /** Gets or sets a boolean indicating if the control is visible */
  7006. get: function () {
  7007. return this._isVisible;
  7008. },
  7009. set: function (value) {
  7010. if (this._isVisible === value) {
  7011. return;
  7012. }
  7013. this._isVisible = value;
  7014. var mesh = this.mesh;
  7015. if (mesh) {
  7016. mesh.isVisible = value;
  7017. }
  7018. },
  7019. enumerable: true,
  7020. configurable: true
  7021. });
  7022. Object.defineProperty(Control3D.prototype, "typeName", {
  7023. /**
  7024. * Gets a string representing the class name
  7025. */
  7026. get: function () {
  7027. return this._getTypeName();
  7028. },
  7029. enumerable: true,
  7030. configurable: true
  7031. });
  7032. Control3D.prototype._getTypeName = function () {
  7033. return "Control3D";
  7034. };
  7035. Object.defineProperty(Control3D.prototype, "node", {
  7036. /**
  7037. * Gets the transform node used by this control
  7038. */
  7039. get: function () {
  7040. return this._node;
  7041. },
  7042. enumerable: true,
  7043. configurable: true
  7044. });
  7045. Object.defineProperty(Control3D.prototype, "mesh", {
  7046. /**
  7047. * Gets the mesh used to render this control
  7048. */
  7049. get: function () {
  7050. if (this._node instanceof BABYLON.AbstractMesh) {
  7051. return this._node;
  7052. }
  7053. return null;
  7054. },
  7055. enumerable: true,
  7056. configurable: true
  7057. });
  7058. /**
  7059. * Link the control as child of the given node
  7060. * @param node defines the node to link to. Use null to unlink the control
  7061. * @returns the current control
  7062. */
  7063. Control3D.prototype.linkToTransformNode = function (node) {
  7064. if (this._node) {
  7065. this._node.parent = node;
  7066. }
  7067. return this;
  7068. };
  7069. /** @hidden **/
  7070. Control3D.prototype._prepareNode = function (scene) {
  7071. if (!this._node) {
  7072. this._node = this._createNode(scene);
  7073. if (!this.node) {
  7074. return;
  7075. }
  7076. this._node.metadata = this; // Store the control on the metadata field in order to get it when picking
  7077. this._node.position = this.position;
  7078. this._node.scaling = this.scaling;
  7079. var mesh = this.mesh;
  7080. if (mesh) {
  7081. mesh.isPickable = true;
  7082. this._affectMaterial(mesh);
  7083. }
  7084. }
  7085. };
  7086. /**
  7087. * Node creation.
  7088. * Can be overriden by children
  7089. * @param scene defines the scene where the node must be attached
  7090. * @returns the attached node or null if none. Must return a Mesh or AbstractMesh if there is an atttached visible object
  7091. */
  7092. Control3D.prototype._createNode = function (scene) {
  7093. // Do nothing by default
  7094. return null;
  7095. };
  7096. /**
  7097. * Affect a material to the given mesh
  7098. * @param mesh defines the mesh which will represent the control
  7099. */
  7100. Control3D.prototype._affectMaterial = function (mesh) {
  7101. mesh.material = null;
  7102. };
  7103. // Pointers
  7104. /** @hidden */
  7105. Control3D.prototype._onPointerMove = function (target, coordinates) {
  7106. this.onPointerMoveObservable.notifyObservers(coordinates, -1, target, this);
  7107. };
  7108. /** @hidden */
  7109. Control3D.prototype._onPointerEnter = function (target) {
  7110. if (this._enterCount !== 0) {
  7111. return false;
  7112. }
  7113. this._enterCount++;
  7114. this.onPointerEnterObservable.notifyObservers(this, -1, target, this);
  7115. if (this.pointerEnterAnimation) {
  7116. this.pointerEnterAnimation();
  7117. }
  7118. return true;
  7119. };
  7120. /** @hidden */
  7121. Control3D.prototype._onPointerOut = function (target) {
  7122. this._enterCount = 0;
  7123. this.onPointerOutObservable.notifyObservers(this, -1, target, this);
  7124. if (this.pointerOutAnimation) {
  7125. this.pointerOutAnimation();
  7126. }
  7127. };
  7128. /** @hidden */
  7129. Control3D.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
  7130. if (this._downCount !== 0) {
  7131. return false;
  7132. }
  7133. this._downCount++;
  7134. this._downPointerIds[pointerId] = true;
  7135. this.onPointerDownObservable.notifyObservers(new GUI.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  7136. if (this.pointerDownAnimation) {
  7137. this.pointerDownAnimation();
  7138. }
  7139. return true;
  7140. };
  7141. /** @hidden */
  7142. Control3D.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
  7143. this._downCount = 0;
  7144. delete this._downPointerIds[pointerId];
  7145. if (notifyClick && this._enterCount > 0) {
  7146. this.onPointerClickObservable.notifyObservers(new GUI.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  7147. }
  7148. this.onPointerUpObservable.notifyObservers(new GUI.Vector3WithInfo(coordinates, buttonIndex), -1, target, this);
  7149. if (this.pointerUpAnimation) {
  7150. this.pointerUpAnimation();
  7151. }
  7152. };
  7153. /** @hidden */
  7154. Control3D.prototype.forcePointerUp = function (pointerId) {
  7155. if (pointerId === void 0) { pointerId = null; }
  7156. if (pointerId !== null) {
  7157. this._onPointerUp(this, BABYLON.Vector3.Zero(), pointerId, 0, true);
  7158. }
  7159. else {
  7160. for (var key in this._downPointerIds) {
  7161. this._onPointerUp(this, BABYLON.Vector3.Zero(), +key, 0, true);
  7162. }
  7163. }
  7164. };
  7165. /** @hidden */
  7166. Control3D.prototype._processObservables = function (type, pickedPoint, pointerId, buttonIndex) {
  7167. if (type === BABYLON.PointerEventTypes.POINTERMOVE) {
  7168. this._onPointerMove(this, pickedPoint);
  7169. var previousControlOver = this._host._lastControlOver[pointerId];
  7170. if (previousControlOver && previousControlOver !== this) {
  7171. previousControlOver._onPointerOut(this);
  7172. }
  7173. if (previousControlOver !== this) {
  7174. this._onPointerEnter(this);
  7175. }
  7176. this._host._lastControlOver[pointerId] = this;
  7177. return true;
  7178. }
  7179. if (type === BABYLON.PointerEventTypes.POINTERDOWN) {
  7180. this._onPointerDown(this, pickedPoint, pointerId, buttonIndex);
  7181. this._host._lastControlDown[pointerId] = this;
  7182. this._host._lastPickedControl = this;
  7183. return true;
  7184. }
  7185. if (type === BABYLON.PointerEventTypes.POINTERUP) {
  7186. if (this._host._lastControlDown[pointerId]) {
  7187. this._host._lastControlDown[pointerId]._onPointerUp(this, pickedPoint, pointerId, buttonIndex, true);
  7188. }
  7189. delete this._host._lastControlDown[pointerId];
  7190. return true;
  7191. }
  7192. return false;
  7193. };
  7194. /**
  7195. * Releases all associated resources
  7196. */
  7197. Control3D.prototype.dispose = function () {
  7198. this.onPointerDownObservable.clear();
  7199. this.onPointerEnterObservable.clear();
  7200. this.onPointerMoveObservable.clear();
  7201. this.onPointerOutObservable.clear();
  7202. this.onPointerUpObservable.clear();
  7203. this.onPointerClickObservable.clear();
  7204. if (this._node) {
  7205. this._node.dispose();
  7206. this._node = null;
  7207. }
  7208. // Behaviors
  7209. for (var _i = 0, _a = this._behaviors; _i < _a.length; _i++) {
  7210. var behavior = _a[_i];
  7211. behavior.detach();
  7212. }
  7213. };
  7214. return Control3D;
  7215. }());
  7216. GUI.Control3D = Control3D;
  7217. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7218. })(BABYLON || (BABYLON = {}));
  7219. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  7220. var BABYLON;
  7221. (function (BABYLON) {
  7222. var GUI;
  7223. (function (GUI) {
  7224. /**
  7225. * Class used to create containers for controls
  7226. */
  7227. var Container3D = /** @class */ (function (_super) {
  7228. __extends(Container3D, _super);
  7229. /**
  7230. * Creates a new container
  7231. * @param name defines the container name
  7232. */
  7233. function Container3D(name) {
  7234. var _this = _super.call(this, name) || this;
  7235. /**
  7236. * Gets the list of child controls
  7237. */
  7238. _this._children = new Array();
  7239. return _this;
  7240. }
  7241. /**
  7242. * Gets a boolean indicating if the given control is in the children of this control
  7243. * @param control defines the control to check
  7244. * @returns true if the control is in the child list
  7245. */
  7246. Container3D.prototype.containsControl = function (control) {
  7247. return this._children.indexOf(control) !== -1;
  7248. };
  7249. /**
  7250. * Adds a control to the children of this control
  7251. * @param control defines the control to add
  7252. * @returns the current container
  7253. */
  7254. Container3D.prototype.addControl = function (control) {
  7255. var index = this._children.indexOf(control);
  7256. if (index !== -1) {
  7257. return this;
  7258. }
  7259. control.parent = this;
  7260. control._host = this._host;
  7261. this._children.push(control);
  7262. if (this._host.utilityLayer) {
  7263. control._prepareNode(this._host.utilityLayer.utilityLayerScene);
  7264. if (control.node) {
  7265. control.node.parent = this.node;
  7266. }
  7267. this._arrangeChildren();
  7268. }
  7269. return this;
  7270. };
  7271. /**
  7272. * This function will be called everytime a new control is added
  7273. */
  7274. Container3D.prototype._arrangeChildren = function () {
  7275. };
  7276. Container3D.prototype._createNode = function (scene) {
  7277. return new BABYLON.TransformNode("ContainerNode", scene);
  7278. };
  7279. /**
  7280. * Removes a control from the children of this control
  7281. * @param control defines the control to remove
  7282. * @returns the current container
  7283. */
  7284. Container3D.prototype.removeControl = function (control) {
  7285. var index = this._children.indexOf(control);
  7286. if (index !== -1) {
  7287. this._children.splice(index, 1);
  7288. control.parent = null;
  7289. }
  7290. return this;
  7291. };
  7292. Container3D.prototype._getTypeName = function () {
  7293. return "Container3D";
  7294. };
  7295. /**
  7296. * Releases all associated resources
  7297. */
  7298. Container3D.prototype.dispose = function () {
  7299. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  7300. var control = _a[_i];
  7301. control.dispose();
  7302. }
  7303. this._children = [];
  7304. _super.prototype.dispose.call(this);
  7305. };
  7306. return Container3D;
  7307. }(GUI.Control3D));
  7308. GUI.Container3D = Container3D;
  7309. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7310. })(BABYLON || (BABYLON = {}));
  7311. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  7312. var BABYLON;
  7313. (function (BABYLON) {
  7314. var GUI;
  7315. (function (GUI) {
  7316. /**
  7317. * Class used to create a button in 3D
  7318. */
  7319. var Button3D = /** @class */ (function (_super) {
  7320. __extends(Button3D, _super);
  7321. /**
  7322. * Creates a new button
  7323. * @param name defines the control name
  7324. */
  7325. function Button3D(name) {
  7326. var _this = _super.call(this, name) || this;
  7327. _this._contentResolution = 512;
  7328. _this._contentScaleRatio = 2;
  7329. // Default animations
  7330. _this.pointerEnterAnimation = function () {
  7331. if (!_this.mesh) {
  7332. return;
  7333. }
  7334. _this._currentMaterial.emissiveColor = BABYLON.Color3.Red();
  7335. };
  7336. _this.pointerOutAnimation = function () {
  7337. _this._currentMaterial.emissiveColor = BABYLON.Color3.Black();
  7338. };
  7339. _this.pointerDownAnimation = function () {
  7340. if (!_this.mesh) {
  7341. return;
  7342. }
  7343. _this.mesh.scaling.scaleInPlace(0.95);
  7344. };
  7345. _this.pointerUpAnimation = function () {
  7346. if (!_this.mesh) {
  7347. return;
  7348. }
  7349. _this.mesh.scaling.scaleInPlace(1.0 / 0.95);
  7350. };
  7351. return _this;
  7352. }
  7353. Object.defineProperty(Button3D.prototype, "contentResolution", {
  7354. /**
  7355. * Gets or sets the texture resolution used to render content (512 by default)
  7356. */
  7357. get: function () {
  7358. return this._contentResolution;
  7359. },
  7360. set: function (value) {
  7361. if (this._contentResolution === value) {
  7362. return;
  7363. }
  7364. this._contentResolution = value;
  7365. this._resetContent();
  7366. },
  7367. enumerable: true,
  7368. configurable: true
  7369. });
  7370. Object.defineProperty(Button3D.prototype, "contentScaleRatio", {
  7371. /**
  7372. * Gets or sets the texture scale ratio used to render content (2 by default)
  7373. */
  7374. get: function () {
  7375. return this._contentScaleRatio;
  7376. },
  7377. set: function (value) {
  7378. if (this._contentScaleRatio === value) {
  7379. return;
  7380. }
  7381. this._contentScaleRatio = value;
  7382. this._resetContent();
  7383. },
  7384. enumerable: true,
  7385. configurable: true
  7386. });
  7387. Button3D.prototype._resetContent = function () {
  7388. if (this._facadeTexture) {
  7389. this._facadeTexture.dispose();
  7390. this._facadeTexture = null;
  7391. }
  7392. this.content = this._content;
  7393. };
  7394. Object.defineProperty(Button3D.prototype, "content", {
  7395. /**
  7396. * Gets or sets the GUI 2D content used to display the button's facade
  7397. */
  7398. get: function () {
  7399. return this._content;
  7400. },
  7401. set: function (value) {
  7402. if (!this._host || !this._host.utilityLayer) {
  7403. return;
  7404. }
  7405. this._content = value;
  7406. if (!this._facadeTexture) {
  7407. this._facadeTexture = new BABYLON.GUI.AdvancedDynamicTexture("Facade", this._contentResolution, this._contentResolution, this._host.utilityLayer.utilityLayerScene, true, BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  7408. this._facadeTexture.rootContainer.scaleX = this._contentScaleRatio;
  7409. this._facadeTexture.rootContainer.scaleY = this._contentScaleRatio;
  7410. this._facadeTexture.premulAlpha = true;
  7411. }
  7412. this._facadeTexture.addControl(value);
  7413. this._applyFacade(this._facadeTexture);
  7414. },
  7415. enumerable: true,
  7416. configurable: true
  7417. });
  7418. /**
  7419. * Apply the facade texture (created from the content property).
  7420. * This function can be overloaded by child classes
  7421. * @param facadeTexture defines the AdvancedDynamicTexture to use
  7422. */
  7423. Button3D.prototype._applyFacade = function (facadeTexture) {
  7424. this._currentMaterial.emissiveTexture = facadeTexture;
  7425. };
  7426. Button3D.prototype._getTypeName = function () {
  7427. return "Button3D";
  7428. };
  7429. // Mesh association
  7430. Button3D.prototype._createNode = function (scene) {
  7431. var faceUV = new Array(6);
  7432. for (var i = 0; i < 6; i++) {
  7433. faceUV[i] = new BABYLON.Vector4(0, 0, 0, 0);
  7434. }
  7435. faceUV[1] = new BABYLON.Vector4(0, 0, 1, 1);
  7436. var mesh = BABYLON.MeshBuilder.CreateBox(this.name + "_rootMesh", {
  7437. width: 1.0,
  7438. height: 1.0,
  7439. depth: 0.08,
  7440. faceUV: faceUV
  7441. }, scene);
  7442. return mesh;
  7443. };
  7444. Button3D.prototype._affectMaterial = function (mesh) {
  7445. var material = new BABYLON.StandardMaterial(this.name + "Material", mesh.getScene());
  7446. material.specularColor = BABYLON.Color3.Black();
  7447. mesh.material = material;
  7448. this._currentMaterial = material;
  7449. };
  7450. /**
  7451. * Releases all associated resources
  7452. */
  7453. Button3D.prototype.dispose = function () {
  7454. _super.prototype.dispose.call(this);
  7455. if (this._currentMaterial) {
  7456. this._currentMaterial.dispose();
  7457. }
  7458. };
  7459. return Button3D;
  7460. }(GUI.Control3D));
  7461. GUI.Button3D = Button3D;
  7462. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7463. })(BABYLON || (BABYLON = {}));
  7464. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  7465. var BABYLON;
  7466. (function (BABYLON) {
  7467. var GUI;
  7468. (function (GUI) {
  7469. /**
  7470. * Class used to create a holographic button in 3D
  7471. */
  7472. var HolographicButton = /** @class */ (function (_super) {
  7473. __extends(HolographicButton, _super);
  7474. /**
  7475. * Creates a new button
  7476. * @param name defines the control name
  7477. */
  7478. function HolographicButton(name, shareMaterials) {
  7479. if (shareMaterials === void 0) { shareMaterials = true; }
  7480. var _this = _super.call(this, name) || this;
  7481. _this._shareMaterials = true;
  7482. _this._shareMaterials = shareMaterials;
  7483. // Default animations
  7484. _this.pointerEnterAnimation = function () {
  7485. if (!_this.mesh) {
  7486. return;
  7487. }
  7488. _this._frontPlate.setEnabled(true);
  7489. };
  7490. _this.pointerOutAnimation = function () {
  7491. if (!_this.mesh) {
  7492. return;
  7493. }
  7494. _this._frontPlate.setEnabled(false);
  7495. };
  7496. return _this;
  7497. }
  7498. Object.defineProperty(HolographicButton.prototype, "text", {
  7499. // private _imageUrl: string;
  7500. /**
  7501. * Gets or sets text for the button
  7502. */
  7503. get: function () {
  7504. return this._text;
  7505. },
  7506. set: function (value) {
  7507. if (this._text === value) {
  7508. return;
  7509. }
  7510. this._text = value;
  7511. this._rebuildContent();
  7512. },
  7513. enumerable: true,
  7514. configurable: true
  7515. });
  7516. Object.defineProperty(HolographicButton.prototype, "imageUrl", {
  7517. /**
  7518. * Gets or sets the image url for the button
  7519. */
  7520. get: function () {
  7521. return this._imageUrl;
  7522. },
  7523. set: function (value) {
  7524. if (this._imageUrl === value) {
  7525. return;
  7526. }
  7527. this._imageUrl = value;
  7528. this._rebuildContent();
  7529. },
  7530. enumerable: true,
  7531. configurable: true
  7532. });
  7533. Object.defineProperty(HolographicButton.prototype, "backMaterial", {
  7534. /**
  7535. * Gets the back material used by this button
  7536. */
  7537. get: function () {
  7538. return this._backMaterial;
  7539. },
  7540. enumerable: true,
  7541. configurable: true
  7542. });
  7543. Object.defineProperty(HolographicButton.prototype, "frontMaterial", {
  7544. /**
  7545. * Gets the front material used by this button
  7546. */
  7547. get: function () {
  7548. return this._frontMaterial;
  7549. },
  7550. enumerable: true,
  7551. configurable: true
  7552. });
  7553. Object.defineProperty(HolographicButton.prototype, "plateMaterial", {
  7554. /**
  7555. * Gets the plate material used by this button
  7556. */
  7557. get: function () {
  7558. return this._plateMaterial;
  7559. },
  7560. enumerable: true,
  7561. configurable: true
  7562. });
  7563. Object.defineProperty(HolographicButton.prototype, "shareMaterials", {
  7564. /**
  7565. * Gets a boolean indicating if this button shares its material with other HolographicButtons
  7566. */
  7567. get: function () {
  7568. return this._shareMaterials;
  7569. },
  7570. enumerable: true,
  7571. configurable: true
  7572. });
  7573. HolographicButton.prototype._getTypeName = function () {
  7574. return "HolographicButton";
  7575. };
  7576. HolographicButton.prototype._rebuildContent = function () {
  7577. var panel = new GUI.StackPanel();
  7578. panel.isVertical = true;
  7579. if (this._imageUrl) {
  7580. var image = new BABYLON.GUI.Image();
  7581. image.source = this._imageUrl;
  7582. image.paddingTop = "40px";
  7583. image.height = "180px";
  7584. image.width = "100px";
  7585. image.paddingBottom = "40px";
  7586. panel.addControl(image);
  7587. }
  7588. if (this._text) {
  7589. var text = new BABYLON.GUI.TextBlock();
  7590. text.text = this._text;
  7591. text.color = "white";
  7592. text.height = "30px";
  7593. text.fontSize = 24;
  7594. panel.addControl(text);
  7595. }
  7596. if (this._frontPlate) {
  7597. this.content = panel;
  7598. }
  7599. };
  7600. // Mesh association
  7601. HolographicButton.prototype._createNode = function (scene) {
  7602. this._backPlate = BABYLON.MeshBuilder.CreateBox(this.name + "BackMesh", {
  7603. width: 1.0,
  7604. height: 1.0,
  7605. depth: 0.08
  7606. }, scene);
  7607. this._frontPlate = BABYLON.MeshBuilder.CreateBox(this.name + "FrontMesh", {
  7608. width: 1.0,
  7609. height: 1.0,
  7610. depth: 0.08
  7611. }, scene);
  7612. this._frontPlate.parent = this._backPlate;
  7613. this._frontPlate.position.z = -0.08;
  7614. this._frontPlate.isPickable = false;
  7615. this._frontPlate.setEnabled(false);
  7616. this._textPlate = _super.prototype._createNode.call(this, scene);
  7617. this._textPlate.parent = this._backPlate;
  7618. this._textPlate.position.z = -0.08;
  7619. this._textPlate.isPickable = false;
  7620. return this._backPlate;
  7621. };
  7622. HolographicButton.prototype._applyFacade = function (facadeTexture) {
  7623. this._plateMaterial.emissiveTexture = facadeTexture;
  7624. this._plateMaterial.opacityTexture = facadeTexture;
  7625. };
  7626. HolographicButton.prototype._createBackMaterial = function (mesh) {
  7627. var _this = this;
  7628. this._backMaterial = new GUI.FluentMaterial(this.name + "Back Material", mesh.getScene());
  7629. this._backMaterial.renderHoverLight = true;
  7630. this._pickedPointObserver = this._host.onPickedPointChangedObservable.add(function (pickedPoint) {
  7631. if (pickedPoint) {
  7632. _this._backMaterial.hoverPosition = pickedPoint;
  7633. _this._backMaterial.hoverColor.a = 1.0;
  7634. }
  7635. else {
  7636. _this._backMaterial.hoverColor.a = 0;
  7637. }
  7638. });
  7639. };
  7640. HolographicButton.prototype._createFrontMaterial = function (mesh) {
  7641. this._frontMaterial = new GUI.FluentMaterial(this.name + "Front Material", mesh.getScene());
  7642. this._frontMaterial.innerGlowColorIntensity = 0; // No inner glow
  7643. this._frontMaterial.alpha = 0.5; // Additive
  7644. this._frontMaterial.renderBorders = true;
  7645. };
  7646. HolographicButton.prototype._createPlateMaterial = function (mesh) {
  7647. this._plateMaterial = new BABYLON.StandardMaterial(this.name + "Plate Material", mesh.getScene());
  7648. this._plateMaterial.specularColor = BABYLON.Color3.Black();
  7649. };
  7650. HolographicButton.prototype._affectMaterial = function (mesh) {
  7651. // Back
  7652. if (this._shareMaterials) {
  7653. if (!this._host._sharedMaterials["backFluentMaterial"]) {
  7654. this._createBackMaterial(mesh);
  7655. this._host._sharedMaterials["backFluentMaterial"] = this._backMaterial;
  7656. }
  7657. else {
  7658. this._backMaterial = this._host._sharedMaterials["backFluentMaterial"];
  7659. }
  7660. // Front
  7661. if (!this._host._sharedMaterials["frontFluentMaterial"]) {
  7662. this._createFrontMaterial(mesh);
  7663. this._host._sharedMaterials["frontFluentMaterial"] = this._frontMaterial;
  7664. }
  7665. else {
  7666. this._frontMaterial = this._host._sharedMaterials["frontFluentMaterial"];
  7667. }
  7668. }
  7669. else {
  7670. this._createBackMaterial(mesh);
  7671. this._createFrontMaterial(mesh);
  7672. }
  7673. this._createPlateMaterial(mesh);
  7674. this._backPlate.material = this._backMaterial;
  7675. this._frontPlate.material = this._frontMaterial;
  7676. this._textPlate.material = this._plateMaterial;
  7677. this._rebuildContent();
  7678. };
  7679. /**
  7680. * Releases all associated resources
  7681. */
  7682. HolographicButton.prototype.dispose = function () {
  7683. _super.prototype.dispose.call(this); // will dispose main mesh ie. back plate
  7684. if (!this.shareMaterials) {
  7685. this._backMaterial.dispose();
  7686. this._frontMaterial.dispose();
  7687. this._plateMaterial.dispose();
  7688. if (this._pickedPointObserver) {
  7689. this._host.onPickedPointChangedObservable.remove(this._pickedPointObserver);
  7690. this._pickedPointObserver = null;
  7691. }
  7692. }
  7693. };
  7694. return HolographicButton;
  7695. }(GUI.Button3D));
  7696. GUI.HolographicButton = HolographicButton;
  7697. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7698. })(BABYLON || (BABYLON = {}));
  7699. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  7700. var BABYLON;
  7701. (function (BABYLON) {
  7702. var GUI;
  7703. (function (GUI) {
  7704. /**
  7705. * Class used to create a stack panel in 3D on XY plane
  7706. */
  7707. var StackPanel3D = /** @class */ (function (_super) {
  7708. __extends(StackPanel3D, _super);
  7709. /**
  7710. * Creates new StackPanel
  7711. * @param isVertical
  7712. */
  7713. function StackPanel3D() {
  7714. var _this = _super.call(this) || this;
  7715. _this._isVertical = false;
  7716. /**
  7717. * Gets or sets the distance between elements
  7718. */
  7719. _this.margin = 0.1;
  7720. return _this;
  7721. }
  7722. Object.defineProperty(StackPanel3D.prototype, "isVertical", {
  7723. /**
  7724. * Gets or sets a boolean indicating if the stack panel is vertical or horizontal (horizontal by default)
  7725. */
  7726. get: function () {
  7727. return this._isVertical;
  7728. },
  7729. set: function (value) {
  7730. var _this = this;
  7731. if (this._isVertical === value) {
  7732. return;
  7733. }
  7734. this._isVertical = value;
  7735. BABYLON.Tools.SetImmediate(function () {
  7736. _this._arrangeChildren();
  7737. });
  7738. },
  7739. enumerable: true,
  7740. configurable: true
  7741. });
  7742. StackPanel3D.prototype._arrangeChildren = function () {
  7743. var width = 0;
  7744. var height = 0;
  7745. var controlCount = 0;
  7746. var extendSizes = [];
  7747. var currentInverseWorld = BABYLON.Matrix.Invert(this.node.computeWorldMatrix(true));
  7748. // Measure
  7749. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  7750. var child = _a[_i];
  7751. if (!child.mesh) {
  7752. continue;
  7753. }
  7754. controlCount++;
  7755. child.mesh.computeWorldMatrix(true);
  7756. var boundingBox = child.mesh.getBoundingInfo().boundingBox;
  7757. var extendSize = BABYLON.Vector3.TransformNormal(boundingBox.extendSizeWorld, currentInverseWorld);
  7758. extendSizes.push(extendSize);
  7759. if (this._isVertical) {
  7760. height += extendSize.y;
  7761. }
  7762. else {
  7763. width += extendSize.x;
  7764. }
  7765. }
  7766. if (this._isVertical) {
  7767. height += (controlCount - 1) * this.margin / 2;
  7768. }
  7769. else {
  7770. width += (controlCount - 1) * this.margin / 2;
  7771. }
  7772. // Arrange
  7773. var offset;
  7774. if (this._isVertical) {
  7775. offset = -height;
  7776. }
  7777. else {
  7778. offset = -width;
  7779. }
  7780. var index = 0;
  7781. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  7782. var child = _c[_b];
  7783. if (!child.mesh) {
  7784. continue;
  7785. }
  7786. controlCount--;
  7787. var extendSize = extendSizes[index++];
  7788. if (this._isVertical) {
  7789. child.position.y = offset + extendSize.y;
  7790. child.position.x = 0;
  7791. offset += extendSize.y * 2;
  7792. }
  7793. else {
  7794. child.position.x = offset + extendSize.x;
  7795. child.position.y = 0;
  7796. offset += extendSize.x * 2;
  7797. }
  7798. offset += (controlCount > 0 ? this.margin : 0);
  7799. }
  7800. };
  7801. return StackPanel3D;
  7802. }(GUI.Container3D));
  7803. GUI.StackPanel3D = StackPanel3D;
  7804. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  7805. })(BABYLON || (BABYLON = {}));
  7806. return BABYLON.GUI;
  7807. });