babylon.gui.js 274 KB

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