laya.core.js 979 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369
  1. /***********************************/
  2. /*http://www.layabox.com 2017/12/12*/
  3. /***********************************/
  4. var Laya=window.Laya=(function(window,document){
  5. var Laya={
  6. __internals:[],
  7. __packages:{},
  8. __classmap:{'Object':Object,'Function':Function,'Array':Array,'String':String},
  9. __sysClass:{'object':'Object','array':'Array','string':'String','dictionary':'Dictionary'},
  10. __propun:{writable: true,enumerable: false,configurable: true},
  11. __presubstr:String.prototype.substr,
  12. __substr:function(ofs,sz){return arguments.length==1?Laya.__presubstr.call(this,ofs):Laya.__presubstr.call(this,ofs,sz>0?sz:(this.length+sz));},
  13. __init:function(_classs){_classs.forEach(function(o){o.__init$ && o.__init$();});},
  14. __isClass:function(o){return o && (o.__isclass || o==Object || o==String || o==Array);},
  15. __newvec:function(sz,value){
  16. var d=[];
  17. d.length=sz;
  18. for(var i=0;i<sz;i++) d[i]=value;
  19. return d;
  20. },
  21. __extend:function(d,b){
  22. for (var p in b){
  23. if (!b.hasOwnProperty(p)) continue;
  24. var gs=Object.getOwnPropertyDescriptor(b, p);
  25. var g = gs.get, s = gs.set;
  26. if ( g || s ) {
  27. if ( g && s)
  28. Object.defineProperty(d,p,gs);
  29. else{
  30. g && Object.defineProperty(d, p, g);
  31. s && Object.defineProperty(d, p, s);
  32. }
  33. }
  34. else d[p] = b[p];
  35. }
  36. function __() { Laya.un(this,'constructor',d); }__.prototype=b.prototype;d.prototype=new __();Laya.un(d.prototype,'__imps',Laya.__copy({},b.prototype.__imps));
  37. },
  38. __copy:function(dec,src){
  39. if(!src) return null;
  40. dec=dec||{};
  41. for(var i in src) dec[i]=src[i];
  42. return dec;
  43. },
  44. __package:function(name,o){
  45. if(Laya.__packages[name]) return;
  46. Laya.__packages[name]=true;
  47. var p=window,strs=name.split('.');
  48. if(strs.length>1){
  49. for(var i=0,sz=strs.length-1;i<sz;i++){
  50. var c=p[strs[i]];
  51. p=c?c:(p[strs[i]]={});
  52. }
  53. }
  54. p[strs[strs.length-1]] || (p[strs[strs.length-1]]=o||{});
  55. },
  56. __hasOwnProperty:function(name,o){
  57. o=o ||this;
  58. function classHas(name,o){
  59. if(Object.hasOwnProperty.call(o.prototype,name)) return true;
  60. var s=o.prototype.__super;
  61. return s==null?null:classHas(name,s);
  62. }
  63. return (Object.hasOwnProperty.call(o,name)) || classHas(name,o.__class);
  64. },
  65. __typeof:function(o,value){
  66. if(!o || !value) return false;
  67. if(value===String) return (typeof o==='string');
  68. if(value===Number) return (typeof o==='number');
  69. if(value.__interface__) value=value.__interface__;
  70. else if(typeof value!='string') return (o instanceof value);
  71. return (o.__imps && o.__imps[value]) || (o.__class==value);
  72. },
  73. __as:function(value,type){
  74. return (this.__typeof(value,type))?value:null;
  75. },
  76. __int:function(value){
  77. return value?parseInt(value):0;
  78. },
  79. interface:function(name,_super){
  80. Laya.__package(name,{});
  81. var ins=Laya.__internals;
  82. var a=ins[name]=ins[name] || {self:name};
  83. if(_super)
  84. {
  85. var supers=_super.split(',');
  86. a.extend=[];
  87. for(var i=0;i<supers.length;i++){
  88. var nm=supers[i];
  89. ins[nm]=ins[nm] || {self:nm};
  90. a.extend.push(ins[nm]);
  91. }
  92. }
  93. var o=window,words=name.split('.');
  94. for(var i=0;i<words.length-1;i++) o=o[words[i]];
  95. o[words[words.length-1]]={__interface__:name};
  96. },
  97. class:function(o,fullName,_super,miniName){
  98. _super && Laya.__extend(o,_super);
  99. if(fullName){
  100. Laya.__package(fullName,o);
  101. Laya.__classmap[fullName]=o;
  102. if(fullName.indexOf('.')>0){
  103. if(fullName.indexOf('laya.')==0){
  104. var paths=fullName.split('.');
  105. miniName=miniName || paths[paths.length-1];
  106. if(Laya[miniName]) console.log("Warning!,this class["+miniName+"] already exist:",Laya[miniName]);
  107. Laya[miniName]=o;
  108. }
  109. }
  110. else {
  111. if(fullName=="Main")
  112. window.Main=o;
  113. else{
  114. if(Laya[fullName]){
  115. console.log("Error!,this class["+fullName+"] already exist:",Laya[fullName]);
  116. }
  117. Laya[fullName]=o;
  118. }
  119. }
  120. }
  121. var un=Laya.un,p=o.prototype;
  122. un(p,'hasOwnProperty',Laya.__hasOwnProperty);
  123. un(p,'__class',o);
  124. un(p,'__super',_super);
  125. un(p,'__className',fullName);
  126. un(o,'__super',_super);
  127. un(o,'__className',fullName);
  128. un(o,'__isclass',true);
  129. un(o,'super',function(o){this.__super.call(o);});
  130. },
  131. imps:function(dec,src){
  132. if(!src) return null;
  133. var d=dec.__imps|| Laya.un(dec,'__imps',{});
  134. function __(name){
  135. var c,exs;
  136. if(! (c=Laya.__internals[name]) ) return;
  137. d[name]=true;
  138. if(!(exs=c.extend)) return;
  139. for(var i=0;i<exs.length;i++){
  140. __(exs[i].self);
  141. }
  142. }
  143. for(var i in src) __(i);
  144. },
  145. superSet:function(clas,o,prop,value){
  146. var fun = clas.prototype["_$set_"+prop];
  147. fun && fun.call(o,value);
  148. },
  149. superGet:function(clas,o,prop){
  150. var fun = clas.prototype["_$get_"+prop];
  151. return fun?fun.call(o):null;
  152. },
  153. getset:function(isStatic,o,name,getfn,setfn){
  154. if(!isStatic){
  155. getfn && Laya.un(o,'_$get_'+name,getfn);
  156. setfn && Laya.un(o,'_$set_'+name,setfn);
  157. }
  158. else{
  159. getfn && (o['_$GET_'+name]=getfn);
  160. setfn && (o['_$SET_'+name]=setfn);
  161. }
  162. if(getfn && setfn)
  163. Object.defineProperty(o,name,{get:getfn,set:setfn,enumerable:false,configurable:true});
  164. else{
  165. getfn && Object.defineProperty(o,name,{get:getfn,enumerable:false,configurable:true});
  166. setfn && Object.defineProperty(o,name,{set:setfn,enumerable:false,configurable:true});
  167. }
  168. },
  169. static:function(_class,def){
  170. for(var i=0,sz=def.length;i<sz;i+=2){
  171. if(def[i]=='length')
  172. _class.length=def[i+1].call(_class);
  173. else{
  174. function tmp(){
  175. var name=def[i];
  176. var getfn=def[i+1];
  177. Object.defineProperty(_class,name,{
  178. get:function(){delete this[name];return this[name]=getfn.call(this);},
  179. set:function(v){delete this[name];this[name]=v;},enumerable: true,configurable: true});
  180. }
  181. tmp();
  182. }
  183. }
  184. },
  185. un:function(obj,name,value){
  186. value || (value=obj[name]);
  187. Laya.__propun.value=value;
  188. Object.defineProperty(obj, name, Laya.__propun);
  189. return value;
  190. },
  191. uns:function(obj,names){
  192. names.forEach(function(o){Laya.un(obj,o)});
  193. }
  194. };
  195. window.console=window.console || ({log:function(){}});
  196. window.trace=window.console.log;
  197. Error.prototype.throwError=function(){throw arguments;};
  198. //String.prototype.substr=Laya.__substr;
  199. Object.defineProperty(Array.prototype,'fixed',{enumerable: false});
  200. return Laya;
  201. })(window,document);
  202. (function(window,document,Laya){
  203. var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
  204. })(window,document,Laya);
  205. (function(window,document,Laya){
  206. var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
  207. Laya.interface('laya.filters.IFilter');
  208. Laya.interface('laya.resource.IDispose');
  209. Laya.interface('laya.resource.IDestroy');
  210. Laya.interface('laya.webgl.submit.ISubmit');
  211. Laya.interface('laya.resource.ICreateResource');
  212. Laya.interface('laya.webgl.canvas.save.ISaveData');
  213. Laya.interface('laya.resource.ISingletonElement');
  214. /**
  215. *<code>Laya</code> 是全局对象的引用入口集。
  216. *Laya类引用了一些常用的全局对象,比如Laya.stage:舞台,Laya.timer:时间管理器,Laya.loader:加载管理器,使用时注意大小写。
  217. */
  218. //class Laya
  219. var ___Laya=(function(){
  220. //function Laya(){}
  221. /**
  222. *表示是否捕获全局错误并弹出提示。默认为false。
  223. *适用于移动设备等不方便调试的时候,设置为true后,如有未知错误,可以弹窗抛出详细错误堆栈。
  224. */
  225. __getset(1,Laya,'alertGlobalError',null,function(value){
  226. var erralert=0;
  227. if (value){
  228. Browser.window.onerror=function (msg,url,line,column,detail){
  229. if (erralert++< 5 && detail)
  230. alert("出错啦,请把此信息截图给研发商\n"+msg+"\n"+detail.stack);
  231. }
  232. }else {
  233. Browser.window.onerror=null;
  234. }
  235. });
  236. Laya.init=function(width,height,__plugins){
  237. var plugins=[];for(var i=2,sz=arguments.length;i<sz;i++)plugins.push(arguments[i]);
  238. if (Laya._isinit)return;
  239. Laya._isinit=true;
  240. ArrayBuffer.prototype.slice || (ArrayBuffer.prototype.slice=Laya._arrayBufferSlice);
  241. Browser.__init__();
  242. Laya.systemTimer=new Timer(false);
  243. Laya.startTimer=new Timer(false);
  244. Laya.physicsTimer=new Timer(false);
  245. Laya.updateTimer=new Timer(false);
  246. Laya.lateTimer=new Timer(false);
  247. Laya.timer=new Timer(false);
  248. Laya.loader=new LoaderManager();
  249. WeakObject.__init__();
  250. WebGL.inner_enable();
  251. for (var i=0,n=plugins.length;i < n;i++){
  252. if (plugins[i] && plugins[i].enable){
  253. plugins[i].enable();
  254. }
  255. }
  256. if (Render.isConchApp){
  257. RunDriver.enableNative();
  258. }
  259. CacheManger.beginCheck();
  260. Laya._currentStage=Laya.stage=new Stage();
  261. URL.rootPath=URL._basePath=Laya._getUrlPath();
  262. Laya.render=new Render(0,0);
  263. Laya.stage.size(width,height);
  264. window.stage=Laya.stage;
  265. RenderSprite.__init__();
  266. KeyBoardManager.__init__();
  267. MouseManager.instance.__init__(Laya.stage,Render.canvas);
  268. Input.__init__();
  269. SoundManager.autoStopMusic=true;
  270. return Render.canvas;
  271. }
  272. Laya._getUrlPath=function(){
  273. var location=Browser.window.location;
  274. var pathName=location.pathname;
  275. pathName=pathName.charAt(2)==':' ? pathName.substring(1):pathName;
  276. return URL.getPath(location.protocol=="file:" ? pathName :location.protocol+"//"+location.host+location.pathname);
  277. }
  278. Laya._arrayBufferSlice=function(start,end){
  279. var arr=/*__JS__ */this;
  280. var arrU8List=new Uint8Array(arr,start,end-start);
  281. var newU8List=new Uint8Array(arrU8List.length);
  282. newU8List.set(arrU8List);
  283. return newU8List.buffer;
  284. }
  285. Laya._runScript=function(script){
  286. return Browser.window[Laya._evcode](script);
  287. }
  288. Laya.enableDebugPanel=function(debugJsPath){
  289. (debugJsPath===void 0)&& (debugJsPath="libs/laya.debugtool.js");
  290. if (!Laya["DebugPanel"]){
  291. var script=Browser.createElement("script");
  292. script.onload=function (){
  293. Laya["DebugPanel"].enable();
  294. }
  295. script.src=debugJsPath;
  296. Browser.document.body.appendChild(script);
  297. }else {
  298. Laya["DebugPanel"].enable();
  299. }
  300. }
  301. Laya.stage=null;
  302. Laya.systemTimer=null;
  303. Laya.startTimer=null;
  304. Laya.physicsTimer=null;
  305. Laya.updateTimer=null;
  306. Laya.lateTimer=null;
  307. Laya.timer=null;
  308. Laya.loader=null;
  309. Laya.version="2.1.2";
  310. Laya.render=null;
  311. Laya._currentStage=null;
  312. Laya._isinit=false;
  313. Laya.isWXOpenDataContext=false;
  314. Laya.isWXPosMsg=false;
  315. __static(Laya,
  316. ['_evcode',function(){return this._evcode="eva"+"l";}
  317. ]);
  318. return Laya;
  319. })()
  320. /**
  321. *@private
  322. *快速节点命令执行器
  323. *多个指令组合才有意义,单个指令没必要在下面加
  324. */
  325. //class laya.renders.LayaGLQuickRunner
  326. var LayaGLQuickRunner=(function(){
  327. function LayaGLQuickRunner(){}
  328. __class(LayaGLQuickRunner,'laya.renders.LayaGLQuickRunner');
  329. LayaGLQuickRunner.__init__=function(){
  330. LayaGLQuickRunner.map[ /*laya.display.SpriteConst.ALPHA*/0x01 | /*laya.display.SpriteConst.TRANSFORM*/0x02 | /*laya.display.SpriteConst.GRAPHICS*/0x200]=LayaGLQuickRunner.alpha_transform_drawLayaGL;
  331. LayaGLQuickRunner.map[ /*laya.display.SpriteConst.ALPHA*/0x01 | /*laya.display.SpriteConst.GRAPHICS*/0x200]=LayaGLQuickRunner.alpha_drawLayaGL;
  332. LayaGLQuickRunner.map[ /*laya.display.SpriteConst.TRANSFORM*/0x02 | /*laya.display.SpriteConst.GRAPHICS*/0x200]=LayaGLQuickRunner.transform_drawLayaGL;
  333. LayaGLQuickRunner.map[ /*laya.display.SpriteConst.TRANSFORM*/0x02 | /*laya.display.SpriteConst.CHILDS*/0x2000]=LayaGLQuickRunner.transform_drawNodes;
  334. LayaGLQuickRunner.map[ /*laya.display.SpriteConst.ALPHA*/0x01 | /*laya.display.SpriteConst.TRANSFORM*/0x02 | /*laya.display.SpriteConst.TEXTURE*/0x100]=LayaGLQuickRunner.alpha_transform_drawTexture;
  335. LayaGLQuickRunner.map[ /*laya.display.SpriteConst.ALPHA*/0x01 | /*laya.display.SpriteConst.TEXTURE*/0x100]=LayaGLQuickRunner.alpha_drawTexture;
  336. LayaGLQuickRunner.map[ /*laya.display.SpriteConst.TRANSFORM*/0x02 | /*laya.display.SpriteConst.TEXTURE*/0x100]=LayaGLQuickRunner.transform_drawTexture;
  337. LayaGLQuickRunner.map[ /*laya.display.SpriteConst.GRAPHICS*/0x200 | /*laya.display.SpriteConst.CHILDS*/0x2000]=LayaGLQuickRunner.drawLayaGL_drawNodes;
  338. }
  339. LayaGLQuickRunner.transform_drawTexture=function(sprite,context,x,y){
  340. var style=sprite._style;
  341. var tex=sprite.texture;
  342. context.saveTransform(LayaGLQuickRunner.curMat);
  343. context.transformByMatrix(sprite.transform,x,y);
  344. context.drawTexture(tex,-sprite.pivotX,-sprite.pivotY,sprite._width || tex.width,sprite._height || tex.height);
  345. context.restoreTransform(LayaGLQuickRunner.curMat);
  346. }
  347. LayaGLQuickRunner.alpha_drawTexture=function(sprite,context,x,y){
  348. var style=sprite._style;
  349. var alpha=NaN;
  350. var tex=sprite.texture;
  351. if ((alpha=style.alpha)> 0.01 || sprite._needRepaint()){
  352. var temp=context.globalAlpha;
  353. context.globalAlpha *=alpha;
  354. context.drawTexture(tex,x-style.pivotX+tex.offsetX,y-style.pivotY+tex.offsetY,sprite._width || tex.width,sprite._height || tex.height);
  355. context.globalAlpha=temp;
  356. }
  357. }
  358. LayaGLQuickRunner.alpha_transform_drawTexture=function(sprite,context,x,y){
  359. var style=sprite._style;
  360. var alpha=NaN;
  361. var tex=sprite.texture;
  362. if ((alpha=style.alpha)> 0.01 || sprite._needRepaint()){
  363. var temp=context.globalAlpha;
  364. context.globalAlpha *=alpha;
  365. context.saveTransform(LayaGLQuickRunner.curMat);
  366. context.transformByMatrix(sprite.transform,x,y);
  367. context.drawTexture(tex,-style.pivotX+tex.offsetX,-style.pivotY+tex.offsetY,sprite._width || tex.width,sprite._height || tex.height);
  368. context.restoreTransform(LayaGLQuickRunner.curMat);
  369. context.globalAlpha=temp;
  370. }
  371. }
  372. LayaGLQuickRunner.alpha_transform_drawLayaGL=function(sprite,context,x,y){
  373. var style=sprite._style;
  374. var alpha=NaN;
  375. if ((alpha=style.alpha)> 0.01 || sprite._needRepaint()){
  376. var temp=context.globalAlpha;
  377. context.globalAlpha *=alpha;
  378. context.saveTransform(LayaGLQuickRunner.curMat);
  379. context.transformByMatrix(sprite.transform,x,y);
  380. sprite._graphics && sprite._graphics._render(sprite,context,-style.pivotX,-style.pivotY);
  381. context.restoreTransform(LayaGLQuickRunner.curMat);
  382. context.globalAlpha=temp;
  383. }
  384. }
  385. LayaGLQuickRunner.alpha_drawLayaGL=function(sprite,context,x,y){
  386. var style=sprite._style;
  387. var alpha=NaN;
  388. if ((alpha=style.alpha)> 0.01 || sprite._needRepaint()){
  389. var temp=context.globalAlpha;
  390. context.globalAlpha *=alpha;
  391. sprite._graphics && sprite._graphics._render(sprite,context,x-style.pivotX,y-style.pivotY);
  392. context.globalAlpha=temp;
  393. }
  394. }
  395. LayaGLQuickRunner.transform_drawLayaGL=function(sprite,context,x,y){
  396. var style=sprite._style;
  397. context.saveTransform(LayaGLQuickRunner.curMat);
  398. context.transformByMatrix(sprite.transform,x,y);
  399. sprite._graphics && sprite._graphics._render(sprite,context,-style.pivotX,-style.pivotY);
  400. context.restoreTransform(LayaGLQuickRunner.curMat);
  401. }
  402. LayaGLQuickRunner.transform_drawNodes=function(sprite,context,x,y){
  403. var textLastRender=sprite._getBit(/*laya.Const.DRAWCALL_OPTIMIZE*/0x100)&& context.drawCallOptimize(true);
  404. var style=sprite._style;
  405. context.saveTransform(LayaGLQuickRunner.curMat);
  406. context.transformByMatrix(sprite.transform,x,y);
  407. x=-style.pivotX;
  408. y=-style.pivotY;
  409. var childs=sprite._children,n=childs.length,ele;
  410. if (style.viewport){
  411. var rect=style.viewport;
  412. var left=rect.x;
  413. var top=rect.y;
  414. var right=rect.right;
  415. var bottom=rect.bottom;
  416. var _x=NaN,_y=NaN;
  417. for (i=0;i < n;++i){
  418. if ((ele=childs [i])._visible && ((_x=ele._x)< right && (_x+ele.width)> left && (_y=ele._y)< bottom && (_y+ele.height)> top)){
  419. ele.render(context,x,y);
  420. }
  421. }
  422. }else {
  423. for (var i=0;i < n;++i)
  424. (ele=(childs [i]))._visible && ele.render(context,x,y);
  425. }
  426. context.restoreTransform(LayaGLQuickRunner.curMat);
  427. textLastRender && context.drawCallOptimize(false);
  428. }
  429. LayaGLQuickRunner.drawLayaGL_drawNodes=function(sprite,context,x,y){
  430. var textLastRender=sprite._getBit(/*laya.Const.DRAWCALL_OPTIMIZE*/0x100)&& context.drawCallOptimize(true);
  431. var style=sprite._style;
  432. x=x-style.pivotX;
  433. y=y-style.pivotY;
  434. sprite._graphics && sprite._graphics._render(sprite,context,x,y);
  435. var childs=sprite._children,n=childs.length,ele;
  436. if (style.viewport){
  437. var rect=style.viewport;
  438. var left=rect.x;
  439. var top=rect.y;
  440. var right=rect.right;
  441. var bottom=rect.bottom;
  442. var _x=NaN,_y=NaN;
  443. for (i=0;i < n;++i){
  444. if ((ele=childs [i])._visible && ((_x=ele._x)< right && (_x+ele.width)> left && (_y=ele._y)< bottom && (_y+ele.height)> top)){
  445. ele.render(context,x,y);
  446. }
  447. }
  448. }else {
  449. for (var i=0;i < n;++i)
  450. (ele=(childs [i]))._visible && ele.render(context,x,y);
  451. }
  452. textLastRender && context.drawCallOptimize(false);
  453. }
  454. LayaGLQuickRunner.map={};
  455. __static(LayaGLQuickRunner,
  456. ['curMat',function(){return this.curMat=new Matrix();}
  457. ]);
  458. return LayaGLQuickRunner;
  459. })()
  460. /**
  461. *@private
  462. *<code>ColorUtils</code> 是一个颜色值处理类。
  463. */
  464. //class laya.utils.ColorUtils
  465. var ColorUtils=(function(){
  466. function ColorUtils(value){
  467. //TODO:delete?
  468. this.arrColor=[];
  469. /**字符串型颜色值。*/
  470. //this.strColor=null;
  471. /**uint 型颜色值。*/
  472. //this.numColor=0;
  473. /**@private TODO:*/
  474. //this._drawStyle=null;
  475. if (value==null){
  476. this.strColor="#00000000";
  477. this.numColor=0;
  478. this.arrColor=[0,0,0,0];
  479. return;
  480. };
  481. var i=0,len=0;
  482. var color=0;
  483. if ((typeof value=='string')){
  484. if ((value).indexOf("rgba(")>=0||(value).indexOf("rgb(")>=0){
  485. var tStr=value;
  486. var beginI=0,endI=0;
  487. beginI=tStr.indexOf("(");
  488. endI=tStr.indexOf(")");
  489. tStr=tStr.substring(beginI+1,endI);
  490. this.arrColor=tStr.split(",");
  491. len=this.arrColor.length;
  492. for (i=0;i < len;i++){
  493. this.arrColor[i]=parseFloat(this.arrColor[i]);
  494. if (i < 3){
  495. this.arrColor[i]=Math.round(this.arrColor[i]);
  496. }
  497. }
  498. if (this.arrColor.length==4){
  499. color=((this.arrColor[0] *256+this.arrColor[1])*256+this.arrColor[2])*256+Math.round(this.arrColor[3] *255);
  500. }else{
  501. color=((this.arrColor[0] *256+this.arrColor[1])*256+this.arrColor[2]);
  502. }
  503. this.strColor=value;
  504. }else{
  505. this.strColor=value;
  506. value.charAt(0)==='#' && (value=value.substr(1));
  507. len=value.length;
  508. if (len===3 || len===4){
  509. var temp="";
  510. for (i=0;i < len;i++){
  511. temp+=(value[i]+value[i]);
  512. }
  513. value=temp;
  514. }
  515. color=parseInt(value,16);
  516. }
  517. }else {
  518. color=value;
  519. this.strColor=Utils.toHexColor(color);
  520. }
  521. if (this.strColor.indexOf("rgba")>=0 || this.strColor.length===9){
  522. this.arrColor=[((0xFF000000 & color)>>>24)/ 255,((0xFF0000 & color)>> 16)/ 255,((0xFF00 & color)>>8)/ 255,(0xFF & color)/ 255];
  523. this.numColor=(0xff000000&color)>>>24|(color & 0xff0000)>> 8 | (color & 0x00ff00)<<8 | ((color & 0xff)<<24);
  524. }else {
  525. this.arrColor=[((0xFF0000 & color)>> 16)/ 255,((0xFF00 & color)>> 8)/ 255,(0xFF & color)/ 255,1];
  526. this.numColor=0xff000000|(color & 0xff0000)>> 16 | (color & 0x00ff00)| (color & 0xff)<< 16;
  527. }
  528. (this.arrColor).__id=++ColorUtils._COLODID;
  529. }
  530. __class(ColorUtils,'laya.utils.ColorUtils');
  531. ColorUtils._initDefault=function(){
  532. ColorUtils._DEFAULT={};
  533. for (var i in ColorUtils._COLOR_MAP)ColorUtils._SAVE[i]=ColorUtils._DEFAULT[i]=new ColorUtils(ColorUtils._COLOR_MAP[i]);
  534. return ColorUtils._DEFAULT;
  535. }
  536. ColorUtils._initSaveMap=function(){
  537. ColorUtils._SAVE_SIZE=0;
  538. ColorUtils._SAVE={};
  539. for (var i in ColorUtils._DEFAULT)ColorUtils._SAVE[i]=ColorUtils._DEFAULT[i];
  540. }
  541. ColorUtils.create=function(value){
  542. var key=value+"";
  543. var color=ColorUtils._SAVE[key];
  544. if (color !=null)return color;
  545. if (ColorUtils._SAVE_SIZE < 1000)ColorUtils._initSaveMap();
  546. return ColorUtils._SAVE[key]=new ColorUtils(value);
  547. }
  548. ColorUtils._SAVE={};
  549. ColorUtils._SAVE_SIZE=0;
  550. ColorUtils._COLOR_MAP={"purple":"#800080","orange":"#ffa500","white":'#FFFFFF',"red":'#FF0000',"green":'#00FF00',"blue":'#0000FF',"black":'#000000',"yellow":'#FFFF00','gray':'#808080' };
  551. ColorUtils._DEFAULT=ColorUtils._initDefault();
  552. ColorUtils._COLODID=1;
  553. return ColorUtils;
  554. })()
  555. //class laya.webgl.canvas.save.SaveBase
  556. var SaveBase=(function(){
  557. function SaveBase(){
  558. //this._valueName=null;
  559. //this._value=null;
  560. //this._dataObj=null;
  561. //this._newSubmit=false;
  562. }
  563. __class(SaveBase,'laya.webgl.canvas.save.SaveBase');
  564. var __proto=SaveBase.prototype;
  565. Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true})
  566. __proto.isSaveMark=function(){return false;}
  567. __proto.restore=function(context){
  568. this._dataObj[this._valueName]=this._value;
  569. SaveBase.POOL[SaveBase.POOL._length++]=this;
  570. this._newSubmit && (context._curSubmit=Submit.RENDERBASE);
  571. }
  572. SaveBase._createArray=function(){
  573. var value=[];
  574. value._length=0;
  575. return value;
  576. }
  577. SaveBase._init=function(){
  578. var namemap=SaveBase._namemap={};
  579. namemap[0x1]="ALPHA";
  580. namemap[0x2]="fillStyle";
  581. namemap[0x8]="font";
  582. namemap[0x100]="lineWidth";
  583. namemap[0x200]="strokeStyle";
  584. namemap[0x2000]="_mergeID";
  585. namemap[0x400]=namemap[0x800]=namemap[0x1000]=[];
  586. namemap[0x4000]="textBaseline";
  587. namemap[0x8000]="textAlign";
  588. namemap[0x10000]="_nBlendType";
  589. namemap[0x100000]="shader";
  590. namemap[0x200000]="filters";
  591. namemap[0x800000]='_colorFiler';
  592. return namemap;
  593. }
  594. SaveBase.save=function(context,type,dataObj,newSubmit){
  595. if ((context._saveMark._saveuse & type)!==type){
  596. context._saveMark._saveuse |=type;
  597. var cache=SaveBase.POOL;
  598. var o=cache._length > 0 ? cache[--cache._length] :(new SaveBase());
  599. o._value=dataObj[o._valueName=SaveBase._namemap[type]];
  600. o._dataObj=dataObj;
  601. o._newSubmit=newSubmit;
  602. var _save=context._save;
  603. _save[_save._length++]=o;
  604. }
  605. }
  606. SaveBase.POOL=laya.webgl.canvas.save.SaveBase._createArray();
  607. SaveBase._namemap=SaveBase._init();
  608. return SaveBase;
  609. })()
  610. /**
  611. *@private
  612. *精灵渲染器
  613. */
  614. //class laya.renders.RenderSprite
  615. var RenderSprite=(function(){
  616. function RenderSprite(type,next){
  617. /**@private */
  618. //this._next=null;
  619. /**@private */
  620. //this._fun=null;
  621. if (LayaGLQuickRunner.map[type]){
  622. this._fun=LayaGLQuickRunner.map[type];
  623. this._next=RenderSprite.NORENDER;
  624. return;
  625. }
  626. this._next=next || RenderSprite.NORENDER;
  627. switch (type){
  628. case 0:
  629. this._fun=this._no;
  630. return;
  631. case /*laya.display.SpriteConst.ALPHA*/0x01:
  632. this._fun=this._alpha;
  633. return;
  634. case /*laya.display.SpriteConst.TRANSFORM*/0x02:
  635. this._fun=this._transform;
  636. return;
  637. case /*laya.display.SpriteConst.BLEND*/0x04:
  638. this._fun=this._blend;
  639. return;
  640. case /*laya.display.SpriteConst.CANVAS*/0x08:
  641. this._fun=this._canvas;
  642. return;
  643. case /*laya.display.SpriteConst.MASK*/0x20:
  644. this._fun=this._mask;
  645. return;
  646. case /*laya.display.SpriteConst.CLIP*/0x40:
  647. this._fun=this._clip;
  648. return;
  649. case /*laya.display.SpriteConst.STYLE*/0x80:
  650. this._fun=this._style;
  651. return;
  652. case /*laya.display.SpriteConst.GRAPHICS*/0x200:
  653. this._fun=this._graphics;
  654. return;
  655. case /*laya.display.SpriteConst.CHILDS*/0x2000:
  656. this._fun=this._children;
  657. return;
  658. case /*laya.display.SpriteConst.CUSTOM*/0x800:
  659. this._fun=this._custom;
  660. return;
  661. case /*laya.display.SpriteConst.TEXTURE*/0x100:
  662. this._fun=this._texture;
  663. return;
  664. case /*laya.display.SpriteConst.FILTERS*/0x10:
  665. this._fun=Filter._filter;
  666. return;
  667. case 0x11111:
  668. this._fun=RenderSprite._initRenderFun;
  669. return;
  670. }
  671. this.onCreate(type);
  672. }
  673. __class(RenderSprite,'laya.renders.RenderSprite');
  674. var __proto=RenderSprite.prototype;
  675. __proto.onCreate=function(type){}
  676. __proto._style=function(sprite,context,x,y){
  677. var style=sprite._style;
  678. if (style.render !=null)style.render(sprite,context,x,y);
  679. var next=this._next;
  680. next._fun.call(next,sprite,context,x,y);
  681. }
  682. __proto._no=function(sprite,context,x,y){}
  683. //TODO:coverage
  684. __proto._custom=function(sprite,context,x,y){
  685. sprite.customRender(context,x,y);
  686. this._next._fun.call(this._next,sprite,context,x-sprite.pivotX,y-sprite.pivotY);
  687. }
  688. __proto._clip=function(sprite,context,x,y){
  689. var next=this._next;
  690. if (next==RenderSprite.NORENDER)return;
  691. var r=sprite._style.scrollRect;
  692. context.save();
  693. context.clipRect(x,y,r.width,r.height);
  694. next._fun.call(next,sprite,context,x-r.x,y-r.y);
  695. context.restore();
  696. }
  697. /*
  698. public function _mask(sprite:Sprite,context:Context,x:Number,y:Number):void {
  699. var next:RenderSprite=this._next;
  700. next._fun.call(next,sprite,context,x,y);
  701. var mask:Sprite=sprite.mask;
  702. if (mask){
  703. context.globalCompositeOperation="destination-in";
  704. if (mask.numChildren > 0 || !mask.graphics._isOnlyOne()){
  705. mask.cacheAs="bitmap";
  706. }
  707. mask.render(context,x-sprite._style.pivotX,y-sprite._style.pivotY);
  708. }
  709. context.globalCompositeOperation="source-over";
  710. }
  711. */
  712. __proto._texture=function(sprite,context,x,y){
  713. var tex=sprite.texture;
  714. if(tex._getSource())
  715. context.drawTexture(tex,x-sprite.pivotX+tex.offsetX,y-sprite.pivotY+tex.offsetY,sprite._width || tex.width,sprite._height || tex.height);
  716. var next=this._next;
  717. if(next!=RenderSprite.NORENDER)
  718. next._fun.call(next,sprite,context,x,y);
  719. }
  720. __proto._graphics=function(sprite,context,x,y){
  721. var style=sprite._style;
  722. var g=sprite._graphics;
  723. g && g._render(sprite,context,x-style.pivotX,y-style.pivotY);
  724. var next=this._next;
  725. if(next!=RenderSprite.NORENDER)
  726. next._fun.call(next,sprite,context,x,y);
  727. }
  728. //TODO:coverage
  729. __proto._image=function(sprite,context,x,y){
  730. var style=sprite._style;
  731. context.drawTexture2(x,y,style.pivotX,style.pivotY,sprite.transform,sprite._graphics._one);
  732. }
  733. //TODO:coverage
  734. __proto._image2=function(sprite,context,x,y){
  735. var style=sprite._style;
  736. context.drawTexture2(x,y,style.pivotX,style.pivotY,sprite.transform,sprite._graphics._one);
  737. }
  738. //TODO:coverage
  739. __proto._alpha=function(sprite,context,x,y){
  740. var style=sprite._style;
  741. var alpha;
  742. if ((alpha=style.alpha)> 0.01 || sprite._needRepaint()){
  743. var temp=context.globalAlpha;
  744. context.globalAlpha *=alpha;
  745. var next=this._next;
  746. next._fun.call(next,sprite,context,x,y);
  747. context.globalAlpha=temp;
  748. }
  749. }
  750. __proto._transform=function(sprite,context,x,y){
  751. var transform=sprite.transform,_next=this._next;
  752. var style=sprite._style;
  753. if (transform && _next !=RenderSprite.NORENDER){
  754. context.save();
  755. context.transform(transform.a,transform.b,transform.c,transform.d,transform.tx+x,transform.ty+y);
  756. _next._fun.call(_next,sprite,context,0,0);
  757. context.restore();
  758. }else {
  759. if(_next!=RenderSprite.NORENDER)
  760. _next._fun.call(_next,sprite,context,x,y);
  761. }
  762. }
  763. __proto._children=function(sprite,context,x,y){
  764. var style=sprite._style;
  765. var childs=sprite._children,n=childs.length,ele;
  766. x=x-sprite.pivotX;
  767. y=y-sprite.pivotY;
  768. var textLastRender=sprite._getBit(/*laya.Const.DRAWCALL_OPTIMIZE*/0x100)&& context.drawCallOptimize(true);
  769. if (style.viewport){
  770. var rect=style.viewport;
  771. var left=rect.x;
  772. var top=rect.y;
  773. var right=rect.right;
  774. var bottom=rect.bottom;
  775. var _x=NaN,_y=NaN;
  776. for (i=0;i < n;++i){
  777. if ((ele=childs [i])._visible && ((_x=ele._x)< right && (_x+ele.width)> left && (_y=ele._y)< bottom && (_y+ele.height)> top)){
  778. ele.render(context,x,y);
  779. }
  780. }
  781. }else {
  782. for (var i=0;i < n;++i)
  783. (ele=(childs [i]))._visible && ele.render(context,x,y);
  784. }
  785. textLastRender && context.drawCallOptimize(false);
  786. }
  787. __proto._canvas=function(sprite,context,x,y){
  788. var _cacheStyle=sprite._cacheStyle;
  789. var _next=this._next;
  790. if (!_cacheStyle.enableCanvasRender){
  791. _next._fun.call(_next,sprite,context,x,y);
  792. return;
  793. }
  794. _cacheStyle.cacheAs==='bitmap' ? (Stat.canvasBitmap++):(Stat.canvasNormal++);
  795. var cacheNeedRebuild=false;
  796. var textNeedRestore=false;
  797. if (_cacheStyle.canvas){
  798. var canv=_cacheStyle.canvas;
  799. var ctx=canv.context;
  800. var charRIs=canv.touches;
  801. if (charRIs){
  802. for (var ci=0;ci < charRIs.length;ci++){
  803. if (charRIs[ci].deleted){
  804. textNeedRestore=true;
  805. break ;
  806. }
  807. }
  808. }
  809. cacheNeedRebuild=canv.isCacheValid && !canv.isCacheValid();
  810. }
  811. if (sprite._needRepaint()|| (!_cacheStyle.canvas)|| textNeedRestore ||cacheNeedRebuild || Laya.stage.isGlobalRepaint()){
  812. if (_cacheStyle.cacheAs==='normal'){
  813. if(context._targets){
  814. _next._fun.call(_next,sprite,context,x,y);
  815. return;
  816. }else{
  817. this._canvas_webgl_normal_repaint(sprite,context);
  818. }
  819. }else{
  820. this._canvas_repaint(sprite,context,x,y);
  821. }
  822. };
  823. var tRec=_cacheStyle.cacheRect;
  824. context.drawCanvas(_cacheStyle.canvas,x+tRec.x,y+tRec.y,tRec.width,tRec.height);
  825. }
  826. __proto._canvas_repaint=function(sprite,context,x,y){
  827. var _cacheStyle=sprite._cacheStyle;
  828. var _next=this._next;
  829. var tx;
  830. var canvas=_cacheStyle.canvas;
  831. var left;
  832. var top;
  833. var tRec;
  834. var tCacheType=_cacheStyle.cacheAs;
  835. var w,h;
  836. var scaleX,scaleY;
  837. var scaleInfo;
  838. scaleInfo=_cacheStyle._calculateCacheRect(sprite,tCacheType,x,y);
  839. scaleX=scaleInfo.x;
  840. scaleY=scaleInfo.y;
  841. tRec=_cacheStyle.cacheRect;
  842. w=tRec.width *scaleX;
  843. h=tRec.height *scaleY;
  844. left=tRec.x;
  845. top=tRec.y;
  846. if (tCacheType==='bitmap' && (w > 2048 || h > 2048)){
  847. console.warn("cache bitmap size larger than 2048,cache ignored");
  848. _cacheStyle.releaseContext();
  849. _next._fun.call(_next,sprite,context,x,y);
  850. return;
  851. }
  852. if (!canvas){
  853. _cacheStyle.createContext();
  854. canvas=_cacheStyle.canvas;
  855. }
  856. tx=canvas.context;
  857. tx.sprite=sprite;
  858. (canvas.width !=w || canvas.height !=h)&& canvas.size(w,h);
  859. if (tCacheType==='bitmap')tx.asBitmap=true;
  860. else if (tCacheType==='normal')tx.asBitmap=false;
  861. tx.clear();
  862. if (scaleX !=1 || scaleY !=1){
  863. var ctx=tx;
  864. ctx.save();
  865. ctx.scale(scaleX,scaleY);
  866. _next._fun.call(_next,sprite,tx,-left,-top);
  867. ctx.restore();
  868. sprite._applyFilters();
  869. }else {
  870. ctx=tx;
  871. _next._fun.call(_next,sprite,tx,-left,-top);
  872. sprite._applyFilters();
  873. }
  874. if (_cacheStyle.staticCache)_cacheStyle.reCache=false;
  875. Stat.canvasReCache++;
  876. }
  877. __proto._canvas_webgl_normal_repaint=function(sprite,context){
  878. var _cacheStyle=sprite._cacheStyle;
  879. var _next=this._next;
  880. var canvas=_cacheStyle.canvas;
  881. var tCacheType=_cacheStyle.cacheAs;
  882. var scaleInfo=_cacheStyle._calculateCacheRect(sprite,tCacheType,0,0);
  883. if (!canvas){
  884. canvas=_cacheStyle.canvas=/*__JS__ */new Laya.WebGLCacheAsNormalCanvas(context,sprite);
  885. };
  886. var tx=canvas.context;
  887. canvas['startRec']();
  888. _next._fun.call(_next,sprite,tx,sprite.pivotX,sprite.pivotY);
  889. sprite._applyFilters();
  890. Stat.canvasReCache++;
  891. canvas['endRec']();
  892. }
  893. //context.drawCanvas(canvas,x ,y ,1,1);// 这种情况下宽高没用
  894. __proto._blend=function(sprite,context,x,y){
  895. var style=sprite._style;
  896. var next=this._next;
  897. if (style.blendMode){
  898. context.save();
  899. context.globalCompositeOperation=style.blendMode;
  900. next._fun.call(next,sprite,context,x,y);
  901. context.restore();
  902. }else {
  903. next._fun.call(next,sprite,context,x,y);
  904. }
  905. }
  906. /**
  907. *mask的渲染。 sprite有mask属性的情况下,来渲染这个sprite
  908. *@param sprite
  909. *@param context
  910. *@param x
  911. *@param y
  912. */
  913. __proto._mask=function(sprite,context,x,y){
  914. var next=this._next;
  915. var mask=sprite.mask;
  916. var submitCMD;
  917. var ctx=context;
  918. if (mask){
  919. ctx.save();
  920. var preBlendMode=ctx.globalCompositeOperation;
  921. var tRect=new Rectangle();
  922. tRect.copyFrom(mask.getBounds());
  923. tRect.width=Math.round(tRect.width);
  924. tRect.height=Math.round(tRect.height);
  925. tRect.x=Math.round(tRect.x);
  926. tRect.y=Math.round(tRect.y);
  927. if (tRect.width > 0 && tRect.height > 0){
  928. var w=tRect.width;
  929. var h=tRect.height;
  930. var tmpRT=WebGLRTMgr.getRT(w,h);
  931. ctx.breakNextMerge();
  932. ctx.pushRT();
  933. ctx.addRenderObject(SubmitCMD.create([ctx,tmpRT,w,h],RenderSprite.tmpTarget,this));
  934. mask.render(ctx,-tRect.x,-tRect.y);
  935. ctx.breakNextMerge();
  936. ctx.popRT();
  937. ctx.save();
  938. ctx.clipRect(x+tRect.x-sprite.getStyle().pivotX,y+tRect.y-sprite.getStyle().pivotY,w,h);
  939. next._fun.call(next,sprite,ctx,x,y);
  940. ctx.restore();
  941. preBlendMode=ctx.globalCompositeOperation;
  942. ctx.addRenderObject(SubmitCMD.create(["mask"],RenderSprite.setBlendMode,this));
  943. var shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  944. var uv=Texture.INV_UV;
  945. ctx.drawTarget(tmpRT,x+tRect.x-sprite.getStyle().pivotX ,y+tRect.y-sprite.getStyle().pivotY,w,h,Matrix.TEMP.identity(),shaderValue,uv,6);
  946. ctx.addRenderObject(SubmitCMD.create([tmpRT],RenderSprite.recycleTarget,this));
  947. ctx.addRenderObject(SubmitCMD.create([preBlendMode],RenderSprite.setBlendMode,this));
  948. }
  949. ctx.restore();
  950. }else {
  951. next._fun.call(next,sprite,context,x,y);
  952. }
  953. }
  954. RenderSprite.__init__=function(){
  955. LayaGLQuickRunner.__init__();
  956. var i=0,len=0;
  957. var initRender;
  958. initRender=new RenderSprite(0x11111,null);
  959. len=RenderSprite.renders.length=/*laya.display.SpriteConst.CHILDS*/0x2000 *2;
  960. for (i=0;i < len;i++)
  961. RenderSprite.renders[i]=initRender;
  962. RenderSprite.renders[0]=new RenderSprite(0,null);
  963. function _initSame (value,o){
  964. var n=0;
  965. for (var i=0;i < value.length;i++){
  966. n |=value[i];
  967. RenderSprite.renders[n]=o;
  968. }
  969. }
  970. }
  971. RenderSprite._initRenderFun=function(sprite,context,x,y){
  972. var type=sprite._renderType;
  973. var r=RenderSprite.renders[type]=RenderSprite._getTypeRender(type);
  974. r._fun(sprite,context,x,y);
  975. }
  976. RenderSprite._getTypeRender=function(type){
  977. if (LayaGLQuickRunner.map[type])return new RenderSprite(type,null);
  978. var rst=null;
  979. var tType=/*laya.display.SpriteConst.CHILDS*/0x2000;
  980. while (tType > 0){
  981. if (tType & type)
  982. rst=new RenderSprite(tType,rst);
  983. tType=tType >> 1;
  984. }
  985. return rst;
  986. }
  987. RenderSprite.tmpTarget=function(ctx,rt,w,h){
  988. rt.start();
  989. rt.clear(0,0,0,0);
  990. }
  991. RenderSprite.recycleTarget=function(rt){
  992. WebGLRTMgr.releaseRT(rt);
  993. }
  994. RenderSprite.setBlendMode=function(blendMode){
  995. var gl=WebGL.mainContext;
  996. BlendMode.targetFns[BlendMode.TOINT[blendMode]](gl);
  997. }
  998. RenderSprite.INIT=0x11111;
  999. RenderSprite.renders=[];
  1000. RenderSprite.NORENDER=new RenderSprite(0,null);
  1001. __static(RenderSprite,
  1002. ['tempUV',function(){return this.tempUV=new Array(8);}
  1003. ]);
  1004. return RenderSprite;
  1005. })()
  1006. //class laya.webgl.submit.SubmitCMD
  1007. var SubmitCMD=(function(){
  1008. function SubmitCMD(){
  1009. this.fun=null;
  1010. this._this=null;
  1011. this.args=null;
  1012. this._ref=1;
  1013. this._key=new SubmitKey();
  1014. }
  1015. __class(SubmitCMD,'laya.webgl.submit.SubmitCMD');
  1016. var __proto=SubmitCMD.prototype;
  1017. Laya.imps(__proto,{"laya.webgl.submit.ISubmit":true})
  1018. __proto.renderSubmit=function(){
  1019. this.fun.apply(this._this,this.args);
  1020. return 1;
  1021. }
  1022. //TODO:coverage
  1023. __proto.getRenderType=function(){
  1024. return 0;
  1025. }
  1026. //TODO:coverage
  1027. __proto.reUse=function(context,pos){
  1028. this._ref++;
  1029. return pos;
  1030. }
  1031. __proto.releaseRender=function(){
  1032. if((--this._ref)<1){
  1033. var pool=SubmitCMD.POOL;
  1034. pool[pool._length++]=this;
  1035. }
  1036. }
  1037. //TODO:coverage
  1038. __proto.clone=function(context,mesh,pos){
  1039. return null;
  1040. }
  1041. SubmitCMD.create=function(args,fun,thisobj){
  1042. var o=SubmitCMD.POOL._length?SubmitCMD.POOL[--SubmitCMD.POOL._length]:new SubmitCMD();
  1043. o.fun=fun;
  1044. o.args=args;
  1045. o._this=thisobj;
  1046. o._ref=1;
  1047. o._key.clear();
  1048. return o;
  1049. }
  1050. SubmitCMD.POOL=[];
  1051. SubmitCMD.__init$=function(){
  1052. {SubmitCMD.POOL._length=0 };
  1053. }
  1054. return SubmitCMD;
  1055. })()
  1056. /**
  1057. *对象 cacheas normal的时候,本质上只是想把submit缓存起来,以后直接执行
  1058. *为了避免各种各样的麻烦,这里采用复制相应部分的submit的方法。执行环境还是在原来的context中
  1059. *否则包括clip等都非常难以处理
  1060. */
  1061. //class laya.webgl.canvas.WebGLCacheAsNormalCanvas
  1062. var WebGLCacheAsNormalCanvas=(function(){
  1063. function WebGLCacheAsNormalCanvas(ctx,sp){
  1064. this.submitStartPos=0;
  1065. // 对应的context的submit的开始的地方
  1066. this.submitEndPos=0;
  1067. this.context=null;
  1068. this.touches=[];
  1069. //记录的文字信息。cacheas normal的话,文字要能正确touch
  1070. this.submits=[];
  1071. // 从context中剪切的submit
  1072. this.sprite=null;
  1073. // submit需要关联稳定独立的mesh。所以这里要创建自己的mesh对象
  1074. this._mesh=null;
  1075. //用Mesh2D代替_vb,_ib. 当前使用的mesh
  1076. this._pathMesh=null;
  1077. //矢量专用mesh。
  1078. this._triangleMesh=null;
  1079. //drawTriangles专用mesh。由于ib不固定,所以不能与_mesh通用
  1080. this.meshlist=[];
  1081. // 原始context的原始值
  1082. this._oldMesh=null;
  1083. this._oldPathMesh=null;
  1084. this._oldTriMesh=null;
  1085. this._oldMeshList=null;
  1086. //private var oldMatrix:Matrix=null;//本地画的时候完全不应用矩阵,所以需要先保存老的,以便恢复 这样会丢失缩放信息,导致文字模糊,所以不用这种方式了
  1087. this.oldTx=0;
  1088. this.oldTy=0;
  1089. this.cachedClipInfo=new Matrix();
  1090. this.invMat=new Matrix();
  1091. this.context=ctx;
  1092. this.sprite=sp;
  1093. ctx._globalClipMatrix.copyTo(this.cachedClipInfo);
  1094. }
  1095. __class(WebGLCacheAsNormalCanvas,'laya.webgl.canvas.WebGLCacheAsNormalCanvas');
  1096. var __proto=WebGLCacheAsNormalCanvas.prototype;
  1097. __proto.startRec=function(){
  1098. if (this.context._charSubmitCache._enbale){
  1099. this.context._charSubmitCache.enable(false,this.context);
  1100. this.context._charSubmitCache.enable(true,this.context);
  1101. }
  1102. this.context._incache=true;
  1103. this.touches.length=0;
  1104. (this.context).touches=this.touches;
  1105. this.context._globalClipMatrix.copyTo(this.cachedClipInfo);
  1106. this.submits.length=0;
  1107. this.submitStartPos=this.context._submits._length;
  1108. for (var i=0,sz=this.meshlist.length;i < sz;i++){
  1109. var curm=this.meshlist[i];
  1110. curm.canReuse?(curm.releaseMesh()):(curm.destroy());
  1111. }
  1112. this.meshlist.length=0;
  1113. this._mesh=MeshQuadTexture.getAMesh(false);
  1114. this._pathMesh=MeshVG.getAMesh(false);
  1115. this._triangleMesh=MeshTexture.getAMesh(false);
  1116. this.meshlist.push(this._mesh);
  1117. this.meshlist.push(this._pathMesh);
  1118. this.meshlist.push(this._triangleMesh);
  1119. this.context._curSubmit=Submit.RENDERBASE;
  1120. this._oldMesh=this.context._mesh;
  1121. this._oldPathMesh=this.context._pathMesh;
  1122. this._oldTriMesh=this.context._triangleMesh;
  1123. this._oldMeshList=this.context.meshlist;
  1124. this.context._mesh=this._mesh;
  1125. this.context._pathMesh=this._pathMesh;
  1126. this.context._triangleMesh=this._triangleMesh;
  1127. this.context.meshlist=this.meshlist;
  1128. this.oldTx=this.context._curMat.tx;
  1129. this.oldTy=this.context._curMat.ty;
  1130. this.context._curMat.tx=0;
  1131. this.context._curMat.ty=0;
  1132. this.context._curMat.copyTo(this.invMat);
  1133. this.invMat.invert();
  1134. }
  1135. //context._curMat=matI;
  1136. __proto.endRec=function(){
  1137. if (this.context._charSubmitCache._enbale){
  1138. this.context._charSubmitCache.enable(false,this.context);
  1139. this.context._charSubmitCache.enable(true,this.context);
  1140. };
  1141. var parsubmits=this.context._submits;
  1142. this.submitEndPos=parsubmits._length;
  1143. var num=this.submitEndPos-this.submitStartPos;
  1144. for (var i=0;i < num;i++){
  1145. this.submits.push(parsubmits[this.submitStartPos+i]);
  1146. }
  1147. parsubmits._length-=num;
  1148. this.context._mesh=this._oldMesh;
  1149. this.context._pathMesh=this._oldPathMesh;
  1150. this.context._triangleMesh=this._oldTriMesh;
  1151. this.context.meshlist=this._oldMeshList;
  1152. this.context._curSubmit=Submit.RENDERBASE;
  1153. this.context._curMat.tx=this.oldTx;
  1154. this.context._curMat.ty=this.oldTy;
  1155. (this.context).touches=null;
  1156. this.context._incache=false;
  1157. }
  1158. /**
  1159. *当前缓存是否还有效。例如clip变了就失效了,因为clip太难自动处理
  1160. *@return
  1161. */
  1162. __proto.isCacheValid=function(){
  1163. var curclip=this.context._globalClipMatrix;
  1164. if (curclip.a !=this.cachedClipInfo.a || curclip.b !=this.cachedClipInfo.b || curclip.c !=this.cachedClipInfo.c
  1165. || curclip.d !=this.cachedClipInfo.d || curclip.tx !=this.cachedClipInfo.tx || curclip.ty !=this.cachedClipInfo.ty)
  1166. return false;
  1167. return true;
  1168. }
  1169. __proto.flushsubmit=function(){
  1170. var curSubmit=Submit.RENDERBASE;
  1171. this.submits.forEach(function(subm){
  1172. if (subm==Submit.RENDERBASE)return;
  1173. Submit.preRender=curSubmit;
  1174. curSubmit=subm;
  1175. subm.renderSubmit();
  1176. });
  1177. }
  1178. __proto.releaseMem=function(){}
  1179. __static(WebGLCacheAsNormalCanvas,
  1180. ['matI',function(){return this.matI=new Matrix();}
  1181. ]);
  1182. return WebGLCacheAsNormalCanvas;
  1183. })()
  1184. /**
  1185. *@private
  1186. *普通命令执行器
  1187. */
  1188. //class laya.layagl.LayaGLRunner
  1189. var LayaGLRunner=(function(){
  1190. function LayaGLRunner(){}
  1191. __class(LayaGLRunner,'laya.layagl.LayaGLRunner');
  1192. LayaGLRunner.uploadShaderUniforms=function(layaGL,commandEncoder,shaderData,uploadUnTexture){
  1193. var data=shaderData._data;
  1194. var shaderUniform=commandEncoder.getArrayData();
  1195. var shaderCall=0;
  1196. for (var i=0,n=shaderUniform.length;i < n;i++){
  1197. var one=shaderUniform[i];
  1198. if (uploadUnTexture || one.textureID!==-1){
  1199. var value=data[one.dataOffset];
  1200. if (value !=null)
  1201. shaderCall+=one.fun.call(one.caller,one,value);
  1202. }
  1203. }
  1204. return shaderCall;
  1205. }
  1206. LayaGLRunner.uploadCustomUniform=function(layaGL,custom,index,data){
  1207. var shaderCall=0;
  1208. var one=custom[index];
  1209. if (one && data !=null)
  1210. shaderCall+=one.fun.call(one.caller,one,data);
  1211. return shaderCall;
  1212. }
  1213. LayaGLRunner.uploadShaderUniformsForNative=function(layaGL,commandEncoder,shaderData){
  1214. var nType=/*laya.layagl.LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID*/0;
  1215. if (shaderData._runtimeCopyValues.length > 0){
  1216. nType=/*laya.layagl.LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA*/1;
  1217. };
  1218. var data=shaderData._data;
  1219. return layaGL.uploadShaderUniforms(commandEncoder,data,nType);
  1220. }
  1221. return LayaGLRunner;
  1222. })()
  1223. /**
  1224. *绘制单条曲线
  1225. */
  1226. //class laya.display.cmd.DrawLineCmd
  1227. var DrawLineCmd=(function(){
  1228. function DrawLineCmd(){
  1229. /**
  1230. *X轴开始位置。
  1231. */
  1232. //this.fromX=NaN;
  1233. /**
  1234. *Y轴开始位置。
  1235. */
  1236. //this.fromY=NaN;
  1237. /**
  1238. *X轴结束位置。
  1239. */
  1240. //this.toX=NaN;
  1241. /**
  1242. *Y轴结束位置。
  1243. */
  1244. //this.toY=NaN;
  1245. /**
  1246. *颜色。
  1247. */
  1248. //this.lineColor=null;
  1249. /**
  1250. *(可选)线条宽度。
  1251. */
  1252. //this.lineWidth=NaN;
  1253. /**@private */
  1254. //this.vid=0;
  1255. }
  1256. __class(DrawLineCmd,'laya.display.cmd.DrawLineCmd');
  1257. var __proto=DrawLineCmd.prototype;
  1258. /**
  1259. *回收到对象池
  1260. */
  1261. __proto.recover=function(){
  1262. Pool.recover("DrawLineCmd",this);
  1263. }
  1264. /**@private */
  1265. __proto.run=function(context,gx,gy){
  1266. context._drawLine(gx,gy,this.fromX,this.fromY,this.toX,this.toY,this.lineColor,this.lineWidth,this.vid);
  1267. }
  1268. /**@private */
  1269. __getset(0,__proto,'cmdID',function(){
  1270. return "DrawLine";
  1271. });
  1272. DrawLineCmd.create=function(fromX,fromY,toX,toY,lineColor,lineWidth,vid){
  1273. var cmd=Pool.getItemByClass("DrawLineCmd",DrawLineCmd);
  1274. cmd.fromX=fromX;
  1275. cmd.fromY=fromY;
  1276. cmd.toX=toX;
  1277. cmd.toY=toY;
  1278. cmd.lineColor=lineColor;
  1279. cmd.lineWidth=lineWidth;
  1280. cmd.vid=vid;
  1281. return cmd;
  1282. }
  1283. DrawLineCmd.ID="DrawLine";
  1284. return DrawLineCmd;
  1285. })()
  1286. /**
  1287. *...
  1288. *@author ...
  1289. */
  1290. //class laya.webgl.BufferStateBase
  1291. var BufferStateBase=(function(){
  1292. function BufferStateBase(){
  1293. /**@private [只读]*/
  1294. this._nativeVertexArrayObject=null;
  1295. /**@private [只读]*/
  1296. this._bindedIndexBuffer=null;
  1297. this._nativeVertexArrayObject=LayaGL.instance.createVertexArray();
  1298. }
  1299. __class(BufferStateBase,'laya.webgl.BufferStateBase');
  1300. var __proto=BufferStateBase.prototype;
  1301. /**
  1302. *@private
  1303. */
  1304. __proto.bind=function(){
  1305. if (BufferStateBase._curBindedBufferState!==this){
  1306. LayaGL.instance.bindVertexArray(this._nativeVertexArrayObject);
  1307. BufferStateBase._curBindedBufferState=this;
  1308. }
  1309. }
  1310. /**
  1311. *@private
  1312. */
  1313. __proto.unBind=function(){
  1314. if (BufferStateBase._curBindedBufferState===this){
  1315. LayaGL.instance.bindVertexArray(null);
  1316. BufferStateBase._curBindedBufferState=null;
  1317. }else {
  1318. throw "BufferState: must call bind() function first.";
  1319. }
  1320. }
  1321. /**
  1322. *@private
  1323. */
  1324. __proto.bindForNative=function(){
  1325. LayaGL.instance.bindVertexArray(this._nativeVertexArrayObject);
  1326. BufferStateBase._curBindedBufferState=this;
  1327. }
  1328. /**
  1329. *@private
  1330. */
  1331. __proto.unBindForNative=function(){
  1332. LayaGL.instance.bindVertexArray(null);
  1333. BufferStateBase._curBindedBufferState=null;
  1334. }
  1335. /**
  1336. *@private
  1337. */
  1338. __proto.destroy=function(){
  1339. LayaGL.instance.deleteVertexArray(this._nativeVertexArrayObject);
  1340. }
  1341. BufferStateBase._curBindedBufferState=null;
  1342. return BufferStateBase;
  1343. })()
  1344. /**
  1345. *<code>EventDispatcher</code> 类是可调度事件的所有类的基类。
  1346. */
  1347. //class laya.events.EventDispatcher
  1348. var EventDispatcher=(function(){
  1349. var EventHandler;
  1350. function EventDispatcher(){
  1351. /**@private */
  1352. this._$0__events=null;
  1353. }
  1354. __class(EventDispatcher,'laya.events.EventDispatcher');
  1355. var __proto=EventDispatcher.prototype;
  1356. /**
  1357. *检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
  1358. *@param type 事件的类型。
  1359. *@return 如果指定类型的侦听器已注册,则值为 true;否则,值为 false。
  1360. */
  1361. __proto.hasListener=function(type){
  1362. var listener=this._$0__events && this._$0__events[type];
  1363. return !!listener;
  1364. }
  1365. /**
  1366. *派发事件。
  1367. *@param type 事件类型。
  1368. *@param data (可选)回调数据。<b>注意:</b>如果是需要传递多个参数 p1,p2,p3,...可以使用数组结构如:[p1,p2,p3,...] ;如果需要回调单个参数 p ,且 p 是一个数组,则需要使用结构如:[p],其他的单个参数 p ,可以直接传入参数 p。
  1369. *@return 此事件类型是否有侦听者,如果有侦听者则值为 true,否则值为 false。
  1370. */
  1371. __proto.event=function(type,data){
  1372. if (!this._$0__events || !this._$0__events[type])return false;
  1373. var listeners=this._$0__events[type];
  1374. if (listeners.run){
  1375. if (listeners.once)delete this._$0__events[type];
  1376. data !=null ? listeners.runWith(data):listeners.run();
  1377. }else {
  1378. for (var i=0,n=listeners.length;i < n;i++){
  1379. var listener=listeners[i];
  1380. if (listener){
  1381. (data !=null)? listener.runWith(data):listener.run();
  1382. }
  1383. if (!listener || listener.once){
  1384. listeners.splice(i,1);
  1385. i--;
  1386. n--;
  1387. }
  1388. }
  1389. if (listeners.length===0 && this._$0__events)delete this._$0__events[type];
  1390. }
  1391. return true;
  1392. }
  1393. /**
  1394. *使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知。
  1395. *@param type 事件的类型。
  1396. *@param caller 事件侦听函数的执行域。
  1397. *@param listener 事件侦听函数。
  1398. *@param args (可选)事件侦听函数的回调参数。
  1399. *@return 此 EventDispatcher 对象。
  1400. */
  1401. __proto.on=function(type,caller,listener,args){
  1402. return this._createListener(type,caller,listener,args,false);
  1403. }
  1404. /**
  1405. *使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知,此侦听事件响应一次后自动移除。
  1406. *@param type 事件的类型。
  1407. *@param caller 事件侦听函数的执行域。
  1408. *@param listener 事件侦听函数。
  1409. *@param args (可选)事件侦听函数的回调参数。
  1410. *@return 此 EventDispatcher 对象。
  1411. */
  1412. __proto.once=function(type,caller,listener,args){
  1413. return this._createListener(type,caller,listener,args,true);
  1414. }
  1415. /**@private */
  1416. __proto._createListener=function(type,caller,listener,args,once,offBefore){
  1417. (offBefore===void 0)&& (offBefore=true);
  1418. offBefore && this.off(type,caller,listener,once);
  1419. var handler=EventHandler.create(caller || this,listener,args,once);
  1420. this._$0__events || (this._$0__events={});
  1421. var events=this._$0__events;
  1422. if (!events[type])events[type]=handler;
  1423. else {
  1424. if (!events[type].run)events[type].push(handler);
  1425. else events[type]=[events[type],handler];
  1426. }
  1427. return this;
  1428. }
  1429. /**
  1430. *从 EventDispatcher 对象中删除侦听器。
  1431. *@param type 事件的类型。
  1432. *@param caller 事件侦听函数的执行域。
  1433. *@param listener 事件侦听函数。
  1434. *@param onceOnly (可选)如果值为 true ,则只移除通过 once 方法添加的侦听器。
  1435. *@return 此 EventDispatcher 对象。
  1436. */
  1437. __proto.off=function(type,caller,listener,onceOnly){
  1438. (onceOnly===void 0)&& (onceOnly=false);
  1439. if (!this._$0__events || !this._$0__events[type])return this;
  1440. var listeners=this._$0__events[type];
  1441. if (listeners !=null){
  1442. if (listeners.run){
  1443. if ((!caller || listeners.caller===caller)&& (listener==null || listeners.method===listener)&& (!onceOnly || listeners.once)){
  1444. delete this._$0__events[type];
  1445. listeners.recover();
  1446. }
  1447. }else {
  1448. var count=0;
  1449. for (var i=0,n=listeners.length;i < n;i++){
  1450. var item=listeners[i];
  1451. if (!item){
  1452. count++;
  1453. continue ;
  1454. }
  1455. if (item && (!caller || item.caller===caller)&& (listener==null || item.method===listener)&& (!onceOnly || item.once)){
  1456. count++;
  1457. listeners[i]=null;
  1458. item.recover();
  1459. }
  1460. }
  1461. if (count===n)delete this._$0__events[type];
  1462. }
  1463. }
  1464. return this;
  1465. }
  1466. /**
  1467. *从 EventDispatcher 对象中删除指定事件类型的所有侦听器。
  1468. *@param type (可选)事件类型,如果值为 null,则移除本对象所有类型的侦听器。
  1469. *@return 此 EventDispatcher 对象。
  1470. */
  1471. __proto.offAll=function(type){
  1472. var events=this._$0__events;
  1473. if (!events)return this;
  1474. if (type){
  1475. this._recoverHandlers(events[type]);
  1476. delete events[type];
  1477. }else {
  1478. for (var name in events){
  1479. this._recoverHandlers(events[name]);
  1480. }
  1481. this._$0__events=null;
  1482. }
  1483. return this;
  1484. }
  1485. /**
  1486. *移除caller为target的所有事件监听
  1487. *@param caller caller对象
  1488. */
  1489. __proto.offAllCaller=function(caller){
  1490. if (caller && this._$0__events){
  1491. for (var name in this._$0__events){
  1492. this.off(name,caller,null);
  1493. }
  1494. }
  1495. return this;
  1496. }
  1497. __proto._recoverHandlers=function(arr){
  1498. if (!arr)return;
  1499. if (arr.run){
  1500. arr.recover();
  1501. }else {
  1502. for (var i=arr.length-1;i >-1;i--){
  1503. if (arr[i]){
  1504. arr[i].recover();
  1505. arr[i]=null;
  1506. }
  1507. }
  1508. }
  1509. }
  1510. /**
  1511. *检测指定事件类型是否是鼠标事件。
  1512. *@param type 事件的类型。
  1513. *@return 如果是鼠标事件,则值为 true;否则,值为 false。
  1514. */
  1515. __proto.isMouseEvent=function(type){
  1516. return EventDispatcher.MOUSE_EVENTS[type] || false;
  1517. }
  1518. EventDispatcher.MOUSE_EVENTS={"rightmousedown":true,"rightmouseup":true,"rightclick":true,"mousedown":true,"mouseup":true,"mousemove":true,"mouseover":true,"mouseout":true,"click":true,"doubleclick":true};
  1519. EventDispatcher.__init$=function(){
  1520. Object.defineProperty(laya.events.EventDispatcher.prototype,"_events",{enumerable:false,writable:true});
  1521. /**@private */
  1522. //class EventHandler extends laya.utils.Handler
  1523. EventHandler=(function(_super){
  1524. function EventHandler(caller,method,args,once){
  1525. EventHandler.__super.call(this,caller,method,args,once);
  1526. }
  1527. __class(EventHandler,'',_super);
  1528. var __proto=EventHandler.prototype;
  1529. __proto.recover=function(){
  1530. if (this._id > 0){
  1531. this._id=0;
  1532. EventHandler._pool.push(this.clear());
  1533. }
  1534. }
  1535. EventHandler.create=function(caller,method,args,once){
  1536. (once===void 0)&& (once=true);
  1537. if (EventHandler._pool.length)return EventHandler._pool.pop().setTo(caller,method,args,once);
  1538. return new EventHandler(caller,method,args,once);
  1539. }
  1540. EventHandler._pool=[];
  1541. return EventHandler;
  1542. })(Handler)
  1543. }
  1544. return EventDispatcher;
  1545. })()
  1546. /**
  1547. *<p><code>Handler</code> 是事件处理器类。</p>
  1548. *<p>推荐使用 Handler.create()方法从对象池创建,减少对象创建消耗。创建的 Handler 对象不再使用后,可以使用 Handler.recover()将其回收到对象池,回收后不要再使用此对象,否则会导致不可预料的错误。</p>
  1549. *<p><b>注意:</b>由于鼠标事件也用本对象池,不正确的回收及调用,可能会影响鼠标事件的执行。</p>
  1550. */
  1551. //class laya.utils.Handler
  1552. var Handler=(function(){
  1553. function Handler(caller,method,args,once){
  1554. /**执行域(this)。*/
  1555. //this.caller=null;
  1556. /**处理方法。*/
  1557. //this.method=null;
  1558. /**参数。*/
  1559. //this.args=null;
  1560. /**表示是否只执行一次。如果为true,回调后执行recover()进行回收,回收后会被再利用,默认为false 。*/
  1561. this.once=false;
  1562. /**@private */
  1563. this._id=0;
  1564. (once===void 0)&& (once=false);
  1565. this.setTo(caller,method,args,once);
  1566. }
  1567. __class(Handler,'laya.utils.Handler');
  1568. var __proto=Handler.prototype;
  1569. /**
  1570. *设置此对象的指定属性值。
  1571. *@param caller 执行域(this)。
  1572. *@param method 回调方法。
  1573. *@param args 携带的参数。
  1574. *@param once 是否只执行一次,如果为true,执行后执行recover()进行回收。
  1575. *@return 返回 handler 本身。
  1576. */
  1577. __proto.setTo=function(caller,method,args,once){
  1578. this._id=Handler._gid++;
  1579. this.caller=caller;
  1580. this.method=method;
  1581. this.args=args;
  1582. this.once=once;
  1583. return this;
  1584. }
  1585. /**
  1586. *执行处理器。
  1587. */
  1588. __proto.run=function(){
  1589. if (this.method==null)return null;
  1590. var id=this._id;
  1591. var result=this.method.apply(this.caller,this.args);
  1592. this._id===id && this.once && this.recover();
  1593. return result;
  1594. }
  1595. /**
  1596. *执行处理器,并携带额外数据。
  1597. *@param data 附加的回调数据,可以是单数据或者Array(作为多参)。
  1598. */
  1599. __proto.runWith=function(data){
  1600. if (this.method==null)return null;
  1601. var id=this._id;
  1602. if (data==null)
  1603. var result=this.method.apply(this.caller,this.args);
  1604. else if (!this.args && !data.unshift)result=this.method.call(this.caller,data);
  1605. else if (this.args)result=this.method.apply(this.caller,this.args.concat(data));
  1606. else result=this.method.apply(this.caller,data);
  1607. this._id===id && this.once && this.recover();
  1608. return result;
  1609. }
  1610. /**
  1611. *清理对象引用。
  1612. */
  1613. __proto.clear=function(){
  1614. this.caller=null;
  1615. this.method=null;
  1616. this.args=null;
  1617. return this;
  1618. }
  1619. /**
  1620. *清理并回收到 Handler 对象池内。
  1621. */
  1622. __proto.recover=function(){
  1623. if (this._id > 0){
  1624. this._id=0;
  1625. Handler._pool.push(this.clear());
  1626. }
  1627. }
  1628. Handler.create=function(caller,method,args,once){
  1629. (once===void 0)&& (once=true);
  1630. if (Handler._pool.length)return Handler._pool.pop().setTo(caller,method,args,once);
  1631. return new Handler(caller,method,args,once);
  1632. }
  1633. Handler._pool=[];
  1634. Handler._gid=1;
  1635. return Handler;
  1636. })()
  1637. /**
  1638. *<p> <code>LocalStorage</code> 类用于没有时间限制的数据存储。</p>
  1639. */
  1640. //class laya.net.LocalStorage
  1641. var LocalStorage=(function(){
  1642. var Storage;
  1643. function LocalStorage(){}
  1644. __class(LocalStorage,'laya.net.LocalStorage');
  1645. LocalStorage.__init__=function(){
  1646. if (!LocalStorage._baseClass){
  1647. LocalStorage._baseClass=Storage;
  1648. Storage.init();
  1649. }
  1650. LocalStorage.items=LocalStorage._baseClass.items;
  1651. LocalStorage.support=LocalStorage._baseClass.support;
  1652. return LocalStorage.support;
  1653. }
  1654. LocalStorage.setItem=function(key,value){
  1655. LocalStorage._baseClass.setItem(key,value);
  1656. }
  1657. LocalStorage.getItem=function(key){
  1658. return LocalStorage._baseClass.getItem(key);
  1659. }
  1660. LocalStorage.setJSON=function(key,value){
  1661. LocalStorage._baseClass.setJSON(key,value);
  1662. }
  1663. LocalStorage.getJSON=function(key){
  1664. return LocalStorage._baseClass.getJSON(key);
  1665. }
  1666. LocalStorage.removeItem=function(key){
  1667. LocalStorage._baseClass.removeItem(key);
  1668. }
  1669. LocalStorage.clear=function(){
  1670. LocalStorage._baseClass.clear();
  1671. }
  1672. LocalStorage._baseClass=null;
  1673. LocalStorage.items=null;
  1674. LocalStorage.support=false;
  1675. LocalStorage.__init$=function(){
  1676. //class Storage
  1677. Storage=(function(){
  1678. function Storage(){}
  1679. __class(Storage,'');
  1680. Storage.init=function(){
  1681. /*__JS__ */try{Storage.support=true;Storage.items=window.localStorage;Storage.setItem('laya','1');Storage.removeItem('laya');}catch(e){Storage.support=false;}if(!Storage.support)console.log('LocalStorage is not supprot or browser is private mode.');
  1682. }
  1683. Storage.setItem=function(key,value){
  1684. try {
  1685. Storage.support && Storage.items.setItem(key,value);
  1686. }catch (e){
  1687. console.warn("set localStorage failed",e);
  1688. }
  1689. }
  1690. Storage.getItem=function(key){
  1691. return Storage.support ? Storage.items.getItem(key):null;
  1692. }
  1693. Storage.setJSON=function(key,value){
  1694. try {
  1695. Storage.support && Storage.items.setItem(key,JSON.stringify(value));
  1696. }catch (e){
  1697. console.warn("set localStorage failed",e);
  1698. }
  1699. }
  1700. Storage.getJSON=function(key){
  1701. return JSON.parse(Storage.support ? Storage.items.getItem(key):null);
  1702. }
  1703. Storage.removeItem=function(key){
  1704. Storage.support && Storage.items.removeItem(key);
  1705. }
  1706. Storage.clear=function(){
  1707. Storage.support && Storage.items.clear();
  1708. }
  1709. Storage.items=null;
  1710. Storage.support=false;
  1711. return Storage;
  1712. })()
  1713. }
  1714. return LocalStorage;
  1715. })()
  1716. /**
  1717. *存储命令,和restore配套使用
  1718. */
  1719. //class laya.display.cmd.SaveCmd
  1720. var SaveCmd=(function(){
  1721. function SaveCmd(){}
  1722. __class(SaveCmd,'laya.display.cmd.SaveCmd');
  1723. var __proto=SaveCmd.prototype;
  1724. /**
  1725. *回收到对象池
  1726. */
  1727. __proto.recover=function(){
  1728. Pool.recover("SaveCmd",this);
  1729. }
  1730. /**@private */
  1731. __proto.run=function(context,gx,gy){
  1732. context.save();
  1733. }
  1734. /**@private */
  1735. __getset(0,__proto,'cmdID',function(){
  1736. return "Save";
  1737. });
  1738. SaveCmd.create=function(){
  1739. var cmd=Pool.getItemByClass("SaveCmd",SaveCmd);
  1740. return cmd;
  1741. }
  1742. SaveCmd.ID="Save";
  1743. return SaveCmd;
  1744. })()
  1745. /**
  1746. *<code>Component</code> 类用于创建组件的基类。
  1747. */
  1748. //class laya.components.Component
  1749. var Component=(function(){
  1750. function Component(){
  1751. /**@private [实现IListPool接口]*/
  1752. //this._destroyed=false;
  1753. /**@private [实现IListPool接口]*/
  1754. //this._indexInList=0;
  1755. /**@private */
  1756. //this._id=0;
  1757. /**@private */
  1758. //this._enabled=false;
  1759. /**@private */
  1760. //this._awaked=false;
  1761. /**
  1762. *[只读]获取所属Node节点。
  1763. *@readonly
  1764. */
  1765. //this.owner=null;
  1766. this._id=Utils.getGID();
  1767. this._resetComp();
  1768. }
  1769. __class(Component,'laya.components.Component');
  1770. var __proto=Component.prototype;
  1771. Laya.imps(__proto,{"laya.resource.ISingletonElement":true,"laya.resource.IDestroy":true})
  1772. /**
  1773. *@private
  1774. */
  1775. __proto._isScript=function(){
  1776. return false;
  1777. }
  1778. /**
  1779. *@private
  1780. */
  1781. __proto._resetComp=function(){
  1782. this._indexInList=-1;
  1783. this._enabled=true;
  1784. this._awaked=false;
  1785. this.owner=null;
  1786. }
  1787. /**
  1788. *[实现IListPool接口]
  1789. *@private
  1790. */
  1791. __proto._getIndexInList=function(){
  1792. return this._indexInList;
  1793. }
  1794. /**
  1795. *[实现IListPool接口]
  1796. *@private
  1797. */
  1798. __proto._setIndexInList=function(index){
  1799. this._indexInList=index;
  1800. }
  1801. /**
  1802. *被添加到节点后调用,可根据需要重写此方法
  1803. *@private
  1804. */
  1805. __proto._onAdded=function(){}
  1806. /**
  1807. *被激活后调用,可根据需要重写此方法
  1808. *@private
  1809. */
  1810. __proto._onAwake=function(){}
  1811. /**
  1812. *被激活后调用,可根据需要重写此方法
  1813. *@private
  1814. */
  1815. __proto._onEnable=function(){}
  1816. /**
  1817. *被禁用时调用,可根据需要重写此方法
  1818. *@private
  1819. */
  1820. __proto._onDisable=function(){}
  1821. /**
  1822. *被添加到Scene后调用,无论Scene是否在舞台上,可根据需要重写此方法
  1823. *@private
  1824. */
  1825. __proto._onEnableInScene=function(){}
  1826. /**
  1827. *从Scene移除后调用,无论Scene是否在舞台上,可根据需要重写此方法
  1828. *@private
  1829. */
  1830. __proto._onDisableInScene=function(){}
  1831. /**
  1832. *被销毁时调用,可根据需要重写此方法
  1833. *@private
  1834. */
  1835. __proto._onDestroy=function(){}
  1836. /**
  1837. *重置组件参数到默认值,如果实现了这个函数,则组件会被重置并且自动回收到对象池,方便下次复用
  1838. *如果没有重置,则不进行回收复用
  1839. *此方法为虚方法,使用时重写覆盖即可
  1840. */
  1841. __proto.onReset=function(){}
  1842. /**
  1843. *@private
  1844. */
  1845. __proto._parse=function(data){}
  1846. /**
  1847. *@private
  1848. */
  1849. __proto._cloneTo=function(dest){}
  1850. /**
  1851. *@private
  1852. */
  1853. __proto._setActive=function(value){
  1854. if (value){
  1855. if (!this._awaked){
  1856. this._awaked=true;
  1857. this._onAwake();
  1858. }
  1859. this._enabled && this._onEnable();
  1860. }else {
  1861. this._enabled && this._onDisable();
  1862. }
  1863. }
  1864. /**
  1865. *@private
  1866. */
  1867. __proto._setActiveInScene=function(value){
  1868. if (value)this._onEnableInScene();
  1869. else this._onDisableInScene();
  1870. }
  1871. /**
  1872. *销毁组件
  1873. */
  1874. __proto.destroy=function(){
  1875. if (this.owner)this.owner._destroyComponent(this);
  1876. }
  1877. /**
  1878. *@private
  1879. */
  1880. __proto._destroy=function(){
  1881. if (this.owner.activeInHierarchy && this._enabled){
  1882. this._setActive(false);
  1883. (this._isScript())&& ((this).onDisable());
  1884. }
  1885. this.owner._scene && this._setActiveInScene(false);
  1886. this._onDestroy();
  1887. this._destroyed=true;
  1888. if (this.onReset!==laya.components.Component.prototype.onReset){
  1889. this.onReset();
  1890. this._resetComp();
  1891. Pool.recoverByClass(this);
  1892. }else {
  1893. this._resetComp();
  1894. }
  1895. }
  1896. /**
  1897. *获取唯一标识ID。
  1898. */
  1899. __getset(0,__proto,'id',function(){
  1900. return this._id;
  1901. });
  1902. /**
  1903. *获取是否启用组件。
  1904. */
  1905. __getset(0,__proto,'enabled',function(){
  1906. return this._enabled;
  1907. },function(value){
  1908. this._enabled=value;
  1909. if (this.owner){
  1910. if (value)
  1911. this.owner.activeInHierarchy && this._onEnable();
  1912. else
  1913. this.owner.activeInHierarchy && this._onDisable();
  1914. }
  1915. });
  1916. /**
  1917. *获取是否为单实例组件。
  1918. */
  1919. __getset(0,__proto,'isSingleton',function(){
  1920. return true;
  1921. });
  1922. /**
  1923. *获取是否已经销毁 。
  1924. */
  1925. __getset(0,__proto,'destroyed',function(){
  1926. return this._destroyed;
  1927. });
  1928. return Component;
  1929. })()
  1930. /**
  1931. *封装弱引用WeakMap
  1932. *如果支持WeakMap,则使用WeakMap,如果不支持,则用Object代替
  1933. *注意:如果采用Object,为了防止内存泄漏,则采用定时清理缓存策略
  1934. */
  1935. //class laya.utils.WeakObject
  1936. var WeakObject=(function(){
  1937. function WeakObject(){
  1938. /**@private */
  1939. this._obj=null;
  1940. this._obj=WeakObject.supportWeakMap ? new Browser.window.WeakMap():{};
  1941. if (!WeakObject.supportWeakMap)WeakObject._maps.push(this);
  1942. }
  1943. __class(WeakObject,'laya.utils.WeakObject');
  1944. var __proto=WeakObject.prototype;
  1945. /**
  1946. *设置缓存
  1947. *@param key kye对象,可被回收
  1948. *@param value object对象,可被回收
  1949. */
  1950. __proto.set=function(key,value){
  1951. if (key==null)return;
  1952. if (WeakObject.supportWeakMap){
  1953. var objKey=key;
  1954. if ((typeof key=='string')|| (typeof key=='number')){
  1955. objKey=WeakObject._keys[key];
  1956. if (!objKey)objKey=WeakObject._keys[key]={k:key};
  1957. }
  1958. this._obj.set(objKey,value);
  1959. }else {
  1960. if ((typeof key=='string')|| (typeof key=='number')){
  1961. this._obj[key]=value;
  1962. }else {
  1963. key.$_GID || (key.$_GID=Utils.getGID());
  1964. this._obj[key.$_GID]=value;
  1965. }
  1966. }
  1967. }
  1968. /**
  1969. *获取缓存
  1970. *@param key kye对象,可被回收
  1971. */
  1972. __proto.get=function(key){
  1973. if (key==null)return null;
  1974. if (WeakObject.supportWeakMap){
  1975. var objKey=((typeof key=='string')|| (typeof key=='number'))? WeakObject._keys[key] :key;
  1976. if (!objKey)return null;
  1977. return this._obj.get(objKey);
  1978. }else {
  1979. if ((typeof key=='string')|| (typeof key=='number'))return this._obj[key];
  1980. return this._obj[key.$_GID];
  1981. }
  1982. }
  1983. //TODO:coverage
  1984. __proto.del=function(key){
  1985. if (key==null)return;
  1986. if (WeakObject.supportWeakMap){
  1987. var objKey=((typeof key=='string')|| (typeof key=='number'))? WeakObject._keys[key] :key;
  1988. if (!objKey)return;
  1989. /*__JS__ */this._obj.delete(objKey);
  1990. }else {
  1991. if ((typeof key=='string')|| (typeof key=='number'))delete this._obj[key];
  1992. else delete this._obj[this._obj.$_GID];
  1993. }
  1994. }
  1995. //TODO:coverage
  1996. __proto.has=function(key){
  1997. if (key==null)return false;
  1998. if (WeakObject.supportWeakMap){
  1999. var objKey=((typeof key=='string')|| (typeof key=='number'))? WeakObject._keys[key] :key;
  2000. return this._obj.has(objKey);
  2001. }else {
  2002. if ((typeof key=='string')|| (typeof key=='number'))return this._obj[key] !=null;
  2003. return this._obj[this._obj.$_GID] !=null;
  2004. }
  2005. }
  2006. WeakObject.__init__=function(){
  2007. WeakObject.supportWeakMap=Browser.window.WeakMap !=null;
  2008. if (!WeakObject.supportWeakMap)Laya.systemTimer.loop(WeakObject.delInterval,null,WeakObject.clearCache);
  2009. }
  2010. WeakObject.clearCache=function(){
  2011. for (var i=0,n=WeakObject._maps.length;i < n;i++){
  2012. var obj=WeakObject._maps[i];
  2013. obj._obj={};
  2014. }
  2015. }
  2016. WeakObject.supportWeakMap=false;
  2017. WeakObject.delInterval=10 *60 *1000;
  2018. WeakObject._keys={};
  2019. WeakObject._maps=[];
  2020. __static(WeakObject,
  2021. ['I',function(){return this.I=new WeakObject();}
  2022. ]);
  2023. return WeakObject;
  2024. })()
  2025. /**
  2026. *@private
  2027. *存储cache相关
  2028. */
  2029. //class laya.display.css.CacheStyle
  2030. var CacheStyle=(function(){
  2031. function CacheStyle(){
  2032. /**当前实际的cache状态*/
  2033. //this.cacheAs=null;
  2034. /**是否开启canvas渲染*/
  2035. //this.enableCanvasRender=false;
  2036. /**用户设的cacheAs类型*/
  2037. //this.userSetCache=null;
  2038. /**是否需要为滤镜cache*/
  2039. //this.cacheForFilters=false;
  2040. /**是否为静态缓存*/
  2041. //this.staticCache=false;
  2042. /**是否需要刷新缓存*/
  2043. //this.reCache=false;
  2044. /**mask对象*/
  2045. //this.mask=null;
  2046. /**作为mask时的父对象*/
  2047. //this.maskParent=null;
  2048. /**滤镜数据*/
  2049. //this.filters=null;
  2050. /**当前缓存区域*/
  2051. //this.cacheRect=null;
  2052. /**当前使用的canvas*/
  2053. //this.canvas=null;
  2054. /**滤镜数据*/
  2055. //this.filterCache=null;
  2056. /**是否有发光滤镜*/
  2057. //this.hasGlowFilter=false;
  2058. this.reset();
  2059. }
  2060. __class(CacheStyle,'laya.display.css.CacheStyle');
  2061. var __proto=CacheStyle.prototype;
  2062. /**
  2063. *是否需要Bitmap缓存
  2064. *@return
  2065. */
  2066. __proto.needBitmapCache=function(){
  2067. return this.cacheForFilters || !!this.mask;
  2068. }
  2069. /**
  2070. *是否需要开启canvas渲染
  2071. */
  2072. __proto.needEnableCanvasRender=function(){
  2073. return this.userSetCache !="none" || this.cacheForFilters || !!this.mask;
  2074. }
  2075. /**
  2076. *释放cache的资源
  2077. */
  2078. __proto.releaseContext=function(){
  2079. if (this.canvas && (this.canvas).size){
  2080. Pool.recover("CacheCanvas",this.canvas);
  2081. this.canvas.size(0,0);
  2082. (this.canvas).width=0;
  2083. (this.canvas).height=0;
  2084. }
  2085. this.canvas=null;
  2086. }
  2087. __proto.createContext=function(){
  2088. if (!this.canvas){
  2089. this.canvas=Pool.getItem("CacheCanvas")|| new HTMLCanvas(false);
  2090. var tx=this.canvas.context;
  2091. if (!tx){
  2092. tx=this.canvas.getContext('2d');
  2093. }
  2094. }
  2095. }
  2096. /**
  2097. *释放滤镜资源
  2098. */
  2099. __proto.releaseFilterCache=function(){
  2100. var fc=this.filterCache;
  2101. if (fc){
  2102. fc.destroy();
  2103. fc.recycle();
  2104. this.filterCache=null;
  2105. }
  2106. }
  2107. /**
  2108. *回收
  2109. */
  2110. __proto.recover=function(){
  2111. if (this===CacheStyle.EMPTY)return;
  2112. Pool.recover("SpriteCache",this.reset());
  2113. }
  2114. /**
  2115. *重置
  2116. */
  2117. __proto.reset=function(){
  2118. this.releaseContext();
  2119. this.releaseFilterCache();
  2120. this.cacheAs="none";
  2121. this.enableCanvasRender=false;
  2122. this.userSetCache="none";
  2123. this.cacheForFilters=false;
  2124. this.staticCache=false;
  2125. this.reCache=true;
  2126. this.mask=null;
  2127. this.maskParent=null;
  2128. this.filterCache=null;
  2129. this.filters=null;
  2130. this.hasGlowFilter=false;
  2131. if(this.cacheRect)this.cacheRect.recover();
  2132. this.cacheRect=null;
  2133. return this
  2134. }
  2135. __proto._calculateCacheRect=function(sprite,tCacheType,x,y){
  2136. var _cacheStyle=sprite._cacheStyle;
  2137. if (!_cacheStyle.cacheRect)
  2138. _cacheStyle.cacheRect=Rectangle.create();
  2139. var tRec;
  2140. if (tCacheType==="bitmap"){
  2141. tRec=sprite.getSelfBounds();
  2142. tRec.width=tRec.width+16*2;
  2143. tRec.height=tRec.height+16*2;
  2144. tRec.x=tRec.x-sprite.pivotX;
  2145. tRec.y=tRec.y-sprite.pivotY;
  2146. tRec.x=tRec.x-16;
  2147. tRec.y=tRec.y-16;
  2148. tRec.x=Math.floor(tRec.x+x)-x;
  2149. tRec.y=Math.floor(tRec.y+y)-y;
  2150. tRec.width=Math.floor(tRec.width);
  2151. tRec.height=Math.floor(tRec.height);
  2152. _cacheStyle.cacheRect.copyFrom(tRec);
  2153. }else {
  2154. _cacheStyle.cacheRect.setTo(-sprite._style.pivotX,-sprite._style.pivotY,1,1);
  2155. }
  2156. tRec=_cacheStyle.cacheRect;
  2157. if (sprite._style.scrollRect){
  2158. var scrollRect=sprite._style.scrollRect;
  2159. tRec.x-=scrollRect.x;
  2160. tRec.y-=scrollRect.y;
  2161. }
  2162. CacheStyle._scaleInfo.setTo(1,1);
  2163. return CacheStyle._scaleInfo;
  2164. }
  2165. CacheStyle.create=function(){
  2166. return Pool.getItemByClass("SpriteCache",CacheStyle);
  2167. }
  2168. CacheStyle.EMPTY=new CacheStyle();
  2169. CacheStyle.CANVAS_EXTEND_EDGE=16;
  2170. __static(CacheStyle,
  2171. ['_scaleInfo',function(){return this._scaleInfo=new Point();}
  2172. ]);
  2173. return CacheStyle;
  2174. })()
  2175. /**
  2176. *绘制图片
  2177. */
  2178. //class laya.display.cmd.DrawImageCmd
  2179. var DrawImageCmd=(function(){
  2180. function DrawImageCmd(){
  2181. /**
  2182. *纹理。
  2183. */
  2184. //this.texture=null;
  2185. /**
  2186. *(可选)X轴偏移量。
  2187. */
  2188. //this.x=NaN;
  2189. /**
  2190. *(可选)Y轴偏移量。
  2191. */
  2192. //this.y=NaN;
  2193. /**
  2194. *(可选)宽度。
  2195. */
  2196. //this.width=NaN;
  2197. /**
  2198. *(可选)高度。
  2199. */
  2200. //this.height=NaN;
  2201. }
  2202. __class(DrawImageCmd,'laya.display.cmd.DrawImageCmd');
  2203. var __proto=DrawImageCmd.prototype;
  2204. /**
  2205. *回收到对象池
  2206. */
  2207. __proto.recover=function(){
  2208. this.texture._removeReference();
  2209. this.texture=null;
  2210. Pool.recover("DrawImageCmd",this);
  2211. }
  2212. /**@private */
  2213. __proto.run=function(context,gx,gy){
  2214. context.drawTexture(this.texture,this.x+gx,this.y+gy,this.width,this.height);
  2215. }
  2216. /**@private */
  2217. __getset(0,__proto,'cmdID',function(){
  2218. return "DrawImage";
  2219. });
  2220. DrawImageCmd.create=function(texture,x,y,width,height){
  2221. var cmd=Pool.getItemByClass("DrawImageCmd",DrawImageCmd);
  2222. cmd.texture=texture;
  2223. texture._addReference();
  2224. cmd.x=x;
  2225. cmd.y=y;
  2226. cmd.width=width;
  2227. cmd.height=height;
  2228. return cmd;
  2229. }
  2230. DrawImageCmd.ID="DrawImage";
  2231. return DrawImageCmd;
  2232. })()
  2233. //class laya.webgl.utils.Buffer
  2234. var Buffer=(function(){
  2235. function Buffer(){
  2236. //当前gl绑定的indexBuffer
  2237. this._glBuffer=null;
  2238. this._buffer=null;
  2239. //可能为Float32Array、Uint16Array、Uint8Array、ArrayBuffer等。
  2240. this._bufferType=0;
  2241. this._bufferUsage=0;
  2242. this._byteLength=0;
  2243. this._glBuffer=LayaGL.instance.createBuffer()
  2244. }
  2245. __class(Buffer,'laya.webgl.utils.Buffer');
  2246. var __proto=Buffer.prototype;
  2247. /**
  2248. *@private
  2249. *绕过全局状态判断,例如VAO局部状态设置
  2250. */
  2251. __proto._bindForVAO=function(){}
  2252. //TODO:coverage
  2253. __proto.bind=function(){
  2254. return false;
  2255. }
  2256. /**
  2257. *@private
  2258. */
  2259. __proto.destroy=function(){
  2260. if (this._glBuffer){
  2261. LayaGL.instance.deleteBuffer(this._glBuffer);
  2262. this._glBuffer=null;
  2263. }
  2264. }
  2265. __getset(0,__proto,'bufferUsage',function(){
  2266. return this._bufferUsage;
  2267. });
  2268. Buffer._bindedVertexBuffer=null;
  2269. Buffer._bindedIndexBuffer=null;
  2270. return Buffer;
  2271. })()
  2272. /**
  2273. *...
  2274. *@author laoxie
  2275. */
  2276. //class laya.webgl.text.CharSubmitCache
  2277. var CharSubmitCache=(function(){
  2278. function CharSubmitCache(){
  2279. this._data=[];
  2280. this._ndata=0;
  2281. this._tex=null;
  2282. this._imgId=0;
  2283. this._clipid=-1;
  2284. this._enbale=false;
  2285. this._colorFiler=null;
  2286. this._clipMatrix=new Matrix();
  2287. }
  2288. __class(CharSubmitCache,'laya.webgl.text.CharSubmitCache');
  2289. var __proto=CharSubmitCache.prototype;
  2290. __proto.clear=function(){
  2291. this._tex=null;
  2292. this._imgId=-1;
  2293. this._ndata=0;
  2294. this._enbale=false;
  2295. this._colorFiler=null;
  2296. }
  2297. __proto.destroy=function(){
  2298. this.clear();
  2299. this._data.length=0;
  2300. this._data=null;
  2301. }
  2302. __proto.add=function(ctx,tex,imgid,pos,uv,color){
  2303. if (this._ndata > 0 && (this._tex !=tex || this._imgId !=imgid ||
  2304. (this._clipid>=0 && this._clipid!=ctx._clipInfoID))){
  2305. this.submit(ctx);
  2306. }
  2307. this._clipid=ctx._clipInfoID;
  2308. ctx._globalClipMatrix.copyTo(this._clipMatrix);
  2309. this._tex=tex;
  2310. this._imgId=imgid;
  2311. this._colorFiler=ctx._colorFiler;
  2312. this._data[this._ndata]=pos;
  2313. this._data[this._ndata+1]=uv;
  2314. this._data[this._ndata+2]=color;
  2315. this._ndata+=3;
  2316. }
  2317. __proto.getPos=function(){
  2318. if (CharSubmitCache.__nPosPool==0)
  2319. return new Array(8);
  2320. return CharSubmitCache.__posPool[--CharSubmitCache.__nPosPool];
  2321. }
  2322. __proto.enable=function(value,ctx){
  2323. if (value===this._enbale)
  2324. return;
  2325. this._enbale=value;
  2326. this._enbale || this.submit(ctx);
  2327. }
  2328. __proto.submit=function(ctx){
  2329. var n=this._ndata;
  2330. if (!n)
  2331. return;
  2332. var _mesh=ctx._mesh;
  2333. var colorFiler=ctx._colorFiler;
  2334. ctx._colorFiler=this._colorFiler;
  2335. var submit=SubmitTexture.create(ctx,_mesh ,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  2336. ctx._submits[ctx._submits._length++]=ctx._curSubmit=submit;
  2337. submit.shaderValue.textureHost=this._tex;
  2338. submit._key.other=this._imgId;
  2339. ctx._colorFiler=colorFiler;
  2340. ctx._copyClipInfo(submit,this._clipMatrix);
  2341. submit.clipInfoID=this._clipid;
  2342. for (var i=0;i < n;i+=3){
  2343. _mesh.addQuad(this._data[i],this._data[i+1] ,this._data [i+2],true);
  2344. CharSubmitCache.__posPool[CharSubmitCache.__nPosPool++]=this._data[i];
  2345. }
  2346. n /=3;
  2347. submit._numEle+=n*6;
  2348. _mesh.indexNum+=n*6;
  2349. _mesh.vertNum+=n*4;
  2350. ctx._drawCount+=n;
  2351. this._ndata=0;
  2352. if (Stat.loopCount % 100==0)
  2353. this._data.length=0;
  2354. }
  2355. CharSubmitCache.__posPool=[];
  2356. CharSubmitCache.__nPosPool=0;
  2357. return CharSubmitCache;
  2358. })()
  2359. /**
  2360. *<code>ClassUtils</code> 是一个类工具类。
  2361. */
  2362. //class laya.utils.ClassUtils
  2363. var ClassUtils=(function(){
  2364. function ClassUtils(){}
  2365. __class(ClassUtils,'laya.utils.ClassUtils');
  2366. ClassUtils.regClass=function(className,classDef){
  2367. ClassUtils._classMap[className]=classDef;
  2368. }
  2369. ClassUtils.regShortClassName=function(classes){
  2370. for (var i=0;i < classes.length;i++){
  2371. var classDef=classes[i];
  2372. var className=classDef.name;
  2373. ClassUtils._classMap[className]=classDef;
  2374. }
  2375. }
  2376. ClassUtils.getRegClass=function(className){
  2377. return ClassUtils._classMap[className];
  2378. }
  2379. ClassUtils.getClass=function(className){
  2380. var classObject=ClassUtils._classMap[className] || className;
  2381. if ((typeof classObject=='string'))return (Laya["__classmap"][classObject] || Laya[className]);
  2382. return classObject;
  2383. }
  2384. ClassUtils.getInstance=function(className){
  2385. var compClass=ClassUtils.getClass(className);
  2386. if (compClass)return new compClass();
  2387. else console.warn("[error] Undefined class:",className);
  2388. return null;
  2389. }
  2390. ClassUtils.createByJson=function(json,node,root,customHandler,instanceHandler){
  2391. if ((typeof json=='string'))json=JSON.parse(json);
  2392. var props=json.props;
  2393. if (!node){
  2394. node=instanceHandler ? instanceHandler.runWith(json):ClassUtils.getInstance(props.runtime || json.type);
  2395. if (!node)return null;
  2396. };
  2397. var child=json.child;
  2398. if (child){
  2399. for (var i=0,n=child.length;i < n;i++){
  2400. var data=child[i];
  2401. if ((data.props.name==="render" || data.props.renderType==="render")&& node["_$set_itemRender"])
  2402. node.itemRender=data;
  2403. else {
  2404. if (data.type=="Graphic"){
  2405. ClassUtils._addGraphicsToSprite(data,node);
  2406. }else if (ClassUtils._isDrawType(data.type)){
  2407. ClassUtils._addGraphicToSprite(data,node,true);
  2408. }else {
  2409. var tChild=ClassUtils.createByJson(data,null,root,customHandler,instanceHandler)
  2410. if (data.type==="Script"){
  2411. if (tChild.hasOwnProperty("owner")){
  2412. tChild["owner"]=node;
  2413. }else if (tChild.hasOwnProperty("target")){
  2414. tChild["target"]=node;
  2415. }
  2416. }else if (data.props.renderType=="mask"){
  2417. node.mask=tChild;
  2418. }else {
  2419. node.addChild(tChild);
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. if (props){
  2426. for (var prop in props){
  2427. var value=props[prop];
  2428. if (prop==="var" && root){
  2429. root[value]=node;
  2430. }else if ((value instanceof Array)&& (typeof (node[prop])=='function')){
  2431. node[prop].apply(node,value);
  2432. }else {
  2433. node[prop]=value;
  2434. }
  2435. }
  2436. }
  2437. if (customHandler && json.customProps){
  2438. customHandler.runWith([node,json]);
  2439. }
  2440. if (node["created"])node.created();
  2441. return node;
  2442. }
  2443. ClassUtils._addGraphicsToSprite=function(graphicO,sprite){
  2444. var graphics=graphicO.child;
  2445. if (!graphics || graphics.length < 1)return;
  2446. var g=ClassUtils._getGraphicsFromSprite(graphicO,sprite);
  2447. var ox=0;
  2448. var oy=0;
  2449. if (graphicO.props){
  2450. ox=ClassUtils._getObjVar(graphicO.props,"x",0);
  2451. oy=ClassUtils._getObjVar(graphicO.props,"y",0);
  2452. }
  2453. if (ox !=0 && oy !=0){
  2454. g.translate(ox,oy);
  2455. };
  2456. var i=0,len=0;
  2457. len=graphics.length;
  2458. for (i=0;i < len;i++){
  2459. ClassUtils._addGraphicToGraphics(graphics[i],g);
  2460. }
  2461. if (ox !=0 && oy !=0){
  2462. g.translate(-ox,-oy);
  2463. }
  2464. }
  2465. ClassUtils._addGraphicToSprite=function(graphicO,sprite,isChild){
  2466. (isChild===void 0)&& (isChild=false);
  2467. var g=isChild ? ClassUtils._getGraphicsFromSprite(graphicO,sprite):sprite.graphics;
  2468. ClassUtils._addGraphicToGraphics(graphicO,g);
  2469. }
  2470. ClassUtils._getGraphicsFromSprite=function(dataO,sprite){
  2471. if (!dataO || !dataO.props)return sprite.graphics;
  2472. var propsName=dataO.props.renderType;
  2473. if (propsName==="hit" || propsName==="unHit"){
  2474. var hitArea=sprite._style.hitArea || (sprite.hitArea=new HitArea());
  2475. if (!hitArea[propsName]){
  2476. hitArea[propsName]=new Graphics();
  2477. };
  2478. var g=hitArea[propsName];
  2479. }
  2480. if (!g)g=sprite.graphics;
  2481. return g;
  2482. }
  2483. ClassUtils._getTransformData=function(propsO){
  2484. var m;
  2485. if (propsO.hasOwnProperty("pivotX")|| propsO.hasOwnProperty("pivotY")){
  2486. m=m || new Matrix();
  2487. m.translate(-ClassUtils._getObjVar(propsO,"pivotX",0),-ClassUtils._getObjVar(propsO,"pivotY",0));
  2488. };
  2489. var sx=ClassUtils._getObjVar(propsO,"scaleX",1),sy=ClassUtils._getObjVar(propsO,"scaleY",1);
  2490. var rotate=ClassUtils._getObjVar(propsO,"rotation",0);
  2491. var skewX=ClassUtils._getObjVar(propsO,"skewX",0);
  2492. var skewY=ClassUtils._getObjVar(propsO,"skewY",0);
  2493. if (sx !=1 || sy !=1 || rotate !=0){
  2494. m=m || new Matrix();
  2495. m.scale(sx,sy);
  2496. m.rotate(rotate *0.0174532922222222);
  2497. }
  2498. return m;
  2499. }
  2500. ClassUtils._addGraphicToGraphics=function(graphicO,graphic){
  2501. var propsO;
  2502. propsO=graphicO.props;
  2503. if (!propsO)return;
  2504. var drawConfig;
  2505. drawConfig=ClassUtils.DrawTypeDic[graphicO.type];
  2506. if (!drawConfig)return;
  2507. var g=graphic;
  2508. var params=ClassUtils._getParams(propsO,drawConfig[1],drawConfig[2],drawConfig[3]);
  2509. var m=ClassUtils._tM;
  2510. if (m || ClassUtils._alpha !=1){
  2511. g.save();
  2512. if (m)g.transform(m);
  2513. if (ClassUtils._alpha !=1)g.alpha(ClassUtils._alpha);
  2514. }
  2515. g[drawConfig[0]].apply(g,params);
  2516. if (m || ClassUtils._alpha !=1){
  2517. g.restore();
  2518. }
  2519. }
  2520. ClassUtils._adptLineData=function(params){
  2521. params[2]=parseFloat(params[0])+parseFloat(params[2]);
  2522. params[3]=parseFloat(params[1])+parseFloat(params[3]);
  2523. return params;
  2524. }
  2525. ClassUtils._adptTextureData=function(params){
  2526. params[0]=Loader.getRes(params[0]);
  2527. return params;
  2528. }
  2529. ClassUtils._adptLinesData=function(params){
  2530. params[2]=ClassUtils._getPointListByStr(params[2]);
  2531. return params;
  2532. }
  2533. ClassUtils._isDrawType=function(type){
  2534. if (type==="Image")return false;
  2535. return ClassUtils.DrawTypeDic.hasOwnProperty(type);
  2536. }
  2537. ClassUtils._getParams=function(obj,params,xPos,adptFun){
  2538. (xPos===void 0)&& (xPos=0);
  2539. var rst=ClassUtils._temParam;
  2540. rst.length=params.length;
  2541. var i=0,len=0;
  2542. len=params.length;
  2543. for (i=0;i < len;i++){
  2544. rst[i]=ClassUtils._getObjVar(obj,params[i][0],params[i][1]);
  2545. }
  2546. ClassUtils._alpha=ClassUtils._getObjVar(obj,"alpha",1);
  2547. var m;
  2548. m=ClassUtils._getTransformData(obj);
  2549. if (m){
  2550. if (!xPos)xPos=0;
  2551. m.translate(rst[xPos],rst[xPos+1]);
  2552. rst[xPos]=rst[xPos+1]=0;
  2553. ClassUtils._tM=m;
  2554. }else {
  2555. ClassUtils._tM=null;
  2556. }
  2557. if (adptFun && ClassUtils[adptFun]){
  2558. rst=ClassUtils[adptFun](rst);
  2559. }
  2560. return rst;
  2561. }
  2562. ClassUtils._getPointListByStr=function(str){
  2563. var pointArr=str.split(",");
  2564. var i=0,len=0;
  2565. len=pointArr.length;
  2566. for (i=0;i < len;i++){
  2567. pointArr[i]=parseFloat(pointArr[i]);
  2568. }
  2569. return pointArr;
  2570. }
  2571. ClassUtils._getObjVar=function(obj,key,noValue){
  2572. if (obj.hasOwnProperty(key)){
  2573. return obj[key];
  2574. }
  2575. return noValue;
  2576. }
  2577. ClassUtils._temParam=[];
  2578. ClassUtils._classMap={'Sprite':Sprite,'Scene':Scene,'Text':Text,'Animation':'laya.display.Animation','Skeleton':'laya.ani.bone.Skeleton','Particle2D':'laya.particle.Particle2D','div':'laya.html.dom.HTMLDivParser','p':'laya.html.dom.HTMLElement','img':'laya.html.dom.HTMLImageElement','span':'laya.html.dom.HTMLElement','br':'laya.html.dom.HTMLBrElement','style':'laya.html.dom.HTMLStyleElement','font':'laya.html.dom.HTMLElement','a':'laya.html.dom.HTMLElement','#text':'laya.html.dom.HTMLElement','link':'laya.html.dom.HTMLLinkElement'};
  2579. ClassUtils._tM=null;
  2580. ClassUtils._alpha=NaN;
  2581. __static(ClassUtils,
  2582. ['DrawTypeDic',function(){return this.DrawTypeDic={"Rect":["drawRect",[["x",0],["y",0],["width",0],["height",0],["fillColor",null],["lineColor",null],["lineWidth",1]]],"Circle":["drawCircle",[["x",0],["y",0],["radius",0],["fillColor",null],["lineColor",null],["lineWidth",1]]],"Pie":["drawPie",[["x",0],["y",0],["radius",0],["startAngle",0],["endAngle",0],["fillColor",null],["lineColor",null],["lineWidth",1]]],"Image":["drawTexture",[["x",0],["y",0],["width",0],["height",0]]],"Texture":["drawTexture",[["skin",null],["x",0],["y",0],["width",0],["height",0]],1,"_adptTextureData"],"FillTexture":["fillTexture",[["skin",null],["x",0],["y",0],["width",0],["height",0],["repeat",null]],1,"_adptTextureData"],"FillText":["fillText",[["text",""],["x",0],["y",0],["font",null],["color",null],["textAlign",null]],1],"Line":["drawLine",[["x",0],["y",0],["toX",0],["toY",0],["lineColor",null],["lineWidth",0]],0,"_adptLineData"],"Lines":["drawLines",[["x",0],["y",0],["points",""],["lineColor",null],["lineWidth",0]],0,"_adptLinesData"],"Curves":["drawCurves",[["x",0],["y",0],["points",""],["lineColor",null],["lineWidth",0]],0,"_adptLinesData"],"Poly":["drawPoly",[["x",0],["y",0],["points",""],["fillColor",null],["lineColor",null],["lineWidth",1]],0,"_adptLinesData"]};}
  2583. ]);
  2584. return ClassUtils;
  2585. })()
  2586. /**
  2587. *<code>Tween</code> 是一个缓动类。使用此类能够实现对目标对象属性的渐变。
  2588. */
  2589. //class laya.utils.Tween
  2590. var Tween=(function(){
  2591. function Tween(){
  2592. /**@private */
  2593. //this._complete=null;
  2594. /**@private */
  2595. //this._target=null;
  2596. /**@private */
  2597. //this._ease=null;
  2598. /**@private */
  2599. //this._props=null;
  2600. /**@private */
  2601. //this._duration=0;
  2602. /**@private */
  2603. //this._delay=0;
  2604. /**@private */
  2605. //this._startTimer=0;
  2606. /**@private */
  2607. //this._usedTimer=0;
  2608. /**@private */
  2609. //this._usedPool=false;
  2610. /**@private */
  2611. //this._delayParam=null;
  2612. /**@private 唯一标识,TimeLintLite用到*/
  2613. this.gid=0;
  2614. /**更新回调,缓动数值发生变化时,回调变化的值*/
  2615. //this.update=null;
  2616. /**重播次数,如果repeat=0,则表示无限循环播放*/
  2617. this.repeat=1;
  2618. /**当前播放次数*/
  2619. this._count=0;
  2620. }
  2621. __class(Tween,'laya.utils.Tween');
  2622. var __proto=Tween.prototype;
  2623. /**
  2624. *缓动对象的props属性到目标值。
  2625. *@param target 目标对象(即将更改属性值的对象)。
  2626. *@param props 变化的属性列表,比如{x:100,y:20,ease:Ease.backOut,complete:Handler.create(this,onComplete),update:new Handler(this,onComplete)}。
  2627. *@param duration 花费的时间,单位毫秒。
  2628. *@param ease 缓动类型,默认为匀速运动。
  2629. *@param complete 结束回调函数。
  2630. *@param delay 延迟执行时间。
  2631. *@param coverBefore 是否覆盖之前的缓动。
  2632. *@return 返回Tween对象。
  2633. */
  2634. __proto.to=function(target,props,duration,ease,complete,delay,coverBefore){
  2635. (delay===void 0)&& (delay=0);
  2636. (coverBefore===void 0)&& (coverBefore=false);
  2637. return this._create(target,props,duration,ease,complete,delay,coverBefore,true,false,true);
  2638. }
  2639. /**
  2640. *从props属性,缓动到当前状态。
  2641. *@param target 目标对象(即将更改属性值的对象)。
  2642. *@param props 变化的属性列表,比如{x:100,y:20,ease:Ease.backOut,complete:Handler.create(this,onComplete),update:new Handler(this,onComplete)}。
  2643. *@param duration 花费的时间,单位毫秒。
  2644. *@param ease 缓动类型,默认为匀速运动。
  2645. *@param complete 结束回调函数。
  2646. *@param delay 延迟执行时间。
  2647. *@param coverBefore 是否覆盖之前的缓动。
  2648. *@return 返回Tween对象。
  2649. */
  2650. __proto.from=function(target,props,duration,ease,complete,delay,coverBefore){
  2651. (delay===void 0)&& (delay=0);
  2652. (coverBefore===void 0)&& (coverBefore=false);
  2653. return this._create(target,props,duration,ease,complete,delay,coverBefore,false,false,true);
  2654. }
  2655. /**@private */
  2656. __proto._create=function(target,props,duration,ease,complete,delay,coverBefore,isTo,usePool,runNow){
  2657. if (!target)throw new Error("Tween:target is null");
  2658. this._target=target;
  2659. this._duration=duration;
  2660. this._ease=ease || props.ease || Tween.easeNone;
  2661. this._complete=complete || props.complete;
  2662. this._delay=delay;
  2663. this._props=[];
  2664. this._usedTimer=0;
  2665. this._startTimer=Browser.now();
  2666. this._usedPool=usePool;
  2667. this._delayParam=null;
  2668. this.update=props.update;
  2669. var gid=(target.$_GID || (target.$_GID=Utils.getGID()));
  2670. if (!Tween.tweenMap[gid]){
  2671. Tween.tweenMap[gid]=[this];
  2672. }else {
  2673. if (coverBefore)Tween.clearTween(target);
  2674. Tween.tweenMap[gid].push(this);
  2675. }
  2676. if (runNow){
  2677. if (delay <=0)this.firstStart(target,props,isTo);
  2678. else {
  2679. this._delayParam=[target,props,isTo];
  2680. Laya.timer.once(delay,this,this.firstStart,this._delayParam);
  2681. }
  2682. }else {
  2683. this._initProps(target,props,isTo);
  2684. }
  2685. return this;
  2686. }
  2687. __proto.firstStart=function(target,props,isTo){
  2688. this._delayParam=null;
  2689. if (target.destroyed){
  2690. this.clear();
  2691. return;
  2692. }
  2693. this._initProps(target,props,isTo);
  2694. this._beginLoop();
  2695. }
  2696. __proto._initProps=function(target,props,isTo){
  2697. for (var p in props){
  2698. if ((typeof (target[p])=='number')){
  2699. var start=isTo ? target[p] :props[p];
  2700. var end=isTo ? props[p] :target[p];
  2701. this._props.push([p,start,end-start]);
  2702. if (!isTo)target[p]=start;
  2703. }
  2704. }
  2705. }
  2706. __proto._beginLoop=function(){
  2707. Laya.timer.frameLoop(1,this,this._doEase);
  2708. }
  2709. /**执行缓动**/
  2710. __proto._doEase=function(){
  2711. this._updateEase(Browser.now());
  2712. }
  2713. /**@private */
  2714. __proto._updateEase=function(time){
  2715. var target=this._target;
  2716. if (!target)return;
  2717. if (target.destroyed)return Tween.clearTween(target);
  2718. var usedTimer=this._usedTimer=time-this._startTimer-this._delay;
  2719. if (usedTimer < 0)return;
  2720. if (usedTimer >=this._duration)return this.complete();
  2721. var ratio=usedTimer > 0 ? this._ease(usedTimer,0,1,this._duration):0;
  2722. var props=this._props;
  2723. for (var i=0,n=props.length;i < n;i++){
  2724. var prop=props[i];
  2725. target[prop[0]]=prop[1]+(ratio *prop[2]);
  2726. }
  2727. if (this.update)this.update.run();
  2728. }
  2729. /**
  2730. *立即结束缓动并到终点。
  2731. */
  2732. __proto.complete=function(){
  2733. if (!this._target)return;
  2734. Laya.timer.runTimer(this,this.firstStart);
  2735. var target=this._target;
  2736. var props=this._props;
  2737. var handler=this._complete;
  2738. for (var i=0,n=props.length;i < n;i++){
  2739. var prop=props[i];
  2740. target[prop[0]]=prop[1]+prop[2];
  2741. }
  2742. if (this.update)this.update.run();
  2743. this._count++;
  2744. if (this.repeat !=0 && this._count >=this.repeat){
  2745. this.clear();
  2746. handler && handler.run();
  2747. }else {
  2748. this.restart();
  2749. }
  2750. }
  2751. /**
  2752. *暂停缓动,可以通过resume或restart重新开始。
  2753. */
  2754. __proto.pause=function(){
  2755. Laya.timer.clear(this,this._beginLoop);
  2756. Laya.timer.clear(this,this._doEase);
  2757. Laya.timer.clear(this,this.firstStart);
  2758. var time=Browser.now();
  2759. var dTime=NaN;
  2760. dTime=time-this._startTimer-this._delay;
  2761. if (dTime < 0){
  2762. this._usedTimer=dTime;
  2763. }
  2764. }
  2765. /**
  2766. *设置开始时间。
  2767. *@param startTime 开始时间。
  2768. */
  2769. __proto.setStartTime=function(startTime){
  2770. this._startTimer=startTime;
  2771. }
  2772. /**
  2773. *停止并清理当前缓动。
  2774. */
  2775. __proto.clear=function(){
  2776. if (this._target){
  2777. this._remove();
  2778. this._clear();
  2779. }
  2780. }
  2781. /**
  2782. *@private
  2783. */
  2784. __proto._clear=function(){
  2785. this.pause();
  2786. Laya.timer.clear(this,this.firstStart);
  2787. this._complete=null;
  2788. this._target=null;
  2789. this._ease=null;
  2790. this._props=null;
  2791. this._delayParam=null;
  2792. if (this._usedPool){
  2793. this.update=null;
  2794. Pool.recover("tween",this);
  2795. }
  2796. }
  2797. /**回收到对象池。*/
  2798. __proto.recover=function(){
  2799. this._usedPool=true;
  2800. this._clear();
  2801. }
  2802. __proto._remove=function(){
  2803. var tweens=Tween.tweenMap[this._target.$_GID];
  2804. if (tweens){
  2805. for (var i=0,n=tweens.length;i < n;i++){
  2806. if (tweens[i]===this){
  2807. tweens.splice(i,1);
  2808. break ;
  2809. }
  2810. }
  2811. }
  2812. }
  2813. /**
  2814. *重新开始暂停的缓动。
  2815. */
  2816. __proto.restart=function(){
  2817. this.pause();
  2818. this._usedTimer=0;
  2819. this._startTimer=Browser.now();
  2820. if (this._delayParam){
  2821. Laya.timer.once(this._delay,this,this.firstStart,this._delayParam);
  2822. return;
  2823. };
  2824. var props=this._props;
  2825. for (var i=0,n=props.length;i < n;i++){
  2826. var prop=props[i];
  2827. this._target[prop[0]]=prop[1];
  2828. }
  2829. Laya.timer.once(this._delay,this,this._beginLoop);
  2830. }
  2831. /**
  2832. *恢复暂停的缓动。
  2833. */
  2834. __proto.resume=function(){
  2835. if (this._usedTimer >=this._duration)return;
  2836. this._startTimer=Browser.now()-this._usedTimer-this._delay;
  2837. if (this._delayParam){
  2838. if (this._usedTimer < 0){
  2839. Laya.timer.once(-this._usedTimer,this,this.firstStart,this._delayParam);
  2840. }else {
  2841. this.firstStart.apply(this,this._delayParam);
  2842. }
  2843. }else {
  2844. this._beginLoop();
  2845. }
  2846. }
  2847. /**设置当前执行比例**/
  2848. __getset(0,__proto,'progress',null,function(v){
  2849. var uTime=v *this._duration;
  2850. this._startTimer=Browser.now()-this._delay-uTime;
  2851. });
  2852. Tween.to=function(target,props,duration,ease,complete,delay,coverBefore,autoRecover){
  2853. (delay===void 0)&& (delay=0);
  2854. (coverBefore===void 0)&& (coverBefore=false);
  2855. (autoRecover===void 0)&& (autoRecover=true);
  2856. return Pool.getItemByClass("tween",Tween)._create(target,props,duration,ease,complete,delay,coverBefore,true,autoRecover,true);
  2857. }
  2858. Tween.from=function(target,props,duration,ease,complete,delay,coverBefore,autoRecover){
  2859. (delay===void 0)&& (delay=0);
  2860. (coverBefore===void 0)&& (coverBefore=false);
  2861. (autoRecover===void 0)&& (autoRecover=true);
  2862. return Pool.getItemByClass("tween",Tween)._create(target,props,duration,ease,complete,delay,coverBefore,false,autoRecover,true);
  2863. }
  2864. Tween.clearAll=function(target){
  2865. if (!target || !target.$_GID)return;
  2866. var tweens=Tween.tweenMap[target.$_GID];
  2867. if (tweens){
  2868. for (var i=0,n=tweens.length;i < n;i++){
  2869. tweens[i]._clear();
  2870. }
  2871. tweens.length=0;
  2872. }
  2873. }
  2874. Tween.clear=function(tween){
  2875. tween.clear();
  2876. }
  2877. Tween.clearTween=function(target){
  2878. Tween.clearAll(target);
  2879. }
  2880. Tween.easeNone=function(t,b,c,d){
  2881. return c *t / d+b;
  2882. }
  2883. Tween.tweenMap=[];
  2884. return Tween;
  2885. })()
  2886. //class laya.webgl.shader.ShaderDefinesBase
  2887. var ShaderDefinesBase=(function(){
  2888. function ShaderDefinesBase(name2int,int2name,int2nameMap){
  2889. this._value=0;
  2890. //this._name2int=null;
  2891. //this._int2name=null;
  2892. //this._int2nameMap=null;
  2893. this._name2int=name2int;
  2894. this._int2name=int2name;
  2895. this._int2nameMap=int2nameMap;
  2896. }
  2897. __class(ShaderDefinesBase,'laya.webgl.shader.ShaderDefinesBase');
  2898. var __proto=ShaderDefinesBase.prototype;
  2899. //TODO:coverage
  2900. __proto.add=function(value){
  2901. if ((typeof value=='string'))value=this._name2int[value];
  2902. this._value |=value;
  2903. return this._value;
  2904. }
  2905. __proto.addInt=function(value){
  2906. this._value |=value;
  2907. return this._value;
  2908. }
  2909. //TODO:coverage
  2910. __proto.remove=function(value){
  2911. if ((typeof value=='string'))value=this._name2int[value];
  2912. this._value &=(~value);
  2913. return this._value;
  2914. }
  2915. //TODO:coverage
  2916. __proto.isDefine=function(def){
  2917. return (this._value & def)===def;
  2918. }
  2919. //TODO:coverage
  2920. __proto.getValue=function(){
  2921. return this._value;
  2922. }
  2923. __proto.setValue=function(value){
  2924. this._value=value;
  2925. }
  2926. __proto.toNameDic=function(){
  2927. var r=this._int2nameMap[this._value];
  2928. return r ? r :ShaderDefinesBase._toText(this._value,this._int2name,this._int2nameMap);
  2929. }
  2930. ShaderDefinesBase._reg=function(name,value,_name2int,_int2name){
  2931. _name2int[name]=value;
  2932. _int2name[value]=name;
  2933. }
  2934. ShaderDefinesBase._toText=function(value,_int2name,_int2nameMap){
  2935. var r=_int2nameMap[value];
  2936. if (r)return r;
  2937. var o={};
  2938. var d=1;
  2939. for (var i=0;i < 32;i++){
  2940. d=1 << i;
  2941. if (d > value)break ;
  2942. if (value & d){
  2943. var name=_int2name[d];
  2944. name && (o[name]="");
  2945. }
  2946. }
  2947. _int2nameMap[value]=o;
  2948. return o;
  2949. }
  2950. ShaderDefinesBase._toInt=function(names,_name2int){
  2951. var words=names.split('.');
  2952. var num=0;
  2953. for (var i=0,n=words.length;i < n;i++){
  2954. var value=_name2int[words[i]];
  2955. if (!value)throw new Error("Defines to int err:"+names+"/"+words[i]);
  2956. num |=value;
  2957. }
  2958. return num;
  2959. }
  2960. return ShaderDefinesBase;
  2961. })()
  2962. /**
  2963. *@private
  2964. *TODO:
  2965. */
  2966. //class laya.utils.VectorGraphManager
  2967. var VectorGraphManager=(function(){
  2968. function VectorGraphManager(){
  2969. this.useDic={};
  2970. this.shapeDic={};
  2971. this.shapeLineDic={};
  2972. this._id=0;
  2973. this._checkKey=false;
  2974. this._freeIdArray=[];
  2975. CacheManger.regCacheByFunction(Utils.bind(this.startDispose,this),Utils.bind(this.getCacheList,this));
  2976. }
  2977. __class(VectorGraphManager,'laya.utils.VectorGraphManager');
  2978. var __proto=VectorGraphManager.prototype;
  2979. /**
  2980. *得到个空闲的ID
  2981. *@return
  2982. */
  2983. __proto.getId=function(){
  2984. return this._id++;
  2985. }
  2986. /**
  2987. *添加一个图形到列表中
  2988. *@param id
  2989. *@param shape
  2990. */
  2991. __proto.addShape=function(id,shape){
  2992. this.shapeDic[id]=shape;
  2993. if (!this.useDic[id]){
  2994. this.useDic[id]=true;
  2995. }
  2996. }
  2997. /**
  2998. *添加一个线图形到列表中
  2999. *@param id
  3000. *@param Line
  3001. */
  3002. __proto.addLine=function(id,Line){
  3003. this.shapeLineDic[id]=Line;
  3004. if (!this.shapeLineDic[id]){
  3005. this.shapeLineDic[id]=true;
  3006. }
  3007. }
  3008. /**
  3009. *检测一个对象是否在使用中
  3010. *@param id
  3011. */
  3012. __proto.getShape=function(id){
  3013. if (this._checkKey){
  3014. if (this.useDic[id] !=null){
  3015. this.useDic[id]=true;
  3016. }
  3017. }
  3018. }
  3019. /**
  3020. *删除一个图形对象
  3021. *@param id
  3022. */
  3023. __proto.deleteShape=function(id){
  3024. if (this.shapeDic[id]){
  3025. this.shapeDic[id]=null;
  3026. delete this.shapeDic[id];
  3027. }
  3028. if (this.shapeLineDic[id]){
  3029. this.shapeLineDic[id]=null;
  3030. delete this.shapeLineDic[id];
  3031. }
  3032. if (this.useDic[id] !=null){
  3033. delete this.useDic[id];
  3034. }
  3035. }
  3036. /**
  3037. *得到缓存列表
  3038. *@return
  3039. */
  3040. __proto.getCacheList=function(){
  3041. var str;
  3042. var list=[];
  3043. for (str in this.shapeDic){
  3044. list.push(this.shapeDic[str]);
  3045. }
  3046. for (str in this.shapeLineDic){
  3047. list.push(this.shapeLineDic[str]);
  3048. }
  3049. return list;
  3050. }
  3051. /**
  3052. *开始清理状态,准备销毁
  3053. */
  3054. __proto.startDispose=function(key){
  3055. var str;
  3056. for (str in this.useDic){
  3057. this.useDic[str]=false;
  3058. }
  3059. this._checkKey=true;
  3060. }
  3061. /**
  3062. *确认销毁
  3063. */
  3064. __proto.endDispose=function(){
  3065. if (this._checkKey){
  3066. var str;
  3067. for (str in this.useDic){
  3068. if (!this.useDic[str]){
  3069. this.deleteShape(str);
  3070. }
  3071. }
  3072. this._checkKey=false;
  3073. }
  3074. }
  3075. VectorGraphManager.getInstance=function(){
  3076. return VectorGraphManager.instance=VectorGraphManager.instance|| new VectorGraphManager();
  3077. }
  3078. VectorGraphManager.instance=null;
  3079. return VectorGraphManager;
  3080. })()
  3081. /**
  3082. *根据路径绘制矢量图形
  3083. */
  3084. //class laya.display.cmd.DrawPathCmd
  3085. var DrawPathCmd=(function(){
  3086. function DrawPathCmd(){
  3087. /**
  3088. *开始绘制的 X 轴位置。
  3089. */
  3090. //this.x=NaN;
  3091. /**
  3092. *开始绘制的 Y 轴位置。
  3093. */
  3094. //this.y=NaN;
  3095. /**
  3096. *路径集合,路径支持以下格式:[["moveTo",x,y],["lineTo",x,y],["arcTo",x1,y1,x2,y2,r],["closePath"]]。
  3097. */
  3098. //this.paths=null;
  3099. /**
  3100. *(可选)刷子定义,支持以下设置{fillStyle:"#FF0000"}。
  3101. */
  3102. //this.brush=null;
  3103. /**
  3104. *(可选)画笔定义,支持以下设置{strokeStyle,lineWidth,lineJoin:"bevel|round|miter",lineCap:"butt|round|square",miterLimit}。
  3105. */
  3106. //this.pen=null;
  3107. }
  3108. __class(DrawPathCmd,'laya.display.cmd.DrawPathCmd');
  3109. var __proto=DrawPathCmd.prototype;
  3110. /**
  3111. *回收到对象池
  3112. */
  3113. __proto.recover=function(){
  3114. this.paths=null;
  3115. this.brush=null;
  3116. this.pen=null;
  3117. Pool.recover("DrawPathCmd",this);
  3118. }
  3119. /**@private */
  3120. __proto.run=function(context,gx,gy){
  3121. context._drawPath(this.x+gx,this.y+gy,this.paths,this.brush,this.pen);
  3122. }
  3123. /**@private */
  3124. __getset(0,__proto,'cmdID',function(){
  3125. return "DrawPath";
  3126. });
  3127. DrawPathCmd.create=function(x,y,paths,brush,pen){
  3128. var cmd=Pool.getItemByClass("DrawPathCmd",DrawPathCmd);
  3129. cmd.x=x;
  3130. cmd.y=y;
  3131. cmd.paths=paths;
  3132. cmd.brush=brush;
  3133. cmd.pen=pen;
  3134. return cmd;
  3135. }
  3136. DrawPathCmd.ID="DrawPath";
  3137. return DrawPathCmd;
  3138. })()
  3139. /**
  3140. *@private
  3141. */
  3142. //class laya.filters.GlowFilterGLRender
  3143. var GlowFilterGLRender=(function(){
  3144. function GlowFilterGLRender(){}
  3145. __class(GlowFilterGLRender,'laya.filters.GlowFilterGLRender');
  3146. var __proto=GlowFilterGLRender.prototype;
  3147. __proto.setShaderInfo=function(shader,w,h,data){
  3148. shader.defines.add(data.type);
  3149. var sv=shader;
  3150. sv.u_blurInfo1=data._sv_blurInfo1;
  3151. var info2=data._sv_blurInfo2;
  3152. info2[0]=w;info2[1]=h;
  3153. sv.u_blurInfo2=info2;
  3154. sv.u_color=data.getColor();
  3155. }
  3156. __proto.render=function(rt,ctx,width,height,filter){
  3157. var w=width,h=height;
  3158. var svBlur=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  3159. this.setShaderInfo(svBlur,w,h,filter);
  3160. var svCP=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  3161. var matI=Matrix.TEMP.identity();
  3162. ctx.drawTarget(rt,0,0,w,h,matI,svBlur);
  3163. ctx.drawTarget(rt,0,0,w,h,matI,svCP);
  3164. }
  3165. return GlowFilterGLRender;
  3166. })()
  3167. /**
  3168. *<code>Timer</code> 是时钟管理类。它是一个单例,不要手动实例化此类,应该通过 Laya.timer 访问。
  3169. */
  3170. //class laya.utils.Timer
  3171. var Timer=(function(){
  3172. var TimerHandler;
  3173. function Timer(autoActive){
  3174. /**时针缩放。*/
  3175. this.scale=1;
  3176. /**当前的帧数。*/
  3177. this.currFrame=0;
  3178. /**@private 两帧之间的时间间隔,单位毫秒。*/
  3179. this._delta=0;
  3180. /**@private */
  3181. this._map=[];
  3182. /**@private */
  3183. this._handlers=[];
  3184. /**@private */
  3185. this._temp=[];
  3186. /**@private */
  3187. this._count=0;
  3188. this.currTimer=Browser.now();
  3189. this._lastTimer=Browser.now();
  3190. (autoActive===void 0)&& (autoActive=true);
  3191. autoActive && Laya.systemTimer && Laya.systemTimer.frameLoop(1,this,this._update);
  3192. }
  3193. __class(Timer,'laya.utils.Timer');
  3194. var __proto=Timer.prototype;
  3195. /**
  3196. *@private
  3197. *帧循环处理函数。
  3198. */
  3199. __proto._update=function(){
  3200. if (this.scale <=0){
  3201. this._lastTimer=Browser.now();
  3202. return;
  3203. };
  3204. var frame=this.currFrame=this.currFrame+this.scale;
  3205. var now=Browser.now();
  3206. this._delta=(now-this._lastTimer)*this.scale;
  3207. var timer=this.currTimer=this.currTimer+this._delta;
  3208. this._lastTimer=now;
  3209. var handlers=this._handlers;
  3210. this._count=0;
  3211. for (var i=0,n=handlers.length;i < n;i++){
  3212. var handler=handlers[i];
  3213. if (handler.method!==null){
  3214. var t=handler.userFrame ? frame :timer;
  3215. if (t >=handler.exeTime){
  3216. if (handler.repeat){
  3217. if (!handler.jumpFrame){
  3218. handler.exeTime+=handler.delay;
  3219. handler.run(false);
  3220. if (t > handler.exeTime){
  3221. handler.exeTime+=Math.ceil((t-handler.exeTime)/ handler.delay)*handler.delay;
  3222. }
  3223. }else {
  3224. while (t >=handler.exeTime){
  3225. handler.exeTime+=handler.delay;
  3226. handler.run(false);
  3227. }
  3228. }
  3229. }else {
  3230. handler.run(true);
  3231. }
  3232. }
  3233. }else {
  3234. this._count++;
  3235. }
  3236. }
  3237. if (this._count > 30 || frame % 200===0)this._clearHandlers();
  3238. }
  3239. /**@private */
  3240. __proto._clearHandlers=function(){
  3241. var handlers=this._handlers;
  3242. for (var i=0,n=handlers.length;i < n;i++){
  3243. var handler=handlers[i];
  3244. if (handler.method!==null)this._temp.push(handler);
  3245. else this._recoverHandler(handler);
  3246. }
  3247. this._handlers=this._temp;
  3248. handlers.length=0;
  3249. this._temp=handlers;
  3250. }
  3251. /**@private */
  3252. __proto._recoverHandler=function(handler){
  3253. if (this._map[handler.key]==handler)this._map[handler.key]=null;
  3254. handler.clear();
  3255. Timer._pool.push(handler);
  3256. }
  3257. /**@private */
  3258. __proto._create=function(useFrame,repeat,delay,caller,method,args,coverBefore){
  3259. if (!delay){
  3260. method.apply(caller,args);
  3261. return null;
  3262. }
  3263. if (coverBefore){
  3264. var handler=this._getHandler(caller,method);
  3265. if (handler){
  3266. handler.repeat=repeat;
  3267. handler.userFrame=useFrame;
  3268. handler.delay=delay;
  3269. handler.caller=caller;
  3270. handler.method=method;
  3271. handler.args=args;
  3272. handler.exeTime=delay+(useFrame ? this.currFrame :this.currTimer+Browser.now()-this._lastTimer);
  3273. return handler;
  3274. }
  3275. }
  3276. handler=Timer._pool.length > 0 ? Timer._pool.pop():new TimerHandler();
  3277. handler.repeat=repeat;
  3278. handler.userFrame=useFrame;
  3279. handler.delay=delay;
  3280. handler.caller=caller;
  3281. handler.method=method;
  3282. handler.args=args;
  3283. handler.exeTime=delay+(useFrame ? this.currFrame :this.currTimer+Browser.now()-this._lastTimer);
  3284. this._indexHandler(handler);
  3285. this._handlers.push(handler);
  3286. return handler;
  3287. }
  3288. /**@private */
  3289. __proto._indexHandler=function(handler){
  3290. var caller=handler.caller;
  3291. var method=handler.method;
  3292. var cid=caller ? caller.$_GID || (caller.$_GID=Utils.getGID()):0;
  3293. var mid=method.$_TID || (method.$_TID=(Timer._mid++)*100000);
  3294. handler.key=cid+mid;
  3295. this._map[handler.key]=handler;
  3296. }
  3297. /**
  3298. *定时执行一次。
  3299. *@param delay 延迟时间(单位为毫秒)。
  3300. *@param caller 执行域(this)。
  3301. *@param method 定时器回调函数。
  3302. *@param args 回调参数。
  3303. *@param coverBefore 是否覆盖之前的延迟执行,默认为 true 。
  3304. */
  3305. __proto.once=function(delay,caller,method,args,coverBefore){
  3306. (coverBefore===void 0)&& (coverBefore=true);
  3307. this._create(false,false,delay,caller,method,args,coverBefore);
  3308. }
  3309. /**
  3310. *定时重复执行。
  3311. *@param delay 间隔时间(单位毫秒)。
  3312. *@param caller 执行域(this)。
  3313. *@param method 定时器回调函数。
  3314. *@param args 回调参数。
  3315. *@param coverBefore 是否覆盖之前的延迟执行,默认为 true 。
  3316. *@param jumpFrame 时钟是否跳帧。基于时间的循环回调,单位时间间隔内,如能执行多次回调,出于性能考虑,引擎默认只执行一次,设置jumpFrame=true后,则回调会连续执行多次
  3317. */
  3318. __proto.loop=function(delay,caller,method,args,coverBefore,jumpFrame){
  3319. (coverBefore===void 0)&& (coverBefore=true);
  3320. (jumpFrame===void 0)&& (jumpFrame=false);
  3321. var handler=this._create(false,true,delay,caller,method,args,coverBefore);
  3322. if (handler)handler.jumpFrame=jumpFrame;
  3323. }
  3324. /**
  3325. *定时执行一次(基于帧率)。
  3326. *@param delay 延迟几帧(单位为帧)。
  3327. *@param caller 执行域(this)。
  3328. *@param method 定时器回调函数。
  3329. *@param args 回调参数。
  3330. *@param coverBefore 是否覆盖之前的延迟执行,默认为 true 。
  3331. */
  3332. __proto.frameOnce=function(delay,caller,method,args,coverBefore){
  3333. (coverBefore===void 0)&& (coverBefore=true);
  3334. this._create(true,false,delay,caller,method,args,coverBefore);
  3335. }
  3336. /**
  3337. *定时重复执行(基于帧率)。
  3338. *@param delay 间隔几帧(单位为帧)。
  3339. *@param caller 执行域(this)。
  3340. *@param method 定时器回调函数。
  3341. *@param args 回调参数。
  3342. *@param coverBefore 是否覆盖之前的延迟执行,默认为 true 。
  3343. */
  3344. __proto.frameLoop=function(delay,caller,method,args,coverBefore){
  3345. (coverBefore===void 0)&& (coverBefore=true);
  3346. this._create(true,true,delay,caller,method,args,coverBefore);
  3347. }
  3348. /**返回统计信息。*/
  3349. __proto.toString=function(){
  3350. return " handlers:"+this._handlers.length+" pool:"+Timer._pool.length;
  3351. }
  3352. /**
  3353. *清理定时器。
  3354. *@param caller 执行域(this)。
  3355. *@param method 定时器回调函数。
  3356. */
  3357. __proto.clear=function(caller,method){
  3358. var handler=this._getHandler(caller,method);
  3359. if (handler){
  3360. this._map[handler.key]=null;
  3361. handler.key=0;
  3362. handler.clear();
  3363. }
  3364. }
  3365. /**
  3366. *清理对象身上的所有定时器。
  3367. *@param caller 执行域(this)。
  3368. */
  3369. __proto.clearAll=function(caller){
  3370. if (!caller)return;
  3371. for (var i=0,n=this._handlers.length;i < n;i++){
  3372. var handler=this._handlers[i];
  3373. if (handler.caller===caller){
  3374. this._map[handler.key]=null;
  3375. handler.key=0;
  3376. handler.clear();
  3377. }
  3378. }
  3379. }
  3380. /**@private */
  3381. __proto._getHandler=function(caller,method){
  3382. var cid=caller ? caller.$_GID || (caller.$_GID=Utils.getGID()):0;
  3383. var mid=method.$_TID || (method.$_TID=(Timer._mid++)*100000);
  3384. return this._map[cid+mid];
  3385. }
  3386. /**
  3387. *延迟执行。
  3388. *@param caller 执行域(this)。
  3389. *@param method 定时器回调函数。
  3390. *@param args 回调参数。
  3391. */
  3392. __proto.callLater=function(caller,method,args){
  3393. CallLater.I.callLater(caller,method,args);
  3394. }
  3395. /**
  3396. *立即执行 callLater 。
  3397. *@param caller 执行域(this)。
  3398. *@param method 定时器回调函数。
  3399. */
  3400. __proto.runCallLater=function(caller,method){
  3401. CallLater.I.runCallLater(caller,method);
  3402. }
  3403. /**
  3404. *立即提前执行定时器,执行之后从队列中删除
  3405. *@param caller 执行域(this)。
  3406. *@param method 定时器回调函数。
  3407. */
  3408. __proto.runTimer=function(caller,method){
  3409. var handler=this._getHandler(caller,method);
  3410. if (handler && handler.method !=null){
  3411. this._map[handler.key]=null;
  3412. handler.run(true);
  3413. }
  3414. }
  3415. /**
  3416. *暂停时钟
  3417. */
  3418. __proto.pause=function(){
  3419. this.scale=0;
  3420. }
  3421. /**
  3422. *恢复时钟
  3423. */
  3424. __proto.resume=function(){
  3425. this.scale=1;
  3426. }
  3427. /**两帧之间的时间间隔,单位毫秒。*/
  3428. __getset(0,__proto,'delta',function(){
  3429. return this._delta;
  3430. });
  3431. Timer._pool=[];
  3432. Timer._mid=1;
  3433. Timer.__init$=function(){
  3434. /**@private */
  3435. //class TimerHandler
  3436. TimerHandler=(function(){
  3437. function TimerHandler(){
  3438. this.key=0;
  3439. this.repeat=false;
  3440. this.delay=0;
  3441. this.userFrame=false;
  3442. this.exeTime=0;
  3443. this.caller=null;
  3444. this.method=null;
  3445. this.args=null;
  3446. this.jumpFrame=false;
  3447. }
  3448. __class(TimerHandler,'');
  3449. var __proto=TimerHandler.prototype;
  3450. __proto.clear=function(){
  3451. this.caller=null;
  3452. this.method=null;
  3453. this.args=null;
  3454. }
  3455. __proto.run=function(withClear){
  3456. var caller=this.caller;
  3457. if (caller && caller.destroyed)return this.clear();
  3458. var method=this.method;
  3459. var args=this.args;
  3460. withClear && this.clear();
  3461. if (method==null)return;
  3462. args ? method.apply(caller,args):method.call(caller);
  3463. }
  3464. return TimerHandler;
  3465. })()
  3466. }
  3467. return Timer;
  3468. })()
  3469. //class laya.webgl.text.TextRender
  3470. var TextRender=(function(){
  3471. function TextRender(){
  3472. /**
  3473. *fontSizeInfo
  3474. *记录每种字体的像素的大小。标准是32px的字体。由4个byte组成,分别表示[xdist,ydist,w,h]。
  3475. *xdist,ydist 是像素起点到排版原点的距离,都是正的,表示实际数据往左和上偏多少,如果实际往右和下偏,则算作0,毕竟这个只是一个大概
  3476. *例如 [Arial]=0x00002020,表示宽高都是32
  3477. */
  3478. this.fontSizeInfo={};
  3479. this.charRender=null;
  3480. this.mapFont={};
  3481. // 把font名称映射到数字
  3482. this.fontID=0;
  3483. this.mapColor=[];
  3484. // 把color映射到数字
  3485. this.colorID=0;
  3486. this.fontScaleX=1.0;
  3487. //临时缩放。
  3488. this.fontScaleY=1.0;
  3489. //private var charMaps:Object={};// 所有的都放到一起
  3490. this._curStrPos=0;
  3491. // 所有的独立贴图
  3492. this.bmpData32=null;
  3493. // 当前字体的测量信息。
  3494. this.lastFont=null;
  3495. this.fontSizeW=0;
  3496. this.fontSizeH=0;
  3497. this.fontSizeOffX=0;
  3498. this.fontSizeOffY=0;
  3499. this.renderPerChar=true;
  3500. this.textureMem=0;
  3501. // 当前贴图所占用的内存
  3502. this.fontStr=null;
  3503. this.textAtlases=[];
  3504. this.isoTextures=[];
  3505. this.tmpAtlasPos=new Point();
  3506. var bugIOS=false;
  3507. var miniadp=Laya['MiniAdpter'];
  3508. if (miniadp && miniadp.systemInfo && miniadp.systemInfo.system){
  3509. bugIOS=miniadp.systemInfo.system.toLowerCase()==='ios 10.1.1';
  3510. }
  3511. if (Browser.onMiniGame && !bugIOS)TextRender.isWan1Wan=true;
  3512. if (Browser.onLimixiu)TextRender.isWan1Wan=true;
  3513. this.charRender=Render.isConchApp ? (new CharRender_Native()):(new CharRender_Canvas(TextRender.atlasWidth,TextRender.atlasWidth,TextRender.scaleFontWithCtx,!TextRender.isWan1Wan,false));
  3514. TextRender.textRenderInst=this;
  3515. Laya['textRender']=this;
  3516. TextRender.atlasWidth2=TextRender.atlasWidth *TextRender.atlasWidth;
  3517. }
  3518. __class(TextRender,'laya.webgl.text.TextRender');
  3519. var __proto=TextRender.prototype;
  3520. /**
  3521. *设置当前字体,获得字体的大小信息。
  3522. *@param font
  3523. */
  3524. __proto.setFont=function(font){
  3525. if (this.lastFont==font)return;
  3526. this.lastFont=font;
  3527. var fontsz=this.getFontSizeInfo(font._family);
  3528. var offx=fontsz >> 24;
  3529. var offy=(fontsz >> 16)& 0xff;
  3530. var fw=(fontsz >> 8)& 0xff;
  3531. var fh=fontsz & 0xff;
  3532. var k=font._size / TextRender.standardFontSize;
  3533. this.fontSizeOffX=Math.ceil(offx *k);
  3534. this.fontSizeOffY=Math.ceil(offy *k);
  3535. this.fontSizeW=Math.ceil(fw *k);
  3536. this.fontSizeH=Math.ceil(fh *k);
  3537. if(font._font.indexOf('italic')>=0){
  3538. this.fontStr=font._font.replace('italic','');
  3539. }else {
  3540. this.fontStr=font._font;
  3541. }
  3542. }
  3543. /**
  3544. *从string中取出一个完整的char,例如emoji的话要多个
  3545. *会修改 _curStrPos
  3546. *TODO 由于各种文字中的组合写法,这个需要能扩展,以便支持泰文等
  3547. *@param str
  3548. *@param start 开始位置
  3549. */
  3550. __proto.getNextChar=function(str){
  3551. var len=str.length;
  3552. var start=this._curStrPos;
  3553. if (start >=len)
  3554. return null;
  3555. var link=false;
  3556. var i=start;
  3557. var state=0;
  3558. for (;i < len;i++){
  3559. var c=str.charCodeAt(i);
  3560. if ((c >>> 11)==0x1b){
  3561. if (state==1)break ;
  3562. state=1;
  3563. i++;
  3564. }
  3565. else if (c===0xfe0e || c===0xfe0f){}
  3566. else if (c==0x200d){
  3567. state=2;
  3568. }else {
  3569. if (state==0)state=1;
  3570. else if (state==1)break ;
  3571. else if (state==2){}
  3572. }
  3573. }
  3574. this._curStrPos=i;
  3575. return str.substring(start,i);
  3576. }
  3577. __proto.filltext=function(ctx,data,x,y,fontStr,color,strokeColor,lineWidth,textAlign,underLine){
  3578. (underLine===void 0)&& (underLine=0);
  3579. if (data.length <=0)
  3580. return;
  3581. var font=FontInfo.Parse(fontStr);
  3582. var nTextAlign=0;
  3583. switch (textAlign){
  3584. case 'center':
  3585. nTextAlign=Context.ENUM_TEXTALIGN_CENTER;
  3586. break ;
  3587. case 'right':
  3588. nTextAlign=Context.ENUM_TEXTALIGN_RIGHT;
  3589. break ;
  3590. }
  3591. this._fast_filltext(ctx,data,null,x,y,font,color,strokeColor,lineWidth,nTextAlign,underLine);
  3592. }
  3593. __proto.fillWords=function(ctx,data,x,y,fontStr,color,strokeColor,lineWidth){
  3594. if (!data)return;
  3595. if (data.length <=0)return;
  3596. var font=FontInfo.Parse(fontStr);
  3597. this._fast_filltext(ctx,null,data,x,y,font,color,strokeColor,lineWidth,0,0);
  3598. }
  3599. __proto._fast_filltext=function(ctx,data,htmlchars,x,y,font,color,strokeColor,lineWidth,textAlign,underLine){
  3600. (underLine===void 0)&& (underLine=0);
  3601. if (data && data.length < 1)return;
  3602. if (htmlchars && htmlchars.length < 1)return;
  3603. if (lineWidth < 0)lineWidth=0;
  3604. this.setFont(font);
  3605. this.fontScaleX=this.fontScaleY=1.0;
  3606. if (!Render.isConchApp && TextRender.scaleFontWithCtx){
  3607. var sx=1;
  3608. var sy=1;
  3609. if (Render.isConchApp){
  3610. sx=ctx._curMat.getScaleX();
  3611. sy=ctx._curMat.getScaleY();
  3612. }else{
  3613. sx=ctx.getMatScaleX();
  3614. sy=ctx.getMatScaleY();
  3615. }
  3616. if (sx < 1e-4 || sy < 1e-1)
  3617. return;
  3618. if (sx > 1)this.fontScaleX=sx;
  3619. if (sy > 1)this.fontScaleY=sy;
  3620. }
  3621. font._italic && (ctx._italicDeg=13);
  3622. var wt=data;
  3623. var isWT=!htmlchars && ((data instanceof laya.utils.WordText ));
  3624. var str=data;
  3625. var isHtmlChar=!!htmlchars;
  3626. var sameTexData=isWT ? wt.pageChars :[];
  3627. var strWidth=0;
  3628. if (isWT){
  3629. str=wt._text;
  3630. strWidth=wt.width;
  3631. if (strWidth < 0){
  3632. strWidth=wt.width=this.charRender.getWidth(this.fontStr,str);
  3633. }
  3634. }else {
  3635. strWidth=str?this.charRender.getWidth(this.fontStr,str):0;
  3636. }
  3637. switch (textAlign){
  3638. case Context.ENUM_TEXTALIGN_CENTER:
  3639. x-=strWidth / 2;
  3640. break ;
  3641. case Context.ENUM_TEXTALIGN_RIGHT:
  3642. x-=strWidth;
  3643. break ;
  3644. }
  3645. if (wt && sameTexData){
  3646. if (this.hasFreedText(sameTexData)){
  3647. sameTexData=wt.pageChars=[];
  3648. }
  3649. };
  3650. var ri=null;
  3651. var oneTex=isWT || TextRender.forceWholeRender;
  3652. var splitTex=this.renderPerChar=(!isWT)|| TextRender.forceSplitRender || isHtmlChar || (isWT && wt.splitRender);
  3653. if (!sameTexData || sameTexData.length < 1){
  3654. if (splitTex){
  3655. var stx=0;
  3656. var sty=0;
  3657. this._curStrPos=0;
  3658. var curstr;
  3659. while(true){
  3660. if (isHtmlChar){
  3661. var chc=htmlchars[this._curStrPos++];
  3662. if(chc){
  3663. curstr=chc.char;
  3664. stx=chc.x;
  3665. sty=chc.y;
  3666. }else {
  3667. curstr=null;
  3668. }
  3669. }else {
  3670. curstr=this.getNextChar(str);
  3671. }
  3672. if (!curstr)
  3673. break ;
  3674. ri=this.getCharRenderInfo(curstr,font,color,strokeColor,lineWidth,false);
  3675. if (!ri){
  3676. break ;
  3677. }
  3678. if (ri.isSpace){
  3679. }else {
  3680. var add=sameTexData[ri.tex.id];
  3681. if (!add){
  3682. var o1={texgen:(ri.tex).genID,tex:ri.tex,words:[] };
  3683. sameTexData[ri.tex.id]=o1;
  3684. add=o1.words;
  3685. }else {
  3686. add=add.words;
  3687. }
  3688. if (Render.isConchApp){
  3689. add.push({ri:ri,x:stx,y:sty,w:ri.bmpWidth / this.fontScaleX,h:ri.bmpHeight / this.fontScaleY });
  3690. }else{
  3691. add.push({ri:ri,x:stx+1/this.fontScaleX,y:sty,w:(ri.bmpWidth-2)/ this.fontScaleX,h:(ri.bmpHeight-1)/ this.fontScaleY });
  3692. }
  3693. stx+=ri.width;
  3694. }
  3695. }
  3696. }else {
  3697. var isotex=TextRender.noAtlas || strWidth*this.fontScaleX > TextRender.atlasWidth;
  3698. ri=this.getCharRenderInfo(str,font,color,strokeColor,lineWidth,isotex);
  3699. if (Render.isConchApp){
  3700. sameTexData[0]={texgen:(ri.tex).genID,tex:ri.tex,words:[{ri:ri,x:0,y:0,w:ri.bmpWidth / this.fontScaleX,h:ri.bmpHeight / this.fontScaleY }]};
  3701. }else{
  3702. sameTexData[0]={texgen:(ri.tex).genID,tex:ri.tex,words:[{ri:ri,x:1/this.fontScaleX,y:0/this.fontScaleY,w:(ri.bmpWidth-2)/ this.fontScaleX,h:(ri.bmpHeight-1)/ this.fontScaleY }]};
  3703. }
  3704. }
  3705. }
  3706. this._drawResortedWords(ctx,x,y,sameTexData);
  3707. ctx._italicDeg=0;
  3708. }
  3709. /**
  3710. *画出重新按照贴图顺序分组的文字。
  3711. *@param samePagesData
  3712. *@param startx 保存的数据是相对位置,所以需要加上这个偏移。用相对位置更灵活一些。
  3713. *@param y {int}因为这个只能画在一行上所以没有必要保存y。所以这里再把y传进来
  3714. */
  3715. __proto._drawResortedWords=function(ctx,startx,starty,samePagesData){
  3716. var isLastRender=ctx._charSubmitCache && ctx._charSubmitCache._enbale;
  3717. var mat=ctx._curMat;
  3718. var slen=samePagesData.length;
  3719. for (var id=0;id < slen;id++){
  3720. var dt=samePagesData[id];
  3721. if (!dt)continue ;
  3722. var pri=dt.words;
  3723. var pisz=pri.length;if (pisz <=0)continue ;
  3724. var tex=(samePagesData[id] .tex);
  3725. for (var j=0;j < pisz;j++){
  3726. var riSaved=pri[j];
  3727. var ri=riSaved.ri;
  3728. if (ri.isSpace)continue ;
  3729. ri.touch();
  3730. ctx.drawTexAlign=true;
  3731. if (Render.isConchApp){
  3732. ctx._drawTextureM(tex.texture,startx+riSaved.x-ri.orix ,starty+riSaved.y-ri.oriy,riSaved.w,riSaved.h,null,1.0,ri.uv);
  3733. }else
  3734. ctx._inner_drawTexture(tex.texture,(tex.texture).bitmap.id,
  3735. startx+riSaved.x-ri.orix ,starty+riSaved.y-ri.oriy,riSaved.w,riSaved.h,
  3736. mat,ri.uv,1.0,isLastRender);
  3737. if ((ctx).touches){
  3738. (ctx).touches.push(ri);
  3739. }
  3740. }
  3741. }
  3742. }
  3743. /**
  3744. *检查 txts数组中有没有被释放的资源
  3745. *@param txts {{ri:CharRenderInfo,...}[][]}
  3746. *@param startid
  3747. *@return
  3748. */
  3749. __proto.hasFreedText=function(txts){
  3750. var sz=txts.length;
  3751. for (var i=0;i < sz;i++){
  3752. var pri=txts[i];
  3753. if (!pri)continue ;
  3754. var tex=(pri.tex);
  3755. if (tex.__destroyed || tex.genID !=pri.texgen){
  3756. return true;
  3757. }
  3758. }
  3759. return false;
  3760. }
  3761. __proto.getCharRenderInfo=function(str,font,color,strokeColor,lineWidth,isoTexture){
  3762. (isoTexture===void 0)&& (isoTexture=false);
  3763. var fid=this.mapFont[font._family];
  3764. if (fid==undefined){
  3765. this.mapFont[font._family]=fid=this.fontID++;
  3766. };
  3767. var key=str+'_'+fid+'_'+font._size+'_'+color;
  3768. if (lineWidth > 0)
  3769. key+='_'+strokeColor+lineWidth;
  3770. if (font._bold)
  3771. key+='P';
  3772. if (this.fontScaleX !=1 || this.fontScaleY !=1){
  3773. key+=(this.fontScaleX*20|0)+'_'+(this.fontScaleY*20|0);
  3774. };
  3775. var i=0;
  3776. var sz=this.textAtlases.length;
  3777. var ri=null;
  3778. var atlas=null;
  3779. if(!isoTexture){
  3780. for (i=0;i < sz;i++){
  3781. atlas=this.textAtlases[i];
  3782. ri=atlas.charMaps[key]
  3783. if (ri){
  3784. ri.touch();
  3785. return ri;
  3786. }
  3787. }
  3788. }
  3789. ri=new CharRenderInfo();
  3790. this.charRender.scale(this.fontScaleX,this.fontScaleY);
  3791. ri.char=str;
  3792. ri.height=font._size;
  3793. var margin=font._size / 3 |0;
  3794. var imgdt=null;
  3795. var w1=Math.ceil(this.charRender.getWidth(this.fontStr,str)*this.fontScaleX);
  3796. if (w1 > this.charRender.canvasWidth){
  3797. this.charRender.canvasWidth=Math.min(2048,w1+margin *2);
  3798. }
  3799. if (isoTexture){
  3800. imgdt=this.charRender.getCharBmp(str,this.fontStr,lineWidth,color,strokeColor,ri,margin,margin,margin,margin,null);
  3801. var tex=TextTexture.getTextTexture(imgdt.width,imgdt.height);
  3802. tex.addChar(imgdt,0,0,ri.uv);
  3803. ri.tex=tex;
  3804. ri.orix=margin;
  3805. ri.oriy=margin;
  3806. tex.ri=ri;
  3807. this.isoTextures.push(tex);
  3808. }else {
  3809. var len=str.length;
  3810. if (len > 1){
  3811. };
  3812. var lineExt=lineWidth*1;
  3813. var fw=Math.ceil((this.fontSizeW+lineExt*2)*this.fontScaleX);
  3814. var fh=Math.ceil((this.fontSizeH+lineExt*2)*this.fontScaleY);
  3815. TextRender.imgdtRect[0]=((margin-this.fontSizeOffX-lineExt)*this.fontScaleX)|0;
  3816. TextRender.imgdtRect[1]=((margin-this.fontSizeOffY-lineExt)*this.fontScaleY)|0;
  3817. if (this.renderPerChar||len==1){
  3818. TextRender.imgdtRect[2]=Math.max(w1,fw);
  3819. TextRender.imgdtRect[3]=Math.max(w1,fh);
  3820. }else {
  3821. TextRender.imgdtRect[2]=-1;
  3822. TextRender.imgdtRect[3]=fh;
  3823. }
  3824. imgdt=this.charRender.getCharBmp(str,this.fontStr,lineWidth,color,strokeColor,ri,
  3825. margin,margin,margin,margin,TextRender.imgdtRect);
  3826. atlas=this.addBmpData(imgdt,ri);
  3827. if (TextRender.isWan1Wan){
  3828. ri.orix=margin;
  3829. ri.oriy=margin;
  3830. }else {
  3831. ri.orix=(this.fontSizeOffX+lineExt);
  3832. ri.oriy=(this.fontSizeOffY+lineExt);
  3833. }
  3834. atlas.charMaps[key]=ri;
  3835. }
  3836. return ri;
  3837. }
  3838. /**
  3839. *添加数据到大图集
  3840. *@param w
  3841. *@param h
  3842. *@return
  3843. */
  3844. __proto.addBmpData=function(data,ri){
  3845. var w=data.width;
  3846. var h=data.height;
  3847. var sz=this.textAtlases.length;
  3848. var atlas=null;
  3849. var find=false;
  3850. for (var i=0;i < sz;i++){
  3851. atlas=this.textAtlases[i];
  3852. find=atlas.getAEmpty(w,h,this.tmpAtlasPos);
  3853. if (find){
  3854. break ;
  3855. }
  3856. }
  3857. if (!find){
  3858. atlas=new TextAtlas()
  3859. this.textAtlases.push(atlas);
  3860. find=atlas.getAEmpty(w,h,this.tmpAtlasPos);
  3861. if (!find){
  3862. throw 'err1';
  3863. }
  3864. this.cleanAtlases();
  3865. }
  3866. if(find){
  3867. atlas.texture.addChar(data,this.tmpAtlasPos.x,this.tmpAtlasPos.y,ri.uv);
  3868. ri.tex=/*__JS__ */atlas.texture;
  3869. }
  3870. return atlas;
  3871. }
  3872. /**
  3873. *清理利用率低的大图集
  3874. */
  3875. __proto.GC=function(){
  3876. var i=0;
  3877. var sz=this.textAtlases.length;
  3878. var dt=0;
  3879. var destroyDt=TextRender.destroyAtlasDt;
  3880. var totalUsedRate=0;
  3881. var totalUsedRateAtlas=0;
  3882. var curloop=Stat.loopCount;
  3883. var maxWasteRateID=-1;
  3884. var maxWasteRate=0;
  3885. var tex=null;
  3886. var curatlas=null;
  3887. for (;i < sz;i++){
  3888. curatlas=this.textAtlases[i];
  3889. tex=curatlas.texture;
  3890. if (tex){
  3891. totalUsedRate+=tex.curUsedCovRate;
  3892. totalUsedRateAtlas+=tex.curUsedCovRateAtlas;
  3893. var waste=curatlas.usedRate-tex.curUsedCovRateAtlas;
  3894. if (maxWasteRate < waste){
  3895. maxWasteRate=waste;
  3896. maxWasteRateID=i;
  3897. }
  3898. }
  3899. dt=curloop-curatlas.texture.lastTouchTm;
  3900. if (dt > destroyDt){
  3901. TextRender.showLog && console.log('TextRender GC delete atlas '+tex?curatlas.texture.id:'unk');
  3902. curatlas.destroy();
  3903. this.textAtlases[i]=this.textAtlases[sz-1];
  3904. sz--;
  3905. i--;
  3906. maxWasteRateID=-1;
  3907. }
  3908. }
  3909. this.textAtlases.length=sz;
  3910. sz=this.isoTextures.length;
  3911. for (i=0;i < sz;i++){
  3912. tex=this.isoTextures[i];
  3913. dt=curloop-tex.lastTouchTm;
  3914. if (dt > TextRender.destroyUnusedTextureDt){
  3915. tex.ri.deleted=true;
  3916. tex.ri.tex=null;
  3917. tex.destroy();
  3918. this.isoTextures[i]=this.isoTextures[sz-1];
  3919. sz--;
  3920. i--;
  3921. }
  3922. }
  3923. this.isoTextures.length=sz;
  3924. var needGC=this.textAtlases.length > 1 && this.textAtlases.length-totalUsedRateAtlas >=2;
  3925. if (TextRender.atlasWidth *TextRender.atlasWidth *4 *this.textAtlases.length > TextRender.cleanMem || needGC || TextRender.simClean){
  3926. TextRender.simClean=false;
  3927. TextRender.showLog && console.log('清理使用率低的贴图。总使用率:',totalUsedRateAtlas,':',this.textAtlases.length,'最差贴图:'+maxWasteRateID);
  3928. if(maxWasteRateID>=0){
  3929. curatlas=this.textAtlases[maxWasteRateID];
  3930. curatlas.destroy();
  3931. this.textAtlases[maxWasteRateID]=this.textAtlases[this.textAtlases.length-1];
  3932. this.textAtlases.length=this.textAtlases.length-1;
  3933. }
  3934. }
  3935. TextTexture.clean();
  3936. }
  3937. /**
  3938. *尝试清理大图集
  3939. */
  3940. __proto.cleanAtlases=function(){}
  3941. // TODO 根据覆盖率决定是否清理
  3942. __proto.getCharBmp=function(c){}
  3943. /**
  3944. *检查当前线是否存在数据
  3945. *@param data
  3946. *@param l
  3947. *@param sx
  3948. *@param ex
  3949. *@return
  3950. */
  3951. __proto.checkBmpLine=function(data,l,sx,ex){
  3952. if (this.bmpData32.buffer !=data.data.buffer){
  3953. this.bmpData32=new Uint32Array(data.data.buffer);
  3954. };
  3955. var stpos=data.width *l+sx;
  3956. for (var x=sx;x < ex;x++){
  3957. if (this.bmpData32[stpos++] !=0)return true;
  3958. }
  3959. return false;
  3960. }
  3961. /**
  3962. *根据bmp数据和当前的包围盒,更新包围盒
  3963. *由于选择的文字是连续的,所以可以用二分法
  3964. *@param data
  3965. *@param curbbx [l,t,r,b]
  3966. *@param onlyH 不检查左右
  3967. */
  3968. __proto.updateBbx=function(data,curbbx,onlyH){
  3969. (onlyH===void 0)&& (onlyH=false);
  3970. var w=data.width;
  3971. var h=data.height;
  3972. var x=0;
  3973. var sy=curbbx[1];
  3974. var ey=0;
  3975. var y=sy;
  3976. if (this.checkBmpLine(data,sy,0,w)){
  3977. while (true){
  3978. y=(sy+ey)/ 2 | 0;
  3979. if (y+1 >=sy){
  3980. curbbx[1]=y;
  3981. break ;
  3982. }
  3983. if(this.checkBmpLine(data,y,0,w)){
  3984. sy=y;
  3985. }else {
  3986. ey=y;
  3987. }
  3988. }
  3989. }
  3990. if (curbbx[3] > h)curbbx[3]=h;
  3991. else{
  3992. y=sy=curbbx[3];
  3993. ey=h;
  3994. if (this.checkBmpLine(data,sy,0,w)){
  3995. while(true){
  3996. y=(sy+ey)/ 2 | 0;
  3997. if (y-1 <=sy){
  3998. curbbx[3]=y;
  3999. break ;
  4000. }
  4001. if (this.checkBmpLine(data,y,0,w)){
  4002. sy=y;
  4003. }else {
  4004. ey=y;
  4005. }
  4006. }
  4007. }
  4008. }
  4009. if (onlyH)
  4010. return;
  4011. var minx=curbbx[0];
  4012. var stpos=w*curbbx[1];
  4013. for (y=curbbx[1];y < curbbx[3];y++){
  4014. for (x=0;x < minx;x++){
  4015. if (this.bmpData32[stpos+x] !=0){
  4016. minx=x;
  4017. break ;
  4018. }
  4019. }
  4020. stpos+=w;
  4021. }
  4022. curbbx[0]=minx;
  4023. var maxx=curbbx[2];
  4024. stpos=w*curbbx[1];
  4025. for (y=curbbx[1];y < curbbx[3];y++){
  4026. for (x=maxx;x < w;x++){
  4027. if (this.bmpData32[stpos+x] !=0){
  4028. maxx=x;
  4029. break ;
  4030. }
  4031. }
  4032. stpos+=w;
  4033. }
  4034. curbbx[2]=maxx;
  4035. }
  4036. __proto.getFontSizeInfo=function(font){
  4037. var finfo=this.fontSizeInfo[font];
  4038. if (finfo !=undefined)
  4039. return finfo;
  4040. var fontstr='bold '+TextRender.standardFontSize+'px '+font;
  4041. if (TextRender.isWan1Wan){
  4042. this.fontSizeW=this.charRender.getWidth(fontstr,'有')*1.5;
  4043. this.fontSizeH=TextRender.standardFontSize *1.5;
  4044. var szinfo=this.fontSizeW << 8 | this.fontSizeH;
  4045. this.fontSizeInfo[font]=szinfo;
  4046. return szinfo;
  4047. }
  4048. TextRender.pixelBBX[0]=TextRender.standardFontSize / 2;
  4049. TextRender.pixelBBX[1]=TextRender.standardFontSize / 2;
  4050. TextRender.pixelBBX[2]=TextRender.standardFontSize;
  4051. TextRender.pixelBBX[3]=TextRender.standardFontSize;
  4052. var orix=16;
  4053. var oriy=16;
  4054. var marginr=16;
  4055. var marginb=16;
  4056. this.charRender.scale(1,1);
  4057. TextRender.tmpRI.height=TextRender.standardFontSize;
  4058. var bmpdt=this.charRender.getCharBmp('g',fontstr,0,'red',null,TextRender.tmpRI,orix,oriy,marginr,marginb);
  4059. if (Render.isConchApp){
  4060. bmpdt.data=new /*__JS__ */Uint8ClampedArray(bmpdt.data);
  4061. }
  4062. this.bmpData32=new Uint32Array(bmpdt.data.buffer);
  4063. this.updateBbx(bmpdt,TextRender.pixelBBX,false);
  4064. bmpdt=this.charRender.getCharBmp('有',fontstr,0,'red',null,TextRender.tmpRI,oriy,oriy,marginr,marginb);
  4065. if (Render.isConchApp){
  4066. bmpdt.data=new /*__JS__ */Uint8ClampedArray(bmpdt.data);
  4067. }
  4068. this.bmpData32=new Uint32Array(bmpdt.data.buffer);
  4069. if (TextRender.pixelBBX[2] < orix+TextRender.tmpRI.width)
  4070. TextRender.pixelBBX[2]=orix+TextRender.tmpRI.width;
  4071. this.updateBbx(bmpdt,TextRender.pixelBBX,false);
  4072. if (Render.isConchApp){
  4073. orix=0;
  4074. oriy=0;
  4075. };
  4076. var xoff=Math.max(orix-TextRender.pixelBBX[0],0);
  4077. var yoff=Math.max(oriy-TextRender.pixelBBX[1],0);
  4078. var bbxw=TextRender.pixelBBX[2]-TextRender.pixelBBX[0];
  4079. var bbxh=TextRender.pixelBBX[3]-TextRender.pixelBBX[1]+2;
  4080. var sizeinfo=xoff<<24 |yoff<<16 | bbxw << 8 | bbxh;
  4081. this.fontSizeInfo[font]=sizeinfo;
  4082. return sizeinfo;
  4083. }
  4084. __proto.printDbgInfo=function(){
  4085. console.log('图集个数:'+this.textAtlases.length+',每个图集大小:'+TextRender.atlasWidth+'x'+TextRender.atlasWidth,' 用canvas:',TextRender.isWan1Wan);
  4086. console.log('图集占用空间:'+(TextRender.atlasWidth *TextRender.atlasWidth *4 / 1024 / 1024 *this.textAtlases.length)+'M');
  4087. console.log('缓存用到的字体:');
  4088. for (var f in this.mapFont){
  4089. var fontsz=this.getFontSizeInfo(f);
  4090. var offx=fontsz >> 24;
  4091. var offy=(fontsz >> 16)& 0xff;
  4092. var fw=(fontsz >> 8)& 0xff;
  4093. var fh=fontsz & 0xff;
  4094. console.log(' '+f,' off:',offx,offy,' size:',fw,fh);
  4095. };
  4096. var num=0;
  4097. console.log('缓存数据:');
  4098. var totalUsedRate=0;
  4099. var totalUsedRateAtlas=0;
  4100. this.textAtlases.forEach(function(a){
  4101. var id=a.texture.id;
  4102. var dt=Stat.loopCount-a.texture.lastTouchTm;
  4103. var dtstr=dt > 0?(''+dt+'帧以前'):'当前帧';
  4104. totalUsedRate+=a.texture.curUsedCovRate;
  4105. totalUsedRateAtlas+=a.texture.curUsedCovRateAtlas;
  4106. console.log('--图集(id:'+id+',当前使用率:'+(a.texture.curUsedCovRate*1000|0)+'‰','当前图集使用率:',(a.texture.curUsedCovRateAtlas*100|0)+'%','图集使用率:',(a.usedRate*100|0),'%, 使用于:'+dtstr+')--:');
  4107. for (var k in a.charMaps){
  4108. var ri=a.charMaps[k];
  4109. console.log(' off:',ri.orix,ri.oriy,' bmp宽高:',ri.bmpWidth,ri.bmpHeight,'无效:',ri.deleted,'touchdt:',(Stat.loopCount-ri.touchTick),'位置:',ri.uv[0] *TextRender.atlasWidth | 0,ri.uv[1] *TextRender.atlasWidth | 0,
  4110. '字符:',ri.char,'key:',k);
  4111. num++;
  4112. }
  4113. });
  4114. console.log('独立贴图文字('+this.isoTextures.length+'个):');
  4115. this.isoTextures.forEach(function(tex){
  4116. console.log(' size:',tex._texW,tex._texH,'touch间隔:',(Stat.loopCount-tex.lastTouchTm),'char:',tex.ri.char);
  4117. });
  4118. console.log('总缓存:',num,'总使用率:',totalUsedRate,'总当前图集使用率:',totalUsedRateAtlas);
  4119. }
  4120. // 在屏幕上显示某个大图集
  4121. __proto.showAtlas=function(n,bgcolor,x,y,w,h){
  4122. if (!this.textAtlases[n]){
  4123. console.log('没有这个图集');
  4124. return null;
  4125. };
  4126. var sp=new Sprite();
  4127. var texttex=this.textAtlases[n].texture;
  4128. var texture={
  4129. width:TextRender.atlasWidth,
  4130. height:TextRender.atlasWidth,
  4131. sourceWidth:TextRender.atlasWidth,
  4132. sourceHeight:TextRender.atlasWidth,
  4133. offsetX:0,
  4134. offsetY:0,
  4135. getIsReady:function (){return true;},
  4136. _addReference:function (){},
  4137. _removeReference:function (){},
  4138. _getSource:function (){return texttex._getSource();},
  4139. bitmap:{id:texttex.id },
  4140. _uv:Texture.DEF_UV
  4141. };
  4142. (sp).size=function (w,h){
  4143. this.width=w;
  4144. this.height=h;
  4145. sp.graphics.clear();
  4146. sp.graphics.drawRect(0,0,sp.width,sp.height,bgcolor);
  4147. sp.graphics.drawTexture(texture,0,0,sp.width,sp.height);
  4148. return this;
  4149. }
  4150. sp.graphics.drawRect(0,0,w,h,bgcolor);
  4151. sp.graphics.drawTexture(texture,0,0,w,h);
  4152. sp.pos(x,y);
  4153. Laya.stage.addChild(sp);
  4154. return sp;
  4155. }
  4156. /////// native ///////
  4157. __proto.filltext_native=function(ctx,data,htmlchars,x,y,fontStr,color,strokeColor,lineWidth,textAlign,underLine){
  4158. (underLine===void 0)&& (underLine=0);
  4159. if (data && data.length <=0)return;
  4160. if (htmlchars && htmlchars.length < 1)return;
  4161. var font=FontInfo.Parse(fontStr);
  4162. var nTextAlign=0;
  4163. switch (textAlign){
  4164. case 'center':
  4165. nTextAlign=Context.ENUM_TEXTALIGN_CENTER;
  4166. break ;
  4167. case 'right':
  4168. nTextAlign=Context.ENUM_TEXTALIGN_RIGHT;
  4169. break ;
  4170. }
  4171. return this._fast_filltext(ctx,data,htmlchars,x,y,font,color,strokeColor,lineWidth,nTextAlign,underLine);
  4172. }
  4173. TextRender.useOldCharBook=false;
  4174. TextRender.atlasWidth=2048;
  4175. TextRender.noAtlas=false;
  4176. TextRender.forceSplitRender=false;
  4177. TextRender.forceWholeRender=false;
  4178. TextRender.scaleFontWithCtx=true;
  4179. TextRender.standardFontSize=32;
  4180. TextRender.destroyAtlasDt=10;
  4181. TextRender.checkCleanTextureDt=2000;
  4182. TextRender.destroyUnusedTextureDt=3000;
  4183. TextRender.cleanMem=100 *1024 *1024;
  4184. TextRender.isWan1Wan=false;
  4185. TextRender.showLog=false;
  4186. TextRender.debugUV=false;
  4187. TextRender.atlasWidth2=2048 *2048;
  4188. TextRender.textRenderInst=null;
  4189. TextRender.simClean=false;
  4190. __static(TextRender,
  4191. ['tmpRI',function(){return this.tmpRI=new CharRenderInfo();},'pixelBBX',function(){return this.pixelBBX=[0,0,0,0];},'imgdtRect',function(){return this.imgdtRect=[0,0,0,0];}
  4192. ]);
  4193. return TextRender;
  4194. })()
  4195. //class laya.utils.PerfData
  4196. var PerfData=(function(){
  4197. function PerfData(id,color,name,scale){
  4198. this.id=0;
  4199. this.name=null;
  4200. this.color=0;
  4201. this.scale=1.0;
  4202. this.datapos=0;
  4203. this.datas=new Array(PerfHUD.DATANUM);
  4204. this.id=id;
  4205. this.color=color;
  4206. this.name=name;
  4207. this.scale=scale;
  4208. }
  4209. __class(PerfData,'laya.utils.PerfData');
  4210. var __proto=PerfData.prototype;
  4211. __proto.addData=function(v){
  4212. this.datas[this.datapos]=v;
  4213. this.datapos++;
  4214. this.datapos %=PerfHUD.DATANUM;
  4215. }
  4216. return PerfData;
  4217. })()
  4218. /**
  4219. *<p><code>KeyBoardManager</code> 是键盘事件管理类。该类从浏览器中接收键盘事件,并派发该事件。</p>
  4220. *<p>派发事件时若 Stage.focus 为空则只从 Stage 上派发该事件,否则将从 Stage.focus 对象开始一直冒泡派发该事件。所以在 Laya.stage 上监听键盘事件一定能够收到,如果在其他地方监听,则必须处在Stage.focus的冒泡链上才能收到该事件。</p>
  4221. *<p>用户可以通过代码 Laya.stage.focus=someNode 的方式来设置focus对象。</p>
  4222. *<p>用户可统一的根据事件对象中 e.keyCode 来判断按键类型,该属性兼容了不同浏览器的实现。</p>
  4223. */
  4224. //class laya.events.KeyBoardManager
  4225. var KeyBoardManager=(function(){
  4226. function KeyBoardManager(){}
  4227. __class(KeyBoardManager,'laya.events.KeyBoardManager');
  4228. KeyBoardManager.__init__=function(){
  4229. KeyBoardManager._addEvent("keydown");
  4230. KeyBoardManager._addEvent("keypress");
  4231. KeyBoardManager._addEvent("keyup");
  4232. }
  4233. KeyBoardManager._addEvent=function(type){
  4234. Browser.document.addEventListener(type,function(e){
  4235. laya.events.KeyBoardManager._dispatch(e,type);
  4236. },true);
  4237. }
  4238. KeyBoardManager._dispatch=function(e,type){
  4239. if (!KeyBoardManager.enabled)return;
  4240. KeyBoardManager._event._stoped=false;
  4241. KeyBoardManager._event.nativeEvent=e;
  4242. KeyBoardManager._event.keyCode=e.keyCode || e.which || e.charCode;
  4243. if (type==="keydown")KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode]=true;
  4244. else if (type==="keyup")KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode]=null;
  4245. var target=(Laya.stage.focus && (Laya.stage.focus.event !=null)&& Laya.stage.focus.displayedInStage)? Laya.stage.focus :Laya.stage;
  4246. var ct=target;
  4247. while (ct){
  4248. ct.event(type,KeyBoardManager._event.setTo(type,ct,target));
  4249. ct=ct.parent;
  4250. }
  4251. }
  4252. KeyBoardManager.hasKeyDown=function(key){
  4253. return KeyBoardManager._pressKeys[key];
  4254. }
  4255. KeyBoardManager._pressKeys={};
  4256. KeyBoardManager.enabled=true;
  4257. __static(KeyBoardManager,
  4258. ['_event',function(){return this._event=new Event();}
  4259. ]);
  4260. return KeyBoardManager;
  4261. })()
  4262. /**
  4263. *绘制Canvas贴图
  4264. *@private
  4265. */
  4266. //class laya.display.cmd.DrawCanvasCmd
  4267. var DrawCanvasCmd=(function(){
  4268. function DrawCanvasCmd(){
  4269. this._graphicsCmdEncoder=null;
  4270. this._index=0;
  4271. this._paramData=null;
  4272. /**
  4273. *绘图数据
  4274. */
  4275. this.texture=null;
  4276. /**
  4277. *绘制区域起始位置x
  4278. */
  4279. this.x=NaN;
  4280. /**
  4281. *绘制区域起始位置y
  4282. */
  4283. this.y=NaN;
  4284. /**
  4285. *绘制区域宽
  4286. */
  4287. this.width=NaN;
  4288. /**
  4289. *绘制区域高
  4290. */
  4291. this.height=NaN;
  4292. }
  4293. __class(DrawCanvasCmd,'laya.display.cmd.DrawCanvasCmd');
  4294. var __proto=DrawCanvasCmd.prototype;
  4295. /**
  4296. *回收到对象池
  4297. */
  4298. __proto.recover=function(){
  4299. this._graphicsCmdEncoder=null;
  4300. Pool.recover("DrawCanvasCmd",this);
  4301. }
  4302. /**@private */
  4303. __getset(0,__proto,'cmdID',function(){
  4304. return "DrawCanvasCmd";
  4305. });
  4306. DrawCanvasCmd.create=function(texture,x,y,width,height){
  4307. return null;
  4308. }
  4309. DrawCanvasCmd.ID="DrawCanvasCmd";
  4310. DrawCanvasCmd._DRAW_IMAGE_CMD_ENCODER_=null;
  4311. DrawCanvasCmd._PARAM_TEXTURE_POS_=2;
  4312. DrawCanvasCmd._PARAM_VB_POS_=5;
  4313. return DrawCanvasCmd;
  4314. })()
  4315. //class laya.webgl.shapes.Earcut
  4316. var Earcut=(function(){
  4317. function Earcut(){}
  4318. __class(Earcut,'laya.webgl.shapes.Earcut');
  4319. Earcut.earcut=function(data,holeIndices,dim){
  4320. dim=dim || 2;
  4321. var hasHoles=holeIndices && holeIndices.length,
  4322. outerLen=hasHoles ? holeIndices[0] *dim :data.length,
  4323. outerNode=Earcut.linkedList(data,0,outerLen,dim,true),
  4324. triangles=[];
  4325. if (!outerNode)return triangles;
  4326. var minX,minY,maxX,maxY,x,y,invSize;
  4327. if (hasHoles)outerNode=Earcut.eliminateHoles(data,holeIndices,outerNode,dim);
  4328. if (data.length > 80 *dim){
  4329. minX=maxX=data[0];
  4330. minY=maxY=data[1];
  4331. for (var i=dim;i < outerLen;i+=dim){
  4332. x=data[i];
  4333. y=data[i+1];
  4334. if (x < minX)minX=x;
  4335. if (y < minY)minY=y;
  4336. if (x > maxX)maxX=x;
  4337. if (y > maxY)maxY=y;
  4338. }
  4339. invSize=Math.max(maxX-minX,maxY-minY);
  4340. invSize=invSize!==0 ? 1 / invSize :0;
  4341. }
  4342. Earcut.earcutLinked(outerNode,triangles,dim,minX,minY,invSize);
  4343. return triangles;
  4344. }
  4345. Earcut.linkedList=function(data,start,end,dim,clockwise){
  4346. var i,last;
  4347. if (clockwise===(Earcut.signedArea(data,start,end,dim)> 0)){
  4348. for (i=start;i < end;i+=dim)last=Earcut.insertNode(i,data[i],data[i+1],last);
  4349. }else {
  4350. for (i=end-dim;i >=start;i-=dim)last=Earcut.insertNode(i,data[i],data[i+1],last);
  4351. }
  4352. if (last && Earcut.equals(last,last.next)){
  4353. Earcut.removeNode(last);
  4354. last=last.next;
  4355. }
  4356. return last;
  4357. }
  4358. Earcut.filterPoints=function(start,end){
  4359. if (!start)return start;
  4360. if (!end)end=start;
  4361. var p=start,
  4362. again;
  4363. do {
  4364. again=false;
  4365. if (!p.steiner && (Earcut.equals(p,p.next)|| Earcut.area(p.prev,p,p.next)===0)){
  4366. Earcut.removeNode(p);
  4367. p=end=p.prev;
  4368. if (p===p.next)break ;
  4369. again=true;
  4370. }else {
  4371. p=p.next;
  4372. }
  4373. }while (again || p!==end);
  4374. return end;
  4375. }
  4376. Earcut.earcutLinked=function(ear,triangles,dim,minX,minY,invSize,pass){
  4377. if (!ear)return;
  4378. if (!pass && invSize)Earcut.indexCurve(ear,minX,minY,invSize);
  4379. var stop=ear,
  4380. prev,next;
  4381. while (ear.prev!==ear.next){
  4382. prev=ear.prev;
  4383. next=ear.next;
  4384. if (invSize ? Earcut.isEarHashed(ear,minX,minY,invSize):Earcut.isEar(ear)){
  4385. triangles.push(prev.i / dim);
  4386. triangles.push(ear.i / dim);
  4387. triangles.push(next.i / dim);
  4388. Earcut.removeNode(ear);
  4389. ear=next.next;
  4390. stop=next.next;
  4391. continue ;
  4392. }
  4393. ear=next;
  4394. if (ear===stop){
  4395. if (!pass){
  4396. Earcut.earcutLinked(Earcut.filterPoints(ear,null),triangles,dim,minX,minY,invSize,1);
  4397. }else if (pass===1){
  4398. ear=Earcut.cureLocalIntersections(ear,triangles,dim);
  4399. Earcut.earcutLinked(ear,triangles,dim,minX,minY,invSize,2);
  4400. }else if (pass===2){
  4401. Earcut.splitEarcut(ear,triangles,dim,minX,minY,invSize);
  4402. }
  4403. break ;
  4404. }
  4405. }
  4406. }
  4407. Earcut.isEar=function(ear){
  4408. var a=ear.prev,
  4409. b=ear,
  4410. c=ear.next;
  4411. if (Earcut.area(a,b,c)>=0)return false;
  4412. var p=ear.next.next;
  4413. while (p!==ear.prev){
  4414. if (Earcut.pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&
  4415. Earcut.area(p.prev,p,p.next)>=0)return false;
  4416. p=p.next;
  4417. }
  4418. return true;
  4419. }
  4420. Earcut.isEarHashed=function(ear,minX,minY,invSize){
  4421. var a=ear.prev,
  4422. b=ear,
  4423. c=ear.next;
  4424. if (Earcut.area(a,b,c)>=0)return false;
  4425. var minTX=a.x < b.x ? (a.x < c.x ? a.x :c.x):(b.x < c.x ? b.x :c.x),
  4426. minTY=a.y < b.y ? (a.y < c.y ? a.y :c.y):(b.y < c.y ? b.y :c.y),
  4427. maxTX=a.x > b.x ? (a.x > c.x ? a.x :c.x):(b.x > c.x ? b.x :c.x),
  4428. maxTY=a.y > b.y ? (a.y > c.y ? a.y :c.y):(b.y > c.y ? b.y :c.y);
  4429. var minZ=Earcut.zOrder(minTX,minTY,minX,minY,invSize),
  4430. maxZ=Earcut.zOrder(maxTX,maxTY,minX,minY,invSize);
  4431. var p=ear.nextZ;
  4432. while (p && p.z <=maxZ){
  4433. if (p!==ear.prev && p!==ear.next &&
  4434. Earcut.pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&
  4435. Earcut.area(p.prev,p,p.next)>=0)return false;
  4436. p=p.nextZ;
  4437. }
  4438. p=ear.prevZ;
  4439. while (p && p.z >=minZ){
  4440. if (p!==ear.prev && p!==ear.next &&
  4441. Earcut.pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&
  4442. Earcut.area(p.prev,p,p.next)>=0)return false;
  4443. p=p.prevZ;
  4444. }
  4445. return true;
  4446. }
  4447. Earcut.cureLocalIntersections=function(start,triangles,dim){
  4448. var p=start;
  4449. do {
  4450. var a=p.prev,
  4451. b=p.next.next;
  4452. if (!Earcut.equals(a,b)&& Earcut.intersects(a,p,p.next,b)&& Earcut.locallyInside(a,b)&& Earcut.locallyInside(b,a)){
  4453. triangles.push(a.i / dim);
  4454. triangles.push(p.i / dim);
  4455. triangles.push(b.i / dim);
  4456. Earcut.removeNode(p);
  4457. Earcut.removeNode(p.next);
  4458. p=start=b;
  4459. }
  4460. p=p.next;
  4461. }while (p!==start);
  4462. return p;
  4463. }
  4464. Earcut.splitEarcut=function(start,triangles,dim,minX,minY,invSize){
  4465. var a=start;
  4466. do {
  4467. var b=a.next.next;
  4468. while (b!==a.prev){
  4469. if (a.i!==b.i && Earcut.isValidDiagonal(a,b)){
  4470. var c=Earcut.splitPolygon(a,b);
  4471. a=Earcut.filterPoints(a,a.next);
  4472. c=Earcut.filterPoints(c,c.next);
  4473. Earcut.earcutLinked(a,triangles,dim,minX,minY,invSize);
  4474. Earcut.earcutLinked(c,triangles,dim,minX,minY,invSize);
  4475. return;
  4476. }
  4477. b=b.next;
  4478. }
  4479. a=a.next;
  4480. }while (a!==start);
  4481. }
  4482. Earcut.eliminateHoles=function(data,holeIndices,outerNode,dim){
  4483. var queue=[],
  4484. i,len,start,end,list;
  4485. for (i=0,len=holeIndices.length;i < len;i++){
  4486. start=holeIndices[i] *dim;
  4487. end=i < len-1 ? holeIndices[i+1] *dim :data.length;
  4488. list=Earcut.linkedList(data,start,end,dim,false);
  4489. if (list===list.next)list.steiner=true;
  4490. queue.push(Earcut.getLeftmost(list));
  4491. }
  4492. queue.sort(Earcut.compareX);
  4493. for (i=0;i < queue.length;i++){
  4494. Earcut.eliminateHole(queue[i],outerNode);
  4495. outerNode=Earcut.filterPoints(outerNode,outerNode.next);
  4496. }
  4497. return outerNode;
  4498. }
  4499. Earcut.compareX=function(a,b){
  4500. return a.x-b.x;
  4501. }
  4502. Earcut.eliminateHole=function(hole,outerNode){
  4503. outerNode=Earcut.findHoleBridge(hole,outerNode);
  4504. if (outerNode){
  4505. var b=Earcut.splitPolygon(outerNode,hole);
  4506. Earcut.filterPoints(b,b.next);
  4507. }
  4508. }
  4509. Earcut.findHoleBridge=function(hole,outerNode){
  4510. var p=outerNode,
  4511. hx=hole.x,
  4512. hy=hole.y,
  4513. qx=-Infinity,
  4514. m;
  4515. do {
  4516. if (hy <=p.y && hy >=p.next.y && p.next.y!==p.y){
  4517. var x=p.x+(hy-p.y)*(p.next.x-p.x)/ (p.next.y-p.y);
  4518. if (x <=hx && x > qx){
  4519. qx=x;
  4520. if (x===hx){
  4521. if (hy===p.y)return p;
  4522. if (hy===p.next.y)return p.next;
  4523. }
  4524. m=p.x < p.next.x ? p :p.next;
  4525. }
  4526. }
  4527. p=p.next;
  4528. }while (p!==outerNode);
  4529. if (!m)return null;
  4530. if (hx===qx)return m.prev;
  4531. var stop=m,
  4532. mx=m.x,
  4533. my=m.y,
  4534. tanMin=Infinity,
  4535. tan;
  4536. p=m.next;
  4537. while (p!==stop){
  4538. if (hx >=p.x && p.x >=mx && hx!==p.x &&
  4539. Earcut.pointInTriangle(hy < my ? hx :qx,hy,mx,my,hy < my ? qx :hx,hy,p.x,p.y)){
  4540. tan=Math.abs(hy-p.y)/ (hx-p.x);
  4541. if ((tan < tanMin || (tan===tanMin && p.x > m.x))&& Earcut.locallyInside(p,hole)){
  4542. m=p;
  4543. tanMin=tan;
  4544. }
  4545. }
  4546. p=p.next;
  4547. }
  4548. return m;
  4549. }
  4550. Earcut.indexCurve=function(start,minX,minY,invSize){
  4551. var p=start;
  4552. do {
  4553. if (p.z===null)p.z=Earcut.zOrder(p.x,p.y,minX,minY,invSize);
  4554. p.prevZ=p.prev;
  4555. p.nextZ=p.next;
  4556. p=p.next;
  4557. }while (p!==start);
  4558. p.prevZ.nextZ=null;
  4559. p.prevZ=null;
  4560. Earcut.sortLinked(p);
  4561. }
  4562. Earcut.sortLinked=function(list){
  4563. var i,p,q,e,tail,numMerges,pSize,qSize,
  4564. inSize=1;
  4565. do {
  4566. p=list;
  4567. list=null;
  4568. tail=null;
  4569. numMerges=0;
  4570. while (p){
  4571. numMerges++;
  4572. q=p;
  4573. pSize=0;
  4574. for (i=0;i < inSize;i++){
  4575. pSize++;
  4576. q=q.nextZ;
  4577. if (!q)break ;
  4578. }
  4579. qSize=inSize;
  4580. while (pSize > 0 || (qSize > 0 && q)){
  4581. if (pSize!==0 && (qSize===0 || !q || p.z <=q.z)){
  4582. e=p;
  4583. p=p.nextZ;
  4584. pSize--;
  4585. }else {
  4586. e=q;
  4587. q=q.nextZ;
  4588. qSize--;
  4589. }
  4590. if (tail)tail.nextZ=e;
  4591. else list=e;
  4592. e.prevZ=tail;
  4593. tail=e;
  4594. }
  4595. p=q;
  4596. }
  4597. tail.nextZ=null;
  4598. inSize *=2;
  4599. }while (numMerges > 1);
  4600. return list;
  4601. }
  4602. Earcut.zOrder=function(x,y,minX,minY,invSize){
  4603. x=32767 *(x-minX)*invSize;
  4604. y=32767 *(y-minY)*invSize;
  4605. x=(x | (x << 8))& 0x00FF00FF;
  4606. x=(x | (x << 4))& 0x0F0F0F0F;
  4607. x=(x | (x << 2))& 0x33333333;
  4608. x=(x | (x << 1))& 0x55555555;
  4609. y=(y | (y << 8))& 0x00FF00FF;
  4610. y=(y | (y << 4))& 0x0F0F0F0F;
  4611. y=(y | (y << 2))& 0x33333333;
  4612. y=(y | (y << 1))& 0x55555555;
  4613. return x | (y << 1);
  4614. }
  4615. Earcut.getLeftmost=function(start){
  4616. var p=start,
  4617. leftmost=start;
  4618. do {
  4619. if (p.x < leftmost.x)leftmost=p;
  4620. p=p.next;
  4621. }while (p!==start);
  4622. return leftmost;
  4623. }
  4624. Earcut.pointInTriangle=function(ax,ay,bx,by,cx,cy,px,py){
  4625. return (cx-px)*(ay-py)-(ax-px)*(cy-py)>=0 &&
  4626. (ax-px)*(by-py)-(bx-px)*(ay-py)>=0 &&
  4627. (bx-px)*(cy-py)-(cx-px)*(by-py)>=0;
  4628. }
  4629. Earcut.isValidDiagonal=function(a,b){
  4630. return a.next.i!==b.i && a.prev.i!==b.i && !Earcut.intersectsPolygon(a,b)&&
  4631. Earcut.locallyInside(a,b)&& Earcut.locallyInside(b,a)&& Earcut.middleInside(a,b);
  4632. }
  4633. Earcut.area=function(p,q,r){
  4634. return (q.y-p.y)*(r.x-q.x)-(q.x-p.x)*(r.y-q.y);
  4635. }
  4636. Earcut.equals=function(p1,p2){
  4637. return p1.x===p2.x && p1.y===p2.y;
  4638. }
  4639. Earcut.intersects=function(p1,q1,p2,q2){
  4640. if ((Earcut.equals(p1,q1)&& Earcut.equals(p2,q2))||
  4641. (Earcut.equals(p1,q2)&& Earcut.equals(p2,q1)))return true;
  4642. return Earcut.area(p1,q1,p2)> 0!==Earcut.area(p1,q1,q2)> 0 &&
  4643. Earcut.area(p2,q2,p1)> 0!==Earcut.area(p2,q2,q1)> 0;
  4644. }
  4645. Earcut.intersectsPolygon=function(a,b){
  4646. var p=a;
  4647. do {
  4648. if (p.i!==a.i && p.next.i!==a.i && p.i!==b.i && p.next.i!==b.i &&
  4649. Earcut.intersects(p,p.next,a,b))return true;
  4650. p=p.next;
  4651. }while (p!==a);
  4652. return false;
  4653. }
  4654. Earcut.locallyInside=function(a,b){
  4655. return Earcut.area(a.prev,a,a.next)< 0 ?
  4656. Earcut.area(a,b,a.next)>=0 && Earcut.area(a,a.prev,b)>=0 :
  4657. Earcut.area(a,b,a.prev)< 0 || Earcut.area(a,a.next,b)< 0;
  4658. }
  4659. Earcut.middleInside=function(a,b){
  4660. var p=a,
  4661. inside=false,
  4662. px=(a.x+b.x)/ 2,
  4663. py=(a.y+b.y)/ 2;
  4664. do {
  4665. if (((p.y > py)!==(p.next.y > py))&& p.next.y!==p.y &&
  4666. (px < (p.next.x-p.x)*(py-p.y)/ (p.next.y-p.y)+p.x))
  4667. inside=!inside;
  4668. p=p.next;
  4669. }while (p!==a);
  4670. return inside;
  4671. }
  4672. Earcut.splitPolygon=function(a,b){
  4673. var a2=new EarcutNode(a.i,a.x,a.y),
  4674. b2=new EarcutNode(b.i,b.x,b.y),
  4675. an=a.next,
  4676. bp=b.prev;
  4677. a.next=b;
  4678. b.prev=a;
  4679. a2.next=an;
  4680. an.prev=a2;
  4681. b2.next=a2;
  4682. a2.prev=b2;
  4683. bp.next=b2;
  4684. b2.prev=bp;
  4685. return b2;
  4686. }
  4687. Earcut.insertNode=function(i,x,y,last){
  4688. var p=new EarcutNode(i,x,y);
  4689. if (!last){
  4690. p.prev=p;
  4691. p.next=p;
  4692. }else {
  4693. p.next=last.next;
  4694. p.prev=last;
  4695. last.next.prev=p;
  4696. last.next=p;
  4697. }
  4698. return p;
  4699. }
  4700. Earcut.removeNode=function(p){
  4701. p.next.prev=p.prev;
  4702. p.prev.next=p.next;
  4703. if (p.prevZ)p.prevZ.nextZ=p.nextZ;
  4704. if (p.nextZ)p.nextZ.prevZ=p.prevZ;
  4705. }
  4706. Earcut.signedArea=function(data,start,end,dim){
  4707. var sum=0;
  4708. for (var i=start,j=end-dim;i < end;i+=dim){
  4709. sum+=(data[j]-data[i])*(data[i+1]+data[j+1]);
  4710. j=i;
  4711. }
  4712. return sum;
  4713. }
  4714. return Earcut;
  4715. })()
  4716. /**
  4717. *@private
  4718. *Graphic bounds数据类
  4719. */
  4720. //class laya.display.css.BoundsStyle
  4721. var BoundsStyle=(function(){
  4722. function BoundsStyle(){
  4723. /**@private */
  4724. //this.bounds=null;
  4725. /**用户设的bounds*/
  4726. //this.userBounds=null;
  4727. /**缓存的bounds顶点,sprite计算bounds用*/
  4728. //this.temBM=null;
  4729. }
  4730. __class(BoundsStyle,'laya.display.css.BoundsStyle');
  4731. var __proto=BoundsStyle.prototype;
  4732. /**
  4733. *重置
  4734. */
  4735. __proto.reset=function(){
  4736. if(this.bounds)this.bounds.recover();
  4737. if(this.userBounds)this.userBounds.recover();
  4738. this.bounds=null;
  4739. this.userBounds=null;
  4740. this.temBM=null;
  4741. return this;
  4742. }
  4743. /**
  4744. *回收
  4745. */
  4746. __proto.recover=function(){
  4747. Pool.recover("BoundsStyle",this.reset());
  4748. }
  4749. BoundsStyle.create=function(){
  4750. return Pool.getItemByClass("BoundsStyle",BoundsStyle);
  4751. }
  4752. return BoundsStyle;
  4753. })()
  4754. /**
  4755. *<code>Keyboard</code> 类的属性是一些常数,这些常数表示控制游戏时最常用的键。
  4756. */
  4757. //class laya.events.Keyboard
  4758. var Keyboard=(function(){
  4759. function Keyboard(){}
  4760. __class(Keyboard,'laya.events.Keyboard');
  4761. Keyboard.NUMBER_0=48;
  4762. Keyboard.NUMBER_1=49;
  4763. Keyboard.NUMBER_2=50;
  4764. Keyboard.NUMBER_3=51;
  4765. Keyboard.NUMBER_4=52;
  4766. Keyboard.NUMBER_5=53;
  4767. Keyboard.NUMBER_6=54;
  4768. Keyboard.NUMBER_7=55;
  4769. Keyboard.NUMBER_8=56;
  4770. Keyboard.NUMBER_9=57;
  4771. Keyboard.A=65;
  4772. Keyboard.B=66;
  4773. Keyboard.C=67;
  4774. Keyboard.D=68;
  4775. Keyboard.E=69;
  4776. Keyboard.F=70;
  4777. Keyboard.G=71;
  4778. Keyboard.H=72;
  4779. Keyboard.I=73;
  4780. Keyboard.J=74;
  4781. Keyboard.K=75;
  4782. Keyboard.L=76;
  4783. Keyboard.M=77;
  4784. Keyboard.N=78;
  4785. Keyboard.O=79;
  4786. Keyboard.P=80;
  4787. Keyboard.Q=81;
  4788. Keyboard.R=82;
  4789. Keyboard.S=83;
  4790. Keyboard.T=84;
  4791. Keyboard.U=85;
  4792. Keyboard.V=86;
  4793. Keyboard.W=87;
  4794. Keyboard.X=88;
  4795. Keyboard.Y=89;
  4796. Keyboard.Z=90;
  4797. Keyboard.F1=112;
  4798. Keyboard.F2=113;
  4799. Keyboard.F3=114;
  4800. Keyboard.F4=115;
  4801. Keyboard.F5=116;
  4802. Keyboard.F6=117;
  4803. Keyboard.F7=118;
  4804. Keyboard.F8=119;
  4805. Keyboard.F9=120;
  4806. Keyboard.F10=121;
  4807. Keyboard.F11=122;
  4808. Keyboard.F12=123;
  4809. Keyboard.F13=124;
  4810. Keyboard.F14=125;
  4811. Keyboard.F15=126;
  4812. Keyboard.NUMPAD=21;
  4813. Keyboard.NUMPAD_0=96;
  4814. Keyboard.NUMPAD_1=97;
  4815. Keyboard.NUMPAD_2=98;
  4816. Keyboard.NUMPAD_3=99;
  4817. Keyboard.NUMPAD_4=100;
  4818. Keyboard.NUMPAD_5=101;
  4819. Keyboard.NUMPAD_6=102;
  4820. Keyboard.NUMPAD_7=103;
  4821. Keyboard.NUMPAD_8=104;
  4822. Keyboard.NUMPAD_9=105;
  4823. Keyboard.NUMPAD_ADD=107;
  4824. Keyboard.NUMPAD_DECIMAL=110;
  4825. Keyboard.NUMPAD_DIVIDE=111;
  4826. Keyboard.NUMPAD_ENTER=108;
  4827. Keyboard.NUMPAD_MULTIPLY=106;
  4828. Keyboard.NUMPAD_SUBTRACT=109;
  4829. Keyboard.SEMICOLON=186;
  4830. Keyboard.EQUAL=187;
  4831. Keyboard.COMMA=188;
  4832. Keyboard.MINUS=189;
  4833. Keyboard.PERIOD=190;
  4834. Keyboard.SLASH=191;
  4835. Keyboard.BACKQUOTE=192;
  4836. Keyboard.LEFTBRACKET=219;
  4837. Keyboard.BACKSLASH=220;
  4838. Keyboard.RIGHTBRACKET=221;
  4839. Keyboard.QUOTE=222;
  4840. Keyboard.ALTERNATE=18;
  4841. Keyboard.BACKSPACE=8;
  4842. Keyboard.CAPS_LOCK=20;
  4843. Keyboard.COMMAND=15;
  4844. Keyboard.CONTROL=17;
  4845. Keyboard.DELETE=46;
  4846. Keyboard.ENTER=13;
  4847. Keyboard.ESCAPE=27;
  4848. Keyboard.PAGE_UP=33;
  4849. Keyboard.PAGE_DOWN=34;
  4850. Keyboard.END=35;
  4851. Keyboard.HOME=36;
  4852. Keyboard.LEFT=37;
  4853. Keyboard.UP=38;
  4854. Keyboard.RIGHT=39;
  4855. Keyboard.DOWN=40;
  4856. Keyboard.SHIFT=16;
  4857. Keyboard.SPACE=32;
  4858. Keyboard.TAB=9;
  4859. Keyboard.INSERT=45;
  4860. return Keyboard;
  4861. })()
  4862. /**
  4863. *@private
  4864. */
  4865. //class laya.system.System
  4866. var System=(function(){
  4867. function System(){}
  4868. __class(System,'laya.system.System');
  4869. System.changeDefinition=function(name,classObj){
  4870. Laya[name]=classObj;
  4871. var str=name+"=classObj";
  4872. Laya._runScript(str);
  4873. }
  4874. System.__init__=function(){}
  4875. return System;
  4876. })()
  4877. //class laya.webgl.shader.d2.Shader2D
  4878. var Shader2D=(function(){
  4879. function Shader2D(){
  4880. this.ALPHA=1;
  4881. //this.shader=null;
  4882. //this.filters=null;
  4883. this.shaderType=0;
  4884. //this.colorAdd=null;
  4885. this.defines=new ShaderDefines2D();
  4886. this.fillStyle=DrawStyle.DEFAULT;
  4887. this.strokeStyle=DrawStyle.DEFAULT;
  4888. }
  4889. __class(Shader2D,'laya.webgl.shader.d2.Shader2D');
  4890. var __proto=Shader2D.prototype;
  4891. __proto.destroy=function(){
  4892. this.defines=null;
  4893. this.filters=null;
  4894. }
  4895. Shader2D.__init__=function(){
  4896. var vs,ps;
  4897. vs="/*\n texture和fillrect使用的。\n*/\nattribute vec4 posuv;\nattribute vec4 attribColor;\nattribute vec4 attribFlags;\n//attribute vec4 clipDir;\n//attribute vec2 clipRect;\nuniform vec4 clipMatDir;\nuniform vec2 clipMatPos; // 这个是全局的,不用再应用矩阵了。\nvarying vec2 cliped;\nuniform vec2 size;\nuniform vec2 clipOff; // 使用要把clip偏移。cacheas normal用. 只用了[0]\n#ifdef WORLDMAT\n uniform mat4 mmat;\n#endif\n#ifdef MVP3D\n uniform mat4 u_MvpMatrix;\n#endif\nvarying vec4 v_texcoordAlpha;\nvarying vec4 v_color;\nvarying float v_useTex;\n\nvoid main() {\n\n vec4 pos = vec4(posuv.xy,0.,1.);\n#ifdef WORLDMAT\n pos=mmat*pos;\n#endif\n vec4 pos1 =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,0.,1.0);\n#ifdef MVP3D\n gl_Position=u_MvpMatrix*pos1;\n#else\n gl_Position=pos1;\n#endif\n v_texcoordAlpha.xy = posuv.zw;\n //v_texcoordAlpha.z = attribColor.a/255.0;\n v_color = attribColor/255.0;\n v_color.xyz*=v_color.w;//反正后面也要预乘\n \n v_useTex = attribFlags.r/255.0;\n float clipw = length(clipMatDir.xy);\n float cliph = length(clipMatDir.zw);\n \n vec2 clpos = clipMatPos.xy;\n #ifdef WORLDMAT\n // 如果有mmat,需要修改clipMatPos,因为 这是cacheas normal (如果不是就错了), clipMatPos被去掉了偏移\n if(clipOff[0]>0.0){\n clpos.x+=mmat[3].x; //tx 最简单处理\n clpos.y+=mmat[3].y; //ty\n }\n #endif\n vec2 clippos = pos.xy - clpos; //pos已经应用矩阵了,为了减的有意义,clip的位置也要缩放\n if(clipw>20000. && cliph>20000.)\n cliped = vec2(0.5,0.5);\n else {\n //转成0到1之间。/clipw/clipw 表示clippos与normalize之后的clip朝向点积之后,再除以clipw\n cliped=vec2( dot(clippos,clipMatDir.xy)/clipw/clipw, dot(clippos,clipMatDir.zw)/cliph/cliph);\n }\n\n}";
  4898. ps="/*\n texture和fillrect使用的。\n*/\n#ifdef FSHIGHPRECISION\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n\nvarying vec4 v_texcoordAlpha;\nvarying vec4 v_color;\nvarying float v_useTex;\nuniform sampler2D texture;\nvarying vec2 cliped;\n\n#ifdef BLUR_FILTER\nuniform vec4 strength_sig2_2sig2_gauss1;\nuniform vec2 blurInfo;\n\n#define PI 3.141593\n\nfloat getGaussian(float x, float y){\n return strength_sig2_2sig2_gauss1.w*exp(-(x*x+y*y)/strength_sig2_2sig2_gauss1.z);\n}\n\nvec4 blur(){\n const float blurw = 9.0;\n vec4 vec4Color = vec4(0.0,0.0,0.0,0.0);\n vec2 halfsz=vec2(blurw,blurw)/2.0/blurInfo; \n vec2 startpos=v_texcoordAlpha.xy-halfsz;\n vec2 ctexcoord = startpos;\n vec2 step = 1.0/blurInfo; //每个像素 \n \n for(float y = 0.0;y<=blurw; ++y){\n ctexcoord.x=startpos.x;\n for(float x = 0.0;x<=blurw; ++x){\n //TODO 纹理坐标的固定偏移应该在vs中处理\n vec4Color += texture2D(texture, ctexcoord)*getGaussian(x-blurw/2.0,y-blurw/2.0);\n ctexcoord.x+=step.x;\n }\n ctexcoord.y+=step.y;\n }\n return vec4Color;\n}\n#endif\n\n#ifdef COLOR_FILTER\nuniform vec4 colorAlpha;\nuniform mat4 colorMat;\n#endif\n\n#ifdef GLOW_FILTER\nuniform vec4 u_color;\nuniform vec4 u_blurInfo1;\nuniform vec4 u_blurInfo2;\n#endif\n\n#ifdef COLOR_ADD\nuniform vec4 colorAdd;\n#endif\n\n#ifdef FILLTEXTURE \nuniform vec4 u_TexRange;//startu,startv,urange, vrange\n#endif\nvoid main() {\n if(cliped.x<0.) discard;\n if(cliped.x>1.) discard;\n if(cliped.y<0.) discard;\n if(cliped.y>1.) discard;\n \n#ifdef FILLTEXTURE \n vec4 color= texture2D(texture, fract(v_texcoordAlpha.xy)*u_TexRange.zw + u_TexRange.xy);\n#else\n vec4 color= texture2D(texture, v_texcoordAlpha.xy);\n#endif\n\n if(v_useTex<=0.)color = vec4(1.,1.,1.,1.);\n color.a*=v_color.w;\n //color.rgb*=v_color.w;\n color.rgb*=v_color.rgb;\n gl_FragColor=color;\n \n #ifdef COLOR_ADD\n gl_FragColor = vec4(colorAdd.rgb,colorAdd.a*gl_FragColor.a);\n gl_FragColor.xyz *= colorAdd.a;\n #endif\n \n #ifdef BLUR_FILTER\n gl_FragColor = blur();\n gl_FragColor.w*=v_color.w; \n #endif\n \n #ifdef COLOR_FILTER\n mat4 alphaMat =colorMat;\n\n alphaMat[0][3] *= gl_FragColor.a;\n alphaMat[1][3] *= gl_FragColor.a;\n alphaMat[2][3] *= gl_FragColor.a;\n\n gl_FragColor = gl_FragColor * alphaMat;\n gl_FragColor += colorAlpha/255.0*gl_FragColor.a;\n #endif\n \n #ifdef GLOW_FILTER\n const float c_IterationTime = 10.0;\n float floatIterationTotalTime = c_IterationTime * c_IterationTime;\n vec4 vec4Color = vec4(0.0,0.0,0.0,0.0);\n vec2 vec2FilterDir = vec2(-(u_blurInfo1.z)/u_blurInfo2.x,-(u_blurInfo1.w)/u_blurInfo2.y);\n vec2 vec2FilterOff = vec2(u_blurInfo1.x/u_blurInfo2.x/c_IterationTime * 2.0,u_blurInfo1.y/u_blurInfo2.y/c_IterationTime * 2.0);\n float maxNum = u_blurInfo1.x * u_blurInfo1.y;\n vec2 vec2Off = vec2(0.0,0.0);\n float floatOff = c_IterationTime/2.0;\n for(float i = 0.0;i<=c_IterationTime; ++i){\n for(float j = 0.0;j<=c_IterationTime; ++j){\n vec2Off = vec2(vec2FilterOff.x * (i - floatOff),vec2FilterOff.y * (j - floatOff));\n vec4Color += texture2D(texture, v_texcoordAlpha.xy + vec2FilterDir + vec2Off)/floatIterationTotalTime;\n }\n }\n gl_FragColor = vec4(u_color.rgb,vec4Color.a * u_blurInfo2.z);\n gl_FragColor.rgb *= gl_FragColor.a; \n #endif\n \n}";
  4899. Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,vs,ps,null);
  4900. vs="attribute vec4 position;\nattribute vec4 attribColor;\n//attribute vec4 clipDir;\n//attribute vec2 clipRect;\nuniform vec4 clipMatDir;\nuniform vec2 clipMatPos;\n#ifdef WORLDMAT\n uniform mat4 mmat;\n#endif\nuniform mat4 u_mmat2;\n//uniform vec2 u_pos;\nuniform vec2 size;\nvarying vec4 color;\n//vec4 dirxy=vec4(0.9,0.1, -0.1,0.9);\n//vec4 clip=vec4(100.,30.,300.,600.);\nvarying vec2 cliped;\nvoid main(){\n \n#ifdef WORLDMAT\n vec4 pos=mmat*vec4(position.xy,0.,1.);\n gl_Position =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\n#else\n gl_Position =vec4((position.x/size.x-0.5)*2.0,(0.5-position.y/size.y)*2.0,position.z,1.0);\n#endif \n float clipw = length(clipMatDir.xy);\n float cliph = length(clipMatDir.zw);\n vec2 clippos = position.xy - clipMatPos.xy; //pos已经应用矩阵了,为了减的有意义,clip的位置也要缩放\n if(clipw>20000. && cliph>20000.)\n cliped = vec2(0.5,0.5);\n else {\n //clipdir是带缩放的方向,由于上面clippos是在缩放后的空间计算的,所以需要把方向先normalize一下\n cliped=vec2( dot(clippos,clipMatDir.xy)/clipw/clipw, dot(clippos,clipMatDir.zw)/cliph/cliph);\n }\n //pos2d.x = dot(clippos,dirx);\n color=attribColor/255.;\n}";
  4901. ps="precision mediump float;\n//precision mediump float;\nvarying vec4 color;\n//uniform float alpha;\nvarying vec2 cliped;\nvoid main(){\n //vec4 a=vec4(color.r, color.g, color.b, 1);\n //a.a*=alpha;\n gl_FragColor= color;// vec4(color.r, color.g, color.b, alpha);\n gl_FragColor.rgb*=color.a;\n if(cliped.x<0.) discard;\n if(cliped.x>1.) discard;\n if(cliped.y<0.) discard;\n if(cliped.y>1.) discard;\n}";
  4902. Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.PRIMITIVE*/0x04,vs,ps,null);
  4903. vs="attribute vec2 position;\nattribute vec2 texcoord;\nattribute vec4 color;\nuniform vec2 size;\nuniform float offsetX;\nuniform float offsetY;\nuniform mat4 mmat;\nuniform mat4 u_mmat2;\nvarying vec2 v_texcoord;\nvarying vec4 v_color;\nvoid main() {\n vec4 pos=mmat*u_mmat2*vec4(offsetX+position.x,offsetY+position.y,0,1 );\n gl_Position = vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\n v_color = color;\n v_color.rgb *= v_color.a;\n v_texcoord = texcoord; \n}";
  4904. ps="precision mediump float;\nvarying vec2 v_texcoord;\nvarying vec4 v_color;\nuniform sampler2D texture;\nuniform float alpha;\nvoid main() {\n vec4 t_color = texture2D(texture, v_texcoord);\n gl_FragColor = t_color.rgba * v_color;\n gl_FragColor *= alpha;\n}";
  4905. Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.SKINMESH*/0x200,vs,ps,null);
  4906. }
  4907. return Shader2D;
  4908. })()
  4909. //class laya.webgl.canvas.DrawStyle
  4910. var DrawStyle=(function(){
  4911. function DrawStyle(value){
  4912. this._color=null;
  4913. this.setValue(value);
  4914. }
  4915. __class(DrawStyle,'laya.webgl.canvas.DrawStyle');
  4916. var __proto=DrawStyle.prototype;
  4917. __proto.setValue=function(value){
  4918. if (value){
  4919. this._color=((value instanceof laya.utils.ColorUtils ))?(value):ColorUtils.create(value);
  4920. }
  4921. else this._color=ColorUtils.create("#000000");
  4922. }
  4923. __proto.reset=function(){
  4924. this._color=ColorUtils.create("#000000");
  4925. }
  4926. __proto.toInt=function(){
  4927. return this._color.numColor;
  4928. }
  4929. __proto.equal=function(value){
  4930. if ((typeof value=='string'))return this._color.strColor===value;
  4931. if ((value instanceof laya.utils.ColorUtils ))return this._color.numColor===(value).numColor;
  4932. return false;
  4933. }
  4934. __proto.toColorStr=function(){
  4935. return this._color.strColor;
  4936. }
  4937. DrawStyle.create=function(value){
  4938. if (value){
  4939. var color=((value instanceof laya.utils.ColorUtils ))?(value):ColorUtils.create(value);
  4940. return color._drawStyle || (color._drawStyle=new DrawStyle(value));
  4941. }
  4942. return DrawStyle.DEFAULT;
  4943. }
  4944. __static(DrawStyle,
  4945. ['DEFAULT',function(){return this.DEFAULT=new DrawStyle("#000000");}
  4946. ]);
  4947. return DrawStyle;
  4948. })()
  4949. //class laya.webgl.text.ICharRender
  4950. var ICharRender=(function(){
  4951. function ICharRender(){}
  4952. __class(ICharRender,'laya.webgl.text.ICharRender');
  4953. var __proto=ICharRender.prototype;
  4954. __proto.getWidth=function(font,str){return 0;}
  4955. __proto.scale=function(sx,sy){}
  4956. /**
  4957. *TODO stroke
  4958. *@param char
  4959. *@param font
  4960. *@param size 返回宽高
  4961. *@return
  4962. */
  4963. __proto.getCharBmp=function(char,font,lineWidth,colStr,strokeColStr,size,margin_left,margin_top,margin_right,margin_bottom,rect){
  4964. return null;
  4965. }
  4966. __getset(0,__proto,'canvasWidth',function(){
  4967. return 0;
  4968. },function(w){
  4969. });
  4970. return ICharRender;
  4971. })()
  4972. /**
  4973. *<p> <code>Matrix</code> 类表示一个转换矩阵,它确定如何将点从一个坐标空间映射到另一个坐标空间。</p>
  4974. *<p>您可以对一个显示对象执行不同的图形转换,方法是设置 Matrix 对象的属性,将该 Matrix 对象应用于 Transform 对象的 matrix 属性,然后应用该 Transform 对象作为显示对象的 transform 属性。这些转换函数包括平移(x 和 y 重新定位)、旋转、缩放和倾斜。</p>
  4975. */
  4976. //class laya.maths.Matrix
  4977. var Matrix=(function(){
  4978. function Matrix(a,b,c,d,tx,ty,nums){
  4979. /**缩放或旋转图像时影响像素沿 x 轴定位的值。*/
  4980. //this.a=NaN;
  4981. /**旋转或倾斜图像时影响像素沿 y 轴定位的值。*/
  4982. //this.b=NaN;
  4983. /**旋转或倾斜图像时影响像素沿 x 轴定位的值。*/
  4984. //this.c=NaN;
  4985. /**缩放或旋转图像时影响像素沿 y 轴定位的值。*/
  4986. //this.d=NaN;
  4987. /**沿 x 轴平移每个点的距离。*/
  4988. //this.tx=NaN;
  4989. /**沿 y 轴平移每个点的距离。*/
  4990. //this.ty=NaN;
  4991. /**@private 是否有旋转缩放操作*/
  4992. this._bTransform=false;
  4993. (a===void 0)&& (a=1);
  4994. (b===void 0)&& (b=0);
  4995. (c===void 0)&& (c=0);
  4996. (d===void 0)&& (d=1);
  4997. (tx===void 0)&& (tx=0);
  4998. (ty===void 0)&& (ty=0);
  4999. (nums===void 0)&& (nums=0);
  5000. if (Matrix._createFun !=null){
  5001. /*__JS__ */return Matrix._createFun(a,b,c,d,tx,ty,nums);
  5002. }
  5003. this.a=a;
  5004. this.b=b;
  5005. this.c=c;
  5006. this.d=d;
  5007. this.tx=tx;
  5008. this.ty=ty;
  5009. this._checkTransform();
  5010. }
  5011. __class(Matrix,'laya.maths.Matrix');
  5012. var __proto=Matrix.prototype;
  5013. /**
  5014. *将本矩阵设置为单位矩阵。
  5015. *@return 返回当前矩形。
  5016. */
  5017. __proto.identity=function(){
  5018. this.a=this.d=1;
  5019. this.b=this.tx=this.ty=this.c=0;
  5020. this._bTransform=false;
  5021. return this;
  5022. }
  5023. /**@private */
  5024. __proto._checkTransform=function(){
  5025. return this._bTransform=(this.a!==1 || this.b!==0 || this.c!==0 || this.d!==1);
  5026. }
  5027. /**
  5028. *设置沿 x 、y 轴平移每个点的距离。
  5029. *@param x 沿 x 轴平移每个点的距离。
  5030. *@param y 沿 y 轴平移每个点的距离。
  5031. *@return 返回对象本身
  5032. */
  5033. __proto.setTranslate=function(x,y){
  5034. this.tx=x;
  5035. this.ty=y;
  5036. return this;
  5037. }
  5038. /**
  5039. *沿 x 和 y 轴平移矩阵,平移的变化量由 x 和 y 参数指定。
  5040. *@param x 沿 x 轴向右移动的量(以像素为单位)。
  5041. *@param y 沿 y 轴向下移动的量(以像素为单位)。
  5042. *@return 返回此矩形对象。
  5043. */
  5044. __proto.translate=function(x,y){
  5045. this.tx+=x;
  5046. this.ty+=y;
  5047. return this;
  5048. }
  5049. /**
  5050. *对矩阵应用缩放转换。
  5051. *@param x 用于沿 x 轴缩放对象的乘数。
  5052. *@param y 用于沿 y 轴缩放对象的乘数。
  5053. *@return 返回矩阵对象本身
  5054. */
  5055. __proto.scale=function(x,y){
  5056. this.a *=x;
  5057. this.d *=y;
  5058. this.c *=x;
  5059. this.b *=y;
  5060. this.tx *=x;
  5061. this.ty *=y;
  5062. this._bTransform=true;
  5063. return this;
  5064. }
  5065. /**
  5066. *对 Matrix 对象应用旋转转换。
  5067. *@param angle 以弧度为单位的旋转角度。
  5068. *@return 返回矩阵对象本身
  5069. */
  5070. __proto.rotate=function(angle){
  5071. var cos=Math.cos(angle);
  5072. var sin=Math.sin(angle);
  5073. var a1=this.a;
  5074. var c1=this.c;
  5075. var tx1=this.tx;
  5076. this.a=a1 *cos-this.b *sin;
  5077. this.b=a1 *sin+this.b *cos;
  5078. this.c=c1 *cos-this.d *sin;
  5079. this.d=c1 *sin+this.d *cos;
  5080. this.tx=tx1 *cos-this.ty *sin;
  5081. this.ty=tx1 *sin+this.ty *cos;
  5082. this._bTransform=true;
  5083. return this;
  5084. }
  5085. /**
  5086. *对 Matrix 对象应用倾斜转换。
  5087. *@param x 沿着 X 轴的 2D 倾斜弧度。
  5088. *@param y 沿着 Y 轴的 2D 倾斜弧度。
  5089. *@return 当前 Matrix 对象。
  5090. */
  5091. __proto.skew=function(x,y){
  5092. var tanX=Math.tan(x);
  5093. var tanY=Math.tan(y);
  5094. var a1=this.a;
  5095. var b1=this.b;
  5096. this.a+=tanY *this.c;
  5097. this.b+=tanY *this.d;
  5098. this.c+=tanX *a1;
  5099. this.d+=tanX *b1;
  5100. return this;
  5101. }
  5102. /**
  5103. *对指定的点应用当前矩阵的逆转化并返回此点。
  5104. *@param out 待转化的点 Point 对象。
  5105. *@return 返回out
  5106. */
  5107. __proto.invertTransformPoint=function(out){
  5108. var a1=this.a;
  5109. var b1=this.b;
  5110. var c1=this.c;
  5111. var d1=this.d;
  5112. var tx1=this.tx;
  5113. var n=a1 *d1-b1 *c1;
  5114. var a2=d1 / n;
  5115. var b2=-b1 / n;
  5116. var c2=-c1 / n;
  5117. var d2=a1 / n;
  5118. var tx2=(c1 *this.ty-d1 *tx1)/ n;
  5119. var ty2=-(a1 *this.ty-b1 *tx1)/ n;
  5120. return out.setTo(a2 *out.x+c2 *out.y+tx2,b2 *out.x+d2 *out.y+ty2);
  5121. }
  5122. /**
  5123. *将 Matrix 对象表示的几何转换应用于指定点。
  5124. *@param out 用来设定输出结果的点。
  5125. *@return 返回out
  5126. */
  5127. __proto.transformPoint=function(out){
  5128. return out.setTo(this.a *out.x+this.c *out.y+this.tx,this.b *out.x+this.d *out.y+this.ty);
  5129. }
  5130. /**
  5131. *将 Matrix 对象表示的几何转换应用于指定点,忽略tx、ty。
  5132. *@param out 用来设定输出结果的点。
  5133. *@return 返回out
  5134. */
  5135. __proto.transformPointN=function(out){
  5136. return out.setTo(this.a *out.x+this.c *out.y ,this.b *out.x+this.d *out.y);
  5137. }
  5138. /**
  5139. *获取 X 轴缩放值。
  5140. *@return X 轴缩放值。
  5141. */
  5142. __proto.getScaleX=function(){
  5143. return this.b===0 ? this.a :Math.sqrt(this.a *this.a+this.b *this.b);
  5144. }
  5145. /**
  5146. *获取 Y 轴缩放值。
  5147. *@return Y 轴缩放值。
  5148. */
  5149. __proto.getScaleY=function(){
  5150. return this.c===0 ? this.d :Math.sqrt(this.c *this.c+this.d *this.d);
  5151. }
  5152. /**
  5153. *执行原始矩阵的逆转换。
  5154. *@return 当前矩阵对象。
  5155. */
  5156. __proto.invert=function(){
  5157. var a1=this.a;
  5158. var b1=this.b;
  5159. var c1=this.c;
  5160. var d1=this.d;
  5161. var tx1=this.tx;
  5162. var n=a1 *d1-b1 *c1;
  5163. this.a=d1 / n;
  5164. this.b=-b1 / n;
  5165. this.c=-c1 / n;
  5166. this.d=a1 / n;
  5167. this.tx=(c1 *this.ty-d1 *tx1)/ n;
  5168. this.ty=-(a1 *this.ty-b1 *tx1)/ n;
  5169. return this;
  5170. }
  5171. /**
  5172. *将 Matrix 的成员设置为指定值。
  5173. *@param a 缩放或旋转图像时影响像素沿 x 轴定位的值。
  5174. *@param b 旋转或倾斜图像时影响像素沿 y 轴定位的值。
  5175. *@param c 旋转或倾斜图像时影响像素沿 x 轴定位的值。
  5176. *@param d 缩放或旋转图像时影响像素沿 y 轴定位的值。
  5177. *@param tx 沿 x 轴平移每个点的距离。
  5178. *@param ty 沿 y 轴平移每个点的距离。
  5179. *@return 当前矩阵对象。
  5180. */
  5181. __proto.setTo=function(a,b,c,d,tx,ty){
  5182. this.a=a,this.b=b,this.c=c,this.d=d,this.tx=tx,this.ty=ty;
  5183. return this;
  5184. }
  5185. /**
  5186. *将指定矩阵与当前矩阵连接,从而将这两个矩阵的几何效果有效地结合在一起。
  5187. *@param matrix 要连接到源矩阵的矩阵。
  5188. *@return 当前矩阵。
  5189. */
  5190. __proto.concat=function(matrix){
  5191. var a=this.a;
  5192. var c=this.c;
  5193. var tx=this.tx;
  5194. this.a=a *matrix.a+this.b *matrix.c;
  5195. this.b=a *matrix.b+this.b *matrix.d;
  5196. this.c=c *matrix.a+this.d *matrix.c;
  5197. this.d=c *matrix.b+this.d *matrix.d;
  5198. this.tx=tx *matrix.a+this.ty *matrix.c+matrix.tx;
  5199. this.ty=tx *matrix.b+this.ty *matrix.d+matrix.ty;
  5200. return this;
  5201. }
  5202. /**
  5203. *@private
  5204. *对矩阵应用缩放转换。反向相乘
  5205. *@param x 用于沿 x 轴缩放对象的乘数。
  5206. *@param y 用于沿 y 轴缩放对象的乘数。
  5207. */
  5208. __proto.scaleEx=function(x,y){
  5209. var ba=this.a,bb=this.b,bc=this.c,bd=this.d;
  5210. if (bb!==0 || bc!==0){
  5211. this.a=x *ba;
  5212. this.b=x *bb;
  5213. this.c=y *bc;
  5214. this.d=y *bd;
  5215. }else {
  5216. this.a=x *ba;
  5217. this.b=0 *bd;
  5218. this.c=0 *ba;
  5219. this.d=y *bd;
  5220. }
  5221. this._bTransform=true;
  5222. }
  5223. /**
  5224. *@private
  5225. *对 Matrix 对象应用旋转转换。反向相乘
  5226. *@param angle 以弧度为单位的旋转角度。
  5227. */
  5228. __proto.rotateEx=function(angle){
  5229. var cos=Math.cos(angle);
  5230. var sin=Math.sin(angle);
  5231. var ba=this.a,bb=this.b,bc=this.c,bd=this.d;
  5232. if (bb!==0 || bc!==0){
  5233. this.a=cos *ba+sin *bc;
  5234. this.b=cos *bb+sin *bd;
  5235. this.c=-sin *ba+cos *bc;
  5236. this.d=-sin *bb+cos *bd;
  5237. }else {
  5238. this.a=cos *ba;
  5239. this.b=sin *bd;
  5240. this.c=-sin *ba;
  5241. this.d=cos *bd;
  5242. }
  5243. this._bTransform=true;
  5244. }
  5245. /**
  5246. *返回此 Matrix 对象的副本。
  5247. *@return 与原始实例具有完全相同的属性的新 Matrix 实例。
  5248. */
  5249. __proto.clone=function(){
  5250. var dec=Matrix.create();
  5251. dec.a=this.a;
  5252. dec.b=this.b;
  5253. dec.c=this.c;
  5254. dec.d=this.d;
  5255. dec.tx=this.tx;
  5256. dec.ty=this.ty;
  5257. dec._bTransform=this._bTransform;
  5258. return dec;
  5259. }
  5260. /**
  5261. *将当前 Matrix 对象中的所有矩阵数据复制到指定的 Matrix 对象中。
  5262. *@param dec 要复制当前矩阵数据的 Matrix 对象。
  5263. *@return 已复制当前矩阵数据的 Matrix 对象。
  5264. */
  5265. __proto.copyTo=function(dec){
  5266. dec.a=this.a;
  5267. dec.b=this.b;
  5268. dec.c=this.c;
  5269. dec.d=this.d;
  5270. dec.tx=this.tx;
  5271. dec.ty=this.ty;
  5272. dec._bTransform=this._bTransform;
  5273. return dec;
  5274. }
  5275. /**
  5276. *返回列出该 Matrix 对象属性的文本值。
  5277. *@return 一个字符串,它包含 Matrix 对象的属性值:a、b、c、d、tx 和 ty。
  5278. */
  5279. __proto.toString=function(){
  5280. return this.a+","+this.b+","+this.c+","+this.d+","+this.tx+","+this.ty;
  5281. }
  5282. /**
  5283. *销毁此对象。
  5284. */
  5285. __proto.destroy=function(){
  5286. this.recover();
  5287. }
  5288. /**
  5289. *回收到对象池,方便复用
  5290. */
  5291. __proto.recover=function(){
  5292. Pool.recover("Matrix",this.identity());
  5293. }
  5294. Matrix.mul=function(m1,m2,out){
  5295. var aa=m1.a,ab=m1.b,ac=m1.c,ad=m1.d,atx=m1.tx,aty=m1.ty;
  5296. var ba=m2.a,bb=m2.b,bc=m2.c,bd=m2.d,btx=m2.tx,bty=m2.ty;
  5297. if (bb!==0 || bc!==0){
  5298. out.a=aa *ba+ab *bc;
  5299. out.b=aa *bb+ab *bd;
  5300. out.c=ac *ba+ad *bc;
  5301. out.d=ac *bb+ad *bd;
  5302. out.tx=ba *atx+bc *aty+btx;
  5303. out.ty=bb *atx+bd *aty+bty;
  5304. }else {
  5305. out.a=aa *ba;
  5306. out.b=ab *bd;
  5307. out.c=ac *ba;
  5308. out.d=ad *bd;
  5309. out.tx=ba *atx+btx;
  5310. out.ty=bd *aty+bty;
  5311. }
  5312. return out;
  5313. }
  5314. Matrix.mul16=function(m1,m2,out){
  5315. var aa=m1.a,ab=m1.b,ac=m1.c,ad=m1.d,atx=m1.tx,aty=m1.ty;
  5316. var ba=m2.a,bb=m2.b,bc=m2.c,bd=m2.d,btx=m2.tx,bty=m2.ty;
  5317. if (bb!==0 || bc!==0){
  5318. out[0]=aa *ba+ab *bc;
  5319. out[1]=aa *bb+ab *bd;
  5320. out[4]=ac *ba+ad *bc;
  5321. out[5]=ac *bb+ad *bd;
  5322. out[12]=ba *atx+bc *aty+btx;
  5323. out[13]=bb *atx+bd *aty+bty;
  5324. }else {
  5325. out[0]=aa *ba;
  5326. out[1]=ab *bd;
  5327. out[4]=ac *ba;
  5328. out[5]=ad *bd;
  5329. out[12]=ba *atx+btx;
  5330. out[13]=bd *aty+bty;
  5331. }
  5332. return out;
  5333. }
  5334. Matrix.create=function(){
  5335. return Pool.getItemByClass("Matrix",Matrix);
  5336. }
  5337. Matrix.EMPTY=new Matrix();
  5338. Matrix.TEMP=new Matrix();
  5339. Matrix._createFun=null;
  5340. return Matrix;
  5341. })()
  5342. /**
  5343. *<code>Graphics</code> 类用于创建绘图显示对象。Graphics可以同时绘制多个位图或者矢量图,还可以结合save,restore,transform,scale,rotate,translate,alpha等指令对绘图效果进行变化。
  5344. *Graphics以命令流方式存储,可以通过cmds属性访问所有命令流。Graphics是比Sprite更轻量级的对象,合理使用能提高应用性能(比如把大量的节点绘图改为一个节点的Graphics命令集合,能减少大量节点创建消耗)。
  5345. *@see laya.display.Sprite#graphics
  5346. */
  5347. //class laya.display.Graphics
  5348. var Graphics=(function(){
  5349. function Graphics(){
  5350. /**@private */
  5351. this._sp=null;
  5352. /**@private */
  5353. this._one=null;
  5354. /**@private */
  5355. this._cmds=null;
  5356. /**@private */
  5357. this._vectorgraphArray=null;
  5358. /**@private */
  5359. this._graphicBounds=null;
  5360. /**@private */
  5361. this.autoDestroy=false;
  5362. this._render=this._renderEmpty;
  5363. this._createData();
  5364. }
  5365. __class(Graphics,'laya.display.Graphics');
  5366. var __proto=Graphics.prototype;
  5367. /**@private */
  5368. __proto._createData=function(){}
  5369. /**@private */
  5370. __proto._clearData=function(){}
  5371. /**@private */
  5372. __proto._destroyData=function(){}
  5373. /**
  5374. *<p>销毁此对象。</p>
  5375. */
  5376. __proto.destroy=function(){
  5377. this.clear(true);
  5378. if (this._graphicBounds)this._graphicBounds.destroy();
  5379. this._graphicBounds=null;
  5380. this._vectorgraphArray=null;
  5381. if (this._sp){
  5382. this._sp._renderType=0;
  5383. this._sp._setRenderType(0);
  5384. this._sp=null;
  5385. }
  5386. this._destroyData();
  5387. }
  5388. /**
  5389. *<p>清空绘制命令。</p>
  5390. *@param recoverCmds 是否回收绘图指令数组,设置为true,则对指令数组进行回收以节省内存开销,建议设置为true进行回收,但如果手动引用了数组,不建议回收
  5391. */
  5392. __proto.clear=function(recoverCmds){
  5393. (recoverCmds===void 0)&& (recoverCmds=true);
  5394. if (recoverCmds){
  5395. var tCmd=this._one;
  5396. if (this._cmds){
  5397. var i=0,len=this._cmds.length;
  5398. for (i=0;i < len;i++){
  5399. tCmd=this._cmds[i];
  5400. tCmd.recover();
  5401. }
  5402. this._cmds.length=0;
  5403. }else if (tCmd){
  5404. tCmd.recover();
  5405. }
  5406. }else {
  5407. this._cmds=null;
  5408. }
  5409. this._one=null;
  5410. this._render=this._renderEmpty;
  5411. this._clearData();
  5412. if (this._sp){
  5413. this._sp._renderType &=~ /*laya.display.SpriteConst.GRAPHICS*/0x200;
  5414. this._sp._setRenderType(this._sp._renderType);
  5415. }
  5416. this._repaint();
  5417. if (this._vectorgraphArray){
  5418. for (i=0,len=this._vectorgraphArray.length;i < len;i++){
  5419. VectorGraphManager.getInstance().deleteShape(this._vectorgraphArray[i]);
  5420. }
  5421. this._vectorgraphArray.length=0;
  5422. }
  5423. }
  5424. /**@private */
  5425. __proto._clearBoundsCache=function(){
  5426. if (this._graphicBounds)this._graphicBounds.reset();
  5427. }
  5428. /**@private */
  5429. __proto._initGraphicBounds=function(){
  5430. if (!this._graphicBounds){
  5431. this._graphicBounds=GraphicsBounds.create();
  5432. this._graphicBounds._graphics=this;
  5433. }
  5434. }
  5435. /**
  5436. *@private
  5437. *重绘此对象。
  5438. */
  5439. __proto._repaint=function(){
  5440. this._clearBoundsCache();
  5441. this._sp && this._sp.repaint();
  5442. }
  5443. //TODO:coverage
  5444. __proto._isOnlyOne=function(){
  5445. return !this._cmds || this._cmds.length===0;
  5446. }
  5447. /**
  5448. *获取位置及宽高信息矩阵(比较耗CPU,频繁使用会造成卡顿,尽量少用)。
  5449. *@param realSize (可选)使用图片的真实大小,默认为false
  5450. *@return 位置与宽高组成的 一个 Rectangle 对象。
  5451. */
  5452. __proto.getBounds=function(realSize){
  5453. (realSize===void 0)&& (realSize=false);
  5454. this._initGraphicBounds();
  5455. return this._graphicBounds.getBounds(realSize);
  5456. }
  5457. /**
  5458. *@private
  5459. *@param realSize (可选)使用图片的真实大小,默认为false
  5460. *获取端点列表。
  5461. */
  5462. __proto.getBoundPoints=function(realSize){
  5463. (realSize===void 0)&& (realSize=false);
  5464. this._initGraphicBounds();
  5465. return this._graphicBounds.getBoundPoints(realSize);
  5466. }
  5467. /**
  5468. *绘制单独图片
  5469. *@param texture 纹理。
  5470. *@param x (可选)X轴偏移量。
  5471. *@param y (可选)Y轴偏移量。
  5472. *@param width (可选)宽度。
  5473. *@param height (可选)高度。
  5474. */
  5475. __proto.drawImage=function(texture,x,y,width,height){
  5476. (x===void 0)&& (x=0);
  5477. (y===void 0)&& (y=0);
  5478. (width===void 0)&& (width=0);
  5479. (height===void 0)&& (height=0);
  5480. if (!texture)return null;
  5481. if (!width)width=texture.sourceWidth;
  5482. if (!height)height=texture.sourceHeight;
  5483. if (texture.getIsReady()){
  5484. var wRate=width / texture.sourceWidth;
  5485. var hRate=height / texture.sourceHeight;
  5486. width=texture.width *wRate;
  5487. height=texture.height *hRate;
  5488. if (width <=0 || height <=0)return null;
  5489. x+=texture.offsetX *wRate;
  5490. y+=texture.offsetY *hRate;
  5491. }
  5492. if (this._sp){
  5493. this._sp._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  5494. this._sp._setRenderType(this._sp._renderType);
  5495. };
  5496. var args=DrawImageCmd.create.call(this,texture,x,y,width,height);
  5497. if (this._one==null){
  5498. this._one=args;
  5499. this._render=this._renderOneImg;
  5500. }else {
  5501. this._saveToCmd(null,args);
  5502. }
  5503. this._repaint();
  5504. return args;
  5505. }
  5506. /**
  5507. *绘制纹理,相比drawImage功能更强大,性能会差一些
  5508. *@param texture 纹理。
  5509. *@param x (可选)X轴偏移量。
  5510. *@param y (可选)Y轴偏移量。
  5511. *@param width (可选)宽度。
  5512. *@param height (可选)高度。
  5513. *@param matrix (可选)矩阵信息。
  5514. *@param alpha (可选)透明度。
  5515. *@param color (可选)颜色滤镜。
  5516. *@param blendMode (可选)混合模式。
  5517. */
  5518. __proto.drawTexture=function(texture,x,y,width,height,matrix,alpha,color,blendMode){
  5519. (x===void 0)&& (x=0);
  5520. (y===void 0)&& (y=0);
  5521. (width===void 0)&& (width=0);
  5522. (height===void 0)&& (height=0);
  5523. (alpha===void 0)&& (alpha=1);
  5524. if (!texture || alpha < 0.01)return null;
  5525. if (!texture.getIsReady())return null;
  5526. if (!width)width=texture.sourceWidth;
  5527. if (!height)height=texture.sourceHeight;
  5528. if (texture.getIsReady()){
  5529. var wRate=width / texture.sourceWidth;
  5530. var hRate=height / texture.sourceHeight;
  5531. width=texture.width *wRate;
  5532. height=texture.height *hRate;
  5533. if (width <=0 || height <=0)return null;
  5534. x+=texture.offsetX *wRate;
  5535. y+=texture.offsetY *hRate;
  5536. }
  5537. if (this._sp){
  5538. this._sp._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  5539. this._sp._setRenderType(this._sp._renderType);
  5540. };
  5541. var args=DrawTextureCmd.create.call(this,texture,x,y,width,height,matrix,alpha,color,blendMode);
  5542. this._repaint();
  5543. return this._saveToCmd(null,args);
  5544. }
  5545. /**
  5546. *批量绘制同样纹理。
  5547. *@param texture 纹理。
  5548. *@param pos 绘制次数和坐标。
  5549. */
  5550. __proto.drawTextures=function(texture,pos){
  5551. if (!texture)return null;
  5552. return this._saveToCmd(Render._context.drawTextures,DrawTexturesCmd.create.call(this,texture,pos));
  5553. }
  5554. /**
  5555. *绘制一组三角形
  5556. *@param texture 纹理。
  5557. *@param x X轴偏移量。
  5558. *@param y Y轴偏移量。
  5559. *@param vertices 顶点数组。
  5560. *@param indices 顶点索引。
  5561. *@param uvData UV数据。
  5562. *@param matrix 缩放矩阵。
  5563. *@param alpha alpha
  5564. *@param color 颜色变换
  5565. *@param blendMode blend模式
  5566. */
  5567. __proto.drawTriangles=function(texture,x,y,vertices,uvs,indices,matrix,alpha,color,blendMode){
  5568. (alpha===void 0)&& (alpha=1);
  5569. return this._saveToCmd(Render._context.drawTriangles,DrawTrianglesCmd.create.call(this,texture,x,y,vertices,uvs,indices,matrix,alpha,color,blendMode));
  5570. }
  5571. /**
  5572. *用texture填充。
  5573. *@param texture 纹理。
  5574. *@param x X轴偏移量。
  5575. *@param y Y轴偏移量。
  5576. *@param width (可选)宽度。
  5577. *@param height (可选)高度。
  5578. *@param type (可选)填充类型 repeat|repeat-x|repeat-y|no-repeat
  5579. *@param offset (可选)贴图纹理偏移
  5580. *
  5581. */
  5582. __proto.fillTexture=function(texture,x,y,width,height,type,offset){
  5583. (width===void 0)&& (width=0);
  5584. (height===void 0)&& (height=0);
  5585. (type===void 0)&& (type="repeat");
  5586. if (texture && texture.getIsReady())
  5587. return this._saveToCmd(Render._context._fillTexture,FillTextureCmd.create.call(this,texture,x,y,width,height,type,offset || Point.EMPTY,{}));
  5588. else
  5589. return null;
  5590. }
  5591. /**
  5592. *@private
  5593. *保存到命令流。
  5594. */
  5595. __proto._saveToCmd=function(fun,args){
  5596. if (this._sp){
  5597. this._sp._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  5598. this._sp._setRenderType(this._sp._renderType);
  5599. }
  5600. if (this._one==null){
  5601. this._one=args;
  5602. this._render=this._renderOne;
  5603. }else {
  5604. this._render=this._renderAll;
  5605. (this._cmds || (this._cmds=[])).length===0 && this._cmds.push(this._one);
  5606. this._cmds.push(args);
  5607. }
  5608. this._repaint();
  5609. return args;
  5610. }
  5611. /**
  5612. *设置剪裁区域,超出剪裁区域的坐标不显示。
  5613. *@param x X 轴偏移量。
  5614. *@param y Y 轴偏移量。
  5615. *@param width 宽度。
  5616. *@param height 高度。
  5617. */
  5618. __proto.clipRect=function(x,y,width,height){
  5619. return this._saveToCmd(Render._context.clipRect,ClipRectCmd.create.call(this,x,y,width,height));
  5620. }
  5621. /**
  5622. *在画布上绘制文本。
  5623. *@param text 在画布上输出的文本。
  5624. *@param x 开始绘制文本的 x 坐标位置(相对于画布)。
  5625. *@param y 开始绘制文本的 y 坐标位置(相对于画布)。
  5626. *@param font 定义字号和字体,比如"20px Arial"。
  5627. *@param color 定义文本颜色,比如"#ff0000"。
  5628. *@param textAlign 文本对齐方式,可选值:"left","center","right"。
  5629. */
  5630. __proto.fillText=function(text,x,y,font,color,textAlign){
  5631. return this._saveToCmd(Render._context.fillText,FillTextCmd.create.call(this,text,x,y,font || Text.defaultFontStr(),color,textAlign));
  5632. }
  5633. /**
  5634. *在画布上绘制“被填充且镶边的”文本。
  5635. *@param text 在画布上输出的文本。
  5636. *@param x 开始绘制文本的 x 坐标位置(相对于画布)。
  5637. *@param y 开始绘制文本的 y 坐标位置(相对于画布)。
  5638. *@param font 定义字体和字号,比如"20px Arial"。
  5639. *@param fillColor 定义文本颜色,比如"#ff0000"。
  5640. *@param borderColor 定义镶边文本颜色。
  5641. *@param lineWidth 镶边线条宽度。
  5642. *@param textAlign 文本对齐方式,可选值:"left","center","right"。
  5643. */
  5644. __proto.fillBorderText=function(text,x,y,font,fillColor,borderColor,lineWidth,textAlign){
  5645. return this._saveToCmd(Render._context.fillBorderText,FillBorderTextCmd.create.call(this,text,x,y,font || Text.defaultFontStr(),fillColor,borderColor,lineWidth,textAlign));
  5646. }
  5647. /***@private */
  5648. __proto.fillWords=function(words,x,y,font,color){
  5649. return this._saveToCmd(Render._context.fillWords,FillWordsCmd.create.call(this,words,x,y,font || Text.defaultFontStr(),color));
  5650. }
  5651. /***@private */
  5652. __proto.fillBorderWords=function(words,x,y,font,fillColor,borderColor,lineWidth){
  5653. return this._saveToCmd(Render._context.fillBorderWords,FillBorderWordsCmd.create.call(this,words,x,y,font || Text.defaultFontStr(),fillColor,borderColor,lineWidth));
  5654. }
  5655. /**
  5656. *在画布上绘制文本(没有填色)。文本的默认颜色是黑色。
  5657. *@param text 在画布上输出的文本。
  5658. *@param x 开始绘制文本的 x 坐标位置(相对于画布)。
  5659. *@param y 开始绘制文本的 y 坐标位置(相对于画布)。
  5660. *@param font 定义字体和字号,比如"20px Arial"。
  5661. *@param color 定义文本颜色,比如"#ff0000"。
  5662. *@param lineWidth 线条宽度。
  5663. *@param textAlign 文本对齐方式,可选值:"left","center","right"。
  5664. */
  5665. __proto.strokeText=function(text,x,y,font,color,lineWidth,textAlign){
  5666. return this._saveToCmd(Render._context.fillBorderText,StrokeTextCmd.create.call(this,text,x,y,font || Text.defaultFontStr(),null,color,lineWidth,textAlign));
  5667. }
  5668. /**
  5669. *设置透明度。
  5670. *@param value 透明度。
  5671. */
  5672. __proto.alpha=function(alpha){
  5673. return this._saveToCmd(Render._context.alpha,AlphaCmd.create.call(this,alpha));
  5674. }
  5675. /**
  5676. *替换绘图的当前转换矩阵。
  5677. *@param mat 矩阵。
  5678. *@param pivotX (可选)水平方向轴心点坐标。
  5679. *@param pivotY (可选)垂直方向轴心点坐标。
  5680. */
  5681. __proto.transform=function(matrix,pivotX,pivotY){
  5682. (pivotX===void 0)&& (pivotX=0);
  5683. (pivotY===void 0)&& (pivotY=0);
  5684. return this._saveToCmd(Render._context._transform,TransformCmd.create.call(this,matrix,pivotX,pivotY));
  5685. }
  5686. /**
  5687. *旋转当前绘图。(推荐使用transform,性能更高)
  5688. *@param angle 旋转角度,以弧度计。
  5689. *@param pivotX (可选)水平方向轴心点坐标。
  5690. *@param pivotY (可选)垂直方向轴心点坐标。
  5691. */
  5692. __proto.rotate=function(angle,pivotX,pivotY){
  5693. (pivotX===void 0)&& (pivotX=0);
  5694. (pivotY===void 0)&& (pivotY=0);
  5695. return this._saveToCmd(Render._context._rotate,RotateCmd.create.call(this,angle,pivotX,pivotY));
  5696. }
  5697. /**
  5698. *缩放当前绘图至更大或更小。(推荐使用transform,性能更高)
  5699. *@param scaleX 水平方向缩放值。
  5700. *@param scaleY 垂直方向缩放值。
  5701. *@param pivotX (可选)水平方向轴心点坐标。
  5702. *@param pivotY (可选)垂直方向轴心点坐标。
  5703. */
  5704. __proto.scale=function(scaleX,scaleY,pivotX,pivotY){
  5705. (pivotX===void 0)&& (pivotX=0);
  5706. (pivotY===void 0)&& (pivotY=0);
  5707. return this._saveToCmd(Render._context._scale,ScaleCmd.create.call(this,scaleX,scaleY,pivotX,pivotY));
  5708. }
  5709. /**
  5710. *重新映射画布上的 (0,0)位置。
  5711. *@param x 添加到水平坐标(x)上的值。
  5712. *@param y 添加到垂直坐标(y)上的值。
  5713. */
  5714. __proto.translate=function(tx,ty){
  5715. return this._saveToCmd(Render._context.translate,TranslateCmd.create.call(this,tx,ty));
  5716. }
  5717. /**
  5718. *保存当前环境的状态。
  5719. */
  5720. __proto.save=function(){
  5721. return this._saveToCmd(Render._context._save,SaveCmd.create.call(this));
  5722. }
  5723. /**
  5724. *返回之前保存过的路径状态和属性。
  5725. */
  5726. __proto.restore=function(){
  5727. return this._saveToCmd(Render._context.restore,RestoreCmd.create.call(this));
  5728. }
  5729. /**
  5730. *@private
  5731. *替换文本内容。
  5732. *@param text 文本内容。
  5733. *@return 替换成功则值为true,否则值为flase。
  5734. */
  5735. __proto.replaceText=function(text){
  5736. this._repaint();
  5737. var cmds=this._cmds;
  5738. if (!cmds){
  5739. if (this._one && this._isTextCmd(this._one)){
  5740. this._one.text=text;
  5741. return true;
  5742. }
  5743. }else {
  5744. for (var i=cmds.length-1;i >-1;i--){
  5745. if (this._isTextCmd(cmds[i])){
  5746. cmds[i].text=text;
  5747. return true;
  5748. }
  5749. }
  5750. }
  5751. return false;
  5752. }
  5753. /**@private */
  5754. __proto._isTextCmd=function(cmd){
  5755. var cmdID=cmd.cmdID;
  5756. return cmdID==/*laya.display.cmd.FillTextCmd.ID*/"FillText" || cmdID==/*laya.display.cmd.StrokeTextCmd.ID*/"StrokeText" || cmdID==/*laya.display.cmd.FillBorderTextCmd.ID*/"FillBorderText";
  5757. }
  5758. /**
  5759. *@private
  5760. *替换文本颜色。
  5761. *@param color 颜色。
  5762. */
  5763. __proto.replaceTextColor=function(color){
  5764. this._repaint();
  5765. var cmds=this._cmds;
  5766. if (!cmds){
  5767. if (this._one && this._isTextCmd(this._one)){
  5768. this._setTextCmdColor(this._one,color);
  5769. }
  5770. }else {
  5771. for (var i=cmds.length-1;i >-1;i--){
  5772. if (this._isTextCmd(cmds[i])){
  5773. this._setTextCmdColor(cmds[i],color);
  5774. }
  5775. }
  5776. }
  5777. }
  5778. /**@private */
  5779. __proto._setTextCmdColor=function(cmdO,color){
  5780. var cmdID=cmdO.cmdID;
  5781. switch (cmdID){
  5782. case /*laya.display.cmd.FillTextCmd.ID*/"FillText":
  5783. case /*laya.display.cmd.StrokeTextCmd.ID*/"StrokeText":
  5784. cmdO.color=color;
  5785. break ;
  5786. case /*laya.display.cmd.FillBorderTextCmd.ID*/"FillBorderText":
  5787. case /*laya.display.cmd.FillBorderWordsCmd.ID*/"FillBorderWords":
  5788. case /*laya.display.cmd.FillBorderTextCmd.ID*/"FillBorderText":
  5789. cmdO.fillColor=color;
  5790. break ;
  5791. }
  5792. }
  5793. /**
  5794. *加载并显示一个图片。
  5795. *@param url 图片地址。
  5796. *@param x (可选)显示图片的x位置。
  5797. *@param y (可选)显示图片的y位置。
  5798. *@param width (可选)显示图片的宽度,设置为0表示使用图片默认宽度。
  5799. *@param height (可选)显示图片的高度,设置为0表示使用图片默认高度。
  5800. *@param complete (可选)加载完成回调。
  5801. */
  5802. __proto.loadImage=function(url,x,y,width,height,complete){
  5803. (x===void 0)&& (x=0);
  5804. (y===void 0)&& (y=0);
  5805. (width===void 0)&& (width=0);
  5806. (height===void 0)&& (height=0);
  5807. var tex=Loader.getRes(url);
  5808. if (!tex){
  5809. tex=new Texture();
  5810. tex.load(url);
  5811. Loader.cacheRes(url,tex);
  5812. tex.once(/*laya.events.Event.READY*/"ready",this,this.drawImage,[tex,x,y,width,height]);
  5813. }else {
  5814. if (!tex.getIsReady()){
  5815. tex.once(/*laya.events.Event.READY*/"ready",this,this.drawImage,[tex,x,y,width,height]);
  5816. }else
  5817. this.drawImage(tex,x,y,width,height);
  5818. }
  5819. if (complete !=null){
  5820. tex.getIsReady()? complete.call(this._sp):tex.on(/*laya.events.Event.READY*/"ready",this._sp,complete);
  5821. }
  5822. }
  5823. /**
  5824. *@private
  5825. */
  5826. __proto._renderEmpty=function(sprite,context,x,y){}
  5827. /**
  5828. *@private
  5829. */
  5830. __proto._renderAll=function(sprite,context,x,y){
  5831. var cmds=this._cmds;
  5832. for (var i=0,n=cmds.length;i < n;i++){
  5833. cmds[i].run(context,x,y);
  5834. }
  5835. }
  5836. /**
  5837. *@private
  5838. */
  5839. __proto._renderOne=function(sprite,context,x,y){
  5840. context.sprite=sprite;
  5841. this._one.run(context,x,y);
  5842. }
  5843. /**
  5844. *@private
  5845. */
  5846. __proto._renderOneImg=function(sprite,context,x,y){
  5847. context.sprite=sprite;
  5848. this._one.run(context,x,y);
  5849. }
  5850. /**
  5851. *绘制一条线。
  5852. *@param fromX X轴开始位置。
  5853. *@param fromY Y轴开始位置。
  5854. *@param toX X轴结束位置。
  5855. *@param toY Y轴结束位置。
  5856. *@param lineColor 颜色。
  5857. *@param lineWidth (可选)线条宽度。
  5858. */
  5859. __proto.drawLine=function(fromX,fromY,toX,toY,lineColor,lineWidth){
  5860. (lineWidth===void 0)&& (lineWidth=1);
  5861. var offset=(lineWidth < 1 || lineWidth % 2===0)? 0 :0.5;
  5862. return this._saveToCmd(Render._context._drawLine,DrawLineCmd.create.call(this,fromX+offset,fromY+offset,toX+offset,toY+offset,lineColor,lineWidth,0));
  5863. }
  5864. /**
  5865. *绘制一系列线段。
  5866. *@param x 开始绘制的X轴位置。
  5867. *@param y 开始绘制的Y轴位置。
  5868. *@param points 线段的点集合。格式:[x1,y1,x2,y2,x3,y3...]。
  5869. *@param lineColor 线段颜色,或者填充绘图的渐变对象。
  5870. *@param lineWidth (可选)线段宽度。
  5871. */
  5872. __proto.drawLines=function(x,y,points,lineColor,lineWidth){
  5873. (lineWidth===void 0)&& (lineWidth=1);
  5874. if (!points || points.length < 4)return null;
  5875. var offset=(lineWidth < 1 || lineWidth % 2===0)? 0 :0.5;
  5876. return this._saveToCmd(Render._context._drawLines,DrawLinesCmd.create.call(this,x+offset,y+offset,points,lineColor,lineWidth,0));
  5877. }
  5878. /**
  5879. *绘制一系列曲线。
  5880. *@param x 开始绘制的 X 轴位置。
  5881. *@param y 开始绘制的 Y 轴位置。
  5882. *@param points 线段的点集合,格式[controlX,controlY,anchorX,anchorY...]。
  5883. *@param lineColor 线段颜色,或者填充绘图的渐变对象。
  5884. *@param lineWidth (可选)线段宽度。
  5885. */
  5886. __proto.drawCurves=function(x,y,points,lineColor,lineWidth){
  5887. (lineWidth===void 0)&& (lineWidth=1);
  5888. return this._saveToCmd(Render._context.drawCurves,DrawCurvesCmd.create.call(this,x,y,points,lineColor,lineWidth));
  5889. }
  5890. /**
  5891. *绘制矩形。
  5892. *@param x 开始绘制的 X 轴位置。
  5893. *@param y 开始绘制的 Y 轴位置。
  5894. *@param width 矩形宽度。
  5895. *@param height 矩形高度。
  5896. *@param fillColor 填充颜色,或者填充绘图的渐变对象。
  5897. *@param lineColor (可选)边框颜色,或者填充绘图的渐变对象。
  5898. *@param lineWidth (可选)边框宽度。
  5899. */
  5900. __proto.drawRect=function(x,y,width,height,fillColor,lineColor,lineWidth){
  5901. (lineWidth===void 0)&& (lineWidth=1);
  5902. var offset=(lineWidth >=1 && lineColor)? lineWidth / 2 :0;
  5903. var lineOffset=lineColor ? lineWidth :0;
  5904. return this._saveToCmd(Render._context.drawRect,DrawRectCmd.create.call(this,x+offset,y+offset,width-lineOffset,height-lineOffset,fillColor,lineColor,lineWidth));
  5905. }
  5906. /**
  5907. *绘制圆形。
  5908. *@param x 圆点X 轴位置。
  5909. *@param y 圆点Y 轴位置。
  5910. *@param radius 半径。
  5911. *@param fillColor 填充颜色,或者填充绘图的渐变对象。
  5912. *@param lineColor (可选)边框颜色,或者填充绘图的渐变对象。
  5913. *@param lineWidth (可选)边框宽度。
  5914. */
  5915. __proto.drawCircle=function(x,y,radius,fillColor,lineColor,lineWidth){
  5916. (lineWidth===void 0)&& (lineWidth=1);
  5917. var offset=(lineWidth >=1 && lineColor)? lineWidth / 2 :0;
  5918. return this._saveToCmd(Render._context._drawCircle,DrawCircleCmd.create.call(this,x,y,radius-offset,fillColor,lineColor,lineWidth,0));
  5919. }
  5920. /**
  5921. *绘制扇形。
  5922. *@param x 开始绘制的 X 轴位置。
  5923. *@param y 开始绘制的 Y 轴位置。
  5924. *@param radius 扇形半径。
  5925. *@param startAngle 开始角度。
  5926. *@param endAngle 结束角度。
  5927. *@param fillColor 填充颜色,或者填充绘图的渐变对象。
  5928. *@param lineColor (可选)边框颜色,或者填充绘图的渐变对象。
  5929. *@param lineWidth (可选)边框宽度。
  5930. */
  5931. __proto.drawPie=function(x,y,radius,startAngle,endAngle,fillColor,lineColor,lineWidth){
  5932. (lineWidth===void 0)&& (lineWidth=1);
  5933. var offset=(lineWidth >=1 && lineColor)? lineWidth / 2 :0;
  5934. var lineOffset=lineColor ? lineWidth :0;
  5935. return this._saveToCmd(Render._context._drawPie,DrawPieCmd.create.call(this,x+offset,y+offset,radius-lineOffset,Utils.toRadian(startAngle),Utils.toRadian(endAngle),fillColor,lineColor,lineWidth,0));
  5936. }
  5937. /**
  5938. *绘制多边形。
  5939. *@param x 开始绘制的 X 轴位置。
  5940. *@param y 开始绘制的 Y 轴位置。
  5941. *@param points 多边形的点集合。
  5942. *@param fillColor 填充颜色,或者填充绘图的渐变对象。
  5943. *@param lineColor (可选)边框颜色,或者填充绘图的渐变对象。
  5944. *@param lineWidth (可选)边框宽度。
  5945. */
  5946. __proto.drawPoly=function(x,y,points,fillColor,lineColor,lineWidth){
  5947. (lineWidth===void 0)&& (lineWidth=1);
  5948. var tIsConvexPolygon=false;
  5949. if (points.length > 6){
  5950. tIsConvexPolygon=false;
  5951. }else {
  5952. tIsConvexPolygon=true;
  5953. };
  5954. var offset=(lineWidth >=1 && lineColor)? (lineWidth % 2===0 ? 0 :0.5):0;
  5955. return this._saveToCmd(Render._context._drawPoly,DrawPolyCmd.create.call(this,x+offset,y+offset,points,fillColor,lineColor,lineWidth,tIsConvexPolygon,0));
  5956. }
  5957. /**
  5958. *绘制路径。
  5959. *@param x 开始绘制的 X 轴位置。
  5960. *@param y 开始绘制的 Y 轴位置。
  5961. *@param paths 路径集合,路径支持以下格式:[["moveTo",x,y],["lineTo",x,y],["arcTo",x1,y1,x2,y2,r],["closePath"]]。
  5962. *@param brush (可选)刷子定义,支持以下设置{fillStyle:"#FF0000"}。
  5963. *@param pen (可选)画笔定义,支持以下设置{strokeStyle,lineWidth,lineJoin:"bevel|round|miter",lineCap:"butt|round|square",miterLimit}。
  5964. */
  5965. __proto.drawPath=function(x,y,paths,brush,pen){
  5966. return this._saveToCmd(Render._context._drawPath,DrawPathCmd.create.call(this,x,y,paths,brush,pen));
  5967. }
  5968. /**
  5969. *@private
  5970. *绘制带九宫格的图片
  5971. *@param texture
  5972. *@param x
  5973. *@param y
  5974. *@param width
  5975. *@param height
  5976. *@param sizeGrid
  5977. */
  5978. __proto.draw9Grid=function(texture,x,y,width,height,sizeGrid){
  5979. (x===void 0)&& (x=0);
  5980. (y===void 0)&& (y=0);
  5981. (width===void 0)&& (width=0);
  5982. (height===void 0)&& (height=0);
  5983. this._saveToCmd(null,Draw9GridTexture.create(texture,x,y,width,height,sizeGrid));
  5984. }
  5985. /**
  5986. *@private
  5987. *命令流。存储了所有绘制命令。
  5988. */
  5989. __getset(0,__proto,'cmds',function(){
  5990. return this._cmds;
  5991. },function(value){
  5992. if (this._sp){
  5993. this._sp._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  5994. this._sp._setRenderType(this._sp._renderType);
  5995. }
  5996. this._cmds=value;
  5997. this._render=this._renderAll;
  5998. this._repaint();
  5999. });
  6000. return Graphics;
  6001. })()
  6002. //class laya.webgl.submit.Submit
  6003. var Submit=(function(){
  6004. function Submit(renderType){
  6005. this.clipInfoID=-1;
  6006. //用来比较clipinfo
  6007. this._mesh=null;
  6008. //代替 _vb,_ib
  6009. this._blendFn=null;
  6010. this._id=0;
  6011. //protected var _isSelfVb:Boolean=false;
  6012. this._renderType=0;
  6013. this._parent=null;
  6014. // 从VB中什么地方开始画,画到哪
  6015. this._startIdx=0;
  6016. //indexbuffer 的偏移,单位是byte
  6017. this._numEle=0;
  6018. this._ref=1;
  6019. this.shaderValue=null;
  6020. this._key=new SubmitKey();
  6021. (renderType===void 0)&& (renderType=10000);
  6022. this._renderType=renderType;
  6023. this._id=++Submit.ID;
  6024. }
  6025. __class(Submit,'laya.webgl.submit.Submit');
  6026. var __proto=Submit.prototype;
  6027. Laya.imps(__proto,{"laya.webgl.submit.ISubmit":true})
  6028. //TODO:coverage
  6029. __proto.getID=function(){
  6030. return this._id;
  6031. }
  6032. __proto.releaseRender=function(){
  6033. if (Submit.RENDERBASE==this)
  6034. return;
  6035. if((--this._ref)<1){
  6036. Submit.POOL[Submit._poolSize++]=this;
  6037. this.shaderValue.release();
  6038. this.shaderValue=null;
  6039. this._mesh=null;
  6040. this._parent && (this._parent.releaseRender(),this._parent=null);
  6041. }
  6042. }
  6043. //TODO:coverage
  6044. __proto.getRenderType=function(){
  6045. return this._renderType;
  6046. }
  6047. __proto.renderSubmit=function(){
  6048. if (this._numEle===0 || !this._mesh || this._numEle==0)return 1;
  6049. var _tex=this.shaderValue.textureHost;
  6050. if (_tex){
  6051. var source=_tex._getSource();
  6052. if (!source)
  6053. return 1;
  6054. this.shaderValue.texture=source;
  6055. };
  6056. var gl=WebGL.mainContext;
  6057. this._mesh.useMesh(gl);
  6058. this.shaderValue.upload();
  6059. if (BlendMode.activeBlendFunction!==this._blendFn){
  6060. WebGLContext.setBlend(gl,true);
  6061. this._blendFn(gl);
  6062. BlendMode.activeBlendFunction=this._blendFn;
  6063. }
  6064. gl.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,this._numEle,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,this._startIdx);
  6065. Stat.renderBatches++;
  6066. Stat.trianglesFaces+=this._numEle / 3;
  6067. return 1;
  6068. }
  6069. //TODO:coverage
  6070. __proto._cloneInit=function(o,context,mesh,pos){;
  6071. o._ref=1;
  6072. o._mesh=mesh;
  6073. o._id=this._id;
  6074. o._key.copyFrom(this._key);
  6075. o._parent=this;
  6076. o._blendFn=this._blendFn;
  6077. o._renderType=this._renderType;
  6078. o._startIdx=pos *CONST3D2D.BYTES_PIDX;
  6079. o._numEle=this._numEle;
  6080. o.shaderValue=this.shaderValue;
  6081. this.shaderValue.ref++;
  6082. this._ref++;
  6083. }
  6084. //TODO:coverage
  6085. __proto.clone=function(context,mesh,pos){;
  6086. return null;
  6087. }
  6088. //TODO:coverage
  6089. __proto.reUse=function(context,pos){;
  6090. return 0;
  6091. }
  6092. //TODO:coverage
  6093. __proto.toString=function(){
  6094. return "ibindex:"+this._startIdx+" num:"+this._numEle+" key="+this._key;
  6095. }
  6096. Submit.__init__=function(){
  6097. var s=Submit.RENDERBASE=new Submit(-1);
  6098. s.shaderValue=new Value2D(0,0);
  6099. s.shaderValue.ALPHA=1;
  6100. s._ref=0xFFFFFFFF;
  6101. }
  6102. Submit.create=function(context,mesh,sv){;
  6103. var o=Submit._poolSize ? Submit.POOL[--Submit._poolSize] :new Submit();
  6104. o._ref=1;
  6105. o._mesh=mesh;
  6106. o._key.clear();
  6107. o._startIdx=mesh.indexNum *CONST3D2D.BYTES_PIDX;
  6108. o._numEle=0;
  6109. var blendType=context._nBlendType;
  6110. o._blendFn=context._targets ? BlendMode.targetFns[blendType] :BlendMode.fns[blendType];
  6111. o.shaderValue=sv;
  6112. o.shaderValue.setValue(context._shader2D);
  6113. var filters=context._shader2D.filters;
  6114. filters && o.shaderValue.setFilters(filters);
  6115. return o;
  6116. }
  6117. Submit.createShape=function(ctx,mesh,numEle,sv){
  6118. var o=Submit._poolSize ? Submit.POOL[--Submit._poolSize]:(new Submit());
  6119. o._mesh=mesh;
  6120. o._numEle=numEle;
  6121. o._startIdx=mesh.indexNum *2;
  6122. o._ref=1;
  6123. o.shaderValue=sv;
  6124. o.shaderValue.setValue(ctx._shader2D);
  6125. var blendType=ctx._nBlendType;
  6126. o._key.blendShader=blendType;
  6127. o._blendFn=ctx._targets ? BlendMode.targetFns[blendType] :BlendMode.fns[blendType];
  6128. return o;
  6129. }
  6130. Submit.TYPE_2D=10000;
  6131. Submit.TYPE_CANVAS=10003;
  6132. Submit.TYPE_CMDSETRT=10004;
  6133. Submit.TYPE_CUSTOM=10005;
  6134. Submit.TYPE_BLURRT=10006;
  6135. Submit.TYPE_CMDDESTORYPRERT=10007;
  6136. Submit.TYPE_DISABLESTENCIL=10008;
  6137. Submit.TYPE_OTHERIBVB=10009;
  6138. Submit.TYPE_PRIMITIVE=10010;
  6139. Submit.TYPE_RT=10011;
  6140. Submit.TYPE_BLUR_RT=10012;
  6141. Submit.TYPE_TARGET=10013;
  6142. Submit.TYPE_CHANGE_VALUE=10014;
  6143. Submit.TYPE_SHAPE=10015;
  6144. Submit.TYPE_TEXTURE=10016;
  6145. Submit.TYPE_FILLTEXTURE=10017;
  6146. Submit.KEY_ONCE=-1;
  6147. Submit.KEY_FILLRECT=1;
  6148. Submit.KEY_DRAWTEXTURE=2;
  6149. Submit.KEY_VG=3;
  6150. Submit.KEY_TRIANGLES=4;
  6151. Submit.RENDERBASE=null;
  6152. Submit.ID=1;
  6153. Submit.preRender=null;
  6154. Submit._poolSize=0;
  6155. Submit.POOL=[];
  6156. return Submit;
  6157. })()
  6158. /**
  6159. *填充贴图
  6160. */
  6161. //class laya.display.cmd.FillTextureCmd
  6162. var FillTextureCmd=(function(){
  6163. function FillTextureCmd(){
  6164. /**
  6165. *纹理。
  6166. */
  6167. //this.texture=null;
  6168. /**
  6169. *X轴偏移量。
  6170. */
  6171. //this.x=NaN;
  6172. /**
  6173. *Y轴偏移量。
  6174. */
  6175. //this.y=NaN;
  6176. /**
  6177. *(可选)宽度。
  6178. */
  6179. //this.width=NaN;
  6180. /**
  6181. *(可选)高度。
  6182. */
  6183. //this.height=NaN;
  6184. /**
  6185. *(可选)填充类型 repeat|repeat-x|repeat-y|no-repeat
  6186. */
  6187. //this.type=null;
  6188. /**
  6189. *(可选)贴图纹理偏移
  6190. */
  6191. //this.offset=null;
  6192. /**@private */
  6193. //this.other=null;
  6194. }
  6195. __class(FillTextureCmd,'laya.display.cmd.FillTextureCmd');
  6196. var __proto=FillTextureCmd.prototype;
  6197. /**
  6198. *回收到对象池
  6199. */
  6200. __proto.recover=function(){
  6201. this.texture=null;
  6202. this.offset=null;
  6203. this.other=null;
  6204. Pool.recover("FillTextureCmd",this);
  6205. }
  6206. /**@private */
  6207. __proto.run=function(context,gx,gy){
  6208. context.fillTexture(this.texture,this.x+gx,this.y+gy,this.width,this.height,this.type,this.offset,this.other);
  6209. }
  6210. /**@private */
  6211. __getset(0,__proto,'cmdID',function(){
  6212. return "FillTexture";
  6213. });
  6214. FillTextureCmd.create=function(texture,x,y,width,height,type,offset,other){
  6215. var cmd=Pool.getItemByClass("FillTextureCmd",FillTextureCmd);
  6216. cmd.texture=texture;
  6217. cmd.x=x;
  6218. cmd.y=y;
  6219. cmd.width=width;
  6220. cmd.height=height;
  6221. cmd.type=type;
  6222. cmd.offset=offset;
  6223. cmd.other=other;
  6224. return cmd;
  6225. }
  6226. FillTextureCmd.ID="FillTexture";
  6227. return FillTextureCmd;
  6228. })()
  6229. /**
  6230. *<p><code>KeyLocation</code> 类包含表示在键盘或类似键盘的输入设备上按键位置的常量。</p>
  6231. *<p><code>KeyLocation</code> 常数用在键盘事件对象的 <code>keyLocation </code>属性中。</p>
  6232. */
  6233. //class laya.events.KeyLocation
  6234. var KeyLocation=(function(){
  6235. function KeyLocation(){}
  6236. __class(KeyLocation,'laya.events.KeyLocation');
  6237. KeyLocation.STANDARD=0;
  6238. KeyLocation.LEFT=1;
  6239. KeyLocation.RIGHT=2;
  6240. KeyLocation.NUM_PAD=3;
  6241. return KeyLocation;
  6242. })()
  6243. /**
  6244. *@private
  6245. *封装GL命令
  6246. */
  6247. //class laya.layagl.LayaGL
  6248. var LayaGL=(function(){
  6249. function LayaGL(){}
  6250. __class(LayaGL,'laya.layagl.LayaGL');
  6251. var __proto=LayaGL.prototype;
  6252. //TODO:coverage
  6253. __proto.createCommandEncoder=function(reserveSize,adjustSize,isSyncToRenderThread){
  6254. (reserveSize===void 0)&& (reserveSize=128);
  6255. (adjustSize===void 0)&& (adjustSize=64);
  6256. (isSyncToRenderThread===void 0)&& (isSyncToRenderThread=false);
  6257. return new CommandEncoder(this,reserveSize,adjustSize,isSyncToRenderThread);
  6258. }
  6259. __proto.beginCommandEncoding=function(commandEncoder){}
  6260. __proto.endCommandEncoding=function(){}
  6261. __proto.matrix4x4Multiply=function(m1,m2,out){}
  6262. __proto.evaluateClipDatasRealTime=function(nodes,playCurTime,realTimeCurrentFrameIndexs,addtive){}
  6263. LayaGL.getFrameCount=function(){
  6264. return 0;
  6265. }
  6266. LayaGL.syncBufferToRenderThread=function(value,index){
  6267. (index===void 0)&& (index=0);
  6268. }
  6269. LayaGL.createArrayBufferRef=function(arrayBuffer,type,syncRender){}
  6270. LayaGL.createArrayBufferRefs=function(arrayBuffer,type,syncRender,refType){}
  6271. LayaGL.EXECUTE_JS_THREAD_BUFFER=0;
  6272. LayaGL.EXECUTE_RENDER_THREAD_BUFFER=1;
  6273. LayaGL.EXECUTE_COPY_TO_RENDER=2;
  6274. LayaGL.EXECUTE_COPY_TO_RENDER3D=3;
  6275. LayaGL.ARRAY_BUFFER_TYPE_DATA=0;
  6276. LayaGL.ARRAY_BUFFER_TYPE_CMD=1;
  6277. LayaGL.ARRAY_BUFFER_REF_REFERENCE=0;
  6278. LayaGL.ARRAY_BUFFER_REF_COPY=1;
  6279. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID=0;
  6280. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA=1;
  6281. LayaGL.instance=null;
  6282. return LayaGL;
  6283. })()
  6284. /**
  6285. *<code>Browser</code> 是浏览器代理类。封装浏览器及原生 js 提供的一些功能。
  6286. */
  6287. //class laya.utils.Browser
  6288. var Browser=(function(){
  6289. function Browser(){}
  6290. __class(Browser,'laya.utils.Browser');
  6291. /**获得设备像素比。*/
  6292. __getset(1,Browser,'pixelRatio',function(){
  6293. if (Browser._pixelRatio < 0){
  6294. Browser.__init__();
  6295. if (Browser.userAgent.indexOf("Mozilla/6.0(Linux; Android 6.0; HUAWEI NXT-AL10 Build/HUAWEINXT-AL10)")>-1)Browser._pixelRatio=2;
  6296. else {
  6297. var ctx=Browser.context;
  6298. var backingStore=ctx.backingStorePixelRatio || ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  6299. Browser._pixelRatio=(Browser._window.devicePixelRatio || 1)/ backingStore;
  6300. if (Browser._pixelRatio < 1)Browser._pixelRatio=1;
  6301. }
  6302. }
  6303. return Browser._pixelRatio;
  6304. });
  6305. /**浏览器窗口物理高度。考虑了设备像素比。*/
  6306. __getset(1,Browser,'height',function(){
  6307. Browser.__init__();
  6308. return ((Laya.stage && Laya.stage.canvasRotation)? Browser.clientWidth :Browser.clientHeight)*Browser.pixelRatio;
  6309. });
  6310. /**
  6311. *浏览器窗口可视宽度。
  6312. *通过分析浏览器信息获得。浏览器多个属性值优先级为:window.innerWidth(包含滚动条宽度)> document.body.clientWidth(不包含滚动条宽度),如果前者为0或为空,则选择后者。
  6313. */
  6314. __getset(1,Browser,'clientWidth',function(){
  6315. Browser.__init__();
  6316. return Browser._window.innerWidth || Browser._document.body.clientWidth;
  6317. });
  6318. /**浏览器原生 window 对象的引用。*/
  6319. __getset(1,Browser,'window',function(){
  6320. return Browser._window || Browser.__init__();
  6321. });
  6322. /**
  6323. *浏览器窗口可视高度。
  6324. *通过分析浏览器信息获得。浏览器多个属性值优先级为:window.innerHeight(包含滚动条高度)> document.body.clientHeight(不包含滚动条高度)> document.documentElement.clientHeight(不包含滚动条高度),如果前者为0或为空,则选择后者。
  6325. */
  6326. __getset(1,Browser,'clientHeight',function(){
  6327. Browser.__init__();
  6328. return Browser._window.innerHeight || Browser._document.body.clientHeight || Browser._document.documentElement.clientHeight;
  6329. });
  6330. /**浏览器窗口物理宽度。考虑了设备像素比。*/
  6331. __getset(1,Browser,'width',function(){
  6332. Browser.__init__();
  6333. return ((Laya.stage && Laya.stage.canvasRotation)? Browser.clientHeight :Browser.clientWidth)*Browser.pixelRatio;
  6334. });
  6335. /**画布容器,用来盛放画布的容器。方便对画布进行控制*/
  6336. __getset(1,Browser,'container',function(){
  6337. if (!Browser._container){
  6338. Browser.__init__();
  6339. Browser._container=Browser.createElement("div");
  6340. Browser._container.id="layaContainer";
  6341. Browser._document.body.appendChild(Browser._container);
  6342. }
  6343. return Browser._container;
  6344. },function(value){
  6345. Browser._container=value;
  6346. });
  6347. /**浏览器原生 document 对象的引用。*/
  6348. __getset(1,Browser,'document',function(){
  6349. Browser.__init__();
  6350. return Browser._document;
  6351. });
  6352. Browser.__init__=function(){
  6353. if (Browser._window)return Browser._window;
  6354. var win=Browser._window=/*__JS__ */window;
  6355. var doc=Browser._document=win.document;
  6356. var u=Browser.userAgent=win.navigator.userAgent;
  6357. var libs=win._layalibs;
  6358. if (libs){
  6359. libs.sort(function(a,b){
  6360. return a.i-b.i;
  6361. });
  6362. for (var j=0;j < libs.length;j++){
  6363. libs[j].f(win,doc,Laya);
  6364. }
  6365. }
  6366. if (u.indexOf("MiniGame")>-1 && Browser.window.hasOwnProperty("wx")){
  6367. if(laya.utils.Browser.window.hasOwnProperty("bl")){
  6368. if (!Laya["BLMiniAdapter"]){
  6369. console.error("请先添加小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6370. }else {
  6371. Laya["BLMiniAdapter"].enable();
  6372. }
  6373. }else if(laya.utils.Browser.window.hasOwnProperty("qq")){
  6374. if (!Laya["QQMiniAdapter"]){
  6375. console.error("请先添加小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6376. }else{
  6377. Laya["QQMiniAdapter"].enable();
  6378. }
  6379. }
  6380. else if (!Laya["MiniAdpter"]){
  6381. console.error("请先添加小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6382. }else {
  6383. Laya["MiniAdpter"].enable();
  6384. }
  6385. }
  6386. if (u.indexOf("SwanGame")>-1){
  6387. if (!Laya["BMiniAdapter"]){
  6388. console.error("请先添加百度小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6389. }else {
  6390. Laya["BMiniAdapter"].enable();
  6391. }
  6392. }
  6393. if((typeof /*__JS__ */getApp=='function')){
  6394. if (!Laya["KGMiniAdapter"]){
  6395. console.error("请先添加小米小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6396. }else {
  6397. Laya["KGMiniAdapter"].enable();
  6398. }
  6399. }
  6400. if (u.indexOf('OPPO')>-1 && u.indexOf('MiniGame')>-1){
  6401. if (!Laya["QGMiniAdapter"]){
  6402. console.error("请先添加OPPO小游戏适配库");
  6403. }else {
  6404. Laya["QGMiniAdapter"].enable();
  6405. }
  6406. }
  6407. if (u.indexOf('VVGame')>-1){
  6408. if (!Laya["VVMiniAdapter"]){
  6409. console.error("请先添加VIVO小游戏适配库");
  6410. }else {
  6411. Laya["VVMiniAdapter"].enable();
  6412. }
  6413. }
  6414. if (u.indexOf('AlipayMiniGame')>-1){
  6415. if (!Laya["ALIMiniAdapter"]){
  6416. console.error("请先添加VIVO小游戏适配库");
  6417. }else {
  6418. Laya["ALIMiniAdapter"].enable();
  6419. }
  6420. }
  6421. win.trace=console.log;
  6422. win.requestAnimationFrame=win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || win.oRequestAnimationFrame || win.msRequestAnimationFrame || function (fun){
  6423. return win.setTimeout(fun,1000 / 60);
  6424. };
  6425. var bodyStyle=doc.body.style;
  6426. bodyStyle.margin=0;
  6427. bodyStyle.overflow='hidden';
  6428. bodyStyle['-webkit-user-select']='none';
  6429. bodyStyle['-webkit-tap-highlight-color']='rgba(200,200,200,0)';
  6430. var metas=doc.getElementsByTagName('meta');
  6431. var i=0,flag=false,content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no';
  6432. while (i < metas.length){
  6433. var meta=metas[i];
  6434. if (meta.name=='viewport'){
  6435. meta.content=content;
  6436. flag=true;
  6437. break ;
  6438. }
  6439. i++;
  6440. }
  6441. if (!flag){
  6442. meta=doc.createElement('meta');
  6443. meta.name='viewport',meta.content=content;
  6444. doc.getElementsByTagName('head')[0].appendChild(meta);
  6445. }
  6446. Browser.onMobile=/*__JS__ */window.isConchApp ? true :u.indexOf("Mobile")>-1;
  6447. Browser.onIOS=!!u.match(/\(i[^;]+;(U;)? CPU.+Mac OS X/);
  6448. Browser.onIPhone=u.indexOf("iPhone")>-1;
  6449. Browser.onMac=/*[SAFE]*/ u.indexOf("Mac OS X")>-1;
  6450. Browser.onIPad=u.indexOf("iPad")>-1;
  6451. Browser.onAndroid=u.indexOf('Android')>-1 || u.indexOf('Adr')>-1;
  6452. Browser.onWP=u.indexOf("Windows Phone")>-1;
  6453. Browser.onQQBrowser=u.indexOf("QQBrowser")>-1;
  6454. Browser.onMQQBrowser=u.indexOf("MQQBrowser")>-1 || (u.indexOf("Mobile")>-1 && u.indexOf("QQ")>-1);
  6455. Browser.onIE=!!win.ActiveXObject || "ActiveXObject" in win;
  6456. Browser.onWeiXin=u.indexOf('MicroMessenger')>-1;
  6457. Browser.onSafari=/*[SAFE]*/ u.indexOf("Safari")>-1;
  6458. Browser.onPC=!Browser.onMobile;
  6459. Browser.onMiniGame=/*[SAFE]*/ u.indexOf('MiniGame')>-1;
  6460. Browser.onBDMiniGame=/*[SAFE]*/ u.indexOf('SwanGame')>-1;
  6461. if(u.indexOf('OPPO')>-1 && u.indexOf('MiniGame')>-1){
  6462. Browser.onQGMiniGame=true;
  6463. Browser.onMiniGame=false;
  6464. }
  6465. else if(laya.utils.Browser.window.hasOwnProperty("bl")&& u.indexOf('MiniGame')>-1){
  6466. Browser.onBLMiniGame=true;
  6467. Browser.onMiniGame=false;
  6468. }
  6469. else if(laya.utils.Browser.window.hasOwnProperty("qq")&& u.indexOf('MiniGame')>-1){
  6470. Browser.onQQMiniGame=true;
  6471. Browser.onMiniGame=false;
  6472. }
  6473. Browser.onVVMiniGame=/*[SAFE]*/ u.indexOf('VVGame')>-1;
  6474. Browser.onLimixiu=/*[SAFE]*/ u.indexOf('limixiu')>-1;
  6475. Browser.onKGMiniGame=/*[SAFE]*/ u.indexOf('QuickGame')>-1;
  6476. if(u.indexOf('AlipayMiniGame')>-1){
  6477. Browser.onAlipayMiniGame=true;
  6478. Browser.onMiniGame=false;
  6479. }
  6480. Browser.supportLocalStorage=LocalStorage.__init__();
  6481. Browser.supportWebAudio=SoundManager.__init__();
  6482. Render._mainCanvas=new HTMLCanvas(true);
  6483. var style=Render._mainCanvas.source.style;
  6484. style.position='absolute';
  6485. style.top=style.left="0px";
  6486. style.background="#000000";
  6487. Browser.canvas=new HTMLCanvas(true);
  6488. Browser.context=Browser.canvas.getContext('2d');
  6489. var tmpCanv=new HTMLCanvas(true);
  6490. if(laya.utils.Browser.onQGMiniGame || laya.utils.Browser.onVVMiniGame)
  6491. tmpCanv=Render._mainCanvas;
  6492. var names=["webgl","experimental-webgl","webkit-3d","moz-webgl"];
  6493. var gl=null;
  6494. for (i=0;i < names.length;i++){
  6495. try {
  6496. gl=tmpCanv.source.getContext(names[i]);
  6497. }catch (e){}
  6498. if (gl){
  6499. Browser._supportWebGL=true;
  6500. break ;
  6501. }
  6502. }
  6503. return win;
  6504. }
  6505. Browser.createElement=function(type){
  6506. Browser.__init__();
  6507. return Browser._document.createElement(type);
  6508. }
  6509. Browser.getElementById=function(type){
  6510. Browser.__init__();
  6511. return Browser._document.getElementById(type);
  6512. }
  6513. Browser.removeElement=function(ele){
  6514. if (ele && ele.parentNode)ele.parentNode.removeChild(ele);
  6515. }
  6516. Browser.now=function(){
  6517. return /*__JS__ */Date.now();;
  6518. }
  6519. Browser.userAgent=null;
  6520. Browser.onMobile=false;
  6521. Browser.onIOS=false;
  6522. Browser.onMac=false;
  6523. Browser.onIPhone=false;
  6524. Browser.onIPad=false;
  6525. Browser.onAndroid=false;
  6526. Browser.onWP=false;
  6527. Browser.onQQBrowser=false;
  6528. Browser.onMQQBrowser=false;
  6529. Browser.onSafari=false;
  6530. Browser.onIE=false;
  6531. Browser.onWeiXin=false;
  6532. Browser.onPC=false;
  6533. Browser.onMiniGame=false;
  6534. Browser.onBDMiniGame=false;
  6535. Browser.onVVMiniGame=false;
  6536. Browser.onKGMiniGame=false;
  6537. Browser.onQGMiniGame=false;
  6538. Browser.onBLMiniGame=false;
  6539. Browser.onAlipayMiniGame=false;
  6540. Browser.onQQMiniGame=false;
  6541. Browser.onLimixiu=false;
  6542. Browser.onFirefox=false;
  6543. Browser.onEdge=false;
  6544. Browser.supportWebAudio=false;
  6545. Browser.supportLocalStorage=false;
  6546. Browser.canvas=null;
  6547. Browser.context=null;
  6548. Browser._window=null;
  6549. Browser._document=null;
  6550. Browser._container=null;
  6551. Browser._pixelRatio=-1;
  6552. Browser._supportWebGL=false;
  6553. return Browser;
  6554. })()
  6555. /**
  6556. *@private
  6557. *Graphic bounds数据类
  6558. */
  6559. //class laya.display.GraphicsBounds
  6560. var GraphicsBounds=(function(){
  6561. function GraphicsBounds(){
  6562. /**@private */
  6563. //this._temp=null;
  6564. /**@private */
  6565. //this._bounds=null;
  6566. /**@private */
  6567. //this._rstBoundPoints=null;
  6568. /**@private */
  6569. this._cacheBoundsType=false;
  6570. /**@private */
  6571. //this._graphics=null;
  6572. }
  6573. __class(GraphicsBounds,'laya.display.GraphicsBounds');
  6574. var __proto=GraphicsBounds.prototype;
  6575. /**
  6576. *销毁
  6577. */
  6578. __proto.destroy=function(){
  6579. this._graphics=null;
  6580. this._cacheBoundsType=false;
  6581. if (this._temp)this._temp.length=0;
  6582. if (this._rstBoundPoints)this._rstBoundPoints.length=0;
  6583. if (this._bounds)this._bounds.recover();
  6584. this._bounds=null;
  6585. Pool.recover("GraphicsBounds",this);
  6586. }
  6587. /**
  6588. *重置数据
  6589. */
  6590. __proto.reset=function(){
  6591. this._temp && (this._temp.length=0);
  6592. }
  6593. /**
  6594. *获取位置及宽高信息矩阵(比较耗CPU,频繁使用会造成卡顿,尽量少用)。
  6595. *@param realSize (可选)使用图片的真实大小,默认为false
  6596. *@return 位置与宽高组成的 一个 Rectangle 对象。
  6597. */
  6598. __proto.getBounds=function(realSize){
  6599. (realSize===void 0)&& (realSize=false);
  6600. if (!this._bounds || !this._temp || this._temp.length < 1 || realSize !=this._cacheBoundsType){
  6601. this._bounds=Rectangle._getWrapRec(this.getBoundPoints(realSize),this._bounds)
  6602. }
  6603. this._cacheBoundsType=realSize;
  6604. return this._bounds;
  6605. }
  6606. /**
  6607. *@private
  6608. *@param realSize (可选)使用图片的真实大小,默认为false
  6609. *获取端点列表。
  6610. */
  6611. __proto.getBoundPoints=function(realSize){
  6612. (realSize===void 0)&& (realSize=false);
  6613. if (!this._temp || this._temp.length < 1 || realSize !=this._cacheBoundsType)
  6614. this._temp=this._getCmdPoints(realSize);
  6615. this._cacheBoundsType=realSize;
  6616. return this._rstBoundPoints=Utils.copyArray(this._rstBoundPoints,this._temp);
  6617. }
  6618. __proto._getCmdPoints=function(realSize){
  6619. (realSize===void 0)&& (realSize=false);
  6620. var context=Render._context;
  6621. var cmds=this._graphics.cmds;
  6622. var rst;
  6623. rst=this._temp || (this._temp=[]);
  6624. rst.length=0;
  6625. if (!cmds && this._graphics._one !=null){
  6626. GraphicsBounds._tempCmds.length=0;
  6627. GraphicsBounds._tempCmds.push(this._graphics._one);
  6628. cmds=GraphicsBounds._tempCmds;
  6629. }
  6630. if (!cmds)return rst;
  6631. var matrixs=GraphicsBounds._tempMatrixArrays;
  6632. matrixs.length=0;
  6633. var tMatrix=GraphicsBounds._initMatrix;
  6634. tMatrix.identity();
  6635. var tempMatrix=GraphicsBounds._tempMatrix;
  6636. var cmd;
  6637. var tex;
  6638. for (var i=0,n=cmds.length;i < n;i++){
  6639. cmd=cmds[i];
  6640. switch (cmd.cmdID){
  6641. case /*laya.display.cmd.AlphaCmd.ID*/"Alpha":
  6642. matrixs.push(tMatrix);
  6643. tMatrix=tMatrix.clone();
  6644. break ;
  6645. case /*laya.display.cmd.RestoreCmd.ID*/"Restore":
  6646. tMatrix=matrixs.pop();
  6647. break ;
  6648. case /*laya.display.cmd.ScaleCmd.ID*/"Scale":
  6649. tempMatrix.identity();
  6650. tempMatrix.translate(-cmd.pivotX,-cmd.pivotY);
  6651. tempMatrix.scale(cmd.scaleX,cmd.scaleY);
  6652. tempMatrix.translate(cmd.pivotX,cmd.pivotY);
  6653. this._switchMatrix(tMatrix,tempMatrix);
  6654. break ;
  6655. case /*laya.display.cmd.RotateCmd.ID*/"Rotate":
  6656. tempMatrix.identity();
  6657. tempMatrix.translate(-cmd.pivotX,-cmd.pivotY);
  6658. tempMatrix.rotate(cmd.angle);
  6659. tempMatrix.translate(cmd.pivotX,cmd.pivotY);
  6660. this._switchMatrix(tMatrix,tempMatrix);
  6661. break ;
  6662. case /*laya.display.cmd.TranslateCmd.ID*/"Translate":
  6663. tempMatrix.identity();
  6664. tempMatrix.translate(cmd.tx,cmd.ty);
  6665. this._switchMatrix(tMatrix,tempMatrix);
  6666. break ;
  6667. case /*laya.display.cmd.TransformCmd.ID*/"Transform":
  6668. tempMatrix.identity();
  6669. tempMatrix.translate(-cmd.pivotX,-cmd.pivotY);
  6670. tempMatrix.concat(cmd.matrix);
  6671. tempMatrix.translate(cmd.pivotX,cmd.pivotY);
  6672. this._switchMatrix(tMatrix,tempMatrix);
  6673. break ;
  6674. case /*laya.display.cmd.DrawImageCmd.ID*/"DrawImage":
  6675. case /*laya.display.cmd.FillTextureCmd.ID*/"FillTexture":
  6676. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tMatrix);
  6677. break ;
  6678. case /*laya.display.cmd.DrawTextureCmd.ID*/"DrawTexture":
  6679. tMatrix.copyTo(tempMatrix);
  6680. if(cmd.matrix)
  6681. tempMatrix.concat(cmd.matrix);
  6682. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tempMatrix);
  6683. break ;
  6684. case /*laya.display.cmd.DrawImageCmd.ID*/"DrawImage":
  6685. tex=cmd.texture;
  6686. if (realSize){
  6687. if (cmd.width && cmd.height){
  6688. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tMatrix);
  6689. }else {
  6690. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,tex.width,tex.height),tMatrix);
  6691. }
  6692. }else {
  6693. var wRate=(cmd.width || tex.sourceWidth)/ tex.width;
  6694. var hRate=(cmd.height || tex.sourceHeight)/ tex.height;
  6695. var oWidth=wRate *tex.sourceWidth;
  6696. var oHeight=hRate *tex.sourceHeight;
  6697. var offX=tex.offsetX > 0 ? tex.offsetX :0;
  6698. var offY=tex.offsetY > 0 ? tex.offsetY :0;
  6699. offX *=wRate;
  6700. offY *=hRate;
  6701. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x-offX,cmd.y-offY,oWidth,oHeight),tMatrix);
  6702. }
  6703. break ;
  6704. case /*laya.display.cmd.FillTextureCmd.ID*/"FillTexture":
  6705. if (cmd.width && cmd.height){
  6706. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tMatrix);
  6707. }else {
  6708. tex=cmd.texture;
  6709. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,tex.width,tex.height),tMatrix);
  6710. }
  6711. break ;
  6712. case /*laya.display.cmd.DrawTextureCmd.ID*/"DrawTexture":;
  6713. var drawMatrix;
  6714. if (cmd.matrix){
  6715. tMatrix.copyTo(tempMatrix);
  6716. tempMatrix.concat(cmd.matrix);
  6717. drawMatrix=tempMatrix;
  6718. }else {
  6719. drawMatrix=tMatrix;
  6720. }
  6721. if (realSize){
  6722. if (cmd.width && cmd.height){
  6723. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),drawMatrix);
  6724. }else {
  6725. tex=cmd.texture;
  6726. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,tex.width,tex.height),drawMatrix);
  6727. }
  6728. }else {
  6729. tex=cmd.texture;
  6730. wRate=(cmd.width || tex.sourceWidth)/ tex.width;
  6731. hRate=(cmd.height || tex.sourceHeight)/ tex.height;
  6732. oWidth=wRate *tex.sourceWidth;
  6733. oHeight=hRate *tex.sourceHeight;
  6734. offX=tex.offsetX > 0 ? tex.offsetX :0;
  6735. offY=tex.offsetY > 0 ? tex.offsetY :0;
  6736. offX *=wRate;
  6737. offY *=hRate;
  6738. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x-offX,cmd.y-offY,oWidth,oHeight),drawMatrix);
  6739. }
  6740. break ;
  6741. case /*laya.display.cmd.DrawRectCmd.ID*/"DrawRect":
  6742. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tMatrix);
  6743. break ;
  6744. case /*laya.display.cmd.DrawCircleCmd.ID*/"DrawCircle":
  6745. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x-cmd.radius,cmd.y-cmd.radius,cmd.radius+cmd.radius,cmd.radius+cmd.radius),tMatrix);
  6746. break ;
  6747. case /*laya.display.cmd.DrawLineCmd.ID*/"DrawLine":
  6748. GraphicsBounds._tempPoints.length=0;
  6749. var lineWidth=NaN;
  6750. lineWidth=cmd.lineWidth *0.5;
  6751. if (cmd.fromX==cmd.toX){
  6752. GraphicsBounds._tempPoints.push(cmd.fromX+lineWidth,cmd.fromY,cmd.toX+lineWidth,cmd.toY,cmd.fromX-lineWidth,cmd.fromY,cmd.toX-lineWidth,cmd.toY);
  6753. }else if (cmd.fromY==cmd.toY){
  6754. GraphicsBounds._tempPoints.push(cmd.fromX,cmd.fromY+lineWidth,cmd.toX,cmd.toY+lineWidth,cmd.fromX,cmd.fromY-lineWidth,cmd.toX,cmd.toY-lineWidth);
  6755. }else {
  6756. GraphicsBounds._tempPoints.push(cmd.fromX,cmd.fromY,cmd.toX,cmd.toY);
  6757. }
  6758. GraphicsBounds._addPointArrToRst(rst,GraphicsBounds._tempPoints,tMatrix);
  6759. break ;
  6760. case /*laya.display.cmd.DrawCurvesCmd.ID*/"DrawCurves":
  6761. GraphicsBounds._addPointArrToRst(rst,Bezier.I.getBezierPoints(cmd.points),tMatrix,cmd.x,cmd.y);
  6762. break ;
  6763. case /*laya.display.cmd.DrawLinesCmd.ID*/"DrawLines":
  6764. case /*laya.display.cmd.DrawPolyCmd.ID*/"DrawPoly":
  6765. GraphicsBounds._addPointArrToRst(rst,cmd.points,tMatrix,cmd.x,cmd.y);
  6766. break ;
  6767. case /*laya.display.cmd.DrawPathCmd.ID*/"DrawPath":
  6768. GraphicsBounds._addPointArrToRst(rst,this._getPathPoints(cmd.paths),tMatrix,cmd.x,cmd.y);
  6769. break ;
  6770. case /*laya.display.cmd.DrawPieCmd.ID*/"DrawPie":
  6771. GraphicsBounds._addPointArrToRst(rst,this._getPiePoints(cmd.x,cmd.y,cmd.radius,cmd.startAngle,cmd.endAngle),tMatrix);
  6772. break ;
  6773. }
  6774. }
  6775. if (rst.length > 200){
  6776. rst=Utils.copyArray(rst,Rectangle._getWrapRec(rst)._getBoundPoints());
  6777. }else if (rst.length > 8)
  6778. rst=GrahamScan.scanPList(rst);
  6779. return rst;
  6780. }
  6781. __proto._switchMatrix=function(tMatix,tempMatrix){
  6782. tempMatrix.concat(tMatix);
  6783. tempMatrix.copyTo(tMatix);
  6784. }
  6785. /**
  6786. *获得drawPie命令可能的产生的点。注意 这里只假设用在包围盒计算上。
  6787. *@param x
  6788. *@param y
  6789. *@param radius
  6790. *@param startAngle
  6791. *@param endAngle
  6792. *@return
  6793. */
  6794. __proto._getPiePoints=function(x,y,radius,startAngle,endAngle){
  6795. var rst=GraphicsBounds._tempPoints;
  6796. GraphicsBounds._tempPoints.length=0;
  6797. var k=Math.PI / 180;
  6798. var d1=endAngle-startAngle;
  6799. if (d1 >=360 || d1 <=-360){
  6800. rst.push(x-radius,y-radius);
  6801. rst.push(x+radius,y-radius);
  6802. rst.push(x+radius,y+radius);
  6803. rst.push(x-radius,y+radius);
  6804. return rst;
  6805. }
  6806. rst.push(x,y);
  6807. var delta=d1 % 360;
  6808. if (delta < 0)delta+=360;
  6809. var end1=startAngle+delta;
  6810. var st=startAngle *k;
  6811. var ed=end1 *k;
  6812. rst.push(x+radius *Math.cos(st),y+radius *Math.sin(st));
  6813. rst.push(x+radius *Math.cos(ed),y+radius *Math.sin(ed));
  6814. var s1=Math.ceil(startAngle / 90)*90;
  6815. var s2=Math.floor(end1 / 90)*90;
  6816. for (var cs=s1;cs <=s2;cs+=90){
  6817. var csr=cs *k;
  6818. rst.push(x+radius *Math.cos(csr),y+radius *Math.sin(csr));
  6819. }
  6820. return rst;
  6821. }
  6822. /*
  6823. var segnum:int=32;
  6824. var step:Number=delta / segnum;
  6825. var i:Number;
  6826. var angle:Number=startAngle;
  6827. for (i=0;i <=segnum;i++){
  6828. rst.push(x+radius *Math.cos(angle),y+radius *Math.sin(angle));
  6829. angle+=step;
  6830. }
  6831. */
  6832. __proto._getPathPoints=function(paths){
  6833. var i=0,len=0;
  6834. var rst=GraphicsBounds._tempPoints;
  6835. rst.length=0;
  6836. len=paths.length;
  6837. var tCMD;
  6838. for (i=0;i < len;i++){
  6839. tCMD=paths[i];
  6840. if (tCMD.length > 1){
  6841. rst.push(tCMD[1],tCMD[2]);
  6842. if (tCMD.length > 3){
  6843. rst.push(tCMD[3],tCMD[4]);
  6844. }
  6845. }
  6846. }
  6847. return rst;
  6848. }
  6849. GraphicsBounds.create=function(){
  6850. return Pool.getItemByClass("GraphicsBounds",GraphicsBounds);
  6851. }
  6852. GraphicsBounds._addPointArrToRst=function(rst,points,matrix,dx,dy){
  6853. (dx===void 0)&& (dx=0);
  6854. (dy===void 0)&& (dy=0);
  6855. var i=0,len=0;
  6856. len=points.length;
  6857. for (i=0;i < len;i+=2){
  6858. GraphicsBounds._addPointToRst(rst,points[i]+dx,points[i+1]+dy,matrix);
  6859. }
  6860. }
  6861. GraphicsBounds._addPointToRst=function(rst,x,y,matrix){
  6862. var _tempPoint=Point.TEMP;
  6863. _tempPoint.setTo(x ? x :0,y ? y :0);
  6864. matrix.transformPoint(_tempPoint);
  6865. rst.push(_tempPoint.x,_tempPoint.y);
  6866. }
  6867. GraphicsBounds._tempPoints=[];
  6868. GraphicsBounds._tempMatrixArrays=[];
  6869. GraphicsBounds._tempCmds=[];
  6870. __static(GraphicsBounds,
  6871. ['_tempMatrix',function(){return this._tempMatrix=new Matrix();},'_initMatrix',function(){return this._initMatrix=new Matrix();}
  6872. ]);
  6873. return GraphicsBounds;
  6874. })()
  6875. /**
  6876. *@private
  6877. *<code>Render</code> 是渲染管理类。它是一个单例,可以使用 Laya.render 访问。
  6878. */
  6879. //class laya.renders.Render
  6880. var Render=(function(){
  6881. function Render(width,height){
  6882. /**@private */
  6883. this._timeId=0;
  6884. Render._mainCanvas.source.id="layaCanvas";
  6885. Render._mainCanvas.source.width=width;
  6886. Render._mainCanvas.source.height=height;
  6887. if (laya.renders.Render.isConchApp){
  6888. Browser.document.body.appendChild(Render._mainCanvas.source);
  6889. }
  6890. else{
  6891. if(!Browser.onKGMiniGame){
  6892. Browser.container.appendChild(Render._mainCanvas.source);
  6893. }
  6894. }
  6895. this.initRender(Render._mainCanvas,width,height);
  6896. Browser.window.requestAnimationFrame(loop);
  6897. function loop (stamp){
  6898. Laya.stage._loop();
  6899. Browser.window.requestAnimationFrame(loop);
  6900. }
  6901. Laya.stage.on("visibilitychange",this,this._onVisibilitychange);
  6902. }
  6903. __class(Render,'laya.renders.Render');
  6904. var __proto=Render.prototype;
  6905. /**@private */
  6906. __proto._onVisibilitychange=function(){
  6907. if (!Laya.stage.isVisibility){
  6908. this._timeId=Browser.window.setInterval(this._enterFrame,1000);
  6909. }else if (this._timeId !=0){
  6910. Browser.window.clearInterval(this._timeId);
  6911. }
  6912. }
  6913. __proto.initRender=function(canvas,w,h){
  6914. function getWebGLContext (canvas){
  6915. var gl;
  6916. var names=["webgl2","webgl","experimental-webgl","webkit-3d","moz-webgl"];
  6917. if (!Config.useWebGL2){
  6918. names.shift();
  6919. }
  6920. for (var i=0;i < names.length;i++){
  6921. try {
  6922. gl=canvas.getContext(names[i],{stencil:Config.isStencil,alpha:Config.isAlpha,antialias:Config.isAntialias,premultipliedAlpha:Config.premultipliedAlpha,preserveDrawingBuffer:Config.preserveDrawingBuffer});
  6923. }catch (e){}
  6924. if (gl){
  6925. (names[i]==='webgl2')&& (WebGL._isWebGL2=true);
  6926. new LayaGL();
  6927. return gl;
  6928. }
  6929. }
  6930. return null;
  6931. };
  6932. var gl=LayaGL.instance=WebGL.mainContext=getWebGLContext(laya.renders.Render._mainCanvas.source);
  6933. if (!gl)
  6934. return false;
  6935. canvas.size(w,h);
  6936. WebGLContext.__init__(gl);
  6937. Context.__init__();
  6938. Submit.__init__();
  6939. var ctx=new Context();
  6940. ctx.isMain=true;
  6941. laya.renders.Render._context=ctx;
  6942. canvas._setContext(ctx);
  6943. WebGL.shaderHighPrecision=false;
  6944. try {
  6945. var precisionFormat=gl.getShaderPrecisionFormat(/*laya.webgl.WebGLContext.FRAGMENT_SHADER*/0x8B30,/*laya.webgl.WebGLContext.HIGH_FLOAT*/0x8DF2);
  6946. precisionFormat.precision ? WebGL.shaderHighPrecision=true :WebGL.shaderHighPrecision=false;
  6947. }catch (e){}
  6948. LayaGL.instance=gl;
  6949. System.__init__();
  6950. ShaderDefines2D.__init__();
  6951. Value2D.__init__();
  6952. Shader2D.__init__();
  6953. Buffer2D.__int__(gl);
  6954. BlendMode._init_(gl);
  6955. return true;
  6956. }
  6957. /**@private */
  6958. __proto._enterFrame=function(e){
  6959. Laya.stage._loop();
  6960. }
  6961. /**目前使用的渲染器。*/
  6962. __getset(1,Render,'context',function(){
  6963. return Render._context;
  6964. });
  6965. /**渲染使用的原生画布引用。 */
  6966. __getset(1,Render,'canvas',function(){
  6967. return Render._mainCanvas.source;
  6968. });
  6969. Render._context=null;
  6970. Render._mainCanvas=null;
  6971. Render.supportWebGLPlusCulling=false;
  6972. Render.supportWebGLPlusAnimation=false;
  6973. Render.supportWebGLPlusRendering=false;
  6974. Render.isConchApp=false;
  6975. Render.is3DMode=false;
  6976. Render.__init$=function(){{
  6977. Render.isConchApp=/*__JS__ */(window.conch !=null);
  6978. if (Render.isConchApp){
  6979. Render.supportWebGLPlusCulling=true;
  6980. Render.supportWebGLPlusAnimation=true;
  6981. Render.supportWebGLPlusRendering=true;
  6982. }
  6983. };;
  6984. }
  6985. return Render;
  6986. })()
  6987. /**
  6988. *@private
  6989. */
  6990. //class laya.webgl.WebGL
  6991. var WebGL=(function(){
  6992. function WebGL(){}
  6993. __class(WebGL,'laya.webgl.WebGL');
  6994. WebGL._uint8ArraySlice=function(){
  6995. var _this=/*__JS__ */this;
  6996. var sz=_this.length;
  6997. var dec=new Uint8Array(_this.length);
  6998. for (var i=0;i < sz;i++)dec[i]=_this[i];
  6999. return dec;
  7000. }
  7001. WebGL._float32ArraySlice=function(){
  7002. var _this=/*__JS__ */this;
  7003. var sz=_this.length;
  7004. var dec=new Float32Array(_this.length);
  7005. for (var i=0;i < sz;i++)dec[i]=_this[i];
  7006. return dec;
  7007. }
  7008. WebGL._uint16ArraySlice=function(__arg){
  7009. var arg=arguments;
  7010. var _this=/*__JS__ */this;
  7011. var sz=0;
  7012. var dec;
  7013. var i=0;
  7014. if (arg.length===0){
  7015. sz=_this.length;
  7016. dec=new Uint16Array(sz);
  7017. for (i=0;i < sz;i++)
  7018. dec[i]=_this[i];
  7019. }else if (arg.length===2){
  7020. var start=arg[0];
  7021. var end=arg[1];
  7022. if (end > start){
  7023. sz=end-start;
  7024. dec=new Uint16Array(sz);
  7025. for (i=start;i < end;i++)
  7026. dec[i-start]=_this[i];
  7027. }else {
  7028. dec=new Uint16Array(0);
  7029. }
  7030. }
  7031. return dec;
  7032. }
  7033. WebGL._nativeRender_enable=function(){
  7034. if (WebGL.isNativeRender_enable)
  7035. return;
  7036. WebGL.isNativeRender_enable=true;
  7037. WebGLContext.__init_native();
  7038. Shader.prototype.uploadTexture2D=function (value){
  7039. var CTX=WebGLContext;
  7040. CTX.bindTexture(laya.webgl.WebGL.mainContext,CTX.TEXTURE_2D,value);
  7041. }
  7042. RenderState2D.width=Browser.window.innerWidth;
  7043. RenderState2D.height=Browser.window.innerHeight;
  7044. RunDriver.measureText=function (txt,font){
  7045. window["conchTextCanvas"].font=font;
  7046. return window["conchTextCanvas"].measureText(txt);
  7047. }
  7048. RunDriver.enableNative=function (){
  7049. if (Render.supportWebGLPlusRendering){
  7050. (LayaGLRunner).uploadShaderUniforms=LayaGLRunner.uploadShaderUniformsForNative;
  7051. /*__JS__ */CommandEncoder=window.GLCommandEncoder;
  7052. /*__JS__ */LayaGL=window.LayaGLContext;
  7053. };
  7054. var stage=Stage;
  7055. stage.prototype.render=stage.prototype.renderToNative;
  7056. }
  7057. RunDriver.clear=function (color){
  7058. Context.set2DRenderConfig();
  7059. var c=ColorUtils.create(color).arrColor;
  7060. var gl=LayaGL.instance;
  7061. if (c)gl.clearColor(c[0],c[1],c[2],c[3]);
  7062. gl.clear(/*laya.webgl.WebGLContext.COLOR_BUFFER_BIT*/0x00004000 | /*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100 | /*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400);
  7063. RenderState2D.clear();
  7064. }
  7065. RunDriver.drawToCanvas=RunDriver.drawToTexture=function (sprite,_renderType,canvasWidth,canvasHeight,offsetX,offsetY){
  7066. offsetX-=sprite.x;
  7067. offsetY-=sprite.y;
  7068. offsetX |=0;
  7069. offsetY |=0;
  7070. canvasWidth |=0;
  7071. canvasHeight |=0;
  7072. var canv=new HTMLCanvas(false);
  7073. var ctx=canv.getContext('2d');
  7074. canv.size(canvasWidth,canvasHeight);
  7075. ctx.asBitmap=true;
  7076. ctx._targets.start();
  7077. RenderSprite.renders[_renderType]._fun(sprite,ctx,offsetX,offsetY);
  7078. ctx.flush();
  7079. ctx._targets.end();
  7080. ctx._targets.restore();
  7081. return canv;
  7082. }
  7083. RenderTexture2D.prototype._uv=RenderTexture2D.flipyuv;
  7084. Object["defineProperty"](RenderTexture2D.prototype,"uv",{
  7085. "get":function (){
  7086. return this._uv;
  7087. },
  7088. "set":function (v){
  7089. this._uv=v;
  7090. }
  7091. });
  7092. HTMLCanvas.prototype.getTexture=function (){
  7093. if (!this._texture){
  7094. this._texture=this.context._targets;
  7095. this._texture.uv=RenderTexture2D.flipyuv;
  7096. this._texture.bitmap=this._texture;
  7097. }
  7098. return this._texture;
  7099. }
  7100. }
  7101. WebGL.enable=function(){
  7102. return true;
  7103. }
  7104. WebGL.inner_enable=function(){
  7105. Float32Array.prototype.slice || (Float32Array.prototype.slice=WebGL._float32ArraySlice);
  7106. Uint16Array.prototype.slice || (Uint16Array.prototype.slice=WebGL._uint16ArraySlice);
  7107. Uint8Array.prototype.slice || (Uint8Array.prototype.slice=WebGL._uint8ArraySlice);
  7108. if (Render.isConchApp){
  7109. WebGL._nativeRender_enable();
  7110. }
  7111. return true;
  7112. }
  7113. WebGL.onStageResize=function(width,height){
  7114. if (WebGL.mainContext==null)return;
  7115. WebGL.mainContext.viewport(0,0,width,height);
  7116. RenderState2D.width=width;
  7117. RenderState2D.height=height;
  7118. }
  7119. WebGL.mainContext=null;
  7120. WebGL.shaderHighPrecision=false;
  7121. WebGL._isWebGL2=false;
  7122. WebGL.isNativeRender_enable=false;
  7123. return WebGL;
  7124. })()
  7125. /**
  7126. *...
  7127. *@author ww
  7128. */
  7129. //class laya.layagl.QuickTestTool
  7130. var QuickTestTool=(function(){
  7131. function QuickTestTool(){
  7132. this._renderType=0;
  7133. this._repaint=0;
  7134. this._x=NaN;
  7135. this._y=NaN;
  7136. }
  7137. __class(QuickTestTool,'laya.layagl.QuickTestTool');
  7138. var __proto=QuickTestTool.prototype;
  7139. //TODO:coverage
  7140. __proto.render=function(context,x,y){
  7141. QuickTestTool._addType(this._renderType);
  7142. QuickTestTool.showRenderTypeInfo(this._renderType);
  7143. RenderSprite.renders[this._renderType]._fun(this,context,x+this._x,y+this._y);
  7144. this._repaint=0;
  7145. }
  7146. //TODO:coverage
  7147. __proto._stageRender=function(context,x,y){
  7148. QuickTestTool._countStart();
  7149. QuickTestTool._PreStageRender.call(Laya.stage,context,x,y);
  7150. QuickTestTool._countEnd();
  7151. }
  7152. QuickTestTool.getMCDName=function(type){
  7153. return QuickTestTool._typeToNameDic[type];
  7154. }
  7155. QuickTestTool.showRenderTypeInfo=function(type,force){
  7156. (force===void 0)&& (force=false);
  7157. if (!force&&QuickTestTool.showedDic[type])
  7158. return;
  7159. QuickTestTool.showedDic[type]=true;
  7160. if (!QuickTestTool._rendertypeToStrDic[type]){
  7161. var arr=[];
  7162. var tType=0;
  7163. tType=1;
  7164. while (tType <=type){
  7165. if (tType & type){
  7166. arr.push(QuickTestTool.getMCDName(tType & type));
  7167. }
  7168. tType=tType << 1;
  7169. }
  7170. QuickTestTool._rendertypeToStrDic[type]=arr.join(",");
  7171. }
  7172. console.log("cmd:",QuickTestTool._rendertypeToStrDic[type]);
  7173. }
  7174. QuickTestTool.__init__=function(){
  7175. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.ALPHA*/0x01]="ALPHA";
  7176. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.TRANSFORM*/0x02]="TRANSFORM";
  7177. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.TEXTURE*/0x100]="TEXTURE";
  7178. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.GRAPHICS*/0x200]="GRAPHICS";
  7179. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.ONECHILD*/0x1000]="ONECHILD";
  7180. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.CHILDS*/0x2000]="CHILDS";
  7181. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.TRANSFORM*/0x02 | /*laya.display.SpriteConst.ALPHA*/0x01]="TRANSFORM|ALPHA";
  7182. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.CANVAS*/0x08]="CANVAS";
  7183. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.BLEND*/0x04]="BLEND";
  7184. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.FILTERS*/0x10]="FILTERS";
  7185. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.MASK*/0x20]="MASK";
  7186. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.CLIP*/0x40]="CLIP";
  7187. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.LAYAGL3D*/0x400]="LAYAGL3D";
  7188. }
  7189. QuickTestTool._countStart=function(){
  7190. var key;
  7191. for (key in QuickTestTool._countDic){
  7192. QuickTestTool._countDic[key]=0;
  7193. }
  7194. }
  7195. QuickTestTool._countEnd=function(){
  7196. QuickTestTool._i++;
  7197. if (QuickTestTool._i > 60){
  7198. QuickTestTool.showCountInfo();
  7199. QuickTestTool._i=0;
  7200. }
  7201. }
  7202. QuickTestTool._addType=function(type){
  7203. if (!QuickTestTool._countDic[type]){
  7204. QuickTestTool._countDic[type]=1;
  7205. }else{
  7206. QuickTestTool._countDic[type]+=1;
  7207. }
  7208. }
  7209. QuickTestTool.showCountInfo=function(){
  7210. console.log("===================");
  7211. var key;
  7212. for (key in QuickTestTool._countDic){
  7213. console.log("count:"+QuickTestTool._countDic[key]);
  7214. QuickTestTool.showRenderTypeInfo(key,true);
  7215. }
  7216. }
  7217. QuickTestTool.enableQuickTest=function(){
  7218. QuickTestTool.__init__();
  7219. Sprite["prototype"]["render"]=QuickTestTool["prototype"]["render"];
  7220. QuickTestTool._PreStageRender=Stage["prototype"]["render"];
  7221. Stage["prototype"]["render"]=QuickTestTool["prototype"]["_stageRender"];
  7222. }
  7223. QuickTestTool.showedDic={};
  7224. QuickTestTool._rendertypeToStrDic={};
  7225. QuickTestTool._typeToNameDic={};
  7226. QuickTestTool._PreStageRender=null;
  7227. QuickTestTool._countDic={};
  7228. QuickTestTool._i=0;
  7229. return QuickTestTool;
  7230. })()
  7231. /**
  7232. *WebGLRTMgr 管理WebGLRenderTarget的创建和回收
  7233. */
  7234. //class laya.resource.WebGLRTMgr
  7235. var WebGLRTMgr=(function(){
  7236. function WebGLRTMgr(){}
  7237. __class(WebGLRTMgr,'laya.resource.WebGLRTMgr');
  7238. WebGLRTMgr.getRT=function(w,h){
  7239. w=w | 0;
  7240. h=h | 0;
  7241. if (w >=10000){
  7242. console.error('getRT error! w too big');
  7243. };
  7244. var key=h *10000+w;
  7245. var sw=WebGLRTMgr.dict[key];
  7246. var ret;
  7247. if (sw){
  7248. if (sw.length > 0){
  7249. ret=sw.pop();
  7250. ret._mgrKey=key;
  7251. return ret;
  7252. }
  7253. }
  7254. ret=new RenderTexture2D(w,h,/*laya.resource.BaseTexture.FORMAT_R8G8B8A8*/1,-1);
  7255. ret._mgrKey=key;
  7256. return ret;
  7257. }
  7258. WebGLRTMgr.releaseRT=function(rt){
  7259. if (rt._mgrKey <=0)
  7260. return;
  7261. var sw=WebGLRTMgr.dict[rt._mgrKey];
  7262. !sw && (sw=[],WebGLRTMgr.dict[rt._mgrKey]=sw);
  7263. rt._mgrKey=0;
  7264. sw.push(rt);
  7265. }
  7266. WebGLRTMgr.dict={};
  7267. return WebGLRTMgr;
  7268. })()
  7269. /**
  7270. *<p> <code>Byte</code> 类提供用于优化读取、写入以及处理二进制数据的方法和属性。</p>
  7271. *<p> <code>Byte</code> 类适用于需要在字节层访问数据的高级开发人员。</p>
  7272. */
  7273. //class laya.utils.Byte
  7274. var Byte=(function(){
  7275. function Byte(data){
  7276. /**@private 是否为小端数据。*/
  7277. this._xd_=true;
  7278. /**@private */
  7279. this._allocated_=8;
  7280. /**@private 原始数据。*/
  7281. //this._d_=null;
  7282. /**@private DataView*/
  7283. //this._u8d_=null;
  7284. /**@private */
  7285. this._pos_=0;
  7286. /**@private */
  7287. this._length=0;
  7288. if (data){
  7289. this._u8d_=new Uint8Array(data);
  7290. this._d_=new DataView(this._u8d_.buffer);
  7291. this._length=this._d_.byteLength;
  7292. }else {
  7293. this._resizeBuffer(this._allocated_);
  7294. }
  7295. }
  7296. __class(Byte,'laya.utils.Byte');
  7297. var __proto=Byte.prototype;
  7298. /**@private */
  7299. __proto._resizeBuffer=function(len){
  7300. try {
  7301. var newByteView=new Uint8Array(len);
  7302. if (this._u8d_ !=null){
  7303. if (this._u8d_.length <=len)newByteView.set(this._u8d_);
  7304. else newByteView.set(this._u8d_.subarray(0,len));
  7305. }
  7306. this._u8d_=newByteView;
  7307. this._d_=new DataView(newByteView.buffer);
  7308. }catch (err){
  7309. throw "Invalid typed array length:"+len;
  7310. }
  7311. }
  7312. /**
  7313. *@private
  7314. *<p>常用于解析固定格式的字节流。</p>
  7315. *<p>先从字节流的当前字节偏移位置处读取一个 <code>Uint16</code> 值,然后以此值为长度,读取此长度的字符串。</p>
  7316. *@return 读取的字符串。
  7317. */
  7318. __proto.getString=function(){
  7319. return this.readString();
  7320. }
  7321. /**
  7322. *<p>常用于解析固定格式的字节流。</p>
  7323. *<p>先从字节流的当前字节偏移位置处读取一个 <code>Uint16</code> 值,然后以此值为长度,读取此长度的字符串。</p>
  7324. *@return 读取的字符串。
  7325. */
  7326. __proto.readString=function(){
  7327. return this._rUTF(this.getUint16());
  7328. }
  7329. /**
  7330. *@private
  7331. *<p>从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Float32Array</code> 对象并返回此对象。</p>
  7332. *<p><b>注意:</b>返回的 Float32Array 对象,在 JavaScript 环境下,是原生的 HTML5 Float32Array 对象,对此对象的读取操作都是基于运行此程序的当前主机字节序,此顺序可能与实际数据的字节序不同,如果使用此对象进行读取,需要用户知晓实际数据的字节序和当前主机字节序,如果相同,可正常读取,否则需要用户对实际数据(Float32Array.buffer)包装一层 DataView ,使用 DataView 对象可按照指定的字节序进行读取。</p>
  7333. *@param start 开始位置。
  7334. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  7335. *@return 读取的 Float32Array 对象。
  7336. */
  7337. __proto.getFloat32Array=function(start,len){
  7338. return this.readFloat32Array(start,len);
  7339. }
  7340. /**
  7341. *从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Float32Array</code> 对象并返回此对象。
  7342. *@param start 开始位置。
  7343. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  7344. *@return 读取的 Float32Array 对象。
  7345. */
  7346. __proto.readFloat32Array=function(start,len){
  7347. var end=start+len;
  7348. end=(end > this._length)? this._length :end;
  7349. var v=new Float32Array(this._d_.buffer.slice(start,end));
  7350. this._pos_=end;
  7351. return v;
  7352. }
  7353. /**
  7354. *@private
  7355. *从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Uint8Array</code> 对象并返回此对象。
  7356. *@param start 开始位置。
  7357. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  7358. *@return 读取的 Uint8Array 对象。
  7359. */
  7360. __proto.getUint8Array=function(start,len){
  7361. return this.readUint8Array(start,len);
  7362. }
  7363. /**
  7364. *从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Uint8Array</code> 对象并返回此对象。
  7365. *@param start 开始位置。
  7366. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  7367. *@return 读取的 Uint8Array 对象。
  7368. */
  7369. __proto.readUint8Array=function(start,len){
  7370. var end=start+len;
  7371. end=(end > this._length)? this._length :end;
  7372. var v=new Uint8Array(this._d_.buffer.slice(start,end));
  7373. this._pos_=end;
  7374. return v;
  7375. }
  7376. /**
  7377. *@private
  7378. *<p>从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Int16Array</code> 对象并返回此对象。</p>
  7379. *<p><b>注意:</b>返回的 Int16Array 对象,在 JavaScript 环境下,是原生的 HTML5 Int16Array 对象,对此对象的读取操作都是基于运行此程序的当前主机字节序,此顺序可能与实际数据的字节序不同,如果使用此对象进行读取,需要用户知晓实际数据的字节序和当前主机字节序,如果相同,可正常读取,否则需要用户对实际数据(Int16Array.buffer)包装一层 DataView ,使用 DataView 对象可按照指定的字节序进行读取。</p>
  7380. *@param start 开始读取的字节偏移量位置。
  7381. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  7382. *@return 读取的 Int16Array 对象。
  7383. */
  7384. __proto.getInt16Array=function(start,len){
  7385. return this.readInt16Array(start,len);
  7386. }
  7387. /**
  7388. *从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Int16Array</code> 对象并返回此对象。
  7389. *@param start 开始读取的字节偏移量位置。
  7390. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  7391. *@return 读取的 Uint8Array 对象。
  7392. */
  7393. __proto.readInt16Array=function(start,len){
  7394. var end=start+len;
  7395. end=(end > this._length)? this._length :end;
  7396. var v=new Int16Array(this._d_.buffer.slice(start,end));
  7397. this._pos_=end;
  7398. return v;
  7399. }
  7400. /**
  7401. *@private
  7402. *从字节流的当前字节偏移位置处读取一个 IEEE 754 单精度(32 位)浮点数。
  7403. *@return 单精度(32 位)浮点数。
  7404. */
  7405. __proto.getFloat32=function(){
  7406. return this.readFloat32();
  7407. }
  7408. /**
  7409. *从字节流的当前字节偏移位置处读取一个 IEEE 754 单精度(32 位)浮点数。
  7410. *@return 单精度(32 位)浮点数。
  7411. */
  7412. __proto.readFloat32=function(){
  7413. if (this._pos_+4 > this._length)throw "getFloat32 error - Out of bounds";
  7414. var v=this._d_.getFloat32(this._pos_,this._xd_);
  7415. this._pos_+=4;
  7416. return v;
  7417. }
  7418. /**
  7419. *@private
  7420. *从字节流的当前字节偏移量位置处读取一个 IEEE 754 双精度(64 位)浮点数。
  7421. *@return 双精度(64 位)浮点数。
  7422. */
  7423. __proto.getFloat64=function(){
  7424. return this.readFloat64();
  7425. }
  7426. /**
  7427. *从字节流的当前字节偏移量位置处读取一个 IEEE 754 双精度(64 位)浮点数。
  7428. *@return 双精度(64 位)浮点数。
  7429. */
  7430. __proto.readFloat64=function(){
  7431. if (this._pos_+8 > this._length)throw "getFloat64 error - Out of bounds";
  7432. var v=this._d_.getFloat64(this._pos_,this._xd_);
  7433. this._pos_+=8;
  7434. return v;
  7435. }
  7436. /**
  7437. *在字节流的当前字节偏移量位置处写入一个 IEEE 754 单精度(32 位)浮点数。
  7438. *@param value 单精度(32 位)浮点数。
  7439. */
  7440. __proto.writeFloat32=function(value){
  7441. this._ensureWrite(this._pos_+4);
  7442. this._d_.setFloat32(this._pos_,value,this._xd_);
  7443. this._pos_+=4;
  7444. }
  7445. /**
  7446. *在字节流的当前字节偏移量位置处写入一个 IEEE 754 双精度(64 位)浮点数。
  7447. *@param value 双精度(64 位)浮点数。
  7448. */
  7449. __proto.writeFloat64=function(value){
  7450. this._ensureWrite(this._pos_+8);
  7451. this._d_.setFloat64(this._pos_,value,this._xd_);
  7452. this._pos_+=8;
  7453. }
  7454. /**
  7455. *@private
  7456. *从字节流的当前字节偏移量位置处读取一个 Int32 值。
  7457. *@return Int32 值。
  7458. */
  7459. __proto.getInt32=function(){
  7460. return this.readInt32();
  7461. }
  7462. /**
  7463. *从字节流的当前字节偏移量位置处读取一个 Int32 值。
  7464. *@return Int32 值。
  7465. */
  7466. __proto.readInt32=function(){
  7467. if (this._pos_+4 > this._length)throw "getInt32 error - Out of bounds";
  7468. var float=this._d_.getInt32(this._pos_,this._xd_);
  7469. this._pos_+=4;
  7470. return float;
  7471. }
  7472. /**
  7473. *@private
  7474. *从字节流的当前字节偏移量位置处读取一个 Uint32 值。
  7475. *@return Uint32 值。
  7476. */
  7477. __proto.getUint32=function(){
  7478. return this.readUint32();
  7479. }
  7480. /**
  7481. *从字节流的当前字节偏移量位置处读取一个 Uint32 值。
  7482. *@return Uint32 值。
  7483. */
  7484. __proto.readUint32=function(){
  7485. if (this._pos_+4 > this._length)throw "getUint32 error - Out of bounds";
  7486. var v=this._d_.getUint32(this._pos_,this._xd_);
  7487. this._pos_+=4;
  7488. return v;
  7489. }
  7490. /**
  7491. *在字节流的当前字节偏移量位置处写入指定的 Int32 值。
  7492. *@param value 需要写入的 Int32 值。
  7493. */
  7494. __proto.writeInt32=function(value){
  7495. this._ensureWrite(this._pos_+4);
  7496. this._d_.setInt32(this._pos_,value,this._xd_);
  7497. this._pos_+=4;
  7498. }
  7499. /**
  7500. *在字节流的当前字节偏移量位置处写入 Uint32 值。
  7501. *@param value 需要写入的 Uint32 值。
  7502. */
  7503. __proto.writeUint32=function(value){
  7504. this._ensureWrite(this._pos_+4);
  7505. this._d_.setUint32(this._pos_,value,this._xd_);
  7506. this._pos_+=4;
  7507. }
  7508. /**
  7509. *@private
  7510. *从字节流的当前字节偏移量位置处读取一个 Int16 值。
  7511. *@return Int16 值。
  7512. */
  7513. __proto.getInt16=function(){
  7514. return this.readInt16();
  7515. }
  7516. /**
  7517. *从字节流的当前字节偏移量位置处读取一个 Int16 值。
  7518. *@return Int16 值。
  7519. */
  7520. __proto.readInt16=function(){
  7521. if (this._pos_+2 > this._length)throw "getInt16 error - Out of bounds";
  7522. var us=this._d_.getInt16(this._pos_,this._xd_);
  7523. this._pos_+=2;
  7524. return us;
  7525. }
  7526. /**
  7527. *@private
  7528. *从字节流的当前字节偏移量位置处读取一个 Uint16 值。
  7529. *@return Uint16 值。
  7530. */
  7531. __proto.getUint16=function(){
  7532. return this.readUint16();
  7533. }
  7534. /**
  7535. *从字节流的当前字节偏移量位置处读取一个 Uint16 值。
  7536. *@return Uint16 值。
  7537. */
  7538. __proto.readUint16=function(){
  7539. if (this._pos_+2 > this._length)throw "getUint16 error - Out of bounds";
  7540. var us=this._d_.getUint16(this._pos_,this._xd_);
  7541. this._pos_+=2;
  7542. return us;
  7543. }
  7544. /**
  7545. *在字节流的当前字节偏移量位置处写入指定的 Uint16 值。
  7546. *@param value 需要写入的Uint16 值。
  7547. */
  7548. __proto.writeUint16=function(value){
  7549. this._ensureWrite(this._pos_+2);
  7550. this._d_.setUint16(this._pos_,value,this._xd_);
  7551. this._pos_+=2;
  7552. }
  7553. /**
  7554. *在字节流的当前字节偏移量位置处写入指定的 Int16 值。
  7555. *@param value 需要写入的 Int16 值。
  7556. */
  7557. __proto.writeInt16=function(value){
  7558. this._ensureWrite(this._pos_+2);
  7559. this._d_.setInt16(this._pos_,value,this._xd_);
  7560. this._pos_+=2;
  7561. }
  7562. /**
  7563. *@private
  7564. *从字节流的当前字节偏移量位置处读取一个 Uint8 值。
  7565. *@return Uint8 值。
  7566. */
  7567. __proto.getUint8=function(){
  7568. return this.readUint8();
  7569. }
  7570. /**
  7571. *从字节流的当前字节偏移量位置处读取一个 Uint8 值。
  7572. *@return Uint8 值。
  7573. */
  7574. __proto.readUint8=function(){
  7575. if (this._pos_+1 > this._length)throw "getUint8 error - Out of bounds";
  7576. return this._u8d_[this._pos_++];
  7577. }
  7578. /**
  7579. *在字节流的当前字节偏移量位置处写入指定的 Uint8 值。
  7580. *@param value 需要写入的 Uint8 值。
  7581. */
  7582. __proto.writeUint8=function(value){
  7583. this._ensureWrite(this._pos_+1);
  7584. this._d_.setUint8(this._pos_,value);
  7585. this._pos_++;
  7586. }
  7587. //TODO:coverage
  7588. __proto._getUInt8=function(pos){
  7589. return this._readUInt8(pos);
  7590. }
  7591. //TODO:coverage
  7592. __proto._readUInt8=function(pos){
  7593. return this._d_.getUint8(pos);
  7594. }
  7595. //TODO:coverage
  7596. __proto._getUint16=function(pos){
  7597. return this._readUint16(pos);
  7598. }
  7599. //TODO:coverage
  7600. __proto._readUint16=function(pos){
  7601. return this._d_.getUint16(pos,this._xd_);
  7602. }
  7603. //TODO:coverage
  7604. __proto._getMatrix=function(){
  7605. return this._readMatrix();
  7606. }
  7607. //TODO:coverage
  7608. __proto._readMatrix=function(){
  7609. var rst=new Matrix(this.getFloat32(),this.getFloat32(),this.getFloat32(),this.getFloat32(),this.getFloat32(),this.getFloat32());
  7610. return rst;
  7611. }
  7612. /**
  7613. *@private
  7614. *读取指定长度的 UTF 型字符串。
  7615. *@param len 需要读取的长度。
  7616. *@return 读取的字符串。
  7617. */
  7618. __proto._rUTF=function(len){
  7619. var v="",max=this._pos_+len,c=0,c2=0,c3=0,f=String.fromCharCode;
  7620. var u=this._u8d_,i=0;
  7621. var strs=[];
  7622. var n=0;
  7623. strs.length=1000;
  7624. while (this._pos_ < max){
  7625. c=u[this._pos_++];
  7626. if (c < 0x80){
  7627. if (c !=0)
  7628. strs[n++]=f(c);
  7629. }else if (c < 0xE0){
  7630. strs[n++]=f(((c & 0x3F)<< 6)| (u[this._pos_++] & 0x7F));
  7631. }else if (c < 0xF0){
  7632. c2=u[this._pos_++];
  7633. strs[n++]=f(((c & 0x1F)<< 12)| ((c2 & 0x7F)<< 6)| (u[this._pos_++] & 0x7F));
  7634. }else {
  7635. c2=u[this._pos_++];
  7636. c3=u[this._pos_++];
  7637. strs[n++]=f(((c & 0x0F)<< 18)| ((c2 & 0x7F)<< 12)| ((c3 << 6)& 0x7F)| (u[this._pos_++] & 0x7F));
  7638. }
  7639. i++;
  7640. }
  7641. strs.length=n;
  7642. return strs.join('');
  7643. }
  7644. //TODO:coverage
  7645. __proto.getCustomString=function(len){
  7646. return this.readCustomString(len);
  7647. }
  7648. //TODO:coverage
  7649. __proto.readCustomString=function(len){
  7650. var v="",ulen=0,c=0,c2=0,f=String.fromCharCode;
  7651. var u=this._u8d_,i=0;
  7652. while (len > 0){
  7653. c=u[this._pos_];
  7654. if (c < 0x80){
  7655. v+=f(c);
  7656. this._pos_++;
  7657. len--;
  7658. }else {
  7659. ulen=c-0x80;
  7660. this._pos_++;
  7661. len-=ulen;
  7662. while (ulen > 0){
  7663. c=u[this._pos_++];
  7664. c2=u[this._pos_++];
  7665. v+=f((c2 << 8)| c);
  7666. ulen--;
  7667. }
  7668. }
  7669. }
  7670. return v;
  7671. }
  7672. /**
  7673. *清除字节数组的内容,并将 length 和 pos 属性重置为 0。调用此方法将释放 Byte 实例占用的内存。
  7674. */
  7675. __proto.clear=function(){
  7676. this._pos_=0;
  7677. this.length=0;
  7678. }
  7679. /**
  7680. *@private
  7681. *获取此对象的 ArrayBuffer 引用。
  7682. *@return
  7683. */
  7684. __proto.__getBuffer=function(){
  7685. return this._d_.buffer;
  7686. }
  7687. /**
  7688. *<p>将 UTF-8 字符串写入字节流。类似于 writeUTF()方法,但 writeUTFBytes()不使用 16 位长度的字为字符串添加前缀。</p>
  7689. *<p>对应的读取方法为: getUTFBytes 。</p>
  7690. *@param value 要写入的字符串。
  7691. */
  7692. __proto.writeUTFBytes=function(value){
  7693. value=value+"";
  7694. for (var i=0,sz=value.length;i < sz;i++){
  7695. var c=value.charCodeAt(i);
  7696. if (c <=0x7F){
  7697. this.writeByte(c);
  7698. }else if (c <=0x7FF){
  7699. this._ensureWrite(this._pos_+2);
  7700. this._u8d_.set([0xC0 | (c >> 6),0x80 | (c & 0x3F)],this._pos_);
  7701. this._pos_+=2;
  7702. }else if (c <=0xFFFF){
  7703. this._ensureWrite(this._pos_+3);
  7704. this._u8d_.set([0xE0 | (c >> 12),0x80 | ((c >> 6)& 0x3F),0x80 | (c & 0x3F)],this._pos_);
  7705. this._pos_+=3;
  7706. }else {
  7707. this._ensureWrite(this._pos_+4);
  7708. this._u8d_.set([0xF0 | (c >> 18),0x80 | ((c >> 12)& 0x3F),0x80 | ((c >> 6)& 0x3F),0x80 | (c & 0x3F)],this._pos_);
  7709. this._pos_+=4;
  7710. }
  7711. }
  7712. }
  7713. /**
  7714. *<p>将 UTF-8 字符串写入字节流。先写入以字节表示的 UTF-8 字符串长度(作为 16 位整数),然后写入表示字符串字符的字节。</p>
  7715. *<p>对应的读取方法为: getUTFString 。</p>
  7716. *@param value 要写入的字符串值。
  7717. */
  7718. __proto.writeUTFString=function(value){
  7719. var tPos=this.pos;
  7720. this.writeUint16(1);
  7721. this.writeUTFBytes(value);
  7722. var dPos=this.pos-tPos-2;
  7723. this._d_.setUint16(tPos,dPos,this._xd_);
  7724. }
  7725. /**
  7726. *@private
  7727. *读取 UTF-8 字符串。
  7728. *@return 读取的字符串。
  7729. */
  7730. __proto.readUTFString=function(){
  7731. return this.readUTFBytes(this.getUint16());
  7732. }
  7733. /**
  7734. *<p>从字节流中读取一个 UTF-8 字符串。假定字符串的前缀是一个无符号的短整型(以此字节表示要读取的长度)。</p>
  7735. *<p>对应的写入方法为: writeUTFString 。</p>
  7736. *@return 读取的字符串。
  7737. */
  7738. __proto.getUTFString=function(){
  7739. return this.readUTFString();
  7740. }
  7741. /**
  7742. *@private
  7743. *读字符串,必须是 writeUTFBytes 方法写入的字符串。
  7744. *@param len 要读的buffer长度,默认将读取缓冲区全部数据。
  7745. *@return 读取的字符串。
  7746. */
  7747. __proto.readUTFBytes=function(len){
  7748. (len===void 0)&& (len=-1);
  7749. if (len===0)return "";
  7750. var lastBytes=this.bytesAvailable;
  7751. if (len > lastBytes)throw "readUTFBytes error - Out of bounds";
  7752. len=len > 0 ? len :lastBytes;
  7753. return this._rUTF(len);
  7754. }
  7755. /**
  7756. *<p>从字节流中读取一个由 length 参数指定的长度的 UTF-8 字节序列,并返回一个字符串。</p>
  7757. *<p>一般读取的是由 writeUTFBytes 方法写入的字符串。</p>
  7758. *@param len 要读的buffer长度,默认将读取缓冲区全部数据。
  7759. *@return 读取的字符串。
  7760. */
  7761. __proto.getUTFBytes=function(len){
  7762. (len===void 0)&& (len=-1);
  7763. return this.readUTFBytes(len);
  7764. }
  7765. /**
  7766. *<p>在字节流中写入一个字节。</p>
  7767. *<p>使用参数的低 8 位。忽略高 24 位。</p>
  7768. *@param value
  7769. */
  7770. __proto.writeByte=function(value){
  7771. this._ensureWrite(this._pos_+1);
  7772. this._d_.setInt8(this._pos_,value);
  7773. this._pos_+=1;
  7774. }
  7775. /**
  7776. *<p>从字节流中读取带符号的字节。</p>
  7777. *<p>返回值的范围是从-128 到 127。</p>
  7778. *@return 介于-128 和 127 之间的整数。
  7779. */
  7780. __proto.readByte=function(){
  7781. if (this._pos_+1 > this._length)throw "readByte error - Out of bounds";
  7782. return this._d_.getInt8(this._pos_++);
  7783. }
  7784. /**
  7785. *@private
  7786. *从字节流中读取带符号的字节。
  7787. */
  7788. __proto.getByte=function(){
  7789. return this.readByte();
  7790. }
  7791. /**
  7792. *@private
  7793. *<p>保证该字节流的可用长度不小于 <code>lengthToEnsure</code> 参数指定的值。</p>
  7794. *@param lengthToEnsure 指定的长度。
  7795. */
  7796. __proto._ensureWrite=function(lengthToEnsure){
  7797. if (this._length < lengthToEnsure)this._length=lengthToEnsure;
  7798. if (this._allocated_ < lengthToEnsure)this.length=lengthToEnsure;
  7799. }
  7800. /**
  7801. *<p>将指定 arraybuffer 对象中的以 offset 为起始偏移量, length 为长度的字节序列写入字节流。</p>
  7802. *<p>如果省略 length 参数,则使用默认长度 0,该方法将从 offset 开始写入整个缓冲区;如果还省略了 offset 参数,则写入整个缓冲区。</p>
  7803. *<p>如果 offset 或 length 小于0,本函数将抛出异常。</p>
  7804. *@param arraybuffer 需要写入的 Arraybuffer 对象。
  7805. *@param offset Arraybuffer 对象的索引的偏移量(以字节为单位)
  7806. *@param length 从 Arraybuffer 对象写入到 Byte 对象的长度(以字节为单位)
  7807. */
  7808. __proto.writeArrayBuffer=function(arraybuffer,offset,length){
  7809. (offset===void 0)&& (offset=0);
  7810. (length===void 0)&& (length=0);
  7811. if (offset < 0 || length < 0)throw "writeArrayBuffer error - Out of bounds";
  7812. if (length==0)length=arraybuffer.byteLength-offset;
  7813. this._ensureWrite(this._pos_+length);
  7814. var uint8array=new Uint8Array(arraybuffer);
  7815. this._u8d_.set(uint8array.subarray(offset,offset+length),this._pos_);
  7816. this._pos_+=length;
  7817. }
  7818. /**
  7819. *读取ArrayBuffer数据
  7820. *@param length
  7821. *@return
  7822. */
  7823. __proto.readArrayBuffer=function(length){
  7824. var rst;
  7825. rst=this._u8d_.buffer.slice(this._pos_,this._pos_+length);
  7826. this._pos_=this._pos_+length
  7827. return rst;
  7828. }
  7829. /**
  7830. *获取此对象的 ArrayBuffer 数据,数据只包含有效数据部分。
  7831. */
  7832. __getset(0,__proto,'buffer',function(){
  7833. var rstBuffer=this._d_.buffer;
  7834. if (rstBuffer.byteLength===this._length)return rstBuffer;
  7835. return rstBuffer.slice(0,this._length);
  7836. });
  7837. /**
  7838. *<p> <code>Byte</code> 实例的字节序。取值为:<code>BIG_ENDIAN</code> 或 <code>BIG_ENDIAN</code> 。</p>
  7839. *<p>主机字节序,是 CPU 存放数据的两种不同顺序,包括小端字节序和大端字节序。通过 <code>getSystemEndian</code> 可以获取当前系统的字节序。</p>
  7840. *<p> <code>BIG_ENDIAN</code> :大端字节序,地址低位存储值的高位,地址高位存储值的低位。有时也称之为网络字节序。<br/>
  7841. *<code>LITTLE_ENDIAN</code> :小端字节序,地址低位存储值的低位,地址高位存储值的高位。</p>
  7842. */
  7843. __getset(0,__proto,'endian',function(){
  7844. return this._xd_ ? "littleEndian" :"bigEndian";
  7845. },function(value){
  7846. this._xd_=(value==="littleEndian");
  7847. });
  7848. /**
  7849. *<p> <code>Byte</code> 对象的长度(以字节为单位)。</p>
  7850. *<p>如果将长度设置为大于当前长度的值,则用零填充字节数组的右侧;如果将长度设置为小于当前长度的值,将会截断该字节数组。</p>
  7851. *<p>如果要设置的长度大于当前已分配的内存空间的字节长度,则重新分配内存空间,大小为以下两者较大者:要设置的长度、当前已分配的长度的2倍,并将原有数据拷贝到新的内存空间中;如果要设置的长度小于当前已分配的内存空间的字节长度,也会重新分配内存空间,大小为要设置的长度,并将原有数据从头截断为要设置的长度存入新的内存空间中。</p>
  7852. */
  7853. __getset(0,__proto,'length',function(){
  7854. return this._length;
  7855. },function(value){
  7856. if (this._allocated_ < value)this._resizeBuffer(this._allocated_=Math.floor(Math.max(value,this._allocated_ *2)));
  7857. else if (this._allocated_ > value)this._resizeBuffer(this._allocated_=value);
  7858. this._length=value;
  7859. });
  7860. /**
  7861. *移动或返回 Byte 对象的读写指针的当前位置(以字节为单位)。下一次调用读取方法时将在此位置开始读取,或者下一次调用写入方法时将在此位置开始写入。
  7862. */
  7863. __getset(0,__proto,'pos',function(){
  7864. return this._pos_;
  7865. },function(value){
  7866. this._pos_=value;
  7867. });
  7868. /**
  7869. *可从字节流的当前位置到末尾读取的数据的字节数。
  7870. */
  7871. __getset(0,__proto,'bytesAvailable',function(){
  7872. return this._length-this._pos_;
  7873. });
  7874. Byte.getSystemEndian=function(){
  7875. if (!Byte._sysEndian){
  7876. var buffer=new ArrayBuffer(2);
  7877. new DataView(buffer).setInt16(0,256,true);
  7878. Byte._sysEndian=(new Int16Array(buffer))[0]===256 ? /*CLASS CONST:laya.utils.Byte.LITTLE_ENDIAN*/"littleEndian" :/*CLASS CONST:laya.utils.Byte.BIG_ENDIAN*/"bigEndian";
  7879. }
  7880. return Byte._sysEndian;
  7881. }
  7882. Byte.BIG_ENDIAN="bigEndian";
  7883. Byte.LITTLE_ENDIAN="littleEndian";
  7884. Byte._sysEndian=null;
  7885. return Byte;
  7886. })()
  7887. //class laya.webgl.utils.ShaderNode
  7888. var ShaderNode=(function(){
  7889. function ShaderNode(includefiles){
  7890. this.childs=[];
  7891. this.text="";
  7892. this.parent=null;
  7893. this.name=null;
  7894. this.noCompile=false;
  7895. this.includefiles=null;
  7896. this.condition=null;
  7897. this.conditionType=0;
  7898. this.useFuns="";
  7899. this.z=0;
  7900. this.src=null;
  7901. this.includefiles=includefiles;
  7902. }
  7903. __class(ShaderNode,'laya.webgl.utils.ShaderNode');
  7904. var __proto=ShaderNode.prototype;
  7905. __proto.setParent=function(parent){
  7906. parent.childs.push(this);
  7907. this.z=parent.z+1;
  7908. this.parent=parent;
  7909. }
  7910. __proto.setCondition=function(condition,type){
  7911. if (condition){
  7912. this.conditionType=type;
  7913. condition=condition.replace(/(\s*$)/g,"");
  7914. this.condition=function (){
  7915. return this[condition];
  7916. }
  7917. this.condition.__condition=condition;
  7918. }
  7919. }
  7920. __proto.toscript=function(def,out){
  7921. return this._toscript(def,out,++ShaderNode.__id);
  7922. }
  7923. __proto._toscript=function(def,out,id){
  7924. if (this.childs.length < 1 && !this.text)return out;
  7925. var outIndex=out.length;
  7926. if (this.condition){
  7927. var ifdef=!!this.condition.call(def);
  7928. this.conditionType===/*laya.webgl.utils.ShaderCompile.IFDEF_ELSE*/2 && (ifdef=!ifdef);
  7929. if (!ifdef)return out;
  7930. }
  7931. this.text && out.push(this.text);
  7932. this.childs.length > 0 && this.childs.forEach(function(o,index,arr){
  7933. o._toscript(def,out,id);
  7934. });
  7935. if (this.includefiles.length > 0 && this.useFuns.length > 0){
  7936. var funsCode;
  7937. for (var i=0,n=this.includefiles.length;i < n;i++){
  7938. if (this.includefiles[i].curUseID==id){
  7939. continue ;
  7940. }
  7941. funsCode=this.includefiles[i].file.getFunsScript(this.useFuns);
  7942. if (funsCode.length > 0){
  7943. this.includefiles[i].curUseID=id;
  7944. out[0]=funsCode+out[0];
  7945. }
  7946. }
  7947. }
  7948. return out;
  7949. }
  7950. ShaderNode.__id=1;
  7951. return ShaderNode;
  7952. })()
  7953. /**
  7954. *绘制圆形
  7955. */
  7956. //class laya.display.cmd.DrawCircleCmd
  7957. var DrawCircleCmd=(function(){
  7958. function DrawCircleCmd(){
  7959. /**
  7960. *圆点X 轴位置。
  7961. */
  7962. //this.x=NaN;
  7963. /**
  7964. *圆点Y 轴位置。
  7965. */
  7966. //this.y=NaN;
  7967. /**
  7968. *半径。
  7969. */
  7970. //this.radius=NaN;
  7971. /**
  7972. *填充颜色,或者填充绘图的渐变对象。
  7973. */
  7974. //this.fillColor=null;
  7975. /**
  7976. *(可选)边框颜色,或者填充绘图的渐变对象。
  7977. */
  7978. //this.lineColor=null;
  7979. /**
  7980. *(可选)边框宽度。
  7981. */
  7982. //this.lineWidth=NaN;
  7983. /**@private */
  7984. //this.vid=0;
  7985. }
  7986. __class(DrawCircleCmd,'laya.display.cmd.DrawCircleCmd');
  7987. var __proto=DrawCircleCmd.prototype;
  7988. /**
  7989. *回收到对象池
  7990. */
  7991. __proto.recover=function(){
  7992. this.fillColor=null;
  7993. this.lineColor=null;
  7994. Pool.recover("DrawCircleCmd",this);
  7995. }
  7996. /**@private */
  7997. __proto.run=function(context,gx,gy){
  7998. context._drawCircle(this.x+gx,this.y+gy,this.radius,this.fillColor,this.lineColor,this.lineWidth,this.vid);
  7999. }
  8000. /**@private */
  8001. __getset(0,__proto,'cmdID',function(){
  8002. return "DrawCircle";
  8003. });
  8004. DrawCircleCmd.create=function(x,y,radius,fillColor,lineColor,lineWidth,vid){
  8005. var cmd=Pool.getItemByClass("DrawCircleCmd",DrawCircleCmd);
  8006. cmd.x=x;
  8007. cmd.y=y;
  8008. cmd.radius=radius;
  8009. cmd.fillColor=fillColor;
  8010. cmd.lineColor=lineColor;
  8011. cmd.lineWidth=lineWidth;
  8012. cmd.vid=vid;
  8013. return cmd;
  8014. }
  8015. DrawCircleCmd.ID="DrawCircle";
  8016. return DrawCircleCmd;
  8017. })()
  8018. /**
  8019. *TODO如果占用内存较大,这个结构有很多成员可以临时计算
  8020. */
  8021. //class laya.webgl.text.CharRenderInfo
  8022. var CharRenderInfo=(function(){
  8023. function CharRenderInfo(){
  8024. this.char='';
  8025. // 调试用
  8026. this.tex=null;
  8027. //
  8028. this.deleted=false;
  8029. // [0,0,1,1];//uv
  8030. this.pos=0;
  8031. //数组下标
  8032. this.width=0;
  8033. //字体宽度。测量的宽度,用来排版。没有缩放
  8034. this.height=0;
  8035. //字体高度。没有缩放
  8036. this.bmpWidth=0;
  8037. //实际图片的宽度。可能与排版用的width不一致。包含缩放和margin
  8038. this.bmpHeight=0;
  8039. this.orix=0;
  8040. // 原点位置,通常都是所在区域的左上角
  8041. this.oriy=0;
  8042. this.touchTick=0;
  8043. //
  8044. this.isSpace=false;
  8045. this.uv=new Array(8);
  8046. }
  8047. __class(CharRenderInfo,'laya.webgl.text.CharRenderInfo');
  8048. var __proto=CharRenderInfo.prototype;
  8049. //是否是空格,如果是空格,则只有width有效
  8050. __proto.touch=function(){
  8051. var curLoop=Stat.loopCount;
  8052. if (this.touchTick !=curLoop){
  8053. this.tex.touchRect(this,curLoop);
  8054. }
  8055. this.touchTick=curLoop;
  8056. }
  8057. return CharRenderInfo;
  8058. })()
  8059. //class laya.webgl.utils.RenderState2D
  8060. var RenderState2D=(function(){
  8061. function RenderState2D(){}
  8062. __class(RenderState2D,'laya.webgl.utils.RenderState2D');
  8063. RenderState2D.mat2MatArray=function(mat,matArray){
  8064. var m=mat;
  8065. var m4=matArray;
  8066. m4[0]=m.a;
  8067. m4[1]=m.b;
  8068. m4[2]=RenderState2D.EMPTYMAT4_ARRAY[2];
  8069. m4[3]=RenderState2D.EMPTYMAT4_ARRAY[3];
  8070. m4[4]=m.c;
  8071. m4[5]=m.d;
  8072. m4[6]=RenderState2D.EMPTYMAT4_ARRAY[6];
  8073. m4[7]=RenderState2D.EMPTYMAT4_ARRAY[7];
  8074. m4[8]=RenderState2D.EMPTYMAT4_ARRAY[8];
  8075. m4[9]=RenderState2D.EMPTYMAT4_ARRAY[9];
  8076. m4[10]=RenderState2D.EMPTYMAT4_ARRAY[10];
  8077. m4[11]=RenderState2D.EMPTYMAT4_ARRAY[11];
  8078. m4[12]=m.tx;
  8079. m4[13]=m.ty;
  8080. m4[14]=RenderState2D.EMPTYMAT4_ARRAY[14];
  8081. m4[15]=RenderState2D.EMPTYMAT4_ARRAY[15];
  8082. return matArray;
  8083. }
  8084. RenderState2D.restoreTempArray=function(){
  8085. RenderState2D.TEMPMAT4_ARRAY[0]=1;
  8086. RenderState2D.TEMPMAT4_ARRAY[1]=0;
  8087. RenderState2D.TEMPMAT4_ARRAY[4]=0;
  8088. RenderState2D.TEMPMAT4_ARRAY[5]=1;
  8089. RenderState2D.TEMPMAT4_ARRAY[12]=0;
  8090. RenderState2D.TEMPMAT4_ARRAY[13]=0;
  8091. }
  8092. RenderState2D.clear=function(){
  8093. RenderState2D.worldScissorTest=false;
  8094. RenderState2D.worldAlpha=1;
  8095. }
  8096. RenderState2D._MAXSIZE=99999999;
  8097. RenderState2D.EMPTYMAT4_ARRAY=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];
  8098. RenderState2D.TEMPMAT4_ARRAY=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];
  8099. RenderState2D.worldMatrix4=RenderState2D.TEMPMAT4_ARRAY;
  8100. RenderState2D.matWVP=null;
  8101. RenderState2D.worldAlpha=1.0;
  8102. RenderState2D.worldScissorTest=false;
  8103. RenderState2D.worldShaderDefines=null;
  8104. RenderState2D.worldFilters=null;
  8105. RenderState2D.width=0;
  8106. RenderState2D.height=0;
  8107. __static(RenderState2D,
  8108. ['worldMatrix',function(){return this.worldMatrix=new Matrix();}
  8109. ]);
  8110. return RenderState2D;
  8111. })()
  8112. /**
  8113. *Mesh2d只是保存数据。描述attribute用的。本身不具有渲染功能。
  8114. */
  8115. //class laya.webgl.utils.Mesh2D
  8116. var Mesh2D=(function(){
  8117. function Mesh2D(stride,vballoc,iballoc){
  8118. this._stride=0;
  8119. //顶点结构大小。每个mesh的顶点结构是固定的。
  8120. this.vertNum=0;
  8121. //当前的顶点的个数
  8122. this.indexNum=0;
  8123. //实际index 个数。例如一个三角形是3个。由于ib本身可能超过实际使用的数量,所以需要一个indexNum
  8124. this._applied=false;
  8125. //是否已经设置给webgl了
  8126. this._vb=null;
  8127. //vb和ib都可能需要在外部修改,所以public
  8128. this._ib=null;
  8129. this._vao=null;
  8130. this._attribInfo=null;
  8131. //保存起来的属性定义数组。
  8132. this._quadNum=0;
  8133. //public static var meshlist:Array=[];//活着的mesh对象列表。
  8134. this.canReuse=false;
  8135. this._stride=stride;
  8136. this._vb=new VertexBuffer2D(stride,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
  8137. if (vballoc){
  8138. this._vb._resizeBuffer(vballoc,false);
  8139. }else{
  8140. Config.webGL2D_MeshAllocMaxMem && this._vb._resizeBuffer(64 *1024 *stride,false);
  8141. }
  8142. this._ib=new IndexBuffer2D();
  8143. if (iballoc){
  8144. this._ib._resizeBuffer(iballoc,false);
  8145. }
  8146. }
  8147. __class(Mesh2D,'laya.webgl.utils.Mesh2D');
  8148. var __proto=Mesh2D.prototype;
  8149. //TODO:coverage
  8150. __proto.cloneWithNewVB=function(){
  8151. var mesh=new Mesh2D(this._stride,0,0);
  8152. mesh._ib=this._ib;
  8153. mesh._quadNum=this._quadNum;
  8154. mesh._attribInfo=this._attribInfo;
  8155. return mesh;
  8156. }
  8157. //TODO:coverage
  8158. __proto.cloneWithNewVBIB=function(){
  8159. var mesh=new Mesh2D(this._stride,0,0);
  8160. mesh._attribInfo=this._attribInfo;
  8161. return mesh;
  8162. }
  8163. //TODO:coverage
  8164. __proto.getVBW=function(){
  8165. this._vb.setNeedUpload();
  8166. return this._vb;
  8167. }
  8168. //TODO:coverage
  8169. __proto.getVBR=function(){
  8170. return this._vb;
  8171. }
  8172. //TODO:coverage
  8173. __proto.getIBR=function(){
  8174. return this._ib;
  8175. }
  8176. //TODO:coverage
  8177. __proto.getIBW=function(){
  8178. this._ib.setNeedUpload();
  8179. return this._ib;
  8180. }
  8181. /**
  8182. *直接创建一个固定的ib。按照固定四边形的索引。
  8183. *@param var QuadNum
  8184. */
  8185. __proto.createQuadIB=function(QuadNum){
  8186. this._quadNum=QuadNum;
  8187. this._ib._resizeBuffer(QuadNum *6 *2,false);
  8188. this._ib.byteLength=this._ib.bufferLength;
  8189. var bd=this._ib.getUint16Array();
  8190. var idx=0;
  8191. var curvert=0;
  8192. for (var i=0;i < QuadNum;i++){
  8193. bd[idx++]=curvert;
  8194. bd[idx++]=curvert+2;
  8195. bd[idx++]=curvert+1;
  8196. bd[idx++]=curvert;
  8197. bd[idx++]=curvert+3;
  8198. bd[idx++]=curvert+2;
  8199. curvert+=4;
  8200. }
  8201. this._ib.setNeedUpload();
  8202. }
  8203. /**
  8204. *设置mesh的属性。每3个一组,对应的location分别是0,1,2...
  8205. *含义是:type,size,offset
  8206. *不允许多流。因此stride是固定的,offset只是在一个vertex之内。
  8207. *@param attribs
  8208. */
  8209. __proto.setAttributes=function(attribs){
  8210. this._attribInfo=attribs;
  8211. if (this._attribInfo.length % 3 !=0){
  8212. throw 'Mesh2D setAttributes error!';
  8213. }
  8214. }
  8215. /**
  8216. *初始化VAO的配置,只需要执行一次。以后使用的时候直接bind就行
  8217. *@param gl
  8218. */
  8219. __proto.configVAO=function(gl){
  8220. if (this._applied)
  8221. return;
  8222. this._applied=true;
  8223. if (!this._vao){
  8224. this._vao=new BufferState2D();
  8225. }
  8226. this._vao.bind();
  8227. this._vb._bindForVAO();
  8228. this._ib.setNeedUpload();
  8229. this._ib._bind_uploadForVAO();
  8230. var attribNum=this._attribInfo.length / 3;
  8231. var idx=0;
  8232. for (var i=0;i < attribNum;i++){
  8233. var _size=this._attribInfo[idx+1];
  8234. var _type=this._attribInfo[idx];
  8235. var _off=this._attribInfo[idx+2];
  8236. gl.enableVertexAttribArray(i);
  8237. gl.vertexAttribPointer(i,_size,_type,false,this._stride,_off);
  8238. idx+=3;
  8239. }
  8240. this._vao.unBind();
  8241. }
  8242. /**
  8243. *应用这个mesh
  8244. *@param gl
  8245. */
  8246. __proto.useMesh=function(gl){
  8247. this._applied || this.configVAO(gl);
  8248. this._vao.bind();
  8249. this._vb.bind();
  8250. this._ib._bind_upload()|| this._ib.bind();
  8251. this._vb._bind_upload()|| this._vb.bind();
  8252. }
  8253. //TODO:coverage
  8254. __proto.getEleNum=function(){
  8255. return this._ib.getBuffer().byteLength / 2;
  8256. }
  8257. /**
  8258. *子类实现。用来把自己放到对应的回收池中,以便复用。
  8259. */
  8260. __proto.releaseMesh=function(){}
  8261. /**
  8262. *释放资源。
  8263. */
  8264. __proto.destroy=function(){}
  8265. /**
  8266. *清理vb数据
  8267. */
  8268. __proto.clearVB=function(){
  8269. this._vb.clear();
  8270. }
  8271. Mesh2D._gvaoid=0;
  8272. return Mesh2D;
  8273. })()
  8274. /**
  8275. *@private
  8276. *<code>Dragging</code> 类是触摸滑动控件。
  8277. */
  8278. //class laya.utils.Dragging
  8279. var Dragging=(function(){
  8280. function Dragging(){
  8281. /**被拖动的对象。*/
  8282. //this.target=null;
  8283. /**缓动衰减系数。*/
  8284. this.ratio=0.92;
  8285. /**单帧最大偏移量。*/
  8286. this.maxOffset=60;
  8287. /**滑动范围。*/
  8288. //this.area=null;
  8289. /**表示拖动是否有惯性。*/
  8290. //this.hasInertia=false;
  8291. /**橡皮筋最大值。*/
  8292. //this.elasticDistance=NaN;
  8293. /**橡皮筋回弹时间,单位为毫秒。*/
  8294. //this.elasticBackTime=NaN;
  8295. /**事件携带数据。*/
  8296. //this.data=null;
  8297. this._dragging=false;
  8298. this._clickOnly=true;
  8299. //this._elasticRateX=NaN;
  8300. //this._elasticRateY=NaN;
  8301. //this._lastX=NaN;
  8302. //this._lastY=NaN;
  8303. //this._offsetX=NaN;
  8304. //this._offsetY=NaN;
  8305. //this._offsets=null;
  8306. //this._disableMouseEvent=false;
  8307. //this._tween=null;
  8308. //this._parent=null;
  8309. }
  8310. __class(Dragging,'laya.utils.Dragging');
  8311. var __proto=Dragging.prototype;
  8312. /**
  8313. *开始拖拽。
  8314. *@param target 待拖拽的 <code>Sprite</code> 对象。
  8315. *@param area 滑动范围。
  8316. *@param hasInertia 拖动是否有惯性。
  8317. *@param elasticDistance 橡皮筋最大值。
  8318. *@param elasticBackTime 橡皮筋回弹时间,单位为毫秒。
  8319. *@param data 事件携带数据。
  8320. *@param disableMouseEvent 鼠标事件是否有效。
  8321. *@param ratio 惯性阻尼系数
  8322. */
  8323. __proto.start=function(target,area,hasInertia,elasticDistance,elasticBackTime,data,disableMouseEvent,ratio){
  8324. (ratio===void 0)&& (ratio=0.92);
  8325. this.clearTimer();
  8326. this.target=target;
  8327. this.area=area;
  8328. this.hasInertia=hasInertia;
  8329. this.elasticDistance=area ? elasticDistance :0;
  8330. this.elasticBackTime=elasticBackTime;
  8331. this.data=data;
  8332. this._disableMouseEvent=disableMouseEvent;
  8333. this.ratio=ratio;
  8334. this._parent=target.parent;
  8335. this._clickOnly=true;
  8336. this._dragging=true;
  8337. this._elasticRateX=this._elasticRateY=1;
  8338. this._lastX=this._parent.mouseX;
  8339. this._lastY=this._parent.mouseY;
  8340. Laya.stage.on(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onStageMouseUp);
  8341. Laya.stage.on(/*laya.events.Event.MOUSE_OUT*/"mouseout",this,this.onStageMouseUp);
  8342. Laya.systemTimer.frameLoop(1,this,this.loop);
  8343. }
  8344. /**
  8345. *清除计时器。
  8346. */
  8347. __proto.clearTimer=function(){
  8348. Laya.systemTimer.clear(this,this.loop);
  8349. Laya.systemTimer.clear(this,this.tweenMove);
  8350. if (this._tween){
  8351. this._tween.recover();
  8352. this._tween=null;
  8353. }
  8354. }
  8355. /**
  8356. *停止拖拽。
  8357. */
  8358. __proto.stop=function(){
  8359. if (this._dragging){
  8360. MouseManager.instance.disableMouseEvent=false;
  8361. Laya.stage.off(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onStageMouseUp);
  8362. Laya.stage.off(/*laya.events.Event.MOUSE_OUT*/"mouseout",this,this.onStageMouseUp);
  8363. this._dragging=false;
  8364. this.target && this.area && this.backToArea();
  8365. this.clear();
  8366. }
  8367. }
  8368. /**
  8369. *拖拽的循环处理函数。
  8370. */
  8371. __proto.loop=function(){
  8372. var point=this._parent.getMousePoint();
  8373. var mouseX=point.x;
  8374. var mouseY=point.y;
  8375. var offsetX=mouseX-this._lastX;
  8376. var offsetY=mouseY-this._lastY;
  8377. if (this._clickOnly){
  8378. if (Math.abs(offsetX *Laya.stage._canvasTransform.getScaleX())> 1 || Math.abs(offsetY *Laya.stage._canvasTransform.getScaleY())> 1){
  8379. this._clickOnly=false;
  8380. this._offsets || (this._offsets=[]);
  8381. this._offsets.length=0;
  8382. this.target.event(/*laya.events.Event.DRAG_START*/"dragstart",this.data);
  8383. MouseManager.instance.disableMouseEvent=this._disableMouseEvent;
  8384. }else return;
  8385. }else {
  8386. this._offsets.push(offsetX,offsetY);
  8387. }
  8388. if (offsetX===0 && offsetY===0)return;
  8389. this._lastX=mouseX;
  8390. this._lastY=mouseY;
  8391. this.target.x+=offsetX *this._elasticRateX;
  8392. this.target.y+=offsetY *this._elasticRateY;
  8393. this.area && this.checkArea();
  8394. this.target.event(/*laya.events.Event.DRAG_MOVE*/"dragmove",this.data);
  8395. }
  8396. /**
  8397. *拖拽区域检测。
  8398. */
  8399. __proto.checkArea=function(){
  8400. if (this.elasticDistance <=0){
  8401. this.backToArea();
  8402. }else {
  8403. if (this.target._x < this.area.x){
  8404. var offsetX=this.area.x-this.target._x;
  8405. }else if (this.target._x > this.area.x+this.area.width){
  8406. offsetX=this.target._x-this.area.x-this.area.width;
  8407. }else {
  8408. offsetX=0;
  8409. }
  8410. this._elasticRateX=Math.max(0,1-(offsetX / this.elasticDistance));
  8411. if (this.target._y < this.area.y){
  8412. var offsetY=this.area.y-this.target.y;
  8413. }else if (this.target._y > this.area.y+this.area.height){
  8414. offsetY=this.target._y-this.area.y-this.area.height;
  8415. }else {
  8416. offsetY=0;
  8417. }
  8418. this._elasticRateY=Math.max(0,1-(offsetY / this.elasticDistance));
  8419. }
  8420. }
  8421. /**
  8422. *移动至设定的拖拽区域。
  8423. */
  8424. __proto.backToArea=function(){
  8425. this.target.x=Math.min(Math.max(this.target._x,this.area.x),this.area.x+this.area.width);
  8426. this.target.y=Math.min(Math.max(this.target._y,this.area.y),this.area.y+this.area.height);
  8427. }
  8428. /**
  8429. *舞台的抬起事件侦听函数。
  8430. *@param e Event 对象。
  8431. */
  8432. __proto.onStageMouseUp=function(e){
  8433. MouseManager.instance.disableMouseEvent=false;
  8434. Laya.stage.off(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onStageMouseUp);
  8435. Laya.stage.off(/*laya.events.Event.MOUSE_OUT*/"mouseout",this,this.onStageMouseUp);
  8436. Laya.systemTimer.clear(this,this.loop);
  8437. if (this._clickOnly || !this.target)return;
  8438. if (this.hasInertia){
  8439. if (this._offsets.length < 1){
  8440. this._offsets.push(this._parent.mouseX-this._lastX,this._parent.mouseY-this._lastY);
  8441. }
  8442. this._offsetX=this._offsetY=0;
  8443. var len=this._offsets.length;
  8444. var n=Math.min(len,6);
  8445. var m=this._offsets.length-n;
  8446. for (var i=len-1;i > m;i--){
  8447. this._offsetY+=this._offsets[i--];
  8448. this._offsetX+=this._offsets[i];
  8449. }
  8450. this._offsetX=this._offsetX / n *2;
  8451. this._offsetY=this._offsetY / n *2;
  8452. if (Math.abs(this._offsetX)> this.maxOffset)this._offsetX=this._offsetX > 0 ? this.maxOffset :-this.maxOffset;
  8453. if (Math.abs(this._offsetY)> this.maxOffset)this._offsetY=this._offsetY > 0 ? this.maxOffset :-this.maxOffset;
  8454. Laya.systemTimer.frameLoop(1,this,this.tweenMove);
  8455. }else if (this.elasticDistance > 0){
  8456. this.checkElastic();
  8457. }else {
  8458. this.clear();
  8459. }
  8460. }
  8461. /**
  8462. *橡皮筋效果检测。
  8463. */
  8464. __proto.checkElastic=function(){
  8465. var tx=NaN;
  8466. var ty=NaN;
  8467. if (this.target.x < this.area.x)tx=this.area.x;
  8468. else if (this.target._x > this.area.x+this.area.width)tx=this.area.x+this.area.width;
  8469. if (this.target.y < this.area.y)ty=this.area.y;
  8470. else if (this.target._y > this.area.y+this.area.height)ty=this.area.y+this.area.height;
  8471. if (!isNaN(tx)|| !isNaN(ty)){
  8472. var obj={};
  8473. if (!isNaN(tx))obj.x=tx;
  8474. if (!isNaN(ty))obj.y=ty;
  8475. this._tween=Tween.to(this.target,obj,this.elasticBackTime,Ease.sineOut,Handler.create(this,this.clear),0,false,false);
  8476. }else {
  8477. this.clear();
  8478. }
  8479. }
  8480. /**
  8481. *移动。
  8482. */
  8483. __proto.tweenMove=function(){
  8484. this._offsetX *=this.ratio *this._elasticRateX;
  8485. this._offsetY *=this.ratio *this._elasticRateY;
  8486. this.target.x+=this._offsetX;
  8487. this.target.y+=this._offsetY;
  8488. this.area && this.checkArea();
  8489. this.target.event(/*laya.events.Event.DRAG_MOVE*/"dragmove",this.data);
  8490. if ((Math.abs(this._offsetX)< 1 && Math.abs(this._offsetY)< 1)|| this._elasticRateX < 0.5 || this._elasticRateY < 0.5){
  8491. Laya.systemTimer.clear(this,this.tweenMove);
  8492. if (this.elasticDistance > 0)this.checkElastic();
  8493. else this.clear();
  8494. }
  8495. }
  8496. /**
  8497. *结束拖拽。
  8498. */
  8499. __proto.clear=function(){
  8500. if (this.target){
  8501. this.clearTimer();
  8502. var sp=this.target;
  8503. this.target=null;
  8504. this._parent=null;
  8505. sp.event(/*laya.events.Event.DRAG_END*/"dragend",this.data);
  8506. }
  8507. }
  8508. return Dragging;
  8509. })()
  8510. /**
  8511. *<code>Ease</code> 类定义了缓动函数,以便实现 <code>Tween</code> 动画的缓动效果。
  8512. */
  8513. //class laya.utils.Ease
  8514. var Ease=(function(){
  8515. function Ease(){}
  8516. __class(Ease,'laya.utils.Ease');
  8517. Ease.linearNone=function(t,b,c,d){
  8518. return c *t / d+b;
  8519. }
  8520. Ease.linearIn=function(t,b,c,d){
  8521. return c *t / d+b;
  8522. }
  8523. Ease.linearInOut=function(t,b,c,d){
  8524. return c *t / d+b;
  8525. }
  8526. Ease.linearOut=function(t,b,c,d){
  8527. return c *t / d+b;
  8528. }
  8529. Ease.bounceIn=function(t,b,c,d){
  8530. return c-Ease.bounceOut(d-t,0,c,d)+b;
  8531. }
  8532. Ease.bounceInOut=function(t,b,c,d){
  8533. if (t < d *0.5)return Ease.bounceIn(t *2,0,c,d)*.5+b;
  8534. else return Ease.bounceOut(t *2-d,0,c,d)*.5+c *.5+b;
  8535. }
  8536. Ease.bounceOut=function(t,b,c,d){
  8537. if ((t /=d)< (1 / 2.75))return c *(7.5625 *t *t)+b;
  8538. else if (t < (2 / 2.75))return c *(7.5625 *(t-=(1.5 / 2.75))*t+.75)+b;
  8539. else if (t < (2.5 / 2.75))return c *(7.5625 *(t-=(2.25 / 2.75))*t+.9375)+b;
  8540. else return c *(7.5625 *(t-=(2.625 / 2.75))*t+.984375)+b;
  8541. }
  8542. Ease.backIn=function(t,b,c,d,s){
  8543. (s===void 0)&& (s=1.70158);
  8544. return c *(t /=d)*t *((s+1)*t-s)+b;
  8545. }
  8546. Ease.backInOut=function(t,b,c,d,s){
  8547. (s===void 0)&& (s=1.70158);
  8548. if ((t /=d *0.5)< 1)return c *0.5 *(t *t *(((s *=(1.525))+1)*t-s))+b;
  8549. return c / 2 *((t-=2)*t *(((s *=(1.525))+1)*t+s)+2)+b;
  8550. }
  8551. Ease.backOut=function(t,b,c,d,s){
  8552. (s===void 0)&& (s=1.70158);
  8553. return c *((t=t / d-1)*t *((s+1)*t+s)+1)+b;
  8554. }
  8555. Ease.elasticIn=function(t,b,c,d,a,p){
  8556. (a===void 0)&& (a=0);
  8557. (p===void 0)&& (p=0);
  8558. var s;
  8559. if (t==0)return b;
  8560. if ((t /=d)==1)return b+c;
  8561. if (!p)p=d *.3;
  8562. if (!a || (c > 0 && a < c)|| (c < 0 && a <-c)){
  8563. a=c;
  8564. s=p / 4;
  8565. }else s=p / Ease.PI2 *Math.asin(c / a);
  8566. return-(a *Math.pow(2,10 *(t-=1))*Math.sin((t *d-s)*Ease.PI2 / p))+b;
  8567. }
  8568. Ease.elasticInOut=function(t,b,c,d,a,p){
  8569. (a===void 0)&& (a=0);
  8570. (p===void 0)&& (p=0);
  8571. var s;
  8572. if (t==0)return b;
  8573. if ((t /=d *0.5)==2)return b+c;
  8574. if (!p)p=d *(.3 *1.5);
  8575. if (!a || (c > 0 && a < c)|| (c < 0 && a <-c)){
  8576. a=c;
  8577. s=p / 4;
  8578. }else s=p / Ease.PI2 *Math.asin(c / a);
  8579. if (t < 1)return-.5 *(a *Math.pow(2,10 *(t-=1))*Math.sin((t *d-s)*Ease.PI2 / p))+b;
  8580. return a *Math.pow(2,-10 *(t-=1))*Math.sin((t *d-s)*Ease.PI2 / p)*.5+c+b;
  8581. }
  8582. Ease.elasticOut=function(t,b,c,d,a,p){
  8583. (a===void 0)&& (a=0);
  8584. (p===void 0)&& (p=0);
  8585. var s;
  8586. if (t==0)return b;
  8587. if ((t /=d)==1)return b+c;
  8588. if (!p)p=d *.3;
  8589. if (!a || (c > 0 && a < c)|| (c < 0 && a <-c)){
  8590. a=c;
  8591. s=p / 4;
  8592. }else s=p / Ease.PI2 *Math.asin(c / a);
  8593. return (a *Math.pow(2,-10 *t)*Math.sin((t *d-s)*Ease.PI2 / p)+c+b);
  8594. }
  8595. Ease.strongIn=function(t,b,c,d){
  8596. return c *(t /=d)*t *t *t *t+b;
  8597. }
  8598. Ease.strongInOut=function(t,b,c,d){
  8599. if ((t /=d *0.5)< 1)return c *0.5 *t *t *t *t *t+b;
  8600. return c *0.5 *((t-=2)*t *t *t *t+2)+b;
  8601. }
  8602. Ease.strongOut=function(t,b,c,d){
  8603. return c *((t=t / d-1)*t *t *t *t+1)+b;
  8604. }
  8605. Ease.sineInOut=function(t,b,c,d){
  8606. return-c *0.5 *(Math.cos(Math.PI *t / d)-1)+b;
  8607. }
  8608. Ease.sineIn=function(t,b,c,d){
  8609. return-c *Math.cos(t / d *Ease.HALF_PI)+c+b;
  8610. }
  8611. Ease.sineOut=function(t,b,c,d){
  8612. return c *Math.sin(t / d *Ease.HALF_PI)+b;
  8613. }
  8614. Ease.quintIn=function(t,b,c,d){
  8615. return c *(t /=d)*t *t *t *t+b;
  8616. }
  8617. Ease.quintInOut=function(t,b,c,d){
  8618. if ((t /=d *0.5)< 1)return c *0.5 *t *t *t *t *t+b;
  8619. return c *0.5 *((t-=2)*t *t *t *t+2)+b;
  8620. }
  8621. Ease.quintOut=function(t,b,c,d){
  8622. return c *((t=t / d-1)*t *t *t *t+1)+b;
  8623. }
  8624. Ease.quartIn=function(t,b,c,d){
  8625. return c *(t /=d)*t *t *t+b;
  8626. }
  8627. Ease.quartInOut=function(t,b,c,d){
  8628. if ((t /=d *0.5)< 1)return c *0.5 *t *t *t *t+b;
  8629. return-c *0.5 *((t-=2)*t *t *t-2)+b;
  8630. }
  8631. Ease.quartOut=function(t,b,c,d){
  8632. return-c *((t=t / d-1)*t *t *t-1)+b;
  8633. }
  8634. Ease.cubicIn=function(t,b,c,d){
  8635. return c *(t /=d)*t *t+b;
  8636. }
  8637. Ease.cubicInOut=function(t,b,c,d){
  8638. if ((t /=d *0.5)< 1)return c *0.5 *t *t *t+b;
  8639. return c *0.5 *((t-=2)*t *t+2)+b;
  8640. }
  8641. Ease.cubicOut=function(t,b,c,d){
  8642. return c *((t=t / d-1)*t *t+1)+b;
  8643. }
  8644. Ease.quadIn=function(t,b,c,d){
  8645. return c *(t /=d)*t+b;
  8646. }
  8647. Ease.quadInOut=function(t,b,c,d){
  8648. if ((t /=d *0.5)< 1)return c *0.5 *t *t+b;
  8649. return-c *0.5 *((--t)*(t-2)-1)+b;
  8650. }
  8651. Ease.quadOut=function(t,b,c,d){
  8652. return-c *(t /=d)*(t-2)+b;
  8653. }
  8654. Ease.expoIn=function(t,b,c,d){
  8655. return (t==0)? b :c *Math.pow(2,10 *(t / d-1))+b-c *0.001;
  8656. }
  8657. Ease.expoInOut=function(t,b,c,d){
  8658. if (t==0)return b;
  8659. if (t==d)return b+c;
  8660. if ((t /=d *0.5)< 1)return c *0.5 *Math.pow(2,10 *(t-1))+b;
  8661. return c *0.5 *(-Math.pow(2,-10 *--t)+2)+b;
  8662. }
  8663. Ease.expoOut=function(t,b,c,d){
  8664. return (t==d)? b+c :c *(-Math.pow(2,-10 *t / d)+1)+b;
  8665. }
  8666. Ease.circIn=function(t,b,c,d){
  8667. return-c *(Math.sqrt(1-(t /=d)*t)-1)+b;
  8668. }
  8669. Ease.circInOut=function(t,b,c,d){
  8670. if ((t /=d *0.5)< 1)return-c *0.5 *(Math.sqrt(1-t *t)-1)+b;
  8671. return c *0.5 *(Math.sqrt(1-(t-=2)*t)+1)+b;
  8672. }
  8673. Ease.circOut=function(t,b,c,d){
  8674. return c *Math.sqrt(1-(t=t / d-1)*t)+b;
  8675. }
  8676. Ease.HALF_PI=Math.PI *0.5;
  8677. Ease.PI2=Math.PI *2;
  8678. return Ease;
  8679. })()
  8680. /**
  8681. *<code>SoundManager</code> 是一个声音管理类。提供了对背景音乐、音效的播放控制方法。
  8682. *引擎默认有两套声音方案:WebAudio和H5Audio
  8683. *播放音效,优先使用WebAudio播放声音,如果WebAudio不可用,则用H5Audio播放,H5Audio在部分机器上有兼容问题(比如不能混音,播放有延迟等)。
  8684. *播放背景音乐,则使用H5Audio播放(使用WebAudio会增加特别大的内存,并且要等加载完毕后才能播放,有延迟)
  8685. *建议背景音乐用mp3类型,音效用wav或者mp3类型(如果打包为app,音效只能用wav格式)。
  8686. *详细教程及声音格式请参考:http://ldc2.layabox.com/doc/?nav=ch-as-1-7-0
  8687. */
  8688. //class laya.media.SoundManager
  8689. var SoundManager=(function(){
  8690. function SoundManager(){}
  8691. __class(SoundManager,'laya.media.SoundManager');
  8692. __getset(1,SoundManager,'useAudioMusic',function(){
  8693. return SoundManager._useAudioMusic;
  8694. },function(value){
  8695. SoundManager._useAudioMusic=value;
  8696. if (value){
  8697. SoundManager._musicClass=AudioSound;
  8698. }else{
  8699. SoundManager._musicClass=null;
  8700. }
  8701. });
  8702. /**
  8703. *失去焦点后是否自动停止背景音乐。
  8704. *@param v Boolean 失去焦点后是否自动停止背景音乐。
  8705. *
  8706. */
  8707. /**
  8708. *失去焦点后是否自动停止背景音乐。
  8709. */
  8710. __getset(1,SoundManager,'autoStopMusic',function(){
  8711. return SoundManager._autoStopMusic;
  8712. },function(v){
  8713. Laya.stage.off(/*laya.events.Event.BLUR*/"blur",null,SoundManager._stageOnBlur);
  8714. Laya.stage.off(/*laya.events.Event.FOCUS*/"focus",null,SoundManager._stageOnFocus);
  8715. Laya.stage.off(/*laya.events.Event.VISIBILITY_CHANGE*/"visibilitychange",null,SoundManager._visibilityChange);
  8716. SoundManager._autoStopMusic=v;
  8717. if (v){
  8718. Laya.stage.on(/*laya.events.Event.BLUR*/"blur",null,SoundManager._stageOnBlur);
  8719. Laya.stage.on(/*laya.events.Event.FOCUS*/"focus",null,SoundManager._stageOnFocus);
  8720. Laya.stage.on(/*laya.events.Event.VISIBILITY_CHANGE*/"visibilitychange",null,SoundManager._visibilityChange);
  8721. }
  8722. });
  8723. /**
  8724. *背景音乐和所有音效是否静音。
  8725. */
  8726. __getset(1,SoundManager,'muted',function(){
  8727. return SoundManager._muted;
  8728. },function(value){
  8729. if (value==SoundManager._muted)return;
  8730. if (value){
  8731. SoundManager.stopAllSound();
  8732. }
  8733. SoundManager.musicMuted=value;
  8734. SoundManager._muted=value;
  8735. });
  8736. /**
  8737. *背景音乐(不包括音效)是否静音。
  8738. */
  8739. __getset(1,SoundManager,'musicMuted',function(){
  8740. return SoundManager._musicMuted;
  8741. },function(value){
  8742. if (value==SoundManager._musicMuted)return;
  8743. if (value){
  8744. if (SoundManager._bgMusic){
  8745. if (SoundManager._musicChannel&&!SoundManager._musicChannel.isStopped){
  8746. if (Render.isConchApp){
  8747. /*__JS__ */if (SoundManager._musicChannel._audio)SoundManager._musicChannel._audio.muted=true;;
  8748. }
  8749. else {
  8750. SoundManager._musicChannel.pause();
  8751. }
  8752. }else{
  8753. SoundManager._musicChannel=null;
  8754. }
  8755. }else{
  8756. SoundManager._musicChannel=null;
  8757. }
  8758. SoundManager._musicMuted=value;
  8759. }else {
  8760. SoundManager._musicMuted=value;
  8761. if (SoundManager._bgMusic){
  8762. if (SoundManager._musicChannel){
  8763. if (Render.isConchApp){
  8764. /*__JS__ */if(SoundManager._musicChannel._audio)SoundManager._musicChannel._audio.muted=false;;
  8765. }
  8766. else {
  8767. SoundManager._musicChannel.resume();
  8768. }
  8769. }
  8770. }
  8771. }
  8772. });
  8773. /**
  8774. *所有音效(不包括背景音乐)是否静音。
  8775. */
  8776. __getset(1,SoundManager,'soundMuted',function(){
  8777. return SoundManager._soundMuted;
  8778. },function(value){
  8779. SoundManager._soundMuted=value;
  8780. });
  8781. SoundManager.__init__=function(){
  8782. var win=Browser.window;
  8783. var supportWebAudio=win["AudioContext"] || win["webkitAudioContext"] || win["mozAudioContext"] ? true :false;
  8784. if (supportWebAudio)WebAudioSound.initWebAudio();
  8785. SoundManager._soundClass=supportWebAudio?WebAudioSound:AudioSound;
  8786. AudioSound._initMusicAudio();
  8787. SoundManager._musicClass=AudioSound;
  8788. return supportWebAudio;
  8789. }
  8790. SoundManager.addChannel=function(channel){
  8791. if (SoundManager._channels.indexOf(channel)>=0)return;
  8792. SoundManager._channels.push(channel);
  8793. }
  8794. SoundManager.removeChannel=function(channel){
  8795. var i=0;
  8796. for (i=SoundManager._channels.length-1;i >=0;i--){
  8797. if (SoundManager._channels[i]==channel){
  8798. SoundManager._channels.splice(i,1);
  8799. }
  8800. }
  8801. }
  8802. SoundManager.disposeSoundLater=function(url){
  8803. SoundManager._lastSoundUsedTimeDic[url]=Browser.now();
  8804. if (!SoundManager._isCheckingDispose){
  8805. SoundManager._isCheckingDispose=true;
  8806. Laya.timer.loop(5000,null,SoundManager._checkDisposeSound);
  8807. }
  8808. }
  8809. SoundManager._checkDisposeSound=function(){
  8810. var key;
  8811. var tTime=Browser.now();
  8812. var hasCheck=false;
  8813. for (key in SoundManager._lastSoundUsedTimeDic){
  8814. if (tTime-SoundManager._lastSoundUsedTimeDic[key]>30000){
  8815. delete SoundManager._lastSoundUsedTimeDic[key];
  8816. SoundManager.disposeSoundIfNotUsed(key);
  8817. }else{
  8818. hasCheck=true;
  8819. }
  8820. }
  8821. if (!hasCheck){
  8822. SoundManager._isCheckingDispose=false;
  8823. Laya.timer.clear(null,SoundManager._checkDisposeSound);
  8824. }
  8825. }
  8826. SoundManager.disposeSoundIfNotUsed=function(url){
  8827. var i=0;
  8828. for (i=SoundManager._channels.length-1;i >=0;i--){
  8829. if (SoundManager._channels[i].url==url){
  8830. return;
  8831. }
  8832. }
  8833. SoundManager.destroySound(url);
  8834. }
  8835. SoundManager._visibilityChange=function(){
  8836. if (Laya.stage.isVisibility){
  8837. SoundManager._stageOnFocus();
  8838. }else {
  8839. SoundManager._stageOnBlur();
  8840. }
  8841. }
  8842. SoundManager._stageOnBlur=function(){
  8843. SoundManager._isActive=false;
  8844. if (SoundManager._musicChannel){
  8845. if (!SoundManager._musicChannel.isStopped){
  8846. SoundManager._blurPaused=true;
  8847. SoundManager._musicChannel.pause();
  8848. }
  8849. }
  8850. SoundManager.stopAllSound();
  8851. Laya.stage.once(/*laya.events.Event.MOUSE_DOWN*/"mousedown",null,SoundManager._stageOnFocus);
  8852. }
  8853. SoundManager._recoverWebAudio=function(){
  8854. if(WebAudioSound.ctx&&WebAudioSound.ctx.state!="running"&&WebAudioSound.ctx.resume)
  8855. WebAudioSound.ctx.resume();
  8856. }
  8857. SoundManager._stageOnFocus=function(){
  8858. SoundManager._isActive=true;
  8859. SoundManager._recoverWebAudio();
  8860. Laya.stage.off(/*laya.events.Event.MOUSE_DOWN*/"mousedown",null,SoundManager._stageOnFocus);
  8861. if (SoundManager._blurPaused){
  8862. if (SoundManager._musicChannel && SoundManager._musicChannel.isStopped){
  8863. SoundManager._blurPaused=false;
  8864. SoundManager._musicChannel.resume();
  8865. }
  8866. }
  8867. }
  8868. SoundManager.playSound=function(url,loops,complete,soundClass,startTime){
  8869. (loops===void 0)&& (loops=1);
  8870. (startTime===void 0)&& (startTime=0);
  8871. if (!SoundManager._isActive || !url)return null;
  8872. if (SoundManager._muted)return null;
  8873. SoundManager._recoverWebAudio();
  8874. url=URL.formatURL(url);
  8875. if (url==SoundManager._bgMusic){
  8876. if (SoundManager._musicMuted)return null;
  8877. }else {
  8878. if (Render.isConchApp){
  8879. var ext=Utils.getFileExtension(url);
  8880. if (ext !="wav" && ext !="ogg"){
  8881. alert("The sound only supports wav or ogg format,for optimal performance reason,please refer to the official website document.");
  8882. return null;
  8883. }
  8884. }
  8885. if (SoundManager._soundMuted)return null;
  8886. };
  8887. var tSound;
  8888. if (!Browser.onMiniGame && !Browser.onBLMiniGame && !Browser.onQQMiniGame && !Browser.onQGMiniGame && !Browser.onVVMiniGame && !Browser.onBDMiniGame && !Browser.onKGMiniGame){
  8889. tSound=Laya.loader.getRes(url);
  8890. }
  8891. if (!soundClass)soundClass=SoundManager._soundClass;
  8892. if (!tSound){
  8893. tSound=new soundClass();
  8894. tSound.load(url);
  8895. if (!Browser.onMiniGame && !Browser.onBLMiniGame && !Browser.onQQMiniGame && !Browser.onQGMiniGame && !Browser.onVVMiniGame && !Browser.onBDMiniGame && !Browser.onKGMiniGame){
  8896. Loader.cacheRes(url,tSound);
  8897. }
  8898. };
  8899. var channel;
  8900. channel=tSound.play(startTime,loops);
  8901. if (!channel)return null;
  8902. channel.url=url;
  8903. channel.volume=(url==SoundManager._bgMusic)? SoundManager.musicVolume :SoundManager.soundVolume;
  8904. channel.completeHandler=complete;
  8905. return channel;
  8906. }
  8907. SoundManager.destroySound=function(url){
  8908. var tSound=Laya.loader.getRes(url);
  8909. if (tSound){
  8910. Loader.clearRes(url);
  8911. tSound.dispose();
  8912. }
  8913. }
  8914. SoundManager.playMusic=function(url,loops,complete,startTime){
  8915. (loops===void 0)&& (loops=0);
  8916. (startTime===void 0)&& (startTime=0);
  8917. url=URL.formatURL(url);
  8918. SoundManager._bgMusic=url;
  8919. if (SoundManager._musicChannel)SoundManager._musicChannel.stop();
  8920. return SoundManager._musicChannel=SoundManager.playSound(url,loops,complete,SoundManager._musicClass,startTime);
  8921. }
  8922. SoundManager.stopSound=function(url){
  8923. url=URL.formatURL(url);
  8924. var i=0;
  8925. var channel;
  8926. for (i=SoundManager._channels.length-1;i >=0;i--){
  8927. channel=SoundManager._channels[i];
  8928. if (channel.url==url){
  8929. channel.stop();
  8930. }
  8931. }
  8932. }
  8933. SoundManager.stopAll=function(){
  8934. SoundManager._bgMusic=null;
  8935. var i=0;
  8936. var channel;
  8937. for (i=SoundManager._channels.length-1;i >=0;i--){
  8938. channel=SoundManager._channels[i];
  8939. channel.stop();
  8940. }
  8941. }
  8942. SoundManager.stopAllSound=function(){
  8943. var i=0;
  8944. var channel;
  8945. for (i=SoundManager._channels.length-1;i >=0;i--){
  8946. channel=SoundManager._channels[i];
  8947. if (channel.url !=SoundManager._bgMusic){
  8948. channel.stop();
  8949. }
  8950. }
  8951. }
  8952. SoundManager.stopMusic=function(){
  8953. if (SoundManager._musicChannel)SoundManager._musicChannel.stop();
  8954. SoundManager._bgMusic=null;
  8955. }
  8956. SoundManager.setSoundVolume=function(volume,url){
  8957. if (url){
  8958. url=URL.formatURL(url);
  8959. SoundManager._setVolume(url,volume);
  8960. }else {
  8961. SoundManager.soundVolume=volume;
  8962. var i=0;
  8963. var channel;
  8964. for (i=SoundManager._channels.length-1;i >=0;i--){
  8965. channel=SoundManager._channels[i];
  8966. if (channel.url !=SoundManager._bgMusic){
  8967. channel.volume=volume;
  8968. }
  8969. }
  8970. }
  8971. }
  8972. SoundManager.setMusicVolume=function(volume){
  8973. SoundManager.musicVolume=volume;
  8974. SoundManager._setVolume(SoundManager._bgMusic,volume);
  8975. }
  8976. SoundManager._setVolume=function(url,volume){
  8977. url=URL.formatURL(url);
  8978. var i=0;
  8979. var channel;
  8980. for (i=SoundManager._channels.length-1;i >=0;i--){
  8981. channel=SoundManager._channels[i];
  8982. if (channel.url==url){
  8983. channel.volume=volume;
  8984. }
  8985. }
  8986. }
  8987. SoundManager.musicVolume=1;
  8988. SoundManager.soundVolume=1;
  8989. SoundManager.playbackRate=1;
  8990. SoundManager._useAudioMusic=true;
  8991. SoundManager._muted=false;
  8992. SoundManager._soundMuted=false;
  8993. SoundManager._musicMuted=false;
  8994. SoundManager._bgMusic=null;
  8995. SoundManager._musicChannel=null;
  8996. SoundManager._channels=[];
  8997. SoundManager._autoStopMusic=false;
  8998. SoundManager._blurPaused=false;
  8999. SoundManager._isActive=true;
  9000. SoundManager._soundClass=null;
  9001. SoundManager._musicClass=null;
  9002. SoundManager._lastSoundUsedTimeDic={};
  9003. SoundManager._isCheckingDispose=false;
  9004. SoundManager.autoReleaseSound=true;
  9005. return SoundManager;
  9006. })()
  9007. /**
  9008. *<code>Log</code> 类用于在界面内显示日志记录信息。
  9009. *注意:在加速器内不可使用
  9010. */
  9011. //class laya.utils.Log
  9012. var Log=(function(){
  9013. function Log(){}
  9014. __class(Log,'laya.utils.Log');
  9015. Log.enable=function(){
  9016. if (!Log._logdiv){
  9017. Log._logdiv=Browser.createElement('div');
  9018. Log._logdiv.style.cssText="border:white;padding:4px;overflow-y:auto;z-index:1000000;background:rgba(100,100,100,0.6);color:white;position: absolute;left:0px;top:0px;width:50%;height:50%;";
  9019. Browser.document.body.appendChild(Log._logdiv);
  9020. Log._btn=Browser.createElement("button");
  9021. Log._btn.innerText="Hide";
  9022. Log._btn.style.cssText="z-index:1000001;position: absolute;left:10px;top:10px;";
  9023. Log._btn.onclick=Log.toggle;
  9024. Browser.document.body.appendChild(Log._btn);
  9025. }
  9026. }
  9027. Log.toggle=function(){
  9028. var style=Log._logdiv.style;
  9029. if (style.display===""){
  9030. Log._btn.innerText="Show";
  9031. style.display="none";
  9032. }else {
  9033. Log._btn.innerText="Hide";
  9034. style.display="";
  9035. }
  9036. }
  9037. Log.print=function(value){
  9038. if (Log._logdiv){
  9039. if (Log._count >=Log.maxCount)Log.clear();
  9040. Log._count++;
  9041. Log._logdiv.innerText+=value+"\n";
  9042. if (Log.autoScrollToBottom){
  9043. if (Log._logdiv.scrollHeight-Log._logdiv.scrollTop-Log._logdiv.clientHeight < 50){
  9044. Log._logdiv.scrollTop=Log._logdiv.scrollHeight;
  9045. }
  9046. }
  9047. }
  9048. }
  9049. Log.clear=function(){
  9050. Log._logdiv.innerText="";
  9051. Log._count=0;
  9052. }
  9053. Log._logdiv=null;
  9054. Log._btn=null;
  9055. Log._count=0;
  9056. Log.maxCount=50;
  9057. Log.autoScrollToBottom=true;
  9058. return Log;
  9059. })()
  9060. //class laya.webgl.shader.d2.value.Value2D
  9061. var Value2D=(function(){
  9062. function Value2D(mainID,subID){
  9063. this.size=[0,0];
  9064. this.alpha=1.0;
  9065. //这个目前只给setIBVB用。其他的都放到attribute的color中了
  9066. //this.mmat=null;
  9067. //worldmatrix,是4x4的,因为为了shader使用方便。 TODO 换成float32Array
  9068. //this.u_MvpMatrix=null;
  9069. //this.texture=null;
  9070. this.ALPHA=1.0;
  9071. //这个?
  9072. //this.shader=null;
  9073. //this.mainID=0;
  9074. this.subID=0;
  9075. //this.filters=null;
  9076. //this.textureHost=null;
  9077. //public var fillStyle:DrawStyle;//TODO 这个有什么用?
  9078. //this.color=null;
  9079. //public var strokeStyle:DrawStyle;
  9080. //this.colorAdd=null;
  9081. //this.u_mmat2=null;
  9082. this.ref=1;
  9083. //this._attribLocation=null;
  9084. //[name,location,name,location...] 由继承类赋值。这个最终会传给对应的shader
  9085. //this._inClassCache=null;
  9086. this._cacheID=0;
  9087. this.clipMatDir=[ /*laya.resource.Context._MAXSIZE*/99999999,0,0,/*laya.resource.Context._MAXSIZE*/99999999];
  9088. this.clipMatPos=[0,0];
  9089. this.clipOff=[0,0];
  9090. this.defines=new ShaderDefines2D();
  9091. this.mainID=mainID;
  9092. this.subID=subID;
  9093. this.textureHost=null;
  9094. this.texture=null;
  9095. this.color=null;
  9096. this.colorAdd=null;
  9097. this.u_mmat2=null;
  9098. this._cacheID=mainID|subID;
  9099. this._inClassCache=Value2D._cache[this._cacheID];
  9100. if (mainID>0 && !this._inClassCache){
  9101. this._inClassCache=Value2D._cache[this._cacheID]=[];
  9102. this._inClassCache._length=0;
  9103. }
  9104. this.clear();
  9105. }
  9106. __class(Value2D,'laya.webgl.shader.d2.value.Value2D');
  9107. var __proto=Value2D.prototype;
  9108. __proto.setValue=function(value){}
  9109. //public function refresh():ShaderValue
  9110. __proto._ShaderWithCompile=function(){
  9111. var ret=Shader.withCompile2D(0,this.mainID,this.defines.toNameDic(),this.mainID | this.defines._value,Shader2X.create,this._attribLocation);
  9112. return ret;
  9113. }
  9114. __proto.upload=function(){
  9115. var renderstate2d=RenderState2D;
  9116. RenderState2D.worldMatrix4===RenderState2D.TEMPMAT4_ARRAY || this.defines.addInt(/*laya.webgl.shader.d2.ShaderDefines2D.WORLDMAT*/0x80);
  9117. this.mmat=renderstate2d.worldMatrix4;
  9118. if (RenderState2D.matWVP){
  9119. this.defines.addInt(/*laya.webgl.shader.d2.ShaderDefines2D.MVP3D*/0x800);
  9120. this.u_MvpMatrix=RenderState2D.matWVP.elements;
  9121. };
  9122. var sd=Shader.sharders[this.mainID | this.defines._value] || this._ShaderWithCompile();
  9123. if (sd._shaderValueWidth!==renderstate2d.width || sd._shaderValueHeight!==renderstate2d.height){
  9124. this.size[0]=renderstate2d.width;
  9125. this.size[1]=renderstate2d.height;
  9126. sd._shaderValueWidth=renderstate2d.width;
  9127. sd._shaderValueHeight=renderstate2d.height;
  9128. sd.upload(this,null);
  9129. }
  9130. else{
  9131. sd.upload(this,sd._params2dQuick2 || sd._make2dQuick2());
  9132. }
  9133. }
  9134. //TODO:coverage
  9135. __proto.setFilters=function(value){
  9136. this.filters=value;
  9137. if (!value)
  9138. return;
  9139. var n=value.length,f;
  9140. for (var i=0;i < n;i++){
  9141. f=value[i];
  9142. if (f){
  9143. this.defines.add(f.type);
  9144. f.action.setValue(this);
  9145. }
  9146. }
  9147. }
  9148. __proto.clear=function(){
  9149. this.defines._value=this.subID+(WebGL.shaderHighPrecision? /*laya.webgl.shader.d2.ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION*/0x400:0);
  9150. this.clipOff[0]=0;
  9151. }
  9152. __proto.release=function(){
  9153. if ((--this.ref)< 1){
  9154. this._inClassCache && (this._inClassCache[this._inClassCache._length++]=this);
  9155. this.clear();
  9156. this.filters=null;
  9157. this.ref=1;
  9158. this.clipOff[0]=0;
  9159. }
  9160. }
  9161. Value2D._initone=function(type,classT){
  9162. Value2D._typeClass[type]=classT;
  9163. Value2D._cache[type]=[];
  9164. Value2D._cache[type]._length=0;
  9165. }
  9166. Value2D.__init__=function(){
  9167. Value2D._initone(/*laya.webgl.shader.d2.ShaderDefines2D.PRIMITIVE*/0x04,PrimitiveSV);
  9168. Value2D._initone(/*laya.webgl.shader.d2.ShaderDefines2D.SKINMESH*/0x200,SkinSV);
  9169. Value2D._initone(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,TextureSV);
  9170. Value2D._initone(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01 | /*laya.webgl.shader.d2.ShaderDefines2D.FILTERGLOW*/0x08,TextureSV);
  9171. }
  9172. Value2D.create=function(mainType,subType){
  9173. var types=Value2D._cache[mainType|subType];
  9174. if (types._length)
  9175. return types[--types._length];
  9176. else
  9177. return new Value2D._typeClass[mainType|subType](subType);
  9178. }
  9179. Value2D._cache=[];
  9180. Value2D._typeClass=[];
  9181. Value2D.TEMPMAT4_ARRAY=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];
  9182. return Value2D;
  9183. })()
  9184. //class laya.webgl.utils.MatirxArray
  9185. var MatirxArray=(function(){
  9186. function MatirxArray(){}
  9187. __class(MatirxArray,'laya.webgl.utils.MatirxArray');
  9188. MatirxArray.ArrayMul=function(a,b,o){
  9189. if (!a){
  9190. MatirxArray.copyArray(b,o);
  9191. return;
  9192. }
  9193. if (!b){
  9194. MatirxArray.copyArray(a,o);
  9195. return;
  9196. };
  9197. var ai0=NaN,ai1=NaN,ai2=NaN,ai3=NaN;
  9198. for (var i=0;i < 4;i++){
  9199. ai0=a[i];
  9200. ai1=a[i+4];
  9201. ai2=a[i+8];
  9202. ai3=a[i+12];
  9203. o[i]=ai0 *b[0]+ai1 *b[1]+ai2 *b[2]+ai3 *b[3];
  9204. o[i+4]=ai0 *b[4]+ai1 *b[5]+ai2 *b[6]+ai3 *b[7];
  9205. o[i+8]=ai0 *b[8]+ai1 *b[9]+ai2 *b[10]+ai3 *b[11];
  9206. o[i+12]=ai0 *b[12]+ai1 *b[13]+ai2 *b[14]+ai3 *b[15];
  9207. }
  9208. }
  9209. MatirxArray.copyArray=function(f,t){
  9210. if (!f)return;
  9211. if (!t)return;
  9212. for (var i=0;i < f.length;i++){
  9213. t[i]=f[i];
  9214. }
  9215. }
  9216. return MatirxArray;
  9217. })()
  9218. /**
  9219. *填充文字命令
  9220. *@private
  9221. */
  9222. //class laya.display.cmd.FillWordsCmd
  9223. var FillWordsCmd=(function(){
  9224. function FillWordsCmd(){
  9225. /**
  9226. *文字数组
  9227. */
  9228. //this.words=null;
  9229. /**
  9230. *开始绘制文本的 x 坐标位置(相对于画布)。
  9231. */
  9232. //this.x=NaN;
  9233. /**
  9234. *开始绘制文本的 y 坐标位置(相对于画布)。
  9235. */
  9236. //this.y=NaN;
  9237. /**
  9238. *定义字体和字号,比如"20px Arial"。
  9239. */
  9240. //this.font=null;
  9241. /**
  9242. *定义文本颜色,比如"#ff0000"。
  9243. */
  9244. //this.color=null;
  9245. }
  9246. __class(FillWordsCmd,'laya.display.cmd.FillWordsCmd');
  9247. var __proto=FillWordsCmd.prototype;
  9248. /**
  9249. *回收到对象池
  9250. */
  9251. __proto.recover=function(){
  9252. this.words=null;
  9253. Pool.recover("FillWordsCmd",this);
  9254. }
  9255. /**@private */
  9256. __proto.run=function(context,gx,gy){
  9257. context.fillWords(this.words,this.x+gx,this.y+gy,this.font,this.color);
  9258. }
  9259. /**@private */
  9260. __getset(0,__proto,'cmdID',function(){
  9261. return "FillWords";
  9262. });
  9263. FillWordsCmd.create=function(words,x,y,font,color){
  9264. var cmd=Pool.getItemByClass("FillWordsCmd",FillWordsCmd);
  9265. cmd.words=words;
  9266. cmd.x=x;
  9267. cmd.y=y;
  9268. cmd.font=font;
  9269. cmd.color=color;
  9270. return cmd;
  9271. }
  9272. FillWordsCmd.ID="FillWords";
  9273. return FillWordsCmd;
  9274. })()
  9275. /**
  9276. *矩阵命令
  9277. */
  9278. //class laya.display.cmd.TransformCmd
  9279. var TransformCmd=(function(){
  9280. function TransformCmd(){
  9281. /**
  9282. *矩阵。
  9283. */
  9284. //this.matrix=null;
  9285. /**
  9286. *(可选)水平方向轴心点坐标。
  9287. */
  9288. //this.pivotX=NaN;
  9289. /**
  9290. *(可选)垂直方向轴心点坐标。
  9291. */
  9292. //this.pivotY=NaN;
  9293. }
  9294. __class(TransformCmd,'laya.display.cmd.TransformCmd');
  9295. var __proto=TransformCmd.prototype;
  9296. /**
  9297. *回收到对象池
  9298. */
  9299. __proto.recover=function(){
  9300. this.matrix=null;
  9301. Pool.recover("TransformCmd",this);
  9302. }
  9303. /**@private */
  9304. __proto.run=function(context,gx,gy){
  9305. context._transform(this.matrix,this.pivotX+gx,this.pivotY+gy);
  9306. }
  9307. /**@private */
  9308. __getset(0,__proto,'cmdID',function(){
  9309. return "Transform";
  9310. });
  9311. TransformCmd.create=function(matrix,pivotX,pivotY){
  9312. var cmd=Pool.getItemByClass("TransformCmd",TransformCmd);
  9313. cmd.matrix=matrix;
  9314. cmd.pivotX=pivotX;
  9315. cmd.pivotY=pivotY;
  9316. return cmd;
  9317. }
  9318. TransformCmd.ID="Transform";
  9319. return TransformCmd;
  9320. })()
  9321. /**
  9322. *@private
  9323. *计算贝塞尔曲线的工具类。
  9324. */
  9325. //class laya.maths.Bezier
  9326. var Bezier=(function(){
  9327. function Bezier(){
  9328. /**@private */
  9329. this._controlPoints=[new Point(),new Point(),new Point()];
  9330. this._calFun=this.getPoint2;
  9331. }
  9332. __class(Bezier,'laya.maths.Bezier');
  9333. var __proto=Bezier.prototype;
  9334. /**@private */
  9335. __proto._switchPoint=function(x,y){
  9336. var tPoint=this._controlPoints.shift();
  9337. tPoint.setTo(x,y);
  9338. this._controlPoints.push(tPoint);
  9339. }
  9340. /**
  9341. *计算二次贝塞尔点。
  9342. */
  9343. __proto.getPoint2=function(t,rst){
  9344. var p1=this._controlPoints[0];
  9345. var p2=this._controlPoints[1];
  9346. var p3=this._controlPoints[2];
  9347. var lineX=Math.pow((1-t),2)*p1.x+2 *t *(1-t)*p2.x+Math.pow(t,2)*p3.x;
  9348. var lineY=Math.pow((1-t),2)*p1.y+2 *t *(1-t)*p2.y+Math.pow(t,2)*p3.y;
  9349. rst.push(lineX,lineY);
  9350. }
  9351. /**
  9352. *计算三次贝塞尔点
  9353. */
  9354. __proto.getPoint3=function(t,rst){
  9355. var p1=this._controlPoints[0];
  9356. var p2=this._controlPoints[1];
  9357. var p3=this._controlPoints[2];
  9358. var p4=this._controlPoints[3];
  9359. var lineX=Math.pow((1-t),3)*p1.x+3 *p2.x *t *(1-t)*(1-t)+3 *p3.x *t *t *(1-t)+p4.x *Math.pow(t,3);
  9360. var lineY=Math.pow((1-t),3)*p1.y+3 *p2.y *t *(1-t)*(1-t)+3 *p3.y *t *t *(1-t)+p4.y *Math.pow(t,3);
  9361. rst.push(lineX,lineY);
  9362. }
  9363. /**
  9364. *计算贝塞尔点序列
  9365. */
  9366. __proto.insertPoints=function(count,rst){
  9367. var i=NaN;
  9368. count=count > 0 ? count :5;
  9369. var dLen=NaN;
  9370. dLen=1 / count;
  9371. for (i=0;i <=1;i+=dLen){
  9372. this._calFun(i,rst);
  9373. }
  9374. }
  9375. /**
  9376. *获取贝塞尔曲线上的点。
  9377. *@param pList 控制点[x0,y0,x1,y1...]
  9378. *@param inSertCount 每次曲线的插值数量
  9379. */
  9380. __proto.getBezierPoints=function(pList,inSertCount,count){
  9381. (inSertCount===void 0)&& (inSertCount=5);
  9382. (count===void 0)&& (count=2);
  9383. var i=0,len=0;
  9384. len=pList.length;
  9385. if (len < (count+1)*2)return [];
  9386. var rst=[];
  9387. switch (count){
  9388. case 2:
  9389. this._calFun=this.getPoint2;
  9390. break ;
  9391. case 3:
  9392. this._calFun=this.getPoint3;
  9393. break ;
  9394. default :
  9395. return [];
  9396. }
  9397. while (this._controlPoints.length <=count){
  9398. this._controlPoints.push(Point.create());
  9399. }
  9400. for (i=0;i < count *2;i+=2){
  9401. this._switchPoint(pList[i],pList[i+1]);
  9402. }
  9403. for (i=count *2;i < len;i+=2){
  9404. this._switchPoint(pList[i],pList[i+1]);
  9405. if ((i / 2)% count==0)this.insertPoints(inSertCount,rst);
  9406. }
  9407. return rst;
  9408. }
  9409. __static(Bezier,
  9410. ['I',function(){return this.I=new Bezier();}
  9411. ]);
  9412. return Bezier;
  9413. })()
  9414. /**
  9415. *...
  9416. *@author ...
  9417. */
  9418. //class laya.webgl.VertexArrayObject
  9419. var VertexArrayObject=(function(){
  9420. function VertexArrayObject(){}
  9421. __class(VertexArrayObject,'laya.webgl.VertexArrayObject');
  9422. return VertexArrayObject;
  9423. })()
  9424. /*__JS__ */(function(){var glErrorShadow={};function error(msg){if(window.console&&window.console.error){window.console.error(msg)}}function log(msg){if(window.console&&window.console.log){window.console.log(msg)}}function synthesizeGLError(err,opt_msg){glErrorShadow[err]=true;if(opt_msg!==undefined){error(opt_msg)}}function wrapGLError(gl){var f=gl.getError;gl.getError=function(){var err;do{err=f.apply(gl);if(err!=gl.NO_ERROR){glErrorShadow[err]=true}}while(err!=gl.NO_ERROR);for(var err in glErrorShadow){if(glErrorShadow[err]){delete glErrorShadow[err];return parseInt(err)}}return gl.NO_ERROR}}var WebGLVertexArrayObjectOES=function WebGLVertexArrayObjectOES(ext){var gl=ext.gl;this.ext=ext;this.isAlive=true;this.hasBeenBound=false;this.elementArrayBuffer=null;this.attribs=new Array(ext.maxVertexAttribs);for(var n=0;n<this.attribs.length;n++){var attrib=new WebGLVertexArrayObjectOES.VertexAttrib(gl);this.attribs[n]=attrib}this.maxAttrib=0};WebGLVertexArrayObjectOES.VertexAttrib=function VertexAttrib(gl){this.enabled=false;this.buffer=null;this.size=4;this.type=gl.FLOAT;this.normalized=false;this.stride=16;this.offset=0;this.cached="";this.recache()};WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache=function recache(){this.cached=[this.size,this.type,this.normalized,this.stride,this.offset].join(":")};var OESVertexArrayObject=function OESVertexArrayObject(gl){var self=this;this.gl=gl;wrapGLError(gl);var original=this.original={getParameter:gl.getParameter,enableVertexAttribArray:gl.enableVertexAttribArray,disableVertexAttribArray:gl.disableVertexAttribArray,bindBuffer:gl.bindBuffer,getVertexAttrib:gl.getVertexAttrib,vertexAttribPointer:gl.vertexAttribPointer};gl.getParameter=function getParameter(pname){if(pname==self.VERTEX_ARRAY_BINDING_OES){if(self.currentVertexArrayObject==self.defaultVertexArrayObject){return null}else{return self.currentVertexArrayObject}}return original.getParameter.apply(this,arguments)};gl.enableVertexAttribArray=function enableVertexAttribArray(index){var vao=self.currentVertexArrayObject;vao.maxAttrib=Math.max(vao.maxAttrib,index);var attrib=vao.attribs[index];attrib.enabled=true;return original.enableVertexAttribArray.apply(this,arguments)};gl.disableVertexAttribArray=function disableVertexAttribArray(index){var vao=self.currentVertexArrayObject;vao.maxAttrib=Math.max(vao.maxAttrib,index);var attrib=vao.attribs[index];attrib.enabled=false;return original.disableVertexAttribArray.apply(this,arguments)};gl.bindBuffer=function bindBuffer(target,buffer){switch(target){case gl.ARRAY_BUFFER:self.currentArrayBuffer=buffer;break;case gl.ELEMENT_ARRAY_BUFFER:self.currentVertexArrayObject.elementArrayBuffer=buffer;break}return original.bindBuffer.apply(this,arguments)};gl.getVertexAttrib=function getVertexAttrib(index,pname){var vao=self.currentVertexArrayObject;var attrib=vao.attribs[index];switch(pname){case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:return attrib.buffer;case gl.VERTEX_ATTRIB_ARRAY_ENABLED:return attrib.enabled;case gl.VERTEX_ATTRIB_ARRAY_SIZE:return attrib.size;case gl.VERTEX_ATTRIB_ARRAY_STRIDE:return attrib.stride;case gl.VERTEX_ATTRIB_ARRAY_TYPE:return attrib.type;case gl.VERTEX_ATTRIB_ARRAY_NORMALIZED:return attrib.normalized;default:return original.getVertexAttrib.apply(this,arguments)}};gl.vertexAttribPointer=function vertexAttribPointer(indx,size,type,normalized,stride,offset){var vao=self.currentVertexArrayObject;vao.maxAttrib=Math.max(vao.maxAttrib,indx);var attrib=vao.attribs[indx];attrib.buffer=self.currentArrayBuffer;attrib.size=size;attrib.type=type;attrib.normalized=normalized;attrib.stride=stride;attrib.offset=offset;attrib.recache();return original.vertexAttribPointer.apply(this,arguments)};if(gl.instrumentExtension){gl.instrumentExtension(this,"OES_vertex_array_object")}if(gl.canvas&&gl.canvas.addEventListener)gl.canvas.addEventListener("webglcontextrestored",function(){log("OESVertexArrayObject emulation library context restored");self.reset_()},true);this.reset_()};OESVertexArrayObject.prototype.VERTEX_ARRAY_BINDING_OES=34229;OESVertexArrayObject.prototype.reset_=function reset_(){var contextWasLost=this.vertexArrayObjects!==undefined;if(contextWasLost){for(var ii=0;ii<this.vertexArrayObjects.length;++ii){this.vertexArrayObjects.isAlive=false}}var gl=this.gl;this.maxVertexAttribs=gl.getParameter(gl.MAX_VERTEX_ATTRIBS);this.defaultVertexArrayObject=new WebGLVertexArrayObjectOES(this);this.currentVertexArrayObject=null;this.currentArrayBuffer=null;this.vertexArrayObjects=[this.defaultVertexArrayObject];this.bindVertexArrayOES(null)};OESVertexArrayObject.prototype.createVertexArrayOES=function createVertexArrayOES(){var arrayObject=new WebGLVertexArrayObjectOES(this);this.vertexArrayObjects.push(arrayObject);return arrayObject};OESVertexArrayObject.prototype.deleteVertexArrayOES=function deleteVertexArrayOES(arrayObject){arrayObject.isAlive=false;this.vertexArrayObjects.splice(this.vertexArrayObjects.indexOf(arrayObject),1);if(this.currentVertexArrayObject==arrayObject){this.bindVertexArrayOES(null)}};OESVertexArrayObject.prototype.isVertexArrayOES=function isVertexArrayOES(arrayObject){if(arrayObject&&arrayObject instanceof WebGLVertexArrayObjectOES){if(arrayObject.hasBeenBound&&arrayObject.ext==this){return true}}return false};OESVertexArrayObject.prototype.bindVertexArrayOES=function bindVertexArrayOES(arrayObject){var gl=this.gl;if(arrayObject&&!arrayObject.isAlive){synthesizeGLError(gl.INVALID_OPERATION,"bindVertexArrayOES: attempt to bind deleted arrayObject");return}var original=this.original;var oldVAO=this.currentVertexArrayObject;this.currentVertexArrayObject=arrayObject||this.defaultVertexArrayObject;this.currentVertexArrayObject.hasBeenBound=true;var newVAO=this.currentVertexArrayObject;if(oldVAO==newVAO){return}if(!oldVAO||newVAO.elementArrayBuffer!=oldVAO.elementArrayBuffer){original.bindBuffer.call(gl,gl.ELEMENT_ARRAY_BUFFER,newVAO.elementArrayBuffer)}var currentBinding=this.currentArrayBuffer;var maxAttrib=Math.max(oldVAO?oldVAO.maxAttrib:0,newVAO.maxAttrib);for(var n=0;n<=maxAttrib;n++){var attrib=newVAO.attribs[n];var oldAttrib=oldVAO?oldVAO.attribs[n]:null;if(!oldVAO||attrib.enabled!=oldAttrib.enabled){if(attrib.enabled){original.enableVertexAttribArray.call(gl,n)}else{original.disableVertexAttribArray.call(gl,n)}}if(attrib.enabled){var bufferChanged=false;if(!oldVAO||attrib.buffer!=oldAttrib.buffer){if(currentBinding!=attrib.buffer){original.bindBuffer.call(gl,gl.ARRAY_BUFFER,attrib.buffer);currentBinding=attrib.buffer}bufferChanged=true}if(bufferChanged||attrib.cached!=oldAttrib.cached){original.vertexAttribPointer.call(gl,n,attrib.size,attrib.type,attrib.normalized,attrib.stride,attrib.offset)}}}if(this.currentArrayBuffer!=currentBinding){original.bindBuffer.call(gl,gl.ARRAY_BUFFER,this.currentArrayBuffer)}};window._setupVertexArrayObject=function(gl){var original_getSupportedExtensions=gl.getSupportedExtensions;gl.getSupportedExtensions=function getSupportedExtensions(){var list=original_getSupportedExtensions.call(this)||[];if(list.indexOf("OES_vertex_array_object")<0){list.push("OES_vertex_array_object")}return list};var original_getExtension=gl.getExtension;gl.getExtension=function getExtension(name){var ext=original_getExtension.call(this,name);if(ext){return ext}if(name!=="OES_vertex_array_object"){return null}if(!this.__OESVertexArrayObject){console.log("Setup OES_vertex_array_object polyfill");this.__OESVertexArrayObject=new OESVertexArrayObject(this)}return this.__OESVertexArrayObject}};window._forceSetupVertexArrayObject=function(gl){var original_getSupportedExtensions=gl.getSupportedExtensions;gl.getSupportedExtensions=function getSupportedExtensions(){var list=original_getSupportedExtensions.call(this)||[];if(list.indexOf("OES_vertex_array_object")<0){list.push("OES_vertex_array_object")}return list};var original_getExtension=gl.getExtension;gl.getExtension=function getExtension(name){if(name==="OES_vertex_array_object"){if(!this.__OESVertexArrayObject){console.log("Setup OES_vertex_array_object polyfill");this.__OESVertexArrayObject=new OESVertexArrayObject(this)}return this.__OESVertexArrayObject}else{var ext=original_getExtension.call(this,name);if(ext){return ext}else{return null}}}}}());;
  9425. /**
  9426. *绘制三角形命令
  9427. */
  9428. //class laya.display.cmd.DrawTrianglesCmd
  9429. var DrawTrianglesCmd=(function(){
  9430. function DrawTrianglesCmd(){
  9431. /**
  9432. *纹理。
  9433. */
  9434. //this.texture=null;
  9435. /**
  9436. *X轴偏移量。
  9437. */
  9438. //this.x=NaN;
  9439. /**
  9440. *Y轴偏移量。
  9441. */
  9442. //this.y=NaN;
  9443. /**
  9444. *顶点数组。
  9445. */
  9446. //this.vertices=null;
  9447. /**
  9448. *UV数据。
  9449. */
  9450. //this.uvs=null;
  9451. /**
  9452. *顶点索引。
  9453. */
  9454. //this.indices=null;
  9455. /**
  9456. *缩放矩阵。
  9457. */
  9458. //this.matrix=null;
  9459. /**
  9460. *alpha
  9461. */
  9462. //this.alpha=NaN;
  9463. /**
  9464. *blend模式
  9465. */
  9466. //this.blendMode=null;
  9467. /**
  9468. *颜色变换
  9469. */
  9470. //this.color=null;
  9471. }
  9472. __class(DrawTrianglesCmd,'laya.display.cmd.DrawTrianglesCmd');
  9473. var __proto=DrawTrianglesCmd.prototype;
  9474. /**
  9475. *回收到对象池
  9476. */
  9477. __proto.recover=function(){
  9478. this.texture=null;
  9479. this.vertices=null;
  9480. this.uvs=null;
  9481. this.indices=null;
  9482. this.matrix=null;
  9483. Pool.recover("DrawTrianglesCmd",this);
  9484. }
  9485. /**@private */
  9486. __proto.run=function(context,gx,gy){
  9487. context.drawTriangles(this.texture,this.x+gx,this.y+gy,this.vertices,this.uvs,this.indices,this.matrix,this.alpha,this.color,this.blendMode);
  9488. }
  9489. /**@private */
  9490. __getset(0,__proto,'cmdID',function(){
  9491. return "DrawTriangles";
  9492. });
  9493. DrawTrianglesCmd.create=function(texture,x,y,vertices,uvs,indices,matrix,alpha,color,blendMode){
  9494. var cmd=Pool.getItemByClass("DrawTrianglesCmd",DrawTrianglesCmd);
  9495. cmd.texture=texture;
  9496. cmd.x=x;
  9497. cmd.y=y;
  9498. cmd.vertices=vertices;
  9499. cmd.uvs=uvs;
  9500. cmd.indices=indices;
  9501. cmd.matrix=matrix;
  9502. cmd.alpha=alpha;
  9503. if (color){
  9504. cmd.color=new ColorFilter();
  9505. var c=ColorUtils.create(color).arrColor;
  9506. cmd.color.color(c[0]*255,c[1]*255,c[2]*255,c[3]*255);
  9507. }
  9508. cmd.blendMode=blendMode;
  9509. return cmd;
  9510. }
  9511. DrawTrianglesCmd.ID="DrawTriangles";
  9512. return DrawTrianglesCmd;
  9513. })()
  9514. /**
  9515. *根据坐标集合绘制多个贴图
  9516. */
  9517. //class laya.display.cmd.DrawTexturesCmd
  9518. var DrawTexturesCmd=(function(){
  9519. function DrawTexturesCmd(){
  9520. /**
  9521. *纹理。
  9522. */
  9523. //this.texture=null;
  9524. /**
  9525. *绘制次数和坐标。
  9526. */
  9527. //this.pos=null;
  9528. }
  9529. __class(DrawTexturesCmd,'laya.display.cmd.DrawTexturesCmd');
  9530. var __proto=DrawTexturesCmd.prototype;
  9531. /**
  9532. *回收到对象池
  9533. */
  9534. __proto.recover=function(){
  9535. this.texture._removeReference();
  9536. this.texture=null;
  9537. this.pos=null;
  9538. Pool.recover("DrawTexturesCmd",this);
  9539. }
  9540. /**@private */
  9541. __proto.run=function(context,gx,gy){
  9542. context.drawTextures(this.texture,this.pos,gx,gy);
  9543. }
  9544. /**@private */
  9545. __getset(0,__proto,'cmdID',function(){
  9546. return "DrawTextures";
  9547. });
  9548. DrawTexturesCmd.create=function(texture,pos){
  9549. var cmd=Pool.getItemByClass("DrawTexturesCmd",DrawTexturesCmd);
  9550. cmd.texture=texture;
  9551. texture._addReference();
  9552. cmd.pos=pos;
  9553. return cmd;
  9554. }
  9555. DrawTexturesCmd.ID="DrawTextures";
  9556. return DrawTexturesCmd;
  9557. })()
  9558. /**
  9559. *<code>Point</code> 对象表示二维坐标系统中的某个位置,其中 x 表示水平轴,y 表示垂直轴。
  9560. */
  9561. //class laya.maths.Point
  9562. var Point=(function(){
  9563. function Point(x,y){
  9564. /**该点的水平坐标。*/
  9565. //this.x=NaN;
  9566. /**该点的垂直坐标。*/
  9567. //this.y=NaN;
  9568. (x===void 0)&& (x=0);
  9569. (y===void 0)&& (y=0);
  9570. this.x=x;
  9571. this.y=y;
  9572. }
  9573. __class(Point,'laya.maths.Point');
  9574. var __proto=Point.prototype;
  9575. /**
  9576. *将 <code>Point</code> 的成员设置为指定值。
  9577. *@param x 水平坐标。
  9578. *@param y 垂直坐标。
  9579. *@return 当前 Point 对象。
  9580. */
  9581. __proto.setTo=function(x,y){
  9582. this.x=x;
  9583. this.y=y;
  9584. return this;
  9585. }
  9586. /**
  9587. *重置
  9588. */
  9589. __proto.reset=function(){
  9590. this.x=this.y=0;
  9591. return this;
  9592. }
  9593. /**
  9594. *回收到对象池,方便复用
  9595. */
  9596. __proto.recover=function(){
  9597. Pool.recover("Point",this.reset());
  9598. }
  9599. /**
  9600. *计算当前点和目标点(x,y)的距离。
  9601. *@param x 水平坐标。
  9602. *@param y 垂直坐标。
  9603. *@return 返回当前点和目标点之间的距离。
  9604. */
  9605. __proto.distance=function(x,y){
  9606. return Math.sqrt((this.x-x)*(this.x-x)+(this.y-y)*(this.y-y));
  9607. }
  9608. /**返回包含 x 和 y 坐标的值的字符串。*/
  9609. __proto.toString=function(){
  9610. return this.x+","+this.y;
  9611. }
  9612. /**
  9613. *标准化向量。
  9614. */
  9615. __proto.normalize=function(){
  9616. var d=Math.sqrt(this.x *this.x+this.y *this.y);
  9617. if (d > 0){
  9618. var id=1.0 / d;
  9619. this.x *=id;
  9620. this.y *=id;
  9621. }
  9622. }
  9623. /**
  9624. *copy point坐标
  9625. *@param point 需要被copy的point
  9626. */
  9627. __proto.copy=function(point){
  9628. return this.setTo(point.x,point.y);
  9629. }
  9630. Point.create=function(){
  9631. return Pool.getItemByClass("Point",Point);
  9632. }
  9633. Point.TEMP=new Point();
  9634. Point.EMPTY=new Point();
  9635. return Point;
  9636. })()
  9637. /**
  9638. *@private
  9639. *<code>HTMLChar</code> 是一个 HTML 字符类。
  9640. */
  9641. //class laya.utils.HTMLChar
  9642. var HTMLChar=(function(){
  9643. function HTMLChar(){
  9644. /**x坐标*/
  9645. //this.x=NaN;
  9646. /**y坐标*/
  9647. //this.y=NaN;
  9648. /**宽*/
  9649. //this.width=NaN;
  9650. /**高*/
  9651. //this.height=NaN;
  9652. /**表示是否是正常单词(英文|.|数字)。*/
  9653. //this.isWord=false;
  9654. /**字符。*/
  9655. //this.char=null;
  9656. /**字符数量。*/
  9657. //this.charNum=NaN;
  9658. /**CSS 样式。*/
  9659. //this.style=null;
  9660. this.reset();
  9661. }
  9662. __class(HTMLChar,'laya.utils.HTMLChar');
  9663. var __proto=HTMLChar.prototype;
  9664. /**
  9665. *根据指定的字符、宽高、样式,创建一个 <code>HTMLChar</code> 类的实例。
  9666. *@param char 字符。
  9667. *@param w 宽度。
  9668. *@param h 高度。
  9669. *@param style CSS 样式。
  9670. */
  9671. __proto.setData=function(char,w,h,style){
  9672. this.char=char;
  9673. this.charNum=char.charCodeAt(0);
  9674. this.x=this.y=0;
  9675. this.width=w;
  9676. this.height=h;
  9677. this.style=style;
  9678. this.isWord=!HTMLChar._isWordRegExp.test(char);
  9679. return this;
  9680. }
  9681. /**
  9682. *重置
  9683. */
  9684. __proto.reset=function(){
  9685. this.x=this.y=this.width=this.height=0;
  9686. this.isWord=false;
  9687. this.char=null;
  9688. this.charNum=0;
  9689. this.style=null;
  9690. return this;
  9691. }
  9692. //TODO:coverage
  9693. __proto.recover=function(){
  9694. Pool.recover("HTMLChar",this.reset());
  9695. }
  9696. /**@private */
  9697. __proto._isChar=function(){
  9698. return true;
  9699. }
  9700. /**@private */
  9701. __proto._getCSSStyle=function(){
  9702. return this.style;
  9703. }
  9704. HTMLChar.create=function(){
  9705. return Pool.getItemByClass("HTMLChar",HTMLChar);
  9706. }
  9707. HTMLChar._isWordRegExp=new RegExp("[\\w\.]","");
  9708. return HTMLChar;
  9709. })()
  9710. /**
  9711. *绘制文字
  9712. */
  9713. //class laya.display.cmd.FillTextCmd
  9714. var FillTextCmd=(function(){
  9715. function FillTextCmd(){
  9716. //this._text=null;
  9717. /**@private */
  9718. this._textIsWorldText=false;
  9719. /**
  9720. *开始绘制文本的 x 坐标位置(相对于画布)。
  9721. */
  9722. //this.x=NaN;
  9723. /**
  9724. *开始绘制文本的 y 坐标位置(相对于画布)。
  9725. */
  9726. //this.y=NaN;
  9727. //this._font=null;
  9728. //this._color=null;
  9729. //this._textAlign=null;
  9730. this._fontColor=0xffffffff;
  9731. this._strokeColor=0;
  9732. this._nTexAlign=0;
  9733. this._fontObj=FillTextCmd._defFontObj;
  9734. }
  9735. __class(FillTextCmd,'laya.display.cmd.FillTextCmd');
  9736. var __proto=FillTextCmd.prototype;
  9737. /**
  9738. *回收到对象池
  9739. */
  9740. __proto.recover=function(){
  9741. Pool.recover("FillTextCmd",this);
  9742. }
  9743. /**@private */
  9744. __proto.run=function(context,gx,gy){
  9745. if(Laya.stage.isGlobalRepaint()){
  9746. this._textIsWorldText && (this._text).cleanCache();
  9747. }
  9748. if (this._textIsWorldText){
  9749. context._fast_filltext((this._text),this.x+gx,this.y+gy,this._fontObj,this._color,null,0,this._nTexAlign,0);
  9750. }else {
  9751. context.drawText(this._text,this.x+gx,this.y+gy,this._font,this._color,this._textAlign);
  9752. }
  9753. }
  9754. /**
  9755. *在画布上输出的文本。
  9756. */
  9757. __getset(0,__proto,'text',function(){
  9758. return this._text;
  9759. },function(value){
  9760. this._text=value;
  9761. this._textIsWorldText=(value instanceof laya.utils.WordText );
  9762. this._textIsWorldText && (this._text).cleanCache();
  9763. });
  9764. /**@private */
  9765. __getset(0,__proto,'cmdID',function(){
  9766. return "FillText";
  9767. });
  9768. /**
  9769. *定义文本颜色,比如"#ff0000"。
  9770. */
  9771. __getset(0,__proto,'color',function(){
  9772. return this._color;
  9773. },function(value){
  9774. this._color=value;
  9775. this._fontColor=ColorUtils.create(value).numColor;
  9776. this._textIsWorldText && (this._text).cleanCache();
  9777. });
  9778. /**
  9779. *定义字号和字体,比如"20px Arial"。
  9780. */
  9781. __getset(0,__proto,'font',function(){
  9782. return this._font;
  9783. },function(value){
  9784. this._font=value;
  9785. this._fontObj=FontInfo.Parse(value);
  9786. this._textIsWorldText && (this._text).cleanCache();
  9787. });
  9788. /**
  9789. *文本对齐方式,可选值:"left","center","right"。
  9790. */
  9791. __getset(0,__proto,'textAlign',function(){
  9792. return this._textAlign;
  9793. },function(value){
  9794. this._textAlign=value;
  9795. switch (value){
  9796. case 'center':
  9797. this._nTexAlign=Context.ENUM_TEXTALIGN_CENTER;
  9798. break ;
  9799. case 'right':
  9800. this._nTexAlign=Context.ENUM_TEXTALIGN_RIGHT;
  9801. break ;
  9802. default :
  9803. this._nTexAlign=Context.ENUM_TEXTALIGN_DEFAULT;
  9804. }
  9805. this._textIsWorldText && (this._text).cleanCache();
  9806. });
  9807. FillTextCmd.create=function(text,x,y,font,color,textAlign){
  9808. var cmd=Pool.getItemByClass("FillTextCmd",FillTextCmd);
  9809. cmd.text=text;
  9810. cmd._textIsWorldText=(text instanceof laya.utils.WordText );
  9811. cmd.x=x;
  9812. cmd.y=y;
  9813. cmd.font=font;
  9814. cmd.color=color;
  9815. cmd.textAlign=textAlign;
  9816. return cmd;
  9817. }
  9818. FillTextCmd.ID="FillText";
  9819. __static(FillTextCmd,
  9820. ['_defFontObj',function(){return this._defFontObj=new FontInfo(null);}
  9821. ]);
  9822. return FillTextCmd;
  9823. })()
  9824. /**
  9825. *文字贴图的大图集。
  9826. */
  9827. //class laya.webgl.text.TextAtlas
  9828. var TextAtlas=(function(){
  9829. function TextAtlas(){
  9830. this.texWidth=1024;
  9831. this.texHeight=1024;
  9832. this.atlasgrid=null;
  9833. this.protectDist=1;
  9834. this.texture=null;
  9835. this.charMaps={};
  9836. this.texHeight=this.texWidth=TextRender.atlasWidth;
  9837. this.texture=TextTexture.getTextTexture(this.texWidth,this.texHeight);
  9838. if (this.texWidth / TextAtlas.atlasGridW > 256){
  9839. TextAtlas.atlasGridW=Math.ceil(this.texWidth / 256);
  9840. }
  9841. this.atlasgrid=new AtlasGrid(this.texWidth / TextAtlas.atlasGridW,this.texHeight / TextAtlas.atlasGridW,this.texture.id);
  9842. }
  9843. __class(TextAtlas,'laya.webgl.text.TextAtlas');
  9844. var __proto=TextAtlas.prototype;
  9845. __proto.setProtecteDist=function(d){
  9846. this.protectDist=d;
  9847. }
  9848. /**
  9849. *如果返回null,则表示无法加入了
  9850. *分配的时候优先选择最接近自己高度的节点
  9851. *@param w
  9852. *@param h
  9853. *@return
  9854. */
  9855. __proto.getAEmpty=function(w,h,pt){
  9856. var find=this.atlasgrid.addRect(1,Math.ceil(w / TextAtlas.atlasGridW),Math.ceil(h / TextAtlas.atlasGridW),pt);
  9857. if (find){
  9858. pt.x *=TextAtlas.atlasGridW;
  9859. pt.y *=TextAtlas.atlasGridW;
  9860. }
  9861. return find;
  9862. }
  9863. /*
  9864. public function pushData(data:ImageData,node:TextAtlasNode):void {
  9865. texture.addChar(data,node.x,node.y);
  9866. }
  9867. */
  9868. __proto.destroy=function(){
  9869. for (var k in this.charMaps){
  9870. var ri=this.charMaps[k];
  9871. ri.deleted=true;
  9872. }
  9873. this.texture.discard();
  9874. }
  9875. __proto.printDebugInfo=function(){}
  9876. /**
  9877. *大图集格子单元的占用率,老的也算上了。只是表示这个大图集还能插入多少东西。
  9878. */
  9879. __getset(0,__proto,'usedRate',function(){
  9880. return this.atlasgrid._used;
  9881. });
  9882. TextAtlas.atlasGridW=16;
  9883. return TextAtlas;
  9884. })()
  9885. //class laya.webgl.utils.CONST3D2D
  9886. var CONST3D2D=(function(){
  9887. function CONST3D2D(){}
  9888. __class(CONST3D2D,'laya.webgl.utils.CONST3D2D');
  9889. CONST3D2D.BYTES_PE=4;
  9890. CONST3D2D.BYTES_PIDX=2;
  9891. CONST3D2D.defaultMatrix4=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];
  9892. CONST3D2D.defaultMinusYMatrix4=[1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1];
  9893. CONST3D2D.uniformMatrix3=[1,0,0,0,0,1,0,0,0,0,1,0];
  9894. CONST3D2D._TMPARRAY=[];
  9895. CONST3D2D._OFFSETX=0;
  9896. CONST3D2D._OFFSETY=0;
  9897. return CONST3D2D;
  9898. })()
  9899. /**
  9900. *模板,预制件
  9901. */
  9902. //class laya.components.Prefab
  9903. var Prefab=(function(){
  9904. function Prefab(){
  9905. /**@private */
  9906. this.json=null;
  9907. }
  9908. __class(Prefab,'laya.components.Prefab');
  9909. var __proto=Prefab.prototype;
  9910. /**
  9911. *通过预制创建实例
  9912. */
  9913. __proto.create=function(){
  9914. if (this.json)return SceneUtils.createByData(null,this.json);
  9915. return null;
  9916. }
  9917. return Prefab;
  9918. })()
  9919. /**
  9920. *<p><code>Rectangle</code> 对象是按其位置(由它左上角的点 (x,y)确定)以及宽度和高度定义的区域。</p>
  9921. *<p>Rectangle 类的 x、y、width 和 height 属性相互独立;更改一个属性的值不会影响其他属性。</p>
  9922. */
  9923. //class laya.maths.Rectangle
  9924. var Rectangle=(function(){
  9925. function Rectangle(x,y,width,height){
  9926. /**矩形左上角的 X 轴坐标。*/
  9927. //this.x=NaN;
  9928. /**矩形左上角的 Y 轴坐标。*/
  9929. //this.y=NaN;
  9930. /**矩形的宽度。*/
  9931. //this.width=NaN;
  9932. /**矩形的高度。*/
  9933. //this.height=NaN;
  9934. (x===void 0)&& (x=0);
  9935. (y===void 0)&& (y=0);
  9936. (width===void 0)&& (width=0);
  9937. (height===void 0)&& (height=0);
  9938. this.x=x;
  9939. this.y=y;
  9940. this.width=width;
  9941. this.height=height;
  9942. }
  9943. __class(Rectangle,'laya.maths.Rectangle');
  9944. var __proto=Rectangle.prototype;
  9945. /**
  9946. *将 Rectangle 的属性设置为指定值。
  9947. *@param x x 矩形左上角的 X 轴坐标。
  9948. *@param y x 矩形左上角的 Y 轴坐标。
  9949. *@param width 矩形的宽度。
  9950. *@param height 矩形的高。
  9951. *@return 返回属性值修改后的矩形对象本身。
  9952. */
  9953. __proto.setTo=function(x,y,width,height){
  9954. this.x=x;
  9955. this.y=y;
  9956. this.width=width;
  9957. this.height=height;
  9958. return this;
  9959. }
  9960. /**
  9961. *重置
  9962. */
  9963. __proto.reset=function(){
  9964. this.x=this.y=this.width=this.height=0;
  9965. return this;
  9966. }
  9967. /**
  9968. *回收
  9969. */
  9970. __proto.recover=function(){
  9971. if (this==Rectangle.TEMP || this==Rectangle.EMPTY){
  9972. console.log("recover Temp or Empty:",this);
  9973. return;
  9974. }
  9975. Pool.recover("Rectangle",this.reset());
  9976. }
  9977. /**
  9978. *复制 source 对象的属性值到此矩形对象中。
  9979. *@param sourceRect 源 Rectangle 对象。
  9980. *@return 返回属性值修改后的矩形对象本身。
  9981. */
  9982. __proto.copyFrom=function(source){
  9983. this.x=source.x;
  9984. this.y=source.y;
  9985. this.width=source.width;
  9986. this.height=source.height;
  9987. return this;
  9988. }
  9989. /**
  9990. *确定由此 Rectangle 对象定义的矩形区域内是否包含指定的点。
  9991. *@param x 点的 X 轴坐标值(水平位置)。
  9992. *@param y 点的 Y 轴坐标值(垂直位置)。
  9993. *@return 如果 Rectangle 对象包含指定的点,则值为 true;否则为 false。
  9994. */
  9995. __proto.contains=function(x,y){
  9996. if (this.width <=0 || this.height <=0)return false;
  9997. if (x >=this.x && x < this.right){
  9998. if (y >=this.y && y < this.bottom){
  9999. return true;
  10000. }
  10001. }
  10002. return false;
  10003. }
  10004. /**
  10005. *确定在 rect 参数中指定的对象是否与此 Rectangle 对象相交。此方法检查指定的 Rectangle 对象的 x、y、width 和 height 属性,以查看它是否与此 Rectangle 对象相交。
  10006. *@param rect Rectangle 对象。
  10007. *@return 如果传入的矩形对象与此对象相交,则返回 true 值,否则返回 false。
  10008. */
  10009. __proto.intersects=function(rect){
  10010. return !(rect.x > (this.x+this.width)|| (rect.x+rect.width)< this.x || rect.y > (this.y+this.height)|| (rect.y+rect.height)< this.y);
  10011. }
  10012. /**
  10013. *如果在 rect 参数中指定的 Rectangle 对象与此 Rectangle 对象相交,则返回交集区域作为 Rectangle 对象。如果矩形不相交,则此方法返回null。
  10014. *@param rect 待比较的矩形区域。
  10015. *@param out (可选)待输出的矩形区域。如果为空则创建一个新的。建议:尽量复用对象,减少对象创建消耗。
  10016. *@return 返回相交的矩形区域对象。
  10017. */
  10018. __proto.intersection=function(rect,out){
  10019. if (!this.intersects(rect))return null;
  10020. out || (out=new Rectangle());
  10021. out.x=Math.max(this.x,rect.x);
  10022. out.y=Math.max(this.y,rect.y);
  10023. out.width=Math.min(this.right,rect.right)-out.x;
  10024. out.height=Math.min(this.bottom,rect.bottom)-out.y;
  10025. return out;
  10026. }
  10027. /**
  10028. *<p>矩形联合,通过填充两个矩形之间的水平和垂直空间,将这两个矩形组合在一起以创建一个新的 Rectangle 对象。</p>
  10029. *<p>注意:union()方法忽略高度或宽度值为 0 的矩形,如:var rect2:Rectangle=new Rectangle(300,300,50,0);</p>
  10030. *@param 要添加到此 Rectangle 对象的 Rectangle 对象。
  10031. *@param out 用于存储输出结果的矩形对象。如果为空,则创建一个新的。建议:尽量复用对象,减少对象创建消耗。Rectangle.TEMP对象用于对象复用。
  10032. *@return 充当两个矩形的联合的新 Rectangle 对象。
  10033. */
  10034. __proto.union=function(source,out){
  10035. out || (out=new Rectangle());
  10036. this.clone(out);
  10037. if (source.width <=0 || source.height <=0)return out;
  10038. out.addPoint(source.x,source.y);
  10039. out.addPoint(source.right,source.bottom);
  10040. return this;
  10041. }
  10042. /**
  10043. *返回一个 Rectangle 对象,其 x、y、width 和 height 属性的值与当前 Rectangle 对象的对应值相同。
  10044. *@param out (可选)用于存储结果的矩形对象。如果为空,则创建一个新的。建议:尽量复用对象,减少对象创建消耗。。Rectangle.TEMP对象用于对象复用。
  10045. *@return Rectangle 对象,其 x、y、width 和 height 属性的值与当前 Rectangle 对象的对应值相同。
  10046. */
  10047. __proto.clone=function(out){
  10048. out || (out=new Rectangle());
  10049. out.x=this.x;
  10050. out.y=this.y;
  10051. out.width=this.width;
  10052. out.height=this.height;
  10053. return out;
  10054. }
  10055. /**
  10056. *当前 Rectangle 对象的水平位置 x 和垂直位置 y 以及高度 width 和宽度 height 以逗号连接成的字符串。
  10057. */
  10058. __proto.toString=function(){
  10059. return this.x+","+this.y+","+this.width+","+this.height;
  10060. }
  10061. /**
  10062. *检测传入的 Rectangle 对象的属性是否与当前 Rectangle 对象的属性 x、y、width、height 属性值都相等。
  10063. *@param rect 待比较的 Rectangle 对象。
  10064. *@return 如果判断的属性都相等,则返回 true ,否则返回 false。
  10065. */
  10066. __proto.equals=function(rect){
  10067. if (!rect || rect.x!==this.x || rect.y!==this.y || rect.width!==this.width || rect.height!==this.height)return false;
  10068. return true;
  10069. }
  10070. /**
  10071. *<p>为当前矩形对象加一个点,以使当前矩形扩展为包含当前矩形和此点的最小矩形。</p>
  10072. *<p>此方法会修改本对象。</p>
  10073. *@param x 点的 X 坐标。
  10074. *@param y 点的 Y 坐标。
  10075. *@return 返回此 Rectangle 对象。
  10076. */
  10077. __proto.addPoint=function(x,y){
  10078. this.x > x && (this.width+=this.x-x,this.x=x);
  10079. this.y > y && (this.height+=this.y-y,this.y=y);
  10080. if (this.width < x-this.x)this.width=x-this.x;
  10081. if (this.height < y-this.y)this.height=y-this.y;
  10082. return this;
  10083. }
  10084. /**
  10085. *@private
  10086. *返回代表当前矩形的顶点数据。
  10087. *@return 顶点数据。
  10088. */
  10089. __proto._getBoundPoints=function(){
  10090. var rst=Rectangle._temB;
  10091. rst.length=0;
  10092. if (this.width==0 || this.height==0)return rst;
  10093. rst.push(this.x,this.y,this.x+this.width,this.y,this.x,this.y+this.height,this.x+this.width,this.y+this.height);
  10094. return rst;
  10095. }
  10096. /**
  10097. *确定此 Rectangle 对象是否为空。
  10098. *@return 如果 Rectangle 对象的宽度或高度小于等于 0,则返回 true 值,否则返回 false。
  10099. */
  10100. __proto.isEmpty=function(){
  10101. if (this.width <=0 || this.height <=0)return true;
  10102. return false;
  10103. }
  10104. /**此矩形右侧的 X 轴坐标。 x 和 width 属性的和。*/
  10105. __getset(0,__proto,'right',function(){
  10106. return this.x+this.width;
  10107. });
  10108. /**此矩形底端的 Y 轴坐标。y 和 height 属性的和。*/
  10109. __getset(0,__proto,'bottom',function(){
  10110. return this.y+this.height;
  10111. });
  10112. Rectangle.create=function(){
  10113. return Pool.getItemByClass("Rectangle",Rectangle);
  10114. }
  10115. Rectangle._getBoundPointS=function(x,y,width,height){
  10116. var rst=Rectangle._temA;
  10117. rst.length=0;
  10118. if (width==0 || height==0)return rst;
  10119. rst.push(x,y,x+width,y,x,y+height,x+width,y+height);
  10120. return rst;
  10121. }
  10122. Rectangle._getWrapRec=function(pointList,rst){
  10123. if (!pointList || pointList.length < 1)return rst ? rst.setTo(0,0,0,0):Rectangle.TEMP.setTo(0,0,0,0);
  10124. rst=rst ? rst :laya.maths.Rectangle.create();
  10125. var i,len=pointList.length,minX,maxX,minY,maxY,tPoint=Point.TEMP;
  10126. minX=minY=99999;
  10127. maxX=maxY=-minX;
  10128. for (i=0;i < len;i+=2){
  10129. tPoint.x=pointList[i];
  10130. tPoint.y=pointList[i+1];
  10131. minX=minX < tPoint.x ? minX :tPoint.x;
  10132. minY=minY < tPoint.y ? minY :tPoint.y;
  10133. maxX=maxX > tPoint.x ? maxX :tPoint.x;
  10134. maxY=maxY > tPoint.y ? maxY :tPoint.y;
  10135. }
  10136. return rst.setTo(minX,minY,maxX-minX,maxY-minY);
  10137. }
  10138. Rectangle.EMPTY=new Rectangle();
  10139. Rectangle.TEMP=new Rectangle();
  10140. Rectangle._temB=[];
  10141. Rectangle._temA=[];
  10142. return Rectangle;
  10143. })()
  10144. /**
  10145. *绘制单个贴图
  10146. */
  10147. //class laya.display.cmd.DrawTextureCmd
  10148. var DrawTextureCmd=(function(){
  10149. function DrawTextureCmd(){
  10150. /**
  10151. *纹理。
  10152. */
  10153. //this.texture=null;
  10154. /**
  10155. *(可选)X轴偏移量。
  10156. */
  10157. //this.x=NaN;
  10158. /**
  10159. *(可选)Y轴偏移量。
  10160. */
  10161. //this.y=NaN;
  10162. /**
  10163. *(可选)宽度。
  10164. */
  10165. //this.width=NaN;
  10166. /**
  10167. *(可选)高度。
  10168. */
  10169. //this.height=NaN;
  10170. /**
  10171. *(可选)矩阵信息。
  10172. */
  10173. //this.matrix=null;
  10174. /**
  10175. *(可选)透明度。
  10176. */
  10177. //this.alpha=NaN;
  10178. /**
  10179. *(可选)颜色滤镜。
  10180. */
  10181. //this.color=null;
  10182. this.colorFlt=null;
  10183. /**
  10184. *(可选)混合模式。
  10185. */
  10186. //this.blendMode=null;
  10187. }
  10188. __class(DrawTextureCmd,'laya.display.cmd.DrawTextureCmd');
  10189. var __proto=DrawTextureCmd.prototype;
  10190. /**
  10191. *回收到对象池
  10192. */
  10193. __proto.recover=function(){
  10194. this.texture._removeReference();
  10195. this.texture=null;
  10196. this.matrix=null;
  10197. Pool.recover("DrawTextureCmd",this);
  10198. }
  10199. /**@private */
  10200. __proto.run=function(context,gx,gy){
  10201. context.drawTextureWithTransform(this.texture,this.x,this.y,this.width,this.height,this.matrix,gx,gy,this.alpha,this.blendMode,this.colorFlt);
  10202. }
  10203. /**@private */
  10204. __getset(0,__proto,'cmdID',function(){
  10205. return "DrawTexture";
  10206. });
  10207. DrawTextureCmd.create=function(texture,x,y,width,height,matrix,alpha,color,blendMode){
  10208. var cmd=Pool.getItemByClass("DrawTextureCmd",DrawTextureCmd);
  10209. cmd.texture=texture;
  10210. texture._addReference();
  10211. cmd.x=x;
  10212. cmd.y=y;
  10213. cmd.width=width;
  10214. cmd.height=height;
  10215. cmd.matrix=matrix;
  10216. cmd.alpha=alpha;
  10217. cmd.color=color;
  10218. cmd.blendMode=blendMode;
  10219. if (color){
  10220. cmd.colorFlt=new ColorFilter();
  10221. cmd.colorFlt.setColor(color);
  10222. }
  10223. return cmd;
  10224. }
  10225. DrawTextureCmd.ID="DrawTexture";
  10226. return DrawTextureCmd;
  10227. })()
  10228. /**
  10229. *<code>Filter</code> 是滤镜基类。
  10230. */
  10231. //class laya.filters.Filter
  10232. var Filter=(function(){
  10233. function Filter(){
  10234. /**@private*/
  10235. this._glRender=null;
  10236. }
  10237. __class(Filter,'laya.filters.Filter');
  10238. var __proto=Filter.prototype;
  10239. Laya.imps(__proto,{"laya.filters.IFilter":true})
  10240. /**@private 滤镜类型。*/
  10241. __getset(0,__proto,'type',function(){return-1 });
  10242. Filter.BLUR=0x10;
  10243. Filter.COLOR=0x20;
  10244. Filter.GLOW=0x08;
  10245. Filter._filter=function(sprite,context,x,y){
  10246. var webglctx=context;
  10247. var next=(this)._next;
  10248. if (next){
  10249. var filters=sprite.filters,len=filters.length;
  10250. if (len==1 && (filters[0].type==/*CLASS CONST:laya.filters.Filter.COLOR*/0x20)){
  10251. context.save();
  10252. context.setColorFilter(filters[0]);
  10253. next._fun.call(next,sprite,context,x,y);
  10254. context.restore();
  10255. return;
  10256. };
  10257. var svCP=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  10258. var b;
  10259. var p=Point.TEMP;
  10260. var tMatrix=webglctx._curMat;
  10261. var mat=Matrix.create();
  10262. tMatrix.copyTo(mat);
  10263. var tPadding=0;
  10264. var tHalfPadding=0;
  10265. var tIsHaveGlowFilter=false;
  10266. var source=null;
  10267. var out=sprite._cacheStyle.filterCache || null;
  10268. if (!out || sprite.getRepaint()!=0){
  10269. tIsHaveGlowFilter=sprite._isHaveGlowFilter();
  10270. if (tIsHaveGlowFilter){
  10271. tPadding=50;
  10272. tHalfPadding=25;
  10273. }
  10274. b=new Rectangle();
  10275. b.copyFrom(sprite.getSelfBounds());
  10276. b.x+=sprite.x;
  10277. b.y+=sprite.y;
  10278. b.x-=sprite.pivotX+4;
  10279. b.y-=sprite.pivotY+4;
  10280. var tSX=b.x;
  10281. var tSY=b.y;
  10282. b.width+=(tPadding+8);
  10283. b.height+=(tPadding+8);
  10284. p.x=b.x *mat.a+b.y *mat.c;
  10285. p.y=b.y *mat.d+b.x *mat.b;
  10286. b.x=p.x;
  10287. b.y=p.y;
  10288. p.x=b.width *mat.a+b.height *mat.c;
  10289. p.y=b.height *mat.d+b.width *mat.b;
  10290. b.width=p.x;
  10291. b.height=p.y;
  10292. if (b.width <=0 || b.height <=0){
  10293. return;
  10294. }
  10295. out && WebGLRTMgr.releaseRT(out);
  10296. source=WebGLRTMgr.getRT(b.width,b.height);
  10297. var outRT=out=WebGLRTMgr.getRT(b.width,b.height);
  10298. sprite._getCacheStyle().filterCache=out;
  10299. webglctx.pushRT();
  10300. webglctx.useRT(source);
  10301. var tX=sprite.x-tSX+tHalfPadding;
  10302. var tY=sprite.y-tSY+tHalfPadding;
  10303. next._fun.call(next,sprite,context,tX,tY);
  10304. webglctx.useRT(outRT);
  10305. for (var i=0;i < len;i++){
  10306. if (i !=0){
  10307. webglctx.useRT(source);
  10308. webglctx.drawTarget(outRT,0,0,b.width,b.height,Matrix.TEMP.identity(),svCP,null,BlendMode.TOINT.overlay);
  10309. webglctx.useRT(outRT);
  10310. };
  10311. var fil=filters[i];
  10312. switch (fil.type){
  10313. case /*CLASS CONST:laya.filters.Filter.BLUR*/0x10:
  10314. fil._glRender && fil._glRender.render(source,context,b.width,b.height,fil);
  10315. break ;
  10316. case /*CLASS CONST:laya.filters.Filter.GLOW*/0x08:
  10317. fil._glRender && fil._glRender.render(source,context,b.width,b.height,fil);
  10318. break ;
  10319. case /*CLASS CONST:laya.filters.Filter.COLOR*/0x20:
  10320. webglctx.setColorFilter(fil);
  10321. webglctx.drawTarget(source,0,0,b.width,b.height,Matrix.EMPTY.identity(),Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  10322. webglctx.setColorFilter(null);
  10323. break ;
  10324. }
  10325. }
  10326. webglctx.popRT();
  10327. }else {
  10328. tIsHaveGlowFilter=sprite._cacheStyle.hasGlowFilter || false;
  10329. if (tIsHaveGlowFilter){
  10330. tPadding=50;
  10331. tHalfPadding=25;
  10332. }
  10333. b=sprite.getBounds();
  10334. if (b.width <=0 || b.height <=0){
  10335. return;
  10336. }
  10337. b.width+=tPadding;
  10338. b.height+=tPadding;
  10339. p.x=b.x *mat.a+b.y *mat.c;
  10340. p.y=b.y *mat.d+b.x *mat.b;
  10341. b.x=p.x;
  10342. b.y=p.y;
  10343. p.x=b.width *mat.a+b.height *mat.c;
  10344. p.y=b.height *mat.d+b.width *mat.b;
  10345. b.width=p.x;
  10346. b.height=p.y;
  10347. }
  10348. x=x-tHalfPadding-sprite.x;
  10349. y=y-tHalfPadding-sprite.y;
  10350. p.setTo(x,y);
  10351. mat.transformPoint(p);
  10352. x=p.x+b.x;
  10353. y=p.y+b.y;
  10354. webglctx._drawRenderTexture(out,x,y,b.width,b.height,Matrix.TEMP.identity(),1.0,RenderTexture2D.defuv);
  10355. if(source){
  10356. var submit=SubmitCMD.create([source],function(s){
  10357. s.destroy();
  10358. },this);
  10359. source=null;
  10360. context.addRenderObject(submit);
  10361. }
  10362. mat.destroy();
  10363. }
  10364. }
  10365. return Filter;
  10366. })()
  10367. /**
  10368. *@private
  10369. *Touch事件管理类,处理多点触控下的鼠标事件
  10370. */
  10371. //class laya.events.TouchManager
  10372. var TouchManager=(function(){
  10373. function TouchManager(){
  10374. /**
  10375. *当前over的touch表
  10376. */
  10377. this.preOvers=[];
  10378. /**
  10379. *当前down的touch表
  10380. */
  10381. this.preDowns=[];
  10382. this.preRightDowns=[];
  10383. /**
  10384. *是否启用
  10385. */
  10386. this.enable=true;
  10387. this._lastClickTime=0;
  10388. this._event=new Event();
  10389. }
  10390. __class(TouchManager,'laya.events.TouchManager');
  10391. var __proto=TouchManager.prototype;
  10392. __proto._clearTempArrs=function(){
  10393. TouchManager._oldArr.length=0;
  10394. TouchManager._newArr.length=0;
  10395. TouchManager._tEleArr.length=0;
  10396. }
  10397. /**
  10398. *从touch表里查找对应touchID的数据
  10399. *@param touchID touch ID
  10400. *@param arr touch表
  10401. *@return
  10402. *
  10403. */
  10404. __proto.getTouchFromArr=function(touchID,arr){
  10405. var i=0,len=0;
  10406. len=arr.length;
  10407. var tTouchO;
  10408. for (i=0;i < len;i++){
  10409. tTouchO=arr[i];
  10410. if (tTouchO.id==touchID){
  10411. return tTouchO;
  10412. }
  10413. }
  10414. return null;
  10415. }
  10416. /**
  10417. *从touch表里移除一个元素
  10418. *@param touchID touch ID
  10419. *@param arr touch表
  10420. *
  10421. */
  10422. __proto.removeTouchFromArr=function(touchID,arr){
  10423. var i=0;
  10424. for (i=arr.length-1;i >=0;i--){
  10425. if (arr[i].id==touchID){
  10426. arr.splice(i,1);
  10427. }
  10428. }
  10429. }
  10430. /**
  10431. *创建一个touch数据
  10432. *@param ele 当前的根节点
  10433. *@param touchID touchID
  10434. *@return
  10435. *
  10436. */
  10437. __proto.createTouchO=function(ele,touchID){
  10438. var rst;
  10439. rst=Pool.getItem("TouchData")|| {};
  10440. rst.id=touchID;
  10441. rst.tar=ele;
  10442. return rst;
  10443. }
  10444. /**
  10445. *处理touchStart
  10446. *@param ele 根节点
  10447. *@param touchID touchID
  10448. *@param isLeft (可选)是否为左键
  10449. */
  10450. __proto.onMouseDown=function(ele,touchID,isLeft){
  10451. (isLeft===void 0)&& (isLeft=false);
  10452. if (!this.enable)
  10453. return;
  10454. var preO;
  10455. var tO;
  10456. var arrs;
  10457. preO=this.getTouchFromArr(touchID,this.preOvers);
  10458. arrs=this.getEles(ele,null,TouchManager._tEleArr);
  10459. if (!preO){
  10460. tO=this.createTouchO(ele,touchID);
  10461. this.preOvers.push(tO);
  10462. }else {
  10463. preO.tar=ele;
  10464. }
  10465. if (Browser.onMobile)
  10466. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OVER*/"mouseover");
  10467. var preDowns;
  10468. preDowns=isLeft ? this.preDowns :this.preRightDowns;
  10469. preO=this.getTouchFromArr(touchID,preDowns);
  10470. if (!preO){
  10471. tO=this.createTouchO(ele,touchID);
  10472. preDowns.push(tO);
  10473. }else {
  10474. preO.tar=ele;
  10475. }
  10476. this.sendEvents(arrs,isLeft ? /*laya.events.Event.MOUSE_DOWN*/"mousedown" :/*laya.events.Event.RIGHT_MOUSE_DOWN*/"rightmousedown");
  10477. this._clearTempArrs();
  10478. }
  10479. /**
  10480. *派发事件。
  10481. *@param eles 对象列表。
  10482. *@param type 事件类型。
  10483. */
  10484. __proto.sendEvents=function(eles,type){
  10485. var i=0,len=0;
  10486. len=eles.length;
  10487. this._event._stoped=false;
  10488. var _target;
  10489. _target=eles[0];
  10490. var tE;
  10491. for (i=0;i < len;i++){
  10492. tE=eles[i];
  10493. if (tE.destroyed)return;
  10494. tE.event(type,this._event.setTo(type,tE,_target));
  10495. if (this._event._stoped)
  10496. break ;
  10497. }
  10498. }
  10499. /**
  10500. *获取对象列表。
  10501. *@param start 起始节点。
  10502. *@param end 结束节点。
  10503. *@param rst 返回值。如果此值不为空,则将其赋值为计算结果,从而避免创建新数组;如果此值为空,则创建新数组返回。
  10504. *@return Array 返回节点列表。
  10505. */
  10506. __proto.getEles=function(start,end,rst){
  10507. if (!rst){
  10508. rst=[];
  10509. }else {
  10510. rst.length=0;
  10511. }
  10512. while (start && start !=end){
  10513. rst.push(start);
  10514. start=start.parent;
  10515. }
  10516. return rst;
  10517. }
  10518. /**
  10519. *touchMove时处理out事件和over时间。
  10520. *@param eleNew 新的根节点。
  10521. *@param elePre 旧的根节点。
  10522. *@param touchID (可选)touchID,默认为0。
  10523. */
  10524. __proto.checkMouseOutAndOverOfMove=function(eleNew,elePre,touchID){
  10525. (touchID===void 0)&& (touchID=0);
  10526. if (elePre==eleNew)
  10527. return;
  10528. var tar;
  10529. var arrs;
  10530. var i=0,len=0;
  10531. if (elePre.contains(eleNew)){
  10532. arrs=this.getEles(eleNew,elePre,TouchManager._tEleArr);
  10533. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OVER*/"mouseover");
  10534. }else if (eleNew.contains(elePre)){
  10535. arrs=this.getEles(elePre,eleNew,TouchManager._tEleArr);
  10536. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OUT*/"mouseout");
  10537. }else {
  10538. arrs=TouchManager._tEleArr;
  10539. arrs.length=0;
  10540. var oldArr;
  10541. oldArr=this.getEles(elePre,null,TouchManager._oldArr);
  10542. var newArr;
  10543. newArr=this.getEles(eleNew,null,TouchManager._newArr);
  10544. len=oldArr.length;
  10545. var tIndex=0;
  10546. for (i=0;i < len;i++){
  10547. tar=oldArr[i];
  10548. tIndex=newArr.indexOf(tar);
  10549. if (tIndex >=0){
  10550. newArr.splice(tIndex,newArr.length-tIndex);
  10551. break ;
  10552. }else {
  10553. arrs.push(tar);
  10554. }
  10555. }
  10556. if (arrs.length > 0){
  10557. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OUT*/"mouseout");
  10558. }
  10559. if (newArr.length > 0){
  10560. this.sendEvents(newArr,/*laya.events.Event.MOUSE_OVER*/"mouseover");
  10561. }
  10562. }
  10563. }
  10564. /**
  10565. *处理TouchMove事件
  10566. *@param ele 根节点
  10567. *@param touchID touchID
  10568. *
  10569. */
  10570. __proto.onMouseMove=function(ele,touchID){
  10571. if (!this.enable)
  10572. return;
  10573. var preO;
  10574. preO=this.getTouchFromArr(touchID,this.preOvers);
  10575. var arrs;
  10576. var tO;
  10577. if (!preO){
  10578. arrs=this.getEles(ele,null,TouchManager._tEleArr);
  10579. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OVER*/"mouseover");
  10580. this.preOvers.push(this.createTouchO(ele,touchID));
  10581. }else {
  10582. this.checkMouseOutAndOverOfMove(ele,preO.tar);
  10583. preO.tar=ele;
  10584. arrs=this.getEles(ele,null,TouchManager._tEleArr);
  10585. }
  10586. this.sendEvents(arrs,/*laya.events.Event.MOUSE_MOVE*/"mousemove");
  10587. this._clearTempArrs();
  10588. }
  10589. __proto.getLastOvers=function(){
  10590. TouchManager._tEleArr.length=0;
  10591. if (this.preOvers.length > 0 && this.preOvers[0].tar){
  10592. return this.getEles(this.preOvers[0].tar,null,TouchManager._tEleArr);
  10593. }
  10594. TouchManager._tEleArr.push(Laya.stage);
  10595. return TouchManager._tEleArr;
  10596. }
  10597. __proto.stageMouseOut=function(){
  10598. var lastOvers;
  10599. lastOvers=this.getLastOvers();
  10600. this.preOvers.length=0;
  10601. this.sendEvents(lastOvers,/*laya.events.Event.MOUSE_OUT*/"mouseout");
  10602. }
  10603. /**
  10604. *处理TouchEnd事件
  10605. *@param ele 根节点
  10606. *@param touchID touchID
  10607. *@param isLeft 是否为左键
  10608. */
  10609. __proto.onMouseUp=function(ele,touchID,isLeft){
  10610. (isLeft===void 0)&& (isLeft=false);
  10611. if (!this.enable)
  10612. return;
  10613. var preO;
  10614. var tO;
  10615. var arrs;
  10616. var oldArr;
  10617. var i=0,len=0;
  10618. var tar;
  10619. var sendArr;
  10620. var onMobile=Browser.onMobile;
  10621. arrs=this.getEles(ele,null,TouchManager._tEleArr);
  10622. this.sendEvents(arrs,isLeft ? /*laya.events.Event.MOUSE_UP*/"mouseup" :/*laya.events.Event.RIGHT_MOUSE_UP*/"rightmouseup");
  10623. var preDowns;
  10624. preDowns=isLeft ? this.preDowns :this.preRightDowns;
  10625. preO=this.getTouchFromArr(touchID,preDowns);
  10626. if (!preO){
  10627. }else {
  10628. var isDouble=false;
  10629. var now=Browser.now();
  10630. isDouble=now-this._lastClickTime < 300;
  10631. this._lastClickTime=now;
  10632. if (ele==preO.tar){
  10633. sendArr=arrs;
  10634. }else {
  10635. oldArr=this.getEles(preO.tar,null,TouchManager._oldArr);
  10636. sendArr=TouchManager._newArr;
  10637. sendArr.length=0;
  10638. len=oldArr.length;
  10639. for (i=0;i < len;i++){
  10640. tar=oldArr[i];
  10641. if (arrs.indexOf(tar)>=0){
  10642. sendArr.push(tar);
  10643. }
  10644. }
  10645. }
  10646. if (sendArr.length > 0){
  10647. this.sendEvents(sendArr,isLeft ? /*laya.events.Event.CLICK*/"click" :/*laya.events.Event.RIGHT_CLICK*/"rightclick");
  10648. }
  10649. if (isLeft && isDouble){
  10650. this.sendEvents(sendArr,/*laya.events.Event.DOUBLE_CLICK*/"doubleclick");
  10651. }
  10652. this.removeTouchFromArr(touchID,preDowns);
  10653. preO.tar=null;
  10654. Pool.recover("TouchData",preO);
  10655. }
  10656. preO=this.getTouchFromArr(touchID,this.preOvers);
  10657. if (!preO){
  10658. }else {
  10659. if (onMobile){
  10660. sendArr=this.getEles(preO.tar,null,sendArr);
  10661. if (sendArr && sendArr.length > 0){
  10662. this.sendEvents(sendArr,/*laya.events.Event.MOUSE_OUT*/"mouseout");
  10663. }
  10664. this.removeTouchFromArr(touchID,this.preOvers);
  10665. preO.tar=null;
  10666. Pool.recover("TouchData",preO);
  10667. }
  10668. }
  10669. this._clearTempArrs();
  10670. }
  10671. TouchManager._oldArr=[];
  10672. TouchManager._newArr=[];
  10673. TouchManager._tEleArr=[];
  10674. __static(TouchManager,
  10675. ['I',function(){return this.I=new TouchManager();}
  10676. ]);
  10677. return TouchManager;
  10678. })()
  10679. /**
  10680. *缩放命令
  10681. */
  10682. //class laya.display.cmd.ScaleCmd
  10683. var ScaleCmd=(function(){
  10684. function ScaleCmd(){
  10685. /**
  10686. *水平方向缩放值。
  10687. */
  10688. //this.scaleX=NaN;
  10689. /**
  10690. *垂直方向缩放值。
  10691. */
  10692. //this.scaleY=NaN;
  10693. /**
  10694. *(可选)水平方向轴心点坐标。
  10695. */
  10696. //this.pivotX=NaN;
  10697. /**
  10698. *(可选)垂直方向轴心点坐标。
  10699. */
  10700. //this.pivotY=NaN;
  10701. }
  10702. __class(ScaleCmd,'laya.display.cmd.ScaleCmd');
  10703. var __proto=ScaleCmd.prototype;
  10704. /**
  10705. *回收到对象池
  10706. */
  10707. __proto.recover=function(){
  10708. Pool.recover("ScaleCmd",this);
  10709. }
  10710. /**@private */
  10711. __proto.run=function(context,gx,gy){
  10712. context._scale(this.scaleX,this.scaleY,this.pivotX+gx,this.pivotY+gy);
  10713. }
  10714. /**@private */
  10715. __getset(0,__proto,'cmdID',function(){
  10716. return "Scale";
  10717. });
  10718. ScaleCmd.create=function(scaleX,scaleY,pivotX,pivotY){
  10719. var cmd=Pool.getItemByClass("ScaleCmd",ScaleCmd);
  10720. cmd.scaleX=scaleX;
  10721. cmd.scaleY=scaleY;
  10722. cmd.pivotX=pivotX;
  10723. cmd.pivotY=pivotY;
  10724. return cmd;
  10725. }
  10726. ScaleCmd.ID="Scale";
  10727. return ScaleCmd;
  10728. })()
  10729. /**
  10730. *透明命令
  10731. */
  10732. //class laya.display.cmd.AlphaCmd
  10733. var AlphaCmd=(function(){
  10734. function AlphaCmd(){
  10735. /**
  10736. *透明度
  10737. */
  10738. //this.alpha=NaN;
  10739. }
  10740. __class(AlphaCmd,'laya.display.cmd.AlphaCmd');
  10741. var __proto=AlphaCmd.prototype;
  10742. /**
  10743. *回收到对象池
  10744. */
  10745. __proto.recover=function(){
  10746. Pool.recover("AlphaCmd",this);
  10747. }
  10748. /**@private */
  10749. __proto.run=function(context,gx,gy){
  10750. context.alpha(this.alpha);
  10751. }
  10752. /**@private */
  10753. __getset(0,__proto,'cmdID',function(){
  10754. return "Alpha";
  10755. });
  10756. AlphaCmd.create=function(alpha){
  10757. var cmd=Pool.getItemByClass("AlphaCmd",AlphaCmd);
  10758. cmd.alpha=alpha;
  10759. return cmd;
  10760. }
  10761. AlphaCmd.ID="Alpha";
  10762. return AlphaCmd;
  10763. })()
  10764. /**
  10765. *绘制粒子
  10766. *@private
  10767. */
  10768. //class laya.display.cmd.DrawParticleCmd
  10769. var DrawParticleCmd=(function(){
  10770. function DrawParticleCmd(){
  10771. //this._templ=null;
  10772. }
  10773. __class(DrawParticleCmd,'laya.display.cmd.DrawParticleCmd');
  10774. var __proto=DrawParticleCmd.prototype;
  10775. /**
  10776. *回收到对象池
  10777. */
  10778. __proto.recover=function(){
  10779. this._templ=null;
  10780. Pool.recover("DrawParticleCmd",this);
  10781. }
  10782. /**@private */
  10783. __proto.run=function(context,gx,gy){
  10784. context.drawParticle(gx,gy,this._templ);
  10785. }
  10786. /**@private */
  10787. __getset(0,__proto,'cmdID',function(){
  10788. return "DrawParticleCmd";
  10789. });
  10790. DrawParticleCmd.create=function(_temp){
  10791. var cmd=Pool.getItemByClass("DrawParticleCmd",DrawParticleCmd);
  10792. cmd._templ=_temp;
  10793. return cmd;
  10794. }
  10795. DrawParticleCmd.ID="DrawParticleCmd";
  10796. return DrawParticleCmd;
  10797. })()
  10798. //class laya.webgl.canvas.save.SaveMark
  10799. var SaveMark=(function(){
  10800. function SaveMark(){
  10801. this._saveuse=0;
  10802. //this._preSaveMark=null;
  10803. }
  10804. __class(SaveMark,'laya.webgl.canvas.save.SaveMark');
  10805. var __proto=SaveMark.prototype;
  10806. Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true})
  10807. __proto.isSaveMark=function(){
  10808. return true;
  10809. }
  10810. __proto.restore=function(context){
  10811. context._saveMark=this._preSaveMark;
  10812. SaveMark.POOL[SaveMark.POOL._length++]=this;
  10813. }
  10814. SaveMark.Create=function(context){
  10815. var no=SaveMark.POOL;
  10816. var o=no._length > 0 ? no[--no._length] :(new SaveMark());
  10817. o._saveuse=0;
  10818. o._preSaveMark=context._saveMark;
  10819. context._saveMark=o;
  10820. return o;
  10821. }
  10822. SaveMark.POOL=SaveBase._createArray();
  10823. return SaveMark;
  10824. })()
  10825. /**
  10826. *<code>Mouse</code> 类用于控制鼠标光标样式。
  10827. */
  10828. //class laya.utils.Mouse
  10829. var Mouse=(function(){
  10830. function Mouse(){}
  10831. __class(Mouse,'laya.utils.Mouse');
  10832. /**
  10833. *设置鼠标样式
  10834. *@param cursorStr
  10835. *例如auto move no-drop col-resize
  10836. *all-scroll pointer not-allowed row-resize
  10837. *crosshair progress e-resize ne-resize
  10838. *default text n-resize nw-resize
  10839. *help vertical-text s-resize se-resize
  10840. *inherit wait w-resize sw-resize
  10841. */
  10842. __getset(1,Mouse,'cursor',function(){
  10843. return Mouse._style.cursor;
  10844. },function(cursorStr){
  10845. Mouse._style.cursor=cursorStr;
  10846. });
  10847. Mouse.hide=function(){
  10848. if (Mouse.cursor !="none"){
  10849. Mouse._preCursor=Mouse.cursor;
  10850. Mouse.cursor="none";
  10851. }
  10852. }
  10853. Mouse.show=function(){
  10854. if (Mouse.cursor=="none"){
  10855. if (Mouse._preCursor){
  10856. Mouse.cursor=Mouse._preCursor;
  10857. }else {
  10858. Mouse.cursor="auto";
  10859. }
  10860. }
  10861. }
  10862. Mouse._preCursor=null;
  10863. __static(Mouse,
  10864. ['_style',function(){return this._style=Browser.document.body.style;}
  10865. ]);
  10866. return Mouse;
  10867. })()
  10868. /**
  10869. *@private
  10870. *元素样式
  10871. */
  10872. //class laya.display.css.SpriteStyle
  10873. var SpriteStyle=(function(){
  10874. function SpriteStyle(){
  10875. //this.scaleX=NaN;
  10876. //this.scaleY=NaN;
  10877. //this.skewX=NaN;
  10878. //this.skewY=NaN;
  10879. //this.pivotX=NaN;
  10880. //this.pivotY=NaN;
  10881. //this.rotation=NaN;
  10882. //this.alpha=NaN;
  10883. //this.scrollRect=null;
  10884. //this.viewport=null;
  10885. //this.hitArea=null;
  10886. //this.dragging=null;
  10887. //this.blendMode=null;
  10888. this.reset();
  10889. }
  10890. __class(SpriteStyle,'laya.display.css.SpriteStyle');
  10891. var __proto=SpriteStyle.prototype;
  10892. /**
  10893. *重置,方便下次复用
  10894. */
  10895. __proto.reset=function(){
  10896. this.scaleX=this.scaleY=1;
  10897. this.skewX=this.skewY=0;
  10898. this.pivotX=this.pivotY=this.rotation=0;
  10899. this.alpha=1;
  10900. if(this.scrollRect)this.scrollRect.recover();
  10901. this.scrollRect=null;
  10902. if(this.viewport)this.viewport.recover();
  10903. this.viewport=null;
  10904. this.hitArea=null;
  10905. this.dragging=null;
  10906. this.blendMode=null;
  10907. return this
  10908. }
  10909. /**
  10910. *回收
  10911. */
  10912. __proto.recover=function(){
  10913. if (this===SpriteStyle.EMPTY)return;
  10914. Pool.recover("SpriteStyle",this.reset());
  10915. }
  10916. SpriteStyle.create=function(){
  10917. return Pool.getItemByClass("SpriteStyle",SpriteStyle);
  10918. }
  10919. SpriteStyle.EMPTY=new SpriteStyle();
  10920. return SpriteStyle;
  10921. })()
  10922. /**
  10923. *<code>Utils</code> 是工具类。
  10924. */
  10925. //class laya.utils.Utils
  10926. var Utils=(function(){
  10927. function Utils(){}
  10928. __class(Utils,'laya.utils.Utils');
  10929. Utils.toRadian=function(angle){
  10930. return angle *Utils._pi2;
  10931. }
  10932. Utils.toAngle=function(radian){
  10933. return radian *Utils._pi;
  10934. }
  10935. Utils.toHexColor=function(color){
  10936. if (color < 0 || isNaN(color))return null;
  10937. var str=color.toString(16);
  10938. while (str.length < 6)str="0"+str;
  10939. return "#"+str;
  10940. }
  10941. Utils.getGID=function(){
  10942. return Utils._gid++;
  10943. }
  10944. Utils.concatArray=function(source,array){
  10945. if (!array)return source;
  10946. if (!source)return array;
  10947. var i=0,len=array.length;
  10948. for (i=0;i < len;i++){
  10949. source.push(array[i]);
  10950. }
  10951. return source;
  10952. }
  10953. Utils.clearArray=function(array){
  10954. if (!array)return array;
  10955. array.length=0;
  10956. return array;
  10957. }
  10958. Utils.copyArray=function(source,array){
  10959. source || (source=[]);
  10960. if (!array)return source;
  10961. source.length=array.length;
  10962. var i=0,len=array.length;
  10963. for (i=0;i < len;i++){
  10964. source[i]=array[i];
  10965. }
  10966. return source;
  10967. }
  10968. Utils.getGlobalRecByPoints=function(sprite,x0,y0,x1,y1){
  10969. var newLTPoint;
  10970. newLTPoint=Point.create().setTo(x0,y0);
  10971. newLTPoint=sprite.localToGlobal(newLTPoint);
  10972. var newRBPoint;
  10973. newRBPoint=Point.create().setTo(x1,y1);
  10974. newRBPoint=sprite.localToGlobal(newRBPoint);
  10975. var rst=Rectangle._getWrapRec([newLTPoint.x,newLTPoint.y,newRBPoint.x,newRBPoint.y]);
  10976. newLTPoint.recover();
  10977. newRBPoint.recover();
  10978. return rst;
  10979. }
  10980. Utils.getGlobalPosAndScale=function(sprite){
  10981. return Utils.getGlobalRecByPoints(sprite,0,0,1,1);
  10982. }
  10983. Utils.bind=function(fun,scope){
  10984. var rst=fun;
  10985. /*__JS__ */rst=fun.bind(scope);;
  10986. return rst;
  10987. }
  10988. Utils.measureText=function(txt,font){
  10989. return RunDriver.measureText(txt,font);
  10990. }
  10991. Utils.updateOrder=function(array){
  10992. if (!array || array.length < 2)return false;
  10993. var i=1,j=0,len=array.length,key=NaN,c;
  10994. while (i < len){
  10995. j=i;
  10996. c=array[j];
  10997. key=array[j]._zOrder;
  10998. while (--j >-1){
  10999. if (array[j]._zOrder > key)array[j+1]=array[j];
  11000. else break ;
  11001. }
  11002. array[j+1]=c;
  11003. i++;
  11004. }
  11005. return true;
  11006. }
  11007. Utils.transPointList=function(points,x,y){
  11008. var i=0,len=points.length;
  11009. for (i=0;i < len;i+=2){
  11010. points[i]+=x;
  11011. points[i+1]+=y;
  11012. }
  11013. }
  11014. Utils.parseInt=function(str,radix){
  11015. (radix===void 0)&& (radix=0);
  11016. var result=Browser.window.parseInt(str,radix);
  11017. if (isNaN(result))return 0;
  11018. return result;
  11019. }
  11020. Utils.getFileExtension=function(path){
  11021. Utils._extReg.lastIndex=path.lastIndexOf(".");
  11022. var result=Utils._extReg.exec(path);
  11023. if (result && result.length > 1){
  11024. return result[1].toLowerCase();
  11025. }
  11026. return null;
  11027. }
  11028. Utils.getTransformRelativeToWindow=function(coordinateSpace,x,y){
  11029. var stage=Laya.stage;
  11030. var globalTransform=laya.utils.Utils.getGlobalPosAndScale(coordinateSpace);
  11031. var canvasMatrix=stage._canvasTransform.clone();
  11032. var canvasLeft=canvasMatrix.tx;
  11033. var canvasTop=canvasMatrix.ty;
  11034. canvasMatrix.rotate(-Math.PI / 180 *Laya.stage.canvasDegree);
  11035. canvasMatrix.scale(Laya.stage.clientScaleX,Laya.stage.clientScaleY);
  11036. var perpendicular=(Laya.stage.canvasDegree % 180 !=0);
  11037. var tx=NaN,ty=NaN;
  11038. if (perpendicular){
  11039. tx=y+globalTransform.y;
  11040. ty=x+globalTransform.x;
  11041. tx *=canvasMatrix.d;
  11042. ty *=canvasMatrix.a;
  11043. if (Laya.stage.canvasDegree==90){
  11044. tx=canvasLeft-tx;
  11045. ty+=canvasTop;
  11046. }
  11047. else {
  11048. tx+=canvasLeft;
  11049. ty=canvasTop-ty;
  11050. }
  11051. }
  11052. else {
  11053. tx=x+globalTransform.x;
  11054. ty=y+globalTransform.y;
  11055. tx *=canvasMatrix.a;
  11056. ty *=canvasMatrix.d;
  11057. tx+=canvasLeft;
  11058. ty+=canvasTop;
  11059. }
  11060. ty+=Laya.stage['_safariOffsetY'];
  11061. var domScaleX=NaN,domScaleY=NaN;
  11062. if (perpendicular){
  11063. domScaleX=canvasMatrix.d *globalTransform.height;
  11064. domScaleY=canvasMatrix.a *globalTransform.width;
  11065. }else {
  11066. domScaleX=canvasMatrix.a *globalTransform.width;
  11067. domScaleY=canvasMatrix.d *globalTransform.height;
  11068. }
  11069. return {x:tx,y:ty,scaleX:domScaleX,scaleY:domScaleY};
  11070. }
  11071. Utils.fitDOMElementInArea=function(dom,coordinateSpace,x,y,width,height){
  11072. if (!dom._fitLayaAirInitialized){
  11073. dom._fitLayaAirInitialized=true;
  11074. dom.style.transformOrigin=dom.style.webKittransformOrigin="left top";
  11075. dom.style.position="absolute"
  11076. };
  11077. var transform=Utils.getTransformRelativeToWindow(coordinateSpace,x,y);
  11078. dom.style.transform=dom.style.webkitTransform="scale("+transform.scaleX+","+transform.scaleY+") rotate("+(Laya.stage.canvasDegree)+"deg)";
  11079. dom.style.width=width+'px';
  11080. dom.style.height=height+'px';
  11081. dom.style.left=transform.x+'px';
  11082. dom.style.top=transform.y+'px';
  11083. }
  11084. Utils.isOkTextureList=function(textureList){
  11085. if (!textureList)return false;
  11086. var i=0,len=textureList.length;
  11087. var tTexture;
  11088. for (i=0;i < len;i++){
  11089. tTexture=textureList[i];
  11090. if (!tTexture || !tTexture._getSource())return false;
  11091. }
  11092. return true;
  11093. }
  11094. Utils.isOKCmdList=function(cmds){
  11095. if (!cmds)return false;
  11096. var i=0,len=cmds.length;
  11097. var cmd;
  11098. var tex;
  11099. for (i=0;i < len;i++){
  11100. cmd=cmds[i];
  11101. }
  11102. return true;
  11103. }
  11104. Utils.getQueryString=function(name){
  11105. if (Browser.onMiniGame)return null;
  11106. if(!window.location || !window.location.search)
  11107. return null;
  11108. var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
  11109. var r=window.location.search.substr(1).match(reg);
  11110. if (r !=null)return unescape(r[2]);
  11111. return null;
  11112. }
  11113. Utils._gid=1;
  11114. Utils._pi=180 / Math.PI;
  11115. Utils._pi2=Math.PI / 180;
  11116. Utils._extReg=/\.(\w+)\??/g;
  11117. Utils.parseXMLFromString=function(value){
  11118. var rst;
  11119. value=value.replace(/>\s+</g,'><');
  11120. /*__JS__ */rst=(new DOMParser()).parseFromString(value,'text/xml');
  11121. if (rst.firstChild.textContent.indexOf("This page contains the following errors")>-1){
  11122. throw new Error(rst.firstChild.firstChild.textContent);
  11123. }
  11124. return rst;
  11125. }
  11126. return Utils;
  11127. })()
  11128. // 注意长宽都不要超过256,一个是影响效率,一个是超出表达能力
  11129. //class laya.webgl.text.AtlasGrid
  11130. var AtlasGrid=(function(){
  11131. function AtlasGrid(width,height,id){
  11132. this.atlasID=0;
  11133. this._width=0;
  11134. this._height=0;
  11135. this._texCount=0;
  11136. this._rowInfo=null;
  11137. // 当前行的最大长度
  11138. this._cells=null;
  11139. // 每个格子的信息。{type,w,h}相当于一个距离场. type=0 表示空闲的。不为0的情况下填充的是宽高(有什么用呢)
  11140. this._used=0;
  11141. (width===void 0)&& (width=0);
  11142. (height===void 0)&& (height=0);
  11143. (id===void 0)&& (id=0);
  11144. this._cells=null;
  11145. this._rowInfo=null;
  11146. this.atlasID=id;
  11147. this._init(width,height);
  11148. }
  11149. __class(AtlasGrid,'laya.webgl.text.AtlasGrid');
  11150. var __proto=AtlasGrid.prototype;
  11151. //------------------------------------------------------------------
  11152. __proto.addRect=function(type,width,height,pt){
  11153. if (!this._get(width,height,pt))
  11154. return false;
  11155. this._fill(pt.x,pt.y,width,height,type);
  11156. this._texCount++;
  11157. return true;
  11158. }
  11159. //------------------------------------------------------------------------------
  11160. __proto._release=function(){
  11161. this._cells=null;
  11162. this._rowInfo=null;
  11163. }
  11164. //------------------------------------------------------------------------------
  11165. __proto._init=function(width,height){
  11166. this._width=width;
  11167. this._height=height;
  11168. this._release();
  11169. if (this._width==0)return false;
  11170. this._cells=new Uint8Array(this._width *this._height*3);
  11171. this._rowInfo=new Uint8Array(this._height);
  11172. this._used=0;
  11173. this._clear();
  11174. return true;
  11175. }
  11176. //------------------------------------------------------------------
  11177. __proto._get=function(width,height,pt){
  11178. if (width > this._width || height >this._height){
  11179. return false;
  11180. };
  11181. var rx=-1;
  11182. var ry=-1;
  11183. var nWidth=this._width;
  11184. var nHeight=this._height;
  11185. var pCellBox=this._cells;
  11186. for (var y=0;y < nHeight;y++){
  11187. if (this._rowInfo[y] < width)continue ;
  11188. for (var x=0;x < nWidth;){
  11189. var tm=(y *nWidth+x)*3;
  11190. if (pCellBox[tm] !=0 || pCellBox[tm+1] < width || pCellBox[tm+2] < height){
  11191. x+=pCellBox[tm+1];
  11192. continue ;
  11193. }
  11194. rx=x;
  11195. ry=y;
  11196. for (var xx=0;xx < width;xx++){
  11197. if (pCellBox[3*xx+tm+2] < height){
  11198. rx=-1;
  11199. break ;
  11200. }
  11201. }
  11202. if (rx < 0){
  11203. x+=pCellBox[tm+1];
  11204. continue ;
  11205. }
  11206. pt.x=rx;
  11207. pt.y=ry;
  11208. return true;
  11209. }
  11210. }
  11211. return false;
  11212. }
  11213. //------------------------------------------------------------------
  11214. __proto._fill=function(x,y,w,h,type){
  11215. var nWidth=this._width;
  11216. var nHeghit=this._height;
  11217. this._check((x+w)<=nWidth && (y+h)<=nHeghit);
  11218. for (var yy=y;yy < (h+y);++yy){
  11219. this._check(this._rowInfo[yy] >=w);
  11220. this._rowInfo[yy]-=w;
  11221. for (var xx=0;xx < w;xx++){
  11222. var tm=(x+yy *nWidth+xx)*3;
  11223. this._check(this._cells[tm]==0);
  11224. this._cells[tm]=type;
  11225. this._cells[tm+1]=w;
  11226. this._cells[tm+2]=h;
  11227. }
  11228. }
  11229. if (x > 0){
  11230. for (yy=0;yy < h;++yy){
  11231. var s=0;
  11232. for (xx=x-1;xx >=0;--xx,++s){
  11233. if (this._cells[((y+yy)*nWidth+xx)*3] !=0)break ;
  11234. }
  11235. for (xx=s;xx > 0;--xx){
  11236. this._cells[((y+yy)*nWidth+x-xx)*3+1]=xx;
  11237. this._check(xx > 0);
  11238. }
  11239. }
  11240. }
  11241. if (y > 0){
  11242. for (xx=x;xx < (x+w);++xx){
  11243. s=0;
  11244. for (yy=y-1;yy >=0;--yy,s++){
  11245. if (this._cells[(xx+yy *nWidth)*3] !=0)break ;
  11246. }
  11247. for (yy=s;yy > 0;--yy){
  11248. this._cells[(xx+(y-yy)*nWidth)*3+2]=yy;
  11249. this._check(yy > 0);
  11250. }
  11251. }
  11252. }
  11253. this._used+=(w*h)/(this._width*this._height);
  11254. }
  11255. __proto._check=function(ret){
  11256. if (ret==false){
  11257. console.log("xtexMerger 错误啦");
  11258. }
  11259. }
  11260. //------------------------------------------------------------------
  11261. __proto._clear=function(){
  11262. this._texCount=0;
  11263. for (var y=0;y < this._height;y++){
  11264. this._rowInfo[y]=this._width;
  11265. }
  11266. for (var i=0;i < this._height;i++){
  11267. for (var j=0;j < this._width;j++){
  11268. var tm=(i *this._width+j)*3;
  11269. this._cells[tm]=0;
  11270. this._cells[tm+1]=this._width-j;
  11271. this._cells[tm+2]=this._width-i;
  11272. }
  11273. }
  11274. }
  11275. return AtlasGrid;
  11276. })()
  11277. /**
  11278. *<code>BitmapFont</code> 是位图字体类,用于定义位图字体信息。
  11279. *字体制作及使用方法,请参考文章
  11280. *@see http://ldc2.layabox.com/doc/?nav=ch-js-1-2-5
  11281. */
  11282. //class laya.display.BitmapFont
  11283. var BitmapFont=(function(){
  11284. function BitmapFont(){
  11285. this._texture=null;
  11286. this._fontCharDic={};
  11287. this._fontWidthMap={};
  11288. this._complete=null;
  11289. this._path=null;
  11290. this._maxWidth=0;
  11291. this._spaceWidth=10;
  11292. this._padding=null;
  11293. /**当前位图字体字号,使用时,如果字号和设置不同,并且autoScaleSize=true,则按照设置字号比率进行缩放显示。*/
  11294. this.fontSize=12;
  11295. /**表示是否根据实际使用的字体大小缩放位图字体大小。*/
  11296. this.autoScaleSize=false;
  11297. /**字符间距(以像素为单位)。*/
  11298. this.letterSpacing=0;
  11299. }
  11300. __class(BitmapFont,'laya.display.BitmapFont');
  11301. var __proto=BitmapFont.prototype;
  11302. /**
  11303. *通过指定位图字体文件路径,加载位图字体文件,加载完成后会自动解析。
  11304. *@param path 位图字体文件的路径。
  11305. *@param complete 加载并解析完成的回调。
  11306. */
  11307. __proto.loadFont=function(path,complete){
  11308. this._path=path;
  11309. this._complete=complete;
  11310. if (!path || path.indexOf(".fnt")===-1){
  11311. console.error('Bitmap font configuration information must be a ".fnt" file');
  11312. return;
  11313. }
  11314. Laya.loader.load([{url:path,type:/*laya.net.Loader.XML*/"xml"},{url:path.replace(".fnt",".png"),type:/*laya.net.Loader.IMAGE*/"image"}],Handler.create(this,this._onLoaded));
  11315. }
  11316. /**
  11317. *@private
  11318. */
  11319. __proto._onLoaded=function(){
  11320. this.parseFont(Loader.getRes(this._path),Loader.getRes(this._path.replace(".fnt",".png")));
  11321. this._complete && this._complete.run();
  11322. }
  11323. /**
  11324. *解析字体文件。
  11325. *@param xml 字体文件XML。
  11326. *@param texture 字体的纹理。
  11327. */
  11328. __proto.parseFont=function(xml,texture){
  11329. if (xml==null || texture==null)return;
  11330. this._texture=texture;
  11331. var tX=0;
  11332. var tScale=1;
  11333. var tInfo=xml.getElementsByTagName("info");
  11334. if (!tInfo[0].getAttributeNode){
  11335. return this.parseFont2(xml,texture);
  11336. }
  11337. this.fontSize=parseInt(tInfo[0].getAttributeNode("size").nodeValue);
  11338. var tPadding=tInfo[0].getAttributeNode("padding").nodeValue;
  11339. var tPaddingArray=tPadding.split(",");
  11340. this._padding=[parseInt(tPaddingArray[0]),parseInt(tPaddingArray[1]),parseInt(tPaddingArray[2]),parseInt(tPaddingArray[3])];
  11341. var chars;
  11342. chars=xml.getElementsByTagName("char");
  11343. var i=0;
  11344. for (i=0;i < chars.length;i++){
  11345. var tAttribute=chars[i];
  11346. var tId=parseInt(tAttribute.getAttributeNode("id").nodeValue);
  11347. var xOffset=parseInt(tAttribute.getAttributeNode("xoffset").nodeValue)/ tScale;
  11348. var yOffset=parseInt(tAttribute.getAttributeNode("yoffset").nodeValue)/ tScale;
  11349. var xAdvance=parseInt(tAttribute.getAttributeNode("xadvance").nodeValue)/ tScale;
  11350. var region=new Rectangle();
  11351. region.x=parseInt(tAttribute.getAttributeNode("x").nodeValue);
  11352. region.y=parseInt(tAttribute.getAttributeNode("y").nodeValue);
  11353. region.width=parseInt(tAttribute.getAttributeNode("width").nodeValue);
  11354. region.height=parseInt(tAttribute.getAttributeNode("height").nodeValue);
  11355. var tTexture=Texture.create((texture),region.x,region.y,region.width,region.height,xOffset,yOffset);
  11356. this._maxWidth=Math.max(this._maxWidth,xAdvance+this.letterSpacing);
  11357. this._fontCharDic[tId]=tTexture;
  11358. this._fontWidthMap[tId]=xAdvance;
  11359. }
  11360. }
  11361. /**
  11362. *解析字体文件。
  11363. *@param xml 字体文件XML。
  11364. *@param texture 字体的纹理。
  11365. */
  11366. __proto.parseFont2=function(xml,texture){
  11367. if (xml==null || texture==null)return;
  11368. this._texture=texture;
  11369. var tX=0;
  11370. var tScale=1;
  11371. var tInfo=xml.getElementsByTagName("info");
  11372. this.fontSize=parseInt(tInfo[0].attributes["size"].nodeValue);
  11373. var tPadding=tInfo[0].attributes["padding"].nodeValue;
  11374. var tPaddingArray=tPadding.split(",");
  11375. this._padding=[parseInt(tPaddingArray[0]),parseInt(tPaddingArray[1]),parseInt(tPaddingArray[2]),parseInt(tPaddingArray[3])];
  11376. var chars=xml.getElementsByTagName("char");
  11377. var i=0;
  11378. for (i=0;i < chars.length;i++){
  11379. var tAttribute=chars[i].attributes;
  11380. var tId=parseInt(tAttribute["id"].nodeValue);
  11381. var xOffset=parseInt(tAttribute["xoffset"].nodeValue)/ tScale;
  11382. var yOffset=parseInt(tAttribute["yoffset"].nodeValue)/ tScale;
  11383. var xAdvance=parseInt(tAttribute["xadvance"].nodeValue)/ tScale;
  11384. var region=new Rectangle();
  11385. region.x=parseInt(tAttribute["x"].nodeValue);
  11386. region.y=parseInt(tAttribute["y"].nodeValue);
  11387. region.width=parseInt(tAttribute["width"].nodeValue);
  11388. region.height=parseInt(tAttribute["height"].nodeValue);
  11389. var tTexture=Texture.create((texture),region.x,region.y,region.width,region.height,xOffset,yOffset);
  11390. this._maxWidth=Math.max(this._maxWidth,xAdvance+this.letterSpacing);
  11391. this._fontCharDic[tId]=tTexture;
  11392. this._fontWidthMap[tId]=xAdvance;
  11393. }
  11394. }
  11395. /**
  11396. *获取指定字符的字体纹理对象。
  11397. *@param char 字符。
  11398. *@return 指定的字体纹理对象。
  11399. */
  11400. __proto.getCharTexture=function(char){
  11401. return this._fontCharDic[char.charCodeAt(0)];
  11402. }
  11403. /**
  11404. *销毁位图字体,调用Text.unregisterBitmapFont 时,默认会销毁。
  11405. */
  11406. __proto.destroy=function(){
  11407. if (this._texture){
  11408. for (var p in this._fontCharDic){
  11409. var tTexture=this._fontCharDic[p];
  11410. if (tTexture)tTexture.destroy();
  11411. }
  11412. this._texture.destroy();
  11413. this._fontCharDic=null;
  11414. this._fontWidthMap=null;
  11415. this._texture=null;
  11416. this._complete=null;
  11417. this._padding=null;
  11418. }
  11419. }
  11420. /**
  11421. *设置空格的宽(如果字体库有空格,这里就可以不用设置了)。
  11422. *@param spaceWidth 宽度,单位为像素。
  11423. */
  11424. __proto.setSpaceWidth=function(spaceWidth){
  11425. this._spaceWidth=spaceWidth;
  11426. }
  11427. /**
  11428. *获取指定字符的宽度。
  11429. *@param char 字符。
  11430. *@return 宽度。
  11431. */
  11432. __proto.getCharWidth=function(char){
  11433. var code=char.charCodeAt(0);
  11434. if (this._fontWidthMap[code])return this._fontWidthMap[code]+this.letterSpacing;
  11435. if (char===" ")return this._spaceWidth+this.letterSpacing;
  11436. return 0;
  11437. }
  11438. /**
  11439. *获取指定文本内容的宽度。
  11440. *@param text 文本内容。
  11441. *@return 宽度。
  11442. */
  11443. __proto.getTextWidth=function(text){
  11444. var tWidth=0;
  11445. for (var i=0,n=text.length;i < n;i++){
  11446. tWidth+=this.getCharWidth(text.charAt(i));
  11447. }
  11448. return tWidth;
  11449. }
  11450. /**
  11451. *获取最大字符宽度。
  11452. */
  11453. __proto.getMaxWidth=function(){
  11454. return this._maxWidth;
  11455. }
  11456. /**
  11457. *获取最大字符高度。
  11458. */
  11459. __proto.getMaxHeight=function(){
  11460. return this.fontSize;
  11461. }
  11462. /**
  11463. *@private
  11464. *将指定的文本绘制到指定的显示对象上。
  11465. */
  11466. __proto._drawText=function(text,sprite,drawX,drawY,align,width){
  11467. var tWidth=this.getTextWidth(text);
  11468. var tTexture;
  11469. var dx=0;
  11470. align==="center" && (dx=(width-tWidth)/ 2);
  11471. align==="right" && (dx=(width-tWidth));
  11472. var tx=0;
  11473. for (var i=0,n=text.length;i < n;i++){
  11474. tTexture=this.getCharTexture(text.charAt(i));
  11475. if (tTexture){
  11476. sprite.graphics.drawImage(tTexture,drawX+tx+dx,drawY);
  11477. tx+=this.getCharWidth(text.charAt(i));
  11478. }
  11479. }
  11480. }
  11481. return BitmapFont;
  11482. })()
  11483. //class laya.webgl.canvas.save.SaveTranslate
  11484. var SaveTranslate=(function(){
  11485. function SaveTranslate(){
  11486. this._mat=new Matrix();
  11487. }
  11488. __class(SaveTranslate,'laya.webgl.canvas.save.SaveTranslate');
  11489. var __proto=SaveTranslate.prototype;
  11490. Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true})
  11491. __proto.isSaveMark=function(){return false;}
  11492. __proto.restore=function(context){
  11493. this._mat.copyTo(context._curMat);
  11494. SaveTranslate.POOL[SaveTranslate.POOL._length++]=this;
  11495. }
  11496. SaveTranslate.save=function(context){
  11497. var no=SaveTranslate.POOL;
  11498. var o=no._length > 0 ? no[--no._length] :(new SaveTranslate());
  11499. context._curMat.copyTo(o._mat);
  11500. var _save=context._save;
  11501. _save[_save._length++]=o;
  11502. }
  11503. SaveTranslate.POOL=SaveBase._createArray();
  11504. return SaveTranslate;
  11505. })()
  11506. /**
  11507. *Config 用于配置一些全局参数。如需更改,请在初始化引擎之前设置。
  11508. */
  11509. //class Config
  11510. var Config=(function(){
  11511. function Config(){}
  11512. __class(Config,'Config');
  11513. Config.animationInterval=50;
  11514. Config.isAntialias=false;
  11515. Config.isAlpha=false;
  11516. Config.premultipliedAlpha=true;
  11517. Config.isStencil=true;
  11518. Config.preserveDrawingBuffer=false;
  11519. Config.webGL2D_MeshAllocMaxMem=true;
  11520. Config.is2DPixelArtGame=false;
  11521. Config.useWebGL2=false;
  11522. Config.useRetinalCanvas=false;
  11523. return Config;
  11524. })()
  11525. //class laya.webgl.canvas.BlendMode
  11526. var BlendMode=(function(){
  11527. function BlendMode(){}
  11528. __class(BlendMode,'laya.webgl.canvas.BlendMode');
  11529. BlendMode._init_=function(gl){
  11530. BlendMode.fns=[BlendMode.BlendNormal,BlendMode.BlendAdd,BlendMode.BlendMultiply,BlendMode.BlendScreen,BlendMode.BlendOverlay,BlendMode.BlendLight,BlendMode.BlendMask,BlendMode.BlendDestinationOut];
  11531. BlendMode.targetFns=[BlendMode.BlendNormalTarget,BlendMode.BlendAddTarget,BlendMode.BlendMultiplyTarget,BlendMode.BlendScreenTarget,BlendMode.BlendOverlayTarget,BlendMode.BlendLightTarget,BlendMode.BlendMask,BlendMode.BlendDestinationOut];
  11532. }
  11533. BlendMode.BlendNormal=function(gl){
  11534. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  11535. }
  11536. BlendMode.BlendAdd=function(gl){
  11537. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.DST_ALPHA*/0x0304);
  11538. }
  11539. BlendMode.BlendMultiply=function(gl){
  11540. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.DST_COLOR*/0x0306,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  11541. }
  11542. BlendMode.BlendScreen=function(gl){
  11543. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1);
  11544. }
  11545. BlendMode.BlendOverlay=function(gl){
  11546. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_COLOR*/0x0301);
  11547. }
  11548. BlendMode.BlendLight=function(gl){
  11549. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1);
  11550. }
  11551. BlendMode.BlendNormalTarget=function(gl){
  11552. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  11553. }
  11554. BlendMode.BlendAddTarget=function(gl){
  11555. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.DST_ALPHA*/0x0304);
  11556. }
  11557. BlendMode.BlendMultiplyTarget=function(gl){
  11558. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.DST_COLOR*/0x0306,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  11559. }
  11560. BlendMode.BlendScreenTarget=function(gl){
  11561. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1);
  11562. }
  11563. BlendMode.BlendOverlayTarget=function(gl){
  11564. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_COLOR*/0x0301);
  11565. }
  11566. BlendMode.BlendLightTarget=function(gl){
  11567. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1);
  11568. }
  11569. BlendMode.BlendMask=function(gl){
  11570. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ZERO*/0,/*laya.webgl.WebGLContext.SRC_ALPHA*/0x0302);
  11571. }
  11572. BlendMode.BlendDestinationOut=function(gl){
  11573. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ZERO*/0,/*laya.webgl.WebGLContext.ZERO*/0);
  11574. }
  11575. BlendMode.activeBlendFunction=null;
  11576. BlendMode.NAMES=["normal","add","multiply","screen","overlay","light","mask","destination-out"];
  11577. BlendMode.TOINT={"normal":0,"add":1,"multiply":2,"screen":3 ,"overlay":4,"light":5,"mask":6,"destination-out":7,"lighter":1 };
  11578. BlendMode.NORMAL="normal";
  11579. BlendMode.ADD="add";
  11580. BlendMode.MULTIPLY="multiply";
  11581. BlendMode.SCREEN="screen";
  11582. BlendMode.OVERLAY="overlay";
  11583. BlendMode.LIGHT="light";
  11584. BlendMode.MASK="mask";
  11585. BlendMode.DESTINATIONOUT="destination-out";
  11586. BlendMode.LIGHTER="lighter";
  11587. BlendMode.fns=[];
  11588. BlendMode.targetFns=[];
  11589. return BlendMode;
  11590. })()
  11591. /**
  11592. *<p><code>MouseManager</code> 是鼠标、触摸交互管理器。</p>
  11593. *<p>鼠标事件流包括捕获阶段、目标阶段、冒泡阶段。<br/>
  11594. *捕获阶段:此阶段引擎会从stage开始递归检测stage及其子对象,直到找到命中的目标对象或者未命中任何对象;<br/>
  11595. *目标阶段:找到命中的目标对象;<br/>
  11596. *冒泡阶段:事件离开目标对象,按节点层级向上逐层通知,直到到达舞台的过程。</p>
  11597. */
  11598. //class laya.events.MouseManager
  11599. var MouseManager=(function(){
  11600. function MouseManager(){
  11601. /**canvas 上的鼠标X坐标。*/
  11602. this.mouseX=0;
  11603. /**canvas 上的鼠标Y坐标。*/
  11604. this.mouseY=0;
  11605. /**是否禁用除 stage 以外的鼠标事件检测。*/
  11606. this.disableMouseEvent=false;
  11607. /**鼠标按下的时间。单位为毫秒。*/
  11608. this.mouseDownTime=0;
  11609. /**鼠标移动精度。*/
  11610. this.mouseMoveAccuracy=2;
  11611. this._stage=null;
  11612. /**@private 希望capture鼠标事件的对象。*/
  11613. this._captureSp=null;
  11614. /**@private capture对象独占消息 */
  11615. this._captureExlusiveMode=false;
  11616. /**@private 在发送事件的过程中,是否发送给了_captureSp */
  11617. this._hitCaputreSp=false;
  11618. this._target=null;
  11619. this._lastMoveTimer=0;
  11620. this._isLeftMouse=false;
  11621. this._touchIDs={};
  11622. this._id=1;
  11623. this._tTouchID=0;
  11624. this._event=new Event();
  11625. this._captureChain=[];
  11626. this._matrix=new Matrix();
  11627. this._point=new Point();
  11628. this._rect=new Rectangle();
  11629. this._prePoint=new Point();
  11630. this._curTouchID=NaN;
  11631. }
  11632. __class(MouseManager,'laya.events.MouseManager');
  11633. var __proto=MouseManager.prototype;
  11634. /**
  11635. *@private
  11636. *初始化。
  11637. */
  11638. __proto.__init__=function(stage,canvas){
  11639. var _$this=this;
  11640. this._stage=stage;
  11641. var _this=this;
  11642. canvas.oncontextmenu=function (e){
  11643. if (MouseManager.enabled)return false;
  11644. }
  11645. canvas.addEventListener('mousedown',function(e){
  11646. if (MouseManager.enabled){
  11647. if(!Browser.onIE)e.preventDefault();
  11648. _this.mouseDownTime=Browser.now();
  11649. _$this.runEvent(e);
  11650. }
  11651. });
  11652. canvas.addEventListener('mouseup',function(e){
  11653. if (MouseManager.enabled){
  11654. e.preventDefault();
  11655. _this.mouseDownTime=-Browser.now();
  11656. _$this.runEvent(e);
  11657. }
  11658. },true);
  11659. canvas.addEventListener('mousemove',function(e){
  11660. if (MouseManager.enabled){
  11661. e.preventDefault();
  11662. var now=Browser.now();
  11663. if (now-_this._lastMoveTimer < 10)return;
  11664. _this._lastMoveTimer=now;
  11665. _$this.runEvent(e);
  11666. }
  11667. },true);
  11668. canvas.addEventListener("mouseout",function(e){
  11669. if (MouseManager.enabled)_$this.runEvent(e);
  11670. })
  11671. canvas.addEventListener("mouseover",function(e){
  11672. if (MouseManager.enabled)_$this.runEvent(e);
  11673. })
  11674. canvas.addEventListener("touchstart",function(e){
  11675. if (MouseManager.enabled){
  11676. if (!MouseManager._isFirstTouch&&!Input.isInputting)e.preventDefault();
  11677. _this.mouseDownTime=Browser.now();
  11678. _$this.runEvent(e);
  11679. }
  11680. });
  11681. canvas.addEventListener("touchend",function(e){
  11682. if (MouseManager.enabled){
  11683. if (!MouseManager._isFirstTouch&&!Input.isInputting)e.preventDefault();
  11684. MouseManager._isFirstTouch=false;
  11685. _this.mouseDownTime=-Browser.now();
  11686. _$this.runEvent(e);
  11687. }else {
  11688. _$this._curTouchID=NaN;
  11689. }
  11690. },true);
  11691. canvas.addEventListener("touchmove",function(e){
  11692. if (MouseManager.enabled){
  11693. e.preventDefault();
  11694. _$this.runEvent(e);
  11695. }
  11696. },true);
  11697. canvas.addEventListener("touchcancel",function(e){
  11698. if (MouseManager.enabled){
  11699. e.preventDefault();
  11700. _$this.runEvent(e);
  11701. }else {
  11702. _$this._curTouchID=NaN;
  11703. }
  11704. },true);
  11705. canvas.addEventListener('mousewheel',function(e){
  11706. if (MouseManager.enabled)_$this.runEvent(e);
  11707. });
  11708. canvas.addEventListener('DOMMouseScroll',function(e){
  11709. if (MouseManager.enabled)_$this.runEvent(e);
  11710. });
  11711. }
  11712. __proto.initEvent=function(e,nativeEvent){
  11713. var _this=this;
  11714. _this._event._stoped=false;
  11715. _this._event.nativeEvent=nativeEvent || e;
  11716. _this._target=null;
  11717. this._point.setTo(e.pageX || e.clientX,e.pageY || e.clientY);
  11718. if (this._stage._canvasTransform){
  11719. this._stage._canvasTransform.invertTransformPoint(this._point);
  11720. _this.mouseX=this._point.x;
  11721. _this.mouseY=this._point.y;
  11722. }
  11723. _this._event.touchId=e.identifier || 0;
  11724. this._tTouchID=_this._event.touchId;
  11725. var evt;
  11726. evt=TouchManager.I._event;
  11727. evt._stoped=false;
  11728. evt.nativeEvent=_this._event.nativeEvent;
  11729. evt.touchId=_this._event.touchId;
  11730. }
  11731. __proto.checkMouseWheel=function(e){
  11732. this._event.delta=e.wheelDelta ? e.wheelDelta *0.025 :-e.detail;
  11733. var _lastOvers=TouchManager.I.getLastOvers();
  11734. for (var i=0,n=_lastOvers.length;i < n;i++){
  11735. var ele=_lastOvers[i];
  11736. ele.event(/*laya.events.Event.MOUSE_WHEEL*/"mousewheel",this._event.setTo(/*laya.events.Event.MOUSE_WHEEL*/"mousewheel",ele,this._target));
  11737. }
  11738. }
  11739. // _stage.event(Event.MOUSE_WHEEL,_event.setTo(Event.MOUSE_WHEEL,_stage,_target));
  11740. __proto.onMouseMove=function(ele){
  11741. TouchManager.I.onMouseMove(ele,this._tTouchID);
  11742. }
  11743. __proto.onMouseDown=function(ele){
  11744. if (Input.isInputting && Laya.stage.focus && Laya.stage.focus["focus"] && !Laya.stage.focus.contains(this._target)){
  11745. var pre_input=Laya.stage.focus['_tf'] || Laya.stage.focus;
  11746. var new_input=ele['_tf'] || ele;
  11747. if ((new_input instanceof laya.display.Input )&& new_input.multiline==pre_input.multiline)
  11748. pre_input['_focusOut']();
  11749. else
  11750. pre_input.focus=false;
  11751. }
  11752. TouchManager.I.onMouseDown(ele,this._tTouchID,this._isLeftMouse);
  11753. }
  11754. __proto.onMouseUp=function(ele){
  11755. TouchManager.I.onMouseUp(ele,this._tTouchID,this._isLeftMouse);
  11756. }
  11757. __proto.check=function(sp,mouseX,mouseY,callBack){
  11758. this._point.setTo(mouseX,mouseY);
  11759. sp.fromParentPoint(this._point);
  11760. mouseX=this._point.x;
  11761. mouseY=this._point.y;
  11762. var scrollRect=sp._style.scrollRect;
  11763. if (scrollRect){
  11764. this._rect.setTo(scrollRect.x,scrollRect.y,scrollRect.width,scrollRect.height);
  11765. if (!this._rect.contains(mouseX,mouseY))return false;
  11766. }
  11767. if (!this.disableMouseEvent){
  11768. if (sp.hitTestPrior && !sp.mouseThrough && !this.hitTest(sp,mouseX,mouseY)){
  11769. return false;
  11770. }
  11771. for (var i=sp._children.length-1;i >-1;i--){
  11772. var child=sp._children[i];
  11773. if (!child.destroyed && child._mouseState > 1 && child._visible){
  11774. if (this.check(child,mouseX,mouseY,callBack))return true;
  11775. }
  11776. }
  11777. for (i=sp._extUIChild.length-1;i >=0;i--){
  11778. var c=sp._extUIChild[i];
  11779. if (!c.destroyed && c._mouseState > 1 && c._visible){
  11780. if (this.check(c,mouseX,mouseY,callBack))return true;
  11781. }
  11782. }
  11783. };
  11784. var isHit=(sp.hitTestPrior && !sp.mouseThrough && !this.disableMouseEvent)? true :this.hitTest(sp,mouseX,mouseY);
  11785. if (isHit){
  11786. this._target=sp;
  11787. callBack.call(this,sp);
  11788. if (this._target==this._hitCaputreSp){
  11789. this._hitCaputreSp=true;
  11790. }
  11791. }else if (callBack===this.onMouseUp && sp===this._stage){
  11792. this._target=this._stage;
  11793. callBack.call(this,this._target);
  11794. }
  11795. return isHit;
  11796. }
  11797. __proto.hitTest=function(sp,mouseX,mouseY){
  11798. var isHit=false;
  11799. if (sp.scrollRect){
  11800. mouseX-=sp._style.scrollRect.x;
  11801. mouseY-=sp._style.scrollRect.y;
  11802. };
  11803. var hitArea=sp._style.hitArea;
  11804. if (hitArea && hitArea._hit){
  11805. return hitArea.contains(mouseX,mouseY);
  11806. }
  11807. if (sp.width > 0 && sp.height > 0 || sp.mouseThrough || hitArea){
  11808. if (!sp.mouseThrough){
  11809. isHit=(hitArea ? hitArea :this._rect.setTo(0,0,sp.width,sp.height)).contains(mouseX,mouseY);
  11810. }else {
  11811. isHit=sp.getGraphicBounds().contains(mouseX,mouseY);
  11812. }
  11813. }
  11814. return isHit;
  11815. }
  11816. __proto._checkAllBaseUI=function(mousex,mousey,callback){
  11817. var ret=this.handleExclusiveCapture(this.mouseX,this.mouseY,callback);
  11818. if (ret)return true;
  11819. ret=this.check(this._stage,this.mouseX,this.mouseY,callback);
  11820. return this.handleCapture(this.mouseX,this.mouseY,callback)||ret;
  11821. }
  11822. /**
  11823. *处理3d界面。
  11824. *@param mousex
  11825. *@param mousey
  11826. *@param callback
  11827. *@return
  11828. */
  11829. __proto.check3DUI=function(mousex,mousey,callback){
  11830. var uis=this._stage._3dUI;
  11831. var i=0;
  11832. var ret=false;
  11833. for (;i < uis.length;i++){
  11834. var curui=uis[i];
  11835. this._stage._curUIBase=curui;
  11836. if(!curui.destroyed && curui._mouseState > 1 && curui._visible){
  11837. ret=ret || this.check(curui,this.mouseX,this.mouseY,callback);
  11838. }
  11839. }
  11840. this._stage._curUIBase=this._stage;
  11841. return ret;
  11842. }
  11843. __proto.handleExclusiveCapture=function(mousex,mousey,callback){
  11844. if (this._captureExlusiveMode && this._captureSp && this._captureChain.length > 0){
  11845. var cursp;
  11846. this._point.setTo(mousex,mousey);
  11847. for (var i=0;i < this._captureChain.length;i++){
  11848. cursp=this._captureChain[i];
  11849. cursp.fromParentPoint(this._point);
  11850. }
  11851. this._target=cursp;
  11852. callback.call(this,cursp);
  11853. return true;
  11854. }
  11855. return false;
  11856. }
  11857. __proto.handleCapture=function(mousex,mousey,callback){
  11858. if (!this._hitCaputreSp && this._captureSp && this._captureChain.length > 0){
  11859. var cursp;
  11860. this._point.setTo(mousex,mousey);
  11861. for (var i=0;i < this._captureChain.length;i++){
  11862. cursp=this._captureChain[i];
  11863. cursp.fromParentPoint(this._point);
  11864. }
  11865. this._target=cursp;
  11866. callback.call(this,cursp);
  11867. return true;
  11868. }
  11869. return false;
  11870. }
  11871. /**
  11872. *执行事件处理。
  11873. */
  11874. __proto.runEvent=function(evt){
  11875. var _this=this;
  11876. var i=0,n=0,touch;
  11877. if (evt.type!=='mousemove')this._prePoint.x=this._prePoint.y=-1000000;
  11878. switch (evt.type){
  11879. case 'mousedown':
  11880. this._touchIDs[0]=this._id++;
  11881. if (!MouseManager._isTouchRespond){
  11882. this._isLeftMouse=evt.button===0;
  11883. this.initEvent(evt);
  11884. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseDown);
  11885. }else
  11886. MouseManager._isTouchRespond=false;
  11887. break ;
  11888. case 'mouseup':
  11889. this._isLeftMouse=evt.button===0;
  11890. this.initEvent(evt);
  11891. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseUp);
  11892. break ;
  11893. case 'mousemove':
  11894. if ((Math.abs(this._prePoint.x-evt.clientX)+Math.abs(this._prePoint.y-evt.clientY))>=this.mouseMoveAccuracy){
  11895. this._prePoint.x=evt.clientX;
  11896. this._prePoint.y=evt.clientY;
  11897. this.initEvent(evt);
  11898. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseMove);
  11899. }
  11900. break ;
  11901. case "touchstart":
  11902. MouseManager._isTouchRespond=true;
  11903. this._isLeftMouse=true;
  11904. var touches=evt.changedTouches;
  11905. for (i=0,n=touches.length;i < n;i++){
  11906. touch=touches[i];
  11907. if (MouseManager.multiTouchEnabled || isNaN(this._curTouchID)){
  11908. this._curTouchID=touch.identifier;
  11909. if (this._id % 200===0)this._touchIDs={};
  11910. this._touchIDs[touch.identifier]=this._id++;
  11911. this.initEvent(touch,evt);
  11912. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseDown);
  11913. }
  11914. }
  11915. break ;
  11916. case "touchend":
  11917. case "touchcancel":
  11918. MouseManager._isTouchRespond=true;
  11919. this._isLeftMouse=true;
  11920. var touchends=evt.changedTouches;
  11921. for (i=0,n=touchends.length;i < n;i++){
  11922. touch=touchends[i];
  11923. if (MouseManager.multiTouchEnabled || touch.identifier==this._curTouchID){
  11924. this._curTouchID=NaN;
  11925. this.initEvent(touch,evt);
  11926. var isChecked=false;
  11927. isChecked=this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseUp);
  11928. if (!isChecked){
  11929. this.onMouseUp(null);
  11930. }
  11931. }
  11932. }
  11933. break ;
  11934. case "touchmove":;
  11935. var touchemoves=evt.changedTouches;
  11936. for (i=0,n=touchemoves.length;i < n;i++){
  11937. touch=touchemoves[i];
  11938. if (MouseManager.multiTouchEnabled || touch.identifier==this._curTouchID){
  11939. this.initEvent(touch,evt);
  11940. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseMove);
  11941. }
  11942. }
  11943. break ;
  11944. case "wheel":
  11945. case "mousewheel":
  11946. case "DOMMouseScroll":
  11947. this.checkMouseWheel(evt);
  11948. break ;
  11949. case "mouseout":
  11950. TouchManager.I.stageMouseOut();
  11951. break ;
  11952. case "mouseover":
  11953. this._stage.event(/*laya.events.Event.MOUSE_OVER*/"mouseover",this._event.setTo(/*laya.events.Event.MOUSE_OVER*/"mouseover",this._stage,this._stage));
  11954. break ;
  11955. }
  11956. }
  11957. /**
  11958. *
  11959. *@param sp
  11960. *@param exlusive 是否是独占模式
  11961. */
  11962. __proto.setCapture=function(sp,exclusive){
  11963. (exclusive===void 0)&& (exclusive=false);
  11964. this._captureSp=sp;
  11965. this._captureExlusiveMode=exclusive;
  11966. this._captureChain.length=0;
  11967. this._captureChain.push(sp);
  11968. var cursp=sp;
  11969. while (true){
  11970. if (cursp==Laya.stage)break ;
  11971. if (cursp==Laya.stage._curUIBase)break ;
  11972. cursp=cursp.parent;
  11973. if (!cursp)break ;
  11974. this._captureChain.splice(0,0,cursp);
  11975. }
  11976. }
  11977. __proto.releaseCapture=function(){
  11978. console.log('release capture');
  11979. this._captureSp=null;
  11980. }
  11981. MouseManager.enabled=true;
  11982. MouseManager.multiTouchEnabled=true;
  11983. MouseManager._isTouchRespond=false;
  11984. MouseManager._isFirstTouch=true;
  11985. __static(MouseManager,
  11986. ['instance',function(){return this.instance=new MouseManager();}
  11987. ]);
  11988. return MouseManager;
  11989. })()
  11990. /**
  11991. *绘制描边文字
  11992. */
  11993. //class laya.display.cmd.StrokeTextCmd
  11994. var StrokeTextCmd=(function(){
  11995. function StrokeTextCmd(){
  11996. /**
  11997. *在画布上输出的文本。
  11998. */
  11999. //this.text=null;
  12000. /**
  12001. *开始绘制文本的 x 坐标位置(相对于画布)。
  12002. */
  12003. //this.x=NaN;
  12004. /**
  12005. *开始绘制文本的 y 坐标位置(相对于画布)。
  12006. */
  12007. //this.y=NaN;
  12008. /**
  12009. *定义字体和字号,比如"20px Arial"。
  12010. */
  12011. //this.font=null;
  12012. /**
  12013. *定义文本颜色,比如"#ff0000"。
  12014. */
  12015. //this.color=null;
  12016. /**
  12017. *线条宽度。
  12018. */
  12019. //this.lineWidth=NaN;
  12020. /**
  12021. *文本对齐方式,可选值:"left","center","right"。
  12022. */
  12023. //this.textAlign=null;
  12024. }
  12025. __class(StrokeTextCmd,'laya.display.cmd.StrokeTextCmd');
  12026. var __proto=StrokeTextCmd.prototype;
  12027. /**
  12028. *回收到对象池
  12029. */
  12030. __proto.recover=function(){
  12031. Pool.recover("StrokeTextCmd",this);
  12032. }
  12033. /**@private */
  12034. __proto.run=function(context,gx,gy){
  12035. context.strokeWord(this.text,this.x+gx,this.y+gy,this.font,this.color,this.lineWidth,this.textAlign);
  12036. }
  12037. /**@private */
  12038. __getset(0,__proto,'cmdID',function(){
  12039. return "StrokeText";
  12040. });
  12041. StrokeTextCmd.create=function(text,x,y,font,color,lineWidth,textAlign){
  12042. var cmd=Pool.getItemByClass("StrokeTextCmd",StrokeTextCmd);
  12043. cmd.text=text;
  12044. cmd.x=x;
  12045. cmd.y=y;
  12046. cmd.font=font;
  12047. cmd.color=color;
  12048. cmd.lineWidth=lineWidth;
  12049. cmd.textAlign=textAlign;
  12050. return cmd;
  12051. }
  12052. StrokeTextCmd.ID="StrokeText";
  12053. return StrokeTextCmd;
  12054. })()
  12055. /**
  12056. *@private
  12057. *CommandEncoder
  12058. */
  12059. //class laya.layagl.CommandEncoder
  12060. var CommandEncoder=(function(){
  12061. function CommandEncoder(layagl,reserveSize,adjustSize,isSyncToRenderThread){
  12062. this._idata=[];
  12063. }
  12064. __class(CommandEncoder,'laya.layagl.CommandEncoder');
  12065. var __proto=CommandEncoder.prototype;
  12066. //TODO:coverage
  12067. __proto.getArrayData=function(){
  12068. return this._idata;
  12069. }
  12070. //TODO:coverage
  12071. __proto.getPtrID=function(){
  12072. return 0;
  12073. }
  12074. __proto.beginEncoding=function(){}
  12075. __proto.endEncoding=function(){}
  12076. //TODO:coverage
  12077. __proto.clearEncoding=function(){
  12078. this._idata.length=0;
  12079. }
  12080. //TODO:coverage
  12081. __proto.getCount=function(){
  12082. return this._idata.length;
  12083. }
  12084. //TODO:coverage
  12085. __proto.add_ShaderValue=function(o){
  12086. this._idata.push(o);
  12087. }
  12088. //TODO:coverage
  12089. __proto.addShaderUniform=function(one){
  12090. this.add_ShaderValue(one);
  12091. }
  12092. return CommandEncoder;
  12093. })()
  12094. /**
  12095. *鼠标点击区域,可以设置绘制一系列矢量图作为点击区域和非点击区域(目前只支持圆形,矩形,多边形)
  12096. *
  12097. */
  12098. //class laya.utils.HitArea
  12099. var HitArea=(function(){
  12100. function HitArea(){
  12101. /**@private */
  12102. this._hit=null;
  12103. /**@private */
  12104. this._unHit=null;
  12105. }
  12106. __class(HitArea,'laya.utils.HitArea');
  12107. var __proto=HitArea.prototype;
  12108. /**
  12109. *检测对象是否包含指定的点。
  12110. *@param x 点的 X 轴坐标值(水平位置)。
  12111. *@param y 点的 Y 轴坐标值(垂直位置)。
  12112. *@return 如果包含指定的点,则值为 true;否则为 false。
  12113. */
  12114. __proto.contains=function(x,y){
  12115. if (!HitArea._isHitGraphic(x,y,this.hit))return false;
  12116. return !HitArea._isHitGraphic(x,y,this.unHit);
  12117. }
  12118. /**
  12119. *可点击区域,可以设置绘制一系列矢量图作为点击区域(目前只支持圆形,矩形,多边形)
  12120. */
  12121. __getset(0,__proto,'hit',function(){
  12122. if (!this._hit)this._hit=new Graphics();
  12123. return this._hit;
  12124. },function(value){
  12125. this._hit=value;
  12126. });
  12127. /**
  12128. *不可点击区域,可以设置绘制一系列矢量图作为非点击区域(目前只支持圆形,矩形,多边形)
  12129. */
  12130. __getset(0,__proto,'unHit',function(){
  12131. if (!this._unHit)this._unHit=new Graphics();
  12132. return this._unHit;
  12133. },function(value){
  12134. this._unHit=value;
  12135. });
  12136. HitArea._isHitGraphic=function(x,y,graphic){
  12137. if (!graphic)return false;
  12138. var cmds=graphic.cmds;
  12139. if (!cmds && graphic._one){
  12140. cmds=HitArea._cmds;
  12141. cmds.length=1;
  12142. cmds[0]=graphic._one;
  12143. }
  12144. if (!cmds)return false;
  12145. var i=0,len=0;
  12146. len=cmds.length;
  12147. var cmd;
  12148. for (i=0;i < len;i++){
  12149. cmd=cmds[i];
  12150. if (!cmd)continue ;
  12151. switch (cmd.cmdID){
  12152. case "Translate":
  12153. x-=cmd.tx;
  12154. y-=cmd.ty;
  12155. }
  12156. if (HitArea._isHitCmd(x,y,cmd))return true;
  12157. }
  12158. return false;
  12159. }
  12160. HitArea._isHitCmd=function(x,y,cmd){
  12161. if (!cmd)return false;
  12162. var rst=false;
  12163. switch (cmd.cmdID){
  12164. case "DrawRect":
  12165. HitArea._rect.setTo(cmd.x,cmd.y,cmd.width,cmd.height);
  12166. rst=HitArea._rect.contains(x,y);
  12167. break ;
  12168. case "DrawCircle":;
  12169. var d=NaN;
  12170. x-=cmd.x;
  12171. y-=cmd.y;
  12172. d=x *x+y *y;
  12173. rst=d < cmd.radius *cmd.radius;
  12174. break ;
  12175. case "DrawPoly":
  12176. x-=cmd.x;
  12177. y-=cmd.y;
  12178. rst=HitArea._ptInPolygon(x,y,cmd.points);
  12179. break ;
  12180. }
  12181. return rst;
  12182. }
  12183. HitArea._ptInPolygon=function(x,y,areaPoints){
  12184. var p=HitArea._ptPoint;
  12185. p.setTo(x,y);
  12186. var nCross=0;
  12187. var p1x=NaN,p1y=NaN,p2x=NaN,p2y=NaN;
  12188. var len=0;
  12189. len=areaPoints.length;
  12190. for (var i=0;i < len;i+=2){
  12191. p1x=areaPoints[i];
  12192. p1y=areaPoints[i+1];
  12193. p2x=areaPoints[(i+2)% len];
  12194. p2y=areaPoints[(i+3)% len];
  12195. if (p1y==p2y)continue ;
  12196. if (p.y < Math.min(p1y,p2y))continue ;
  12197. if (p.y >=Math.max(p1y,p2y))continue ;
  12198. var tx=(p.y-p1y)*(p2x-p1x)/ (p2y-p1y)+p1x;
  12199. if (tx > p.x)nCross++;
  12200. }
  12201. return (nCross % 2==1);
  12202. }
  12203. HitArea._cmds=[];
  12204. __static(HitArea,
  12205. ['_rect',function(){return this._rect=new Rectangle();},'_ptPoint',function(){return this._ptPoint=new Point();}
  12206. ]);
  12207. return HitArea;
  12208. })()
  12209. /**
  12210. *@private
  12211. *静态常量集合
  12212. */
  12213. //class laya.Const
  12214. var Const=(function(){
  12215. function Const(){}
  12216. __class(Const,'laya.Const');
  12217. Const.NOT_ACTIVE=0x01;
  12218. Const.ACTIVE_INHIERARCHY=0x02;
  12219. Const.AWAKED=0x04;
  12220. Const.NOT_READY=0x08;
  12221. Const.DISPLAY=0x10;
  12222. Const.HAS_ZORDER=0x20;
  12223. Const.HAS_MOUSE=0x40;
  12224. Const.DISPLAYED_INSTAGE=0x80;
  12225. Const.DRAWCALL_OPTIMIZE=0x100;
  12226. return Const;
  12227. })()
  12228. //class laya.utils.FontInfo
  12229. var FontInfo=(function(){
  12230. function FontInfo(font){
  12231. //this._id=0;
  12232. this._font="14px Arial";
  12233. this._family="Arial";
  12234. this._size=14;
  12235. this._italic=false;
  12236. this._bold=false;
  12237. this._id=FontInfo._gfontID++;
  12238. this.setFont(font || this._font);
  12239. }
  12240. __class(FontInfo,'laya.utils.FontInfo');
  12241. var __proto=FontInfo.prototype;
  12242. __proto.setFont=function(value){
  12243. this._font=value;
  12244. var _words=value.split(' ');
  12245. var l=_words.length;
  12246. if (l < 2){
  12247. if (l==1){
  12248. if (_words[0].indexOf('px')> 0){
  12249. this._size=parseInt(_words[0]);
  12250. }
  12251. }
  12252. return;
  12253. };
  12254. var szpos=-1;
  12255. for (var i=0;i < l;i++){
  12256. if (_words[i].indexOf('px')> 0 || _words[i].indexOf('pt')> 0){
  12257. szpos=i;
  12258. this._size=parseInt(_words[i]);
  12259. if (this._size <=0){
  12260. console.error('font parse error:'+value);
  12261. this._size=14;
  12262. }
  12263. break ;
  12264. }
  12265. };
  12266. var fpos=szpos+1;
  12267. var familys=_words[fpos];
  12268. fpos++;
  12269. for (;fpos < l;fpos++){
  12270. familys+=' '+_words[fpos];
  12271. }
  12272. this._family=(familys.split(','))[0];
  12273. this._italic=_words.indexOf('italic')>=0;
  12274. this._bold=_words.indexOf('bold')>=0;
  12275. }
  12276. FontInfo.Parse=function(font){
  12277. if (font===FontInfo._lastFont){
  12278. return FontInfo._lastFontInfo;
  12279. };
  12280. var r=FontInfo._cache[font];
  12281. if(!r){
  12282. r=FontInfo._cache[font]=new FontInfo(font);
  12283. }
  12284. FontInfo._lastFont=font;
  12285. FontInfo._lastFontInfo=r;
  12286. return r;
  12287. }
  12288. FontInfo.EMPTY=new FontInfo(null);
  12289. FontInfo._cache={};
  12290. FontInfo._gfontID=0;
  12291. FontInfo._lastFont='';
  12292. FontInfo._lastFontInfo=null;
  12293. return FontInfo;
  12294. })()
  12295. /**
  12296. *位移命令
  12297. */
  12298. //class laya.display.cmd.TranslateCmd
  12299. var TranslateCmd=(function(){
  12300. function TranslateCmd(){
  12301. /**
  12302. *添加到水平坐标(x)上的值。
  12303. */
  12304. //this.tx=NaN;
  12305. /**
  12306. *添加到垂直坐标(y)上的值。
  12307. */
  12308. //this.ty=NaN;
  12309. }
  12310. __class(TranslateCmd,'laya.display.cmd.TranslateCmd');
  12311. var __proto=TranslateCmd.prototype;
  12312. /**
  12313. *回收到对象池
  12314. */
  12315. __proto.recover=function(){
  12316. Pool.recover("TranslateCmd",this);
  12317. }
  12318. /**@private */
  12319. __proto.run=function(context,gx,gy){
  12320. context.translate(this.tx,this.ty);
  12321. }
  12322. /**@private */
  12323. __getset(0,__proto,'cmdID',function(){
  12324. return "Translate";
  12325. });
  12326. TranslateCmd.create=function(tx,ty){
  12327. var cmd=Pool.getItemByClass("TranslateCmd",TranslateCmd);
  12328. cmd.tx=tx;
  12329. cmd.ty=ty;
  12330. return cmd;
  12331. }
  12332. TranslateCmd.ID="Translate";
  12333. return TranslateCmd;
  12334. })()
  12335. //class laya.webgl.canvas.Path
  12336. var Path=(function(){
  12337. var renderPath;
  12338. function Path(){
  12339. //public var _rect:Rectangle;
  12340. this._lastOriX=0;
  12341. //moveto等的原始位置。没有经过内部矩阵变换的
  12342. this._lastOriY=0;
  12343. this.paths=[];
  12344. //所有的路径。{@type renderPath[] }
  12345. this._curPath=null;
  12346. }
  12347. __class(Path,'laya.webgl.canvas.Path');
  12348. var __proto=Path.prototype;
  12349. __proto.beginPath=function(convex){
  12350. this.paths.length=1;
  12351. this._curPath=this.paths[0]=new renderPath();
  12352. this._curPath.convex=convex;
  12353. }
  12354. //_curPath.path=[];
  12355. __proto.closePath=function(){
  12356. this._curPath.loop=true;
  12357. }
  12358. __proto.newPath=function(){
  12359. this._curPath=new renderPath();
  12360. this.paths.push(this._curPath);
  12361. }
  12362. __proto.addPoint=function(pointX,pointY){
  12363. this._curPath.path.push(pointX,pointY);
  12364. }
  12365. //直接添加一个完整的path
  12366. __proto.push=function(points,convex){
  12367. if (!this._curPath){
  12368. this._curPath=new renderPath();
  12369. this.paths.push(this._curPath);
  12370. }else if (this._curPath.path.length > 0){
  12371. this._curPath=new renderPath();
  12372. this.paths.push(this._curPath);
  12373. };
  12374. var rp=this._curPath;
  12375. rp.path=points.slice();
  12376. rp.convex=convex;
  12377. }
  12378. __proto.reset=function(){
  12379. this.paths.length=0;
  12380. }
  12381. Path.__init$=function(){
  12382. //TODO 复用
  12383. //class renderPath
  12384. renderPath=(function(){
  12385. function renderPath(){
  12386. this.path=[];
  12387. //[x,y,x,y,....]的数组
  12388. this.loop=false;
  12389. this.convex=false;
  12390. }
  12391. __class(renderPath,'');
  12392. return renderPath;
  12393. })()
  12394. }
  12395. return Path;
  12396. })()
  12397. /**
  12398. *@private
  12399. */
  12400. //class laya.filters.BlurFilterGLRender
  12401. var BlurFilterGLRender=(function(){
  12402. function BlurFilterGLRender(){}
  12403. __class(BlurFilterGLRender,'laya.filters.BlurFilterGLRender');
  12404. var __proto=BlurFilterGLRender.prototype;
  12405. __proto.render=function(rt,ctx,width,height,filter){
  12406. var shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  12407. this.setShaderInfo(shaderValue,filter,rt.width,rt.height);
  12408. ctx.drawTarget(rt,0,0,width,height,Matrix.EMPTY.identity(),shaderValue);
  12409. }
  12410. __proto.setShaderInfo=function(shader,filter,w,h){
  12411. shader.defines.add(/*laya.filters.Filter.BLUR*/0x10);
  12412. var sv=shader;
  12413. BlurFilterGLRender.blurinfo[0]=w;BlurFilterGLRender.blurinfo[1]=h;
  12414. sv.blurInfo=BlurFilterGLRender.blurinfo;
  12415. var sigma=filter.strength/3.0;
  12416. var sigma2=sigma*sigma;
  12417. filter.strength_sig2_2sig2_gauss1[0]=filter.strength;
  12418. filter.strength_sig2_2sig2_gauss1[1]=sigma2;
  12419. filter.strength_sig2_2sig2_gauss1[2]=2.0*sigma2;
  12420. filter.strength_sig2_2sig2_gauss1[3]=1.0/(2.0*Math.PI*sigma2);
  12421. sv.strength_sig2_2sig2_gauss1=filter.strength_sig2_2sig2_gauss1;
  12422. }
  12423. __static(BlurFilterGLRender,
  12424. ['blurinfo',function(){return this.blurinfo=new Array(2);}
  12425. ]);
  12426. return BlurFilterGLRender;
  12427. })()
  12428. /**
  12429. *@private
  12430. *<code>StringKey</code> 类用于存取字符串对应的数字。
  12431. */
  12432. //class laya.utils.StringKey
  12433. var StringKey=(function(){
  12434. function StringKey(){
  12435. this._strsToID={};
  12436. this._idToStrs=[];
  12437. this._length=0;
  12438. }
  12439. __class(StringKey,'laya.utils.StringKey');
  12440. var __proto=StringKey.prototype;
  12441. //TODO:coverage
  12442. __proto.add=function(str){
  12443. var index=this._strsToID[str];
  12444. if (index !=null)return index;
  12445. this._idToStrs[this._length]=str;
  12446. return this._strsToID[str]=this._length++;
  12447. }
  12448. //TODO:coverage
  12449. __proto.getID=function(str){
  12450. var index=this._strsToID[str];
  12451. return index==null ?-1 :index;
  12452. }
  12453. //TODO:coverage
  12454. __proto.getName=function(id){
  12455. var str=this._idToStrs[id];
  12456. return str==null ? undefined :str;
  12457. }
  12458. return StringKey;
  12459. })()
  12460. /**
  12461. *Javascript Arabic Reshaper by Louy Alakkad
  12462. *https://github.com/louy/Javascript-Arabic-Reshaper
  12463. *Based on (http://git.io/vsnAd)
  12464. */
  12465. //class laya.webgl.text.ArabicReshaper
  12466. var ArabicReshaper=(function(){
  12467. function ArabicReshaper(){}
  12468. __class(ArabicReshaper,'laya.webgl.text.ArabicReshaper');
  12469. var __proto=ArabicReshaper.prototype;
  12470. //TODO:coverage
  12471. __proto.characterMapContains=function(c){
  12472. for (var i=0;i < ArabicReshaper.charsMap.length;++i){
  12473. if (ArabicReshaper.charsMap[ i][0]===c){
  12474. return true;
  12475. }
  12476. }
  12477. return false;
  12478. }
  12479. //TODO:coverage
  12480. __proto.getCharRep=function(c){
  12481. for (var i=0;i < ArabicReshaper.charsMap.length;++i){
  12482. if (ArabicReshaper.charsMap[ i][0]===c){
  12483. return ArabicReshaper.charsMap[i];
  12484. }
  12485. }
  12486. return false;
  12487. }
  12488. //TODO:coverage
  12489. __proto.getCombCharRep=function(c1,c2){
  12490. for (var i=0;i < ArabicReshaper.combCharsMap.length;++i){
  12491. if (ArabicReshaper.combCharsMap[i][0][0]===c1 && ArabicReshaper.combCharsMap[i][0][1]===c2){
  12492. return ArabicReshaper.combCharsMap[i];
  12493. }
  12494. }
  12495. return false;
  12496. }
  12497. //TODO:coverage
  12498. __proto.isTransparent=function(c){
  12499. for (var i=0;i < ArabicReshaper.transChars.length;++i){
  12500. if (ArabicReshaper.transChars[i]===c){
  12501. return true;
  12502. }
  12503. }
  12504. return false;
  12505. }
  12506. //TODO:coverage
  12507. __proto.getOriginalCharsFromCode=function(code){
  12508. var j=0;
  12509. for (j=0;j < ArabicReshaper.charsMap.length;++j){
  12510. if (ArabicReshaper.charsMap[j].indexOf(code)>-1){
  12511. return String.fromCharCode(ArabicReshaper.charsMap[j][0]);
  12512. }
  12513. }
  12514. for (j=0;j < ArabicReshaper.combCharsMap.length;++j){
  12515. if (ArabicReshaper.combCharsMap[j].indexOf(code)>-1){
  12516. return String.fromCharCode(ArabicReshaper.combCharsMap[j][0][0])+
  12517. String.fromCharCode(ArabicReshaper.combCharsMap[j][0][1]);
  12518. }
  12519. }
  12520. return String.fromCharCode(code);
  12521. }
  12522. //TODO:coverage
  12523. __proto.convertArabic=function(normal){
  12524. var crep,
  12525. combcrep,
  12526. shaped='';
  12527. for (var i=0;i < normal.length;++i){
  12528. var current=normal.charCodeAt(i);
  12529. if (this.characterMapContains(current)){
  12530. var prev=null,
  12531. next=null,
  12532. prevID=i-1,
  12533. nextID=i+1;
  12534. for (;prevID >=0;--prevID){
  12535. if (!this.isTransparent(normal.charCodeAt(prevID))){
  12536. break ;
  12537. }
  12538. }
  12539. prev=(prevID >=0)? normal.charCodeAt(prevID):null;
  12540. crep=prev ? this.getCharRep(prev):false;
  12541. if (!crep || crep[2]==null && crep[3]==null){
  12542. prev=null;
  12543. }
  12544. for (;nextID < normal.length;++nextID){
  12545. if (!this.isTransparent(normal.charCodeAt(nextID))){
  12546. break ;
  12547. }
  12548. }
  12549. next=(nextID < normal.length)? normal.charCodeAt(nextID):null;
  12550. crep=next ? this.getCharRep(next):false;
  12551. if (!crep || crep[3]==null && crep[4]==null){
  12552. next=null;
  12553. }
  12554. if (current===0x0644 && next !=null &&
  12555. (next===0x0622 || next===0x0623 || next===0x0625 || next===0x0627)){
  12556. combcrep=this.getCombCharRep(current,next);
  12557. if (prev !=null){
  12558. shaped+=String.fromCharCode(combcrep[4]);
  12559. }else {
  12560. shaped+=String.fromCharCode(combcrep[1]);
  12561. }
  12562. ++i;
  12563. continue ;
  12564. }
  12565. crep=this.getCharRep(current);
  12566. if (prev !=null && next !=null && crep[3] !=null){
  12567. shaped+=String.fromCharCode(crep[3]);
  12568. continue ;
  12569. }else
  12570. if (prev !=null && crep[4] !=null){
  12571. shaped+=String.fromCharCode(crep[4]);
  12572. continue ;
  12573. }else
  12574. if (next !=null && crep[2] !=null){
  12575. shaped+=String.fromCharCode(crep[2]);
  12576. continue ;
  12577. }else {
  12578. shaped+=String.fromCharCode(crep[1]);
  12579. }
  12580. }else {
  12581. shaped+=String.fromCharCode(current);
  12582. }
  12583. }
  12584. return shaped;
  12585. }
  12586. //TODO:coverage
  12587. __proto.convertArabicBack=function(apfb){
  12588. var toReturn='',
  12589. selectedChar=0;
  12590. var i=0;
  12591. for (i=0;i < apfb.length;++i){
  12592. selectedChar=apfb.charCodeAt(i);
  12593. toReturn+=this.getOriginalCharsFromCode(selectedChar);
  12594. }
  12595. return toReturn;
  12596. }
  12597. __static(ArabicReshaper,
  12598. ['charsMap',function(){return this.charsMap=[
  12599. [0x0621,0xFE80,null,null,null],
  12600. [0x0622,0xFE81,null,null,0xFE82],
  12601. [0x0623,0xFE83,null,null,0xFE84],
  12602. [0x0624,0xFE85,null,null,0xFE86],
  12603. [0x0625,0xFE87,null,null,0xFE88],
  12604. [0x0626,0xFE89,0xFE8B,0xFE8C,0xFE8A],
  12605. [0x0627,0xFE8D,null,null,0xFE8E],
  12606. [0x0628,0xFE8F,0xFE91,0xFE92,0xFE90],
  12607. [0x0629,0xFE93,null,null,0xFE94],
  12608. [0x062A,0xFE95,0xFE97,0xFE98,0xFE96],
  12609. [0x062B,0xFE99,0xFE9B,0xFE9C,0xFE9A],
  12610. [0x062C,0xFE9D,0xFE9F,0xFEA0,0xFE9E],
  12611. [0x062D,0xFEA1,0xFEA3,0xFEA4,0xFEA2],
  12612. [0x062E,0xFEA5,0xFEA7,0xFEA8,0xFEA6],
  12613. [0x062F,0xFEA9,null,null,0xFEAA],
  12614. [0x0630,0xFEAB,null,null,0xFEAC],
  12615. [0x0631,0xFEAD,null,null,0xFEAE],
  12616. [0x0632,0xFEAF,null,null,0xFEB0],
  12617. [0x0633,0xFEB1,0xFEB3,0xFEB4,0xFEB2],
  12618. [0x0634,0xFEB5,0xFEB7,0xFEB8,0xFEB6],
  12619. [0x0635,0xFEB9,0xFEBB,0xFEBC,0xFEBA],
  12620. [0x0636,0xFEBD,0xFEBF,0xFEC0,0xFEBE],
  12621. [0x0637,0xFEC1,0xFEC3,0xFEC4,0xFEC2],
  12622. [0x0638,0xFEC5,0xFEC7,0xFEC8,0xFEC6],
  12623. [0x0639,0xFEC9,0xFECB,0xFECC,0xFECA],
  12624. [0x063A,0xFECD,0xFECF,0xFED0,0xFECE],
  12625. [0x0640,0x0640,0x0640,0x0640,0x0640],
  12626. [0x0641,0xFED1,0xFED3,0xFED4,0xFED2],
  12627. [0x0642,0xFED5,0xFED7,0xFED8,0xFED6],
  12628. [0x0643,0xFED9,0xFEDB,0xFEDC,0xFEDA],
  12629. [0x0644,0xFEDD,0xFEDF,0xFEE0,0xFEDE],
  12630. [0x0645,0xFEE1,0xFEE3,0xFEE4,0xFEE2],
  12631. [0x0646,0xFEE5,0xFEE7,0xFEE8,0xFEE6],
  12632. [0x0647,0xFEE9,0xFEEB,0xFEEC,0xFEEA],
  12633. [0x0648,0xFEED,null,null,0xFEEE],
  12634. [0x0649,0xFEEF,null,null,0xFEF0],
  12635. [0x064A,0xFEF1,0xFEF3,0xFEF4,0xFEF2],
  12636. [0x067E,0xFB56,0xFB58,0xFB59,0xFB57],
  12637. [0x06CC,0xFBFC,0xFBFE,0xFBFF,0xFBFD],
  12638. [0x0686,0xFB7A,0xFB7C,0xFB7D,0xFB7B],
  12639. [0x06A9,0xFB8E,0xFB90,0xFB91,0xFB8F],
  12640. [0x06AF,0xFB92,0xFB94,0xFB95,0xFB93],
  12641. [0x0698,0xFB8A,null,null,0xFB8B],];},'combCharsMap',function(){return this.combCharsMap=[
  12642. [[0x0644,0x0622],0xFEF5,null,null,0xFEF6],
  12643. [[0x0644,0x0623],0xFEF7,null,null,0xFEF8],
  12644. [[0x0644,0x0625],0xFEF9,null,null,0xFEFA],
  12645. [[0x0644,0x0627],0xFEFB,null,null,0xFEFC],];},'transChars',function(){return this.transChars=[
  12646. 0x0610,
  12647. 0x0612,
  12648. 0x0613,
  12649. 0x0614,
  12650. 0x0615,
  12651. 0x064B,
  12652. 0x064C,
  12653. 0x064D,
  12654. 0x064E,
  12655. 0x064F,
  12656. 0x0650,
  12657. 0x0651,
  12658. 0x0652,
  12659. 0x0653,
  12660. 0x0654,
  12661. 0x0655,
  12662. 0x0656,
  12663. 0x0657,
  12664. 0x0658,
  12665. 0x0670,
  12666. 0x06D6,
  12667. 0x06D7,
  12668. 0x06D8,
  12669. 0x06D9,
  12670. 0x06DA,
  12671. 0x06DB,
  12672. 0x06DC,
  12673. 0x06DF,
  12674. 0x06E0,
  12675. 0x06E1,
  12676. 0x06E2,
  12677. 0x06E3,
  12678. 0x06E4,
  12679. 0x06E7,
  12680. 0x06E8,
  12681. 0x06EA,
  12682. 0x06EB,
  12683. 0x06EC,
  12684. 0x06ED,];}
  12685. ]);
  12686. return ArabicReshaper;
  12687. })()
  12688. //class laya.webgl.shapes.BasePoly
  12689. var BasePoly=(function(){
  12690. function BasePoly(){}
  12691. __class(BasePoly,'laya.webgl.shapes.BasePoly');
  12692. BasePoly.createLine2=function(p,indices,lineWidth,indexBase,outVertex,loop){
  12693. if (p.length < 4)return null;
  12694. var points=BasePoly.tempData.length>(p.length+2)?BasePoly.tempData:new Array(p.length+2);
  12695. points[0]=p[0];points[1]=p[1];
  12696. var newlen=2;
  12697. var i=0;
  12698. var length=p.length;
  12699. for (i=2;i < length;i+=2){
  12700. if (Math.abs(p[i]-p[i-2])+Math.abs(p[i+1]-p[i-1])> 0.01){
  12701. points[newlen++]=p[i];points[newlen++]=p[i+1];
  12702. }
  12703. }
  12704. if (loop && Math.abs(p[0]-points[newlen-2])+Math.abs(p[1]-points[newlen-1])> 0.01){
  12705. points[newlen++]=p[0];points[newlen++]=p[1];
  12706. };
  12707. var result=outVertex;
  12708. length=newlen / 2;
  12709. var w=lineWidth / 2;
  12710. var px,py,p1x,p1y,p2x,p2y,p3x,p3y;
  12711. var perpx,perpy,perp2x,perp2y,perp3x,perp3y;
  12712. var a1,b1,c1,a2,b2,c2;
  12713. var denom,pdist,dist;
  12714. p1x=points[0];
  12715. p1y=points[1];
  12716. p2x=points[2];
  12717. p2y=points[3];
  12718. perpx=-(p1y-p2y);
  12719. perpy=p1x-p2x;
  12720. dist=Math.sqrt(perpx *perpx+perpy *perpy);
  12721. perpx=perpx / dist *w;
  12722. perpy=perpy / dist *w;
  12723. var tpx=perpx,tpy=perpy;
  12724. result.push(p1x-perpx ,p1y-perpy ,p1x+perpx ,p1y+perpy);
  12725. for (i=1;i < length-1;i++){
  12726. p1x=points[(i-1)*2];
  12727. p1y=points[(i-1)*2+1];
  12728. p2x=points[(i)*2];
  12729. p2y=points[(i)*2+1];
  12730. p3x=points[(i+1)*2];
  12731. p3y=points[(i+1)*2+1];
  12732. perpx=-(p1y-p2y);
  12733. perpy=p1x-p2x;
  12734. dist=Math.sqrt(perpx *perpx+perpy *perpy);
  12735. perpx=perpx / dist *w;
  12736. perpy=perpy / dist *w;
  12737. perp2x=-(p2y-p3y);
  12738. perp2y=p2x-p3x;
  12739. dist=Math.sqrt(perp2x *perp2x+perp2y *perp2y);
  12740. perp2x=perp2x / dist *w;
  12741. perp2y=perp2y / dist *w;
  12742. a1=(-perpy+p1y)-(-perpy+p2y);
  12743. b1=(-perpx+p2x)-(-perpx+p1x);
  12744. c1=(-perpx+p1x)*(-perpy+p2y)-(-perpx+p2x)*(-perpy+p1y);
  12745. a2=(-perp2y+p3y)-(-perp2y+p2y);
  12746. b2=(-perp2x+p2x)-(-perp2x+p3x);
  12747. c2=(-perp2x+p3x)*(-perp2y+p2y)-(-perp2x+p2x)*(-perp2y+p3y);
  12748. denom=a1 *b2-a2 *b1;
  12749. if (Math.abs(denom)< 0.1){
  12750. denom+=10.1;
  12751. result.push(p2x-perpx ,p2y-perpy ,p2x+perpx ,p2y+perpy);
  12752. continue ;
  12753. }
  12754. px=(b1 *c2-b2 *c1)/ denom;
  12755. py=(a2 *c1-a1 *c2)/ denom;
  12756. pdist=(px-p2x)*(px-p2x)+(py-p2y)+(py-p2y);
  12757. result.push(px,py ,p2x-(px-p2x),p2y-(py-p2y));
  12758. }
  12759. p1x=points[newlen-4];
  12760. p1y=points[newlen-3];
  12761. p2x=points[newlen-2];
  12762. p2y=points[newlen-1];
  12763. perpx=-(p1y-p2y);
  12764. perpy=p1x-p2x;
  12765. dist=Math.sqrt(perpx *perpx+perpy *perpy);
  12766. perpx=perpx / dist *w;
  12767. perpy=perpy / dist *w;
  12768. result.push(p2x-perpx ,p2y-perpy ,p2x+perpx ,p2y+perpy);
  12769. for (i=1;i < length;i++){
  12770. indices.push(indexBase+(i-1)*2,indexBase+(i-1)*2+1,indexBase+i *2+1,indexBase+i *2+1,indexBase+i *2,indexBase+(i-1)*2);
  12771. }
  12772. return result;
  12773. }
  12774. BasePoly.createLineTriangle=function(path,color,width,loop,outvb,vbstride,outib){
  12775. var points=path.slice();
  12776. var ptlen=points.length;
  12777. var p1x=points[0],p1y=points[1];
  12778. var p2x=points[2],p2y=points[2];
  12779. var len=0;
  12780. var rp=0;
  12781. var dx=0,dy=0;
  12782. var pointnum=ptlen / 2;
  12783. if (pointnum <=1)return;
  12784. if (pointnum==2){
  12785. return;
  12786. };
  12787. var tmpData=new Array(pointnum *4);
  12788. var realPtNum=0;
  12789. var ci=0;
  12790. for (var i=0;i < pointnum-1;i++){
  12791. p1x=points[ci++],p1y=points[ci++];
  12792. p2x=points[ci++],p2y=points[ci++];
  12793. dx=p2x-p1x,dy=p2y-p1y;
  12794. if(dx!=0 && dy!=0){
  12795. len=Math.sqrt(dx *dx+dy *dy);
  12796. if (len > 1e-3){
  12797. rp=realPtNum *4;
  12798. tmpData[rp]=p1x;
  12799. tmpData[rp+1]=p1y;
  12800. tmpData[rp+2]=dx / len;
  12801. tmpData[rp+3]=dy / len;
  12802. realPtNum++;
  12803. }
  12804. }
  12805. }
  12806. if (loop){
  12807. p1x=points[ptlen-2],p1y=points[ptlen-1];
  12808. p2x=points[0],p2y=points[1];
  12809. dx=p2x-p1x,dy=p2y-p1y;
  12810. if(dx!=0 && dy!=0){
  12811. len=Math.sqrt(dx *dx+dy *dy);
  12812. if (len > 1e-3){
  12813. rp=realPtNum *4;
  12814. tmpData[rp]=p1x;
  12815. tmpData[rp+1]=p1y;
  12816. tmpData[rp+2]=dx / len;
  12817. tmpData[rp+3]=dy / len;
  12818. realPtNum++;
  12819. }
  12820. }
  12821. }else {
  12822. rp=realPtNum *4;
  12823. tmpData[rp]=p1x;
  12824. tmpData[rp+1]=p1y;
  12825. tmpData[rp+2]=dx / len;
  12826. tmpData[rp+3]=dy / len;
  12827. realPtNum++;
  12828. }
  12829. ci=0;
  12830. for (i=0;i < pointnum;i++){
  12831. p1x=points[ci],p1y=points[ci+1];
  12832. p2x=points[ci+2],p2y=points[ci+3];
  12833. var p3x=points[ci+4],p3y=points[ci+5];
  12834. }
  12835. if (loop){}
  12836. }
  12837. __static(BasePoly,
  12838. ['tempData',function(){return this.tempData=new Array(256);}
  12839. ]);
  12840. return BasePoly;
  12841. })()
  12842. /**
  12843. *<p><code>URL</code> 提供URL格式化,URL版本管理的类。</p>
  12844. *<p>引擎加载资源的时候,会自动调用formatURL函数格式化URL路径</p>
  12845. *<p>通过basePath属性可以设置网络基础路径</p>
  12846. *<p>通过设置customFormat函数,可以自定义URL格式化的方式</p>
  12847. *<p>除了默认的通过增加后缀的格式化外,通过VersionManager类,可以开启IDE提供的,基于目录的管理方式来替代 "?v=" 的管理方式</p>
  12848. *@see laya.net.VersionManager
  12849. */
  12850. //class laya.net.URL
  12851. var URL=(function(){
  12852. function URL(url){
  12853. /**@private */
  12854. this._url=null;
  12855. /**@private */
  12856. this._path=null;
  12857. this._url=URL.formatURL(url);
  12858. this._path=URL.getPath(url);
  12859. }
  12860. __class(URL,'laya.net.URL');
  12861. var __proto=URL.prototype;
  12862. /**地址的文件夹路径(不包括文件名)。*/
  12863. __getset(0,__proto,'path',function(){
  12864. return this._path;
  12865. });
  12866. /**格式化后的地址。*/
  12867. __getset(0,__proto,'url',function(){
  12868. return this._url;
  12869. });
  12870. /**基础路径。如果不设置,默认为当前网页的路径。最终地址将被格式化为 basePath+相对URL地址,*/
  12871. __getset(1,URL,'basePath',function(){
  12872. return URL._basePath;
  12873. },function(value){
  12874. URL._basePath=Laya._getUrlPath();
  12875. URL._basePath=URL.formatURL(value);
  12876. });
  12877. URL.formatURL=function(url){
  12878. if (!url)return "null path";
  12879. if (url.indexOf(":")> 0)return url;
  12880. if (URL.customFormat !=null)url=URL.customFormat(url);
  12881. if (url.indexOf(":")> 0)return url;
  12882. var char1=url.charAt(0);
  12883. if (char1==="."){
  12884. return URL._formatRelativePath(URL._basePath+url);
  12885. }else if (char1==='~'){
  12886. return URL.rootPath+url.substring(1);
  12887. }else if (char1==="d"){
  12888. if (url.indexOf("data:image")===0)return url;
  12889. }else if (char1==="/"){
  12890. return url;
  12891. }
  12892. return URL._basePath+url;
  12893. }
  12894. URL._formatRelativePath=function(value){
  12895. var parts=value.split("/");
  12896. for (var i=0,len=parts.length;i < len;i++){
  12897. if (parts[i]=='..'){
  12898. parts.splice(i-1,2);
  12899. i-=2;
  12900. }
  12901. }
  12902. return parts.join('/');
  12903. }
  12904. URL.getPath=function(url){
  12905. var ofs=url.lastIndexOf('/');
  12906. return ofs > 0 ? url.substr(0,ofs+1):"";
  12907. }
  12908. URL.getFileName=function(url){
  12909. var ofs=url.lastIndexOf('/');
  12910. return ofs > 0 ? url.substr(ofs+1):url;
  12911. }
  12912. URL.getAdptedFilePath=function(url){
  12913. if (!URL.exportSceneToJson || !url)return url;
  12914. var i=0,len=0;
  12915. len=URL._adpteTypeList.length;
  12916. var tArr;
  12917. for (i=0;i < len;i++){
  12918. tArr=URL._adpteTypeList[i];
  12919. url=url.replace(tArr[0],tArr[1]);
  12920. }
  12921. return url;
  12922. }
  12923. URL.version={};
  12924. URL.exportSceneToJson=false;
  12925. URL._basePath="";
  12926. URL.rootPath="";
  12927. URL.customFormat=function(url){
  12928. var newUrl=URL.version[url];
  12929. if (!Render.isConchApp && newUrl)url+="?v="+newUrl;
  12930. return url;
  12931. }
  12932. __static(URL,
  12933. ['_adpteTypeList',function(){return this._adpteTypeList=[[".scene3d",".json"],[".scene",".json"],[".taa",".json"],[".prefab",".json"]];}
  12934. ]);
  12935. return URL;
  12936. })()
  12937. /**
  12938. *<p> <code>Stat</code> 是一个性能统计面板,可以实时更新相关的性能参数。</p>
  12939. *<p>参与统计的性能参数如下(所有参数都是每大约1秒进行更新):<br/>
  12940. *FPS(Canvas)/FPS(WebGL):Canvas 模式或者 WebGL 模式下的帧频,也就是每秒显示的帧数,值越高、越稳定,感觉越流畅;<br/>
  12941. *Sprite:统计所有渲染节点(包括容器)数量,它的大小会影响引擎进行节点遍历、数据组织和渲染的效率。其值越小,游戏运行效率越高;<br/>
  12942. *DrawCall:此值是决定性能的重要指标,其值越小,游戏运行效率越高。Canvas模式下表示每大约1秒的图像绘制次数;WebGL模式下表示每大约1秒的渲染提交批次,每次准备数据并通知GPU渲染绘制的过程称为1次DrawCall,在每次DrawCall中除了在通知GPU的渲染上比较耗时之外,切换材质与shader也是非常耗时的操作;<br/>
  12943. *CurMem:Canvas模式下,表示内存占用大小,值越小越好,过高会导致游戏闪退;WebGL模式下,表示内存与显存的占用,值越小越好;<br/>
  12944. *Shader:是 WebGL 模式独有的性能指标,表示每大约1秒 Shader 提交次数,值越小越好;<br/>
  12945. *Canvas:由三个数值组成,只有设置 CacheAs 后才会有值,默认为0/0/0。从左到右数值的意义分别为:每帧重绘的画布数量 / 缓存类型为"normal"类型的画布数量 / 缓存类型为"bitmap"类型的画布数量。</p>
  12946. */
  12947. //class laya.utils.Stat
  12948. var Stat=(function(){
  12949. function Stat(){}
  12950. __class(Stat,'laya.utils.Stat');
  12951. /**
  12952. *点击性能统计显示区域的处理函数。
  12953. */
  12954. __getset(1,Stat,'onclick',null,function(fn){
  12955. if (Stat._sp){
  12956. Stat._sp.on("click",Stat._sp,fn);
  12957. }
  12958. if (Stat._canvas){
  12959. Stat._canvas.source.onclick=fn;
  12960. Stat._canvas.source.style.pointerEvents='';
  12961. }
  12962. });
  12963. Stat.show=function(x,y){
  12964. (x===void 0)&& (x=0);
  12965. (y===void 0)&& (y=0);
  12966. if (!Browser.onMiniGame && !Browser.onLimixiu && !Render.isConchApp && !Browser.onBDMiniGame && !Browser.onKGMiniGame && !Browser.onQGMiniGame && !Browser.onVVMiniGame && !Browser.onAlipayMiniGame && !Browser.onBLMiniGame && !Browser.onQQMiniGame)Stat._useCanvas=true;
  12967. Stat._show=true;
  12968. Stat._fpsData.length=60;
  12969. Stat._view[0]={title:"FPS(Canvas)",value:"_fpsStr",color:"yellow",units:"int"};
  12970. Stat._view[1]={title:"Sprite",value:"_spriteStr",color:"white",units:"int"};
  12971. Stat._view[2]={title:"RenderBatches",value:"renderBatches",color:"white",units:"int"};
  12972. Stat._view[3]={title:"SavedRenderBatches",value:"savedRenderBatches",color:"white",units:"int"};
  12973. Stat._view[4]={title:"CPUMemory",value:"cpuMemory",color:"yellow",units:"M"};
  12974. Stat._view[5]={title:"GPUMemory",value:"gpuMemory",color:"yellow",units:"M"};
  12975. Stat._view[6]={title:"Shader",value:"shaderCall",color:"white",units:"int"};
  12976. if (!Render.is3DMode){
  12977. Stat._view[0].title="FPS(WebGL)";
  12978. Stat._view[7]={title:"Canvas",value:"_canvasStr",color:"white",units:"int"};
  12979. }else {
  12980. Stat._view[0].title="FPS(3D)";
  12981. Stat._view[7]={title:"TriFaces",value:"trianglesFaces",color:"white",units:"int"};
  12982. Stat._view[8]={title:"FrustumCulling",value:"frustumCulling",color:"white",units:"int"};
  12983. Stat._view[9]={title:"OctreeNodeCulling",value:"octreeNodeCulling",color:"white",units:"int"};
  12984. }
  12985. if (Stat._useCanvas){
  12986. Stat.createUIPre(x,y);
  12987. }else
  12988. Stat.createUI(x,y);
  12989. Stat.enable();
  12990. }
  12991. Stat.createUIPre=function(x,y){
  12992. var pixel=Browser.pixelRatio;
  12993. if(Browser.onQGMiniGame || Browser.onVVMiniGame){
  12994. pixel=3;
  12995. }
  12996. Stat._width=pixel *180;
  12997. Stat._vx=pixel *120;
  12998. Stat._height=pixel *(Stat._view.length *12+3 *pixel)+4;
  12999. Stat._fontSize=12 *pixel;
  13000. for (var i=0;i < Stat._view.length;i++){
  13001. Stat._view[i].x=4;
  13002. Stat._view[i].y=i *Stat._fontSize+2 *pixel;
  13003. }
  13004. if (!Stat._canvas){
  13005. Stat._canvas=new HTMLCanvas(true);
  13006. Stat._canvas.size(Stat._width,Stat._height);
  13007. Stat._ctx=Stat._canvas.getContext('2d');
  13008. Stat._ctx.textBaseline="top";
  13009. Stat._ctx.font=Stat._fontSize+"px Arial";
  13010. Stat._canvas.source.style.cssText="pointer-events:none;background:rgba(150,150,150,0.8);z-index:100000;position: absolute;direction:ltr;left:"+x+"px;top:"+y+"px;width:"+(Stat._width / pixel)+"px;height:"+(Stat._height / pixel)+"px;";
  13011. }
  13012. if(!Browser.onKGMiniGame){
  13013. Browser.container.appendChild(Stat._canvas.source);
  13014. }
  13015. Stat._first=true;
  13016. Stat.loop();
  13017. Stat._first=false;
  13018. }
  13019. Stat.createUI=function(x,y){
  13020. var stat=Stat._sp;
  13021. var pixel=Browser.pixelRatio;
  13022. if(Browser.onQGMiniGame || Browser.onVVMiniGame){
  13023. pixel=3;
  13024. }
  13025. if (!stat){
  13026. stat=new Sprite();
  13027. Stat._leftText=new Text();
  13028. Stat._leftText.pos(5,5);
  13029. Stat._leftText.color="#ffffff";
  13030. stat.addChild(Stat._leftText);
  13031. Stat._txt=new Text();
  13032. Stat._txt.pos(80 *pixel,5);
  13033. Stat._txt.color="#ffffff";
  13034. stat.addChild(Stat._txt);
  13035. Stat._sp=stat;
  13036. }
  13037. stat.pos(x,y);
  13038. var text="";
  13039. for (var i=0;i < Stat._view.length;i++){
  13040. var one=Stat._view[i];
  13041. text+=one.title+"\n";
  13042. }
  13043. Stat._leftText.text=text;
  13044. var width=pixel *138;
  13045. var height=pixel *(Stat._view.length *12+3 *pixel)+4;
  13046. Stat._txt.fontSize=Stat._fontSize *pixel;
  13047. Stat._leftText.fontSize=Stat._fontSize *pixel;
  13048. stat.size(width,height);
  13049. stat.graphics.clear();
  13050. stat.graphics.alpha(0.5);
  13051. stat.graphics.drawRect(0,0,width,height,"#999999");
  13052. stat.graphics.alpha(2);
  13053. Stat.loop();
  13054. }
  13055. Stat.enable=function(){
  13056. Laya.systemTimer.frameLoop(1,Stat,Stat.loop);
  13057. }
  13058. Stat.hide=function(){
  13059. Stat._show=false;
  13060. Laya.systemTimer.clear(Stat,Stat.loop);
  13061. if (Stat._canvas){
  13062. Browser.removeElement(Stat._canvas.source);
  13063. }
  13064. }
  13065. Stat.clear=function(){
  13066. Stat.trianglesFaces=Stat.renderBatches=Stat.savedRenderBatches=Stat.shaderCall=Stat.spriteRenderUseCacheCount=Stat.frustumCulling=Stat.octreeNodeCulling=Stat.canvasNormal=Stat.canvasBitmap=Stat.canvasReCache=0;
  13067. }
  13068. Stat.loop=function(){
  13069. Stat._count++;
  13070. var timer=Browser.now();
  13071. if (timer-Stat._timer < 1000)return;
  13072. var count=Stat._count;
  13073. Stat.FPS=Math.round((count *1000)/ (timer-Stat._timer));
  13074. if (Stat._show){
  13075. Stat.trianglesFaces=Math.round(Stat.trianglesFaces / count);
  13076. if (!Stat._useCanvas){
  13077. Stat.renderBatches=Math.round(Stat.renderBatches / count)-1;
  13078. }else {
  13079. Stat.renderBatches=Math.round(Stat.renderBatches / count);
  13080. }
  13081. Stat.savedRenderBatches=Math.round(Stat.savedRenderBatches / count);
  13082. Stat.shaderCall=Math.round(Stat.shaderCall / count);
  13083. Stat.spriteRenderUseCacheCount=Math.round(Stat.spriteRenderUseCacheCount / count);
  13084. Stat.canvasNormal=Math.round(Stat.canvasNormal / count);
  13085. Stat.canvasBitmap=Math.round(Stat.canvasBitmap / count);
  13086. Stat.canvasReCache=Math.ceil(Stat.canvasReCache / count);
  13087. Stat.frustumCulling=Math.round(Stat.frustumCulling / count);
  13088. Stat.octreeNodeCulling=Math.round(Stat.octreeNodeCulling / count);
  13089. var delay=Stat.FPS > 0 ? Math.floor(1000 / Stat.FPS).toString():" ";
  13090. Stat._fpsStr=Stat.FPS+(Stat.renderSlow ? " slow" :"")+" "+delay;
  13091. if (Stat._useCanvas)
  13092. Stat._spriteStr=(Stat.spriteCount-1)+(Stat.spriteRenderUseCacheCount ? ("/"+Stat.spriteRenderUseCacheCount):'');
  13093. else
  13094. Stat._spriteStr=(Stat.spriteCount-4)+(Stat.spriteRenderUseCacheCount ? ("/"+Stat.spriteRenderUseCacheCount):'');
  13095. Stat._canvasStr=Stat.canvasReCache+"/"+Stat.canvasNormal+"/"+Stat.canvasBitmap;
  13096. Stat.cpuMemory=Resource.cpuMemory;
  13097. Stat.gpuMemory=Resource.gpuMemory;
  13098. if (Stat._useCanvas){
  13099. Stat.renderInfoPre();
  13100. }else
  13101. Stat.renderInfo();
  13102. Stat.clear();
  13103. }
  13104. Stat._count=0;
  13105. Stat._timer=timer;
  13106. }
  13107. Stat.renderInfoPre=function(){
  13108. var i=0;
  13109. var one;
  13110. var value;
  13111. if (Stat._canvas){
  13112. var ctx=Stat._ctx;
  13113. ctx.clearRect(Stat._first ? 0 :Stat._vx,0,Stat._width,Stat._height);
  13114. for (i=0;i < Stat._view.length;i++){
  13115. one=Stat._view[i];
  13116. if (Stat._first){
  13117. ctx.fillStyle="white";
  13118. ctx.fillText(one.title,one.x,one.y);
  13119. }
  13120. ctx.fillStyle=one.color;
  13121. value=Stat[one.value];
  13122. (one.units=="M")&& (value=Math.floor(value / (1024 *1024)*100)/ 100+" M");
  13123. ctx.fillText(value+"",one.x+Stat._vx,one.y);
  13124. }
  13125. }
  13126. }
  13127. Stat.renderInfo=function(){
  13128. var text="";
  13129. for (var i=0;i < Stat._view.length;i++){
  13130. var one=Stat._view[i];
  13131. var value=Stat[one.value];
  13132. (one.units=="M")&& (value=Math.floor(value / (1024 *1024)*100)/ 100+" M");
  13133. (one.units=="K")&& (value=Math.floor(value / (1024)*100)/ 100+" K");
  13134. text+=value+"\n";
  13135. }
  13136. Stat._txt.text=text;
  13137. }
  13138. Stat.FPS=0;
  13139. Stat.loopCount=0;
  13140. Stat.shaderCall=0;
  13141. Stat.renderBatches=0;
  13142. Stat.savedRenderBatches=0;
  13143. Stat.trianglesFaces=0;
  13144. Stat.spriteCount=0;
  13145. Stat.spriteRenderUseCacheCount=0;
  13146. Stat.frustumCulling=0;
  13147. Stat.octreeNodeCulling=0;
  13148. Stat.canvasNormal=0;
  13149. Stat.canvasBitmap=0;
  13150. Stat.canvasReCache=0;
  13151. Stat.renderSlow=false;
  13152. Stat.gpuMemory=0;
  13153. Stat.cpuMemory=0;
  13154. Stat._fpsStr=null;
  13155. Stat._canvasStr=null;
  13156. Stat._spriteStr=null;
  13157. Stat._fpsData=[];
  13158. Stat._timer=0;
  13159. Stat._count=0;
  13160. Stat._view=[];
  13161. Stat._fontSize=12;
  13162. Stat._txt=null;
  13163. Stat._leftText=null;
  13164. Stat._sp=null;
  13165. Stat._titleSp=null;
  13166. Stat._bgSp=null;
  13167. Stat._show=false;
  13168. Stat._useCanvas=false;
  13169. Stat._canvas=null;
  13170. Stat._ctx=null;
  13171. Stat._first=false;
  13172. Stat._vx=NaN;
  13173. Stat._width=0;
  13174. Stat._height=100;
  13175. return Stat;
  13176. })()
  13177. /**
  13178. *绘制曲线
  13179. */
  13180. //class laya.display.cmd.DrawCurvesCmd
  13181. var DrawCurvesCmd=(function(){
  13182. function DrawCurvesCmd(){
  13183. /**
  13184. *开始绘制的 X 轴位置。
  13185. */
  13186. //this.x=NaN;
  13187. /**
  13188. *开始绘制的 Y 轴位置。
  13189. */
  13190. //this.y=NaN;
  13191. /**
  13192. *线段的点集合,格式[controlX,controlY,anchorX,anchorY...]。
  13193. */
  13194. //this.points=null;
  13195. /**
  13196. *线段颜色,或者填充绘图的渐变对象。
  13197. */
  13198. //this.lineColor=null;
  13199. /**
  13200. *(可选)线段宽度。
  13201. */
  13202. //this.lineWidth=NaN;
  13203. }
  13204. __class(DrawCurvesCmd,'laya.display.cmd.DrawCurvesCmd');
  13205. var __proto=DrawCurvesCmd.prototype;
  13206. /**
  13207. *回收到对象池
  13208. */
  13209. __proto.recover=function(){
  13210. this.points=null;
  13211. this.lineColor=null;
  13212. Pool.recover("DrawCurvesCmd",this);
  13213. }
  13214. /**@private */
  13215. __proto.run=function(context,gx,gy){
  13216. context.drawCurves(this.x+gx,this.y+gy,this.points,this.lineColor,this.lineWidth);
  13217. }
  13218. /**@private */
  13219. __getset(0,__proto,'cmdID',function(){
  13220. return "DrawCurves";
  13221. });
  13222. DrawCurvesCmd.create=function(x,y,points,lineColor,lineWidth){
  13223. var cmd=Pool.getItemByClass("DrawCurvesCmd",DrawCurvesCmd);
  13224. cmd.x=x;
  13225. cmd.y=y;
  13226. cmd.points=points;
  13227. cmd.lineColor=lineColor;
  13228. cmd.lineWidth=lineWidth;
  13229. return cmd;
  13230. }
  13231. DrawCurvesCmd.ID="DrawCurves";
  13232. return DrawCurvesCmd;
  13233. })()
  13234. /**
  13235. *@private
  13236. */
  13237. //class laya.net.AtlasInfoManager
  13238. var AtlasInfoManager=(function(){
  13239. function AtlasInfoManager(){}
  13240. __class(AtlasInfoManager,'laya.net.AtlasInfoManager');
  13241. AtlasInfoManager.enable=function(infoFile,callback){
  13242. Laya.loader.load(infoFile,Handler.create(null,AtlasInfoManager._onInfoLoaded,[callback]),null,/*laya.net.Loader.JSON*/"json");
  13243. }
  13244. AtlasInfoManager._onInfoLoaded=function(callback,data){
  13245. var tKey;
  13246. var tPrefix;
  13247. var tArr;
  13248. var i=0,len=0;
  13249. for (tKey in data){
  13250. tArr=data[tKey];
  13251. tPrefix=tArr[0];
  13252. tArr=tArr[1];
  13253. len=tArr.length;
  13254. for (i=0;i < len;i++){
  13255. AtlasInfoManager._fileLoadDic[tPrefix+tArr[i]]=tKey;
  13256. }
  13257. }
  13258. callback && callback.run();
  13259. }
  13260. AtlasInfoManager.getFileLoadPath=function(file){
  13261. return AtlasInfoManager._fileLoadDic[file] || file;
  13262. }
  13263. AtlasInfoManager._fileLoadDic={};
  13264. return AtlasInfoManager;
  13265. })()
  13266. //class laya.webgl.shader.d2.skinAnishader.SkinMeshBuffer
  13267. var SkinMeshBuffer=(function(){
  13268. function SkinMeshBuffer(){
  13269. this.ib=null;
  13270. this.vb=null;
  13271. var gl=WebGL.mainContext;
  13272. this.ib=IndexBuffer2D.create(/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
  13273. this.vb=VertexBuffer2D.create(8);
  13274. }
  13275. __class(SkinMeshBuffer,'laya.webgl.shader.d2.skinAnishader.SkinMeshBuffer');
  13276. var __proto=SkinMeshBuffer.prototype;
  13277. //TODO:coverage
  13278. __proto.addSkinMesh=function(skinMesh){
  13279. skinMesh.getData2(this.vb,this.ib,this.vb._byteLength / 32);
  13280. }
  13281. __proto.reset=function(){
  13282. this.vb.clear();
  13283. this.ib.clear();
  13284. }
  13285. SkinMeshBuffer.getInstance=function(){
  13286. return SkinMeshBuffer.instance=SkinMeshBuffer.instance|| new SkinMeshBuffer();
  13287. }
  13288. SkinMeshBuffer.instance=null;
  13289. return SkinMeshBuffer;
  13290. })()
  13291. /**
  13292. *绘制扇形
  13293. */
  13294. //class laya.display.cmd.DrawPieCmd
  13295. var DrawPieCmd=(function(){
  13296. function DrawPieCmd(){
  13297. /**
  13298. *开始绘制的 X 轴位置。
  13299. */
  13300. //this.x=NaN;
  13301. /**
  13302. *开始绘制的 Y 轴位置。
  13303. */
  13304. //this.y=NaN;
  13305. /**
  13306. *扇形半径。
  13307. */
  13308. //this.radius=NaN;
  13309. //this._startAngle=NaN;
  13310. //this._endAngle=NaN;
  13311. /**
  13312. *填充颜色,或者填充绘图的渐变对象。
  13313. */
  13314. //this.fillColor=null;
  13315. /**
  13316. *(可选)边框颜色,或者填充绘图的渐变对象。
  13317. */
  13318. //this.lineColor=null;
  13319. /**
  13320. *(可选)边框宽度。
  13321. */
  13322. //this.lineWidth=NaN;
  13323. /**@private */
  13324. //this.vid=0;
  13325. }
  13326. __class(DrawPieCmd,'laya.display.cmd.DrawPieCmd');
  13327. var __proto=DrawPieCmd.prototype;
  13328. /**
  13329. *回收到对象池
  13330. */
  13331. __proto.recover=function(){
  13332. this.fillColor=null;
  13333. this.lineColor=null;
  13334. Pool.recover("DrawPieCmd",this);
  13335. }
  13336. /**@private */
  13337. __proto.run=function(context,gx,gy){
  13338. context._drawPie(this.x+gx,this.y+gy,this.radius,this._startAngle,this._endAngle,this.fillColor,this.lineColor,this.lineWidth,this.vid);
  13339. }
  13340. /**
  13341. *开始角度。
  13342. */
  13343. __getset(0,__proto,'startAngle',function(){
  13344. return this._startAngle *180 / Math.PI;
  13345. },function(value){
  13346. this._startAngle=value *Math.PI / 180;
  13347. });
  13348. /**@private */
  13349. __getset(0,__proto,'cmdID',function(){
  13350. return "DrawPie";
  13351. });
  13352. /**
  13353. *结束角度。
  13354. */
  13355. __getset(0,__proto,'endAngle',function(){
  13356. return this._endAngle *180 / Math.PI;
  13357. },function(value){
  13358. this._endAngle=value *Math.PI / 180;
  13359. });
  13360. DrawPieCmd.create=function(x,y,radius,startAngle,endAngle,fillColor,lineColor,lineWidth,vid){
  13361. var cmd=Pool.getItemByClass("DrawPieCmd",DrawPieCmd);
  13362. cmd.x=x;
  13363. cmd.y=y;
  13364. cmd.radius=radius;
  13365. cmd._startAngle=startAngle;
  13366. cmd._endAngle=endAngle;
  13367. cmd.fillColor=fillColor;
  13368. cmd.lineColor=lineColor;
  13369. cmd.lineWidth=lineWidth;
  13370. cmd.vid=vid;
  13371. return cmd;
  13372. }
  13373. DrawPieCmd.ID="DrawPie";
  13374. return DrawPieCmd;
  13375. })()
  13376. /**
  13377. *@private
  13378. */
  13379. //class laya.utils.CallLater
  13380. var CallLater=(function(){
  13381. var LaterHandler;
  13382. function CallLater(){
  13383. /**@private */
  13384. this._pool=[];
  13385. /**@private */
  13386. this._map=[];
  13387. /**@private */
  13388. this._laters=[];
  13389. }
  13390. __class(CallLater,'laya.utils.CallLater');
  13391. var __proto=CallLater.prototype;
  13392. /**
  13393. *@private
  13394. *帧循环处理函数。
  13395. */
  13396. __proto._update=function(){
  13397. var laters=this._laters;
  13398. var len=laters.length;
  13399. if (len > 0){
  13400. for (var i=0,n=len-1;i <=n;i++){
  13401. var handler=laters[i];
  13402. this._map[handler.key]=null;
  13403. if (handler.method!==null){
  13404. handler.run();
  13405. handler.clear();
  13406. }
  13407. this._pool.push(handler);
  13408. i===n && (n=laters.length-1);
  13409. }
  13410. laters.length=0;
  13411. }
  13412. }
  13413. /**@private */
  13414. __proto._getHandler=function(caller,method){
  13415. var cid=caller ? caller.$_GID || (caller.$_GID=Utils.getGID()):0;
  13416. var mid=method.$_TID || (method.$_TID=(Timer._mid++)*100000);
  13417. return this._map[cid+mid];
  13418. }
  13419. /**
  13420. *延迟执行。
  13421. *@param caller 执行域(this)。
  13422. *@param method 定时器回调函数。
  13423. *@param args 回调参数。
  13424. */
  13425. __proto.callLater=function(caller,method,args){
  13426. if (this._getHandler(caller,method)==null){
  13427. if (this._pool.length)
  13428. var handler=this._pool.pop();
  13429. else handler=new LaterHandler();
  13430. handler.caller=caller;
  13431. handler.method=method;
  13432. handler.args=args;
  13433. var cid=caller ? caller.$_GID :0;
  13434. var mid=method["$_TID"];
  13435. handler.key=cid+mid;
  13436. this._map[handler.key]=handler
  13437. this._laters.push(handler);
  13438. }
  13439. }
  13440. /**
  13441. *立即执行 callLater 。
  13442. *@param caller 执行域(this)。
  13443. *@param method 定时器回调函数。
  13444. */
  13445. __proto.runCallLater=function(caller,method){
  13446. var handler=this._getHandler(caller,method);
  13447. if (handler && handler.method !=null){
  13448. this._map[handler.key]=null;
  13449. handler.run();
  13450. handler.clear();
  13451. }
  13452. }
  13453. CallLater.I=new CallLater();
  13454. CallLater.__init$=function(){
  13455. /**@private */
  13456. //class LaterHandler
  13457. LaterHandler=(function(){
  13458. function LaterHandler(){
  13459. this.key=0;
  13460. this.caller=null;
  13461. this.method=null;
  13462. this.args=null;
  13463. }
  13464. __class(LaterHandler,'');
  13465. var __proto=LaterHandler.prototype;
  13466. __proto.clear=function(){
  13467. this.caller=null;
  13468. this.method=null;
  13469. this.args=null;
  13470. }
  13471. __proto.run=function(){
  13472. var caller=this.caller;
  13473. if (caller && caller.destroyed)return this.clear();
  13474. var method=this.method;
  13475. var args=this.args;
  13476. if (method==null)return;
  13477. args ? method.apply(caller,args):method.call(caller);
  13478. }
  13479. return LaterHandler;
  13480. })()
  13481. }
  13482. return CallLater;
  13483. })()
  13484. //class laya.webgl.canvas.save.SaveClipRect
  13485. var SaveClipRect=(function(){
  13486. function SaveClipRect(){
  13487. this._clipInfoID=-1;
  13488. this.incache=false;
  13489. this._globalClipMatrix=new Matrix();
  13490. this._clipRect=new Rectangle();
  13491. }
  13492. __class(SaveClipRect,'laya.webgl.canvas.save.SaveClipRect');
  13493. var __proto=SaveClipRect.prototype;
  13494. Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true})
  13495. __proto.isSaveMark=function(){return false;}
  13496. __proto.restore=function(context){
  13497. this._globalClipMatrix.copyTo(context._globalClipMatrix);
  13498. this._clipRect.clone(context._clipRect);
  13499. context._clipInfoID=this._clipInfoID;
  13500. SaveClipRect.POOL[SaveClipRect.POOL._length++]=this;
  13501. context._clipInCache=this.incache;
  13502. }
  13503. SaveClipRect.save=function(context){
  13504. if ((context._saveMark._saveuse & /*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT*/0x20000)==/*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT*/0x20000)return;
  13505. context._saveMark._saveuse |=/*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT*/0x20000;
  13506. var cache=SaveClipRect.POOL;
  13507. var o=cache._length > 0 ? cache[--cache._length] :(new SaveClipRect());
  13508. context._globalClipMatrix.copyTo(o._globalClipMatrix);
  13509. context._clipRect.clone(o._clipRect);
  13510. o._clipInfoID=context._clipInfoID;
  13511. o.incache=context._clipInCache;
  13512. var _save=context._save;
  13513. _save[_save._length++]=o;
  13514. }
  13515. SaveClipRect.POOL=SaveBase._createArray();
  13516. return SaveClipRect;
  13517. })()
  13518. //class laya.webgl.WebGLContext
  13519. var WebGLContext=(function(){
  13520. function WebGLContext(){}
  13521. __class(WebGLContext,'laya.webgl.WebGLContext');
  13522. var __proto=WebGLContext.prototype;
  13523. __proto.getContextAttributes=function(){return null;}
  13524. __proto.isContextLost=function(){}
  13525. __proto.getSupportedExtensions=function(){return null;}
  13526. __proto.getExtension=function(name){return null;}
  13527. __proto.activeTexture=function(texture){}
  13528. __proto.attachShader=function(program,shader){}
  13529. __proto.bindAttribLocation=function(program,index,name){}
  13530. __proto.bindBuffer=function(target,buffer){}
  13531. __proto.bindFramebuffer=function(target,framebuffer){}
  13532. __proto.bindRenderbuffer=function(target,renderbuffer){}
  13533. __proto.bindTexture=function(target,texture){}
  13534. __proto.useTexture=function(value){}
  13535. __proto.blendColor=function(red,green,blue,alpha){}
  13536. __proto.blendEquation=function(mode){}
  13537. __proto.blendEquationSeparate=function(modeRGB,modeAlpha){}
  13538. __proto.blendFunc=function(sfactor,dfactor){}
  13539. __proto.blendFuncSeparate=function(srcRGB,dstRGB,srcAlpha,dstAlpha){}
  13540. __proto.bufferData=function(target,size,usage){}
  13541. __proto.bufferSubData=function(target,offset,data){}
  13542. __proto.checkFramebufferStatus=function(target){return null;}
  13543. __proto.clear=function(mask){}
  13544. __proto.clearColor=function(red,green,blue,alpha){}
  13545. __proto.clearDepth=function(depth){}
  13546. __proto.clearStencil=function(s){}
  13547. __proto.colorMask=function(red,green,blue,alpha){}
  13548. __proto.compileShader=function(shader){}
  13549. __proto.copyTexImage2D=function(target,level,internalformat,x,y,width,height,border){}
  13550. __proto.copyTexSubImage2D=function(target,level,xoffset,yoffset,x,y,width,height){}
  13551. __proto.createBuffer=function(){}
  13552. __proto.createFramebuffer=function(){}
  13553. __proto.createProgram=function(){}
  13554. __proto.createRenderbuffer=function(){}
  13555. __proto.createShader=function(type){}
  13556. __proto.createTexture=function(){return null}
  13557. __proto.cullFace=function(mode){}
  13558. __proto.deleteBuffer=function(buffer){}
  13559. __proto.deleteFramebuffer=function(framebuffer){}
  13560. __proto.deleteProgram=function(program){}
  13561. __proto.deleteRenderbuffer=function(renderbuffer){}
  13562. __proto.deleteShader=function(shader){}
  13563. __proto.deleteTexture=function(texture){}
  13564. __proto.depthFunc=function(func){}
  13565. __proto.depthMask=function(flag){}
  13566. __proto.depthRange=function(zNear,zFar){}
  13567. __proto.detachShader=function(program,shader){}
  13568. __proto.disable=function(cap){}
  13569. __proto.disableVertexAttribArray=function(index){}
  13570. __proto.drawArrays=function(mode,first,count){}
  13571. __proto.drawElements=function(mode,count,type,offset){}
  13572. __proto.enable=function(cap){}
  13573. __proto.enableVertexAttribArray=function(index){}
  13574. __proto.finish=function(){}
  13575. __proto.flush=function(){}
  13576. __proto.framebufferRenderbuffer=function(target,attachment,renderbuffertarget,renderbuffer){}
  13577. __proto.framebufferTexture2D=function(target,attachment,textarget,texture,level){}
  13578. __proto.frontFace=function(mode){return null;}
  13579. __proto.generateMipmap=function(target){return null;}
  13580. __proto.getActiveAttrib=function(program,index){return null;}
  13581. __proto.getActiveUniform=function(program,index){return null;}
  13582. __proto.getAttribLocation=function(program,name){return 0;}
  13583. __proto.getParameter=function(pname){return null;}
  13584. __proto.getBufferParameter=function(target,pname){return null;}
  13585. __proto.getError=function(){return null;}
  13586. __proto.getFramebufferAttachmentParameter=function(target,attachment,pname){}
  13587. __proto.getProgramParameter=function(program,pname){return 0;}
  13588. __proto.getProgramInfoLog=function(program){return null;}
  13589. __proto.getRenderbufferParameter=function(target,pname){return null;}
  13590. __proto.getShaderPrecisionFormat=function(__arg){
  13591. var arg=arguments;return null;}
  13592. __proto.getShaderParameter=function(shader,pname){}
  13593. __proto.getShaderInfoLog=function(shader){return null;}
  13594. __proto.getShaderSource=function(shader){return null;}
  13595. __proto.getTexParameter=function(target,pname){}
  13596. __proto.getUniform=function(program,location){}
  13597. __proto.getUniformLocation=function(program,name){return null;}
  13598. __proto.getVertexAttrib=function(index,pname){return null;}
  13599. __proto.getVertexAttribOffset=function(index,pname){return null;}
  13600. __proto.hint=function(target,mode){}
  13601. __proto.isBuffer=function(buffer){}
  13602. __proto.isEnabled=function(cap){}
  13603. __proto.isFramebuffer=function(framebuffer){}
  13604. __proto.isProgram=function(program){}
  13605. __proto.isRenderbuffer=function(renderbuffer){}
  13606. __proto.isShader=function(shader){}
  13607. __proto.isTexture=function(texture){}
  13608. __proto.lineWidth=function(width){}
  13609. __proto.linkProgram=function(program){}
  13610. __proto.pixelStorei=function(pname,param){}
  13611. __proto.polygonOffset=function(factor,units){}
  13612. __proto.readPixels=function(x,y,width,height,format,type,pixels){}
  13613. __proto.renderbufferStorage=function(target,internalformat,width,height){}
  13614. __proto.sampleCoverage=function(value,invert){}
  13615. __proto.scissor=function(x,y,width,height){}
  13616. __proto.shaderSource=function(shader,source){}
  13617. __proto.stencilFunc=function(func,ref,mask){}
  13618. __proto.stencilFuncSeparate=function(face,func,ref,mask){}
  13619. __proto.stencilMask=function(mask){}
  13620. __proto.stencilMaskSeparate=function(face,mask){}
  13621. __proto.stencilOp=function(fail,zfail,zpass){}
  13622. __proto.stencilOpSeparate=function(face,fail,zfail,zpass){}
  13623. __proto.texImage2D=function(__args){}
  13624. __proto.texParameterf=function(target,pname,param){}
  13625. __proto.texParameteri=function(target,pname,param){}
  13626. __proto.texSubImage2D=function(__args){}
  13627. __proto.uniform1f=function(location,x){}
  13628. __proto.uniform1fv=function(location,v){}
  13629. __proto.uniform1i=function(location,x){}
  13630. __proto.uniform1iv=function(location,v){}
  13631. __proto.uniform2f=function(location,x,y){}
  13632. __proto.uniform2fv=function(location,v){}
  13633. __proto.uniform2i=function(location,x,y){}
  13634. __proto.uniform2iv=function(location,v){}
  13635. __proto.uniform3f=function(location,x,y,z){}
  13636. __proto.uniform3fv=function(location,v){}
  13637. __proto.uniform3i=function(location,x,y,z){}
  13638. __proto.uniform3iv=function(location,v){}
  13639. __proto.uniform4f=function(location,x,y,z,w){}
  13640. __proto.uniform4fv=function(location,v){}
  13641. __proto.uniform4i=function(location,x,y,z,w){}
  13642. __proto.uniform4iv=function(location,v){}
  13643. __proto.uniformMatrix2fv=function(location,transpose,value){}
  13644. __proto.uniformMatrix3fv=function(location,transpose,value){}
  13645. __proto.uniformMatrix4fv=function(location,transpose,value){}
  13646. __proto.useProgram=function(program){}
  13647. __proto.validateProgram=function(program){}
  13648. __proto.vertexAttrib1f=function(indx,x){}
  13649. __proto.vertexAttrib1fv=function(indx,values){}
  13650. __proto.vertexAttrib2f=function(indx,x,y){}
  13651. __proto.vertexAttrib2fv=function(indx,values){}
  13652. __proto.vertexAttrib3f=function(indx,x,y,z){}
  13653. __proto.vertexAttrib3fv=function(indx,values){}
  13654. __proto.vertexAttrib4f=function(indx,x,y,z,w){}
  13655. __proto.vertexAttrib4fv=function(indx,values){}
  13656. __proto.vertexAttribPointer=function(indx,size,type,normalized,stride,offset){}
  13657. __proto.viewport=function(x,y,width,height){}
  13658. __proto.configureBackBuffer=function(width,height,antiAlias,enableDepthAndStencil,wantsBestResolution){
  13659. (enableDepthAndStencil===void 0)&& (enableDepthAndStencil=true);
  13660. (wantsBestResolution===void 0)&& (wantsBestResolution=false);
  13661. }
  13662. __proto.compressedTexImage2D=function(__args){}
  13663. //TODO:coverage
  13664. __proto.createVertexArray=function(){
  13665. throw "not implemented";
  13666. }
  13667. //TODO:coverage
  13668. __proto.bindVertexArray=function(vao){
  13669. throw "not implemented";
  13670. }
  13671. //TODO:coverage
  13672. __proto.deleteVertexArray=function(vao){
  13673. throw "not implemented";
  13674. }
  13675. //TODO:coverage
  13676. __proto.isVertexArray=function(vao){
  13677. throw "not implemented";
  13678. }
  13679. WebGLContext._forceSupportVAOPlatform=function(){
  13680. return (Browser.onMiniGame && Browser.onIOS)|| Browser.onBDMiniGame || Browser.onQGMiniGame;
  13681. }
  13682. WebGLContext.__init__=function(gl){
  13683. laya.webgl.WebGLContext._checkExtensions(gl);
  13684. if (!WebGL._isWebGL2 && !Render.isConchApp){
  13685. VertexArrayObject;
  13686. if (window._setupVertexArrayObject){
  13687. if (WebGLContext._forceSupportVAOPlatform())
  13688. window._forceSetupVertexArrayObject(gl);
  13689. else
  13690. window._setupVertexArrayObject(gl);
  13691. };
  13692. var ext=((gl).rawgl || gl).getExtension("OES_vertex_array_object");
  13693. if (ext){
  13694. var glContext=gl;
  13695. glContext.createVertexArray=function (){return ext.createVertexArrayOES();};
  13696. glContext.bindVertexArray=function (vao){ext.bindVertexArrayOES(vao);};
  13697. glContext.deleteVertexArray=function (vao){ext.deleteVertexArrayOES(vao);};
  13698. glContext.isVertexArray=function (vao){ext.isVertexArrayOES(vao);};
  13699. }
  13700. }
  13701. }
  13702. WebGLContext._getExtension=function(gl,name){
  13703. var prefixes=WebGLContext._extentionVendorPrefixes;
  13704. for (var k in prefixes){
  13705. var ext=gl.getExtension(prefixes[k]+name);
  13706. if (ext)
  13707. return ext;
  13708. }
  13709. return null;
  13710. }
  13711. WebGLContext._checkExtensions=function(gl){
  13712. WebGLContext._extTextureFilterAnisotropic=WebGLContext._getExtension(gl,"EXT_texture_filter_anisotropic");
  13713. WebGLContext._compressedTextureS3tc=WebGLContext._getExtension(gl,"WEBGL_compressed_texture_s3tc");
  13714. WebGLContext._compressedTexturePvrtc=WebGLContext._getExtension(gl,"WEBGL_compressed_texture_pvrtc");
  13715. WebGLContext._compressedTextureEtc1=WebGLContext._getExtension(gl,"WEBGL_compressed_texture_etc1");
  13716. if (!WebGLContext._forceSupportVAOPlatform())
  13717. WebGLContext._angleInstancedArrays=WebGLContext._getExtension(gl,"ANGLE_instanced_arrays");
  13718. }
  13719. WebGLContext.__init_native=function(){
  13720. if (!Render.supportWebGLPlusRendering)return;
  13721. var webGLContext=WebGLContext;
  13722. webGLContext.activeTexture=webGLContext.activeTextureForNative;
  13723. webGLContext.bindTexture=webGLContext.bindTextureForNative;
  13724. }
  13725. WebGLContext.useProgram=function(gl,program){
  13726. if (WebGLContext._useProgram===program)
  13727. return false;
  13728. gl.useProgram(program);
  13729. WebGLContext._useProgram=program;
  13730. return true;
  13731. }
  13732. WebGLContext.setDepthTest=function(gl,value){
  13733. value!==WebGLContext._depthTest && (WebGLContext._depthTest=value,value?gl.enable(/*CLASS CONST:laya.webgl.WebGLContext.DEPTH_TEST*/0x0B71):gl.disable(/*CLASS CONST:laya.webgl.WebGLContext.DEPTH_TEST*/0x0B71));
  13734. }
  13735. WebGLContext.setDepthMask=function(gl,value){
  13736. value!==WebGLContext._depthMask && (WebGLContext._depthMask=value,gl.depthMask(value));
  13737. }
  13738. WebGLContext.setDepthFunc=function(gl,value){
  13739. value!==WebGLContext._depthFunc && (WebGLContext._depthFunc=value,gl.depthFunc(value));
  13740. }
  13741. WebGLContext.setBlend=function(gl,value){
  13742. value!==WebGLContext._blend && (WebGLContext._blend=value,value?gl.enable(/*CLASS CONST:laya.webgl.WebGLContext.BLEND*/0x0BE2):gl.disable(/*CLASS CONST:laya.webgl.WebGLContext.BLEND*/0x0BE2));
  13743. }
  13744. WebGLContext.setBlendFunc=function(gl,sFactor,dFactor){
  13745. (sFactor!==WebGLContext._sFactor || dFactor!==WebGLContext._dFactor)&& (WebGLContext._sFactor=WebGLContext._srcAlpha=sFactor,WebGLContext._dFactor=WebGLContext._dstAlpha=dFactor,gl.blendFunc(sFactor,dFactor));
  13746. }
  13747. WebGLContext.setBlendFuncSeperate=function(gl,srcRGB,dstRGB,srcAlpha,dstAlpha){
  13748. if (srcRGB!==WebGLContext._sFactor || dstRGB!==WebGLContext._dFactor || srcAlpha!==WebGLContext._srcAlpha || dstAlpha!==WebGLContext._dstAlpha){
  13749. WebGLContext._sFactor=srcRGB;
  13750. WebGLContext._dFactor=dstRGB;
  13751. WebGLContext._srcAlpha=srcAlpha;
  13752. WebGLContext._dstAlpha=dstAlpha;
  13753. gl.blendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha);
  13754. }
  13755. }
  13756. WebGLContext.setCullFace=function(gl,value){
  13757. value!==WebGLContext._cullFace && (WebGLContext._cullFace=value,value?gl.enable(/*CLASS CONST:laya.webgl.WebGLContext.CULL_FACE*/0x0B44):gl.disable(/*CLASS CONST:laya.webgl.WebGLContext.CULL_FACE*/0x0B44));
  13758. }
  13759. WebGLContext.setFrontFace=function(gl,value){
  13760. value!==WebGLContext._frontFace && (WebGLContext._frontFace=value,gl.frontFace(value));
  13761. }
  13762. WebGLContext.activeTexture=function(gl,textureID){
  13763. if (WebGLContext._activedTextureID!==textureID){
  13764. gl.activeTexture(textureID);
  13765. WebGLContext._activedTextureID=textureID;
  13766. }
  13767. }
  13768. WebGLContext.bindTexture=function(gl,target,texture){
  13769. if (WebGLContext._activeTextures[WebGLContext._activedTextureID-0x84C0]!==texture){
  13770. gl.bindTexture(target,texture);
  13771. WebGLContext._activeTextures[WebGLContext._activedTextureID-0x84C0]=texture;
  13772. }
  13773. }
  13774. WebGLContext.useProgramForNative=function(gl,program){
  13775. gl.useProgram(program);
  13776. return true;
  13777. }
  13778. WebGLContext.setDepthTestForNative=function(gl,value){
  13779. if (value)gl.enable(/*CLASS CONST:laya.webgl.WebGLContext.DEPTH_TEST*/0x0B71);
  13780. else gl.disable(/*CLASS CONST:laya.webgl.WebGLContext.DEPTH_TEST*/0x0B71);
  13781. }
  13782. WebGLContext.setDepthMaskForNative=function(gl,value){
  13783. gl.depthMask(value);
  13784. }
  13785. WebGLContext.setDepthFuncForNative=function(gl,value){
  13786. gl.depthFunc(value);
  13787. }
  13788. WebGLContext.setBlendForNative=function(gl,value){
  13789. if (value)gl.enable(/*CLASS CONST:laya.webgl.WebGLContext.BLEND*/0x0BE2);
  13790. else gl.disable(/*CLASS CONST:laya.webgl.WebGLContext.BLEND*/0x0BE2);
  13791. }
  13792. WebGLContext.setBlendFuncForNative=function(gl,sFactor,dFactor){
  13793. gl.blendFunc(sFactor,dFactor);
  13794. }
  13795. WebGLContext.setCullFaceForNative=function(gl,value){
  13796. if (value)gl.enable(/*CLASS CONST:laya.webgl.WebGLContext.CULL_FACE*/0x0B44)
  13797. else gl.disable(/*CLASS CONST:laya.webgl.WebGLContext.CULL_FACE*/0x0B44);
  13798. }
  13799. WebGLContext.setFrontFaceForNative=function(gl,value){
  13800. gl.frontFace(value);
  13801. }
  13802. WebGLContext.activeTextureForNative=function(gl,textureID){
  13803. gl.activeTexture(textureID);
  13804. }
  13805. WebGLContext.bindTextureForNative=function(gl,target,texture){
  13806. gl.bindTexture(target,texture);
  13807. }
  13808. WebGLContext.bindVertexArrayForNative=function(gl,vertexArray){
  13809. /*__JS__ */gl.bindVertexArray(vertexArray);
  13810. }
  13811. WebGLContext.DEPTH_BUFFER_BIT=0x00000100;
  13812. WebGLContext.STENCIL_BUFFER_BIT=0x00000400;
  13813. WebGLContext.COLOR_BUFFER_BIT=0x00004000;
  13814. WebGLContext.POINTS=0x0000;
  13815. WebGLContext.LINES=0x0001;
  13816. WebGLContext.LINE_LOOP=0x0002;
  13817. WebGLContext.LINE_STRIP=0x0003;
  13818. WebGLContext.TRIANGLES=0x0004;
  13819. WebGLContext.TRIANGLE_STRIP=0x0005;
  13820. WebGLContext.TRIANGLE_FAN=0x0006;
  13821. WebGLContext.ZERO=0;
  13822. WebGLContext.ONE=1;
  13823. WebGLContext.SRC_COLOR=0x0300;
  13824. WebGLContext.ONE_MINUS_SRC_COLOR=0x0301;
  13825. WebGLContext.SRC_ALPHA=0x0302;
  13826. WebGLContext.ONE_MINUS_SRC_ALPHA=0x0303;
  13827. WebGLContext.DST_ALPHA=0x0304;
  13828. WebGLContext.ONE_MINUS_DST_ALPHA=0x0305;
  13829. WebGLContext.DST_COLOR=0x0306;
  13830. WebGLContext.ONE_MINUS_DST_COLOR=0x0307;
  13831. WebGLContext.SRC_ALPHA_SATURATE=0x0308;
  13832. WebGLContext.FUNC_ADD=0x8006;
  13833. WebGLContext.BLEND_EQUATION=0x8009;
  13834. WebGLContext.BLEND_EQUATION_RGB=0x8009;
  13835. WebGLContext.BLEND_EQUATION_ALPHA=0x883D;
  13836. WebGLContext.FUNC_SUBTRACT=0x800A;
  13837. WebGLContext.FUNC_REVERSE_SUBTRACT=0x800B;
  13838. WebGLContext.BLEND_DST_RGB=0x80C8;
  13839. WebGLContext.BLEND_SRC_RGB=0x80C9;
  13840. WebGLContext.BLEND_DST_ALPHA=0x80CA;
  13841. WebGLContext.BLEND_SRC_ALPHA=0x80CB;
  13842. WebGLContext.CONSTANT_COLOR=0x8001;
  13843. WebGLContext.ONE_MINUS_CONSTANT_COLOR=0x8002;
  13844. WebGLContext.CONSTANT_ALPHA=0x8003;
  13845. WebGLContext.ONE_MINUS_CONSTANT_ALPHA=0x8004;
  13846. WebGLContext.BLEND_COLOR=0x8005;
  13847. WebGLContext.ARRAY_BUFFER=0x8892;
  13848. WebGLContext.ELEMENT_ARRAY_BUFFER=0x8893;
  13849. WebGLContext.ARRAY_BUFFER_BINDING=0x8894;
  13850. WebGLContext.ELEMENT_ARRAY_BUFFER_BINDING=0x8895;
  13851. WebGLContext.STREAM_DRAW=0x88E0;
  13852. WebGLContext.STATIC_DRAW=0x88E4;
  13853. WebGLContext.DYNAMIC_DRAW=0x88E8;
  13854. WebGLContext.BUFFER_SIZE=0x8764;
  13855. WebGLContext.BUFFER_USAGE=0x8765;
  13856. WebGLContext.CURRENT_VERTEX_ATTRIB=0x8626;
  13857. WebGLContext.FRONT=0x0404;
  13858. WebGLContext.BACK=0x0405;
  13859. WebGLContext.CULL_FACE=0x0B44;
  13860. WebGLContext.FRONT_AND_BACK=0x0408;
  13861. WebGLContext.BLEND=0x0BE2;
  13862. WebGLContext.DITHER=0x0BD0;
  13863. WebGLContext.STENCIL_TEST=0x0B90;
  13864. WebGLContext.DEPTH_TEST=0x0B71;
  13865. WebGLContext.SCISSOR_TEST=0x0C11;
  13866. WebGLContext.POLYGON_OFFSET_FILL=0x8037;
  13867. WebGLContext.SAMPLE_ALPHA_TO_COVERAGE=0x809E;
  13868. WebGLContext.SAMPLE_COVERAGE=0x80A0;
  13869. WebGLContext.NO_ERROR=0;
  13870. WebGLContext.INVALID_ENUM=0x0500;
  13871. WebGLContext.INVALID_VALUE=0x0501;
  13872. WebGLContext.INVALID_OPERATION=0x0502;
  13873. WebGLContext.OUT_OF_MEMORY=0x0505;
  13874. WebGLContext.CW=0x0900;
  13875. WebGLContext.CCW=0x0901;
  13876. WebGLContext.LINE_WIDTH=0x0B21;
  13877. WebGLContext.ALIASED_POINT_SIZE_RANGE=0x846D;
  13878. WebGLContext.ALIASED_LINE_WIDTH_RANGE=0x846E;
  13879. WebGLContext.CULL_FACE_MODE=0x0B45;
  13880. WebGLContext.FRONT_FACE=0x0B46;
  13881. WebGLContext.DEPTH_RANGE=0x0B70;
  13882. WebGLContext.DEPTH_WRITEMASK=0x0B72;
  13883. WebGLContext.DEPTH_CLEAR_VALUE=0x0B73;
  13884. WebGLContext.DEPTH_FUNC=0x0B74;
  13885. WebGLContext.STENCIL_CLEAR_VALUE=0x0B91;
  13886. WebGLContext.STENCIL_FUNC=0x0B92;
  13887. WebGLContext.STENCIL_FAIL=0x0B94;
  13888. WebGLContext.STENCIL_PASS_DEPTH_FAIL=0x0B95;
  13889. WebGLContext.STENCIL_PASS_DEPTH_PASS=0x0B96;
  13890. WebGLContext.STENCIL_REF=0x0B97;
  13891. WebGLContext.STENCIL_VALUE_MASK=0x0B93;
  13892. WebGLContext.STENCIL_WRITEMASK=0x0B98;
  13893. WebGLContext.STENCIL_BACK_FUNC=0x8800;
  13894. WebGLContext.STENCIL_BACK_FAIL=0x8801;
  13895. WebGLContext.STENCIL_BACK_PASS_DEPTH_FAIL=0x8802;
  13896. WebGLContext.STENCIL_BACK_PASS_DEPTH_PASS=0x8803;
  13897. WebGLContext.STENCIL_BACK_REF=0x8CA3;
  13898. WebGLContext.STENCIL_BACK_VALUE_MASK=0x8CA4;
  13899. WebGLContext.STENCIL_BACK_WRITEMASK=0x8CA5;
  13900. WebGLContext.VIEWPORT=0x0BA2;
  13901. WebGLContext.SCISSOR_BOX=0x0C10;
  13902. WebGLContext.COLOR_CLEAR_VALUE=0x0C22;
  13903. WebGLContext.COLOR_WRITEMASK=0x0C23;
  13904. WebGLContext.UNPACK_ALIGNMENT=0x0CF5;
  13905. WebGLContext.PACK_ALIGNMENT=0x0D05;
  13906. WebGLContext.MAX_TEXTURE_SIZE=0x0D33;
  13907. WebGLContext.MAX_VIEWPORT_DIMS=0x0D3A;
  13908. WebGLContext.SUBPIXEL_BITS=0x0D50;
  13909. WebGLContext.RED_BITS=0x0D52;
  13910. WebGLContext.GREEN_BITS=0x0D53;
  13911. WebGLContext.BLUE_BITS=0x0D54;
  13912. WebGLContext.ALPHA_BITS=0x0D55;
  13913. WebGLContext.DEPTH_BITS=0x0D56;
  13914. WebGLContext.STENCIL_BITS=0x0D57;
  13915. WebGLContext.POLYGON_OFFSET_UNITS=0x2A00;
  13916. WebGLContext.POLYGON_OFFSET_FACTOR=0x8038;
  13917. WebGLContext.TEXTURE_BINDING_2D=0x8069;
  13918. WebGLContext.SAMPLE_BUFFERS=0x80A8;
  13919. WebGLContext.SAMPLES=0x80A9;
  13920. WebGLContext.SAMPLE_COVERAGE_VALUE=0x80AA;
  13921. WebGLContext.SAMPLE_COVERAGE_INVERT=0x80AB;
  13922. WebGLContext.NUM_COMPRESSED_TEXTURE_FORMATS=0x86A2;
  13923. WebGLContext.COMPRESSED_TEXTURE_FORMATS=0x86A3;
  13924. WebGLContext.DONT_CARE=0x1100;
  13925. WebGLContext.FASTEST=0x1101;
  13926. WebGLContext.NICEST=0x1102;
  13927. WebGLContext.GENERATE_MIPMAP_HINT=0x8192;
  13928. WebGLContext.BYTE=0x1400;
  13929. WebGLContext.UNSIGNED_BYTE=0x1401;
  13930. WebGLContext.SHORT=0x1402;
  13931. WebGLContext.UNSIGNED_SHORT=0x1403;
  13932. WebGLContext.INT=0x1404;
  13933. WebGLContext.UNSIGNED_INT=0x1405;
  13934. WebGLContext.FLOAT=0x1406;
  13935. WebGLContext.DEPTH_COMPONENT=0x1902;
  13936. WebGLContext.ALPHA=0x1906;
  13937. WebGLContext.RGB=0x1907;
  13938. WebGLContext.RGBA=0x1908;
  13939. WebGLContext.LUMINANCE=0x1909;
  13940. WebGLContext.LUMINANCE_ALPHA=0x190A;
  13941. WebGLContext.UNSIGNED_SHORT_4_4_4_4=0x8033;
  13942. WebGLContext.UNSIGNED_SHORT_5_5_5_1=0x8034;
  13943. WebGLContext.UNSIGNED_SHORT_5_6_5=0x8363;
  13944. WebGLContext.FRAGMENT_SHADER=0x8B30;
  13945. WebGLContext.VERTEX_SHADER=0x8B31;
  13946. WebGLContext.MAX_VERTEX_ATTRIBS=0x8869;
  13947. WebGLContext.MAX_VERTEX_UNIFORM_VECTORS=0x8DFB;
  13948. WebGLContext.MAX_VARYING_VECTORS=0x8DFC;
  13949. WebGLContext.MAX_COMBINED_TEXTURE_IMAGE_UNITS=0x8B4D;
  13950. WebGLContext.MAX_VERTEX_TEXTURE_IMAGE_UNITS=0x8B4C;
  13951. WebGLContext.MAX_TEXTURE_IMAGE_UNITS=0x8872;
  13952. WebGLContext.MAX_FRAGMENT_UNIFORM_VECTORS=0x8DFD;
  13953. WebGLContext.SHADER_TYPE=0x8B4F;
  13954. WebGLContext.DELETE_STATUS=0x8B80;
  13955. WebGLContext.LINK_STATUS=0x8B82;
  13956. WebGLContext.VALIDATE_STATUS=0x8B83;
  13957. WebGLContext.ATTACHED_SHADERS=0x8B85;
  13958. WebGLContext.ACTIVE_UNIFORMS=0x8B86;
  13959. WebGLContext.ACTIVE_ATTRIBUTES=0x8B89;
  13960. WebGLContext.SHADING_LANGUAGE_VERSION=0x8B8C;
  13961. WebGLContext.CURRENT_PROGRAM=0x8B8D;
  13962. WebGLContext.NEVER=0x0200;
  13963. WebGLContext.LESS=0x0201;
  13964. WebGLContext.EQUAL=0x0202;
  13965. WebGLContext.LEQUAL=0x0203;
  13966. WebGLContext.GREATER=0x0204;
  13967. WebGLContext.NOTEQUAL=0x0205;
  13968. WebGLContext.GEQUAL=0x0206;
  13969. WebGLContext.ALWAYS=0x0207;
  13970. WebGLContext.KEEP=0x1E00;
  13971. WebGLContext.REPLACE=0x1E01;
  13972. WebGLContext.INCR=0x1E02;
  13973. WebGLContext.DECR=0x1E03;
  13974. WebGLContext.INVERT=0x150A;
  13975. WebGLContext.INCR_WRAP=0x8507;
  13976. WebGLContext.DECR_WRAP=0x8508;
  13977. WebGLContext.VENDOR=0x1F00;
  13978. WebGLContext.RENDERER=0x1F01;
  13979. WebGLContext.VERSION=0x1F02;
  13980. WebGLContext.NEAREST=0x2600;
  13981. WebGLContext.LINEAR=0x2601;
  13982. WebGLContext.NEAREST_MIPMAP_NEAREST=0x2700;
  13983. WebGLContext.LINEAR_MIPMAP_NEAREST=0x2701;
  13984. WebGLContext.NEAREST_MIPMAP_LINEAR=0x2702;
  13985. WebGLContext.LINEAR_MIPMAP_LINEAR=0x2703;
  13986. WebGLContext.TEXTURE_MAG_FILTER=0x2800;
  13987. WebGLContext.TEXTURE_MIN_FILTER=0x2801;
  13988. WebGLContext.TEXTURE_WRAP_S=0x2802;
  13989. WebGLContext.TEXTURE_WRAP_T=0x2803;
  13990. WebGLContext.TEXTURE_2D=0x0DE1;
  13991. WebGLContext.TEXTURE_3D=0x806f;
  13992. WebGLContext.TEXTURE=0x1702;
  13993. WebGLContext.TEXTURE_CUBE_MAP=0x8513;
  13994. WebGLContext.TEXTURE_BINDING_CUBE_MAP=0x8514;
  13995. WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_X=0x8515;
  13996. WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_X=0x8516;
  13997. WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Y=0x8517;
  13998. WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Y=0x8518;
  13999. WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Z=0x8519;
  14000. WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Z=0x851A;
  14001. WebGLContext.MAX_CUBE_MAP_TEXTURE_SIZE=0x851C;
  14002. WebGLContext.TEXTURE0=0x84C0;
  14003. WebGLContext.TEXTURE1=0x84C1;
  14004. WebGLContext.TEXTURE2=0x84C2;
  14005. WebGLContext.TEXTURE3=0x84C3;
  14006. WebGLContext.TEXTURE4=0x84C4;
  14007. WebGLContext.TEXTURE5=0x84C5;
  14008. WebGLContext.TEXTURE6=0x84C6;
  14009. WebGLContext.TEXTURE7=0x84C7;
  14010. WebGLContext.TEXTURE8=0x84C8;
  14011. WebGLContext.TEXTURE9=0x84C9;
  14012. WebGLContext.TEXTURE10=0x84CA;
  14013. WebGLContext.TEXTURE11=0x84CB;
  14014. WebGLContext.TEXTURE12=0x84CC;
  14015. WebGLContext.TEXTURE13=0x84CD;
  14016. WebGLContext.TEXTURE14=0x84CE;
  14017. WebGLContext.TEXTURE15=0x84CF;
  14018. WebGLContext.TEXTURE16=0x84D0;
  14019. WebGLContext.TEXTURE17=0x84D1;
  14020. WebGLContext.TEXTURE18=0x84D2;
  14021. WebGLContext.TEXTURE19=0x84D3;
  14022. WebGLContext.TEXTURE20=0x84D4;
  14023. WebGLContext.TEXTURE21=0x84D5;
  14024. WebGLContext.TEXTURE22=0x84D6;
  14025. WebGLContext.TEXTURE23=0x84D7;
  14026. WebGLContext.TEXTURE24=0x84D8;
  14027. WebGLContext.TEXTURE25=0x84D9;
  14028. WebGLContext.TEXTURE26=0x84DA;
  14029. WebGLContext.TEXTURE27=0x84DB;
  14030. WebGLContext.TEXTURE28=0x84DC;
  14031. WebGLContext.TEXTURE29=0x84DD;
  14032. WebGLContext.TEXTURE30=0x84DE;
  14033. WebGLContext.TEXTURE31=0x84DF;
  14034. WebGLContext.ACTIVE_TEXTURE=0x84E0;
  14035. WebGLContext.REPEAT=0x2901;
  14036. WebGLContext.CLAMP_TO_EDGE=0x812F;
  14037. WebGLContext.MIRRORED_REPEAT=0x8370;
  14038. WebGLContext.FLOAT_VEC2=0x8B50;
  14039. WebGLContext.FLOAT_VEC3=0x8B51;
  14040. WebGLContext.FLOAT_VEC4=0x8B52;
  14041. WebGLContext.INT_VEC2=0x8B53;
  14042. WebGLContext.INT_VEC3=0x8B54;
  14043. WebGLContext.INT_VEC4=0x8B55;
  14044. WebGLContext.BOOL=0x8B56;
  14045. WebGLContext.BOOL_VEC2=0x8B57;
  14046. WebGLContext.BOOL_VEC3=0x8B58;
  14047. WebGLContext.BOOL_VEC4=0x8B59;
  14048. WebGLContext.FLOAT_MAT2=0x8B5A;
  14049. WebGLContext.FLOAT_MAT3=0x8B5B;
  14050. WebGLContext.FLOAT_MAT4=0x8B5C;
  14051. WebGLContext.SAMPLER_2D=0x8B5E;
  14052. WebGLContext.SAMPLER_CUBE=0x8B60;
  14053. WebGLContext.VERTEX_ATTRIB_ARRAY_ENABLED=0x8622;
  14054. WebGLContext.VERTEX_ATTRIB_ARRAY_SIZE=0x8623;
  14055. WebGLContext.VERTEX_ATTRIB_ARRAY_STRIDE=0x8624;
  14056. WebGLContext.VERTEX_ATTRIB_ARRAY_TYPE=0x8625;
  14057. WebGLContext.VERTEX_ATTRIB_ARRAY_NORMALIZED=0x886A;
  14058. WebGLContext.VERTEX_ATTRIB_ARRAY_POINTER=0x8645;
  14059. WebGLContext.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING=0x889F;
  14060. WebGLContext.COMPILE_STATUS=0x8B81;
  14061. WebGLContext.LOW_FLOAT=0x8DF0;
  14062. WebGLContext.MEDIUM_FLOAT=0x8DF1;
  14063. WebGLContext.HIGH_FLOAT=0x8DF2;
  14064. WebGLContext.LOW_INT=0x8DF3;
  14065. WebGLContext.MEDIUM_INT=0x8DF4;
  14066. WebGLContext.HIGH_INT=0x8DF5;
  14067. WebGLContext.FRAMEBUFFER=0x8D40;
  14068. WebGLContext.RENDERBUFFER=0x8D41;
  14069. WebGLContext.RGBA4=0x8056;
  14070. WebGLContext.RGB5_A1=0x8057;
  14071. WebGLContext.RGB565=0x8D62;
  14072. WebGLContext.DEPTH_COMPONENT16=0x81A5;
  14073. WebGLContext.STENCIL_INDEX=0x1901;
  14074. WebGLContext.STENCIL_INDEX8=0x8D48;
  14075. WebGLContext.DEPTH_STENCIL=0x84F9;
  14076. WebGLContext.RENDERBUFFER_WIDTH=0x8D42;
  14077. WebGLContext.RENDERBUFFER_HEIGHT=0x8D43;
  14078. WebGLContext.RENDERBUFFER_INTERNAL_FORMAT=0x8D44;
  14079. WebGLContext.RENDERBUFFER_RED_SIZE=0x8D50;
  14080. WebGLContext.RENDERBUFFER_GREEN_SIZE=0x8D51;
  14081. WebGLContext.RENDERBUFFER_BLUE_SIZE=0x8D52;
  14082. WebGLContext.RENDERBUFFER_ALPHA_SIZE=0x8D53;
  14083. WebGLContext.RENDERBUFFER_DEPTH_SIZE=0x8D54;
  14084. WebGLContext.RENDERBUFFER_STENCIL_SIZE=0x8D55;
  14085. WebGLContext.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE=0x8CD0;
  14086. WebGLContext.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME=0x8CD1;
  14087. WebGLContext.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL=0x8CD2;
  14088. WebGLContext.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE=0x8CD3;
  14089. WebGLContext.COLOR_ATTACHMENT0=0x8CE0;
  14090. WebGLContext.DEPTH_ATTACHMENT=0x8D00;
  14091. WebGLContext.STENCIL_ATTACHMENT=0x8D20;
  14092. WebGLContext.DEPTH_STENCIL_ATTACHMENT=0x821A;
  14093. WebGLContext.NONE=0;
  14094. WebGLContext.FRAMEBUFFER_COMPLETE=0x8CD5;
  14095. WebGLContext.FRAMEBUFFER_INCOMPLETE_ATTACHMENT=0x8CD6;
  14096. WebGLContext.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT=0x8CD7;
  14097. WebGLContext.FRAMEBUFFER_INCOMPLETE_DIMENSIONS=0x8CD9;
  14098. WebGLContext.FRAMEBUFFER_UNSUPPORTED=0x8CDD;
  14099. WebGLContext.FRAMEBUFFER_BINDING=0x8CA6;
  14100. WebGLContext.RENDERBUFFER_BINDING=0x8CA7;
  14101. WebGLContext.MAX_RENDERBUFFER_SIZE=0x84E8;
  14102. WebGLContext.INVALID_FRAMEBUFFER_OPERATION=0x0506;
  14103. WebGLContext.UNPACK_FLIP_Y_WEBGL=0x9240;
  14104. WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL=0x9241;
  14105. WebGLContext.CONTEXT_LOST_WEBGL=0x9242;
  14106. WebGLContext.UNPACK_COLORSPACE_CONVERSION_WEBGL=0x9243;
  14107. WebGLContext.BROWSER_DEFAULT_WEBGL=0x9244;
  14108. WebGLContext._extTextureFilterAnisotropic=null;
  14109. WebGLContext._compressedTextureS3tc=null;
  14110. WebGLContext._compressedTexturePvrtc=null;
  14111. WebGLContext._compressedTextureEtc1=null;
  14112. WebGLContext._angleInstancedArrays=null;
  14113. WebGLContext._glTextureIDs=[ /*CLASS CONST:laya.webgl.WebGLContext.TEXTURE0*/0x84C0,/*CLASS CONST:laya.webgl.WebGLContext.TEXTURE1*/0x84C1,/*CLASS CONST:laya.webgl.WebGLContext.TEXTURE2*/0x84C2,/*CLASS CONST:laya.webgl.WebGLContext.TEXTURE3*/0x84C3,/*CLASS CONST:laya.webgl.WebGLContext.TEXTURE4*/0x84C4,/*CLASS CONST:laya.webgl.WebGLContext.TEXTURE5*/0x84C5,/*CLASS CONST:laya.webgl.WebGLContext.TEXTURE6*/0x84C6,/*CLASS CONST:laya.webgl.WebGLContext.TEXTURE7*/0x84C7];
  14114. WebGLContext._useProgram=null;
  14115. WebGLContext._depthTest=true;
  14116. WebGLContext._depthMask=true;
  14117. WebGLContext._blend=false;
  14118. WebGLContext._cullFace=false;
  14119. WebGLContext._activedTextureID=0x84C0;
  14120. __static(WebGLContext,
  14121. ['_extentionVendorPrefixes',function(){return this._extentionVendorPrefixes=["","WEBKIT_","MOZ_"];},'_activeTextures',function(){return this._activeTextures=new Array(8);},'_depthFunc',function(){return this._depthFunc=/*CLASS CONST:laya.webgl.WebGLContext.LESS*/0x0201;},'_sFactor',function(){return this._sFactor=/*CLASS CONST:laya.webgl.WebGLContext.ONE*/1;},'_dFactor',function(){return this._dFactor=/*CLASS CONST:laya.webgl.WebGLContext.ZERO*/0;},'_srcAlpha',function(){return this._srcAlpha=/*CLASS CONST:laya.webgl.WebGLContext.ONE*/1;},'_dstAlpha',function(){return this._dstAlpha=/*CLASS CONST:laya.webgl.WebGLContext.ZERO*/0;},'_frontFace',function(){return this._frontFace=/*CLASS CONST:laya.webgl.WebGLContext.CCW*/0x0901;}
  14122. ]);
  14123. return WebGLContext;
  14124. })()
  14125. /**
  14126. *@private
  14127. */
  14128. //class laya.display.SpriteConst
  14129. var SpriteConst=(function(){
  14130. function SpriteConst(){}
  14131. __class(SpriteConst,'laya.display.SpriteConst');
  14132. SpriteConst.ALPHA=0x01;
  14133. SpriteConst.TRANSFORM=0x02;
  14134. SpriteConst.BLEND=0x04;
  14135. SpriteConst.CANVAS=0x08;
  14136. SpriteConst.FILTERS=0x10;
  14137. SpriteConst.MASK=0x20;
  14138. SpriteConst.CLIP=0x40;
  14139. SpriteConst.STYLE=0x80;
  14140. SpriteConst.TEXTURE=0x100;
  14141. SpriteConst.GRAPHICS=0x200;
  14142. SpriteConst.LAYAGL3D=0x400;
  14143. SpriteConst.CUSTOM=0x800;
  14144. SpriteConst.ONECHILD=0x1000;
  14145. SpriteConst.CHILDS=0x2000;
  14146. SpriteConst.REPAINT_NONE=0;
  14147. SpriteConst.REPAINT_NODE=0x01;
  14148. SpriteConst.REPAINT_CACHE=0x02;
  14149. SpriteConst.REPAINT_ALL=0x03;
  14150. return SpriteConst;
  14151. })()
  14152. /**
  14153. *绘制连续曲线
  14154. */
  14155. //class laya.display.cmd.DrawLinesCmd
  14156. var DrawLinesCmd=(function(){
  14157. function DrawLinesCmd(){
  14158. /**
  14159. *开始绘制的X轴位置。
  14160. */
  14161. //this.x=NaN;
  14162. /**
  14163. *开始绘制的Y轴位置。
  14164. */
  14165. //this.y=NaN;
  14166. /**
  14167. *线段的点集合。格式:[x1,y1,x2,y2,x3,y3...]。
  14168. */
  14169. //this.points=null;
  14170. /**
  14171. *线段颜色,或者填充绘图的渐变对象。
  14172. */
  14173. //this.lineColor=null;
  14174. /**
  14175. *(可选)线段宽度。
  14176. */
  14177. //this.lineWidth=NaN;
  14178. /**@private */
  14179. //this.vid=0;
  14180. }
  14181. __class(DrawLinesCmd,'laya.display.cmd.DrawLinesCmd');
  14182. var __proto=DrawLinesCmd.prototype;
  14183. /**
  14184. *回收到对象池
  14185. */
  14186. __proto.recover=function(){
  14187. this.points=null;
  14188. this.lineColor=null;
  14189. Pool.recover("DrawLinesCmd",this);
  14190. }
  14191. /**@private */
  14192. __proto.run=function(context,gx,gy){
  14193. context._drawLines(this.x+gx,this.y+gy,this.points,this.lineColor,this.lineWidth,this.vid);
  14194. }
  14195. /**@private */
  14196. __getset(0,__proto,'cmdID',function(){
  14197. return "DrawLines";
  14198. });
  14199. DrawLinesCmd.create=function(x,y,points,lineColor,lineWidth,vid){
  14200. var cmd=Pool.getItemByClass("DrawLinesCmd",DrawLinesCmd);
  14201. cmd.x=x;
  14202. cmd.y=y;
  14203. cmd.points=points;
  14204. cmd.lineColor=lineColor;
  14205. cmd.lineWidth=lineWidth;
  14206. cmd.vid=vid;
  14207. return cmd;
  14208. }
  14209. DrawLinesCmd.ID="DrawLines";
  14210. return DrawLinesCmd;
  14211. })()
  14212. /**
  14213. *@private
  14214. *凸包算法。
  14215. */
  14216. //class laya.maths.GrahamScan
  14217. var GrahamScan=(function(){
  14218. function GrahamScan(){}
  14219. __class(GrahamScan,'laya.maths.GrahamScan');
  14220. GrahamScan.multiply=function(p1,p2,p0){
  14221. return ((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));
  14222. }
  14223. GrahamScan.dis=function(p1,p2){
  14224. return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
  14225. }
  14226. GrahamScan._getPoints=function(count,tempUse,rst){
  14227. (tempUse===void 0)&& (tempUse=false);
  14228. if (!GrahamScan._mPointList)GrahamScan._mPointList=[];
  14229. while (GrahamScan._mPointList.length < count)GrahamScan._mPointList.push(new Point());
  14230. if (!rst)rst=[];
  14231. rst.length=0;
  14232. if (tempUse){
  14233. GrahamScan.getFrom(rst,GrahamScan._mPointList,count);
  14234. }else {
  14235. GrahamScan.getFromR(rst,GrahamScan._mPointList,count);
  14236. }
  14237. return rst;
  14238. }
  14239. GrahamScan.getFrom=function(rst,src,count){
  14240. var i=0;
  14241. for (i=0;i < count;i++){
  14242. rst.push(src[i]);
  14243. }
  14244. return rst;
  14245. }
  14246. GrahamScan.getFromR=function(rst,src,count){
  14247. var i=0;
  14248. for (i=0;i < count;i++){
  14249. rst.push(src.pop());
  14250. }
  14251. return rst;
  14252. }
  14253. GrahamScan.pListToPointList=function(pList,tempUse){
  14254. (tempUse===void 0)&& (tempUse=false);
  14255. var i=0,len=pList.length / 2,rst=GrahamScan._getPoints(len,tempUse,GrahamScan._tempPointList);
  14256. for (i=0;i < len;i++){
  14257. rst[i].setTo(pList[i+i],pList[i+i+1]);
  14258. }
  14259. return rst;
  14260. }
  14261. GrahamScan.pointListToPlist=function(pointList){
  14262. var i=0,len=pointList.length,rst=GrahamScan._temPList,tPoint;
  14263. rst.length=0;
  14264. for (i=0;i < len;i++){
  14265. tPoint=pointList[i];
  14266. rst.push(tPoint.x,tPoint.y);
  14267. }
  14268. return rst;
  14269. }
  14270. GrahamScan.scanPList=function(pList){
  14271. return Utils.copyArray(pList,GrahamScan.pointListToPlist(GrahamScan.scan(GrahamScan.pListToPointList(pList,true))));
  14272. }
  14273. GrahamScan.scan=function(PointSet){
  14274. var i=0,j=0,k=0,top=2,tmp,n=PointSet.length,ch;
  14275. var _tmpDic={};
  14276. var key;
  14277. ch=GrahamScan._temArr;
  14278. ch.length=0;
  14279. n=PointSet.length;
  14280. for (i=n-1;i >=0;i--){
  14281. tmp=PointSet[i];
  14282. key=tmp.x+"_"+tmp.y;
  14283. if (!_tmpDic.hasOwnProperty(key)){
  14284. _tmpDic[key]=true;
  14285. ch.push(tmp);
  14286. }
  14287. }
  14288. n=ch.length;
  14289. Utils.copyArray(PointSet,ch);
  14290. for (i=1;i < n;i++)
  14291. if ((PointSet[i].y < PointSet[k].y)|| ((PointSet[i].y==PointSet[k].y)&& (PointSet[i].x < PointSet[k].x)))
  14292. k=i;
  14293. tmp=PointSet[0];
  14294. PointSet[0]=PointSet[k];
  14295. PointSet[k]=tmp;
  14296. for (i=1;i < n-1;i++){
  14297. k=i;
  14298. for (j=i+1;j < n;j++)
  14299. if ((GrahamScan.multiply(PointSet[j],PointSet[k],PointSet[0])> 0)|| ((GrahamScan.multiply(PointSet[j],PointSet[k],PointSet[0])==0)&& (GrahamScan.dis(PointSet[0],PointSet[j])< GrahamScan.dis(PointSet[0],PointSet[k]))))
  14300. k=j;
  14301. tmp=PointSet[i];
  14302. PointSet[i]=PointSet[k];
  14303. PointSet[k]=tmp;
  14304. }
  14305. ch=GrahamScan._temArr;
  14306. ch.length=0;
  14307. if (PointSet.length < 3){
  14308. return Utils.copyArray(ch,PointSet);
  14309. }
  14310. ch.push(PointSet[0],PointSet[1],PointSet[2]);
  14311. for (i=3;i < n;i++){
  14312. while (ch.length >=2 && GrahamScan.multiply(PointSet[i],ch[ch.length-1],ch[ch.length-2])>=0)ch.pop();
  14313. PointSet[i] && ch.push(PointSet[i]);
  14314. }
  14315. return ch;
  14316. }
  14317. GrahamScan._mPointList=null;
  14318. GrahamScan._tempPointList=[];
  14319. GrahamScan._temPList=[];
  14320. GrahamScan._temArr=[];
  14321. return GrahamScan;
  14322. })()
  14323. /**
  14324. *@private
  14325. */
  14326. //class laya.utils.WordText
  14327. var WordText=(function(){
  14328. function WordText(){
  14329. //TODO:
  14330. this.id=NaN;
  14331. this.save=[];
  14332. this.toUpperCase=null;
  14333. this.changed=false;
  14334. this._text=null;
  14335. this.width=-1;
  14336. //整个WordText的长度。-1表示没有计算还。
  14337. this.pageChars=[];
  14338. //把本对象的字符按照texture分组保存的文字信息。里面又是一个数组。具体含义见使用的地方。
  14339. this.startID=0;
  14340. //上面的是个数组,但是可能前面都是空的,加个起始位置
  14341. this.startIDStroke=0;
  14342. this.lastGCCnt=0;
  14343. //如果文字gc了,需要检查缓存是否有效,这里记录上次检查对应的gc值。
  14344. this.splitRender=false;
  14345. }
  14346. __class(WordText,'laya.utils.WordText');
  14347. var __proto=WordText.prototype;
  14348. // 强制拆分渲染
  14349. __proto.setText=function(txt){
  14350. this.changed=true;
  14351. this._text=txt;
  14352. this.width=-1;
  14353. this.cleanCache();
  14354. }
  14355. //TODO:coverage
  14356. __proto.toString=function(){
  14357. return this._text;
  14358. }
  14359. //TODO:coverage
  14360. __proto.charCodeAt=function(i){
  14361. return this._text ? this._text.charCodeAt(i):NaN;
  14362. }
  14363. //TODO:coverage
  14364. __proto.charAt=function(i){
  14365. return this._text ? this._text.charAt(i):null;
  14366. }
  14367. /**
  14368. *自己主动清理缓存,需要把关联的贴图删掉
  14369. *不做也可以,textrender会自动清理不用的
  14370. *TODO 重用
  14371. */
  14372. __proto.cleanCache=function(){
  14373. this.pageChars.forEach(function(p){
  14374. var tex=p.tex;
  14375. var words=p.words;
  14376. if (p.words.length==1 && tex && tex.ri){
  14377. tex.destroy();
  14378. }
  14379. });
  14380. this.pageChars=[];
  14381. this.startID=0;
  14382. }
  14383. __getset(0,__proto,'length',function(){
  14384. return this._text ? this._text.length :0;
  14385. });
  14386. return WordText;
  14387. })()
  14388. //class laya.webgl.canvas.save.SaveTransform
  14389. var SaveTransform=(function(){
  14390. function SaveTransform(){
  14391. //this._savematrix=null;
  14392. this._matrix=new Matrix();
  14393. }
  14394. __class(SaveTransform,'laya.webgl.canvas.save.SaveTransform');
  14395. var __proto=SaveTransform.prototype;
  14396. Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true})
  14397. __proto.isSaveMark=function(){return false;}
  14398. __proto.restore=function(context){
  14399. context._curMat=this._savematrix;
  14400. SaveTransform.POOL[SaveTransform.POOL._length++]=this;
  14401. }
  14402. SaveTransform.save=function(context){
  14403. var _saveMark=context._saveMark;
  14404. if ((_saveMark._saveuse & /*laya.webgl.canvas.save.SaveBase.TYPE_TRANSFORM*/0x800)===/*laya.webgl.canvas.save.SaveBase.TYPE_TRANSFORM*/0x800)return;
  14405. _saveMark._saveuse |=/*laya.webgl.canvas.save.SaveBase.TYPE_TRANSFORM*/0x800;
  14406. var no=SaveTransform.POOL;
  14407. var o=no._length > 0 ? no[--no._length] :(new SaveTransform());
  14408. o._savematrix=context._curMat;
  14409. context._curMat=context._curMat.copyTo(o._matrix);
  14410. var _save=context._save;
  14411. _save[_save._length++]=o;
  14412. }
  14413. SaveTransform.POOL=SaveBase._createArray();
  14414. return SaveTransform;
  14415. })()
  14416. /**
  14417. *@private
  14418. *<code>ShaderCompile</code> 类用于实现Shader编译。
  14419. */
  14420. //class laya.webgl.utils.ShaderCompile
  14421. var ShaderCompile=(function(){
  14422. function ShaderCompile(vs,ps,nameMap,defs){
  14423. //this._nameMap=null;
  14424. //this._VS=null;
  14425. //this._PS=null;
  14426. this._clearCR=new RegExp("\r","g");
  14427. var _$this=this;
  14428. function _compile (script){
  14429. script=script.replace(_$this._clearCR,"");
  14430. var includefiles=[];
  14431. var top=new ShaderNode(includefiles);
  14432. _$this._compileToTree(top,script.split('\n'),0,includefiles,defs);
  14433. return top;
  14434. };
  14435. var startTime=Browser.now();
  14436. this._VS=_compile(vs);
  14437. this._PS=_compile(ps);
  14438. this._nameMap=nameMap;
  14439. if ((Browser.now()-startTime)> 2)
  14440. console.log("ShaderCompile use time:"+(Browser.now()-startTime)+" size:"+vs.length+"/"+ps.length);
  14441. }
  14442. __class(ShaderCompile,'laya.webgl.utils.ShaderCompile');
  14443. var __proto=ShaderCompile.prototype;
  14444. /**
  14445. *@private
  14446. */
  14447. __proto._compileToTree=function(parent,lines,start,includefiles,defs){
  14448. var node,preNode;
  14449. var text,name,fname;
  14450. var ofs=0,words,noUseNode;
  14451. var i=0,n=0,j=0;
  14452. for (i=start;i < lines.length;i++){
  14453. text=lines[i];
  14454. if (text.length < 1)continue ;
  14455. ofs=text.indexOf("//");
  14456. if (ofs===0)continue ;
  14457. if (ofs >=0)text=text.substr(0,ofs);
  14458. node=noUseNode || new ShaderNode(includefiles);
  14459. noUseNode=null;
  14460. node.text=text;
  14461. node.noCompile=true;
  14462. if ((ofs=text.indexOf("#"))>=0){
  14463. name="#";
  14464. for (j=ofs+1,n=text.length;j < n;j++){
  14465. var c=text.charAt(j);
  14466. if (c===' ' || c==='\t' || c==='?')break ;
  14467. name+=c;
  14468. }
  14469. node.name=name;
  14470. switch (name){
  14471. case "#ifdef":
  14472. case "#ifndef":
  14473. node.src=text;
  14474. node.noCompile=text.match(/[!&|()=<>]/)!=null;
  14475. if (!node.noCompile){
  14476. words=text.replace(/^\s*/,'').split(/\s+/);
  14477. node.setCondition(words[1],name==="#ifdef" ? 1 :2);
  14478. node.text="//"+node.text;
  14479. }else {
  14480. console.log("function():Boolean{return "+text.substr(ofs+node.name.length)+"}");
  14481. }
  14482. node.setParent(parent);
  14483. parent=node;
  14484. if (defs){
  14485. words=text.substr(j).split(ShaderCompile._splitToWordExps3);
  14486. for (j=0;j < words.length;j++){
  14487. text=words[j];
  14488. text.length && (defs[text]=true);
  14489. }
  14490. }
  14491. continue ;
  14492. case "#if":
  14493. node.src=text;
  14494. node.noCompile=true;
  14495. node.setParent(parent);
  14496. parent=node;
  14497. if (defs){
  14498. words=text.substr(j).split(ShaderCompile._splitToWordExps3);
  14499. for (j=0;j < words.length;j++){
  14500. text=words[j];
  14501. text.length && text !="defined" && (defs[text]=true);
  14502. }
  14503. }
  14504. continue ;
  14505. case "#else":
  14506. node.src=text;
  14507. parent=parent.parent;
  14508. preNode=parent.childs[parent.childs.length-1];
  14509. node.noCompile=preNode.noCompile;
  14510. if (!node.noCompile){
  14511. node.condition=preNode.condition;
  14512. node.conditionType=preNode.conditionType==1 ? 2 :1;
  14513. node.text="//"+node.text+" "+preNode.text+" "+node.conditionType;
  14514. }
  14515. node.setParent(parent);
  14516. parent=node;
  14517. continue ;
  14518. case "#endif":
  14519. parent=parent.parent;
  14520. preNode=parent.childs[parent.childs.length-1];
  14521. node.noCompile=preNode.noCompile;
  14522. if (!node.noCompile){
  14523. node.text="//"+node.text;
  14524. }
  14525. node.setParent(parent);
  14526. continue ;
  14527. case "#include":
  14528. words=ShaderCompile.splitToWords(text,null);
  14529. var inlcudeFile=ShaderCompile.includes[words[1]];
  14530. if (!inlcudeFile){
  14531. throw "ShaderCompile error no this include file:"+words[1];
  14532. }
  14533. if ((ofs=words[0].indexOf("?"))< 0){
  14534. node.setParent(parent);
  14535. text=inlcudeFile.getWith(words[2]=='with' ? words[3] :null);
  14536. this._compileToTree(node,text.split('\n'),0,includefiles,defs);
  14537. node.text="";
  14538. continue ;
  14539. }
  14540. node.setCondition(words[0].substr(ofs+1),1);
  14541. node.text=inlcudeFile.getWith(words[2]=='with' ? words[3] :null);
  14542. break ;
  14543. case "#import":
  14544. words=ShaderCompile.splitToWords(text,null);
  14545. fname=words[1];
  14546. includefiles.push({node:node,file:ShaderCompile.includes[fname],ofs:node.text.length});
  14547. continue ;
  14548. }
  14549. }else {
  14550. preNode=parent.childs[parent.childs.length-1];
  14551. if (preNode && !preNode.name){
  14552. includefiles.length > 0 && ShaderCompile.splitToWords(text,preNode);
  14553. noUseNode=node;
  14554. preNode.text+="\n"+text;
  14555. continue ;
  14556. }
  14557. includefiles.length > 0 && ShaderCompile.splitToWords(text,node);
  14558. }
  14559. node.setParent(parent);
  14560. }
  14561. }
  14562. __proto.createShader=function(define,shaderName,createShader,bindAttrib){
  14563. var defMap={};
  14564. var defineStr="";
  14565. if (define){
  14566. for (var i in define){
  14567. defineStr+="#define "+i+"\n";
  14568. defMap[i]=true;
  14569. }
  14570. };
  14571. var vs=this._VS.toscript(defMap,[]);
  14572. var ps=this._PS.toscript(defMap,[]);
  14573. return (createShader || Shader.create)(defineStr+vs.join('\n'),defineStr+ps.join('\n'),shaderName,this._nameMap,bindAttrib);
  14574. }
  14575. ShaderCompile._parseOne=function(attributes,uniforms,words,i,word,b){
  14576. var one={type:ShaderCompile.shaderParamsMap[words[i+1]],name:words[i+2],size:isNaN(parseInt(words[i+3]))? 1 :parseInt(words[i+3])};
  14577. if (b){
  14578. if (word=="attribute"){
  14579. attributes.push(one);
  14580. }else {
  14581. uniforms.push(one);
  14582. }
  14583. }
  14584. if (words[i+3]==':'){
  14585. one.type=words[i+4];
  14586. i+=2;
  14587. }
  14588. i+=2;
  14589. return i;
  14590. }
  14591. ShaderCompile.addInclude=function(fileName,txt){
  14592. if (!txt || txt.length===0)
  14593. throw new Error("add shader include file err:"+fileName);
  14594. if (ShaderCompile.includes[fileName])
  14595. throw new Error("add shader include file err, has add:"+fileName);
  14596. ShaderCompile.includes[fileName]=new InlcudeFile(txt);
  14597. }
  14598. ShaderCompile.preGetParams=function(vs,ps){
  14599. var text=[vs,ps];
  14600. var result={};
  14601. var attributes=[];
  14602. var uniforms=[];
  14603. var definesInfo={};
  14604. var definesName=[];
  14605. result.attributes=attributes;
  14606. result.uniforms=uniforms;
  14607. result.defines=definesInfo;
  14608. var i=0,n=0,one;
  14609. for (var s=0;s < 2;s++){
  14610. text[s]=text[s].replace(ShaderCompile._removeAnnotation,"");
  14611. var words=text[s].match(ShaderCompile._reg);
  14612. var tempelse;
  14613. for (i=0,n=words.length;i < n;i++){
  14614. var word=words[i];
  14615. if (word !="attribute" && word !="uniform"){
  14616. if (word=="#define"){
  14617. word=words[++i];
  14618. definesName[word]=1;
  14619. continue ;
  14620. }else if (word=="#ifdef"){
  14621. tempelse=words[++i];
  14622. var def=definesInfo[tempelse]=definesInfo[tempelse] || [];
  14623. for (i++;i < n;i++){
  14624. word=words[i];
  14625. if (word !="attribute" && word !="uniform"){
  14626. if (word=="#else"){
  14627. for (i++;i < n;i++){
  14628. word=words[i];
  14629. if (word !="attribute" && word !="uniform"){
  14630. if (word=="#endif"){
  14631. break ;
  14632. }
  14633. continue ;
  14634. }
  14635. i=ShaderCompile._parseOne(attributes,uniforms,words,i,word,!definesName[tempelse]);
  14636. }
  14637. }
  14638. continue ;
  14639. }
  14640. i=ShaderCompile._parseOne(attributes,uniforms,words,i,word,definesName[tempelse]);
  14641. }
  14642. }
  14643. continue ;
  14644. }
  14645. i=ShaderCompile._parseOne(attributes,uniforms,words,i,word,true);
  14646. }
  14647. }
  14648. return result;
  14649. }
  14650. ShaderCompile.splitToWords=function(str,block){
  14651. var out=[];
  14652. var c;
  14653. var ofs=-1;
  14654. var word;
  14655. for (var i=0,n=str.length;i < n;i++){
  14656. c=str.charAt(i);
  14657. if (" \t=+-*/&%!<>()'\",;".indexOf(c)>=0){
  14658. if (ofs >=0 && (i-ofs)> 1){
  14659. word=str.substr(ofs,i-ofs);
  14660. out.push(word);
  14661. }
  14662. if (c=='"' || c=="'"){
  14663. var ofs2=str.indexOf(c,i+1);
  14664. if (ofs2 < 0){
  14665. throw "Sharder err:"+str;
  14666. }
  14667. out.push(str.substr(i+1,ofs2-i-1));
  14668. i=ofs2;
  14669. ofs=-1;
  14670. continue ;
  14671. }
  14672. if (c=='(' && block && out.length > 0){
  14673. word=out[out.length-1]+";";
  14674. if ("vec4;main;".indexOf(word)< 0)
  14675. block.useFuns+=word;
  14676. }
  14677. ofs=-1;
  14678. continue ;
  14679. }
  14680. if (ofs < 0)ofs=i;
  14681. }
  14682. if (ofs < n && (n-ofs)> 1){
  14683. word=str.substr(ofs,n-ofs);
  14684. out.push(word);
  14685. }
  14686. return out;
  14687. }
  14688. ShaderCompile.IFDEF_NO=0;
  14689. ShaderCompile.IFDEF_YES=1;
  14690. ShaderCompile.IFDEF_ELSE=2;
  14691. ShaderCompile.IFDEF_PARENT=3;
  14692. ShaderCompile._removeAnnotation=new RegExp("(/\\*([^*]|[\\r\\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/)|(//.*)","g");
  14693. ShaderCompile._reg=new RegExp("(\".*\")|('.*')|([#\\w\\*-\\.+/()=<>{}\\\\]+)|([,;:\\\\])","g");
  14694. ShaderCompile._splitToWordExps=new RegExp("[(\".*\")]+|[('.*')]+|([ \\t=\\+\\-*/&%!<>!%\(\),;])","g");
  14695. ShaderCompile.includes={};
  14696. __static(ShaderCompile,
  14697. ['shaderParamsMap',function(){return this.shaderParamsMap={"float":/*laya.webgl.WebGLContext.FLOAT*/0x1406,"int":/*laya.webgl.WebGLContext.INT*/0x1404,"bool":/*laya.webgl.WebGLContext.BOOL*/0x8B56,"vec2":/*laya.webgl.WebGLContext.FLOAT_VEC2*/0x8B50,"vec3":/*laya.webgl.WebGLContext.FLOAT_VEC3*/0x8B51,"vec4":/*laya.webgl.WebGLContext.FLOAT_VEC4*/0x8B52,"ivec2":/*laya.webgl.WebGLContext.INT_VEC2*/0x8B53,"ivec3":/*laya.webgl.WebGLContext.INT_VEC3*/0x8B54,"ivec4":/*laya.webgl.WebGLContext.INT_VEC4*/0x8B55,"bvec2":/*laya.webgl.WebGLContext.BOOL_VEC2*/0x8B57,"bvec3":/*laya.webgl.WebGLContext.BOOL_VEC3*/0x8B58,"bvec4":/*laya.webgl.WebGLContext.BOOL_VEC4*/0x8B59,"mat2":/*laya.webgl.WebGLContext.FLOAT_MAT2*/0x8B5A,"mat3":/*laya.webgl.WebGLContext.FLOAT_MAT3*/0x8B5B,"mat4":/*laya.webgl.WebGLContext.FLOAT_MAT4*/0x8B5C,"sampler2D":/*laya.webgl.WebGLContext.SAMPLER_2D*/0x8B5E,"samplerCube":/*laya.webgl.WebGLContext.SAMPLER_CUBE*/0x8B60};},'_splitToWordExps3',function(){return this._splitToWordExps3=new RegExp("[ \\t=\\+\\-*/&%!<>!%\(\),;\\|]","g");}
  14698. ]);
  14699. return ShaderCompile;
  14700. })()
  14701. /**
  14702. *@private
  14703. *基于个数的对象缓存管理器
  14704. */
  14705. //class laya.utils.PoolCache
  14706. var PoolCache=(function(){
  14707. function PoolCache(){
  14708. /**
  14709. *对象在Pool中的标识
  14710. */
  14711. this.sign=null;
  14712. /**
  14713. *允许缓存的最大数量
  14714. */
  14715. this.maxCount=1000;
  14716. }
  14717. __class(PoolCache,'laya.utils.PoolCache');
  14718. var __proto=PoolCache.prototype;
  14719. /**
  14720. *获取缓存的对象列表
  14721. *@return
  14722. *
  14723. */
  14724. __proto.getCacheList=function(){
  14725. return Pool.getPoolBySign(this.sign);
  14726. }
  14727. /**
  14728. *尝试清理缓存
  14729. *@param force 是否强制清理
  14730. *
  14731. */
  14732. __proto.tryDispose=function(force){
  14733. var list;
  14734. list=Pool.getPoolBySign(this.sign);
  14735. if (list.length > this.maxCount){
  14736. list.splice(this.maxCount,list.length-this.maxCount);
  14737. }
  14738. }
  14739. PoolCache.addPoolCacheManager=function(sign,maxCount){
  14740. (maxCount===void 0)&& (maxCount=100);
  14741. var cache;
  14742. cache=new PoolCache();
  14743. cache.sign=sign;
  14744. cache.maxCount=maxCount;
  14745. CacheManger.regCacheByFunction(Utils.bind(cache.tryDispose,cache),Utils.bind(cache.getCacheList,cache));
  14746. }
  14747. return PoolCache;
  14748. })()
  14749. /**
  14750. *裁剪命令
  14751. */
  14752. //class laya.display.cmd.ClipRectCmd
  14753. var ClipRectCmd=(function(){
  14754. function ClipRectCmd(){
  14755. /**
  14756. *X 轴偏移量。
  14757. */
  14758. //this.x=NaN;
  14759. /**
  14760. *Y 轴偏移量。
  14761. */
  14762. //this.y=NaN;
  14763. /**
  14764. *宽度。
  14765. */
  14766. //this.width=NaN;
  14767. /**
  14768. *高度。
  14769. */
  14770. //this.height=NaN;
  14771. }
  14772. __class(ClipRectCmd,'laya.display.cmd.ClipRectCmd');
  14773. var __proto=ClipRectCmd.prototype;
  14774. /**
  14775. *回收到对象池
  14776. */
  14777. __proto.recover=function(){
  14778. Pool.recover("ClipRectCmd",this);
  14779. }
  14780. /**@private */
  14781. __proto.run=function(context,gx,gy){
  14782. context.clipRect(this.x+gx,this.y+gy,this.width,this.height);
  14783. }
  14784. /**@private */
  14785. __getset(0,__proto,'cmdID',function(){
  14786. return "ClipRect";
  14787. });
  14788. ClipRectCmd.create=function(x,y,width,height){
  14789. var cmd=Pool.getItemByClass("ClipRectCmd",ClipRectCmd);
  14790. cmd.x=x;
  14791. cmd.y=y;
  14792. cmd.width=width;
  14793. cmd.height=height;
  14794. return cmd;
  14795. }
  14796. ClipRectCmd.ID="ClipRect";
  14797. return ClipRectCmd;
  14798. })()
  14799. //class laya.webgl.shader.ShaderValue
  14800. var ShaderValue=(function(){
  14801. function ShaderValue(){}
  14802. __class(ShaderValue,'laya.webgl.shader.ShaderValue');
  14803. return ShaderValue;
  14804. })()
  14805. /**
  14806. *绘制多边形
  14807. */
  14808. //class laya.display.cmd.DrawPolyCmd
  14809. var DrawPolyCmd=(function(){
  14810. function DrawPolyCmd(){
  14811. /**
  14812. *开始绘制的 X 轴位置。
  14813. */
  14814. //this.x=NaN;
  14815. /**
  14816. *开始绘制的 Y 轴位置。
  14817. */
  14818. //this.y=NaN;
  14819. /**
  14820. *多边形的点集合。
  14821. */
  14822. //this.points=null;
  14823. /**
  14824. *填充颜色,或者填充绘图的渐变对象。
  14825. */
  14826. //this.fillColor=null;
  14827. /**
  14828. *(可选)边框颜色,或者填充绘图的渐变对象。
  14829. */
  14830. //this.lineColor=null;
  14831. /**
  14832. *可选)边框宽度。
  14833. */
  14834. //this.lineWidth=NaN;
  14835. /**@private */
  14836. //this.isConvexPolygon=false;
  14837. /**@private */
  14838. //this.vid=0;
  14839. }
  14840. __class(DrawPolyCmd,'laya.display.cmd.DrawPolyCmd');
  14841. var __proto=DrawPolyCmd.prototype;
  14842. /**
  14843. *回收到对象池
  14844. */
  14845. __proto.recover=function(){
  14846. this.points=null;
  14847. this.fillColor=null;
  14848. this.lineColor=null;
  14849. Pool.recover("DrawPolyCmd",this);
  14850. }
  14851. /**@private */
  14852. __proto.run=function(context,gx,gy){
  14853. context._drawPoly(this.x+gx,this.y+gy,this.points,this.fillColor,this.lineColor,this.lineWidth,this.isConvexPolygon,this.vid);
  14854. }
  14855. /**@private */
  14856. __getset(0,__proto,'cmdID',function(){
  14857. return "DrawPoly";
  14858. });
  14859. DrawPolyCmd.create=function(x,y,points,fillColor,lineColor,lineWidth,isConvexPolygon,vid){
  14860. var cmd=Pool.getItemByClass("DrawPolyCmd",DrawPolyCmd);
  14861. cmd.x=x;
  14862. cmd.y=y;
  14863. cmd.points=points;
  14864. cmd.fillColor=fillColor;
  14865. cmd.lineColor=lineColor;
  14866. cmd.lineWidth=lineWidth;
  14867. cmd.isConvexPolygon=isConvexPolygon;
  14868. cmd.vid=vid;
  14869. return cmd;
  14870. }
  14871. DrawPolyCmd.ID="DrawPoly";
  14872. return DrawPolyCmd;
  14873. })()
  14874. /**
  14875. *@private
  14876. *<code>MathUtil</code> 是一个数据处理工具类。
  14877. */
  14878. //class laya.maths.MathUtil
  14879. var MathUtil=(function(){
  14880. function MathUtil(){}
  14881. __class(MathUtil,'laya.maths.MathUtil');
  14882. MathUtil.subtractVector3=function(l,r,o){
  14883. o[0]=l[0]-r[0];
  14884. o[1]=l[1]-r[1];
  14885. o[2]=l[2]-r[2];
  14886. }
  14887. MathUtil.lerp=function(left,right,amount){
  14888. return left *(1-amount)+right *amount;
  14889. }
  14890. MathUtil.scaleVector3=function(f,b,e){
  14891. e[0]=f[0] *b;
  14892. e[1]=f[1] *b;
  14893. e[2]=f[2] *b;
  14894. }
  14895. MathUtil.lerpVector3=function(l,r,t,o){
  14896. var ax=l[0],ay=l[1],az=l[2];
  14897. o[0]=ax+t *(r[0]-ax);
  14898. o[1]=ay+t *(r[1]-ay);
  14899. o[2]=az+t *(r[2]-az);
  14900. }
  14901. MathUtil.lerpVector4=function(l,r,t,o){
  14902. var ax=l[0],ay=l[1],az=l[2],aw=l[3];
  14903. o[0]=ax+t *(r[0]-ax);
  14904. o[1]=ay+t *(r[1]-ay);
  14905. o[2]=az+t *(r[2]-az);
  14906. o[3]=aw+t *(r[3]-aw);
  14907. }
  14908. MathUtil.slerpQuaternionArray=function(a,Offset1,b,Offset2,t,out,Offset3){
  14909. var ax=a[Offset1+0],ay=a[Offset1+1],az=a[Offset1+2],aw=a[Offset1+3],bx=b[Offset2+0],by=b[Offset2+1],bz=b[Offset2+2],bw=b[Offset2+3];
  14910. var omega,cosom,sinom,scale0,scale1;
  14911. cosom=ax *bx+ay *by+az *bz+aw *bw;
  14912. if (cosom < 0.0){
  14913. cosom=-cosom;
  14914. bx=-bx;
  14915. by=-by;
  14916. bz=-bz;
  14917. bw=-bw;
  14918. }
  14919. if ((1.0-cosom)> 0.000001){
  14920. omega=Math.acos(cosom);
  14921. sinom=Math.sin(omega);
  14922. scale0=Math.sin((1.0-t)*omega)/ sinom;
  14923. scale1=Math.sin(t *omega)/ sinom;
  14924. }else {
  14925. scale0=1.0-t;
  14926. scale1=t;
  14927. }
  14928. out[Offset3+0]=scale0 *ax+scale1 *bx;
  14929. out[Offset3+1]=scale0 *ay+scale1 *by;
  14930. out[Offset3+2]=scale0 *az+scale1 *bz;
  14931. out[Offset3+3]=scale0 *aw+scale1 *bw;
  14932. return out;
  14933. }
  14934. MathUtil.getRotation=function(x0,y0,x1,y1){
  14935. return Math.atan2(y1-y0,x1-x0)/ Math.PI *180;
  14936. }
  14937. MathUtil.sortBigFirst=function(a,b){
  14938. if (a==b)return 0;
  14939. return b > a ? 1 :-1;
  14940. }
  14941. MathUtil.sortSmallFirst=function(a,b){
  14942. if (a==b)return 0;
  14943. return b > a ?-1 :1;
  14944. }
  14945. MathUtil.sortNumBigFirst=function(a,b){
  14946. return parseFloat(b)-parseFloat(a);
  14947. }
  14948. MathUtil.sortNumSmallFirst=function(a,b){
  14949. return parseFloat(a)-parseFloat(b);
  14950. }
  14951. MathUtil.sortByKey=function(key,bigFirst,forceNum){
  14952. (bigFirst===void 0)&& (bigFirst=false);
  14953. (forceNum===void 0)&& (forceNum=true);
  14954. var _sortFun;
  14955. if (bigFirst){
  14956. _sortFun=forceNum ? MathUtil.sortNumBigFirst :MathUtil.sortBigFirst;
  14957. }else {
  14958. _sortFun=forceNum ? MathUtil.sortNumSmallFirst :MathUtil.sortSmallFirst;
  14959. }
  14960. return function (a,b){
  14961. return _sortFun(a[key],b[key]);
  14962. }
  14963. }
  14964. return MathUtil;
  14965. })()
  14966. /**
  14967. *恢复命令,和save配套使用
  14968. */
  14969. //class laya.display.cmd.RestoreCmd
  14970. var RestoreCmd=(function(){
  14971. function RestoreCmd(){}
  14972. __class(RestoreCmd,'laya.display.cmd.RestoreCmd');
  14973. var __proto=RestoreCmd.prototype;
  14974. /**
  14975. *回收到对象池
  14976. */
  14977. __proto.recover=function(){
  14978. Pool.recover("RestoreCmd",this);
  14979. }
  14980. /**@private */
  14981. __proto.run=function(context,gx,gy){
  14982. context.restore();
  14983. }
  14984. /**@private */
  14985. __getset(0,__proto,'cmdID',function(){
  14986. return "Restore";
  14987. });
  14988. RestoreCmd.create=function(){
  14989. var cmd=Pool.getItemByClass("RestoreCmd",RestoreCmd);
  14990. return cmd;
  14991. }
  14992. RestoreCmd.ID="Restore";
  14993. return RestoreCmd;
  14994. })()
  14995. /**
  14996. *<p> <code>Pool</code> 是对象池类,用于对象的存储、重复使用。</p>
  14997. *<p>合理使用对象池,可以有效减少对象创建的开销,避免频繁的垃圾回收,从而优化游戏流畅度。</p>
  14998. */
  14999. //class laya.utils.Pool
  15000. var Pool=(function(){
  15001. function Pool(){}
  15002. __class(Pool,'laya.utils.Pool');
  15003. Pool.getPoolBySign=function(sign){
  15004. return Pool._poolDic[sign] || (Pool._poolDic[sign]=[]);
  15005. }
  15006. Pool.clearBySign=function(sign){
  15007. if (Pool._poolDic[sign])Pool._poolDic[sign].length=0;
  15008. }
  15009. Pool.recover=function(sign,item){
  15010. if (item["__InPool"])return;
  15011. item["__InPool"]=true;
  15012. Pool.getPoolBySign(sign).push(item);
  15013. }
  15014. Pool.recoverByClass=function(instance){
  15015. if (instance){
  15016. var className=instance["__className"] || instance.constructor._$gid;
  15017. if (className)Pool.recover(className,instance);
  15018. }
  15019. }
  15020. Pool._getClassSign=function(cla){
  15021. var className=cla["__className"] || cla["_$gid"];
  15022. if (!className){
  15023. cla["_$gid"]=className=Utils.getGID()+"";
  15024. }
  15025. return className;
  15026. }
  15027. Pool.createByClass=function(cls){
  15028. return Pool.getItemByClass(Pool._getClassSign(cls),cls);
  15029. }
  15030. Pool.getItemByClass=function(sign,cls){
  15031. if (!Pool._poolDic[sign])return new cls();
  15032. var pool=Pool.getPoolBySign(sign);
  15033. if (pool.length){
  15034. var rst=pool.pop();
  15035. rst["__InPool"]=false;
  15036. }else {
  15037. rst=new cls();
  15038. }
  15039. return rst;
  15040. }
  15041. Pool.getItemByCreateFun=function(sign,createFun,caller){
  15042. var pool=Pool.getPoolBySign(sign);
  15043. var rst=pool.length ? pool.pop():createFun.call(caller);
  15044. rst["__InPool"]=false;
  15045. return rst;
  15046. }
  15047. Pool.getItem=function(sign){
  15048. var pool=Pool.getPoolBySign(sign);
  15049. var rst=pool.length ? pool.pop():null;
  15050. if (rst){
  15051. rst["__InPool"]=false;
  15052. }
  15053. return rst;
  15054. }
  15055. Pool.POOLSIGN="__InPool";
  15056. Pool._poolDic={};
  15057. return Pool;
  15058. })()
  15059. /**
  15060. *绘制边框
  15061. *@private
  15062. */
  15063. //class laya.display.cmd.FillBorderWordsCmd
  15064. var FillBorderWordsCmd=(function(){
  15065. function FillBorderWordsCmd(){
  15066. /**
  15067. *文字数组
  15068. */
  15069. //this.words=null;
  15070. /**
  15071. *开始绘制文本的 x 坐标位置(相对于画布)。
  15072. */
  15073. //this.x=NaN;
  15074. /**
  15075. *开始绘制文本的 y 坐标位置(相对于画布)。
  15076. */
  15077. //this.y=NaN;
  15078. /**
  15079. *定义字体和字号,比如"20px Arial"。
  15080. */
  15081. //this.font=null;
  15082. /**
  15083. *定义文本颜色,比如"#ff0000"。
  15084. */
  15085. //this.fillColor=null;
  15086. /**
  15087. *定义镶边文本颜色。
  15088. */
  15089. //this.borderColor=null;
  15090. /**
  15091. *镶边线条宽度。
  15092. */
  15093. //this.lineWidth=0;
  15094. }
  15095. __class(FillBorderWordsCmd,'laya.display.cmd.FillBorderWordsCmd');
  15096. var __proto=FillBorderWordsCmd.prototype;
  15097. /**
  15098. *回收到对象池
  15099. */
  15100. __proto.recover=function(){
  15101. this.words=null;
  15102. Pool.recover("FillBorderWordsCmd",this);
  15103. }
  15104. /**@private */
  15105. __proto.run=function(context,gx,gy){
  15106. context.fillBorderWords(this.words,this.x+gx,this.y+gy,this.font,this.fillColor,this.borderColor,this.lineWidth);
  15107. }
  15108. /**@private */
  15109. __getset(0,__proto,'cmdID',function(){
  15110. return "FillBorderWords";
  15111. });
  15112. FillBorderWordsCmd.create=function(words,x,y,font,fillColor,borderColor,lineWidth){
  15113. var cmd=Pool.getItemByClass("FillBorderWordsCmd",FillBorderWordsCmd);
  15114. cmd.words=words;
  15115. cmd.x=x;
  15116. cmd.y=y;
  15117. cmd.font=font;
  15118. cmd.fillColor=fillColor;
  15119. cmd.borderColor=borderColor;
  15120. cmd.lineWidth=lineWidth;
  15121. return cmd;
  15122. }
  15123. FillBorderWordsCmd.ID="FillBorderWords";
  15124. return FillBorderWordsCmd;
  15125. })()
  15126. /**
  15127. *@private
  15128. *对象缓存统一管理类
  15129. */
  15130. //class laya.utils.CacheManger
  15131. var CacheManger=(function(){
  15132. function CacheManger(){}
  15133. __class(CacheManger,'laya.utils.CacheManger');
  15134. CacheManger.regCacheByFunction=function(disposeFunction,getCacheListFunction){
  15135. CacheManger.unRegCacheByFunction(disposeFunction,getCacheListFunction);
  15136. var cache;
  15137. cache={tryDispose:disposeFunction,getCacheList:getCacheListFunction};
  15138. CacheManger._cacheList.push(cache);
  15139. }
  15140. CacheManger.unRegCacheByFunction=function(disposeFunction,getCacheListFunction){
  15141. var i=0,len=0;
  15142. len=CacheManger._cacheList.length;
  15143. for (i=0;i < len;i++){
  15144. if (CacheManger._cacheList[i].tryDispose==disposeFunction && CacheManger._cacheList[i].getCacheList==getCacheListFunction){
  15145. CacheManger._cacheList.splice(i,1);
  15146. return;
  15147. }
  15148. }
  15149. }
  15150. CacheManger.forceDispose=function(){
  15151. var i=0,len=CacheManger._cacheList.length;
  15152. for (i=0;i < len;i++){
  15153. CacheManger._cacheList[i].tryDispose(true);
  15154. }
  15155. }
  15156. CacheManger.beginCheck=function(waitTime){
  15157. (waitTime===void 0)&& (waitTime=15000);
  15158. Laya.systemTimer.loop(waitTime,null,CacheManger._checkLoop);
  15159. }
  15160. CacheManger.stopCheck=function(){
  15161. Laya.systemTimer.clear(null,CacheManger._checkLoop);
  15162. }
  15163. CacheManger._checkLoop=function(){
  15164. var cacheList=CacheManger._cacheList;
  15165. if (cacheList.length < 1)return;
  15166. var tTime=Browser.now();
  15167. var count=0;
  15168. var len=0;
  15169. len=count=cacheList.length;
  15170. while (count > 0){
  15171. CacheManger._index++;
  15172. CacheManger._index=CacheManger._index % len;
  15173. cacheList[CacheManger._index].tryDispose(false);
  15174. if (Browser.now()-tTime > CacheManger.loopTimeLimit)break ;
  15175. count--;
  15176. }
  15177. }
  15178. CacheManger.loopTimeLimit=2;
  15179. CacheManger._cacheList=[];
  15180. CacheManger._index=0;
  15181. return CacheManger;
  15182. })()
  15183. /**
  15184. *@private
  15185. */
  15186. //class laya.net.TTFLoader
  15187. var TTFLoader=(function(){
  15188. function TTFLoader(){
  15189. this.fontName=null;
  15190. this.complete=null;
  15191. this.err=null;
  15192. this._fontTxt=null;
  15193. this._url=null;
  15194. this._div=null;
  15195. this._txtWidth=NaN;
  15196. this._http=null;
  15197. }
  15198. __class(TTFLoader,'laya.net.TTFLoader');
  15199. var __proto=TTFLoader.prototype;
  15200. //TODO:coverage
  15201. __proto.load=function(fontPath){
  15202. this._url=fontPath;
  15203. var tArr=fontPath.split(".ttf")[0].split("/");
  15204. this.fontName=tArr[tArr.length-1];
  15205. if (Render.isConchApp){
  15206. this._loadConch();
  15207. }else
  15208. if (Browser.window.FontFace){
  15209. this._loadWithFontFace()
  15210. }
  15211. else {
  15212. this._loadWithCSS();
  15213. }
  15214. }
  15215. //TODO:coverage
  15216. __proto._loadConch=function(){
  15217. this._http=new HttpRequest();
  15218. this._http.on(/*laya.events.Event.ERROR*/"error",this,this._onErr);
  15219. this._http.on(/*laya.events.Event.COMPLETE*/"complete",this,this._onHttpLoaded);
  15220. this._http.send(this._url,null,"get",/*laya.net.Loader.BUFFER*/"arraybuffer");
  15221. }
  15222. //TODO:coverage
  15223. __proto._onHttpLoaded=function(data){
  15224. Browser.window["conchTextCanvas"].setFontFaceFromBuffer(this.fontName,data);
  15225. this._clearHttp();
  15226. this._complete();
  15227. }
  15228. //TODO:coverage
  15229. __proto._clearHttp=function(){
  15230. if (this._http){
  15231. this._http.off(/*laya.events.Event.ERROR*/"error",this,this._onErr);
  15232. this._http.off(/*laya.events.Event.COMPLETE*/"complete",this,this._onHttpLoaded);
  15233. this._http=null;
  15234. }
  15235. }
  15236. //TODO:coverage
  15237. __proto._onErr=function(){
  15238. this._clearHttp();
  15239. if (this.err){
  15240. this.err.runWith("fail:"+this._url);
  15241. this.err=null;
  15242. }
  15243. }
  15244. //TODO:coverage
  15245. __proto._complete=function(){
  15246. Laya.systemTimer.clear(this,this._complete);
  15247. Laya.systemTimer.clear(this,this._checkComplete);
  15248. if (this._div && this._div.parentNode){
  15249. this._div.parentNode.removeChild(this._div);
  15250. this._div=null;
  15251. }
  15252. if (this.complete){
  15253. this.complete.runWith(this);
  15254. this.complete=null;
  15255. }
  15256. }
  15257. //TODO:coverage
  15258. __proto._checkComplete=function(){
  15259. if (RunDriver.measureText("LayaTTFFont",this._fontTxt).width !=this._txtWidth){
  15260. this._complete();
  15261. }
  15262. }
  15263. //TODO:coverage
  15264. __proto._loadWithFontFace=function(){
  15265. var fontFace=new Browser.window.FontFace(this.fontName,"url('"+this._url+"')");
  15266. Browser.window.document.fonts.add(fontFace);
  15267. var self=this;
  15268. fontFace.loaded.then((function(){
  15269. self._complete()
  15270. }));
  15271. fontFace.load();
  15272. }
  15273. //TODO:coverage
  15274. __proto._createDiv=function(){
  15275. this._div=Browser.createElement("div");
  15276. this._div.innerHTML="laya";
  15277. var _style=this._div.style;
  15278. _style.fontFamily=this.fontName;
  15279. _style.position="absolute";
  15280. _style.left="-100px";
  15281. _style.top="-100px";
  15282. Browser.document.body.appendChild(this._div);
  15283. }
  15284. //TODO:coverage
  15285. __proto._loadWithCSS=function(){
  15286. var _$this=this;
  15287. var fontStyle=Browser.createElement("style");
  15288. fontStyle.type="text/css";
  15289. Browser.document.body.appendChild(fontStyle);
  15290. fontStyle.textContent="@font-face { font-family:'"+this.fontName+"'; src:url('"+this._url+"');}";
  15291. this._fontTxt="40px "+this.fontName;
  15292. this._txtWidth=RunDriver.measureText("LayaTTFFont",this._fontTxt).width;
  15293. var self=this;
  15294. fontStyle.onload=function (){
  15295. Laya.systemTimer.once(10000,self,_$this._complete);
  15296. };
  15297. Laya.systemTimer.loop(20,this,this._checkComplete);
  15298. this._createDiv();
  15299. }
  15300. TTFLoader._testString="LayaTTFFont";
  15301. return TTFLoader;
  15302. })()
  15303. //class laya.webgl.utils.InlcudeFile
  15304. var InlcudeFile=(function(){
  15305. function InlcudeFile(txt){
  15306. this.script=null;
  15307. this.codes={};
  15308. this.funs={};
  15309. this.curUseID=-1;
  15310. this.funnames="";
  15311. this.script=txt;
  15312. var begin=0,ofs=0,end=0;
  15313. while (true){
  15314. begin=txt.indexOf("#begin",begin);
  15315. if (begin < 0)break ;
  15316. end=begin+5;
  15317. while (true){
  15318. end=txt.indexOf("#end",end);
  15319. if (end < 0)break ;
  15320. if (txt.charAt(end+4)==='i')
  15321. end+=5;
  15322. else break ;
  15323. }
  15324. if (end < 0){
  15325. throw "add include err,no #end:"+txt;
  15326. }
  15327. ofs=txt.indexOf('\n',begin);
  15328. var words=ShaderCompile.splitToWords(txt.substr(begin,ofs-begin),null);
  15329. if (words[1]=='code'){
  15330. this.codes[words[2]]=txt.substr(ofs+1,end-ofs-1);
  15331. }else if (words[1]=='function'){
  15332. ofs=txt.indexOf("function",begin);
  15333. ofs+="function".length;
  15334. this.funs[words[3]]=txt.substr(ofs+1,end-ofs-1);
  15335. this.funnames+=words[3]+";";
  15336. }
  15337. begin=end+1;
  15338. }
  15339. }
  15340. __class(InlcudeFile,'laya.webgl.utils.InlcudeFile');
  15341. var __proto=InlcudeFile.prototype;
  15342. __proto.getWith=function(name){
  15343. var r=name ? this.codes[name] :this.script;
  15344. if (!r){
  15345. throw "get with error:"+name;
  15346. }
  15347. return r;
  15348. }
  15349. __proto.getFunsScript=function(funsdef){
  15350. var r="";
  15351. for (var i in this.funs){
  15352. if (funsdef.indexOf(i+";")>=0){
  15353. r+=this.funs[i];
  15354. }
  15355. }
  15356. return r;
  15357. }
  15358. return InlcudeFile;
  15359. })()
  15360. /**
  15361. *<p>资源版本的生成由layacmd或IDE完成,使用 <code>ResourceVersion</code> 简化使用过程。</p>
  15362. *<p>调用 <code>enable</code> 启用资源版本管理。</p>
  15363. */
  15364. //class laya.net.ResourceVersion
  15365. var ResourceVersion=(function(){
  15366. function ResourceVersion(){}
  15367. __class(ResourceVersion,'laya.net.ResourceVersion');
  15368. ResourceVersion.enable=function(manifestFile,callback,type){
  15369. (type===void 0)&& (type=2);
  15370. laya.net.ResourceVersion.type=type;
  15371. Laya.loader.load(manifestFile,Handler.create(null,ResourceVersion.onManifestLoaded,[callback]),null,/*laya.net.Loader.JSON*/"json");
  15372. URL.customFormat=ResourceVersion.addVersionPrefix;
  15373. }
  15374. ResourceVersion.onManifestLoaded=function(callback,data){
  15375. ResourceVersion.manifest=data;
  15376. callback.run();
  15377. if (!data){
  15378. console.warn("资源版本清单文件不存在,不使用资源版本管理。忽略ERR_FILE_NOT_FOUND错误。");
  15379. }
  15380. }
  15381. ResourceVersion.addVersionPrefix=function(originURL){
  15382. originURL=URL.getAdptedFilePath(originURL);
  15383. if (ResourceVersion.manifest && ResourceVersion.manifest[originURL]){
  15384. if (ResourceVersion.type==2)return ResourceVersion.manifest[originURL];
  15385. return ResourceVersion.manifest[originURL]+"/"+originURL;
  15386. }
  15387. return originURL;
  15388. }
  15389. ResourceVersion.FOLDER_VERSION=1;
  15390. ResourceVersion.FILENAME_VERSION=2;
  15391. ResourceVersion.manifest=null;
  15392. ResourceVersion.type=1;
  15393. return ResourceVersion;
  15394. })()
  15395. /**
  15396. *<code>Event</code> 是事件类型的集合。一般当发生事件时,<code>Event</code> 对象将作为参数传递给事件侦听器。
  15397. */
  15398. //class laya.events.Event
  15399. var Event=(function(){
  15400. function Event(){
  15401. /**事件类型。*/
  15402. //this.type=null;
  15403. /**原生浏览器事件。*/
  15404. //this.nativeEvent=null;
  15405. /**事件目标触发对象。*/
  15406. //this.target=null;
  15407. /**事件当前冒泡对象。*/
  15408. //this.currentTarget=null;
  15409. /**@private */
  15410. //this._stoped=false;
  15411. /**分配给触摸点的唯一标识号(作为 int)。*/
  15412. //this.touchId=0;
  15413. /**键盘值*/
  15414. //this.keyCode=0;
  15415. /**滚轮滑动增量*/
  15416. //this.delta=0;
  15417. }
  15418. __class(Event,'laya.events.Event');
  15419. var __proto=Event.prototype;
  15420. /**
  15421. *设置事件数据。
  15422. *@param type 事件类型。
  15423. *@param currentTarget 事件目标触发对象。
  15424. *@param target 事件当前冒泡对象。
  15425. *@return 返回当前 Event 对象。
  15426. */
  15427. __proto.setTo=function(type,currentTarget,target){
  15428. this.type=type;
  15429. this.currentTarget=currentTarget;
  15430. this.target=target;
  15431. return this;
  15432. }
  15433. /**
  15434. *阻止对事件流中当前节点的后续节点中的所有事件侦听器进行处理。此方法不会影响当前节点 (currentTarget)中的任何事件侦听器。
  15435. */
  15436. __proto.stopPropagation=function(){
  15437. this._stoped=true;
  15438. }
  15439. /**鼠标在 Stage 上的 Y 轴坐标*/
  15440. __getset(0,__proto,'stageY',function(){
  15441. return Laya.stage.mouseY;
  15442. });
  15443. /**
  15444. *包含按下或释放的键的字符代码值。字符代码值为英文键盘值。
  15445. */
  15446. __getset(0,__proto,'charCode',function(){
  15447. return this.nativeEvent.charCode;
  15448. });
  15449. /**
  15450. *触摸点列表。
  15451. */
  15452. __getset(0,__proto,'touches',function(){
  15453. if (!this.nativeEvent)return null;
  15454. var arr=this.nativeEvent.touches;
  15455. if (arr){
  15456. var stage=Laya.stage;
  15457. for (var i=0,n=arr.length;i < n;i++){
  15458. var e=arr[i];
  15459. var point=Point.TEMP;
  15460. point.setTo(e.clientX,e.clientY);
  15461. stage._canvasTransform.invertTransformPoint(point);
  15462. stage.transform.invertTransformPoint(point);
  15463. e.stageX=point.x;
  15464. e.stageY=point.y;
  15465. }
  15466. }
  15467. return arr;
  15468. });
  15469. /**
  15470. *表示键在键盘上的位置。这对于区分在键盘上多次出现的键非常有用。<br>
  15471. *例如,您可以根据此属性的值来区分左 Shift 键和右 Shift 键:左 Shift 键的值为 KeyLocation.LEFT,右 Shift 键的值为 KeyLocation.RIGHT。另一个示例是区分标准键盘 (KeyLocation.STANDARD)与数字键盘 (KeyLocation.NUM_PAD)上按下的数字键。
  15472. */
  15473. __getset(0,__proto,'keyLocation',function(){
  15474. return this.nativeEvent.location || this.nativeEvent.keyLocation;
  15475. });
  15476. /**
  15477. *表示 Ctrl 键是处于活动状态 (true)还是非活动状态 (false)。
  15478. */
  15479. __getset(0,__proto,'ctrlKey',function(){
  15480. return this.nativeEvent.ctrlKey;
  15481. });
  15482. /**
  15483. *表示 Alt 键是处于活动状态 (true)还是非活动状态 (false)。
  15484. */
  15485. __getset(0,__proto,'altKey',function(){
  15486. return this.nativeEvent.altKey;
  15487. });
  15488. /**
  15489. *表示 Shift 键是处于活动状态 (true)还是非活动状态 (false)。
  15490. */
  15491. __getset(0,__proto,'shiftKey',function(){
  15492. return this.nativeEvent.shiftKey;
  15493. });
  15494. /**鼠标在 Stage 上的 X 轴坐标*/
  15495. __getset(0,__proto,'stageX',function(){
  15496. return Laya.stage.mouseX;
  15497. });
  15498. Event.EMPTY=new Event();
  15499. Event.MOUSE_DOWN="mousedown";
  15500. Event.MOUSE_UP="mouseup";
  15501. Event.CLICK="click";
  15502. Event.RIGHT_MOUSE_DOWN="rightmousedown";
  15503. Event.RIGHT_MOUSE_UP="rightmouseup";
  15504. Event.RIGHT_CLICK="rightclick";
  15505. Event.MOUSE_MOVE="mousemove";
  15506. Event.MOUSE_OVER="mouseover";
  15507. Event.MOUSE_OUT="mouseout";
  15508. Event.MOUSE_WHEEL="mousewheel";
  15509. Event.ROLL_OVER="mouseover";
  15510. Event.ROLL_OUT="mouseout";
  15511. Event.DOUBLE_CLICK="doubleclick";
  15512. Event.CHANGE="change";
  15513. Event.CHANGED="changed";
  15514. Event.RESIZE="resize";
  15515. Event.ADDED="added";
  15516. Event.REMOVED="removed";
  15517. Event.DISPLAY="display";
  15518. Event.UNDISPLAY="undisplay";
  15519. Event.ERROR="error";
  15520. Event.COMPLETE="complete";
  15521. Event.LOADED="loaded";
  15522. Event.READY="ready";
  15523. Event.PROGRESS="progress";
  15524. Event.INPUT="input";
  15525. Event.RENDER="render";
  15526. Event.OPEN="open";
  15527. Event.MESSAGE="message";
  15528. Event.CLOSE="close";
  15529. Event.KEY_DOWN="keydown";
  15530. Event.KEY_PRESS="keypress";
  15531. Event.KEY_UP="keyup";
  15532. Event.FRAME="enterframe";
  15533. Event.DRAG_START="dragstart";
  15534. Event.DRAG_MOVE="dragmove";
  15535. Event.DRAG_END="dragend";
  15536. Event.ENTER="enter";
  15537. Event.SELECT="select";
  15538. Event.BLUR="blur";
  15539. Event.FOCUS="focus";
  15540. Event.VISIBILITY_CHANGE="visibilitychange";
  15541. Event.FOCUS_CHANGE="focuschange";
  15542. Event.PLAYED="played";
  15543. Event.PAUSED="paused";
  15544. Event.STOPPED="stopped";
  15545. Event.START="start";
  15546. Event.END="end";
  15547. Event.COMPONENT_ADDED="componentadded";
  15548. Event.COMPONENT_REMOVED="componentremoved";
  15549. Event.RELEASED="released";
  15550. Event.LINK="link";
  15551. Event.LABEL="label";
  15552. Event.FULL_SCREEN_CHANGE="fullscreenchange";
  15553. Event.DEVICE_LOST="devicelost";
  15554. Event.TRANSFORM_CHANGED="transformchanged";
  15555. Event.ANIMATION_CHANGED="animationchanged";
  15556. Event.TRAIL_FILTER_CHANGE="trailfilterchange";
  15557. Event.TRIGGER_ENTER="triggerenter";
  15558. Event.TRIGGER_STAY="triggerstay";
  15559. Event.TRIGGER_EXIT="triggerexit";
  15560. return Event;
  15561. })()
  15562. /**
  15563. *绘制文本边框
  15564. */
  15565. //class laya.display.cmd.FillBorderTextCmd
  15566. var FillBorderTextCmd=(function(){
  15567. function FillBorderTextCmd(){
  15568. /**
  15569. *在画布上输出的文本。
  15570. */
  15571. //this.text=null;
  15572. /**
  15573. *开始绘制文本的 x 坐标位置(相对于画布)。
  15574. */
  15575. //this.x=NaN;
  15576. /**
  15577. *开始绘制文本的 y 坐标位置(相对于画布)。
  15578. */
  15579. //this.y=NaN;
  15580. /**
  15581. *定义字体和字号,比如"20px Arial"。
  15582. */
  15583. //this.font=null;
  15584. /**
  15585. *定义文本颜色,比如"#ff0000"。
  15586. */
  15587. //this.fillColor=null;
  15588. /**
  15589. *定义镶边文本颜色。
  15590. */
  15591. //this.borderColor=null;
  15592. /**
  15593. *镶边线条宽度。
  15594. */
  15595. //this.lineWidth=NaN;
  15596. /**
  15597. *文本对齐方式,可选值:"left","center","right"。
  15598. */
  15599. //this.textAlign=null;
  15600. }
  15601. __class(FillBorderTextCmd,'laya.display.cmd.FillBorderTextCmd');
  15602. var __proto=FillBorderTextCmd.prototype;
  15603. /**
  15604. *回收到对象池
  15605. */
  15606. __proto.recover=function(){
  15607. Pool.recover("FillBorderTextCmd",this);
  15608. }
  15609. /**@private */
  15610. __proto.run=function(context,gx,gy){
  15611. context.fillBorderText(this.text,this.x+gx,this.y+gy,this.font,this.fillColor,this.borderColor,this.lineWidth,this.textAlign);
  15612. }
  15613. /**@private */
  15614. __getset(0,__proto,'cmdID',function(){
  15615. return "FillBorderText";
  15616. });
  15617. FillBorderTextCmd.create=function(text,x,y,font,fillColor,borderColor,lineWidth,textAlign){
  15618. var cmd=Pool.getItemByClass("FillBorderTextCmd",FillBorderTextCmd);
  15619. cmd.text=text;
  15620. cmd.x=x;
  15621. cmd.y=y;
  15622. cmd.font=font;
  15623. cmd.fillColor=fillColor;
  15624. cmd.borderColor=borderColor;
  15625. cmd.lineWidth=lineWidth;
  15626. cmd.textAlign=textAlign;
  15627. return cmd;
  15628. }
  15629. FillBorderTextCmd.ID="FillBorderText";
  15630. return FillBorderTextCmd;
  15631. })()
  15632. //class laya.webgl.submit.SubmitTarget
  15633. var SubmitTarget=(function(){
  15634. function SubmitTarget(){
  15635. this._mesh=null;
  15636. //代替 _vb,_ib
  15637. this._startIdx=0;
  15638. this._numEle=0;
  15639. this.shaderValue=null;
  15640. this.blendType=0;
  15641. this._ref=1;
  15642. //public var scope:SubmitCMDScope;
  15643. this.srcRT=null;
  15644. this._key=new SubmitKey();
  15645. }
  15646. __class(SubmitTarget,'laya.webgl.submit.SubmitTarget');
  15647. var __proto=SubmitTarget.prototype;
  15648. Laya.imps(__proto,{"laya.webgl.submit.ISubmit":true})
  15649. __proto.renderSubmit=function(){
  15650. var gl=WebGL.mainContext;
  15651. this._mesh.useMesh(gl);
  15652. var target=this.srcRT;
  15653. if (target){
  15654. this.shaderValue.texture=target._getSource();
  15655. this.shaderValue.upload();
  15656. this.blend();
  15657. Stat.renderBatches++;
  15658. Stat.trianglesFaces+=this._numEle/3;
  15659. WebGL.mainContext.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,this._numEle,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,this._startIdx);
  15660. }
  15661. return 1;
  15662. }
  15663. __proto.blend=function(){
  15664. if (BlendMode.activeBlendFunction!==BlendMode.fns[this.blendType]){
  15665. var gl=WebGL.mainContext;
  15666. gl.enable(/*laya.webgl.WebGLContext.BLEND*/0x0BE2);
  15667. BlendMode.fns[this.blendType](gl);
  15668. BlendMode.activeBlendFunction=BlendMode.fns[this.blendType];
  15669. }
  15670. }
  15671. //TODO:coverage
  15672. __proto.getRenderType=function(){
  15673. return 0;
  15674. }
  15675. __proto.releaseRender=function(){
  15676. if ((--this._ref)< 1){
  15677. var pool=SubmitTarget.POOL;
  15678. pool[pool._length++]=this;
  15679. }
  15680. }
  15681. //TODO:coverage
  15682. __proto.reUse=function(context,pos){
  15683. this._startIdx=pos;
  15684. this._ref++;
  15685. return pos;
  15686. }
  15687. SubmitTarget.create=function(context,mesh,sv,rt){
  15688. var o=SubmitTarget.POOL._length?SubmitTarget.POOL[--SubmitTarget.POOL._length]:new SubmitTarget();
  15689. o._mesh=mesh;
  15690. o.srcRT=rt;
  15691. o._startIdx=mesh.indexNum *CONST3D2D.BYTES_PIDX;
  15692. o._ref=1;
  15693. o._key.clear();
  15694. o._numEle=0;
  15695. o.blendType=context._nBlendType;
  15696. o._key.blendShader=o.blendType;
  15697. o.shaderValue=sv;
  15698. o.shaderValue.setValue(context._shader2D);
  15699. if (context._colorFiler){
  15700. var ft=context._colorFiler;
  15701. sv.defines.add(ft.type);
  15702. (sv).colorMat=ft._mat;
  15703. (sv).colorAlpha=ft._alpha;
  15704. }
  15705. return o;
  15706. }
  15707. SubmitTarget.POOL=[];
  15708. SubmitTarget.__init$=function(){
  15709. ;{
  15710. SubmitTarget.POOL._length=0;
  15711. }
  15712. }
  15713. return SubmitTarget;
  15714. })()
  15715. /**
  15716. *...
  15717. *@author xie
  15718. */
  15719. //class laya.webgl.submit.SubmitKey
  15720. var SubmitKey=(function(){
  15721. function SubmitKey(){
  15722. this.blendShader=0;
  15723. this.submitType=0;
  15724. this.other=0;
  15725. this.clear();
  15726. }
  15727. __class(SubmitKey,'laya.webgl.submit.SubmitKey');
  15728. var __proto=SubmitKey.prototype;
  15729. __proto.clear=function(){
  15730. this.submitType=-1;
  15731. this.blendShader=this.other=0;
  15732. }
  15733. //TODO:coverage
  15734. __proto.copyFrom=function(src){
  15735. this.other=src.other;
  15736. this.blendShader=src.blendShader;
  15737. this.submitType=src.submitType;
  15738. }
  15739. //alpha=src.alpha;
  15740. __proto.copyFrom2=function(src,submitType,other){
  15741. this.other=other;
  15742. this.submitType=submitType;
  15743. }
  15744. //TODO:coverage
  15745. __proto.equal3_2=function(next,submitType,other){
  15746. return this.submitType===submitType && this.other===other && this.blendShader===next.blendShader;
  15747. }
  15748. //TODO:coverage
  15749. __proto.equal4_2=function(next,submitType,other){
  15750. return this.submitType===submitType && this.other===other && this.blendShader===next.blendShader;
  15751. }
  15752. //TODO:coverage
  15753. __proto.equal_3=function(next){
  15754. return this.submitType===next.submitType && this.blendShader===next.blendShader;
  15755. }
  15756. //TODO:coverage
  15757. __proto.equal=function(next){
  15758. return this.other===next.other && this.submitType===next.submitType && this.blendShader===next.blendShader;
  15759. }
  15760. return SubmitKey;
  15761. })()
  15762. /**
  15763. *绘制矩形
  15764. */
  15765. //class laya.display.cmd.DrawRectCmd
  15766. var DrawRectCmd=(function(){
  15767. function DrawRectCmd(){
  15768. /**
  15769. *开始绘制的 X 轴位置。
  15770. */
  15771. //this.x=NaN;
  15772. /**
  15773. *开始绘制的 Y 轴位置。
  15774. */
  15775. //this.y=NaN;
  15776. /**
  15777. *矩形宽度。
  15778. */
  15779. //this.width=NaN;
  15780. /**
  15781. *矩形高度。
  15782. */
  15783. //this.height=NaN;
  15784. /**
  15785. *填充颜色,或者填充绘图的渐变对象。
  15786. */
  15787. //this.fillColor=null;
  15788. /**
  15789. *(可选)边框颜色,或者填充绘图的渐变对象。
  15790. */
  15791. //this.lineColor=null;
  15792. /**
  15793. *(可选)边框宽度。
  15794. */
  15795. //this.lineWidth=NaN;
  15796. }
  15797. __class(DrawRectCmd,'laya.display.cmd.DrawRectCmd');
  15798. var __proto=DrawRectCmd.prototype;
  15799. /**
  15800. *回收到对象池
  15801. */
  15802. __proto.recover=function(){
  15803. this.fillColor=null;
  15804. this.lineColor=null;
  15805. Pool.recover("DrawRectCmd",this);
  15806. }
  15807. /**@private */
  15808. __proto.run=function(context,gx,gy){
  15809. context.drawRect(this.x+gx,this.y+gy,this.width,this.height,this.fillColor,this.lineColor,this.lineWidth);
  15810. }
  15811. /**@private */
  15812. __getset(0,__proto,'cmdID',function(){
  15813. return "DrawRect";
  15814. });
  15815. DrawRectCmd.create=function(x,y,width,height,fillColor,lineColor,lineWidth){
  15816. var cmd=Pool.getItemByClass("DrawRectCmd",DrawRectCmd);
  15817. cmd.x=x;
  15818. cmd.y=y;
  15819. cmd.width=width;
  15820. cmd.height=height;
  15821. cmd.fillColor=fillColor;
  15822. cmd.lineColor=lineColor;
  15823. cmd.lineWidth=lineWidth;
  15824. return cmd;
  15825. }
  15826. DrawRectCmd.ID="DrawRect";
  15827. return DrawRectCmd;
  15828. })()
  15829. //class laya.webgl.shapes.EarcutNode
  15830. var EarcutNode=(function(){
  15831. function EarcutNode(i,x,y){
  15832. this.i=null;
  15833. this.x=null;
  15834. this.y=null;
  15835. this.prev=null;
  15836. this.next=null;
  15837. this.z=null;
  15838. this.prevZ=null;
  15839. this.nextZ=null;
  15840. this.steiner=null;
  15841. this.i=i;
  15842. this.x=x;
  15843. this.y=y;
  15844. this.prev=null;
  15845. this.next=null;
  15846. this.z=null;
  15847. this.prevZ=null;
  15848. this.nextZ=null;
  15849. this.steiner=false;
  15850. }
  15851. __class(EarcutNode,'laya.webgl.shapes.EarcutNode');
  15852. return EarcutNode;
  15853. })()
  15854. /**
  15855. *@private
  15856. */
  15857. //class laya.utils.RunDriver
  15858. var RunDriver=(function(){
  15859. function RunDriver(){}
  15860. __class(RunDriver,'laya.utils.RunDriver');
  15861. RunDriver.createShaderCondition=function(conditionScript){
  15862. var fn="(function() {return "+conditionScript+";})";
  15863. return Laya._runScript(fn);
  15864. }
  15865. RunDriver.fontMap=[];
  15866. RunDriver.measureText=function(txt,font){
  15867. var isChinese=RunDriver.hanzi.test(txt);
  15868. if (isChinese && RunDriver.fontMap[font]){
  15869. return RunDriver.fontMap[font];
  15870. };
  15871. var ctx=Browser.context;
  15872. ctx.font=font;
  15873. var r=ctx.measureText(txt);
  15874. if (isChinese)RunDriver.fontMap[font]=r;
  15875. return r;
  15876. }
  15877. RunDriver.drawToCanvas=function(sprite,_renderType,canvasWidth,canvasHeight,offsetX,offsetY){
  15878. offsetX-=sprite.x;
  15879. offsetY-=sprite.y;
  15880. offsetX |=0;
  15881. offsetY |=0;
  15882. canvasWidth |=0;
  15883. canvasHeight |=0;
  15884. var ctx=new Context();
  15885. ctx.size(canvasWidth,canvasHeight);
  15886. ctx.asBitmap=true;
  15887. ctx._targets.start();
  15888. RenderSprite.renders[_renderType]._fun(sprite,ctx,offsetX,offsetY);
  15889. ctx.flush();
  15890. ctx._targets.end();
  15891. ctx._targets.restore();
  15892. var dt=ctx._targets.getData(0,0,canvasWidth,canvasHeight);
  15893. ctx.destroy();
  15894. var imgdata=/*__JS__ */new ImageData(canvasWidth,canvasHeight);;
  15895. var lineLen=canvasWidth *4;
  15896. var temp=new Uint8Array(lineLen);
  15897. var dst=imgdata.data;
  15898. var y=canvasHeight-1;
  15899. var off=y *lineLen;
  15900. var srcoff=0;
  15901. for (;y >=0;y--){
  15902. dst.set(dt.subarray(srcoff,srcoff+lineLen),off);
  15903. off-=lineLen;
  15904. srcoff+=lineLen;
  15905. };
  15906. var canv=new HTMLCanvas(true);
  15907. canv.size(canvasWidth,canvasHeight);
  15908. var ctx2d=canv.getContext('2d');
  15909. /*__JS__ */ctx2d.putImageData(imgdata,0,0);;
  15910. return canv;
  15911. }
  15912. RunDriver.drawToTexture=function(sprite,_renderType,canvasWidth,canvasHeight,offsetX,offsetY){
  15913. offsetX-=sprite.x;
  15914. offsetY-=sprite.y;
  15915. offsetX |=0;
  15916. offsetY |=0;
  15917. canvasWidth |=0;
  15918. canvasHeight |=0;
  15919. var ctx=new Context();
  15920. ctx.size(canvasWidth,canvasHeight);
  15921. ctx.asBitmap=true;
  15922. ctx._targets.start();
  15923. RenderSprite.renders[_renderType]._fun(sprite,ctx,offsetX,offsetY);
  15924. ctx.flush();
  15925. ctx._targets.end();
  15926. ctx._targets.restore();
  15927. var rtex=new Texture((ctx._targets),Texture.INV_UV);
  15928. ctx.destroy(true);
  15929. return rtex;
  15930. }
  15931. RunDriver.changeWebGLSize=function(w,h){
  15932. WebGL.onStageResize(w,h);
  15933. }
  15934. RunDriver.clear=function(value){
  15935. Context.set2DRenderConfig();
  15936. RenderState2D.worldScissorTest && WebGL.mainContext.disable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11);
  15937. var ctx=Render.context;
  15938. var c=(ctx._submits._length==0 || Config.preserveDrawingBuffer)? ColorUtils.create(value).arrColor :Laya.stage._wgColor;
  15939. if (c)
  15940. ctx.clearBG(c[0],c[1],c[2],c[3]);
  15941. else
  15942. ctx.clearBG(0,0,0,0);
  15943. RenderState2D.clear();
  15944. }
  15945. RunDriver.enableNative=null;
  15946. __static(RunDriver,
  15947. ['hanzi',function(){return this.hanzi=new RegExp("^[\u4E00-\u9FA5]$");}
  15948. ]);
  15949. return RunDriver;
  15950. })()
  15951. /**
  15952. *@private
  15953. *Context扩展类
  15954. */
  15955. //class laya.resource.Context
  15956. var Context=(function(){
  15957. var ContextParams;
  15958. function Context(){
  15959. //this._canvas=null;
  15960. this._drawTriUseAbsMatrix=false;
  15961. //还原2D视口
  15962. this._id=++Context._COUNT;
  15963. this._other=null;
  15964. this._renderNextSubmitIndex=0;
  15965. this._path=null;
  15966. //this._primitiveValue2D=null;
  15967. this._drawCount=1;
  15968. this._renderCount=0;
  15969. this._isConvexCmd=true;
  15970. //arc等是convex的,moveTo,linTo就不是了
  15971. this._submits=null;
  15972. this._curSubmit=null;
  15973. //当前将要使用的设置。用来跟上一次的_curSubmit比较
  15974. this._mesh=null;
  15975. //用Mesh2D代替_vb,_ib. 当前使用的mesh
  15976. this._pathMesh=null;
  15977. //矢量专用mesh。
  15978. this._triangleMesh=null;
  15979. //drawTriangles专用mesh。由于ib不固定,所以不能与_mesh通用
  15980. this.meshlist=[];
  15981. //用矩阵描述的clip信息。最终的点投影到这个矩阵上,在0~1之间就可见。
  15982. this._clipInCache=false;
  15983. // 当前记录的clipinfo是在cacheas normal后赋值的,因为cacheas normal会去掉当前矩阵的tx,ty,所以需要记录一下,以便在是shader中恢复
  15984. this._clipInfoID=0;
  15985. //生成clipid的,原来是 _clipInfoID=++_clipInfoID 这样会有问题,导致兄弟clip的id都相同
  15986. this._curMat=null;
  15987. //计算矩阵缩放的缓存
  15988. this._lastMatScaleX=1.0;
  15989. this._lastMatScaleY=1.0;
  15990. this._lastMat_a=1.0;
  15991. this._lastMat_b=0.0;
  15992. this._lastMat_c=0.0;
  15993. this._lastMat_d=1.0;
  15994. this._nBlendType=0;
  15995. this._save=null;
  15996. this._targets=null;
  15997. this._charSubmitCache=null;
  15998. this._saveMark=null;
  15999. /**
  16000. *所cacheAs精灵
  16001. *对于cacheas bitmap的情况,如果图片还没准备好,需要有机会重画,所以要保存sprite。例如在图片
  16002. *加载完成后,调用repaint
  16003. */
  16004. this.sprite=null;
  16005. this._italicDeg=0;
  16006. //文字的倾斜角度
  16007. this._lastTex=null;
  16008. //上次使用的texture。主要是给fillrect用,假装自己也是一个drawtexture
  16009. this._fillColor=0;
  16010. this._flushCnt=0;
  16011. this.defTexture=null;
  16012. //给fillrect用
  16013. this._colorFiler=null;
  16014. this.drawTexAlign=false;
  16015. // 按照像素对齐
  16016. this._incache=false;
  16017. // 正处在cacheas normal过程中
  16018. this.isMain=false;
  16019. this._tmpMatrix=new Matrix();
  16020. this._drawTexToDrawTri_Vert=new Float32Array(8);
  16021. this._drawTexToDrawTri_Index=new Uint16Array([0,1,2,0,2,3]);
  16022. this._tempUV=new Float32Array(8);
  16023. this._width=99999999;
  16024. this._height=99999999;
  16025. this._submitKey=new SubmitKey();
  16026. this._transedPoints=new Array(8);
  16027. this._temp4Points=new Array(8);
  16028. this._clipRect=Context.MAXCLIPRECT;
  16029. this._globalClipMatrix=new Matrix(/*CLASS CONST:laya.resource.Context._MAXSIZE*/99999999,0,0,/*CLASS CONST:laya.resource.Context._MAXSIZE*/99999999,0,0);
  16030. this._shader2D=new Shader2D();
  16031. Context._contextcount++;
  16032. if (!this.defTexture){
  16033. var defTex2d=new Texture2D(2,2);
  16034. defTex2d.setPixels(new Uint8Array(16));
  16035. defTex2d.lock=true;
  16036. this.defTexture=new Texture(defTex2d);
  16037. }
  16038. this._lastTex=this.defTexture;
  16039. this.clear();
  16040. }
  16041. __class(Context,'laya.resource.Context');
  16042. var __proto=Context.prototype;
  16043. /**@private */
  16044. __proto.drawImage=function(__args){}
  16045. /**@private */
  16046. __proto.getImageData=function(__args){}
  16047. /**@private */
  16048. __proto.measureText=function(text){
  16049. return null;
  16050. }
  16051. /**@private */
  16052. __proto.setTransform=function(__args){}
  16053. /**@private */
  16054. __proto.$transform=function(a,b,c,d,tx,ty){}
  16055. /**@private */
  16056. __proto.clearRect=function(x,y,width,height){}
  16057. //TODO:coverage
  16058. __proto._drawRect=function(x,y,width,height,style){
  16059. Stat.renderBatches++;
  16060. style && (this.fillStyle=style);
  16061. /*__JS__ */this.fillRect(x,y,width,height);
  16062. }
  16063. //TODO:coverage
  16064. __proto.drawTexture2=function(x,y,pivotX,pivotY,m,args2){}
  16065. //=============新增==================
  16066. __proto.transformByMatrix=function(matrix,tx,ty){
  16067. this.transform(matrix.a,matrix.b,matrix.c,matrix.d,matrix.tx+tx,matrix.ty+ty);
  16068. }
  16069. __proto.saveTransform=function(matrix){
  16070. this.save();
  16071. }
  16072. __proto.restoreTransform=function(matrix){
  16073. this.restore();
  16074. }
  16075. __proto.drawRect=function(x,y,width,height,fillColor,lineColor,lineWidth){
  16076. var ctx=this;
  16077. if (fillColor !=null){
  16078. ctx.fillStyle=fillColor;
  16079. ctx.fillRect(x,y,width,height);
  16080. }
  16081. if (lineColor !=null){
  16082. ctx.strokeStyle=lineColor;
  16083. ctx.lineWidth=lineWidth;
  16084. ctx.strokeRect(x,y,width,height);
  16085. }
  16086. }
  16087. __proto.alpha=function(value){
  16088. this.globalAlpha *=value;
  16089. }
  16090. //TODO:coverage
  16091. __proto._transform=function(mat,pivotX,pivotY){
  16092. this.translate(pivotX,pivotY);
  16093. this.transform(mat.a,mat.b,mat.c,mat.d,mat.tx,mat.ty);
  16094. this.translate(-pivotX,-pivotY);
  16095. }
  16096. __proto._rotate=function(angle,pivotX,pivotY){
  16097. this.translate(pivotX,pivotY);
  16098. this.rotate(angle);
  16099. this.translate(-pivotX,-pivotY);
  16100. }
  16101. __proto._scale=function(scaleX,scaleY,pivotX,pivotY){
  16102. this.translate(pivotX,pivotY);
  16103. this.scale(scaleX,scaleY);
  16104. this.translate(-pivotX,-pivotY);
  16105. }
  16106. __proto._drawLine=function(x,y,fromX,fromY,toX,toY,lineColor,lineWidth,vid){
  16107. this.beginPath();
  16108. this.strokeStyle=lineColor;
  16109. this.lineWidth=lineWidth;
  16110. this.moveTo(x+fromX,y+fromY);
  16111. this.lineTo(x+toX,y+toY);
  16112. this.stroke();
  16113. }
  16114. __proto._drawLines=function(x,y,points,lineColor,lineWidth,vid){
  16115. this.beginPath();
  16116. this.strokeStyle=lineColor;
  16117. this.lineWidth=lineWidth;
  16118. var i=2,n=points.length;
  16119. this.addPath(points.slice(),false,false,x,y);
  16120. this.stroke();
  16121. }
  16122. __proto.drawCurves=function(x,y,points,lineColor,lineWidth){
  16123. this.beginPath();
  16124. this.strokeStyle=lineColor;
  16125. this.lineWidth=lineWidth;
  16126. this.moveTo(x+points[0],y+points[1]);
  16127. var i=2,n=points.length;
  16128. while (i < n){
  16129. this.quadraticCurveTo(x+points[i++],y+points[i++],x+points[i++],y+points[i++]);
  16130. }
  16131. this.stroke();
  16132. }
  16133. __proto._fillAndStroke=function(fillColor,strokeColor,lineWidth,isConvexPolygon){
  16134. (isConvexPolygon===void 0)&& (isConvexPolygon=false);
  16135. if (fillColor !=null){
  16136. this.fillStyle=fillColor;
  16137. this.fill();
  16138. }
  16139. if (strokeColor !=null && lineWidth > 0){
  16140. this.strokeStyle=strokeColor;
  16141. this.lineWidth=lineWidth;
  16142. this.stroke();
  16143. }
  16144. }
  16145. __proto._drawCircle=function(x,y,radius,fillColor,lineColor,lineWidth,vid){
  16146. Stat.renderBatches++;
  16147. this.beginPath(true);
  16148. this.arc(x,y,radius,0,Context.PI2);
  16149. this.closePath();
  16150. this._fillAndStroke(fillColor,lineColor,lineWidth);
  16151. }
  16152. //矢量方法
  16153. __proto._drawPie=function(x,y,radius,startAngle,endAngle,fillColor,lineColor,lineWidth,vid){
  16154. this.beginPath();
  16155. this.moveTo(x ,y);
  16156. this.arc(x,y,radius,startAngle,endAngle);
  16157. this.closePath();
  16158. this._fillAndStroke(fillColor,lineColor,lineWidth);
  16159. }
  16160. //ctx.translate(-x-args[0],-y-args[1]);
  16161. __proto._drawPoly=function(x,y,points,fillColor,lineColor,lineWidth,isConvexPolygon,vid){
  16162. var i=2,n=points.length;
  16163. this.beginPath();
  16164. this.addPath(points.slice(),true,isConvexPolygon,x,y);
  16165. this.closePath();
  16166. this._fillAndStroke(fillColor,lineColor,lineWidth,isConvexPolygon);
  16167. }
  16168. __proto._drawPath=function(x,y,paths,brush,pen){
  16169. this.beginPath();
  16170. for (var i=0,n=paths.length;i < n;i++){
  16171. var path=paths[i];
  16172. switch (path[0]){
  16173. case "moveTo":
  16174. this.moveTo(x+path[1],y+path[2]);
  16175. break ;
  16176. case "lineTo":
  16177. this.lineTo(x+path[1],y+path[2]);
  16178. break ;
  16179. case "arcTo":
  16180. this.arcTo(x+path[1],y+path[2],x+path[3],y+path[4],path[5]);
  16181. break ;
  16182. case "closePath":
  16183. this.closePath();
  16184. break ;
  16185. }
  16186. }
  16187. if (brush !=null){
  16188. this.fillStyle=brush.fillStyle;
  16189. this.fill();
  16190. }
  16191. if (pen !=null){
  16192. this.strokeStyle=pen.strokeStyle;
  16193. this.lineWidth=pen.lineWidth || 1;
  16194. this.lineJoin=pen.lineJoin;
  16195. this.lineCap=pen.lineCap;
  16196. this.miterLimit=pen.miterLimit;
  16197. this.stroke();
  16198. }
  16199. }
  16200. __proto.clearBG=function(r,g,b,a){
  16201. var gl=WebGL.mainContext;
  16202. gl.clearColor(r,g,b,a);
  16203. gl.clear(/*laya.webgl.WebGLContext.COLOR_BUFFER_BIT*/0x00004000);
  16204. }
  16205. //TODO:coverage
  16206. __proto._getSubmits=function(){
  16207. return this._submits;
  16208. }
  16209. /**
  16210. *释放占用内存
  16211. *@param keepRT 是否保留rendertarget
  16212. */
  16213. __proto._releaseMem=function(keepRT){
  16214. (keepRT===void 0)&& (keepRT=false);
  16215. if (!this._submits)
  16216. return;
  16217. this._curMat.destroy();
  16218. this._curMat=null;
  16219. this._shader2D.destroy();
  16220. this._shader2D=null;
  16221. this._charSubmitCache.clear();
  16222. for (var i=0,n=this._submits._length;i < n;i++){
  16223. this._submits[i].releaseRender();
  16224. }
  16225. this._submits.length=0;
  16226. this._submits._length=0;
  16227. this._submits=null;
  16228. this._curSubmit=null;
  16229. this._path=null;
  16230. this._save=null;
  16231. var sz=0;
  16232. for (i=0,sz=this.meshlist.length;i < sz;i++){
  16233. var curm=this.meshlist[i];
  16234. curm.destroy();
  16235. }
  16236. this.meshlist.length=0;
  16237. this.sprite=null;
  16238. if(!keepRT){
  16239. this._targets && (this._targets.destroy());
  16240. this._targets=null;
  16241. }
  16242. }
  16243. /**
  16244. *释放所有资源
  16245. *@param keepRT 是否保留rendertarget
  16246. */
  16247. __proto.destroy=function(keepRT){
  16248. (keepRT===void 0)&& (keepRT=false);
  16249. --Context._contextcount;
  16250. this.sprite=null;
  16251. this._releaseMem(keepRT);
  16252. this._charSubmitCache.destroy();
  16253. this._mesh.destroy();
  16254. if(!keepRT){
  16255. this._targets && this._targets.destroy();
  16256. this._targets=null;
  16257. }
  16258. }
  16259. __proto.clear=function(){
  16260. if (!this._submits){
  16261. this._other=ContextParams.DEFAULT;
  16262. this._curMat=Matrix.create();
  16263. this._charSubmitCache=new CharSubmitCache();
  16264. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  16265. this.meshlist.push(this._mesh);
  16266. this._pathMesh=MeshVG.getAMesh(this.isMain);
  16267. this.meshlist.push(this._pathMesh);
  16268. this._triangleMesh=MeshTexture.getAMesh(this.isMain);
  16269. this.meshlist.push(this._triangleMesh);
  16270. this._submits=[];
  16271. this._save=[SaveMark.Create(this)];
  16272. this._save.length=10;
  16273. this._shader2D=new Shader2D();
  16274. }
  16275. this._submitKey.clear();
  16276. this._mesh.clearVB();
  16277. this._renderCount++;
  16278. this._drawCount=1;
  16279. this._other=ContextParams.DEFAULT;
  16280. this._other.lineWidth=this._shader2D.ALPHA=1.0;
  16281. this._nBlendType=0;
  16282. this._clipRect=Context.MAXCLIPRECT;
  16283. this._curSubmit=Submit.RENDERBASE;
  16284. Submit.RENDERBASE._ref=0xFFFFFF;
  16285. Submit.RENDERBASE._numEle=0;
  16286. this._shader2D.fillStyle=this._shader2D.strokeStyle=DrawStyle.DEFAULT;
  16287. for (var i=0,n=this._submits._length;i < n;i++)
  16288. this._submits[i].releaseRender();
  16289. this._submits._length=0;
  16290. this._curMat.identity();
  16291. this._other.clear();
  16292. this._saveMark=this._save[0];
  16293. this._save._length=1;
  16294. }
  16295. /**
  16296. *设置ctx的size,这个不允许直接设置,必须是canvas调过来的。所以这个函数里也不用考虑canvas相关的东西
  16297. *@param w
  16298. *@param h
  16299. */
  16300. __proto.size=function(w,h){
  16301. if (this._width !=w || this._height !=h){
  16302. this._width=w;
  16303. this._height=h;
  16304. if (this._targets){
  16305. this._targets.destroy();
  16306. this._targets=new RenderTexture2D(w,h,/*laya.resource.BaseTexture.FORMAT_R8G8B8A8*/1,-1);
  16307. }
  16308. if (Render._context==this){
  16309. WebGL.mainContext.viewport(0,0,w,h);
  16310. RenderState2D.width=w;
  16311. RenderState2D.height=h;
  16312. }
  16313. }
  16314. if (w===0 && h===0)this._releaseMem();
  16315. }
  16316. /**
  16317. *获得当前矩阵的缩放值
  16318. *避免每次都计算getScaleX
  16319. *@return
  16320. */
  16321. __proto.getMatScaleX=function(){
  16322. if (this._lastMat_a==this._curMat.a && this._lastMat_b==this._curMat.b)
  16323. return this._lastMatScaleX;
  16324. this._lastMatScaleX=this._curMat.getScaleX();
  16325. this._lastMat_a=this._curMat.a;
  16326. this._lastMat_b=this._curMat.b;
  16327. return this._lastMatScaleX;
  16328. }
  16329. __proto.getMatScaleY=function(){
  16330. if (this._lastMat_c==this._curMat.c && this._lastMat_d==this._curMat.d)
  16331. return this._lastMatScaleY;
  16332. this._lastMatScaleY=this._curMat.getScaleY();
  16333. this._lastMat_c=this._curMat.c;
  16334. this._lastMat_d=this._curMat.d;
  16335. return this._lastMatScaleY;
  16336. }
  16337. //TODO
  16338. __proto.setFillColor=function(color){
  16339. this._fillColor=color;
  16340. }
  16341. __proto.getFillColor=function(){
  16342. return this._fillColor;
  16343. }
  16344. __proto.translate=function(x,y){
  16345. if (x!==0 || y!==0){
  16346. SaveTranslate.save(this);
  16347. if (this._curMat._bTransform){
  16348. SaveTransform.save(this);
  16349. this._curMat.tx+=(x *this._curMat.a+y *this._curMat.c);
  16350. this._curMat.ty+=(x *this._curMat.b+y *this._curMat.d);
  16351. }else {
  16352. this._curMat.tx=x;
  16353. this._curMat.ty=y;
  16354. }
  16355. }
  16356. }
  16357. __proto.save=function(){
  16358. this._save[this._save._length++]=SaveMark.Create(this);
  16359. }
  16360. __proto.restore=function(){
  16361. var sz=this._save._length;
  16362. var lastBlend=this._nBlendType;
  16363. if (sz < 1)
  16364. return;
  16365. for (var i=sz-1;i >=0;i--){
  16366. var o=this._save[i];
  16367. o.restore(this);
  16368. if (o.isSaveMark()){
  16369. this._save._length=i;
  16370. return;
  16371. }
  16372. }
  16373. if (lastBlend !=this._nBlendType){
  16374. this._curSubmit=Submit.RENDERBASE;
  16375. }
  16376. }
  16377. //TODO:coverage
  16378. __proto.fillText=function(txt,x,y,fontStr,color,align){
  16379. this._fillText(txt,null,x,y,fontStr,color,null,0,null);
  16380. }
  16381. /**
  16382. *
  16383. *@param txt
  16384. *@param words HTMLChar 数组,是已经在外面排好版的一个数组
  16385. *@param x
  16386. *@param y
  16387. *@param fontStr
  16388. *@param color
  16389. *@param strokeColor
  16390. *@param lineWidth
  16391. *@param textAlign
  16392. *@param underLine
  16393. */
  16394. __proto._fillText=function(txt,words,x,y,fontStr,color,strokeColor,lineWidth,textAlign,underLine){
  16395. (underLine===void 0)&& (underLine=0);
  16396. if (txt)
  16397. Context._textRender.filltext(this,txt,x,y,fontStr,color,strokeColor,lineWidth,textAlign,underLine);
  16398. else if(words)
  16399. Context._textRender.fillWords(this,words,x,y,fontStr,color,strokeColor,lineWidth);
  16400. }
  16401. __proto._fast_filltext=function(data,x,y,fontObj,color,strokeColor,lineWidth,textAlign,underLine){
  16402. (underLine===void 0)&& (underLine=0);
  16403. Context._textRender._fast_filltext(this,data,null,x,y,fontObj,color,strokeColor,lineWidth,textAlign,underLine);
  16404. }
  16405. //TODO:coverage
  16406. __proto.fillWords=function(words,x,y,fontStr,color){
  16407. this._fillText(null,words,x,y,fontStr,color,null,-1,null,0);
  16408. }
  16409. //TODO:coverage
  16410. __proto.fillBorderWords=function(words,x,y,font,color,borderColor,lineWidth){
  16411. this._fillBorderText(null,words,x,y,font,color,borderColor,lineWidth,null);
  16412. }
  16413. __proto.drawText=function(text,x,y,font,color,textAlign){
  16414. this._fillText(text,null,x,y,font,ColorUtils.create(color).strColor,null,-1,textAlign);
  16415. }
  16416. /**
  16417. *只画边框
  16418. *@param text
  16419. *@param x
  16420. *@param y
  16421. *@param font
  16422. *@param color
  16423. *@param lineWidth
  16424. *@param textAlign
  16425. */
  16426. __proto.strokeWord=function(text,x,y,font,color,lineWidth,textAlign){
  16427. this._fillText(text,null,x,y,font,null,ColorUtils.create(color).strColor,lineWidth || 1,textAlign);
  16428. }
  16429. /**
  16430. *即画文字又画边框
  16431. *@param txt
  16432. *@param x
  16433. *@param y
  16434. *@param fontStr
  16435. *@param fillColor
  16436. *@param borderColor
  16437. *@param lineWidth
  16438. *@param textAlign
  16439. */
  16440. __proto.fillBorderText=function(txt,x,y,fontStr,fillColor,borderColor,lineWidth,textAlign){
  16441. this._fillBorderText(txt,null,x,y,fontStr,ColorUtils.create(fillColor).strColor,ColorUtils.create(borderColor).strColor,lineWidth,textAlign);
  16442. }
  16443. __proto._fillBorderText=function(txt,words,x,y,fontStr,fillColor,borderColor,lineWidth,textAlign){
  16444. this._fillText(txt,words,x,y,fontStr,fillColor,borderColor,lineWidth || 1,textAlign);
  16445. }
  16446. __proto._fillRect=function(x,y,width,height,rgba){
  16447. var submit=this._curSubmit;
  16448. var sameKey=submit && (submit._key.submitType===/*laya.webgl.submit.Submit.KEY_DRAWTEXTURE*/2 && submit._key.blendShader===this._nBlendType);
  16449. if (this._mesh.vertNum+4 > 65535){
  16450. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  16451. this.meshlist.push(this._mesh);
  16452. sameKey=false;
  16453. }
  16454. sameKey && (sameKey=sameKey&& this.isSameClipInfo(submit));
  16455. this.transformQuad(x,y,width,height,0,this._curMat,this._transedPoints);
  16456. if(!this.clipedOff(this._transedPoints)){
  16457. this._mesh.addQuad(this._transedPoints,Texture.NO_UV,rgba,false);
  16458. if (!sameKey){
  16459. submit=this._curSubmit=SubmitTexture.create(this,this._mesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  16460. this._submits[this._submits._length++]=submit;
  16461. this._copyClipInfo(submit,this._globalClipMatrix);
  16462. submit.shaderValue.textureHost=this._lastTex;
  16463. submit._key.other=(this._lastTex && this._lastTex.bitmap)?this._lastTex.bitmap.id:-1
  16464. submit._renderType=/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016;
  16465. }
  16466. this._curSubmit._numEle+=6;
  16467. this._mesh.indexNum+=6;
  16468. this._mesh.vertNum+=4;
  16469. }
  16470. }
  16471. __proto.fillRect=function(x,y,width,height,fillStyle){
  16472. var drawstyle=fillStyle? DrawStyle.create(fillStyle):this._shader2D.fillStyle;
  16473. var rgba=this.mixRGBandAlpha(drawstyle.toInt());
  16474. this._fillRect(x,y,width,height,rgba);
  16475. }
  16476. //TODO:coverage
  16477. __proto.fillTexture=function(texture,x,y,width,height,type,offset,other){
  16478. if (!texture._getSource()){
  16479. this.sprite && Laya.systemTimer.callLater(this,this._repaintSprite);
  16480. return;
  16481. }
  16482. this._fillTexture(texture,texture.width,texture.height,texture.uvrect,x,y,width,height,type,offset.x,offset.y);
  16483. }
  16484. __proto._fillTexture=function(texture,texw,texh,texuvRect,x,y,width,height,type,offsetx,offsety){
  16485. var submit=this._curSubmit;
  16486. var sameKey=false;
  16487. if (this._mesh.vertNum+4 > 65535){
  16488. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  16489. this.meshlist.push(this._mesh);
  16490. sameKey=false;
  16491. };
  16492. var repeatx=true;
  16493. var repeaty=true;
  16494. switch(type){
  16495. case "repeat":break ;
  16496. case "repeat-x":repeaty=false;break ;
  16497. case "repeat-y":repeatx=false;break ;
  16498. case "no-repeat":repeatx=repeaty=false;break ;
  16499. default :break ;
  16500. };
  16501. var uv=this._temp4Points;
  16502. var stu=0;
  16503. var stv=0;
  16504. var stx=0,sty=0,edx=0,edy=0;
  16505. if (offsetx < 0){
  16506. stx=x;
  16507. stu=(-offsetx %texw)/ texw;
  16508. }else {
  16509. stx=x+offsetx;
  16510. }
  16511. if (offsety < 0){
  16512. sty=y;
  16513. stv=(-offsety %texh)/ texh;
  16514. }else {
  16515. sty=y+offsety;
  16516. }
  16517. edx=x+width;
  16518. edy=y+height;
  16519. (!repeatx)&& (edx=Math.min(edx,x+offsetx+texw));
  16520. (!repeaty)&& (edy=Math.min(edy,y+offsety+texh));
  16521. if (edx < x || edy < y)
  16522. return;
  16523. if (stx > edx || sty > edy)
  16524. return;
  16525. var edu=(edx-x-offsetx)/texw;
  16526. var edv=(edy-y-offsety)/ texh;
  16527. this.transformQuad(stx,sty,edx-stx,edy-sty,0,this._curMat,this._transedPoints);
  16528. uv[0]=stu;uv[1]=stv;uv[2]=edu;uv[3]=stv;uv[4]=edu;uv[5]=edv;uv[6]=stu;uv[7]=edv;
  16529. if (!this.clipedOff(this._transedPoints)){
  16530. var rgba=this._mixRGBandAlpha(0xffffffff,this._shader2D.ALPHA);
  16531. this._mesh.addQuad(this._transedPoints,uv,rgba,true);
  16532. var sv=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  16533. sv.defines.add(/*laya.webgl.shader.d2.ShaderDefines2D.FILLTEXTURE*/0x100);
  16534. (sv).u_TexRange=texuvRect;
  16535. submit=this._curSubmit=SubmitTexture.create(this,this._mesh,sv);
  16536. this._submits[this._submits._length++]=submit;
  16537. this._copyClipInfo(submit,this._globalClipMatrix);
  16538. submit.shaderValue.textureHost=texture;
  16539. submit._renderType=/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016;
  16540. this._curSubmit._numEle+=6;
  16541. this._mesh.indexNum+=6;
  16542. this._mesh.vertNum+=4;
  16543. }
  16544. this.breakNextMerge();
  16545. }
  16546. /**
  16547. *反正只支持一种filter,就不要叫setFilter了,直接叫setColorFilter
  16548. *@param value
  16549. */
  16550. __proto.setColorFilter=function(filter){
  16551. SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_COLORFILTER*/0x800000,this,true);
  16552. this._colorFiler=filter;
  16553. this._curSubmit=Submit.RENDERBASE;
  16554. }
  16555. //_reCalculateBlendShader();
  16556. __proto.drawTexture=function(tex,x,y,width,height){
  16557. this._drawTextureM(tex,x,y,width,height,null,1,null);
  16558. }
  16559. __proto.drawTextures=function(tex,pos,tx,ty){
  16560. if (!tex._getSource()){
  16561. this.sprite && Laya.systemTimer.callLater(this,this._repaintSprite);
  16562. return;
  16563. };
  16564. var n=pos.length / 2;
  16565. var ipos=0;
  16566. var bmpid=tex.bitmap.id;
  16567. for (var i=0;i < n;i++){
  16568. this._inner_drawTexture(tex,bmpid,pos[ipos++]+tx,pos[ipos++]+ty,0,0,null,null,1.0,false);
  16569. }
  16570. }
  16571. //TODO:coverage
  16572. __proto._drawTextureAddSubmit=function(imgid,tex){
  16573. var submit=null;
  16574. submit=SubmitTexture.create(this,this._mesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  16575. this._submits[this._submits._length++]=submit;
  16576. submit.shaderValue.textureHost=tex;
  16577. submit._key.other=imgid;
  16578. submit._renderType=/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016;
  16579. this._curSubmit=submit;
  16580. }
  16581. //shader.ALPHA=alphaBack;
  16582. __proto._drawTextureM=function(tex,x,y,width,height,m,alpha,uv){
  16583. var cs=this.sprite;
  16584. if (!tex._getSource(function(){
  16585. if (cs){
  16586. cs.repaint();
  16587. }
  16588. })){
  16589. return false;
  16590. }
  16591. return this._inner_drawTexture(tex,tex.bitmap.id,x,y,width,height,m,uv,alpha,false);
  16592. }
  16593. __proto._drawRenderTexture=function(tex,x,y,width,height,m,alpha,uv){
  16594. return this._inner_drawTexture(tex,-1,x,y,width,height,m,uv,1.0,false);
  16595. }
  16596. //TODO:coverage
  16597. __proto.submitDebugger=function(){
  16598. this._submits[this._submits._length++]=SubmitCMD.create([],function(){debugger;},this);
  16599. }
  16600. /*
  16601. private function copyClipInfo(submit:Submit,clipInfo:Array):void {
  16602. var cd:Array=submit.shaderValue.clipDir;
  16603. cd[0]=clipInfo[2];cd[1]=clipInfo[3];cd[2]=clipInfo[4];cd[3]=clipInfo[5];
  16604. var cp:Array=submit.shaderValue.clipRect;
  16605. cp[0]=clipInfo[0];cp[1]=clipInfo[1];
  16606. submit.clipInfoID=this._clipInfoID;
  16607. }
  16608. */
  16609. __proto._copyClipInfo=function(submit,clipInfo){
  16610. var cm=submit.shaderValue.clipMatDir;
  16611. cm[0]=clipInfo.a;cm[1]=clipInfo.b;cm[2]=clipInfo.c;cm[3]=clipInfo.d;
  16612. var cmp=submit.shaderValue.clipMatPos;
  16613. cmp[0]=clipInfo.tx;cmp[1]=clipInfo.ty;
  16614. submit.clipInfoID=this._clipInfoID;
  16615. if (this._clipInCache){
  16616. submit.shaderValue.clipOff[0]=1;
  16617. }
  16618. }
  16619. __proto.isSameClipInfo=function(submit){
  16620. return (submit.clipInfoID===this._clipInfoID);
  16621. }
  16622. /**
  16623. *这个还是会检查是否合并
  16624. *@param tex
  16625. *@param minVertNum
  16626. */
  16627. __proto._useNewTex2DSubmit=function(tex,minVertNum){
  16628. if (this._mesh.vertNum+minVertNum > 65535){
  16629. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  16630. this.meshlist.push(this._mesh);
  16631. };
  16632. var submit=SubmitTexture.create(this,this._mesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  16633. this._submits[this._submits._length++]=this._curSubmit=submit;
  16634. submit.shaderValue.textureHost=tex;
  16635. this._copyClipInfo(submit,this._globalClipMatrix);
  16636. }
  16637. /**
  16638. *使用上面的设置(texture,submit,alpha,clip),画一个rect
  16639. */
  16640. __proto._drawTexRect=function(x,y,w,h,uv){
  16641. this.transformQuad(x,y,w,h,this._italicDeg,this._curMat,this._transedPoints);
  16642. var ops=this._transedPoints;
  16643. ops[0]=(ops[0]+0.5)| 0;
  16644. ops[1]=(ops[1]+0.5)| 0;
  16645. ops[2]=(ops[2]+0.5)| 0;
  16646. ops[3]=(ops[3]+0.5)| 0;
  16647. ops[4]=(ops[4]+0.5)| 0;
  16648. ops[5]=(ops[5]+0.5)| 0;
  16649. ops[6]=(ops[6]+0.5)| 0;
  16650. ops[7]=(ops[7]+0.5)| 0;
  16651. if (!this.clipedOff(this._transedPoints)){
  16652. this._mesh.addQuad(this._transedPoints,uv ,this._fillColor,true);
  16653. this._curSubmit._numEle+=6;
  16654. this._mesh.indexNum+=6;
  16655. this._mesh.vertNum+=4;
  16656. }
  16657. }
  16658. __proto.drawCallOptimize=function(enbale){
  16659. this._charSubmitCache.enable(enbale,this);
  16660. return enbale;
  16661. }
  16662. /**
  16663. *
  16664. *@param tex {Texture | RenderTexture }
  16665. *@param imgid 图片id用来比较合并的
  16666. *@param x
  16667. *@param y
  16668. *@param width
  16669. *@param height
  16670. *@param m
  16671. *@param alpha
  16672. *@param uv
  16673. *@return
  16674. */
  16675. __proto._inner_drawTexture=function(tex,imgid,x,y,width,height,m,uv,alpha,lastRender){
  16676. var preKey=this._curSubmit._key;
  16677. uv=uv || /*__JS__ */tex._uv
  16678. if (preKey.submitType===/*laya.webgl.submit.Submit.KEY_TRIANGLES*/4 && preKey.other===imgid){
  16679. var tv=this._drawTexToDrawTri_Vert;
  16680. tv[0]=x;tv[1]=y;tv[2]=x+width,tv[3]=y,tv[4]=x+width,tv[5]=y+height,tv[6]=x,tv[7]=y+height;
  16681. this._drawTriUseAbsMatrix=true;
  16682. var tuv=this._tempUV;
  16683. tuv[0]=uv[0];tuv[1]=uv[1];tuv[2]=uv[2];tuv[3]=uv[3];tuv[4]=uv[4];tuv[5]=uv[5];tuv[6]=uv[6];tuv[7]=uv[7];
  16684. this.drawTriangles(tex,0,0,tv,tuv,this._drawTexToDrawTri_Index,m,alpha,null,null);
  16685. this._drawTriUseAbsMatrix=false;
  16686. return true;
  16687. };
  16688. var mesh=this._mesh;
  16689. var submit=this._curSubmit;
  16690. var ops=lastRender?this._charSubmitCache.getPos():this._transedPoints;
  16691. this.transformQuad(x,y,width || tex.width,height || tex.height,this._italicDeg,m || this._curMat,ops);
  16692. if (this.drawTexAlign){
  16693. var round=Math.round;
  16694. ops[0]=round(ops[0]);
  16695. ops[1]=round(ops[1]);
  16696. ops[2]=round(ops[2]);
  16697. ops[3]=round(ops[3]);
  16698. ops[4]=round(ops[4]);
  16699. ops[5]=round(ops[5]);
  16700. ops[6]=round(ops[6]);
  16701. ops[7]=round(ops[7]);
  16702. this.drawTexAlign=false;
  16703. };
  16704. var rgba=this._mixRGBandAlpha(0xffffffff,this._shader2D.ALPHA *alpha);
  16705. if (lastRender){
  16706. this._charSubmitCache.add(this,tex,imgid,ops,uv ,rgba);
  16707. return true;
  16708. }
  16709. this._drawCount++;
  16710. var sameKey=imgid >=0 && preKey.submitType===/*laya.webgl.submit.Submit.KEY_DRAWTEXTURE*/2 && preKey.other===imgid;
  16711. sameKey && (sameKey=sameKey&& this.isSameClipInfo(submit));
  16712. this._lastTex=tex;
  16713. if (mesh.vertNum+4 > 65535){
  16714. mesh=this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  16715. this.meshlist.push(mesh);
  16716. sameKey=false;
  16717. }{
  16718. mesh.addQuad(ops,uv ,rgba,true);
  16719. if (!sameKey){
  16720. this._submits[this._submits._length++]=this._curSubmit=submit=SubmitTexture.create(this,mesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  16721. submit.shaderValue.textureHost=tex;
  16722. submit._key.other=imgid;
  16723. this._copyClipInfo(submit,this._globalClipMatrix);
  16724. }
  16725. submit._numEle+=6;
  16726. mesh.indexNum+=6;
  16727. mesh.vertNum+=4;
  16728. return true;
  16729. }
  16730. return false;
  16731. }
  16732. /**
  16733. *转换4个顶点。为了效率这个不做任何检查。需要调用者的配合。
  16734. *@param a 输入。8个元素表示4个点
  16735. *@param out 输出
  16736. */
  16737. __proto.transform4Points=function(a,m,out){
  16738. var tx=m.tx;
  16739. var ty=m.ty;
  16740. var ma=m.a;
  16741. var mb=m.b;
  16742. var mc=m.c;
  16743. var md=m.d;
  16744. var a0=a[0];
  16745. var a1=a[1];
  16746. var a2=a[2];
  16747. var a3=a[3];
  16748. var a4=a[4];
  16749. var a5=a[5];
  16750. var a6=a[6];
  16751. var a7=a[7];
  16752. if (m._bTransform){
  16753. out[0]=a0 *ma+a1 *mc+tx;out[1]=a0 *mb+a1 *md+ty;
  16754. out[2]=a2 *ma+a3 *mc+tx;out[3]=a2 *mb+a3 *md+ty;
  16755. out[4]=a4 *ma+a5 *mc+tx;out[5]=a4 *mb+a5 *md+ty;
  16756. out[6]=a6 *ma+a7 *mc+tx;out[7]=a6 *mb+a7 *md+ty;
  16757. }else {
  16758. out[0]=a0+tx;out[1]=a1+ty;
  16759. out[2]=a2+tx;out[3]=a3+ty;
  16760. out[4]=a4+tx;out[5]=a5+ty;
  16761. out[6]=a6+tx;out[7]=a7+ty;
  16762. }
  16763. }
  16764. /**
  16765. *pt所描述的多边形完全在clip外边,整个被裁掉了
  16766. *@param pt
  16767. *@return
  16768. */
  16769. __proto.clipedOff=function(pt){
  16770. if (this._clipRect.width <=0 || this._clipRect.height <=0)
  16771. return true;
  16772. return false;
  16773. }
  16774. /**
  16775. *应用当前矩阵。把转换后的位置放到输出数组中。
  16776. *@param x
  16777. *@param y
  16778. *@param w
  16779. *@param h
  16780. *@param italicDeg 倾斜角度,单位是度。0度无,目前是下面不动。以后要做成可调的
  16781. */
  16782. __proto.transformQuad=function(x,y,w,h,italicDeg,m,out){
  16783. var xoff=0;
  16784. if (italicDeg !=0){
  16785. xoff=Math.tan(italicDeg *Math.PI / 180)*h;
  16786. };
  16787. var maxx=x+w;var maxy=y+h;
  16788. var tx=m.tx;
  16789. var ty=m.ty;
  16790. var ma=m.a;
  16791. var mb=m.b;
  16792. var mc=m.c;
  16793. var md=m.d;
  16794. var a0=x+xoff;
  16795. var a1=y;
  16796. var a2=maxx+xoff;
  16797. var a3=y;
  16798. var a4=maxx;
  16799. var a5=maxy;
  16800. var a6=x;
  16801. var a7=maxy;
  16802. if (m._bTransform){
  16803. out[0]=a0 *ma+a1 *mc+tx;out[1]=a0 *mb+a1 *md+ty;
  16804. out[2]=a2 *ma+a3 *mc+tx;out[3]=a2 *mb+a3 *md+ty;
  16805. out[4]=a4 *ma+a5 *mc+tx;out[5]=a4 *mb+a5 *md+ty;
  16806. out[6]=a6 *ma+a7 *mc+tx;out[7]=a6 *mb+a7 *md+ty;
  16807. }else {
  16808. out[0]=a0+tx;out[1]=a1+ty;
  16809. out[2]=a2+tx;out[3]=a3+ty;
  16810. out[4]=a4+tx;out[5]=a5+ty;
  16811. out[6]=a6+tx;out[7]=a7+ty;
  16812. }
  16813. }
  16814. __proto.pushRT=function(){
  16815. this.addRenderObject(SubmitCMD.create(null,RenderTexture2D.pushRT,this));
  16816. }
  16817. __proto.popRT=function(){
  16818. this.addRenderObject(SubmitCMD.create(null,RenderTexture2D.popRT,this));
  16819. this.breakNextMerge();
  16820. }
  16821. //TODO:coverage
  16822. __proto.useRT=function(rt){
  16823. function _use (rt){
  16824. if (!rt){
  16825. throw 'error useRT'
  16826. }else{
  16827. rt.start();
  16828. rt.clear(0,0,0,0);
  16829. }
  16830. }
  16831. this.addRenderObject(SubmitCMD.create([rt],_use,this));
  16832. this.breakNextMerge();
  16833. }
  16834. //TODO:coverage
  16835. __proto.RTRestore=function(rt){
  16836. function _restore (rt){
  16837. rt.restore();
  16838. }
  16839. this.addRenderObject(SubmitCMD.create([rt],_restore,this));
  16840. this.breakNextMerge();
  16841. }
  16842. /**
  16843. *强制拒绝submit合并
  16844. *例如切换rt的时候
  16845. */
  16846. __proto.breakNextMerge=function(){
  16847. this._curSubmit=Submit.RENDERBASE;
  16848. }
  16849. //TODO:coverage
  16850. __proto._repaintSprite=function(){
  16851. this.sprite && this.sprite.repaint();
  16852. }
  16853. /**
  16854. *
  16855. *@param tex
  16856. *@param x
  16857. *@param y
  16858. *@param width
  16859. *@param height
  16860. *@param transform 图片本身希望的矩阵
  16861. *@param tx 节点的位置
  16862. *@param ty
  16863. *@param alpha
  16864. */
  16865. __proto.drawTextureWithTransform=function(tex,x,y,width,height,transform,tx,ty,alpha,blendMode,colorfilter){
  16866. var oldcomp=null;
  16867. var curMat=this._curMat;
  16868. if (blendMode){
  16869. oldcomp=this.globalCompositeOperation;
  16870. this.globalCompositeOperation=blendMode;
  16871. };
  16872. var oldColorFilter=this._colorFiler;
  16873. if (colorfilter){
  16874. this.setColorFilter(colorfilter);
  16875. }
  16876. if (!transform){
  16877. this._drawTextureM(tex,x+tx,y+ty,width,height,curMat,alpha,null);
  16878. if (blendMode){
  16879. this.globalCompositeOperation=oldcomp;
  16880. }
  16881. if (colorfilter){
  16882. this.setColorFilter(oldColorFilter);
  16883. }
  16884. return;
  16885. };
  16886. var tmpMat=this._tmpMatrix;
  16887. tmpMat.a=transform.a;tmpMat.b=transform.b;tmpMat.c=transform.c;tmpMat.d=transform.d;tmpMat.tx=transform.tx+tx;tmpMat.ty=transform.ty+ty;
  16888. tmpMat._bTransform=transform._bTransform;
  16889. if (transform && curMat._bTransform){
  16890. Matrix.mul(tmpMat,curMat,tmpMat);
  16891. transform=tmpMat;
  16892. transform._bTransform=true;
  16893. }else {
  16894. tmpMat.tx+=curMat.tx;
  16895. tmpMat.ty+=curMat.ty;
  16896. transform=tmpMat;
  16897. }
  16898. this._drawTextureM(tex,x,y,width,height,transform,alpha,null);
  16899. if (blendMode){
  16900. this.globalCompositeOperation=oldcomp;
  16901. }
  16902. if (colorfilter){
  16903. this.setColorFilter(oldColorFilter);
  16904. }
  16905. }
  16906. /**
  16907. **把ctx中的submits提交。结果渲染到target上
  16908. *@param ctx
  16909. *@param target
  16910. */
  16911. __proto._flushToTarget=function(context,target){
  16912. RenderState2D.worldScissorTest=false;
  16913. WebGL.mainContext.disable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11);
  16914. var preAlpha=RenderState2D.worldAlpha;
  16915. var preMatrix4=RenderState2D.worldMatrix4;
  16916. var preMatrix=RenderState2D.worldMatrix;
  16917. var preShaderDefines=RenderState2D.worldShaderDefines;
  16918. RenderState2D.worldMatrix=Matrix.EMPTY;
  16919. RenderState2D.restoreTempArray();
  16920. RenderState2D.worldMatrix4=RenderState2D.TEMPMAT4_ARRAY;
  16921. RenderState2D.worldAlpha=1;
  16922. BaseShader.activeShader=null;
  16923. target.start();
  16924. if(context._submits._length>0)
  16925. target.clear(0,0,0,0);
  16926. context._curSubmit=Submit.RENDERBASE;
  16927. context.flush();
  16928. context.clear();
  16929. target.restore();
  16930. context._curSubmit=Submit.RENDERBASE;
  16931. BaseShader.activeShader=null;
  16932. RenderState2D.worldAlpha=preAlpha;
  16933. RenderState2D.worldMatrix4=preMatrix4;
  16934. RenderState2D.worldMatrix=preMatrix;
  16935. }
  16936. //RenderState2D.worldShaderDefines=preShaderDefines;
  16937. __proto.drawCanvas=function(canvas,x,y,width,height){
  16938. if (!canvas)return;
  16939. var src=canvas.context;
  16940. var submit;
  16941. if (src._targets){
  16942. if (src._submits._length > 0){
  16943. submit=SubmitCMD.create([src,src._targets],this._flushToTarget,this);
  16944. this._submits[this._submits._length++]=submit;
  16945. }
  16946. this._drawRenderTexture(src._targets,x,y,width,height,null,1.0,RenderTexture2D.flipyuv);
  16947. this._curSubmit=Submit.RENDERBASE;
  16948. }else {
  16949. var canv=canvas;
  16950. if (canv.touches){
  16951. (canv.touches).forEach(function(v){v.touch();});
  16952. }
  16953. submit=SubmitCanvas.create(canvas,this._shader2D.ALPHA,this._shader2D.filters);
  16954. this._submits[this._submits._length++]=submit;
  16955. (submit)._key.clear();
  16956. var mat=(submit)._matrix;
  16957. this._curMat.copyTo(mat);
  16958. var tx=mat.tx,ty=mat.ty;
  16959. mat.tx=mat.ty=0;
  16960. mat.transformPoint(Point.TEMP.setTo(x,y));
  16961. mat.translate(Point.TEMP.x+tx,Point.TEMP.y+ty);
  16962. Matrix.mul(canv.invMat,mat,mat);
  16963. this._curSubmit=Submit.RENDERBASE;
  16964. }
  16965. }
  16966. __proto.drawTarget=function(rt,x,y,width,height,m,shaderValue,uv,blend){
  16967. (blend===void 0)&& (blend=-1);
  16968. this._drawCount++;
  16969. var rgba=0xffffffff;
  16970. if (this._mesh.vertNum+4 > 65535){
  16971. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  16972. this.meshlist.push(this._mesh);
  16973. }
  16974. this.transformQuad(x,y,width,height,0,m || this._curMat,this._transedPoints);
  16975. if(!this.clipedOff(this._transedPoints)){
  16976. this._mesh.addQuad(this._transedPoints,uv || Texture.DEF_UV,0xffffffff,true);
  16977. var submit=this._curSubmit=SubmitTarget.create(this,this._mesh,shaderValue,rt);
  16978. submit.blendType=(blend==-1)?this._nBlendType:blend;
  16979. this._copyClipInfo(submit,this._globalClipMatrix);
  16980. submit._numEle=6;
  16981. this._mesh.indexNum+=6;
  16982. this._mesh.vertNum+=4;
  16983. this._submits[this._submits._length++]=submit;
  16984. this._curSubmit=Submit.RENDERBASE
  16985. return true;
  16986. }
  16987. this._curSubmit=Submit.RENDERBASE
  16988. return false;
  16989. }
  16990. __proto.drawTriangles=function(tex,x,y,vertices,uvs,indices,matrix,alpha,color,blendMode){
  16991. if (!tex._getSource()){
  16992. if (this.sprite){
  16993. Laya.systemTimer.callLater(this,this._repaintSprite);
  16994. }
  16995. return;
  16996. }
  16997. this._drawCount++;
  16998. var tmpMat=this._tmpMatrix;
  16999. var triMesh=this._triangleMesh;
  17000. var oldColorFilter=null;
  17001. var needRestorFilter=false;
  17002. if (color){
  17003. oldColorFilter=this._colorFiler;
  17004. this._colorFiler=color;
  17005. this._curSubmit=Submit.RENDERBASE;
  17006. needRestorFilter=oldColorFilter!=color;
  17007. };
  17008. var webGLImg=tex.bitmap;
  17009. var preKey=this._curSubmit._key;
  17010. var sameKey=preKey.submitType===/*laya.webgl.submit.Submit.KEY_TRIANGLES*/4 && preKey.other===webGLImg.id && preKey.blendShader==this._nBlendType;
  17011. if (triMesh.vertNum+vertices.length / 2 > 65535){
  17012. triMesh=this._triangleMesh=MeshTexture.getAMesh(this.isMain);
  17013. this.meshlist.push(triMesh);
  17014. sameKey=false;
  17015. }
  17016. if (!sameKey){
  17017. var submit=this._curSubmit=SubmitTexture.create(this,triMesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  17018. submit.shaderValue.textureHost=tex;
  17019. submit._renderType=/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016;
  17020. submit._key.submitType=/*laya.webgl.submit.Submit.KEY_TRIANGLES*/4;
  17021. submit._key.other=webGLImg.id;
  17022. this._copyClipInfo(submit,this._globalClipMatrix);
  17023. this._submits[this._submits._length++]=submit;
  17024. };
  17025. var rgba=this._mixRGBandAlpha(0xffffffff,this._shader2D.ALPHA *alpha);
  17026. if(!this._drawTriUseAbsMatrix){
  17027. if (!matrix){
  17028. tmpMat.a=1;tmpMat.b=0;tmpMat.c=0;tmpMat.d=1;tmpMat.tx=x;tmpMat.ty=y;
  17029. }else {
  17030. tmpMat.a=matrix.a;tmpMat.b=matrix.b;tmpMat.c=matrix.c;tmpMat.d=matrix.d;tmpMat.tx=matrix.tx+x;tmpMat.ty=matrix.ty+y;
  17031. }
  17032. Matrix.mul(tmpMat,this._curMat,tmpMat);
  17033. triMesh.addData(vertices,uvs,indices,tmpMat,rgba);
  17034. }else {
  17035. triMesh.addData(vertices,uvs,indices,matrix,rgba);
  17036. }
  17037. this._curSubmit._numEle+=indices.length;
  17038. if (needRestorFilter){
  17039. this._colorFiler=oldColorFilter;
  17040. this._curSubmit=Submit.RENDERBASE;
  17041. }
  17042. }
  17043. //return true;
  17044. __proto.transform=function(a,b,c,d,tx,ty){
  17045. SaveTransform.save(this);
  17046. Matrix.mul(Matrix.TEMP.setTo(a,b,c,d,tx,ty),this._curMat,this._curMat);
  17047. this._curMat._checkTransform();
  17048. }
  17049. //TODO:coverage
  17050. __proto._transformByMatrix=function(matrix,tx,ty){
  17051. matrix.setTranslate(tx,ty);
  17052. Matrix.mul(matrix,this._curMat,this._curMat);
  17053. matrix.setTranslate(0,0);
  17054. this._curMat._bTransform=true;
  17055. }
  17056. //TODO:coverage
  17057. __proto.setTransformByMatrix=function(value){
  17058. value.copyTo(this._curMat);
  17059. }
  17060. __proto.rotate=function(angle){
  17061. SaveTransform.save(this);
  17062. this._curMat.rotateEx(angle);
  17063. }
  17064. __proto.scale=function(scaleX,scaleY){
  17065. SaveTransform.save(this);
  17066. this._curMat.scaleEx(scaleX,scaleY);
  17067. }
  17068. __proto.clipRect=function(x,y,width,height){
  17069. SaveClipRect.save(this);
  17070. if (this._clipRect==Context.MAXCLIPRECT){
  17071. this._clipRect=new Rectangle(x,y,width,height);
  17072. }else {
  17073. this._clipRect.width=width;
  17074. this._clipRect.height=height;
  17075. this._clipRect.x=x;
  17076. this._clipRect.y=y;
  17077. }
  17078. Context._clipID_Gen++;
  17079. Context._clipID_Gen %=10000;
  17080. this._clipInfoID=Context._clipID_Gen;
  17081. var cm=this._globalClipMatrix;
  17082. var minx=cm.tx;
  17083. var miny=cm.ty;
  17084. var maxx=minx+cm.a;
  17085. var maxy=miny+cm.d;
  17086. if (this._clipRect.width >=/*CLASS CONST:laya.resource.Context._MAXSIZE*/99999999){
  17087. cm.a=cm.d=/*CLASS CONST:laya.resource.Context._MAXSIZE*/99999999;
  17088. cm.b=cm.c=cm.tx=cm.ty=0;
  17089. }else {
  17090. if (this._curMat._bTransform){
  17091. cm.tx=this._clipRect.x *this._curMat.a+this._clipRect.y *this._curMat.c+this._curMat.tx;
  17092. cm.ty=this._clipRect.x *this._curMat.b+this._clipRect.y *this._curMat.d+this._curMat.ty;
  17093. cm.a=this._clipRect.width *this._curMat.a;
  17094. cm.b=this._clipRect.width *this._curMat.b;
  17095. cm.c=this._clipRect.height *this._curMat.c;
  17096. cm.d=this._clipRect.height *this._curMat.d;
  17097. }else {
  17098. cm.tx=this._clipRect.x+this._curMat.tx;
  17099. cm.ty=this._clipRect.y+this._curMat.ty;
  17100. cm.a=this._clipRect.width;
  17101. cm.b=cm.c=0;
  17102. cm.d=this._clipRect.height;
  17103. }
  17104. if (this._incache){
  17105. this._clipInCache=true;
  17106. }
  17107. }
  17108. if (cm.a > 0 && cm.d > 0){
  17109. var cmaxx=cm.tx+cm.a;
  17110. var cmaxy=cm.ty+cm.d;
  17111. if (cmaxx <=minx ||cmaxy<=miny || cm.tx>=maxx || cm.ty>=maxy){
  17112. cm.a=-0.1;cm.d=-0.1;
  17113. }else{
  17114. if (cm.tx < minx){
  17115. cm.a-=(minx-cm.tx);
  17116. cm.tx=minx;
  17117. }
  17118. if (cmaxx > maxx){
  17119. cm.a-=(cmaxx-maxx);
  17120. }
  17121. if (cm.ty < miny){
  17122. cm.d-=(miny-cm.ty);
  17123. cm.ty=miny;
  17124. }
  17125. if (cmaxy > maxy){
  17126. cm.d-=(cmaxy-maxy);
  17127. }
  17128. if (cm.a <=0)cm.a=-0.1;
  17129. if (cm.d <=0)cm.d=-0.1;
  17130. }
  17131. }
  17132. }
  17133. //TODO:coverage
  17134. __proto.drawMesh=function(x,y,ib,vb,numElement,mat,shader,shaderValues,startIndex){
  17135. (startIndex===void 0)&& (startIndex=0);
  17136. ;
  17137. }
  17138. __proto.addRenderObject=function(o){
  17139. this._submits[this._submits._length++]=o;
  17140. }
  17141. /**
  17142. *
  17143. *@param start
  17144. *@param end
  17145. */
  17146. __proto.submitElement=function(start,end){
  17147. var mainCtx=Render._context===this;
  17148. var renderList=this._submits;
  17149. var ret=(renderList)._length;
  17150. end < 0 && (end=(renderList)._length);
  17151. var submit=Submit.RENDERBASE;
  17152. while (start < end){
  17153. this._renderNextSubmitIndex=start+1;
  17154. if (renderList[start]===Submit.RENDERBASE){
  17155. start++;
  17156. continue ;
  17157. }
  17158. Submit.preRender=submit;
  17159. submit=renderList[start];
  17160. start+=submit.renderSubmit();
  17161. }
  17162. return ret;
  17163. }
  17164. __proto.flush=function(){
  17165. var ret=this.submitElement(0,this._submits._length);
  17166. this._path && this._path.reset();
  17167. SkinMeshBuffer.instance && SkinMeshBuffer.getInstance().reset();
  17168. this._curSubmit=Submit.RENDERBASE;
  17169. for (var i=0,sz=this.meshlist.length;i < sz;i++){
  17170. var curm=this.meshlist[i];
  17171. curm.canReuse?(curm.releaseMesh()):(curm.destroy());
  17172. }
  17173. this.meshlist.length=0;
  17174. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  17175. this._pathMesh=MeshVG.getAMesh(this.isMain);
  17176. this._triangleMesh=MeshTexture.getAMesh(this.isMain);
  17177. this.meshlist.push(this._mesh,this._pathMesh,this._triangleMesh);
  17178. this._flushCnt++;
  17179. if (this._flushCnt % 60==0 && Render._context==this){
  17180. if (TextRender.textRenderInst){
  17181. TextRender.textRenderInst.GC();
  17182. }
  17183. }
  17184. return ret;
  17185. }
  17186. /*******************************************start矢量绘制***************************************************/
  17187. __proto.beginPath=function(convex){
  17188. (convex===void 0)&& (convex=false);
  17189. var tPath=this._getPath();
  17190. tPath.beginPath(convex);
  17191. }
  17192. __proto.closePath=function(){
  17193. this._path.closePath();
  17194. }
  17195. /**
  17196. *添加一个path。
  17197. *@param points [x,y,x,y....] 这个会被保存下来,所以调用者需要注意复制。
  17198. *@param close 是否闭合
  17199. *@param convex 是否是凸多边形。convex的优先级是这个最大。fill的时候的次之。其实fill的时候不应该指定convex,因为可以多个path
  17200. *@param dx 需要添加的平移。这个需要在应用矩阵之前应用。
  17201. *@param dy
  17202. */
  17203. __proto.addPath=function(points,close,convex,dx,dy){
  17204. var ci=0;
  17205. for (var i=0,sz=points.length / 2;i < sz;i++){
  17206. var x1=points[ci]+dx,y1=points[ci+1]+dy;
  17207. points[ci]=x1;
  17208. points[ci+1]=y1;
  17209. ci+=2;
  17210. }
  17211. this._getPath().push(points,convex);
  17212. }
  17213. __proto.fill=function(){
  17214. var m=this._curMat;
  17215. var tPath=this._getPath();
  17216. var submit=this._curSubmit;
  17217. var sameKey=(submit._key.submitType===/*laya.webgl.submit.Submit.KEY_VG*/3 && submit._key.blendShader===this._nBlendType);
  17218. sameKey && (sameKey=sameKey&&this.isSameClipInfo(submit));
  17219. if (!sameKey){
  17220. this._curSubmit=this.addVGSubmit(this._pathMesh);
  17221. };
  17222. var rgba=this.mixRGBandAlpha(this.fillStyle.toInt());
  17223. var curEleNum=0;
  17224. var idx;
  17225. for (var i=0,sz=tPath.paths.length;i < sz;i++){
  17226. var p=tPath.paths[i];
  17227. var vertNum=p.path.length / 2;
  17228. if (vertNum < 3 ||(vertNum==3 && !p.convex))
  17229. continue ;
  17230. var cpath=p.path.concat();
  17231. var pi=0;
  17232. var xp=0,yp=0;
  17233. var _x=NaN,_y=NaN;
  17234. if (m._bTransform){
  17235. for (pi=0;pi < vertNum;pi++){
  17236. xp=pi << 1;
  17237. yp=xp+1;
  17238. _x=cpath[xp];
  17239. _y=cpath[yp];
  17240. cpath[xp]=m.a *_x+m.c *_y+m.tx;
  17241. cpath[yp]=m.b *_x+m.d *_y+m.ty;
  17242. }
  17243. }else {
  17244. for (pi=0;pi < vertNum;pi++){
  17245. xp=pi << 1;
  17246. yp=xp+1;
  17247. _x=cpath[xp];
  17248. _y=cpath[yp];
  17249. cpath[xp]=_x+m.tx;
  17250. cpath[yp]=_y+m.ty;
  17251. }
  17252. }
  17253. if (this._pathMesh.vertNum+vertNum > 65535){
  17254. this._curSubmit._numEle+=curEleNum;
  17255. curEleNum=0;
  17256. this._pathMesh=MeshVG.getAMesh(this.isMain);
  17257. this._curSubmit=this.addVGSubmit(this._pathMesh);
  17258. };
  17259. var curvert=this._pathMesh.vertNum;
  17260. if (p.convex){
  17261. var faceNum=vertNum-2;
  17262. idx=new Array(faceNum *3);
  17263. var idxpos=0;
  17264. for (var fi=0;fi < faceNum;fi++){
  17265. idx[idxpos++]=curvert;
  17266. idx[idxpos++]=fi+1+curvert;
  17267. idx[idxpos++]=fi+2+curvert;
  17268. }
  17269. }
  17270. else {
  17271. idx=Earcut.earcut(cpath,null,2);
  17272. if (curvert > 0){
  17273. for (var ii=0;ii < idx.length;ii++){
  17274. idx[ii]+=curvert;
  17275. }
  17276. }
  17277. }
  17278. this._pathMesh.addVertAndIBToMesh(this,cpath,rgba,idx);
  17279. curEleNum+=idx.length;
  17280. }
  17281. this._curSubmit._numEle+=curEleNum;
  17282. }
  17283. __proto.addVGSubmit=function(mesh){
  17284. var submit=Submit.createShape(this,mesh,0,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.PRIMITIVE*/0x04,0));
  17285. submit._key.submitType=/*laya.webgl.submit.Submit.KEY_VG*/3;
  17286. this._submits[this._submits._length++]=submit;
  17287. this._copyClipInfo(submit,this._globalClipMatrix);
  17288. return submit;
  17289. }
  17290. __proto.stroke=function(){
  17291. if (this.lineWidth > 0){
  17292. var rgba=this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  17293. var tPath=this._getPath();
  17294. var submit=this._curSubmit;
  17295. var sameKey=(submit._key.submitType===/*laya.webgl.submit.Submit.KEY_VG*/3 && submit._key.blendShader===this._nBlendType);
  17296. sameKey && (sameKey=sameKey&& this.isSameClipInfo(submit));
  17297. if (!sameKey){
  17298. this._curSubmit=this.addVGSubmit(this._pathMesh);
  17299. };
  17300. var curEleNum=0;
  17301. for (var i=0,sz=tPath.paths.length;i < sz;i++){
  17302. var p=tPath.paths[i];
  17303. if (p.path.length <=0)
  17304. continue ;
  17305. var idx=[];
  17306. var vertex=[];
  17307. var maxVertexNum=p.path.length *2;
  17308. if (maxVertexNum < 2)
  17309. continue ;
  17310. if (this._pathMesh.vertNum+maxVertexNum > 65535){
  17311. this._curSubmit._numEle+=curEleNum;
  17312. curEleNum=0;
  17313. this._pathMesh=MeshVG.getAMesh(this.isMain);
  17314. this.meshlist.push(this._pathMesh);
  17315. this._curSubmit=this.addVGSubmit(this._pathMesh);
  17316. }
  17317. BasePoly.createLine2(p.path,idx,this.lineWidth,this._pathMesh.vertNum,vertex,p.loop);
  17318. var ptnum=vertex.length / 2;
  17319. var m=this._curMat;
  17320. var pi=0;
  17321. var xp=0,yp=0;
  17322. var _x=NaN,_y=NaN;
  17323. if (m._bTransform){
  17324. for (pi=0;pi < ptnum;pi++){
  17325. xp=pi << 1;
  17326. yp=xp+1;
  17327. _x=vertex[xp];
  17328. _y=vertex[yp];
  17329. vertex[xp]=m.a *_x+m.c *_y+m.tx;
  17330. vertex[yp]=m.b *_x+m.d *_y+m.ty;
  17331. }
  17332. }else {
  17333. for (pi=0;pi < ptnum;pi++){
  17334. xp=pi << 1;
  17335. yp=xp+1;
  17336. _x=vertex[xp];
  17337. _y=vertex[yp];
  17338. vertex[xp]=_x+m.tx;
  17339. vertex[yp]=_y+m.ty;
  17340. }
  17341. }
  17342. this._pathMesh.addVertAndIBToMesh(this,vertex,rgba,idx);
  17343. curEleNum+=idx.length;
  17344. }
  17345. this._curSubmit._numEle+=curEleNum;
  17346. }
  17347. }
  17348. __proto.moveTo=function(x,y){
  17349. var tPath=this._getPath();
  17350. tPath.newPath();
  17351. tPath._lastOriX=x;
  17352. tPath._lastOriY=y;
  17353. tPath.addPoint(x,y);
  17354. }
  17355. /**
  17356. *
  17357. *@param x
  17358. *@param y
  17359. *@param b 是否应用矩阵
  17360. */
  17361. __proto.lineTo=function(x,y){
  17362. var tPath=this._getPath();
  17363. if (Math.abs(x-tPath._lastOriX)<1e-3 && Math.abs(y-tPath._lastOriY)<1e-3)
  17364. return;
  17365. tPath._lastOriX=x;
  17366. tPath._lastOriY=y;
  17367. tPath.addPoint(x,y);
  17368. }
  17369. /*
  17370. public function drawCurves(x:Number,y:Number,points:Array,lineColor:*,lineWidth:Number=1):void {
  17371. //setPathId(-1);
  17372. beginPath();
  17373. strokeStyle=lineColor;
  17374. this.lineWidth=lineWidth;
  17375. var points:Array=points;
  17376. //movePath(x,y);TODO 这个被去掉了
  17377. moveTo(points[0],points[1]);
  17378. var i:int=2,n:int=points.length;
  17379. while (i < n){
  17380. quadraticCurveTo(points[i++],points[i++],points[i++],points[i++]);
  17381. }
  17382. stroke();
  17383. }
  17384. */
  17385. __proto.arcTo=function(x1,y1,x2,y2,r){
  17386. var i=0;
  17387. var x=0,y=0;
  17388. var dx=this._path._lastOriX-x1;
  17389. var dy=this._path._lastOriY-y1;
  17390. var len1=Math.sqrt(dx*dx+dy*dy);
  17391. if (len1 <=0.000001){
  17392. return;
  17393. };
  17394. var ndx=dx / len1;
  17395. var ndy=dy / len1;
  17396. var dx2=x2-x1;
  17397. var dy2=y2-y1;
  17398. var len22=dx2*dx2+dy2*dy2;
  17399. var len2=Math.sqrt(len22);
  17400. if (len2 <=0.000001){
  17401. return;
  17402. };
  17403. var ndx2=dx2 / len2;
  17404. var ndy2=dy2 / len2;
  17405. var odx=ndx+ndx2;
  17406. var ody=ndy+ndy2;
  17407. var olen=Math.sqrt(odx*odx+ody*ody);
  17408. if (olen <=0.000001){
  17409. return;
  17410. };
  17411. var nOdx=odx / olen;
  17412. var nOdy=ody / olen;
  17413. var alpha=Math.acos(nOdx*ndx+nOdy*ndy);
  17414. var halfAng=Math.PI / 2-alpha;
  17415. len1=r / Math.tan(halfAng);
  17416. var ptx1=len1*ndx+x1;
  17417. var pty1=len1*ndy+y1;
  17418. var orilen=Math.sqrt(len1 *len1+r *r);
  17419. var orix=x1+nOdx*orilen;
  17420. var oriy=y1+nOdy*orilen;
  17421. var ptx2=len1*ndx2+x1;
  17422. var pty2=len1*ndy2+y1;
  17423. var dir=ndx *ndy2-ndy *ndx2;
  17424. var fChgAng=0;
  17425. var sinx=0.0;
  17426. var cosx=0.0;
  17427. if (dir >=0){
  17428. fChgAng=halfAng *2;
  17429. var fda=fChgAng / Context.SEGNUM;
  17430. sinx=Math.sin(fda);
  17431. cosx=Math.cos(fda);
  17432. }
  17433. else {
  17434. fChgAng=-halfAng *2;
  17435. fda=fChgAng / Context.SEGNUM;
  17436. sinx=Math.sin(fda);
  17437. cosx=Math.cos(fda);
  17438. };
  17439. var lastx=this._path._lastOriX,lasty=this._path._lastOriY;
  17440. var _x1=ptx1 ,_y1=pty1;
  17441. if (Math.abs(_x1-this._path._lastOriX)>0.1 || Math.abs(_y1-this._path._lastOriY)>0.1){
  17442. x=_x1;
  17443. y=_y1;
  17444. lastx=_x1;
  17445. lasty=_y1;
  17446. this._path.addPoint(x,y);
  17447. };
  17448. var cvx=ptx1-orix;
  17449. var cvy=pty1-oriy;
  17450. var tx=0.0;
  17451. var ty=0.0;
  17452. for (i=0;i < Context.SEGNUM;i++){
  17453. var cx=cvx*cosx+cvy*sinx;
  17454. var cy=-cvx*sinx+cvy*cosx;
  17455. x=cx+orix;
  17456. y=cy+oriy;
  17457. if (Math.abs(lastx-x)>0.1 || Math.abs(lasty-y)>0.1){
  17458. this._path.addPoint(x,y);
  17459. lastx=x;
  17460. lasty=y;
  17461. }
  17462. cvx=cx;
  17463. cvy=cy;
  17464. }
  17465. }
  17466. __proto.arc=function(cx,cy,r,startAngle,endAngle,counterclockwise,b){
  17467. (counterclockwise===void 0)&& (counterclockwise=false);
  17468. (b===void 0)&& (b=true);
  17469. var a=0,da=0,hda=0,kappa=0;
  17470. var dx=0,dy=0,x=0,y=0,tanx=0,tany=0;
  17471. var px=0,py=0,ptanx=0,ptany=0;
  17472. var i=0,ndivs=0,nvals=0;
  17473. da=endAngle-startAngle;
  17474. if (!counterclockwise){
  17475. if (Math.abs(da)>=Math.PI *2){
  17476. da=Math.PI *2;
  17477. }else {
  17478. while (da < 0.0){
  17479. da+=Math.PI *2;
  17480. }
  17481. }
  17482. }else {
  17483. if (Math.abs(da)>=Math.PI *2){
  17484. da=-Math.PI *2;
  17485. }else {
  17486. while (da > 0.0){
  17487. da-=Math.PI *2;
  17488. }
  17489. }
  17490. };
  17491. var sx=this.getMatScaleX();
  17492. var sy=this.getMatScaleY();
  17493. var sr=r *(sx > sy?sx:sy);
  17494. var cl=2 *Math.PI *sr;
  17495. ndivs=(Math.max(cl / 10,10))|0;
  17496. hda=(da / ndivs)/ 2.0;
  17497. kappa=Math.abs(4 / 3 *(1-Math.cos(hda))/ Math.sin(hda));
  17498. if (counterclockwise)
  17499. kappa=-kappa;
  17500. nvals=0;
  17501. var tPath=this._getPath();
  17502. var _x1=NaN,_y1=NaN;
  17503. for (i=0;i <=ndivs;i++){
  17504. a=startAngle+da *(i / ndivs);
  17505. dx=Math.cos(a);
  17506. dy=Math.sin(a);
  17507. x=cx+dx *r;
  17508. y=cy+dy *r;
  17509. if (x !=this._path._lastOriX || y !=this._path._lastOriY){
  17510. tPath.addPoint(x,y);
  17511. }
  17512. }
  17513. dx=Math.cos(endAngle);
  17514. dy=Math.sin(endAngle);
  17515. x=cx+dx *r;
  17516. y=cy+dy *r;
  17517. if (x !=this._path._lastOriX|| y !=this._path._lastOriY){
  17518. tPath.addPoint(x,y);
  17519. }
  17520. }
  17521. __proto.quadraticCurveTo=function(cpx,cpy,x,y){
  17522. var tBezier=Bezier.I;
  17523. var tResultArray=[];
  17524. var tArray=tBezier.getBezierPoints([this._path._lastOriX,this._path._lastOriY,cpx,cpy,x,y],30,2);
  17525. for (var i=0,n=tArray.length / 2;i < n;i++){
  17526. this.lineTo(tArray[i *2],tArray[i *2+1]);
  17527. }
  17528. this.lineTo(x,y);
  17529. }
  17530. /**
  17531. *把颜色跟当前设置的alpha混合
  17532. *@return
  17533. */
  17534. __proto.mixRGBandAlpha=function(color){
  17535. return this._mixRGBandAlpha(color,this._shader2D.ALPHA);
  17536. }
  17537. __proto._mixRGBandAlpha=function(color,alpha){
  17538. if (alpha >=1){
  17539. return color;
  17540. };
  17541. var a=((color & 0xff000000)>>> 24);
  17542. if (a !=0){
  17543. a*=alpha;
  17544. }else {
  17545. a=alpha*255;
  17546. }
  17547. return (color & 0x00ffffff)| (a << 24);
  17548. }
  17549. __proto.strokeRect=function(x,y,width,height,parameterLineWidth){
  17550. var tW=parameterLineWidth *0.5;
  17551. if (this.lineWidth > 0){
  17552. var rgba=this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  17553. var hw=this.lineWidth / 2;
  17554. this._fillRect(x-hw,y-hw,width+this.lineWidth,this.lineWidth,rgba);
  17555. this._fillRect(x-hw,y-hw+height,width+this.lineWidth,this.lineWidth,rgba);
  17556. this._fillRect(x-hw,y+hw,this.lineWidth,height-this.lineWidth,rgba);
  17557. this._fillRect(x-hw+width,y+hw,this.lineWidth,height-this.lineWidth,rgba);
  17558. }
  17559. }
  17560. //右
  17561. __proto.clip=function(){}
  17562. //TODO:coverage
  17563. __proto.drawParticle=function(x,y,pt){
  17564. pt.x=x;
  17565. pt.y=y;
  17566. this._submits[this._submits._length++]=pt;
  17567. }
  17568. __proto._getPath=function(){
  17569. return this._path || (this._path=new Path());
  17570. }
  17571. /**
  17572. *专用函数。通过循环创建来水平填充
  17573. *@param tex
  17574. *@param bmpid
  17575. *@param uv 希望循环的部分的uv
  17576. *@param oriw
  17577. *@param orih
  17578. *@param x
  17579. *@param y
  17580. *@param w
  17581. */
  17582. __proto._fillTexture_h=function(tex,imgid,uv,oriw,orih,x,y,w){
  17583. var stx=x;
  17584. var num=Math.floor(w / oriw);
  17585. var left=w % oriw;
  17586. for (var i=0;i < num;i++){
  17587. this._inner_drawTexture(tex,imgid,stx,y,oriw,orih,this._curMat,uv,1,false);
  17588. stx+=oriw;
  17589. }
  17590. if (left > 0){
  17591. var du=uv[2]-uv[0];
  17592. var uvr=uv[0]+du *(left / oriw);
  17593. var tuv=Context.tmpuv1;
  17594. tuv[0]=uv[0];tuv[1]=uv[1];tuv[2]=uvr;tuv[3]=uv[3];
  17595. tuv[4]=uvr;tuv[5]=uv[5];tuv[6]=uv[6];tuv[7]=uv[7];
  17596. this._inner_drawTexture(tex,imgid,stx,y,left,orih,this._curMat,tuv,1,false);
  17597. }
  17598. }
  17599. /**
  17600. *专用函数。通过循环创建来垂直填充
  17601. *@param tex
  17602. *@param imgid
  17603. *@param uv
  17604. *@param oriw
  17605. *@param orih
  17606. *@param x
  17607. *@param y
  17608. *@param h
  17609. */
  17610. __proto._fillTexture_v=function(tex,imgid,uv,oriw,orih,x,y,h){
  17611. var sty=y;
  17612. var num=Math.floor(h / orih);
  17613. var left=h % orih;
  17614. for (var i=0;i < num;i++){
  17615. this._inner_drawTexture(tex,imgid,x,sty,oriw,orih,this._curMat,uv,1,false);
  17616. sty+=orih;
  17617. }
  17618. if (left > 0){
  17619. var dv=uv[7]-uv[1];
  17620. var uvb=uv[1]+dv *(left / orih);
  17621. var tuv=Context.tmpuv1;
  17622. tuv[0]=uv[0];tuv[1]=uv[1];tuv[2]=uv[2];tuv[3]=uv[3];
  17623. tuv[4]=uv[4];tuv[5]=uvb;tuv[6]=uv[6];tuv[7]=uvb;
  17624. this._inner_drawTexture(tex,imgid,x,sty,oriw,left,this._curMat,tuv,1,false);
  17625. }
  17626. }
  17627. __proto.drawTextureWithSizeGrid=function(tex,tx,ty,width,height,sizeGrid,gx,gy){
  17628. if (!tex._getSource())
  17629. return;
  17630. tx+=gx;
  17631. ty+=gy;
  17632. var uv=tex.uv,w=tex.bitmap.width,h=tex.bitmap.height;
  17633. var top=sizeGrid[0];
  17634. var left=sizeGrid[3];
  17635. var d_top=top / h;
  17636. var d_left=left / w;
  17637. var right=sizeGrid[1];
  17638. var bottom=sizeGrid[2];
  17639. var d_right=right / w;
  17640. var d_bottom=bottom / h;
  17641. var repeat=sizeGrid[4];
  17642. var needClip=false;
  17643. if (width==w){
  17644. left=right=0;
  17645. }
  17646. if (height==h){
  17647. top=bottom=0;
  17648. }
  17649. if (left+right > width){
  17650. var clipWidth=width;
  17651. needClip=true;
  17652. width=left+right;
  17653. this.save();
  17654. this.clipRect(0+tx,0+ty,clipWidth,height);
  17655. };
  17656. var imgid=tex.bitmap.id;
  17657. var mat=this._curMat;
  17658. var tuv=this._tempUV;
  17659. var uvl=uv[0];
  17660. var uvt=uv[1];
  17661. var uvr=uv[4];
  17662. var uvb=uv[5];
  17663. var uvl_=uvl;
  17664. var uvt_=uvt;
  17665. var uvr_=uvr;
  17666. var uvb_=uvb;
  17667. if(left && top){
  17668. uvr_=uvl+d_left;
  17669. uvb_=uvt+d_top;
  17670. tuv[0]=uvl,tuv[1]=uvt,tuv[2]=uvr_,tuv[3]=uvt,
  17671. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl,tuv[7]=uvb_;
  17672. this._inner_drawTexture(tex,imgid,tx,ty,left,top,mat,tuv,1,false);
  17673. }
  17674. if (right && top){
  17675. uvl_=uvr-d_right;uvt_=uvt;
  17676. uvr_=uvr;uvb_=uvt+d_top;
  17677. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  17678. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  17679. this._inner_drawTexture(tex,imgid,width-right+tx,0+ty,right,top,mat,tuv,1,false);
  17680. }
  17681. if (left && bottom){
  17682. uvl_=uvl;uvt_=uvb-d_bottom;
  17683. uvr_=uvl+d_left;uvb_=uvb;
  17684. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  17685. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  17686. this._inner_drawTexture(tex,imgid,0+tx,height-bottom+ty,left,bottom,mat,tuv,1,false);
  17687. }
  17688. if (right && bottom){
  17689. uvl_=uvr-d_right;uvt_=uvb-d_bottom;
  17690. uvr_=uvr;uvb_=uvb;
  17691. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  17692. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  17693. this._inner_drawTexture(tex,imgid,width-right+tx,height-bottom+ty,right,bottom,mat,tuv,1,false);
  17694. }
  17695. if (top){
  17696. uvl_=uvl+d_left;uvt_=uvt;
  17697. uvr_=uvr-d_right;uvb_=uvt+d_top;
  17698. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  17699. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  17700. if (repeat){
  17701. this._fillTexture_h(tex,imgid,tuv,tex.width-left-right,top,left+tx,ty,width-left-right);
  17702. }else {
  17703. this._inner_drawTexture(tex,imgid,left+tx,ty,width-left-right,top,mat,tuv,1,false);
  17704. }
  17705. }
  17706. if (bottom){
  17707. uvl_=uvl+d_left;uvt_=uvb-d_bottom;
  17708. uvr_=uvr-d_right;uvb_=uvb;
  17709. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  17710. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  17711. if (repeat){
  17712. this._fillTexture_h(tex,imgid,tuv,tex.width-left-right,bottom,left+tx,height-bottom+ty,width-left-right);
  17713. }else{
  17714. this._inner_drawTexture(tex,imgid,left+tx,height-bottom+ty,width-left-right,bottom,mat,tuv,1,false);
  17715. }
  17716. }
  17717. if (left){
  17718. uvl_=uvl;uvt_=uvt+d_top;
  17719. uvr_=uvl+d_left;uvb_=uvb-d_bottom;
  17720. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  17721. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  17722. if (repeat){
  17723. this._fillTexture_v(tex,imgid,tuv,left,tex.height-top-bottom,tx,top+ty,height-top-bottom);
  17724. }else{
  17725. this._inner_drawTexture(tex,imgid,tx,top+ty,left,height-top-bottom,mat,tuv,1,false);
  17726. }
  17727. }
  17728. if (right){
  17729. uvl_=uvr-d_right;uvt_=uvt+d_top;
  17730. uvr_=uvr;uvb_=uvb-d_bottom;
  17731. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  17732. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  17733. if (repeat){
  17734. this._fillTexture_v(tex,imgid,tuv,right,tex.height-top-bottom,width-right+tx,top+ty,height-top-bottom);
  17735. }else{
  17736. this._inner_drawTexture(tex,imgid,width-right+tx,top+ty,right,height-top-bottom,mat,tuv,1,false);
  17737. }
  17738. }
  17739. uvl_=uvl+d_left;uvt_=uvt+d_top;
  17740. uvr_=uvr-d_right;uvb_=uvb-d_bottom;
  17741. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  17742. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  17743. if (repeat){
  17744. var tuvr=Context.tmpUVRect;
  17745. tuvr[0]=uvl_;tuvr[1]=uvt_;
  17746. tuvr[2]=uvr_-uvl_;tuvr[3]=uvb_-uvt_;
  17747. this._fillTexture(tex,tex.width-left-right,tex.height-top-bottom,tuvr,left+tx,top+ty,width-left-right,height-top-bottom,'repeat',0,0);
  17748. }else{
  17749. this._inner_drawTexture(tex,imgid,left+tx,top+ty,width-left-right,height-top-bottom,mat,tuv,1,false);
  17750. }
  17751. if (needClip)this.restore();
  17752. }
  17753. __getset(0,__proto,'textAlign',function(){
  17754. return this._other.textAlign;
  17755. },function(value){
  17756. (this._other.textAlign===value)|| (this._other=this._other.make(),SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_TEXTALIGN*/0x8000,this._other,false),this._other.textAlign=value);
  17757. });
  17758. /**@private */
  17759. /**@private */
  17760. __getset(0,__proto,'lineJoin',function(){
  17761. return null;
  17762. },function(value){
  17763. });
  17764. __getset(0,__proto,'fillStyle',function(){
  17765. return this._shader2D.fillStyle;
  17766. },function(value){
  17767. if (!this._shader2D.fillStyle.equal(value)){
  17768. SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_FILESTYLE*/0x2,this._shader2D,false);
  17769. this._shader2D.fillStyle=DrawStyle.create(value);
  17770. this._submitKey.other=-this._shader2D.fillStyle.toInt();
  17771. }
  17772. });
  17773. /**@private */
  17774. /**@private */
  17775. __getset(0,__proto,'lineCap',function(){
  17776. return null;
  17777. },function(value){
  17778. });
  17779. /**@private */
  17780. /**@private */
  17781. __getset(0,__proto,'miterLimit',function(){
  17782. return null;
  17783. },function(value){
  17784. });
  17785. __getset(0,__proto,'strokeStyle',function(){
  17786. return this._shader2D.strokeStyle;
  17787. },function(value){
  17788. this._shader2D.strokeStyle.equal(value)|| (SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_STROKESTYLE*/0x200,this._shader2D,false),this._shader2D.strokeStyle=DrawStyle.create(value),this._submitKey.other=-this._shader2D.strokeStyle.toInt());
  17789. });
  17790. /*,_shader2D.ALPHA=1*/
  17791. __getset(0,__proto,'globalCompositeOperation',function(){
  17792. return BlendMode.NAMES[this._nBlendType];
  17793. },function(value){
  17794. var n=BlendMode.TOINT[value];
  17795. n==null || (this._nBlendType===n)|| (SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_GLOBALCOMPOSITEOPERATION*/0x10000,this,true),this._curSubmit=Submit.RENDERBASE,this._nBlendType=n);
  17796. });
  17797. __getset(0,__proto,'globalAlpha',function(){
  17798. return this._shader2D.ALPHA;
  17799. },function(value){
  17800. value=Math.floor(value *1000)/ 1000;
  17801. if (value !=this._shader2D.ALPHA){
  17802. SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_ALPHA*/0x1,this._shader2D,false);
  17803. this._shader2D.ALPHA=value;
  17804. }
  17805. });
  17806. /**
  17807. *当前canvas请求保存渲染结果。
  17808. *实现:
  17809. *如果value==true,就要给_target赋值
  17810. *@param value {Boolean}
  17811. */
  17812. __getset(0,__proto,'asBitmap',null,function(value){
  17813. if (value){
  17814. this._targets || (this._targets=new RenderTexture2D(this._width,this._height,/*laya.resource.BaseTexture.FORMAT_R8G8B8A8*/1,-1));
  17815. if (!this._width || !this._height)
  17816. throw Error("asBitmap no size!");
  17817. }else {
  17818. this._targets && this._targets.destroy();
  17819. this._targets=null;
  17820. }
  17821. });
  17822. __getset(0,__proto,'textBaseline',function(){
  17823. return this._other.textBaseline;
  17824. },function(value){
  17825. (this._other.textBaseline===value)|| (this._other=this._other.make(),SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_TEXTBASELINE*/0x4000,this._other,false),this._other.textBaseline=value);
  17826. });
  17827. __getset(0,__proto,'lineWidth',function(){
  17828. return this._other.lineWidth;
  17829. },function(value){
  17830. (this._other.lineWidth===value)|| (this._other=this._other.make(),SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_LINEWIDTH*/0x100,this._other,false),this._other.lineWidth=value);
  17831. });
  17832. __getset(0,__proto,'font',null,function(str){
  17833. this._other=this._other.make();
  17834. SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_FONT*/0x8,this._other,false);
  17835. });
  17836. //注意这个是对外接口
  17837. __getset(0,__proto,'canvas',function(){
  17838. return this._canvas;
  17839. });
  17840. Context.__init__=function(){
  17841. Context.MAXCLIPRECT=new Rectangle(0,0,99999999,99999999);
  17842. ContextParams.DEFAULT=new ContextParams();
  17843. WebGLCacheAsNormalCanvas;
  17844. }
  17845. Context.set2DRenderConfig=function(){
  17846. var gl=LayaGL.instance;
  17847. WebGLContext.setBlend(gl,true);
  17848. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  17849. WebGLContext.setDepthTest(gl,false);
  17850. WebGLContext.setCullFace(gl,false);
  17851. WebGLContext.setDepthMask(gl,true);
  17852. WebGLContext.setFrontFace(gl,/*laya.webgl.WebGLContext.CCW*/0x0901);
  17853. gl.viewport(0,0,RenderState2D.width,RenderState2D.height);
  17854. }
  17855. Context.ENUM_TEXTALIGN_DEFAULT=0;
  17856. Context.ENUM_TEXTALIGN_CENTER=1;
  17857. Context.ENUM_TEXTALIGN_RIGHT=2;
  17858. Context._SUBMITVBSIZE=32000;
  17859. Context._MAXSIZE=99999999;
  17860. Context._MAXVERTNUM=65535;
  17861. Context.MAXCLIPRECT=null;
  17862. Context._COUNT=0;
  17863. Context.SEGNUM=32;
  17864. Context._contextcount=0;
  17865. Context.PI2=2 *Math.PI;
  17866. Context._clipID_Gen=0;
  17867. __static(Context,
  17868. ['_textRender',function(){return this._textRender=new TextRender();},'tmpuv1',function(){return this.tmpuv1=[0,0,0,0,0,0,0,0];},'tmpUV',function(){return this.tmpUV=[0,0,0,0,0,0,0,0];},'tmpUVRect',function(){return this.tmpUVRect=[0,0,0,0];}
  17869. ]);
  17870. Context.__init$=function(){
  17871. //class ContextParams
  17872. ContextParams=(function(){
  17873. function ContextParams(){
  17874. this.lineWidth=1;
  17875. this.textAlign=null;
  17876. this.textBaseline=null;
  17877. }
  17878. __class(ContextParams,'');
  17879. var __proto=ContextParams.prototype;
  17880. __proto.clear=function(){
  17881. this.lineWidth=1;
  17882. this.textAlign=this.textBaseline=null;
  17883. }
  17884. __proto.make=function(){
  17885. return this===ContextParams.DEFAULT ? new ContextParams():this;
  17886. }
  17887. ContextParams.DEFAULT=null;
  17888. return ContextParams;
  17889. })()
  17890. }
  17891. return Context;
  17892. })()
  17893. /**
  17894. *旋转命令
  17895. */
  17896. //class laya.display.cmd.RotateCmd
  17897. var RotateCmd=(function(){
  17898. function RotateCmd(){
  17899. /**
  17900. *旋转角度,以弧度计。
  17901. */
  17902. //this.angle=NaN;
  17903. /**
  17904. *(可选)水平方向轴心点坐标。
  17905. */
  17906. //this.pivotX=NaN;
  17907. /**
  17908. *(可选)垂直方向轴心点坐标。
  17909. */
  17910. //this.pivotY=NaN;
  17911. }
  17912. __class(RotateCmd,'laya.display.cmd.RotateCmd');
  17913. var __proto=RotateCmd.prototype;
  17914. /**
  17915. *回收到对象池
  17916. */
  17917. __proto.recover=function(){
  17918. Pool.recover("RotateCmd",this);
  17919. }
  17920. /**@private */
  17921. __proto.run=function(context,gx,gy){
  17922. context._rotate(this.angle,this.pivotX+gx,this.pivotY+gy);
  17923. }
  17924. /**@private */
  17925. __getset(0,__proto,'cmdID',function(){
  17926. return "Rotate";
  17927. });
  17928. RotateCmd.create=function(angle,pivotX,pivotY){
  17929. var cmd=Pool.getItemByClass("RotateCmd",RotateCmd);
  17930. cmd.angle=angle;
  17931. cmd.pivotX=pivotX;
  17932. cmd.pivotY=pivotY;
  17933. return cmd;
  17934. }
  17935. RotateCmd.ID="Rotate";
  17936. return RotateCmd;
  17937. })()
  17938. /**
  17939. *绘制带九宫格信息的图片
  17940. *@private
  17941. */
  17942. //class laya.display.cmd.Draw9GridTexture
  17943. var Draw9GridTexture=(function(){
  17944. function Draw9GridTexture(){
  17945. /**
  17946. *纹理。
  17947. */
  17948. //this.texture=null;
  17949. /**
  17950. *(可选)X轴偏移量。
  17951. */
  17952. //this.x=NaN;
  17953. /**
  17954. *(可选)Y轴偏移量。
  17955. */
  17956. //this.y=NaN;
  17957. /**
  17958. *(可选)宽度。
  17959. */
  17960. //this.width=NaN;
  17961. /**
  17962. *(可选)高度。
  17963. */
  17964. //this.height=NaN;
  17965. //this.sizeGrid=null;
  17966. }
  17967. __class(Draw9GridTexture,'laya.display.cmd.Draw9GridTexture');
  17968. var __proto=Draw9GridTexture.prototype;
  17969. /**
  17970. *回收到对象池
  17971. */
  17972. __proto.recover=function(){
  17973. this.texture._removeReference();
  17974. Pool.recover("Draw9GridTexture",this);
  17975. }
  17976. /**@private */
  17977. __proto.run=function(context,gx,gy){
  17978. context.drawTextureWithSizeGrid(this.texture,this.x,this.y,this.width,this.height,this.sizeGrid,gx,gy);
  17979. }
  17980. /**@private */
  17981. __getset(0,__proto,'cmdID',function(){
  17982. return "Draw9GridTexture";
  17983. });
  17984. Draw9GridTexture.create=function(texture,x,y,width,height,sizeGrid){
  17985. var cmd=Pool.getItemByClass("Draw9GridTexture",Draw9GridTexture);
  17986. cmd.texture=texture;
  17987. texture._addReference();
  17988. cmd.x=x;
  17989. cmd.y=y;
  17990. cmd.width=width;
  17991. cmd.height=height;
  17992. cmd.sizeGrid=sizeGrid;
  17993. return cmd;
  17994. }
  17995. Draw9GridTexture.ID="Draw9GridTexture";
  17996. return Draw9GridTexture;
  17997. })()
  17998. /**
  17999. *@private 场景辅助类
  18000. */
  18001. //class laya.utils.SceneUtils
  18002. var SceneUtils=(function(){
  18003. var DataWatcher,InitTool;
  18004. function SceneUtils(){}
  18005. __class(SceneUtils,'laya.utils.SceneUtils');
  18006. SceneUtils.getBindFun=function(value){
  18007. var fun=SceneUtils._funMap.get(value);
  18008. if (fun==null){
  18009. var temp="\""+value+"\"";
  18010. temp=temp.replace(/^"\${|}"$/g,"").replace(/\${/g,"\"+").replace(/}/g,"+\"");
  18011. var str="(function(data){if(data==null)return;with(data){try{\nreturn "+temp+"\n}catch(e){}}})";
  18012. fun=Laya._runScript(str);
  18013. SceneUtils._funMap.set(value,fun);
  18014. }
  18015. return fun;
  18016. }
  18017. SceneUtils.createByData=function(root,uiView){
  18018. var tInitTool=InitTool.create();
  18019. root=SceneUtils.createComp(uiView,root,root,null,tInitTool);
  18020. root._setBit(/*laya.Const.NOT_READY*/0x08,true);
  18021. if (root.hasOwnProperty("_idMap")){
  18022. root["_idMap"]=tInitTool._idMap;
  18023. }
  18024. if (uiView.animations){
  18025. var anilist=[];
  18026. var animations=uiView.animations;
  18027. var i=0,len=animations.length;
  18028. var tAni;
  18029. var tAniO;
  18030. for (i=0;i < len;i++){
  18031. tAni=new FrameAnimation();
  18032. tAniO=animations[i];
  18033. tAni._setUp(tInitTool._idMap,tAniO);
  18034. root[tAniO.name]=tAni;
  18035. tAni._setControlNode(root);
  18036. switch (tAniO.action){
  18037. case 1:
  18038. tAni.play(0,false);
  18039. break ;
  18040. case 2:
  18041. tAni.play(0,true);
  18042. break ;
  18043. }
  18044. anilist.push(tAni);
  18045. }
  18046. root._aniList=anilist;
  18047. }
  18048. if (root._$componentType==="Scene" && root._width > 0 && uiView.props.hitTestPrior==null && !root.mouseThrough)
  18049. root.hitTestPrior=true;
  18050. tInitTool.beginLoad(root);
  18051. return root;
  18052. }
  18053. SceneUtils.createInitTool=function(){
  18054. return InitTool.create();
  18055. }
  18056. SceneUtils.createComp=function(uiView,comp,view,dataMap,initTool){
  18057. if (uiView.type=="Scene3D"||uiView.type=="Sprite3D"){
  18058. var outBatchSprits=[];
  18059. var scene3D=Laya["Utils3D"]._createSceneByJsonForMaker(uiView,outBatchSprits,initTool);
  18060. if (uiView.type=="Sprite3D")
  18061. Laya["StaticBatchManager"].combine(scene3D,outBatchSprits);
  18062. else
  18063. Laya["StaticBatchManager"].combine(null,outBatchSprits);
  18064. return scene3D;
  18065. }
  18066. comp=comp || SceneUtils.getCompInstance(uiView);
  18067. if (!comp){
  18068. if (uiView.props && uiView.props.runtime)
  18069. console.warn("runtime not found:"+uiView.props.runtime);
  18070. else
  18071. console.warn("can not create:"+uiView.type);
  18072. return null;
  18073. };
  18074. var child=uiView.child;
  18075. if (child){
  18076. var isList=comp["_$componentType"]=="List";
  18077. for (var i=0,n=child.length;i < n;i++){
  18078. var node=child[i];
  18079. if (comp.hasOwnProperty("itemRender")&& (node.props.name=="render" || node.props.renderType==="render")){
  18080. comp["itemRender"]=node;
  18081. }else if (node.type=="Graphic"){
  18082. ClassUtils._addGraphicsToSprite(node,comp);
  18083. }else if (ClassUtils._isDrawType(node.type)){
  18084. ClassUtils._addGraphicToSprite(node,comp,true);
  18085. }else {
  18086. if (isList){
  18087. var arr=[];
  18088. var tChild=SceneUtils.createComp(node,null,view,arr,initTool);
  18089. if (arr.length)
  18090. tChild["_$bindData"]=arr;
  18091. }else {
  18092. tChild=SceneUtils.createComp(node,null,view,dataMap,initTool);
  18093. }
  18094. if (node.type=="Script"){
  18095. if ((tChild instanceof laya.components.Component )){
  18096. comp._addComponentInstance(tChild);
  18097. }else {
  18098. if ("owner" in tChild){
  18099. tChild["owner"]=comp;
  18100. }else if ("target" in tChild){
  18101. tChild["target"]=comp;
  18102. }
  18103. }
  18104. }else if (node.props.renderType=="mask" || node.props.name=="mask"){
  18105. comp.mask=tChild;
  18106. }else {(
  18107. tChild instanceof laya.display.Node )&& comp.addChild(tChild);
  18108. }
  18109. }
  18110. }
  18111. };
  18112. var props=uiView.props;
  18113. for (var prop in props){
  18114. var value=props[prop];
  18115. if ((typeof value=='string')&& (value.indexOf("@node:")>=0 || value.indexOf("@Prefab:")>=0)){
  18116. if (initTool){
  18117. initTool.addNodeRef(comp,prop,value);
  18118. }
  18119. }else
  18120. SceneUtils.setCompValue(comp,prop,value,view,dataMap);
  18121. }
  18122. if (comp._afterInited){
  18123. comp._afterInited();
  18124. }
  18125. if (uiView.compId && initTool && initTool._idMap){
  18126. initTool._idMap[uiView.compId]=comp;
  18127. }
  18128. return comp;
  18129. }
  18130. SceneUtils.setCompValue=function(comp,prop,value,view,dataMap){
  18131. if ((typeof value=='string')&& value.indexOf("${")>-1){
  18132. SceneUtils._sheet || (SceneUtils._sheet=ClassUtils.getClass("laya.data.Table"));
  18133. if (!SceneUtils._sheet){
  18134. console.warn("Can not find class Sheet");
  18135. return;
  18136. }
  18137. if (dataMap){
  18138. dataMap.push(comp,prop,value);
  18139. }else if (view){
  18140. if (value.indexOf("].")==-1){
  18141. value=value.replace(".","[0].");
  18142. };
  18143. var watcher=new DataWatcher(comp,prop,value);
  18144. watcher.exe(view);
  18145. var one,temp;
  18146. var str=value.replace(/\[.*?\]\./g,".");
  18147. while ((one=SceneUtils._parseWatchData.exec(str))!=null){
  18148. var key1=one[1];
  18149. while ((temp=SceneUtils._parseKeyWord.exec(key1))!=null){
  18150. var key2=temp[0];
  18151. var arr=(view._watchMap[key2] || (view._watchMap[key2]=[]));
  18152. arr.push(watcher);
  18153. SceneUtils._sheet.I.notifer.on(key2,view,view.changeData,[key2]);
  18154. }
  18155. arr=(view._watchMap[key1] || (view._watchMap[key1]=[]));
  18156. arr.push(watcher);
  18157. SceneUtils._sheet.I.notifer.on(key1,view,view.changeData,[key1]);
  18158. }
  18159. }
  18160. return;
  18161. }
  18162. if (prop==="var" && view){
  18163. view[value]=comp;
  18164. }else {
  18165. comp[prop]=(value==="true" ? true :(value==="false" ? false :value));
  18166. }
  18167. }
  18168. SceneUtils.getCompInstance=function(json){
  18169. if (json.type=="UIView"){
  18170. if (json.props && json.props.pageData){
  18171. return SceneUtils.createByData(null,json.props.pageData);
  18172. }
  18173. };
  18174. var runtime=(json.props && json.props.runtime)|| json.type;
  18175. var compClass=ClassUtils.getClass(runtime);
  18176. if (!compClass)throw "Can not find class "+runtime;
  18177. if (json.type==="Script" && compClass.prototype._doAwake){
  18178. var comp=Pool.createByClass(compClass);
  18179. comp._destroyed=false;
  18180. return comp;
  18181. }
  18182. if (json.props && json.props.hasOwnProperty("renderType")&& json.props["renderType"]=="instance"){
  18183. if (!compClass["instance"])compClass["instance"]=new compClass();
  18184. return compClass["instance"];
  18185. }
  18186. return new compClass();
  18187. }
  18188. SceneUtils._sheet=null;
  18189. __static(SceneUtils,
  18190. ['_funMap',function(){return this._funMap=new WeakObject();},'_parseWatchData',function(){return this._parseWatchData=/\${(.*?)}/g;},'_parseKeyWord',function(){return this._parseKeyWord=/[a-zA-Z_][a-zA-Z0-9_]*(?:(?:\.[a-zA-Z_][a-zA-Z0-9_]*)+)/g;}
  18191. ]);
  18192. SceneUtils.__init$=function(){
  18193. /**
  18194. *@private 场景辅助类
  18195. */
  18196. //class DataWatcher
  18197. DataWatcher=(function(){
  18198. function DataWatcher(comp,prop,value){
  18199. this.comp=null;
  18200. this.prop=null;
  18201. this.value=null;
  18202. this.comp=comp;
  18203. this.prop=prop;
  18204. this.value=value;
  18205. }
  18206. __class(DataWatcher,'');
  18207. var __proto=DataWatcher.prototype;
  18208. __proto.exe=function(view){
  18209. var fun=SceneUtils.getBindFun(this.value);
  18210. this.comp[this.prop]=fun.call(this,view);
  18211. }
  18212. return DataWatcher;
  18213. })()
  18214. /**
  18215. *@private 场景辅助类
  18216. */
  18217. //class InitTool
  18218. InitTool=(function(){
  18219. function InitTool(){
  18220. /**@private */
  18221. this._nodeRefList=null;
  18222. /**@private */
  18223. this._initList=null;
  18224. this._loadList=null;
  18225. /**@private */
  18226. this._idMap=null;
  18227. this._scene=null;
  18228. }
  18229. __class(InitTool,'');
  18230. var __proto=InitTool.prototype;
  18231. //TODO:coverage
  18232. __proto.reset=function(){
  18233. this._nodeRefList=null;
  18234. this._initList=null;
  18235. this._idMap=null;
  18236. this._loadList=null;
  18237. this._scene=null;
  18238. }
  18239. //TODO:coverage
  18240. __proto.recover=function(){
  18241. this.reset();
  18242. Pool.recover("InitTool",this);
  18243. }
  18244. //TODO:coverage
  18245. __proto.addLoadRes=function(url,type){
  18246. if (!this._loadList)this._loadList=[];
  18247. if (!type){
  18248. this._loadList.push(url);
  18249. }else {
  18250. this._loadList.push({url:url,type:type});
  18251. }
  18252. }
  18253. //TODO:coverage
  18254. __proto.addNodeRef=function(node,prop,referStr){
  18255. if (!this._nodeRefList)this._nodeRefList=[];
  18256. this._nodeRefList.push([node,prop,referStr]);
  18257. if (referStr.indexOf("@Prefab:")>=0){
  18258. this.addLoadRes(referStr.replace("@Prefab:",""),/*laya.net.Loader.PREFAB*/"prefab");
  18259. }
  18260. }
  18261. //TODO:coverage
  18262. __proto.setNodeRef=function(){
  18263. if (!this._nodeRefList)return;
  18264. if (!this._idMap){
  18265. this._nodeRefList=null;
  18266. return;
  18267. };
  18268. var i=0,len=0;
  18269. len=this._nodeRefList.length;
  18270. var tRefInfo;
  18271. for (i=0;i < len;i++){
  18272. tRefInfo=this._nodeRefList[i];
  18273. tRefInfo[0][tRefInfo[1]]=this.getReferData(tRefInfo[2]);
  18274. }
  18275. this._nodeRefList=null;
  18276. }
  18277. //TODO:coverage
  18278. __proto.getReferData=function(referStr){
  18279. if (referStr.indexOf("@Prefab:")>=0){
  18280. var prefab;
  18281. prefab=Loader.getRes(referStr.replace("@Prefab:",""));
  18282. return prefab;
  18283. }else if (referStr.indexOf("@arr:")>=0){
  18284. referStr=referStr.replace("@arr:","");
  18285. var list;
  18286. list=referStr.split(",");
  18287. var i=0,len=0;
  18288. var tStr;
  18289. len=list.length;
  18290. for (i=0;i < len;i++){
  18291. tStr=list[i];
  18292. if (tStr){
  18293. list[i]=this._idMap[tStr.replace("@node:","")];
  18294. }else {
  18295. list[i]=null;
  18296. }
  18297. }
  18298. return list;
  18299. }else {
  18300. return this._idMap[referStr.replace("@node:","")];
  18301. }
  18302. }
  18303. //TODO:coverage
  18304. __proto.addInitItem=function(item){
  18305. if (!this._initList)this._initList=[];
  18306. this._initList.push(item);
  18307. }
  18308. //TODO:coverage
  18309. __proto.doInits=function(){
  18310. if (!this._initList)return;
  18311. this._initList=null;
  18312. }
  18313. //TODO:coverage
  18314. __proto.finish=function(){
  18315. this.setNodeRef();
  18316. this.doInits();
  18317. this._scene._setBit(/*laya.Const.NOT_READY*/0x08,false);
  18318. if (this._scene.parent && this._scene.parent.activeInHierarchy && this._scene.active)this._scene._processActive();
  18319. this._scene.event("onViewCreated");
  18320. this.recover();
  18321. }
  18322. //TODO:coverage
  18323. __proto.beginLoad=function(scene){
  18324. this._scene=scene;
  18325. if (!this._loadList || this._loadList.length < 1){
  18326. this.finish();
  18327. }else {
  18328. Laya.loader.load(this._loadList,Handler.create(this,this.finish));
  18329. }
  18330. }
  18331. InitTool.create=function(){
  18332. var tool=Pool.getItemByClass("InitTool",InitTool);
  18333. tool._idMap=[];
  18334. return tool;
  18335. }
  18336. return InitTool;
  18337. })()
  18338. }
  18339. return SceneUtils;
  18340. })()
  18341. /**
  18342. *...
  18343. *@author ...
  18344. */
  18345. //class laya.webgl.BufferState2D extends laya.webgl.BufferStateBase
  18346. var BufferState2D=(function(_super){
  18347. function BufferState2D(){
  18348. BufferState2D.__super.call(this);
  18349. }
  18350. __class(BufferState2D,'laya.webgl.BufferState2D',_super);
  18351. return BufferState2D;
  18352. })(BufferStateBase)
  18353. /**
  18354. *<p> <code>SoundChannel</code> 用来控制程序中的声音。每个声音均分配给一个声道,而且应用程序可以具有混合在一起的多个声道。</p>
  18355. *<p> <code>SoundChannel</code> 类包含控制声音的播放、暂停、停止、音量的方法,以及获取声音的播放状态、总时间、当前播放时间、总循环次数、播放地址等信息的方法。</p>
  18356. */
  18357. //class laya.media.SoundChannel extends laya.events.EventDispatcher
  18358. var SoundChannel=(function(_super){
  18359. function SoundChannel(){
  18360. /**
  18361. *声音地址。
  18362. */
  18363. this.url=null;
  18364. /**
  18365. *循环次数。
  18366. */
  18367. this.loops=0;
  18368. /**
  18369. *播放声音开始时间。
  18370. */
  18371. this.startTime=NaN;
  18372. /**
  18373. *表示声音是否已暂停。
  18374. */
  18375. this.isStopped=false;
  18376. /**
  18377. *播放完成处理器。
  18378. */
  18379. this.completeHandler=null;
  18380. SoundChannel.__super.call(this);
  18381. }
  18382. __class(SoundChannel,'laya.media.SoundChannel',_super);
  18383. var __proto=SoundChannel.prototype;
  18384. /**
  18385. *播放声音。
  18386. */
  18387. __proto.play=function(){}
  18388. /**
  18389. *停止播放。
  18390. */
  18391. __proto.stop=function(){
  18392. if (this.completeHandler)this.completeHandler.run();
  18393. }
  18394. /**
  18395. *暂停播放。
  18396. */
  18397. __proto.pause=function(){}
  18398. /**
  18399. *继续播放。
  18400. */
  18401. __proto.resume=function(){}
  18402. /**
  18403. *private
  18404. */
  18405. __proto.__runComplete=function(handler){
  18406. if (handler){
  18407. handler.run();
  18408. }
  18409. }
  18410. /**
  18411. *音量范围从 0(静音)至 1(最大音量)。
  18412. */
  18413. __getset(0,__proto,'volume',function(){
  18414. return 1;
  18415. },function(v){
  18416. });
  18417. /**
  18418. *获取当前播放时间,单位是秒。
  18419. */
  18420. __getset(0,__proto,'position',function(){
  18421. return 0;
  18422. });
  18423. /**
  18424. *获取总时间,单位是秒。
  18425. */
  18426. __getset(0,__proto,'duration',function(){
  18427. return 0;
  18428. });
  18429. return SoundChannel;
  18430. })(EventDispatcher)
  18431. /**
  18432. *<code>TimeLine</code> 是一个用来创建时间轴动画的类。
  18433. */
  18434. //class laya.utils.TimeLine extends laya.events.EventDispatcher
  18435. var TimeLine=(function(_super){
  18436. var tweenData;
  18437. function TimeLine(){
  18438. this._labelDic=null;
  18439. this._tweenDic={};
  18440. this._tweenDataList=[];
  18441. this._endTweenDataList=null;
  18442. //以结束时间进行排序
  18443. this._currTime=0;
  18444. this._lastTime=0;
  18445. this._startTime=0;
  18446. /**当前动画数据播放到第几个了*/
  18447. this._index=0;
  18448. /**为TWEEN创建属于自己的唯一标识,方便管理*/
  18449. this._gidIndex=0;
  18450. /**保留所有对象第一次注册动画时的状态(根据时间跳转时,需要把对象的恢复,再计算接下来的状态)*/
  18451. this._firstTweenDic={};
  18452. /**是否需要排序*/
  18453. this._startTimeSort=false;
  18454. this._endTimeSort=false;
  18455. /**是否循环*/
  18456. this._loopKey=false;
  18457. /**缩放动画播放的速度。*/
  18458. this.scale=1;
  18459. this._frameRate=60;
  18460. this._frameIndex=0;
  18461. this._total=0;
  18462. TimeLine.__super.call(this);
  18463. }
  18464. __class(TimeLine,'laya.utils.TimeLine',_super);
  18465. var __proto=TimeLine.prototype;
  18466. /**
  18467. *控制一个对象,从当前点移动到目标点。
  18468. *@param target 要控制的对象。
  18469. *@param props 要控制对象的属性。
  18470. *@param duration 对象TWEEN的时间。
  18471. *@param ease 缓动类型
  18472. *@param offset 相对于上一个对象,偏移多长时间(单位:毫秒)。
  18473. */
  18474. __proto.to=function(target,props,duration,ease,offset){
  18475. (offset===void 0)&& (offset=0);
  18476. return this._create(target,props,duration,ease,offset,true);
  18477. }
  18478. /**
  18479. *从 props 属性,缓动到当前状态。
  18480. *@param target target 目标对象(即将更改属性值的对象)
  18481. *@param props 要控制对象的属性
  18482. *@param duration 对象TWEEN的时间
  18483. *@param ease 缓动类型
  18484. *@param offset 相对于上一个对象,偏移多长时间(单位:毫秒)
  18485. */
  18486. __proto.from=function(target,props,duration,ease,offset){
  18487. (offset===void 0)&& (offset=0);
  18488. return this._create(target,props,duration,ease,offset,false);
  18489. }
  18490. /**@private */
  18491. __proto._create=function(target,props,duration,ease,offset,isTo){
  18492. var tTweenData=Pool.getItemByClass("tweenData",tweenData);
  18493. tTweenData.isTo=isTo;
  18494. tTweenData.type=0;
  18495. tTweenData.target=target;
  18496. tTweenData.duration=duration;
  18497. tTweenData.data=props;
  18498. tTweenData.startTime=this._startTime+offset;
  18499. tTweenData.endTime=tTweenData.startTime+tTweenData.duration;
  18500. tTweenData.ease=ease;
  18501. this._startTime=Math.max(tTweenData.endTime,this._startTime);
  18502. this._tweenDataList.push(tTweenData);
  18503. this._startTimeSort=true;
  18504. this._endTimeSort=true;
  18505. return this;
  18506. }
  18507. /**
  18508. *在时间队列中加入一个标签。
  18509. *@param label 标签名称。
  18510. *@param offset 标签相对于上个动画的偏移时间(单位:毫秒)。
  18511. */
  18512. __proto.addLabel=function(label,offset){
  18513. var tTweenData=Pool.getItemByClass("tweenData",tweenData);
  18514. tTweenData.type=1;
  18515. tTweenData.data=label;
  18516. tTweenData.endTime=tTweenData.startTime=this._startTime+offset;
  18517. this._labelDic || (this._labelDic={});
  18518. this._labelDic[label]=tTweenData;
  18519. this._tweenDataList.push(tTweenData);
  18520. return this;
  18521. }
  18522. /**
  18523. *移除指定的标签
  18524. *@param label
  18525. */
  18526. __proto.removeLabel=function(label){
  18527. if (this._labelDic && this._labelDic[label]){
  18528. var tTweenData=this._labelDic[label];
  18529. if (tTweenData){
  18530. var tIndex=this._tweenDataList.indexOf(tTweenData);
  18531. if (tIndex >-1){
  18532. this._tweenDataList.splice(tIndex,1);
  18533. }
  18534. }
  18535. delete this._labelDic[label];
  18536. }
  18537. }
  18538. /**
  18539. *动画从整个动画的某一时间开始。
  18540. *@param time(单位:毫秒)。
  18541. */
  18542. __proto.gotoTime=function(time){
  18543. if (this._tweenDataList==null || this._tweenDataList.length==0)return;
  18544. var tTween;
  18545. var tObject;
  18546. for (var p in this._firstTweenDic){
  18547. tObject=this._firstTweenDic[p];
  18548. if (tObject){
  18549. for (var tDataP in tObject){
  18550. if (tObject.diyTarget.hasOwnProperty(tDataP)){
  18551. tObject.diyTarget[tDataP]=tObject[tDataP];
  18552. }
  18553. }
  18554. }
  18555. }
  18556. for (p in this._tweenDic){
  18557. tTween=this._tweenDic[p];
  18558. tTween.clear();
  18559. delete this._tweenDic[p];
  18560. }
  18561. this._index=0;
  18562. this._gidIndex=0;
  18563. this._currTime=time;
  18564. this._lastTime=Browser.now();
  18565. var tTweenDataCopyList;
  18566. if (this._endTweenDataList==null || this._endTimeSort){
  18567. this._endTimeSort=false;
  18568. this._endTweenDataList=tTweenDataCopyList=this._tweenDataList.concat();
  18569. function Compare (paraA,paraB){
  18570. if (paraA.endTime > paraB.endTime){
  18571. return 1;
  18572. }else if (paraA.endTime < paraB.endTime){
  18573. return-1;
  18574. }else {
  18575. return 0;
  18576. }
  18577. }
  18578. tTweenDataCopyList.sort(Compare);
  18579. }else {
  18580. tTweenDataCopyList=this._endTweenDataList
  18581. };
  18582. var tTweenData;
  18583. for (var i=0,n=tTweenDataCopyList.length;i < n;i++){
  18584. tTweenData=tTweenDataCopyList[i];
  18585. if (tTweenData.type==0){
  18586. if (time >=tTweenData.endTime){
  18587. this._index=Math.max(this._index,i+1);
  18588. var props=tTweenData.data;
  18589. if (tTweenData.isTo){
  18590. for (var tP in props){
  18591. tTweenData.target[tP]=props[tP];
  18592. }
  18593. }
  18594. }else {
  18595. break ;
  18596. }
  18597. }
  18598. }
  18599. for (i=0,n=this._tweenDataList.length;i < n;i++){
  18600. tTweenData=this._tweenDataList[i];
  18601. if (tTweenData.type==0){
  18602. if (time >=tTweenData.startTime && time < tTweenData.endTime){
  18603. this._index=Math.max(this._index,i+1);
  18604. this._gidIndex++;
  18605. tTween=Pool.getItemByClass("tween",Tween);
  18606. tTween._create(tTweenData.target,tTweenData.data,tTweenData.duration,tTweenData.ease,Handler.create(this,this._animComplete,[this._gidIndex]),0,false,tTweenData.isTo,true,false);
  18607. tTween.setStartTime(this._currTime-(time-tTweenData.startTime));
  18608. tTween._updateEase(this._currTime);
  18609. tTween.gid=this._gidIndex;
  18610. this._tweenDic[this._gidIndex]=tTween;
  18611. }
  18612. }
  18613. }
  18614. }
  18615. /**
  18616. *从指定的标签开始播。
  18617. *@param Label 标签名。
  18618. */
  18619. __proto.gotoLabel=function(Label){
  18620. if (this._labelDic==null)return;
  18621. var tLabelData=this._labelDic[Label];
  18622. if (tLabelData)this.gotoTime(tLabelData.startTime);
  18623. }
  18624. /**
  18625. *暂停整个动画。
  18626. */
  18627. __proto.pause=function(){
  18628. Laya.timer.clear(this,this._update);
  18629. }
  18630. /**
  18631. *恢复暂停动画的播放。
  18632. */
  18633. __proto.resume=function(){
  18634. this.play(this._currTime,this._loopKey);
  18635. }
  18636. /**
  18637. *播放动画。
  18638. *@param timeOrLabel 开启播放的时间点或标签名。
  18639. *@param loop 是否循环播放。
  18640. */
  18641. __proto.play=function(timeOrLabel,loop){
  18642. (timeOrLabel===void 0)&& (timeOrLabel=0);
  18643. (loop===void 0)&& (loop=false);
  18644. if (!this._tweenDataList)return;
  18645. if (this._startTimeSort){
  18646. this._startTimeSort=false;
  18647. function Compare (paraA,paraB){
  18648. if (paraA.startTime > paraB.startTime){
  18649. return 1;
  18650. }else if (paraA.startTime < paraB.startTime){
  18651. return-1;
  18652. }else {
  18653. return 0;
  18654. }
  18655. }
  18656. this._tweenDataList.sort(Compare);
  18657. for (var i=0,n=this._tweenDataList.length;i < n;i++){
  18658. var tTweenData=this._tweenDataList[i];
  18659. if (tTweenData !=null && tTweenData.type==0){
  18660. var tTarget=tTweenData.target;
  18661. var gid=(tTarget.$_GID || (tTarget.$_GID=Utils.getGID()));
  18662. var tSrcData=null;
  18663. if (this._firstTweenDic[gid]==null){
  18664. tSrcData={};
  18665. tSrcData.diyTarget=tTarget;
  18666. this._firstTweenDic[gid]=tSrcData;
  18667. }else {
  18668. tSrcData=this._firstTweenDic[gid];
  18669. }
  18670. for (var p in tTweenData.data){
  18671. if (tSrcData[p]==null){
  18672. tSrcData[p]=tTarget[p];
  18673. }
  18674. }
  18675. }
  18676. }
  18677. }
  18678. if ((typeof timeOrLabel=='string')){
  18679. this.gotoLabel(timeOrLabel);
  18680. }else {
  18681. this.gotoTime(timeOrLabel);
  18682. }
  18683. this._loopKey=loop;
  18684. this._lastTime=Browser.now();
  18685. Laya.timer.frameLoop(1,this,this._update);
  18686. }
  18687. /**
  18688. *更新当前动画。
  18689. */
  18690. __proto._update=function(){
  18691. if (this._currTime >=this._startTime){
  18692. if (this._loopKey){
  18693. this._complete();
  18694. if (!this._tweenDataList)return;
  18695. this.gotoTime(0);
  18696. }else {
  18697. for (var p in this._tweenDic){
  18698. tTween=this._tweenDic[p];
  18699. tTween.complete();
  18700. }
  18701. this._complete();
  18702. this.pause();
  18703. return;
  18704. }
  18705. };
  18706. var tNow=Browser.now();
  18707. var tFrameTime=tNow-this._lastTime;
  18708. var tCurrTime=this._currTime+=tFrameTime *this.scale;
  18709. this._lastTime=tNow;
  18710. for (p in this._tweenDic){
  18711. tTween=this._tweenDic[p];
  18712. tTween._updateEase(tCurrTime);
  18713. };
  18714. var tTween;
  18715. if (this._tweenDataList.length !=0 && this._index < this._tweenDataList.length){
  18716. var tTweenData=this._tweenDataList[this._index];
  18717. if (tCurrTime >=tTweenData.startTime){
  18718. this._index++;
  18719. if (tTweenData.type==0){
  18720. this._gidIndex++;
  18721. tTween=Pool.getItemByClass("tween",Tween);
  18722. tTween._create(tTweenData.target,tTweenData.data,tTweenData.duration,tTweenData.ease,Handler.create(this,this._animComplete,[this._gidIndex]),0,false,tTweenData.isTo,true,false);
  18723. tTween.setStartTime(tCurrTime);
  18724. tTween.gid=this._gidIndex;
  18725. this._tweenDic[this._gidIndex]=tTween;
  18726. tTween._updateEase(tCurrTime);
  18727. }else {
  18728. this.event(/*laya.events.Event.LABEL*/"label",tTweenData.data);
  18729. }
  18730. }
  18731. }
  18732. }
  18733. /**
  18734. *指定的动画索引处的动画播放完成后,把此动画从列表中删除。
  18735. *@param index
  18736. */
  18737. __proto._animComplete=function(index){
  18738. var tTween=this._tweenDic[index];
  18739. if (tTween)delete this._tweenDic[index];
  18740. }
  18741. /**@private */
  18742. __proto._complete=function(){
  18743. this.event(/*laya.events.Event.COMPLETE*/"complete");
  18744. }
  18745. /**
  18746. *重置所有对象,复用对象的时候使用。
  18747. */
  18748. __proto.reset=function(){
  18749. var p;
  18750. if (this._labelDic){
  18751. for (p in this._labelDic){
  18752. delete this._labelDic[p];
  18753. }
  18754. };
  18755. var tTween;
  18756. for (p in this._tweenDic){
  18757. tTween=this._tweenDic[p];
  18758. tTween.clear();
  18759. delete this._tweenDic[p];
  18760. }
  18761. for (p in this._firstTweenDic){
  18762. delete this._firstTweenDic[p];
  18763. }
  18764. this._endTweenDataList=null;
  18765. if (this._tweenDataList && this._tweenDataList.length){
  18766. var i=0,len=0;
  18767. len=this._tweenDataList.length;
  18768. for (i=0;i < len;i++){
  18769. if(this._tweenDataList[i])
  18770. this._tweenDataList[i].destroy();
  18771. }
  18772. }
  18773. this._tweenDataList.length=0;
  18774. this._currTime=0;
  18775. this._lastTime=0;
  18776. this._startTime=0;
  18777. this._index=0;
  18778. this._gidIndex=0;
  18779. this.scale=1;
  18780. Laya.timer.clear(this,this._update);
  18781. }
  18782. /**
  18783. *彻底销毁此对象。
  18784. */
  18785. __proto.destroy=function(){
  18786. this.reset();
  18787. this._labelDic=null;
  18788. this._tweenDic=null;
  18789. this._tweenDataList=null;
  18790. this._firstTweenDic=null;
  18791. }
  18792. /**
  18793. *@private
  18794. *设置帧索引
  18795. */
  18796. /**
  18797. *@private
  18798. *得到帧索引
  18799. */
  18800. __getset(0,__proto,'index',function(){
  18801. return this._frameIndex;
  18802. },function(value){
  18803. this._frameIndex=value;
  18804. this.gotoTime(this._frameIndex / this._frameRate *1000);
  18805. });
  18806. /**
  18807. *得到总帧数。
  18808. */
  18809. __getset(0,__proto,'total',function(){
  18810. this._total=Math.floor(this._startTime / 1000 *this._frameRate);
  18811. return this._total;
  18812. });
  18813. TimeLine.to=function(target,props,duration,ease,offset){
  18814. (offset===void 0)&& (offset=0);
  18815. return (new TimeLine()).to(target,props,duration,ease,offset);
  18816. }
  18817. TimeLine.from=function(target,props,duration,ease,offset){
  18818. (offset===void 0)&& (offset=0);
  18819. return (new TimeLine()).from(target,props,duration,ease,offset);
  18820. }
  18821. TimeLine.__init$=function(){
  18822. //class tweenData
  18823. tweenData=(function(){
  18824. function tweenData(){
  18825. this.type=0;
  18826. //0代表TWEEN,1代表标签
  18827. this.isTo=true;
  18828. this.startTime=NaN;
  18829. this.endTime=NaN;
  18830. this.target=null;
  18831. this.duration=NaN;
  18832. this.ease=null;
  18833. this.data=null;
  18834. }
  18835. __class(tweenData,'');
  18836. var __proto=tweenData.prototype;
  18837. __proto.destroy=function(){
  18838. this.target=null;
  18839. this.ease=null;
  18840. this.data=null;
  18841. this.isTo=true;
  18842. this.type=0;
  18843. Pool.recover("tweenData",this);
  18844. }
  18845. return tweenData;
  18846. })()
  18847. }
  18848. return TimeLine;
  18849. })(EventDispatcher)
  18850. /**
  18851. *<code>Loader</code> 类可用来加载文本、JSON、XML、二进制、图像等资源。
  18852. */
  18853. //class laya.net.Loader extends laya.events.EventDispatcher
  18854. var Loader=(function(_super){
  18855. function Loader(){
  18856. /**@private 加载后的数据对象,只读*/
  18857. this._data=null;
  18858. /**@private */
  18859. this._url=null;
  18860. /**@private */
  18861. this._type=null;
  18862. /**@private */
  18863. this._cache=false;
  18864. /**@private */
  18865. this._http=null;
  18866. /**@private */
  18867. this._useWorkerLoader=false;
  18868. /**@private 自定义解析不派发complete事件,但会派发loaded事件,手动调用endLoad方法再派发complete事件*/
  18869. this._customParse=false;
  18870. /**@private */
  18871. this._constructParams=null;
  18872. /**@private */
  18873. this._propertyParams=null;
  18874. /**@private */
  18875. this._createCache=false;
  18876. Loader.__super.call(this);
  18877. }
  18878. __class(Loader,'laya.net.Loader',_super);
  18879. var __proto=Loader.prototype;
  18880. /**
  18881. *加载资源。加载错误会派发 Event.ERROR 事件,参数为错误信息。
  18882. *@param url 资源地址。
  18883. *@param type (default=null)资源类型。可选值为:Loader.TEXT、Loader.JSON、Loader.XML、Loader.BUFFER、Loader.IMAGE、Loader.SOUND、Loader.ATLAS、Loader.FONT。如果为null,则根据文件后缀分析类型。
  18884. *@param cache (default=true)是否缓存数据。
  18885. *@param group (default=null)分组名称。
  18886. *@param ignoreCache (default=false)是否忽略缓存,强制重新加载。
  18887. *@param useWorkerLoader(default=false)是否使用worker加载(只针对IMAGE类型和ATLAS类型,并且浏览器支持的情况下生效)
  18888. */
  18889. __proto.load=function(url,type,cache,group,ignoreCache,useWorkerLoader){
  18890. (cache===void 0)&& (cache=true);
  18891. (ignoreCache===void 0)&& (ignoreCache=false);
  18892. (useWorkerLoader===void 0)&& (useWorkerLoader=false);
  18893. if (!url){
  18894. this.onLoaded(null);
  18895. return;
  18896. }
  18897. Loader.setGroup(url,"666");
  18898. this._url=url;
  18899. if (url.indexOf("data:image")===0)type="image";
  18900. else url=URL.formatURL(url);
  18901. this._type=type || (type=Loader.getTypeFromUrl(this._url));
  18902. this._cache=cache;
  18903. this._useWorkerLoader=useWorkerLoader;
  18904. this._data=null;
  18905. if (useWorkerLoader)WorkerLoader.enableWorkerLoader();
  18906. if (!ignoreCache && Loader.loadedMap[url]){
  18907. this._data=Loader.loadedMap[url];
  18908. this.event(/*laya.events.Event.PROGRESS*/"progress",1);
  18909. this.event(/*laya.events.Event.COMPLETE*/"complete",this._data);
  18910. return;
  18911. }
  18912. if (group)Loader.setGroup(url,group);
  18913. if (Loader.parserMap[type] !=null){
  18914. this._customParse=true;
  18915. if (((Loader.parserMap[type])instanceof laya.utils.Handler ))Loader.parserMap[type].runWith(this);
  18916. else Loader.parserMap[type].call(null,this);
  18917. return;
  18918. }
  18919. if (type==="image" || type==="htmlimage" || type==="nativeimage")return this._loadImage(url);
  18920. if (type==="sound")return this._loadSound(url);
  18921. if (type==="ttf")return this._loadTTF(url);
  18922. var contentType;
  18923. switch (type){
  18924. case "atlas":
  18925. case "prefab":
  18926. case "plf":
  18927. contentType="json";
  18928. break ;
  18929. case "font":
  18930. contentType="xml";
  18931. break ;
  18932. case "plfb":
  18933. contentType="arraybuffer";
  18934. break ;
  18935. default :
  18936. contentType=type;
  18937. }
  18938. if (Loader.preLoadedMap[url]){
  18939. this.onLoaded(Loader.preLoadedMap[url]);
  18940. }else {
  18941. if(Browser.onVVMiniGame){
  18942. this._http=new HttpRequest();
  18943. this._http.on(/*laya.events.Event.PROGRESS*/"progress",this,this.onProgress);
  18944. this._http.on(/*laya.events.Event.ERROR*/"error",this,this.onError);
  18945. this._http.on(/*laya.events.Event.COMPLETE*/"complete",this,this.onLoaded);
  18946. }else{
  18947. if (!this._http){
  18948. this._http=new HttpRequest();
  18949. this._http.on(/*laya.events.Event.PROGRESS*/"progress",this,this.onProgress);
  18950. this._http.on(/*laya.events.Event.ERROR*/"error",this,this.onError);
  18951. this._http.on(/*laya.events.Event.COMPLETE*/"complete",this,this.onLoaded);
  18952. }
  18953. }
  18954. this._http.send(url,null,"get",contentType);
  18955. }
  18956. }
  18957. /**
  18958. *@private
  18959. *加载TTF资源。
  18960. *@param url 资源地址。
  18961. */
  18962. __proto._loadTTF=function(url){
  18963. url=URL.formatURL(url);
  18964. var ttfLoader=new TTFLoader();
  18965. ttfLoader.complete=Handler.create(this,this.onLoaded);
  18966. ttfLoader.load(url);
  18967. }
  18968. /**
  18969. *@private
  18970. *加载图片资源。
  18971. *@param url 资源地址。
  18972. */
  18973. __proto._loadImage=function(url){
  18974. url=URL.formatURL(url);
  18975. var _this=this;
  18976. var image;
  18977. function clear (){
  18978. var img=image;
  18979. if (img){
  18980. img.onload=null;
  18981. img.onerror=null;
  18982. delete Loader._imgCache[url];
  18983. }
  18984. };
  18985. var onerror=function (){
  18986. clear();
  18987. _this.event(/*laya.events.Event.ERROR*/"error","Load image failed");
  18988. }
  18989. if (this._type==="nativeimage"){
  18990. var onload=function (){
  18991. clear();
  18992. _this.onLoaded(image);
  18993. };
  18994. image=new Browser.window.Image();
  18995. image.crossOrigin="";
  18996. image.onload=onload;
  18997. image.onerror=onerror;
  18998. image.src=url;
  18999. Loader._imgCache[url]=image;
  19000. }else {
  19001. var ext=Utils.getFileExtension(url);
  19002. if (ext==="ktx" || ext==="pvr"){
  19003. onload=function (imageData){
  19004. var format=0;
  19005. switch (ext){
  19006. case "ktx":
  19007. format=5;
  19008. break ;
  19009. case "pvr":
  19010. format=12;
  19011. break ;
  19012. }
  19013. image=new Texture2D(0,0,format,false,false);
  19014. image.wrapModeU=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  19015. image.wrapModeV=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  19016. image.setCompressData(imageData);
  19017. image._setCreateURL(url);
  19018. clear();
  19019. _this.onLoaded(image);
  19020. };
  19021. var tempHttp;
  19022. tempHttp=new HttpRequest();
  19023. tempHttp.on(/*laya.events.Event.ERROR*/"error",null,onerror);
  19024. tempHttp.on(/*laya.events.Event.COMPLETE*/"complete",null,onload);
  19025. tempHttp.send(url,null,"get",/*CLASS CONST:laya.net.Loader.BUFFER*/"arraybuffer");
  19026. }else {
  19027. var imageSource=new Browser.window.Image();
  19028. onload=function (){
  19029. var tex=new Texture2D(imageSource.width,imageSource.height,1,false,false);
  19030. tex.wrapModeU=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  19031. tex.wrapModeV=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  19032. tex.loadImageSource(imageSource,true);
  19033. tex._setCreateURL(url);
  19034. clear();
  19035. _this.onLoaded(tex);
  19036. };
  19037. imageSource.crossOrigin="";
  19038. imageSource.onload=onload;
  19039. imageSource.onerror=onerror;
  19040. imageSource.src=url;
  19041. Loader._imgCache[url]=imageSource;
  19042. }
  19043. }
  19044. }
  19045. /**
  19046. *@private
  19047. *加载声音资源。
  19048. *@param url 资源地址。
  19049. */
  19050. __proto._loadSound=function(url){
  19051. var sound=(new SoundManager._soundClass());
  19052. var _this=this;
  19053. sound.on(/*laya.events.Event.COMPLETE*/"complete",this,soundOnload);
  19054. sound.on(/*laya.events.Event.ERROR*/"error",this,soundOnErr);
  19055. sound.load(url);
  19056. function soundOnload (){
  19057. clear();
  19058. _this.onLoaded(sound);
  19059. }
  19060. function soundOnErr (){
  19061. clear();
  19062. sound.dispose();
  19063. _this.event(/*laya.events.Event.ERROR*/"error","Load sound failed");
  19064. }
  19065. function clear (){
  19066. sound.offAll();
  19067. }
  19068. }
  19069. /**@private */
  19070. __proto.onProgress=function(value){
  19071. if (this._type==="atlas")this.event(/*laya.events.Event.PROGRESS*/"progress",value *0.3);
  19072. else this.event(/*laya.events.Event.PROGRESS*/"progress",value);
  19073. }
  19074. /**@private */
  19075. __proto.onError=function(message){
  19076. this.event(/*laya.events.Event.ERROR*/"error",message);
  19077. }
  19078. /**
  19079. *资源加载完成的处理函数。
  19080. *@param data 数据。
  19081. */
  19082. __proto.onLoaded=function(data){
  19083. var type=this._type;
  19084. if (type=="plfb"){
  19085. this.parsePLFBData(data);
  19086. this.complete(data);
  19087. }else
  19088. if (type=="plf"){
  19089. this.parsePLFData(data);
  19090. this.complete(data);
  19091. }else if (type==="image"){
  19092. var tex=new Texture(data);
  19093. tex.url=this._url;
  19094. this.complete(tex);
  19095. }else if (type==="sound" || type==="htmlimage" || type==="nativeimage"){
  19096. this.complete(data);
  19097. }else if (type==="atlas"){
  19098. if (!data.url && !data._setContext){
  19099. if (!this._data){
  19100. this._data=data;
  19101. if (data.meta && data.meta.image){
  19102. var toloadPics=data.meta.image.split(",");
  19103. var split=this._url.indexOf("/")>=0 ? "/" :"\\";
  19104. var idx=this._url.lastIndexOf(split);
  19105. var folderPath=idx >=0 ? this._url.substr(0,idx+1):"";
  19106. var changeType;
  19107. if (Browser.onAndroid && data.meta.compressTextureAndroid){
  19108. changeType=".ktx";
  19109. }
  19110. if (Browser.onIOS && data.meta.compressTextureIOS){
  19111. changeType=".pvr";
  19112. }
  19113. for (var i=0,len=toloadPics.length;i < len;i++){
  19114. if (changeType){
  19115. toloadPics[i]=folderPath+toloadPics[i].replace(".png",changeType);
  19116. }else{
  19117. toloadPics[i]=folderPath+toloadPics[i];
  19118. }
  19119. }
  19120. }else {
  19121. toloadPics=[this._url.replace(".json",".png")];
  19122. }
  19123. toloadPics.reverse();
  19124. data.toLoads=toloadPics;
  19125. data.pics=[];
  19126. }
  19127. this.event(/*laya.events.Event.PROGRESS*/"progress",0.3+1 / toloadPics.length *0.6);
  19128. return this._loadImage(toloadPics.pop());
  19129. }else {
  19130. this._data.pics.push(data);
  19131. if (this._data.toLoads.length > 0){
  19132. this.event(/*laya.events.Event.PROGRESS*/"progress",0.3+1 / this._data.toLoads.length *0.6);
  19133. return this._loadImage(this._data.toLoads.pop());
  19134. };
  19135. var frames=this._data.frames;
  19136. var cleanUrl=this._url.split("?")[0];
  19137. var directory=(this._data.meta && this._data.meta.prefix)? this._data.meta.prefix :cleanUrl.substring(0,cleanUrl.lastIndexOf("."))+"/";
  19138. var pics=this._data.pics;
  19139. var atlasURL=URL.formatURL(this._url);
  19140. var map=Loader.atlasMap[atlasURL] || (Loader.atlasMap[atlasURL]=[]);
  19141. map.dir=directory;
  19142. var scaleRate=1;
  19143. if (this._data.meta && this._data.meta.scale && this._data.meta.scale !=1){
  19144. scaleRate=parseFloat(this._data.meta.scale);
  19145. for (var name in frames){
  19146. var obj=frames[name];
  19147. var tPic=pics[obj.frame.idx ? obj.frame.idx :0];
  19148. var url=URL.formatURL(directory+name);
  19149. (tPic).scaleRate=scaleRate;
  19150. var tTexture;
  19151. tTexture=Texture._create(tPic,obj.frame.x,obj.frame.y,obj.frame.w,obj.frame.h,obj.spriteSourceSize.x,obj.spriteSourceSize.y,obj.sourceSize.w,obj.sourceSize.h,laya.net.Loader.getRes(url));
  19152. Loader.cacheRes(url,tTexture);
  19153. tTexture.url=url;
  19154. map.push(url);
  19155. }
  19156. }else {
  19157. for (name in frames){
  19158. obj=frames[name];
  19159. tPic=pics[obj.frame.idx ? obj.frame.idx :0];
  19160. url=URL.formatURL(directory+name);
  19161. tTexture=Texture._create(tPic,obj.frame.x,obj.frame.y,obj.frame.w,obj.frame.h,obj.spriteSourceSize.x,obj.spriteSourceSize.y,obj.sourceSize.w,obj.sourceSize.h,laya.net.Loader.getRes(url));
  19162. Loader.cacheRes(url,tTexture);
  19163. tTexture.url=url;
  19164. map.push(url);
  19165. }
  19166. }
  19167. delete this._data.pics;
  19168. this.complete(this._data);
  19169. }
  19170. }else if (type==="font"){
  19171. if (!data._source){
  19172. this._data=data;
  19173. this.event(/*laya.events.Event.PROGRESS*/"progress",0.5);
  19174. return this._loadImage(this._url.replace(".fnt",".png"));
  19175. }else {
  19176. var bFont=new BitmapFont();
  19177. bFont.parseFont(this._data,new Texture(data));
  19178. var tArr=this._url.split(".fnt")[0].split("/");
  19179. var fontName=tArr[tArr.length-1];
  19180. Text.registerBitmapFont(fontName,bFont);
  19181. this._data=bFont;
  19182. this.complete(this._data);
  19183. }
  19184. }else if (type==="prefab"){
  19185. var prefab=new Prefab();
  19186. prefab.json=data;
  19187. this.complete(prefab);
  19188. }else {
  19189. this.complete(data);
  19190. }
  19191. }
  19192. __proto.parsePLFData=function(plfData){
  19193. var type;
  19194. var filePath;
  19195. var fileDic;
  19196. for (type in plfData){
  19197. fileDic=plfData[type];
  19198. switch (type){
  19199. case "json":
  19200. case "text":
  19201. for (filePath in fileDic){
  19202. Loader.preLoadedMap[URL.formatURL(filePath)]=fileDic[filePath]
  19203. }
  19204. break ;
  19205. default :
  19206. for (filePath in fileDic){
  19207. Loader.preLoadedMap[URL.formatURL(filePath)]=fileDic[filePath]
  19208. }
  19209. }
  19210. }
  19211. }
  19212. __proto.parsePLFBData=function(plfData){
  19213. var byte;
  19214. byte=new Byte(plfData);
  19215. var i=0,len=0;
  19216. len=byte.getInt32();
  19217. for (i=0;i < len;i++){
  19218. this.parseOnePLFBFile(byte);
  19219. }
  19220. }
  19221. __proto.parseOnePLFBFile=function(byte){
  19222. var fileLen=0;
  19223. var fileName;
  19224. var fileData;
  19225. fileName=byte.getUTFString();
  19226. fileLen=byte.getInt32();
  19227. fileData=byte.readArrayBuffer(fileLen);
  19228. Loader.preLoadedMap[URL.formatURL(fileName)]=fileData;
  19229. }
  19230. /**
  19231. *加载完成。
  19232. *@param data 加载的数据。
  19233. */
  19234. __proto.complete=function(data){
  19235. this._data=data;
  19236. if (this._customParse){
  19237. this.event(/*laya.events.Event.LOADED*/"loaded",(data instanceof Array)? [data] :data);
  19238. }else {
  19239. Loader._loaders.push(this);
  19240. if (!Loader._isWorking)Loader.checkNext();
  19241. }
  19242. }
  19243. /**
  19244. *结束加载,处理是否缓存及派发完成事件 <code>Event.COMPLETE</code> 。
  19245. *@param content 加载后的数据
  19246. */
  19247. __proto.endLoad=function(content){
  19248. content && (this._data=content);
  19249. if (this._cache)Loader.cacheRes(this._url,this._data);
  19250. this.event(/*laya.events.Event.PROGRESS*/"progress",1);
  19251. this.event(/*laya.events.Event.COMPLETE*/"complete",(this.data instanceof Array)? [this.data] :this.data);
  19252. }
  19253. /**加载地址。*/
  19254. __getset(0,__proto,'url',function(){
  19255. return this._url;
  19256. });
  19257. /**返回的数据。*/
  19258. __getset(0,__proto,'data',function(){
  19259. return this._data;
  19260. });
  19261. /**是否缓存。*/
  19262. __getset(0,__proto,'cache',function(){
  19263. return this._cache;
  19264. });
  19265. /**加载类型。*/
  19266. __getset(0,__proto,'type',function(){
  19267. return this._type;
  19268. });
  19269. Loader.getTypeFromUrl=function(url){
  19270. var type=Utils.getFileExtension(url);
  19271. if (type)return Loader.typeMap[type];
  19272. console.warn("Not recognize the resources suffix",url);
  19273. return "text";
  19274. }
  19275. Loader.checkNext=function(){
  19276. Loader._isWorking=true;
  19277. var startTimer=Browser.now();
  19278. var thisTimer=startTimer;
  19279. while (Loader._startIndex < Loader._loaders.length){
  19280. thisTimer=Browser.now();
  19281. Loader._loaders[Loader._startIndex].endLoad();
  19282. Loader._startIndex++;
  19283. if (Browser.now()-startTimer > Loader.maxTimeOut){
  19284. console.warn("loader callback cost a long time:"+(Browser.now()-startTimer)+" url="+Loader._loaders[Loader._startIndex-1].url);
  19285. Laya.systemTimer.frameOnce(1,null,Loader.checkNext);
  19286. return;
  19287. }
  19288. }
  19289. Loader._loaders.length=0;
  19290. Loader._startIndex=0;
  19291. Loader._isWorking=false;
  19292. }
  19293. Loader.clearRes=function(url){
  19294. url=URL.formatURL(url);
  19295. var arr=Loader.getAtlas(url);
  19296. if (arr){
  19297. for (var i=0,n=arr.length;i < n;i++){
  19298. var resUrl=arr[i];
  19299. var tex=Loader.getRes(resUrl);
  19300. delete Loader.loadedMap[resUrl];
  19301. if (tex)tex.destroy();
  19302. }
  19303. arr.length=0;
  19304. delete Loader.atlasMap[url];
  19305. delete Loader.loadedMap[url];
  19306. }else {
  19307. var res=Loader.loadedMap[url];
  19308. if (res){
  19309. delete Loader.loadedMap[url];
  19310. if ((res instanceof laya.resource.Texture )&& res.bitmap)(res).destroy();
  19311. }
  19312. }
  19313. }
  19314. Loader.clearTextureRes=function(url){
  19315. url=URL.formatURL(url);
  19316. var arr=laya.net.Loader.getAtlas(url);
  19317. var res=(arr && arr.length > 0)? laya.net.Loader.getRes(arr[0]):laya.net.Loader.getRes(url);
  19318. if ((res instanceof laya.resource.Texture ))
  19319. res.disposeBitmap();
  19320. }
  19321. Loader.getRes=function(url){
  19322. return Loader.loadedMap[URL.formatURL(url)];
  19323. }
  19324. Loader.getAtlas=function(url){
  19325. return Loader.atlasMap[URL.formatURL(url)];
  19326. }
  19327. Loader.cacheRes=function(url,data){
  19328. url=URL.formatURL(url);
  19329. if (Loader.loadedMap[url] !=null){
  19330. console.warn("Resources already exist,is repeated loading:",url);
  19331. }else {
  19332. Loader.loadedMap[url]=data;
  19333. }
  19334. }
  19335. Loader.setGroup=function(url,group){
  19336. if (!Loader.groupMap[group])Loader.groupMap[group]=[];
  19337. Loader.groupMap[group].push(url);
  19338. }
  19339. Loader.clearResByGroup=function(group){
  19340. if (!Loader.groupMap[group])return;
  19341. var arr=Loader.groupMap[group],i=0,len=arr.length;
  19342. for (i=0;i < len;i++){
  19343. Loader.clearRes(arr[i]);
  19344. }
  19345. arr.length=0;
  19346. }
  19347. Loader.TEXT="text";
  19348. Loader.JSON="json";
  19349. Loader.PREFAB="prefab";
  19350. Loader.XML="xml";
  19351. Loader.BUFFER="arraybuffer";
  19352. Loader.IMAGE="image";
  19353. Loader.SOUND="sound";
  19354. Loader.ATLAS="atlas";
  19355. Loader.FONT="font";
  19356. Loader.TTF="ttf";
  19357. Loader.PLF="plf";
  19358. Loader.PLFB="plfb";
  19359. Loader.HIERARCHY="HIERARCHY";
  19360. Loader.MESH="MESH";
  19361. Loader.MATERIAL="MATERIAL";
  19362. Loader.TEXTURE2D="TEXTURE2D";
  19363. Loader.TEXTURECUBE="TEXTURECUBE";
  19364. Loader.ANIMATIONCLIP="ANIMATIONCLIP";
  19365. Loader.AVATAR="AVATAR";
  19366. Loader.TERRAINHEIGHTDATA="TERRAINHEIGHTDATA";
  19367. Loader.TERRAINRES="TERRAIN";
  19368. Loader.typeMap={"ttf":"ttf","png":"image","jpg":"image","jpeg":"image","ktx":"image","pvr":"image","txt":"text","json":"json","prefab":"prefab","xml":"xml","als":"atlas","atlas":"atlas","mp3":"sound","ogg":"sound","wav":"sound","part":"json","fnt":"font","plf":"plf","plfb":"plfb","scene":"json","ani":"json","sk":"arraybuffer"};
  19369. Loader.parserMap={};
  19370. Loader.maxTimeOut=100;
  19371. Loader.groupMap={};
  19372. Loader.loadedMap={};
  19373. Loader.atlasMap={};
  19374. Loader.preLoadedMap={};
  19375. Loader._imgCache={};
  19376. Loader._loaders=[];
  19377. Loader._isWorking=false;
  19378. Loader._startIndex=0;
  19379. return Loader;
  19380. })(EventDispatcher)
  19381. /**
  19382. *@private
  19383. *使用Audio标签播放声音
  19384. */
  19385. //class laya.media.h5audio.AudioSound extends laya.events.EventDispatcher
  19386. var AudioSound=(function(_super){
  19387. function AudioSound(){
  19388. /**
  19389. *声音URL
  19390. */
  19391. this.url=null;
  19392. /**
  19393. *播放用的audio标签
  19394. */
  19395. this.audio=null;
  19396. /**
  19397. *是否已加载完成
  19398. */
  19399. this.loaded=false;
  19400. AudioSound.__super.call(this);
  19401. }
  19402. __class(AudioSound,'laya.media.h5audio.AudioSound',_super);
  19403. var __proto=AudioSound.prototype;
  19404. /**
  19405. *释放声音
  19406. *
  19407. */
  19408. __proto.dispose=function(){
  19409. var ad=AudioSound._audioCache[this.url];
  19410. Pool.clearBySign("audio:"+this.url);
  19411. if (ad){
  19412. if (!Render.isConchApp){
  19413. ad.src="";
  19414. }
  19415. delete AudioSound._audioCache[this.url];
  19416. }
  19417. }
  19418. /**
  19419. *加载声音
  19420. *@param url
  19421. *
  19422. */
  19423. __proto.load=function(url){
  19424. url=URL.formatURL(url);
  19425. this.url=url;
  19426. var ad;
  19427. if (url==SoundManager._bgMusic){
  19428. AudioSound._initMusicAudio();
  19429. ad=AudioSound._musicAudio;
  19430. if (ad.src !=url){
  19431. AudioSound._audioCache[ad.src]=null;
  19432. ad=null;
  19433. }
  19434. }else{
  19435. ad=AudioSound._audioCache[url];
  19436. }
  19437. if (ad && ad.readyState >=2){
  19438. this.event(/*laya.events.Event.COMPLETE*/"complete");
  19439. return;
  19440. }
  19441. if (!ad){
  19442. if (url==SoundManager._bgMusic){
  19443. AudioSound._initMusicAudio();
  19444. ad=AudioSound._musicAudio;
  19445. }else{
  19446. ad=Browser.createElement("audio");
  19447. }
  19448. AudioSound._audioCache[url]=ad;
  19449. ad.src=url;
  19450. }
  19451. ad.addEventListener("canplaythrough",onLoaded);
  19452. ad.addEventListener("error",onErr);
  19453. var me=this;
  19454. function onLoaded (){
  19455. offs();
  19456. me.loaded=true;
  19457. me.event(/*laya.events.Event.COMPLETE*/"complete");
  19458. }
  19459. function onErr (){
  19460. ad.load=null;
  19461. offs();
  19462. me.event(/*laya.events.Event.ERROR*/"error");
  19463. }
  19464. function offs (){
  19465. ad.removeEventListener("canplaythrough",onLoaded);
  19466. ad.removeEventListener("error",onErr);
  19467. }
  19468. this.audio=ad;
  19469. if (ad.load){
  19470. ad.load();
  19471. }else {
  19472. onErr();
  19473. }
  19474. }
  19475. /**
  19476. *播放声音
  19477. *@param startTime 起始时间
  19478. *@param loops 循环次数
  19479. *@return
  19480. *
  19481. */
  19482. __proto.play=function(startTime,loops){
  19483. (startTime===void 0)&& (startTime=0);
  19484. (loops===void 0)&& (loops=0);
  19485. if (!this.url)return null;
  19486. var ad;
  19487. if (this.url==SoundManager._bgMusic){
  19488. ad=AudioSound._musicAudio;
  19489. }else{
  19490. ad=AudioSound._audioCache[this.url];
  19491. }
  19492. if (!ad)return null;
  19493. var tAd;
  19494. tAd=Pool.getItem("audio:"+this.url);
  19495. if (Render.isConchApp){
  19496. if (!tAd){
  19497. tAd=Browser.createElement("audio");
  19498. tAd.src=this.url;
  19499. }
  19500. }
  19501. else {
  19502. if (this.url==SoundManager._bgMusic){
  19503. AudioSound._initMusicAudio();
  19504. tAd=AudioSound._musicAudio;
  19505. tAd.src=this.url;
  19506. }else{
  19507. tAd=tAd ? tAd :ad.cloneNode(true);
  19508. }
  19509. };
  19510. var channel=new AudioSoundChannel(tAd);
  19511. channel.url=this.url;
  19512. channel.loops=loops;
  19513. channel.startTime=startTime;
  19514. channel.play();
  19515. SoundManager.addChannel(channel);
  19516. return channel;
  19517. }
  19518. /**
  19519. *获取总时间。
  19520. */
  19521. __getset(0,__proto,'duration',function(){
  19522. var ad;
  19523. ad=AudioSound._audioCache[this.url];
  19524. if (!ad)
  19525. return 0;
  19526. return ad.duration;
  19527. });
  19528. AudioSound._initMusicAudio=function(){
  19529. if (AudioSound._musicAudio)return;
  19530. if (!AudioSound._musicAudio)AudioSound._musicAudio=Browser.createElement("audio");
  19531. if (!Render.isConchApp){
  19532. Browser.document.addEventListener("mousedown",AudioSound._makeMusicOK);
  19533. }
  19534. }
  19535. AudioSound._makeMusicOK=function(){
  19536. Browser.document.removeEventListener("mousedown",AudioSound._makeMusicOK);
  19537. if (!AudioSound._musicAudio.src){
  19538. AudioSound._musicAudio.src="";
  19539. AudioSound._musicAudio.load();
  19540. }else{
  19541. AudioSound._musicAudio.play();
  19542. }
  19543. }
  19544. AudioSound._audioCache={};
  19545. AudioSound._musicAudio=null;
  19546. return AudioSound;
  19547. })(EventDispatcher)
  19548. /**
  19549. *<p> <code>Socket</code> 封装了 HTML5 WebSocket ,允许服务器端与客户端进行全双工(full-duplex)的实时通信,并且允许跨域通信。在建立连接后,服务器和 Browser/Client Agent 都能主动的向对方发送或接收文本和二进制数据。</p>
  19550. *<p>要使用 <code>Socket</code> 类的方法,请先使用构造函数 <code>new Socket</code> 创建一个 <code>Socket</code> 对象。 <code>Socket</code> 以异步方式传输和接收数据。</p>
  19551. */
  19552. //class laya.net.Socket extends laya.events.EventDispatcher
  19553. var Socket=(function(_super){
  19554. function Socket(host,port,byteClass,protocols){
  19555. /**@private */
  19556. this._endian=null;
  19557. /**@private */
  19558. this._socket=null;
  19559. /**@private */
  19560. this._connected=false;
  19561. /**@private */
  19562. this._addInputPosition=0;
  19563. /**@private */
  19564. this._input=null;
  19565. /**@private */
  19566. this._output=null;
  19567. /**
  19568. *不再缓存服务端发来的数据,如果传输的数据为字符串格式,建议设置为true,减少二进制转换消耗。
  19569. */
  19570. this.disableInput=false;
  19571. /**
  19572. *用来发送和接收数据的 <code>Byte</code> 类。
  19573. */
  19574. this._byteClass=null;
  19575. /**
  19576. *<p>子协议名称。子协议名称字符串,或由多个子协议名称字符串构成的数组。必须在调用 connect 或者 connectByUrl 之前进行赋值,否则无效。</p>
  19577. *<p>指定后,只有当服务器选择了其中的某个子协议,连接才能建立成功,否则建立失败,派发 Event.ERROR 事件。</p>
  19578. *@see https://html.spec.whatwg.org/multipage/comms.html#dom-websocket
  19579. */
  19580. this.protocols=[];
  19581. Socket.__super.call(this);
  19582. (port===void 0)&& (port=0);
  19583. this._byteClass=byteClass ? byteClass :Byte;
  19584. this.protocols=protocols;
  19585. this.endian="bigEndian";
  19586. if (host && port > 0 && port < 65535)this.connect(host,port);
  19587. }
  19588. __class(Socket,'laya.net.Socket',_super);
  19589. var __proto=Socket.prototype;
  19590. /**
  19591. *<p>连接到指定的主机和端口。</p>
  19592. *<p>连接成功派发 Event.OPEN 事件;连接失败派发 Event.ERROR 事件;连接被关闭派发 Event.CLOSE 事件;接收到数据派发 Event.MESSAGE 事件; 除了 Event.MESSAGE 事件参数为数据内容,其他事件参数都是原生的 HTML DOM Event 对象。</p>
  19593. *@param host 服务器地址。
  19594. *@param port 服务器端口。
  19595. */
  19596. __proto.connect=function(host,port){
  19597. var url="ws://"+host+":"+port;
  19598. this.connectByUrl(url);
  19599. }
  19600. /**
  19601. *<p>连接到指定的服务端 WebSocket URL。 URL 类似 ws://yourdomain:port。</p>
  19602. *<p>连接成功派发 Event.OPEN 事件;连接失败派发 Event.ERROR 事件;连接被关闭派发 Event.CLOSE 事件;接收到数据派发 Event.MESSAGE 事件; 除了 Event.MESSAGE 事件参数为数据内容,其他事件参数都是原生的 HTML DOM Event 对象。</p>
  19603. *@param url 要连接的服务端 WebSocket URL。 URL 类似 ws://yourdomain:port。
  19604. */
  19605. __proto.connectByUrl=function(url){
  19606. var _$this=this;
  19607. if (this._socket !=null)this.close();
  19608. this._socket && this.cleanSocket();
  19609. if (!this.protocols || this.protocols.length==0){
  19610. this._socket=new Browser.window.WebSocket(url);
  19611. }else {
  19612. this._socket=new Browser.window.WebSocket(url,this.protocols);
  19613. }
  19614. this._socket.binaryType="arraybuffer";
  19615. this._output=new this._byteClass();
  19616. this._output.endian=this.endian;
  19617. this._input=new this._byteClass();
  19618. this._input.endian=this.endian;
  19619. this._addInputPosition=0;
  19620. this._socket.onopen=function (e){
  19621. _$this._onOpen(e);
  19622. };
  19623. this._socket.onmessage=function (msg){
  19624. _$this._onMessage(msg);
  19625. };
  19626. this._socket.onclose=function (e){
  19627. _$this._onClose(e);
  19628. };
  19629. this._socket.onerror=function (e){
  19630. _$this._onError(e);
  19631. };
  19632. }
  19633. /**
  19634. *清理Socket:关闭Socket链接,关闭事件监听,重置Socket
  19635. */
  19636. __proto.cleanSocket=function(){
  19637. this.close();
  19638. this._connected=false;
  19639. this._socket.onopen=null;
  19640. this._socket.onmessage=null;
  19641. this._socket.onclose=null;
  19642. this._socket.onerror=null;
  19643. this._socket=null;
  19644. }
  19645. /**
  19646. *关闭连接。
  19647. */
  19648. __proto.close=function(){
  19649. if (this._socket !=null){
  19650. try {
  19651. this._socket.close();
  19652. }catch (e){}
  19653. }
  19654. }
  19655. /**
  19656. *@private
  19657. *连接建立成功 。
  19658. */
  19659. __proto._onOpen=function(e){
  19660. this._connected=true;
  19661. this.event(/*laya.events.Event.OPEN*/"open",e);
  19662. }
  19663. /**
  19664. *@private
  19665. *接收到数据处理方法。
  19666. *@param msg 数据。
  19667. */
  19668. __proto._onMessage=function(msg){
  19669. if (!msg || !msg.data)return;
  19670. var data=msg.data;
  19671. if (this.disableInput && data){
  19672. this.event(/*laya.events.Event.MESSAGE*/"message",data);
  19673. return;
  19674. }
  19675. if (this._input.length > 0 && this._input.bytesAvailable < 1){
  19676. this._input.clear();
  19677. this._addInputPosition=0;
  19678. };
  19679. var pre=this._input.pos;
  19680. !this._addInputPosition && (this._addInputPosition=0);
  19681. this._input.pos=this._addInputPosition;
  19682. if (data){
  19683. if ((typeof data=='string')){
  19684. this._input.writeUTFBytes(data);
  19685. }else {
  19686. this._input.writeArrayBuffer(data);
  19687. }
  19688. this._addInputPosition=this._input.pos;
  19689. this._input.pos=pre;
  19690. }
  19691. this.event(/*laya.events.Event.MESSAGE*/"message",data);
  19692. }
  19693. /**
  19694. *@private
  19695. *连接被关闭处理方法。
  19696. */
  19697. __proto._onClose=function(e){
  19698. this._connected=false;
  19699. this.event(/*laya.events.Event.CLOSE*/"close",e)
  19700. }
  19701. /**
  19702. *@private
  19703. *出现异常处理方法。
  19704. */
  19705. __proto._onError=function(e){
  19706. this.event(/*laya.events.Event.ERROR*/"error",e)
  19707. }
  19708. /**
  19709. *发送数据到服务器。
  19710. *@param data 需要发送的数据,可以是String或者ArrayBuffer。
  19711. */
  19712. __proto.send=function(data){
  19713. this._socket.send(data);
  19714. }
  19715. /**
  19716. *发送缓冲区中的数据到服务器。
  19717. */
  19718. __proto.flush=function(){
  19719. if (this._output && this._output.length > 0){
  19720. var evt;
  19721. try {
  19722. this._socket && this._socket.send(this._output.__getBuffer().slice(0,this._output.length));
  19723. }catch (e){
  19724. evt=e;
  19725. }
  19726. this._output.endian=this.endian;
  19727. this._output.clear();
  19728. if (evt)this.event(/*laya.events.Event.ERROR*/"error",evt);
  19729. }
  19730. }
  19731. /**
  19732. *缓存的服务端发来的数据。
  19733. */
  19734. __getset(0,__proto,'input',function(){
  19735. return this._input;
  19736. });
  19737. /**
  19738. *表示需要发送至服务端的缓冲区中的数据。
  19739. */
  19740. __getset(0,__proto,'output',function(){
  19741. return this._output;
  19742. });
  19743. /**
  19744. *表示此 Socket 对象目前是否已连接。
  19745. */
  19746. __getset(0,__proto,'connected',function(){
  19747. return this._connected;
  19748. });
  19749. /**
  19750. *<p>主机字节序,是 CPU 存放数据的两种不同顺序,包括小端字节序和大端字节序。</p>
  19751. *<p> LITTLE_ENDIAN :小端字节序,地址低位存储值的低位,地址高位存储值的高位。</p>
  19752. *<p> BIG_ENDIAN :大端字节序,地址低位存储值的高位,地址高位存储值的低位。</p>
  19753. */
  19754. __getset(0,__proto,'endian',function(){
  19755. return this._endian;
  19756. },function(value){
  19757. this._endian=value;
  19758. if (this._input !=null)this._input.endian=value;
  19759. if (this._output !=null)this._output.endian=value;
  19760. });
  19761. Socket.LITTLE_ENDIAN="littleEndian";
  19762. Socket.BIG_ENDIAN="bigEndian";
  19763. return Socket;
  19764. })(EventDispatcher)
  19765. /**
  19766. *<code>Node</code> 类是可放在显示列表中的所有对象的基类。该显示列表管理 Laya 运行时中显示的所有对象。使用 Node 类排列显示列表中的显示对象。Node 对象可以有子显示对象。
  19767. */
  19768. //class laya.display.Node extends laya.events.EventDispatcher
  19769. var Node=(function(_super){
  19770. function Node(){
  19771. /**@private */
  19772. this._bits=0;
  19773. /**@private 父节点对象*/
  19774. this._parent=null;
  19775. /**节点名称。*/
  19776. this.name="";
  19777. /**[只读]是否已经销毁。对象销毁后不能再使用。*/
  19778. this.destroyed=false;
  19779. /**@private */
  19780. this._conchData=null;
  19781. /**@private */
  19782. this._components=null;
  19783. /**@private */
  19784. this._activeChangeScripts=null;
  19785. /**@private */
  19786. this._scene=null;
  19787. Node.__super.call(this);
  19788. this._children=Node.ARRAY_EMPTY;
  19789. this._extUIChild=Node.ARRAY_EMPTY;
  19790. this.createGLBuffer();
  19791. }
  19792. __class(Node,'laya.display.Node',_super);
  19793. var __proto=Node.prototype;
  19794. /**@private */
  19795. __proto.createGLBuffer=function(){}
  19796. /**@private */
  19797. __proto._setBit=function(type,value){
  19798. if (type===/*laya.Const.DISPLAY*/0x10){
  19799. var preValue=this._getBit(type);
  19800. if (preValue !=value)this._updateDisplayedInstage();
  19801. }
  19802. if (value)this._bits |=type;
  19803. else this._bits &=~type;
  19804. }
  19805. /**@private */
  19806. __proto._getBit=function(type){
  19807. return (this._bits & type)!=0;
  19808. }
  19809. /**@private */
  19810. __proto._setUpNoticeChain=function(){
  19811. if (this._getBit(/*laya.Const.DISPLAY*/0x10))this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  19812. }
  19813. /**@private */
  19814. __proto._setBitUp=function(type){
  19815. var ele=this;
  19816. ele._setBit(type,true);
  19817. ele=ele._parent;
  19818. while (ele){
  19819. if (ele._getBit(type))return;
  19820. ele._setBit(type,true);
  19821. ele=ele._parent;
  19822. }
  19823. }
  19824. /**
  19825. *<p>增加事件侦听器,以使侦听器能够接收事件通知。</p>
  19826. *<p>如果侦听鼠标事件,则会自动设置自己和父亲节点的属性 mouseEnabled 的值为 true(如果父节点mouseEnabled=false,则停止设置父节点mouseEnabled属性)。</p>
  19827. *@param type 事件的类型。
  19828. *@param caller 事件侦听函数的执行域。
  19829. *@param listener 事件侦听函数。
  19830. *@param args (可选)事件侦听函数的回调参数。
  19831. *@return 此 EventDispatcher 对象。
  19832. */
  19833. __proto.on=function(type,caller,listener,args){
  19834. if (type===/*laya.events.Event.DISPLAY*/"display" || type===/*laya.events.Event.UNDISPLAY*/"undisplay"){
  19835. if (!this._getBit(/*laya.Const.DISPLAY*/0x10))this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  19836. }
  19837. return this._createListener(type,caller,listener,args,false);
  19838. }
  19839. /**
  19840. *<p>增加事件侦听器,以使侦听器能够接收事件通知,此侦听事件响应一次后则自动移除侦听。</p>
  19841. *<p>如果侦听鼠标事件,则会自动设置自己和父亲节点的属性 mouseEnabled 的值为 true(如果父节点mouseEnabled=false,则停止设置父节点mouseEnabled属性)。</p>
  19842. *@param type 事件的类型。
  19843. *@param caller 事件侦听函数的执行域。
  19844. *@param listener 事件侦听函数。
  19845. *@param args (可选)事件侦听函数的回调参数。
  19846. *@return 此 EventDispatcher 对象。
  19847. */
  19848. __proto.once=function(type,caller,listener,args){
  19849. if (type===/*laya.events.Event.DISPLAY*/"display" || type===/*laya.events.Event.UNDISPLAY*/"undisplay"){
  19850. if (!this._getBit(/*laya.Const.DISPLAY*/0x10))this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  19851. }
  19852. return this._createListener(type,caller,listener,args,true);
  19853. }
  19854. /**
  19855. *<p>销毁此对象。destroy对象默认会把自己从父节点移除,并且清理自身引用关系,等待js自动垃圾回收机制回收。destroy后不能再使用。</p>
  19856. *<p>destroy时会移除自身的事情监听,自身的timer监听,移除子对象及从父节点移除自己。</p>
  19857. *@param destroyChild (可选)是否同时销毁子节点,若值为true,则销毁子节点,否则不销毁子节点。
  19858. */
  19859. __proto.destroy=function(destroyChild){
  19860. (destroyChild===void 0)&& (destroyChild=true);
  19861. this.destroyed=true;
  19862. this._destroyAllComponent();
  19863. this._parent && this._parent.removeChild(this);
  19864. if (this._children){
  19865. if (destroyChild)this.destroyChildren();
  19866. else this.removeChildren();
  19867. }
  19868. this.onDestroy();
  19869. this._children=null;
  19870. this.offAll();
  19871. }
  19872. /**
  19873. *销毁时执行
  19874. *此方法为虚方法,使用时重写覆盖即可
  19875. */
  19876. __proto.onDestroy=function(){}
  19877. /**
  19878. *销毁所有子对象,不销毁自己本身。
  19879. */
  19880. __proto.destroyChildren=function(){
  19881. if (this._children){
  19882. for (var i=0,n=this._children.length;i < n;i++){
  19883. this._children[0].destroy(true);
  19884. }
  19885. }
  19886. }
  19887. /**
  19888. *添加子节点。
  19889. *@param node 节点对象
  19890. *@return 返回添加的节点
  19891. */
  19892. __proto.addChild=function(node){
  19893. if (!node || this.destroyed || node===this)return node;
  19894. if ((node)._zOrder)this._setBit(/*laya.Const.HAS_ZORDER*/0x20,true);
  19895. if (node._parent===this){
  19896. var index=this.getChildIndex(node);
  19897. if (index!==this._children.length-1){
  19898. this._children.splice(index,1);
  19899. this._children.push(node);
  19900. this._childChanged();
  19901. }
  19902. }else {
  19903. node._parent && node._parent.removeChild(node);
  19904. this._children===Node.ARRAY_EMPTY && (this._children=[]);
  19905. this._children.push(node);
  19906. node._setParent(this);
  19907. this._childChanged();
  19908. }
  19909. return node;
  19910. }
  19911. __proto.addInputChild=function(node){
  19912. if (this._extUIChild==Node.ARRAY_EMPTY){
  19913. this._extUIChild=[node];
  19914. }else {
  19915. if (this._extUIChild.indexOf(node)>=0){
  19916. return null;
  19917. }
  19918. this._extUIChild.push(node);
  19919. }
  19920. return null;
  19921. }
  19922. __proto.removeInputChild=function(node){
  19923. var idx=this._extUIChild.indexOf(node);
  19924. if (idx >=0){
  19925. this._extUIChild.splice(idx,1);
  19926. }
  19927. }
  19928. /**
  19929. *批量增加子节点
  19930. *@param ...args 无数子节点。
  19931. */
  19932. __proto.addChildren=function(__args){
  19933. var args=arguments;
  19934. var i=0,n=args.length;
  19935. while (i < n){
  19936. this.addChild(args[i++]);
  19937. }
  19938. }
  19939. /**
  19940. *添加子节点到指定的索引位置。
  19941. *@param node 节点对象。
  19942. *@param index 索引位置。
  19943. *@return 返回添加的节点。
  19944. */
  19945. __proto.addChildAt=function(node,index){
  19946. if (!node || this.destroyed || node===this)return node;
  19947. if ((node)._zOrder)this._setBit(/*laya.Const.HAS_ZORDER*/0x20,true);
  19948. if (index >=0 && index <=this._children.length){
  19949. if (node._parent===this){
  19950. var oldIndex=this.getChildIndex(node);
  19951. this._children.splice(oldIndex,1);
  19952. this._children.splice(index,0,node);
  19953. this._childChanged();
  19954. }else {
  19955. node._parent && node._parent.removeChild(node);
  19956. this._children===Node.ARRAY_EMPTY && (this._children=[]);
  19957. this._children.splice(index,0,node);
  19958. node._setParent(this);
  19959. }
  19960. return node;
  19961. }else {
  19962. throw new Error("appendChildAt:The index is out of bounds");
  19963. }
  19964. }
  19965. /**
  19966. *根据子节点对象,获取子节点的索引位置。
  19967. *@param node 子节点。
  19968. *@return 子节点所在的索引位置。
  19969. */
  19970. __proto.getChildIndex=function(node){
  19971. return this._children.indexOf(node);
  19972. }
  19973. /**
  19974. *根据子节点的名字,获取子节点对象。
  19975. *@param name 子节点的名字。
  19976. *@return 节点对象。
  19977. */
  19978. __proto.getChildByName=function(name){
  19979. var nodes=this._children;
  19980. if (nodes){
  19981. for (var i=0,n=nodes.length;i < n;i++){
  19982. var node=nodes[i];
  19983. if (node.name===name)return node;
  19984. }
  19985. }
  19986. return null;
  19987. }
  19988. /**
  19989. *根据子节点的索引位置,获取子节点对象。
  19990. *@param index 索引位置
  19991. *@return 子节点
  19992. */
  19993. __proto.getChildAt=function(index){
  19994. return this._children[index] || null;
  19995. }
  19996. /**
  19997. *设置子节点的索引位置。
  19998. *@param node 子节点。
  19999. *@param index 新的索引。
  20000. *@return 返回子节点本身。
  20001. */
  20002. __proto.setChildIndex=function(node,index){
  20003. var childs=this._children;
  20004. if (index < 0 || index >=childs.length){
  20005. throw new Error("setChildIndex:The index is out of bounds.");
  20006. };
  20007. var oldIndex=this.getChildIndex(node);
  20008. if (oldIndex < 0)throw new Error("setChildIndex:node is must child of this object.");
  20009. childs.splice(oldIndex,1);
  20010. childs.splice(index,0,node);
  20011. this._childChanged();
  20012. return node;
  20013. }
  20014. /**
  20015. *子节点发生改变。
  20016. *@private
  20017. *@param child 子节点。
  20018. */
  20019. __proto._childChanged=function(child){}
  20020. /**
  20021. *删除子节点。
  20022. *@param node 子节点
  20023. *@return 被删除的节点
  20024. */
  20025. __proto.removeChild=function(node){
  20026. if (!this._children)return node;
  20027. var index=this._children.indexOf(node);
  20028. return this.removeChildAt(index);
  20029. }
  20030. /**
  20031. *从父容器删除自己,如已经被删除不会抛出异常。
  20032. *@return 当前节点( Node )对象。
  20033. */
  20034. __proto.removeSelf=function(){
  20035. this._parent && this._parent.removeChild(this);
  20036. return this;
  20037. }
  20038. /**
  20039. *根据子节点名字删除对应的子节点对象,如果找不到不会抛出异常。
  20040. *@param name 对象名字。
  20041. *@return 查找到的节点( Node )对象。
  20042. */
  20043. __proto.removeChildByName=function(name){
  20044. var node=this.getChildByName(name);
  20045. node && this.removeChild(node);
  20046. return node;
  20047. }
  20048. /**
  20049. *根据子节点索引位置,删除对应的子节点对象。
  20050. *@param index 节点索引位置。
  20051. *@return 被删除的节点。
  20052. */
  20053. __proto.removeChildAt=function(index){
  20054. var node=this.getChildAt(index);
  20055. if (node){
  20056. this._children.splice(index,1);
  20057. node._setParent(null);
  20058. }
  20059. return node;
  20060. }
  20061. /**
  20062. *删除指定索引区间的所有子对象。
  20063. *@param beginIndex 开始索引。
  20064. *@param endIndex 结束索引。
  20065. *@return 当前节点对象。
  20066. */
  20067. __proto.removeChildren=function(beginIndex,endIndex){
  20068. (beginIndex===void 0)&& (beginIndex=0);
  20069. (endIndex===void 0)&& (endIndex=0x7fffffff);
  20070. if (this._children && this._children.length > 0){
  20071. var childs=this._children;
  20072. if (beginIndex===0 && endIndex >=childs.length-1){
  20073. var arr=childs;
  20074. this._children=Node.ARRAY_EMPTY;
  20075. }else {
  20076. arr=childs.splice(beginIndex,endIndex-beginIndex);
  20077. }
  20078. for (var i=0,n=arr.length;i < n;i++){
  20079. arr[i]._setParent(null);
  20080. }
  20081. }
  20082. return this;
  20083. }
  20084. /**
  20085. *替换子节点。
  20086. *@internal 将传入的新节点对象替换到已有子节点索引位置处。
  20087. *@param newNode 新节点。
  20088. *@param oldNode 老节点。
  20089. *@return 返回新节点。
  20090. */
  20091. __proto.replaceChild=function(newNode,oldNode){
  20092. var index=this._children.indexOf(oldNode);
  20093. if (index >-1){
  20094. this._children.splice(index,1,newNode);
  20095. oldNode._setParent(null);
  20096. newNode._setParent(this);
  20097. return newNode;
  20098. }
  20099. return null;
  20100. }
  20101. /**@private */
  20102. __proto._setParent=function(value){
  20103. if (this._parent!==value){
  20104. if (value){
  20105. this._parent=value;
  20106. this._onAdded();
  20107. this.event(/*laya.events.Event.ADDED*/"added");
  20108. if (this._getBit(/*laya.Const.DISPLAY*/0x10)){
  20109. this._setUpNoticeChain();
  20110. value.displayedInStage && this._displayChild(this,true);
  20111. }
  20112. value._childChanged(this);
  20113. }else {
  20114. this._onRemoved();
  20115. this.event(/*laya.events.Event.REMOVED*/"removed");
  20116. this._parent._childChanged();
  20117. if (this._getBit(/*laya.Const.DISPLAY*/0x10))this._displayChild(this,false);
  20118. this._parent=value;
  20119. }
  20120. }
  20121. }
  20122. /**@private */
  20123. __proto._updateDisplayedInstage=function(){
  20124. var ele;
  20125. ele=this;
  20126. var stage=Laya.stage;
  20127. var displayedInStage=false;
  20128. while (ele){
  20129. if (ele._getBit(/*laya.Const.DISPLAY*/0x10)){
  20130. displayedInStage=ele._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80);
  20131. break ;
  20132. }
  20133. if (ele===stage || ele._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80)){
  20134. displayedInStage=true;
  20135. break ;
  20136. }
  20137. ele=ele._parent;
  20138. }
  20139. this._setBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80,displayedInStage);
  20140. }
  20141. /**@private */
  20142. __proto._setDisplay=function(value){
  20143. if (this._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80)!==value){
  20144. this._setBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80,value);
  20145. if (value)this.event(/*laya.events.Event.DISPLAY*/"display");
  20146. else this.event(/*laya.events.Event.UNDISPLAY*/"undisplay");
  20147. }
  20148. }
  20149. /**
  20150. *设置指定节点对象是否可见(是否在渲染列表中)。
  20151. *@private
  20152. *@param node 节点。
  20153. *@param display 是否可见。
  20154. */
  20155. __proto._displayChild=function(node,display){
  20156. var childs=node._children;
  20157. if (childs){
  20158. for (var i=0,n=childs.length;i < n;i++){
  20159. var child=childs[i];
  20160. if (!child._getBit(/*laya.Const.DISPLAY*/0x10))continue ;
  20161. if (child._children.length > 0){
  20162. this._displayChild(child,display);
  20163. }else {
  20164. child._setDisplay(display);
  20165. }
  20166. }
  20167. }
  20168. node._setDisplay(display);
  20169. }
  20170. /**
  20171. *当前容器是否包含指定的 <code>Node</code> 节点对象 。
  20172. *@param node 指定的 <code>Node</code> 节点对象 。
  20173. *@return 一个布尔值表示是否包含指定的 <code>Node</code> 节点对象 。
  20174. */
  20175. __proto.contains=function(node){
  20176. if (node===this)return true;
  20177. while (node){
  20178. if (node._parent===this)return true;
  20179. node=node._parent;
  20180. }
  20181. return false;
  20182. }
  20183. /**
  20184. *定时重复执行某函数。功能同Laya.timer.timerLoop()。
  20185. *@param delay 间隔时间(单位毫秒)。
  20186. *@param caller 执行域(this)。
  20187. *@param method 结束时的回调方法。
  20188. *@param args (可选)回调参数。
  20189. *@param coverBefore (可选)是否覆盖之前的延迟执行,默认为true。
  20190. *@param jumpFrame 时钟是否跳帧。基于时间的循环回调,单位时间间隔内,如能执行多次回调,出于性能考虑,引擎默认只执行一次,设置jumpFrame=true后,则回调会连续执行多次
  20191. */
  20192. __proto.timerLoop=function(delay,caller,method,args,coverBefore,jumpFrame){
  20193. (coverBefore===void 0)&& (coverBefore=true);
  20194. (jumpFrame===void 0)&& (jumpFrame=false);
  20195. var timer=this.scene ? this.scene.timer :Laya.timer;
  20196. timer.loop(delay,caller,method,args,coverBefore,jumpFrame);
  20197. }
  20198. /**
  20199. *定时执行某函数一次。功能同Laya.timer.timerOnce()。
  20200. *@param delay 延迟时间(单位毫秒)。
  20201. *@param caller 执行域(this)。
  20202. *@param method 结束时的回调方法。
  20203. *@param args (可选)回调参数。
  20204. *@param coverBefore (可选)是否覆盖之前的延迟执行,默认为true。
  20205. */
  20206. __proto.timerOnce=function(delay,caller,method,args,coverBefore){
  20207. (coverBefore===void 0)&& (coverBefore=true);
  20208. var timer=this.scene ? this.scene.timer :Laya.timer;
  20209. timer._create(false,false,delay,caller,method,args,coverBefore);
  20210. }
  20211. /**
  20212. *定时重复执行某函数(基于帧率)。功能同Laya.timer.frameLoop()。
  20213. *@param delay 间隔几帧(单位为帧)。
  20214. *@param caller 执行域(this)。
  20215. *@param method 结束时的回调方法。
  20216. *@param args (可选)回调参数。
  20217. *@param coverBefore (可选)是否覆盖之前的延迟执行,默认为true。
  20218. */
  20219. __proto.frameLoop=function(delay,caller,method,args,coverBefore){
  20220. (coverBefore===void 0)&& (coverBefore=true);
  20221. var timer=this.scene ? this.scene.timer :Laya.timer;
  20222. timer._create(true,true,delay,caller,method,args,coverBefore);
  20223. }
  20224. /**
  20225. *定时执行一次某函数(基于帧率)。功能同Laya.timer.frameOnce()。
  20226. *@param delay 延迟几帧(单位为帧)。
  20227. *@param caller 执行域(this)
  20228. *@param method 结束时的回调方法
  20229. *@param args (可选)回调参数
  20230. *@param coverBefore (可选)是否覆盖之前的延迟执行,默认为true
  20231. */
  20232. __proto.frameOnce=function(delay,caller,method,args,coverBefore){
  20233. (coverBefore===void 0)&& (coverBefore=true);
  20234. var timer=this.scene ? this.scene.timer :Laya.timer;
  20235. timer._create(true,false,delay,caller,method,args,coverBefore);
  20236. }
  20237. /**
  20238. *清理定时器。功能同Laya.timer.clearTimer()。
  20239. *@param caller 执行域(this)。
  20240. *@param method 结束时的回调方法。
  20241. */
  20242. __proto.clearTimer=function(caller,method){
  20243. var timer=this.scene ? this.scene.timer :Laya.timer;
  20244. timer.clear(caller,method);
  20245. }
  20246. /**
  20247. *<p>延迟运行指定的函数。</p>
  20248. *<p>在控件被显示在屏幕之前调用,一般用于延迟计算数据。</p>
  20249. *@param method 要执行的函数的名称。例如,functionName。
  20250. *@param args 传递给 <code>method</code> 函数的可选参数列表。
  20251. *
  20252. *@see #runCallLater()
  20253. */
  20254. __proto.callLater=function(method,args){
  20255. var timer=this.scene ? this.scene.timer :Laya.timer;
  20256. timer.callLater(this,method,args);
  20257. }
  20258. /**
  20259. *<p>如果有需要延迟调用的函数(通过 <code>callLater</code> 函数设置),则立即执行延迟调用函数。</p>
  20260. *@param method 要执行的函数名称。例如,functionName。
  20261. *@see #callLater()
  20262. */
  20263. __proto.runCallLater=function(method){
  20264. var timer=this.scene ? this.scene.timer :Laya.timer;
  20265. timer.runCallLater(this,method);
  20266. }
  20267. /**
  20268. *@private
  20269. */
  20270. __proto._onActive=function(){
  20271. Stat.spriteCount++;
  20272. }
  20273. /**
  20274. *@private
  20275. */
  20276. __proto._onInActive=function(){
  20277. Stat.spriteCount--;
  20278. }
  20279. /**
  20280. *@private
  20281. */
  20282. __proto._onActiveInScene=function(){}
  20283. /**
  20284. *@private
  20285. */
  20286. __proto._onInActiveInScene=function(){}
  20287. /**
  20288. *@private
  20289. */
  20290. __proto._parse=function(data,spriteMap){}
  20291. /**
  20292. *@private
  20293. */
  20294. __proto._setBelongScene=function(scene){
  20295. if (!this._scene){
  20296. this._scene=scene;
  20297. if (this._components){
  20298. for (var i=0,n=this._components.length;i < n;i++)
  20299. this._components[i]._setActiveInScene(true);
  20300. }
  20301. this._onActiveInScene();
  20302. for (i=0,n=this._children.length;i < n;i++)
  20303. this._children[i]._setBelongScene(scene);
  20304. }
  20305. }
  20306. /**
  20307. *@private
  20308. */
  20309. __proto._setUnBelongScene=function(){
  20310. if (this._scene!==this){
  20311. this._onInActiveInScene();
  20312. if (this._components){
  20313. for (var i=0,n=this._components.length;i < n;i++)
  20314. this._components[i]._setActiveInScene(false);
  20315. }
  20316. this._scene=null;
  20317. for (i=0,n=this._children.length;i < n;i++)
  20318. this._children[i]._setUnBelongScene();
  20319. }
  20320. }
  20321. /**
  20322. *组件被激活后执行,此时所有节点和组件均已创建完毕,次方法只执行一次
  20323. *此方法为虚方法,使用时重写覆盖即可
  20324. */
  20325. __proto.onAwake=function(){}
  20326. /**
  20327. *组件被启用后执行,比如节点被添加到舞台后
  20328. *此方法为虚方法,使用时重写覆盖即可
  20329. */
  20330. __proto.onEnable=function(){}
  20331. /**
  20332. *@private
  20333. */
  20334. __proto._processActive=function(){
  20335. (this._activeChangeScripts)|| (this._activeChangeScripts=[]);
  20336. this._activeHierarchy(this._activeChangeScripts);
  20337. this._activeScripts();
  20338. }
  20339. /**
  20340. *@private
  20341. */
  20342. __proto._activeHierarchy=function(activeChangeScripts){
  20343. this._setBit(/*laya.Const.ACTIVE_INHIERARCHY*/0x02,true);
  20344. if (this._components){
  20345. for (var i=0,n=this._components.length;i < n;i++){
  20346. var comp=this._components[i];
  20347. comp._setActive(true);
  20348. (comp._isScript()&& comp._enabled)&& (activeChangeScripts.push(comp));
  20349. }
  20350. }
  20351. this._onActive();
  20352. for (i=0,n=this._children.length;i < n;i++){
  20353. var child=this._children[i];
  20354. (!child._getBit(/*laya.Const.NOT_ACTIVE*/0x01))&& (child._activeHierarchy(activeChangeScripts));
  20355. }
  20356. if (!this._getBit(/*laya.Const.AWAKED*/0x04)){
  20357. this._setBit(/*laya.Const.AWAKED*/0x04,true);
  20358. this.onAwake();
  20359. }
  20360. this.onEnable();
  20361. }
  20362. /**
  20363. *@private
  20364. */
  20365. __proto._activeScripts=function(){
  20366. for (var i=0,n=this._activeChangeScripts.length;i < n;i++)
  20367. this._activeChangeScripts[i].onEnable();
  20368. this._activeChangeScripts.length=0;
  20369. }
  20370. /**
  20371. *@private
  20372. */
  20373. __proto._processInActive=function(){
  20374. (this._activeChangeScripts)|| (this._activeChangeScripts=[]);
  20375. this._inActiveHierarchy(this._activeChangeScripts);
  20376. this._inActiveScripts();
  20377. }
  20378. /**
  20379. *@private
  20380. */
  20381. __proto._inActiveHierarchy=function(activeChangeScripts){
  20382. this._onInActive();
  20383. if (this._components){
  20384. for (var i=0,n=this._components.length;i < n;i++){
  20385. var comp=this._components[i];
  20386. comp._setActive(false);
  20387. (comp._isScript()&& comp._enabled)&& (activeChangeScripts.push(comp));
  20388. }
  20389. }
  20390. this._setBit(/*laya.Const.ACTIVE_INHIERARCHY*/0x02,false);
  20391. for (i=0,n=this._children.length;i < n;i++){
  20392. var child=this._children[i];
  20393. (child && !child._getBit(/*laya.Const.NOT_ACTIVE*/0x01))&& (child._inActiveHierarchy(activeChangeScripts));
  20394. }
  20395. this.onDisable();
  20396. }
  20397. /**
  20398. *@private
  20399. */
  20400. __proto._inActiveScripts=function(){
  20401. for (var i=0,n=this._activeChangeScripts.length;i < n;i++)
  20402. this._activeChangeScripts[i].onDisable();
  20403. this._activeChangeScripts.length=0;
  20404. }
  20405. /**
  20406. *组件被禁用时执行,比如从节点从舞台移除后
  20407. *此方法为虚方法,使用时重写覆盖即可
  20408. */
  20409. __proto.onDisable=function(){}
  20410. /**
  20411. *@private
  20412. */
  20413. __proto._onAdded=function(){
  20414. if (this._activeChangeScripts && this._activeChangeScripts.length!==0){
  20415. throw "Node: can't set the main inActive node active in hierarchy,if the operate is in main inActive node or it's children script's onDisable Event.";
  20416. }else {
  20417. var parentScene=this._parent.scene;
  20418. parentScene && this._setBelongScene(parentScene);
  20419. (this._parent.activeInHierarchy && this.active)&& this._processActive();
  20420. }
  20421. }
  20422. /**
  20423. *@private
  20424. */
  20425. __proto._onRemoved=function(){
  20426. if (this._activeChangeScripts && this._activeChangeScripts.length!==0){
  20427. throw "Node: can't set the main active node inActive in hierarchy,if the operate is in main active node or it's children script's onEnable Event.";
  20428. }else {
  20429. (this._parent.activeInHierarchy && this.active)&& this._processInActive();
  20430. this._parent.scene && this._setUnBelongScene();
  20431. }
  20432. }
  20433. /**
  20434. *@private
  20435. */
  20436. __proto._addComponentInstance=function(comp){
  20437. this._components=this._components||[];
  20438. this._components.push(comp);
  20439. comp.owner=this;
  20440. comp._onAdded();
  20441. if (this.activeInHierarchy){
  20442. comp._setActive(true);
  20443. (comp._isScript()&& comp._enabled)&& ((comp).onEnable());
  20444. }
  20445. this._scene && comp._setActiveInScene(true);
  20446. }
  20447. /**
  20448. *@private
  20449. */
  20450. __proto._destroyComponent=function(comp){
  20451. if (this._components){
  20452. for (var i=0,n=this._components.length;i < n;i++){
  20453. var item=this._components[i];
  20454. if (item===comp){
  20455. item._destroy();
  20456. this._components.splice(i,1);
  20457. break ;
  20458. }
  20459. }
  20460. }
  20461. }
  20462. /**
  20463. *@private
  20464. */
  20465. __proto._destroyAllComponent=function(){
  20466. if (this._components){
  20467. for (var i=0,n=this._components.length;i < n;i++){
  20468. var item=this._components[i];
  20469. item._destroy();
  20470. }
  20471. this._components.length=0;
  20472. }
  20473. }
  20474. /**
  20475. *@private 克隆。
  20476. *@param destObject 克隆源。
  20477. */
  20478. __proto._cloneTo=function(destObject,srcRoot,dstRoot){
  20479. var destNode=destObject;
  20480. if (this._components){
  20481. for (var i=0,n=this._components.length;i < n;i++){
  20482. var destComponent=destNode.addComponent(this._components[i].constructor);
  20483. this._components[i]._cloneTo(destComponent);
  20484. }
  20485. }
  20486. }
  20487. /**
  20488. *添加组件实例。
  20489. *@param comp 组件实例。
  20490. *@return 组件。
  20491. */
  20492. __proto.addComponentIntance=function(comp){
  20493. if (comp.owner)
  20494. throw "Node:the component has belong to other node.";
  20495. if (comp.isSingleton && this.getComponent((comp).constructor))
  20496. throw "Node:the component is singleton,can't add the second one.";
  20497. this._addComponentInstance(comp);
  20498. return comp;
  20499. }
  20500. /**
  20501. *添加组件。
  20502. *@param type 组件类型。
  20503. *@return 组件。
  20504. */
  20505. __proto.addComponent=function(type){
  20506. var comp=Pool.createByClass(type);
  20507. comp._destroyed=false;
  20508. if (comp.isSingleton && this.getComponent(type))
  20509. throw "无法实例"+type+"组件"+","+type+"组件已存在!";
  20510. this._addComponentInstance(comp);
  20511. return comp;
  20512. }
  20513. /**
  20514. *获得组件实例,如果没有则返回为null
  20515. *@param clas 组建类型
  20516. *@return 返回组件
  20517. */
  20518. __proto.getComponent=function(clas){
  20519. if (this._components){
  20520. for (var i=0,n=this._components.length;i < n;i++){
  20521. var comp=this._components[i];
  20522. if (Laya.__typeof(comp,clas))
  20523. return comp;
  20524. }
  20525. }
  20526. return null;
  20527. }
  20528. /**
  20529. *获得组件实例,如果没有则返回为null
  20530. *@param clas 组建类型
  20531. *@return 返回组件数组
  20532. */
  20533. __proto.getComponents=function(clas){
  20534. var arr;
  20535. if (this._components){
  20536. for (var i=0,n=this._components.length;i < n;i++){
  20537. var comp=this._components[i];
  20538. if (Laya.__typeof(comp,clas)){
  20539. arr=arr||[];
  20540. arr.push(comp);
  20541. }
  20542. }
  20543. }
  20544. return arr;
  20545. }
  20546. /**
  20547. *子对象数量。
  20548. */
  20549. __getset(0,__proto,'numChildren',function(){
  20550. return this._children.length;
  20551. });
  20552. /**父节点。*/
  20553. __getset(0,__proto,'parent',function(){
  20554. return this._parent;
  20555. });
  20556. /**
  20557. *获取在场景中是否激活。
  20558. *@return 在场景中是否激活。
  20559. */
  20560. __getset(0,__proto,'activeInHierarchy',function(){
  20561. return this._getBit(/*laya.Const.ACTIVE_INHIERARCHY*/0x02);
  20562. });
  20563. /**
  20564. *设置是否激活。
  20565. *@param value 是否激活。
  20566. */
  20567. /**
  20568. *获取自身是否激活。
  20569. *@return 自身是否激活。
  20570. */
  20571. __getset(0,__proto,'active',function(){
  20572. return !this._getBit(/*laya.Const.NOT_READY*/0x08)&& !this._getBit(/*laya.Const.NOT_ACTIVE*/0x01);
  20573. },function(value){
  20574. value=!!value;
  20575. if (!this._getBit(/*laya.Const.NOT_ACTIVE*/0x01)!==value){
  20576. if (this._activeChangeScripts && this._activeChangeScripts.length!==0){
  20577. if (value)
  20578. throw "Node: can't set the main inActive node active in hierarchy,if the operate is in main inActive node or it's children script's onDisable Event.";
  20579. else
  20580. throw "Node: can't set the main active node inActive in hierarchy,if the operate is in main active node or it's children script's onEnable Event.";
  20581. }else {
  20582. this._setBit(/*laya.Const.NOT_ACTIVE*/0x01,!value);
  20583. if (this._parent){
  20584. if (this._parent.activeInHierarchy){
  20585. if (value)this._processActive();
  20586. else this._processInActive();
  20587. }
  20588. }
  20589. }
  20590. }
  20591. });
  20592. /**表示是否在显示列表中显示。*/
  20593. __getset(0,__proto,'displayedInStage',function(){
  20594. if (this._getBit(/*laya.Const.DISPLAY*/0x10))return this._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80);
  20595. this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  20596. return this._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80);
  20597. });
  20598. /**
  20599. *获得所属场景。
  20600. *@return 场景。
  20601. */
  20602. __getset(0,__proto,'scene',function(){
  20603. return this._scene;
  20604. });
  20605. /**
  20606. *@private
  20607. *获取timer
  20608. */
  20609. __getset(0,__proto,'timer',function(){
  20610. return this.scene ? this.scene.timer :Laya.timer;
  20611. });
  20612. Node.ARRAY_EMPTY=[];
  20613. return Node;
  20614. })(EventDispatcher)
  20615. /**
  20616. *@private
  20617. *<code>Resource</code> 资源存取类。
  20618. */
  20619. //class laya.resource.Resource extends laya.events.EventDispatcher
  20620. var Resource=(function(_super){
  20621. function Resource(){
  20622. /**@private */
  20623. this._id=0;
  20624. /**@private */
  20625. this._url=null;
  20626. /**@private */
  20627. this._cpuMemory=0;
  20628. /**@private */
  20629. this._gpuMemory=0;
  20630. /**@private */
  20631. this._destroyed=false;
  20632. /**@private */
  20633. this._referenceCount=0;
  20634. /**是否加锁,如果true为不能使用自动释放机制。*/
  20635. this.lock=false;
  20636. /**名称。 */
  20637. this.name=null;
  20638. Resource.__super.call(this);
  20639. this._id=++Resource._uniqueIDCounter;
  20640. this._destroyed=false;
  20641. this._referenceCount=0;
  20642. Resource._idResourcesMap[this.id]=this;
  20643. this.lock=false;
  20644. }
  20645. __class(Resource,'laya.resource.Resource',_super);
  20646. var __proto=Resource.prototype;
  20647. Laya.imps(__proto,{"laya.resource.ICreateResource":true,"laya.resource.IDestroy":true})
  20648. /**
  20649. *@private
  20650. */
  20651. __proto._setCPUMemory=function(value){
  20652. var offsetValue=value-this._cpuMemory;
  20653. this._cpuMemory=value;
  20654. Resource._addCPUMemory(offsetValue);
  20655. }
  20656. /**
  20657. *@private
  20658. */
  20659. __proto._setGPUMemory=function(value){
  20660. var offsetValue=value-this._gpuMemory;
  20661. this._gpuMemory=value;
  20662. Resource._addGPUMemory(offsetValue);
  20663. }
  20664. /**
  20665. *@private
  20666. */
  20667. __proto._setCreateURL=function(url){
  20668. url=URL.formatURL(url);
  20669. if (this._url!==url){
  20670. var resList;
  20671. if (this._url){
  20672. resList=Resource._urlResourcesMap[this._url];
  20673. resList.splice(resList.indexOf(this),1);
  20674. (resList.length===0)&& (delete Resource._urlResourcesMap[this._url]);
  20675. }
  20676. if (url){
  20677. resList=Resource._urlResourcesMap[url];
  20678. (resList)|| (Resource._urlResourcesMap[url]=resList=[]);
  20679. resList.push(this);
  20680. }
  20681. this._url=url;
  20682. }
  20683. }
  20684. /**
  20685. *@private
  20686. */
  20687. __proto._addReference=function(count){
  20688. (count===void 0)&& (count=1);
  20689. this._referenceCount+=count;
  20690. }
  20691. /**
  20692. *@private
  20693. */
  20694. __proto._removeReference=function(count){
  20695. (count===void 0)&& (count=1);
  20696. this._referenceCount-=count;
  20697. }
  20698. /**
  20699. *@private
  20700. */
  20701. __proto._clearReference=function(){
  20702. this._referenceCount=0;
  20703. }
  20704. /**
  20705. *@private
  20706. */
  20707. __proto._recoverResource=function(){}
  20708. /**
  20709. *@private
  20710. */
  20711. __proto._disposeResource=function(){}
  20712. /**
  20713. *@private
  20714. */
  20715. __proto._activeResource=function(){}
  20716. /**
  20717. *销毁资源,销毁后资源不能恢复。
  20718. */
  20719. __proto.destroy=function(){
  20720. if (this._destroyed)
  20721. return;
  20722. this._destroyed=true;
  20723. this.lock=false;
  20724. this._disposeResource();
  20725. delete Resource._idResourcesMap[this.id];
  20726. var resList;
  20727. if (this._url){
  20728. resList=Resource._urlResourcesMap[this._url];
  20729. if (resList){
  20730. resList.splice(resList.indexOf(this),1);
  20731. (resList.length===0)&& (delete Resource._urlResourcesMap[this._url]);
  20732. };
  20733. var resou=Loader.getRes(this._url);
  20734. (resou==this)&& (delete Loader.loadedMap[this._url]);
  20735. }
  20736. }
  20737. /**
  20738. *获取唯一标识ID,通常用于识别。
  20739. */
  20740. __getset(0,__proto,'id',function(){
  20741. return this._id;
  20742. });
  20743. /**
  20744. *显存大小。
  20745. */
  20746. __getset(0,__proto,'gpuMemory',function(){
  20747. return this._gpuMemory;
  20748. });
  20749. /**
  20750. *获取资源的URL地址。
  20751. *@return URL地址。
  20752. */
  20753. __getset(0,__proto,'url',function(){
  20754. return this._url;
  20755. });
  20756. /**
  20757. *内存大小。
  20758. */
  20759. __getset(0,__proto,'cpuMemory',function(){
  20760. return this._cpuMemory;
  20761. });
  20762. /**
  20763. *是否已处理。
  20764. */
  20765. __getset(0,__proto,'destroyed',function(){
  20766. return this._destroyed;
  20767. });
  20768. /**
  20769. *获取资源的引用计数。
  20770. */
  20771. __getset(0,__proto,'referenceCount',function(){
  20772. return this._referenceCount;
  20773. });
  20774. /**
  20775. *当前内存,以字节为单位。
  20776. */
  20777. __getset(1,Resource,'cpuMemory',function(){
  20778. return this._cpuMemory;
  20779. },laya.events.EventDispatcher._$SET_cpuMemory);
  20780. /**
  20781. *当前显存,以字节为单位。
  20782. */
  20783. __getset(1,Resource,'gpuMemory',function(){
  20784. return this._gpuMemory;
  20785. },laya.events.EventDispatcher._$SET_gpuMemory);
  20786. Resource._addCPUMemory=function(size){
  20787. this._cpuMemory+=size;
  20788. }
  20789. Resource._addGPUMemory=function(size){
  20790. this._gpuMemory+=size;
  20791. }
  20792. Resource._addMemory=function(cpuSize,gpuSize){
  20793. this._cpuMemory+=cpuSize;
  20794. this._gpuMemory+=gpuSize;
  20795. }
  20796. Resource.getResourceByID=function(id){
  20797. return Resource._idResourcesMap[id];
  20798. }
  20799. Resource.getResourceByURL=function(url,index){
  20800. (index===void 0)&& (index=0);
  20801. return Resource._urlResourcesMap[url][index];
  20802. }
  20803. Resource.destroyUnusedResources=function(){
  20804. for (var k in Resource._idResourcesMap){
  20805. var res=Resource._idResourcesMap[k];
  20806. if (!res.lock && res._referenceCount===0)
  20807. res.destroy();
  20808. }
  20809. }
  20810. Resource._uniqueIDCounter=0;
  20811. Resource._idResourcesMap={};
  20812. Resource._urlResourcesMap={};
  20813. Resource._cpuMemory=0;
  20814. Resource._gpuMemory=0;
  20815. return Resource;
  20816. })(EventDispatcher)
  20817. //class laya.webgl.utils.Buffer2D extends laya.webgl.utils.Buffer
  20818. var Buffer2D=(function(_super){
  20819. function Buffer2D(){
  20820. this._maxsize=0;
  20821. this._upload=true;
  20822. this._uploadSize=0;
  20823. this._bufferSize=0;
  20824. this._u8Array=null;
  20825. Buffer2D.__super.call(this);
  20826. }
  20827. __class(Buffer2D,'laya.webgl.utils.Buffer2D',_super);
  20828. var __proto=Buffer2D.prototype;
  20829. __proto.setByteLength=function(value){
  20830. if (this._byteLength!==value){
  20831. value <=this._bufferSize || (this._resizeBuffer(value *2+256,true));
  20832. this._byteLength=value;
  20833. }
  20834. }
  20835. /**
  20836. *在当前的基础上需要多大空间,单位是byte
  20837. *@param sz
  20838. *@return 增加大小之前的写位置。单位是byte
  20839. */
  20840. __proto.needSize=function(sz){
  20841. var old=this._byteLength;
  20842. if (sz){
  20843. var needsz=this._byteLength+sz;
  20844. needsz <=this._bufferSize || (this._resizeBuffer(needsz << 1,true));
  20845. this._byteLength=needsz;
  20846. }
  20847. return old;
  20848. }
  20849. __proto._bufferData=function(){
  20850. this._maxsize=Math.max(this._maxsize,this._byteLength);
  20851. if (Stat.loopCount % 30==0){
  20852. if (this._buffer.byteLength > (this._maxsize+64)){
  20853. this._buffer=this._buffer.slice(0,this._maxsize+64);
  20854. this._bufferSize=this._buffer.byteLength;
  20855. this._checkArrayUse();
  20856. }
  20857. this._maxsize=this._byteLength;
  20858. }
  20859. if (this._uploadSize < this._buffer.byteLength){
  20860. this._uploadSize=this._buffer.byteLength;
  20861. LayaGL.instance.bufferData(this._bufferType,this._uploadSize,this._bufferUsage);
  20862. }
  20863. LayaGL.instance.bufferSubData(this._bufferType,0,new Uint8Array(this._buffer,0,this._byteLength));
  20864. }
  20865. //TODO:coverage
  20866. __proto._bufferSubData=function(offset,dataStart,dataLength){
  20867. (offset===void 0)&& (offset=0);
  20868. (dataStart===void 0)&& (dataStart=0);
  20869. (dataLength===void 0)&& (dataLength=0);
  20870. this._maxsize=Math.max(this._maxsize,this._byteLength);
  20871. if (Stat.loopCount % 30==0){
  20872. if (this._buffer.byteLength > (this._maxsize+64)){
  20873. this._buffer=this._buffer.slice(0,this._maxsize+64);
  20874. this._bufferSize=this._buffer.byteLength;
  20875. this._checkArrayUse();
  20876. }
  20877. this._maxsize=this._byteLength;
  20878. }
  20879. if (this._uploadSize < this._buffer.byteLength){
  20880. this._uploadSize=this._buffer.byteLength;
  20881. LayaGL.instance.bufferData(this._bufferType,this._uploadSize,this._bufferUsage);
  20882. }
  20883. if (dataStart || dataLength){
  20884. var subBuffer=this._buffer.slice(dataStart,dataLength);
  20885. LayaGL.instance.bufferSubData(this._bufferType,offset,subBuffer);
  20886. }else {
  20887. LayaGL.instance.bufferSubData(this._bufferType,offset,this._buffer);
  20888. }
  20889. }
  20890. /**
  20891. *buffer重新分配了,继承类根据需要做相应的处理。
  20892. */
  20893. __proto._checkArrayUse=function(){}
  20894. /**
  20895. *给vao使用的 _bind_upload函数。不要与已经绑定的判断是否相同
  20896. *@return
  20897. */
  20898. __proto._bind_uploadForVAO=function(){
  20899. if (!this._upload)
  20900. return false;
  20901. this._upload=false;
  20902. this._bindForVAO();
  20903. this._bufferData();
  20904. return true;
  20905. }
  20906. __proto._bind_upload=function(){
  20907. if (!this._upload)
  20908. return false;
  20909. this._upload=false;
  20910. this.bind();
  20911. this._bufferData();
  20912. return true;
  20913. }
  20914. //TODO:coverage
  20915. __proto._bind_subUpload=function(offset,dataStart,dataLength){
  20916. (offset===void 0)&& (offset=0);
  20917. (dataStart===void 0)&& (dataStart=0);
  20918. (dataLength===void 0)&& (dataLength=0);
  20919. if (!this._upload)
  20920. return false;
  20921. this._upload=false;
  20922. this.bind();
  20923. this._bufferSubData(offset,dataStart,dataLength);
  20924. return true;
  20925. }
  20926. /**
  20927. *重新分配buffer大小,如果nsz比原来的小则什么都不做。
  20928. *@param nsz buffer大小,单位是byte。
  20929. *@param copy 是否拷贝原来的buffer的数据。
  20930. *@return
  20931. */
  20932. __proto._resizeBuffer=function(nsz,copy){
  20933. var buff=this._buffer;
  20934. if (nsz <=buff.byteLength)
  20935. return this;
  20936. var u8buf=this._u8Array;
  20937. if (copy && buff && buff.byteLength > 0){
  20938. var newbuffer=new ArrayBuffer(nsz);
  20939. var oldU8Arr=(u8buf && u8buf.buffer==buff)?u8buf :new Uint8Array(buff);
  20940. u8buf=this._u8Array=new Uint8Array(newbuffer);
  20941. u8buf.set(oldU8Arr,0);
  20942. buff=this._buffer=newbuffer;
  20943. }else{
  20944. buff=this._buffer=new ArrayBuffer(nsz);
  20945. this._u8Array=null;
  20946. }
  20947. this._checkArrayUse();
  20948. this._upload=true;
  20949. this._bufferSize=buff.byteLength;
  20950. return this;
  20951. }
  20952. __proto.append=function(data){
  20953. this._upload=true;
  20954. var byteLen=0,n;
  20955. byteLen=data.byteLength;
  20956. if ((data instanceof Uint8Array)){
  20957. this._resizeBuffer(this._byteLength+byteLen,true);
  20958. n=new Uint8Array(this._buffer,this._byteLength);
  20959. }else if ((data instanceof Uint16Array)){
  20960. this._resizeBuffer(this._byteLength+byteLen,true);
  20961. n=new Uint16Array(this._buffer,this._byteLength);
  20962. }else if ((data instanceof Float32Array)){
  20963. this._resizeBuffer(this._byteLength+byteLen,true);
  20964. n=new Float32Array(this._buffer,this._byteLength);
  20965. }
  20966. n.set(data,0);
  20967. this._byteLength+=byteLen;
  20968. this._checkArrayUse();
  20969. }
  20970. /**
  20971. *附加Uint16Array的数据。数据长度是len。byte的话要*2
  20972. *@param data
  20973. *@param len
  20974. */
  20975. __proto.appendU16Array=function(data,len){
  20976. this._resizeBuffer(this._byteLength+len*2,true);
  20977. var u=new Uint16Array(this._buffer,this._byteLength,len);
  20978. if (len==6){
  20979. u[0]=data[0];u[1]=data[1];u[2]=data[2];
  20980. u[3]=data[3];u[4]=data[4];u[5]=data[5];
  20981. }else if(len>=100){
  20982. /*__JS__ */u.set(new Uint16Array(data.buffer,0,len));
  20983. }else{
  20984. for (var i=0;i < len;i++){
  20985. u[i]=data[i];
  20986. }
  20987. }
  20988. this._byteLength+=len *2;
  20989. this._checkArrayUse();
  20990. }
  20991. //TODO:coverage
  20992. __proto.appendEx=function(data,type){
  20993. this._upload=true;
  20994. var byteLen=0,n;
  20995. byteLen=data.byteLength;
  20996. this._resizeBuffer(this._byteLength+byteLen,true);
  20997. n=new type(this._buffer,this._byteLength);
  20998. n.set(data,0);
  20999. this._byteLength+=byteLen;
  21000. this._checkArrayUse();
  21001. }
  21002. //TODO:coverage
  21003. __proto.appendEx2=function(data,type,dataLen,perDataLen){
  21004. (perDataLen===void 0)&& (perDataLen=1);
  21005. this._upload=true;
  21006. var byteLen=0,n;
  21007. byteLen=dataLen*perDataLen;
  21008. this._resizeBuffer(this._byteLength+byteLen,true);
  21009. n=new type(this._buffer,this._byteLength);
  21010. var i=0;
  21011. for (i=0;i < dataLen;i++){
  21012. n[i]=data[i];
  21013. }
  21014. this._byteLength+=byteLen;
  21015. this._checkArrayUse();
  21016. }
  21017. //TODO:coverage
  21018. __proto.getBuffer=function(){
  21019. return this._buffer;
  21020. }
  21021. __proto.setNeedUpload=function(){
  21022. this._upload=true;
  21023. }
  21024. //TODO:coverage
  21025. __proto.getNeedUpload=function(){
  21026. return this._upload;
  21027. }
  21028. //TODO:coverage
  21029. __proto.upload=function(){
  21030. var scuess=this._bind_upload();
  21031. LayaGL.instance.bindBuffer(this._bufferType,null);
  21032. if(this._bufferType==/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892)Buffer._bindedVertexBuffer=null;
  21033. if(this._bufferType==/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893)Buffer._bindedIndexBuffer=null;
  21034. BaseShader.activeShader=null
  21035. return scuess;
  21036. }
  21037. //TODO:coverage
  21038. __proto.subUpload=function(offset,dataStart,dataLength){
  21039. (offset===void 0)&& (offset=0);
  21040. (dataStart===void 0)&& (dataStart=0);
  21041. (dataLength===void 0)&& (dataLength=0);
  21042. var scuess=this._bind_subUpload();
  21043. LayaGL.instance.bindBuffer(this._bufferType,null);
  21044. if(this._bufferType==/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892)Buffer._bindedVertexBuffer=null;
  21045. if(this._bufferType==/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893)Buffer._bindedIndexBuffer=null;
  21046. BaseShader.activeShader=null
  21047. return scuess;
  21048. }
  21049. __proto._disposeResource=function(){
  21050. this._upload=true;
  21051. this._uploadSize=0;
  21052. }
  21053. /**
  21054. *清理数据。保留ArrayBuffer
  21055. */
  21056. __proto.clear=function(){
  21057. this._byteLength=0;
  21058. this._upload=true;
  21059. }
  21060. //反正常常要拷贝老的数据,所以保留这个可以提高效率
  21061. __getset(0,__proto,'bufferLength',function(){
  21062. return this._buffer.byteLength;
  21063. });
  21064. __getset(0,__proto,'byteLength',null,function(value){
  21065. this.setByteLength(value);
  21066. });
  21067. Buffer2D.__int__=function(gl){}
  21068. Buffer2D.FLOAT32=4;
  21069. Buffer2D.SHORT=2;
  21070. return Buffer2D;
  21071. })(Buffer)
  21072. /**
  21073. *<code>CommonScript</code> 类用于创建公共脚本类。
  21074. */
  21075. //class laya.components.CommonScript extends laya.components.Component
  21076. var CommonScript=(function(_super){
  21077. function CommonScript(){
  21078. CommonScript.__super.call(this);
  21079. }
  21080. __class(CommonScript,'laya.components.CommonScript',_super);
  21081. var __proto=CommonScript.prototype;
  21082. /**
  21083. *创建后只执行一次
  21084. *此方法为虚方法,使用时重写覆盖即可
  21085. */
  21086. __proto.onAwake=function(){}
  21087. /**
  21088. *每次启动后执行
  21089. *此方法为虚方法,使用时重写覆盖即可
  21090. */
  21091. __proto.onEnable=function(){}
  21092. /**
  21093. *第一次执行update之前执行,只会执行一次
  21094. *此方法为虚方法,使用时重写覆盖即可
  21095. */
  21096. __proto.onStart=function(){}
  21097. /**
  21098. *每帧更新时执行
  21099. *此方法为虚方法,使用时重写覆盖即可
  21100. */
  21101. __proto.onUpdate=function(){}
  21102. /**
  21103. *每帧更新时执行,在update之后执行
  21104. *此方法为虚方法,使用时重写覆盖即可
  21105. */
  21106. __proto.onLateUpdate=function(){}
  21107. /**
  21108. *禁用时执行
  21109. *此方法为虚方法,使用时重写覆盖即可
  21110. */
  21111. __proto.onDisable=function(){}
  21112. /**
  21113. *销毁时执行
  21114. *此方法为虚方法,使用时重写覆盖即可
  21115. */
  21116. __proto.onDestroy=function(){}
  21117. /**
  21118. *@inheritDoc
  21119. */
  21120. __getset(0,__proto,'isSingleton',function(){
  21121. return false;
  21122. });
  21123. return CommonScript;
  21124. })(Component)
  21125. /**
  21126. *<p> <code>LoaderManager</code> 类用于用于批量加载资源。此类是单例,不要手动实例化此类,请通过Laya.loader访问。</p>
  21127. *<p>全部队列加载完成,会派发 Event.COMPLETE 事件;如果队列中任意一个加载失败,会派发 Event.ERROR 事件,事件回调参数值为加载出错的资源地址。</p>
  21128. *<p> <code>LoaderManager</code> 类提供了以下几种功能:<br/>
  21129. *多线程:默认5个加载线程,可以通过maxLoader属性修改线程数量;<br/>
  21130. *多优先级:有0-4共5个优先级,优先级高的优先加载。0最高,4最低;<br/>
  21131. *重复过滤:自动过滤重复加载(不会有多个相同地址的资源同时加载)以及复用缓存资源,防止重复加载;<br/>
  21132. *错误重试:资源加载失败后,会重试加载(以最低优先级插入加载队列),retryNum设定加载失败后重试次数,retryDelay设定加载重试的时间间隔。</p>
  21133. *@see laya.net.Loader
  21134. */
  21135. //class laya.net.LoaderManager extends laya.events.EventDispatcher
  21136. var LoaderManager=(function(_super){
  21137. var ResInfo;
  21138. function LoaderManager(){
  21139. /**加载出错后的重试次数,默认重试一次*/
  21140. this.retryNum=1;
  21141. /**延迟时间多久再进行错误重试,默认立即重试*/
  21142. this.retryDelay=0;
  21143. /**最大下载线程,默认为5个*/
  21144. this.maxLoader=5;
  21145. /**@private */
  21146. this._loaders=[];
  21147. /**@private */
  21148. this._loaderCount=0;
  21149. /**@private */
  21150. this._resInfos=[];
  21151. /**@private */
  21152. this._infoPool=[];
  21153. /**@private */
  21154. this._maxPriority=5;
  21155. /**@private */
  21156. this._failRes={};
  21157. /**@private */
  21158. this._statInfo={count:1,loaded:1};
  21159. LoaderManager.__super.call(this);
  21160. for (var i=0;i < this._maxPriority;i++)this._resInfos[i]=[];
  21161. }
  21162. __class(LoaderManager,'laya.net.LoaderManager',_super);
  21163. var __proto=LoaderManager.prototype;
  21164. /**@private */
  21165. __proto.getProgress=function(){
  21166. return this._statInfo.loaded / this._statInfo.count;
  21167. }
  21168. /**@private */
  21169. __proto.resetProgress=function(){
  21170. this._statInfo.count=this._statInfo.loaded=1;
  21171. }
  21172. /**
  21173. *<p>根据clas类型创建一个未初始化资源的对象,随后进行异步加载,资源加载完成后,初始化对象的资源,并通过此对象派发 Event.LOADED 事件,事件回调参数值为此对象本身。套嵌资源的子资源会保留资源路径"?"后的部分。</p>
  21174. *<p>如果url为数组,返回true;否则返回指定的资源类对象,可以通过侦听此对象的 Event.LOADED 事件来判断资源是否已经加载完毕。</p>
  21175. *<p><b>注意:</b>cache参数只能对文件后缀为atlas的资源进行缓存控制,其他资源会忽略缓存,强制重新加载。</p>
  21176. *@param url 资源地址或者数组。如果url和clas同时指定了资源类型,优先使用url指定的资源类型。参数形如:[{url:xx,clas:xx,priority:xx,params:xx},{url:xx,clas:xx,priority:xx,params:xx}]。
  21177. *@param complete 加载结束回调。根据url类型不同分为2种情况:1. url为String类型,也就是单个资源地址,如果加载成功,则回调参数值为加载完成的资源,否则为null;2. url为数组类型,指定了一组要加载的资源,如果全部加载成功,则回调参数值为true,否则为false。
  21178. *@param progress 资源加载进度回调,回调参数值为当前资源加载的进度信息(0-1)。
  21179. *@param type 资源类型。
  21180. *@param constructParams 资源构造函数参数。
  21181. *@param propertyParams 资源属性参数。
  21182. *@param priority (default=1)加载的优先级,优先级高的优先加载。有0-4共5个优先级,0最高,4最低。
  21183. *@param cache 是否缓存加载的资源。
  21184. *@return 如果url为数组,返回true;否则返回指定的资源类对象。
  21185. */
  21186. __proto.create=function(url,complete,progress,type,constructParams,propertyParams,priority,cache){
  21187. (priority===void 0)&& (priority=1);
  21188. (cache===void 0)&& (cache=true);
  21189. this._create(url,true,complete,progress,type,constructParams,propertyParams,priority,cache);
  21190. }
  21191. /**
  21192. *@private
  21193. */
  21194. __proto._create=function(url,mainResou,complete,progress,type,constructParams,propertyParams,priority,cache){
  21195. (priority===void 0)&& (priority=1);
  21196. (cache===void 0)&& (cache=true);
  21197. if ((url instanceof Array)){
  21198. var allScuess=true;
  21199. var items=url;
  21200. var itemCount=items.length;
  21201. var loadedCount=0;
  21202. if (progress){
  21203. var progress2=Handler.create(progress.caller,progress.method,progress.args,false);
  21204. }
  21205. for (var i=0;i < itemCount;i++){
  21206. var item=items[i];
  21207. if ((typeof item=='string'))
  21208. item=items[i]={url:item};
  21209. item.progress=0;
  21210. }
  21211. for (i=0;i < itemCount;i++){
  21212. item=items[i];
  21213. var progressHandler=progress ? Handler.create(null,onProgress,[item],false):null;
  21214. var completeHandler=(progress || complete)? Handler.create(null,onComplete,[item]):null;
  21215. this._createOne(item.url,mainResou,completeHandler,progressHandler,item.type || type,item.constructParams || constructParams,item.propertyParams || propertyParams,item.priority || priority,cache);
  21216. }
  21217. function onComplete (item,content){
  21218. loadedCount++;
  21219. item.progress=1;
  21220. content || (allScuess=false);
  21221. if (loadedCount===itemCount && complete){
  21222. complete.runWith(allScuess);
  21223. }
  21224. }
  21225. function onProgress (item,value){
  21226. item.progress=value;
  21227. var num=0;
  21228. for (var j=0;j < itemCount;j++){
  21229. var item1=items[j];
  21230. num+=item1.progress;
  21231. };
  21232. var v=num / itemCount;
  21233. progress2.runWith(v);
  21234. }
  21235. }else {
  21236. this._createOne(url,mainResou,complete,progress,type,constructParams,propertyParams,priority,cache);
  21237. }
  21238. }
  21239. /**
  21240. *@private
  21241. */
  21242. __proto._createOne=function(url,mainResou,complete,progress,type,constructParams,propertyParams,priority,cache){
  21243. (priority===void 0)&& (priority=1);
  21244. (cache===void 0)&& (cache=true);
  21245. var item=this.getRes(url);
  21246. if (!item){
  21247. var extension=Utils.getFileExtension(url);
  21248. (type)|| (type=LoaderManager.createMap[extension] ? LoaderManager.createMap[extension][0] :null);
  21249. if (!type){
  21250. this.load(url,complete,progress,type,priority,cache);
  21251. return;
  21252. };
  21253. var parserMap=Loader.parserMap;
  21254. if (!parserMap[type]){
  21255. this.load(url,complete,progress,type,priority,cache);
  21256. return;
  21257. }
  21258. this._createLoad(url,Handler.create(null,onLoaded),progress,type,constructParams,propertyParams,priority,cache,true);
  21259. function onLoaded (createRes){
  21260. if (createRes){
  21261. if (!mainResou && (createRes instanceof laya.resource.Resource ))
  21262. (createRes)._addReference();
  21263. createRes._setCreateURL(url);
  21264. }
  21265. complete && complete.runWith(createRes);
  21266. Laya.loader.event(url);
  21267. };
  21268. }else {
  21269. if (!mainResou && (item instanceof laya.resource.Resource ))
  21270. item._addReference();
  21271. progress && progress.runWith(1);
  21272. complete && complete.runWith(item);
  21273. }
  21274. }
  21275. /**
  21276. *<p>加载资源。资源加载错误时,本对象会派发 Event.ERROR 事件,事件回调参数值为加载出错的资源地址。</p>
  21277. *<p>因为返回值为 LoaderManager 对象本身,所以可以使用如下语法:loaderManager.load(...).load(...);</p>
  21278. *@param url 要加载的单个资源地址或资源信息数组。比如:简单数组:["a.png","b.png"];复杂数组[{url:"a.png",type:Loader.IMAGE,size:100,priority:1},{url:"b.json",type:Loader.JSON,size:50,priority:1}]。
  21279. *@param complete 加载结束回调。根据url类型不同分为2种情况:1. url为String类型,也就是单个资源地址,如果加载成功,则回调参数值为加载完成的资源,否则为null;2. url为数组类型,指定了一组要加载的资源,如果全部加载成功,则回调参数值为true,否则为false。
  21280. *@param progress 加载进度回调。回调参数值为当前资源的加载进度信息(0-1)。
  21281. *@param type 资源类型。比如:Loader.IMAGE。
  21282. *@param priority (default=1)加载的优先级,优先级高的优先加载。有0-4共5个优先级,0最高,4最低。
  21283. *@param cache 是否缓存加载结果。
  21284. *@param group 分组,方便对资源进行管理。
  21285. *@param ignoreCache 是否忽略缓存,强制重新加载。
  21286. *@param useWorkerLoader(default=false)是否使用worker加载(只针对IMAGE类型和ATLAS类型,并且浏览器支持的情况下生效)
  21287. *@return 此 LoaderManager 对象本身。
  21288. */
  21289. __proto.load=function(url,complete,progress,type,priority,cache,group,ignoreCache,useWorkerLoader){
  21290. var _$this=this;
  21291. (priority===void 0)&& (priority=1);
  21292. (cache===void 0)&& (cache=true);
  21293. (ignoreCache===void 0)&& (ignoreCache=false);
  21294. (useWorkerLoader===void 0)&& (useWorkerLoader=false);
  21295. if ((url instanceof Array))return this._loadAssets(url,complete,progress,type,priority,cache,group);
  21296. var content=Loader.getRes(url);
  21297. if (!ignoreCache && content !=null){
  21298. Laya.systemTimer.frameOnce(1,null,function(){
  21299. progress && progress.runWith(1);
  21300. complete && complete.runWith((content instanceof Array)?[content]:content);
  21301. _$this._loaderCount || _$this.event(/*laya.events.Event.COMPLETE*/"complete");
  21302. });
  21303. }else {
  21304. var original;
  21305. original=url;
  21306. url=AtlasInfoManager.getFileLoadPath(url);
  21307. if (url !=original && type!=="nativeimage"){
  21308. type=/*laya.net.Loader.ATLAS*/"atlas";
  21309. }else {
  21310. original=null;
  21311. };
  21312. var info=LoaderManager._resMap[url];
  21313. if (!info){
  21314. info=this._infoPool.length ? this._infoPool.pop():new ResInfo();
  21315. info.url=url;
  21316. info.type=type;
  21317. info.cache=cache;
  21318. info.group=group;
  21319. info.ignoreCache=ignoreCache;
  21320. info.useWorkerLoader=useWorkerLoader;
  21321. info.originalUrl=original;
  21322. complete && info.on(/*laya.events.Event.COMPLETE*/"complete",complete.caller,complete.method,complete.args);
  21323. progress && info.on(/*laya.events.Event.PROGRESS*/"progress",progress.caller,progress.method,progress.args);
  21324. LoaderManager._resMap[url]=info;
  21325. priority=priority < this._maxPriority ? priority :this._maxPriority-1;
  21326. this._resInfos[priority].push(info);
  21327. this._statInfo.count++;
  21328. this.event(/*laya.events.Event.PROGRESS*/"progress",this.getProgress());
  21329. this._next();
  21330. }else {
  21331. if (complete){
  21332. if (original){
  21333. complete && info._createListener(/*laya.events.Event.COMPLETE*/"complete",this,this._resInfoLoaded,[original,complete],false,false);
  21334. }else {
  21335. complete && info._createListener(/*laya.events.Event.COMPLETE*/"complete",complete.caller,complete.method,complete.args,false,false);
  21336. }
  21337. }
  21338. progress && info._createListener(/*laya.events.Event.PROGRESS*/"progress",progress.caller,progress.method,progress.args,false,false);
  21339. }
  21340. }
  21341. return this;
  21342. }
  21343. __proto._resInfoLoaded=function(original,complete){
  21344. complete.runWith(Loader.getRes(original));
  21345. }
  21346. /**
  21347. *@private
  21348. */
  21349. __proto._createLoad=function(url,complete,progress,type,constructParams,propertyParams,priority,cache,ignoreCache){
  21350. var _$this=this;
  21351. (priority===void 0)&& (priority=1);
  21352. (cache===void 0)&& (cache=true);
  21353. (ignoreCache===void 0)&& (ignoreCache=false);
  21354. if ((url instanceof Array))return this._loadAssets(url,complete,progress,type,priority,cache);
  21355. var content=Loader.getRes(url);
  21356. if (content !=null){
  21357. Laya.systemTimer.frameOnce(1,null,function(){
  21358. progress && progress.runWith(1);
  21359. complete && complete.runWith(content);
  21360. _$this._loaderCount || _$this.event(/*laya.events.Event.COMPLETE*/"complete");
  21361. });
  21362. }else {
  21363. var info=LoaderManager._resMap[url];
  21364. if (!info){
  21365. info=this._infoPool.length ? this._infoPool.pop():new ResInfo();
  21366. info.url=url;
  21367. info.type=type;
  21368. info.cache=false;
  21369. info.ignoreCache=ignoreCache;
  21370. info.originalUrl=null;
  21371. info.createCache=cache;
  21372. info.createConstructParams=constructParams;
  21373. info.createPropertyParams=propertyParams;
  21374. complete && info.on(/*laya.events.Event.COMPLETE*/"complete",complete.caller,complete.method,complete.args);
  21375. progress && info.on(/*laya.events.Event.PROGRESS*/"progress",progress.caller,progress.method,progress.args);
  21376. LoaderManager._resMap[url]=info;
  21377. priority=priority < this._maxPriority ? priority :this._maxPriority-1;
  21378. this._resInfos[priority].push(info);
  21379. this._statInfo.count++;
  21380. this.event(/*laya.events.Event.PROGRESS*/"progress",this.getProgress());
  21381. this._next();
  21382. }else {
  21383. complete && info._createListener(/*laya.events.Event.COMPLETE*/"complete",complete.caller,complete.method,complete.args,false,false);
  21384. progress && info._createListener(/*laya.events.Event.PROGRESS*/"progress",progress.caller,progress.method,progress.args,false,false);
  21385. }
  21386. }
  21387. return this;
  21388. }
  21389. __proto._next=function(){
  21390. if (this._loaderCount >=this.maxLoader)return;
  21391. for (var i=0;i < this._maxPriority;i++){
  21392. var infos=this._resInfos[i];
  21393. while (infos.length > 0){
  21394. var info=infos.shift();
  21395. if (info)return this._doLoad(info);
  21396. }
  21397. }
  21398. this._loaderCount || this.event(/*laya.events.Event.COMPLETE*/"complete");
  21399. }
  21400. __proto._doLoad=function(resInfo){
  21401. this._loaderCount++;
  21402. var loader=this._loaders.length ? this._loaders.pop():new Loader();
  21403. loader.on(/*laya.events.Event.COMPLETE*/"complete",null,onLoaded);
  21404. loader.on(/*laya.events.Event.PROGRESS*/"progress",null,function(num){
  21405. resInfo.event(/*laya.events.Event.PROGRESS*/"progress",num);
  21406. });
  21407. loader.on(/*laya.events.Event.ERROR*/"error",null,function(msg){
  21408. onLoaded(null);
  21409. });
  21410. var _me=this;
  21411. function onLoaded (data){
  21412. loader.offAll();
  21413. loader._data=null;
  21414. loader._customParse=false;
  21415. _me._loaders.push(loader);
  21416. _me._endLoad(resInfo,(data instanceof Array)? [data] :data);
  21417. _me._loaderCount--;
  21418. _me._next();
  21419. }
  21420. loader._constructParams=resInfo.createConstructParams;
  21421. loader._propertyParams=resInfo.createPropertyParams;
  21422. loader._createCache=resInfo.createCache;
  21423. loader.load(resInfo.url,resInfo.type,resInfo.cache,resInfo.group,resInfo.ignoreCache,resInfo.useWorkerLoader);
  21424. }
  21425. __proto._endLoad=function(resInfo,content){
  21426. var url=resInfo.url;
  21427. if (content==null){
  21428. var errorCount=this._failRes[url] || 0;
  21429. if (errorCount < this.retryNum){
  21430. console.warn("[warn]Retry to load:",url);
  21431. this._failRes[url]=errorCount+1;
  21432. Laya.systemTimer.once(this.retryDelay,this,this._addReTry,[resInfo],false);
  21433. return;
  21434. }else {
  21435. Loader.clearRes(url);
  21436. console.warn("[error]Failed to load:",url);
  21437. this.event(/*laya.events.Event.ERROR*/"error",url);
  21438. }
  21439. }
  21440. if (this._failRes[url])this._failRes[url]=0;
  21441. delete LoaderManager._resMap[url];
  21442. if (resInfo.originalUrl){
  21443. content=Loader.getRes(resInfo.originalUrl);
  21444. }
  21445. resInfo.event(/*laya.events.Event.COMPLETE*/"complete",content);
  21446. resInfo.offAll();
  21447. this._infoPool.push(resInfo);
  21448. this._statInfo.loaded++;
  21449. this.event(/*laya.events.Event.PROGRESS*/"progress",this.getProgress());
  21450. }
  21451. __proto._addReTry=function(resInfo){
  21452. this._resInfos[this._maxPriority-1].push(resInfo);
  21453. this._next();
  21454. }
  21455. /**
  21456. *清理指定资源地址缓存。
  21457. *@param url 资源地址。
  21458. */
  21459. __proto.clearRes=function(url){
  21460. Loader.clearRes(url);
  21461. }
  21462. /**
  21463. *销毁Texture使用的图片资源,保留texture壳,如果下次渲染的时候,发现texture使用的图片资源不存在,则会自动恢复
  21464. *相比clearRes,clearTextureRes只是清理texture里面使用的图片资源,并不销毁texture,再次使用到的时候会自动恢复图片资源
  21465. *而clearRes会彻底销毁texture,导致不能再使用;clearTextureRes能确保立即销毁图片资源,并且不用担心销毁错误,clearRes则采用引用计数方式销毁
  21466. *【注意】如果图片本身在自动合集里面(默认图片小于512*512),内存是不能被销毁的,此图片被大图合集管理器管理
  21467. *@param url 图集地址或者texture地址,比如 Loader.clearTextureRes("res/atlas/comp.atlas");Loader.clearTextureRes("hall/bg.jpg");
  21468. */
  21469. __proto.clearTextureRes=function(url){
  21470. Loader.clearTextureRes(url);
  21471. }
  21472. /**
  21473. *获取指定资源地址的资源。
  21474. *@param url 资源地址。
  21475. *@return 返回资源。
  21476. */
  21477. __proto.getRes=function(url){
  21478. return Loader.getRes(url);
  21479. }
  21480. /**
  21481. *缓存资源。
  21482. *@param url 资源地址。
  21483. *@param data 要缓存的内容。
  21484. */
  21485. __proto.cacheRes=function(url,data){
  21486. Loader.cacheRes(url,data);
  21487. }
  21488. /**
  21489. *设置资源分组。
  21490. *@param url 资源地址。
  21491. *@param group 分组名
  21492. */
  21493. __proto.setGroup=function(url,group){
  21494. Loader.setGroup(url,group);
  21495. }
  21496. /**
  21497. *根据分组清理资源。
  21498. *@param group 分组名
  21499. */
  21500. __proto.clearResByGroup=function(group){
  21501. Loader.clearResByGroup(group);
  21502. }
  21503. /**清理当前未完成的加载,所有未加载的内容全部停止加载。*/
  21504. __proto.clearUnLoaded=function(){
  21505. for (var i=0;i < this._maxPriority;i++){
  21506. var infos=this._resInfos[i];
  21507. for (var j=infos.length-1;j >-1;j--){
  21508. var info=infos[j];
  21509. if (info){
  21510. info.offAll();
  21511. this._infoPool.push(info);
  21512. }
  21513. }
  21514. infos.length=0;
  21515. }
  21516. this._loaderCount=0;
  21517. LoaderManager._resMap={};
  21518. }
  21519. /**
  21520. *根据地址集合清理掉未加载的内容
  21521. *@param urls 资源地址集合
  21522. */
  21523. __proto.cancelLoadByUrls=function(urls){
  21524. if (!urls)return;
  21525. for (var i=0,n=urls.length;i < n;i++){
  21526. this.cancelLoadByUrl(urls[i]);
  21527. }
  21528. }
  21529. /**
  21530. *根据地址清理掉未加载的内容
  21531. *@param url 资源地址
  21532. */
  21533. __proto.cancelLoadByUrl=function(url){
  21534. for (var i=0;i < this._maxPriority;i++){
  21535. var infos=this._resInfos[i];
  21536. for (var j=infos.length-1;j >-1;j--){
  21537. var info=infos[j];
  21538. if (info && info.url===url){
  21539. infos[j]=null;
  21540. info.offAll();
  21541. this._infoPool.push(info);
  21542. }
  21543. }
  21544. }
  21545. if (LoaderManager._resMap[url])delete LoaderManager._resMap[url];
  21546. }
  21547. /**
  21548. *@private
  21549. *加载数组里面的资源。
  21550. *@param arr 简单:["a.png","b.png"],复杂[{url:"a.png",type:Loader.IMAGE,size:100,priority:1,useWorkerLoader:true},{url:"b.json",type:Loader.JSON,size:50,priority:1}]*/
  21551. __proto._loadAssets=function(arr,complete,progress,type,priority,cache,group){
  21552. (priority===void 0)&& (priority=1);
  21553. (cache===void 0)&& (cache=true);
  21554. var itemCount=arr.length;
  21555. var loadedCount=0;
  21556. var totalSize=0;
  21557. var items=[];
  21558. var success=true;
  21559. for (var i=0;i < itemCount;i++){
  21560. var item=arr[i];
  21561. if ((typeof item=='string'))item={url:item,type:type,size:1,priority:priority};
  21562. if (!item.size)item.size=1;
  21563. item.progress=0;
  21564. totalSize+=item.size;
  21565. items.push(item);
  21566. var progressHandler=progress ? Handler.create(null,loadProgress,[item],false):null;
  21567. var completeHandler=(complete || progress)? Handler.create(null,loadComplete,[item]):null;
  21568. this.load(item.url,completeHandler,progressHandler,item.type,item.priority || 1,cache,item.group || group,false,item.useWorkerLoader);
  21569. }
  21570. function loadComplete (item,content){
  21571. loadedCount++;
  21572. item.progress=1;
  21573. if (!content)success=false;
  21574. if (loadedCount===itemCount && complete){
  21575. complete.runWith(success);
  21576. }
  21577. }
  21578. function loadProgress (item,value){
  21579. if (progress !=null){
  21580. item.progress=value;
  21581. var num=0;
  21582. for (var j=0;j < items.length;j++){
  21583. var item1=items[j];
  21584. num+=item1.size *item1.progress;
  21585. };
  21586. var v=num / totalSize;
  21587. progress.runWith(v);
  21588. }
  21589. }
  21590. return this;
  21591. }
  21592. //TODO:TESTs
  21593. __proto.decodeBitmaps=function(urls){
  21594. var i=0,len=urls.length;
  21595. var ctx;
  21596. ctx=Render._context;
  21597. for (i=0;i < len;i++){
  21598. var atlas;
  21599. atlas=Loader.getAtlas(urls[i]);
  21600. if (atlas){
  21601. this._decodeTexture(atlas[0],ctx);
  21602. }else {
  21603. var tex;
  21604. tex=this.getRes(urls[i]);
  21605. if (tex && (tex instanceof laya.resource.Texture )){
  21606. this._decodeTexture(tex,ctx);
  21607. }
  21608. }
  21609. }
  21610. }
  21611. __proto._decodeTexture=function(tex,ctx){
  21612. var bitmap=tex.bitmap;
  21613. if (!tex || !bitmap)return;
  21614. var tImg=bitmap.source || bitmap.image;
  21615. if (!tImg)return;
  21616. if (Laya.__typeof(tImg,Browser.window.HTMLImageElement)){
  21617. ctx.drawImage(tImg,0,0,1,1);
  21618. var info=ctx.getImageData(0,0,1,1);
  21619. }
  21620. }
  21621. LoaderManager.cacheRes=function(url,data){
  21622. Loader.cacheRes(url,data);
  21623. }
  21624. LoaderManager._resMap={};
  21625. __static(LoaderManager,
  21626. ['createMap',function(){return this.createMap={atlas:[null,/*laya.net.Loader.ATLAS*/"atlas"]};}
  21627. ]);
  21628. LoaderManager.__init$=function(){
  21629. //class ResInfo extends laya.events.EventDispatcher
  21630. ResInfo=(function(_super){
  21631. function ResInfo(){
  21632. this.url=null;
  21633. this.type=null;
  21634. this.cache=false;
  21635. this.group=null;
  21636. this.ignoreCache=false;
  21637. this.useWorkerLoader=false;
  21638. this.originalUrl=null;
  21639. this.createCache=false;
  21640. this.createConstructParams=null;
  21641. this.createPropertyParams=null;
  21642. ResInfo.__super.call(this);
  21643. }
  21644. __class(ResInfo,'',_super);
  21645. return ResInfo;
  21646. })(EventDispatcher)
  21647. }
  21648. return LoaderManager;
  21649. })(EventDispatcher)
  21650. /**
  21651. *@private
  21652. *Worker Image加载器
  21653. */
  21654. //class laya.net.WorkerLoader extends laya.events.EventDispatcher
  21655. var WorkerLoader=(function(_super){
  21656. function WorkerLoader(){
  21657. /**使用的Worker对象。*/
  21658. this.worker=null;
  21659. /**@private */
  21660. this._useWorkerLoader=false;
  21661. WorkerLoader.__super.call(this);
  21662. var _$this=this;
  21663. this.worker=new Worker(WorkerLoader.workerPath);
  21664. this.worker.onmessage=function (evt){
  21665. _$this.workerMessage(evt.data);
  21666. }
  21667. }
  21668. __class(WorkerLoader,'laya.net.WorkerLoader',_super);
  21669. var __proto=WorkerLoader.prototype;
  21670. /**
  21671. *@private
  21672. */
  21673. __proto.workerMessage=function(data){
  21674. if (data){
  21675. switch (data.type){
  21676. case "Image":
  21677. this.imageLoaded(data);
  21678. break ;
  21679. case "Disable":
  21680. WorkerLoader.enable=false;
  21681. break ;
  21682. }
  21683. }
  21684. }
  21685. /**
  21686. *@private
  21687. */
  21688. __proto.imageLoaded=function(data){
  21689. if (!data.dataType || data.dataType !="imageBitmap"){
  21690. this.event(data.url,null);
  21691. return;
  21692. };
  21693. var canvas=new HTMLCanvas(true);
  21694. var ctx=canvas.source.getContext("2d");
  21695. switch (data.dataType){
  21696. case "imageBitmap":;
  21697. var imageData=data.imageBitmap;
  21698. canvas.size(imageData.width,imageData.height);
  21699. ctx.drawImage(imageData,0,0);
  21700. break ;
  21701. }
  21702. console.log("load:",data.url);
  21703. canvas._setGPUMemory(0);
  21704. var tex=new Texture2D();
  21705. tex.loadImageSource(canvas.source);
  21706. this.event(data.url,tex);
  21707. }
  21708. /**
  21709. *加载图片
  21710. *@param url 图片地址
  21711. */
  21712. __proto.loadImage=function(url){
  21713. this.worker.postMessage(url);
  21714. }
  21715. /**
  21716. *@private
  21717. *加载图片资源。
  21718. *@param url 资源地址。
  21719. */
  21720. __proto._loadImage=function(url){
  21721. var _this=this;
  21722. if (!this._useWorkerLoader || !WorkerLoader._enable){
  21723. WorkerLoader._preLoadFun.call(_this,url);
  21724. return;
  21725. }
  21726. url=URL.formatURL(url);
  21727. function clear (){
  21728. laya.net.WorkerLoader.I.off(url,_this,onload);
  21729. };
  21730. var onload=function (image){
  21731. clear();
  21732. if (image){
  21733. _this["onLoaded"](image);
  21734. }else {
  21735. WorkerLoader._preLoadFun.call(_this,url);
  21736. }
  21737. };
  21738. laya.net.WorkerLoader.I.on(url,_this,onload);
  21739. laya.net.WorkerLoader.I.loadImage(url);
  21740. }
  21741. /**
  21742. *是否启用。
  21743. */
  21744. __getset(1,WorkerLoader,'enable',function(){
  21745. return WorkerLoader._enable;
  21746. },function(value){
  21747. if (WorkerLoader._enable !=value){
  21748. WorkerLoader._enable=value;
  21749. if (value && WorkerLoader._preLoadFun==null)WorkerLoader._enable=WorkerLoader.__init__();
  21750. }
  21751. });
  21752. WorkerLoader.__init__=function(){
  21753. if (WorkerLoader._preLoadFun !=null)return false;
  21754. if (!Worker)return false;
  21755. WorkerLoader._preLoadFun=Loader["prototype"]["_loadImage"];
  21756. Loader["prototype"]["_loadImage"]=WorkerLoader["prototype"]["_loadImage"];
  21757. if (!WorkerLoader.I)WorkerLoader.I=new WorkerLoader();
  21758. return true;
  21759. }
  21760. WorkerLoader.workerSupported=function(){
  21761. return Worker ? true :false;
  21762. }
  21763. WorkerLoader.enableWorkerLoader=function(){
  21764. if (!WorkerLoader._tryEnabled){
  21765. WorkerLoader.enable=true;
  21766. WorkerLoader._tryEnabled=true;
  21767. }
  21768. }
  21769. WorkerLoader.I=null;
  21770. WorkerLoader.workerPath="libs/workerloader.js";
  21771. WorkerLoader._preLoadFun=null;
  21772. WorkerLoader._enable=false;
  21773. WorkerLoader._tryEnabled=false;
  21774. return WorkerLoader;
  21775. })(EventDispatcher)
  21776. /**
  21777. *<p> <code>HttpRequest</code> 通过封装 HTML <code>XMLHttpRequest</code> 对象提供了对 HTTP 协议的完全的访问,包括做出 POST 和 HEAD 请求以及普通的 GET 请求的能力。 <code>HttpRequest</code> 只提供以异步的形式返回 Web 服务器的响应,并且能够以文本或者二进制的形式返回内容。</p>
  21778. *<p><b>注意:</b>建议每次请求都使用新的 <code>HttpRequest</code> 对象,因为每次调用该对象的send方法时,都会清空之前设置的数据,并重置 HTTP 请求的状态,这会导致之前还未返回响应的请求被重置,从而得不到之前请求的响应结果。</p>
  21779. */
  21780. //class laya.net.HttpRequest extends laya.events.EventDispatcher
  21781. var HttpRequest=(function(_super){
  21782. function HttpRequest(){
  21783. /**@private */
  21784. this._responseType=null;
  21785. /**@private */
  21786. this._data=null;
  21787. /**@private */
  21788. this._url=null;
  21789. HttpRequest.__super.call(this);
  21790. this._http=new Browser.window.XMLHttpRequest();
  21791. }
  21792. __class(HttpRequest,'laya.net.HttpRequest',_super);
  21793. var __proto=HttpRequest.prototype;
  21794. /**
  21795. *发送 HTTP 请求。
  21796. *@param url 请求的地址。大多数浏览器实施了一个同源安全策略,并且要求这个 URL 与包含脚本的文本具有相同的主机名和端口。
  21797. *@param data (default=null)发送的数据。
  21798. *@param method (default="get")用于请求的 HTTP 方法。值包括 "get"、"post"、"head"。
  21799. *@param responseType (default="text")Web 服务器的响应类型,可设置为 "text"、"json"、"xml"、"arraybuffer"。
  21800. *@param headers (default=null)HTTP 请求的头部信息。参数形如key-value数组:key是头部的名称,不应该包括空白、冒号或换行;value是头部的值,不应该包括换行。比如["Content-Type","application/json"]。
  21801. */
  21802. __proto.send=function(url,data,method,responseType,headers){
  21803. (method===void 0)&& (method="get");
  21804. (responseType===void 0)&& (responseType="text");
  21805. this._responseType=responseType;
  21806. this._data=null;
  21807. if(Browser.onQGMiniGame || Browser.onVVMiniGame || Browser.onQQMiniGame){
  21808. url=encodeURI(url);
  21809. }
  21810. this._url=url;
  21811. var _this=this;
  21812. var http=this._http;
  21813. url=URL.getAdptedFilePath(url);
  21814. http.open(method,url,true);
  21815. if (headers){
  21816. for (var i=0;i < headers.length;i++){
  21817. http.setRequestHeader(headers[i++],headers[i]);
  21818. }
  21819. }else if (!Render.isConchApp){
  21820. if (!data || (typeof data=='string'))http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  21821. else http.setRequestHeader("Content-Type","application/json");
  21822. }
  21823. http.responseType=responseType!=="arraybuffer" ? "text" :"arraybuffer";
  21824. http.onerror=function (e){
  21825. _this._onError(e);
  21826. }
  21827. http.onabort=function (e){
  21828. _this._onAbort(e);
  21829. }
  21830. http.onprogress=function (e){
  21831. _this._onProgress(e);
  21832. }
  21833. http.onload=function (e){
  21834. _this._onLoad(e);
  21835. }
  21836. http.send(data);
  21837. }
  21838. /**
  21839. *@private
  21840. *请求进度的侦听处理函数。
  21841. *@param e 事件对象。
  21842. */
  21843. __proto._onProgress=function(e){
  21844. if (e && e.lengthComputable)this.event(/*laya.events.Event.PROGRESS*/"progress",e.loaded / e.total);
  21845. }
  21846. /**
  21847. *@private
  21848. *请求中断的侦听处理函数。
  21849. *@param e 事件对象。
  21850. */
  21851. __proto._onAbort=function(e){
  21852. this.error("Request was aborted by user");
  21853. }
  21854. /**
  21855. *@private
  21856. *请求出错侦的听处理函数。
  21857. *@param e 事件对象。
  21858. */
  21859. __proto._onError=function(e){
  21860. this.error("Request failed Status:"+this._http.status+" text:"+this._http.statusText);
  21861. }
  21862. /**
  21863. *@private
  21864. *请求消息返回的侦听处理函数。
  21865. *@param e 事件对象。
  21866. */
  21867. __proto._onLoad=function(e){
  21868. var http=this._http;
  21869. var status=http.status!==undefined ? http.status :200;
  21870. if (status===200 || status===204 || status===0){
  21871. this.complete();
  21872. }else {
  21873. this.error("["+http.status+"]"+http.statusText+":"+http.responseURL);
  21874. }
  21875. }
  21876. /**
  21877. *@private
  21878. *请求错误的处理函数。
  21879. *@param message 错误信息。
  21880. */
  21881. __proto.error=function(message){
  21882. this.clear();
  21883. console.warn(this.url,message);
  21884. this.event(/*laya.events.Event.ERROR*/"error",message);
  21885. }
  21886. /**
  21887. *@private
  21888. *请求成功完成的处理函数。
  21889. */
  21890. __proto.complete=function(){
  21891. this.clear();
  21892. var flag=true;
  21893. try {
  21894. if (this._responseType==="json"){
  21895. this._data=JSON.parse(this._http.responseText);
  21896. }else if (this._responseType==="xml"){
  21897. this._data=Utils.parseXMLFromString(this._http.responseText);
  21898. }else {
  21899. this._data=this._http.response || this._http.responseText;
  21900. }
  21901. }catch (e){
  21902. flag=false;
  21903. this.error(e.message);
  21904. }
  21905. flag && this.event(/*laya.events.Event.COMPLETE*/"complete",(this._data instanceof Array)? [this._data] :this._data);
  21906. }
  21907. /**
  21908. *@private
  21909. *清除当前请求。
  21910. */
  21911. __proto.clear=function(){
  21912. var http=this._http;
  21913. http.onerror=http.onabort=http.onprogress=http.onload=null;
  21914. }
  21915. /**请求的地址。*/
  21916. __getset(0,__proto,'url',function(){
  21917. return this._url;
  21918. });
  21919. /**
  21920. *本对象所封装的原生 XMLHttpRequest 引用。
  21921. */
  21922. __getset(0,__proto,'http',function(){
  21923. return this._http;
  21924. });
  21925. /**返回的数据。*/
  21926. __getset(0,__proto,'data',function(){
  21927. return this._data;
  21928. });
  21929. return HttpRequest;
  21930. })(EventDispatcher)
  21931. //class laya.webgl.text.CharRender_Canvas extends laya.webgl.text.ICharRender
  21932. var CharRender_Canvas=(function(_super){
  21933. function CharRender_Canvas(maxw,maxh,scalefont,useImageData,showdbg){
  21934. // HTMLCanvasElement;
  21935. this.ctx=null;
  21936. this.lastScaleX=1.0;
  21937. this.lastScaleY=1.0;
  21938. this.needResetScale=false;
  21939. this.maxTexW=0;
  21940. this.maxTexH=0;
  21941. this.scaleFontSize=true;
  21942. this.showDbgInfo=false;
  21943. this.supportImageData=true;
  21944. this.settrans=null;
  21945. CharRender_Canvas.__super.call(this);
  21946. (scalefont===void 0)&& (scalefont=true);
  21947. (useImageData===void 0)&& (useImageData=true);
  21948. (showdbg===void 0)&& (showdbg=false);
  21949. this.maxTexW=maxw;
  21950. this.maxTexH=maxh;
  21951. this.scaleFontSize=scalefont;
  21952. this.supportImageData=useImageData;
  21953. this.showDbgInfo=showdbg;
  21954. if (!CharRender_Canvas.canvas){
  21955. CharRender_Canvas.canvas=window.document.createElement('canvas');
  21956. CharRender_Canvas.canvas.width=1024;
  21957. CharRender_Canvas.canvas.height=512;
  21958. CharRender_Canvas.canvas.style.left="-10000px";
  21959. CharRender_Canvas.canvas.style.position="absolute";
  21960. /*__JS__ */document.body.appendChild(CharRender_Canvas.canvas);;
  21961. this.ctx=CharRender_Canvas.canvas.getContext('2d');
  21962. this.settrans=this.ctx._setTransform || this.ctx.setTransform;
  21963. }
  21964. }
  21965. __class(CharRender_Canvas,'laya.webgl.text.CharRender_Canvas',_super);
  21966. var __proto=CharRender_Canvas.prototype;
  21967. __proto.getWidth=function(font,str){
  21968. if (!this.ctx)return 0;
  21969. if(this.ctx._lastFont!=font){
  21970. this.ctx.font=font;
  21971. this.ctx._lastFont=font;
  21972. }
  21973. return this.ctx.measureText(str).width;
  21974. }
  21975. __proto.scale=function(sx,sy){
  21976. if (!this.supportImageData){
  21977. this.lastScaleX=sx;
  21978. this.lastScaleY=sy;
  21979. return;
  21980. }
  21981. if (this.lastScaleX !=sx || this.lastScaleY !=sy){
  21982. this.settrans.call(this.ctx,sx,0,0,sy,0,0);
  21983. this.lastScaleX=sx;
  21984. this.lastScaleY=sy;
  21985. }
  21986. }
  21987. /**
  21988. *TODO stroke
  21989. *@param char
  21990. *@param font
  21991. *@param cri 修改里面的width。
  21992. *@return
  21993. */
  21994. __proto.getCharBmp=function(char,font,lineWidth,colStr,strokeColStr,cri,margin_left,margin_top,margin_right,margin_bottom,rect){
  21995. if (!this.supportImageData)
  21996. return this.getCharCanvas(char,font,lineWidth,colStr,strokeColStr,cri,margin_left,margin_top,margin_right,margin_bottom);
  21997. var ctx=this.ctx;
  21998. if (ctx.font !=font){
  21999. ctx.font=font;
  22000. ctx._lastFont=font;
  22001. }
  22002. cri.width=ctx.measureText(char).width;
  22003. var w=cri.width *this.lastScaleX;
  22004. var h=cri.height*this.lastScaleY;
  22005. w+=(margin_left+margin_right)*this.lastScaleX;
  22006. h+=(margin_top+margin_bottom)*this.lastScaleY;
  22007. w=Math.ceil(w);
  22008. h=Math.ceil(h);
  22009. w=Math.min(w,laya.webgl.text.CharRender_Canvas.canvas.width);
  22010. h=Math.min(h,laya.webgl.text.CharRender_Canvas.canvas.height);
  22011. var clearW=w+lineWidth *2+1;
  22012. var clearH=h+lineWidth *2+1;
  22013. if (rect){
  22014. clearW=Math.max(clearW,rect[0]+rect[2]+1);
  22015. clearH=Math.max(clearH,rect[1]+rect[3]+1);
  22016. }
  22017. ctx.clearRect(0,0,clearW,clearH);
  22018. ctx.save();
  22019. ctx.textBaseline="top";
  22020. if (lineWidth > 0){
  22021. ctx.strokeStyle=strokeColStr;
  22022. ctx.lineWidth=lineWidth;
  22023. ctx.strokeText(char,margin_left,margin_top);
  22024. }
  22025. ctx.fillStyle=colStr;
  22026. ctx.fillText(char,margin_left,margin_top);
  22027. if (this.showDbgInfo){
  22028. ctx.strokeStyle='#ff0000';
  22029. ctx.strokeRect(0,0,w,h);
  22030. ctx.strokeStyle='#00ff00';
  22031. ctx.strokeRect(margin_left,margin_top,cri.width,cri.height);
  22032. }
  22033. if (rect){
  22034. if (rect[2]==-1)rect[2]=Math.ceil((cri.width+lineWidth*2)*this.lastScaleX);
  22035. };
  22036. var imgdt=rect?(ctx.getImageData(rect[0],rect[1],rect[2],rect[3])):(ctx.getImageData(0,0,w,h));
  22037. ctx.restore();
  22038. cri.bmpWidth=imgdt.width;
  22039. cri.bmpHeight=imgdt.height;
  22040. return imgdt;
  22041. }
  22042. __proto.getCharCanvas=function(char,font,lineWidth,colStr,strokeColStr,cri,margin_left,margin_top,margin_right,margin_bottom){
  22043. var ctx=this.ctx;
  22044. if (ctx.font !=font){
  22045. ctx.font=font;
  22046. ctx._lastFont=font;
  22047. }
  22048. cri.width=ctx.measureText(char).width;
  22049. var w=cri.width *this.lastScaleX;
  22050. var h=cri.height*this.lastScaleY;
  22051. w+=(margin_left+margin_right)*this.lastScaleX;
  22052. h+=((margin_top+margin_bottom)*this.lastScaleY+1);
  22053. w=Math.min(w,this.maxTexW);
  22054. h=Math.min(h,this.maxTexH);
  22055. CharRender_Canvas.canvas.width=Math.min(w+1,this.maxTexW);
  22056. CharRender_Canvas.canvas.height=Math.min(h+1,this.maxTexH);
  22057. ctx.font=font;
  22058. ctx.clearRect(0,0,w+1+lineWidth,h+1+lineWidth);
  22059. this.settrans.call(ctx,1,0,0,1,0,0);
  22060. ctx.save();
  22061. if (this.scaleFontSize){
  22062. ctx.scale(this.lastScaleX,this.lastScaleY);
  22063. }
  22064. ctx.translate(margin_left,margin_top);
  22065. ctx.textAlign="left";
  22066. ctx.textBaseline="top";
  22067. if (lineWidth > 0){
  22068. ctx.strokeStyle=strokeColStr;
  22069. ctx.fillStyle=colStr;
  22070. ctx.lineWidth=lineWidth;
  22071. if (ctx.fillAndStrokeText){
  22072. ctx.fillAndStrokeText(char,0,0);
  22073. }else{
  22074. ctx.strokeText(char,0,0);
  22075. ctx.fillText(char,0,0);
  22076. }
  22077. }else {
  22078. ctx.fillStyle=colStr;
  22079. ctx.fillText(char,0,0);
  22080. }
  22081. if (this.showDbgInfo){
  22082. ctx.strokeStyle='#ff0000';
  22083. ctx.strokeRect(0,0,w,h);
  22084. ctx.strokeStyle='#00ff00';
  22085. ctx.strokeRect(0,0,cri.width,cri.height);
  22086. }
  22087. ctx.restore();
  22088. cri.bmpWidth=CharRender_Canvas.canvas.width;
  22089. cri.bmpHeight=CharRender_Canvas.canvas.height;
  22090. return CharRender_Canvas.canvas;
  22091. }
  22092. __getset(0,__proto,'canvasWidth',function(){
  22093. return CharRender_Canvas.canvas.width;
  22094. },function(w){
  22095. if (CharRender_Canvas.canvas.width==w)
  22096. return;
  22097. CharRender_Canvas.canvas.width=w;
  22098. if (w > 2048){
  22099. console.warn("画文字设置的宽度太大,超过2048了");
  22100. }
  22101. this.settrans.call(this.ctx,1,0,0,1,0,0);
  22102. this.ctx.scale(this.lastScaleX,this.lastScaleY);
  22103. });
  22104. CharRender_Canvas.canvas=null;
  22105. return CharRender_Canvas;
  22106. })(ICharRender)
  22107. //class laya.webgl.submit.SubmitTexture extends laya.webgl.submit.Submit
  22108. var SubmitTexture=(function(_super){
  22109. function SubmitTexture(renderType){
  22110. (renderType===void 0)&& (renderType=10000);
  22111. SubmitTexture.__super.call(this,renderType);
  22112. }
  22113. __class(SubmitTexture,'laya.webgl.submit.SubmitTexture',_super);
  22114. var __proto=SubmitTexture.prototype;
  22115. __proto.clone=function(context,mesh,pos){
  22116. var o=SubmitTexture._poolSize ? SubmitTexture.POOL[--SubmitTexture._poolSize] :new SubmitTexture();
  22117. this._cloneInit(o,context,mesh,pos);
  22118. return o;
  22119. }
  22120. __proto.releaseRender=function(){
  22121. if ((--this._ref)< 1){
  22122. SubmitTexture.POOL[SubmitTexture._poolSize++]=this;
  22123. this.shaderValue.release();
  22124. this._mesh=null;
  22125. this._parent && (this._parent.releaseRender(),this._parent=null);
  22126. }
  22127. }
  22128. __proto.renderSubmit=function(){
  22129. if (this._numEle===0)
  22130. return 1;
  22131. var tex=this.shaderValue.textureHost;
  22132. if(tex){
  22133. var source=tex?tex._getSource():null;
  22134. if (!source)return 1;
  22135. };
  22136. var gl=WebGL.mainContext;
  22137. this._mesh.useMesh(gl);
  22138. var lastSubmit=Submit.preRender;
  22139. var prekey=(Submit.preRender)._key;
  22140. if (this._key.blendShader===0 && (this._key.submitType===prekey.submitType && this._key.blendShader===prekey.blendShader)&& BaseShader.activeShader &&
  22141. (Submit.preRender).clipInfoID==this.clipInfoID &&
  22142. lastSubmit.shaderValue.defines._value===this.shaderValue.defines._value &&
  22143. (this.shaderValue.defines._value & ShaderDefines2D.NOOPTMASK)==0){
  22144. (BaseShader.activeShader).uploadTexture2D(source);
  22145. }
  22146. else{
  22147. if (BlendMode.activeBlendFunction!==this._blendFn){
  22148. WebGLContext.setBlend(gl,true);
  22149. this._blendFn(gl);
  22150. BlendMode.activeBlendFunction=this._blendFn;
  22151. }
  22152. this.shaderValue.texture=source;
  22153. this.shaderValue.upload();
  22154. }
  22155. gl.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,this._numEle,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,this._startIdx);
  22156. Stat.renderBatches++;
  22157. Stat.trianglesFaces+=this._numEle / 3;
  22158. return 1;
  22159. }
  22160. SubmitTexture.create=function(context,mesh,sv){
  22161. var o=SubmitTexture._poolSize ? SubmitTexture.POOL[--SubmitTexture._poolSize] :new SubmitTexture(/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016);
  22162. o._mesh=mesh;
  22163. o._key.clear();
  22164. o._key.submitType=/*laya.webgl.submit.Submit.KEY_DRAWTEXTURE*/2;
  22165. o._ref=1;
  22166. o._startIdx=mesh.indexNum *CONST3D2D.BYTES_PIDX;
  22167. o._numEle=0;
  22168. var blendType=context._nBlendType;
  22169. o._key.blendShader=blendType;
  22170. o._blendFn=context._targets ? BlendMode.targetFns[blendType] :BlendMode.fns[blendType];
  22171. o.shaderValue=sv;
  22172. if (context._colorFiler){
  22173. var ft=context._colorFiler;
  22174. sv.defines.add(ft.type);
  22175. (sv).colorMat=ft._mat;
  22176. (sv).colorAlpha=ft._alpha;
  22177. }
  22178. return o;
  22179. }
  22180. SubmitTexture._poolSize=0;
  22181. SubmitTexture.POOL=[];
  22182. return SubmitTexture;
  22183. })(Submit)
  22184. //class laya.webgl.shader.d2.ShaderDefines2D extends laya.webgl.shader.ShaderDefinesBase
  22185. var ShaderDefines2D=(function(_super){
  22186. function ShaderDefines2D(){
  22187. ShaderDefines2D.__super.call(this,ShaderDefines2D.__name2int,ShaderDefines2D.__int2name,ShaderDefines2D.__int2nameMap);
  22188. }
  22189. __class(ShaderDefines2D,'laya.webgl.shader.d2.ShaderDefines2D',_super);
  22190. ShaderDefines2D.__init__=function(){
  22191. ShaderDefines2D.reg("TEXTURE2D",0x01);
  22192. ShaderDefines2D.reg("PRIMITIVE",0x04);
  22193. ShaderDefines2D.reg("GLOW_FILTER",0x08);
  22194. ShaderDefines2D.reg("BLUR_FILTER",0x10);
  22195. ShaderDefines2D.reg("COLOR_FILTER",0x20);
  22196. ShaderDefines2D.reg("COLOR_ADD",0x40);
  22197. ShaderDefines2D.reg("WORLDMAT",0x80);
  22198. ShaderDefines2D.reg("FILLTEXTURE",0x100);
  22199. ShaderDefines2D.reg("FSHIGHPRECISION",0x400);
  22200. ShaderDefines2D.reg('MVP3D',0x800);
  22201. }
  22202. ShaderDefines2D.reg=function(name,value){
  22203. ShaderDefinesBase._reg(name,value,ShaderDefines2D.__name2int,ShaderDefines2D.__int2name);
  22204. }
  22205. ShaderDefines2D.toText=function(value,int2name,int2nameMap){
  22206. return ShaderDefinesBase._toText(value,int2name,int2nameMap);
  22207. }
  22208. ShaderDefines2D.toInt=function(names){
  22209. return ShaderDefinesBase._toInt(names,ShaderDefines2D.__name2int);
  22210. }
  22211. ShaderDefines2D.TEXTURE2D=0x01;
  22212. ShaderDefines2D.PRIMITIVE=0x04;
  22213. ShaderDefines2D.FILTERGLOW=0x08;
  22214. ShaderDefines2D.FILTERBLUR=0x10;
  22215. ShaderDefines2D.FILTERCOLOR=0x20;
  22216. ShaderDefines2D.COLORADD=0x40;
  22217. ShaderDefines2D.WORLDMAT=0x80;
  22218. ShaderDefines2D.FILLTEXTURE=0x100;
  22219. ShaderDefines2D.SKINMESH=0x200;
  22220. ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION=0x400;
  22221. ShaderDefines2D.MVP3D=0x800;
  22222. ShaderDefines2D.NOOPTMASK=0x08|0x10|0x20|0x100;
  22223. ShaderDefines2D.__name2int={};
  22224. ShaderDefines2D.__int2name=[];
  22225. ShaderDefines2D.__int2nameMap=[];
  22226. return ShaderDefines2D;
  22227. })(ShaderDefinesBase)
  22228. //class laya.webgl.text.CharRender_Native extends laya.webgl.text.ICharRender
  22229. var CharRender_Native=(function(_super){
  22230. function CharRender_Native(){
  22231. this.lastFont='';
  22232. CharRender_Native.__super.call(this);
  22233. }
  22234. __class(CharRender_Native,'laya.webgl.text.CharRender_Native',_super);
  22235. var __proto=CharRender_Native.prototype;
  22236. //TODO:coverage
  22237. __proto.getWidth=function(font,str){
  22238. if (!window.conchTextCanvas)return 0;
  22239. window.conchTextCanvas.font=font;
  22240. this.lastFont=font;
  22241. return window.conchTextCanvas.measureText(str).width;
  22242. }
  22243. __proto.scale=function(sx,sy){}
  22244. //TODO:coverage
  22245. __proto.getCharBmp=function(char,font,lineWidth,colStr,strokeColStr,size,margin_left,margin_top,margin_right,margin_bottom,rect){
  22246. if (!window.conchTextCanvas)return null;
  22247. window.conchTextCanvas.font=font;
  22248. this.lastFont=font;
  22249. var w=size.width=window.conchTextCanvas.measureText(char).width;
  22250. var h=size.height;
  22251. w+=(margin_left+margin_right);
  22252. h+=(margin_top+margin_bottom);
  22253. var c1=ColorUtils.create(strokeColStr);
  22254. var nStrokeColor=c1.numColor;
  22255. var c2=ColorUtils.create(colStr);
  22256. var nTextColor=c2.numColor;
  22257. var textInfo=window.conchTextCanvas.getTextBitmapData(char,nTextColor,lineWidth>2?2:lineWidth,nStrokeColor);
  22258. size.bmpWidth=textInfo.width;
  22259. size.bmpHeight=textInfo.height;
  22260. return textInfo;
  22261. }
  22262. return CharRender_Native;
  22263. })(ICharRender)
  22264. /**
  22265. *<code>Script</code> 类用于创建脚本的父类,该类为抽象类,不允许实例。
  22266. *组件的生命周期
  22267. */
  22268. //class laya.components.Script extends laya.components.Component
  22269. var Script=(function(_super){
  22270. function Script(){
  22271. Script.__super.call(this);;
  22272. }
  22273. __class(Script,'laya.components.Script',_super);
  22274. var __proto=Script.prototype;
  22275. /**
  22276. *@inheritDoc
  22277. */
  22278. __proto._onAwake=function(){
  22279. this.onAwake();
  22280. if (this.onStart!==laya.components.Script.prototype.onStart){
  22281. Laya.startTimer.callLater(this,this.onStart);
  22282. }
  22283. }
  22284. /**
  22285. *@inheritDoc
  22286. */
  22287. __proto._onEnable=function(){
  22288. var proto=laya.components.Script.prototype;
  22289. if (this.onTriggerEnter!==proto.onTriggerEnter){
  22290. this.owner.on(/*laya.events.Event.TRIGGER_ENTER*/"triggerenter",this,this.onTriggerEnter);
  22291. }
  22292. if (this.onTriggerStay!==proto.onTriggerStay){
  22293. this.owner.on(/*laya.events.Event.TRIGGER_STAY*/"triggerstay",this,this.onTriggerStay);
  22294. }
  22295. if (this.onTriggerExit!==proto.onTriggerExit){
  22296. this.owner.on(/*laya.events.Event.TRIGGER_EXIT*/"triggerexit",this,this.onTriggerExit);
  22297. }
  22298. if (this.onMouseDown!==proto.onMouseDown){
  22299. this.owner.on(/*laya.events.Event.MOUSE_DOWN*/"mousedown",this,this.onMouseDown);
  22300. }
  22301. if (this.onMouseUp!==proto.onMouseUp){
  22302. this.owner.on(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onMouseUp);
  22303. }
  22304. if (this.onClick!==proto.onClick){
  22305. this.owner.on(/*laya.events.Event.CLICK*/"click",this,this.onClick);
  22306. }
  22307. if (this.onStageMouseDown!==proto.onStageMouseDown){
  22308. Laya.stage.on(/*laya.events.Event.MOUSE_DOWN*/"mousedown",this,this.onStageMouseDown);
  22309. }
  22310. if (this.onStageMouseUp!==proto.onStageMouseUp){
  22311. Laya.stage.on(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onStageMouseUp);
  22312. }
  22313. if (this.onStageClick!==proto.onStageClick){
  22314. Laya.stage.on(/*laya.events.Event.CLICK*/"click",this,this.onStageClick);
  22315. }
  22316. if (this.onStageMouseMove!==proto.onStageMouseMove){
  22317. Laya.stage.on(/*laya.events.Event.MOUSE_MOVE*/"mousemove",this,this.onStageMouseMove);
  22318. }
  22319. if (this.onDoubleClick!==proto.onDoubleClick){
  22320. this.owner.on(/*laya.events.Event.DOUBLE_CLICK*/"doubleclick",this,this.onDoubleClick);
  22321. }
  22322. if (this.onRightClick!==proto.onRightClick){
  22323. this.owner.on(/*laya.events.Event.RIGHT_CLICK*/"rightclick",this,this.onRightClick);
  22324. }
  22325. if (this.onMouseMove!==proto.onMouseMove){
  22326. this.owner.on(/*laya.events.Event.MOUSE_MOVE*/"mousemove",this,this.onMouseMove);
  22327. }
  22328. if (this.onMouseOver!==proto.onMouseOver){
  22329. this.owner.on(/*laya.events.Event.MOUSE_OVER*/"mouseover",this,this.onMouseOver);
  22330. }
  22331. if (this.onMouseOut!==proto.onMouseOut){
  22332. this.owner.on(/*laya.events.Event.MOUSE_OUT*/"mouseout",this,this.onMouseOut);
  22333. }
  22334. if (this.onKeyDown!==proto.onKeyDown){
  22335. Laya.stage.on(/*laya.events.Event.KEY_DOWN*/"keydown",this,this.onKeyDown);
  22336. }
  22337. if (this.onKeyPress!==proto.onKeyPress){
  22338. Laya.stage.on(/*laya.events.Event.KEY_PRESS*/"keypress",this,this.onKeyPress);
  22339. }
  22340. if (this.onKeyUp!==proto.onKeyUp){
  22341. Laya.stage.on(/*laya.events.Event.KEY_UP*/"keyup",this,this.onKeyUp);
  22342. }
  22343. if (this.onUpdate!==proto.onUpdate){
  22344. Laya.updateTimer.frameLoop(1,this,this.onUpdate);
  22345. }
  22346. if (this.onLateUpdate!==proto.onLateUpdate){
  22347. Laya.lateTimer.frameLoop(1,this,this.onLateUpdate);
  22348. }
  22349. if (this.onPreRender!==proto.onPreRender){
  22350. Laya.lateTimer.frameLoop(1,this,this.onPreRender);
  22351. }
  22352. }
  22353. /**
  22354. *@inheritDoc
  22355. */
  22356. __proto._onDisable=function(){
  22357. this.owner.offAllCaller(this);
  22358. Laya.stage.offAllCaller(this);
  22359. Laya.startTimer.clearAll(this);
  22360. Laya.updateTimer.clearAll(this);
  22361. Laya.lateTimer.clearAll(this);
  22362. }
  22363. /**
  22364. *@inheritDoc
  22365. */
  22366. __proto._isScript=function(){
  22367. return true;
  22368. }
  22369. /**
  22370. *@inheritDoc
  22371. */
  22372. __proto._onDestroy=function(){
  22373. this.onDestroy();
  22374. }
  22375. /**
  22376. *组件被激活后执行,此时所有节点和组件均已创建完毕,次方法只执行一次
  22377. *此方法为虚方法,使用时重写覆盖即可
  22378. */
  22379. __proto.onAwake=function(){}
  22380. /**
  22381. *组件被启用后执行,比如节点被添加到舞台后
  22382. *此方法为虚方法,使用时重写覆盖即可
  22383. */
  22384. __proto.onEnable=function(){}
  22385. /**
  22386. *第一次执行update之前执行,只会执行一次
  22387. *此方法为虚方法,使用时重写覆盖即可
  22388. */
  22389. __proto.onStart=function(){}
  22390. /**
  22391. *开始碰撞时执行
  22392. *此方法为虚方法,使用时重写覆盖即可
  22393. */
  22394. __proto.onTriggerEnter=function(other,self,contact){}
  22395. /**
  22396. *持续碰撞时执行
  22397. *此方法为虚方法,使用时重写覆盖即可
  22398. */
  22399. __proto.onTriggerStay=function(other,self,contact){}
  22400. /**
  22401. *结束碰撞时执行
  22402. *此方法为虚方法,使用时重写覆盖即可
  22403. */
  22404. __proto.onTriggerExit=function(other,self,contact){}
  22405. /**
  22406. *鼠标按下时执行
  22407. *此方法为虚方法,使用时重写覆盖即可
  22408. */
  22409. __proto.onMouseDown=function(e){}
  22410. /**
  22411. *鼠标抬起时执行
  22412. *此方法为虚方法,使用时重写覆盖即可
  22413. */
  22414. __proto.onMouseUp=function(e){}
  22415. /**
  22416. *鼠标点击时执行
  22417. *此方法为虚方法,使用时重写覆盖即可
  22418. */
  22419. __proto.onClick=function(e){}
  22420. /**
  22421. *鼠标在舞台按下时执行
  22422. *此方法为虚方法,使用时重写覆盖即可
  22423. */
  22424. __proto.onStageMouseDown=function(e){}
  22425. /**
  22426. *鼠标在舞台抬起时执行
  22427. *此方法为虚方法,使用时重写覆盖即可
  22428. */
  22429. __proto.onStageMouseUp=function(e){}
  22430. /**
  22431. *鼠标在舞台点击时执行
  22432. *此方法为虚方法,使用时重写覆盖即可
  22433. */
  22434. __proto.onStageClick=function(e){}
  22435. /**
  22436. *鼠标在舞台移动时执行
  22437. *此方法为虚方法,使用时重写覆盖即可
  22438. */
  22439. __proto.onStageMouseMove=function(e){}
  22440. /**
  22441. *鼠标双击时执行
  22442. *此方法为虚方法,使用时重写覆盖即可
  22443. */
  22444. __proto.onDoubleClick=function(e){}
  22445. /**
  22446. *鼠标右键点击时执行
  22447. *此方法为虚方法,使用时重写覆盖即可
  22448. */
  22449. __proto.onRightClick=function(e){}
  22450. /**
  22451. *鼠标移动时执行
  22452. *此方法为虚方法,使用时重写覆盖即可
  22453. */
  22454. __proto.onMouseMove=function(e){}
  22455. /**
  22456. *鼠标经过节点时触发
  22457. *此方法为虚方法,使用时重写覆盖即可
  22458. */
  22459. __proto.onMouseOver=function(e){}
  22460. /**
  22461. *鼠标离开节点时触发
  22462. *此方法为虚方法,使用时重写覆盖即可
  22463. */
  22464. __proto.onMouseOut=function(e){}
  22465. /**
  22466. *键盘按下时执行
  22467. *此方法为虚方法,使用时重写覆盖即可
  22468. */
  22469. __proto.onKeyDown=function(e){}
  22470. /**
  22471. *键盘产生一个字符时执行
  22472. *此方法为虚方法,使用时重写覆盖即可
  22473. */
  22474. __proto.onKeyPress=function(e){}
  22475. /**
  22476. *键盘抬起时执行
  22477. *此方法为虚方法,使用时重写覆盖即可
  22478. */
  22479. __proto.onKeyUp=function(e){}
  22480. /**
  22481. *每帧更新时执行,尽量不要在这里写大循环逻辑或者使用getComponent方法
  22482. *此方法为虚方法,使用时重写覆盖即可
  22483. */
  22484. __proto.onUpdate=function(){}
  22485. /**
  22486. *每帧更新时执行,在update之后执行,尽量不要在这里写大循环逻辑或者使用getComponent方法
  22487. *此方法为虚方法,使用时重写覆盖即可
  22488. */
  22489. __proto.onLateUpdate=function(){}
  22490. /**
  22491. *渲染之前执行
  22492. *此方法为虚方法,使用时重写覆盖即可
  22493. */
  22494. __proto.onPreRender=function(){}
  22495. /**
  22496. *渲染之后执行
  22497. *此方法为虚方法,使用时重写覆盖即可
  22498. */
  22499. __proto.onPostRender=function(){}
  22500. /**
  22501. *组件被禁用时执行,比如从节点从舞台移除后
  22502. *此方法为虚方法,使用时重写覆盖即可
  22503. */
  22504. __proto.onDisable=function(){}
  22505. /**
  22506. *手动调用节点销毁时执行
  22507. *此方法为虚方法,使用时重写覆盖即可
  22508. */
  22509. __proto.onDestroy=function(){}
  22510. /**
  22511. *@inheritDoc
  22512. */
  22513. __getset(0,__proto,'isSingleton',function(){
  22514. return false;
  22515. });
  22516. return Script;
  22517. })(Component)
  22518. /**
  22519. *@private
  22520. *web audio api方式播放声音
  22521. */
  22522. //class laya.media.webaudio.WebAudioSound extends laya.events.EventDispatcher
  22523. var WebAudioSound=(function(_super){
  22524. function WebAudioSound(){
  22525. /**
  22526. *声音URL
  22527. */
  22528. this.url=null;
  22529. /**
  22530. *是否已加载完成
  22531. */
  22532. this.loaded=false;
  22533. /**
  22534. *声音文件数据
  22535. */
  22536. this.data=null;
  22537. /**
  22538. *声音原始文件数据
  22539. */
  22540. this.audioBuffer=null;
  22541. /**
  22542. *待播放的声音列表
  22543. */
  22544. this.__toPlays=null;
  22545. /**
  22546. *@private
  22547. */
  22548. this._disposed=false;
  22549. WebAudioSound.__super.call(this);
  22550. }
  22551. __class(WebAudioSound,'laya.media.webaudio.WebAudioSound',_super);
  22552. var __proto=WebAudioSound.prototype;
  22553. /**
  22554. *加载声音
  22555. *@param url
  22556. *
  22557. */
  22558. __proto.load=function(url){
  22559. var me=this;
  22560. url=URL.formatURL(url);
  22561. this.url=url;
  22562. this.audioBuffer=WebAudioSound._dataCache[url];
  22563. if (this.audioBuffer){
  22564. this._loaded(this.audioBuffer);
  22565. return;
  22566. }
  22567. WebAudioSound.e.on("loaded:"+url,this,this._loaded);
  22568. WebAudioSound.e.on("err:"+url,this,this._err);
  22569. if (WebAudioSound.__loadingSound[url]){
  22570. return;
  22571. }
  22572. WebAudioSound.__loadingSound[url]=true;
  22573. var request=new Browser.window.XMLHttpRequest();
  22574. request.open("GET",url,true);
  22575. request.responseType="arraybuffer";
  22576. request.onload=function (){
  22577. if (me._disposed){
  22578. me._removeLoadEvents();
  22579. return;
  22580. }
  22581. me.data=request.response;
  22582. WebAudioSound.buffs.push({"buffer":me.data,"url":me.url});
  22583. WebAudioSound.decode();
  22584. };
  22585. request.onerror=function (e){
  22586. me._err();
  22587. }
  22588. request.send();
  22589. }
  22590. __proto._err=function(){
  22591. this._removeLoadEvents();
  22592. WebAudioSound.__loadingSound[this.url]=false;
  22593. this.event(/*laya.events.Event.ERROR*/"error");
  22594. }
  22595. __proto._loaded=function(audioBuffer){
  22596. this._removeLoadEvents();
  22597. if (this._disposed){
  22598. return;
  22599. }
  22600. this.audioBuffer=audioBuffer;
  22601. WebAudioSound._dataCache[this.url]=this.audioBuffer;
  22602. this.loaded=true;
  22603. this.event(/*laya.events.Event.COMPLETE*/"complete");
  22604. }
  22605. __proto._removeLoadEvents=function(){
  22606. WebAudioSound.e.off("loaded:"+this.url,this,this._loaded);
  22607. WebAudioSound.e.off("err:"+this.url,this,this._err);
  22608. }
  22609. __proto.__playAfterLoaded=function(){
  22610. if (!this.__toPlays)return;
  22611. var i=0,len=0;
  22612. var toPlays;
  22613. toPlays=this.__toPlays;
  22614. len=toPlays.length;
  22615. var tParams;
  22616. for (i=0;i < len;i++){
  22617. tParams=toPlays[i];
  22618. if (tParams[2] && !(tParams [2]).isStopped){
  22619. this.play(tParams[0],tParams[1],tParams[2]);
  22620. }
  22621. }
  22622. this.__toPlays.length=0;
  22623. }
  22624. /**
  22625. *播放声音
  22626. *@param startTime 起始时间
  22627. *@param loops 循环次数
  22628. *@return
  22629. *
  22630. */
  22631. __proto.play=function(startTime,loops,channel){
  22632. (startTime===void 0)&& (startTime=0);
  22633. (loops===void 0)&& (loops=0);
  22634. channel=channel ? channel :new WebAudioSoundChannel();
  22635. if (!this.audioBuffer){
  22636. if (this.url){
  22637. if (!this.__toPlays)this.__toPlays=[];
  22638. this.__toPlays.push([startTime,loops,channel]);
  22639. this.once(/*laya.events.Event.COMPLETE*/"complete",this,this.__playAfterLoaded);
  22640. this.load(this.url);
  22641. }
  22642. }
  22643. channel.url=this.url;
  22644. channel.loops=loops;
  22645. channel["audioBuffer"]=this.audioBuffer;
  22646. channel.startTime=startTime;
  22647. channel.play();
  22648. SoundManager.addChannel(channel);
  22649. return channel;
  22650. }
  22651. __proto.dispose=function(){
  22652. this._disposed=true;
  22653. delete WebAudioSound._dataCache[this.url];
  22654. delete WebAudioSound.__loadingSound[this.url];
  22655. this.audioBuffer=null;
  22656. this.data=null;
  22657. this.__toPlays=[];
  22658. }
  22659. __getset(0,__proto,'duration',function(){
  22660. if (this.audioBuffer){
  22661. return this.audioBuffer.duration;
  22662. }
  22663. return 0;
  22664. });
  22665. WebAudioSound.decode=function(){
  22666. if (WebAudioSound.buffs.length <=0 || WebAudioSound.isDecoding){
  22667. return;
  22668. }
  22669. WebAudioSound.isDecoding=true;
  22670. WebAudioSound.tInfo=WebAudioSound.buffs.shift();
  22671. WebAudioSound.ctx.decodeAudioData(WebAudioSound.tInfo["buffer"],WebAudioSound._done,WebAudioSound._fail);
  22672. }
  22673. WebAudioSound._done=function(audioBuffer){
  22674. WebAudioSound.e.event("loaded:"+WebAudioSound.tInfo.url,audioBuffer);
  22675. WebAudioSound.isDecoding=false;
  22676. WebAudioSound.decode();
  22677. }
  22678. WebAudioSound._fail=function(){
  22679. WebAudioSound.e.event("err:"+WebAudioSound.tInfo.url,null);
  22680. WebAudioSound.isDecoding=false;
  22681. WebAudioSound.decode();
  22682. }
  22683. WebAudioSound._playEmptySound=function(){
  22684. if (WebAudioSound.ctx==null){
  22685. return;
  22686. };
  22687. var source=WebAudioSound.ctx.createBufferSource();
  22688. source.buffer=WebAudioSound._miniBuffer;
  22689. source.connect(WebAudioSound.ctx.destination);
  22690. source.start(0,0,0);
  22691. }
  22692. WebAudioSound._unlock=function(){
  22693. if (WebAudioSound._unlocked){
  22694. return;
  22695. }
  22696. WebAudioSound._playEmptySound();
  22697. if (WebAudioSound.ctx.state=="running"){
  22698. Browser.document.removeEventListener("mousedown",WebAudioSound._unlock,true);
  22699. Browser.document.removeEventListener("touchend",WebAudioSound._unlock,true);
  22700. Browser.document.removeEventListener("touchstart",WebAudioSound._unlock,true);
  22701. WebAudioSound._unlocked=true;
  22702. }
  22703. }
  22704. WebAudioSound.initWebAudio=function(){
  22705. if (WebAudioSound.ctx.state !="running"){
  22706. WebAudioSound._unlock();
  22707. Browser.document.addEventListener("mousedown",WebAudioSound._unlock,true);
  22708. Browser.document.addEventListener("touchend",WebAudioSound._unlock,true);
  22709. Browser.document.addEventListener("touchstart",WebAudioSound._unlock,true);
  22710. }
  22711. }
  22712. WebAudioSound._dataCache={};
  22713. WebAudioSound.buffs=[];
  22714. WebAudioSound.isDecoding=false;
  22715. WebAudioSound._unlocked=false;
  22716. WebAudioSound.tInfo=null;
  22717. WebAudioSound.__loadingSound={};
  22718. __static(WebAudioSound,
  22719. ['window',function(){return this.window=Browser.window;},'webAudioEnabled',function(){return this.webAudioEnabled=WebAudioSound.window["AudioContext"] || WebAudioSound.window["webkitAudioContext"] || WebAudioSound.window["mozAudioContext"];},'ctx',function(){return this.ctx=WebAudioSound.webAudioEnabled ? new (WebAudioSound.window["AudioContext"] || WebAudioSound.window["webkitAudioContext"] || WebAudioSound.window["mozAudioContext"])():undefined;},'_miniBuffer',function(){return this._miniBuffer=WebAudioSound.ctx.createBuffer(1,1,22050);},'e',function(){return this.e=new EventDispatcher();}
  22720. ]);
  22721. return WebAudioSound;
  22722. })(EventDispatcher)
  22723. /**
  22724. *drawImage,fillRect等会用到的简单的mesh。每次添加必然是一个四边形。
  22725. */
  22726. //class laya.webgl.utils.MeshParticle2D extends laya.webgl.utils.Mesh2D
  22727. var MeshParticle2D=(function(_super){
  22728. //TODO:coverage
  22729. function MeshParticle2D(maxNum){
  22730. MeshParticle2D.__super.call(this,/*CLASS CONST:laya.webgl.utils.MeshParticle2D.const_stride*/116,maxNum*4*116,4);
  22731. this.canReuse=true;
  22732. this.setAttributes(laya.webgl.utils.MeshParticle2D._fixattriInfo);
  22733. this.createQuadIB(maxNum);
  22734. this._quadNum=maxNum;
  22735. }
  22736. __class(MeshParticle2D,'laya.webgl.utils.MeshParticle2D',_super);
  22737. var __proto=MeshParticle2D.prototype;
  22738. __proto.setMaxParticleNum=function(maxNum){
  22739. this._vb._resizeBuffer(maxNum *4 *116,false);
  22740. this.createQuadIB(maxNum);
  22741. }
  22742. //TODO:coverage
  22743. __proto.releaseMesh=function(){;
  22744. this._vb.setByteLength(0);
  22745. this.vertNum=0;
  22746. this.indexNum=0;
  22747. laya.webgl.utils.MeshParticle2D._POOL.push(this);
  22748. }
  22749. //TODO:coverage
  22750. __proto.destroy=function(){
  22751. this._ib.destroy();
  22752. this._vb.destroy();
  22753. this._vb.deleteBuffer();
  22754. }
  22755. MeshParticle2D.getAMesh=function(maxNum){
  22756. if (laya.webgl.utils.MeshParticle2D._POOL.length){
  22757. var ret=laya.webgl.utils.MeshParticle2D._POOL.pop();
  22758. ret.setMaxParticleNum(maxNum);
  22759. return ret;
  22760. }
  22761. return new MeshParticle2D(maxNum);
  22762. }
  22763. MeshParticle2D.const_stride=116;
  22764. MeshParticle2D._POOL=[];
  22765. __static(MeshParticle2D,
  22766. ['_fixattriInfo',function(){return this._fixattriInfo=[
  22767. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,0,
  22768. /*laya.webgl.WebGLContext.FLOAT*/0x1406,3,16,
  22769. /*laya.webgl.WebGLContext.FLOAT*/0x1406,3,28,
  22770. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,40,
  22771. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,56,
  22772. /*laya.webgl.WebGLContext.FLOAT*/0x1406,3,72,
  22773. /*laya.webgl.WebGLContext.FLOAT*/0x1406,2,84,
  22774. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,92,
  22775. /*laya.webgl.WebGLContext.FLOAT*/0x1406,1,108,
  22776. /*laya.webgl.WebGLContext.FLOAT*/0x1406,1,112];}
  22777. ]);
  22778. return MeshParticle2D;
  22779. })(Mesh2D)
  22780. /**
  22781. *<code>Texture</code> 是一个纹理处理类。
  22782. */
  22783. //class laya.resource.Texture extends laya.events.EventDispatcher
  22784. var Texture=(function(_super){
  22785. function Texture(bitmap,uv,sourceWidth,sourceHeight){
  22786. /**@private uv的范围*/
  22787. this.uvrect=[0,0,1,1];
  22788. /**@private */
  22789. this._destroyed=false;
  22790. /**@private */
  22791. //this._bitmap=null;
  22792. /**@private */
  22793. //this._uv=null;
  22794. /**@private */
  22795. this._referenceCount=0;
  22796. /**@private [NATIVE]*/
  22797. //this._nativeObj=null;
  22798. /**@private 唯一ID*/
  22799. this.$_GID=0;
  22800. /**沿 X 轴偏移量。*/
  22801. this.offsetX=0;
  22802. /**沿 Y 轴偏移量。*/
  22803. this.offsetY=0;
  22804. /**@private */
  22805. this._w=0;
  22806. /**@private */
  22807. this._h=0;
  22808. /**原始宽度(包括被裁剪的透明区域)。*/
  22809. this.sourceWidth=0;
  22810. /**原始高度(包括被裁剪的透明区域)。*/
  22811. this.sourceHeight=0;
  22812. /**图片地址*/
  22813. this.url=null;
  22814. /**@private */
  22815. this.scaleRate=1;
  22816. Texture.__super.call(this);
  22817. (sourceWidth===void 0)&& (sourceWidth=0);
  22818. (sourceHeight===void 0)&& (sourceHeight=0);
  22819. this.setTo(bitmap,uv,sourceWidth,sourceHeight);
  22820. }
  22821. __class(Texture,'laya.resource.Texture',_super);
  22822. var __proto=Texture.prototype;
  22823. /**
  22824. *@private
  22825. */
  22826. __proto._addReference=function(){
  22827. this._bitmap && this._bitmap._addReference();
  22828. this._referenceCount++;
  22829. }
  22830. /**
  22831. *@private
  22832. */
  22833. __proto._removeReference=function(){
  22834. this._bitmap && this._bitmap._removeReference();
  22835. this._referenceCount--;
  22836. }
  22837. /**
  22838. *@private
  22839. */
  22840. __proto._getSource=function(cb){
  22841. if (this._destroyed || !this._bitmap)
  22842. return null;
  22843. this.recoverBitmap(cb);
  22844. return this._bitmap.destroyed ? null :this.bitmap._getSource();
  22845. }
  22846. /**
  22847. *@private
  22848. */
  22849. __proto._onLoaded=function(complete,context){
  22850. if (!context){
  22851. }else if (context==this){
  22852. }else if ((context instanceof laya.resource.Texture )){
  22853. var tex=context;
  22854. Texture._create(context,0,0,tex.width,tex.height,0,0,tex.sourceWidth,tex.sourceHeight,this);
  22855. }else {
  22856. this.bitmap=context;
  22857. this.sourceWidth=this._w=context.width;
  22858. this.sourceHeight=this._h=context.height;
  22859. }
  22860. complete && complete.run();
  22861. this.event(/*laya.events.Event.READY*/"ready",this);
  22862. }
  22863. /**
  22864. *获取是否可以使用。
  22865. */
  22866. __proto.getIsReady=function(){
  22867. return this._destroyed ? false :(this._bitmap ? true :false);
  22868. }
  22869. /**
  22870. *设置此对象的位图资源、UV数据信息。
  22871. *@param bitmap 位图资源
  22872. *@param uv UV数据信息
  22873. */
  22874. __proto.setTo=function(bitmap,uv,sourceWidth,sourceHeight){
  22875. (sourceWidth===void 0)&& (sourceWidth=0);
  22876. (sourceHeight===void 0)&& (sourceHeight=0);
  22877. this.bitmap=bitmap;
  22878. this.sourceWidth=sourceWidth;
  22879. this.sourceHeight=sourceHeight;
  22880. if (bitmap){
  22881. this._w=bitmap.width;
  22882. this._h=bitmap.height;
  22883. this.sourceWidth=this.sourceWidth || bitmap.width;
  22884. this.sourceHeight=this.sourceHeight || bitmap.height
  22885. }
  22886. this.uv=uv || Texture.DEF_UV;
  22887. }
  22888. /**
  22889. *加载指定地址的图片。
  22890. *@param url 图片地址。
  22891. *@param complete 加载完成回调
  22892. */
  22893. __proto.load=function(url,complete){
  22894. if (!this._destroyed)
  22895. Laya.loader.load(url,Handler.create(this,this._onLoaded,[complete]),null,"htmlimage",1,false,null,true);
  22896. }
  22897. __proto.getTexturePixels=function(x,y,width,height){
  22898. var st=0,dst=0,i=0;
  22899. var tex2d=this.bitmap;
  22900. var texw=tex2d.width;
  22901. var texh=tex2d.height;
  22902. if (x+width > texw)width-=(x+width)-texw;
  22903. if (y+height > texh)height-=(y+height)-texh;
  22904. if (width <=0 || height <=0)return null;
  22905. var wstride=width *4;
  22906. var pix=null;
  22907. try {
  22908. pix=tex2d.getPixels();
  22909. }catch (e){}
  22910. if (pix){
  22911. if(x==0&&y==0&&width==texw&&height==texh)
  22912. return pix;
  22913. var ret=new Uint8Array(width *height *4);
  22914. wstride=texw *4;
  22915. st=x*4;
  22916. dst=(y+height-1)*wstride+x*4;
  22917. for (i=height-1;i >=0;i--){
  22918. ret.set(dt.slice(dst,dst+width*4),st);
  22919. st+=wstride;
  22920. dst-=wstride;
  22921. }
  22922. return ret;
  22923. };
  22924. var ctx=new Context();
  22925. ctx.size(width,height);
  22926. ctx.asBitmap=true;
  22927. var uv=null;
  22928. if (x !=0 || y !=0 || width !=texw || height !=texh){
  22929. uv=uv.concat();
  22930. var stu=uv[0];
  22931. var stv=uv[1];
  22932. var uvw=uv[2]-stu;
  22933. var uvh=uv[7]-stv;
  22934. var uk=uvw / texw;
  22935. var vk=uvh / texh;
  22936. uv=[
  22937. stu+x *uk,stv+y *vk,
  22938. stu+(x+width)*uk,stv+y *vk,
  22939. stu+(x+width)*uk,stv+(y+height)*vk,
  22940. stu+x *uk,stv+(y+height)*vk,];
  22941. }
  22942. ctx._drawTextureM(this,0,0,width,height,null,1.0,uv);
  22943. ctx._targets.start();
  22944. ctx.flush();
  22945. ctx._targets.end();
  22946. ctx._targets.restore();
  22947. var dt=ctx._targets.getData(0,0,width,height);
  22948. ctx.destroy();
  22949. ret=new Uint8Array(width *height *4);
  22950. st=0;
  22951. dst=(height-1)*wstride;
  22952. for (i=height-1;i >=0;i--){
  22953. ret.set(dt.slice(dst,dst+wstride),st);
  22954. st+=wstride;
  22955. dst-=wstride;
  22956. }
  22957. return ret;
  22958. }
  22959. /**
  22960. *获取Texture上的某个区域的像素点
  22961. *@param x
  22962. *@param y
  22963. *@param width
  22964. *@param height
  22965. *@return 返回像素点集合
  22966. */
  22967. __proto.getPixels=function(x,y,width,height){
  22968. if (Render.isConchApp){
  22969. return this._nativeObj.getImageData(x,y,width,height);
  22970. }else {
  22971. return this.getTexturePixels(x,y,width,height);
  22972. }
  22973. }
  22974. /**
  22975. *通过url强制恢复bitmap。
  22976. */
  22977. __proto.recoverBitmap=function(onok){
  22978. var _$this=this;
  22979. var url=this._bitmap.url;
  22980. if (!this._destroyed && (!this._bitmap || this._bitmap.destroyed)&& url){
  22981. Laya.loader.load(url,Handler.create(this,function(bit){
  22982. _$this.bitmap=bit;
  22983. onok && onok();
  22984. }),null,"htmlimage",1,false,null,true);
  22985. }
  22986. }
  22987. /**
  22988. *强制释放Bitmap,无论是否被引用。
  22989. */
  22990. __proto.disposeBitmap=function(){
  22991. if (!this._destroyed && this._bitmap){
  22992. this._bitmap.destroy();
  22993. }
  22994. }
  22995. /**
  22996. *销毁纹理。
  22997. */
  22998. __proto.destroy=function(force){
  22999. (force===void 0)&& (force=false);
  23000. if (!this._destroyed){
  23001. this._destroyed=true;
  23002. var bit=this._bitmap;
  23003. if (bit){
  23004. bit._removeReference(this._referenceCount);
  23005. if (bit.referenceCount===0||force)
  23006. bit.destroy();
  23007. bit=null;
  23008. }
  23009. if (this.url && this===Laya.loader.getRes(this.url))
  23010. Laya.loader.clearRes(this.url);
  23011. }
  23012. }
  23013. /**实际高度。*/
  23014. __getset(0,__proto,'height',function(){
  23015. if (this._h)
  23016. return this._h;
  23017. if (!this.bitmap)return 0;
  23018. return (this.uv && this.uv!==Texture.DEF_UV)? (this.uv[5]-this.uv[1])*this.bitmap.height :this.bitmap.height;
  23019. },function(value){
  23020. this._h=value;
  23021. this.sourceHeight || (this.sourceHeight=value);
  23022. });
  23023. __getset(0,__proto,'uv',function(){
  23024. return this._uv;
  23025. },function(value){
  23026. this.uvrect[0]=Math.min(value[0],value[2],value[4],value[6]);
  23027. this.uvrect[1]=Math.min(value[1],value[3],value[5],value[7]);
  23028. this.uvrect[2]=Math.max(value[0],value[2],value[4],value[6])-this.uvrect[0];
  23029. this.uvrect[3]=Math.max(value[1],value[3],value[5],value[7])-this.uvrect[1];
  23030. this._uv=value;
  23031. });
  23032. /**实际宽度。*/
  23033. __getset(0,__proto,'width',function(){
  23034. if (this._w)
  23035. return this._w;
  23036. if (!this.bitmap)return 0;
  23037. return (this.uv && this.uv!==Texture.DEF_UV)? (this.uv[2]-this.uv[0])*this.bitmap.width :this.bitmap.width;
  23038. },function(value){
  23039. this._w=value;
  23040. this.sourceWidth || (this.sourceWidth=value);
  23041. });
  23042. /**
  23043. *设置位图。
  23044. *@param 位图。
  23045. */
  23046. /**
  23047. *获取位图。
  23048. *@return 位图。
  23049. */
  23050. __getset(0,__proto,'bitmap',function(){
  23051. return this._bitmap;
  23052. },function(value){
  23053. this._bitmap && this._bitmap._removeReference(this._referenceCount);
  23054. this._bitmap=value;
  23055. value && (value._addReference(this._referenceCount));
  23056. });
  23057. /**
  23058. *获取是否已经销毁。
  23059. *@return 是否已经销毁。
  23060. */
  23061. __getset(0,__proto,'destroyed',function(){
  23062. return this._destroyed;
  23063. });
  23064. Texture.moveUV=function(offsetX,offsetY,uv){
  23065. for (var i=0;i < 8;i+=2){
  23066. uv[i]+=offsetX;
  23067. uv[i+1]+=offsetY;
  23068. }
  23069. return uv;
  23070. }
  23071. Texture.create=function(source,x,y,width,height,offsetX,offsetY,sourceWidth,sourceHeight){
  23072. (offsetX===void 0)&& (offsetX=0);
  23073. (offsetY===void 0)&& (offsetY=0);
  23074. (sourceWidth===void 0)&& (sourceWidth=0);
  23075. (sourceHeight===void 0)&& (sourceHeight=0);
  23076. return Texture._create(source,x,y,width,height,offsetX,offsetY,sourceWidth,sourceHeight);
  23077. }
  23078. Texture._create=function(source,x,y,width,height,offsetX,offsetY,sourceWidth,sourceHeight,outTexture){
  23079. (offsetX===void 0)&& (offsetX=0);
  23080. (offsetY===void 0)&& (offsetY=0);
  23081. (sourceWidth===void 0)&& (sourceWidth=0);
  23082. (sourceHeight===void 0)&& (sourceHeight=0);
  23083. var btex=(source instanceof laya.resource.Texture );
  23084. var uv=btex ? (source).uv :Texture.DEF_UV;
  23085. var bitmap=btex ? (source).bitmap :source;
  23086. if (bitmap.width && (x+width)> bitmap.width)
  23087. width=bitmap.width-x;
  23088. if (bitmap.height && (y+height)> bitmap.height)
  23089. height=bitmap.height-y;
  23090. var tex;
  23091. if (outTexture){
  23092. tex=outTexture;
  23093. tex.setTo(bitmap,null,sourceWidth || width,sourceHeight || height);
  23094. }else {
  23095. tex=new Texture(bitmap,null,sourceWidth || width,sourceHeight || height)
  23096. }
  23097. tex.width=width;
  23098. tex.height=height;
  23099. tex.offsetX=offsetX;
  23100. tex.offsetY=offsetY;
  23101. var dwidth=1 / bitmap.width;
  23102. var dheight=1 / bitmap.height;
  23103. x *=dwidth;
  23104. y *=dheight;
  23105. width *=dwidth;
  23106. height *=dheight;
  23107. var u1=tex.uv[0],v1=tex.uv[1],u2=tex.uv[4],v2=tex.uv[5];
  23108. var inAltasUVWidth=(u2-u1),inAltasUVHeight=(v2-v1);
  23109. var oriUV=Texture.moveUV(uv[0],uv[1],[x,y,x+width,y,x+width,y+height,x,y+height]);
  23110. tex.uv=new Float32Array([
  23111. u1+oriUV[0] *inAltasUVWidth,v1+oriUV[1] *inAltasUVHeight,
  23112. u2-(1-oriUV[2])*inAltasUVWidth,v1+oriUV[3] *inAltasUVHeight,
  23113. u2-(1-oriUV[4])*inAltasUVWidth,v2-(1-oriUV[5])*inAltasUVHeight,
  23114. u1+oriUV[6] *inAltasUVWidth,v2-(1-oriUV[7])*inAltasUVHeight]);
  23115. var bitmapScale=(bitmap).scaleRate;
  23116. if (bitmapScale && bitmapScale !=1){
  23117. tex.sourceWidth /=bitmapScale;
  23118. tex.sourceHeight /=bitmapScale;
  23119. tex.width /=bitmapScale;
  23120. tex.height /=bitmapScale;
  23121. tex.scaleRate=bitmapScale;
  23122. }else {
  23123. tex.scaleRate=1;
  23124. }
  23125. return tex;
  23126. }
  23127. Texture.createFromTexture=function(texture,x,y,width,height){
  23128. var texScaleRate=texture.scaleRate;
  23129. if (texScaleRate !=1){
  23130. x *=texScaleRate;
  23131. y *=texScaleRate;
  23132. width *=texScaleRate;
  23133. height *=texScaleRate;
  23134. };
  23135. var rect=Rectangle.TEMP.setTo(x-texture.offsetX,y-texture.offsetY,width,height);
  23136. var result=rect.intersection(Texture._rect1.setTo(0,0,texture.width,texture.height),Texture._rect2);
  23137. if (result)
  23138. var tex=Texture.create((texture),result.x,result.y,result.width,result.height,result.x-rect.x,result.y-rect.y,width,height);
  23139. else
  23140. return null;
  23141. return tex;
  23142. }
  23143. Texture.DEF_UV=new Float32Array([0,0,1.0,0,1.0,1.0,0,1.0]);
  23144. Texture.NO_UV=new Float32Array([0,0,0,0,0,0,0,0]);
  23145. Texture.INV_UV=new Float32Array([0,1,1.0,1,1.0,0.0,0,0.0]);
  23146. Texture._rect1=new Rectangle();
  23147. Texture._rect2=new Rectangle();
  23148. return Texture;
  23149. })(EventDispatcher)
  23150. //class laya.webgl.shader.d2.skinAnishader.SkinSV extends laya.webgl.shader.d2.value.Value2D
  23151. var SkinSV=(function(_super){
  23152. function SkinSV(type){
  23153. this.texcoord=null;
  23154. this.position=null;
  23155. this.offsetX=300;
  23156. this.offsetY=0;
  23157. SkinSV.__super.call(this,/*laya.webgl.shader.d2.ShaderDefines2D.SKINMESH*/0x200,0);
  23158. var _vlen=8 *CONST3D2D.BYTES_PE;
  23159. this.position=[2,/*laya.webgl.WebGLContext.FLOAT*/0x1406,false,_vlen,0];
  23160. this.texcoord=[2,/*laya.webgl.WebGLContext.FLOAT*/0x1406,false,_vlen,2 *CONST3D2D.BYTES_PE];
  23161. this.color=[4,/*laya.webgl.WebGLContext.FLOAT*/0x1406,false,_vlen,4 *CONST3D2D.BYTES_PE];
  23162. }
  23163. __class(SkinSV,'laya.webgl.shader.d2.skinAnishader.SkinSV',_super);
  23164. return SkinSV;
  23165. })(Value2D)
  23166. /**
  23167. *<code>Sound</code> 类是用来播放控制声音的类。
  23168. *引擎默认有两套声音方案,优先使用WebAudio播放声音,如果WebAudio不可用,则用H5Audio播放,H5Audio在部分机器上有兼容问题(比如不能混音,播放有延迟等)。
  23169. */
  23170. //class laya.media.Sound extends laya.events.EventDispatcher
  23171. var Sound=(function(_super){
  23172. function Sound(){
  23173. Sound.__super.call(this);;
  23174. }
  23175. __class(Sound,'laya.media.Sound',_super);
  23176. var __proto=Sound.prototype;
  23177. /**
  23178. *加载声音。
  23179. *@param url 地址。
  23180. */
  23181. __proto.load=function(url){}
  23182. /**
  23183. *播放声音。
  23184. *@param startTime 开始时间,单位秒
  23185. *@param loops 循环次数,0表示一直循环
  23186. *@return 声道 SoundChannel 对象。
  23187. */
  23188. __proto.play=function(startTime,loops){
  23189. (startTime===void 0)&& (startTime=0);
  23190. (loops===void 0)&& (loops=0);
  23191. return null;
  23192. }
  23193. /**
  23194. *释放声音资源。
  23195. */
  23196. __proto.dispose=function(){}
  23197. /**
  23198. *获取总时间。
  23199. */
  23200. __getset(0,__proto,'duration',function(){
  23201. return 0;
  23202. });
  23203. return Sound;
  23204. })(EventDispatcher)
  23205. /**
  23206. *drawImage,fillRect等会用到的简单的mesh。每次添加必然是一个四边形。
  23207. */
  23208. //class laya.webgl.utils.MeshQuadTexture extends laya.webgl.utils.Mesh2D
  23209. var MeshQuadTexture=(function(_super){
  23210. //private static var _num;
  23211. function MeshQuadTexture(){
  23212. MeshQuadTexture.__super.call(this,/*CLASS CONST:laya.webgl.utils.MeshQuadTexture.const_stride*/24,4,4);
  23213. this.canReuse=true;
  23214. this.setAttributes(laya.webgl.utils.MeshQuadTexture._fixattriInfo);
  23215. if(!laya.webgl.utils.MeshQuadTexture._fixib){
  23216. this.createQuadIB(MeshQuadTexture._maxIB);
  23217. laya.webgl.utils.MeshQuadTexture._fixib=this._ib;
  23218. }else {
  23219. this._ib=laya.webgl.utils.MeshQuadTexture._fixib;
  23220. this._quadNum=MeshQuadTexture._maxIB;
  23221. }
  23222. }
  23223. __class(MeshQuadTexture,'laya.webgl.utils.MeshQuadTexture',_super);
  23224. var __proto=MeshQuadTexture.prototype;
  23225. /**
  23226. *把本对象放到回收池中,以便getMesh能用。
  23227. */
  23228. __proto.releaseMesh=function(){
  23229. this._vb.setByteLength(0);
  23230. this.vertNum=0;
  23231. this.indexNum=0;
  23232. laya.webgl.utils.MeshQuadTexture._POOL.push(this);
  23233. }
  23234. __proto.destroy=function(){
  23235. this._vb.destroy();
  23236. this._vb.deleteBuffer();
  23237. }
  23238. /**
  23239. *
  23240. *@param pos
  23241. *@param uv
  23242. *@param color
  23243. *@param clip ox,oy,xx,xy,yx,yy
  23244. *@param useTex 是否使用贴图。false的话是给fillRect用的
  23245. */
  23246. __proto.addQuad=function(pos,uv,color,useTex){
  23247. var vb=this._vb;
  23248. var vpos=(vb._byteLength >> 2);
  23249. vb.setByteLength((vpos+/*CLASS CONST:laya.webgl.utils.MeshQuadTexture.const_stride*/24)<<2);
  23250. var vbdata=vb._floatArray32 || vb.getFloat32Array();
  23251. var vbu32Arr=vb._uint32Array;
  23252. var cpos=vpos;
  23253. var useTexVal=useTex?0xff:0;
  23254. vbdata[cpos++]=pos[0];vbdata[cpos++]=pos[1];vbdata[cpos++]=uv[0];vbdata[cpos++]=uv[1];vbu32Arr[cpos++]=color;vbu32Arr[cpos++]=useTexVal;
  23255. vbdata[cpos++]=pos[2];vbdata[cpos++]=pos[3];vbdata[cpos++]=uv[2];vbdata[cpos++]=uv[3];vbu32Arr[cpos++]=color;vbu32Arr[cpos++]=useTexVal;
  23256. vbdata[cpos++]=pos[4];vbdata[cpos++]=pos[5];vbdata[cpos++]=uv[4];vbdata[cpos++]=uv[5];vbu32Arr[cpos++]=color;vbu32Arr[cpos++]=useTexVal;
  23257. vbdata[cpos++]=pos[6];vbdata[cpos++]=pos[7];vbdata[cpos++]=uv[6];vbdata[cpos++]=uv[7];vbu32Arr[cpos++]=color;vbu32Arr[cpos++]=useTexVal;
  23258. vb._upload=true;
  23259. }
  23260. MeshQuadTexture.getAMesh=function(mainctx){
  23261. var ret=null;
  23262. if (laya.webgl.utils.MeshQuadTexture._POOL.length){
  23263. ret=laya.webgl.utils.MeshQuadTexture._POOL.pop();
  23264. }else
  23265. ret=new MeshQuadTexture();
  23266. mainctx && ret._vb._resizeBuffer(64 *1024 *24,false);
  23267. return ret;
  23268. }
  23269. MeshQuadTexture.const_stride=24;
  23270. MeshQuadTexture._fixib=null;
  23271. MeshQuadTexture._maxIB=16 *1024;
  23272. MeshQuadTexture._POOL=[];
  23273. __static(MeshQuadTexture,
  23274. ['_fixattriInfo',function(){return this._fixattriInfo=[
  23275. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,0,
  23276. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,16,
  23277. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,20];}
  23278. ]);
  23279. return MeshQuadTexture;
  23280. })(Mesh2D)
  23281. /**
  23282. *与MeshQuadTexture基本相同。不过index不是固定的
  23283. */
  23284. //class laya.webgl.utils.MeshTexture extends laya.webgl.utils.Mesh2D
  23285. var MeshTexture=(function(_super){
  23286. function MeshTexture(){
  23287. MeshTexture.__super.call(this,/*CLASS CONST:laya.webgl.utils.MeshTexture.const_stride*/24,4,4);
  23288. this.canReuse=true;
  23289. this.setAttributes(laya.webgl.utils.MeshTexture._fixattriInfo);
  23290. }
  23291. __class(MeshTexture,'laya.webgl.utils.MeshTexture',_super);
  23292. var __proto=MeshTexture.prototype;
  23293. __proto.addData=function(vertices,uvs,idx,matrix,rgba){
  23294. var vb=this._vb;
  23295. var ib=this._ib;
  23296. var vertsz=vertices.length >>1;
  23297. var startpos=vb.needSize(vertsz *24);
  23298. var f32pos=startpos >> 2;
  23299. var vbdata=vb._floatArray32 || vb.getFloat32Array();
  23300. var vbu32Arr=vb._uint32Array;
  23301. var ci=0;
  23302. var m00=matrix.a;
  23303. var m01=matrix.b;
  23304. var m10=matrix.c;
  23305. var m11=matrix.d;
  23306. var tx=matrix.tx;
  23307. var ty=matrix.ty;
  23308. var i=0;
  23309. for (i=0;i < vertsz;i++){
  23310. var x=vertices[ci],y=vertices[ci+1];
  23311. vbdata[f32pos]=x *m00+y *m10+tx;
  23312. vbdata[f32pos+1]=x *m01+y *m11+ty;
  23313. vbdata[f32pos+2]=uvs[ci];
  23314. vbdata[f32pos+3]=uvs[ci+1];
  23315. vbu32Arr[f32pos+4]=rgba;
  23316. vbu32Arr[f32pos+5]=0xff;
  23317. f32pos+=6;
  23318. ci+=2;
  23319. }
  23320. vb.setNeedUpload();
  23321. var vertN=this.vertNum;
  23322. var sz=idx.length;
  23323. var stib=ib.needSize(idx.byteLength);
  23324. var cidx=ib.getUint16Array();
  23325. var stibid=stib >> 1;
  23326. if (vertN > 0){
  23327. var end=stibid+sz;
  23328. var si=0;
  23329. for (i=stibid;i < end;i++,si++){
  23330. cidx[i]=idx[si]+vertN;
  23331. }
  23332. }else {
  23333. cidx.set(idx,stibid);
  23334. }
  23335. ib.setNeedUpload();
  23336. this.vertNum+=vertsz;
  23337. this.indexNum+=idx.length;
  23338. }
  23339. /**
  23340. *把本对象放到回收池中,以便getMesh能用。
  23341. */
  23342. __proto.releaseMesh=function(){
  23343. this._vb.setByteLength(0);
  23344. this._ib.setByteLength(0);
  23345. this.vertNum=0;
  23346. this.indexNum=0;
  23347. laya.webgl.utils.MeshTexture._POOL.push(this);
  23348. }
  23349. __proto.destroy=function(){
  23350. this._ib.destroy();
  23351. this._vb.destroy();
  23352. this._ib.disposeResource();
  23353. this._vb.deleteBuffer();
  23354. }
  23355. MeshTexture.getAMesh=function(mainctx){
  23356. var ret;
  23357. if (laya.webgl.utils.MeshTexture._POOL.length){
  23358. ret=laya.webgl.utils.MeshTexture._POOL.pop();
  23359. }
  23360. else ret=new MeshTexture();
  23361. mainctx && ret._vb._resizeBuffer(64 *1024 *24,false);
  23362. return ret;
  23363. }
  23364. MeshTexture.const_stride=24;
  23365. MeshTexture._POOL=[];
  23366. __static(MeshTexture,
  23367. ['_fixattriInfo',function(){return this._fixattriInfo=[
  23368. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,0,
  23369. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,16,
  23370. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,20];}
  23371. ]);
  23372. return MeshTexture;
  23373. })(Mesh2D)
  23374. /**
  23375. *@private
  23376. *场景资源加载器
  23377. */
  23378. //class laya.net.SceneLoader extends laya.events.EventDispatcher
  23379. var SceneLoader=(function(_super){
  23380. function SceneLoader(){
  23381. this.totalCount=0;
  23382. this._completeHandler=null;
  23383. this._toLoadList=null;
  23384. this._isLoading=false;
  23385. this._curUrl=null;
  23386. SceneLoader.__super.call(this);
  23387. this._completeHandler=new Handler(this,this.onOneLoadComplete);
  23388. this.reset();
  23389. }
  23390. __class(SceneLoader,'laya.net.SceneLoader',_super);
  23391. var __proto=SceneLoader.prototype;
  23392. __proto.reset=function(){
  23393. this._toLoadList=[];
  23394. this._isLoading=false;
  23395. this.totalCount=0;
  23396. }
  23397. __proto.load=function(url,is3D,ifCheck){
  23398. (is3D===void 0)&& (is3D=false);
  23399. (ifCheck===void 0)&& (ifCheck=true);
  23400. if ((url instanceof Array)){
  23401. var i=0,len=0;
  23402. len=url.length;
  23403. for (i=0;i < len;i++){
  23404. this._addToLoadList(url[i],is3D);
  23405. }
  23406. }else {
  23407. this._addToLoadList(url,is3D);
  23408. }
  23409. if(ifCheck)
  23410. this._checkNext();
  23411. }
  23412. __proto._addToLoadList=function(url,is3D){
  23413. (is3D===void 0)&& (is3D=false);
  23414. if (this._toLoadList.indexOf(url)>=0)return;
  23415. if (Loader.getRes(url))return;
  23416. if (is3D){
  23417. this._toLoadList.push({url:url});
  23418. }else
  23419. this._toLoadList.push(url);
  23420. this.totalCount++;
  23421. }
  23422. __proto._checkNext=function(){
  23423. if (!this._isLoading){
  23424. if (this._toLoadList.length==0){
  23425. this.event(/*laya.events.Event.COMPLETE*/"complete");
  23426. return;
  23427. };
  23428. var tItem;
  23429. tItem=this._toLoadList.pop();
  23430. if ((typeof tItem=='string')){
  23431. this.loadOne(tItem);
  23432. }else{
  23433. this.loadOne(tItem.url,true);
  23434. }
  23435. }
  23436. }
  23437. __proto.loadOne=function(url,is3D){
  23438. (is3D===void 0)&& (is3D=false);
  23439. this._curUrl=url;
  23440. var type=Utils.getFileExtension(this._curUrl);
  23441. if (is3D){
  23442. Laya.loader.create(url,this._completeHandler);
  23443. }else
  23444. if (SceneLoader.LoadableExtensions[type]){
  23445. Laya.loader.load(url,this._completeHandler,null,SceneLoader.LoadableExtensions[type]);
  23446. }else if (url !=AtlasInfoManager.getFileLoadPath(url)|| SceneLoader.No3dLoadTypes[type] || !LoaderManager.createMap[type]){
  23447. Laya.loader.load(url,this._completeHandler);
  23448. }else {
  23449. Laya.loader.create(url,this._completeHandler);
  23450. }
  23451. }
  23452. __proto.onOneLoadComplete=function(){
  23453. this._isLoading=false;
  23454. if (!Loader.getRes(this._curUrl)){
  23455. console.log("Fail to load:",this._curUrl);
  23456. };
  23457. var type=Utils.getFileExtension(this._curUrl);
  23458. if (SceneLoader.LoadableExtensions[type]){
  23459. var dataO;
  23460. dataO=Loader.getRes(this._curUrl);
  23461. if (dataO&&((dataO instanceof laya.components.Prefab ))){
  23462. dataO=dataO.json;
  23463. }
  23464. if (dataO){
  23465. if (dataO.loadList){
  23466. this.load(dataO.loadList,false,false);
  23467. }
  23468. if (dataO.loadList3D){
  23469. this.load(dataO.loadList3D,true,false);
  23470. }
  23471. }
  23472. }
  23473. if (type=="sk"){
  23474. this.load(this._curUrl.replace(".sk",".png"),false,false);
  23475. }
  23476. this.event(/*laya.events.Event.PROGRESS*/"progress",this.getProgress());
  23477. this._checkNext();
  23478. }
  23479. __proto.getProgress=function(){
  23480. return this.loadedCount / this.totalCount;
  23481. }
  23482. __getset(0,__proto,'loadedCount',function(){
  23483. return this.totalCount-this.leftCount;
  23484. });
  23485. __getset(0,__proto,'leftCount',function(){
  23486. if (this._isLoading)return this._toLoadList.length+1;
  23487. return this._toLoadList.length;
  23488. });
  23489. __static(SceneLoader,
  23490. ['LoadableExtensions',function(){return this.LoadableExtensions={"scene":/*laya.net.Loader.JSON*/"json","scene3d":/*laya.net.Loader.JSON*/"json","ani":/*laya.net.Loader.JSON*/"json","ui":/*laya.net.Loader.JSON*/"json","prefab":/*laya.net.Loader.PREFAB*/"prefab"};},'No3dLoadTypes',function(){return this.No3dLoadTypes={"png":true,"jpg":true,"txt":true};}
  23491. ]);
  23492. return SceneLoader;
  23493. })(EventDispatcher)
  23494. //class laya.webgl.shader.d2.value.TextureSV extends laya.webgl.shader.d2.value.Value2D
  23495. var TextureSV=(function(_super){
  23496. function TextureSV(subID){
  23497. this.u_colorMatrix=null;
  23498. this.strength=0;
  23499. this.blurInfo=null;
  23500. this.colorMat=null;
  23501. this.colorAlpha=null;
  23502. (subID===void 0)&& (subID=0);
  23503. TextureSV.__super.call(this,/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,subID);
  23504. this._attribLocation=['posuv',0,'attribColor',1,'attribFlags',2];
  23505. }
  23506. __class(TextureSV,'laya.webgl.shader.d2.value.TextureSV',_super);
  23507. var __proto=TextureSV.prototype;
  23508. // ,'clipDir',3,'clipRect',4];
  23509. __proto.clear=function(){
  23510. this.texture=null;
  23511. this.shader=null;
  23512. this.defines._value=this.subID+(WebGL.shaderHighPrecision? /*laya.webgl.shader.d2.ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION*/0x400:0);
  23513. }
  23514. return TextureSV;
  23515. })(Value2D)
  23516. /**
  23517. *用来画矢量的mesh。顶点格式固定为 x,y,rgba
  23518. */
  23519. //class laya.webgl.utils.MeshVG extends laya.webgl.utils.Mesh2D
  23520. var MeshVG=(function(_super){
  23521. function MeshVG(){
  23522. MeshVG.__super.call(this,/*CLASS CONST:laya.webgl.utils.MeshVG.const_stride*/12,4,4);
  23523. this.canReuse=true;
  23524. this.setAttributes(laya.webgl.utils.MeshVG._fixattriInfo);
  23525. }
  23526. __class(MeshVG,'laya.webgl.utils.MeshVG',_super);
  23527. var __proto=MeshVG.prototype;
  23528. /**
  23529. *往矢量mesh中添加顶点和index。会把rgba和points在mesh中合并。
  23530. *@param points 顶点数组,只包含x,y。[x,y,x,y...]
  23531. *@param rgba rgba颜色
  23532. *@param ib index数组。
  23533. */
  23534. __proto.addVertAndIBToMesh=function(ctx,points,rgba,ib){
  23535. var startpos=this._vb.needSize(points.length / 2 *12);
  23536. var f32pos=startpos >> 2;
  23537. var vbdata=this._vb._floatArray32 || this._vb.getFloat32Array();
  23538. var vbu32Arr=this._vb._uint32Array;
  23539. var ci=0;
  23540. var sz=points.length / 2;
  23541. for (var i=0;i < sz;i++){
  23542. vbdata[f32pos++]=points[ci];vbdata[f32pos++]=points[ci+1];ci+=2;
  23543. vbu32Arr[f32pos++]=rgba;
  23544. }
  23545. this._vb.setNeedUpload();
  23546. this._ib.append(new Uint16Array(ib));
  23547. this._ib.setNeedUpload();
  23548. this.vertNum+=sz;
  23549. this.indexNum+=ib.length;
  23550. }
  23551. /**
  23552. *把本对象放到回收池中,以便getMesh能用。
  23553. */
  23554. __proto.releaseMesh=function(){
  23555. this._vb.setByteLength(0);
  23556. this._ib.setByteLength(0);
  23557. this.vertNum=0;
  23558. this.indexNum=0;
  23559. laya.webgl.utils.MeshVG._POOL.push(this);
  23560. }
  23561. __proto.destroy=function(){
  23562. this._ib.destroy();
  23563. this._vb.destroy();
  23564. this._ib.disposeResource();
  23565. this._vb.deleteBuffer();
  23566. }
  23567. MeshVG.getAMesh=function(mainctx){
  23568. var ret;
  23569. if (laya.webgl.utils.MeshVG._POOL.length){
  23570. ret=laya.webgl.utils.MeshVG._POOL.pop();
  23571. }else
  23572. ret=new MeshVG();
  23573. mainctx && ret._vb._resizeBuffer(64 *1024 *12,false);
  23574. return ret;
  23575. }
  23576. MeshVG.const_stride=12;
  23577. MeshVG._POOL=[];
  23578. __static(MeshVG,
  23579. ['_fixattriInfo',function(){return this._fixattriInfo=[
  23580. /*laya.webgl.WebGLContext.FLOAT*/0x1406,2,0,
  23581. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,8];}
  23582. ]);
  23583. return MeshVG;
  23584. })(Mesh2D)
  23585. /**
  23586. *<p><code>ColorFilter</code> 是颜色滤镜。使用 ColorFilter 类可以将 4 x 5 矩阵转换应用于输入图像上的每个像素的 RGBA 颜色和 Alpha 值,以生成具有一组新的 RGBA 颜色和 Alpha 值的结果。该类允许饱和度更改、色相旋转、亮度转 Alpha 以及各种其他效果。您可以将滤镜应用于任何显示对象(即,从 Sprite 类继承的对象)。</p>
  23587. *<p>注意:对于 RGBA 值,最高有效字节代表红色通道值,其后的有效字节分别代表绿色、蓝色和 Alpha 通道值。</p>
  23588. */
  23589. //class laya.filters.ColorFilter extends laya.filters.Filter
  23590. var ColorFilter=(function(_super){
  23591. function ColorFilter(mat){
  23592. /**@private */
  23593. //this._mat=null;
  23594. /**@private */
  23595. //this._alpha=null;
  23596. /**当前使用的矩阵*/
  23597. //this._matrix=null;
  23598. ColorFilter.__super.call(this);
  23599. if (!mat)mat=this._copyMatrix(ColorFilter.IDENTITY_MATRIX);
  23600. this._mat=new Float32Array(16);
  23601. this._alpha=new Float32Array(4);
  23602. this.setByMatrix(mat);
  23603. }
  23604. __class(ColorFilter,'laya.filters.ColorFilter',_super);
  23605. var __proto=ColorFilter.prototype;
  23606. Laya.imps(__proto,{"laya.filters.IFilter":true})
  23607. /**
  23608. *设置为灰色滤镜
  23609. */
  23610. __proto.gray=function(){
  23611. return this.setByMatrix(ColorFilter.GRAY_MATRIX);
  23612. }
  23613. /**
  23614. *设置为变色滤镜
  23615. *@param red 红色增量,范围:0~255
  23616. *@param green 绿色增量,范围:0~255
  23617. *@param blue 蓝色增量,范围:0~255
  23618. *@param alpha alpha,范围:0~1
  23619. */
  23620. __proto.color=function(red,green,blue,alpha){
  23621. (red===void 0)&& (red=0);
  23622. (green===void 0)&& (green=0);
  23623. (blue===void 0)&& (blue=0);
  23624. (alpha===void 0)&& (alpha=1);
  23625. return this.setByMatrix([1,0,0,0,red,0,1,0,0,green,0,0,1,0,blue,0,0,0,1,alpha]);
  23626. }
  23627. /**
  23628. *设置滤镜色
  23629. *@param color 颜色值
  23630. */
  23631. __proto.setColor=function(color){
  23632. var arr=ColorUtils.create(color).arrColor;
  23633. var mt=[0,0,0,0,256 *arr[0],0,0,0,0,256 *arr[1],0,0,0,0,256 *arr[2],0,0,0,1,0];
  23634. return this.setByMatrix(mt);
  23635. }
  23636. /**
  23637. *设置矩阵数据
  23638. *@param matrix 由 20 个项目(排列成 4 x 5 矩阵)组成的数组
  23639. *@return this
  23640. */
  23641. __proto.setByMatrix=function(matrix){
  23642. if (this._matrix !=matrix)this._copyMatrix(matrix);
  23643. var j=0;
  23644. var z=0;
  23645. for (var i=0;i < 20;i++){
  23646. if (i % 5 !=4){
  23647. this._mat[j++]=matrix[i];
  23648. }else {
  23649. this._alpha[z++]=matrix[i];
  23650. }
  23651. }
  23652. return this;
  23653. }
  23654. /**
  23655. *调整颜色,包括亮度,对比度,饱和度和色调
  23656. *@param brightness 亮度,范围:-100~100
  23657. *@param contrast 对比度,范围:-100~100
  23658. *@param saturation 饱和度,范围:-100~100
  23659. *@param hue 色调,范围:-180~180
  23660. *@return this
  23661. */
  23662. __proto.adjustColor=function(brightness,contrast,saturation,hue){
  23663. this.adjustHue(hue);
  23664. this.adjustContrast(contrast);
  23665. this.adjustBrightness(brightness);
  23666. this.adjustSaturation(saturation);
  23667. return this;
  23668. }
  23669. /**
  23670. *调整亮度
  23671. *@param brightness 亮度,范围:-100~100
  23672. *@return this
  23673. */
  23674. __proto.adjustBrightness=function(brightness){
  23675. brightness=this._clampValue(brightness,100);
  23676. if (brightness==0 || isNaN(brightness))return this;
  23677. return this._multiplyMatrix([1,0,0,0,brightness,0,1,0,0,brightness,0,0,1,0,brightness,0,0,0,1,0,0,0,0,0,1]);
  23678. }
  23679. /**
  23680. *调整对比度
  23681. *@param contrast 对比度,范围:-100~100
  23682. *@return this
  23683. */
  23684. __proto.adjustContrast=function(contrast){
  23685. contrast=this._clampValue(contrast,100);
  23686. if (contrast==0 || isNaN(contrast))return this;
  23687. var x=NaN;
  23688. if (contrast < 0){
  23689. x=127+contrast / 100 *127
  23690. }else {
  23691. x=contrast % 1;
  23692. if (x==0){
  23693. x=ColorFilter.DELTA_INDEX[contrast];
  23694. }else {
  23695. x=ColorFilter.DELTA_INDEX[(contrast << 0)] *(1-x)+ColorFilter.DELTA_INDEX[(contrast << 0)+1] *x;
  23696. }
  23697. x=x *127+127;
  23698. };
  23699. var x1=x / 127;
  23700. var x2=(127-x)*0.5;
  23701. return this._multiplyMatrix([x1,0,0,0,x2,0,x1,0,0,x2,0,0,x1,0,x2,0,0,0,1,0,0,0,0,0,1]);
  23702. }
  23703. /**
  23704. *调整饱和度
  23705. *@param saturation 饱和度,范围:-100~100
  23706. *@return this
  23707. */
  23708. __proto.adjustSaturation=function(saturation){
  23709. saturation=this._clampValue(saturation,100);
  23710. if (saturation==0 || isNaN(saturation))return this;
  23711. var x=1+((saturation > 0)? 3 *saturation / 100 :saturation / 100);
  23712. var dx=1-x;
  23713. var r=0.3086 *dx;
  23714. var g=0.6094 *dx;
  23715. var b=0.0820 *dx;
  23716. return this._multiplyMatrix([r+x,g,b,0,0,r,g+x,b,0,0,r,g,b+x,0,0,0,0,0,1,0,0,0,0,0,1]);
  23717. }
  23718. /**
  23719. *调整色调
  23720. *@param hue 色调,范围:-180~180
  23721. *@return this
  23722. */
  23723. __proto.adjustHue=function(hue){
  23724. hue=this._clampValue(hue,180)/ 180 *Math.PI;
  23725. if (hue==0 || isNaN(hue))return this;
  23726. var cos=Math.cos(hue);
  23727. var sin=Math.sin(hue);
  23728. var r=0.213;
  23729. var g=0.715;
  23730. var b=0.072;
  23731. return this._multiplyMatrix([r+cos *(1-r)+sin *(-r),g+cos *(-g)+sin *(-g),b+cos *(-b)+sin *(1-b),0,0,r+cos *(-r)+sin *(0.143),g+cos *(1-g)+sin *(0.140),b+cos *(-b)+sin *(-0.283),0,0,r+cos *(-r)+sin *(-(1-r)),g+cos *(-g)+sin *(g),b+cos *(1-b)+sin *(b),0,0,0,0,0,1,0,0,0,0,0,1]);
  23732. }
  23733. /**
  23734. *重置成单位矩阵,去除滤镜效果
  23735. */
  23736. __proto.reset=function(){
  23737. return this.setByMatrix(this._copyMatrix(ColorFilter.IDENTITY_MATRIX));
  23738. }
  23739. /**
  23740. *矩阵乘法
  23741. *@param matrix
  23742. *@return this
  23743. */
  23744. __proto._multiplyMatrix=function(matrix){
  23745. var col=[];
  23746. this._matrix=this._fixMatrix(this._matrix);
  23747. for (var i=0;i < 5;i++){
  23748. for (var j=0;j < 5;j++){
  23749. col[j]=this._matrix[j+i *5];
  23750. }
  23751. for (j=0;j < 5;j++){
  23752. var val=0;
  23753. for (var k=0;k < 5;k++){
  23754. val+=matrix[j+k *5] *col[k];
  23755. }
  23756. this._matrix[j+i *5]=val;
  23757. }
  23758. }
  23759. return this.setByMatrix(this._matrix);
  23760. }
  23761. /**
  23762. *规范值的范围
  23763. *@param val 当前值
  23764. *@param limit 值的范围-limit~limit
  23765. */
  23766. __proto._clampValue=function(val,limit){
  23767. return Math.min(limit,Math.max(-limit,val));
  23768. }
  23769. /**
  23770. *规范矩阵,将矩阵调整到正确的大小
  23771. *@param matrix 需要调整的矩阵
  23772. */
  23773. __proto._fixMatrix=function(matrix){
  23774. if (matrix==null)return ColorFilter.IDENTITY_MATRIX;
  23775. if (matrix.length < 25)matrix=matrix.slice(0,matrix.length).concat(ColorFilter.IDENTITY_MATRIX.slice(matrix.length,25));
  23776. else if (matrix.length > 25)matrix=matrix.slice(0,25);
  23777. return matrix;
  23778. }
  23779. /**
  23780. *复制矩阵
  23781. */
  23782. __proto._copyMatrix=function(matrix){
  23783. var len=25;
  23784. if (!this._matrix)this._matrix=[];
  23785. for (var i=0;i < len;i++){
  23786. this._matrix[i]=matrix[i];
  23787. }
  23788. return this._matrix;
  23789. }
  23790. /**@private */
  23791. __getset(0,__proto,'type',function(){
  23792. return 0x20;
  23793. });
  23794. ColorFilter.LENGTH=25;
  23795. __static(ColorFilter,
  23796. ['DELTA_INDEX',function(){return this.DELTA_INDEX=[0,0.01,0.02,0.04,0.05,0.06,0.07,0.08,0.1,0.11,0.12,0.14,0.15,0.16,0.17,0.18,0.20,0.21,0.22,0.24,0.25,0.27,0.28,0.30,0.32,0.34,0.36,0.38,0.40,0.42,0.44,0.46,0.48,0.5,0.53,0.56,0.59,0.62,0.65,0.68,0.71,0.74,0.77,0.80,0.83,0.86,0.89,0.92,0.95,0.98,1.0,1.06,1.12,1.18,1.24,1.30,1.36,1.42,1.48,1.54,1.60,1.66,1.72,1.78,1.84,1.90,1.96,2.0,2.12,2.25,2.37,2.50,2.62,2.75,2.87,3.0,3.2,3.4,3.6,3.8,4.0,4.3,4.7,4.9,5.0,5.5,6.0,6.5,6.8,7.0,7.3,7.5,7.8,8.0,8.4,8.7,9.0,9.4,9.6,9.8,10.0];},'GRAY_MATRIX',function(){return this.GRAY_MATRIX=[0.3086,0.6094,0.082,0,0,0.3086,0.6094,0.082,0,0,0.3086,0.6094,0.082,0,0,0,0,0,1,0];},'IDENTITY_MATRIX',function(){return this.IDENTITY_MATRIX=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1];}
  23797. ]);
  23798. return ColorFilter;
  23799. })(Filter)
  23800. /**
  23801. *文本的样式类
  23802. */
  23803. //class laya.display.css.TextStyle extends laya.display.css.SpriteStyle
  23804. var TextStyle=(function(_super){
  23805. function TextStyle(){
  23806. /**
  23807. *表示使用此文本格式的文本是否为斜体。
  23808. *@default false
  23809. */
  23810. this.italic=false;
  23811. /**
  23812. *<p>表示使用此文本格式的文本段落的水平对齐方式。</p>
  23813. *@default "left"
  23814. */
  23815. //this.align=null;
  23816. /**
  23817. *<p>表示使用此文本格式的文本字段是否自动换行。</p>
  23818. *如果 wordWrap 的值为 true,则该文本字段自动换行;如果值为 false,则该文本字段不自动换行。
  23819. *@default false。
  23820. */
  23821. //this.wordWrap=false;
  23822. /**
  23823. *<p>垂直行间距(以像素为单位)</p>
  23824. */
  23825. //this.leading=NaN;
  23826. /**
  23827. *<p>默认边距信息</p>
  23828. *<p>[左边距,上边距,右边距,下边距](边距以像素为单位)</p>
  23829. */
  23830. //this.padding=null;
  23831. /**
  23832. *文本背景颜色,以字符串表示。
  23833. */
  23834. //this.bgColor=null;
  23835. /**
  23836. *文本边框背景颜色,以字符串表示。
  23837. */
  23838. //this.borderColor=null;
  23839. /**
  23840. *<p>指定文本字段是否是密码文本字段。</p>
  23841. *如果此属性的值为 true,则文本字段被视为密码文本字段,并使用星号而不是实际字符来隐藏输入的字符。如果为 false,则不会将文本字段视为密码文本字段。
  23842. */
  23843. //this.asPassword=false;
  23844. /**
  23845. *<p>描边宽度(以像素为单位)。</p>
  23846. *默认值0,表示不描边。
  23847. *@default 0
  23848. */
  23849. //this.stroke=NaN;
  23850. /**
  23851. *<p>描边颜色,以字符串表示。</p>
  23852. *@default "#000000";
  23853. */
  23854. //this.strokeColor=null;
  23855. /**是否为粗体*/
  23856. //this.bold=false;
  23857. /**是否显示下划线*/
  23858. //this.underline=false;
  23859. /**下划线颜色*/
  23860. //this.underlineColor=null;
  23861. /**当前使用的位置字体。*/
  23862. //this.currBitmapFont=null;
  23863. TextStyle.__super.call(this);
  23864. }
  23865. __class(TextStyle,'laya.display.css.TextStyle',_super);
  23866. var __proto=TextStyle.prototype;
  23867. __proto.reset=function(){
  23868. _super.prototype.reset.call(this);
  23869. this.italic=false;
  23870. this.align="left";
  23871. this.wordWrap=false;
  23872. this.leading=0;
  23873. this.padding=[0,0,0,0];
  23874. this.bgColor=null;
  23875. this.borderColor=null;
  23876. this.asPassword=false;
  23877. this.stroke=0;
  23878. this.strokeColor="#000000";
  23879. this.bold=false;
  23880. this.underline=false;
  23881. this.underlineColor=null;
  23882. this.currBitmapFont=null;
  23883. return this;
  23884. }
  23885. __proto.recover=function(){
  23886. if (this===TextStyle.EMPTY)
  23887. return;
  23888. Pool.recover("TextStyle",this.reset());
  23889. }
  23890. /**@inheritDoc */
  23891. __proto.render=function(sprite,context,x,y){
  23892. (this.bgColor || this.borderColor)&& context.drawRect(x,y,sprite.width,sprite.height,this.bgColor,this.borderColor,1);
  23893. }
  23894. TextStyle.create=function(){
  23895. return Pool.getItemByClass("TextStyle",TextStyle);
  23896. }
  23897. TextStyle.EMPTY=new TextStyle();
  23898. return TextStyle;
  23899. })(SpriteStyle)
  23900. /**
  23901. *cache as normal 模式下的生成的canvas的渲染。
  23902. */
  23903. //class laya.webgl.submit.SubmitCanvas extends laya.webgl.submit.Submit
  23904. var SubmitCanvas=(function(_super){
  23905. function SubmitCanvas(){
  23906. // 用来计算当前的世界矩阵
  23907. //this.canv=null;
  23908. this._matrix=new Matrix();
  23909. this._matrix4=CONST3D2D.defaultMatrix4.concat();
  23910. SubmitCanvas.__super.call(this,/*laya.webgl.submit.Submit.TYPE_2D*/10000);
  23911. this.shaderValue=new Value2D(0,0);
  23912. }
  23913. __class(SubmitCanvas,'laya.webgl.submit.SubmitCanvas',_super);
  23914. var __proto=SubmitCanvas.prototype;
  23915. __proto.renderSubmit=function(){
  23916. var preAlpha=RenderState2D.worldAlpha;
  23917. var preMatrix4=RenderState2D.worldMatrix4;
  23918. var preMatrix=RenderState2D.worldMatrix;
  23919. var preFilters=RenderState2D.worldFilters;
  23920. var preWorldShaderDefines=RenderState2D.worldShaderDefines;
  23921. var v=this.shaderValue;
  23922. var m=this._matrix;
  23923. var m4=this._matrix4;
  23924. var mout=Matrix.TEMP;
  23925. Matrix.mul(m,preMatrix,mout);
  23926. m4[0]=mout.a;
  23927. m4[1]=mout.b;
  23928. m4[4]=mout.c;
  23929. m4[5]=mout.d;
  23930. m4[12]=mout.tx;
  23931. m4[13]=mout.ty;
  23932. RenderState2D.worldMatrix=mout.clone();
  23933. RenderState2D.worldMatrix4=m4;
  23934. RenderState2D.worldAlpha=RenderState2D.worldAlpha *v.alpha;
  23935. if (v.filters && v.filters.length){
  23936. RenderState2D.worldFilters=v.filters;
  23937. RenderState2D.worldShaderDefines=v.defines;
  23938. }
  23939. this.canv['flushsubmit']();
  23940. RenderState2D.worldAlpha=preAlpha;
  23941. RenderState2D.worldMatrix4=preMatrix4;
  23942. RenderState2D.worldMatrix.destroy();
  23943. RenderState2D.worldMatrix=preMatrix;
  23944. RenderState2D.worldFilters=preFilters;
  23945. RenderState2D.worldShaderDefines=preWorldShaderDefines;
  23946. return 1;
  23947. }
  23948. __proto.releaseRender=function(){
  23949. if((--this._ref)<1){
  23950. var cache=SubmitCanvas.POOL;
  23951. this._mesh=null;
  23952. cache[cache._length++]=this;
  23953. }
  23954. }
  23955. //TODO:coverage
  23956. __proto.clone=function(context,mesh,pos){
  23957. return null;
  23958. }
  23959. //TODO:coverage
  23960. __proto.getRenderType=function(){
  23961. return /*laya.webgl.submit.Submit.TYPE_CANVAS*/10003;
  23962. }
  23963. SubmitCanvas.create=function(canvas,alpha,filters){
  23964. var o=(!SubmitCanvas.POOL._length)? (new SubmitCanvas()):SubmitCanvas.POOL[--SubmitCanvas.POOL._length];
  23965. o.canv=canvas;
  23966. o._ref=1;
  23967. o._numEle=0;
  23968. var v=o.shaderValue;
  23969. v.alpha=alpha;
  23970. v.defines.setValue(0);
  23971. filters && filters.length && v.setFilters(filters);
  23972. return o;
  23973. }
  23974. SubmitCanvas.POOL=[];
  23975. SubmitCanvas.__init$=function(){
  23976. ;;{SubmitCanvas.POOL._length=0};
  23977. }
  23978. return SubmitCanvas;
  23979. })(Submit)
  23980. //class laya.webgl.shader.d2.value.PrimitiveSV extends laya.webgl.shader.d2.value.Value2D
  23981. var PrimitiveSV=(function(_super){
  23982. function PrimitiveSV(args){
  23983. PrimitiveSV.__super.call(this,/*laya.webgl.shader.d2.ShaderDefines2D.PRIMITIVE*/0x04,0);
  23984. this._attribLocation=['position',0,'attribColor',1];
  23985. }
  23986. __class(PrimitiveSV,'laya.webgl.shader.d2.value.PrimitiveSV',_super);
  23987. return PrimitiveSV;
  23988. })(Value2D)
  23989. /**
  23990. *模糊滤镜
  23991. */
  23992. //class laya.filters.BlurFilter extends laya.filters.Filter
  23993. var BlurFilter=(function(_super){
  23994. function BlurFilter(strength){
  23995. /**模糊滤镜的强度(值越大,越不清晰 */
  23996. this.strength=NaN;
  23997. this.strength_sig2_2sig2_gauss1=[];
  23998. //给shader用的。避免创建对象
  23999. this.strength_sig2_native=null;
  24000. //给native用的
  24001. this.renderFunc=null;
  24002. BlurFilter.__super.call(this);
  24003. (strength===void 0)&& (strength=4);
  24004. this.strength=strength;
  24005. this._glRender=new BlurFilterGLRender();
  24006. }
  24007. __class(BlurFilter,'laya.filters.BlurFilter',_super);
  24008. var __proto=BlurFilter.prototype;
  24009. __proto.getStrenth_sig2_2sig2_native=function(){
  24010. if (!this.strength_sig2_native){
  24011. this.strength_sig2_native=new Float32Array(4);
  24012. };
  24013. var sigma=this.strength/3.0;
  24014. var sigma2=sigma *sigma;
  24015. this.strength_sig2_native[0]=this.strength;
  24016. this.strength_sig2_native[1]=sigma2;
  24017. this.strength_sig2_native[2]=2.0*sigma2;
  24018. this.strength_sig2_native[3]=1.0 / (2.0 *Math.PI *sigma2);
  24019. return this.strength_sig2_native;
  24020. }
  24021. /**
  24022. *@private
  24023. *当前滤镜的类型
  24024. */
  24025. __getset(0,__proto,'type',function(){
  24026. return 0x10;
  24027. });
  24028. return BlurFilter;
  24029. })(Filter)
  24030. /**
  24031. *发光滤镜(也可以当成阴影滤使用)
  24032. */
  24033. //class laya.filters.GlowFilter extends laya.filters.Filter
  24034. var GlowFilter=(function(_super){
  24035. function GlowFilter(color,blur,offX,offY){
  24036. //给shader用
  24037. this._sv_blurInfo2=[0,0,1,0];
  24038. /**滤镜的颜色*/
  24039. this._color=null;
  24040. this._color_native=null;
  24041. this._blurInof1_native=null;
  24042. this._blurInof2_native=null;
  24043. GlowFilter.__super.call(this);
  24044. this._elements=new Float32Array(9);
  24045. this._sv_blurInfo1=new Array(4);
  24046. (blur===void 0)&& (blur=4);
  24047. (offX===void 0)&& (offX=6);
  24048. (offY===void 0)&& (offY=6);
  24049. this._color=new ColorUtils(color);
  24050. this.blur=Math.min(blur,20);
  24051. this.offX=offX;
  24052. this.offY=offY;
  24053. this._sv_blurInfo1[0]=this._sv_blurInfo1[1]=this.blur;this._sv_blurInfo1[2]=offX;this._sv_blurInfo1[3]=-offY;
  24054. this._glRender=new GlowFilterGLRender();
  24055. }
  24056. __class(GlowFilter,'laya.filters.GlowFilter',_super);
  24057. var __proto=GlowFilter.prototype;
  24058. /**@private */
  24059. __proto.getColor=function(){
  24060. return this._color.arrColor;
  24061. }
  24062. __proto.getColorNative=function(){
  24063. if (!this._color_native){
  24064. this._color_native=new Float32Array(4);
  24065. };
  24066. var color=this.getColor();
  24067. this._color_native[0]=color[0];
  24068. this._color_native[1]=color[1];
  24069. this._color_native[2]=color[2];
  24070. this._color_native[3]=color[3];
  24071. return this._color_native;
  24072. }
  24073. __proto.getBlurInfo1Native=function(){
  24074. if (!this._blurInof1_native){
  24075. this._blurInof1_native=new Float32Array(4);
  24076. }
  24077. this._blurInof1_native[0]=this._blurInof1_native[1]=this.blur;
  24078. this._blurInof1_native[2]=this.offX;
  24079. this._blurInof1_native[3]=this.offY;
  24080. return this._blurInof1_native;
  24081. }
  24082. __proto.getBlurInfo2Native=function(){
  24083. if (!this._blurInof2_native){
  24084. this._blurInof2_native=new Float32Array(4);
  24085. }
  24086. this._blurInof2_native[2]=1;
  24087. return this._blurInof2_native;
  24088. }
  24089. /**
  24090. *@private
  24091. *滤镜类型
  24092. */
  24093. __getset(0,__proto,'type',function(){
  24094. return 0x08;
  24095. });
  24096. /**@private */
  24097. /**@private */
  24098. __getset(0,__proto,'offY',function(){
  24099. return this._elements[6];
  24100. },function(value){
  24101. this._elements[6]=value;
  24102. this._sv_blurInfo1[3]=-value;
  24103. });
  24104. /**@private */
  24105. /**@private */
  24106. __getset(0,__proto,'offX',function(){
  24107. return this._elements[5];
  24108. },function(value){
  24109. this._elements[5]=value;
  24110. this._sv_blurInfo1[2]=value;
  24111. });
  24112. /**@private */
  24113. /**@private */
  24114. __getset(0,__proto,'blur',function(){
  24115. return this._elements[4];
  24116. },function(value){
  24117. this._elements[4]=value;
  24118. this._sv_blurInfo1[0]=this._sv_blurInfo1[1]=value;
  24119. });
  24120. return GlowFilter;
  24121. })(Filter)
  24122. /**
  24123. *@private
  24124. *audio标签播放声音的音轨控制
  24125. */
  24126. //class laya.media.h5audio.AudioSoundChannel extends laya.media.SoundChannel
  24127. var AudioSoundChannel=(function(_super){
  24128. function AudioSoundChannel(audio){
  24129. /**
  24130. *播放用的audio标签
  24131. */
  24132. this._audio=null;
  24133. this._onEnd=null;
  24134. this._resumePlay=null;
  24135. AudioSoundChannel.__super.call(this);
  24136. this._onEnd=Utils.bind(this.__onEnd,this);
  24137. this._resumePlay=Utils.bind(this.__resumePlay,this);
  24138. audio.addEventListener("ended",this._onEnd);
  24139. this._audio=audio;
  24140. }
  24141. __class(AudioSoundChannel,'laya.media.h5audio.AudioSoundChannel',_super);
  24142. var __proto=AudioSoundChannel.prototype;
  24143. __proto.__onEnd=function(){
  24144. if (this.loops==1){
  24145. if (this.completeHandler){
  24146. Laya.systemTimer.once(10,this,this.__runComplete,[this.completeHandler],false);
  24147. this.completeHandler=null;
  24148. }
  24149. this.stop();
  24150. this.event(/*laya.events.Event.COMPLETE*/"complete");
  24151. return;
  24152. }
  24153. if (this.loops > 0){
  24154. this.loops--;
  24155. }
  24156. this.startTime=0;
  24157. this.play();
  24158. }
  24159. __proto.__resumePlay=function(){
  24160. if (this._audio)this._audio.removeEventListener("canplay",this._resumePlay);
  24161. if (this.isStopped)return;
  24162. try {
  24163. this._audio.currentTime=this.startTime;
  24164. Browser.container.appendChild(this._audio);
  24165. this._audio.play();
  24166. }catch (e){
  24167. this.event(/*laya.events.Event.ERROR*/"error");
  24168. }
  24169. }
  24170. /**
  24171. *播放
  24172. */
  24173. __proto.play=function(){
  24174. this.isStopped=false;
  24175. try {
  24176. this._audio.playbackRate=SoundManager.playbackRate;
  24177. this._audio.currentTime=this.startTime;
  24178. }catch (e){
  24179. this._audio.addEventListener("canplay",this._resumePlay);
  24180. return;
  24181. }
  24182. SoundManager.addChannel(this);
  24183. Browser.container.appendChild(this._audio);
  24184. if("play" in this._audio)
  24185. this._audio.play();
  24186. }
  24187. /**
  24188. *停止播放
  24189. *
  24190. */
  24191. __proto.stop=function(){
  24192. _super.prototype.stop.call(this);
  24193. this.isStopped=true;
  24194. SoundManager.removeChannel(this);
  24195. this.completeHandler=null;
  24196. if (!this._audio)
  24197. return;
  24198. if ("pause" in this._audio)
  24199. if (Render.isConchApp){
  24200. this._audio.stop();
  24201. }
  24202. this._audio.pause();
  24203. this._audio.removeEventListener("ended",this._onEnd);
  24204. this._audio.removeEventListener("canplay",this._resumePlay);
  24205. if (!Browser.onIE){
  24206. if (this._audio!=AudioSound._musicAudio){
  24207. Pool.recover("audio:"+this.url,this._audio);
  24208. }
  24209. }
  24210. Browser.removeElement(this._audio);
  24211. this._audio=null;
  24212. }
  24213. __proto.pause=function(){
  24214. this.isStopped=true;
  24215. SoundManager.removeChannel(this);
  24216. if("pause" in this._audio)
  24217. this._audio.pause();
  24218. }
  24219. __proto.resume=function(){
  24220. if (!this._audio)
  24221. return;
  24222. this.isStopped=false;
  24223. SoundManager.addChannel(this);
  24224. if("play" in this._audio)
  24225. this._audio.play();
  24226. }
  24227. /**
  24228. *当前播放到的位置
  24229. *@return
  24230. *
  24231. */
  24232. __getset(0,__proto,'position',function(){
  24233. if (!this._audio)
  24234. return 0;
  24235. return this._audio.currentTime;
  24236. });
  24237. /**
  24238. *获取总时间。
  24239. */
  24240. __getset(0,__proto,'duration',function(){
  24241. if (!this._audio)
  24242. return 0;
  24243. return this._audio.duration;
  24244. });
  24245. /**
  24246. *设置音量
  24247. *@param v
  24248. *
  24249. */
  24250. /**
  24251. *获取音量
  24252. *@return
  24253. *
  24254. */
  24255. __getset(0,__proto,'volume',function(){
  24256. if (!this._audio)return 1;
  24257. return this._audio.volume;
  24258. },function(v){
  24259. if (!this._audio)return;
  24260. this._audio.volume=v;
  24261. });
  24262. return AudioSoundChannel;
  24263. })(SoundChannel)
  24264. /**
  24265. *<p> <code>Sprite</code> 是基本的显示图形的显示列表节点。 <code>Sprite</code> 默认没有宽高,默认不接受鼠标事件。通过 <code>graphics</code> 可以绘制图片或者矢量图,支持旋转,缩放,位移等操作。<code>Sprite</code>同时也是容器类,可用来添加多个子节点。</p>
  24266. *<p>注意: <code>Sprite</code> 默认没有宽高,可以通过<code>getBounds</code>函数获取;也可手动设置宽高;还可以设置<code>autoSize=true</code>,然后再获取宽高。<code>Sprite</code>的宽高一般用于进行碰撞检测和排版,并不影响显示图像大小,如果需要更改显示图像大小,请使用 <code>scaleX</code> , <code>scaleY</code> , <code>scale</code>。</p>
  24267. *<p> <code>Sprite</code> 默认不接受鼠标事件,即<code>mouseEnabled=false</code>,但是只要对其监听任意鼠标事件,会自动打开自己以及所有父对象的<code>mouseEnabled=true</code>。所以一般也无需手动设置<code>mouseEnabled</code>。</p>
  24268. *<p>LayaAir引擎API设计精简巧妙。核心显示类只有一个<code>Sprite</code>。<code>Sprite</code>针对不同的情况做了渲染优化,所以保证一个类实现丰富功能的同时,又达到高性能。</p>
  24269. *
  24270. *@example <caption>创建了一个 <code>Sprite</code> 实例。</caption>
  24271. *package
  24272. *{
  24273. *import laya.display.Sprite;
  24274. *import laya.events.Event;
  24275. *
  24276. *public class Sprite_Example
  24277. *{
  24278. *private var sprite:Sprite;
  24279. *private var shape:Sprite
  24280. *public function Sprite_Example()
  24281. *{
  24282. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  24283. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  24284. *onInit();
  24285. *}
  24286. *private function onInit():void
  24287. *{
  24288. *sprite=new Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24289. *sprite.loadImage("resource/ui/bg.png");//加载并显示图片。
  24290. *sprite.x=200;//设置 sprite 对象相对于父容器的水平方向坐标值。
  24291. *sprite.y=200;//设置 sprite 对象相对于父容器的垂直方向坐标值。
  24292. *sprite.pivotX=0;//设置 sprite 对象的水平方法轴心点坐标。
  24293. *sprite.pivotY=0;//设置 sprite 对象的垂直方法轴心点坐标。
  24294. *Laya.stage.addChild(sprite);//将此 sprite 对象添加到显示列表。
  24295. *sprite.on(Event.CLICK,this,onClickSprite);//给 sprite 对象添加点击事件侦听。
  24296. *shape=new Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24297. *shape.graphics.drawRect(0,0,100,100,"#ccff00","#ff0000",2);//绘制一个有边框的填充矩形。
  24298. *shape.x=400;//设置 shape 对象相对于父容器的水平方向坐标值。
  24299. *shape.y=200;//设置 shape 对象相对于父容器的垂直方向坐标值。
  24300. *shape.width=100;//设置 shape 对象的宽度。
  24301. *shape.height=100;//设置 shape 对象的高度。
  24302. *shape.pivotX=50;//设置 shape 对象的水平方法轴心点坐标。
  24303. *shape.pivotY=50;//设置 shape 对象的垂直方法轴心点坐标。
  24304. *Laya.stage.addChild(shape);//将此 shape 对象添加到显示列表。
  24305. *shape.on(Event.CLICK,this,onClickShape);//给 shape 对象添加点击事件侦听。
  24306. *}
  24307. *private function onClickSprite():void
  24308. *{
  24309. *trace("点击 sprite 对象。");
  24310. *sprite.rotation+=5;//旋转 sprite 对象。
  24311. *}
  24312. *private function onClickShape():void
  24313. *{
  24314. *trace("点击 shape 对象。");
  24315. *shape.rotation+=5;//旋转 shape 对象。
  24316. *}
  24317. *}
  24318. *}
  24319. *
  24320. *@example
  24321. *var sprite;
  24322. *var shape;
  24323. *Sprite_Example();
  24324. *function Sprite_Example()
  24325. *{
  24326. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  24327. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  24328. *onInit();
  24329. *}
  24330. *function onInit()
  24331. *{
  24332. *sprite=new laya.display.Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24333. *sprite.loadImage("resource/ui/bg.png");//加载并显示图片。
  24334. *sprite.x=200;//设置 sprite 对象相对于父容器的水平方向坐标值。
  24335. *sprite.y=200;//设置 sprite 对象相对于父容器的垂直方向坐标值。
  24336. *sprite.pivotX=0;//设置 sprite 对象的水平方法轴心点坐标。
  24337. *sprite.pivotY=0;//设置 sprite 对象的垂直方法轴心点坐标。
  24338. *Laya.stage.addChild(sprite);//将此 sprite 对象添加到显示列表。
  24339. *sprite.on(Event.CLICK,this,onClickSprite);//给 sprite 对象添加点击事件侦听。
  24340. *shape=new laya.display.Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24341. *shape.graphics.drawRect(0,0,100,100,"#ccff00","#ff0000",2);//绘制一个有边框的填充矩形。
  24342. *shape.x=400;//设置 shape 对象相对于父容器的水平方向坐标值。
  24343. *shape.y=200;//设置 shape 对象相对于父容器的垂直方向坐标值。
  24344. *shape.width=100;//设置 shape 对象的宽度。
  24345. *shape.height=100;//设置 shape 对象的高度。
  24346. *shape.pivotX=50;//设置 shape 对象的水平方法轴心点坐标。
  24347. *shape.pivotY=50;//设置 shape 对象的垂直方法轴心点坐标。
  24348. *Laya.stage.addChild(shape);//将此 shape 对象添加到显示列表。
  24349. *shape.on(laya.events.Event.CLICK,this,onClickShape);//给 shape 对象添加点击事件侦听。
  24350. *}
  24351. *function onClickSprite()
  24352. *{
  24353. *console.log("点击 sprite 对象。");
  24354. *sprite.rotation+=5;//旋转 sprite 对象。
  24355. *}
  24356. *function onClickShape()
  24357. *{
  24358. *console.log("点击 shape 对象。");
  24359. *shape.rotation+=5;//旋转 shape 对象。
  24360. *}
  24361. *
  24362. *@example
  24363. *import Sprite=laya.display.Sprite;
  24364. *class Sprite_Example {
  24365. *private sprite:Sprite;
  24366. *private shape:Sprite
  24367. *public Sprite_Example(){
  24368. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  24369. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  24370. *this.onInit();
  24371. *}
  24372. *private onInit():void {
  24373. *this.sprite=new Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24374. *this.sprite.loadImage("resource/ui/bg.png");//加载并显示图片。
  24375. *this.sprite.x=200;//设置 sprite 对象相对于父容器的水平方向坐标值。
  24376. *this.sprite.y=200;//设置 sprite 对象相对于父容器的垂直方向坐标值。
  24377. *this.sprite.pivotX=0;//设置 sprite 对象的水平方法轴心点坐标。
  24378. *this.sprite.pivotY=0;//设置 sprite 对象的垂直方法轴心点坐标。
  24379. *Laya.stage.addChild(this.sprite);//将此 sprite 对象添加到显示列表。
  24380. *this.sprite.on(laya.events.Event.CLICK,this,this.onClickSprite);//给 sprite 对象添加点击事件侦听。
  24381. *this.shape=new Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24382. *this.shape.graphics.drawRect(0,0,100,100,"#ccff00","#ff0000",2);//绘制一个有边框的填充矩形。
  24383. *this.shape.x=400;//设置 shape 对象相对于父容器的水平方向坐标值。
  24384. *this.shape.y=200;//设置 shape 对象相对于父容器的垂直方向坐标值。
  24385. *this.shape.width=100;//设置 shape 对象的宽度。
  24386. *this.shape.height=100;//设置 shape 对象的高度。
  24387. *this.shape.pivotX=50;//设置 shape 对象的水平方法轴心点坐标。
  24388. *this.shape.pivotY=50;//设置 shape 对象的垂直方法轴心点坐标。
  24389. *Laya.stage.addChild(this.shape);//将此 shape 对象添加到显示列表。
  24390. *this.shape.on(laya.events.Event.CLICK,this,this.onClickShape);//给 shape 对象添加点击事件侦听。
  24391. *}
  24392. *private onClickSprite():void {
  24393. *console.log("点击 sprite 对象。");
  24394. *this.sprite.rotation+=5;//旋转 sprite 对象。
  24395. *}
  24396. *private onClickShape():void {
  24397. *console.log("点击 shape 对象。");
  24398. *this.shape.rotation+=5;//旋转 shape 对象。
  24399. *}
  24400. *}
  24401. */
  24402. //class laya.display.Sprite extends laya.display.Node
  24403. var Sprite=(function(_super){
  24404. function Sprite(){
  24405. /**@private */
  24406. this._x=0;
  24407. /**@private */
  24408. this._y=0;
  24409. /**@private */
  24410. this._width=0;
  24411. /**@private */
  24412. this._height=0;
  24413. /**@private */
  24414. this._visible=true;
  24415. /**@private 鼠标状态,0:auto,1:mouseEnabled=false,2:mouseEnabled=true。*/
  24416. this._mouseState=0;
  24417. /**@private z排序,数值越大越靠前。*/
  24418. this._zOrder=0;
  24419. /**@private */
  24420. this._renderType=0;
  24421. /**@private */
  24422. this._transform=null;
  24423. /**@private */
  24424. this._tfChanged=false;
  24425. /**@private */
  24426. this._texture=null;
  24427. /**@private */
  24428. this._boundStyle=null;
  24429. /**@private */
  24430. this._graphics=null;
  24431. /**
  24432. *<p>鼠标事件与此对象的碰撞检测是否可穿透。碰撞检测发生在鼠标事件的捕获阶段,此阶段引擎会从stage开始递归检测stage及其子对象,直到找到命中的目标对象或者未命中任何对象。</p>
  24433. *<p>穿透表示鼠标事件发生的位置处于本对象绘图区域内时,才算命中,而与对象宽高和值为Rectangle对象的hitArea属性无关。如果sprite.hitArea值是HitArea对象,表示显式声明了此对象的鼠标事件响应区域,而忽略对象的宽高、mouseThrough属性。</p>
  24434. *<p>影响对象鼠标事件响应区域的属性为:width、height、hitArea,优先级顺序为:hitArea(type:HitArea)>hitArea(type:Rectangle)>width/height。</p>
  24435. *@default false 不可穿透,此对象的鼠标响应区域由width、height、hitArea属性决定。</p>
  24436. */
  24437. this.mouseThrough=false;
  24438. /**
  24439. *<p>指定是否自动计算宽高数据。默认值为 false 。</p>
  24440. *<p>Sprite宽高默认为0,并且不会随着绘制内容的变化而变化,如果想根据绘制内容获取宽高,可以设置本属性为true,或者通过getBounds方法获取。设置为true,对性能有一定影响。</p>
  24441. */
  24442. this.autoSize=false;
  24443. /**
  24444. *<p>指定鼠标事件检测是优先检测自身,还是优先检测其子对象。鼠标事件检测发生在鼠标事件的捕获阶段,此阶段引擎会从stage开始递归检测stage及其子对象,直到找到命中的目标对象或者未命中任何对象。</p>
  24445. *<p>如果为false,优先检测子对象,当有子对象被命中时,中断检测,获得命中目标。如果未命中任何子对象,最后再检测此对象;如果为true,则优先检测本对象,如果本对象没有被命中,直接中断检测,表示没有命中目标;如果本对象被命中,则进一步递归检测其子对象,以确认最终的命中目标。</p>
  24446. *<p>合理使用本属性,能减少鼠标事件检测的节点,提高性能。可以设置为true的情况:开发者并不关心此节点的子节点的鼠标事件检测结果,也就是以此节点作为其子节点的鼠标事件检测依据。</p>
  24447. *<p>Stage对象和UI的View组件默认为true。</p>
  24448. *@default false 优先检测此对象的子对象,当递归检测完所有子对象后,仍然没有找到目标对象,最后再检测此对象。
  24449. */
  24450. this.hitTestPrior=false;
  24451. Sprite.__super.call(this);
  24452. this._repaint=/*laya.display.SpriteConst.REPAINT_NONE*/0;
  24453. this._style=SpriteStyle.EMPTY;
  24454. this._cacheStyle=CacheStyle.EMPTY;
  24455. }
  24456. __class(Sprite,'laya.display.Sprite',_super);
  24457. var __proto=Sprite.prototype;
  24458. /**@inheritDoc */
  24459. __proto.destroy=function(destroyChild){
  24460. (destroyChild===void 0)&& (destroyChild=true);
  24461. _super.prototype.destroy.call(this,destroyChild);
  24462. this._style && this._style.recover();
  24463. this._cacheStyle && this._cacheStyle.recover();
  24464. this._boundStyle && this._boundStyle.recover();
  24465. this._style=null;
  24466. this._cacheStyle=null;
  24467. this._boundStyle=null;
  24468. this._transform=null;
  24469. if (this._graphics&&this._graphics.autoDestroy){
  24470. this._graphics.destroy();
  24471. }
  24472. this._graphics=null;
  24473. this.texture=null;
  24474. }
  24475. /**根据zOrder进行重新排序。*/
  24476. __proto.updateZOrder=function(){
  24477. Utils.updateOrder(this._children)&& this.repaint();
  24478. }
  24479. /**
  24480. *@private
  24481. */
  24482. __proto._getBoundsStyle=function(){
  24483. if (!this._boundStyle)this._boundStyle=BoundsStyle.create();
  24484. return this._boundStyle;
  24485. }
  24486. /**@private */
  24487. __proto._setCustomRender=function(){}
  24488. /**@private */
  24489. __proto._setCacheAs=function(value){}
  24490. /**
  24491. *更新_cnavas相关的状态
  24492. */
  24493. __proto._checkCanvasEnable=function(){
  24494. var tEnable=this._cacheStyle.needEnableCanvasRender();
  24495. this._getCacheStyle().enableCanvasRender=tEnable;
  24496. if (tEnable){
  24497. if (this._cacheStyle.needBitmapCache()){
  24498. this._cacheStyle.cacheAs="bitmap";
  24499. }else {
  24500. this._cacheStyle.cacheAs=this._cacheStyle.userSetCache;
  24501. }
  24502. this._cacheStyle.reCache=true;
  24503. this._renderType |=/*laya.display.SpriteConst.CANVAS*/0x08;
  24504. }else {
  24505. this._cacheStyle.cacheAs="none";
  24506. this._cacheStyle.releaseContext();
  24507. this._renderType &=~ /*laya.display.SpriteConst.CANVAS*/0x08;
  24508. }
  24509. this._setCacheAs(this._cacheStyle.cacheAs);
  24510. this._setRenderType(this._renderType);
  24511. }
  24512. /**在设置cacheAs的情况下,调用此方法会重新刷新缓存。*/
  24513. __proto.reCache=function(){
  24514. this._cacheStyle.reCache=true;
  24515. this._repaint |=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02;
  24516. }
  24517. __proto.getRepaint=function(){
  24518. return this._repaint;
  24519. }
  24520. /**@private */
  24521. __proto._setX=function(value){
  24522. this._x=value;
  24523. }
  24524. /**@private */
  24525. __proto._setY=function(value){
  24526. this._y=value;
  24527. }
  24528. /**@private */
  24529. __proto._setWidth=function(texture,value){}
  24530. /**@private */
  24531. __proto._setHeight=function(texture,value){}
  24532. /**
  24533. *设置对象bounds大小,如果有设置,则不再通过getBounds计算,合理使用能提高性能。
  24534. *@param bound bounds矩形区域
  24535. */
  24536. __proto.setSelfBounds=function(bound){
  24537. this._getBoundsStyle().userBounds=bound;
  24538. }
  24539. /**
  24540. *<p>获取本对象在父容器坐标系的矩形显示区域。</p>
  24541. *<p><b>注意:</b>计算量较大,尽量少用。</p>
  24542. *@return 矩形区域。
  24543. */
  24544. __proto.getBounds=function(){
  24545. return this._getBoundsStyle().bounds=Rectangle._getWrapRec(this._boundPointsToParent());
  24546. }
  24547. /**
  24548. *获取本对象在自己坐标系的矩形显示区域。
  24549. *<p><b>注意:</b>计算量较大,尽量少用。</p>
  24550. *@return 矩形区域。
  24551. */
  24552. __proto.getSelfBounds=function(){
  24553. if (this._boundStyle && this._boundStyle.userBounds)return this._boundStyle.userBounds;
  24554. if (!this._graphics && this._children.length===0&&!this._texture)return Rectangle.TEMP.setTo(0,0,0,0);
  24555. return this._getBoundsStyle().bounds=Rectangle._getWrapRec(this._getBoundPointsM(false));
  24556. }
  24557. /**
  24558. *@private
  24559. *获取本对象在父容器坐标系的显示区域多边形顶点列表。
  24560. *当显示对象链中有旋转时,返回多边形顶点列表,无旋转时返回矩形的四个顶点。
  24561. *@param ifRotate (可选)之前的对象链中是否有旋转。
  24562. *@return 顶点列表。结构:[x1,y1,x2,y2,x3,y3,...]。
  24563. */
  24564. __proto._boundPointsToParent=function(ifRotate){
  24565. (ifRotate===void 0)&& (ifRotate=false);
  24566. var pX=0,pY=0;
  24567. if (this._style){
  24568. pX=this.pivotX;
  24569. pY=this.pivotY;
  24570. ifRotate=ifRotate || (this._style.rotation!==0);
  24571. if (this._style.scrollRect){
  24572. pX+=this._style.scrollRect.x;
  24573. pY+=this._style.scrollRect.y;
  24574. }
  24575. };
  24576. var pList=this._getBoundPointsM(ifRotate);
  24577. if (!pList || pList.length < 1)return pList;
  24578. if (pList.length !=8){
  24579. pList=ifRotate ? GrahamScan.scanPList(pList):Rectangle._getWrapRec(pList,Rectangle.TEMP)._getBoundPoints();
  24580. }
  24581. if (!this.transform){
  24582. Utils.transPointList(pList,this._x-pX,this._y-pY);
  24583. return pList;
  24584. };
  24585. var tPoint=Point.TEMP;
  24586. var i=0,len=pList.length;
  24587. for (i=0;i < len;i+=2){
  24588. tPoint.x=pList[i];
  24589. tPoint.y=pList[i+1];
  24590. this.toParentPoint(tPoint);
  24591. pList[i]=tPoint.x;
  24592. pList[i+1]=tPoint.y;
  24593. }
  24594. return pList;
  24595. }
  24596. /**
  24597. *返回此实例中的绘图对象( <code>Graphics</code> )的显示区域,不包括子对象。
  24598. *@param realSize (可选)使用图片的真实大小,默认为false
  24599. *@return 一个 Rectangle 对象,表示获取到的显示区域。
  24600. */
  24601. __proto.getGraphicBounds=function(realSize){
  24602. (realSize===void 0)&& (realSize=false);
  24603. if (!this._graphics)return Rectangle.TEMP.setTo(0,0,0,0);
  24604. return this._graphics.getBounds(realSize);
  24605. }
  24606. /**
  24607. *@private
  24608. *获取自己坐标系的显示区域多边形顶点列表
  24609. *@param ifRotate (可选)当前的显示对象链是否由旋转
  24610. *@return 顶点列表。结构:[x1,y1,x2,y2,x3,y3,...]。
  24611. */
  24612. __proto._getBoundPointsM=function(ifRotate){
  24613. (ifRotate===void 0)&& (ifRotate=false);
  24614. if (this._boundStyle && this._boundStyle.userBounds)return this._boundStyle.userBounds._getBoundPoints();
  24615. if (!this._boundStyle)this._getBoundsStyle();
  24616. if (!this._boundStyle.temBM)this._boundStyle.temBM=[];
  24617. if (this._style.scrollRect){
  24618. var rst=Utils.clearArray(this._boundStyle.temBM);
  24619. var rec=Rectangle.TEMP;
  24620. rec.copyFrom(this._style.scrollRect);
  24621. Utils.concatArray(rst,rec._getBoundPoints());
  24622. return rst;
  24623. };
  24624. var pList;
  24625. if (this._graphics){
  24626. pList=this._graphics.getBoundPoints();
  24627. }else {
  24628. pList=Utils.clearArray(this._boundStyle.temBM);
  24629. if (this._texture){
  24630. rec=Rectangle.TEMP;
  24631. rec.setTo(0,0,this.width||this._texture.width,this.height||this._texture.height);
  24632. Utils.concatArray(pList,rec._getBoundPoints());
  24633. }
  24634. };
  24635. var child;
  24636. var cList;
  24637. var __childs;
  24638. __childs=this._children;
  24639. for (var i=0,n=__childs.length;i < n;i++){
  24640. child=__childs [i];
  24641. if ((child instanceof laya.display.Sprite )&& child._visible===true){
  24642. cList=child._boundPointsToParent(ifRotate);
  24643. if (cList)
  24644. pList=pList ? Utils.concatArray(pList,cList):cList;
  24645. }
  24646. }
  24647. return pList;
  24648. }
  24649. /**
  24650. *@private
  24651. *获取cache数据。
  24652. *@return cache数据 CacheStyle 。
  24653. */
  24654. __proto._getCacheStyle=function(){
  24655. this._cacheStyle===CacheStyle.EMPTY && (this._cacheStyle=CacheStyle.create());
  24656. return this._cacheStyle;
  24657. }
  24658. /**
  24659. *@private
  24660. *获取样式。
  24661. *@return 样式 Style 。
  24662. */
  24663. __proto.getStyle=function(){
  24664. this._style===SpriteStyle.EMPTY && (this._style=SpriteStyle.create());
  24665. return this._style;
  24666. }
  24667. /**
  24668. *@private
  24669. *设置样式。
  24670. *@param value 样式。
  24671. */
  24672. __proto.setStyle=function(value){
  24673. this._style=value;
  24674. }
  24675. /**@private */
  24676. __proto._setScaleX=function(value){
  24677. this._style.scaleX=value;
  24678. }
  24679. /**@private */
  24680. __proto._setScaleY=function(value){
  24681. this._style.scaleY=value;
  24682. }
  24683. /**@private */
  24684. __proto._setRotation=function(value){
  24685. this._style.rotation=value;
  24686. }
  24687. /**@private */
  24688. __proto._setSkewX=function(value){
  24689. this._style.skewX=value;
  24690. }
  24691. /**@private */
  24692. __proto._setSkewY=function(value){
  24693. this._style.skewY=value;
  24694. }
  24695. /**@private */
  24696. __proto._createTransform=function(){
  24697. return Matrix.create();
  24698. }
  24699. /**@private */
  24700. __proto._adjustTransform=function(){
  24701. this._tfChanged=false;
  24702. var style=this._style;
  24703. var sx=style.scaleX,sy=style.scaleY;
  24704. var sskx=style.skewX;
  24705. var ssky=style.skewY;
  24706. var rot=style.rotation;
  24707. var m=this._transform || (this._transform=this._createTransform());
  24708. if (rot || sx!==1 || sy!==1 || sskx!==0 || ssky!==0){
  24709. m._bTransform=true;
  24710. var skx=(rot-sskx)*0.0174532922222222;
  24711. var sky=(rot+ssky)*0.0174532922222222;
  24712. var cx=Math.cos(sky);
  24713. var ssx=Math.sin(sky);
  24714. var cy=Math.sin(skx);
  24715. var ssy=Math.cos(skx);
  24716. m.a=sx *cx;
  24717. m.b=sx *ssx;
  24718. m.c=-sy *cy;
  24719. m.d=sy *ssy;
  24720. m.tx=m.ty=0;
  24721. }else {
  24722. m.identity();
  24723. this._renderType &=~ /*laya.display.SpriteConst.TRANSFORM*/0x02;
  24724. this._setRenderType(this._renderType);
  24725. }
  24726. return m;
  24727. }
  24728. /**@private */
  24729. __proto._setTransform=function(value){}
  24730. /**@private */
  24731. __proto._setPivotX=function(value){
  24732. var style=this.getStyle();
  24733. style.pivotX=value;
  24734. }
  24735. /**@private */
  24736. __proto._getPivotX=function(){
  24737. return this._style.pivotX;
  24738. }
  24739. /**@private */
  24740. __proto._setPivotY=function(value){
  24741. var style=this.getStyle();
  24742. style.pivotY=value;
  24743. }
  24744. /**@private */
  24745. __proto._getPivotY=function(){
  24746. return this._style.pivotY;
  24747. }
  24748. /**@private */
  24749. __proto._setAlpha=function(value){
  24750. if (this._style.alpha!==value){
  24751. var style=this.getStyle();
  24752. style.alpha=value;
  24753. if (value!==1)this._renderType |=/*laya.display.SpriteConst.ALPHA*/0x01;
  24754. else this._renderType &=~ /*laya.display.SpriteConst.ALPHA*/0x01;
  24755. this._setRenderType(this._renderType);
  24756. this.parentRepaint();
  24757. }
  24758. }
  24759. /**@private */
  24760. __proto._getAlpha=function(){
  24761. return this._style.alpha;
  24762. }
  24763. /**@private */
  24764. __proto._setBlendMode=function(value){}
  24765. /**@private */
  24766. __proto._setGraphics=function(value){}
  24767. /**@private */
  24768. __proto._setGraphicsCallBack=function(){}
  24769. /**@private */
  24770. __proto._setScrollRect=function(value){}
  24771. /**
  24772. *<p>设置坐标位置。相当于分别设置x和y属性。</p>
  24773. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.pos(...).scale(...);</p>
  24774. *@param x X轴坐标。
  24775. *@param y Y轴坐标。
  24776. *@param speedMode (可选)是否极速模式,正常是调用this.x=value进行赋值,极速模式直接调用内部函数处理,如果未重写x,y属性,建议设置为急速模式性能更高。
  24777. *@return 返回对象本身。
  24778. */
  24779. __proto.pos=function(x,y,speedMode){
  24780. (speedMode===void 0)&& (speedMode=false);
  24781. if (this._x!==x || this._y!==y){
  24782. if (this.destroyed)return this;
  24783. if (speedMode){
  24784. this._setX(x);
  24785. this._setY(y);
  24786. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  24787. var p=this._cacheStyle.maskParent;
  24788. if (p){
  24789. p.repaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  24790. }
  24791. }else {
  24792. this.x=x;
  24793. this.y=y;
  24794. }
  24795. }
  24796. return this;
  24797. }
  24798. /**
  24799. *<p>设置轴心点。相当于分别设置pivotX和pivotY属性。</p>
  24800. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.pivot(...).pos(50,100);</p>
  24801. *@param x X轴心点。
  24802. *@param y Y轴心点。
  24803. *@return 返回对象本身。
  24804. */
  24805. __proto.pivot=function(x,y){
  24806. this.pivotX=x;
  24807. this.pivotY=y;
  24808. return this;
  24809. }
  24810. /**
  24811. *<p>设置宽高。相当于分别设置width和height属性。</p>
  24812. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.size(...).pos(50,100);</p>
  24813. *@param width 宽度值。
  24814. *@param hegiht 高度值。
  24815. *@return 返回对象本身。
  24816. */
  24817. __proto.size=function(width,height){
  24818. this.width=width;
  24819. this.height=height;
  24820. return this;
  24821. }
  24822. /**
  24823. *<p>设置缩放。相当于分别设置scaleX和scaleY属性。</p>
  24824. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.scale(...).pos(50,100);</p>
  24825. *@param scaleX X轴缩放比例。
  24826. *@param scaleY Y轴缩放比例。
  24827. *@param speedMode (可选)是否极速模式,正常是调用this.scaleX=value进行赋值,极速模式直接调用内部函数处理,如果未重写scaleX,scaleY属性,建议设置为急速模式性能更高。
  24828. *@return 返回对象本身。
  24829. */
  24830. __proto.scale=function(scaleX,scaleY,speedMode){
  24831. (speedMode===void 0)&& (speedMode=false);
  24832. var style=this.getStyle();
  24833. if (style.scaleX !=scaleX || style.scaleY !=scaleY){
  24834. if (this.destroyed)return this;
  24835. if (speedMode){
  24836. this._setScaleX(scaleX);
  24837. this._setScaleY(scaleY);
  24838. this._setTranformChange();
  24839. }else {
  24840. this.scaleX=scaleX;
  24841. this.scaleY=scaleY;
  24842. }
  24843. }
  24844. return this;
  24845. }
  24846. /**
  24847. *<p>设置倾斜角度。相当于分别设置skewX和skewY属性。</p>
  24848. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.skew(...).pos(50,100);</p>
  24849. *@param skewX 水平倾斜角度。
  24850. *@param skewY 垂直倾斜角度。
  24851. *@return 返回对象本身
  24852. */
  24853. __proto.skew=function(skewX,skewY){
  24854. this.skewX=skewX;
  24855. this.skewY=skewY;
  24856. return this;
  24857. }
  24858. /**
  24859. *更新、呈现显示对象。由系统调用。
  24860. *@param context 渲染的上下文引用。
  24861. *@param x X轴坐标。
  24862. *@param y Y轴坐标。
  24863. */
  24864. __proto.render=function(ctx,x,y){
  24865. RenderSprite.renders[this._renderType]._fun(this,ctx,x+this._x,y+this._y);
  24866. this._repaint=0;
  24867. }
  24868. /**
  24869. *<p>绘制 当前<code>Sprite</code> 到 <code>Canvas</code> 上,并返回一个HtmlCanvas。</p>
  24870. *<p>绘制的结果可以当作图片源,再次绘制到其他Sprite里面,示例:</p>
  24871. *
  24872. *var htmlCanvas:HTMLCanvas=sprite.drawToCanvas(100,100,0,0);//把精灵绘制到canvas上面
  24873. *var sp:Sprite=new Sprite();//创建精灵
  24874. *sp.graphics.drawTexture(htmlCanvas.getTexture());//把截图绘制到精灵上
  24875. *Laya.stage.addChild(sp);//把精灵显示到舞台
  24876. *
  24877. *<p>也可以获取原始图片数据,分享到网上,从而实现截图效果,示例:</p>
  24878. *
  24879. *var htmlCanvas:HTMLCanvas=sprite.drawToCanvas(100,100,0,0);//把精灵绘制到canvas上面
  24880. *htmlCanvas.toBase64("image/png",0.9);//打印图片base64信息,可以发给服务器或者保存为图片
  24881. *
  24882. *@param canvasWidth 画布宽度。
  24883. *@param canvasHeight 画布高度。
  24884. *@param x 绘制的 X 轴偏移量。
  24885. *@param y 绘制的 Y 轴偏移量。
  24886. *@return HTMLCanvas 对象。
  24887. */
  24888. __proto.drawToCanvas=function(canvasWidth,canvasHeight,offsetX,offsetY){
  24889. return RunDriver.drawToCanvas(this,this._renderType,canvasWidth,canvasHeight,offsetX,offsetY);
  24890. }
  24891. __proto.drawToTexture=function(canvasWidth,canvasHeight,offsetX,offsetY){
  24892. return RunDriver.drawToTexture(this,this._renderType,canvasWidth,canvasHeight,offsetX,offsetY);
  24893. }
  24894. /**
  24895. *<p>自定义更新、呈现显示对象。一般用来扩展渲染模式,请合理使用,可能会导致在加速器上无法渲染。</p>
  24896. *<p><b>注意</b>不要在此函数内增加或删除树节点,否则会对树节点遍历造成影响。</p>
  24897. *@param context 渲染的上下文引用。
  24898. *@param x X轴坐标。
  24899. *@param y Y轴坐标。
  24900. */
  24901. __proto.customRender=function(context,x,y){
  24902. this._repaint=/*laya.display.SpriteConst.REPAINT_ALL*/0x03;
  24903. }
  24904. /**
  24905. *@private
  24906. *应用滤镜。
  24907. */
  24908. __proto._applyFilters=function(){}
  24909. /**@private */
  24910. __proto._setColorFilter=function(value){}
  24911. /**
  24912. *@private
  24913. *查看当前原件中是否包含发光滤镜。
  24914. *@return 一个 Boolean 值,表示当前原件中是否包含发光滤镜。
  24915. */
  24916. __proto._isHaveGlowFilter=function(){
  24917. var i=0,len=0;
  24918. if (this.filters){
  24919. for (i=0;i < this.filters.length;i++){
  24920. if (this.filters[i].type==/*laya.filters.Filter.GLOW*/0x08){
  24921. return true;
  24922. }
  24923. }
  24924. }
  24925. for (i=0,len=this._children.length;i < len;i++){
  24926. if (this._children[i]._isHaveGlowFilter()){
  24927. return true;
  24928. }
  24929. }
  24930. return false;
  24931. }
  24932. /**
  24933. *把本地坐标转换为相对stage的全局坐标。
  24934. *@param point 本地坐标点。
  24935. *@param createNewPoint (可选)是否创建一个新的Point对象作为返回值,默认为false,使用输入的point对象返回,减少对象创建开销。
  24936. *@param globalNode global节点,默认为Laya.stage
  24937. *@return 转换后的坐标的点。
  24938. */
  24939. __proto.localToGlobal=function(point,createNewPoint,globalNode){
  24940. (createNewPoint===void 0)&& (createNewPoint=false);
  24941. if (createNewPoint===true){
  24942. point=new Point(point.x,point.y);
  24943. };
  24944. var ele=this;
  24945. globalNode=globalNode || Laya.stage;
  24946. while (ele && !ele.destroyed){
  24947. if (ele==globalNode)break ;
  24948. point=ele.toParentPoint(point);
  24949. ele=ele.parent;
  24950. }
  24951. return point;
  24952. }
  24953. /**
  24954. *把stage的全局坐标转换为本地坐标。
  24955. *@param point 全局坐标点。
  24956. *@param createNewPoint (可选)是否创建一个新的Point对象作为返回值,默认为false,使用输入的point对象返回,减少对象创建开销。
  24957. *@param globalNode global节点,默认为Laya.stage
  24958. *@return 转换后的坐标的点。
  24959. */
  24960. __proto.globalToLocal=function(point,createNewPoint,globalNode){
  24961. (createNewPoint===void 0)&& (createNewPoint=false);
  24962. if (createNewPoint){
  24963. point=new Point(point.x,point.y);
  24964. };
  24965. var ele=this;
  24966. var list=[];
  24967. globalNode=globalNode || Laya.stage;
  24968. while (ele && !ele.destroyed){
  24969. if (ele==globalNode)break ;
  24970. list.push(ele);
  24971. ele=ele.parent;
  24972. };
  24973. var i=list.length-1;
  24974. while (i >=0){
  24975. ele=list[i];
  24976. point=ele.fromParentPoint(point);
  24977. i--;
  24978. }
  24979. return point;
  24980. }
  24981. /**
  24982. *将本地坐标系坐标转转换到父容器坐标系。
  24983. *@param point 本地坐标点。
  24984. *@return 转换后的点。
  24985. */
  24986. __proto.toParentPoint=function(point){
  24987. if (!point)return point;
  24988. point.x-=this.pivotX;
  24989. point.y-=this.pivotY;
  24990. if (this.transform){
  24991. this._transform.transformPoint(point);
  24992. }
  24993. point.x+=this._x;
  24994. point.y+=this._y;
  24995. var scroll=this._style.scrollRect;
  24996. if (scroll){
  24997. point.x-=scroll.x;
  24998. point.y-=scroll.y;
  24999. }
  25000. return point;
  25001. }
  25002. /**
  25003. *将父容器坐标系坐标转换到本地坐标系。
  25004. *@param point 父容器坐标点。
  25005. *@return 转换后的点。
  25006. */
  25007. __proto.fromParentPoint=function(point){
  25008. if (!point)return point;
  25009. point.x-=this._x;
  25010. point.y-=this._y;
  25011. var scroll=this._style.scrollRect;
  25012. if (scroll){
  25013. point.x+=scroll.x;
  25014. point.y+=scroll.y;
  25015. }
  25016. if (this.transform){
  25017. this._transform.invertTransformPoint(point);
  25018. }
  25019. point.x+=this.pivotX;
  25020. point.y+=this.pivotY;
  25021. return point;
  25022. }
  25023. /**
  25024. *将Stage坐标系坐标转换到本地坐标系。
  25025. *@param point 父容器坐标点。
  25026. *@return 转换后的点。
  25027. */
  25028. __proto.fromStagePoint=function(point){
  25029. return point;
  25030. }
  25031. /**
  25032. *<p>增加事件侦听器,以使侦听器能够接收事件通知。</p>
  25033. *<p>如果侦听鼠标事件,则会自动设置自己和父亲节点的属性 mouseEnabled 的值为 true(如果父节点mouseEnabled=false,则停止设置父节点mouseEnabled属性)。</p>
  25034. *@param type 事件的类型。
  25035. *@param caller 事件侦听函数的执行域。
  25036. *@param listener 事件侦听函数。
  25037. *@param args (可选)事件侦听函数的回调参数。
  25038. *@return 此 EventDispatcher 对象。
  25039. */
  25040. __proto.on=function(type,caller,listener,args){
  25041. if (this._mouseState!==1 && this.isMouseEvent(type)){
  25042. this.mouseEnabled=true;
  25043. this._setBit(/*laya.Const.HAS_MOUSE*/0x40,true);
  25044. if (this._parent){
  25045. this._$2__onDisplay();
  25046. }
  25047. return this._createListener(type,caller,listener,args,false);
  25048. }
  25049. return _super.prototype.on.call(this,type,caller,listener,args);
  25050. }
  25051. /**
  25052. *<p>增加事件侦听器,以使侦听器能够接收事件通知,此侦听事件响应一次后则自动移除侦听。</p>
  25053. *<p>如果侦听鼠标事件,则会自动设置自己和父亲节点的属性 mouseEnabled 的值为 true(如果父节点mouseEnabled=false,则停止设置父节点mouseEnabled属性)。</p>
  25054. *@param type 事件的类型。
  25055. *@param caller 事件侦听函数的执行域。
  25056. *@param listener 事件侦听函数。
  25057. *@param args (可选)事件侦听函数的回调参数。
  25058. *@return 此 EventDispatcher 对象。
  25059. */
  25060. __proto.once=function(type,caller,listener,args){
  25061. if (this._mouseState!==1 && this.isMouseEvent(type)){
  25062. this.mouseEnabled=true;
  25063. this._setBit(/*laya.Const.HAS_MOUSE*/0x40,true);
  25064. if (this._parent){
  25065. this._$2__onDisplay();
  25066. }
  25067. return this._createListener(type,caller,listener,args,true);
  25068. }
  25069. return _super.prototype.once.call(this,type,caller,listener,args);
  25070. }
  25071. /**@private */
  25072. __proto._$2__onDisplay=function(){
  25073. if (this._mouseState!==1){
  25074. var ele=this;
  25075. ele=ele.parent;
  25076. while (ele && ele._mouseState!==1){
  25077. if (ele._getBit(/*laya.Const.HAS_MOUSE*/0x40))break ;
  25078. ele.mouseEnabled=true;
  25079. ele._setBit(/*laya.Const.HAS_MOUSE*/0x40,true);
  25080. ele=ele.parent;
  25081. }
  25082. }
  25083. }
  25084. /**@private */
  25085. __proto._setParent=function(value){
  25086. _super.prototype._setParent.call(this,value);
  25087. if (value && this._getBit(/*laya.Const.HAS_MOUSE*/0x40)){
  25088. this._$2__onDisplay();
  25089. }
  25090. }
  25091. /**
  25092. *<p>加载并显示一个图片。相当于加载图片后,设置texture属性</p>
  25093. *<p>注意:2.0改动:多次调用,只会显示一个图片(1.0会显示多个图片),x,y,width,height参数取消。</p>
  25094. *@param url 图片地址。
  25095. *@param complete (可选)加载完成回调。
  25096. *@return 返回精灵对象本身。
  25097. */
  25098. __proto.loadImage=function(url,complete){
  25099. var _$this=this;
  25100. if (url==null){
  25101. this.texture=null;
  25102. loaded();
  25103. }else{
  25104. var tex=Loader.getRes(url);
  25105. if (!tex){
  25106. tex=new Texture();
  25107. tex.load(url);
  25108. Loader.cacheRes(url,tex);
  25109. }
  25110. this.texture=tex;
  25111. if (!tex.getIsReady())tex.once(/*laya.events.Event.READY*/"ready",null,loaded);
  25112. else loaded();
  25113. }
  25114. function loaded (){
  25115. _$this.repaint(/*laya.display.SpriteConst.REPAINT_ALL*/0x03);
  25116. complete && complete.run();
  25117. }
  25118. return this;
  25119. }
  25120. /**cacheAs后,设置自己和父对象缓存失效。*/
  25121. __proto.repaint=function(type){
  25122. (type===void 0)&& (type=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25123. if (!(this._repaint&type)){
  25124. this._repaint |=type;
  25125. this.parentRepaint(type);
  25126. }
  25127. if (this._cacheStyle && this._cacheStyle.maskParent){
  25128. this._cacheStyle.maskParent.repaint(type);
  25129. }
  25130. }
  25131. /**
  25132. *@private
  25133. *获取是否重新缓存。
  25134. *@return 如果重新缓存值为 true,否则值为 false。
  25135. */
  25136. __proto._needRepaint=function(){
  25137. return (this._repaint& /*laya.display.SpriteConst.REPAINT_CACHE*/0x02)&& this._cacheStyle.enableCanvasRender && this._cacheStyle.reCache;
  25138. }
  25139. /**@private */
  25140. __proto._childChanged=function(child){
  25141. if (this._children.length)this._renderType |=/*laya.display.SpriteConst.CHILDS*/0x2000;
  25142. else this._renderType &=~ /*laya.display.SpriteConst.CHILDS*/0x2000;
  25143. this._setRenderType(this._renderType);
  25144. if (child && this._getBit(/*laya.Const.HAS_ZORDER*/0x20))Laya.systemTimer.callLater(this,this.updateZOrder);
  25145. this.repaint(/*laya.display.SpriteConst.REPAINT_ALL*/0x03);
  25146. }
  25147. /**cacheAs时,设置所有父对象缓存失效。 */
  25148. __proto.parentRepaint=function(type){
  25149. (type===void 0)&& (type=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25150. var p=this._parent;
  25151. if (p && !(p._repaint&type)){
  25152. p._repaint |=type;
  25153. p.parentRepaint(type);
  25154. }
  25155. }
  25156. /**@private */
  25157. __proto._setMask=function(value){}
  25158. /**
  25159. *开始拖动此对象。
  25160. *@param area (可选)拖动区域,此区域为当前对象注册点活动区域(不包括对象宽高),可选。
  25161. *@param hasInertia (可选)鼠标松开后,是否还惯性滑动,默认为false,可选。
  25162. *@param elasticDistance (可选)橡皮筋效果的距离值,0为无橡皮筋效果,默认为0,可选。
  25163. *@param elasticBackTime (可选)橡皮筋回弹时间,单位为毫秒,默认为300毫秒,可选。
  25164. *@param data (可选)拖动事件携带的数据,可选。
  25165. *@param disableMouseEvent (可选)禁用其他对象的鼠标检测,默认为false,设置为true能提高性能。
  25166. *@param ratio (可选)惯性阻尼系数,影响惯性力度和时长。
  25167. */
  25168. __proto.startDrag=function(area,hasInertia,elasticDistance,elasticBackTime,data,disableMouseEvent,ratio){
  25169. (hasInertia===void 0)&& (hasInertia=false);
  25170. (elasticDistance===void 0)&& (elasticDistance=0);
  25171. (elasticBackTime===void 0)&& (elasticBackTime=300);
  25172. (disableMouseEvent===void 0)&& (disableMouseEvent=false);
  25173. (ratio===void 0)&& (ratio=0.92);
  25174. this._style.dragging || (this.getStyle().dragging=new Dragging());
  25175. this._style.dragging.start(this,area,hasInertia,elasticDistance,elasticBackTime,data,disableMouseEvent,ratio);
  25176. }
  25177. /**停止拖动此对象。*/
  25178. __proto.stopDrag=function(){
  25179. this._style.dragging && this._style.dragging.stop();
  25180. }
  25181. /**@private */
  25182. __proto._setDisplay=function(value){
  25183. if (!value){
  25184. if (this._cacheStyle){
  25185. this._cacheStyle.releaseContext();
  25186. this._cacheStyle.releaseFilterCache();
  25187. if (this._cacheStyle.hasGlowFilter){
  25188. this._cacheStyle.hasGlowFilter=false;
  25189. }
  25190. }
  25191. }
  25192. _super.prototype._setDisplay.call(this,value);
  25193. }
  25194. /**
  25195. *检测某个点是否在此对象内。
  25196. *@param x 全局x坐标。
  25197. *@param y 全局y坐标。
  25198. *@return 表示是否在对象内。
  25199. */
  25200. __proto.hitTestPoint=function(x,y){
  25201. var point=this.globalToLocal(Point.TEMP.setTo(x,y));
  25202. x=point.x;
  25203. y=point.y;
  25204. var rect=this._style.hitArea ? this._style.hitArea :(this._width > 0 && this._height > 0)? Rectangle.TEMP.setTo(0,0,this._width,this._height):this.getSelfBounds();
  25205. return rect.contains(x,y);
  25206. }
  25207. /**获得相对于本对象上的鼠标坐标信息。*/
  25208. __proto.getMousePoint=function(){
  25209. return this.globalToLocal(Point.TEMP.setTo(Laya.stage.mouseX,Laya.stage.mouseY));
  25210. }
  25211. /**@private */
  25212. __proto._setTexture=function(value){}
  25213. /**@private */
  25214. __proto._setRenderType=function(type){}
  25215. /**@private */
  25216. __proto._setTranformChange=function(){
  25217. this._tfChanged=true;
  25218. this._renderType |=/*laya.display.SpriteConst.TRANSFORM*/0x02;
  25219. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25220. }
  25221. /**@private */
  25222. __proto._setBgStyleColor=function(x,y,width,height,fillColor){}
  25223. /**@private */
  25224. __proto._setBorderStyleColor=function(x,y,width,height,fillColor,borderWidth){}
  25225. /**@private */
  25226. __proto.captureMouseEvent=function(exclusive){
  25227. MouseManager.instance.setCapture(this,exclusive);
  25228. }
  25229. /**@private */
  25230. __proto.releaseMouseEvent=function(){
  25231. MouseManager.instance.releaseCapture();
  25232. }
  25233. /**
  25234. *设置是否开启自定义渲染,只有开启自定义渲染,才能使用customRender函数渲染。
  25235. */
  25236. __getset(0,__proto,'customRenderEnable',null,function(b){
  25237. if (b){
  25238. this._renderType |=/*laya.display.SpriteConst.CUSTOM*/0x800;
  25239. this._setRenderType(this._renderType);
  25240. this._setCustomRender();
  25241. }
  25242. });
  25243. //_dataf32[SpriteConst.POSCACHE]=value=="bitmap"?2:(value=="normal"?1:0);
  25244. /**
  25245. *<p>指定显示对象是否缓存为静态图像,cacheAs时,子对象发生变化,会自动重新缓存,同时也可以手动调用reCache方法更新缓存。</p>
  25246. *<p>建议把不经常变化的“复杂内容”缓存为静态图像,能极大提高渲染性能。cacheAs有"none","normal"和"bitmap"三个值可选。
  25247. *<li>默认为"none",不做任何缓存。</li>
  25248. *<li>当值为"normal"时,canvas模式下进行画布缓存,webgl模式下进行命令缓存。</li>
  25249. *<li>当值为"bitmap"时,canvas模式下进行依然是画布缓存,webgl模式下使用renderTarget缓存。</li></p>
  25250. *<p>webgl下renderTarget缓存模式缺点:会额外创建renderTarget对象,增加内存开销,缓存面积有最大2048限制,不断重绘时会增加CPU开销。优点:大幅减少drawcall,渲染性能最高。
  25251. *webgl下命令缓存模式缺点:只会减少节点遍历及命令组织,不会减少drawcall数,性能中等。优点:没有额外内存开销,无需renderTarget支持。</p>
  25252. */
  25253. __getset(0,__proto,'cacheAs',function(){
  25254. return this._cacheStyle.cacheAs;
  25255. },function(value){
  25256. if (value===this._cacheStyle.userSetCache)return;
  25257. if (this.mask && value==='normal')return;
  25258. this._setCacheAs(value);
  25259. this._getCacheStyle().userSetCache=value;
  25260. this._checkCanvasEnable();
  25261. this.repaint();
  25262. });
  25263. /**
  25264. *获得相对于stage的全局Y轴缩放值(会叠加父亲节点的缩放值)。
  25265. */
  25266. __getset(0,__proto,'globalScaleY',function(){
  25267. var scale=1;
  25268. var ele=this;
  25269. while (ele){
  25270. if (ele===Laya.stage)break ;
  25271. scale *=ele.scaleY;
  25272. ele=ele.parent;
  25273. }
  25274. return scale;
  25275. });
  25276. /**
  25277. *<p>可以设置一个Rectangle区域作为点击区域,或者设置一个<code>HitArea</code>实例作为点击区域,HitArea内可以设置可点击和不可点击区域。</p>
  25278. *<p>如果不设置hitArea,则根据宽高形成的区域进行碰撞。</p>
  25279. */
  25280. __getset(0,__proto,'hitArea',function(){
  25281. return this._style.hitArea;
  25282. },function(value){
  25283. this.getStyle().hitArea=value;
  25284. });
  25285. /**设置cacheAs为非空时此值才有效,staticCache=true时,子对象变化时不会自动更新缓存,只能通过调用reCache方法手动刷新。*/
  25286. __getset(0,__proto,'staticCache',function(){
  25287. return this._cacheStyle.staticCache;
  25288. },function(value){
  25289. this._getCacheStyle().staticCache=value;
  25290. if (!value)this.reCache();
  25291. });
  25292. /**
  25293. *<p>对象的显示宽度(以像素为单位)。</p>
  25294. */
  25295. __getset(0,__proto,'displayWidth',function(){
  25296. return this.width *this.scaleX;
  25297. });
  25298. /**z排序,更改此值,则会按照值的大小对同一容器的所有对象重新排序。值越大,越靠上。默认为0,则根据添加顺序排序。*/
  25299. __getset(0,__proto,'zOrder',function(){
  25300. return this._zOrder;
  25301. },function(value){
  25302. if (this._zOrder !=value){
  25303. this._zOrder=value;
  25304. if (this._parent){
  25305. value && this._parent._setBit(/*laya.Const.HAS_ZORDER*/0x20,true);
  25306. Laya.systemTimer.callLater(this._parent,this.updateZOrder);
  25307. }
  25308. }
  25309. });
  25310. /**旋转角度,默认值为0。以角度为单位。*/
  25311. __getset(0,__proto,'rotation',function(){
  25312. return this._style.rotation;
  25313. },function(value){
  25314. var style=this.getStyle();
  25315. if (style.rotation!==value){
  25316. this._setRotation(value);
  25317. this._setTranformChange();
  25318. }
  25319. });
  25320. /**
  25321. *<p>显示对象的宽度,单位为像素,默认为0。</p>
  25322. *<p>此宽度用于鼠标碰撞检测,并不影响显示对象图像大小。需要对显示对象的图像进行缩放,请使用scale、scaleX、scaleY。</p>
  25323. *<p>可以通过getbounds获取显示对象图像的实际宽度。</p>
  25324. */
  25325. __getset(0,__proto,'width',function(){
  25326. if (!this.autoSize)return this._width || (this.texture?this.texture.width:0);
  25327. if (this.texture)return this.texture.width;
  25328. if (!this._graphics && this._children.length===0)return 0;
  25329. return this.getSelfBounds().width;
  25330. },function(value){
  25331. if (this._width!==value){
  25332. this._width=value;
  25333. this._setWidth(this.texture,value);
  25334. this._setTranformChange();
  25335. }
  25336. });
  25337. /**表示显示对象相对于父容器的水平方向坐标值。*/
  25338. __getset(0,__proto,'x',function(){
  25339. return this._x;
  25340. },function(value){
  25341. if (this.destroyed)return;
  25342. if (this._x!==value){
  25343. this._setX(value);
  25344. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25345. var p=this._cacheStyle.maskParent;
  25346. if (p){
  25347. p.repaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25348. }
  25349. }
  25350. });
  25351. __getset(0,__proto,'drawCallOptimize',function(){
  25352. return this._getBit(/*laya.Const.DRAWCALL_OPTIMIZE*/0x100);
  25353. },function(value){
  25354. this._setBit(/*laya.Const.DRAWCALL_OPTIMIZE*/0x100,value);
  25355. });
  25356. /**
  25357. *设置一个Texture实例,并显示此图片(如果之前有其他绘制,则会被清除掉)。
  25358. *等同于graphics.clear();graphics.drawImage(),但性能更高
  25359. *还可以赋值一个图片地址,则会自动加载图片,然后显示
  25360. */
  25361. __getset(0,__proto,'texture',function(){
  25362. return this._texture;
  25363. },function(value){
  25364. if ((typeof value=='string')){
  25365. this.loadImage(value);
  25366. }else if (this._texture !=value){
  25367. this._texture && this._texture._removeReference();
  25368. this._texture=value;
  25369. value && value._addReference();
  25370. this._setTexture(value);
  25371. this._setWidth(this._texture,this.width);
  25372. this._setHeight(this._texture,this.height);
  25373. if (value)this._renderType |=/*laya.display.SpriteConst.TEXTURE*/0x100;
  25374. else this._renderType &=~ /*laya.display.SpriteConst.TEXTURE*/0x100;
  25375. this._setRenderType(this._renderType);
  25376. this.repaint();
  25377. }
  25378. });
  25379. /**
  25380. *获得相对于stage的全局旋转值(会叠加父亲节点的旋转值)。
  25381. */
  25382. __getset(0,__proto,'globalRotation',function(){
  25383. var angle=0;
  25384. var ele=this;
  25385. while (ele){
  25386. if (ele===Laya.stage)break ;
  25387. angle+=ele.rotation;
  25388. ele=ele.parent;
  25389. }
  25390. return angle;
  25391. });
  25392. /**表示显示对象相对于父容器的垂直方向坐标值。*/
  25393. __getset(0,__proto,'y',function(){
  25394. return this._y;
  25395. },function(value){
  25396. if (this.destroyed)return;
  25397. if (this._y!==value){
  25398. this._setY(value);
  25399. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25400. var p=this._cacheStyle.maskParent;
  25401. if (p){
  25402. p.repaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25403. }
  25404. }
  25405. });
  25406. /**
  25407. *<p>对象的显示高度(以像素为单位)。</p>
  25408. */
  25409. __getset(0,__proto,'displayHeight',function(){
  25410. return this.height *this.scaleY;
  25411. });
  25412. /**
  25413. *<p>显示对象的高度,单位为像素,默认为0。</p>
  25414. *<p>此高度用于鼠标碰撞检测,并不影响显示对象图像大小。需要对显示对象的图像进行缩放,请使用scale、scaleX、scaleY。</p>
  25415. *<p>可以通过getbounds获取显示对象图像的实际高度。</p>
  25416. */
  25417. __getset(0,__proto,'height',function(){
  25418. if (!this.autoSize)return this._height || (this.texture?this.texture.height:0);
  25419. if (this.texture)return this.texture.height;
  25420. if (!this._graphics && this._children.length===0)return 0;
  25421. return this.getSelfBounds().height;
  25422. },function(value){
  25423. if (this._height!==value){
  25424. this._height=value;
  25425. this._setHeight(this.texture,value);
  25426. this._setTranformChange();
  25427. }
  25428. });
  25429. /**指定要使用的混合模式。目前只支持"lighter"。*/
  25430. __getset(0,__proto,'blendMode',function(){
  25431. return this._style.blendMode;
  25432. },function(value){
  25433. this._setBlendMode(value);
  25434. this.getStyle().blendMode=value;
  25435. if (value && value !="source-over")this._renderType |=/*laya.display.SpriteConst.BLEND*/0x04;
  25436. else this._renderType &=~ /*laya.display.SpriteConst.BLEND*/0x04;
  25437. this._setRenderType(this._renderType);
  25438. this.parentRepaint();
  25439. });
  25440. /**X轴缩放值,默认值为1。设置为负数,可以实现水平反转效果,比如scaleX=-1。*/
  25441. __getset(0,__proto,'scaleX',function(){
  25442. return this._style.scaleX;
  25443. },function(value){
  25444. var style=this.getStyle();
  25445. if (style.scaleX!==value){
  25446. this._setScaleX(value);
  25447. this._setTranformChange();
  25448. }
  25449. });
  25450. /**Y轴缩放值,默认值为1。设置为负数,可以实现垂直反转效果,比如scaleX=-1。*/
  25451. __getset(0,__proto,'scaleY',function(){
  25452. return this._style.scaleY;
  25453. },function(value){
  25454. var style=this.getStyle();
  25455. if (style.scaleY!==value){
  25456. this._setScaleY(value);
  25457. this._setTranformChange();
  25458. }
  25459. });
  25460. /**对舞台 <code>stage</code> 的引用。*/
  25461. __getset(0,__proto,'stage',function(){
  25462. return Laya.stage;
  25463. });
  25464. /**水平倾斜角度,默认值为0。以角度为单位。*/
  25465. __getset(0,__proto,'skewX',function(){
  25466. return this._style.skewX;
  25467. },function(value){
  25468. var style=this.getStyle();
  25469. if (style.skewX!==value){
  25470. this._setSkewX(value);
  25471. this._setTranformChange();
  25472. }
  25473. });
  25474. /**
  25475. *<p>显示对象的滚动矩形范围,具有裁剪效果(如果只想限制子对象渲染区域,请使用viewport)</p>
  25476. *<p> srollRect和viewport的区别:<br/>
  25477. *1.srollRect自带裁剪效果,viewport只影响子对象渲染是否渲染,不具有裁剪效果(性能更高)。<br/>
  25478. *2.设置rect的x,y属性均能实现区域滚动效果,但scrollRect会保持0,0点位置不变。</p>
  25479. */
  25480. __getset(0,__proto,'scrollRect',function(){
  25481. return this._style.scrollRect;
  25482. },function(value){
  25483. this.getStyle().scrollRect=value;
  25484. this._setScrollRect(value);
  25485. this.repaint();
  25486. if (value){
  25487. this._renderType |=/*laya.display.SpriteConst.CLIP*/0x40;
  25488. }else {
  25489. this._renderType &=~ /*laya.display.SpriteConst.CLIP*/0x40;
  25490. }
  25491. this._setRenderType(this._renderType);
  25492. });
  25493. /**垂直倾斜角度,默认值为0。以角度为单位。*/
  25494. __getset(0,__proto,'skewY',function(){
  25495. return this._style.skewY;
  25496. },function(value){
  25497. var style=this.getStyle();
  25498. if (style.skewY!==value){
  25499. this._setSkewY(value);
  25500. this._setTranformChange();
  25501. }
  25502. });
  25503. /**
  25504. *<p>对象的矩阵信息。通过设置矩阵可以实现节点旋转,缩放,位移效果。</p>
  25505. *<p>矩阵更多信息请参考 <code>Matrix</code></p>
  25506. */
  25507. __getset(0,__proto,'transform',function(){
  25508. return this._tfChanged ? this._adjustTransform():this._transform;
  25509. },function(value){
  25510. this._tfChanged=false;
  25511. var m=this._transform || (this._transform=this._createTransform());
  25512. value.copyTo(m);
  25513. this._setTransform(m);
  25514. if (value){
  25515. this._x=m.tx;
  25516. this._y=m.ty;
  25517. m.tx=m.ty=0;
  25518. }
  25519. if (value)this._renderType |=/*laya.display.SpriteConst.TRANSFORM*/0x02;
  25520. else {
  25521. this._renderType &=~ /*laya.display.SpriteConst.TRANSFORM*/0x02;
  25522. }
  25523. this._setRenderType(this._renderType);
  25524. this.parentRepaint();
  25525. });
  25526. /**X轴 轴心点的位置,单位为像素,默认为0。轴心点会影响对象位置,缩放中心,旋转中心。*/
  25527. __getset(0,__proto,'pivotX',function(){
  25528. return this._getPivotX();
  25529. },function(value){
  25530. this._setPivotX(value);
  25531. this.repaint();
  25532. });
  25533. /**Y轴 轴心点的位置,单位为像素,默认为0。轴心点会影响对象位置,缩放中心,旋转中心。*/
  25534. __getset(0,__proto,'pivotY',function(){
  25535. return this._getPivotY();
  25536. },function(value){
  25537. this._setPivotY(value);
  25538. this.repaint();
  25539. });
  25540. /**透明度,值为0-1,默认值为1,表示不透明。更改alpha值会影响drawcall。*/
  25541. __getset(0,__proto,'alpha',function(){
  25542. return this._getAlpha();
  25543. },function(value){
  25544. value=value < 0 ? 0 :(value > 1 ? 1 :value);
  25545. this._setAlpha(value);
  25546. });
  25547. /**表示是否可见,默认为true。如果设置不可见,节点将不被渲染。*/
  25548. __getset(0,__proto,'visible',function(){
  25549. return this._visible;
  25550. },function(value){
  25551. if (this._visible!==value){
  25552. this._visible=value;
  25553. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_ALL*/0x03);
  25554. }
  25555. });
  25556. /**绘图对象。封装了绘制位图和矢量图的接口,Sprite所有的绘图操作都通过Graphics来实现的。*/
  25557. __getset(0,__proto,'graphics',function(){
  25558. if (!this._graphics){
  25559. this.graphics=new Graphics();
  25560. this._graphics.autoDestroy=true;
  25561. }
  25562. return this._graphics;
  25563. },function(value){
  25564. if (this._graphics)this._graphics._sp=null;
  25565. this._graphics=value;
  25566. if (value){
  25567. this._setGraphics(value);
  25568. this._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  25569. value._sp=this;
  25570. }else {
  25571. this._renderType &=~ /*laya.display.SpriteConst.GRAPHICS*/0x200;
  25572. }
  25573. this._setRenderType(this._renderType);
  25574. this.repaint();
  25575. });
  25576. /**滤镜集合。可以设置多个滤镜组合。*/
  25577. __getset(0,__proto,'filters',function(){
  25578. return this._cacheStyle.filters;
  25579. },function(value){
  25580. value && value.length===0 && (value=null);
  25581. if (this._cacheStyle.filters==value)return;
  25582. this._getCacheStyle().filters=value ? value.slice():null;
  25583. if (value && value.length){
  25584. this._setColorFilter(value[0]);
  25585. this._renderType |=/*laya.display.SpriteConst.FILTERS*/0x10;
  25586. }else {
  25587. this._setColorFilter(null);
  25588. this._renderType &=~ /*laya.display.SpriteConst.FILTERS*/0x10;
  25589. }
  25590. this._setRenderType(this._renderType);
  25591. if (value && value.length > 0){
  25592. if (!this._getBit(/*laya.Const.DISPLAY*/0x10))this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  25593. if (!(value.length==1 && (((value[0])instanceof laya.filters.ColorFilter )))){
  25594. this._getCacheStyle().cacheForFilters=true;
  25595. this._checkCanvasEnable();
  25596. }
  25597. }else {
  25598. if (this._cacheStyle.cacheForFilters){
  25599. this._cacheStyle.cacheForFilters=false;
  25600. this._checkCanvasEnable();
  25601. }
  25602. }
  25603. this._getCacheStyle().hasGlowFilter=this._isHaveGlowFilter();
  25604. this.repaint();
  25605. });
  25606. /**
  25607. *<p>遮罩,可以设置一个对象(支持位图和矢量图),根据对象形状进行遮罩显示。</p>
  25608. *<p>【注意】遮罩对象坐标系是相对遮罩对象本身的,和Flash机制不同</p>
  25609. */
  25610. __getset(0,__proto,'mask',function(){
  25611. return this._cacheStyle.mask;
  25612. },function(value){
  25613. if (value && this.mask && this.mask._cacheStyle.maskParent)return;
  25614. this._getCacheStyle().mask=value;
  25615. this._setMask(value);
  25616. this._checkCanvasEnable();
  25617. if (value){
  25618. value._getCacheStyle().maskParent=this;
  25619. }else {
  25620. if (this.mask){
  25621. this.mask._getCacheStyle().maskParent=null;
  25622. }
  25623. }
  25624. this._renderType |=/*laya.display.SpriteConst.MASK*/0x20;
  25625. this._setRenderType(this._renderType);
  25626. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_ALL*/0x03);
  25627. });
  25628. /**
  25629. *是否接受鼠标事件。
  25630. *默认为false,如果监听鼠标事件,则会自动设置本对象及父节点的属性 mouseEnable 的值都为 true(如果父节点手动设置为false,则不会更改)。
  25631. **/
  25632. __getset(0,__proto,'mouseEnabled',function(){
  25633. return this._mouseState > 1;
  25634. },function(value){
  25635. this._mouseState=value ? 2 :1;
  25636. });
  25637. /**
  25638. *获得相对于stage的全局X轴缩放值(会叠加父亲节点的缩放值)。
  25639. */
  25640. __getset(0,__proto,'globalScaleX',function(){
  25641. var scale=1;
  25642. var ele=this;
  25643. while (ele){
  25644. if (ele===Laya.stage)break ;
  25645. scale *=ele.scaleX;
  25646. ele=ele.parent;
  25647. }
  25648. return scale;
  25649. });
  25650. /**
  25651. *返回鼠标在此对象坐标系上的 X 轴坐标信息。
  25652. */
  25653. __getset(0,__proto,'mouseX',function(){
  25654. return this.getMousePoint().x;
  25655. });
  25656. /**
  25657. *返回鼠标在此对象坐标系上的 Y 轴坐标信息。
  25658. */
  25659. __getset(0,__proto,'mouseY',function(){
  25660. return this.getMousePoint().y;
  25661. });
  25662. /**
  25663. *<p>视口大小,视口外的子对象,将不被渲染(如果想实现裁剪效果,请使用srollRect),合理使用能提高渲染性能。比如由一个个小图片拼成的地图块,viewport外面的小图片将不渲染</p>
  25664. *<p>srollRect和viewport的区别:<br/>
  25665. *1. srollRect自带裁剪效果,viewport只影响子对象渲染是否渲染,不具有裁剪效果(性能更高)。<br/>
  25666. *2. 设置rect的x,y属性均能实现区域滚动效果,但scrollRect会保持0,0点位置不变。</p>
  25667. *@default null
  25668. */
  25669. __getset(0,__proto,'viewport',function(){
  25670. return this._style.viewport;
  25671. },function(value){
  25672. if ((typeof value=='string')){
  25673. var recArr;
  25674. recArr=(value).split(",");
  25675. if (recArr.length > 3){
  25676. value=new Rectangle(parseFloat(recArr[0]),parseFloat(recArr[1]),parseFloat(recArr[2]),parseFloat(recArr[3]));
  25677. }
  25678. }
  25679. this.getStyle().viewport=value;
  25680. });
  25681. Sprite.fromImage=function(url){
  25682. return new Sprite().loadImage(url);
  25683. }
  25684. return Sprite;
  25685. })(Node)
  25686. /**
  25687. *@private
  25688. *web audio api方式播放声音的音轨控制
  25689. */
  25690. //class laya.media.webaudio.WebAudioSoundChannel extends laya.media.SoundChannel
  25691. var WebAudioSoundChannel=(function(_super){
  25692. function WebAudioSoundChannel(){
  25693. /**
  25694. *声音原始文件数据
  25695. */
  25696. this.audioBuffer=null;
  25697. /**
  25698. *gain节点
  25699. */
  25700. this.gain=null;
  25701. /**
  25702. *播放用的数据
  25703. */
  25704. this.bufferSource=null;
  25705. /**
  25706. *当前时间
  25707. */
  25708. this._currentTime=0;
  25709. /**
  25710. *当前音量
  25711. */
  25712. this._volume=1;
  25713. /**
  25714. *播放开始时的时间戳
  25715. */
  25716. this._startTime=0;
  25717. this._pauseTime=0;
  25718. this._onPlayEnd=null;
  25719. this.context=WebAudioSound.ctx;
  25720. WebAudioSoundChannel.__super.call(this);
  25721. this._onPlayEnd=Utils.bind(this.__onPlayEnd,this);
  25722. if (this.context["createGain"]){
  25723. this.gain=this.context["createGain"]();
  25724. }else {
  25725. this.gain=this.context["createGainNode"]();
  25726. }
  25727. }
  25728. __class(WebAudioSoundChannel,'laya.media.webaudio.WebAudioSoundChannel',_super);
  25729. var __proto=WebAudioSoundChannel.prototype;
  25730. /**
  25731. *播放声音
  25732. */
  25733. __proto.play=function(){
  25734. SoundManager.addChannel(this);
  25735. this.isStopped=false;
  25736. this._clearBufferSource();
  25737. if (!this.audioBuffer)return;
  25738. if (this.startTime >=this.duration)return this.stop();
  25739. var context=this.context;
  25740. var gain=this.gain;
  25741. var bufferSource=context.createBufferSource();
  25742. this.bufferSource=bufferSource;
  25743. bufferSource.buffer=this.audioBuffer;
  25744. bufferSource.connect(gain);
  25745. if (gain)
  25746. gain.disconnect();
  25747. gain.connect(context.destination);
  25748. bufferSource.onended=this._onPlayEnd;
  25749. this._startTime=Browser.now();
  25750. if (this.gain.gain.setTargetAtTime){
  25751. this.gain.gain.setTargetAtTime(this._volume,this.context.currentTime,0.001);
  25752. }else
  25753. this.gain.gain.value=this._volume;
  25754. if (this.loops==0){
  25755. bufferSource.loop=true;
  25756. }
  25757. if (bufferSource.playbackRate.setTargetAtTime){
  25758. bufferSource.playbackRate.setTargetAtTime(SoundManager.playbackRate,this.context.currentTime,0.001)
  25759. }else
  25760. bufferSource.playbackRate.value=SoundManager.playbackRate;
  25761. bufferSource.start(0,this.startTime);
  25762. this._currentTime=0;
  25763. }
  25764. __proto.__onPlayEnd=function(){
  25765. if (this.loops==1){
  25766. if (this.completeHandler){
  25767. Laya.timer.once(10,this,this.__runComplete,[this.completeHandler],false);
  25768. this.completeHandler=null;
  25769. }
  25770. this.stop();
  25771. this.event(/*laya.events.Event.COMPLETE*/"complete");
  25772. return;
  25773. }
  25774. if (this.loops > 0){
  25775. this.loops--;
  25776. }
  25777. this.startTime=0;
  25778. this.play();
  25779. }
  25780. __proto._clearBufferSource=function(){
  25781. if (this.bufferSource){
  25782. var sourceNode=this.bufferSource;
  25783. if (sourceNode.stop){
  25784. sourceNode.stop(0);
  25785. }else {
  25786. sourceNode.noteOff(0);
  25787. }
  25788. sourceNode.disconnect(0);
  25789. sourceNode.onended=null;
  25790. if (!WebAudioSoundChannel._tryCleanFailed)this._tryClearBuffer(sourceNode);
  25791. this.bufferSource=null;
  25792. }
  25793. }
  25794. __proto._tryClearBuffer=function(sourceNode){
  25795. if (!Browser.onMac){
  25796. try{
  25797. sourceNode.buffer=null;
  25798. }catch (e){
  25799. WebAudioSoundChannel._tryCleanFailed=true;
  25800. }
  25801. return;
  25802. }
  25803. try {sourceNode.buffer=WebAudioSound._miniBuffer;}catch (e){WebAudioSoundChannel._tryCleanFailed=true;}
  25804. }
  25805. /**
  25806. *停止播放
  25807. */
  25808. __proto.stop=function(){
  25809. _super.prototype.stop.call(this);
  25810. this._clearBufferSource();
  25811. this.audioBuffer=null;
  25812. if (this.gain)
  25813. this.gain.disconnect();
  25814. this.isStopped=true;
  25815. SoundManager.removeChannel(this);
  25816. this.completeHandler=null;
  25817. if (SoundManager.autoReleaseSound)
  25818. SoundManager.disposeSoundLater(this.url);
  25819. }
  25820. __proto.pause=function(){
  25821. if (!this.isStopped){
  25822. this._pauseTime=this.position;
  25823. }
  25824. this._clearBufferSource();
  25825. if (this.gain)
  25826. this.gain.disconnect();
  25827. this.isStopped=true;
  25828. SoundManager.removeChannel(this);
  25829. if (SoundManager.autoReleaseSound)
  25830. SoundManager.disposeSoundLater(this.url);
  25831. }
  25832. __proto.resume=function(){
  25833. this.startTime=this._pauseTime;
  25834. this.play();
  25835. }
  25836. /**
  25837. *获取当前播放位置
  25838. */
  25839. __getset(0,__proto,'position',function(){
  25840. if (this.bufferSource){
  25841. return (Browser.now()-this._startTime)/ 1000+this.startTime;
  25842. }
  25843. return 0;
  25844. });
  25845. __getset(0,__proto,'duration',function(){
  25846. if (this.audioBuffer){
  25847. return this.audioBuffer.duration;
  25848. }
  25849. return 0;
  25850. });
  25851. /**
  25852. *设置音量
  25853. */
  25854. /**
  25855. *获取音量
  25856. */
  25857. __getset(0,__proto,'volume',function(){
  25858. return this._volume;
  25859. },function(v){
  25860. this._volume=v;
  25861. if (this.isStopped){
  25862. return;
  25863. }
  25864. if (this.gain.gain.setTargetAtTime){
  25865. this.gain.gain.setTargetAtTime(v,this.context.currentTime,0.001);
  25866. }else
  25867. this.gain.gain.value=v;
  25868. });
  25869. WebAudioSoundChannel._tryCleanFailed=false;
  25870. WebAudioSoundChannel.SetTargetDelay=0.001;
  25871. return WebAudioSoundChannel;
  25872. })(SoundChannel)
  25873. /**
  25874. *...
  25875. *@author ...
  25876. */
  25877. //class laya.webgl.shader.BaseShader extends laya.resource.Resource
  25878. var BaseShader=(function(_super){
  25879. //当前绑定的shader
  25880. function BaseShader(){
  25881. BaseShader.__super.call(this);
  25882. }
  25883. __class(BaseShader,'laya.webgl.shader.BaseShader',_super);
  25884. BaseShader.activeShader=null;
  25885. BaseShader.bindShader=null;
  25886. return BaseShader;
  25887. })(Resource)
  25888. //class laya.webgl.utils.IndexBuffer2D extends laya.webgl.utils.Buffer2D
  25889. var IndexBuffer2D=(function(_super){
  25890. function IndexBuffer2D(bufferUsage){
  25891. this._uint16Array=null;
  25892. (bufferUsage===void 0)&& (bufferUsage=0x88e4);
  25893. IndexBuffer2D.__super.call(this);
  25894. this._bufferUsage=bufferUsage;
  25895. this._bufferType=/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893;
  25896. this._buffer=new ArrayBuffer(8);
  25897. }
  25898. __class(IndexBuffer2D,'laya.webgl.utils.IndexBuffer2D',_super);
  25899. var __proto=IndexBuffer2D.prototype;
  25900. __proto._checkArrayUse=function(){
  25901. this._uint16Array && (this._uint16Array=new Uint16Array(this._buffer));
  25902. }
  25903. __proto.getUint16Array=function(){
  25904. return this._uint16Array || (this._uint16Array=new Uint16Array(this._buffer));
  25905. }
  25906. /**
  25907. *@inheritDoc
  25908. */
  25909. __proto._bindForVAO=function(){
  25910. LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893,this._glBuffer);
  25911. }
  25912. /**
  25913. *@inheritDoc
  25914. */
  25915. __proto.bind=function(){
  25916. if (Buffer._bindedIndexBuffer!==this._glBuffer){
  25917. LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893,this._glBuffer);
  25918. Buffer._bindedIndexBuffer=this._glBuffer;
  25919. return true;
  25920. }
  25921. return false;
  25922. }
  25923. __proto.destory=function(){
  25924. this._uint16Array=null;
  25925. this._buffer=null;
  25926. }
  25927. __proto.disposeResource=function(){
  25928. this._disposeResource();
  25929. }
  25930. IndexBuffer2D.create=function(bufferUsage){
  25931. (bufferUsage===void 0)&& (bufferUsage=0x88e4);
  25932. return new IndexBuffer2D(bufferUsage);
  25933. }
  25934. return IndexBuffer2D;
  25935. })(Buffer2D)
  25936. //class laya.webgl.utils.VertexBuffer2D extends laya.webgl.utils.Buffer2D
  25937. var VertexBuffer2D=(function(_super){
  25938. function VertexBuffer2D(vertexStride,bufferUsage){
  25939. this._floatArray32=null;
  25940. this._uint32Array=null;
  25941. this._vertexStride=0;
  25942. VertexBuffer2D.__super.call(this);
  25943. this._vertexStride=vertexStride;
  25944. this._bufferUsage=bufferUsage;
  25945. this._bufferType=/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892;
  25946. this._buffer=new ArrayBuffer(8);
  25947. this._floatArray32=new Float32Array(this._buffer);
  25948. this._uint32Array=new Uint32Array(this._buffer);
  25949. }
  25950. __class(VertexBuffer2D,'laya.webgl.utils.VertexBuffer2D',_super);
  25951. var __proto=VertexBuffer2D.prototype;
  25952. __proto.getFloat32Array=function(){
  25953. return this._floatArray32;
  25954. }
  25955. /**
  25956. *在当前位置插入float数组。
  25957. *@param data
  25958. *@param pos
  25959. */
  25960. __proto.appendArray=function(data){
  25961. var oldoff=this._byteLength >> 2;
  25962. this.setByteLength(this._byteLength+data.length *4);
  25963. var vbdata=this.getFloat32Array();
  25964. vbdata.set(data,oldoff);
  25965. this._upload=true;
  25966. }
  25967. __proto._checkArrayUse=function(){
  25968. this._floatArray32 && (this._floatArray32=new Float32Array(this._buffer));
  25969. this._uint32Array && (this._uint32Array=new Uint32Array(this._buffer));
  25970. }
  25971. //只删除buffer,不disableVertexAttribArray
  25972. __proto.deleteBuffer=function(){
  25973. this._disposeResource();
  25974. }
  25975. /**
  25976. *@inheritDoc
  25977. */
  25978. __proto._bindForVAO=function(){
  25979. LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892,this._glBuffer);
  25980. }
  25981. /**
  25982. *@inheritDoc
  25983. */
  25984. __proto.bind=function(){
  25985. if (Buffer._bindedVertexBuffer!==this._glBuffer){
  25986. LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892,this._glBuffer);
  25987. Buffer._bindedVertexBuffer=this._glBuffer;
  25988. return true;
  25989. }
  25990. return false;
  25991. }
  25992. __proto.destroy=function(){
  25993. laya.webgl.utils.Buffer.prototype.destroy.call(this);
  25994. this._byteLength=0;
  25995. this._upload=true;
  25996. this._buffer=null;
  25997. this._floatArray32=null;
  25998. }
  25999. __getset(0,__proto,'vertexStride',function(){
  26000. return this._vertexStride;
  26001. });
  26002. VertexBuffer2D.create=function(vertexStride,bufferUsage){
  26003. (bufferUsage===void 0)&& (bufferUsage=0x88e8);
  26004. return new VertexBuffer2D(vertexStride,bufferUsage);
  26005. }
  26006. return VertexBuffer2D;
  26007. })(Buffer2D)
  26008. /**
  26009. *@private
  26010. *<code>Bitmap</code> 图片资源类。
  26011. */
  26012. //class laya.resource.Bitmap extends laya.resource.Resource
  26013. var Bitmap=(function(_super){
  26014. function Bitmap(){
  26015. /**@private */
  26016. //this._width=0;
  26017. /**@private */
  26018. //this._height=0;
  26019. Bitmap.__super.call(this);
  26020. this._width=-1;
  26021. this._height=-1;
  26022. }
  26023. __class(Bitmap,'laya.resource.Bitmap',_super);
  26024. var __proto=Bitmap.prototype;
  26025. //TODO:coverage
  26026. __proto._getSource=function(){
  26027. throw "Bitmap: must override it.";
  26028. }
  26029. /**
  26030. */
  26031. /**
  26032. *获取宽度。
  26033. */
  26034. __getset(0,__proto,'width',function(){
  26035. return this._width;
  26036. },function(value){
  26037. this._width=value;
  26038. });
  26039. /**
  26040. */
  26041. /***
  26042. *获取高度。
  26043. */
  26044. __getset(0,__proto,'height',function(){
  26045. return this._height;
  26046. },function(value){
  26047. this._height=value;
  26048. });
  26049. return Bitmap;
  26050. })(Resource)
  26051. //class laya.webgl.text.TextTexture extends laya.resource.Resource
  26052. var TextTexture=(function(_super){
  26053. function TextTexture(textureW,textureH){
  26054. this._source=null;
  26055. // webgl 贴图
  26056. this._texW=0;
  26057. this._texH=0;
  26058. this.__destroyed=false;
  26059. //父类有,但是private
  26060. this._discardTm=0;
  26061. //释放的时间。超过一定时间会被真正删除
  26062. this.genID=0;
  26063. // 这个对象会重新利用,为了能让引用他的人知道自己引用的是否有效,加个id
  26064. this.bitmap={id:0,_glTexture:null};
  26065. //samekey的判断用的
  26066. this.curUsedCovRate=0;
  26067. // 当前使用到的使用率。根据面积算的
  26068. this.curUsedCovRateAtlas=0;
  26069. // 大图集中的占用率。由于大图集分辨率低,所以会浪费一些空间
  26070. this.lastTouchTm=0;
  26071. this.ri=null;
  26072. TextTexture.__super.call(this);
  26073. this._texW=textureW || TextRender.atlasWidth;
  26074. this._texH=textureH || TextRender.atlasWidth;
  26075. this.bitmap.id=this.id;
  26076. this.lock=true;
  26077. }
  26078. __class(TextTexture,'laya.webgl.text.TextTexture',_super);
  26079. var __proto=TextTexture.prototype;
  26080. //防止被资源管理清除
  26081. __proto.recreateResource=function(){
  26082. if (this._source)
  26083. return;
  26084. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  26085. var glTex=this._source=gl.createTexture();
  26086. this.bitmap._glTexture=glTex;
  26087. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,glTex);
  26088. gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,this._texW,this._texH,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,null);
  26089. gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  26090. gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_MAG_FILTER*/0x2800,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  26091. gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
  26092. gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
  26093. if (TextRender.debugUV){
  26094. this.fillWhite();
  26095. }
  26096. }
  26097. /**
  26098. *
  26099. *@param data
  26100. *@param x 拷贝位置。
  26101. *@param y
  26102. *@param uv
  26103. *@return uv数组 如果uv不为空就返回传入的uv,否则new一个数组
  26104. */
  26105. __proto.addChar=function(data,x,y,uv){
  26106. if(TextRender.isWan1Wan){
  26107. return this.addCharCanvas(data ,x,y,uv);
  26108. }
  26109. !this._source && this.recreateResource();
  26110. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  26111. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,this._source);
  26112. !Render.isConchApp && gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,true);
  26113. var dt=data.data;
  26114. if (/*__JS__ */data.data instanceof Uint8ClampedArray)
  26115. dt=new Uint8Array(dt.buffer);
  26116. gl.texSubImage2D(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,0,x,y,data.width,data.height,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,dt);
  26117. !Render.isConchApp && gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,false);
  26118. var u0=NaN;
  26119. var v0=NaN;
  26120. var u1=NaN;
  26121. var v1=NaN;
  26122. if(Render.isConchApp){
  26123. u0=x / this._texW;
  26124. v0=y / this._texH;
  26125. u1=(x+data.width)/ this._texW;
  26126. v1=(y+data.height)/ this._texH;
  26127. }else{
  26128. u0=(x+1)/ this._texW;
  26129. v0=(y)/ this._texH;
  26130. u1=(x+data.width-1)/ this._texW;
  26131. v1=(y+data.height-1)/ this._texH;
  26132. }
  26133. uv=uv || new Array(8);
  26134. uv[0]=u0,uv[1]=v0;
  26135. uv[2]=u1,uv[3]=v0;
  26136. uv[4]=u1,uv[5]=v1;
  26137. uv[6]=u0,uv[7]=v1;
  26138. return uv;
  26139. }
  26140. /**
  26141. *玩一玩不支持 getImageData
  26142. *@param canv
  26143. *@param x
  26144. *@param y
  26145. */
  26146. __proto.addCharCanvas=function(canv,x,y,uv){
  26147. !this._source && this.recreateResource();
  26148. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  26149. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,this._source);
  26150. !Render.isConchApp && gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,true);
  26151. gl.texSubImage2D(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,0,x,y,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,canv);
  26152. !Render.isConchApp && gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,false);
  26153. var u0=NaN;
  26154. var v0=NaN;
  26155. var u1=NaN;
  26156. var v1=NaN;
  26157. if(Render.isConchApp){
  26158. u0=x / this._texW;
  26159. v0=y / this._texH;
  26160. u1=(x+canv.width)/ this._texW;
  26161. v1=(y+canv.height)/ this._texH;
  26162. }else{
  26163. u0=(x+1)/ this._texW;
  26164. v0=(y+1)/ this._texH;
  26165. u1=(x+canv.width-1)/ this._texW;
  26166. v1=(y+canv.height-1)/ this._texH;
  26167. }
  26168. uv=uv || new Array(8);
  26169. uv[0]=u0,uv[1]=v0;
  26170. uv[2]=u1,uv[3]=v0;
  26171. uv[4]=u1,uv[5]=v1;
  26172. uv[6]=u0,uv[7]=v1;
  26173. return uv;
  26174. }
  26175. /**
  26176. *填充白色。调试用。
  26177. */
  26178. __proto.fillWhite=function(){
  26179. !this._source && this.recreateResource();
  26180. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  26181. var dt=new Uint8Array(this._texW *this._texH *4);
  26182. (dt).fill(0xff);
  26183. gl.texSubImage2D(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,0,0,0,this._texW,this._texH,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,dt);
  26184. }
  26185. __proto.discard=function(){
  26186. if (this._texW !=TextRender.atlasWidth || this._texH !=TextRender.atlasWidth){
  26187. this.destroy();
  26188. return;
  26189. }
  26190. this.genID++;
  26191. if (TextTexture.poolLen >=TextTexture.pool.length){
  26192. TextTexture.pool=TextTexture.pool.concat(new Array(10));
  26193. }
  26194. this._discardTm=Laya.stage.getFrameTm();
  26195. TextTexture.pool[TextTexture.poolLen++]=this;
  26196. }
  26197. __proto.destroy=function(){
  26198. this.__destroyed=true;
  26199. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  26200. this._source && gl.deleteTexture(this._source);
  26201. this._source=null;
  26202. }
  26203. __proto.touchRect=function(ri,curloop){
  26204. if (this.lastTouchTm !=curloop){
  26205. this.curUsedCovRate=0;
  26206. this.curUsedCovRateAtlas=0;
  26207. this.lastTouchTm=curloop;
  26208. };
  26209. var texw2=TextRender.atlasWidth *TextRender.atlasWidth;
  26210. var gridw2=TextAtlas.atlasGridW *TextAtlas.atlasGridW;
  26211. this.curUsedCovRate+=(ri.bmpWidth *ri.bmpHeight)/ texw2;
  26212. this.curUsedCovRateAtlas+=(Math.ceil(ri.bmpWidth / TextAtlas.atlasGridW)*Math.ceil(ri.bmpHeight / TextAtlas.atlasGridW))/ (texw2 / gridw2);
  26213. }
  26214. __proto._getSource=function(){
  26215. return this._source;
  26216. }
  26217. // for debug
  26218. __proto.drawOnScreen=function(x,y){}
  26219. // 为了与当前的文字渲染兼容的补丁
  26220. __getset(0,__proto,'texture',function(){
  26221. return this;
  26222. });
  26223. TextTexture.getTextTexture=function(w,h){
  26224. if (w !=TextRender.atlasWidth || w !=TextRender.atlasWidth)
  26225. return new TextTexture(w,h);
  26226. if (TextTexture.poolLen > 0){
  26227. var ret=TextTexture.pool[--TextTexture.poolLen];
  26228. if (TextTexture.poolLen > 0)
  26229. TextTexture.clean();
  26230. return ret;
  26231. }
  26232. return new TextTexture(w,h);
  26233. }
  26234. TextTexture.clean=function(){
  26235. var curtm=Laya.stage.getFrameTm();
  26236. if (TextTexture.cleanTm===0)TextTexture.cleanTm=curtm;
  26237. if (curtm-TextTexture.cleanTm >=TextRender.checkCleanTextureDt){
  26238. for (var i=0;i < TextTexture.poolLen;i++){
  26239. var p=TextTexture.pool[i];
  26240. if (curtm-p._discardTm >=TextRender.destroyUnusedTextureDt){
  26241. p.destroy();
  26242. TextTexture.pool[i]=TextTexture.pool[TextTexture.poolLen-1];
  26243. TextTexture.poolLen--;
  26244. i--;
  26245. }
  26246. }
  26247. TextTexture.cleanTm=curtm;
  26248. }
  26249. }
  26250. TextTexture.poolLen=0;
  26251. TextTexture.cleanTm=0;
  26252. __static(TextTexture,
  26253. ['pool',function(){return this.pool=new Array(10);}
  26254. ]);
  26255. return TextTexture;
  26256. })(Resource)
  26257. /**
  26258. *<p>动画基类,提供了基础的动画播放控制方法和帧标签事件相关功能。</p>
  26259. *<p>可以继承此类,但不要直接实例化此类,因为有些方法需要由子类实现。</p>
  26260. */
  26261. //class laya.display.AnimationBase extends laya.display.Sprite
  26262. var AnimationBase=(function(_super){
  26263. function AnimationBase(){
  26264. /**是否循环播放,调用play(...)方法时,会将此值设置为指定的参数值。*/
  26265. this.loop=false;
  26266. /**播放顺序类型:AnimationBase.WRAP_POSITIVE为正序播放(默认值),AnimationBase.WRAP_REVERSE为倒序播放,AnimationBase.WRAP_PINGPONG为pingpong播放(当按指定顺序播放完结尾后,如果继续播发,则会改变播放顺序)。*/
  26267. this.wrapMode=0;
  26268. /**@private */
  26269. this._index=0;
  26270. /**@private */
  26271. this._count=0;
  26272. /**@private */
  26273. this._isPlaying=false;
  26274. /**@private */
  26275. this._labels=null;
  26276. /**是否是逆序播放*/
  26277. this._isReverse=false;
  26278. /**@private */
  26279. this._frameRateChanged=false;
  26280. /**@private */
  26281. this._actionName=null;
  26282. /**@private */
  26283. this._controlNode=null;
  26284. AnimationBase.__super.call(this);
  26285. this._interval=Config.animationInterval;
  26286. this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  26287. }
  26288. __class(AnimationBase,'laya.display.AnimationBase',_super);
  26289. var __proto=AnimationBase.prototype;
  26290. /**
  26291. *<p>开始播放动画。play(...)方法被设计为在创建实例后的任何时候都可以被调用,当相应的资源加载完毕、调用动画帧填充方法(set frames)或者将实例显示在舞台上时,会判断是否正在播放中,如果是,则进行播放。</p>
  26292. *<p>配合wrapMode属性,可设置动画播放顺序类型。</p>
  26293. *@param start (可选)指定动画播放开始的索引(int)或帧标签(String)。帧标签可以通过addLabel(...)和removeLabel(...)进行添加和删除。
  26294. *@param loop (可选)是否循环播放。
  26295. *@param name (可选)动画名称。
  26296. */
  26297. __proto.play=function(start,loop,name){
  26298. (start===void 0)&& (start=0);
  26299. (loop===void 0)&& (loop=true);
  26300. (name===void 0)&& (name="");
  26301. this._isPlaying=true;
  26302. this._actionName=name;
  26303. this.index=((typeof start=='string'))? this._getFrameByLabel(start):start;
  26304. this.loop=loop;
  26305. this._isReverse=this.wrapMode===1;
  26306. if (this.index==0 && this._isReverse){
  26307. this.index=this.count-1;
  26308. }
  26309. if (this.interval > 0)this.timerLoop(this.interval,this,this._frameLoop,null,true,true);
  26310. }
  26311. /**@private */
  26312. __proto._getFrameByLabel=function(label){
  26313. for (var i=0;i < this._count;i++){
  26314. var item=this._labels[i];
  26315. if (item && (item).indexOf(label)>-1)return i;
  26316. }
  26317. return 0;
  26318. }
  26319. /**@private */
  26320. __proto._frameLoop=function(){
  26321. if (this._isReverse){
  26322. this._index--;
  26323. if (this._index < 0){
  26324. if (this.loop){
  26325. if (this.wrapMode==2){
  26326. this._index=this._count > 0 ? 1 :0;
  26327. this._isReverse=false;
  26328. }else {
  26329. this._index=this._count-1;
  26330. }
  26331. this.event(/*laya.events.Event.COMPLETE*/"complete");
  26332. }else {
  26333. this._index=0;
  26334. this.stop();
  26335. this.event(/*laya.events.Event.COMPLETE*/"complete");
  26336. return;
  26337. }
  26338. }
  26339. }else {
  26340. this._index++;
  26341. if (this._index >=this._count){
  26342. if (this.loop){
  26343. if (this.wrapMode==2){
  26344. this._index=this._count-2 >=0 ? this._count-2 :0;
  26345. this._isReverse=true;
  26346. }else {
  26347. this._index=0;
  26348. }
  26349. this.event(/*laya.events.Event.COMPLETE*/"complete");
  26350. }else {
  26351. this._index--;
  26352. this.stop();
  26353. this.event(/*laya.events.Event.COMPLETE*/"complete");
  26354. return;
  26355. }
  26356. }
  26357. }
  26358. this.index=this._index;
  26359. }
  26360. /**@private */
  26361. __proto._setControlNode=function(node){
  26362. if (this._controlNode){
  26363. this._controlNode.off(/*laya.events.Event.DISPLAY*/"display",this,this._resumePlay);
  26364. this._controlNode.off(/*laya.events.Event.UNDISPLAY*/"undisplay",this,this._resumePlay);
  26365. }
  26366. this._controlNode=node;
  26367. if (node && node !=this){
  26368. node.on(/*laya.events.Event.DISPLAY*/"display",this,this._resumePlay);
  26369. node.on(/*laya.events.Event.UNDISPLAY*/"undisplay",this,this._resumePlay);
  26370. }
  26371. }
  26372. /**@private */
  26373. __proto._setDisplay=function(value){
  26374. _super.prototype._setDisplay.call(this,value);
  26375. this._resumePlay();
  26376. }
  26377. /**@private */
  26378. __proto._resumePlay=function(){
  26379. if (this._isPlaying){
  26380. if (this._controlNode.displayedInStage)this.play(this._index,this.loop,this._actionName);
  26381. else this.clearTimer(this,this._frameLoop);
  26382. }
  26383. }
  26384. /**
  26385. *停止动画播放。
  26386. */
  26387. __proto.stop=function(){
  26388. this._isPlaying=false;
  26389. this.clearTimer(this,this._frameLoop);
  26390. }
  26391. /**
  26392. *增加一个帧标签到指定索引的帧上。当动画播放到此索引的帧时会派发Event.LABEL事件,派发事件是在完成当前帧画面更新之后。
  26393. *@param label 帧标签名称
  26394. *@param index 帧索引
  26395. */
  26396. __proto.addLabel=function(label,index){
  26397. if (!this._labels)this._labels={};
  26398. if (!this._labels[index])this._labels[index]=[];
  26399. this._labels[index].push(label);
  26400. }
  26401. /**
  26402. *删除指定的帧标签。
  26403. *@param label 帧标签名称。注意:如果为空,则删除所有帧标签!
  26404. */
  26405. __proto.removeLabel=function(label){
  26406. if (!label)this._labels=null;
  26407. else if (this._labels){
  26408. for (var name in this._labels){
  26409. this._removeLabelFromList(this._labels[name],label);
  26410. }
  26411. }
  26412. }
  26413. /**@private */
  26414. __proto._removeLabelFromList=function(list,label){
  26415. if (!list)return;
  26416. for (var i=list.length-1;i >=0;i--){
  26417. if (list[i]==label){
  26418. list.splice(i,1);
  26419. }
  26420. }
  26421. }
  26422. /**
  26423. *将动画切换到指定帧并停在那里。
  26424. *@param position 帧索引或帧标签
  26425. */
  26426. __proto.gotoAndStop=function(position){
  26427. this.index=((typeof position=='string'))? this._getFrameByLabel(position):position;
  26428. this.stop();
  26429. }
  26430. /**
  26431. *@private
  26432. *显示到某帧
  26433. *@param value 帧索引
  26434. */
  26435. __proto._displayToIndex=function(value){}
  26436. /**
  26437. *停止动画播放,并清理对象属性。之后可存入对象池,方便对象复用。
  26438. *@return 返回对象本身
  26439. */
  26440. __proto.clear=function(){
  26441. this.stop();
  26442. this._labels=null;
  26443. return this;
  26444. }
  26445. /**
  26446. *<p>动画播放的帧间隔时间(单位:毫秒)。默认值依赖于Config.animationInterval=50,通过Config.animationInterval可以修改默认帧间隔时间。</p>
  26447. *<p>要想为某动画设置独立的帧间隔时间,可以使用set interval,注意:如果动画正在播放,设置后会重置帧循环定时器的起始时间为当前时间,也就是说,如果频繁设置interval,会导致动画帧更新的时间间隔会比预想的要慢,甚至不更新。</p>
  26448. */
  26449. __getset(0,__proto,'interval',function(){
  26450. return this._interval;
  26451. },function(value){
  26452. if (this._interval !=value){
  26453. this._frameRateChanged=true;
  26454. this._interval=value;
  26455. if (this._isPlaying && value > 0){
  26456. this.timerLoop(value,this,this._frameLoop,null,true,true);
  26457. }
  26458. }
  26459. });
  26460. /**
  26461. *是否正在播放中。
  26462. */
  26463. __getset(0,__proto,'isPlaying',function(){
  26464. return this._isPlaying;
  26465. });
  26466. /**
  26467. *动画当前帧的索引。
  26468. */
  26469. __getset(0,__proto,'index',function(){
  26470. return this._index;
  26471. },function(value){
  26472. this._index=value;
  26473. this._displayToIndex(value);
  26474. if (this._labels && this._labels[value]){
  26475. var tArr=this._labels[value];
  26476. for (var i=0,len=tArr.length;i < len;i++){
  26477. this.event(/*laya.events.Event.LABEL*/"label",tArr[i]);
  26478. }
  26479. }
  26480. });
  26481. /**
  26482. *当前动画中帧的总数。
  26483. */
  26484. __getset(0,__proto,'count',function(){
  26485. return this._count;
  26486. });
  26487. AnimationBase.WRAP_POSITIVE=0;
  26488. AnimationBase.WRAP_REVERSE=1;
  26489. AnimationBase.WRAP_PINGPONG=2;
  26490. return AnimationBase;
  26491. })(Sprite)
  26492. //class laya.webgl.shader.Shader extends laya.webgl.shader.BaseShader
  26493. var Shader=(function(_super){
  26494. function Shader(vs,ps,saveName,nameMap,bindAttrib){
  26495. //存储预编译结果,可以通过名字获得内容,目前不支持#ifdef嵌套和条件
  26496. this._attribInfo=null;
  26497. this.customCompile=false;
  26498. //this._nameMap=null;
  26499. //shader参数别名,语义
  26500. //this._vs=null;
  26501. //this._ps=null;
  26502. this._curActTexIndex=0;
  26503. //this._reCompile=false;
  26504. //存储一些私有变量
  26505. this.tag={};
  26506. //this._vshader=null;
  26507. //this._pshader=null;
  26508. this._program=null;
  26509. this._params=null;
  26510. this._paramsMap={};
  26511. Shader.__super.call(this);
  26512. if ((!vs)|| (!ps))throw "Shader Error";
  26513. this._attribInfo=bindAttrib;
  26514. this._id=++Shader._count;
  26515. this._vs=vs;
  26516. this._ps=ps;
  26517. this._nameMap=nameMap ? nameMap :{};
  26518. saveName !=null && (Shader.sharders[saveName]=this);
  26519. this.recreateResource();
  26520. this.lock=true;
  26521. }
  26522. __class(Shader,'laya.webgl.shader.Shader',_super);
  26523. var __proto=Shader.prototype;
  26524. __proto.recreateResource=function(){
  26525. this._compile();
  26526. this._setGPUMemory(0);
  26527. }
  26528. //TODO:coverage
  26529. __proto._disposeResource=function(){
  26530. WebGL.mainContext.deleteShader(this._vshader);
  26531. WebGL.mainContext.deleteShader(this._pshader);
  26532. WebGL.mainContext.deleteProgram(this._program);
  26533. this._vshader=this._pshader=this._program=null;
  26534. this._params=null;
  26535. this._paramsMap={};
  26536. this._setGPUMemory(0);
  26537. this._curActTexIndex=0;
  26538. }
  26539. __proto._compile=function(){
  26540. if (!this._vs || !this._ps || this._params)
  26541. return;
  26542. this._reCompile=true;
  26543. this._params=[];
  26544. var result;
  26545. if (this.customCompile)
  26546. result=ShaderCompile.preGetParams(this._vs,this._ps);
  26547. var gl=WebGL.mainContext;
  26548. this._program=gl.createProgram();
  26549. this._vshader=Shader._createShader(gl,this._vs,/*laya.webgl.WebGLContext.VERTEX_SHADER*/0x8B31);
  26550. this._pshader=Shader._createShader(gl,this._ps,/*laya.webgl.WebGLContext.FRAGMENT_SHADER*/0x8B30);
  26551. gl.attachShader(this._program,this._vshader);
  26552. gl.attachShader(this._program,this._pshader);
  26553. var one,i=0,j=0,n=0,location;
  26554. var attribDescNum=this._attribInfo?this._attribInfo.length:0;
  26555. for (i=0;i < attribDescNum;i+=2){
  26556. gl.bindAttribLocation(this._program,this._attribInfo[i+1],this._attribInfo[i]);
  26557. }
  26558. gl.linkProgram(this._program);
  26559. if (!this.customCompile && !gl.getProgramParameter(this._program,/*laya.webgl.WebGLContext.LINK_STATUS*/0x8B82)){
  26560. throw gl.getProgramInfoLog(this._program);
  26561. };
  26562. var nUniformNum=this.customCompile ? result.uniforms.length :gl.getProgramParameter(this._program,/*laya.webgl.WebGLContext.ACTIVE_UNIFORMS*/0x8B86);
  26563. for (i=0;i < nUniformNum;i++){
  26564. var uniform=this.customCompile ? result.uniforms[i] :gl.getActiveUniform(this._program,i);
  26565. location=gl.getUniformLocation(this._program,uniform.name);
  26566. one={vartype:"uniform",glfun:null,ivartype:1,location:location,name:uniform.name,type:uniform.type,isArray:false,isSame:false,preValue:null,indexOfParams:0};
  26567. if (one.name.indexOf('[0]')> 0){
  26568. one.name=one.name.substr(0,one.name.length-3);
  26569. one.isArray=true;
  26570. one.location=gl.getUniformLocation(this._program,one.name);
  26571. }
  26572. this._params.push(one);
  26573. }
  26574. for (i=0,n=this._params.length;i < n;i++){
  26575. one=this._params[i];
  26576. one.indexOfParams=i;
  26577. one.index=1;
  26578. one.value=[one.location,null];
  26579. one.codename=one.name;
  26580. one.name=this._nameMap[one.codename] ? this._nameMap[one.codename] :one.codename;
  26581. this._paramsMap[one.name]=one;
  26582. one._this=this;
  26583. one.uploadedValue=[];
  26584. switch (one.type){
  26585. case /*laya.webgl.WebGLContext.INT*/0x1404:
  26586. one.fun=one.isArray ? this._uniform1iv :this._uniform1i;
  26587. break ;
  26588. case /*laya.webgl.WebGLContext.FLOAT*/0x1406:
  26589. one.fun=one.isArray ? this._uniform1fv :this._uniform1f;
  26590. break ;
  26591. case /*laya.webgl.WebGLContext.FLOAT_VEC2*/0x8B50:
  26592. one.fun=one.isArray ? this._uniform_vec2v:this._uniform_vec2;
  26593. break ;
  26594. case /*laya.webgl.WebGLContext.FLOAT_VEC3*/0x8B51:
  26595. one.fun=one.isArray ? this._uniform_vec3v:this._uniform_vec3;
  26596. break ;
  26597. case /*laya.webgl.WebGLContext.FLOAT_VEC4*/0x8B52:
  26598. one.fun=one.isArray ? this._uniform_vec4v:this._uniform_vec4;
  26599. break ;
  26600. case /*laya.webgl.WebGLContext.SAMPLER_2D*/0x8B5E:
  26601. one.fun=this._uniform_sampler2D;
  26602. break ;
  26603. case /*laya.webgl.WebGLContext.SAMPLER_CUBE*/0x8B60:
  26604. one.fun=this._uniform_samplerCube;
  26605. break ;
  26606. case /*laya.webgl.WebGLContext.FLOAT_MAT4*/0x8B5C:
  26607. one.glfun=gl.uniformMatrix4fv;
  26608. one.fun=this._uniformMatrix4fv;
  26609. break ;
  26610. case /*laya.webgl.WebGLContext.BOOL*/0x8B56:
  26611. one.fun=this._uniform1i;
  26612. break ;
  26613. case /*laya.webgl.WebGLContext.FLOAT_MAT2*/0x8B5A:
  26614. case /*laya.webgl.WebGLContext.FLOAT_MAT3*/0x8B5B:
  26615. throw new Error("compile shader err!");
  26616. default :
  26617. throw new Error("compile shader err!");
  26618. }
  26619. }
  26620. }
  26621. //TODO:coverage
  26622. __proto.getUniform=function(name){
  26623. return this._paramsMap[name];
  26624. }
  26625. //TODO:coverage
  26626. __proto._uniform1f=function(one,value){
  26627. var uploadedValue=one.uploadedValue;
  26628. if (uploadedValue[0]!==value){
  26629. WebGL.mainContext.uniform1f(one.location,uploadedValue[0]=value);
  26630. return 1;
  26631. }
  26632. return 0;
  26633. }
  26634. //TODO:coverage
  26635. __proto._uniform1fv=function(one,value){
  26636. if (value.length < 4){
  26637. var uploadedValue=one.uploadedValue;
  26638. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
  26639. WebGL.mainContext.uniform1fv(one.location,value);
  26640. uploadedValue[0]=value[0];
  26641. uploadedValue[1]=value[1];
  26642. uploadedValue[2]=value[2];
  26643. uploadedValue[3]=value[3];
  26644. return 1;
  26645. }
  26646. return 0;
  26647. }else {
  26648. WebGL.mainContext.uniform1fv(one.location,value);
  26649. return 1;
  26650. }
  26651. }
  26652. __proto._uniform_vec2=function(one,value){
  26653. var uploadedValue=one.uploadedValue;
  26654. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1]){
  26655. WebGL.mainContext.uniform2f(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1]);
  26656. return 1;
  26657. }
  26658. return 0;
  26659. }
  26660. //TODO:coverage
  26661. __proto._uniform_vec2v=function(one,value){
  26662. if (value.length < 2){
  26663. var uploadedValue=one.uploadedValue;
  26664. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
  26665. WebGL.mainContext.uniform2fv(one.location,value);
  26666. uploadedValue[0]=value[0];
  26667. uploadedValue[1]=value[1];
  26668. uploadedValue[2]=value[2];
  26669. uploadedValue[3]=value[3];
  26670. return 1;
  26671. }
  26672. return 0;
  26673. }else {
  26674. WebGL.mainContext.uniform2fv(one.location,value);
  26675. return 1;
  26676. }
  26677. }
  26678. //TODO:coverage
  26679. __proto._uniform_vec3=function(one,value){
  26680. var uploadedValue=one.uploadedValue;
  26681. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2]){
  26682. WebGL.mainContext.uniform3f(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2]);
  26683. return 1;
  26684. }
  26685. return 0;
  26686. }
  26687. //TODO:coverage
  26688. __proto._uniform_vec3v=function(one,value){
  26689. WebGL.mainContext.uniform3fv(one.location,value);
  26690. return 1;
  26691. }
  26692. __proto._uniform_vec4=function(one,value){
  26693. var uploadedValue=one.uploadedValue;
  26694. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
  26695. WebGL.mainContext.uniform4f(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2],uploadedValue[3]=value[3]);
  26696. return 1;
  26697. }
  26698. return 0;
  26699. }
  26700. //TODO:coverage
  26701. __proto._uniform_vec4v=function(one,value){
  26702. WebGL.mainContext.uniform4fv(one.location,value);
  26703. return 1;
  26704. }
  26705. //TODO:coverage
  26706. __proto._uniformMatrix2fv=function(one,value){
  26707. WebGL.mainContext.uniformMatrix2fv(one.location,false,value);
  26708. return 1;
  26709. }
  26710. //TODO:coverage
  26711. __proto._uniformMatrix3fv=function(one,value){
  26712. WebGL.mainContext.uniformMatrix3fv(one.location,false,value);
  26713. return 1;
  26714. }
  26715. __proto._uniformMatrix4fv=function(one,value){
  26716. WebGL.mainContext.uniformMatrix4fv(one.location,false,value);
  26717. return 1;
  26718. }
  26719. //TODO:coverage
  26720. __proto._uniform1i=function(one,value){
  26721. var uploadedValue=one.uploadedValue;
  26722. if (uploadedValue[0]!==value){
  26723. WebGL.mainContext.uniform1i(one.location,uploadedValue[0]=value);
  26724. return 1;
  26725. }
  26726. return 0;
  26727. }
  26728. //TODO:coverage
  26729. __proto._uniform1iv=function(one,value){
  26730. WebGL.mainContext.uniform1iv(one.location,value);
  26731. return 1;
  26732. }
  26733. //TODO:coverage
  26734. __proto._uniform_ivec2=function(one,value){
  26735. var uploadedValue=one.uploadedValue;
  26736. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1]){
  26737. WebGL.mainContext.uniform2i(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1]);
  26738. return 1;
  26739. }
  26740. return 0;
  26741. }
  26742. //TODO:coverage
  26743. __proto._uniform_ivec2v=function(one,value){
  26744. WebGL.mainContext.uniform2iv(one.location,value);
  26745. return 1;
  26746. }
  26747. //TODO:coverage
  26748. __proto._uniform_vec3i=function(one,value){
  26749. var uploadedValue=one.uploadedValue;
  26750. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2]){
  26751. WebGL.mainContext.uniform3i(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2]);
  26752. return 1;
  26753. }
  26754. return 0;
  26755. }
  26756. __proto._uniform_vec3vi=function(one,value){
  26757. WebGL.mainContext.uniform3iv(one.location,value);
  26758. return 1;
  26759. }
  26760. //TODO:coverage
  26761. __proto._uniform_vec4i=function(one,value){
  26762. var uploadedValue=one.uploadedValue;
  26763. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
  26764. WebGL.mainContext.uniform4i(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2],uploadedValue[3]=value[3]);
  26765. return 1;
  26766. }
  26767. return 0;
  26768. }
  26769. //TODO:coverage
  26770. __proto._uniform_vec4vi=function(one,value){
  26771. WebGL.mainContext.uniform4iv(one.location,value);
  26772. return 1;
  26773. }
  26774. __proto._uniform_sampler2D=function(one,value){
  26775. var gl=WebGL.mainContext;
  26776. var uploadedValue=one.uploadedValue;
  26777. if (uploadedValue[0]==null){
  26778. uploadedValue[0]=this._curActTexIndex;
  26779. gl.uniform1i(one.location,this._curActTexIndex);
  26780. WebGLContext.activeTexture(gl,/*laya.webgl.WebGLContext.TEXTURE0*/0x84C0+this._curActTexIndex);
  26781. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,value);
  26782. this._curActTexIndex++;
  26783. return 1;
  26784. }else {
  26785. WebGLContext.activeTexture(gl,/*laya.webgl.WebGLContext.TEXTURE0*/0x84C0+uploadedValue[0]);
  26786. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,value);
  26787. return 0;
  26788. }
  26789. }
  26790. //TODO:coverage
  26791. __proto._uniform_samplerCube=function(one,value){
  26792. var gl=WebGL.mainContext;
  26793. var uploadedValue=one.uploadedValue;
  26794. if (uploadedValue[0]==null){
  26795. uploadedValue[0]=this._curActTexIndex;
  26796. gl.uniform1i(one.location,this._curActTexIndex);
  26797. WebGLContext.activeTexture(gl,/*laya.webgl.WebGLContext.TEXTURE0*/0x84C0+this._curActTexIndex);
  26798. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP*/0x8513,value);
  26799. this._curActTexIndex++;
  26800. return 1;
  26801. }else {
  26802. WebGLContext.activeTexture(gl,/*laya.webgl.WebGLContext.TEXTURE0*/0x84C0+uploadedValue[0]);
  26803. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP*/0x8513,value);
  26804. return 0;
  26805. }
  26806. }
  26807. //TODO:coverage
  26808. __proto._noSetValue=function(one){
  26809. console.log("no....:"+one.name);
  26810. }
  26811. //TODO:coverage
  26812. __proto.uploadOne=function(name,value){
  26813. WebGLContext.useProgram(WebGL.mainContext,this._program);
  26814. var one=this._paramsMap[name];
  26815. one.fun.call(this,one,value);
  26816. }
  26817. __proto.uploadTexture2D=function(value){
  26818. var CTX=WebGLContext;
  26819. if(CTX._activeTextures[0]!==value){
  26820. CTX.bindTexture(WebGL.mainContext,CTX.TEXTURE_2D,value);
  26821. CTX._activeTextures[0]=value;
  26822. }
  26823. }
  26824. /**
  26825. *提交shader到GPU
  26826. *@param shaderValue
  26827. */
  26828. __proto.upload=function(shaderValue,params){
  26829. BaseShader.activeShader=BaseShader.bindShader=this;
  26830. var gl=WebGL.mainContext;
  26831. WebGLContext.useProgram(gl,this._program);
  26832. if (this._reCompile){
  26833. params=this._params;
  26834. this._reCompile=false;
  26835. }else {
  26836. params=params || this._params;
  26837. };
  26838. var one,value,n=params.length,shaderCall=0;
  26839. for (var i=0;i < n;i++){
  26840. one=params[i];
  26841. if ((value=shaderValue[one.name])!==null)
  26842. shaderCall+=one.fun.call(this,one,value);
  26843. }
  26844. Stat.shaderCall+=shaderCall;
  26845. }
  26846. //TODO:coverage
  26847. __proto.uploadArray=function(shaderValue,length,_bufferUsage){
  26848. BaseShader.activeShader=this;
  26849. BaseShader.bindShader=this;
  26850. WebGLContext.useProgram(WebGL.mainContext,this._program);
  26851. var params=this._params,value;
  26852. var one,shaderCall=0;
  26853. for (var i=length-2;i >=0;i-=2){
  26854. one=this._paramsMap[shaderValue[i]];
  26855. if (!one)
  26856. continue ;
  26857. value=shaderValue[i+1];
  26858. if (value !=null){
  26859. _bufferUsage && _bufferUsage[one.name] && _bufferUsage[one.name].bind();
  26860. shaderCall+=one.fun.call(this,one,value);
  26861. }
  26862. }
  26863. Stat.shaderCall+=shaderCall;
  26864. }
  26865. //TODO:coverage
  26866. __proto.getParams=function(){
  26867. return this._params;
  26868. }
  26869. //TODO:coverage
  26870. __proto.setAttributesLocation=function(attribDesc){
  26871. this._attribInfo=attribDesc;
  26872. }
  26873. Shader.getShader=function(name){
  26874. return Shader.sharders[name];
  26875. }
  26876. Shader.create=function(vs,ps,saveName,nameMap,bindAttrib){
  26877. return new Shader(vs,ps,saveName,nameMap,bindAttrib);
  26878. }
  26879. Shader.withCompile=function(nameID,define,shaderName,createShader){
  26880. if (shaderName && Shader.sharders[shaderName])
  26881. return Shader.sharders[shaderName];
  26882. var pre=Shader._preCompileShader[0.0002 *nameID];
  26883. if (!pre)
  26884. throw new Error("withCompile shader err!"+nameID);
  26885. return pre.createShader(define,shaderName,createShader,null);
  26886. }
  26887. Shader.withCompile2D=function(nameID,mainID,define,shaderName,createShader,bindAttrib){
  26888. if (shaderName && Shader.sharders[shaderName])
  26889. return Shader.sharders[shaderName];
  26890. var pre=Shader._preCompileShader[0.0002 *nameID+mainID];
  26891. if (!pre)
  26892. throw new Error("withCompile shader err!"+nameID+" "+mainID);
  26893. return pre.createShader(define,shaderName,createShader,bindAttrib);
  26894. }
  26895. Shader.addInclude=function(fileName,txt){
  26896. ShaderCompile.addInclude(fileName,txt);
  26897. }
  26898. Shader.preCompile=function(nameID,vs,ps,nameMap){
  26899. var id=0.0002 *nameID;
  26900. Shader._preCompileShader[id]=new ShaderCompile(vs,ps,nameMap);
  26901. }
  26902. Shader.preCompile2D=function(nameID,mainID,vs,ps,nameMap){
  26903. var id=0.0002 *nameID+mainID;
  26904. Shader._preCompileShader[id]=new ShaderCompile(vs,ps,nameMap);
  26905. }
  26906. Shader._createShader=function(gl,str,type){
  26907. var shader=gl.createShader(type);
  26908. gl.shaderSource(shader,str);
  26909. gl.compileShader(shader);
  26910. if(gl.getShaderParameter(shader,/*laya.webgl.WebGLContext.COMPILE_STATUS*/0x8B81)){
  26911. return shader;
  26912. }else{
  26913. console.log(gl.getShaderInfoLog(shader));
  26914. return null;
  26915. }
  26916. }
  26917. Shader._count=0;
  26918. Shader._preCompileShader={};
  26919. Shader.SHADERNAME2ID=0.0002;
  26920. Shader.sharders=new Array(0x20);
  26921. __static(Shader,
  26922. ['nameKey',function(){return this.nameKey=new StringKey();}
  26923. ]);
  26924. return Shader;
  26925. })(BaseShader)
  26926. /**
  26927. *@private
  26928. */
  26929. //class laya.media.SoundNode extends laya.display.Sprite
  26930. var SoundNode=(function(_super){
  26931. function SoundNode(){
  26932. this.url=null;
  26933. this._channel=null;
  26934. this._tar=null;
  26935. this._playEvents=null;
  26936. this._stopEvents=null;
  26937. SoundNode.__super.call(this);
  26938. this.visible=false;
  26939. this.on(/*laya.events.Event.ADDED*/"added",this,this._onParentChange);
  26940. this.on(/*laya.events.Event.REMOVED*/"removed",this,this._onParentChange);
  26941. }
  26942. __class(SoundNode,'laya.media.SoundNode',_super);
  26943. var __proto=SoundNode.prototype;
  26944. /**@private */
  26945. __proto._onParentChange=function(){
  26946. this.target=this.parent;
  26947. }
  26948. /**
  26949. *播放
  26950. *@param loops 循环次数
  26951. *@param complete 完成回调
  26952. *
  26953. */
  26954. __proto.play=function(loops,complete){
  26955. (loops===void 0)&& (loops=1);
  26956. if (isNaN(loops)){
  26957. loops=1;
  26958. }
  26959. if (!this.url)return;
  26960. this.stop();
  26961. this._channel=SoundManager.playSound(this.url,loops,complete);
  26962. }
  26963. /**
  26964. *停止播放
  26965. *
  26966. */
  26967. __proto.stop=function(){
  26968. if (this._channel && !this._channel.isStopped){
  26969. this._channel.stop();
  26970. }
  26971. this._channel=null;
  26972. }
  26973. /**@private */
  26974. __proto._setPlayAction=function(tar,event,action,add){
  26975. (add===void 0)&& (add=true);
  26976. if (!this[action])return;
  26977. if (!tar)return;
  26978. if (add){
  26979. tar.on(event,this,this[action]);
  26980. }else {
  26981. tar.off(event,this,this[action]);
  26982. }
  26983. }
  26984. /**@private */
  26985. __proto._setPlayActions=function(tar,events,action,add){
  26986. (add===void 0)&& (add=true);
  26987. if (!tar)return;
  26988. if (!events)return;
  26989. var eventArr=events.split(",");
  26990. var i=0,len=0;
  26991. len=eventArr.length;
  26992. for (i=0;i < len;i++){
  26993. this._setPlayAction(tar,eventArr[i],action,add);
  26994. }
  26995. }
  26996. /**
  26997. *设置触发播放的事件
  26998. *@param events
  26999. *
  27000. */
  27001. __getset(0,__proto,'playEvent',null,function(events){
  27002. this._playEvents=events;
  27003. if (!events)return;
  27004. if (this._tar){
  27005. this._setPlayActions(this._tar,events,"play");
  27006. }
  27007. });
  27008. /**
  27009. *设置控制播放的对象
  27010. *@param tar
  27011. *
  27012. */
  27013. __getset(0,__proto,'target',null,function(tar){
  27014. if (this._tar){
  27015. this._setPlayActions(this._tar,this._playEvents,"play",false);
  27016. this._setPlayActions(this._tar,this._stopEvents,"stop",false);
  27017. }
  27018. this._tar=tar;
  27019. if (this._tar){
  27020. this._setPlayActions(this._tar,this._playEvents,"play",true);
  27021. this._setPlayActions(this._tar,this._stopEvents,"stop",true);
  27022. }
  27023. });
  27024. /**
  27025. *设置触发停止的事件
  27026. *@param events
  27027. *
  27028. */
  27029. __getset(0,__proto,'stopEvent',null,function(events){
  27030. this._stopEvents=events;
  27031. if (!events)return;
  27032. if (this._tar){
  27033. this._setPlayActions(this._tar,events,"stop");
  27034. }
  27035. });
  27036. return SoundNode;
  27037. })(Sprite)
  27038. /**
  27039. *<p> <code>Stage</code> 是舞台类,显示列表的根节点,所有显示对象都在舞台上显示。通过 Laya.stage 单例访问。</p>
  27040. *<p>Stage提供几种适配模式,不同的适配模式会产生不同的画布大小,画布越大,渲染压力越大,所以要选择合适的适配方案。</p>
  27041. *<p>Stage提供不同的帧率模式,帧率越高,渲染压力越大,越费电,合理使用帧率甚至动态更改帧率有利于改进手机耗电。</p>
  27042. */
  27043. //class laya.display.Stage extends laya.display.Sprite
  27044. var Stage=(function(_super){
  27045. function Stage(){
  27046. /**当前焦点对象,此对象会影响当前键盘事件的派发主体。*/
  27047. this.focus=null;
  27048. /**帧率类型,支持三种模式:fast-60帧(默认),slow-30帧,mouse-30帧(鼠标活动后会自动加速到60,鼠标不动2秒后降低为30帧,以节省消耗),sleep-1帧。*/
  27049. this._frameRate="fast";
  27050. /**设计宽度(初始化时设置的宽度Laya.init(width,height))*/
  27051. this.designWidth=0;
  27052. /**设计高度(初始化时设置的高度Laya.init(width,height))*/
  27053. this.designHeight=0;
  27054. /**画布是否发生翻转。*/
  27055. this.canvasRotation=false;
  27056. /**画布的旋转角度。*/
  27057. this.canvasDegree=0;
  27058. /**
  27059. *<p>设置是否渲染,设置为false,可以停止渲染,画面会停留到最后一次渲染上,减少cpu消耗,此设置不影响时钟。</p>
  27060. *<p>比如非激活状态,可以设置renderingEnabled=false以节省消耗。</p>
  27061. **/
  27062. this.renderingEnabled=true;
  27063. /**是否启用屏幕适配,可以适配后,在某个时候关闭屏幕适配,防止某些操作导致的屏幕意外改变*/
  27064. this.screenAdaptationEnabled=true;
  27065. /**@private */
  27066. this._screenMode="none";
  27067. /**@private */
  27068. this._scaleMode="noscale";
  27069. /**@private */
  27070. this._alignV="top";
  27071. /**@private */
  27072. this._alignH="left";
  27073. /**@private */
  27074. this._bgColor="black";
  27075. /**@private */
  27076. this._mouseMoveTime=0;
  27077. /**@private */
  27078. this._renderCount=0;
  27079. /**@private */
  27080. this._safariOffsetY=0;
  27081. /**@private */
  27082. this._frameStartTime=0;
  27083. /**@private */
  27084. this._isFocused=false;
  27085. /**@private */
  27086. this._isVisibility=false;
  27087. /**@private webgl Color*/
  27088. this._wgColor=[0,0,0,1];
  27089. /**@private */
  27090. this._scene3Ds=[];
  27091. /**@private */
  27092. this._globalRepaintSet=false;
  27093. /**@private */
  27094. this._globalRepaintGet=false;
  27095. /**@private */
  27096. this._curUIBase=null;
  27097. /**使用物理分辨率作为canvas大小,会改进渲染效果,但是会降低性能*/
  27098. this.useRetinalCanvas=false;
  27099. Stage.__super.call(this);
  27100. this.offset=new Point();
  27101. this._canvasTransform=new Matrix();
  27102. this._previousOrientation=Browser.window.orientation;
  27103. this._3dUI=[];
  27104. var _$this=this;
  27105. this.transform=this._createTransform();
  27106. this.mouseEnabled=true;
  27107. this.hitTestPrior=true;
  27108. this.autoSize=false;
  27109. this._setBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80,true);
  27110. this._setBit(/*laya.Const.ACTIVE_INHIERARCHY*/0x02,true);
  27111. this._isFocused=true;
  27112. this._isVisibility=true;
  27113. this.useRetinalCanvas=Config.useRetinalCanvas;
  27114. var window=Browser.window;
  27115. var _me=this;
  27116. window.addEventListener("focus",function(){
  27117. _$this._isFocused=true;
  27118. _me.event(/*laya.events.Event.FOCUS*/"focus");
  27119. _me.event(/*laya.events.Event.FOCUS_CHANGE*/"focuschange");
  27120. });
  27121. window.addEventListener("blur",function(){
  27122. _$this._isFocused=false;
  27123. _me.event(/*laya.events.Event.BLUR*/"blur");
  27124. _me.event(/*laya.events.Event.FOCUS_CHANGE*/"focuschange");
  27125. if (_me._isInputting())Input["inputElement"].target.focus=false;
  27126. });
  27127. var hidden="hidden",state="visibilityState",visibilityChange="visibilitychange";
  27128. var document=window.document;
  27129. if (typeof document.hidden!=="undefined"){
  27130. visibilityChange="visibilitychange";
  27131. state="visibilityState";
  27132. }else if (typeof document.mozHidden!=="undefined"){
  27133. visibilityChange="mozvisibilitychange";
  27134. state="mozVisibilityState";
  27135. }else if (typeof document.msHidden!=="undefined"){
  27136. visibilityChange="msvisibilitychange";
  27137. state="msVisibilityState";
  27138. }else if (typeof document.webkitHidden!=="undefined"){
  27139. visibilityChange="webkitvisibilitychange";
  27140. state="webkitVisibilityState";
  27141. }
  27142. window.document.addEventListener(visibilityChange,visibleChangeFun);
  27143. function visibleChangeFun (){
  27144. if (Browser.document[state]=="hidden"){
  27145. _$this._isVisibility=false;
  27146. if (_me._isInputting())Input["inputElement"].target.focus=false;
  27147. }else {
  27148. _$this._isVisibility=true;
  27149. }
  27150. _$this.renderingEnabled=_$this._isVisibility;
  27151. _me.event(/*laya.events.Event.VISIBILITY_CHANGE*/"visibilitychange");
  27152. }
  27153. window.addEventListener("resize",function(){
  27154. var orientation=Browser.window.orientation;
  27155. if (orientation !=null && orientation !=_$this._previousOrientation && _me._isInputting()){
  27156. Input["inputElement"].target.focus=false;
  27157. }
  27158. _$this._previousOrientation=orientation;
  27159. if (_me._isInputting())return;
  27160. if (Browser.onSafari)
  27161. _me._safariOffsetY=(Browser.window.__innerHeight || Browser.document.body.clientHeight || Browser.document.documentElement.clientHeight)-Browser.window.innerHeight;
  27162. _me._resetCanvas();
  27163. });
  27164. window.addEventListener("orientationchange",function(e){
  27165. _me._resetCanvas();
  27166. });
  27167. this.on(/*laya.events.Event.MOUSE_MOVE*/"mousemove",this,this._onmouseMove);
  27168. if (Browser.onMobile)this.on(/*laya.events.Event.MOUSE_DOWN*/"mousedown",this,this._onmouseMove);
  27169. }
  27170. __class(Stage,'laya.display.Stage',_super);
  27171. var __proto=Stage.prototype;
  27172. /**
  27173. *@private
  27174. *在移动端输入时,输入法弹出期间不进行画布尺寸重置。
  27175. */
  27176. __proto._isInputting=function(){
  27177. return (Browser.onMobile && Input.isInputting);
  27178. }
  27179. /**@private */
  27180. __proto._changeCanvasSize=function(){
  27181. this.setScreenSize(Browser.clientWidth *Browser.pixelRatio,Browser.clientHeight *Browser.pixelRatio);
  27182. }
  27183. /**@private */
  27184. __proto._resetCanvas=function(){
  27185. if (!this.screenAdaptationEnabled)return;
  27186. this._changeCanvasSize();
  27187. }
  27188. /**
  27189. *设置屏幕大小,场景会根据屏幕大小进行适配。可以动态调用此方法,来更改游戏显示的大小。
  27190. *@param screenWidth 屏幕宽度。
  27191. *@param screenHeight 屏幕高度。
  27192. */
  27193. __proto.setScreenSize=function(screenWidth,screenHeight){
  27194. var rotation=false;
  27195. if (this._screenMode!=="none"){
  27196. var screenType=screenWidth / screenHeight < 1 ? "vertical" :"horizontal";
  27197. rotation=screenType!==this._screenMode;
  27198. if (rotation){
  27199. var temp=screenHeight;
  27200. screenHeight=screenWidth;
  27201. screenWidth=temp;
  27202. }
  27203. }
  27204. this.canvasRotation=rotation;
  27205. var canvas=Render._mainCanvas;
  27206. var canvasStyle=canvas.source.style;
  27207. var mat=this._canvasTransform.identity();
  27208. var scaleMode=this._scaleMode;
  27209. var scaleX=screenWidth / this.designWidth;
  27210. var scaleY=screenHeight / this.designHeight;
  27211. var canvasWidth=this.useRetinalCanvas?screenWidth:this.designWidth;
  27212. var canvasHeight=this.useRetinalCanvas?screenHeight:this.designHeight;
  27213. var realWidth=screenWidth;
  27214. var realHeight=screenHeight;
  27215. var pixelRatio=Browser.pixelRatio;
  27216. this._width=this.designWidth;
  27217. this._height=this.designHeight;
  27218. switch (scaleMode){
  27219. case "noscale":
  27220. scaleX=scaleY=1;
  27221. realWidth=this.designWidth;
  27222. realHeight=this.designHeight;
  27223. break ;
  27224. case "showall":
  27225. scaleX=scaleY=Math.min(scaleX,scaleY);
  27226. canvasWidth=realWidth=Math.round(this.designWidth *scaleX);
  27227. canvasHeight=realHeight=Math.round(this.designHeight *scaleY);
  27228. break ;
  27229. case "noborder":
  27230. scaleX=scaleY=Math.max(scaleX,scaleY);
  27231. realWidth=Math.round(this.designWidth *scaleX);
  27232. realHeight=Math.round(this.designHeight *scaleY);
  27233. break ;
  27234. case "full":
  27235. scaleX=scaleY=1;
  27236. this._width=canvasWidth=screenWidth;
  27237. this._height=canvasHeight=screenHeight;
  27238. break ;
  27239. case "fixedwidth":
  27240. scaleY=scaleX;
  27241. this._height=canvasHeight=Math.round(screenHeight / scaleX);
  27242. break ;
  27243. case "fixedheight":
  27244. scaleX=scaleY;
  27245. this._width=canvasWidth=Math.round(screenWidth / scaleY);
  27246. break ;
  27247. case "fixedauto":
  27248. if ((screenWidth / screenHeight)< (this.designWidth / this.designHeight)){
  27249. scaleY=scaleX;
  27250. this._height=canvasHeight=Math.round(screenHeight / scaleX);
  27251. }else {
  27252. scaleX=scaleY;
  27253. this._width=canvasWidth=Math.round(screenWidth / scaleY);
  27254. }
  27255. break ;
  27256. }
  27257. if (this.useRetinalCanvas){
  27258. canvasWidth=screenWidth;
  27259. canvasHeight=screenHeight;
  27260. }
  27261. scaleX *=this.scaleX;
  27262. scaleY *=this.scaleY;
  27263. if (scaleX===1 && scaleY===1){
  27264. this.transform.identity();
  27265. }else {
  27266. this.transform.a=this._formatData(scaleX / (realWidth / canvasWidth));
  27267. this.transform.d=this._formatData(scaleY / (realHeight / canvasHeight));
  27268. }
  27269. canvas.size(canvasWidth,canvasHeight);
  27270. RunDriver.changeWebGLSize(canvasWidth,canvasHeight);
  27271. mat.scale(realWidth / canvasWidth / pixelRatio,realHeight / canvasHeight / pixelRatio);
  27272. if (this._alignH==="left")this.offset.x=0;
  27273. else if (this._alignH==="right")this.offset.x=screenWidth-realWidth;
  27274. else this.offset.x=(screenWidth-realWidth)*0.5 / pixelRatio;
  27275. if (this._alignV==="top")this.offset.y=0;
  27276. else if (this._alignV==="bottom")this.offset.y=screenHeight-realHeight;
  27277. else this.offset.y=(screenHeight-realHeight)*0.5 / pixelRatio;
  27278. this.offset.x=Math.round(this.offset.x);
  27279. this.offset.y=Math.round(this.offset.y);
  27280. mat.translate(this.offset.x,this.offset.y);
  27281. if (this._safariOffsetY)mat.translate(0,this._safariOffsetY);
  27282. this.canvasDegree=0;
  27283. if (rotation){
  27284. if (this._screenMode==="horizontal"){
  27285. mat.rotate(Math.PI / 2);
  27286. mat.translate(screenHeight / pixelRatio,0);
  27287. this.canvasDegree=90;
  27288. }else {
  27289. mat.rotate(-Math.PI / 2);
  27290. mat.translate(0,screenWidth / pixelRatio);
  27291. this.canvasDegree=-90;
  27292. }
  27293. }
  27294. mat.a=this._formatData(mat.a);
  27295. mat.d=this._formatData(mat.d);
  27296. mat.tx=this._formatData(mat.tx);
  27297. mat.ty=this._formatData(mat.ty);
  27298. this.transform=this.transform;
  27299. canvasStyle.transformOrigin=canvasStyle.webkitTransformOrigin=canvasStyle.msTransformOrigin=canvasStyle.mozTransformOrigin=canvasStyle.oTransformOrigin="0px 0px 0px";
  27300. canvasStyle.transform=canvasStyle.webkitTransform=canvasStyle.msTransform=canvasStyle.mozTransform=canvasStyle.oTransform="matrix("+mat.toString()+")";
  27301. if (this._safariOffsetY)mat.translate(0,-this._safariOffsetY);
  27302. mat.translate(parseInt(canvasStyle.left)|| 0,parseInt(canvasStyle.top)|| 0);
  27303. this.visible=true;
  27304. this._repaint |=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02;
  27305. this.event(/*laya.events.Event.RESIZE*/"resize");
  27306. }
  27307. /**@private */
  27308. __proto._formatData=function(value){
  27309. if (Math.abs(value)< 0.000001)return 0;
  27310. if (Math.abs(1-value)< 0.001)return value > 0 ? 1 :-1;
  27311. return value;
  27312. }
  27313. /**@inheritDoc */
  27314. __proto.getMousePoint=function(){
  27315. return Point.TEMP.setTo(this.mouseX,this.mouseY);
  27316. }
  27317. /**@inheritDoc */
  27318. __proto.repaint=function(type){
  27319. (type===void 0)&& (type=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  27320. this._repaint |=type;
  27321. }
  27322. /**@inheritDoc */
  27323. __proto.parentRepaint=function(type){
  27324. (type===void 0)&& (type=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  27325. }
  27326. /**@private */
  27327. __proto._loop=function(){
  27328. this._globalRepaintGet=this._globalRepaintSet;
  27329. this._globalRepaintSet=false;
  27330. this.render(Render._context,0,0);
  27331. return true;
  27332. }
  27333. /**@private */
  27334. __proto.getFrameTm=function(){
  27335. return this._frameStartTime;
  27336. }
  27337. /**@private */
  27338. __proto._onmouseMove=function(e){
  27339. this._mouseMoveTime=Browser.now();
  27340. }
  27341. /**
  27342. *<p>获得距当前帧开始后,过了多少时间,单位为毫秒。</p>
  27343. *<p>可以用来判断函数内时间消耗,通过合理控制每帧函数处理消耗时长,避免一帧做事情太多,对复杂计算分帧处理,能有效降低帧率波动。</p>
  27344. */
  27345. __proto.getTimeFromFrameStart=function(){
  27346. return Browser.now()-this._frameStartTime;
  27347. }
  27348. /**@inheritDoc */
  27349. __proto.render=function(context,x,y){
  27350. Stage._dbgSprite.graphics.clear();
  27351. if (this._frameRate==="sleep"){
  27352. var now=Browser.now();
  27353. if (now-this._frameStartTime >=1000)this._frameStartTime=now;
  27354. else return;
  27355. }else {
  27356. if (!this._visible){
  27357. this._renderCount++;
  27358. if (this._renderCount % 5===0){
  27359. CallLater.I._update();
  27360. Stat.loopCount++;
  27361. this._updateTimers();
  27362. }
  27363. return;
  27364. }
  27365. this._frameStartTime=Browser.now();
  27366. }
  27367. this._renderCount++;
  27368. var frameMode=this._frameRate==="mouse" ? (((this._frameStartTime-this._mouseMoveTime)< 2000)? "fast" :"slow"):this._frameRate;
  27369. var isFastMode=(frameMode!=="slow");
  27370. var isDoubleLoop=(this._renderCount % 2===0);
  27371. Stat.renderSlow=!isFastMode;
  27372. if (isFastMode || isDoubleLoop){
  27373. CallLater.I._update();
  27374. Stat.loopCount++;
  27375. if (this.renderingEnabled){
  27376. for (var i=0,n=this._scene3Ds.length;i < n;i++)
  27377. this._scene3Ds[i]._update();
  27378. context.clear();
  27379. _super.prototype.render.call(this,context,x,y);
  27380. Stat._show && Stat._sp && Stat._sp.render(context,x,y);
  27381. }
  27382. }
  27383. Stage._dbgSprite.render(context,0,0);
  27384. if (isFastMode || !isDoubleLoop){
  27385. if (this.renderingEnabled){
  27386. RunDriver.clear(this._bgColor);
  27387. context.flush();
  27388. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  27389. }
  27390. this._updateTimers();
  27391. }
  27392. }
  27393. __proto.renderToNative=function(context,x,y){
  27394. this._renderCount++;
  27395. if (!this._visible){
  27396. if (this._renderCount % 5===0){
  27397. CallLater.I._update();
  27398. Stat.loopCount++;
  27399. this._updateTimers();
  27400. }
  27401. return;
  27402. }
  27403. CallLater.I._update();
  27404. Stat.loopCount++;
  27405. if (this.renderingEnabled){
  27406. for (var i=0,n=this._scene3Ds.length;i < n;i++)
  27407. this._scene3Ds[i]._update();
  27408. context.clear();
  27409. _super.prototype.render.call(this,context,x,y);
  27410. Stat._show && Stat._sp && Stat._sp.render(context,x,y);
  27411. }
  27412. if (this.renderingEnabled){
  27413. RunDriver.clear(this._bgColor);
  27414. context.flush();
  27415. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  27416. }
  27417. this._updateTimers();
  27418. }
  27419. __proto._updateTimers=function(){
  27420. Laya.systemTimer._update();
  27421. Laya.startTimer._update();
  27422. Laya.physicsTimer._update();
  27423. Laya.updateTimer._update();
  27424. Laya.lateTimer._update();
  27425. Laya.timer._update();
  27426. }
  27427. /**@private */
  27428. __proto._requestFullscreen=function(){
  27429. var element=Browser.document.documentElement;
  27430. if (element.requestFullscreen){
  27431. element.requestFullscreen();
  27432. }else if (element.mozRequestFullScreen){
  27433. element.mozRequestFullScreen();
  27434. }else if (element.webkitRequestFullscreen){
  27435. element.webkitRequestFullscreen();
  27436. }else if (element.msRequestFullscreen){
  27437. element.msRequestFullscreen();
  27438. }
  27439. }
  27440. /**@private */
  27441. __proto._fullScreenChanged=function(){
  27442. Laya.stage.event(/*laya.events.Event.FULL_SCREEN_CHANGE*/"fullscreenchange");
  27443. }
  27444. /**退出全屏模式*/
  27445. __proto.exitFullscreen=function(){
  27446. var document=Browser.document;
  27447. if (document.exitFullscreen){
  27448. document.exitFullscreen();
  27449. }else if (document.mozCancelFullScreen){
  27450. document.mozCancelFullScreen();
  27451. }else if (document.webkitExitFullscreen){
  27452. document.webkitExitFullscreen();
  27453. }
  27454. }
  27455. /**@private */
  27456. __proto.isGlobalRepaint=function(){
  27457. return this._globalRepaintGet;
  27458. }
  27459. /**@private */
  27460. __proto.setGlobalRepaint=function(){
  27461. this._globalRepaintSet=true;
  27462. }
  27463. /**@private */
  27464. __proto.add3DUI=function(uibase){
  27465. var uiroot=/*__JS__ */uibase.rootView;
  27466. if (this._3dUI.indexOf(uiroot)>=0)return;
  27467. this._3dUI.push(uiroot);
  27468. }
  27469. /**@private */
  27470. __proto.remove3DUI=function(uibase){
  27471. var uiroot=/*__JS__ */uibase.rootView;
  27472. var p=this._3dUI.indexOf(uiroot);
  27473. if (p >=0){
  27474. this._3dUI.splice(p,1);
  27475. return true;
  27476. }
  27477. return false;
  27478. }
  27479. /**当前视窗由缩放模式导致的 Y 轴缩放系数。*/
  27480. __getset(0,__proto,'clientScaleY',function(){
  27481. return this._transform ? this._transform.getScaleY():1;
  27482. });
  27483. /**@inheritDoc */
  27484. __getset(0,__proto,'width',_super.prototype._$get_width,function(value){
  27485. this.designWidth=value;
  27486. Laya.superSet(Sprite,this,'width',value);
  27487. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  27488. });
  27489. /**
  27490. *舞台是否获得焦点。
  27491. */
  27492. __getset(0,__proto,'isFocused',function(){
  27493. return this._isFocused;
  27494. });
  27495. /**
  27496. *<p>水平对齐方式。默认值为"left"。</p>
  27497. *<p><ul>取值范围:
  27498. *<li>"left" :居左对齐;</li>
  27499. *<li>"center" :居中对齐;</li>
  27500. *<li>"right" :居右对齐;</li>
  27501. *</ul></p>
  27502. */
  27503. __getset(0,__proto,'alignH',function(){
  27504. return this._alignH;
  27505. },function(value){
  27506. this._alignH=value;
  27507. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  27508. });
  27509. /**@inheritDoc */
  27510. __getset(0,__proto,'height',_super.prototype._$get_height,function(value){
  27511. this.designHeight=value;
  27512. Laya.superSet(Sprite,this,'height',value);
  27513. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  27514. });
  27515. /**@inheritDoc */
  27516. __getset(0,__proto,'transform',function(){
  27517. if (this._tfChanged)this._adjustTransform();
  27518. return (this._transform=this._transform || this._createTransform());
  27519. },_super.prototype._$set_transform);
  27520. /**
  27521. *舞台是否处于可见状态(是否进入后台)。
  27522. */
  27523. __getset(0,__proto,'isVisibility',function(){
  27524. return this._isVisibility;
  27525. });
  27526. /**
  27527. *<p>缩放模式。默认值为 "noscale"。</p>
  27528. *<p><ul>取值范围:
  27529. *<li>"noscale" :不缩放;</li>
  27530. *<li>"exactfit" :全屏不等比缩放;</li>
  27531. *<li>"showall" :最小比例缩放;</li>
  27532. *<li>"noborder" :最大比例缩放;</li>
  27533. *<li>"full" :不缩放,stage的宽高等于屏幕宽高;</li>
  27534. *<li>"fixedwidth" :宽度不变,高度根据屏幕比缩放;</li>
  27535. *<li>"fixedheight" :高度不变,宽度根据屏幕比缩放;</li>
  27536. *<li>"fixedauto" :根据宽高比,自动选择使用fixedwidth或fixedheight;</li>
  27537. *</ul></p>
  27538. */
  27539. __getset(0,__proto,'scaleMode',function(){
  27540. return this._scaleMode;
  27541. },function(value){
  27542. this._scaleMode=value;
  27543. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  27544. });
  27545. /**
  27546. *<p>垂直对齐方式。默认值为"top"。</p>
  27547. *<p><ul>取值范围:
  27548. *<li>"top" :居顶部对齐;</li>
  27549. *<li>"middle" :居中对齐;</li>
  27550. *<li>"bottom" :居底部对齐;</li>
  27551. *</ul></p>
  27552. */
  27553. __getset(0,__proto,'alignV',function(){
  27554. return this._alignV;
  27555. },function(value){
  27556. this._alignV=value;
  27557. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  27558. });
  27559. /**舞台的背景颜色,默认为黑色,null为透明。*/
  27560. __getset(0,__proto,'bgColor',function(){
  27561. return this._bgColor;
  27562. },function(value){
  27563. this._bgColor=value;
  27564. if (value)
  27565. this._wgColor=ColorUtils.create(value).arrColor;
  27566. else
  27567. this._wgColor=null;
  27568. if (Browser.onLimixiu){
  27569. this._wgColor=ColorUtils.create(value).arrColor;
  27570. }else if (value){
  27571. Render.canvas.style.background=value;
  27572. }else {
  27573. Render.canvas.style.background="none";
  27574. }
  27575. });
  27576. /**鼠标在 Stage 上的 X 轴坐标。*/
  27577. __getset(0,__proto,'mouseX',function(){
  27578. return Math.round(MouseManager.instance.mouseX / this.clientScaleX);
  27579. });
  27580. /**鼠标在 Stage 上的 Y 轴坐标。*/
  27581. __getset(0,__proto,'mouseY',function(){
  27582. return Math.round(MouseManager.instance.mouseY / this.clientScaleY);
  27583. });
  27584. /**当前视窗由缩放模式导致的 X 轴缩放系数。*/
  27585. __getset(0,__proto,'clientScaleX',function(){
  27586. return this._transform ? this._transform.getScaleX():1;
  27587. });
  27588. /**
  27589. *<p>场景布局类型。</p>
  27590. *<p><ul>取值范围:
  27591. *<li>"none" :不更改屏幕</li>
  27592. *<li>"horizontal" :自动横屏</li>
  27593. *<li>"vertical" :自动竖屏</li>
  27594. *</ul></p>
  27595. */
  27596. __getset(0,__proto,'screenMode',function(){
  27597. return this._screenMode;
  27598. },function(value){
  27599. this._screenMode=value;
  27600. });
  27601. /**@inheritDoc */
  27602. __getset(0,__proto,'visible',_super.prototype._$get_visible,function(value){
  27603. if (this.visible!==value){
  27604. Laya.superSet(Sprite,this,'visible',value);
  27605. var style=Render._mainCanvas.source.style;
  27606. style.visibility=value ? "visible" :"hidden";
  27607. }
  27608. });
  27609. /**
  27610. *<p>是否开启全屏,用户点击后进入全屏。</p>
  27611. *<p>兼容性提示:部分浏览器不允许点击进入全屏,比如Iphone等。</p>
  27612. */
  27613. __getset(0,__proto,'fullScreenEnabled',null,function(value){
  27614. var document=Browser.document;
  27615. var canvas=Render.canvas;
  27616. if (value){
  27617. canvas.addEventListener('mousedown',this._requestFullscreen);
  27618. canvas.addEventListener('touchstart',this._requestFullscreen);
  27619. document.addEventListener("fullscreenchange",this._fullScreenChanged);
  27620. document.addEventListener("mozfullscreenchange",this._fullScreenChanged);
  27621. document.addEventListener("webkitfullscreenchange",this._fullScreenChanged);
  27622. document.addEventListener("msfullscreenchange",this._fullScreenChanged);
  27623. }else {
  27624. canvas.removeEventListener('mousedown',this._requestFullscreen);
  27625. canvas.removeEventListener('touchstart',this._requestFullscreen);
  27626. document.removeEventListener("fullscreenchange",this._fullScreenChanged);
  27627. document.removeEventListener("mozfullscreenchange",this._fullScreenChanged);
  27628. document.removeEventListener("webkitfullscreenchange",this._fullScreenChanged);
  27629. document.removeEventListener("msfullscreenchange",this._fullScreenChanged);
  27630. }
  27631. });
  27632. __getset(0,__proto,'frameRate',function(){
  27633. if (!Render.isConchApp){
  27634. return this._frameRate;
  27635. }else {
  27636. return /*__JS__ */this._frameRateNative;
  27637. }
  27638. },function(value){
  27639. if (!Render.isConchApp){
  27640. this._frameRate=value;
  27641. }else {
  27642. switch (value){
  27643. case "fast":
  27644. window.conch.config.setLimitFPS(60);
  27645. break ;
  27646. case "mouse":
  27647. window.conch.config.setMouseFrame(2000);
  27648. break ;
  27649. case "slow":
  27650. window.conch.config.setSlowFrame(true);
  27651. break ;
  27652. case "sleep":
  27653. window.conch.config.setLimitFPS(1);
  27654. break ;
  27655. }
  27656. /*__JS__ */this._frameRateNative=value;
  27657. }
  27658. });
  27659. Stage.SCALE_NOSCALE="noscale";
  27660. Stage.SCALE_EXACTFIT="exactfit";
  27661. Stage.SCALE_SHOWALL="showall";
  27662. Stage.SCALE_NOBORDER="noborder";
  27663. Stage.SCALE_FULL="full";
  27664. Stage.SCALE_FIXED_WIDTH="fixedwidth";
  27665. Stage.SCALE_FIXED_HEIGHT="fixedheight";
  27666. Stage.SCALE_FIXED_AUTO="fixedauto";
  27667. Stage.ALIGN_LEFT="left";
  27668. Stage.ALIGN_RIGHT="right";
  27669. Stage.ALIGN_CENTER="center";
  27670. Stage.ALIGN_TOP="top";
  27671. Stage.ALIGN_MIDDLE="middle";
  27672. Stage.ALIGN_BOTTOM="bottom";
  27673. Stage.SCREEN_NONE="none";
  27674. Stage.SCREEN_HORIZONTAL="horizontal";
  27675. Stage.SCREEN_VERTICAL="vertical";
  27676. Stage.FRAME_FAST="fast";
  27677. Stage.FRAME_SLOW="slow";
  27678. Stage.FRAME_MOUSE="mouse";
  27679. Stage.FRAME_SLEEP="sleep";
  27680. __static(Stage,
  27681. ['_dbgSprite',function(){return this._dbgSprite=new Sprite();}
  27682. ]);
  27683. return Stage;
  27684. })(Sprite)
  27685. /**
  27686. *<code>BaseTexture</code> 纹理的父类,抽象类,不允许实例。
  27687. */
  27688. //class laya.resource.BaseTexture extends laya.resource.Bitmap
  27689. var BaseTexture=(function(_super){
  27690. function BaseTexture(format,mipMap){
  27691. /**@private */
  27692. //this._readyed=false;
  27693. /**@private */
  27694. //this._glTextureType=0;
  27695. /**@private */
  27696. //this._glTexture=null;
  27697. /**@private */
  27698. //this._format=0;
  27699. /**@private */
  27700. //this._mipmap=false;
  27701. /**@private */
  27702. //this._wrapModeU=0;
  27703. /**@private */
  27704. //this._wrapModeV=0;
  27705. /**@private */
  27706. //this._filterMode=0;
  27707. /**@private */
  27708. //this._anisoLevel=0;
  27709. BaseTexture.__super.call(this);
  27710. this._wrapModeU=/*CLASS CONST:laya.resource.BaseTexture.WARPMODE_REPEAT*/0;
  27711. this._wrapModeV=/*CLASS CONST:laya.resource.BaseTexture.WARPMODE_REPEAT*/0;
  27712. this._filterMode=/*CLASS CONST:laya.resource.BaseTexture.FILTERMODE_BILINEAR*/1;
  27713. this._readyed=false;
  27714. this._width=-1;
  27715. this._height=-1;
  27716. this._format=format;
  27717. this._mipmap=mipMap;
  27718. this._anisoLevel=1;
  27719. this._glTexture=LayaGL.instance.createTexture();
  27720. }
  27721. __class(BaseTexture,'laya.resource.BaseTexture',_super);
  27722. var __proto=BaseTexture.prototype;
  27723. /**
  27724. *@private
  27725. */
  27726. __proto._isPot=function(size){
  27727. return (size & (size-1))===0;
  27728. }
  27729. /**
  27730. *@private
  27731. */
  27732. __proto._getGLFormat=function(){
  27733. var glFormat=0;
  27734. switch (this._format){
  27735. case 0:
  27736. glFormat=/*laya.webgl.WebGLContext.RGB*/0x1907;
  27737. break ;
  27738. case 1:
  27739. glFormat=/*laya.webgl.WebGLContext.RGBA*/0x1908;
  27740. break ;
  27741. case 2:
  27742. glFormat=/*laya.webgl.WebGLContext.ALPHA*/0x1906;
  27743. break ;
  27744. case 3:
  27745. if (WebGLContext._compressedTextureS3tc)
  27746. glFormat=WebGLContext._compressedTextureS3tc.COMPRESSED_RGB_S3TC_DXT1_EXT;
  27747. else
  27748. throw "BaseTexture: not support DXT1 format.";
  27749. break ;
  27750. case 4:
  27751. if (WebGLContext._compressedTextureS3tc)
  27752. glFormat=WebGLContext._compressedTextureS3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  27753. else
  27754. throw "BaseTexture: not support DXT5 format.";
  27755. break ;
  27756. case 5:
  27757. if (WebGLContext._compressedTextureEtc1)
  27758. glFormat=WebGLContext._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL;
  27759. else
  27760. throw "BaseTexture: not support ETC1RGB format.";
  27761. break ;
  27762. case 9:
  27763. if (WebGLContext._compressedTexturePvrtc)
  27764. glFormat=WebGLContext._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  27765. else
  27766. throw "BaseTexture: not support PVRTCRGB_2BPPV format.";
  27767. break ;
  27768. case 10:
  27769. if (WebGLContext._compressedTexturePvrtc)
  27770. glFormat=WebGLContext._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  27771. else
  27772. throw "BaseTexture: not support PVRTCRGBA_2BPPV format.";
  27773. break ;
  27774. case 11:
  27775. if (WebGLContext._compressedTexturePvrtc)
  27776. glFormat=WebGLContext._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  27777. else
  27778. throw "BaseTexture: not support PVRTCRGB_4BPPV format.";
  27779. break ;
  27780. case 12:
  27781. if (WebGLContext._compressedTexturePvrtc)
  27782. glFormat=WebGLContext._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  27783. else
  27784. throw "BaseTexture: not support PVRTCRGBA_4BPPV format.";
  27785. break ;
  27786. default :
  27787. throw "BaseTexture: unknown texture format.";
  27788. }
  27789. return glFormat;
  27790. }
  27791. /**
  27792. *@private
  27793. */
  27794. __proto._setFilterMode=function(value){
  27795. var gl=LayaGL.instance;
  27796. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  27797. switch (value){
  27798. case 0:
  27799. if (this._mipmap)
  27800. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.NEAREST_MIPMAP_NEAREST*/0x2700);
  27801. else
  27802. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.NEAREST*/0x2600);
  27803. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MAG_FILTER*/0x2800,/*laya.webgl.WebGLContext.NEAREST*/0x2600);
  27804. break ;
  27805. case 1:
  27806. if (this._mipmap)
  27807. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR_MIPMAP_NEAREST*/0x2701);
  27808. else
  27809. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  27810. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MAG_FILTER*/0x2800,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  27811. break ;
  27812. case 2:
  27813. if (this._mipmap)
  27814. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR_MIPMAP_LINEAR*/0x2703);
  27815. else
  27816. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  27817. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MAG_FILTER*/0x2800,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  27818. break ;
  27819. default :
  27820. throw new Error("BaseTexture:unknown filterMode value.");
  27821. }
  27822. }
  27823. /**
  27824. *@private
  27825. */
  27826. __proto._setWarpMode=function(orientation,mode){
  27827. var gl=LayaGL.instance;
  27828. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  27829. if (this._isPot(this._width)&& this._isPot(this._height)){
  27830. switch (mode){
  27831. case 0:
  27832. gl.texParameteri(this._glTextureType,orientation,/*laya.webgl.WebGLContext.REPEAT*/0x2901);
  27833. break ;
  27834. case 1:
  27835. gl.texParameteri(this._glTextureType,orientation,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
  27836. break ;
  27837. }
  27838. }else {
  27839. gl.texParameteri(this._glTextureType,orientation,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
  27840. }
  27841. }
  27842. /**
  27843. *@private
  27844. */
  27845. __proto._setAnisotropy=function(value){
  27846. var anisotropic=WebGLContext._extTextureFilterAnisotropic;
  27847. if (anisotropic && !Browser.onLimixiu){
  27848. value=Math.max(value,1);
  27849. var gl=LayaGL.instance;
  27850. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  27851. value=Math.min(gl.getParameter(anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT),value);
  27852. gl.texParameterf(this._glTextureType,anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,value);
  27853. }
  27854. }
  27855. /**
  27856. *@inheritDoc
  27857. */
  27858. __proto._disposeResource=function(){
  27859. if (this._glTexture){
  27860. LayaGL.instance.deleteTexture(this._glTexture);
  27861. this._glTexture=null;
  27862. this._setGPUMemory(0);
  27863. }
  27864. }
  27865. /**
  27866. *获取纹理资源。
  27867. */
  27868. __proto._getSource=function(){
  27869. if (this._readyed)
  27870. return this._glTexture;
  27871. else
  27872. return null;
  27873. }
  27874. /**
  27875. *通过基础数据生成mipMap。
  27876. */
  27877. __proto.generateMipmap=function(){
  27878. if (this._isPot(this.width)&& this._isPot(this.height))
  27879. LayaGL.instance.generateMipmap(this._glTextureType);
  27880. }
  27881. /**
  27882. *设置纹理横向循环模式。
  27883. */
  27884. /**
  27885. *获取纹理横向循环模式。
  27886. */
  27887. __getset(0,__proto,'wrapModeU',function(){
  27888. return this._wrapModeU;
  27889. },function(value){
  27890. if (this._wrapModeU!==value){
  27891. this._wrapModeU=value;
  27892. (this._width!==-1)&& (this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,value));
  27893. }
  27894. });
  27895. /**
  27896. *是否使用mipLevel
  27897. */
  27898. __getset(0,__proto,'mipmap',function(){
  27899. return this._mipmap;
  27900. });
  27901. /**
  27902. *纹理格式
  27903. */
  27904. __getset(0,__proto,'format',function(){
  27905. return this._format;
  27906. });
  27907. /**
  27908. *设置纹理纵向循环模式。
  27909. */
  27910. /**
  27911. *获取纹理纵向循环模式。
  27912. */
  27913. __getset(0,__proto,'wrapModeV',function(){
  27914. return this._wrapModeV;
  27915. },function(value){
  27916. if (this._wrapModeV!==value){
  27917. this._wrapModeV=value;
  27918. (this._height!==-1)&& (this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,value));
  27919. }
  27920. });
  27921. /**
  27922. *获取默认纹理资源。
  27923. */
  27924. __getset(0,__proto,'defaulteTexture',function(){
  27925. throw "BaseTexture:must override it."
  27926. });
  27927. /**
  27928. *缩小过滤器
  27929. */
  27930. /**
  27931. *缩小过滤器
  27932. */
  27933. __getset(0,__proto,'filterMode',function(){
  27934. return this._filterMode;
  27935. },function(value){
  27936. if (value!==this._filterMode){
  27937. this._filterMode=value;
  27938. ((this._width!==-1)&& (this._height!==-1))&& (this._setFilterMode(value));
  27939. }
  27940. });
  27941. /**
  27942. *各向异性等级
  27943. */
  27944. /**
  27945. *各向异性等级
  27946. */
  27947. __getset(0,__proto,'anisoLevel',function(){
  27948. return this._anisoLevel;
  27949. },function(value){
  27950. if (value!==this._anisoLevel){
  27951. this._anisoLevel=Math.max(1,Math.min(16,value));
  27952. ((this._width!==-1)&& (this._height!==-1))&& (this._setAnisotropy(value));
  27953. }
  27954. });
  27955. BaseTexture.WARPMODE_REPEAT=0;
  27956. BaseTexture.WARPMODE_CLAMP=1;
  27957. BaseTexture.FILTERMODE_POINT=0;
  27958. BaseTexture.FILTERMODE_BILINEAR=1;
  27959. BaseTexture.FILTERMODE_TRILINEAR=2;
  27960. BaseTexture.FORMAT_R8G8B8=0;
  27961. BaseTexture.FORMAT_R8G8B8A8=1;
  27962. BaseTexture.FORMAT_ALPHA8=2;
  27963. BaseTexture.FORMAT_DXT1=3;
  27964. BaseTexture.FORMAT_DXT5=4;
  27965. BaseTexture.FORMAT_ETC1RGB=5;
  27966. BaseTexture.FORMAT_PVRTCRGB_2BPPV=9;
  27967. BaseTexture.FORMAT_PVRTCRGBA_2BPPV=10;
  27968. BaseTexture.FORMAT_PVRTCRGB_4BPPV=11;
  27969. BaseTexture.FORMAT_PVRTCRGBA_4BPPV=12;
  27970. BaseTexture.FORMAT_DEPTH_16=0;
  27971. BaseTexture.FORMAT_STENCIL_8=1;
  27972. BaseTexture.FORMAT_DEPTHSTENCIL_16_8=2;
  27973. BaseTexture.FORMAT_DEPTHSTENCIL_NONE=3;
  27974. return BaseTexture;
  27975. })(Bitmap)
  27976. //class laya.utils.PerfHUD extends laya.display.Sprite
  27977. var PerfHUD=(function(_super){
  27978. function PerfHUD(){
  27979. this.datas=[];
  27980. this.hud_width=800;
  27981. this.hud_height=200;
  27982. this.gMinV=0;
  27983. this.gMaxV=100;
  27984. this.textSpace=40;
  27985. this._now=null;
  27986. this.sttm=0;
  27987. PerfHUD.__super.call(this);
  27988. this.xdata=new Array(PerfHUD.DATANUM);
  27989. this.ydata=new Array(PerfHUD.DATANUM);
  27990. PerfHUD.inst=this;
  27991. this._renderType |=/*laya.display.SpriteConst.CUSTOM*/0x800;
  27992. this._setRenderType(this._renderType);
  27993. this._setCustomRender();
  27994. this.addDataDef(0,0xffffff,'frame',1.0);
  27995. this.addDataDef(1,0x00ff00,'update',1.0);
  27996. this.addDataDef(2,0xff0000,'flush',1.0);
  27997. this._now=/*__JS__ */performance?performance.now.bind(performance):Date.now;
  27998. }
  27999. __class(PerfHUD,'laya.utils.PerfHUD',_super);
  28000. var __proto=PerfHUD.prototype;
  28001. //TODO:coverage
  28002. __proto.now=function(){
  28003. return this._now();
  28004. }
  28005. //TODO:coverage
  28006. __proto.start=function(){
  28007. this.sttm=this._now();
  28008. }
  28009. //TODO:coverage
  28010. __proto.end=function(i){
  28011. var dt=this._now()-this.sttm;
  28012. this.updateValue(i,dt);
  28013. }
  28014. //TODO:coverage
  28015. __proto.config=function(w,h){
  28016. this.hud_width=w;
  28017. this.hud_height=h;
  28018. }
  28019. //TODO:coverage
  28020. __proto.addDataDef=function(id,color,name,scale){
  28021. this.datas[id]=new PerfData(id,color,name,scale);
  28022. }
  28023. //TODO:coverage
  28024. __proto.updateValue=function(id,v){
  28025. this.datas[id].addData(v);
  28026. }
  28027. //TODO:coverage
  28028. __proto.v2y=function(v){
  28029. var bb=this._y+this.hud_height *(1-(v-this.gMinV)/ this.gMaxV);
  28030. return this._y+this.hud_height*(1-(v-this.gMinV)/this.gMaxV);
  28031. }
  28032. //TODO:coverage
  28033. __proto.drawHLine=function(ctx,v,color,text){
  28034. var sx=this._x;
  28035. var ex=this._x+this.hud_width;
  28036. var sy=this.v2y(v);
  28037. ctx.fillText(text,sx,sy-6,null,'green',null);
  28038. sx+=this.textSpace;
  28039. ctx.fillStyle=color;
  28040. ctx.fillRect(sx,sy,this._x+this.hud_width,1,null);
  28041. }
  28042. //TODO:coverage
  28043. __proto.customRender=function(ctx,x,y){
  28044. var now=/*__JS__ */performance.now();;
  28045. if (PerfHUD._lastTm <=0)PerfHUD._lastTm=now;
  28046. this.updateValue(0,now-PerfHUD._lastTm);
  28047. PerfHUD._lastTm=now;
  28048. ctx.save();
  28049. ctx.fillRect(this._x,this._y,this.hud_width,this.hud_height+4,'#000000cc');
  28050. ctx.globalAlpha=0.9;
  28051. this.drawHLine(ctx,0,'green',' 0');
  28052. this.drawHLine(ctx,10,'green',' 10');
  28053. this.drawHLine(ctx,16.667,'red',' ');
  28054. this.drawHLine(ctx,20,'green','50|20');
  28055. this.drawHLine(ctx,16.667 *2,'yellow','');
  28056. this.drawHLine(ctx,16.667 *3,'yellow','');
  28057. this.drawHLine(ctx,16.667 *4,'yellow','');
  28058. this.drawHLine(ctx,50,'green','20|50');
  28059. this.drawHLine(ctx,100,'green','10|100');
  28060. for (var di=0,sz=this.datas.length;di < sz;di++){
  28061. var cd=this.datas[di];
  28062. if (!cd)continue ;
  28063. var dtlen=cd.datas.length;
  28064. var dx=(this.hud_width-this.textSpace)/dtlen;
  28065. var cx=cd.datapos;
  28066. var _cx=this._x+this.textSpace;
  28067. ctx.fillStyle=cd.color;
  28068. for (var dtsz=dtlen;cx < dtsz;cx++){
  28069. var sty=this.v2y(cd.datas[cx] *cd.scale);
  28070. ctx.fillRect(_cx,sty,dx,this.hud_height+this._y-sty,null);
  28071. _cx+=dx;
  28072. }
  28073. for (cx=0;cx < cd.datapos;cx++){
  28074. sty=this.v2y(cd.datas[cx] *cd.scale);
  28075. ctx.fillRect(_cx,sty,dx,this.hud_height+this._y-sty,null);
  28076. _cx+=dx;
  28077. }
  28078. }
  28079. ctx.restore();
  28080. }
  28081. PerfHUD._lastTm=0;
  28082. PerfHUD._now=0;
  28083. PerfHUD.DATANUM=300;
  28084. PerfHUD.inst=null;
  28085. PerfHUD.drawTexTm=0;
  28086. return PerfHUD;
  28087. })(Sprite)
  28088. /**
  28089. *场景类,负责场景创建,加载,销毁等功能
  28090. *场景被从节点移除后,并不会被自动垃圾机制回收,如果想回收,请调用destroy接口,可以通过unDestroyedScenes属性查看还未被销毁的场景列表
  28091. */
  28092. //class laya.display.Scene extends laya.display.Sprite
  28093. var Scene=(function(_super){
  28094. function Scene(){
  28095. /**场景被关闭后,是否自动销毁(销毁节点和使用到的资源),默认为false*/
  28096. this.autoDestroyAtClosed=false;
  28097. /**场景地址*/
  28098. this.url=null;
  28099. /**场景时钟*/
  28100. this._timer=null;
  28101. /**@private */
  28102. this._viewCreated=false;
  28103. /**@private */
  28104. this._idMap=null;
  28105. /**@private */
  28106. this._$componentType="Scene";
  28107. Scene.__super.call(this);
  28108. this._setBit(/*laya.Const.NOT_READY*/0x08,true);
  28109. Scene.unDestroyedScenes.push(this);
  28110. this._scene=this;
  28111. this.createChildren();
  28112. }
  28113. __class(Scene,'laya.display.Scene',_super);
  28114. var __proto=Scene.prototype;
  28115. /**
  28116. *@private 兼容老项目
  28117. */
  28118. __proto.createChildren=function(){}
  28119. /**
  28120. *@private 兼容老项目
  28121. *装载场景视图。用于加载模式。
  28122. *@param path 场景地址。
  28123. */
  28124. __proto.loadScene=function(path){
  28125. var url=path.indexOf(".")>-1 ? path :path+".scene";
  28126. var view=Laya.loader.getRes(url);
  28127. if (view){
  28128. this.createView(view);
  28129. }else {
  28130. Laya.loader.resetProgress();
  28131. var loader=new SceneLoader();
  28132. loader.on(/*laya.events.Event.COMPLETE*/"complete",this,this._onSceneLoaded,[url]);
  28133. loader.load(url);
  28134. }
  28135. }
  28136. //Laya.loader.load(url,Handler.create(this,createView),null,Loader.JSON);
  28137. __proto._onSceneLoaded=function(url){
  28138. this.createView(Loader.getRes(url));
  28139. }
  28140. /**
  28141. *@private 兼容老项目
  28142. *通过视图数据创建视图。
  28143. *@param uiView 视图数据信息。
  28144. */
  28145. __proto.createView=function(view){
  28146. if (view && !this._viewCreated){
  28147. this._viewCreated=true;
  28148. SceneUtils.createByData(this,view);
  28149. }
  28150. }
  28151. /**
  28152. *根据IDE内的节点id,获得节点实例
  28153. */
  28154. __proto.getNodeByID=function(id){
  28155. if (this._idMap)return this._idMap[id];
  28156. return null;
  28157. }
  28158. /**
  28159. *打开场景。【注意】被关闭的场景,如果没有设置autoDestroyAtRemoved=true,则资源可能不能被回收,需要自己手动回收
  28160. *@param closeOther 是否关闭其他场景,默认为true(可选)
  28161. *@param param 打开页面的参数,会传递给onOpened方法(可选)
  28162. */
  28163. __proto.open=function(closeOther,param){
  28164. (closeOther===void 0)&& (closeOther=true);
  28165. if (closeOther)Scene.closeAll();
  28166. Scene.root.addChild(this);
  28167. this.onOpened(param);
  28168. }
  28169. /**场景打开完成后,调用此方法(如果有弹出动画,则在动画完成后执行)*/
  28170. __proto.onOpened=function(param){}
  28171. /**
  28172. *关闭场景
  28173. *【注意】被关闭的场景,如果没有设置autoDestroyAtRemoved=true,则资源可能不能被回收,需要自己手动回收
  28174. *@param type 关闭的原因,会传递给onClosed函数
  28175. */
  28176. __proto.close=function(type){
  28177. this.onClosed(type);
  28178. if (this.autoDestroyAtClosed)this.destroy();
  28179. else this.removeSelf();
  28180. }
  28181. /**关闭完成后,调用此方法(如果有关闭动画,则在动画完成后执行)
  28182. *@param type 如果是点击默认关闭按钮触发,则传入关闭按钮的名字(name),否则为null。
  28183. */
  28184. __proto.onClosed=function(type){}
  28185. /**@inheritDoc */
  28186. __proto.destroy=function(destroyChild){
  28187. (destroyChild===void 0)&& (destroyChild=true);
  28188. this._idMap=null;
  28189. _super.prototype.destroy.call(this,destroyChild);
  28190. var list=laya.display.Scene.unDestroyedScenes;
  28191. for (var i=list.length-1;i >-1;i--){
  28192. if (list[i]===this){
  28193. list.splice(i,1);
  28194. return;
  28195. }
  28196. }
  28197. }
  28198. /**@private */
  28199. __proto._sizeChanged=function(){
  28200. this.event(/*laya.events.Event.RESIZE*/"resize");
  28201. }
  28202. /**@inheritDoc */
  28203. __getset(0,__proto,'scaleX',_super.prototype._$get_scaleX,function(value){
  28204. if (Laya.superGet(Sprite,this,'scaleX')==value)return;
  28205. Laya.superSet(Sprite,this,'scaleX',value);
  28206. this.event(/*laya.events.Event.RESIZE*/"resize");
  28207. });
  28208. /**@inheritDoc */
  28209. __getset(0,__proto,'scaleY',_super.prototype._$get_scaleY,function(value){
  28210. if (Laya.superGet(Sprite,this,'scaleY')==value)return;
  28211. Laya.superSet(Sprite,this,'scaleY',value);
  28212. this.event(/*laya.events.Event.RESIZE*/"resize");
  28213. });
  28214. /**@inheritDoc */
  28215. /**@inheritDoc */
  28216. __getset(0,__proto,'width',function(){
  28217. if (this._width)return this._width;
  28218. var max=0;
  28219. for (var i=this.numChildren-1;i >-1;i--){
  28220. var comp=this.getChildAt(i);
  28221. if (comp._visible){
  28222. max=Math.max(comp._x+comp.width *comp.scaleX,max);
  28223. }
  28224. }
  28225. return max;
  28226. },function(value){
  28227. if (Laya.superGet(Sprite,this,'width')==value)return;
  28228. Laya.superSet(Sprite,this,'width',value);
  28229. this.callLater(this._sizeChanged);
  28230. });
  28231. /**场景时钟*/
  28232. __getset(0,__proto,'timer',function(){
  28233. return this._timer || Laya.timer;
  28234. },function(value){
  28235. this._timer=value;
  28236. });
  28237. /**@inheritDoc */
  28238. /**@inheritDoc */
  28239. __getset(0,__proto,'height',function(){
  28240. if (this._height)return this._height;
  28241. var max=0;
  28242. for (var i=this.numChildren-1;i >-1;i--){
  28243. var comp=this.getChildAt(i);
  28244. if (comp._visible){
  28245. max=Math.max(comp._y+comp.height *comp.scaleY,max);
  28246. }
  28247. }
  28248. return max;
  28249. },function(value){
  28250. if (Laya.superGet(Sprite,this,'height')==value)return;
  28251. Laya.superSet(Sprite,this,'height',value);
  28252. this.callLater(this._sizeChanged);
  28253. });
  28254. /**获取场景根容器*/
  28255. __getset(1,Scene,'root',function(){
  28256. if (!Scene._root){
  28257. Scene._root=Laya.stage.addChild(new Sprite());
  28258. Scene._root.name="root";
  28259. Laya.stage.on("resize",null,resize);
  28260. function resize (){
  28261. Scene._root.size(Laya.stage.width,Laya.stage.height);
  28262. Scene._root.event(/*laya.events.Event.RESIZE*/"resize");
  28263. }
  28264. resize();
  28265. }
  28266. return Scene._root;
  28267. },laya.display.Sprite._$SET_root);
  28268. Scene.load=function(url,complete,progress){
  28269. Laya.loader.resetProgress();
  28270. var loader=new SceneLoader();
  28271. loader.on(/*laya.events.Event.PROGRESS*/"progress",null,onProgress);
  28272. loader.once(/*laya.events.Event.COMPLETE*/"complete",null,create);
  28273. loader.load(url);
  28274. function onProgress (value){
  28275. if (Scene._loadPage)Scene._loadPage.event("progress",value);
  28276. progress && progress.runWith(value);
  28277. }
  28278. function create (){
  28279. loader.off(/*laya.events.Event.PROGRESS*/"progress",null,onProgress);
  28280. var obj=Loader.getRes(url);
  28281. if (!obj)throw "Can not find scene:"+url;
  28282. if (!obj.props)throw "Scene data is error:"+url;
  28283. var runtime=obj.props.runtime ? obj.props.runtime :obj.type;
  28284. var clas=ClassUtils.getClass(runtime);
  28285. if (obj.props.renderType=="instance"){
  28286. var scene=clas.instance || (clas.instance=new clas());
  28287. }else {
  28288. scene=new clas();
  28289. }
  28290. if (scene && (scene instanceof laya.display.Node )){
  28291. scene.url=url;
  28292. if (!scene._getBit(/*laya.Const.NOT_READY*/0x08)){
  28293. complete && complete.runWith(scene);
  28294. }else {
  28295. scene.on("onViewCreated",null,function(){
  28296. complete && complete.runWith(scene)
  28297. })
  28298. scene.createView(obj);
  28299. }
  28300. Scene.hideLoadingPage();
  28301. }else {
  28302. throw "Can not find scene:"+runtime;
  28303. }
  28304. }
  28305. }
  28306. Scene.open=function(url,closeOther,param,complete,progress){
  28307. (closeOther===void 0)&& (closeOther=true);
  28308. if ((param instanceof laya.utils.Handler )){
  28309. var temp=complete;
  28310. complete=param;
  28311. param=temp;
  28312. }
  28313. Scene.showLoadingPage();
  28314. Scene.load(url,Handler.create(null,this._onSceneLoaded,[closeOther,complete,param]),progress);
  28315. }
  28316. Scene._onSceneLoaded=function(closeOther,complete,param,scene){
  28317. scene.open(closeOther,param);
  28318. if (complete)complete.runWith(scene);
  28319. }
  28320. Scene.close=function(url,name){
  28321. (name===void 0)&& (name="");
  28322. var flag=false;
  28323. var list=laya.display.Scene.unDestroyedScenes;
  28324. for (var i=0,n=list.length;i < n;i++){
  28325. var scene=list[i];
  28326. if (scene && scene.parent && scene.url===url && scene.name==name){
  28327. scene.close();
  28328. flag=true;
  28329. }
  28330. }
  28331. return flag;
  28332. }
  28333. Scene.closeAll=function(){
  28334. var root=laya.display.Scene.root;
  28335. for (var i=0,n=root.numChildren;i < n;i++){
  28336. var scene=root.getChildAt(0);
  28337. if ((scene instanceof laya.display.Scene ))scene.close();
  28338. else scene.removeSelf();
  28339. }
  28340. }
  28341. Scene.destroy=function(url,name){
  28342. (name===void 0)&& (name="");
  28343. var flag=false;
  28344. var list=laya.display.Scene.unDestroyedScenes;
  28345. for (var i=0,n=list.length;i < n;i++){
  28346. var scene=list[i];
  28347. if (scene.url===url && scene.name==name){
  28348. scene.destroy();
  28349. flag=true;
  28350. }
  28351. }
  28352. return flag;
  28353. }
  28354. Scene.gc=function(){
  28355. Resource.destroyUnusedResources();
  28356. }
  28357. Scene.setLoadingPage=function(loadPage){
  28358. if (Scene._loadPage !=loadPage){
  28359. Scene._loadPage=loadPage;
  28360. }
  28361. }
  28362. Scene.showLoadingPage=function(param,delay){
  28363. (delay===void 0)&& (delay=500);
  28364. if (Scene._loadPage){
  28365. Laya.systemTimer.clear(null,Scene._showLoading);
  28366. Laya.systemTimer.clear(null,Scene._hideLoading);
  28367. Laya.systemTimer.once(delay,null,Scene._showLoading,[param],false);
  28368. }
  28369. }
  28370. Scene._showLoading=function(param){
  28371. Laya.stage.addChild(Scene._loadPage);
  28372. Scene._loadPage.onOpened(param);
  28373. }
  28374. Scene._hideLoading=function(){
  28375. Scene._loadPage.close();
  28376. }
  28377. Scene.hideLoadingPage=function(delay){
  28378. (delay===void 0)&& (delay=500);
  28379. if (Scene._loadPage){
  28380. Laya.systemTimer.clear(null,Scene._showLoading);
  28381. Laya.systemTimer.clear(null,Scene._hideLoading);
  28382. Laya.systemTimer.once(delay,null,Scene._hideLoading);
  28383. }
  28384. }
  28385. Scene.unDestroyedScenes=[];
  28386. Scene._root=null;
  28387. Scene._loadPage=null;
  28388. return Scene;
  28389. })(Sprite)
  28390. /**
  28391. *<p> <code>Text</code> 类用于创建显示对象以显示文本。</p>
  28392. *<p>
  28393. *注意:如果运行时系统找不到设定的字体,则用系统默认的字体渲染文字,从而导致显示异常。(通常电脑上显示正常,在一些移动端因缺少设置的字体而显示异常)。
  28394. *</p>
  28395. *@example
  28396. *package
  28397. *{
  28398. *import laya.display.Text;
  28399. *public class Text_Example
  28400. *{
  28401. *public function Text_Example()
  28402. *{
  28403. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  28404. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  28405. *onInit();
  28406. *}
  28407. *private function onInit():void
  28408. *{
  28409. *var text:Text=new Text();//创建一个 Text 类的实例对象 text 。
  28410. *text.text="这个是一个 Text 文本示例。";
  28411. *text.color="#008fff";//设置 text 的文本颜色。
  28412. *text.font="Arial";//设置 text 的文本字体。
  28413. *text.bold=true;//设置 text 的文本显示为粗体。
  28414. *text.fontSize=30;//设置 text 的字体大小。
  28415. *text.wordWrap=true;//设置 text 的文本自动换行。
  28416. *text.x=100;//设置 text 对象的属性 x 的值,用于控制 text 对象的显示位置。
  28417. *text.y=100;//设置 text 对象的属性 y 的值,用于控制 text 对象的显示位置。
  28418. *text.width=300;//设置 text 的宽度。
  28419. *text.height=200;//设置 text 的高度。
  28420. *text.italic=true;//设置 text 的文本显示为斜体。
  28421. *text.borderColor="#fff000";//设置 text 的文本边框颜色。
  28422. *Laya.stage.addChild(text);//将 text 添加到显示列表。
  28423. *}
  28424. *}
  28425. *}
  28426. *@example
  28427. *Text_Example();
  28428. *function Text_Example()
  28429. *{
  28430. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  28431. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  28432. *onInit();
  28433. *}
  28434. *function onInit()
  28435. *{
  28436. *var text=new laya.display.Text();//创建一个 Text 类的实例对象 text 。
  28437. *text.text="这个是一个 Text 文本示例。";
  28438. *text.color="#008fff";//设置 text 的文本颜色。
  28439. *text.font="Arial";//设置 text 的文本字体。
  28440. *text.bold=true;//设置 text 的文本显示为粗体。
  28441. *text.fontSize=30;//设置 text 的字体大小。
  28442. *text.wordWrap=true;//设置 text 的文本自动换行。
  28443. *text.x=100;//设置 text 对象的属性 x 的值,用于控制 text 对象的显示位置。
  28444. *text.y=100;//设置 text 对象的属性 y 的值,用于控制 text 对象的显示位置。
  28445. *text.width=300;//设置 text 的宽度。
  28446. *text.height=200;//设置 text 的高度。
  28447. *text.italic=true;//设置 text 的文本显示为斜体。
  28448. *text.borderColor="#fff000";//设置 text 的文本边框颜色。
  28449. *Laya.stage.addChild(text);//将 text 添加到显示列表。
  28450. *}
  28451. *@example
  28452. *class Text_Example {
  28453. *constructor(){
  28454. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  28455. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  28456. *this.onInit();
  28457. *}
  28458. *private onInit():void {
  28459. *var text:laya.display.Text=new laya.display.Text();//创建一个 Text 类的实例对象 text 。
  28460. *text.text="这个是一个 Text 文本示例。";
  28461. *text.color="#008fff";//设置 text 的文本颜色。
  28462. *text.font="Arial";//设置 text 的文本字体。
  28463. *text.bold=true;//设置 text 的文本显示为粗体。
  28464. *text.fontSize=30;//设置 text 的字体大小。
  28465. *text.wordWrap=true;//设置 text 的文本自动换行。
  28466. *text.x=100;//设置 text 对象的属性 x 的值,用于控制 text 对象的显示位置。
  28467. *text.y=100;//设置 text 对象的属性 y 的值,用于控制 text 对象的显示位置。
  28468. *text.width=300;//设置 text 的宽度。
  28469. *text.height=200;//设置 text 的高度。
  28470. *text.italic=true;//设置 text 的文本显示为斜体。
  28471. *text.borderColor="#fff000";//设置 text 的文本边框颜色。
  28472. *Laya.stage.addChild(text);//将 text 添加到显示列表。
  28473. *}
  28474. *}
  28475. */
  28476. //class laya.display.Text extends laya.display.Sprite
  28477. var Text=(function(_super){
  28478. function Text(){
  28479. /**@private */
  28480. this._clipPoint=null;
  28481. /**@private 表示文本内容字符串。*/
  28482. this._text=null;
  28483. /**@private 表示文本内容是否发生改变。*/
  28484. this._isChanged=false;
  28485. /**@private 表示文本的宽度,以像素为单位。*/
  28486. this._textWidth=0;
  28487. /**@private 表示文本的高度,以像素为单位。*/
  28488. this._textHeight=0;
  28489. /**@private 存储文字行数信息。*/
  28490. this._lines=[];
  28491. /**@private 保存每行宽度*/
  28492. this._lineWidths=[];
  28493. /**@private 文本的内容位置 X 轴信息。*/
  28494. this._startX=0;
  28495. /**@private 文本的内容位置X轴信息。 */
  28496. this._startY=0;
  28497. /**@private */
  28498. this._words=null;
  28499. /**@private */
  28500. this._charSize={};
  28501. /**@private */
  28502. this._valign="top";
  28503. /**@private */
  28504. this._color="#000000";
  28505. /**@private */
  28506. this._singleCharRender=false;
  28507. Text.__super.call(this);
  28508. this._fontSize=Text.defaultFontSize;
  28509. this._font=Text.defaultFont;
  28510. this.overflow="visible";
  28511. this._style=TextStyle.EMPTY;
  28512. }
  28513. __class(Text,'laya.display.Text',_super);
  28514. var __proto=Text.prototype;
  28515. /**
  28516. *@private
  28517. *获取样式。
  28518. *@return 样式 Style 。
  28519. */
  28520. __proto.getStyle=function(){
  28521. this._style===TextStyle.EMPTY && (this._style=TextStyle.create());
  28522. return this._style;
  28523. }
  28524. __proto._getTextStyle=function(){
  28525. if (this._style===TextStyle.EMPTY){
  28526. this._style=TextStyle.create();
  28527. }
  28528. return this._style;
  28529. }
  28530. /**@inheritDoc */
  28531. __proto.destroy=function(destroyChild){
  28532. (destroyChild===void 0)&& (destroyChild=true);
  28533. _super.prototype.destroy.call(this,destroyChild);
  28534. this._clipPoint=null;
  28535. this._lines=null;
  28536. this._lineWidths=null;
  28537. this._words && this._words.forEach(function(w){
  28538. w.cleanCache();
  28539. });
  28540. this._words=null;
  28541. this._charSize=null;
  28542. }
  28543. /**
  28544. *@private
  28545. *@inheritDoc
  28546. */
  28547. __proto._getBoundPointsM=function(ifRotate){
  28548. (ifRotate===void 0)&& (ifRotate=false);
  28549. var rec=Rectangle.TEMP;
  28550. rec.setTo(0,0,this.width,this.height);
  28551. return rec._getBoundPoints();
  28552. }
  28553. /**
  28554. *@inheritDoc
  28555. */
  28556. __proto.getGraphicBounds=function(realSize){
  28557. (realSize===void 0)&& (realSize=false);
  28558. var rec=Rectangle.TEMP;
  28559. rec.setTo(0,0,this.width,this.height);
  28560. return rec;
  28561. }
  28562. /**
  28563. *@private
  28564. */
  28565. __proto._getCSSStyle=function(){
  28566. return this._style;
  28567. }
  28568. /**
  28569. *<p>根据指定的文本,从语言包中取当前语言的文本内容。并对此文本中的{i}文本进行替换。</p>
  28570. *<p>设置Text.langPacks语言包后,即可使用lang获取里面的语言</p>
  28571. *<p>例如:
  28572. *<li>(1)text 的值为“我的名字”,先取到这个文本对应的当前语言版本里的值“My name”,将“My name”设置为当前文本的内容。</li>
  28573. *<li>(2)text 的值为“恭喜你赢得{0}个钻石,{1}经验。”,arg1 的值为100,arg2 的值为200。
  28574. *则先取到这个文本对应的当前语言版本里的值“Congratulations on your winning {0}diamonds,{1}experience.”,
  28575. *然后将文本里的{0}、{1},依据括号里的数字从0开始替换为 arg1、arg2 的值。
  28576. *将替换处理后的文本“Congratulations on your winning 100 diamonds,200 experience.”设置为当前文本的内容。
  28577. *</li>
  28578. *</p>
  28579. *@param text 文本内容。
  28580. *@param ...args 文本替换参数。
  28581. */
  28582. __proto.lang=function(text,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10){
  28583. text=Text.langPacks && Text.langPacks[text] ? Text.langPacks[text] :text;
  28584. if (arguments.length < 2){
  28585. this._text=text;
  28586. }else {
  28587. for (var i=0,n=arguments.length;i < n;i++){
  28588. text=text.replace("{"+i+"}",arguments[i+1]);
  28589. }
  28590. this._text=text;
  28591. }
  28592. }
  28593. /**
  28594. *@private
  28595. */
  28596. __proto._getContextFont=function(){
  28597. return (this.italic ? "italic " :"")+(this.bold ? "bold " :"")+this.fontSize+"px "+(Browser.onIPhone ? (laya.display.Text.fontFamilyMap[this.font] || this.font):this.font);
  28598. }
  28599. /**
  28600. *@private
  28601. */
  28602. __proto._isPassWordMode=function(){
  28603. var style=this._style;
  28604. var password=style.asPassword;
  28605. if (("prompt" in this)&& this['prompt']==this._text)
  28606. password=false;
  28607. return password;
  28608. }
  28609. /**
  28610. *@private
  28611. */
  28612. __proto._getPassWordTxt=function(txt){
  28613. var len=txt.length;
  28614. var word;
  28615. word="";
  28616. for (var j=len;j > 0;j--){
  28617. word+="●";
  28618. }
  28619. return word;
  28620. }
  28621. /**
  28622. *@private
  28623. *渲染文字。
  28624. *@param begin 开始渲染的行索引。
  28625. *@param visibleLineCount 渲染的行数。
  28626. */
  28627. __proto._renderText=function(){
  28628. var padding=this.padding;
  28629. var visibleLineCount=this._lines.length;
  28630. if (this.overflow !="visible"){
  28631. visibleLineCount=Math.min(visibleLineCount,Math.floor((this.height-padding[0]-padding[2])/ (this.leading+this._charSize.height))+1);
  28632. };
  28633. var beginLine=this.scrollY / (this._charSize.height+this.leading)| 0;
  28634. var graphics=this.graphics;
  28635. graphics.clear(true);
  28636. var ctxFont=this._getContextFont();
  28637. Browser.context.font=ctxFont;
  28638. var startX=padding[3];
  28639. var textAlgin="left";
  28640. var lines=this._lines;
  28641. var lineHeight=this.leading+this._charSize.height;
  28642. var tCurrBitmapFont=(this._style).currBitmapFont;
  28643. if (tCurrBitmapFont){
  28644. lineHeight=this.leading+tCurrBitmapFont.getMaxHeight();
  28645. };
  28646. var startY=padding[0];
  28647. if ((!tCurrBitmapFont)&& this._width > 0 && this._textWidth <=this._width){
  28648. if (this.align=="right"){
  28649. textAlgin="right";
  28650. startX=this._width-padding[1];
  28651. }else if (this.align=="center"){
  28652. textAlgin="center";
  28653. startX=this._width *0.5+padding[3]-padding[1];
  28654. }
  28655. }
  28656. if (this._height > 0){
  28657. var tempVAlign=(this._textHeight > this._height)? "top" :this.valign;
  28658. if (tempVAlign==="middle")
  28659. startY=(this._height-visibleLineCount *lineHeight)*0.5+padding[0]-padding[2];
  28660. else if (tempVAlign==="bottom")
  28661. startY=this._height-visibleLineCount *lineHeight-padding[2];
  28662. };
  28663. var style=this._style;
  28664. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize){
  28665. var bitmapScale=tCurrBitmapFont.fontSize / this.fontSize;
  28666. }
  28667. if (this._clipPoint){
  28668. graphics.save();
  28669. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize){
  28670. var tClipWidth=0;
  28671. var tClipHeight=0;
  28672. this._width ? tClipWidth=(this._width-padding[3]-padding[1]):tClipWidth=this._textWidth;
  28673. this._height ? tClipHeight=(this._height-padding[0]-padding[2]):tClipHeight=this._textHeight;
  28674. tClipWidth *=bitmapScale;
  28675. tClipHeight *=bitmapScale;
  28676. graphics.clipRect(padding[3],padding[0],tClipWidth,tClipHeight);
  28677. }else {
  28678. graphics.clipRect(padding[3],padding[0],this._width ? (this._width-padding[3]-padding[1]):this._textWidth,this._height ? (this._height-padding[0]-padding[2]):this._textHeight);
  28679. }
  28680. this.repaint();
  28681. };
  28682. var password=style.asPassword;
  28683. if (("prompt" in this)&& this['prompt']==this._text)
  28684. password=false;
  28685. var x=0,y=0;
  28686. var end=Math.min(this._lines.length,visibleLineCount+beginLine)|| 1;
  28687. for (var i=beginLine;i < end;i++){
  28688. var word=lines[i];
  28689. var _word;
  28690. if (password){
  28691. var len=word.length;
  28692. word="";
  28693. for (var j=len;j > 0;j--){
  28694. word+="●";
  28695. }
  28696. }
  28697. if (word==null)word="";
  28698. x=startX-(this._clipPoint ? this._clipPoint.x :0);
  28699. y=startY+lineHeight *i-(this._clipPoint ? this._clipPoint.y :0);
  28700. this.underline && this._drawUnderline(textAlgin,x,y,i);
  28701. if (tCurrBitmapFont){
  28702. var tWidth=this.width;
  28703. if (tCurrBitmapFont.autoScaleSize){
  28704. tWidth=this.width *bitmapScale;
  28705. }
  28706. tCurrBitmapFont._drawText(word,this,x,y,this.align,tWidth);
  28707. }else {
  28708. this._words || (this._words=[]);
  28709. if (this._words.length > (i-beginLine)){
  28710. _word=this._words[i-beginLine];
  28711. }else {
  28712. _word=new WordText();
  28713. this._words.push(_word);
  28714. }
  28715. _word.setText(word);
  28716. (_word).splitRender=this._singleCharRender;
  28717. style.stroke ? graphics.fillBorderText(_word,x,y,ctxFont,this.color,style.strokeColor,style.stroke,textAlgin):graphics.fillText(_word,x,y,ctxFont,this.color,textAlgin);
  28718. }
  28719. }
  28720. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize){
  28721. var tScale=1 / bitmapScale;
  28722. this.scale(tScale,tScale);
  28723. }
  28724. if (this._clipPoint)graphics.restore();
  28725. this._startX=startX;
  28726. this._startY=startY;
  28727. }
  28728. /**
  28729. *@private
  28730. *绘制下划线
  28731. *@param x 本行坐标
  28732. *@param y 本行坐标
  28733. *@param lineIndex 本行索引
  28734. */
  28735. __proto._drawUnderline=function(align,x,y,lineIndex){
  28736. var lineWidth=this._lineWidths[lineIndex];
  28737. switch (align){
  28738. case 'center':
  28739. x-=lineWidth / 2;
  28740. break ;
  28741. case 'right':
  28742. x-=lineWidth;
  28743. break ;
  28744. case 'left':
  28745. default :
  28746. break ;
  28747. }
  28748. y+=this._charSize.height;
  28749. this._graphics.drawLine(x,y,x+lineWidth,y,this.underlineColor || this.color,1);
  28750. }
  28751. /**
  28752. *<p>排版文本。</p>
  28753. *<p>进行宽高计算,渲染、重绘文本。</p>
  28754. */
  28755. __proto.typeset=function(){
  28756. this._isChanged=false;
  28757. if (!this._text){
  28758. this._clipPoint=null;
  28759. this._textWidth=this._textHeight=0;
  28760. this.graphics.clear(true);
  28761. return;
  28762. }
  28763. if (Render.isConchApp){
  28764. /*__JS__ */window.conchTextCanvas.font=this._getContextFont();;
  28765. }else{
  28766. Browser.context.font=this._getContextFont();
  28767. }
  28768. this._lines.length=0;
  28769. this._lineWidths.length=0;
  28770. if (this._isPassWordMode()){
  28771. this._parseLines(this._getPassWordTxt(this._text));
  28772. }else
  28773. this._parseLines(this._text);
  28774. this._evalTextSize();
  28775. if (this._checkEnabledViewportOrNot())this._clipPoint || (this._clipPoint=new Point(0,0));
  28776. else this._clipPoint=null;
  28777. this._renderText();
  28778. }
  28779. /**@private */
  28780. __proto._evalTextSize=function(){
  28781. var nw=NaN,nh=NaN;
  28782. nw=Math.max.apply(this,this._lineWidths);
  28783. if ((this._style).currBitmapFont)
  28784. nh=this._lines.length *((this._style).currBitmapFont.getMaxHeight()+this.leading)+this.padding[0]+this.padding[2];
  28785. else
  28786. nh=this._lines.length *(this._charSize.height+this.leading)+this.padding[0]+this.padding[2];
  28787. if (nw !=this._textWidth || nh !=this._textHeight){
  28788. this._textWidth=nw;
  28789. this._textHeight=nh;
  28790. }
  28791. }
  28792. /**@private */
  28793. __proto._checkEnabledViewportOrNot=function(){
  28794. return this.overflow=="scroll" && ((this._width > 0 && this._textWidth > this._width)|| (this._height > 0 && this._textHeight > this._height));
  28795. }
  28796. /**
  28797. *<p>快速更改显示文本。不进行排版计算,效率较高。</p>
  28798. *<p>如果只更改文字内容,不更改文字样式,建议使用此接口,能提高效率。</p>
  28799. *@param text 文本内容。
  28800. */
  28801. __proto.changeText=function(text){
  28802. if (this._text!==text){
  28803. this.lang(text+"");
  28804. if (this._graphics && this._graphics.replaceText(this._text)){
  28805. }else {
  28806. this.typeset();
  28807. }
  28808. }
  28809. }
  28810. /**
  28811. *@private
  28812. *分析文本换行。
  28813. */
  28814. __proto._parseLines=function(text){
  28815. var needWordWrapOrTruncate=this.wordWrap || this.overflow=="hidden";
  28816. if (needWordWrapOrTruncate){
  28817. var wordWrapWidth=this._getWordWrapWidth();
  28818. };
  28819. var bitmapFont=(this._style).currBitmapFont;
  28820. if (bitmapFont){
  28821. this._charSize.width=bitmapFont.getMaxWidth();
  28822. this._charSize.height=bitmapFont.getMaxHeight();
  28823. }else {
  28824. var measureResult=null;
  28825. if (Render.isConchApp){
  28826. measureResult=/*__JS__ */window.conchTextCanvas.measureText(this._testWord);
  28827. }else {
  28828. measureResult=Browser.context.measureText(Text._testWord);
  28829. }
  28830. if (!measureResult)measureResult={width:100 };
  28831. this._charSize.width=measureResult.width;
  28832. this._charSize.height=(measureResult.height || this.fontSize);
  28833. };
  28834. var lines=text.replace(/\r\n/g,"\n").split("\n");
  28835. for (var i=0,n=lines.length;i < n;i++){
  28836. var line=lines[i];
  28837. if (needWordWrapOrTruncate)
  28838. this._parseLine(line,wordWrapWidth);
  28839. else {
  28840. this._lineWidths.push(this._getTextWidth(line));
  28841. this._lines.push(line);
  28842. }
  28843. }
  28844. }
  28845. /**
  28846. *@private
  28847. *解析行文本。
  28848. *@param line 某行的文本。
  28849. *@param wordWrapWidth 文本的显示宽度。
  28850. */
  28851. __proto._parseLine=function(line,wordWrapWidth){
  28852. var ctx=Browser.context;
  28853. var lines=this._lines;
  28854. var maybeIndex=0;
  28855. var execResult;
  28856. var charsWidth=NaN;
  28857. var wordWidth=NaN;
  28858. var startIndex=0;
  28859. charsWidth=this._getTextWidth(line);
  28860. if (charsWidth <=wordWrapWidth){
  28861. lines.push(line);
  28862. this._lineWidths.push(charsWidth);
  28863. return;
  28864. }
  28865. charsWidth=this._charSize.width;
  28866. maybeIndex=Math.floor(wordWrapWidth / charsWidth);
  28867. (maybeIndex==0)&& (maybeIndex=1);
  28868. charsWidth=this._getTextWidth(line.substring(0,maybeIndex));
  28869. wordWidth=charsWidth;
  28870. for (var j=maybeIndex,m=line.length;j < m;j++){
  28871. charsWidth=this._getTextWidth(line.charAt(j));
  28872. wordWidth+=charsWidth;
  28873. if (wordWidth > wordWrapWidth){
  28874. if (this.wordWrap){
  28875. var newLine=line.substring(startIndex,j);
  28876. if (newLine.charCodeAt(newLine.length-1)< 255){
  28877. execResult=/(?:\w|-)+$/.exec(newLine);
  28878. if (execResult){
  28879. j=execResult.index+startIndex;
  28880. if (execResult.index==0)j+=newLine.length;
  28881. else newLine=line.substring(startIndex,j);
  28882. }
  28883. }
  28884. lines.push(newLine);
  28885. this._lineWidths.push(wordWidth-charsWidth);
  28886. startIndex=j;
  28887. if (j+maybeIndex < m){
  28888. j+=maybeIndex;
  28889. charsWidth=this._getTextWidth(line.substring(startIndex,j));
  28890. wordWidth=charsWidth;
  28891. j--;
  28892. }else {
  28893. lines.push(line.substring(startIndex,m));
  28894. this._lineWidths.push(this._getTextWidth(lines[lines.length-1]));
  28895. startIndex=-1;
  28896. break ;
  28897. }
  28898. }else if (this.overflow=="hidden"){
  28899. lines.push(line.substring(0,j));
  28900. this._lineWidths.push(this._getTextWidth(lines[lines.length-1]));
  28901. return;
  28902. }
  28903. }
  28904. }
  28905. if (this.wordWrap && startIndex !=-1){
  28906. lines.push(line.substring(startIndex,m));
  28907. this._lineWidths.push(this._getTextWidth(lines[lines.length-1]));
  28908. }
  28909. }
  28910. /**@private */
  28911. __proto._getTextWidth=function(text){
  28912. var bitmapFont=(this._style).currBitmapFont;
  28913. if (bitmapFont)return bitmapFont.getTextWidth(text);
  28914. else {
  28915. if (Render.isConchApp){
  28916. return /*__JS__ */window.conchTextCanvas.measureText(text).width;;
  28917. }
  28918. else return Browser.context.measureText(text).width;
  28919. }
  28920. }
  28921. /**
  28922. *@private
  28923. *获取换行所需的宽度。
  28924. */
  28925. __proto._getWordWrapWidth=function(){
  28926. var p=this.padding;
  28927. var w=NaN;
  28928. var bitmapFont=(this._style).currBitmapFont;
  28929. if (bitmapFont && bitmapFont.autoScaleSize)w=this._width *(bitmapFont.fontSize / this.fontSize);
  28930. else w=this._width;
  28931. if (w <=0){
  28932. w=this.wordWrap ? 100 :Browser.width;
  28933. }
  28934. w <=0 && (w=100);
  28935. return w-p[3]-p[1];
  28936. }
  28937. /**
  28938. *返回字符在本类实例的父坐标系下的坐标。
  28939. *@param charIndex 索引位置。
  28940. *@param out (可选)输出的Point引用。
  28941. *@return Point 字符在本类实例的父坐标系下的坐标。如果out参数不为空,则将结果赋值给指定的Point对象,否则创建一个新的Point对象返回。建议使用Point.TEMP作为out参数,可以省去Point对象创建和垃圾回收的开销,尤其是在需要频繁执行的逻辑中,比如帧循环和MOUSE_MOVE事件回调函数里面。
  28942. */
  28943. __proto.getCharPoint=function(charIndex,out){
  28944. this._isChanged && Laya.systemTimer.runCallLater(this,this.typeset);
  28945. var len=0,lines=this._lines,startIndex=0;
  28946. for (var i=0,n=lines.length;i < n;i++){
  28947. len+=lines[i].length;
  28948. if (charIndex < len){
  28949. var line=i;
  28950. break ;
  28951. }
  28952. startIndex=len;
  28953. };
  28954. var ctxFont=(this.italic ? "italic " :"")+(this.bold ? "bold " :"")+this.fontSize+"px "+this.font;
  28955. Browser.context.font=ctxFont;
  28956. var width=this._getTextWidth(this._text.substring(startIndex,charIndex));
  28957. var point=out || new Point();
  28958. return point.setTo(this._startX+width-(this._clipPoint ? this._clipPoint.x :0),this._startY+line *(this._charSize.height+this.leading)-(this._clipPoint ? this._clipPoint.y :0));
  28959. }
  28960. /**
  28961. *@inheritDoc
  28962. */
  28963. __getset(0,__proto,'width',function(){
  28964. if (this._width)return this._width;
  28965. return this.textWidth+this.padding[1]+this.padding[3];
  28966. },function(value){
  28967. if (value !=this._width){
  28968. Laya.superSet(Sprite,this,'width',value);
  28969. this.isChanged=true;
  28970. if (this.borderColor){
  28971. this._setBorderStyleColor(0,0,this.width,this.height,this.borderColor,1);
  28972. }
  28973. }
  28974. });
  28975. /**
  28976. *表示文本的宽度,以像素为单位。
  28977. */
  28978. __getset(0,__proto,'textWidth',function(){
  28979. this._isChanged && Laya.systemTimer.runCallLater(this,this.typeset);
  28980. return this._textWidth;
  28981. });
  28982. /**
  28983. *@inheritDoc
  28984. */
  28985. __getset(0,__proto,'height',function(){
  28986. if (this._height)return this._height;
  28987. return this.textHeight;
  28988. },function(value){
  28989. if (value !=this._height){
  28990. Laya.superSet(Sprite,this,'height',value);
  28991. this.isChanged=true;
  28992. if (this.borderColor){
  28993. this._setBorderStyleColor(0,0,this.width,this.height,this.borderColor,1);
  28994. }
  28995. }
  28996. });
  28997. /**
  28998. *表示文本的高度,以像素为单位。
  28999. */
  29000. __getset(0,__proto,'textHeight',function(){
  29001. this._isChanged && Laya.systemTimer.runCallLater(this,this.typeset);
  29002. return this._textHeight;
  29003. });
  29004. /**
  29005. *<p>边距信息。</p>
  29006. *<p>数据格式:[上边距,右边距,下边距,左边距](边距以像素为单位)。</p>
  29007. */
  29008. __getset(0,__proto,'padding',function(){
  29009. return (this._style).padding;
  29010. },function(value){
  29011. if ((typeof value=='string')){
  29012. var arr;
  29013. arr=(value).split(",");
  29014. var i=0,len=0;
  29015. len=arr.length;
  29016. while (arr.length < 4){
  29017. arr.push(0);
  29018. }
  29019. for (i=0;i < len;i++){
  29020. arr[i]=parseFloat(arr[i])|| 0;
  29021. }
  29022. value=arr;
  29023. }
  29024. this._getTextStyle().padding=value;
  29025. this.isChanged=true;
  29026. });
  29027. /**
  29028. *<p>指定文本是否为粗体字。</p>
  29029. *<p>默认值为 false,这意味着不使用粗体字。如果值为 true,则文本为粗体字。</p>
  29030. */
  29031. __getset(0,__proto,'bold',function(){
  29032. return (this._style).bold;
  29033. },function(value){
  29034. this._getTextStyle().bold=value;
  29035. this.isChanged=true;
  29036. });
  29037. /**当前文本的内容字符串。*/
  29038. __getset(0,__proto,'text',function(){
  29039. return this._text || "";
  29040. },function(value){
  29041. if (this._text!==value){
  29042. this.lang(value+"");
  29043. this.isChanged=true;
  29044. this.event(/*laya.events.Event.CHANGE*/"change");
  29045. if (this.borderColor){
  29046. this._setBorderStyleColor(0,0,this.width,this.height,this.borderColor,1);
  29047. }
  29048. }
  29049. });
  29050. /**
  29051. *<p>表示文本的颜色值。可以通过 <code>Text.defaultColor</code> 设置默认颜色。</p>
  29052. *<p>默认值为黑色。</p>
  29053. */
  29054. __getset(0,__proto,'color',function(){
  29055. return this._color;
  29056. },function(value){
  29057. if (this._color !=value){
  29058. this._color=value;
  29059. if (!this._isChanged && this._graphics){
  29060. this._graphics.replaceTextColor(this.color)
  29061. }else {
  29062. this.isChanged=true;
  29063. }
  29064. }
  29065. });
  29066. /**
  29067. *<p>文本的字体名称,以字符串形式表示。</p>
  29068. *<p>默认值为:"Arial",可以通过Text.defaultFont设置默认字体。</p>
  29069. *<p>如果运行时系统找不到设定的字体,则用系统默认的字体渲染文字,从而导致显示异常。(通常电脑上显示正常,在一些移动端因缺少设置的字体而显示异常)。</p>
  29070. *@see laya.display.Text#defaultFont
  29071. */
  29072. __getset(0,__proto,'font',function(){
  29073. return this._font;
  29074. },function(value){
  29075. if ((this._style).currBitmapFont){
  29076. this._getTextStyle().currBitmapFont=null;
  29077. this.scale(1,1);
  29078. }
  29079. if (Text._bitmapFonts && Text._bitmapFonts[value]){
  29080. this._getTextStyle().currBitmapFont=Text._bitmapFonts[value];
  29081. }
  29082. this._font=value;
  29083. this.isChanged=true;
  29084. });
  29085. /**
  29086. *<p>指定文本的字体大小(以像素为单位)。</p>
  29087. *<p>默认为20像素,可以通过 <code>Text.defaultFontSize</code> 设置默认大小。</p>
  29088. */
  29089. __getset(0,__proto,'fontSize',function(){
  29090. return this._fontSize;
  29091. },function(value){
  29092. if (this._fontSize !=value){
  29093. this._fontSize=value;
  29094. this.isChanged=true;
  29095. }
  29096. });
  29097. /**
  29098. *<p>表示使用此文本格式的文本是否为斜体。</p>
  29099. *<p>默认值为 false,这意味着不使用斜体。如果值为 true,则文本为斜体。</p>
  29100. */
  29101. __getset(0,__proto,'italic',function(){
  29102. return (this._style).italic;
  29103. },function(value){
  29104. this._getTextStyle().italic=value;
  29105. this.isChanged=true;
  29106. });
  29107. /**
  29108. *<p>表示文本的水平显示方式。</p>
  29109. *<p><b>取值:</b>
  29110. *<li>"left": 居左对齐显示。</li>
  29111. *<li>"center": 居中对齐显示。</li>
  29112. *<li>"right": 居右对齐显示。</li>
  29113. *</p>
  29114. */
  29115. __getset(0,__proto,'align',function(){
  29116. return (this._style).align;
  29117. },function(value){
  29118. this._getTextStyle().align=value;
  29119. this.isChanged=true;
  29120. });
  29121. /**
  29122. *<p>表示文本的垂直显示方式。</p>
  29123. *<p><b>取值:</b>
  29124. *<li>"top": 居顶部对齐显示。</li>
  29125. *<li>"middle": 居中对齐显示。</li>
  29126. *<li>"bottom": 居底部对齐显示。</li>
  29127. *</p>
  29128. */
  29129. __getset(0,__proto,'valign',function(){
  29130. return this._valign;
  29131. },function(value){
  29132. this._valign=value;
  29133. this.isChanged=true;
  29134. });
  29135. /**
  29136. *<p>表示文本是否自动换行,默认为false。</p>
  29137. *<p>若值为true,则自动换行;否则不自动换行。</p>
  29138. */
  29139. __getset(0,__proto,'wordWrap',function(){
  29140. return (this._style).wordWrap;
  29141. },function(value){
  29142. this._getTextStyle().wordWrap=value;
  29143. this.isChanged=true;
  29144. });
  29145. /**设置是否单个字符渲染,如果Textd的内容一直改变,例如是一个增加的数字,就设置这个,防止无效占用缓存 */
  29146. __getset(0,__proto,'singleCharRender',function(){
  29147. return this._singleCharRender;
  29148. },function(value){
  29149. this._singleCharRender=value;
  29150. });
  29151. /**
  29152. *垂直行间距(以像素为单位)。
  29153. */
  29154. __getset(0,__proto,'leading',function(){
  29155. return (this._style).leading;
  29156. },function(value){
  29157. this._getTextStyle().leading=value;
  29158. this.isChanged=true;
  29159. });
  29160. /**
  29161. *文本背景颜色,以字符串表示。
  29162. */
  29163. __getset(0,__proto,'bgColor',function(){
  29164. return (this._style).bgColor;
  29165. },function(value){
  29166. this._getTextStyle().bgColor=value;
  29167. this._renderType |=/*laya.display.SpriteConst.STYLE*/0x80;
  29168. this._setBgStyleColor(0,0,this.width,this.height,value);
  29169. this._setRenderType(this._renderType);
  29170. this.isChanged=true;
  29171. });
  29172. /**
  29173. *文本边框背景颜色,以字符串表示。
  29174. */
  29175. __getset(0,__proto,'borderColor',function(){
  29176. return (this._style).borderColor;
  29177. },function(value){
  29178. this._getTextStyle().borderColor=value;
  29179. this._renderType |=/*laya.display.SpriteConst.STYLE*/0x80;
  29180. this._setBorderStyleColor(0,0,this.width,this.height,value,1);
  29181. this._setRenderType(this._renderType);
  29182. this.isChanged=true;
  29183. });
  29184. /**
  29185. *<p>描边宽度(以像素为单位)。</p>
  29186. *<p>默认值0,表示不描边。</p>
  29187. */
  29188. __getset(0,__proto,'stroke',function(){
  29189. return (this._style).stroke;
  29190. },function(value){
  29191. this._getTextStyle().stroke=value;
  29192. this.isChanged=true;
  29193. });
  29194. /**
  29195. *<p>描边颜色,以字符串表示。</p>
  29196. *<p>默认值为 "#000000"(黑色);</p>
  29197. */
  29198. __getset(0,__proto,'strokeColor',function(){
  29199. return (this._style).strokeColor;
  29200. },function(value){
  29201. this._getTextStyle().strokeColor=value;
  29202. this.isChanged=true;
  29203. });
  29204. /**
  29205. *@private
  29206. *一个布尔值,表示文本的属性是否有改变。若为true表示有改变。
  29207. */
  29208. __getset(0,__proto,'isChanged',null,function(value){
  29209. if (this._isChanged!==value){
  29210. this._isChanged=value;
  29211. value && Laya.systemTimer.callLater(this,this.typeset);
  29212. }
  29213. });
  29214. /**
  29215. *<p>设置横向滚动量。</p>
  29216. *<p>即使设置超出滚动范围的值,也会被自动限制在可能的最大值处。</p>
  29217. */
  29218. /**
  29219. *获取横向滚动量。
  29220. */
  29221. __getset(0,__proto,'scrollX',function(){
  29222. if (!this._clipPoint)return 0;
  29223. return this._clipPoint.x;
  29224. },function(value){
  29225. if (this.overflow !="scroll" || (this.textWidth < this._width || !this._clipPoint))return;
  29226. value=value < this.padding[3] ? this.padding[3] :value;
  29227. var maxScrollX=this._textWidth-this._width;
  29228. value=value > maxScrollX ? maxScrollX :value;
  29229. this._clipPoint.x=value;
  29230. this._renderText();
  29231. });
  29232. /**
  29233. *设置纵向滚动量(px)。即使设置超出滚动范围的值,也会被自动限制在可能的最大值处。
  29234. */
  29235. /**
  29236. *获取纵向滚动量。
  29237. */
  29238. __getset(0,__proto,'scrollY',function(){
  29239. if (!this._clipPoint)return 0;
  29240. return this._clipPoint.y;
  29241. },function(value){
  29242. if (this.overflow !="scroll" || (this.textHeight < this._height || !this._clipPoint))return;
  29243. value=value < this.padding[0] ? this.padding[0] :value;
  29244. var maxScrollY=this._textHeight-this._height;
  29245. value=value > maxScrollY ? maxScrollY :value;
  29246. this._clipPoint.y=value;
  29247. this._renderText();
  29248. });
  29249. /**
  29250. *获取横向可滚动最大值。
  29251. */
  29252. __getset(0,__proto,'maxScrollX',function(){
  29253. return (this.textWidth < this._width)? 0 :this._textWidth-this._width;
  29254. });
  29255. /**
  29256. *获取纵向可滚动最大值。
  29257. */
  29258. __getset(0,__proto,'maxScrollY',function(){
  29259. return (this.textHeight < this._height)? 0 :this._textHeight-this._height;
  29260. });
  29261. /**返回文字行信息*/
  29262. __getset(0,__proto,'lines',function(){
  29263. if (this._isChanged)this.typeset();
  29264. return this._lines;
  29265. });
  29266. /**下划线的颜色,为null则使用字体颜色。*/
  29267. __getset(0,__proto,'underlineColor',function(){
  29268. return (this._style).underlineColor;
  29269. },function(value){
  29270. this._getTextStyle().underlineColor=value;
  29271. if (!this._isChanged)this._renderText();
  29272. });
  29273. /**是否显示下划线。*/
  29274. __getset(0,__proto,'underline',function(){
  29275. return (this._style).underline;
  29276. },function(value){
  29277. this._getTextStyle().underline=value;
  29278. });
  29279. Text.defaultFontStr=function(){
  29280. return Text.defaultFontSize+"px "+Text.defaultFont;
  29281. }
  29282. Text.registerBitmapFont=function(name,bitmapFont){
  29283. Text._bitmapFonts || (Text._bitmapFonts={});
  29284. Text._bitmapFonts[name]=bitmapFont;
  29285. }
  29286. Text.unregisterBitmapFont=function(name,destroy){
  29287. (destroy===void 0)&& (destroy=true);
  29288. if (Text._bitmapFonts && Text._bitmapFonts[name]){
  29289. var tBitmapFont=Text._bitmapFonts[name];
  29290. if (destroy)tBitmapFont.destroy();
  29291. delete Text._bitmapFonts[name];
  29292. }
  29293. }
  29294. Text.VISIBLE="visible";
  29295. Text.SCROLL="scroll";
  29296. Text.HIDDEN="hidden";
  29297. Text.defaultFontSize=12;
  29298. Text.defaultFont="Arial";
  29299. Text.langPacks=null;
  29300. Text.isComplexText=false;
  29301. Text._testWord="游";
  29302. Text._bitmapFonts=null;
  29303. Text.CharacterCache=true;
  29304. Text.RightToLeft=false;
  29305. __static(Text,
  29306. ['fontFamilyMap',function(){return this.fontFamilyMap={"报隶":"报隶-简","黑体":"黑体-简","楷体":"楷体-简","兰亭黑":"兰亭黑-简","隶变":"隶变-简","凌慧体":"凌慧体-简","翩翩体":"翩翩体-简","苹方":"苹方-简","手札体":"手札体-简","宋体":"宋体-简","娃娃体":"娃娃体-简","魏碑":"魏碑-简","行楷":"行楷-简","雅痞":"雅痞-简","圆体":"圆体-简"};}
  29307. ]);
  29308. return Text;
  29309. })(Sprite)
  29310. /**
  29311. *<code>HTMLCanvas</code> 是 Html Canvas 的代理类,封装了 Canvas 的属性和方法。
  29312. */
  29313. //class laya.resource.HTMLCanvas extends laya.resource.Bitmap
  29314. var HTMLCanvas=(function(_super){
  29315. function HTMLCanvas(createCanvas){
  29316. //this._ctx=null;
  29317. //this._source=null;
  29318. //this._texture=null;
  29319. HTMLCanvas.__super.call(this);
  29320. (createCanvas===void 0)&& (createCanvas=false);
  29321. if(createCanvas)
  29322. this._source=Browser.createElement("canvas");
  29323. else {
  29324. this._source=this;
  29325. }
  29326. this.lock=true;
  29327. }
  29328. __class(HTMLCanvas,'laya.resource.HTMLCanvas',_super);
  29329. var __proto=HTMLCanvas.prototype;
  29330. __proto._getSource=function(){
  29331. return this._source;
  29332. }
  29333. /**
  29334. *清空画布内容。
  29335. */
  29336. __proto.clear=function(){
  29337. this._ctx && this._ctx.clear && this._ctx.clear();
  29338. if (this._texture){
  29339. this._texture.destroy();
  29340. this._texture=null;
  29341. }
  29342. }
  29343. /**
  29344. *销毁。
  29345. */
  29346. __proto.destroy=function(){
  29347. laya.resource.Resource.prototype.destroy.call(this);
  29348. this._setCPUMemory(0);
  29349. this._ctx && this._ctx.destroy();
  29350. this._ctx=null;
  29351. }
  29352. /**
  29353. *释放。
  29354. */
  29355. __proto.release=function(){}
  29356. /**
  29357. *@private
  29358. *设置 Canvas 渲染上下文。是webgl用来替换_ctx用的
  29359. *@param context Canvas 渲染上下文。
  29360. */
  29361. __proto._setContext=function(context){
  29362. this._ctx=context;
  29363. }
  29364. /**
  29365. *获取 Canvas 渲染上下文。
  29366. *@param contextID 上下文ID.
  29367. *@param other
  29368. *@return Canvas 渲染上下文 Context 对象。
  29369. */
  29370. __proto.getContext=function(contextID,other){
  29371. return this.context;
  29372. }
  29373. //TODO:coverage
  29374. __proto.getMemSize=function(){
  29375. return 0;
  29376. }
  29377. /**
  29378. *设置宽高。
  29379. *@param w 宽度。
  29380. *@param h 高度。
  29381. */
  29382. __proto.size=function(w,h){
  29383. if (this._width !=w || this._height !=h || (this._source && (this._source.width !=w || this._source.height !=h))){
  29384. this._width=w;
  29385. this._height=h;
  29386. this._setCPUMemory(w *h *4);
  29387. this._ctx && this._ctx.size && this._ctx.size(w,h);
  29388. this._source && (this._source.height=h,this._source.width=w);
  29389. if (this._texture){
  29390. this._texture.destroy();
  29391. this._texture=null;
  29392. }
  29393. }
  29394. }
  29395. /**
  29396. *获取texture实例
  29397. */
  29398. __proto.getTexture=function(){
  29399. if (!this._texture){
  29400. var bitmap=new Texture2D();
  29401. bitmap.loadImageSource(this.source);
  29402. this._texture=new Texture(bitmap);
  29403. }
  29404. return this._texture;
  29405. }
  29406. /**
  29407. *把图片转换为base64信息
  29408. *@param type "image/png"
  29409. *@param encoderOptions 质量参数,取值范围为0-1
  29410. */
  29411. __proto.toBase64=function(type,encoderOptions){
  29412. if (this._source){
  29413. if (Render.isConchApp){
  29414. if (/*__JS__ */conchConfig.threadMode==2){
  29415. throw "native 2 thread mode use toBase64Async";
  29416. };
  29417. var width=this._ctx._targets.sourceWidth;
  29418. var height=this._ctx._targets.sourceHeight;
  29419. var data=this._ctx._targets.getData(0,0,width,height);
  29420. /*__JS__ */return conchToBase64FlipY ? conchToBase64FlipY(type,encoderOptions,data.buffer,width,height):conchToBase64(type,encoderOptions,data.buffer,width,height);
  29421. }
  29422. else {
  29423. return this._source.toDataURL(type,encoderOptions);
  29424. }
  29425. }
  29426. return null;
  29427. }
  29428. //native多线程
  29429. __proto.toBase64Async=function(type,encoderOptions,callBack){
  29430. var width=this._ctx._targets.sourceWidth;
  29431. var height=this._ctx._targets.sourceHeight;
  29432. this._ctx._targets.getDataAsync(0,0,width,height,function(data){
  29433. /*__JS__ */var base64=conchToBase64FlipY ? conchToBase64FlipY(type,encoderOptions,data.buffer,width,height):conchToBase64(type,encoderOptions,data.buffer,width,height);
  29434. /*__JS__ */callBack(base64);
  29435. });
  29436. }
  29437. /**
  29438. *@inheritDoc
  29439. */
  29440. __getset(0,__proto,'source',function(){
  29441. return this._source;
  29442. });
  29443. /**
  29444. *Canvas 渲染上下文。
  29445. */
  29446. __getset(0,__proto,'context',function(){
  29447. if (this._ctx)return this._ctx;
  29448. if (this._source==this){
  29449. this._ctx=new Context();
  29450. }else {
  29451. this._ctx=this._source.getContext(Render.isConchApp?'layagl':'2d');
  29452. }
  29453. this._ctx._canvas=this;
  29454. return this._ctx;
  29455. });
  29456. return HTMLCanvas;
  29457. })(Bitmap)
  29458. /**
  29459. *@private
  29460. *<p> <code>HTMLImage</code> 用于创建 HTML Image 元素。</p>
  29461. *<p>请使用 <code>HTMLImage.create()<code>获取新实例,不要直接使用 <code>new HTMLImage<code> 。</p>
  29462. */
  29463. //class laya.resource.HTMLImage extends laya.resource.Bitmap
  29464. var HTMLImage=(function(_super){
  29465. function HTMLImage(){
  29466. HTMLImage.__super.call(this);;
  29467. }
  29468. __class(HTMLImage,'laya.resource.HTMLImage',_super);
  29469. HTMLImage.create=function(width,height,format){
  29470. var tex=new Texture2D(width,height,format,false,false);
  29471. tex.wrapModeU=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  29472. tex.wrapModeV=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  29473. return tex;
  29474. }
  29475. return HTMLImage;
  29476. })(Bitmap)
  29477. /**
  29478. *节点关键帧动画播放类。解析播放IDE内制作的节点动画。
  29479. */
  29480. //class laya.display.FrameAnimation extends laya.display.AnimationBase
  29481. var FrameAnimation=(function(_super){
  29482. function FrameAnimation(){
  29483. /**@private id对象表*/
  29484. this._targetDic=null;
  29485. /**@private 动画数据*/
  29486. this._animationData=null;
  29487. /**@private */
  29488. this._usedFrames=null;
  29489. FrameAnimation.__super.call(this);
  29490. if (FrameAnimation._sortIndexFun===null){
  29491. FrameAnimation._sortIndexFun=MathUtil.sortByKey("index",false,true);
  29492. }
  29493. }
  29494. __class(FrameAnimation,'laya.display.FrameAnimation',_super);
  29495. var __proto=FrameAnimation.prototype;
  29496. /**
  29497. *@private
  29498. *初始化动画数据
  29499. *@param targetDic 节点ID索引
  29500. *@param animationData 动画数据
  29501. */
  29502. __proto._setUp=function(targetDic,animationData){
  29503. this._targetDic=targetDic;
  29504. this._animationData=animationData;
  29505. this.interval=1000 / animationData.frameRate;
  29506. if (animationData.parsed){
  29507. this._count=animationData.count;
  29508. this._labels=animationData.labels;
  29509. this._usedFrames=animationData.animationNewFrames;
  29510. }else {
  29511. this._usedFrames=[];
  29512. this._calculateDatas();
  29513. animationData.parsed=true;
  29514. animationData.labels=this._labels;
  29515. animationData.count=this._count;
  29516. animationData.animationNewFrames=this._usedFrames;
  29517. }
  29518. }
  29519. /**@inheritDoc */
  29520. __proto.clear=function(){
  29521. _super.prototype.clear.call(this);
  29522. this._targetDic=null;
  29523. this._animationData=null;
  29524. return this;
  29525. }
  29526. /**@inheritDoc */
  29527. __proto._displayToIndex=function(value){
  29528. if (!this._animationData)return;
  29529. if (value < 0)value=0;
  29530. if (value > this._count)value=this._count;
  29531. var nodes=this._animationData.nodes,i=0,len=nodes.length;
  29532. for (i=0;i < len;i++){
  29533. this._displayNodeToFrame(nodes[i],value);
  29534. }
  29535. }
  29536. /**
  29537. *@private
  29538. *将节点设置到某一帧的状态
  29539. *@param node 节点ID
  29540. *@param frame
  29541. *@param targetDic 节点表
  29542. */
  29543. __proto._displayNodeToFrame=function(node,frame,targetDic){
  29544. if (!targetDic)targetDic=this._targetDic;
  29545. var target=targetDic[node.target];
  29546. if (!target){
  29547. return;
  29548. };
  29549. var frames=node.frames,key,propFrames,value;
  29550. var keys=node.keys,i=0,len=keys.length;
  29551. for (i=0;i < len;i++){
  29552. key=keys[i];
  29553. propFrames=frames[key];
  29554. if (propFrames.length > frame){
  29555. value=propFrames[frame];
  29556. }else {
  29557. value=propFrames[propFrames.length-1];
  29558. }
  29559. target[key]=value;
  29560. };
  29561. var funkeys=node.funkeys;
  29562. len=funkeys.length;
  29563. var funFrames;
  29564. if (len==0)return;
  29565. for (i=0;i < len;i++){
  29566. key=funkeys[i];
  29567. funFrames=frames[key];
  29568. if (funFrames[frame]!==undefined){
  29569. target[key]&&target[key].apply(target,funFrames[frame]);
  29570. }
  29571. }
  29572. }
  29573. /**
  29574. *@private
  29575. *计算帧数据
  29576. */
  29577. __proto._calculateDatas=function(){
  29578. if (!this._animationData)return;
  29579. var nodes=this._animationData.nodes,i=0,len=nodes.length,tNode;
  29580. this._count=0;
  29581. for (i=0;i < len;i++){
  29582. tNode=nodes[i];
  29583. this._calculateKeyFrames(tNode);
  29584. }
  29585. this._count+=1;
  29586. }
  29587. /**
  29588. *@private
  29589. *计算某个节点的帧数据
  29590. */
  29591. __proto._calculateKeyFrames=function(node){
  29592. var keyFrames=node.keyframes,key,tKeyFrames,target=node.target;
  29593. if (!node.frames)node.frames={};
  29594. if (!node.keys)node.keys=[];
  29595. else node.keys.length=0;
  29596. if (!node.funkeys)node.funkeys=[];
  29597. else node.funkeys.length=0;
  29598. if (!node.initValues)node.initValues={};
  29599. for (key in keyFrames){
  29600. var isFun=key.indexOf("()")!=-1;
  29601. tKeyFrames=keyFrames[key];
  29602. if (isFun)key=key.substr(0,key.length-2);
  29603. if (!node.frames[key]){
  29604. node.frames[key]=[];
  29605. }
  29606. if (!isFun){
  29607. if (this._targetDic && this._targetDic[target]){
  29608. node.initValues[key]=this._targetDic[target][key];
  29609. }
  29610. tKeyFrames.sort(FrameAnimation._sortIndexFun);
  29611. node.keys.push(key);
  29612. this._calculateNodePropFrames(tKeyFrames,node.frames[key],key,target);
  29613. }
  29614. else{
  29615. node.funkeys.push(key);
  29616. var map=node.frames[key];
  29617. for (var i=0;i < tKeyFrames.length;i++){
  29618. var temp=tKeyFrames[i];
  29619. map[temp.index]=temp.value;
  29620. if (temp.index > this._count)this._count=temp.index;
  29621. }
  29622. }
  29623. }
  29624. }
  29625. /**
  29626. *重置节点,使节点恢复到动画之前的状态,方便其他动画控制
  29627. */
  29628. __proto.resetNodes=function(){
  29629. if (!this._targetDic)return;
  29630. if (!this._animationData)return;
  29631. var nodes=this._animationData.nodes,i=0,len=nodes.length;
  29632. var tNode;
  29633. var initValues;
  29634. for (i=0;i < len;i++){
  29635. tNode=nodes[i];
  29636. initValues=tNode.initValues;
  29637. if (!initValues)continue ;
  29638. var target=this._targetDic[tNode.target];
  29639. if (!target)continue ;
  29640. var key;
  29641. for (key in initValues){
  29642. target[key]=initValues[key];
  29643. }
  29644. }
  29645. }
  29646. /**
  29647. *@private
  29648. *计算节点某个属性的帧数据
  29649. */
  29650. __proto._calculateNodePropFrames=function(keyframes,frames,key,target){
  29651. var i=0,len=keyframes.length-1;
  29652. frames.length=keyframes[len].index+1;
  29653. for (i=0;i < len;i++){
  29654. this._dealKeyFrame(keyframes[i]);
  29655. this._calculateFrameValues(keyframes[i],keyframes[i+1],frames);
  29656. }
  29657. if (len==0){
  29658. frames[0]=keyframes[0].value;
  29659. if (this._usedFrames)this._usedFrames[keyframes[0].index]=true;
  29660. }
  29661. this._dealKeyFrame(keyframes[i]);
  29662. }
  29663. /**
  29664. *@private
  29665. */
  29666. __proto._dealKeyFrame=function(keyFrame){
  29667. if (keyFrame.label && keyFrame.label !="")this.addLabel(keyFrame.label,keyFrame.index);
  29668. }
  29669. /**
  29670. *@private
  29671. *计算两个关键帧直接的帧数据
  29672. */
  29673. __proto._calculateFrameValues=function(startFrame,endFrame,result){
  29674. var i=0,easeFun;
  29675. var start=startFrame.index,end=endFrame.index;
  29676. var startValue=startFrame.value;
  29677. var dValue=endFrame.value-startFrame.value;
  29678. var dLen=end-start;
  29679. var frames=this._usedFrames;
  29680. if (end > this._count)this._count=end;
  29681. if (startFrame.tween){
  29682. easeFun=Ease[startFrame.tweenMethod];
  29683. if (easeFun==null)easeFun=Ease.linearNone;
  29684. for (i=start;i < end;i++){
  29685. result[i]=easeFun(i-start,startValue,dValue,dLen);
  29686. if (frames)frames[i]=true;
  29687. }
  29688. }else {
  29689. for (i=start;i < end;i++){
  29690. result[i]=startValue;
  29691. }
  29692. }
  29693. if (frames){
  29694. frames[startFrame.index]=true;
  29695. frames[endFrame.index]=true;
  29696. }
  29697. result[endFrame.index]=endFrame.value;
  29698. }
  29699. FrameAnimation._sortIndexFun=null;
  29700. return FrameAnimation;
  29701. })(AnimationBase)
  29702. //class laya.webgl.shader.d2.Shader2X extends laya.webgl.shader.Shader
  29703. var Shader2X=(function(_super){
  29704. function Shader2X(vs,ps,saveName,nameMap,bindAttrib){
  29705. this._params2dQuick2=null;
  29706. this._shaderValueWidth=0;
  29707. this._shaderValueHeight=0;
  29708. Shader2X.__super.call(this,vs,ps,saveName,nameMap,bindAttrib);
  29709. }
  29710. __class(Shader2X,'laya.webgl.shader.d2.Shader2X',_super);
  29711. var __proto=Shader2X.prototype;
  29712. //TODO:coverage
  29713. __proto._disposeResource=function(){
  29714. _super.prototype._disposeResource.call(this);
  29715. this._params2dQuick2=null;
  29716. }
  29717. //TODO:coverage
  29718. __proto.upload2dQuick2=function(shaderValue){
  29719. this.upload(shaderValue,this._params2dQuick2 || this._make2dQuick2());
  29720. }
  29721. //去掉size的所有的uniform
  29722. __proto._make2dQuick2=function(){
  29723. if (!this._params2dQuick2){
  29724. this._params2dQuick2=[];
  29725. var params=this._params,one;
  29726. for (var i=0,n=params.length;i < n;i++){
  29727. one=params[i];
  29728. if (one.name!=="size")this._params2dQuick2.push(one);
  29729. }
  29730. }
  29731. return this._params2dQuick2;
  29732. }
  29733. Shader2X.create=function(vs,ps,saveName,nameMap,bindAttrib){
  29734. return new Shader2X(vs,ps,saveName,nameMap,bindAttrib);
  29735. }
  29736. return Shader2X;
  29737. })(Shader)
  29738. /**
  29739. *<p> <code>Animation</code> 是Graphics动画类。实现了基于Graphics的动画创建、播放、控制接口。</p>
  29740. *<p>本类使用了动画模版缓存池,它以一定的内存开销来节省CPU开销,当相同的动画模版被多次使用时,相比于每次都创建新的动画模版,使用动画模版缓存池,只需创建一次,缓存之后多次复用,从而节省了动画模版创建的开销。</p>
  29741. *<p>动画模版缓存池,以key-value键值对存储,key可以自定义,也可以从指定的配置文件中读取,value为对应的动画模版,是一个Graphics对象数组,每个Graphics对象对应一个帧图像,动画的播放实质就是定时切换Graphics对象。</p>
  29742. *<p>使用set source、loadImages(...)、loadAtlas(...)、loadAnimation(...)方法可以创建动画模版。使用play(...)可以播放指定动画。</p>
  29743. *@example <caption>以下示例代码,创建了一个 <code>Text</code> 实例。</caption>
  29744. *package
  29745. *{
  29746. *import laya.display.Animation;
  29747. *import laya.net.Loader;
  29748. *import laya.utils.Handler;
  29749. *public class Animation_Example
  29750. *{
  29751. *public function Animation_Example()
  29752. *{
  29753. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  29754. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  29755. *init();//初始化
  29756. *}
  29757. *private function init():void
  29758. *{
  29759. *var animation:Animation=new Animation();//创建一个 Animation 类的实例对象 animation 。
  29760. *animation.loadAtlas("resource/ani/fighter.json");//加载图集并播放
  29761. *animation.x=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29762. *animation.y=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29763. *animation.interval=50;//设置 animation 对象的动画播放间隔时间,单位:毫秒。
  29764. *animation.play();//播放动画。
  29765. *Laya.stage.addChild(animation);//将 animation 对象添加到显示列表。
  29766. *}
  29767. *}
  29768. *}
  29769. *
  29770. *@example
  29771. *Animation_Example();
  29772. *function Animation_Example(){
  29773. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  29774. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  29775. *init();//初始化
  29776. *}
  29777. *function init()
  29778. *{
  29779. *var animation=new Laya.Animation();//创建一个 Animation 类的实例对象 animation 。
  29780. *animation.loadAtlas("resource/ani/fighter.json");//加载图集并播放
  29781. *animation.x=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29782. *animation.y=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29783. *animation.interval=50;//设置 animation 对象的动画播放间隔时间,单位:毫秒。
  29784. *animation.play();//播放动画。
  29785. *Laya.stage.addChild(animation);//将 animation 对象添加到显示列表。
  29786. *}
  29787. *
  29788. *@example
  29789. *import Animation=laya.display.Animation;
  29790. *class Animation_Example {
  29791. *constructor(){
  29792. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  29793. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  29794. *this.init();
  29795. *}
  29796. *private init():void {
  29797. *var animation:Animation=new Laya.Animation();//创建一个 Animation 类的实例对象 animation 。
  29798. *animation.loadAtlas("resource/ani/fighter.json");//加载图集并播放
  29799. *animation.x=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29800. *animation.y=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29801. *animation.interval=50;//设置 animation 对象的动画播放间隔时间,单位:毫秒。
  29802. *animation.play();//播放动画。
  29803. *Laya.stage.addChild(animation);//将 animation 对象添加到显示列表。
  29804. *}
  29805. *}
  29806. *new Animation_Example();
  29807. */
  29808. //class laya.display.Animation extends laya.display.AnimationBase
  29809. var Animation=(function(_super){
  29810. function Animation(){
  29811. /**@private */
  29812. this._frames=null;
  29813. /**@private */
  29814. this._url=null;
  29815. Animation.__super.call(this);
  29816. this._setControlNode(this);
  29817. }
  29818. __class(Animation,'laya.display.Animation',_super);
  29819. var __proto=Animation.prototype;
  29820. /**@inheritDoc */
  29821. __proto.destroy=function(destroyChild){
  29822. (destroyChild===void 0)&& (destroyChild=true);
  29823. this.stop();
  29824. laya.display.Sprite.prototype.destroy.call(this,destroyChild);
  29825. this._frames=null;
  29826. this._labels=null;
  29827. }
  29828. /**
  29829. *<p>开始播放动画。会在动画模版缓存池中查找key值为name的动画模版,存在则用此动画模版初始化当前序列帧, 如果不存在,则使用当前序列帧。</p>
  29830. *<p>play(...)方法被设计为在创建实例后的任何时候都可以被调用,调用后就处于播放状态,当相应的资源加载完毕、调用动画帧填充方法(set frames)或者将实例显示在舞台上时,会判断是否处于播放状态,如果是,则开始播放。</p>
  29831. *<p>配合wrapMode属性,可设置动画播放顺序类型。</p>
  29832. *@param start (可选)指定动画播放开始的索引(int)或帧标签(String)。帧标签可以通过addLabel(...)和removeLabel(...)进行添加和删除。
  29833. *@param loop (可选)是否循环播放。
  29834. *@param name (可选)动画模板在动画模版缓存池中的key,也可认为是动画名称。如果name为空,则播放当前动画序列帧;如果不为空,则在动画模版缓存池中寻找key值为name的动画模版,如果存在则用此动画模版初始化当前序列帧并播放,如果不存在,则仍然播放当前动画序列帧;如果没有当前动画的帧数据,则不播放,但该实例仍然处于播放状态。
  29835. */
  29836. __proto.play=function(start,loop,name){
  29837. (start===void 0)&& (start=0);
  29838. (loop===void 0)&& (loop=true);
  29839. (name===void 0)&& (name="");
  29840. if (name)this._setFramesFromCache(name,true);
  29841. _super.prototype.play.call(this,start,loop,name);
  29842. }
  29843. /**@private */
  29844. __proto._setFramesFromCache=function(name,showWarn){
  29845. (showWarn===void 0)&& (showWarn=false);
  29846. if (this._url)name=this._url+"#"+name;
  29847. if (name && Animation.framesMap[name]){
  29848. var tAniO=Animation.framesMap[name];
  29849. if ((tAniO instanceof Array)){
  29850. this._frames=Animation.framesMap[name];
  29851. this._count=this._frames.length;
  29852. }else {
  29853. if (tAniO.nodeRoot){
  29854. Animation.framesMap[name]=GraphicAnimation.parseAnimationByData(tAniO);
  29855. tAniO=Animation.framesMap[name];
  29856. }
  29857. this._frames=tAniO.frames;
  29858. this._count=this._frames.length;
  29859. if (!this._frameRateChanged)this._interval=tAniO.interval;
  29860. this._labels=this._copyLabels(tAniO.labels);
  29861. }
  29862. return true;
  29863. }else {
  29864. if (showWarn)console.log("ani not found:",name);
  29865. }
  29866. return false;
  29867. }
  29868. /**@private */
  29869. __proto._copyLabels=function(labels){
  29870. if (!labels)return null;
  29871. var rst;
  29872. rst={};
  29873. var key;
  29874. for (key in labels){
  29875. rst[key]=Utils.copyArray([],labels[key]);
  29876. }
  29877. return rst;
  29878. }
  29879. /**@private */
  29880. __proto._frameLoop=function(){
  29881. if (this._visible && this._style.alpha > 0.01 && this._frames){
  29882. _super.prototype._frameLoop.call(this);
  29883. }
  29884. }
  29885. /**@private */
  29886. __proto._displayToIndex=function(value){
  29887. if (this._frames)this.graphics=this._frames[value];
  29888. }
  29889. /**
  29890. *停止动画播放,并清理对象属性。之后可存入对象池,方便对象复用。
  29891. */
  29892. __proto.clear=function(){
  29893. _super.prototype.clear.call(this);
  29894. this.stop();
  29895. this.graphics=null;
  29896. this._frames=null;
  29897. this._labels=null;
  29898. return this;
  29899. }
  29900. /**
  29901. *<p>根据指定的动画模版初始化当前动画序列帧。选择动画模版的过程如下:1. 动画模版缓存池中key为cacheName的动画模版;2. 如果不存在,则加载指定的图片集合并创建动画模版。注意:只有指定不为空的cacheName,才能将创建好的动画模版以此为key缓存到动画模版缓存池,否则不进行缓存。</p>
  29902. *<p>动画模版缓存池是以一定的内存开销来节省CPU开销,当相同的动画模版被多次使用时,相比于每次都创建新的动画模版,使用动画模版缓存池,只需创建一次,缓存之后多次复用,从而节省了动画模版创建的开销。</p>
  29903. *<p>因为返回值为Animation对象本身,所以可以使用如下语法:loadImages(...).loadImages(...).play(...);。</p>
  29904. *@param urls 图片路径集合。需要创建动画模版时,会以此为数据源。参数形如:[url1,url2,url3,...]。
  29905. *@param cacheName (可选)动画模板在动画模版缓存池中的key。如果此参数不为空,表示使用动画模版缓存池。如果动画模版缓存池中存在key为cacheName的动画模版,则使用此模版。否则,创建新的动画模版,如果cacheName不为空,则以cacheName为key缓存到动画模版缓存池中,如果cacheName为空,不进行缓存。
  29906. *@return 返回Animation对象本身。
  29907. */
  29908. __proto.loadImages=function(urls,cacheName){
  29909. (cacheName===void 0)&& (cacheName="");
  29910. this._url="";
  29911. if (!this._setFramesFromCache(cacheName)){
  29912. this.frames=Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] :Animation.createFrames(urls,cacheName);
  29913. }
  29914. return this;
  29915. }
  29916. /**
  29917. *<p>根据指定的动画模版初始化当前动画序列帧。选择动画模版的过程如下:1. 动画模版缓存池中key为cacheName的动画模版;2. 如果不存在,则加载指定的图集并创建动画模版。</p>
  29918. *<p>注意:只有指定不为空的cacheName,才能将创建好的动画模版以此为key缓存到动画模版缓存池,否则不进行缓存。</p>
  29919. *<p>动画模版缓存池是以一定的内存开销来节省CPU开销,当相同的动画模版被多次使用时,相比于每次都创建新的动画模版,使用动画模版缓存池,只需创建一次,缓存之后多次复用,从而节省了动画模版创建的开销。</p>
  29920. *<p>因为返回值为Animation对象本身,所以可以使用如下语法:loadAtlas(...).loadAtlas(...).play(...);。</p>
  29921. *@param url 图集路径。需要创建动画模版时,会以此为数据源。
  29922. *@param loaded (可选)使用指定图集初始化动画完毕的回调。
  29923. *@param cacheName (可选)动画模板在动画模版缓存池中的key。如果此参数不为空,表示使用动画模版缓存池。如果动画模版缓存池中存在key为cacheName的动画模版,则使用此模版。否则,创建新的动画模版,如果cacheName不为空,则以cacheName为key缓存到动画模版缓存池中,如果cacheName为空,不进行缓存。
  29924. *@return 返回动画本身。
  29925. */
  29926. __proto.loadAtlas=function(url,loaded,cacheName){
  29927. (cacheName===void 0)&& (cacheName="");
  29928. this._url="";
  29929. var _this=this;
  29930. if (!_this._setFramesFromCache(cacheName)){
  29931. function onLoaded (loadUrl){
  29932. if (url===loadUrl){
  29933. _this.frames=Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] :Animation.createFrames(url,cacheName);
  29934. if (loaded)loaded.run();
  29935. }
  29936. }
  29937. if (Loader.getAtlas(url))onLoaded(url);
  29938. else Laya.loader.load(url,Handler.create(null,onLoaded,[url]),null,/*laya.net.Loader.ATLAS*/"atlas");
  29939. }
  29940. return this;
  29941. }
  29942. /**
  29943. *<p>加载并解析由LayaAir IDE制作的动画文件,此文件中可能包含多个动画。默认帧率为在IDE中设计的帧率,如果调用过set interval,则使用此帧间隔对应的帧率。加载后创建动画模版,并缓存到动画模版缓存池,key "url#动画名称" 对应相应动画名称的动画模板,key "url#" 对应动画模版集合的默认动画模版。</p>
  29944. *<p>注意:如果调用本方法前,还没有预加载动画使用的图集,请将atlas参数指定为对应的图集路径,否则会导致动画创建失败。</p>
  29945. *<p>动画模版缓存池是以一定的内存开销来节省CPU开销,当相同的动画模版被多次使用时,相比于每次都创建新的动画模版,使用动画模版缓存池,只需创建一次,缓存之后多次复用,从而节省了动画模版创建的开销。</p>
  29946. *<p>因为返回值为Animation对象本身,所以可以使用如下语法:loadAnimation(...).loadAnimation(...).play(...);。</p>
  29947. *@param url 动画文件路径。可由LayaAir IDE创建并发布。
  29948. *@param loaded (可选)使用指定动画资源初始化动画完毕的回调。
  29949. *@param atlas (可选)动画用到的图集地址(可选)。
  29950. *@return 返回动画本身。
  29951. */
  29952. __proto.loadAnimation=function(url,loaded,atlas){
  29953. this._url=url;
  29954. var _this=this;
  29955. if (!this._actionName)this._actionName="";
  29956. if (!_this._setFramesFromCache(this._actionName)){
  29957. if (!atlas || Loader.getAtlas(atlas)){
  29958. this._loadAnimationData(url,loaded,atlas);
  29959. }else {
  29960. Laya.loader.load(atlas,Handler.create(this,this._loadAnimationData,[url,loaded,atlas]),null,/*laya.net.Loader.ATLAS*/"atlas")
  29961. }
  29962. }else {
  29963. _this._setFramesFromCache(this._actionName,true);
  29964. this.index=0;
  29965. if (loaded)loaded.run();
  29966. }
  29967. return this;
  29968. }
  29969. /**@private */
  29970. __proto._loadAnimationData=function(url,loaded,atlas){
  29971. var _$this=this;
  29972. if (atlas && !Loader.getAtlas(atlas)){
  29973. console.warn("atlas load fail:"+atlas);
  29974. return;
  29975. };
  29976. var _this=this;
  29977. function onLoaded (loadUrl){
  29978. if (!Loader.getRes(loadUrl)){
  29979. if (Animation.framesMap[url+"#"]){
  29980. _this._setFramesFromCache(_$this._actionName,true);
  29981. _$this.index=0;
  29982. _$this._resumePlay();
  29983. if (loaded)loaded.run();
  29984. }
  29985. return;
  29986. }
  29987. if (url===loadUrl){
  29988. var tAniO;
  29989. if (!Animation.framesMap[url+"#"]){
  29990. var aniData=GraphicAnimation.parseAnimationData(Loader.getRes(url));
  29991. if (!aniData)return;
  29992. var aniList=aniData.animationList;
  29993. var i=0,len=aniList.length;
  29994. var defaultO;
  29995. for (i=0;i < len;i++){
  29996. tAniO=aniList[i];
  29997. Animation.framesMap[url+"#"+tAniO.name]=tAniO;
  29998. if (!defaultO)defaultO=tAniO;
  29999. }
  30000. if (defaultO){
  30001. Animation.framesMap[url+"#"]=defaultO;
  30002. _this._setFramesFromCache(_$this._actionName,true);
  30003. _$this.index=0;
  30004. }
  30005. _$this._resumePlay();
  30006. }else {
  30007. _this._setFramesFromCache(_$this._actionName,true);
  30008. _$this.index=0;
  30009. _$this._resumePlay();
  30010. }
  30011. if (loaded)loaded.run();
  30012. }
  30013. Loader.clearRes(url);
  30014. }
  30015. if (Loader.getRes(url))onLoaded(url);
  30016. else Laya.loader.load(url,Handler.create(null,onLoaded,[url]),null,/*laya.net.Loader.JSON*/"json");
  30017. }
  30018. /**
  30019. *当前动画的帧图像数组。本类中,每个帧图像是一个Graphics对象,而动画播放就是定时切换Graphics对象的过程。
  30020. */
  30021. __getset(0,__proto,'frames',function(){
  30022. return this._frames;
  30023. },function(value){
  30024. this._frames=value;
  30025. if (value){
  30026. this._count=value.length;
  30027. if (this._actionName)this._setFramesFromCache(this._actionName,true);
  30028. this.index=this._index;
  30029. }
  30030. });
  30031. /**
  30032. *是否自动播放,默认为false。如果设置为true,则动画被创建并添加到舞台后自动播放。
  30033. */
  30034. __getset(0,__proto,'autoPlay',null,function(value){
  30035. if (value)this.play();
  30036. else this.stop();
  30037. });
  30038. /**
  30039. *<p>动画数据源。</p>
  30040. *<p>类型如下:<br/>
  30041. *1. LayaAir IDE动画文件路径:使用此类型需要预加载所需的图集资源,否则会创建失败,如果不想预加载或者需要创建完毕的回调,请使用loadAnimation(...)方法;<br/>
  30042. *2. 图集路径:使用此类型创建的动画模版不会被缓存到动画模版缓存池中,如果需要缓存或者创建完毕的回调,请使用loadAtlas(...)方法;<br/>
  30043. *3. 图片路径集合:使用此类型创建的动画模版不会被缓存到动画模版缓存池中,如果需要缓存,请使用loadImages(...)方法。</p>
  30044. *@param value 数据源。比如:图集:"xx/a1.atlas";图片集合:"a1.png,a2.png,a3.png";LayaAir IDE动画"xx/a1.ani"。
  30045. */
  30046. __getset(0,__proto,'source',null,function(value){
  30047. if (value.indexOf(".ani")>-1)this.loadAnimation(value);
  30048. else if (value.indexOf(".json")>-1 || value.indexOf("als")>-1 || value.indexOf("atlas")>-1)this.loadAtlas(value);
  30049. else this.loadImages(value.split(","));
  30050. });
  30051. /**
  30052. *设置自动播放的动画名称,在LayaAir IDE中可以创建的多个动画组成的动画集合,选择其中一个动画名称进行播放。
  30053. */
  30054. __getset(0,__proto,'autoAnimation',null,function(value){
  30055. this.play(0,true,value);
  30056. });
  30057. Animation.createFrames=function(url,name){
  30058. var arr;
  30059. if ((typeof url=='string')){
  30060. var atlas=Loader.getAtlas(url);
  30061. if (atlas && atlas.length){
  30062. arr=[];
  30063. for (var i=0,n=atlas.length;i < n;i++){
  30064. var g=new Graphics();
  30065. g.drawImage(Loader.getRes(atlas[i]),0,0);
  30066. arr.push(g);
  30067. }
  30068. }
  30069. }else if ((url instanceof Array)){
  30070. arr=[];
  30071. for (i=0,n=url.length;i < n;i++){
  30072. g=new Graphics();
  30073. g.loadImage(url[i],0,0);
  30074. arr.push(g);
  30075. }
  30076. }
  30077. if (name)Animation.framesMap[name]=arr;
  30078. return arr;
  30079. }
  30080. Animation.clearCache=function(key){
  30081. var cache=Animation.framesMap;
  30082. var val;
  30083. var key2=key+"#";
  30084. for (val in cache){
  30085. if (val===key || val.indexOf(key2)===0){
  30086. delete Animation.framesMap[val];
  30087. }
  30088. }
  30089. }
  30090. Animation.framesMap={};
  30091. return Animation;
  30092. })(AnimationBase)
  30093. /**
  30094. *<code>RenderTexture</code> 类用于创建渲染目标。
  30095. */
  30096. //class laya.resource.RenderTexture2D extends laya.resource.BaseTexture
  30097. var RenderTexture2D=(function(_super){
  30098. function RenderTexture2D(width,height,format,depthStencilFormat){
  30099. //this._lastRT=null;
  30100. //this._lastWidth=NaN;
  30101. //this._lastHeight=NaN;
  30102. /**@private */
  30103. //this._frameBuffer=null;
  30104. /**@private */
  30105. //this._depthStencilBuffer=null;
  30106. /**@private */
  30107. //this._depthStencilFormat=0;
  30108. this._mgrKey=0;
  30109. (format===void 0)&& (format=0);
  30110. (depthStencilFormat===void 0)&& (depthStencilFormat=/*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0);
  30111. RenderTexture2D.__super.call(this,format,false);
  30112. this._glTextureType=/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1;
  30113. this._width=width;
  30114. this._height=height;
  30115. this._depthStencilFormat=depthStencilFormat;
  30116. this._create(width,height);
  30117. this.lock=true;
  30118. }
  30119. __class(RenderTexture2D,'laya.resource.RenderTexture2D',_super);
  30120. var __proto=RenderTexture2D.prototype;
  30121. __proto.getIsReady=function(){
  30122. return true;
  30123. }
  30124. /**
  30125. *@private
  30126. */
  30127. __proto._create=function(width,height){
  30128. var gl=LayaGL.instance;
  30129. this._frameBuffer=gl.createFramebuffer();
  30130. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  30131. var glFormat=this._getGLFormat();
  30132. gl.texImage2D(this._glTextureType,0,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,null);
  30133. this._setGPUMemory(width *height *4);
  30134. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
  30135. gl.framebufferTexture2D(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.COLOR_ATTACHMENT0*/0x8CE0,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,this._glTexture,0);
  30136. if (this._depthStencilFormat!==/*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_NONE*/3){
  30137. this._depthStencilBuffer=gl.createRenderbuffer();
  30138. gl.bindRenderbuffer(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
  30139. switch (this._depthStencilFormat){
  30140. case /*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0:
  30141. gl.renderbufferStorage(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,/*laya.webgl.WebGLContext.DEPTH_COMPONENT16*/0x81A5,width,height);
  30142. gl.framebufferRenderbuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.DEPTH_ATTACHMENT*/0x8D00,/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
  30143. break ;
  30144. case /*laya.resource.BaseTexture.FORMAT_STENCIL_8*/1:
  30145. gl.renderbufferStorage(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,/*laya.webgl.WebGLContext.STENCIL_INDEX8*/0x8D48,width,height);
  30146. gl.framebufferRenderbuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.STENCIL_ATTACHMENT*/0x8D20,/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
  30147. break ;
  30148. case /*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_16_8*/2:
  30149. gl.renderbufferStorage(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,/*laya.webgl.WebGLContext.DEPTH_STENCIL*/0x84F9,width,height);
  30150. gl.framebufferRenderbuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.DEPTH_STENCIL_ATTACHMENT*/0x821A,/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
  30151. break ;
  30152. default :
  30153. }
  30154. }
  30155. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  30156. gl.bindRenderbuffer(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,null);
  30157. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,this._wrapModeU);
  30158. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,this._wrapModeV);
  30159. this._setFilterMode(this._filterMode);
  30160. this._setAnisotropy(this._anisoLevel);
  30161. this._readyed=true;
  30162. this._activeResource();
  30163. }
  30164. /**
  30165. *生成mipMap。
  30166. */
  30167. __proto.generateMipmap=function(){
  30168. if (this._isPot(this.width)&& this._isPot(this.height)){
  30169. this._mipmap=true;
  30170. LayaGL.instance.generateMipmap(this._glTextureType);
  30171. this._setFilterMode(this._filterMode);
  30172. this._setGPUMemory(this.width *this.height *4 *(1+1 / 3));
  30173. }else {
  30174. this._mipmap=false;
  30175. this._setGPUMemory(this.width *this.height *4);
  30176. }
  30177. }
  30178. /**
  30179. *开始绑定。
  30180. */
  30181. __proto.start=function(){
  30182. var gl=LayaGL.instance;
  30183. LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
  30184. this._lastRT=RenderTexture2D._currentActive;
  30185. RenderTexture2D._currentActive=this;
  30186. this._readyed=true;
  30187. gl.viewport(0,0,this._width,this._height);
  30188. this._lastWidth=RenderState2D.width;
  30189. this._lastHeight=RenderState2D.height;
  30190. RenderState2D.width=this._width;
  30191. RenderState2D.height=this._height;
  30192. BaseShader.activeShader=null;
  30193. }
  30194. /**
  30195. *结束绑定。
  30196. */
  30197. __proto.end=function(){
  30198. LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  30199. RenderTexture2D._currentActive=null;
  30200. this._readyed=true;
  30201. }
  30202. /**
  30203. *恢复上一次的RenderTarge.由于使用自己保存的,所以如果被外面打断了的话,会出错。
  30204. */
  30205. __proto.restore=function(){
  30206. var gl=LayaGL.instance;
  30207. if (this._lastRT !=RenderTexture2D._currentActive){
  30208. LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._lastRT?this._lastRT._frameBuffer:null);
  30209. RenderTexture2D._currentActive=this._lastRT;
  30210. }
  30211. this._readyed=true;
  30212. gl.viewport(0,0,this._lastWidth,this._lastHeight);
  30213. RenderState2D.width=this._lastWidth;
  30214. RenderState2D.height=this._lastHeight;
  30215. BaseShader.activeShader=null;
  30216. }
  30217. // gl.viewport(0,0,Laya.stage.width,Laya.stage.height);
  30218. __proto.clear=function(r,g,b,a){
  30219. (r===void 0)&& (r=0.0);
  30220. (g===void 0)&& (g=0.0);
  30221. (b===void 0)&& (b=0.0);
  30222. (a===void 0)&& (a=1.0);
  30223. var gl=LayaGL.instance;
  30224. gl.clearColor(r,g,b,a);
  30225. var clearFlag=/*laya.webgl.WebGLContext.COLOR_BUFFER_BIT*/0x00004000;
  30226. switch (this._depthStencilFormat){
  30227. case /*laya.webgl.WebGLContext.DEPTH_COMPONENT16*/0x81A5:
  30228. clearFlag |=/*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100;
  30229. break ;
  30230. case /*laya.webgl.WebGLContext.STENCIL_INDEX8*/0x8D48:
  30231. clearFlag |=/*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400;
  30232. break ;
  30233. case /*laya.webgl.WebGLContext.DEPTH_STENCIL*/0x84F9:
  30234. clearFlag |=/*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100;
  30235. clearFlag |=/*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400
  30236. break ;
  30237. }
  30238. gl.clear(clearFlag);
  30239. }
  30240. /**
  30241. *获得像素数据。
  30242. *@param x X像素坐标。
  30243. *@param y Y像素坐标。
  30244. *@param width 宽度。
  30245. *@param height 高度。
  30246. *@return 像素数据。
  30247. */
  30248. __proto.getData=function(x,y,width,height){
  30249. if (Render.isConchApp && /*__JS__ */conchConfig.threadMode==2){
  30250. throw "native 2 thread mode use getDataAsync";
  30251. };
  30252. var gl=LayaGL.instance;
  30253. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
  30254. var canRead=(gl.checkFramebufferStatus(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40)===/*laya.webgl.WebGLContext.FRAMEBUFFER_COMPLETE*/0x8CD5);
  30255. if (!canRead){
  30256. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  30257. return null;
  30258. };
  30259. var pixels=new Uint8Array(this._width *this._height *4);
  30260. var glFormat=this._getGLFormat();
  30261. gl.readPixels(x,y,width,height,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  30262. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  30263. return pixels;
  30264. }
  30265. /**
  30266. *native多线程
  30267. */
  30268. __proto.getDataAsync=function(x,y,width,height,callBack){
  30269. var gl=LayaGL.instance;
  30270. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
  30271. gl.readPixelsAsync(x,y,width,height,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,function(data){
  30272. /*__JS__ */callBack(new Uint8Array(data));
  30273. });
  30274. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  30275. }
  30276. __proto.recycle=function(){}
  30277. /**
  30278. *@inheritDoc
  30279. */
  30280. __proto._disposeResource=function(){
  30281. if (this._frameBuffer){
  30282. var gl=LayaGL.instance;
  30283. gl.deleteTexture(this._glTexture);
  30284. gl.deleteFramebuffer(this._frameBuffer);
  30285. gl.deleteRenderbuffer(this._depthStencilBuffer);
  30286. this._glTexture=null;
  30287. this._frameBuffer=null;
  30288. this._depthStencilBuffer=null;
  30289. this._setGPUMemory(0);
  30290. }
  30291. }
  30292. /**
  30293. *获取深度格式。
  30294. *@return 深度格式。
  30295. */
  30296. __getset(0,__proto,'depthStencilFormat',function(){
  30297. return this._depthStencilFormat;
  30298. });
  30299. /**
  30300. *@inheritDoc
  30301. */
  30302. __getset(0,__proto,'defaulteTexture',function(){
  30303. return Texture2D.grayTexture;
  30304. });
  30305. /**
  30306. *获取宽度。
  30307. */
  30308. __getset(0,__proto,'sourceWidth',function(){
  30309. return this._width;
  30310. });
  30311. /***
  30312. *获取高度。
  30313. */
  30314. __getset(0,__proto,'sourceHeight',function(){
  30315. return this._height;
  30316. });
  30317. /**
  30318. *获取offsetX。
  30319. */
  30320. __getset(0,__proto,'offsetX',function(){
  30321. return 0;
  30322. });
  30323. /***
  30324. *获取offsetY
  30325. */
  30326. __getset(0,__proto,'offsetY',function(){
  30327. return 0;
  30328. });
  30329. /**
  30330. *获取当前激活的Rendertexture
  30331. */
  30332. __getset(1,RenderTexture2D,'currentActive',function(){
  30333. return RenderTexture2D._currentActive;
  30334. },laya.resource.BaseTexture._$SET_currentActive);
  30335. RenderTexture2D.pushRT=function(){
  30336. RenderTexture2D.rtStack.push({rt:RenderTexture2D._currentActive,w:RenderState2D.width,h:RenderState2D.height});
  30337. }
  30338. RenderTexture2D.popRT=function(){
  30339. var gl=LayaGL.instance;
  30340. var top=RenderTexture2D.rtStack.pop();
  30341. if (top){
  30342. if (RenderTexture2D._currentActive !=top.rt){
  30343. LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,top.rt?top.rt._frameBuffer:null);
  30344. RenderTexture2D._currentActive=top.rt;
  30345. }
  30346. gl.viewport(0,0,top.w,top.h);
  30347. RenderState2D.width=top.w;
  30348. RenderState2D.height=top.h;
  30349. }
  30350. }
  30351. RenderTexture2D._currentActive=null;
  30352. RenderTexture2D.rtStack=[];
  30353. __static(RenderTexture2D,
  30354. ['defuv',function(){return this.defuv=[0,0,1,0,1,1,0,1];},'flipyuv',function(){return this.flipyuv=[0,1,1,1,1,0,0,0];}
  30355. ]);
  30356. return RenderTexture2D;
  30357. })(BaseTexture)
  30358. /**
  30359. *<code>Texture2D</code> 类用于生成2D纹理。
  30360. */
  30361. //class laya.resource.Texture2D extends laya.resource.BaseTexture
  30362. var Texture2D=(function(_super){
  30363. function Texture2D(width,height,format,mipmap,canRead){
  30364. /**@private */
  30365. //this._canRead=false;
  30366. /**@private */
  30367. //this._pixels=null;
  30368. /**@private */
  30369. //this._mipmapCount=0;
  30370. (width===void 0)&& (width=0);
  30371. (height===void 0)&& (height=0);
  30372. (format===void 0)&& (format=1);
  30373. (mipmap===void 0)&& (mipmap=true);
  30374. (canRead===void 0)&& (canRead=false);
  30375. Texture2D.__super.call(this,format,mipmap);
  30376. this._glTextureType=/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1;
  30377. this._width=width;
  30378. this._height=height;
  30379. this._canRead=canRead;
  30380. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,this._wrapModeU);
  30381. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,this._wrapModeV);
  30382. this._setFilterMode(this._filterMode);
  30383. this._setAnisotropy(this._anisoLevel);
  30384. if (this._mipmap){
  30385. this._mipmapCount=/*__JS__ */Math.max(Math.ceil(Math.log2(width))+1,Math.ceil(Math.log2(2))+1);
  30386. for (var i=0;i < this._mipmapCount;i++)
  30387. this._setPixels(null,i,Math.max(width >> i,1),Math.max(height >> i,1));
  30388. this._setGPUMemory(width *height *4 *(1+1 / 3));
  30389. }else {
  30390. this._mipmapCount=1;
  30391. this._setGPUMemory(width *height *4);
  30392. }
  30393. }
  30394. __class(Texture2D,'laya.resource.Texture2D',_super);
  30395. var __proto=Texture2D.prototype;
  30396. /**
  30397. *@private
  30398. */
  30399. __proto._getFormatByteCount=function(){
  30400. switch (this._format){
  30401. case 0:
  30402. return 3;
  30403. case 1:
  30404. return 4;
  30405. case 2:
  30406. return 1;
  30407. default :
  30408. throw "Texture2D: unknown format.";
  30409. }
  30410. }
  30411. /**
  30412. *@private
  30413. */
  30414. __proto._setPixels=function(pixels,miplevel,width,height){
  30415. var gl=LayaGL.instance;
  30416. var textureType=this._glTextureType;
  30417. var glFormat=this._getGLFormat();
  30418. WebGLContext.bindTexture(gl,textureType,this._glTexture);
  30419. if (this.format===/*laya.resource.BaseTexture.FORMAT_R8G8B8*/0){
  30420. gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_ALIGNMENT*/0x0CF5,1);
  30421. gl.texImage2D(textureType,miplevel,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  30422. gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_ALIGNMENT*/0x0CF5,4);
  30423. }else {
  30424. gl.texImage2D(textureType,miplevel,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  30425. }
  30426. }
  30427. /**
  30428. *@private
  30429. */
  30430. __proto._calcualatesCompressedDataSize=function(format,width,height){
  30431. switch (format){
  30432. case 3:
  30433. case 5:
  30434. return ((width+3)>> 2)*((height+3)>> 2)*8;
  30435. case 4:
  30436. return ((width+3)>> 2)*((height+3)>> 2)*16;
  30437. case 11:
  30438. case 12:
  30439. return Math.floor((Math.max(width,8)*Math.max(height,8)*4+7)/ 8);
  30440. case 9:
  30441. case 10:
  30442. return Math.floor((Math.max(width,16)*Math.max(height,8)*2+7)/ 8);
  30443. default :
  30444. return 0;
  30445. }
  30446. }
  30447. /**
  30448. *@private
  30449. */
  30450. __proto._pharseDDS=function(arrayBuffer){
  30451. var FOURCC_DXT1=827611204;
  30452. var FOURCC_DXT5=894720068;
  30453. var DDPF_FOURCC=0x4;
  30454. var DDSD_MIPMAPCOUNT=0x20000;
  30455. var DDS_MAGIC=0x20534444;
  30456. var DDS_HEADER_LENGTH=31;
  30457. var DDS_HEADER_MAGIC=0;
  30458. var DDS_HEADER_SIZE=1;
  30459. var DDS_HEADER_FLAGS=2;
  30460. var DDS_HEADER_HEIGHT=3;
  30461. var DDS_HEADER_WIDTH=4;
  30462. var DDS_HEADER_MIPMAPCOUNT=7;
  30463. var DDS_HEADER_PF_FLAGS=20;
  30464. var DDS_HEADER_PF_FOURCC=21;
  30465. var header=new Int32Array(arrayBuffer,0,DDS_HEADER_LENGTH);
  30466. if (header[DDS_HEADER_MAGIC] !=DDS_MAGIC)
  30467. throw "Invalid magic number in DDS header";
  30468. if (!(header[DDS_HEADER_PF_FLAGS] & DDPF_FOURCC))
  30469. throw "Unsupported format, must contain a FourCC code";
  30470. var compressedFormat=header[DDS_HEADER_PF_FOURCC];
  30471. switch (this._format){
  30472. case 3:
  30473. if (compressedFormat!==FOURCC_DXT1)
  30474. throw "the FourCC code is not same with texture format.";
  30475. break ;
  30476. case 4:
  30477. if (compressedFormat!==FOURCC_DXT5)
  30478. throw "the FourCC code is not same with texture format.";
  30479. break ;
  30480. default :
  30481. throw "unknown texture format.";
  30482. };
  30483. var mipLevels=1;
  30484. if (header[DDS_HEADER_FLAGS] & DDSD_MIPMAPCOUNT){
  30485. mipLevels=Math.max(1,header[DDS_HEADER_MIPMAPCOUNT]);
  30486. if (!this._mipmap)
  30487. throw "the mipmap is not same with Texture2D.";
  30488. }else {
  30489. if (this._mipmap)
  30490. throw "the mipmap is not same with Texture2D.";
  30491. };
  30492. var width=header[DDS_HEADER_WIDTH];
  30493. var height=header[DDS_HEADER_HEIGHT];
  30494. this._width=width;
  30495. this._height=height;
  30496. var dataOffset=header[DDS_HEADER_SIZE]+4;
  30497. this._upLoadCompressedTexImage2D(arrayBuffer,width,height,mipLevels,dataOffset,0);
  30498. }
  30499. /**
  30500. *@private
  30501. */
  30502. __proto._pharseKTX=function(arrayBuffer){
  30503. var ETC_HEADER_LENGTH=13;
  30504. var ETC_HEADER_FORMAT=4;
  30505. var ETC_HEADER_HEIGHT=7;
  30506. var ETC_HEADER_WIDTH=6;
  30507. var ETC_HEADER_MIPMAPCOUNT=11;
  30508. var ETC_HEADER_METADATA=12;
  30509. var id=new Uint8Array(arrayBuffer,0,12);
  30510. if (id[0] !=0xAB || id[1] !=0x4B || id[2] !=0x54 || id[3] !=0x58 || id[4] !=0x20 || id[5] !=0x31 || id[6] !=0x31 || id[7] !=0xBB || id[8] !=0x0D || id[9] !=0x0A || id[10] !=0x1A || id[11] !=0x0A)
  30511. throw("Invalid fileIdentifier in KTX header");
  30512. var header=new Int32Array(id.buffer,id.length,ETC_HEADER_LENGTH);
  30513. var compressedFormat=header[ETC_HEADER_FORMAT];
  30514. switch (compressedFormat){
  30515. case WebGLContext._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL:
  30516. this._format=5;
  30517. break ;
  30518. default :
  30519. throw "unknown texture format.";
  30520. };
  30521. var mipLevels=header[ETC_HEADER_MIPMAPCOUNT];
  30522. var width=header[ETC_HEADER_WIDTH];
  30523. var height=header[ETC_HEADER_HEIGHT];
  30524. this._width=width;
  30525. this._height=height;
  30526. var dataOffset=64+header[ETC_HEADER_METADATA];
  30527. this._upLoadCompressedTexImage2D(arrayBuffer,width,height,mipLevels,dataOffset,4);
  30528. }
  30529. /**
  30530. *@private
  30531. */
  30532. __proto._pharsePVR=function(arrayBuffer){
  30533. var PVR_FORMAT_2BPP_RGB=0;
  30534. var PVR_FORMAT_2BPP_RGBA=1;
  30535. var PVR_FORMAT_4BPP_RGB=2;
  30536. var PVR_FORMAT_4BPP_RGBA=3;
  30537. var PVR_MAGIC=0x03525650;
  30538. var PVR_HEADER_LENGTH=13;
  30539. var PVR_HEADER_MAGIC=0;
  30540. var PVR_HEADER_FORMAT=2;
  30541. var PVR_HEADER_HEIGHT=6;
  30542. var PVR_HEADER_WIDTH=7;
  30543. var PVR_HEADER_MIPMAPCOUNT=11;
  30544. var PVR_HEADER_METADATA=12;
  30545. var header=new Int32Array(arrayBuffer,0,PVR_HEADER_LENGTH);
  30546. if (header[PVR_HEADER_MAGIC] !=PVR_MAGIC)
  30547. throw("Invalid magic number in PVR header");
  30548. var compressedFormat=header[PVR_HEADER_FORMAT];
  30549. switch (compressedFormat){
  30550. case PVR_FORMAT_2BPP_RGB:
  30551. this._format=9;
  30552. break ;
  30553. case PVR_FORMAT_4BPP_RGB:
  30554. this._format=11;
  30555. break ;
  30556. case PVR_FORMAT_2BPP_RGBA:
  30557. this._format=10;
  30558. break ;
  30559. case PVR_FORMAT_4BPP_RGBA:
  30560. this._format=12;
  30561. break ;
  30562. default :
  30563. throw "Texture2D:unknown PVR format.";
  30564. };
  30565. var mipLevels=header[PVR_HEADER_MIPMAPCOUNT];
  30566. var width=header[PVR_HEADER_WIDTH];
  30567. var height=header[PVR_HEADER_HEIGHT];
  30568. this._width=width;
  30569. this._height=height;
  30570. var dataOffset=header[PVR_HEADER_METADATA]+52;
  30571. this._upLoadCompressedTexImage2D(arrayBuffer,width,height,mipLevels,dataOffset,0);
  30572. }
  30573. /**
  30574. *@private
  30575. */
  30576. __proto._upLoadCompressedTexImage2D=function(data,width,height,miplevelCount,dataOffset,imageSizeOffset){
  30577. var gl=LayaGL.instance;
  30578. var textureType=this._glTextureType;
  30579. WebGLContext.bindTexture(gl,textureType,this._glTexture);
  30580. var glFormat=this._getGLFormat();
  30581. var offset=dataOffset;
  30582. for (var i=0;i < miplevelCount;i++){
  30583. offset+=imageSizeOffset;
  30584. var mipDataSize=this._calcualatesCompressedDataSize(this._format,width,height);
  30585. var mipData=new Uint8Array(data,offset,mipDataSize);
  30586. gl.compressedTexImage2D(textureType,i,glFormat,width,height,0,mipData);
  30587. width=Math.max(width >> 1,1.0);
  30588. height=Math.max(height >> 1,1.0);
  30589. offset+=mipDataSize;
  30590. };
  30591. var memory=offset;
  30592. this._setGPUMemory(memory);
  30593. this._readyed=true;
  30594. this._activeResource();
  30595. }
  30596. /**
  30597. *通过图片源填充纹理,可为HTMLImageElement、HTMLCanvasElement、HTMLVideoElement、ImageBitmap、ImageData,
  30598. *设置之后纹理宽高可能会发生变化。
  30599. */
  30600. __proto.loadImageSource=function(source,premultiplyAlpha){
  30601. (premultiplyAlpha===void 0)&& (premultiplyAlpha=false);
  30602. var width=source.width;
  30603. var height=source.height;
  30604. this._width=width;
  30605. this._height=height;
  30606. if (!(this._isPot(width)&& this._isPot(height)))
  30607. this._mipmap=false;
  30608. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,this._wrapModeU);
  30609. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,this._wrapModeV);
  30610. this._setFilterMode(this._filterMode);
  30611. var gl=LayaGL.instance;
  30612. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  30613. var glFormat=this._getGLFormat();
  30614. if (Render.isConchApp){
  30615. if ((source instanceof laya.resource.HTMLCanvas )){
  30616. gl.texImage2D(this._glTextureType,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source);
  30617. }
  30618. else {
  30619. source.setPremultiplyAlpha(premultiplyAlpha);
  30620. gl.texImage2D(this._glTextureType,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source);
  30621. }
  30622. }else {
  30623. (premultiplyAlpha)&& (gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,true));
  30624. gl.texImage2D(this._glTextureType,0,glFormat,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source);
  30625. (premultiplyAlpha)&& (gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,false));
  30626. }
  30627. if (this._mipmap){
  30628. gl.generateMipmap(this._glTextureType);
  30629. this._setGPUMemory(width *height *4 *(1+1 / 3));
  30630. }else {
  30631. this._setGPUMemory(width *height *4);
  30632. }
  30633. if (this._canRead){
  30634. if (Render.isConchApp){
  30635. this._pixels=new Uint8Array(source._nativeObj.getImageData(0,0,width,height));
  30636. }else {
  30637. Browser.canvas.size(width,height);
  30638. Browser.canvas.clear();
  30639. Browser.context.drawImage(source,0,0,width,height);
  30640. this._pixels=new Uint8Array(Browser.context.getImageData(0,0,width,height).data.buffer);
  30641. }
  30642. }
  30643. this._readyed=true;
  30644. this._activeResource();
  30645. }
  30646. /**
  30647. *通过像素填充纹理。
  30648. *@param pixels 像素。
  30649. *@param miplevel 层级。
  30650. */
  30651. __proto.setPixels=function(pixels,miplevel){
  30652. (miplevel===void 0)&& (miplevel=0);
  30653. if (!pixels)
  30654. throw "Texture2D:pixels can't be null.";
  30655. var width=Math.max(this._width >> miplevel,1);
  30656. var height=Math.max(this._height >> miplevel,1);
  30657. var pixelsCount=width *height *this._getFormatByteCount();
  30658. if (pixels.length < pixelsCount)
  30659. throw "Texture2D:pixels length should at least "+pixelsCount+".";
  30660. this._setPixels(pixels,miplevel,width,height);
  30661. if (this._canRead)
  30662. this._pixels=pixels;
  30663. this._readyed=true;
  30664. this._activeResource();
  30665. }
  30666. /**
  30667. *通过像素填充部分纹理。
  30668. *@param x X轴像素起点。
  30669. *@param y Y轴像素起点。
  30670. *@param width 像素宽度。
  30671. *@param height 像素高度。
  30672. *@param pixels 像素数组。
  30673. *@param miplevel 层级。
  30674. */
  30675. __proto.setSubPixels=function(x,y,width,height,pixels,miplevel){
  30676. (miplevel===void 0)&& (miplevel=0);
  30677. if (!pixels)
  30678. throw "Texture2D:pixels can't be null.";
  30679. var gl=LayaGL.instance;
  30680. var textureType=this._glTextureType;
  30681. WebGLContext.bindTexture(gl,textureType,this._glTexture);
  30682. var glFormat=this._getGLFormat();
  30683. if (this._format===/*laya.resource.BaseTexture.FORMAT_R8G8B8*/0){
  30684. gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_ALIGNMENT*/0x0CF5,1);
  30685. gl.texSubImage2D(textureType,miplevel,x,y,width,height,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  30686. gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_ALIGNMENT*/0x0CF5,4);
  30687. }else {
  30688. gl.texSubImage2D(textureType,miplevel,x,y,width,height,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  30689. }
  30690. this._readyed=true;
  30691. this._activeResource();
  30692. }
  30693. /**
  30694. *通过压缩数据填充纹理。
  30695. *@param data 压缩数据。
  30696. *@param miplevel 层级。
  30697. */
  30698. __proto.setCompressData=function(data){
  30699. switch (this._format){
  30700. case 3:
  30701. case 4:
  30702. this._pharseDDS(data);
  30703. break ;
  30704. case 5:
  30705. this._pharseKTX(data);
  30706. break ;
  30707. case 9:
  30708. case 10:
  30709. case 11:
  30710. case 12:
  30711. this._pharsePVR(data);
  30712. break ;
  30713. default :
  30714. throw "Texture2D:unkonwn format.";
  30715. }
  30716. }
  30717. /**
  30718. *@inheritDoc
  30719. */
  30720. __proto._recoverResource=function(){}
  30721. /**
  30722. *返回图片像素。
  30723. *@return 图片像素。
  30724. */
  30725. __proto.getPixels=function(){
  30726. if (this._canRead)
  30727. return this._pixels;
  30728. else
  30729. throw new Error("Texture2D: must set texture canRead is true.");
  30730. }
  30731. /**
  30732. *获取mipmap数量。
  30733. */
  30734. __getset(0,__proto,'mipmapCount',function(){
  30735. return this._mipmapCount;
  30736. });
  30737. /**
  30738. *@inheritDoc
  30739. */
  30740. __getset(0,__proto,'defaulteTexture',function(){
  30741. return laya.resource.Texture2D.grayTexture;
  30742. });
  30743. Texture2D.__init__=function(){
  30744. var pixels=new Uint8Array(3);
  30745. pixels[0]=128;
  30746. pixels[1]=128;
  30747. pixels[2]=128;
  30748. Texture2D.grayTexture=new Texture2D(1,1,0,false,false);
  30749. Texture2D.grayTexture.setPixels(pixels);
  30750. Texture2D.grayTexture.lock=true;
  30751. pixels[0]=255;
  30752. pixels[1]=255;
  30753. pixels[2]=255;
  30754. Texture2D.whiteTexture=new Texture2D(1,1,0,false,false);
  30755. Texture2D.whiteTexture.setPixels(pixels);
  30756. Texture2D.whiteTexture.lock=true;
  30757. pixels[0]=0;
  30758. pixels[1]=0;
  30759. pixels[2]=0;
  30760. Texture2D.blackTexture=new Texture2D(1,1,0,false,false);
  30761. Texture2D.blackTexture.setPixels(pixels);
  30762. Texture2D.blackTexture.lock=true;
  30763. }
  30764. Texture2D._parse=function(data,propertyParams,constructParams){
  30765. var texture=constructParams ? new Texture2D(constructParams[0],constructParams[1],constructParams[2],constructParams[3],constructParams[4]):new Texture2D(0,0);
  30766. if (propertyParams){
  30767. texture.wrapModeU=propertyParams.wrapModeU;
  30768. texture.wrapModeV=propertyParams.wrapModeV;
  30769. texture.filterMode=propertyParams.filterMode;
  30770. texture.anisoLevel=propertyParams.anisoLevel;
  30771. }
  30772. switch (texture._format){
  30773. case 0:
  30774. case 1:
  30775. texture.loadImageSource(data);
  30776. break ;
  30777. case 3:
  30778. case 4:
  30779. case 5:
  30780. case 9:
  30781. case 10:
  30782. case 11:
  30783. case 12:
  30784. texture.setCompressData(data);
  30785. break ;
  30786. default :
  30787. throw "Texture2D:unkonwn format.";
  30788. }
  30789. return texture;
  30790. }
  30791. Texture2D.load=function(url,complete){
  30792. Laya.loader.create(url,complete,null,/*laya.net.Loader.TEXTURE2D*/"TEXTURE2D");
  30793. }
  30794. Texture2D.grayTexture=null;
  30795. Texture2D.whiteTexture=null;
  30796. Texture2D.blackTexture=null;
  30797. return Texture2D;
  30798. })(BaseTexture)
  30799. /**
  30800. *<p><code>Input</code> 类用于创建显示对象以显示和输入文本。</p>
  30801. *<p>Input 类封装了原生的文本输入框,由于不同浏览器的差异,会导致此对象的默认文本的位置与用户点击输入时的文本的位置有少许的偏差。</p>
  30802. */
  30803. //class laya.display.Input extends laya.display.Text
  30804. var Input=(function(_super){
  30805. function Input(){
  30806. /**@private */
  30807. this._focus=false;
  30808. /**@private */
  30809. this._multiline=false;
  30810. /**@private */
  30811. this._editable=true;
  30812. /**@private */
  30813. this._restrictPattern=null;
  30814. this._type="text";
  30815. /**输入提示符。*/
  30816. this._prompt='';
  30817. /**输入提示符颜色。*/
  30818. this._promptColor="#A9A9A9";
  30819. this._originColor="#000000";
  30820. this._content='';
  30821. Input.__super.call(this);
  30822. this._maxChars=1E5;
  30823. this._width=100;
  30824. this._height=20;
  30825. this.multiline=false;
  30826. this.overflow=/*laya.display.Text.SCROLL*/"scroll";
  30827. this.on(/*laya.events.Event.MOUSE_DOWN*/"mousedown",this,this._onMouseDown);
  30828. this.on(/*laya.events.Event.UNDISPLAY*/"undisplay",this,this._onUnDisplay);
  30829. }
  30830. __class(Input,'laya.display.Input',_super);
  30831. var __proto=Input.prototype;
  30832. /**
  30833. *设置光标位置和选取字符。
  30834. *@param startIndex 光标起始位置。
  30835. *@param endIndex 光标结束位置。
  30836. */
  30837. __proto.setSelection=function(startIndex,endIndex){
  30838. this.focus=true;
  30839. laya.display.Input.inputElement.selectionStart=startIndex;
  30840. laya.display.Input.inputElement.selectionEnd=endIndex;
  30841. }
  30842. __proto._onUnDisplay=function(e){
  30843. this.focus=false;
  30844. }
  30845. __proto._onMouseDown=function(e){
  30846. this.focus=true;
  30847. }
  30848. /**
  30849. *在输入期间,如果 Input 实例的位置改变,调用_syncInputTransform同步输入框的位置。
  30850. */
  30851. __proto._syncInputTransform=function(){
  30852. var inputElement=this.nativeInput;
  30853. var transform=Utils.getTransformRelativeToWindow(this,this.padding[3],this.padding[0]);
  30854. var inputWid=this._width-this.padding[1]-this.padding[3];
  30855. var inputHei=this._height-this.padding[0]-this.padding[2];
  30856. if (Render.isConchApp){
  30857. inputElement.setScale(transform.scaleX,transform.scaleY);
  30858. inputElement.setSize(inputWid,inputHei);
  30859. inputElement.setPos(transform.x,transform.y);
  30860. }else {
  30861. Input.inputContainer.style.transform=Input.inputContainer.style.webkitTransform="scale("+transform.scaleX+","+transform.scaleY+") rotate("+(Laya.stage.canvasDegree)+"deg)";
  30862. inputElement.style.width=inputWid+'px';
  30863. inputElement.style.height=inputHei+'px';
  30864. Input.inputContainer.style.left=transform.x+'px';
  30865. Input.inputContainer.style.top=transform.y+'px';
  30866. }
  30867. }
  30868. /**选中当前实例的所有文本。*/
  30869. __proto.select=function(){
  30870. this.nativeInput.select();
  30871. }
  30872. __proto._setInputMethod=function(){
  30873. Input.input.parentElement && (Input.inputContainer.removeChild(Input.input));
  30874. Input.area.parentElement && (Input.inputContainer.removeChild(Input.area));
  30875. Input.inputElement=(this._multiline ? Input.area :Input.input);
  30876. Input.inputContainer.appendChild(Input.inputElement);
  30877. if (Text.RightToLeft){
  30878. Input.inputElement.style.direction="rtl";
  30879. }
  30880. }
  30881. __proto._focusIn=function(){
  30882. laya.display.Input.isInputting=true;
  30883. var input=this.nativeInput;
  30884. this._focus=true;
  30885. var cssStyle=input.style;
  30886. cssStyle.whiteSpace=(this.wordWrap ? "pre-wrap" :"nowrap");
  30887. this._setPromptColor();
  30888. input.readOnly=!this._editable;
  30889. if (Render.isConchApp){
  30890. input.setType(this._type);
  30891. input.setForbidEdit(!this._editable);
  30892. }
  30893. input.maxLength=this._maxChars;
  30894. var padding=this.padding;
  30895. input.type=this._type;
  30896. input.value=this._content;
  30897. input.placeholder=this._prompt;
  30898. Laya.stage.off(/*laya.events.Event.KEY_DOWN*/"keydown",this,this._onKeyDown);
  30899. Laya.stage.on(/*laya.events.Event.KEY_DOWN*/"keydown",this,this._onKeyDown);
  30900. Laya.stage.focus=this;
  30901. this.event(/*laya.events.Event.FOCUS*/"focus");
  30902. if (Browser.onPC)input.focus();
  30903. if(!Browser.onMiniGame && !Browser.onBDMiniGame && !Browser.onQGMiniGame && !Browser.onKGMiniGame && !Browser.onVVMiniGame && !Browser.onAlipayMiniGame && !Browser.onBLMiniGame && !Browser.onQQMiniGame){
  30904. var temp=this._text;
  30905. this._text=null;
  30906. }
  30907. this.typeset();
  30908. input.setColor(this._originColor);
  30909. input.setFontSize(this.fontSize);
  30910. input.setFontFace(Browser.onIPhone ? (Text.fontFamilyMap[this.font] || this.font):this.font);
  30911. if (Render.isConchApp){
  30912. input.setMultiAble && input.setMultiAble(this._multiline);
  30913. }
  30914. cssStyle.lineHeight=(this.leading+this.fontSize)+"px";
  30915. cssStyle.fontStyle=(this.italic ? "italic" :"normal");
  30916. cssStyle.fontWeight=(this.bold ? "bold" :"normal");
  30917. cssStyle.textAlign=this.align;
  30918. cssStyle.padding="0 0";
  30919. this._syncInputTransform();
  30920. if (!Render.isConchApp && Browser.onPC)
  30921. Laya.systemTimer.frameLoop(1,this,this._syncInputTransform);
  30922. }
  30923. // 设置DOM输入框提示符颜色。
  30924. __proto._setPromptColor=function(){
  30925. Input.promptStyleDOM=Browser.getElementById("promptStyle");
  30926. if (!Input.promptStyleDOM){
  30927. Input.promptStyleDOM=Browser.createElement("style");
  30928. Input.promptStyleDOM.setAttribute("id","promptStyle");
  30929. Browser.document.head.appendChild(Input.promptStyleDOM);
  30930. }
  30931. Input.promptStyleDOM.innerText="input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {"+"color:"+this._promptColor+"}"+"input:-moz-placeholder, textarea:-moz-placeholder {"+"color:"+this._promptColor+"}"+"input::-moz-placeholder, textarea::-moz-placeholder {"+"color:"+this._promptColor+"}"+"input:-ms-input-placeholder, textarea:-ms-input-placeholder {"+"color:"+this._promptColor+"}";
  30932. }
  30933. /**@private */
  30934. __proto._focusOut=function(){
  30935. laya.display.Input.isInputting=false;
  30936. this._focus=false;
  30937. this._text=null;
  30938. this._content=this.nativeInput.value;
  30939. if (!this._content){
  30940. Laya.superSet(Text,this,'text',this._prompt);
  30941. Laya.superSet(Text,this,'color',this._promptColor);
  30942. }else {
  30943. Laya.superSet(Text,this,'text',this._content);
  30944. Laya.superSet(Text,this,'color',this._originColor);
  30945. }
  30946. Laya.stage.off(/*laya.events.Event.KEY_DOWN*/"keydown",this,this._onKeyDown);
  30947. Laya.stage.focus=null;
  30948. this.event(/*laya.events.Event.BLUR*/"blur");
  30949. this.event(/*laya.events.Event.CHANGE*/"change");
  30950. if (Render.isConchApp)this.nativeInput.blur();
  30951. Browser.onPC && Laya.systemTimer.clear(this,this._syncInputTransform);
  30952. }
  30953. /**@private */
  30954. __proto._onKeyDown=function(e){
  30955. if (e.keyCode===13){
  30956. if (Browser.onMobile && !this._multiline)
  30957. this.focus=false;
  30958. this.event(/*laya.events.Event.ENTER*/"enter");
  30959. }
  30960. }
  30961. __proto.changeText=function(text){
  30962. this._content=text;
  30963. if (this._focus){
  30964. this.nativeInput.value=text || '';
  30965. this.event(/*laya.events.Event.CHANGE*/"change");
  30966. }else
  30967. _super.prototype.changeText.call(this,text);
  30968. }
  30969. /**@inheritDoc */
  30970. __getset(0,__proto,'color',_super.prototype._$get_color,function(value){
  30971. if (this._focus)
  30972. this.nativeInput.setColor(value);
  30973. Laya.superSet(Text,this,'color',this._content?value:this._promptColor);
  30974. this._originColor=value;
  30975. });
  30976. /**表示是否是多行输入框。*/
  30977. __getset(0,__proto,'multiline',function(){
  30978. return this._multiline;
  30979. },function(value){
  30980. this._multiline=value;
  30981. this.valign=value ? "top" :"middle";
  30982. });
  30983. /**
  30984. *<p>字符数量限制,默认为10000。</p>
  30985. *<p>设置字符数量限制时,小于等于0的值将会限制字符数量为10000。</p>
  30986. */
  30987. __getset(0,__proto,'maxChars',function(){
  30988. return this._maxChars;
  30989. },function(value){
  30990. if (value <=0)
  30991. value=1E5;
  30992. this._maxChars=value;
  30993. });
  30994. /**@inheritDoc */
  30995. __getset(0,__proto,'text',function(){
  30996. if (this._focus)
  30997. return this.nativeInput.value;
  30998. else
  30999. return this._content || "";
  31000. },function(value){
  31001. Laya.superSet(Text,this,'color',this._originColor);
  31002. value+='';
  31003. if (this._focus){
  31004. this.nativeInput.value=value || '';
  31005. this.event(/*laya.events.Event.CHANGE*/"change");
  31006. }else {
  31007. if (!this._multiline)
  31008. value=value.replace(/\r?\n/g,'');
  31009. this._content=value;
  31010. if (value)
  31011. Laya.superSet(Text,this,'text',value);
  31012. else {
  31013. Laya.superSet(Text,this,'text',this._prompt);
  31014. Laya.superSet(Text,this,'color',this.promptColor);
  31015. }
  31016. }
  31017. });
  31018. /**
  31019. *获取对输入框的引用实例。
  31020. */
  31021. __getset(0,__proto,'nativeInput',function(){
  31022. return this._multiline ? Input.area :Input.input;
  31023. });
  31024. // 因此 调用focus接口是无法都在移动平台立刻弹出键盘的
  31025. /**
  31026. *表示焦点是否在此实例上。
  31027. */
  31028. __getset(0,__proto,'focus',function(){
  31029. return this._focus;
  31030. },function(value){
  31031. var input=this.nativeInput;
  31032. if (this._focus!==value){
  31033. if (value){
  31034. if (input.target){
  31035. input.target._focusOut();
  31036. }else {
  31037. this._setInputMethod();
  31038. }
  31039. input.target=this;
  31040. this._focusIn();
  31041. }else {
  31042. input.target=null;
  31043. this._focusOut();
  31044. Browser.document.body.scrollTop=0;
  31045. input.blur();
  31046. if (Render.isConchApp)input.setPos(-10000,-10000);
  31047. else if (Input.inputContainer.contains(input))Input.inputContainer.removeChild(input);
  31048. }
  31049. }
  31050. });
  31051. /**
  31052. *是否可编辑。
  31053. */
  31054. __getset(0,__proto,'editable',function(){
  31055. return this._editable;
  31056. },function(value){
  31057. this._editable=value;
  31058. if (Render.isConchApp){
  31059. Input.input.setForbidEdit(!value);
  31060. }
  31061. });
  31062. /**@inheritDoc */
  31063. __getset(0,__proto,'bgColor',_super.prototype._$get_bgColor,function(value){
  31064. Laya.superSet(Text,this,'bgColor',value);
  31065. if(Render.isConchApp)
  31066. this.nativeInput.setBgColor(value);
  31067. });
  31068. /**限制输入的字符。*/
  31069. __getset(0,__proto,'restrict',function(){
  31070. if (this._restrictPattern){
  31071. return this._restrictPattern.source;
  31072. }
  31073. return "";
  31074. },function(pattern){
  31075. if (pattern){
  31076. pattern="[^"+pattern+"]";
  31077. if (pattern.indexOf("^^")>-1)
  31078. pattern=pattern.replace("^^","");
  31079. this._restrictPattern=new RegExp(pattern,"g");
  31080. }else
  31081. this._restrictPattern=null;
  31082. });
  31083. /**
  31084. *设置输入提示符。
  31085. */
  31086. __getset(0,__proto,'prompt',function(){
  31087. return this._prompt;
  31088. },function(value){
  31089. if (!this._text && value)
  31090. Laya.superSet(Text,this,'color',this._promptColor);
  31091. this.promptColor=this._promptColor;
  31092. if (this._text)
  31093. Laya.superSet(Text,this,'text',(this._text==this._prompt)?value:this._text);
  31094. else
  31095. Laya.superSet(Text,this,'text',value);
  31096. this._prompt=Text.langPacks && Text.langPacks[value] ? Text.langPacks[value] :value;
  31097. });
  31098. /**
  31099. *设置输入提示符颜色。
  31100. */
  31101. __getset(0,__proto,'promptColor',function(){
  31102. return this._promptColor;
  31103. },function(value){
  31104. this._promptColor=value;
  31105. if (!this._content)Laya.superSet(Text,this,'color',value);
  31106. });
  31107. /**
  31108. *<p>输入框类型为Input静态常量之一。</p>
  31109. *<ul>
  31110. *<li>TYPE_TEXT</li>
  31111. *<li>TYPE_PASSWORD</li>
  31112. *<li>TYPE_EMAIL</li>
  31113. *<li>TYPE_URL</li>
  31114. *<li>TYPE_NUMBER</li>
  31115. *<li>TYPE_RANGE</li>
  31116. *<li>TYPE_DATE</li>
  31117. *<li>TYPE_MONTH</li>
  31118. *<li>TYPE_WEEK</li>
  31119. *<li>TYPE_TIME</li>
  31120. *<li>TYPE_DATE_TIME</li>
  31121. *<li>TYPE_DATE_TIME_LOCAL</li>
  31122. *</ul>
  31123. *<p>平台兼容性参见http://www.w3school.com.cn/html5/html_5_form_input_types.asp。</p>
  31124. */
  31125. __getset(0,__proto,'type',function(){
  31126. return this._type;
  31127. },function(value){
  31128. if (value==="password")this._getTextStyle().asPassword=true;
  31129. else this._getTextStyle().asPassword=false;
  31130. this._type=value;
  31131. });
  31132. Input.__init__=function(){
  31133. Input._createInputElement();
  31134. if (Browser.onMobile){
  31135. var isTrue=false;
  31136. if(Browser.onMiniGame || Browser.onBDMiniGame || Browser.onQGMiniGame || Browser.onKGMiniGame || Browser.onVVMiniGame || Browser.onAlipayMiniGame || Browser.onBLMiniGame || Browser.onQQMiniGame){
  31137. isTrue=true;
  31138. }
  31139. Render.canvas.addEventListener(Input.IOS_IFRAME ?(isTrue ? "touchend" :"click"):"touchend",Input._popupInputMethod);
  31140. }
  31141. }
  31142. Input._popupInputMethod=function(e){
  31143. if (!laya.display.Input.isInputting)return;
  31144. var input=laya.display.Input.inputElement;
  31145. input.focus();
  31146. }
  31147. Input._createInputElement=function(){
  31148. Input._initInput(Input.area=Browser.createElement("textarea"));
  31149. Input._initInput(Input.input=Browser.createElement("input"));
  31150. Input.inputContainer=Browser.createElement("div");
  31151. Input.inputContainer.style.position="absolute";
  31152. Input.inputContainer.style.zIndex=1E5;
  31153. Browser.container.appendChild(Input.inputContainer);
  31154. Input.inputContainer.setPos=function (x,y){
  31155. Input.inputContainer.style.left=x+'px';
  31156. Input.inputContainer.style.top=y+'px';
  31157. };
  31158. }
  31159. Input._initInput=function(input){
  31160. var style=input.style;
  31161. style.cssText="position:absolute;overflow:hidden;resize:none;transform-origin:0 0;-webkit-transform-origin:0 0;-moz-transform-origin:0 0;-o-transform-origin:0 0;";
  31162. style.resize='none';
  31163. style.backgroundColor='transparent';
  31164. style.border='none';
  31165. style.outline='none';
  31166. style.zIndex=1;
  31167. input.addEventListener('input',Input._processInputting);
  31168. input.addEventListener('mousemove',Input._stopEvent);
  31169. input.addEventListener('mousedown',Input._stopEvent);
  31170. input.addEventListener('touchmove',Input._stopEvent);
  31171. input.setFontFace=function (fontFace){input.style.fontFamily=fontFace;};
  31172. if(!Render.isConchApp){
  31173. input.setColor=function (color){input.style.color=color;};
  31174. input.setFontSize=function (fontSize){input.style.fontSize=fontSize+'px';};
  31175. }
  31176. }
  31177. Input._processInputting=function(e){
  31178. var input=laya.display.Input.inputElement.target;
  31179. if (!input)return;
  31180. var value=laya.display.Input.inputElement.value;
  31181. if (input._restrictPattern){
  31182. value=value.replace(/\u2006|\x27/g,"");
  31183. if (input._restrictPattern.test(value)){
  31184. value=value.replace(input._restrictPattern,"");
  31185. laya.display.Input.inputElement.value=value;
  31186. }
  31187. }
  31188. input._text=value;
  31189. input.event(/*laya.events.Event.INPUT*/"input");
  31190. }
  31191. Input._stopEvent=function(e){
  31192. if (e.type=='touchmove')
  31193. e.preventDefault();
  31194. e.stopPropagation && e.stopPropagation();
  31195. }
  31196. Input.TYPE_TEXT="text";
  31197. Input.TYPE_PASSWORD="password";
  31198. Input.TYPE_EMAIL="email";
  31199. Input.TYPE_URL="url";
  31200. Input.TYPE_NUMBER="number";
  31201. Input.TYPE_RANGE="range";
  31202. Input.TYPE_DATE="date";
  31203. Input.TYPE_MONTH="month";
  31204. Input.TYPE_WEEK="week";
  31205. Input.TYPE_TIME="time";
  31206. Input.TYPE_DATE_TIME="datetime";
  31207. Input.TYPE_DATE_TIME_LOCAL="datetime-local";
  31208. Input.TYPE_SEARCH="search";
  31209. Input.input=null;
  31210. Input.area=null;
  31211. Input.inputElement=null;
  31212. Input.inputContainer=null;
  31213. Input.confirmButton=null;
  31214. Input.promptStyleDOM=null;
  31215. Input.inputHeight=45;
  31216. Input.isInputting=false;
  31217. Input.stageMatrix=null;
  31218. __static(Input,
  31219. ['IOS_IFRAME',function(){return this.IOS_IFRAME=(Browser.onIOS && Browser.window.top !=Browser.window.self);}
  31220. ]);
  31221. return Input;
  31222. })(Text)
  31223. /**
  31224. *Graphics动画解析器
  31225. *@private
  31226. */
  31227. //class laya.utils.GraphicAnimation extends laya.display.FrameAnimation
  31228. var GraphicAnimation=(function(_super){
  31229. var GraphicNode;
  31230. function GraphicAnimation(){
  31231. /**@private */
  31232. this.animationList=null;
  31233. /**@private */
  31234. this.animationDic=null;
  31235. /**@private */
  31236. this._nodeList=null;
  31237. /**@private */
  31238. this._nodeDefaultProps=null;
  31239. /**@private */
  31240. this._gList=null;
  31241. /**@private */
  31242. this._nodeIDAniDic={};
  31243. /**@private */
  31244. this._rootNode=null;
  31245. /**@private */
  31246. this._nodeGDic=null;
  31247. GraphicAnimation.__super.call(this);
  31248. }
  31249. __class(GraphicAnimation,'laya.utils.GraphicAnimation',_super);
  31250. var __proto=GraphicAnimation.prototype;
  31251. /**@private */
  31252. __proto._parseNodeList=function(uiView){
  31253. if (!this._nodeList)this._nodeList=[];
  31254. this._nodeDefaultProps[uiView.compId]=uiView.props;
  31255. if (uiView.compId)this._nodeList.push(uiView.compId);
  31256. var childs=uiView.child;
  31257. if (childs){
  31258. var i=0,len=childs.length;
  31259. for (i=0;i < len;i++){
  31260. this._parseNodeList(childs[i]);
  31261. }
  31262. }
  31263. }
  31264. /**@private */
  31265. __proto._calGraphicData=function(aniData){
  31266. this._setUp(null,aniData);
  31267. this._createGraphicData();
  31268. if (this._nodeIDAniDic){
  31269. var key;
  31270. for (key in this._nodeIDAniDic){
  31271. this._nodeIDAniDic[key]=null;
  31272. }
  31273. }
  31274. }
  31275. /**@private */
  31276. __proto._createGraphicData=function(){
  31277. var gList=[];
  31278. var i=0,len=this.count;
  31279. var animationDataNew=this._usedFrames;
  31280. if (!animationDataNew)animationDataNew=[];
  31281. var preGraphic;
  31282. for (i=0;i < len;i++){
  31283. if (animationDataNew[i] || !preGraphic){
  31284. preGraphic=this._createFrameGraphic(i);
  31285. }
  31286. gList.push(preGraphic);
  31287. }
  31288. this._gList=gList;
  31289. }
  31290. /**@private */
  31291. __proto._createFrameGraphic=function(frame){
  31292. var g=new Graphics();
  31293. if (!GraphicAnimation._rootMatrix)GraphicAnimation._rootMatrix=new Matrix();
  31294. this._updateNodeGraphic(this._rootNode,frame,GraphicAnimation._rootMatrix,g);
  31295. return g;
  31296. }
  31297. __proto._updateNodeGraphic=function(node,frame,parentTransfrom,g,alpha){
  31298. (alpha===void 0)&& (alpha=1);
  31299. var tNodeG;
  31300. tNodeG=this._nodeGDic[node.compId]=this._getNodeGraphicData(node.compId,frame,this._nodeGDic[node.compId]);
  31301. if (!tNodeG.resultTransform)
  31302. tNodeG.resultTransform=new Matrix();
  31303. var tResultTransform;
  31304. tResultTransform=tNodeG.resultTransform;
  31305. Matrix.mul(tNodeG.transform,parentTransfrom,tResultTransform);
  31306. var tTex;
  31307. var tGraphicAlpha=tNodeG.alpha *alpha;
  31308. if (tGraphicAlpha < 0.01)return;
  31309. if (tNodeG.skin){
  31310. tTex=this._getTextureByUrl(tNodeG.skin);
  31311. if (tTex){
  31312. if (tResultTransform._checkTransform()){
  31313. g.drawTexture(tTex,0,0,tNodeG.width,tNodeG.height,tResultTransform,tGraphicAlpha);
  31314. tNodeG.resultTransform=null;
  31315. }else {
  31316. g.drawTexture(tTex,tResultTransform.tx,tResultTransform.ty,tNodeG.width,tNodeG.height,null,tGraphicAlpha);
  31317. }
  31318. }
  31319. };
  31320. var childs=node.child;
  31321. if (!childs)return;
  31322. var i=0,len=0;
  31323. len=childs.length;
  31324. for (i=0;i < len;i++){
  31325. this._updateNodeGraphic(childs[i],frame,tResultTransform,g,tGraphicAlpha);
  31326. }
  31327. }
  31328. __proto._updateNoChilds=function(tNodeG,g){
  31329. if (!tNodeG.skin)return;
  31330. var tTex=this._getTextureByUrl(tNodeG.skin);
  31331. if (!tTex)return;
  31332. var tTransform=tNodeG.transform;
  31333. tTransform._checkTransform();
  31334. var onlyTranslate=false;
  31335. onlyTranslate=!tTransform._bTransform;
  31336. if (!onlyTranslate){
  31337. g.drawTexture(tTex,0,0,tNodeG.width,tNodeG.height,tTransform.clone(),tNodeG.alpha);
  31338. }else {
  31339. g.drawTexture(tTex,tTransform.tx,tTransform.ty,tNodeG.width,tNodeG.height,null,tNodeG.alpha);
  31340. }
  31341. }
  31342. __proto._updateNodeGraphic2=function(node,frame,g){
  31343. var tNodeG;
  31344. tNodeG=this._nodeGDic[node.compId]=this._getNodeGraphicData(node.compId,frame,this._nodeGDic[node.compId]);
  31345. if (!node.child){
  31346. this._updateNoChilds(tNodeG,g);
  31347. return;
  31348. };
  31349. var tTransform=tNodeG.transform;
  31350. tTransform._checkTransform();
  31351. var onlyTranslate=false;
  31352. onlyTranslate=!tTransform._bTransform;
  31353. var hasTrans=false;
  31354. hasTrans=onlyTranslate && (tTransform.tx !=0 || tTransform.ty !=0);
  31355. var ifSave=false;
  31356. ifSave=(tTransform._bTransform)|| tNodeG.alpha !=1;
  31357. if (ifSave)g.save();
  31358. if (tNodeG.alpha !=1)g.alpha(tNodeG.alpha);
  31359. if (!onlyTranslate)g.transform(tTransform.clone());
  31360. else if (hasTrans)g.translate(tTransform.tx,tTransform.ty);
  31361. var childs=node.child;
  31362. var tTex;
  31363. if (tNodeG.skin){
  31364. tTex=this._getTextureByUrl(tNodeG.skin);
  31365. if (tTex){
  31366. g.drawImage(tTex,0,0,tNodeG.width,tNodeG.height);
  31367. }
  31368. }
  31369. if (childs){
  31370. var i=0,len=0;
  31371. len=childs.length;
  31372. for (i=0;i < len;i++){
  31373. this._updateNodeGraphic2(childs[i],frame,g);
  31374. }
  31375. }
  31376. if (ifSave){
  31377. g.restore();
  31378. }else {
  31379. if (!onlyTranslate){
  31380. g.transform(tTransform.clone().invert());
  31381. }else if (hasTrans){
  31382. g.translate(-tTransform.tx,-tTransform.ty);
  31383. }
  31384. }
  31385. }
  31386. /**@private */
  31387. __proto._calculateKeyFrames=function(node){
  31388. _super.prototype._calculateKeyFrames.call(this,node);
  31389. this._nodeIDAniDic[node.target]=node;
  31390. }
  31391. /**@private */
  31392. __proto.getNodeDataByID=function(nodeID){
  31393. return this._nodeIDAniDic[nodeID];
  31394. }
  31395. /**@private */
  31396. __proto._getParams=function(obj,params,frame,obj2){
  31397. var rst=GraphicAnimation._temParam;
  31398. rst.length=params.length;
  31399. var i=0,len=params.length;
  31400. for (i=0;i < len;i++){
  31401. rst[i]=this._getObjVar(obj,params[i][0],frame,params[i][1],obj2);
  31402. }
  31403. return rst;
  31404. }
  31405. /**@private */
  31406. __proto._getObjVar=function(obj,key,frame,noValue,obj2){
  31407. if (obj.hasOwnProperty(key)){
  31408. var vArr=obj[key];
  31409. if (frame >=vArr.length)frame=vArr.length-1;
  31410. return obj[key][frame];
  31411. }
  31412. if (obj2.hasOwnProperty(key)){
  31413. return obj2[key];
  31414. }
  31415. return noValue;
  31416. }
  31417. __proto._getNodeGraphicData=function(nodeID,frame,rst){
  31418. if (!rst)
  31419. rst=new GraphicNode();
  31420. if (!rst.transform){
  31421. rst.transform=new Matrix();
  31422. }else {
  31423. rst.transform.identity();
  31424. };
  31425. var node=this.getNodeDataByID(nodeID);
  31426. if (!node)return rst;
  31427. var frameData=node.frames;
  31428. var params=this._getParams(frameData,GraphicAnimation._drawTextureCmd,frame,this._nodeDefaultProps[nodeID]);
  31429. var url=params[0];
  31430. var width=NaN,height=NaN;
  31431. var px=params[5],py=params[6];
  31432. var aX=params[13],aY=params[14];
  31433. var sx=params[7],sy=params[8];
  31434. var rotate=params[9];
  31435. var skewX=params[11],skewY=params[12]
  31436. width=params[3];
  31437. height=params[4];
  31438. if (width==0 || height==0)url=null;
  31439. if (width==-1)width=0;
  31440. if (height==-1)height=0;
  31441. var tex;
  31442. rst.skin=url;
  31443. rst.width=width;
  31444. rst.height=height;
  31445. if (url){
  31446. tex=this._getTextureByUrl(url);
  31447. if (tex){
  31448. if (!width)
  31449. width=tex.sourceWidth;
  31450. if (!height)
  31451. height=tex.sourceHeight;
  31452. }else {
  31453. console.warn("lost skin:",url,",you may load pics first");
  31454. }
  31455. }
  31456. rst.alpha=params[10];
  31457. var m=rst.transform;
  31458. if (aX !=0){
  31459. px=aX *width;
  31460. }
  31461. if (aY !=0){
  31462. py=aY *height;
  31463. }
  31464. if (px !=0 || py !=0){
  31465. m.translate(-px,-py);
  31466. };
  31467. var tm=null;
  31468. if (rotate || sx!==1 || sy!==1 || skewX || skewY){
  31469. tm=GraphicAnimation._tempMt;
  31470. tm.identity();
  31471. tm._bTransform=true;
  31472. var skx=(rotate-skewX)*0.0174532922222222;
  31473. var sky=(rotate+skewY)*0.0174532922222222;
  31474. var cx=Math.cos(sky);
  31475. var ssx=Math.sin(sky);
  31476. var cy=Math.sin(skx);
  31477. var ssy=Math.cos(skx);
  31478. tm.a=sx *cx;
  31479. tm.b=sx *ssx;
  31480. tm.c=-sy *cy;
  31481. tm.d=sy *ssy;
  31482. tm.tx=tm.ty=0;
  31483. }
  31484. if (tm){
  31485. m=Matrix.mul(m,tm,m);
  31486. }
  31487. m.translate(params[1],params[2]);
  31488. return rst;
  31489. }
  31490. /**@private */
  31491. __proto._getTextureByUrl=function(url){
  31492. return Loader.getRes(url);
  31493. }
  31494. /**@private */
  31495. __proto.setAniData=function(uiView,aniName){
  31496. if (uiView.animations){
  31497. this._nodeDefaultProps={};
  31498. this._nodeGDic={};
  31499. if (this._nodeList)this._nodeList.length=0;
  31500. this._rootNode=uiView;
  31501. this._parseNodeList(uiView);
  31502. var aniDic={};
  31503. var anilist=[];
  31504. var animations=uiView.animations;
  31505. var i=0,len=animations.length;
  31506. var tAniO;
  31507. for (i=0;i < len;i++){
  31508. tAniO=animations[i];
  31509. this._labels=null;
  31510. if (aniName && aniName !=tAniO.name){
  31511. continue ;
  31512. }
  31513. if (!tAniO)
  31514. continue ;
  31515. try {
  31516. this._calGraphicData(tAniO);
  31517. }catch (e){
  31518. console.warn("parse animation fail:"+tAniO.name+",empty animation created");
  31519. this._gList=[];
  31520. };
  31521. var frameO={};
  31522. frameO.interval=1000 / tAniO["frameRate"];
  31523. frameO.frames=this._gList;
  31524. frameO.labels=this._labels;
  31525. frameO.name=tAniO.name;
  31526. anilist.push(frameO);
  31527. aniDic[tAniO.name]=frameO;
  31528. }
  31529. this.animationList=anilist;
  31530. this.animationDic=aniDic;
  31531. }
  31532. GraphicAnimation._temParam.length=0;
  31533. }
  31534. __proto.parseByData=function(aniData){
  31535. var rootNode,aniO;
  31536. rootNode=aniData.nodeRoot;
  31537. aniO=aniData.aniO;
  31538. delete aniData.nodeRoot;
  31539. delete aniData.aniO;
  31540. this._nodeDefaultProps={};
  31541. this._nodeGDic={};
  31542. if (this._nodeList)this._nodeList.length=0;
  31543. this._rootNode=rootNode;
  31544. this._parseNodeList(rootNode);
  31545. this._labels=null;
  31546. try {
  31547. this._calGraphicData(aniO);
  31548. }catch (e){
  31549. console.warn("parse animation fail:"+aniO.name+",empty animation created");
  31550. this._gList=[];
  31551. };
  31552. var frameO=aniData;
  31553. frameO.interval=1000 / aniO["frameRate"];
  31554. frameO.frames=this._gList;
  31555. frameO.labels=this._labels;
  31556. frameO.name=aniO.name;
  31557. return frameO;
  31558. }
  31559. /**@private */
  31560. __proto.setUpAniData=function(uiView){
  31561. if (uiView.animations){
  31562. var aniDic={};
  31563. var anilist=[];
  31564. var animations=uiView.animations;
  31565. var i=0,len=animations.length;
  31566. var tAniO;
  31567. for (i=0;i < len;i++){
  31568. tAniO=animations[i];
  31569. if (!tAniO)continue ;
  31570. var frameO={};
  31571. frameO.name=tAniO.name;
  31572. frameO.aniO=tAniO;
  31573. frameO.nodeRoot=uiView;
  31574. anilist.push(frameO);
  31575. aniDic[tAniO.name]=frameO;
  31576. }
  31577. this.animationList=anilist;
  31578. this.animationDic=aniDic;
  31579. }
  31580. }
  31581. /**@private */
  31582. __proto._clear=function(){
  31583. this.animationList=null;
  31584. this.animationDic=null;
  31585. this._gList=null;
  31586. this._nodeGDic=null;
  31587. }
  31588. GraphicAnimation.parseAnimationByData=function(animationObject){
  31589. if (!GraphicAnimation._I)GraphicAnimation._I=new GraphicAnimation();
  31590. var rst;
  31591. rst=GraphicAnimation._I.parseByData(animationObject);
  31592. GraphicAnimation._I._clear();
  31593. return rst;
  31594. }
  31595. GraphicAnimation.parseAnimationData=function(aniData){
  31596. if (!GraphicAnimation._I)GraphicAnimation._I=new GraphicAnimation();
  31597. GraphicAnimation._I.setUpAniData(aniData);
  31598. var rst;
  31599. rst={};
  31600. rst.animationList=GraphicAnimation._I.animationList;
  31601. rst.animationDic=GraphicAnimation._I.animationDic;
  31602. GraphicAnimation._I._clear();
  31603. return rst;
  31604. }
  31605. GraphicAnimation._temParam=[];
  31606. GraphicAnimation._I=null;
  31607. GraphicAnimation._rootMatrix=null;
  31608. __static(GraphicAnimation,
  31609. ['_drawTextureCmd',function(){return this._drawTextureCmd=[["skin",null],["x",0],["y",0],["width",-1],["height",-1],["pivotX",0],["pivotY",0],["scaleX",1],["scaleY",1],["rotation",0],["alpha",1],["skewX",0],["skewY",0],["anchorX",0],["anchorY",0]];},'_tempMt',function(){return this._tempMt=new Matrix();}
  31610. ]);
  31611. GraphicAnimation.__init$=function(){
  31612. //class GraphicNode
  31613. GraphicNode=(function(){
  31614. function GraphicNode(){
  31615. this.skin=null;
  31616. this.transform=null;
  31617. this.resultTransform=null;
  31618. this.width=NaN;
  31619. this.height=NaN;
  31620. this.alpha=1;
  31621. }
  31622. __class(GraphicNode,'');
  31623. return GraphicNode;
  31624. })()
  31625. }
  31626. return GraphicAnimation;
  31627. })(FrameAnimation)
  31628. /**
  31629. *<p> 动效模板。用于为指定目标对象添加动画效果。每个动效有唯一的目标对象,而同一个对象可以添加多个动效。 当一个动效开始播放时,其他动效会自动停止播放。</p>
  31630. *<p> 可以通过LayaAir IDE创建。 </p>
  31631. */
  31632. //class laya.display.EffectAnimation extends laya.display.FrameAnimation
  31633. var EffectAnimation=(function(_super){
  31634. function EffectAnimation(){
  31635. /**@private */
  31636. this._target=null;
  31637. /**@private */
  31638. this._playEvent=null;
  31639. /**@private */
  31640. this._initData={};
  31641. /**@private */
  31642. this._aniKeys=null;
  31643. /**@private */
  31644. this._effectClass=null;
  31645. EffectAnimation.__super.call(this);
  31646. }
  31647. __class(EffectAnimation,'laya.display.EffectAnimation',_super);
  31648. var __proto=EffectAnimation.prototype;
  31649. /**@private */
  31650. __proto._onOtherBegin=function(effect){
  31651. if (effect===this)return;
  31652. this.stop();
  31653. }
  31654. /**@private */
  31655. __proto._addEvent=function(){
  31656. if (!this._target || !this._playEvent)return;
  31657. this._setControlNode(this._target);
  31658. this._target.on(this._playEvent,this,this._onPlayAction);
  31659. }
  31660. /**@private */
  31661. __proto._onPlayAction=function(){
  31662. this.play(0,false);
  31663. }
  31664. __proto.play=function(start,loop,name){
  31665. (start===void 0)&& (start=0);
  31666. (loop===void 0)&& (loop=true);
  31667. (name===void 0)&& (name="");
  31668. if (!this._target)
  31669. return;
  31670. this._target.event("effectbegin",[this]);
  31671. this._recordInitData();
  31672. laya.display.AnimationBase.prototype.play.call(this,start,loop,name);
  31673. }
  31674. /**@private */
  31675. __proto._recordInitData=function(){
  31676. if (!this._aniKeys)return;
  31677. var i=0,len=0;
  31678. len=this._aniKeys.length;
  31679. var key;
  31680. for (i=0;i < len;i++){
  31681. key=this._aniKeys[i];
  31682. this._initData[key]=this._target[key];
  31683. }
  31684. }
  31685. /**@private */
  31686. __proto._displayToIndex=function(value){
  31687. if (!this._animationData)return;
  31688. if (value < 0)value=0;
  31689. if (value > this._count)value=this._count;
  31690. var nodes=this._animationData.nodes,i=0,len=nodes.length;
  31691. len=len > 1 ? 1 :len;
  31692. for (i=0;i < len;i++){
  31693. this._displayNodeToFrame(nodes[i],value);
  31694. }
  31695. }
  31696. /**@private */
  31697. __proto._displayNodeToFrame=function(node,frame,targetDic){
  31698. if (!this._target)return;
  31699. var target=this._target;
  31700. var frames=node.frames,key,propFrames,value;
  31701. var keys=node.keys,i=0,len=keys.length;
  31702. var secondFrames=node.secondFrames;
  31703. var tSecondFrame=0;
  31704. var easeFun;
  31705. var tKeyFrames;
  31706. var startFrame;
  31707. var endFrame;
  31708. for (i=0;i < len;i++){
  31709. key=keys[i];
  31710. propFrames=frames[key];
  31711. tSecondFrame=secondFrames[key];
  31712. if (tSecondFrame==-1){
  31713. value=this._initData[key];
  31714. }else {
  31715. if (frame < tSecondFrame){
  31716. tKeyFrames=node.keyframes[key];
  31717. startFrame=tKeyFrames[0];
  31718. if (startFrame.tween){
  31719. easeFun=Ease[startFrame.tweenMethod];
  31720. if (easeFun==null)easeFun=Ease.linearNone;
  31721. endFrame=tKeyFrames[1];
  31722. value=easeFun(frame,this._initData[key],endFrame.value-this._initData[key],endFrame.index);
  31723. }else {
  31724. value=this._initData[key];
  31725. }
  31726. }else {
  31727. if (propFrames.length > frame)value=propFrames[frame];
  31728. else value=propFrames[propFrames.length-1];
  31729. }
  31730. }
  31731. target[key]=value;
  31732. }
  31733. }
  31734. /**@private */
  31735. __proto._calculateKeyFrames=function(node){
  31736. _super.prototype._calculateKeyFrames.call(this,node);
  31737. var keyFrames=node.keyframes,key,tKeyFrames,target=node.target;
  31738. var secondFrames={};
  31739. node.secondFrames=secondFrames;
  31740. for (key in keyFrames){
  31741. tKeyFrames=keyFrames[key];
  31742. if (tKeyFrames.length <=1)secondFrames[key]=-1;
  31743. else secondFrames[key]=tKeyFrames[1].index;
  31744. }
  31745. }
  31746. /**
  31747. *本实例的目标对象。通过本实例控制目标对象的属性变化。
  31748. *@param v 指定的目标对象。
  31749. */
  31750. __getset(0,__proto,'target',function(){
  31751. return this._target;
  31752. },function(v){
  31753. if (this._target)this._target.off("effectbegin",this,this._onOtherBegin);
  31754. this._target=v;
  31755. if (this._target)this._target.on("effectbegin",this,this._onOtherBegin);
  31756. this._addEvent();
  31757. });
  31758. /**
  31759. *设置开始播放的事件。本实例会侦听目标对象的指定事件,触发后播放相应动画效果。
  31760. *@param event
  31761. */
  31762. __getset(0,__proto,'playEvent',null,function(event){
  31763. this._playEvent=event;
  31764. if (!event)return;
  31765. this._addEvent();
  31766. });
  31767. /**
  31768. *设置动画数据。
  31769. *@param uiData
  31770. */
  31771. __getset(0,__proto,'effectData',null,function(uiData){
  31772. if (uiData){
  31773. var aniData=uiData["animations"];
  31774. if (aniData && aniData[0]){
  31775. var data=aniData[0];
  31776. this._setUp({},data);
  31777. if (data.nodes && data.nodes[0]){
  31778. this._aniKeys=data.nodes[0].keys;
  31779. }
  31780. }
  31781. }
  31782. });
  31783. /**
  31784. *设置提供数据的类。
  31785. *@param classStr 类路径
  31786. */
  31787. __getset(0,__proto,'effectClass',null,function(classStr){
  31788. this._effectClass=ClassUtils.getClass(classStr);
  31789. if (this._effectClass){
  31790. var uiData=this._effectClass["uiView"];
  31791. if (uiData){
  31792. var aniData=uiData["animations"];
  31793. if (aniData && aniData[0]){
  31794. var data=aniData[0];
  31795. this._setUp({},data);
  31796. if (data.nodes && data.nodes[0]){
  31797. this._aniKeys=data.nodes[0].keys;
  31798. }
  31799. }
  31800. }
  31801. }
  31802. });
  31803. EffectAnimation.EFFECT_BEGIN="effectbegin";
  31804. return EffectAnimation;
  31805. })(FrameAnimation)
  31806. Laya.__init([LoaderManager,EventDispatcher,Context,Path,GraphicAnimation,SceneUtils,Render,SubmitCMD,Timer,CallLater,LocalStorage,SubmitCanvas,SubmitTarget,TimeLine]);
  31807. })(window,document,Laya);
  31808. (function(window,document,Laya){
  31809. var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
  31810. //class LayaMain
  31811. var LayaMain=(function(){
  31812. /*[COMPILER OPTIONS:normal]*/
  31813. function LayaMain(){}
  31814. __class(LayaMain,'LayaMain');
  31815. return LayaMain;
  31816. })()
  31817. /**LayaGameStart**/
  31818. new LayaMain();
  31819. })(window,document,Laya);