美素佳儿 litter wizard小游戏
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

5 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493
  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 (d, b) {
  5. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. //////////////////////////////////////////////////////////////////////////////////////
  10. //
  11. // Copyright (c) 2014-present, Egret Technology.
  12. // All rights reserved.
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions are met:
  15. //
  16. // * Redistributions of source code must retain the above copyright
  17. // notice, this list of conditions and the following disclaimer.
  18. // * Redistributions in binary form must reproduce the above copyright
  19. // notice, this list of conditions and the following disclaimer in the
  20. // documentation and/or other materials provided with the distribution.
  21. // * Neither the name of the Egret nor the
  22. // names of its contributors may be used to endorse or promote products
  23. // derived from this software without specific prior written permission.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  27. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  28. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  31. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  34. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //////////////////////////////////////////////////////////////////////////////////////
  37. var egret;
  38. (function (egret) {
  39. var native;
  40. (function (native) {
  41. /**
  42. * 测量文本在指定样式下的宽度。
  43. * @param text 要测量的文本内容。
  44. * @param fontFamily 字体名称
  45. * @param fontSize 字体大小
  46. * @param bold 是否粗体
  47. * @param italic 是否斜体
  48. */
  49. function measureText(text, fontFamily, fontSize, bold, italic) {
  50. var font;
  51. var arr;
  52. if (fontFamily.indexOf(", ") != -1) {
  53. arr = fontFamily.split(", ");
  54. }
  55. else if (fontFamily.indexOf(",") != -1) {
  56. arr = fontFamily.split(",");
  57. var length_1 = arr.length;
  58. for (var i = 0; i < length_1; i++) {
  59. var fontFamily_1 = arr[i];
  60. //暂时先不考虑带有引号的情况
  61. if (egret.fontMapping[fontFamily_1]) {
  62. font = egret.fontMapping[fontFamily_1];
  63. break;
  64. }
  65. }
  66. }
  67. else {
  68. font = egret.fontMapping[fontFamily];
  69. }
  70. if (!font) {
  71. font = "/system/fonts/DroidSansFallback.ttf";
  72. }
  73. egret_native.Label.createLabel(font, fontSize, "", 0);
  74. return egret_native.Label.getTextSize(text)[0];
  75. }
  76. egret.sys.measureText = measureText;
  77. })(native = egret.native || (egret.native = {}));
  78. })(egret || (egret = {}));
  79. //////////////////////////////////////////////////////////////////////////////////////
  80. //
  81. // Copyright (c) 2014-present, Egret Technology.
  82. // All rights reserved.
  83. // Redistribution and use in source and binary forms, with or without
  84. // modification, are permitted provided that the following conditions are met:
  85. //
  86. // * Redistributions of source code must retain the above copyright
  87. // notice, this list of conditions and the following disclaimer.
  88. // * Redistributions in binary form must reproduce the above copyright
  89. // notice, this list of conditions and the following disclaimer in the
  90. // documentation and/or other materials provided with the distribution.
  91. // * Neither the name of the Egret nor the
  92. // names of its contributors may be used to endorse or promote products
  93. // derived from this software without specific prior written permission.
  94. //
  95. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  96. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  97. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  98. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  99. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  100. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  101. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  102. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  103. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  104. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  105. //
  106. //////////////////////////////////////////////////////////////////////////////////////
  107. var egret;
  108. (function (egret) {
  109. var native;
  110. (function (native) {
  111. var blendModesForGL = {
  112. "source-over": [1, 771],
  113. "lighter": [770, 1],
  114. "destination-out": [0, 771],
  115. "destination-in": [0, 770]
  116. };
  117. /**
  118. * @version Egret 2.4
  119. * @platform Web,Native
  120. * @private
  121. */
  122. var NativeRenderTextureRenderContext = (function (_super) {
  123. __extends(NativeRenderTextureRenderContext, _super);
  124. function NativeRenderTextureRenderContext() {
  125. var _this = _super.apply(this, arguments) || this;
  126. _this.$matrix = new egret.Matrix();
  127. _this.$nativeContext = egret_native.Graphics;
  128. _this.$nativeGraphicsContext = egret_native.rastergl;
  129. _this.$globalCompositeOperation = "source-over";
  130. _this.$globalAlpha = 1;
  131. _this.$lineWidth = 0;
  132. _this.$strokeStyle = "#000000";
  133. _this.$fillStyle = "#000000";
  134. _this.$font = "normal normal 10px sans-serif";
  135. _this.$fontSize = 10;
  136. _this.$fontFamily = "";
  137. _this.clipRectArray = null;
  138. _this.$saveList = [];
  139. _this.$clipRect = new egret.Rectangle();
  140. _this.$saveCount = 0;
  141. _this.$clipList = [];
  142. _this.$hasStrokeText = false;
  143. return _this;
  144. }
  145. Object.defineProperty(NativeRenderTextureRenderContext.prototype, "globalCompositeOperation", {
  146. /**
  147. * @private
  148. * 设置新图像如何绘制到已有的图像上的规制
  149. * @version Egret 2.4
  150. * @platform Web,Native
  151. */
  152. get: function () {
  153. return this.$globalCompositeOperation;
  154. },
  155. set: function (value) {
  156. this.$globalCompositeOperation = value;
  157. var arr = blendModesForGL[value];
  158. if (arr) {
  159. this.checkSurface();
  160. native.$cmdManager.setContext(this.$nativeContext);
  161. native.$cmdManager.setBlendArg(arr[0], arr[1]);
  162. }
  163. },
  164. enumerable: true,
  165. configurable: true
  166. });
  167. Object.defineProperty(NativeRenderTextureRenderContext.prototype, "globalAlpha", {
  168. /**
  169. * @private
  170. * 设置接下来绘图填充的整体透明度
  171. * @version Egret 2.4
  172. * @platform Web,Native
  173. */
  174. get: function () {
  175. return this.$globalAlpha;
  176. },
  177. set: function (value) {
  178. this.$globalAlpha = value;
  179. this.checkSurface();
  180. native.$cmdManager.setContext(this.$nativeContext);
  181. native.$cmdManager.setGlobalAlpha(value);
  182. },
  183. enumerable: true,
  184. configurable: true
  185. });
  186. Object.defineProperty(NativeRenderTextureRenderContext.prototype, "lineWidth", {
  187. /**
  188. * @private
  189. * 设置线条粗细,以像素为单位。设置为0,负数,Infinity 或 NaN 将会被忽略。
  190. * @default 1
  191. * @version Egret 2.4
  192. * @platform Web,Native
  193. */
  194. get: function () {
  195. return this.$lineWidth;
  196. },
  197. set: function (value) {
  198. //console.log("set lineWidth" + value);
  199. this.$lineWidth = value;
  200. native.$cmdManager.setContext(this.$nativeContext);
  201. native.$cmdManager.setLineWidth(value);
  202. this.checkSurface();
  203. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  204. native.$cmdManager.setLineWidth(value);
  205. },
  206. enumerable: true,
  207. configurable: true
  208. });
  209. Object.defineProperty(NativeRenderTextureRenderContext.prototype, "strokeStyle", {
  210. /**
  211. * @private
  212. * 设置要在图形边线填充的颜色或样式
  213. * @default "#000000"
  214. * @version Egret 2.4
  215. * @platform Web,Native
  216. */
  217. get: function () {
  218. return this.$strokeStyle;
  219. },
  220. set: function (value) {
  221. this.$strokeStyle = value;
  222. if (value != null) {
  223. if (value.indexOf("rgba") != -1) {
  224. value = this.$parseRGBA(value);
  225. }
  226. else if (value.indexOf("rgb") != -1) {
  227. value = this.$parseRGB(value);
  228. }
  229. native.$cmdManager.setContext(egret_native.Label);
  230. native.$cmdManager.setStrokeColor(parseInt(value.replace("#", "0x")));
  231. }
  232. this.checkSurface();
  233. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  234. var s1 = native.$cmdManager.pushString(value);
  235. native.$cmdManager.setStrokeStyle(s1);
  236. },
  237. enumerable: true,
  238. configurable: true
  239. });
  240. Object.defineProperty(NativeRenderTextureRenderContext.prototype, "fillStyle", {
  241. /**
  242. * @private
  243. * 设置要在图形内部填充的颜色或样式
  244. * @default "#000000"
  245. * @version Egret 2.4
  246. * @platform Web,Native
  247. */
  248. get: function () {
  249. return this.$fillStyle;
  250. },
  251. set: function (value) {
  252. this.$fillStyle = value;
  253. if (value != null) {
  254. if (value.indexOf("rgba") != -1) {
  255. value = this.$parseRGBA(value);
  256. }
  257. else if (value.indexOf("rgb") != -1) {
  258. value = this.$parseRGB(value);
  259. }
  260. native.$cmdManager.setContext(egret_native.Label);
  261. native.$cmdManager.setTextColor(parseInt(value.replace("#", "0x")));
  262. }
  263. this.checkSurface();
  264. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  265. var s1 = native.$cmdManager.pushString(value);
  266. native.$cmdManager.setFillStyle(s1);
  267. },
  268. enumerable: true,
  269. configurable: true
  270. });
  271. NativeRenderTextureRenderContext.prototype.$fillColorStr = function (s) {
  272. if (s.length < 2) {
  273. s = "0" + s;
  274. }
  275. return s;
  276. };
  277. NativeRenderTextureRenderContext.prototype.$parseRGBA = function (str) {
  278. var index = str.indexOf("(");
  279. str = str.slice(index + 1, str.length - 1);
  280. var arr = str.split(",");
  281. var a = parseInt((parseFloat(arr[3]) * 255)).toString(16);
  282. var r = parseInt(arr[0]).toString(16);
  283. var g = parseInt(arr[1]).toString(16);
  284. var b = parseInt(arr[2]).toString(16);
  285. str = "#" + this.$fillColorStr(a) + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
  286. return str;
  287. };
  288. NativeRenderTextureRenderContext.prototype.$parseRGB = function (str) {
  289. var index = str.indexOf("(");
  290. str = str.slice(index + 1, str.length - 1);
  291. var arr = str.split(",");
  292. var r = parseInt(arr[0]).toString(16);
  293. var g = parseInt(arr[1]).toString(16);
  294. var b = parseInt(arr[2]).toString(16);
  295. str = "#" + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
  296. return str;
  297. };
  298. Object.defineProperty(NativeRenderTextureRenderContext.prototype, "font", {
  299. /**
  300. * @private
  301. * 当前的字体样式
  302. * @version Egret 2.4
  303. * @platform Web,Native
  304. */
  305. get: function () {
  306. return this.$font;
  307. },
  308. set: function (value) {
  309. this.$font = value;
  310. var arr = value.split(" ");
  311. var sizeTxt = arr[2];
  312. if (sizeTxt.indexOf("px") != -1) {
  313. this.$fontSize = parseInt(sizeTxt.replace("px", ""));
  314. }
  315. if (egret.useFontMapping) {
  316. var fontFamilyText = void 0;
  317. if (arr.length == 4) {
  318. fontFamilyText = arr[3];
  319. }
  320. else {
  321. fontFamilyText = arr.slice(3).join(" ");
  322. }
  323. if (fontFamilyText.indexOf(", ") != -1) {
  324. arr = fontFamilyText.split(", ");
  325. }
  326. else if (fontFamilyText.indexOf(",") != -1) {
  327. arr = fontFamilyText.split(",");
  328. var length_2 = arr.length;
  329. for (var i = 0; i < length_2; i++) {
  330. var fontFamily = arr[i];
  331. //暂时先不考虑带有引号的情况
  332. if (egret.fontMapping[fontFamily]) {
  333. this.$fontFamily = egret.fontMapping[fontFamily];
  334. return;
  335. }
  336. }
  337. }
  338. else {
  339. this.$fontFamily = egret.fontMapping[fontFamilyText];
  340. }
  341. if (!this.$fontFamily) {
  342. this.$fontFamily = "/system/fonts/DroidSansFallback.ttf";
  343. }
  344. }
  345. else {
  346. //兼容旧版本直接将 default_fontFamily 设置为字体路径的情况
  347. this.$fontFamily = egret.TextField.default_fontFamily;
  348. }
  349. },
  350. enumerable: true,
  351. configurable: true
  352. });
  353. /**
  354. * @private
  355. * 绘制一段圆弧路径。圆弧路径的圆心在 (x, y) 位置,半径为 r ,根据anticlockwise (默认为顺时针)指定的方向从 startAngle 开始绘制,到 endAngle 结束。
  356. * @param x 圆弧中心(圆心)的 x 轴坐标。
  357. * @param y 圆弧中心(圆心)的 y 轴坐标。
  358. * @param radius 圆弧的半径。
  359. * @param startAngle 圆弧的起始点, x轴方向开始计算,单位以弧度表示。
  360. * @param endAngle 圆弧的重点, 单位以弧度表示。
  361. * @param anticlockwise 如果为 true,逆时针绘制圆弧,反之,顺时针绘制。
  362. * @version Egret 2.4
  363. * @platform Web,Native
  364. */
  365. NativeRenderTextureRenderContext.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
  366. this.checkSurface();
  367. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  368. native.$cmdManager.arc(x, y, radius, startAngle, endAngle, anticlockwise ? 1 : 0);
  369. // this.$nativeGraphicsContext.arc(x, y, radius, startAngle, endAngle, anticlockwise);
  370. };
  371. /**
  372. * @private
  373. * 绘制一段二次贝塞尔曲线路径。它需要2个点。 第一个点是控制点,第二个点是终点。 起始点是当前路径最新的点,当创建二次贝赛尔曲线之前,可以使用 moveTo() 方法进行改变。
  374. * @param cpx 控制点的 x 轴坐标。
  375. * @param cpy 控制点的 y 轴坐标。
  376. * @param x 终点的 x 轴坐标。
  377. * @param y 终点的 y 轴坐标。
  378. * @version Egret 2.4
  379. * @platform Web,Native
  380. */
  381. NativeRenderTextureRenderContext.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
  382. this.checkSurface();
  383. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  384. native.$cmdManager.quadraticCurveTo(cpx, cpy, x, y);
  385. // this.$nativeGraphicsContext.quadraticCurveTo(cpx, cpy, x, y);
  386. };
  387. /**
  388. * @private
  389. * 使用直线连接子路径的终点到x,y坐标。
  390. * @param x 直线终点的 x 轴坐标。
  391. * @param y 直线终点的 y 轴坐标。
  392. * @version Egret 2.4
  393. * @platform Web,Native
  394. */
  395. NativeRenderTextureRenderContext.prototype.lineTo = function (x, y) {
  396. this.checkSurface();
  397. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  398. native.$cmdManager.lineTo(x, y);
  399. };
  400. /**
  401. * @private
  402. * 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
  403. * @param fillRule 一种算法,决定点是在路径内还是在路径外。允许的值:
  404. * "nonzero": 非零环绕规则, 默认的规则。
  405. * "evenodd": 奇偶环绕规则。
  406. * @version Egret 2.4
  407. * @platform Web,Native
  408. */
  409. NativeRenderTextureRenderContext.prototype.fill = function (fillRule) {
  410. this.checkSurface();
  411. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  412. var s1 = native.$cmdManager.pushString(fillRule);
  413. native.$cmdManager.fill(s1);
  414. };
  415. /**
  416. * @private
  417. * 使笔点返回到当前子路径的起始点。它尝试从当前点到起始点绘制一条直线。如果图形已经是封闭的或者只有一个点,那么此方法不会做任何操作。
  418. * @version Egret 2.4
  419. * @platform Web,Native
  420. */
  421. NativeRenderTextureRenderContext.prototype.closePath = function () {
  422. this.checkSurface();
  423. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  424. native.$cmdManager.closePath();
  425. };
  426. /**
  427. * @private
  428. * 创建一段矩形路径,矩形的起点位置是 (x, y) ,尺寸为 width 和 height。矩形的4个点通过直线连接,子路径做为闭合的标记,所以你可以填充或者描边矩形。
  429. * @param x 矩形起点的 x 轴坐标。
  430. * @param y 矩形起点的 y 轴坐标。
  431. * @param width 矩形的宽度。
  432. * @param height 矩形的高度。
  433. * @version Egret 2.4
  434. * @platform Web,Native
  435. */
  436. NativeRenderTextureRenderContext.prototype.rect = function (x, y, w, h) {
  437. this.checkSurface();
  438. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  439. native.$cmdManager.rect(x, y, w, h);
  440. this.$clipRect.setTo(x, y, w, h);
  441. };
  442. /**
  443. * @private
  444. * 将一个新的子路径的起始点移动到(x,y)坐标
  445. * @param x 点的 x 轴
  446. * @param y 点的 y 轴
  447. * @version Egret 2.4
  448. * @platform Web,Native
  449. */
  450. NativeRenderTextureRenderContext.prototype.moveTo = function (x, y) {
  451. this.checkSurface();
  452. // this.$nativeGraphicsContext.moveTo(x, y);
  453. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  454. native.$cmdManager.moveTo(x, y);
  455. };
  456. /**
  457. * @private
  458. * 绘制一个填充矩形。矩形的起点在 (x, y) 位置,矩形的尺寸是 width 和 height ,fillStyle 属性决定矩形的样式。
  459. * @param x 矩形起始点的 x 轴坐标。
  460. * @param y 矩形起始点的 y 轴坐标。
  461. * @param width 矩形的宽度。
  462. * @param height 矩形的高度。
  463. * @version Egret 2.4
  464. * @platform Web,Native
  465. */
  466. NativeRenderTextureRenderContext.prototype.fillRect = function (x, y, w, h) {
  467. this.checkSurface();
  468. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  469. native.$cmdManager.fillRect(x, y, w, h);
  470. // this.$nativeGraphicsContext.fillRect(x, y, w, h);
  471. };
  472. /**
  473. * @private
  474. * 绘制一段三次贝赛尔曲线路径。该方法需要三个点。 第一、第二个点是控制点,第三个点是结束点。起始点是当前路径的最后一个点,
  475. * 绘制贝赛尔曲线前,可以通过调用 moveTo() 进行修改。
  476. * @param cp1x 第一个控制点的 x 轴坐标。
  477. * @param cp1y 第一个控制点的 y 轴坐标。
  478. * @param cp2x 第二个控制点的 x 轴坐标。
  479. * @param cp2y 第二个控制点的 y 轴坐标。
  480. * @param x 结束点的 x 轴坐标。
  481. * @param y 结束点的 y 轴坐标。
  482. * @version Egret 2.4
  483. * @platform Web,Native
  484. */
  485. NativeRenderTextureRenderContext.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  486. this.checkSurface();
  487. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  488. native.$cmdManager.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  489. // this.$nativeGraphicsContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  490. };
  491. /**
  492. * @private
  493. * 根据当前的画线样式,绘制当前或已经存在的路径的方法。
  494. * @version Egret 2.4
  495. * @platform Web,Native
  496. */
  497. NativeRenderTextureRenderContext.prototype.stroke = function () {
  498. this.checkSurface();
  499. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  500. native.$cmdManager.stroke();
  501. // this.$nativeGraphicsContext.stroke();
  502. };
  503. /**
  504. * @private
  505. * 使用当前的绘画样式,描绘一个起点在 (x, y) 、宽度为 w 、高度为 h 的矩形的方法。
  506. * @param x 矩形起点的 x 轴坐标。
  507. * @param y 矩形起点的 y 轴坐标。
  508. * @param width 矩形的宽度。
  509. * @param height 矩形的高度。
  510. * @version Egret 2.4
  511. * @platform Web,Native
  512. */
  513. NativeRenderTextureRenderContext.prototype.strokeRect = function (x, y, w, h) {
  514. //console.log("strokeRect");
  515. this.checkSurface();
  516. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  517. native.$cmdManager.strokeRect(x, y, w, h);
  518. // this.$nativeGraphicsContext.strokeRect(x, y, w, h);
  519. };
  520. /**
  521. * @private
  522. * 清空子路径列表开始一个新路径。 当你想创建一个新的路径时,调用此方法。
  523. * @version Egret 2.4
  524. * @platform Web,Native
  525. */
  526. NativeRenderTextureRenderContext.prototype.beginPath = function () {
  527. this.checkSurface();
  528. native.$cmdManager.setContext(this.$nativeGraphicsContext);
  529. native.$cmdManager.beginPath();
  530. };
  531. /**
  532. * @private
  533. * 根据控制点和半径绘制一段圆弧路径,使用直线连接前一个点。
  534. * @param x1 第一个控制点的 x 轴坐标。
  535. * @param y1 第一个控制点的 y 轴坐标。
  536. * @param x2 第二个控制点的 x 轴坐标。
  537. * @param y2 第二个控制点的 y 轴坐标。
  538. * @param radius 圆弧的半径。
  539. * @version Egret 2.4
  540. * @platform Web,Native
  541. */
  542. NativeRenderTextureRenderContext.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  543. this.checkSurface();
  544. this.$nativeGraphicsContext.arcTo(x1, y1, x2, y2, radius);
  545. };
  546. /**
  547. * @private
  548. * 使用方法参数描述的矩阵多次叠加当前的变换矩阵。
  549. * @param a 水平缩放。
  550. * @param b 水平倾斜。
  551. * @param c 垂直倾斜。
  552. * @param d 垂直缩放。
  553. * @param tx 水平移动。
  554. * @param ty 垂直移动。
  555. * @version Egret 2.4
  556. * @platform Web,Native
  557. */
  558. NativeRenderTextureRenderContext.prototype.transform = function (a, b, c, d, tx, ty) {
  559. this.$matrix.append(a, b, c, d, tx, ty);
  560. this.setTransformToNative();
  561. };
  562. /**
  563. * @private
  564. * 通过在网格中移动 surface 和 surface 原点 x 水平方向、原点 y 垂直方向,添加平移变换
  565. * @param x 水平移动。
  566. * @param y 垂直移动。
  567. * @version Egret 2.4
  568. * @platform Web,Native
  569. */
  570. NativeRenderTextureRenderContext.prototype.translate = function (x, y) {
  571. this.$matrix.translate(x, y);
  572. this.setTransformToNative();
  573. };
  574. /**
  575. * @private
  576. * 根据 x 水平方向和 y 垂直方向,为 surface 单位添加缩放变换。
  577. * @param x 水平方向的缩放因子。
  578. * @param y 垂直方向的缩放因子。
  579. * @version Egret 2.4
  580. * @platform Web,Native
  581. */
  582. NativeRenderTextureRenderContext.prototype.scale = function (x, y) {
  583. this.$matrix.scale(x, y);
  584. this.setTransformToNative();
  585. };
  586. /**
  587. * @private
  588. * 在变换矩阵中增加旋转,角度变量表示一个顺时针旋转角度并且用弧度表示。
  589. * @param angle 顺时针旋转的弧度。
  590. * @version Egret 2.4
  591. * @platform Web,Native
  592. */
  593. NativeRenderTextureRenderContext.prototype.rotate = function (angle) {
  594. this.$matrix.rotate(angle);
  595. this.setTransformToNative();
  596. };
  597. /**
  598. * @private
  599. * 恢复到最近的绘制样式状态,此状态是通过 save() 保存到”状态栈“中最新的元素。
  600. * @version Egret 2.4
  601. * @platform Web,Native
  602. */
  603. NativeRenderTextureRenderContext.prototype.restore = function () {
  604. //console.log("restore");
  605. if (this.$saveCount > 0) {
  606. if (this.$saveList.length) {
  607. var data = this.$saveList.pop();
  608. for (var key in data) {
  609. this[key] = data[key];
  610. }
  611. this.setTransformToNative();
  612. }
  613. var index = this.$clipList.indexOf(this.$saveCount);
  614. if (index != -1) {
  615. var length_3 = this.$clipList.length;
  616. this.$clipList.splice(index, length_3 - index);
  617. for (; index < length_3; index++) {
  618. this.checkSurface();
  619. native.$cmdManager.setContext(this.$nativeContext);
  620. native.$cmdManager.popClip();
  621. }
  622. }
  623. this.$saveCount--;
  624. }
  625. };
  626. /**
  627. * @private
  628. * 使用栈保存当前的绘画样式状态,你可以使用 restore() 恢复任何改变。
  629. * @version Egret 2.4
  630. * @platform Web,Native
  631. */
  632. NativeRenderTextureRenderContext.prototype.save = function () {
  633. //console.log("save");
  634. var transformMatrix = new egret.Matrix();
  635. transformMatrix.copyFrom(this.$matrix);
  636. this.$saveList.push({
  637. lineWidth: this.$lineWidth,
  638. globalCompositeOperation: this.$globalCompositeOperation,
  639. globalAlpha: this.$globalAlpha,
  640. strokeStyle: this.$strokeStyle,
  641. fillStyle: this.$fillStyle,
  642. font: this.$font,
  643. $matrix: transformMatrix
  644. });
  645. this.$saveCount++;
  646. };
  647. /**
  648. * @private
  649. * 从当前路径创建一个剪切路径。在 clip() 调用之后,绘制的所有信息只会出现在剪切路径内部。
  650. * @version Egret 2.4
  651. * @platform Web,Native
  652. */
  653. NativeRenderTextureRenderContext.prototype.clip = function (fillRule) {
  654. if (this.$clipRect.width > 0 && this.$clipRect.height > 0) {
  655. //console.log("push clip" + this.$clipRect.x + " " + this.$clipRect.y + " " + this.$clipRect.width + " " + this.$clipRect.height);
  656. this.checkSurface();
  657. native.$cmdManager.setContext(this.$nativeContext);
  658. native.$cmdManager.pushClip(this.$clipRect.x, this.$clipRect.y, this.$clipRect.width, this.$clipRect.height);
  659. this.$clipRect.setEmpty();
  660. this.$clipList.push(this.$saveCount);
  661. }
  662. };
  663. /**
  664. * @private
  665. * 设置指定矩形区域内(以 点 (x, y) 为起点,范围是(width, height) )所有像素变成透明,并擦除之前绘制的所有内容。
  666. * @param x 矩形起点的 x 轴坐标。
  667. * @param y 矩形起点的 y 轴坐标。
  668. * @param width 矩形的宽度。
  669. * @param height 矩形的高度。
  670. * @version Egret 2.4
  671. * @platform Web,Native
  672. */
  673. NativeRenderTextureRenderContext.prototype.clearRect = function (x, y, width, height) {
  674. //console.log("clearScreen");
  675. this.checkSurface();
  676. native.$cmdManager.setContext(this.$nativeContext);
  677. native.$cmdManager.clearScreen(0, 0, 0, 0);
  678. };
  679. /**
  680. * @private
  681. * 重新设置当前的变换为单位矩阵,并使用同样的变量调用 transform() 方法。
  682. * @param a 水平缩放。
  683. * @param b 水平倾斜。
  684. * @param c 垂直倾斜。
  685. * @param d 垂直缩放。
  686. * @param tx 水平移动。
  687. * @param ty 垂直移动。
  688. * @version Egret 2.4
  689. * @platform Web,Native
  690. */
  691. NativeRenderTextureRenderContext.prototype.setTransform = function (a, b, c, d, tx, ty) {
  692. this.$matrix.setTo(a, b, c, d, tx, ty);
  693. this.setTransformToNative();
  694. };
  695. NativeRenderTextureRenderContext.prototype.setTransformToNative = function () {
  696. var m = this.$matrix;
  697. //console.log("setTransformToNative::a=" + m.a + " b=" + m.b + " c=" + m.c + " d=" + m.d + " tx=" + m.tx + " ty=" + m.ty);
  698. this.checkSurface();
  699. // this.$nativeContext.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
  700. native.$cmdManager.setContext(this.$nativeContext);
  701. native.$cmdManager.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
  702. };
  703. /**
  704. * @private
  705. * 创建一个沿参数坐标指定的直线的渐变。该方法返回一个线性的 GraphicsGradient 对象。
  706. * @param x0 起点的 x 轴坐标。
  707. * @param y0 起点的 y 轴坐标。
  708. * @param x1 终点的 x 轴坐标。
  709. * @param y1 终点的 y 轴坐标。
  710. * @version Egret 2.4
  711. * @platform Web,Native
  712. */
  713. NativeRenderTextureRenderContext.prototype.createLinearGradient = function (x0, y0, x1, y1) {
  714. this.checkSurface();
  715. return this.$nativeGraphicsContext.createLinearGradient(x0, y0, x1, y1);
  716. };
  717. /**
  718. * @private
  719. * 根据参数确定的两个圆的坐标,创建一个放射性渐变。该方法返回一个放射性的 GraphicsGradient。
  720. * @param x0 开始圆形的 x 轴坐标。
  721. * @param y0 开始圆形的 y 轴坐标。
  722. * @param r0 开始圆形的半径。
  723. * @param x1 结束圆形的 x 轴坐标。
  724. * @param y1 结束圆形的 y 轴坐标。
  725. * @param r1 结束圆形的半径。
  726. * @version Egret 2.4
  727. * @platform Web,Native
  728. */
  729. NativeRenderTextureRenderContext.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) {
  730. this.checkSurface();
  731. return this.$nativeGraphicsContext.createRadialGradient(x0, y0, r0, x1, y1, r1);
  732. };
  733. /**
  734. * @private
  735. * 在(x,y)位置绘制(填充)文本。
  736. * @version Egret 2.4
  737. * @platform Web,Native
  738. */
  739. NativeRenderTextureRenderContext.prototype.fillText = function (text, x, y, maxWidth) {
  740. //console.log("drawText" + text);
  741. native.$cmdManager.setContext(egret_native.Label);
  742. var s1 = native.$cmdManager.pushString(this.$fontFamily);
  743. var s2 = native.$cmdManager.pushString("");
  744. native.$cmdManager.createLabel(s1, this.$fontSize, s2, this.$hasStrokeText ? this.$lineWidth : 0);
  745. this.$hasStrokeText = false;
  746. var s3 = native.$cmdManager.pushString(text);
  747. native.$cmdManager.drawText(s3, x, y);
  748. };
  749. NativeRenderTextureRenderContext.prototype.strokeText = function (text, x, y, maxWidth) {
  750. this.$hasStrokeText = true;
  751. };
  752. /**
  753. * @private
  754. * 测量指定文本宽度,返回 TextMetrics 对象。
  755. * @version Egret 2.4
  756. * @platform Web,Native
  757. */
  758. NativeRenderTextureRenderContext.prototype.measureText = function (text) {
  759. native.$cmdManager.setContext(egret_native.Label);
  760. var s1 = native.$cmdManager.pushString(this.$fontFamily);
  761. var s2 = native.$cmdManager.pushString("");
  762. native.$cmdManager.createLabel(s1, this.$fontSize, s2, this.$hasStrokeText ? this.$lineWidth : 0);
  763. return { width: egret_native.Label.getTextSize(text)[0] };
  764. };
  765. /**
  766. * @private
  767. * 注意:如果要对绘制的图片进行缩放,出于性能优化考虑,系统不会主动去每次重置imageSmoothingEnabled属性,因此您在调用drawImage()方法前请务必
  768. * 确保 imageSmoothingEnabled 已被重置为正常的值,否则有可能沿用上个显示对象绘制过程留下的值。
  769. * @version Egret 2.4
  770. * @platform Web,Native
  771. */
  772. NativeRenderTextureRenderContext.prototype.drawImage = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight) {
  773. var bitmapData;
  774. var isNative;
  775. if (image.$nativeRenderTexture) {
  776. bitmapData = image.$nativeRenderTexture;
  777. isNative = true;
  778. }
  779. else {
  780. bitmapData = image;
  781. isNative = false;
  782. }
  783. if (!bitmapData) {
  784. return;
  785. }
  786. if (arguments.length == 3) {
  787. surfaceOffsetX = offsetX;
  788. surfaceOffsetY = offsetY;
  789. offsetX = 0;
  790. offsetY = 0;
  791. width = surfaceImageWidth = image.width;
  792. height = surfaceImageHeight = image.height;
  793. }
  794. else if (arguments.length == 5) {
  795. surfaceOffsetX = offsetX;
  796. surfaceOffsetY = offsetY;
  797. surfaceImageWidth = width;
  798. surfaceImageHeight = height;
  799. offsetX = 0;
  800. offsetY = 0;
  801. width = image.width;
  802. height = image.height;
  803. }
  804. else {
  805. if (width == void 0) {
  806. width = image.width;
  807. }
  808. if (height == void 0) {
  809. height = image.height;
  810. }
  811. if (surfaceOffsetX == void 0) {
  812. surfaceOffsetX = 0;
  813. }
  814. if (surfaceOffsetY == void 0) {
  815. surfaceOffsetY = 0;
  816. }
  817. if (surfaceImageWidth == void 0) {
  818. surfaceImageWidth = width;
  819. }
  820. if (surfaceImageHeight == void 0) {
  821. surfaceImageHeight = height;
  822. }
  823. }
  824. //console.log("drawImage::" + offsetX + " " + offsetY + " " + width + " " + height + " " + surfaceOffsetX + " " + surfaceOffsetY + " " + surfaceImageWidth + " " + surfaceImageHeight);
  825. this.checkSurface();
  826. var imageAdress;
  827. if (!isNative) {
  828. if (!bitmapData._native_tex_loc) {
  829. bitmapData._native_tex_loc = bitmapData.___native_texture__p;
  830. }
  831. imageAdress = bitmapData._native_tex_loc;
  832. }
  833. else {
  834. imageAdress = bitmapData.___native_texture__p;
  835. }
  836. native.$cmdManager.setContext(this.$nativeContext);
  837. native.$cmdManager.drawImage(imageAdress, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight);
  838. };
  839. /**
  840. * @private
  841. * 基于指定的源图象(BitmapData)创建一个模板,通过repetition参数指定源图像在什么方向上进行重复,返回一个GraphicsPattern对象。
  842. * @param bitmapData 做为重复图像源的 BitmapData 对象。
  843. * @param repetition 指定如何重复图像。
  844. * 可能的值有:"repeat" (两个方向重复),"repeat-x" (仅水平方向重复),"repeat-y" (仅垂直方向重复),"no-repeat" (不重复).
  845. * @version Egret 2.4
  846. * @platform Web,Native
  847. */
  848. NativeRenderTextureRenderContext.prototype.createPattern = function (image, repetition) {
  849. return null;
  850. };
  851. /**
  852. * @private
  853. * 返回一个 ImageData 对象,用来描述canvas区域隐含的像素数据,这个区域通过矩形表示,起始点为(sx, sy)、宽为sw、高为sh。
  854. * @version Egret 2.4
  855. * @platform Web,Native
  856. */
  857. NativeRenderTextureRenderContext.prototype.getImageData = function (sx, sy, sw, sh) {
  858. native.$cmdManager.flush();
  859. var res;
  860. if (native.$currentSurface == this.surface) {
  861. if (native.$currentSurface != null) {
  862. native.$currentSurface.end();
  863. }
  864. }
  865. res = this.surface.getImageData(sx, sy, sw, sh);
  866. if (res.pixelData) {
  867. res.data = res.pixelData;
  868. }
  869. return res;
  870. };
  871. NativeRenderTextureRenderContext.prototype.checkSurface = function () {
  872. //todo 暂时先写这里
  873. if (native.$currentSurface != this.surface) {
  874. if (native.$currentSurface != null) {
  875. native.$currentSurface.end();
  876. }
  877. if (this.surface) {
  878. this.surface.begin();
  879. }
  880. }
  881. };
  882. return NativeRenderTextureRenderContext;
  883. }(egret.HashObject));
  884. native.NativeRenderTextureRenderContext = NativeRenderTextureRenderContext;
  885. __reflect(NativeRenderTextureRenderContext.prototype, "egret.native.NativeRenderTextureRenderContext");
  886. })(native = egret.native || (egret.native = {}));
  887. })(egret || (egret = {}));
  888. //////////////////////////////////////////////////////////////////////////////////////
  889. //
  890. // Copyright (c) 2014-present, Egret Technology.
  891. // All rights reserved.
  892. // Redistribution and use in source and binary forms, with or without
  893. // modification, are permitted provided that the following conditions are met:
  894. //
  895. // * Redistributions of source code must retain the above copyright
  896. // notice, this list of conditions and the following disclaimer.
  897. // * Redistributions in binary form must reproduce the above copyright
  898. // notice, this list of conditions and the following disclaimer in the
  899. // documentation and/or other materials provided with the distribution.
  900. // * Neither the name of the Egret nor the
  901. // names of its contributors may be used to endorse or promote products
  902. // derived from this software without specific prior written permission.
  903. //
  904. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  905. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  906. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  907. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  908. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  909. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  910. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  911. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  912. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  913. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  914. //
  915. //////////////////////////////////////////////////////////////////////////////////////
  916. var egret;
  917. (function (egret) {
  918. var native;
  919. (function (native) {
  920. var blendModesForGL = {
  921. "source-over": [1, 771],
  922. "lighter": [770, 1],
  923. "destination-out": [0, 771],
  924. "destination-in": [0, 770]
  925. };
  926. /**
  927. * @version Egret 2.4
  928. * @platform Web,Native
  929. * @private
  930. */
  931. var OldNativeRenderTextureRenderContext = (function (_super) {
  932. __extends(OldNativeRenderTextureRenderContext, _super);
  933. function OldNativeRenderTextureRenderContext() {
  934. var _this = _super.apply(this, arguments) || this;
  935. _this.$matrix = new egret.Matrix();
  936. _this.$nativeContext = egret_native.Graphics;
  937. _this.$nativeGraphicsContext = egret_native.rastergl;
  938. _this.$globalCompositeOperation = "source-over";
  939. _this.$globalAlpha = 1;
  940. _this.$lineWidth = 0;
  941. _this.$strokeStyle = "#000000";
  942. _this.$fillStyle = "#000000";
  943. _this.$font = "normal normal 10px sans-serif";
  944. _this.$fontSize = 10;
  945. _this.$fontFamily = "";
  946. _this.clipRectArray = null;
  947. _this.$saveList = [];
  948. _this.$clipRect = new egret.Rectangle();
  949. _this.$saveCount = 0;
  950. _this.$clipList = [];
  951. _this.$hasStrokeText = false;
  952. return _this;
  953. }
  954. Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "globalCompositeOperation", {
  955. /**
  956. * @private
  957. * 设置新图像如何绘制到已有的图像上的规制
  958. * @version Egret 2.4
  959. * @platform Web,Native
  960. */
  961. get: function () {
  962. return this.$globalCompositeOperation;
  963. },
  964. set: function (value) {
  965. this.$globalCompositeOperation = value;
  966. var arr = blendModesForGL[value];
  967. if (arr) {
  968. this.checkSurface();
  969. this.$nativeContext.setBlendArg(arr[0], arr[1]);
  970. }
  971. },
  972. enumerable: true,
  973. configurable: true
  974. });
  975. Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "globalAlpha", {
  976. /**
  977. * @private
  978. * 设置接下来绘图填充的整体透明度
  979. * @version Egret 2.4
  980. * @platform Web,Native
  981. */
  982. get: function () {
  983. return this.$globalAlpha;
  984. },
  985. set: function (value) {
  986. this.$globalAlpha = value;
  987. this.checkSurface();
  988. this.$nativeContext.setGlobalAlpha(value);
  989. },
  990. enumerable: true,
  991. configurable: true
  992. });
  993. Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "lineWidth", {
  994. /**
  995. * @private
  996. * 设置线条粗细,以像素为单位。设置为0,负数,Infinity 或 NaN 将会被忽略。
  997. * @default 1
  998. * @version Egret 2.4
  999. * @platform Web,Native
  1000. */
  1001. get: function () {
  1002. return this.$lineWidth;
  1003. },
  1004. set: function (value) {
  1005. //console.log("set lineWidth" + value);
  1006. this.$lineWidth = value;
  1007. this.$nativeContext.lineWidth = value;
  1008. this.checkSurface();
  1009. this.$nativeGraphicsContext.lineWidth = value;
  1010. },
  1011. enumerable: true,
  1012. configurable: true
  1013. });
  1014. Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "strokeStyle", {
  1015. /**
  1016. * @private
  1017. * 设置要在图形边线填充的颜色或样式
  1018. * @default "#000000"
  1019. * @version Egret 2.4
  1020. * @platform Web,Native
  1021. */
  1022. get: function () {
  1023. return this.$strokeStyle;
  1024. },
  1025. set: function (value) {
  1026. this.$strokeStyle = value;
  1027. if (value != null) {
  1028. if (value.indexOf("rgba") != -1) {
  1029. value = this.$parseRGBA(value);
  1030. }
  1031. else if (value.indexOf("rgb") != -1) {
  1032. value = this.$parseRGB(value);
  1033. }
  1034. egret_native.Label.setStrokeColor(parseInt(value.replace("#", "0x")));
  1035. }
  1036. this.checkSurface();
  1037. this.$nativeGraphicsContext.strokeStyle = value;
  1038. },
  1039. enumerable: true,
  1040. configurable: true
  1041. });
  1042. Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "fillStyle", {
  1043. /**
  1044. * @private
  1045. * 设置要在图形内部填充的颜色或样式
  1046. * @default "#000000"
  1047. * @version Egret 2.4
  1048. * @platform Web,Native
  1049. */
  1050. get: function () {
  1051. return this.$fillStyle;
  1052. },
  1053. set: function (value) {
  1054. this.$fillStyle = value;
  1055. if (value != null) {
  1056. if (value.indexOf("rgba") != -1) {
  1057. value = this.$parseRGBA(value);
  1058. }
  1059. else if (value.indexOf("rgb") != -1) {
  1060. value = this.$parseRGB(value);
  1061. }
  1062. egret_native.Label.setTextColor(parseInt(value.replace("#", "0x")));
  1063. }
  1064. this.checkSurface();
  1065. this.$nativeGraphicsContext.fillStyle = value;
  1066. },
  1067. enumerable: true,
  1068. configurable: true
  1069. });
  1070. OldNativeRenderTextureRenderContext.prototype.$fillColorStr = function (s) {
  1071. if (s.length < 2) {
  1072. s = "0" + s;
  1073. }
  1074. return s;
  1075. };
  1076. OldNativeRenderTextureRenderContext.prototype.$parseRGBA = function (str) {
  1077. var index = str.indexOf("(");
  1078. str = str.slice(index + 1, str.length - 1);
  1079. var arr = str.split(",");
  1080. var a = parseInt((parseFloat(arr[3]) * 255)).toString(16);
  1081. var r = parseInt(arr[0]).toString(16);
  1082. var g = parseInt(arr[1]).toString(16);
  1083. var b = parseInt(arr[2]).toString(16);
  1084. str = "#" + this.$fillColorStr(a) + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
  1085. return str;
  1086. };
  1087. OldNativeRenderTextureRenderContext.prototype.$parseRGB = function (str) {
  1088. var index = str.indexOf("(");
  1089. str = str.slice(index + 1, str.length - 1);
  1090. var arr = str.split(",");
  1091. var r = parseInt(arr[0]).toString(16);
  1092. var g = parseInt(arr[1]).toString(16);
  1093. var b = parseInt(arr[2]).toString(16);
  1094. str = "#" + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
  1095. return str;
  1096. };
  1097. Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "font", {
  1098. /**
  1099. * @private
  1100. * 当前的字体样式
  1101. * @version Egret 2.4
  1102. * @platform Web,Native
  1103. */
  1104. get: function () {
  1105. return this.$font;
  1106. },
  1107. set: function (value) {
  1108. this.$font = value;
  1109. var arr = value.split(" ");
  1110. var sizeTxt = arr[2];
  1111. if (sizeTxt.indexOf("px") != -1) {
  1112. this.$fontSize = parseInt(sizeTxt.replace("px", ""));
  1113. }
  1114. if (egret.useFontMapping) {
  1115. var fontFamilyText = void 0;
  1116. if (arr.length == 4) {
  1117. fontFamilyText = arr[3];
  1118. }
  1119. else {
  1120. fontFamilyText = arr.slice(3).join(" ");
  1121. }
  1122. if (fontFamilyText.indexOf(", ") != -1) {
  1123. arr = fontFamilyText.split(", ");
  1124. }
  1125. else if (fontFamilyText.indexOf(",") != -1) {
  1126. arr = fontFamilyText.split(",");
  1127. var length_4 = arr.length;
  1128. for (var i = 0; i < length_4; i++) {
  1129. var fontFamily = arr[i];
  1130. //暂时先不考虑带有引号的情况
  1131. if (egret.fontMapping[fontFamily]) {
  1132. this.$fontFamily = egret.fontMapping[fontFamily];
  1133. return;
  1134. }
  1135. }
  1136. }
  1137. else {
  1138. this.$fontFamily = egret.fontMapping[fontFamilyText];
  1139. }
  1140. if (!this.$fontFamily) {
  1141. this.$fontFamily = "/system/fonts/DroidSansFallback.ttf";
  1142. }
  1143. }
  1144. else {
  1145. //兼容旧版本直接将 default_fontFamily 设置为字体路径的情况
  1146. this.$fontFamily = egret.TextField.default_fontFamily;
  1147. }
  1148. },
  1149. enumerable: true,
  1150. configurable: true
  1151. });
  1152. /**
  1153. * @private
  1154. * 绘制一段圆弧路径。圆弧路径的圆心在 (x, y) 位置,半径为 r ,根据anticlockwise (默认为顺时针)指定的方向从 startAngle 开始绘制,到 endAngle 结束。
  1155. * @param x 圆弧中心(圆心)的 x 轴坐标。
  1156. * @param y 圆弧中心(圆心)的 y 轴坐标。
  1157. * @param radius 圆弧的半径。
  1158. * @param startAngle 圆弧的起始点, x轴方向开始计算,单位以弧度表示。
  1159. * @param endAngle 圆弧的重点, 单位以弧度表示。
  1160. * @param anticlockwise 如果为 true,逆时针绘制圆弧,反之,顺时针绘制。
  1161. * @version Egret 2.4
  1162. * @platform Web,Native
  1163. */
  1164. OldNativeRenderTextureRenderContext.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
  1165. this.checkSurface();
  1166. this.$nativeGraphicsContext.arc(x, y, radius, startAngle, endAngle, anticlockwise);
  1167. };
  1168. /**
  1169. * @private
  1170. * 绘制一段二次贝塞尔曲线路径。它需要2个点。 第一个点是控制点,第二个点是终点。 起始点是当前路径最新的点,当创建二次贝赛尔曲线之前,可以使用 moveTo() 方法进行改变。
  1171. * @param cpx 控制点的 x 轴坐标。
  1172. * @param cpy 控制点的 y 轴坐标。
  1173. * @param x 终点的 x 轴坐标。
  1174. * @param y 终点的 y 轴坐标。
  1175. * @version Egret 2.4
  1176. * @platform Web,Native
  1177. */
  1178. OldNativeRenderTextureRenderContext.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
  1179. this.checkSurface();
  1180. this.$nativeGraphicsContext.quadraticCurveTo(cpx, cpy, x, y);
  1181. };
  1182. /**
  1183. * @private
  1184. * 使用直线连接子路径的终点到x,y坐标。
  1185. * @param x 直线终点的 x 轴坐标。
  1186. * @param y 直线终点的 y 轴坐标。
  1187. * @version Egret 2.4
  1188. * @platform Web,Native
  1189. */
  1190. OldNativeRenderTextureRenderContext.prototype.lineTo = function (x, y) {
  1191. this.checkSurface();
  1192. this.$nativeGraphicsContext.lineTo(x, y);
  1193. };
  1194. /**
  1195. * @private
  1196. * 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
  1197. * @param fillRule 一种算法,决定点是在路径内还是在路径外。允许的值:
  1198. * "nonzero": 非零环绕规则, 默认的规则。
  1199. * "evenodd": 奇偶环绕规则。
  1200. * @version Egret 2.4
  1201. * @platform Web,Native
  1202. */
  1203. OldNativeRenderTextureRenderContext.prototype.fill = function (fillRule) {
  1204. this.checkSurface();
  1205. this.$nativeGraphicsContext.fill(fillRule);
  1206. };
  1207. /**
  1208. * @private
  1209. * 使笔点返回到当前子路径的起始点。它尝试从当前点到起始点绘制一条直线。如果图形已经是封闭的或者只有一个点,那么此方法不会做任何操作。
  1210. * @version Egret 2.4
  1211. * @platform Web,Native
  1212. */
  1213. OldNativeRenderTextureRenderContext.prototype.closePath = function () {
  1214. this.checkSurface();
  1215. this.$nativeGraphicsContext.closePath();
  1216. };
  1217. /**
  1218. * @private
  1219. * 创建一段矩形路径,矩形的起点位置是 (x, y) ,尺寸为 width 和 height。矩形的4个点通过直线连接,子路径做为闭合的标记,所以你可以填充或者描边矩形。
  1220. * @param x 矩形起点的 x 轴坐标。
  1221. * @param y 矩形起点的 y 轴坐标。
  1222. * @param width 矩形的宽度。
  1223. * @param height 矩形的高度。
  1224. * @version Egret 2.4
  1225. * @platform Web,Native
  1226. */
  1227. OldNativeRenderTextureRenderContext.prototype.rect = function (x, y, w, h) {
  1228. this.checkSurface();
  1229. this.$nativeGraphicsContext.rect(x, y, w, h);
  1230. this.$clipRect.setTo(x, y, w, h);
  1231. };
  1232. /**
  1233. * @private
  1234. * 将一个新的子路径的起始点移动到(x,y)坐标
  1235. * @param x 点的 x 轴
  1236. * @param y 点的 y 轴
  1237. * @version Egret 2.4
  1238. * @platform Web,Native
  1239. */
  1240. OldNativeRenderTextureRenderContext.prototype.moveTo = function (x, y) {
  1241. this.checkSurface();
  1242. this.$nativeGraphicsContext.moveTo(x, y);
  1243. };
  1244. /**
  1245. * @private
  1246. * 绘制一个填充矩形。矩形的起点在 (x, y) 位置,矩形的尺寸是 width 和 height ,fillStyle 属性决定矩形的样式。
  1247. * @param x 矩形起始点的 x 轴坐标。
  1248. * @param y 矩形起始点的 y 轴坐标。
  1249. * @param width 矩形的宽度。
  1250. * @param height 矩形的高度。
  1251. * @version Egret 2.4
  1252. * @platform Web,Native
  1253. */
  1254. OldNativeRenderTextureRenderContext.prototype.fillRect = function (x, y, w, h) {
  1255. this.checkSurface();
  1256. this.$nativeGraphicsContext.fillRect(x, y, w, h);
  1257. };
  1258. /**
  1259. * @private
  1260. * 绘制一段三次贝赛尔曲线路径。该方法需要三个点。 第一、第二个点是控制点,第三个点是结束点。起始点是当前路径的最后一个点,
  1261. * 绘制贝赛尔曲线前,可以通过调用 moveTo() 进行修改。
  1262. * @param cp1x 第一个控制点的 x 轴坐标。
  1263. * @param cp1y 第一个控制点的 y 轴坐标。
  1264. * @param cp2x 第二个控制点的 x 轴坐标。
  1265. * @param cp2y 第二个控制点的 y 轴坐标。
  1266. * @param x 结束点的 x 轴坐标。
  1267. * @param y 结束点的 y 轴坐标。
  1268. * @version Egret 2.4
  1269. * @platform Web,Native
  1270. */
  1271. OldNativeRenderTextureRenderContext.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  1272. this.checkSurface();
  1273. this.$nativeGraphicsContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  1274. };
  1275. /**
  1276. * @private
  1277. * 根据当前的画线样式,绘制当前或已经存在的路径的方法。
  1278. * @version Egret 2.4
  1279. * @platform Web,Native
  1280. */
  1281. OldNativeRenderTextureRenderContext.prototype.stroke = function () {
  1282. this.checkSurface();
  1283. this.$nativeGraphicsContext.stroke();
  1284. };
  1285. /**
  1286. * @private
  1287. * 使用当前的绘画样式,描绘一个起点在 (x, y) 、宽度为 w 、高度为 h 的矩形的方法。
  1288. * @param x 矩形起点的 x 轴坐标。
  1289. * @param y 矩形起点的 y 轴坐标。
  1290. * @param width 矩形的宽度。
  1291. * @param height 矩形的高度。
  1292. * @version Egret 2.4
  1293. * @platform Web,Native
  1294. */
  1295. OldNativeRenderTextureRenderContext.prototype.strokeRect = function (x, y, w, h) {
  1296. //console.log("strokeRect");
  1297. this.checkSurface();
  1298. this.$nativeGraphicsContext.strokeRect(x, y, w, h);
  1299. };
  1300. /**
  1301. * @private
  1302. * 清空子路径列表开始一个新路径。 当你想创建一个新的路径时,调用此方法。
  1303. * @version Egret 2.4
  1304. * @platform Web,Native
  1305. */
  1306. OldNativeRenderTextureRenderContext.prototype.beginPath = function () {
  1307. this.checkSurface();
  1308. this.$nativeGraphicsContext.beginPath();
  1309. };
  1310. /**
  1311. * @private
  1312. * 根据控制点和半径绘制一段圆弧路径,使用直线连接前一个点。
  1313. * @param x1 第一个控制点的 x 轴坐标。
  1314. * @param y1 第一个控制点的 y 轴坐标。
  1315. * @param x2 第二个控制点的 x 轴坐标。
  1316. * @param y2 第二个控制点的 y 轴坐标。
  1317. * @param radius 圆弧的半径。
  1318. * @version Egret 2.4
  1319. * @platform Web,Native
  1320. */
  1321. OldNativeRenderTextureRenderContext.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  1322. this.checkSurface();
  1323. this.$nativeGraphicsContext.arcTo(x1, y1, x2, y2, radius);
  1324. };
  1325. /**
  1326. * @private
  1327. * 使用方法参数描述的矩阵多次叠加当前的变换矩阵。
  1328. * @param a 水平缩放。
  1329. * @param b 水平倾斜。
  1330. * @param c 垂直倾斜。
  1331. * @param d 垂直缩放。
  1332. * @param tx 水平移动。
  1333. * @param ty 垂直移动。
  1334. * @version Egret 2.4
  1335. * @platform Web,Native
  1336. */
  1337. OldNativeRenderTextureRenderContext.prototype.transform = function (a, b, c, d, tx, ty) {
  1338. this.$matrix.append(a, b, c, d, tx, ty);
  1339. this.setTransformToNative();
  1340. };
  1341. /**
  1342. * @private
  1343. * 通过在网格中移动 surface 和 surface 原点 x 水平方向、原点 y 垂直方向,添加平移变换
  1344. * @param x 水平移动。
  1345. * @param y 垂直移动。
  1346. * @version Egret 2.4
  1347. * @platform Web,Native
  1348. */
  1349. OldNativeRenderTextureRenderContext.prototype.translate = function (x, y) {
  1350. this.$matrix.translate(x, y);
  1351. this.setTransformToNative();
  1352. };
  1353. /**
  1354. * @private
  1355. * 根据 x 水平方向和 y 垂直方向,为 surface 单位添加缩放变换。
  1356. * @param x 水平方向的缩放因子。
  1357. * @param y 垂直方向的缩放因子。
  1358. * @version Egret 2.4
  1359. * @platform Web,Native
  1360. */
  1361. OldNativeRenderTextureRenderContext.prototype.scale = function (x, y) {
  1362. this.$matrix.scale(x, y);
  1363. this.setTransformToNative();
  1364. };
  1365. /**
  1366. * @private
  1367. * 在变换矩阵中增加旋转,角度变量表示一个顺时针旋转角度并且用弧度表示。
  1368. * @param angle 顺时针旋转的弧度。
  1369. * @version Egret 2.4
  1370. * @platform Web,Native
  1371. */
  1372. OldNativeRenderTextureRenderContext.prototype.rotate = function (angle) {
  1373. this.$matrix.rotate(angle);
  1374. this.setTransformToNative();
  1375. };
  1376. /**
  1377. * @private
  1378. * 恢复到最近的绘制样式状态,此状态是通过 save() 保存到”状态栈“中最新的元素。
  1379. * @version Egret 2.4
  1380. * @platform Web,Native
  1381. */
  1382. OldNativeRenderTextureRenderContext.prototype.restore = function () {
  1383. //console.log("restore");
  1384. if (this.$saveCount > 0) {
  1385. if (this.$saveList.length) {
  1386. var data = this.$saveList.pop();
  1387. for (var key in data) {
  1388. this[key] = data[key];
  1389. }
  1390. this.setTransformToNative();
  1391. }
  1392. var index = this.$clipList.indexOf(this.$saveCount);
  1393. if (index != -1) {
  1394. var length_5 = this.$clipList.length;
  1395. this.$clipList.splice(index, length_5 - index);
  1396. for (; index < length_5; index++) {
  1397. this.checkSurface();
  1398. this.$nativeContext.popClip();
  1399. }
  1400. }
  1401. this.$saveCount--;
  1402. }
  1403. };
  1404. /**
  1405. * @private
  1406. * 使用栈保存当前的绘画样式状态,你可以使用 restore() 恢复任何改变。
  1407. * @version Egret 2.4
  1408. * @platform Web,Native
  1409. */
  1410. OldNativeRenderTextureRenderContext.prototype.save = function () {
  1411. //console.log("save");
  1412. var transformMatrix = new egret.Matrix();
  1413. transformMatrix.copyFrom(this.$matrix);
  1414. this.$saveList.push({
  1415. lineWidth: this.$lineWidth,
  1416. globalCompositeOperation: this.$globalCompositeOperation,
  1417. globalAlpha: this.$globalAlpha,
  1418. strokeStyle: this.$strokeStyle,
  1419. fillStyle: this.$fillStyle,
  1420. font: this.$font,
  1421. $matrix: transformMatrix
  1422. });
  1423. this.$saveCount++;
  1424. };
  1425. /**
  1426. * @private
  1427. * 从当前路径创建一个剪切路径。在 clip() 调用之后,绘制的所有信息只会出现在剪切路径内部。
  1428. * @version Egret 2.4
  1429. * @platform Web,Native
  1430. */
  1431. OldNativeRenderTextureRenderContext.prototype.clip = function (fillRule) {
  1432. if (this.$clipRect.width > 0 && this.$clipRect.height > 0) {
  1433. //console.log("push clip" + this.$clipRect.x + " " + this.$clipRect.y + " " + this.$clipRect.width + " " + this.$clipRect.height);
  1434. this.checkSurface();
  1435. this.$nativeContext.pushClip(this.$clipRect.x, this.$clipRect.y, this.$clipRect.width, this.$clipRect.height);
  1436. this.$clipRect.setEmpty();
  1437. this.$clipList.push(this.$saveCount);
  1438. }
  1439. };
  1440. /**
  1441. * @private
  1442. * 设置指定矩形区域内(以 点 (x, y) 为起点,范围是(width, height) )所有像素变成透明,并擦除之前绘制的所有内容。
  1443. * @param x 矩形起点的 x 轴坐标。
  1444. * @param y 矩形起点的 y 轴坐标。
  1445. * @param width 矩形的宽度。
  1446. * @param height 矩形的高度。
  1447. * @version Egret 2.4
  1448. * @platform Web,Native
  1449. */
  1450. OldNativeRenderTextureRenderContext.prototype.clearRect = function (x, y, width, height) {
  1451. //console.log("clearScreen");
  1452. this.checkSurface();
  1453. this.$nativeContext.clearScreen(0, 0, 0);
  1454. };
  1455. /**
  1456. * @private
  1457. * 重新设置当前的变换为单位矩阵,并使用同样的变量调用 transform() 方法。
  1458. * @param a 水平缩放。
  1459. * @param b 水平倾斜。
  1460. * @param c 垂直倾斜。
  1461. * @param d 垂直缩放。
  1462. * @param tx 水平移动。
  1463. * @param ty 垂直移动。
  1464. * @version Egret 2.4
  1465. * @platform Web,Native
  1466. */
  1467. OldNativeRenderTextureRenderContext.prototype.setTransform = function (a, b, c, d, tx, ty) {
  1468. this.$matrix.setTo(a, b, c, d, tx, ty);
  1469. this.setTransformToNative();
  1470. };
  1471. OldNativeRenderTextureRenderContext.prototype.setTransformToNative = function () {
  1472. var m = this.$matrix;
  1473. //console.log("setTransformToNative::a=" + m.a + " b=" + m.b + " c=" + m.c + " d=" + m.d + " tx=" + m.tx + " ty=" + m.ty);
  1474. this.checkSurface();
  1475. this.$nativeContext.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
  1476. };
  1477. /**
  1478. * @private
  1479. * 创建一个沿参数坐标指定的直线的渐变。该方法返回一个线性的 GraphicsGradient 对象。
  1480. * @param x0 起点的 x 轴坐标。
  1481. * @param y0 起点的 y 轴坐标。
  1482. * @param x1 终点的 x 轴坐标。
  1483. * @param y1 终点的 y 轴坐标。
  1484. * @version Egret 2.4
  1485. * @platform Web,Native
  1486. */
  1487. OldNativeRenderTextureRenderContext.prototype.createLinearGradient = function (x0, y0, x1, y1) {
  1488. this.checkSurface();
  1489. return this.$nativeGraphicsContext.createLinearGradient(x0, y0, x1, y1);
  1490. };
  1491. /**
  1492. * @private
  1493. * 根据参数确定的两个圆的坐标,创建一个放射性渐变。该方法返回一个放射性的 GraphicsGradient。
  1494. * @param x0 开始圆形的 x 轴坐标。
  1495. * @param y0 开始圆形的 y 轴坐标。
  1496. * @param r0 开始圆形的半径。
  1497. * @param x1 结束圆形的 x 轴坐标。
  1498. * @param y1 结束圆形的 y 轴坐标。
  1499. * @param r1 结束圆形的半径。
  1500. * @version Egret 2.4
  1501. * @platform Web,Native
  1502. */
  1503. OldNativeRenderTextureRenderContext.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) {
  1504. this.checkSurface();
  1505. return this.$nativeGraphicsContext.createRadialGradient(x0, y0, r0, x1, y1, r1);
  1506. };
  1507. /**
  1508. * @private
  1509. * 在(x,y)位置绘制(填充)文本。
  1510. * @version Egret 2.4
  1511. * @platform Web,Native
  1512. */
  1513. OldNativeRenderTextureRenderContext.prototype.fillText = function (text, x, y, maxWidth) {
  1514. //console.log("drawText" + text);
  1515. egret_native.Label.createLabel(this.$fontFamily, this.$fontSize, "", this.$hasStrokeText ? this.$lineWidth : 0);
  1516. this.$hasStrokeText = false;
  1517. egret_native.Label.drawText(text, x, y);
  1518. };
  1519. OldNativeRenderTextureRenderContext.prototype.strokeText = function (text, x, y, maxWidth) {
  1520. this.$hasStrokeText = true;
  1521. };
  1522. /**
  1523. * @private
  1524. * 测量指定文本宽度,返回 TextMetrics 对象。
  1525. * @version Egret 2.4
  1526. * @platform Web,Native
  1527. */
  1528. OldNativeRenderTextureRenderContext.prototype.measureText = function (text) {
  1529. egret_native.Label.createLabel(this.$fontFamily, this.$fontSize, "", this.$hasStrokeText ? this.$lineWidth : 0);
  1530. return { width: egret_native.Label.getTextSize(text)[0] };
  1531. };
  1532. /**
  1533. * @private
  1534. * 注意:如果要对绘制的图片进行缩放,出于性能优化考虑,系统不会主动去每次重置imageSmoothingEnabled属性,因此您在调用drawImage()方法前请务必
  1535. * 确保 imageSmoothingEnabled 已被重置为正常的值,否则有可能沿用上个显示对象绘制过程留下的值。
  1536. * @version Egret 2.4
  1537. * @platform Web,Native
  1538. */
  1539. OldNativeRenderTextureRenderContext.prototype.drawImage = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight) {
  1540. var bitmapData;
  1541. var isNative;
  1542. if (image.$nativeRenderTexture) {
  1543. bitmapData = image.$nativeRenderTexture;
  1544. isNative = true;
  1545. }
  1546. else {
  1547. bitmapData = image;
  1548. isNative = false;
  1549. }
  1550. if (!bitmapData) {
  1551. return;
  1552. }
  1553. if (arguments.length == 3) {
  1554. surfaceOffsetX = offsetX;
  1555. surfaceOffsetY = offsetY;
  1556. offsetX = 0;
  1557. offsetY = 0;
  1558. width = surfaceImageWidth = image.width;
  1559. height = surfaceImageHeight = image.height;
  1560. }
  1561. else if (arguments.length == 5) {
  1562. surfaceOffsetX = offsetX;
  1563. surfaceOffsetY = offsetY;
  1564. surfaceImageWidth = width;
  1565. surfaceImageHeight = height;
  1566. offsetX = 0;
  1567. offsetY = 0;
  1568. width = image.width;
  1569. height = image.height;
  1570. }
  1571. else {
  1572. if (width == void 0) {
  1573. width = image.width;
  1574. }
  1575. if (height == void 0) {
  1576. height = image.height;
  1577. }
  1578. if (surfaceOffsetX == void 0) {
  1579. surfaceOffsetX = 0;
  1580. }
  1581. if (surfaceOffsetY == void 0) {
  1582. surfaceOffsetY = 0;
  1583. }
  1584. if (surfaceImageWidth == void 0) {
  1585. surfaceImageWidth = width;
  1586. }
  1587. if (surfaceImageHeight == void 0) {
  1588. surfaceImageHeight = height;
  1589. }
  1590. }
  1591. //console.log("drawImage::" + offsetX + " " + offsetY + " " + width + " " + height + " " + surfaceOffsetX + " " + surfaceOffsetY + " " + surfaceImageWidth + " " + surfaceImageHeight);
  1592. this.checkSurface();
  1593. this.$nativeContext.drawImage(bitmapData, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight);
  1594. };
  1595. /**
  1596. * @private
  1597. * 基于指定的源图象(BitmapData)创建一个模板,通过repetition参数指定源图像在什么方向上进行重复,返回一个GraphicsPattern对象。
  1598. * @param bitmapData 做为重复图像源的 BitmapData 对象。
  1599. * @param repetition 指定如何重复图像。
  1600. * 可能的值有:"repeat" (两个方向重复),"repeat-x" (仅水平方向重复),"repeat-y" (仅垂直方向重复),"no-repeat" (不重复).
  1601. * @version Egret 2.4
  1602. * @platform Web,Native
  1603. */
  1604. OldNativeRenderTextureRenderContext.prototype.createPattern = function (image, repetition) {
  1605. return null;
  1606. };
  1607. /**
  1608. * @private
  1609. * 返回一个 ImageData 对象,用来描述canvas区域隐含的像素数据,这个区域通过矩形表示,起始点为(sx, sy)、宽为sw、高为sh。
  1610. * @version Egret 2.4
  1611. * @platform Web,Native
  1612. */
  1613. OldNativeRenderTextureRenderContext.prototype.getImageData = function (sx, sy, sw, sh) {
  1614. var res;
  1615. if (native.$currentSurface == this.surface) {
  1616. if (native.$currentSurface != null) {
  1617. native.$currentSurface.end();
  1618. }
  1619. }
  1620. res = this.surface.getImageData(sx, sy, sw, sh);
  1621. if (res.pixelData) {
  1622. res.data = res.pixelData;
  1623. }
  1624. return res;
  1625. };
  1626. OldNativeRenderTextureRenderContext.prototype.checkSurface = function () {
  1627. //todo 暂时先写这里
  1628. if (native.$currentSurface != this.surface) {
  1629. if (native.$currentSurface != null) {
  1630. native.$currentSurface.end();
  1631. }
  1632. if (this.surface) {
  1633. this.surface.begin();
  1634. }
  1635. }
  1636. };
  1637. return OldNativeRenderTextureRenderContext;
  1638. }(egret.HashObject));
  1639. native.OldNativeRenderTextureRenderContext = OldNativeRenderTextureRenderContext;
  1640. __reflect(OldNativeRenderTextureRenderContext.prototype, "egret.native.OldNativeRenderTextureRenderContext");
  1641. })(native = egret.native || (egret.native = {}));
  1642. })(egret || (egret = {}));
  1643. //////////////////////////////////////////////////////////////////////////////////////
  1644. //
  1645. // Copyright (c) 2014-present, Egret Technology.
  1646. // All rights reserved.
  1647. // Redistribution and use in source and binary forms, with or without
  1648. // modification, are permitted provided that the following conditions are met:
  1649. //
  1650. // * Redistributions of source code must retain the above copyright
  1651. // notice, this list of conditions and the following disclaimer.
  1652. // * Redistributions in binary form must reproduce the above copyright
  1653. // notice, this list of conditions and the following disclaimer in the
  1654. // documentation and/or other materials provided with the distribution.
  1655. // * Neither the name of the Egret nor the
  1656. // names of its contributors may be used to endorse or promote products
  1657. // derived from this software without specific prior written permission.
  1658. //
  1659. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1660. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1661. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1662. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1663. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1664. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1665. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1666. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1667. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1668. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1669. //
  1670. //////////////////////////////////////////////////////////////////////////////////////
  1671. var egret;
  1672. (function (egret) {
  1673. var native;
  1674. (function (native) {
  1675. /**
  1676. * @private
  1677. * 呈现最终绘图结果的画布
  1678. */
  1679. var NativeRenderTexture = (function (_super) {
  1680. __extends(NativeRenderTexture, _super);
  1681. /**
  1682. * @private
  1683. */
  1684. function NativeRenderTexture() {
  1685. var _this = _super.call(this) || this;
  1686. _this.$widthReadySet = false;
  1687. _this.$heightReadySet = false;
  1688. _this.$isRoot = false;
  1689. _this.$isDispose = false;
  1690. _this.renderContext = native.$supportCmdBatch ? new native.NativeRenderTextureRenderContext() : new native.OldNativeRenderTextureRenderContext();
  1691. return _this;
  1692. }
  1693. NativeRenderTexture.prototype.toDataURL = function (type) {
  1694. var args = [];
  1695. for (var _i = 1; _i < arguments.length; _i++) {
  1696. args[_i - 1] = arguments[_i];
  1697. }
  1698. if (this.$nativeRenderTexture) {
  1699. return this.$nativeRenderTexture.toDataURL.apply(this.$nativeRenderTexture, arguments);
  1700. }
  1701. return null;
  1702. };
  1703. NativeRenderTexture.prototype.saveToFile = function (type, filePath) {
  1704. if (this.$nativeRenderTexture && this.$nativeRenderTexture.saveToFile) {
  1705. this.$nativeRenderTexture.saveToFile(type, filePath);
  1706. }
  1707. };
  1708. Object.defineProperty(NativeRenderTexture.prototype, "width", {
  1709. /**
  1710. * @private
  1711. * @inheritDoc
  1712. */
  1713. get: function () {
  1714. return this.$width;
  1715. },
  1716. set: function (value) {
  1717. if (this.$width == value) {
  1718. return;
  1719. }
  1720. this.$width = value;
  1721. if (!this.$isDispose) {
  1722. this.$widthReadySet = true;
  1723. this.createRenderTexture();
  1724. }
  1725. },
  1726. enumerable: true,
  1727. configurable: true
  1728. });
  1729. Object.defineProperty(NativeRenderTexture.prototype, "height", {
  1730. /**
  1731. * @private
  1732. * @inheritDoc
  1733. */
  1734. get: function () {
  1735. return this.$height;
  1736. },
  1737. set: function (value) {
  1738. if (this.$height == value) {
  1739. return;
  1740. }
  1741. this.$height = value;
  1742. if (!this.$isDispose) {
  1743. this.$heightReadySet = true;
  1744. this.createRenderTexture();
  1745. }
  1746. },
  1747. enumerable: true,
  1748. configurable: true
  1749. });
  1750. NativeRenderTexture.prototype.getImageData = function (sx, sy, sw, sh) {
  1751. if (sx != Math.floor(sx)) {
  1752. sx = Math.floor(sx);
  1753. sw++;
  1754. }
  1755. if (sy != Math.floor(sy)) {
  1756. sy = Math.floor(sy);
  1757. sh++;
  1758. }
  1759. return this.$nativeRenderTexture.getPixels(sx, sy, sw, sh);
  1760. };
  1761. NativeRenderTexture.prototype.createRenderTexture = function () {
  1762. if (this.$isRoot) {
  1763. return;
  1764. }
  1765. if (this.$nativeRenderTexture || (this.$widthReadySet && this.$heightReadySet)) {
  1766. if (this.$nativeRenderTexture) {
  1767. this.$nativeRenderTexture.dispose();
  1768. }
  1769. //console.log("new RenderTexture" + this.id);
  1770. this.$nativeRenderTexture = new egret_native.RenderTexture(this.$width, this.$height);
  1771. this.renderContext.globalAlpha = 1;
  1772. this.renderContext.globalCompositeOperation = "source-over";
  1773. this.renderContext.setTransform(1, 0, 0, 1, 0, 0);
  1774. this.$widthReadySet = false;
  1775. this.$heightReadySet = false;
  1776. }
  1777. };
  1778. NativeRenderTexture.prototype.begin = function () {
  1779. if (this.$nativeRenderTexture) {
  1780. //console.log("begin" + this.id);
  1781. native.$currentSurface = this;
  1782. if (this.$nativeRenderTexture.getIn) {
  1783. this.$nativeRenderTexture.getIn();
  1784. }
  1785. else {
  1786. this.$nativeRenderTexture.begin();
  1787. }
  1788. }
  1789. };
  1790. NativeRenderTexture.prototype.end = function () {
  1791. if (this.$nativeRenderTexture) {
  1792. //console.log("end" + this.id);
  1793. native.$currentSurface = null;
  1794. if (this.$nativeRenderTexture.getOut) {
  1795. this.$nativeRenderTexture.getOut();
  1796. }
  1797. else {
  1798. this.$nativeRenderTexture.end();
  1799. }
  1800. }
  1801. };
  1802. NativeRenderTexture.prototype.getContext = function (type) {
  1803. return this.renderContext;
  1804. };
  1805. return NativeRenderTexture;
  1806. }(egret.HashObject));
  1807. native.NativeRenderTexture = NativeRenderTexture;
  1808. __reflect(NativeRenderTexture.prototype, "egret.native.NativeRenderTexture");
  1809. })(native = egret.native || (egret.native = {}));
  1810. })(egret || (egret = {}));
  1811. //////////////////////////////////////////////////////////////////////////////////////
  1812. //
  1813. // Copyright (c) 2014-present, Egret Technology.
  1814. // All rights reserved.
  1815. // Redistribution and use in source and binary forms, with or without
  1816. // modification, are permitted provided that the following conditions are met:
  1817. //
  1818. // * Redistributions of source code must retain the above copyright
  1819. // notice, this list of conditions and the following disclaimer.
  1820. // * Redistributions in binary form must reproduce the above copyright
  1821. // notice, this list of conditions and the following disclaimer in the
  1822. // documentation and/or other materials provided with the distribution.
  1823. // * Neither the name of the Egret nor the
  1824. // names of its contributors may be used to endorse or promote products
  1825. // derived from this software without specific prior written permission.
  1826. //
  1827. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1828. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1829. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1830. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1831. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1832. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1833. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1834. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1835. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1836. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1837. //
  1838. //////////////////////////////////////////////////////////////////////////////////////
  1839. var egret;
  1840. (function (egret) {
  1841. var native;
  1842. (function (native) {
  1843. /**
  1844. * 创建一个RenderTexture。
  1845. */
  1846. function createRenderTexture(width, height) {
  1847. var result = new native.NativeRenderTexture();
  1848. if (!isNaN(width) && !isNaN(height)) {
  1849. result.width = width;
  1850. result.height = height;
  1851. }
  1852. return result;
  1853. }
  1854. var sharedRenderTexture;
  1855. /**
  1856. * @private
  1857. * NativeRenderTexture渲染器
  1858. */
  1859. var NativeRenderTextureRenderBuffer = (function () {
  1860. function NativeRenderTextureRenderBuffer(width, height) {
  1861. this.surface = createRenderTexture(width, height);
  1862. this.context = this.surface.getContext("2d");
  1863. }
  1864. Object.defineProperty(NativeRenderTextureRenderBuffer.prototype, "width", {
  1865. /**
  1866. * 渲染缓冲的宽度,以像素为单位。
  1867. * @readOnly
  1868. */
  1869. get: function () {
  1870. return this.surface.width;
  1871. },
  1872. enumerable: true,
  1873. configurable: true
  1874. });
  1875. Object.defineProperty(NativeRenderTextureRenderBuffer.prototype, "height", {
  1876. /**
  1877. * 渲染缓冲的高度,以像素为单位。
  1878. * @readOnly
  1879. */
  1880. get: function () {
  1881. return this.surface.height;
  1882. },
  1883. enumerable: true,
  1884. configurable: true
  1885. });
  1886. /**
  1887. * 改变渲染缓冲的大小并清空缓冲区
  1888. * @param width 改变后的宽
  1889. * @param height 改变后的高
  1890. * @param useMaxSize 若传入true,则将改变后的尺寸与已有尺寸对比,保留较大的尺寸。
  1891. */
  1892. NativeRenderTextureRenderBuffer.prototype.resize = function (width, height, useMaxSize) {
  1893. var surface = this.surface;
  1894. if (useMaxSize) {
  1895. if (surface.width < width) {
  1896. surface.width = width;
  1897. }
  1898. if (surface.height < height) {
  1899. surface.height = height;
  1900. }
  1901. }
  1902. else {
  1903. if (surface.width != width) {
  1904. surface.width = width;
  1905. }
  1906. if (surface.height != height) {
  1907. surface.height = height;
  1908. }
  1909. }
  1910. this.clear();
  1911. };
  1912. /**
  1913. * 改变渲染缓冲为指定大小,但保留原始图像数据
  1914. * @param width 改变后的宽
  1915. * @param height 改变后的高
  1916. * @param offsetX 原始图像数据在改变后缓冲区的绘制起始位置x
  1917. * @param offsetY 原始图像数据在改变后缓冲区的绘制起始位置y
  1918. */
  1919. NativeRenderTextureRenderBuffer.prototype.resizeTo = function (width, height, offsetX, offsetY) {
  1920. if (!sharedRenderTexture) {
  1921. sharedRenderTexture = createRenderTexture();
  1922. }
  1923. var oldContext = this.context;
  1924. var oldSurface = this.surface;
  1925. var newSurface = sharedRenderTexture;
  1926. var newContext = newSurface.getContext("2d");
  1927. sharedRenderTexture = oldSurface;
  1928. this.context = newContext;
  1929. this.surface = newSurface;
  1930. newSurface.width = Math.max(width, 1);
  1931. newSurface.height = Math.max(height, 1);
  1932. newContext.setTransform(1, 0, 0, 1, 0, 0);
  1933. newContext.drawImage(oldSurface, offsetX, offsetY);
  1934. oldSurface.height = 1;
  1935. oldSurface.width = 1;
  1936. };
  1937. NativeRenderTextureRenderBuffer.prototype.setDirtyRegionPolicy = function (state) {
  1938. };
  1939. /**
  1940. * 清空并设置裁切
  1941. * @param regions 矩形列表
  1942. * @param offsetX 矩形要加上的偏移量x
  1943. * @param offsetY 矩形要加上的偏移量y
  1944. */
  1945. NativeRenderTextureRenderBuffer.prototype.beginClip = function (regions, offsetX, offsetY) {
  1946. offsetX = +offsetX || 0;
  1947. offsetY = +offsetY || 0;
  1948. var context = this.context;
  1949. context.save();
  1950. context.beginPath();
  1951. context.setTransform(1, 0, 0, 1, offsetX, offsetY);
  1952. var length = regions.length;
  1953. for (var i = 0; i < length; i++) {
  1954. var region = regions[i];
  1955. context.clearRect(region.minX, region.minY, region.width, region.height);
  1956. context.rect(region.minX, region.minY, region.width, region.height);
  1957. }
  1958. context.clip();
  1959. };
  1960. /**
  1961. * 取消上一次设置的clip。
  1962. */
  1963. NativeRenderTextureRenderBuffer.prototype.endClip = function () {
  1964. this.context.restore();
  1965. };
  1966. /**
  1967. * 获取指定区域的像素
  1968. */
  1969. NativeRenderTextureRenderBuffer.prototype.getPixels = function (x, y, width, height) {
  1970. if (width === void 0) { width = 1; }
  1971. if (height === void 0) { height = 1; }
  1972. return this.context.getImageData(x, y, width, height).data;
  1973. };
  1974. /**
  1975. * 转换成base64字符串,如果图片(或者包含的图片)跨域,则返回null
  1976. * @param type 转换的类型,如: "image/png","image/jpeg"
  1977. */
  1978. NativeRenderTextureRenderBuffer.prototype.toDataURL = function (type, encoderOptions) {
  1979. return this.surface.toDataURL(type, encoderOptions);
  1980. };
  1981. /**
  1982. * 清空缓冲区数据
  1983. */
  1984. NativeRenderTextureRenderBuffer.prototype.clear = function () {
  1985. var width = this.surface.width;
  1986. var height = this.surface.height;
  1987. if (width > 0 && height > 0) {
  1988. this.context.setTransform(1, 0, 0, 1, 0, 0);
  1989. this.context.clearRect(0, 0, width, height);
  1990. }
  1991. };
  1992. /**
  1993. * 销毁绘制对象
  1994. */
  1995. NativeRenderTextureRenderBuffer.prototype.destroy = function () {
  1996. this.surface.width = this.surface.height = 1;
  1997. };
  1998. return NativeRenderTextureRenderBuffer;
  1999. }());
  2000. native.NativeRenderTextureRenderBuffer = NativeRenderTextureRenderBuffer;
  2001. __reflect(NativeRenderTextureRenderBuffer.prototype, "egret.native.NativeRenderTextureRenderBuffer", ["egret.sys.RenderBuffer"]);
  2002. })(native = egret.native || (egret.native = {}));
  2003. })(egret || (egret = {}));
  2004. //////////////////////////////////////////////////////////////////////////////////////
  2005. //
  2006. // Copyright (c) 2014-present, Egret Technology.
  2007. // All rights reserved.
  2008. // Redistribution and use in source and binary forms, with or without
  2009. // modification, are permitted provided that the following conditions are met:
  2010. //
  2011. // * Redistributions of source code must retain the above copyright
  2012. // notice, this list of conditions and the following disclaimer.
  2013. // * Redistributions in binary form must reproduce the above copyright
  2014. // notice, this list of conditions and the following disclaimer in the
  2015. // documentation and/or other materials provided with the distribution.
  2016. // * Neither the name of the Egret nor the
  2017. // names of its contributors may be used to endorse or promote products
  2018. // derived from this software without specific prior written permission.
  2019. //
  2020. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2021. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2022. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2023. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2024. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2025. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2026. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2027. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2028. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2029. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2030. //
  2031. //////////////////////////////////////////////////////////////////////////////////////
  2032. var egret;
  2033. (function (egret) {
  2034. var native;
  2035. (function (native) {
  2036. var blendModesForGL = {
  2037. "source-over": [1, 771],
  2038. "lighter": [770, 1],
  2039. "destination-out": [0, 771],
  2040. "destination-in": [0, 770]
  2041. };
  2042. /**
  2043. * @version Egret 2.4
  2044. * @platform Web,Native
  2045. * @private
  2046. */
  2047. var NativeCanvasRenderContext = (function (_super) {
  2048. __extends(NativeCanvasRenderContext, _super);
  2049. function NativeCanvasRenderContext() {
  2050. var _this = _super.apply(this, arguments) || this;
  2051. _this.$matrix = new egret.Matrix();
  2052. _this.$nativeContext = null;
  2053. _this.$globalCompositeOperation = "source-over";
  2054. _this.$globalAlpha = 1;
  2055. _this.$lineWidth = 0;
  2056. _this.$strokeStyle = "#000000";
  2057. _this.$fillStyle = "#000000";
  2058. _this.$font = "normal normal 10px sans-serif";
  2059. _this.$fontSize = 10;
  2060. _this.$fontFamily = "";
  2061. _this.clipRectArray = null;
  2062. _this.$saveList = [];
  2063. _this.$clipRectArray = [];
  2064. _this.$clipRect = new egret.Rectangle();
  2065. _this.$saveCount = 0;
  2066. _this.$clipList = [];
  2067. _this.savedMatrix = new egret.Matrix();
  2068. _this.$hasStrokeText = false;
  2069. return _this;
  2070. }
  2071. Object.defineProperty(NativeCanvasRenderContext.prototype, "globalCompositeOperation", {
  2072. /**
  2073. * @private
  2074. * 设置新图像如何绘制到已有的图像上的规制
  2075. * @version Egret 2.4
  2076. * @platform Web,Native
  2077. */
  2078. get: function () {
  2079. return this.$globalCompositeOperation;
  2080. },
  2081. set: function (value) {
  2082. this.$globalCompositeOperation = value;
  2083. var arr = blendModesForGL[value];
  2084. if (arr) {
  2085. native.$cmdManager.setContext(this.$nativeContext);
  2086. native.$cmdManager.setBlendArg(arr[0], arr[1]);
  2087. }
  2088. },
  2089. enumerable: true,
  2090. configurable: true
  2091. });
  2092. Object.defineProperty(NativeCanvasRenderContext.prototype, "globalAlpha", {
  2093. /**
  2094. * @private
  2095. * 设置接下来绘图填充的整体透明度
  2096. * @version Egret 2.4
  2097. * @platform Web,Native
  2098. */
  2099. get: function () {
  2100. return this.$globalAlpha;
  2101. },
  2102. set: function (value) {
  2103. this.$globalAlpha = value;
  2104. native.$cmdManager.setContext(this.$nativeContext);
  2105. native.$cmdManager.setGlobalAlpha(value);
  2106. },
  2107. enumerable: true,
  2108. configurable: true
  2109. });
  2110. Object.defineProperty(NativeCanvasRenderContext.prototype, "lineWidth", {
  2111. /**
  2112. * @private
  2113. * 设置线条粗细,以像素为单位。设置为0,负数,Infinity 或 NaN 将会被忽略。
  2114. * @default 1
  2115. * @version Egret 2.4
  2116. * @platform Web,Native
  2117. */
  2118. get: function () {
  2119. return this.$lineWidth;
  2120. },
  2121. set: function (value) {
  2122. //console.log("set lineWidth" + value);
  2123. this.$lineWidth = value;
  2124. native.$cmdManager.setContext(this.$nativeContext);
  2125. native.$cmdManager.setLineWidth(value);
  2126. },
  2127. enumerable: true,
  2128. configurable: true
  2129. });
  2130. Object.defineProperty(NativeCanvasRenderContext.prototype, "strokeStyle", {
  2131. /**
  2132. * @private
  2133. * 设置要在图形边线填充的颜色或样式
  2134. * @default "#000000"
  2135. * @version Egret 2.4
  2136. * @platform Web,Native
  2137. */
  2138. get: function () {
  2139. return this.$strokeStyle;
  2140. },
  2141. set: function (value) {
  2142. this.$strokeStyle = value;
  2143. if (value != null) {
  2144. if (value.indexOf("rgba") != -1) {
  2145. value = this.$parseRGBA(value);
  2146. }
  2147. else if (value.indexOf("rgb") != -1) {
  2148. value = this.$parseRGB(value);
  2149. }
  2150. native.$cmdManager.setContext(egret_native.Label);
  2151. native.$cmdManager.setStrokeColor(parseInt(value.replace("#", "0x")));
  2152. }
  2153. native.$cmdManager.setContext(this.$nativeContext);
  2154. var s1 = native.$cmdManager.pushString(value);
  2155. native.$cmdManager.setStrokeStyle(s1);
  2156. },
  2157. enumerable: true,
  2158. configurable: true
  2159. });
  2160. Object.defineProperty(NativeCanvasRenderContext.prototype, "fillStyle", {
  2161. /**
  2162. * @private
  2163. * 设置要在图形内部填充的颜色或样式
  2164. * @default "#000000"
  2165. * @version Egret 2.4
  2166. * @platform Web,Native
  2167. */
  2168. get: function () {
  2169. return this.$fillStyle;
  2170. },
  2171. set: function (value) {
  2172. this.$fillStyle = value;
  2173. if (value != null) {
  2174. if (value.indexOf("rgba") != -1) {
  2175. value = this.$parseRGBA(value);
  2176. }
  2177. else if (value.indexOf("rgb") != -1) {
  2178. value = this.$parseRGB(value);
  2179. }
  2180. native.$cmdManager.setContext(egret_native.Label);
  2181. native.$cmdManager.setTextColor(parseInt(value.replace("#", "0x")));
  2182. }
  2183. native.$cmdManager.setContext(this.$nativeContext);
  2184. var s1 = native.$cmdManager.pushString(value);
  2185. native.$cmdManager.setFillStyle(s1);
  2186. },
  2187. enumerable: true,
  2188. configurable: true
  2189. });
  2190. NativeCanvasRenderContext.prototype.$fillColorStr = function (s) {
  2191. if (s.length < 2) {
  2192. s = "0" + s;
  2193. }
  2194. return s;
  2195. };
  2196. NativeCanvasRenderContext.prototype.$parseRGBA = function (str) {
  2197. var index = str.indexOf("(");
  2198. str = str.slice(index + 1, str.length - 1);
  2199. var arr = str.split(",");
  2200. var a = parseInt((parseFloat(arr[3]) * 255)).toString(16);
  2201. var r = parseInt(arr[0]).toString(16);
  2202. var g = parseInt(arr[1]).toString(16);
  2203. var b = parseInt(arr[2]).toString(16);
  2204. str = "#" + this.$fillColorStr(a) + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
  2205. return str;
  2206. };
  2207. NativeCanvasRenderContext.prototype.$parseRGB = function (str) {
  2208. var index = str.indexOf("(");
  2209. str = str.slice(index + 1, str.length - 1);
  2210. var arr = str.split(",");
  2211. var r = parseInt(arr[0]).toString(16);
  2212. var g = parseInt(arr[1]).toString(16);
  2213. var b = parseInt(arr[2]).toString(16);
  2214. str = "#" + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
  2215. return str;
  2216. };
  2217. Object.defineProperty(NativeCanvasRenderContext.prototype, "font", {
  2218. /**
  2219. * @private
  2220. * 当前的字体样式
  2221. * @version Egret 2.4
  2222. * @platform Web,Native
  2223. */
  2224. get: function () {
  2225. return this.$font;
  2226. },
  2227. set: function (value) {
  2228. this.$font = value;
  2229. var arr = value.split(" ");
  2230. var sizeTxt = arr[2];
  2231. if (sizeTxt.indexOf("px") != -1) {
  2232. this.$fontSize = parseInt(sizeTxt.replace("px", ""));
  2233. }
  2234. if (egret.useFontMapping) {
  2235. var fontFamilyText = void 0;
  2236. if (arr.length == 4) {
  2237. fontFamilyText = arr[3];
  2238. }
  2239. else {
  2240. fontFamilyText = arr.slice(3).join(" ");
  2241. }
  2242. if (fontFamilyText.indexOf(", ") != -1) {
  2243. arr = fontFamilyText.split(", ");
  2244. }
  2245. else if (fontFamilyText.indexOf(",") != -1) {
  2246. arr = fontFamilyText.split(",");
  2247. var length_6 = arr.length;
  2248. for (var i = 0; i < length_6; i++) {
  2249. var fontFamily = arr[i];
  2250. //暂时先不考虑带有引号的情况
  2251. if (egret.fontMapping[fontFamily]) {
  2252. this.$fontFamily = egret.fontMapping[fontFamily];
  2253. return;
  2254. }
  2255. }
  2256. }
  2257. else {
  2258. this.$fontFamily = egret.fontMapping[fontFamilyText];
  2259. }
  2260. if (!this.$fontFamily) {
  2261. this.$fontFamily = "/system/fonts/DroidSansFallback.ttf";
  2262. }
  2263. }
  2264. else {
  2265. //兼容旧版本直接将 default_fontFamily 设置为字体路径的情况
  2266. this.$fontFamily = egret.TextField.default_fontFamily;
  2267. }
  2268. },
  2269. enumerable: true,
  2270. configurable: true
  2271. });
  2272. /**
  2273. * @private
  2274. * 绘制一段圆弧路径。圆弧路径的圆心在 (x, y) 位置,半径为 r ,根据anticlockwise (默认为顺时针)指定的方向从 startAngle 开始绘制,到 endAngle 结束。
  2275. * @param x 圆弧中心(圆心)的 x 轴坐标。
  2276. * @param y 圆弧中心(圆心)的 y 轴坐标。
  2277. * @param radius 圆弧的半径。
  2278. * @param startAngle 圆弧的起始点, x轴方向开始计算,单位以弧度表示。
  2279. * @param endAngle 圆弧的重点, 单位以弧度表示。
  2280. * @param anticlockwise 如果为 true,逆时针绘制圆弧,反之,顺时针绘制。
  2281. * @version Egret 2.4
  2282. * @platform Web,Native
  2283. */
  2284. NativeCanvasRenderContext.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
  2285. native.$cmdManager.setContext(this.$nativeContext);
  2286. native.$cmdManager.arc(x, y, radius, startAngle, endAngle, anticlockwise ? 1 : 0);
  2287. // this.$nativeContext.arc(x, y, radius, startAngle, endAngle, anticlockwise);
  2288. };
  2289. /**
  2290. * @private
  2291. * 绘制一段二次贝塞尔曲线路径。它需要2个点。 第一个点是控制点,第二个点是终点。 起始点是当前路径最新的点,当创建二次贝赛尔曲线之前,可以使用 moveTo() 方法进行改变。
  2292. * @param cpx 控制点的 x 轴坐标。
  2293. * @param cpy 控制点的 y 轴坐标。
  2294. * @param x 终点的 x 轴坐标。
  2295. * @param y 终点的 y 轴坐标。
  2296. * @version Egret 2.4
  2297. * @platform Web,Native
  2298. */
  2299. NativeCanvasRenderContext.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
  2300. //console.log("quadraticCurveTo " + cpx + " " + cpy + " " + x + " " + y);
  2301. native.$cmdManager.setContext(this.$nativeContext);
  2302. native.$cmdManager.quadraticCurveTo(cpx, cpy, x, y);
  2303. // this.$nativeContext.quadraticCurveTo(cpx, cpy, x, y);
  2304. };
  2305. /**
  2306. * @private
  2307. * 使用直线连接子路径的终点到x,y坐标。
  2308. * @param x 直线终点的 x 轴坐标。
  2309. * @param y 直线终点的 y 轴坐标。
  2310. * @version Egret 2.4
  2311. * @platform Web,Native
  2312. */
  2313. NativeCanvasRenderContext.prototype.lineTo = function (x, y) {
  2314. //console.log("lineTo " + x + " " + y);
  2315. native.$cmdManager.setContext(this.$nativeContext);
  2316. native.$cmdManager.lineTo(x, y);
  2317. };
  2318. /**
  2319. * @private
  2320. * 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
  2321. * @param fillRule 一种算法,决定点是在路径内还是在路径外。允许的值:
  2322. * "nonzero": 非零环绕规则, 默认的规则。
  2323. * "evenodd": 奇偶环绕规则。
  2324. * @version Egret 2.4
  2325. * @platform Web,Native
  2326. */
  2327. NativeCanvasRenderContext.prototype.fill = function (fillRule) {
  2328. native.$cmdManager.setContext(this.$nativeContext);
  2329. var s1 = native.$cmdManager.pushString(fillRule);
  2330. native.$cmdManager.fill(s1);
  2331. };
  2332. /**
  2333. * @private
  2334. * 使笔点返回到当前子路径的起始点。它尝试从当前点到起始点绘制一条直线。如果图形已经是封闭的或者只有一个点,那么此方法不会做任何操作。
  2335. * @version Egret 2.4
  2336. * @platform Web,Native
  2337. */
  2338. NativeCanvasRenderContext.prototype.closePath = function () {
  2339. native.$cmdManager.setContext(this.$nativeContext);
  2340. native.$cmdManager.closePath();
  2341. if (this.clipRectArray) {
  2342. this.$clipRectArray = this.clipRectArray;
  2343. this.clipRectArray = null;
  2344. }
  2345. };
  2346. /**
  2347. * @private
  2348. * 创建一段矩形路径,矩形的起点位置是 (x, y) ,尺寸为 width 和 height。矩形的4个点通过直线连接,子路径做为闭合的标记,所以你可以填充或者描边矩形。
  2349. * @param x 矩形起点的 x 轴坐标。
  2350. * @param y 矩形起点的 y 轴坐标。
  2351. * @param width 矩形的宽度。
  2352. * @param height 矩形的高度。
  2353. * @version Egret 2.4
  2354. * @platform Web,Native
  2355. */
  2356. NativeCanvasRenderContext.prototype.rect = function (x, y, w, h) {
  2357. native.$cmdManager.setContext(this.$nativeContext);
  2358. native.$cmdManager.rect(x, y, w, h);
  2359. this.$clipRectArray.push({ x: x, y: y, w: w, h: h });
  2360. };
  2361. /**
  2362. * @private
  2363. * 将一个新的子路径的起始点移动到(x,y)坐标
  2364. * @param x 点的 x 轴
  2365. * @param y 点的 y 轴
  2366. * @version Egret 2.4
  2367. * @platform Web,Native
  2368. */
  2369. NativeCanvasRenderContext.prototype.moveTo = function (x, y) {
  2370. native.$cmdManager.setContext(this.$nativeContext);
  2371. native.$cmdManager.moveTo(x, y);
  2372. };
  2373. /**
  2374. * @private
  2375. * 绘制一个填充矩形。矩形的起点在 (x, y) 位置,矩形的尺寸是 width 和 height ,fillStyle 属性决定矩形的样式。
  2376. * @param x 矩形起始点的 x 轴坐标。
  2377. * @param y 矩形起始点的 y 轴坐标。
  2378. * @param width 矩形的宽度。
  2379. * @param height 矩形的高度。
  2380. * @version Egret 2.4
  2381. * @platform Web,Native
  2382. */
  2383. NativeCanvasRenderContext.prototype.fillRect = function (x, y, w, h) {
  2384. native.$cmdManager.setContext(this.$nativeContext);
  2385. native.$cmdManager.fillRect(x, y, w, h);
  2386. // this.$nativeContext.fillRect(x, y, w, h);
  2387. };
  2388. /**
  2389. * @private
  2390. * 绘制一段三次贝赛尔曲线路径。该方法需要三个点。 第一、第二个点是控制点,第三个点是结束点。起始点是当前路径的最后一个点,
  2391. * 绘制贝赛尔曲线前,可以通过调用 moveTo() 进行修改。
  2392. * @param cp1x 第一个控制点的 x 轴坐标。
  2393. * @param cp1y 第一个控制点的 y 轴坐标。
  2394. * @param cp2x 第二个控制点的 x 轴坐标。
  2395. * @param cp2y 第二个控制点的 y 轴坐标。
  2396. * @param x 结束点的 x 轴坐标。
  2397. * @param y 结束点的 y 轴坐标。
  2398. * @version Egret 2.4
  2399. * @platform Web,Native
  2400. */
  2401. NativeCanvasRenderContext.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  2402. native.$cmdManager.setContext(this.$nativeContext);
  2403. native.$cmdManager.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  2404. // this.$nativeContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  2405. };
  2406. /**
  2407. * @private
  2408. * 根据当前的画线样式,绘制当前或已经存在的路径的方法。
  2409. * @version Egret 2.4
  2410. * @platform Web,Native
  2411. */
  2412. NativeCanvasRenderContext.prototype.stroke = function () {
  2413. native.$cmdManager.setContext(this.$nativeContext);
  2414. native.$cmdManager.stroke();
  2415. // this.$nativeContext.stroke();
  2416. };
  2417. /**
  2418. * @private
  2419. * 使用当前的绘画样式,描绘一个起点在 (x, y) 、宽度为 w 、高度为 h 的矩形的方法。
  2420. * @param x 矩形起点的 x 轴坐标。
  2421. * @param y 矩形起点的 y 轴坐标。
  2422. * @param w 矩形的宽度。
  2423. * @param h 矩形的高度。
  2424. * @version Egret 2.4
  2425. * @platform Web,Native
  2426. */
  2427. NativeCanvasRenderContext.prototype.strokeRect = function (x, y, w, h) {
  2428. //console.log("strokeRect");
  2429. native.$cmdManager.setContext(this.$nativeContext);
  2430. native.$cmdManager.strokeRect(x, y, w, h);
  2431. // this.$nativeContext.strokeRect(x, y, w, h);
  2432. };
  2433. /**
  2434. * @private
  2435. * 清空子路径列表开始一个新路径。 当你想创建一个新的路径时,调用此方法。
  2436. * @version Egret 2.4
  2437. * @platform Web,Native
  2438. */
  2439. NativeCanvasRenderContext.prototype.beginPath = function () {
  2440. native.$cmdManager.setContext(this.$nativeContext);
  2441. native.$cmdManager.beginPath();
  2442. this.clipRectArray = this.$clipRectArray.concat();
  2443. };
  2444. /**
  2445. * @private
  2446. * 根据控制点和半径绘制一段圆弧路径,使用直线连接前一个点。
  2447. * @param x1 第一个控制点的 x 轴坐标。
  2448. * @param y1 第一个控制点的 y 轴坐标。
  2449. * @param x2 第二个控制点的 x 轴坐标。
  2450. * @param y2 第二个控制点的 y 轴坐标。
  2451. * @param radius 圆弧的半径。
  2452. * @version Egret 2.4
  2453. * @platform Web,Native
  2454. */
  2455. NativeCanvasRenderContext.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  2456. this.$nativeContext.arcTo(x1, y1, x2, y2, radius);
  2457. };
  2458. /**
  2459. * @private
  2460. * 使用方法参数描述的矩阵多次叠加当前的变换矩阵。
  2461. * @param a 水平缩放。
  2462. * @param b 水平倾斜。
  2463. * @param c 垂直倾斜。
  2464. * @param d 垂直缩放。
  2465. * @param tx 水平移动。
  2466. * @param ty 垂直移动。
  2467. * @version Egret 2.4
  2468. * @platform Web,Native
  2469. */
  2470. NativeCanvasRenderContext.prototype.transform = function (a, b, c, d, tx, ty) {
  2471. this.$matrix.append(a, b, c, d, tx, ty);
  2472. this.setTransformToNative();
  2473. };
  2474. /**
  2475. * @private
  2476. * 通过在网格中移动 surface 和 surface 原点 x 水平方向、原点 y 垂直方向,添加平移变换
  2477. * @param x 水平移动。
  2478. * @param y 垂直移动。
  2479. * @version Egret 2.4
  2480. * @platform Web,Native
  2481. */
  2482. NativeCanvasRenderContext.prototype.translate = function (x, y) {
  2483. this.$matrix.translate(x, y);
  2484. this.setTransformToNative();
  2485. };
  2486. /**
  2487. * @private
  2488. * 根据 x 水平方向和 y 垂直方向,为 surface 单位添加缩放变换。
  2489. * @param x 水平方向的缩放因子。
  2490. * @param y 垂直方向的缩放因子。
  2491. * @version Egret 2.4
  2492. * @platform Web,Native
  2493. */
  2494. NativeCanvasRenderContext.prototype.scale = function (x, y) {
  2495. this.$matrix.scale(x, y);
  2496. this.setTransformToNative();
  2497. };
  2498. /**
  2499. * @private
  2500. * 在变换矩阵中增加旋转,角度变量表示一个顺时针旋转角度并且用弧度表示。
  2501. * @param angle 顺时针旋转的弧度。
  2502. * @version Egret 2.4
  2503. * @platform Web,Native
  2504. */
  2505. NativeCanvasRenderContext.prototype.rotate = function (angle) {
  2506. this.$matrix.rotate(angle);
  2507. this.setTransformToNative();
  2508. };
  2509. /**
  2510. * @private
  2511. * 恢复到最近的绘制样式状态,此状态是通过 save() 保存到”状态栈“中最新的元素。
  2512. * @version Egret 2.4
  2513. * @platform Web,Native
  2514. */
  2515. NativeCanvasRenderContext.prototype.restore = function () {
  2516. //console.log("restore");
  2517. if (this.$saveList.length) {
  2518. var data = this.$saveList.pop();
  2519. for (var key in data) {
  2520. this[key] = data[key];
  2521. }
  2522. this.setTransformToNative();
  2523. native.$cmdManager.setContext(this.$nativeContext);
  2524. native.$cmdManager.restore();
  2525. this.clipRectArray = null;
  2526. }
  2527. };
  2528. /**
  2529. * @private
  2530. * 使用栈保存当前的绘画样式状态,你可以使用 restore() 恢复任何改变。
  2531. * @version Egret 2.4
  2532. * @platform Web,Native
  2533. */
  2534. NativeCanvasRenderContext.prototype.save = function () {
  2535. //console.log("save");
  2536. var transformMatrix = new egret.Matrix();
  2537. transformMatrix.copyFrom(this.$matrix);
  2538. this.$saveList.push({
  2539. lineWidth: this.$lineWidth,
  2540. globalCompositeOperation: this.$globalCompositeOperation,
  2541. globalAlpha: this.$globalAlpha,
  2542. strokeStyle: this.$strokeStyle,
  2543. fillStyle: this.$fillStyle,
  2544. font: this.$font,
  2545. $matrix: transformMatrix,
  2546. $clipRectArray: this.$clipRectArray.concat()
  2547. });
  2548. native.$cmdManager.setContext(this.$nativeContext);
  2549. native.$cmdManager.save();
  2550. };
  2551. /**
  2552. * @private
  2553. * 从当前路径创建一个剪切路径。在 clip() 调用之后,绘制的所有信息只会出现在剪切路径内部。
  2554. * @version Egret 2.4
  2555. * @platform Web,Native
  2556. */
  2557. NativeCanvasRenderContext.prototype.clip = function (fillRule) {
  2558. if (this.$clipRectArray.length > 0) {
  2559. var arr = [];
  2560. for (var i = 0; i < this.$clipRectArray.length; i++) {
  2561. var clipRect = this.$clipRectArray[i];
  2562. arr.push(clipRect.x);
  2563. arr.push(clipRect.y);
  2564. arr.push(clipRect.w);
  2565. arr.push(clipRect.h);
  2566. }
  2567. //console.log("pushRectStencils " + arr.toString());
  2568. native.$cmdManager.setContext(this.$nativeContext);
  2569. native.$cmdManager.pushRectStencils(arr);
  2570. this.$clipRectArray.length = 0;
  2571. }
  2572. };
  2573. /**
  2574. * @private
  2575. * 设置指定矩形区域内(以 点 (x, y) 为起点,范围是(width, height) )所有像素变成透明,并擦除之前绘制的所有内容。
  2576. * @param x 矩形起点的 x 轴坐标。
  2577. * @param y 矩形起点的 y 轴坐标。
  2578. * @param width 矩形的宽度。
  2579. * @param height 矩形的高度。
  2580. * @version Egret 2.4
  2581. * @platform Web,Native
  2582. */
  2583. NativeCanvasRenderContext.prototype.clearRect = function (x, y, width, height) {
  2584. //console.log("clearRect x:" + x + " y:" + y + " width:" + width + " height:" + height);
  2585. native.$cmdManager.setContext(this.$nativeContext);
  2586. native.$cmdManager.clearRect(x, y, width, height);
  2587. };
  2588. /**
  2589. * @private
  2590. * 重新设置当前的变换为单位矩阵,并使用同样的变量调用 transform() 方法。
  2591. * @param a 水平缩放。
  2592. * @param b 水平倾斜。
  2593. * @param c 垂直倾斜。
  2594. * @param d 垂直缩放。
  2595. * @param tx 水平移动。
  2596. * @param ty 垂直移动。
  2597. * @version Egret 2.4
  2598. * @platform Web,Native
  2599. */
  2600. NativeCanvasRenderContext.prototype.setTransform = function (a, b, c, d, tx, ty) {
  2601. this.$matrix.setTo(a, b, c, d, tx, ty);
  2602. this.setTransformToNative();
  2603. };
  2604. NativeCanvasRenderContext.prototype.setTransformToNative = function () {
  2605. var m = this.$matrix;
  2606. //console.log("setTransformToNative::a=" + m.a + " b=" + m.b + " c=" + m.c + " d=" + m.d + " tx=" + m.tx + " ty=" + m.ty);
  2607. native.$cmdManager.setContext(this.$nativeContext);
  2608. native.$cmdManager.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
  2609. };
  2610. /**
  2611. * @private
  2612. * 保存矩阵,这里只能保存一次,嵌套无效
  2613. */
  2614. NativeCanvasRenderContext.prototype.saveTransform = function () {
  2615. this.savedMatrix.copyFrom(this.$matrix);
  2616. };
  2617. /**
  2618. * @private
  2619. * 保存矩阵,这里只能保存一次,嵌套无效
  2620. */
  2621. NativeCanvasRenderContext.prototype.restoreTransform = function () {
  2622. this.$matrix.copyFrom(this.savedMatrix);
  2623. };
  2624. /**
  2625. * @private
  2626. * 创建一个沿参数坐标指定的直线的渐变。该方法返回一个线性的 GraphicsGradient 对象。
  2627. * @param x0 起点的 x 轴坐标。
  2628. * @param y0 起点的 y 轴坐标。
  2629. * @param x1 终点的 x 轴坐标。
  2630. * @param y1 终点的 y 轴坐标。
  2631. * @version Egret 2.4
  2632. * @platform Web,Native
  2633. */
  2634. NativeCanvasRenderContext.prototype.createLinearGradient = function (x0, y0, x1, y1) {
  2635. return this.$nativeContext.createLinearGradient(x0, y0, x1, y1);
  2636. };
  2637. /**
  2638. * @private
  2639. * 根据参数确定的两个圆的坐标,创建一个放射性渐变。该方法返回一个放射性的 GraphicsGradient。
  2640. * @param x0 开始圆形的 x 轴坐标。
  2641. * @param y0 开始圆形的 y 轴坐标。
  2642. * @param r0 开始圆形的半径。
  2643. * @param x1 结束圆形的 x 轴坐标。
  2644. * @param y1 结束圆形的 y 轴坐标。
  2645. * @param r1 结束圆形的半径。
  2646. * @version Egret 2.4
  2647. * @platform Web,Native
  2648. */
  2649. NativeCanvasRenderContext.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) {
  2650. return this.$nativeContext.createRadialGradient(x0, y0, r0, x1, y1, r1);
  2651. };
  2652. /**
  2653. * @private
  2654. * 在(x,y)位置绘制(填充)文本。
  2655. * @version Egret 2.4
  2656. * @platform Web,Native
  2657. */
  2658. NativeCanvasRenderContext.prototype.fillText = function (text, x, y, maxWidth) {
  2659. //console.log("drawText" + text);
  2660. native.$cmdManager.setContext(this.$nativeContext);
  2661. var s1 = native.$cmdManager.pushString(this.$fontFamily);
  2662. var s2 = native.$cmdManager.pushString("");
  2663. native.$cmdManager.createLabel(s1, this.$fontSize, s2, this.$hasStrokeText ? this.$lineWidth : 0);
  2664. this.$hasStrokeText = false;
  2665. var s3 = native.$cmdManager.pushString(text);
  2666. native.$cmdManager.drawText(s3, x, y);
  2667. };
  2668. NativeCanvasRenderContext.prototype.strokeText = function (text, x, y, maxWidth) {
  2669. this.$hasStrokeText = true;
  2670. };
  2671. /**
  2672. * @private
  2673. * 测量指定文本宽度,返回 TextMetrics 对象。
  2674. * @version Egret 2.4
  2675. * @platform Web,Native
  2676. */
  2677. NativeCanvasRenderContext.prototype.measureText = function (text) {
  2678. native.$cmdManager.setContext(egret_native.Label);
  2679. var s1 = native.$cmdManager.pushString(this.$fontFamily);
  2680. var s2 = native.$cmdManager.pushString("");
  2681. native.$cmdManager.createLabel(s1, this.$fontSize, s2, this.$hasStrokeText ? this.$lineWidth : 0);
  2682. //同步更新
  2683. native.$cmdManager.flush();
  2684. return { width: egret_native.Label.getTextSize(text)[0] };
  2685. };
  2686. /**
  2687. * @private
  2688. * 注意:如果要对绘制的图片进行缩放,出于性能优化考虑,系统不会主动去每次重置imageSmoothingEnabled属性,因此您在调用drawImage()方法前请务必
  2689. * 确保 imageSmoothingEnabled 已被重置为正常的值,否则有可能沿用上个显示对象绘制过程留下的值。
  2690. * @version Egret 2.4
  2691. * @platform Web,Native
  2692. */
  2693. NativeCanvasRenderContext.prototype.drawImage = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight) {
  2694. var bitmapData;
  2695. var isNative;
  2696. if (image.$nativeCanvas) {
  2697. bitmapData = image.$nativeCanvas;
  2698. isNative = true;
  2699. }
  2700. else {
  2701. bitmapData = image;
  2702. isNative = false;
  2703. }
  2704. if (!bitmapData) {
  2705. return;
  2706. }
  2707. if (arguments.length == 3) {
  2708. surfaceOffsetX = offsetX;
  2709. surfaceOffsetY = offsetY;
  2710. offsetX = 0;
  2711. offsetY = 0;
  2712. width = surfaceImageWidth = image.width;
  2713. height = surfaceImageHeight = image.height;
  2714. }
  2715. else if (arguments.length == 5) {
  2716. surfaceOffsetX = offsetX;
  2717. surfaceOffsetY = offsetY;
  2718. surfaceImageWidth = width;
  2719. surfaceImageHeight = height;
  2720. offsetX = 0;
  2721. offsetY = 0;
  2722. width = image.width;
  2723. height = image.height;
  2724. }
  2725. else {
  2726. if (width == void 0) {
  2727. width = image.width;
  2728. }
  2729. if (height == void 0) {
  2730. height = image.height;
  2731. }
  2732. if (surfaceOffsetX == void 0) {
  2733. surfaceOffsetX = 0;
  2734. }
  2735. if (surfaceOffsetY == void 0) {
  2736. surfaceOffsetY = 0;
  2737. }
  2738. if (surfaceImageWidth == void 0) {
  2739. surfaceImageWidth = width;
  2740. }
  2741. if (surfaceImageHeight == void 0) {
  2742. surfaceImageHeight = height;
  2743. }
  2744. }
  2745. //console.log("drawImage::" + offsetX + " " + offsetY + " " + width + " " + height + " " + surfaceOffsetX + " " + surfaceOffsetY + " " + surfaceImageWidth + " " + surfaceImageHeight);
  2746. //console.log("drawImage::" + bitmapData);
  2747. var imageAdress;
  2748. if (!isNative) {
  2749. if (!bitmapData._native_tex_loc) {
  2750. bitmapData._native_tex_loc = bitmapData.___native_texture__p;
  2751. }
  2752. imageAdress = bitmapData._native_tex_loc;
  2753. }
  2754. else {
  2755. imageAdress = bitmapData.___native_texture__p;
  2756. }
  2757. native.$cmdManager.setContext(this.$nativeContext);
  2758. native.$cmdManager.drawImage(imageAdress, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight);
  2759. };
  2760. /**
  2761. * @private
  2762. * draw mesh
  2763. */
  2764. NativeCanvasRenderContext.prototype.drawMesh = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices) {
  2765. var bitmapData;
  2766. if (image.$nativeCanvas) {
  2767. bitmapData = image.$nativeCanvas;
  2768. }
  2769. else {
  2770. bitmapData = image;
  2771. }
  2772. if (!bitmapData) {
  2773. return;
  2774. }
  2775. if (arguments.length == 3) {
  2776. surfaceOffsetX = offsetX;
  2777. surfaceOffsetY = offsetY;
  2778. offsetX = 0;
  2779. offsetY = 0;
  2780. width = surfaceImageWidth = image.width;
  2781. height = surfaceImageHeight = image.height;
  2782. }
  2783. else if (arguments.length == 5) {
  2784. surfaceOffsetX = offsetX;
  2785. surfaceOffsetY = offsetY;
  2786. surfaceImageWidth = width;
  2787. surfaceImageHeight = height;
  2788. offsetX = 0;
  2789. offsetY = 0;
  2790. width = image.width;
  2791. height = image.height;
  2792. }
  2793. else {
  2794. if (!width) {
  2795. width = image.width;
  2796. }
  2797. if (!height) {
  2798. height = image.height;
  2799. }
  2800. if (!surfaceOffsetX) {
  2801. surfaceOffsetX = 0;
  2802. }
  2803. if (!surfaceOffsetY) {
  2804. surfaceOffsetY = 0;
  2805. }
  2806. if (!surfaceImageWidth) {
  2807. surfaceImageWidth = width;
  2808. }
  2809. if (!surfaceImageHeight) {
  2810. surfaceImageHeight = height;
  2811. }
  2812. }
  2813. this.vertices = new Float32Array(meshVertices.length / 2 * 5);
  2814. this.indicesForMesh = new Uint32Array(meshIndices.length);
  2815. this.cacheArrays(this.$matrix, 1, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices);
  2816. // 打断批渲染
  2817. native.$cmdManager.flush();
  2818. this.$nativeContext.drawMesh(bitmapData, this.vertices, this.indicesForMesh, this.vertices.length, this.indicesForMesh.length);
  2819. };
  2820. NativeCanvasRenderContext.prototype.cacheArrays = function (transform, alpha, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices) {
  2821. //计算出绘制矩阵,之后把矩阵还原回之前的
  2822. var locWorldTransform = transform;
  2823. var originalA = locWorldTransform.a;
  2824. var originalB = locWorldTransform.b;
  2825. var originalC = locWorldTransform.c;
  2826. var originalD = locWorldTransform.d;
  2827. var originalTx = locWorldTransform.tx;
  2828. var originalTy = locWorldTransform.ty;
  2829. if (destX != 0 || destY != 0) {
  2830. locWorldTransform.append(1, 0, 0, 1, destX, destY);
  2831. }
  2832. if (sourceWidth / destWidth != 1 || sourceHeight / destHeight != 1) {
  2833. locWorldTransform.append(destWidth / sourceWidth, 0, 0, destHeight / sourceHeight, 0, 0);
  2834. }
  2835. var a = locWorldTransform.a;
  2836. var b = locWorldTransform.b;
  2837. var c = locWorldTransform.c;
  2838. var d = locWorldTransform.d;
  2839. var tx = locWorldTransform.tx;
  2840. var ty = locWorldTransform.ty;
  2841. locWorldTransform.a = originalA;
  2842. locWorldTransform.b = originalB;
  2843. locWorldTransform.c = originalC;
  2844. locWorldTransform.d = originalD;
  2845. locWorldTransform.tx = originalTx;
  2846. locWorldTransform.ty = originalTy;
  2847. if (meshVertices) {
  2848. // 计算索引位置与赋值
  2849. var vertices = this.vertices;
  2850. // 缓存顶点数组
  2851. var i = 0, iD = 0, l = 0;
  2852. var u = 0, v = 0, x = 0, y = 0;
  2853. for (i = 0, l = meshUVs.length; i < l; i += 2) {
  2854. iD = i * 5 / 2;
  2855. x = meshVertices[i];
  2856. y = meshVertices[i + 1];
  2857. u = meshUVs[i];
  2858. v = meshUVs[i + 1];
  2859. // xy
  2860. vertices[iD + 0] = a * x + c * y + tx;
  2861. vertices[iD + 1] = b * x + d * y + ty;
  2862. // uv
  2863. vertices[iD + 2] = (sourceX + u * sourceWidth) / textureSourceWidth;
  2864. vertices[iD + 3] = (sourceY + v * sourceHeight) / textureSourceHeight;
  2865. // alpha
  2866. vertices[iD + 4] = alpha;
  2867. }
  2868. for (i = 0; i < meshIndices.length; i++) {
  2869. this.indicesForMesh[i] = meshIndices[i];
  2870. }
  2871. }
  2872. else {
  2873. console.log("meshVertices not exist");
  2874. }
  2875. };
  2876. /**
  2877. * @private
  2878. * 基于指定的源图象(BitmapData)创建一个模板,通过repetition参数指定源图像在什么方向上进行重复,返回一个GraphicsPattern对象。
  2879. * @param bitmapData 做为重复图像源的 BitmapData 对象。
  2880. * @param repetition 指定如何重复图像。
  2881. * 可能的值有:"repeat" (两个方向重复),"repeat-x" (仅水平方向重复),"repeat-y" (仅垂直方向重复),"no-repeat" (不重复).
  2882. * @version Egret 2.4
  2883. * @platform Web,Native
  2884. */
  2885. NativeCanvasRenderContext.prototype.createPattern = function (image, repetition) {
  2886. return null;
  2887. };
  2888. /**
  2889. * @private
  2890. * 返回一个 ImageData 对象,用来描述canvas区域隐含的像素数据,这个区域通过矩形表示,起始点为(sx, sy)、宽为sw、高为sh。
  2891. * @version Egret 2.4
  2892. * @platform Web,Native
  2893. */
  2894. NativeCanvasRenderContext.prototype.getImageData = function (sx, sy, sw, sh) {
  2895. native.$cmdManager.flush();
  2896. var res;
  2897. if (sx != Math.floor(sx)) {
  2898. sx = Math.floor(sx);
  2899. sw++;
  2900. }
  2901. if (sy != Math.floor(sy)) {
  2902. sy = Math.floor(sy);
  2903. sh++;
  2904. }
  2905. res = this.$nativeContext.getPixels(sx, sy, sw, sh);
  2906. if (res.pixelData) {
  2907. res.data = res.pixelData;
  2908. }
  2909. return res;
  2910. };
  2911. /**
  2912. * @private
  2913. * 设置全局shader
  2914. * @param filter filter属性生成的json
  2915. */
  2916. NativeCanvasRenderContext.prototype.setGlobalShader = function (filter) {
  2917. native.$cmdManager.setContext(this.$nativeContext);
  2918. var s1;
  2919. if (filter) {
  2920. s1 = native.$cmdManager.pushString(filter.$toJson());
  2921. }
  2922. else {
  2923. s1 = native.$cmdManager.pushString("");
  2924. }
  2925. native.$cmdManager.setGlobalShader(s1);
  2926. };
  2927. return NativeCanvasRenderContext;
  2928. }(egret.HashObject));
  2929. native.NativeCanvasRenderContext = NativeCanvasRenderContext;
  2930. __reflect(NativeCanvasRenderContext.prototype, "egret.native.NativeCanvasRenderContext");
  2931. })(native = egret.native || (egret.native = {}));
  2932. })(egret || (egret = {}));
  2933. //////////////////////////////////////////////////////////////////////////////////////
  2934. //
  2935. // Copyright (c) 2014-present, Egret Technology.
  2936. // All rights reserved.
  2937. // Redistribution and use in source and binary forms, with or without
  2938. // modification, are permitted provided that the following conditions are met:
  2939. //
  2940. // * Redistributions of source code must retain the above copyright
  2941. // notice, this list of conditions and the following disclaimer.
  2942. // * Redistributions in binary form must reproduce the above copyright
  2943. // notice, this list of conditions and the following disclaimer in the
  2944. // documentation and/or other materials provided with the distribution.
  2945. // * Neither the name of the Egret nor the
  2946. // names of its contributors may be used to endorse or promote products
  2947. // derived from this software without specific prior written permission.
  2948. //
  2949. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2950. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2951. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2952. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2953. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2954. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2955. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2956. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2957. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2958. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2959. //
  2960. //////////////////////////////////////////////////////////////////////////////////////
  2961. var egret;
  2962. (function (egret) {
  2963. var native;
  2964. (function (native) {
  2965. var blendModesForGL = {
  2966. "source-over": [1, 771],
  2967. "lighter": [770, 1],
  2968. "destination-out": [0, 771],
  2969. "destination-in": [0, 770]
  2970. };
  2971. /**
  2972. * @version Egret 2.4
  2973. * @platform Web,Native
  2974. * @private
  2975. */
  2976. var OldNativeCanvasRenderContext = (function (_super) {
  2977. __extends(OldNativeCanvasRenderContext, _super);
  2978. function OldNativeCanvasRenderContext() {
  2979. var _this = _super.apply(this, arguments) || this;
  2980. _this.$matrix = new egret.Matrix();
  2981. _this.$nativeContext = null;
  2982. _this.$globalCompositeOperation = "source-over";
  2983. _this.$globalAlpha = 1;
  2984. _this.$lineWidth = 0;
  2985. _this.$strokeStyle = "#000000";
  2986. _this.$fillStyle = "#000000";
  2987. _this.$font = "normal normal 10px sans-serif";
  2988. _this.$fontSize = 10;
  2989. _this.$fontFamily = "";
  2990. _this.clipRectArray = null;
  2991. _this.$saveList = [];
  2992. _this.$clipRectArray = [];
  2993. _this.$clipRect = new egret.Rectangle();
  2994. _this.$saveCount = 0;
  2995. _this.$clipList = [];
  2996. _this.savedMatrix = new egret.Matrix();
  2997. _this.$hasStrokeText = false;
  2998. return _this;
  2999. }
  3000. Object.defineProperty(OldNativeCanvasRenderContext.prototype, "globalCompositeOperation", {
  3001. /**
  3002. * @private
  3003. * 设置新图像如何绘制到已有的图像上的规制
  3004. * @version Egret 2.4
  3005. * @platform Web,Native
  3006. */
  3007. get: function () {
  3008. return this.$globalCompositeOperation;
  3009. },
  3010. set: function (value) {
  3011. this.$globalCompositeOperation = value;
  3012. var arr = blendModesForGL[value];
  3013. if (arr) {
  3014. this.$nativeContext.setBlendArg(arr[0], arr[1]);
  3015. }
  3016. },
  3017. enumerable: true,
  3018. configurable: true
  3019. });
  3020. Object.defineProperty(OldNativeCanvasRenderContext.prototype, "globalAlpha", {
  3021. /**
  3022. * @private
  3023. * 设置接下来绘图填充的整体透明度
  3024. * @version Egret 2.4
  3025. * @platform Web,Native
  3026. */
  3027. get: function () {
  3028. return this.$globalAlpha;
  3029. },
  3030. set: function (value) {
  3031. this.$globalAlpha = value;
  3032. this.$nativeContext.setGlobalAlpha(value);
  3033. },
  3034. enumerable: true,
  3035. configurable: true
  3036. });
  3037. Object.defineProperty(OldNativeCanvasRenderContext.prototype, "lineWidth", {
  3038. /**
  3039. * @private
  3040. * 设置线条粗细,以像素为单位。设置为0,负数,Infinity 或 NaN 将会被忽略。
  3041. * @default 1
  3042. * @version Egret 2.4
  3043. * @platform Web,Native
  3044. */
  3045. get: function () {
  3046. return this.$lineWidth;
  3047. },
  3048. set: function (value) {
  3049. //console.log("set lineWidth" + value);
  3050. this.$lineWidth = value;
  3051. this.$nativeContext.lineWidth = value;
  3052. },
  3053. enumerable: true,
  3054. configurable: true
  3055. });
  3056. Object.defineProperty(OldNativeCanvasRenderContext.prototype, "strokeStyle", {
  3057. /**
  3058. * @private
  3059. * 设置要在图形边线填充的颜色或样式
  3060. * @default "#000000"
  3061. * @version Egret 2.4
  3062. * @platform Web,Native
  3063. */
  3064. get: function () {
  3065. return this.$strokeStyle;
  3066. },
  3067. set: function (value) {
  3068. this.$strokeStyle = value;
  3069. if (value != null) {
  3070. if (value.indexOf("rgba") != -1) {
  3071. value = this.$parseRGBA(value);
  3072. }
  3073. else if (value.indexOf("rgb") != -1) {
  3074. value = this.$parseRGB(value);
  3075. }
  3076. egret_native.Label.setStrokeColor(parseInt(value.replace("#", "0x")));
  3077. }
  3078. this.$nativeContext.strokeStyle = value;
  3079. },
  3080. enumerable: true,
  3081. configurable: true
  3082. });
  3083. Object.defineProperty(OldNativeCanvasRenderContext.prototype, "fillStyle", {
  3084. /**
  3085. * @private
  3086. * 设置要在图形内部填充的颜色或样式
  3087. * @default "#000000"
  3088. * @version Egret 2.4
  3089. * @platform Web,Native
  3090. */
  3091. get: function () {
  3092. return this.$fillStyle;
  3093. },
  3094. set: function (value) {
  3095. this.$fillStyle = value;
  3096. if (value != null) {
  3097. if (value.indexOf("rgba") != -1) {
  3098. value = this.$parseRGBA(value);
  3099. }
  3100. else if (value.indexOf("rgb") != -1) {
  3101. value = this.$parseRGB(value);
  3102. }
  3103. egret_native.Label.setTextColor(parseInt(value.replace("#", "0x")));
  3104. }
  3105. this.$nativeContext.fillStyle = value;
  3106. },
  3107. enumerable: true,
  3108. configurable: true
  3109. });
  3110. OldNativeCanvasRenderContext.prototype.$fillColorStr = function (s) {
  3111. if (s.length < 2) {
  3112. s = "0" + s;
  3113. }
  3114. return s;
  3115. };
  3116. OldNativeCanvasRenderContext.prototype.$parseRGBA = function (str) {
  3117. var index = str.indexOf("(");
  3118. str = str.slice(index + 1, str.length - 1);
  3119. var arr = str.split(",");
  3120. var a = parseInt((parseFloat(arr[3]) * 255)).toString(16);
  3121. var r = parseInt(arr[0]).toString(16);
  3122. var g = parseInt(arr[1]).toString(16);
  3123. var b = parseInt(arr[2]).toString(16);
  3124. str = "#" + this.$fillColorStr(a) + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
  3125. return str;
  3126. };
  3127. OldNativeCanvasRenderContext.prototype.$parseRGB = function (str) {
  3128. var index = str.indexOf("(");
  3129. str = str.slice(index + 1, str.length - 1);
  3130. var arr = str.split(",");
  3131. var r = parseInt(arr[0]).toString(16);
  3132. var g = parseInt(arr[1]).toString(16);
  3133. var b = parseInt(arr[2]).toString(16);
  3134. str = "#" + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
  3135. return str;
  3136. };
  3137. Object.defineProperty(OldNativeCanvasRenderContext.prototype, "font", {
  3138. /**
  3139. * @private
  3140. * 当前的字体样式
  3141. * @version Egret 2.4
  3142. * @platform Web,Native
  3143. */
  3144. get: function () {
  3145. return this.$font;
  3146. },
  3147. set: function (value) {
  3148. this.$font = value;
  3149. var arr = value.split(" ");
  3150. var sizeTxt = arr[2];
  3151. if (sizeTxt.indexOf("px") != -1) {
  3152. this.$fontSize = parseInt(sizeTxt.replace("px", ""));
  3153. }
  3154. if (egret.useFontMapping) {
  3155. var fontFamilyText = void 0;
  3156. if (arr.length == 4) {
  3157. fontFamilyText = arr[3];
  3158. }
  3159. else {
  3160. fontFamilyText = arr.slice(3).join(" ");
  3161. }
  3162. if (fontFamilyText.indexOf(", ") != -1) {
  3163. arr = fontFamilyText.split(", ");
  3164. }
  3165. else if (fontFamilyText.indexOf(",") != -1) {
  3166. arr = fontFamilyText.split(",");
  3167. var length_7 = arr.length;
  3168. for (var i = 0; i < length_7; i++) {
  3169. var fontFamily = arr[i];
  3170. //暂时先不考虑带有引号的情况
  3171. if (egret.fontMapping[fontFamily]) {
  3172. this.$fontFamily = egret.fontMapping[fontFamily];
  3173. return;
  3174. }
  3175. }
  3176. }
  3177. else {
  3178. this.$fontFamily = egret.fontMapping[fontFamilyText];
  3179. }
  3180. if (!this.$fontFamily) {
  3181. this.$fontFamily = "/system/fonts/DroidSansFallback.ttf";
  3182. }
  3183. }
  3184. else {
  3185. //兼容旧版本直接将 default_fontFamily 设置为字体路径的情况
  3186. this.$fontFamily = egret.TextField.default_fontFamily;
  3187. }
  3188. },
  3189. enumerable: true,
  3190. configurable: true
  3191. });
  3192. /**
  3193. * @private
  3194. * 绘制一段圆弧路径。圆弧路径的圆心在 (x, y) 位置,半径为 r ,根据anticlockwise (默认为顺时针)指定的方向从 startAngle 开始绘制,到 endAngle 结束。
  3195. * @param x 圆弧中心(圆心)的 x 轴坐标。
  3196. * @param y 圆弧中心(圆心)的 y 轴坐标。
  3197. * @param radius 圆弧的半径。
  3198. * @param startAngle 圆弧的起始点, x轴方向开始计算,单位以弧度表示。
  3199. * @param endAngle 圆弧的重点, 单位以弧度表示。
  3200. * @param anticlockwise 如果为 true,逆时针绘制圆弧,反之,顺时针绘制。
  3201. * @version Egret 2.4
  3202. * @platform Web,Native
  3203. */
  3204. OldNativeCanvasRenderContext.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
  3205. this.$nativeContext.arc(x, y, radius, startAngle, endAngle, anticlockwise);
  3206. };
  3207. /**
  3208. * @private
  3209. * 绘制一段二次贝塞尔曲线路径。它需要2个点。 第一个点是控制点,第二个点是终点。 起始点是当前路径最新的点,当创建二次贝赛尔曲线之前,可以使用 moveTo() 方法进行改变。
  3210. * @param cpx 控制点的 x 轴坐标。
  3211. * @param cpy 控制点的 y 轴坐标。
  3212. * @param x 终点的 x 轴坐标。
  3213. * @param y 终点的 y 轴坐标。
  3214. * @version Egret 2.4
  3215. * @platform Web,Native
  3216. */
  3217. OldNativeCanvasRenderContext.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
  3218. //console.log("quadraticCurveTo " + cpx + " " + cpy + " " + x + " " + y);
  3219. this.$nativeContext.quadraticCurveTo(cpx, cpy, x, y);
  3220. };
  3221. /**
  3222. * @private
  3223. * 使用直线连接子路径的终点到x,y坐标。
  3224. * @param x 直线终点的 x 轴坐标。
  3225. * @param y 直线终点的 y 轴坐标。
  3226. * @version Egret 2.4
  3227. * @platform Web,Native
  3228. */
  3229. OldNativeCanvasRenderContext.prototype.lineTo = function (x, y) {
  3230. //console.log("lineTo " + x + " " + y);
  3231. this.$nativeContext.lineTo(x, y);
  3232. };
  3233. /**
  3234. * @private
  3235. * 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
  3236. * @param fillRule 一种算法,决定点是在路径内还是在路径外。允许的值:
  3237. * "nonzero": 非零环绕规则, 默认的规则。
  3238. * "evenodd": 奇偶环绕规则。
  3239. * @version Egret 2.4
  3240. * @platform Web,Native
  3241. */
  3242. OldNativeCanvasRenderContext.prototype.fill = function (fillRule) {
  3243. this.$nativeContext.fill(fillRule);
  3244. };
  3245. /**
  3246. * @private
  3247. * 使笔点返回到当前子路径的起始点。它尝试从当前点到起始点绘制一条直线。如果图形已经是封闭的或者只有一个点,那么此方法不会做任何操作。
  3248. * @version Egret 2.4
  3249. * @platform Web,Native
  3250. */
  3251. OldNativeCanvasRenderContext.prototype.closePath = function () {
  3252. this.$nativeContext.closePath();
  3253. if (this.clipRectArray) {
  3254. this.$clipRectArray = this.clipRectArray;
  3255. this.clipRectArray = null;
  3256. }
  3257. };
  3258. /**
  3259. * @private
  3260. * 创建一段矩形路径,矩形的起点位置是 (x, y) ,尺寸为 width 和 height。矩形的4个点通过直线连接,子路径做为闭合的标记,所以你可以填充或者描边矩形。
  3261. * @param x 矩形起点的 x 轴坐标。
  3262. * @param y 矩形起点的 y 轴坐标。
  3263. * @param width 矩形的宽度。
  3264. * @param height 矩形的高度。
  3265. * @version Egret 2.4
  3266. * @platform Web,Native
  3267. */
  3268. OldNativeCanvasRenderContext.prototype.rect = function (x, y, w, h) {
  3269. this.$nativeContext.rect(x, y, w, h);
  3270. this.$clipRectArray.push({ x: x, y: y, w: w, h: h });
  3271. };
  3272. /**
  3273. * @private
  3274. * 将一个新的子路径的起始点移动到(x,y)坐标
  3275. * @param x 点的 x 轴
  3276. * @param y 点的 y 轴
  3277. * @version Egret 2.4
  3278. * @platform Web,Native
  3279. */
  3280. OldNativeCanvasRenderContext.prototype.moveTo = function (x, y) {
  3281. this.$nativeContext.moveTo(x, y);
  3282. };
  3283. /**
  3284. * @private
  3285. * 绘制一个填充矩形。矩形的起点在 (x, y) 位置,矩形的尺寸是 width 和 height ,fillStyle 属性决定矩形的样式。
  3286. * @param x 矩形起始点的 x 轴坐标。
  3287. * @param y 矩形起始点的 y 轴坐标。
  3288. * @param width 矩形的宽度。
  3289. * @param height 矩形的高度。
  3290. * @version Egret 2.4
  3291. * @platform Web,Native
  3292. */
  3293. OldNativeCanvasRenderContext.prototype.fillRect = function (x, y, w, h) {
  3294. this.$nativeContext.fillRect(x, y, w, h);
  3295. };
  3296. /**
  3297. * @private
  3298. * 绘制一段三次贝赛尔曲线路径。该方法需要三个点。 第一、第二个点是控制点,第三个点是结束点。起始点是当前路径的最后一个点,
  3299. * 绘制贝赛尔曲线前,可以通过调用 moveTo() 进行修改。
  3300. * @param cp1x 第一个控制点的 x 轴坐标。
  3301. * @param cp1y 第一个控制点的 y 轴坐标。
  3302. * @param cp2x 第二个控制点的 x 轴坐标。
  3303. * @param cp2y 第二个控制点的 y 轴坐标。
  3304. * @param x 结束点的 x 轴坐标。
  3305. * @param y 结束点的 y 轴坐标。
  3306. * @version Egret 2.4
  3307. * @platform Web,Native
  3308. */
  3309. OldNativeCanvasRenderContext.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  3310. this.$nativeContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  3311. };
  3312. /**
  3313. * @private
  3314. * 根据当前的画线样式,绘制当前或已经存在的路径的方法。
  3315. * @version Egret 2.4
  3316. * @platform Web,Native
  3317. */
  3318. OldNativeCanvasRenderContext.prototype.stroke = function () {
  3319. this.$nativeContext.stroke();
  3320. };
  3321. /**
  3322. * @private
  3323. * 使用当前的绘画样式,描绘一个起点在 (x, y) 、宽度为 w 、高度为 h 的矩形的方法。
  3324. * @param x 矩形起点的 x 轴坐标。
  3325. * @param y 矩形起点的 y 轴坐标。
  3326. * @param w 矩形的宽度。
  3327. * @param h 矩形的高度。
  3328. * @version Egret 2.4
  3329. * @platform Web,Native
  3330. */
  3331. OldNativeCanvasRenderContext.prototype.strokeRect = function (x, y, w, h) {
  3332. //console.log("strokeRect");
  3333. this.$nativeContext.strokeRect(x, y, w, h);
  3334. };
  3335. /**
  3336. * @private
  3337. * 清空子路径列表开始一个新路径。 当你想创建一个新的路径时,调用此方法。
  3338. * @version Egret 2.4
  3339. * @platform Web,Native
  3340. */
  3341. OldNativeCanvasRenderContext.prototype.beginPath = function () {
  3342. this.$nativeContext.beginPath();
  3343. this.clipRectArray = this.$clipRectArray.concat();
  3344. };
  3345. /**
  3346. * @private
  3347. * 根据控制点和半径绘制一段圆弧路径,使用直线连接前一个点。
  3348. * @param x1 第一个控制点的 x 轴坐标。
  3349. * @param y1 第一个控制点的 y 轴坐标。
  3350. * @param x2 第二个控制点的 x 轴坐标。
  3351. * @param y2 第二个控制点的 y 轴坐标。
  3352. * @param radius 圆弧的半径。
  3353. * @version Egret 2.4
  3354. * @platform Web,Native
  3355. */
  3356. OldNativeCanvasRenderContext.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  3357. this.$nativeContext.arcTo(x1, y1, x2, y2, radius);
  3358. };
  3359. /**
  3360. * @private
  3361. * 使用方法参数描述的矩阵多次叠加当前的变换矩阵。
  3362. * @param a 水平缩放。
  3363. * @param b 水平倾斜。
  3364. * @param c 垂直倾斜。
  3365. * @param d 垂直缩放。
  3366. * @param tx 水平移动。
  3367. * @param ty 垂直移动。
  3368. * @version Egret 2.4
  3369. * @platform Web,Native
  3370. */
  3371. OldNativeCanvasRenderContext.prototype.transform = function (a, b, c, d, tx, ty) {
  3372. this.$matrix.append(a, b, c, d, tx, ty);
  3373. this.setTransformToNative();
  3374. };
  3375. /**
  3376. * @private
  3377. * 通过在网格中移动 surface 和 surface 原点 x 水平方向、原点 y 垂直方向,添加平移变换
  3378. * @param x 水平移动。
  3379. * @param y 垂直移动。
  3380. * @version Egret 2.4
  3381. * @platform Web,Native
  3382. */
  3383. OldNativeCanvasRenderContext.prototype.translate = function (x, y) {
  3384. this.$matrix.translate(x, y);
  3385. this.setTransformToNative();
  3386. };
  3387. /**
  3388. * @private
  3389. * 根据 x 水平方向和 y 垂直方向,为 surface 单位添加缩放变换。
  3390. * @param x 水平方向的缩放因子。
  3391. * @param y 垂直方向的缩放因子。
  3392. * @version Egret 2.4
  3393. * @platform Web,Native
  3394. */
  3395. OldNativeCanvasRenderContext.prototype.scale = function (x, y) {
  3396. this.$matrix.scale(x, y);
  3397. this.setTransformToNative();
  3398. };
  3399. /**
  3400. * @private
  3401. * 在变换矩阵中增加旋转,角度变量表示一个顺时针旋转角度并且用弧度表示。
  3402. * @param angle 顺时针旋转的弧度。
  3403. * @version Egret 2.4
  3404. * @platform Web,Native
  3405. */
  3406. OldNativeCanvasRenderContext.prototype.rotate = function (angle) {
  3407. this.$matrix.rotate(angle);
  3408. this.setTransformToNative();
  3409. };
  3410. /**
  3411. * @private
  3412. * 恢复到最近的绘制样式状态,此状态是通过 save() 保存到”状态栈“中最新的元素。
  3413. * @version Egret 2.4
  3414. * @platform Web,Native
  3415. */
  3416. OldNativeCanvasRenderContext.prototype.restore = function () {
  3417. //console.log("restore");
  3418. if (this.$saveList.length) {
  3419. var data = this.$saveList.pop();
  3420. for (var key in data) {
  3421. this[key] = data[key];
  3422. }
  3423. this.setTransformToNative();
  3424. this.$nativeContext.restore();
  3425. this.clipRectArray = null;
  3426. }
  3427. };
  3428. /**
  3429. * @private
  3430. * 使用栈保存当前的绘画样式状态,你可以使用 restore() 恢复任何改变。
  3431. * @version Egret 2.4
  3432. * @platform Web,Native
  3433. */
  3434. OldNativeCanvasRenderContext.prototype.save = function () {
  3435. //console.log("save");
  3436. var transformMatrix = new egret.Matrix();
  3437. transformMatrix.copyFrom(this.$matrix);
  3438. this.$saveList.push({
  3439. lineWidth: this.$lineWidth,
  3440. globalCompositeOperation: this.$globalCompositeOperation,
  3441. globalAlpha: this.$globalAlpha,
  3442. strokeStyle: this.$strokeStyle,
  3443. fillStyle: this.$fillStyle,
  3444. font: this.$font,
  3445. $matrix: transformMatrix,
  3446. $clipRectArray: this.$clipRectArray.concat()
  3447. });
  3448. this.$nativeContext.save();
  3449. };
  3450. /**
  3451. * @private
  3452. * 从当前路径创建一个剪切路径。在 clip() 调用之后,绘制的所有信息只会出现在剪切路径内部。
  3453. * @version Egret 2.4
  3454. * @platform Web,Native
  3455. */
  3456. OldNativeCanvasRenderContext.prototype.clip = function (fillRule) {
  3457. if (this.$clipRectArray.length > 0) {
  3458. var arr = [];
  3459. for (var i = 0; i < this.$clipRectArray.length; i++) {
  3460. var clipRect = this.$clipRectArray[i];
  3461. arr.push(clipRect.x);
  3462. arr.push(clipRect.y);
  3463. arr.push(clipRect.w);
  3464. arr.push(clipRect.h);
  3465. }
  3466. //console.log("pushRectStencils " + arr.toString());
  3467. this.$nativeContext.pushRectStencils(arr);
  3468. this.$clipRectArray.length = 0;
  3469. }
  3470. };
  3471. /**
  3472. * @private
  3473. * 设置指定矩形区域内(以 点 (x, y) 为起点,范围是(width, height) )所有像素变成透明,并擦除之前绘制的所有内容。
  3474. * @param x 矩形起点的 x 轴坐标。
  3475. * @param y 矩形起点的 y 轴坐标。
  3476. * @param width 矩形的宽度。
  3477. * @param height 矩形的高度。
  3478. * @version Egret 2.4
  3479. * @platform Web,Native
  3480. */
  3481. OldNativeCanvasRenderContext.prototype.clearRect = function (x, y, width, height) {
  3482. //console.log("clearRect x:" + x + " y:" + y + " width:" + width + " height:" + height);
  3483. this.$nativeContext.clearRect(x, y, width, height);
  3484. };
  3485. /**
  3486. * @private
  3487. * 重新设置当前的变换为单位矩阵,并使用同样的变量调用 transform() 方法。
  3488. * @param a 水平缩放。
  3489. * @param b 水平倾斜。
  3490. * @param c 垂直倾斜。
  3491. * @param d 垂直缩放。
  3492. * @param tx 水平移动。
  3493. * @param ty 垂直移动。
  3494. * @version Egret 2.4
  3495. * @platform Web,Native
  3496. */
  3497. OldNativeCanvasRenderContext.prototype.setTransform = function (a, b, c, d, tx, ty) {
  3498. this.$matrix.setTo(a, b, c, d, tx, ty);
  3499. this.setTransformToNative();
  3500. };
  3501. OldNativeCanvasRenderContext.prototype.setTransformToNative = function () {
  3502. var m = this.$matrix;
  3503. //console.log("setTransformToNative::a=" + m.a + " b=" + m.b + " c=" + m.c + " d=" + m.d + " tx=" + m.tx + " ty=" + m.ty);
  3504. this.$nativeContext.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
  3505. };
  3506. /**
  3507. * @private
  3508. * 保存矩阵,这里只能保存一次,嵌套无效
  3509. */
  3510. OldNativeCanvasRenderContext.prototype.saveTransform = function () {
  3511. this.savedMatrix.copyFrom(this.$matrix);
  3512. };
  3513. /**
  3514. * @private
  3515. * 保存矩阵,这里只能保存一次,嵌套无效
  3516. */
  3517. OldNativeCanvasRenderContext.prototype.restoreTransform = function () {
  3518. this.$matrix.copyFrom(this.savedMatrix);
  3519. };
  3520. /**
  3521. * @private
  3522. * 创建一个沿参数坐标指定的直线的渐变。该方法返回一个线性的 GraphicsGradient 对象。
  3523. * @param x0 起点的 x 轴坐标。
  3524. * @param y0 起点的 y 轴坐标。
  3525. * @param x1 终点的 x 轴坐标。
  3526. * @param y1 终点的 y 轴坐标。
  3527. * @version Egret 2.4
  3528. * @platform Web,Native
  3529. */
  3530. OldNativeCanvasRenderContext.prototype.createLinearGradient = function (x0, y0, x1, y1) {
  3531. return this.$nativeContext.createLinearGradient(x0, y0, x1, y1);
  3532. };
  3533. /**
  3534. * @private
  3535. * 根据参数确定的两个圆的坐标,创建一个放射性渐变。该方法返回一个放射性的 GraphicsGradient。
  3536. * @param x0 开始圆形的 x 轴坐标。
  3537. * @param y0 开始圆形的 y 轴坐标。
  3538. * @param r0 开始圆形的半径。
  3539. * @param x1 结束圆形的 x 轴坐标。
  3540. * @param y1 结束圆形的 y 轴坐标。
  3541. * @param r1 结束圆形的半径。
  3542. * @version Egret 2.4
  3543. * @platform Web,Native
  3544. */
  3545. OldNativeCanvasRenderContext.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) {
  3546. return this.$nativeContext.createRadialGradient(x0, y0, r0, x1, y1, r1);
  3547. };
  3548. /**
  3549. * @private
  3550. * 在(x,y)位置绘制(填充)文本。
  3551. * @version Egret 2.4
  3552. * @platform Web,Native
  3553. */
  3554. OldNativeCanvasRenderContext.prototype.fillText = function (text, x, y, maxWidth) {
  3555. //console.log("drawText" + text);
  3556. this.$nativeContext.createLabel(this.$fontFamily, this.$fontSize, "", this.$hasStrokeText ? this.$lineWidth : 0);
  3557. this.$hasStrokeText = false;
  3558. this.$nativeContext.drawText(text, x, y);
  3559. };
  3560. OldNativeCanvasRenderContext.prototype.strokeText = function (text, x, y, maxWidth) {
  3561. this.$hasStrokeText = true;
  3562. };
  3563. /**
  3564. * @private
  3565. * 测量指定文本宽度,返回 TextMetrics 对象。
  3566. * @version Egret 2.4
  3567. * @platform Web,Native
  3568. */
  3569. OldNativeCanvasRenderContext.prototype.measureText = function (text) {
  3570. egret_native.Label.createLabel(this.$fontFamily, this.$fontSize, "", this.$hasStrokeText ? this.$lineWidth : 0);
  3571. return { width: egret_native.Label.getTextSize(text)[0] };
  3572. };
  3573. /**
  3574. * @private
  3575. * 注意:如果要对绘制的图片进行缩放,出于性能优化考虑,系统不会主动去每次重置imageSmoothingEnabled属性,因此您在调用drawImage()方法前请务必
  3576. * 确保 imageSmoothingEnabled 已被重置为正常的值,否则有可能沿用上个显示对象绘制过程留下的值。
  3577. * @version Egret 2.4
  3578. * @platform Web,Native
  3579. */
  3580. OldNativeCanvasRenderContext.prototype.drawImage = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight) {
  3581. var bitmapData;
  3582. var isNative;
  3583. if (image.$nativeCanvas) {
  3584. bitmapData = image.$nativeCanvas;
  3585. isNative = true;
  3586. }
  3587. else {
  3588. bitmapData = image;
  3589. isNative = false;
  3590. }
  3591. if (!bitmapData) {
  3592. return;
  3593. }
  3594. if (arguments.length == 3) {
  3595. surfaceOffsetX = offsetX;
  3596. surfaceOffsetY = offsetY;
  3597. offsetX = 0;
  3598. offsetY = 0;
  3599. width = surfaceImageWidth = image.width;
  3600. height = surfaceImageHeight = image.height;
  3601. }
  3602. else if (arguments.length == 5) {
  3603. surfaceOffsetX = offsetX;
  3604. surfaceOffsetY = offsetY;
  3605. surfaceImageWidth = width;
  3606. surfaceImageHeight = height;
  3607. offsetX = 0;
  3608. offsetY = 0;
  3609. width = image.width;
  3610. height = image.height;
  3611. }
  3612. else {
  3613. if (width == void 0) {
  3614. width = image.width;
  3615. }
  3616. if (height == void 0) {
  3617. height = image.height;
  3618. }
  3619. if (surfaceOffsetX == void 0) {
  3620. surfaceOffsetX = 0;
  3621. }
  3622. if (surfaceOffsetY == void 0) {
  3623. surfaceOffsetY = 0;
  3624. }
  3625. if (surfaceImageWidth == void 0) {
  3626. surfaceImageWidth = width;
  3627. }
  3628. if (surfaceImageHeight == void 0) {
  3629. surfaceImageHeight = height;
  3630. }
  3631. }
  3632. //console.log("drawImage::" + offsetX + " " + offsetY + " " + width + " " + height + " " + surfaceOffsetX + " " + surfaceOffsetY + " " + surfaceImageWidth + " " + surfaceImageHeight);
  3633. //console.log("drawImage::" + bitmapData);
  3634. this.$nativeContext.drawImage(bitmapData, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight);
  3635. };
  3636. /**
  3637. * @private
  3638. * draw mesh
  3639. */
  3640. OldNativeCanvasRenderContext.prototype.drawMesh = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices) {
  3641. var bitmapData;
  3642. if (image.$nativeCanvas) {
  3643. bitmapData = image.$nativeCanvas;
  3644. }
  3645. else {
  3646. bitmapData = image;
  3647. }
  3648. if (!bitmapData) {
  3649. return;
  3650. }
  3651. if (arguments.length == 3) {
  3652. surfaceOffsetX = offsetX;
  3653. surfaceOffsetY = offsetY;
  3654. offsetX = 0;
  3655. offsetY = 0;
  3656. width = surfaceImageWidth = image.width;
  3657. height = surfaceImageHeight = image.height;
  3658. }
  3659. else if (arguments.length == 5) {
  3660. surfaceOffsetX = offsetX;
  3661. surfaceOffsetY = offsetY;
  3662. surfaceImageWidth = width;
  3663. surfaceImageHeight = height;
  3664. offsetX = 0;
  3665. offsetY = 0;
  3666. width = image.width;
  3667. height = image.height;
  3668. }
  3669. else {
  3670. if (!width) {
  3671. width = image.width;
  3672. }
  3673. if (!height) {
  3674. height = image.height;
  3675. }
  3676. if (!surfaceOffsetX) {
  3677. surfaceOffsetX = 0;
  3678. }
  3679. if (!surfaceOffsetY) {
  3680. surfaceOffsetY = 0;
  3681. }
  3682. if (!surfaceImageWidth) {
  3683. surfaceImageWidth = width;
  3684. }
  3685. if (!surfaceImageHeight) {
  3686. surfaceImageHeight = height;
  3687. }
  3688. }
  3689. this.vertices = new Float32Array(meshVertices.length / 2 * 5);
  3690. this.indicesForMesh = new Uint32Array(meshIndices.length);
  3691. this.cacheArrays(this.$matrix, 1, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices);
  3692. this.$nativeContext.drawMesh(bitmapData, this.vertices, this.indicesForMesh, this.vertices.length, this.indicesForMesh.length);
  3693. };
  3694. OldNativeCanvasRenderContext.prototype.cacheArrays = function (transform, alpha, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices) {
  3695. //计算出绘制矩阵,之后把矩阵还原回之前的
  3696. var locWorldTransform = transform;
  3697. var originalA = locWorldTransform.a;
  3698. var originalB = locWorldTransform.b;
  3699. var originalC = locWorldTransform.c;
  3700. var originalD = locWorldTransform.d;
  3701. var originalTx = locWorldTransform.tx;
  3702. var originalTy = locWorldTransform.ty;
  3703. if (destX != 0 || destY != 0) {
  3704. locWorldTransform.append(1, 0, 0, 1, destX, destY);
  3705. }
  3706. if (sourceWidth / destWidth != 1 || sourceHeight / destHeight != 1) {
  3707. locWorldTransform.append(destWidth / sourceWidth, 0, 0, destHeight / sourceHeight, 0, 0);
  3708. }
  3709. var a = locWorldTransform.a;
  3710. var b = locWorldTransform.b;
  3711. var c = locWorldTransform.c;
  3712. var d = locWorldTransform.d;
  3713. var tx = locWorldTransform.tx;
  3714. var ty = locWorldTransform.ty;
  3715. locWorldTransform.a = originalA;
  3716. locWorldTransform.b = originalB;
  3717. locWorldTransform.c = originalC;
  3718. locWorldTransform.d = originalD;
  3719. locWorldTransform.tx = originalTx;
  3720. locWorldTransform.ty = originalTy;
  3721. if (meshVertices) {
  3722. // 计算索引位置与赋值
  3723. var vertices = this.vertices;
  3724. // 缓存顶点数组
  3725. var i = 0, iD = 0, l = 0;
  3726. var u = 0, v = 0, x = 0, y = 0;
  3727. for (i = 0, l = meshUVs.length; i < l; i += 2) {
  3728. iD = i * 5 / 2;
  3729. x = meshVertices[i];
  3730. y = meshVertices[i + 1];
  3731. u = meshUVs[i];
  3732. v = meshUVs[i + 1];
  3733. // xy
  3734. vertices[iD + 0] = a * x + c * y + tx;
  3735. vertices[iD + 1] = b * x + d * y + ty;
  3736. // uv
  3737. vertices[iD + 2] = (sourceX + u * sourceWidth) / textureSourceWidth;
  3738. vertices[iD + 3] = (sourceY + v * sourceHeight) / textureSourceHeight;
  3739. // alpha
  3740. vertices[iD + 4] = alpha;
  3741. }
  3742. for (i = 0; i < meshIndices.length; i++) {
  3743. this.indicesForMesh[i] = meshIndices[i];
  3744. }
  3745. }
  3746. else {
  3747. console.log("meshVertices not exist");
  3748. }
  3749. };
  3750. /**
  3751. * @private
  3752. * 基于指定的源图象(BitmapData)创建一个模板,通过repetition参数指定源图像在什么方向上进行重复,返回一个GraphicsPattern对象。
  3753. * @param bitmapData 做为重复图像源的 BitmapData 对象。
  3754. * @param repetition 指定如何重复图像。
  3755. * 可能的值有:"repeat" (两个方向重复),"repeat-x" (仅水平方向重复),"repeat-y" (仅垂直方向重复),"no-repeat" (不重复).
  3756. * @version Egret 2.4
  3757. * @platform Web,Native
  3758. */
  3759. OldNativeCanvasRenderContext.prototype.createPattern = function (image, repetition) {
  3760. return null;
  3761. };
  3762. /**
  3763. * @private
  3764. * 返回一个 ImageData 对象,用来描述canvas区域隐含的像素数据,这个区域通过矩形表示,起始点为(sx, sy)、宽为sw、高为sh。
  3765. * @version Egret 2.4
  3766. * @platform Web,Native
  3767. */
  3768. OldNativeCanvasRenderContext.prototype.getImageData = function (sx, sy, sw, sh) {
  3769. var res;
  3770. if (sx != Math.floor(sx)) {
  3771. sx = Math.floor(sx);
  3772. sw++;
  3773. }
  3774. if (sy != Math.floor(sy)) {
  3775. sy = Math.floor(sy);
  3776. sh++;
  3777. }
  3778. res = this.$nativeContext.getPixels(sx, sy, sw, sh);
  3779. if (res.pixelData) {
  3780. res.data = res.pixelData;
  3781. }
  3782. return res;
  3783. };
  3784. /**
  3785. * @private
  3786. * 设置全局shader
  3787. * @param filter filter属性生成的json
  3788. */
  3789. OldNativeCanvasRenderContext.prototype.setGlobalShader = function (filter) {
  3790. egret_native.Graphics.setGlobalShader(filter);
  3791. };
  3792. return OldNativeCanvasRenderContext;
  3793. }(egret.HashObject));
  3794. native.OldNativeCanvasRenderContext = OldNativeCanvasRenderContext;
  3795. __reflect(OldNativeCanvasRenderContext.prototype, "egret.native.OldNativeCanvasRenderContext");
  3796. })(native = egret.native || (egret.native = {}));
  3797. })(egret || (egret = {}));
  3798. //////////////////////////////////////////////////////////////////////////////////////
  3799. //
  3800. // Copyright (c) 2014-present, Egret Technology.
  3801. // All rights reserved.
  3802. // Redistribution and use in source and binary forms, with or without
  3803. // modification, are permitted provided that the following conditions are met:
  3804. //
  3805. // * Redistributions of source code must retain the above copyright
  3806. // notice, this list of conditions and the following disclaimer.
  3807. // * Redistributions in binary form must reproduce the above copyright
  3808. // notice, this list of conditions and the following disclaimer in the
  3809. // documentation and/or other materials provided with the distribution.
  3810. // * Neither the name of the Egret nor the
  3811. // names of its contributors may be used to endorse or promote products
  3812. // derived from this software without specific prior written permission.
  3813. //
  3814. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3815. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3816. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3817. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3818. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3819. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3820. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3821. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3822. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3823. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3824. //
  3825. //////////////////////////////////////////////////////////////////////////////////////
  3826. var egret;
  3827. (function (egret) {
  3828. var native;
  3829. (function (native) {
  3830. /**
  3831. * @private
  3832. * 呈现最终绘图结果的画布
  3833. */
  3834. var NativeCanvas = (function (_super) {
  3835. __extends(NativeCanvas, _super);
  3836. /**
  3837. * @private
  3838. */
  3839. function NativeCanvas() {
  3840. var _this = _super.call(this) || this;
  3841. _this.$width = 0;
  3842. _this.$height = 0;
  3843. _this.renderContext = native.$supportCmdBatch ? new native.NativeCanvasRenderContext() : new native.OldNativeCanvasRenderContext();
  3844. return _this;
  3845. }
  3846. NativeCanvas.prototype.toDataURL = function (type) {
  3847. var args = [];
  3848. for (var _i = 1; _i < arguments.length; _i++) {
  3849. args[_i - 1] = arguments[_i];
  3850. }
  3851. if (this.$nativeCanvas) {
  3852. return this.$nativeCanvas.toDataURL.apply(this.$nativeCanvas, arguments);
  3853. }
  3854. return null;
  3855. };
  3856. NativeCanvas.prototype.saveToFile = function (type, filePath) {
  3857. if (this.$nativeCanvas && this.$nativeCanvas.saveToFile) {
  3858. this.$nativeCanvas.saveToFile(type, filePath);
  3859. }
  3860. };
  3861. Object.defineProperty(NativeCanvas.prototype, "width", {
  3862. /**
  3863. * @private
  3864. * @inheritDoc
  3865. */
  3866. get: function () {
  3867. return this.$width;
  3868. },
  3869. set: function (value) {
  3870. if (value > 0) {
  3871. this.$width = value;
  3872. if (!this.$nativeCanvas) {
  3873. this.$nativeCanvas = new egret_native.Canvas(value, 1);
  3874. if (this.$isRoot) {
  3875. egret_native.setScreenCanvas(this.$nativeCanvas);
  3876. }
  3877. var context = this.$nativeCanvas.getContext("2d");
  3878. if (native.$supportCmdBatch) {
  3879. native.$cmdManager.setContext(context);
  3880. native.$cmdManager.clearScreen(0, 0, 0, 0);
  3881. }
  3882. else {
  3883. context.clearScreen(0, 0, 0, 0);
  3884. }
  3885. this.renderContext.$nativeContext = context;
  3886. }
  3887. else {
  3888. this.$nativeCanvas.width = value;
  3889. }
  3890. }
  3891. },
  3892. enumerable: true,
  3893. configurable: true
  3894. });
  3895. Object.defineProperty(NativeCanvas.prototype, "height", {
  3896. /**
  3897. * @private
  3898. * @inheritDoc
  3899. */
  3900. get: function () {
  3901. return this.$height;
  3902. },
  3903. set: function (value) {
  3904. if (value > 0) {
  3905. this.$height = value;
  3906. if (!this.$nativeCanvas) {
  3907. this.$nativeCanvas = new egret_native.Canvas(1, value);
  3908. if (this.$isRoot) {
  3909. egret_native.setScreenCanvas(this.$nativeCanvas);
  3910. }
  3911. var context = this.$nativeCanvas.getContext("2d");
  3912. if (native.$supportCmdBatch) {
  3913. native.$cmdManager.setContext(context);
  3914. native.$cmdManager.clearScreen(0, 0, 0, 0);
  3915. }
  3916. else {
  3917. context.clearScreen(0, 0, 0, 0);
  3918. }
  3919. this.renderContext.$nativeContext = context;
  3920. }
  3921. else {
  3922. this.$nativeCanvas.height = value;
  3923. }
  3924. }
  3925. },
  3926. enumerable: true,
  3927. configurable: true
  3928. });
  3929. NativeCanvas.prototype.getContext = function (type) {
  3930. return this.renderContext;
  3931. };
  3932. return NativeCanvas;
  3933. }(egret.HashObject));
  3934. native.NativeCanvas = NativeCanvas;
  3935. __reflect(NativeCanvas.prototype, "egret.native.NativeCanvas");
  3936. })(native = egret.native || (egret.native = {}));
  3937. })(egret || (egret = {}));
  3938. //////////////////////////////////////////////////////////////////////////////////////
  3939. //
  3940. // Copyright (c) 2014-present, Egret Technology.
  3941. // All rights reserved.
  3942. // Redistribution and use in source and binary forms, with or without
  3943. // modification, are permitted provided that the following conditions are met:
  3944. //
  3945. // * Redistributions of source code must retain the above copyright
  3946. // notice, this list of conditions and the following disclaimer.
  3947. // * Redistributions in binary form must reproduce the above copyright
  3948. // notice, this list of conditions and the following disclaimer in the
  3949. // documentation and/or other materials provided with the distribution.
  3950. // * Neither the name of the Egret nor the
  3951. // names of its contributors may be used to endorse or promote products
  3952. // derived from this software without specific prior written permission.
  3953. //
  3954. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3955. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3956. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3957. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3958. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3959. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3960. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3961. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3962. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3963. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3964. //
  3965. //////////////////////////////////////////////////////////////////////////////////////
  3966. var egret;
  3967. (function (egret) {
  3968. var native;
  3969. (function (native) {
  3970. /**
  3971. * 创建一个canvas。
  3972. */
  3973. function createCanvas(width, height) {
  3974. var result = new native.NativeCanvas();
  3975. if (!isNaN(width) && !isNaN(height)) {
  3976. result.width = width;
  3977. result.height = height;
  3978. }
  3979. return result;
  3980. }
  3981. var sharedCanvas;
  3982. /**
  3983. * @private
  3984. * NativeCanvas2D渲染器
  3985. */
  3986. var NativeCanvasRenderBuffer = (function () {
  3987. function NativeCanvasRenderBuffer(width, height) {
  3988. this.surface = createCanvas(width, height);
  3989. this.context = this.surface.getContext("2d");
  3990. //保证rootCanvas是第一个创建的canvas
  3991. }
  3992. Object.defineProperty(NativeCanvasRenderBuffer.prototype, "width", {
  3993. /**
  3994. * 渲染缓冲的宽度,以像素为单位。
  3995. * @readOnly
  3996. */
  3997. get: function () {
  3998. return this.surface.width;
  3999. },
  4000. enumerable: true,
  4001. configurable: true
  4002. });
  4003. Object.defineProperty(NativeCanvasRenderBuffer.prototype, "height", {
  4004. /**
  4005. * 渲染缓冲的高度,以像素为单位。
  4006. * @readOnly
  4007. */
  4008. get: function () {
  4009. return this.surface.height;
  4010. },
  4011. enumerable: true,
  4012. configurable: true
  4013. });
  4014. /**
  4015. * 改变渲染缓冲的大小并清空缓冲区
  4016. * @param width 改变后的宽
  4017. * @param height 改变后的高
  4018. * @param useMaxSize 若传入true,则将改变后的尺寸与已有尺寸对比,保留较大的尺寸。
  4019. */
  4020. NativeCanvasRenderBuffer.prototype.resize = function (width, height, useMaxSize) {
  4021. //resize 之前要提交下绘制命令
  4022. if (native.$supportCmdBatch) {
  4023. native.$cmdManager.flush();
  4024. }
  4025. var surface = this.surface;
  4026. surface.width = width;
  4027. surface.height = height;
  4028. this.clear();
  4029. };
  4030. /**
  4031. * 改变渲染缓冲为指定大小,但保留原始图像数据
  4032. * @param width 改变后的宽
  4033. * @param height 改变后的高
  4034. * @param offsetX 原始图像数据在改变后缓冲区的绘制起始位置x
  4035. * @param offsetY 原始图像数据在改变后缓冲区的绘制起始位置y
  4036. */
  4037. NativeCanvasRenderBuffer.prototype.resizeTo = function (width, height, offsetX, offsetY) {
  4038. //resize 之前要提交下绘制命令
  4039. if (native.$supportCmdBatch) {
  4040. native.$cmdManager.flush();
  4041. }
  4042. if (!sharedCanvas) {
  4043. sharedCanvas = createCanvas();
  4044. }
  4045. var oldContext = this.context;
  4046. var oldSurface = this.surface;
  4047. var newSurface = sharedCanvas;
  4048. var newContext = newSurface.getContext("2d");
  4049. sharedCanvas = oldSurface;
  4050. this.context = newContext;
  4051. this.surface = newSurface;
  4052. newSurface.width = Math.max(width, 1);
  4053. newSurface.height = Math.max(height, 1);
  4054. newContext.setTransform(1, 0, 0, 1, 0, 0);
  4055. newContext.drawImage(oldSurface, offsetX, offsetY);
  4056. oldSurface.height = 1;
  4057. oldSurface.width = 1;
  4058. };
  4059. NativeCanvasRenderBuffer.prototype.setDirtyRegionPolicy = function (state) {
  4060. };
  4061. /**
  4062. * 清空并设置裁切
  4063. * @param regions 矩形列表
  4064. * @param offsetX 矩形要加上的偏移量x
  4065. * @param offsetY 矩形要加上的偏移量y
  4066. */
  4067. NativeCanvasRenderBuffer.prototype.beginClip = function (regions, offsetX, offsetY) {
  4068. offsetX = +offsetX || 0;
  4069. offsetY = +offsetY || 0;
  4070. var context = this.context;
  4071. context.save();
  4072. context.beginPath();
  4073. context.setTransform(1, 0, 0, 1, offsetX, offsetY);
  4074. var length = regions.length;
  4075. for (var i = 0; i < length; i++) {
  4076. var region = regions[i];
  4077. context.clearRect(region.minX, region.minY, region.width, region.height);
  4078. context.rect(region.minX, region.minY, region.width, region.height);
  4079. }
  4080. context.clip();
  4081. };
  4082. /**
  4083. * 取消上一次设置的clip。
  4084. */
  4085. NativeCanvasRenderBuffer.prototype.endClip = function () {
  4086. this.context.restore();
  4087. };
  4088. /**
  4089. * 获取指定区域的像素
  4090. */
  4091. NativeCanvasRenderBuffer.prototype.getPixels = function (x, y, width, height) {
  4092. if (width === void 0) { width = 1; }
  4093. if (height === void 0) { height = 1; }
  4094. return this.context.getImageData(x, y, width, height).data;
  4095. };
  4096. /**
  4097. * 转换成base64字符串,如果图片(或者包含的图片)跨域,则返回null
  4098. * @param type 转换的类型,如: "image/png","image/jpeg"
  4099. */
  4100. NativeCanvasRenderBuffer.prototype.toDataURL = function (type, encoderOptions) {
  4101. return this.surface.toDataURL(type, encoderOptions);
  4102. };
  4103. /**
  4104. * 清空缓冲区数据
  4105. */
  4106. NativeCanvasRenderBuffer.prototype.clear = function () {
  4107. var width = this.surface.width;
  4108. var height = this.surface.height;
  4109. if (width > 0 && height > 0) {
  4110. this.context.setTransform(1, 0, 0, 1, 0, 0);
  4111. this.context.clearRect(0, 0, width, height);
  4112. }
  4113. };
  4114. /**
  4115. * 销毁绘制对象
  4116. */
  4117. NativeCanvasRenderBuffer.prototype.destroy = function () {
  4118. this.surface.width = this.surface.height = 1;
  4119. };
  4120. return NativeCanvasRenderBuffer;
  4121. }());
  4122. native.NativeCanvasRenderBuffer = NativeCanvasRenderBuffer;
  4123. __reflect(NativeCanvasRenderBuffer.prototype, "egret.native.NativeCanvasRenderBuffer", ["egret.sys.RenderBuffer"]);
  4124. })(native = egret.native || (egret.native = {}));
  4125. })(egret || (egret = {}));
  4126. //////////////////////////////////////////////////////////////////////////////////////
  4127. //
  4128. // Copyright (c) 2014-present, Egret Technology.
  4129. // All rights reserved.
  4130. // Redistribution and use in source and binary forms, with or without
  4131. // modification, are permitted provided that the following conditions are met:
  4132. //
  4133. // * Redistributions of source code must retain the above copyright
  4134. // notice, this list of conditions and the following disclaimer.
  4135. // * Redistributions in binary form must reproduce the above copyright
  4136. // notice, this list of conditions and the following disclaimer in the
  4137. // documentation and/or other materials provided with the distribution.
  4138. // * Neither the name of the Egret nor the
  4139. // names of its contributors may be used to endorse or promote products
  4140. // derived from this software without specific prior written permission.
  4141. //
  4142. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4143. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4144. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4145. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4146. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4147. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4148. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4149. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4150. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4151. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4152. //
  4153. //////////////////////////////////////////////////////////////////////////////////////
  4154. var egret;
  4155. (function (egret) {
  4156. var native;
  4157. (function (native) {
  4158. /**
  4159. * @private
  4160. */
  4161. function convertImageToRenderTexture(texture, rect) {
  4162. var buffer = egret.sys.canvasHitTestBuffer;
  4163. var w = texture.$getTextureWidth();
  4164. var h = texture.$getTextureHeight();
  4165. if (rect == null) {
  4166. rect = egret.$TempRectangle;
  4167. rect.x = 0;
  4168. rect.y = 0;
  4169. rect.width = w;
  4170. rect.height = h;
  4171. }
  4172. rect.x = Math.min(rect.x, w - 1);
  4173. rect.y = Math.min(rect.y, h - 1);
  4174. rect.width = Math.min(rect.width, w - rect.x);
  4175. rect.height = Math.min(rect.height, h - rect.y);
  4176. var iWidth = rect.width;
  4177. var iHeight = rect.height;
  4178. var surface = buffer.surface;
  4179. buffer.resize(iWidth, iHeight);
  4180. var bitmapData = texture;
  4181. var offsetX = Math.round(bitmapData._offsetX);
  4182. var offsetY = Math.round(bitmapData._offsetY);
  4183. var bitmapWidth = bitmapData._bitmapWidth;
  4184. var bitmapHeight = bitmapData._bitmapHeight;
  4185. buffer.context.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);
  4186. return surface;
  4187. }
  4188. /**
  4189. * @private
  4190. */
  4191. function toDataURL(type, rect) {
  4192. try {
  4193. var renderTexture = convertImageToRenderTexture(this, rect);
  4194. var base64 = renderTexture.toDataURL(type);
  4195. //renderTexture.$dispose();
  4196. return base64;
  4197. }
  4198. catch (e) {
  4199. egret.$error(1033);
  4200. return null;
  4201. }
  4202. }
  4203. function saveToFile(type, filePath, rect) {
  4204. try {
  4205. var renderTexture = convertImageToRenderTexture(this, rect);
  4206. renderTexture.saveToFile(type, filePath);
  4207. }
  4208. catch (e) {
  4209. egret.$error(1033);
  4210. }
  4211. }
  4212. function getPixel32(x, y) {
  4213. egret.$error(1035);
  4214. return null;
  4215. }
  4216. function getPixels(x, y, width, height) {
  4217. egret.$error(1035);
  4218. return null;
  4219. }
  4220. egret.Texture.prototype.toDataURL = toDataURL;
  4221. egret.Texture.prototype.saveToFile = saveToFile;
  4222. egret.Texture.prototype.getPixel32 = getPixel32;
  4223. egret.Texture.prototype.getPixels = getPixels;
  4224. })(native = egret.native || (egret.native = {}));
  4225. })(egret || (egret = {}));
  4226. //////////////////////////////////////////////////////////////////////////////////////
  4227. //
  4228. // Copyright (c) 2014-present, Egret Technology.
  4229. // All rights reserved.
  4230. // Redistribution and use in source and binary forms, with or without
  4231. // modification, are permitted provided that the following conditions are met:
  4232. //
  4233. // * Redistributions of source code must retain the above copyright
  4234. // notice, this list of conditions and the following disclaimer.
  4235. // * Redistributions in binary form must reproduce the above copyright
  4236. // notice, this list of conditions and the following disclaimer in the
  4237. // documentation and/or other materials provided with the distribution.
  4238. // * Neither the name of the Egret nor the
  4239. // names of its contributors may be used to endorse or promote products
  4240. // derived from this software without specific prior written permission.
  4241. //
  4242. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4243. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4244. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4245. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4246. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4247. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4248. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4249. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4250. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4251. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4252. //
  4253. //////////////////////////////////////////////////////////////////////////////////////
  4254. var egret;
  4255. (function (egret) {
  4256. var native;
  4257. (function (native) {
  4258. /**
  4259. * @private
  4260. */
  4261. var NativePlayer = (function (_super) {
  4262. __extends(NativePlayer, _super);
  4263. function NativePlayer() {
  4264. var _this = _super.call(this) || this;
  4265. _this.init(NativePlayer.option);
  4266. return _this;
  4267. }
  4268. NativePlayer.prototype.init = function (option) {
  4269. //暂时无法显示重绘区域
  4270. option.showPaintRect = false;
  4271. var stage = new egret.Stage();
  4272. stage.$screen = this;
  4273. stage.$scaleMode = option.scaleMode;
  4274. stage.$maxTouches = option.maxTouches;
  4275. stage.textureScaleFactor = option.textureScaleFactor;
  4276. //设置帧频到native
  4277. stage.frameRate = option.frameRate;
  4278. if (!egret.native.$supportCanvas) {
  4279. stage.addEventListener(egret.Event.ENTER_FRAME, function () {
  4280. if (native.$currentSurface) {
  4281. native.$currentSurface.end();
  4282. }
  4283. }, this);
  4284. }
  4285. var buffer = new egret.sys.RenderBuffer(undefined, undefined, true);
  4286. var canvas = buffer.surface;
  4287. canvas.$isRoot = true;
  4288. var touch = new native.NativeTouchHandler(stage);
  4289. var player = new egret.sys.Player(buffer, stage, option.entryClassName);
  4290. new native.NativeHideHandler(stage);
  4291. player.showPaintRect(option.showPaintRect);
  4292. if (option.showFPS || option.showLog) {
  4293. var styleStr = option.fpsStyles || "";
  4294. var stylesArr = styleStr.split(",");
  4295. var styles = {};
  4296. for (var i = 0; i < stylesArr.length; i++) {
  4297. var tempStyleArr = stylesArr[i].split(":");
  4298. styles[tempStyleArr[0]] = tempStyleArr[1];
  4299. }
  4300. option.fpsStyles = styles;
  4301. player.displayFPS(option.showFPS, option.showLog, option.logFilter, option.fpsStyles);
  4302. }
  4303. this.playerOption = option;
  4304. this.$stage = stage;
  4305. this.player = player;
  4306. this.nativeTouch = touch;
  4307. //this.nativeInput = nativeInput;
  4308. this.updateScreenSize();
  4309. this.updateMaxTouches();
  4310. player.start();
  4311. };
  4312. NativePlayer.prototype.updateScreenSize = function () {
  4313. var option = this.playerOption;
  4314. var screenWidth = egret_native.EGTView.getFrameWidth();
  4315. var screenHeight = egret_native.EGTView.getFrameHeight();
  4316. egret.Capabilities.$boundingClientWidth = screenWidth;
  4317. egret.Capabilities.$boundingClientHeight = screenHeight;
  4318. var stageSize = egret.sys.screenAdapter.calculateStageSize(this.$stage.$scaleMode, screenWidth, screenHeight, option.contentWidth, option.contentHeight);
  4319. var stageWidth = stageSize.stageWidth;
  4320. var stageHeight = stageSize.stageHeight;
  4321. var displayWidth = stageSize.displayWidth;
  4322. var displayHeight = stageSize.displayHeight;
  4323. var top = (screenHeight - displayHeight) / 2;
  4324. var left = (screenWidth - displayWidth) / 2;
  4325. egret_native.EGTView.setVisibleRect(left, top, displayWidth, displayHeight);
  4326. egret_native.EGTView.setDesignSize(stageWidth, stageHeight);
  4327. this.player.updateStageSize(stageWidth, stageHeight);
  4328. };
  4329. NativePlayer.prototype.setContentSize = function (width, height) {
  4330. var option = this.playerOption;
  4331. option.contentWidth = width;
  4332. option.contentHeight = height;
  4333. this.updateScreenSize();
  4334. };
  4335. /**
  4336. * @private
  4337. * 更新触摸数量
  4338. */
  4339. NativePlayer.prototype.updateMaxTouches = function () {
  4340. this.nativeTouch.$updateMaxTouches();
  4341. };
  4342. return NativePlayer;
  4343. }(egret.HashObject));
  4344. native.NativePlayer = NativePlayer;
  4345. __reflect(NativePlayer.prototype, "egret.native.NativePlayer", ["egret.sys.Screen"]);
  4346. })(native = egret.native || (egret.native = {}));
  4347. })(egret || (egret = {}));
  4348. //////////////////////////////////////////////////////////////////////////////////////
  4349. //
  4350. // Copyright (c) 2014-present, Egret Technology.
  4351. // All rights reserved.
  4352. // Redistribution and use in source and binary forms, with or without
  4353. // modification, are permitted provided that the following conditions are met:
  4354. //
  4355. // * Redistributions of source code must retain the above copyright
  4356. // notice, this list of conditions and the following disclaimer.
  4357. // * Redistributions in binary form must reproduce the above copyright
  4358. // notice, this list of conditions and the following disclaimer in the
  4359. // documentation and/or other materials provided with the distribution.
  4360. // * Neither the name of the Egret nor the
  4361. // names of its contributors may be used to endorse or promote products
  4362. // derived from this software without specific prior written permission.
  4363. //
  4364. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4365. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4366. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4367. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4368. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4369. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4370. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4371. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4372. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4373. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4374. //
  4375. //////////////////////////////////////////////////////////////////////////////////////
  4376. var egret;
  4377. (function (egret) {
  4378. var native;
  4379. (function (native) {
  4380. /**
  4381. * @private
  4382. */
  4383. native.$supportCanvas = egret_native.Canvas ? true : false;
  4384. /**
  4385. * @private
  4386. * 判断当前runtime版本是否支持cmdBatch
  4387. */
  4388. native.$supportCmdBatch = egret_native.sendToC ? true : false;
  4389. /*
  4390. * @private
  4391. * 命令控制器
  4392. * */
  4393. var CmdManager = (function () {
  4394. function CmdManager() {
  4395. /*
  4396. * 存储绘制命令的 array buffer
  4397. **/
  4398. this.maxArrayBufferLen = 80000;
  4399. this.arrayBuffer = new ArrayBuffer(this.maxArrayBufferLen * 4);
  4400. this.uint32View = new Uint32Array(this.arrayBuffer);
  4401. this.float32View = new Float32Array(this.arrayBuffer);
  4402. this.arrayBufferLen = 0;
  4403. /*
  4404. * 存储字符串的数组
  4405. */
  4406. this.strArray = [];
  4407. //------绘制命令 end-------------
  4408. }
  4409. /*
  4410. * 上传绘制命令到C
  4411. */
  4412. CmdManager.prototype.flush = function () {
  4413. egret_native.sendToC(this.float32View, this.arrayBufferLen, this.strArray);
  4414. this.clear();
  4415. };
  4416. /*
  4417. * 切换native上下文
  4418. * native绘制需要在自身的上下文进行绘制
  4419. */
  4420. CmdManager.prototype.setContext = function (ctx) {
  4421. if (this.context != ctx) {
  4422. if (this.arrayBufferLen + 3 > this.maxArrayBufferLen) {
  4423. this.flush();
  4424. }
  4425. this.context = ctx;
  4426. var uint32View = this.uint32View;
  4427. var arrayBufferLen = this.arrayBufferLen;
  4428. uint32View[arrayBufferLen++] = 1000;
  4429. // uint32View[arrayBufferLen++] = ctx.___native_texture__p;
  4430. // 兼容64位
  4431. var addr = ctx.___native_texture__p;
  4432. uint32View[arrayBufferLen++] = (addr / 4294967296) >>> 0;
  4433. uint32View[arrayBufferLen++] = (addr & 4294967295) >>> 0;
  4434. // uint32View[arrayBufferLen++] = addr >> 32;
  4435. // uint32View[arrayBufferLen++] = addr & 4294967295;
  4436. this.arrayBufferLen = arrayBufferLen;
  4437. }
  4438. };
  4439. /*
  4440. * 清空绘制命令
  4441. */
  4442. CmdManager.prototype.clear = function () {
  4443. this.arrayBufferLen = 0;
  4444. this.strArray.length = 0;
  4445. };
  4446. /*
  4447. * 压入一个字符串并返回索引
  4448. */
  4449. CmdManager.prototype.pushString = function (str) {
  4450. var array = this.strArray;
  4451. var len = array.length;
  4452. array[len] = str;
  4453. return len;
  4454. };
  4455. //------绘制命令 start-------------
  4456. CmdManager.prototype.clearScreen = function (i1, i2, i3, i4) {
  4457. if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
  4458. this.flush();
  4459. }
  4460. var uint32View = this.uint32View;
  4461. var arrayBufferLen = this.arrayBufferLen;
  4462. uint32View[arrayBufferLen++] = 100;
  4463. uint32View[arrayBufferLen++] = i1;
  4464. uint32View[arrayBufferLen++] = i2;
  4465. uint32View[arrayBufferLen++] = i3;
  4466. uint32View[arrayBufferLen++] = i4;
  4467. this.arrayBufferLen = arrayBufferLen;
  4468. };
  4469. CmdManager.prototype.drawImage = function (i1, f1, f2, f3, f4, f5, f6, f7, f8) {
  4470. if (this.arrayBufferLen + 11 > this.maxArrayBufferLen) {
  4471. this.flush();
  4472. }
  4473. var uint32View = this.uint32View;
  4474. var float32View = this.float32View;
  4475. var arrayBufferLen = this.arrayBufferLen;
  4476. uint32View[arrayBufferLen++] = 101;
  4477. // uint32View[arrayBufferLen++] = i1;
  4478. // 兼容64位
  4479. // uint32View[arrayBufferLen++] = i1 >> 32;
  4480. // uint32View[arrayBufferLen++] = i1 & 4294967295;
  4481. uint32View[arrayBufferLen++] = (i1 / 4294967296) >>> 0;
  4482. uint32View[arrayBufferLen++] = (i1 & 4294967295) >>> 0;
  4483. float32View[arrayBufferLen++] = f1;
  4484. float32View[arrayBufferLen++] = f2;
  4485. float32View[arrayBufferLen++] = f3;
  4486. float32View[arrayBufferLen++] = f4;
  4487. float32View[arrayBufferLen++] = f5;
  4488. float32View[arrayBufferLen++] = f6;
  4489. float32View[arrayBufferLen++] = f7;
  4490. float32View[arrayBufferLen++] = f8;
  4491. this.arrayBufferLen = arrayBufferLen;
  4492. };
  4493. CmdManager.prototype.setTransform = function (f1, f2, f3, f4, f5, f6) {
  4494. if (this.arrayBufferLen + 7 > this.maxArrayBufferLen) {
  4495. this.flush();
  4496. }
  4497. var uint32View = this.uint32View;
  4498. var float32View = this.float32View;
  4499. var arrayBufferLen = this.arrayBufferLen;
  4500. uint32View[arrayBufferLen++] = 103;
  4501. float32View[arrayBufferLen++] = f1;
  4502. float32View[arrayBufferLen++] = f2;
  4503. float32View[arrayBufferLen++] = f3;
  4504. float32View[arrayBufferLen++] = f4;
  4505. float32View[arrayBufferLen++] = f5;
  4506. float32View[arrayBufferLen++] = f6;
  4507. this.arrayBufferLen = arrayBufferLen;
  4508. };
  4509. CmdManager.prototype.setGlobalAlpha = function (f1) {
  4510. if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
  4511. this.flush();
  4512. }
  4513. var uint32View = this.uint32View;
  4514. var float32View = this.float32View;
  4515. var arrayBufferLen = this.arrayBufferLen;
  4516. uint32View[arrayBufferLen++] = 106;
  4517. float32View[arrayBufferLen++] = f1;
  4518. this.arrayBufferLen = arrayBufferLen;
  4519. };
  4520. CmdManager.prototype.pushRectStencils = function (array) {
  4521. var len = array.length;
  4522. if (this.arrayBufferLen + len + 1 > this.maxArrayBufferLen) {
  4523. this.flush();
  4524. }
  4525. var uint32View = this.uint32View;
  4526. var float32View = this.float32View;
  4527. var arrayBufferLen = this.arrayBufferLen;
  4528. uint32View[arrayBufferLen++] = 113;
  4529. uint32View[arrayBufferLen++] = len;
  4530. for (var i = 0; i < len; i++) {
  4531. float32View[arrayBufferLen++] = array[i];
  4532. }
  4533. this.arrayBufferLen = arrayBufferLen;
  4534. };
  4535. CmdManager.prototype.restore = function () {
  4536. if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
  4537. this.flush();
  4538. }
  4539. this.uint32View[this.arrayBufferLen++] = 116;
  4540. };
  4541. CmdManager.prototype.save = function () {
  4542. if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
  4543. this.flush();
  4544. }
  4545. this.uint32View[this.arrayBufferLen++] = 117;
  4546. };
  4547. CmdManager.prototype.setBlendArg = function (f1, f2) {
  4548. if (this.arrayBufferLen + 3 > this.maxArrayBufferLen) {
  4549. this.flush();
  4550. }
  4551. var uint32View = this.uint32View;
  4552. var float32View = this.float32View;
  4553. var arrayBufferLen = this.arrayBufferLen;
  4554. uint32View[arrayBufferLen++] = 120;
  4555. float32View[arrayBufferLen++] = f1;
  4556. float32View[arrayBufferLen++] = f2;
  4557. this.arrayBufferLen = arrayBufferLen;
  4558. };
  4559. CmdManager.prototype.beginPath = function () {
  4560. if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
  4561. this.flush();
  4562. }
  4563. this.uint32View[this.arrayBufferLen++] = 204;
  4564. };
  4565. CmdManager.prototype.closePath = function () {
  4566. if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
  4567. this.flush();
  4568. }
  4569. this.uint32View[this.arrayBufferLen++] = 205;
  4570. };
  4571. CmdManager.prototype.rect = function (f1, f2, f3, f4) {
  4572. if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
  4573. this.flush();
  4574. }
  4575. var uint32View = this.uint32View;
  4576. var float32View = this.float32View;
  4577. var arrayBufferLen = this.arrayBufferLen;
  4578. uint32View[arrayBufferLen++] = 210;
  4579. float32View[arrayBufferLen++] = f1;
  4580. float32View[arrayBufferLen++] = f2;
  4581. float32View[arrayBufferLen++] = f3;
  4582. float32View[arrayBufferLen++] = f4;
  4583. this.arrayBufferLen = arrayBufferLen;
  4584. };
  4585. CmdManager.prototype.clearRect = function (f1, f2, f3, f4) {
  4586. if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
  4587. this.flush();
  4588. }
  4589. var uint32View = this.uint32View;
  4590. var float32View = this.float32View;
  4591. var arrayBufferLen = this.arrayBufferLen;
  4592. uint32View[arrayBufferLen++] = 214;
  4593. float32View[arrayBufferLen++] = f1;
  4594. float32View[arrayBufferLen++] = f2;
  4595. float32View[arrayBufferLen++] = f3;
  4596. float32View[arrayBufferLen++] = f4;
  4597. this.arrayBufferLen = arrayBufferLen;
  4598. };
  4599. CmdManager.prototype.createLabel = function (i1, f1, i2, f2) {
  4600. if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
  4601. this.flush();
  4602. }
  4603. var uint32View = this.uint32View;
  4604. var float32View = this.float32View;
  4605. var arrayBufferLen = this.arrayBufferLen;
  4606. uint32View[arrayBufferLen++] = 300;
  4607. uint32View[arrayBufferLen++] = i1;
  4608. float32View[arrayBufferLen++] = f1;
  4609. uint32View[arrayBufferLen++] = i2;
  4610. float32View[arrayBufferLen++] = f2;
  4611. this.arrayBufferLen = arrayBufferLen;
  4612. };
  4613. CmdManager.prototype.drawText = function (i1, f1, f2) {
  4614. if (this.arrayBufferLen + 4 > this.maxArrayBufferLen) {
  4615. this.flush();
  4616. }
  4617. var uint32View = this.uint32View;
  4618. var float32View = this.float32View;
  4619. var arrayBufferLen = this.arrayBufferLen;
  4620. uint32View[arrayBufferLen++] = 301;
  4621. uint32View[arrayBufferLen++] = i1;
  4622. float32View[arrayBufferLen++] = f1;
  4623. float32View[arrayBufferLen++] = f2;
  4624. this.arrayBufferLen = arrayBufferLen;
  4625. };
  4626. CmdManager.prototype.setTextColor = function (i1) {
  4627. if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
  4628. this.flush();
  4629. }
  4630. var uint32View = this.uint32View;
  4631. var arrayBufferLen = this.arrayBufferLen;
  4632. uint32View[arrayBufferLen++] = 302;
  4633. uint32View[arrayBufferLen++] = i1;
  4634. this.arrayBufferLen = arrayBufferLen;
  4635. };
  4636. CmdManager.prototype.setStrokeColor = function (i1) {
  4637. if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
  4638. this.flush();
  4639. }
  4640. var uint32View = this.uint32View;
  4641. var arrayBufferLen = this.arrayBufferLen;
  4642. uint32View[arrayBufferLen++] = 303;
  4643. uint32View[arrayBufferLen++] = i1;
  4644. this.arrayBufferLen = arrayBufferLen;
  4645. };
  4646. CmdManager.prototype.setFillStyle = function (i1) {
  4647. if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
  4648. this.flush();
  4649. }
  4650. var uint32View = this.uint32View;
  4651. var arrayBufferLen = this.arrayBufferLen;
  4652. uint32View[arrayBufferLen++] = 1200;
  4653. uint32View[arrayBufferLen++] = i1;
  4654. this.arrayBufferLen = arrayBufferLen;
  4655. };
  4656. CmdManager.prototype.setStrokeStyle = function (i1) {
  4657. if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
  4658. this.flush();
  4659. }
  4660. var uint32View = this.uint32View;
  4661. var arrayBufferLen = this.arrayBufferLen;
  4662. uint32View[arrayBufferLen++] = 1201;
  4663. uint32View[arrayBufferLen++] = i1;
  4664. this.arrayBufferLen = arrayBufferLen;
  4665. };
  4666. CmdManager.prototype.setLineWidth = function (f1) {
  4667. if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
  4668. this.flush();
  4669. }
  4670. var uint32View = this.uint32View;
  4671. var float32View = this.float32View;
  4672. var arrayBufferLen = this.arrayBufferLen;
  4673. uint32View[arrayBufferLen++] = 1202;
  4674. float32View[arrayBufferLen++] = f1;
  4675. this.arrayBufferLen = arrayBufferLen;
  4676. };
  4677. CmdManager.prototype.moveTo = function (f1, f2) {
  4678. if (this.arrayBufferLen + 3 > this.maxArrayBufferLen) {
  4679. this.flush();
  4680. }
  4681. var uint32View = this.uint32View;
  4682. var float32View = this.float32View;
  4683. var arrayBufferLen = this.arrayBufferLen;
  4684. uint32View[arrayBufferLen++] = 207;
  4685. float32View[arrayBufferLen++] = f1;
  4686. float32View[arrayBufferLen++] = f2;
  4687. this.arrayBufferLen = arrayBufferLen;
  4688. };
  4689. CmdManager.prototype.lineTo = function (f1, f2) {
  4690. if (this.arrayBufferLen + 3 > this.maxArrayBufferLen) {
  4691. this.flush();
  4692. }
  4693. var uint32View = this.uint32View;
  4694. var float32View = this.float32View;
  4695. var arrayBufferLen = this.arrayBufferLen;
  4696. uint32View[arrayBufferLen++] = 208;
  4697. float32View[arrayBufferLen++] = f1;
  4698. float32View[arrayBufferLen++] = f2;
  4699. this.arrayBufferLen = arrayBufferLen;
  4700. };
  4701. CmdManager.prototype.fill = function (i1) {
  4702. if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
  4703. this.flush();
  4704. }
  4705. var uint32View = this.uint32View;
  4706. var arrayBufferLen = this.arrayBufferLen;
  4707. uint32View[arrayBufferLen++] = 203;
  4708. uint32View[arrayBufferLen++] = i1;
  4709. this.arrayBufferLen = arrayBufferLen;
  4710. };
  4711. CmdManager.prototype.pushClip = function (f1, f2, f3, f4) {
  4712. if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
  4713. this.flush();
  4714. }
  4715. var uint32View = this.uint32View;
  4716. var float32View = this.float32View;
  4717. var arrayBufferLen = this.arrayBufferLen;
  4718. uint32View[arrayBufferLen++] = 107;
  4719. float32View[arrayBufferLen++] = f1;
  4720. float32View[arrayBufferLen++] = f2;
  4721. float32View[arrayBufferLen++] = f3;
  4722. float32View[arrayBufferLen++] = f4;
  4723. this.arrayBufferLen = arrayBufferLen;
  4724. };
  4725. CmdManager.prototype.popClip = function () {
  4726. if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
  4727. this.flush();
  4728. }
  4729. this.uint32View[this.arrayBufferLen++] = 108;
  4730. };
  4731. CmdManager.prototype.stroke = function () {
  4732. if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
  4733. this.flush();
  4734. }
  4735. this.uint32View[this.arrayBufferLen++] = 206;
  4736. };
  4737. CmdManager.prototype.arc = function (f1, f2, f3, f4, f5, i6) {
  4738. if (this.arrayBufferLen + 7 > this.maxArrayBufferLen) {
  4739. this.flush();
  4740. }
  4741. var uint32View = this.uint32View;
  4742. var float32View = this.float32View;
  4743. var arrayBufferLen = this.arrayBufferLen;
  4744. uint32View[arrayBufferLen++] = 209;
  4745. float32View[arrayBufferLen++] = f1;
  4746. float32View[arrayBufferLen++] = f2;
  4747. float32View[arrayBufferLen++] = f3;
  4748. float32View[arrayBufferLen++] = f4;
  4749. float32View[arrayBufferLen++] = f5;
  4750. uint32View[arrayBufferLen++] = i6;
  4751. this.arrayBufferLen = arrayBufferLen;
  4752. };
  4753. CmdManager.prototype.quadraticCurveTo = function (f1, f2, f3, f4) {
  4754. if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
  4755. this.flush();
  4756. }
  4757. var uint32View = this.uint32View;
  4758. var float32View = this.float32View;
  4759. var arrayBufferLen = this.arrayBufferLen;
  4760. uint32View[arrayBufferLen++] = 211;
  4761. float32View[arrayBufferLen++] = f1;
  4762. float32View[arrayBufferLen++] = f2;
  4763. float32View[arrayBufferLen++] = f3;
  4764. float32View[arrayBufferLen++] = f4;
  4765. this.arrayBufferLen = arrayBufferLen;
  4766. };
  4767. CmdManager.prototype.fillRect = function (f1, f2, f3, f4) {
  4768. if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
  4769. this.flush();
  4770. }
  4771. var uint32View = this.uint32View;
  4772. var float32View = this.float32View;
  4773. var arrayBufferLen = this.arrayBufferLen;
  4774. uint32View[arrayBufferLen++] = 212;
  4775. float32View[arrayBufferLen++] = f1;
  4776. float32View[arrayBufferLen++] = f2;
  4777. float32View[arrayBufferLen++] = f3;
  4778. float32View[arrayBufferLen++] = f4;
  4779. this.arrayBufferLen = arrayBufferLen;
  4780. };
  4781. CmdManager.prototype.strokeRect = function (f1, f2, f3, f4) {
  4782. if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
  4783. this.flush();
  4784. }
  4785. var uint32View = this.uint32View;
  4786. var float32View = this.float32View;
  4787. var arrayBufferLen = this.arrayBufferLen;
  4788. uint32View[arrayBufferLen++] = 213;
  4789. float32View[arrayBufferLen++] = f1;
  4790. float32View[arrayBufferLen++] = f2;
  4791. float32View[arrayBufferLen++] = f3;
  4792. float32View[arrayBufferLen++] = f4;
  4793. this.arrayBufferLen = arrayBufferLen;
  4794. };
  4795. CmdManager.prototype.bezierCurveTo = function (f1, f2, f3, f4, f5, f6) {
  4796. if (this.arrayBufferLen + 7 > this.maxArrayBufferLen) {
  4797. this.flush();
  4798. }
  4799. var uint32View = this.uint32View;
  4800. var float32View = this.float32View;
  4801. var arrayBufferLen = this.arrayBufferLen;
  4802. uint32View[arrayBufferLen++] = 215;
  4803. float32View[arrayBufferLen++] = f1;
  4804. float32View[arrayBufferLen++] = f2;
  4805. float32View[arrayBufferLen++] = f3;
  4806. float32View[arrayBufferLen++] = f4;
  4807. float32View[arrayBufferLen++] = f5;
  4808. float32View[arrayBufferLen++] = f6;
  4809. this.arrayBufferLen = arrayBufferLen;
  4810. };
  4811. CmdManager.prototype.setGlobalShader = function (i1) {
  4812. if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
  4813. this.flush();
  4814. }
  4815. var uint32View = this.uint32View;
  4816. var arrayBufferLen = this.arrayBufferLen;
  4817. uint32View[arrayBufferLen++] = 111;
  4818. uint32View[arrayBufferLen++] = i1;
  4819. this.arrayBufferLen = arrayBufferLen;
  4820. };
  4821. return CmdManager;
  4822. }());
  4823. __reflect(CmdManager.prototype, "CmdManager");
  4824. /*
  4825. * @private
  4826. * 输出一个单例命令控制器,供所有需要调用的地方使用
  4827. */
  4828. native.$cmdManager = new CmdManager();
  4829. var isRunning = false;
  4830. var playerList = [];
  4831. function runEgret(options) {
  4832. if (isRunning) {
  4833. return;
  4834. }
  4835. isRunning = true;
  4836. if (!options) {
  4837. options = {};
  4838. }
  4839. setRenderMode(options.renderMode);
  4840. if (true) {
  4841. //todo 获得系统语言版本
  4842. var language = "zh_CN";
  4843. if (language in egret.$locale_strings)
  4844. egret.$language = language;
  4845. }
  4846. try {
  4847. egret.Capabilities.$setNativeCapabilities(egret_native.getVersion());
  4848. }
  4849. catch (e) {
  4850. }
  4851. var ticker = egret.sys.$ticker;
  4852. var mainLoop = native.$supportCmdBatch ? function () {
  4853. ticker.update();
  4854. native.$cmdManager.flush();
  4855. } : function () {
  4856. ticker.update();
  4857. };
  4858. egret_native.executeMainLoop(mainLoop, ticker);
  4859. if (!egret.sys.screenAdapter) {
  4860. if (options.screenAdapter) {
  4861. egret.sys.screenAdapter = options.screenAdapter;
  4862. }
  4863. else {
  4864. egret.sys.screenAdapter = new egret.sys.DefaultScreenAdapter();
  4865. }
  4866. }
  4867. //todo
  4868. var player = new native.NativePlayer();
  4869. playerList.push(player);
  4870. egret.sys.customHitTestBuffer = new native.NativeCanvasRenderBuffer(3, 3);
  4871. egret.sys.canvasHitTestBuffer = egret.sys.customHitTestBuffer;
  4872. //老版本runtime不支持canvas,关闭脏矩形
  4873. if (!native.$supportCanvas) {
  4874. player.$stage.dirtyRegionPolicy = egret.DirtyRegionPolicy.OFF;
  4875. egret.sys.DisplayList.prototype.setDirtyRegionPolicy = function () {
  4876. };
  4877. }
  4878. }
  4879. /**
  4880. * 设置渲染模式。"auto","webgl","canvas"
  4881. * @param renderMode
  4882. */
  4883. function setRenderMode(renderMode) {
  4884. if (native.$supportCanvas) {
  4885. egret.sys.RenderBuffer = native.NativeCanvasRenderBuffer;
  4886. egret.sys.CanvasRenderBuffer = native.NativeCanvasRenderBuffer;
  4887. }
  4888. else {
  4889. egret.sys.RenderBuffer = native.NativeRenderTextureRenderBuffer;
  4890. egret.sys.CanvasRenderBuffer = native.NativeRenderTextureRenderBuffer;
  4891. }
  4892. egret.sys.systemRenderer = new egret.CanvasRenderer();
  4893. egret.sys.canvasRenderer = egret.sys.systemRenderer;
  4894. egret.Capabilities.$renderMode = "canvas";
  4895. }
  4896. function updateAllScreens() {
  4897. var length = playerList.length;
  4898. for (var i = 0; i < length; i++) {
  4899. playerList[i].updateScreenSize();
  4900. }
  4901. }
  4902. function toArray(argument) {
  4903. var args = [];
  4904. for (var i = 0; i < argument.length; i++) {
  4905. args.push(argument[i]);
  4906. }
  4907. return args;
  4908. }
  4909. egret.warn = function () {
  4910. console.warn.apply(console, toArray(arguments));
  4911. };
  4912. egret.error = function () {
  4913. console.error.apply(console, toArray(arguments));
  4914. };
  4915. egret.assert = function () {
  4916. console.assert.apply(console, toArray(arguments));
  4917. };
  4918. if (true) {
  4919. egret.log = function () {
  4920. if (true) {
  4921. var length_8 = arguments.length;
  4922. var info = "";
  4923. for (var i = 0; i < length_8; i++) {
  4924. info += arguments[i] + " ";
  4925. }
  4926. egret.sys.$logToFPS(info);
  4927. }
  4928. console.log.apply(console, toArray(arguments));
  4929. };
  4930. }
  4931. else {
  4932. egret.log = function () {
  4933. console.log.apply(console, toArray(arguments));
  4934. };
  4935. }
  4936. egret.runEgret = runEgret;
  4937. egret.updateAllScreens = updateAllScreens;
  4938. })(native = egret.native || (egret.native = {}));
  4939. })(egret || (egret = {}));
  4940. //////////////////////////////////////////////////////////////////////////////////////
  4941. //
  4942. // Copyright (c) 2014-present, Egret Technology.
  4943. // All rights reserved.
  4944. // Redistribution and use in source and binary forms, with or without
  4945. // modification, are permitted provided that the following conditions are met:
  4946. //
  4947. // * Redistributions of source code must retain the above copyright
  4948. // notice, this list of conditions and the following disclaimer.
  4949. // * Redistributions in binary form must reproduce the above copyright
  4950. // notice, this list of conditions and the following disclaimer in the
  4951. // documentation and/or other materials provided with the distribution.
  4952. // * Neither the name of the Egret nor the
  4953. // names of its contributors may be used to endorse or promote products
  4954. // derived from this software without specific prior written permission.
  4955. //
  4956. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4957. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4958. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4959. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4960. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4961. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4962. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4963. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4964. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4965. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4966. //
  4967. //////////////////////////////////////////////////////////////////////////////////////
  4968. var egret;
  4969. (function (egret) {
  4970. var native;
  4971. (function (native) {
  4972. /**
  4973. * @private
  4974. */
  4975. var NativeFps = (function (_super) {
  4976. __extends(NativeFps, _super);
  4977. function NativeFps(stage, showFPS, showLog, logFilter, styles) {
  4978. var _this = _super.call(this) || this;
  4979. _this.arrFps = [];
  4980. _this.arrLog = [];
  4981. if (showFPS || showLog) {
  4982. _this.panelX = styles["x"] === undefined ? 0 : parseInt(styles['x']);
  4983. _this.panelY = styles["y"] === undefined ? 0 : parseInt(styles['y']);
  4984. _this._stage = stage;
  4985. _this.showFps = showFPS;
  4986. _this.showLog = showLog;
  4987. _this.fontColor = styles["textColor"] === undefined ? 0xffffff : parseInt(styles['textColor']);
  4988. _this.fontSize = styles["size"] === undefined ? 24 : parseInt(styles['size']);
  4989. _this.bgAlpha = styles["bgAlpha"] || 0.9;
  4990. _this.shape = new egret.Shape();
  4991. _this.addChild(_this.shape);
  4992. if (showFPS)
  4993. _this.addFps();
  4994. if (showLog)
  4995. _this.addLog();
  4996. }
  4997. return _this;
  4998. }
  4999. NativeFps.prototype.addFps = function () {
  5000. var fps = new egret.TextField();
  5001. fps.x = fps.y = 4;
  5002. this.textFps = fps;
  5003. this.addChild(fps);
  5004. fps.lineSpacing = 2;
  5005. fps.size = this.fontSize;
  5006. fps.textColor = this.fontColor;
  5007. fps.textFlow = [
  5008. { text: "0 FPS " + egret.Capabilities.renderMode + "\n" },
  5009. { text: "Draw: 0\nDirty: 0%\n" },
  5010. { text: "Cost: " },
  5011. { text: "0 ", style: { "textColor": 0x18fefe } },
  5012. { text: "0 ", style: { "textColor": 0xffff00 } },
  5013. { text: "0 ", style: { "textColor": 0xff0000 } }
  5014. ];
  5015. };
  5016. NativeFps.prototype.addLog = function () {
  5017. var text = new egret.TextField();
  5018. text.size = this.fontSize;
  5019. text.textColor = this.fontColor;
  5020. text.x = 4;
  5021. this.addChild(text);
  5022. this.textLog = text;
  5023. };
  5024. ;
  5025. NativeFps.prototype.update = function (datas) {
  5026. this.arrFps.push(datas.fps);
  5027. var fpsTotal = 0;
  5028. var lenFps = this.arrFps.length;
  5029. if (lenFps > 101) {
  5030. lenFps = 101;
  5031. this.arrFps.shift();
  5032. }
  5033. var fpsMin = this.arrFps[0];
  5034. var fpsMax = this.arrFps[0];
  5035. for (var i = 0; i < lenFps; i++) {
  5036. var num = this.arrFps[i];
  5037. fpsTotal += num;
  5038. if (num < fpsMin)
  5039. fpsMin = num;
  5040. else if (num > fpsMax)
  5041. fpsMax = num;
  5042. }
  5043. this.textFps.textFlow = [
  5044. { text: datas.fps + " FPS " + egret.Capabilities.renderMode + "\n" },
  5045. { text: "min" + fpsMin + " max" + fpsMax + " avg" + Math.floor(fpsTotal / lenFps) + "\n" },
  5046. { text: "Draw: " + datas.draw + "\nDirty: " + datas.dirty + "%\n" },
  5047. { text: "Cost: " },
  5048. { text: datas.costTicker + " ", style: { "textColor": 0x18fefe } },
  5049. { text: datas.costDirty + " ", style: { "textColor": 0xffff00 } },
  5050. { text: datas.costRender + " ", style: { "textColor": 0xff0000 } }
  5051. ];
  5052. this.updateLayout();
  5053. };
  5054. ;
  5055. NativeFps.prototype.updateInfo = function (info) {
  5056. var fpsHeight = 0;
  5057. if (this.showFps) {
  5058. fpsHeight = this.textFps.height;
  5059. this.textLog.y = fpsHeight + 4;
  5060. }
  5061. this.arrLog.push(info);
  5062. this.textLog.text = this.arrLog.join('\n');
  5063. if (this._stage.stageHeight > 0) {
  5064. if (this.textLog.textWidth > this._stage.stageWidth - 20 - this.panelX) {
  5065. this.textLog.width = this._stage.stageWidth - 20 - this.panelX;
  5066. }
  5067. while (this.textLog.textHeight > this._stage.stageHeight - fpsHeight - 20 - this.panelY) {
  5068. this.arrLog.shift();
  5069. this.textLog.text = this.arrLog.join("\n");
  5070. }
  5071. }
  5072. this.updateLayout();
  5073. };
  5074. NativeFps.prototype.updateLayout = function () {
  5075. if (egret.Capabilities.runtimeType == egret.RuntimeType.NATIVE) {
  5076. return;
  5077. }
  5078. var g = this.shape.$graphics;
  5079. g.clear();
  5080. g.beginFill(0x000000, this.bgAlpha);
  5081. g.drawRect(0, 0, this.width + 8, this.height + 8);
  5082. g.endFill();
  5083. };
  5084. return NativeFps;
  5085. }(egret.Sprite));
  5086. native.NativeFps = NativeFps;
  5087. __reflect(NativeFps.prototype, "egret.native.NativeFps", ["egret.FPSDisplay"]);
  5088. egret.FPSDisplay = NativeFps;
  5089. })(native = egret.native || (egret.native = {}));
  5090. })(egret || (egret = {}));
  5091. //////////////////////////////////////////////////////////////////////////////////////
  5092. //
  5093. // Copyright (c) 2014-present, Egret Technology.
  5094. // All rights reserved.
  5095. // Redistribution and use in source and binary forms, with or without
  5096. // modification, are permitted provided that the following conditions are met:
  5097. //
  5098. // * Redistributions of source code must retain the above copyright
  5099. // notice, this list of conditions and the following disclaimer.
  5100. // * Redistributions in binary form must reproduce the above copyright
  5101. // notice, this list of conditions and the following disclaimer in the
  5102. // documentation and/or other materials provided with the distribution.
  5103. // * Neither the name of the Egret nor the
  5104. // names of its contributors may be used to endorse or promote products
  5105. // derived from this software without specific prior written permission.
  5106. //
  5107. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5108. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5109. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5110. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5111. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5112. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5113. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5114. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5115. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5116. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5117. //
  5118. //////////////////////////////////////////////////////////////////////////////////////
  5119. var egret;
  5120. (function (egret) {
  5121. var native;
  5122. (function (native) {
  5123. if (true) {
  5124. function setLogLevel(logType) {
  5125. egret_native.loglevel(logType);
  5126. }
  5127. Object.defineProperty(egret.Logger, "logLevel", {
  5128. set: setLogLevel,
  5129. enumerable: true,
  5130. configurable: true
  5131. });
  5132. }
  5133. })(native = egret.native || (egret.native = {}));
  5134. })(egret || (egret = {}));
  5135. //////////////////////////////////////////////////////////////////////////////////////
  5136. //
  5137. // Copyright (c) 2014-present, Egret Technology.
  5138. // All rights reserved.
  5139. // Redistribution and use in source and binary forms, with or without
  5140. // modification, are permitted provided that the following conditions are met:
  5141. //
  5142. // * Redistributions of source code must retain the above copyright
  5143. // notice, this list of conditions and the following disclaimer.
  5144. // * Redistributions in binary form must reproduce the above copyright
  5145. // notice, this list of conditions and the following disclaimer in the
  5146. // documentation and/or other materials provided with the distribution.
  5147. // * Neither the name of the Egret nor the
  5148. // names of its contributors may be used to endorse or promote products
  5149. // derived from this software without specific prior written permission.
  5150. //
  5151. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5152. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5153. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5154. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5155. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5156. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5157. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5158. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5159. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5160. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5161. //
  5162. //////////////////////////////////////////////////////////////////////////////////////
  5163. var egret;
  5164. (function (egret) {
  5165. var native;
  5166. (function (native) {
  5167. var callBackDic = {};
  5168. /**
  5169. * @private
  5170. */
  5171. var NativeExternalInterface = (function () {
  5172. function NativeExternalInterface() {
  5173. }
  5174. NativeExternalInterface.call = function (functionName, value) {
  5175. var data = {};
  5176. data.functionName = functionName;
  5177. data.value = value;
  5178. egret_native.sendInfoToPlugin(JSON.stringify(data));
  5179. };
  5180. NativeExternalInterface.addCallback = function (functionName, listener) {
  5181. callBackDic[functionName] = listener;
  5182. };
  5183. return NativeExternalInterface;
  5184. }());
  5185. native.NativeExternalInterface = NativeExternalInterface;
  5186. __reflect(NativeExternalInterface.prototype, "egret.native.NativeExternalInterface", ["egret.ExternalInterface"]);
  5187. /**
  5188. * @private
  5189. * @param info
  5190. */
  5191. function onReceivedPluginInfo(info) {
  5192. var data = JSON.parse(info);
  5193. var functionName = data.functionName;
  5194. var listener = callBackDic[functionName];
  5195. if (listener) {
  5196. var value = data.value;
  5197. listener.call(null, value);
  5198. }
  5199. else {
  5200. egret.$warn(1050, functionName);
  5201. }
  5202. }
  5203. egret.ExternalInterface = NativeExternalInterface;
  5204. egret_native.receivedPluginInfo = onReceivedPluginInfo;
  5205. })(native = egret.native || (egret.native = {}));
  5206. })(egret || (egret = {}));
  5207. //////////////////////////////////////////////////////////////////////////////////////
  5208. //
  5209. // Copyright (c) 2014-present, Egret Technology.
  5210. // All rights reserved.
  5211. // Redistribution and use in source and binary forms, with or without
  5212. // modification, are permitted provided that the following conditions are met:
  5213. //
  5214. // * Redistributions of source code must retain the above copyright
  5215. // notice, this list of conditions and the following disclaimer.
  5216. // * Redistributions in binary form must reproduce the above copyright
  5217. // notice, this list of conditions and the following disclaimer in the
  5218. // documentation and/or other materials provided with the distribution.
  5219. // * Neither the name of the Egret nor the
  5220. // names of its contributors may be used to endorse or promote products
  5221. // derived from this software without specific prior written permission.
  5222. //
  5223. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5224. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5225. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5226. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5227. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5228. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5229. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5230. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5231. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5232. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5233. //
  5234. //////////////////////////////////////////////////////////////////////////////////////
  5235. var egret;
  5236. (function (egret) {
  5237. var native;
  5238. (function (native) {
  5239. /**
  5240. * @private
  5241. * @inheritDoc
  5242. */
  5243. var NativeSound = (function (_super) {
  5244. __extends(NativeSound, _super);
  5245. /**
  5246. * @private
  5247. * @inheritDoc
  5248. */
  5249. function NativeSound() {
  5250. var _this = _super.call(this) || this;
  5251. /**
  5252. * @private
  5253. */
  5254. _this.loaded = false;
  5255. return _this;
  5256. }
  5257. Object.defineProperty(NativeSound.prototype, "length", {
  5258. get: function () {
  5259. if (this.originAudio) {
  5260. return this.originAudio.duration;
  5261. }
  5262. throw new Error("sound not loaded!");
  5263. //return 0;
  5264. },
  5265. enumerable: true,
  5266. configurable: true
  5267. });
  5268. /**
  5269. * @inheritDoc
  5270. */
  5271. NativeSound.prototype.load = function (url) {
  5272. var self = this;
  5273. this.url = url;
  5274. if (true && !url) {
  5275. egret.$error(3002);
  5276. }
  5277. var audio = new Audio(url);
  5278. audio.addEventListener("canplaythrough", onCanPlay);
  5279. audio.addEventListener("error", onAudioError);
  5280. this.originAudio = audio;
  5281. if (!egret_native.isFileExists(url)) {
  5282. download();
  5283. }
  5284. else {
  5285. onAudioLoaded();
  5286. }
  5287. function download() {
  5288. var promise = egret.PromiseObject.create();
  5289. promise.onSuccessFunc = onAudioLoaded;
  5290. promise.onErrorFunc = onAudioError;
  5291. egret_native.download(url, url, promise);
  5292. }
  5293. function onAudioLoaded() {
  5294. audio.load();
  5295. NativeSound.$recycle(url, audio);
  5296. }
  5297. function onCanPlay() {
  5298. removeListeners();
  5299. self.loaded = true;
  5300. self.dispatchEventWith(egret.Event.COMPLETE);
  5301. }
  5302. function onAudioError() {
  5303. removeListeners();
  5304. self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  5305. }
  5306. function removeListeners() {
  5307. audio.removeEventListener("canplaythrough", onCanPlay);
  5308. audio.removeEventListener("error", onAudioError);
  5309. }
  5310. };
  5311. /**
  5312. * @inheritDoc
  5313. */
  5314. NativeSound.prototype.play = function (startTime, loops) {
  5315. startTime = +startTime || 0;
  5316. loops = +loops || 0;
  5317. if (true && this.loaded == false) {
  5318. egret.$error(1049);
  5319. }
  5320. var audio = NativeSound.$pop(this.url);
  5321. if (audio == null) {
  5322. audio = new Audio(this.url);
  5323. }
  5324. else {
  5325. }
  5326. audio.autoplay = true;
  5327. var channel = new native.NativeSoundChannel(audio);
  5328. channel.$url = this.url;
  5329. channel.$loops = loops;
  5330. channel.$startTime = startTime;
  5331. channel.$play();
  5332. egret.sys.$pushSoundChannel(channel);
  5333. return channel;
  5334. };
  5335. /**
  5336. * @inheritDoc
  5337. */
  5338. NativeSound.prototype.close = function () {
  5339. if (this.loaded == false && this.originAudio)
  5340. this.originAudio.src = "";
  5341. if (this.originAudio)
  5342. this.originAudio = null;
  5343. NativeSound.$clear(this.url);
  5344. };
  5345. NativeSound.$clear = function (url) {
  5346. var array = NativeSound.audios[url];
  5347. if (array) {
  5348. array.length = 0;
  5349. }
  5350. };
  5351. NativeSound.$pop = function (url) {
  5352. var array = NativeSound.audios[url];
  5353. if (array && array.length > 0) {
  5354. return array.pop();
  5355. }
  5356. return null;
  5357. };
  5358. NativeSound.$recycle = function (url, audio) {
  5359. var array = NativeSound.audios[url];
  5360. if (NativeSound.audios[url] == null) {
  5361. array = NativeSound.audios[url] = [];
  5362. }
  5363. array.push(audio);
  5364. };
  5365. return NativeSound;
  5366. }(egret.EventDispatcher));
  5367. /**
  5368. * @language en_US
  5369. * Background music
  5370. * @version Egret 2.4
  5371. * @platform Web,Native
  5372. */
  5373. /**
  5374. * @language zh_CN
  5375. * 背景音乐
  5376. * @version Egret 2.4
  5377. * @platform Web,Native
  5378. */
  5379. NativeSound.MUSIC = "music";
  5380. /**
  5381. * @language en_US
  5382. * EFFECT
  5383. * @version Egret 2.4
  5384. * @platform Web,Native
  5385. */
  5386. /**
  5387. * @language zh_CN
  5388. * 音效
  5389. * @version Egret 2.4
  5390. * @platform Web,Native
  5391. */
  5392. NativeSound.EFFECT = "effect";
  5393. /**
  5394. * @private
  5395. */
  5396. NativeSound.audios = {};
  5397. native.NativeSound = NativeSound;
  5398. __reflect(NativeSound.prototype, "egret.native.NativeSound", ["egret.Sound"]);
  5399. if (__global.Audio) {
  5400. egret.Sound = NativeSound;
  5401. }
  5402. })(native = egret.native || (egret.native = {}));
  5403. })(egret || (egret = {}));
  5404. //////////////////////////////////////////////////////////////////////////////////////
  5405. //
  5406. // Copyright (c) 2014-present, Egret Technology.
  5407. // All rights reserved.
  5408. // Redistribution and use in source and binary forms, with or without
  5409. // modification, are permitted provided that the following conditions are met:
  5410. //
  5411. // * Redistributions of source code must retain the above copyright
  5412. // notice, this list of conditions and the following disclaimer.
  5413. // * Redistributions in binary form must reproduce the above copyright
  5414. // notice, this list of conditions and the following disclaimer in the
  5415. // documentation and/or other materials provided with the distribution.
  5416. // * Neither the name of the Egret nor the
  5417. // names of its contributors may be used to endorse or promote products
  5418. // derived from this software without specific prior written permission.
  5419. //
  5420. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5421. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5422. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5423. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5424. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5425. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5426. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5427. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5428. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5429. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5430. //
  5431. //////////////////////////////////////////////////////////////////////////////////////
  5432. var egret;
  5433. (function (egret) {
  5434. var native;
  5435. (function (native) {
  5436. /**
  5437. * @private
  5438. * @inheritDoc
  5439. */
  5440. var NativeSoundChannel = (function (_super) {
  5441. __extends(NativeSoundChannel, _super);
  5442. /**
  5443. * @private
  5444. */
  5445. function NativeSoundChannel(audio) {
  5446. var _this = _super.call(this) || this;
  5447. /**
  5448. * @private
  5449. */
  5450. _this.$startTime = 0;
  5451. /**
  5452. * @private
  5453. */
  5454. _this.audio = null;
  5455. //声音是否已经播放完成
  5456. _this.isStopped = false;
  5457. /**
  5458. * @private
  5459. */
  5460. _this.onPlayEnd = function () {
  5461. if (_this.$loops == 1) {
  5462. _this.stop();
  5463. _this.dispatchEventWith(egret.Event.SOUND_COMPLETE);
  5464. return;
  5465. }
  5466. if (_this.$loops > 0) {
  5467. _this.$loops--;
  5468. }
  5469. /////////////
  5470. //this.audio.load();
  5471. _this.$play();
  5472. };
  5473. _this.$volume = 1;
  5474. audio.addEventListener("ended", _this.onPlayEnd);
  5475. _this.audio = audio;
  5476. return _this;
  5477. }
  5478. NativeSoundChannel.prototype.$play = function () {
  5479. if (this.isStopped) {
  5480. egret.$error(1036);
  5481. return;
  5482. }
  5483. try {
  5484. this.audio.currentTime = this.$startTime;
  5485. }
  5486. catch (e) {
  5487. }
  5488. finally {
  5489. this.audio.volume = this.$volume;
  5490. this.audio.play();
  5491. }
  5492. };
  5493. /**
  5494. * @private
  5495. * @inheritDoc
  5496. */
  5497. NativeSoundChannel.prototype.stop = function () {
  5498. if (!this.audio)
  5499. return;
  5500. if (!this.isStopped) {
  5501. egret.sys.$popSoundChannel(this);
  5502. }
  5503. this.isStopped = true;
  5504. var audio = this.audio;
  5505. audio.pause();
  5506. audio.removeEventListener("ended", this.onPlayEnd);
  5507. this.audio = null;
  5508. native.NativeSound.$recycle(this.$url, audio);
  5509. };
  5510. Object.defineProperty(NativeSoundChannel.prototype, "volume", {
  5511. /**
  5512. * @private
  5513. * @inheritDoc
  5514. */
  5515. get: function () {
  5516. return this.$volume;
  5517. },
  5518. /**
  5519. * @inheritDoc
  5520. */
  5521. set: function (value) {
  5522. if (this.isStopped) {
  5523. egret.$error(1036);
  5524. return;
  5525. }
  5526. this.$volume = value;
  5527. if (!this.audio)
  5528. return;
  5529. this.audio.volume = value;
  5530. },
  5531. enumerable: true,
  5532. configurable: true
  5533. });
  5534. Object.defineProperty(NativeSoundChannel.prototype, "position", {
  5535. /**
  5536. * @private
  5537. * @inheritDoc
  5538. */
  5539. get: function () {
  5540. if (!this.audio)
  5541. return 0;
  5542. return this.audio.currentTime;
  5543. },
  5544. enumerable: true,
  5545. configurable: true
  5546. });
  5547. return NativeSoundChannel;
  5548. }(egret.EventDispatcher));
  5549. native.NativeSoundChannel = NativeSoundChannel;
  5550. __reflect(NativeSoundChannel.prototype, "egret.native.NativeSoundChannel", ["egret.SoundChannel", "egret.IEventDispatcher"]);
  5551. })(native = egret.native || (egret.native = {}));
  5552. })(egret || (egret = {}));
  5553. //////////////////////////////////////////////////////////////////////////////////////
  5554. //
  5555. // Copyright (c) 2014-present, Egret Technology.
  5556. // All rights reserved.
  5557. // Redistribution and use in source and binary forms, with or without
  5558. // modification, are permitted provided that the following conditions are met:
  5559. //
  5560. // * Redistributions of source code must retain the above copyright
  5561. // notice, this list of conditions and the following disclaimer.
  5562. // * Redistributions in binary form must reproduce the above copyright
  5563. // notice, this list of conditions and the following disclaimer in the
  5564. // documentation and/or other materials provided with the distribution.
  5565. // * Neither the name of the Egret nor the
  5566. // names of its contributors may be used to endorse or promote products
  5567. // derived from this software without specific prior written permission.
  5568. //
  5569. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5570. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5571. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5572. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5573. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5574. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5575. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5576. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5577. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5578. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5579. //
  5580. //////////////////////////////////////////////////////////////////////////////////////
  5581. var egret;
  5582. (function (egret) {
  5583. var native;
  5584. (function (native) {
  5585. /**
  5586. * @private
  5587. * @inheritDoc
  5588. */
  5589. var NaSound = (function (_super) {
  5590. __extends(NaSound, _super);
  5591. /**
  5592. * @private
  5593. * @inheritDoc
  5594. */
  5595. function NaSound() {
  5596. var _this = _super.call(this) || this;
  5597. /**
  5598. * @private
  5599. */
  5600. _this.loaded = false;
  5601. return _this;
  5602. }
  5603. Object.defineProperty(NaSound.prototype, "length", {
  5604. get: function () {
  5605. throw new Error("sound length not supported");
  5606. //return 0;
  5607. },
  5608. enumerable: true,
  5609. configurable: true
  5610. });
  5611. /**
  5612. * @inheritDoc
  5613. */
  5614. NaSound.prototype.load = function (url) {
  5615. var self = this;
  5616. this.url = url;
  5617. if (true && !url) {
  5618. egret.$error(3002);
  5619. }
  5620. if (!egret_native.isFileExists(url)) {
  5621. download();
  5622. }
  5623. else {
  5624. if (__global.setTimeout) {
  5625. __global.setTimeout(onLoadComplete, 0);
  5626. }
  5627. else {
  5628. egret.$callAsync(onLoadComplete, self);
  5629. }
  5630. }
  5631. function download() {
  5632. var promise = egret.PromiseObject.create();
  5633. promise.onSuccessFunc = onLoadComplete;
  5634. promise.onErrorFunc = function () {
  5635. egret.IOErrorEvent.dispatchIOErrorEvent(self);
  5636. };
  5637. egret_native.download(url, url, promise);
  5638. }
  5639. function onLoadComplete() {
  5640. self.loaded = true;
  5641. self.preload();
  5642. }
  5643. };
  5644. NaSound.prototype.preload = function () {
  5645. var self = this;
  5646. if (self.type == egret.Sound.EFFECT) {
  5647. var promise = new egret.PromiseObject();
  5648. promise.onSuccessFunc = function (soundId) {
  5649. self.dispatchEventWith(egret.Event.COMPLETE);
  5650. };
  5651. egret_native.Audio.preloadEffectAsync(self.url, promise);
  5652. }
  5653. else {
  5654. self.dispatchEventWith(egret.Event.COMPLETE);
  5655. }
  5656. };
  5657. /**
  5658. * @inheritDoc
  5659. */
  5660. NaSound.prototype.play = function (startTime, loops) {
  5661. startTime = +startTime || 0;
  5662. loops = +loops || 0;
  5663. if (true && this.loaded == false) {
  5664. egret.$error(1049);
  5665. }
  5666. var channel = new native.NaSoundChannel();
  5667. channel.$url = this.url;
  5668. channel.$loops = loops;
  5669. channel.$type = this.type;
  5670. channel.$startTime = startTime;
  5671. channel.$play();
  5672. egret.sys.$pushSoundChannel(channel);
  5673. return channel;
  5674. };
  5675. /**
  5676. * @inheritDoc
  5677. */
  5678. NaSound.prototype.close = function () {
  5679. };
  5680. return NaSound;
  5681. }(egret.EventDispatcher));
  5682. /**
  5683. * @language en_US
  5684. * Background music
  5685. * @version Egret 2.4
  5686. * @platform Web,Native
  5687. */
  5688. /**
  5689. * @language zh_CN
  5690. * 背景音乐
  5691. * @version Egret 2.4
  5692. * @platform Web,Native
  5693. */
  5694. NaSound.MUSIC = "music";
  5695. /**
  5696. * @language en_US
  5697. * EFFECT
  5698. * @version Egret 2.4
  5699. * @platform Web,Native
  5700. */
  5701. /**
  5702. * @language zh_CN
  5703. * 音效
  5704. * @version Egret 2.4
  5705. * @platform Web,Native
  5706. */
  5707. NaSound.EFFECT = "effect";
  5708. native.NaSound = NaSound;
  5709. __reflect(NaSound.prototype, "egret.native.NaSound", ["egret.Sound"]);
  5710. if (!__global.Audio) {
  5711. egret.Sound = NaSound;
  5712. }
  5713. })(native = egret.native || (egret.native = {}));
  5714. })(egret || (egret = {}));
  5715. //////////////////////////////////////////////////////////////////////////////////////
  5716. //
  5717. // Copyright (c) 2014-present, Egret Technology.
  5718. // All rights reserved.
  5719. // Redistribution and use in source and binary forms, with or without
  5720. // modification, are permitted provided that the following conditions are met:
  5721. //
  5722. // * Redistributions of source code must retain the above copyright
  5723. // notice, this list of conditions and the following disclaimer.
  5724. // * Redistributions in binary form must reproduce the above copyright
  5725. // notice, this list of conditions and the following disclaimer in the
  5726. // documentation and/or other materials provided with the distribution.
  5727. // * Neither the name of the Egret nor the
  5728. // names of its contributors may be used to endorse or promote products
  5729. // derived from this software without specific prior written permission.
  5730. //
  5731. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5732. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5733. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5734. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5735. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5736. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5737. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5738. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5739. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5740. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5741. //
  5742. //////////////////////////////////////////////////////////////////////////////////////
  5743. var egret;
  5744. (function (egret) {
  5745. var native;
  5746. (function (native) {
  5747. /**
  5748. * @private
  5749. * @inheritDoc
  5750. */
  5751. var NaSoundChannel = (function (_super) {
  5752. __extends(NaSoundChannel, _super);
  5753. /**
  5754. * @private
  5755. */
  5756. function NaSoundChannel() {
  5757. var _this = _super.call(this) || this;
  5758. /**
  5759. * @private
  5760. */
  5761. _this.$startTime = 0;
  5762. //声音是否已经播放完成
  5763. _this.isStopped = false;
  5764. /**
  5765. * @private
  5766. */
  5767. _this._startTime = 0;
  5768. return _this;
  5769. }
  5770. NaSoundChannel.prototype.$play = function () {
  5771. this.isStopped = false;
  5772. if (this.$type == egret.Sound.EFFECT) {
  5773. this._effectId = egret_native.Audio.playEffect(this.$url, this.$loops != 1);
  5774. }
  5775. else {
  5776. NaSoundChannel.currentPath = this.$url;
  5777. egret_native.Audio.playBackgroundMusic(this.$url, this.$loops != 1);
  5778. }
  5779. this._startTime = Date.now();
  5780. };
  5781. /**
  5782. * @private
  5783. * @inheritDoc
  5784. */
  5785. NaSoundChannel.prototype.stop = function () {
  5786. if (!this.isStopped) {
  5787. egret.sys.$popSoundChannel(this);
  5788. }
  5789. this.isStopped = true;
  5790. if (this.$type == egret.Sound.EFFECT) {
  5791. if (this._effectId) {
  5792. egret_native.Audio.stopEffect(this._effectId);
  5793. this._effectId = null;
  5794. }
  5795. }
  5796. else {
  5797. if (this.$url == NaSoundChannel.currentPath) {
  5798. egret_native.Audio.stopBackgroundMusic(false);
  5799. }
  5800. }
  5801. };
  5802. Object.defineProperty(NaSoundChannel.prototype, "volume", {
  5803. /**
  5804. * @private
  5805. * @inheritDoc
  5806. */
  5807. get: function () {
  5808. if (this.$type == egret.Sound.EFFECT) {
  5809. return egret_native.Audio.getEffectsVolume();
  5810. }
  5811. else {
  5812. return egret_native.Audio.getBackgroundMusicVolume();
  5813. }
  5814. return 1;
  5815. },
  5816. /**
  5817. * @inheritDoc
  5818. */
  5819. set: function (value) {
  5820. if (this.$type == egret.Sound.EFFECT) {
  5821. egret_native.Audio.setEffectsVolume(value);
  5822. }
  5823. else {
  5824. egret_native.Audio.setBackgroundMusicVolume(value);
  5825. }
  5826. },
  5827. enumerable: true,
  5828. configurable: true
  5829. });
  5830. Object.defineProperty(NaSoundChannel.prototype, "position", {
  5831. /**
  5832. * @private
  5833. * @inheritDoc
  5834. */
  5835. get: function () {
  5836. return (Date.now() - this._startTime) / 1000;
  5837. },
  5838. enumerable: true,
  5839. configurable: true
  5840. });
  5841. return NaSoundChannel;
  5842. }(egret.EventDispatcher));
  5843. native.NaSoundChannel = NaSoundChannel;
  5844. __reflect(NaSoundChannel.prototype, "egret.native.NaSoundChannel", ["egret.SoundChannel", "egret.IEventDispatcher"]);
  5845. })(native = egret.native || (egret.native = {}));
  5846. })(egret || (egret = {}));
  5847. //////////////////////////////////////////////////////////////////////////////////////
  5848. //
  5849. // Copyright (c) 2014-present, Egret Technology.
  5850. // All rights reserved.
  5851. // Redistribution and use in source and binary forms, with or without
  5852. // modification, are permitted provided that the following conditions are met:
  5853. //
  5854. // * Redistributions of source code must retain the above copyright
  5855. // notice, this list of conditions and the following disclaimer.
  5856. // * Redistributions in binary form must reproduce the above copyright
  5857. // notice, this list of conditions and the following disclaimer in the
  5858. // documentation and/or other materials provided with the distribution.
  5859. // * Neither the name of the Egret nor the
  5860. // names of its contributors may be used to endorse or promote products
  5861. // derived from this software without specific prior written permission.
  5862. //
  5863. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  5864. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  5865. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  5866. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  5867. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5868. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  5869. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5870. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5871. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5872. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5873. //
  5874. //////////////////////////////////////////////////////////////////////////////////////
  5875. var egret;
  5876. (function (egret) {
  5877. var native;
  5878. (function (native) {
  5879. /**
  5880. * @private
  5881. * @inheritDoc
  5882. */
  5883. var NativeVideo = (function (_super) {
  5884. __extends(NativeVideo, _super);
  5885. /**
  5886. * @private
  5887. * @inheritDoc
  5888. */
  5889. function NativeVideo(url, cache) {
  5890. if (cache === void 0) { cache = true; }
  5891. var _this = _super.call(this) || this;
  5892. /**
  5893. * @private
  5894. */
  5895. _this.loaded = false;
  5896. /**
  5897. * @private
  5898. */
  5899. _this.loading = false;
  5900. /**
  5901. * @private
  5902. * */
  5903. _this.loop = false;
  5904. /**
  5905. * @private
  5906. * */
  5907. _this.isPlayed = false;
  5908. /**
  5909. * @private
  5910. * */
  5911. _this.firstPlay = true;
  5912. /**
  5913. * @inheritDoc
  5914. */
  5915. _this.src = "";
  5916. _this._fullscreen = true;
  5917. _this._bitmapData = null;
  5918. /**
  5919. * @inheritDoc
  5920. */
  5921. _this.paused = false;
  5922. /**
  5923. * @private
  5924. */
  5925. _this.isAddToStage = false;
  5926. /**
  5927. * @private
  5928. */
  5929. _this.heightSet = 0;
  5930. /**
  5931. * @private
  5932. */
  5933. _this.widthSet = 0;
  5934. _this.$renderNode = new egret.sys.BitmapNode();
  5935. _this.cache = cache;
  5936. if (!__global.Video) {
  5937. egret.$error(1044);
  5938. }
  5939. if (url) {
  5940. _this.load(url, cache);
  5941. }
  5942. return _this;
  5943. }
  5944. /**
  5945. * @inheritDoc
  5946. */
  5947. NativeVideo.prototype.load = function (url, cache) {
  5948. if (cache === void 0) { cache = true; }
  5949. if (true && !url) {
  5950. egret.$error(3002);
  5951. return;
  5952. }
  5953. if (this.loading) {
  5954. return;
  5955. }
  5956. if (url.indexOf('/') == 0) {
  5957. url = url.slice(1, url.length);
  5958. }
  5959. this.src = url;
  5960. this.loading = true;
  5961. this.loaded = false;
  5962. if (cache && !egret_native.isFileExists(url)) {
  5963. var self_1 = this;
  5964. var promise = egret.PromiseObject.create();
  5965. promise.onSuccessFunc = function () {
  5966. self_1.loadEnd();
  5967. };
  5968. promise.onErrorFunc = function () {
  5969. egret.$warn(1048);
  5970. self_1.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  5971. };
  5972. egret_native.download(url, url, promise);
  5973. }
  5974. else {
  5975. this.loadEnd();
  5976. }
  5977. };
  5978. /**
  5979. * @private
  5980. * */
  5981. NativeVideo.prototype.loadEnd = function () {
  5982. var video = new __global.Video(this.src);
  5983. video['setVideoRect'](0, 0, 1, 1);
  5984. video['setKeepRatio'](false);
  5985. video.addEventListener("canplaythrough", onCanPlay);
  5986. video.addEventListener("error", onVideoError);
  5987. video.addEventListener("playing", onPlaying);
  5988. video.load();
  5989. var self = this;
  5990. function onCanPlay() {
  5991. video['setVideoRect'](0, 0, 1, 1);
  5992. video.play();
  5993. }
  5994. function onPlaying() {
  5995. video['setVideoRect'](0, 0, 1, 1);
  5996. __global.setTimeout(function () {
  5997. video.pause();
  5998. if (self._fullscreen) {
  5999. video.fullScreen = true;
  6000. }
  6001. video.currentTime = 0;
  6002. self.originVideo = video;
  6003. self.loaded = true;
  6004. self.loading = false;
  6005. removeListeners();
  6006. self.dispatchEventWith(egret.Event.COMPLETE);
  6007. video.addEventListener('pause', function () {
  6008. self.paused = true;
  6009. });
  6010. video.addEventListener('playing', function () {
  6011. self.paused = false;
  6012. });
  6013. video.addEventListener('ended', function () {
  6014. self.dispatchEventWith(egret.Event.ENDED);
  6015. if (self.loop) {
  6016. self.play(0, true);
  6017. }
  6018. });
  6019. }, 1);
  6020. }
  6021. function onVideoError() {
  6022. removeListeners();
  6023. self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  6024. }
  6025. function removeListeners() {
  6026. video.removeEventListener("canplaythrough", onCanPlay);
  6027. video.removeEventListener("error", onVideoError);
  6028. video.removeEventListener("playing", onPlaying);
  6029. }
  6030. };
  6031. /**
  6032. * @inheritDoc
  6033. */
  6034. NativeVideo.prototype.play = function (startTime, loop) {
  6035. var _this = this;
  6036. if (loop === void 0) { loop = false; }
  6037. this.loop = loop;
  6038. if (!this.loaded) {
  6039. this.load(this.src);
  6040. this.once(egret.Event.COMPLETE, function (e) { return _this.play(startTime, loop); }, this);
  6041. return;
  6042. }
  6043. var haveStartTime = false;
  6044. if (startTime != undefined && startTime != this.originVideo.currentTime) {
  6045. this.originVideo.currentTime = startTime || 0;
  6046. haveStartTime = true;
  6047. }
  6048. this.startPlay(haveStartTime);
  6049. };
  6050. /**
  6051. * @private
  6052. * */
  6053. NativeVideo.prototype.startPlay = function (haveStartTime) {
  6054. if (haveStartTime === void 0) { haveStartTime = false; }
  6055. if (!this.isAddToStage || !this.loaded) {
  6056. return;
  6057. }
  6058. this.firstPlay = false;
  6059. this.setVideoSize();
  6060. this.isPlayed = true;
  6061. if (!haveStartTime && this.paused && this.position != 0) {
  6062. this.originVideo['resume']();
  6063. }
  6064. else {
  6065. this.originVideo.play();
  6066. }
  6067. egret.startTick(this.markDirty, this);
  6068. };
  6069. /**
  6070. * @private
  6071. * */
  6072. NativeVideo.prototype.stopPlay = function () {
  6073. egret.stopTick(this.markDirty, this);
  6074. if (this.isPlayed) {
  6075. this.isPlayed = false;
  6076. this.originVideo.pause();
  6077. }
  6078. };
  6079. /**
  6080. * @inheritDoc
  6081. */
  6082. NativeVideo.prototype.close = function () {
  6083. if (this.originVideo) {
  6084. this.originVideo['destroy']();
  6085. }
  6086. this.loaded = false;
  6087. this.loading = false;
  6088. this.originVideo = null;
  6089. this.loop = false;
  6090. this.src = null;
  6091. };
  6092. Object.defineProperty(NativeVideo.prototype, "poster", {
  6093. /**
  6094. * @inheritDoc
  6095. */
  6096. get: function () {
  6097. return this.posterUrl;
  6098. },
  6099. /**
  6100. * @inheritDoc
  6101. */
  6102. set: function (value) {
  6103. var _this = this;
  6104. this.posterUrl = value;
  6105. var loader = new native.NativeImageLoader();
  6106. loader.load(value);
  6107. loader.addEventListener(egret.Event.COMPLETE, function () {
  6108. _this.posterData = loader.data;
  6109. _this.markDirty();
  6110. _this.$invalidateContentBounds();
  6111. }, this);
  6112. },
  6113. enumerable: true,
  6114. configurable: true
  6115. });
  6116. Object.defineProperty(NativeVideo.prototype, "fullscreen", {
  6117. /**
  6118. * @inheritDoc
  6119. */
  6120. get: function () {
  6121. if (this.originVideo) {
  6122. return this.originVideo['fullScreen'];
  6123. }
  6124. return this._fullscreen;
  6125. },
  6126. /**
  6127. * @inheritDoc
  6128. */
  6129. set: function (value) {
  6130. this._fullscreen = value;
  6131. if (this.originVideo) {
  6132. this.originVideo['fullScreen'] = value;
  6133. }
  6134. },
  6135. enumerable: true,
  6136. configurable: true
  6137. });
  6138. Object.defineProperty(NativeVideo.prototype, "volume", {
  6139. /**
  6140. * @inheritDoc
  6141. */
  6142. get: function () {
  6143. if (!this.loaded)
  6144. return 0;
  6145. return this.originVideo.volume;
  6146. },
  6147. /**
  6148. * @inheritDoc
  6149. */
  6150. set: function (value) {
  6151. if (!this.loaded)
  6152. return;
  6153. this.originVideo.volume = value;
  6154. },
  6155. enumerable: true,
  6156. configurable: true
  6157. });
  6158. Object.defineProperty(NativeVideo.prototype, "position", {
  6159. /**
  6160. * @inheritDoc
  6161. */
  6162. get: function () {
  6163. return this.originVideo.currentTime;
  6164. },
  6165. /**
  6166. * @inheritDoc
  6167. */
  6168. set: function (value) {
  6169. if (this.loaded) {
  6170. this.originVideo.currentTime = value;
  6171. }
  6172. },
  6173. enumerable: true,
  6174. configurable: true
  6175. });
  6176. /**
  6177. * @inheritDoc
  6178. */
  6179. NativeVideo.prototype.pause = function () {
  6180. this.originVideo.pause();
  6181. };
  6182. Object.defineProperty(NativeVideo.prototype, "bitmapData", {
  6183. /**
  6184. * @inheritDoc
  6185. */
  6186. get: function () {
  6187. return this._bitmapData;
  6188. },
  6189. enumerable: true,
  6190. configurable: true
  6191. });
  6192. Object.defineProperty(NativeVideo.prototype, "length", {
  6193. /**
  6194. * @inheritDoc
  6195. */
  6196. get: function () {
  6197. if (this.loaded) {
  6198. return this.originVideo.duration;
  6199. }
  6200. throw new Error("Video not loaded!");
  6201. //return 0;
  6202. },
  6203. enumerable: true,
  6204. configurable: true
  6205. });
  6206. /**
  6207. * @inheritDoc
  6208. */
  6209. NativeVideo.prototype.$onAddToStage = function (stage, nestLevel) {
  6210. this.isAddToStage = true;
  6211. if (this.originVideo) {
  6212. this.originVideo["setVideoVisible"](true);
  6213. }
  6214. this.$invalidate();
  6215. this.$invalidateContentBounds();
  6216. _super.prototype.$onAddToStage.call(this, stage, nestLevel);
  6217. };
  6218. /**
  6219. * @inheritDoc
  6220. */
  6221. NativeVideo.prototype.$onRemoveFromStage = function () {
  6222. this.isAddToStage = false;
  6223. if (this.originVideo) {
  6224. this.stopPlay();
  6225. this.originVideo["setVideoVisible"](false);
  6226. }
  6227. _super.prototype.$onRemoveFromStage.call(this);
  6228. };
  6229. /**
  6230. * @private
  6231. */
  6232. NativeVideo.prototype.getPlayWidth = function () {
  6233. if (!isNaN(this.widthSet)) {
  6234. return this.widthSet;
  6235. }
  6236. if (this.bitmapData) {
  6237. return this.bitmapData.width;
  6238. }
  6239. if (this.posterData) {
  6240. return this.posterData.width;
  6241. }
  6242. return NaN;
  6243. };
  6244. /**
  6245. * @private
  6246. */
  6247. NativeVideo.prototype.getPlayHeight = function () {
  6248. if (!isNaN(this.heightSet)) {
  6249. return this.heightSet;
  6250. }
  6251. if (this.bitmapData) {
  6252. return this.bitmapData.height;
  6253. }
  6254. if (this.posterData) {
  6255. return this.posterData.height;
  6256. }
  6257. return NaN;
  6258. };
  6259. /**
  6260. * @private
  6261. */
  6262. NativeVideo.prototype.$setHeight = function (value) {
  6263. this.heightSet = +value || 0;
  6264. this.setVideoSize();
  6265. this.$invalidate();
  6266. this.$invalidateContentBounds();
  6267. return _super.prototype.$setHeight.call(this, value);
  6268. };
  6269. /**
  6270. * @private
  6271. */
  6272. NativeVideo.prototype.$setWidth = function (value) {
  6273. this.widthSet = +value || 0;
  6274. this.setVideoSize();
  6275. this.$invalidate();
  6276. this.$invalidateContentBounds();
  6277. return _super.prototype.$setWidth.call(this, value);
  6278. };
  6279. /**
  6280. * @inheritDoc
  6281. */
  6282. NativeVideo.prototype.$setX = function (value) {
  6283. var result = _super.prototype.$setX.call(this, value);
  6284. this.setVideoSize();
  6285. return result;
  6286. };
  6287. /**
  6288. * @inheritDoc
  6289. */
  6290. NativeVideo.prototype.$setY = function (value) {
  6291. var result = _super.prototype.$setY.call(this, value);
  6292. this.setVideoSize();
  6293. return result;
  6294. };
  6295. /**
  6296. * @private
  6297. */
  6298. NativeVideo.prototype.setVideoSize = function () {
  6299. var video = this.originVideo;
  6300. if (video && !this.fullscreen) {
  6301. if (!this.firstPlay) {
  6302. video['setVideoRect'](this.x, this.y, this.widthSet, this.heightSet);
  6303. }
  6304. else {
  6305. video['setVideoRect'](this.x, this.y, 0, 0);
  6306. }
  6307. }
  6308. };
  6309. /**
  6310. * @private
  6311. */
  6312. NativeVideo.prototype.$measureContentBounds = function (bounds) {
  6313. var posterData = this.posterData;
  6314. if (posterData) {
  6315. bounds.setTo(0, 0, this.getPlayWidth(), this.getPlayHeight());
  6316. }
  6317. else {
  6318. bounds.setEmpty();
  6319. }
  6320. };
  6321. /**
  6322. * @private
  6323. */
  6324. NativeVideo.prototype.$render = function () {
  6325. var node = this.$renderNode;
  6326. var posterData = this.posterData;
  6327. var width = this.getPlayWidth();
  6328. var height = this.getPlayHeight();
  6329. if (width <= 0 || height <= 0) {
  6330. return;
  6331. }
  6332. if (!this.isPlayed && posterData) {
  6333. node.image = posterData;
  6334. node.drawImage(0, 0, posterData.width, posterData.height, 0, 0, width, height);
  6335. }
  6336. else if (this.isPlayed) {
  6337. this.setVideoSize();
  6338. }
  6339. };
  6340. NativeVideo.prototype.markDirty = function () {
  6341. this.$invalidate();
  6342. return true;
  6343. };
  6344. return NativeVideo;
  6345. }(egret.DisplayObject));
  6346. native.NativeVideo = NativeVideo;
  6347. __reflect(NativeVideo.prototype, "egret.native.NativeVideo", ["egret.Video"]);
  6348. if (__global.Video) {
  6349. egret.Video = NativeVideo;
  6350. }
  6351. else {
  6352. egret.$warn(1044);
  6353. }
  6354. })(native = egret.native || (egret.native = {}));
  6355. })(egret || (egret = {}));
  6356. //////////////////////////////////////////////////////////////////////////////////////
  6357. //
  6358. // Copyright (c) 2014-present, Egret Technology.
  6359. // All rights reserved.
  6360. // Redistribution and use in source and binary forms, with or without
  6361. // modification, are permitted provided that the following conditions are met:
  6362. //
  6363. // * Redistributions of source code must retain the above copyright
  6364. // notice, this list of conditions and the following disclaimer.
  6365. // * Redistributions in binary form must reproduce the above copyright
  6366. // notice, this list of conditions and the following disclaimer in the
  6367. // documentation and/or other materials provided with the distribution.
  6368. // * Neither the name of the Egret nor the
  6369. // names of its contributors may be used to endorse or promote products
  6370. // derived from this software without specific prior written permission.
  6371. //
  6372. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  6373. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  6374. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  6375. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  6376. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6377. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  6378. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6379. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6380. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6381. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6382. //
  6383. //////////////////////////////////////////////////////////////////////////////////////
  6384. var egret;
  6385. (function (egret) {
  6386. var localStorage;
  6387. (function (localStorage) {
  6388. var native;
  6389. (function (native) {
  6390. var filePath = "LocalStorage.local";
  6391. var localStorageData = {};
  6392. /**
  6393. * @private
  6394. *
  6395. * @param key
  6396. * @returns
  6397. */
  6398. function getItem(key) {
  6399. return localStorageData[key];
  6400. }
  6401. /**
  6402. * @private
  6403. *
  6404. * @param key
  6405. * @param value
  6406. * @returns
  6407. */
  6408. function setItem(key, value) {
  6409. if (value === undefined) {
  6410. value = "undefined";
  6411. }
  6412. else if (value === null) {
  6413. value = "null";
  6414. }
  6415. else {
  6416. value = value.toString();
  6417. }
  6418. localStorageData[key] = value;
  6419. try {
  6420. save();
  6421. return true;
  6422. }
  6423. catch (e) {
  6424. egret.$warn(1018, key, value);
  6425. return false;
  6426. }
  6427. }
  6428. /**
  6429. * @private
  6430. *
  6431. * @param key
  6432. */
  6433. function removeItem(key) {
  6434. delete localStorageData[key];
  6435. save();
  6436. }
  6437. /**
  6438. * @private
  6439. *
  6440. */
  6441. function clear() {
  6442. for (var key in localStorageData) {
  6443. delete localStorageData[key];
  6444. }
  6445. save();
  6446. }
  6447. /**
  6448. * @private
  6449. *
  6450. */
  6451. function save() {
  6452. egret_native.saveRecord(filePath, JSON.stringify(localStorageData));
  6453. }
  6454. if (egret_native.isRecordExists(filePath)) {
  6455. var str = egret_native.loadRecord(filePath);
  6456. try {
  6457. localStorageData = JSON.parse(str);
  6458. }
  6459. catch (e) {
  6460. localStorageData = {};
  6461. }
  6462. }
  6463. else {
  6464. localStorageData = {};
  6465. }
  6466. localStorage.getItem = getItem;
  6467. localStorage.setItem = setItem;
  6468. localStorage.removeItem = removeItem;
  6469. localStorage.clear = clear;
  6470. })(native = localStorage.native || (localStorage.native = {}));
  6471. })(localStorage = egret.localStorage || (egret.localStorage = {}));
  6472. })(egret || (egret = {}));
  6473. //////////////////////////////////////////////////////////////////////////////////////
  6474. //
  6475. // Copyright (c) 2014-present, Egret Technology.
  6476. // All rights reserved.
  6477. // Redistribution and use in source and binary forms, with or without
  6478. // modification, are permitted provided that the following conditions are met:
  6479. //
  6480. // * Redistributions of source code must retain the above copyright
  6481. // notice, this list of conditions and the following disclaimer.
  6482. // * Redistributions in binary form must reproduce the above copyright
  6483. // notice, this list of conditions and the following disclaimer in the
  6484. // documentation and/or other materials provided with the distribution.
  6485. // * Neither the name of the Egret nor the
  6486. // names of its contributors may be used to endorse or promote products
  6487. // derived from this software without specific prior written permission.
  6488. //
  6489. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  6490. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  6491. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  6492. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  6493. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6494. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  6495. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6496. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6497. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6498. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6499. //
  6500. //////////////////////////////////////////////////////////////////////////////////////
  6501. var egret;
  6502. (function (egret) {
  6503. var native;
  6504. (function (native) {
  6505. /**
  6506. * @private
  6507. */
  6508. var NativeHideHandler = (function (_super) {
  6509. __extends(NativeHideHandler, _super);
  6510. function NativeHideHandler(stage) {
  6511. var _this = _super.call(this) || this;
  6512. egret_native.pauseApp = function () {
  6513. //console.log("pauseApp");
  6514. stage.dispatchEvent(new egret.Event(egret.Event.DEACTIVATE));
  6515. egret_native.Audio.pauseBackgroundMusic();
  6516. egret_native.Audio.pauseAllEffects();
  6517. };
  6518. egret_native.resumeApp = function () {
  6519. //console.log("resumeApp");
  6520. stage.dispatchEvent(new egret.Event(egret.Event.ACTIVATE));
  6521. egret_native.Audio.resumeBackgroundMusic();
  6522. egret_native.Audio.resumeAllEffects();
  6523. };
  6524. return _this;
  6525. }
  6526. return NativeHideHandler;
  6527. }(egret.HashObject));
  6528. native.NativeHideHandler = NativeHideHandler;
  6529. __reflect(NativeHideHandler.prototype, "egret.native.NativeHideHandler");
  6530. })(native = egret.native || (egret.native = {}));
  6531. })(egret || (egret = {}));
  6532. //////////////////////////////////////////////////////////////////////////////////////
  6533. //
  6534. // Copyright (c) 2014-present, Egret Technology.
  6535. // All rights reserved.
  6536. // Redistribution and use in source and binary forms, with or without
  6537. // modification, are permitted provided that the following conditions are met:
  6538. //
  6539. // * Redistributions of source code must retain the above copyright
  6540. // notice, this list of conditions and the following disclaimer.
  6541. // * Redistributions in binary form must reproduce the above copyright
  6542. // notice, this list of conditions and the following disclaimer in the
  6543. // documentation and/or other materials provided with the distribution.
  6544. // * Neither the name of the Egret nor the
  6545. // names of its contributors may be used to endorse or promote products
  6546. // derived from this software without specific prior written permission.
  6547. //
  6548. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  6549. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  6550. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  6551. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  6552. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6553. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  6554. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6555. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6556. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6557. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6558. //
  6559. //////////////////////////////////////////////////////////////////////////////////////
  6560. var egret;
  6561. (function (egret) {
  6562. /**
  6563. * @private
  6564. * @version Egret 2.4
  6565. * @platform Web,Native
  6566. */
  6567. var NativeResourceLoader = (function (_super) {
  6568. __extends(NativeResourceLoader, _super);
  6569. function NativeResourceLoader() {
  6570. var _this = _super.apply(this, arguments) || this;
  6571. /**
  6572. * @private
  6573. */
  6574. _this._downCount = 0;
  6575. /**
  6576. * @private
  6577. */
  6578. _this._path = null;
  6579. /**
  6580. * @private
  6581. */
  6582. _this._bytesTotal = 0;
  6583. return _this;
  6584. }
  6585. /**
  6586. *
  6587. * @param path
  6588. * @param bytesTotal
  6589. * @version Egret 2.4
  6590. * @platform Web,Native
  6591. */
  6592. NativeResourceLoader.prototype.load = function (path, bytesTotal) {
  6593. this._downCount = 0;
  6594. this._path = path;
  6595. this._bytesTotal = bytesTotal;
  6596. this.reload();
  6597. };
  6598. /**
  6599. * @private
  6600. *
  6601. */
  6602. NativeResourceLoader.prototype.reload = function () {
  6603. if (this._downCount >= 3) {
  6604. this.downloadFileError();
  6605. return;
  6606. }
  6607. //if (egret_native.isRecordExists(this._path)) {//卡里
  6608. // this.loadOver();
  6609. // return;
  6610. //}
  6611. //else if (egret_native.isFileExists(this._path)){
  6612. // this.loadOver();
  6613. // return;
  6614. //}
  6615. //else {
  6616. this._downCount++;
  6617. var promise = egret.PromiseObject.create();
  6618. var self = this;
  6619. promise.onSuccessFunc = function () {
  6620. self.loadOver();
  6621. };
  6622. promise.onErrorFunc = function () {
  6623. self.reload();
  6624. };
  6625. promise.downloadingSizeFunc = function (bytesLoaded) {
  6626. self.downloadingProgress(bytesLoaded);
  6627. };
  6628. egret_native.download(this._path, this._path, promise);
  6629. //}
  6630. };
  6631. /**
  6632. * @private
  6633. *
  6634. * @param bytesLoaded
  6635. */
  6636. NativeResourceLoader.prototype.downloadingProgress = function (bytesLoaded) {
  6637. egret.ProgressEvent.dispatchProgressEvent(this, egret.ProgressEvent.PROGRESS, bytesLoaded, this._bytesTotal);
  6638. };
  6639. /**
  6640. * @private
  6641. *
  6642. */
  6643. NativeResourceLoader.prototype.downloadFileError = function () {
  6644. this.dispatchEvent(new egret.Event(egret.IOErrorEvent.IO_ERROR));
  6645. };
  6646. /**
  6647. * @private
  6648. *
  6649. */
  6650. NativeResourceLoader.prototype.loadOver = function () {
  6651. this.dispatchEvent(new egret.Event(egret.Event.COMPLETE));
  6652. };
  6653. return NativeResourceLoader;
  6654. }(egret.EventDispatcher));
  6655. egret.NativeResourceLoader = NativeResourceLoader;
  6656. __reflect(NativeResourceLoader.prototype, "egret.NativeResourceLoader");
  6657. })(egret || (egret = {}));
  6658. //////////////////////////////////////////////////////////////////////////////////////
  6659. //
  6660. // Copyright (c) 2014-present, Egret Technology.
  6661. // All rights reserved.
  6662. // Redistribution and use in source and binary forms, with or without
  6663. // modification, are permitted provided this the following conditions are met:
  6664. //
  6665. // * Redistributions of source code must retain the above copyright
  6666. // notice, this list of conditions and the following disclaimer.
  6667. // * Redistributions in binary form must reproduce the above copyright
  6668. // notice, this list of conditions and the following disclaimer in the
  6669. // documentation and/or other materials provided with the distribution.
  6670. // * Neither the name of the Egret nor the
  6671. // names of its contributors may be used to endorse or promote products
  6672. // derived from this software without specific prior written permission.
  6673. //
  6674. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  6675. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  6676. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  6677. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  6678. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6679. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  6680. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6681. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6682. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6683. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6684. //
  6685. //////////////////////////////////////////////////////////////////////////////////////
  6686. var egret;
  6687. (function (egret) {
  6688. var native;
  6689. (function (native) {
  6690. /**
  6691. * @private
  6692. */
  6693. var NativeTouchHandler = (function (_super) {
  6694. __extends(NativeTouchHandler, _super);
  6695. function NativeTouchHandler(stage) {
  6696. var _this = _super.call(this) || this;
  6697. _this.$touch = new egret.sys.TouchHandler(stage);
  6698. var self = _this;
  6699. egret_native.onTouchesBegin = function (num, ids, xs_array, ys_array) {
  6700. self.$executeTouchCallback(num, ids, xs_array, ys_array, self.$touch.onTouchBegin);
  6701. };
  6702. egret_native.onTouchesMove = function (num, ids, xs_array, ys_array) {
  6703. self.$executeTouchCallback(num, ids, xs_array, ys_array, self.$touch.onTouchMove);
  6704. };
  6705. egret_native.onTouchesEnd = function (num, ids, xs_array, ys_array) {
  6706. self.$executeTouchCallback(num, ids, xs_array, ys_array, self.$touch.onTouchEnd);
  6707. };
  6708. egret_native.onTouchesCancel = function (num, ids, xs_array, ys_array) {
  6709. };
  6710. return _this;
  6711. }
  6712. NativeTouchHandler.prototype.$executeTouchCallback = function (num, ids, xs_array, ys_array, callback) {
  6713. for (var i = 0; i < num; i++) {
  6714. var id = ids[i];
  6715. var x = xs_array[i];
  6716. var y = ys_array[i];
  6717. callback.call(this.$touch, x, y, id);
  6718. }
  6719. };
  6720. /**
  6721. * @private
  6722. * 更新同时触摸点的数量
  6723. */
  6724. NativeTouchHandler.prototype.$updateMaxTouches = function () {
  6725. this.$touch.$initMaxTouches();
  6726. };
  6727. return NativeTouchHandler;
  6728. }(egret.HashObject));
  6729. native.NativeTouchHandler = NativeTouchHandler;
  6730. __reflect(NativeTouchHandler.prototype, "egret.native.NativeTouchHandler");
  6731. })(native = egret.native || (egret.native = {}));
  6732. })(egret || (egret = {}));
  6733. //////////////////////////////////////////////////////////////////////////////////////
  6734. //
  6735. // Copyright (c) 2014-present, Egret Technology.
  6736. // All rights reserved.
  6737. // Redistribution and use in source and binary forms, with or without
  6738. // modification, are permitted provided that the following conditions are met:
  6739. //
  6740. // * Redistributions of source code must retain the above copyright
  6741. // notice, this list of conditions and the following disclaimer.
  6742. // * Redistributions in binary form must reproduce the above copyright
  6743. // notice, this list of conditions and the following disclaimer in the
  6744. // documentation and/or other materials provided with the distribution.
  6745. // * Neither the name of the Egret nor the
  6746. // names of its contributors may be used to endorse or promote products
  6747. // derived from this software without specific prior written permission.
  6748. //
  6749. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  6750. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  6751. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  6752. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  6753. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6754. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  6755. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6756. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6757. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6758. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6759. //
  6760. //////////////////////////////////////////////////////////////////////////////////////
  6761. var egret;
  6762. (function (egret) {
  6763. var native;
  6764. (function (native) {
  6765. /**
  6766. * @private
  6767. */
  6768. var NativeHttpRequest = (function (_super) {
  6769. __extends(NativeHttpRequest, _super);
  6770. /**
  6771. * @private
  6772. */
  6773. function NativeHttpRequest() {
  6774. var _this = _super.call(this) || this;
  6775. /**
  6776. * @private
  6777. */
  6778. _this._url = "";
  6779. _this._method = "";
  6780. /**
  6781. * @private
  6782. */
  6783. _this.urlData = {};
  6784. _this.responseHeader = "";
  6785. return _this;
  6786. }
  6787. Object.defineProperty(NativeHttpRequest.prototype, "response", {
  6788. /**
  6789. * @private
  6790. * 本次请求返回的数据,数据类型根据responseType设置的值确定。
  6791. */
  6792. get: function () {
  6793. return this._response;
  6794. },
  6795. enumerable: true,
  6796. configurable: true
  6797. });
  6798. Object.defineProperty(NativeHttpRequest.prototype, "responseType", {
  6799. /**
  6800. * @private
  6801. * 设置返回的数据格式,请使用 HttpResponseType 里定义的枚举值。设置非法的值或不设置,都将使用HttpResponseType.TEXT。
  6802. */
  6803. get: function () {
  6804. return this._responseType;
  6805. },
  6806. set: function (value) {
  6807. this._responseType = value;
  6808. },
  6809. enumerable: true,
  6810. configurable: true
  6811. });
  6812. Object.defineProperty(NativeHttpRequest.prototype, "withCredentials", {
  6813. /**
  6814. * @private
  6815. * 表明在进行跨站(cross-site)的访问控制(Access-Control)请求时,是否使用认证信息(例如cookie或授权的header)。 默认为 false。(这个标志不会影响同站的请求)
  6816. */
  6817. get: function () {
  6818. return this._withCredentials;
  6819. },
  6820. set: function (value) {
  6821. this._withCredentials = value;
  6822. },
  6823. enumerable: true,
  6824. configurable: true
  6825. });
  6826. /**
  6827. * @private
  6828. * 初始化一个请求.注意,若在已经发出请求的对象上调用此方法,相当于立即调用abort().
  6829. * @param url 该请求所要访问的URL该请求所要访问的URL
  6830. * @param method 请求所使用的HTTP方法, 请使用 HttpMethod 定义的枚举值.
  6831. */
  6832. NativeHttpRequest.prototype.open = function (url, method) {
  6833. if (method === void 0) { method = "GET"; }
  6834. this._url = url;
  6835. this._method = method;
  6836. };
  6837. /**
  6838. * @private
  6839. * 发送请求.
  6840. * @param data 需要发送的数据
  6841. */
  6842. NativeHttpRequest.prototype.send = function (data) {
  6843. var self = this;
  6844. if (self.isNetUrl(self._url)) {
  6845. self.urlData.type = self._method;
  6846. //写入POST数据
  6847. if (self._method == egret.HttpMethod.POST && data) {
  6848. if (data instanceof ArrayBuffer) {
  6849. self.urlData.data = data;
  6850. }
  6851. else {
  6852. self.urlData.data = data.toString();
  6853. }
  6854. }
  6855. else {
  6856. delete self.urlData["data"];
  6857. }
  6858. if (self._responseType == egret.HttpResponseType.ARRAY_BUFFER) {
  6859. self.urlData.binary = true;
  6860. }
  6861. else {
  6862. self.urlData.header = false;
  6863. }
  6864. //写入header信息
  6865. if (this.headerObj) {
  6866. self.urlData.header = JSON.stringify(this.headerObj);
  6867. }
  6868. else {
  6869. delete self.urlData.header;
  6870. }
  6871. var promise = egret.PromiseObject.create();
  6872. promise.onSuccessFunc = function (getted_str) {
  6873. self._response = getted_str;
  6874. egret.$callAsync(egret.Event.dispatchEvent, egret.Event, self, egret.Event.COMPLETE);
  6875. };
  6876. promise.onErrorFunc = function (error_code) {
  6877. egret.$warn(1019, error_code);
  6878. egret.Event.dispatchEvent(self, egret.IOErrorEvent.IO_ERROR);
  6879. };
  6880. promise.onResponseHeaderFunc = this.onResponseHeader;
  6881. promise.onResponseHeaderThisObject = this;
  6882. egret_native.requireHttp(self._url, self.urlData, promise);
  6883. }
  6884. else if (!egret_native.isFileExists(self._url)) {
  6885. download();
  6886. }
  6887. else {
  6888. readFileAsync();
  6889. }
  6890. function readFileAsync() {
  6891. var promise = new egret.PromiseObject();
  6892. promise.onSuccessFunc = function (content) {
  6893. self._response = content;
  6894. egret.Event.dispatchEvent(self, egret.Event.COMPLETE);
  6895. };
  6896. promise.onErrorFunc = function () {
  6897. egret.Event.dispatchEvent(self, egret.IOErrorEvent.IO_ERROR);
  6898. };
  6899. if (self._responseType == egret.HttpResponseType.ARRAY_BUFFER) {
  6900. egret_native.readFileAsync(self._url, promise, "ArrayBuffer");
  6901. }
  6902. else {
  6903. egret_native.readFileAsync(self._url, promise);
  6904. }
  6905. }
  6906. function download() {
  6907. var promise = egret.PromiseObject.create();
  6908. promise.onSuccessFunc = readFileAsync;
  6909. promise.onErrorFunc = function () {
  6910. egret.Event.dispatchEvent(self, egret.IOErrorEvent.IO_ERROR);
  6911. };
  6912. promise.onResponseHeaderFunc = this.onResponseHeader;
  6913. promise.onResponseHeaderThisObject = this;
  6914. egret_native.download(self._url, self._url, promise);
  6915. }
  6916. };
  6917. /**
  6918. * 是否是网络地址
  6919. * @param url
  6920. * @returns {boolean}
  6921. */
  6922. NativeHttpRequest.prototype.isNetUrl = function (url) {
  6923. return url.indexOf("http://") != -1 || url.indexOf("HTTP://") != -1 || url.indexOf("https://") != -1 || url.indexOf("HTTPS://") != -1;
  6924. };
  6925. /**
  6926. * @private
  6927. * 如果请求已经被发送,则立刻中止请求.
  6928. */
  6929. NativeHttpRequest.prototype.abort = function () {
  6930. };
  6931. NativeHttpRequest.prototype.onResponseHeader = function (headers) {
  6932. this.responseHeader = "";
  6933. var obj = JSON.parse(headers);
  6934. for (var key in obj) {
  6935. this.responseHeader += key + ": " + obj[key] + "\r\n";
  6936. }
  6937. };
  6938. /**
  6939. * @private
  6940. * 返回所有响应头信息(响应头名和值), 如果响应头还没接受,则返回"".
  6941. */
  6942. NativeHttpRequest.prototype.getAllResponseHeaders = function () {
  6943. return this.responseHeader;
  6944. };
  6945. /**
  6946. * @private
  6947. * 给指定的HTTP请求头赋值.在这之前,您必须确认已经调用 open() 方法打开了一个url.
  6948. * @param header 将要被赋值的请求头名称.
  6949. * @param value 给指定的请求头赋的值.
  6950. */
  6951. NativeHttpRequest.prototype.setRequestHeader = function (header, value) {
  6952. if (!this.headerObj) {
  6953. this.headerObj = {};
  6954. }
  6955. this.headerObj[header] = value;
  6956. };
  6957. /**
  6958. * @private
  6959. * 返回指定的响应头的值, 如果响应头还没被接受,或该响应头不存在,则返回"".
  6960. * @param header 要返回的响应头名称
  6961. */
  6962. NativeHttpRequest.prototype.getResponseHeader = function (header) {
  6963. return "";
  6964. };
  6965. return NativeHttpRequest;
  6966. }(egret.EventDispatcher));
  6967. native.NativeHttpRequest = NativeHttpRequest;
  6968. __reflect(NativeHttpRequest.prototype, "egret.native.NativeHttpRequest", ["egret.HttpRequest"]);
  6969. egret.HttpRequest = NativeHttpRequest;
  6970. if (true) {
  6971. egret.$markReadOnly(NativeHttpRequest, "response");
  6972. }
  6973. })(native = egret.native || (egret.native = {}));
  6974. })(egret || (egret = {}));
  6975. //////////////////////////////////////////////////////////////////////////////////////
  6976. //
  6977. // Copyright (c) 2014-present, Egret Technology.
  6978. // All rights reserved.
  6979. // Redistribution and use in source and binary forms, with or without
  6980. // modification, are permitted provided that the following conditions are met:
  6981. //
  6982. // * Redistributions of source code must retain the above copyright
  6983. // notice, this list of conditions and the following disclaimer.
  6984. // * Redistributions in binary form must reproduce the above copyright
  6985. // notice, this list of conditions and the following disclaimer in the
  6986. // documentation and/or other materials provided with the distribution.
  6987. // * Neither the name of the Egret nor the
  6988. // names of its contributors may be used to endorse or promote products
  6989. // derived from this software without specific prior written permission.
  6990. //
  6991. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  6992. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  6993. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  6994. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  6995. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6996. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  6997. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6998. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6999. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7000. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7001. //
  7002. //////////////////////////////////////////////////////////////////////////////////////
  7003. var egret;
  7004. (function (egret) {
  7005. var native;
  7006. (function (native) {
  7007. /**
  7008. * @private
  7009. * ImageLoader 类可用于加载图像(JPG、PNG 或 GIF)文件。使用 load() 方法来启动加载。被加载的图像对象数据将存储在 ImageLoader.data 属性上 。
  7010. */
  7011. var NativeImageLoader = (function (_super) {
  7012. __extends(NativeImageLoader, _super);
  7013. function NativeImageLoader() {
  7014. var _this = _super.apply(this, arguments) || this;
  7015. /**
  7016. * @private
  7017. * 使用 load() 方法加载成功的 BitmapData 图像数据。
  7018. */
  7019. _this.data = null;
  7020. /**
  7021. * @private
  7022. * 当从其他站点加载一个图片时,指定是否启用跨域资源共享(CORS),默认值为null。
  7023. * 可以设置为"anonymous","use-credentials"或null,设置为其他值将等同于"anonymous"。
  7024. */
  7025. _this._crossOrigin = null;
  7026. return _this;
  7027. }
  7028. Object.defineProperty(NativeImageLoader.prototype, "crossOrigin", {
  7029. get: function () {
  7030. return this._crossOrigin;
  7031. },
  7032. set: function (value) {
  7033. this._crossOrigin = value;
  7034. },
  7035. enumerable: true,
  7036. configurable: true
  7037. });
  7038. /**
  7039. * @private
  7040. *
  7041. * @param url
  7042. * @param callback
  7043. */
  7044. NativeImageLoader.prototype.load = function (url) {
  7045. this.check(url);
  7046. };
  7047. NativeImageLoader.prototype.check = function (url) {
  7048. var self = this;
  7049. if (self.isNetUrl(url)) {
  7050. self.download(url);
  7051. }
  7052. else if (!egret_native.isFileExists(url)) {
  7053. self.download(url);
  7054. }
  7055. else {
  7056. self.loadTexture(url);
  7057. }
  7058. };
  7059. NativeImageLoader.prototype.download = function (url) {
  7060. var self = this;
  7061. var promise = egret.PromiseObject.create();
  7062. promise.onSuccessFunc = function () {
  7063. self.loadTexture(url);
  7064. };
  7065. promise.onErrorFunc = function () {
  7066. self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  7067. };
  7068. egret_native.download(url, url, promise);
  7069. };
  7070. NativeImageLoader.prototype.loadTexture = function (url) {
  7071. var self = this;
  7072. var promise = new egret.PromiseObject();
  7073. promise.onSuccessFunc = function (bitmapData) {
  7074. self.data = new egret.BitmapData(bitmapData);
  7075. self.dispatchEventWith(egret.Event.COMPLETE);
  7076. };
  7077. promise.onErrorFunc = function () {
  7078. self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
  7079. };
  7080. egret_native.Texture.addTextureAsyn(url, promise);
  7081. };
  7082. /**
  7083. * 是否是网络地址
  7084. * @param url
  7085. * @returns {boolean}
  7086. */
  7087. NativeImageLoader.prototype.isNetUrl = function (url) {
  7088. return url.indexOf("http://") != -1 || url.indexOf("HTTP://") != -1 || url.indexOf("https://") != -1 || url.indexOf("HTTPS://") != -1;
  7089. };
  7090. return NativeImageLoader;
  7091. }(egret.EventDispatcher));
  7092. /**
  7093. * @private
  7094. * 指定是否启用跨域资源共享,如果ImageLoader实例有设置过crossOrigin属性将使用设置的属性
  7095. */
  7096. NativeImageLoader.crossOrigin = null;
  7097. native.NativeImageLoader = NativeImageLoader;
  7098. __reflect(NativeImageLoader.prototype, "egret.native.NativeImageLoader", ["egret.ImageLoader"]);
  7099. egret.ImageLoader = NativeImageLoader;
  7100. })(native = egret.native || (egret.native = {}));
  7101. })(egret || (egret = {}));
  7102. //////////////////////////////////////////////////////////////////////////////////////
  7103. //
  7104. // Copyright (c) 2014-present, Egret Technology.
  7105. // All rights reserved.
  7106. // Redistribution and use in source and binary forms, with or without
  7107. // modification, are permitted provided that the following conditions are met:
  7108. //
  7109. // * Redistributions of source code must retain the above copyright
  7110. // notice, this list of conditions and the following disclaimer.
  7111. // * Redistributions in binary form must reproduce the above copyright
  7112. // notice, this list of conditions and the following disclaimer in the
  7113. // documentation and/or other materials provided with the distribution.
  7114. // * Neither the name of the Egret nor the
  7115. // names of its contributors may be used to endorse or promote products
  7116. // derived from this software without specific prior written permission.
  7117. //
  7118. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  7119. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7120. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7121. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  7122. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7123. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  7124. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7125. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7126. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7127. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7128. //
  7129. //////////////////////////////////////////////////////////////////////////////////////
  7130. var egret;
  7131. (function (egret) {
  7132. var native;
  7133. (function (native) {
  7134. /**
  7135. * @classdesc
  7136. * @implements egret.StageText
  7137. * @private
  7138. * @version Egret 2.4
  7139. * @platform Web,Native
  7140. */
  7141. var NativeStageText = (function (_super) {
  7142. __extends(NativeStageText, _super);
  7143. /**
  7144. * @version Egret 2.4
  7145. * @platform Web,Native
  7146. */
  7147. function NativeStageText() {
  7148. var _this = _super.call(this) || this;
  7149. /**
  7150. * @private
  7151. */
  7152. _this.textValue = "";
  7153. /**
  7154. * @private
  7155. */
  7156. _this.colorValue = 0xffffff;
  7157. /**
  7158. * @private
  7159. */
  7160. _this.isFinishDown = false;
  7161. _this.textValue = "";
  7162. return _this;
  7163. }
  7164. /**
  7165. * @private
  7166. *
  7167. * @returns
  7168. */
  7169. NativeStageText.prototype.$getText = function () {
  7170. if (!this.textValue) {
  7171. this.textValue = "";
  7172. }
  7173. return this.textValue;
  7174. };
  7175. /**
  7176. * @private
  7177. *
  7178. * @param value
  7179. */
  7180. NativeStageText.prototype.$setText = function (value) {
  7181. this.textValue = value;
  7182. return true;
  7183. };
  7184. NativeStageText.prototype.$setColor = function (value) {
  7185. this.colorValue = value;
  7186. return true;
  7187. };
  7188. /**
  7189. * @private
  7190. *
  7191. */
  7192. NativeStageText.prototype.$onBlur = function () {
  7193. };
  7194. //全屏键盘
  7195. NativeStageText.prototype.showScreenKeyboard = function () {
  7196. var self = this;
  7197. self.dispatchEvent(new egret.Event("focus"));
  7198. egret.Event.dispatchEvent(self, "focus", false, { "showing": true });
  7199. egret_native.EGT_TextInput = function (appendText) {
  7200. if (self.$textfield.multiline) {
  7201. self.textValue = appendText;
  7202. self.dispatchEvent(new egret.Event("updateText"));
  7203. if (self.isFinishDown) {
  7204. self.isFinishDown = false;
  7205. self.dispatchEvent(new egret.Event("blur"));
  7206. }
  7207. }
  7208. else {
  7209. self.textValue = appendText.replace(/[\n|\r]/, "");
  7210. //关闭软键盘
  7211. egret_native.TextInputOp.setKeybordOpen(false);
  7212. self.dispatchEvent(new egret.Event("updateText"));
  7213. self.dispatchEvent(new egret.Event("blur"));
  7214. }
  7215. };
  7216. //点击完成
  7217. egret_native.EGT_keyboardFinish = function () {
  7218. if (self.$textfield.multiline) {
  7219. self.isFinishDown = true;
  7220. }
  7221. };
  7222. };
  7223. /**
  7224. * @private
  7225. *
  7226. */
  7227. NativeStageText.prototype.$show = function () {
  7228. var self = this;
  7229. var textfield = this.$textfield;
  7230. var values = textfield.$TextField;
  7231. egret_native.TextInputOp.setKeybordOpen(false);
  7232. egret_native.EGT_getTextEditerContentText = function () {
  7233. return self.$getText();
  7234. };
  7235. egret_native.EGT_keyboardDidShow = function () {
  7236. //if (egret_native.TextInputOp.isFullScreenKeyBoard()) {//横屏
  7237. //}
  7238. self.showScreenKeyboard();
  7239. egret_native.EGT_keyboardDidShow = function () {
  7240. };
  7241. if (egret_native.TextInputOp.updateConfig) {
  7242. egret_native.TextInputOp.updateConfig(JSON.stringify({
  7243. "font_color": values[2 /* textColor */]
  7244. }));
  7245. }
  7246. };
  7247. egret_native.EGT_keyboardDidHide = function () {
  7248. };
  7249. egret_native.EGT_deleteBackward = function () {
  7250. };
  7251. var inputType = values[37 /* inputType */];
  7252. var inputMode = values[30 /* multiline */] ? 0 : 6;
  7253. var inputFlag = -1; //textfield.displayAsPassword ? 0 : -1;
  7254. if (inputType == egret.TextFieldInputType.PASSWORD) {
  7255. inputFlag = 0;
  7256. }
  7257. else if (inputType == egret.TextFieldInputType.TEL) {
  7258. inputMode = 3;
  7259. }
  7260. var returnType = 1;
  7261. var maxLength = values[21 /* maxChars */] <= 0 ? -1 : values[21 /* maxChars */];
  7262. var node = textfield.$getRenderNode();
  7263. var point = this.$textfield.localToGlobal(0, 0);
  7264. egret_native.TextInputOp.setKeybordOpen(true, JSON.stringify({
  7265. "inputMode": inputMode,
  7266. "inputFlag": inputFlag,
  7267. "returnType": returnType,
  7268. "maxLength": maxLength,
  7269. "x": point.x,
  7270. "y": point.y,
  7271. "width": textfield.width,
  7272. "height": textfield.height,
  7273. "font_size": values[0 /* fontSize */],
  7274. "font_color": values[2 /* textColor */],
  7275. "textAlign": values[9 /* textAlign */],
  7276. "verticalAlign": values[10 /* verticalAlign */]
  7277. }));
  7278. };
  7279. /**
  7280. * @private
  7281. *
  7282. */
  7283. NativeStageText.prototype.$hide = function () {
  7284. egret_native.TextInputOp.setKeybordOpen(false);
  7285. this.dispatchEvent(new egret.Event("blur"));
  7286. };
  7287. NativeStageText.prototype.$resetStageText = function () {
  7288. };
  7289. NativeStageText.prototype.$addToStage = function () {
  7290. };
  7291. NativeStageText.prototype.$removeFromStage = function () {
  7292. };
  7293. NativeStageText.prototype.$setTextField = function (value) {
  7294. this.$textfield = value;
  7295. return true;
  7296. };
  7297. return NativeStageText;
  7298. }(egret.EventDispatcher));
  7299. native.NativeStageText = NativeStageText;
  7300. __reflect(NativeStageText.prototype, "egret.native.NativeStageText", ["egret.StageText"]);
  7301. egret.StageText = NativeStageText;
  7302. })(native = egret.native || (egret.native = {}));
  7303. })(egret || (egret = {}));
  7304. //////////////////////////////////////////////////////////////////////////////////////
  7305. //
  7306. // Copyright (c) 2014-present, Egret Technology.
  7307. // All rights reserved.
  7308. // Redistribution and use in source and binary forms, with or without
  7309. // modification, are permitted provided that the following conditions are met:
  7310. //
  7311. // * Redistributions of source code must retain the above copyright
  7312. // notice, this list of conditions and the following disclaimer.
  7313. // * Redistributions in binary form must reproduce the above copyright
  7314. // notice, this list of conditions and the following disclaimer in the
  7315. // documentation and/or other materials provided with the distribution.
  7316. // * Neither the name of the Egret nor the
  7317. // names of its contributors may be used to endorse or promote products
  7318. // derived from this software without specific prior written permission.
  7319. //
  7320. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  7321. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7322. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7323. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  7324. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7325. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  7326. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7327. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7328. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7329. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7330. //
  7331. //////////////////////////////////////////////////////////////////////////////////////
  7332. var egret;
  7333. (function (egret) {
  7334. var web;
  7335. (function (web) {
  7336. /**
  7337. * @private
  7338. * XML节点基类
  7339. */
  7340. var XMLNode = (function () {
  7341. /**
  7342. * @private
  7343. */
  7344. function XMLNode(nodeType, parent) {
  7345. this.nodeType = nodeType;
  7346. this.parent = parent;
  7347. }
  7348. return XMLNode;
  7349. }());
  7350. web.XMLNode = XMLNode;
  7351. __reflect(XMLNode.prototype, "egret.web.XMLNode");
  7352. /**
  7353. * @private
  7354. * XML节点对象
  7355. */
  7356. var XML = (function (_super) {
  7357. __extends(XML, _super);
  7358. /**
  7359. * @private
  7360. */
  7361. function XML(localName, parent, prefix, namespace, name) {
  7362. var _this = _super.call(this, 1, parent) || this;
  7363. /**
  7364. * @private
  7365. * 当前节点上的属性列表
  7366. */
  7367. _this.attributes = {};
  7368. /**
  7369. * @private
  7370. * 当前节点的子节点列表
  7371. */
  7372. _this.children = [];
  7373. _this.localName = localName;
  7374. _this.prefix = prefix;
  7375. _this.namespace = namespace;
  7376. _this.name = name;
  7377. return _this;
  7378. }
  7379. return XML;
  7380. }(XMLNode));
  7381. web.XML = XML;
  7382. __reflect(XML.prototype, "egret.web.XML");
  7383. /**
  7384. * @private
  7385. * XML文本节点
  7386. */
  7387. var XMLText = (function (_super) {
  7388. __extends(XMLText, _super);
  7389. /**
  7390. * @private
  7391. */
  7392. function XMLText(text, parent) {
  7393. var _this = _super.call(this, 3, parent) || this;
  7394. _this.text = text;
  7395. return _this;
  7396. }
  7397. return XMLText;
  7398. }(XMLNode));
  7399. web.XMLText = XMLText;
  7400. __reflect(XMLText.prototype, "egret.web.XMLText");
  7401. /**
  7402. * @private
  7403. * 解析字符串为XML对象
  7404. * @param text 要解析的字符串
  7405. */
  7406. function parse(text) {
  7407. var xmlDocStr = egret_native.xmlStr2JsonStr(text);
  7408. //替换换行符
  7409. xmlDocStr = xmlDocStr.replace(/\n/g, "\\n");
  7410. var xmlDoc = JSON.parse(xmlDocStr);
  7411. return parseNode(xmlDoc, null);
  7412. }
  7413. /**
  7414. * @private
  7415. * 解析一个节点
  7416. */
  7417. function parseNode(node, parent) {
  7418. if (node.localName == "parsererror") {
  7419. throw new Error(node.textContent);
  7420. }
  7421. var xml = new XML(node.localName, parent, node.prefix, node.namespace, node.name);
  7422. var nodeAttributes = node.attributes;
  7423. var attributes = xml.attributes;
  7424. for (var key in nodeAttributes) {
  7425. attributes[key] = xml["$" + key] = nodeAttributes[key];
  7426. }
  7427. var childNodes = node.children;
  7428. var length = childNodes.length;
  7429. var children = xml.children;
  7430. for (var i = 0; i < length; i++) {
  7431. var childNode = childNodes[i];
  7432. var nodeType = childNode.nodeType;
  7433. var childXML = null;
  7434. if (nodeType == 1) {
  7435. childXML = parseNode(childNode, xml);
  7436. }
  7437. else if (nodeType == 3) {
  7438. var text = childNode.text.trim();
  7439. if (text) {
  7440. childXML = new XMLText(text, xml);
  7441. }
  7442. }
  7443. if (childXML) {
  7444. children.push(childXML);
  7445. }
  7446. }
  7447. return xml;
  7448. }
  7449. egret.XML = { parse: parse };
  7450. })(web = egret.web || (egret.web = {}));
  7451. })(egret || (egret = {}));
  7452. //////////////////////////////////////////////////////////////////////////////////////
  7453. //
  7454. // Copyright (c) 2014-present, Egret Technology.
  7455. // All rights reserved.
  7456. // Redistribution and use in source and binary forms, with or without
  7457. // modification, are permitted provided that the following conditions are met:
  7458. //
  7459. // * Redistributions of source code must retain the above copyright
  7460. // notice, this list of conditions and the following disclaimer.
  7461. // * Redistributions in binary form must reproduce the above copyright
  7462. // notice, this list of conditions and the following disclaimer in the
  7463. // documentation and/or other materials provided with the distribution.
  7464. // * Neither the name of the Egret nor the
  7465. // names of its contributors may be used to endorse or promote products
  7466. // derived from this software without specific prior written permission.
  7467. //
  7468. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  7469. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7470. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7471. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  7472. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7473. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  7474. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7475. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7476. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7477. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7478. //
  7479. //////////////////////////////////////////////////////////////////////////////////////
  7480. var egret;
  7481. (function (egret) {
  7482. var native;
  7483. (function (native) {
  7484. /**
  7485. * @private
  7486. */
  7487. function getOption(key) {
  7488. return egret_native.getOption(key);
  7489. }
  7490. native.getOption = getOption;
  7491. egret.getOption = getOption;
  7492. })(native = egret.native || (egret.native = {}));
  7493. })(egret || (egret = {}));