|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493 |
- var __reflect = (this && this.__reflect) || function (p, c, t) {
- p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
- };
- var __extends = (this && this.__extends) || function (d, b) {
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * 测量文本在指定样式下的宽度。
- * @param text 要测量的文本内容。
- * @param fontFamily 字体名称
- * @param fontSize 字体大小
- * @param bold 是否粗体
- * @param italic 是否斜体
- */
- function measureText(text, fontFamily, fontSize, bold, italic) {
- var font;
- var arr;
- if (fontFamily.indexOf(", ") != -1) {
- arr = fontFamily.split(", ");
- }
- else if (fontFamily.indexOf(",") != -1) {
- arr = fontFamily.split(",");
- var length_1 = arr.length;
- for (var i = 0; i < length_1; i++) {
- var fontFamily_1 = arr[i];
- //暂时先不考虑带有引号的情况
- if (egret.fontMapping[fontFamily_1]) {
- font = egret.fontMapping[fontFamily_1];
- break;
- }
- }
- }
- else {
- font = egret.fontMapping[fontFamily];
- }
- if (!font) {
- font = "/system/fonts/DroidSansFallback.ttf";
- }
- egret_native.Label.createLabel(font, fontSize, "", 0);
- return egret_native.Label.getTextSize(text)[0];
- }
- egret.sys.measureText = measureText;
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- var blendModesForGL = {
- "source-over": [1, 771],
- "lighter": [770, 1],
- "destination-out": [0, 771],
- "destination-in": [0, 770]
- };
- /**
- * @version Egret 2.4
- * @platform Web,Native
- * @private
- */
- var NativeRenderTextureRenderContext = (function (_super) {
- __extends(NativeRenderTextureRenderContext, _super);
- function NativeRenderTextureRenderContext() {
- var _this = _super.apply(this, arguments) || this;
- _this.$matrix = new egret.Matrix();
- _this.$nativeContext = egret_native.Graphics;
- _this.$nativeGraphicsContext = egret_native.rastergl;
- _this.$globalCompositeOperation = "source-over";
- _this.$globalAlpha = 1;
- _this.$lineWidth = 0;
- _this.$strokeStyle = "#000000";
- _this.$fillStyle = "#000000";
- _this.$font = "normal normal 10px sans-serif";
- _this.$fontSize = 10;
- _this.$fontFamily = "";
- _this.clipRectArray = null;
- _this.$saveList = [];
- _this.$clipRect = new egret.Rectangle();
- _this.$saveCount = 0;
- _this.$clipList = [];
- _this.$hasStrokeText = false;
- return _this;
- }
- Object.defineProperty(NativeRenderTextureRenderContext.prototype, "globalCompositeOperation", {
- /**
- * @private
- * 设置新图像如何绘制到已有的图像上的规制
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$globalCompositeOperation;
- },
- set: function (value) {
- this.$globalCompositeOperation = value;
- var arr = blendModesForGL[value];
- if (arr) {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.setBlendArg(arr[0], arr[1]);
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeRenderTextureRenderContext.prototype, "globalAlpha", {
- /**
- * @private
- * 设置接下来绘图填充的整体透明度
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$globalAlpha;
- },
- set: function (value) {
- this.$globalAlpha = value;
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.setGlobalAlpha(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeRenderTextureRenderContext.prototype, "lineWidth", {
- /**
- * @private
- * 设置线条粗细,以像素为单位。设置为0,负数,Infinity 或 NaN 将会被忽略。
- * @default 1
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$lineWidth;
- },
- set: function (value) {
- //console.log("set lineWidth" + value);
- this.$lineWidth = value;
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.setLineWidth(value);
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.setLineWidth(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeRenderTextureRenderContext.prototype, "strokeStyle", {
- /**
- * @private
- * 设置要在图形边线填充的颜色或样式
- * @default "#000000"
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$strokeStyle;
- },
- set: function (value) {
- this.$strokeStyle = value;
- if (value != null) {
- if (value.indexOf("rgba") != -1) {
- value = this.$parseRGBA(value);
- }
- else if (value.indexOf("rgb") != -1) {
- value = this.$parseRGB(value);
- }
- native.$cmdManager.setContext(egret_native.Label);
- native.$cmdManager.setStrokeColor(parseInt(value.replace("#", "0x")));
- }
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- var s1 = native.$cmdManager.pushString(value);
- native.$cmdManager.setStrokeStyle(s1);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeRenderTextureRenderContext.prototype, "fillStyle", {
- /**
- * @private
- * 设置要在图形内部填充的颜色或样式
- * @default "#000000"
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$fillStyle;
- },
- set: function (value) {
- this.$fillStyle = value;
- if (value != null) {
- if (value.indexOf("rgba") != -1) {
- value = this.$parseRGBA(value);
- }
- else if (value.indexOf("rgb") != -1) {
- value = this.$parseRGB(value);
- }
- native.$cmdManager.setContext(egret_native.Label);
- native.$cmdManager.setTextColor(parseInt(value.replace("#", "0x")));
- }
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- var s1 = native.$cmdManager.pushString(value);
- native.$cmdManager.setFillStyle(s1);
- },
- enumerable: true,
- configurable: true
- });
- NativeRenderTextureRenderContext.prototype.$fillColorStr = function (s) {
- if (s.length < 2) {
- s = "0" + s;
- }
- return s;
- };
- NativeRenderTextureRenderContext.prototype.$parseRGBA = function (str) {
- var index = str.indexOf("(");
- str = str.slice(index + 1, str.length - 1);
- var arr = str.split(",");
- var a = parseInt((parseFloat(arr[3]) * 255)).toString(16);
- var r = parseInt(arr[0]).toString(16);
- var g = parseInt(arr[1]).toString(16);
- var b = parseInt(arr[2]).toString(16);
- str = "#" + this.$fillColorStr(a) + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
- return str;
- };
- NativeRenderTextureRenderContext.prototype.$parseRGB = function (str) {
- var index = str.indexOf("(");
- str = str.slice(index + 1, str.length - 1);
- var arr = str.split(",");
- var r = parseInt(arr[0]).toString(16);
- var g = parseInt(arr[1]).toString(16);
- var b = parseInt(arr[2]).toString(16);
- str = "#" + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
- return str;
- };
- Object.defineProperty(NativeRenderTextureRenderContext.prototype, "font", {
- /**
- * @private
- * 当前的字体样式
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$font;
- },
- set: function (value) {
- this.$font = value;
- var arr = value.split(" ");
- var sizeTxt = arr[2];
- if (sizeTxt.indexOf("px") != -1) {
- this.$fontSize = parseInt(sizeTxt.replace("px", ""));
- }
- if (egret.useFontMapping) {
- var fontFamilyText = void 0;
- if (arr.length == 4) {
- fontFamilyText = arr[3];
- }
- else {
- fontFamilyText = arr.slice(3).join(" ");
- }
- if (fontFamilyText.indexOf(", ") != -1) {
- arr = fontFamilyText.split(", ");
- }
- else if (fontFamilyText.indexOf(",") != -1) {
- arr = fontFamilyText.split(",");
- var length_2 = arr.length;
- for (var i = 0; i < length_2; i++) {
- var fontFamily = arr[i];
- //暂时先不考虑带有引号的情况
- if (egret.fontMapping[fontFamily]) {
- this.$fontFamily = egret.fontMapping[fontFamily];
- return;
- }
- }
- }
- else {
- this.$fontFamily = egret.fontMapping[fontFamilyText];
- }
- if (!this.$fontFamily) {
- this.$fontFamily = "/system/fonts/DroidSansFallback.ttf";
- }
- }
- else {
- //兼容旧版本直接将 default_fontFamily 设置为字体路径的情况
- this.$fontFamily = egret.TextField.default_fontFamily;
- }
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @private
- * 绘制一段圆弧路径。圆弧路径的圆心在 (x, y) 位置,半径为 r ,根据anticlockwise (默认为顺时针)指定的方向从 startAngle 开始绘制,到 endAngle 结束。
- * @param x 圆弧中心(圆心)的 x 轴坐标。
- * @param y 圆弧中心(圆心)的 y 轴坐标。
- * @param radius 圆弧的半径。
- * @param startAngle 圆弧的起始点, x轴方向开始计算,单位以弧度表示。
- * @param endAngle 圆弧的重点, 单位以弧度表示。
- * @param anticlockwise 如果为 true,逆时针绘制圆弧,反之,顺时针绘制。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.arc(x, y, radius, startAngle, endAngle, anticlockwise ? 1 : 0);
- // this.$nativeGraphicsContext.arc(x, y, radius, startAngle, endAngle, anticlockwise);
- };
- /**
- * @private
- * 绘制一段二次贝塞尔曲线路径。它需要2个点。 第一个点是控制点,第二个点是终点。 起始点是当前路径最新的点,当创建二次贝赛尔曲线之前,可以使用 moveTo() 方法进行改变。
- * @param cpx 控制点的 x 轴坐标。
- * @param cpy 控制点的 y 轴坐标。
- * @param x 终点的 x 轴坐标。
- * @param y 终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.quadraticCurveTo(cpx, cpy, x, y);
- // this.$nativeGraphicsContext.quadraticCurveTo(cpx, cpy, x, y);
- };
- /**
- * @private
- * 使用直线连接子路径的终点到x,y坐标。
- * @param x 直线终点的 x 轴坐标。
- * @param y 直线终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.lineTo = function (x, y) {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.lineTo(x, y);
- };
- /**
- * @private
- * 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
- * @param fillRule 一种算法,决定点是在路径内还是在路径外。允许的值:
- * "nonzero": 非零环绕规则, 默认的规则。
- * "evenodd": 奇偶环绕规则。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.fill = function (fillRule) {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- var s1 = native.$cmdManager.pushString(fillRule);
- native.$cmdManager.fill(s1);
- };
- /**
- * @private
- * 使笔点返回到当前子路径的起始点。它尝试从当前点到起始点绘制一条直线。如果图形已经是封闭的或者只有一个点,那么此方法不会做任何操作。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.closePath = function () {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.closePath();
- };
- /**
- * @private
- * 创建一段矩形路径,矩形的起点位置是 (x, y) ,尺寸为 width 和 height。矩形的4个点通过直线连接,子路径做为闭合的标记,所以你可以填充或者描边矩形。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.rect = function (x, y, w, h) {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.rect(x, y, w, h);
- this.$clipRect.setTo(x, y, w, h);
- };
- /**
- * @private
- * 将一个新的子路径的起始点移动到(x,y)坐标
- * @param x 点的 x 轴
- * @param y 点的 y 轴
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.moveTo = function (x, y) {
- this.checkSurface();
- // this.$nativeGraphicsContext.moveTo(x, y);
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.moveTo(x, y);
- };
- /**
- * @private
- * 绘制一个填充矩形。矩形的起点在 (x, y) 位置,矩形的尺寸是 width 和 height ,fillStyle 属性决定矩形的样式。
- * @param x 矩形起始点的 x 轴坐标。
- * @param y 矩形起始点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.fillRect = function (x, y, w, h) {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.fillRect(x, y, w, h);
- // this.$nativeGraphicsContext.fillRect(x, y, w, h);
- };
- /**
- * @private
- * 绘制一段三次贝赛尔曲线路径。该方法需要三个点。 第一、第二个点是控制点,第三个点是结束点。起始点是当前路径的最后一个点,
- * 绘制贝赛尔曲线前,可以通过调用 moveTo() 进行修改。
- * @param cp1x 第一个控制点的 x 轴坐标。
- * @param cp1y 第一个控制点的 y 轴坐标。
- * @param cp2x 第二个控制点的 x 轴坐标。
- * @param cp2y 第二个控制点的 y 轴坐标。
- * @param x 结束点的 x 轴坐标。
- * @param y 结束点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
- // this.$nativeGraphicsContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
- };
- /**
- * @private
- * 根据当前的画线样式,绘制当前或已经存在的路径的方法。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.stroke = function () {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.stroke();
- // this.$nativeGraphicsContext.stroke();
- };
- /**
- * @private
- * 使用当前的绘画样式,描绘一个起点在 (x, y) 、宽度为 w 、高度为 h 的矩形的方法。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.strokeRect = function (x, y, w, h) {
- //console.log("strokeRect");
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.strokeRect(x, y, w, h);
- // this.$nativeGraphicsContext.strokeRect(x, y, w, h);
- };
- /**
- * @private
- * 清空子路径列表开始一个新路径。 当你想创建一个新的路径时,调用此方法。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.beginPath = function () {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeGraphicsContext);
- native.$cmdManager.beginPath();
- };
- /**
- * @private
- * 根据控制点和半径绘制一段圆弧路径,使用直线连接前一个点。
- * @param x1 第一个控制点的 x 轴坐标。
- * @param y1 第一个控制点的 y 轴坐标。
- * @param x2 第二个控制点的 x 轴坐标。
- * @param y2 第二个控制点的 y 轴坐标。
- * @param radius 圆弧的半径。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.arcTo = function (x1, y1, x2, y2, radius) {
- this.checkSurface();
- this.$nativeGraphicsContext.arcTo(x1, y1, x2, y2, radius);
- };
- /**
- * @private
- * 使用方法参数描述的矩阵多次叠加当前的变换矩阵。
- * @param a 水平缩放。
- * @param b 水平倾斜。
- * @param c 垂直倾斜。
- * @param d 垂直缩放。
- * @param tx 水平移动。
- * @param ty 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.transform = function (a, b, c, d, tx, ty) {
- this.$matrix.append(a, b, c, d, tx, ty);
- this.setTransformToNative();
- };
- /**
- * @private
- * 通过在网格中移动 surface 和 surface 原点 x 水平方向、原点 y 垂直方向,添加平移变换
- * @param x 水平移动。
- * @param y 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.translate = function (x, y) {
- this.$matrix.translate(x, y);
- this.setTransformToNative();
- };
- /**
- * @private
- * 根据 x 水平方向和 y 垂直方向,为 surface 单位添加缩放变换。
- * @param x 水平方向的缩放因子。
- * @param y 垂直方向的缩放因子。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.scale = function (x, y) {
- this.$matrix.scale(x, y);
- this.setTransformToNative();
- };
- /**
- * @private
- * 在变换矩阵中增加旋转,角度变量表示一个顺时针旋转角度并且用弧度表示。
- * @param angle 顺时针旋转的弧度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.rotate = function (angle) {
- this.$matrix.rotate(angle);
- this.setTransformToNative();
- };
- /**
- * @private
- * 恢复到最近的绘制样式状态,此状态是通过 save() 保存到”状态栈“中最新的元素。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.restore = function () {
- //console.log("restore");
- if (this.$saveCount > 0) {
- if (this.$saveList.length) {
- var data = this.$saveList.pop();
- for (var key in data) {
- this[key] = data[key];
- }
- this.setTransformToNative();
- }
- var index = this.$clipList.indexOf(this.$saveCount);
- if (index != -1) {
- var length_3 = this.$clipList.length;
- this.$clipList.splice(index, length_3 - index);
- for (; index < length_3; index++) {
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.popClip();
- }
- }
- this.$saveCount--;
- }
- };
- /**
- * @private
- * 使用栈保存当前的绘画样式状态,你可以使用 restore() 恢复任何改变。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.save = function () {
- //console.log("save");
- var transformMatrix = new egret.Matrix();
- transformMatrix.copyFrom(this.$matrix);
- this.$saveList.push({
- lineWidth: this.$lineWidth,
- globalCompositeOperation: this.$globalCompositeOperation,
- globalAlpha: this.$globalAlpha,
- strokeStyle: this.$strokeStyle,
- fillStyle: this.$fillStyle,
- font: this.$font,
- $matrix: transformMatrix
- });
- this.$saveCount++;
- };
- /**
- * @private
- * 从当前路径创建一个剪切路径。在 clip() 调用之后,绘制的所有信息只会出现在剪切路径内部。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.clip = function (fillRule) {
- if (this.$clipRect.width > 0 && this.$clipRect.height > 0) {
- //console.log("push clip" + this.$clipRect.x + " " + this.$clipRect.y + " " + this.$clipRect.width + " " + this.$clipRect.height);
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.pushClip(this.$clipRect.x, this.$clipRect.y, this.$clipRect.width, this.$clipRect.height);
- this.$clipRect.setEmpty();
- this.$clipList.push(this.$saveCount);
- }
- };
- /**
- * @private
- * 设置指定矩形区域内(以 点 (x, y) 为起点,范围是(width, height) )所有像素变成透明,并擦除之前绘制的所有内容。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.clearRect = function (x, y, width, height) {
- //console.log("clearScreen");
- this.checkSurface();
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.clearScreen(0, 0, 0, 0);
- };
- /**
- * @private
- * 重新设置当前的变换为单位矩阵,并使用同样的变量调用 transform() 方法。
- * @param a 水平缩放。
- * @param b 水平倾斜。
- * @param c 垂直倾斜。
- * @param d 垂直缩放。
- * @param tx 水平移动。
- * @param ty 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.setTransform = function (a, b, c, d, tx, ty) {
- this.$matrix.setTo(a, b, c, d, tx, ty);
- this.setTransformToNative();
- };
- NativeRenderTextureRenderContext.prototype.setTransformToNative = function () {
- var m = this.$matrix;
- //console.log("setTransformToNative::a=" + m.a + " b=" + m.b + " c=" + m.c + " d=" + m.d + " tx=" + m.tx + " ty=" + m.ty);
- this.checkSurface();
- // this.$nativeContext.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
- };
- /**
- * @private
- * 创建一个沿参数坐标指定的直线的渐变。该方法返回一个线性的 GraphicsGradient 对象。
- * @param x0 起点的 x 轴坐标。
- * @param y0 起点的 y 轴坐标。
- * @param x1 终点的 x 轴坐标。
- * @param y1 终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.createLinearGradient = function (x0, y0, x1, y1) {
- this.checkSurface();
- return this.$nativeGraphicsContext.createLinearGradient(x0, y0, x1, y1);
- };
- /**
- * @private
- * 根据参数确定的两个圆的坐标,创建一个放射性渐变。该方法返回一个放射性的 GraphicsGradient。
- * @param x0 开始圆形的 x 轴坐标。
- * @param y0 开始圆形的 y 轴坐标。
- * @param r0 开始圆形的半径。
- * @param x1 结束圆形的 x 轴坐标。
- * @param y1 结束圆形的 y 轴坐标。
- * @param r1 结束圆形的半径。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) {
- this.checkSurface();
- return this.$nativeGraphicsContext.createRadialGradient(x0, y0, r0, x1, y1, r1);
- };
- /**
- * @private
- * 在(x,y)位置绘制(填充)文本。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.fillText = function (text, x, y, maxWidth) {
- //console.log("drawText" + text);
- native.$cmdManager.setContext(egret_native.Label);
- var s1 = native.$cmdManager.pushString(this.$fontFamily);
- var s2 = native.$cmdManager.pushString("");
- native.$cmdManager.createLabel(s1, this.$fontSize, s2, this.$hasStrokeText ? this.$lineWidth : 0);
- this.$hasStrokeText = false;
- var s3 = native.$cmdManager.pushString(text);
- native.$cmdManager.drawText(s3, x, y);
- };
- NativeRenderTextureRenderContext.prototype.strokeText = function (text, x, y, maxWidth) {
- this.$hasStrokeText = true;
- };
- /**
- * @private
- * 测量指定文本宽度,返回 TextMetrics 对象。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.measureText = function (text) {
- native.$cmdManager.setContext(egret_native.Label);
- var s1 = native.$cmdManager.pushString(this.$fontFamily);
- var s2 = native.$cmdManager.pushString("");
- native.$cmdManager.createLabel(s1, this.$fontSize, s2, this.$hasStrokeText ? this.$lineWidth : 0);
- return { width: egret_native.Label.getTextSize(text)[0] };
- };
- /**
- * @private
- * 注意:如果要对绘制的图片进行缩放,出于性能优化考虑,系统不会主动去每次重置imageSmoothingEnabled属性,因此您在调用drawImage()方法前请务必
- * 确保 imageSmoothingEnabled 已被重置为正常的值,否则有可能沿用上个显示对象绘制过程留下的值。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.drawImage = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight) {
- var bitmapData;
- var isNative;
- if (image.$nativeRenderTexture) {
- bitmapData = image.$nativeRenderTexture;
- isNative = true;
- }
- else {
- bitmapData = image;
- isNative = false;
- }
- if (!bitmapData) {
- return;
- }
- if (arguments.length == 3) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- offsetX = 0;
- offsetY = 0;
- width = surfaceImageWidth = image.width;
- height = surfaceImageHeight = image.height;
- }
- else if (arguments.length == 5) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- surfaceImageWidth = width;
- surfaceImageHeight = height;
- offsetX = 0;
- offsetY = 0;
- width = image.width;
- height = image.height;
- }
- else {
- if (width == void 0) {
- width = image.width;
- }
- if (height == void 0) {
- height = image.height;
- }
- if (surfaceOffsetX == void 0) {
- surfaceOffsetX = 0;
- }
- if (surfaceOffsetY == void 0) {
- surfaceOffsetY = 0;
- }
- if (surfaceImageWidth == void 0) {
- surfaceImageWidth = width;
- }
- if (surfaceImageHeight == void 0) {
- surfaceImageHeight = height;
- }
- }
- //console.log("drawImage::" + offsetX + " " + offsetY + " " + width + " " + height + " " + surfaceOffsetX + " " + surfaceOffsetY + " " + surfaceImageWidth + " " + surfaceImageHeight);
- this.checkSurface();
- var imageAdress;
- if (!isNative) {
- if (!bitmapData._native_tex_loc) {
- bitmapData._native_tex_loc = bitmapData.___native_texture__p;
- }
- imageAdress = bitmapData._native_tex_loc;
- }
- else {
- imageAdress = bitmapData.___native_texture__p;
- }
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.drawImage(imageAdress, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight);
- };
- /**
- * @private
- * 基于指定的源图象(BitmapData)创建一个模板,通过repetition参数指定源图像在什么方向上进行重复,返回一个GraphicsPattern对象。
- * @param bitmapData 做为重复图像源的 BitmapData 对象。
- * @param repetition 指定如何重复图像。
- * 可能的值有:"repeat" (两个方向重复),"repeat-x" (仅水平方向重复),"repeat-y" (仅垂直方向重复),"no-repeat" (不重复).
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.createPattern = function (image, repetition) {
- return null;
- };
- /**
- * @private
- * 返回一个 ImageData 对象,用来描述canvas区域隐含的像素数据,这个区域通过矩形表示,起始点为(sx, sy)、宽为sw、高为sh。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeRenderTextureRenderContext.prototype.getImageData = function (sx, sy, sw, sh) {
- native.$cmdManager.flush();
- var res;
- if (native.$currentSurface == this.surface) {
- if (native.$currentSurface != null) {
- native.$currentSurface.end();
- }
- }
- res = this.surface.getImageData(sx, sy, sw, sh);
- if (res.pixelData) {
- res.data = res.pixelData;
- }
- return res;
- };
- NativeRenderTextureRenderContext.prototype.checkSurface = function () {
- //todo 暂时先写这里
- if (native.$currentSurface != this.surface) {
- if (native.$currentSurface != null) {
- native.$currentSurface.end();
- }
- if (this.surface) {
- this.surface.begin();
- }
- }
- };
- return NativeRenderTextureRenderContext;
- }(egret.HashObject));
- native.NativeRenderTextureRenderContext = NativeRenderTextureRenderContext;
- __reflect(NativeRenderTextureRenderContext.prototype, "egret.native.NativeRenderTextureRenderContext");
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- var blendModesForGL = {
- "source-over": [1, 771],
- "lighter": [770, 1],
- "destination-out": [0, 771],
- "destination-in": [0, 770]
- };
- /**
- * @version Egret 2.4
- * @platform Web,Native
- * @private
- */
- var OldNativeRenderTextureRenderContext = (function (_super) {
- __extends(OldNativeRenderTextureRenderContext, _super);
- function OldNativeRenderTextureRenderContext() {
- var _this = _super.apply(this, arguments) || this;
- _this.$matrix = new egret.Matrix();
- _this.$nativeContext = egret_native.Graphics;
- _this.$nativeGraphicsContext = egret_native.rastergl;
- _this.$globalCompositeOperation = "source-over";
- _this.$globalAlpha = 1;
- _this.$lineWidth = 0;
- _this.$strokeStyle = "#000000";
- _this.$fillStyle = "#000000";
- _this.$font = "normal normal 10px sans-serif";
- _this.$fontSize = 10;
- _this.$fontFamily = "";
- _this.clipRectArray = null;
- _this.$saveList = [];
- _this.$clipRect = new egret.Rectangle();
- _this.$saveCount = 0;
- _this.$clipList = [];
- _this.$hasStrokeText = false;
- return _this;
- }
- Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "globalCompositeOperation", {
- /**
- * @private
- * 设置新图像如何绘制到已有的图像上的规制
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$globalCompositeOperation;
- },
- set: function (value) {
- this.$globalCompositeOperation = value;
- var arr = blendModesForGL[value];
- if (arr) {
- this.checkSurface();
- this.$nativeContext.setBlendArg(arr[0], arr[1]);
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "globalAlpha", {
- /**
- * @private
- * 设置接下来绘图填充的整体透明度
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$globalAlpha;
- },
- set: function (value) {
- this.$globalAlpha = value;
- this.checkSurface();
- this.$nativeContext.setGlobalAlpha(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "lineWidth", {
- /**
- * @private
- * 设置线条粗细,以像素为单位。设置为0,负数,Infinity 或 NaN 将会被忽略。
- * @default 1
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$lineWidth;
- },
- set: function (value) {
- //console.log("set lineWidth" + value);
- this.$lineWidth = value;
- this.$nativeContext.lineWidth = value;
- this.checkSurface();
- this.$nativeGraphicsContext.lineWidth = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "strokeStyle", {
- /**
- * @private
- * 设置要在图形边线填充的颜色或样式
- * @default "#000000"
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$strokeStyle;
- },
- set: function (value) {
- this.$strokeStyle = value;
- if (value != null) {
- if (value.indexOf("rgba") != -1) {
- value = this.$parseRGBA(value);
- }
- else if (value.indexOf("rgb") != -1) {
- value = this.$parseRGB(value);
- }
- egret_native.Label.setStrokeColor(parseInt(value.replace("#", "0x")));
- }
- this.checkSurface();
- this.$nativeGraphicsContext.strokeStyle = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "fillStyle", {
- /**
- * @private
- * 设置要在图形内部填充的颜色或样式
- * @default "#000000"
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$fillStyle;
- },
- set: function (value) {
- this.$fillStyle = value;
- if (value != null) {
- if (value.indexOf("rgba") != -1) {
- value = this.$parseRGBA(value);
- }
- else if (value.indexOf("rgb") != -1) {
- value = this.$parseRGB(value);
- }
- egret_native.Label.setTextColor(parseInt(value.replace("#", "0x")));
- }
- this.checkSurface();
- this.$nativeGraphicsContext.fillStyle = value;
- },
- enumerable: true,
- configurable: true
- });
- OldNativeRenderTextureRenderContext.prototype.$fillColorStr = function (s) {
- if (s.length < 2) {
- s = "0" + s;
- }
- return s;
- };
- OldNativeRenderTextureRenderContext.prototype.$parseRGBA = function (str) {
- var index = str.indexOf("(");
- str = str.slice(index + 1, str.length - 1);
- var arr = str.split(",");
- var a = parseInt((parseFloat(arr[3]) * 255)).toString(16);
- var r = parseInt(arr[0]).toString(16);
- var g = parseInt(arr[1]).toString(16);
- var b = parseInt(arr[2]).toString(16);
- str = "#" + this.$fillColorStr(a) + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
- return str;
- };
- OldNativeRenderTextureRenderContext.prototype.$parseRGB = function (str) {
- var index = str.indexOf("(");
- str = str.slice(index + 1, str.length - 1);
- var arr = str.split(",");
- var r = parseInt(arr[0]).toString(16);
- var g = parseInt(arr[1]).toString(16);
- var b = parseInt(arr[2]).toString(16);
- str = "#" + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
- return str;
- };
- Object.defineProperty(OldNativeRenderTextureRenderContext.prototype, "font", {
- /**
- * @private
- * 当前的字体样式
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$font;
- },
- set: function (value) {
- this.$font = value;
- var arr = value.split(" ");
- var sizeTxt = arr[2];
- if (sizeTxt.indexOf("px") != -1) {
- this.$fontSize = parseInt(sizeTxt.replace("px", ""));
- }
- if (egret.useFontMapping) {
- var fontFamilyText = void 0;
- if (arr.length == 4) {
- fontFamilyText = arr[3];
- }
- else {
- fontFamilyText = arr.slice(3).join(" ");
- }
- if (fontFamilyText.indexOf(", ") != -1) {
- arr = fontFamilyText.split(", ");
- }
- else if (fontFamilyText.indexOf(",") != -1) {
- arr = fontFamilyText.split(",");
- var length_4 = arr.length;
- for (var i = 0; i < length_4; i++) {
- var fontFamily = arr[i];
- //暂时先不考虑带有引号的情况
- if (egret.fontMapping[fontFamily]) {
- this.$fontFamily = egret.fontMapping[fontFamily];
- return;
- }
- }
- }
- else {
- this.$fontFamily = egret.fontMapping[fontFamilyText];
- }
- if (!this.$fontFamily) {
- this.$fontFamily = "/system/fonts/DroidSansFallback.ttf";
- }
- }
- else {
- //兼容旧版本直接将 default_fontFamily 设置为字体路径的情况
- this.$fontFamily = egret.TextField.default_fontFamily;
- }
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @private
- * 绘制一段圆弧路径。圆弧路径的圆心在 (x, y) 位置,半径为 r ,根据anticlockwise (默认为顺时针)指定的方向从 startAngle 开始绘制,到 endAngle 结束。
- * @param x 圆弧中心(圆心)的 x 轴坐标。
- * @param y 圆弧中心(圆心)的 y 轴坐标。
- * @param radius 圆弧的半径。
- * @param startAngle 圆弧的起始点, x轴方向开始计算,单位以弧度表示。
- * @param endAngle 圆弧的重点, 单位以弧度表示。
- * @param anticlockwise 如果为 true,逆时针绘制圆弧,反之,顺时针绘制。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
- this.checkSurface();
- this.$nativeGraphicsContext.arc(x, y, radius, startAngle, endAngle, anticlockwise);
- };
- /**
- * @private
- * 绘制一段二次贝塞尔曲线路径。它需要2个点。 第一个点是控制点,第二个点是终点。 起始点是当前路径最新的点,当创建二次贝赛尔曲线之前,可以使用 moveTo() 方法进行改变。
- * @param cpx 控制点的 x 轴坐标。
- * @param cpy 控制点的 y 轴坐标。
- * @param x 终点的 x 轴坐标。
- * @param y 终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
- this.checkSurface();
- this.$nativeGraphicsContext.quadraticCurveTo(cpx, cpy, x, y);
- };
- /**
- * @private
- * 使用直线连接子路径的终点到x,y坐标。
- * @param x 直线终点的 x 轴坐标。
- * @param y 直线终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.lineTo = function (x, y) {
- this.checkSurface();
- this.$nativeGraphicsContext.lineTo(x, y);
- };
- /**
- * @private
- * 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
- * @param fillRule 一种算法,决定点是在路径内还是在路径外。允许的值:
- * "nonzero": 非零环绕规则, 默认的规则。
- * "evenodd": 奇偶环绕规则。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.fill = function (fillRule) {
- this.checkSurface();
- this.$nativeGraphicsContext.fill(fillRule);
- };
- /**
- * @private
- * 使笔点返回到当前子路径的起始点。它尝试从当前点到起始点绘制一条直线。如果图形已经是封闭的或者只有一个点,那么此方法不会做任何操作。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.closePath = function () {
- this.checkSurface();
- this.$nativeGraphicsContext.closePath();
- };
- /**
- * @private
- * 创建一段矩形路径,矩形的起点位置是 (x, y) ,尺寸为 width 和 height。矩形的4个点通过直线连接,子路径做为闭合的标记,所以你可以填充或者描边矩形。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.rect = function (x, y, w, h) {
- this.checkSurface();
- this.$nativeGraphicsContext.rect(x, y, w, h);
- this.$clipRect.setTo(x, y, w, h);
- };
- /**
- * @private
- * 将一个新的子路径的起始点移动到(x,y)坐标
- * @param x 点的 x 轴
- * @param y 点的 y 轴
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.moveTo = function (x, y) {
- this.checkSurface();
- this.$nativeGraphicsContext.moveTo(x, y);
- };
- /**
- * @private
- * 绘制一个填充矩形。矩形的起点在 (x, y) 位置,矩形的尺寸是 width 和 height ,fillStyle 属性决定矩形的样式。
- * @param x 矩形起始点的 x 轴坐标。
- * @param y 矩形起始点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.fillRect = function (x, y, w, h) {
- this.checkSurface();
- this.$nativeGraphicsContext.fillRect(x, y, w, h);
- };
- /**
- * @private
- * 绘制一段三次贝赛尔曲线路径。该方法需要三个点。 第一、第二个点是控制点,第三个点是结束点。起始点是当前路径的最后一个点,
- * 绘制贝赛尔曲线前,可以通过调用 moveTo() 进行修改。
- * @param cp1x 第一个控制点的 x 轴坐标。
- * @param cp1y 第一个控制点的 y 轴坐标。
- * @param cp2x 第二个控制点的 x 轴坐标。
- * @param cp2y 第二个控制点的 y 轴坐标。
- * @param x 结束点的 x 轴坐标。
- * @param y 结束点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
- this.checkSurface();
- this.$nativeGraphicsContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
- };
- /**
- * @private
- * 根据当前的画线样式,绘制当前或已经存在的路径的方法。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.stroke = function () {
- this.checkSurface();
- this.$nativeGraphicsContext.stroke();
- };
- /**
- * @private
- * 使用当前的绘画样式,描绘一个起点在 (x, y) 、宽度为 w 、高度为 h 的矩形的方法。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.strokeRect = function (x, y, w, h) {
- //console.log("strokeRect");
- this.checkSurface();
- this.$nativeGraphicsContext.strokeRect(x, y, w, h);
- };
- /**
- * @private
- * 清空子路径列表开始一个新路径。 当你想创建一个新的路径时,调用此方法。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.beginPath = function () {
- this.checkSurface();
- this.$nativeGraphicsContext.beginPath();
- };
- /**
- * @private
- * 根据控制点和半径绘制一段圆弧路径,使用直线连接前一个点。
- * @param x1 第一个控制点的 x 轴坐标。
- * @param y1 第一个控制点的 y 轴坐标。
- * @param x2 第二个控制点的 x 轴坐标。
- * @param y2 第二个控制点的 y 轴坐标。
- * @param radius 圆弧的半径。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.arcTo = function (x1, y1, x2, y2, radius) {
- this.checkSurface();
- this.$nativeGraphicsContext.arcTo(x1, y1, x2, y2, radius);
- };
- /**
- * @private
- * 使用方法参数描述的矩阵多次叠加当前的变换矩阵。
- * @param a 水平缩放。
- * @param b 水平倾斜。
- * @param c 垂直倾斜。
- * @param d 垂直缩放。
- * @param tx 水平移动。
- * @param ty 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.transform = function (a, b, c, d, tx, ty) {
- this.$matrix.append(a, b, c, d, tx, ty);
- this.setTransformToNative();
- };
- /**
- * @private
- * 通过在网格中移动 surface 和 surface 原点 x 水平方向、原点 y 垂直方向,添加平移变换
- * @param x 水平移动。
- * @param y 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.translate = function (x, y) {
- this.$matrix.translate(x, y);
- this.setTransformToNative();
- };
- /**
- * @private
- * 根据 x 水平方向和 y 垂直方向,为 surface 单位添加缩放变换。
- * @param x 水平方向的缩放因子。
- * @param y 垂直方向的缩放因子。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.scale = function (x, y) {
- this.$matrix.scale(x, y);
- this.setTransformToNative();
- };
- /**
- * @private
- * 在变换矩阵中增加旋转,角度变量表示一个顺时针旋转角度并且用弧度表示。
- * @param angle 顺时针旋转的弧度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.rotate = function (angle) {
- this.$matrix.rotate(angle);
- this.setTransformToNative();
- };
- /**
- * @private
- * 恢复到最近的绘制样式状态,此状态是通过 save() 保存到”状态栈“中最新的元素。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.restore = function () {
- //console.log("restore");
- if (this.$saveCount > 0) {
- if (this.$saveList.length) {
- var data = this.$saveList.pop();
- for (var key in data) {
- this[key] = data[key];
- }
- this.setTransformToNative();
- }
- var index = this.$clipList.indexOf(this.$saveCount);
- if (index != -1) {
- var length_5 = this.$clipList.length;
- this.$clipList.splice(index, length_5 - index);
- for (; index < length_5; index++) {
- this.checkSurface();
- this.$nativeContext.popClip();
- }
- }
- this.$saveCount--;
- }
- };
- /**
- * @private
- * 使用栈保存当前的绘画样式状态,你可以使用 restore() 恢复任何改变。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.save = function () {
- //console.log("save");
- var transformMatrix = new egret.Matrix();
- transformMatrix.copyFrom(this.$matrix);
- this.$saveList.push({
- lineWidth: this.$lineWidth,
- globalCompositeOperation: this.$globalCompositeOperation,
- globalAlpha: this.$globalAlpha,
- strokeStyle: this.$strokeStyle,
- fillStyle: this.$fillStyle,
- font: this.$font,
- $matrix: transformMatrix
- });
- this.$saveCount++;
- };
- /**
- * @private
- * 从当前路径创建一个剪切路径。在 clip() 调用之后,绘制的所有信息只会出现在剪切路径内部。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.clip = function (fillRule) {
- if (this.$clipRect.width > 0 && this.$clipRect.height > 0) {
- //console.log("push clip" + this.$clipRect.x + " " + this.$clipRect.y + " " + this.$clipRect.width + " " + this.$clipRect.height);
- this.checkSurface();
- this.$nativeContext.pushClip(this.$clipRect.x, this.$clipRect.y, this.$clipRect.width, this.$clipRect.height);
- this.$clipRect.setEmpty();
- this.$clipList.push(this.$saveCount);
- }
- };
- /**
- * @private
- * 设置指定矩形区域内(以 点 (x, y) 为起点,范围是(width, height) )所有像素变成透明,并擦除之前绘制的所有内容。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.clearRect = function (x, y, width, height) {
- //console.log("clearScreen");
- this.checkSurface();
- this.$nativeContext.clearScreen(0, 0, 0);
- };
- /**
- * @private
- * 重新设置当前的变换为单位矩阵,并使用同样的变量调用 transform() 方法。
- * @param a 水平缩放。
- * @param b 水平倾斜。
- * @param c 垂直倾斜。
- * @param d 垂直缩放。
- * @param tx 水平移动。
- * @param ty 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.setTransform = function (a, b, c, d, tx, ty) {
- this.$matrix.setTo(a, b, c, d, tx, ty);
- this.setTransformToNative();
- };
- OldNativeRenderTextureRenderContext.prototype.setTransformToNative = function () {
- var m = this.$matrix;
- //console.log("setTransformToNative::a=" + m.a + " b=" + m.b + " c=" + m.c + " d=" + m.d + " tx=" + m.tx + " ty=" + m.ty);
- this.checkSurface();
- this.$nativeContext.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
- };
- /**
- * @private
- * 创建一个沿参数坐标指定的直线的渐变。该方法返回一个线性的 GraphicsGradient 对象。
- * @param x0 起点的 x 轴坐标。
- * @param y0 起点的 y 轴坐标。
- * @param x1 终点的 x 轴坐标。
- * @param y1 终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.createLinearGradient = function (x0, y0, x1, y1) {
- this.checkSurface();
- return this.$nativeGraphicsContext.createLinearGradient(x0, y0, x1, y1);
- };
- /**
- * @private
- * 根据参数确定的两个圆的坐标,创建一个放射性渐变。该方法返回一个放射性的 GraphicsGradient。
- * @param x0 开始圆形的 x 轴坐标。
- * @param y0 开始圆形的 y 轴坐标。
- * @param r0 开始圆形的半径。
- * @param x1 结束圆形的 x 轴坐标。
- * @param y1 结束圆形的 y 轴坐标。
- * @param r1 结束圆形的半径。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) {
- this.checkSurface();
- return this.$nativeGraphicsContext.createRadialGradient(x0, y0, r0, x1, y1, r1);
- };
- /**
- * @private
- * 在(x,y)位置绘制(填充)文本。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.fillText = function (text, x, y, maxWidth) {
- //console.log("drawText" + text);
- egret_native.Label.createLabel(this.$fontFamily, this.$fontSize, "", this.$hasStrokeText ? this.$lineWidth : 0);
- this.$hasStrokeText = false;
- egret_native.Label.drawText(text, x, y);
- };
- OldNativeRenderTextureRenderContext.prototype.strokeText = function (text, x, y, maxWidth) {
- this.$hasStrokeText = true;
- };
- /**
- * @private
- * 测量指定文本宽度,返回 TextMetrics 对象。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.measureText = function (text) {
- egret_native.Label.createLabel(this.$fontFamily, this.$fontSize, "", this.$hasStrokeText ? this.$lineWidth : 0);
- return { width: egret_native.Label.getTextSize(text)[0] };
- };
- /**
- * @private
- * 注意:如果要对绘制的图片进行缩放,出于性能优化考虑,系统不会主动去每次重置imageSmoothingEnabled属性,因此您在调用drawImage()方法前请务必
- * 确保 imageSmoothingEnabled 已被重置为正常的值,否则有可能沿用上个显示对象绘制过程留下的值。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.drawImage = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight) {
- var bitmapData;
- var isNative;
- if (image.$nativeRenderTexture) {
- bitmapData = image.$nativeRenderTexture;
- isNative = true;
- }
- else {
- bitmapData = image;
- isNative = false;
- }
- if (!bitmapData) {
- return;
- }
- if (arguments.length == 3) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- offsetX = 0;
- offsetY = 0;
- width = surfaceImageWidth = image.width;
- height = surfaceImageHeight = image.height;
- }
- else if (arguments.length == 5) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- surfaceImageWidth = width;
- surfaceImageHeight = height;
- offsetX = 0;
- offsetY = 0;
- width = image.width;
- height = image.height;
- }
- else {
- if (width == void 0) {
- width = image.width;
- }
- if (height == void 0) {
- height = image.height;
- }
- if (surfaceOffsetX == void 0) {
- surfaceOffsetX = 0;
- }
- if (surfaceOffsetY == void 0) {
- surfaceOffsetY = 0;
- }
- if (surfaceImageWidth == void 0) {
- surfaceImageWidth = width;
- }
- if (surfaceImageHeight == void 0) {
- surfaceImageHeight = height;
- }
- }
- //console.log("drawImage::" + offsetX + " " + offsetY + " " + width + " " + height + " " + surfaceOffsetX + " " + surfaceOffsetY + " " + surfaceImageWidth + " " + surfaceImageHeight);
- this.checkSurface();
- this.$nativeContext.drawImage(bitmapData, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight);
- };
- /**
- * @private
- * 基于指定的源图象(BitmapData)创建一个模板,通过repetition参数指定源图像在什么方向上进行重复,返回一个GraphicsPattern对象。
- * @param bitmapData 做为重复图像源的 BitmapData 对象。
- * @param repetition 指定如何重复图像。
- * 可能的值有:"repeat" (两个方向重复),"repeat-x" (仅水平方向重复),"repeat-y" (仅垂直方向重复),"no-repeat" (不重复).
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.createPattern = function (image, repetition) {
- return null;
- };
- /**
- * @private
- * 返回一个 ImageData 对象,用来描述canvas区域隐含的像素数据,这个区域通过矩形表示,起始点为(sx, sy)、宽为sw、高为sh。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeRenderTextureRenderContext.prototype.getImageData = function (sx, sy, sw, sh) {
- var res;
- if (native.$currentSurface == this.surface) {
- if (native.$currentSurface != null) {
- native.$currentSurface.end();
- }
- }
- res = this.surface.getImageData(sx, sy, sw, sh);
- if (res.pixelData) {
- res.data = res.pixelData;
- }
- return res;
- };
- OldNativeRenderTextureRenderContext.prototype.checkSurface = function () {
- //todo 暂时先写这里
- if (native.$currentSurface != this.surface) {
- if (native.$currentSurface != null) {
- native.$currentSurface.end();
- }
- if (this.surface) {
- this.surface.begin();
- }
- }
- };
- return OldNativeRenderTextureRenderContext;
- }(egret.HashObject));
- native.OldNativeRenderTextureRenderContext = OldNativeRenderTextureRenderContext;
- __reflect(OldNativeRenderTextureRenderContext.prototype, "egret.native.OldNativeRenderTextureRenderContext");
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- * 呈现最终绘图结果的画布
- */
- var NativeRenderTexture = (function (_super) {
- __extends(NativeRenderTexture, _super);
- /**
- * @private
- */
- function NativeRenderTexture() {
- var _this = _super.call(this) || this;
- _this.$widthReadySet = false;
- _this.$heightReadySet = false;
- _this.$isRoot = false;
- _this.$isDispose = false;
- _this.renderContext = native.$supportCmdBatch ? new native.NativeRenderTextureRenderContext() : new native.OldNativeRenderTextureRenderContext();
- return _this;
- }
- NativeRenderTexture.prototype.toDataURL = function (type) {
- var args = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- args[_i - 1] = arguments[_i];
- }
- if (this.$nativeRenderTexture) {
- return this.$nativeRenderTexture.toDataURL.apply(this.$nativeRenderTexture, arguments);
- }
- return null;
- };
- NativeRenderTexture.prototype.saveToFile = function (type, filePath) {
- if (this.$nativeRenderTexture && this.$nativeRenderTexture.saveToFile) {
- this.$nativeRenderTexture.saveToFile(type, filePath);
- }
- };
- Object.defineProperty(NativeRenderTexture.prototype, "width", {
- /**
- * @private
- * @inheritDoc
- */
- get: function () {
- return this.$width;
- },
- set: function (value) {
- if (this.$width == value) {
- return;
- }
- this.$width = value;
- if (!this.$isDispose) {
- this.$widthReadySet = true;
- this.createRenderTexture();
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeRenderTexture.prototype, "height", {
- /**
- * @private
- * @inheritDoc
- */
- get: function () {
- return this.$height;
- },
- set: function (value) {
- if (this.$height == value) {
- return;
- }
- this.$height = value;
- if (!this.$isDispose) {
- this.$heightReadySet = true;
- this.createRenderTexture();
- }
- },
- enumerable: true,
- configurable: true
- });
- NativeRenderTexture.prototype.getImageData = function (sx, sy, sw, sh) {
- if (sx != Math.floor(sx)) {
- sx = Math.floor(sx);
- sw++;
- }
- if (sy != Math.floor(sy)) {
- sy = Math.floor(sy);
- sh++;
- }
- return this.$nativeRenderTexture.getPixels(sx, sy, sw, sh);
- };
- NativeRenderTexture.prototype.createRenderTexture = function () {
- if (this.$isRoot) {
- return;
- }
- if (this.$nativeRenderTexture || (this.$widthReadySet && this.$heightReadySet)) {
- if (this.$nativeRenderTexture) {
- this.$nativeRenderTexture.dispose();
- }
- //console.log("new RenderTexture" + this.id);
- this.$nativeRenderTexture = new egret_native.RenderTexture(this.$width, this.$height);
- this.renderContext.globalAlpha = 1;
- this.renderContext.globalCompositeOperation = "source-over";
- this.renderContext.setTransform(1, 0, 0, 1, 0, 0);
- this.$widthReadySet = false;
- this.$heightReadySet = false;
- }
- };
- NativeRenderTexture.prototype.begin = function () {
- if (this.$nativeRenderTexture) {
- //console.log("begin" + this.id);
- native.$currentSurface = this;
- if (this.$nativeRenderTexture.getIn) {
- this.$nativeRenderTexture.getIn();
- }
- else {
- this.$nativeRenderTexture.begin();
- }
- }
- };
- NativeRenderTexture.prototype.end = function () {
- if (this.$nativeRenderTexture) {
- //console.log("end" + this.id);
- native.$currentSurface = null;
- if (this.$nativeRenderTexture.getOut) {
- this.$nativeRenderTexture.getOut();
- }
- else {
- this.$nativeRenderTexture.end();
- }
- }
- };
- NativeRenderTexture.prototype.getContext = function (type) {
- return this.renderContext;
- };
- return NativeRenderTexture;
- }(egret.HashObject));
- native.NativeRenderTexture = NativeRenderTexture;
- __reflect(NativeRenderTexture.prototype, "egret.native.NativeRenderTexture");
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * 创建一个RenderTexture。
- */
- function createRenderTexture(width, height) {
- var result = new native.NativeRenderTexture();
- if (!isNaN(width) && !isNaN(height)) {
- result.width = width;
- result.height = height;
- }
- return result;
- }
- var sharedRenderTexture;
- /**
- * @private
- * NativeRenderTexture渲染器
- */
- var NativeRenderTextureRenderBuffer = (function () {
- function NativeRenderTextureRenderBuffer(width, height) {
- this.surface = createRenderTexture(width, height);
- this.context = this.surface.getContext("2d");
- }
- Object.defineProperty(NativeRenderTextureRenderBuffer.prototype, "width", {
- /**
- * 渲染缓冲的宽度,以像素为单位。
- * @readOnly
- */
- get: function () {
- return this.surface.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeRenderTextureRenderBuffer.prototype, "height", {
- /**
- * 渲染缓冲的高度,以像素为单位。
- * @readOnly
- */
- get: function () {
- return this.surface.height;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * 改变渲染缓冲的大小并清空缓冲区
- * @param width 改变后的宽
- * @param height 改变后的高
- * @param useMaxSize 若传入true,则将改变后的尺寸与已有尺寸对比,保留较大的尺寸。
- */
- NativeRenderTextureRenderBuffer.prototype.resize = function (width, height, useMaxSize) {
- var surface = this.surface;
- if (useMaxSize) {
- if (surface.width < width) {
- surface.width = width;
- }
- if (surface.height < height) {
- surface.height = height;
- }
- }
- else {
- if (surface.width != width) {
- surface.width = width;
- }
- if (surface.height != height) {
- surface.height = height;
- }
- }
- this.clear();
- };
- /**
- * 改变渲染缓冲为指定大小,但保留原始图像数据
- * @param width 改变后的宽
- * @param height 改变后的高
- * @param offsetX 原始图像数据在改变后缓冲区的绘制起始位置x
- * @param offsetY 原始图像数据在改变后缓冲区的绘制起始位置y
- */
- NativeRenderTextureRenderBuffer.prototype.resizeTo = function (width, height, offsetX, offsetY) {
- if (!sharedRenderTexture) {
- sharedRenderTexture = createRenderTexture();
- }
- var oldContext = this.context;
- var oldSurface = this.surface;
- var newSurface = sharedRenderTexture;
- var newContext = newSurface.getContext("2d");
- sharedRenderTexture = oldSurface;
- this.context = newContext;
- this.surface = newSurface;
- newSurface.width = Math.max(width, 1);
- newSurface.height = Math.max(height, 1);
- newContext.setTransform(1, 0, 0, 1, 0, 0);
- newContext.drawImage(oldSurface, offsetX, offsetY);
- oldSurface.height = 1;
- oldSurface.width = 1;
- };
- NativeRenderTextureRenderBuffer.prototype.setDirtyRegionPolicy = function (state) {
- };
- /**
- * 清空并设置裁切
- * @param regions 矩形列表
- * @param offsetX 矩形要加上的偏移量x
- * @param offsetY 矩形要加上的偏移量y
- */
- NativeRenderTextureRenderBuffer.prototype.beginClip = function (regions, offsetX, offsetY) {
- offsetX = +offsetX || 0;
- offsetY = +offsetY || 0;
- var context = this.context;
- context.save();
- context.beginPath();
- context.setTransform(1, 0, 0, 1, offsetX, offsetY);
- var length = regions.length;
- for (var i = 0; i < length; i++) {
- var region = regions[i];
- context.clearRect(region.minX, region.minY, region.width, region.height);
- context.rect(region.minX, region.minY, region.width, region.height);
- }
- context.clip();
- };
- /**
- * 取消上一次设置的clip。
- */
- NativeRenderTextureRenderBuffer.prototype.endClip = function () {
- this.context.restore();
- };
- /**
- * 获取指定区域的像素
- */
- NativeRenderTextureRenderBuffer.prototype.getPixels = function (x, y, width, height) {
- if (width === void 0) { width = 1; }
- if (height === void 0) { height = 1; }
- return this.context.getImageData(x, y, width, height).data;
- };
- /**
- * 转换成base64字符串,如果图片(或者包含的图片)跨域,则返回null
- * @param type 转换的类型,如: "image/png","image/jpeg"
- */
- NativeRenderTextureRenderBuffer.prototype.toDataURL = function (type, encoderOptions) {
- return this.surface.toDataURL(type, encoderOptions);
- };
- /**
- * 清空缓冲区数据
- */
- NativeRenderTextureRenderBuffer.prototype.clear = function () {
- var width = this.surface.width;
- var height = this.surface.height;
- if (width > 0 && height > 0) {
- this.context.setTransform(1, 0, 0, 1, 0, 0);
- this.context.clearRect(0, 0, width, height);
- }
- };
- /**
- * 销毁绘制对象
- */
- NativeRenderTextureRenderBuffer.prototype.destroy = function () {
- this.surface.width = this.surface.height = 1;
- };
- return NativeRenderTextureRenderBuffer;
- }());
- native.NativeRenderTextureRenderBuffer = NativeRenderTextureRenderBuffer;
- __reflect(NativeRenderTextureRenderBuffer.prototype, "egret.native.NativeRenderTextureRenderBuffer", ["egret.sys.RenderBuffer"]);
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- var blendModesForGL = {
- "source-over": [1, 771],
- "lighter": [770, 1],
- "destination-out": [0, 771],
- "destination-in": [0, 770]
- };
- /**
- * @version Egret 2.4
- * @platform Web,Native
- * @private
- */
- var NativeCanvasRenderContext = (function (_super) {
- __extends(NativeCanvasRenderContext, _super);
- function NativeCanvasRenderContext() {
- var _this = _super.apply(this, arguments) || this;
- _this.$matrix = new egret.Matrix();
- _this.$nativeContext = null;
- _this.$globalCompositeOperation = "source-over";
- _this.$globalAlpha = 1;
- _this.$lineWidth = 0;
- _this.$strokeStyle = "#000000";
- _this.$fillStyle = "#000000";
- _this.$font = "normal normal 10px sans-serif";
- _this.$fontSize = 10;
- _this.$fontFamily = "";
- _this.clipRectArray = null;
- _this.$saveList = [];
- _this.$clipRectArray = [];
- _this.$clipRect = new egret.Rectangle();
- _this.$saveCount = 0;
- _this.$clipList = [];
- _this.savedMatrix = new egret.Matrix();
- _this.$hasStrokeText = false;
- return _this;
- }
- Object.defineProperty(NativeCanvasRenderContext.prototype, "globalCompositeOperation", {
- /**
- * @private
- * 设置新图像如何绘制到已有的图像上的规制
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$globalCompositeOperation;
- },
- set: function (value) {
- this.$globalCompositeOperation = value;
- var arr = blendModesForGL[value];
- if (arr) {
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.setBlendArg(arr[0], arr[1]);
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeCanvasRenderContext.prototype, "globalAlpha", {
- /**
- * @private
- * 设置接下来绘图填充的整体透明度
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$globalAlpha;
- },
- set: function (value) {
- this.$globalAlpha = value;
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.setGlobalAlpha(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeCanvasRenderContext.prototype, "lineWidth", {
- /**
- * @private
- * 设置线条粗细,以像素为单位。设置为0,负数,Infinity 或 NaN 将会被忽略。
- * @default 1
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$lineWidth;
- },
- set: function (value) {
- //console.log("set lineWidth" + value);
- this.$lineWidth = value;
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.setLineWidth(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeCanvasRenderContext.prototype, "strokeStyle", {
- /**
- * @private
- * 设置要在图形边线填充的颜色或样式
- * @default "#000000"
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$strokeStyle;
- },
- set: function (value) {
- this.$strokeStyle = value;
- if (value != null) {
- if (value.indexOf("rgba") != -1) {
- value = this.$parseRGBA(value);
- }
- else if (value.indexOf("rgb") != -1) {
- value = this.$parseRGB(value);
- }
- native.$cmdManager.setContext(egret_native.Label);
- native.$cmdManager.setStrokeColor(parseInt(value.replace("#", "0x")));
- }
- native.$cmdManager.setContext(this.$nativeContext);
- var s1 = native.$cmdManager.pushString(value);
- native.$cmdManager.setStrokeStyle(s1);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeCanvasRenderContext.prototype, "fillStyle", {
- /**
- * @private
- * 设置要在图形内部填充的颜色或样式
- * @default "#000000"
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$fillStyle;
- },
- set: function (value) {
- this.$fillStyle = value;
- if (value != null) {
- if (value.indexOf("rgba") != -1) {
- value = this.$parseRGBA(value);
- }
- else if (value.indexOf("rgb") != -1) {
- value = this.$parseRGB(value);
- }
- native.$cmdManager.setContext(egret_native.Label);
- native.$cmdManager.setTextColor(parseInt(value.replace("#", "0x")));
- }
- native.$cmdManager.setContext(this.$nativeContext);
- var s1 = native.$cmdManager.pushString(value);
- native.$cmdManager.setFillStyle(s1);
- },
- enumerable: true,
- configurable: true
- });
- NativeCanvasRenderContext.prototype.$fillColorStr = function (s) {
- if (s.length < 2) {
- s = "0" + s;
- }
- return s;
- };
- NativeCanvasRenderContext.prototype.$parseRGBA = function (str) {
- var index = str.indexOf("(");
- str = str.slice(index + 1, str.length - 1);
- var arr = str.split(",");
- var a = parseInt((parseFloat(arr[3]) * 255)).toString(16);
- var r = parseInt(arr[0]).toString(16);
- var g = parseInt(arr[1]).toString(16);
- var b = parseInt(arr[2]).toString(16);
- str = "#" + this.$fillColorStr(a) + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
- return str;
- };
- NativeCanvasRenderContext.prototype.$parseRGB = function (str) {
- var index = str.indexOf("(");
- str = str.slice(index + 1, str.length - 1);
- var arr = str.split(",");
- var r = parseInt(arr[0]).toString(16);
- var g = parseInt(arr[1]).toString(16);
- var b = parseInt(arr[2]).toString(16);
- str = "#" + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
- return str;
- };
- Object.defineProperty(NativeCanvasRenderContext.prototype, "font", {
- /**
- * @private
- * 当前的字体样式
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$font;
- },
- set: function (value) {
- this.$font = value;
- var arr = value.split(" ");
- var sizeTxt = arr[2];
- if (sizeTxt.indexOf("px") != -1) {
- this.$fontSize = parseInt(sizeTxt.replace("px", ""));
- }
- if (egret.useFontMapping) {
- var fontFamilyText = void 0;
- if (arr.length == 4) {
- fontFamilyText = arr[3];
- }
- else {
- fontFamilyText = arr.slice(3).join(" ");
- }
- if (fontFamilyText.indexOf(", ") != -1) {
- arr = fontFamilyText.split(", ");
- }
- else if (fontFamilyText.indexOf(",") != -1) {
- arr = fontFamilyText.split(",");
- var length_6 = arr.length;
- for (var i = 0; i < length_6; i++) {
- var fontFamily = arr[i];
- //暂时先不考虑带有引号的情况
- if (egret.fontMapping[fontFamily]) {
- this.$fontFamily = egret.fontMapping[fontFamily];
- return;
- }
- }
- }
- else {
- this.$fontFamily = egret.fontMapping[fontFamilyText];
- }
- if (!this.$fontFamily) {
- this.$fontFamily = "/system/fonts/DroidSansFallback.ttf";
- }
- }
- else {
- //兼容旧版本直接将 default_fontFamily 设置为字体路径的情况
- this.$fontFamily = egret.TextField.default_fontFamily;
- }
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @private
- * 绘制一段圆弧路径。圆弧路径的圆心在 (x, y) 位置,半径为 r ,根据anticlockwise (默认为顺时针)指定的方向从 startAngle 开始绘制,到 endAngle 结束。
- * @param x 圆弧中心(圆心)的 x 轴坐标。
- * @param y 圆弧中心(圆心)的 y 轴坐标。
- * @param radius 圆弧的半径。
- * @param startAngle 圆弧的起始点, x轴方向开始计算,单位以弧度表示。
- * @param endAngle 圆弧的重点, 单位以弧度表示。
- * @param anticlockwise 如果为 true,逆时针绘制圆弧,反之,顺时针绘制。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.arc(x, y, radius, startAngle, endAngle, anticlockwise ? 1 : 0);
- // this.$nativeContext.arc(x, y, radius, startAngle, endAngle, anticlockwise);
- };
- /**
- * @private
- * 绘制一段二次贝塞尔曲线路径。它需要2个点。 第一个点是控制点,第二个点是终点。 起始点是当前路径最新的点,当创建二次贝赛尔曲线之前,可以使用 moveTo() 方法进行改变。
- * @param cpx 控制点的 x 轴坐标。
- * @param cpy 控制点的 y 轴坐标。
- * @param x 终点的 x 轴坐标。
- * @param y 终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
- //console.log("quadraticCurveTo " + cpx + " " + cpy + " " + x + " " + y);
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.quadraticCurveTo(cpx, cpy, x, y);
- // this.$nativeContext.quadraticCurveTo(cpx, cpy, x, y);
- };
- /**
- * @private
- * 使用直线连接子路径的终点到x,y坐标。
- * @param x 直线终点的 x 轴坐标。
- * @param y 直线终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.lineTo = function (x, y) {
- //console.log("lineTo " + x + " " + y);
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.lineTo(x, y);
- };
- /**
- * @private
- * 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
- * @param fillRule 一种算法,决定点是在路径内还是在路径外。允许的值:
- * "nonzero": 非零环绕规则, 默认的规则。
- * "evenodd": 奇偶环绕规则。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.fill = function (fillRule) {
- native.$cmdManager.setContext(this.$nativeContext);
- var s1 = native.$cmdManager.pushString(fillRule);
- native.$cmdManager.fill(s1);
- };
- /**
- * @private
- * 使笔点返回到当前子路径的起始点。它尝试从当前点到起始点绘制一条直线。如果图形已经是封闭的或者只有一个点,那么此方法不会做任何操作。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.closePath = function () {
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.closePath();
- if (this.clipRectArray) {
- this.$clipRectArray = this.clipRectArray;
- this.clipRectArray = null;
- }
- };
- /**
- * @private
- * 创建一段矩形路径,矩形的起点位置是 (x, y) ,尺寸为 width 和 height。矩形的4个点通过直线连接,子路径做为闭合的标记,所以你可以填充或者描边矩形。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.rect = function (x, y, w, h) {
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.rect(x, y, w, h);
- this.$clipRectArray.push({ x: x, y: y, w: w, h: h });
- };
- /**
- * @private
- * 将一个新的子路径的起始点移动到(x,y)坐标
- * @param x 点的 x 轴
- * @param y 点的 y 轴
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.moveTo = function (x, y) {
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.moveTo(x, y);
- };
- /**
- * @private
- * 绘制一个填充矩形。矩形的起点在 (x, y) 位置,矩形的尺寸是 width 和 height ,fillStyle 属性决定矩形的样式。
- * @param x 矩形起始点的 x 轴坐标。
- * @param y 矩形起始点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.fillRect = function (x, y, w, h) {
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.fillRect(x, y, w, h);
- // this.$nativeContext.fillRect(x, y, w, h);
- };
- /**
- * @private
- * 绘制一段三次贝赛尔曲线路径。该方法需要三个点。 第一、第二个点是控制点,第三个点是结束点。起始点是当前路径的最后一个点,
- * 绘制贝赛尔曲线前,可以通过调用 moveTo() 进行修改。
- * @param cp1x 第一个控制点的 x 轴坐标。
- * @param cp1y 第一个控制点的 y 轴坐标。
- * @param cp2x 第二个控制点的 x 轴坐标。
- * @param cp2y 第二个控制点的 y 轴坐标。
- * @param x 结束点的 x 轴坐标。
- * @param y 结束点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
- // this.$nativeContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
- };
- /**
- * @private
- * 根据当前的画线样式,绘制当前或已经存在的路径的方法。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.stroke = function () {
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.stroke();
- // this.$nativeContext.stroke();
- };
- /**
- * @private
- * 使用当前的绘画样式,描绘一个起点在 (x, y) 、宽度为 w 、高度为 h 的矩形的方法。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param w 矩形的宽度。
- * @param h 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.strokeRect = function (x, y, w, h) {
- //console.log("strokeRect");
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.strokeRect(x, y, w, h);
- // this.$nativeContext.strokeRect(x, y, w, h);
- };
- /**
- * @private
- * 清空子路径列表开始一个新路径。 当你想创建一个新的路径时,调用此方法。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.beginPath = function () {
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.beginPath();
- this.clipRectArray = this.$clipRectArray.concat();
- };
- /**
- * @private
- * 根据控制点和半径绘制一段圆弧路径,使用直线连接前一个点。
- * @param x1 第一个控制点的 x 轴坐标。
- * @param y1 第一个控制点的 y 轴坐标。
- * @param x2 第二个控制点的 x 轴坐标。
- * @param y2 第二个控制点的 y 轴坐标。
- * @param radius 圆弧的半径。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.arcTo = function (x1, y1, x2, y2, radius) {
- this.$nativeContext.arcTo(x1, y1, x2, y2, radius);
- };
- /**
- * @private
- * 使用方法参数描述的矩阵多次叠加当前的变换矩阵。
- * @param a 水平缩放。
- * @param b 水平倾斜。
- * @param c 垂直倾斜。
- * @param d 垂直缩放。
- * @param tx 水平移动。
- * @param ty 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.transform = function (a, b, c, d, tx, ty) {
- this.$matrix.append(a, b, c, d, tx, ty);
- this.setTransformToNative();
- };
- /**
- * @private
- * 通过在网格中移动 surface 和 surface 原点 x 水平方向、原点 y 垂直方向,添加平移变换
- * @param x 水平移动。
- * @param y 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.translate = function (x, y) {
- this.$matrix.translate(x, y);
- this.setTransformToNative();
- };
- /**
- * @private
- * 根据 x 水平方向和 y 垂直方向,为 surface 单位添加缩放变换。
- * @param x 水平方向的缩放因子。
- * @param y 垂直方向的缩放因子。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.scale = function (x, y) {
- this.$matrix.scale(x, y);
- this.setTransformToNative();
- };
- /**
- * @private
- * 在变换矩阵中增加旋转,角度变量表示一个顺时针旋转角度并且用弧度表示。
- * @param angle 顺时针旋转的弧度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.rotate = function (angle) {
- this.$matrix.rotate(angle);
- this.setTransformToNative();
- };
- /**
- * @private
- * 恢复到最近的绘制样式状态,此状态是通过 save() 保存到”状态栈“中最新的元素。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.restore = function () {
- //console.log("restore");
- if (this.$saveList.length) {
- var data = this.$saveList.pop();
- for (var key in data) {
- this[key] = data[key];
- }
- this.setTransformToNative();
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.restore();
- this.clipRectArray = null;
- }
- };
- /**
- * @private
- * 使用栈保存当前的绘画样式状态,你可以使用 restore() 恢复任何改变。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.save = function () {
- //console.log("save");
- var transformMatrix = new egret.Matrix();
- transformMatrix.copyFrom(this.$matrix);
- this.$saveList.push({
- lineWidth: this.$lineWidth,
- globalCompositeOperation: this.$globalCompositeOperation,
- globalAlpha: this.$globalAlpha,
- strokeStyle: this.$strokeStyle,
- fillStyle: this.$fillStyle,
- font: this.$font,
- $matrix: transformMatrix,
- $clipRectArray: this.$clipRectArray.concat()
- });
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.save();
- };
- /**
- * @private
- * 从当前路径创建一个剪切路径。在 clip() 调用之后,绘制的所有信息只会出现在剪切路径内部。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.clip = function (fillRule) {
- if (this.$clipRectArray.length > 0) {
- var arr = [];
- for (var i = 0; i < this.$clipRectArray.length; i++) {
- var clipRect = this.$clipRectArray[i];
- arr.push(clipRect.x);
- arr.push(clipRect.y);
- arr.push(clipRect.w);
- arr.push(clipRect.h);
- }
- //console.log("pushRectStencils " + arr.toString());
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.pushRectStencils(arr);
- this.$clipRectArray.length = 0;
- }
- };
- /**
- * @private
- * 设置指定矩形区域内(以 点 (x, y) 为起点,范围是(width, height) )所有像素变成透明,并擦除之前绘制的所有内容。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.clearRect = function (x, y, width, height) {
- //console.log("clearRect x:" + x + " y:" + y + " width:" + width + " height:" + height);
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.clearRect(x, y, width, height);
- };
- /**
- * @private
- * 重新设置当前的变换为单位矩阵,并使用同样的变量调用 transform() 方法。
- * @param a 水平缩放。
- * @param b 水平倾斜。
- * @param c 垂直倾斜。
- * @param d 垂直缩放。
- * @param tx 水平移动。
- * @param ty 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.setTransform = function (a, b, c, d, tx, ty) {
- this.$matrix.setTo(a, b, c, d, tx, ty);
- this.setTransformToNative();
- };
- NativeCanvasRenderContext.prototype.setTransformToNative = function () {
- var m = this.$matrix;
- //console.log("setTransformToNative::a=" + m.a + " b=" + m.b + " c=" + m.c + " d=" + m.d + " tx=" + m.tx + " ty=" + m.ty);
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
- };
- /**
- * @private
- * 保存矩阵,这里只能保存一次,嵌套无效
- */
- NativeCanvasRenderContext.prototype.saveTransform = function () {
- this.savedMatrix.copyFrom(this.$matrix);
- };
- /**
- * @private
- * 保存矩阵,这里只能保存一次,嵌套无效
- */
- NativeCanvasRenderContext.prototype.restoreTransform = function () {
- this.$matrix.copyFrom(this.savedMatrix);
- };
- /**
- * @private
- * 创建一个沿参数坐标指定的直线的渐变。该方法返回一个线性的 GraphicsGradient 对象。
- * @param x0 起点的 x 轴坐标。
- * @param y0 起点的 y 轴坐标。
- * @param x1 终点的 x 轴坐标。
- * @param y1 终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.createLinearGradient = function (x0, y0, x1, y1) {
- return this.$nativeContext.createLinearGradient(x0, y0, x1, y1);
- };
- /**
- * @private
- * 根据参数确定的两个圆的坐标,创建一个放射性渐变。该方法返回一个放射性的 GraphicsGradient。
- * @param x0 开始圆形的 x 轴坐标。
- * @param y0 开始圆形的 y 轴坐标。
- * @param r0 开始圆形的半径。
- * @param x1 结束圆形的 x 轴坐标。
- * @param y1 结束圆形的 y 轴坐标。
- * @param r1 结束圆形的半径。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) {
- return this.$nativeContext.createRadialGradient(x0, y0, r0, x1, y1, r1);
- };
- /**
- * @private
- * 在(x,y)位置绘制(填充)文本。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.fillText = function (text, x, y, maxWidth) {
- //console.log("drawText" + text);
- native.$cmdManager.setContext(this.$nativeContext);
- var s1 = native.$cmdManager.pushString(this.$fontFamily);
- var s2 = native.$cmdManager.pushString("");
- native.$cmdManager.createLabel(s1, this.$fontSize, s2, this.$hasStrokeText ? this.$lineWidth : 0);
- this.$hasStrokeText = false;
- var s3 = native.$cmdManager.pushString(text);
- native.$cmdManager.drawText(s3, x, y);
- };
- NativeCanvasRenderContext.prototype.strokeText = function (text, x, y, maxWidth) {
- this.$hasStrokeText = true;
- };
- /**
- * @private
- * 测量指定文本宽度,返回 TextMetrics 对象。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.measureText = function (text) {
- native.$cmdManager.setContext(egret_native.Label);
- var s1 = native.$cmdManager.pushString(this.$fontFamily);
- var s2 = native.$cmdManager.pushString("");
- native.$cmdManager.createLabel(s1, this.$fontSize, s2, this.$hasStrokeText ? this.$lineWidth : 0);
- //同步更新
- native.$cmdManager.flush();
- return { width: egret_native.Label.getTextSize(text)[0] };
- };
- /**
- * @private
- * 注意:如果要对绘制的图片进行缩放,出于性能优化考虑,系统不会主动去每次重置imageSmoothingEnabled属性,因此您在调用drawImage()方法前请务必
- * 确保 imageSmoothingEnabled 已被重置为正常的值,否则有可能沿用上个显示对象绘制过程留下的值。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.drawImage = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight) {
- var bitmapData;
- var isNative;
- if (image.$nativeCanvas) {
- bitmapData = image.$nativeCanvas;
- isNative = true;
- }
- else {
- bitmapData = image;
- isNative = false;
- }
- if (!bitmapData) {
- return;
- }
- if (arguments.length == 3) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- offsetX = 0;
- offsetY = 0;
- width = surfaceImageWidth = image.width;
- height = surfaceImageHeight = image.height;
- }
- else if (arguments.length == 5) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- surfaceImageWidth = width;
- surfaceImageHeight = height;
- offsetX = 0;
- offsetY = 0;
- width = image.width;
- height = image.height;
- }
- else {
- if (width == void 0) {
- width = image.width;
- }
- if (height == void 0) {
- height = image.height;
- }
- if (surfaceOffsetX == void 0) {
- surfaceOffsetX = 0;
- }
- if (surfaceOffsetY == void 0) {
- surfaceOffsetY = 0;
- }
- if (surfaceImageWidth == void 0) {
- surfaceImageWidth = width;
- }
- if (surfaceImageHeight == void 0) {
- surfaceImageHeight = height;
- }
- }
- //console.log("drawImage::" + offsetX + " " + offsetY + " " + width + " " + height + " " + surfaceOffsetX + " " + surfaceOffsetY + " " + surfaceImageWidth + " " + surfaceImageHeight);
- //console.log("drawImage::" + bitmapData);
- var imageAdress;
- if (!isNative) {
- if (!bitmapData._native_tex_loc) {
- bitmapData._native_tex_loc = bitmapData.___native_texture__p;
- }
- imageAdress = bitmapData._native_tex_loc;
- }
- else {
- imageAdress = bitmapData.___native_texture__p;
- }
- native.$cmdManager.setContext(this.$nativeContext);
- native.$cmdManager.drawImage(imageAdress, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight);
- };
- /**
- * @private
- * draw mesh
- */
- NativeCanvasRenderContext.prototype.drawMesh = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices) {
- var bitmapData;
- if (image.$nativeCanvas) {
- bitmapData = image.$nativeCanvas;
- }
- else {
- bitmapData = image;
- }
- if (!bitmapData) {
- return;
- }
- if (arguments.length == 3) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- offsetX = 0;
- offsetY = 0;
- width = surfaceImageWidth = image.width;
- height = surfaceImageHeight = image.height;
- }
- else if (arguments.length == 5) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- surfaceImageWidth = width;
- surfaceImageHeight = height;
- offsetX = 0;
- offsetY = 0;
- width = image.width;
- height = image.height;
- }
- else {
- if (!width) {
- width = image.width;
- }
- if (!height) {
- height = image.height;
- }
- if (!surfaceOffsetX) {
- surfaceOffsetX = 0;
- }
- if (!surfaceOffsetY) {
- surfaceOffsetY = 0;
- }
- if (!surfaceImageWidth) {
- surfaceImageWidth = width;
- }
- if (!surfaceImageHeight) {
- surfaceImageHeight = height;
- }
- }
- this.vertices = new Float32Array(meshVertices.length / 2 * 5);
- this.indicesForMesh = new Uint32Array(meshIndices.length);
- this.cacheArrays(this.$matrix, 1, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices);
- // 打断批渲染
- native.$cmdManager.flush();
- this.$nativeContext.drawMesh(bitmapData, this.vertices, this.indicesForMesh, this.vertices.length, this.indicesForMesh.length);
- };
- NativeCanvasRenderContext.prototype.cacheArrays = function (transform, alpha, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices) {
- //计算出绘制矩阵,之后把矩阵还原回之前的
- var locWorldTransform = transform;
- var originalA = locWorldTransform.a;
- var originalB = locWorldTransform.b;
- var originalC = locWorldTransform.c;
- var originalD = locWorldTransform.d;
- var originalTx = locWorldTransform.tx;
- var originalTy = locWorldTransform.ty;
- if (destX != 0 || destY != 0) {
- locWorldTransform.append(1, 0, 0, 1, destX, destY);
- }
- if (sourceWidth / destWidth != 1 || sourceHeight / destHeight != 1) {
- locWorldTransform.append(destWidth / sourceWidth, 0, 0, destHeight / sourceHeight, 0, 0);
- }
- var a = locWorldTransform.a;
- var b = locWorldTransform.b;
- var c = locWorldTransform.c;
- var d = locWorldTransform.d;
- var tx = locWorldTransform.tx;
- var ty = locWorldTransform.ty;
- locWorldTransform.a = originalA;
- locWorldTransform.b = originalB;
- locWorldTransform.c = originalC;
- locWorldTransform.d = originalD;
- locWorldTransform.tx = originalTx;
- locWorldTransform.ty = originalTy;
- if (meshVertices) {
- // 计算索引位置与赋值
- var vertices = this.vertices;
- // 缓存顶点数组
- var i = 0, iD = 0, l = 0;
- var u = 0, v = 0, x = 0, y = 0;
- for (i = 0, l = meshUVs.length; i < l; i += 2) {
- iD = i * 5 / 2;
- x = meshVertices[i];
- y = meshVertices[i + 1];
- u = meshUVs[i];
- v = meshUVs[i + 1];
- // xy
- vertices[iD + 0] = a * x + c * y + tx;
- vertices[iD + 1] = b * x + d * y + ty;
- // uv
- vertices[iD + 2] = (sourceX + u * sourceWidth) / textureSourceWidth;
- vertices[iD + 3] = (sourceY + v * sourceHeight) / textureSourceHeight;
- // alpha
- vertices[iD + 4] = alpha;
- }
- for (i = 0; i < meshIndices.length; i++) {
- this.indicesForMesh[i] = meshIndices[i];
- }
- }
- else {
- console.log("meshVertices not exist");
- }
- };
- /**
- * @private
- * 基于指定的源图象(BitmapData)创建一个模板,通过repetition参数指定源图像在什么方向上进行重复,返回一个GraphicsPattern对象。
- * @param bitmapData 做为重复图像源的 BitmapData 对象。
- * @param repetition 指定如何重复图像。
- * 可能的值有:"repeat" (两个方向重复),"repeat-x" (仅水平方向重复),"repeat-y" (仅垂直方向重复),"no-repeat" (不重复).
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.createPattern = function (image, repetition) {
- return null;
- };
- /**
- * @private
- * 返回一个 ImageData 对象,用来描述canvas区域隐含的像素数据,这个区域通过矩形表示,起始点为(sx, sy)、宽为sw、高为sh。
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeCanvasRenderContext.prototype.getImageData = function (sx, sy, sw, sh) {
- native.$cmdManager.flush();
- var res;
- if (sx != Math.floor(sx)) {
- sx = Math.floor(sx);
- sw++;
- }
- if (sy != Math.floor(sy)) {
- sy = Math.floor(sy);
- sh++;
- }
- res = this.$nativeContext.getPixels(sx, sy, sw, sh);
- if (res.pixelData) {
- res.data = res.pixelData;
- }
- return res;
- };
- /**
- * @private
- * 设置全局shader
- * @param filter filter属性生成的json
- */
- NativeCanvasRenderContext.prototype.setGlobalShader = function (filter) {
- native.$cmdManager.setContext(this.$nativeContext);
- var s1;
- if (filter) {
- s1 = native.$cmdManager.pushString(filter.$toJson());
- }
- else {
- s1 = native.$cmdManager.pushString("");
- }
- native.$cmdManager.setGlobalShader(s1);
- };
- return NativeCanvasRenderContext;
- }(egret.HashObject));
- native.NativeCanvasRenderContext = NativeCanvasRenderContext;
- __reflect(NativeCanvasRenderContext.prototype, "egret.native.NativeCanvasRenderContext");
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- var blendModesForGL = {
- "source-over": [1, 771],
- "lighter": [770, 1],
- "destination-out": [0, 771],
- "destination-in": [0, 770]
- };
- /**
- * @version Egret 2.4
- * @platform Web,Native
- * @private
- */
- var OldNativeCanvasRenderContext = (function (_super) {
- __extends(OldNativeCanvasRenderContext, _super);
- function OldNativeCanvasRenderContext() {
- var _this = _super.apply(this, arguments) || this;
- _this.$matrix = new egret.Matrix();
- _this.$nativeContext = null;
- _this.$globalCompositeOperation = "source-over";
- _this.$globalAlpha = 1;
- _this.$lineWidth = 0;
- _this.$strokeStyle = "#000000";
- _this.$fillStyle = "#000000";
- _this.$font = "normal normal 10px sans-serif";
- _this.$fontSize = 10;
- _this.$fontFamily = "";
- _this.clipRectArray = null;
- _this.$saveList = [];
- _this.$clipRectArray = [];
- _this.$clipRect = new egret.Rectangle();
- _this.$saveCount = 0;
- _this.$clipList = [];
- _this.savedMatrix = new egret.Matrix();
- _this.$hasStrokeText = false;
- return _this;
- }
- Object.defineProperty(OldNativeCanvasRenderContext.prototype, "globalCompositeOperation", {
- /**
- * @private
- * 设置新图像如何绘制到已有的图像上的规制
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$globalCompositeOperation;
- },
- set: function (value) {
- this.$globalCompositeOperation = value;
- var arr = blendModesForGL[value];
- if (arr) {
- this.$nativeContext.setBlendArg(arr[0], arr[1]);
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(OldNativeCanvasRenderContext.prototype, "globalAlpha", {
- /**
- * @private
- * 设置接下来绘图填充的整体透明度
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$globalAlpha;
- },
- set: function (value) {
- this.$globalAlpha = value;
- this.$nativeContext.setGlobalAlpha(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(OldNativeCanvasRenderContext.prototype, "lineWidth", {
- /**
- * @private
- * 设置线条粗细,以像素为单位。设置为0,负数,Infinity 或 NaN 将会被忽略。
- * @default 1
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$lineWidth;
- },
- set: function (value) {
- //console.log("set lineWidth" + value);
- this.$lineWidth = value;
- this.$nativeContext.lineWidth = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(OldNativeCanvasRenderContext.prototype, "strokeStyle", {
- /**
- * @private
- * 设置要在图形边线填充的颜色或样式
- * @default "#000000"
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$strokeStyle;
- },
- set: function (value) {
- this.$strokeStyle = value;
- if (value != null) {
- if (value.indexOf("rgba") != -1) {
- value = this.$parseRGBA(value);
- }
- else if (value.indexOf("rgb") != -1) {
- value = this.$parseRGB(value);
- }
- egret_native.Label.setStrokeColor(parseInt(value.replace("#", "0x")));
- }
- this.$nativeContext.strokeStyle = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(OldNativeCanvasRenderContext.prototype, "fillStyle", {
- /**
- * @private
- * 设置要在图形内部填充的颜色或样式
- * @default "#000000"
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$fillStyle;
- },
- set: function (value) {
- this.$fillStyle = value;
- if (value != null) {
- if (value.indexOf("rgba") != -1) {
- value = this.$parseRGBA(value);
- }
- else if (value.indexOf("rgb") != -1) {
- value = this.$parseRGB(value);
- }
- egret_native.Label.setTextColor(parseInt(value.replace("#", "0x")));
- }
- this.$nativeContext.fillStyle = value;
- },
- enumerable: true,
- configurable: true
- });
- OldNativeCanvasRenderContext.prototype.$fillColorStr = function (s) {
- if (s.length < 2) {
- s = "0" + s;
- }
- return s;
- };
- OldNativeCanvasRenderContext.prototype.$parseRGBA = function (str) {
- var index = str.indexOf("(");
- str = str.slice(index + 1, str.length - 1);
- var arr = str.split(",");
- var a = parseInt((parseFloat(arr[3]) * 255)).toString(16);
- var r = parseInt(arr[0]).toString(16);
- var g = parseInt(arr[1]).toString(16);
- var b = parseInt(arr[2]).toString(16);
- str = "#" + this.$fillColorStr(a) + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
- return str;
- };
- OldNativeCanvasRenderContext.prototype.$parseRGB = function (str) {
- var index = str.indexOf("(");
- str = str.slice(index + 1, str.length - 1);
- var arr = str.split(",");
- var r = parseInt(arr[0]).toString(16);
- var g = parseInt(arr[1]).toString(16);
- var b = parseInt(arr[2]).toString(16);
- str = "#" + this.$fillColorStr(r) + this.$fillColorStr(g) + this.$fillColorStr(b);
- return str;
- };
- Object.defineProperty(OldNativeCanvasRenderContext.prototype, "font", {
- /**
- * @private
- * 当前的字体样式
- * @version Egret 2.4
- * @platform Web,Native
- */
- get: function () {
- return this.$font;
- },
- set: function (value) {
- this.$font = value;
- var arr = value.split(" ");
- var sizeTxt = arr[2];
- if (sizeTxt.indexOf("px") != -1) {
- this.$fontSize = parseInt(sizeTxt.replace("px", ""));
- }
- if (egret.useFontMapping) {
- var fontFamilyText = void 0;
- if (arr.length == 4) {
- fontFamilyText = arr[3];
- }
- else {
- fontFamilyText = arr.slice(3).join(" ");
- }
- if (fontFamilyText.indexOf(", ") != -1) {
- arr = fontFamilyText.split(", ");
- }
- else if (fontFamilyText.indexOf(",") != -1) {
- arr = fontFamilyText.split(",");
- var length_7 = arr.length;
- for (var i = 0; i < length_7; i++) {
- var fontFamily = arr[i];
- //暂时先不考虑带有引号的情况
- if (egret.fontMapping[fontFamily]) {
- this.$fontFamily = egret.fontMapping[fontFamily];
- return;
- }
- }
- }
- else {
- this.$fontFamily = egret.fontMapping[fontFamilyText];
- }
- if (!this.$fontFamily) {
- this.$fontFamily = "/system/fonts/DroidSansFallback.ttf";
- }
- }
- else {
- //兼容旧版本直接将 default_fontFamily 设置为字体路径的情况
- this.$fontFamily = egret.TextField.default_fontFamily;
- }
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @private
- * 绘制一段圆弧路径。圆弧路径的圆心在 (x, y) 位置,半径为 r ,根据anticlockwise (默认为顺时针)指定的方向从 startAngle 开始绘制,到 endAngle 结束。
- * @param x 圆弧中心(圆心)的 x 轴坐标。
- * @param y 圆弧中心(圆心)的 y 轴坐标。
- * @param radius 圆弧的半径。
- * @param startAngle 圆弧的起始点, x轴方向开始计算,单位以弧度表示。
- * @param endAngle 圆弧的重点, 单位以弧度表示。
- * @param anticlockwise 如果为 true,逆时针绘制圆弧,反之,顺时针绘制。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.arc = function (x, y, radius, startAngle, endAngle, anticlockwise) {
- this.$nativeContext.arc(x, y, radius, startAngle, endAngle, anticlockwise);
- };
- /**
- * @private
- * 绘制一段二次贝塞尔曲线路径。它需要2个点。 第一个点是控制点,第二个点是终点。 起始点是当前路径最新的点,当创建二次贝赛尔曲线之前,可以使用 moveTo() 方法进行改变。
- * @param cpx 控制点的 x 轴坐标。
- * @param cpy 控制点的 y 轴坐标。
- * @param x 终点的 x 轴坐标。
- * @param y 终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
- //console.log("quadraticCurveTo " + cpx + " " + cpy + " " + x + " " + y);
- this.$nativeContext.quadraticCurveTo(cpx, cpy, x, y);
- };
- /**
- * @private
- * 使用直线连接子路径的终点到x,y坐标。
- * @param x 直线终点的 x 轴坐标。
- * @param y 直线终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.lineTo = function (x, y) {
- //console.log("lineTo " + x + " " + y);
- this.$nativeContext.lineTo(x, y);
- };
- /**
- * @private
- * 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
- * @param fillRule 一种算法,决定点是在路径内还是在路径外。允许的值:
- * "nonzero": 非零环绕规则, 默认的规则。
- * "evenodd": 奇偶环绕规则。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.fill = function (fillRule) {
- this.$nativeContext.fill(fillRule);
- };
- /**
- * @private
- * 使笔点返回到当前子路径的起始点。它尝试从当前点到起始点绘制一条直线。如果图形已经是封闭的或者只有一个点,那么此方法不会做任何操作。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.closePath = function () {
- this.$nativeContext.closePath();
- if (this.clipRectArray) {
- this.$clipRectArray = this.clipRectArray;
- this.clipRectArray = null;
- }
- };
- /**
- * @private
- * 创建一段矩形路径,矩形的起点位置是 (x, y) ,尺寸为 width 和 height。矩形的4个点通过直线连接,子路径做为闭合的标记,所以你可以填充或者描边矩形。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.rect = function (x, y, w, h) {
- this.$nativeContext.rect(x, y, w, h);
- this.$clipRectArray.push({ x: x, y: y, w: w, h: h });
- };
- /**
- * @private
- * 将一个新的子路径的起始点移动到(x,y)坐标
- * @param x 点的 x 轴
- * @param y 点的 y 轴
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.moveTo = function (x, y) {
- this.$nativeContext.moveTo(x, y);
- };
- /**
- * @private
- * 绘制一个填充矩形。矩形的起点在 (x, y) 位置,矩形的尺寸是 width 和 height ,fillStyle 属性决定矩形的样式。
- * @param x 矩形起始点的 x 轴坐标。
- * @param y 矩形起始点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.fillRect = function (x, y, w, h) {
- this.$nativeContext.fillRect(x, y, w, h);
- };
- /**
- * @private
- * 绘制一段三次贝赛尔曲线路径。该方法需要三个点。 第一、第二个点是控制点,第三个点是结束点。起始点是当前路径的最后一个点,
- * 绘制贝赛尔曲线前,可以通过调用 moveTo() 进行修改。
- * @param cp1x 第一个控制点的 x 轴坐标。
- * @param cp1y 第一个控制点的 y 轴坐标。
- * @param cp2x 第二个控制点的 x 轴坐标。
- * @param cp2y 第二个控制点的 y 轴坐标。
- * @param x 结束点的 x 轴坐标。
- * @param y 结束点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
- this.$nativeContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
- };
- /**
- * @private
- * 根据当前的画线样式,绘制当前或已经存在的路径的方法。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.stroke = function () {
- this.$nativeContext.stroke();
- };
- /**
- * @private
- * 使用当前的绘画样式,描绘一个起点在 (x, y) 、宽度为 w 、高度为 h 的矩形的方法。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param w 矩形的宽度。
- * @param h 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.strokeRect = function (x, y, w, h) {
- //console.log("strokeRect");
- this.$nativeContext.strokeRect(x, y, w, h);
- };
- /**
- * @private
- * 清空子路径列表开始一个新路径。 当你想创建一个新的路径时,调用此方法。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.beginPath = function () {
- this.$nativeContext.beginPath();
- this.clipRectArray = this.$clipRectArray.concat();
- };
- /**
- * @private
- * 根据控制点和半径绘制一段圆弧路径,使用直线连接前一个点。
- * @param x1 第一个控制点的 x 轴坐标。
- * @param y1 第一个控制点的 y 轴坐标。
- * @param x2 第二个控制点的 x 轴坐标。
- * @param y2 第二个控制点的 y 轴坐标。
- * @param radius 圆弧的半径。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.arcTo = function (x1, y1, x2, y2, radius) {
- this.$nativeContext.arcTo(x1, y1, x2, y2, radius);
- };
- /**
- * @private
- * 使用方法参数描述的矩阵多次叠加当前的变换矩阵。
- * @param a 水平缩放。
- * @param b 水平倾斜。
- * @param c 垂直倾斜。
- * @param d 垂直缩放。
- * @param tx 水平移动。
- * @param ty 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.transform = function (a, b, c, d, tx, ty) {
- this.$matrix.append(a, b, c, d, tx, ty);
- this.setTransformToNative();
- };
- /**
- * @private
- * 通过在网格中移动 surface 和 surface 原点 x 水平方向、原点 y 垂直方向,添加平移变换
- * @param x 水平移动。
- * @param y 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.translate = function (x, y) {
- this.$matrix.translate(x, y);
- this.setTransformToNative();
- };
- /**
- * @private
- * 根据 x 水平方向和 y 垂直方向,为 surface 单位添加缩放变换。
- * @param x 水平方向的缩放因子。
- * @param y 垂直方向的缩放因子。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.scale = function (x, y) {
- this.$matrix.scale(x, y);
- this.setTransformToNative();
- };
- /**
- * @private
- * 在变换矩阵中增加旋转,角度变量表示一个顺时针旋转角度并且用弧度表示。
- * @param angle 顺时针旋转的弧度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.rotate = function (angle) {
- this.$matrix.rotate(angle);
- this.setTransformToNative();
- };
- /**
- * @private
- * 恢复到最近的绘制样式状态,此状态是通过 save() 保存到”状态栈“中最新的元素。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.restore = function () {
- //console.log("restore");
- if (this.$saveList.length) {
- var data = this.$saveList.pop();
- for (var key in data) {
- this[key] = data[key];
- }
- this.setTransformToNative();
- this.$nativeContext.restore();
- this.clipRectArray = null;
- }
- };
- /**
- * @private
- * 使用栈保存当前的绘画样式状态,你可以使用 restore() 恢复任何改变。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.save = function () {
- //console.log("save");
- var transformMatrix = new egret.Matrix();
- transformMatrix.copyFrom(this.$matrix);
- this.$saveList.push({
- lineWidth: this.$lineWidth,
- globalCompositeOperation: this.$globalCompositeOperation,
- globalAlpha: this.$globalAlpha,
- strokeStyle: this.$strokeStyle,
- fillStyle: this.$fillStyle,
- font: this.$font,
- $matrix: transformMatrix,
- $clipRectArray: this.$clipRectArray.concat()
- });
- this.$nativeContext.save();
- };
- /**
- * @private
- * 从当前路径创建一个剪切路径。在 clip() 调用之后,绘制的所有信息只会出现在剪切路径内部。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.clip = function (fillRule) {
- if (this.$clipRectArray.length > 0) {
- var arr = [];
- for (var i = 0; i < this.$clipRectArray.length; i++) {
- var clipRect = this.$clipRectArray[i];
- arr.push(clipRect.x);
- arr.push(clipRect.y);
- arr.push(clipRect.w);
- arr.push(clipRect.h);
- }
- //console.log("pushRectStencils " + arr.toString());
- this.$nativeContext.pushRectStencils(arr);
- this.$clipRectArray.length = 0;
- }
- };
- /**
- * @private
- * 设置指定矩形区域内(以 点 (x, y) 为起点,范围是(width, height) )所有像素变成透明,并擦除之前绘制的所有内容。
- * @param x 矩形起点的 x 轴坐标。
- * @param y 矩形起点的 y 轴坐标。
- * @param width 矩形的宽度。
- * @param height 矩形的高度。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.clearRect = function (x, y, width, height) {
- //console.log("clearRect x:" + x + " y:" + y + " width:" + width + " height:" + height);
- this.$nativeContext.clearRect(x, y, width, height);
- };
- /**
- * @private
- * 重新设置当前的变换为单位矩阵,并使用同样的变量调用 transform() 方法。
- * @param a 水平缩放。
- * @param b 水平倾斜。
- * @param c 垂直倾斜。
- * @param d 垂直缩放。
- * @param tx 水平移动。
- * @param ty 垂直移动。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.setTransform = function (a, b, c, d, tx, ty) {
- this.$matrix.setTo(a, b, c, d, tx, ty);
- this.setTransformToNative();
- };
- OldNativeCanvasRenderContext.prototype.setTransformToNative = function () {
- var m = this.$matrix;
- //console.log("setTransformToNative::a=" + m.a + " b=" + m.b + " c=" + m.c + " d=" + m.d + " tx=" + m.tx + " ty=" + m.ty);
- this.$nativeContext.setTransform(m.a, m.b, m.c, m.d, m.tx, m.ty);
- };
- /**
- * @private
- * 保存矩阵,这里只能保存一次,嵌套无效
- */
- OldNativeCanvasRenderContext.prototype.saveTransform = function () {
- this.savedMatrix.copyFrom(this.$matrix);
- };
- /**
- * @private
- * 保存矩阵,这里只能保存一次,嵌套无效
- */
- OldNativeCanvasRenderContext.prototype.restoreTransform = function () {
- this.$matrix.copyFrom(this.savedMatrix);
- };
- /**
- * @private
- * 创建一个沿参数坐标指定的直线的渐变。该方法返回一个线性的 GraphicsGradient 对象。
- * @param x0 起点的 x 轴坐标。
- * @param y0 起点的 y 轴坐标。
- * @param x1 终点的 x 轴坐标。
- * @param y1 终点的 y 轴坐标。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.createLinearGradient = function (x0, y0, x1, y1) {
- return this.$nativeContext.createLinearGradient(x0, y0, x1, y1);
- };
- /**
- * @private
- * 根据参数确定的两个圆的坐标,创建一个放射性渐变。该方法返回一个放射性的 GraphicsGradient。
- * @param x0 开始圆形的 x 轴坐标。
- * @param y0 开始圆形的 y 轴坐标。
- * @param r0 开始圆形的半径。
- * @param x1 结束圆形的 x 轴坐标。
- * @param y1 结束圆形的 y 轴坐标。
- * @param r1 结束圆形的半径。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) {
- return this.$nativeContext.createRadialGradient(x0, y0, r0, x1, y1, r1);
- };
- /**
- * @private
- * 在(x,y)位置绘制(填充)文本。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.fillText = function (text, x, y, maxWidth) {
- //console.log("drawText" + text);
- this.$nativeContext.createLabel(this.$fontFamily, this.$fontSize, "", this.$hasStrokeText ? this.$lineWidth : 0);
- this.$hasStrokeText = false;
- this.$nativeContext.drawText(text, x, y);
- };
- OldNativeCanvasRenderContext.prototype.strokeText = function (text, x, y, maxWidth) {
- this.$hasStrokeText = true;
- };
- /**
- * @private
- * 测量指定文本宽度,返回 TextMetrics 对象。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.measureText = function (text) {
- egret_native.Label.createLabel(this.$fontFamily, this.$fontSize, "", this.$hasStrokeText ? this.$lineWidth : 0);
- return { width: egret_native.Label.getTextSize(text)[0] };
- };
- /**
- * @private
- * 注意:如果要对绘制的图片进行缩放,出于性能优化考虑,系统不会主动去每次重置imageSmoothingEnabled属性,因此您在调用drawImage()方法前请务必
- * 确保 imageSmoothingEnabled 已被重置为正常的值,否则有可能沿用上个显示对象绘制过程留下的值。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.drawImage = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight) {
- var bitmapData;
- var isNative;
- if (image.$nativeCanvas) {
- bitmapData = image.$nativeCanvas;
- isNative = true;
- }
- else {
- bitmapData = image;
- isNative = false;
- }
- if (!bitmapData) {
- return;
- }
- if (arguments.length == 3) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- offsetX = 0;
- offsetY = 0;
- width = surfaceImageWidth = image.width;
- height = surfaceImageHeight = image.height;
- }
- else if (arguments.length == 5) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- surfaceImageWidth = width;
- surfaceImageHeight = height;
- offsetX = 0;
- offsetY = 0;
- width = image.width;
- height = image.height;
- }
- else {
- if (width == void 0) {
- width = image.width;
- }
- if (height == void 0) {
- height = image.height;
- }
- if (surfaceOffsetX == void 0) {
- surfaceOffsetX = 0;
- }
- if (surfaceOffsetY == void 0) {
- surfaceOffsetY = 0;
- }
- if (surfaceImageWidth == void 0) {
- surfaceImageWidth = width;
- }
- if (surfaceImageHeight == void 0) {
- surfaceImageHeight = height;
- }
- }
- //console.log("drawImage::" + offsetX + " " + offsetY + " " + width + " " + height + " " + surfaceOffsetX + " " + surfaceOffsetY + " " + surfaceImageWidth + " " + surfaceImageHeight);
- //console.log("drawImage::" + bitmapData);
- this.$nativeContext.drawImage(bitmapData, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight);
- };
- /**
- * @private
- * draw mesh
- */
- OldNativeCanvasRenderContext.prototype.drawMesh = function (image, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices) {
- var bitmapData;
- if (image.$nativeCanvas) {
- bitmapData = image.$nativeCanvas;
- }
- else {
- bitmapData = image;
- }
- if (!bitmapData) {
- return;
- }
- if (arguments.length == 3) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- offsetX = 0;
- offsetY = 0;
- width = surfaceImageWidth = image.width;
- height = surfaceImageHeight = image.height;
- }
- else if (arguments.length == 5) {
- surfaceOffsetX = offsetX;
- surfaceOffsetY = offsetY;
- surfaceImageWidth = width;
- surfaceImageHeight = height;
- offsetX = 0;
- offsetY = 0;
- width = image.width;
- height = image.height;
- }
- else {
- if (!width) {
- width = image.width;
- }
- if (!height) {
- height = image.height;
- }
- if (!surfaceOffsetX) {
- surfaceOffsetX = 0;
- }
- if (!surfaceOffsetY) {
- surfaceOffsetY = 0;
- }
- if (!surfaceImageWidth) {
- surfaceImageWidth = width;
- }
- if (!surfaceImageHeight) {
- surfaceImageHeight = height;
- }
- }
- this.vertices = new Float32Array(meshVertices.length / 2 * 5);
- this.indicesForMesh = new Uint32Array(meshIndices.length);
- this.cacheArrays(this.$matrix, 1, offsetX, offsetY, width, height, surfaceOffsetX, surfaceOffsetY, surfaceImageWidth, surfaceImageHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices);
- this.$nativeContext.drawMesh(bitmapData, this.vertices, this.indicesForMesh, this.vertices.length, this.indicesForMesh.length);
- };
- OldNativeCanvasRenderContext.prototype.cacheArrays = function (transform, alpha, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight, textureSourceWidth, textureSourceHeight, meshUVs, meshVertices, meshIndices) {
- //计算出绘制矩阵,之后把矩阵还原回之前的
- var locWorldTransform = transform;
- var originalA = locWorldTransform.a;
- var originalB = locWorldTransform.b;
- var originalC = locWorldTransform.c;
- var originalD = locWorldTransform.d;
- var originalTx = locWorldTransform.tx;
- var originalTy = locWorldTransform.ty;
- if (destX != 0 || destY != 0) {
- locWorldTransform.append(1, 0, 0, 1, destX, destY);
- }
- if (sourceWidth / destWidth != 1 || sourceHeight / destHeight != 1) {
- locWorldTransform.append(destWidth / sourceWidth, 0, 0, destHeight / sourceHeight, 0, 0);
- }
- var a = locWorldTransform.a;
- var b = locWorldTransform.b;
- var c = locWorldTransform.c;
- var d = locWorldTransform.d;
- var tx = locWorldTransform.tx;
- var ty = locWorldTransform.ty;
- locWorldTransform.a = originalA;
- locWorldTransform.b = originalB;
- locWorldTransform.c = originalC;
- locWorldTransform.d = originalD;
- locWorldTransform.tx = originalTx;
- locWorldTransform.ty = originalTy;
- if (meshVertices) {
- // 计算索引位置与赋值
- var vertices = this.vertices;
- // 缓存顶点数组
- var i = 0, iD = 0, l = 0;
- var u = 0, v = 0, x = 0, y = 0;
- for (i = 0, l = meshUVs.length; i < l; i += 2) {
- iD = i * 5 / 2;
- x = meshVertices[i];
- y = meshVertices[i + 1];
- u = meshUVs[i];
- v = meshUVs[i + 1];
- // xy
- vertices[iD + 0] = a * x + c * y + tx;
- vertices[iD + 1] = b * x + d * y + ty;
- // uv
- vertices[iD + 2] = (sourceX + u * sourceWidth) / textureSourceWidth;
- vertices[iD + 3] = (sourceY + v * sourceHeight) / textureSourceHeight;
- // alpha
- vertices[iD + 4] = alpha;
- }
- for (i = 0; i < meshIndices.length; i++) {
- this.indicesForMesh[i] = meshIndices[i];
- }
- }
- else {
- console.log("meshVertices not exist");
- }
- };
- /**
- * @private
- * 基于指定的源图象(BitmapData)创建一个模板,通过repetition参数指定源图像在什么方向上进行重复,返回一个GraphicsPattern对象。
- * @param bitmapData 做为重复图像源的 BitmapData 对象。
- * @param repetition 指定如何重复图像。
- * 可能的值有:"repeat" (两个方向重复),"repeat-x" (仅水平方向重复),"repeat-y" (仅垂直方向重复),"no-repeat" (不重复).
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.createPattern = function (image, repetition) {
- return null;
- };
- /**
- * @private
- * 返回一个 ImageData 对象,用来描述canvas区域隐含的像素数据,这个区域通过矩形表示,起始点为(sx, sy)、宽为sw、高为sh。
- * @version Egret 2.4
- * @platform Web,Native
- */
- OldNativeCanvasRenderContext.prototype.getImageData = function (sx, sy, sw, sh) {
- var res;
- if (sx != Math.floor(sx)) {
- sx = Math.floor(sx);
- sw++;
- }
- if (sy != Math.floor(sy)) {
- sy = Math.floor(sy);
- sh++;
- }
- res = this.$nativeContext.getPixels(sx, sy, sw, sh);
- if (res.pixelData) {
- res.data = res.pixelData;
- }
- return res;
- };
- /**
- * @private
- * 设置全局shader
- * @param filter filter属性生成的json
- */
- OldNativeCanvasRenderContext.prototype.setGlobalShader = function (filter) {
- egret_native.Graphics.setGlobalShader(filter);
- };
- return OldNativeCanvasRenderContext;
- }(egret.HashObject));
- native.OldNativeCanvasRenderContext = OldNativeCanvasRenderContext;
- __reflect(OldNativeCanvasRenderContext.prototype, "egret.native.OldNativeCanvasRenderContext");
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- * 呈现最终绘图结果的画布
- */
- var NativeCanvas = (function (_super) {
- __extends(NativeCanvas, _super);
- /**
- * @private
- */
- function NativeCanvas() {
- var _this = _super.call(this) || this;
- _this.$width = 0;
- _this.$height = 0;
- _this.renderContext = native.$supportCmdBatch ? new native.NativeCanvasRenderContext() : new native.OldNativeCanvasRenderContext();
- return _this;
- }
- NativeCanvas.prototype.toDataURL = function (type) {
- var args = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- args[_i - 1] = arguments[_i];
- }
- if (this.$nativeCanvas) {
- return this.$nativeCanvas.toDataURL.apply(this.$nativeCanvas, arguments);
- }
- return null;
- };
- NativeCanvas.prototype.saveToFile = function (type, filePath) {
- if (this.$nativeCanvas && this.$nativeCanvas.saveToFile) {
- this.$nativeCanvas.saveToFile(type, filePath);
- }
- };
- Object.defineProperty(NativeCanvas.prototype, "width", {
- /**
- * @private
- * @inheritDoc
- */
- get: function () {
- return this.$width;
- },
- set: function (value) {
- if (value > 0) {
- this.$width = value;
- if (!this.$nativeCanvas) {
- this.$nativeCanvas = new egret_native.Canvas(value, 1);
- if (this.$isRoot) {
- egret_native.setScreenCanvas(this.$nativeCanvas);
- }
- var context = this.$nativeCanvas.getContext("2d");
- if (native.$supportCmdBatch) {
- native.$cmdManager.setContext(context);
- native.$cmdManager.clearScreen(0, 0, 0, 0);
- }
- else {
- context.clearScreen(0, 0, 0, 0);
- }
- this.renderContext.$nativeContext = context;
- }
- else {
- this.$nativeCanvas.width = value;
- }
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeCanvas.prototype, "height", {
- /**
- * @private
- * @inheritDoc
- */
- get: function () {
- return this.$height;
- },
- set: function (value) {
- if (value > 0) {
- this.$height = value;
- if (!this.$nativeCanvas) {
- this.$nativeCanvas = new egret_native.Canvas(1, value);
- if (this.$isRoot) {
- egret_native.setScreenCanvas(this.$nativeCanvas);
- }
- var context = this.$nativeCanvas.getContext("2d");
- if (native.$supportCmdBatch) {
- native.$cmdManager.setContext(context);
- native.$cmdManager.clearScreen(0, 0, 0, 0);
- }
- else {
- context.clearScreen(0, 0, 0, 0);
- }
- this.renderContext.$nativeContext = context;
- }
- else {
- this.$nativeCanvas.height = value;
- }
- }
- },
- enumerable: true,
- configurable: true
- });
- NativeCanvas.prototype.getContext = function (type) {
- return this.renderContext;
- };
- return NativeCanvas;
- }(egret.HashObject));
- native.NativeCanvas = NativeCanvas;
- __reflect(NativeCanvas.prototype, "egret.native.NativeCanvas");
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * 创建一个canvas。
- */
- function createCanvas(width, height) {
- var result = new native.NativeCanvas();
- if (!isNaN(width) && !isNaN(height)) {
- result.width = width;
- result.height = height;
- }
- return result;
- }
- var sharedCanvas;
- /**
- * @private
- * NativeCanvas2D渲染器
- */
- var NativeCanvasRenderBuffer = (function () {
- function NativeCanvasRenderBuffer(width, height) {
- this.surface = createCanvas(width, height);
- this.context = this.surface.getContext("2d");
- //保证rootCanvas是第一个创建的canvas
- }
- Object.defineProperty(NativeCanvasRenderBuffer.prototype, "width", {
- /**
- * 渲染缓冲的宽度,以像素为单位。
- * @readOnly
- */
- get: function () {
- return this.surface.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeCanvasRenderBuffer.prototype, "height", {
- /**
- * 渲染缓冲的高度,以像素为单位。
- * @readOnly
- */
- get: function () {
- return this.surface.height;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * 改变渲染缓冲的大小并清空缓冲区
- * @param width 改变后的宽
- * @param height 改变后的高
- * @param useMaxSize 若传入true,则将改变后的尺寸与已有尺寸对比,保留较大的尺寸。
- */
- NativeCanvasRenderBuffer.prototype.resize = function (width, height, useMaxSize) {
- //resize 之前要提交下绘制命令
- if (native.$supportCmdBatch) {
- native.$cmdManager.flush();
- }
- var surface = this.surface;
- surface.width = width;
- surface.height = height;
- this.clear();
- };
- /**
- * 改变渲染缓冲为指定大小,但保留原始图像数据
- * @param width 改变后的宽
- * @param height 改变后的高
- * @param offsetX 原始图像数据在改变后缓冲区的绘制起始位置x
- * @param offsetY 原始图像数据在改变后缓冲区的绘制起始位置y
- */
- NativeCanvasRenderBuffer.prototype.resizeTo = function (width, height, offsetX, offsetY) {
- //resize 之前要提交下绘制命令
- if (native.$supportCmdBatch) {
- native.$cmdManager.flush();
- }
- if (!sharedCanvas) {
- sharedCanvas = createCanvas();
- }
- var oldContext = this.context;
- var oldSurface = this.surface;
- var newSurface = sharedCanvas;
- var newContext = newSurface.getContext("2d");
- sharedCanvas = oldSurface;
- this.context = newContext;
- this.surface = newSurface;
- newSurface.width = Math.max(width, 1);
- newSurface.height = Math.max(height, 1);
- newContext.setTransform(1, 0, 0, 1, 0, 0);
- newContext.drawImage(oldSurface, offsetX, offsetY);
- oldSurface.height = 1;
- oldSurface.width = 1;
- };
- NativeCanvasRenderBuffer.prototype.setDirtyRegionPolicy = function (state) {
- };
- /**
- * 清空并设置裁切
- * @param regions 矩形列表
- * @param offsetX 矩形要加上的偏移量x
- * @param offsetY 矩形要加上的偏移量y
- */
- NativeCanvasRenderBuffer.prototype.beginClip = function (regions, offsetX, offsetY) {
- offsetX = +offsetX || 0;
- offsetY = +offsetY || 0;
- var context = this.context;
- context.save();
- context.beginPath();
- context.setTransform(1, 0, 0, 1, offsetX, offsetY);
- var length = regions.length;
- for (var i = 0; i < length; i++) {
- var region = regions[i];
- context.clearRect(region.minX, region.minY, region.width, region.height);
- context.rect(region.minX, region.minY, region.width, region.height);
- }
- context.clip();
- };
- /**
- * 取消上一次设置的clip。
- */
- NativeCanvasRenderBuffer.prototype.endClip = function () {
- this.context.restore();
- };
- /**
- * 获取指定区域的像素
- */
- NativeCanvasRenderBuffer.prototype.getPixels = function (x, y, width, height) {
- if (width === void 0) { width = 1; }
- if (height === void 0) { height = 1; }
- return this.context.getImageData(x, y, width, height).data;
- };
- /**
- * 转换成base64字符串,如果图片(或者包含的图片)跨域,则返回null
- * @param type 转换的类型,如: "image/png","image/jpeg"
- */
- NativeCanvasRenderBuffer.prototype.toDataURL = function (type, encoderOptions) {
- return this.surface.toDataURL(type, encoderOptions);
- };
- /**
- * 清空缓冲区数据
- */
- NativeCanvasRenderBuffer.prototype.clear = function () {
- var width = this.surface.width;
- var height = this.surface.height;
- if (width > 0 && height > 0) {
- this.context.setTransform(1, 0, 0, 1, 0, 0);
- this.context.clearRect(0, 0, width, height);
- }
- };
- /**
- * 销毁绘制对象
- */
- NativeCanvasRenderBuffer.prototype.destroy = function () {
- this.surface.width = this.surface.height = 1;
- };
- return NativeCanvasRenderBuffer;
- }());
- native.NativeCanvasRenderBuffer = NativeCanvasRenderBuffer;
- __reflect(NativeCanvasRenderBuffer.prototype, "egret.native.NativeCanvasRenderBuffer", ["egret.sys.RenderBuffer"]);
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- */
- function convertImageToRenderTexture(texture, rect) {
- var buffer = egret.sys.canvasHitTestBuffer;
- var w = texture.$getTextureWidth();
- var h = texture.$getTextureHeight();
- if (rect == null) {
- rect = egret.$TempRectangle;
- rect.x = 0;
- rect.y = 0;
- rect.width = w;
- rect.height = h;
- }
- rect.x = Math.min(rect.x, w - 1);
- rect.y = Math.min(rect.y, h - 1);
- rect.width = Math.min(rect.width, w - rect.x);
- rect.height = Math.min(rect.height, h - rect.y);
- var iWidth = rect.width;
- var iHeight = rect.height;
- var surface = buffer.surface;
- buffer.resize(iWidth, iHeight);
- var bitmapData = texture;
- var offsetX = Math.round(bitmapData._offsetX);
- var offsetY = Math.round(bitmapData._offsetY);
- var bitmapWidth = bitmapData._bitmapWidth;
- var bitmapHeight = bitmapData._bitmapHeight;
- 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);
- return surface;
- }
- /**
- * @private
- */
- function toDataURL(type, rect) {
- try {
- var renderTexture = convertImageToRenderTexture(this, rect);
- var base64 = renderTexture.toDataURL(type);
- //renderTexture.$dispose();
- return base64;
- }
- catch (e) {
- egret.$error(1033);
- return null;
- }
- }
- function saveToFile(type, filePath, rect) {
- try {
- var renderTexture = convertImageToRenderTexture(this, rect);
- renderTexture.saveToFile(type, filePath);
- }
- catch (e) {
- egret.$error(1033);
- }
- }
- function getPixel32(x, y) {
- egret.$error(1035);
- return null;
- }
- function getPixels(x, y, width, height) {
- egret.$error(1035);
- return null;
- }
- egret.Texture.prototype.toDataURL = toDataURL;
- egret.Texture.prototype.saveToFile = saveToFile;
- egret.Texture.prototype.getPixel32 = getPixel32;
- egret.Texture.prototype.getPixels = getPixels;
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- */
- var NativePlayer = (function (_super) {
- __extends(NativePlayer, _super);
- function NativePlayer() {
- var _this = _super.call(this) || this;
- _this.init(NativePlayer.option);
- return _this;
- }
- NativePlayer.prototype.init = function (option) {
- //暂时无法显示重绘区域
- option.showPaintRect = false;
- var stage = new egret.Stage();
- stage.$screen = this;
- stage.$scaleMode = option.scaleMode;
- stage.$maxTouches = option.maxTouches;
- stage.textureScaleFactor = option.textureScaleFactor;
- //设置帧频到native
- stage.frameRate = option.frameRate;
- if (!egret.native.$supportCanvas) {
- stage.addEventListener(egret.Event.ENTER_FRAME, function () {
- if (native.$currentSurface) {
- native.$currentSurface.end();
- }
- }, this);
- }
- var buffer = new egret.sys.RenderBuffer(undefined, undefined, true);
- var canvas = buffer.surface;
- canvas.$isRoot = true;
- var touch = new native.NativeTouchHandler(stage);
- var player = new egret.sys.Player(buffer, stage, option.entryClassName);
- new native.NativeHideHandler(stage);
- player.showPaintRect(option.showPaintRect);
- if (option.showFPS || option.showLog) {
- var styleStr = option.fpsStyles || "";
- var stylesArr = styleStr.split(",");
- var styles = {};
- for (var i = 0; i < stylesArr.length; i++) {
- var tempStyleArr = stylesArr[i].split(":");
- styles[tempStyleArr[0]] = tempStyleArr[1];
- }
- option.fpsStyles = styles;
- player.displayFPS(option.showFPS, option.showLog, option.logFilter, option.fpsStyles);
- }
- this.playerOption = option;
- this.$stage = stage;
- this.player = player;
- this.nativeTouch = touch;
- //this.nativeInput = nativeInput;
- this.updateScreenSize();
- this.updateMaxTouches();
- player.start();
- };
- NativePlayer.prototype.updateScreenSize = function () {
- var option = this.playerOption;
- var screenWidth = egret_native.EGTView.getFrameWidth();
- var screenHeight = egret_native.EGTView.getFrameHeight();
- egret.Capabilities.$boundingClientWidth = screenWidth;
- egret.Capabilities.$boundingClientHeight = screenHeight;
- var stageSize = egret.sys.screenAdapter.calculateStageSize(this.$stage.$scaleMode, screenWidth, screenHeight, option.contentWidth, option.contentHeight);
- var stageWidth = stageSize.stageWidth;
- var stageHeight = stageSize.stageHeight;
- var displayWidth = stageSize.displayWidth;
- var displayHeight = stageSize.displayHeight;
- var top = (screenHeight - displayHeight) / 2;
- var left = (screenWidth - displayWidth) / 2;
- egret_native.EGTView.setVisibleRect(left, top, displayWidth, displayHeight);
- egret_native.EGTView.setDesignSize(stageWidth, stageHeight);
- this.player.updateStageSize(stageWidth, stageHeight);
- };
- NativePlayer.prototype.setContentSize = function (width, height) {
- var option = this.playerOption;
- option.contentWidth = width;
- option.contentHeight = height;
- this.updateScreenSize();
- };
- /**
- * @private
- * 更新触摸数量
- */
- NativePlayer.prototype.updateMaxTouches = function () {
- this.nativeTouch.$updateMaxTouches();
- };
- return NativePlayer;
- }(egret.HashObject));
- native.NativePlayer = NativePlayer;
- __reflect(NativePlayer.prototype, "egret.native.NativePlayer", ["egret.sys.Screen"]);
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- */
- native.$supportCanvas = egret_native.Canvas ? true : false;
- /**
- * @private
- * 判断当前runtime版本是否支持cmdBatch
- */
- native.$supportCmdBatch = egret_native.sendToC ? true : false;
- /*
- * @private
- * 命令控制器
- * */
- var CmdManager = (function () {
- function CmdManager() {
- /*
- * 存储绘制命令的 array buffer
- **/
- this.maxArrayBufferLen = 80000;
- this.arrayBuffer = new ArrayBuffer(this.maxArrayBufferLen * 4);
- this.uint32View = new Uint32Array(this.arrayBuffer);
- this.float32View = new Float32Array(this.arrayBuffer);
- this.arrayBufferLen = 0;
- /*
- * 存储字符串的数组
- */
- this.strArray = [];
- //------绘制命令 end-------------
- }
- /*
- * 上传绘制命令到C
- */
- CmdManager.prototype.flush = function () {
- egret_native.sendToC(this.float32View, this.arrayBufferLen, this.strArray);
- this.clear();
- };
- /*
- * 切换native上下文
- * native绘制需要在自身的上下文进行绘制
- */
- CmdManager.prototype.setContext = function (ctx) {
- if (this.context != ctx) {
- if (this.arrayBufferLen + 3 > this.maxArrayBufferLen) {
- this.flush();
- }
- this.context = ctx;
- var uint32View = this.uint32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 1000;
- // uint32View[arrayBufferLen++] = ctx.___native_texture__p;
- // 兼容64位
- var addr = ctx.___native_texture__p;
- uint32View[arrayBufferLen++] = (addr / 4294967296) >>> 0;
- uint32View[arrayBufferLen++] = (addr & 4294967295) >>> 0;
- // uint32View[arrayBufferLen++] = addr >> 32;
- // uint32View[arrayBufferLen++] = addr & 4294967295;
- this.arrayBufferLen = arrayBufferLen;
- }
- };
- /*
- * 清空绘制命令
- */
- CmdManager.prototype.clear = function () {
- this.arrayBufferLen = 0;
- this.strArray.length = 0;
- };
- /*
- * 压入一个字符串并返回索引
- */
- CmdManager.prototype.pushString = function (str) {
- var array = this.strArray;
- var len = array.length;
- array[len] = str;
- return len;
- };
- //------绘制命令 start-------------
- CmdManager.prototype.clearScreen = function (i1, i2, i3, i4) {
- if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 100;
- uint32View[arrayBufferLen++] = i1;
- uint32View[arrayBufferLen++] = i2;
- uint32View[arrayBufferLen++] = i3;
- uint32View[arrayBufferLen++] = i4;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.drawImage = function (i1, f1, f2, f3, f4, f5, f6, f7, f8) {
- if (this.arrayBufferLen + 11 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 101;
- // uint32View[arrayBufferLen++] = i1;
- // 兼容64位
- // uint32View[arrayBufferLen++] = i1 >> 32;
- // uint32View[arrayBufferLen++] = i1 & 4294967295;
- uint32View[arrayBufferLen++] = (i1 / 4294967296) >>> 0;
- uint32View[arrayBufferLen++] = (i1 & 4294967295) >>> 0;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- float32View[arrayBufferLen++] = f5;
- float32View[arrayBufferLen++] = f6;
- float32View[arrayBufferLen++] = f7;
- float32View[arrayBufferLen++] = f8;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.setTransform = function (f1, f2, f3, f4, f5, f6) {
- if (this.arrayBufferLen + 7 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 103;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- float32View[arrayBufferLen++] = f5;
- float32View[arrayBufferLen++] = f6;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.setGlobalAlpha = function (f1) {
- if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 106;
- float32View[arrayBufferLen++] = f1;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.pushRectStencils = function (array) {
- var len = array.length;
- if (this.arrayBufferLen + len + 1 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 113;
- uint32View[arrayBufferLen++] = len;
- for (var i = 0; i < len; i++) {
- float32View[arrayBufferLen++] = array[i];
- }
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.restore = function () {
- if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
- this.flush();
- }
- this.uint32View[this.arrayBufferLen++] = 116;
- };
- CmdManager.prototype.save = function () {
- if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
- this.flush();
- }
- this.uint32View[this.arrayBufferLen++] = 117;
- };
- CmdManager.prototype.setBlendArg = function (f1, f2) {
- if (this.arrayBufferLen + 3 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 120;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.beginPath = function () {
- if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
- this.flush();
- }
- this.uint32View[this.arrayBufferLen++] = 204;
- };
- CmdManager.prototype.closePath = function () {
- if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
- this.flush();
- }
- this.uint32View[this.arrayBufferLen++] = 205;
- };
- CmdManager.prototype.rect = function (f1, f2, f3, f4) {
- if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 210;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.clearRect = function (f1, f2, f3, f4) {
- if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 214;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.createLabel = function (i1, f1, i2, f2) {
- if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 300;
- uint32View[arrayBufferLen++] = i1;
- float32View[arrayBufferLen++] = f1;
- uint32View[arrayBufferLen++] = i2;
- float32View[arrayBufferLen++] = f2;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.drawText = function (i1, f1, f2) {
- if (this.arrayBufferLen + 4 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 301;
- uint32View[arrayBufferLen++] = i1;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.setTextColor = function (i1) {
- if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 302;
- uint32View[arrayBufferLen++] = i1;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.setStrokeColor = function (i1) {
- if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 303;
- uint32View[arrayBufferLen++] = i1;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.setFillStyle = function (i1) {
- if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 1200;
- uint32View[arrayBufferLen++] = i1;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.setStrokeStyle = function (i1) {
- if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 1201;
- uint32View[arrayBufferLen++] = i1;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.setLineWidth = function (f1) {
- if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 1202;
- float32View[arrayBufferLen++] = f1;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.moveTo = function (f1, f2) {
- if (this.arrayBufferLen + 3 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 207;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.lineTo = function (f1, f2) {
- if (this.arrayBufferLen + 3 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 208;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.fill = function (i1) {
- if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 203;
- uint32View[arrayBufferLen++] = i1;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.pushClip = function (f1, f2, f3, f4) {
- if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 107;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.popClip = function () {
- if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
- this.flush();
- }
- this.uint32View[this.arrayBufferLen++] = 108;
- };
- CmdManager.prototype.stroke = function () {
- if (this.arrayBufferLen + 1 > this.maxArrayBufferLen) {
- this.flush();
- }
- this.uint32View[this.arrayBufferLen++] = 206;
- };
- CmdManager.prototype.arc = function (f1, f2, f3, f4, f5, i6) {
- if (this.arrayBufferLen + 7 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 209;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- float32View[arrayBufferLen++] = f5;
- uint32View[arrayBufferLen++] = i6;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.quadraticCurveTo = function (f1, f2, f3, f4) {
- if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 211;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.fillRect = function (f1, f2, f3, f4) {
- if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 212;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.strokeRect = function (f1, f2, f3, f4) {
- if (this.arrayBufferLen + 5 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 213;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.bezierCurveTo = function (f1, f2, f3, f4, f5, f6) {
- if (this.arrayBufferLen + 7 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var float32View = this.float32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 215;
- float32View[arrayBufferLen++] = f1;
- float32View[arrayBufferLen++] = f2;
- float32View[arrayBufferLen++] = f3;
- float32View[arrayBufferLen++] = f4;
- float32View[arrayBufferLen++] = f5;
- float32View[arrayBufferLen++] = f6;
- this.arrayBufferLen = arrayBufferLen;
- };
- CmdManager.prototype.setGlobalShader = function (i1) {
- if (this.arrayBufferLen + 2 > this.maxArrayBufferLen) {
- this.flush();
- }
- var uint32View = this.uint32View;
- var arrayBufferLen = this.arrayBufferLen;
- uint32View[arrayBufferLen++] = 111;
- uint32View[arrayBufferLen++] = i1;
- this.arrayBufferLen = arrayBufferLen;
- };
- return CmdManager;
- }());
- __reflect(CmdManager.prototype, "CmdManager");
- /*
- * @private
- * 输出一个单例命令控制器,供所有需要调用的地方使用
- */
- native.$cmdManager = new CmdManager();
- var isRunning = false;
- var playerList = [];
- function runEgret(options) {
- if (isRunning) {
- return;
- }
- isRunning = true;
- if (!options) {
- options = {};
- }
- setRenderMode(options.renderMode);
- if (true) {
- //todo 获得系统语言版本
- var language = "zh_CN";
- if (language in egret.$locale_strings)
- egret.$language = language;
- }
- try {
- egret.Capabilities.$setNativeCapabilities(egret_native.getVersion());
- }
- catch (e) {
- }
- var ticker = egret.sys.$ticker;
- var mainLoop = native.$supportCmdBatch ? function () {
- ticker.update();
- native.$cmdManager.flush();
- } : function () {
- ticker.update();
- };
- egret_native.executeMainLoop(mainLoop, ticker);
- if (!egret.sys.screenAdapter) {
- if (options.screenAdapter) {
- egret.sys.screenAdapter = options.screenAdapter;
- }
- else {
- egret.sys.screenAdapter = new egret.sys.DefaultScreenAdapter();
- }
- }
- //todo
- var player = new native.NativePlayer();
- playerList.push(player);
- egret.sys.customHitTestBuffer = new native.NativeCanvasRenderBuffer(3, 3);
- egret.sys.canvasHitTestBuffer = egret.sys.customHitTestBuffer;
- //老版本runtime不支持canvas,关闭脏矩形
- if (!native.$supportCanvas) {
- player.$stage.dirtyRegionPolicy = egret.DirtyRegionPolicy.OFF;
- egret.sys.DisplayList.prototype.setDirtyRegionPolicy = function () {
- };
- }
- }
- /**
- * 设置渲染模式。"auto","webgl","canvas"
- * @param renderMode
- */
- function setRenderMode(renderMode) {
- if (native.$supportCanvas) {
- egret.sys.RenderBuffer = native.NativeCanvasRenderBuffer;
- egret.sys.CanvasRenderBuffer = native.NativeCanvasRenderBuffer;
- }
- else {
- egret.sys.RenderBuffer = native.NativeRenderTextureRenderBuffer;
- egret.sys.CanvasRenderBuffer = native.NativeRenderTextureRenderBuffer;
- }
- egret.sys.systemRenderer = new egret.CanvasRenderer();
- egret.sys.canvasRenderer = egret.sys.systemRenderer;
- egret.Capabilities.$renderMode = "canvas";
- }
- function updateAllScreens() {
- var length = playerList.length;
- for (var i = 0; i < length; i++) {
- playerList[i].updateScreenSize();
- }
- }
- function toArray(argument) {
- var args = [];
- for (var i = 0; i < argument.length; i++) {
- args.push(argument[i]);
- }
- return args;
- }
- egret.warn = function () {
- console.warn.apply(console, toArray(arguments));
- };
- egret.error = function () {
- console.error.apply(console, toArray(arguments));
- };
- egret.assert = function () {
- console.assert.apply(console, toArray(arguments));
- };
- if (true) {
- egret.log = function () {
- if (true) {
- var length_8 = arguments.length;
- var info = "";
- for (var i = 0; i < length_8; i++) {
- info += arguments[i] + " ";
- }
- egret.sys.$logToFPS(info);
- }
- console.log.apply(console, toArray(arguments));
- };
- }
- else {
- egret.log = function () {
- console.log.apply(console, toArray(arguments));
- };
- }
- egret.runEgret = runEgret;
- egret.updateAllScreens = updateAllScreens;
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- */
- var NativeFps = (function (_super) {
- __extends(NativeFps, _super);
- function NativeFps(stage, showFPS, showLog, logFilter, styles) {
- var _this = _super.call(this) || this;
- _this.arrFps = [];
- _this.arrLog = [];
- if (showFPS || showLog) {
- _this.panelX = styles["x"] === undefined ? 0 : parseInt(styles['x']);
- _this.panelY = styles["y"] === undefined ? 0 : parseInt(styles['y']);
- _this._stage = stage;
- _this.showFps = showFPS;
- _this.showLog = showLog;
- _this.fontColor = styles["textColor"] === undefined ? 0xffffff : parseInt(styles['textColor']);
- _this.fontSize = styles["size"] === undefined ? 24 : parseInt(styles['size']);
- _this.bgAlpha = styles["bgAlpha"] || 0.9;
- _this.shape = new egret.Shape();
- _this.addChild(_this.shape);
- if (showFPS)
- _this.addFps();
- if (showLog)
- _this.addLog();
- }
- return _this;
- }
- NativeFps.prototype.addFps = function () {
- var fps = new egret.TextField();
- fps.x = fps.y = 4;
- this.textFps = fps;
- this.addChild(fps);
- fps.lineSpacing = 2;
- fps.size = this.fontSize;
- fps.textColor = this.fontColor;
- fps.textFlow = [
- { text: "0 FPS " + egret.Capabilities.renderMode + "\n" },
- { text: "Draw: 0\nDirty: 0%\n" },
- { text: "Cost: " },
- { text: "0 ", style: { "textColor": 0x18fefe } },
- { text: "0 ", style: { "textColor": 0xffff00 } },
- { text: "0 ", style: { "textColor": 0xff0000 } }
- ];
- };
- NativeFps.prototype.addLog = function () {
- var text = new egret.TextField();
- text.size = this.fontSize;
- text.textColor = this.fontColor;
- text.x = 4;
- this.addChild(text);
- this.textLog = text;
- };
- ;
- NativeFps.prototype.update = function (datas) {
- this.arrFps.push(datas.fps);
- var fpsTotal = 0;
- var lenFps = this.arrFps.length;
- if (lenFps > 101) {
- lenFps = 101;
- this.arrFps.shift();
- }
- var fpsMin = this.arrFps[0];
- var fpsMax = this.arrFps[0];
- for (var i = 0; i < lenFps; i++) {
- var num = this.arrFps[i];
- fpsTotal += num;
- if (num < fpsMin)
- fpsMin = num;
- else if (num > fpsMax)
- fpsMax = num;
- }
- this.textFps.textFlow = [
- { text: datas.fps + " FPS " + egret.Capabilities.renderMode + "\n" },
- { text: "min" + fpsMin + " max" + fpsMax + " avg" + Math.floor(fpsTotal / lenFps) + "\n" },
- { text: "Draw: " + datas.draw + "\nDirty: " + datas.dirty + "%\n" },
- { text: "Cost: " },
- { text: datas.costTicker + " ", style: { "textColor": 0x18fefe } },
- { text: datas.costDirty + " ", style: { "textColor": 0xffff00 } },
- { text: datas.costRender + " ", style: { "textColor": 0xff0000 } }
- ];
- this.updateLayout();
- };
- ;
- NativeFps.prototype.updateInfo = function (info) {
- var fpsHeight = 0;
- if (this.showFps) {
- fpsHeight = this.textFps.height;
- this.textLog.y = fpsHeight + 4;
- }
- this.arrLog.push(info);
- this.textLog.text = this.arrLog.join('\n');
- if (this._stage.stageHeight > 0) {
- if (this.textLog.textWidth > this._stage.stageWidth - 20 - this.panelX) {
- this.textLog.width = this._stage.stageWidth - 20 - this.panelX;
- }
- while (this.textLog.textHeight > this._stage.stageHeight - fpsHeight - 20 - this.panelY) {
- this.arrLog.shift();
- this.textLog.text = this.arrLog.join("\n");
- }
- }
- this.updateLayout();
- };
- NativeFps.prototype.updateLayout = function () {
- if (egret.Capabilities.runtimeType == egret.RuntimeType.NATIVE) {
- return;
- }
- var g = this.shape.$graphics;
- g.clear();
- g.beginFill(0x000000, this.bgAlpha);
- g.drawRect(0, 0, this.width + 8, this.height + 8);
- g.endFill();
- };
- return NativeFps;
- }(egret.Sprite));
- native.NativeFps = NativeFps;
- __reflect(NativeFps.prototype, "egret.native.NativeFps", ["egret.FPSDisplay"]);
- egret.FPSDisplay = NativeFps;
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- if (true) {
- function setLogLevel(logType) {
- egret_native.loglevel(logType);
- }
- Object.defineProperty(egret.Logger, "logLevel", {
- set: setLogLevel,
- enumerable: true,
- configurable: true
- });
- }
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- var callBackDic = {};
- /**
- * @private
- */
- var NativeExternalInterface = (function () {
- function NativeExternalInterface() {
- }
- NativeExternalInterface.call = function (functionName, value) {
- var data = {};
- data.functionName = functionName;
- data.value = value;
- egret_native.sendInfoToPlugin(JSON.stringify(data));
- };
- NativeExternalInterface.addCallback = function (functionName, listener) {
- callBackDic[functionName] = listener;
- };
- return NativeExternalInterface;
- }());
- native.NativeExternalInterface = NativeExternalInterface;
- __reflect(NativeExternalInterface.prototype, "egret.native.NativeExternalInterface", ["egret.ExternalInterface"]);
- /**
- * @private
- * @param info
- */
- function onReceivedPluginInfo(info) {
- var data = JSON.parse(info);
- var functionName = data.functionName;
- var listener = callBackDic[functionName];
- if (listener) {
- var value = data.value;
- listener.call(null, value);
- }
- else {
- egret.$warn(1050, functionName);
- }
- }
- egret.ExternalInterface = NativeExternalInterface;
- egret_native.receivedPluginInfo = onReceivedPluginInfo;
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- * @inheritDoc
- */
- var NativeSound = (function (_super) {
- __extends(NativeSound, _super);
- /**
- * @private
- * @inheritDoc
- */
- function NativeSound() {
- var _this = _super.call(this) || this;
- /**
- * @private
- */
- _this.loaded = false;
- return _this;
- }
- Object.defineProperty(NativeSound.prototype, "length", {
- get: function () {
- if (this.originAudio) {
- return this.originAudio.duration;
- }
- throw new Error("sound not loaded!");
- //return 0;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @inheritDoc
- */
- NativeSound.prototype.load = function (url) {
- var self = this;
- this.url = url;
- if (true && !url) {
- egret.$error(3002);
- }
- var audio = new Audio(url);
- audio.addEventListener("canplaythrough", onCanPlay);
- audio.addEventListener("error", onAudioError);
- this.originAudio = audio;
- if (!egret_native.isFileExists(url)) {
- download();
- }
- else {
- onAudioLoaded();
- }
- function download() {
- var promise = egret.PromiseObject.create();
- promise.onSuccessFunc = onAudioLoaded;
- promise.onErrorFunc = onAudioError;
- egret_native.download(url, url, promise);
- }
- function onAudioLoaded() {
- audio.load();
- NativeSound.$recycle(url, audio);
- }
- function onCanPlay() {
- removeListeners();
- self.loaded = true;
- self.dispatchEventWith(egret.Event.COMPLETE);
- }
- function onAudioError() {
- removeListeners();
- self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
- }
- function removeListeners() {
- audio.removeEventListener("canplaythrough", onCanPlay);
- audio.removeEventListener("error", onAudioError);
- }
- };
- /**
- * @inheritDoc
- */
- NativeSound.prototype.play = function (startTime, loops) {
- startTime = +startTime || 0;
- loops = +loops || 0;
- if (true && this.loaded == false) {
- egret.$error(1049);
- }
- var audio = NativeSound.$pop(this.url);
- if (audio == null) {
- audio = new Audio(this.url);
- }
- else {
- }
- audio.autoplay = true;
- var channel = new native.NativeSoundChannel(audio);
- channel.$url = this.url;
- channel.$loops = loops;
- channel.$startTime = startTime;
- channel.$play();
- egret.sys.$pushSoundChannel(channel);
- return channel;
- };
- /**
- * @inheritDoc
- */
- NativeSound.prototype.close = function () {
- if (this.loaded == false && this.originAudio)
- this.originAudio.src = "";
- if (this.originAudio)
- this.originAudio = null;
- NativeSound.$clear(this.url);
- };
- NativeSound.$clear = function (url) {
- var array = NativeSound.audios[url];
- if (array) {
- array.length = 0;
- }
- };
- NativeSound.$pop = function (url) {
- var array = NativeSound.audios[url];
- if (array && array.length > 0) {
- return array.pop();
- }
- return null;
- };
- NativeSound.$recycle = function (url, audio) {
- var array = NativeSound.audios[url];
- if (NativeSound.audios[url] == null) {
- array = NativeSound.audios[url] = [];
- }
- array.push(audio);
- };
- return NativeSound;
- }(egret.EventDispatcher));
- /**
- * @language en_US
- * Background music
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 背景音乐
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeSound.MUSIC = "music";
- /**
- * @language en_US
- * EFFECT
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 音效
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeSound.EFFECT = "effect";
- /**
- * @private
- */
- NativeSound.audios = {};
- native.NativeSound = NativeSound;
- __reflect(NativeSound.prototype, "egret.native.NativeSound", ["egret.Sound"]);
- if (__global.Audio) {
- egret.Sound = NativeSound;
- }
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- * @inheritDoc
- */
- var NativeSoundChannel = (function (_super) {
- __extends(NativeSoundChannel, _super);
- /**
- * @private
- */
- function NativeSoundChannel(audio) {
- var _this = _super.call(this) || this;
- /**
- * @private
- */
- _this.$startTime = 0;
- /**
- * @private
- */
- _this.audio = null;
- //声音是否已经播放完成
- _this.isStopped = false;
- /**
- * @private
- */
- _this.onPlayEnd = function () {
- if (_this.$loops == 1) {
- _this.stop();
- _this.dispatchEventWith(egret.Event.SOUND_COMPLETE);
- return;
- }
- if (_this.$loops > 0) {
- _this.$loops--;
- }
- /////////////
- //this.audio.load();
- _this.$play();
- };
- _this.$volume = 1;
- audio.addEventListener("ended", _this.onPlayEnd);
- _this.audio = audio;
- return _this;
- }
- NativeSoundChannel.prototype.$play = function () {
- if (this.isStopped) {
- egret.$error(1036);
- return;
- }
- try {
- this.audio.currentTime = this.$startTime;
- }
- catch (e) {
- }
- finally {
- this.audio.volume = this.$volume;
- this.audio.play();
- }
- };
- /**
- * @private
- * @inheritDoc
- */
- NativeSoundChannel.prototype.stop = function () {
- if (!this.audio)
- return;
- if (!this.isStopped) {
- egret.sys.$popSoundChannel(this);
- }
- this.isStopped = true;
- var audio = this.audio;
- audio.pause();
- audio.removeEventListener("ended", this.onPlayEnd);
- this.audio = null;
- native.NativeSound.$recycle(this.$url, audio);
- };
- Object.defineProperty(NativeSoundChannel.prototype, "volume", {
- /**
- * @private
- * @inheritDoc
- */
- get: function () {
- return this.$volume;
- },
- /**
- * @inheritDoc
- */
- set: function (value) {
- if (this.isStopped) {
- egret.$error(1036);
- return;
- }
- this.$volume = value;
- if (!this.audio)
- return;
- this.audio.volume = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeSoundChannel.prototype, "position", {
- /**
- * @private
- * @inheritDoc
- */
- get: function () {
- if (!this.audio)
- return 0;
- return this.audio.currentTime;
- },
- enumerable: true,
- configurable: true
- });
- return NativeSoundChannel;
- }(egret.EventDispatcher));
- native.NativeSoundChannel = NativeSoundChannel;
- __reflect(NativeSoundChannel.prototype, "egret.native.NativeSoundChannel", ["egret.SoundChannel", "egret.IEventDispatcher"]);
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- * @inheritDoc
- */
- var NaSound = (function (_super) {
- __extends(NaSound, _super);
- /**
- * @private
- * @inheritDoc
- */
- function NaSound() {
- var _this = _super.call(this) || this;
- /**
- * @private
- */
- _this.loaded = false;
- return _this;
- }
- Object.defineProperty(NaSound.prototype, "length", {
- get: function () {
- throw new Error("sound length not supported");
- //return 0;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @inheritDoc
- */
- NaSound.prototype.load = function (url) {
- var self = this;
- this.url = url;
- if (true && !url) {
- egret.$error(3002);
- }
- if (!egret_native.isFileExists(url)) {
- download();
- }
- else {
- if (__global.setTimeout) {
- __global.setTimeout(onLoadComplete, 0);
- }
- else {
- egret.$callAsync(onLoadComplete, self);
- }
- }
- function download() {
- var promise = egret.PromiseObject.create();
- promise.onSuccessFunc = onLoadComplete;
- promise.onErrorFunc = function () {
- egret.IOErrorEvent.dispatchIOErrorEvent(self);
- };
- egret_native.download(url, url, promise);
- }
- function onLoadComplete() {
- self.loaded = true;
- self.preload();
- }
- };
- NaSound.prototype.preload = function () {
- var self = this;
- if (self.type == egret.Sound.EFFECT) {
- var promise = new egret.PromiseObject();
- promise.onSuccessFunc = function (soundId) {
- self.dispatchEventWith(egret.Event.COMPLETE);
- };
- egret_native.Audio.preloadEffectAsync(self.url, promise);
- }
- else {
- self.dispatchEventWith(egret.Event.COMPLETE);
- }
- };
- /**
- * @inheritDoc
- */
- NaSound.prototype.play = function (startTime, loops) {
- startTime = +startTime || 0;
- loops = +loops || 0;
- if (true && this.loaded == false) {
- egret.$error(1049);
- }
- var channel = new native.NaSoundChannel();
- channel.$url = this.url;
- channel.$loops = loops;
- channel.$type = this.type;
- channel.$startTime = startTime;
- channel.$play();
- egret.sys.$pushSoundChannel(channel);
- return channel;
- };
- /**
- * @inheritDoc
- */
- NaSound.prototype.close = function () {
- };
- return NaSound;
- }(egret.EventDispatcher));
- /**
- * @language en_US
- * Background music
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 背景音乐
- * @version Egret 2.4
- * @platform Web,Native
- */
- NaSound.MUSIC = "music";
- /**
- * @language en_US
- * EFFECT
- * @version Egret 2.4
- * @platform Web,Native
- */
- /**
- * @language zh_CN
- * 音效
- * @version Egret 2.4
- * @platform Web,Native
- */
- NaSound.EFFECT = "effect";
- native.NaSound = NaSound;
- __reflect(NaSound.prototype, "egret.native.NaSound", ["egret.Sound"]);
- if (!__global.Audio) {
- egret.Sound = NaSound;
- }
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- * @inheritDoc
- */
- var NaSoundChannel = (function (_super) {
- __extends(NaSoundChannel, _super);
- /**
- * @private
- */
- function NaSoundChannel() {
- var _this = _super.call(this) || this;
- /**
- * @private
- */
- _this.$startTime = 0;
- //声音是否已经播放完成
- _this.isStopped = false;
- /**
- * @private
- */
- _this._startTime = 0;
- return _this;
- }
- NaSoundChannel.prototype.$play = function () {
- this.isStopped = false;
- if (this.$type == egret.Sound.EFFECT) {
- this._effectId = egret_native.Audio.playEffect(this.$url, this.$loops != 1);
- }
- else {
- NaSoundChannel.currentPath = this.$url;
- egret_native.Audio.playBackgroundMusic(this.$url, this.$loops != 1);
- }
- this._startTime = Date.now();
- };
- /**
- * @private
- * @inheritDoc
- */
- NaSoundChannel.prototype.stop = function () {
- if (!this.isStopped) {
- egret.sys.$popSoundChannel(this);
- }
- this.isStopped = true;
- if (this.$type == egret.Sound.EFFECT) {
- if (this._effectId) {
- egret_native.Audio.stopEffect(this._effectId);
- this._effectId = null;
- }
- }
- else {
- if (this.$url == NaSoundChannel.currentPath) {
- egret_native.Audio.stopBackgroundMusic(false);
- }
- }
- };
- Object.defineProperty(NaSoundChannel.prototype, "volume", {
- /**
- * @private
- * @inheritDoc
- */
- get: function () {
- if (this.$type == egret.Sound.EFFECT) {
- return egret_native.Audio.getEffectsVolume();
- }
- else {
- return egret_native.Audio.getBackgroundMusicVolume();
- }
- return 1;
- },
- /**
- * @inheritDoc
- */
- set: function (value) {
- if (this.$type == egret.Sound.EFFECT) {
- egret_native.Audio.setEffectsVolume(value);
- }
- else {
- egret_native.Audio.setBackgroundMusicVolume(value);
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NaSoundChannel.prototype, "position", {
- /**
- * @private
- * @inheritDoc
- */
- get: function () {
- return (Date.now() - this._startTime) / 1000;
- },
- enumerable: true,
- configurable: true
- });
- return NaSoundChannel;
- }(egret.EventDispatcher));
- native.NaSoundChannel = NaSoundChannel;
- __reflect(NaSoundChannel.prototype, "egret.native.NaSoundChannel", ["egret.SoundChannel", "egret.IEventDispatcher"]);
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- * @inheritDoc
- */
- var NativeVideo = (function (_super) {
- __extends(NativeVideo, _super);
- /**
- * @private
- * @inheritDoc
- */
- function NativeVideo(url, cache) {
- if (cache === void 0) { cache = true; }
- var _this = _super.call(this) || this;
- /**
- * @private
- */
- _this.loaded = false;
- /**
- * @private
- */
- _this.loading = false;
- /**
- * @private
- * */
- _this.loop = false;
- /**
- * @private
- * */
- _this.isPlayed = false;
- /**
- * @private
- * */
- _this.firstPlay = true;
- /**
- * @inheritDoc
- */
- _this.src = "";
- _this._fullscreen = true;
- _this._bitmapData = null;
- /**
- * @inheritDoc
- */
- _this.paused = false;
- /**
- * @private
- */
- _this.isAddToStage = false;
- /**
- * @private
- */
- _this.heightSet = 0;
- /**
- * @private
- */
- _this.widthSet = 0;
- _this.$renderNode = new egret.sys.BitmapNode();
- _this.cache = cache;
- if (!__global.Video) {
- egret.$error(1044);
- }
- if (url) {
- _this.load(url, cache);
- }
- return _this;
- }
- /**
- * @inheritDoc
- */
- NativeVideo.prototype.load = function (url, cache) {
- if (cache === void 0) { cache = true; }
- if (true && !url) {
- egret.$error(3002);
- return;
- }
- if (this.loading) {
- return;
- }
- if (url.indexOf('/') == 0) {
- url = url.slice(1, url.length);
- }
- this.src = url;
- this.loading = true;
- this.loaded = false;
- if (cache && !egret_native.isFileExists(url)) {
- var self_1 = this;
- var promise = egret.PromiseObject.create();
- promise.onSuccessFunc = function () {
- self_1.loadEnd();
- };
- promise.onErrorFunc = function () {
- egret.$warn(1048);
- self_1.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
- };
- egret_native.download(url, url, promise);
- }
- else {
- this.loadEnd();
- }
- };
- /**
- * @private
- * */
- NativeVideo.prototype.loadEnd = function () {
- var video = new __global.Video(this.src);
- video['setVideoRect'](0, 0, 1, 1);
- video['setKeepRatio'](false);
- video.addEventListener("canplaythrough", onCanPlay);
- video.addEventListener("error", onVideoError);
- video.addEventListener("playing", onPlaying);
- video.load();
- var self = this;
- function onCanPlay() {
- video['setVideoRect'](0, 0, 1, 1);
- video.play();
- }
- function onPlaying() {
- video['setVideoRect'](0, 0, 1, 1);
- __global.setTimeout(function () {
- video.pause();
- if (self._fullscreen) {
- video.fullScreen = true;
- }
- video.currentTime = 0;
- self.originVideo = video;
- self.loaded = true;
- self.loading = false;
- removeListeners();
- self.dispatchEventWith(egret.Event.COMPLETE);
- video.addEventListener('pause', function () {
- self.paused = true;
- });
- video.addEventListener('playing', function () {
- self.paused = false;
- });
- video.addEventListener('ended', function () {
- self.dispatchEventWith(egret.Event.ENDED);
- if (self.loop) {
- self.play(0, true);
- }
- });
- }, 1);
- }
- function onVideoError() {
- removeListeners();
- self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
- }
- function removeListeners() {
- video.removeEventListener("canplaythrough", onCanPlay);
- video.removeEventListener("error", onVideoError);
- video.removeEventListener("playing", onPlaying);
- }
- };
- /**
- * @inheritDoc
- */
- NativeVideo.prototype.play = function (startTime, loop) {
- var _this = this;
- if (loop === void 0) { loop = false; }
- this.loop = loop;
- if (!this.loaded) {
- this.load(this.src);
- this.once(egret.Event.COMPLETE, function (e) { return _this.play(startTime, loop); }, this);
- return;
- }
- var haveStartTime = false;
- if (startTime != undefined && startTime != this.originVideo.currentTime) {
- this.originVideo.currentTime = startTime || 0;
- haveStartTime = true;
- }
- this.startPlay(haveStartTime);
- };
- /**
- * @private
- * */
- NativeVideo.prototype.startPlay = function (haveStartTime) {
- if (haveStartTime === void 0) { haveStartTime = false; }
- if (!this.isAddToStage || !this.loaded) {
- return;
- }
- this.firstPlay = false;
- this.setVideoSize();
- this.isPlayed = true;
- if (!haveStartTime && this.paused && this.position != 0) {
- this.originVideo['resume']();
- }
- else {
- this.originVideo.play();
- }
- egret.startTick(this.markDirty, this);
- };
- /**
- * @private
- * */
- NativeVideo.prototype.stopPlay = function () {
- egret.stopTick(this.markDirty, this);
- if (this.isPlayed) {
- this.isPlayed = false;
- this.originVideo.pause();
- }
- };
- /**
- * @inheritDoc
- */
- NativeVideo.prototype.close = function () {
- if (this.originVideo) {
- this.originVideo['destroy']();
- }
- this.loaded = false;
- this.loading = false;
- this.originVideo = null;
- this.loop = false;
- this.src = null;
- };
- Object.defineProperty(NativeVideo.prototype, "poster", {
- /**
- * @inheritDoc
- */
- get: function () {
- return this.posterUrl;
- },
- /**
- * @inheritDoc
- */
- set: function (value) {
- var _this = this;
- this.posterUrl = value;
- var loader = new native.NativeImageLoader();
- loader.load(value);
- loader.addEventListener(egret.Event.COMPLETE, function () {
- _this.posterData = loader.data;
- _this.markDirty();
- _this.$invalidateContentBounds();
- }, this);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeVideo.prototype, "fullscreen", {
- /**
- * @inheritDoc
- */
- get: function () {
- if (this.originVideo) {
- return this.originVideo['fullScreen'];
- }
- return this._fullscreen;
- },
- /**
- * @inheritDoc
- */
- set: function (value) {
- this._fullscreen = value;
- if (this.originVideo) {
- this.originVideo['fullScreen'] = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeVideo.prototype, "volume", {
- /**
- * @inheritDoc
- */
- get: function () {
- if (!this.loaded)
- return 0;
- return this.originVideo.volume;
- },
- /**
- * @inheritDoc
- */
- set: function (value) {
- if (!this.loaded)
- return;
- this.originVideo.volume = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeVideo.prototype, "position", {
- /**
- * @inheritDoc
- */
- get: function () {
- return this.originVideo.currentTime;
- },
- /**
- * @inheritDoc
- */
- set: function (value) {
- if (this.loaded) {
- this.originVideo.currentTime = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @inheritDoc
- */
- NativeVideo.prototype.pause = function () {
- this.originVideo.pause();
- };
- Object.defineProperty(NativeVideo.prototype, "bitmapData", {
- /**
- * @inheritDoc
- */
- get: function () {
- return this._bitmapData;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeVideo.prototype, "length", {
- /**
- * @inheritDoc
- */
- get: function () {
- if (this.loaded) {
- return this.originVideo.duration;
- }
- throw new Error("Video not loaded!");
- //return 0;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @inheritDoc
- */
- NativeVideo.prototype.$onAddToStage = function (stage, nestLevel) {
- this.isAddToStage = true;
- if (this.originVideo) {
- this.originVideo["setVideoVisible"](true);
- }
- this.$invalidate();
- this.$invalidateContentBounds();
- _super.prototype.$onAddToStage.call(this, stage, nestLevel);
- };
- /**
- * @inheritDoc
- */
- NativeVideo.prototype.$onRemoveFromStage = function () {
- this.isAddToStage = false;
- if (this.originVideo) {
- this.stopPlay();
- this.originVideo["setVideoVisible"](false);
- }
- _super.prototype.$onRemoveFromStage.call(this);
- };
- /**
- * @private
- */
- NativeVideo.prototype.getPlayWidth = function () {
- if (!isNaN(this.widthSet)) {
- return this.widthSet;
- }
- if (this.bitmapData) {
- return this.bitmapData.width;
- }
- if (this.posterData) {
- return this.posterData.width;
- }
- return NaN;
- };
- /**
- * @private
- */
- NativeVideo.prototype.getPlayHeight = function () {
- if (!isNaN(this.heightSet)) {
- return this.heightSet;
- }
- if (this.bitmapData) {
- return this.bitmapData.height;
- }
- if (this.posterData) {
- return this.posterData.height;
- }
- return NaN;
- };
- /**
- * @private
- */
- NativeVideo.prototype.$setHeight = function (value) {
- this.heightSet = +value || 0;
- this.setVideoSize();
- this.$invalidate();
- this.$invalidateContentBounds();
- return _super.prototype.$setHeight.call(this, value);
- };
- /**
- * @private
- */
- NativeVideo.prototype.$setWidth = function (value) {
- this.widthSet = +value || 0;
- this.setVideoSize();
- this.$invalidate();
- this.$invalidateContentBounds();
- return _super.prototype.$setWidth.call(this, value);
- };
- /**
- * @inheritDoc
- */
- NativeVideo.prototype.$setX = function (value) {
- var result = _super.prototype.$setX.call(this, value);
- this.setVideoSize();
- return result;
- };
- /**
- * @inheritDoc
- */
- NativeVideo.prototype.$setY = function (value) {
- var result = _super.prototype.$setY.call(this, value);
- this.setVideoSize();
- return result;
- };
- /**
- * @private
- */
- NativeVideo.prototype.setVideoSize = function () {
- var video = this.originVideo;
- if (video && !this.fullscreen) {
- if (!this.firstPlay) {
- video['setVideoRect'](this.x, this.y, this.widthSet, this.heightSet);
- }
- else {
- video['setVideoRect'](this.x, this.y, 0, 0);
- }
- }
- };
- /**
- * @private
- */
- NativeVideo.prototype.$measureContentBounds = function (bounds) {
- var posterData = this.posterData;
- if (posterData) {
- bounds.setTo(0, 0, this.getPlayWidth(), this.getPlayHeight());
- }
- else {
- bounds.setEmpty();
- }
- };
- /**
- * @private
- */
- NativeVideo.prototype.$render = function () {
- var node = this.$renderNode;
- var posterData = this.posterData;
- var width = this.getPlayWidth();
- var height = this.getPlayHeight();
- if (width <= 0 || height <= 0) {
- return;
- }
- if (!this.isPlayed && posterData) {
- node.image = posterData;
- node.drawImage(0, 0, posterData.width, posterData.height, 0, 0, width, height);
- }
- else if (this.isPlayed) {
- this.setVideoSize();
- }
- };
- NativeVideo.prototype.markDirty = function () {
- this.$invalidate();
- return true;
- };
- return NativeVideo;
- }(egret.DisplayObject));
- native.NativeVideo = NativeVideo;
- __reflect(NativeVideo.prototype, "egret.native.NativeVideo", ["egret.Video"]);
- if (__global.Video) {
- egret.Video = NativeVideo;
- }
- else {
- egret.$warn(1044);
- }
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var localStorage;
- (function (localStorage) {
- var native;
- (function (native) {
- var filePath = "LocalStorage.local";
- var localStorageData = {};
- /**
- * @private
- *
- * @param key
- * @returns
- */
- function getItem(key) {
- return localStorageData[key];
- }
- /**
- * @private
- *
- * @param key
- * @param value
- * @returns
- */
- function setItem(key, value) {
- if (value === undefined) {
- value = "undefined";
- }
- else if (value === null) {
- value = "null";
- }
- else {
- value = value.toString();
- }
- localStorageData[key] = value;
- try {
- save();
- return true;
- }
- catch (e) {
- egret.$warn(1018, key, value);
- return false;
- }
- }
- /**
- * @private
- *
- * @param key
- */
- function removeItem(key) {
- delete localStorageData[key];
- save();
- }
- /**
- * @private
- *
- */
- function clear() {
- for (var key in localStorageData) {
- delete localStorageData[key];
- }
- save();
- }
- /**
- * @private
- *
- */
- function save() {
- egret_native.saveRecord(filePath, JSON.stringify(localStorageData));
- }
- if (egret_native.isRecordExists(filePath)) {
- var str = egret_native.loadRecord(filePath);
- try {
- localStorageData = JSON.parse(str);
- }
- catch (e) {
- localStorageData = {};
- }
- }
- else {
- localStorageData = {};
- }
- localStorage.getItem = getItem;
- localStorage.setItem = setItem;
- localStorage.removeItem = removeItem;
- localStorage.clear = clear;
- })(native = localStorage.native || (localStorage.native = {}));
- })(localStorage = egret.localStorage || (egret.localStorage = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- */
- var NativeHideHandler = (function (_super) {
- __extends(NativeHideHandler, _super);
- function NativeHideHandler(stage) {
- var _this = _super.call(this) || this;
- egret_native.pauseApp = function () {
- //console.log("pauseApp");
- stage.dispatchEvent(new egret.Event(egret.Event.DEACTIVATE));
- egret_native.Audio.pauseBackgroundMusic();
- egret_native.Audio.pauseAllEffects();
- };
- egret_native.resumeApp = function () {
- //console.log("resumeApp");
- stage.dispatchEvent(new egret.Event(egret.Event.ACTIVATE));
- egret_native.Audio.resumeBackgroundMusic();
- egret_native.Audio.resumeAllEffects();
- };
- return _this;
- }
- return NativeHideHandler;
- }(egret.HashObject));
- native.NativeHideHandler = NativeHideHandler;
- __reflect(NativeHideHandler.prototype, "egret.native.NativeHideHandler");
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- /**
- * @private
- * @version Egret 2.4
- * @platform Web,Native
- */
- var NativeResourceLoader = (function (_super) {
- __extends(NativeResourceLoader, _super);
- function NativeResourceLoader() {
- var _this = _super.apply(this, arguments) || this;
- /**
- * @private
- */
- _this._downCount = 0;
- /**
- * @private
- */
- _this._path = null;
- /**
- * @private
- */
- _this._bytesTotal = 0;
- return _this;
- }
- /**
- *
- * @param path
- * @param bytesTotal
- * @version Egret 2.4
- * @platform Web,Native
- */
- NativeResourceLoader.prototype.load = function (path, bytesTotal) {
- this._downCount = 0;
- this._path = path;
- this._bytesTotal = bytesTotal;
- this.reload();
- };
- /**
- * @private
- *
- */
- NativeResourceLoader.prototype.reload = function () {
- if (this._downCount >= 3) {
- this.downloadFileError();
- return;
- }
- //if (egret_native.isRecordExists(this._path)) {//卡里
- // this.loadOver();
- // return;
- //}
- //else if (egret_native.isFileExists(this._path)){
- // this.loadOver();
- // return;
- //}
- //else {
- this._downCount++;
- var promise = egret.PromiseObject.create();
- var self = this;
- promise.onSuccessFunc = function () {
- self.loadOver();
- };
- promise.onErrorFunc = function () {
- self.reload();
- };
- promise.downloadingSizeFunc = function (bytesLoaded) {
- self.downloadingProgress(bytesLoaded);
- };
- egret_native.download(this._path, this._path, promise);
- //}
- };
- /**
- * @private
- *
- * @param bytesLoaded
- */
- NativeResourceLoader.prototype.downloadingProgress = function (bytesLoaded) {
- egret.ProgressEvent.dispatchProgressEvent(this, egret.ProgressEvent.PROGRESS, bytesLoaded, this._bytesTotal);
- };
- /**
- * @private
- *
- */
- NativeResourceLoader.prototype.downloadFileError = function () {
- this.dispatchEvent(new egret.Event(egret.IOErrorEvent.IO_ERROR));
- };
- /**
- * @private
- *
- */
- NativeResourceLoader.prototype.loadOver = function () {
- this.dispatchEvent(new egret.Event(egret.Event.COMPLETE));
- };
- return NativeResourceLoader;
- }(egret.EventDispatcher));
- egret.NativeResourceLoader = NativeResourceLoader;
- __reflect(NativeResourceLoader.prototype, "egret.NativeResourceLoader");
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided this the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- */
- var NativeTouchHandler = (function (_super) {
- __extends(NativeTouchHandler, _super);
- function NativeTouchHandler(stage) {
- var _this = _super.call(this) || this;
- _this.$touch = new egret.sys.TouchHandler(stage);
- var self = _this;
- egret_native.onTouchesBegin = function (num, ids, xs_array, ys_array) {
- self.$executeTouchCallback(num, ids, xs_array, ys_array, self.$touch.onTouchBegin);
- };
- egret_native.onTouchesMove = function (num, ids, xs_array, ys_array) {
- self.$executeTouchCallback(num, ids, xs_array, ys_array, self.$touch.onTouchMove);
- };
- egret_native.onTouchesEnd = function (num, ids, xs_array, ys_array) {
- self.$executeTouchCallback(num, ids, xs_array, ys_array, self.$touch.onTouchEnd);
- };
- egret_native.onTouchesCancel = function (num, ids, xs_array, ys_array) {
- };
- return _this;
- }
- NativeTouchHandler.prototype.$executeTouchCallback = function (num, ids, xs_array, ys_array, callback) {
- for (var i = 0; i < num; i++) {
- var id = ids[i];
- var x = xs_array[i];
- var y = ys_array[i];
- callback.call(this.$touch, x, y, id);
- }
- };
- /**
- * @private
- * 更新同时触摸点的数量
- */
- NativeTouchHandler.prototype.$updateMaxTouches = function () {
- this.$touch.$initMaxTouches();
- };
- return NativeTouchHandler;
- }(egret.HashObject));
- native.NativeTouchHandler = NativeTouchHandler;
- __reflect(NativeTouchHandler.prototype, "egret.native.NativeTouchHandler");
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- */
- var NativeHttpRequest = (function (_super) {
- __extends(NativeHttpRequest, _super);
- /**
- * @private
- */
- function NativeHttpRequest() {
- var _this = _super.call(this) || this;
- /**
- * @private
- */
- _this._url = "";
- _this._method = "";
- /**
- * @private
- */
- _this.urlData = {};
- _this.responseHeader = "";
- return _this;
- }
- Object.defineProperty(NativeHttpRequest.prototype, "response", {
- /**
- * @private
- * 本次请求返回的数据,数据类型根据responseType设置的值确定。
- */
- get: function () {
- return this._response;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeHttpRequest.prototype, "responseType", {
- /**
- * @private
- * 设置返回的数据格式,请使用 HttpResponseType 里定义的枚举值。设置非法的值或不设置,都将使用HttpResponseType.TEXT。
- */
- get: function () {
- return this._responseType;
- },
- set: function (value) {
- this._responseType = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(NativeHttpRequest.prototype, "withCredentials", {
- /**
- * @private
- * 表明在进行跨站(cross-site)的访问控制(Access-Control)请求时,是否使用认证信息(例如cookie或授权的header)。 默认为 false。(这个标志不会影响同站的请求)
- */
- get: function () {
- return this._withCredentials;
- },
- set: function (value) {
- this._withCredentials = value;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @private
- * 初始化一个请求.注意,若在已经发出请求的对象上调用此方法,相当于立即调用abort().
- * @param url 该请求所要访问的URL该请求所要访问的URL
- * @param method 请求所使用的HTTP方法, 请使用 HttpMethod 定义的枚举值.
- */
- NativeHttpRequest.prototype.open = function (url, method) {
- if (method === void 0) { method = "GET"; }
- this._url = url;
- this._method = method;
- };
- /**
- * @private
- * 发送请求.
- * @param data 需要发送的数据
- */
- NativeHttpRequest.prototype.send = function (data) {
- var self = this;
- if (self.isNetUrl(self._url)) {
- self.urlData.type = self._method;
- //写入POST数据
- if (self._method == egret.HttpMethod.POST && data) {
- if (data instanceof ArrayBuffer) {
- self.urlData.data = data;
- }
- else {
- self.urlData.data = data.toString();
- }
- }
- else {
- delete self.urlData["data"];
- }
- if (self._responseType == egret.HttpResponseType.ARRAY_BUFFER) {
- self.urlData.binary = true;
- }
- else {
- self.urlData.header = false;
- }
- //写入header信息
- if (this.headerObj) {
- self.urlData.header = JSON.stringify(this.headerObj);
- }
- else {
- delete self.urlData.header;
- }
- var promise = egret.PromiseObject.create();
- promise.onSuccessFunc = function (getted_str) {
- self._response = getted_str;
- egret.$callAsync(egret.Event.dispatchEvent, egret.Event, self, egret.Event.COMPLETE);
- };
- promise.onErrorFunc = function (error_code) {
- egret.$warn(1019, error_code);
- egret.Event.dispatchEvent(self, egret.IOErrorEvent.IO_ERROR);
- };
- promise.onResponseHeaderFunc = this.onResponseHeader;
- promise.onResponseHeaderThisObject = this;
- egret_native.requireHttp(self._url, self.urlData, promise);
- }
- else if (!egret_native.isFileExists(self._url)) {
- download();
- }
- else {
- readFileAsync();
- }
- function readFileAsync() {
- var promise = new egret.PromiseObject();
- promise.onSuccessFunc = function (content) {
- self._response = content;
- egret.Event.dispatchEvent(self, egret.Event.COMPLETE);
- };
- promise.onErrorFunc = function () {
- egret.Event.dispatchEvent(self, egret.IOErrorEvent.IO_ERROR);
- };
- if (self._responseType == egret.HttpResponseType.ARRAY_BUFFER) {
- egret_native.readFileAsync(self._url, promise, "ArrayBuffer");
- }
- else {
- egret_native.readFileAsync(self._url, promise);
- }
- }
- function download() {
- var promise = egret.PromiseObject.create();
- promise.onSuccessFunc = readFileAsync;
- promise.onErrorFunc = function () {
- egret.Event.dispatchEvent(self, egret.IOErrorEvent.IO_ERROR);
- };
- promise.onResponseHeaderFunc = this.onResponseHeader;
- promise.onResponseHeaderThisObject = this;
- egret_native.download(self._url, self._url, promise);
- }
- };
- /**
- * 是否是网络地址
- * @param url
- * @returns {boolean}
- */
- NativeHttpRequest.prototype.isNetUrl = function (url) {
- return url.indexOf("http://") != -1 || url.indexOf("HTTP://") != -1 || url.indexOf("https://") != -1 || url.indexOf("HTTPS://") != -1;
- };
- /**
- * @private
- * 如果请求已经被发送,则立刻中止请求.
- */
- NativeHttpRequest.prototype.abort = function () {
- };
- NativeHttpRequest.prototype.onResponseHeader = function (headers) {
- this.responseHeader = "";
- var obj = JSON.parse(headers);
- for (var key in obj) {
- this.responseHeader += key + ": " + obj[key] + "\r\n";
- }
- };
- /**
- * @private
- * 返回所有响应头信息(响应头名和值), 如果响应头还没接受,则返回"".
- */
- NativeHttpRequest.prototype.getAllResponseHeaders = function () {
- return this.responseHeader;
- };
- /**
- * @private
- * 给指定的HTTP请求头赋值.在这之前,您必须确认已经调用 open() 方法打开了一个url.
- * @param header 将要被赋值的请求头名称.
- * @param value 给指定的请求头赋的值.
- */
- NativeHttpRequest.prototype.setRequestHeader = function (header, value) {
- if (!this.headerObj) {
- this.headerObj = {};
- }
- this.headerObj[header] = value;
- };
- /**
- * @private
- * 返回指定的响应头的值, 如果响应头还没被接受,或该响应头不存在,则返回"".
- * @param header 要返回的响应头名称
- */
- NativeHttpRequest.prototype.getResponseHeader = function (header) {
- return "";
- };
- return NativeHttpRequest;
- }(egret.EventDispatcher));
- native.NativeHttpRequest = NativeHttpRequest;
- __reflect(NativeHttpRequest.prototype, "egret.native.NativeHttpRequest", ["egret.HttpRequest"]);
- egret.HttpRequest = NativeHttpRequest;
- if (true) {
- egret.$markReadOnly(NativeHttpRequest, "response");
- }
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- * ImageLoader 类可用于加载图像(JPG、PNG 或 GIF)文件。使用 load() 方法来启动加载。被加载的图像对象数据将存储在 ImageLoader.data 属性上 。
- */
- var NativeImageLoader = (function (_super) {
- __extends(NativeImageLoader, _super);
- function NativeImageLoader() {
- var _this = _super.apply(this, arguments) || this;
- /**
- * @private
- * 使用 load() 方法加载成功的 BitmapData 图像数据。
- */
- _this.data = null;
- /**
- * @private
- * 当从其他站点加载一个图片时,指定是否启用跨域资源共享(CORS),默认值为null。
- * 可以设置为"anonymous","use-credentials"或null,设置为其他值将等同于"anonymous"。
- */
- _this._crossOrigin = null;
- return _this;
- }
- Object.defineProperty(NativeImageLoader.prototype, "crossOrigin", {
- get: function () {
- return this._crossOrigin;
- },
- set: function (value) {
- this._crossOrigin = value;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @private
- *
- * @param url
- * @param callback
- */
- NativeImageLoader.prototype.load = function (url) {
- this.check(url);
- };
- NativeImageLoader.prototype.check = function (url) {
- var self = this;
- if (self.isNetUrl(url)) {
- self.download(url);
- }
- else if (!egret_native.isFileExists(url)) {
- self.download(url);
- }
- else {
- self.loadTexture(url);
- }
- };
- NativeImageLoader.prototype.download = function (url) {
- var self = this;
- var promise = egret.PromiseObject.create();
- promise.onSuccessFunc = function () {
- self.loadTexture(url);
- };
- promise.onErrorFunc = function () {
- self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
- };
- egret_native.download(url, url, promise);
- };
- NativeImageLoader.prototype.loadTexture = function (url) {
- var self = this;
- var promise = new egret.PromiseObject();
- promise.onSuccessFunc = function (bitmapData) {
- self.data = new egret.BitmapData(bitmapData);
- self.dispatchEventWith(egret.Event.COMPLETE);
- };
- promise.onErrorFunc = function () {
- self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
- };
- egret_native.Texture.addTextureAsyn(url, promise);
- };
- /**
- * 是否是网络地址
- * @param url
- * @returns {boolean}
- */
- NativeImageLoader.prototype.isNetUrl = function (url) {
- return url.indexOf("http://") != -1 || url.indexOf("HTTP://") != -1 || url.indexOf("https://") != -1 || url.indexOf("HTTPS://") != -1;
- };
- return NativeImageLoader;
- }(egret.EventDispatcher));
- /**
- * @private
- * 指定是否启用跨域资源共享,如果ImageLoader实例有设置过crossOrigin属性将使用设置的属性
- */
- NativeImageLoader.crossOrigin = null;
- native.NativeImageLoader = NativeImageLoader;
- __reflect(NativeImageLoader.prototype, "egret.native.NativeImageLoader", ["egret.ImageLoader"]);
- egret.ImageLoader = NativeImageLoader;
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @classdesc
- * @implements egret.StageText
- * @private
- * @version Egret 2.4
- * @platform Web,Native
- */
- var NativeStageText = (function (_super) {
- __extends(NativeStageText, _super);
- /**
- * @version Egret 2.4
- * @platform Web,Native
- */
- function NativeStageText() {
- var _this = _super.call(this) || this;
- /**
- * @private
- */
- _this.textValue = "";
- /**
- * @private
- */
- _this.colorValue = 0xffffff;
- /**
- * @private
- */
- _this.isFinishDown = false;
- _this.textValue = "";
- return _this;
- }
- /**
- * @private
- *
- * @returns
- */
- NativeStageText.prototype.$getText = function () {
- if (!this.textValue) {
- this.textValue = "";
- }
- return this.textValue;
- };
- /**
- * @private
- *
- * @param value
- */
- NativeStageText.prototype.$setText = function (value) {
- this.textValue = value;
- return true;
- };
- NativeStageText.prototype.$setColor = function (value) {
- this.colorValue = value;
- return true;
- };
- /**
- * @private
- *
- */
- NativeStageText.prototype.$onBlur = function () {
- };
- //全屏键盘
- NativeStageText.prototype.showScreenKeyboard = function () {
- var self = this;
- self.dispatchEvent(new egret.Event("focus"));
- egret.Event.dispatchEvent(self, "focus", false, { "showing": true });
- egret_native.EGT_TextInput = function (appendText) {
- if (self.$textfield.multiline) {
- self.textValue = appendText;
- self.dispatchEvent(new egret.Event("updateText"));
- if (self.isFinishDown) {
- self.isFinishDown = false;
- self.dispatchEvent(new egret.Event("blur"));
- }
- }
- else {
- self.textValue = appendText.replace(/[\n|\r]/, "");
- //关闭软键盘
- egret_native.TextInputOp.setKeybordOpen(false);
- self.dispatchEvent(new egret.Event("updateText"));
- self.dispatchEvent(new egret.Event("blur"));
- }
- };
- //点击完成
- egret_native.EGT_keyboardFinish = function () {
- if (self.$textfield.multiline) {
- self.isFinishDown = true;
- }
- };
- };
- /**
- * @private
- *
- */
- NativeStageText.prototype.$show = function () {
- var self = this;
- var textfield = this.$textfield;
- var values = textfield.$TextField;
- egret_native.TextInputOp.setKeybordOpen(false);
- egret_native.EGT_getTextEditerContentText = function () {
- return self.$getText();
- };
- egret_native.EGT_keyboardDidShow = function () {
- //if (egret_native.TextInputOp.isFullScreenKeyBoard()) {//横屏
- //}
- self.showScreenKeyboard();
- egret_native.EGT_keyboardDidShow = function () {
- };
- if (egret_native.TextInputOp.updateConfig) {
- egret_native.TextInputOp.updateConfig(JSON.stringify({
- "font_color": values[2 /* textColor */]
- }));
- }
- };
- egret_native.EGT_keyboardDidHide = function () {
- };
- egret_native.EGT_deleteBackward = function () {
- };
- var inputType = values[37 /* inputType */];
- var inputMode = values[30 /* multiline */] ? 0 : 6;
- var inputFlag = -1; //textfield.displayAsPassword ? 0 : -1;
- if (inputType == egret.TextFieldInputType.PASSWORD) {
- inputFlag = 0;
- }
- else if (inputType == egret.TextFieldInputType.TEL) {
- inputMode = 3;
- }
- var returnType = 1;
- var maxLength = values[21 /* maxChars */] <= 0 ? -1 : values[21 /* maxChars */];
- var node = textfield.$getRenderNode();
- var point = this.$textfield.localToGlobal(0, 0);
- egret_native.TextInputOp.setKeybordOpen(true, JSON.stringify({
- "inputMode": inputMode,
- "inputFlag": inputFlag,
- "returnType": returnType,
- "maxLength": maxLength,
- "x": point.x,
- "y": point.y,
- "width": textfield.width,
- "height": textfield.height,
- "font_size": values[0 /* fontSize */],
- "font_color": values[2 /* textColor */],
- "textAlign": values[9 /* textAlign */],
- "verticalAlign": values[10 /* verticalAlign */]
- }));
- };
- /**
- * @private
- *
- */
- NativeStageText.prototype.$hide = function () {
- egret_native.TextInputOp.setKeybordOpen(false);
- this.dispatchEvent(new egret.Event("blur"));
- };
- NativeStageText.prototype.$resetStageText = function () {
- };
- NativeStageText.prototype.$addToStage = function () {
- };
- NativeStageText.prototype.$removeFromStage = function () {
- };
- NativeStageText.prototype.$setTextField = function (value) {
- this.$textfield = value;
- return true;
- };
- return NativeStageText;
- }(egret.EventDispatcher));
- native.NativeStageText = NativeStageText;
- __reflect(NativeStageText.prototype, "egret.native.NativeStageText", ["egret.StageText"]);
- egret.StageText = NativeStageText;
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var web;
- (function (web) {
- /**
- * @private
- * XML节点基类
- */
- var XMLNode = (function () {
- /**
- * @private
- */
- function XMLNode(nodeType, parent) {
- this.nodeType = nodeType;
- this.parent = parent;
- }
- return XMLNode;
- }());
- web.XMLNode = XMLNode;
- __reflect(XMLNode.prototype, "egret.web.XMLNode");
- /**
- * @private
- * XML节点对象
- */
- var XML = (function (_super) {
- __extends(XML, _super);
- /**
- * @private
- */
- function XML(localName, parent, prefix, namespace, name) {
- var _this = _super.call(this, 1, parent) || this;
- /**
- * @private
- * 当前节点上的属性列表
- */
- _this.attributes = {};
- /**
- * @private
- * 当前节点的子节点列表
- */
- _this.children = [];
- _this.localName = localName;
- _this.prefix = prefix;
- _this.namespace = namespace;
- _this.name = name;
- return _this;
- }
- return XML;
- }(XMLNode));
- web.XML = XML;
- __reflect(XML.prototype, "egret.web.XML");
- /**
- * @private
- * XML文本节点
- */
- var XMLText = (function (_super) {
- __extends(XMLText, _super);
- /**
- * @private
- */
- function XMLText(text, parent) {
- var _this = _super.call(this, 3, parent) || this;
- _this.text = text;
- return _this;
- }
- return XMLText;
- }(XMLNode));
- web.XMLText = XMLText;
- __reflect(XMLText.prototype, "egret.web.XMLText");
- /**
- * @private
- * 解析字符串为XML对象
- * @param text 要解析的字符串
- */
- function parse(text) {
- var xmlDocStr = egret_native.xmlStr2JsonStr(text);
- //替换换行符
- xmlDocStr = xmlDocStr.replace(/\n/g, "\\n");
- var xmlDoc = JSON.parse(xmlDocStr);
- return parseNode(xmlDoc, null);
- }
- /**
- * @private
- * 解析一个节点
- */
- function parseNode(node, parent) {
- if (node.localName == "parsererror") {
- throw new Error(node.textContent);
- }
- var xml = new XML(node.localName, parent, node.prefix, node.namespace, node.name);
- var nodeAttributes = node.attributes;
- var attributes = xml.attributes;
- for (var key in nodeAttributes) {
- attributes[key] = xml["$" + key] = nodeAttributes[key];
- }
- var childNodes = node.children;
- var length = childNodes.length;
- var children = xml.children;
- for (var i = 0; i < length; i++) {
- var childNode = childNodes[i];
- var nodeType = childNode.nodeType;
- var childXML = null;
- if (nodeType == 1) {
- childXML = parseNode(childNode, xml);
- }
- else if (nodeType == 3) {
- var text = childNode.text.trim();
- if (text) {
- childXML = new XMLText(text, xml);
- }
- }
- if (childXML) {
- children.push(childXML);
- }
- }
- return xml;
- }
- egret.XML = { parse: parse };
- })(web = egret.web || (egret.web = {}));
- })(egret || (egret = {}));
- //////////////////////////////////////////////////////////////////////////////////////
- //
- // Copyright (c) 2014-present, Egret Technology.
- // All rights reserved.
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the distribution.
- // * Neither the name of the Egret nor the
- // names of its contributors may be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
- // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
- // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //////////////////////////////////////////////////////////////////////////////////////
- var egret;
- (function (egret) {
- var native;
- (function (native) {
- /**
- * @private
- */
- function getOption(key) {
- return egret_native.getOption(key);
- }
- native.getOption = getOption;
- egret.getOption = getOption;
- })(native = egret.native || (egret.native = {}));
- })(egret || (egret = {}));
|