egret.web.js 371 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328
  1. var __reflect = (this && this.__reflect) || function (p, c, t) {
  2. p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
  3. };
  4. var __extends = this && this.__extends || function __extends(t, e) {
  5. function r() {
  6. this.constructor = t;
  7. }
  8. for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
  9. r.prototype = e.prototype, t.prototype = new r();
  10. };
  11. //////////////////////////////////////////////////////////////////////////////////////
  12. //
  13. // Copyright (c) 2014-present, Egret Technology.
  14. // All rights reserved.
  15. // Redistribution and use in source and binary forms, with or without
  16. // modification, are permitted provided that the following conditions are met:
  17. //
  18. // * Redistributions of source code must retain the above copyright
  19. // notice, this list of conditions and the following disclaimer.
  20. // * Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the distribution.
  23. // * Neither the name of the Egret nor the
  24. // names of its contributors may be used to endorse or promote products
  25. // derived from this software without specific prior written permission.
  26. //
  27. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  28. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  30. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  33. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  36. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. //
  38. //////////////////////////////////////////////////////////////////////////////////////
  39. var egret;
  40. (function (egret) {
  41. var web;
  42. (function (web) {
  43. /**
  44. * @private
  45. */
  46. function getOption(key) {
  47. if (window.location) {
  48. var search = location.search;
  49. if (search == "") {
  50. return "";
  51. }
  52. search = search.slice(1);
  53. var searchArr = search.split("&");
  54. var length_1 = searchArr.length;
  55. for (var i = 0; i < length_1; i++) {
  56. var str = searchArr[i];
  57. var arr = str.split("=");
  58. if (arr[0] == key) {
  59. return arr[1];
  60. }
  61. }
  62. }
  63. return "";
  64. }
  65. web.getOption = getOption;
  66. egret.getOption = getOption;
  67. })(web = egret.web || (egret.web = {}));
  68. })(egret || (egret = {}));
  69. //////////////////////////////////////////////////////////////////////////////////////
  70. //
  71. // Copyright (c) 2014-present, Egret Technology.
  72. // All rights reserved.
  73. // Redistribution and use in source and binary forms, with or without
  74. // modification, are permitted provided that the following conditions are met:
  75. //
  76. // * Redistributions of source code must retain the above copyright
  77. // notice, this list of conditions and the following disclaimer.
  78. // * Redistributions in binary form must reproduce the above copyright
  79. // notice, this list of conditions and the following disclaimer in the
  80. // documentation and/or other materials provided with the distribution.
  81. // * Neither the name of the Egret nor the
  82. // names of its contributors may be used to endorse or promote products
  83. // derived from this software without specific prior written permission.
  84. //
  85. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  86. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  87. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  88. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  89. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  90. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  91. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  92. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  93. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  94. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  95. //
  96. //////////////////////////////////////////////////////////////////////////////////////
  97. var egret;
  98. (function (egret) {
  99. var web;
  100. (function (web) {
  101. /**
  102. * @private
  103. */
  104. var WebExternalInterface = (function () {
  105. function WebExternalInterface() {
  106. }
  107. /**
  108. * @private
  109. * @param functionName
  110. * @param value
  111. */
  112. WebExternalInterface.call = function (functionName, value) {
  113. };
  114. /**
  115. * @private
  116. * @param functionName
  117. * @param listener
  118. */
  119. WebExternalInterface.addCallback = function (functionName, listener) {
  120. };
  121. return WebExternalInterface;
  122. }());
  123. web.WebExternalInterface = WebExternalInterface;
  124. __reflect(WebExternalInterface.prototype, "egret.web.WebExternalInterface", ["egret.ExternalInterface"]);
  125. var ua = navigator.userAgent.toLowerCase();
  126. if (ua.indexOf("egretnative") < 0) {
  127. egret.ExternalInterface = WebExternalInterface;
  128. }
  129. })(web = egret.web || (egret.web = {}));
  130. })(egret || (egret = {}));
  131. (function (egret) {
  132. var web;
  133. (function (web) {
  134. var callBackDic = {};
  135. /**
  136. * @private
  137. */
  138. var NativeExternalInterface = (function () {
  139. function NativeExternalInterface() {
  140. }
  141. NativeExternalInterface.call = function (functionName, value) {
  142. var data = {};
  143. data.functionName = functionName;
  144. data.value = value;
  145. egret_native.sendInfoToPlugin(JSON.stringify(data));
  146. };
  147. NativeExternalInterface.addCallback = function (functionName, listener) {
  148. callBackDic[functionName] = listener;
  149. };
  150. return NativeExternalInterface;
  151. }());
  152. web.NativeExternalInterface = NativeExternalInterface;
  153. __reflect(NativeExternalInterface.prototype, "egret.web.NativeExternalInterface", ["egret.ExternalInterface"]);
  154. /**
  155. * @private
  156. * @param info
  157. */
  158. function onReceivedPluginInfo(info) {
  159. var data = JSON.parse(info);
  160. var functionName = data.functionName;
  161. var listener = callBackDic[functionName];
  162. if (listener) {
  163. var value = data.value;
  164. listener.call(null, value);
  165. }
  166. else {
  167. egret.$warn(1050, functionName);
  168. }
  169. }
  170. var ua = navigator.userAgent.toLowerCase();
  171. if (ua.indexOf("egretnative") >= 0) {
  172. egret.ExternalInterface = NativeExternalInterface;
  173. egret_native.receivedPluginInfo = onReceivedPluginInfo;
  174. }
  175. })(web = egret.web || (egret.web = {}));
  176. })(egret || (egret = {}));
  177. (function (egret) {
  178. var web;
  179. (function (web) {
  180. var callBackDic = {};
  181. /**
  182. * @private
  183. */
  184. var WebViewExternalInterface = (function () {
  185. function WebViewExternalInterface() {
  186. }
  187. WebViewExternalInterface.call = function (functionName, value) {
  188. __global.ExternalInterface.call(functionName, value);
  189. };
  190. WebViewExternalInterface.addCallback = function (functionName, listener) {
  191. callBackDic[functionName] = listener;
  192. };
  193. WebViewExternalInterface.invokeCallback = function (functionName, value) {
  194. var listener = callBackDic[functionName];
  195. if (listener) {
  196. listener.call(null, value);
  197. }
  198. else {
  199. egret.$warn(1050, functionName);
  200. }
  201. };
  202. return WebViewExternalInterface;
  203. }());
  204. web.WebViewExternalInterface = WebViewExternalInterface;
  205. __reflect(WebViewExternalInterface.prototype, "egret.web.WebViewExternalInterface", ["egret.ExternalInterface"]);
  206. var ua = navigator.userAgent.toLowerCase();
  207. if (ua.indexOf("egretwebview") >= 0) {
  208. egret.ExternalInterface = WebViewExternalInterface;
  209. }
  210. })(web = egret.web || (egret.web = {}));
  211. })(egret || (egret = {}));
  212. //////////////////////////////////////////////////////////////////////////////////////
  213. //
  214. // Copyright (c) 2014-present, Egret Technology.
  215. // All rights reserved.
  216. // Redistribution and use in source and binary forms, with or without
  217. // modification, are permitted provided that the following conditions are met:
  218. //
  219. // * Redistributions of source code must retain the above copyright
  220. // notice, this list of conditions and the following disclaimer.
  221. // * Redistributions in binary form must reproduce the above copyright
  222. // notice, this list of conditions and the following disclaimer in the
  223. // documentation and/or other materials provided with the distribution.
  224. // * Neither the name of the Egret nor the
  225. // names of its contributors may be used to endorse or promote products
  226. // derived from this software without specific prior written permission.
  227. //
  228. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  229. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  230. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  231. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  232. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  233. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  234. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  235. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  236. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  237. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  238. //
  239. //////////////////////////////////////////////////////////////////////////////////////
  240. var egret;
  241. (function (egret) {
  242. var web;
  243. (function (web) {
  244. /**
  245. * @private
  246. * @inheritDoc
  247. */
  248. var HtmlSound = (function (_super) {
  249. __extends(HtmlSound, _super);
  250. /**
  251. * @private
  252. * @inheritDoc
  253. */
  254. function HtmlSound() {
  255. var _this = _super.call(this) || this;
  256. /**
  257. * @private
  258. */
  259. _this.loaded = false;
  260. return _this;
  261. }
  262. Object.defineProperty(HtmlSound.prototype, "length", {
  263. get: function () {
  264. if (this.originAudio) {
  265. return this.originAudio.duration;
  266. }
  267. throw new Error("sound not loaded!");
  268. //return 0;
  269. },
  270. enumerable: true,
  271. configurable: true
  272. });
  273. /**
  274. * @inheritDoc
  275. */
  276. HtmlSound.prototype.load = function (url) {
  277. var self = this;
  278. this.url = url;
  279. if (true && !url) {
  280. egret.$error(3002);
  281. }
  282. var audio = new Audio(url);
  283. audio.addEventListener("canplaythrough", onAudioLoaded);
  284. audio.addEventListener("error", onAudioError);
  285. var ua = navigator.userAgent.toLowerCase();
  286. if (ua.indexOf("firefox") >= 0) {
  287. audio.autoplay = !0;
  288. audio.muted = true;
  289. }
  290. if (ua.indexOf("edge") >= 0) {
  291. document.body.appendChild(audio);
  292. }
  293. audio.load();
  294. this.originAudio = audio;
  295. if (HtmlSound.clearAudios[this.url]) {
  296. delete HtmlSound.clearAudios[this.url];
  297. }
  298. function onAudioLoaded() {
  299. HtmlSound.$recycle(this.url, audio);
  300. removeListeners();
  301. if (ua.indexOf("firefox") >= 0) {
  302. audio.pause();
  303. audio.muted = false;
  304. }
  305. self.loaded = true;
  306. self.dispatchEventWith(egret.Event.COMPLETE);
  307. }
  308. function onAudioError() {
  309. removeListeners();
  310. self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  311. }
  312. function removeListeners() {
  313. audio.removeEventListener("canplaythrough", onAudioLoaded);
  314. audio.removeEventListener("error", onAudioError);
  315. if (ua.indexOf("edge") >= 0) {
  316. document.body.removeChild(audio);
  317. }
  318. }
  319. };
  320. /**
  321. * @inheritDoc
  322. */
  323. HtmlSound.prototype.play = function (startTime, loops) {
  324. startTime = +startTime || 0;
  325. loops = +loops || 0;
  326. if (true && this.loaded == false) {
  327. egret.$error(1049);
  328. }
  329. var audio = HtmlSound.$pop(this.url);
  330. if (audio == null) {
  331. audio = this.originAudio.cloneNode();
  332. }
  333. else {
  334. //audio.load();
  335. }
  336. audio.autoplay = true;
  337. var channel = new web.HtmlSoundChannel(audio);
  338. channel.$url = this.url;
  339. channel.$loops = loops;
  340. channel.$startTime = startTime;
  341. channel.$play();
  342. egret.sys.$pushSoundChannel(channel);
  343. return channel;
  344. };
  345. /**
  346. * @inheritDoc
  347. */
  348. HtmlSound.prototype.close = function () {
  349. if (this.loaded == false && this.originAudio)
  350. this.originAudio.src = "";
  351. if (this.originAudio)
  352. this.originAudio = null;
  353. HtmlSound.$clear(this.url);
  354. };
  355. HtmlSound.$clear = function (url) {
  356. HtmlSound.clearAudios[url] = true;
  357. var array = HtmlSound.audios[url];
  358. if (array) {
  359. array.length = 0;
  360. }
  361. };
  362. HtmlSound.$pop = function (url) {
  363. var array = HtmlSound.audios[url];
  364. if (array && array.length > 0) {
  365. return array.pop();
  366. }
  367. return null;
  368. };
  369. HtmlSound.$recycle = function (url, audio) {
  370. if (HtmlSound.clearAudios[url]) {
  371. return;
  372. }
  373. var array = HtmlSound.audios[url];
  374. if (HtmlSound.audios[url] == null) {
  375. array = HtmlSound.audios[url] = [];
  376. }
  377. array.push(audio);
  378. };
  379. /**
  380. * Background music
  381. * @version Egret 2.4
  382. * @platform Web,Native
  383. * @language en_US
  384. */
  385. /**
  386. * 背景音乐
  387. * @version Egret 2.4
  388. * @platform Web,Native
  389. * @language zh_CN
  390. */
  391. HtmlSound.MUSIC = "music";
  392. /**
  393. * EFFECT
  394. * @version Egret 2.4
  395. * @platform Web,Native
  396. * @language en_US
  397. */
  398. /**
  399. * 音效
  400. * @version Egret 2.4
  401. * @platform Web,Native
  402. * @language zh_CN
  403. */
  404. HtmlSound.EFFECT = "effect";
  405. /**
  406. * @private
  407. */
  408. HtmlSound.audios = {};
  409. HtmlSound.clearAudios = {};
  410. return HtmlSound;
  411. }(egret.EventDispatcher));
  412. web.HtmlSound = HtmlSound;
  413. __reflect(HtmlSound.prototype, "egret.web.HtmlSound", ["egret.Sound"]);
  414. })(web = egret.web || (egret.web = {}));
  415. })(egret || (egret = {}));
  416. //////////////////////////////////////////////////////////////////////////////////////
  417. //
  418. // Copyright (c) 2014-present, Egret Technology.
  419. // All rights reserved.
  420. // Redistribution and use in source and binary forms, with or without
  421. // modification, are permitted provided that the following conditions are met:
  422. //
  423. // * Redistributions of source code must retain the above copyright
  424. // notice, this list of conditions and the following disclaimer.
  425. // * Redistributions in binary form must reproduce the above copyright
  426. // notice, this list of conditions and the following disclaimer in the
  427. // documentation and/or other materials provided with the distribution.
  428. // * Neither the name of the Egret nor the
  429. // names of its contributors may be used to endorse or promote products
  430. // derived from this software without specific prior written permission.
  431. //
  432. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  433. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  434. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  435. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  436. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  437. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  438. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  439. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  440. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  441. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  442. //
  443. //////////////////////////////////////////////////////////////////////////////////////
  444. var egret;
  445. (function (egret) {
  446. var web;
  447. (function (web) {
  448. /**
  449. * @private
  450. * @inheritDoc
  451. */
  452. var HtmlSoundChannel = (function (_super) {
  453. __extends(HtmlSoundChannel, _super);
  454. /**
  455. * @private
  456. */
  457. function HtmlSoundChannel(audio) {
  458. var _this = _super.call(this) || this;
  459. /**
  460. * @private
  461. */
  462. _this.$startTime = 0;
  463. /**
  464. * @private
  465. */
  466. _this.audio = null;
  467. //声音是否已经播放完成
  468. _this.isStopped = false;
  469. _this.canPlay = function () {
  470. _this.audio.removeEventListener("canplay", _this.canPlay);
  471. try {
  472. _this.audio.currentTime = _this.$startTime;
  473. }
  474. catch (e) {
  475. }
  476. finally {
  477. _this.audio.play();
  478. }
  479. };
  480. /**
  481. * @private
  482. */
  483. _this.onPlayEnd = function () {
  484. if (_this.$loops == 1) {
  485. _this.stop();
  486. _this.dispatchEventWith(egret.Event.SOUND_COMPLETE);
  487. return;
  488. }
  489. if (_this.$loops > 0) {
  490. _this.$loops--;
  491. }
  492. /////////////
  493. //this.audio.load();
  494. _this.$play();
  495. };
  496. /**
  497. * @private
  498. */
  499. _this._volume = 1;
  500. audio.addEventListener("ended", _this.onPlayEnd);
  501. _this.audio = audio;
  502. return _this;
  503. }
  504. HtmlSoundChannel.prototype.$play = function () {
  505. if (this.isStopped) {
  506. egret.$error(1036);
  507. return;
  508. }
  509. try {
  510. //this.audio.pause();
  511. this.audio.volume = this._volume;
  512. this.audio.currentTime = this.$startTime;
  513. }
  514. catch (e) {
  515. this.audio.addEventListener("canplay", this.canPlay);
  516. return;
  517. }
  518. this.audio.play();
  519. };
  520. /**
  521. * @private
  522. * @inheritDoc
  523. */
  524. HtmlSoundChannel.prototype.stop = function () {
  525. if (!this.audio)
  526. return;
  527. if (!this.isStopped) {
  528. egret.sys.$popSoundChannel(this);
  529. }
  530. this.isStopped = true;
  531. var audio = this.audio;
  532. audio.removeEventListener("ended", this.onPlayEnd);
  533. audio.removeEventListener("canplay", this.canPlay);
  534. audio.volume = 0;
  535. this._volume = 0;
  536. this.audio = null;
  537. var url = this.$url;
  538. //延迟一定时间再停止,规避chrome报错
  539. window.setTimeout(function () {
  540. audio.pause();
  541. web.HtmlSound.$recycle(url, audio);
  542. }, 200);
  543. };
  544. Object.defineProperty(HtmlSoundChannel.prototype, "volume", {
  545. /**
  546. * @private
  547. * @inheritDoc
  548. */
  549. get: function () {
  550. return this._volume;
  551. },
  552. /**
  553. * @inheritDoc
  554. */
  555. set: function (value) {
  556. if (this.isStopped) {
  557. egret.$error(1036);
  558. return;
  559. }
  560. this._volume = value;
  561. if (!this.audio)
  562. return;
  563. this.audio.volume = value;
  564. },
  565. enumerable: true,
  566. configurable: true
  567. });
  568. Object.defineProperty(HtmlSoundChannel.prototype, "position", {
  569. /**
  570. * @private
  571. * @inheritDoc
  572. */
  573. get: function () {
  574. if (!this.audio)
  575. return 0;
  576. return this.audio.currentTime;
  577. },
  578. enumerable: true,
  579. configurable: true
  580. });
  581. return HtmlSoundChannel;
  582. }(egret.EventDispatcher));
  583. web.HtmlSoundChannel = HtmlSoundChannel;
  584. __reflect(HtmlSoundChannel.prototype, "egret.web.HtmlSoundChannel", ["egret.SoundChannel", "egret.IEventDispatcher"]);
  585. })(web = egret.web || (egret.web = {}));
  586. })(egret || (egret = {}));
  587. //////////////////////////////////////////////////////////////////////////////////////
  588. //
  589. // Copyright (c) 2014-present, Egret Technology.
  590. // All rights reserved.
  591. // Redistribution and use in source and binary forms, with or without
  592. // modification, are permitted provided that the following conditions are met:
  593. //
  594. // * Redistributions of source code must retain the above copyright
  595. // notice, this list of conditions and the following disclaimer.
  596. // * Redistributions in binary form must reproduce the above copyright
  597. // notice, this list of conditions and the following disclaimer in the
  598. // documentation and/or other materials provided with the distribution.
  599. // * Neither the name of the Egret nor the
  600. // names of its contributors may be used to endorse or promote products
  601. // derived from this software without specific prior written permission.
  602. //
  603. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  604. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  605. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  606. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  607. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  608. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  609. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  610. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  611. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  612. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  613. //
  614. //////////////////////////////////////////////////////////////////////////////////////
  615. var egret;
  616. (function (egret) {
  617. var web;
  618. (function (web) {
  619. /**
  620. * @private
  621. */
  622. var WebAudioDecode = (function () {
  623. function WebAudioDecode() {
  624. }
  625. /**
  626. * @private
  627. *
  628. */
  629. WebAudioDecode.decodeAudios = function () {
  630. if (WebAudioDecode.decodeArr.length <= 0) {
  631. return;
  632. }
  633. if (WebAudioDecode.isDecoding) {
  634. return;
  635. }
  636. WebAudioDecode.isDecoding = true;
  637. var decodeInfo = WebAudioDecode.decodeArr.shift();
  638. WebAudioDecode.ctx.decodeAudioData(decodeInfo["buffer"], function (audioBuffer) {
  639. decodeInfo["self"].audioBuffer = audioBuffer;
  640. if (decodeInfo["success"]) {
  641. decodeInfo["success"]();
  642. }
  643. WebAudioDecode.isDecoding = false;
  644. WebAudioDecode.decodeAudios();
  645. }, function () {
  646. alert("sound decode error: " + decodeInfo["url"] + "!\nsee http://edn.egret.com/cn/docs/page/156");
  647. if (decodeInfo["fail"]) {
  648. decodeInfo["fail"]();
  649. }
  650. WebAudioDecode.isDecoding = false;
  651. WebAudioDecode.decodeAudios();
  652. });
  653. };
  654. /**
  655. * @private
  656. */
  657. WebAudioDecode.decodeArr = [];
  658. /**
  659. * @private
  660. */
  661. WebAudioDecode.isDecoding = false;
  662. return WebAudioDecode;
  663. }());
  664. web.WebAudioDecode = WebAudioDecode;
  665. __reflect(WebAudioDecode.prototype, "egret.web.WebAudioDecode");
  666. /**
  667. * @private
  668. * @inheritDoc
  669. */
  670. var WebAudioSound = (function (_super) {
  671. __extends(WebAudioSound, _super);
  672. /**
  673. * @private
  674. * @inheritDoc
  675. */
  676. function WebAudioSound() {
  677. var _this = _super.call(this) || this;
  678. /**
  679. * @private
  680. */
  681. _this.loaded = false;
  682. return _this;
  683. }
  684. Object.defineProperty(WebAudioSound.prototype, "length", {
  685. get: function () {
  686. if (this.audioBuffer) {
  687. return this.audioBuffer.duration;
  688. }
  689. throw new Error("sound not loaded!");
  690. //return 0;
  691. },
  692. enumerable: true,
  693. configurable: true
  694. });
  695. /**
  696. * @inheritDoc
  697. */
  698. WebAudioSound.prototype.load = function (url) {
  699. var self = this;
  700. this.url = url;
  701. if (true && !url) {
  702. egret.$error(3002);
  703. }
  704. var request = new XMLHttpRequest();
  705. request.open("GET", url, true);
  706. request.responseType = "arraybuffer";
  707. request.onreadystatechange = function () {
  708. if (request.readyState == 4) {
  709. var ioError = (request.status >= 400 || request.status == 0);
  710. if (ioError) {
  711. self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  712. }
  713. else {
  714. WebAudioDecode.decodeArr.push({
  715. "buffer": request.response,
  716. "success": onAudioLoaded,
  717. "fail": onAudioError,
  718. "self": self,
  719. "url": self.url
  720. });
  721. WebAudioDecode.decodeAudios();
  722. }
  723. }
  724. };
  725. request.send();
  726. function onAudioLoaded() {
  727. self.loaded = true;
  728. self.dispatchEventWith(egret.Event.COMPLETE);
  729. }
  730. function onAudioError() {
  731. self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  732. }
  733. };
  734. /**
  735. * @inheritDoc
  736. */
  737. WebAudioSound.prototype.play = function (startTime, loops) {
  738. startTime = +startTime || 0;
  739. loops = +loops || 0;
  740. if (true && this.loaded == false) {
  741. egret.$error(1049);
  742. }
  743. var channel = new web.WebAudioSoundChannel();
  744. channel.$url = this.url;
  745. channel.$loops = loops;
  746. channel.$audioBuffer = this.audioBuffer;
  747. channel.$startTime = startTime;
  748. channel.$play();
  749. egret.sys.$pushSoundChannel(channel);
  750. return channel;
  751. };
  752. /**
  753. * @inheritDoc
  754. */
  755. WebAudioSound.prototype.close = function () {
  756. };
  757. /**
  758. * Background music
  759. * @version Egret 2.4
  760. * @platform Web,Native
  761. * @language en_US
  762. */
  763. /**
  764. * 背景音乐
  765. * @version Egret 2.4
  766. * @platform Web,Native
  767. * @language zh_CN
  768. */
  769. WebAudioSound.MUSIC = "music";
  770. /**
  771. * EFFECT
  772. * @version Egret 2.4
  773. * @platform Web,Native
  774. * @language en_US
  775. */
  776. /**
  777. * 音效
  778. * @version Egret 2.4
  779. * @platform Web,Native
  780. * @language zh_CN
  781. */
  782. WebAudioSound.EFFECT = "effect";
  783. return WebAudioSound;
  784. }(egret.EventDispatcher));
  785. web.WebAudioSound = WebAudioSound;
  786. __reflect(WebAudioSound.prototype, "egret.web.WebAudioSound", ["egret.Sound"]);
  787. })(web = egret.web || (egret.web = {}));
  788. })(egret || (egret = {}));
  789. //////////////////////////////////////////////////////////////////////////////////////
  790. //
  791. // Copyright (c) 2014-present, Egret Technology.
  792. // All rights reserved.
  793. // Redistribution and use in source and binary forms, with or without
  794. // modification, are permitted provided that the following conditions are met:
  795. //
  796. // * Redistributions of source code must retain the above copyright
  797. // notice, this list of conditions and the following disclaimer.
  798. // * Redistributions in binary form must reproduce the above copyright
  799. // notice, this list of conditions and the following disclaimer in the
  800. // documentation and/or other materials provided with the distribution.
  801. // * Neither the name of the Egret nor the
  802. // names of its contributors may be used to endorse or promote products
  803. // derived from this software without specific prior written permission.
  804. //
  805. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  806. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  807. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  808. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  809. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  810. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  811. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  812. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  813. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  814. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  815. //
  816. //////////////////////////////////////////////////////////////////////////////////////
  817. var egret;
  818. (function (egret) {
  819. var web;
  820. (function (web) {
  821. /**
  822. * @private
  823. * @inheritDoc
  824. */
  825. var WebAudioSoundChannel = (function (_super) {
  826. __extends(WebAudioSoundChannel, _super);
  827. /**
  828. * @private
  829. */
  830. function WebAudioSoundChannel() {
  831. var _this = _super.call(this) || this;
  832. /**
  833. * @private
  834. */
  835. _this.$startTime = 0;
  836. /**
  837. * @private
  838. */
  839. _this.bufferSource = null;
  840. /**
  841. * @private
  842. */
  843. _this.context = web.WebAudioDecode.ctx;
  844. //声音是否已经播放完成
  845. _this.isStopped = false;
  846. /**
  847. * @private
  848. */
  849. _this._currentTime = 0;
  850. /**
  851. * @private
  852. */
  853. _this._volume = 1;
  854. /**
  855. * @private
  856. */
  857. _this.onPlayEnd = function () {
  858. if (_this.$loops == 1) {
  859. _this.stop();
  860. _this.dispatchEventWith(egret.Event.SOUND_COMPLETE);
  861. return;
  862. }
  863. if (_this.$loops > 0) {
  864. _this.$loops--;
  865. }
  866. /////////////
  867. _this.$play();
  868. };
  869. /**
  870. * @private
  871. */
  872. _this._startTime = 0;
  873. if (_this.context["createGain"]) {
  874. _this.gain = _this.context["createGain"]();
  875. }
  876. else {
  877. _this.gain = _this.context["createGainNode"]();
  878. }
  879. return _this;
  880. }
  881. WebAudioSoundChannel.prototype.$play = function () {
  882. if (this.isStopped) {
  883. egret.$error(1036);
  884. return;
  885. }
  886. if (this.bufferSource) {
  887. this.bufferSource.onended = null;
  888. this.bufferSource = null;
  889. }
  890. var context = this.context;
  891. var gain = this.gain;
  892. var bufferSource = context.createBufferSource();
  893. this.bufferSource = bufferSource;
  894. bufferSource.buffer = this.$audioBuffer;
  895. bufferSource.connect(gain);
  896. gain.connect(context.destination);
  897. bufferSource.onended = this.onPlayEnd;
  898. this._startTime = Date.now();
  899. this.gain.gain.value = this._volume;
  900. bufferSource.start(0, this.$startTime);
  901. this._currentTime = 0;
  902. };
  903. WebAudioSoundChannel.prototype.stop = function () {
  904. if (this.bufferSource) {
  905. var sourceNode = this.bufferSource;
  906. if (sourceNode.stop) {
  907. sourceNode.stop(0);
  908. }
  909. else {
  910. sourceNode.noteOff(0);
  911. }
  912. sourceNode.onended = null;
  913. sourceNode.disconnect();
  914. this.bufferSource = null;
  915. this.$audioBuffer = null;
  916. }
  917. if (!this.isStopped) {
  918. egret.sys.$popSoundChannel(this);
  919. }
  920. this.isStopped = true;
  921. };
  922. Object.defineProperty(WebAudioSoundChannel.prototype, "volume", {
  923. /**
  924. * @private
  925. * @inheritDoc
  926. */
  927. get: function () {
  928. return this._volume;
  929. },
  930. /**
  931. * @inheritDoc
  932. */
  933. set: function (value) {
  934. if (this.isStopped) {
  935. egret.$error(1036);
  936. return;
  937. }
  938. this._volume = value;
  939. this.gain.gain.value = value;
  940. },
  941. enumerable: true,
  942. configurable: true
  943. });
  944. Object.defineProperty(WebAudioSoundChannel.prototype, "position", {
  945. /**
  946. * @private
  947. * @inheritDoc
  948. */
  949. get: function () {
  950. if (this.bufferSource) {
  951. return (Date.now() - this._startTime) / 1000 + this.$startTime;
  952. }
  953. return 0;
  954. },
  955. enumerable: true,
  956. configurable: true
  957. });
  958. return WebAudioSoundChannel;
  959. }(egret.EventDispatcher));
  960. web.WebAudioSoundChannel = WebAudioSoundChannel;
  961. __reflect(WebAudioSoundChannel.prototype, "egret.web.WebAudioSoundChannel", ["egret.SoundChannel", "egret.IEventDispatcher"]);
  962. })(web = egret.web || (egret.web = {}));
  963. })(egret || (egret = {}));
  964. //////////////////////////////////////////////////////////////////////////////////////
  965. //
  966. // Copyright (c) 2014-present, Egret Technology.
  967. // All rights reserved.
  968. // Redistribution and use in source and binary forms, with or without
  969. // modification, are permitted provided that the following conditions are met:
  970. //
  971. // * Redistributions of source code must retain the above copyright
  972. // notice, this list of conditions and the following disclaimer.
  973. // * Redistributions in binary form must reproduce the above copyright
  974. // notice, this list of conditions and the following disclaimer in the
  975. // documentation and/or other materials provided with the distribution.
  976. // * Neither the name of the Egret nor the
  977. // names of its contributors may be used to endorse or promote products
  978. // derived from this software without specific prior written permission.
  979. //
  980. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  981. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  982. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  983. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  984. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  985. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  986. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  987. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  988. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  989. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  990. //
  991. //////////////////////////////////////////////////////////////////////////////////////
  992. var egret;
  993. (function (egret) {
  994. var web;
  995. (function (web) {
  996. /**
  997. * @private
  998. * @inheritDoc
  999. */
  1000. var WebVideo = (function (_super) {
  1001. __extends(WebVideo, _super);
  1002. /**
  1003. * @inheritDoc
  1004. */
  1005. function WebVideo(url, cache) {
  1006. if (cache === void 0) { cache = true; }
  1007. var _this = _super.call(this) || this;
  1008. /**
  1009. * @private
  1010. */
  1011. _this.loaded = false;
  1012. /**
  1013. * @private
  1014. */
  1015. _this.closed = false;
  1016. /**
  1017. * @private
  1018. */
  1019. _this.heightSet = NaN;
  1020. /**
  1021. * @private
  1022. */
  1023. _this.widthSet = NaN;
  1024. /**
  1025. * @private
  1026. * pc上视频卡住的时候不能暂停
  1027. */
  1028. _this.waiting = false;
  1029. /**
  1030. * @private
  1031. * 用户是否设置了 pause
  1032. */
  1033. _this.userPause = false;
  1034. /**
  1035. * @private
  1036. * 用户是否设置了 play
  1037. */
  1038. _this.userPlay = false;
  1039. _this.isPlayed = false;
  1040. _this.screenChanged = function (e) {
  1041. var isfullscreen = document.fullscreenEnabled || document.webkitIsFullScreen;
  1042. if (!isfullscreen) {
  1043. _this.checkFullScreen(false);
  1044. if (!egret.Capabilities.isMobile) {
  1045. _this._fullscreen = isfullscreen;
  1046. }
  1047. }
  1048. };
  1049. _this._fullscreen = true;
  1050. /**
  1051. * @private
  1052. *
  1053. */
  1054. _this.onVideoLoaded = function () {
  1055. _this.video.removeEventListener("canplay", _this.onVideoLoaded);
  1056. var video = _this.video;
  1057. _this.loaded = true;
  1058. //video.pause();
  1059. if (_this.posterData) {
  1060. _this.posterData.width = _this.getPlayWidth();
  1061. _this.posterData.height = _this.getPlayHeight();
  1062. }
  1063. video.width = video.videoWidth;
  1064. video.height = video.videoHeight;
  1065. window.setTimeout(function () {
  1066. _this.dispatchEventWith(egret.Event.COMPLETE);
  1067. }, 200);
  1068. };
  1069. _this.$renderNode = new egret.sys.BitmapNode();
  1070. _this.src = url;
  1071. _this.once(egret.Event.ADDED_TO_STAGE, _this.loadPoster, _this);
  1072. if (url) {
  1073. _this.load();
  1074. }
  1075. return _this;
  1076. }
  1077. WebVideo.prototype.createNativeDisplayObject = function () {
  1078. this.$nativeDisplayObject = new egret_native.NativeDisplayObject(1 /* BITMAP */);
  1079. };
  1080. /**
  1081. * @inheritDoc
  1082. */
  1083. WebVideo.prototype.load = function (url, cache) {
  1084. var _this = this;
  1085. if (cache === void 0) { cache = true; }
  1086. url = url || this.src;
  1087. this.src = url;
  1088. if (true && !url) {
  1089. egret.$error(3002);
  1090. }
  1091. if (this.video && this.video.src == url) {
  1092. return;
  1093. }
  1094. var video;
  1095. if (!this.video || egret.Capabilities.isMobile) {
  1096. video = document.createElement("video");
  1097. this.video = video;
  1098. video.controls = null;
  1099. }
  1100. else {
  1101. video = this.video;
  1102. }
  1103. video.src = url;
  1104. video.setAttribute("autoplay", "autoplay");
  1105. video.setAttribute("webkit-playsinline", "true");
  1106. video.addEventListener("canplay", this.onVideoLoaded);
  1107. video.addEventListener("error", function () { return _this.onVideoError(); });
  1108. video.addEventListener("ended", function () { return _this.onVideoEnded(); });
  1109. var firstPause = false;
  1110. video.addEventListener("canplay", function () {
  1111. _this.waiting = false;
  1112. if (!firstPause) {
  1113. firstPause = true;
  1114. video.pause();
  1115. }
  1116. else {
  1117. if (_this.userPause) {
  1118. _this.pause();
  1119. }
  1120. else if (_this.userPlay) {
  1121. _this.play();
  1122. }
  1123. }
  1124. });
  1125. video.addEventListener("waiting", function () {
  1126. _this.waiting = true;
  1127. });
  1128. video.load();
  1129. this.videoPlay();
  1130. video.style.position = "absolute";
  1131. video.style.top = "0px";
  1132. video.style.zIndex = "-88888";
  1133. video.style.left = "0px";
  1134. video.height = 1;
  1135. video.width = 1;
  1136. };
  1137. /**
  1138. * @inheritDoc
  1139. */
  1140. WebVideo.prototype.play = function (startTime, loop) {
  1141. var _this = this;
  1142. if (loop === void 0) { loop = false; }
  1143. if (this.loaded == false) {
  1144. this.load(this.src);
  1145. this.once(egret.Event.COMPLETE, function (e) { return _this.play(startTime, loop); }, this);
  1146. return;
  1147. }
  1148. this.isPlayed = true;
  1149. var video = this.video;
  1150. if (startTime != undefined) {
  1151. video.currentTime = +startTime || 0;
  1152. }
  1153. video.loop = !!loop;
  1154. if (egret.Capabilities.isMobile) {
  1155. video.style.zIndex = "-88888"; //移动端,就算设置成最小,只要全屏,都会在最上层,而且在自动退出去后,不担心挡住canvas
  1156. }
  1157. else {
  1158. video.style.zIndex = "9999";
  1159. }
  1160. video.style.position = "absolute";
  1161. video.style.top = "0px";
  1162. video.style.left = "0px";
  1163. video.height = video.videoHeight;
  1164. video.width = video.videoWidth;
  1165. if (egret.Capabilities.os != "Windows PC" && egret.Capabilities.os != "Mac OS") {
  1166. window.setTimeout(function () {
  1167. video.width = 0;
  1168. }, 1000);
  1169. }
  1170. this.checkFullScreen(this._fullscreen);
  1171. };
  1172. WebVideo.prototype.videoPlay = function () {
  1173. this.userPause = false;
  1174. if (this.waiting) {
  1175. this.userPlay = true;
  1176. return;
  1177. }
  1178. this.userPlay = false;
  1179. this.video.play();
  1180. };
  1181. WebVideo.prototype.checkFullScreen = function (playFullScreen) {
  1182. var video = this.video;
  1183. if (playFullScreen) {
  1184. if (video.parentElement == null) {
  1185. video.removeAttribute("webkit-playsinline");
  1186. document.body.appendChild(video);
  1187. }
  1188. egret.stopTick(this.markDirty, this);
  1189. this.goFullscreen();
  1190. }
  1191. else {
  1192. if (video.parentElement != null) {
  1193. video.parentElement.removeChild(video);
  1194. }
  1195. video.setAttribute("webkit-playsinline", "true");
  1196. this.setFullScreenMonitor(false);
  1197. egret.startTick(this.markDirty, this);
  1198. if (egret.Capabilities.isMobile) {
  1199. this.video.currentTime = 0;
  1200. this.onVideoEnded();
  1201. return;
  1202. }
  1203. }
  1204. this.videoPlay();
  1205. };
  1206. WebVideo.prototype.goFullscreen = function () {
  1207. var video = this.video;
  1208. var fullscreenType;
  1209. fullscreenType = egret.web.getPrefixStyleName('requestFullscreen', video);
  1210. if (!video[fullscreenType]) {
  1211. fullscreenType = egret.web.getPrefixStyleName('requestFullScreen', video);
  1212. if (!video[fullscreenType]) {
  1213. return true;
  1214. }
  1215. }
  1216. video.removeAttribute("webkit-playsinline");
  1217. video[fullscreenType]();
  1218. this.setFullScreenMonitor(true);
  1219. return true;
  1220. };
  1221. WebVideo.prototype.setFullScreenMonitor = function (use) {
  1222. var video = this.video;
  1223. if (use) {
  1224. video.addEventListener("mozfullscreenchange", this.screenChanged);
  1225. video.addEventListener("webkitfullscreenchange", this.screenChanged);
  1226. video.addEventListener("mozfullscreenerror", this.screenError);
  1227. video.addEventListener("webkitfullscreenerror", this.screenError);
  1228. }
  1229. else {
  1230. video.removeEventListener("mozfullscreenchange", this.screenChanged);
  1231. video.removeEventListener("webkitfullscreenchange", this.screenChanged);
  1232. video.removeEventListener("mozfullscreenerror", this.screenError);
  1233. video.removeEventListener("webkitfullscreenerror", this.screenError);
  1234. }
  1235. };
  1236. WebVideo.prototype.screenError = function () {
  1237. egret.$error(3014);
  1238. };
  1239. WebVideo.prototype.exitFullscreen = function () {
  1240. //退出全屏
  1241. if (document['exitFullscreen']) {
  1242. document['exitFullscreen']();
  1243. }
  1244. else if (document['msExitFullscreen']) {
  1245. document['msExitFullscreen']();
  1246. }
  1247. else if (document['mozCancelFullScreen']) {
  1248. document['mozCancelFullScreen']();
  1249. }
  1250. else if (document['oCancelFullScreen']) {
  1251. document['oCancelFullScreen']();
  1252. }
  1253. else if (document['webkitExitFullscreen']) {
  1254. document['webkitExitFullscreen']();
  1255. }
  1256. else {
  1257. }
  1258. };
  1259. /**
  1260. * @private
  1261. *
  1262. */
  1263. WebVideo.prototype.onVideoEnded = function () {
  1264. this.pause();
  1265. this.isPlayed = false;
  1266. this.dispatchEventWith(egret.Event.ENDED);
  1267. };
  1268. /**
  1269. * @private
  1270. *
  1271. */
  1272. WebVideo.prototype.onVideoError = function () {
  1273. this.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  1274. };
  1275. /**
  1276. * @inheritDoc
  1277. */
  1278. WebVideo.prototype.close = function () {
  1279. var _this = this;
  1280. this.closed = true;
  1281. this.video.removeEventListener("canplay", this.onVideoLoaded);
  1282. this.video.removeEventListener("error", function () { return _this.onVideoError(); });
  1283. this.video.removeEventListener("ended", function () { return _this.onVideoEnded(); });
  1284. this.pause();
  1285. if (this.loaded == false && this.video)
  1286. this.video.src = "";
  1287. if (this.video && this.video.parentElement) {
  1288. this.video.parentElement.removeChild(this.video);
  1289. this.video = null;
  1290. }
  1291. this.loaded = false;
  1292. };
  1293. /**
  1294. * @inheritDoc
  1295. */
  1296. WebVideo.prototype.pause = function () {
  1297. this.userPlay = false;
  1298. if (this.waiting) {
  1299. this.userPause = true;
  1300. return;
  1301. }
  1302. this.userPause = false;
  1303. this.video.pause();
  1304. egret.stopTick(this.markDirty, this);
  1305. };
  1306. Object.defineProperty(WebVideo.prototype, "volume", {
  1307. /**
  1308. * @inheritDoc
  1309. */
  1310. get: function () {
  1311. if (!this.video)
  1312. return 1;
  1313. return this.video.volume;
  1314. },
  1315. /**
  1316. * @inheritDoc
  1317. */
  1318. set: function (value) {
  1319. if (!this.video)
  1320. return;
  1321. this.video.volume = value;
  1322. },
  1323. enumerable: true,
  1324. configurable: true
  1325. });
  1326. Object.defineProperty(WebVideo.prototype, "position", {
  1327. /**
  1328. * @inheritDoc
  1329. */
  1330. get: function () {
  1331. if (!this.video)
  1332. return 0;
  1333. return this.video.currentTime;
  1334. },
  1335. /**
  1336. * @inheritDoc
  1337. */
  1338. set: function (value) {
  1339. if (!this.video)
  1340. return;
  1341. this.video.currentTime = value;
  1342. },
  1343. enumerable: true,
  1344. configurable: true
  1345. });
  1346. Object.defineProperty(WebVideo.prototype, "fullscreen", {
  1347. /**
  1348. * @inheritDoc
  1349. */
  1350. get: function () {
  1351. return this._fullscreen;
  1352. },
  1353. /**
  1354. * @inheritDoc
  1355. */
  1356. set: function (value) {
  1357. if (egret.Capabilities.isMobile) {
  1358. return;
  1359. }
  1360. this._fullscreen = !!value;
  1361. if (this.video && this.video.paused == false) {
  1362. this.checkFullScreen(this._fullscreen);
  1363. }
  1364. },
  1365. enumerable: true,
  1366. configurable: true
  1367. });
  1368. Object.defineProperty(WebVideo.prototype, "bitmapData", {
  1369. /**
  1370. * @inheritDoc
  1371. */
  1372. get: function () {
  1373. if (!this.video || !this.loaded)
  1374. return null;
  1375. if (!this._bitmapData) {
  1376. this.video.width = this.video.videoWidth;
  1377. this.video.height = this.video.videoHeight;
  1378. this._bitmapData = new egret.BitmapData(this.video);
  1379. this._bitmapData.$deleteSource = false;
  1380. }
  1381. return this._bitmapData;
  1382. },
  1383. enumerable: true,
  1384. configurable: true
  1385. });
  1386. WebVideo.prototype.loadPoster = function () {
  1387. var _this = this;
  1388. var poster = this.poster;
  1389. if (!poster)
  1390. return;
  1391. var imageLoader = new egret.ImageLoader();
  1392. imageLoader.once(egret.Event.COMPLETE, function (e) {
  1393. var posterData = imageLoader.data;
  1394. _this.posterData = imageLoader.data;
  1395. _this.$renderDirty = true;
  1396. _this.posterData.width = _this.getPlayWidth();
  1397. _this.posterData.height = _this.getPlayHeight();
  1398. if (egret.nativeRender) {
  1399. var texture = new egret.Texture();
  1400. texture._setBitmapData(_this.posterData);
  1401. _this.$nativeDisplayObject.setBitmapData(texture);
  1402. }
  1403. }, this);
  1404. imageLoader.load(poster);
  1405. };
  1406. /**
  1407. * @private
  1408. */
  1409. WebVideo.prototype.$measureContentBounds = function (bounds) {
  1410. var bitmapData = this.bitmapData;
  1411. var posterData = this.posterData;
  1412. if (bitmapData) {
  1413. bounds.setTo(0, 0, this.getPlayWidth(), this.getPlayHeight());
  1414. }
  1415. else if (posterData) {
  1416. bounds.setTo(0, 0, this.getPlayWidth(), this.getPlayHeight());
  1417. }
  1418. else {
  1419. bounds.setEmpty();
  1420. }
  1421. };
  1422. WebVideo.prototype.getPlayWidth = function () {
  1423. if (!isNaN(this.widthSet)) {
  1424. return this.widthSet;
  1425. }
  1426. if (this.bitmapData) {
  1427. return this.bitmapData.width;
  1428. }
  1429. if (this.posterData) {
  1430. return this.posterData.width;
  1431. }
  1432. return NaN;
  1433. };
  1434. WebVideo.prototype.getPlayHeight = function () {
  1435. if (!isNaN(this.heightSet)) {
  1436. return this.heightSet;
  1437. }
  1438. if (this.bitmapData) {
  1439. return this.bitmapData.height;
  1440. }
  1441. if (this.posterData) {
  1442. return this.posterData.height;
  1443. }
  1444. return NaN;
  1445. };
  1446. /**
  1447. * @private
  1448. */
  1449. WebVideo.prototype.$updateRenderNode = function () {
  1450. var node = this.$renderNode;
  1451. var bitmapData = this.bitmapData;
  1452. var posterData = this.posterData;
  1453. var width = this.getPlayWidth();
  1454. var height = this.getPlayHeight();
  1455. if ((!this.isPlayed || egret.Capabilities.isMobile) && posterData) {
  1456. node.image = posterData;
  1457. node.imageWidth = width;
  1458. node.imageHeight = height;
  1459. node.drawImage(0, 0, posterData.width, posterData.height, 0, 0, width, height);
  1460. }
  1461. else if (this.isPlayed && bitmapData) {
  1462. node.image = bitmapData;
  1463. node.imageWidth = bitmapData.width;
  1464. node.imageHeight = bitmapData.height;
  1465. egret.WebGLUtils.deleteWebGLTexture(bitmapData.webGLTexture);
  1466. bitmapData.webGLTexture = null;
  1467. node.drawImage(0, 0, bitmapData.width, bitmapData.height, 0, 0, width, height);
  1468. }
  1469. };
  1470. WebVideo.prototype.markDirty = function () {
  1471. this.$renderDirty = true;
  1472. return true;
  1473. };
  1474. /**
  1475. * @private
  1476. * 设置显示高度
  1477. */
  1478. WebVideo.prototype.$setHeight = function (value) {
  1479. this.heightSet = value;
  1480. if (this.paused) {
  1481. var self_1 = this;
  1482. this.$renderDirty = true;
  1483. window.setTimeout(function () {
  1484. self_1.$renderDirty = false;
  1485. }, 200);
  1486. }
  1487. _super.prototype.$setHeight.call(this, value);
  1488. };
  1489. /**
  1490. * @private
  1491. * 设置显示宽度
  1492. */
  1493. WebVideo.prototype.$setWidth = function (value) {
  1494. this.widthSet = value;
  1495. if (this.paused) {
  1496. var self_2 = this;
  1497. this.$renderDirty = true;
  1498. window.setTimeout(function () {
  1499. self_2.$renderDirty = false;
  1500. }, 200);
  1501. }
  1502. _super.prototype.$setWidth.call(this, value);
  1503. };
  1504. Object.defineProperty(WebVideo.prototype, "paused", {
  1505. get: function () {
  1506. if (this.video) {
  1507. return this.video.paused;
  1508. }
  1509. return true;
  1510. },
  1511. enumerable: true,
  1512. configurable: true
  1513. });
  1514. Object.defineProperty(WebVideo.prototype, "length", {
  1515. /**
  1516. * @inheritDoc
  1517. */
  1518. get: function () {
  1519. if (this.video) {
  1520. return this.video.duration;
  1521. }
  1522. throw new Error("Video not loaded!");
  1523. },
  1524. enumerable: true,
  1525. configurable: true
  1526. });
  1527. return WebVideo;
  1528. }(egret.DisplayObject));
  1529. web.WebVideo = WebVideo;
  1530. __reflect(WebVideo.prototype, "egret.web.WebVideo", ["egret.Video", "egret.DisplayObject"]);
  1531. egret.Video = WebVideo;
  1532. })(web = egret.web || (egret.web = {}));
  1533. })(egret || (egret = {}));
  1534. //////////////////////////////////////////////////////////////////////////////////////
  1535. //
  1536. // Copyright (c) 2014-present, Egret Technology.
  1537. // All rights reserved.
  1538. // Redistribution and use in source and binary forms, with or without
  1539. // modification, are permitted provided that the following conditions are met:
  1540. //
  1541. // * Redistributions of source code must retain the above copyright
  1542. // notice, this list of conditions and the following disclaimer.
  1543. // * Redistributions in binary form must reproduce the above copyright
  1544. // notice, this list of conditions and the following disclaimer in the
  1545. // documentation and/or other materials provided with the distribution.
  1546. // * Neither the name of the Egret nor the
  1547. // names of its contributors may be used to endorse or promote products
  1548. // derived from this software without specific prior written permission.
  1549. //
  1550. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1551. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1552. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1553. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1554. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1555. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1556. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1557. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1558. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1559. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1560. //
  1561. //////////////////////////////////////////////////////////////////////////////////////
  1562. var egret;
  1563. (function (egret) {
  1564. var web;
  1565. (function (web) {
  1566. /**
  1567. * @private
  1568. */
  1569. var WebHttpRequest = (function (_super) {
  1570. __extends(WebHttpRequest, _super);
  1571. /**
  1572. * @private
  1573. */
  1574. function WebHttpRequest() {
  1575. var _this = _super.call(this) || this;
  1576. /**
  1577. * @private
  1578. */
  1579. _this._url = "";
  1580. _this._method = "";
  1581. return _this;
  1582. }
  1583. Object.defineProperty(WebHttpRequest.prototype, "response", {
  1584. /**
  1585. * @private
  1586. * 本次请求返回的数据,数据类型根据responseType设置的值确定。
  1587. */
  1588. get: function () {
  1589. if (!this._xhr) {
  1590. return null;
  1591. }
  1592. if (this._xhr.response != undefined) {
  1593. return this._xhr.response;
  1594. }
  1595. if (this._responseType == "text") {
  1596. return this._xhr.responseText;
  1597. }
  1598. if (this._responseType == "arraybuffer" && /msie 9.0/i.test(navigator.userAgent)) {
  1599. var w = window;
  1600. return w.convertResponseBodyToText(this._xhr["responseBody"]);
  1601. }
  1602. if (this._responseType == "document") {
  1603. return this._xhr.responseXML;
  1604. }
  1605. /*if (this._xhr.responseXML) {
  1606. return this._xhr.responseXML;
  1607. }
  1608. if (this._xhr.responseText != undefined) {
  1609. return this._xhr.responseText;
  1610. }*/
  1611. return null;
  1612. },
  1613. enumerable: true,
  1614. configurable: true
  1615. });
  1616. Object.defineProperty(WebHttpRequest.prototype, "responseType", {
  1617. /**
  1618. * @private
  1619. * 设置返回的数据格式,请使用 HttpResponseType 里定义的枚举值。设置非法的值或不设置,都将使用HttpResponseType.TEXT。
  1620. */
  1621. get: function () {
  1622. return this._responseType;
  1623. },
  1624. set: function (value) {
  1625. this._responseType = value;
  1626. },
  1627. enumerable: true,
  1628. configurable: true
  1629. });
  1630. Object.defineProperty(WebHttpRequest.prototype, "withCredentials", {
  1631. /**
  1632. * @private
  1633. * 表明在进行跨站(cross-site)的访问控制(Access-Control)请求时,是否使用认证信息(例如cookie或授权的header)。 默认为 false。(这个标志不会影响同站的请求)
  1634. */
  1635. get: function () {
  1636. return this._withCredentials;
  1637. },
  1638. set: function (value) {
  1639. this._withCredentials = value;
  1640. },
  1641. enumerable: true,
  1642. configurable: true
  1643. });
  1644. /**
  1645. * @private
  1646. *
  1647. * @returns
  1648. */
  1649. WebHttpRequest.prototype.getXHR = function () {
  1650. if (window["XMLHttpRequest"]) {
  1651. return new window["XMLHttpRequest"]();
  1652. }
  1653. else {
  1654. return new ActiveXObject("MSXML2.XMLHTTP");
  1655. }
  1656. };
  1657. /**
  1658. * @private
  1659. * 初始化一个请求.注意,若在已经发出请求的对象上调用此方法,相当于立即调用abort().
  1660. * @param url 该请求所要访问的URL该请求所要访问的URL
  1661. * @param method 请求所使用的HTTP方法, 请使用 HttpMethod 定义的枚举值.
  1662. */
  1663. WebHttpRequest.prototype.open = function (url, method) {
  1664. if (method === void 0) { method = "GET"; }
  1665. this._url = url;
  1666. this._method = method;
  1667. if (this._xhr) {
  1668. this._xhr.abort();
  1669. this._xhr = null;
  1670. }
  1671. this._xhr = this.getXHR(); //new XMLHttpRequest();
  1672. this._xhr.onreadystatechange = this.onReadyStateChange.bind(this);
  1673. this._xhr.onprogress = this.updateProgress.bind(this);
  1674. this._xhr.open(this._method, this._url, true);
  1675. };
  1676. /**
  1677. * @private
  1678. * 发送请求.
  1679. * @param data 需要发送的数据
  1680. */
  1681. WebHttpRequest.prototype.send = function (data) {
  1682. if (this._responseType != null) {
  1683. this._xhr.responseType = this._responseType;
  1684. }
  1685. if (this._withCredentials != null) {
  1686. this._xhr.withCredentials = this._withCredentials;
  1687. }
  1688. if (this.headerObj) {
  1689. for (var key in this.headerObj) {
  1690. this._xhr.setRequestHeader(key, this.headerObj[key]);
  1691. }
  1692. }
  1693. this._xhr.send(data);
  1694. };
  1695. /**
  1696. * @private
  1697. * 如果请求已经被发送,则立刻中止请求.
  1698. */
  1699. WebHttpRequest.prototype.abort = function () {
  1700. if (this._xhr) {
  1701. this._xhr.abort();
  1702. }
  1703. };
  1704. /**
  1705. * @private
  1706. * 返回所有响应头信息(响应头名和值), 如果响应头还没接受,则返回"".
  1707. */
  1708. WebHttpRequest.prototype.getAllResponseHeaders = function () {
  1709. if (!this._xhr) {
  1710. return null;
  1711. }
  1712. var result = this._xhr.getAllResponseHeaders();
  1713. return result ? result : "";
  1714. };
  1715. /**
  1716. * @private
  1717. * 给指定的HTTP请求头赋值.在这之前,您必须确认已经调用 open() 方法打开了一个url.
  1718. * @param header 将要被赋值的请求头名称.
  1719. * @param value 给指定的请求头赋的值.
  1720. */
  1721. WebHttpRequest.prototype.setRequestHeader = function (header, value) {
  1722. if (!this.headerObj) {
  1723. this.headerObj = {};
  1724. }
  1725. this.headerObj[header] = value;
  1726. };
  1727. /**
  1728. * @private
  1729. * 返回指定的响应头的值, 如果响应头还没被接受,或该响应头不存在,则返回"".
  1730. * @param header 要返回的响应头名称
  1731. */
  1732. WebHttpRequest.prototype.getResponseHeader = function (header) {
  1733. if (!this._xhr) {
  1734. return null;
  1735. }
  1736. var result = this._xhr.getResponseHeader(header);
  1737. return result ? result : "";
  1738. };
  1739. /**
  1740. * @private
  1741. */
  1742. WebHttpRequest.prototype.onReadyStateChange = function () {
  1743. var xhr = this._xhr;
  1744. if (xhr.readyState == 4) {
  1745. var ioError_1 = (xhr.status >= 400 || xhr.status == 0);
  1746. var url_1 = this._url;
  1747. var self_3 = this;
  1748. window.setTimeout(function () {
  1749. if (ioError_1) {
  1750. if (true && !self_3.hasEventListener(egret.IOErrorEvent.IO_ERROR)) {
  1751. egret.$error(1011, url_1);
  1752. }
  1753. self_3.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  1754. }
  1755. else {
  1756. self_3.dispatchEventWith(egret.Event.COMPLETE);
  1757. }
  1758. }, 0);
  1759. }
  1760. };
  1761. /**
  1762. * @private
  1763. */
  1764. WebHttpRequest.prototype.updateProgress = function (event) {
  1765. if (event.lengthComputable) {
  1766. egret.ProgressEvent.dispatchProgressEvent(this, egret.ProgressEvent.PROGRESS, event.loaded, event.total);
  1767. }
  1768. };
  1769. return WebHttpRequest;
  1770. }(egret.EventDispatcher));
  1771. web.WebHttpRequest = WebHttpRequest;
  1772. __reflect(WebHttpRequest.prototype, "egret.web.WebHttpRequest", ["egret.HttpRequest"]);
  1773. egret.HttpRequest = WebHttpRequest;
  1774. })(web = egret.web || (egret.web = {}));
  1775. })(egret || (egret = {}));
  1776. //////////////////////////////////////////////////////////////////////////////////////
  1777. //
  1778. // Copyright (c) 2014-present, Egret Technology.
  1779. // All rights reserved.
  1780. // Redistribution and use in source and binary forms, with or without
  1781. // modification, are permitted provided that the following conditions are met:
  1782. //
  1783. // * Redistributions of source code must retain the above copyright
  1784. // notice, this list of conditions and the following disclaimer.
  1785. // * Redistributions in binary form must reproduce the above copyright
  1786. // notice, this list of conditions and the following disclaimer in the
  1787. // documentation and/or other materials provided with the distribution.
  1788. // * Neither the name of the Egret nor the
  1789. // names of its contributors may be used to endorse or promote products
  1790. // derived from this software without specific prior written permission.
  1791. //
  1792. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1793. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1794. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1795. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1796. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1797. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1798. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1799. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1800. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1801. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1802. //
  1803. //////////////////////////////////////////////////////////////////////////////////////
  1804. var egret;
  1805. (function (egret) {
  1806. var web;
  1807. (function (web) {
  1808. var winURL = window["URL"] || window["webkitURL"];
  1809. /**
  1810. * @private
  1811. * ImageLoader 类可用于加载图像(JPG、PNG 或 GIF)文件。使用 load() 方法来启动加载。被加载的图像对象数据将存储在 ImageLoader.data 属性上 。
  1812. */
  1813. var WebImageLoader = (function (_super) {
  1814. __extends(WebImageLoader, _super);
  1815. function WebImageLoader() {
  1816. var _this = _super !== null && _super.apply(this, arguments) || this;
  1817. /**
  1818. * @private
  1819. * 使用 load() 方法加载成功的 BitmapData 图像数据。
  1820. */
  1821. _this.data = null;
  1822. /**
  1823. * @private
  1824. * 当从其他站点加载一个图片时,指定是否启用跨域资源共享(CORS),默认值为null。
  1825. * 可以设置为"anonymous","use-credentials"或null,设置为其他值将等同于"anonymous"。
  1826. */
  1827. _this._crossOrigin = null;
  1828. /**
  1829. * @private
  1830. * 标记crossOrigin有没有被设置过,设置过之后使用设置的属性
  1831. */
  1832. _this._hasCrossOriginSet = false;
  1833. /**
  1834. * @private
  1835. */
  1836. _this.currentImage = null;
  1837. /**
  1838. * @private
  1839. */
  1840. _this.request = null;
  1841. return _this;
  1842. }
  1843. Object.defineProperty(WebImageLoader.prototype, "crossOrigin", {
  1844. get: function () {
  1845. return this._crossOrigin;
  1846. },
  1847. set: function (value) {
  1848. this._hasCrossOriginSet = true;
  1849. this._crossOrigin = value;
  1850. },
  1851. enumerable: true,
  1852. configurable: true
  1853. });
  1854. /**
  1855. * @private
  1856. * 启动一次图像加载。注意:若之前已经调用过加载请求,重新调用 load() 将终止先前的请求,并开始新的加载。
  1857. * @param url 要加载的图像文件的地址。
  1858. */
  1859. WebImageLoader.prototype.load = function (url) {
  1860. if (web.Html5Capatibility._canUseBlob
  1861. && url.indexOf("wxLocalResource:") != 0 //微信专用不能使用 blob
  1862. && url.indexOf("data:") != 0
  1863. && url.indexOf("http:") != 0
  1864. && url.indexOf("https:") != 0) {
  1865. var request = this.request;
  1866. if (!request) {
  1867. request = this.request = new egret.web.WebHttpRequest();
  1868. request.addEventListener(egret.Event.COMPLETE, this.onBlobLoaded, this);
  1869. request.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onBlobError, this);
  1870. request.responseType = "blob";
  1871. }
  1872. if (true) {
  1873. this.currentURL = url;
  1874. }
  1875. request.open(url);
  1876. request.send();
  1877. }
  1878. else {
  1879. this.loadImage(url);
  1880. }
  1881. };
  1882. /**
  1883. * @private
  1884. */
  1885. WebImageLoader.prototype.onBlobLoaded = function (event) {
  1886. var blob = this.request.response;
  1887. this.request = undefined;
  1888. this.loadImage(winURL.createObjectURL(blob));
  1889. };
  1890. /**
  1891. * @private
  1892. */
  1893. WebImageLoader.prototype.onBlobError = function (event) {
  1894. this.dispatchIOError(this.currentURL);
  1895. this.request = undefined;
  1896. };
  1897. /**
  1898. * @private
  1899. */
  1900. WebImageLoader.prototype.loadImage = function (src) {
  1901. var image = new Image();
  1902. this.data = null;
  1903. this.currentImage = image;
  1904. if (this._hasCrossOriginSet) {
  1905. if (this._crossOrigin) {
  1906. image.crossOrigin = this._crossOrigin;
  1907. }
  1908. }
  1909. else {
  1910. if (WebImageLoader.crossOrigin) {
  1911. image.crossOrigin = WebImageLoader.crossOrigin;
  1912. }
  1913. }
  1914. /*else {
  1915. if (image.hasAttribute("crossOrigin")) {//兼容猎豹
  1916. image.removeAttribute("crossOrigin");
  1917. }
  1918. }*/
  1919. image.onload = this.onImageComplete.bind(this);
  1920. image.onerror = this.onLoadError.bind(this);
  1921. image.src = src;
  1922. };
  1923. /**
  1924. * @private
  1925. */
  1926. WebImageLoader.prototype.onImageComplete = function (event) {
  1927. var image = this.getImage(event);
  1928. if (!image) {
  1929. return;
  1930. }
  1931. this.data = new egret.BitmapData(image);
  1932. var self = this;
  1933. window.setTimeout(function () {
  1934. self.dispatchEventWith(egret.Event.COMPLETE);
  1935. }, 0);
  1936. };
  1937. /**
  1938. * @private
  1939. */
  1940. WebImageLoader.prototype.onLoadError = function (event) {
  1941. var image = this.getImage(event);
  1942. if (!image) {
  1943. return;
  1944. }
  1945. this.dispatchIOError(image.src);
  1946. };
  1947. WebImageLoader.prototype.dispatchIOError = function (url) {
  1948. var self = this;
  1949. window.setTimeout(function () {
  1950. if (true && !self.hasEventListener(egret.IOErrorEvent.IO_ERROR)) {
  1951. egret.$error(1011, url);
  1952. }
  1953. self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  1954. }, 0);
  1955. };
  1956. /**
  1957. * @private
  1958. */
  1959. WebImageLoader.prototype.getImage = function (event) {
  1960. var image = event.target;
  1961. var url = image.src;
  1962. if (url.indexOf("blob:") == 0) {
  1963. try {
  1964. winURL.revokeObjectURL(image.src);
  1965. }
  1966. catch (e) {
  1967. egret.$warn(1037);
  1968. }
  1969. }
  1970. image.onerror = null;
  1971. image.onload = null;
  1972. if (this.currentImage !== image) {
  1973. return null;
  1974. }
  1975. this.currentImage = null;
  1976. return image;
  1977. };
  1978. /**
  1979. * @private
  1980. * 指定是否启用跨域资源共享,如果ImageLoader实例有设置过crossOrigin属性将使用设置的属性
  1981. */
  1982. WebImageLoader.crossOrigin = null;
  1983. return WebImageLoader;
  1984. }(egret.EventDispatcher));
  1985. web.WebImageLoader = WebImageLoader;
  1986. __reflect(WebImageLoader.prototype, "egret.web.WebImageLoader", ["egret.ImageLoader"]);
  1987. egret.ImageLoader = WebImageLoader;
  1988. })(web = egret.web || (egret.web = {}));
  1989. })(egret || (egret = {}));
  1990. //////////////////////////////////////////////////////////////////////////////////////
  1991. //
  1992. // Copyright (c) 2014-present, Egret Technology.
  1993. // All rights reserved.
  1994. // Redistribution and use in source and binary forms, with or without
  1995. // modification, are permitted provided that the following conditions are met:
  1996. //
  1997. // * Redistributions of source code must retain the above copyright
  1998. // notice, this list of conditions and the following disclaimer.
  1999. // * Redistributions in binary form must reproduce the above copyright
  2000. // notice, this list of conditions and the following disclaimer in the
  2001. // documentation and/or other materials provided with the distribution.
  2002. // * Neither the name of the Egret nor the
  2003. // names of its contributors may be used to endorse or promote products
  2004. // derived from this software without specific prior written permission.
  2005. //
  2006. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2007. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2008. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2009. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2010. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2011. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2012. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2013. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2014. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2015. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2016. //
  2017. //////////////////////////////////////////////////////////////////////////////////////
  2018. var egret;
  2019. (function (egret) {
  2020. var web;
  2021. (function (web) {
  2022. /**
  2023. * @classdesc
  2024. * @extends egret.StageText
  2025. * @private
  2026. */
  2027. var HTML5StageText = (function (_super) {
  2028. __extends(HTML5StageText, _super);
  2029. /**
  2030. * @private
  2031. */
  2032. function HTML5StageText() {
  2033. var _this = _super.call(this) || this;
  2034. /**
  2035. * @private
  2036. */
  2037. _this._isNeedShow = false;
  2038. /**
  2039. * @private
  2040. */
  2041. _this.inputElement = null;
  2042. /**
  2043. * @private
  2044. */
  2045. _this.inputDiv = null;
  2046. /**
  2047. * @private
  2048. */
  2049. _this._gscaleX = 0;
  2050. /**
  2051. * @private
  2052. */
  2053. _this._gscaleY = 0;
  2054. /**
  2055. * @private
  2056. */
  2057. _this.textValue = "";
  2058. /**
  2059. * @private
  2060. */
  2061. _this.colorValue = 0xffffff;
  2062. /**
  2063. * @private
  2064. */
  2065. _this._styleInfoes = {};
  2066. return _this;
  2067. }
  2068. /**
  2069. * @private
  2070. *
  2071. * @param textfield
  2072. */
  2073. HTML5StageText.prototype.$setTextField = function (textfield) {
  2074. this.$textfield = textfield;
  2075. return true;
  2076. };
  2077. /**
  2078. * @private
  2079. *
  2080. */
  2081. HTML5StageText.prototype.$addToStage = function () {
  2082. this.htmlInput = egret.web.$getTextAdapter(this.$textfield);
  2083. };
  2084. /**
  2085. * @private
  2086. *
  2087. */
  2088. HTML5StageText.prototype._initElement = function () {
  2089. var point = this.$textfield.localToGlobal(0, 0);
  2090. var x = point.x;
  2091. var y = point.y;
  2092. // let m = this.$textfield.$renderNode.renderMatrix;
  2093. // let cX = m.a;
  2094. // let cY = m.d;
  2095. var scaleX = this.htmlInput.$scaleX;
  2096. var scaleY = this.htmlInput.$scaleY;
  2097. this.inputDiv.style.left = x * scaleX + "px";
  2098. this.inputDiv.style.top = y * scaleY + "px";
  2099. if (this.$textfield.multiline && this.$textfield.height > this.$textfield.size) {
  2100. this.inputDiv.style.top = (y) * scaleY + "px";
  2101. this.inputElement.style.top = (-this.$textfield.lineSpacing / 2) * scaleY + "px";
  2102. }
  2103. else {
  2104. this.inputDiv.style.top = y * scaleY + "px";
  2105. this.inputElement.style.top = 0 + "px";
  2106. }
  2107. var node = this.$textfield;
  2108. var cX = 1;
  2109. var cY = 1;
  2110. var rotation = 0;
  2111. while (node.parent) {
  2112. cX *= node.scaleX;
  2113. cY *= node.scaleY;
  2114. rotation += node.rotation;
  2115. node = node.parent;
  2116. }
  2117. var transformKey = egret.web.getPrefixStyleName("transform");
  2118. this.inputDiv.style[transformKey] = "rotate(" + rotation + "deg)";
  2119. this._gscaleX = scaleX * cX;
  2120. this._gscaleY = scaleY * cY;
  2121. };
  2122. /**
  2123. * @private
  2124. *
  2125. */
  2126. HTML5StageText.prototype.$show = function () {
  2127. if (!this.htmlInput.isCurrentStageText(this)) {
  2128. this.inputElement = this.htmlInput.getInputElement(this);
  2129. if (!this.$textfield.multiline) {
  2130. this.inputElement.type = this.$textfield.inputType;
  2131. }
  2132. else {
  2133. this.inputElement.type = "text";
  2134. }
  2135. this.inputDiv = this.htmlInput._inputDIV;
  2136. }
  2137. else {
  2138. this.inputElement.onblur = null;
  2139. }
  2140. this.htmlInput._needShow = true;
  2141. //标记当前文本被选中
  2142. this._isNeedShow = true;
  2143. this._initElement();
  2144. };
  2145. /**
  2146. * @private
  2147. *
  2148. */
  2149. HTML5StageText.prototype.onBlurHandler = function () {
  2150. this.htmlInput.clearInputElement();
  2151. window.scrollTo(0, 0);
  2152. };
  2153. /**
  2154. * @private
  2155. *
  2156. */
  2157. HTML5StageText.prototype.executeShow = function () {
  2158. var self = this;
  2159. //打开
  2160. this.inputElement.value = this.$getText();
  2161. if (this.inputElement.onblur == null) {
  2162. this.inputElement.onblur = this.onBlurHandler.bind(this);
  2163. }
  2164. this.$resetStageText();
  2165. if (this.$textfield.maxChars > 0) {
  2166. this.inputElement.setAttribute("maxlength", this.$textfield.maxChars);
  2167. }
  2168. else {
  2169. this.inputElement.removeAttribute("maxlength");
  2170. }
  2171. this.inputElement.selectionStart = this.inputElement.value.length;
  2172. this.inputElement.selectionEnd = this.inputElement.value.length;
  2173. this.inputElement.focus();
  2174. };
  2175. /**
  2176. * @private
  2177. */
  2178. HTML5StageText.prototype.$hide = function () {
  2179. if (this.htmlInput) {
  2180. this.htmlInput.disconnectStageText(this);
  2181. }
  2182. };
  2183. /**
  2184. * @private
  2185. *
  2186. * @returns
  2187. */
  2188. HTML5StageText.prototype.$getText = function () {
  2189. if (!this.textValue) {
  2190. this.textValue = "";
  2191. }
  2192. return this.textValue;
  2193. };
  2194. /**
  2195. * @private
  2196. *
  2197. * @param value
  2198. */
  2199. HTML5StageText.prototype.$setText = function (value) {
  2200. this.textValue = value;
  2201. this.resetText();
  2202. return true;
  2203. };
  2204. /**
  2205. * @private
  2206. *
  2207. */
  2208. HTML5StageText.prototype.resetText = function () {
  2209. if (this.inputElement) {
  2210. this.inputElement.value = this.textValue;
  2211. }
  2212. };
  2213. HTML5StageText.prototype.$setColor = function (value) {
  2214. this.colorValue = value;
  2215. this.resetColor();
  2216. return true;
  2217. };
  2218. /**
  2219. * @private
  2220. *
  2221. */
  2222. HTML5StageText.prototype.resetColor = function () {
  2223. if (this.inputElement) {
  2224. this.setElementStyle("color", egret.toColorString(this.colorValue));
  2225. }
  2226. };
  2227. HTML5StageText.prototype.$onBlur = function () {
  2228. };
  2229. /**
  2230. * @private
  2231. *
  2232. */
  2233. HTML5StageText.prototype._onInput = function () {
  2234. var self = this;
  2235. window.setTimeout(function () {
  2236. if (self.inputElement && self.inputElement.selectionStart == self.inputElement.selectionEnd) {
  2237. self.textValue = self.inputElement.value;
  2238. egret.Event.dispatchEvent(self, "updateText", false);
  2239. }
  2240. }, 0);
  2241. };
  2242. HTML5StageText.prototype.setAreaHeight = function () {
  2243. var textfield = this.$textfield;
  2244. if (textfield.multiline) {
  2245. var textheight = egret.TextFieldUtils.$getTextHeight(textfield);
  2246. if (textfield.height <= textfield.size) {
  2247. this.setElementStyle("height", (textfield.size) * this._gscaleY + "px");
  2248. this.setElementStyle("padding", "0px");
  2249. this.setElementStyle("lineHeight", (textfield.size) * this._gscaleY + "px");
  2250. }
  2251. else if (textfield.height < textheight) {
  2252. this.setElementStyle("height", (textfield.height) * this._gscaleY + "px");
  2253. this.setElementStyle("padding", "0px");
  2254. this.setElementStyle("lineHeight", (textfield.size + textfield.lineSpacing) * this._gscaleY + "px");
  2255. }
  2256. else {
  2257. this.setElementStyle("height", (textheight + textfield.lineSpacing) * this._gscaleY + "px");
  2258. var rap = (textfield.height - textheight) * this._gscaleY;
  2259. var valign = egret.TextFieldUtils.$getValign(textfield);
  2260. var top_1 = rap * valign;
  2261. var bottom = rap - top_1;
  2262. this.setElementStyle("padding", top_1 + "px 0px " + bottom + "px 0px");
  2263. this.setElementStyle("lineHeight", (textfield.size + textfield.lineSpacing) * this._gscaleY + "px");
  2264. }
  2265. }
  2266. };
  2267. /**
  2268. * @private
  2269. *
  2270. * @param e
  2271. */
  2272. HTML5StageText.prototype._onClickHandler = function (e) {
  2273. if (this._isNeedShow) {
  2274. e.stopImmediatePropagation();
  2275. //e.preventDefault();
  2276. this._isNeedShow = false;
  2277. this.executeShow();
  2278. this.dispatchEvent(new egret.Event("focus"));
  2279. }
  2280. };
  2281. /**
  2282. * @private
  2283. *
  2284. */
  2285. HTML5StageText.prototype._onDisconnect = function () {
  2286. this.inputElement = null;
  2287. this.dispatchEvent(new egret.Event("blur"));
  2288. };
  2289. /**
  2290. * @private
  2291. *
  2292. * @param style
  2293. * @param value
  2294. */
  2295. HTML5StageText.prototype.setElementStyle = function (style, value) {
  2296. if (this.inputElement) {
  2297. if (this._styleInfoes[style] != value) {
  2298. this.inputElement.style[style] = value;
  2299. //this._styleInfoes[style] = value;
  2300. }
  2301. }
  2302. };
  2303. /**
  2304. * @private
  2305. *
  2306. */
  2307. HTML5StageText.prototype.$removeFromStage = function () {
  2308. if (this.inputElement) {
  2309. this.htmlInput.disconnectStageText(this);
  2310. }
  2311. };
  2312. /**
  2313. * 修改位置
  2314. * @private
  2315. */
  2316. HTML5StageText.prototype.$resetStageText = function () {
  2317. if (this.inputElement) {
  2318. var textfield = this.$textfield;
  2319. this.setElementStyle("fontFamily", textfield.fontFamily);
  2320. this.setElementStyle("fontStyle", textfield.italic ? "italic" : "normal");
  2321. this.setElementStyle("fontWeight", textfield.bold ? "bold" : "normal");
  2322. this.setElementStyle("textAlign", textfield.textAlign);
  2323. this.setElementStyle("fontSize", textfield.size * this._gscaleY + "px");
  2324. this.setElementStyle("color", egret.toColorString(textfield.textColor));
  2325. var tw = void 0;
  2326. if (textfield.stage) {
  2327. tw = textfield.localToGlobal(0, 0).x;
  2328. tw = Math.min(textfield.width, textfield.stage.stageWidth - tw);
  2329. }
  2330. else {
  2331. tw = textfield.width;
  2332. }
  2333. this.setElementStyle("width", tw * this._gscaleX + "px");
  2334. this.setElementStyle("verticalAlign", textfield.verticalAlign);
  2335. if (textfield.multiline) {
  2336. this.setAreaHeight();
  2337. }
  2338. else {
  2339. this.setElementStyle("lineHeight", (textfield.size) * this._gscaleY + "px");
  2340. if (textfield.height < textfield.size) {
  2341. this.setElementStyle("height", (textfield.size) * this._gscaleY + "px");
  2342. var bottom = (textfield.size / 2) * this._gscaleY;
  2343. this.setElementStyle("padding", "0px 0px " + bottom + "px 0px");
  2344. }
  2345. else {
  2346. this.setElementStyle("height", (textfield.size) * this._gscaleY + "px");
  2347. var rap = (textfield.height - textfield.size) * this._gscaleY;
  2348. var valign = egret.TextFieldUtils.$getValign(textfield);
  2349. var top_2 = rap * valign;
  2350. var bottom = rap - top_2;
  2351. if (bottom < textfield.size / 2 * this._gscaleY) {
  2352. bottom = textfield.size / 2 * this._gscaleY;
  2353. }
  2354. this.setElementStyle("padding", top_2 + "px 0px " + bottom + "px 0px");
  2355. }
  2356. }
  2357. this.inputDiv.style.clip = "rect(0px " + (textfield.width * this._gscaleX) + "px " + (textfield.height * this._gscaleY) + "px 0px)";
  2358. this.inputDiv.style.height = textfield.height * this._gscaleY + "px";
  2359. this.inputDiv.style.width = tw * this._gscaleX + "px";
  2360. }
  2361. };
  2362. return HTML5StageText;
  2363. }(egret.EventDispatcher));
  2364. web.HTML5StageText = HTML5StageText;
  2365. __reflect(HTML5StageText.prototype, "egret.web.HTML5StageText", ["egret.StageText"]);
  2366. egret.StageText = HTML5StageText;
  2367. })(web = egret.web || (egret.web = {}));
  2368. })(egret || (egret = {}));
  2369. (function (egret) {
  2370. var web;
  2371. (function (web) {
  2372. /**
  2373. * @private
  2374. */
  2375. var HTMLInput = (function () {
  2376. function HTMLInput() {
  2377. /**
  2378. * @private
  2379. */
  2380. this._needShow = false;
  2381. /**
  2382. * @private
  2383. */
  2384. this.$scaleX = 1;
  2385. /**
  2386. * @private
  2387. */
  2388. this.$scaleY = 1;
  2389. }
  2390. /**
  2391. * @private
  2392. *
  2393. * @returns
  2394. */
  2395. HTMLInput.prototype.isInputOn = function () {
  2396. return this._stageText != null;
  2397. };
  2398. /**
  2399. * @private
  2400. *
  2401. * @param stageText
  2402. * @returns
  2403. */
  2404. HTMLInput.prototype.isCurrentStageText = function (stageText) {
  2405. return this._stageText == stageText;
  2406. };
  2407. /**
  2408. * @private
  2409. *
  2410. * @param dom
  2411. */
  2412. HTMLInput.prototype.initValue = function (dom) {
  2413. dom.style.position = "absolute";
  2414. dom.style.left = "0px";
  2415. dom.style.top = "0px";
  2416. dom.style.border = "none";
  2417. dom.style.padding = "0";
  2418. };
  2419. /**
  2420. * @private
  2421. *
  2422. */
  2423. HTMLInput.prototype.$updateSize = function () {
  2424. if (!this.canvas) {
  2425. return;
  2426. }
  2427. this.$scaleX = egret.sys.DisplayList.$canvasScaleX;
  2428. this.$scaleY = egret.sys.DisplayList.$canvasScaleY;
  2429. this.StageDelegateDiv.style.left = this.canvas.style.left;
  2430. this.StageDelegateDiv.style.top = this.canvas.style.top;
  2431. var transformKey = egret.web.getPrefixStyleName("transform");
  2432. this.StageDelegateDiv.style[transformKey] = this.canvas.style[transformKey];
  2433. this.StageDelegateDiv.style[egret.web.getPrefixStyleName("transformOrigin")] = "0% 0% 0px";
  2434. };
  2435. /**
  2436. * @private
  2437. *
  2438. * @param container
  2439. * @param canvas
  2440. * @returns
  2441. */
  2442. HTMLInput.prototype._initStageDelegateDiv = function (container, canvas) {
  2443. this.canvas = canvas;
  2444. var self = this;
  2445. var stageDelegateDiv;
  2446. if (!stageDelegateDiv) {
  2447. stageDelegateDiv = document.createElement("div");
  2448. this.StageDelegateDiv = stageDelegateDiv;
  2449. stageDelegateDiv.id = "StageDelegateDiv";
  2450. container.appendChild(stageDelegateDiv);
  2451. self.initValue(stageDelegateDiv);
  2452. self._inputDIV = document.createElement("div");
  2453. self.initValue(self._inputDIV);
  2454. self._inputDIV.style.width = "0px";
  2455. self._inputDIV.style.height = "0px";
  2456. self._inputDIV.style.left = 0 + "px";
  2457. self._inputDIV.style.top = "-100px";
  2458. self._inputDIV.style[egret.web.getPrefixStyleName("transformOrigin")] = "0% 0% 0px";
  2459. stageDelegateDiv.appendChild(self._inputDIV);
  2460. this.canvas.addEventListener("click", function (e) {
  2461. if (self._needShow) {
  2462. self._needShow = false;
  2463. self._stageText._onClickHandler(e);
  2464. self.show();
  2465. }
  2466. else {
  2467. if (self._inputElement) {
  2468. self.clearInputElement();
  2469. self._inputElement.blur();
  2470. self._inputElement = null;
  2471. }
  2472. }
  2473. });
  2474. self.initInputElement(true);
  2475. self.initInputElement(false);
  2476. }
  2477. };
  2478. //初始化输入框
  2479. HTMLInput.prototype.initInputElement = function (multiline) {
  2480. var self = this;
  2481. //增加1个空的textarea
  2482. var inputElement;
  2483. if (multiline) {
  2484. inputElement = document.createElement("textarea");
  2485. inputElement.style["resize"] = "none";
  2486. self._multiElement = inputElement;
  2487. inputElement.id = "egretTextarea";
  2488. }
  2489. else {
  2490. inputElement = document.createElement("input");
  2491. self._simpleElement = inputElement;
  2492. inputElement.id = "egretInput";
  2493. }
  2494. inputElement.type = "text";
  2495. self._inputDIV.appendChild(inputElement);
  2496. inputElement.setAttribute("tabindex", "-1");
  2497. inputElement.style.width = "1px";
  2498. inputElement.style.height = "12px";
  2499. self.initValue(inputElement);
  2500. inputElement.style.outline = "thin";
  2501. inputElement.style.background = "none";
  2502. inputElement.style.overflow = "hidden";
  2503. inputElement.style.wordBreak = "break-all";
  2504. //隐藏输入框
  2505. inputElement.style.opacity = 0;
  2506. inputElement.oninput = function () {
  2507. if (self._stageText) {
  2508. self._stageText._onInput();
  2509. }
  2510. };
  2511. };
  2512. /**
  2513. * @private
  2514. *
  2515. */
  2516. HTMLInput.prototype.show = function () {
  2517. var self = this;
  2518. var inputElement = self._inputElement;
  2519. //隐藏输入框
  2520. egret.$callAsync(function () {
  2521. inputElement.style.opacity = 1;
  2522. }, self);
  2523. };
  2524. /**
  2525. * @private
  2526. *
  2527. * @param stageText
  2528. */
  2529. HTMLInput.prototype.disconnectStageText = function (stageText) {
  2530. if (this._stageText == null || this._stageText == stageText) {
  2531. this.clearInputElement();
  2532. if (this._inputElement) {
  2533. this._inputElement.blur();
  2534. }
  2535. }
  2536. this._needShow = false;
  2537. };
  2538. /**
  2539. * @private
  2540. *
  2541. */
  2542. HTMLInput.prototype.clearInputElement = function () {
  2543. var self = this;
  2544. if (self._inputElement) {
  2545. self._inputElement.value = "";
  2546. self._inputElement.onblur = null;
  2547. self._inputElement.style.width = "1px";
  2548. self._inputElement.style.height = "12px";
  2549. self._inputElement.style.left = "0px";
  2550. self._inputElement.style.top = "0px";
  2551. self._inputElement.style.opacity = 0;
  2552. var otherElement = void 0;
  2553. if (self._simpleElement == self._inputElement) {
  2554. otherElement = self._multiElement;
  2555. }
  2556. else {
  2557. otherElement = self._simpleElement;
  2558. }
  2559. otherElement.style.display = "block";
  2560. self._inputDIV.style.left = 0 + "px";
  2561. self._inputDIV.style.top = "-100px";
  2562. self._inputDIV.style.height = 0 + "px";
  2563. self._inputDIV.style.width = 0 + "px";
  2564. }
  2565. if (self._stageText) {
  2566. self._stageText._onDisconnect();
  2567. self._stageText = null;
  2568. this.canvas['userTyping'] = false;
  2569. }
  2570. };
  2571. /**
  2572. * @private
  2573. *
  2574. * @param stageText
  2575. * @returns
  2576. */
  2577. HTMLInput.prototype.getInputElement = function (stageText) {
  2578. var self = this;
  2579. self.clearInputElement();
  2580. self._stageText = stageText;
  2581. this.canvas['userTyping'] = true;
  2582. if (self._stageText.$textfield.multiline) {
  2583. self._inputElement = self._multiElement;
  2584. }
  2585. else {
  2586. self._inputElement = self._simpleElement;
  2587. }
  2588. var otherElement;
  2589. if (self._simpleElement == self._inputElement) {
  2590. otherElement = self._multiElement;
  2591. }
  2592. else {
  2593. otherElement = self._simpleElement;
  2594. }
  2595. otherElement.style.display = "none";
  2596. return self._inputElement;
  2597. };
  2598. return HTMLInput;
  2599. }());
  2600. web.HTMLInput = HTMLInput;
  2601. __reflect(HTMLInput.prototype, "egret.web.HTMLInput");
  2602. })(web = egret.web || (egret.web = {}));
  2603. })(egret || (egret = {}));
  2604. (function (egret) {
  2605. var web;
  2606. (function (web) {
  2607. var stageToTextLayerMap = {};
  2608. var stageToCanvasMap = {};
  2609. var stageToContainerMap = {};
  2610. /**
  2611. * @private
  2612. * 获取
  2613. */
  2614. function $getTextAdapter(textfield) {
  2615. var stageHash = textfield.stage ? textfield.stage.$hashCode : 0;
  2616. var adapter = stageToTextLayerMap[stageHash];
  2617. var canvas = stageToCanvasMap[stageHash];
  2618. var container = stageToContainerMap[stageHash];
  2619. if (canvas && container) {
  2620. //adapter._initStageDelegateDiv(container, canvas);
  2621. //adapter.$updateSize();
  2622. delete stageToCanvasMap[stageHash];
  2623. delete stageToContainerMap[stageHash];
  2624. }
  2625. return adapter;
  2626. }
  2627. web.$getTextAdapter = $getTextAdapter;
  2628. /**
  2629. * @private
  2630. */
  2631. function $cacheTextAdapter(adapter, stage, container, canvas) {
  2632. adapter._initStageDelegateDiv(container, canvas);
  2633. stageToTextLayerMap[stage.$hashCode] = adapter;
  2634. stageToCanvasMap[stage.$hashCode] = canvas;
  2635. stageToContainerMap[stage.$hashCode] = container;
  2636. }
  2637. web.$cacheTextAdapter = $cacheTextAdapter;
  2638. })(web = egret.web || (egret.web = {}));
  2639. })(egret || (egret = {}));
  2640. //////////////////////////////////////////////////////////////////////////////////////
  2641. //
  2642. // Copyright (c) 2014-present, Egret Technology.
  2643. // All rights reserved.
  2644. // Redistribution and use in source and binary forms, with or without
  2645. // modification, are permitted provided that the following conditions are met:
  2646. //
  2647. // * Redistributions of source code must retain the above copyright
  2648. // notice, this list of conditions and the following disclaimer.
  2649. // * Redistributions in binary form must reproduce the above copyright
  2650. // notice, this list of conditions and the following disclaimer in the
  2651. // documentation and/or other materials provided with the distribution.
  2652. // * Neither the name of the Egret nor the
  2653. // names of its contributors may be used to endorse or promote products
  2654. // derived from this software without specific prior written permission.
  2655. //
  2656. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2657. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2658. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2659. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2660. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2661. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2662. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2663. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2664. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2665. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2666. //
  2667. //////////////////////////////////////////////////////////////////////////////////////
  2668. var egret;
  2669. (function (egret) {
  2670. var web;
  2671. (function (web) {
  2672. /**
  2673. * @private
  2674. */
  2675. var context = null;
  2676. /**
  2677. * @private
  2678. */
  2679. var fontCache = {};
  2680. /**
  2681. * 测量文本在指定样式下的宽度。
  2682. * @param text 要测量的文本内容。
  2683. * @param fontFamily 字体名称
  2684. * @param fontSize 字体大小
  2685. * @param bold 是否粗体
  2686. * @param italic 是否斜体
  2687. */
  2688. function measureText(text, fontFamily, fontSize, bold, italic) {
  2689. if (!context) {
  2690. createContext();
  2691. }
  2692. var font = "";
  2693. if (italic)
  2694. font += "italic ";
  2695. if (bold)
  2696. font += "bold ";
  2697. font += (fontSize || 12) + "px ";
  2698. font += (fontFamily || "Arial");
  2699. context.font = font;
  2700. return context.measureText(text).width;
  2701. }
  2702. /**
  2703. * @private
  2704. */
  2705. function createContext() {
  2706. context = egret.sys.canvasHitTestBuffer.context;
  2707. context.textAlign = "left";
  2708. context.textBaseline = "middle";
  2709. }
  2710. egret.sys.measureText = measureText;
  2711. })(web = egret.web || (egret.web = {}));
  2712. })(egret || (egret = {}));
  2713. //////////////////////////////////////////////////////////////////////////////////////
  2714. //
  2715. // Copyright (c) 2014-present, Egret Technology.
  2716. // All rights reserved.
  2717. // Redistribution and use in source and binary forms, with or without
  2718. // modification, are permitted provided that the following conditions are met:
  2719. //
  2720. // * Redistributions of source code must retain the above copyright
  2721. // notice, this list of conditions and the following disclaimer.
  2722. // * Redistributions in binary form must reproduce the above copyright
  2723. // notice, this list of conditions and the following disclaimer in the
  2724. // documentation and/or other materials provided with the distribution.
  2725. // * Neither the name of the Egret nor the
  2726. // names of its contributors may be used to endorse or promote products
  2727. // derived from this software without specific prior written permission.
  2728. //
  2729. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2730. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2731. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2732. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2733. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2734. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2735. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2736. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2737. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2738. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2739. //
  2740. //////////////////////////////////////////////////////////////////////////////////////
  2741. var egret;
  2742. (function (egret) {
  2743. var web;
  2744. (function (web) {
  2745. /**
  2746. * 创建一个canvas。
  2747. */
  2748. function createCanvas(width, height) {
  2749. var canvas = document.createElement("canvas");
  2750. if (!isNaN(width) && !isNaN(height)) {
  2751. canvas.width = width;
  2752. canvas.height = height;
  2753. }
  2754. var context = canvas.getContext("2d");
  2755. if (context["imageSmoothingEnabled"] === undefined) {
  2756. var keys = ["webkitImageSmoothingEnabled", "mozImageSmoothingEnabled", "msImageSmoothingEnabled"];
  2757. var key_1;
  2758. for (var i = keys.length - 1; i >= 0; i--) {
  2759. key_1 = keys[i];
  2760. if (context[key_1] !== void 0) {
  2761. break;
  2762. }
  2763. }
  2764. try {
  2765. Object.defineProperty(context, "imageSmoothingEnabled", {
  2766. get: function () {
  2767. return this[key_1];
  2768. },
  2769. set: function (value) {
  2770. this[key_1] = value;
  2771. }
  2772. });
  2773. }
  2774. catch (e) {
  2775. context["imageSmoothingEnabled"] = context[key_1];
  2776. }
  2777. }
  2778. return canvas;
  2779. }
  2780. var sharedCanvas;
  2781. /**
  2782. * @private
  2783. * Canvas2D渲染缓冲
  2784. */
  2785. var CanvasRenderBuffer = (function () {
  2786. function CanvasRenderBuffer(width, height, root) {
  2787. this.surface = createCanvas(width, height);
  2788. this.context = this.surface.getContext("2d");
  2789. if (this.context) {
  2790. this.context.$offsetX = 0;
  2791. this.context.$offsetY = 0;
  2792. }
  2793. }
  2794. Object.defineProperty(CanvasRenderBuffer.prototype, "width", {
  2795. /**
  2796. * 渲染缓冲的宽度,以像素为单位。
  2797. * @readOnly
  2798. */
  2799. get: function () {
  2800. return this.surface.width;
  2801. },
  2802. enumerable: true,
  2803. configurable: true
  2804. });
  2805. Object.defineProperty(CanvasRenderBuffer.prototype, "height", {
  2806. /**
  2807. * 渲染缓冲的高度,以像素为单位。
  2808. * @readOnly
  2809. */
  2810. get: function () {
  2811. return this.surface.height;
  2812. },
  2813. enumerable: true,
  2814. configurable: true
  2815. });
  2816. /**
  2817. * 改变渲染缓冲的大小并清空缓冲区
  2818. * @param width 改变后的宽
  2819. * @param height 改变后的高
  2820. * @param useMaxSize 若传入true,则将改变后的尺寸与已有尺寸对比,保留较大的尺寸。
  2821. */
  2822. CanvasRenderBuffer.prototype.resize = function (width, height, useMaxSize) {
  2823. var surface = this.surface;
  2824. if (useMaxSize) {
  2825. var change = false;
  2826. if (surface.width < width) {
  2827. surface.width = width;
  2828. change = true;
  2829. }
  2830. if (surface.height < height) {
  2831. surface.height = height;
  2832. change = true;
  2833. }
  2834. //尺寸没有变化时,将绘制属性重置
  2835. if (!change) {
  2836. this.context.globalCompositeOperation = "source-over";
  2837. this.context.setTransform(1, 0, 0, 1, 0, 0);
  2838. this.context.globalAlpha = 1;
  2839. }
  2840. }
  2841. else {
  2842. if (surface.width != width) {
  2843. surface.width = width;
  2844. }
  2845. if (surface.height != height) {
  2846. surface.height = height;
  2847. }
  2848. }
  2849. this.clear();
  2850. };
  2851. /**
  2852. * 获取指定区域的像素
  2853. */
  2854. CanvasRenderBuffer.prototype.getPixels = function (x, y, width, height) {
  2855. if (width === void 0) { width = 1; }
  2856. if (height === void 0) { height = 1; }
  2857. return this.context.getImageData(x, y, width, height).data;
  2858. };
  2859. /**
  2860. * 转换成base64字符串,如果图片(或者包含的图片)跨域,则返回null
  2861. * @param type 转换的类型,如: "image/png","image/jpeg"
  2862. */
  2863. CanvasRenderBuffer.prototype.toDataURL = function (type, encoderOptions) {
  2864. return this.surface.toDataURL(type, encoderOptions);
  2865. };
  2866. /**
  2867. * 清空缓冲区数据
  2868. */
  2869. CanvasRenderBuffer.prototype.clear = function () {
  2870. this.context.setTransform(1, 0, 0, 1, 0, 0);
  2871. this.context.clearRect(0, 0, this.surface.width, this.surface.height);
  2872. };
  2873. /**
  2874. * 销毁绘制对象
  2875. */
  2876. CanvasRenderBuffer.prototype.destroy = function () {
  2877. this.surface.width = this.surface.height = 0;
  2878. };
  2879. return CanvasRenderBuffer;
  2880. }());
  2881. web.CanvasRenderBuffer = CanvasRenderBuffer;
  2882. __reflect(CanvasRenderBuffer.prototype, "egret.web.CanvasRenderBuffer", ["egret.sys.RenderBuffer"]);
  2883. })(web = egret.web || (egret.web = {}));
  2884. })(egret || (egret = {}));
  2885. //////////////////////////////////////////////////////////////////////////////////////
  2886. //
  2887. // Copyright (c) 2014-present, Egret Technology.
  2888. // All rights reserved.
  2889. // Redistribution and use in source and binary forms, with or without
  2890. // modification, are permitted provided this the following conditions are met:
  2891. //
  2892. // * Redistributions of source code must retain the above copyright
  2893. // notice, this list of conditions and the following disclaimer.
  2894. // * Redistributions in binary form must reproduce the above copyright
  2895. // notice, this list of conditions and the following disclaimer in the
  2896. // documentation and/or other materials provided with the distribution.
  2897. // * Neither the name of the Egret nor the
  2898. // names of its contributors may be used to endorse or promote products
  2899. // derived from this software without specific prior written permission.
  2900. //
  2901. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2902. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2903. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2904. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2905. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2906. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2907. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2908. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2909. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2910. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2911. //
  2912. //////////////////////////////////////////////////////////////////////////////////////
  2913. var egret;
  2914. (function (egret) {
  2915. var web;
  2916. (function (web) {
  2917. /**
  2918. * @private
  2919. */
  2920. var WebTouchHandler = (function (_super) {
  2921. __extends(WebTouchHandler, _super);
  2922. /**
  2923. * @private
  2924. */
  2925. function WebTouchHandler(stage, canvas) {
  2926. var _this = _super.call(this) || this;
  2927. /**
  2928. * @private
  2929. */
  2930. _this.onTouchBegin = function (event) {
  2931. var location = _this.getLocation(event);
  2932. _this.touch.onTouchBegin(location.x, location.y, event.identifier);
  2933. };
  2934. _this.onMouseMove = function (event) {
  2935. if (event.buttons == 0) {
  2936. _this.onTouchEnd(event);
  2937. }
  2938. else {
  2939. _this.onTouchMove(event);
  2940. }
  2941. };
  2942. /**
  2943. * @private
  2944. */
  2945. _this.onTouchMove = function (event) {
  2946. var location = _this.getLocation(event);
  2947. _this.touch.onTouchMove(location.x, location.y, event.identifier);
  2948. };
  2949. /**
  2950. * @private
  2951. */
  2952. _this.onTouchEnd = function (event) {
  2953. var location = _this.getLocation(event);
  2954. _this.touch.onTouchEnd(location.x, location.y, event.identifier);
  2955. };
  2956. /**
  2957. * @private
  2958. */
  2959. _this.scaleX = 1;
  2960. /**
  2961. * @private
  2962. */
  2963. _this.scaleY = 1;
  2964. /**
  2965. * @private
  2966. */
  2967. _this.rotation = 0;
  2968. _this.canvas = canvas;
  2969. _this.touch = new egret.sys.TouchHandler(stage);
  2970. _this.addListeners();
  2971. return _this;
  2972. }
  2973. /**
  2974. * @private
  2975. * 添加事件监听
  2976. */
  2977. WebTouchHandler.prototype.addListeners = function () {
  2978. var _this = this;
  2979. if (window.navigator.msPointerEnabled) {
  2980. this.canvas.addEventListener("MSPointerDown", function (event) {
  2981. event.identifier = event.pointerId;
  2982. _this.onTouchBegin(event);
  2983. _this.prevent(event);
  2984. }, false);
  2985. this.canvas.addEventListener("MSPointerMove", function (event) {
  2986. event.identifier = event.pointerId;
  2987. _this.onTouchMove(event);
  2988. _this.prevent(event);
  2989. }, false);
  2990. this.canvas.addEventListener("MSPointerUp", function (event) {
  2991. event.identifier = event.pointerId;
  2992. _this.onTouchEnd(event);
  2993. _this.prevent(event);
  2994. }, false);
  2995. }
  2996. else {
  2997. if (!egret.Capabilities.isMobile) {
  2998. this.addMouseListener();
  2999. }
  3000. this.addTouchListener();
  3001. }
  3002. };
  3003. /**
  3004. * @private
  3005. *
  3006. */
  3007. WebTouchHandler.prototype.addMouseListener = function () {
  3008. this.canvas.addEventListener("mousedown", this.onTouchBegin);
  3009. this.canvas.addEventListener("mousemove", this.onMouseMove);
  3010. this.canvas.addEventListener("mouseup", this.onTouchEnd);
  3011. };
  3012. /**
  3013. * @private
  3014. *
  3015. */
  3016. WebTouchHandler.prototype.addTouchListener = function () {
  3017. var _this = this;
  3018. this.canvas.addEventListener("touchstart", function (event) {
  3019. var l = event.changedTouches.length;
  3020. for (var i = 0; i < l; i++) {
  3021. _this.onTouchBegin(event.changedTouches[i]);
  3022. }
  3023. _this.prevent(event);
  3024. }, false);
  3025. this.canvas.addEventListener("touchmove", function (event) {
  3026. var l = event.changedTouches.length;
  3027. for (var i = 0; i < l; i++) {
  3028. _this.onTouchMove(event.changedTouches[i]);
  3029. }
  3030. _this.prevent(event);
  3031. }, false);
  3032. this.canvas.addEventListener("touchend", function (event) {
  3033. var l = event.changedTouches.length;
  3034. for (var i = 0; i < l; i++) {
  3035. _this.onTouchEnd(event.changedTouches[i]);
  3036. }
  3037. _this.prevent(event);
  3038. }, false);
  3039. this.canvas.addEventListener("touchcancel", function (event) {
  3040. var l = event.changedTouches.length;
  3041. for (var i = 0; i < l; i++) {
  3042. _this.onTouchEnd(event.changedTouches[i]);
  3043. }
  3044. _this.prevent(event);
  3045. }, false);
  3046. };
  3047. /**
  3048. * @private
  3049. */
  3050. WebTouchHandler.prototype.prevent = function (event) {
  3051. event.stopPropagation();
  3052. if (event["isScroll"] != true && !this.canvas['userTyping']) {
  3053. event.preventDefault();
  3054. }
  3055. };
  3056. /**
  3057. * @private
  3058. */
  3059. WebTouchHandler.prototype.getLocation = function (event) {
  3060. event.identifier = +event.identifier || 0;
  3061. var doc = document.documentElement;
  3062. var box = this.canvas.getBoundingClientRect();
  3063. var left = box.left + window.pageXOffset - doc.clientLeft;
  3064. var top = box.top + window.pageYOffset - doc.clientTop;
  3065. var x = event.pageX - left, newx = x;
  3066. var y = event.pageY - top, newy = y;
  3067. if (this.rotation == 90) {
  3068. newx = y;
  3069. newy = box.width - x;
  3070. }
  3071. else if (this.rotation == -90) {
  3072. newx = box.height - y;
  3073. newy = x;
  3074. }
  3075. newx = newx / this.scaleX;
  3076. newy = newy / this.scaleY;
  3077. return egret.$TempPoint.setTo(Math.round(newx), Math.round(newy));
  3078. };
  3079. /**
  3080. * @private
  3081. * 更新屏幕当前的缩放比例,用于计算准确的点击位置。
  3082. * @param scaleX 水平方向的缩放比例。
  3083. * @param scaleY 垂直方向的缩放比例。
  3084. */
  3085. WebTouchHandler.prototype.updateScaleMode = function (scaleX, scaleY, rotation) {
  3086. this.scaleX = scaleX;
  3087. this.scaleY = scaleY;
  3088. this.rotation = rotation;
  3089. };
  3090. /**
  3091. * @private
  3092. * 更新同时触摸点的数量
  3093. */
  3094. WebTouchHandler.prototype.$updateMaxTouches = function () {
  3095. this.touch.$initMaxTouches();
  3096. };
  3097. return WebTouchHandler;
  3098. }(egret.HashObject));
  3099. web.WebTouchHandler = WebTouchHandler;
  3100. __reflect(WebTouchHandler.prototype, "egret.web.WebTouchHandler");
  3101. })(web = egret.web || (egret.web = {}));
  3102. })(egret || (egret = {}));
  3103. //////////////////////////////////////////////////////////////////////////////////////
  3104. //
  3105. // Copyright (c) 2014-present, Egret Technology.
  3106. // All rights reserved.
  3107. // Redistribution and use in source and binary forms, with or without
  3108. // modification, are permitted provided that the following conditions are met:
  3109. //
  3110. // * Redistributions of source code must retain the above copyright
  3111. // notice, this list of conditions and the following disclaimer.
  3112. // * Redistributions in binary form must reproduce the above copyright
  3113. // notice, this list of conditions and the following disclaimer in the
  3114. // documentation and/or other materials provided with the distribution.
  3115. // * Neither the name of the Egret nor the
  3116. // names of its contributors may be used to endorse or promote products
  3117. // derived from this software without specific prior written permission.
  3118. //
  3119. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3120. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3121. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3122. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3123. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3124. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3125. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3126. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3127. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3128. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3129. //
  3130. //////////////////////////////////////////////////////////////////////////////////////
  3131. var egret;
  3132. (function (egret) {
  3133. var web;
  3134. (function (web) {
  3135. /**
  3136. * @private
  3137. */
  3138. web.WebLifeCycleHandler = function (context) {
  3139. var handleVisibilityChange = function () {
  3140. if (!document[hidden]) {
  3141. context.resume();
  3142. }
  3143. else {
  3144. context.pause();
  3145. }
  3146. };
  3147. window.addEventListener("focus", context.resume, false);
  3148. window.addEventListener("blur", context.pause, false);
  3149. var hidden, visibilityChange;
  3150. if (typeof document.hidden !== "undefined") {
  3151. hidden = "hidden";
  3152. visibilityChange = "visibilitychange";
  3153. }
  3154. else if (typeof document["mozHidden"] !== "undefined") {
  3155. hidden = "mozHidden";
  3156. visibilityChange = "mozvisibilitychange";
  3157. }
  3158. else if (typeof document["msHidden"] !== "undefined") {
  3159. hidden = "msHidden";
  3160. visibilityChange = "msvisibilitychange";
  3161. }
  3162. else if (typeof document["webkitHidden"] !== "undefined") {
  3163. hidden = "webkitHidden";
  3164. visibilityChange = "webkitvisibilitychange";
  3165. }
  3166. else if (typeof document["oHidden"] !== "undefined") {
  3167. hidden = "oHidden";
  3168. visibilityChange = "ovisibilitychange";
  3169. }
  3170. if ("onpageshow" in window && "onpagehide" in window) {
  3171. window.addEventListener("pageshow", context.resume, false);
  3172. window.addEventListener("pagehide", context.pause, false);
  3173. }
  3174. if (hidden && visibilityChange) {
  3175. document.addEventListener(visibilityChange, handleVisibilityChange, false);
  3176. }
  3177. var ua = navigator.userAgent;
  3178. var isWX = /micromessenger/gi.test(ua);
  3179. var isQQBrowser = /mqq/ig.test(ua);
  3180. var isQQ = /mobile.*qq/gi.test(ua);
  3181. if (isQQ || isWX) {
  3182. isQQBrowser = false;
  3183. }
  3184. if (isQQBrowser) {
  3185. var browser = window["browser"] || {};
  3186. browser.execWebFn = browser.execWebFn || {};
  3187. browser.execWebFn.postX5GamePlayerMessage = function (event) {
  3188. var eventType = event.type;
  3189. if (eventType == "app_enter_background") {
  3190. context.pause();
  3191. }
  3192. else if (eventType == "app_enter_foreground") {
  3193. context.resume();
  3194. }
  3195. };
  3196. window["browser"] = browser;
  3197. }
  3198. };
  3199. })(web = egret.web || (egret.web = {}));
  3200. })(egret || (egret = {}));
  3201. //////////////////////////////////////////////////////////////////////////////////////
  3202. //
  3203. // Copyright (c) 2014-present, Egret Technology.
  3204. // All rights reserved.
  3205. // Redistribution and use in source and binary forms, with or without
  3206. // modification, are permitted provided that the following conditions are met:
  3207. //
  3208. // * Redistributions of source code must retain the above copyright
  3209. // notice, this list of conditions and the following disclaimer.
  3210. // * Redistributions in binary form must reproduce the above copyright
  3211. // notice, this list of conditions and the following disclaimer in the
  3212. // documentation and/or other materials provided with the distribution.
  3213. // * Neither the name of the Egret nor the
  3214. // names of its contributors may be used to endorse or promote products
  3215. // derived from this software without specific prior written permission.
  3216. //
  3217. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3218. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3219. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3220. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3221. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3222. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3223. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3224. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3225. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3226. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3227. //
  3228. //////////////////////////////////////////////////////////////////////////////////////
  3229. var egret;
  3230. (function (egret) {
  3231. var web;
  3232. (function (web) {
  3233. /**
  3234. * @private
  3235. */
  3236. var AudioType = (function () {
  3237. function AudioType() {
  3238. }
  3239. /**
  3240. * @private
  3241. */
  3242. AudioType.WEB_AUDIO = 2;
  3243. /**
  3244. * @private
  3245. */
  3246. AudioType.HTML5_AUDIO = 3;
  3247. return AudioType;
  3248. }());
  3249. web.AudioType = AudioType;
  3250. __reflect(AudioType.prototype, "egret.web.AudioType");
  3251. /**
  3252. * html5兼容性配置
  3253. * @private
  3254. */
  3255. var Html5Capatibility = (function (_super) {
  3256. __extends(Html5Capatibility, _super);
  3257. /**
  3258. * @private
  3259. */
  3260. function Html5Capatibility() {
  3261. return _super.call(this) || this;
  3262. }
  3263. /**
  3264. * @private
  3265. *
  3266. */
  3267. Html5Capatibility.$init = function () {
  3268. var ua = navigator.userAgent.toLowerCase();
  3269. Html5Capatibility.ua = ua;
  3270. Html5Capatibility._canUseBlob = false;
  3271. var canUseWebAudio = window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"];
  3272. if (canUseWebAudio) {
  3273. try {
  3274. //防止某些chrome版本创建异常问题
  3275. web.WebAudioDecode.ctx = new (window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"])();
  3276. }
  3277. catch (e) {
  3278. canUseWebAudio = false;
  3279. }
  3280. }
  3281. var audioType = Html5Capatibility._audioType;
  3282. var checkAudioType;
  3283. if ((audioType == AudioType.WEB_AUDIO && canUseWebAudio) || audioType == AudioType.HTML5_AUDIO) {
  3284. checkAudioType = false;
  3285. Html5Capatibility.setAudioType(audioType);
  3286. }
  3287. else {
  3288. checkAudioType = true;
  3289. Html5Capatibility.setAudioType(AudioType.HTML5_AUDIO);
  3290. }
  3291. if (ua.indexOf("android") >= 0) {
  3292. if (checkAudioType && canUseWebAudio) {
  3293. Html5Capatibility.setAudioType(AudioType.WEB_AUDIO);
  3294. }
  3295. }
  3296. else if (ua.indexOf("iphone") >= 0 || ua.indexOf("ipad") >= 0 || ua.indexOf("ipod") >= 0) {
  3297. if (Html5Capatibility.getIOSVersion() >= 7) {
  3298. Html5Capatibility._canUseBlob = true;
  3299. if (checkAudioType && canUseWebAudio) {
  3300. Html5Capatibility.setAudioType(AudioType.WEB_AUDIO);
  3301. }
  3302. }
  3303. }
  3304. var winURL = window["URL"] || window["webkitURL"];
  3305. if (!winURL) {
  3306. Html5Capatibility._canUseBlob = false;
  3307. }
  3308. if (ua.indexOf("egretnative") >= 0) {
  3309. Html5Capatibility.setAudioType(AudioType.HTML5_AUDIO);
  3310. Html5Capatibility._canUseBlob = true;
  3311. }
  3312. egret.Sound = Html5Capatibility._AudioClass;
  3313. };
  3314. Html5Capatibility.setAudioType = function (type) {
  3315. Html5Capatibility._audioType = type;
  3316. switch (type) {
  3317. case AudioType.WEB_AUDIO:
  3318. Html5Capatibility._AudioClass = egret.web.WebAudioSound;
  3319. break;
  3320. case AudioType.HTML5_AUDIO:
  3321. Html5Capatibility._AudioClass = egret.web.HtmlSound;
  3322. break;
  3323. }
  3324. };
  3325. /**
  3326. * @private
  3327. * 获取ios版本
  3328. * @returns {string}
  3329. */
  3330. Html5Capatibility.getIOSVersion = function () {
  3331. var matches = Html5Capatibility.ua.toLowerCase().match(/cpu [^\d]*\d.*like mac os x/);
  3332. if (!matches || matches.length == 0) {
  3333. return 0;
  3334. }
  3335. var value = matches[0];
  3336. return parseInt(value.match(/\d+(_\d)*/)[0]) || 0;
  3337. };
  3338. //当前浏览器版本是否支持blob
  3339. Html5Capatibility._canUseBlob = false;
  3340. //当前浏览器版本是否支持webaudio
  3341. Html5Capatibility._audioType = 0;
  3342. /**
  3343. * @private
  3344. */
  3345. Html5Capatibility.ua = "";
  3346. return Html5Capatibility;
  3347. }(egret.HashObject));
  3348. web.Html5Capatibility = Html5Capatibility;
  3349. __reflect(Html5Capatibility.prototype, "egret.web.Html5Capatibility");
  3350. /**
  3351. * @private
  3352. */
  3353. var currentPrefix = null;
  3354. /**
  3355. * @private
  3356. */
  3357. function getPrefixStyleName(name, element) {
  3358. var header = "";
  3359. if (element != null) {
  3360. header = getPrefix(name, element);
  3361. }
  3362. else {
  3363. if (currentPrefix == null) {
  3364. var tempStyle = document.createElement('div').style;
  3365. currentPrefix = getPrefix("transform", tempStyle);
  3366. }
  3367. header = currentPrefix;
  3368. }
  3369. if (header == "") {
  3370. return name;
  3371. }
  3372. return header + name.charAt(0).toUpperCase() + name.substring(1, name.length);
  3373. }
  3374. web.getPrefixStyleName = getPrefixStyleName;
  3375. /**
  3376. * @private
  3377. */
  3378. function getPrefix(name, element) {
  3379. if (name in element) {
  3380. return "";
  3381. }
  3382. name = name.charAt(0).toUpperCase() + name.substring(1, name.length);
  3383. var transArr = ["webkit", "ms", "Moz", "O"];
  3384. for (var i = 0; i < transArr.length; i++) {
  3385. var tempStyle = transArr[i] + name;
  3386. if (tempStyle in element) {
  3387. return transArr[i];
  3388. }
  3389. }
  3390. return "";
  3391. }
  3392. web.getPrefix = getPrefix;
  3393. })(web = egret.web || (egret.web = {}));
  3394. })(egret || (egret = {}));
  3395. //////////////////////////////////////////////////////////////////////////////////////
  3396. //
  3397. // Copyright (c) 2014-present, Egret Technology.
  3398. // All rights reserved.
  3399. // Redistribution and use in source and binary forms, with or without
  3400. // modification, are permitted provided that the following conditions are met:
  3401. //
  3402. // * Redistributions of source code must retain the above copyright
  3403. // notice, this list of conditions and the following disclaimer.
  3404. // * Redistributions in binary form must reproduce the above copyright
  3405. // notice, this list of conditions and the following disclaimer in the
  3406. // documentation and/or other materials provided with the distribution.
  3407. // * Neither the name of the Egret nor the
  3408. // names of its contributors may be used to endorse or promote products
  3409. // derived from this software without specific prior written permission.
  3410. //
  3411. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3412. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3413. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3414. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3415. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3416. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3417. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3418. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3419. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3420. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3421. //
  3422. //////////////////////////////////////////////////////////////////////////////////////
  3423. var egret;
  3424. (function (egret) {
  3425. var web;
  3426. (function (web) {
  3427. /**
  3428. * @private
  3429. * 刷新所有Egret播放器的显示区域尺寸。仅当使用外部JavaScript代码动态修改了Egret容器大小时,需要手动调用此方法刷新显示区域。
  3430. * 当网页尺寸发生改变时此方法会自动被调用。
  3431. */
  3432. function updateAllScreens() {
  3433. if (!isRunning) {
  3434. return;
  3435. }
  3436. var containerList = document.querySelectorAll(".egret-player");
  3437. var length = containerList.length;
  3438. for (var i = 0; i < length; i++) {
  3439. var container = containerList[i];
  3440. var player = container["egret-player"];
  3441. player.updateScreenSize();
  3442. }
  3443. }
  3444. var isRunning = false;
  3445. /**
  3446. * @private
  3447. * 网页加载完成,实例化页面中定义的Egret标签
  3448. */
  3449. function runEgret(options) {
  3450. if (isRunning) {
  3451. return;
  3452. }
  3453. isRunning = true;
  3454. if (!options) {
  3455. options = {};
  3456. }
  3457. var ua = navigator.userAgent.toLowerCase();
  3458. if (ua.indexOf("egretnative") >= 0 && ua.indexOf("egretwebview") == -1) {
  3459. egret.Capabilities["runtimeType" + ""] = egret.RuntimeType.RUNTIME2;
  3460. }
  3461. if (ua.indexOf("egretnative") >= 0 && egret.nativeRender) {
  3462. egret_native.addModuleCallback(function () {
  3463. web.Html5Capatibility.$init();
  3464. // WebGL上下文参数自定义
  3465. if (options.renderMode == "webgl") {
  3466. // WebGL抗锯齿默认关闭,提升PC及某些平台性能
  3467. var antialias = options.antialias;
  3468. web.WebGLRenderContext.antialias = !!antialias;
  3469. }
  3470. egret.sys.CanvasRenderBuffer = web.CanvasRenderBuffer;
  3471. setRenderMode(options.renderMode);
  3472. egret_native.nrSetRenderMode(2);
  3473. var canvasScaleFactor;
  3474. if (options.canvasScaleFactor) {
  3475. canvasScaleFactor = options.canvasScaleFactor;
  3476. }
  3477. else if (options.calculateCanvasScaleFactor) {
  3478. canvasScaleFactor = options.calculateCanvasScaleFactor(egret.sys.canvasHitTestBuffer.context);
  3479. }
  3480. else {
  3481. canvasScaleFactor = window.devicePixelRatio;
  3482. }
  3483. egret.sys.DisplayList.$canvasScaleFactor = canvasScaleFactor;
  3484. var ticker = egret.ticker;
  3485. startTicker(ticker);
  3486. if (options.screenAdapter) {
  3487. egret.sys.screenAdapter = options.screenAdapter;
  3488. }
  3489. else if (!egret.sys.screenAdapter) {
  3490. egret.sys.screenAdapter = new egret.sys.DefaultScreenAdapter();
  3491. }
  3492. var list = document.querySelectorAll(".egret-player");
  3493. var length = list.length;
  3494. for (var i = 0; i < length; i++) {
  3495. var container = list[i];
  3496. var player = new web.WebPlayer(container, options);
  3497. container["egret-player"] = player;
  3498. }
  3499. window.addEventListener("resize", function () {
  3500. if (isNaN(resizeTimer)) {
  3501. resizeTimer = window.setTimeout(doResize, 300);
  3502. }
  3503. });
  3504. }, null);
  3505. egret_native.initNativeRender();
  3506. }
  3507. else {
  3508. web.Html5Capatibility._audioType = options.audioType;
  3509. web.Html5Capatibility.$init();
  3510. var renderMode = options.renderMode;
  3511. // WebGL上下文参数自定义
  3512. if (renderMode == "webgl") {
  3513. // WebGL抗锯齿默认关闭,提升PC及某些平台性能
  3514. var antialias = options.antialias;
  3515. web.WebGLRenderContext.antialias = !!antialias;
  3516. // WebGLRenderContext.antialias = (typeof antialias == undefined) ? true : antialias;
  3517. }
  3518. egret.sys.CanvasRenderBuffer = web.CanvasRenderBuffer;
  3519. if (ua.indexOf("egretnative") >= 0 && renderMode != "webgl") {
  3520. egret.$warn(1051);
  3521. renderMode = "webgl";
  3522. }
  3523. setRenderMode(renderMode);
  3524. var canvasScaleFactor = void 0;
  3525. if (options.canvasScaleFactor) {
  3526. canvasScaleFactor = options.canvasScaleFactor;
  3527. }
  3528. else if (options.calculateCanvasScaleFactor) {
  3529. canvasScaleFactor = options.calculateCanvasScaleFactor(egret.sys.canvasHitTestBuffer.context);
  3530. }
  3531. else {
  3532. //based on : https://github.com/jondavidjohn/hidpi-canvas-polyfill
  3533. var context = egret.sys.canvasHitTestBuffer.context;
  3534. var backingStore = context.backingStorePixelRatio ||
  3535. context.webkitBackingStorePixelRatio ||
  3536. context.mozBackingStorePixelRatio ||
  3537. context.msBackingStorePixelRatio ||
  3538. context.oBackingStorePixelRatio ||
  3539. context.backingStorePixelRatio || 1;
  3540. canvasScaleFactor = (window.devicePixelRatio || 1) / backingStore;
  3541. }
  3542. egret.sys.DisplayList.$canvasScaleFactor = canvasScaleFactor;
  3543. var ticker_1 = egret.ticker;
  3544. startTicker(ticker_1);
  3545. if (options.screenAdapter) {
  3546. egret.sys.screenAdapter = options.screenAdapter;
  3547. }
  3548. else if (!egret.sys.screenAdapter) {
  3549. egret.sys.screenAdapter = new egret.sys.DefaultScreenAdapter();
  3550. }
  3551. var list = document.querySelectorAll(".egret-player");
  3552. var length_2 = list.length;
  3553. for (var i = 0; i < length_2; i++) {
  3554. var container = list[i];
  3555. var player = new web.WebPlayer(container, options);
  3556. container["egret-player"] = player;
  3557. }
  3558. window.addEventListener("resize", function () {
  3559. if (isNaN(resizeTimer)) {
  3560. resizeTimer = window.setTimeout(doResize, 300);
  3561. }
  3562. });
  3563. }
  3564. }
  3565. /**
  3566. * 设置渲染模式。"auto","webgl","canvas"
  3567. * @param renderMode
  3568. */
  3569. function setRenderMode(renderMode) {
  3570. if (renderMode == "webgl" && egret.WebGLUtils.checkCanUseWebGL()) {
  3571. egret.sys.RenderBuffer = web.WebGLRenderBuffer;
  3572. egret.sys.systemRenderer = new web.WebGLRenderer();
  3573. egret.sys.canvasRenderer = new egret.CanvasRenderer();
  3574. egret.sys.customHitTestBuffer = new web.WebGLRenderBuffer(3, 3);
  3575. egret.sys.canvasHitTestBuffer = new web.CanvasRenderBuffer(3, 3);
  3576. egret.Capabilities["renderMode" + ""] = "webgl";
  3577. }
  3578. else {
  3579. egret.sys.RenderBuffer = web.CanvasRenderBuffer;
  3580. egret.sys.systemRenderer = new egret.CanvasRenderer();
  3581. egret.sys.canvasRenderer = egret.sys.systemRenderer;
  3582. egret.sys.customHitTestBuffer = new web.CanvasRenderBuffer(3, 3);
  3583. egret.sys.canvasHitTestBuffer = egret.sys.customHitTestBuffer;
  3584. egret.Capabilities["renderMode" + ""] = "canvas";
  3585. }
  3586. }
  3587. /**
  3588. * @private
  3589. * 启动心跳计时器。
  3590. */
  3591. function startTicker(ticker) {
  3592. var requestAnimationFrame = window["requestAnimationFrame"] ||
  3593. window["webkitRequestAnimationFrame"] ||
  3594. window["mozRequestAnimationFrame"] ||
  3595. window["oRequestAnimationFrame"] ||
  3596. window["msRequestAnimationFrame"];
  3597. if (!requestAnimationFrame) {
  3598. requestAnimationFrame = function (callback) {
  3599. return window.setTimeout(callback, 1000 / 60);
  3600. };
  3601. }
  3602. requestAnimationFrame(onTick);
  3603. function onTick() {
  3604. ticker.update();
  3605. requestAnimationFrame(onTick);
  3606. }
  3607. }
  3608. //覆盖原生的isNaN()方法实现,在不同浏览器上有2~10倍性能提升。
  3609. window["isNaN"] = function (value) {
  3610. value = +value;
  3611. return value !== value;
  3612. };
  3613. egret.runEgret = runEgret;
  3614. egret.updateAllScreens = updateAllScreens;
  3615. var resizeTimer = NaN;
  3616. function doResize() {
  3617. resizeTimer = NaN;
  3618. egret.updateAllScreens();
  3619. }
  3620. })(web = egret.web || (egret.web = {}));
  3621. })(egret || (egret = {}));
  3622. if (true) {
  3623. var language = navigator.language || navigator["browserLanguage"] || "en_US";
  3624. language = language.replace("-", "_");
  3625. if (language in egret.$locale_strings)
  3626. egret.$language = language;
  3627. }
  3628. //////////////////////////////////////////////////////////////////////////////////////
  3629. //
  3630. // Copyright (c) 2014-present, Egret Technology.
  3631. // All rights reserved.
  3632. // Redistribution and use in source and binary forms, with or without
  3633. // modification, are permitted provided that the following conditions are met:
  3634. //
  3635. // * Redistributions of source code must retain the above copyright
  3636. // notice, this list of conditions and the following disclaimer.
  3637. // * Redistributions in binary form must reproduce the above copyright
  3638. // notice, this list of conditions and the following disclaimer in the
  3639. // documentation and/or other materials provided with the distribution.
  3640. // * Neither the name of the Egret nor the
  3641. // names of its contributors may be used to endorse or promote products
  3642. // derived from this software without specific prior written permission.
  3643. //
  3644. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3645. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3646. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3647. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3648. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3649. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3650. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3651. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3652. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3653. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3654. //
  3655. //////////////////////////////////////////////////////////////////////////////////////
  3656. var egret;
  3657. (function (egret) {
  3658. var web;
  3659. (function (web) {
  3660. /**
  3661. * @private
  3662. */
  3663. var WebCapability = (function () {
  3664. function WebCapability() {
  3665. }
  3666. /**
  3667. * @private
  3668. * 检测系统属性
  3669. */
  3670. WebCapability.detect = function () {
  3671. var capabilities = egret.Capabilities;
  3672. var ua = navigator.userAgent.toLowerCase();
  3673. capabilities["isMobile" + ""] = (ua.indexOf('mobile') != -1 || ua.indexOf('android') != -1);
  3674. if (capabilities.isMobile) {
  3675. if (ua.indexOf("windows") < 0 && (ua.indexOf("iphone") != -1 || ua.indexOf("ipad") != -1 || ua.indexOf("ipod") != -1)) {
  3676. capabilities["os" + ""] = "iOS";
  3677. }
  3678. else if (ua.indexOf("android") != -1 && ua.indexOf("linux") != -1) {
  3679. capabilities["os" + ""] = "Android";
  3680. }
  3681. else if (ua.indexOf("windows") != -1) {
  3682. capabilities["os" + ""] = "Windows Phone";
  3683. }
  3684. }
  3685. else {
  3686. if (ua.indexOf("windows nt") != -1) {
  3687. capabilities["os" + ""] = "Windows PC";
  3688. }
  3689. else if (ua.indexOf("mac os") != -1) {
  3690. capabilities["os" + ""] = "Mac OS";
  3691. }
  3692. }
  3693. var language = (navigator.language || navigator["browserLanguage"]).toLowerCase();
  3694. var strings = language.split("-");
  3695. if (strings.length > 1) {
  3696. strings[1] = strings[1].toUpperCase();
  3697. }
  3698. capabilities["language" + ""] = strings.join("-");
  3699. WebCapability.injectUIntFixOnIE9();
  3700. };
  3701. WebCapability.injectUIntFixOnIE9 = function () {
  3702. if (/msie 9.0/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
  3703. var IEBinaryToArray_ByteStr_Script = "<!-- IEBinaryToArray_ByteStr -->\r\n" +
  3704. "<script type='text/vbscript' language='VBScript'>\r\n" +
  3705. "Function IEBinaryToArray_ByteStr(Binary)\r\n" +
  3706. " IEBinaryToArray_ByteStr = CStr(Binary)\r\n" +
  3707. "End Function\r\n" +
  3708. "Function IEBinaryToArray_ByteStr_Last(Binary)\r\n" +
  3709. " Dim lastIndex\r\n" +
  3710. " lastIndex = LenB(Binary)\r\n" +
  3711. " if lastIndex mod 2 Then\r\n" +
  3712. " IEBinaryToArray_ByteStr_Last = Chr( AscB( MidB( Binary, lastIndex, 1 ) ) )\r\n" +
  3713. " Else\r\n" +
  3714. " IEBinaryToArray_ByteStr_Last = " + '""' + "\r\n" +
  3715. " End If\r\n" +
  3716. "End Function\r\n" + "<\/script>\r\n" +
  3717. "<!-- convertResponseBodyToText -->\r\n" +
  3718. "<script>\r\n" +
  3719. "let convertResponseBodyToText = function (binary) {\r\n" +
  3720. " let byteMapping = {};\r\n" +
  3721. " for ( let i = 0; i < 256; i++ ) {\r\n" +
  3722. " for ( let j = 0; j < 256; j++ ) {\r\n" +
  3723. " byteMapping[ String.fromCharCode( i + j * 256 ) ] =\r\n" +
  3724. " String.fromCharCode(i) + String.fromCharCode(j);\r\n" +
  3725. " }\r\n" +
  3726. " }\r\n" +
  3727. " let rawBytes = IEBinaryToArray_ByteStr(binary);\r\n" +
  3728. " let lastChr = IEBinaryToArray_ByteStr_Last(binary);\r\n" +
  3729. " return rawBytes.replace(/[\\s\\S]/g," +
  3730. " function( match ) { return byteMapping[match]; }) + lastChr;\r\n" +
  3731. "};\r\n" +
  3732. "<\/script>\r\n";
  3733. document.write(IEBinaryToArray_ByteStr_Script);
  3734. }
  3735. };
  3736. return WebCapability;
  3737. }());
  3738. web.WebCapability = WebCapability;
  3739. __reflect(WebCapability.prototype, "egret.web.WebCapability");
  3740. WebCapability.detect();
  3741. })(web = egret.web || (egret.web = {}));
  3742. })(egret || (egret = {}));
  3743. //////////////////////////////////////////////////////////////////////////////////////
  3744. //
  3745. // Copyright (c) 2014-present, Egret Technology.
  3746. // All rights reserved.
  3747. // Redistribution and use in source and binary forms, with or without
  3748. // modification, are permitted provided that the following conditions are met:
  3749. //
  3750. // * Redistributions of source code must retain the above copyright
  3751. // notice, this list of conditions and the following disclaimer.
  3752. // * Redistributions in binary form must reproduce the above copyright
  3753. // notice, this list of conditions and the following disclaimer in the
  3754. // documentation and/or other materials provided with the distribution.
  3755. // * Neither the name of the Egret nor the
  3756. // names of its contributors may be used to endorse or promote products
  3757. // derived from this software without specific prior written permission.
  3758. //
  3759. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3760. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3761. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3762. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3763. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3764. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3765. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3766. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3767. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3768. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3769. //
  3770. //////////////////////////////////////////////////////////////////////////////////////
  3771. var egret;
  3772. (function (egret) {
  3773. var web;
  3774. (function (web) {
  3775. /**
  3776. * @private
  3777. */
  3778. var WebFps = (function () {
  3779. function WebFps(stage, showFPS, showLog, logFilter, styles) {
  3780. this.showPanle = true;
  3781. this.fpsHeight = 0;
  3782. this.WIDTH = 101;
  3783. this.HEIGHT = 20;
  3784. this.bgCanvasColor = "#18304b";
  3785. this.fpsFrontColor = "#18fefe";
  3786. this.WIDTH_COST = 50;
  3787. this.cost1Color = "#18fefe";
  3788. // private cost2Color = "#ffff00";
  3789. this.cost3Color = "#ff0000";
  3790. this.arrFps = [];
  3791. this.arrCost = [];
  3792. this.arrLog = [];
  3793. if (showFPS || showLog) {
  3794. if (egret.Capabilities.renderMode == 'canvas') {
  3795. this.renderMode = "Canvas";
  3796. }
  3797. else {
  3798. this.renderMode = "WebGL";
  3799. }
  3800. this.panelX = styles["x"] === undefined ? 0 : parseInt(styles['x']);
  3801. this.panelY = styles["y"] === undefined ? 0 : parseInt(styles['y']);
  3802. this.fontColor = styles["textColor"] === undefined ? '#ffffff' : styles['textColor'].replace("0x", "#");
  3803. this.fontSize = styles["size"] === undefined ? 12 : parseInt(styles['size']);
  3804. if (egret.Capabilities.isMobile) {
  3805. this.fontSize -= 2;
  3806. }
  3807. var all = document.createElement('div');
  3808. all.style.position = 'absolute';
  3809. all.style.background = "rgba(0,0,0," + styles['bgAlpha'] + ")";
  3810. all.style.left = this.panelX + 'px';
  3811. all.style.top = this.panelY + 'px';
  3812. all.style.pointerEvents = 'none';
  3813. document.body.appendChild(all);
  3814. var container = document.createElement('div');
  3815. container.style.color = this.fontColor;
  3816. container.style.fontSize = this.fontSize + 'px';
  3817. container.style.lineHeight = this.fontSize + 'px';
  3818. container.style.margin = '4px 4px 4px 4px';
  3819. this.container = container;
  3820. all.appendChild(container);
  3821. if (showFPS)
  3822. this.addFps();
  3823. if (showLog)
  3824. this.addLog();
  3825. }
  3826. }
  3827. WebFps.prototype.addFps = function () {
  3828. var div = document.createElement('div');
  3829. div.style.display = 'inline-block';
  3830. this.containerFps = div;
  3831. this.container.appendChild(div);
  3832. var fps = document.createElement('div');
  3833. fps.style.paddingBottom = '2px';
  3834. this.fps = fps;
  3835. this.containerFps.appendChild(fps);
  3836. fps.innerHTML = "0 FPS " + this.renderMode + "<br/>min0 max0 avg0";
  3837. var canvas = document.createElement('canvas');
  3838. this.containerFps.appendChild(canvas);
  3839. canvas.width = this.WIDTH;
  3840. canvas.height = this.HEIGHT;
  3841. this.canvasFps = canvas;
  3842. var context = canvas.getContext('2d');
  3843. this.contextFps = context;
  3844. context.fillStyle = this.bgCanvasColor;
  3845. context.fillRect(0, 0, this.WIDTH, this.HEIGHT);
  3846. var divDatas = document.createElement('div');
  3847. this.divDatas = divDatas;
  3848. this.containerFps.appendChild(divDatas);
  3849. var left = document.createElement('div');
  3850. left.style['float'] = 'left';
  3851. left.innerHTML = "Draw<br/>Cost";
  3852. divDatas.appendChild(left);
  3853. var right = document.createElement('div');
  3854. right.style.paddingLeft = left.offsetWidth + 20 + "px";
  3855. divDatas.appendChild(right);
  3856. var draw = document.createElement('div');
  3857. this.divDraw = draw;
  3858. draw.innerHTML = "0<br/>";
  3859. right.appendChild(draw);
  3860. var cost = document.createElement('div');
  3861. this.divCost = cost;
  3862. cost.innerHTML = "<font style=\"color:" + this.cost1Color + "\">0<font/> <font style=\"color:" + this.cost3Color + "\">0<font/>";
  3863. right.appendChild(cost);
  3864. canvas = document.createElement('canvas');
  3865. this.canvasCost = canvas;
  3866. this.containerFps.appendChild(canvas);
  3867. canvas.width = this.WIDTH;
  3868. canvas.height = this.HEIGHT;
  3869. context = canvas.getContext('2d');
  3870. this.contextCost = context;
  3871. context.fillStyle = this.bgCanvasColor;
  3872. context.fillRect(0, 0, this.WIDTH, this.HEIGHT);
  3873. context.fillStyle = "#000000";
  3874. context.fillRect(this.WIDTH_COST, 0, 1, this.HEIGHT);
  3875. this.fpsHeight = this.container.offsetHeight;
  3876. };
  3877. WebFps.prototype.addLog = function () {
  3878. var log = document.createElement('div');
  3879. log.style.maxWidth = document.body.clientWidth - 8 - this.panelX + 'px';
  3880. log.style.wordWrap = "break-word";
  3881. this.log = log;
  3882. this.container.appendChild(log);
  3883. };
  3884. WebFps.prototype.update = function (datas, showLastData) {
  3885. if (showLastData === void 0) { showLastData = false; }
  3886. var numFps;
  3887. var numCostTicker;
  3888. var numCostRender;
  3889. if (!showLastData) {
  3890. numFps = datas.fps;
  3891. numCostTicker = datas.costTicker;
  3892. numCostRender = datas.costRender;
  3893. this.lastNumDraw = datas.draw;
  3894. this.arrFps.push(numFps);
  3895. this.arrCost.push([numCostTicker, numCostRender]);
  3896. }
  3897. else {
  3898. numFps = this.arrFps[this.arrFps.length - 1];
  3899. numCostTicker = this.arrCost[this.arrCost.length - 1][0];
  3900. numCostRender = this.arrCost[this.arrCost.length - 1][1];
  3901. }
  3902. var fpsTotal = 0;
  3903. var lenFps = this.arrFps.length;
  3904. if (lenFps > 101) {
  3905. lenFps = 101;
  3906. this.arrFps.shift();
  3907. this.arrCost.shift();
  3908. }
  3909. var fpsMin = this.arrFps[0];
  3910. var fpsMax = this.arrFps[0];
  3911. for (var i = 0; i < lenFps; i++) {
  3912. var num = this.arrFps[i];
  3913. fpsTotal += num;
  3914. if (num < fpsMin)
  3915. fpsMin = num;
  3916. else if (num > fpsMax)
  3917. fpsMax = num;
  3918. }
  3919. var WIDTH = this.WIDTH;
  3920. var HEIGHT = this.HEIGHT;
  3921. var context = this.contextFps;
  3922. context.drawImage(this.canvasFps, 1, 0, WIDTH - 1, HEIGHT, 0, 0, WIDTH - 1, HEIGHT);
  3923. context.fillStyle = this.bgCanvasColor;
  3924. context.fillRect(WIDTH - 1, 0, 1, HEIGHT);
  3925. var lastHeight = Math.floor(numFps / 60 * 20);
  3926. if (lastHeight < 1)
  3927. lastHeight = 1;
  3928. context.fillStyle = this.fpsFrontColor;
  3929. context.fillRect(WIDTH - 1, 20 - lastHeight, 1, lastHeight);
  3930. var WIDTH_COST = this.WIDTH_COST;
  3931. context = this.contextCost;
  3932. context.drawImage(this.canvasCost, 1, 0, WIDTH_COST - 1, HEIGHT, 0, 0, WIDTH_COST - 1, HEIGHT);
  3933. context.drawImage(this.canvasCost, WIDTH_COST + 2, 0, WIDTH_COST - 1, HEIGHT, WIDTH_COST + 1, 0, WIDTH_COST - 1, HEIGHT);
  3934. var c1Height = Math.floor(numCostTicker / 2);
  3935. if (c1Height < 1)
  3936. c1Height = 1;
  3937. else if (c1Height > 20)
  3938. c1Height = 20;
  3939. //todo lcj
  3940. var c2Height = Math.floor(numCostRender / 2);
  3941. if (c2Height < 1)
  3942. c2Height = 1;
  3943. else if (c2Height > 20)
  3944. c2Height = 20;
  3945. context.fillStyle = this.bgCanvasColor;
  3946. context.fillRect(WIDTH_COST - 1, 0, 1, HEIGHT);
  3947. context.fillRect(WIDTH_COST * 2, 0, 1, HEIGHT);
  3948. context.fillRect(WIDTH_COST * 3 + 1, 0, 1, HEIGHT);
  3949. context.fillStyle = this.cost1Color;
  3950. context.fillRect(WIDTH_COST - 1, 20 - c1Height, 1, c1Height);
  3951. context.fillStyle = this.cost3Color;
  3952. context.fillRect(WIDTH_COST * 2, 20 - c2Height, 1, c2Height);
  3953. var fpsAvg = Math.floor(fpsTotal / lenFps);
  3954. var fpsOutput = numFps + " FPS " + this.renderMode;
  3955. if (this.showPanle) {
  3956. fpsOutput += "<br/>min" + fpsMin + " max" + fpsMax + " avg" + fpsAvg;
  3957. this.divDraw.innerHTML = this.lastNumDraw + "<br/>";
  3958. this.divCost.innerHTML = "<font style=\"color:#18fefe\">" + numCostTicker + "<font/> <font style=\"color:#ff0000\">" + numCostRender + "<font/>";
  3959. }
  3960. this.fps.innerHTML = fpsOutput;
  3961. };
  3962. ;
  3963. WebFps.prototype.updateInfo = function (info) {
  3964. this.arrLog.push(info);
  3965. this.updateLogLayout();
  3966. };
  3967. WebFps.prototype.updateWarn = function (info) {
  3968. this.arrLog.push("[Warning]" + info);
  3969. this.updateLogLayout();
  3970. };
  3971. WebFps.prototype.updateError = function (info) {
  3972. this.arrLog.push("[Error]" + info);
  3973. this.updateLogLayout();
  3974. };
  3975. WebFps.prototype.updateLogLayout = function () {
  3976. this.log.innerHTML = this.arrLog.join('<br/>');
  3977. while (document.body.clientHeight < (this.log.offsetHeight + this.fpsHeight + this.panelY + this.fontSize * 2)) {
  3978. this.arrLog.shift();
  3979. this.log.innerHTML = this.arrLog.join('<br/>');
  3980. }
  3981. };
  3982. return WebFps;
  3983. }());
  3984. web.WebFps = WebFps;
  3985. __reflect(WebFps.prototype, "egret.web.WebFps", ["egret.FPSDisplay"]);
  3986. egret.FPSDisplay = WebFps;
  3987. })(web = egret.web || (egret.web = {}));
  3988. })(egret || (egret = {}));
  3989. //////////////////////////////////////////////////////////////////////////////////////
  3990. //
  3991. // Copyright (c) 2014-present, Egret Technology.
  3992. // All rights reserved.
  3993. // Redistribution and use in source and binary forms, with or without
  3994. // modification, are permitted provided that the following conditions are met:
  3995. //
  3996. // * Redistributions of source code must retain the above copyright
  3997. // notice, this list of conditions and the following disclaimer.
  3998. // * Redistributions in binary form must reproduce the above copyright
  3999. // notice, this list of conditions and the following disclaimer in the
  4000. // documentation and/or other materials provided with the distribution.
  4001. // * Neither the name of the Egret nor the
  4002. // names of its contributors may be used to endorse or promote products
  4003. // derived from this software without specific prior written permission.
  4004. //
  4005. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4006. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4007. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4008. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4009. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4010. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4011. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4012. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4013. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4014. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4015. //
  4016. //////////////////////////////////////////////////////////////////////////////////////
  4017. var egret;
  4018. (function (egret) {
  4019. var localStorage;
  4020. (function (localStorage) {
  4021. var web;
  4022. (function (web) {
  4023. /**
  4024. * @private
  4025. *
  4026. * @param key
  4027. * @returns
  4028. */
  4029. function getItem(key) {
  4030. return window.localStorage.getItem(key);
  4031. }
  4032. /**
  4033. * @private
  4034. *
  4035. * @param key
  4036. * @param value
  4037. * @returns
  4038. */
  4039. function setItem(key, value) {
  4040. try {
  4041. window.localStorage.setItem(key, value);
  4042. return true;
  4043. }
  4044. catch (e) {
  4045. egret.$warn(1047, key, value);
  4046. return false;
  4047. }
  4048. }
  4049. /**
  4050. * @private
  4051. *
  4052. * @param key
  4053. */
  4054. function removeItem(key) {
  4055. window.localStorage.removeItem(key);
  4056. }
  4057. /**
  4058. * @private
  4059. *
  4060. */
  4061. function clear() {
  4062. window.localStorage.clear();
  4063. }
  4064. localStorage.getItem = getItem;
  4065. localStorage.setItem = setItem;
  4066. localStorage.removeItem = removeItem;
  4067. localStorage.clear = clear;
  4068. })(web = localStorage.web || (localStorage.web = {}));
  4069. })(localStorage = egret.localStorage || (egret.localStorage = {}));
  4070. })(egret || (egret = {}));
  4071. //////////////////////////////////////////////////////////////////////////////////////
  4072. //
  4073. // Copyright (c) 2014-present, Egret Technology.
  4074. // All rights reserved.
  4075. // Redistribution and use in source and binary forms, with or without
  4076. // modification, are permitted provided that the following conditions are met:
  4077. //
  4078. // * Redistributions of source code must retain the above copyright
  4079. // notice, this list of conditions and the following disclaimer.
  4080. // * Redistributions in binary form must reproduce the above copyright
  4081. // notice, this list of conditions and the following disclaimer in the
  4082. // documentation and/or other materials provided with the distribution.
  4083. // * Neither the name of the Egret nor the
  4084. // names of its contributors may be used to endorse or promote products
  4085. // derived from this software without specific prior written permission.
  4086. //
  4087. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4088. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4089. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4090. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4091. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4092. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4093. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4094. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4095. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4096. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4097. //
  4098. //////////////////////////////////////////////////////////////////////////////////////
  4099. var egret;
  4100. (function (egret) {
  4101. var web;
  4102. (function (web) {
  4103. /**
  4104. * @private
  4105. */
  4106. var WebPlayer = (function (_super) {
  4107. __extends(WebPlayer, _super);
  4108. function WebPlayer(container, options) {
  4109. var _this = _super.call(this) || this;
  4110. _this.init(container, options);
  4111. _this.initOrientation();
  4112. return _this;
  4113. }
  4114. WebPlayer.prototype.init = function (container, options) {
  4115. var option = this.readOption(container, options);
  4116. var stage = new egret.Stage();
  4117. stage.$screen = this;
  4118. stage.$scaleMode = option.scaleMode;
  4119. stage.$orientation = option.orientation;
  4120. stage.$maxTouches = option.maxTouches;
  4121. stage.frameRate = option.frameRate;
  4122. stage.textureScaleFactor = option.textureScaleFactor;
  4123. var buffer = new egret.sys.RenderBuffer(undefined, undefined, true);
  4124. var canvas = buffer.surface;
  4125. this.attachCanvas(container, canvas);
  4126. var webTouch = new web.WebTouchHandler(stage, canvas);
  4127. var player = new egret.sys.Player(buffer, stage, option.entryClassName);
  4128. egret.lifecycle.stage = stage;
  4129. egret.lifecycle.addLifecycleListener(web.WebLifeCycleHandler);
  4130. var webInput = new web.HTMLInput();
  4131. if (option.showFPS || option.showLog) {
  4132. if (!egret.nativeRender) {
  4133. player.displayFPS(option.showFPS, option.showLog, option.logFilter, option.fpsStyles);
  4134. }
  4135. }
  4136. this.playerOption = option;
  4137. this.container = container;
  4138. this.canvas = canvas;
  4139. this.stage = stage;
  4140. this.player = player;
  4141. this.webTouchHandler = webTouch;
  4142. this.webInput = webInput;
  4143. egret.web.$cacheTextAdapter(webInput, stage, container, canvas);
  4144. this.updateScreenSize();
  4145. this.updateMaxTouches();
  4146. player.start();
  4147. };
  4148. WebPlayer.prototype.initOrientation = function () {
  4149. var self = this;
  4150. window.addEventListener("orientationchange", function () {
  4151. window.setTimeout(function () {
  4152. egret.StageOrientationEvent.dispatchStageOrientationEvent(self.stage, egret.StageOrientationEvent.ORIENTATION_CHANGE);
  4153. }, 350);
  4154. });
  4155. };
  4156. /**
  4157. * 读取初始化参数
  4158. */
  4159. WebPlayer.prototype.readOption = function (container, options) {
  4160. var option = {};
  4161. option.entryClassName = container.getAttribute("data-entry-class");
  4162. option.scaleMode = container.getAttribute("data-scale-mode") || egret.StageScaleMode.NO_SCALE;
  4163. option.frameRate = +container.getAttribute("data-frame-rate") || 30;
  4164. option.contentWidth = +container.getAttribute("data-content-width") || 480;
  4165. option.contentHeight = +container.getAttribute("data-content-height") || 800;
  4166. option.orientation = container.getAttribute("data-orientation") || egret.OrientationMode.AUTO;
  4167. option.maxTouches = +container.getAttribute("data-multi-fingered") || 2;
  4168. option.textureScaleFactor = +container.getAttribute("texture-scale-factor") || 1;
  4169. option.showFPS = container.getAttribute("data-show-fps") == "true";
  4170. var styleStr = container.getAttribute("data-show-fps-style") || "";
  4171. var stylesArr = styleStr.split(",");
  4172. var styles = {};
  4173. for (var i = 0; i < stylesArr.length; i++) {
  4174. var tempStyleArr = stylesArr[i].split(":");
  4175. styles[tempStyleArr[0]] = tempStyleArr[1];
  4176. }
  4177. option.fpsStyles = styles;
  4178. option.showLog = container.getAttribute("data-show-log") == "true";
  4179. option.logFilter = container.getAttribute("data-log-filter");
  4180. return option;
  4181. };
  4182. /**
  4183. * @private
  4184. * 添加canvas到container。
  4185. */
  4186. WebPlayer.prototype.attachCanvas = function (container, canvas) {
  4187. var style = canvas.style;
  4188. style.cursor = "inherit";
  4189. style.position = "absolute";
  4190. style.top = "0";
  4191. style.bottom = "0";
  4192. style.left = "0";
  4193. style.right = "0";
  4194. container.appendChild(canvas);
  4195. style = container.style;
  4196. style.overflow = "hidden";
  4197. style.position = "absolute";
  4198. };
  4199. /**
  4200. * @private
  4201. * 更新播放器视口尺寸
  4202. */
  4203. WebPlayer.prototype.updateScreenSize = function () {
  4204. var canvas = this.canvas;
  4205. if (canvas['userTyping'])
  4206. return;
  4207. var option = this.playerOption;
  4208. var screenRect = this.container.getBoundingClientRect();
  4209. var top = 0;
  4210. var boundingClientWidth = screenRect.width;
  4211. var boundingClientHeight = screenRect.height;
  4212. if (boundingClientWidth == 0 || boundingClientHeight == 0) {
  4213. return;
  4214. }
  4215. if (screenRect.top < 0) {
  4216. boundingClientHeight += screenRect.top;
  4217. top = -screenRect.top;
  4218. }
  4219. var shouldRotate = false;
  4220. var orientation = this.stage.$orientation;
  4221. if (orientation != egret.OrientationMode.AUTO) {
  4222. shouldRotate = orientation != egret.OrientationMode.PORTRAIT && boundingClientHeight > boundingClientWidth
  4223. || orientation == egret.OrientationMode.PORTRAIT && boundingClientWidth > boundingClientHeight;
  4224. }
  4225. var screenWidth = shouldRotate ? boundingClientHeight : boundingClientWidth;
  4226. var screenHeight = shouldRotate ? boundingClientWidth : boundingClientHeight;
  4227. egret.Capabilities["boundingClientWidth" + ""] = screenWidth;
  4228. egret.Capabilities["boundingClientHeight" + ""] = screenHeight;
  4229. var stageSize = egret.sys.screenAdapter.calculateStageSize(this.stage.$scaleMode, screenWidth, screenHeight, option.contentWidth, option.contentHeight);
  4230. var stageWidth = stageSize.stageWidth;
  4231. var stageHeight = stageSize.stageHeight;
  4232. var displayWidth = stageSize.displayWidth;
  4233. var displayHeight = stageSize.displayHeight;
  4234. canvas.style[egret.web.getPrefixStyleName("transformOrigin")] = "0% 0% 0px";
  4235. if (canvas.width != stageWidth) {
  4236. canvas.width = stageWidth;
  4237. }
  4238. if (canvas.height != stageHeight) {
  4239. canvas.height = stageHeight;
  4240. }
  4241. var rotation = 0;
  4242. if (shouldRotate) {
  4243. if (orientation == egret.OrientationMode.LANDSCAPE) {
  4244. rotation = 90;
  4245. canvas.style.top = top + (boundingClientHeight - displayWidth) / 2 + "px";
  4246. canvas.style.left = (boundingClientWidth + displayHeight) / 2 + "px";
  4247. }
  4248. else {
  4249. rotation = -90;
  4250. canvas.style.top = top + (boundingClientHeight + displayWidth) / 2 + "px";
  4251. canvas.style.left = (boundingClientWidth - displayHeight) / 2 + "px";
  4252. }
  4253. }
  4254. else {
  4255. canvas.style.top = top + (boundingClientHeight - displayHeight) / 2 + "px";
  4256. canvas.style.left = (boundingClientWidth - displayWidth) / 2 + "px";
  4257. }
  4258. var scalex = displayWidth / stageWidth, scaley = displayHeight / stageHeight;
  4259. var canvasScaleX = scalex * egret.sys.DisplayList.$canvasScaleFactor;
  4260. var canvasScaleY = scaley * egret.sys.DisplayList.$canvasScaleFactor;
  4261. if (egret.Capabilities.renderMode == "canvas") {
  4262. canvasScaleX = Math.ceil(canvasScaleX);
  4263. canvasScaleY = Math.ceil(canvasScaleY);
  4264. }
  4265. var m = egret.Matrix.create();
  4266. m.identity();
  4267. m.scale(scalex / canvasScaleX, scaley / canvasScaleY);
  4268. m.rotate(rotation * Math.PI / 180);
  4269. var transform = "matrix(" + m.a + "," + m.b + "," + m.c + "," + m.d + "," + m.tx + "," + m.ty + ")";
  4270. egret.Matrix.release(m);
  4271. canvas.style[egret.web.getPrefixStyleName("transform")] = transform;
  4272. egret.sys.DisplayList.$setCanvasScale(canvasScaleX, canvasScaleY);
  4273. this.webTouchHandler.updateScaleMode(scalex, scaley, rotation);
  4274. this.webInput.$updateSize();
  4275. this.player.updateStageSize(stageWidth, stageHeight); //不要在这个方法后面修改属性
  4276. // todo
  4277. if (egret.nativeRender) {
  4278. canvas.width = stageWidth * canvasScaleX;
  4279. canvas.height = stageHeight * canvasScaleY;
  4280. }
  4281. };
  4282. WebPlayer.prototype.setContentSize = function (width, height) {
  4283. var option = this.playerOption;
  4284. option.contentWidth = width;
  4285. option.contentHeight = height;
  4286. this.updateScreenSize();
  4287. };
  4288. /**
  4289. * @private
  4290. * 更新触摸数量
  4291. */
  4292. WebPlayer.prototype.updateMaxTouches = function () {
  4293. this.webTouchHandler.$updateMaxTouches();
  4294. };
  4295. return WebPlayer;
  4296. }(egret.HashObject));
  4297. web.WebPlayer = WebPlayer;
  4298. __reflect(WebPlayer.prototype, "egret.web.WebPlayer", ["egret.sys.Screen"]);
  4299. })(web = egret.web || (egret.web = {}));
  4300. })(egret || (egret = {}));
  4301. //////////////////////////////////////////////////////////////////////////////////////
  4302. //
  4303. // Copyright (c) 2014-present, Egret Technology.
  4304. // All rights reserved.
  4305. // Redistribution and use in source and binary forms, with or without
  4306. // modification, are permitted provided that the following conditions are met:
  4307. //
  4308. // * Redistributions of source code must retain the above copyright
  4309. // notice, this list of conditions and the following disclaimer.
  4310. // * Redistributions in binary form must reproduce the above copyright
  4311. // notice, this list of conditions and the following disclaimer in the
  4312. // documentation and/or other materials provided with the distribution.
  4313. // * Neither the name of the Egret nor the
  4314. // names of its contributors may be used to endorse or promote products
  4315. // derived from this software without specific prior written permission.
  4316. //
  4317. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4318. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4319. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4320. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4321. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4322. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4323. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4324. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4325. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4326. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4327. //
  4328. //////////////////////////////////////////////////////////////////////////////////////
  4329. var egret;
  4330. (function (egret) {
  4331. var web;
  4332. (function (web) {
  4333. var sharedCanvas;
  4334. var sharedContext;
  4335. /**
  4336. * @private
  4337. */
  4338. function convertImageToCanvas(texture, rect) {
  4339. if (!sharedCanvas) {
  4340. sharedCanvas = document.createElement("canvas");
  4341. sharedContext = sharedCanvas.getContext("2d");
  4342. }
  4343. var w = texture.$getTextureWidth();
  4344. var h = texture.$getTextureHeight();
  4345. if (rect == null) {
  4346. rect = egret.$TempRectangle;
  4347. rect.x = 0;
  4348. rect.y = 0;
  4349. rect.width = w;
  4350. rect.height = h;
  4351. }
  4352. rect.x = Math.min(rect.x, w - 1);
  4353. rect.y = Math.min(rect.y, h - 1);
  4354. rect.width = Math.min(rect.width, w - rect.x);
  4355. rect.height = Math.min(rect.height, h - rect.y);
  4356. var iWidth = rect.width;
  4357. var iHeight = rect.height;
  4358. var surface = sharedCanvas;
  4359. surface["style"]["width"] = iWidth + "px";
  4360. surface["style"]["height"] = iHeight + "px";
  4361. sharedCanvas.width = iWidth;
  4362. sharedCanvas.height = iHeight;
  4363. if (egret.Capabilities.renderMode == "webgl") {
  4364. var renderTexture = void 0;
  4365. //webgl下非RenderTexture纹理先画到RenderTexture
  4366. if (!texture.$renderBuffer) {
  4367. renderTexture = new egret.RenderTexture();
  4368. renderTexture.drawToTexture(new egret.Bitmap(texture));
  4369. }
  4370. else {
  4371. renderTexture = texture;
  4372. }
  4373. //从RenderTexture中读取像素数据,填入canvas
  4374. var pixels = renderTexture.$renderBuffer.getPixels(rect.x, rect.y, iWidth, iHeight);
  4375. var imageData = new ImageData(iWidth, iHeight);
  4376. for (var i = 0; i < pixels.length; i++) {
  4377. imageData.data[i] = pixels[i];
  4378. }
  4379. sharedContext.putImageData(imageData, 0, 0);
  4380. if (!texture.$renderBuffer) {
  4381. renderTexture.dispose();
  4382. }
  4383. return surface;
  4384. }
  4385. else {
  4386. var bitmapData = texture;
  4387. var offsetX = Math.round(bitmapData.$offsetX);
  4388. var offsetY = Math.round(bitmapData.$offsetY);
  4389. var bitmapWidth = bitmapData.$bitmapWidth;
  4390. var bitmapHeight = bitmapData.$bitmapHeight;
  4391. sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / egret.$TextureScaleFactor, bitmapData.$bitmapY + rect.y / egret.$TextureScaleFactor, bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height);
  4392. return surface;
  4393. }
  4394. }
  4395. /**
  4396. * @private
  4397. */
  4398. function toDataURL(type, rect, encoderOptions) {
  4399. try {
  4400. var surface = convertImageToCanvas(this, rect);
  4401. var result = surface.toDataURL(type, encoderOptions);
  4402. return result;
  4403. }
  4404. catch (e) {
  4405. egret.$error(1033);
  4406. }
  4407. return null;
  4408. }
  4409. /**
  4410. * 有些杀毒软件认为 saveToFile 可能是一个病毒文件
  4411. */
  4412. function eliFoTevas(type, filePath, rect, encoderOptions) {
  4413. var base64 = toDataURL.call(this, type, rect, encoderOptions);
  4414. if (base64 == null) {
  4415. return;
  4416. }
  4417. var href = base64.replace(/^data:image[^;]*/, "data:image/octet-stream");
  4418. var aLink = document.createElement('a');
  4419. aLink['download'] = filePath;
  4420. aLink.href = href;
  4421. var evt = document.createEvent('MouseEvents');
  4422. evt.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  4423. aLink.dispatchEvent(evt);
  4424. }
  4425. function getPixel32(x, y) {
  4426. egret.$warn(1041, "getPixel32", "getPixels");
  4427. return this.getPixels(x, y);
  4428. }
  4429. function getPixels(x, y, width, height) {
  4430. if (width === void 0) { width = 1; }
  4431. if (height === void 0) { height = 1; }
  4432. //webgl环境下不需要转换成canvas获取像素信息
  4433. if (egret.Capabilities.renderMode == "webgl") {
  4434. var renderTexture = void 0;
  4435. //webgl下非RenderTexture纹理先画到RenderTexture
  4436. if (!this.$renderBuffer) {
  4437. renderTexture = new egret.RenderTexture();
  4438. renderTexture.drawToTexture(new egret.Bitmap(this));
  4439. }
  4440. else {
  4441. renderTexture = this;
  4442. }
  4443. //从RenderTexture中读取像素数据
  4444. var pixels = renderTexture.$renderBuffer.getPixels(x, y, width, height);
  4445. return pixels;
  4446. }
  4447. try {
  4448. var surface = convertImageToCanvas(this);
  4449. var result = sharedContext.getImageData(x, y, width, height).data;
  4450. return result;
  4451. }
  4452. catch (e) {
  4453. egret.$error(1039);
  4454. }
  4455. }
  4456. egret.Texture.prototype.toDataURL = toDataURL;
  4457. egret.Texture.prototype.saveToFile = eliFoTevas;
  4458. egret.Texture.prototype.getPixel32 = getPixel32;
  4459. egret.Texture.prototype.getPixels = getPixels;
  4460. })(web = egret.web || (egret.web = {}));
  4461. })(egret || (egret = {}));
  4462. //////////////////////////////////////////////////////////////////////////////////////
  4463. //
  4464. // Copyright (c) 2014-present, Egret Technology.
  4465. // All rights reserved.
  4466. // Redistribution and use in source and binary forms, with or without
  4467. // modification, are permitted provided that the following conditions are met:
  4468. //
  4469. // * Redistributions of source code must retain the above copyright
  4470. // notice, this list of conditions and the following disclaimer.
  4471. // * Redistributions in binary form must reproduce the above copyright
  4472. // notice, this list of conditions and the following disclaimer in the
  4473. // documentation and/or other materials provided with the distribution.
  4474. // * Neither the name of the Egret nor the
  4475. // names of its contributors may be used to endorse or promote products
  4476. // derived from this software without specific prior written permission.
  4477. //
  4478. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4479. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4480. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4481. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4482. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4483. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4484. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4485. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4486. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4487. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4488. //
  4489. //////////////////////////////////////////////////////////////////////////////////////
  4490. var egret;
  4491. (function (egret) {
  4492. var web;
  4493. (function (web) {
  4494. /**
  4495. * @private
  4496. * XML节点基类
  4497. */
  4498. var XMLNode = (function () {
  4499. /**
  4500. * @private
  4501. */
  4502. function XMLNode(nodeType, parent) {
  4503. this.nodeType = nodeType;
  4504. this.parent = parent;
  4505. }
  4506. return XMLNode;
  4507. }());
  4508. web.XMLNode = XMLNode;
  4509. __reflect(XMLNode.prototype, "egret.web.XMLNode");
  4510. /**
  4511. * @private
  4512. * XML节点对象
  4513. */
  4514. var XML = (function (_super) {
  4515. __extends(XML, _super);
  4516. /**
  4517. * @private
  4518. */
  4519. function XML(localName, parent, prefix, namespace, name) {
  4520. var _this = _super.call(this, 1, parent) || this;
  4521. /**
  4522. * @private
  4523. * 当前节点上的属性列表
  4524. */
  4525. _this.attributes = {};
  4526. /**
  4527. * @private
  4528. * 当前节点的子节点列表
  4529. */
  4530. _this.children = [];
  4531. _this.localName = localName;
  4532. _this.prefix = prefix;
  4533. _this.namespace = namespace;
  4534. _this.name = name;
  4535. return _this;
  4536. }
  4537. return XML;
  4538. }(XMLNode));
  4539. web.XML = XML;
  4540. __reflect(XML.prototype, "egret.web.XML");
  4541. /**
  4542. * @private
  4543. * XML文本节点
  4544. */
  4545. var XMLText = (function (_super) {
  4546. __extends(XMLText, _super);
  4547. /**
  4548. * @private
  4549. */
  4550. function XMLText(text, parent) {
  4551. var _this = _super.call(this, 3, parent) || this;
  4552. _this.text = text;
  4553. return _this;
  4554. }
  4555. return XMLText;
  4556. }(XMLNode));
  4557. web.XMLText = XMLText;
  4558. __reflect(XMLText.prototype, "egret.web.XMLText");
  4559. var parser = new DOMParser();
  4560. /**
  4561. * @private
  4562. * 解析字符串为XML对象
  4563. * @param text 要解析的字符串
  4564. */
  4565. function parse(text) {
  4566. var xmlDoc = parser.parseFromString(text, "text/xml");
  4567. var length = xmlDoc.childNodes.length;
  4568. for (var i = 0; i < length; i++) {
  4569. var node = xmlDoc.childNodes[i];
  4570. if (node.nodeType == 1) {
  4571. return parseNode(node, null);
  4572. }
  4573. }
  4574. return null;
  4575. }
  4576. /**
  4577. * @private
  4578. * 解析一个节点
  4579. */
  4580. function parseNode(node, parent) {
  4581. if (node.localName == "parsererror") {
  4582. throw new Error(node.textContent);
  4583. }
  4584. var xml = new XML(node.localName, parent, node["prefix"], node.namespaceURI, node.nodeName);
  4585. var nodeAttributes = node.attributes;
  4586. var attributes = xml.attributes;
  4587. var length = nodeAttributes.length;
  4588. for (var i = 0; i < length; i++) {
  4589. var attributeNode = nodeAttributes[i];
  4590. var name_1 = attributeNode.name;
  4591. if (name_1.indexOf("xmlns:") == 0) {
  4592. continue;
  4593. }
  4594. attributes[name_1] = attributeNode.value;
  4595. xml["$" + name_1] = attributeNode.value;
  4596. }
  4597. var childNodes = node.childNodes;
  4598. length = childNodes.length;
  4599. var children = xml.children;
  4600. for (var i = 0; i < length; i++) {
  4601. var childNode = childNodes[i];
  4602. var nodeType = childNode.nodeType;
  4603. var childXML = null;
  4604. if (nodeType == 1) {
  4605. childXML = parseNode(childNode, xml);
  4606. }
  4607. else if (nodeType == 3) {
  4608. var text = childNode.textContent.trim();
  4609. if (text) {
  4610. childXML = new XMLText(text, xml);
  4611. }
  4612. }
  4613. if (childXML) {
  4614. children.push(childXML);
  4615. }
  4616. }
  4617. return xml;
  4618. }
  4619. egret.XML = { parse: parse };
  4620. })(web = egret.web || (egret.web = {}));
  4621. })(egret || (egret = {}));
  4622. var egret;
  4623. (function (egret) {
  4624. var web;
  4625. (function (web) {
  4626. /**
  4627. * @private
  4628. */
  4629. var WebDeviceOrientation = (function (_super) {
  4630. __extends(WebDeviceOrientation, _super);
  4631. function WebDeviceOrientation() {
  4632. var _this = _super !== null && _super.apply(this, arguments) || this;
  4633. /**
  4634. * @private
  4635. */
  4636. _this.onChange = function (e) {
  4637. var event = new egret.OrientationEvent(egret.Event.CHANGE);
  4638. event.beta = e.beta;
  4639. event.gamma = e.gamma;
  4640. event.alpha = e.alpha;
  4641. _this.dispatchEvent(event);
  4642. };
  4643. return _this;
  4644. }
  4645. /**
  4646. * @private
  4647. *
  4648. */
  4649. WebDeviceOrientation.prototype.start = function () {
  4650. window.addEventListener("deviceorientation", this.onChange);
  4651. };
  4652. /**
  4653. * @private
  4654. *
  4655. */
  4656. WebDeviceOrientation.prototype.stop = function () {
  4657. window.removeEventListener("deviceorientation", this.onChange);
  4658. };
  4659. return WebDeviceOrientation;
  4660. }(egret.EventDispatcher));
  4661. web.WebDeviceOrientation = WebDeviceOrientation;
  4662. __reflect(WebDeviceOrientation.prototype, "egret.web.WebDeviceOrientation", ["egret.DeviceOrientation"]);
  4663. })(web = egret.web || (egret.web = {}));
  4664. })(egret || (egret = {}));
  4665. egret.DeviceOrientation = egret.web.WebDeviceOrientation;
  4666. var egret;
  4667. (function (egret) {
  4668. var web;
  4669. (function (web) {
  4670. /**
  4671. * @private
  4672. */
  4673. var WebGeolocation = (function (_super) {
  4674. __extends(WebGeolocation, _super);
  4675. /**
  4676. * @private
  4677. */
  4678. function WebGeolocation(option) {
  4679. var _this = _super.call(this) || this;
  4680. /**
  4681. * @private
  4682. */
  4683. _this.onUpdate = function (position) {
  4684. var event = new egret.GeolocationEvent(egret.Event.CHANGE);
  4685. var coords = position.coords;
  4686. event.altitude = coords.altitude;
  4687. event.heading = coords.heading;
  4688. event.accuracy = coords.accuracy;
  4689. event.latitude = coords.latitude;
  4690. event.longitude = coords.longitude;
  4691. event.speed = coords.speed;
  4692. event.altitudeAccuracy = coords.altitudeAccuracy;
  4693. _this.dispatchEvent(event);
  4694. };
  4695. /**
  4696. * @private
  4697. */
  4698. _this.onError = function (error) {
  4699. var errorType = egret.GeolocationEvent.UNAVAILABLE;
  4700. if (error.code == error.PERMISSION_DENIED)
  4701. errorType = egret.GeolocationEvent.PERMISSION_DENIED;
  4702. var event = new egret.GeolocationEvent(egret.IOErrorEvent.IO_ERROR);
  4703. event.errorType = errorType;
  4704. event.errorMessage = error.message;
  4705. _this.dispatchEvent(event);
  4706. };
  4707. _this.geolocation = navigator.geolocation;
  4708. return _this;
  4709. }
  4710. /**
  4711. * @private
  4712. *
  4713. */
  4714. WebGeolocation.prototype.start = function () {
  4715. var geo = this.geolocation;
  4716. if (geo)
  4717. this.watchId = geo.watchPosition(this.onUpdate, this.onError);
  4718. else
  4719. this.onError({
  4720. code: 2,
  4721. message: egret.sys.tr(3004),
  4722. PERMISSION_DENIED: 1,
  4723. POSITION_UNAVAILABLE: 2
  4724. });
  4725. };
  4726. /**
  4727. * @private
  4728. *
  4729. */
  4730. WebGeolocation.prototype.stop = function () {
  4731. var geo = this.geolocation;
  4732. geo.clearWatch(this.watchId);
  4733. };
  4734. return WebGeolocation;
  4735. }(egret.EventDispatcher));
  4736. web.WebGeolocation = WebGeolocation;
  4737. __reflect(WebGeolocation.prototype, "egret.web.WebGeolocation", ["egret.Geolocation"]);
  4738. egret.Geolocation = egret.web.WebGeolocation;
  4739. })(web = egret.web || (egret.web = {}));
  4740. })(egret || (egret = {}));
  4741. var egret;
  4742. (function (egret) {
  4743. var web;
  4744. (function (web) {
  4745. /**
  4746. * @private
  4747. */
  4748. var WebMotion = (function (_super) {
  4749. __extends(WebMotion, _super);
  4750. function WebMotion() {
  4751. var _this = _super !== null && _super.apply(this, arguments) || this;
  4752. /**
  4753. * @private
  4754. */
  4755. _this.onChange = function (e) {
  4756. var event = new egret.MotionEvent(egret.Event.CHANGE);
  4757. var acceleration = {
  4758. x: e.acceleration.x,
  4759. y: e.acceleration.y,
  4760. z: e.acceleration.z
  4761. };
  4762. var accelerationIncludingGravity = {
  4763. x: e.accelerationIncludingGravity.x,
  4764. y: e.accelerationIncludingGravity.y,
  4765. z: e.accelerationIncludingGravity.z
  4766. };
  4767. var rotation = {
  4768. alpha: e.rotationRate.alpha,
  4769. beta: e.rotationRate.beta,
  4770. gamma: e.rotationRate.gamma
  4771. };
  4772. event.acceleration = acceleration;
  4773. event.accelerationIncludingGravity = accelerationIncludingGravity;
  4774. event.rotationRate = rotation;
  4775. _this.dispatchEvent(event);
  4776. };
  4777. return _this;
  4778. }
  4779. /**
  4780. * @private
  4781. *
  4782. */
  4783. WebMotion.prototype.start = function () {
  4784. window.addEventListener("devicemotion", this.onChange);
  4785. };
  4786. /**
  4787. * @private
  4788. *
  4789. */
  4790. WebMotion.prototype.stop = function () {
  4791. window.removeEventListener("devicemotion", this.onChange);
  4792. };
  4793. return WebMotion;
  4794. }(egret.EventDispatcher));
  4795. web.WebMotion = WebMotion;
  4796. __reflect(WebMotion.prototype, "egret.web.WebMotion", ["egret.Motion"]);
  4797. egret.Motion = egret.web.WebMotion;
  4798. })(web = egret.web || (egret.web = {}));
  4799. })(egret || (egret = {}));
  4800. //////////////////////////////////////////////////////////////////////////////////////
  4801. //
  4802. // Copyright (c) 2014-present, Egret Technology.
  4803. // All rights reserved.
  4804. // Redistribution and use in source and binary forms, with or without
  4805. // modification, are permitted provided that the following conditions are met:
  4806. //
  4807. // * Redistributions of source code must retain the above copyright
  4808. // notice, this list of conditions and the following disclaimer.
  4809. // * Redistributions in binary form must reproduce the above copyright
  4810. // notice, this list of conditions and the following disclaimer in the
  4811. // documentation and/or other materials provided with the distribution.
  4812. // * Neither the name of the Egret nor the
  4813. // names of its contributors may be used to endorse or promote products
  4814. // derived from this software without specific prior written permission.
  4815. //
  4816. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4817. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4818. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4819. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4820. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4821. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4822. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4823. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4824. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4825. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4826. //
  4827. //////////////////////////////////////////////////////////////////////////////////////
  4828. var egret;
  4829. (function (egret) {
  4830. var web;
  4831. (function (web) {
  4832. if (true) {
  4833. var logFuncs_1;
  4834. function setLogLevel(logType) {
  4835. if (logFuncs_1 == null) {
  4836. logFuncs_1 = {
  4837. "error": console.error,
  4838. "debug": console.debug,
  4839. "warn": console.warn,
  4840. "info": console.info,
  4841. "log": console.log
  4842. };
  4843. }
  4844. switch (logType) {
  4845. case egret.Logger.OFF:
  4846. console.error = function () {
  4847. };
  4848. case egret.Logger.ERROR:
  4849. console.warn = function () {
  4850. };
  4851. case egret.Logger.WARN:
  4852. console.info = function () {
  4853. };
  4854. console.log = function () {
  4855. };
  4856. case egret.Logger.INFO:
  4857. console.debug = function () {
  4858. };
  4859. default:
  4860. break;
  4861. }
  4862. switch (logType) {
  4863. case egret.Logger.ALL:
  4864. case egret.Logger.DEBUG:
  4865. console.debug = logFuncs_1["debug"];
  4866. case egret.Logger.INFO:
  4867. console.log = logFuncs_1["log"];
  4868. console.info = logFuncs_1["info"];
  4869. case egret.Logger.WARN:
  4870. console.warn = logFuncs_1["warn"];
  4871. case egret.Logger.ERROR:
  4872. console.error = logFuncs_1["error"];
  4873. default:
  4874. break;
  4875. }
  4876. }
  4877. Object.defineProperty(egret.Logger, "logLevel", {
  4878. set: setLogLevel,
  4879. enumerable: true,
  4880. configurable: true
  4881. });
  4882. }
  4883. })(web = egret.web || (egret.web = {}));
  4884. })(egret || (egret = {}));
  4885. //////////////////////////////////////////////////////////////////////////////////////
  4886. //
  4887. // Copyright (c) 2014-present, Egret Technology.
  4888. // All rights reserved.
  4889. // Redistribution and use in source and binary forms, with or without
  4890. // modification, are permitted provided that the following conditions are met:
  4891. //
  4892. // * Redistributions of source code must retain the above copyright
  4893. // notice, this list of conditions and the following disclaimer.
  4894. // * Redistributions in binary form must reproduce the above copyright
  4895. // notice, this list of conditions and the following disclaimer in the
  4896. // documentation and/or other materials provided with the distribution.
  4897. // * Neither the name of the Egret nor the
  4898. // names of its contributors may be used to endorse or promote products
  4899. // derived from this software without specific prior written permission.
  4900. //
  4901. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4902. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4903. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4904. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4905. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4906. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4907. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4908. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4909. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4910. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4911. //
  4912. //////////////////////////////////////////////////////////////////////////////////////
  4913. var egret;
  4914. (function (egret) {
  4915. var web;
  4916. (function (web) {
  4917. /**
  4918. * @private
  4919. * 绘制指令管理器
  4920. * 用来维护drawData数组
  4921. */
  4922. var WebGLDrawCmdManager = (function () {
  4923. function WebGLDrawCmdManager() {
  4924. /**
  4925. * 用于缓存绘制命令的数组
  4926. */
  4927. this.drawData = [];
  4928. this.drawDataLen = 0;
  4929. }
  4930. /**
  4931. * 压入绘制矩形指令
  4932. */
  4933. WebGLDrawCmdManager.prototype.pushDrawRect = function () {
  4934. if (this.drawDataLen == 0 || this.drawData[this.drawDataLen - 1].type != 1 /* RECT */) {
  4935. var data = this.drawData[this.drawDataLen] || {};
  4936. data.type = 1 /* RECT */;
  4937. data.count = 0;
  4938. this.drawData[this.drawDataLen] = data;
  4939. this.drawDataLen++;
  4940. }
  4941. this.drawData[this.drawDataLen - 1].count += 2;
  4942. };
  4943. /**
  4944. * 压入绘制texture指令
  4945. */
  4946. WebGLDrawCmdManager.prototype.pushDrawTexture = function (texture, count, filter, textureWidth, textureHeight) {
  4947. if (count === void 0) { count = 2; }
  4948. if (filter) {
  4949. // 目前有滤镜的情况下不会合并绘制
  4950. var data = this.drawData[this.drawDataLen] || {};
  4951. data.type = 0 /* TEXTURE */;
  4952. data.texture = texture;
  4953. data.filter = filter;
  4954. data.count = count;
  4955. data.textureWidth = textureWidth;
  4956. data.textureHeight = textureHeight;
  4957. this.drawData[this.drawDataLen] = data;
  4958. this.drawDataLen++;
  4959. }
  4960. else {
  4961. if (this.drawDataLen == 0 || this.drawData[this.drawDataLen - 1].type != 0 /* TEXTURE */ || texture != this.drawData[this.drawDataLen - 1].texture || this.drawData[this.drawDataLen - 1].filter) {
  4962. var data = this.drawData[this.drawDataLen] || {};
  4963. data.type = 0 /* TEXTURE */;
  4964. data.texture = texture;
  4965. data.count = 0;
  4966. this.drawData[this.drawDataLen] = data;
  4967. this.drawDataLen++;
  4968. }
  4969. this.drawData[this.drawDataLen - 1].count += count;
  4970. }
  4971. };
  4972. WebGLDrawCmdManager.prototype.pushChangeSmoothing = function (texture, smoothing) {
  4973. texture["smoothing"] = smoothing;
  4974. var data = this.drawData[this.drawDataLen] || {};
  4975. data.type = 10 /* SMOOTHING */;
  4976. data.texture = texture;
  4977. data.smoothing = smoothing;
  4978. this.drawData[this.drawDataLen] = data;
  4979. this.drawDataLen++;
  4980. };
  4981. /**
  4982. * 压入pushMask指令
  4983. */
  4984. WebGLDrawCmdManager.prototype.pushPushMask = function (count) {
  4985. if (count === void 0) { count = 1; }
  4986. var data = this.drawData[this.drawDataLen] || {};
  4987. data.type = 2 /* PUSH_MASK */;
  4988. data.count = count * 2;
  4989. this.drawData[this.drawDataLen] = data;
  4990. this.drawDataLen++;
  4991. };
  4992. /**
  4993. * 压入popMask指令
  4994. */
  4995. WebGLDrawCmdManager.prototype.pushPopMask = function (count) {
  4996. if (count === void 0) { count = 1; }
  4997. var data = this.drawData[this.drawDataLen] || {};
  4998. data.type = 3 /* POP_MASK */;
  4999. data.count = count * 2;
  5000. this.drawData[this.drawDataLen] = data;
  5001. this.drawDataLen++;
  5002. };
  5003. /**
  5004. * 压入混色指令
  5005. */
  5006. WebGLDrawCmdManager.prototype.pushSetBlend = function (value) {
  5007. var len = this.drawDataLen;
  5008. // 有无遍历到有效绘图操作
  5009. var drawState = false;
  5010. for (var i = len - 1; i >= 0; i--) {
  5011. var data = this.drawData[i];
  5012. if (data) {
  5013. if (data.type == 0 /* TEXTURE */ || data.type == 1 /* RECT */) {
  5014. drawState = true;
  5015. }
  5016. // 如果与上一次blend操作之间无有效绘图,上一次操作无效
  5017. if (!drawState && data.type == 4 /* BLEND */) {
  5018. this.drawData.splice(i, 1);
  5019. this.drawDataLen--;
  5020. continue;
  5021. }
  5022. // 如果与上一次blend操作重复,本次操作无效
  5023. if (data.type == 4 /* BLEND */) {
  5024. if (data.value == value) {
  5025. return;
  5026. }
  5027. else {
  5028. break;
  5029. }
  5030. }
  5031. }
  5032. }
  5033. var _data = this.drawData[this.drawDataLen] || {};
  5034. _data.type = 4 /* BLEND */;
  5035. _data.value = value;
  5036. this.drawData[this.drawDataLen] = _data;
  5037. this.drawDataLen++;
  5038. };
  5039. /*
  5040. * 压入resize render target命令
  5041. */
  5042. WebGLDrawCmdManager.prototype.pushResize = function (buffer, width, height) {
  5043. var data = this.drawData[this.drawDataLen] || {};
  5044. data.type = 5 /* RESIZE_TARGET */;
  5045. data.buffer = buffer;
  5046. data.width = width;
  5047. data.height = height;
  5048. this.drawData[this.drawDataLen] = data;
  5049. this.drawDataLen++;
  5050. };
  5051. /*
  5052. * 压入clear color命令
  5053. */
  5054. WebGLDrawCmdManager.prototype.pushClearColor = function () {
  5055. var data = this.drawData[this.drawDataLen] || {};
  5056. data.type = 6 /* CLEAR_COLOR */;
  5057. this.drawData[this.drawDataLen] = data;
  5058. this.drawDataLen++;
  5059. };
  5060. /**
  5061. * 压入激活buffer命令
  5062. */
  5063. WebGLDrawCmdManager.prototype.pushActivateBuffer = function (buffer) {
  5064. var len = this.drawDataLen;
  5065. // 有无遍历到有效绘图操作
  5066. var drawState = false;
  5067. for (var i = len - 1; i >= 0; i--) {
  5068. var data = this.drawData[i];
  5069. if (data) {
  5070. if (data.type != 4 /* BLEND */ && data.type != 7 /* ACT_BUFFER */) {
  5071. drawState = true;
  5072. }
  5073. // 如果与上一次buffer操作之间无有效绘图,上一次操作无效
  5074. if (!drawState && data.type == 7 /* ACT_BUFFER */) {
  5075. this.drawData.splice(i, 1);
  5076. this.drawDataLen--;
  5077. continue;
  5078. }
  5079. // 如果与上一次buffer操作重复,本次操作无效
  5080. // if(data.type == DRAWABLE_TYPE.ACT_BUFFER) {
  5081. // if(data.buffer == buffer) {
  5082. // return;
  5083. // } else {
  5084. // break;
  5085. // }
  5086. // }
  5087. }
  5088. }
  5089. var _data = this.drawData[this.drawDataLen] || {};
  5090. _data.type = 7 /* ACT_BUFFER */;
  5091. _data.buffer = buffer;
  5092. _data.width = buffer.rootRenderTarget.width;
  5093. _data.height = buffer.rootRenderTarget.height;
  5094. this.drawData[this.drawDataLen] = _data;
  5095. this.drawDataLen++;
  5096. };
  5097. /*
  5098. * 压入enabel scissor命令
  5099. */
  5100. WebGLDrawCmdManager.prototype.pushEnableScissor = function (x, y, width, height) {
  5101. var data = this.drawData[this.drawDataLen] || {};
  5102. data.type = 8 /* ENABLE_SCISSOR */;
  5103. data.x = x;
  5104. data.y = y;
  5105. data.width = width;
  5106. data.height = height;
  5107. this.drawData[this.drawDataLen] = data;
  5108. this.drawDataLen++;
  5109. };
  5110. /*
  5111. * 压入disable scissor命令
  5112. */
  5113. WebGLDrawCmdManager.prototype.pushDisableScissor = function () {
  5114. var data = this.drawData[this.drawDataLen] || {};
  5115. data.type = 9 /* DISABLE_SCISSOR */;
  5116. this.drawData[this.drawDataLen] = data;
  5117. this.drawDataLen++;
  5118. };
  5119. /**
  5120. * 清空命令数组
  5121. */
  5122. WebGLDrawCmdManager.prototype.clear = function () {
  5123. for (var i = 0; i < this.drawDataLen; i++) {
  5124. var data = this.drawData[i];
  5125. data.type = 0;
  5126. data.count = 0;
  5127. data.texture = null;
  5128. data.filter = null;
  5129. data.uv = null;
  5130. data.value = "";
  5131. data.buffer = null;
  5132. data.width = 0;
  5133. data.height = 0;
  5134. }
  5135. this.drawDataLen = 0;
  5136. };
  5137. return WebGLDrawCmdManager;
  5138. }());
  5139. web.WebGLDrawCmdManager = WebGLDrawCmdManager;
  5140. __reflect(WebGLDrawCmdManager.prototype, "egret.web.WebGLDrawCmdManager");
  5141. })(web = egret.web || (egret.web = {}));
  5142. })(egret || (egret = {}));
  5143. //////////////////////////////////////////////////////////////////////////////////////
  5144. //
  5145. // Copyright (c) 2014-present, Egret Technology.
  5146. // All rights reserved.
  5147. // Redistribution and use in source and binary forms, with or without
  5148. // modification, are permitted provided that the following conditions are met:
  5149. //
  5150. // * Redistributions of source code must retain the above copyright
  5151. // notice, this list of conditions and the following disclaimer.
  5152. // * Redistributions in binary form must reproduce the above copyright
  5153. // notice, this list of conditions and the following disclaimer in the
  5154. // documentation and/or other materials provided with the distribution.
  5155. // * Neither the name of the Egret nor the
  5156. // names of its contributors may be used to endorse or promote products
  5157. // derived from this software without specific prior written permission.
  5158. //
  5159. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5160. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5161. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5162. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5163. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5164. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5165. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5166. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5167. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5168. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5169. //
  5170. //////////////////////////////////////////////////////////////////////////////////////
  5171. var egret;
  5172. (function (egret) {
  5173. var web;
  5174. (function (web) {
  5175. /**
  5176. * @private
  5177. * 顶点数组管理对象
  5178. * 用来维护顶点数组
  5179. */
  5180. var WebGLVertexArrayObject = (function () {
  5181. function WebGLVertexArrayObject() {
  5182. this.size = 2000;
  5183. this.vertexMaxSize = this.size * 4;
  5184. this.indicesMaxSize = this.size * 6;
  5185. this.vertSize = 5;
  5186. this.vertices = null;
  5187. this.indices = null;
  5188. this.indicesForMesh = null;
  5189. this.vertexIndex = 0;
  5190. this.indexIndex = 0;
  5191. this.hasMesh = false;
  5192. var numVerts = this.vertexMaxSize * this.vertSize;
  5193. var numIndices = this.indicesMaxSize;
  5194. this.vertices = new Float32Array(numVerts);
  5195. this.indices = new Uint16Array(numIndices);
  5196. this.indicesForMesh = new Uint16Array(numIndices);
  5197. for (var i = 0, j = 0; i < numIndices; i += 6, j += 4) {
  5198. this.indices[i + 0] = j + 0;
  5199. this.indices[i + 1] = j + 1;
  5200. this.indices[i + 2] = j + 2;
  5201. this.indices[i + 3] = j + 0;
  5202. this.indices[i + 4] = j + 2;
  5203. this.indices[i + 5] = j + 3;
  5204. }
  5205. }
  5206. /**
  5207. * 是否达到最大缓存数量
  5208. */
  5209. WebGLVertexArrayObject.prototype.reachMaxSize = function (vertexCount, indexCount) {
  5210. if (vertexCount === void 0) { vertexCount = 4; }
  5211. if (indexCount === void 0) { indexCount = 6; }
  5212. return this.vertexIndex > this.vertexMaxSize - vertexCount || this.indexIndex > this.indicesMaxSize - indexCount;
  5213. };
  5214. /**
  5215. * 获取缓存完成的顶点数组
  5216. */
  5217. WebGLVertexArrayObject.prototype.getVertices = function () {
  5218. var view = this.vertices.subarray(0, this.vertexIndex * this.vertSize);
  5219. return view;
  5220. };
  5221. /**
  5222. * 获取缓存完成的索引数组
  5223. */
  5224. WebGLVertexArrayObject.prototype.getIndices = function () {
  5225. return this.indices;
  5226. };
  5227. /**
  5228. * 获取缓存完成的mesh索引数组
  5229. */
  5230. WebGLVertexArrayObject.prototype.getMeshIndices = function () {
  5231. return this.indicesForMesh;
  5232. };
  5233. /**
  5234. * 切换成mesh索引缓存方式
  5235. */
  5236. WebGLVertexArrayObject.prototype.changeToMeshIndices = function () {
  5237. if (!this.hasMesh) {
  5238. // 拷贝默认index信息到for mesh中
  5239. for (var i = 0, l = this.indexIndex; i < l; ++i) {
  5240. this.indicesForMesh[i] = this.indices[i];
  5241. }
  5242. this.hasMesh = true;
  5243. }
  5244. };
  5245. WebGLVertexArrayObject.prototype.isMesh = function () {
  5246. return this.hasMesh;
  5247. };
  5248. /**
  5249. * 默认构成矩形
  5250. */
  5251. // private defaultMeshVertices = [0, 0, 1, 0, 1, 1, 0, 1];
  5252. // private defaultMeshUvs = [
  5253. // 0, 0,
  5254. // 1, 0,
  5255. // 1, 1,
  5256. // 0, 1
  5257. // ];
  5258. // private defaultMeshIndices = [0, 1, 2, 0, 2, 3];
  5259. /**
  5260. * 缓存一组顶点
  5261. */
  5262. WebGLVertexArrayObject.prototype.cacheArrays = function (buffer, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices, rotated) {
  5263. var alpha = buffer.globalAlpha;
  5264. //计算出绘制矩阵,之后把矩阵还原回之前的
  5265. var locWorldTransform = buffer.globalMatrix;
  5266. var a = locWorldTransform.a;
  5267. var b = locWorldTransform.b;
  5268. var c = locWorldTransform.c;
  5269. var d = locWorldTransform.d;
  5270. var tx = locWorldTransform.tx;
  5271. var ty = locWorldTransform.ty;
  5272. var offsetX = buffer.$offsetX;
  5273. var offsetY = buffer.$offsetY;
  5274. if (offsetX != 0 || offsetY != 0) {
  5275. tx = offsetX * a + offsetY * c + tx;
  5276. ty = offsetX * b + offsetY * d + ty;
  5277. }
  5278. if (!meshVertices) {
  5279. if (destX != 0 || destY != 0) {
  5280. tx = destX * a + destY * c + tx;
  5281. ty = destX * b + destY * d + ty;
  5282. }
  5283. var a1 = destWidth / sourceWidth;
  5284. if (a1 != 1) {
  5285. a = a1 * a;
  5286. b = a1 * b;
  5287. }
  5288. var d1 = destHeight / sourceHeight;
  5289. if (d1 != 1) {
  5290. c = d1 * c;
  5291. d = d1 * d;
  5292. }
  5293. }
  5294. if (meshVertices) {
  5295. // 计算索引位置与赋值
  5296. var vertices = this.vertices;
  5297. var index = this.vertexIndex * this.vertSize;
  5298. // 缓存顶点数组
  5299. var i = 0, iD = 0, l = 0;
  5300. var u = 0, v = 0, x = 0, y = 0;
  5301. for (i = 0, l = meshUVs.length; i < l; i += 2) {
  5302. iD = index + i * 5 / 2;
  5303. x = meshVertices[i];
  5304. y = meshVertices[i + 1];
  5305. u = meshUVs[i];
  5306. v = meshUVs[i + 1];
  5307. // xy
  5308. vertices[iD + 0] = a * x + c * y + tx;
  5309. vertices[iD + 1] = b * x + d * y + ty;
  5310. // uv
  5311. if (rotated) {
  5312. vertices[iD + 2] = (sourceX + (1.0 - v) * sourceHeight) / textureSourceWidth;
  5313. vertices[iD + 3] = (sourceY + u * sourceWidth) / textureSourceHeight;
  5314. }
  5315. else {
  5316. vertices[iD + 2] = (sourceX + u * sourceWidth) / textureSourceWidth;
  5317. vertices[iD + 3] = (sourceY + v * sourceHeight) / textureSourceHeight;
  5318. }
  5319. // alpha
  5320. vertices[iD + 4] = alpha;
  5321. }
  5322. // 缓存索引数组
  5323. if (this.hasMesh) {
  5324. for (var i_1 = 0, l_1 = meshIndices.length; i_1 < l_1; ++i_1) {
  5325. this.indicesForMesh[this.indexIndex + i_1] = meshIndices[i_1] + this.vertexIndex;
  5326. }
  5327. }
  5328. this.vertexIndex += meshUVs.length / 2;
  5329. this.indexIndex += meshIndices.length;
  5330. }
  5331. else {
  5332. var width = textureSourceWidth;
  5333. var height = textureSourceHeight;
  5334. var w = sourceWidth;
  5335. var h = sourceHeight;
  5336. sourceX = sourceX / width;
  5337. sourceY = sourceY / height;
  5338. var vertices = this.vertices;
  5339. var index = this.vertexIndex * this.vertSize;
  5340. if (rotated) {
  5341. var temp = sourceWidth;
  5342. sourceWidth = sourceHeight / width;
  5343. sourceHeight = temp / height;
  5344. // xy
  5345. vertices[index++] = tx;
  5346. vertices[index++] = ty;
  5347. // uv
  5348. vertices[index++] = sourceWidth + sourceX;
  5349. vertices[index++] = sourceY;
  5350. // alpha
  5351. vertices[index++] = alpha;
  5352. // xy
  5353. vertices[index++] = a * w + tx;
  5354. vertices[index++] = b * w + ty;
  5355. // uv
  5356. vertices[index++] = sourceWidth + sourceX;
  5357. vertices[index++] = sourceHeight + sourceY;
  5358. // alpha
  5359. vertices[index++] = alpha;
  5360. // xy
  5361. vertices[index++] = a * w + c * h + tx;
  5362. vertices[index++] = d * h + b * w + ty;
  5363. // uv
  5364. vertices[index++] = sourceX;
  5365. vertices[index++] = sourceHeight + sourceY;
  5366. // alpha
  5367. vertices[index++] = alpha;
  5368. // xy
  5369. vertices[index++] = c * h + tx;
  5370. vertices[index++] = d * h + ty;
  5371. // uv
  5372. vertices[index++] = sourceX;
  5373. vertices[index++] = sourceY;
  5374. // alpha
  5375. vertices[index++] = alpha;
  5376. }
  5377. else {
  5378. sourceWidth = sourceWidth / width;
  5379. sourceHeight = sourceHeight / height;
  5380. // xy
  5381. vertices[index++] = tx;
  5382. vertices[index++] = ty;
  5383. // uv
  5384. vertices[index++] = sourceX;
  5385. vertices[index++] = sourceY;
  5386. // alpha
  5387. vertices[index++] = alpha;
  5388. // xy
  5389. vertices[index++] = a * w + tx;
  5390. vertices[index++] = b * w + ty;
  5391. // uv
  5392. vertices[index++] = sourceWidth + sourceX;
  5393. vertices[index++] = sourceY;
  5394. // alpha
  5395. vertices[index++] = alpha;
  5396. // xy
  5397. vertices[index++] = a * w + c * h + tx;
  5398. vertices[index++] = d * h + b * w + ty;
  5399. // uv
  5400. vertices[index++] = sourceWidth + sourceX;
  5401. vertices[index++] = sourceHeight + sourceY;
  5402. // alpha
  5403. vertices[index++] = alpha;
  5404. // xy
  5405. vertices[index++] = c * h + tx;
  5406. vertices[index++] = d * h + ty;
  5407. // uv
  5408. vertices[index++] = sourceX;
  5409. vertices[index++] = sourceHeight + sourceY;
  5410. // alpha
  5411. vertices[index++] = alpha;
  5412. }
  5413. // 缓存索引数组
  5414. if (this.hasMesh) {
  5415. var indicesForMesh = this.indicesForMesh;
  5416. indicesForMesh[this.indexIndex + 0] = 0 + this.vertexIndex;
  5417. indicesForMesh[this.indexIndex + 1] = 1 + this.vertexIndex;
  5418. indicesForMesh[this.indexIndex + 2] = 2 + this.vertexIndex;
  5419. indicesForMesh[this.indexIndex + 3] = 0 + this.vertexIndex;
  5420. indicesForMesh[this.indexIndex + 4] = 2 + this.vertexIndex;
  5421. indicesForMesh[this.indexIndex + 5] = 3 + this.vertexIndex;
  5422. }
  5423. this.vertexIndex += 4;
  5424. this.indexIndex += 6;
  5425. }
  5426. };
  5427. WebGLVertexArrayObject.prototype.clear = function () {
  5428. this.hasMesh = false;
  5429. this.vertexIndex = 0;
  5430. this.indexIndex = 0;
  5431. };
  5432. return WebGLVertexArrayObject;
  5433. }());
  5434. web.WebGLVertexArrayObject = WebGLVertexArrayObject;
  5435. __reflect(WebGLVertexArrayObject.prototype, "egret.web.WebGLVertexArrayObject");
  5436. })(web = egret.web || (egret.web = {}));
  5437. })(egret || (egret = {}));
  5438. //////////////////////////////////////////////////////////////////////////////////////
  5439. //
  5440. // Copyright (c) 2014-present, Egret Technology.
  5441. // All rights reserved.
  5442. // Redistribution and use in source and binary forms, with or without
  5443. // modification, are permitted provided that the following conditions are met:
  5444. //
  5445. // * Redistributions of source code must retain the above copyright
  5446. // notice, this list of conditions and the following disclaimer.
  5447. // * Redistributions in binary form must reproduce the above copyright
  5448. // notice, this list of conditions and the following disclaimer in the
  5449. // documentation and/or other materials provided with the distribution.
  5450. // * Neither the name of the Egret nor the
  5451. // names of its contributors may be used to endorse or promote products
  5452. // derived from this software without specific prior written permission.
  5453. //
  5454. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5455. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5456. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5457. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5458. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5459. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5460. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5461. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5462. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5463. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5464. //
  5465. //////////////////////////////////////////////////////////////////////////////////////
  5466. var egret;
  5467. (function (egret) {
  5468. var web;
  5469. (function (web) {
  5470. /**
  5471. * @private
  5472. * WebGLRenderTarget类
  5473. * 一个WebGL渲染目标,拥有一个frame buffer和texture
  5474. */
  5475. var WebGLRenderTarget = (function (_super) {
  5476. __extends(WebGLRenderTarget, _super);
  5477. function WebGLRenderTarget(gl, width, height) {
  5478. var _this = _super.call(this) || this;
  5479. // 清除色
  5480. _this.clearColor = [0, 0, 0, 0];
  5481. // 是否启用frame buffer, 默认为true
  5482. _this.useFrameBuffer = true;
  5483. _this.gl = gl;
  5484. // 如果尺寸为 0 chrome会报警
  5485. _this.width = width || 1;
  5486. _this.height = height || 1;
  5487. return _this;
  5488. }
  5489. /**
  5490. * 重置render target的尺寸
  5491. */
  5492. WebGLRenderTarget.prototype.resize = function (width, height) {
  5493. var gl = this.gl;
  5494. this.width = width;
  5495. this.height = height;
  5496. if (this.frameBuffer) {
  5497. // 设置texture尺寸
  5498. gl.bindTexture(gl.TEXTURE_2D, this.texture);
  5499. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  5500. // gl.bindTexture(gl.TEXTURE_2D, null);
  5501. }
  5502. if (this.stencilBuffer) {
  5503. gl.deleteRenderbuffer(this.stencilBuffer);
  5504. this.stencilBuffer = null;
  5505. }
  5506. };
  5507. /**
  5508. * 激活此render target
  5509. */
  5510. WebGLRenderTarget.prototype.activate = function () {
  5511. var gl = this.gl;
  5512. gl.bindFramebuffer(gl.FRAMEBUFFER, this.getFrameBuffer());
  5513. };
  5514. /**
  5515. * 获取frame buffer
  5516. */
  5517. WebGLRenderTarget.prototype.getFrameBuffer = function () {
  5518. if (!this.useFrameBuffer) {
  5519. return null;
  5520. }
  5521. return this.frameBuffer;
  5522. };
  5523. WebGLRenderTarget.prototype.initFrameBuffer = function () {
  5524. if (!this.frameBuffer) {
  5525. var gl = this.gl;
  5526. // 创建材质
  5527. this.texture = this.createTexture();
  5528. // 创建frame buffer
  5529. this.frameBuffer = gl.createFramebuffer();
  5530. gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer);
  5531. // 绑定材质
  5532. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0);
  5533. }
  5534. };
  5535. /**
  5536. * 创建材质
  5537. * TODO 创建材质的方法可以合并
  5538. */
  5539. WebGLRenderTarget.prototype.createTexture = function () {
  5540. var gl = this.gl;
  5541. var texture = gl.createTexture();
  5542. texture["glContext"] = gl;
  5543. gl.bindTexture(gl.TEXTURE_2D, texture);
  5544. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  5545. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  5546. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  5547. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  5548. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  5549. return texture;
  5550. };
  5551. /**
  5552. * 清除render target颜色缓存
  5553. */
  5554. WebGLRenderTarget.prototype.clear = function (bind) {
  5555. var gl = this.gl;
  5556. if (bind) {
  5557. this.activate();
  5558. }
  5559. gl.colorMask(true, true, true, true);
  5560. gl.clearColor(this.clearColor[0], this.clearColor[1], this.clearColor[2], this.clearColor[3]);
  5561. gl.clear(gl.COLOR_BUFFER_BIT);
  5562. };
  5563. WebGLRenderTarget.prototype.enabledStencil = function () {
  5564. if (!this.frameBuffer || this.stencilBuffer) {
  5565. return;
  5566. }
  5567. var gl = this.gl;
  5568. // 设置render buffer的尺寸
  5569. gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer); // 是否需要强制绑定?
  5570. // 绑定stencil buffer
  5571. this.stencilBuffer = gl.createRenderbuffer();
  5572. gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencilBuffer);
  5573. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, this.width, this.height);
  5574. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.stencilBuffer);
  5575. // 此处不解绑是否会造成bug?
  5576. // gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  5577. };
  5578. WebGLRenderTarget.prototype.dispose = function () {
  5579. egret.WebGLUtils.deleteWebGLTexture(this.texture);
  5580. };
  5581. return WebGLRenderTarget;
  5582. }(egret.HashObject));
  5583. web.WebGLRenderTarget = WebGLRenderTarget;
  5584. __reflect(WebGLRenderTarget.prototype, "egret.web.WebGLRenderTarget");
  5585. })(web = egret.web || (egret.web = {}));
  5586. })(egret || (egret = {}));
  5587. //////////////////////////////////////////////////////////////////////////////////////
  5588. //
  5589. // Copyright (c) 2014-present, Egret Technology.
  5590. // All rights reserved.
  5591. // Redistribution and use in source and binary forms, with or without
  5592. // modification, are permitted provided that the following conditions are met:
  5593. //
  5594. // * Redistributions of source code must retain the above copyright
  5595. // notice, this list of conditions and the following disclaimer.
  5596. // * Redistributions in binary form must reproduce the above copyright
  5597. // notice, this list of conditions and the following disclaimer in the
  5598. // documentation and/or other materials provided with the distribution.
  5599. // * Neither the name of the Egret nor the
  5600. // names of its contributors may be used to endorse or promote products
  5601. // derived from this software without specific prior written permission.
  5602. //
  5603. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5604. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5605. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5606. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5607. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5608. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5609. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5610. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5611. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5612. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5613. //
  5614. //////////////////////////////////////////////////////////////////////////////////////
  5615. var egret;
  5616. (function (egret) {
  5617. var web;
  5618. (function (web) {
  5619. /**
  5620. * 创建一个canvas。
  5621. */
  5622. function createCanvas(width, height) {
  5623. var canvas = document.createElement("canvas");
  5624. if (!isNaN(width) && !isNaN(height)) {
  5625. canvas.width = width;
  5626. canvas.height = height;
  5627. }
  5628. return canvas;
  5629. }
  5630. /**
  5631. * @private
  5632. * WebGL上下文对象,提供简单的绘图接口
  5633. * 抽象出此类,以实现共用一个context
  5634. */
  5635. var WebGLRenderContext = (function () {
  5636. function WebGLRenderContext(width, height) {
  5637. this.glID = null;
  5638. this.projectionX = NaN;
  5639. this.projectionY = NaN;
  5640. this.contextLost = false;
  5641. this.$scissorState = false;
  5642. this.vertSize = 5;
  5643. this.surface = createCanvas(width, height);
  5644. if (egret.nativeRender) {
  5645. return;
  5646. }
  5647. this.initWebGL();
  5648. this.$bufferStack = [];
  5649. var gl = this.context;
  5650. this.vertexBuffer = gl.createBuffer();
  5651. this.indexBuffer = gl.createBuffer();
  5652. gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
  5653. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
  5654. this.drawCmdManager = new web.WebGLDrawCmdManager();
  5655. this.vao = new web.WebGLVertexArrayObject();
  5656. this.setGlobalCompositeOperation("source-over");
  5657. }
  5658. WebGLRenderContext.getInstance = function (width, height) {
  5659. if (this.instance) {
  5660. return this.instance;
  5661. }
  5662. this.instance = new WebGLRenderContext(width, height);
  5663. return this.instance;
  5664. };
  5665. /**
  5666. * 推入一个RenderBuffer并绑定
  5667. */
  5668. WebGLRenderContext.prototype.pushBuffer = function (buffer) {
  5669. this.$bufferStack.push(buffer);
  5670. if (buffer != this.currentBuffer) {
  5671. if (this.currentBuffer) {
  5672. // this.$drawWebGL();
  5673. }
  5674. this.drawCmdManager.pushActivateBuffer(buffer);
  5675. }
  5676. this.currentBuffer = buffer;
  5677. };
  5678. /**
  5679. * 推出一个RenderBuffer并绑定上一个RenderBuffer
  5680. */
  5681. WebGLRenderContext.prototype.popBuffer = function () {
  5682. // 如果只剩下一个buffer,则不执行pop操作
  5683. // 保证舞台buffer永远在最开始
  5684. if (this.$bufferStack.length <= 1) {
  5685. return;
  5686. }
  5687. var buffer = this.$bufferStack.pop();
  5688. var lastBuffer = this.$bufferStack[this.$bufferStack.length - 1];
  5689. // 重新绑定
  5690. if (buffer != lastBuffer) {
  5691. // this.$drawWebGL();
  5692. this.drawCmdManager.pushActivateBuffer(lastBuffer);
  5693. }
  5694. this.currentBuffer = lastBuffer;
  5695. };
  5696. /**
  5697. * 启用RenderBuffer
  5698. */
  5699. WebGLRenderContext.prototype.activateBuffer = function (buffer, width, height) {
  5700. buffer.rootRenderTarget.activate();
  5701. if (!this.bindIndices) {
  5702. this.uploadIndicesArray(this.vao.getIndices());
  5703. }
  5704. buffer.restoreStencil();
  5705. buffer.restoreScissor();
  5706. this.onResize(width, height);
  5707. };
  5708. /**
  5709. * 上传顶点数据
  5710. */
  5711. WebGLRenderContext.prototype.uploadVerticesArray = function (array) {
  5712. var gl = this.context;
  5713. gl.bufferData(gl.ARRAY_BUFFER, array, gl.STREAM_DRAW);
  5714. // gl.bufferSubData(gl.ARRAY_BUFFER, 0, array);
  5715. };
  5716. /**
  5717. * 上传索引数据
  5718. */
  5719. WebGLRenderContext.prototype.uploadIndicesArray = function (array) {
  5720. var gl = this.context;
  5721. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, array, gl.STATIC_DRAW);
  5722. this.bindIndices = true;
  5723. };
  5724. /**
  5725. * 销毁绘制对象
  5726. */
  5727. WebGLRenderContext.prototype.destroy = function () {
  5728. this.surface.width = this.surface.height = 0;
  5729. };
  5730. WebGLRenderContext.prototype.onResize = function (width, height) {
  5731. width = width || this.surface.width;
  5732. height = height || this.surface.height;
  5733. this.projectionX = width / 2;
  5734. this.projectionY = -height / 2;
  5735. if (this.context) {
  5736. this.context.viewport(0, 0, width, height);
  5737. }
  5738. };
  5739. /**
  5740. * 改变渲染缓冲的大小并清空缓冲区
  5741. * @param width 改变后的宽
  5742. * @param height 改变后的高
  5743. * @param useMaxSize 若传入true,则将改变后的尺寸与已有尺寸对比,保留较大的尺寸。
  5744. */
  5745. WebGLRenderContext.prototype.resize = function (width, height, useMaxSize) {
  5746. var surface = this.surface;
  5747. if (useMaxSize) {
  5748. if (surface.width < width) {
  5749. surface.width = width;
  5750. }
  5751. if (surface.height < height) {
  5752. surface.height = height;
  5753. }
  5754. }
  5755. else {
  5756. if (surface.width != width) {
  5757. surface.width = width;
  5758. }
  5759. if (surface.height != height) {
  5760. surface.height = height;
  5761. }
  5762. }
  5763. this.onResize();
  5764. };
  5765. WebGLRenderContext.prototype.initWebGL = function () {
  5766. this.onResize();
  5767. this.surface.addEventListener("webglcontextlost", this.handleContextLost.bind(this), false);
  5768. this.surface.addEventListener("webglcontextrestored", this.handleContextRestored.bind(this), false);
  5769. this.getWebGLContext();
  5770. var gl = this.context;
  5771. this.$maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
  5772. };
  5773. WebGLRenderContext.prototype.handleContextLost = function () {
  5774. this.contextLost = true;
  5775. };
  5776. WebGLRenderContext.prototype.handleContextRestored = function () {
  5777. this.initWebGL();
  5778. this.contextLost = false;
  5779. };
  5780. WebGLRenderContext.prototype.getWebGLContext = function () {
  5781. var options = {
  5782. antialias: WebGLRenderContext.antialias,
  5783. stencil: true //设置可以使用模板(用于不规则遮罩)
  5784. };
  5785. var gl;
  5786. //todo 是否使用chrome源码names
  5787. //let contextNames = ["moz-webgl", "webkit-3d", "experimental-webgl", "webgl", "3d"];
  5788. var names = ["webgl", "experimental-webgl"];
  5789. for (var i = 0; i < names.length; i++) {
  5790. try {
  5791. gl = this.surface.getContext(names[i], options);
  5792. }
  5793. catch (e) {
  5794. }
  5795. if (gl) {
  5796. break;
  5797. }
  5798. }
  5799. if (!gl) {
  5800. egret.$error(1021);
  5801. }
  5802. this.setContext(gl);
  5803. };
  5804. WebGLRenderContext.prototype.setContext = function (gl) {
  5805. this.context = gl;
  5806. gl.id = WebGLRenderContext.glContextId++;
  5807. this.glID = gl.id;
  5808. gl.disable(gl.DEPTH_TEST);
  5809. gl.disable(gl.CULL_FACE);
  5810. gl.enable(gl.BLEND);
  5811. gl.colorMask(true, true, true, true);
  5812. // 目前只使用0号材质单元,默认开启
  5813. gl.activeTexture(gl.TEXTURE0);
  5814. };
  5815. /**
  5816. * 开启模版检测
  5817. */
  5818. WebGLRenderContext.prototype.enableStencilTest = function () {
  5819. var gl = this.context;
  5820. gl.enable(gl.STENCIL_TEST);
  5821. };
  5822. /**
  5823. * 关闭模版检测
  5824. */
  5825. WebGLRenderContext.prototype.disableStencilTest = function () {
  5826. var gl = this.context;
  5827. gl.disable(gl.STENCIL_TEST);
  5828. };
  5829. /**
  5830. * 开启scissor检测
  5831. */
  5832. WebGLRenderContext.prototype.enableScissorTest = function (rect) {
  5833. var gl = this.context;
  5834. gl.enable(gl.SCISSOR_TEST);
  5835. gl.scissor(rect.x, rect.y, rect.width, rect.height);
  5836. };
  5837. /**
  5838. * 关闭scissor检测
  5839. */
  5840. WebGLRenderContext.prototype.disableScissorTest = function () {
  5841. var gl = this.context;
  5842. gl.disable(gl.SCISSOR_TEST);
  5843. };
  5844. /**
  5845. * 获取像素信息
  5846. */
  5847. WebGLRenderContext.prototype.getPixels = function (x, y, width, height, pixels) {
  5848. var gl = this.context;
  5849. gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
  5850. };
  5851. /**
  5852. * 创建一个WebGLTexture
  5853. */
  5854. WebGLRenderContext.prototype.createTexture = function (bitmapData) {
  5855. var gl = this.context;
  5856. var texture = gl.createTexture();
  5857. if (!texture) {
  5858. //先创建texture失败,然后lost事件才发出来..
  5859. this.contextLost = true;
  5860. return;
  5861. }
  5862. texture.glContext = gl;
  5863. gl.bindTexture(gl.TEXTURE_2D, texture);
  5864. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
  5865. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmapData);
  5866. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  5867. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  5868. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  5869. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  5870. return texture;
  5871. };
  5872. WebGLRenderContext.prototype.createTextureFromCompressedData = function (data, width, height, levels, internalFormat) {
  5873. return null;
  5874. };
  5875. /**
  5876. * 更新材质的bitmapData
  5877. */
  5878. WebGLRenderContext.prototype.updateTexture = function (texture, bitmapData) {
  5879. var gl = this.context;
  5880. gl.bindTexture(gl.TEXTURE_2D, texture);
  5881. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmapData);
  5882. };
  5883. /**
  5884. * 获取一个WebGLTexture
  5885. * 如果有缓存的texture返回缓存的texture,如果没有则创建并缓存texture
  5886. */
  5887. WebGLRenderContext.prototype.getWebGLTexture = function (bitmapData) {
  5888. if (!bitmapData.webGLTexture) {
  5889. if (bitmapData.format == "image") {
  5890. bitmapData.webGLTexture = this.createTexture(bitmapData.source);
  5891. }
  5892. else if (bitmapData.format == "pvr") {
  5893. bitmapData.webGLTexture = this.createTextureFromCompressedData(bitmapData.source.pvrtcData, bitmapData.width, bitmapData.height, bitmapData.source.mipmapsCount, bitmapData.source.format);
  5894. }
  5895. if (bitmapData.$deleteSource && bitmapData.webGLTexture) {
  5896. bitmapData.source = null;
  5897. }
  5898. if (bitmapData.webGLTexture) {
  5899. //todo 默认值
  5900. bitmapData.webGLTexture["smoothing"] = true;
  5901. }
  5902. }
  5903. return bitmapData.webGLTexture;
  5904. };
  5905. /**
  5906. * 清除矩形区域
  5907. */
  5908. WebGLRenderContext.prototype.clearRect = function (x, y, width, height) {
  5909. if (x != 0 || y != 0 || width != this.surface.width || height != this.surface.height) {
  5910. var buffer = this.currentBuffer;
  5911. if (buffer.$hasScissor) {
  5912. this.setGlobalCompositeOperation("destination-out");
  5913. this.drawRect(x, y, width, height);
  5914. this.setGlobalCompositeOperation("source-over");
  5915. }
  5916. else {
  5917. var m = buffer.globalMatrix;
  5918. if (m.b == 0 && m.c == 0) {
  5919. x = x * m.a + m.tx;
  5920. y = y * m.d + m.ty;
  5921. width = width * m.a;
  5922. height = height * m.d;
  5923. this.enableScissor(x, -y - height + buffer.height, width, height);
  5924. this.clear();
  5925. this.disableScissor();
  5926. }
  5927. else {
  5928. this.setGlobalCompositeOperation("destination-out");
  5929. this.drawRect(x, y, width, height);
  5930. this.setGlobalCompositeOperation("source-over");
  5931. }
  5932. }
  5933. }
  5934. else {
  5935. this.clear();
  5936. }
  5937. };
  5938. /**
  5939. * 设置混色
  5940. */
  5941. WebGLRenderContext.prototype.setGlobalCompositeOperation = function (value) {
  5942. this.drawCmdManager.pushSetBlend(value);
  5943. };
  5944. /**
  5945. * 绘制图片,image参数可以是BitmapData或者renderTarget
  5946. */
  5947. WebGLRenderContext.prototype.drawImage = function (image, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, imageSourceWidth, imageSourceHeight, rotated, smoothing) {
  5948. var buffer = this.currentBuffer;
  5949. if (this.contextLost || !image || !buffer) {
  5950. return;
  5951. }
  5952. var texture;
  5953. var offsetX;
  5954. var offsetY;
  5955. if (image["texture"] || (image.source && image.source["texture"])) {
  5956. // 如果是render target
  5957. texture = image["texture"] || image.source["texture"];
  5958. buffer.saveTransform();
  5959. offsetX = buffer.$offsetX;
  5960. offsetY = buffer.$offsetY;
  5961. buffer.useOffset();
  5962. buffer.transform(1, 0, 0, -1, 0, destHeight + destY * 2); // 翻转
  5963. }
  5964. else if (!image.source && !image.webGLTexture) {
  5965. return;
  5966. }
  5967. else {
  5968. texture = this.getWebGLTexture(image);
  5969. }
  5970. if (!texture) {
  5971. return;
  5972. }
  5973. this.drawTexture(texture, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, imageSourceWidth, imageSourceHeight, undefined, undefined, undefined, undefined, rotated, smoothing);
  5974. if (image.source && image.source["texture"]) {
  5975. buffer.$offsetX = offsetX;
  5976. buffer.$offsetY = offsetY;
  5977. buffer.restoreTransform();
  5978. }
  5979. };
  5980. /**
  5981. * 绘制Mesh
  5982. */
  5983. WebGLRenderContext.prototype.drawMesh = function (image, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, imageSourceWidth, imageSourceHeight, meshUVs, meshVertices, meshIndices, bounds, rotated, smoothing) {
  5984. var buffer = this.currentBuffer;
  5985. if (this.contextLost || !image || !buffer) {
  5986. return;
  5987. }
  5988. var texture;
  5989. var offsetX;
  5990. var offsetY;
  5991. if (image["texture"] || (image.source && image.source["texture"])) {
  5992. // 如果是render target
  5993. texture = image["texture"] || image.source["texture"];
  5994. buffer.saveTransform();
  5995. offsetX = buffer.$offsetX;
  5996. offsetY = buffer.$offsetY;
  5997. buffer.useOffset();
  5998. buffer.transform(1, 0, 0, -1, 0, destHeight + destY * 2); // 翻转
  5999. }
  6000. else if (!image.source && !image.webGLTexture) {
  6001. return;
  6002. }
  6003. else {
  6004. texture = this.getWebGLTexture(image);
  6005. }
  6006. if (!texture) {
  6007. return;
  6008. }
  6009. this.drawTexture(texture, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, imageSourceWidth, imageSourceHeight, meshUVs, meshVertices, meshIndices, bounds, rotated, smoothing);
  6010. if (image["texture"] || (image.source && image.source["texture"])) {
  6011. buffer.$offsetX = offsetX;
  6012. buffer.$offsetY = offsetY;
  6013. buffer.restoreTransform();
  6014. }
  6015. };
  6016. /**
  6017. * 绘制材质
  6018. */
  6019. WebGLRenderContext.prototype.drawTexture = function (texture, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, textureWidth, textureHeight, meshUVs, meshVertices, meshIndices, bounds, rotated, smoothing) {
  6020. var buffer = this.currentBuffer;
  6021. if (this.contextLost || !texture || !buffer) {
  6022. return;
  6023. }
  6024. if (meshVertices && meshIndices) {
  6025. if (this.vao.reachMaxSize(meshVertices.length / 2, meshIndices.length)) {
  6026. this.$drawWebGL();
  6027. }
  6028. }
  6029. else {
  6030. if (this.vao.reachMaxSize()) {
  6031. this.$drawWebGL();
  6032. }
  6033. }
  6034. if (smoothing != undefined && texture["smoothing"] != smoothing) {
  6035. this.drawCmdManager.pushChangeSmoothing(texture, smoothing);
  6036. }
  6037. if (meshUVs) {
  6038. this.vao.changeToMeshIndices();
  6039. }
  6040. var count = meshIndices ? meshIndices.length / 3 : 2;
  6041. // 应用$filter,因为只可能是colorMatrixFilter,最后两个参数可不传
  6042. this.drawCmdManager.pushDrawTexture(texture, count, this.$filter, textureWidth, textureHeight);
  6043. this.vao.cacheArrays(buffer, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, textureWidth, textureHeight, meshUVs, meshVertices, meshIndices, rotated);
  6044. };
  6045. /**
  6046. * 绘制矩形(仅用于遮罩擦除等)
  6047. */
  6048. WebGLRenderContext.prototype.drawRect = function (x, y, width, height) {
  6049. var buffer = this.currentBuffer;
  6050. if (this.contextLost || !buffer) {
  6051. return;
  6052. }
  6053. if (this.vao.reachMaxSize()) {
  6054. this.$drawWebGL();
  6055. }
  6056. this.drawCmdManager.pushDrawRect();
  6057. this.vao.cacheArrays(buffer, 0, 0, width, height, x, y, width, height, width, height);
  6058. };
  6059. /**
  6060. * 绘制遮罩
  6061. */
  6062. WebGLRenderContext.prototype.pushMask = function (x, y, width, height) {
  6063. var buffer = this.currentBuffer;
  6064. if (this.contextLost || !buffer) {
  6065. return;
  6066. }
  6067. buffer.$stencilList.push({ x: x, y: y, width: width, height: height });
  6068. if (this.vao.reachMaxSize()) {
  6069. this.$drawWebGL();
  6070. }
  6071. this.drawCmdManager.pushPushMask();
  6072. this.vao.cacheArrays(buffer, 0, 0, width, height, x, y, width, height, width, height);
  6073. };
  6074. /**
  6075. * 恢复遮罩
  6076. */
  6077. WebGLRenderContext.prototype.popMask = function () {
  6078. var buffer = this.currentBuffer;
  6079. if (this.contextLost || !buffer) {
  6080. return;
  6081. }
  6082. var mask = buffer.$stencilList.pop();
  6083. if (this.vao.reachMaxSize()) {
  6084. this.$drawWebGL();
  6085. }
  6086. this.drawCmdManager.pushPopMask();
  6087. this.vao.cacheArrays(buffer, 0, 0, mask.width, mask.height, mask.x, mask.y, mask.width, mask.height, mask.width, mask.height);
  6088. };
  6089. /**
  6090. * 清除颜色缓存
  6091. */
  6092. WebGLRenderContext.prototype.clear = function () {
  6093. this.drawCmdManager.pushClearColor();
  6094. };
  6095. /**
  6096. * 开启scissor test
  6097. */
  6098. WebGLRenderContext.prototype.enableScissor = function (x, y, width, height) {
  6099. var buffer = this.currentBuffer;
  6100. this.drawCmdManager.pushEnableScissor(x, y, width, height);
  6101. buffer.$hasScissor = true;
  6102. };
  6103. /**
  6104. * 关闭scissor test
  6105. */
  6106. WebGLRenderContext.prototype.disableScissor = function () {
  6107. var buffer = this.currentBuffer;
  6108. this.drawCmdManager.pushDisableScissor();
  6109. buffer.$hasScissor = false;
  6110. };
  6111. WebGLRenderContext.prototype.$drawWebGL = function () {
  6112. if (this.drawCmdManager.drawDataLen == 0 || this.contextLost) {
  6113. return;
  6114. }
  6115. this.uploadVerticesArray(this.vao.getVertices());
  6116. // 有mesh,则使用indicesForMesh
  6117. if (this.vao.isMesh()) {
  6118. this.uploadIndicesArray(this.vao.getMeshIndices());
  6119. }
  6120. var length = this.drawCmdManager.drawDataLen;
  6121. var offset = 0;
  6122. for (var i = 0; i < length; i++) {
  6123. var data = this.drawCmdManager.drawData[i];
  6124. offset = this.drawData(data, offset);
  6125. // 计算draw call
  6126. if (data.type == 7 /* ACT_BUFFER */) {
  6127. this.activatedBuffer = data.buffer;
  6128. }
  6129. if (data.type == 0 /* TEXTURE */ || data.type == 1 /* RECT */ || data.type == 2 /* PUSH_MASK */ || data.type == 3 /* POP_MASK */) {
  6130. if (this.activatedBuffer && this.activatedBuffer.$computeDrawCall) {
  6131. this.activatedBuffer.$drawCalls++;
  6132. }
  6133. }
  6134. }
  6135. // 切换回默认indices
  6136. if (this.vao.isMesh()) {
  6137. this.uploadIndicesArray(this.vao.getIndices());
  6138. }
  6139. // 清空数据
  6140. this.drawCmdManager.clear();
  6141. this.vao.clear();
  6142. };
  6143. /**
  6144. * 执行绘制命令
  6145. */
  6146. WebGLRenderContext.prototype.drawData = function (data, offset) {
  6147. if (!data) {
  6148. return;
  6149. }
  6150. var gl = this.context;
  6151. var program;
  6152. var filter = data.filter;
  6153. switch (data.type) {
  6154. case 0 /* TEXTURE */:
  6155. if (filter) {
  6156. if (filter.type === "custom") {
  6157. program = web.EgretWebGLProgram.getProgram(gl, filter.$vertexSrc, filter.$fragmentSrc, filter.$shaderKey);
  6158. }
  6159. else if (filter.type === "colorTransform") {
  6160. program = web.EgretWebGLProgram.getProgram(gl, web.EgretShaderLib.default_vert, web.EgretShaderLib.colorTransform_frag, "colorTransform");
  6161. }
  6162. else if (filter.type === "blurX") {
  6163. program = web.EgretWebGLProgram.getProgram(gl, web.EgretShaderLib.default_vert, web.EgretShaderLib.blur_frag, "blur");
  6164. }
  6165. else if (filter.type === "blurY") {
  6166. program = web.EgretWebGLProgram.getProgram(gl, web.EgretShaderLib.default_vert, web.EgretShaderLib.blur_frag, "blur");
  6167. }
  6168. else if (filter.type === "glow") {
  6169. program = web.EgretWebGLProgram.getProgram(gl, web.EgretShaderLib.default_vert, web.EgretShaderLib.glow_frag, "glow");
  6170. }
  6171. }
  6172. else {
  6173. program = web.EgretWebGLProgram.getProgram(gl, web.EgretShaderLib.default_vert, web.EgretShaderLib.texture_frag, "texture");
  6174. }
  6175. this.activeProgram(gl, program);
  6176. this.syncUniforms(program, filter, data.textureWidth, data.textureHeight);
  6177. offset += this.drawTextureElements(data, offset);
  6178. break;
  6179. case 1 /* RECT */:
  6180. program = web.EgretWebGLProgram.getProgram(gl, web.EgretShaderLib.default_vert, web.EgretShaderLib.primitive_frag, "primitive");
  6181. this.activeProgram(gl, program);
  6182. this.syncUniforms(program, filter, data.textureWidth, data.textureHeight);
  6183. offset += this.drawRectElements(data, offset);
  6184. break;
  6185. case 2 /* PUSH_MASK */:
  6186. program = web.EgretWebGLProgram.getProgram(gl, web.EgretShaderLib.default_vert, web.EgretShaderLib.primitive_frag, "primitive");
  6187. this.activeProgram(gl, program);
  6188. this.syncUniforms(program, filter, data.textureWidth, data.textureHeight);
  6189. offset += this.drawPushMaskElements(data, offset);
  6190. break;
  6191. case 3 /* POP_MASK */:
  6192. program = web.EgretWebGLProgram.getProgram(gl, web.EgretShaderLib.default_vert, web.EgretShaderLib.primitive_frag, "primitive");
  6193. this.activeProgram(gl, program);
  6194. this.syncUniforms(program, filter, data.textureWidth, data.textureHeight);
  6195. offset += this.drawPopMaskElements(data, offset);
  6196. break;
  6197. case 4 /* BLEND */:
  6198. this.setBlendMode(data.value);
  6199. break;
  6200. case 5 /* RESIZE_TARGET */:
  6201. data.buffer.rootRenderTarget.resize(data.width, data.height);
  6202. this.onResize(data.width, data.height);
  6203. break;
  6204. case 6 /* CLEAR_COLOR */:
  6205. if (this.activatedBuffer) {
  6206. var target = this.activatedBuffer.rootRenderTarget;
  6207. if (target.width != 0 || target.height != 0) {
  6208. target.clear(true);
  6209. }
  6210. }
  6211. break;
  6212. case 7 /* ACT_BUFFER */:
  6213. this.activateBuffer(data.buffer, data.width, data.height);
  6214. break;
  6215. case 8 /* ENABLE_SCISSOR */:
  6216. var buffer = this.activatedBuffer;
  6217. if (buffer) {
  6218. if (buffer.rootRenderTarget) {
  6219. buffer.rootRenderTarget.enabledStencil();
  6220. }
  6221. buffer.enableScissor(data.x, data.y, data.width, data.height);
  6222. }
  6223. break;
  6224. case 9 /* DISABLE_SCISSOR */:
  6225. buffer = this.activatedBuffer;
  6226. if (buffer) {
  6227. buffer.disableScissor();
  6228. }
  6229. break;
  6230. case 10 /* SMOOTHING */:
  6231. gl.bindTexture(gl.TEXTURE_2D, data.texture);
  6232. if (data.smoothing) {
  6233. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  6234. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  6235. }
  6236. else {
  6237. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  6238. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  6239. }
  6240. break;
  6241. default:
  6242. break;
  6243. }
  6244. return offset;
  6245. };
  6246. WebGLRenderContext.prototype.activeProgram = function (gl, program) {
  6247. if (program != this.currentProgram) {
  6248. gl.useProgram(program.id);
  6249. // 目前所有attribute buffer的绑定方法都是一致的
  6250. var attribute = program.attributes;
  6251. for (var key in attribute) {
  6252. if (key === "aVertexPosition") {
  6253. gl.vertexAttribPointer(attribute["aVertexPosition"].location, 2, gl.FLOAT, false, 5 * 4, 0);
  6254. gl.enableVertexAttribArray(attribute["aVertexPosition"].location);
  6255. }
  6256. else if (key === "aTextureCoord") {
  6257. gl.vertexAttribPointer(attribute["aTextureCoord"].location, 2, gl.FLOAT, false, 5 * 4, 2 * 4);
  6258. gl.enableVertexAttribArray(attribute["aTextureCoord"].location);
  6259. }
  6260. else if (key === "aColor") {
  6261. gl.vertexAttribPointer(attribute["aColor"].location, 1, gl.FLOAT, false, 5 * 4, 4 * 4);
  6262. gl.enableVertexAttribArray(attribute["aColor"].location);
  6263. }
  6264. }
  6265. this.currentProgram = program;
  6266. }
  6267. };
  6268. WebGLRenderContext.prototype.syncUniforms = function (program, filter, textureWidth, textureHeight) {
  6269. var uniforms = program.uniforms;
  6270. var isCustomFilter = filter && filter.type === "custom";
  6271. for (var key in uniforms) {
  6272. if (key === "projectionVector") {
  6273. uniforms[key].setValue({ x: this.projectionX, y: this.projectionY });
  6274. }
  6275. else if (key === "uTextureSize") {
  6276. uniforms[key].setValue({ x: textureWidth, y: textureHeight });
  6277. }
  6278. else if (key === "uSampler") {
  6279. }
  6280. else {
  6281. var value = filter.$uniforms[key];
  6282. if (value !== undefined) {
  6283. uniforms[key].setValue(value);
  6284. }
  6285. else {
  6286. // egret.warn("filter custom: uniform " + key + " not defined!");
  6287. }
  6288. }
  6289. }
  6290. };
  6291. /**
  6292. * 画texture
  6293. **/
  6294. WebGLRenderContext.prototype.drawTextureElements = function (data, offset) {
  6295. var gl = this.context;
  6296. gl.bindTexture(gl.TEXTURE_2D, data.texture);
  6297. var size = data.count * 3;
  6298. gl.drawElements(gl.TRIANGLES, size, gl.UNSIGNED_SHORT, offset * 2);
  6299. return size;
  6300. };
  6301. /**
  6302. * @private
  6303. * 画rect
  6304. **/
  6305. WebGLRenderContext.prototype.drawRectElements = function (data, offset) {
  6306. var gl = this.context;
  6307. // gl.bindTexture(gl.TEXTURE_2D, null);
  6308. var size = data.count * 3;
  6309. gl.drawElements(gl.TRIANGLES, size, gl.UNSIGNED_SHORT, offset * 2);
  6310. return size;
  6311. };
  6312. /**
  6313. * 画push mask
  6314. **/
  6315. WebGLRenderContext.prototype.drawPushMaskElements = function (data, offset) {
  6316. var gl = this.context;
  6317. var size = data.count * 3;
  6318. var buffer = this.activatedBuffer;
  6319. if (buffer) {
  6320. if (buffer.rootRenderTarget) {
  6321. buffer.rootRenderTarget.enabledStencil();
  6322. }
  6323. if (buffer.stencilHandleCount == 0) {
  6324. buffer.enableStencil();
  6325. gl.clear(gl.STENCIL_BUFFER_BIT); // clear
  6326. }
  6327. var level = buffer.stencilHandleCount;
  6328. buffer.stencilHandleCount++;
  6329. gl.colorMask(false, false, false, false);
  6330. gl.stencilFunc(gl.EQUAL, level, 0xFF);
  6331. gl.stencilOp(gl.KEEP, gl.KEEP, gl.INCR);
  6332. // gl.bindTexture(gl.TEXTURE_2D, null);
  6333. gl.drawElements(gl.TRIANGLES, size, gl.UNSIGNED_SHORT, offset * 2);
  6334. gl.stencilFunc(gl.EQUAL, level + 1, 0xFF);
  6335. gl.colorMask(true, true, true, true);
  6336. gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
  6337. }
  6338. return size;
  6339. };
  6340. /**
  6341. * 画pop mask
  6342. **/
  6343. WebGLRenderContext.prototype.drawPopMaskElements = function (data, offset) {
  6344. var gl = this.context;
  6345. var size = data.count * 3;
  6346. var buffer = this.activatedBuffer;
  6347. if (buffer) {
  6348. buffer.stencilHandleCount--;
  6349. if (buffer.stencilHandleCount == 0) {
  6350. buffer.disableStencil(); // skip this draw
  6351. }
  6352. else {
  6353. var level = buffer.stencilHandleCount;
  6354. gl.colorMask(false, false, false, false);
  6355. gl.stencilFunc(gl.EQUAL, level + 1, 0xFF);
  6356. gl.stencilOp(gl.KEEP, gl.KEEP, gl.DECR);
  6357. // gl.bindTexture(gl.TEXTURE_2D, null);
  6358. gl.drawElements(gl.TRIANGLES, size, gl.UNSIGNED_SHORT, offset * 2);
  6359. gl.stencilFunc(gl.EQUAL, level, 0xFF);
  6360. gl.colorMask(true, true, true, true);
  6361. gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
  6362. }
  6363. }
  6364. return size;
  6365. };
  6366. /**
  6367. * 设置混色
  6368. */
  6369. WebGLRenderContext.prototype.setBlendMode = function (value) {
  6370. var gl = this.context;
  6371. var blendModeWebGL = WebGLRenderContext.blendModesForGL[value];
  6372. if (blendModeWebGL) {
  6373. gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]);
  6374. }
  6375. };
  6376. /**
  6377. * 应用滤镜绘制给定的render target
  6378. * 此方法不会导致input被释放,所以如果需要释放input,需要调用此方法后手动调用release
  6379. */
  6380. WebGLRenderContext.prototype.drawTargetWidthFilters = function (filters, input) {
  6381. var originInput = input, filtersLen = filters.length, output;
  6382. // 应用前面的滤镜
  6383. if (filtersLen > 1) {
  6384. for (var i = 0; i < filtersLen - 1; i++) {
  6385. var filter_1 = filters[i];
  6386. var width = input.rootRenderTarget.width;
  6387. var height = input.rootRenderTarget.height;
  6388. output = web.WebGLRenderBuffer.create(width, height);
  6389. output.setTransform(1, 0, 0, 1, 0, 0);
  6390. output.globalAlpha = 1;
  6391. this.drawToRenderTarget(filter_1, input, output);
  6392. if (input != originInput) {
  6393. web.WebGLRenderBuffer.release(input);
  6394. }
  6395. input = output;
  6396. }
  6397. }
  6398. // 应用最后一个滤镜并绘制到当前场景中
  6399. var filter = filters[filtersLen - 1];
  6400. this.drawToRenderTarget(filter, input, this.currentBuffer);
  6401. // 释放掉用于交换的buffer
  6402. if (input != originInput) {
  6403. web.WebGLRenderBuffer.release(input);
  6404. }
  6405. };
  6406. /**
  6407. * 向一个renderTarget中绘制
  6408. * */
  6409. WebGLRenderContext.prototype.drawToRenderTarget = function (filter, input, output) {
  6410. if (this.contextLost) {
  6411. return;
  6412. }
  6413. if (this.vao.reachMaxSize()) {
  6414. this.$drawWebGL();
  6415. }
  6416. this.pushBuffer(output);
  6417. var originInput = input, temp, width = input.rootRenderTarget.width, height = input.rootRenderTarget.height;
  6418. // 模糊滤镜分别处理blurX与blurY
  6419. if (filter.type == "blur") {
  6420. var blurXFilter = filter.blurXFilter;
  6421. var blurYFilter = filter.blurYFilter;
  6422. if (blurXFilter.blurX != 0 && blurYFilter.blurY != 0) {
  6423. temp = web.WebGLRenderBuffer.create(width, height);
  6424. temp.setTransform(1, 0, 0, 1, 0, 0);
  6425. temp.globalAlpha = 1;
  6426. this.drawToRenderTarget(filter.blurXFilter, input, temp);
  6427. if (input != originInput) {
  6428. web.WebGLRenderBuffer.release(input);
  6429. }
  6430. input = temp;
  6431. filter = blurYFilter;
  6432. }
  6433. else {
  6434. filter = blurXFilter.blurX === 0 ? blurYFilter : blurXFilter;
  6435. }
  6436. }
  6437. // 绘制input结果到舞台
  6438. output.saveTransform();
  6439. output.transform(1, 0, 0, -1, 0, height);
  6440. this.vao.cacheArrays(output, 0, 0, width, height, 0, 0, width, height, width, height);
  6441. output.restoreTransform();
  6442. this.drawCmdManager.pushDrawTexture(input.rootRenderTarget.texture, 2, filter, width, height);
  6443. // 释放掉input
  6444. if (input != originInput) {
  6445. web.WebGLRenderBuffer.release(input);
  6446. }
  6447. this.popBuffer();
  6448. };
  6449. WebGLRenderContext.initBlendMode = function () {
  6450. WebGLRenderContext.blendModesForGL = {};
  6451. WebGLRenderContext.blendModesForGL["source-over"] = [1, 771];
  6452. WebGLRenderContext.blendModesForGL["lighter"] = [1, 1];
  6453. WebGLRenderContext.blendModesForGL["lighter-in"] = [770, 771];
  6454. WebGLRenderContext.blendModesForGL["destination-out"] = [0, 771];
  6455. WebGLRenderContext.blendModesForGL["destination-in"] = [0, 770];
  6456. };
  6457. WebGLRenderContext.glContextId = 0;
  6458. WebGLRenderContext.blendModesForGL = null;
  6459. return WebGLRenderContext;
  6460. }());
  6461. web.WebGLRenderContext = WebGLRenderContext;
  6462. __reflect(WebGLRenderContext.prototype, "egret.web.WebGLRenderContext");
  6463. WebGLRenderContext.initBlendMode();
  6464. })(web = egret.web || (egret.web = {}));
  6465. })(egret || (egret = {}));
  6466. //////////////////////////////////////////////////////////////////////////////////////
  6467. //
  6468. // Copyright (c) 2014-present, Egret Technology.
  6469. // All rights reserved.
  6470. // Redistribution and use in source and binary forms, with or without
  6471. // modification, are permitted provided that the following conditions are met:
  6472. //
  6473. // * Redistributions of source code must retain the above copyright
  6474. // notice, this list of conditions and the following disclaimer.
  6475. // * Redistributions in binary form must reproduce the above copyright
  6476. // notice, this list of conditions and the following disclaimer in the
  6477. // documentation and/or other materials provided with the distribution.
  6478. // * Neither the name of the Egret nor the
  6479. // names of its contributors may be used to endorse or promote products
  6480. // derived from this software without specific prior written permission.
  6481. //
  6482. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  6483. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  6484. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  6485. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  6486. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6487. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  6488. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6489. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6490. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6491. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6492. //
  6493. //////////////////////////////////////////////////////////////////////////////////////
  6494. var egret;
  6495. (function (egret) {
  6496. var web;
  6497. (function (web) {
  6498. /**
  6499. * @private
  6500. * WebGL渲染缓存
  6501. */
  6502. var WebGLRenderBuffer = (function (_super) {
  6503. __extends(WebGLRenderBuffer, _super);
  6504. function WebGLRenderBuffer(width, height, root) {
  6505. var _this = _super.call(this) || this;
  6506. _this.globalAlpha = 1;
  6507. /**
  6508. * stencil state
  6509. * 模版开关状态
  6510. */
  6511. _this.stencilState = false;
  6512. _this.$stencilList = [];
  6513. _this.stencilHandleCount = 0;
  6514. /**
  6515. * scissor state
  6516. * scissor 开关状态
  6517. */
  6518. _this.$scissorState = false;
  6519. _this.scissorRect = new egret.Rectangle();
  6520. _this.$hasScissor = false;
  6521. _this.$drawCalls = 0;
  6522. _this.$computeDrawCall = false;
  6523. _this.globalMatrix = new egret.Matrix();
  6524. _this.savedGlobalMatrix = new egret.Matrix();
  6525. _this.$offsetX = 0;
  6526. _this.$offsetY = 0;
  6527. // 获取webglRenderContext
  6528. _this.context = web.WebGLRenderContext.getInstance(width, height);
  6529. if (egret.nativeRender) {
  6530. if (root) {
  6531. _this.surface = _this.context.surface;
  6532. }
  6533. else {
  6534. _this.surface = new egret_native.NativeRenderSurface(_this, width, height, root);
  6535. }
  6536. _this.rootRenderTarget = null;
  6537. return _this;
  6538. }
  6539. // buffer 对应的 render target
  6540. _this.rootRenderTarget = new web.WebGLRenderTarget(_this.context.context, 3, 3);
  6541. if (width && height) {
  6542. _this.resize(width, height);
  6543. }
  6544. // 如果是第一个加入的buffer,说明是舞台buffer
  6545. _this.root = root;
  6546. // 如果是用于舞台渲染的renderBuffer,则默认添加renderTarget到renderContext中,而且是第一个
  6547. if (_this.root) {
  6548. _this.context.pushBuffer(_this);
  6549. // 画布
  6550. _this.surface = _this.context.surface;
  6551. _this.$computeDrawCall = true;
  6552. }
  6553. else {
  6554. // 由于创建renderTarget造成的frameBuffer绑定,这里重置绑定
  6555. var lastBuffer = _this.context.activatedBuffer;
  6556. if (lastBuffer) {
  6557. lastBuffer.rootRenderTarget.activate();
  6558. }
  6559. _this.rootRenderTarget.initFrameBuffer();
  6560. _this.surface = _this.rootRenderTarget;
  6561. }
  6562. return _this;
  6563. }
  6564. WebGLRenderBuffer.prototype.enableStencil = function () {
  6565. if (!this.stencilState) {
  6566. this.context.enableStencilTest();
  6567. this.stencilState = true;
  6568. }
  6569. };
  6570. WebGLRenderBuffer.prototype.disableStencil = function () {
  6571. if (this.stencilState) {
  6572. this.context.disableStencilTest();
  6573. this.stencilState = false;
  6574. }
  6575. };
  6576. WebGLRenderBuffer.prototype.restoreStencil = function () {
  6577. if (this.stencilState) {
  6578. this.context.enableStencilTest();
  6579. }
  6580. else {
  6581. this.context.disableStencilTest();
  6582. }
  6583. };
  6584. WebGLRenderBuffer.prototype.enableScissor = function (x, y, width, height) {
  6585. if (!this.$scissorState) {
  6586. this.$scissorState = true;
  6587. this.scissorRect.setTo(x, y, width, height);
  6588. this.context.enableScissorTest(this.scissorRect);
  6589. }
  6590. };
  6591. WebGLRenderBuffer.prototype.disableScissor = function () {
  6592. if (this.$scissorState) {
  6593. this.$scissorState = false;
  6594. this.scissorRect.setEmpty();
  6595. this.context.disableScissorTest();
  6596. }
  6597. };
  6598. WebGLRenderBuffer.prototype.restoreScissor = function () {
  6599. if (this.$scissorState) {
  6600. this.context.enableScissorTest(this.scissorRect);
  6601. }
  6602. else {
  6603. this.context.disableScissorTest();
  6604. }
  6605. };
  6606. Object.defineProperty(WebGLRenderBuffer.prototype, "width", {
  6607. /**
  6608. * 渲染缓冲的宽度,以像素为单位。
  6609. * @readOnly
  6610. */
  6611. get: function () {
  6612. if (egret.nativeRender) {
  6613. return this.surface.width;
  6614. }
  6615. else {
  6616. return this.rootRenderTarget.width;
  6617. }
  6618. },
  6619. enumerable: true,
  6620. configurable: true
  6621. });
  6622. Object.defineProperty(WebGLRenderBuffer.prototype, "height", {
  6623. /**
  6624. * 渲染缓冲的高度,以像素为单位。
  6625. * @readOnly
  6626. */
  6627. get: function () {
  6628. if (egret.nativeRender) {
  6629. return this.surface.height;
  6630. }
  6631. else {
  6632. return this.rootRenderTarget.height;
  6633. }
  6634. },
  6635. enumerable: true,
  6636. configurable: true
  6637. });
  6638. /**
  6639. * 改变渲染缓冲的大小并清空缓冲区
  6640. * @param width 改变后的宽
  6641. * @param height 改变后的高
  6642. * @param useMaxSize 若传入true,则将改变后的尺寸与已有尺寸对比,保留较大的尺寸。
  6643. */
  6644. WebGLRenderBuffer.prototype.resize = function (width, height, useMaxSize) {
  6645. width = width || 1;
  6646. height = height || 1;
  6647. if (egret.nativeRender) {
  6648. this.surface.resize(width, height);
  6649. return;
  6650. }
  6651. this.context.pushBuffer(this);
  6652. // render target 尺寸重置
  6653. if (width != this.rootRenderTarget.width || height != this.rootRenderTarget.height) {
  6654. this.context.drawCmdManager.pushResize(this, width, height);
  6655. // 同步更改宽高
  6656. this.rootRenderTarget.width = width;
  6657. this.rootRenderTarget.height = height;
  6658. }
  6659. // 如果是舞台的渲染缓冲,执行resize,否则surface大小不随之改变
  6660. if (this.root) {
  6661. this.context.resize(width, height, useMaxSize);
  6662. }
  6663. this.context.clear();
  6664. this.context.popBuffer();
  6665. };
  6666. /**
  6667. * 获取指定区域的像素
  6668. */
  6669. WebGLRenderBuffer.prototype.getPixels = function (x, y, width, height) {
  6670. if (width === void 0) { width = 1; }
  6671. if (height === void 0) { height = 1; }
  6672. var pixels = new Uint8Array(4 * width * height);
  6673. if (egret.nativeRender) {
  6674. egret_native.activateBuffer(this);
  6675. egret_native.nrGetPixels(x, y, width, height, pixels);
  6676. egret_native.activateBuffer(null);
  6677. }
  6678. else {
  6679. var useFrameBuffer = this.rootRenderTarget.useFrameBuffer;
  6680. this.rootRenderTarget.useFrameBuffer = true;
  6681. this.rootRenderTarget.activate();
  6682. this.context.getPixels(x, y, width, height, pixels);
  6683. this.rootRenderTarget.useFrameBuffer = useFrameBuffer;
  6684. this.rootRenderTarget.activate();
  6685. }
  6686. //图像反转
  6687. var result = new Uint8Array(4 * width * height);
  6688. for (var i = 0; i < height; i++) {
  6689. for (var j = 0; j < width; j++) {
  6690. var index1 = (width * (height - i - 1) + j) * 4;
  6691. var index2 = (width * i + j) * 4;
  6692. var a = pixels[index2 + 3];
  6693. result[index1] = Math.round(pixels[index2] / a * 255);
  6694. result[index1 + 1] = Math.round(pixels[index2 + 1] / a * 255);
  6695. result[index1 + 2] = Math.round(pixels[index2 + 2] / a * 255);
  6696. result[index1 + 3] = pixels[index2 + 3];
  6697. }
  6698. }
  6699. return result;
  6700. };
  6701. /**
  6702. * 转换成base64字符串,如果图片(或者包含的图片)跨域,则返回null
  6703. * @param type 转换的类型,如: "image/png","image/jpeg"
  6704. */
  6705. WebGLRenderBuffer.prototype.toDataURL = function (type, encoderOptions) {
  6706. return this.context.surface.toDataURL(type, encoderOptions);
  6707. };
  6708. /**
  6709. * 销毁绘制对象
  6710. */
  6711. WebGLRenderBuffer.prototype.destroy = function () {
  6712. this.context.destroy();
  6713. };
  6714. WebGLRenderBuffer.prototype.onRenderFinish = function () {
  6715. this.$drawCalls = 0;
  6716. };
  6717. /**
  6718. * 交换frameBuffer中的图像到surface中
  6719. * @param width 宽度
  6720. * @param height 高度
  6721. */
  6722. WebGLRenderBuffer.prototype.drawFrameBufferToSurface = function (sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, clear) {
  6723. if (clear === void 0) { clear = false; }
  6724. this.rootRenderTarget.useFrameBuffer = false;
  6725. this.rootRenderTarget.activate();
  6726. this.context.disableStencilTest(); // 切换frameBuffer注意要禁用STENCIL_TEST
  6727. this.context.disableScissorTest();
  6728. this.setTransform(1, 0, 0, 1, 0, 0);
  6729. this.globalAlpha = 1;
  6730. this.context.setGlobalCompositeOperation("source-over");
  6731. clear && this.context.clear();
  6732. this.context.drawImage(this.rootRenderTarget, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, sourceWidth, sourceHeight, false);
  6733. this.context.$drawWebGL();
  6734. this.rootRenderTarget.useFrameBuffer = true;
  6735. this.rootRenderTarget.activate();
  6736. this.restoreStencil();
  6737. this.restoreScissor();
  6738. };
  6739. /**
  6740. * 交换surface的图像到frameBuffer中
  6741. * @param width 宽度
  6742. * @param height 高度
  6743. */
  6744. WebGLRenderBuffer.prototype.drawSurfaceToFrameBuffer = function (sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, clear) {
  6745. if (clear === void 0) { clear = false; }
  6746. this.rootRenderTarget.useFrameBuffer = true;
  6747. this.rootRenderTarget.activate();
  6748. this.context.disableStencilTest(); // 切换frameBuffer注意要禁用STENCIL_TEST
  6749. this.context.disableScissorTest();
  6750. this.setTransform(1, 0, 0, 1, 0, 0);
  6751. this.globalAlpha = 1;
  6752. this.context.setGlobalCompositeOperation("source-over");
  6753. clear && this.context.clear();
  6754. this.context.drawImage(this.context.surface, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, sourceWidth, sourceHeight, false);
  6755. this.context.$drawWebGL();
  6756. this.rootRenderTarget.useFrameBuffer = false;
  6757. this.rootRenderTarget.activate();
  6758. this.restoreStencil();
  6759. this.restoreScissor();
  6760. };
  6761. /**
  6762. * 清空缓冲区数据
  6763. */
  6764. WebGLRenderBuffer.prototype.clear = function () {
  6765. this.context.pushBuffer(this);
  6766. this.context.clear();
  6767. this.context.popBuffer();
  6768. };
  6769. WebGLRenderBuffer.prototype.setTransform = function (a, b, c, d, tx, ty) {
  6770. // this.globalMatrix.setTo(a, b, c, d, tx, ty);
  6771. var matrix = this.globalMatrix;
  6772. matrix.a = a;
  6773. matrix.b = b;
  6774. matrix.c = c;
  6775. matrix.d = d;
  6776. matrix.tx = tx;
  6777. matrix.ty = ty;
  6778. };
  6779. WebGLRenderBuffer.prototype.transform = function (a, b, c, d, tx, ty) {
  6780. var matrix = this.globalMatrix;
  6781. var a1 = matrix.a;
  6782. var b1 = matrix.b;
  6783. var c1 = matrix.c;
  6784. var d1 = matrix.d;
  6785. if (a != 1 || b != 0 || c != 0 || d != 1) {
  6786. matrix.a = a * a1 + b * c1;
  6787. matrix.b = a * b1 + b * d1;
  6788. matrix.c = c * a1 + d * c1;
  6789. matrix.d = c * b1 + d * d1;
  6790. }
  6791. matrix.tx = tx * a1 + ty * c1 + matrix.tx;
  6792. matrix.ty = tx * b1 + ty * d1 + matrix.ty;
  6793. };
  6794. WebGLRenderBuffer.prototype.useOffset = function () {
  6795. var self = this;
  6796. if (self.$offsetX != 0 || self.$offsetY != 0) {
  6797. self.globalMatrix.append(1, 0, 0, 1, self.$offsetX, self.$offsetY);
  6798. self.$offsetX = self.$offsetY = 0;
  6799. }
  6800. };
  6801. WebGLRenderBuffer.prototype.saveTransform = function () {
  6802. var matrix = this.globalMatrix;
  6803. var sMatrix = this.savedGlobalMatrix;
  6804. sMatrix.a = matrix.a;
  6805. sMatrix.b = matrix.b;
  6806. sMatrix.c = matrix.c;
  6807. sMatrix.d = matrix.d;
  6808. sMatrix.tx = matrix.tx;
  6809. sMatrix.ty = matrix.ty;
  6810. };
  6811. WebGLRenderBuffer.prototype.restoreTransform = function () {
  6812. var matrix = this.globalMatrix;
  6813. var sMatrix = this.savedGlobalMatrix;
  6814. matrix.a = sMatrix.a;
  6815. matrix.b = sMatrix.b;
  6816. matrix.c = sMatrix.c;
  6817. matrix.d = sMatrix.d;
  6818. matrix.tx = sMatrix.tx;
  6819. matrix.ty = sMatrix.ty;
  6820. };
  6821. /**
  6822. * 创建一个buffer实例
  6823. */
  6824. WebGLRenderBuffer.create = function (width, height) {
  6825. var buffer = renderBufferPool.pop();
  6826. // width = Math.min(width, 1024);
  6827. // height = Math.min(height, 1024);
  6828. if (buffer) {
  6829. buffer.resize(width, height);
  6830. var matrix = buffer.globalMatrix;
  6831. matrix.a = 1;
  6832. matrix.b = 0;
  6833. matrix.c = 0;
  6834. matrix.d = 1;
  6835. matrix.tx = 0;
  6836. matrix.ty = 0;
  6837. buffer.globalAlpha = 1;
  6838. buffer.$offsetX = 0;
  6839. buffer.$offsetY = 0;
  6840. }
  6841. else {
  6842. buffer = new WebGLRenderBuffer(width, height);
  6843. buffer.$computeDrawCall = false;
  6844. }
  6845. return buffer;
  6846. };
  6847. /**
  6848. * 回收一个buffer实例
  6849. */
  6850. WebGLRenderBuffer.release = function (buffer) {
  6851. renderBufferPool.push(buffer);
  6852. };
  6853. WebGLRenderBuffer.autoClear = true;
  6854. return WebGLRenderBuffer;
  6855. }(egret.HashObject));
  6856. web.WebGLRenderBuffer = WebGLRenderBuffer;
  6857. __reflect(WebGLRenderBuffer.prototype, "egret.web.WebGLRenderBuffer", ["egret.sys.RenderBuffer"]);
  6858. var renderBufferPool = []; //渲染缓冲区对象池
  6859. })(web = egret.web || (egret.web = {}));
  6860. })(egret || (egret = {}));
  6861. //////////////////////////////////////////////////////////////////////////////////////
  6862. //
  6863. // Copyright (c) 2014-present, Egret Technology.
  6864. // All rights reserved.
  6865. // Redistribution and use in source and binary forms, with or without
  6866. // modification, are permitted provided that the following conditions are met:
  6867. //
  6868. // * Redistributions of source code must retain the above copyright
  6869. // notice, this list of conditions and the following disclaimer.
  6870. // * Redistributions in binary form must reproduce the above copyright
  6871. // notice, this list of conditions and the following disclaimer in the
  6872. // documentation and/or other materials provided with the distribution.
  6873. // * Neither the name of the Egret nor the
  6874. // names of its contributors may be used to endorse or promote products
  6875. // derived from this software without specific prior written permission.
  6876. //
  6877. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  6878. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  6879. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  6880. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  6881. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6882. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  6883. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6884. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6885. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6886. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6887. //
  6888. //////////////////////////////////////////////////////////////////////////////////////
  6889. var egret;
  6890. (function (egret) {
  6891. var web;
  6892. (function (web) {
  6893. var blendModes = ["source-over", "lighter", "destination-out"];
  6894. var defaultCompositeOp = "source-over";
  6895. var BLACK_COLOR = "#000000";
  6896. var CAPS_STYLES = { none: 'butt', square: 'square', round: 'round' };
  6897. var renderBufferPool = []; //渲染缓冲区对象池
  6898. /**
  6899. * @private
  6900. * WebGL渲染器
  6901. */
  6902. var WebGLRenderer = (function () {
  6903. function WebGLRenderer() {
  6904. this.nestLevel = 0; //渲染的嵌套层次,0表示在调用堆栈的最外层。
  6905. }
  6906. /**
  6907. * 渲染一个显示对象
  6908. * @param displayObject 要渲染的显示对象
  6909. * @param buffer 渲染缓冲
  6910. * @param matrix 要对显示对象整体叠加的变换矩阵
  6911. * @param dirtyList 脏矩形列表
  6912. * @param forRenderTexture 绘制目标是RenderTexture的标志
  6913. * @returns drawCall触发绘制的次数
  6914. */
  6915. WebGLRenderer.prototype.render = function (displayObject, buffer, matrix, forRenderTexture) {
  6916. this.nestLevel++;
  6917. var webglBuffer = buffer;
  6918. var webglBufferContext = webglBuffer.context;
  6919. var root = forRenderTexture ? displayObject : null;
  6920. webglBufferContext.pushBuffer(webglBuffer);
  6921. //绘制显示对象
  6922. webglBuffer.transform(matrix.a, matrix.b, matrix.c, matrix.d, 0, 0);
  6923. this.drawDisplayObject(displayObject, webglBuffer, matrix.tx, matrix.ty, true);
  6924. webglBufferContext.$drawWebGL();
  6925. var drawCall = webglBuffer.$drawCalls;
  6926. webglBuffer.onRenderFinish();
  6927. webglBufferContext.popBuffer();
  6928. var invert = egret.Matrix.create();
  6929. matrix.$invertInto(invert);
  6930. webglBuffer.transform(invert.a, invert.b, invert.c, invert.d, 0, 0);
  6931. egret.Matrix.release(invert);
  6932. this.nestLevel--;
  6933. if (this.nestLevel === 0) {
  6934. //最大缓存6个渲染缓冲
  6935. if (renderBufferPool.length > 6) {
  6936. renderBufferPool.length = 6;
  6937. }
  6938. var length_3 = renderBufferPool.length;
  6939. for (var i = 0; i < length_3; i++) {
  6940. renderBufferPool[i].resize(0, 0);
  6941. }
  6942. }
  6943. return drawCall;
  6944. };
  6945. /**
  6946. * @private
  6947. * 绘制一个显示对象
  6948. */
  6949. WebGLRenderer.prototype.drawDisplayObject = function (displayObject, buffer, offsetX, offsetY, isStage) {
  6950. var drawCalls = 0;
  6951. var node;
  6952. var displayList = displayObject.$displayList;
  6953. if (displayList && !isStage) {
  6954. if (displayObject.$cacheDirty || displayObject.$renderDirty ||
  6955. displayList.$canvasScaleX != egret.sys.DisplayList.$canvasScaleX ||
  6956. displayList.$canvasScaleY != egret.sys.DisplayList.$canvasScaleY) {
  6957. drawCalls += displayList.drawToSurface();
  6958. }
  6959. node = displayList.$renderNode;
  6960. }
  6961. else {
  6962. if (displayObject.$renderDirty) {
  6963. node = displayObject.$getRenderNode();
  6964. }
  6965. else {
  6966. node = displayObject.$renderNode;
  6967. }
  6968. }
  6969. displayObject.$cacheDirty = false;
  6970. if (node) {
  6971. drawCalls++;
  6972. buffer.$offsetX = offsetX;
  6973. buffer.$offsetY = offsetY;
  6974. switch (node.type) {
  6975. case 1 /* BitmapNode */:
  6976. this.renderBitmap(node, buffer);
  6977. break;
  6978. case 2 /* TextNode */:
  6979. this.renderText(node, buffer);
  6980. break;
  6981. case 3 /* GraphicsNode */:
  6982. this.renderGraphics(node, buffer);
  6983. break;
  6984. case 4 /* GroupNode */:
  6985. this.renderGroup(node, buffer);
  6986. break;
  6987. case 5 /* MeshNode */:
  6988. this.renderMesh(node, buffer);
  6989. break;
  6990. case 6 /* NormalBitmapNode */:
  6991. this.renderNormalBitmap(node, buffer);
  6992. break;
  6993. }
  6994. buffer.$offsetX = 0;
  6995. buffer.$offsetY = 0;
  6996. }
  6997. if (displayList && !isStage) {
  6998. return drawCalls;
  6999. }
  7000. var children = displayObject.$children;
  7001. if (children) {
  7002. var length_4 = children.length;
  7003. for (var i = 0; i < length_4; i++) {
  7004. var child = children[i];
  7005. var offsetX2 = void 0;
  7006. var offsetY2 = void 0;
  7007. var tempAlpha = void 0;
  7008. if (child.$alpha != 1) {
  7009. tempAlpha = buffer.globalAlpha;
  7010. buffer.globalAlpha *= child.$alpha;
  7011. }
  7012. var savedMatrix = void 0;
  7013. if (child.$useTranslate) {
  7014. var m = child.$getMatrix();
  7015. offsetX2 = offsetX + child.$x;
  7016. offsetY2 = offsetY + child.$y;
  7017. var m2 = buffer.globalMatrix;
  7018. savedMatrix = egret.Matrix.create();
  7019. savedMatrix.a = m2.a;
  7020. savedMatrix.b = m2.b;
  7021. savedMatrix.c = m2.c;
  7022. savedMatrix.d = m2.d;
  7023. savedMatrix.tx = m2.tx;
  7024. savedMatrix.ty = m2.ty;
  7025. buffer.transform(m.a, m.b, m.c, m.d, offsetX2, offsetY2);
  7026. offsetX2 = -child.$anchorOffsetX;
  7027. offsetY2 = -child.$anchorOffsetY;
  7028. }
  7029. else {
  7030. offsetX2 = offsetX + child.$x - child.$anchorOffsetX;
  7031. offsetY2 = offsetY + child.$y - child.$anchorOffsetY;
  7032. }
  7033. switch (child.$renderMode) {
  7034. case 1 /* NONE */:
  7035. break;
  7036. case 2 /* FILTER */:
  7037. drawCalls += this.drawWithFilter(child, buffer, offsetX2, offsetY2);
  7038. break;
  7039. case 3 /* CLIP */:
  7040. drawCalls += this.drawWithClip(child, buffer, offsetX2, offsetY2);
  7041. break;
  7042. case 4 /* SCROLLRECT */:
  7043. drawCalls += this.drawWithScrollRect(child, buffer, offsetX2, offsetY2);
  7044. break;
  7045. default:
  7046. drawCalls += this.drawDisplayObject(child, buffer, offsetX2, offsetY2);
  7047. break;
  7048. }
  7049. if (tempAlpha) {
  7050. buffer.globalAlpha = tempAlpha;
  7051. }
  7052. if (savedMatrix) {
  7053. var m = buffer.globalMatrix;
  7054. m.a = savedMatrix.a;
  7055. m.b = savedMatrix.b;
  7056. m.c = savedMatrix.c;
  7057. m.d = savedMatrix.d;
  7058. m.tx = savedMatrix.tx;
  7059. m.ty = savedMatrix.ty;
  7060. egret.Matrix.release(savedMatrix);
  7061. }
  7062. }
  7063. }
  7064. return drawCalls;
  7065. };
  7066. /**
  7067. * @private
  7068. */
  7069. WebGLRenderer.prototype.drawWithFilter = function (displayObject, buffer, offsetX, offsetY) {
  7070. var drawCalls = 0;
  7071. if (displayObject.$children && displayObject.$children.length == 0 && (!displayObject.$renderNode || displayObject.$renderNode.$getRenderCount() == 0)) {
  7072. return drawCalls;
  7073. }
  7074. var filters = displayObject.$filters;
  7075. var hasBlendMode = (displayObject.$blendMode !== 0);
  7076. var compositeOp;
  7077. if (hasBlendMode) {
  7078. compositeOp = blendModes[displayObject.$blendMode];
  7079. if (!compositeOp) {
  7080. compositeOp = defaultCompositeOp;
  7081. }
  7082. }
  7083. var displayBounds = displayObject.$getOriginalBounds();
  7084. var displayBoundsX = displayBounds.x;
  7085. var displayBoundsY = displayBounds.y;
  7086. var displayBoundsWidth = displayBounds.width;
  7087. var displayBoundsHeight = displayBounds.height;
  7088. if (displayBoundsWidth <= 0 || displayBoundsHeight <= 0) {
  7089. return drawCalls;
  7090. }
  7091. if (!displayObject.mask && filters.length == 1 && (filters[0].type == "colorTransform" || (filters[0].type === "custom" && filters[0].padding === 0))) {
  7092. var childrenDrawCount = this.getRenderCount(displayObject);
  7093. if (!displayObject.$children || childrenDrawCount == 1) {
  7094. if (hasBlendMode) {
  7095. buffer.context.setGlobalCompositeOperation(compositeOp);
  7096. }
  7097. buffer.context.$filter = filters[0];
  7098. if (displayObject.$mask) {
  7099. drawCalls += this.drawWithClip(displayObject, buffer, offsetX, offsetY);
  7100. }
  7101. else if (displayObject.$scrollRect || displayObject.$maskRect) {
  7102. drawCalls += this.drawWithScrollRect(displayObject, buffer, offsetX, offsetY);
  7103. }
  7104. else {
  7105. drawCalls += this.drawDisplayObject(displayObject, buffer, offsetX, offsetY);
  7106. }
  7107. buffer.context.$filter = null;
  7108. if (hasBlendMode) {
  7109. buffer.context.setGlobalCompositeOperation(defaultCompositeOp);
  7110. }
  7111. return drawCalls;
  7112. }
  7113. }
  7114. // 为显示对象创建一个新的buffer
  7115. var displayBuffer = this.createRenderBuffer(displayBoundsWidth, displayBoundsHeight);
  7116. displayBuffer.context.pushBuffer(displayBuffer);
  7117. //todo 可以优化减少draw次数
  7118. if (displayObject.$mask) {
  7119. drawCalls += this.drawWithClip(displayObject, displayBuffer, -displayBoundsX, -displayBoundsY);
  7120. }
  7121. else if (displayObject.$scrollRect || displayObject.$maskRect) {
  7122. drawCalls += this.drawWithScrollRect(displayObject, displayBuffer, -displayBoundsX, -displayBoundsY);
  7123. }
  7124. else {
  7125. drawCalls += this.drawDisplayObject(displayObject, displayBuffer, -displayBoundsX, -displayBoundsY);
  7126. }
  7127. displayBuffer.context.popBuffer();
  7128. //绘制结果到屏幕
  7129. if (drawCalls > 0) {
  7130. if (hasBlendMode) {
  7131. buffer.context.setGlobalCompositeOperation(compositeOp);
  7132. }
  7133. drawCalls++;
  7134. // 绘制结果的时候,应用滤镜
  7135. buffer.$offsetX = offsetX + displayBoundsX;
  7136. buffer.$offsetY = offsetY + displayBoundsY;
  7137. var savedMatrix = egret.Matrix.create();
  7138. var curMatrix = buffer.globalMatrix;
  7139. savedMatrix.a = curMatrix.a;
  7140. savedMatrix.b = curMatrix.b;
  7141. savedMatrix.c = curMatrix.c;
  7142. savedMatrix.d = curMatrix.d;
  7143. savedMatrix.tx = curMatrix.tx;
  7144. savedMatrix.ty = curMatrix.ty;
  7145. buffer.useOffset();
  7146. buffer.context.drawTargetWidthFilters(filters, displayBuffer);
  7147. curMatrix.a = savedMatrix.a;
  7148. curMatrix.b = savedMatrix.b;
  7149. curMatrix.c = savedMatrix.c;
  7150. curMatrix.d = savedMatrix.d;
  7151. curMatrix.tx = savedMatrix.tx;
  7152. curMatrix.ty = savedMatrix.ty;
  7153. egret.Matrix.release(savedMatrix);
  7154. if (hasBlendMode) {
  7155. buffer.context.setGlobalCompositeOperation(defaultCompositeOp);
  7156. }
  7157. }
  7158. renderBufferPool.push(displayBuffer);
  7159. return drawCalls;
  7160. };
  7161. WebGLRenderer.prototype.getRenderCount = function (displayObject) {
  7162. var drawCount = 0;
  7163. var node = displayObject.$getRenderNode();
  7164. if (node) {
  7165. drawCount += node.$getRenderCount();
  7166. }
  7167. if (displayObject.$children) {
  7168. for (var _i = 0, _a = displayObject.$children; _i < _a.length; _i++) {
  7169. var child = _a[_i];
  7170. var filters = child.$filters;
  7171. // 特殊处理有滤镜的对象
  7172. if (filters && filters.length > 0) {
  7173. return 2;
  7174. }
  7175. else if (child.$children) {
  7176. drawCount += this.getRenderCount(child);
  7177. }
  7178. else {
  7179. var node_1 = child.$getRenderNode();
  7180. if (node_1) {
  7181. drawCount += node_1.$getRenderCount();
  7182. }
  7183. }
  7184. }
  7185. }
  7186. return drawCount;
  7187. };
  7188. /**
  7189. * @private
  7190. */
  7191. WebGLRenderer.prototype.drawWithClip = function (displayObject, buffer, offsetX, offsetY) {
  7192. var drawCalls = 0;
  7193. var hasBlendMode = (displayObject.$blendMode !== 0);
  7194. var compositeOp;
  7195. if (hasBlendMode) {
  7196. compositeOp = blendModes[displayObject.$blendMode];
  7197. if (!compositeOp) {
  7198. compositeOp = defaultCompositeOp;
  7199. }
  7200. }
  7201. var scrollRect = displayObject.$scrollRect ? displayObject.$scrollRect : displayObject.$maskRect;
  7202. var mask = displayObject.$mask;
  7203. if (mask) {
  7204. var maskRenderMatrix = mask.$getMatrix();
  7205. //遮罩scaleX或scaleY为0,放弃绘制
  7206. if ((maskRenderMatrix.a == 0 && maskRenderMatrix.b == 0) || (maskRenderMatrix.c == 0 && maskRenderMatrix.d == 0)) {
  7207. return drawCalls;
  7208. }
  7209. }
  7210. //没有遮罩,同时显示对象没有子项
  7211. if (!mask && (!displayObject.$children || displayObject.$children.length == 0)) {
  7212. if (scrollRect) {
  7213. buffer.context.pushMask(scrollRect.x + offsetX, scrollRect.y + offsetY, scrollRect.width, scrollRect.height);
  7214. }
  7215. //绘制显示对象
  7216. if (hasBlendMode) {
  7217. buffer.context.setGlobalCompositeOperation(compositeOp);
  7218. }
  7219. drawCalls += this.drawDisplayObject(displayObject, buffer, offsetX, offsetY);
  7220. if (hasBlendMode) {
  7221. buffer.context.setGlobalCompositeOperation(defaultCompositeOp);
  7222. }
  7223. if (scrollRect) {
  7224. buffer.context.popMask();
  7225. }
  7226. return drawCalls;
  7227. }
  7228. else {
  7229. var displayBounds = displayObject.$getOriginalBounds();
  7230. var displayBoundsX = displayBounds.x;
  7231. var displayBoundsY = displayBounds.y;
  7232. var displayBoundsWidth = displayBounds.width;
  7233. var displayBoundsHeight = displayBounds.height;
  7234. if (displayBoundsWidth <= 0 || displayBoundsHeight <= 0) {
  7235. return drawCalls;
  7236. }
  7237. //绘制显示对象自身,若有scrollRect,应用clip
  7238. var displayBuffer = this.createRenderBuffer(displayBoundsWidth, displayBoundsHeight);
  7239. displayBuffer.context.pushBuffer(displayBuffer);
  7240. drawCalls += this.drawDisplayObject(displayObject, displayBuffer, -displayBoundsX, -displayBoundsY);
  7241. //绘制遮罩
  7242. if (mask) {
  7243. var maskBuffer = this.createRenderBuffer(displayBoundsWidth, displayBoundsHeight);
  7244. maskBuffer.context.pushBuffer(maskBuffer);
  7245. var maskMatrix = egret.Matrix.create();
  7246. maskMatrix.copyFrom(mask.$getConcatenatedMatrix());
  7247. mask.$getConcatenatedMatrixAt(displayObject, maskMatrix);
  7248. maskMatrix.translate(-displayBoundsX, -displayBoundsY);
  7249. maskBuffer.setTransform(maskMatrix.a, maskMatrix.b, maskMatrix.c, maskMatrix.d, maskMatrix.tx, maskMatrix.ty);
  7250. egret.Matrix.release(maskMatrix);
  7251. drawCalls += this.drawDisplayObject(mask, maskBuffer, 0, 0);
  7252. maskBuffer.context.popBuffer();
  7253. displayBuffer.context.setGlobalCompositeOperation("destination-in");
  7254. displayBuffer.setTransform(1, 0, 0, -1, 0, maskBuffer.height);
  7255. var maskBufferWidth = maskBuffer.rootRenderTarget.width;
  7256. var maskBufferHeight = maskBuffer.rootRenderTarget.height;
  7257. displayBuffer.context.drawTexture(maskBuffer.rootRenderTarget.texture, 0, 0, maskBufferWidth, maskBufferHeight, 0, 0, maskBufferWidth, maskBufferHeight, maskBufferWidth, maskBufferHeight);
  7258. displayBuffer.setTransform(1, 0, 0, 1, 0, 0);
  7259. displayBuffer.context.setGlobalCompositeOperation("source-over");
  7260. maskBuffer.setTransform(1, 0, 0, 1, 0, 0);
  7261. renderBufferPool.push(maskBuffer);
  7262. }
  7263. displayBuffer.context.setGlobalCompositeOperation(defaultCompositeOp);
  7264. displayBuffer.context.popBuffer();
  7265. //绘制结果到屏幕
  7266. if (drawCalls > 0) {
  7267. drawCalls++;
  7268. if (hasBlendMode) {
  7269. buffer.context.setGlobalCompositeOperation(compositeOp);
  7270. }
  7271. if (scrollRect) {
  7272. buffer.context.pushMask(scrollRect.x + offsetX, scrollRect.y + offsetY, scrollRect.width, scrollRect.height);
  7273. }
  7274. var savedMatrix = egret.Matrix.create();
  7275. var curMatrix = buffer.globalMatrix;
  7276. savedMatrix.a = curMatrix.a;
  7277. savedMatrix.b = curMatrix.b;
  7278. savedMatrix.c = curMatrix.c;
  7279. savedMatrix.d = curMatrix.d;
  7280. savedMatrix.tx = curMatrix.tx;
  7281. savedMatrix.ty = curMatrix.ty;
  7282. curMatrix.append(1, 0, 0, -1, offsetX + displayBoundsX, offsetY + displayBoundsY + displayBuffer.height);
  7283. var displayBufferWidth = displayBuffer.rootRenderTarget.width;
  7284. var displayBufferHeight = displayBuffer.rootRenderTarget.height;
  7285. buffer.context.drawTexture(displayBuffer.rootRenderTarget.texture, 0, 0, displayBufferWidth, displayBufferHeight, 0, 0, displayBufferWidth, displayBufferHeight, displayBufferWidth, displayBufferHeight);
  7286. if (scrollRect) {
  7287. displayBuffer.context.popMask();
  7288. }
  7289. if (hasBlendMode) {
  7290. buffer.context.setGlobalCompositeOperation(defaultCompositeOp);
  7291. }
  7292. var matrix = buffer.globalMatrix;
  7293. matrix.a = savedMatrix.a;
  7294. matrix.b = savedMatrix.b;
  7295. matrix.c = savedMatrix.c;
  7296. matrix.d = savedMatrix.d;
  7297. matrix.tx = savedMatrix.tx;
  7298. matrix.ty = savedMatrix.ty;
  7299. egret.Matrix.release(savedMatrix);
  7300. }
  7301. renderBufferPool.push(displayBuffer);
  7302. return drawCalls;
  7303. }
  7304. };
  7305. /**
  7306. * @private
  7307. */
  7308. WebGLRenderer.prototype.drawWithScrollRect = function (displayObject, buffer, offsetX, offsetY) {
  7309. var drawCalls = 0;
  7310. var scrollRect = displayObject.$scrollRect ? displayObject.$scrollRect : displayObject.$maskRect;
  7311. if (scrollRect.isEmpty()) {
  7312. return drawCalls;
  7313. }
  7314. if (displayObject.$scrollRect) {
  7315. offsetX -= scrollRect.x;
  7316. offsetY -= scrollRect.y;
  7317. }
  7318. var m = buffer.globalMatrix;
  7319. var context = buffer.context;
  7320. var scissor = false;
  7321. if (buffer.$hasScissor || m.b != 0 || m.c != 0) {
  7322. buffer.context.pushMask(scrollRect.x + offsetX, scrollRect.y + offsetY, scrollRect.width, scrollRect.height);
  7323. }
  7324. else {
  7325. var a = m.a;
  7326. var d = m.d;
  7327. var tx = m.tx;
  7328. var ty = m.ty;
  7329. var x = scrollRect.x + offsetX;
  7330. var y = scrollRect.y + offsetY;
  7331. var xMax = x + scrollRect.width;
  7332. var yMax = y + scrollRect.height;
  7333. var minX = void 0, minY = void 0, maxX = void 0, maxY = void 0;
  7334. //优化,通常情况下不缩放的对象占多数,直接加上偏移量即可。
  7335. if (a == 1.0 && d == 1.0) {
  7336. minX = x + tx;
  7337. minY = y + ty;
  7338. maxX = xMax + tx;
  7339. maxY = yMax + ty;
  7340. }
  7341. else {
  7342. var x0 = a * x + tx;
  7343. var y0 = d * y + ty;
  7344. var x1 = a * xMax + tx;
  7345. var y1 = d * y + ty;
  7346. var x2 = a * xMax + tx;
  7347. var y2 = d * yMax + ty;
  7348. var x3 = a * x + tx;
  7349. var y3 = d * yMax + ty;
  7350. var tmp = 0;
  7351. if (x0 > x1) {
  7352. tmp = x0;
  7353. x0 = x1;
  7354. x1 = tmp;
  7355. }
  7356. if (x2 > x3) {
  7357. tmp = x2;
  7358. x2 = x3;
  7359. x3 = tmp;
  7360. }
  7361. minX = (x0 < x2 ? x0 : x2);
  7362. maxX = (x1 > x3 ? x1 : x3);
  7363. if (y0 > y1) {
  7364. tmp = y0;
  7365. y0 = y1;
  7366. y1 = tmp;
  7367. }
  7368. if (y2 > y3) {
  7369. tmp = y2;
  7370. y2 = y3;
  7371. y3 = tmp;
  7372. }
  7373. minY = (y0 < y2 ? y0 : y2);
  7374. maxY = (y1 > y3 ? y1 : y3);
  7375. }
  7376. context.enableScissor(minX, -maxY + buffer.height, maxX - minX, maxY - minY);
  7377. scissor = true;
  7378. }
  7379. drawCalls += this.drawDisplayObject(displayObject, buffer, offsetX, offsetY);
  7380. if (scissor) {
  7381. context.disableScissor();
  7382. }
  7383. else {
  7384. context.popMask();
  7385. }
  7386. return drawCalls;
  7387. };
  7388. /**
  7389. * 将一个RenderNode对象绘制到渲染缓冲
  7390. * @param node 要绘制的节点
  7391. * @param buffer 渲染缓冲
  7392. * @param matrix 要叠加的矩阵
  7393. * @param forHitTest 绘制结果是用于碰撞检测。若为true,当渲染GraphicsNode时,会忽略透明度样式设置,全都绘制为不透明的。
  7394. */
  7395. WebGLRenderer.prototype.drawNodeToBuffer = function (node, buffer, matrix, forHitTest) {
  7396. var webglBuffer = buffer;
  7397. //pushRenderTARGET
  7398. webglBuffer.context.pushBuffer(webglBuffer);
  7399. webglBuffer.setTransform(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
  7400. this.renderNode(node, buffer, 0, 0, forHitTest);
  7401. webglBuffer.context.$drawWebGL();
  7402. webglBuffer.onRenderFinish();
  7403. //popRenderTARGET
  7404. webglBuffer.context.popBuffer();
  7405. };
  7406. /**
  7407. * 将一个DisplayObject绘制到渲染缓冲,用于RenderTexture绘制
  7408. * @param displayObject 要绘制的显示对象
  7409. * @param buffer 渲染缓冲
  7410. * @param matrix 要叠加的矩阵
  7411. */
  7412. WebGLRenderer.prototype.drawDisplayToBuffer = function (displayObject, buffer, matrix) {
  7413. buffer.context.pushBuffer(buffer);
  7414. if (matrix) {
  7415. buffer.setTransform(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
  7416. }
  7417. var node;
  7418. if (displayObject.$renderDirty) {
  7419. node = displayObject.$getRenderNode();
  7420. }
  7421. else {
  7422. node = displayObject.$renderNode;
  7423. }
  7424. var drawCalls = 0;
  7425. if (node) {
  7426. drawCalls++;
  7427. switch (node.type) {
  7428. case 1 /* BitmapNode */:
  7429. this.renderBitmap(node, buffer);
  7430. break;
  7431. case 2 /* TextNode */:
  7432. this.renderText(node, buffer);
  7433. break;
  7434. case 3 /* GraphicsNode */:
  7435. this.renderGraphics(node, buffer);
  7436. break;
  7437. case 4 /* GroupNode */:
  7438. this.renderGroup(node, buffer);
  7439. break;
  7440. case 5 /* MeshNode */:
  7441. this.renderMesh(node, buffer);
  7442. break;
  7443. case 6 /* NormalBitmapNode */:
  7444. this.renderNormalBitmap(node, buffer);
  7445. break;
  7446. }
  7447. }
  7448. var children = displayObject.$children;
  7449. if (children) {
  7450. var length_5 = children.length;
  7451. for (var i = 0; i < length_5; i++) {
  7452. var child = children[i];
  7453. switch (child.$renderMode) {
  7454. case 1 /* NONE */:
  7455. break;
  7456. case 2 /* FILTER */:
  7457. drawCalls += this.drawWithFilter(child, buffer, 0, 0);
  7458. break;
  7459. case 3 /* CLIP */:
  7460. drawCalls += this.drawWithClip(child, buffer, 0, 0);
  7461. break;
  7462. case 4 /* SCROLLRECT */:
  7463. drawCalls += this.drawWithScrollRect(child, buffer, 0, 0);
  7464. break;
  7465. default:
  7466. drawCalls += this.drawDisplayObject(child, buffer, 0, 0);
  7467. break;
  7468. }
  7469. }
  7470. }
  7471. buffer.context.$drawWebGL();
  7472. buffer.onRenderFinish();
  7473. buffer.context.popBuffer();
  7474. return drawCalls;
  7475. };
  7476. /**
  7477. * @private
  7478. */
  7479. WebGLRenderer.prototype.renderNode = function (node, buffer, offsetX, offsetY, forHitTest) {
  7480. buffer.$offsetX = offsetX;
  7481. buffer.$offsetY = offsetY;
  7482. switch (node.type) {
  7483. case 1 /* BitmapNode */:
  7484. this.renderBitmap(node, buffer);
  7485. break;
  7486. case 2 /* TextNode */:
  7487. this.renderText(node, buffer);
  7488. break;
  7489. case 3 /* GraphicsNode */:
  7490. this.renderGraphics(node, buffer, forHitTest);
  7491. break;
  7492. case 4 /* GroupNode */:
  7493. this.renderGroup(node, buffer);
  7494. break;
  7495. case 5 /* MeshNode */:
  7496. this.renderMesh(node, buffer);
  7497. break;
  7498. case 6 /* NormalBitmapNode */:
  7499. this.renderNormalBitmap(node, buffer);
  7500. break;
  7501. }
  7502. };
  7503. /**
  7504. * @private
  7505. */
  7506. WebGLRenderer.prototype.renderNormalBitmap = function (node, buffer) {
  7507. var image = node.image;
  7508. if (!image) {
  7509. return;
  7510. }
  7511. buffer.context.drawImage(image, node.sourceX, node.sourceY, node.sourceW, node.sourceH, node.drawX, node.drawY, node.drawW, node.drawH, node.imageWidth, node.imageHeight, node.rotated, node.smoothing);
  7512. };
  7513. /**
  7514. * @private
  7515. */
  7516. WebGLRenderer.prototype.renderBitmap = function (node, buffer) {
  7517. var image = node.image;
  7518. if (!image) {
  7519. return;
  7520. }
  7521. //buffer.imageSmoothingEnabled = node.smoothing;
  7522. var data = node.drawData;
  7523. var length = data.length;
  7524. var pos = 0;
  7525. var m = node.matrix;
  7526. var blendMode = node.blendMode;
  7527. var alpha = node.alpha;
  7528. var savedMatrix;
  7529. var offsetX;
  7530. var offsetY;
  7531. if (m) {
  7532. savedMatrix = egret.Matrix.create();
  7533. var curMatrix = buffer.globalMatrix;
  7534. savedMatrix.a = curMatrix.a;
  7535. savedMatrix.b = curMatrix.b;
  7536. savedMatrix.c = curMatrix.c;
  7537. savedMatrix.d = curMatrix.d;
  7538. savedMatrix.tx = curMatrix.tx;
  7539. savedMatrix.ty = curMatrix.ty;
  7540. offsetX = buffer.$offsetX;
  7541. offsetY = buffer.$offsetY;
  7542. buffer.useOffset();
  7543. buffer.transform(m.a, m.b, m.c, m.d, m.tx, m.ty);
  7544. }
  7545. //这里不考虑嵌套
  7546. if (blendMode) {
  7547. buffer.context.setGlobalCompositeOperation(blendModes[blendMode]);
  7548. }
  7549. var originAlpha;
  7550. if (alpha == alpha) {
  7551. originAlpha = buffer.globalAlpha;
  7552. buffer.globalAlpha *= alpha;
  7553. }
  7554. if (node.filter) {
  7555. buffer.context.$filter = node.filter;
  7556. while (pos < length) {
  7557. buffer.context.drawImage(image, data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], node.imageWidth, node.imageHeight, node.rotated, node.smoothing);
  7558. }
  7559. buffer.context.$filter = null;
  7560. }
  7561. else {
  7562. while (pos < length) {
  7563. buffer.context.drawImage(image, data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], node.imageWidth, node.imageHeight, node.rotated, node.smoothing);
  7564. }
  7565. }
  7566. if (blendMode) {
  7567. buffer.context.setGlobalCompositeOperation(defaultCompositeOp);
  7568. }
  7569. if (alpha == alpha) {
  7570. buffer.globalAlpha = originAlpha;
  7571. }
  7572. if (m) {
  7573. var matrix = buffer.globalMatrix;
  7574. matrix.a = savedMatrix.a;
  7575. matrix.b = savedMatrix.b;
  7576. matrix.c = savedMatrix.c;
  7577. matrix.d = savedMatrix.d;
  7578. matrix.tx = savedMatrix.tx;
  7579. matrix.ty = savedMatrix.ty;
  7580. buffer.$offsetX = offsetX;
  7581. buffer.$offsetY = offsetY;
  7582. egret.Matrix.release(savedMatrix);
  7583. }
  7584. };
  7585. /**
  7586. * @private
  7587. */
  7588. WebGLRenderer.prototype.renderMesh = function (node, buffer) {
  7589. var image = node.image;
  7590. //buffer.imageSmoothingEnabled = node.smoothing;
  7591. var data = node.drawData;
  7592. var length = data.length;
  7593. var pos = 0;
  7594. var m = node.matrix;
  7595. var blendMode = node.blendMode;
  7596. var alpha = node.alpha;
  7597. var savedMatrix;
  7598. var offsetX;
  7599. var offsetY;
  7600. if (m) {
  7601. savedMatrix = egret.Matrix.create();
  7602. var curMatrix = buffer.globalMatrix;
  7603. savedMatrix.a = curMatrix.a;
  7604. savedMatrix.b = curMatrix.b;
  7605. savedMatrix.c = curMatrix.c;
  7606. savedMatrix.d = curMatrix.d;
  7607. savedMatrix.tx = curMatrix.tx;
  7608. savedMatrix.ty = curMatrix.ty;
  7609. offsetX = buffer.$offsetX;
  7610. offsetY = buffer.$offsetY;
  7611. buffer.useOffset();
  7612. buffer.transform(m.a, m.b, m.c, m.d, m.tx, m.ty);
  7613. }
  7614. //这里不考虑嵌套
  7615. if (blendMode) {
  7616. buffer.context.setGlobalCompositeOperation(blendModes[blendMode]);
  7617. }
  7618. var originAlpha;
  7619. if (alpha == alpha) {
  7620. originAlpha = buffer.globalAlpha;
  7621. buffer.globalAlpha *= alpha;
  7622. }
  7623. if (node.filter) {
  7624. buffer.context.$filter = node.filter;
  7625. while (pos < length) {
  7626. buffer.context.drawMesh(image, data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], node.imageWidth, node.imageHeight, node.uvs, node.vertices, node.indices, node.bounds, node.rotated, node.smoothing);
  7627. }
  7628. buffer.context.$filter = null;
  7629. }
  7630. else {
  7631. while (pos < length) {
  7632. buffer.context.drawMesh(image, data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], data[pos++], node.imageWidth, node.imageHeight, node.uvs, node.vertices, node.indices, node.bounds, node.rotated, node.smoothing);
  7633. }
  7634. }
  7635. if (blendMode) {
  7636. buffer.context.setGlobalCompositeOperation(defaultCompositeOp);
  7637. }
  7638. if (alpha == alpha) {
  7639. buffer.globalAlpha = originAlpha;
  7640. }
  7641. if (m) {
  7642. var matrix = buffer.globalMatrix;
  7643. matrix.a = savedMatrix.a;
  7644. matrix.b = savedMatrix.b;
  7645. matrix.c = savedMatrix.c;
  7646. matrix.d = savedMatrix.d;
  7647. matrix.tx = savedMatrix.tx;
  7648. matrix.ty = savedMatrix.ty;
  7649. buffer.$offsetX = offsetX;
  7650. buffer.$offsetY = offsetY;
  7651. egret.Matrix.release(savedMatrix);
  7652. }
  7653. };
  7654. /**
  7655. * @private
  7656. */
  7657. WebGLRenderer.prototype.renderText = function (node, buffer) {
  7658. var width = node.width - node.x;
  7659. var height = node.height - node.y;
  7660. if (width <= 0 || height <= 0 || !width || !height || node.drawData.length == 0) {
  7661. return;
  7662. }
  7663. var canvasScaleX = egret.sys.DisplayList.$canvasScaleX;
  7664. var canvasScaleY = egret.sys.DisplayList.$canvasScaleY;
  7665. var maxTextureSize = buffer.context.$maxTextureSize;
  7666. if (width * canvasScaleX > maxTextureSize) {
  7667. canvasScaleX *= maxTextureSize / (width * canvasScaleX);
  7668. }
  7669. if (height * canvasScaleY > maxTextureSize) {
  7670. canvasScaleY *= maxTextureSize / (height * canvasScaleY);
  7671. }
  7672. width *= canvasScaleX;
  7673. height *= canvasScaleY;
  7674. var x = node.x * canvasScaleX;
  7675. var y = node.y * canvasScaleY;
  7676. if (node.$canvasScaleX != canvasScaleX || node.$canvasScaleY != canvasScaleY) {
  7677. node.$canvasScaleX = canvasScaleX;
  7678. node.$canvasScaleY = canvasScaleY;
  7679. node.dirtyRender = true;
  7680. }
  7681. if (!this.canvasRenderBuffer || !this.canvasRenderBuffer.context) {
  7682. this.canvasRenderer = new egret.CanvasRenderer();
  7683. this.canvasRenderBuffer = new web.CanvasRenderBuffer(width, height);
  7684. }
  7685. else if (node.dirtyRender) {
  7686. this.canvasRenderBuffer.resize(width, height);
  7687. }
  7688. if (!this.canvasRenderBuffer.context) {
  7689. return;
  7690. }
  7691. if (canvasScaleX != 1 || canvasScaleY != 1) {
  7692. this.canvasRenderBuffer.context.setTransform(canvasScaleX, 0, 0, canvasScaleY, 0, 0);
  7693. }
  7694. if (x || y) {
  7695. if (node.dirtyRender) {
  7696. this.canvasRenderBuffer.context.setTransform(canvasScaleX, 0, 0, canvasScaleY, -x, -y);
  7697. }
  7698. buffer.transform(1, 0, 0, 1, x / canvasScaleX, y / canvasScaleY);
  7699. }
  7700. else if (canvasScaleX != 1 || canvasScaleY != 1) {
  7701. this.canvasRenderBuffer.context.setTransform(canvasScaleX, 0, 0, canvasScaleY, 0, 0);
  7702. }
  7703. if (node.dirtyRender) {
  7704. var surface = this.canvasRenderBuffer.surface;
  7705. this.canvasRenderer.renderText(node, this.canvasRenderBuffer.context);
  7706. // 拷贝canvas到texture
  7707. var texture = node.$texture;
  7708. if (!texture) {
  7709. texture = buffer.context.createTexture(surface);
  7710. node.$texture = texture;
  7711. }
  7712. else {
  7713. // 重新拷贝新的图像
  7714. buffer.context.updateTexture(texture, surface);
  7715. }
  7716. // 保存材质尺寸
  7717. node.$textureWidth = surface.width;
  7718. node.$textureHeight = surface.height;
  7719. }
  7720. var textureWidth = node.$textureWidth;
  7721. var textureHeight = node.$textureHeight;
  7722. buffer.context.drawTexture(node.$texture, 0, 0, textureWidth, textureHeight, 0, 0, textureWidth / canvasScaleX, textureHeight / canvasScaleY, textureWidth, textureHeight);
  7723. if (x || y) {
  7724. if (node.dirtyRender) {
  7725. this.canvasRenderBuffer.context.setTransform(canvasScaleX, 0, 0, canvasScaleY, 0, 0);
  7726. }
  7727. buffer.transform(1, 0, 0, 1, -x / canvasScaleX, -y / canvasScaleY);
  7728. }
  7729. node.dirtyRender = false;
  7730. };
  7731. /**
  7732. * @private
  7733. */
  7734. WebGLRenderer.prototype.renderGraphics = function (node, buffer, forHitTest) {
  7735. var width = node.width;
  7736. var height = node.height;
  7737. if (width <= 0 || height <= 0 || !width || !height || node.drawData.length == 0) {
  7738. return;
  7739. }
  7740. var canvasScaleX = egret.sys.DisplayList.$canvasScaleX;
  7741. var canvasScaleY = egret.sys.DisplayList.$canvasScaleY;
  7742. if (width * canvasScaleX < 1 || height * canvasScaleY < 1) {
  7743. canvasScaleX = canvasScaleY = 1;
  7744. }
  7745. if (node.$canvasScaleX != canvasScaleX || node.$canvasScaleY != canvasScaleY) {
  7746. node.$canvasScaleX = canvasScaleX;
  7747. node.$canvasScaleY = canvasScaleY;
  7748. node.dirtyRender = true;
  7749. }
  7750. //缩放叠加 width2 / width 填满整个区域
  7751. width = width * canvasScaleX;
  7752. height = height * canvasScaleY;
  7753. var width2 = Math.ceil(width);
  7754. var height2 = Math.ceil(height);
  7755. canvasScaleX *= width2 / width;
  7756. canvasScaleY *= height2 / height;
  7757. width = width2;
  7758. height = height2;
  7759. if (!this.canvasRenderBuffer || !this.canvasRenderBuffer.context) {
  7760. this.canvasRenderer = new egret.CanvasRenderer();
  7761. this.canvasRenderBuffer = new web.CanvasRenderBuffer(width, height);
  7762. }
  7763. else if (node.dirtyRender || forHitTest) {
  7764. this.canvasRenderBuffer.resize(width, height);
  7765. }
  7766. if (!this.canvasRenderBuffer.context) {
  7767. return;
  7768. }
  7769. if (canvasScaleX != 1 || canvasScaleY != 1) {
  7770. this.canvasRenderBuffer.context.setTransform(canvasScaleX, 0, 0, canvasScaleY, 0, 0);
  7771. }
  7772. if (node.x || node.y) {
  7773. if (node.dirtyRender || forHitTest) {
  7774. this.canvasRenderBuffer.context.translate(-node.x, -node.y);
  7775. }
  7776. buffer.transform(1, 0, 0, 1, node.x, node.y);
  7777. }
  7778. var surface = this.canvasRenderBuffer.surface;
  7779. if (forHitTest) {
  7780. this.canvasRenderer.renderGraphics(node, this.canvasRenderBuffer.context, true);
  7781. egret.WebGLUtils.deleteWebGLTexture(surface);
  7782. var texture = buffer.context.getWebGLTexture(surface);
  7783. buffer.context.drawTexture(texture, 0, 0, width, height, 0, 0, width, height, surface.width, surface.height);
  7784. }
  7785. else {
  7786. if (node.dirtyRender) {
  7787. this.canvasRenderer.renderGraphics(node, this.canvasRenderBuffer.context);
  7788. // 拷贝canvas到texture
  7789. var texture = node.$texture;
  7790. if (!texture) {
  7791. texture = buffer.context.createTexture(surface);
  7792. node.$texture = texture;
  7793. }
  7794. else {
  7795. // 重新拷贝新的图像
  7796. buffer.context.updateTexture(texture, surface);
  7797. }
  7798. // 保存材质尺寸
  7799. node.$textureWidth = surface.width;
  7800. node.$textureHeight = surface.height;
  7801. }
  7802. var textureWidth = node.$textureWidth;
  7803. var textureHeight = node.$textureHeight;
  7804. buffer.context.drawTexture(node.$texture, 0, 0, textureWidth, textureHeight, 0, 0, textureWidth / canvasScaleX, textureHeight / canvasScaleY, textureWidth, textureHeight);
  7805. }
  7806. if (node.x || node.y) {
  7807. if (node.dirtyRender || forHitTest) {
  7808. this.canvasRenderBuffer.context.translate(node.x, node.y);
  7809. }
  7810. buffer.transform(1, 0, 0, 1, -node.x, -node.y);
  7811. }
  7812. if (!forHitTest) {
  7813. node.dirtyRender = false;
  7814. }
  7815. };
  7816. WebGLRenderer.prototype.renderGroup = function (groupNode, buffer) {
  7817. var m = groupNode.matrix;
  7818. var savedMatrix;
  7819. var offsetX;
  7820. var offsetY;
  7821. if (m) {
  7822. savedMatrix = egret.Matrix.create();
  7823. var curMatrix = buffer.globalMatrix;
  7824. savedMatrix.a = curMatrix.a;
  7825. savedMatrix.b = curMatrix.b;
  7826. savedMatrix.c = curMatrix.c;
  7827. savedMatrix.d = curMatrix.d;
  7828. savedMatrix.tx = curMatrix.tx;
  7829. savedMatrix.ty = curMatrix.ty;
  7830. offsetX = buffer.$offsetX;
  7831. offsetY = buffer.$offsetY;
  7832. buffer.useOffset();
  7833. buffer.transform(m.a, m.b, m.c, m.d, m.tx, m.ty);
  7834. }
  7835. var children = groupNode.drawData;
  7836. var length = children.length;
  7837. for (var i = 0; i < length; i++) {
  7838. var node = children[i];
  7839. this.renderNode(node, buffer, buffer.$offsetX, buffer.$offsetY);
  7840. }
  7841. if (m) {
  7842. var matrix = buffer.globalMatrix;
  7843. matrix.a = savedMatrix.a;
  7844. matrix.b = savedMatrix.b;
  7845. matrix.c = savedMatrix.c;
  7846. matrix.d = savedMatrix.d;
  7847. matrix.tx = savedMatrix.tx;
  7848. matrix.ty = savedMatrix.ty;
  7849. buffer.$offsetX = offsetX;
  7850. buffer.$offsetY = offsetY;
  7851. egret.Matrix.release(savedMatrix);
  7852. }
  7853. };
  7854. /**
  7855. * @private
  7856. */
  7857. WebGLRenderer.prototype.createRenderBuffer = function (width, height) {
  7858. var buffer = renderBufferPool.pop();
  7859. if (buffer) {
  7860. buffer.resize(width, height);
  7861. }
  7862. else {
  7863. buffer = new web.WebGLRenderBuffer(width, height);
  7864. buffer.$computeDrawCall = false;
  7865. }
  7866. return buffer;
  7867. };
  7868. return WebGLRenderer;
  7869. }());
  7870. web.WebGLRenderer = WebGLRenderer;
  7871. __reflect(WebGLRenderer.prototype, "egret.web.WebGLRenderer", ["egret.sys.SystemRenderer"]);
  7872. })(web = egret.web || (egret.web = {}));
  7873. })(egret || (egret = {}));
  7874. //////////////////////////////////////////////////////////////////////////////////////
  7875. //
  7876. // Copyright (c) 2014-present, Egret Technology.
  7877. // All rights reserved.
  7878. // Redistribution and use in source and binary forms, with or without
  7879. // modification, are permitted provided that the following conditions are met:
  7880. //
  7881. // * Redistributions of source code must retain the above copyright
  7882. // notice, this list of conditions and the following disclaimer.
  7883. // * Redistributions in binary form must reproduce the above copyright
  7884. // notice, this list of conditions and the following disclaimer in the
  7885. // documentation and/or other materials provided with the distribution.
  7886. // * Neither the name of the Egret nor the
  7887. // names of its contributors may be used to endorse or promote products
  7888. // derived from this software without specific prior written permission.
  7889. //
  7890. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  7891. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7892. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7893. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  7894. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7895. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  7896. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7897. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7898. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7899. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7900. //
  7901. //////////////////////////////////////////////////////////////////////////////////////
  7902. var egret;
  7903. (function (egret) {
  7904. var web;
  7905. (function (web) {
  7906. /**
  7907. * @private
  7908. */
  7909. var EgretWebGLAttribute = (function () {
  7910. function EgretWebGLAttribute(gl, program, attributeData) {
  7911. this.gl = gl;
  7912. this.name = attributeData.name;
  7913. this.type = attributeData.type;
  7914. this.size = attributeData.size;
  7915. this.location = gl.getAttribLocation(program, this.name);
  7916. this.count = 0;
  7917. this.initCount(gl);
  7918. this.format = gl.FLOAT;
  7919. this.initFormat(gl);
  7920. }
  7921. EgretWebGLAttribute.prototype.initCount = function (gl) {
  7922. var type = this.type;
  7923. switch (type) {
  7924. case 5126 /* FLOAT */:
  7925. case 5120 /* BYTE */:
  7926. case 5121 /* UNSIGNED_BYTE */:
  7927. case 5123 /* UNSIGNED_SHORT */:
  7928. this.count = 1;
  7929. break;
  7930. case 35664 /* FLOAT_VEC2 */:
  7931. this.count = 2;
  7932. break;
  7933. case 35665 /* FLOAT_VEC3 */:
  7934. this.count = 3;
  7935. break;
  7936. case 35666 /* FLOAT_VEC4 */:
  7937. this.count = 4;
  7938. break;
  7939. }
  7940. };
  7941. EgretWebGLAttribute.prototype.initFormat = function (gl) {
  7942. var type = this.type;
  7943. switch (type) {
  7944. case 5126 /* FLOAT */:
  7945. case 35664 /* FLOAT_VEC2 */:
  7946. case 35665 /* FLOAT_VEC3 */:
  7947. case 35666 /* FLOAT_VEC4 */:
  7948. this.format = gl.FLOAT;
  7949. break;
  7950. case 5121 /* UNSIGNED_BYTE */:
  7951. this.format = gl.UNSIGNED_BYTE;
  7952. break;
  7953. case 5123 /* UNSIGNED_SHORT */:
  7954. this.format = gl.UNSIGNED_SHORT;
  7955. break;
  7956. case 5120 /* BYTE */:
  7957. this.format = gl.BYTE;
  7958. break;
  7959. }
  7960. };
  7961. return EgretWebGLAttribute;
  7962. }());
  7963. web.EgretWebGLAttribute = EgretWebGLAttribute;
  7964. __reflect(EgretWebGLAttribute.prototype, "egret.web.EgretWebGLAttribute");
  7965. })(web = egret.web || (egret.web = {}));
  7966. })(egret || (egret = {}));
  7967. //////////////////////////////////////////////////////////////////////////////////////
  7968. //
  7969. // Copyright (c) 2014-present, Egret Technology.
  7970. // All rights reserved.
  7971. // Redistribution and use in source and binary forms, with or without
  7972. // modification, are permitted provided that the following conditions are met:
  7973. //
  7974. // * Redistributions of source code must retain the above copyright
  7975. // notice, this list of conditions and the following disclaimer.
  7976. // * Redistributions in binary form must reproduce the above copyright
  7977. // notice, this list of conditions and the following disclaimer in the
  7978. // documentation and/or other materials provided with the distribution.
  7979. // * Neither the name of the Egret nor the
  7980. // names of its contributors may be used to endorse or promote products
  7981. // derived from this software without specific prior written permission.
  7982. //
  7983. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  7984. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7985. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7986. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  7987. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7988. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  7989. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7990. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7991. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7992. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7993. //
  7994. //////////////////////////////////////////////////////////////////////////////////////
  7995. var egret;
  7996. (function (egret) {
  7997. var web;
  7998. (function (web) {
  7999. function loadShader(gl, type, source) {
  8000. var shader = gl.createShader(type);
  8001. gl.shaderSource(shader, source);
  8002. gl.compileShader(shader);
  8003. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  8004. if (!compiled) {
  8005. console.log("shader not compiled!");
  8006. console.log(gl.getShaderInfoLog(shader));
  8007. }
  8008. return shader;
  8009. }
  8010. function createWebGLProgram(gl, vertexShader, fragmentShader) {
  8011. var program = gl.createProgram();
  8012. gl.attachShader(program, vertexShader);
  8013. gl.attachShader(program, fragmentShader);
  8014. gl.linkProgram(program);
  8015. return program;
  8016. }
  8017. function extractAttributes(gl, program) {
  8018. var attributes = {};
  8019. var totalAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
  8020. for (var i = 0; i < totalAttributes; i++) {
  8021. var attribData = gl.getActiveAttrib(program, i);
  8022. var name_2 = attribData.name;
  8023. var attribute = new web.EgretWebGLAttribute(gl, program, attribData);
  8024. attributes[name_2] = attribute;
  8025. }
  8026. return attributes;
  8027. }
  8028. function extractUniforms(gl, program) {
  8029. var uniforms = {};
  8030. var totalUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
  8031. for (var i = 0; i < totalUniforms; i++) {
  8032. var uniformData = gl.getActiveUniform(program, i);
  8033. var name_3 = uniformData.name;
  8034. var uniform = new web.EgretWebGLUniform(gl, program, uniformData);
  8035. uniforms[name_3] = uniform;
  8036. }
  8037. return uniforms;
  8038. }
  8039. /**
  8040. * @private
  8041. */
  8042. var EgretWebGLProgram = (function () {
  8043. function EgretWebGLProgram(gl, vertSource, fragSource) {
  8044. this.vshaderSource = vertSource;
  8045. this.fshaderSource = fragSource;
  8046. this.vertexShader = loadShader(gl, gl.VERTEX_SHADER, this.vshaderSource);
  8047. this.fragmentShader = loadShader(gl, gl.FRAGMENT_SHADER, this.fshaderSource);
  8048. this.id = createWebGLProgram(gl, this.vertexShader, this.fragmentShader);
  8049. this.uniforms = extractUniforms(gl, this.id);
  8050. this.attributes = extractAttributes(gl, this.id);
  8051. }
  8052. /**
  8053. * 获取所需的WebGL Program
  8054. * @param key {string} 对于唯一的program程序,对应唯一的key
  8055. */
  8056. EgretWebGLProgram.getProgram = function (gl, vertSource, fragSource, key) {
  8057. if (!this.programCache[key]) {
  8058. this.programCache[key] = new EgretWebGLProgram(gl, vertSource, fragSource);
  8059. }
  8060. return this.programCache[key];
  8061. };
  8062. EgretWebGLProgram.deleteProgram = function (gl, vertSource, fragSource, key) {
  8063. // TODO delete
  8064. };
  8065. EgretWebGLProgram.programCache = {};
  8066. return EgretWebGLProgram;
  8067. }());
  8068. web.EgretWebGLProgram = EgretWebGLProgram;
  8069. __reflect(EgretWebGLProgram.prototype, "egret.web.EgretWebGLProgram");
  8070. })(web = egret.web || (egret.web = {}));
  8071. })(egret || (egret = {}));
  8072. //////////////////////////////////////////////////////////////////////////////////////
  8073. //
  8074. // Copyright (c) 2014-present, Egret Technology.
  8075. // All rights reserved.
  8076. // Redistribution and use in source and binary forms, with or without
  8077. // modification, are permitted provided that the following conditions are met:
  8078. //
  8079. // * Redistributions of source code must retain the above copyright
  8080. // notice, this list of conditions and the following disclaimer.
  8081. // * Redistributions in binary form must reproduce the above copyright
  8082. // notice, this list of conditions and the following disclaimer in the
  8083. // documentation and/or other materials provided with the distribution.
  8084. // * Neither the name of the Egret nor the
  8085. // names of its contributors may be used to endorse or promote products
  8086. // derived from this software without specific prior written permission.
  8087. //
  8088. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  8089. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  8090. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  8091. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  8092. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  8093. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  8094. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  8095. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  8096. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  8097. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8098. //
  8099. //////////////////////////////////////////////////////////////////////////////////////
  8100. var egret;
  8101. (function (egret) {
  8102. var web;
  8103. (function (web) {
  8104. /**
  8105. * @private
  8106. */
  8107. var EgretWebGLUniform = (function () {
  8108. function EgretWebGLUniform(gl, program, uniformData) {
  8109. this.gl = gl;
  8110. this.name = uniformData.name;
  8111. this.type = uniformData.type;
  8112. this.size = uniformData.size;
  8113. this.location = gl.getUniformLocation(program, this.name);
  8114. this.setDefaultValue();
  8115. this.generateSetValue();
  8116. this.generateUpload();
  8117. }
  8118. EgretWebGLUniform.prototype.setDefaultValue = function () {
  8119. var type = this.type;
  8120. switch (type) {
  8121. case 5126 /* FLOAT */:
  8122. case 35678 /* SAMPLER_2D */:
  8123. case 35680 /* SAMPLER_CUBE */:
  8124. case 35670 /* BOOL */:
  8125. case 5124 /* INT */:
  8126. this.value = 0;
  8127. break;
  8128. case 35664 /* FLOAT_VEC2 */:
  8129. case 35671 /* BOOL_VEC2 */:
  8130. case 35667 /* INT_VEC2 */:
  8131. this.value = [0, 0];
  8132. break;
  8133. case 35665 /* FLOAT_VEC3 */:
  8134. case 35672 /* BOOL_VEC3 */:
  8135. case 35668 /* INT_VEC3 */:
  8136. this.value = [0, 0, 0];
  8137. break;
  8138. case 35666 /* FLOAT_VEC4 */:
  8139. case 35673 /* BOOL_VEC4 */:
  8140. case 35669 /* INT_VEC4 */:
  8141. this.value = [0, 0, 0, 0];
  8142. break;
  8143. case 35674 /* FLOAT_MAT2 */:
  8144. this.value = new Float32Array([
  8145. 1, 0,
  8146. 0, 1
  8147. ]);
  8148. break;
  8149. case 35675 /* FLOAT_MAT3 */:
  8150. this.value = new Float32Array([
  8151. 1, 0, 0,
  8152. 0, 1, 0,
  8153. 0, 0, 1
  8154. ]);
  8155. break;
  8156. case 35676 /* FLOAT_MAT4 */:
  8157. this.value = new Float32Array([
  8158. 1, 0, 0, 0,
  8159. 0, 1, 0, 0,
  8160. 0, 0, 1, 0,
  8161. 0, 0, 0, 1
  8162. ]);
  8163. break;
  8164. }
  8165. };
  8166. EgretWebGLUniform.prototype.generateSetValue = function () {
  8167. var type = this.type;
  8168. switch (type) {
  8169. case 5126 /* FLOAT */:
  8170. case 35678 /* SAMPLER_2D */:
  8171. case 35680 /* SAMPLER_CUBE */:
  8172. case 35670 /* BOOL */:
  8173. case 5124 /* INT */:
  8174. this.setValue = function (value) {
  8175. var notEqual = this.value !== value;
  8176. this.value = value;
  8177. notEqual && this.upload();
  8178. };
  8179. break;
  8180. case 35664 /* FLOAT_VEC2 */:
  8181. case 35671 /* BOOL_VEC2 */:
  8182. case 35667 /* INT_VEC2 */:
  8183. this.setValue = function (value) {
  8184. var notEqual = this.value[0] !== value.x || this.value[1] !== value.y;
  8185. this.value[0] = value.x;
  8186. this.value[1] = value.y;
  8187. notEqual && this.upload();
  8188. };
  8189. break;
  8190. case 35665 /* FLOAT_VEC3 */:
  8191. case 35672 /* BOOL_VEC3 */:
  8192. case 35668 /* INT_VEC3 */:
  8193. this.setValue = function (value) {
  8194. this.value[0] = value.x;
  8195. this.value[1] = value.y;
  8196. this.value[2] = value.z;
  8197. this.upload();
  8198. };
  8199. break;
  8200. case 35666 /* FLOAT_VEC4 */:
  8201. case 35673 /* BOOL_VEC4 */:
  8202. case 35669 /* INT_VEC4 */:
  8203. this.setValue = function (value) {
  8204. this.value[0] = value.x;
  8205. this.value[1] = value.y;
  8206. this.value[2] = value.z;
  8207. this.value[3] = value.w;
  8208. this.upload();
  8209. };
  8210. break;
  8211. case 35674 /* FLOAT_MAT2 */:
  8212. case 35675 /* FLOAT_MAT3 */:
  8213. case 35676 /* FLOAT_MAT4 */:
  8214. this.setValue = function (value) {
  8215. this.value.set(value);
  8216. this.upload();
  8217. };
  8218. break;
  8219. }
  8220. };
  8221. EgretWebGLUniform.prototype.generateUpload = function () {
  8222. var gl = this.gl;
  8223. var type = this.type;
  8224. var location = this.location;
  8225. switch (type) {
  8226. case 5126 /* FLOAT */:
  8227. this.upload = function () {
  8228. var value = this.value;
  8229. gl.uniform1f(location, value);
  8230. };
  8231. break;
  8232. case 35664 /* FLOAT_VEC2 */:
  8233. this.upload = function () {
  8234. var value = this.value;
  8235. gl.uniform2f(location, value[0], value[1]);
  8236. };
  8237. break;
  8238. case 35665 /* FLOAT_VEC3 */:
  8239. this.upload = function () {
  8240. var value = this.value;
  8241. gl.uniform3f(location, value[0], value[1], value[2]);
  8242. };
  8243. break;
  8244. case 35666 /* FLOAT_VEC4 */:
  8245. this.upload = function () {
  8246. var value = this.value;
  8247. gl.uniform4f(location, value[0], value[1], value[2], value[3]);
  8248. };
  8249. break;
  8250. case 35678 /* SAMPLER_2D */:
  8251. case 35680 /* SAMPLER_CUBE */:
  8252. case 35670 /* BOOL */:
  8253. case 5124 /* INT */:
  8254. this.upload = function () {
  8255. var value = this.value;
  8256. gl.uniform1i(location, value);
  8257. };
  8258. break;
  8259. case 35671 /* BOOL_VEC2 */:
  8260. case 35667 /* INT_VEC2 */:
  8261. this.upload = function () {
  8262. var value = this.value;
  8263. gl.uniform2i(location, value[0], value[1]);
  8264. };
  8265. break;
  8266. case 35672 /* BOOL_VEC3 */:
  8267. case 35668 /* INT_VEC3 */:
  8268. this.upload = function () {
  8269. var value = this.value;
  8270. gl.uniform3i(location, value[0], value[1], value[2]);
  8271. };
  8272. break;
  8273. case 35673 /* BOOL_VEC4 */:
  8274. case 35669 /* INT_VEC4 */:
  8275. this.upload = function () {
  8276. var value = this.value;
  8277. gl.uniform4i(location, value[0], value[1], value[2], value[3]);
  8278. };
  8279. break;
  8280. case 35674 /* FLOAT_MAT2 */:
  8281. this.upload = function () {
  8282. var value = this.value;
  8283. gl.uniformMatrix2fv(location, false, value);
  8284. };
  8285. break;
  8286. case 35675 /* FLOAT_MAT3 */:
  8287. this.upload = function () {
  8288. var value = this.value;
  8289. gl.uniformMatrix3fv(location, false, value);
  8290. };
  8291. break;
  8292. case 35676 /* FLOAT_MAT4 */:
  8293. this.upload = function () {
  8294. var value = this.value;
  8295. gl.uniformMatrix4fv(location, false, value);
  8296. };
  8297. break;
  8298. }
  8299. };
  8300. return EgretWebGLUniform;
  8301. }());
  8302. web.EgretWebGLUniform = EgretWebGLUniform;
  8303. __reflect(EgretWebGLUniform.prototype, "egret.web.EgretWebGLUniform");
  8304. })(web = egret.web || (egret.web = {}));
  8305. })(egret || (egret = {}));
  8306. var egret;
  8307. (function (egret) {
  8308. var web;
  8309. (function (web) {
  8310. /**
  8311. * @private
  8312. */
  8313. var EgretShaderLib = (function () {
  8314. function EgretShaderLib() {
  8315. }
  8316. EgretShaderLib.blur_frag = "precision mediump float;\r\nuniform vec2 blur;\r\nuniform sampler2D uSampler;\r\nvarying vec2 vTextureCoord;\r\nuniform vec2 uTextureSize;\r\nvoid main()\r\n{\r\n const int sampleRadius = 5;\r\n const int samples = sampleRadius * 2 + 1;\r\n vec2 blurUv = blur / uTextureSize;\r\n vec4 color = vec4(0, 0, 0, 0);\r\n vec2 uv = vec2(0.0, 0.0);\r\n blurUv /= float(sampleRadius);\r\n\r\n for (int i = -sampleRadius; i <= sampleRadius; i++) {\r\n uv.x = vTextureCoord.x + float(i) * blurUv.x;\r\n uv.y = vTextureCoord.y + float(i) * blurUv.y;\r\n color += texture2D(uSampler, uv);\r\n }\r\n\r\n color /= float(samples);\r\n gl_FragColor = color;\r\n}";
  8317. EgretShaderLib.colorTransform_frag = "precision mediump float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform mat4 matrix;\r\nuniform vec4 colorAdd;\r\nuniform sampler2D uSampler;\r\n\r\nvoid main(void) {\r\n vec4 texColor = texture2D(uSampler, vTextureCoord);\r\n if(texColor.a > 0.) {\r\n // 抵消预乘的alpha通道\r\n texColor = vec4(texColor.rgb / texColor.a, texColor.a);\r\n }\r\n vec4 locColor = clamp(texColor * matrix + colorAdd, 0., 1.);\r\n gl_FragColor = vColor * vec4(locColor.rgb * locColor.a, locColor.a);\r\n}";
  8318. EgretShaderLib.default_vert = "attribute vec2 aVertexPosition;\r\nattribute vec2 aTextureCoord;\r\nattribute vec2 aColor;\r\n\r\nuniform vec2 projectionVector;\r\n// uniform vec2 offsetVector;\r\n\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\n\r\nconst vec2 center = vec2(-1.0, 1.0);\r\n\r\nvoid main(void) {\r\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\r\n vTextureCoord = aTextureCoord;\r\n vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\r\n}";
  8319. EgretShaderLib.glow_frag = "precision highp float;\r\nvarying vec2 vTextureCoord;\r\n\r\nuniform sampler2D uSampler;\r\n\r\nuniform float dist;\r\nuniform float angle;\r\nuniform vec4 color;\r\nuniform float alpha;\r\nuniform float blurX;\r\nuniform float blurY;\r\n// uniform vec4 quality;\r\nuniform float strength;\r\nuniform float inner;\r\nuniform float knockout;\r\nuniform float hideObject;\r\n\r\nuniform vec2 uTextureSize;\r\n\r\nfloat random(vec2 scale)\r\n{\r\n return fract(sin(dot(gl_FragCoord.xy, scale)) * 43758.5453);\r\n}\r\n\r\nvoid main(void) {\r\n vec2 px = vec2(1.0 / uTextureSize.x, 1.0 / uTextureSize.y);\r\n // TODO 自动调节采样次数?\r\n const float linearSamplingTimes = 7.0;\r\n const float circleSamplingTimes = 12.0;\r\n vec4 ownColor = texture2D(uSampler, vTextureCoord);\r\n vec4 curColor;\r\n float totalAlpha = 0.0;\r\n float maxTotalAlpha = 0.0;\r\n float curDistanceX = 0.0;\r\n float curDistanceY = 0.0;\r\n float offsetX = dist * cos(angle) * px.x;\r\n float offsetY = dist * sin(angle) * px.y;\r\n\r\n const float PI = 3.14159265358979323846264;\r\n float cosAngle;\r\n float sinAngle;\r\n float offset = PI * 2.0 / circleSamplingTimes * random(vec2(12.9898, 78.233));\r\n float stepX = blurX * px.x / linearSamplingTimes;\r\n float stepY = blurY * px.y / linearSamplingTimes;\r\n for (float a = 0.0; a <= PI * 2.0; a += PI * 2.0 / circleSamplingTimes) {\r\n cosAngle = cos(a + offset);\r\n sinAngle = sin(a + offset);\r\n for (float i = 1.0; i <= linearSamplingTimes; i++) {\r\n curDistanceX = i * stepX * cosAngle;\r\n curDistanceY = i * stepY * sinAngle;\r\n if (vTextureCoord.x + curDistanceX - offsetX >= 0.0 && vTextureCoord.y + curDistanceY + offsetY <= 1.0){\r\n curColor = texture2D(uSampler, vec2(vTextureCoord.x + curDistanceX - offsetX, vTextureCoord.y + curDistanceY + offsetY));\r\n totalAlpha += (linearSamplingTimes - i) * curColor.a;\r\n }\r\n maxTotalAlpha += (linearSamplingTimes - i);\r\n }\r\n }\r\n\r\n ownColor.a = max(ownColor.a, 0.0001);\r\n ownColor.rgb = ownColor.rgb / ownColor.a;\r\n\r\n float outerGlowAlpha = (totalAlpha / maxTotalAlpha) * strength * alpha * (1. - inner) * max(min(hideObject, knockout), 1. - ownColor.a);\r\n float innerGlowAlpha = ((maxTotalAlpha - totalAlpha) / maxTotalAlpha) * strength * alpha * inner * ownColor.a;\r\n\r\n ownColor.a = max(ownColor.a * knockout * (1. - hideObject), 0.0001);\r\n vec3 mix1 = mix(ownColor.rgb, color.rgb, innerGlowAlpha / (innerGlowAlpha + ownColor.a));\r\n vec3 mix2 = mix(mix1, color.rgb, outerGlowAlpha / (innerGlowAlpha + ownColor.a + outerGlowAlpha));\r\n float resultAlpha = min(ownColor.a + outerGlowAlpha + innerGlowAlpha, 1.);\r\n gl_FragColor = vec4(mix2 * resultAlpha, resultAlpha);\r\n}";
  8320. EgretShaderLib.primitive_frag = "precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n gl_FragColor = vColor;\r\n}";
  8321. EgretShaderLib.texture_frag = "precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform sampler2D uSampler;\r\n\r\nvoid main(void) {\r\n gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;\r\n}";
  8322. return EgretShaderLib;
  8323. }());
  8324. web.EgretShaderLib = EgretShaderLib;
  8325. __reflect(EgretShaderLib.prototype, "egret.web.EgretShaderLib");
  8326. })(web = egret.web || (egret.web = {}));
  8327. })(egret || (egret = {}));
  8328. ;