laya.core.js 977 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299
  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.0beta";
  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. //class laya.webgl.submit.Submit
  611. var Submit=(function(){
  612. function Submit(renderType){
  613. this.clipInfoID=-1;
  614. //用来比较clipinfo
  615. this._mesh=null;
  616. //代替 _vb,_ib
  617. this._blendFn=null;
  618. this._id=0;
  619. //protected var _isSelfVb:Boolean=false;
  620. this._renderType=0;
  621. this._parent=null;
  622. // 从VB中什么地方开始画,画到哪
  623. this._startIdx=0;
  624. //indexbuffer 的偏移,单位是byte
  625. this._numEle=0;
  626. this._ref=1;
  627. this.shaderValue=null;
  628. this._key=new SubmitKey();
  629. (renderType===void 0)&& (renderType=10000);
  630. this._renderType=renderType;
  631. this._id=++Submit.ID;
  632. }
  633. __class(Submit,'laya.webgl.submit.Submit');
  634. var __proto=Submit.prototype;
  635. Laya.imps(__proto,{"laya.webgl.submit.ISubmit":true})
  636. //TODO:coverage
  637. __proto.getID=function(){
  638. return this._id;
  639. }
  640. __proto.releaseRender=function(){
  641. if (Submit.RENDERBASE==this)
  642. return;
  643. if((--this._ref)<1){
  644. Submit.POOL[Submit._poolSize++]=this;
  645. this.shaderValue.release();
  646. this.shaderValue=null;
  647. this._mesh=null;
  648. this._parent && (this._parent.releaseRender(),this._parent=null);
  649. }
  650. }
  651. //TODO:coverage
  652. __proto.getRenderType=function(){
  653. return this._renderType;
  654. }
  655. __proto.renderSubmit=function(){
  656. if (this._numEle===0 || !this._mesh || this._numEle==0)return 1;
  657. var _tex=this.shaderValue.textureHost;
  658. if (_tex){
  659. var source=_tex._getSource();
  660. if (!source)
  661. return 1;
  662. this.shaderValue.texture=source;
  663. };
  664. var gl=WebGL.mainContext;
  665. this._mesh.useMesh(gl);
  666. this.shaderValue.upload();
  667. if (BlendMode.activeBlendFunction!==this._blendFn){
  668. WebGLContext.setBlend(gl,true);
  669. this._blendFn(gl);
  670. BlendMode.activeBlendFunction=this._blendFn;
  671. }
  672. gl.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,this._numEle,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,this._startIdx);
  673. Stat.renderBatches++;
  674. Stat.trianglesFaces+=this._numEle / 3;
  675. return 1;
  676. }
  677. //TODO:coverage
  678. __proto._cloneInit=function(o,context,mesh,pos){;
  679. o._ref=1;
  680. o._mesh=mesh;
  681. o._id=this._id;
  682. o._key.copyFrom(this._key);
  683. o._parent=this;
  684. o._blendFn=this._blendFn;
  685. o._renderType=this._renderType;
  686. o._startIdx=pos *CONST3D2D.BYTES_PIDX;
  687. o._numEle=this._numEle;
  688. o.shaderValue=this.shaderValue;
  689. this.shaderValue.ref++;
  690. this._ref++;
  691. }
  692. //TODO:coverage
  693. __proto.clone=function(context,mesh,pos){;
  694. return null;
  695. }
  696. //TODO:coverage
  697. __proto.reUse=function(context,pos){;
  698. return 0;
  699. }
  700. //TODO:coverage
  701. __proto.toString=function(){
  702. return "ibindex:"+this._startIdx+" num:"+this._numEle+" key="+this._key;
  703. }
  704. Submit.__init__=function(){
  705. var s=Submit.RENDERBASE=new Submit(-1);
  706. s.shaderValue=new Value2D(0,0);
  707. s.shaderValue.ALPHA=1;
  708. s._ref=0xFFFFFFFF;
  709. }
  710. Submit.create=function(context,mesh,sv){;
  711. var o=Submit._poolSize ? Submit.POOL[--Submit._poolSize] :new Submit();
  712. o._ref=1;
  713. o._mesh=mesh;
  714. o._key.clear();
  715. o._startIdx=mesh.indexNum *CONST3D2D.BYTES_PIDX;
  716. o._numEle=0;
  717. var blendType=context._nBlendType;
  718. o._blendFn=context._targets ? BlendMode.targetFns[blendType] :BlendMode.fns[blendType];
  719. o.shaderValue=sv;
  720. o.shaderValue.setValue(context._shader2D);
  721. var filters=context._shader2D.filters;
  722. filters && o.shaderValue.setFilters(filters);
  723. return o;
  724. }
  725. Submit.createShape=function(ctx,mesh,numEle,sv){
  726. var o=Submit._poolSize ? Submit.POOL[--Submit._poolSize]:(new Submit());
  727. o._mesh=mesh;
  728. o._numEle=numEle;
  729. o._startIdx=mesh.indexNum *2;
  730. o._ref=1;
  731. o.shaderValue=sv;
  732. o.shaderValue.setValue(ctx._shader2D);
  733. var blendType=ctx._nBlendType;
  734. o._key.blendShader=blendType;
  735. o._blendFn=ctx._targets ? BlendMode.targetFns[blendType] :BlendMode.fns[blendType];
  736. return o;
  737. }
  738. Submit.TYPE_2D=10000;
  739. Submit.TYPE_CANVAS=10003;
  740. Submit.TYPE_CMDSETRT=10004;
  741. Submit.TYPE_CUSTOM=10005;
  742. Submit.TYPE_BLURRT=10006;
  743. Submit.TYPE_CMDDESTORYPRERT=10007;
  744. Submit.TYPE_DISABLESTENCIL=10008;
  745. Submit.TYPE_OTHERIBVB=10009;
  746. Submit.TYPE_PRIMITIVE=10010;
  747. Submit.TYPE_RT=10011;
  748. Submit.TYPE_BLUR_RT=10012;
  749. Submit.TYPE_TARGET=10013;
  750. Submit.TYPE_CHANGE_VALUE=10014;
  751. Submit.TYPE_SHAPE=10015;
  752. Submit.TYPE_TEXTURE=10016;
  753. Submit.TYPE_FILLTEXTURE=10017;
  754. Submit.KEY_ONCE=-1;
  755. Submit.KEY_FILLRECT=1;
  756. Submit.KEY_DRAWTEXTURE=2;
  757. Submit.KEY_VG=3;
  758. Submit.KEY_TRIANGLES=4;
  759. Submit.RENDERBASE=null;
  760. Submit.ID=1;
  761. Submit.preRender=null;
  762. Submit._poolSize=0;
  763. Submit.POOL=[];
  764. return Submit;
  765. })()
  766. /**
  767. *填充贴图
  768. */
  769. //class laya.display.cmd.FillTextureCmd
  770. var FillTextureCmd=(function(){
  771. function FillTextureCmd(){
  772. /**
  773. *纹理。
  774. */
  775. //this.texture=null;
  776. /**
  777. *X轴偏移量。
  778. */
  779. //this.x=NaN;
  780. /**
  781. *Y轴偏移量。
  782. */
  783. //this.y=NaN;
  784. /**
  785. *(可选)宽度。
  786. */
  787. //this.width=NaN;
  788. /**
  789. *(可选)高度。
  790. */
  791. //this.height=NaN;
  792. /**
  793. *(可选)填充类型 repeat|repeat-x|repeat-y|no-repeat
  794. */
  795. //this.type=null;
  796. /**
  797. *(可选)贴图纹理偏移
  798. */
  799. //this.offset=null;
  800. /**@private */
  801. //this.other=null;
  802. }
  803. __class(FillTextureCmd,'laya.display.cmd.FillTextureCmd');
  804. var __proto=FillTextureCmd.prototype;
  805. /**
  806. *回收到对象池
  807. */
  808. __proto.recover=function(){
  809. this.texture=null;
  810. this.offset=null;
  811. this.other=null;
  812. Pool.recover("FillTextureCmd",this);
  813. }
  814. /**@private */
  815. __proto.run=function(context,gx,gy){
  816. context.fillTexture(this.texture,this.x+gx,this.y+gy,this.width,this.height,this.type,this.offset,this.other);
  817. }
  818. /**@private */
  819. __getset(0,__proto,'cmdID',function(){
  820. return "FillTexture";
  821. });
  822. FillTextureCmd.create=function(texture,x,y,width,height,type,offset,other){
  823. var cmd=Pool.getItemByClass("FillTextureCmd",FillTextureCmd);
  824. cmd.texture=texture;
  825. cmd.x=x;
  826. cmd.y=y;
  827. cmd.width=width;
  828. cmd.height=height;
  829. cmd.type=type;
  830. cmd.offset=offset;
  831. cmd.other=other;
  832. return cmd;
  833. }
  834. FillTextureCmd.ID="FillTexture";
  835. return FillTextureCmd;
  836. })()
  837. /**
  838. *<code>Filter</code> 是滤镜基类。
  839. */
  840. //class laya.filters.Filter
  841. var Filter=(function(){
  842. function Filter(){
  843. /**@private*/
  844. this._glRender=null;
  845. }
  846. __class(Filter,'laya.filters.Filter');
  847. var __proto=Filter.prototype;
  848. Laya.imps(__proto,{"laya.filters.IFilter":true})
  849. /**@private 滤镜类型。*/
  850. __getset(0,__proto,'type',function(){return-1 });
  851. Filter.BLUR=0x10;
  852. Filter.COLOR=0x20;
  853. Filter.GLOW=0x08;
  854. Filter._filter=function(sprite,context,x,y){
  855. var webglctx=context;
  856. var next=(this)._next;
  857. if (next){
  858. var filters=sprite.filters,len=filters.length;
  859. if (len==1 && (filters[0].type==/*CLASS CONST:laya.filters.Filter.COLOR*/0x20)){
  860. context.save();
  861. context.setColorFilter(filters[0]);
  862. next._fun.call(next,sprite,context,x,y);
  863. context.restore();
  864. return;
  865. };
  866. var svCP=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  867. var b;
  868. var p=Point.TEMP;
  869. var tMatrix=webglctx._curMat;
  870. var mat=Matrix.create();
  871. tMatrix.copyTo(mat);
  872. var tPadding=0;
  873. var tHalfPadding=0;
  874. var tIsHaveGlowFilter=false;
  875. var source=null;
  876. var out=sprite._cacheStyle.filterCache || null;
  877. if (!out || sprite.getRepaint()!=0){
  878. tIsHaveGlowFilter=sprite._isHaveGlowFilter();
  879. if (tIsHaveGlowFilter){
  880. tPadding=50;
  881. tHalfPadding=25;
  882. }
  883. b=new Rectangle();
  884. b.copyFrom(sprite.getSelfBounds());
  885. b.x+=sprite.x;
  886. b.y+=sprite.y;
  887. b.x-=sprite.pivotX+4;
  888. b.y-=sprite.pivotY+4;
  889. var tSX=b.x;
  890. var tSY=b.y;
  891. b.width+=(tPadding+8);
  892. b.height+=(tPadding+8);
  893. p.x=b.x *mat.a+b.y *mat.c;
  894. p.y=b.y *mat.d+b.x *mat.b;
  895. b.x=p.x;
  896. b.y=p.y;
  897. p.x=b.width *mat.a+b.height *mat.c;
  898. p.y=b.height *mat.d+b.width *mat.b;
  899. b.width=p.x;
  900. b.height=p.y;
  901. if (b.width <=0 || b.height <=0){
  902. return;
  903. }
  904. out && WebGLRTMgr.releaseRT(out);
  905. source=WebGLRTMgr.getRT(b.width,b.height);
  906. var outRT=out=WebGLRTMgr.getRT(b.width,b.height);
  907. sprite._getCacheStyle().filterCache=out;
  908. webglctx.pushRT();
  909. webglctx.useRT(source);
  910. var tX=sprite.x-tSX+tHalfPadding;
  911. var tY=sprite.y-tSY+tHalfPadding;
  912. next._fun.call(next,sprite,context,tX,tY);
  913. webglctx.useRT(outRT);
  914. for (var i=0;i < len;i++){
  915. if (i !=0){
  916. webglctx.useRT(source);
  917. webglctx.drawTarget(outRT,0,0,b.width,b.height,Matrix.TEMP.identity(),svCP,null,BlendMode.TOINT.overlay);
  918. webglctx.useRT(outRT);
  919. };
  920. var fil=filters[i];
  921. switch (fil.type){
  922. case /*CLASS CONST:laya.filters.Filter.BLUR*/0x10:
  923. fil._glRender && fil._glRender.render(source,context,b.width,b.height,fil);
  924. break ;
  925. case /*CLASS CONST:laya.filters.Filter.GLOW*/0x08:
  926. fil._glRender && fil._glRender.render(source,context,b.width,b.height,fil);
  927. break ;
  928. case /*CLASS CONST:laya.filters.Filter.COLOR*/0x20:
  929. webglctx.setColorFilter(fil);
  930. webglctx.drawTarget(source,0,0,b.width,b.height,Matrix.EMPTY.identity(),Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  931. webglctx.setColorFilter(null);
  932. break ;
  933. }
  934. }
  935. webglctx.popRT();
  936. }else {
  937. tIsHaveGlowFilter=sprite._cacheStyle.hasGlowFilter || false;
  938. if (tIsHaveGlowFilter){
  939. tPadding=50;
  940. tHalfPadding=25;
  941. }
  942. b=sprite.getBounds();
  943. if (b.width <=0 || b.height <=0){
  944. return;
  945. }
  946. b.width+=tPadding;
  947. b.height+=tPadding;
  948. p.x=b.x *mat.a+b.y *mat.c;
  949. p.y=b.y *mat.d+b.x *mat.b;
  950. b.x=p.x;
  951. b.y=p.y;
  952. p.x=b.width *mat.a+b.height *mat.c;
  953. p.y=b.height *mat.d+b.width *mat.b;
  954. b.width=p.x;
  955. b.height=p.y;
  956. }
  957. x=x-tHalfPadding-sprite.x;
  958. y=y-tHalfPadding-sprite.y;
  959. p.setTo(x,y);
  960. mat.transformPoint(p);
  961. x=p.x+b.x;
  962. y=p.y+b.y;
  963. webglctx._drawRenderTexture(out,x,y,b.width,b.height,Matrix.TEMP.identity(),1.0,RenderTexture2D.defuv);
  964. if(source){
  965. var submit=SubmitCMD.create([source],function(s){
  966. s.destroy();
  967. },this);
  968. source=null;
  969. context.addRenderObject(submit);
  970. }
  971. mat.destroy();
  972. }
  973. }
  974. return Filter;
  975. })()
  976. /**
  977. *<code>Log</code> 类用于在界面内显示日志记录信息。
  978. *注意:在加速器内不可使用
  979. */
  980. //class laya.utils.Log
  981. var Log=(function(){
  982. function Log(){}
  983. __class(Log,'laya.utils.Log');
  984. Log.enable=function(){
  985. if (!Log._logdiv){
  986. Log._logdiv=Browser.createElement('div');
  987. 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%;";
  988. Browser.document.body.appendChild(Log._logdiv);
  989. Log._btn=Browser.createElement("button");
  990. Log._btn.innerText="Hide";
  991. Log._btn.style.cssText="z-index:1000001;position: absolute;left:10px;top:10px;";
  992. Log._btn.onclick=Log.toggle;
  993. Browser.document.body.appendChild(Log._btn);
  994. }
  995. }
  996. Log.toggle=function(){
  997. var style=Log._logdiv.style;
  998. if (style.display===""){
  999. Log._btn.innerText="Show";
  1000. style.display="none";
  1001. }else {
  1002. Log._btn.innerText="Hide";
  1003. style.display="";
  1004. }
  1005. }
  1006. Log.print=function(value){
  1007. if (Log._logdiv){
  1008. if (Log._count >=Log.maxCount)Log.clear();
  1009. Log._count++;
  1010. Log._logdiv.innerText+=value+"\n";
  1011. if (Log.autoScrollToBottom){
  1012. if (Log._logdiv.scrollHeight-Log._logdiv.scrollTop-Log._logdiv.clientHeight < 50){
  1013. Log._logdiv.scrollTop=Log._logdiv.scrollHeight;
  1014. }
  1015. }
  1016. }
  1017. }
  1018. Log.clear=function(){
  1019. Log._logdiv.innerText="";
  1020. Log._count=0;
  1021. }
  1022. Log._logdiv=null;
  1023. Log._btn=null;
  1024. Log._count=0;
  1025. Log.maxCount=50;
  1026. Log.autoScrollToBottom=true;
  1027. return Log;
  1028. })()
  1029. /**
  1030. *@private
  1031. *Touch事件管理类,处理多点触控下的鼠标事件
  1032. */
  1033. //class laya.events.TouchManager
  1034. var TouchManager=(function(){
  1035. function TouchManager(){
  1036. /**
  1037. *当前over的touch表
  1038. */
  1039. this.preOvers=[];
  1040. /**
  1041. *当前down的touch表
  1042. */
  1043. this.preDowns=[];
  1044. this.preRightDowns=[];
  1045. /**
  1046. *是否启用
  1047. */
  1048. this.enable=true;
  1049. this._lastClickTime=0;
  1050. this._event=new Event();
  1051. }
  1052. __class(TouchManager,'laya.events.TouchManager');
  1053. var __proto=TouchManager.prototype;
  1054. __proto._clearTempArrs=function(){
  1055. TouchManager._oldArr.length=0;
  1056. TouchManager._newArr.length=0;
  1057. TouchManager._tEleArr.length=0;
  1058. }
  1059. /**
  1060. *从touch表里查找对应touchID的数据
  1061. *@param touchID touch ID
  1062. *@param arr touch表
  1063. *@return
  1064. *
  1065. */
  1066. __proto.getTouchFromArr=function(touchID,arr){
  1067. var i=0,len=0;
  1068. len=arr.length;
  1069. var tTouchO;
  1070. for (i=0;i < len;i++){
  1071. tTouchO=arr[i];
  1072. if (tTouchO.id==touchID){
  1073. return tTouchO;
  1074. }
  1075. }
  1076. return null;
  1077. }
  1078. /**
  1079. *从touch表里移除一个元素
  1080. *@param touchID touch ID
  1081. *@param arr touch表
  1082. *
  1083. */
  1084. __proto.removeTouchFromArr=function(touchID,arr){
  1085. var i=0;
  1086. for (i=arr.length-1;i >=0;i--){
  1087. if (arr[i].id==touchID){
  1088. arr.splice(i,1);
  1089. }
  1090. }
  1091. }
  1092. /**
  1093. *创建一个touch数据
  1094. *@param ele 当前的根节点
  1095. *@param touchID touchID
  1096. *@return
  1097. *
  1098. */
  1099. __proto.createTouchO=function(ele,touchID){
  1100. var rst;
  1101. rst=Pool.getItem("TouchData")|| {};
  1102. rst.id=touchID;
  1103. rst.tar=ele;
  1104. return rst;
  1105. }
  1106. /**
  1107. *处理touchStart
  1108. *@param ele 根节点
  1109. *@param touchID touchID
  1110. *@param isLeft (可选)是否为左键
  1111. */
  1112. __proto.onMouseDown=function(ele,touchID,isLeft){
  1113. (isLeft===void 0)&& (isLeft=false);
  1114. if (!this.enable)
  1115. return;
  1116. var preO;
  1117. var tO;
  1118. var arrs;
  1119. preO=this.getTouchFromArr(touchID,this.preOvers);
  1120. arrs=this.getEles(ele,null,TouchManager._tEleArr);
  1121. if (!preO){
  1122. tO=this.createTouchO(ele,touchID);
  1123. this.preOvers.push(tO);
  1124. }else {
  1125. preO.tar=ele;
  1126. }
  1127. if (Browser.onMobile)
  1128. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OVER*/"mouseover");
  1129. var preDowns;
  1130. preDowns=isLeft ? this.preDowns :this.preRightDowns;
  1131. preO=this.getTouchFromArr(touchID,preDowns);
  1132. if (!preO){
  1133. tO=this.createTouchO(ele,touchID);
  1134. preDowns.push(tO);
  1135. }else {
  1136. preO.tar=ele;
  1137. }
  1138. this.sendEvents(arrs,isLeft ? /*laya.events.Event.MOUSE_DOWN*/"mousedown" :/*laya.events.Event.RIGHT_MOUSE_DOWN*/"rightmousedown");
  1139. this._clearTempArrs();
  1140. }
  1141. /**
  1142. *派发事件。
  1143. *@param eles 对象列表。
  1144. *@param type 事件类型。
  1145. */
  1146. __proto.sendEvents=function(eles,type){
  1147. var i=0,len=0;
  1148. len=eles.length;
  1149. this._event._stoped=false;
  1150. var _target;
  1151. _target=eles[0];
  1152. var tE;
  1153. for (i=0;i < len;i++){
  1154. tE=eles[i];
  1155. if (tE.destroyed)return;
  1156. tE.event(type,this._event.setTo(type,tE,_target));
  1157. if (this._event._stoped)
  1158. break ;
  1159. }
  1160. }
  1161. /**
  1162. *获取对象列表。
  1163. *@param start 起始节点。
  1164. *@param end 结束节点。
  1165. *@param rst 返回值。如果此值不为空,则将其赋值为计算结果,从而避免创建新数组;如果此值为空,则创建新数组返回。
  1166. *@return Array 返回节点列表。
  1167. */
  1168. __proto.getEles=function(start,end,rst){
  1169. if (!rst){
  1170. rst=[];
  1171. }else {
  1172. rst.length=0;
  1173. }
  1174. while (start && start !=end){
  1175. rst.push(start);
  1176. start=start.parent;
  1177. }
  1178. return rst;
  1179. }
  1180. /**
  1181. *touchMove时处理out事件和over时间。
  1182. *@param eleNew 新的根节点。
  1183. *@param elePre 旧的根节点。
  1184. *@param touchID (可选)touchID,默认为0。
  1185. */
  1186. __proto.checkMouseOutAndOverOfMove=function(eleNew,elePre,touchID){
  1187. (touchID===void 0)&& (touchID=0);
  1188. if (elePre==eleNew)
  1189. return;
  1190. var tar;
  1191. var arrs;
  1192. var i=0,len=0;
  1193. if (elePre.contains(eleNew)){
  1194. arrs=this.getEles(eleNew,elePre,TouchManager._tEleArr);
  1195. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OVER*/"mouseover");
  1196. }else if (eleNew.contains(elePre)){
  1197. arrs=this.getEles(elePre,eleNew,TouchManager._tEleArr);
  1198. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OUT*/"mouseout");
  1199. }else {
  1200. arrs=TouchManager._tEleArr;
  1201. arrs.length=0;
  1202. var oldArr;
  1203. oldArr=this.getEles(elePre,null,TouchManager._oldArr);
  1204. var newArr;
  1205. newArr=this.getEles(eleNew,null,TouchManager._newArr);
  1206. len=oldArr.length;
  1207. var tIndex=0;
  1208. for (i=0;i < len;i++){
  1209. tar=oldArr[i];
  1210. tIndex=newArr.indexOf(tar);
  1211. if (tIndex >=0){
  1212. newArr.splice(tIndex,newArr.length-tIndex);
  1213. break ;
  1214. }else {
  1215. arrs.push(tar);
  1216. }
  1217. }
  1218. if (arrs.length > 0){
  1219. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OUT*/"mouseout");
  1220. }
  1221. if (newArr.length > 0){
  1222. this.sendEvents(newArr,/*laya.events.Event.MOUSE_OVER*/"mouseover");
  1223. }
  1224. }
  1225. }
  1226. /**
  1227. *处理TouchMove事件
  1228. *@param ele 根节点
  1229. *@param touchID touchID
  1230. *
  1231. */
  1232. __proto.onMouseMove=function(ele,touchID){
  1233. if (!this.enable)
  1234. return;
  1235. var preO;
  1236. preO=this.getTouchFromArr(touchID,this.preOvers);
  1237. var arrs;
  1238. var tO;
  1239. if (!preO){
  1240. arrs=this.getEles(ele,null,TouchManager._tEleArr);
  1241. this.sendEvents(arrs,/*laya.events.Event.MOUSE_OVER*/"mouseover");
  1242. this.preOvers.push(this.createTouchO(ele,touchID));
  1243. }else {
  1244. this.checkMouseOutAndOverOfMove(ele,preO.tar);
  1245. preO.tar=ele;
  1246. arrs=this.getEles(ele,null,TouchManager._tEleArr);
  1247. }
  1248. this.sendEvents(arrs,/*laya.events.Event.MOUSE_MOVE*/"mousemove");
  1249. this._clearTempArrs();
  1250. }
  1251. __proto.getLastOvers=function(){
  1252. TouchManager._tEleArr.length=0;
  1253. if (this.preOvers.length > 0 && this.preOvers[0].tar){
  1254. return this.getEles(this.preOvers[0].tar,null,TouchManager._tEleArr);
  1255. }
  1256. TouchManager._tEleArr.push(Laya.stage);
  1257. return TouchManager._tEleArr;
  1258. }
  1259. __proto.stageMouseOut=function(){
  1260. var lastOvers;
  1261. lastOvers=this.getLastOvers();
  1262. this.preOvers.length=0;
  1263. this.sendEvents(lastOvers,/*laya.events.Event.MOUSE_OUT*/"mouseout");
  1264. }
  1265. /**
  1266. *处理TouchEnd事件
  1267. *@param ele 根节点
  1268. *@param touchID touchID
  1269. *@param isLeft 是否为左键
  1270. */
  1271. __proto.onMouseUp=function(ele,touchID,isLeft){
  1272. (isLeft===void 0)&& (isLeft=false);
  1273. if (!this.enable)
  1274. return;
  1275. var preO;
  1276. var tO;
  1277. var arrs;
  1278. var oldArr;
  1279. var i=0,len=0;
  1280. var tar;
  1281. var sendArr;
  1282. var onMobile=Browser.onMobile;
  1283. arrs=this.getEles(ele,null,TouchManager._tEleArr);
  1284. this.sendEvents(arrs,isLeft ? /*laya.events.Event.MOUSE_UP*/"mouseup" :/*laya.events.Event.RIGHT_MOUSE_UP*/"rightmouseup");
  1285. var preDowns;
  1286. preDowns=isLeft ? this.preDowns :this.preRightDowns;
  1287. preO=this.getTouchFromArr(touchID,preDowns);
  1288. if (!preO){
  1289. }else {
  1290. var isDouble=false;
  1291. var now=Browser.now();
  1292. isDouble=now-this._lastClickTime < 300;
  1293. this._lastClickTime=now;
  1294. if (ele==preO.tar){
  1295. sendArr=arrs;
  1296. }else {
  1297. oldArr=this.getEles(preO.tar,null,TouchManager._oldArr);
  1298. sendArr=TouchManager._newArr;
  1299. sendArr.length=0;
  1300. len=oldArr.length;
  1301. for (i=0;i < len;i++){
  1302. tar=oldArr[i];
  1303. if (arrs.indexOf(tar)>=0){
  1304. sendArr.push(tar);
  1305. }
  1306. }
  1307. }
  1308. if (sendArr.length > 0){
  1309. this.sendEvents(sendArr,isLeft ? /*laya.events.Event.CLICK*/"click" :/*laya.events.Event.RIGHT_CLICK*/"rightclick");
  1310. }
  1311. if (isLeft && isDouble){
  1312. this.sendEvents(sendArr,/*laya.events.Event.DOUBLE_CLICK*/"doubleclick");
  1313. }
  1314. this.removeTouchFromArr(touchID,preDowns);
  1315. preO.tar=null;
  1316. Pool.recover("TouchData",preO);
  1317. }
  1318. preO=this.getTouchFromArr(touchID,this.preOvers);
  1319. if (!preO){
  1320. }else {
  1321. if (onMobile){
  1322. sendArr=this.getEles(preO.tar,null,sendArr);
  1323. if (sendArr && sendArr.length > 0){
  1324. this.sendEvents(sendArr,/*laya.events.Event.MOUSE_OUT*/"mouseout");
  1325. }
  1326. this.removeTouchFromArr(touchID,this.preOvers);
  1327. preO.tar=null;
  1328. Pool.recover("TouchData",preO);
  1329. }
  1330. }
  1331. this._clearTempArrs();
  1332. }
  1333. TouchManager._oldArr=[];
  1334. TouchManager._newArr=[];
  1335. TouchManager._tEleArr=[];
  1336. __static(TouchManager,
  1337. ['I',function(){return this.I=new TouchManager();}
  1338. ]);
  1339. return TouchManager;
  1340. })()
  1341. //class laya.webgl.submit.SubmitTarget
  1342. var SubmitTarget=(function(){
  1343. function SubmitTarget(){
  1344. this._mesh=null;
  1345. //代替 _vb,_ib
  1346. this._startIdx=0;
  1347. this._numEle=0;
  1348. this.shaderValue=null;
  1349. this.blendType=0;
  1350. this._ref=1;
  1351. //public var scope:SubmitCMDScope;
  1352. this.srcRT=null;
  1353. this._key=new SubmitKey();
  1354. }
  1355. __class(SubmitTarget,'laya.webgl.submit.SubmitTarget');
  1356. var __proto=SubmitTarget.prototype;
  1357. Laya.imps(__proto,{"laya.webgl.submit.ISubmit":true})
  1358. __proto.renderSubmit=function(){
  1359. var gl=WebGL.mainContext;
  1360. this._mesh.useMesh(gl);
  1361. var target=this.srcRT;
  1362. if (target){
  1363. this.shaderValue.texture=target._getSource();
  1364. this.shaderValue.upload();
  1365. this.blend();
  1366. Stat.renderBatches++;
  1367. Stat.trianglesFaces+=this._numEle/3;
  1368. WebGL.mainContext.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,this._numEle,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,this._startIdx);
  1369. }
  1370. return 1;
  1371. }
  1372. __proto.blend=function(){
  1373. if (BlendMode.activeBlendFunction!==BlendMode.fns[this.blendType]){
  1374. var gl=WebGL.mainContext;
  1375. gl.enable(/*laya.webgl.WebGLContext.BLEND*/0x0BE2);
  1376. BlendMode.fns[this.blendType](gl);
  1377. BlendMode.activeBlendFunction=BlendMode.fns[this.blendType];
  1378. }
  1379. }
  1380. //TODO:coverage
  1381. __proto.getRenderType=function(){
  1382. return 0;
  1383. }
  1384. __proto.releaseRender=function(){
  1385. if ((--this._ref)< 1){
  1386. var pool=SubmitTarget.POOL;
  1387. pool[pool._length++]=this;
  1388. }
  1389. }
  1390. //TODO:coverage
  1391. __proto.reUse=function(context,pos){
  1392. this._startIdx=pos;
  1393. this._ref++;
  1394. return pos;
  1395. }
  1396. SubmitTarget.create=function(context,mesh,sv,rt){
  1397. var o=SubmitTarget.POOL._length?SubmitTarget.POOL[--SubmitTarget.POOL._length]:new SubmitTarget();
  1398. o._mesh=mesh;
  1399. o.srcRT=rt;
  1400. o._startIdx=mesh.indexNum *CONST3D2D.BYTES_PIDX;
  1401. o._ref=1;
  1402. o._key.clear();
  1403. o._numEle=0;
  1404. o.blendType=context._nBlendType;
  1405. o._key.blendShader=o.blendType;
  1406. o.shaderValue=sv;
  1407. o.shaderValue.setValue(context._shader2D);
  1408. if (context._colorFiler){
  1409. var ft=context._colorFiler;
  1410. sv.defines.add(ft.type);
  1411. (sv).colorMat=ft._mat;
  1412. (sv).colorAlpha=ft._alpha;
  1413. }
  1414. return o;
  1415. }
  1416. SubmitTarget.POOL=[];
  1417. SubmitTarget.__init$=function(){
  1418. ;{
  1419. SubmitTarget.POOL._length=0;
  1420. }
  1421. }
  1422. return SubmitTarget;
  1423. })()
  1424. /**
  1425. *绘制图片
  1426. */
  1427. //class laya.display.cmd.DrawImageCmd
  1428. var DrawImageCmd=(function(){
  1429. function DrawImageCmd(){
  1430. /**
  1431. *纹理。
  1432. */
  1433. //this.texture=null;
  1434. /**
  1435. *(可选)X轴偏移量。
  1436. */
  1437. //this.x=NaN;
  1438. /**
  1439. *(可选)Y轴偏移量。
  1440. */
  1441. //this.y=NaN;
  1442. /**
  1443. *(可选)宽度。
  1444. */
  1445. //this.width=NaN;
  1446. /**
  1447. *(可选)高度。
  1448. */
  1449. //this.height=NaN;
  1450. }
  1451. __class(DrawImageCmd,'laya.display.cmd.DrawImageCmd');
  1452. var __proto=DrawImageCmd.prototype;
  1453. /**
  1454. *回收到对象池
  1455. */
  1456. __proto.recover=function(){
  1457. this.texture._removeReference();
  1458. this.texture=null;
  1459. Pool.recover("DrawImageCmd",this);
  1460. }
  1461. /**@private */
  1462. __proto.run=function(context,gx,gy){
  1463. context.drawTexture(this.texture,this.x+gx,this.y+gy,this.width,this.height);
  1464. }
  1465. /**@private */
  1466. __getset(0,__proto,'cmdID',function(){
  1467. return "DrawImage";
  1468. });
  1469. DrawImageCmd.create=function(texture,x,y,width,height){
  1470. var cmd=Pool.getItemByClass("DrawImageCmd",DrawImageCmd);
  1471. cmd.texture=texture;
  1472. texture._addReference();
  1473. cmd.x=x;
  1474. cmd.y=y;
  1475. cmd.width=width;
  1476. cmd.height=height;
  1477. return cmd;
  1478. }
  1479. DrawImageCmd.ID="DrawImage";
  1480. return DrawImageCmd;
  1481. })()
  1482. /**
  1483. *<code>Component</code> 类用于创建组件的基类。
  1484. */
  1485. //class laya.components.Component
  1486. var Component=(function(){
  1487. function Component(){
  1488. /**@private [实现IListPool接口]*/
  1489. //this._destroyed=false;
  1490. /**@private [实现IListPool接口]*/
  1491. //this._indexInList=0;
  1492. /**@private */
  1493. //this._id=0;
  1494. /**@private */
  1495. //this._enabled=false;
  1496. /**@private */
  1497. //this._awaked=false;
  1498. /**
  1499. *[只读]获取所属Node节点。
  1500. *@readonly
  1501. */
  1502. //this.owner=null;
  1503. this._id=Utils.getGID();
  1504. this._resetComp();
  1505. }
  1506. __class(Component,'laya.components.Component');
  1507. var __proto=Component.prototype;
  1508. Laya.imps(__proto,{"laya.resource.ISingletonElement":true,"laya.resource.IDestroy":true})
  1509. /**
  1510. *@private
  1511. */
  1512. __proto._isScript=function(){
  1513. return false;
  1514. }
  1515. /**
  1516. *@private
  1517. */
  1518. __proto._resetComp=function(){
  1519. this._indexInList=-1;
  1520. this._enabled=true;
  1521. this._awaked=false;
  1522. this.owner=null;
  1523. }
  1524. /**
  1525. *[实现IListPool接口]
  1526. *@private
  1527. */
  1528. __proto._getIndexInList=function(){
  1529. return this._indexInList;
  1530. }
  1531. /**
  1532. *[实现IListPool接口]
  1533. *@private
  1534. */
  1535. __proto._setIndexInList=function(index){
  1536. this._indexInList=index;
  1537. }
  1538. /**
  1539. *被添加到节点后调用,可根据需要重写此方法
  1540. *@private
  1541. */
  1542. __proto._onAdded=function(){}
  1543. /**
  1544. *被激活后调用,可根据需要重写此方法
  1545. *@private
  1546. */
  1547. __proto._onAwake=function(){}
  1548. /**
  1549. *被激活后调用,可根据需要重写此方法
  1550. *@private
  1551. */
  1552. __proto._onEnable=function(){}
  1553. /**
  1554. *被禁用时调用,可根据需要重写此方法
  1555. *@private
  1556. */
  1557. __proto._onDisable=function(){}
  1558. /**
  1559. *被添加到Scene后调用,无论Scene是否在舞台上,可根据需要重写此方法
  1560. *@private
  1561. */
  1562. __proto._onEnableInScene=function(){}
  1563. /**
  1564. *从Scene移除后调用,无论Scene是否在舞台上,可根据需要重写此方法
  1565. *@private
  1566. */
  1567. __proto._onDisableInScene=function(){}
  1568. /**
  1569. *被销毁时调用,可根据需要重写此方法
  1570. *@private
  1571. */
  1572. __proto._onDestroy=function(){}
  1573. /**
  1574. *重置组件参数到默认值,如果实现了这个函数,则组件会被重置并且自动回收到对象池,方便下次复用
  1575. *如果没有重置,则不进行回收复用
  1576. *此方法为虚方法,使用时重写覆盖即可
  1577. */
  1578. __proto.onReset=function(){}
  1579. /**
  1580. *@private
  1581. */
  1582. __proto._parse=function(data){}
  1583. /**
  1584. *@private
  1585. */
  1586. __proto._cloneTo=function(dest){}
  1587. /**
  1588. *@private
  1589. */
  1590. __proto._setActive=function(value){
  1591. if (value){
  1592. if (!this._awaked){
  1593. this._awaked=true;
  1594. this._onAwake();
  1595. }
  1596. this._enabled && this._onEnable();
  1597. }else {
  1598. this._enabled && this._onDisable();
  1599. }
  1600. }
  1601. /**
  1602. *@private
  1603. */
  1604. __proto._setActiveInScene=function(value){
  1605. if (value)this._onEnableInScene();
  1606. else this._onDisableInScene();
  1607. }
  1608. /**
  1609. *销毁组件
  1610. */
  1611. __proto.destroy=function(){
  1612. if (this.owner)this.owner._destroyComponent(this);
  1613. }
  1614. /**
  1615. *@private
  1616. */
  1617. __proto._destroy=function(){
  1618. if (this.owner.activeInHierarchy && this._enabled){
  1619. this._setActive(false);
  1620. (this._isScript())&& ((this).onDisable());
  1621. }
  1622. this.owner._scene && this._setActiveInScene(false);
  1623. this._onDestroy();
  1624. this._destroyed=true;
  1625. if (this.onReset!==laya.components.Component.prototype.onReset){
  1626. this.onReset();
  1627. this._resetComp();
  1628. Pool.recoverByClass(this);
  1629. }else {
  1630. this._resetComp();
  1631. }
  1632. }
  1633. /**
  1634. *获取唯一标识ID。
  1635. */
  1636. __getset(0,__proto,'id',function(){
  1637. return this._id;
  1638. });
  1639. /**
  1640. *获取是否启用组件。
  1641. */
  1642. __getset(0,__proto,'enabled',function(){
  1643. return this._enabled;
  1644. },function(value){
  1645. this._enabled=value;
  1646. if (this.owner){
  1647. if (value)
  1648. this.owner.activeInHierarchy && this._onEnable();
  1649. else
  1650. this.owner.activeInHierarchy && this._onDisable();
  1651. }
  1652. });
  1653. /**
  1654. *获取是否为单实例组件。
  1655. */
  1656. __getset(0,__proto,'isSingleton',function(){
  1657. return true;
  1658. });
  1659. /**
  1660. *获取是否已经销毁 。
  1661. */
  1662. __getset(0,__proto,'destroyed',function(){
  1663. return this._destroyed;
  1664. });
  1665. return Component;
  1666. })()
  1667. /**
  1668. *<code>EventDispatcher</code> 类是可调度事件的所有类的基类。
  1669. */
  1670. //class laya.events.EventDispatcher
  1671. var EventDispatcher=(function(){
  1672. var EventHandler;
  1673. function EventDispatcher(){
  1674. /**@private */
  1675. this._$0__events=null;
  1676. }
  1677. __class(EventDispatcher,'laya.events.EventDispatcher');
  1678. var __proto=EventDispatcher.prototype;
  1679. /**
  1680. *检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
  1681. *@param type 事件的类型。
  1682. *@return 如果指定类型的侦听器已注册,则值为 true;否则,值为 false。
  1683. */
  1684. __proto.hasListener=function(type){
  1685. var listener=this._$0__events && this._$0__events[type];
  1686. return !!listener;
  1687. }
  1688. /**
  1689. *派发事件。
  1690. *@param type 事件类型。
  1691. *@param data (可选)回调数据。<b>注意:</b>如果是需要传递多个参数 p1,p2,p3,...可以使用数组结构如:[p1,p2,p3,...] ;如果需要回调单个参数 p ,且 p 是一个数组,则需要使用结构如:[p],其他的单个参数 p ,可以直接传入参数 p。
  1692. *@return 此事件类型是否有侦听者,如果有侦听者则值为 true,否则值为 false。
  1693. */
  1694. __proto.event=function(type,data){
  1695. if (!this._$0__events || !this._$0__events[type])return false;
  1696. var listeners=this._$0__events[type];
  1697. if (listeners.run){
  1698. if (listeners.once)delete this._$0__events[type];
  1699. data !=null ? listeners.runWith(data):listeners.run();
  1700. }else {
  1701. for (var i=0,n=listeners.length;i < n;i++){
  1702. var listener=listeners[i];
  1703. if (listener){
  1704. (data !=null)? listener.runWith(data):listener.run();
  1705. }
  1706. if (!listener || listener.once){
  1707. listeners.splice(i,1);
  1708. i--;
  1709. n--;
  1710. }
  1711. }
  1712. if (listeners.length===0 && this._$0__events)delete this._$0__events[type];
  1713. }
  1714. return true;
  1715. }
  1716. /**
  1717. *使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知。
  1718. *@param type 事件的类型。
  1719. *@param caller 事件侦听函数的执行域。
  1720. *@param listener 事件侦听函数。
  1721. *@param args (可选)事件侦听函数的回调参数。
  1722. *@return 此 EventDispatcher 对象。
  1723. */
  1724. __proto.on=function(type,caller,listener,args){
  1725. return this._createListener(type,caller,listener,args,false);
  1726. }
  1727. /**
  1728. *使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知,此侦听事件响应一次后自动移除。
  1729. *@param type 事件的类型。
  1730. *@param caller 事件侦听函数的执行域。
  1731. *@param listener 事件侦听函数。
  1732. *@param args (可选)事件侦听函数的回调参数。
  1733. *@return 此 EventDispatcher 对象。
  1734. */
  1735. __proto.once=function(type,caller,listener,args){
  1736. return this._createListener(type,caller,listener,args,true);
  1737. }
  1738. /**@private */
  1739. __proto._createListener=function(type,caller,listener,args,once,offBefore){
  1740. (offBefore===void 0)&& (offBefore=true);
  1741. offBefore && this.off(type,caller,listener,once);
  1742. var handler=EventHandler.create(caller || this,listener,args,once);
  1743. this._$0__events || (this._$0__events={});
  1744. var events=this._$0__events;
  1745. if (!events[type])events[type]=handler;
  1746. else {
  1747. if (!events[type].run)events[type].push(handler);
  1748. else events[type]=[events[type],handler];
  1749. }
  1750. return this;
  1751. }
  1752. /**
  1753. *从 EventDispatcher 对象中删除侦听器。
  1754. *@param type 事件的类型。
  1755. *@param caller 事件侦听函数的执行域。
  1756. *@param listener 事件侦听函数。
  1757. *@param onceOnly (可选)如果值为 true ,则只移除通过 once 方法添加的侦听器。
  1758. *@return 此 EventDispatcher 对象。
  1759. */
  1760. __proto.off=function(type,caller,listener,onceOnly){
  1761. (onceOnly===void 0)&& (onceOnly=false);
  1762. if (!this._$0__events || !this._$0__events[type])return this;
  1763. var listeners=this._$0__events[type];
  1764. if (listeners !=null){
  1765. if (listeners.run){
  1766. if ((!caller || listeners.caller===caller)&& (listener==null || listeners.method===listener)&& (!onceOnly || listeners.once)){
  1767. delete this._$0__events[type];
  1768. listeners.recover();
  1769. }
  1770. }else {
  1771. var count=0;
  1772. for (var i=0,n=listeners.length;i < n;i++){
  1773. var item=listeners[i];
  1774. if (!item){
  1775. count++;
  1776. continue ;
  1777. }
  1778. if (item && (!caller || item.caller===caller)&& (listener==null || item.method===listener)&& (!onceOnly || item.once)){
  1779. count++;
  1780. listeners[i]=null;
  1781. item.recover();
  1782. }
  1783. }
  1784. if (count===n)delete this._$0__events[type];
  1785. }
  1786. }
  1787. return this;
  1788. }
  1789. /**
  1790. *从 EventDispatcher 对象中删除指定事件类型的所有侦听器。
  1791. *@param type (可选)事件类型,如果值为 null,则移除本对象所有类型的侦听器。
  1792. *@return 此 EventDispatcher 对象。
  1793. */
  1794. __proto.offAll=function(type){
  1795. var events=this._$0__events;
  1796. if (!events)return this;
  1797. if (type){
  1798. this._recoverHandlers(events[type]);
  1799. delete events[type];
  1800. }else {
  1801. for (var name in events){
  1802. this._recoverHandlers(events[name]);
  1803. }
  1804. this._$0__events=null;
  1805. }
  1806. return this;
  1807. }
  1808. /**
  1809. *移除caller为target的所有事件监听
  1810. *@param caller caller对象
  1811. */
  1812. __proto.offAllCaller=function(caller){
  1813. if (caller && this._$0__events){
  1814. for (var name in this._$0__events){
  1815. this.off(name,caller,null);
  1816. }
  1817. }
  1818. return this;
  1819. }
  1820. __proto._recoverHandlers=function(arr){
  1821. if (!arr)return;
  1822. if (arr.run){
  1823. arr.recover();
  1824. }else {
  1825. for (var i=arr.length-1;i >-1;i--){
  1826. if (arr[i]){
  1827. arr[i].recover();
  1828. arr[i]=null;
  1829. }
  1830. }
  1831. }
  1832. }
  1833. /**
  1834. *检测指定事件类型是否是鼠标事件。
  1835. *@param type 事件的类型。
  1836. *@return 如果是鼠标事件,则值为 true;否则,值为 false。
  1837. */
  1838. __proto.isMouseEvent=function(type){
  1839. return EventDispatcher.MOUSE_EVENTS[type] || false;
  1840. }
  1841. EventDispatcher.MOUSE_EVENTS={"rightmousedown":true,"rightmouseup":true,"rightclick":true,"mousedown":true,"mouseup":true,"mousemove":true,"mouseover":true,"mouseout":true,"click":true,"doubleclick":true};
  1842. EventDispatcher.__init$=function(){
  1843. Object.defineProperty(laya.events.EventDispatcher.prototype,"_events",{enumerable:false,writable:true});
  1844. /**@private */
  1845. //class EventHandler extends laya.utils.Handler
  1846. EventHandler=(function(_super){
  1847. function EventHandler(caller,method,args,once){
  1848. EventHandler.__super.call(this,caller,method,args,once);
  1849. }
  1850. __class(EventHandler,'',_super);
  1851. var __proto=EventHandler.prototype;
  1852. __proto.recover=function(){
  1853. if (this._id > 0){
  1854. this._id=0;
  1855. EventHandler._pool.push(this.clear());
  1856. }
  1857. }
  1858. EventHandler.create=function(caller,method,args,once){
  1859. (once===void 0)&& (once=true);
  1860. if (EventHandler._pool.length)return EventHandler._pool.pop().setTo(caller,method,args,once);
  1861. return new EventHandler(caller,method,args,once);
  1862. }
  1863. EventHandler._pool=[];
  1864. return EventHandler;
  1865. })(Handler)
  1866. }
  1867. return EventDispatcher;
  1868. })()
  1869. /**
  1870. *<p><code>Handler</code> 是事件处理器类。</p>
  1871. *<p>推荐使用 Handler.create()方法从对象池创建,减少对象创建消耗。创建的 Handler 对象不再使用后,可以使用 Handler.recover()将其回收到对象池,回收后不要再使用此对象,否则会导致不可预料的错误。</p>
  1872. *<p><b>注意:</b>由于鼠标事件也用本对象池,不正确的回收及调用,可能会影响鼠标事件的执行。</p>
  1873. */
  1874. //class laya.utils.Handler
  1875. var Handler=(function(){
  1876. function Handler(caller,method,args,once){
  1877. /**执行域(this)。*/
  1878. //this.caller=null;
  1879. /**处理方法。*/
  1880. //this.method=null;
  1881. /**参数。*/
  1882. //this.args=null;
  1883. /**表示是否只执行一次。如果为true,回调后执行recover()进行回收,回收后会被再利用,默认为false 。*/
  1884. this.once=false;
  1885. /**@private */
  1886. this._id=0;
  1887. (once===void 0)&& (once=false);
  1888. this.setTo(caller,method,args,once);
  1889. }
  1890. __class(Handler,'laya.utils.Handler');
  1891. var __proto=Handler.prototype;
  1892. /**
  1893. *设置此对象的指定属性值。
  1894. *@param caller 执行域(this)。
  1895. *@param method 回调方法。
  1896. *@param args 携带的参数。
  1897. *@param once 是否只执行一次,如果为true,执行后执行recover()进行回收。
  1898. *@return 返回 handler 本身。
  1899. */
  1900. __proto.setTo=function(caller,method,args,once){
  1901. this._id=Handler._gid++;
  1902. this.caller=caller;
  1903. this.method=method;
  1904. this.args=args;
  1905. this.once=once;
  1906. return this;
  1907. }
  1908. /**
  1909. *执行处理器。
  1910. */
  1911. __proto.run=function(){
  1912. if (this.method==null)return null;
  1913. var id=this._id;
  1914. var result=this.method.apply(this.caller,this.args);
  1915. this._id===id && this.once && this.recover();
  1916. return result;
  1917. }
  1918. /**
  1919. *执行处理器,并携带额外数据。
  1920. *@param data 附加的回调数据,可以是单数据或者Array(作为多参)。
  1921. */
  1922. __proto.runWith=function(data){
  1923. if (this.method==null)return null;
  1924. var id=this._id;
  1925. if (data==null)
  1926. var result=this.method.apply(this.caller,this.args);
  1927. else if (!this.args && !data.unshift)result=this.method.call(this.caller,data);
  1928. else if (this.args)result=this.method.apply(this.caller,this.args.concat(data));
  1929. else result=this.method.apply(this.caller,data);
  1930. this._id===id && this.once && this.recover();
  1931. return result;
  1932. }
  1933. /**
  1934. *清理对象引用。
  1935. */
  1936. __proto.clear=function(){
  1937. this.caller=null;
  1938. this.method=null;
  1939. this.args=null;
  1940. return this;
  1941. }
  1942. /**
  1943. *清理并回收到 Handler 对象池内。
  1944. */
  1945. __proto.recover=function(){
  1946. if (this._id > 0){
  1947. this._id=0;
  1948. Handler._pool.push(this.clear());
  1949. }
  1950. }
  1951. Handler.create=function(caller,method,args,once){
  1952. (once===void 0)&& (once=true);
  1953. if (Handler._pool.length)return Handler._pool.pop().setTo(caller,method,args,once);
  1954. return new Handler(caller,method,args,once);
  1955. }
  1956. Handler._pool=[];
  1957. Handler._gid=1;
  1958. return Handler;
  1959. })()
  1960. //class laya.webgl.shader.d2.skinAnishader.SkinMeshBuffer
  1961. var SkinMeshBuffer=(function(){
  1962. function SkinMeshBuffer(){
  1963. this.ib=null;
  1964. this.vb=null;
  1965. var gl=WebGL.mainContext;
  1966. this.ib=IndexBuffer2D.create(/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
  1967. this.vb=VertexBuffer2D.create(8);
  1968. }
  1969. __class(SkinMeshBuffer,'laya.webgl.shader.d2.skinAnishader.SkinMeshBuffer');
  1970. var __proto=SkinMeshBuffer.prototype;
  1971. //TODO:coverage
  1972. __proto.addSkinMesh=function(skinMesh){
  1973. skinMesh.getData2(this.vb,this.ib,this.vb._byteLength / 32);
  1974. }
  1975. __proto.reset=function(){
  1976. this.vb.clear();
  1977. this.ib.clear();
  1978. }
  1979. SkinMeshBuffer.getInstance=function(){
  1980. return SkinMeshBuffer.instance=SkinMeshBuffer.instance|| new SkinMeshBuffer();
  1981. }
  1982. SkinMeshBuffer.instance=null;
  1983. return SkinMeshBuffer;
  1984. })()
  1985. /**
  1986. *绘制三角形命令
  1987. */
  1988. //class laya.display.cmd.DrawTrianglesCmd
  1989. var DrawTrianglesCmd=(function(){
  1990. function DrawTrianglesCmd(){
  1991. /**
  1992. *纹理。
  1993. */
  1994. //this.texture=null;
  1995. /**
  1996. *X轴偏移量。
  1997. */
  1998. //this.x=NaN;
  1999. /**
  2000. *Y轴偏移量。
  2001. */
  2002. //this.y=NaN;
  2003. /**
  2004. *顶点数组。
  2005. */
  2006. //this.vertices=null;
  2007. /**
  2008. *UV数据。
  2009. */
  2010. //this.uvs=null;
  2011. /**
  2012. *顶点索引。
  2013. */
  2014. //this.indices=null;
  2015. /**
  2016. *缩放矩阵。
  2017. */
  2018. //this.matrix=null;
  2019. /**
  2020. *alpha
  2021. */
  2022. //this.alpha=NaN;
  2023. /**
  2024. *blend模式
  2025. */
  2026. //this.blendMode=null;
  2027. /**
  2028. *颜色变换
  2029. */
  2030. //this.color=null;
  2031. }
  2032. __class(DrawTrianglesCmd,'laya.display.cmd.DrawTrianglesCmd');
  2033. var __proto=DrawTrianglesCmd.prototype;
  2034. /**
  2035. *回收到对象池
  2036. */
  2037. __proto.recover=function(){
  2038. this.texture=null;
  2039. this.vertices=null;
  2040. this.uvs=null;
  2041. this.indices=null;
  2042. this.matrix=null;
  2043. Pool.recover("DrawTrianglesCmd",this);
  2044. }
  2045. /**@private */
  2046. __proto.run=function(context,gx,gy){
  2047. context.drawTriangles(this.texture,this.x+gx,this.y+gy,this.vertices,this.uvs,this.indices,this.matrix,this.alpha,this.color,this.blendMode);
  2048. }
  2049. /**@private */
  2050. __getset(0,__proto,'cmdID',function(){
  2051. return "DrawTriangles";
  2052. });
  2053. DrawTrianglesCmd.create=function(texture,x,y,vertices,uvs,indices,matrix,alpha,color,blendMode){
  2054. var cmd=Pool.getItemByClass("DrawTrianglesCmd",DrawTrianglesCmd);
  2055. cmd.texture=texture;
  2056. cmd.x=x;
  2057. cmd.y=y;
  2058. cmd.vertices=vertices;
  2059. cmd.uvs=uvs;
  2060. cmd.indices=indices;
  2061. cmd.matrix=matrix;
  2062. cmd.alpha=alpha;
  2063. if (color){
  2064. cmd.color=new ColorFilter();
  2065. var c=ColorUtils.create(color).arrColor;
  2066. cmd.color.color(c[0]*255,c[1]*255,c[2]*255,c[3]*255);
  2067. }
  2068. cmd.blendMode=blendMode;
  2069. return cmd;
  2070. }
  2071. DrawTrianglesCmd.ID="DrawTriangles";
  2072. return DrawTrianglesCmd;
  2073. })()
  2074. /**
  2075. *绘制扇形
  2076. */
  2077. //class laya.display.cmd.DrawPieCmd
  2078. var DrawPieCmd=(function(){
  2079. function DrawPieCmd(){
  2080. /**
  2081. *开始绘制的 X 轴位置。
  2082. */
  2083. //this.x=NaN;
  2084. /**
  2085. *开始绘制的 Y 轴位置。
  2086. */
  2087. //this.y=NaN;
  2088. /**
  2089. *扇形半径。
  2090. */
  2091. //this.radius=NaN;
  2092. //this._startAngle=NaN;
  2093. //this._endAngle=NaN;
  2094. /**
  2095. *填充颜色,或者填充绘图的渐变对象。
  2096. */
  2097. //this.fillColor=null;
  2098. /**
  2099. *(可选)边框颜色,或者填充绘图的渐变对象。
  2100. */
  2101. //this.lineColor=null;
  2102. /**
  2103. *(可选)边框宽度。
  2104. */
  2105. //this.lineWidth=NaN;
  2106. /**@private */
  2107. //this.vid=0;
  2108. }
  2109. __class(DrawPieCmd,'laya.display.cmd.DrawPieCmd');
  2110. var __proto=DrawPieCmd.prototype;
  2111. /**
  2112. *回收到对象池
  2113. */
  2114. __proto.recover=function(){
  2115. this.fillColor=null;
  2116. this.lineColor=null;
  2117. Pool.recover("DrawPieCmd",this);
  2118. }
  2119. /**@private */
  2120. __proto.run=function(context,gx,gy){
  2121. context._drawPie(this.x+gx,this.y+gy,this.radius,this._startAngle,this._endAngle,this.fillColor,this.lineColor,this.lineWidth,this.vid);
  2122. }
  2123. /**
  2124. *开始角度。
  2125. */
  2126. __getset(0,__proto,'startAngle',function(){
  2127. return this._startAngle *180 / Math.PI;
  2128. },function(value){
  2129. this._startAngle=value *Math.PI / 180;
  2130. });
  2131. /**@private */
  2132. __getset(0,__proto,'cmdID',function(){
  2133. return "DrawPie";
  2134. });
  2135. /**
  2136. *结束角度。
  2137. */
  2138. __getset(0,__proto,'endAngle',function(){
  2139. return this._endAngle *180 / Math.PI;
  2140. },function(value){
  2141. this._endAngle=value *Math.PI / 180;
  2142. });
  2143. DrawPieCmd.create=function(x,y,radius,startAngle,endAngle,fillColor,lineColor,lineWidth,vid){
  2144. var cmd=Pool.getItemByClass("DrawPieCmd",DrawPieCmd);
  2145. cmd.x=x;
  2146. cmd.y=y;
  2147. cmd.radius=radius;
  2148. cmd._startAngle=startAngle;
  2149. cmd._endAngle=endAngle;
  2150. cmd.fillColor=fillColor;
  2151. cmd.lineColor=lineColor;
  2152. cmd.lineWidth=lineWidth;
  2153. cmd.vid=vid;
  2154. return cmd;
  2155. }
  2156. DrawPieCmd.ID="DrawPie";
  2157. return DrawPieCmd;
  2158. })()
  2159. /**
  2160. *@private
  2161. */
  2162. //class laya.utils.WordText
  2163. var WordText=(function(){
  2164. function WordText(){
  2165. //TODO:
  2166. this.id=NaN;
  2167. this.save=[];
  2168. this.toUpperCase=null;
  2169. this.changed=false;
  2170. this._text=null;
  2171. this.width=-1;
  2172. //整个WordText的长度。-1表示没有计算还。
  2173. this.pageChars=[];
  2174. //把本对象的字符按照texture分组保存的文字信息。里面又是一个数组。具体含义见使用的地方。
  2175. this.startID=0;
  2176. //上面的是个数组,但是可能前面都是空的,加个起始位置
  2177. this.startIDStroke=0;
  2178. this.lastGCCnt=0;
  2179. //如果文字gc了,需要检查缓存是否有效,这里记录上次检查对应的gc值。
  2180. this.splitRender=false;
  2181. }
  2182. __class(WordText,'laya.utils.WordText');
  2183. var __proto=WordText.prototype;
  2184. // 强制拆分渲染
  2185. __proto.setText=function(txt){
  2186. this.changed=true;
  2187. this._text=txt;
  2188. this.width=-1;
  2189. this.cleanCache();
  2190. }
  2191. //TODO:coverage
  2192. __proto.toString=function(){
  2193. return this._text;
  2194. }
  2195. //TODO:coverage
  2196. __proto.charCodeAt=function(i){
  2197. return this._text ? this._text.charCodeAt(i):NaN;
  2198. }
  2199. //TODO:coverage
  2200. __proto.charAt=function(i){
  2201. return this._text ? this._text.charAt(i):null;
  2202. }
  2203. /**
  2204. *自己主动清理缓存,需要把关联的贴图删掉
  2205. *不做也可以,textrender会自动清理不用的
  2206. *TODO 重用
  2207. */
  2208. __proto.cleanCache=function(){
  2209. this.pageChars.forEach(function(p){
  2210. var tex=p.tex;
  2211. var words=p.words;
  2212. if (p.words.length==1 && tex && tex.ri){
  2213. tex.destroy();
  2214. }
  2215. });
  2216. this.pageChars=[];
  2217. this.startID=0;
  2218. }
  2219. __getset(0,__proto,'length',function(){
  2220. return this._text ? this._text.length :0;
  2221. });
  2222. return WordText;
  2223. })()
  2224. /**
  2225. *Mesh2d只是保存数据。描述attribute用的。本身不具有渲染功能。
  2226. */
  2227. //class laya.webgl.utils.Mesh2D
  2228. var Mesh2D=(function(){
  2229. function Mesh2D(stride,vballoc,iballoc){
  2230. this._stride=0;
  2231. //顶点结构大小。每个mesh的顶点结构是固定的。
  2232. this.vertNum=0;
  2233. //当前的顶点的个数
  2234. this.indexNum=0;
  2235. //实际index 个数。例如一个三角形是3个。由于ib本身可能超过实际使用的数量,所以需要一个indexNum
  2236. this._applied=false;
  2237. //是否已经设置给webgl了
  2238. this._vb=null;
  2239. //vb和ib都可能需要在外部修改,所以public
  2240. this._ib=null;
  2241. this._vao=null;
  2242. this._attribInfo=null;
  2243. //保存起来的属性定义数组。
  2244. this._quadNum=0;
  2245. //public static var meshlist:Array=[];//活着的mesh对象列表。
  2246. this.canReuse=false;
  2247. this._stride=stride;
  2248. this._vb=new VertexBuffer2D(stride,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
  2249. if (vballoc){
  2250. this._vb._resizeBuffer(vballoc,false);
  2251. }else{
  2252. Config.webGL2D_MeshAllocMaxMem && this._vb._resizeBuffer(64 *1024 *stride,false);
  2253. }
  2254. this._ib=new IndexBuffer2D();
  2255. if (iballoc){
  2256. this._ib._resizeBuffer(iballoc,false);
  2257. }
  2258. }
  2259. __class(Mesh2D,'laya.webgl.utils.Mesh2D');
  2260. var __proto=Mesh2D.prototype;
  2261. //TODO:coverage
  2262. __proto.cloneWithNewVB=function(){
  2263. var mesh=new Mesh2D(this._stride,0,0);
  2264. mesh._ib=this._ib;
  2265. mesh._quadNum=this._quadNum;
  2266. mesh._attribInfo=this._attribInfo;
  2267. return mesh;
  2268. }
  2269. //TODO:coverage
  2270. __proto.cloneWithNewVBIB=function(){
  2271. var mesh=new Mesh2D(this._stride,0,0);
  2272. mesh._attribInfo=this._attribInfo;
  2273. return mesh;
  2274. }
  2275. //TODO:coverage
  2276. __proto.getVBW=function(){
  2277. this._vb.setNeedUpload();
  2278. return this._vb;
  2279. }
  2280. //TODO:coverage
  2281. __proto.getVBR=function(){
  2282. return this._vb;
  2283. }
  2284. //TODO:coverage
  2285. __proto.getIBR=function(){
  2286. return this._ib;
  2287. }
  2288. //TODO:coverage
  2289. __proto.getIBW=function(){
  2290. this._ib.setNeedUpload();
  2291. return this._ib;
  2292. }
  2293. /**
  2294. *直接创建一个固定的ib。按照固定四边形的索引。
  2295. *@param var QuadNum
  2296. */
  2297. __proto.createQuadIB=function(QuadNum){
  2298. this._quadNum=QuadNum;
  2299. this._ib._resizeBuffer(QuadNum *6 *2,false);
  2300. this._ib.byteLength=this._ib.bufferLength;
  2301. var bd=this._ib.getUint16Array();
  2302. var idx=0;
  2303. var curvert=0;
  2304. for (var i=0;i < QuadNum;i++){
  2305. bd[idx++]=curvert;
  2306. bd[idx++]=curvert+2;
  2307. bd[idx++]=curvert+1;
  2308. bd[idx++]=curvert;
  2309. bd[idx++]=curvert+3;
  2310. bd[idx++]=curvert+2;
  2311. curvert+=4;
  2312. }
  2313. this._ib.setNeedUpload();
  2314. }
  2315. /**
  2316. *设置mesh的属性。每3个一组,对应的location分别是0,1,2...
  2317. *含义是:type,size,offset
  2318. *不允许多流。因此stride是固定的,offset只是在一个vertex之内。
  2319. *@param attribs
  2320. */
  2321. __proto.setAttributes=function(attribs){
  2322. this._attribInfo=attribs;
  2323. if (this._attribInfo.length % 3 !=0){
  2324. throw 'Mesh2D setAttributes error!';
  2325. }
  2326. }
  2327. /**
  2328. *初始化VAO的配置,只需要执行一次。以后使用的时候直接bind就行
  2329. *@param gl
  2330. */
  2331. __proto.configVAO=function(gl){
  2332. if (this._applied)
  2333. return;
  2334. this._applied=true;
  2335. if (!this._vao){
  2336. this._vao=new BufferState2D();
  2337. }
  2338. this._vao.bind();
  2339. this._vb._bindForVAO();
  2340. this._ib.setNeedUpload();
  2341. this._ib._bind_uploadForVAO();
  2342. var attribNum=this._attribInfo.length / 3;
  2343. var idx=0;
  2344. for (var i=0;i < attribNum;i++){
  2345. var _size=this._attribInfo[idx+1];
  2346. var _type=this._attribInfo[idx];
  2347. var _off=this._attribInfo[idx+2];
  2348. gl.enableVertexAttribArray(i);
  2349. gl.vertexAttribPointer(i,_size,_type,false,this._stride,_off);
  2350. idx+=3;
  2351. }
  2352. this._vao.unBind();
  2353. }
  2354. /**
  2355. *应用这个mesh
  2356. *@param gl
  2357. */
  2358. __proto.useMesh=function(gl){
  2359. this._applied || this.configVAO(gl);
  2360. this._vao.bind();
  2361. this._vb.bind();
  2362. this._ib._bind_upload()|| this._ib.bind();
  2363. this._vb._bind_upload()|| this._vb.bind();
  2364. }
  2365. //TODO:coverage
  2366. __proto.getEleNum=function(){
  2367. return this._ib.getBuffer().byteLength / 2;
  2368. }
  2369. /**
  2370. *子类实现。用来把自己放到对应的回收池中,以便复用。
  2371. */
  2372. __proto.releaseMesh=function(){}
  2373. /**
  2374. *释放资源。
  2375. */
  2376. __proto.destroy=function(){}
  2377. /**
  2378. *清理vb数据
  2379. */
  2380. __proto.clearVB=function(){
  2381. this._vb.clear();
  2382. }
  2383. Mesh2D._gvaoid=0;
  2384. return Mesh2D;
  2385. })()
  2386. /**
  2387. *<code>Event</code> 是事件类型的集合。一般当发生事件时,<code>Event</code> 对象将作为参数传递给事件侦听器。
  2388. */
  2389. //class laya.events.Event
  2390. var Event=(function(){
  2391. function Event(){
  2392. /**事件类型。*/
  2393. //this.type=null;
  2394. /**原生浏览器事件。*/
  2395. //this.nativeEvent=null;
  2396. /**事件目标触发对象。*/
  2397. //this.target=null;
  2398. /**事件当前冒泡对象。*/
  2399. //this.currentTarget=null;
  2400. /**@private */
  2401. //this._stoped=false;
  2402. /**分配给触摸点的唯一标识号(作为 int)。*/
  2403. //this.touchId=0;
  2404. /**键盘值*/
  2405. //this.keyCode=0;
  2406. /**滚轮滑动增量*/
  2407. //this.delta=0;
  2408. }
  2409. __class(Event,'laya.events.Event');
  2410. var __proto=Event.prototype;
  2411. /**
  2412. *设置事件数据。
  2413. *@param type 事件类型。
  2414. *@param currentTarget 事件目标触发对象。
  2415. *@param target 事件当前冒泡对象。
  2416. *@return 返回当前 Event 对象。
  2417. */
  2418. __proto.setTo=function(type,currentTarget,target){
  2419. this.type=type;
  2420. this.currentTarget=currentTarget;
  2421. this.target=target;
  2422. return this;
  2423. }
  2424. /**
  2425. *阻止对事件流中当前节点的后续节点中的所有事件侦听器进行处理。此方法不会影响当前节点 (currentTarget)中的任何事件侦听器。
  2426. */
  2427. __proto.stopPropagation=function(){
  2428. this._stoped=true;
  2429. }
  2430. /**鼠标在 Stage 上的 Y 轴坐标*/
  2431. __getset(0,__proto,'stageY',function(){
  2432. return Laya.stage.mouseY;
  2433. });
  2434. /**
  2435. *包含按下或释放的键的字符代码值。字符代码值为英文键盘值。
  2436. */
  2437. __getset(0,__proto,'charCode',function(){
  2438. return this.nativeEvent.charCode;
  2439. });
  2440. /**
  2441. *触摸点列表。
  2442. */
  2443. __getset(0,__proto,'touches',function(){
  2444. if (!this.nativeEvent)return null;
  2445. var arr=this.nativeEvent.touches;
  2446. if (arr){
  2447. var stage=Laya.stage;
  2448. for (var i=0,n=arr.length;i < n;i++){
  2449. var e=arr[i];
  2450. var point=Point.TEMP;
  2451. point.setTo(e.clientX,e.clientY);
  2452. stage._canvasTransform.invertTransformPoint(point);
  2453. stage.transform.invertTransformPoint(point);
  2454. e.stageX=point.x;
  2455. e.stageY=point.y;
  2456. }
  2457. }
  2458. return arr;
  2459. });
  2460. /**
  2461. *表示键在键盘上的位置。这对于区分在键盘上多次出现的键非常有用。<br>
  2462. *例如,您可以根据此属性的值来区分左 Shift 键和右 Shift 键:左 Shift 键的值为 KeyLocation.LEFT,右 Shift 键的值为 KeyLocation.RIGHT。另一个示例是区分标准键盘 (KeyLocation.STANDARD)与数字键盘 (KeyLocation.NUM_PAD)上按下的数字键。
  2463. */
  2464. __getset(0,__proto,'keyLocation',function(){
  2465. return this.nativeEvent.location || this.nativeEvent.keyLocation;
  2466. });
  2467. /**
  2468. *表示 Ctrl 键是处于活动状态 (true)还是非活动状态 (false)。
  2469. */
  2470. __getset(0,__proto,'ctrlKey',function(){
  2471. return this.nativeEvent.ctrlKey;
  2472. });
  2473. /**
  2474. *表示 Alt 键是处于活动状态 (true)还是非活动状态 (false)。
  2475. */
  2476. __getset(0,__proto,'altKey',function(){
  2477. return this.nativeEvent.altKey;
  2478. });
  2479. /**
  2480. *表示 Shift 键是处于活动状态 (true)还是非活动状态 (false)。
  2481. */
  2482. __getset(0,__proto,'shiftKey',function(){
  2483. return this.nativeEvent.shiftKey;
  2484. });
  2485. /**鼠标在 Stage 上的 X 轴坐标*/
  2486. __getset(0,__proto,'stageX',function(){
  2487. return Laya.stage.mouseX;
  2488. });
  2489. Event.EMPTY=new Event();
  2490. Event.MOUSE_DOWN="mousedown";
  2491. Event.MOUSE_UP="mouseup";
  2492. Event.CLICK="click";
  2493. Event.RIGHT_MOUSE_DOWN="rightmousedown";
  2494. Event.RIGHT_MOUSE_UP="rightmouseup";
  2495. Event.RIGHT_CLICK="rightclick";
  2496. Event.MOUSE_MOVE="mousemove";
  2497. Event.MOUSE_OVER="mouseover";
  2498. Event.MOUSE_OUT="mouseout";
  2499. Event.MOUSE_WHEEL="mousewheel";
  2500. Event.ROLL_OVER="mouseover";
  2501. Event.ROLL_OUT="mouseout";
  2502. Event.DOUBLE_CLICK="doubleclick";
  2503. Event.CHANGE="change";
  2504. Event.CHANGED="changed";
  2505. Event.RESIZE="resize";
  2506. Event.ADDED="added";
  2507. Event.REMOVED="removed";
  2508. Event.DISPLAY="display";
  2509. Event.UNDISPLAY="undisplay";
  2510. Event.ERROR="error";
  2511. Event.COMPLETE="complete";
  2512. Event.LOADED="loaded";
  2513. Event.READY="ready";
  2514. Event.PROGRESS="progress";
  2515. Event.INPUT="input";
  2516. Event.RENDER="render";
  2517. Event.OPEN="open";
  2518. Event.MESSAGE="message";
  2519. Event.CLOSE="close";
  2520. Event.KEY_DOWN="keydown";
  2521. Event.KEY_PRESS="keypress";
  2522. Event.KEY_UP="keyup";
  2523. Event.FRAME="enterframe";
  2524. Event.DRAG_START="dragstart";
  2525. Event.DRAG_MOVE="dragmove";
  2526. Event.DRAG_END="dragend";
  2527. Event.ENTER="enter";
  2528. Event.SELECT="select";
  2529. Event.BLUR="blur";
  2530. Event.FOCUS="focus";
  2531. Event.VISIBILITY_CHANGE="visibilitychange";
  2532. Event.FOCUS_CHANGE="focuschange";
  2533. Event.PLAYED="played";
  2534. Event.PAUSED="paused";
  2535. Event.STOPPED="stopped";
  2536. Event.START="start";
  2537. Event.END="end";
  2538. Event.COMPONENT_ADDED="componentadded";
  2539. Event.COMPONENT_REMOVED="componentremoved";
  2540. Event.RELEASED="released";
  2541. Event.LINK="link";
  2542. Event.LABEL="label";
  2543. Event.FULL_SCREEN_CHANGE="fullscreenchange";
  2544. Event.DEVICE_LOST="devicelost";
  2545. Event.TRANSFORM_CHANGED="transformchanged";
  2546. Event.ANIMATION_CHANGED="animationchanged";
  2547. Event.TRAIL_FILTER_CHANGE="trailfilterchange";
  2548. Event.TRIGGER_ENTER="triggerenter";
  2549. Event.TRIGGER_STAY="triggerstay";
  2550. Event.TRIGGER_EXIT="triggerexit";
  2551. return Event;
  2552. })()
  2553. //class laya.webgl.text.TextRender
  2554. var TextRender=(function(){
  2555. function TextRender(){
  2556. /**
  2557. *fontSizeInfo
  2558. *记录每种字体的像素的大小。标准是32px的字体。由4个byte组成,分别表示[xdist,ydist,w,h]。
  2559. *xdist,ydist 是像素起点到排版原点的距离,都是正的,表示实际数据往左和上偏多少,如果实际往右和下偏,则算作0,毕竟这个只是一个大概
  2560. *例如 [Arial]=0x00002020,表示宽高都是32
  2561. */
  2562. this.fontSizeInfo={};
  2563. this.charRender=null;
  2564. this.mapFont={};
  2565. // 把font名称映射到数字
  2566. this.fontID=0;
  2567. this.mapColor=[];
  2568. // 把color映射到数字
  2569. this.colorID=0;
  2570. this.fontScaleX=1.0;
  2571. //临时缩放。
  2572. this.fontScaleY=1.0;
  2573. //private var charMaps:Object={};// 所有的都放到一起
  2574. this._curStrPos=0;
  2575. // 所有的独立贴图
  2576. this.bmpData32=null;
  2577. // 当前字体的测量信息。
  2578. this.lastFont=null;
  2579. this.fontSizeW=0;
  2580. this.fontSizeH=0;
  2581. this.fontSizeOffX=0;
  2582. this.fontSizeOffY=0;
  2583. this.renderPerChar=true;
  2584. this.textureMem=0;
  2585. // 当前贴图所占用的内存
  2586. this.fontStr=null;
  2587. this.textAtlases=[];
  2588. this.isoTextures=[];
  2589. this.tmpAtlasPos=new Point();
  2590. var bugIOS=false;
  2591. var miniadp=Laya['MiniAdpter'];
  2592. if (miniadp && miniadp.systemInfo && miniadp.systemInfo.system){
  2593. bugIOS=miniadp.systemInfo.system.toLowerCase()==='ios 10.1.1';
  2594. }
  2595. if (Browser.onMiniGame && !bugIOS)TextRender.isWan1Wan=true;
  2596. if (Browser.onLimixiu)TextRender.isWan1Wan=true;
  2597. this.charRender=Render.isConchApp ? (new CharRender_Native()):(new CharRender_Canvas(TextRender.atlasWidth,TextRender.atlasWidth,TextRender.scaleFontWithCtx,!TextRender.isWan1Wan,false));
  2598. TextRender.textRenderInst=this;
  2599. Laya['textRender']=this;
  2600. TextRender.atlasWidth2=TextRender.atlasWidth *TextRender.atlasWidth;
  2601. }
  2602. __class(TextRender,'laya.webgl.text.TextRender');
  2603. var __proto=TextRender.prototype;
  2604. /**
  2605. *设置当前字体,获得字体的大小信息。
  2606. *@param font
  2607. */
  2608. __proto.setFont=function(font){
  2609. if (this.lastFont==font)return;
  2610. this.lastFont=font;
  2611. var fontsz=this.getFontSizeInfo(font._family);
  2612. var offx=fontsz >> 24;
  2613. var offy=(fontsz >> 16)& 0xff;
  2614. var fw=(fontsz >> 8)& 0xff;
  2615. var fh=fontsz & 0xff;
  2616. var k=font._size / TextRender.standardFontSize;
  2617. this.fontSizeOffX=Math.ceil(offx *k);
  2618. this.fontSizeOffY=Math.ceil(offy *k);
  2619. this.fontSizeW=Math.ceil(fw *k);
  2620. this.fontSizeH=Math.ceil(fh *k);
  2621. if(font._font.indexOf('italic')>=0){
  2622. this.fontStr=font._font.replace('italic','');
  2623. }else {
  2624. this.fontStr=font._font;
  2625. }
  2626. }
  2627. /**
  2628. *从string中取出一个完整的char,例如emoji的话要多个
  2629. *会修改 _curStrPos
  2630. *TODO 由于各种文字中的组合写法,这个需要能扩展,以便支持泰文等
  2631. *@param str
  2632. *@param start 开始位置
  2633. */
  2634. __proto.getNextChar=function(str){
  2635. var len=str.length;
  2636. var start=this._curStrPos;
  2637. if (start >=len)
  2638. return null;
  2639. var link=false;
  2640. var i=start;
  2641. var state=0;
  2642. for (;i < len;i++){
  2643. var c=str.charCodeAt(i);
  2644. if ((c >>> 11)==0x1b){
  2645. if (state==1)break ;
  2646. state=1;
  2647. i++;
  2648. }
  2649. else if (c===0xfe0e || c===0xfe0f){}
  2650. else if (c==0x200d){
  2651. state=2;
  2652. }else {
  2653. if (state==0)state=1;
  2654. else if (state==1)break ;
  2655. else if (state==2){}
  2656. }
  2657. }
  2658. this._curStrPos=i;
  2659. return str.substring(start,i);
  2660. }
  2661. __proto.filltext=function(ctx,data,x,y,fontStr,color,strokeColor,lineWidth,textAlign,underLine){
  2662. (underLine===void 0)&& (underLine=0);
  2663. if (data.length <=0)
  2664. return;
  2665. var font=FontInfo.Parse(fontStr);
  2666. var nTextAlign=0;
  2667. switch (textAlign){
  2668. case 'center':
  2669. nTextAlign=Context.ENUM_TEXTALIGN_CENTER;
  2670. break ;
  2671. case 'right':
  2672. nTextAlign=Context.ENUM_TEXTALIGN_RIGHT;
  2673. break ;
  2674. }
  2675. this._fast_filltext(ctx,data,null,x,y,font,color,strokeColor,lineWidth,nTextAlign,underLine);
  2676. }
  2677. __proto.fillWords=function(ctx,data,x,y,fontStr,color,strokeColor,lineWidth){
  2678. if (!data)return;
  2679. if (data.length <=0)return;
  2680. var font=FontInfo.Parse(fontStr);
  2681. this._fast_filltext(ctx,null,data,x,y,font,color,strokeColor,lineWidth,0,0);
  2682. }
  2683. __proto._fast_filltext=function(ctx,data,htmlchars,x,y,font,color,strokeColor,lineWidth,textAlign,underLine){
  2684. (underLine===void 0)&& (underLine=0);
  2685. if (data && data.length < 1)return;
  2686. if (htmlchars && htmlchars.length < 1)return;
  2687. if (lineWidth < 0)lineWidth=0;
  2688. this.setFont(font);
  2689. this.fontScaleX=this.fontScaleY=1.0;
  2690. if (!Render.isConchApp && TextRender.scaleFontWithCtx){
  2691. var sx=1;
  2692. var sy=1;
  2693. if (Render.isConchApp){
  2694. sx=ctx._curMat.getScaleX();
  2695. sy=ctx._curMat.getScaleY();
  2696. }else{
  2697. sx=ctx.getMatScaleX();
  2698. sy=ctx.getMatScaleY();
  2699. }
  2700. if (sx < 1e-4 || sy < 1e-1)
  2701. return;
  2702. if (sx > 1)this.fontScaleX=sx;
  2703. if (sy > 1)this.fontScaleY=sy;
  2704. }
  2705. font._italic && (ctx._italicDeg=13);
  2706. var wt=data;
  2707. var isWT=!htmlchars && ((data instanceof laya.utils.WordText ));
  2708. var str=data;
  2709. var isHtmlChar=!!htmlchars;
  2710. var sameTexData=isWT ? wt.pageChars :[];
  2711. var strWidth=0;
  2712. if (isWT){
  2713. str=wt._text;
  2714. strWidth=wt.width;
  2715. if (strWidth < 0){
  2716. strWidth=wt.width=this.charRender.getWidth(this.fontStr,str);
  2717. }
  2718. }else {
  2719. strWidth=str?this.charRender.getWidth(this.fontStr,str):0;
  2720. }
  2721. switch (textAlign){
  2722. case Context.ENUM_TEXTALIGN_CENTER:
  2723. x-=strWidth / 2;
  2724. break ;
  2725. case Context.ENUM_TEXTALIGN_RIGHT:
  2726. x-=strWidth;
  2727. break ;
  2728. }
  2729. if (wt && sameTexData){
  2730. if (this.hasFreedText(sameTexData)){
  2731. sameTexData=wt.pageChars=[];
  2732. }
  2733. };
  2734. var ri=null;
  2735. var oneTex=isWT || TextRender.forceWholeRender;
  2736. var splitTex=this.renderPerChar=(!isWT)|| TextRender.forceSplitRender || isHtmlChar || (isWT && wt.splitRender);
  2737. if (!sameTexData || sameTexData.length < 1){
  2738. if (splitTex){
  2739. var stx=0;
  2740. var sty=0;
  2741. this._curStrPos=0;
  2742. var curstr;
  2743. while(true){
  2744. if (isHtmlChar){
  2745. var chc=htmlchars[this._curStrPos++];
  2746. if(chc){
  2747. curstr=chc.char;
  2748. stx=chc.x;
  2749. sty=chc.y;
  2750. }else {
  2751. curstr=null;
  2752. }
  2753. }else {
  2754. curstr=this.getNextChar(str);
  2755. }
  2756. if (!curstr)
  2757. break ;
  2758. ri=this.getCharRenderInfo(curstr,font,color,strokeColor,lineWidth,false);
  2759. if (!ri){
  2760. break ;
  2761. }
  2762. if (ri.isSpace){
  2763. }else {
  2764. var add=sameTexData[ri.tex.id];
  2765. if (!add){
  2766. var o1={texgen:(ri.tex).genID,tex:ri.tex,words:[] };
  2767. sameTexData[ri.tex.id]=o1;
  2768. add=o1.words;
  2769. }else {
  2770. add=add.words;
  2771. }
  2772. if (Render.isConchApp){
  2773. add.push({ri:ri,x:stx,y:sty,w:ri.bmpWidth / this.fontScaleX,h:ri.bmpHeight / this.fontScaleY });
  2774. }else{
  2775. add.push({ri:ri,x:stx+1/this.fontScaleX,y:sty,w:(ri.bmpWidth-2)/ this.fontScaleX,h:(ri.bmpHeight-1)/ this.fontScaleY });
  2776. }
  2777. stx+=ri.width;
  2778. }
  2779. }
  2780. }else {
  2781. var isotex=TextRender.noAtlas || strWidth*this.fontScaleX > TextRender.atlasWidth;
  2782. ri=this.getCharRenderInfo(str,font,color,strokeColor,lineWidth,isotex);
  2783. if (Render.isConchApp){
  2784. 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 }]};
  2785. }else{
  2786. 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 }]};
  2787. }
  2788. }
  2789. }
  2790. this._drawResortedWords(ctx,x,y,sameTexData);
  2791. ctx._italicDeg=0;
  2792. }
  2793. /**
  2794. *画出重新按照贴图顺序分组的文字。
  2795. *@param samePagesData
  2796. *@param startx 保存的数据是相对位置,所以需要加上这个偏移。用相对位置更灵活一些。
  2797. *@param y {int}因为这个只能画在一行上所以没有必要保存y。所以这里再把y传进来
  2798. */
  2799. __proto._drawResortedWords=function(ctx,startx,starty,samePagesData){
  2800. var isLastRender=ctx._charSubmitCache && ctx._charSubmitCache._enbale;
  2801. var mat=ctx._curMat;
  2802. var slen=samePagesData.length;
  2803. for (var id=0;id < slen;id++){
  2804. var dt=samePagesData[id];
  2805. if (!dt)continue ;
  2806. var pri=dt.words;
  2807. var pisz=pri.length;if (pisz <=0)continue ;
  2808. var tex=(samePagesData[id] .tex);
  2809. for (var j=0;j < pisz;j++){
  2810. var riSaved=pri[j];
  2811. var ri=riSaved.ri;
  2812. if (ri.isSpace)continue ;
  2813. ri.touch();
  2814. ctx.drawTexAlign=true;
  2815. if (Render.isConchApp){
  2816. ctx._drawTextureM(tex.texture,startx+riSaved.x-ri.orix ,starty+riSaved.y-ri.oriy,riSaved.w,riSaved.h,null,1.0,ri.uv);
  2817. }else
  2818. ctx._inner_drawTexture(tex.texture,(tex.texture).bitmap.id,
  2819. startx+riSaved.x-ri.orix ,starty+riSaved.y-ri.oriy,riSaved.w,riSaved.h,
  2820. mat,ri.uv,1.0,isLastRender);
  2821. if ((ctx).touches){
  2822. (ctx).touches.push(ri);
  2823. }
  2824. }
  2825. }
  2826. }
  2827. /**
  2828. *检查 txts数组中有没有被释放的资源
  2829. *@param txts {{ri:CharRenderInfo,...}[][]}
  2830. *@param startid
  2831. *@return
  2832. */
  2833. __proto.hasFreedText=function(txts){
  2834. var sz=txts.length;
  2835. for (var i=0;i < sz;i++){
  2836. var pri=txts[i];
  2837. if (!pri)continue ;
  2838. var tex=(pri.tex);
  2839. if (tex.__destroyed || tex.genID !=pri.texgen){
  2840. return true;
  2841. }
  2842. }
  2843. return false;
  2844. }
  2845. __proto.getCharRenderInfo=function(str,font,color,strokeColor,lineWidth,isoTexture){
  2846. (isoTexture===void 0)&& (isoTexture=false);
  2847. var fid=this.mapFont[font._family];
  2848. if (fid==undefined){
  2849. this.mapFont[font._family]=fid=this.fontID++;
  2850. };
  2851. var key=str+'_'+fid+'_'+font._size+'_'+color;
  2852. if (lineWidth > 0)
  2853. key+='_'+strokeColor+lineWidth;
  2854. if (font._bold)
  2855. key+='P';
  2856. if (this.fontScaleX !=1 || this.fontScaleY !=1){
  2857. key+=(this.fontScaleX*20|0)+'_'+(this.fontScaleY*20|0);
  2858. };
  2859. var i=0;
  2860. var sz=this.textAtlases.length;
  2861. var ri=null;
  2862. var atlas=null;
  2863. if(!isoTexture){
  2864. for (i=0;i < sz;i++){
  2865. atlas=this.textAtlases[i];
  2866. ri=atlas.charMaps[key]
  2867. if (ri){
  2868. ri.touch();
  2869. return ri;
  2870. }
  2871. }
  2872. }
  2873. ri=new CharRenderInfo();
  2874. this.charRender.scale(this.fontScaleX,this.fontScaleY);
  2875. ri.char=str;
  2876. ri.height=font._size;
  2877. var margin=font._size / 3 |0;
  2878. var imgdt=null;
  2879. var w1=Math.ceil(this.charRender.getWidth(this.fontStr,str)*this.fontScaleX);
  2880. if (w1 > this.charRender.canvasWidth){
  2881. this.charRender.canvasWidth=Math.min(2048,w1+margin *2);
  2882. }
  2883. if (isoTexture){
  2884. imgdt=this.charRender.getCharBmp(str,this.fontStr,lineWidth,color,strokeColor,ri,margin,margin,margin,margin,null);
  2885. var tex=TextTexture.getTextTexture(imgdt.width,imgdt.height);
  2886. tex.addChar(imgdt,0,0,ri.uv);
  2887. ri.tex=tex;
  2888. ri.orix=margin;
  2889. ri.oriy=margin;
  2890. tex.ri=ri;
  2891. this.isoTextures.push(tex);
  2892. }else {
  2893. var len=str.length;
  2894. if (len > 1){
  2895. };
  2896. var lineExt=lineWidth*1;
  2897. var fw=Math.ceil((this.fontSizeW+lineExt*2)*this.fontScaleX);
  2898. var fh=Math.ceil((this.fontSizeH+lineExt*2)*this.fontScaleY);
  2899. TextRender.imgdtRect[0]=((margin-this.fontSizeOffX-lineExt)*this.fontScaleX)|0;
  2900. TextRender.imgdtRect[1]=((margin-this.fontSizeOffY-lineExt)*this.fontScaleY)|0;
  2901. if (this.renderPerChar||len==1){
  2902. TextRender.imgdtRect[2]=Math.max(w1,fw);
  2903. TextRender.imgdtRect[3]=Math.max(w1,fh);
  2904. }else {
  2905. TextRender.imgdtRect[2]=-1;
  2906. TextRender.imgdtRect[3]=fh;
  2907. }
  2908. imgdt=this.charRender.getCharBmp(str,this.fontStr,lineWidth,color,strokeColor,ri,
  2909. margin,margin,margin,margin,TextRender.imgdtRect);
  2910. atlas=this.addBmpData(imgdt,ri);
  2911. if (TextRender.isWan1Wan){
  2912. ri.orix=margin;
  2913. ri.oriy=margin;
  2914. }else {
  2915. ri.orix=(this.fontSizeOffX+lineExt);
  2916. ri.oriy=(this.fontSizeOffY+lineExt);
  2917. }
  2918. atlas.charMaps[key]=ri;
  2919. }
  2920. return ri;
  2921. }
  2922. /**
  2923. *添加数据到大图集
  2924. *@param w
  2925. *@param h
  2926. *@return
  2927. */
  2928. __proto.addBmpData=function(data,ri){
  2929. var w=data.width;
  2930. var h=data.height;
  2931. var sz=this.textAtlases.length;
  2932. var atlas=null;
  2933. var find=false;
  2934. for (var i=0;i < sz;i++){
  2935. atlas=this.textAtlases[i];
  2936. find=atlas.getAEmpty(w,h,this.tmpAtlasPos);
  2937. if (find){
  2938. break ;
  2939. }
  2940. }
  2941. if (!find){
  2942. atlas=new TextAtlas()
  2943. this.textAtlases.push(atlas);
  2944. find=atlas.getAEmpty(w,h,this.tmpAtlasPos);
  2945. if (!find){
  2946. throw 'err1';
  2947. }
  2948. this.cleanAtlases();
  2949. }
  2950. if(find){
  2951. atlas.texture.addChar(data,this.tmpAtlasPos.x,this.tmpAtlasPos.y,ri.uv);
  2952. ri.tex=/*__JS__ */atlas.texture;
  2953. }
  2954. return atlas;
  2955. }
  2956. /**
  2957. *清理利用率低的大图集
  2958. */
  2959. __proto.GC=function(){
  2960. var i=0;
  2961. var sz=this.textAtlases.length;
  2962. var dt=0;
  2963. var destroyDt=TextRender.destroyAtlasDt;
  2964. var totalUsedRate=0;
  2965. var totalUsedRateAtlas=0;
  2966. var curloop=Stat.loopCount;
  2967. var maxWasteRateID=-1;
  2968. var maxWasteRate=0;
  2969. var tex=null;
  2970. var curatlas=null;
  2971. for (;i < sz;i++){
  2972. curatlas=this.textAtlases[i];
  2973. tex=curatlas.texture;
  2974. if (tex){
  2975. totalUsedRate+=tex.curUsedCovRate;
  2976. totalUsedRateAtlas+=tex.curUsedCovRateAtlas;
  2977. var waste=curatlas.usedRate-tex.curUsedCovRateAtlas;
  2978. if (maxWasteRate < waste){
  2979. maxWasteRate=waste;
  2980. maxWasteRateID=i;
  2981. }
  2982. }
  2983. dt=curloop-curatlas.texture.lastTouchTm;
  2984. if (dt > destroyDt){
  2985. TextRender.showLog && console.log('TextRender GC delete atlas '+tex?curatlas.texture.id:'unk');
  2986. curatlas.destroy();
  2987. this.textAtlases[i]=this.textAtlases[sz-1];
  2988. sz--;
  2989. i--;
  2990. maxWasteRateID=-1;
  2991. }
  2992. }
  2993. this.textAtlases.length=sz;
  2994. sz=this.isoTextures.length;
  2995. for (i=0;i < sz;i++){
  2996. tex=this.isoTextures[i];
  2997. dt=curloop-tex.lastTouchTm;
  2998. if (dt > TextRender.destroyUnusedTextureDt){
  2999. tex.ri.deleted=true;
  3000. tex.ri.tex=null;
  3001. tex.destroy();
  3002. this.isoTextures[i]=this.isoTextures[sz-1];
  3003. sz--;
  3004. i--;
  3005. }
  3006. }
  3007. this.isoTextures.length=sz;
  3008. var needGC=this.textAtlases.length > 1 && this.textAtlases.length-totalUsedRateAtlas >=2;
  3009. if (TextRender.atlasWidth *TextRender.atlasWidth *4 *this.textAtlases.length > TextRender.cleanMem || needGC || TextRender.simClean){
  3010. TextRender.simClean=false;
  3011. TextRender.showLog && console.log('清理使用率低的贴图。总使用率:',totalUsedRateAtlas,':',this.textAtlases.length,'最差贴图:'+maxWasteRateID);
  3012. if(maxWasteRateID>=0){
  3013. curatlas=this.textAtlases[maxWasteRateID];
  3014. curatlas.destroy();
  3015. this.textAtlases[maxWasteRateID]=this.textAtlases[this.textAtlases.length-1];
  3016. this.textAtlases.length=this.textAtlases.length-1;
  3017. }
  3018. }
  3019. TextTexture.clean();
  3020. }
  3021. /**
  3022. *尝试清理大图集
  3023. */
  3024. __proto.cleanAtlases=function(){}
  3025. // TODO 根据覆盖率决定是否清理
  3026. __proto.getCharBmp=function(c){}
  3027. /**
  3028. *检查当前线是否存在数据
  3029. *@param data
  3030. *@param l
  3031. *@param sx
  3032. *@param ex
  3033. *@return
  3034. */
  3035. __proto.checkBmpLine=function(data,l,sx,ex){
  3036. if (this.bmpData32.buffer !=data.data.buffer){
  3037. this.bmpData32=new Uint32Array(data.data.buffer);
  3038. };
  3039. var stpos=data.width *l+sx;
  3040. for (var x=sx;x < ex;x++){
  3041. if (this.bmpData32[stpos++] !=0)return true;
  3042. }
  3043. return false;
  3044. }
  3045. /**
  3046. *根据bmp数据和当前的包围盒,更新包围盒
  3047. *由于选择的文字是连续的,所以可以用二分法
  3048. *@param data
  3049. *@param curbbx [l,t,r,b]
  3050. *@param onlyH 不检查左右
  3051. */
  3052. __proto.updateBbx=function(data,curbbx,onlyH){
  3053. (onlyH===void 0)&& (onlyH=false);
  3054. var w=data.width;
  3055. var h=data.height;
  3056. var x=0;
  3057. var sy=curbbx[1];
  3058. var ey=0;
  3059. var y=sy;
  3060. if (this.checkBmpLine(data,sy,0,w)){
  3061. while (true){
  3062. y=(sy+ey)/ 2 | 0;
  3063. if (y+1 >=sy){
  3064. curbbx[1]=y;
  3065. break ;
  3066. }
  3067. if(this.checkBmpLine(data,y,0,w)){
  3068. sy=y;
  3069. }else {
  3070. ey=y;
  3071. }
  3072. }
  3073. }
  3074. if (curbbx[3] > h)curbbx[3]=h;
  3075. else{
  3076. y=sy=curbbx[3];
  3077. ey=h;
  3078. if (this.checkBmpLine(data,sy,0,w)){
  3079. while(true){
  3080. y=(sy+ey)/ 2 | 0;
  3081. if (y-1 <=sy){
  3082. curbbx[3]=y;
  3083. break ;
  3084. }
  3085. if (this.checkBmpLine(data,y,0,w)){
  3086. sy=y;
  3087. }else {
  3088. ey=y;
  3089. }
  3090. }
  3091. }
  3092. }
  3093. if (onlyH)
  3094. return;
  3095. var minx=curbbx[0];
  3096. var stpos=w*curbbx[1];
  3097. for (y=curbbx[1];y < curbbx[3];y++){
  3098. for (x=0;x < minx;x++){
  3099. if (this.bmpData32[stpos+x] !=0){
  3100. minx=x;
  3101. break ;
  3102. }
  3103. }
  3104. stpos+=w;
  3105. }
  3106. curbbx[0]=minx;
  3107. var maxx=curbbx[2];
  3108. stpos=w*curbbx[1];
  3109. for (y=curbbx[1];y < curbbx[3];y++){
  3110. for (x=maxx;x < w;x++){
  3111. if (this.bmpData32[stpos+x] !=0){
  3112. maxx=x;
  3113. break ;
  3114. }
  3115. }
  3116. stpos+=w;
  3117. }
  3118. curbbx[2]=maxx;
  3119. }
  3120. __proto.getFontSizeInfo=function(font){
  3121. var finfo=this.fontSizeInfo[font];
  3122. if (finfo !=undefined)
  3123. return finfo;
  3124. var fontstr='bold '+TextRender.standardFontSize+'px '+font;
  3125. if (TextRender.isWan1Wan){
  3126. this.fontSizeW=this.charRender.getWidth(fontstr,'有')*1.5;
  3127. this.fontSizeH=TextRender.standardFontSize *1.5;
  3128. var szinfo=this.fontSizeW << 8 | this.fontSizeH;
  3129. this.fontSizeInfo[font]=szinfo;
  3130. return szinfo;
  3131. }
  3132. TextRender.pixelBBX[0]=TextRender.standardFontSize / 2;
  3133. TextRender.pixelBBX[1]=TextRender.standardFontSize / 2;
  3134. TextRender.pixelBBX[2]=TextRender.standardFontSize;
  3135. TextRender.pixelBBX[3]=TextRender.standardFontSize;
  3136. var orix=16;
  3137. var oriy=16;
  3138. var marginr=16;
  3139. var marginb=16;
  3140. this.charRender.scale(1,1);
  3141. TextRender.tmpRI.height=TextRender.standardFontSize;
  3142. var bmpdt=this.charRender.getCharBmp('g',fontstr,0,'red',null,TextRender.tmpRI,orix,oriy,marginr,marginb);
  3143. if (Render.isConchApp){
  3144. bmpdt.data=new /*__JS__ */Uint8ClampedArray(bmpdt.data);
  3145. }
  3146. this.bmpData32=new Uint32Array(bmpdt.data.buffer);
  3147. this.updateBbx(bmpdt,TextRender.pixelBBX,false);
  3148. bmpdt=this.charRender.getCharBmp('有',fontstr,0,'red',null,TextRender.tmpRI,oriy,oriy,marginr,marginb);
  3149. if (Render.isConchApp){
  3150. bmpdt.data=new /*__JS__ */Uint8ClampedArray(bmpdt.data);
  3151. }
  3152. this.bmpData32=new Uint32Array(bmpdt.data.buffer);
  3153. if (TextRender.pixelBBX[2] < orix+TextRender.tmpRI.width)
  3154. TextRender.pixelBBX[2]=orix+TextRender.tmpRI.width;
  3155. this.updateBbx(bmpdt,TextRender.pixelBBX,false);
  3156. if (Render.isConchApp){
  3157. orix=0;
  3158. oriy=0;
  3159. };
  3160. var xoff=Math.max(orix-TextRender.pixelBBX[0],0);
  3161. var yoff=Math.max(oriy-TextRender.pixelBBX[1],0);
  3162. var bbxw=TextRender.pixelBBX[2]-TextRender.pixelBBX[0];
  3163. var bbxh=TextRender.pixelBBX[3]-TextRender.pixelBBX[1]+1;
  3164. var sizeinfo=xoff<<24 |yoff<<16 | bbxw << 8 | bbxh;
  3165. this.fontSizeInfo[font]=sizeinfo;
  3166. return sizeinfo;
  3167. }
  3168. __proto.printDbgInfo=function(){
  3169. console.log('图集个数:'+this.textAtlases.length+',每个图集大小:'+TextRender.atlasWidth+'x'+TextRender.atlasWidth,' 用canvas:',TextRender.isWan1Wan);
  3170. console.log('图集占用空间:'+(TextRender.atlasWidth *TextRender.atlasWidth *4 / 1024 / 1024 *this.textAtlases.length)+'M');
  3171. console.log('缓存用到的字体:');
  3172. for (var f in this.mapFont){
  3173. var fontsz=this.getFontSizeInfo(f);
  3174. var offx=fontsz >> 24;
  3175. var offy=(fontsz >> 16)& 0xff;
  3176. var fw=(fontsz >> 8)& 0xff;
  3177. var fh=fontsz & 0xff;
  3178. console.log(' '+f,' off:',offx,offy,' size:',fw,fh);
  3179. };
  3180. var num=0;
  3181. console.log('缓存数据:');
  3182. var totalUsedRate=0;
  3183. var totalUsedRateAtlas=0;
  3184. this.textAtlases.forEach(function(a){
  3185. var id=a.texture.id;
  3186. var dt=Stat.loopCount-a.texture.lastTouchTm;
  3187. var dtstr=dt > 0?(''+dt+'帧以前'):'当前帧';
  3188. totalUsedRate+=a.texture.curUsedCovRate;
  3189. totalUsedRateAtlas+=a.texture.curUsedCovRateAtlas;
  3190. console.log('--图集(id:'+id+',当前使用率:'+(a.texture.curUsedCovRate*1000|0)+'‰','当前图集使用率:',(a.texture.curUsedCovRateAtlas*100|0)+'%','图集使用率:',(a.usedRate*100|0),'%, 使用于:'+dtstr+')--:');
  3191. for (var k in a.charMaps){
  3192. var ri=a.charMaps[k];
  3193. 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,
  3194. '字符:',ri.char,'key:',k);
  3195. num++;
  3196. }
  3197. });
  3198. console.log('独立贴图文字('+this.isoTextures.length+'个):');
  3199. this.isoTextures.forEach(function(tex){
  3200. console.log(' size:',tex._texW,tex._texH,'touch间隔:',(Stat.loopCount-tex.lastTouchTm),'char:',tex.ri.char);
  3201. });
  3202. console.log('总缓存:',num,'总使用率:',totalUsedRate,'总当前图集使用率:',totalUsedRateAtlas);
  3203. }
  3204. // 在屏幕上显示某个大图集
  3205. __proto.showAtlas=function(n,bgcolor,x,y,w,h){
  3206. if (!this.textAtlases[n]){
  3207. console.log('没有这个图集');
  3208. return null;
  3209. };
  3210. var sp=new Sprite();
  3211. var texttex=this.textAtlases[n].texture;
  3212. var texture={
  3213. width:TextRender.atlasWidth,
  3214. height:TextRender.atlasWidth,
  3215. sourceWidth:TextRender.atlasWidth,
  3216. sourceHeight:TextRender.atlasWidth,
  3217. offsetX:0,
  3218. offsetY:0,
  3219. getIsReady:function (){return true;},
  3220. _addReference:function (){},
  3221. _removeReference:function (){},
  3222. _getSource:function (){return texttex._getSource();},
  3223. bitmap:{id:texttex.id },
  3224. _uv:Texture.DEF_UV
  3225. };
  3226. (sp).size=function (w,h){
  3227. this.width=w;
  3228. this.height=h;
  3229. sp.graphics.clear();
  3230. sp.graphics.drawRect(0,0,sp.width,sp.height,bgcolor);
  3231. sp.graphics.drawTexture(texture,0,0,sp.width,sp.height);
  3232. return this;
  3233. }
  3234. sp.graphics.drawRect(0,0,w,h,bgcolor);
  3235. sp.graphics.drawTexture(texture,0,0,w,h);
  3236. sp.pos(x,y);
  3237. Laya.stage.addChild(sp);
  3238. return sp;
  3239. }
  3240. /////// native ///////
  3241. __proto.filltext_native=function(ctx,data,htmlchars,x,y,fontStr,color,strokeColor,lineWidth,textAlign,underLine){
  3242. (underLine===void 0)&& (underLine=0);
  3243. if (data && data.length <=0)return;
  3244. if (htmlchars && htmlchars.length < 1)return;
  3245. var font=FontInfo.Parse(fontStr);
  3246. var nTextAlign=0;
  3247. switch (textAlign){
  3248. case 'center':
  3249. nTextAlign=Context.ENUM_TEXTALIGN_CENTER;
  3250. break ;
  3251. case 'right':
  3252. nTextAlign=Context.ENUM_TEXTALIGN_RIGHT;
  3253. break ;
  3254. }
  3255. return this._fast_filltext(ctx,data,htmlchars,x,y,font,color,strokeColor,lineWidth,nTextAlign,underLine);
  3256. }
  3257. TextRender.useOldCharBook=false;
  3258. TextRender.atlasWidth=2048;
  3259. TextRender.noAtlas=false;
  3260. TextRender.forceSplitRender=false;
  3261. TextRender.forceWholeRender=false;
  3262. TextRender.scaleFontWithCtx=true;
  3263. TextRender.standardFontSize=32;
  3264. TextRender.destroyAtlasDt=10;
  3265. TextRender.checkCleanTextureDt=2000;
  3266. TextRender.destroyUnusedTextureDt=3000;
  3267. TextRender.cleanMem=100 *1024 *1024;
  3268. TextRender.isWan1Wan=false;
  3269. TextRender.showLog=false;
  3270. TextRender.debugUV=false;
  3271. TextRender.atlasWidth2=2048 *2048;
  3272. TextRender.textRenderInst=null;
  3273. TextRender.simClean=false;
  3274. __static(TextRender,
  3275. ['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];}
  3276. ]);
  3277. return TextRender;
  3278. })()
  3279. /**
  3280. *<p> <code>Stat</code> 是一个性能统计面板,可以实时更新相关的性能参数。</p>
  3281. *<p>参与统计的性能参数如下(所有参数都是每大约1秒进行更新):<br/>
  3282. *FPS(Canvas)/FPS(WebGL):Canvas 模式或者 WebGL 模式下的帧频,也就是每秒显示的帧数,值越高、越稳定,感觉越流畅;<br/>
  3283. *Sprite:统计所有渲染节点(包括容器)数量,它的大小会影响引擎进行节点遍历、数据组织和渲染的效率。其值越小,游戏运行效率越高;<br/>
  3284. *DrawCall:此值是决定性能的重要指标,其值越小,游戏运行效率越高。Canvas模式下表示每大约1秒的图像绘制次数;WebGL模式下表示每大约1秒的渲染提交批次,每次准备数据并通知GPU渲染绘制的过程称为1次DrawCall,在每次DrawCall中除了在通知GPU的渲染上比较耗时之外,切换材质与shader也是非常耗时的操作;<br/>
  3285. *CurMem:Canvas模式下,表示内存占用大小,值越小越好,过高会导致游戏闪退;WebGL模式下,表示内存与显存的占用,值越小越好;<br/>
  3286. *Shader:是 WebGL 模式独有的性能指标,表示每大约1秒 Shader 提交次数,值越小越好;<br/>
  3287. *Canvas:由三个数值组成,只有设置 CacheAs 后才会有值,默认为0/0/0。从左到右数值的意义分别为:每帧重绘的画布数量 / 缓存类型为"normal"类型的画布数量 / 缓存类型为"bitmap"类型的画布数量。</p>
  3288. */
  3289. //class laya.utils.Stat
  3290. var Stat=(function(){
  3291. function Stat(){}
  3292. __class(Stat,'laya.utils.Stat');
  3293. /**
  3294. *点击性能统计显示区域的处理函数。
  3295. */
  3296. __getset(1,Stat,'onclick',null,function(fn){
  3297. if (Stat._sp){
  3298. Stat._sp.on("click",Stat._sp,fn);
  3299. }
  3300. if (Stat._canvas){
  3301. Stat._canvas.source.onclick=fn;
  3302. Stat._canvas.source.style.pointerEvents='';
  3303. }
  3304. });
  3305. Stat.show=function(x,y){
  3306. (x===void 0)&& (x=0);
  3307. (y===void 0)&& (y=0);
  3308. if (!Browser.onMiniGame && !Browser.onLimixiu && !Render.isConchApp && !Browser.onBDMiniGame && !Browser.onKGMiniGame && !Browser.onQGMiniGame)Stat._useCanvas=true;
  3309. Stat._show=true;
  3310. Stat._fpsData.length=60;
  3311. Stat._view[0]={title:"FPS(Canvas)",value:"_fpsStr",color:"yellow",units:"int"};
  3312. Stat._view[1]={title:"Sprite",value:"_spriteStr",color:"white",units:"int"};
  3313. Stat._view[2]={title:"RenderBatches",value:"renderBatches",color:"white",units:"int"};
  3314. Stat._view[3]={title:"SavedRenderBatches",value:"savedRenderBatches",color:"white",units:"int"};
  3315. Stat._view[4]={title:"CPUMemory",value:"cpuMemory",color:"yellow",units:"M"};
  3316. Stat._view[5]={title:"GPUMemory",value:"gpuMemory",color:"yellow",units:"M"};
  3317. Stat._view[6]={title:"Shader",value:"shaderCall",color:"white",units:"int"};
  3318. if (!Render.is3DMode){
  3319. Stat._view[0].title="FPS(WebGL)";
  3320. Stat._view[7]={title:"Canvas",value:"_canvasStr",color:"white",units:"int"};
  3321. }else {
  3322. Stat._view[0].title="FPS(3D)";
  3323. Stat._view[7]={title:"TriFaces",value:"trianglesFaces",color:"white",units:"int"};
  3324. Stat._view[8]={title:"FrustumCulling",value:"frustumCulling",color:"white",units:"int"};
  3325. Stat._view[9]={title:"OctreeNodeCulling",value:"octreeNodeCulling",color:"white",units:"int"};
  3326. }
  3327. if (Stat._useCanvas){
  3328. Stat.createUIPre(x,y);
  3329. }else
  3330. Stat.createUI(x,y);
  3331. Stat.enable();
  3332. }
  3333. Stat.createUIPre=function(x,y){
  3334. var pixel=Browser.pixelRatio;
  3335. Stat._width=pixel *180;
  3336. Stat._vx=pixel *120;
  3337. Stat._height=pixel *(Stat._view.length *12+3 *pixel)+4;
  3338. Stat._fontSize=12 *pixel;
  3339. for (var i=0;i < Stat._view.length;i++){
  3340. Stat._view[i].x=4;
  3341. Stat._view[i].y=i *Stat._fontSize+2 *pixel;
  3342. }
  3343. if (!Stat._canvas){
  3344. Stat._canvas=new HTMLCanvas(true);
  3345. Stat._canvas.size(Stat._width,Stat._height);
  3346. Stat._ctx=Stat._canvas.getContext('2d');
  3347. Stat._ctx.textBaseline="top";
  3348. Stat._ctx.font=Stat._fontSize+"px Arial";
  3349. 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;";
  3350. }
  3351. if(!Browser.onKGMiniGame){
  3352. Browser.container.appendChild(Stat._canvas.source);
  3353. }
  3354. Stat._first=true;
  3355. Stat.loop();
  3356. Stat._first=false;
  3357. }
  3358. Stat.createUI=function(x,y){
  3359. var stat=Stat._sp;
  3360. var pixel=Browser.pixelRatio;
  3361. if (!stat){
  3362. stat=new Sprite();
  3363. Stat._leftText=new Text();
  3364. Stat._leftText.pos(5,5);
  3365. Stat._leftText.color="#ffffff";
  3366. stat.addChild(Stat._leftText);
  3367. Stat._txt=new Text();
  3368. Stat._txt.pos(80 *pixel,5);
  3369. Stat._txt.color="#ffffff";
  3370. stat.addChild(Stat._txt);
  3371. Stat._sp=stat;
  3372. }
  3373. stat.pos(x,y);
  3374. var text="";
  3375. for (var i=0;i < Stat._view.length;i++){
  3376. var one=Stat._view[i];
  3377. text+=one.title+"\n";
  3378. }
  3379. Stat._leftText.text=text;
  3380. var width=pixel *138;
  3381. var height=pixel *(Stat._view.length *12+3 *pixel)+4;
  3382. Stat._txt.fontSize=Stat._fontSize *pixel;
  3383. Stat._leftText.fontSize=Stat._fontSize *pixel;
  3384. stat.size(width,height);
  3385. stat.graphics.clear();
  3386. stat.graphics.alpha(0.5);
  3387. stat.graphics.drawRect(0,0,width,height,"#999999");
  3388. stat.graphics.alpha(2);
  3389. Stat.loop();
  3390. }
  3391. Stat.enable=function(){
  3392. Laya.systemTimer.frameLoop(1,Stat,Stat.loop);
  3393. }
  3394. Stat.hide=function(){
  3395. Stat._show=false;
  3396. Laya.systemTimer.clear(Stat,Stat.loop);
  3397. if (Stat._canvas){
  3398. Browser.removeElement(Stat._canvas.source);
  3399. }
  3400. }
  3401. Stat.clear=function(){
  3402. Stat.trianglesFaces=Stat.renderBatches=Stat.savedRenderBatches=Stat.shaderCall=Stat.spriteRenderUseCacheCount=Stat.frustumCulling=Stat.octreeNodeCulling=Stat.canvasNormal=Stat.canvasBitmap=Stat.canvasReCache=0;
  3403. }
  3404. Stat.loop=function(){
  3405. Stat._count++;
  3406. var timer=Browser.now();
  3407. if (timer-Stat._timer < 1000)return;
  3408. var count=Stat._count;
  3409. Stat.FPS=Math.round((count *1000)/ (timer-Stat._timer));
  3410. if (Stat._show){
  3411. Stat.trianglesFaces=Math.round(Stat.trianglesFaces / count);
  3412. if (!Stat._useCanvas){
  3413. Stat.renderBatches=Math.round(Stat.renderBatches / count)-1;
  3414. }else {
  3415. Stat.renderBatches=Math.round(Stat.renderBatches / count);
  3416. }
  3417. Stat.savedRenderBatches=Math.round(Stat.savedRenderBatches / count);
  3418. Stat.shaderCall=Math.round(Stat.shaderCall / count);
  3419. Stat.spriteRenderUseCacheCount=Math.round(Stat.spriteRenderUseCacheCount / count);
  3420. Stat.canvasNormal=Math.round(Stat.canvasNormal / count);
  3421. Stat.canvasBitmap=Math.round(Stat.canvasBitmap / count);
  3422. Stat.canvasReCache=Math.ceil(Stat.canvasReCache / count);
  3423. Stat.frustumCulling=Math.round(Stat.frustumCulling / count);
  3424. Stat.octreeNodeCulling=Math.round(Stat.octreeNodeCulling / count);
  3425. var delay=Stat.FPS > 0 ? Math.floor(1000 / Stat.FPS).toString():" ";
  3426. Stat._fpsStr=Stat.FPS+(Stat.renderSlow ? " slow" :"")+" "+delay;
  3427. if (Stat._useCanvas)
  3428. Stat._spriteStr=(Stat.spriteCount-1)+(Stat.spriteRenderUseCacheCount ? ("/"+Stat.spriteRenderUseCacheCount):'');
  3429. else
  3430. Stat._spriteStr=(Stat.spriteCount-4)+(Stat.spriteRenderUseCacheCount ? ("/"+Stat.spriteRenderUseCacheCount):'');
  3431. Stat._canvasStr=Stat.canvasReCache+"/"+Stat.canvasNormal+"/"+Stat.canvasBitmap;
  3432. Stat.cpuMemory=Resource.cpuMemory;
  3433. Stat.gpuMemory=Resource.gpuMemory;
  3434. if (Stat._useCanvas){
  3435. Stat.renderInfoPre();
  3436. }else
  3437. Stat.renderInfo();
  3438. Stat.clear();
  3439. }
  3440. Stat._count=0;
  3441. Stat._timer=timer;
  3442. }
  3443. Stat.renderInfoPre=function(){
  3444. var i=0;
  3445. var one;
  3446. var value;
  3447. if (Stat._canvas){
  3448. var ctx=Stat._ctx;
  3449. ctx.clearRect(Stat._first ? 0 :Stat._vx,0,Stat._width,Stat._height);
  3450. for (i=0;i < Stat._view.length;i++){
  3451. one=Stat._view[i];
  3452. if (Stat._first){
  3453. ctx.fillStyle="white";
  3454. ctx.fillText(one.title,one.x,one.y);
  3455. }
  3456. ctx.fillStyle=one.color;
  3457. value=Stat[one.value];
  3458. (one.units=="M")&& (value=Math.floor(value / (1024 *1024)*100)/ 100+" M");
  3459. ctx.fillText(value+"",one.x+Stat._vx,one.y);
  3460. }
  3461. }
  3462. }
  3463. Stat.renderInfo=function(){
  3464. var text="";
  3465. for (var i=0;i < Stat._view.length;i++){
  3466. var one=Stat._view[i];
  3467. var value=Stat[one.value];
  3468. (one.units=="M")&& (value=Math.floor(value / (1024 *1024)*100)/ 100+" M");
  3469. (one.units=="K")&& (value=Math.floor(value / (1024)*100)/ 100+" K");
  3470. text+=value+"\n";
  3471. }
  3472. Stat._txt.text=text;
  3473. }
  3474. Stat.FPS=0;
  3475. Stat.loopCount=0;
  3476. Stat.shaderCall=0;
  3477. Stat.renderBatches=0;
  3478. Stat.savedRenderBatches=0;
  3479. Stat.trianglesFaces=0;
  3480. Stat.spriteCount=0;
  3481. Stat.spriteRenderUseCacheCount=0;
  3482. Stat.frustumCulling=0;
  3483. Stat.octreeNodeCulling=0;
  3484. Stat.canvasNormal=0;
  3485. Stat.canvasBitmap=0;
  3486. Stat.canvasReCache=0;
  3487. Stat.renderSlow=false;
  3488. Stat.gpuMemory=0;
  3489. Stat.cpuMemory=0;
  3490. Stat._fpsStr=null;
  3491. Stat._canvasStr=null;
  3492. Stat._spriteStr=null;
  3493. Stat._fpsData=[];
  3494. Stat._timer=0;
  3495. Stat._count=0;
  3496. Stat._view=[];
  3497. Stat._fontSize=12;
  3498. Stat._txt=null;
  3499. Stat._leftText=null;
  3500. Stat._sp=null;
  3501. Stat._titleSp=null;
  3502. Stat._bgSp=null;
  3503. Stat._show=false;
  3504. Stat._useCanvas=false;
  3505. Stat._canvas=null;
  3506. Stat._ctx=null;
  3507. Stat._first=false;
  3508. Stat._vx=NaN;
  3509. Stat._width=0;
  3510. Stat._height=100;
  3511. return Stat;
  3512. })()
  3513. //class laya.webgl.canvas.Path
  3514. var Path=(function(){
  3515. var renderPath;
  3516. function Path(){
  3517. //public var _rect:Rectangle;
  3518. this._lastOriX=0;
  3519. //moveto等的原始位置。没有经过内部矩阵变换的
  3520. this._lastOriY=0;
  3521. this.paths=[];
  3522. //所有的路径。{@type renderPath[] }
  3523. this._curPath=null;
  3524. }
  3525. __class(Path,'laya.webgl.canvas.Path');
  3526. var __proto=Path.prototype;
  3527. __proto.beginPath=function(convex){
  3528. this.paths.length=1;
  3529. this._curPath=this.paths[0]=new renderPath();
  3530. this._curPath.convex=convex;
  3531. }
  3532. //_curPath.path=[];
  3533. __proto.closePath=function(){
  3534. this._curPath.loop=true;
  3535. }
  3536. __proto.newPath=function(){
  3537. this._curPath=new renderPath();
  3538. this.paths.push(this._curPath);
  3539. }
  3540. __proto.addPoint=function(pointX,pointY){
  3541. this._curPath.path.push(pointX,pointY);
  3542. }
  3543. //直接添加一个完整的path
  3544. __proto.push=function(points,convex){
  3545. if (!this._curPath){
  3546. this._curPath=new renderPath();
  3547. this.paths.push(this._curPath);
  3548. }else if (this._curPath.path.length > 0){
  3549. this._curPath=new renderPath();
  3550. this.paths.push(this._curPath);
  3551. };
  3552. var rp=this._curPath;
  3553. rp.path=points.slice();
  3554. rp.convex=convex;
  3555. }
  3556. __proto.reset=function(){
  3557. this.paths.length=0;
  3558. }
  3559. Path.__init$=function(){
  3560. //TODO 复用
  3561. //class renderPath
  3562. renderPath=(function(){
  3563. function renderPath(){
  3564. this.path=[];
  3565. //[x,y,x,y,....]的数组
  3566. this.loop=false;
  3567. this.convex=false;
  3568. }
  3569. __class(renderPath,'');
  3570. return renderPath;
  3571. })()
  3572. }
  3573. return Path;
  3574. })()
  3575. /**
  3576. *<p><code>MouseManager</code> 是鼠标、触摸交互管理器。</p>
  3577. *<p>鼠标事件流包括捕获阶段、目标阶段、冒泡阶段。<br/>
  3578. *捕获阶段:此阶段引擎会从stage开始递归检测stage及其子对象,直到找到命中的目标对象或者未命中任何对象;<br/>
  3579. *目标阶段:找到命中的目标对象;<br/>
  3580. *冒泡阶段:事件离开目标对象,按节点层级向上逐层通知,直到到达舞台的过程。</p>
  3581. */
  3582. //class laya.events.MouseManager
  3583. var MouseManager=(function(){
  3584. function MouseManager(){
  3585. /**canvas 上的鼠标X坐标。*/
  3586. this.mouseX=0;
  3587. /**canvas 上的鼠标Y坐标。*/
  3588. this.mouseY=0;
  3589. /**是否禁用除 stage 以外的鼠标事件检测。*/
  3590. this.disableMouseEvent=false;
  3591. /**鼠标按下的时间。单位为毫秒。*/
  3592. this.mouseDownTime=0;
  3593. /**鼠标移动精度。*/
  3594. this.mouseMoveAccuracy=2;
  3595. this._stage=null;
  3596. /**@private 希望capture鼠标事件的对象。*/
  3597. this._captureSp=null;
  3598. /**@private capture对象独占消息 */
  3599. this._captureExlusiveMode=false;
  3600. /**@private 在发送事件的过程中,是否发送给了_captureSp */
  3601. this._hitCaputreSp=false;
  3602. this._target=null;
  3603. this._lastMoveTimer=0;
  3604. this._isLeftMouse=false;
  3605. this._touchIDs={};
  3606. this._id=1;
  3607. this._tTouchID=0;
  3608. this._event=new Event();
  3609. this._captureChain=[];
  3610. this._matrix=new Matrix();
  3611. this._point=new Point();
  3612. this._rect=new Rectangle();
  3613. this._prePoint=new Point();
  3614. this._curTouchID=NaN;
  3615. }
  3616. __class(MouseManager,'laya.events.MouseManager');
  3617. var __proto=MouseManager.prototype;
  3618. /**
  3619. *@private
  3620. *初始化。
  3621. */
  3622. __proto.__init__=function(stage,canvas){
  3623. var _$this=this;
  3624. this._stage=stage;
  3625. var _this=this;
  3626. canvas.oncontextmenu=function (e){
  3627. if (MouseManager.enabled)return false;
  3628. }
  3629. canvas.addEventListener('mousedown',function(e){
  3630. if (MouseManager.enabled){
  3631. if(!Browser.onIE)e.preventDefault();
  3632. _this.mouseDownTime=Browser.now();
  3633. _$this.runEvent(e);
  3634. }
  3635. });
  3636. canvas.addEventListener('mouseup',function(e){
  3637. if (MouseManager.enabled){
  3638. e.preventDefault();
  3639. _this.mouseDownTime=-Browser.now();
  3640. _$this.runEvent(e);
  3641. }
  3642. },true);
  3643. canvas.addEventListener('mousemove',function(e){
  3644. if (MouseManager.enabled){
  3645. e.preventDefault();
  3646. var now=Browser.now();
  3647. if (now-_this._lastMoveTimer < 10)return;
  3648. _this._lastMoveTimer=now;
  3649. _$this.runEvent(e);
  3650. }
  3651. },true);
  3652. canvas.addEventListener("mouseout",function(e){
  3653. if (MouseManager.enabled)_$this.runEvent(e);
  3654. })
  3655. canvas.addEventListener("mouseover",function(e){
  3656. if (MouseManager.enabled)_$this.runEvent(e);
  3657. })
  3658. canvas.addEventListener("touchstart",function(e){
  3659. if (MouseManager.enabled){
  3660. if (!MouseManager._isFirstTouch&&!Input.isInputting)e.preventDefault();
  3661. _this.mouseDownTime=Browser.now();
  3662. _$this.runEvent(e);
  3663. }
  3664. });
  3665. canvas.addEventListener("touchend",function(e){
  3666. if (MouseManager.enabled){
  3667. if (!MouseManager._isFirstTouch&&!Input.isInputting)e.preventDefault();
  3668. MouseManager._isFirstTouch=false;
  3669. _this.mouseDownTime=-Browser.now();
  3670. _$this.runEvent(e);
  3671. }else {
  3672. _$this._curTouchID=NaN;
  3673. }
  3674. },true);
  3675. canvas.addEventListener("touchmove",function(e){
  3676. if (MouseManager.enabled){
  3677. e.preventDefault();
  3678. _$this.runEvent(e);
  3679. }
  3680. },true);
  3681. canvas.addEventListener("touchcancel",function(e){
  3682. if (MouseManager.enabled){
  3683. e.preventDefault();
  3684. _$this.runEvent(e);
  3685. }else {
  3686. _$this._curTouchID=NaN;
  3687. }
  3688. },true);
  3689. canvas.addEventListener('mousewheel',function(e){
  3690. if (MouseManager.enabled)_$this.runEvent(e);
  3691. });
  3692. canvas.addEventListener('DOMMouseScroll',function(e){
  3693. if (MouseManager.enabled)_$this.runEvent(e);
  3694. });
  3695. }
  3696. __proto.initEvent=function(e,nativeEvent){
  3697. var _this=this;
  3698. _this._event._stoped=false;
  3699. _this._event.nativeEvent=nativeEvent || e;
  3700. _this._target=null;
  3701. this._point.setTo(e.pageX || e.clientX,e.pageY || e.clientY);
  3702. if (this._stage._canvasTransform){
  3703. this._stage._canvasTransform.invertTransformPoint(this._point);
  3704. _this.mouseX=this._point.x;
  3705. _this.mouseY=this._point.y;
  3706. }
  3707. _this._event.touchId=e.identifier || 0;
  3708. this._tTouchID=_this._event.touchId;
  3709. var evt;
  3710. evt=TouchManager.I._event;
  3711. evt._stoped=false;
  3712. evt.nativeEvent=_this._event.nativeEvent;
  3713. evt.touchId=_this._event.touchId;
  3714. }
  3715. __proto.checkMouseWheel=function(e){
  3716. this._event.delta=e.wheelDelta ? e.wheelDelta *0.025 :-e.detail;
  3717. var _lastOvers=TouchManager.I.getLastOvers();
  3718. for (var i=0,n=_lastOvers.length;i < n;i++){
  3719. var ele=_lastOvers[i];
  3720. ele.event(/*laya.events.Event.MOUSE_WHEEL*/"mousewheel",this._event.setTo(/*laya.events.Event.MOUSE_WHEEL*/"mousewheel",ele,this._target));
  3721. }
  3722. }
  3723. // _stage.event(Event.MOUSE_WHEEL,_event.setTo(Event.MOUSE_WHEEL,_stage,_target));
  3724. __proto.onMouseMove=function(ele){
  3725. TouchManager.I.onMouseMove(ele,this._tTouchID);
  3726. }
  3727. __proto.onMouseDown=function(ele){
  3728. if (Input.isInputting && Laya.stage.focus && Laya.stage.focus["focus"] && !Laya.stage.focus.contains(this._target)){
  3729. var pre_input=Laya.stage.focus['_tf'] || Laya.stage.focus;
  3730. var new_input=ele['_tf'] || ele;
  3731. if ((new_input instanceof laya.display.Input )&& new_input.multiline==pre_input.multiline)
  3732. pre_input['_focusOut']();
  3733. else
  3734. pre_input.focus=false;
  3735. }
  3736. TouchManager.I.onMouseDown(ele,this._tTouchID,this._isLeftMouse);
  3737. }
  3738. __proto.onMouseUp=function(ele){
  3739. TouchManager.I.onMouseUp(ele,this._tTouchID,this._isLeftMouse);
  3740. }
  3741. __proto.check=function(sp,mouseX,mouseY,callBack){
  3742. this._point.setTo(mouseX,mouseY);
  3743. sp.fromParentPoint(this._point);
  3744. mouseX=this._point.x;
  3745. mouseY=this._point.y;
  3746. var scrollRect=sp._style.scrollRect;
  3747. if (scrollRect){
  3748. this._rect.setTo(scrollRect.x,scrollRect.y,scrollRect.width,scrollRect.height);
  3749. if (!this._rect.contains(mouseX,mouseY))return false;
  3750. }
  3751. if (!this.disableMouseEvent){
  3752. if (sp.hitTestPrior && !sp.mouseThrough && !this.hitTest(sp,mouseX,mouseY)){
  3753. return false;
  3754. }
  3755. for (var i=sp._children.length-1;i >-1;i--){
  3756. var child=sp._children[i];
  3757. if (!child.destroyed && child._mouseState > 1 && child._visible){
  3758. if (this.check(child,mouseX,mouseY,callBack))return true;
  3759. }
  3760. }
  3761. for (i=sp._extUIChild.length-1;i >=0;i--){
  3762. var c=sp._extUIChild[i];
  3763. if (!c.destroyed && c._mouseState > 1 && c._visible){
  3764. if (this.check(c,mouseX,mouseY,callBack))return true;
  3765. }
  3766. }
  3767. };
  3768. var isHit=(sp.hitTestPrior && !sp.mouseThrough && !this.disableMouseEvent)? true :this.hitTest(sp,mouseX,mouseY);
  3769. if (isHit){
  3770. this._target=sp;
  3771. callBack.call(this,sp);
  3772. if (this._target==this._hitCaputreSp){
  3773. this._hitCaputreSp=true;
  3774. }
  3775. }else if (callBack===this.onMouseUp && sp===this._stage){
  3776. this._target=this._stage;
  3777. callBack.call(this,this._target);
  3778. }
  3779. return isHit;
  3780. }
  3781. __proto.hitTest=function(sp,mouseX,mouseY){
  3782. var isHit=false;
  3783. if (sp.scrollRect){
  3784. mouseX-=sp._style.scrollRect.x;
  3785. mouseY-=sp._style.scrollRect.y;
  3786. };
  3787. var hitArea=sp._style.hitArea;
  3788. if (hitArea && hitArea._hit){
  3789. return hitArea.contains(mouseX,mouseY);
  3790. }
  3791. if (sp.width > 0 && sp.height > 0 || sp.mouseThrough || hitArea){
  3792. if (!sp.mouseThrough){
  3793. isHit=(hitArea ? hitArea :this._rect.setTo(0,0,sp.width,sp.height)).contains(mouseX,mouseY);
  3794. }else {
  3795. isHit=sp.getGraphicBounds().contains(mouseX,mouseY);
  3796. }
  3797. }
  3798. return isHit;
  3799. }
  3800. __proto._checkAllBaseUI=function(mousex,mousey,callback){
  3801. var ret=this.handleExclusiveCapture(this.mouseX,this.mouseY,callback);
  3802. if (ret)return true;
  3803. ret=this.check(this._stage,this.mouseX,this.mouseY,callback);
  3804. return this.handleCapture(this.mouseX,this.mouseY,callback)||ret;
  3805. }
  3806. /**
  3807. *处理3d界面。
  3808. *@param mousex
  3809. *@param mousey
  3810. *@param callback
  3811. *@return
  3812. */
  3813. __proto.check3DUI=function(mousex,mousey,callback){
  3814. var uis=this._stage._3dUI;
  3815. var i=0;
  3816. var ret=false;
  3817. for (;i < uis.length;i++){
  3818. var curui=uis[i];
  3819. this._stage._curUIBase=curui;
  3820. if(!curui.destroyed && curui._mouseState > 1 && curui._visible){
  3821. ret=ret || this.check(curui,this.mouseX,this.mouseY,callback);
  3822. }
  3823. }
  3824. this._stage._curUIBase=this._stage;
  3825. return ret;
  3826. }
  3827. __proto.handleExclusiveCapture=function(mousex,mousey,callback){
  3828. if (this._captureExlusiveMode && this._captureSp && this._captureChain.length > 0){
  3829. var cursp;
  3830. this._point.setTo(mousex,mousey);
  3831. for (var i=0;i < this._captureChain.length;i++){
  3832. cursp=this._captureChain[i];
  3833. cursp.fromParentPoint(this._point);
  3834. }
  3835. this._target=cursp;
  3836. callback.call(this,cursp);
  3837. return true;
  3838. }
  3839. return false;
  3840. }
  3841. __proto.handleCapture=function(mousex,mousey,callback){
  3842. if (!this._hitCaputreSp && this._captureSp && this._captureChain.length > 0){
  3843. var cursp;
  3844. this._point.setTo(mousex,mousey);
  3845. for (var i=0;i < this._captureChain.length;i++){
  3846. cursp=this._captureChain[i];
  3847. cursp.fromParentPoint(this._point);
  3848. }
  3849. this._target=cursp;
  3850. callback.call(this,cursp);
  3851. return true;
  3852. }
  3853. return false;
  3854. }
  3855. /**
  3856. *执行事件处理。
  3857. */
  3858. __proto.runEvent=function(evt){
  3859. var _this=this;
  3860. var i=0,n=0,touch;
  3861. if (evt.type!=='mousemove')this._prePoint.x=this._prePoint.y=-1000000;
  3862. switch (evt.type){
  3863. case 'mousedown':
  3864. this._touchIDs[0]=this._id++;
  3865. if (!MouseManager._isTouchRespond){
  3866. this._isLeftMouse=evt.button===0;
  3867. this.initEvent(evt);
  3868. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseDown);
  3869. }else
  3870. MouseManager._isTouchRespond=false;
  3871. break ;
  3872. case 'mouseup':
  3873. this._isLeftMouse=evt.button===0;
  3874. this.initEvent(evt);
  3875. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseUp);
  3876. break ;
  3877. case 'mousemove':
  3878. if ((Math.abs(this._prePoint.x-evt.clientX)+Math.abs(this._prePoint.y-evt.clientY))>=this.mouseMoveAccuracy){
  3879. this._prePoint.x=evt.clientX;
  3880. this._prePoint.y=evt.clientY;
  3881. this.initEvent(evt);
  3882. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseMove);
  3883. }
  3884. break ;
  3885. case "touchstart":
  3886. MouseManager._isTouchRespond=true;
  3887. this._isLeftMouse=true;
  3888. var touches=evt.changedTouches;
  3889. for (i=0,n=touches.length;i < n;i++){
  3890. touch=touches[i];
  3891. if (MouseManager.multiTouchEnabled || isNaN(this._curTouchID)){
  3892. this._curTouchID=touch.identifier;
  3893. if (this._id % 200===0)this._touchIDs={};
  3894. this._touchIDs[touch.identifier]=this._id++;
  3895. this.initEvent(touch,evt);
  3896. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseDown);
  3897. }
  3898. }
  3899. break ;
  3900. case "touchend":
  3901. case "touchcancel":
  3902. MouseManager._isTouchRespond=true;
  3903. this._isLeftMouse=true;
  3904. var touchends=evt.changedTouches;
  3905. for (i=0,n=touchends.length;i < n;i++){
  3906. touch=touchends[i];
  3907. if (MouseManager.multiTouchEnabled || touch.identifier==this._curTouchID){
  3908. this._curTouchID=NaN;
  3909. this.initEvent(touch,evt);
  3910. var isChecked=false;
  3911. isChecked=this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseUp);
  3912. if (!isChecked){
  3913. this.onMouseUp(null);
  3914. }
  3915. }
  3916. }
  3917. break ;
  3918. case "touchmove":;
  3919. var touchemoves=evt.changedTouches;
  3920. for (i=0,n=touchemoves.length;i < n;i++){
  3921. touch=touchemoves[i];
  3922. if (MouseManager.multiTouchEnabled || touch.identifier==this._curTouchID){
  3923. this.initEvent(touch,evt);
  3924. this._checkAllBaseUI(this.mouseX,this.mouseY,this.onMouseMove);
  3925. }
  3926. }
  3927. break ;
  3928. case "wheel":
  3929. case "mousewheel":
  3930. case "DOMMouseScroll":
  3931. this.checkMouseWheel(evt);
  3932. break ;
  3933. case "mouseout":
  3934. TouchManager.I.stageMouseOut();
  3935. break ;
  3936. case "mouseover":
  3937. this._stage.event(/*laya.events.Event.MOUSE_OVER*/"mouseover",this._event.setTo(/*laya.events.Event.MOUSE_OVER*/"mouseover",this._stage,this._stage));
  3938. break ;
  3939. }
  3940. }
  3941. /**
  3942. *
  3943. *@param sp
  3944. *@param exlusive 是否是独占模式
  3945. */
  3946. __proto.setCapture=function(sp,exclusive){
  3947. (exclusive===void 0)&& (exclusive=false);
  3948. this._captureSp=sp;
  3949. this._captureExlusiveMode=exclusive;
  3950. this._captureChain.length=0;
  3951. this._captureChain.push(sp);
  3952. var cursp=sp;
  3953. while (true){
  3954. if (cursp==Laya.stage)break ;
  3955. if (cursp==Laya.stage._curUIBase)break ;
  3956. cursp=cursp.parent;
  3957. if (!cursp)break ;
  3958. this._captureChain.splice(0,0,cursp);
  3959. }
  3960. }
  3961. __proto.releaseCapture=function(){
  3962. console.log('release capture');
  3963. this._captureSp=null;
  3964. }
  3965. MouseManager.enabled=true;
  3966. MouseManager.multiTouchEnabled=true;
  3967. MouseManager._isTouchRespond=false;
  3968. MouseManager._isFirstTouch=true;
  3969. __static(MouseManager,
  3970. ['instance',function(){return this.instance=new MouseManager();}
  3971. ]);
  3972. return MouseManager;
  3973. })()
  3974. /**
  3975. *@private
  3976. *TODO:
  3977. */
  3978. //class laya.utils.VectorGraphManager
  3979. var VectorGraphManager=(function(){
  3980. function VectorGraphManager(){
  3981. this.useDic={};
  3982. this.shapeDic={};
  3983. this.shapeLineDic={};
  3984. this._id=0;
  3985. this._checkKey=false;
  3986. this._freeIdArray=[];
  3987. CacheManger.regCacheByFunction(Utils.bind(this.startDispose,this),Utils.bind(this.getCacheList,this));
  3988. }
  3989. __class(VectorGraphManager,'laya.utils.VectorGraphManager');
  3990. var __proto=VectorGraphManager.prototype;
  3991. /**
  3992. *得到个空闲的ID
  3993. *@return
  3994. */
  3995. __proto.getId=function(){
  3996. return this._id++;
  3997. }
  3998. /**
  3999. *添加一个图形到列表中
  4000. *@param id
  4001. *@param shape
  4002. */
  4003. __proto.addShape=function(id,shape){
  4004. this.shapeDic[id]=shape;
  4005. if (!this.useDic[id]){
  4006. this.useDic[id]=true;
  4007. }
  4008. }
  4009. /**
  4010. *添加一个线图形到列表中
  4011. *@param id
  4012. *@param Line
  4013. */
  4014. __proto.addLine=function(id,Line){
  4015. this.shapeLineDic[id]=Line;
  4016. if (!this.shapeLineDic[id]){
  4017. this.shapeLineDic[id]=true;
  4018. }
  4019. }
  4020. /**
  4021. *检测一个对象是否在使用中
  4022. *@param id
  4023. */
  4024. __proto.getShape=function(id){
  4025. if (this._checkKey){
  4026. if (this.useDic[id] !=null){
  4027. this.useDic[id]=true;
  4028. }
  4029. }
  4030. }
  4031. /**
  4032. *删除一个图形对象
  4033. *@param id
  4034. */
  4035. __proto.deleteShape=function(id){
  4036. if (this.shapeDic[id]){
  4037. this.shapeDic[id]=null;
  4038. delete this.shapeDic[id];
  4039. }
  4040. if (this.shapeLineDic[id]){
  4041. this.shapeLineDic[id]=null;
  4042. delete this.shapeLineDic[id];
  4043. }
  4044. if (this.useDic[id] !=null){
  4045. delete this.useDic[id];
  4046. }
  4047. }
  4048. /**
  4049. *得到缓存列表
  4050. *@return
  4051. */
  4052. __proto.getCacheList=function(){
  4053. var str;
  4054. var list=[];
  4055. for (str in this.shapeDic){
  4056. list.push(this.shapeDic[str]);
  4057. }
  4058. for (str in this.shapeLineDic){
  4059. list.push(this.shapeLineDic[str]);
  4060. }
  4061. return list;
  4062. }
  4063. /**
  4064. *开始清理状态,准备销毁
  4065. */
  4066. __proto.startDispose=function(key){
  4067. var str;
  4068. for (str in this.useDic){
  4069. this.useDic[str]=false;
  4070. }
  4071. this._checkKey=true;
  4072. }
  4073. /**
  4074. *确认销毁
  4075. */
  4076. __proto.endDispose=function(){
  4077. if (this._checkKey){
  4078. var str;
  4079. for (str in this.useDic){
  4080. if (!this.useDic[str]){
  4081. this.deleteShape(str);
  4082. }
  4083. }
  4084. this._checkKey=false;
  4085. }
  4086. }
  4087. VectorGraphManager.getInstance=function(){
  4088. return VectorGraphManager.instance=VectorGraphManager.instance|| new VectorGraphManager();
  4089. }
  4090. VectorGraphManager.instance=null;
  4091. return VectorGraphManager;
  4092. })()
  4093. /**
  4094. *@private
  4095. *<code>MathUtil</code> 是一个数据处理工具类。
  4096. */
  4097. //class laya.maths.MathUtil
  4098. var MathUtil=(function(){
  4099. function MathUtil(){}
  4100. __class(MathUtil,'laya.maths.MathUtil');
  4101. MathUtil.subtractVector3=function(l,r,o){
  4102. o[0]=l[0]-r[0];
  4103. o[1]=l[1]-r[1];
  4104. o[2]=l[2]-r[2];
  4105. }
  4106. MathUtil.lerp=function(left,right,amount){
  4107. return left *(1-amount)+right *amount;
  4108. }
  4109. MathUtil.scaleVector3=function(f,b,e){
  4110. e[0]=f[0] *b;
  4111. e[1]=f[1] *b;
  4112. e[2]=f[2] *b;
  4113. }
  4114. MathUtil.lerpVector3=function(l,r,t,o){
  4115. var ax=l[0],ay=l[1],az=l[2];
  4116. o[0]=ax+t *(r[0]-ax);
  4117. o[1]=ay+t *(r[1]-ay);
  4118. o[2]=az+t *(r[2]-az);
  4119. }
  4120. MathUtil.lerpVector4=function(l,r,t,o){
  4121. var ax=l[0],ay=l[1],az=l[2],aw=l[3];
  4122. o[0]=ax+t *(r[0]-ax);
  4123. o[1]=ay+t *(r[1]-ay);
  4124. o[2]=az+t *(r[2]-az);
  4125. o[3]=aw+t *(r[3]-aw);
  4126. }
  4127. MathUtil.slerpQuaternionArray=function(a,Offset1,b,Offset2,t,out,Offset3){
  4128. 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];
  4129. var omega,cosom,sinom,scale0,scale1;
  4130. cosom=ax *bx+ay *by+az *bz+aw *bw;
  4131. if (cosom < 0.0){
  4132. cosom=-cosom;
  4133. bx=-bx;
  4134. by=-by;
  4135. bz=-bz;
  4136. bw=-bw;
  4137. }
  4138. if ((1.0-cosom)> 0.000001){
  4139. omega=Math.acos(cosom);
  4140. sinom=Math.sin(omega);
  4141. scale0=Math.sin((1.0-t)*omega)/ sinom;
  4142. scale1=Math.sin(t *omega)/ sinom;
  4143. }else {
  4144. scale0=1.0-t;
  4145. scale1=t;
  4146. }
  4147. out[Offset3+0]=scale0 *ax+scale1 *bx;
  4148. out[Offset3+1]=scale0 *ay+scale1 *by;
  4149. out[Offset3+2]=scale0 *az+scale1 *bz;
  4150. out[Offset3+3]=scale0 *aw+scale1 *bw;
  4151. return out;
  4152. }
  4153. MathUtil.getRotation=function(x0,y0,x1,y1){
  4154. return Math.atan2(y1-y0,x1-x0)/ Math.PI *180;
  4155. }
  4156. MathUtil.sortBigFirst=function(a,b){
  4157. if (a==b)return 0;
  4158. return b > a ? 1 :-1;
  4159. }
  4160. MathUtil.sortSmallFirst=function(a,b){
  4161. if (a==b)return 0;
  4162. return b > a ?-1 :1;
  4163. }
  4164. MathUtil.sortNumBigFirst=function(a,b){
  4165. return parseFloat(b)-parseFloat(a);
  4166. }
  4167. MathUtil.sortNumSmallFirst=function(a,b){
  4168. return parseFloat(a)-parseFloat(b);
  4169. }
  4170. MathUtil.sortByKey=function(key,bigFirst,forceNum){
  4171. (bigFirst===void 0)&& (bigFirst=false);
  4172. (forceNum===void 0)&& (forceNum=true);
  4173. var _sortFun;
  4174. if (bigFirst){
  4175. _sortFun=forceNum ? MathUtil.sortNumBigFirst :MathUtil.sortBigFirst;
  4176. }else {
  4177. _sortFun=forceNum ? MathUtil.sortNumSmallFirst :MathUtil.sortSmallFirst;
  4178. }
  4179. return function (a,b){
  4180. return _sortFun(a[key],b[key]);
  4181. }
  4182. }
  4183. return MathUtil;
  4184. })()
  4185. /**
  4186. *@private
  4187. *精灵渲染器
  4188. */
  4189. //class laya.renders.RenderSprite
  4190. var RenderSprite=(function(){
  4191. function RenderSprite(type,next){
  4192. /**@private */
  4193. //this._next=null;
  4194. /**@private */
  4195. //this._fun=null;
  4196. if (LayaGLQuickRunner.map[type]){
  4197. this._fun=LayaGLQuickRunner.map[type];
  4198. this._next=RenderSprite.NORENDER;
  4199. return;
  4200. }
  4201. this._next=next || RenderSprite.NORENDER;
  4202. switch (type){
  4203. case 0:
  4204. this._fun=this._no;
  4205. return;
  4206. case /*laya.display.SpriteConst.ALPHA*/0x01:
  4207. this._fun=this._alpha;
  4208. return;
  4209. case /*laya.display.SpriteConst.TRANSFORM*/0x02:
  4210. this._fun=this._transform;
  4211. return;
  4212. case /*laya.display.SpriteConst.BLEND*/0x04:
  4213. this._fun=this._blend;
  4214. return;
  4215. case /*laya.display.SpriteConst.CANVAS*/0x08:
  4216. this._fun=this._canvas;
  4217. return;
  4218. case /*laya.display.SpriteConst.MASK*/0x20:
  4219. this._fun=this._mask;
  4220. return;
  4221. case /*laya.display.SpriteConst.CLIP*/0x40:
  4222. this._fun=this._clip;
  4223. return;
  4224. case /*laya.display.SpriteConst.STYLE*/0x80:
  4225. this._fun=this._style;
  4226. return;
  4227. case /*laya.display.SpriteConst.GRAPHICS*/0x200:
  4228. this._fun=this._graphics;
  4229. return;
  4230. case /*laya.display.SpriteConst.CHILDS*/0x2000:
  4231. this._fun=this._children;
  4232. return;
  4233. case /*laya.display.SpriteConst.CUSTOM*/0x800:
  4234. this._fun=this._custom;
  4235. return;
  4236. case /*laya.display.SpriteConst.TEXTURE*/0x100:
  4237. this._fun=this._texture;
  4238. return;
  4239. case /*laya.display.SpriteConst.FILTERS*/0x10:
  4240. this._fun=Filter._filter;
  4241. return;
  4242. case 0x11111:
  4243. this._fun=RenderSprite._initRenderFun;
  4244. return;
  4245. }
  4246. this.onCreate(type);
  4247. }
  4248. __class(RenderSprite,'laya.renders.RenderSprite');
  4249. var __proto=RenderSprite.prototype;
  4250. __proto.onCreate=function(type){}
  4251. __proto._style=function(sprite,context,x,y){
  4252. var style=sprite._style;
  4253. if (style.render !=null)style.render(sprite,context,x,y);
  4254. var next=this._next;
  4255. next._fun.call(next,sprite,context,x,y);
  4256. }
  4257. __proto._no=function(sprite,context,x,y){}
  4258. //TODO:coverage
  4259. __proto._custom=function(sprite,context,x,y){
  4260. sprite.customRender(context,x,y);
  4261. this._next._fun.call(this._next,sprite,context,x-sprite.pivotX,y-sprite.pivotY);
  4262. }
  4263. __proto._clip=function(sprite,context,x,y){
  4264. var next=this._next;
  4265. if (next==RenderSprite.NORENDER)return;
  4266. var r=sprite._style.scrollRect;
  4267. context.save();
  4268. context.clipRect(x,y,r.width,r.height);
  4269. next._fun.call(next,sprite,context,x-r.x,y-r.y);
  4270. context.restore();
  4271. }
  4272. /*
  4273. public function _mask(sprite:Sprite,context:Context,x:Number,y:Number):void {
  4274. var next:RenderSprite=this._next;
  4275. next._fun.call(next,sprite,context,x,y);
  4276. var mask:Sprite=sprite.mask;
  4277. if (mask){
  4278. context.globalCompositeOperation="destination-in";
  4279. if (mask.numChildren > 0 || !mask.graphics._isOnlyOne()){
  4280. mask.cacheAs="bitmap";
  4281. }
  4282. mask.render(context,x-sprite._style.pivotX,y-sprite._style.pivotY);
  4283. }
  4284. context.globalCompositeOperation="source-over";
  4285. }
  4286. */
  4287. __proto._texture=function(sprite,context,x,y){
  4288. var tex=sprite.texture;
  4289. if(tex._getSource())
  4290. context.drawTexture(tex,x-sprite.pivotX+tex.offsetX,y-sprite.pivotY+tex.offsetY,sprite._width || tex.width,sprite._height || tex.height);
  4291. var next=this._next;
  4292. if(next!=RenderSprite.NORENDER)
  4293. next._fun.call(next,sprite,context,x,y);
  4294. }
  4295. __proto._graphics=function(sprite,context,x,y){
  4296. var style=sprite._style;
  4297. var g=sprite._graphics;
  4298. g && g._render(sprite,context,x-style.pivotX,y-style.pivotY);
  4299. var next=this._next;
  4300. if(next!=RenderSprite.NORENDER)
  4301. next._fun.call(next,sprite,context,x,y);
  4302. }
  4303. //TODO:coverage
  4304. __proto._image=function(sprite,context,x,y){
  4305. var style=sprite._style;
  4306. context.drawTexture2(x,y,style.pivotX,style.pivotY,sprite.transform,sprite._graphics._one);
  4307. }
  4308. //TODO:coverage
  4309. __proto._image2=function(sprite,context,x,y){
  4310. var style=sprite._style;
  4311. context.drawTexture2(x,y,style.pivotX,style.pivotY,sprite.transform,sprite._graphics._one);
  4312. }
  4313. //TODO:coverage
  4314. __proto._alpha=function(sprite,context,x,y){
  4315. var style=sprite._style;
  4316. var alpha;
  4317. if ((alpha=style.alpha)> 0.01 || sprite._needRepaint()){
  4318. var temp=context.globalAlpha;
  4319. context.globalAlpha *=alpha;
  4320. var next=this._next;
  4321. next._fun.call(next,sprite,context,x,y);
  4322. context.globalAlpha=temp;
  4323. }
  4324. }
  4325. __proto._transform=function(sprite,context,x,y){
  4326. var transform=sprite.transform,_next=this._next;
  4327. var style=sprite._style;
  4328. if (transform && _next !=RenderSprite.NORENDER){
  4329. context.save();
  4330. context.transform(transform.a,transform.b,transform.c,transform.d,transform.tx+x,transform.ty+y);
  4331. _next._fun.call(_next,sprite,context,0,0);
  4332. context.restore();
  4333. }else {
  4334. if(_next!=RenderSprite.NORENDER)
  4335. _next._fun.call(_next,sprite,context,x,y);
  4336. }
  4337. }
  4338. __proto._children=function(sprite,context,x,y){
  4339. var style=sprite._style;
  4340. var childs=sprite._children,n=childs.length,ele;
  4341. x=x-sprite.pivotX;
  4342. y=y-sprite.pivotY;
  4343. var textLastRender=sprite._getBit(/*laya.Const.DRAWCALL_OPTIMIZE*/0x100)&& context.drawCallOptimize(true);
  4344. if (style.viewport){
  4345. var rect=style.viewport;
  4346. var left=rect.x;
  4347. var top=rect.y;
  4348. var right=rect.right;
  4349. var bottom=rect.bottom;
  4350. var _x=NaN,_y=NaN;
  4351. for (i=0;i < n;++i){
  4352. if ((ele=childs [i])._visible && ((_x=ele._x)< right && (_x+ele.width)> left && (_y=ele._y)< bottom && (_y+ele.height)> top)){
  4353. ele.render(context,x,y);
  4354. }
  4355. }
  4356. }else {
  4357. for (var i=0;i < n;++i)
  4358. (ele=(childs [i]))._visible && ele.render(context,x,y);
  4359. }
  4360. textLastRender && context.drawCallOptimize(false);
  4361. }
  4362. __proto._canvas=function(sprite,context,x,y){
  4363. var _cacheStyle=sprite._cacheStyle;
  4364. var _next=this._next;
  4365. if (!_cacheStyle.enableCanvasRender){
  4366. _next._fun.call(_next,sprite,context,x,y);
  4367. return;
  4368. }
  4369. _cacheStyle.cacheAs==='bitmap' ? (Stat.canvasBitmap++):(Stat.canvasNormal++);
  4370. var cacheNeedRebuild=false;
  4371. var textNeedRestore=false;
  4372. if (_cacheStyle.canvas){
  4373. var canv=_cacheStyle.canvas;
  4374. var ctx=canv.context;
  4375. var charRIs=canv.touches;
  4376. if (charRIs){
  4377. for (var ci=0;ci < charRIs.length;ci++){
  4378. if (charRIs[ci].deleted){
  4379. textNeedRestore=true;
  4380. break ;
  4381. }
  4382. }
  4383. }
  4384. cacheNeedRebuild=canv.isCacheValid && !canv.isCacheValid();
  4385. }
  4386. if (sprite._needRepaint()|| (!_cacheStyle.canvas)|| textNeedRestore ||cacheNeedRebuild || Laya.stage.isGlobalRepaint()){
  4387. if (_cacheStyle.cacheAs==='normal'){
  4388. if(context._targets){
  4389. _next._fun.call(_next,sprite,context,x,y);
  4390. return;
  4391. }else{
  4392. this._canvas_webgl_normal_repaint(sprite,context);
  4393. }
  4394. }else{
  4395. this._canvas_repaint(sprite,context,x,y);
  4396. }
  4397. };
  4398. var tRec=_cacheStyle.cacheRect;
  4399. context.drawCanvas(_cacheStyle.canvas,x+tRec.x,y+tRec.y,tRec.width,tRec.height);
  4400. }
  4401. __proto._canvas_repaint=function(sprite,context,x,y){
  4402. var _cacheStyle=sprite._cacheStyle;
  4403. var _next=this._next;
  4404. var tx;
  4405. var canvas=_cacheStyle.canvas;
  4406. var left;
  4407. var top;
  4408. var tRec;
  4409. var tCacheType=_cacheStyle.cacheAs;
  4410. var w,h;
  4411. var scaleX,scaleY;
  4412. var scaleInfo;
  4413. scaleInfo=_cacheStyle._calculateCacheRect(sprite,tCacheType,x,y);
  4414. scaleX=scaleInfo.x;
  4415. scaleY=scaleInfo.y;
  4416. tRec=_cacheStyle.cacheRect;
  4417. w=tRec.width *scaleX;
  4418. h=tRec.height *scaleY;
  4419. left=tRec.x;
  4420. top=tRec.y;
  4421. if (tCacheType==='bitmap' && (w > 2048 || h > 2048)){
  4422. console.warn("cache bitmap size larger than 2048,cache ignored");
  4423. _cacheStyle.releaseContext();
  4424. _next._fun.call(_next,sprite,context,x,y);
  4425. return;
  4426. }
  4427. if (!canvas){
  4428. _cacheStyle.createContext();
  4429. canvas=_cacheStyle.canvas;
  4430. }
  4431. tx=canvas.context;
  4432. tx.sprite=sprite;
  4433. (canvas.width !=w || canvas.height !=h)&& canvas.size(w,h);
  4434. if (tCacheType==='bitmap')tx.asBitmap=true;
  4435. else if (tCacheType==='normal')tx.asBitmap=false;
  4436. tx.clear();
  4437. if (scaleX !=1 || scaleY !=1){
  4438. var ctx=tx;
  4439. ctx.save();
  4440. ctx.scale(scaleX,scaleY);
  4441. _next._fun.call(_next,sprite,tx,-left,-top);
  4442. ctx.restore();
  4443. sprite._applyFilters();
  4444. }else {
  4445. ctx=tx;
  4446. _next._fun.call(_next,sprite,tx,-left,-top);
  4447. sprite._applyFilters();
  4448. }
  4449. if (_cacheStyle.staticCache)_cacheStyle.reCache=false;
  4450. Stat.canvasReCache++;
  4451. }
  4452. __proto._canvas_webgl_normal_repaint=function(sprite,context){
  4453. var _cacheStyle=sprite._cacheStyle;
  4454. var _next=this._next;
  4455. var canvas=_cacheStyle.canvas;
  4456. var tCacheType=_cacheStyle.cacheAs;
  4457. var scaleInfo=_cacheStyle._calculateCacheRect(sprite,tCacheType,0,0);
  4458. if (!canvas){
  4459. canvas=_cacheStyle.canvas=/*__JS__ */new Laya.WebGLCacheAsNormalCanvas(context,sprite);
  4460. };
  4461. var tx=canvas.context;
  4462. canvas['startRec']();
  4463. _next._fun.call(_next,sprite,tx,sprite.pivotX,sprite.pivotY);
  4464. sprite._applyFilters();
  4465. Stat.canvasReCache++;
  4466. canvas['endRec']();
  4467. }
  4468. //context.drawCanvas(canvas,x ,y ,1,1);// 这种情况下宽高没用
  4469. __proto._blend=function(sprite,context,x,y){
  4470. var style=sprite._style;
  4471. var next=this._next;
  4472. if (style.blendMode){
  4473. context.save();
  4474. context.globalCompositeOperation=style.blendMode;
  4475. next._fun.call(next,sprite,context,x,y);
  4476. context.restore();
  4477. }else {
  4478. next._fun.call(next,sprite,context,x,y);
  4479. }
  4480. }
  4481. /**
  4482. *mask的渲染。 sprite有mask属性的情况下,来渲染这个sprite
  4483. *@param sprite
  4484. *@param context
  4485. *@param x
  4486. *@param y
  4487. */
  4488. __proto._mask=function(sprite,context,x,y){
  4489. var next=this._next;
  4490. var mask=sprite.mask;
  4491. var submitCMD;
  4492. var ctx=context;
  4493. if (mask){
  4494. ctx.save();
  4495. var preBlendMode=ctx.globalCompositeOperation;
  4496. var tRect=new Rectangle();
  4497. tRect.copyFrom(mask.getBounds());
  4498. tRect.width=Math.round(tRect.width);
  4499. tRect.height=Math.round(tRect.height);
  4500. tRect.x=Math.round(tRect.x);
  4501. tRect.y=Math.round(tRect.y);
  4502. if (tRect.width > 0 && tRect.height > 0){
  4503. var w=tRect.width;
  4504. var h=tRect.height;
  4505. var tmpRT=WebGLRTMgr.getRT(w,h);
  4506. ctx.breakNextMerge();
  4507. ctx.pushRT();
  4508. ctx.addRenderObject(SubmitCMD.create([ctx,tmpRT,w,h],RenderSprite.tmpTarget,this));
  4509. mask.render(ctx,-tRect.x,-tRect.y);
  4510. ctx.breakNextMerge();
  4511. ctx.popRT();
  4512. ctx.save();
  4513. ctx.clipRect(x+tRect.x-sprite.getStyle().pivotX,y+tRect.y-sprite.getStyle().pivotY,w,h);
  4514. next._fun.call(next,sprite,ctx,x,y);
  4515. ctx.restore();
  4516. preBlendMode=ctx.globalCompositeOperation;
  4517. ctx.addRenderObject(SubmitCMD.create(["mask"],RenderSprite.setBlendMode,this));
  4518. var shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  4519. var uv=Texture.INV_UV;
  4520. ctx.drawTarget(tmpRT,x+tRect.x-sprite.getStyle().pivotX ,y+tRect.y-sprite.getStyle().pivotY,w,h,Matrix.TEMP.identity(),shaderValue,uv,6);
  4521. ctx.addRenderObject(SubmitCMD.create([tmpRT],RenderSprite.recycleTarget,this));
  4522. ctx.addRenderObject(SubmitCMD.create([preBlendMode],RenderSprite.setBlendMode,this));
  4523. }
  4524. ctx.restore();
  4525. }else {
  4526. next._fun.call(next,sprite,context,x,y);
  4527. }
  4528. }
  4529. RenderSprite.__init__=function(){
  4530. LayaGLQuickRunner.__init__();
  4531. var i=0,len=0;
  4532. var initRender;
  4533. initRender=new RenderSprite(0x11111,null);
  4534. len=RenderSprite.renders.length=/*laya.display.SpriteConst.CHILDS*/0x2000 *2;
  4535. for (i=0;i < len;i++)
  4536. RenderSprite.renders[i]=initRender;
  4537. RenderSprite.renders[0]=new RenderSprite(0,null);
  4538. function _initSame (value,o){
  4539. var n=0;
  4540. for (var i=0;i < value.length;i++){
  4541. n |=value[i];
  4542. RenderSprite.renders[n]=o;
  4543. }
  4544. }
  4545. }
  4546. RenderSprite._initRenderFun=function(sprite,context,x,y){
  4547. var type=sprite._renderType;
  4548. var r=RenderSprite.renders[type]=RenderSprite._getTypeRender(type);
  4549. r._fun(sprite,context,x,y);
  4550. }
  4551. RenderSprite._getTypeRender=function(type){
  4552. if (LayaGLQuickRunner.map[type])return new RenderSprite(type,null);
  4553. var rst=null;
  4554. var tType=/*laya.display.SpriteConst.CHILDS*/0x2000;
  4555. while (tType > 0){
  4556. if (tType & type)
  4557. rst=new RenderSprite(tType,rst);
  4558. tType=tType >> 1;
  4559. }
  4560. return rst;
  4561. }
  4562. RenderSprite.tmpTarget=function(ctx,rt,w,h){
  4563. rt.start();
  4564. rt.clear(0,0,0,0);
  4565. }
  4566. RenderSprite.recycleTarget=function(rt){
  4567. WebGLRTMgr.releaseRT(rt);
  4568. }
  4569. RenderSprite.setBlendMode=function(blendMode){
  4570. var gl=WebGL.mainContext;
  4571. BlendMode.targetFns[BlendMode.TOINT[blendMode]](gl);
  4572. }
  4573. RenderSprite.INIT=0x11111;
  4574. RenderSprite.renders=[];
  4575. RenderSprite.NORENDER=new RenderSprite(0,null);
  4576. __static(RenderSprite,
  4577. ['tempUV',function(){return this.tempUV=new Array(8);}
  4578. ]);
  4579. return RenderSprite;
  4580. })()
  4581. /**
  4582. *<code>Keyboard</code> 类的属性是一些常数,这些常数表示控制游戏时最常用的键。
  4583. */
  4584. //class laya.events.Keyboard
  4585. var Keyboard=(function(){
  4586. function Keyboard(){}
  4587. __class(Keyboard,'laya.events.Keyboard');
  4588. Keyboard.NUMBER_0=48;
  4589. Keyboard.NUMBER_1=49;
  4590. Keyboard.NUMBER_2=50;
  4591. Keyboard.NUMBER_3=51;
  4592. Keyboard.NUMBER_4=52;
  4593. Keyboard.NUMBER_5=53;
  4594. Keyboard.NUMBER_6=54;
  4595. Keyboard.NUMBER_7=55;
  4596. Keyboard.NUMBER_8=56;
  4597. Keyboard.NUMBER_9=57;
  4598. Keyboard.A=65;
  4599. Keyboard.B=66;
  4600. Keyboard.C=67;
  4601. Keyboard.D=68;
  4602. Keyboard.E=69;
  4603. Keyboard.F=70;
  4604. Keyboard.G=71;
  4605. Keyboard.H=72;
  4606. Keyboard.I=73;
  4607. Keyboard.J=74;
  4608. Keyboard.K=75;
  4609. Keyboard.L=76;
  4610. Keyboard.M=77;
  4611. Keyboard.N=78;
  4612. Keyboard.O=79;
  4613. Keyboard.P=80;
  4614. Keyboard.Q=81;
  4615. Keyboard.R=82;
  4616. Keyboard.S=83;
  4617. Keyboard.T=84;
  4618. Keyboard.U=85;
  4619. Keyboard.V=86;
  4620. Keyboard.W=87;
  4621. Keyboard.X=88;
  4622. Keyboard.Y=89;
  4623. Keyboard.Z=90;
  4624. Keyboard.F1=112;
  4625. Keyboard.F2=113;
  4626. Keyboard.F3=114;
  4627. Keyboard.F4=115;
  4628. Keyboard.F5=116;
  4629. Keyboard.F6=117;
  4630. Keyboard.F7=118;
  4631. Keyboard.F8=119;
  4632. Keyboard.F9=120;
  4633. Keyboard.F10=121;
  4634. Keyboard.F11=122;
  4635. Keyboard.F12=123;
  4636. Keyboard.F13=124;
  4637. Keyboard.F14=125;
  4638. Keyboard.F15=126;
  4639. Keyboard.NUMPAD=21;
  4640. Keyboard.NUMPAD_0=96;
  4641. Keyboard.NUMPAD_1=97;
  4642. Keyboard.NUMPAD_2=98;
  4643. Keyboard.NUMPAD_3=99;
  4644. Keyboard.NUMPAD_4=100;
  4645. Keyboard.NUMPAD_5=101;
  4646. Keyboard.NUMPAD_6=102;
  4647. Keyboard.NUMPAD_7=103;
  4648. Keyboard.NUMPAD_8=104;
  4649. Keyboard.NUMPAD_9=105;
  4650. Keyboard.NUMPAD_ADD=107;
  4651. Keyboard.NUMPAD_DECIMAL=110;
  4652. Keyboard.NUMPAD_DIVIDE=111;
  4653. Keyboard.NUMPAD_ENTER=108;
  4654. Keyboard.NUMPAD_MULTIPLY=106;
  4655. Keyboard.NUMPAD_SUBTRACT=109;
  4656. Keyboard.SEMICOLON=186;
  4657. Keyboard.EQUAL=187;
  4658. Keyboard.COMMA=188;
  4659. Keyboard.MINUS=189;
  4660. Keyboard.PERIOD=190;
  4661. Keyboard.SLASH=191;
  4662. Keyboard.BACKQUOTE=192;
  4663. Keyboard.LEFTBRACKET=219;
  4664. Keyboard.BACKSLASH=220;
  4665. Keyboard.RIGHTBRACKET=221;
  4666. Keyboard.QUOTE=222;
  4667. Keyboard.ALTERNATE=18;
  4668. Keyboard.BACKSPACE=8;
  4669. Keyboard.CAPS_LOCK=20;
  4670. Keyboard.COMMAND=15;
  4671. Keyboard.CONTROL=17;
  4672. Keyboard.DELETE=46;
  4673. Keyboard.ENTER=13;
  4674. Keyboard.ESCAPE=27;
  4675. Keyboard.PAGE_UP=33;
  4676. Keyboard.PAGE_DOWN=34;
  4677. Keyboard.END=35;
  4678. Keyboard.HOME=36;
  4679. Keyboard.LEFT=37;
  4680. Keyboard.UP=38;
  4681. Keyboard.RIGHT=39;
  4682. Keyboard.DOWN=40;
  4683. Keyboard.SHIFT=16;
  4684. Keyboard.SPACE=32;
  4685. Keyboard.TAB=9;
  4686. Keyboard.INSERT=45;
  4687. return Keyboard;
  4688. })()
  4689. /**
  4690. *恢复命令,和save配套使用
  4691. */
  4692. //class laya.display.cmd.RestoreCmd
  4693. var RestoreCmd=(function(){
  4694. function RestoreCmd(){}
  4695. __class(RestoreCmd,'laya.display.cmd.RestoreCmd');
  4696. var __proto=RestoreCmd.prototype;
  4697. /**
  4698. *回收到对象池
  4699. */
  4700. __proto.recover=function(){
  4701. Pool.recover("RestoreCmd",this);
  4702. }
  4703. /**@private */
  4704. __proto.run=function(context,gx,gy){
  4705. context.restore();
  4706. }
  4707. /**@private */
  4708. __getset(0,__proto,'cmdID',function(){
  4709. return "Restore";
  4710. });
  4711. RestoreCmd.create=function(){
  4712. var cmd=Pool.getItemByClass("RestoreCmd",RestoreCmd);
  4713. return cmd;
  4714. }
  4715. RestoreCmd.ID="Restore";
  4716. return RestoreCmd;
  4717. })()
  4718. //class laya.webgl.shader.ShaderDefinesBase
  4719. var ShaderDefinesBase=(function(){
  4720. function ShaderDefinesBase(name2int,int2name,int2nameMap){
  4721. this._value=0;
  4722. //this._name2int=null;
  4723. //this._int2name=null;
  4724. //this._int2nameMap=null;
  4725. this._name2int=name2int;
  4726. this._int2name=int2name;
  4727. this._int2nameMap=int2nameMap;
  4728. }
  4729. __class(ShaderDefinesBase,'laya.webgl.shader.ShaderDefinesBase');
  4730. var __proto=ShaderDefinesBase.prototype;
  4731. //TODO:coverage
  4732. __proto.add=function(value){
  4733. if ((typeof value=='string'))value=this._name2int[value];
  4734. this._value |=value;
  4735. return this._value;
  4736. }
  4737. __proto.addInt=function(value){
  4738. this._value |=value;
  4739. return this._value;
  4740. }
  4741. //TODO:coverage
  4742. __proto.remove=function(value){
  4743. if ((typeof value=='string'))value=this._name2int[value];
  4744. this._value &=(~value);
  4745. return this._value;
  4746. }
  4747. //TODO:coverage
  4748. __proto.isDefine=function(def){
  4749. return (this._value & def)===def;
  4750. }
  4751. //TODO:coverage
  4752. __proto.getValue=function(){
  4753. return this._value;
  4754. }
  4755. __proto.setValue=function(value){
  4756. this._value=value;
  4757. }
  4758. __proto.toNameDic=function(){
  4759. var r=this._int2nameMap[this._value];
  4760. return r ? r :ShaderDefinesBase._toText(this._value,this._int2name,this._int2nameMap);
  4761. }
  4762. ShaderDefinesBase._reg=function(name,value,_name2int,_int2name){
  4763. _name2int[name]=value;
  4764. _int2name[value]=name;
  4765. }
  4766. ShaderDefinesBase._toText=function(value,_int2name,_int2nameMap){
  4767. var r=_int2nameMap[value];
  4768. if (r)return r;
  4769. var o={};
  4770. var d=1;
  4771. for (var i=0;i < 32;i++){
  4772. d=1 << i;
  4773. if (d > value)break ;
  4774. if (value & d){
  4775. var name=_int2name[d];
  4776. name && (o[name]="");
  4777. }
  4778. }
  4779. _int2nameMap[value]=o;
  4780. return o;
  4781. }
  4782. ShaderDefinesBase._toInt=function(names,_name2int){
  4783. var words=names.split('.');
  4784. var num=0;
  4785. for (var i=0,n=words.length;i < n;i++){
  4786. var value=_name2int[words[i]];
  4787. if (!value)throw new Error("Defines to int err:"+names+"/"+words[i]);
  4788. num |=value;
  4789. }
  4790. return num;
  4791. }
  4792. return ShaderDefinesBase;
  4793. })()
  4794. /**
  4795. *<code>BitmapFont</code> 是位图字体类,用于定义位图字体信息。
  4796. *字体制作及使用方法,请参考文章
  4797. *@see http://ldc2.layabox.com/doc/?nav=ch-js-1-2-5
  4798. */
  4799. //class laya.display.BitmapFont
  4800. var BitmapFont=(function(){
  4801. function BitmapFont(){
  4802. this._texture=null;
  4803. this._fontCharDic={};
  4804. this._fontWidthMap={};
  4805. this._complete=null;
  4806. this._path=null;
  4807. this._maxWidth=0;
  4808. this._spaceWidth=10;
  4809. this._padding=null;
  4810. /**当前位图字体字号,使用时,如果字号和设置不同,并且autoScaleSize=true,则按照设置字号比率进行缩放显示。*/
  4811. this.fontSize=12;
  4812. /**表示是否根据实际使用的字体大小缩放位图字体大小。*/
  4813. this.autoScaleSize=false;
  4814. /**字符间距(以像素为单位)。*/
  4815. this.letterSpacing=0;
  4816. }
  4817. __class(BitmapFont,'laya.display.BitmapFont');
  4818. var __proto=BitmapFont.prototype;
  4819. /**
  4820. *通过指定位图字体文件路径,加载位图字体文件,加载完成后会自动解析。
  4821. *@param path 位图字体文件的路径。
  4822. *@param complete 加载并解析完成的回调。
  4823. */
  4824. __proto.loadFont=function(path,complete){
  4825. this._path=path;
  4826. this._complete=complete;
  4827. if (!path || path.indexOf(".fnt")===-1){
  4828. console.error('Bitmap font configuration information must be a ".fnt" file');
  4829. return;
  4830. }
  4831. 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));
  4832. }
  4833. /**
  4834. *@private
  4835. */
  4836. __proto._onLoaded=function(){
  4837. this.parseFont(Loader.getRes(this._path),Loader.getRes(this._path.replace(".fnt",".png")));
  4838. this._complete && this._complete.run();
  4839. }
  4840. /**
  4841. *解析字体文件。
  4842. *@param xml 字体文件XML。
  4843. *@param texture 字体的纹理。
  4844. */
  4845. __proto.parseFont=function(xml,texture){
  4846. if (xml==null || texture==null)return;
  4847. this._texture=texture;
  4848. var tX=0;
  4849. var tScale=1;
  4850. var tInfo=xml.getElementsByTagName("info");
  4851. if (!tInfo[0].getAttributeNode){
  4852. return this.parseFont2(xml,texture);
  4853. }
  4854. this.fontSize=parseInt(tInfo[0].getAttributeNode("size").nodeValue);
  4855. var tPadding=tInfo[0].getAttributeNode("padding").nodeValue;
  4856. var tPaddingArray=tPadding.split(",");
  4857. this._padding=[parseInt(tPaddingArray[0]),parseInt(tPaddingArray[1]),parseInt(tPaddingArray[2]),parseInt(tPaddingArray[3])];
  4858. var chars;
  4859. chars=xml.getElementsByTagName("char");
  4860. var i=0;
  4861. for (i=0;i < chars.length;i++){
  4862. var tAttribute=chars[i];
  4863. var tId=parseInt(tAttribute.getAttributeNode("id").nodeValue);
  4864. var xOffset=parseInt(tAttribute.getAttributeNode("xoffset").nodeValue)/ tScale;
  4865. var yOffset=parseInt(tAttribute.getAttributeNode("yoffset").nodeValue)/ tScale;
  4866. var xAdvance=parseInt(tAttribute.getAttributeNode("xadvance").nodeValue)/ tScale;
  4867. var region=new Rectangle();
  4868. region.x=parseInt(tAttribute.getAttributeNode("x").nodeValue);
  4869. region.y=parseInt(tAttribute.getAttributeNode("y").nodeValue);
  4870. region.width=parseInt(tAttribute.getAttributeNode("width").nodeValue);
  4871. region.height=parseInt(tAttribute.getAttributeNode("height").nodeValue);
  4872. var tTexture=Texture.create((texture),region.x,region.y,region.width,region.height,xOffset,yOffset);
  4873. this._maxWidth=Math.max(this._maxWidth,xAdvance+this.letterSpacing);
  4874. this._fontCharDic[tId]=tTexture;
  4875. this._fontWidthMap[tId]=xAdvance;
  4876. }
  4877. }
  4878. /**
  4879. *解析字体文件。
  4880. *@param xml 字体文件XML。
  4881. *@param texture 字体的纹理。
  4882. */
  4883. __proto.parseFont2=function(xml,texture){
  4884. if (xml==null || texture==null)return;
  4885. this._texture=texture;
  4886. var tX=0;
  4887. var tScale=1;
  4888. var tInfo=xml.getElementsByTagName("info");
  4889. this.fontSize=parseInt(tInfo[0].attributes["size"].nodeValue);
  4890. var tPadding=tInfo[0].attributes["padding"].nodeValue;
  4891. var tPaddingArray=tPadding.split(",");
  4892. this._padding=[parseInt(tPaddingArray[0]),parseInt(tPaddingArray[1]),parseInt(tPaddingArray[2]),parseInt(tPaddingArray[3])];
  4893. var chars=xml.getElementsByTagName("char");
  4894. var i=0;
  4895. for (i=0;i < chars.length;i++){
  4896. var tAttribute=chars[i].attributes;
  4897. var tId=parseInt(tAttribute["id"].nodeValue);
  4898. var xOffset=parseInt(tAttribute["xoffset"].nodeValue)/ tScale;
  4899. var yOffset=parseInt(tAttribute["yoffset"].nodeValue)/ tScale;
  4900. var xAdvance=parseInt(tAttribute["xadvance"].nodeValue)/ tScale;
  4901. var region=new Rectangle();
  4902. region.x=parseInt(tAttribute["x"].nodeValue);
  4903. region.y=parseInt(tAttribute["y"].nodeValue);
  4904. region.width=parseInt(tAttribute["width"].nodeValue);
  4905. region.height=parseInt(tAttribute["height"].nodeValue);
  4906. var tTexture=Texture.create((texture),region.x,region.y,region.width,region.height,xOffset,yOffset);
  4907. this._maxWidth=Math.max(this._maxWidth,xAdvance+this.letterSpacing);
  4908. this._fontCharDic[tId]=tTexture;
  4909. this._fontWidthMap[tId]=xAdvance;
  4910. }
  4911. }
  4912. /**
  4913. *获取指定字符的字体纹理对象。
  4914. *@param char 字符。
  4915. *@return 指定的字体纹理对象。
  4916. */
  4917. __proto.getCharTexture=function(char){
  4918. return this._fontCharDic[char.charCodeAt(0)];
  4919. }
  4920. /**
  4921. *销毁位图字体,调用Text.unregisterBitmapFont 时,默认会销毁。
  4922. */
  4923. __proto.destroy=function(){
  4924. if (this._texture){
  4925. for (var p in this._fontCharDic){
  4926. var tTexture=this._fontCharDic[p];
  4927. if (tTexture)tTexture.destroy();
  4928. }
  4929. this._texture.destroy();
  4930. this._fontCharDic=null;
  4931. this._fontWidthMap=null;
  4932. this._texture=null;
  4933. this._complete=null;
  4934. this._padding=null;
  4935. }
  4936. }
  4937. /**
  4938. *设置空格的宽(如果字体库有空格,这里就可以不用设置了)。
  4939. *@param spaceWidth 宽度,单位为像素。
  4940. */
  4941. __proto.setSpaceWidth=function(spaceWidth){
  4942. this._spaceWidth=spaceWidth;
  4943. }
  4944. /**
  4945. *获取指定字符的宽度。
  4946. *@param char 字符。
  4947. *@return 宽度。
  4948. */
  4949. __proto.getCharWidth=function(char){
  4950. var code=char.charCodeAt(0);
  4951. if (this._fontWidthMap[code])return this._fontWidthMap[code]+this.letterSpacing;
  4952. if (char===" ")return this._spaceWidth+this.letterSpacing;
  4953. return 0;
  4954. }
  4955. /**
  4956. *获取指定文本内容的宽度。
  4957. *@param text 文本内容。
  4958. *@return 宽度。
  4959. */
  4960. __proto.getTextWidth=function(text){
  4961. var tWidth=0;
  4962. for (var i=0,n=text.length;i < n;i++){
  4963. tWidth+=this.getCharWidth(text.charAt(i));
  4964. }
  4965. return tWidth;
  4966. }
  4967. /**
  4968. *获取最大字符宽度。
  4969. */
  4970. __proto.getMaxWidth=function(){
  4971. return this._maxWidth;
  4972. }
  4973. /**
  4974. *获取最大字符高度。
  4975. */
  4976. __proto.getMaxHeight=function(){
  4977. return this.fontSize;
  4978. }
  4979. /**
  4980. *@private
  4981. *将指定的文本绘制到指定的显示对象上。
  4982. */
  4983. __proto._drawText=function(text,sprite,drawX,drawY,align,width){
  4984. var tWidth=this.getTextWidth(text);
  4985. var tTexture;
  4986. var dx=0;
  4987. align==="center" && (dx=(width-tWidth)/ 2);
  4988. align==="right" && (dx=(width-tWidth));
  4989. var tx=0;
  4990. for (var i=0,n=text.length;i < n;i++){
  4991. tTexture=this.getCharTexture(text.charAt(i));
  4992. if (tTexture){
  4993. sprite.graphics.drawImage(tTexture,drawX+tx+dx,drawY);
  4994. tx+=this.getCharWidth(text.charAt(i));
  4995. }
  4996. }
  4997. }
  4998. return BitmapFont;
  4999. })()
  5000. /**
  5001. *裁剪命令
  5002. */
  5003. //class laya.display.cmd.ClipRectCmd
  5004. var ClipRectCmd=(function(){
  5005. function ClipRectCmd(){
  5006. /**
  5007. *X 轴偏移量。
  5008. */
  5009. //this.x=NaN;
  5010. /**
  5011. *Y 轴偏移量。
  5012. */
  5013. //this.y=NaN;
  5014. /**
  5015. *宽度。
  5016. */
  5017. //this.width=NaN;
  5018. /**
  5019. *高度。
  5020. */
  5021. //this.height=NaN;
  5022. }
  5023. __class(ClipRectCmd,'laya.display.cmd.ClipRectCmd');
  5024. var __proto=ClipRectCmd.prototype;
  5025. /**
  5026. *回收到对象池
  5027. */
  5028. __proto.recover=function(){
  5029. Pool.recover("ClipRectCmd",this);
  5030. }
  5031. /**@private */
  5032. __proto.run=function(context,gx,gy){
  5033. context.clipRect(this.x+gx,this.y+gy,this.width,this.height);
  5034. }
  5035. /**@private */
  5036. __getset(0,__proto,'cmdID',function(){
  5037. return "ClipRect";
  5038. });
  5039. ClipRectCmd.create=function(x,y,width,height){
  5040. var cmd=Pool.getItemByClass("ClipRectCmd",ClipRectCmd);
  5041. cmd.x=x;
  5042. cmd.y=y;
  5043. cmd.width=width;
  5044. cmd.height=height;
  5045. return cmd;
  5046. }
  5047. ClipRectCmd.ID="ClipRect";
  5048. return ClipRectCmd;
  5049. })()
  5050. //class laya.webgl.shader.d2.Shader2D
  5051. var Shader2D=(function(){
  5052. function Shader2D(){
  5053. this.ALPHA=1;
  5054. //this.shader=null;
  5055. //this.filters=null;
  5056. this.shaderType=0;
  5057. //this.colorAdd=null;
  5058. this.defines=new ShaderDefines2D();
  5059. this.fillStyle=DrawStyle.DEFAULT;
  5060. this.strokeStyle=DrawStyle.DEFAULT;
  5061. }
  5062. __class(Shader2D,'laya.webgl.shader.d2.Shader2D');
  5063. var __proto=Shader2D.prototype;
  5064. __proto.destroy=function(){
  5065. this.defines=null;
  5066. this.filters=null;
  5067. }
  5068. Shader2D.__init__=function(){
  5069. var vs,ps;
  5070. 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}";
  5071. 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}";
  5072. Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,vs,ps,null);
  5073. 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}";
  5074. 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}";
  5075. Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.PRIMITIVE*/0x04,vs,ps,null);
  5076. 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}";
  5077. 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}";
  5078. Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.SKINMESH*/0x200,vs,ps,null);
  5079. }
  5080. return Shader2D;
  5081. })()
  5082. /**
  5083. *绘制多边形
  5084. */
  5085. //class laya.display.cmd.DrawPolyCmd
  5086. var DrawPolyCmd=(function(){
  5087. function DrawPolyCmd(){
  5088. /**
  5089. *开始绘制的 X 轴位置。
  5090. */
  5091. //this.x=NaN;
  5092. /**
  5093. *开始绘制的 Y 轴位置。
  5094. */
  5095. //this.y=NaN;
  5096. /**
  5097. *多边形的点集合。
  5098. */
  5099. //this.points=null;
  5100. /**
  5101. *填充颜色,或者填充绘图的渐变对象。
  5102. */
  5103. //this.fillColor=null;
  5104. /**
  5105. *(可选)边框颜色,或者填充绘图的渐变对象。
  5106. */
  5107. //this.lineColor=null;
  5108. /**
  5109. *可选)边框宽度。
  5110. */
  5111. //this.lineWidth=NaN;
  5112. /**@private */
  5113. //this.isConvexPolygon=false;
  5114. /**@private */
  5115. //this.vid=0;
  5116. }
  5117. __class(DrawPolyCmd,'laya.display.cmd.DrawPolyCmd');
  5118. var __proto=DrawPolyCmd.prototype;
  5119. /**
  5120. *回收到对象池
  5121. */
  5122. __proto.recover=function(){
  5123. this.points=null;
  5124. this.fillColor=null;
  5125. this.lineColor=null;
  5126. Pool.recover("DrawPolyCmd",this);
  5127. }
  5128. /**@private */
  5129. __proto.run=function(context,gx,gy){
  5130. context._drawPoly(this.x+gx,this.y+gy,this.points,this.fillColor,this.lineColor,this.lineWidth,this.isConvexPolygon,this.vid);
  5131. }
  5132. /**@private */
  5133. __getset(0,__proto,'cmdID',function(){
  5134. return "DrawPoly";
  5135. });
  5136. DrawPolyCmd.create=function(x,y,points,fillColor,lineColor,lineWidth,isConvexPolygon,vid){
  5137. var cmd=Pool.getItemByClass("DrawPolyCmd",DrawPolyCmd);
  5138. cmd.x=x;
  5139. cmd.y=y;
  5140. cmd.points=points;
  5141. cmd.fillColor=fillColor;
  5142. cmd.lineColor=lineColor;
  5143. cmd.lineWidth=lineWidth;
  5144. cmd.isConvexPolygon=isConvexPolygon;
  5145. cmd.vid=vid;
  5146. return cmd;
  5147. }
  5148. DrawPolyCmd.ID="DrawPoly";
  5149. return DrawPolyCmd;
  5150. })()
  5151. /**
  5152. *@private
  5153. */
  5154. //class laya.net.TTFLoader
  5155. var TTFLoader=(function(){
  5156. function TTFLoader(){
  5157. this.fontName=null;
  5158. this.complete=null;
  5159. this.err=null;
  5160. this._fontTxt=null;
  5161. this._url=null;
  5162. this._div=null;
  5163. this._txtWidth=NaN;
  5164. this._http=null;
  5165. }
  5166. __class(TTFLoader,'laya.net.TTFLoader');
  5167. var __proto=TTFLoader.prototype;
  5168. //TODO:coverage
  5169. __proto.load=function(fontPath){
  5170. this._url=fontPath;
  5171. var tArr=fontPath.split(".ttf")[0].split("/");
  5172. this.fontName=tArr[tArr.length-1];
  5173. if (Render.isConchApp){
  5174. this._loadConch();
  5175. }else
  5176. if (Browser.window.FontFace){
  5177. this._loadWithFontFace()
  5178. }
  5179. else {
  5180. this._loadWithCSS();
  5181. }
  5182. }
  5183. //TODO:coverage
  5184. __proto._loadConch=function(){
  5185. this._http=new HttpRequest();
  5186. this._http.on(/*laya.events.Event.ERROR*/"error",this,this._onErr);
  5187. this._http.on(/*laya.events.Event.COMPLETE*/"complete",this,this._onHttpLoaded);
  5188. this._http.send(this._url,null,"get",/*laya.net.Loader.BUFFER*/"arraybuffer");
  5189. }
  5190. //TODO:coverage
  5191. __proto._onHttpLoaded=function(data){
  5192. Browser.window["conchTextCanvas"].setFontFaceFromBuffer(this.fontName,data);
  5193. this._clearHttp();
  5194. this._complete();
  5195. }
  5196. //TODO:coverage
  5197. __proto._clearHttp=function(){
  5198. if (this._http){
  5199. this._http.off(/*laya.events.Event.ERROR*/"error",this,this._onErr);
  5200. this._http.off(/*laya.events.Event.COMPLETE*/"complete",this,this._onHttpLoaded);
  5201. this._http=null;
  5202. }
  5203. }
  5204. //TODO:coverage
  5205. __proto._onErr=function(){
  5206. this._clearHttp();
  5207. if (this.err){
  5208. this.err.runWith("fail:"+this._url);
  5209. this.err=null;
  5210. }
  5211. }
  5212. //TODO:coverage
  5213. __proto._complete=function(){
  5214. Laya.systemTimer.clear(this,this._complete);
  5215. Laya.systemTimer.clear(this,this._checkComplete);
  5216. if (this._div && this._div.parentNode){
  5217. this._div.parentNode.removeChild(this._div);
  5218. this._div=null;
  5219. }
  5220. if (this.complete){
  5221. this.complete.runWith(this);
  5222. this.complete=null;
  5223. }
  5224. }
  5225. //TODO:coverage
  5226. __proto._checkComplete=function(){
  5227. if (RunDriver.measureText("LayaTTFFont",this._fontTxt).width !=this._txtWidth){
  5228. this._complete();
  5229. }
  5230. }
  5231. //TODO:coverage
  5232. __proto._loadWithFontFace=function(){
  5233. var fontFace=new Browser.window.FontFace(this.fontName,"url('"+this._url+"')");
  5234. Browser.window.document.fonts.add(fontFace);
  5235. var self=this;
  5236. fontFace.loaded.then((function(){
  5237. self._complete()
  5238. }));
  5239. fontFace.load();
  5240. }
  5241. //TODO:coverage
  5242. __proto._createDiv=function(){
  5243. this._div=Browser.createElement("div");
  5244. this._div.innerHTML="laya";
  5245. var _style=this._div.style;
  5246. _style.fontFamily=this.fontName;
  5247. _style.position="absolute";
  5248. _style.left="-100px";
  5249. _style.top="-100px";
  5250. Browser.document.body.appendChild(this._div);
  5251. }
  5252. //TODO:coverage
  5253. __proto._loadWithCSS=function(){
  5254. var _$this=this;
  5255. var fontStyle=Browser.createElement("style");
  5256. fontStyle.type="text/css";
  5257. Browser.document.body.appendChild(fontStyle);
  5258. fontStyle.textContent="@font-face { font-family:'"+this.fontName+"'; src:url('"+this._url+"');}";
  5259. this._fontTxt="40px "+this.fontName;
  5260. this._txtWidth=RunDriver.measureText("LayaTTFFont",this._fontTxt).width;
  5261. var self=this;
  5262. fontStyle.onload=function (){
  5263. Laya.systemTimer.once(10000,self,_$this._complete);
  5264. };
  5265. Laya.systemTimer.loop(20,this,this._checkComplete);
  5266. this._createDiv();
  5267. }
  5268. TTFLoader._testString="LayaTTFFont";
  5269. return TTFLoader;
  5270. })()
  5271. /**
  5272. *...
  5273. *@author xie
  5274. */
  5275. //class laya.webgl.submit.SubmitKey
  5276. var SubmitKey=(function(){
  5277. function SubmitKey(){
  5278. this.blendShader=0;
  5279. this.submitType=0;
  5280. this.other=0;
  5281. this.clear();
  5282. }
  5283. __class(SubmitKey,'laya.webgl.submit.SubmitKey');
  5284. var __proto=SubmitKey.prototype;
  5285. __proto.clear=function(){
  5286. this.submitType=-1;
  5287. this.blendShader=this.other=0;
  5288. }
  5289. //TODO:coverage
  5290. __proto.copyFrom=function(src){
  5291. this.other=src.other;
  5292. this.blendShader=src.blendShader;
  5293. this.submitType=src.submitType;
  5294. }
  5295. //alpha=src.alpha;
  5296. __proto.copyFrom2=function(src,submitType,other){
  5297. this.other=other;
  5298. this.submitType=submitType;
  5299. }
  5300. //TODO:coverage
  5301. __proto.equal3_2=function(next,submitType,other){
  5302. return this.submitType===submitType && this.other===other && this.blendShader===next.blendShader;
  5303. }
  5304. //TODO:coverage
  5305. __proto.equal4_2=function(next,submitType,other){
  5306. return this.submitType===submitType && this.other===other && this.blendShader===next.blendShader;
  5307. }
  5308. //TODO:coverage
  5309. __proto.equal_3=function(next){
  5310. return this.submitType===next.submitType && this.blendShader===next.blendShader;
  5311. }
  5312. //TODO:coverage
  5313. __proto.equal=function(next){
  5314. return this.other===next.other && this.submitType===next.submitType && this.blendShader===next.blendShader;
  5315. }
  5316. return SubmitKey;
  5317. })()
  5318. /**
  5319. *绘制Canvas贴图
  5320. *@private
  5321. */
  5322. //class laya.display.cmd.DrawCanvasCmd
  5323. var DrawCanvasCmd=(function(){
  5324. function DrawCanvasCmd(){
  5325. this._graphicsCmdEncoder=null;
  5326. this._index=0;
  5327. this._paramData=null;
  5328. /**
  5329. *绘图数据
  5330. */
  5331. this.texture=null;
  5332. /**
  5333. *绘制区域起始位置x
  5334. */
  5335. this.x=NaN;
  5336. /**
  5337. *绘制区域起始位置y
  5338. */
  5339. this.y=NaN;
  5340. /**
  5341. *绘制区域宽
  5342. */
  5343. this.width=NaN;
  5344. /**
  5345. *绘制区域高
  5346. */
  5347. this.height=NaN;
  5348. }
  5349. __class(DrawCanvasCmd,'laya.display.cmd.DrawCanvasCmd');
  5350. var __proto=DrawCanvasCmd.prototype;
  5351. /**
  5352. *回收到对象池
  5353. */
  5354. __proto.recover=function(){
  5355. this._graphicsCmdEncoder=null;
  5356. Pool.recover("DrawCanvasCmd",this);
  5357. }
  5358. /**@private */
  5359. __getset(0,__proto,'cmdID',function(){
  5360. return "DrawCanvasCmd";
  5361. });
  5362. DrawCanvasCmd.create=function(texture,x,y,width,height){
  5363. return null;
  5364. }
  5365. DrawCanvasCmd.ID="DrawCanvasCmd";
  5366. DrawCanvasCmd._DRAW_IMAGE_CMD_ENCODER_=null;
  5367. DrawCanvasCmd._PARAM_TEXTURE_POS_=2;
  5368. DrawCanvasCmd._PARAM_VB_POS_=5;
  5369. return DrawCanvasCmd;
  5370. })()
  5371. /**
  5372. *<p> <code>Pool</code> 是对象池类,用于对象的存储、重复使用。</p>
  5373. *<p>合理使用对象池,可以有效减少对象创建的开销,避免频繁的垃圾回收,从而优化游戏流畅度。</p>
  5374. */
  5375. //class laya.utils.Pool
  5376. var Pool=(function(){
  5377. function Pool(){}
  5378. __class(Pool,'laya.utils.Pool');
  5379. Pool.getPoolBySign=function(sign){
  5380. return Pool._poolDic[sign] || (Pool._poolDic[sign]=[]);
  5381. }
  5382. Pool.clearBySign=function(sign){
  5383. if (Pool._poolDic[sign])Pool._poolDic[sign].length=0;
  5384. }
  5385. Pool.recover=function(sign,item){
  5386. if (item["__InPool"])return;
  5387. item["__InPool"]=true;
  5388. Pool.getPoolBySign(sign).push(item);
  5389. }
  5390. Pool.recoverByClass=function(instance){
  5391. if (instance){
  5392. var className=instance["__className"] || instance.constructor._$gid;
  5393. if (className)Pool.recover(className,instance);
  5394. }
  5395. }
  5396. Pool._getClassSign=function(cla){
  5397. var className=cla["__className"] || cla["_$gid"];
  5398. if (!className){
  5399. cla["_$gid"]=className=Utils.getGID()+"";
  5400. }
  5401. return className;
  5402. }
  5403. Pool.createByClass=function(cls){
  5404. return Pool.getItemByClass(Pool._getClassSign(cls),cls);
  5405. }
  5406. Pool.getItemByClass=function(sign,cls){
  5407. if (!Pool._poolDic[sign])return new cls();
  5408. var pool=Pool.getPoolBySign(sign);
  5409. if (pool.length){
  5410. var rst=pool.pop();
  5411. rst["__InPool"]=false;
  5412. }else {
  5413. rst=new cls();
  5414. }
  5415. return rst;
  5416. }
  5417. Pool.getItemByCreateFun=function(sign,createFun,caller){
  5418. var pool=Pool.getPoolBySign(sign);
  5419. var rst=pool.length ? pool.pop():createFun.call(caller);
  5420. rst["__InPool"]=false;
  5421. return rst;
  5422. }
  5423. Pool.getItem=function(sign){
  5424. var pool=Pool.getPoolBySign(sign);
  5425. var rst=pool.length ? pool.pop():null;
  5426. if (rst){
  5427. rst["__InPool"]=false;
  5428. }
  5429. return rst;
  5430. }
  5431. Pool.POOLSIGN="__InPool";
  5432. Pool._poolDic={};
  5433. return Pool;
  5434. })()
  5435. //class laya.webgl.utils.InlcudeFile
  5436. var InlcudeFile=(function(){
  5437. function InlcudeFile(txt){
  5438. this.script=null;
  5439. this.codes={};
  5440. this.funs={};
  5441. this.curUseID=-1;
  5442. this.funnames="";
  5443. this.script=txt;
  5444. var begin=0,ofs=0,end=0;
  5445. while (true){
  5446. begin=txt.indexOf("#begin",begin);
  5447. if (begin < 0)break ;
  5448. end=begin+5;
  5449. while (true){
  5450. end=txt.indexOf("#end",end);
  5451. if (end < 0)break ;
  5452. if (txt.charAt(end+4)==='i')
  5453. end+=5;
  5454. else break ;
  5455. }
  5456. if (end < 0){
  5457. throw "add include err,no #end:"+txt;
  5458. }
  5459. ofs=txt.indexOf('\n',begin);
  5460. var words=ShaderCompile.splitToWords(txt.substr(begin,ofs-begin),null);
  5461. if (words[1]=='code'){
  5462. this.codes[words[2]]=txt.substr(ofs+1,end-ofs-1);
  5463. }else if (words[1]=='function'){
  5464. ofs=txt.indexOf("function",begin);
  5465. ofs+="function".length;
  5466. this.funs[words[3]]=txt.substr(ofs+1,end-ofs-1);
  5467. this.funnames+=words[3]+";";
  5468. }
  5469. begin=end+1;
  5470. }
  5471. }
  5472. __class(InlcudeFile,'laya.webgl.utils.InlcudeFile');
  5473. var __proto=InlcudeFile.prototype;
  5474. __proto.getWith=function(name){
  5475. var r=name ? this.codes[name] :this.script;
  5476. if (!r){
  5477. throw "get with error:"+name;
  5478. }
  5479. return r;
  5480. }
  5481. __proto.getFunsScript=function(funsdef){
  5482. var r="";
  5483. for (var i in this.funs){
  5484. if (funsdef.indexOf(i+";")>=0){
  5485. r+=this.funs[i];
  5486. }
  5487. }
  5488. return r;
  5489. }
  5490. return InlcudeFile;
  5491. })()
  5492. /**
  5493. *@private
  5494. */
  5495. //class laya.display.SpriteConst
  5496. var SpriteConst=(function(){
  5497. function SpriteConst(){}
  5498. __class(SpriteConst,'laya.display.SpriteConst');
  5499. SpriteConst.ALPHA=0x01;
  5500. SpriteConst.TRANSFORM=0x02;
  5501. SpriteConst.BLEND=0x04;
  5502. SpriteConst.CANVAS=0x08;
  5503. SpriteConst.FILTERS=0x10;
  5504. SpriteConst.MASK=0x20;
  5505. SpriteConst.CLIP=0x40;
  5506. SpriteConst.STYLE=0x80;
  5507. SpriteConst.TEXTURE=0x100;
  5508. SpriteConst.GRAPHICS=0x200;
  5509. SpriteConst.LAYAGL3D=0x400;
  5510. SpriteConst.CUSTOM=0x800;
  5511. SpriteConst.ONECHILD=0x1000;
  5512. SpriteConst.CHILDS=0x2000;
  5513. SpriteConst.REPAINT_NONE=0;
  5514. SpriteConst.REPAINT_NODE=0x01;
  5515. SpriteConst.REPAINT_CACHE=0x02;
  5516. SpriteConst.REPAINT_ALL=0x03;
  5517. return SpriteConst;
  5518. })()
  5519. //class laya.webgl.utils.Buffer
  5520. var Buffer=(function(){
  5521. function Buffer(){
  5522. //当前gl绑定的indexBuffer
  5523. this._glBuffer=null;
  5524. this._buffer=null;
  5525. //可能为Float32Array、Uint16Array、Uint8Array、ArrayBuffer等。
  5526. this._bufferType=0;
  5527. this._bufferUsage=0;
  5528. this._byteLength=0;
  5529. this._glBuffer=LayaGL.instance.createBuffer()
  5530. }
  5531. __class(Buffer,'laya.webgl.utils.Buffer');
  5532. var __proto=Buffer.prototype;
  5533. /**
  5534. *@private
  5535. *绕过全局状态判断,例如VAO局部状态设置
  5536. */
  5537. __proto._bindForVAO=function(){}
  5538. //TODO:coverage
  5539. __proto.bind=function(){
  5540. return false;
  5541. }
  5542. /**
  5543. *@private
  5544. */
  5545. __proto.destroy=function(){
  5546. if (this._glBuffer){
  5547. LayaGL.instance.deleteBuffer(this._glBuffer);
  5548. this._glBuffer=null;
  5549. }
  5550. }
  5551. __getset(0,__proto,'bufferUsage',function(){
  5552. return this._bufferUsage;
  5553. });
  5554. Buffer._bindedVertexBuffer=null;
  5555. Buffer._bindedIndexBuffer=null;
  5556. return Buffer;
  5557. })()
  5558. /**
  5559. *绘制单个贴图
  5560. */
  5561. //class laya.display.cmd.DrawTextureCmd
  5562. var DrawTextureCmd=(function(){
  5563. function DrawTextureCmd(){
  5564. /**
  5565. *纹理。
  5566. */
  5567. //this.texture=null;
  5568. /**
  5569. *(可选)X轴偏移量。
  5570. */
  5571. //this.x=NaN;
  5572. /**
  5573. *(可选)Y轴偏移量。
  5574. */
  5575. //this.y=NaN;
  5576. /**
  5577. *(可选)宽度。
  5578. */
  5579. //this.width=NaN;
  5580. /**
  5581. *(可选)高度。
  5582. */
  5583. //this.height=NaN;
  5584. /**
  5585. *(可选)矩阵信息。
  5586. */
  5587. //this.matrix=null;
  5588. /**
  5589. *(可选)透明度。
  5590. */
  5591. //this.alpha=NaN;
  5592. /**
  5593. *(可选)颜色滤镜。
  5594. */
  5595. //this.color=null;
  5596. this.colorFlt=null;
  5597. /**
  5598. *(可选)混合模式。
  5599. */
  5600. //this.blendMode=null;
  5601. }
  5602. __class(DrawTextureCmd,'laya.display.cmd.DrawTextureCmd');
  5603. var __proto=DrawTextureCmd.prototype;
  5604. /**
  5605. *回收到对象池
  5606. */
  5607. __proto.recover=function(){
  5608. this.texture._removeReference();
  5609. this.texture=null;
  5610. this.matrix=null;
  5611. Pool.recover("DrawTextureCmd",this);
  5612. }
  5613. /**@private */
  5614. __proto.run=function(context,gx,gy){
  5615. context.drawTextureWithTransform(this.texture,this.x,this.y,this.width,this.height,this.matrix,gx,gy,this.alpha,this.blendMode,this.colorFlt);
  5616. }
  5617. /**@private */
  5618. __getset(0,__proto,'cmdID',function(){
  5619. return "DrawTexture";
  5620. });
  5621. DrawTextureCmd.create=function(texture,x,y,width,height,matrix,alpha,color,blendMode){
  5622. var cmd=Pool.getItemByClass("DrawTextureCmd",DrawTextureCmd);
  5623. cmd.texture=texture;
  5624. texture._addReference();
  5625. cmd.x=x;
  5626. cmd.y=y;
  5627. cmd.width=width;
  5628. cmd.height=height;
  5629. cmd.matrix=matrix;
  5630. cmd.alpha=alpha;
  5631. cmd.color=color;
  5632. cmd.blendMode=blendMode;
  5633. if (color){
  5634. cmd.colorFlt=new ColorFilter();
  5635. cmd.colorFlt.setColor(color);
  5636. }
  5637. return cmd;
  5638. }
  5639. DrawTextureCmd.ID="DrawTexture";
  5640. return DrawTextureCmd;
  5641. })()
  5642. //class laya.webgl.shader.d2.value.Value2D
  5643. var Value2D=(function(){
  5644. function Value2D(mainID,subID){
  5645. this.size=[0,0];
  5646. this.alpha=1.0;
  5647. //这个目前只给setIBVB用。其他的都放到attribute的color中了
  5648. //this.mmat=null;
  5649. //worldmatrix,是4x4的,因为为了shader使用方便。 TODO 换成float32Array
  5650. //this.u_MvpMatrix=null;
  5651. //this.texture=null;
  5652. this.ALPHA=1.0;
  5653. //这个?
  5654. //this.shader=null;
  5655. //this.mainID=0;
  5656. this.subID=0;
  5657. //this.filters=null;
  5658. //this.textureHost=null;
  5659. //public var fillStyle:DrawStyle;//TODO 这个有什么用?
  5660. //this.color=null;
  5661. //public var strokeStyle:DrawStyle;
  5662. //this.colorAdd=null;
  5663. //this.u_mmat2=null;
  5664. this.ref=1;
  5665. //this._attribLocation=null;
  5666. //[name,location,name,location...] 由继承类赋值。这个最终会传给对应的shader
  5667. //this._inClassCache=null;
  5668. this._cacheID=0;
  5669. this.clipMatDir=[ /*laya.resource.Context._MAXSIZE*/99999999,0,0,/*laya.resource.Context._MAXSIZE*/99999999];
  5670. this.clipMatPos=[0,0];
  5671. this.clipOff=[0,0];
  5672. this.defines=new ShaderDefines2D();
  5673. this.mainID=mainID;
  5674. this.subID=subID;
  5675. this.textureHost=null;
  5676. this.texture=null;
  5677. this.color=null;
  5678. this.colorAdd=null;
  5679. this.u_mmat2=null;
  5680. this._cacheID=mainID|subID;
  5681. this._inClassCache=Value2D._cache[this._cacheID];
  5682. if (mainID>0 && !this._inClassCache){
  5683. this._inClassCache=Value2D._cache[this._cacheID]=[];
  5684. this._inClassCache._length=0;
  5685. }
  5686. this.clear();
  5687. }
  5688. __class(Value2D,'laya.webgl.shader.d2.value.Value2D');
  5689. var __proto=Value2D.prototype;
  5690. __proto.setValue=function(value){}
  5691. //public function refresh():ShaderValue
  5692. __proto._ShaderWithCompile=function(){
  5693. var ret=Shader.withCompile2D(0,this.mainID,this.defines.toNameDic(),this.mainID | this.defines._value,Shader2X.create,this._attribLocation);
  5694. return ret;
  5695. }
  5696. __proto.upload=function(){
  5697. var renderstate2d=RenderState2D;
  5698. RenderState2D.worldMatrix4===RenderState2D.TEMPMAT4_ARRAY || this.defines.addInt(/*laya.webgl.shader.d2.ShaderDefines2D.WORLDMAT*/0x80);
  5699. this.mmat=renderstate2d.worldMatrix4;
  5700. if (RenderState2D.matWVP){
  5701. this.defines.addInt(/*laya.webgl.shader.d2.ShaderDefines2D.MVP3D*/0x800);
  5702. this.u_MvpMatrix=RenderState2D.matWVP.elements;
  5703. };
  5704. var sd=Shader.sharders[this.mainID | this.defines._value] || this._ShaderWithCompile();
  5705. if (sd._shaderValueWidth!==renderstate2d.width || sd._shaderValueHeight!==renderstate2d.height){
  5706. this.size[0]=renderstate2d.width;
  5707. this.size[1]=renderstate2d.height;
  5708. sd._shaderValueWidth=renderstate2d.width;
  5709. sd._shaderValueHeight=renderstate2d.height;
  5710. sd.upload(this,null);
  5711. }
  5712. else{
  5713. sd.upload(this,sd._params2dQuick2 || sd._make2dQuick2());
  5714. }
  5715. }
  5716. //TODO:coverage
  5717. __proto.setFilters=function(value){
  5718. this.filters=value;
  5719. if (!value)
  5720. return;
  5721. var n=value.length,f;
  5722. for (var i=0;i < n;i++){
  5723. f=value[i];
  5724. if (f){
  5725. this.defines.add(f.type);
  5726. f.action.setValue(this);
  5727. }
  5728. }
  5729. }
  5730. __proto.clear=function(){
  5731. this.defines._value=this.subID+(WebGL.shaderHighPrecision? /*laya.webgl.shader.d2.ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION*/0x400:0);
  5732. this.clipOff[0]=0;
  5733. }
  5734. __proto.release=function(){
  5735. if ((--this.ref)< 1){
  5736. this._inClassCache && (this._inClassCache[this._inClassCache._length++]=this);
  5737. this.clear();
  5738. this.filters=null;
  5739. this.ref=1;
  5740. this.clipOff[0]=0;
  5741. }
  5742. }
  5743. Value2D._initone=function(type,classT){
  5744. Value2D._typeClass[type]=classT;
  5745. Value2D._cache[type]=[];
  5746. Value2D._cache[type]._length=0;
  5747. }
  5748. Value2D.__init__=function(){
  5749. Value2D._initone(/*laya.webgl.shader.d2.ShaderDefines2D.PRIMITIVE*/0x04,PrimitiveSV);
  5750. Value2D._initone(/*laya.webgl.shader.d2.ShaderDefines2D.SKINMESH*/0x200,SkinSV);
  5751. Value2D._initone(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,TextureSV);
  5752. Value2D._initone(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01 | /*laya.webgl.shader.d2.ShaderDefines2D.FILTERGLOW*/0x08,TextureSV);
  5753. }
  5754. Value2D.create=function(mainType,subType){
  5755. var types=Value2D._cache[mainType|subType];
  5756. if (types._length)
  5757. return types[--types._length];
  5758. else
  5759. return new Value2D._typeClass[mainType|subType](subType);
  5760. }
  5761. Value2D._cache=[];
  5762. Value2D._typeClass=[];
  5763. Value2D.TEMPMAT4_ARRAY=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];
  5764. return Value2D;
  5765. })()
  5766. /**
  5767. *@private
  5768. *凸包算法。
  5769. */
  5770. //class laya.maths.GrahamScan
  5771. var GrahamScan=(function(){
  5772. function GrahamScan(){}
  5773. __class(GrahamScan,'laya.maths.GrahamScan');
  5774. GrahamScan.multiply=function(p1,p2,p0){
  5775. return ((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));
  5776. }
  5777. GrahamScan.dis=function(p1,p2){
  5778. return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
  5779. }
  5780. GrahamScan._getPoints=function(count,tempUse,rst){
  5781. (tempUse===void 0)&& (tempUse=false);
  5782. if (!GrahamScan._mPointList)GrahamScan._mPointList=[];
  5783. while (GrahamScan._mPointList.length < count)GrahamScan._mPointList.push(new Point());
  5784. if (!rst)rst=[];
  5785. rst.length=0;
  5786. if (tempUse){
  5787. GrahamScan.getFrom(rst,GrahamScan._mPointList,count);
  5788. }else {
  5789. GrahamScan.getFromR(rst,GrahamScan._mPointList,count);
  5790. }
  5791. return rst;
  5792. }
  5793. GrahamScan.getFrom=function(rst,src,count){
  5794. var i=0;
  5795. for (i=0;i < count;i++){
  5796. rst.push(src[i]);
  5797. }
  5798. return rst;
  5799. }
  5800. GrahamScan.getFromR=function(rst,src,count){
  5801. var i=0;
  5802. for (i=0;i < count;i++){
  5803. rst.push(src.pop());
  5804. }
  5805. return rst;
  5806. }
  5807. GrahamScan.pListToPointList=function(pList,tempUse){
  5808. (tempUse===void 0)&& (tempUse=false);
  5809. var i=0,len=pList.length / 2,rst=GrahamScan._getPoints(len,tempUse,GrahamScan._tempPointList);
  5810. for (i=0;i < len;i++){
  5811. rst[i].setTo(pList[i+i],pList[i+i+1]);
  5812. }
  5813. return rst;
  5814. }
  5815. GrahamScan.pointListToPlist=function(pointList){
  5816. var i=0,len=pointList.length,rst=GrahamScan._temPList,tPoint;
  5817. rst.length=0;
  5818. for (i=0;i < len;i++){
  5819. tPoint=pointList[i];
  5820. rst.push(tPoint.x,tPoint.y);
  5821. }
  5822. return rst;
  5823. }
  5824. GrahamScan.scanPList=function(pList){
  5825. return Utils.copyArray(pList,GrahamScan.pointListToPlist(GrahamScan.scan(GrahamScan.pListToPointList(pList,true))));
  5826. }
  5827. GrahamScan.scan=function(PointSet){
  5828. var i=0,j=0,k=0,top=2,tmp,n=PointSet.length,ch;
  5829. var _tmpDic={};
  5830. var key;
  5831. ch=GrahamScan._temArr;
  5832. ch.length=0;
  5833. n=PointSet.length;
  5834. for (i=n-1;i >=0;i--){
  5835. tmp=PointSet[i];
  5836. key=tmp.x+"_"+tmp.y;
  5837. if (!_tmpDic.hasOwnProperty(key)){
  5838. _tmpDic[key]=true;
  5839. ch.push(tmp);
  5840. }
  5841. }
  5842. n=ch.length;
  5843. Utils.copyArray(PointSet,ch);
  5844. for (i=1;i < n;i++)
  5845. if ((PointSet[i].y < PointSet[k].y)|| ((PointSet[i].y==PointSet[k].y)&& (PointSet[i].x < PointSet[k].x)))
  5846. k=i;
  5847. tmp=PointSet[0];
  5848. PointSet[0]=PointSet[k];
  5849. PointSet[k]=tmp;
  5850. for (i=1;i < n-1;i++){
  5851. k=i;
  5852. for (j=i+1;j < n;j++)
  5853. 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]))))
  5854. k=j;
  5855. tmp=PointSet[i];
  5856. PointSet[i]=PointSet[k];
  5857. PointSet[k]=tmp;
  5858. }
  5859. ch=GrahamScan._temArr;
  5860. ch.length=0;
  5861. if (PointSet.length < 3){
  5862. return Utils.copyArray(ch,PointSet);
  5863. }
  5864. ch.push(PointSet[0],PointSet[1],PointSet[2]);
  5865. for (i=3;i < n;i++){
  5866. while (ch.length >=2 && GrahamScan.multiply(PointSet[i],ch[ch.length-1],ch[ch.length-2])>=0)ch.pop();
  5867. PointSet[i] && ch.push(PointSet[i]);
  5868. }
  5869. return ch;
  5870. }
  5871. GrahamScan._mPointList=null;
  5872. GrahamScan._tempPointList=[];
  5873. GrahamScan._temPList=[];
  5874. GrahamScan._temArr=[];
  5875. return GrahamScan;
  5876. })()
  5877. //class laya.webgl.canvas.save.SaveMark
  5878. var SaveMark=(function(){
  5879. function SaveMark(){
  5880. this._saveuse=0;
  5881. //this._preSaveMark=null;
  5882. }
  5883. __class(SaveMark,'laya.webgl.canvas.save.SaveMark');
  5884. var __proto=SaveMark.prototype;
  5885. Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true})
  5886. __proto.isSaveMark=function(){
  5887. return true;
  5888. }
  5889. __proto.restore=function(context){
  5890. context._saveMark=this._preSaveMark;
  5891. SaveMark.POOL[SaveMark.POOL._length++]=this;
  5892. }
  5893. SaveMark.Create=function(context){
  5894. var no=SaveMark.POOL;
  5895. var o=no._length > 0 ? no[--no._length] :(new SaveMark());
  5896. o._saveuse=0;
  5897. o._preSaveMark=context._saveMark;
  5898. context._saveMark=o;
  5899. return o;
  5900. }
  5901. SaveMark.POOL=SaveBase._createArray();
  5902. return SaveMark;
  5903. })()
  5904. /**
  5905. *<code>Tween</code> 是一个缓动类。使用此类能够实现对目标对象属性的渐变。
  5906. */
  5907. //class laya.utils.Tween
  5908. var Tween=(function(){
  5909. function Tween(){
  5910. /**@private */
  5911. //this._complete=null;
  5912. /**@private */
  5913. //this._target=null;
  5914. /**@private */
  5915. //this._ease=null;
  5916. /**@private */
  5917. //this._props=null;
  5918. /**@private */
  5919. //this._duration=0;
  5920. /**@private */
  5921. //this._delay=0;
  5922. /**@private */
  5923. //this._startTimer=0;
  5924. /**@private */
  5925. //this._usedTimer=0;
  5926. /**@private */
  5927. //this._usedPool=false;
  5928. /**@private */
  5929. //this._delayParam=null;
  5930. /**@private 唯一标识,TimeLintLite用到*/
  5931. this.gid=0;
  5932. /**更新回调,缓动数值发生变化时,回调变化的值*/
  5933. //this.update=null;
  5934. /**重播次数,如果repeat=0,则表示无限循环播放*/
  5935. this.repeat=1;
  5936. /**当前播放次数*/
  5937. this._count=0;
  5938. }
  5939. __class(Tween,'laya.utils.Tween');
  5940. var __proto=Tween.prototype;
  5941. /**
  5942. *缓动对象的props属性到目标值。
  5943. *@param target 目标对象(即将更改属性值的对象)。
  5944. *@param props 变化的属性列表,比如{x:100,y:20,ease:Ease.backOut,complete:Handler.create(this,onComplete),update:new Handler(this,onComplete)}。
  5945. *@param duration 花费的时间,单位毫秒。
  5946. *@param ease 缓动类型,默认为匀速运动。
  5947. *@param complete 结束回调函数。
  5948. *@param delay 延迟执行时间。
  5949. *@param coverBefore 是否覆盖之前的缓动。
  5950. *@return 返回Tween对象。
  5951. */
  5952. __proto.to=function(target,props,duration,ease,complete,delay,coverBefore){
  5953. (delay===void 0)&& (delay=0);
  5954. (coverBefore===void 0)&& (coverBefore=false);
  5955. return this._create(target,props,duration,ease,complete,delay,coverBefore,true,false,true);
  5956. }
  5957. /**
  5958. *从props属性,缓动到当前状态。
  5959. *@param target 目标对象(即将更改属性值的对象)。
  5960. *@param props 变化的属性列表,比如{x:100,y:20,ease:Ease.backOut,complete:Handler.create(this,onComplete),update:new Handler(this,onComplete)}。
  5961. *@param duration 花费的时间,单位毫秒。
  5962. *@param ease 缓动类型,默认为匀速运动。
  5963. *@param complete 结束回调函数。
  5964. *@param delay 延迟执行时间。
  5965. *@param coverBefore 是否覆盖之前的缓动。
  5966. *@return 返回Tween对象。
  5967. */
  5968. __proto.from=function(target,props,duration,ease,complete,delay,coverBefore){
  5969. (delay===void 0)&& (delay=0);
  5970. (coverBefore===void 0)&& (coverBefore=false);
  5971. return this._create(target,props,duration,ease,complete,delay,coverBefore,false,false,true);
  5972. }
  5973. /**@private */
  5974. __proto._create=function(target,props,duration,ease,complete,delay,coverBefore,isTo,usePool,runNow){
  5975. if (!target)throw new Error("Tween:target is null");
  5976. this._target=target;
  5977. this._duration=duration;
  5978. this._ease=ease || props.ease || Tween.easeNone;
  5979. this._complete=complete || props.complete;
  5980. this._delay=delay;
  5981. this._props=[];
  5982. this._usedTimer=0;
  5983. this._startTimer=Browser.now();
  5984. this._usedPool=usePool;
  5985. this._delayParam=null;
  5986. this.update=props.update;
  5987. var gid=(target.$_GID || (target.$_GID=Utils.getGID()));
  5988. if (!Tween.tweenMap[gid]){
  5989. Tween.tweenMap[gid]=[this];
  5990. }else {
  5991. if (coverBefore)Tween.clearTween(target);
  5992. Tween.tweenMap[gid].push(this);
  5993. }
  5994. if (runNow){
  5995. if (delay <=0)this.firstStart(target,props,isTo);
  5996. else {
  5997. this._delayParam=[target,props,isTo];
  5998. Laya.timer.once(delay,this,this.firstStart,this._delayParam);
  5999. }
  6000. }else {
  6001. this._initProps(target,props,isTo);
  6002. }
  6003. return this;
  6004. }
  6005. __proto.firstStart=function(target,props,isTo){
  6006. this._delayParam=null;
  6007. if (target.destroyed){
  6008. this.clear();
  6009. return;
  6010. }
  6011. this._initProps(target,props,isTo);
  6012. this._beginLoop();
  6013. }
  6014. __proto._initProps=function(target,props,isTo){
  6015. for (var p in props){
  6016. if ((typeof (target[p])=='number')){
  6017. var start=isTo ? target[p] :props[p];
  6018. var end=isTo ? props[p] :target[p];
  6019. this._props.push([p,start,end-start]);
  6020. if (!isTo)target[p]=start;
  6021. }
  6022. }
  6023. }
  6024. __proto._beginLoop=function(){
  6025. Laya.timer.frameLoop(1,this,this._doEase);
  6026. }
  6027. /**执行缓动**/
  6028. __proto._doEase=function(){
  6029. this._updateEase(Browser.now());
  6030. }
  6031. /**@private */
  6032. __proto._updateEase=function(time){
  6033. var target=this._target;
  6034. if (!target)return;
  6035. if (target.destroyed)return Tween.clearTween(target);
  6036. var usedTimer=this._usedTimer=time-this._startTimer-this._delay;
  6037. if (usedTimer < 0)return;
  6038. if (usedTimer >=this._duration)return this.complete();
  6039. var ratio=usedTimer > 0 ? this._ease(usedTimer,0,1,this._duration):0;
  6040. var props=this._props;
  6041. for (var i=0,n=props.length;i < n;i++){
  6042. var prop=props[i];
  6043. target[prop[0]]=prop[1]+(ratio *prop[2]);
  6044. }
  6045. if (this.update)this.update.run();
  6046. }
  6047. /**
  6048. *立即结束缓动并到终点。
  6049. */
  6050. __proto.complete=function(){
  6051. if (!this._target)return;
  6052. Laya.timer.runTimer(this,this.firstStart);
  6053. var target=this._target;
  6054. var props=this._props;
  6055. var handler=this._complete;
  6056. for (var i=0,n=props.length;i < n;i++){
  6057. var prop=props[i];
  6058. target[prop[0]]=prop[1]+prop[2];
  6059. }
  6060. if (this.update)this.update.run();
  6061. this._count++;
  6062. if (this.repeat !=0 && this._count >=this.repeat){
  6063. this.clear();
  6064. handler && handler.run();
  6065. }else {
  6066. this.restart();
  6067. }
  6068. }
  6069. /**
  6070. *暂停缓动,可以通过resume或restart重新开始。
  6071. */
  6072. __proto.pause=function(){
  6073. Laya.timer.clear(this,this._beginLoop);
  6074. Laya.timer.clear(this,this._doEase);
  6075. Laya.timer.clear(this,this.firstStart);
  6076. var time=Browser.now();
  6077. var dTime=NaN;
  6078. dTime=time-this._startTimer-this._delay;
  6079. if (dTime < 0){
  6080. this._usedTimer=dTime;
  6081. }
  6082. }
  6083. /**
  6084. *设置开始时间。
  6085. *@param startTime 开始时间。
  6086. */
  6087. __proto.setStartTime=function(startTime){
  6088. this._startTimer=startTime;
  6089. }
  6090. /**
  6091. *停止并清理当前缓动。
  6092. */
  6093. __proto.clear=function(){
  6094. if (this._target){
  6095. this._remove();
  6096. this._clear();
  6097. }
  6098. }
  6099. /**
  6100. *@private
  6101. */
  6102. __proto._clear=function(){
  6103. this.pause();
  6104. Laya.timer.clear(this,this.firstStart);
  6105. this._complete=null;
  6106. this._target=null;
  6107. this._ease=null;
  6108. this._props=null;
  6109. this._delayParam=null;
  6110. if (this._usedPool){
  6111. this.update=null;
  6112. Pool.recover("tween",this);
  6113. }
  6114. }
  6115. /**回收到对象池。*/
  6116. __proto.recover=function(){
  6117. this._usedPool=true;
  6118. this._clear();
  6119. }
  6120. __proto._remove=function(){
  6121. var tweens=Tween.tweenMap[this._target.$_GID];
  6122. if (tweens){
  6123. for (var i=0,n=tweens.length;i < n;i++){
  6124. if (tweens[i]===this){
  6125. tweens.splice(i,1);
  6126. break ;
  6127. }
  6128. }
  6129. }
  6130. }
  6131. /**
  6132. *重新开始暂停的缓动。
  6133. */
  6134. __proto.restart=function(){
  6135. this.pause();
  6136. this._usedTimer=0;
  6137. this._startTimer=Browser.now();
  6138. if (this._delayParam){
  6139. Laya.timer.once(this._delay,this,this.firstStart,this._delayParam);
  6140. return;
  6141. };
  6142. var props=this._props;
  6143. for (var i=0,n=props.length;i < n;i++){
  6144. var prop=props[i];
  6145. this._target[prop[0]]=prop[1];
  6146. }
  6147. Laya.timer.once(this._delay,this,this._beginLoop);
  6148. }
  6149. /**
  6150. *恢复暂停的缓动。
  6151. */
  6152. __proto.resume=function(){
  6153. if (this._usedTimer >=this._duration)return;
  6154. this._startTimer=Browser.now()-this._usedTimer-this._delay;
  6155. if (this._delayParam){
  6156. if (this._usedTimer < 0){
  6157. Laya.timer.once(-this._usedTimer,this,this.firstStart,this._delayParam);
  6158. }else {
  6159. this.firstStart.apply(this,this._delayParam);
  6160. }
  6161. }else {
  6162. this._beginLoop();
  6163. }
  6164. }
  6165. /**设置当前执行比例**/
  6166. __getset(0,__proto,'progress',null,function(v){
  6167. var uTime=v *this._duration;
  6168. this._startTimer=Browser.now()-this._delay-uTime;
  6169. });
  6170. Tween.to=function(target,props,duration,ease,complete,delay,coverBefore,autoRecover){
  6171. (delay===void 0)&& (delay=0);
  6172. (coverBefore===void 0)&& (coverBefore=false);
  6173. (autoRecover===void 0)&& (autoRecover=true);
  6174. return Pool.getItemByClass("tween",Tween)._create(target,props,duration,ease,complete,delay,coverBefore,true,autoRecover,true);
  6175. }
  6176. Tween.from=function(target,props,duration,ease,complete,delay,coverBefore,autoRecover){
  6177. (delay===void 0)&& (delay=0);
  6178. (coverBefore===void 0)&& (coverBefore=false);
  6179. (autoRecover===void 0)&& (autoRecover=true);
  6180. return Pool.getItemByClass("tween",Tween)._create(target,props,duration,ease,complete,delay,coverBefore,false,autoRecover,true);
  6181. }
  6182. Tween.clearAll=function(target){
  6183. if (!target || !target.$_GID)return;
  6184. var tweens=Tween.tweenMap[target.$_GID];
  6185. if (tweens){
  6186. for (var i=0,n=tweens.length;i < n;i++){
  6187. tweens[i]._clear();
  6188. }
  6189. tweens.length=0;
  6190. }
  6191. }
  6192. Tween.clear=function(tween){
  6193. tween.clear();
  6194. }
  6195. Tween.clearTween=function(target){
  6196. Tween.clearAll(target);
  6197. }
  6198. Tween.easeNone=function(t,b,c,d){
  6199. return c *t / d+b;
  6200. }
  6201. Tween.tweenMap=[];
  6202. return Tween;
  6203. })()
  6204. /**
  6205. *绘制矩形
  6206. */
  6207. //class laya.display.cmd.DrawRectCmd
  6208. var DrawRectCmd=(function(){
  6209. function DrawRectCmd(){
  6210. /**
  6211. *开始绘制的 X 轴位置。
  6212. */
  6213. //this.x=NaN;
  6214. /**
  6215. *开始绘制的 Y 轴位置。
  6216. */
  6217. //this.y=NaN;
  6218. /**
  6219. *矩形宽度。
  6220. */
  6221. //this.width=NaN;
  6222. /**
  6223. *矩形高度。
  6224. */
  6225. //this.height=NaN;
  6226. /**
  6227. *填充颜色,或者填充绘图的渐变对象。
  6228. */
  6229. //this.fillColor=null;
  6230. /**
  6231. *(可选)边框颜色,或者填充绘图的渐变对象。
  6232. */
  6233. //this.lineColor=null;
  6234. /**
  6235. *(可选)边框宽度。
  6236. */
  6237. //this.lineWidth=NaN;
  6238. }
  6239. __class(DrawRectCmd,'laya.display.cmd.DrawRectCmd');
  6240. var __proto=DrawRectCmd.prototype;
  6241. /**
  6242. *回收到对象池
  6243. */
  6244. __proto.recover=function(){
  6245. this.fillColor=null;
  6246. this.lineColor=null;
  6247. Pool.recover("DrawRectCmd",this);
  6248. }
  6249. /**@private */
  6250. __proto.run=function(context,gx,gy){
  6251. context.drawRect(this.x+gx,this.y+gy,this.width,this.height,this.fillColor,this.lineColor,this.lineWidth);
  6252. }
  6253. /**@private */
  6254. __getset(0,__proto,'cmdID',function(){
  6255. return "DrawRect";
  6256. });
  6257. DrawRectCmd.create=function(x,y,width,height,fillColor,lineColor,lineWidth){
  6258. var cmd=Pool.getItemByClass("DrawRectCmd",DrawRectCmd);
  6259. cmd.x=x;
  6260. cmd.y=y;
  6261. cmd.width=width;
  6262. cmd.height=height;
  6263. cmd.fillColor=fillColor;
  6264. cmd.lineColor=lineColor;
  6265. cmd.lineWidth=lineWidth;
  6266. return cmd;
  6267. }
  6268. DrawRectCmd.ID="DrawRect";
  6269. return DrawRectCmd;
  6270. })()
  6271. //class laya.webgl.shapes.EarcutNode
  6272. var EarcutNode=(function(){
  6273. function EarcutNode(i,x,y){
  6274. this.i=null;
  6275. this.x=null;
  6276. this.y=null;
  6277. this.prev=null;
  6278. this.next=null;
  6279. this.z=null;
  6280. this.prevZ=null;
  6281. this.nextZ=null;
  6282. this.steiner=null;
  6283. this.i=i;
  6284. this.x=x;
  6285. this.y=y;
  6286. this.prev=null;
  6287. this.next=null;
  6288. this.z=null;
  6289. this.prevZ=null;
  6290. this.nextZ=null;
  6291. this.steiner=false;
  6292. }
  6293. __class(EarcutNode,'laya.webgl.shapes.EarcutNode');
  6294. return EarcutNode;
  6295. })()
  6296. //class laya.webgl.submit.SubmitCMD
  6297. var SubmitCMD=(function(){
  6298. function SubmitCMD(){
  6299. this.fun=null;
  6300. this._this=null;
  6301. this.args=null;
  6302. this._ref=1;
  6303. this._key=new SubmitKey();
  6304. }
  6305. __class(SubmitCMD,'laya.webgl.submit.SubmitCMD');
  6306. var __proto=SubmitCMD.prototype;
  6307. Laya.imps(__proto,{"laya.webgl.submit.ISubmit":true})
  6308. __proto.renderSubmit=function(){
  6309. this.fun.apply(this._this,this.args);
  6310. return 1;
  6311. }
  6312. //TODO:coverage
  6313. __proto.getRenderType=function(){
  6314. return 0;
  6315. }
  6316. //TODO:coverage
  6317. __proto.reUse=function(context,pos){
  6318. this._ref++;
  6319. return pos;
  6320. }
  6321. __proto.releaseRender=function(){
  6322. if((--this._ref)<1){
  6323. var pool=SubmitCMD.POOL;
  6324. pool[pool._length++]=this;
  6325. }
  6326. }
  6327. //TODO:coverage
  6328. __proto.clone=function(context,mesh,pos){
  6329. return null;
  6330. }
  6331. SubmitCMD.create=function(args,fun,thisobj){
  6332. var o=SubmitCMD.POOL._length?SubmitCMD.POOL[--SubmitCMD.POOL._length]:new SubmitCMD();
  6333. o.fun=fun;
  6334. o.args=args;
  6335. o._this=thisobj;
  6336. o._ref=1;
  6337. o._key.clear();
  6338. return o;
  6339. }
  6340. SubmitCMD.POOL=[];
  6341. SubmitCMD.__init$=function(){
  6342. {SubmitCMD.POOL._length=0 };
  6343. }
  6344. return SubmitCMD;
  6345. })()
  6346. /**
  6347. *<p><code>URL</code> 提供URL格式化,URL版本管理的类。</p>
  6348. *<p>引擎加载资源的时候,会自动调用formatURL函数格式化URL路径</p>
  6349. *<p>通过basePath属性可以设置网络基础路径</p>
  6350. *<p>通过设置customFormat函数,可以自定义URL格式化的方式</p>
  6351. *<p>除了默认的通过增加后缀的格式化外,通过VersionManager类,可以开启IDE提供的,基于目录的管理方式来替代 "?v=" 的管理方式</p>
  6352. *@see laya.net.VersionManager
  6353. */
  6354. //class laya.net.URL
  6355. var URL=(function(){
  6356. function URL(url){
  6357. /**@private */
  6358. this._url=null;
  6359. /**@private */
  6360. this._path=null;
  6361. this._url=URL.formatURL(url);
  6362. this._path=URL.getPath(url);
  6363. }
  6364. __class(URL,'laya.net.URL');
  6365. var __proto=URL.prototype;
  6366. /**地址的文件夹路径(不包括文件名)。*/
  6367. __getset(0,__proto,'path',function(){
  6368. return this._path;
  6369. });
  6370. /**格式化后的地址。*/
  6371. __getset(0,__proto,'url',function(){
  6372. return this._url;
  6373. });
  6374. /**基础路径。如果不设置,默认为当前网页的路径。最终地址将被格式化为 basePath+相对URL地址,*/
  6375. __getset(1,URL,'basePath',function(){
  6376. return URL._basePath;
  6377. },function(value){
  6378. URL._basePath=Laya._getUrlPath();
  6379. URL._basePath=URL.formatURL(value);
  6380. });
  6381. URL.formatURL=function(url){
  6382. if (!url)return "null path";
  6383. if (url.indexOf(":")> 0)return url;
  6384. if (URL.customFormat !=null)url=URL.customFormat(url);
  6385. if (url.indexOf(":")> 0)return url;
  6386. var char1=url.charAt(0);
  6387. if (char1==="."){
  6388. return URL._formatRelativePath(URL._basePath+url);
  6389. }else if (char1==='~'){
  6390. return URL.rootPath+url.substring(1);
  6391. }else if (char1==="d"){
  6392. if (url.indexOf("data:image")===0)return url;
  6393. }else if (char1==="/"){
  6394. return url;
  6395. }
  6396. return URL._basePath+url;
  6397. }
  6398. URL._formatRelativePath=function(value){
  6399. var parts=value.split("/");
  6400. for (var i=0,len=parts.length;i < len;i++){
  6401. if (parts[i]=='..'){
  6402. parts.splice(i-1,2);
  6403. i-=2;
  6404. }
  6405. }
  6406. return parts.join('/');
  6407. }
  6408. URL.getPath=function(url){
  6409. var ofs=url.lastIndexOf('/');
  6410. return ofs > 0 ? url.substr(0,ofs+1):"";
  6411. }
  6412. URL.getFileName=function(url){
  6413. var ofs=url.lastIndexOf('/');
  6414. return ofs > 0 ? url.substr(ofs+1):url;
  6415. }
  6416. URL.getAdptedFilePath=function(url){
  6417. if (!URL.exportSceneToJson || !url)return url;
  6418. var i=0,len=0;
  6419. len=URL._adpteTypeList.length;
  6420. var tArr;
  6421. for (i=0;i < len;i++){
  6422. tArr=URL._adpteTypeList[i];
  6423. url=url.replace(tArr[0],tArr[1]);
  6424. }
  6425. return url;
  6426. }
  6427. URL.version={};
  6428. URL.exportSceneToJson=false;
  6429. URL._basePath="";
  6430. URL.rootPath="";
  6431. URL.customFormat=function(url){
  6432. var newUrl=URL.version[url];
  6433. if (!Render.isConchApp && newUrl)url+="?v="+newUrl;
  6434. return url;
  6435. }
  6436. __static(URL,
  6437. ['_adpteTypeList',function(){return this._adpteTypeList=[[".scene3d",".json"],[".scene",".json"],[".taa",".json"],[".prefab",".json"]];}
  6438. ]);
  6439. return URL;
  6440. })()
  6441. /**
  6442. *@private
  6443. *对象缓存统一管理类
  6444. */
  6445. //class laya.utils.CacheManger
  6446. var CacheManger=(function(){
  6447. function CacheManger(){}
  6448. __class(CacheManger,'laya.utils.CacheManger');
  6449. CacheManger.regCacheByFunction=function(disposeFunction,getCacheListFunction){
  6450. CacheManger.unRegCacheByFunction(disposeFunction,getCacheListFunction);
  6451. var cache;
  6452. cache={tryDispose:disposeFunction,getCacheList:getCacheListFunction};
  6453. CacheManger._cacheList.push(cache);
  6454. }
  6455. CacheManger.unRegCacheByFunction=function(disposeFunction,getCacheListFunction){
  6456. var i=0,len=0;
  6457. len=CacheManger._cacheList.length;
  6458. for (i=0;i < len;i++){
  6459. if (CacheManger._cacheList[i].tryDispose==disposeFunction && CacheManger._cacheList[i].getCacheList==getCacheListFunction){
  6460. CacheManger._cacheList.splice(i,1);
  6461. return;
  6462. }
  6463. }
  6464. }
  6465. CacheManger.forceDispose=function(){
  6466. var i=0,len=CacheManger._cacheList.length;
  6467. for (i=0;i < len;i++){
  6468. CacheManger._cacheList[i].tryDispose(true);
  6469. }
  6470. }
  6471. CacheManger.beginCheck=function(waitTime){
  6472. (waitTime===void 0)&& (waitTime=15000);
  6473. Laya.systemTimer.loop(waitTime,null,CacheManger._checkLoop);
  6474. }
  6475. CacheManger.stopCheck=function(){
  6476. Laya.systemTimer.clear(null,CacheManger._checkLoop);
  6477. }
  6478. CacheManger._checkLoop=function(){
  6479. var cacheList=CacheManger._cacheList;
  6480. if (cacheList.length < 1)return;
  6481. var tTime=Browser.now();
  6482. var count=0;
  6483. var len=0;
  6484. len=count=cacheList.length;
  6485. while (count > 0){
  6486. CacheManger._index++;
  6487. CacheManger._index=CacheManger._index % len;
  6488. cacheList[CacheManger._index].tryDispose(false);
  6489. if (Browser.now()-tTime > CacheManger.loopTimeLimit)break ;
  6490. count--;
  6491. }
  6492. }
  6493. CacheManger.loopTimeLimit=2;
  6494. CacheManger._cacheList=[];
  6495. CacheManger._index=0;
  6496. return CacheManger;
  6497. })()
  6498. /**
  6499. *@private
  6500. *元素样式
  6501. */
  6502. //class laya.display.css.SpriteStyle
  6503. var SpriteStyle=(function(){
  6504. function SpriteStyle(){
  6505. //this.scaleX=NaN;
  6506. //this.scaleY=NaN;
  6507. //this.skewX=NaN;
  6508. //this.skewY=NaN;
  6509. //this.pivotX=NaN;
  6510. //this.pivotY=NaN;
  6511. //this.rotation=NaN;
  6512. //this.alpha=NaN;
  6513. //this.scrollRect=null;
  6514. //this.viewport=null;
  6515. //this.hitArea=null;
  6516. //this.dragging=null;
  6517. //this.blendMode=null;
  6518. this.reset();
  6519. }
  6520. __class(SpriteStyle,'laya.display.css.SpriteStyle');
  6521. var __proto=SpriteStyle.prototype;
  6522. /**
  6523. *重置,方便下次复用
  6524. */
  6525. __proto.reset=function(){
  6526. this.scaleX=this.scaleY=1;
  6527. this.skewX=this.skewY=0;
  6528. this.pivotX=this.pivotY=this.rotation=0;
  6529. this.alpha=1;
  6530. if(this.scrollRect)this.scrollRect.recover();
  6531. this.scrollRect=null;
  6532. if(this.viewport)this.viewport.recover();
  6533. this.viewport=null;
  6534. this.hitArea=null;
  6535. this.dragging=null;
  6536. this.blendMode=null;
  6537. return this
  6538. }
  6539. /**
  6540. *回收
  6541. */
  6542. __proto.recover=function(){
  6543. if (this===SpriteStyle.EMPTY)return;
  6544. Pool.recover("SpriteStyle",this.reset());
  6545. }
  6546. SpriteStyle.create=function(){
  6547. return Pool.getItemByClass("SpriteStyle",SpriteStyle);
  6548. }
  6549. SpriteStyle.EMPTY=new SpriteStyle();
  6550. return SpriteStyle;
  6551. })()
  6552. /**
  6553. *对象 cacheas normal的时候,本质上只是想把submit缓存起来,以后直接执行
  6554. *为了避免各种各样的麻烦,这里采用复制相应部分的submit的方法。执行环境还是在原来的context中
  6555. *否则包括clip等都非常难以处理
  6556. */
  6557. //class laya.webgl.canvas.WebGLCacheAsNormalCanvas
  6558. var WebGLCacheAsNormalCanvas=(function(){
  6559. function WebGLCacheAsNormalCanvas(ctx,sp){
  6560. this.submitStartPos=0;
  6561. // 对应的context的submit的开始的地方
  6562. this.submitEndPos=0;
  6563. this.context=null;
  6564. this.touches=[];
  6565. //记录的文字信息。cacheas normal的话,文字要能正确touch
  6566. this.submits=[];
  6567. // 从context中剪切的submit
  6568. this.sprite=null;
  6569. // submit需要关联稳定独立的mesh。所以这里要创建自己的mesh对象
  6570. this._mesh=null;
  6571. //用Mesh2D代替_vb,_ib. 当前使用的mesh
  6572. this._pathMesh=null;
  6573. //矢量专用mesh。
  6574. this._triangleMesh=null;
  6575. //drawTriangles专用mesh。由于ib不固定,所以不能与_mesh通用
  6576. this.meshlist=[];
  6577. // 原始context的原始值
  6578. this._oldMesh=null;
  6579. this._oldPathMesh=null;
  6580. this._oldTriMesh=null;
  6581. this._oldMeshList=null;
  6582. //private var oldMatrix:Matrix=null;//本地画的时候完全不应用矩阵,所以需要先保存老的,以便恢复 这样会丢失缩放信息,导致文字模糊,所以不用这种方式了
  6583. this.oldTx=0;
  6584. this.oldTy=0;
  6585. this.cachedClipInfo=new Matrix();
  6586. this.invMat=new Matrix();
  6587. this.context=ctx;
  6588. this.sprite=sp;
  6589. ctx._globalClipMatrix.copyTo(this.cachedClipInfo);
  6590. }
  6591. __class(WebGLCacheAsNormalCanvas,'laya.webgl.canvas.WebGLCacheAsNormalCanvas');
  6592. var __proto=WebGLCacheAsNormalCanvas.prototype;
  6593. __proto.startRec=function(){
  6594. if (this.context._charSubmitCache._enbale){
  6595. this.context._charSubmitCache.enable(false,this.context);
  6596. this.context._charSubmitCache.enable(true,this.context);
  6597. }
  6598. this.context._incache=true;
  6599. this.touches.length=0;
  6600. (this.context).touches=this.touches;
  6601. this.context._globalClipMatrix.copyTo(this.cachedClipInfo);
  6602. this.submits.length=0;
  6603. this.submitStartPos=this.context._submits._length;
  6604. for (var i=0,sz=this.meshlist.length;i < sz;i++){
  6605. var curm=this.meshlist[i];
  6606. curm.canReuse?(curm.releaseMesh()):(curm.destroy());
  6607. }
  6608. this.meshlist.length=0;
  6609. this._mesh=MeshQuadTexture.getAMesh(false);
  6610. this._pathMesh=MeshVG.getAMesh(false);
  6611. this._triangleMesh=MeshTexture.getAMesh(false);
  6612. this.meshlist.push(this._mesh);
  6613. this.meshlist.push(this._pathMesh);
  6614. this.meshlist.push(this._triangleMesh);
  6615. this.context._curSubmit=Submit.RENDERBASE;
  6616. this._oldMesh=this.context._mesh;
  6617. this._oldPathMesh=this.context._pathMesh;
  6618. this._oldTriMesh=this.context._triangleMesh;
  6619. this._oldMeshList=this.context.meshlist;
  6620. this.context._mesh=this._mesh;
  6621. this.context._pathMesh=this._pathMesh;
  6622. this.context._triangleMesh=this._triangleMesh;
  6623. this.context.meshlist=this.meshlist;
  6624. this.oldTx=this.context._curMat.tx;
  6625. this.oldTy=this.context._curMat.ty;
  6626. this.context._curMat.tx=0;
  6627. this.context._curMat.ty=0;
  6628. this.context._curMat.copyTo(this.invMat);
  6629. this.invMat.invert();
  6630. }
  6631. //context._curMat=matI;
  6632. __proto.endRec=function(){
  6633. if (this.context._charSubmitCache._enbale){
  6634. this.context._charSubmitCache.enable(false,this.context);
  6635. this.context._charSubmitCache.enable(true,this.context);
  6636. };
  6637. var parsubmits=this.context._submits;
  6638. this.submitEndPos=parsubmits._length;
  6639. var num=this.submitEndPos-this.submitStartPos;
  6640. for (var i=0;i < num;i++){
  6641. this.submits.push(parsubmits[this.submitStartPos+i]);
  6642. }
  6643. parsubmits._length-=num;
  6644. this.context._mesh=this._oldMesh;
  6645. this.context._pathMesh=this._oldPathMesh;
  6646. this.context._triangleMesh=this._oldTriMesh;
  6647. this.context.meshlist=this._oldMeshList;
  6648. this.context._curSubmit=Submit.RENDERBASE;
  6649. this.context._curMat.tx=this.oldTx;
  6650. this.context._curMat.ty=this.oldTy;
  6651. (this.context).touches=null;
  6652. this.context._incache=false;
  6653. }
  6654. /**
  6655. *当前缓存是否还有效。例如clip变了就失效了,因为clip太难自动处理
  6656. *@return
  6657. */
  6658. __proto.isCacheValid=function(){
  6659. var curclip=this.context._globalClipMatrix;
  6660. if (curclip.a !=this.cachedClipInfo.a || curclip.b !=this.cachedClipInfo.b || curclip.c !=this.cachedClipInfo.c
  6661. || curclip.d !=this.cachedClipInfo.d || curclip.tx !=this.cachedClipInfo.tx || curclip.ty !=this.cachedClipInfo.ty)
  6662. return false;
  6663. return true;
  6664. }
  6665. __proto.flushsubmit=function(){
  6666. var curSubmit=Submit.RENDERBASE;
  6667. this.submits.forEach(function(subm){
  6668. if (subm==Submit.RENDERBASE)return;
  6669. Submit.preRender=curSubmit;
  6670. curSubmit=subm;
  6671. subm.renderSubmit();
  6672. });
  6673. }
  6674. __proto.releaseMem=function(){}
  6675. __static(WebGLCacheAsNormalCanvas,
  6676. ['matI',function(){return this.matI=new Matrix();}
  6677. ]);
  6678. return WebGLCacheAsNormalCanvas;
  6679. })()
  6680. /**
  6681. *<code>Timer</code> 是时钟管理类。它是一个单例,不要手动实例化此类,应该通过 Laya.timer 访问。
  6682. */
  6683. //class laya.utils.Timer
  6684. var Timer=(function(){
  6685. var TimerHandler;
  6686. function Timer(autoActive){
  6687. /**时针缩放。*/
  6688. this.scale=1;
  6689. /**当前的帧数。*/
  6690. this.currFrame=0;
  6691. /**@private 两帧之间的时间间隔,单位毫秒。*/
  6692. this._delta=0;
  6693. /**@private */
  6694. this._map=[];
  6695. /**@private */
  6696. this._handlers=[];
  6697. /**@private */
  6698. this._temp=[];
  6699. /**@private */
  6700. this._count=0;
  6701. this.currTimer=Browser.now();
  6702. this._lastTimer=Browser.now();
  6703. (autoActive===void 0)&& (autoActive=true);
  6704. autoActive && Laya.systemTimer && Laya.systemTimer.frameLoop(1,this,this._update);
  6705. }
  6706. __class(Timer,'laya.utils.Timer');
  6707. var __proto=Timer.prototype;
  6708. /**
  6709. *@private
  6710. *帧循环处理函数。
  6711. */
  6712. __proto._update=function(){
  6713. if (this.scale <=0){
  6714. this._lastTimer=Browser.now();
  6715. return;
  6716. };
  6717. var frame=this.currFrame=this.currFrame+this.scale;
  6718. var now=Browser.now();
  6719. this._delta=(now-this._lastTimer)*this.scale;
  6720. var timer=this.currTimer=this.currTimer+this._delta;
  6721. this._lastTimer=now;
  6722. var handlers=this._handlers;
  6723. this._count=0;
  6724. for (var i=0,n=handlers.length;i < n;i++){
  6725. var handler=handlers[i];
  6726. if (handler.method!==null){
  6727. var t=handler.userFrame ? frame :timer;
  6728. if (t >=handler.exeTime){
  6729. if (handler.repeat){
  6730. if (!handler.jumpFrame){
  6731. handler.exeTime+=handler.delay;
  6732. handler.run(false);
  6733. if (t > handler.exeTime){
  6734. handler.exeTime+=Math.ceil((t-handler.exeTime)/ handler.delay)*handler.delay;
  6735. }
  6736. }else {
  6737. while (t >=handler.exeTime){
  6738. handler.exeTime+=handler.delay;
  6739. handler.run(false);
  6740. }
  6741. }
  6742. }else {
  6743. handler.run(true);
  6744. }
  6745. }
  6746. }else {
  6747. this._count++;
  6748. }
  6749. }
  6750. if (this._count > 30 || frame % 200===0)this._clearHandlers();
  6751. }
  6752. /**@private */
  6753. __proto._clearHandlers=function(){
  6754. var handlers=this._handlers;
  6755. for (var i=0,n=handlers.length;i < n;i++){
  6756. var handler=handlers[i];
  6757. if (handler.method!==null)this._temp.push(handler);
  6758. else this._recoverHandler(handler);
  6759. }
  6760. this._handlers=this._temp;
  6761. handlers.length=0;
  6762. this._temp=handlers;
  6763. }
  6764. /**@private */
  6765. __proto._recoverHandler=function(handler){
  6766. if (this._map[handler.key]==handler)this._map[handler.key]=null;
  6767. handler.clear();
  6768. Timer._pool.push(handler);
  6769. }
  6770. /**@private */
  6771. __proto._create=function(useFrame,repeat,delay,caller,method,args,coverBefore){
  6772. if (!delay){
  6773. method.apply(caller,args);
  6774. return null;
  6775. }
  6776. if (coverBefore){
  6777. var handler=this._getHandler(caller,method);
  6778. if (handler){
  6779. handler.repeat=repeat;
  6780. handler.userFrame=useFrame;
  6781. handler.delay=delay;
  6782. handler.caller=caller;
  6783. handler.method=method;
  6784. handler.args=args;
  6785. handler.exeTime=delay+(useFrame ? this.currFrame :this.currTimer+Browser.now()-this._lastTimer);
  6786. return handler;
  6787. }
  6788. }
  6789. handler=Timer._pool.length > 0 ? Timer._pool.pop():new TimerHandler();
  6790. handler.repeat=repeat;
  6791. handler.userFrame=useFrame;
  6792. handler.delay=delay;
  6793. handler.caller=caller;
  6794. handler.method=method;
  6795. handler.args=args;
  6796. handler.exeTime=delay+(useFrame ? this.currFrame :this.currTimer+Browser.now()-this._lastTimer);
  6797. this._indexHandler(handler);
  6798. this._handlers.push(handler);
  6799. return handler;
  6800. }
  6801. /**@private */
  6802. __proto._indexHandler=function(handler){
  6803. var caller=handler.caller;
  6804. var method=handler.method;
  6805. var cid=caller ? caller.$_GID || (caller.$_GID=Utils.getGID()):0;
  6806. var mid=method.$_TID || (method.$_TID=(Timer._mid++)*100000);
  6807. handler.key=cid+mid;
  6808. this._map[handler.key]=handler;
  6809. }
  6810. /**
  6811. *定时执行一次。
  6812. *@param delay 延迟时间(单位为毫秒)。
  6813. *@param caller 执行域(this)。
  6814. *@param method 定时器回调函数。
  6815. *@param args 回调参数。
  6816. *@param coverBefore 是否覆盖之前的延迟执行,默认为 true 。
  6817. */
  6818. __proto.once=function(delay,caller,method,args,coverBefore){
  6819. (coverBefore===void 0)&& (coverBefore=true);
  6820. this._create(false,false,delay,caller,method,args,coverBefore);
  6821. }
  6822. /**
  6823. *定时重复执行。
  6824. *@param delay 间隔时间(单位毫秒)。
  6825. *@param caller 执行域(this)。
  6826. *@param method 定时器回调函数。
  6827. *@param args 回调参数。
  6828. *@param coverBefore 是否覆盖之前的延迟执行,默认为 true 。
  6829. *@param jumpFrame 时钟是否跳帧。基于时间的循环回调,单位时间间隔内,如能执行多次回调,出于性能考虑,引擎默认只执行一次,设置jumpFrame=true后,则回调会连续执行多次
  6830. */
  6831. __proto.loop=function(delay,caller,method,args,coverBefore,jumpFrame){
  6832. (coverBefore===void 0)&& (coverBefore=true);
  6833. (jumpFrame===void 0)&& (jumpFrame=false);
  6834. var handler=this._create(false,true,delay,caller,method,args,coverBefore);
  6835. if (handler)handler.jumpFrame=jumpFrame;
  6836. }
  6837. /**
  6838. *定时执行一次(基于帧率)。
  6839. *@param delay 延迟几帧(单位为帧)。
  6840. *@param caller 执行域(this)。
  6841. *@param method 定时器回调函数。
  6842. *@param args 回调参数。
  6843. *@param coverBefore 是否覆盖之前的延迟执行,默认为 true 。
  6844. */
  6845. __proto.frameOnce=function(delay,caller,method,args,coverBefore){
  6846. (coverBefore===void 0)&& (coverBefore=true);
  6847. this._create(true,false,delay,caller,method,args,coverBefore);
  6848. }
  6849. /**
  6850. *定时重复执行(基于帧率)。
  6851. *@param delay 间隔几帧(单位为帧)。
  6852. *@param caller 执行域(this)。
  6853. *@param method 定时器回调函数。
  6854. *@param args 回调参数。
  6855. *@param coverBefore 是否覆盖之前的延迟执行,默认为 true 。
  6856. */
  6857. __proto.frameLoop=function(delay,caller,method,args,coverBefore){
  6858. (coverBefore===void 0)&& (coverBefore=true);
  6859. this._create(true,true,delay,caller,method,args,coverBefore);
  6860. }
  6861. /**返回统计信息。*/
  6862. __proto.toString=function(){
  6863. return " handlers:"+this._handlers.length+" pool:"+Timer._pool.length;
  6864. }
  6865. /**
  6866. *清理定时器。
  6867. *@param caller 执行域(this)。
  6868. *@param method 定时器回调函数。
  6869. */
  6870. __proto.clear=function(caller,method){
  6871. var handler=this._getHandler(caller,method);
  6872. if (handler){
  6873. this._map[handler.key]=null;
  6874. handler.key=0;
  6875. handler.clear();
  6876. }
  6877. }
  6878. /**
  6879. *清理对象身上的所有定时器。
  6880. *@param caller 执行域(this)。
  6881. */
  6882. __proto.clearAll=function(caller){
  6883. if (!caller)return;
  6884. for (var i=0,n=this._handlers.length;i < n;i++){
  6885. var handler=this._handlers[i];
  6886. if (handler.caller===caller){
  6887. this._map[handler.key]=null;
  6888. handler.key=0;
  6889. handler.clear();
  6890. }
  6891. }
  6892. }
  6893. /**@private */
  6894. __proto._getHandler=function(caller,method){
  6895. var cid=caller ? caller.$_GID || (caller.$_GID=Utils.getGID()):0;
  6896. var mid=method.$_TID || (method.$_TID=(Timer._mid++)*100000);
  6897. return this._map[cid+mid];
  6898. }
  6899. /**
  6900. *延迟执行。
  6901. *@param caller 执行域(this)。
  6902. *@param method 定时器回调函数。
  6903. *@param args 回调参数。
  6904. */
  6905. __proto.callLater=function(caller,method,args){
  6906. CallLater.I.callLater(caller,method,args);
  6907. }
  6908. /**
  6909. *立即执行 callLater 。
  6910. *@param caller 执行域(this)。
  6911. *@param method 定时器回调函数。
  6912. */
  6913. __proto.runCallLater=function(caller,method){
  6914. CallLater.I.runCallLater(caller,method);
  6915. }
  6916. /**
  6917. *立即提前执行定时器,执行之后从队列中删除
  6918. *@param caller 执行域(this)。
  6919. *@param method 定时器回调函数。
  6920. */
  6921. __proto.runTimer=function(caller,method){
  6922. var handler=this._getHandler(caller,method);
  6923. if (handler && handler.method !=null){
  6924. this._map[handler.key]=null;
  6925. handler.run(true);
  6926. }
  6927. }
  6928. /**
  6929. *暂停时钟
  6930. */
  6931. __proto.pause=function(){
  6932. this.scale=0;
  6933. }
  6934. /**
  6935. *恢复时钟
  6936. */
  6937. __proto.resume=function(){
  6938. this.scale=1;
  6939. }
  6940. /**两帧之间的时间间隔,单位毫秒。*/
  6941. __getset(0,__proto,'delta',function(){
  6942. return this._delta;
  6943. });
  6944. Timer._pool=[];
  6945. Timer._mid=1;
  6946. Timer.__init$=function(){
  6947. /**@private */
  6948. //class TimerHandler
  6949. TimerHandler=(function(){
  6950. function TimerHandler(){
  6951. this.key=0;
  6952. this.repeat=false;
  6953. this.delay=0;
  6954. this.userFrame=false;
  6955. this.exeTime=0;
  6956. this.caller=null;
  6957. this.method=null;
  6958. this.args=null;
  6959. this.jumpFrame=false;
  6960. }
  6961. __class(TimerHandler,'');
  6962. var __proto=TimerHandler.prototype;
  6963. __proto.clear=function(){
  6964. this.caller=null;
  6965. this.method=null;
  6966. this.args=null;
  6967. }
  6968. __proto.run=function(withClear){
  6969. var caller=this.caller;
  6970. if (caller && caller.destroyed)return this.clear();
  6971. var method=this.method;
  6972. var args=this.args;
  6973. withClear && this.clear();
  6974. if (method==null)return;
  6975. args ? method.apply(caller,args):method.call(caller);
  6976. }
  6977. return TimerHandler;
  6978. })()
  6979. }
  6980. return Timer;
  6981. })()
  6982. /**
  6983. *@private
  6984. *存储cache相关
  6985. */
  6986. //class laya.display.css.CacheStyle
  6987. var CacheStyle=(function(){
  6988. function CacheStyle(){
  6989. /**当前实际的cache状态*/
  6990. //this.cacheAs=null;
  6991. /**是否开启canvas渲染*/
  6992. //this.enableCanvasRender=false;
  6993. /**用户设的cacheAs类型*/
  6994. //this.userSetCache=null;
  6995. /**是否需要为滤镜cache*/
  6996. //this.cacheForFilters=false;
  6997. /**是否为静态缓存*/
  6998. //this.staticCache=false;
  6999. /**是否需要刷新缓存*/
  7000. //this.reCache=false;
  7001. /**mask对象*/
  7002. //this.mask=null;
  7003. /**作为mask时的父对象*/
  7004. //this.maskParent=null;
  7005. /**滤镜数据*/
  7006. //this.filters=null;
  7007. /**当前缓存区域*/
  7008. //this.cacheRect=null;
  7009. /**当前使用的canvas*/
  7010. //this.canvas=null;
  7011. /**滤镜数据*/
  7012. //this.filterCache=null;
  7013. /**是否有发光滤镜*/
  7014. //this.hasGlowFilter=false;
  7015. this.reset();
  7016. }
  7017. __class(CacheStyle,'laya.display.css.CacheStyle');
  7018. var __proto=CacheStyle.prototype;
  7019. /**
  7020. *是否需要Bitmap缓存
  7021. *@return
  7022. */
  7023. __proto.needBitmapCache=function(){
  7024. return this.cacheForFilters || !!this.mask;
  7025. }
  7026. /**
  7027. *是否需要开启canvas渲染
  7028. */
  7029. __proto.needEnableCanvasRender=function(){
  7030. return this.userSetCache !="none" || this.cacheForFilters || !!this.mask;
  7031. }
  7032. /**
  7033. *释放cache的资源
  7034. */
  7035. __proto.releaseContext=function(){
  7036. if (this.canvas && (this.canvas).size){
  7037. Pool.recover("CacheCanvas",this.canvas);
  7038. this.canvas.size(0,0);
  7039. (this.canvas).width=0;
  7040. (this.canvas).height=0;
  7041. }
  7042. this.canvas=null;
  7043. }
  7044. __proto.createContext=function(){
  7045. if (!this.canvas){
  7046. this.canvas=Pool.getItem("CacheCanvas")|| new HTMLCanvas(false);
  7047. var tx=this.canvas.context;
  7048. if (!tx){
  7049. tx=this.canvas.getContext('2d');
  7050. }
  7051. }
  7052. }
  7053. /**
  7054. *释放滤镜资源
  7055. */
  7056. __proto.releaseFilterCache=function(){
  7057. var fc=this.filterCache;
  7058. if (fc){
  7059. fc.destroy();
  7060. fc.recycle();
  7061. this.filterCache=null;
  7062. }
  7063. }
  7064. /**
  7065. *回收
  7066. */
  7067. __proto.recover=function(){
  7068. if (this===CacheStyle.EMPTY)return;
  7069. Pool.recover("SpriteCache",this.reset());
  7070. }
  7071. /**
  7072. *重置
  7073. */
  7074. __proto.reset=function(){
  7075. this.releaseContext();
  7076. this.releaseFilterCache();
  7077. this.cacheAs="none";
  7078. this.enableCanvasRender=false;
  7079. this.userSetCache="none";
  7080. this.cacheForFilters=false;
  7081. this.staticCache=false;
  7082. this.reCache=true;
  7083. this.mask=null;
  7084. this.maskParent=null;
  7085. this.filterCache=null;
  7086. this.filters=null;
  7087. this.hasGlowFilter=false;
  7088. if(this.cacheRect)this.cacheRect.recover();
  7089. this.cacheRect=null;
  7090. return this
  7091. }
  7092. __proto._calculateCacheRect=function(sprite,tCacheType,x,y){
  7093. var _cacheStyle=sprite._cacheStyle;
  7094. if (!_cacheStyle.cacheRect)
  7095. _cacheStyle.cacheRect=Rectangle.create();
  7096. var tRec;
  7097. if (tCacheType==="bitmap"){
  7098. tRec=sprite.getSelfBounds();
  7099. tRec.width=tRec.width+16*2;
  7100. tRec.height=tRec.height+16*2;
  7101. tRec.x=tRec.x-sprite.pivotX;
  7102. tRec.y=tRec.y-sprite.pivotY;
  7103. tRec.x=tRec.x-16;
  7104. tRec.y=tRec.y-16;
  7105. tRec.x=Math.floor(tRec.x+x)-x;
  7106. tRec.y=Math.floor(tRec.y+y)-y;
  7107. tRec.width=Math.floor(tRec.width);
  7108. tRec.height=Math.floor(tRec.height);
  7109. _cacheStyle.cacheRect.copyFrom(tRec);
  7110. }else {
  7111. _cacheStyle.cacheRect.setTo(-sprite._style.pivotX,-sprite._style.pivotY,1,1);
  7112. }
  7113. tRec=_cacheStyle.cacheRect;
  7114. if (sprite._style.scrollRect){
  7115. var scrollRect=sprite._style.scrollRect;
  7116. tRec.x-=scrollRect.x;
  7117. tRec.y-=scrollRect.y;
  7118. }
  7119. CacheStyle._scaleInfo.setTo(1,1);
  7120. return CacheStyle._scaleInfo;
  7121. }
  7122. CacheStyle.create=function(){
  7123. return Pool.getItemByClass("SpriteCache",CacheStyle);
  7124. }
  7125. CacheStyle.EMPTY=new CacheStyle();
  7126. CacheStyle.CANVAS_EXTEND_EDGE=16;
  7127. __static(CacheStyle,
  7128. ['_scaleInfo',function(){return this._scaleInfo=new Point();}
  7129. ]);
  7130. return CacheStyle;
  7131. })()
  7132. //class laya.webgl.canvas.save.SaveTranslate
  7133. var SaveTranslate=(function(){
  7134. function SaveTranslate(){
  7135. this._mat=new Matrix();
  7136. }
  7137. __class(SaveTranslate,'laya.webgl.canvas.save.SaveTranslate');
  7138. var __proto=SaveTranslate.prototype;
  7139. Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true})
  7140. __proto.isSaveMark=function(){return false;}
  7141. __proto.restore=function(context){
  7142. this._mat.copyTo(context._curMat);
  7143. SaveTranslate.POOL[SaveTranslate.POOL._length++]=this;
  7144. }
  7145. SaveTranslate.save=function(context){
  7146. var no=SaveTranslate.POOL;
  7147. var o=no._length > 0 ? no[--no._length] :(new SaveTranslate());
  7148. context._curMat.copyTo(o._mat);
  7149. var _save=context._save;
  7150. _save[_save._length++]=o;
  7151. }
  7152. SaveTranslate.POOL=SaveBase._createArray();
  7153. return SaveTranslate;
  7154. })()
  7155. /**
  7156. *绘制单条曲线
  7157. */
  7158. //class laya.display.cmd.DrawLineCmd
  7159. var DrawLineCmd=(function(){
  7160. function DrawLineCmd(){
  7161. /**
  7162. *X轴开始位置。
  7163. */
  7164. //this.fromX=NaN;
  7165. /**
  7166. *Y轴开始位置。
  7167. */
  7168. //this.fromY=NaN;
  7169. /**
  7170. *X轴结束位置。
  7171. */
  7172. //this.toX=NaN;
  7173. /**
  7174. *Y轴结束位置。
  7175. */
  7176. //this.toY=NaN;
  7177. /**
  7178. *颜色。
  7179. */
  7180. //this.lineColor=null;
  7181. /**
  7182. *(可选)线条宽度。
  7183. */
  7184. //this.lineWidth=NaN;
  7185. /**@private */
  7186. //this.vid=0;
  7187. }
  7188. __class(DrawLineCmd,'laya.display.cmd.DrawLineCmd');
  7189. var __proto=DrawLineCmd.prototype;
  7190. /**
  7191. *回收到对象池
  7192. */
  7193. __proto.recover=function(){
  7194. Pool.recover("DrawLineCmd",this);
  7195. }
  7196. /**@private */
  7197. __proto.run=function(context,gx,gy){
  7198. context._drawLine(gx,gy,this.fromX,this.fromY,this.toX,this.toY,this.lineColor,this.lineWidth,this.vid);
  7199. }
  7200. /**@private */
  7201. __getset(0,__proto,'cmdID',function(){
  7202. return "DrawLine";
  7203. });
  7204. DrawLineCmd.create=function(fromX,fromY,toX,toY,lineColor,lineWidth,vid){
  7205. var cmd=Pool.getItemByClass("DrawLineCmd",DrawLineCmd);
  7206. cmd.fromX=fromX;
  7207. cmd.fromY=fromY;
  7208. cmd.toX=toX;
  7209. cmd.toY=toY;
  7210. cmd.lineColor=lineColor;
  7211. cmd.lineWidth=lineWidth;
  7212. cmd.vid=vid;
  7213. return cmd;
  7214. }
  7215. DrawLineCmd.ID="DrawLine";
  7216. return DrawLineCmd;
  7217. })()
  7218. //class laya.webgl.WebGLContext
  7219. var WebGLContext=(function(){
  7220. function WebGLContext(){}
  7221. __class(WebGLContext,'laya.webgl.WebGLContext');
  7222. var __proto=WebGLContext.prototype;
  7223. __proto.getContextAttributes=function(){return null;}
  7224. __proto.isContextLost=function(){}
  7225. __proto.getSupportedExtensions=function(){return null;}
  7226. __proto.getExtension=function(name){return null;}
  7227. __proto.activeTexture=function(texture){}
  7228. __proto.attachShader=function(program,shader){}
  7229. __proto.bindAttribLocation=function(program,index,name){}
  7230. __proto.bindBuffer=function(target,buffer){}
  7231. __proto.bindFramebuffer=function(target,framebuffer){}
  7232. __proto.bindRenderbuffer=function(target,renderbuffer){}
  7233. __proto.bindTexture=function(target,texture){}
  7234. __proto.useTexture=function(value){}
  7235. __proto.blendColor=function(red,green,blue,alpha){}
  7236. __proto.blendEquation=function(mode){}
  7237. __proto.blendEquationSeparate=function(modeRGB,modeAlpha){}
  7238. __proto.blendFunc=function(sfactor,dfactor){}
  7239. __proto.blendFuncSeparate=function(srcRGB,dstRGB,srcAlpha,dstAlpha){}
  7240. __proto.bufferData=function(target,size,usage){}
  7241. __proto.bufferSubData=function(target,offset,data){}
  7242. __proto.checkFramebufferStatus=function(target){return null;}
  7243. __proto.clear=function(mask){}
  7244. __proto.clearColor=function(red,green,blue,alpha){}
  7245. __proto.clearDepth=function(depth){}
  7246. __proto.clearStencil=function(s){}
  7247. __proto.colorMask=function(red,green,blue,alpha){}
  7248. __proto.compileShader=function(shader){}
  7249. __proto.copyTexImage2D=function(target,level,internalformat,x,y,width,height,border){}
  7250. __proto.copyTexSubImage2D=function(target,level,xoffset,yoffset,x,y,width,height){}
  7251. __proto.createBuffer=function(){}
  7252. __proto.createFramebuffer=function(){}
  7253. __proto.createProgram=function(){}
  7254. __proto.createRenderbuffer=function(){}
  7255. __proto.createShader=function(type){}
  7256. __proto.createTexture=function(){return null}
  7257. __proto.cullFace=function(mode){}
  7258. __proto.deleteBuffer=function(buffer){}
  7259. __proto.deleteFramebuffer=function(framebuffer){}
  7260. __proto.deleteProgram=function(program){}
  7261. __proto.deleteRenderbuffer=function(renderbuffer){}
  7262. __proto.deleteShader=function(shader){}
  7263. __proto.deleteTexture=function(texture){}
  7264. __proto.depthFunc=function(func){}
  7265. __proto.depthMask=function(flag){}
  7266. __proto.depthRange=function(zNear,zFar){}
  7267. __proto.detachShader=function(program,shader){}
  7268. __proto.disable=function(cap){}
  7269. __proto.disableVertexAttribArray=function(index){}
  7270. __proto.drawArrays=function(mode,first,count){}
  7271. __proto.drawElements=function(mode,count,type,offset){}
  7272. __proto.enable=function(cap){}
  7273. __proto.enableVertexAttribArray=function(index){}
  7274. __proto.finish=function(){}
  7275. __proto.flush=function(){}
  7276. __proto.framebufferRenderbuffer=function(target,attachment,renderbuffertarget,renderbuffer){}
  7277. __proto.framebufferTexture2D=function(target,attachment,textarget,texture,level){}
  7278. __proto.frontFace=function(mode){return null;}
  7279. __proto.generateMipmap=function(target){return null;}
  7280. __proto.getActiveAttrib=function(program,index){return null;}
  7281. __proto.getActiveUniform=function(program,index){return null;}
  7282. __proto.getAttribLocation=function(program,name){return 0;}
  7283. __proto.getParameter=function(pname){return null;}
  7284. __proto.getBufferParameter=function(target,pname){return null;}
  7285. __proto.getError=function(){return null;}
  7286. __proto.getFramebufferAttachmentParameter=function(target,attachment,pname){}
  7287. __proto.getProgramParameter=function(program,pname){return 0;}
  7288. __proto.getProgramInfoLog=function(program){return null;}
  7289. __proto.getRenderbufferParameter=function(target,pname){return null;}
  7290. __proto.getShaderPrecisionFormat=function(__arg){
  7291. var arg=arguments;return null;}
  7292. __proto.getShaderParameter=function(shader,pname){}
  7293. __proto.getShaderInfoLog=function(shader){return null;}
  7294. __proto.getShaderSource=function(shader){return null;}
  7295. __proto.getTexParameter=function(target,pname){}
  7296. __proto.getUniform=function(program,location){}
  7297. __proto.getUniformLocation=function(program,name){return null;}
  7298. __proto.getVertexAttrib=function(index,pname){return null;}
  7299. __proto.getVertexAttribOffset=function(index,pname){return null;}
  7300. __proto.hint=function(target,mode){}
  7301. __proto.isBuffer=function(buffer){}
  7302. __proto.isEnabled=function(cap){}
  7303. __proto.isFramebuffer=function(framebuffer){}
  7304. __proto.isProgram=function(program){}
  7305. __proto.isRenderbuffer=function(renderbuffer){}
  7306. __proto.isShader=function(shader){}
  7307. __proto.isTexture=function(texture){}
  7308. __proto.lineWidth=function(width){}
  7309. __proto.linkProgram=function(program){}
  7310. __proto.pixelStorei=function(pname,param){}
  7311. __proto.polygonOffset=function(factor,units){}
  7312. __proto.readPixels=function(x,y,width,height,format,type,pixels){}
  7313. __proto.renderbufferStorage=function(target,internalformat,width,height){}
  7314. __proto.sampleCoverage=function(value,invert){}
  7315. __proto.scissor=function(x,y,width,height){}
  7316. __proto.shaderSource=function(shader,source){}
  7317. __proto.stencilFunc=function(func,ref,mask){}
  7318. __proto.stencilFuncSeparate=function(face,func,ref,mask){}
  7319. __proto.stencilMask=function(mask){}
  7320. __proto.stencilMaskSeparate=function(face,mask){}
  7321. __proto.stencilOp=function(fail,zfail,zpass){}
  7322. __proto.stencilOpSeparate=function(face,fail,zfail,zpass){}
  7323. __proto.texImage2D=function(__args){}
  7324. __proto.texParameterf=function(target,pname,param){}
  7325. __proto.texParameteri=function(target,pname,param){}
  7326. __proto.texSubImage2D=function(__args){}
  7327. __proto.uniform1f=function(location,x){}
  7328. __proto.uniform1fv=function(location,v){}
  7329. __proto.uniform1i=function(location,x){}
  7330. __proto.uniform1iv=function(location,v){}
  7331. __proto.uniform2f=function(location,x,y){}
  7332. __proto.uniform2fv=function(location,v){}
  7333. __proto.uniform2i=function(location,x,y){}
  7334. __proto.uniform2iv=function(location,v){}
  7335. __proto.uniform3f=function(location,x,y,z){}
  7336. __proto.uniform3fv=function(location,v){}
  7337. __proto.uniform3i=function(location,x,y,z){}
  7338. __proto.uniform3iv=function(location,v){}
  7339. __proto.uniform4f=function(location,x,y,z,w){}
  7340. __proto.uniform4fv=function(location,v){}
  7341. __proto.uniform4i=function(location,x,y,z,w){}
  7342. __proto.uniform4iv=function(location,v){}
  7343. __proto.uniformMatrix2fv=function(location,transpose,value){}
  7344. __proto.uniformMatrix3fv=function(location,transpose,value){}
  7345. __proto.uniformMatrix4fv=function(location,transpose,value){}
  7346. __proto.useProgram=function(program){}
  7347. __proto.validateProgram=function(program){}
  7348. __proto.vertexAttrib1f=function(indx,x){}
  7349. __proto.vertexAttrib1fv=function(indx,values){}
  7350. __proto.vertexAttrib2f=function(indx,x,y){}
  7351. __proto.vertexAttrib2fv=function(indx,values){}
  7352. __proto.vertexAttrib3f=function(indx,x,y,z){}
  7353. __proto.vertexAttrib3fv=function(indx,values){}
  7354. __proto.vertexAttrib4f=function(indx,x,y,z,w){}
  7355. __proto.vertexAttrib4fv=function(indx,values){}
  7356. __proto.vertexAttribPointer=function(indx,size,type,normalized,stride,offset){}
  7357. __proto.viewport=function(x,y,width,height){}
  7358. __proto.configureBackBuffer=function(width,height,antiAlias,enableDepthAndStencil,wantsBestResolution){
  7359. (enableDepthAndStencil===void 0)&& (enableDepthAndStencil=true);
  7360. (wantsBestResolution===void 0)&& (wantsBestResolution=false);
  7361. }
  7362. __proto.compressedTexImage2D=function(__args){}
  7363. //TODO:coverage
  7364. __proto.createVertexArray=function(){
  7365. throw "not implemented";
  7366. }
  7367. //TODO:coverage
  7368. __proto.bindVertexArray=function(vao){
  7369. throw "not implemented";
  7370. }
  7371. //TODO:coverage
  7372. __proto.deleteVertexArray=function(vao){
  7373. throw "not implemented";
  7374. }
  7375. //TODO:coverage
  7376. __proto.isVertexArray=function(vao){
  7377. throw "not implemented";
  7378. }
  7379. WebGLContext._forceSupportVAOPlatform=function(){
  7380. return (Browser.onMiniGame && Browser.onIOS)|| Browser.onBDMiniGame || Browser.onQGMiniGame;
  7381. }
  7382. WebGLContext.__init__=function(gl){
  7383. laya.webgl.WebGLContext._checkExtensions(gl);
  7384. if (!WebGL._isWebGL2 && !Render.isConchApp){
  7385. VertexArrayObject;
  7386. if (window._setupVertexArrayObject){
  7387. if (WebGLContext._forceSupportVAOPlatform())
  7388. window._forceSetupVertexArrayObject(gl);
  7389. else
  7390. window._setupVertexArrayObject(gl);
  7391. };
  7392. var ext=((gl).rawgl || gl).getExtension("OES_vertex_array_object");
  7393. if (ext){
  7394. var glContext=gl;
  7395. glContext.createVertexArray=function (){return ext.createVertexArrayOES();};
  7396. glContext.bindVertexArray=function (vao){ext.bindVertexArrayOES(vao);};
  7397. glContext.deleteVertexArray=function (vao){ext.deleteVertexArrayOES(vao);};
  7398. glContext.isVertexArray=function (vao){ext.isVertexArrayOES(vao);};
  7399. }
  7400. }
  7401. }
  7402. WebGLContext._getExtension=function(gl,name){
  7403. var prefixes=WebGLContext._extentionVendorPrefixes;
  7404. for (var k in prefixes){
  7405. var ext=gl.getExtension(prefixes[k]+name);
  7406. if (ext)
  7407. return ext;
  7408. }
  7409. return null;
  7410. }
  7411. WebGLContext._checkExtensions=function(gl){
  7412. WebGLContext._extTextureFilterAnisotropic=WebGLContext._getExtension(gl,"EXT_texture_filter_anisotropic");
  7413. WebGLContext._compressedTextureS3tc=WebGLContext._getExtension(gl,"WEBGL_compressed_texture_s3tc");
  7414. WebGLContext._compressedTexturePvrtc=WebGLContext._getExtension(gl,"WEBGL_compressed_texture_pvrtc");
  7415. WebGLContext._compressedTextureEtc1=WebGLContext._getExtension(gl,"WEBGL_compressed_texture_etc1");
  7416. if (!WebGLContext._forceSupportVAOPlatform())
  7417. WebGLContext._angleInstancedArrays=WebGLContext._getExtension(gl,"ANGLE_instanced_arrays");
  7418. }
  7419. WebGLContext.__init_native=function(){
  7420. if (!Render.supportWebGLPlusRendering)return;
  7421. var webGLContext=WebGLContext;
  7422. webGLContext.activeTexture=webGLContext.activeTextureForNative;
  7423. webGLContext.bindTexture=webGLContext.bindTextureForNative;
  7424. }
  7425. WebGLContext.useProgram=function(gl,program){
  7426. if (WebGLContext._useProgram===program)
  7427. return false;
  7428. gl.useProgram(program);
  7429. WebGLContext._useProgram=program;
  7430. return true;
  7431. }
  7432. WebGLContext.setDepthTest=function(gl,value){
  7433. 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));
  7434. }
  7435. WebGLContext.setDepthMask=function(gl,value){
  7436. value!==WebGLContext._depthMask && (WebGLContext._depthMask=value,gl.depthMask(value));
  7437. }
  7438. WebGLContext.setDepthFunc=function(gl,value){
  7439. value!==WebGLContext._depthFunc && (WebGLContext._depthFunc=value,gl.depthFunc(value));
  7440. }
  7441. WebGLContext.setBlend=function(gl,value){
  7442. 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));
  7443. }
  7444. WebGLContext.setBlendFunc=function(gl,sFactor,dFactor){
  7445. (sFactor!==WebGLContext._sFactor || dFactor!==WebGLContext._dFactor)&& (WebGLContext._sFactor=WebGLContext._srcAlpha=sFactor,WebGLContext._dFactor=WebGLContext._dstAlpha=dFactor,gl.blendFunc(sFactor,dFactor));
  7446. }
  7447. WebGLContext.setBlendFuncSeperate=function(gl,srcRGB,dstRGB,srcAlpha,dstAlpha){
  7448. if (srcRGB!==WebGLContext._sFactor || dstRGB!==WebGLContext._dFactor || srcAlpha!==WebGLContext._srcAlpha || dstAlpha!==WebGLContext._dstAlpha){
  7449. WebGLContext._sFactor=srcRGB;
  7450. WebGLContext._dFactor=dstRGB;
  7451. WebGLContext._srcAlpha=srcAlpha;
  7452. WebGLContext._dstAlpha=dstAlpha;
  7453. gl.blendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha);
  7454. }
  7455. }
  7456. WebGLContext.setCullFace=function(gl,value){
  7457. 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));
  7458. }
  7459. WebGLContext.setFrontFace=function(gl,value){
  7460. value!==WebGLContext._frontFace && (WebGLContext._frontFace=value,gl.frontFace(value));
  7461. }
  7462. WebGLContext.activeTexture=function(gl,textureID){
  7463. if (WebGLContext._activedTextureID!==textureID){
  7464. gl.activeTexture(textureID);
  7465. WebGLContext._activedTextureID=textureID;
  7466. }
  7467. }
  7468. WebGLContext.bindTexture=function(gl,target,texture){
  7469. if (WebGLContext._activeTextures[WebGLContext._activedTextureID-0x84C0]!==texture){
  7470. gl.bindTexture(target,texture);
  7471. WebGLContext._activeTextures[WebGLContext._activedTextureID-0x84C0]=texture;
  7472. }
  7473. }
  7474. WebGLContext.useProgramForNative=function(gl,program){
  7475. gl.useProgram(program);
  7476. return true;
  7477. }
  7478. WebGLContext.setDepthTestForNative=function(gl,value){
  7479. if (value)gl.enable(/*CLASS CONST:laya.webgl.WebGLContext.DEPTH_TEST*/0x0B71);
  7480. else gl.disable(/*CLASS CONST:laya.webgl.WebGLContext.DEPTH_TEST*/0x0B71);
  7481. }
  7482. WebGLContext.setDepthMaskForNative=function(gl,value){
  7483. gl.depthMask(value);
  7484. }
  7485. WebGLContext.setDepthFuncForNative=function(gl,value){
  7486. gl.depthFunc(value);
  7487. }
  7488. WebGLContext.setBlendForNative=function(gl,value){
  7489. if (value)gl.enable(/*CLASS CONST:laya.webgl.WebGLContext.BLEND*/0x0BE2);
  7490. else gl.disable(/*CLASS CONST:laya.webgl.WebGLContext.BLEND*/0x0BE2);
  7491. }
  7492. WebGLContext.setBlendFuncForNative=function(gl,sFactor,dFactor){
  7493. gl.blendFunc(sFactor,dFactor);
  7494. }
  7495. WebGLContext.setCullFaceForNative=function(gl,value){
  7496. if (value)gl.enable(/*CLASS CONST:laya.webgl.WebGLContext.CULL_FACE*/0x0B44)
  7497. else gl.disable(/*CLASS CONST:laya.webgl.WebGLContext.CULL_FACE*/0x0B44);
  7498. }
  7499. WebGLContext.setFrontFaceForNative=function(gl,value){
  7500. gl.frontFace(value);
  7501. }
  7502. WebGLContext.activeTextureForNative=function(gl,textureID){
  7503. gl.activeTexture(textureID);
  7504. }
  7505. WebGLContext.bindTextureForNative=function(gl,target,texture){
  7506. gl.bindTexture(target,texture);
  7507. }
  7508. WebGLContext.bindVertexArrayForNative=function(gl,vertexArray){
  7509. /*__JS__ */gl.bindVertexArray(vertexArray);
  7510. }
  7511. WebGLContext.DEPTH_BUFFER_BIT=0x00000100;
  7512. WebGLContext.STENCIL_BUFFER_BIT=0x00000400;
  7513. WebGLContext.COLOR_BUFFER_BIT=0x00004000;
  7514. WebGLContext.POINTS=0x0000;
  7515. WebGLContext.LINES=0x0001;
  7516. WebGLContext.LINE_LOOP=0x0002;
  7517. WebGLContext.LINE_STRIP=0x0003;
  7518. WebGLContext.TRIANGLES=0x0004;
  7519. WebGLContext.TRIANGLE_STRIP=0x0005;
  7520. WebGLContext.TRIANGLE_FAN=0x0006;
  7521. WebGLContext.ZERO=0;
  7522. WebGLContext.ONE=1;
  7523. WebGLContext.SRC_COLOR=0x0300;
  7524. WebGLContext.ONE_MINUS_SRC_COLOR=0x0301;
  7525. WebGLContext.SRC_ALPHA=0x0302;
  7526. WebGLContext.ONE_MINUS_SRC_ALPHA=0x0303;
  7527. WebGLContext.DST_ALPHA=0x0304;
  7528. WebGLContext.ONE_MINUS_DST_ALPHA=0x0305;
  7529. WebGLContext.DST_COLOR=0x0306;
  7530. WebGLContext.ONE_MINUS_DST_COLOR=0x0307;
  7531. WebGLContext.SRC_ALPHA_SATURATE=0x0308;
  7532. WebGLContext.FUNC_ADD=0x8006;
  7533. WebGLContext.BLEND_EQUATION=0x8009;
  7534. WebGLContext.BLEND_EQUATION_RGB=0x8009;
  7535. WebGLContext.BLEND_EQUATION_ALPHA=0x883D;
  7536. WebGLContext.FUNC_SUBTRACT=0x800A;
  7537. WebGLContext.FUNC_REVERSE_SUBTRACT=0x800B;
  7538. WebGLContext.BLEND_DST_RGB=0x80C8;
  7539. WebGLContext.BLEND_SRC_RGB=0x80C9;
  7540. WebGLContext.BLEND_DST_ALPHA=0x80CA;
  7541. WebGLContext.BLEND_SRC_ALPHA=0x80CB;
  7542. WebGLContext.CONSTANT_COLOR=0x8001;
  7543. WebGLContext.ONE_MINUS_CONSTANT_COLOR=0x8002;
  7544. WebGLContext.CONSTANT_ALPHA=0x8003;
  7545. WebGLContext.ONE_MINUS_CONSTANT_ALPHA=0x8004;
  7546. WebGLContext.BLEND_COLOR=0x8005;
  7547. WebGLContext.ARRAY_BUFFER=0x8892;
  7548. WebGLContext.ELEMENT_ARRAY_BUFFER=0x8893;
  7549. WebGLContext.ARRAY_BUFFER_BINDING=0x8894;
  7550. WebGLContext.ELEMENT_ARRAY_BUFFER_BINDING=0x8895;
  7551. WebGLContext.STREAM_DRAW=0x88E0;
  7552. WebGLContext.STATIC_DRAW=0x88E4;
  7553. WebGLContext.DYNAMIC_DRAW=0x88E8;
  7554. WebGLContext.BUFFER_SIZE=0x8764;
  7555. WebGLContext.BUFFER_USAGE=0x8765;
  7556. WebGLContext.CURRENT_VERTEX_ATTRIB=0x8626;
  7557. WebGLContext.FRONT=0x0404;
  7558. WebGLContext.BACK=0x0405;
  7559. WebGLContext.CULL_FACE=0x0B44;
  7560. WebGLContext.FRONT_AND_BACK=0x0408;
  7561. WebGLContext.BLEND=0x0BE2;
  7562. WebGLContext.DITHER=0x0BD0;
  7563. WebGLContext.STENCIL_TEST=0x0B90;
  7564. WebGLContext.DEPTH_TEST=0x0B71;
  7565. WebGLContext.SCISSOR_TEST=0x0C11;
  7566. WebGLContext.POLYGON_OFFSET_FILL=0x8037;
  7567. WebGLContext.SAMPLE_ALPHA_TO_COVERAGE=0x809E;
  7568. WebGLContext.SAMPLE_COVERAGE=0x80A0;
  7569. WebGLContext.NO_ERROR=0;
  7570. WebGLContext.INVALID_ENUM=0x0500;
  7571. WebGLContext.INVALID_VALUE=0x0501;
  7572. WebGLContext.INVALID_OPERATION=0x0502;
  7573. WebGLContext.OUT_OF_MEMORY=0x0505;
  7574. WebGLContext.CW=0x0900;
  7575. WebGLContext.CCW=0x0901;
  7576. WebGLContext.LINE_WIDTH=0x0B21;
  7577. WebGLContext.ALIASED_POINT_SIZE_RANGE=0x846D;
  7578. WebGLContext.ALIASED_LINE_WIDTH_RANGE=0x846E;
  7579. WebGLContext.CULL_FACE_MODE=0x0B45;
  7580. WebGLContext.FRONT_FACE=0x0B46;
  7581. WebGLContext.DEPTH_RANGE=0x0B70;
  7582. WebGLContext.DEPTH_WRITEMASK=0x0B72;
  7583. WebGLContext.DEPTH_CLEAR_VALUE=0x0B73;
  7584. WebGLContext.DEPTH_FUNC=0x0B74;
  7585. WebGLContext.STENCIL_CLEAR_VALUE=0x0B91;
  7586. WebGLContext.STENCIL_FUNC=0x0B92;
  7587. WebGLContext.STENCIL_FAIL=0x0B94;
  7588. WebGLContext.STENCIL_PASS_DEPTH_FAIL=0x0B95;
  7589. WebGLContext.STENCIL_PASS_DEPTH_PASS=0x0B96;
  7590. WebGLContext.STENCIL_REF=0x0B97;
  7591. WebGLContext.STENCIL_VALUE_MASK=0x0B93;
  7592. WebGLContext.STENCIL_WRITEMASK=0x0B98;
  7593. WebGLContext.STENCIL_BACK_FUNC=0x8800;
  7594. WebGLContext.STENCIL_BACK_FAIL=0x8801;
  7595. WebGLContext.STENCIL_BACK_PASS_DEPTH_FAIL=0x8802;
  7596. WebGLContext.STENCIL_BACK_PASS_DEPTH_PASS=0x8803;
  7597. WebGLContext.STENCIL_BACK_REF=0x8CA3;
  7598. WebGLContext.STENCIL_BACK_VALUE_MASK=0x8CA4;
  7599. WebGLContext.STENCIL_BACK_WRITEMASK=0x8CA5;
  7600. WebGLContext.VIEWPORT=0x0BA2;
  7601. WebGLContext.SCISSOR_BOX=0x0C10;
  7602. WebGLContext.COLOR_CLEAR_VALUE=0x0C22;
  7603. WebGLContext.COLOR_WRITEMASK=0x0C23;
  7604. WebGLContext.UNPACK_ALIGNMENT=0x0CF5;
  7605. WebGLContext.PACK_ALIGNMENT=0x0D05;
  7606. WebGLContext.MAX_TEXTURE_SIZE=0x0D33;
  7607. WebGLContext.MAX_VIEWPORT_DIMS=0x0D3A;
  7608. WebGLContext.SUBPIXEL_BITS=0x0D50;
  7609. WebGLContext.RED_BITS=0x0D52;
  7610. WebGLContext.GREEN_BITS=0x0D53;
  7611. WebGLContext.BLUE_BITS=0x0D54;
  7612. WebGLContext.ALPHA_BITS=0x0D55;
  7613. WebGLContext.DEPTH_BITS=0x0D56;
  7614. WebGLContext.STENCIL_BITS=0x0D57;
  7615. WebGLContext.POLYGON_OFFSET_UNITS=0x2A00;
  7616. WebGLContext.POLYGON_OFFSET_FACTOR=0x8038;
  7617. WebGLContext.TEXTURE_BINDING_2D=0x8069;
  7618. WebGLContext.SAMPLE_BUFFERS=0x80A8;
  7619. WebGLContext.SAMPLES=0x80A9;
  7620. WebGLContext.SAMPLE_COVERAGE_VALUE=0x80AA;
  7621. WebGLContext.SAMPLE_COVERAGE_INVERT=0x80AB;
  7622. WebGLContext.NUM_COMPRESSED_TEXTURE_FORMATS=0x86A2;
  7623. WebGLContext.COMPRESSED_TEXTURE_FORMATS=0x86A3;
  7624. WebGLContext.DONT_CARE=0x1100;
  7625. WebGLContext.FASTEST=0x1101;
  7626. WebGLContext.NICEST=0x1102;
  7627. WebGLContext.GENERATE_MIPMAP_HINT=0x8192;
  7628. WebGLContext.BYTE=0x1400;
  7629. WebGLContext.UNSIGNED_BYTE=0x1401;
  7630. WebGLContext.SHORT=0x1402;
  7631. WebGLContext.UNSIGNED_SHORT=0x1403;
  7632. WebGLContext.INT=0x1404;
  7633. WebGLContext.UNSIGNED_INT=0x1405;
  7634. WebGLContext.FLOAT=0x1406;
  7635. WebGLContext.DEPTH_COMPONENT=0x1902;
  7636. WebGLContext.ALPHA=0x1906;
  7637. WebGLContext.RGB=0x1907;
  7638. WebGLContext.RGBA=0x1908;
  7639. WebGLContext.LUMINANCE=0x1909;
  7640. WebGLContext.LUMINANCE_ALPHA=0x190A;
  7641. WebGLContext.UNSIGNED_SHORT_4_4_4_4=0x8033;
  7642. WebGLContext.UNSIGNED_SHORT_5_5_5_1=0x8034;
  7643. WebGLContext.UNSIGNED_SHORT_5_6_5=0x8363;
  7644. WebGLContext.FRAGMENT_SHADER=0x8B30;
  7645. WebGLContext.VERTEX_SHADER=0x8B31;
  7646. WebGLContext.MAX_VERTEX_ATTRIBS=0x8869;
  7647. WebGLContext.MAX_VERTEX_UNIFORM_VECTORS=0x8DFB;
  7648. WebGLContext.MAX_VARYING_VECTORS=0x8DFC;
  7649. WebGLContext.MAX_COMBINED_TEXTURE_IMAGE_UNITS=0x8B4D;
  7650. WebGLContext.MAX_VERTEX_TEXTURE_IMAGE_UNITS=0x8B4C;
  7651. WebGLContext.MAX_TEXTURE_IMAGE_UNITS=0x8872;
  7652. WebGLContext.MAX_FRAGMENT_UNIFORM_VECTORS=0x8DFD;
  7653. WebGLContext.SHADER_TYPE=0x8B4F;
  7654. WebGLContext.DELETE_STATUS=0x8B80;
  7655. WebGLContext.LINK_STATUS=0x8B82;
  7656. WebGLContext.VALIDATE_STATUS=0x8B83;
  7657. WebGLContext.ATTACHED_SHADERS=0x8B85;
  7658. WebGLContext.ACTIVE_UNIFORMS=0x8B86;
  7659. WebGLContext.ACTIVE_ATTRIBUTES=0x8B89;
  7660. WebGLContext.SHADING_LANGUAGE_VERSION=0x8B8C;
  7661. WebGLContext.CURRENT_PROGRAM=0x8B8D;
  7662. WebGLContext.NEVER=0x0200;
  7663. WebGLContext.LESS=0x0201;
  7664. WebGLContext.EQUAL=0x0202;
  7665. WebGLContext.LEQUAL=0x0203;
  7666. WebGLContext.GREATER=0x0204;
  7667. WebGLContext.NOTEQUAL=0x0205;
  7668. WebGLContext.GEQUAL=0x0206;
  7669. WebGLContext.ALWAYS=0x0207;
  7670. WebGLContext.KEEP=0x1E00;
  7671. WebGLContext.REPLACE=0x1E01;
  7672. WebGLContext.INCR=0x1E02;
  7673. WebGLContext.DECR=0x1E03;
  7674. WebGLContext.INVERT=0x150A;
  7675. WebGLContext.INCR_WRAP=0x8507;
  7676. WebGLContext.DECR_WRAP=0x8508;
  7677. WebGLContext.VENDOR=0x1F00;
  7678. WebGLContext.RENDERER=0x1F01;
  7679. WebGLContext.VERSION=0x1F02;
  7680. WebGLContext.NEAREST=0x2600;
  7681. WebGLContext.LINEAR=0x2601;
  7682. WebGLContext.NEAREST_MIPMAP_NEAREST=0x2700;
  7683. WebGLContext.LINEAR_MIPMAP_NEAREST=0x2701;
  7684. WebGLContext.NEAREST_MIPMAP_LINEAR=0x2702;
  7685. WebGLContext.LINEAR_MIPMAP_LINEAR=0x2703;
  7686. WebGLContext.TEXTURE_MAG_FILTER=0x2800;
  7687. WebGLContext.TEXTURE_MIN_FILTER=0x2801;
  7688. WebGLContext.TEXTURE_WRAP_S=0x2802;
  7689. WebGLContext.TEXTURE_WRAP_T=0x2803;
  7690. WebGLContext.TEXTURE_2D=0x0DE1;
  7691. WebGLContext.TEXTURE_3D=0x806f;
  7692. WebGLContext.TEXTURE=0x1702;
  7693. WebGLContext.TEXTURE_CUBE_MAP=0x8513;
  7694. WebGLContext.TEXTURE_BINDING_CUBE_MAP=0x8514;
  7695. WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_X=0x8515;
  7696. WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_X=0x8516;
  7697. WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Y=0x8517;
  7698. WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Y=0x8518;
  7699. WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Z=0x8519;
  7700. WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Z=0x851A;
  7701. WebGLContext.MAX_CUBE_MAP_TEXTURE_SIZE=0x851C;
  7702. WebGLContext.TEXTURE0=0x84C0;
  7703. WebGLContext.TEXTURE1=0x84C1;
  7704. WebGLContext.TEXTURE2=0x84C2;
  7705. WebGLContext.TEXTURE3=0x84C3;
  7706. WebGLContext.TEXTURE4=0x84C4;
  7707. WebGLContext.TEXTURE5=0x84C5;
  7708. WebGLContext.TEXTURE6=0x84C6;
  7709. WebGLContext.TEXTURE7=0x84C7;
  7710. WebGLContext.TEXTURE8=0x84C8;
  7711. WebGLContext.TEXTURE9=0x84C9;
  7712. WebGLContext.TEXTURE10=0x84CA;
  7713. WebGLContext.TEXTURE11=0x84CB;
  7714. WebGLContext.TEXTURE12=0x84CC;
  7715. WebGLContext.TEXTURE13=0x84CD;
  7716. WebGLContext.TEXTURE14=0x84CE;
  7717. WebGLContext.TEXTURE15=0x84CF;
  7718. WebGLContext.TEXTURE16=0x84D0;
  7719. WebGLContext.TEXTURE17=0x84D1;
  7720. WebGLContext.TEXTURE18=0x84D2;
  7721. WebGLContext.TEXTURE19=0x84D3;
  7722. WebGLContext.TEXTURE20=0x84D4;
  7723. WebGLContext.TEXTURE21=0x84D5;
  7724. WebGLContext.TEXTURE22=0x84D6;
  7725. WebGLContext.TEXTURE23=0x84D7;
  7726. WebGLContext.TEXTURE24=0x84D8;
  7727. WebGLContext.TEXTURE25=0x84D9;
  7728. WebGLContext.TEXTURE26=0x84DA;
  7729. WebGLContext.TEXTURE27=0x84DB;
  7730. WebGLContext.TEXTURE28=0x84DC;
  7731. WebGLContext.TEXTURE29=0x84DD;
  7732. WebGLContext.TEXTURE30=0x84DE;
  7733. WebGLContext.TEXTURE31=0x84DF;
  7734. WebGLContext.ACTIVE_TEXTURE=0x84E0;
  7735. WebGLContext.REPEAT=0x2901;
  7736. WebGLContext.CLAMP_TO_EDGE=0x812F;
  7737. WebGLContext.MIRRORED_REPEAT=0x8370;
  7738. WebGLContext.FLOAT_VEC2=0x8B50;
  7739. WebGLContext.FLOAT_VEC3=0x8B51;
  7740. WebGLContext.FLOAT_VEC4=0x8B52;
  7741. WebGLContext.INT_VEC2=0x8B53;
  7742. WebGLContext.INT_VEC3=0x8B54;
  7743. WebGLContext.INT_VEC4=0x8B55;
  7744. WebGLContext.BOOL=0x8B56;
  7745. WebGLContext.BOOL_VEC2=0x8B57;
  7746. WebGLContext.BOOL_VEC3=0x8B58;
  7747. WebGLContext.BOOL_VEC4=0x8B59;
  7748. WebGLContext.FLOAT_MAT2=0x8B5A;
  7749. WebGLContext.FLOAT_MAT3=0x8B5B;
  7750. WebGLContext.FLOAT_MAT4=0x8B5C;
  7751. WebGLContext.SAMPLER_2D=0x8B5E;
  7752. WebGLContext.SAMPLER_CUBE=0x8B60;
  7753. WebGLContext.VERTEX_ATTRIB_ARRAY_ENABLED=0x8622;
  7754. WebGLContext.VERTEX_ATTRIB_ARRAY_SIZE=0x8623;
  7755. WebGLContext.VERTEX_ATTRIB_ARRAY_STRIDE=0x8624;
  7756. WebGLContext.VERTEX_ATTRIB_ARRAY_TYPE=0x8625;
  7757. WebGLContext.VERTEX_ATTRIB_ARRAY_NORMALIZED=0x886A;
  7758. WebGLContext.VERTEX_ATTRIB_ARRAY_POINTER=0x8645;
  7759. WebGLContext.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING=0x889F;
  7760. WebGLContext.COMPILE_STATUS=0x8B81;
  7761. WebGLContext.LOW_FLOAT=0x8DF0;
  7762. WebGLContext.MEDIUM_FLOAT=0x8DF1;
  7763. WebGLContext.HIGH_FLOAT=0x8DF2;
  7764. WebGLContext.LOW_INT=0x8DF3;
  7765. WebGLContext.MEDIUM_INT=0x8DF4;
  7766. WebGLContext.HIGH_INT=0x8DF5;
  7767. WebGLContext.FRAMEBUFFER=0x8D40;
  7768. WebGLContext.RENDERBUFFER=0x8D41;
  7769. WebGLContext.RGBA4=0x8056;
  7770. WebGLContext.RGB5_A1=0x8057;
  7771. WebGLContext.RGB565=0x8D62;
  7772. WebGLContext.DEPTH_COMPONENT16=0x81A5;
  7773. WebGLContext.STENCIL_INDEX=0x1901;
  7774. WebGLContext.STENCIL_INDEX8=0x8D48;
  7775. WebGLContext.DEPTH_STENCIL=0x84F9;
  7776. WebGLContext.RENDERBUFFER_WIDTH=0x8D42;
  7777. WebGLContext.RENDERBUFFER_HEIGHT=0x8D43;
  7778. WebGLContext.RENDERBUFFER_INTERNAL_FORMAT=0x8D44;
  7779. WebGLContext.RENDERBUFFER_RED_SIZE=0x8D50;
  7780. WebGLContext.RENDERBUFFER_GREEN_SIZE=0x8D51;
  7781. WebGLContext.RENDERBUFFER_BLUE_SIZE=0x8D52;
  7782. WebGLContext.RENDERBUFFER_ALPHA_SIZE=0x8D53;
  7783. WebGLContext.RENDERBUFFER_DEPTH_SIZE=0x8D54;
  7784. WebGLContext.RENDERBUFFER_STENCIL_SIZE=0x8D55;
  7785. WebGLContext.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE=0x8CD0;
  7786. WebGLContext.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME=0x8CD1;
  7787. WebGLContext.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL=0x8CD2;
  7788. WebGLContext.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE=0x8CD3;
  7789. WebGLContext.COLOR_ATTACHMENT0=0x8CE0;
  7790. WebGLContext.DEPTH_ATTACHMENT=0x8D00;
  7791. WebGLContext.STENCIL_ATTACHMENT=0x8D20;
  7792. WebGLContext.DEPTH_STENCIL_ATTACHMENT=0x821A;
  7793. WebGLContext.NONE=0;
  7794. WebGLContext.FRAMEBUFFER_COMPLETE=0x8CD5;
  7795. WebGLContext.FRAMEBUFFER_INCOMPLETE_ATTACHMENT=0x8CD6;
  7796. WebGLContext.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT=0x8CD7;
  7797. WebGLContext.FRAMEBUFFER_INCOMPLETE_DIMENSIONS=0x8CD9;
  7798. WebGLContext.FRAMEBUFFER_UNSUPPORTED=0x8CDD;
  7799. WebGLContext.FRAMEBUFFER_BINDING=0x8CA6;
  7800. WebGLContext.RENDERBUFFER_BINDING=0x8CA7;
  7801. WebGLContext.MAX_RENDERBUFFER_SIZE=0x84E8;
  7802. WebGLContext.INVALID_FRAMEBUFFER_OPERATION=0x0506;
  7803. WebGLContext.UNPACK_FLIP_Y_WEBGL=0x9240;
  7804. WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL=0x9241;
  7805. WebGLContext.CONTEXT_LOST_WEBGL=0x9242;
  7806. WebGLContext.UNPACK_COLORSPACE_CONVERSION_WEBGL=0x9243;
  7807. WebGLContext.BROWSER_DEFAULT_WEBGL=0x9244;
  7808. WebGLContext._extTextureFilterAnisotropic=null;
  7809. WebGLContext._compressedTextureS3tc=null;
  7810. WebGLContext._compressedTexturePvrtc=null;
  7811. WebGLContext._compressedTextureEtc1=null;
  7812. WebGLContext._angleInstancedArrays=null;
  7813. 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];
  7814. WebGLContext._useProgram=null;
  7815. WebGLContext._depthTest=true;
  7816. WebGLContext._depthMask=true;
  7817. WebGLContext._blend=false;
  7818. WebGLContext._cullFace=false;
  7819. WebGLContext._activedTextureID=0x84C0;
  7820. __static(WebGLContext,
  7821. ['_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;}
  7822. ]);
  7823. return WebGLContext;
  7824. })()
  7825. /**
  7826. *<p>资源版本的生成由layacmd或IDE完成,使用 <code>ResourceVersion</code> 简化使用过程。</p>
  7827. *<p>调用 <code>enable</code> 启用资源版本管理。</p>
  7828. */
  7829. //class laya.net.ResourceVersion
  7830. var ResourceVersion=(function(){
  7831. function ResourceVersion(){}
  7832. __class(ResourceVersion,'laya.net.ResourceVersion');
  7833. ResourceVersion.enable=function(manifestFile,callback,type){
  7834. (type===void 0)&& (type=2);
  7835. laya.net.ResourceVersion.type=type;
  7836. Laya.loader.load(manifestFile,Handler.create(null,ResourceVersion.onManifestLoaded,[callback]),null,/*laya.net.Loader.JSON*/"json");
  7837. URL.customFormat=ResourceVersion.addVersionPrefix;
  7838. }
  7839. ResourceVersion.onManifestLoaded=function(callback,data){
  7840. ResourceVersion.manifest=data;
  7841. callback.run();
  7842. if (!data){
  7843. console.warn("资源版本清单文件不存在,不使用资源版本管理。忽略ERR_FILE_NOT_FOUND错误。");
  7844. }
  7845. }
  7846. ResourceVersion.addVersionPrefix=function(originURL){
  7847. originURL=URL.getAdptedFilePath(originURL);
  7848. if (ResourceVersion.manifest && ResourceVersion.manifest[originURL]){
  7849. if (ResourceVersion.type==2)return ResourceVersion.manifest[originURL];
  7850. return ResourceVersion.manifest[originURL]+"/"+originURL;
  7851. }
  7852. return originURL;
  7853. }
  7854. ResourceVersion.FOLDER_VERSION=1;
  7855. ResourceVersion.FILENAME_VERSION=2;
  7856. ResourceVersion.manifest=null;
  7857. ResourceVersion.type=1;
  7858. return ResourceVersion;
  7859. })()
  7860. /**
  7861. *填充文字命令
  7862. *@private
  7863. */
  7864. //class laya.display.cmd.FillWordsCmd
  7865. var FillWordsCmd=(function(){
  7866. function FillWordsCmd(){
  7867. /**
  7868. *文字数组
  7869. */
  7870. //this.words=null;
  7871. /**
  7872. *开始绘制文本的 x 坐标位置(相对于画布)。
  7873. */
  7874. //this.x=NaN;
  7875. /**
  7876. *开始绘制文本的 y 坐标位置(相对于画布)。
  7877. */
  7878. //this.y=NaN;
  7879. /**
  7880. *定义字体和字号,比如"20px Arial"。
  7881. */
  7882. //this.font=null;
  7883. /**
  7884. *定义文本颜色,比如"#ff0000"。
  7885. */
  7886. //this.color=null;
  7887. }
  7888. __class(FillWordsCmd,'laya.display.cmd.FillWordsCmd');
  7889. var __proto=FillWordsCmd.prototype;
  7890. /**
  7891. *回收到对象池
  7892. */
  7893. __proto.recover=function(){
  7894. this.words=null;
  7895. Pool.recover("FillWordsCmd",this);
  7896. }
  7897. /**@private */
  7898. __proto.run=function(context,gx,gy){
  7899. context.fillWords(this.words,this.x+gx,this.y+gy,this.font,this.color);
  7900. }
  7901. /**@private */
  7902. __getset(0,__proto,'cmdID',function(){
  7903. return "FillWords";
  7904. });
  7905. FillWordsCmd.create=function(words,x,y,font,color){
  7906. var cmd=Pool.getItemByClass("FillWordsCmd",FillWordsCmd);
  7907. cmd.words=words;
  7908. cmd.x=x;
  7909. cmd.y=y;
  7910. cmd.font=font;
  7911. cmd.color=color;
  7912. return cmd;
  7913. }
  7914. FillWordsCmd.ID="FillWords";
  7915. return FillWordsCmd;
  7916. })()
  7917. /**
  7918. *<p> <code>Matrix</code> 类表示一个转换矩阵,它确定如何将点从一个坐标空间映射到另一个坐标空间。</p>
  7919. *<p>您可以对一个显示对象执行不同的图形转换,方法是设置 Matrix 对象的属性,将该 Matrix 对象应用于 Transform 对象的 matrix 属性,然后应用该 Transform 对象作为显示对象的 transform 属性。这些转换函数包括平移(x 和 y 重新定位)、旋转、缩放和倾斜。</p>
  7920. */
  7921. //class laya.maths.Matrix
  7922. var Matrix=(function(){
  7923. function Matrix(a,b,c,d,tx,ty,nums){
  7924. /**缩放或旋转图像时影响像素沿 x 轴定位的值。*/
  7925. //this.a=NaN;
  7926. /**旋转或倾斜图像时影响像素沿 y 轴定位的值。*/
  7927. //this.b=NaN;
  7928. /**旋转或倾斜图像时影响像素沿 x 轴定位的值。*/
  7929. //this.c=NaN;
  7930. /**缩放或旋转图像时影响像素沿 y 轴定位的值。*/
  7931. //this.d=NaN;
  7932. /**沿 x 轴平移每个点的距离。*/
  7933. //this.tx=NaN;
  7934. /**沿 y 轴平移每个点的距离。*/
  7935. //this.ty=NaN;
  7936. /**@private 是否有旋转缩放操作*/
  7937. this._bTransform=false;
  7938. (a===void 0)&& (a=1);
  7939. (b===void 0)&& (b=0);
  7940. (c===void 0)&& (c=0);
  7941. (d===void 0)&& (d=1);
  7942. (tx===void 0)&& (tx=0);
  7943. (ty===void 0)&& (ty=0);
  7944. (nums===void 0)&& (nums=0);
  7945. if (Matrix._createFun !=null){
  7946. /*__JS__ */return Matrix._createFun(a,b,c,d,tx,ty,nums);
  7947. }
  7948. this.a=a;
  7949. this.b=b;
  7950. this.c=c;
  7951. this.d=d;
  7952. this.tx=tx;
  7953. this.ty=ty;
  7954. this._checkTransform();
  7955. }
  7956. __class(Matrix,'laya.maths.Matrix');
  7957. var __proto=Matrix.prototype;
  7958. /**
  7959. *将本矩阵设置为单位矩阵。
  7960. *@return 返回当前矩形。
  7961. */
  7962. __proto.identity=function(){
  7963. this.a=this.d=1;
  7964. this.b=this.tx=this.ty=this.c=0;
  7965. this._bTransform=false;
  7966. return this;
  7967. }
  7968. /**@private */
  7969. __proto._checkTransform=function(){
  7970. return this._bTransform=(this.a!==1 || this.b!==0 || this.c!==0 || this.d!==1);
  7971. }
  7972. /**
  7973. *设置沿 x 、y 轴平移每个点的距离。
  7974. *@param x 沿 x 轴平移每个点的距离。
  7975. *@param y 沿 y 轴平移每个点的距离。
  7976. *@return 返回对象本身
  7977. */
  7978. __proto.setTranslate=function(x,y){
  7979. this.tx=x;
  7980. this.ty=y;
  7981. return this;
  7982. }
  7983. /**
  7984. *沿 x 和 y 轴平移矩阵,平移的变化量由 x 和 y 参数指定。
  7985. *@param x 沿 x 轴向右移动的量(以像素为单位)。
  7986. *@param y 沿 y 轴向下移动的量(以像素为单位)。
  7987. *@return 返回此矩形对象。
  7988. */
  7989. __proto.translate=function(x,y){
  7990. this.tx+=x;
  7991. this.ty+=y;
  7992. return this;
  7993. }
  7994. /**
  7995. *对矩阵应用缩放转换。
  7996. *@param x 用于沿 x 轴缩放对象的乘数。
  7997. *@param y 用于沿 y 轴缩放对象的乘数。
  7998. *@return 返回矩阵对象本身
  7999. */
  8000. __proto.scale=function(x,y){
  8001. this.a *=x;
  8002. this.d *=y;
  8003. this.c *=x;
  8004. this.b *=y;
  8005. this.tx *=x;
  8006. this.ty *=y;
  8007. this._bTransform=true;
  8008. return this;
  8009. }
  8010. /**
  8011. *对 Matrix 对象应用旋转转换。
  8012. *@param angle 以弧度为单位的旋转角度。
  8013. *@return 返回矩阵对象本身
  8014. */
  8015. __proto.rotate=function(angle){
  8016. var cos=Math.cos(angle);
  8017. var sin=Math.sin(angle);
  8018. var a1=this.a;
  8019. var c1=this.c;
  8020. var tx1=this.tx;
  8021. this.a=a1 *cos-this.b *sin;
  8022. this.b=a1 *sin+this.b *cos;
  8023. this.c=c1 *cos-this.d *sin;
  8024. this.d=c1 *sin+this.d *cos;
  8025. this.tx=tx1 *cos-this.ty *sin;
  8026. this.ty=tx1 *sin+this.ty *cos;
  8027. this._bTransform=true;
  8028. return this;
  8029. }
  8030. /**
  8031. *对 Matrix 对象应用倾斜转换。
  8032. *@param x 沿着 X 轴的 2D 倾斜弧度。
  8033. *@param y 沿着 Y 轴的 2D 倾斜弧度。
  8034. *@return 当前 Matrix 对象。
  8035. */
  8036. __proto.skew=function(x,y){
  8037. var tanX=Math.tan(x);
  8038. var tanY=Math.tan(y);
  8039. var a1=this.a;
  8040. var b1=this.b;
  8041. this.a+=tanY *this.c;
  8042. this.b+=tanY *this.d;
  8043. this.c+=tanX *a1;
  8044. this.d+=tanX *b1;
  8045. return this;
  8046. }
  8047. /**
  8048. *对指定的点应用当前矩阵的逆转化并返回此点。
  8049. *@param out 待转化的点 Point 对象。
  8050. *@return 返回out
  8051. */
  8052. __proto.invertTransformPoint=function(out){
  8053. var a1=this.a;
  8054. var b1=this.b;
  8055. var c1=this.c;
  8056. var d1=this.d;
  8057. var tx1=this.tx;
  8058. var n=a1 *d1-b1 *c1;
  8059. var a2=d1 / n;
  8060. var b2=-b1 / n;
  8061. var c2=-c1 / n;
  8062. var d2=a1 / n;
  8063. var tx2=(c1 *this.ty-d1 *tx1)/ n;
  8064. var ty2=-(a1 *this.ty-b1 *tx1)/ n;
  8065. return out.setTo(a2 *out.x+c2 *out.y+tx2,b2 *out.x+d2 *out.y+ty2);
  8066. }
  8067. /**
  8068. *将 Matrix 对象表示的几何转换应用于指定点。
  8069. *@param out 用来设定输出结果的点。
  8070. *@return 返回out
  8071. */
  8072. __proto.transformPoint=function(out){
  8073. return out.setTo(this.a *out.x+this.c *out.y+this.tx,this.b *out.x+this.d *out.y+this.ty);
  8074. }
  8075. /**
  8076. *将 Matrix 对象表示的几何转换应用于指定点,忽略tx、ty。
  8077. *@param out 用来设定输出结果的点。
  8078. *@return 返回out
  8079. */
  8080. __proto.transformPointN=function(out){
  8081. return out.setTo(this.a *out.x+this.c *out.y ,this.b *out.x+this.d *out.y);
  8082. }
  8083. /**
  8084. *获取 X 轴缩放值。
  8085. *@return X 轴缩放值。
  8086. */
  8087. __proto.getScaleX=function(){
  8088. return this.b===0 ? this.a :Math.sqrt(this.a *this.a+this.b *this.b);
  8089. }
  8090. /**
  8091. *获取 Y 轴缩放值。
  8092. *@return Y 轴缩放值。
  8093. */
  8094. __proto.getScaleY=function(){
  8095. return this.c===0 ? this.d :Math.sqrt(this.c *this.c+this.d *this.d);
  8096. }
  8097. /**
  8098. *执行原始矩阵的逆转换。
  8099. *@return 当前矩阵对象。
  8100. */
  8101. __proto.invert=function(){
  8102. var a1=this.a;
  8103. var b1=this.b;
  8104. var c1=this.c;
  8105. var d1=this.d;
  8106. var tx1=this.tx;
  8107. var n=a1 *d1-b1 *c1;
  8108. this.a=d1 / n;
  8109. this.b=-b1 / n;
  8110. this.c=-c1 / n;
  8111. this.d=a1 / n;
  8112. this.tx=(c1 *this.ty-d1 *tx1)/ n;
  8113. this.ty=-(a1 *this.ty-b1 *tx1)/ n;
  8114. return this;
  8115. }
  8116. /**
  8117. *将 Matrix 的成员设置为指定值。
  8118. *@param a 缩放或旋转图像时影响像素沿 x 轴定位的值。
  8119. *@param b 旋转或倾斜图像时影响像素沿 y 轴定位的值。
  8120. *@param c 旋转或倾斜图像时影响像素沿 x 轴定位的值。
  8121. *@param d 缩放或旋转图像时影响像素沿 y 轴定位的值。
  8122. *@param tx 沿 x 轴平移每个点的距离。
  8123. *@param ty 沿 y 轴平移每个点的距离。
  8124. *@return 当前矩阵对象。
  8125. */
  8126. __proto.setTo=function(a,b,c,d,tx,ty){
  8127. this.a=a,this.b=b,this.c=c,this.d=d,this.tx=tx,this.ty=ty;
  8128. return this;
  8129. }
  8130. /**
  8131. *将指定矩阵与当前矩阵连接,从而将这两个矩阵的几何效果有效地结合在一起。
  8132. *@param matrix 要连接到源矩阵的矩阵。
  8133. *@return 当前矩阵。
  8134. */
  8135. __proto.concat=function(matrix){
  8136. var a=this.a;
  8137. var c=this.c;
  8138. var tx=this.tx;
  8139. this.a=a *matrix.a+this.b *matrix.c;
  8140. this.b=a *matrix.b+this.b *matrix.d;
  8141. this.c=c *matrix.a+this.d *matrix.c;
  8142. this.d=c *matrix.b+this.d *matrix.d;
  8143. this.tx=tx *matrix.a+this.ty *matrix.c+matrix.tx;
  8144. this.ty=tx *matrix.b+this.ty *matrix.d+matrix.ty;
  8145. return this;
  8146. }
  8147. /**
  8148. *@private
  8149. *对矩阵应用缩放转换。反向相乘
  8150. *@param x 用于沿 x 轴缩放对象的乘数。
  8151. *@param y 用于沿 y 轴缩放对象的乘数。
  8152. */
  8153. __proto.scaleEx=function(x,y){
  8154. var ba=this.a,bb=this.b,bc=this.c,bd=this.d;
  8155. if (bb!==0 || bc!==0){
  8156. this.a=x *ba;
  8157. this.b=x *bb;
  8158. this.c=y *bc;
  8159. this.d=y *bd;
  8160. }else {
  8161. this.a=x *ba;
  8162. this.b=0 *bd;
  8163. this.c=0 *ba;
  8164. this.d=y *bd;
  8165. }
  8166. this._bTransform=true;
  8167. }
  8168. /**
  8169. *@private
  8170. *对 Matrix 对象应用旋转转换。反向相乘
  8171. *@param angle 以弧度为单位的旋转角度。
  8172. */
  8173. __proto.rotateEx=function(angle){
  8174. var cos=Math.cos(angle);
  8175. var sin=Math.sin(angle);
  8176. var ba=this.a,bb=this.b,bc=this.c,bd=this.d;
  8177. if (bb!==0 || bc!==0){
  8178. this.a=cos *ba+sin *bc;
  8179. this.b=cos *bb+sin *bd;
  8180. this.c=-sin *ba+cos *bc;
  8181. this.d=-sin *bb+cos *bd;
  8182. }else {
  8183. this.a=cos *ba;
  8184. this.b=sin *bd;
  8185. this.c=-sin *ba;
  8186. this.d=cos *bd;
  8187. }
  8188. this._bTransform=true;
  8189. }
  8190. /**
  8191. *返回此 Matrix 对象的副本。
  8192. *@return 与原始实例具有完全相同的属性的新 Matrix 实例。
  8193. */
  8194. __proto.clone=function(){
  8195. var dec=Matrix.create();
  8196. dec.a=this.a;
  8197. dec.b=this.b;
  8198. dec.c=this.c;
  8199. dec.d=this.d;
  8200. dec.tx=this.tx;
  8201. dec.ty=this.ty;
  8202. dec._bTransform=this._bTransform;
  8203. return dec;
  8204. }
  8205. /**
  8206. *将当前 Matrix 对象中的所有矩阵数据复制到指定的 Matrix 对象中。
  8207. *@param dec 要复制当前矩阵数据的 Matrix 对象。
  8208. *@return 已复制当前矩阵数据的 Matrix 对象。
  8209. */
  8210. __proto.copyTo=function(dec){
  8211. dec.a=this.a;
  8212. dec.b=this.b;
  8213. dec.c=this.c;
  8214. dec.d=this.d;
  8215. dec.tx=this.tx;
  8216. dec.ty=this.ty;
  8217. dec._bTransform=this._bTransform;
  8218. return dec;
  8219. }
  8220. /**
  8221. *返回列出该 Matrix 对象属性的文本值。
  8222. *@return 一个字符串,它包含 Matrix 对象的属性值:a、b、c、d、tx 和 ty。
  8223. */
  8224. __proto.toString=function(){
  8225. return this.a+","+this.b+","+this.c+","+this.d+","+this.tx+","+this.ty;
  8226. }
  8227. /**
  8228. *销毁此对象。
  8229. */
  8230. __proto.destroy=function(){
  8231. this.recover();
  8232. }
  8233. /**
  8234. *回收到对象池,方便复用
  8235. */
  8236. __proto.recover=function(){
  8237. Pool.recover("Matrix",this.identity());
  8238. }
  8239. Matrix.mul=function(m1,m2,out){
  8240. var aa=m1.a,ab=m1.b,ac=m1.c,ad=m1.d,atx=m1.tx,aty=m1.ty;
  8241. var ba=m2.a,bb=m2.b,bc=m2.c,bd=m2.d,btx=m2.tx,bty=m2.ty;
  8242. if (bb!==0 || bc!==0){
  8243. out.a=aa *ba+ab *bc;
  8244. out.b=aa *bb+ab *bd;
  8245. out.c=ac *ba+ad *bc;
  8246. out.d=ac *bb+ad *bd;
  8247. out.tx=ba *atx+bc *aty+btx;
  8248. out.ty=bb *atx+bd *aty+bty;
  8249. }else {
  8250. out.a=aa *ba;
  8251. out.b=ab *bd;
  8252. out.c=ac *ba;
  8253. out.d=ad *bd;
  8254. out.tx=ba *atx+btx;
  8255. out.ty=bd *aty+bty;
  8256. }
  8257. return out;
  8258. }
  8259. Matrix.mul16=function(m1,m2,out){
  8260. var aa=m1.a,ab=m1.b,ac=m1.c,ad=m1.d,atx=m1.tx,aty=m1.ty;
  8261. var ba=m2.a,bb=m2.b,bc=m2.c,bd=m2.d,btx=m2.tx,bty=m2.ty;
  8262. if (bb!==0 || bc!==0){
  8263. out[0]=aa *ba+ab *bc;
  8264. out[1]=aa *bb+ab *bd;
  8265. out[4]=ac *ba+ad *bc;
  8266. out[5]=ac *bb+ad *bd;
  8267. out[12]=ba *atx+bc *aty+btx;
  8268. out[13]=bb *atx+bd *aty+bty;
  8269. }else {
  8270. out[0]=aa *ba;
  8271. out[1]=ab *bd;
  8272. out[4]=ac *ba;
  8273. out[5]=ad *bd;
  8274. out[12]=ba *atx+btx;
  8275. out[13]=bd *aty+bty;
  8276. }
  8277. return out;
  8278. }
  8279. Matrix.create=function(){
  8280. return Pool.getItemByClass("Matrix",Matrix);
  8281. }
  8282. Matrix.EMPTY=new Matrix();
  8283. Matrix.TEMP=new Matrix();
  8284. Matrix._createFun=null;
  8285. return Matrix;
  8286. })()
  8287. //class laya.utils.PerfData
  8288. var PerfData=(function(){
  8289. function PerfData(id,color,name,scale){
  8290. this.id=0;
  8291. this.name=null;
  8292. this.color=0;
  8293. this.scale=1.0;
  8294. this.datapos=0;
  8295. this.datas=new Array(PerfHUD.DATANUM);
  8296. this.id=id;
  8297. this.color=color;
  8298. this.name=name;
  8299. this.scale=scale;
  8300. }
  8301. __class(PerfData,'laya.utils.PerfData');
  8302. var __proto=PerfData.prototype;
  8303. __proto.addData=function(v){
  8304. this.datas[this.datapos]=v;
  8305. this.datapos++;
  8306. this.datapos %=PerfHUD.DATANUM;
  8307. }
  8308. return PerfData;
  8309. })()
  8310. /**
  8311. *矩阵命令
  8312. */
  8313. //class laya.display.cmd.TransformCmd
  8314. var TransformCmd=(function(){
  8315. function TransformCmd(){
  8316. /**
  8317. *矩阵。
  8318. */
  8319. //this.matrix=null;
  8320. /**
  8321. *(可选)水平方向轴心点坐标。
  8322. */
  8323. //this.pivotX=NaN;
  8324. /**
  8325. *(可选)垂直方向轴心点坐标。
  8326. */
  8327. //this.pivotY=NaN;
  8328. }
  8329. __class(TransformCmd,'laya.display.cmd.TransformCmd');
  8330. var __proto=TransformCmd.prototype;
  8331. /**
  8332. *回收到对象池
  8333. */
  8334. __proto.recover=function(){
  8335. this.matrix=null;
  8336. Pool.recover("TransformCmd",this);
  8337. }
  8338. /**@private */
  8339. __proto.run=function(context,gx,gy){
  8340. context._transform(this.matrix,this.pivotX+gx,this.pivotY+gy);
  8341. }
  8342. /**@private */
  8343. __getset(0,__proto,'cmdID',function(){
  8344. return "Transform";
  8345. });
  8346. TransformCmd.create=function(matrix,pivotX,pivotY){
  8347. var cmd=Pool.getItemByClass("TransformCmd",TransformCmd);
  8348. cmd.matrix=matrix;
  8349. cmd.pivotX=pivotX;
  8350. cmd.pivotY=pivotY;
  8351. return cmd;
  8352. }
  8353. TransformCmd.ID="Transform";
  8354. return TransformCmd;
  8355. })()
  8356. /**
  8357. *根据坐标集合绘制多个贴图
  8358. */
  8359. //class laya.display.cmd.DrawTexturesCmd
  8360. var DrawTexturesCmd=(function(){
  8361. function DrawTexturesCmd(){
  8362. /**
  8363. *纹理。
  8364. */
  8365. //this.texture=null;
  8366. /**
  8367. *绘制次数和坐标。
  8368. */
  8369. //this.pos=null;
  8370. }
  8371. __class(DrawTexturesCmd,'laya.display.cmd.DrawTexturesCmd');
  8372. var __proto=DrawTexturesCmd.prototype;
  8373. /**
  8374. *回收到对象池
  8375. */
  8376. __proto.recover=function(){
  8377. this.texture._removeReference();
  8378. this.texture=null;
  8379. this.pos=null;
  8380. Pool.recover("DrawTexturesCmd",this);
  8381. }
  8382. /**@private */
  8383. __proto.run=function(context,gx,gy){
  8384. context.drawTextures(this.texture,this.pos,gx,gy);
  8385. }
  8386. /**@private */
  8387. __getset(0,__proto,'cmdID',function(){
  8388. return "DrawTextures";
  8389. });
  8390. DrawTexturesCmd.create=function(texture,pos){
  8391. var cmd=Pool.getItemByClass("DrawTexturesCmd",DrawTexturesCmd);
  8392. cmd.texture=texture;
  8393. texture._addReference();
  8394. cmd.pos=pos;
  8395. return cmd;
  8396. }
  8397. DrawTexturesCmd.ID="DrawTextures";
  8398. return DrawTexturesCmd;
  8399. })()
  8400. /**
  8401. *绘制圆形
  8402. */
  8403. //class laya.display.cmd.DrawCircleCmd
  8404. var DrawCircleCmd=(function(){
  8405. function DrawCircleCmd(){
  8406. /**
  8407. *圆点X 轴位置。
  8408. */
  8409. //this.x=NaN;
  8410. /**
  8411. *圆点Y 轴位置。
  8412. */
  8413. //this.y=NaN;
  8414. /**
  8415. *半径。
  8416. */
  8417. //this.radius=NaN;
  8418. /**
  8419. *填充颜色,或者填充绘图的渐变对象。
  8420. */
  8421. //this.fillColor=null;
  8422. /**
  8423. *(可选)边框颜色,或者填充绘图的渐变对象。
  8424. */
  8425. //this.lineColor=null;
  8426. /**
  8427. *(可选)边框宽度。
  8428. */
  8429. //this.lineWidth=NaN;
  8430. /**@private */
  8431. //this.vid=0;
  8432. }
  8433. __class(DrawCircleCmd,'laya.display.cmd.DrawCircleCmd');
  8434. var __proto=DrawCircleCmd.prototype;
  8435. /**
  8436. *回收到对象池
  8437. */
  8438. __proto.recover=function(){
  8439. this.fillColor=null;
  8440. this.lineColor=null;
  8441. Pool.recover("DrawCircleCmd",this);
  8442. }
  8443. /**@private */
  8444. __proto.run=function(context,gx,gy){
  8445. context._drawCircle(this.x+gx,this.y+gy,this.radius,this.fillColor,this.lineColor,this.lineWidth,this.vid);
  8446. }
  8447. /**@private */
  8448. __getset(0,__proto,'cmdID',function(){
  8449. return "DrawCircle";
  8450. });
  8451. DrawCircleCmd.create=function(x,y,radius,fillColor,lineColor,lineWidth,vid){
  8452. var cmd=Pool.getItemByClass("DrawCircleCmd",DrawCircleCmd);
  8453. cmd.x=x;
  8454. cmd.y=y;
  8455. cmd.radius=radius;
  8456. cmd.fillColor=fillColor;
  8457. cmd.lineColor=lineColor;
  8458. cmd.lineWidth=lineWidth;
  8459. cmd.vid=vid;
  8460. return cmd;
  8461. }
  8462. DrawCircleCmd.ID="DrawCircle";
  8463. return DrawCircleCmd;
  8464. })()
  8465. /**
  8466. *@private
  8467. *Context扩展类
  8468. */
  8469. //class laya.resource.Context
  8470. var Context=(function(){
  8471. var ContextParams;
  8472. function Context(){
  8473. //this._canvas=null;
  8474. this._drawTriUseAbsMatrix=false;
  8475. //还原2D视口
  8476. this._id=++Context._COUNT;
  8477. this._other=null;
  8478. this._renderNextSubmitIndex=0;
  8479. this._path=null;
  8480. //this._primitiveValue2D=null;
  8481. this._drawCount=1;
  8482. this._renderCount=0;
  8483. this._isConvexCmd=true;
  8484. //arc等是convex的,moveTo,linTo就不是了
  8485. this._submits=null;
  8486. this._curSubmit=null;
  8487. //当前将要使用的设置。用来跟上一次的_curSubmit比较
  8488. this._mesh=null;
  8489. //用Mesh2D代替_vb,_ib. 当前使用的mesh
  8490. this._pathMesh=null;
  8491. //矢量专用mesh。
  8492. this._triangleMesh=null;
  8493. //drawTriangles专用mesh。由于ib不固定,所以不能与_mesh通用
  8494. this.meshlist=[];
  8495. //用矩阵描述的clip信息。最终的点投影到这个矩阵上,在0~1之间就可见。
  8496. this._clipInCache=false;
  8497. // 当前记录的clipinfo是在cacheas normal后赋值的,因为cacheas normal会去掉当前矩阵的tx,ty,所以需要记录一下,以便在是shader中恢复
  8498. this._clipInfoID=0;
  8499. //生成clipid的,原来是 _clipInfoID=++_clipInfoID 这样会有问题,导致兄弟clip的id都相同
  8500. this._curMat=null;
  8501. //计算矩阵缩放的缓存
  8502. this._lastMatScaleX=1.0;
  8503. this._lastMatScaleY=1.0;
  8504. this._lastMat_a=1.0;
  8505. this._lastMat_b=0.0;
  8506. this._lastMat_c=0.0;
  8507. this._lastMat_d=1.0;
  8508. this._nBlendType=0;
  8509. this._save=null;
  8510. this._targets=null;
  8511. this._charSubmitCache=null;
  8512. this._saveMark=null;
  8513. /**
  8514. *所cacheAs精灵
  8515. *对于cacheas bitmap的情况,如果图片还没准备好,需要有机会重画,所以要保存sprite。例如在图片
  8516. *加载完成后,调用repaint
  8517. */
  8518. this.sprite=null;
  8519. this._italicDeg=0;
  8520. //文字的倾斜角度
  8521. this._lastTex=null;
  8522. //上次使用的texture。主要是给fillrect用,假装自己也是一个drawtexture
  8523. this._fillColor=0;
  8524. this._flushCnt=0;
  8525. this.defTexture=null;
  8526. //给fillrect用
  8527. this._colorFiler=null;
  8528. this.drawTexAlign=false;
  8529. // 按照像素对齐
  8530. this._incache=false;
  8531. // 正处在cacheas normal过程中
  8532. this.isMain=false;
  8533. this._tmpMatrix=new Matrix();
  8534. this._drawTexToDrawTri_Vert=new Float32Array(8);
  8535. this._drawTexToDrawTri_Index=new Uint16Array([0,1,2,0,2,3]);
  8536. this._tempUV=new Float32Array(8);
  8537. this._width=99999999;
  8538. this._height=99999999;
  8539. this._submitKey=new SubmitKey();
  8540. this._transedPoints=new Array(8);
  8541. this._temp4Points=new Array(8);
  8542. this._clipRect=Context.MAXCLIPRECT;
  8543. this._globalClipMatrix=new Matrix(/*CLASS CONST:laya.resource.Context._MAXSIZE*/99999999,0,0,/*CLASS CONST:laya.resource.Context._MAXSIZE*/99999999,0,0);
  8544. this._shader2D=new Shader2D();
  8545. Context._contextcount++;
  8546. if (!this.defTexture){
  8547. var defTex2d=new Texture2D(2,2);
  8548. defTex2d.setPixels(new Uint8Array(16));
  8549. defTex2d.lock=true;
  8550. this.defTexture=new Texture(defTex2d);
  8551. }
  8552. this._lastTex=this.defTexture;
  8553. this.clear();
  8554. }
  8555. __class(Context,'laya.resource.Context');
  8556. var __proto=Context.prototype;
  8557. /**@private */
  8558. __proto.drawImage=function(__args){}
  8559. /**@private */
  8560. __proto.getImageData=function(__args){}
  8561. /**@private */
  8562. __proto.measureText=function(text){
  8563. return null;
  8564. }
  8565. /**@private */
  8566. __proto.setTransform=function(__args){}
  8567. /**@private */
  8568. __proto.$transform=function(a,b,c,d,tx,ty){}
  8569. /**@private */
  8570. __proto.clearRect=function(x,y,width,height){}
  8571. //TODO:coverage
  8572. __proto._drawRect=function(x,y,width,height,style){
  8573. Stat.renderBatches++;
  8574. style && (this.fillStyle=style);
  8575. /*__JS__ */this.fillRect(x,y,width,height);
  8576. }
  8577. //TODO:coverage
  8578. __proto.drawTexture2=function(x,y,pivotX,pivotY,m,args2){}
  8579. //=============新增==================
  8580. __proto.transformByMatrix=function(matrix,tx,ty){
  8581. this.transform(matrix.a,matrix.b,matrix.c,matrix.d,matrix.tx+tx,matrix.ty+ty);
  8582. }
  8583. __proto.saveTransform=function(matrix){
  8584. this.save();
  8585. }
  8586. __proto.restoreTransform=function(matrix){
  8587. this.restore();
  8588. }
  8589. __proto.drawRect=function(x,y,width,height,fillColor,lineColor,lineWidth){
  8590. var ctx=this;
  8591. if (fillColor !=null){
  8592. ctx.fillStyle=fillColor;
  8593. ctx.fillRect(x,y,width,height);
  8594. }
  8595. if (lineColor !=null){
  8596. ctx.strokeStyle=lineColor;
  8597. ctx.lineWidth=lineWidth;
  8598. ctx.strokeRect(x,y,width,height);
  8599. }
  8600. }
  8601. __proto.alpha=function(value){
  8602. this.globalAlpha *=value;
  8603. }
  8604. //TODO:coverage
  8605. __proto._transform=function(mat,pivotX,pivotY){
  8606. this.translate(pivotX,pivotY);
  8607. this.transform(mat.a,mat.b,mat.c,mat.d,mat.tx,mat.ty);
  8608. this.translate(-pivotX,-pivotY);
  8609. }
  8610. __proto._rotate=function(angle,pivotX,pivotY){
  8611. this.translate(pivotX,pivotY);
  8612. this.rotate(angle);
  8613. this.translate(-pivotX,-pivotY);
  8614. }
  8615. __proto._scale=function(scaleX,scaleY,pivotX,pivotY){
  8616. this.translate(pivotX,pivotY);
  8617. this.scale(scaleX,scaleY);
  8618. this.translate(-pivotX,-pivotY);
  8619. }
  8620. __proto._drawLine=function(x,y,fromX,fromY,toX,toY,lineColor,lineWidth,vid){
  8621. this.beginPath();
  8622. this.strokeStyle=lineColor;
  8623. this.lineWidth=lineWidth;
  8624. this.moveTo(x+fromX,y+fromY);
  8625. this.lineTo(x+toX,y+toY);
  8626. this.stroke();
  8627. }
  8628. __proto._drawLines=function(x,y,points,lineColor,lineWidth,vid){
  8629. this.beginPath();
  8630. this.strokeStyle=lineColor;
  8631. this.lineWidth=lineWidth;
  8632. var i=2,n=points.length;
  8633. this.addPath(points.slice(),false,false,x,y);
  8634. this.stroke();
  8635. }
  8636. __proto.drawCurves=function(x,y,points,lineColor,lineWidth){
  8637. this.beginPath();
  8638. this.strokeStyle=lineColor;
  8639. this.lineWidth=lineWidth;
  8640. this.moveTo(x+points[0],y+points[1]);
  8641. var i=2,n=points.length;
  8642. while (i < n){
  8643. this.quadraticCurveTo(x+points[i++],y+points[i++],x+points[i++],y+points[i++]);
  8644. }
  8645. this.stroke();
  8646. }
  8647. __proto._fillAndStroke=function(fillColor,strokeColor,lineWidth,isConvexPolygon){
  8648. (isConvexPolygon===void 0)&& (isConvexPolygon=false);
  8649. if (fillColor !=null){
  8650. this.fillStyle=fillColor;
  8651. this.fill();
  8652. }
  8653. if (strokeColor !=null && lineWidth > 0){
  8654. this.strokeStyle=strokeColor;
  8655. this.lineWidth=lineWidth;
  8656. this.stroke();
  8657. }
  8658. }
  8659. __proto._drawCircle=function(x,y,radius,fillColor,lineColor,lineWidth,vid){
  8660. Stat.renderBatches++;
  8661. this.beginPath(true);
  8662. this.arc(x,y,radius,0,Context.PI2);
  8663. this.closePath();
  8664. this._fillAndStroke(fillColor,lineColor,lineWidth);
  8665. }
  8666. //矢量方法
  8667. __proto._drawPie=function(x,y,radius,startAngle,endAngle,fillColor,lineColor,lineWidth,vid){
  8668. this.beginPath();
  8669. this.moveTo(x ,y);
  8670. this.arc(x,y,radius,startAngle,endAngle);
  8671. this.closePath();
  8672. this._fillAndStroke(fillColor,lineColor,lineWidth);
  8673. }
  8674. //ctx.translate(-x-args[0],-y-args[1]);
  8675. __proto._drawPoly=function(x,y,points,fillColor,lineColor,lineWidth,isConvexPolygon,vid){
  8676. var i=2,n=points.length;
  8677. this.beginPath();
  8678. this.addPath(points.slice(),true,isConvexPolygon,x,y);
  8679. this.closePath();
  8680. this._fillAndStroke(fillColor,lineColor,lineWidth,isConvexPolygon);
  8681. }
  8682. __proto._drawPath=function(x,y,paths,brush,pen){
  8683. this.beginPath();
  8684. for (var i=0,n=paths.length;i < n;i++){
  8685. var path=paths[i];
  8686. switch (path[0]){
  8687. case "moveTo":
  8688. this.moveTo(x+path[1],y+path[2]);
  8689. break ;
  8690. case "lineTo":
  8691. this.lineTo(x+path[1],y+path[2]);
  8692. break ;
  8693. case "arcTo":
  8694. this.arcTo(x+path[1],y+path[2],x+path[3],y+path[4],path[5]);
  8695. break ;
  8696. case "closePath":
  8697. this.closePath();
  8698. break ;
  8699. }
  8700. }
  8701. if (brush !=null){
  8702. this.fillStyle=brush.fillStyle;
  8703. this.fill();
  8704. }
  8705. if (pen !=null){
  8706. this.strokeStyle=pen.strokeStyle;
  8707. this.lineWidth=pen.lineWidth || 1;
  8708. this.lineJoin=pen.lineJoin;
  8709. this.lineCap=pen.lineCap;
  8710. this.miterLimit=pen.miterLimit;
  8711. this.stroke();
  8712. }
  8713. }
  8714. __proto.clearBG=function(r,g,b,a){
  8715. var gl=WebGL.mainContext;
  8716. gl.clearColor(r,g,b,a);
  8717. gl.clear(/*laya.webgl.WebGLContext.COLOR_BUFFER_BIT*/0x00004000);
  8718. }
  8719. //TODO:coverage
  8720. __proto._getSubmits=function(){
  8721. return this._submits;
  8722. }
  8723. /**
  8724. *释放占用内存
  8725. *@param keepRT 是否保留rendertarget
  8726. */
  8727. __proto._releaseMem=function(keepRT){
  8728. (keepRT===void 0)&& (keepRT=false);
  8729. if (!this._submits)
  8730. return;
  8731. this._curMat.destroy();
  8732. this._curMat=null;
  8733. this._shader2D.destroy();
  8734. this._shader2D=null;
  8735. this._charSubmitCache.clear();
  8736. for (var i=0,n=this._submits._length;i < n;i++){
  8737. this._submits[i].releaseRender();
  8738. }
  8739. this._submits.length=0;
  8740. this._submits._length=0;
  8741. this._submits=null;
  8742. this._curSubmit=null;
  8743. this._path=null;
  8744. this._save=null;
  8745. var sz=0;
  8746. for (i=0,sz=this.meshlist.length;i < sz;i++){
  8747. var curm=this.meshlist[i];
  8748. curm.destroy();
  8749. }
  8750. this.meshlist.length=0;
  8751. this.sprite=null;
  8752. if(!keepRT){
  8753. this._targets && (this._targets.destroy());
  8754. this._targets=null;
  8755. }
  8756. }
  8757. /**
  8758. *释放所有资源
  8759. *@param keepRT 是否保留rendertarget
  8760. */
  8761. __proto.destroy=function(keepRT){
  8762. (keepRT===void 0)&& (keepRT=false);
  8763. --Context._contextcount;
  8764. this.sprite=null;
  8765. this._releaseMem(keepRT);
  8766. this._charSubmitCache.destroy();
  8767. this._mesh.destroy();
  8768. if(!keepRT){
  8769. this._targets && this._targets.destroy();
  8770. this._targets=null;
  8771. }
  8772. }
  8773. __proto.clear=function(){
  8774. if (!this._submits){
  8775. this._other=ContextParams.DEFAULT;
  8776. this._curMat=Matrix.create();
  8777. this._charSubmitCache=new CharSubmitCache();
  8778. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  8779. this.meshlist.push(this._mesh);
  8780. this._pathMesh=MeshVG.getAMesh(this.isMain);
  8781. this.meshlist.push(this._pathMesh);
  8782. this._triangleMesh=MeshTexture.getAMesh(this.isMain);
  8783. this.meshlist.push(this._triangleMesh);
  8784. this._submits=[];
  8785. this._save=[SaveMark.Create(this)];
  8786. this._save.length=10;
  8787. this._shader2D=new Shader2D();
  8788. }
  8789. this._submitKey.clear();
  8790. this._mesh.clearVB();
  8791. this._renderCount++;
  8792. this._drawCount=1;
  8793. this._other=ContextParams.DEFAULT;
  8794. this._other.lineWidth=this._shader2D.ALPHA=1.0;
  8795. this._nBlendType=0;
  8796. this._clipRect=Context.MAXCLIPRECT;
  8797. this._curSubmit=Submit.RENDERBASE;
  8798. Submit.RENDERBASE._ref=0xFFFFFF;
  8799. Submit.RENDERBASE._numEle=0;
  8800. this._shader2D.fillStyle=this._shader2D.strokeStyle=DrawStyle.DEFAULT;
  8801. for (var i=0,n=this._submits._length;i < n;i++)
  8802. this._submits[i].releaseRender();
  8803. this._submits._length=0;
  8804. this._curMat.identity();
  8805. this._other.clear();
  8806. this._saveMark=this._save[0];
  8807. this._save._length=1;
  8808. }
  8809. /**
  8810. *设置ctx的size,这个不允许直接设置,必须是canvas调过来的。所以这个函数里也不用考虑canvas相关的东西
  8811. *@param w
  8812. *@param h
  8813. */
  8814. __proto.size=function(w,h){
  8815. if (this._width !=w || this._height !=h){
  8816. this._width=w;
  8817. this._height=h;
  8818. if (this._targets){
  8819. this._targets.destroy();
  8820. this._targets=new RenderTexture2D(w,h,/*laya.resource.BaseTexture.FORMAT_R8G8B8A8*/1,-1);
  8821. }
  8822. if (Render._context==this){
  8823. WebGL.mainContext.viewport(0,0,w,h);
  8824. RenderState2D.width=w;
  8825. RenderState2D.height=h;
  8826. }
  8827. }
  8828. if (w===0 && h===0)this._releaseMem();
  8829. }
  8830. /**
  8831. *获得当前矩阵的缩放值
  8832. *避免每次都计算getScaleX
  8833. *@return
  8834. */
  8835. __proto.getMatScaleX=function(){
  8836. if (this._lastMat_a==this._curMat.a && this._lastMat_b==this._curMat.b)
  8837. return this._lastMatScaleX;
  8838. this._lastMatScaleX=this._curMat.getScaleX();
  8839. this._lastMat_a=this._curMat.a;
  8840. this._lastMat_b=this._curMat.b;
  8841. return this._lastMatScaleX;
  8842. }
  8843. __proto.getMatScaleY=function(){
  8844. if (this._lastMat_c==this._curMat.c && this._lastMat_d==this._curMat.d)
  8845. return this._lastMatScaleY;
  8846. this._lastMatScaleY=this._curMat.getScaleY();
  8847. this._lastMat_c=this._curMat.c;
  8848. this._lastMat_d=this._curMat.d;
  8849. return this._lastMatScaleY;
  8850. }
  8851. //TODO
  8852. __proto.setFillColor=function(color){
  8853. this._fillColor=color;
  8854. }
  8855. __proto.getFillColor=function(){
  8856. return this._fillColor;
  8857. }
  8858. __proto.translate=function(x,y){
  8859. if (x!==0 || y!==0){
  8860. SaveTranslate.save(this);
  8861. if (this._curMat._bTransform){
  8862. SaveTransform.save(this);
  8863. this._curMat.tx+=(x *this._curMat.a+y *this._curMat.c);
  8864. this._curMat.ty+=(x *this._curMat.b+y *this._curMat.d);
  8865. }else {
  8866. this._curMat.tx=x;
  8867. this._curMat.ty=y;
  8868. }
  8869. }
  8870. }
  8871. __proto.save=function(){
  8872. this._save[this._save._length++]=SaveMark.Create(this);
  8873. }
  8874. __proto.restore=function(){
  8875. var sz=this._save._length;
  8876. var lastBlend=this._nBlendType;
  8877. if (sz < 1)
  8878. return;
  8879. for (var i=sz-1;i >=0;i--){
  8880. var o=this._save[i];
  8881. o.restore(this);
  8882. if (o.isSaveMark()){
  8883. this._save._length=i;
  8884. return;
  8885. }
  8886. }
  8887. if (lastBlend !=this._nBlendType){
  8888. this._curSubmit=Submit.RENDERBASE;
  8889. }
  8890. }
  8891. //TODO:coverage
  8892. __proto.fillText=function(txt,x,y,fontStr,color,align){
  8893. this._fillText(txt,null,x,y,fontStr,color,null,0,null);
  8894. }
  8895. /**
  8896. *
  8897. *@param txt
  8898. *@param words HTMLChar 数组,是已经在外面排好版的一个数组
  8899. *@param x
  8900. *@param y
  8901. *@param fontStr
  8902. *@param color
  8903. *@param strokeColor
  8904. *@param lineWidth
  8905. *@param textAlign
  8906. *@param underLine
  8907. */
  8908. __proto._fillText=function(txt,words,x,y,fontStr,color,strokeColor,lineWidth,textAlign,underLine){
  8909. (underLine===void 0)&& (underLine=0);
  8910. if (txt)
  8911. Context._textRender.filltext(this,txt,x,y,fontStr,color,strokeColor,lineWidth,textAlign,underLine);
  8912. else if(words)
  8913. Context._textRender.fillWords(this,words,x,y,fontStr,color,strokeColor,lineWidth);
  8914. }
  8915. __proto._fast_filltext=function(data,x,y,fontObj,color,strokeColor,lineWidth,textAlign,underLine){
  8916. (underLine===void 0)&& (underLine=0);
  8917. Context._textRender._fast_filltext(this,data,null,x,y,fontObj,color,strokeColor,lineWidth,textAlign,underLine);
  8918. }
  8919. //TODO:coverage
  8920. __proto.fillWords=function(words,x,y,fontStr,color){
  8921. this._fillText(null,words,x,y,fontStr,color,null,-1,null,0);
  8922. }
  8923. //TODO:coverage
  8924. __proto.fillBorderWords=function(words,x,y,font,color,borderColor,lineWidth){
  8925. this._fillBorderText(null,words,x,y,font,color,borderColor,lineWidth,null);
  8926. }
  8927. __proto.drawText=function(text,x,y,font,color,textAlign){
  8928. this._fillText(text,null,x,y,font,ColorUtils.create(color).strColor,null,-1,textAlign);
  8929. }
  8930. /**
  8931. *只画边框
  8932. *@param text
  8933. *@param x
  8934. *@param y
  8935. *@param font
  8936. *@param color
  8937. *@param lineWidth
  8938. *@param textAlign
  8939. */
  8940. __proto.strokeWord=function(text,x,y,font,color,lineWidth,textAlign){
  8941. this._fillText(text,null,x,y,font,null,ColorUtils.create(color).strColor,lineWidth || 1,textAlign);
  8942. }
  8943. /**
  8944. *即画文字又画边框
  8945. *@param txt
  8946. *@param x
  8947. *@param y
  8948. *@param fontStr
  8949. *@param fillColor
  8950. *@param borderColor
  8951. *@param lineWidth
  8952. *@param textAlign
  8953. */
  8954. __proto.fillBorderText=function(txt,x,y,fontStr,fillColor,borderColor,lineWidth,textAlign){
  8955. this._fillBorderText(txt,null,x,y,fontStr,ColorUtils.create(fillColor).strColor,ColorUtils.create(borderColor).strColor,lineWidth,textAlign);
  8956. }
  8957. __proto._fillBorderText=function(txt,words,x,y,fontStr,fillColor,borderColor,lineWidth,textAlign){
  8958. this._fillText(txt,words,x,y,fontStr,fillColor,borderColor,lineWidth || 1,textAlign);
  8959. }
  8960. __proto._fillRect=function(x,y,width,height,rgba){
  8961. var submit=this._curSubmit;
  8962. var sameKey=submit && (submit._key.submitType===/*laya.webgl.submit.Submit.KEY_DRAWTEXTURE*/2 && submit._key.blendShader===this._nBlendType);
  8963. if (this._mesh.vertNum+4 > 65535){
  8964. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  8965. this.meshlist.push(this._mesh);
  8966. sameKey=false;
  8967. }
  8968. sameKey && (sameKey=sameKey&& this.isSameClipInfo(submit));
  8969. this.transformQuad(x,y,width,height,0,this._curMat,this._transedPoints);
  8970. if(!this.clipedOff(this._transedPoints)){
  8971. this._mesh.addQuad(this._transedPoints,Texture.NO_UV,rgba,false);
  8972. if (!sameKey){
  8973. submit=this._curSubmit=SubmitTexture.create(this,this._mesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  8974. this._submits[this._submits._length++]=submit;
  8975. this._copyClipInfo(submit,this._globalClipMatrix);
  8976. submit.shaderValue.textureHost=this._lastTex;
  8977. submit._key.other=(this._lastTex && this._lastTex.bitmap)?this._lastTex.bitmap.id:-1
  8978. submit._renderType=/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016;
  8979. }
  8980. this._curSubmit._numEle+=6;
  8981. this._mesh.indexNum+=6;
  8982. this._mesh.vertNum+=4;
  8983. }
  8984. }
  8985. __proto.fillRect=function(x,y,width,height,fillStyle){
  8986. var drawstyle=fillStyle? DrawStyle.create(fillStyle):this._shader2D.fillStyle;
  8987. var rgba=this.mixRGBandAlpha(drawstyle.toInt());
  8988. this._fillRect(x,y,width,height,rgba);
  8989. }
  8990. //TODO:coverage
  8991. __proto.fillTexture=function(texture,x,y,width,height,type,offset,other){
  8992. if (!texture._getSource()){
  8993. this.sprite && Laya.systemTimer.callLater(this,this._repaintSprite);
  8994. return;
  8995. }
  8996. this._fillTexture(texture,texture.width,texture.height,texture.uvrect,x,y,width,height,type,offset.x,offset.y);
  8997. }
  8998. __proto._fillTexture=function(texture,texw,texh,texuvRect,x,y,width,height,type,offsetx,offsety){
  8999. var submit=this._curSubmit;
  9000. var sameKey=false;
  9001. if (this._mesh.vertNum+4 > 65535){
  9002. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  9003. this.meshlist.push(this._mesh);
  9004. sameKey=false;
  9005. };
  9006. var repeatx=true;
  9007. var repeaty=true;
  9008. switch(type){
  9009. case "repeat":break ;
  9010. case "repeat-x":repeaty=false;break ;
  9011. case "repeat-y":repeatx=false;break ;
  9012. case "no-repeat":repeatx=repeaty=false;break ;
  9013. default :break ;
  9014. };
  9015. var uv=this._temp4Points;
  9016. var stu=0;
  9017. var stv=0;
  9018. var stx=0,sty=0,edx=0,edy=0;
  9019. if (offsetx < 0){
  9020. stx=x;
  9021. stu=(-offsetx %texw)/ texw;
  9022. }else {
  9023. stx=x+offsetx;
  9024. }
  9025. if (offsety < 0){
  9026. sty=y;
  9027. stv=(-offsety %texh)/ texh;
  9028. }else {
  9029. sty=y+offsety;
  9030. }
  9031. edx=x+width;
  9032. edy=y+height;
  9033. (!repeatx)&& (edx=Math.min(edx,x+offsetx+texw));
  9034. (!repeaty)&& (edy=Math.min(edy,y+offsety+texh));
  9035. if (edx < x || edy < y)
  9036. return;
  9037. if (stx > edx || sty > edy)
  9038. return;
  9039. var edu=(edx-x-offsetx)/texw;
  9040. var edv=(edy-y-offsety)/ texh;
  9041. this.transformQuad(stx,sty,edx-stx,edy-sty,0,this._curMat,this._transedPoints);
  9042. uv[0]=stu;uv[1]=stv;uv[2]=edu;uv[3]=stv;uv[4]=edu;uv[5]=edv;uv[6]=stu;uv[7]=edv;
  9043. if (!this.clipedOff(this._transedPoints)){
  9044. var rgba=this._mixRGBandAlpha(0xffffffff,this._shader2D.ALPHA);
  9045. this._mesh.addQuad(this._transedPoints,uv,rgba,true);
  9046. var sv=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  9047. sv.defines.add(/*laya.webgl.shader.d2.ShaderDefines2D.FILLTEXTURE*/0x100);
  9048. (sv).u_TexRange=texuvRect;
  9049. submit=this._curSubmit=SubmitTexture.create(this,this._mesh,sv);
  9050. this._submits[this._submits._length++]=submit;
  9051. this._copyClipInfo(submit,this._globalClipMatrix);
  9052. submit.shaderValue.textureHost=texture;
  9053. submit._renderType=/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016;
  9054. this._curSubmit._numEle+=6;
  9055. this._mesh.indexNum+=6;
  9056. this._mesh.vertNum+=4;
  9057. }
  9058. this.breakNextMerge();
  9059. }
  9060. /**
  9061. *反正只支持一种filter,就不要叫setFilter了,直接叫setColorFilter
  9062. *@param value
  9063. */
  9064. __proto.setColorFilter=function(filter){
  9065. SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_COLORFILTER*/0x800000,this,true);
  9066. this._colorFiler=filter;
  9067. this._curSubmit=Submit.RENDERBASE;
  9068. }
  9069. //_reCalculateBlendShader();
  9070. __proto.drawTexture=function(tex,x,y,width,height){
  9071. this._drawTextureM(tex,x,y,width,height,null,1,null);
  9072. }
  9073. __proto.drawTextures=function(tex,pos,tx,ty){
  9074. if (!tex._getSource()){
  9075. this.sprite && Laya.systemTimer.callLater(this,this._repaintSprite);
  9076. return;
  9077. };
  9078. var n=pos.length / 2;
  9079. var ipos=0;
  9080. var bmpid=tex.bitmap.id;
  9081. for (var i=0;i < n;i++){
  9082. this._inner_drawTexture(tex,bmpid,pos[ipos++]+tx,pos[ipos++]+ty,0,0,null,null,1.0,false);
  9083. }
  9084. }
  9085. //TODO:coverage
  9086. __proto._drawTextureAddSubmit=function(imgid,tex){
  9087. var submit=null;
  9088. submit=SubmitTexture.create(this,this._mesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  9089. this._submits[this._submits._length++]=submit;
  9090. submit.shaderValue.textureHost=tex;
  9091. submit._key.other=imgid;
  9092. submit._renderType=/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016;
  9093. this._curSubmit=submit;
  9094. }
  9095. //shader.ALPHA=alphaBack;
  9096. __proto._drawTextureM=function(tex,x,y,width,height,m,alpha,uv){
  9097. var cs=this.sprite;
  9098. if (!tex._getSource(function(){
  9099. if (cs){
  9100. cs.repaint();
  9101. }
  9102. })){
  9103. return false;
  9104. }
  9105. return this._inner_drawTexture(tex,tex.bitmap.id,x,y,width,height,m,uv,alpha,false);
  9106. }
  9107. __proto._drawRenderTexture=function(tex,x,y,width,height,m,alpha,uv){
  9108. return this._inner_drawTexture(tex,-1,x,y,width,height,m,uv,1.0,false);
  9109. }
  9110. //TODO:coverage
  9111. __proto.submitDebugger=function(){
  9112. this._submits[this._submits._length++]=SubmitCMD.create([],function(){debugger;},this);
  9113. }
  9114. /*
  9115. private function copyClipInfo(submit:Submit,clipInfo:Array):void {
  9116. var cd:Array=submit.shaderValue.clipDir;
  9117. cd[0]=clipInfo[2];cd[1]=clipInfo[3];cd[2]=clipInfo[4];cd[3]=clipInfo[5];
  9118. var cp:Array=submit.shaderValue.clipRect;
  9119. cp[0]=clipInfo[0];cp[1]=clipInfo[1];
  9120. submit.clipInfoID=this._clipInfoID;
  9121. }
  9122. */
  9123. __proto._copyClipInfo=function(submit,clipInfo){
  9124. var cm=submit.shaderValue.clipMatDir;
  9125. cm[0]=clipInfo.a;cm[1]=clipInfo.b;cm[2]=clipInfo.c;cm[3]=clipInfo.d;
  9126. var cmp=submit.shaderValue.clipMatPos;
  9127. cmp[0]=clipInfo.tx;cmp[1]=clipInfo.ty;
  9128. submit.clipInfoID=this._clipInfoID;
  9129. if (this._clipInCache){
  9130. submit.shaderValue.clipOff[0]=1;
  9131. }
  9132. }
  9133. __proto.isSameClipInfo=function(submit){
  9134. return (submit.clipInfoID===this._clipInfoID);
  9135. }
  9136. /**
  9137. *这个还是会检查是否合并
  9138. *@param tex
  9139. *@param minVertNum
  9140. */
  9141. __proto._useNewTex2DSubmit=function(tex,minVertNum){
  9142. if (this._mesh.vertNum+minVertNum > 65535){
  9143. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  9144. this.meshlist.push(this._mesh);
  9145. };
  9146. var submit=SubmitTexture.create(this,this._mesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  9147. this._submits[this._submits._length++]=this._curSubmit=submit;
  9148. submit.shaderValue.textureHost=tex;
  9149. this._copyClipInfo(submit,this._globalClipMatrix);
  9150. }
  9151. /**
  9152. *使用上面的设置(texture,submit,alpha,clip),画一个rect
  9153. */
  9154. __proto._drawTexRect=function(x,y,w,h,uv){
  9155. this.transformQuad(x,y,w,h,this._italicDeg,this._curMat,this._transedPoints);
  9156. var ops=this._transedPoints;
  9157. ops[0]=(ops[0]+0.5)| 0;
  9158. ops[1]=(ops[1]+0.5)| 0;
  9159. ops[2]=(ops[2]+0.5)| 0;
  9160. ops[3]=(ops[3]+0.5)| 0;
  9161. ops[4]=(ops[4]+0.5)| 0;
  9162. ops[5]=(ops[5]+0.5)| 0;
  9163. ops[6]=(ops[6]+0.5)| 0;
  9164. ops[7]=(ops[7]+0.5)| 0;
  9165. if (!this.clipedOff(this._transedPoints)){
  9166. this._mesh.addQuad(this._transedPoints,uv ,this._fillColor,true);
  9167. this._curSubmit._numEle+=6;
  9168. this._mesh.indexNum+=6;
  9169. this._mesh.vertNum+=4;
  9170. }
  9171. }
  9172. __proto.drawCallOptimize=function(enbale){
  9173. this._charSubmitCache.enable(enbale,this);
  9174. return enbale;
  9175. }
  9176. /**
  9177. *
  9178. *@param tex {Texture | RenderTexture }
  9179. *@param imgid 图片id用来比较合并的
  9180. *@param x
  9181. *@param y
  9182. *@param width
  9183. *@param height
  9184. *@param m
  9185. *@param alpha
  9186. *@param uv
  9187. *@return
  9188. */
  9189. __proto._inner_drawTexture=function(tex,imgid,x,y,width,height,m,uv,alpha,lastRender){
  9190. var preKey=this._curSubmit._key;
  9191. uv=uv || /*__JS__ */tex._uv
  9192. if (preKey.submitType===/*laya.webgl.submit.Submit.KEY_TRIANGLES*/4 && preKey.other===imgid){
  9193. var tv=this._drawTexToDrawTri_Vert;
  9194. 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;
  9195. this._drawTriUseAbsMatrix=true;
  9196. var tuv=this._tempUV;
  9197. 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];
  9198. this.drawTriangles(tex,0,0,tv,tuv,this._drawTexToDrawTri_Index,m,alpha,null,null);
  9199. this._drawTriUseAbsMatrix=false;
  9200. return true;
  9201. };
  9202. var mesh=this._mesh;
  9203. var submit=this._curSubmit;
  9204. var ops=lastRender?this._charSubmitCache.getPos():this._transedPoints;
  9205. this.transformQuad(x,y,width || tex.width,height || tex.height,this._italicDeg,m || this._curMat,ops);
  9206. if (this.drawTexAlign){
  9207. var round=Math.round;
  9208. ops[0]=round(ops[0]);
  9209. ops[1]=round(ops[1]);
  9210. ops[2]=round(ops[2]);
  9211. ops[3]=round(ops[3]);
  9212. ops[4]=round(ops[4]);
  9213. ops[5]=round(ops[5]);
  9214. ops[6]=round(ops[6]);
  9215. ops[7]=round(ops[7]);
  9216. this.drawTexAlign=false;
  9217. };
  9218. var rgba=this._mixRGBandAlpha(0xffffffff,this._shader2D.ALPHA *alpha);
  9219. if (lastRender){
  9220. this._charSubmitCache.add(this,tex,imgid,ops,uv ,rgba);
  9221. return true;
  9222. }
  9223. this._drawCount++;
  9224. var sameKey=imgid >=0 && preKey.submitType===/*laya.webgl.submit.Submit.KEY_DRAWTEXTURE*/2 && preKey.other===imgid;
  9225. sameKey && (sameKey=sameKey&& this.isSameClipInfo(submit));
  9226. this._lastTex=tex;
  9227. if (mesh.vertNum+4 > 65535){
  9228. mesh=this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  9229. this.meshlist.push(mesh);
  9230. sameKey=false;
  9231. }{
  9232. mesh.addQuad(ops,uv ,rgba,true);
  9233. if (!sameKey){
  9234. this._submits[this._submits._length++]=this._curSubmit=submit=SubmitTexture.create(this,mesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  9235. submit.shaderValue.textureHost=tex;
  9236. submit._key.other=imgid;
  9237. this._copyClipInfo(submit,this._globalClipMatrix);
  9238. }
  9239. submit._numEle+=6;
  9240. mesh.indexNum+=6;
  9241. mesh.vertNum+=4;
  9242. return true;
  9243. }
  9244. return false;
  9245. }
  9246. /**
  9247. *转换4个顶点。为了效率这个不做任何检查。需要调用者的配合。
  9248. *@param a 输入。8个元素表示4个点
  9249. *@param out 输出
  9250. */
  9251. __proto.transform4Points=function(a,m,out){
  9252. var tx=m.tx;
  9253. var ty=m.ty;
  9254. var ma=m.a;
  9255. var mb=m.b;
  9256. var mc=m.c;
  9257. var md=m.d;
  9258. var a0=a[0];
  9259. var a1=a[1];
  9260. var a2=a[2];
  9261. var a3=a[3];
  9262. var a4=a[4];
  9263. var a5=a[5];
  9264. var a6=a[6];
  9265. var a7=a[7];
  9266. if (m._bTransform){
  9267. out[0]=a0 *ma+a1 *mc+tx;out[1]=a0 *mb+a1 *md+ty;
  9268. out[2]=a2 *ma+a3 *mc+tx;out[3]=a2 *mb+a3 *md+ty;
  9269. out[4]=a4 *ma+a5 *mc+tx;out[5]=a4 *mb+a5 *md+ty;
  9270. out[6]=a6 *ma+a7 *mc+tx;out[7]=a6 *mb+a7 *md+ty;
  9271. }else {
  9272. out[0]=a0+tx;out[1]=a1+ty;
  9273. out[2]=a2+tx;out[3]=a3+ty;
  9274. out[4]=a4+tx;out[5]=a5+ty;
  9275. out[6]=a6+tx;out[7]=a7+ty;
  9276. }
  9277. }
  9278. /**
  9279. *pt所描述的多边形完全在clip外边,整个被裁掉了
  9280. *@param pt
  9281. *@return
  9282. */
  9283. __proto.clipedOff=function(pt){
  9284. if (this._clipRect.width <=0 || this._clipRect.height <=0)
  9285. return true;
  9286. return false;
  9287. }
  9288. /**
  9289. *应用当前矩阵。把转换后的位置放到输出数组中。
  9290. *@param x
  9291. *@param y
  9292. *@param w
  9293. *@param h
  9294. *@param italicDeg 倾斜角度,单位是度。0度无,目前是下面不动。以后要做成可调的
  9295. */
  9296. __proto.transformQuad=function(x,y,w,h,italicDeg,m,out){
  9297. var xoff=0;
  9298. if (italicDeg !=0){
  9299. xoff=Math.tan(italicDeg *Math.PI / 180)*h;
  9300. };
  9301. var maxx=x+w;var maxy=y+h;
  9302. var tx=m.tx;
  9303. var ty=m.ty;
  9304. var ma=m.a;
  9305. var mb=m.b;
  9306. var mc=m.c;
  9307. var md=m.d;
  9308. var a0=x+xoff;
  9309. var a1=y;
  9310. var a2=maxx+xoff;
  9311. var a3=y;
  9312. var a4=maxx;
  9313. var a5=maxy;
  9314. var a6=x;
  9315. var a7=maxy;
  9316. if (m._bTransform){
  9317. out[0]=a0 *ma+a1 *mc+tx;out[1]=a0 *mb+a1 *md+ty;
  9318. out[2]=a2 *ma+a3 *mc+tx;out[3]=a2 *mb+a3 *md+ty;
  9319. out[4]=a4 *ma+a5 *mc+tx;out[5]=a4 *mb+a5 *md+ty;
  9320. out[6]=a6 *ma+a7 *mc+tx;out[7]=a6 *mb+a7 *md+ty;
  9321. }else {
  9322. out[0]=a0+tx;out[1]=a1+ty;
  9323. out[2]=a2+tx;out[3]=a3+ty;
  9324. out[4]=a4+tx;out[5]=a5+ty;
  9325. out[6]=a6+tx;out[7]=a7+ty;
  9326. }
  9327. }
  9328. __proto.pushRT=function(){
  9329. this.addRenderObject(SubmitCMD.create(null,RenderTexture2D.pushRT,this));
  9330. }
  9331. __proto.popRT=function(){
  9332. this.addRenderObject(SubmitCMD.create(null,RenderTexture2D.popRT,this));
  9333. this.breakNextMerge();
  9334. }
  9335. //TODO:coverage
  9336. __proto.useRT=function(rt){
  9337. function _use (rt){
  9338. if (!rt){
  9339. throw 'error useRT'
  9340. }else{
  9341. rt.start();
  9342. rt.clear(0,0,0,0);
  9343. }
  9344. }
  9345. this.addRenderObject(SubmitCMD.create([rt],_use,this));
  9346. this.breakNextMerge();
  9347. }
  9348. //TODO:coverage
  9349. __proto.RTRestore=function(rt){
  9350. function _restore (rt){
  9351. rt.restore();
  9352. }
  9353. this.addRenderObject(SubmitCMD.create([rt],_restore,this));
  9354. this.breakNextMerge();
  9355. }
  9356. /**
  9357. *强制拒绝submit合并
  9358. *例如切换rt的时候
  9359. */
  9360. __proto.breakNextMerge=function(){
  9361. this._curSubmit=Submit.RENDERBASE;
  9362. }
  9363. //TODO:coverage
  9364. __proto._repaintSprite=function(){
  9365. this.sprite && this.sprite.repaint();
  9366. }
  9367. /**
  9368. *
  9369. *@param tex
  9370. *@param x
  9371. *@param y
  9372. *@param width
  9373. *@param height
  9374. *@param transform 图片本身希望的矩阵
  9375. *@param tx 节点的位置
  9376. *@param ty
  9377. *@param alpha
  9378. */
  9379. __proto.drawTextureWithTransform=function(tex,x,y,width,height,transform,tx,ty,alpha,blendMode,colorfilter){
  9380. var oldcomp=null;
  9381. var curMat=this._curMat;
  9382. if (blendMode){
  9383. oldcomp=this.globalCompositeOperation;
  9384. this.globalCompositeOperation=blendMode;
  9385. };
  9386. var oldColorFilter=this._colorFiler;
  9387. if (colorfilter){
  9388. this.setColorFilter(colorfilter);
  9389. }
  9390. if (!transform){
  9391. this._drawTextureM(tex,x+tx,y+ty,width,height,curMat,alpha,null);
  9392. if (blendMode){
  9393. this.globalCompositeOperation=oldcomp;
  9394. }
  9395. if (colorfilter){
  9396. this.setColorFilter(oldColorFilter);
  9397. }
  9398. return;
  9399. };
  9400. var tmpMat=this._tmpMatrix;
  9401. 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;
  9402. tmpMat._bTransform=transform._bTransform;
  9403. if (transform && curMat._bTransform){
  9404. Matrix.mul(tmpMat,curMat,tmpMat);
  9405. transform=tmpMat;
  9406. transform._bTransform=true;
  9407. }else {
  9408. tmpMat.tx+=curMat.tx;
  9409. tmpMat.ty+=curMat.ty;
  9410. transform=tmpMat;
  9411. }
  9412. this._drawTextureM(tex,x,y,width,height,transform,alpha,null);
  9413. if (blendMode){
  9414. this.globalCompositeOperation=oldcomp;
  9415. }
  9416. if (colorfilter){
  9417. this.setColorFilter(oldColorFilter);
  9418. }
  9419. }
  9420. /**
  9421. **把ctx中的submits提交。结果渲染到target上
  9422. *@param ctx
  9423. *@param target
  9424. */
  9425. __proto._flushToTarget=function(context,target){
  9426. RenderState2D.worldScissorTest=false;
  9427. WebGL.mainContext.disable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11);
  9428. var preAlpha=RenderState2D.worldAlpha;
  9429. var preMatrix4=RenderState2D.worldMatrix4;
  9430. var preMatrix=RenderState2D.worldMatrix;
  9431. var preShaderDefines=RenderState2D.worldShaderDefines;
  9432. RenderState2D.worldMatrix=Matrix.EMPTY;
  9433. RenderState2D.restoreTempArray();
  9434. RenderState2D.worldMatrix4=RenderState2D.TEMPMAT4_ARRAY;
  9435. RenderState2D.worldAlpha=1;
  9436. BaseShader.activeShader=null;
  9437. target.start();
  9438. if(context._submits._length>0)
  9439. target.clear(0,0,0,0);
  9440. context._curSubmit=Submit.RENDERBASE;
  9441. context.flush();
  9442. context.clear();
  9443. target.restore();
  9444. context._curSubmit=Submit.RENDERBASE;
  9445. BaseShader.activeShader=null;
  9446. RenderState2D.worldAlpha=preAlpha;
  9447. RenderState2D.worldMatrix4=preMatrix4;
  9448. RenderState2D.worldMatrix=preMatrix;
  9449. }
  9450. //RenderState2D.worldShaderDefines=preShaderDefines;
  9451. __proto.drawCanvas=function(canvas,x,y,width,height){
  9452. if (!canvas)return;
  9453. var src=canvas.context;
  9454. var submit;
  9455. if (src._targets){
  9456. if (src._submits._length > 0){
  9457. submit=SubmitCMD.create([src,src._targets],this._flushToTarget,this);
  9458. this._submits[this._submits._length++]=submit;
  9459. }
  9460. this._drawRenderTexture(src._targets,x,y,width,height,null,1.0,RenderTexture2D.flipyuv);
  9461. this._curSubmit=Submit.RENDERBASE;
  9462. }else {
  9463. var canv=canvas;
  9464. if (canv.touches){
  9465. (canv.touches).forEach(function(v){v.touch();});
  9466. }
  9467. submit=SubmitCanvas.create(canvas,this._shader2D.ALPHA,this._shader2D.filters);
  9468. this._submits[this._submits._length++]=submit;
  9469. (submit)._key.clear();
  9470. var mat=(submit)._matrix;
  9471. this._curMat.copyTo(mat);
  9472. var tx=mat.tx,ty=mat.ty;
  9473. mat.tx=mat.ty=0;
  9474. mat.transformPoint(Point.TEMP.setTo(x,y));
  9475. mat.translate(Point.TEMP.x+tx,Point.TEMP.y+ty);
  9476. Matrix.mul(canv.invMat,mat,mat);
  9477. this._curSubmit=Submit.RENDERBASE;
  9478. }
  9479. }
  9480. __proto.drawTarget=function(rt,x,y,width,height,m,shaderValue,uv,blend){
  9481. (blend===void 0)&& (blend=-1);
  9482. this._drawCount++;
  9483. var rgba=0xffffffff;
  9484. if (this._mesh.vertNum+4 > 65535){
  9485. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  9486. this.meshlist.push(this._mesh);
  9487. }
  9488. this.transformQuad(x,y,width,height,0,m || this._curMat,this._transedPoints);
  9489. if(!this.clipedOff(this._transedPoints)){
  9490. this._mesh.addQuad(this._transedPoints,uv || Texture.DEF_UV,0xffffffff,true);
  9491. var submit=this._curSubmit=SubmitTarget.create(this,this._mesh,shaderValue,rt);
  9492. submit.blendType=(blend==-1)?this._nBlendType:blend;
  9493. this._copyClipInfo(submit,this._globalClipMatrix);
  9494. submit._numEle=6;
  9495. this._mesh.indexNum+=6;
  9496. this._mesh.vertNum+=4;
  9497. this._submits[this._submits._length++]=submit;
  9498. this._curSubmit=Submit.RENDERBASE
  9499. return true;
  9500. }
  9501. this._curSubmit=Submit.RENDERBASE
  9502. return false;
  9503. }
  9504. __proto.drawTriangles=function(tex,x,y,vertices,uvs,indices,matrix,alpha,color,blendMode){
  9505. if (!tex._getSource()){
  9506. if (this.sprite){
  9507. Laya.systemTimer.callLater(this,this._repaintSprite);
  9508. }
  9509. return;
  9510. }
  9511. this._drawCount++;
  9512. var tmpMat=this._tmpMatrix;
  9513. var triMesh=this._triangleMesh;
  9514. var oldColorFilter=null;
  9515. var needRestorFilter=false;
  9516. if (color){
  9517. oldColorFilter=this._colorFiler;
  9518. this._colorFiler=color;
  9519. this._curSubmit=Submit.RENDERBASE;
  9520. needRestorFilter=oldColorFilter!=color;
  9521. };
  9522. var webGLImg=tex.bitmap;
  9523. var preKey=this._curSubmit._key;
  9524. var sameKey=preKey.submitType===/*laya.webgl.submit.Submit.KEY_TRIANGLES*/4 && preKey.other===webGLImg.id && preKey.blendShader==this._nBlendType;
  9525. if (triMesh.vertNum+vertices.length / 2 > 65535){
  9526. triMesh=this._triangleMesh=MeshTexture.getAMesh(this.isMain);
  9527. this.meshlist.push(triMesh);
  9528. sameKey=false;
  9529. }
  9530. if (!sameKey){
  9531. var submit=this._curSubmit=SubmitTexture.create(this,triMesh,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  9532. submit.shaderValue.textureHost=tex;
  9533. submit._renderType=/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016;
  9534. submit._key.submitType=/*laya.webgl.submit.Submit.KEY_TRIANGLES*/4;
  9535. submit._key.other=webGLImg.id;
  9536. this._copyClipInfo(submit,this._globalClipMatrix);
  9537. this._submits[this._submits._length++]=submit;
  9538. };
  9539. var rgba=this._mixRGBandAlpha(0xffffffff,this._shader2D.ALPHA *alpha);
  9540. if(!this._drawTriUseAbsMatrix){
  9541. if (!matrix){
  9542. tmpMat.a=1;tmpMat.b=0;tmpMat.c=0;tmpMat.d=1;tmpMat.tx=x;tmpMat.ty=y;
  9543. }else {
  9544. 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;
  9545. }
  9546. Matrix.mul(tmpMat,this._curMat,tmpMat);
  9547. triMesh.addData(vertices,uvs,indices,tmpMat,rgba);
  9548. }else {
  9549. triMesh.addData(vertices,uvs,indices,matrix,rgba);
  9550. }
  9551. this._curSubmit._numEle+=indices.length;
  9552. if (needRestorFilter){
  9553. this._colorFiler=oldColorFilter;
  9554. this._curSubmit=Submit.RENDERBASE;
  9555. }
  9556. }
  9557. //return true;
  9558. __proto.transform=function(a,b,c,d,tx,ty){
  9559. SaveTransform.save(this);
  9560. Matrix.mul(Matrix.TEMP.setTo(a,b,c,d,tx,ty),this._curMat,this._curMat);
  9561. this._curMat._checkTransform();
  9562. }
  9563. //TODO:coverage
  9564. __proto._transformByMatrix=function(matrix,tx,ty){
  9565. matrix.setTranslate(tx,ty);
  9566. Matrix.mul(matrix,this._curMat,this._curMat);
  9567. matrix.setTranslate(0,0);
  9568. this._curMat._bTransform=true;
  9569. }
  9570. //TODO:coverage
  9571. __proto.setTransformByMatrix=function(value){
  9572. value.copyTo(this._curMat);
  9573. }
  9574. __proto.rotate=function(angle){
  9575. SaveTransform.save(this);
  9576. this._curMat.rotateEx(angle);
  9577. }
  9578. __proto.scale=function(scaleX,scaleY){
  9579. SaveTransform.save(this);
  9580. this._curMat.scaleEx(scaleX,scaleY);
  9581. }
  9582. __proto.clipRect=function(x,y,width,height){
  9583. SaveClipRect.save(this);
  9584. if (this._clipRect==Context.MAXCLIPRECT){
  9585. this._clipRect=new Rectangle(x,y,width,height);
  9586. }else {
  9587. this._clipRect.width=width;
  9588. this._clipRect.height=height;
  9589. this._clipRect.x=x;
  9590. this._clipRect.y=y;
  9591. }
  9592. Context._clipID_Gen++;
  9593. Context._clipID_Gen %=10000;
  9594. this._clipInfoID=Context._clipID_Gen;
  9595. var cm=this._globalClipMatrix;
  9596. var minx=cm.tx;
  9597. var miny=cm.ty;
  9598. var maxx=minx+cm.a;
  9599. var maxy=miny+cm.d;
  9600. if (this._clipRect.width >=/*CLASS CONST:laya.resource.Context._MAXSIZE*/99999999){
  9601. cm.a=cm.d=/*CLASS CONST:laya.resource.Context._MAXSIZE*/99999999;
  9602. cm.b=cm.c=cm.tx=cm.ty=0;
  9603. }else {
  9604. if (this._curMat._bTransform){
  9605. cm.tx=this._clipRect.x *this._curMat.a+this._clipRect.y *this._curMat.c+this._curMat.tx;
  9606. cm.ty=this._clipRect.x *this._curMat.b+this._clipRect.y *this._curMat.d+this._curMat.ty;
  9607. cm.a=this._clipRect.width *this._curMat.a;
  9608. cm.b=this._clipRect.width *this._curMat.b;
  9609. cm.c=this._clipRect.height *this._curMat.c;
  9610. cm.d=this._clipRect.height *this._curMat.d;
  9611. }else {
  9612. cm.tx=this._clipRect.x+this._curMat.tx;
  9613. cm.ty=this._clipRect.y+this._curMat.ty;
  9614. cm.a=this._clipRect.width;
  9615. cm.b=cm.c=0;
  9616. cm.d=this._clipRect.height;
  9617. }
  9618. if (this._incache){
  9619. this._clipInCache=true;
  9620. }
  9621. }
  9622. if (cm.a > 0 && cm.d > 0){
  9623. var cmaxx=cm.tx+cm.a;
  9624. var cmaxy=cm.ty+cm.d;
  9625. if (cmaxx <=minx ||cmaxy<=miny || cm.tx>=maxx || cm.ty>=maxy){
  9626. cm.a=-0.1;cm.d=-0.1;
  9627. }else{
  9628. if (cm.tx < minx){
  9629. cm.a-=(minx-cm.tx);
  9630. cm.tx=minx;
  9631. }
  9632. if (cmaxx > maxx){
  9633. cm.a-=(cmaxx-maxx);
  9634. }
  9635. if (cm.ty < miny){
  9636. cm.d-=(miny-cm.ty);
  9637. cm.ty=miny;
  9638. }
  9639. if (cmaxy > maxy){
  9640. cm.d-=(cmaxy-maxy);
  9641. }
  9642. if (cm.a <=0)cm.a=-0.1;
  9643. if (cm.d <=0)cm.d=-0.1;
  9644. }
  9645. }
  9646. }
  9647. //TODO:coverage
  9648. __proto.drawMesh=function(x,y,ib,vb,numElement,mat,shader,shaderValues,startIndex){
  9649. (startIndex===void 0)&& (startIndex=0);
  9650. ;
  9651. }
  9652. __proto.addRenderObject=function(o){
  9653. this._submits[this._submits._length++]=o;
  9654. }
  9655. /**
  9656. *
  9657. *@param start
  9658. *@param end
  9659. */
  9660. __proto.submitElement=function(start,end){
  9661. var mainCtx=Render._context===this;
  9662. var renderList=this._submits;
  9663. var ret=(renderList)._length;
  9664. end < 0 && (end=(renderList)._length);
  9665. var submit=Submit.RENDERBASE;
  9666. while (start < end){
  9667. this._renderNextSubmitIndex=start+1;
  9668. if (renderList[start]===Submit.RENDERBASE){
  9669. start++;
  9670. continue ;
  9671. }
  9672. Submit.preRender=submit;
  9673. submit=renderList[start];
  9674. start+=submit.renderSubmit();
  9675. }
  9676. return ret;
  9677. }
  9678. __proto.flush=function(){
  9679. var ret=this.submitElement(0,this._submits._length);
  9680. this._path && this._path.reset();
  9681. SkinMeshBuffer.instance && SkinMeshBuffer.getInstance().reset();
  9682. this._curSubmit=Submit.RENDERBASE;
  9683. for (var i=0,sz=this.meshlist.length;i < sz;i++){
  9684. var curm=this.meshlist[i];
  9685. curm.canReuse?(curm.releaseMesh()):(curm.destroy());
  9686. }
  9687. this.meshlist.length=0;
  9688. this._mesh=MeshQuadTexture.getAMesh(this.isMain);
  9689. this._pathMesh=MeshVG.getAMesh(this.isMain);
  9690. this._triangleMesh=MeshTexture.getAMesh(this.isMain);
  9691. this.meshlist.push(this._mesh,this._pathMesh,this._triangleMesh);
  9692. this._flushCnt++;
  9693. if (this._flushCnt % 60==0 && Render._context==this){
  9694. if (TextRender.textRenderInst){
  9695. TextRender.textRenderInst.GC();
  9696. }
  9697. }
  9698. return ret;
  9699. }
  9700. /*******************************************start矢量绘制***************************************************/
  9701. __proto.beginPath=function(convex){
  9702. (convex===void 0)&& (convex=false);
  9703. var tPath=this._getPath();
  9704. tPath.beginPath(convex);
  9705. }
  9706. __proto.closePath=function(){
  9707. this._path.closePath();
  9708. }
  9709. /**
  9710. *添加一个path。
  9711. *@param points [x,y,x,y....] 这个会被保存下来,所以调用者需要注意复制。
  9712. *@param close 是否闭合
  9713. *@param convex 是否是凸多边形。convex的优先级是这个最大。fill的时候的次之。其实fill的时候不应该指定convex,因为可以多个path
  9714. *@param dx 需要添加的平移。这个需要在应用矩阵之前应用。
  9715. *@param dy
  9716. */
  9717. __proto.addPath=function(points,close,convex,dx,dy){
  9718. var ci=0;
  9719. for (var i=0,sz=points.length / 2;i < sz;i++){
  9720. var x1=points[ci]+dx,y1=points[ci+1]+dy;
  9721. points[ci]=x1;
  9722. points[ci+1]=y1;
  9723. ci+=2;
  9724. }
  9725. this._getPath().push(points,convex);
  9726. }
  9727. __proto.fill=function(){
  9728. var m=this._curMat;
  9729. var tPath=this._getPath();
  9730. var submit=this._curSubmit;
  9731. var sameKey=(submit._key.submitType===/*laya.webgl.submit.Submit.KEY_VG*/3 && submit._key.blendShader===this._nBlendType);
  9732. sameKey && (sameKey=sameKey&&this.isSameClipInfo(submit));
  9733. if (!sameKey){
  9734. this._curSubmit=this.addVGSubmit(this._pathMesh);
  9735. };
  9736. var rgba=this.mixRGBandAlpha(this.fillStyle.toInt());
  9737. var curEleNum=0;
  9738. var idx;
  9739. for (var i=0,sz=tPath.paths.length;i < sz;i++){
  9740. var p=tPath.paths[i];
  9741. var vertNum=p.path.length / 2;
  9742. if (vertNum < 3 ||(vertNum==3 && !p.convex))
  9743. continue ;
  9744. var cpath=p.path.concat();
  9745. var pi=0;
  9746. var xp=0,yp=0;
  9747. var _x=NaN,_y=NaN;
  9748. if (m._bTransform){
  9749. for (pi=0;pi < vertNum;pi++){
  9750. xp=pi << 1;
  9751. yp=xp+1;
  9752. _x=cpath[xp];
  9753. _y=cpath[yp];
  9754. cpath[xp]=m.a *_x+m.c *_y+m.tx;
  9755. cpath[yp]=m.b *_x+m.d *_y+m.ty;
  9756. }
  9757. }else {
  9758. for (pi=0;pi < vertNum;pi++){
  9759. xp=pi << 1;
  9760. yp=xp+1;
  9761. _x=cpath[xp];
  9762. _y=cpath[yp];
  9763. cpath[xp]=_x+m.tx;
  9764. cpath[yp]=_y+m.ty;
  9765. }
  9766. }
  9767. if (this._pathMesh.vertNum+vertNum > 65535){
  9768. this._curSubmit._numEle+=curEleNum;
  9769. curEleNum=0;
  9770. this._pathMesh=MeshVG.getAMesh(this.isMain);
  9771. this._curSubmit=this.addVGSubmit(this._pathMesh);
  9772. };
  9773. var curvert=this._pathMesh.vertNum;
  9774. if (p.convex){
  9775. var faceNum=vertNum-2;
  9776. idx=new Array(faceNum *3);
  9777. var idxpos=0;
  9778. for (var fi=0;fi < faceNum;fi++){
  9779. idx[idxpos++]=curvert;
  9780. idx[idxpos++]=fi+1+curvert;
  9781. idx[idxpos++]=fi+2+curvert;
  9782. }
  9783. }
  9784. else {
  9785. idx=Earcut.earcut(cpath,null,2);
  9786. if (curvert > 0){
  9787. for (var ii=0;ii < idx.length;ii++){
  9788. idx[ii]+=curvert;
  9789. }
  9790. }
  9791. }
  9792. this._pathMesh.addVertAndIBToMesh(this,cpath,rgba,idx);
  9793. curEleNum+=idx.length;
  9794. }
  9795. this._curSubmit._numEle+=curEleNum;
  9796. }
  9797. __proto.addVGSubmit=function(mesh){
  9798. var submit=Submit.createShape(this,mesh,0,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.PRIMITIVE*/0x04,0));
  9799. submit._key.submitType=/*laya.webgl.submit.Submit.KEY_VG*/3;
  9800. this._submits[this._submits._length++]=submit;
  9801. this._copyClipInfo(submit,this._globalClipMatrix);
  9802. return submit;
  9803. }
  9804. __proto.stroke=function(){
  9805. if (this.lineWidth > 0){
  9806. var rgba=this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  9807. var tPath=this._getPath();
  9808. var submit=this._curSubmit;
  9809. var sameKey=(submit._key.submitType===/*laya.webgl.submit.Submit.KEY_VG*/3 && submit._key.blendShader===this._nBlendType);
  9810. sameKey && (sameKey=sameKey&& this.isSameClipInfo(submit));
  9811. if (!sameKey){
  9812. this._curSubmit=this.addVGSubmit(this._pathMesh);
  9813. };
  9814. var curEleNum=0;
  9815. for (var i=0,sz=tPath.paths.length;i < sz;i++){
  9816. var p=tPath.paths[i];
  9817. if (p.path.length <=0)
  9818. continue ;
  9819. var idx=[];
  9820. var vertex=[];
  9821. var maxVertexNum=p.path.length *2;
  9822. if (maxVertexNum < 2)
  9823. continue ;
  9824. if (this._pathMesh.vertNum+maxVertexNum > 65535){
  9825. this._curSubmit._numEle+=curEleNum;
  9826. curEleNum=0;
  9827. this._pathMesh=MeshVG.getAMesh(this.isMain);
  9828. this.meshlist.push(this._pathMesh);
  9829. this._curSubmit=this.addVGSubmit(this._pathMesh);
  9830. }
  9831. BasePoly.createLine2(p.path,idx,this.lineWidth,this._pathMesh.vertNum,vertex,p.loop);
  9832. var ptnum=vertex.length / 2;
  9833. var m=this._curMat;
  9834. var pi=0;
  9835. var xp=0,yp=0;
  9836. var _x=NaN,_y=NaN;
  9837. if (m._bTransform){
  9838. for (pi=0;pi < ptnum;pi++){
  9839. xp=pi << 1;
  9840. yp=xp+1;
  9841. _x=vertex[xp];
  9842. _y=vertex[yp];
  9843. vertex[xp]=m.a *_x+m.c *_y+m.tx;
  9844. vertex[yp]=m.b *_x+m.d *_y+m.ty;
  9845. }
  9846. }else {
  9847. for (pi=0;pi < ptnum;pi++){
  9848. xp=pi << 1;
  9849. yp=xp+1;
  9850. _x=vertex[xp];
  9851. _y=vertex[yp];
  9852. vertex[xp]=_x+m.tx;
  9853. vertex[yp]=_y+m.ty;
  9854. }
  9855. }
  9856. this._pathMesh.addVertAndIBToMesh(this,vertex,rgba,idx);
  9857. curEleNum+=idx.length;
  9858. }
  9859. this._curSubmit._numEle+=curEleNum;
  9860. }
  9861. }
  9862. __proto.moveTo=function(x,y){
  9863. var tPath=this._getPath();
  9864. tPath.newPath();
  9865. tPath._lastOriX=x;
  9866. tPath._lastOriY=y;
  9867. tPath.addPoint(x,y);
  9868. }
  9869. /**
  9870. *
  9871. *@param x
  9872. *@param y
  9873. *@param b 是否应用矩阵
  9874. */
  9875. __proto.lineTo=function(x,y){
  9876. var tPath=this._getPath();
  9877. if (Math.abs(x-tPath._lastOriX)<1e-3 && Math.abs(y-tPath._lastOriY)<1e-3)
  9878. return;
  9879. tPath._lastOriX=x;
  9880. tPath._lastOriY=y;
  9881. tPath.addPoint(x,y);
  9882. }
  9883. /*
  9884. public function drawCurves(x:Number,y:Number,points:Array,lineColor:*,lineWidth:Number=1):void {
  9885. //setPathId(-1);
  9886. beginPath();
  9887. strokeStyle=lineColor;
  9888. this.lineWidth=lineWidth;
  9889. var points:Array=points;
  9890. //movePath(x,y);TODO 这个被去掉了
  9891. moveTo(points[0],points[1]);
  9892. var i:int=2,n:int=points.length;
  9893. while (i < n){
  9894. quadraticCurveTo(points[i++],points[i++],points[i++],points[i++]);
  9895. }
  9896. stroke();
  9897. }
  9898. */
  9899. __proto.arcTo=function(x1,y1,x2,y2,r){
  9900. var i=0;
  9901. var x=0,y=0;
  9902. var dx=this._path._lastOriX-x1;
  9903. var dy=this._path._lastOriY-y1;
  9904. var len1=Math.sqrt(dx*dx+dy*dy);
  9905. if (len1 <=0.000001){
  9906. return;
  9907. };
  9908. var ndx=dx / len1;
  9909. var ndy=dy / len1;
  9910. var dx2=x2-x1;
  9911. var dy2=y2-y1;
  9912. var len22=dx2*dx2+dy2*dy2;
  9913. var len2=Math.sqrt(len22);
  9914. if (len2 <=0.000001){
  9915. return;
  9916. };
  9917. var ndx2=dx2 / len2;
  9918. var ndy2=dy2 / len2;
  9919. var odx=ndx+ndx2;
  9920. var ody=ndy+ndy2;
  9921. var olen=Math.sqrt(odx*odx+ody*ody);
  9922. if (olen <=0.000001){
  9923. return;
  9924. };
  9925. var nOdx=odx / olen;
  9926. var nOdy=ody / olen;
  9927. var alpha=Math.acos(nOdx*ndx+nOdy*ndy);
  9928. var halfAng=Math.PI / 2-alpha;
  9929. len1=r / Math.tan(halfAng);
  9930. var ptx1=len1*ndx+x1;
  9931. var pty1=len1*ndy+y1;
  9932. var orilen=Math.sqrt(len1 *len1+r *r);
  9933. var orix=x1+nOdx*orilen;
  9934. var oriy=y1+nOdy*orilen;
  9935. var ptx2=len1*ndx2+x1;
  9936. var pty2=len1*ndy2+y1;
  9937. var dir=ndx *ndy2-ndy *ndx2;
  9938. var fChgAng=0;
  9939. var sinx=0.0;
  9940. var cosx=0.0;
  9941. if (dir >=0){
  9942. fChgAng=halfAng *2;
  9943. var fda=fChgAng / Context.SEGNUM;
  9944. sinx=Math.sin(fda);
  9945. cosx=Math.cos(fda);
  9946. }
  9947. else {
  9948. fChgAng=-halfAng *2;
  9949. fda=fChgAng / Context.SEGNUM;
  9950. sinx=Math.sin(fda);
  9951. cosx=Math.cos(fda);
  9952. };
  9953. var lastx=this._path._lastOriX,lasty=this._path._lastOriY;
  9954. var _x1=ptx1 ,_y1=pty1;
  9955. if (Math.abs(_x1-this._path._lastOriX)>0.1 || Math.abs(_y1-this._path._lastOriY)>0.1){
  9956. x=_x1;
  9957. y=_y1;
  9958. lastx=_x1;
  9959. lasty=_y1;
  9960. this._path.addPoint(x,y);
  9961. };
  9962. var cvx=ptx1-orix;
  9963. var cvy=pty1-oriy;
  9964. var tx=0.0;
  9965. var ty=0.0;
  9966. for (i=0;i < Context.SEGNUM;i++){
  9967. var cx=cvx*cosx+cvy*sinx;
  9968. var cy=-cvx*sinx+cvy*cosx;
  9969. x=cx+orix;
  9970. y=cy+oriy;
  9971. if (Math.abs(lastx-x)>0.1 || Math.abs(lasty-y)>0.1){
  9972. this._path.addPoint(x,y);
  9973. lastx=x;
  9974. lasty=y;
  9975. }
  9976. cvx=cx;
  9977. cvy=cy;
  9978. }
  9979. }
  9980. __proto.arc=function(cx,cy,r,startAngle,endAngle,counterclockwise,b){
  9981. (counterclockwise===void 0)&& (counterclockwise=false);
  9982. (b===void 0)&& (b=true);
  9983. var a=0,da=0,hda=0,kappa=0;
  9984. var dx=0,dy=0,x=0,y=0,tanx=0,tany=0;
  9985. var px=0,py=0,ptanx=0,ptany=0;
  9986. var i=0,ndivs=0,nvals=0;
  9987. da=endAngle-startAngle;
  9988. if (!counterclockwise){
  9989. if (Math.abs(da)>=Math.PI *2){
  9990. da=Math.PI *2;
  9991. }else {
  9992. while (da < 0.0){
  9993. da+=Math.PI *2;
  9994. }
  9995. }
  9996. }else {
  9997. if (Math.abs(da)>=Math.PI *2){
  9998. da=-Math.PI *2;
  9999. }else {
  10000. while (da > 0.0){
  10001. da-=Math.PI *2;
  10002. }
  10003. }
  10004. };
  10005. var sx=this.getMatScaleX();
  10006. var sy=this.getMatScaleY();
  10007. var sr=r *(sx > sy?sx:sy);
  10008. var cl=2 *Math.PI *sr;
  10009. ndivs=(Math.max(cl / 10,10))|0;
  10010. hda=(da / ndivs)/ 2.0;
  10011. kappa=Math.abs(4 / 3 *(1-Math.cos(hda))/ Math.sin(hda));
  10012. if (counterclockwise)
  10013. kappa=-kappa;
  10014. nvals=0;
  10015. var tPath=this._getPath();
  10016. var _x1=NaN,_y1=NaN;
  10017. for (i=0;i <=ndivs;i++){
  10018. a=startAngle+da *(i / ndivs);
  10019. dx=Math.cos(a);
  10020. dy=Math.sin(a);
  10021. x=cx+dx *r;
  10022. y=cy+dy *r;
  10023. if (x !=this._path._lastOriX || y !=this._path._lastOriY){
  10024. tPath.addPoint(x,y);
  10025. }
  10026. }
  10027. dx=Math.cos(endAngle);
  10028. dy=Math.sin(endAngle);
  10029. x=cx+dx *r;
  10030. y=cy+dy *r;
  10031. if (x !=this._path._lastOriX|| y !=this._path._lastOriY){
  10032. tPath.addPoint(x,y);
  10033. }
  10034. }
  10035. __proto.quadraticCurveTo=function(cpx,cpy,x,y){
  10036. var tBezier=Bezier.I;
  10037. var tResultArray=[];
  10038. var tArray=tBezier.getBezierPoints([this._path._lastOriX,this._path._lastOriY,cpx,cpy,x,y],30,2);
  10039. for (var i=0,n=tArray.length / 2;i < n;i++){
  10040. this.lineTo(tArray[i *2],tArray[i *2+1]);
  10041. }
  10042. this.lineTo(x,y);
  10043. }
  10044. /**
  10045. *把颜色跟当前设置的alpha混合
  10046. *@return
  10047. */
  10048. __proto.mixRGBandAlpha=function(color){
  10049. return this._mixRGBandAlpha(color,this._shader2D.ALPHA);
  10050. }
  10051. __proto._mixRGBandAlpha=function(color,alpha){
  10052. if (alpha >=1){
  10053. return color;
  10054. };
  10055. var a=((color & 0xff000000)>>> 24);
  10056. if (a !=0){
  10057. a*=alpha;
  10058. }else {
  10059. a=alpha*255;
  10060. }
  10061. return (color & 0x00ffffff)| (a << 24);
  10062. }
  10063. __proto.strokeRect=function(x,y,width,height,parameterLineWidth){
  10064. var tW=parameterLineWidth *0.5;
  10065. if (this.lineWidth > 0){
  10066. var rgba=this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  10067. var hw=this.lineWidth / 2;
  10068. this._fillRect(x-hw,y-hw,width+this.lineWidth,this.lineWidth,rgba);
  10069. this._fillRect(x-hw,y-hw+height,width+this.lineWidth,this.lineWidth,rgba);
  10070. this._fillRect(x-hw,y+hw,this.lineWidth,height-this.lineWidth,rgba);
  10071. this._fillRect(x-hw+width,y+hw,this.lineWidth,height-this.lineWidth,rgba);
  10072. }
  10073. }
  10074. //右
  10075. __proto.clip=function(){}
  10076. //TODO:coverage
  10077. __proto.drawParticle=function(x,y,pt){
  10078. pt.x=x;
  10079. pt.y=y;
  10080. this._submits[this._submits._length++]=pt;
  10081. }
  10082. __proto._getPath=function(){
  10083. return this._path || (this._path=new Path());
  10084. }
  10085. /**
  10086. *专用函数。通过循环创建来水平填充
  10087. *@param tex
  10088. *@param bmpid
  10089. *@param uv 希望循环的部分的uv
  10090. *@param oriw
  10091. *@param orih
  10092. *@param x
  10093. *@param y
  10094. *@param w
  10095. */
  10096. __proto._fillTexture_h=function(tex,imgid,uv,oriw,orih,x,y,w){
  10097. var stx=x;
  10098. var num=Math.floor(w / oriw);
  10099. var left=w % oriw;
  10100. for (var i=0;i < num;i++){
  10101. this._inner_drawTexture(tex,imgid,stx,y,oriw,orih,this._curMat,uv,1,false);
  10102. stx+=oriw;
  10103. }
  10104. if (left > 0){
  10105. var du=uv[2]-uv[0];
  10106. var uvr=uv[0]+du *(left / oriw);
  10107. var tuv=Context.tmpuv1;
  10108. tuv[0]=uv[0];tuv[1]=uv[1];tuv[2]=uvr;tuv[3]=uv[3];
  10109. tuv[4]=uvr;tuv[5]=uv[5];tuv[6]=uv[6];tuv[7]=uv[7];
  10110. this._inner_drawTexture(tex,imgid,stx,y,left,orih,this._curMat,tuv,1,false);
  10111. }
  10112. }
  10113. /**
  10114. *专用函数。通过循环创建来垂直填充
  10115. *@param tex
  10116. *@param imgid
  10117. *@param uv
  10118. *@param oriw
  10119. *@param orih
  10120. *@param x
  10121. *@param y
  10122. *@param h
  10123. */
  10124. __proto._fillTexture_v=function(tex,imgid,uv,oriw,orih,x,y,h){
  10125. var sty=y;
  10126. var num=Math.floor(h / orih);
  10127. var left=h % orih;
  10128. for (var i=0;i < num;i++){
  10129. this._inner_drawTexture(tex,imgid,x,sty,oriw,orih,this._curMat,uv,1,false);
  10130. sty+=orih;
  10131. }
  10132. if (left > 0){
  10133. var dv=uv[7]-uv[1];
  10134. var uvb=uv[1]+dv *(left / orih);
  10135. var tuv=Context.tmpuv1;
  10136. tuv[0]=uv[0];tuv[1]=uv[1];tuv[2]=uv[2];tuv[3]=uv[3];
  10137. tuv[4]=uv[4];tuv[5]=uvb;tuv[6]=uv[6];tuv[7]=uvb;
  10138. this._inner_drawTexture(tex,imgid,x,sty,oriw,left,this._curMat,tuv,1,false);
  10139. }
  10140. }
  10141. __proto.drawTextureWithSizeGrid=function(tex,tx,ty,width,height,sizeGrid,gx,gy){
  10142. if (!tex._getSource())
  10143. return;
  10144. tx+=gx;
  10145. ty+=gy;
  10146. var uv=tex.uv,w=tex.bitmap.width,h=tex.bitmap.height;
  10147. var top=sizeGrid[0];
  10148. var left=sizeGrid[3];
  10149. var d_top=top / h;
  10150. var d_left=left / w;
  10151. var right=sizeGrid[1];
  10152. var bottom=sizeGrid[2];
  10153. var d_right=right / w;
  10154. var d_bottom=bottom / h;
  10155. var repeat=sizeGrid[4];
  10156. var needClip=false;
  10157. if (width==w){
  10158. left=right=0;
  10159. }
  10160. if (height==h){
  10161. top=bottom=0;
  10162. }
  10163. if (left+right > width){
  10164. var clipWidth=width;
  10165. needClip=true;
  10166. width=left+right;
  10167. this.save();
  10168. this.clipRect(0+tx,0+ty,clipWidth,height);
  10169. };
  10170. var imgid=tex.bitmap.id;
  10171. var mat=this._curMat;
  10172. var tuv=this._tempUV;
  10173. var uvl=uv[0];
  10174. var uvt=uv[1];
  10175. var uvr=uv[4];
  10176. var uvb=uv[5];
  10177. var uvl_=uvl;
  10178. var uvt_=uvt;
  10179. var uvr_=uvr;
  10180. var uvb_=uvb;
  10181. if(left && top){
  10182. uvr_=uvl+d_left;
  10183. uvb_=uvt+d_top;
  10184. tuv[0]=uvl,tuv[1]=uvt,tuv[2]=uvr_,tuv[3]=uvt,
  10185. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl,tuv[7]=uvb_;
  10186. this._inner_drawTexture(tex,imgid,tx,ty,left,top,mat,tuv,1,false);
  10187. }
  10188. if (right && top){
  10189. uvl_=uvr-d_right;uvt_=uvt;
  10190. uvr_=uvr;uvb_=uvt+d_top;
  10191. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  10192. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  10193. this._inner_drawTexture(tex,imgid,width-right+tx,0+ty,right,top,mat,tuv,1,false);
  10194. }
  10195. if (left && bottom){
  10196. uvl_=uvl;uvt_=uvb-d_bottom;
  10197. uvr_=uvl+d_left;uvb_=uvb;
  10198. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  10199. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  10200. this._inner_drawTexture(tex,imgid,0+tx,height-bottom+ty,left,bottom,mat,tuv,1,false);
  10201. }
  10202. if (right && bottom){
  10203. uvl_=uvr-d_right;uvt_=uvb-d_bottom;
  10204. uvr_=uvr;uvb_=uvb;
  10205. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  10206. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  10207. this._inner_drawTexture(tex,imgid,width-right+tx,height-bottom+ty,right,bottom,mat,tuv,1,false);
  10208. }
  10209. if (top){
  10210. uvl_=uvl+d_left;uvt_=uvt;
  10211. uvr_=uvr-d_right;uvb_=uvt+d_top;
  10212. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  10213. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  10214. if (repeat){
  10215. this._fillTexture_h(tex,imgid,tuv,tex.width-left-right,top,left+tx,ty,width-left-right);
  10216. }else {
  10217. this._inner_drawTexture(tex,imgid,left+tx,ty,width-left-right,top,mat,tuv,1,false);
  10218. }
  10219. }
  10220. if (bottom){
  10221. uvl_=uvl+d_left;uvt_=uvb-d_bottom;
  10222. uvr_=uvr-d_right;uvb_=uvb;
  10223. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  10224. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  10225. if (repeat){
  10226. this._fillTexture_h(tex,imgid,tuv,tex.width-left-right,bottom,left+tx,height-bottom+ty,width-left-right);
  10227. }else{
  10228. this._inner_drawTexture(tex,imgid,left+tx,height-bottom+ty,width-left-right,bottom,mat,tuv,1,false);
  10229. }
  10230. }
  10231. if (left){
  10232. uvl_=uvl;uvt_=uvt+d_top;
  10233. uvr_=uvl+d_left;uvb_=uvb-d_bottom;
  10234. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  10235. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  10236. if (repeat){
  10237. this._fillTexture_v(tex,imgid,tuv,left,tex.height-top-bottom,tx,top+ty,height-top-bottom);
  10238. }else{
  10239. this._inner_drawTexture(tex,imgid,tx,top+ty,left,height-top-bottom,mat,tuv,1,false);
  10240. }
  10241. }
  10242. if (right){
  10243. uvl_=uvr-d_right;uvt_=uvt+d_top;
  10244. uvr_=uvr;uvb_=uvb-d_bottom;
  10245. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  10246. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  10247. if (repeat){
  10248. this._fillTexture_v(tex,imgid,tuv,right,tex.height-top-bottom,width-right+tx,top+ty,height-top-bottom);
  10249. }else{
  10250. this._inner_drawTexture(tex,imgid,width-right+tx,top+ty,right,height-top-bottom,mat,tuv,1,false);
  10251. }
  10252. }
  10253. uvl_=uvl+d_left;uvt_=uvt+d_top;
  10254. uvr_=uvr-d_right;uvb_=uvb-d_bottom;
  10255. tuv[0]=uvl_,tuv[1]=uvt_,tuv[2]=uvr_,tuv[3]=uvt_,
  10256. tuv[4]=uvr_,tuv[5]=uvb_,tuv[6]=uvl_,tuv[7]=uvb_;
  10257. if (repeat){
  10258. var tuvr=Context.tmpUVRect;
  10259. tuvr[0]=uvl_;tuvr[1]=uvt_;
  10260. tuvr[2]=uvr_-uvl_;tuvr[3]=uvb_-uvt_;
  10261. 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);
  10262. }else{
  10263. this._inner_drawTexture(tex,imgid,left+tx,top+ty,width-left-right,height-top-bottom,mat,tuv,1,false);
  10264. }
  10265. if (needClip)this.restore();
  10266. }
  10267. __getset(0,__proto,'textAlign',function(){
  10268. return this._other.textAlign;
  10269. },function(value){
  10270. (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);
  10271. });
  10272. /**@private */
  10273. /**@private */
  10274. __getset(0,__proto,'lineJoin',function(){
  10275. return null;
  10276. },function(value){
  10277. });
  10278. __getset(0,__proto,'fillStyle',function(){
  10279. return this._shader2D.fillStyle;
  10280. },function(value){
  10281. if (!this._shader2D.fillStyle.equal(value)){
  10282. SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_FILESTYLE*/0x2,this._shader2D,false);
  10283. this._shader2D.fillStyle=DrawStyle.create(value);
  10284. this._submitKey.other=-this._shader2D.fillStyle.toInt();
  10285. }
  10286. });
  10287. /**@private */
  10288. /**@private */
  10289. __getset(0,__proto,'lineCap',function(){
  10290. return null;
  10291. },function(value){
  10292. });
  10293. /**@private */
  10294. /**@private */
  10295. __getset(0,__proto,'miterLimit',function(){
  10296. return null;
  10297. },function(value){
  10298. });
  10299. __getset(0,__proto,'strokeStyle',function(){
  10300. return this._shader2D.strokeStyle;
  10301. },function(value){
  10302. 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());
  10303. });
  10304. /*,_shader2D.ALPHA=1*/
  10305. __getset(0,__proto,'globalCompositeOperation',function(){
  10306. return BlendMode.NAMES[this._nBlendType];
  10307. },function(value){
  10308. var n=BlendMode.TOINT[value];
  10309. 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);
  10310. });
  10311. __getset(0,__proto,'globalAlpha',function(){
  10312. return this._shader2D.ALPHA;
  10313. },function(value){
  10314. value=Math.floor(value *1000)/ 1000;
  10315. if (value !=this._shader2D.ALPHA){
  10316. SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_ALPHA*/0x1,this._shader2D,false);
  10317. this._shader2D.ALPHA=value;
  10318. }
  10319. });
  10320. /**
  10321. *当前canvas请求保存渲染结果。
  10322. *实现:
  10323. *如果value==true,就要给_target赋值
  10324. *@param value {Boolean}
  10325. */
  10326. __getset(0,__proto,'asBitmap',null,function(value){
  10327. if (value){
  10328. this._targets || (this._targets=new RenderTexture2D(this._width,this._height,/*laya.resource.BaseTexture.FORMAT_R8G8B8A8*/1,-1));
  10329. if (!this._width || !this._height)
  10330. throw Error("asBitmap no size!");
  10331. }else {
  10332. this._targets && this._targets.destroy();
  10333. this._targets=null;
  10334. }
  10335. });
  10336. __getset(0,__proto,'textBaseline',function(){
  10337. return this._other.textBaseline;
  10338. },function(value){
  10339. (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);
  10340. });
  10341. __getset(0,__proto,'lineWidth',function(){
  10342. return this._other.lineWidth;
  10343. },function(value){
  10344. (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);
  10345. });
  10346. __getset(0,__proto,'font',null,function(str){
  10347. this._other=this._other.make();
  10348. SaveBase.save(this,/*laya.webgl.canvas.save.SaveBase.TYPE_FONT*/0x8,this._other,false);
  10349. });
  10350. //注意这个是对外接口
  10351. __getset(0,__proto,'canvas',function(){
  10352. return this._canvas;
  10353. });
  10354. Context.__init__=function(){
  10355. Context.MAXCLIPRECT=new Rectangle(0,0,99999999,99999999);
  10356. ContextParams.DEFAULT=new ContextParams();
  10357. WebGLCacheAsNormalCanvas;
  10358. }
  10359. Context.set2DRenderConfig=function(){
  10360. var gl=LayaGL.instance;
  10361. WebGLContext.setBlend(gl,true);
  10362. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  10363. WebGLContext.setDepthTest(gl,false);
  10364. WebGLContext.setCullFace(gl,false);
  10365. WebGLContext.setDepthMask(gl,true);
  10366. WebGLContext.setFrontFace(gl,/*laya.webgl.WebGLContext.CCW*/0x0901);
  10367. gl.viewport(0,0,RenderState2D.width,RenderState2D.height);
  10368. }
  10369. Context.ENUM_TEXTALIGN_DEFAULT=0;
  10370. Context.ENUM_TEXTALIGN_CENTER=1;
  10371. Context.ENUM_TEXTALIGN_RIGHT=2;
  10372. Context._SUBMITVBSIZE=32000;
  10373. Context._MAXSIZE=99999999;
  10374. Context._MAXVERTNUM=65535;
  10375. Context.MAXCLIPRECT=null;
  10376. Context._COUNT=0;
  10377. Context.SEGNUM=32;
  10378. Context._contextcount=0;
  10379. Context.PI2=2 *Math.PI;
  10380. Context._clipID_Gen=0;
  10381. __static(Context,
  10382. ['_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];}
  10383. ]);
  10384. Context.__init$=function(){
  10385. //class ContextParams
  10386. ContextParams=(function(){
  10387. function ContextParams(){
  10388. this.lineWidth=1;
  10389. this.textAlign=null;
  10390. this.textBaseline=null;
  10391. }
  10392. __class(ContextParams,'');
  10393. var __proto=ContextParams.prototype;
  10394. __proto.clear=function(){
  10395. this.lineWidth=1;
  10396. this.textAlign=this.textBaseline=null;
  10397. }
  10398. __proto.make=function(){
  10399. return this===ContextParams.DEFAULT ? new ContextParams():this;
  10400. }
  10401. ContextParams.DEFAULT=null;
  10402. return ContextParams;
  10403. })()
  10404. }
  10405. return Context;
  10406. })()
  10407. /**
  10408. *@private
  10409. */
  10410. //class laya.filters.BlurFilterGLRender
  10411. var BlurFilterGLRender=(function(){
  10412. function BlurFilterGLRender(){}
  10413. __class(BlurFilterGLRender,'laya.filters.BlurFilterGLRender');
  10414. var __proto=BlurFilterGLRender.prototype;
  10415. __proto.render=function(rt,ctx,width,height,filter){
  10416. var shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  10417. this.setShaderInfo(shaderValue,filter,rt.width,rt.height);
  10418. ctx.drawTarget(rt,0,0,width,height,Matrix.EMPTY.identity(),shaderValue);
  10419. }
  10420. __proto.setShaderInfo=function(shader,filter,w,h){
  10421. shader.defines.add(/*laya.filters.Filter.BLUR*/0x10);
  10422. var sv=shader;
  10423. BlurFilterGLRender.blurinfo[0]=w;BlurFilterGLRender.blurinfo[1]=h;
  10424. sv.blurInfo=BlurFilterGLRender.blurinfo;
  10425. var sigma=filter.strength/3.0;
  10426. var sigma2=sigma*sigma;
  10427. filter.strength_sig2_2sig2_gauss1[0]=filter.strength;
  10428. filter.strength_sig2_2sig2_gauss1[1]=sigma2;
  10429. filter.strength_sig2_2sig2_gauss1[2]=2.0*sigma2;
  10430. filter.strength_sig2_2sig2_gauss1[3]=1.0/(2.0*Math.PI*sigma2);
  10431. sv.strength_sig2_2sig2_gauss1=filter.strength_sig2_2sig2_gauss1;
  10432. }
  10433. __static(BlurFilterGLRender,
  10434. ['blurinfo',function(){return this.blurinfo=new Array(2);}
  10435. ]);
  10436. return BlurFilterGLRender;
  10437. })()
  10438. //class laya.webgl.utils.CONST3D2D
  10439. var CONST3D2D=(function(){
  10440. function CONST3D2D(){}
  10441. __class(CONST3D2D,'laya.webgl.utils.CONST3D2D');
  10442. CONST3D2D.BYTES_PE=4;
  10443. CONST3D2D.BYTES_PIDX=2;
  10444. CONST3D2D.defaultMatrix4=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];
  10445. CONST3D2D.defaultMinusYMatrix4=[1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1];
  10446. CONST3D2D.uniformMatrix3=[1,0,0,0,0,1,0,0,0,0,1,0];
  10447. CONST3D2D._TMPARRAY=[];
  10448. CONST3D2D._OFFSETX=0;
  10449. CONST3D2D._OFFSETY=0;
  10450. return CONST3D2D;
  10451. })()
  10452. /**
  10453. *TODO如果占用内存较大,这个结构有很多成员可以临时计算
  10454. */
  10455. //class laya.webgl.text.CharRenderInfo
  10456. var CharRenderInfo=(function(){
  10457. function CharRenderInfo(){
  10458. this.char='';
  10459. // 调试用
  10460. this.tex=null;
  10461. //
  10462. this.deleted=false;
  10463. // [0,0,1,1];//uv
  10464. this.pos=0;
  10465. //数组下标
  10466. this.width=0;
  10467. //字体宽度。测量的宽度,用来排版。没有缩放
  10468. this.height=0;
  10469. //字体高度。没有缩放
  10470. this.bmpWidth=0;
  10471. //实际图片的宽度。可能与排版用的width不一致。包含缩放和margin
  10472. this.bmpHeight=0;
  10473. this.orix=0;
  10474. // 原点位置,通常都是所在区域的左上角
  10475. this.oriy=0;
  10476. this.touchTick=0;
  10477. //
  10478. this.isSpace=false;
  10479. this.uv=new Array(8);
  10480. }
  10481. __class(CharRenderInfo,'laya.webgl.text.CharRenderInfo');
  10482. var __proto=CharRenderInfo.prototype;
  10483. //是否是空格,如果是空格,则只有width有效
  10484. __proto.touch=function(){
  10485. var curLoop=Stat.loopCount;
  10486. if (this.touchTick !=curLoop){
  10487. this.tex.touchRect(this,curLoop);
  10488. }
  10489. this.touchTick=curLoop;
  10490. }
  10491. return CharRenderInfo;
  10492. })()
  10493. /**
  10494. *...
  10495. *@author ww
  10496. */
  10497. //class laya.layagl.QuickTestTool
  10498. var QuickTestTool=(function(){
  10499. function QuickTestTool(){
  10500. this._renderType=0;
  10501. this._repaint=0;
  10502. this._x=NaN;
  10503. this._y=NaN;
  10504. }
  10505. __class(QuickTestTool,'laya.layagl.QuickTestTool');
  10506. var __proto=QuickTestTool.prototype;
  10507. //TODO:coverage
  10508. __proto.render=function(context,x,y){
  10509. QuickTestTool._addType(this._renderType);
  10510. QuickTestTool.showRenderTypeInfo(this._renderType);
  10511. RenderSprite.renders[this._renderType]._fun(this,context,x+this._x,y+this._y);
  10512. this._repaint=0;
  10513. }
  10514. //TODO:coverage
  10515. __proto._stageRender=function(context,x,y){
  10516. QuickTestTool._countStart();
  10517. QuickTestTool._PreStageRender.call(Laya.stage,context,x,y);
  10518. QuickTestTool._countEnd();
  10519. }
  10520. QuickTestTool.getMCDName=function(type){
  10521. return QuickTestTool._typeToNameDic[type];
  10522. }
  10523. QuickTestTool.showRenderTypeInfo=function(type,force){
  10524. (force===void 0)&& (force=false);
  10525. if (!force&&QuickTestTool.showedDic[type])
  10526. return;
  10527. QuickTestTool.showedDic[type]=true;
  10528. if (!QuickTestTool._rendertypeToStrDic[type]){
  10529. var arr=[];
  10530. var tType=0;
  10531. tType=1;
  10532. while (tType <=type){
  10533. if (tType & type){
  10534. arr.push(QuickTestTool.getMCDName(tType & type));
  10535. }
  10536. tType=tType << 1;
  10537. }
  10538. QuickTestTool._rendertypeToStrDic[type]=arr.join(",");
  10539. }
  10540. console.log("cmd:",QuickTestTool._rendertypeToStrDic[type]);
  10541. }
  10542. QuickTestTool.__init__=function(){
  10543. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.ALPHA*/0x01]="ALPHA";
  10544. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.TRANSFORM*/0x02]="TRANSFORM";
  10545. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.TEXTURE*/0x100]="TEXTURE";
  10546. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.GRAPHICS*/0x200]="GRAPHICS";
  10547. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.ONECHILD*/0x1000]="ONECHILD";
  10548. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.CHILDS*/0x2000]="CHILDS";
  10549. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.TRANSFORM*/0x02 | /*laya.display.SpriteConst.ALPHA*/0x01]="TRANSFORM|ALPHA";
  10550. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.CANVAS*/0x08]="CANVAS";
  10551. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.BLEND*/0x04]="BLEND";
  10552. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.FILTERS*/0x10]="FILTERS";
  10553. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.MASK*/0x20]="MASK";
  10554. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.CLIP*/0x40]="CLIP";
  10555. QuickTestTool._typeToNameDic[ /*laya.display.SpriteConst.LAYAGL3D*/0x400]="LAYAGL3D";
  10556. }
  10557. QuickTestTool._countStart=function(){
  10558. var key;
  10559. for (key in QuickTestTool._countDic){
  10560. QuickTestTool._countDic[key]=0;
  10561. }
  10562. }
  10563. QuickTestTool._countEnd=function(){
  10564. QuickTestTool._i++;
  10565. if (QuickTestTool._i > 60){
  10566. QuickTestTool.showCountInfo();
  10567. QuickTestTool._i=0;
  10568. }
  10569. }
  10570. QuickTestTool._addType=function(type){
  10571. if (!QuickTestTool._countDic[type]){
  10572. QuickTestTool._countDic[type]=1;
  10573. }else{
  10574. QuickTestTool._countDic[type]+=1;
  10575. }
  10576. }
  10577. QuickTestTool.showCountInfo=function(){
  10578. console.log("===================");
  10579. var key;
  10580. for (key in QuickTestTool._countDic){
  10581. console.log("count:"+QuickTestTool._countDic[key]);
  10582. QuickTestTool.showRenderTypeInfo(key,true);
  10583. }
  10584. }
  10585. QuickTestTool.enableQuickTest=function(){
  10586. QuickTestTool.__init__();
  10587. Sprite["prototype"]["render"]=QuickTestTool["prototype"]["render"];
  10588. QuickTestTool._PreStageRender=Stage["prototype"]["render"];
  10589. Stage["prototype"]["render"]=QuickTestTool["prototype"]["_stageRender"];
  10590. }
  10591. QuickTestTool.showedDic={};
  10592. QuickTestTool._rendertypeToStrDic={};
  10593. QuickTestTool._typeToNameDic={};
  10594. QuickTestTool._PreStageRender=null;
  10595. QuickTestTool._countDic={};
  10596. QuickTestTool._i=0;
  10597. return QuickTestTool;
  10598. })()
  10599. //class laya.webgl.utils.RenderState2D
  10600. var RenderState2D=(function(){
  10601. function RenderState2D(){}
  10602. __class(RenderState2D,'laya.webgl.utils.RenderState2D');
  10603. RenderState2D.mat2MatArray=function(mat,matArray){
  10604. var m=mat;
  10605. var m4=matArray;
  10606. m4[0]=m.a;
  10607. m4[1]=m.b;
  10608. m4[2]=RenderState2D.EMPTYMAT4_ARRAY[2];
  10609. m4[3]=RenderState2D.EMPTYMAT4_ARRAY[3];
  10610. m4[4]=m.c;
  10611. m4[5]=m.d;
  10612. m4[6]=RenderState2D.EMPTYMAT4_ARRAY[6];
  10613. m4[7]=RenderState2D.EMPTYMAT4_ARRAY[7];
  10614. m4[8]=RenderState2D.EMPTYMAT4_ARRAY[8];
  10615. m4[9]=RenderState2D.EMPTYMAT4_ARRAY[9];
  10616. m4[10]=RenderState2D.EMPTYMAT4_ARRAY[10];
  10617. m4[11]=RenderState2D.EMPTYMAT4_ARRAY[11];
  10618. m4[12]=m.tx;
  10619. m4[13]=m.ty;
  10620. m4[14]=RenderState2D.EMPTYMAT4_ARRAY[14];
  10621. m4[15]=RenderState2D.EMPTYMAT4_ARRAY[15];
  10622. return matArray;
  10623. }
  10624. RenderState2D.restoreTempArray=function(){
  10625. RenderState2D.TEMPMAT4_ARRAY[0]=1;
  10626. RenderState2D.TEMPMAT4_ARRAY[1]=0;
  10627. RenderState2D.TEMPMAT4_ARRAY[4]=0;
  10628. RenderState2D.TEMPMAT4_ARRAY[5]=1;
  10629. RenderState2D.TEMPMAT4_ARRAY[12]=0;
  10630. RenderState2D.TEMPMAT4_ARRAY[13]=0;
  10631. }
  10632. RenderState2D.clear=function(){
  10633. RenderState2D.worldScissorTest=false;
  10634. RenderState2D.worldAlpha=1;
  10635. }
  10636. RenderState2D._MAXSIZE=99999999;
  10637. RenderState2D.EMPTYMAT4_ARRAY=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];
  10638. RenderState2D.TEMPMAT4_ARRAY=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];
  10639. RenderState2D.worldMatrix4=RenderState2D.TEMPMAT4_ARRAY;
  10640. RenderState2D.matWVP=null;
  10641. RenderState2D.worldAlpha=1.0;
  10642. RenderState2D.worldScissorTest=false;
  10643. RenderState2D.worldShaderDefines=null;
  10644. RenderState2D.worldFilters=null;
  10645. RenderState2D.width=0;
  10646. RenderState2D.height=0;
  10647. __static(RenderState2D,
  10648. ['worldMatrix',function(){return this.worldMatrix=new Matrix();}
  10649. ]);
  10650. return RenderState2D;
  10651. })()
  10652. /**
  10653. *@private 场景辅助类
  10654. */
  10655. //class laya.utils.SceneUtils
  10656. var SceneUtils=(function(){
  10657. var DataWatcher,InitTool;
  10658. function SceneUtils(){}
  10659. __class(SceneUtils,'laya.utils.SceneUtils');
  10660. SceneUtils.getBindFun=function(value){
  10661. var fun=SceneUtils._funMap.get(value);
  10662. if (fun==null){
  10663. var temp="\""+value+"\"";
  10664. temp=temp.replace(/^"\${|}"$/g,"").replace(/\${/g,"\"+").replace(/}/g,"+\"");
  10665. var str="(function(data){if(data==null)return;with(data){try{\nreturn "+temp+"\n}catch(e){}}})";
  10666. fun=Laya._runScript(str);
  10667. SceneUtils._funMap.set(value,fun);
  10668. }
  10669. return fun;
  10670. }
  10671. SceneUtils.createByData=function(root,uiView){
  10672. var tInitTool=InitTool.create();
  10673. root=SceneUtils.createComp(uiView,root,root,null,tInitTool);
  10674. root._setBit(/*laya.Const.NOT_READY*/0x08,true);
  10675. if (root.hasOwnProperty("_idMap")){
  10676. root["_idMap"]=tInitTool._idMap;
  10677. }
  10678. if (uiView.animations){
  10679. var anilist=[];
  10680. var animations=uiView.animations;
  10681. var i=0,len=animations.length;
  10682. var tAni;
  10683. var tAniO;
  10684. for (i=0;i < len;i++){
  10685. tAni=new FrameAnimation();
  10686. tAniO=animations[i];
  10687. tAni._setUp(tInitTool._idMap,tAniO);
  10688. root[tAniO.name]=tAni;
  10689. tAni._setControlNode(root);
  10690. switch (tAniO.action){
  10691. case 1:
  10692. tAni.play(0,false);
  10693. break ;
  10694. case 2:
  10695. tAni.play(0,true);
  10696. break ;
  10697. }
  10698. anilist.push(tAni);
  10699. }
  10700. root._aniList=anilist;
  10701. }
  10702. if (root._$componentType==="Scene" && root._width > 0 && uiView.props.hitTestPrior==null && !root.mouseThrough)
  10703. root.hitTestPrior=true;
  10704. tInitTool.beginLoad(root);
  10705. return root;
  10706. }
  10707. SceneUtils.createInitTool=function(){
  10708. return InitTool.create();
  10709. }
  10710. SceneUtils.createComp=function(uiView,comp,view,dataMap,initTool){
  10711. if (uiView.type=="Scene3D"||uiView.type=="Sprite3D"){
  10712. var outBatchSprits=[];
  10713. var scene3D=Laya["Utils3D"]._createSceneByJsonForMaker(uiView,outBatchSprits,initTool);
  10714. if (uiView.type=="Sprite3D")
  10715. Laya["StaticBatchManager"].combine(scene3D,outBatchSprits);
  10716. else
  10717. Laya["StaticBatchManager"].combine(null,outBatchSprits);
  10718. return scene3D;
  10719. }
  10720. comp=comp || SceneUtils.getCompInstance(uiView);
  10721. if (!comp){
  10722. if (uiView.props && uiView.props.runtime)
  10723. console.warn("runtime not found:"+uiView.props.runtime);
  10724. else
  10725. console.warn("can not create:"+uiView.type);
  10726. return null;
  10727. };
  10728. var child=uiView.child;
  10729. if (child){
  10730. var isList=comp["_$componentType"]=="List";
  10731. for (var i=0,n=child.length;i < n;i++){
  10732. var node=child[i];
  10733. if (comp.hasOwnProperty("itemRender")&& (node.props.name=="render" || node.props.renderType==="render")){
  10734. comp["itemRender"]=node;
  10735. }else if (node.type=="Graphic"){
  10736. ClassUtils._addGraphicsToSprite(node,comp);
  10737. }else if (ClassUtils._isDrawType(node.type)){
  10738. ClassUtils._addGraphicToSprite(node,comp,true);
  10739. }else {
  10740. if (isList){
  10741. var arr=[];
  10742. var tChild=SceneUtils.createComp(node,null,view,arr,initTool);
  10743. if (arr.length)
  10744. tChild["_$bindData"]=arr;
  10745. }else {
  10746. tChild=SceneUtils.createComp(node,null,view,dataMap,initTool);
  10747. }
  10748. if (node.type=="Script"){
  10749. if ((tChild instanceof laya.components.Component )){
  10750. comp._addComponentInstance(tChild);
  10751. }else {
  10752. if ("owner" in tChild){
  10753. tChild["owner"]=comp;
  10754. }else if ("target" in tChild){
  10755. tChild["target"]=comp;
  10756. }
  10757. }
  10758. }else if (node.props.renderType=="mask" || node.props.name=="mask"){
  10759. comp.mask=tChild;
  10760. }else {(
  10761. tChild instanceof laya.display.Node )&& comp.addChild(tChild);
  10762. }
  10763. }
  10764. }
  10765. };
  10766. var props=uiView.props;
  10767. for (var prop in props){
  10768. var value=props[prop];
  10769. if ((typeof value=='string')&& (value.indexOf("@node:")>=0 || value.indexOf("@Prefab:")>=0)){
  10770. if (initTool){
  10771. initTool.addNodeRef(comp,prop,value);
  10772. }
  10773. }else
  10774. SceneUtils.setCompValue(comp,prop,value,view,dataMap);
  10775. }
  10776. if (comp._afterInited){
  10777. comp._afterInited();
  10778. }
  10779. if (uiView.compId && initTool && initTool._idMap){
  10780. initTool._idMap[uiView.compId]=comp;
  10781. }
  10782. return comp;
  10783. }
  10784. SceneUtils.setCompValue=function(comp,prop,value,view,dataMap){
  10785. if ((typeof value=='string')&& value.indexOf("${")>-1){
  10786. SceneUtils._sheet || (SceneUtils._sheet=ClassUtils.getClass("laya.data.Table"));
  10787. if (!SceneUtils._sheet){
  10788. console.warn("Can not find class Sheet");
  10789. return;
  10790. }
  10791. if (dataMap){
  10792. dataMap.push(comp,prop,value);
  10793. }else if (view){
  10794. if (value.indexOf("].")==-1){
  10795. value=value.replace(".","[0].");
  10796. };
  10797. var watcher=new DataWatcher(comp,prop,value);
  10798. watcher.exe(view);
  10799. var one,temp;
  10800. var str=value.replace(/\[.*?\]\./g,".");
  10801. while ((one=SceneUtils._parseWatchData.exec(str))!=null){
  10802. var key1=one[1];
  10803. while ((temp=SceneUtils._parseKeyWord.exec(key1))!=null){
  10804. var key2=temp[0];
  10805. var arr=(view._watchMap[key2] || (view._watchMap[key2]=[]));
  10806. arr.push(watcher);
  10807. SceneUtils._sheet.I.notifer.on(key2,view,view.changeData,[key2]);
  10808. }
  10809. arr=(view._watchMap[key1] || (view._watchMap[key1]=[]));
  10810. arr.push(watcher);
  10811. SceneUtils._sheet.I.notifer.on(key1,view,view.changeData,[key1]);
  10812. }
  10813. }
  10814. return;
  10815. }
  10816. if (prop==="var" && view){
  10817. view[value]=comp;
  10818. }else {
  10819. comp[prop]=(value==="true" ? true :(value==="false" ? false :value));
  10820. }
  10821. }
  10822. SceneUtils.getCompInstance=function(json){
  10823. if (json.type=="UIView"){
  10824. if (json.props && json.props.pageData){
  10825. return SceneUtils.createByData(null,json.props.pageData);
  10826. }
  10827. };
  10828. var runtime=(json.props && json.props.runtime)|| json.type;
  10829. var compClass=ClassUtils.getClass(runtime);
  10830. if (!compClass)throw "Can not find class "+runtime;
  10831. if (json.type==="Script" && compClass.prototype._doAwake){
  10832. var comp=Pool.createByClass(compClass);
  10833. comp._destroyed=false;
  10834. return comp;
  10835. }
  10836. if (json.props && json.props.hasOwnProperty("renderType")&& json.props["renderType"]=="instance"){
  10837. if (!compClass["instance"])compClass["instance"]=new compClass();
  10838. return compClass["instance"];
  10839. }
  10840. return new compClass();
  10841. }
  10842. SceneUtils._sheet=null;
  10843. __static(SceneUtils,
  10844. ['_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;}
  10845. ]);
  10846. SceneUtils.__init$=function(){
  10847. /**
  10848. *@private 场景辅助类
  10849. */
  10850. //class DataWatcher
  10851. DataWatcher=(function(){
  10852. function DataWatcher(comp,prop,value){
  10853. this.comp=null;
  10854. this.prop=null;
  10855. this.value=null;
  10856. this.comp=comp;
  10857. this.prop=prop;
  10858. this.value=value;
  10859. }
  10860. __class(DataWatcher,'');
  10861. var __proto=DataWatcher.prototype;
  10862. __proto.exe=function(view){
  10863. var fun=SceneUtils.getBindFun(this.value);
  10864. this.comp[this.prop]=fun.call(this,view);
  10865. }
  10866. return DataWatcher;
  10867. })()
  10868. /**
  10869. *@private 场景辅助类
  10870. */
  10871. //class InitTool
  10872. InitTool=(function(){
  10873. function InitTool(){
  10874. /**@private */
  10875. this._nodeRefList=null;
  10876. /**@private */
  10877. this._initList=null;
  10878. this._loadList=null;
  10879. /**@private */
  10880. this._idMap=null;
  10881. this._scene=null;
  10882. }
  10883. __class(InitTool,'');
  10884. var __proto=InitTool.prototype;
  10885. //TODO:coverage
  10886. __proto.reset=function(){
  10887. this._nodeRefList=null;
  10888. this._initList=null;
  10889. this._idMap=null;
  10890. this._loadList=null;
  10891. this._scene=null;
  10892. }
  10893. //TODO:coverage
  10894. __proto.recover=function(){
  10895. this.reset();
  10896. Pool.recover("InitTool",this);
  10897. }
  10898. //TODO:coverage
  10899. __proto.addLoadRes=function(url,type){
  10900. if (!this._loadList)this._loadList=[];
  10901. if (!type){
  10902. this._loadList.push(url);
  10903. }else {
  10904. this._loadList.push({url:url,type:type});
  10905. }
  10906. }
  10907. //TODO:coverage
  10908. __proto.addNodeRef=function(node,prop,referStr){
  10909. if (!this._nodeRefList)this._nodeRefList=[];
  10910. this._nodeRefList.push([node,prop,referStr]);
  10911. if (referStr.indexOf("@Prefab:")>=0){
  10912. this.addLoadRes(referStr.replace("@Prefab:",""),/*laya.net.Loader.PREFAB*/"prefab");
  10913. }
  10914. }
  10915. //TODO:coverage
  10916. __proto.setNodeRef=function(){
  10917. if (!this._nodeRefList)return;
  10918. if (!this._idMap){
  10919. this._nodeRefList=null;
  10920. return;
  10921. };
  10922. var i=0,len=0;
  10923. len=this._nodeRefList.length;
  10924. var tRefInfo;
  10925. for (i=0;i < len;i++){
  10926. tRefInfo=this._nodeRefList[i];
  10927. tRefInfo[0][tRefInfo[1]]=this.getReferData(tRefInfo[2]);
  10928. }
  10929. this._nodeRefList=null;
  10930. }
  10931. //TODO:coverage
  10932. __proto.getReferData=function(referStr){
  10933. if (referStr.indexOf("@Prefab:")>=0){
  10934. var prefab;
  10935. prefab=Loader.getRes(referStr.replace("@Prefab:",""));
  10936. return prefab;
  10937. }else if (referStr.indexOf("@arr:")>=0){
  10938. referStr=referStr.replace("@arr:","");
  10939. var list;
  10940. list=referStr.split(",");
  10941. var i=0,len=0;
  10942. var tStr;
  10943. len=list.length;
  10944. for (i=0;i < len;i++){
  10945. tStr=list[i];
  10946. if (tStr){
  10947. list[i]=this._idMap[tStr.replace("@node:","")];
  10948. }else {
  10949. list[i]=null;
  10950. }
  10951. }
  10952. return list;
  10953. }else {
  10954. return this._idMap[referStr.replace("@node:","")];
  10955. }
  10956. }
  10957. //TODO:coverage
  10958. __proto.addInitItem=function(item){
  10959. if (!this._initList)this._initList=[];
  10960. this._initList.push(item);
  10961. }
  10962. //TODO:coverage
  10963. __proto.doInits=function(){
  10964. if (!this._initList)return;
  10965. this._initList=null;
  10966. }
  10967. //TODO:coverage
  10968. __proto.finish=function(){
  10969. this.setNodeRef();
  10970. this.doInits();
  10971. this._scene._setBit(/*laya.Const.NOT_READY*/0x08,false);
  10972. if (this._scene.parent && this._scene.parent.activeInHierarchy && this._scene.active)this._scene._processActive();
  10973. this._scene.event("onViewCreated");
  10974. this.recover();
  10975. }
  10976. //TODO:coverage
  10977. __proto.beginLoad=function(scene){
  10978. this._scene=scene;
  10979. if (!this._loadList || this._loadList.length < 1){
  10980. this.finish();
  10981. }else {
  10982. Laya.loader.load(this._loadList,Handler.create(this,this.finish));
  10983. }
  10984. }
  10985. InitTool.create=function(){
  10986. var tool=Pool.getItemByClass("InitTool",InitTool);
  10987. tool._idMap=[];
  10988. return tool;
  10989. }
  10990. return InitTool;
  10991. })()
  10992. }
  10993. return SceneUtils;
  10994. })()
  10995. /**
  10996. *<p><code>Rectangle</code> 对象是按其位置(由它左上角的点 (x,y)确定)以及宽度和高度定义的区域。</p>
  10997. *<p>Rectangle 类的 x、y、width 和 height 属性相互独立;更改一个属性的值不会影响其他属性。</p>
  10998. */
  10999. //class laya.maths.Rectangle
  11000. var Rectangle=(function(){
  11001. function Rectangle(x,y,width,height){
  11002. /**矩形左上角的 X 轴坐标。*/
  11003. //this.x=NaN;
  11004. /**矩形左上角的 Y 轴坐标。*/
  11005. //this.y=NaN;
  11006. /**矩形的宽度。*/
  11007. //this.width=NaN;
  11008. /**矩形的高度。*/
  11009. //this.height=NaN;
  11010. (x===void 0)&& (x=0);
  11011. (y===void 0)&& (y=0);
  11012. (width===void 0)&& (width=0);
  11013. (height===void 0)&& (height=0);
  11014. this.x=x;
  11015. this.y=y;
  11016. this.width=width;
  11017. this.height=height;
  11018. }
  11019. __class(Rectangle,'laya.maths.Rectangle');
  11020. var __proto=Rectangle.prototype;
  11021. /**
  11022. *将 Rectangle 的属性设置为指定值。
  11023. *@param x x 矩形左上角的 X 轴坐标。
  11024. *@param y x 矩形左上角的 Y 轴坐标。
  11025. *@param width 矩形的宽度。
  11026. *@param height 矩形的高。
  11027. *@return 返回属性值修改后的矩形对象本身。
  11028. */
  11029. __proto.setTo=function(x,y,width,height){
  11030. this.x=x;
  11031. this.y=y;
  11032. this.width=width;
  11033. this.height=height;
  11034. return this;
  11035. }
  11036. /**
  11037. *重置
  11038. */
  11039. __proto.reset=function(){
  11040. this.x=this.y=this.width=this.height=0;
  11041. return this;
  11042. }
  11043. /**
  11044. *回收
  11045. */
  11046. __proto.recover=function(){
  11047. if (this==Rectangle.TEMP || this==Rectangle.EMPTY){
  11048. console.log("recover Temp or Empty:",this);
  11049. return;
  11050. }
  11051. Pool.recover("Rectangle",this.reset());
  11052. }
  11053. /**
  11054. *复制 source 对象的属性值到此矩形对象中。
  11055. *@param sourceRect 源 Rectangle 对象。
  11056. *@return 返回属性值修改后的矩形对象本身。
  11057. */
  11058. __proto.copyFrom=function(source){
  11059. this.x=source.x;
  11060. this.y=source.y;
  11061. this.width=source.width;
  11062. this.height=source.height;
  11063. return this;
  11064. }
  11065. /**
  11066. *确定由此 Rectangle 对象定义的矩形区域内是否包含指定的点。
  11067. *@param x 点的 X 轴坐标值(水平位置)。
  11068. *@param y 点的 Y 轴坐标值(垂直位置)。
  11069. *@return 如果 Rectangle 对象包含指定的点,则值为 true;否则为 false。
  11070. */
  11071. __proto.contains=function(x,y){
  11072. if (this.width <=0 || this.height <=0)return false;
  11073. if (x >=this.x && x < this.right){
  11074. if (y >=this.y && y < this.bottom){
  11075. return true;
  11076. }
  11077. }
  11078. return false;
  11079. }
  11080. /**
  11081. *确定在 rect 参数中指定的对象是否与此 Rectangle 对象相交。此方法检查指定的 Rectangle 对象的 x、y、width 和 height 属性,以查看它是否与此 Rectangle 对象相交。
  11082. *@param rect Rectangle 对象。
  11083. *@return 如果传入的矩形对象与此对象相交,则返回 true 值,否则返回 false。
  11084. */
  11085. __proto.intersects=function(rect){
  11086. 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);
  11087. }
  11088. /**
  11089. *如果在 rect 参数中指定的 Rectangle 对象与此 Rectangle 对象相交,则返回交集区域作为 Rectangle 对象。如果矩形不相交,则此方法返回null。
  11090. *@param rect 待比较的矩形区域。
  11091. *@param out (可选)待输出的矩形区域。如果为空则创建一个新的。建议:尽量复用对象,减少对象创建消耗。
  11092. *@return 返回相交的矩形区域对象。
  11093. */
  11094. __proto.intersection=function(rect,out){
  11095. if (!this.intersects(rect))return null;
  11096. out || (out=new Rectangle());
  11097. out.x=Math.max(this.x,rect.x);
  11098. out.y=Math.max(this.y,rect.y);
  11099. out.width=Math.min(this.right,rect.right)-out.x;
  11100. out.height=Math.min(this.bottom,rect.bottom)-out.y;
  11101. return out;
  11102. }
  11103. /**
  11104. *<p>矩形联合,通过填充两个矩形之间的水平和垂直空间,将这两个矩形组合在一起以创建一个新的 Rectangle 对象。</p>
  11105. *<p>注意:union()方法忽略高度或宽度值为 0 的矩形,如:var rect2:Rectangle=new Rectangle(300,300,50,0);</p>
  11106. *@param 要添加到此 Rectangle 对象的 Rectangle 对象。
  11107. *@param out 用于存储输出结果的矩形对象。如果为空,则创建一个新的。建议:尽量复用对象,减少对象创建消耗。Rectangle.TEMP对象用于对象复用。
  11108. *@return 充当两个矩形的联合的新 Rectangle 对象。
  11109. */
  11110. __proto.union=function(source,out){
  11111. out || (out=new Rectangle());
  11112. this.clone(out);
  11113. if (source.width <=0 || source.height <=0)return out;
  11114. out.addPoint(source.x,source.y);
  11115. out.addPoint(source.right,source.bottom);
  11116. return this;
  11117. }
  11118. /**
  11119. *返回一个 Rectangle 对象,其 x、y、width 和 height 属性的值与当前 Rectangle 对象的对应值相同。
  11120. *@param out (可选)用于存储结果的矩形对象。如果为空,则创建一个新的。建议:尽量复用对象,减少对象创建消耗。。Rectangle.TEMP对象用于对象复用。
  11121. *@return Rectangle 对象,其 x、y、width 和 height 属性的值与当前 Rectangle 对象的对应值相同。
  11122. */
  11123. __proto.clone=function(out){
  11124. out || (out=new Rectangle());
  11125. out.x=this.x;
  11126. out.y=this.y;
  11127. out.width=this.width;
  11128. out.height=this.height;
  11129. return out;
  11130. }
  11131. /**
  11132. *当前 Rectangle 对象的水平位置 x 和垂直位置 y 以及高度 width 和宽度 height 以逗号连接成的字符串。
  11133. */
  11134. __proto.toString=function(){
  11135. return this.x+","+this.y+","+this.width+","+this.height;
  11136. }
  11137. /**
  11138. *检测传入的 Rectangle 对象的属性是否与当前 Rectangle 对象的属性 x、y、width、height 属性值都相等。
  11139. *@param rect 待比较的 Rectangle 对象。
  11140. *@return 如果判断的属性都相等,则返回 true ,否则返回 false。
  11141. */
  11142. __proto.equals=function(rect){
  11143. if (!rect || rect.x!==this.x || rect.y!==this.y || rect.width!==this.width || rect.height!==this.height)return false;
  11144. return true;
  11145. }
  11146. /**
  11147. *<p>为当前矩形对象加一个点,以使当前矩形扩展为包含当前矩形和此点的最小矩形。</p>
  11148. *<p>此方法会修改本对象。</p>
  11149. *@param x 点的 X 坐标。
  11150. *@param y 点的 Y 坐标。
  11151. *@return 返回此 Rectangle 对象。
  11152. */
  11153. __proto.addPoint=function(x,y){
  11154. this.x > x && (this.width+=this.x-x,this.x=x);
  11155. this.y > y && (this.height+=this.y-y,this.y=y);
  11156. if (this.width < x-this.x)this.width=x-this.x;
  11157. if (this.height < y-this.y)this.height=y-this.y;
  11158. return this;
  11159. }
  11160. /**
  11161. *@private
  11162. *返回代表当前矩形的顶点数据。
  11163. *@return 顶点数据。
  11164. */
  11165. __proto._getBoundPoints=function(){
  11166. var rst=Rectangle._temB;
  11167. rst.length=0;
  11168. if (this.width==0 || this.height==0)return rst;
  11169. 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);
  11170. return rst;
  11171. }
  11172. /**
  11173. *确定此 Rectangle 对象是否为空。
  11174. *@return 如果 Rectangle 对象的宽度或高度小于等于 0,则返回 true 值,否则返回 false。
  11175. */
  11176. __proto.isEmpty=function(){
  11177. if (this.width <=0 || this.height <=0)return true;
  11178. return false;
  11179. }
  11180. /**此矩形右侧的 X 轴坐标。 x 和 width 属性的和。*/
  11181. __getset(0,__proto,'right',function(){
  11182. return this.x+this.width;
  11183. });
  11184. /**此矩形底端的 Y 轴坐标。y 和 height 属性的和。*/
  11185. __getset(0,__proto,'bottom',function(){
  11186. return this.y+this.height;
  11187. });
  11188. Rectangle.create=function(){
  11189. return Pool.getItemByClass("Rectangle",Rectangle);
  11190. }
  11191. Rectangle._getBoundPointS=function(x,y,width,height){
  11192. var rst=Rectangle._temA;
  11193. rst.length=0;
  11194. if (width==0 || height==0)return rst;
  11195. rst.push(x,y,x+width,y,x,y+height,x+width,y+height);
  11196. return rst;
  11197. }
  11198. Rectangle._getWrapRec=function(pointList,rst){
  11199. if (!pointList || pointList.length < 1)return rst ? rst.setTo(0,0,0,0):Rectangle.TEMP.setTo(0,0,0,0);
  11200. rst=rst ? rst :laya.maths.Rectangle.create();
  11201. var i,len=pointList.length,minX,maxX,minY,maxY,tPoint=Point.TEMP;
  11202. minX=minY=99999;
  11203. maxX=maxY=-minX;
  11204. for (i=0;i < len;i+=2){
  11205. tPoint.x=pointList[i];
  11206. tPoint.y=pointList[i+1];
  11207. minX=minX < tPoint.x ? minX :tPoint.x;
  11208. minY=minY < tPoint.y ? minY :tPoint.y;
  11209. maxX=maxX > tPoint.x ? maxX :tPoint.x;
  11210. maxY=maxY > tPoint.y ? maxY :tPoint.y;
  11211. }
  11212. return rst.setTo(minX,minY,maxX-minX,maxY-minY);
  11213. }
  11214. Rectangle.EMPTY=new Rectangle();
  11215. Rectangle.TEMP=new Rectangle();
  11216. Rectangle._temB=[];
  11217. Rectangle._temA=[];
  11218. return Rectangle;
  11219. })()
  11220. /**
  11221. *<p><code>KeyBoardManager</code> 是键盘事件管理类。该类从浏览器中接收键盘事件,并派发该事件。</p>
  11222. *<p>派发事件时若 Stage.focus 为空则只从 Stage 上派发该事件,否则将从 Stage.focus 对象开始一直冒泡派发该事件。所以在 Laya.stage 上监听键盘事件一定能够收到,如果在其他地方监听,则必须处在Stage.focus的冒泡链上才能收到该事件。</p>
  11223. *<p>用户可以通过代码 Laya.stage.focus=someNode 的方式来设置focus对象。</p>
  11224. *<p>用户可统一的根据事件对象中 e.keyCode 来判断按键类型,该属性兼容了不同浏览器的实现。</p>
  11225. */
  11226. //class laya.events.KeyBoardManager
  11227. var KeyBoardManager=(function(){
  11228. function KeyBoardManager(){}
  11229. __class(KeyBoardManager,'laya.events.KeyBoardManager');
  11230. KeyBoardManager.__init__=function(){
  11231. KeyBoardManager._addEvent("keydown");
  11232. KeyBoardManager._addEvent("keypress");
  11233. KeyBoardManager._addEvent("keyup");
  11234. }
  11235. KeyBoardManager._addEvent=function(type){
  11236. Browser.document.addEventListener(type,function(e){
  11237. laya.events.KeyBoardManager._dispatch(e,type);
  11238. },true);
  11239. }
  11240. KeyBoardManager._dispatch=function(e,type){
  11241. if (!KeyBoardManager.enabled)return;
  11242. KeyBoardManager._event._stoped=false;
  11243. KeyBoardManager._event.nativeEvent=e;
  11244. KeyBoardManager._event.keyCode=e.keyCode || e.which || e.charCode;
  11245. if (type==="keydown")KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode]=true;
  11246. else if (type==="keyup")KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode]=null;
  11247. var target=(Laya.stage.focus && (Laya.stage.focus.event !=null)&& Laya.stage.focus.displayedInStage)? Laya.stage.focus :Laya.stage;
  11248. var ct=target;
  11249. while (ct){
  11250. ct.event(type,KeyBoardManager._event.setTo(type,ct,target));
  11251. ct=ct.parent;
  11252. }
  11253. }
  11254. KeyBoardManager.hasKeyDown=function(key){
  11255. return KeyBoardManager._pressKeys[key];
  11256. }
  11257. KeyBoardManager._pressKeys={};
  11258. KeyBoardManager.enabled=true;
  11259. __static(KeyBoardManager,
  11260. ['_event',function(){return this._event=new Event();}
  11261. ]);
  11262. return KeyBoardManager;
  11263. })()
  11264. /**
  11265. *@private
  11266. *普通命令执行器
  11267. */
  11268. //class laya.layagl.LayaGLRunner
  11269. var LayaGLRunner=(function(){
  11270. function LayaGLRunner(){}
  11271. __class(LayaGLRunner,'laya.layagl.LayaGLRunner');
  11272. LayaGLRunner.uploadShaderUniforms=function(layaGL,commandEncoder,shaderData,uploadUnTexture){
  11273. var data=shaderData._data;
  11274. var shaderUniform=commandEncoder.getArrayData();
  11275. var shaderCall=0;
  11276. for (var i=0,n=shaderUniform.length;i < n;i++){
  11277. var one=shaderUniform[i];
  11278. if (uploadUnTexture || one.textureID!==-1){
  11279. var value=data[one.dataOffset];
  11280. if (value !=null)
  11281. shaderCall+=one.fun.call(one.caller,one,value);
  11282. }
  11283. }
  11284. return shaderCall;
  11285. }
  11286. LayaGLRunner.uploadCustomUniform=function(layaGL,custom,index,data){
  11287. var shaderCall=0;
  11288. var one=custom[index];
  11289. if (one && data !=null)
  11290. shaderCall+=one.fun.call(one.caller,one,data);
  11291. return shaderCall;
  11292. }
  11293. LayaGLRunner.uploadShaderUniformsForNative=function(layaGL,commandEncoder,shaderData){
  11294. var nType=/*laya.layagl.LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID*/0;
  11295. if (shaderData._runtimeCopyValues.length > 0){
  11296. nType=/*laya.layagl.LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA*/1;
  11297. };
  11298. var data=shaderData._data;
  11299. return layaGL.uploadShaderUniforms(commandEncoder,data,nType);
  11300. }
  11301. return LayaGLRunner;
  11302. })()
  11303. /**
  11304. *根据路径绘制矢量图形
  11305. */
  11306. //class laya.display.cmd.DrawPathCmd
  11307. var DrawPathCmd=(function(){
  11308. function DrawPathCmd(){
  11309. /**
  11310. *开始绘制的 X 轴位置。
  11311. */
  11312. //this.x=NaN;
  11313. /**
  11314. *开始绘制的 Y 轴位置。
  11315. */
  11316. //this.y=NaN;
  11317. /**
  11318. *路径集合,路径支持以下格式:[["moveTo",x,y],["lineTo",x,y],["arcTo",x1,y1,x2,y2,r],["closePath"]]。
  11319. */
  11320. //this.paths=null;
  11321. /**
  11322. *(可选)刷子定义,支持以下设置{fillStyle:"#FF0000"}。
  11323. */
  11324. //this.brush=null;
  11325. /**
  11326. *(可选)画笔定义,支持以下设置{strokeStyle,lineWidth,lineJoin:"bevel|round|miter",lineCap:"butt|round|square",miterLimit}。
  11327. */
  11328. //this.pen=null;
  11329. }
  11330. __class(DrawPathCmd,'laya.display.cmd.DrawPathCmd');
  11331. var __proto=DrawPathCmd.prototype;
  11332. /**
  11333. *回收到对象池
  11334. */
  11335. __proto.recover=function(){
  11336. this.paths=null;
  11337. this.brush=null;
  11338. this.pen=null;
  11339. Pool.recover("DrawPathCmd",this);
  11340. }
  11341. /**@private */
  11342. __proto.run=function(context,gx,gy){
  11343. context._drawPath(this.x+gx,this.y+gy,this.paths,this.brush,this.pen);
  11344. }
  11345. /**@private */
  11346. __getset(0,__proto,'cmdID',function(){
  11347. return "DrawPath";
  11348. });
  11349. DrawPathCmd.create=function(x,y,paths,brush,pen){
  11350. var cmd=Pool.getItemByClass("DrawPathCmd",DrawPathCmd);
  11351. cmd.x=x;
  11352. cmd.y=y;
  11353. cmd.paths=paths;
  11354. cmd.brush=brush;
  11355. cmd.pen=pen;
  11356. return cmd;
  11357. }
  11358. DrawPathCmd.ID="DrawPath";
  11359. return DrawPathCmd;
  11360. })()
  11361. /**
  11362. *...
  11363. *@author ...
  11364. */
  11365. //class laya.webgl.BufferStateBase
  11366. var BufferStateBase=(function(){
  11367. function BufferStateBase(){
  11368. /**@private [只读]*/
  11369. this._nativeVertexArrayObject=null;
  11370. /**@private [只读]*/
  11371. this._bindedIndexBuffer=null;
  11372. this._nativeVertexArrayObject=LayaGL.instance.createVertexArray();
  11373. }
  11374. __class(BufferStateBase,'laya.webgl.BufferStateBase');
  11375. var __proto=BufferStateBase.prototype;
  11376. /**
  11377. *@private
  11378. */
  11379. __proto.bind=function(){
  11380. if (BufferStateBase._curBindedBufferState!==this){
  11381. LayaGL.instance.bindVertexArray(this._nativeVertexArrayObject);
  11382. BufferStateBase._curBindedBufferState=this;
  11383. }
  11384. }
  11385. /**
  11386. *@private
  11387. */
  11388. __proto.unBind=function(){
  11389. if (BufferStateBase._curBindedBufferState===this){
  11390. LayaGL.instance.bindVertexArray(null);
  11391. BufferStateBase._curBindedBufferState=null;
  11392. }else {
  11393. throw "BufferState: must call bind() function first.";
  11394. }
  11395. }
  11396. /**
  11397. *@private
  11398. */
  11399. __proto.bindForNative=function(){
  11400. LayaGL.instance.bindVertexArray(this._nativeVertexArrayObject);
  11401. BufferStateBase._curBindedBufferState=this;
  11402. }
  11403. /**
  11404. *@private
  11405. */
  11406. __proto.unBindForNative=function(){
  11407. LayaGL.instance.bindVertexArray(null);
  11408. BufferStateBase._curBindedBufferState=null;
  11409. }
  11410. /**
  11411. *@private
  11412. */
  11413. __proto.destroy=function(){
  11414. LayaGL.instance.deleteVertexArray(this._nativeVertexArrayObject);
  11415. }
  11416. BufferStateBase._curBindedBufferState=null;
  11417. return BufferStateBase;
  11418. })()
  11419. /**
  11420. *存储命令,和restore配套使用
  11421. */
  11422. //class laya.display.cmd.SaveCmd
  11423. var SaveCmd=(function(){
  11424. function SaveCmd(){}
  11425. __class(SaveCmd,'laya.display.cmd.SaveCmd');
  11426. var __proto=SaveCmd.prototype;
  11427. /**
  11428. *回收到对象池
  11429. */
  11430. __proto.recover=function(){
  11431. Pool.recover("SaveCmd",this);
  11432. }
  11433. /**@private */
  11434. __proto.run=function(context,gx,gy){
  11435. context.save();
  11436. }
  11437. /**@private */
  11438. __getset(0,__proto,'cmdID',function(){
  11439. return "Save";
  11440. });
  11441. SaveCmd.create=function(){
  11442. var cmd=Pool.getItemByClass("SaveCmd",SaveCmd);
  11443. return cmd;
  11444. }
  11445. SaveCmd.ID="Save";
  11446. return SaveCmd;
  11447. })()
  11448. /**
  11449. *<p> <code>LocalStorage</code> 类用于没有时间限制的数据存储。</p>
  11450. */
  11451. //class laya.net.LocalStorage
  11452. var LocalStorage=(function(){
  11453. var Storage;
  11454. function LocalStorage(){}
  11455. __class(LocalStorage,'laya.net.LocalStorage');
  11456. LocalStorage.__init__=function(){
  11457. if (!LocalStorage._baseClass){
  11458. LocalStorage._baseClass=Storage;
  11459. Storage.init();
  11460. }
  11461. LocalStorage.items=LocalStorage._baseClass.items;
  11462. LocalStorage.support=LocalStorage._baseClass.support;
  11463. return LocalStorage.support;
  11464. }
  11465. LocalStorage.setItem=function(key,value){
  11466. LocalStorage._baseClass.setItem(key,value);
  11467. }
  11468. LocalStorage.getItem=function(key){
  11469. return LocalStorage._baseClass.getItem(key);
  11470. }
  11471. LocalStorage.setJSON=function(key,value){
  11472. LocalStorage._baseClass.setJSON(key,value);
  11473. }
  11474. LocalStorage.getJSON=function(key){
  11475. return LocalStorage._baseClass.getJSON(key);
  11476. }
  11477. LocalStorage.removeItem=function(key){
  11478. LocalStorage._baseClass.removeItem(key);
  11479. }
  11480. LocalStorage.clear=function(){
  11481. LocalStorage._baseClass.clear();
  11482. }
  11483. LocalStorage._baseClass=null;
  11484. LocalStorage.items=null;
  11485. LocalStorage.support=false;
  11486. LocalStorage.__init$=function(){
  11487. //class Storage
  11488. Storage=(function(){
  11489. function Storage(){}
  11490. __class(Storage,'');
  11491. Storage.init=function(){
  11492. /*__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.');
  11493. }
  11494. Storage.setItem=function(key,value){
  11495. try {
  11496. Storage.support && Storage.items.setItem(key,value);
  11497. }catch (e){
  11498. console.warn("set localStorage failed",e);
  11499. }
  11500. }
  11501. Storage.getItem=function(key){
  11502. return Storage.support ? Storage.items.getItem(key):null;
  11503. }
  11504. Storage.setJSON=function(key,value){
  11505. try {
  11506. Storage.support && Storage.items.setItem(key,JSON.stringify(value));
  11507. }catch (e){
  11508. console.warn("set localStorage failed",e);
  11509. }
  11510. }
  11511. Storage.getJSON=function(key){
  11512. return JSON.parse(Storage.support ? Storage.items.getItem(key):null);
  11513. }
  11514. Storage.removeItem=function(key){
  11515. Storage.support && Storage.items.removeItem(key);
  11516. }
  11517. Storage.clear=function(){
  11518. Storage.support && Storage.items.clear();
  11519. }
  11520. Storage.items=null;
  11521. Storage.support=false;
  11522. return Storage;
  11523. })()
  11524. }
  11525. return LocalStorage;
  11526. })()
  11527. /**
  11528. *@private
  11529. */
  11530. //class laya.webgl.WebGL
  11531. var WebGL=(function(){
  11532. function WebGL(){}
  11533. __class(WebGL,'laya.webgl.WebGL');
  11534. WebGL._uint8ArraySlice=function(){
  11535. var _this=/*__JS__ */this;
  11536. var sz=_this.length;
  11537. var dec=new Uint8Array(_this.length);
  11538. for (var i=0;i < sz;i++)dec[i]=_this[i];
  11539. return dec;
  11540. }
  11541. WebGL._float32ArraySlice=function(){
  11542. var _this=/*__JS__ */this;
  11543. var sz=_this.length;
  11544. var dec=new Float32Array(_this.length);
  11545. for (var i=0;i < sz;i++)dec[i]=_this[i];
  11546. return dec;
  11547. }
  11548. WebGL._uint16ArraySlice=function(__arg){
  11549. var arg=arguments;
  11550. var _this=/*__JS__ */this;
  11551. var sz=0;
  11552. var dec;
  11553. var i=0;
  11554. if (arg.length===0){
  11555. sz=_this.length;
  11556. dec=new Uint16Array(sz);
  11557. for (i=0;i < sz;i++)
  11558. dec[i]=_this[i];
  11559. }else if (arg.length===2){
  11560. var start=arg[0];
  11561. var end=arg[1];
  11562. if (end > start){
  11563. sz=end-start;
  11564. dec=new Uint16Array(sz);
  11565. for (i=start;i < end;i++)
  11566. dec[i-start]=_this[i];
  11567. }else {
  11568. dec=new Uint16Array(0);
  11569. }
  11570. }
  11571. return dec;
  11572. }
  11573. WebGL._nativeRender_enable=function(){
  11574. if (WebGL.isNativeRender_enable)
  11575. return;
  11576. WebGL.isNativeRender_enable=true;
  11577. WebGLContext.__init_native();
  11578. Shader.prototype.uploadTexture2D=function (value){
  11579. var CTX=WebGLContext;
  11580. CTX.bindTexture(laya.webgl.WebGL.mainContext,CTX.TEXTURE_2D,value);
  11581. }
  11582. RenderState2D.width=Browser.window.innerWidth;
  11583. RenderState2D.height=Browser.window.innerHeight;
  11584. RunDriver.measureText=function (txt,font){
  11585. window["conchTextCanvas"].font=font;
  11586. return window["conchTextCanvas"].measureText(txt);
  11587. }
  11588. RunDriver.enableNative=function (){
  11589. if (Render.supportWebGLPlusRendering){
  11590. (LayaGLRunner).uploadShaderUniforms=LayaGLRunner.uploadShaderUniformsForNative;
  11591. /*__JS__ */CommandEncoder=window.GLCommandEncoder;
  11592. /*__JS__ */LayaGL=window.LayaGLContext;
  11593. };
  11594. var stage=Stage;
  11595. stage.prototype.render=stage.prototype.renderToNative;
  11596. }
  11597. RunDriver.clear=function (color){
  11598. Context.set2DRenderConfig();
  11599. var c=ColorUtils.create(color).arrColor;
  11600. var gl=LayaGL.instance;
  11601. if (c)gl.clearColor(c[0],c[1],c[2],c[3]);
  11602. gl.clear(/*laya.webgl.WebGLContext.COLOR_BUFFER_BIT*/0x00004000 | /*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100 | /*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400);
  11603. RenderState2D.clear();
  11604. }
  11605. RunDriver.drawToCanvas=RunDriver.drawToTexture=function (sprite,_renderType,canvasWidth,canvasHeight,offsetX,offsetY){
  11606. offsetX-=sprite.x;
  11607. offsetY-=sprite.y;
  11608. offsetX |=0;
  11609. offsetY |=0;
  11610. canvasWidth |=0;
  11611. canvasHeight |=0;
  11612. var canv=new HTMLCanvas(false);
  11613. var ctx=canv.getContext('2d');
  11614. canv.size(canvasWidth,canvasHeight);
  11615. ctx.asBitmap=true;
  11616. ctx._targets.start();
  11617. RenderSprite.renders[_renderType]._fun(sprite,ctx,offsetX,offsetY);
  11618. ctx.flush();
  11619. ctx._targets.end();
  11620. ctx._targets.restore();
  11621. return canv;
  11622. }
  11623. RenderTexture2D.prototype._uv=RenderTexture2D.flipyuv;
  11624. Object["defineProperty"](RenderTexture2D.prototype,"uv",{
  11625. "get":function (){
  11626. return this._uv;
  11627. },
  11628. "set":function (v){
  11629. this._uv=v;
  11630. }
  11631. });
  11632. HTMLCanvas.prototype.getTexture=function (){
  11633. if (!this._texture){
  11634. this._texture=this.context._targets;
  11635. this._texture.uv=RenderTexture2D.flipyuv;
  11636. this._texture.bitmap=this._texture;
  11637. }
  11638. return this._texture;
  11639. }
  11640. }
  11641. WebGL.enable=function(){
  11642. return true;
  11643. }
  11644. WebGL.inner_enable=function(){
  11645. Float32Array.prototype.slice || (Float32Array.prototype.slice=WebGL._float32ArraySlice);
  11646. Uint16Array.prototype.slice || (Uint16Array.prototype.slice=WebGL._uint16ArraySlice);
  11647. Uint8Array.prototype.slice || (Uint8Array.prototype.slice=WebGL._uint8ArraySlice);
  11648. if (Render.isConchApp){
  11649. WebGL._nativeRender_enable();
  11650. }
  11651. return true;
  11652. }
  11653. WebGL.onStageResize=function(width,height){
  11654. if (WebGL.mainContext==null)return;
  11655. WebGL.mainContext.viewport(0,0,width,height);
  11656. RenderState2D.width=width;
  11657. RenderState2D.height=height;
  11658. }
  11659. WebGL.mainContext=null;
  11660. WebGL.shaderHighPrecision=false;
  11661. WebGL._isWebGL2=false;
  11662. WebGL.isNativeRender_enable=false;
  11663. return WebGL;
  11664. })()
  11665. /**
  11666. *封装弱引用WeakMap
  11667. *如果支持WeakMap,则使用WeakMap,如果不支持,则用Object代替
  11668. *注意:如果采用Object,为了防止内存泄漏,则采用定时清理缓存策略
  11669. */
  11670. //class laya.utils.WeakObject
  11671. var WeakObject=(function(){
  11672. function WeakObject(){
  11673. /**@private */
  11674. this._obj=null;
  11675. this._obj=WeakObject.supportWeakMap ? new Browser.window.WeakMap():{};
  11676. if (!WeakObject.supportWeakMap)WeakObject._maps.push(this);
  11677. }
  11678. __class(WeakObject,'laya.utils.WeakObject');
  11679. var __proto=WeakObject.prototype;
  11680. /**
  11681. *设置缓存
  11682. *@param key kye对象,可被回收
  11683. *@param value object对象,可被回收
  11684. */
  11685. __proto.set=function(key,value){
  11686. if (key==null)return;
  11687. if (WeakObject.supportWeakMap){
  11688. var objKey=key;
  11689. if ((typeof key=='string')|| (typeof key=='number')){
  11690. objKey=WeakObject._keys[key];
  11691. if (!objKey)objKey=WeakObject._keys[key]={k:key};
  11692. }
  11693. this._obj.set(objKey,value);
  11694. }else {
  11695. if ((typeof key=='string')|| (typeof key=='number')){
  11696. this._obj[key]=value;
  11697. }else {
  11698. key.$_GID || (key.$_GID=Utils.getGID());
  11699. this._obj[key.$_GID]=value;
  11700. }
  11701. }
  11702. }
  11703. /**
  11704. *获取缓存
  11705. *@param key kye对象,可被回收
  11706. */
  11707. __proto.get=function(key){
  11708. if (key==null)return null;
  11709. if (WeakObject.supportWeakMap){
  11710. var objKey=((typeof key=='string')|| (typeof key=='number'))? WeakObject._keys[key] :key;
  11711. if (!objKey)return null;
  11712. return this._obj.get(objKey);
  11713. }else {
  11714. if ((typeof key=='string')|| (typeof key=='number'))return this._obj[key];
  11715. return this._obj[key.$_GID];
  11716. }
  11717. }
  11718. //TODO:coverage
  11719. __proto.del=function(key){
  11720. if (key==null)return;
  11721. if (WeakObject.supportWeakMap){
  11722. var objKey=((typeof key=='string')|| (typeof key=='number'))? WeakObject._keys[key] :key;
  11723. if (!objKey)return;
  11724. /*__JS__ */this._obj.delete(objKey);
  11725. }else {
  11726. if ((typeof key=='string')|| (typeof key=='number'))delete this._obj[key];
  11727. else delete this._obj[this._obj.$_GID];
  11728. }
  11729. }
  11730. //TODO:coverage
  11731. __proto.has=function(key){
  11732. if (key==null)return false;
  11733. if (WeakObject.supportWeakMap){
  11734. var objKey=((typeof key=='string')|| (typeof key=='number'))? WeakObject._keys[key] :key;
  11735. return this._obj.has(objKey);
  11736. }else {
  11737. if ((typeof key=='string')|| (typeof key=='number'))return this._obj[key] !=null;
  11738. return this._obj[this._obj.$_GID] !=null;
  11739. }
  11740. }
  11741. WeakObject.__init__=function(){
  11742. WeakObject.supportWeakMap=Browser.window.WeakMap !=null;
  11743. if (!WeakObject.supportWeakMap)Laya.systemTimer.loop(WeakObject.delInterval,null,WeakObject.clearCache);
  11744. }
  11745. WeakObject.clearCache=function(){
  11746. for (var i=0,n=WeakObject._maps.length;i < n;i++){
  11747. var obj=WeakObject._maps[i];
  11748. obj._obj={};
  11749. }
  11750. }
  11751. WeakObject.supportWeakMap=false;
  11752. WeakObject.delInterval=10 *60 *1000;
  11753. WeakObject._keys={};
  11754. WeakObject._maps=[];
  11755. __static(WeakObject,
  11756. ['I',function(){return this.I=new WeakObject();}
  11757. ]);
  11758. return WeakObject;
  11759. })()
  11760. /**
  11761. *@private
  11762. *Graphic bounds数据类
  11763. */
  11764. //class laya.display.css.BoundsStyle
  11765. var BoundsStyle=(function(){
  11766. function BoundsStyle(){
  11767. /**@private */
  11768. //this.bounds=null;
  11769. /**用户设的bounds*/
  11770. //this.userBounds=null;
  11771. /**缓存的bounds顶点,sprite计算bounds用*/
  11772. //this.temBM=null;
  11773. }
  11774. __class(BoundsStyle,'laya.display.css.BoundsStyle');
  11775. var __proto=BoundsStyle.prototype;
  11776. /**
  11777. *重置
  11778. */
  11779. __proto.reset=function(){
  11780. if(this.bounds)this.bounds.recover();
  11781. if(this.userBounds)this.userBounds.recover();
  11782. this.bounds=null;
  11783. this.userBounds=null;
  11784. this.temBM=null;
  11785. return this;
  11786. }
  11787. /**
  11788. *回收
  11789. */
  11790. __proto.recover=function(){
  11791. Pool.recover("BoundsStyle",this.reset());
  11792. }
  11793. BoundsStyle.create=function(){
  11794. return Pool.getItemByClass("BoundsStyle",BoundsStyle);
  11795. }
  11796. return BoundsStyle;
  11797. })()
  11798. //class laya.webgl.canvas.DrawStyle
  11799. var DrawStyle=(function(){
  11800. function DrawStyle(value){
  11801. this._color=null;
  11802. this.setValue(value);
  11803. }
  11804. __class(DrawStyle,'laya.webgl.canvas.DrawStyle');
  11805. var __proto=DrawStyle.prototype;
  11806. __proto.setValue=function(value){
  11807. if (value){
  11808. this._color=((value instanceof laya.utils.ColorUtils ))?(value):ColorUtils.create(value);
  11809. }
  11810. else this._color=ColorUtils.create("#000000");
  11811. }
  11812. __proto.reset=function(){
  11813. this._color=ColorUtils.create("#000000");
  11814. }
  11815. __proto.toInt=function(){
  11816. return this._color.numColor;
  11817. }
  11818. __proto.equal=function(value){
  11819. if ((typeof value=='string'))return this._color.strColor===value;
  11820. if ((value instanceof laya.utils.ColorUtils ))return this._color.numColor===(value).numColor;
  11821. return false;
  11822. }
  11823. __proto.toColorStr=function(){
  11824. return this._color.strColor;
  11825. }
  11826. DrawStyle.create=function(value){
  11827. if (value){
  11828. var color=((value instanceof laya.utils.ColorUtils ))?(value):ColorUtils.create(value);
  11829. return color._drawStyle || (color._drawStyle=new DrawStyle(value));
  11830. }
  11831. return DrawStyle.DEFAULT;
  11832. }
  11833. __static(DrawStyle,
  11834. ['DEFAULT',function(){return this.DEFAULT=new DrawStyle("#000000");}
  11835. ]);
  11836. return DrawStyle;
  11837. })()
  11838. /**
  11839. *@private
  11840. */
  11841. //class laya.system.System
  11842. var System=(function(){
  11843. function System(){}
  11844. __class(System,'laya.system.System');
  11845. System.changeDefinition=function(name,classObj){
  11846. Laya[name]=classObj;
  11847. var str=name+"=classObj";
  11848. Laya._runScript(str);
  11849. }
  11850. System.__init__=function(){}
  11851. return System;
  11852. })()
  11853. /**
  11854. *绘制粒子
  11855. *@private
  11856. */
  11857. //class laya.display.cmd.DrawParticleCmd
  11858. var DrawParticleCmd=(function(){
  11859. function DrawParticleCmd(){
  11860. //this._templ=null;
  11861. }
  11862. __class(DrawParticleCmd,'laya.display.cmd.DrawParticleCmd');
  11863. var __proto=DrawParticleCmd.prototype;
  11864. /**
  11865. *回收到对象池
  11866. */
  11867. __proto.recover=function(){
  11868. this._templ=null;
  11869. Pool.recover("DrawParticleCmd",this);
  11870. }
  11871. /**@private */
  11872. __proto.run=function(context,gx,gy){
  11873. context.drawParticle(gx,gy,this._templ);
  11874. }
  11875. /**@private */
  11876. __getset(0,__proto,'cmdID',function(){
  11877. return "DrawParticleCmd";
  11878. });
  11879. DrawParticleCmd.create=function(_temp){
  11880. var cmd=Pool.getItemByClass("DrawParticleCmd",DrawParticleCmd);
  11881. cmd._templ=_temp;
  11882. return cmd;
  11883. }
  11884. DrawParticleCmd.ID="DrawParticleCmd";
  11885. return DrawParticleCmd;
  11886. })()
  11887. /**
  11888. *@private
  11889. *<code>Render</code> 是渲染管理类。它是一个单例,可以使用 Laya.render 访问。
  11890. */
  11891. //class laya.renders.Render
  11892. var Render=(function(){
  11893. function Render(width,height){
  11894. /**@private */
  11895. this._timeId=0;
  11896. Render._mainCanvas.source.id="layaCanvas";
  11897. Render._mainCanvas.source.width=width;
  11898. Render._mainCanvas.source.height=height;
  11899. if (laya.renders.Render.isConchApp){
  11900. Browser.document.body.appendChild(Render._mainCanvas.source);
  11901. }
  11902. else{
  11903. if(!Browser.onKGMiniGame){
  11904. Browser.container.appendChild(Render._mainCanvas.source);
  11905. }
  11906. }
  11907. this.initRender(Render._mainCanvas,width,height);
  11908. Browser.window.requestAnimationFrame(loop);
  11909. function loop (stamp){
  11910. Laya.stage._loop();
  11911. Browser.window.requestAnimationFrame(loop);
  11912. }
  11913. Laya.stage.on("visibilitychange",this,this._onVisibilitychange);
  11914. }
  11915. __class(Render,'laya.renders.Render');
  11916. var __proto=Render.prototype;
  11917. /**@private */
  11918. __proto._onVisibilitychange=function(){
  11919. if (!Laya.stage.isVisibility){
  11920. this._timeId=Browser.window.setInterval(this._enterFrame,1000);
  11921. }else if (this._timeId !=0){
  11922. Browser.window.clearInterval(this._timeId);
  11923. }
  11924. }
  11925. __proto.initRender=function(canvas,w,h){
  11926. function getWebGLContext (canvas){
  11927. var gl;
  11928. var names=["webgl2","webgl","experimental-webgl","webkit-3d","moz-webgl"];
  11929. if (!Config.useWebGL2){
  11930. names.shift();
  11931. }
  11932. for (var i=0;i < names.length;i++){
  11933. try {
  11934. gl=canvas.getContext(names[i],{stencil:Config.isStencil,alpha:Config.isAlpha,antialias:Config.isAntialias,premultipliedAlpha:Config.premultipliedAlpha,preserveDrawingBuffer:Config.preserveDrawingBuffer});
  11935. }catch (e){}
  11936. if (gl){
  11937. (names[i]==='webgl2')&& (WebGL._isWebGL2=true);
  11938. new LayaGL();
  11939. return gl;
  11940. }
  11941. }
  11942. return null;
  11943. };
  11944. var gl=LayaGL.instance=WebGL.mainContext=getWebGLContext(laya.renders.Render._mainCanvas.source);
  11945. if (!gl)
  11946. return false;
  11947. canvas.size(w,h);
  11948. WebGLContext.__init__(gl);
  11949. Context.__init__();
  11950. Submit.__init__();
  11951. var ctx=new Context();
  11952. ctx.isMain=true;
  11953. laya.renders.Render._context=ctx;
  11954. canvas._setContext(ctx);
  11955. WebGL.shaderHighPrecision=false;
  11956. try {
  11957. var precisionFormat=gl.getShaderPrecisionFormat(/*laya.webgl.WebGLContext.FRAGMENT_SHADER*/0x8B30,/*laya.webgl.WebGLContext.HIGH_FLOAT*/0x8DF2);
  11958. precisionFormat.precision ? WebGL.shaderHighPrecision=true :WebGL.shaderHighPrecision=false;
  11959. }catch (e){}
  11960. LayaGL.instance=gl;
  11961. System.__init__();
  11962. ShaderDefines2D.__init__();
  11963. Value2D.__init__();
  11964. Shader2D.__init__();
  11965. Buffer2D.__int__(gl);
  11966. BlendMode._init_(gl);
  11967. return true;
  11968. }
  11969. /**@private */
  11970. __proto._enterFrame=function(e){
  11971. Laya.stage._loop();
  11972. }
  11973. /**目前使用的渲染器。*/
  11974. __getset(1,Render,'context',function(){
  11975. return Render._context;
  11976. });
  11977. /**渲染使用的原生画布引用。 */
  11978. __getset(1,Render,'canvas',function(){
  11979. return Render._mainCanvas.source;
  11980. });
  11981. Render._context=null;
  11982. Render._mainCanvas=null;
  11983. Render.supportWebGLPlusCulling=false;
  11984. Render.supportWebGLPlusAnimation=false;
  11985. Render.supportWebGLPlusRendering=false;
  11986. Render.isConchApp=false;
  11987. Render.is3DMode=false;
  11988. Render.__init$=function(){{
  11989. Render.isConchApp=/*__JS__ */(window.conch !=null);
  11990. if (Render.isConchApp){
  11991. Render.supportWebGLPlusCulling=true;
  11992. Render.supportWebGLPlusAnimation=true;
  11993. Render.supportWebGLPlusRendering=true;
  11994. }
  11995. };;
  11996. }
  11997. return Render;
  11998. })()
  11999. /**
  12000. *<code>ClassUtils</code> 是一个类工具类。
  12001. */
  12002. //class laya.utils.ClassUtils
  12003. var ClassUtils=(function(){
  12004. function ClassUtils(){}
  12005. __class(ClassUtils,'laya.utils.ClassUtils');
  12006. ClassUtils.regClass=function(className,classDef){
  12007. ClassUtils._classMap[className]=classDef;
  12008. }
  12009. ClassUtils.regShortClassName=function(classes){
  12010. for (var i=0;i < classes.length;i++){
  12011. var classDef=classes[i];
  12012. var className=classDef.name;
  12013. ClassUtils._classMap[className]=classDef;
  12014. }
  12015. }
  12016. ClassUtils.getRegClass=function(className){
  12017. return ClassUtils._classMap[className];
  12018. }
  12019. ClassUtils.getClass=function(className){
  12020. var classObject=ClassUtils._classMap[className] || className;
  12021. if ((typeof classObject=='string'))return (Laya["__classmap"][classObject] || Laya[className]);
  12022. return classObject;
  12023. }
  12024. ClassUtils.getInstance=function(className){
  12025. var compClass=ClassUtils.getClass(className);
  12026. if (compClass)return new compClass();
  12027. else console.warn("[error] Undefined class:",className);
  12028. return null;
  12029. }
  12030. ClassUtils.createByJson=function(json,node,root,customHandler,instanceHandler){
  12031. if ((typeof json=='string'))json=JSON.parse(json);
  12032. var props=json.props;
  12033. if (!node){
  12034. node=instanceHandler ? instanceHandler.runWith(json):ClassUtils.getInstance(props.runtime || json.type);
  12035. if (!node)return null;
  12036. };
  12037. var child=json.child;
  12038. if (child){
  12039. for (var i=0,n=child.length;i < n;i++){
  12040. var data=child[i];
  12041. if ((data.props.name==="render" || data.props.renderType==="render")&& node["_$set_itemRender"])
  12042. node.itemRender=data;
  12043. else {
  12044. if (data.type=="Graphic"){
  12045. ClassUtils._addGraphicsToSprite(data,node);
  12046. }else if (ClassUtils._isDrawType(data.type)){
  12047. ClassUtils._addGraphicToSprite(data,node,true);
  12048. }else {
  12049. var tChild=ClassUtils.createByJson(data,null,root,customHandler,instanceHandler)
  12050. if (data.type==="Script"){
  12051. if (tChild.hasOwnProperty("owner")){
  12052. tChild["owner"]=node;
  12053. }else if (tChild.hasOwnProperty("target")){
  12054. tChild["target"]=node;
  12055. }
  12056. }else if (data.props.renderType=="mask"){
  12057. node.mask=tChild;
  12058. }else {
  12059. node.addChild(tChild);
  12060. }
  12061. }
  12062. }
  12063. }
  12064. }
  12065. if (props){
  12066. for (var prop in props){
  12067. var value=props[prop];
  12068. if (prop==="var" && root){
  12069. root[value]=node;
  12070. }else if ((value instanceof Array)&& (typeof (node[prop])=='function')){
  12071. node[prop].apply(node,value);
  12072. }else {
  12073. node[prop]=value;
  12074. }
  12075. }
  12076. }
  12077. if (customHandler && json.customProps){
  12078. customHandler.runWith([node,json]);
  12079. }
  12080. if (node["created"])node.created();
  12081. return node;
  12082. }
  12083. ClassUtils._addGraphicsToSprite=function(graphicO,sprite){
  12084. var graphics=graphicO.child;
  12085. if (!graphics || graphics.length < 1)return;
  12086. var g=ClassUtils._getGraphicsFromSprite(graphicO,sprite);
  12087. var ox=0;
  12088. var oy=0;
  12089. if (graphicO.props){
  12090. ox=ClassUtils._getObjVar(graphicO.props,"x",0);
  12091. oy=ClassUtils._getObjVar(graphicO.props,"y",0);
  12092. }
  12093. if (ox !=0 && oy !=0){
  12094. g.translate(ox,oy);
  12095. };
  12096. var i=0,len=0;
  12097. len=graphics.length;
  12098. for (i=0;i < len;i++){
  12099. ClassUtils._addGraphicToGraphics(graphics[i],g);
  12100. }
  12101. if (ox !=0 && oy !=0){
  12102. g.translate(-ox,-oy);
  12103. }
  12104. }
  12105. ClassUtils._addGraphicToSprite=function(graphicO,sprite,isChild){
  12106. (isChild===void 0)&& (isChild=false);
  12107. var g=isChild ? ClassUtils._getGraphicsFromSprite(graphicO,sprite):sprite.graphics;
  12108. ClassUtils._addGraphicToGraphics(graphicO,g);
  12109. }
  12110. ClassUtils._getGraphicsFromSprite=function(dataO,sprite){
  12111. if (!dataO || !dataO.props)return sprite.graphics;
  12112. var propsName=dataO.props.renderType;
  12113. if (propsName==="hit" || propsName==="unHit"){
  12114. var hitArea=sprite._style.hitArea || (sprite.hitArea=new HitArea());
  12115. if (!hitArea[propsName]){
  12116. hitArea[propsName]=new Graphics();
  12117. };
  12118. var g=hitArea[propsName];
  12119. }
  12120. if (!g)g=sprite.graphics;
  12121. return g;
  12122. }
  12123. ClassUtils._getTransformData=function(propsO){
  12124. var m;
  12125. if (propsO.hasOwnProperty("pivotX")|| propsO.hasOwnProperty("pivotY")){
  12126. m=m || new Matrix();
  12127. m.translate(-ClassUtils._getObjVar(propsO,"pivotX",0),-ClassUtils._getObjVar(propsO,"pivotY",0));
  12128. };
  12129. var sx=ClassUtils._getObjVar(propsO,"scaleX",1),sy=ClassUtils._getObjVar(propsO,"scaleY",1);
  12130. var rotate=ClassUtils._getObjVar(propsO,"rotation",0);
  12131. var skewX=ClassUtils._getObjVar(propsO,"skewX",0);
  12132. var skewY=ClassUtils._getObjVar(propsO,"skewY",0);
  12133. if (sx !=1 || sy !=1 || rotate !=0){
  12134. m=m || new Matrix();
  12135. m.scale(sx,sy);
  12136. m.rotate(rotate *0.0174532922222222);
  12137. }
  12138. return m;
  12139. }
  12140. ClassUtils._addGraphicToGraphics=function(graphicO,graphic){
  12141. var propsO;
  12142. propsO=graphicO.props;
  12143. if (!propsO)return;
  12144. var drawConfig;
  12145. drawConfig=ClassUtils.DrawTypeDic[graphicO.type];
  12146. if (!drawConfig)return;
  12147. var g=graphic;
  12148. var params=ClassUtils._getParams(propsO,drawConfig[1],drawConfig[2],drawConfig[3]);
  12149. var m=ClassUtils._tM;
  12150. if (m || ClassUtils._alpha !=1){
  12151. g.save();
  12152. if (m)g.transform(m);
  12153. if (ClassUtils._alpha !=1)g.alpha(ClassUtils._alpha);
  12154. }
  12155. g[drawConfig[0]].apply(g,params);
  12156. if (m || ClassUtils._alpha !=1){
  12157. g.restore();
  12158. }
  12159. }
  12160. ClassUtils._adptLineData=function(params){
  12161. params[2]=parseFloat(params[0])+parseFloat(params[2]);
  12162. params[3]=parseFloat(params[1])+parseFloat(params[3]);
  12163. return params;
  12164. }
  12165. ClassUtils._adptTextureData=function(params){
  12166. params[0]=Loader.getRes(params[0]);
  12167. return params;
  12168. }
  12169. ClassUtils._adptLinesData=function(params){
  12170. params[2]=ClassUtils._getPointListByStr(params[2]);
  12171. return params;
  12172. }
  12173. ClassUtils._isDrawType=function(type){
  12174. if (type==="Image")return false;
  12175. return ClassUtils.DrawTypeDic.hasOwnProperty(type);
  12176. }
  12177. ClassUtils._getParams=function(obj,params,xPos,adptFun){
  12178. (xPos===void 0)&& (xPos=0);
  12179. var rst=ClassUtils._temParam;
  12180. rst.length=params.length;
  12181. var i=0,len=0;
  12182. len=params.length;
  12183. for (i=0;i < len;i++){
  12184. rst[i]=ClassUtils._getObjVar(obj,params[i][0],params[i][1]);
  12185. }
  12186. ClassUtils._alpha=ClassUtils._getObjVar(obj,"alpha",1);
  12187. var m;
  12188. m=ClassUtils._getTransformData(obj);
  12189. if (m){
  12190. if (!xPos)xPos=0;
  12191. m.translate(rst[xPos],rst[xPos+1]);
  12192. rst[xPos]=rst[xPos+1]=0;
  12193. ClassUtils._tM=m;
  12194. }else {
  12195. ClassUtils._tM=null;
  12196. }
  12197. if (adptFun && ClassUtils[adptFun]){
  12198. rst=ClassUtils[adptFun](rst);
  12199. }
  12200. return rst;
  12201. }
  12202. ClassUtils._getPointListByStr=function(str){
  12203. var pointArr=str.split(",");
  12204. var i=0,len=0;
  12205. len=pointArr.length;
  12206. for (i=0;i < len;i++){
  12207. pointArr[i]=parseFloat(pointArr[i]);
  12208. }
  12209. return pointArr;
  12210. }
  12211. ClassUtils._getObjVar=function(obj,key,noValue){
  12212. if (obj.hasOwnProperty(key)){
  12213. return obj[key];
  12214. }
  12215. return noValue;
  12216. }
  12217. ClassUtils._temParam=[];
  12218. 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'};
  12219. ClassUtils._tM=null;
  12220. ClassUtils._alpha=NaN;
  12221. __static(ClassUtils,
  12222. ['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"]};}
  12223. ]);
  12224. return ClassUtils;
  12225. })()
  12226. /**
  12227. *@private
  12228. *Graphic bounds数据类
  12229. */
  12230. //class laya.display.GraphicsBounds
  12231. var GraphicsBounds=(function(){
  12232. function GraphicsBounds(){
  12233. /**@private */
  12234. //this._temp=null;
  12235. /**@private */
  12236. //this._bounds=null;
  12237. /**@private */
  12238. //this._rstBoundPoints=null;
  12239. /**@private */
  12240. this._cacheBoundsType=false;
  12241. /**@private */
  12242. //this._graphics=null;
  12243. }
  12244. __class(GraphicsBounds,'laya.display.GraphicsBounds');
  12245. var __proto=GraphicsBounds.prototype;
  12246. /**
  12247. *销毁
  12248. */
  12249. __proto.destroy=function(){
  12250. this._graphics=null;
  12251. this._cacheBoundsType=false;
  12252. if (this._temp)this._temp.length=0;
  12253. if (this._rstBoundPoints)this._rstBoundPoints.length=0;
  12254. if (this._bounds)this._bounds.recover();
  12255. this._bounds=null;
  12256. Pool.recover("GraphicsBounds",this);
  12257. }
  12258. /**
  12259. *重置数据
  12260. */
  12261. __proto.reset=function(){
  12262. this._temp && (this._temp.length=0);
  12263. }
  12264. /**
  12265. *获取位置及宽高信息矩阵(比较耗CPU,频繁使用会造成卡顿,尽量少用)。
  12266. *@param realSize (可选)使用图片的真实大小,默认为false
  12267. *@return 位置与宽高组成的 一个 Rectangle 对象。
  12268. */
  12269. __proto.getBounds=function(realSize){
  12270. (realSize===void 0)&& (realSize=false);
  12271. if (!this._bounds || !this._temp || this._temp.length < 1 || realSize !=this._cacheBoundsType){
  12272. this._bounds=Rectangle._getWrapRec(this.getBoundPoints(realSize),this._bounds)
  12273. }
  12274. this._cacheBoundsType=realSize;
  12275. return this._bounds;
  12276. }
  12277. /**
  12278. *@private
  12279. *@param realSize (可选)使用图片的真实大小,默认为false
  12280. *获取端点列表。
  12281. */
  12282. __proto.getBoundPoints=function(realSize){
  12283. (realSize===void 0)&& (realSize=false);
  12284. if (!this._temp || this._temp.length < 1 || realSize !=this._cacheBoundsType)
  12285. this._temp=this._getCmdPoints(realSize);
  12286. this._cacheBoundsType=realSize;
  12287. return this._rstBoundPoints=Utils.copyArray(this._rstBoundPoints,this._temp);
  12288. }
  12289. __proto._getCmdPoints=function(realSize){
  12290. (realSize===void 0)&& (realSize=false);
  12291. var context=Render._context;
  12292. var cmds=this._graphics.cmds;
  12293. var rst;
  12294. rst=this._temp || (this._temp=[]);
  12295. rst.length=0;
  12296. if (!cmds && this._graphics._one !=null){
  12297. GraphicsBounds._tempCmds.length=0;
  12298. GraphicsBounds._tempCmds.push(this._graphics._one);
  12299. cmds=GraphicsBounds._tempCmds;
  12300. }
  12301. if (!cmds)return rst;
  12302. var matrixs=GraphicsBounds._tempMatrixArrays;
  12303. matrixs.length=0;
  12304. var tMatrix=GraphicsBounds._initMatrix;
  12305. tMatrix.identity();
  12306. var tempMatrix=GraphicsBounds._tempMatrix;
  12307. var cmd;
  12308. var tex;
  12309. for (var i=0,n=cmds.length;i < n;i++){
  12310. cmd=cmds[i];
  12311. switch (cmd.cmdID){
  12312. case /*laya.display.cmd.AlphaCmd.ID*/"Alpha":
  12313. matrixs.push(tMatrix);
  12314. tMatrix=tMatrix.clone();
  12315. break ;
  12316. case /*laya.display.cmd.RestoreCmd.ID*/"Restore":
  12317. tMatrix=matrixs.pop();
  12318. break ;
  12319. case /*laya.display.cmd.ScaleCmd.ID*/"Scale":
  12320. tempMatrix.identity();
  12321. tempMatrix.translate(-cmd.pivotX,-cmd.pivotY);
  12322. tempMatrix.scale(cmd.scaleX,cmd.scaleY);
  12323. tempMatrix.translate(cmd.pivotX,cmd.pivotY);
  12324. this._switchMatrix(tMatrix,tempMatrix);
  12325. break ;
  12326. case /*laya.display.cmd.RotateCmd.ID*/"Rotate":
  12327. tempMatrix.identity();
  12328. tempMatrix.translate(-cmd.pivotX,-cmd.pivotY);
  12329. tempMatrix.rotate(cmd.angle);
  12330. tempMatrix.translate(cmd.pivotX,cmd.pivotY);
  12331. this._switchMatrix(tMatrix,tempMatrix);
  12332. break ;
  12333. case /*laya.display.cmd.TranslateCmd.ID*/"Translate":
  12334. tempMatrix.identity();
  12335. tempMatrix.translate(cmd.tx,cmd.ty);
  12336. this._switchMatrix(tMatrix,tempMatrix);
  12337. break ;
  12338. case /*laya.display.cmd.TransformCmd.ID*/"Transform":
  12339. tempMatrix.identity();
  12340. tempMatrix.translate(-cmd.pivotX,-cmd.pivotY);
  12341. tempMatrix.concat(cmd.matrix);
  12342. tempMatrix.translate(cmd.pivotX,cmd.pivotY);
  12343. this._switchMatrix(tMatrix,tempMatrix);
  12344. break ;
  12345. case /*laya.display.cmd.DrawImageCmd.ID*/"DrawImage":
  12346. case /*laya.display.cmd.FillTextureCmd.ID*/"FillTexture":
  12347. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tMatrix);
  12348. break ;
  12349. case /*laya.display.cmd.DrawTextureCmd.ID*/"DrawTexture":
  12350. tMatrix.copyTo(tempMatrix);
  12351. if(cmd.matrix)
  12352. tempMatrix.concat(cmd.matrix);
  12353. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tempMatrix);
  12354. break ;
  12355. case /*laya.display.cmd.DrawImageCmd.ID*/"DrawImage":
  12356. tex=cmd.texture;
  12357. if (realSize){
  12358. if (cmd.width && cmd.height){
  12359. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tMatrix);
  12360. }else {
  12361. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,tex.width,tex.height),tMatrix);
  12362. }
  12363. }else {
  12364. var wRate=(cmd.width || tex.sourceWidth)/ tex.width;
  12365. var hRate=(cmd.height || tex.sourceHeight)/ tex.height;
  12366. var oWidth=wRate *tex.sourceWidth;
  12367. var oHeight=hRate *tex.sourceHeight;
  12368. var offX=tex.offsetX > 0 ? tex.offsetX :0;
  12369. var offY=tex.offsetY > 0 ? tex.offsetY :0;
  12370. offX *=wRate;
  12371. offY *=hRate;
  12372. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x-offX,cmd.y-offY,oWidth,oHeight),tMatrix);
  12373. }
  12374. break ;
  12375. case /*laya.display.cmd.FillTextureCmd.ID*/"FillTexture":
  12376. if (cmd.width && cmd.height){
  12377. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tMatrix);
  12378. }else {
  12379. tex=cmd.texture;
  12380. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,tex.width,tex.height),tMatrix);
  12381. }
  12382. break ;
  12383. case /*laya.display.cmd.DrawTextureCmd.ID*/"DrawTexture":;
  12384. var drawMatrix;
  12385. if (cmd.matrix){
  12386. tMatrix.copyTo(tempMatrix);
  12387. tempMatrix.concat(cmd.matrix);
  12388. drawMatrix=tempMatrix;
  12389. }else {
  12390. drawMatrix=tMatrix;
  12391. }
  12392. if (realSize){
  12393. if (cmd.width && cmd.height){
  12394. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),drawMatrix);
  12395. }else {
  12396. tex=cmd.texture;
  12397. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,tex.width,tex.height),drawMatrix);
  12398. }
  12399. }else {
  12400. tex=cmd.texture;
  12401. wRate=(cmd.width || tex.sourceWidth)/ tex.width;
  12402. hRate=(cmd.height || tex.sourceHeight)/ tex.height;
  12403. oWidth=wRate *tex.sourceWidth;
  12404. oHeight=hRate *tex.sourceHeight;
  12405. offX=tex.offsetX > 0 ? tex.offsetX :0;
  12406. offY=tex.offsetY > 0 ? tex.offsetY :0;
  12407. offX *=wRate;
  12408. offY *=hRate;
  12409. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x-offX,cmd.y-offY,oWidth,oHeight),drawMatrix);
  12410. }
  12411. break ;
  12412. case /*laya.display.cmd.DrawRectCmd.ID*/"DrawRect":
  12413. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x,cmd.y,cmd.width,cmd.height),tMatrix);
  12414. break ;
  12415. case /*laya.display.cmd.DrawCircleCmd.ID*/"DrawCircle":
  12416. GraphicsBounds._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd.x-cmd.radius,cmd.y-cmd.radius,cmd.radius+cmd.radius,cmd.radius+cmd.radius),tMatrix);
  12417. break ;
  12418. case /*laya.display.cmd.DrawLineCmd.ID*/"DrawLine":
  12419. GraphicsBounds._tempPoints.length=0;
  12420. var lineWidth=NaN;
  12421. lineWidth=cmd.lineWidth *0.5;
  12422. if (cmd.fromX==cmd.toX){
  12423. GraphicsBounds._tempPoints.push(cmd.fromX+lineWidth,cmd.fromY,cmd.toX+lineWidth,cmd.toY,cmd.fromX-lineWidth,cmd.fromY,cmd.toX-lineWidth,cmd.toY);
  12424. }else if (cmd.fromY==cmd.toY){
  12425. GraphicsBounds._tempPoints.push(cmd.fromX,cmd.fromY+lineWidth,cmd.toX,cmd.toY+lineWidth,cmd.fromX,cmd.fromY-lineWidth,cmd.toX,cmd.toY-lineWidth);
  12426. }else {
  12427. GraphicsBounds._tempPoints.push(cmd.fromX,cmd.fromY,cmd.toX,cmd.toY);
  12428. }
  12429. GraphicsBounds._addPointArrToRst(rst,GraphicsBounds._tempPoints,tMatrix);
  12430. break ;
  12431. case /*laya.display.cmd.DrawCurvesCmd.ID*/"DrawCurves":
  12432. GraphicsBounds._addPointArrToRst(rst,Bezier.I.getBezierPoints(cmd.points),tMatrix,cmd.x,cmd.y);
  12433. break ;
  12434. case /*laya.display.cmd.DrawLinesCmd.ID*/"DrawLines":
  12435. case /*laya.display.cmd.DrawPolyCmd.ID*/"DrawPoly":
  12436. GraphicsBounds._addPointArrToRst(rst,cmd.points,tMatrix,cmd.x,cmd.y);
  12437. break ;
  12438. case /*laya.display.cmd.DrawPathCmd.ID*/"DrawPath":
  12439. GraphicsBounds._addPointArrToRst(rst,this._getPathPoints(cmd.paths),tMatrix,cmd.x,cmd.y);
  12440. break ;
  12441. case /*laya.display.cmd.DrawPieCmd.ID*/"DrawPie":
  12442. GraphicsBounds._addPointArrToRst(rst,this._getPiePoints(cmd.x,cmd.y,cmd.radius,cmd.startAngle,cmd.endAngle),tMatrix);
  12443. break ;
  12444. }
  12445. }
  12446. if (rst.length > 200){
  12447. rst=Utils.copyArray(rst,Rectangle._getWrapRec(rst)._getBoundPoints());
  12448. }else if (rst.length > 8)
  12449. rst=GrahamScan.scanPList(rst);
  12450. return rst;
  12451. }
  12452. __proto._switchMatrix=function(tMatix,tempMatrix){
  12453. tempMatrix.concat(tMatix);
  12454. tempMatrix.copyTo(tMatix);
  12455. }
  12456. /**
  12457. *获得drawPie命令可能的产生的点。注意 这里只假设用在包围盒计算上。
  12458. *@param x
  12459. *@param y
  12460. *@param radius
  12461. *@param startAngle
  12462. *@param endAngle
  12463. *@return
  12464. */
  12465. __proto._getPiePoints=function(x,y,radius,startAngle,endAngle){
  12466. var rst=GraphicsBounds._tempPoints;
  12467. GraphicsBounds._tempPoints.length=0;
  12468. var k=Math.PI / 180;
  12469. var d1=endAngle-startAngle;
  12470. if (d1 >=360 || d1 <=-360){
  12471. rst.push(x-radius,y-radius);
  12472. rst.push(x+radius,y-radius);
  12473. rst.push(x+radius,y+radius);
  12474. rst.push(x-radius,y+radius);
  12475. return rst;
  12476. }
  12477. rst.push(x,y);
  12478. var delta=d1 % 360;
  12479. if (delta < 0)delta+=360;
  12480. var end1=startAngle+delta;
  12481. var st=startAngle *k;
  12482. var ed=end1 *k;
  12483. rst.push(x+radius *Math.cos(st),y+radius *Math.sin(st));
  12484. rst.push(x+radius *Math.cos(ed),y+radius *Math.sin(ed));
  12485. var s1=Math.ceil(startAngle / 90)*90;
  12486. var s2=Math.floor(end1 / 90)*90;
  12487. for (var cs=s1;cs <=s2;cs+=90){
  12488. var csr=cs *k;
  12489. rst.push(x+radius *Math.cos(csr),y+radius *Math.sin(csr));
  12490. }
  12491. return rst;
  12492. }
  12493. /*
  12494. var segnum:int=32;
  12495. var step:Number=delta / segnum;
  12496. var i:Number;
  12497. var angle:Number=startAngle;
  12498. for (i=0;i <=segnum;i++){
  12499. rst.push(x+radius *Math.cos(angle),y+radius *Math.sin(angle));
  12500. angle+=step;
  12501. }
  12502. */
  12503. __proto._getPathPoints=function(paths){
  12504. var i=0,len=0;
  12505. var rst=GraphicsBounds._tempPoints;
  12506. rst.length=0;
  12507. len=paths.length;
  12508. var tCMD;
  12509. for (i=0;i < len;i++){
  12510. tCMD=paths[i];
  12511. if (tCMD.length > 1){
  12512. rst.push(tCMD[1],tCMD[2]);
  12513. if (tCMD.length > 3){
  12514. rst.push(tCMD[3],tCMD[4]);
  12515. }
  12516. }
  12517. }
  12518. return rst;
  12519. }
  12520. GraphicsBounds.create=function(){
  12521. return Pool.getItemByClass("GraphicsBounds",GraphicsBounds);
  12522. }
  12523. GraphicsBounds._addPointArrToRst=function(rst,points,matrix,dx,dy){
  12524. (dx===void 0)&& (dx=0);
  12525. (dy===void 0)&& (dy=0);
  12526. var i=0,len=0;
  12527. len=points.length;
  12528. for (i=0;i < len;i+=2){
  12529. GraphicsBounds._addPointToRst(rst,points[i]+dx,points[i+1]+dy,matrix);
  12530. }
  12531. }
  12532. GraphicsBounds._addPointToRst=function(rst,x,y,matrix){
  12533. var _tempPoint=Point.TEMP;
  12534. _tempPoint.setTo(x ? x :0,y ? y :0);
  12535. matrix.transformPoint(_tempPoint);
  12536. rst.push(_tempPoint.x,_tempPoint.y);
  12537. }
  12538. GraphicsBounds._tempPoints=[];
  12539. GraphicsBounds._tempMatrixArrays=[];
  12540. GraphicsBounds._tempCmds=[];
  12541. __static(GraphicsBounds,
  12542. ['_tempMatrix',function(){return this._tempMatrix=new Matrix();},'_initMatrix',function(){return this._initMatrix=new Matrix();}
  12543. ]);
  12544. return GraphicsBounds;
  12545. })()
  12546. /**
  12547. *@private
  12548. *封装GL命令
  12549. */
  12550. //class laya.layagl.LayaGL
  12551. var LayaGL=(function(){
  12552. function LayaGL(){}
  12553. __class(LayaGL,'laya.layagl.LayaGL');
  12554. var __proto=LayaGL.prototype;
  12555. //TODO:coverage
  12556. __proto.createCommandEncoder=function(reserveSize,adjustSize,isSyncToRenderThread){
  12557. (reserveSize===void 0)&& (reserveSize=128);
  12558. (adjustSize===void 0)&& (adjustSize=64);
  12559. (isSyncToRenderThread===void 0)&& (isSyncToRenderThread=false);
  12560. return new CommandEncoder(this,reserveSize,adjustSize,isSyncToRenderThread);
  12561. }
  12562. __proto.beginCommandEncoding=function(commandEncoder){}
  12563. __proto.endCommandEncoding=function(){}
  12564. __proto.matrix4x4Multiply=function(m1,m2,out){}
  12565. __proto.evaluateClipDatasRealTime=function(nodes,playCurTime,realTimeCurrentFrameIndexs,addtive){}
  12566. LayaGL.getFrameCount=function(){
  12567. return 0;
  12568. }
  12569. LayaGL.syncBufferToRenderThread=function(value,index){
  12570. (index===void 0)&& (index=0);
  12571. }
  12572. LayaGL.createArrayBufferRef=function(arrayBuffer,type,syncRender){}
  12573. LayaGL.createArrayBufferRefs=function(arrayBuffer,type,syncRender,refType){}
  12574. LayaGL.EXECUTE_JS_THREAD_BUFFER=0;
  12575. LayaGL.EXECUTE_RENDER_THREAD_BUFFER=1;
  12576. LayaGL.EXECUTE_COPY_TO_RENDER=2;
  12577. LayaGL.EXECUTE_COPY_TO_RENDER3D=3;
  12578. LayaGL.ARRAY_BUFFER_TYPE_DATA=0;
  12579. LayaGL.ARRAY_BUFFER_TYPE_CMD=1;
  12580. LayaGL.ARRAY_BUFFER_REF_REFERENCE=0;
  12581. LayaGL.ARRAY_BUFFER_REF_COPY=1;
  12582. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID=0;
  12583. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA=1;
  12584. LayaGL.instance=null;
  12585. return LayaGL;
  12586. })()
  12587. /**
  12588. *<code>Browser</code> 是浏览器代理类。封装浏览器及原生 js 提供的一些功能。
  12589. */
  12590. //class laya.utils.Browser
  12591. var Browser=(function(){
  12592. function Browser(){}
  12593. __class(Browser,'laya.utils.Browser');
  12594. /**获得设备像素比。*/
  12595. __getset(1,Browser,'pixelRatio',function(){
  12596. if (Browser._pixelRatio < 0){
  12597. Browser.__init__();
  12598. if (Browser.userAgent.indexOf("Mozilla/6.0(Linux; Android 6.0; HUAWEI NXT-AL10 Build/HUAWEINXT-AL10)")>-1)Browser._pixelRatio=2;
  12599. else {
  12600. var ctx=Browser.context;
  12601. var backingStore=ctx.backingStorePixelRatio || ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  12602. Browser._pixelRatio=(Browser._window.devicePixelRatio || 1)/ backingStore;
  12603. if (Browser._pixelRatio < 1)Browser._pixelRatio=1;
  12604. }
  12605. }
  12606. return Browser._pixelRatio;
  12607. });
  12608. /**浏览器窗口物理高度。考虑了设备像素比。*/
  12609. __getset(1,Browser,'height',function(){
  12610. Browser.__init__();
  12611. return ((Laya.stage && Laya.stage.canvasRotation)? Browser.clientWidth :Browser.clientHeight)*Browser.pixelRatio;
  12612. });
  12613. /**
  12614. *浏览器窗口可视宽度。
  12615. *通过分析浏览器信息获得。浏览器多个属性值优先级为:window.innerWidth(包含滚动条宽度)> document.body.clientWidth(不包含滚动条宽度),如果前者为0或为空,则选择后者。
  12616. */
  12617. __getset(1,Browser,'clientWidth',function(){
  12618. Browser.__init__();
  12619. return Browser._window.innerWidth || Browser._document.body.clientWidth;
  12620. });
  12621. /**浏览器原生 window 对象的引用。*/
  12622. __getset(1,Browser,'window',function(){
  12623. return Browser._window || Browser.__init__();
  12624. });
  12625. /**
  12626. *浏览器窗口可视高度。
  12627. *通过分析浏览器信息获得。浏览器多个属性值优先级为:window.innerHeight(包含滚动条高度)> document.body.clientHeight(不包含滚动条高度)> document.documentElement.clientHeight(不包含滚动条高度),如果前者为0或为空,则选择后者。
  12628. */
  12629. __getset(1,Browser,'clientHeight',function(){
  12630. Browser.__init__();
  12631. return Browser._window.innerHeight || Browser._document.body.clientHeight || Browser._document.documentElement.clientHeight;
  12632. });
  12633. /**浏览器窗口物理宽度。考虑了设备像素比。*/
  12634. __getset(1,Browser,'width',function(){
  12635. Browser.__init__();
  12636. return ((Laya.stage && Laya.stage.canvasRotation)? Browser.clientHeight :Browser.clientWidth)*Browser.pixelRatio;
  12637. });
  12638. /**画布容器,用来盛放画布的容器。方便对画布进行控制*/
  12639. __getset(1,Browser,'container',function(){
  12640. if (!Browser._container){
  12641. Browser.__init__();
  12642. Browser._container=Browser.createElement("div");
  12643. Browser._container.id="layaContainer";
  12644. Browser._document.body.appendChild(Browser._container);
  12645. }
  12646. return Browser._container;
  12647. },function(value){
  12648. Browser._container=value;
  12649. });
  12650. /**浏览器原生 document 对象的引用。*/
  12651. __getset(1,Browser,'document',function(){
  12652. Browser.__init__();
  12653. return Browser._document;
  12654. });
  12655. Browser.__init__=function(){
  12656. if (Browser._window)return Browser._window;
  12657. var win=Browser._window=/*__JS__ */window;
  12658. var doc=Browser._document=win.document;
  12659. var u=Browser.userAgent=win.navigator.userAgent;
  12660. var libs=win._layalibs;
  12661. if (libs){
  12662. libs.sort(function(a,b){
  12663. return a.i-b.i;
  12664. });
  12665. for (var j=0;j < libs.length;j++){
  12666. libs[j].f(win,doc,Laya);
  12667. }
  12668. }
  12669. if (u.indexOf("MiniGame")>-1 && Browser.window.hasOwnProperty("wx")){
  12670. if (!Laya["MiniAdpter"]){
  12671. console.error("请先添加小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  12672. }else {
  12673. Laya["MiniAdpter"].enable();
  12674. }
  12675. }
  12676. if (u.indexOf("SwanGame")>-1){
  12677. if (!Laya["BMiniAdapter"]){
  12678. console.error("请先添加百度小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  12679. }else {
  12680. Laya["BMiniAdapter"].enable();
  12681. }
  12682. }
  12683. if((typeof /*__JS__ */getApp=='function')){
  12684. if (!Laya["KGMiniAdapter"]){
  12685. console.error("请先添加小米小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  12686. }else {
  12687. Laya["KGMiniAdapter"].enable();
  12688. }
  12689. }
  12690. if (u.indexOf('OPPO')>-1 && u.indexOf('MiniGame')>-1){
  12691. if (!Laya["QGMiniAdapter"]){
  12692. console.error("请先添加OPPO小游戏适配库");
  12693. }else {
  12694. Laya["QGMiniAdapter"].enable();
  12695. }
  12696. }
  12697. win.trace=console.log;
  12698. win.requestAnimationFrame=win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || win.oRequestAnimationFrame || win.msRequestAnimationFrame || function (fun){
  12699. return win.setTimeout(fun,1000 / 60);
  12700. };
  12701. var bodyStyle=doc.body.style;
  12702. bodyStyle.margin=0;
  12703. bodyStyle.overflow='hidden';
  12704. bodyStyle['-webkit-user-select']='none';
  12705. bodyStyle['-webkit-tap-highlight-color']='rgba(200,200,200,0)';
  12706. var metas=doc.getElementsByTagName('meta');
  12707. var i=0,flag=false,content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no';
  12708. while (i < metas.length){
  12709. var meta=metas[i];
  12710. if (meta.name=='viewport'){
  12711. meta.content=content;
  12712. flag=true;
  12713. break ;
  12714. }
  12715. i++;
  12716. }
  12717. if (!flag){
  12718. meta=doc.createElement('meta');
  12719. meta.name='viewport',meta.content=content;
  12720. doc.getElementsByTagName('head')[0].appendChild(meta);
  12721. }
  12722. Browser.onMobile=/*__JS__ */window.isConchApp ? true :u.indexOf("Mobile")>-1;
  12723. Browser.onIOS=!!u.match(/\(i[^;]+;(U;)? CPU.+Mac OS X/);
  12724. Browser.onIPhone=u.indexOf("iPhone")>-1;
  12725. Browser.onMac=/*[SAFE]*/ u.indexOf("Mac OS X")>-1;
  12726. Browser.onIPad=u.indexOf("iPad")>-1;
  12727. Browser.onAndroid=u.indexOf('Android')>-1 || u.indexOf('Adr')>-1;
  12728. Browser.onWP=u.indexOf("Windows Phone")>-1;
  12729. Browser.onQQBrowser=u.indexOf("QQBrowser")>-1;
  12730. Browser.onMQQBrowser=u.indexOf("MQQBrowser")>-1 || (u.indexOf("Mobile")>-1 && u.indexOf("QQ")>-1);
  12731. Browser.onIE=!!win.ActiveXObject || "ActiveXObject" in win;
  12732. Browser.onWeiXin=u.indexOf('MicroMessenger')>-1;
  12733. Browser.onSafari=/*[SAFE]*/ u.indexOf("Safari")>-1;
  12734. Browser.onPC=!Browser.onMobile;
  12735. Browser.onMiniGame=/*[SAFE]*/ u.indexOf('MiniGame')>-1;
  12736. Browser.onBDMiniGame=/*[SAFE]*/ u.indexOf('SwanGame')>-1;
  12737. if(u.indexOf('OPPO')>-1 && u.indexOf('MiniGame')>-1){
  12738. Browser.onQGMiniGame=true;
  12739. Browser.onMiniGame=false;
  12740. }
  12741. Browser.onLimixiu=/*[SAFE]*/ u.indexOf('limixiu')>-1;
  12742. Browser.onKGMiniGame=/*[SAFE]*/ u.indexOf('QuickGame')>-1;
  12743. Browser.supportLocalStorage=LocalStorage.__init__();
  12744. Browser.supportWebAudio=SoundManager.__init__();
  12745. Render._mainCanvas=new HTMLCanvas(true);
  12746. var style=Render._mainCanvas.source.style;
  12747. style.position='absolute';
  12748. style.top=style.left="0px";
  12749. style.background="#000000";
  12750. Browser.canvas=new HTMLCanvas(true);
  12751. Browser.context=Browser.canvas.getContext('2d');
  12752. var tmpCanv=new HTMLCanvas(true);
  12753. if(laya.utils.Browser.onQGMiniGame)
  12754. tmpCanv=Render._mainCanvas;
  12755. var names=["webgl","experimental-webgl","webkit-3d","moz-webgl"];
  12756. var gl=null;
  12757. for (i=0;i < names.length;i++){
  12758. try {
  12759. gl=tmpCanv.source.getContext(names[i]);
  12760. }catch (e){}
  12761. if (gl){
  12762. Browser._supportWebGL=true;
  12763. break ;
  12764. }
  12765. }
  12766. return win;
  12767. }
  12768. Browser.createElement=function(type){
  12769. Browser.__init__();
  12770. return Browser._document.createElement(type);
  12771. }
  12772. Browser.getElementById=function(type){
  12773. Browser.__init__();
  12774. return Browser._document.getElementById(type);
  12775. }
  12776. Browser.removeElement=function(ele){
  12777. if (ele && ele.parentNode)ele.parentNode.removeChild(ele);
  12778. }
  12779. Browser.now=function(){
  12780. return /*__JS__ */Date.now();;
  12781. }
  12782. Browser.userAgent=null;
  12783. Browser.onMobile=false;
  12784. Browser.onIOS=false;
  12785. Browser.onMac=false;
  12786. Browser.onIPhone=false;
  12787. Browser.onIPad=false;
  12788. Browser.onAndroid=false;
  12789. Browser.onWP=false;
  12790. Browser.onQQBrowser=false;
  12791. Browser.onMQQBrowser=false;
  12792. Browser.onSafari=false;
  12793. Browser.onIE=false;
  12794. Browser.onWeiXin=false;
  12795. Browser.onPC=false;
  12796. Browser.onMiniGame=false;
  12797. Browser.onBDMiniGame=false;
  12798. Browser.onKGMiniGame=false;
  12799. Browser.onQGMiniGame=false;
  12800. Browser.onLimixiu=false;
  12801. Browser.onFirefox=false;
  12802. Browser.onEdge=false;
  12803. Browser.supportWebAudio=false;
  12804. Browser.supportLocalStorage=false;
  12805. Browser.canvas=null;
  12806. Browser.context=null;
  12807. Browser._window=null;
  12808. Browser._document=null;
  12809. Browser._container=null;
  12810. Browser._pixelRatio=-1;
  12811. Browser._supportWebGL=false;
  12812. return Browser;
  12813. })()
  12814. //class laya.webgl.canvas.save.SaveTransform
  12815. var SaveTransform=(function(){
  12816. function SaveTransform(){
  12817. //this._savematrix=null;
  12818. this._matrix=new Matrix();
  12819. }
  12820. __class(SaveTransform,'laya.webgl.canvas.save.SaveTransform');
  12821. var __proto=SaveTransform.prototype;
  12822. Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true})
  12823. __proto.isSaveMark=function(){return false;}
  12824. __proto.restore=function(context){
  12825. context._curMat=this._savematrix;
  12826. SaveTransform.POOL[SaveTransform.POOL._length++]=this;
  12827. }
  12828. SaveTransform.save=function(context){
  12829. var _saveMark=context._saveMark;
  12830. if ((_saveMark._saveuse & /*laya.webgl.canvas.save.SaveBase.TYPE_TRANSFORM*/0x800)===/*laya.webgl.canvas.save.SaveBase.TYPE_TRANSFORM*/0x800)return;
  12831. _saveMark._saveuse |=/*laya.webgl.canvas.save.SaveBase.TYPE_TRANSFORM*/0x800;
  12832. var no=SaveTransform.POOL;
  12833. var o=no._length > 0 ? no[--no._length] :(new SaveTransform());
  12834. o._savematrix=context._curMat;
  12835. context._curMat=context._curMat.copyTo(o._matrix);
  12836. var _save=context._save;
  12837. _save[_save._length++]=o;
  12838. }
  12839. SaveTransform.POOL=SaveBase._createArray();
  12840. return SaveTransform;
  12841. })()
  12842. /**
  12843. *@private
  12844. *CommandEncoder
  12845. */
  12846. //class laya.layagl.CommandEncoder
  12847. var CommandEncoder=(function(){
  12848. function CommandEncoder(layagl,reserveSize,adjustSize,isSyncToRenderThread){
  12849. this._idata=[];
  12850. }
  12851. __class(CommandEncoder,'laya.layagl.CommandEncoder');
  12852. var __proto=CommandEncoder.prototype;
  12853. //TODO:coverage
  12854. __proto.getArrayData=function(){
  12855. return this._idata;
  12856. }
  12857. //TODO:coverage
  12858. __proto.getPtrID=function(){
  12859. return 0;
  12860. }
  12861. __proto.beginEncoding=function(){}
  12862. __proto.endEncoding=function(){}
  12863. //TODO:coverage
  12864. __proto.clearEncoding=function(){
  12865. this._idata.length=0;
  12866. }
  12867. //TODO:coverage
  12868. __proto.getCount=function(){
  12869. return this._idata.length;
  12870. }
  12871. //TODO:coverage
  12872. __proto.add_ShaderValue=function(o){
  12873. this._idata.push(o);
  12874. }
  12875. //TODO:coverage
  12876. __proto.addShaderUniform=function(one){
  12877. this.add_ShaderValue(one);
  12878. }
  12879. return CommandEncoder;
  12880. })()
  12881. /**
  12882. *绘制文本边框
  12883. */
  12884. //class laya.display.cmd.FillBorderTextCmd
  12885. var FillBorderTextCmd=(function(){
  12886. function FillBorderTextCmd(){
  12887. /**
  12888. *在画布上输出的文本。
  12889. */
  12890. //this.text=null;
  12891. /**
  12892. *开始绘制文本的 x 坐标位置(相对于画布)。
  12893. */
  12894. //this.x=NaN;
  12895. /**
  12896. *开始绘制文本的 y 坐标位置(相对于画布)。
  12897. */
  12898. //this.y=NaN;
  12899. /**
  12900. *定义字体和字号,比如"20px Arial"。
  12901. */
  12902. //this.font=null;
  12903. /**
  12904. *定义文本颜色,比如"#ff0000"。
  12905. */
  12906. //this.fillColor=null;
  12907. /**
  12908. *定义镶边文本颜色。
  12909. */
  12910. //this.borderColor=null;
  12911. /**
  12912. *镶边线条宽度。
  12913. */
  12914. //this.lineWidth=NaN;
  12915. /**
  12916. *文本对齐方式,可选值:"left","center","right"。
  12917. */
  12918. //this.textAlign=null;
  12919. }
  12920. __class(FillBorderTextCmd,'laya.display.cmd.FillBorderTextCmd');
  12921. var __proto=FillBorderTextCmd.prototype;
  12922. /**
  12923. *回收到对象池
  12924. */
  12925. __proto.recover=function(){
  12926. Pool.recover("FillBorderTextCmd",this);
  12927. }
  12928. /**@private */
  12929. __proto.run=function(context,gx,gy){
  12930. context.fillBorderText(this.text,this.x+gx,this.y+gy,this.font,this.fillColor,this.borderColor,this.lineWidth,this.textAlign);
  12931. }
  12932. /**@private */
  12933. __getset(0,__proto,'cmdID',function(){
  12934. return "FillBorderText";
  12935. });
  12936. FillBorderTextCmd.create=function(text,x,y,font,fillColor,borderColor,lineWidth,textAlign){
  12937. var cmd=Pool.getItemByClass("FillBorderTextCmd",FillBorderTextCmd);
  12938. cmd.text=text;
  12939. cmd.x=x;
  12940. cmd.y=y;
  12941. cmd.font=font;
  12942. cmd.fillColor=fillColor;
  12943. cmd.borderColor=borderColor;
  12944. cmd.lineWidth=lineWidth;
  12945. cmd.textAlign=textAlign;
  12946. return cmd;
  12947. }
  12948. FillBorderTextCmd.ID="FillBorderText";
  12949. return FillBorderTextCmd;
  12950. })()
  12951. /**
  12952. *@private
  12953. *计算贝塞尔曲线的工具类。
  12954. */
  12955. //class laya.maths.Bezier
  12956. var Bezier=(function(){
  12957. function Bezier(){
  12958. /**@private */
  12959. this._controlPoints=[new Point(),new Point(),new Point()];
  12960. this._calFun=this.getPoint2;
  12961. }
  12962. __class(Bezier,'laya.maths.Bezier');
  12963. var __proto=Bezier.prototype;
  12964. /**@private */
  12965. __proto._switchPoint=function(x,y){
  12966. var tPoint=this._controlPoints.shift();
  12967. tPoint.setTo(x,y);
  12968. this._controlPoints.push(tPoint);
  12969. }
  12970. /**
  12971. *计算二次贝塞尔点。
  12972. */
  12973. __proto.getPoint2=function(t,rst){
  12974. var p1=this._controlPoints[0];
  12975. var p2=this._controlPoints[1];
  12976. var p3=this._controlPoints[2];
  12977. var lineX=Math.pow((1-t),2)*p1.x+2 *t *(1-t)*p2.x+Math.pow(t,2)*p3.x;
  12978. var lineY=Math.pow((1-t),2)*p1.y+2 *t *(1-t)*p2.y+Math.pow(t,2)*p3.y;
  12979. rst.push(lineX,lineY);
  12980. }
  12981. /**
  12982. *计算三次贝塞尔点
  12983. */
  12984. __proto.getPoint3=function(t,rst){
  12985. var p1=this._controlPoints[0];
  12986. var p2=this._controlPoints[1];
  12987. var p3=this._controlPoints[2];
  12988. var p4=this._controlPoints[3];
  12989. 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);
  12990. 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);
  12991. rst.push(lineX,lineY);
  12992. }
  12993. /**
  12994. *计算贝塞尔点序列
  12995. */
  12996. __proto.insertPoints=function(count,rst){
  12997. var i=NaN;
  12998. count=count > 0 ? count :5;
  12999. var dLen=NaN;
  13000. dLen=1 / count;
  13001. for (i=0;i <=1;i+=dLen){
  13002. this._calFun(i,rst);
  13003. }
  13004. }
  13005. /**
  13006. *获取贝塞尔曲线上的点。
  13007. *@param pList 控制点[x0,y0,x1,y1...]
  13008. *@param inSertCount 每次曲线的插值数量
  13009. */
  13010. __proto.getBezierPoints=function(pList,inSertCount,count){
  13011. (inSertCount===void 0)&& (inSertCount=5);
  13012. (count===void 0)&& (count=2);
  13013. var i=0,len=0;
  13014. len=pList.length;
  13015. if (len < (count+1)*2)return [];
  13016. var rst=[];
  13017. switch (count){
  13018. case 2:
  13019. this._calFun=this.getPoint2;
  13020. break ;
  13021. case 3:
  13022. this._calFun=this.getPoint3;
  13023. break ;
  13024. default :
  13025. return [];
  13026. }
  13027. while (this._controlPoints.length <=count){
  13028. this._controlPoints.push(Point.create());
  13029. }
  13030. for (i=0;i < count *2;i+=2){
  13031. this._switchPoint(pList[i],pList[i+1]);
  13032. }
  13033. for (i=count *2;i < len;i+=2){
  13034. this._switchPoint(pList[i],pList[i+1]);
  13035. if ((i / 2)% count==0)this.insertPoints(inSertCount,rst);
  13036. }
  13037. return rst;
  13038. }
  13039. __static(Bezier,
  13040. ['I',function(){return this.I=new Bezier();}
  13041. ]);
  13042. return Bezier;
  13043. })()
  13044. /**
  13045. *绘制带九宫格信息的图片
  13046. *@private
  13047. */
  13048. //class laya.display.cmd.Draw9GridTexture
  13049. var Draw9GridTexture=(function(){
  13050. function Draw9GridTexture(){
  13051. /**
  13052. *纹理。
  13053. */
  13054. //this.texture=null;
  13055. /**
  13056. *(可选)X轴偏移量。
  13057. */
  13058. //this.x=NaN;
  13059. /**
  13060. *(可选)Y轴偏移量。
  13061. */
  13062. //this.y=NaN;
  13063. /**
  13064. *(可选)宽度。
  13065. */
  13066. //this.width=NaN;
  13067. /**
  13068. *(可选)高度。
  13069. */
  13070. //this.height=NaN;
  13071. //this.sizeGrid=null;
  13072. }
  13073. __class(Draw9GridTexture,'laya.display.cmd.Draw9GridTexture');
  13074. var __proto=Draw9GridTexture.prototype;
  13075. /**
  13076. *回收到对象池
  13077. */
  13078. __proto.recover=function(){
  13079. this.texture._removeReference();
  13080. Pool.recover("Draw9GridTexture",this);
  13081. }
  13082. /**@private */
  13083. __proto.run=function(context,gx,gy){
  13084. context.drawTextureWithSizeGrid(this.texture,this.x,this.y,this.width,this.height,this.sizeGrid,gx,gy);
  13085. }
  13086. /**@private */
  13087. __getset(0,__proto,'cmdID',function(){
  13088. return "Draw9GridTexture";
  13089. });
  13090. Draw9GridTexture.create=function(texture,x,y,width,height,sizeGrid){
  13091. var cmd=Pool.getItemByClass("Draw9GridTexture",Draw9GridTexture);
  13092. cmd.texture=texture;
  13093. texture._addReference();
  13094. cmd.x=x;
  13095. cmd.y=y;
  13096. cmd.width=width;
  13097. cmd.height=height;
  13098. cmd.sizeGrid=sizeGrid;
  13099. return cmd;
  13100. }
  13101. Draw9GridTexture.ID="Draw9GridTexture";
  13102. return Draw9GridTexture;
  13103. })()
  13104. /**
  13105. *文字贴图的大图集。
  13106. */
  13107. //class laya.webgl.text.TextAtlas
  13108. var TextAtlas=(function(){
  13109. function TextAtlas(){
  13110. this.texWidth=1024;
  13111. this.texHeight=1024;
  13112. this.atlasgrid=null;
  13113. this.protectDist=1;
  13114. this.texture=null;
  13115. this.charMaps={};
  13116. this.texHeight=this.texWidth=TextRender.atlasWidth;
  13117. this.texture=TextTexture.getTextTexture(this.texWidth,this.texHeight);
  13118. if (this.texWidth / TextAtlas.atlasGridW > 256){
  13119. TextAtlas.atlasGridW=Math.ceil(this.texWidth / 256);
  13120. }
  13121. this.atlasgrid=new AtlasGrid(this.texWidth / TextAtlas.atlasGridW,this.texHeight / TextAtlas.atlasGridW,this.texture.id);
  13122. }
  13123. __class(TextAtlas,'laya.webgl.text.TextAtlas');
  13124. var __proto=TextAtlas.prototype;
  13125. __proto.setProtecteDist=function(d){
  13126. this.protectDist=d;
  13127. }
  13128. /**
  13129. *如果返回null,则表示无法加入了
  13130. *分配的时候优先选择最接近自己高度的节点
  13131. *@param w
  13132. *@param h
  13133. *@return
  13134. */
  13135. __proto.getAEmpty=function(w,h,pt){
  13136. var find=this.atlasgrid.addRect(1,Math.ceil(w / TextAtlas.atlasGridW),Math.ceil(h / TextAtlas.atlasGridW),pt);
  13137. if (find){
  13138. pt.x *=TextAtlas.atlasGridW;
  13139. pt.y *=TextAtlas.atlasGridW;
  13140. }
  13141. return find;
  13142. }
  13143. /*
  13144. public function pushData(data:ImageData,node:TextAtlasNode):void {
  13145. texture.addChar(data,node.x,node.y);
  13146. }
  13147. */
  13148. __proto.destroy=function(){
  13149. for (var k in this.charMaps){
  13150. var ri=this.charMaps[k];
  13151. ri.deleted=true;
  13152. }
  13153. this.texture.discard();
  13154. }
  13155. __proto.printDebugInfo=function(){}
  13156. /**
  13157. *大图集格子单元的占用率,老的也算上了。只是表示这个大图集还能插入多少东西。
  13158. */
  13159. __getset(0,__proto,'usedRate',function(){
  13160. return this.atlasgrid._used;
  13161. });
  13162. TextAtlas.atlasGridW=16;
  13163. return TextAtlas;
  13164. })()
  13165. /**
  13166. *@private
  13167. *<code>StringKey</code> 类用于存取字符串对应的数字。
  13168. */
  13169. //class laya.utils.StringKey
  13170. var StringKey=(function(){
  13171. function StringKey(){
  13172. this._strsToID={};
  13173. this._idToStrs=[];
  13174. this._length=0;
  13175. }
  13176. __class(StringKey,'laya.utils.StringKey');
  13177. var __proto=StringKey.prototype;
  13178. //TODO:coverage
  13179. __proto.add=function(str){
  13180. var index=this._strsToID[str];
  13181. if (index !=null)return index;
  13182. this._idToStrs[this._length]=str;
  13183. return this._strsToID[str]=this._length++;
  13184. }
  13185. //TODO:coverage
  13186. __proto.getID=function(str){
  13187. var index=this._strsToID[str];
  13188. return index==null ?-1 :index;
  13189. }
  13190. //TODO:coverage
  13191. __proto.getName=function(id){
  13192. var str=this._idToStrs[id];
  13193. return str==null ? undefined :str;
  13194. }
  13195. return StringKey;
  13196. })()
  13197. /**
  13198. *@private
  13199. *<code>Dragging</code> 类是触摸滑动控件。
  13200. */
  13201. //class laya.utils.Dragging
  13202. var Dragging=(function(){
  13203. function Dragging(){
  13204. /**被拖动的对象。*/
  13205. //this.target=null;
  13206. /**缓动衰减系数。*/
  13207. this.ratio=0.92;
  13208. /**单帧最大偏移量。*/
  13209. this.maxOffset=60;
  13210. /**滑动范围。*/
  13211. //this.area=null;
  13212. /**表示拖动是否有惯性。*/
  13213. //this.hasInertia=false;
  13214. /**橡皮筋最大值。*/
  13215. //this.elasticDistance=NaN;
  13216. /**橡皮筋回弹时间,单位为毫秒。*/
  13217. //this.elasticBackTime=NaN;
  13218. /**事件携带数据。*/
  13219. //this.data=null;
  13220. this._dragging=false;
  13221. this._clickOnly=true;
  13222. //this._elasticRateX=NaN;
  13223. //this._elasticRateY=NaN;
  13224. //this._lastX=NaN;
  13225. //this._lastY=NaN;
  13226. //this._offsetX=NaN;
  13227. //this._offsetY=NaN;
  13228. //this._offsets=null;
  13229. //this._disableMouseEvent=false;
  13230. //this._tween=null;
  13231. //this._parent=null;
  13232. }
  13233. __class(Dragging,'laya.utils.Dragging');
  13234. var __proto=Dragging.prototype;
  13235. /**
  13236. *开始拖拽。
  13237. *@param target 待拖拽的 <code>Sprite</code> 对象。
  13238. *@param area 滑动范围。
  13239. *@param hasInertia 拖动是否有惯性。
  13240. *@param elasticDistance 橡皮筋最大值。
  13241. *@param elasticBackTime 橡皮筋回弹时间,单位为毫秒。
  13242. *@param data 事件携带数据。
  13243. *@param disableMouseEvent 鼠标事件是否有效。
  13244. *@param ratio 惯性阻尼系数
  13245. */
  13246. __proto.start=function(target,area,hasInertia,elasticDistance,elasticBackTime,data,disableMouseEvent,ratio){
  13247. (ratio===void 0)&& (ratio=0.92);
  13248. this.clearTimer();
  13249. this.target=target;
  13250. this.area=area;
  13251. this.hasInertia=hasInertia;
  13252. this.elasticDistance=area ? elasticDistance :0;
  13253. this.elasticBackTime=elasticBackTime;
  13254. this.data=data;
  13255. this._disableMouseEvent=disableMouseEvent;
  13256. this.ratio=ratio;
  13257. this._parent=target.parent;
  13258. this._clickOnly=true;
  13259. this._dragging=true;
  13260. this._elasticRateX=this._elasticRateY=1;
  13261. this._lastX=this._parent.mouseX;
  13262. this._lastY=this._parent.mouseY;
  13263. Laya.stage.on(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onStageMouseUp);
  13264. Laya.stage.on(/*laya.events.Event.MOUSE_OUT*/"mouseout",this,this.onStageMouseUp);
  13265. Laya.systemTimer.frameLoop(1,this,this.loop);
  13266. }
  13267. /**
  13268. *清除计时器。
  13269. */
  13270. __proto.clearTimer=function(){
  13271. Laya.systemTimer.clear(this,this.loop);
  13272. Laya.systemTimer.clear(this,this.tweenMove);
  13273. if (this._tween){
  13274. this._tween.recover();
  13275. this._tween=null;
  13276. }
  13277. }
  13278. /**
  13279. *停止拖拽。
  13280. */
  13281. __proto.stop=function(){
  13282. if (this._dragging){
  13283. MouseManager.instance.disableMouseEvent=false;
  13284. Laya.stage.off(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onStageMouseUp);
  13285. Laya.stage.off(/*laya.events.Event.MOUSE_OUT*/"mouseout",this,this.onStageMouseUp);
  13286. this._dragging=false;
  13287. this.target && this.area && this.backToArea();
  13288. this.clear();
  13289. }
  13290. }
  13291. /**
  13292. *拖拽的循环处理函数。
  13293. */
  13294. __proto.loop=function(){
  13295. var point=this._parent.getMousePoint();
  13296. var mouseX=point.x;
  13297. var mouseY=point.y;
  13298. var offsetX=mouseX-this._lastX;
  13299. var offsetY=mouseY-this._lastY;
  13300. if (this._clickOnly){
  13301. if (Math.abs(offsetX *Laya.stage._canvasTransform.getScaleX())> 1 || Math.abs(offsetY *Laya.stage._canvasTransform.getScaleY())> 1){
  13302. this._clickOnly=false;
  13303. this._offsets || (this._offsets=[]);
  13304. this._offsets.length=0;
  13305. this.target.event(/*laya.events.Event.DRAG_START*/"dragstart",this.data);
  13306. MouseManager.instance.disableMouseEvent=this._disableMouseEvent;
  13307. }else return;
  13308. }else {
  13309. this._offsets.push(offsetX,offsetY);
  13310. }
  13311. if (offsetX===0 && offsetY===0)return;
  13312. this._lastX=mouseX;
  13313. this._lastY=mouseY;
  13314. this.target.x+=offsetX *this._elasticRateX;
  13315. this.target.y+=offsetY *this._elasticRateY;
  13316. this.area && this.checkArea();
  13317. this.target.event(/*laya.events.Event.DRAG_MOVE*/"dragmove",this.data);
  13318. }
  13319. /**
  13320. *拖拽区域检测。
  13321. */
  13322. __proto.checkArea=function(){
  13323. if (this.elasticDistance <=0){
  13324. this.backToArea();
  13325. }else {
  13326. if (this.target._x < this.area.x){
  13327. var offsetX=this.area.x-this.target._x;
  13328. }else if (this.target._x > this.area.x+this.area.width){
  13329. offsetX=this.target._x-this.area.x-this.area.width;
  13330. }else {
  13331. offsetX=0;
  13332. }
  13333. this._elasticRateX=Math.max(0,1-(offsetX / this.elasticDistance));
  13334. if (this.target._y < this.area.y){
  13335. var offsetY=this.area.y-this.target.y;
  13336. }else if (this.target._y > this.area.y+this.area.height){
  13337. offsetY=this.target._y-this.area.y-this.area.height;
  13338. }else {
  13339. offsetY=0;
  13340. }
  13341. this._elasticRateY=Math.max(0,1-(offsetY / this.elasticDistance));
  13342. }
  13343. }
  13344. /**
  13345. *移动至设定的拖拽区域。
  13346. */
  13347. __proto.backToArea=function(){
  13348. this.target.x=Math.min(Math.max(this.target._x,this.area.x),this.area.x+this.area.width);
  13349. this.target.y=Math.min(Math.max(this.target._y,this.area.y),this.area.y+this.area.height);
  13350. }
  13351. /**
  13352. *舞台的抬起事件侦听函数。
  13353. *@param e Event 对象。
  13354. */
  13355. __proto.onStageMouseUp=function(e){
  13356. MouseManager.instance.disableMouseEvent=false;
  13357. Laya.stage.off(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onStageMouseUp);
  13358. Laya.stage.off(/*laya.events.Event.MOUSE_OUT*/"mouseout",this,this.onStageMouseUp);
  13359. Laya.systemTimer.clear(this,this.loop);
  13360. if (this._clickOnly || !this.target)return;
  13361. if (this.hasInertia){
  13362. if (this._offsets.length < 1){
  13363. this._offsets.push(this._parent.mouseX-this._lastX,this._parent.mouseY-this._lastY);
  13364. }
  13365. this._offsetX=this._offsetY=0;
  13366. var len=this._offsets.length;
  13367. var n=Math.min(len,6);
  13368. var m=this._offsets.length-n;
  13369. for (var i=len-1;i > m;i--){
  13370. this._offsetY+=this._offsets[i--];
  13371. this._offsetX+=this._offsets[i];
  13372. }
  13373. this._offsetX=this._offsetX / n *2;
  13374. this._offsetY=this._offsetY / n *2;
  13375. if (Math.abs(this._offsetX)> this.maxOffset)this._offsetX=this._offsetX > 0 ? this.maxOffset :-this.maxOffset;
  13376. if (Math.abs(this._offsetY)> this.maxOffset)this._offsetY=this._offsetY > 0 ? this.maxOffset :-this.maxOffset;
  13377. Laya.systemTimer.frameLoop(1,this,this.tweenMove);
  13378. }else if (this.elasticDistance > 0){
  13379. this.checkElastic();
  13380. }else {
  13381. this.clear();
  13382. }
  13383. }
  13384. /**
  13385. *橡皮筋效果检测。
  13386. */
  13387. __proto.checkElastic=function(){
  13388. var tx=NaN;
  13389. var ty=NaN;
  13390. if (this.target.x < this.area.x)tx=this.area.x;
  13391. else if (this.target._x > this.area.x+this.area.width)tx=this.area.x+this.area.width;
  13392. if (this.target.y < this.area.y)ty=this.area.y;
  13393. else if (this.target._y > this.area.y+this.area.height)ty=this.area.y+this.area.height;
  13394. if (!isNaN(tx)|| !isNaN(ty)){
  13395. var obj={};
  13396. if (!isNaN(tx))obj.x=tx;
  13397. if (!isNaN(ty))obj.y=ty;
  13398. this._tween=Tween.to(this.target,obj,this.elasticBackTime,Ease.sineOut,Handler.create(this,this.clear),0,false,false);
  13399. }else {
  13400. this.clear();
  13401. }
  13402. }
  13403. /**
  13404. *移动。
  13405. */
  13406. __proto.tweenMove=function(){
  13407. this._offsetX *=this.ratio *this._elasticRateX;
  13408. this._offsetY *=this.ratio *this._elasticRateY;
  13409. this.target.x+=this._offsetX;
  13410. this.target.y+=this._offsetY;
  13411. this.area && this.checkArea();
  13412. this.target.event(/*laya.events.Event.DRAG_MOVE*/"dragmove",this.data);
  13413. if ((Math.abs(this._offsetX)< 1 && Math.abs(this._offsetY)< 1)|| this._elasticRateX < 0.5 || this._elasticRateY < 0.5){
  13414. Laya.systemTimer.clear(this,this.tweenMove);
  13415. if (this.elasticDistance > 0)this.checkElastic();
  13416. else this.clear();
  13417. }
  13418. }
  13419. /**
  13420. *结束拖拽。
  13421. */
  13422. __proto.clear=function(){
  13423. if (this.target){
  13424. this.clearTimer();
  13425. var sp=this.target;
  13426. this.target=null;
  13427. this._parent=null;
  13428. sp.event(/*laya.events.Event.DRAG_END*/"dragend",this.data);
  13429. }
  13430. }
  13431. return Dragging;
  13432. })()
  13433. //class laya.webgl.shapes.Earcut
  13434. var Earcut=(function(){
  13435. function Earcut(){}
  13436. __class(Earcut,'laya.webgl.shapes.Earcut');
  13437. Earcut.earcut=function(data,holeIndices,dim){
  13438. dim=dim || 2;
  13439. var hasHoles=holeIndices && holeIndices.length,
  13440. outerLen=hasHoles ? holeIndices[0] *dim :data.length,
  13441. outerNode=Earcut.linkedList(data,0,outerLen,dim,true),
  13442. triangles=[];
  13443. if (!outerNode)return triangles;
  13444. var minX,minY,maxX,maxY,x,y,invSize;
  13445. if (hasHoles)outerNode=Earcut.eliminateHoles(data,holeIndices,outerNode,dim);
  13446. if (data.length > 80 *dim){
  13447. minX=maxX=data[0];
  13448. minY=maxY=data[1];
  13449. for (var i=dim;i < outerLen;i+=dim){
  13450. x=data[i];
  13451. y=data[i+1];
  13452. if (x < minX)minX=x;
  13453. if (y < minY)minY=y;
  13454. if (x > maxX)maxX=x;
  13455. if (y > maxY)maxY=y;
  13456. }
  13457. invSize=Math.max(maxX-minX,maxY-minY);
  13458. invSize=invSize!==0 ? 1 / invSize :0;
  13459. }
  13460. Earcut.earcutLinked(outerNode,triangles,dim,minX,minY,invSize);
  13461. return triangles;
  13462. }
  13463. Earcut.linkedList=function(data,start,end,dim,clockwise){
  13464. var i,last;
  13465. if (clockwise===(Earcut.signedArea(data,start,end,dim)> 0)){
  13466. for (i=start;i < end;i+=dim)last=Earcut.insertNode(i,data[i],data[i+1],last);
  13467. }else {
  13468. for (i=end-dim;i >=start;i-=dim)last=Earcut.insertNode(i,data[i],data[i+1],last);
  13469. }
  13470. if (last && Earcut.equals(last,last.next)){
  13471. Earcut.removeNode(last);
  13472. last=last.next;
  13473. }
  13474. return last;
  13475. }
  13476. Earcut.filterPoints=function(start,end){
  13477. if (!start)return start;
  13478. if (!end)end=start;
  13479. var p=start,
  13480. again;
  13481. do {
  13482. again=false;
  13483. if (!p.steiner && (Earcut.equals(p,p.next)|| Earcut.area(p.prev,p,p.next)===0)){
  13484. Earcut.removeNode(p);
  13485. p=end=p.prev;
  13486. if (p===p.next)break ;
  13487. again=true;
  13488. }else {
  13489. p=p.next;
  13490. }
  13491. }while (again || p!==end);
  13492. return end;
  13493. }
  13494. Earcut.earcutLinked=function(ear,triangles,dim,minX,minY,invSize,pass){
  13495. if (!ear)return;
  13496. if (!pass && invSize)Earcut.indexCurve(ear,minX,minY,invSize);
  13497. var stop=ear,
  13498. prev,next;
  13499. while (ear.prev!==ear.next){
  13500. prev=ear.prev;
  13501. next=ear.next;
  13502. if (invSize ? Earcut.isEarHashed(ear,minX,minY,invSize):Earcut.isEar(ear)){
  13503. triangles.push(prev.i / dim);
  13504. triangles.push(ear.i / dim);
  13505. triangles.push(next.i / dim);
  13506. Earcut.removeNode(ear);
  13507. ear=next.next;
  13508. stop=next.next;
  13509. continue ;
  13510. }
  13511. ear=next;
  13512. if (ear===stop){
  13513. if (!pass){
  13514. Earcut.earcutLinked(Earcut.filterPoints(ear,null),triangles,dim,minX,minY,invSize,1);
  13515. }else if (pass===1){
  13516. ear=Earcut.cureLocalIntersections(ear,triangles,dim);
  13517. Earcut.earcutLinked(ear,triangles,dim,minX,minY,invSize,2);
  13518. }else if (pass===2){
  13519. Earcut.splitEarcut(ear,triangles,dim,minX,minY,invSize);
  13520. }
  13521. break ;
  13522. }
  13523. }
  13524. }
  13525. Earcut.isEar=function(ear){
  13526. var a=ear.prev,
  13527. b=ear,
  13528. c=ear.next;
  13529. if (Earcut.area(a,b,c)>=0)return false;
  13530. var p=ear.next.next;
  13531. while (p!==ear.prev){
  13532. if (Earcut.pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&
  13533. Earcut.area(p.prev,p,p.next)>=0)return false;
  13534. p=p.next;
  13535. }
  13536. return true;
  13537. }
  13538. Earcut.isEarHashed=function(ear,minX,minY,invSize){
  13539. var a=ear.prev,
  13540. b=ear,
  13541. c=ear.next;
  13542. if (Earcut.area(a,b,c)>=0)return false;
  13543. var minTX=a.x < b.x ? (a.x < c.x ? a.x :c.x):(b.x < c.x ? b.x :c.x),
  13544. minTY=a.y < b.y ? (a.y < c.y ? a.y :c.y):(b.y < c.y ? b.y :c.y),
  13545. maxTX=a.x > b.x ? (a.x > c.x ? a.x :c.x):(b.x > c.x ? b.x :c.x),
  13546. maxTY=a.y > b.y ? (a.y > c.y ? a.y :c.y):(b.y > c.y ? b.y :c.y);
  13547. var minZ=Earcut.zOrder(minTX,minTY,minX,minY,invSize),
  13548. maxZ=Earcut.zOrder(maxTX,maxTY,minX,minY,invSize);
  13549. var p=ear.nextZ;
  13550. while (p && p.z <=maxZ){
  13551. if (p!==ear.prev && p!==ear.next &&
  13552. Earcut.pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&
  13553. Earcut.area(p.prev,p,p.next)>=0)return false;
  13554. p=p.nextZ;
  13555. }
  13556. p=ear.prevZ;
  13557. while (p && p.z >=minZ){
  13558. if (p!==ear.prev && p!==ear.next &&
  13559. Earcut.pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&
  13560. Earcut.area(p.prev,p,p.next)>=0)return false;
  13561. p=p.prevZ;
  13562. }
  13563. return true;
  13564. }
  13565. Earcut.cureLocalIntersections=function(start,triangles,dim){
  13566. var p=start;
  13567. do {
  13568. var a=p.prev,
  13569. b=p.next.next;
  13570. if (!Earcut.equals(a,b)&& Earcut.intersects(a,p,p.next,b)&& Earcut.locallyInside(a,b)&& Earcut.locallyInside(b,a)){
  13571. triangles.push(a.i / dim);
  13572. triangles.push(p.i / dim);
  13573. triangles.push(b.i / dim);
  13574. Earcut.removeNode(p);
  13575. Earcut.removeNode(p.next);
  13576. p=start=b;
  13577. }
  13578. p=p.next;
  13579. }while (p!==start);
  13580. return p;
  13581. }
  13582. Earcut.splitEarcut=function(start,triangles,dim,minX,minY,invSize){
  13583. var a=start;
  13584. do {
  13585. var b=a.next.next;
  13586. while (b!==a.prev){
  13587. if (a.i!==b.i && Earcut.isValidDiagonal(a,b)){
  13588. var c=Earcut.splitPolygon(a,b);
  13589. a=Earcut.filterPoints(a,a.next);
  13590. c=Earcut.filterPoints(c,c.next);
  13591. Earcut.earcutLinked(a,triangles,dim,minX,minY,invSize);
  13592. Earcut.earcutLinked(c,triangles,dim,minX,minY,invSize);
  13593. return;
  13594. }
  13595. b=b.next;
  13596. }
  13597. a=a.next;
  13598. }while (a!==start);
  13599. }
  13600. Earcut.eliminateHoles=function(data,holeIndices,outerNode,dim){
  13601. var queue=[],
  13602. i,len,start,end,list;
  13603. for (i=0,len=holeIndices.length;i < len;i++){
  13604. start=holeIndices[i] *dim;
  13605. end=i < len-1 ? holeIndices[i+1] *dim :data.length;
  13606. list=Earcut.linkedList(data,start,end,dim,false);
  13607. if (list===list.next)list.steiner=true;
  13608. queue.push(Earcut.getLeftmost(list));
  13609. }
  13610. queue.sort(Earcut.compareX);
  13611. for (i=0;i < queue.length;i++){
  13612. Earcut.eliminateHole(queue[i],outerNode);
  13613. outerNode=Earcut.filterPoints(outerNode,outerNode.next);
  13614. }
  13615. return outerNode;
  13616. }
  13617. Earcut.compareX=function(a,b){
  13618. return a.x-b.x;
  13619. }
  13620. Earcut.eliminateHole=function(hole,outerNode){
  13621. outerNode=Earcut.findHoleBridge(hole,outerNode);
  13622. if (outerNode){
  13623. var b=Earcut.splitPolygon(outerNode,hole);
  13624. Earcut.filterPoints(b,b.next);
  13625. }
  13626. }
  13627. Earcut.findHoleBridge=function(hole,outerNode){
  13628. var p=outerNode,
  13629. hx=hole.x,
  13630. hy=hole.y,
  13631. qx=-Infinity,
  13632. m;
  13633. do {
  13634. if (hy <=p.y && hy >=p.next.y && p.next.y!==p.y){
  13635. var x=p.x+(hy-p.y)*(p.next.x-p.x)/ (p.next.y-p.y);
  13636. if (x <=hx && x > qx){
  13637. qx=x;
  13638. if (x===hx){
  13639. if (hy===p.y)return p;
  13640. if (hy===p.next.y)return p.next;
  13641. }
  13642. m=p.x < p.next.x ? p :p.next;
  13643. }
  13644. }
  13645. p=p.next;
  13646. }while (p!==outerNode);
  13647. if (!m)return null;
  13648. if (hx===qx)return m.prev;
  13649. var stop=m,
  13650. mx=m.x,
  13651. my=m.y,
  13652. tanMin=Infinity,
  13653. tan;
  13654. p=m.next;
  13655. while (p!==stop){
  13656. if (hx >=p.x && p.x >=mx && hx!==p.x &&
  13657. Earcut.pointInTriangle(hy < my ? hx :qx,hy,mx,my,hy < my ? qx :hx,hy,p.x,p.y)){
  13658. tan=Math.abs(hy-p.y)/ (hx-p.x);
  13659. if ((tan < tanMin || (tan===tanMin && p.x > m.x))&& Earcut.locallyInside(p,hole)){
  13660. m=p;
  13661. tanMin=tan;
  13662. }
  13663. }
  13664. p=p.next;
  13665. }
  13666. return m;
  13667. }
  13668. Earcut.indexCurve=function(start,minX,minY,invSize){
  13669. var p=start;
  13670. do {
  13671. if (p.z===null)p.z=Earcut.zOrder(p.x,p.y,minX,minY,invSize);
  13672. p.prevZ=p.prev;
  13673. p.nextZ=p.next;
  13674. p=p.next;
  13675. }while (p!==start);
  13676. p.prevZ.nextZ=null;
  13677. p.prevZ=null;
  13678. Earcut.sortLinked(p);
  13679. }
  13680. Earcut.sortLinked=function(list){
  13681. var i,p,q,e,tail,numMerges,pSize,qSize,
  13682. inSize=1;
  13683. do {
  13684. p=list;
  13685. list=null;
  13686. tail=null;
  13687. numMerges=0;
  13688. while (p){
  13689. numMerges++;
  13690. q=p;
  13691. pSize=0;
  13692. for (i=0;i < inSize;i++){
  13693. pSize++;
  13694. q=q.nextZ;
  13695. if (!q)break ;
  13696. }
  13697. qSize=inSize;
  13698. while (pSize > 0 || (qSize > 0 && q)){
  13699. if (pSize!==0 && (qSize===0 || !q || p.z <=q.z)){
  13700. e=p;
  13701. p=p.nextZ;
  13702. pSize--;
  13703. }else {
  13704. e=q;
  13705. q=q.nextZ;
  13706. qSize--;
  13707. }
  13708. if (tail)tail.nextZ=e;
  13709. else list=e;
  13710. e.prevZ=tail;
  13711. tail=e;
  13712. }
  13713. p=q;
  13714. }
  13715. tail.nextZ=null;
  13716. inSize *=2;
  13717. }while (numMerges > 1);
  13718. return list;
  13719. }
  13720. Earcut.zOrder=function(x,y,minX,minY,invSize){
  13721. x=32767 *(x-minX)*invSize;
  13722. y=32767 *(y-minY)*invSize;
  13723. x=(x | (x << 8))& 0x00FF00FF;
  13724. x=(x | (x << 4))& 0x0F0F0F0F;
  13725. x=(x | (x << 2))& 0x33333333;
  13726. x=(x | (x << 1))& 0x55555555;
  13727. y=(y | (y << 8))& 0x00FF00FF;
  13728. y=(y | (y << 4))& 0x0F0F0F0F;
  13729. y=(y | (y << 2))& 0x33333333;
  13730. y=(y | (y << 1))& 0x55555555;
  13731. return x | (y << 1);
  13732. }
  13733. Earcut.getLeftmost=function(start){
  13734. var p=start,
  13735. leftmost=start;
  13736. do {
  13737. if (p.x < leftmost.x)leftmost=p;
  13738. p=p.next;
  13739. }while (p!==start);
  13740. return leftmost;
  13741. }
  13742. Earcut.pointInTriangle=function(ax,ay,bx,by,cx,cy,px,py){
  13743. return (cx-px)*(ay-py)-(ax-px)*(cy-py)>=0 &&
  13744. (ax-px)*(by-py)-(bx-px)*(ay-py)>=0 &&
  13745. (bx-px)*(cy-py)-(cx-px)*(by-py)>=0;
  13746. }
  13747. Earcut.isValidDiagonal=function(a,b){
  13748. return a.next.i!==b.i && a.prev.i!==b.i && !Earcut.intersectsPolygon(a,b)&&
  13749. Earcut.locallyInside(a,b)&& Earcut.locallyInside(b,a)&& Earcut.middleInside(a,b);
  13750. }
  13751. Earcut.area=function(p,q,r){
  13752. return (q.y-p.y)*(r.x-q.x)-(q.x-p.x)*(r.y-q.y);
  13753. }
  13754. Earcut.equals=function(p1,p2){
  13755. return p1.x===p2.x && p1.y===p2.y;
  13756. }
  13757. Earcut.intersects=function(p1,q1,p2,q2){
  13758. if ((Earcut.equals(p1,q1)&& Earcut.equals(p2,q2))||
  13759. (Earcut.equals(p1,q2)&& Earcut.equals(p2,q1)))return true;
  13760. return Earcut.area(p1,q1,p2)> 0!==Earcut.area(p1,q1,q2)> 0 &&
  13761. Earcut.area(p2,q2,p1)> 0!==Earcut.area(p2,q2,q1)> 0;
  13762. }
  13763. Earcut.intersectsPolygon=function(a,b){
  13764. var p=a;
  13765. do {
  13766. if (p.i!==a.i && p.next.i!==a.i && p.i!==b.i && p.next.i!==b.i &&
  13767. Earcut.intersects(p,p.next,a,b))return true;
  13768. p=p.next;
  13769. }while (p!==a);
  13770. return false;
  13771. }
  13772. Earcut.locallyInside=function(a,b){
  13773. return Earcut.area(a.prev,a,a.next)< 0 ?
  13774. Earcut.area(a,b,a.next)>=0 && Earcut.area(a,a.prev,b)>=0 :
  13775. Earcut.area(a,b,a.prev)< 0 || Earcut.area(a,a.next,b)< 0;
  13776. }
  13777. Earcut.middleInside=function(a,b){
  13778. var p=a,
  13779. inside=false,
  13780. px=(a.x+b.x)/ 2,
  13781. py=(a.y+b.y)/ 2;
  13782. do {
  13783. if (((p.y > py)!==(p.next.y > py))&& p.next.y!==p.y &&
  13784. (px < (p.next.x-p.x)*(py-p.y)/ (p.next.y-p.y)+p.x))
  13785. inside=!inside;
  13786. p=p.next;
  13787. }while (p!==a);
  13788. return inside;
  13789. }
  13790. Earcut.splitPolygon=function(a,b){
  13791. var a2=new EarcutNode(a.i,a.x,a.y),
  13792. b2=new EarcutNode(b.i,b.x,b.y),
  13793. an=a.next,
  13794. bp=b.prev;
  13795. a.next=b;
  13796. b.prev=a;
  13797. a2.next=an;
  13798. an.prev=a2;
  13799. b2.next=a2;
  13800. a2.prev=b2;
  13801. bp.next=b2;
  13802. b2.prev=bp;
  13803. return b2;
  13804. }
  13805. Earcut.insertNode=function(i,x,y,last){
  13806. var p=new EarcutNode(i,x,y);
  13807. if (!last){
  13808. p.prev=p;
  13809. p.next=p;
  13810. }else {
  13811. p.next=last.next;
  13812. p.prev=last;
  13813. last.next.prev=p;
  13814. last.next=p;
  13815. }
  13816. return p;
  13817. }
  13818. Earcut.removeNode=function(p){
  13819. p.next.prev=p.prev;
  13820. p.prev.next=p.next;
  13821. if (p.prevZ)p.prevZ.nextZ=p.nextZ;
  13822. if (p.nextZ)p.nextZ.prevZ=p.prevZ;
  13823. }
  13824. Earcut.signedArea=function(data,start,end,dim){
  13825. var sum=0;
  13826. for (var i=start,j=end-dim;i < end;i+=dim){
  13827. sum+=(data[j]-data[i])*(data[i+1]+data[j+1]);
  13828. j=i;
  13829. }
  13830. return sum;
  13831. }
  13832. return Earcut;
  13833. })()
  13834. //class laya.webgl.utils.ShaderNode
  13835. var ShaderNode=(function(){
  13836. function ShaderNode(includefiles){
  13837. this.childs=[];
  13838. this.text="";
  13839. this.parent=null;
  13840. this.name=null;
  13841. this.noCompile=false;
  13842. this.includefiles=null;
  13843. this.condition=null;
  13844. this.conditionType=0;
  13845. this.useFuns="";
  13846. this.z=0;
  13847. this.src=null;
  13848. this.includefiles=includefiles;
  13849. }
  13850. __class(ShaderNode,'laya.webgl.utils.ShaderNode');
  13851. var __proto=ShaderNode.prototype;
  13852. __proto.setParent=function(parent){
  13853. parent.childs.push(this);
  13854. this.z=parent.z+1;
  13855. this.parent=parent;
  13856. }
  13857. __proto.setCondition=function(condition,type){
  13858. if (condition){
  13859. this.conditionType=type;
  13860. condition=condition.replace(/(\s*$)/g,"");
  13861. this.condition=function (){
  13862. return this[condition];
  13863. }
  13864. this.condition.__condition=condition;
  13865. }
  13866. }
  13867. __proto.toscript=function(def,out){
  13868. return this._toscript(def,out,++ShaderNode.__id);
  13869. }
  13870. __proto._toscript=function(def,out,id){
  13871. if (this.childs.length < 1 && !this.text)return out;
  13872. var outIndex=out.length;
  13873. if (this.condition){
  13874. var ifdef=!!this.condition.call(def);
  13875. this.conditionType===/*laya.webgl.utils.ShaderCompile.IFDEF_ELSE*/2 && (ifdef=!ifdef);
  13876. if (!ifdef)return out;
  13877. }
  13878. this.text && out.push(this.text);
  13879. this.childs.length > 0 && this.childs.forEach(function(o,index,arr){
  13880. o._toscript(def,out,id);
  13881. });
  13882. if (this.includefiles.length > 0 && this.useFuns.length > 0){
  13883. var funsCode;
  13884. for (var i=0,n=this.includefiles.length;i < n;i++){
  13885. if (this.includefiles[i].curUseID==id){
  13886. continue ;
  13887. }
  13888. funsCode=this.includefiles[i].file.getFunsScript(this.useFuns);
  13889. if (funsCode.length > 0){
  13890. this.includefiles[i].curUseID=id;
  13891. out[0]=funsCode+out[0];
  13892. }
  13893. }
  13894. }
  13895. return out;
  13896. }
  13897. ShaderNode.__id=1;
  13898. return ShaderNode;
  13899. })()
  13900. /**
  13901. *位移命令
  13902. */
  13903. //class laya.display.cmd.TranslateCmd
  13904. var TranslateCmd=(function(){
  13905. function TranslateCmd(){
  13906. /**
  13907. *添加到水平坐标(x)上的值。
  13908. */
  13909. //this.tx=NaN;
  13910. /**
  13911. *添加到垂直坐标(y)上的值。
  13912. */
  13913. //this.ty=NaN;
  13914. }
  13915. __class(TranslateCmd,'laya.display.cmd.TranslateCmd');
  13916. var __proto=TranslateCmd.prototype;
  13917. /**
  13918. *回收到对象池
  13919. */
  13920. __proto.recover=function(){
  13921. Pool.recover("TranslateCmd",this);
  13922. }
  13923. /**@private */
  13924. __proto.run=function(context,gx,gy){
  13925. context.translate(this.tx,this.ty);
  13926. }
  13927. /**@private */
  13928. __getset(0,__proto,'cmdID',function(){
  13929. return "Translate";
  13930. });
  13931. TranslateCmd.create=function(tx,ty){
  13932. var cmd=Pool.getItemByClass("TranslateCmd",TranslateCmd);
  13933. cmd.tx=tx;
  13934. cmd.ty=ty;
  13935. return cmd;
  13936. }
  13937. TranslateCmd.ID="Translate";
  13938. return TranslateCmd;
  13939. })()
  13940. /**
  13941. *<code>Point</code> 对象表示二维坐标系统中的某个位置,其中 x 表示水平轴,y 表示垂直轴。
  13942. */
  13943. //class laya.maths.Point
  13944. var Point=(function(){
  13945. function Point(x,y){
  13946. /**该点的水平坐标。*/
  13947. //this.x=NaN;
  13948. /**该点的垂直坐标。*/
  13949. //this.y=NaN;
  13950. (x===void 0)&& (x=0);
  13951. (y===void 0)&& (y=0);
  13952. this.x=x;
  13953. this.y=y;
  13954. }
  13955. __class(Point,'laya.maths.Point');
  13956. var __proto=Point.prototype;
  13957. /**
  13958. *将 <code>Point</code> 的成员设置为指定值。
  13959. *@param x 水平坐标。
  13960. *@param y 垂直坐标。
  13961. *@return 当前 Point 对象。
  13962. */
  13963. __proto.setTo=function(x,y){
  13964. this.x=x;
  13965. this.y=y;
  13966. return this;
  13967. }
  13968. /**
  13969. *重置
  13970. */
  13971. __proto.reset=function(){
  13972. this.x=this.y=0;
  13973. return this;
  13974. }
  13975. /**
  13976. *回收到对象池,方便复用
  13977. */
  13978. __proto.recover=function(){
  13979. Pool.recover("Point",this.reset());
  13980. }
  13981. /**
  13982. *计算当前点和目标点(x,y)的距离。
  13983. *@param x 水平坐标。
  13984. *@param y 垂直坐标。
  13985. *@return 返回当前点和目标点之间的距离。
  13986. */
  13987. __proto.distance=function(x,y){
  13988. return Math.sqrt((this.x-x)*(this.x-x)+(this.y-y)*(this.y-y));
  13989. }
  13990. /**返回包含 x 和 y 坐标的值的字符串。*/
  13991. __proto.toString=function(){
  13992. return this.x+","+this.y;
  13993. }
  13994. /**
  13995. *标准化向量。
  13996. */
  13997. __proto.normalize=function(){
  13998. var d=Math.sqrt(this.x *this.x+this.y *this.y);
  13999. if (d > 0){
  14000. var id=1.0 / d;
  14001. this.x *=id;
  14002. this.y *=id;
  14003. }
  14004. }
  14005. /**
  14006. *copy point坐标
  14007. *@param point 需要被copy的point
  14008. */
  14009. __proto.copy=function(point){
  14010. return this.setTo(point.x,point.y);
  14011. }
  14012. Point.create=function(){
  14013. return Pool.getItemByClass("Point",Point);
  14014. }
  14015. Point.TEMP=new Point();
  14016. Point.EMPTY=new Point();
  14017. return Point;
  14018. })()
  14019. /**
  14020. *@private
  14021. *静态常量集合
  14022. */
  14023. //class laya.Const
  14024. var Const=(function(){
  14025. function Const(){}
  14026. __class(Const,'laya.Const');
  14027. Const.NOT_ACTIVE=0x01;
  14028. Const.ACTIVE_INHIERARCHY=0x02;
  14029. Const.AWAKED=0x04;
  14030. Const.NOT_READY=0x08;
  14031. Const.DISPLAY=0x10;
  14032. Const.HAS_ZORDER=0x20;
  14033. Const.HAS_MOUSE=0x40;
  14034. Const.DISPLAYED_INSTAGE=0x80;
  14035. Const.DRAWCALL_OPTIMIZE=0x100;
  14036. return Const;
  14037. })()
  14038. //class laya.webgl.shapes.BasePoly
  14039. var BasePoly=(function(){
  14040. function BasePoly(){}
  14041. __class(BasePoly,'laya.webgl.shapes.BasePoly');
  14042. BasePoly.createLine2=function(p,indices,lineWidth,indexBase,outVertex,loop){
  14043. if (p.length < 4)return null;
  14044. var points=BasePoly.tempData.length>(p.length+2)?BasePoly.tempData:new Array(p.length+2);
  14045. points[0]=p[0];points[1]=p[1];
  14046. var newlen=2;
  14047. var i=0;
  14048. var length=p.length;
  14049. for (i=2;i < length;i+=2){
  14050. if (Math.abs(p[i]-p[i-2])+Math.abs(p[i+1]-p[i-1])> 0.01){
  14051. points[newlen++]=p[i];points[newlen++]=p[i+1];
  14052. }
  14053. }
  14054. if (loop && Math.abs(p[0]-points[newlen-2])+Math.abs(p[1]-points[newlen-1])> 0.01){
  14055. points[newlen++]=p[0];points[newlen++]=p[1];
  14056. };
  14057. var result=outVertex;
  14058. length=newlen / 2;
  14059. var w=lineWidth / 2;
  14060. var px,py,p1x,p1y,p2x,p2y,p3x,p3y;
  14061. var perpx,perpy,perp2x,perp2y,perp3x,perp3y;
  14062. var a1,b1,c1,a2,b2,c2;
  14063. var denom,pdist,dist;
  14064. p1x=points[0];
  14065. p1y=points[1];
  14066. p2x=points[2];
  14067. p2y=points[3];
  14068. perpx=-(p1y-p2y);
  14069. perpy=p1x-p2x;
  14070. dist=Math.sqrt(perpx *perpx+perpy *perpy);
  14071. perpx=perpx / dist *w;
  14072. perpy=perpy / dist *w;
  14073. var tpx=perpx,tpy=perpy;
  14074. result.push(p1x-perpx ,p1y-perpy ,p1x+perpx ,p1y+perpy);
  14075. for (i=1;i < length-1;i++){
  14076. p1x=points[(i-1)*2];
  14077. p1y=points[(i-1)*2+1];
  14078. p2x=points[(i)*2];
  14079. p2y=points[(i)*2+1];
  14080. p3x=points[(i+1)*2];
  14081. p3y=points[(i+1)*2+1];
  14082. perpx=-(p1y-p2y);
  14083. perpy=p1x-p2x;
  14084. dist=Math.sqrt(perpx *perpx+perpy *perpy);
  14085. perpx=perpx / dist *w;
  14086. perpy=perpy / dist *w;
  14087. perp2x=-(p2y-p3y);
  14088. perp2y=p2x-p3x;
  14089. dist=Math.sqrt(perp2x *perp2x+perp2y *perp2y);
  14090. perp2x=perp2x / dist *w;
  14091. perp2y=perp2y / dist *w;
  14092. a1=(-perpy+p1y)-(-perpy+p2y);
  14093. b1=(-perpx+p2x)-(-perpx+p1x);
  14094. c1=(-perpx+p1x)*(-perpy+p2y)-(-perpx+p2x)*(-perpy+p1y);
  14095. a2=(-perp2y+p3y)-(-perp2y+p2y);
  14096. b2=(-perp2x+p2x)-(-perp2x+p3x);
  14097. c2=(-perp2x+p3x)*(-perp2y+p2y)-(-perp2x+p2x)*(-perp2y+p3y);
  14098. denom=a1 *b2-a2 *b1;
  14099. if (Math.abs(denom)< 0.1){
  14100. denom+=10.1;
  14101. result.push(p2x-perpx ,p2y-perpy ,p2x+perpx ,p2y+perpy);
  14102. continue ;
  14103. }
  14104. px=(b1 *c2-b2 *c1)/ denom;
  14105. py=(a2 *c1-a1 *c2)/ denom;
  14106. pdist=(px-p2x)*(px-p2x)+(py-p2y)+(py-p2y);
  14107. result.push(px,py ,p2x-(px-p2x),p2y-(py-p2y));
  14108. }
  14109. p1x=points[newlen-4];
  14110. p1y=points[newlen-3];
  14111. p2x=points[newlen-2];
  14112. p2y=points[newlen-1];
  14113. perpx=-(p1y-p2y);
  14114. perpy=p1x-p2x;
  14115. dist=Math.sqrt(perpx *perpx+perpy *perpy);
  14116. perpx=perpx / dist *w;
  14117. perpy=perpy / dist *w;
  14118. result.push(p2x-perpx ,p2y-perpy ,p2x+perpx ,p2y+perpy);
  14119. for (i=1;i < length;i++){
  14120. 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);
  14121. }
  14122. return result;
  14123. }
  14124. BasePoly.createLineTriangle=function(path,color,width,loop,outvb,vbstride,outib){
  14125. var points=path.slice();
  14126. var ptlen=points.length;
  14127. var p1x=points[0],p1y=points[1];
  14128. var p2x=points[2],p2y=points[2];
  14129. var len=0;
  14130. var rp=0;
  14131. var dx=0,dy=0;
  14132. var pointnum=ptlen / 2;
  14133. if (pointnum <=1)return;
  14134. if (pointnum==2){
  14135. return;
  14136. };
  14137. var tmpData=new Array(pointnum *4);
  14138. var realPtNum=0;
  14139. var ci=0;
  14140. for (var i=0;i < pointnum-1;i++){
  14141. p1x=points[ci++],p1y=points[ci++];
  14142. p2x=points[ci++],p2y=points[ci++];
  14143. dx=p2x-p1x,dy=p2y-p1y;
  14144. if(dx!=0 && dy!=0){
  14145. len=Math.sqrt(dx *dx+dy *dy);
  14146. if (len > 1e-3){
  14147. rp=realPtNum *4;
  14148. tmpData[rp]=p1x;
  14149. tmpData[rp+1]=p1y;
  14150. tmpData[rp+2]=dx / len;
  14151. tmpData[rp+3]=dy / len;
  14152. realPtNum++;
  14153. }
  14154. }
  14155. }
  14156. if (loop){
  14157. p1x=points[ptlen-2],p1y=points[ptlen-1];
  14158. p2x=points[0],p2y=points[1];
  14159. dx=p2x-p1x,dy=p2y-p1y;
  14160. if(dx!=0 && dy!=0){
  14161. len=Math.sqrt(dx *dx+dy *dy);
  14162. if (len > 1e-3){
  14163. rp=realPtNum *4;
  14164. tmpData[rp]=p1x;
  14165. tmpData[rp+1]=p1y;
  14166. tmpData[rp+2]=dx / len;
  14167. tmpData[rp+3]=dy / len;
  14168. realPtNum++;
  14169. }
  14170. }
  14171. }else {
  14172. rp=realPtNum *4;
  14173. tmpData[rp]=p1x;
  14174. tmpData[rp+1]=p1y;
  14175. tmpData[rp+2]=dx / len;
  14176. tmpData[rp+3]=dy / len;
  14177. realPtNum++;
  14178. }
  14179. ci=0;
  14180. for (i=0;i < pointnum;i++){
  14181. p1x=points[ci],p1y=points[ci+1];
  14182. p2x=points[ci+2],p2y=points[ci+3];
  14183. var p3x=points[ci+4],p3y=points[ci+5];
  14184. }
  14185. if (loop){}
  14186. }
  14187. __static(BasePoly,
  14188. ['tempData',function(){return this.tempData=new Array(256);}
  14189. ]);
  14190. return BasePoly;
  14191. })()
  14192. /**
  14193. *缩放命令
  14194. */
  14195. //class laya.display.cmd.ScaleCmd
  14196. var ScaleCmd=(function(){
  14197. function ScaleCmd(){
  14198. /**
  14199. *水平方向缩放值。
  14200. */
  14201. //this.scaleX=NaN;
  14202. /**
  14203. *垂直方向缩放值。
  14204. */
  14205. //this.scaleY=NaN;
  14206. /**
  14207. *(可选)水平方向轴心点坐标。
  14208. */
  14209. //this.pivotX=NaN;
  14210. /**
  14211. *(可选)垂直方向轴心点坐标。
  14212. */
  14213. //this.pivotY=NaN;
  14214. }
  14215. __class(ScaleCmd,'laya.display.cmd.ScaleCmd');
  14216. var __proto=ScaleCmd.prototype;
  14217. /**
  14218. *回收到对象池
  14219. */
  14220. __proto.recover=function(){
  14221. Pool.recover("ScaleCmd",this);
  14222. }
  14223. /**@private */
  14224. __proto.run=function(context,gx,gy){
  14225. context._scale(this.scaleX,this.scaleY,this.pivotX+gx,this.pivotY+gy);
  14226. }
  14227. /**@private */
  14228. __getset(0,__proto,'cmdID',function(){
  14229. return "Scale";
  14230. });
  14231. ScaleCmd.create=function(scaleX,scaleY,pivotX,pivotY){
  14232. var cmd=Pool.getItemByClass("ScaleCmd",ScaleCmd);
  14233. cmd.scaleX=scaleX;
  14234. cmd.scaleY=scaleY;
  14235. cmd.pivotX=pivotX;
  14236. cmd.pivotY=pivotY;
  14237. return cmd;
  14238. }
  14239. ScaleCmd.ID="Scale";
  14240. return ScaleCmd;
  14241. })()
  14242. /**
  14243. *透明命令
  14244. */
  14245. //class laya.display.cmd.AlphaCmd
  14246. var AlphaCmd=(function(){
  14247. function AlphaCmd(){
  14248. /**
  14249. *透明度
  14250. */
  14251. //this.alpha=NaN;
  14252. }
  14253. __class(AlphaCmd,'laya.display.cmd.AlphaCmd');
  14254. var __proto=AlphaCmd.prototype;
  14255. /**
  14256. *回收到对象池
  14257. */
  14258. __proto.recover=function(){
  14259. Pool.recover("AlphaCmd",this);
  14260. }
  14261. /**@private */
  14262. __proto.run=function(context,gx,gy){
  14263. context.alpha(this.alpha);
  14264. }
  14265. /**@private */
  14266. __getset(0,__proto,'cmdID',function(){
  14267. return "Alpha";
  14268. });
  14269. AlphaCmd.create=function(alpha){
  14270. var cmd=Pool.getItemByClass("AlphaCmd",AlphaCmd);
  14271. cmd.alpha=alpha;
  14272. return cmd;
  14273. }
  14274. AlphaCmd.ID="Alpha";
  14275. return AlphaCmd;
  14276. })()
  14277. /**
  14278. *<p> <code>Byte</code> 类提供用于优化读取、写入以及处理二进制数据的方法和属性。</p>
  14279. *<p> <code>Byte</code> 类适用于需要在字节层访问数据的高级开发人员。</p>
  14280. */
  14281. //class laya.utils.Byte
  14282. var Byte=(function(){
  14283. function Byte(data){
  14284. /**@private 是否为小端数据。*/
  14285. this._xd_=true;
  14286. /**@private */
  14287. this._allocated_=8;
  14288. /**@private 原始数据。*/
  14289. //this._d_=null;
  14290. /**@private DataView*/
  14291. //this._u8d_=null;
  14292. /**@private */
  14293. this._pos_=0;
  14294. /**@private */
  14295. this._length=0;
  14296. if (data){
  14297. this._u8d_=new Uint8Array(data);
  14298. this._d_=new DataView(this._u8d_.buffer);
  14299. this._length=this._d_.byteLength;
  14300. }else {
  14301. this._resizeBuffer(this._allocated_);
  14302. }
  14303. }
  14304. __class(Byte,'laya.utils.Byte');
  14305. var __proto=Byte.prototype;
  14306. /**@private */
  14307. __proto._resizeBuffer=function(len){
  14308. try {
  14309. var newByteView=new Uint8Array(len);
  14310. if (this._u8d_ !=null){
  14311. if (this._u8d_.length <=len)newByteView.set(this._u8d_);
  14312. else newByteView.set(this._u8d_.subarray(0,len));
  14313. }
  14314. this._u8d_=newByteView;
  14315. this._d_=new DataView(newByteView.buffer);
  14316. }catch (err){
  14317. throw "Invalid typed array length:"+len;
  14318. }
  14319. }
  14320. /**
  14321. *@private
  14322. *<p>常用于解析固定格式的字节流。</p>
  14323. *<p>先从字节流的当前字节偏移位置处读取一个 <code>Uint16</code> 值,然后以此值为长度,读取此长度的字符串。</p>
  14324. *@return 读取的字符串。
  14325. */
  14326. __proto.getString=function(){
  14327. return this.readString();
  14328. }
  14329. /**
  14330. *<p>常用于解析固定格式的字节流。</p>
  14331. *<p>先从字节流的当前字节偏移位置处读取一个 <code>Uint16</code> 值,然后以此值为长度,读取此长度的字符串。</p>
  14332. *@return 读取的字符串。
  14333. */
  14334. __proto.readString=function(){
  14335. return this._rUTF(this.getUint16());
  14336. }
  14337. /**
  14338. *@private
  14339. *<p>从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Float32Array</code> 对象并返回此对象。</p>
  14340. *<p><b>注意:</b>返回的 Float32Array 对象,在 JavaScript 环境下,是原生的 HTML5 Float32Array 对象,对此对象的读取操作都是基于运行此程序的当前主机字节序,此顺序可能与实际数据的字节序不同,如果使用此对象进行读取,需要用户知晓实际数据的字节序和当前主机字节序,如果相同,可正常读取,否则需要用户对实际数据(Float32Array.buffer)包装一层 DataView ,使用 DataView 对象可按照指定的字节序进行读取。</p>
  14341. *@param start 开始位置。
  14342. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  14343. *@return 读取的 Float32Array 对象。
  14344. */
  14345. __proto.getFloat32Array=function(start,len){
  14346. return this.readFloat32Array(start,len);
  14347. }
  14348. /**
  14349. *从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Float32Array</code> 对象并返回此对象。
  14350. *@param start 开始位置。
  14351. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  14352. *@return 读取的 Float32Array 对象。
  14353. */
  14354. __proto.readFloat32Array=function(start,len){
  14355. var end=start+len;
  14356. end=(end > this._length)? this._length :end;
  14357. var v=new Float32Array(this._d_.buffer.slice(start,end));
  14358. this._pos_=end;
  14359. return v;
  14360. }
  14361. /**
  14362. *@private
  14363. *从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Uint8Array</code> 对象并返回此对象。
  14364. *@param start 开始位置。
  14365. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  14366. *@return 读取的 Uint8Array 对象。
  14367. */
  14368. __proto.getUint8Array=function(start,len){
  14369. return this.readUint8Array(start,len);
  14370. }
  14371. /**
  14372. *从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Uint8Array</code> 对象并返回此对象。
  14373. *@param start 开始位置。
  14374. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  14375. *@return 读取的 Uint8Array 对象。
  14376. */
  14377. __proto.readUint8Array=function(start,len){
  14378. var end=start+len;
  14379. end=(end > this._length)? this._length :end;
  14380. var v=new Uint8Array(this._d_.buffer.slice(start,end));
  14381. this._pos_=end;
  14382. return v;
  14383. }
  14384. /**
  14385. *@private
  14386. *<p>从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Int16Array</code> 对象并返回此对象。</p>
  14387. *<p><b>注意:</b>返回的 Int16Array 对象,在 JavaScript 环境下,是原生的 HTML5 Int16Array 对象,对此对象的读取操作都是基于运行此程序的当前主机字节序,此顺序可能与实际数据的字节序不同,如果使用此对象进行读取,需要用户知晓实际数据的字节序和当前主机字节序,如果相同,可正常读取,否则需要用户对实际数据(Int16Array.buffer)包装一层 DataView ,使用 DataView 对象可按照指定的字节序进行读取。</p>
  14388. *@param start 开始读取的字节偏移量位置。
  14389. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  14390. *@return 读取的 Int16Array 对象。
  14391. */
  14392. __proto.getInt16Array=function(start,len){
  14393. return this.readInt16Array(start,len);
  14394. }
  14395. /**
  14396. *从字节流中 <code>start</code> 参数指定的位置开始,读取 <code>len</code> 参数指定的字节数的数据,用于创建一个 <code>Int16Array</code> 对象并返回此对象。
  14397. *@param start 开始读取的字节偏移量位置。
  14398. *@param len 需要读取的字节长度。如果要读取的长度超过可读取范围,则只返回可读范围内的值。
  14399. *@return 读取的 Uint8Array 对象。
  14400. */
  14401. __proto.readInt16Array=function(start,len){
  14402. var end=start+len;
  14403. end=(end > this._length)? this._length :end;
  14404. var v=new Int16Array(this._d_.buffer.slice(start,end));
  14405. this._pos_=end;
  14406. return v;
  14407. }
  14408. /**
  14409. *@private
  14410. *从字节流的当前字节偏移位置处读取一个 IEEE 754 单精度(32 位)浮点数。
  14411. *@return 单精度(32 位)浮点数。
  14412. */
  14413. __proto.getFloat32=function(){
  14414. return this.readFloat32();
  14415. }
  14416. /**
  14417. *从字节流的当前字节偏移位置处读取一个 IEEE 754 单精度(32 位)浮点数。
  14418. *@return 单精度(32 位)浮点数。
  14419. */
  14420. __proto.readFloat32=function(){
  14421. if (this._pos_+4 > this._length)throw "getFloat32 error - Out of bounds";
  14422. var v=this._d_.getFloat32(this._pos_,this._xd_);
  14423. this._pos_+=4;
  14424. return v;
  14425. }
  14426. /**
  14427. *@private
  14428. *从字节流的当前字节偏移量位置处读取一个 IEEE 754 双精度(64 位)浮点数。
  14429. *@return 双精度(64 位)浮点数。
  14430. */
  14431. __proto.getFloat64=function(){
  14432. return this.readFloat64();
  14433. }
  14434. /**
  14435. *从字节流的当前字节偏移量位置处读取一个 IEEE 754 双精度(64 位)浮点数。
  14436. *@return 双精度(64 位)浮点数。
  14437. */
  14438. __proto.readFloat64=function(){
  14439. if (this._pos_+8 > this._length)throw "getFloat64 error - Out of bounds";
  14440. var v=this._d_.getFloat64(this._pos_,this._xd_);
  14441. this._pos_+=8;
  14442. return v;
  14443. }
  14444. /**
  14445. *在字节流的当前字节偏移量位置处写入一个 IEEE 754 单精度(32 位)浮点数。
  14446. *@param value 单精度(32 位)浮点数。
  14447. */
  14448. __proto.writeFloat32=function(value){
  14449. this._ensureWrite(this._pos_+4);
  14450. this._d_.setFloat32(this._pos_,value,this._xd_);
  14451. this._pos_+=4;
  14452. }
  14453. /**
  14454. *在字节流的当前字节偏移量位置处写入一个 IEEE 754 双精度(64 位)浮点数。
  14455. *@param value 双精度(64 位)浮点数。
  14456. */
  14457. __proto.writeFloat64=function(value){
  14458. this._ensureWrite(this._pos_+8);
  14459. this._d_.setFloat64(this._pos_,value,this._xd_);
  14460. this._pos_+=8;
  14461. }
  14462. /**
  14463. *@private
  14464. *从字节流的当前字节偏移量位置处读取一个 Int32 值。
  14465. *@return Int32 值。
  14466. */
  14467. __proto.getInt32=function(){
  14468. return this.readInt32();
  14469. }
  14470. /**
  14471. *从字节流的当前字节偏移量位置处读取一个 Int32 值。
  14472. *@return Int32 值。
  14473. */
  14474. __proto.readInt32=function(){
  14475. if (this._pos_+4 > this._length)throw "getInt32 error - Out of bounds";
  14476. var float=this._d_.getInt32(this._pos_,this._xd_);
  14477. this._pos_+=4;
  14478. return float;
  14479. }
  14480. /**
  14481. *@private
  14482. *从字节流的当前字节偏移量位置处读取一个 Uint32 值。
  14483. *@return Uint32 值。
  14484. */
  14485. __proto.getUint32=function(){
  14486. return this.readUint32();
  14487. }
  14488. /**
  14489. *从字节流的当前字节偏移量位置处读取一个 Uint32 值。
  14490. *@return Uint32 值。
  14491. */
  14492. __proto.readUint32=function(){
  14493. if (this._pos_+4 > this._length)throw "getUint32 error - Out of bounds";
  14494. var v=this._d_.getUint32(this._pos_,this._xd_);
  14495. this._pos_+=4;
  14496. return v;
  14497. }
  14498. /**
  14499. *在字节流的当前字节偏移量位置处写入指定的 Int32 值。
  14500. *@param value 需要写入的 Int32 值。
  14501. */
  14502. __proto.writeInt32=function(value){
  14503. this._ensureWrite(this._pos_+4);
  14504. this._d_.setInt32(this._pos_,value,this._xd_);
  14505. this._pos_+=4;
  14506. }
  14507. /**
  14508. *在字节流的当前字节偏移量位置处写入 Uint32 值。
  14509. *@param value 需要写入的 Uint32 值。
  14510. */
  14511. __proto.writeUint32=function(value){
  14512. this._ensureWrite(this._pos_+4);
  14513. this._d_.setUint32(this._pos_,value,this._xd_);
  14514. this._pos_+=4;
  14515. }
  14516. /**
  14517. *@private
  14518. *从字节流的当前字节偏移量位置处读取一个 Int16 值。
  14519. *@return Int16 值。
  14520. */
  14521. __proto.getInt16=function(){
  14522. return this.readInt16();
  14523. }
  14524. /**
  14525. *从字节流的当前字节偏移量位置处读取一个 Int16 值。
  14526. *@return Int16 值。
  14527. */
  14528. __proto.readInt16=function(){
  14529. if (this._pos_+2 > this._length)throw "getInt16 error - Out of bounds";
  14530. var us=this._d_.getInt16(this._pos_,this._xd_);
  14531. this._pos_+=2;
  14532. return us;
  14533. }
  14534. /**
  14535. *@private
  14536. *从字节流的当前字节偏移量位置处读取一个 Uint16 值。
  14537. *@return Uint16 值。
  14538. */
  14539. __proto.getUint16=function(){
  14540. return this.readUint16();
  14541. }
  14542. /**
  14543. *从字节流的当前字节偏移量位置处读取一个 Uint16 值。
  14544. *@return Uint16 值。
  14545. */
  14546. __proto.readUint16=function(){
  14547. if (this._pos_+2 > this._length)throw "getUint16 error - Out of bounds";
  14548. var us=this._d_.getUint16(this._pos_,this._xd_);
  14549. this._pos_+=2;
  14550. return us;
  14551. }
  14552. /**
  14553. *在字节流的当前字节偏移量位置处写入指定的 Uint16 值。
  14554. *@param value 需要写入的Uint16 值。
  14555. */
  14556. __proto.writeUint16=function(value){
  14557. this._ensureWrite(this._pos_+2);
  14558. this._d_.setUint16(this._pos_,value,this._xd_);
  14559. this._pos_+=2;
  14560. }
  14561. /**
  14562. *在字节流的当前字节偏移量位置处写入指定的 Int16 值。
  14563. *@param value 需要写入的 Int16 值。
  14564. */
  14565. __proto.writeInt16=function(value){
  14566. this._ensureWrite(this._pos_+2);
  14567. this._d_.setInt16(this._pos_,value,this._xd_);
  14568. this._pos_+=2;
  14569. }
  14570. /**
  14571. *@private
  14572. *从字节流的当前字节偏移量位置处读取一个 Uint8 值。
  14573. *@return Uint8 值。
  14574. */
  14575. __proto.getUint8=function(){
  14576. return this.readUint8();
  14577. }
  14578. /**
  14579. *从字节流的当前字节偏移量位置处读取一个 Uint8 值。
  14580. *@return Uint8 值。
  14581. */
  14582. __proto.readUint8=function(){
  14583. if (this._pos_+1 > this._length)throw "getUint8 error - Out of bounds";
  14584. return this._u8d_[this._pos_++];
  14585. }
  14586. /**
  14587. *在字节流的当前字节偏移量位置处写入指定的 Uint8 值。
  14588. *@param value 需要写入的 Uint8 值。
  14589. */
  14590. __proto.writeUint8=function(value){
  14591. this._ensureWrite(this._pos_+1);
  14592. this._d_.setUint8(this._pos_,value);
  14593. this._pos_++;
  14594. }
  14595. //TODO:coverage
  14596. __proto._getUInt8=function(pos){
  14597. return this._readUInt8(pos);
  14598. }
  14599. //TODO:coverage
  14600. __proto._readUInt8=function(pos){
  14601. return this._d_.getUint8(pos);
  14602. }
  14603. //TODO:coverage
  14604. __proto._getUint16=function(pos){
  14605. return this._readUint16(pos);
  14606. }
  14607. //TODO:coverage
  14608. __proto._readUint16=function(pos){
  14609. return this._d_.getUint16(pos,this._xd_);
  14610. }
  14611. //TODO:coverage
  14612. __proto._getMatrix=function(){
  14613. return this._readMatrix();
  14614. }
  14615. //TODO:coverage
  14616. __proto._readMatrix=function(){
  14617. var rst=new Matrix(this.getFloat32(),this.getFloat32(),this.getFloat32(),this.getFloat32(),this.getFloat32(),this.getFloat32());
  14618. return rst;
  14619. }
  14620. /**
  14621. *@private
  14622. *读取指定长度的 UTF 型字符串。
  14623. *@param len 需要读取的长度。
  14624. *@return 读取的字符串。
  14625. */
  14626. __proto._rUTF=function(len){
  14627. var v="",max=this._pos_+len,c=0,c2=0,c3=0,f=String.fromCharCode;
  14628. var u=this._u8d_,i=0;
  14629. var strs=[];
  14630. var n=0;
  14631. strs.length=1000;
  14632. while (this._pos_ < max){
  14633. c=u[this._pos_++];
  14634. if (c < 0x80){
  14635. if (c !=0)
  14636. strs[n++]=f(c);
  14637. }else if (c < 0xE0){
  14638. strs[n++]=f(((c & 0x3F)<< 6)| (u[this._pos_++] & 0x7F));
  14639. }else if (c < 0xF0){
  14640. c2=u[this._pos_++];
  14641. strs[n++]=f(((c & 0x1F)<< 12)| ((c2 & 0x7F)<< 6)| (u[this._pos_++] & 0x7F));
  14642. }else {
  14643. c2=u[this._pos_++];
  14644. c3=u[this._pos_++];
  14645. strs[n++]=f(((c & 0x0F)<< 18)| ((c2 & 0x7F)<< 12)| ((c3 << 6)& 0x7F)| (u[this._pos_++] & 0x7F));
  14646. }
  14647. i++;
  14648. }
  14649. strs.length=n;
  14650. return strs.join('');
  14651. }
  14652. //TODO:coverage
  14653. __proto.getCustomString=function(len){
  14654. return this.readCustomString(len);
  14655. }
  14656. //TODO:coverage
  14657. __proto.readCustomString=function(len){
  14658. var v="",ulen=0,c=0,c2=0,f=String.fromCharCode;
  14659. var u=this._u8d_,i=0;
  14660. while (len > 0){
  14661. c=u[this._pos_];
  14662. if (c < 0x80){
  14663. v+=f(c);
  14664. this._pos_++;
  14665. len--;
  14666. }else {
  14667. ulen=c-0x80;
  14668. this._pos_++;
  14669. len-=ulen;
  14670. while (ulen > 0){
  14671. c=u[this._pos_++];
  14672. c2=u[this._pos_++];
  14673. v+=f((c2 << 8)| c);
  14674. ulen--;
  14675. }
  14676. }
  14677. }
  14678. return v;
  14679. }
  14680. /**
  14681. *清除字节数组的内容,并将 length 和 pos 属性重置为 0。调用此方法将释放 Byte 实例占用的内存。
  14682. */
  14683. __proto.clear=function(){
  14684. this._pos_=0;
  14685. this.length=0;
  14686. }
  14687. /**
  14688. *@private
  14689. *获取此对象的 ArrayBuffer 引用。
  14690. *@return
  14691. */
  14692. __proto.__getBuffer=function(){
  14693. return this._d_.buffer;
  14694. }
  14695. /**
  14696. *<p>将 UTF-8 字符串写入字节流。类似于 writeUTF()方法,但 writeUTFBytes()不使用 16 位长度的字为字符串添加前缀。</p>
  14697. *<p>对应的读取方法为: getUTFBytes 。</p>
  14698. *@param value 要写入的字符串。
  14699. */
  14700. __proto.writeUTFBytes=function(value){
  14701. value=value+"";
  14702. for (var i=0,sz=value.length;i < sz;i++){
  14703. var c=value.charCodeAt(i);
  14704. if (c <=0x7F){
  14705. this.writeByte(c);
  14706. }else if (c <=0x7FF){
  14707. this._ensureWrite(this._pos_+2);
  14708. this._u8d_.set([0xC0 | (c >> 6),0x80 | (c & 0x3F)],this._pos_);
  14709. this._pos_+=2;
  14710. }else if (c <=0xFFFF){
  14711. this._ensureWrite(this._pos_+3);
  14712. this._u8d_.set([0xE0 | (c >> 12),0x80 | ((c >> 6)& 0x3F),0x80 | (c & 0x3F)],this._pos_);
  14713. this._pos_+=3;
  14714. }else {
  14715. this._ensureWrite(this._pos_+4);
  14716. this._u8d_.set([0xF0 | (c >> 18),0x80 | ((c >> 12)& 0x3F),0x80 | ((c >> 6)& 0x3F),0x80 | (c & 0x3F)],this._pos_);
  14717. this._pos_+=4;
  14718. }
  14719. }
  14720. }
  14721. /**
  14722. *<p>将 UTF-8 字符串写入字节流。先写入以字节表示的 UTF-8 字符串长度(作为 16 位整数),然后写入表示字符串字符的字节。</p>
  14723. *<p>对应的读取方法为: getUTFString 。</p>
  14724. *@param value 要写入的字符串值。
  14725. */
  14726. __proto.writeUTFString=function(value){
  14727. var tPos=this.pos;
  14728. this.writeUint16(1);
  14729. this.writeUTFBytes(value);
  14730. var dPos=this.pos-tPos-2;
  14731. this._d_.setUint16(tPos,dPos,this._xd_);
  14732. }
  14733. /**
  14734. *@private
  14735. *读取 UTF-8 字符串。
  14736. *@return 读取的字符串。
  14737. */
  14738. __proto.readUTFString=function(){
  14739. return this.readUTFBytes(this.getUint16());
  14740. }
  14741. /**
  14742. *<p>从字节流中读取一个 UTF-8 字符串。假定字符串的前缀是一个无符号的短整型(以此字节表示要读取的长度)。</p>
  14743. *<p>对应的写入方法为: writeUTFString 。</p>
  14744. *@return 读取的字符串。
  14745. */
  14746. __proto.getUTFString=function(){
  14747. return this.readUTFString();
  14748. }
  14749. /**
  14750. *@private
  14751. *读字符串,必须是 writeUTFBytes 方法写入的字符串。
  14752. *@param len 要读的buffer长度,默认将读取缓冲区全部数据。
  14753. *@return 读取的字符串。
  14754. */
  14755. __proto.readUTFBytes=function(len){
  14756. (len===void 0)&& (len=-1);
  14757. if (len===0)return "";
  14758. var lastBytes=this.bytesAvailable;
  14759. if (len > lastBytes)throw "readUTFBytes error - Out of bounds";
  14760. len=len > 0 ? len :lastBytes;
  14761. return this._rUTF(len);
  14762. }
  14763. /**
  14764. *<p>从字节流中读取一个由 length 参数指定的长度的 UTF-8 字节序列,并返回一个字符串。</p>
  14765. *<p>一般读取的是由 writeUTFBytes 方法写入的字符串。</p>
  14766. *@param len 要读的buffer长度,默认将读取缓冲区全部数据。
  14767. *@return 读取的字符串。
  14768. */
  14769. __proto.getUTFBytes=function(len){
  14770. (len===void 0)&& (len=-1);
  14771. return this.readUTFBytes(len);
  14772. }
  14773. /**
  14774. *<p>在字节流中写入一个字节。</p>
  14775. *<p>使用参数的低 8 位。忽略高 24 位。</p>
  14776. *@param value
  14777. */
  14778. __proto.writeByte=function(value){
  14779. this._ensureWrite(this._pos_+1);
  14780. this._d_.setInt8(this._pos_,value);
  14781. this._pos_+=1;
  14782. }
  14783. /**
  14784. *<p>从字节流中读取带符号的字节。</p>
  14785. *<p>返回值的范围是从-128 到 127。</p>
  14786. *@return 介于-128 和 127 之间的整数。
  14787. */
  14788. __proto.readByte=function(){
  14789. if (this._pos_+1 > this._length)throw "readByte error - Out of bounds";
  14790. return this._d_.getInt8(this._pos_++);
  14791. }
  14792. /**
  14793. *@private
  14794. *从字节流中读取带符号的字节。
  14795. */
  14796. __proto.getByte=function(){
  14797. return this.readByte();
  14798. }
  14799. /**
  14800. *@private
  14801. *<p>保证该字节流的可用长度不小于 <code>lengthToEnsure</code> 参数指定的值。</p>
  14802. *@param lengthToEnsure 指定的长度。
  14803. */
  14804. __proto._ensureWrite=function(lengthToEnsure){
  14805. if (this._length < lengthToEnsure)this._length=lengthToEnsure;
  14806. if (this._allocated_ < lengthToEnsure)this.length=lengthToEnsure;
  14807. }
  14808. /**
  14809. *<p>将指定 arraybuffer 对象中的以 offset 为起始偏移量, length 为长度的字节序列写入字节流。</p>
  14810. *<p>如果省略 length 参数,则使用默认长度 0,该方法将从 offset 开始写入整个缓冲区;如果还省略了 offset 参数,则写入整个缓冲区。</p>
  14811. *<p>如果 offset 或 length 小于0,本函数将抛出异常。</p>
  14812. *@param arraybuffer 需要写入的 Arraybuffer 对象。
  14813. *@param offset Arraybuffer 对象的索引的偏移量(以字节为单位)
  14814. *@param length 从 Arraybuffer 对象写入到 Byte 对象的长度(以字节为单位)
  14815. */
  14816. __proto.writeArrayBuffer=function(arraybuffer,offset,length){
  14817. (offset===void 0)&& (offset=0);
  14818. (length===void 0)&& (length=0);
  14819. if (offset < 0 || length < 0)throw "writeArrayBuffer error - Out of bounds";
  14820. if (length==0)length=arraybuffer.byteLength-offset;
  14821. this._ensureWrite(this._pos_+length);
  14822. var uint8array=new Uint8Array(arraybuffer);
  14823. this._u8d_.set(uint8array.subarray(offset,offset+length),this._pos_);
  14824. this._pos_+=length;
  14825. }
  14826. /**
  14827. *读取ArrayBuffer数据
  14828. *@param length
  14829. *@return
  14830. */
  14831. __proto.readArrayBuffer=function(length){
  14832. var rst;
  14833. rst=this._u8d_.buffer.slice(this._pos_,this._pos_+length);
  14834. this._pos_=this._pos_+length
  14835. return rst;
  14836. }
  14837. /**
  14838. *获取此对象的 ArrayBuffer 数据,数据只包含有效数据部分。
  14839. */
  14840. __getset(0,__proto,'buffer',function(){
  14841. var rstBuffer=this._d_.buffer;
  14842. if (rstBuffer.byteLength===this._length)return rstBuffer;
  14843. return rstBuffer.slice(0,this._length);
  14844. });
  14845. /**
  14846. *<p> <code>Byte</code> 实例的字节序。取值为:<code>BIG_ENDIAN</code> 或 <code>BIG_ENDIAN</code> 。</p>
  14847. *<p>主机字节序,是 CPU 存放数据的两种不同顺序,包括小端字节序和大端字节序。通过 <code>getSystemEndian</code> 可以获取当前系统的字节序。</p>
  14848. *<p> <code>BIG_ENDIAN</code> :大端字节序,地址低位存储值的高位,地址高位存储值的低位。有时也称之为网络字节序。<br/>
  14849. *<code>LITTLE_ENDIAN</code> :小端字节序,地址低位存储值的低位,地址高位存储值的高位。</p>
  14850. */
  14851. __getset(0,__proto,'endian',function(){
  14852. return this._xd_ ? "littleEndian" :"bigEndian";
  14853. },function(value){
  14854. this._xd_=(value==="littleEndian");
  14855. });
  14856. /**
  14857. *<p> <code>Byte</code> 对象的长度(以字节为单位)。</p>
  14858. *<p>如果将长度设置为大于当前长度的值,则用零填充字节数组的右侧;如果将长度设置为小于当前长度的值,将会截断该字节数组。</p>
  14859. *<p>如果要设置的长度大于当前已分配的内存空间的字节长度,则重新分配内存空间,大小为以下两者较大者:要设置的长度、当前已分配的长度的2倍,并将原有数据拷贝到新的内存空间中;如果要设置的长度小于当前已分配的内存空间的字节长度,也会重新分配内存空间,大小为要设置的长度,并将原有数据从头截断为要设置的长度存入新的内存空间中。</p>
  14860. */
  14861. __getset(0,__proto,'length',function(){
  14862. return this._length;
  14863. },function(value){
  14864. if (this._allocated_ < value)this._resizeBuffer(this._allocated_=Math.floor(Math.max(value,this._allocated_ *2)));
  14865. else if (this._allocated_ > value)this._resizeBuffer(this._allocated_=value);
  14866. this._length=value;
  14867. });
  14868. /**
  14869. *移动或返回 Byte 对象的读写指针的当前位置(以字节为单位)。下一次调用读取方法时将在此位置开始读取,或者下一次调用写入方法时将在此位置开始写入。
  14870. */
  14871. __getset(0,__proto,'pos',function(){
  14872. return this._pos_;
  14873. },function(value){
  14874. this._pos_=value;
  14875. });
  14876. /**
  14877. *可从字节流的当前位置到末尾读取的数据的字节数。
  14878. */
  14879. __getset(0,__proto,'bytesAvailable',function(){
  14880. return this._length-this._pos_;
  14881. });
  14882. Byte.getSystemEndian=function(){
  14883. if (!Byte._sysEndian){
  14884. var buffer=new ArrayBuffer(2);
  14885. new DataView(buffer).setInt16(0,256,true);
  14886. Byte._sysEndian=(new Int16Array(buffer))[0]===256 ? /*CLASS CONST:laya.utils.Byte.LITTLE_ENDIAN*/"littleEndian" :/*CLASS CONST:laya.utils.Byte.BIG_ENDIAN*/"bigEndian";
  14887. }
  14888. return Byte._sysEndian;
  14889. }
  14890. Byte.BIG_ENDIAN="bigEndian";
  14891. Byte.LITTLE_ENDIAN="littleEndian";
  14892. Byte._sysEndian=null;
  14893. return Byte;
  14894. })()
  14895. /**
  14896. *@private
  14897. */
  14898. //class laya.utils.CallLater
  14899. var CallLater=(function(){
  14900. var LaterHandler;
  14901. function CallLater(){
  14902. /**@private */
  14903. this._pool=[];
  14904. /**@private */
  14905. this._map=[];
  14906. /**@private */
  14907. this._laters=[];
  14908. }
  14909. __class(CallLater,'laya.utils.CallLater');
  14910. var __proto=CallLater.prototype;
  14911. /**
  14912. *@private
  14913. *帧循环处理函数。
  14914. */
  14915. __proto._update=function(){
  14916. var laters=this._laters;
  14917. var len=laters.length;
  14918. if (len > 0){
  14919. for (var i=0,n=len-1;i <=n;i++){
  14920. var handler=laters[i];
  14921. this._map[handler.key]=null;
  14922. if (handler.method!==null){
  14923. handler.run();
  14924. handler.clear();
  14925. }
  14926. this._pool.push(handler);
  14927. i===n && (n=laters.length-1);
  14928. }
  14929. laters.length=0;
  14930. }
  14931. }
  14932. /**@private */
  14933. __proto._getHandler=function(caller,method){
  14934. var cid=caller ? caller.$_GID || (caller.$_GID=Utils.getGID()):0;
  14935. var mid=method.$_TID || (method.$_TID=(Timer._mid++)*100000);
  14936. return this._map[cid+mid];
  14937. }
  14938. /**
  14939. *延迟执行。
  14940. *@param caller 执行域(this)。
  14941. *@param method 定时器回调函数。
  14942. *@param args 回调参数。
  14943. */
  14944. __proto.callLater=function(caller,method,args){
  14945. if (this._getHandler(caller,method)==null){
  14946. if (this._pool.length)
  14947. var handler=this._pool.pop();
  14948. else handler=new LaterHandler();
  14949. handler.caller=caller;
  14950. handler.method=method;
  14951. handler.args=args;
  14952. var cid=caller ? caller.$_GID :0;
  14953. var mid=method["$_TID"];
  14954. handler.key=cid+mid;
  14955. this._map[handler.key]=handler
  14956. this._laters.push(handler);
  14957. }
  14958. }
  14959. /**
  14960. *立即执行 callLater 。
  14961. *@param caller 执行域(this)。
  14962. *@param method 定时器回调函数。
  14963. */
  14964. __proto.runCallLater=function(caller,method){
  14965. var handler=this._getHandler(caller,method);
  14966. if (handler && handler.method !=null){
  14967. this._map[handler.key]=null;
  14968. handler.run();
  14969. handler.clear();
  14970. }
  14971. }
  14972. CallLater.I=new CallLater();
  14973. CallLater.__init$=function(){
  14974. /**@private */
  14975. //class LaterHandler
  14976. LaterHandler=(function(){
  14977. function LaterHandler(){
  14978. this.key=0;
  14979. this.caller=null;
  14980. this.method=null;
  14981. this.args=null;
  14982. }
  14983. __class(LaterHandler,'');
  14984. var __proto=LaterHandler.prototype;
  14985. __proto.clear=function(){
  14986. this.caller=null;
  14987. this.method=null;
  14988. this.args=null;
  14989. }
  14990. __proto.run=function(){
  14991. var caller=this.caller;
  14992. if (caller && caller.destroyed)return this.clear();
  14993. var method=this.method;
  14994. var args=this.args;
  14995. if (method==null)return;
  14996. args ? method.apply(caller,args):method.call(caller);
  14997. }
  14998. return LaterHandler;
  14999. })()
  15000. }
  15001. return CallLater;
  15002. })()
  15003. /**
  15004. *<code>Graphics</code> 类用于创建绘图显示对象。Graphics可以同时绘制多个位图或者矢量图,还可以结合save,restore,transform,scale,rotate,translate,alpha等指令对绘图效果进行变化。
  15005. *Graphics以命令流方式存储,可以通过cmds属性访问所有命令流。Graphics是比Sprite更轻量级的对象,合理使用能提高应用性能(比如把大量的节点绘图改为一个节点的Graphics命令集合,能减少大量节点创建消耗)。
  15006. *@see laya.display.Sprite#graphics
  15007. */
  15008. //class laya.display.Graphics
  15009. var Graphics=(function(){
  15010. function Graphics(){
  15011. /**@private */
  15012. this._sp=null;
  15013. /**@private */
  15014. this._one=null;
  15015. /**@private */
  15016. this._cmds=null;
  15017. /**@private */
  15018. this._vectorgraphArray=null;
  15019. /**@private */
  15020. this._graphicBounds=null;
  15021. /**@private */
  15022. this.autoDestroy=false;
  15023. this._render=this._renderEmpty;
  15024. this._createData();
  15025. }
  15026. __class(Graphics,'laya.display.Graphics');
  15027. var __proto=Graphics.prototype;
  15028. /**@private */
  15029. __proto._createData=function(){}
  15030. /**@private */
  15031. __proto._clearData=function(){}
  15032. /**@private */
  15033. __proto._destroyData=function(){}
  15034. /**
  15035. *<p>销毁此对象。</p>
  15036. */
  15037. __proto.destroy=function(){
  15038. this.clear(true);
  15039. if (this._graphicBounds)this._graphicBounds.destroy();
  15040. this._graphicBounds=null;
  15041. this._vectorgraphArray=null;
  15042. if (this._sp){
  15043. this._sp._renderType=0;
  15044. this._sp._setRenderType(0);
  15045. this._sp=null;
  15046. }
  15047. this._destroyData();
  15048. }
  15049. /**
  15050. *<p>清空绘制命令。</p>
  15051. *@param recoverCmds 是否回收绘图指令数组,设置为true,则对指令数组进行回收以节省内存开销,建议设置为true进行回收,但如果手动引用了数组,不建议回收
  15052. */
  15053. __proto.clear=function(recoverCmds){
  15054. (recoverCmds===void 0)&& (recoverCmds=true);
  15055. if (recoverCmds){
  15056. var tCmd=this._one;
  15057. if (this._cmds){
  15058. var i=0,len=this._cmds.length;
  15059. for (i=0;i < len;i++){
  15060. tCmd=this._cmds[i];
  15061. tCmd.recover();
  15062. }
  15063. this._cmds.length=0;
  15064. }else if (tCmd){
  15065. tCmd.recover();
  15066. }
  15067. }else {
  15068. this._cmds=null;
  15069. }
  15070. this._one=null;
  15071. this._render=this._renderEmpty;
  15072. this._clearData();
  15073. if (this._sp){
  15074. this._sp._renderType &=~ /*laya.display.SpriteConst.GRAPHICS*/0x200;
  15075. this._sp._setRenderType(this._sp._renderType);
  15076. }
  15077. this._repaint();
  15078. if (this._vectorgraphArray){
  15079. for (i=0,len=this._vectorgraphArray.length;i < len;i++){
  15080. VectorGraphManager.getInstance().deleteShape(this._vectorgraphArray[i]);
  15081. }
  15082. this._vectorgraphArray.length=0;
  15083. }
  15084. }
  15085. /**@private */
  15086. __proto._clearBoundsCache=function(){
  15087. if (this._graphicBounds)this._graphicBounds.reset();
  15088. }
  15089. /**@private */
  15090. __proto._initGraphicBounds=function(){
  15091. if (!this._graphicBounds){
  15092. this._graphicBounds=GraphicsBounds.create();
  15093. this._graphicBounds._graphics=this;
  15094. }
  15095. }
  15096. /**
  15097. *@private
  15098. *重绘此对象。
  15099. */
  15100. __proto._repaint=function(){
  15101. this._clearBoundsCache();
  15102. this._sp && this._sp.repaint();
  15103. }
  15104. //TODO:coverage
  15105. __proto._isOnlyOne=function(){
  15106. return !this._cmds || this._cmds.length===0;
  15107. }
  15108. /**
  15109. *获取位置及宽高信息矩阵(比较耗CPU,频繁使用会造成卡顿,尽量少用)。
  15110. *@param realSize (可选)使用图片的真实大小,默认为false
  15111. *@return 位置与宽高组成的 一个 Rectangle 对象。
  15112. */
  15113. __proto.getBounds=function(realSize){
  15114. (realSize===void 0)&& (realSize=false);
  15115. this._initGraphicBounds();
  15116. return this._graphicBounds.getBounds(realSize);
  15117. }
  15118. /**
  15119. *@private
  15120. *@param realSize (可选)使用图片的真实大小,默认为false
  15121. *获取端点列表。
  15122. */
  15123. __proto.getBoundPoints=function(realSize){
  15124. (realSize===void 0)&& (realSize=false);
  15125. this._initGraphicBounds();
  15126. return this._graphicBounds.getBoundPoints(realSize);
  15127. }
  15128. /**
  15129. *绘制单独图片
  15130. *@param texture 纹理。
  15131. *@param x (可选)X轴偏移量。
  15132. *@param y (可选)Y轴偏移量。
  15133. *@param width (可选)宽度。
  15134. *@param height (可选)高度。
  15135. */
  15136. __proto.drawImage=function(texture,x,y,width,height){
  15137. (x===void 0)&& (x=0);
  15138. (y===void 0)&& (y=0);
  15139. (width===void 0)&& (width=0);
  15140. (height===void 0)&& (height=0);
  15141. if (!texture)return null;
  15142. if (!width)width=texture.sourceWidth;
  15143. if (!height)height=texture.sourceHeight;
  15144. if (texture.getIsReady()){
  15145. var wRate=width / texture.sourceWidth;
  15146. var hRate=height / texture.sourceHeight;
  15147. width=texture.width *wRate;
  15148. height=texture.height *hRate;
  15149. if (width <=0 || height <=0)return null;
  15150. x+=texture.offsetX *wRate;
  15151. y+=texture.offsetY *hRate;
  15152. }
  15153. if (this._sp){
  15154. this._sp._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  15155. this._sp._setRenderType(this._sp._renderType);
  15156. };
  15157. var args=DrawImageCmd.create.call(this,texture,x,y,width,height);
  15158. if (this._one==null){
  15159. this._one=args;
  15160. this._render=this._renderOneImg;
  15161. }else {
  15162. this._saveToCmd(null,args);
  15163. }
  15164. this._repaint();
  15165. return args;
  15166. }
  15167. /**
  15168. *绘制纹理,相比drawImage功能更强大,性能会差一些
  15169. *@param texture 纹理。
  15170. *@param x (可选)X轴偏移量。
  15171. *@param y (可选)Y轴偏移量。
  15172. *@param width (可选)宽度。
  15173. *@param height (可选)高度。
  15174. *@param matrix (可选)矩阵信息。
  15175. *@param alpha (可选)透明度。
  15176. *@param color (可选)颜色滤镜。
  15177. *@param blendMode (可选)混合模式。
  15178. */
  15179. __proto.drawTexture=function(texture,x,y,width,height,matrix,alpha,color,blendMode){
  15180. (x===void 0)&& (x=0);
  15181. (y===void 0)&& (y=0);
  15182. (width===void 0)&& (width=0);
  15183. (height===void 0)&& (height=0);
  15184. (alpha===void 0)&& (alpha=1);
  15185. if (!texture || alpha < 0.01)return null;
  15186. if (!texture.getIsReady())return null;
  15187. if (!width)width=texture.sourceWidth;
  15188. if (!height)height=texture.sourceHeight;
  15189. if (texture.getIsReady()){
  15190. var wRate=width / texture.sourceWidth;
  15191. var hRate=height / texture.sourceHeight;
  15192. width=texture.width *wRate;
  15193. height=texture.height *hRate;
  15194. if (width <=0 || height <=0)return null;
  15195. x+=texture.offsetX *wRate;
  15196. y+=texture.offsetY *hRate;
  15197. }
  15198. if (this._sp){
  15199. this._sp._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  15200. this._sp._setRenderType(this._sp._renderType);
  15201. };
  15202. var args=DrawTextureCmd.create.call(this,texture,x,y,width,height,matrix,alpha,color,blendMode);
  15203. this._repaint();
  15204. return this._saveToCmd(null,args);
  15205. }
  15206. /**
  15207. *批量绘制同样纹理。
  15208. *@param texture 纹理。
  15209. *@param pos 绘制次数和坐标。
  15210. */
  15211. __proto.drawTextures=function(texture,pos){
  15212. if (!texture)return null;
  15213. return this._saveToCmd(Render._context.drawTextures,DrawTexturesCmd.create.call(this,texture,pos));
  15214. }
  15215. /**
  15216. *绘制一组三角形
  15217. *@param texture 纹理。
  15218. *@param x X轴偏移量。
  15219. *@param y Y轴偏移量。
  15220. *@param vertices 顶点数组。
  15221. *@param indices 顶点索引。
  15222. *@param uvData UV数据。
  15223. *@param matrix 缩放矩阵。
  15224. *@param alpha alpha
  15225. *@param color 颜色变换
  15226. *@param blendMode blend模式
  15227. */
  15228. __proto.drawTriangles=function(texture,x,y,vertices,uvs,indices,matrix,alpha,color,blendMode){
  15229. (alpha===void 0)&& (alpha=1);
  15230. return this._saveToCmd(Render._context.drawTriangles,DrawTrianglesCmd.create.call(this,texture,x,y,vertices,uvs,indices,matrix,alpha,color,blendMode));
  15231. }
  15232. /**
  15233. *用texture填充。
  15234. *@param texture 纹理。
  15235. *@param x X轴偏移量。
  15236. *@param y Y轴偏移量。
  15237. *@param width (可选)宽度。
  15238. *@param height (可选)高度。
  15239. *@param type (可选)填充类型 repeat|repeat-x|repeat-y|no-repeat
  15240. *@param offset (可选)贴图纹理偏移
  15241. *
  15242. */
  15243. __proto.fillTexture=function(texture,x,y,width,height,type,offset){
  15244. (width===void 0)&& (width=0);
  15245. (height===void 0)&& (height=0);
  15246. (type===void 0)&& (type="repeat");
  15247. if (texture && texture.getIsReady())
  15248. return this._saveToCmd(Render._context._fillTexture,FillTextureCmd.create.call(this,texture,x,y,width,height,type,offset || Point.EMPTY,{}));
  15249. else
  15250. return null;
  15251. }
  15252. /**
  15253. *@private
  15254. *保存到命令流。
  15255. */
  15256. __proto._saveToCmd=function(fun,args){
  15257. if (this._sp){
  15258. this._sp._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  15259. this._sp._setRenderType(this._sp._renderType);
  15260. }
  15261. if (this._one==null){
  15262. this._one=args;
  15263. this._render=this._renderOne;
  15264. }else {
  15265. this._render=this._renderAll;
  15266. (this._cmds || (this._cmds=[])).length===0 && this._cmds.push(this._one);
  15267. this._cmds.push(args);
  15268. }
  15269. this._repaint();
  15270. return args;
  15271. }
  15272. /**
  15273. *设置剪裁区域,超出剪裁区域的坐标不显示。
  15274. *@param x X 轴偏移量。
  15275. *@param y Y 轴偏移量。
  15276. *@param width 宽度。
  15277. *@param height 高度。
  15278. */
  15279. __proto.clipRect=function(x,y,width,height){
  15280. return this._saveToCmd(Render._context.clipRect,ClipRectCmd.create.call(this,x,y,width,height));
  15281. }
  15282. /**
  15283. *在画布上绘制文本。
  15284. *@param text 在画布上输出的文本。
  15285. *@param x 开始绘制文本的 x 坐标位置(相对于画布)。
  15286. *@param y 开始绘制文本的 y 坐标位置(相对于画布)。
  15287. *@param font 定义字号和字体,比如"20px Arial"。
  15288. *@param color 定义文本颜色,比如"#ff0000"。
  15289. *@param textAlign 文本对齐方式,可选值:"left","center","right"。
  15290. */
  15291. __proto.fillText=function(text,x,y,font,color,textAlign){
  15292. return this._saveToCmd(Render._context.fillText,FillTextCmd.create.call(this,text,x,y,font || Text.defaultFontStr(),color,textAlign));
  15293. }
  15294. /**
  15295. *在画布上绘制“被填充且镶边的”文本。
  15296. *@param text 在画布上输出的文本。
  15297. *@param x 开始绘制文本的 x 坐标位置(相对于画布)。
  15298. *@param y 开始绘制文本的 y 坐标位置(相对于画布)。
  15299. *@param font 定义字体和字号,比如"20px Arial"。
  15300. *@param fillColor 定义文本颜色,比如"#ff0000"。
  15301. *@param borderColor 定义镶边文本颜色。
  15302. *@param lineWidth 镶边线条宽度。
  15303. *@param textAlign 文本对齐方式,可选值:"left","center","right"。
  15304. */
  15305. __proto.fillBorderText=function(text,x,y,font,fillColor,borderColor,lineWidth,textAlign){
  15306. return this._saveToCmd(Render._context.fillBorderText,FillBorderTextCmd.create.call(this,text,x,y,font || Text.defaultFontStr(),fillColor,borderColor,lineWidth,textAlign));
  15307. }
  15308. /***@private */
  15309. __proto.fillWords=function(words,x,y,font,color){
  15310. return this._saveToCmd(Render._context.fillWords,FillWordsCmd.create.call(this,words,x,y,font || Text.defaultFontStr(),color));
  15311. }
  15312. /***@private */
  15313. __proto.fillBorderWords=function(words,x,y,font,fillColor,borderColor,lineWidth){
  15314. return this._saveToCmd(Render._context.fillBorderWords,FillBorderWordsCmd.create.call(this,words,x,y,font || Text.defaultFontStr(),fillColor,borderColor,lineWidth));
  15315. }
  15316. /**
  15317. *在画布上绘制文本(没有填色)。文本的默认颜色是黑色。
  15318. *@param text 在画布上输出的文本。
  15319. *@param x 开始绘制文本的 x 坐标位置(相对于画布)。
  15320. *@param y 开始绘制文本的 y 坐标位置(相对于画布)。
  15321. *@param font 定义字体和字号,比如"20px Arial"。
  15322. *@param color 定义文本颜色,比如"#ff0000"。
  15323. *@param lineWidth 线条宽度。
  15324. *@param textAlign 文本对齐方式,可选值:"left","center","right"。
  15325. */
  15326. __proto.strokeText=function(text,x,y,font,color,lineWidth,textAlign){
  15327. return this._saveToCmd(Render._context.fillBorderText,StrokeTextCmd.create.call(this,text,x,y,font || Text.defaultFontStr(),null,color,lineWidth,textAlign));
  15328. }
  15329. /**
  15330. *设置透明度。
  15331. *@param value 透明度。
  15332. */
  15333. __proto.alpha=function(alpha){
  15334. return this._saveToCmd(Render._context.alpha,AlphaCmd.create.call(this,alpha));
  15335. }
  15336. /**
  15337. *替换绘图的当前转换矩阵。
  15338. *@param mat 矩阵。
  15339. *@param pivotX (可选)水平方向轴心点坐标。
  15340. *@param pivotY (可选)垂直方向轴心点坐标。
  15341. */
  15342. __proto.transform=function(matrix,pivotX,pivotY){
  15343. (pivotX===void 0)&& (pivotX=0);
  15344. (pivotY===void 0)&& (pivotY=0);
  15345. return this._saveToCmd(Render._context._transform,TransformCmd.create.call(this,matrix,pivotX,pivotY));
  15346. }
  15347. /**
  15348. *旋转当前绘图。(推荐使用transform,性能更高)
  15349. *@param angle 旋转角度,以弧度计。
  15350. *@param pivotX (可选)水平方向轴心点坐标。
  15351. *@param pivotY (可选)垂直方向轴心点坐标。
  15352. */
  15353. __proto.rotate=function(angle,pivotX,pivotY){
  15354. (pivotX===void 0)&& (pivotX=0);
  15355. (pivotY===void 0)&& (pivotY=0);
  15356. return this._saveToCmd(Render._context._rotate,RotateCmd.create.call(this,angle,pivotX,pivotY));
  15357. }
  15358. /**
  15359. *缩放当前绘图至更大或更小。(推荐使用transform,性能更高)
  15360. *@param scaleX 水平方向缩放值。
  15361. *@param scaleY 垂直方向缩放值。
  15362. *@param pivotX (可选)水平方向轴心点坐标。
  15363. *@param pivotY (可选)垂直方向轴心点坐标。
  15364. */
  15365. __proto.scale=function(scaleX,scaleY,pivotX,pivotY){
  15366. (pivotX===void 0)&& (pivotX=0);
  15367. (pivotY===void 0)&& (pivotY=0);
  15368. return this._saveToCmd(Render._context._scale,ScaleCmd.create.call(this,scaleX,scaleY,pivotX,pivotY));
  15369. }
  15370. /**
  15371. *重新映射画布上的 (0,0)位置。
  15372. *@param x 添加到水平坐标(x)上的值。
  15373. *@param y 添加到垂直坐标(y)上的值。
  15374. */
  15375. __proto.translate=function(tx,ty){
  15376. return this._saveToCmd(Render._context.translate,TranslateCmd.create.call(this,tx,ty));
  15377. }
  15378. /**
  15379. *保存当前环境的状态。
  15380. */
  15381. __proto.save=function(){
  15382. return this._saveToCmd(Render._context._save,SaveCmd.create.call(this));
  15383. }
  15384. /**
  15385. *返回之前保存过的路径状态和属性。
  15386. */
  15387. __proto.restore=function(){
  15388. return this._saveToCmd(Render._context.restore,RestoreCmd.create.call(this));
  15389. }
  15390. /**
  15391. *@private
  15392. *替换文本内容。
  15393. *@param text 文本内容。
  15394. *@return 替换成功则值为true,否则值为flase。
  15395. */
  15396. __proto.replaceText=function(text){
  15397. this._repaint();
  15398. var cmds=this._cmds;
  15399. if (!cmds){
  15400. if (this._one && this._isTextCmd(this._one)){
  15401. this._one.text=text;
  15402. return true;
  15403. }
  15404. }else {
  15405. for (var i=cmds.length-1;i >-1;i--){
  15406. if (this._isTextCmd(cmds[i])){
  15407. cmds[i].text=text;
  15408. return true;
  15409. }
  15410. }
  15411. }
  15412. return false;
  15413. }
  15414. /**@private */
  15415. __proto._isTextCmd=function(cmd){
  15416. var cmdID=cmd.cmdID;
  15417. return cmdID==/*laya.display.cmd.FillTextCmd.ID*/"FillText" || cmdID==/*laya.display.cmd.StrokeTextCmd.ID*/"StrokeText" || cmdID==/*laya.display.cmd.FillBorderTextCmd.ID*/"FillBorderText";
  15418. }
  15419. /**
  15420. *@private
  15421. *替换文本颜色。
  15422. *@param color 颜色。
  15423. */
  15424. __proto.replaceTextColor=function(color){
  15425. this._repaint();
  15426. var cmds=this._cmds;
  15427. if (!cmds){
  15428. if (this._one && this._isTextCmd(this._one)){
  15429. this._setTextCmdColor(this._one,color);
  15430. }
  15431. }else {
  15432. for (var i=cmds.length-1;i >-1;i--){
  15433. if (this._isTextCmd(cmds[i])){
  15434. this._setTextCmdColor(cmds[i],color);
  15435. }
  15436. }
  15437. }
  15438. }
  15439. /**@private */
  15440. __proto._setTextCmdColor=function(cmdO,color){
  15441. var cmdID=cmdO.cmdID;
  15442. switch (cmdID){
  15443. case /*laya.display.cmd.FillTextCmd.ID*/"FillText":
  15444. case /*laya.display.cmd.StrokeTextCmd.ID*/"StrokeText":
  15445. cmdO.color=color;
  15446. break ;
  15447. case /*laya.display.cmd.FillBorderTextCmd.ID*/"FillBorderText":
  15448. case /*laya.display.cmd.FillBorderWordsCmd.ID*/"FillBorderWords":
  15449. case /*laya.display.cmd.FillBorderTextCmd.ID*/"FillBorderText":
  15450. cmdO.fillColor=color;
  15451. break ;
  15452. }
  15453. }
  15454. /**
  15455. *加载并显示一个图片。
  15456. *@param url 图片地址。
  15457. *@param x (可选)显示图片的x位置。
  15458. *@param y (可选)显示图片的y位置。
  15459. *@param width (可选)显示图片的宽度,设置为0表示使用图片默认宽度。
  15460. *@param height (可选)显示图片的高度,设置为0表示使用图片默认高度。
  15461. *@param complete (可选)加载完成回调。
  15462. */
  15463. __proto.loadImage=function(url,x,y,width,height,complete){
  15464. (x===void 0)&& (x=0);
  15465. (y===void 0)&& (y=0);
  15466. (width===void 0)&& (width=0);
  15467. (height===void 0)&& (height=0);
  15468. var tex=Loader.getRes(url);
  15469. if (!tex){
  15470. tex=new Texture();
  15471. tex.load(url);
  15472. Loader.cacheRes(url,tex);
  15473. tex.once(/*laya.events.Event.READY*/"ready",this,this.drawImage,[tex,x,y,width,height]);
  15474. }else {
  15475. if (!tex.getIsReady()){
  15476. tex.once(/*laya.events.Event.READY*/"ready",this,this.drawImage,[tex,x,y,width,height]);
  15477. }else
  15478. this.drawImage(tex,x,y,width,height);
  15479. }
  15480. if (complete !=null){
  15481. tex.getIsReady()? complete.call(this._sp):tex.on(/*laya.events.Event.READY*/"ready",this._sp,complete);
  15482. }
  15483. }
  15484. /**
  15485. *@private
  15486. */
  15487. __proto._renderEmpty=function(sprite,context,x,y){}
  15488. /**
  15489. *@private
  15490. */
  15491. __proto._renderAll=function(sprite,context,x,y){
  15492. var cmds=this._cmds;
  15493. for (var i=0,n=cmds.length;i < n;i++){
  15494. cmds[i].run(context,x,y);
  15495. }
  15496. }
  15497. /**
  15498. *@private
  15499. */
  15500. __proto._renderOne=function(sprite,context,x,y){
  15501. context.sprite=sprite;
  15502. this._one.run(context,x,y);
  15503. }
  15504. /**
  15505. *@private
  15506. */
  15507. __proto._renderOneImg=function(sprite,context,x,y){
  15508. context.sprite=sprite;
  15509. this._one.run(context,x,y);
  15510. }
  15511. /**
  15512. *绘制一条线。
  15513. *@param fromX X轴开始位置。
  15514. *@param fromY Y轴开始位置。
  15515. *@param toX X轴结束位置。
  15516. *@param toY Y轴结束位置。
  15517. *@param lineColor 颜色。
  15518. *@param lineWidth (可选)线条宽度。
  15519. */
  15520. __proto.drawLine=function(fromX,fromY,toX,toY,lineColor,lineWidth){
  15521. (lineWidth===void 0)&& (lineWidth=1);
  15522. var offset=(lineWidth < 1 || lineWidth % 2===0)? 0 :0.5;
  15523. return this._saveToCmd(Render._context._drawLine,DrawLineCmd.create.call(this,fromX+offset,fromY+offset,toX+offset,toY+offset,lineColor,lineWidth,0));
  15524. }
  15525. /**
  15526. *绘制一系列线段。
  15527. *@param x 开始绘制的X轴位置。
  15528. *@param y 开始绘制的Y轴位置。
  15529. *@param points 线段的点集合。格式:[x1,y1,x2,y2,x3,y3...]。
  15530. *@param lineColor 线段颜色,或者填充绘图的渐变对象。
  15531. *@param lineWidth (可选)线段宽度。
  15532. */
  15533. __proto.drawLines=function(x,y,points,lineColor,lineWidth){
  15534. (lineWidth===void 0)&& (lineWidth=1);
  15535. if (!points || points.length < 4)return null;
  15536. var offset=(lineWidth < 1 || lineWidth % 2===0)? 0 :0.5;
  15537. return this._saveToCmd(Render._context._drawLines,DrawLinesCmd.create.call(this,x+offset,y+offset,points,lineColor,lineWidth,0));
  15538. }
  15539. /**
  15540. *绘制一系列曲线。
  15541. *@param x 开始绘制的 X 轴位置。
  15542. *@param y 开始绘制的 Y 轴位置。
  15543. *@param points 线段的点集合,格式[controlX,controlY,anchorX,anchorY...]。
  15544. *@param lineColor 线段颜色,或者填充绘图的渐变对象。
  15545. *@param lineWidth (可选)线段宽度。
  15546. */
  15547. __proto.drawCurves=function(x,y,points,lineColor,lineWidth){
  15548. (lineWidth===void 0)&& (lineWidth=1);
  15549. return this._saveToCmd(Render._context.drawCurves,DrawCurvesCmd.create.call(this,x,y,points,lineColor,lineWidth));
  15550. }
  15551. /**
  15552. *绘制矩形。
  15553. *@param x 开始绘制的 X 轴位置。
  15554. *@param y 开始绘制的 Y 轴位置。
  15555. *@param width 矩形宽度。
  15556. *@param height 矩形高度。
  15557. *@param fillColor 填充颜色,或者填充绘图的渐变对象。
  15558. *@param lineColor (可选)边框颜色,或者填充绘图的渐变对象。
  15559. *@param lineWidth (可选)边框宽度。
  15560. */
  15561. __proto.drawRect=function(x,y,width,height,fillColor,lineColor,lineWidth){
  15562. (lineWidth===void 0)&& (lineWidth=1);
  15563. var offset=(lineWidth >=1 && lineColor)? lineWidth / 2 :0;
  15564. var lineOffset=lineColor ? lineWidth :0;
  15565. return this._saveToCmd(Render._context.drawRect,DrawRectCmd.create.call(this,x+offset,y+offset,width-lineOffset,height-lineOffset,fillColor,lineColor,lineWidth));
  15566. }
  15567. /**
  15568. *绘制圆形。
  15569. *@param x 圆点X 轴位置。
  15570. *@param y 圆点Y 轴位置。
  15571. *@param radius 半径。
  15572. *@param fillColor 填充颜色,或者填充绘图的渐变对象。
  15573. *@param lineColor (可选)边框颜色,或者填充绘图的渐变对象。
  15574. *@param lineWidth (可选)边框宽度。
  15575. */
  15576. __proto.drawCircle=function(x,y,radius,fillColor,lineColor,lineWidth){
  15577. (lineWidth===void 0)&& (lineWidth=1);
  15578. var offset=(lineWidth >=1 && lineColor)? lineWidth / 2 :0;
  15579. return this._saveToCmd(Render._context._drawCircle,DrawCircleCmd.create.call(this,x,y,radius-offset,fillColor,lineColor,lineWidth,0));
  15580. }
  15581. /**
  15582. *绘制扇形。
  15583. *@param x 开始绘制的 X 轴位置。
  15584. *@param y 开始绘制的 Y 轴位置。
  15585. *@param radius 扇形半径。
  15586. *@param startAngle 开始角度。
  15587. *@param endAngle 结束角度。
  15588. *@param fillColor 填充颜色,或者填充绘图的渐变对象。
  15589. *@param lineColor (可选)边框颜色,或者填充绘图的渐变对象。
  15590. *@param lineWidth (可选)边框宽度。
  15591. */
  15592. __proto.drawPie=function(x,y,radius,startAngle,endAngle,fillColor,lineColor,lineWidth){
  15593. (lineWidth===void 0)&& (lineWidth=1);
  15594. var offset=(lineWidth >=1 && lineColor)? lineWidth / 2 :0;
  15595. var lineOffset=lineColor ? lineWidth :0;
  15596. 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));
  15597. }
  15598. /**
  15599. *绘制多边形。
  15600. *@param x 开始绘制的 X 轴位置。
  15601. *@param y 开始绘制的 Y 轴位置。
  15602. *@param points 多边形的点集合。
  15603. *@param fillColor 填充颜色,或者填充绘图的渐变对象。
  15604. *@param lineColor (可选)边框颜色,或者填充绘图的渐变对象。
  15605. *@param lineWidth (可选)边框宽度。
  15606. */
  15607. __proto.drawPoly=function(x,y,points,fillColor,lineColor,lineWidth){
  15608. (lineWidth===void 0)&& (lineWidth=1);
  15609. var tIsConvexPolygon=false;
  15610. if (points.length > 6){
  15611. tIsConvexPolygon=false;
  15612. }else {
  15613. tIsConvexPolygon=true;
  15614. };
  15615. var offset=(lineWidth >=1 && lineColor)? (lineWidth % 2===0 ? 0 :0.5):0;
  15616. return this._saveToCmd(Render._context._drawPoly,DrawPolyCmd.create.call(this,x+offset,y+offset,points,fillColor,lineColor,lineWidth,tIsConvexPolygon,0));
  15617. }
  15618. /**
  15619. *绘制路径。
  15620. *@param x 开始绘制的 X 轴位置。
  15621. *@param y 开始绘制的 Y 轴位置。
  15622. *@param paths 路径集合,路径支持以下格式:[["moveTo",x,y],["lineTo",x,y],["arcTo",x1,y1,x2,y2,r],["closePath"]]。
  15623. *@param brush (可选)刷子定义,支持以下设置{fillStyle:"#FF0000"}。
  15624. *@param pen (可选)画笔定义,支持以下设置{strokeStyle,lineWidth,lineJoin:"bevel|round|miter",lineCap:"butt|round|square",miterLimit}。
  15625. */
  15626. __proto.drawPath=function(x,y,paths,brush,pen){
  15627. return this._saveToCmd(Render._context._drawPath,DrawPathCmd.create.call(this,x,y,paths,brush,pen));
  15628. }
  15629. /**
  15630. *@private
  15631. *绘制带九宫格的图片
  15632. *@param texture
  15633. *@param x
  15634. *@param y
  15635. *@param width
  15636. *@param height
  15637. *@param sizeGrid
  15638. */
  15639. __proto.draw9Grid=function(texture,x,y,width,height,sizeGrid){
  15640. (x===void 0)&& (x=0);
  15641. (y===void 0)&& (y=0);
  15642. (width===void 0)&& (width=0);
  15643. (height===void 0)&& (height=0);
  15644. this._saveToCmd(null,Draw9GridTexture.create(texture,x,y,width,height,sizeGrid));
  15645. }
  15646. /**
  15647. *@private
  15648. *命令流。存储了所有绘制命令。
  15649. */
  15650. __getset(0,__proto,'cmds',function(){
  15651. return this._cmds;
  15652. },function(value){
  15653. if (this._sp){
  15654. this._sp._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  15655. this._sp._setRenderType(this._sp._renderType);
  15656. }
  15657. this._cmds=value;
  15658. this._render=this._renderAll;
  15659. this._repaint();
  15660. });
  15661. return Graphics;
  15662. })()
  15663. /**
  15664. *@private
  15665. *<code>HTMLChar</code> 是一个 HTML 字符类。
  15666. */
  15667. //class laya.utils.HTMLChar
  15668. var HTMLChar=(function(){
  15669. function HTMLChar(){
  15670. /**x坐标*/
  15671. //this.x=NaN;
  15672. /**y坐标*/
  15673. //this.y=NaN;
  15674. /**宽*/
  15675. //this.width=NaN;
  15676. /**高*/
  15677. //this.height=NaN;
  15678. /**表示是否是正常单词(英文|.|数字)。*/
  15679. //this.isWord=false;
  15680. /**字符。*/
  15681. //this.char=null;
  15682. /**字符数量。*/
  15683. //this.charNum=NaN;
  15684. /**CSS 样式。*/
  15685. //this.style=null;
  15686. this.reset();
  15687. }
  15688. __class(HTMLChar,'laya.utils.HTMLChar');
  15689. var __proto=HTMLChar.prototype;
  15690. /**
  15691. *根据指定的字符、宽高、样式,创建一个 <code>HTMLChar</code> 类的实例。
  15692. *@param char 字符。
  15693. *@param w 宽度。
  15694. *@param h 高度。
  15695. *@param style CSS 样式。
  15696. */
  15697. __proto.setData=function(char,w,h,style){
  15698. this.char=char;
  15699. this.charNum=char.charCodeAt(0);
  15700. this.x=this.y=0;
  15701. this.width=w;
  15702. this.height=h;
  15703. this.style=style;
  15704. this.isWord=!HTMLChar._isWordRegExp.test(char);
  15705. return this;
  15706. }
  15707. /**
  15708. *重置
  15709. */
  15710. __proto.reset=function(){
  15711. this.x=this.y=this.width=this.height=0;
  15712. this.isWord=false;
  15713. this.char=null;
  15714. this.charNum=0;
  15715. this.style=null;
  15716. return this;
  15717. }
  15718. //TODO:coverage
  15719. __proto.recover=function(){
  15720. Pool.recover("HTMLChar",this.reset());
  15721. }
  15722. /**@private */
  15723. __proto._isChar=function(){
  15724. return true;
  15725. }
  15726. /**@private */
  15727. __proto._getCSSStyle=function(){
  15728. return this.style;
  15729. }
  15730. HTMLChar.create=function(){
  15731. return Pool.getItemByClass("HTMLChar",HTMLChar);
  15732. }
  15733. HTMLChar._isWordRegExp=new RegExp("[\\w\.]","");
  15734. return HTMLChar;
  15735. })()
  15736. // 注意长宽都不要超过256,一个是影响效率,一个是超出表达能力
  15737. //class laya.webgl.text.AtlasGrid
  15738. var AtlasGrid=(function(){
  15739. function AtlasGrid(width,height,id){
  15740. this.atlasID=0;
  15741. this._width=0;
  15742. this._height=0;
  15743. this._texCount=0;
  15744. this._rowInfo=null;
  15745. // 当前行的最大长度
  15746. this._cells=null;
  15747. // 每个格子的信息。{type,w,h}相当于一个距离场. type=0 表示空闲的。不为0的情况下填充的是宽高(有什么用呢)
  15748. this._used=0;
  15749. (width===void 0)&& (width=0);
  15750. (height===void 0)&& (height=0);
  15751. (id===void 0)&& (id=0);
  15752. this._cells=null;
  15753. this._rowInfo=null;
  15754. this.atlasID=id;
  15755. this._init(width,height);
  15756. }
  15757. __class(AtlasGrid,'laya.webgl.text.AtlasGrid');
  15758. var __proto=AtlasGrid.prototype;
  15759. //------------------------------------------------------------------
  15760. __proto.addRect=function(type,width,height,pt){
  15761. if (!this._get(width,height,pt))
  15762. return false;
  15763. this._fill(pt.x,pt.y,width,height,type);
  15764. this._texCount++;
  15765. return true;
  15766. }
  15767. //------------------------------------------------------------------------------
  15768. __proto._release=function(){
  15769. this._cells=null;
  15770. this._rowInfo=null;
  15771. }
  15772. //------------------------------------------------------------------------------
  15773. __proto._init=function(width,height){
  15774. this._width=width;
  15775. this._height=height;
  15776. this._release();
  15777. if (this._width==0)return false;
  15778. this._cells=new Uint8Array(this._width *this._height*3);
  15779. this._rowInfo=new Uint8Array(this._height);
  15780. this._used=0;
  15781. this._clear();
  15782. return true;
  15783. }
  15784. //------------------------------------------------------------------
  15785. __proto._get=function(width,height,pt){
  15786. if (width > this._width || height >this._height){
  15787. return false;
  15788. };
  15789. var rx=-1;
  15790. var ry=-1;
  15791. var nWidth=this._width;
  15792. var nHeight=this._height;
  15793. var pCellBox=this._cells;
  15794. for (var y=0;y < nHeight;y++){
  15795. if (this._rowInfo[y] < width)continue ;
  15796. for (var x=0;x < nWidth;){
  15797. var tm=(y *nWidth+x)*3;
  15798. if (pCellBox[tm] !=0 || pCellBox[tm+1] < width || pCellBox[tm+2] < height){
  15799. x+=pCellBox[tm+1];
  15800. continue ;
  15801. }
  15802. rx=x;
  15803. ry=y;
  15804. for (var xx=0;xx < width;xx++){
  15805. if (pCellBox[3*xx+tm+2] < height){
  15806. rx=-1;
  15807. break ;
  15808. }
  15809. }
  15810. if (rx < 0){
  15811. x+=pCellBox[tm+1];
  15812. continue ;
  15813. }
  15814. pt.x=rx;
  15815. pt.y=ry;
  15816. return true;
  15817. }
  15818. }
  15819. return false;
  15820. }
  15821. //------------------------------------------------------------------
  15822. __proto._fill=function(x,y,w,h,type){
  15823. var nWidth=this._width;
  15824. var nHeghit=this._height;
  15825. this._check((x+w)<=nWidth && (y+h)<=nHeghit);
  15826. for (var yy=y;yy < (h+y);++yy){
  15827. this._check(this._rowInfo[yy] >=w);
  15828. this._rowInfo[yy]-=w;
  15829. for (var xx=0;xx < w;xx++){
  15830. var tm=(x+yy *nWidth+xx)*3;
  15831. this._check(this._cells[tm]==0);
  15832. this._cells[tm]=type;
  15833. this._cells[tm+1]=w;
  15834. this._cells[tm+2]=h;
  15835. }
  15836. }
  15837. if (x > 0){
  15838. for (yy=0;yy < h;++yy){
  15839. var s=0;
  15840. for (xx=x-1;xx >=0;--xx,++s){
  15841. if (this._cells[((y+yy)*nWidth+xx)*3] !=0)break ;
  15842. }
  15843. for (xx=s;xx > 0;--xx){
  15844. this._cells[((y+yy)*nWidth+x-xx)*3+1]=xx;
  15845. this._check(xx > 0);
  15846. }
  15847. }
  15848. }
  15849. if (y > 0){
  15850. for (xx=x;xx < (x+w);++xx){
  15851. s=0;
  15852. for (yy=y-1;yy >=0;--yy,s++){
  15853. if (this._cells[(xx+yy *nWidth)*3] !=0)break ;
  15854. }
  15855. for (yy=s;yy > 0;--yy){
  15856. this._cells[(xx+(y-yy)*nWidth)*3+2]=yy;
  15857. this._check(yy > 0);
  15858. }
  15859. }
  15860. }
  15861. this._used+=(w*h)/(this._width*this._height);
  15862. }
  15863. __proto._check=function(ret){
  15864. if (ret==false){
  15865. console.log("xtexMerger 错误啦");
  15866. }
  15867. }
  15868. //------------------------------------------------------------------
  15869. __proto._clear=function(){
  15870. this._texCount=0;
  15871. for (var y=0;y < this._height;y++){
  15872. this._rowInfo[y]=this._width;
  15873. }
  15874. for (var i=0;i < this._height;i++){
  15875. for (var j=0;j < this._width;j++){
  15876. var tm=(i *this._width+j)*3;
  15877. this._cells[tm]=0;
  15878. this._cells[tm+1]=this._width-j;
  15879. this._cells[tm+2]=this._width-i;
  15880. }
  15881. }
  15882. }
  15883. return AtlasGrid;
  15884. })()
  15885. /**
  15886. *绘制描边文字
  15887. */
  15888. //class laya.display.cmd.StrokeTextCmd
  15889. var StrokeTextCmd=(function(){
  15890. function StrokeTextCmd(){
  15891. /**
  15892. *在画布上输出的文本。
  15893. */
  15894. //this.text=null;
  15895. /**
  15896. *开始绘制文本的 x 坐标位置(相对于画布)。
  15897. */
  15898. //this.x=NaN;
  15899. /**
  15900. *开始绘制文本的 y 坐标位置(相对于画布)。
  15901. */
  15902. //this.y=NaN;
  15903. /**
  15904. *定义字体和字号,比如"20px Arial"。
  15905. */
  15906. //this.font=null;
  15907. /**
  15908. *定义文本颜色,比如"#ff0000"。
  15909. */
  15910. //this.color=null;
  15911. /**
  15912. *线条宽度。
  15913. */
  15914. //this.lineWidth=NaN;
  15915. /**
  15916. *文本对齐方式,可选值:"left","center","right"。
  15917. */
  15918. //this.textAlign=null;
  15919. }
  15920. __class(StrokeTextCmd,'laya.display.cmd.StrokeTextCmd');
  15921. var __proto=StrokeTextCmd.prototype;
  15922. /**
  15923. *回收到对象池
  15924. */
  15925. __proto.recover=function(){
  15926. Pool.recover("StrokeTextCmd",this);
  15927. }
  15928. /**@private */
  15929. __proto.run=function(context,gx,gy){
  15930. context.strokeWord(this.text,this.x+gx,this.y+gy,this.font,this.color,this.lineWidth,this.textAlign);
  15931. }
  15932. /**@private */
  15933. __getset(0,__proto,'cmdID',function(){
  15934. return "StrokeText";
  15935. });
  15936. StrokeTextCmd.create=function(text,x,y,font,color,lineWidth,textAlign){
  15937. var cmd=Pool.getItemByClass("StrokeTextCmd",StrokeTextCmd);
  15938. cmd.text=text;
  15939. cmd.x=x;
  15940. cmd.y=y;
  15941. cmd.font=font;
  15942. cmd.color=color;
  15943. cmd.lineWidth=lineWidth;
  15944. cmd.textAlign=textAlign;
  15945. return cmd;
  15946. }
  15947. StrokeTextCmd.ID="StrokeText";
  15948. return StrokeTextCmd;
  15949. })()
  15950. //class laya.webgl.text.ICharRender
  15951. var ICharRender=(function(){
  15952. function ICharRender(){}
  15953. __class(ICharRender,'laya.webgl.text.ICharRender');
  15954. var __proto=ICharRender.prototype;
  15955. __proto.getWidth=function(font,str){return 0;}
  15956. __proto.scale=function(sx,sy){}
  15957. /**
  15958. *TODO stroke
  15959. *@param char
  15960. *@param font
  15961. *@param size 返回宽高
  15962. *@return
  15963. */
  15964. __proto.getCharBmp=function(char,font,lineWidth,colStr,strokeColStr,size,margin_left,margin_top,margin_right,margin_bottom,rect){
  15965. return null;
  15966. }
  15967. __getset(0,__proto,'canvasWidth',function(){
  15968. return 0;
  15969. },function(w){
  15970. });
  15971. return ICharRender;
  15972. })()
  15973. /**
  15974. *<code>Ease</code> 类定义了缓动函数,以便实现 <code>Tween</code> 动画的缓动效果。
  15975. */
  15976. //class laya.utils.Ease
  15977. var Ease=(function(){
  15978. function Ease(){}
  15979. __class(Ease,'laya.utils.Ease');
  15980. Ease.linearNone=function(t,b,c,d){
  15981. return c *t / d+b;
  15982. }
  15983. Ease.linearIn=function(t,b,c,d){
  15984. return c *t / d+b;
  15985. }
  15986. Ease.linearInOut=function(t,b,c,d){
  15987. return c *t / d+b;
  15988. }
  15989. Ease.linearOut=function(t,b,c,d){
  15990. return c *t / d+b;
  15991. }
  15992. Ease.bounceIn=function(t,b,c,d){
  15993. return c-Ease.bounceOut(d-t,0,c,d)+b;
  15994. }
  15995. Ease.bounceInOut=function(t,b,c,d){
  15996. if (t < d *0.5)return Ease.bounceIn(t *2,0,c,d)*.5+b;
  15997. else return Ease.bounceOut(t *2-d,0,c,d)*.5+c *.5+b;
  15998. }
  15999. Ease.bounceOut=function(t,b,c,d){
  16000. if ((t /=d)< (1 / 2.75))return c *(7.5625 *t *t)+b;
  16001. else if (t < (2 / 2.75))return c *(7.5625 *(t-=(1.5 / 2.75))*t+.75)+b;
  16002. else if (t < (2.5 / 2.75))return c *(7.5625 *(t-=(2.25 / 2.75))*t+.9375)+b;
  16003. else return c *(7.5625 *(t-=(2.625 / 2.75))*t+.984375)+b;
  16004. }
  16005. Ease.backIn=function(t,b,c,d,s){
  16006. (s===void 0)&& (s=1.70158);
  16007. return c *(t /=d)*t *((s+1)*t-s)+b;
  16008. }
  16009. Ease.backInOut=function(t,b,c,d,s){
  16010. (s===void 0)&& (s=1.70158);
  16011. if ((t /=d *0.5)< 1)return c *0.5 *(t *t *(((s *=(1.525))+1)*t-s))+b;
  16012. return c / 2 *((t-=2)*t *(((s *=(1.525))+1)*t+s)+2)+b;
  16013. }
  16014. Ease.backOut=function(t,b,c,d,s){
  16015. (s===void 0)&& (s=1.70158);
  16016. return c *((t=t / d-1)*t *((s+1)*t+s)+1)+b;
  16017. }
  16018. Ease.elasticIn=function(t,b,c,d,a,p){
  16019. (a===void 0)&& (a=0);
  16020. (p===void 0)&& (p=0);
  16021. var s;
  16022. if (t==0)return b;
  16023. if ((t /=d)==1)return b+c;
  16024. if (!p)p=d *.3;
  16025. if (!a || (c > 0 && a < c)|| (c < 0 && a <-c)){
  16026. a=c;
  16027. s=p / 4;
  16028. }else s=p / Ease.PI2 *Math.asin(c / a);
  16029. return-(a *Math.pow(2,10 *(t-=1))*Math.sin((t *d-s)*Ease.PI2 / p))+b;
  16030. }
  16031. Ease.elasticInOut=function(t,b,c,d,a,p){
  16032. (a===void 0)&& (a=0);
  16033. (p===void 0)&& (p=0);
  16034. var s;
  16035. if (t==0)return b;
  16036. if ((t /=d *0.5)==2)return b+c;
  16037. if (!p)p=d *(.3 *1.5);
  16038. if (!a || (c > 0 && a < c)|| (c < 0 && a <-c)){
  16039. a=c;
  16040. s=p / 4;
  16041. }else s=p / Ease.PI2 *Math.asin(c / a);
  16042. if (t < 1)return-.5 *(a *Math.pow(2,10 *(t-=1))*Math.sin((t *d-s)*Ease.PI2 / p))+b;
  16043. return a *Math.pow(2,-10 *(t-=1))*Math.sin((t *d-s)*Ease.PI2 / p)*.5+c+b;
  16044. }
  16045. Ease.elasticOut=function(t,b,c,d,a,p){
  16046. (a===void 0)&& (a=0);
  16047. (p===void 0)&& (p=0);
  16048. var s;
  16049. if (t==0)return b;
  16050. if ((t /=d)==1)return b+c;
  16051. if (!p)p=d *.3;
  16052. if (!a || (c > 0 && a < c)|| (c < 0 && a <-c)){
  16053. a=c;
  16054. s=p / 4;
  16055. }else s=p / Ease.PI2 *Math.asin(c / a);
  16056. return (a *Math.pow(2,-10 *t)*Math.sin((t *d-s)*Ease.PI2 / p)+c+b);
  16057. }
  16058. Ease.strongIn=function(t,b,c,d){
  16059. return c *(t /=d)*t *t *t *t+b;
  16060. }
  16061. Ease.strongInOut=function(t,b,c,d){
  16062. if ((t /=d *0.5)< 1)return c *0.5 *t *t *t *t *t+b;
  16063. return c *0.5 *((t-=2)*t *t *t *t+2)+b;
  16064. }
  16065. Ease.strongOut=function(t,b,c,d){
  16066. return c *((t=t / d-1)*t *t *t *t+1)+b;
  16067. }
  16068. Ease.sineInOut=function(t,b,c,d){
  16069. return-c *0.5 *(Math.cos(Math.PI *t / d)-1)+b;
  16070. }
  16071. Ease.sineIn=function(t,b,c,d){
  16072. return-c *Math.cos(t / d *Ease.HALF_PI)+c+b;
  16073. }
  16074. Ease.sineOut=function(t,b,c,d){
  16075. return c *Math.sin(t / d *Ease.HALF_PI)+b;
  16076. }
  16077. Ease.quintIn=function(t,b,c,d){
  16078. return c *(t /=d)*t *t *t *t+b;
  16079. }
  16080. Ease.quintInOut=function(t,b,c,d){
  16081. if ((t /=d *0.5)< 1)return c *0.5 *t *t *t *t *t+b;
  16082. return c *0.5 *((t-=2)*t *t *t *t+2)+b;
  16083. }
  16084. Ease.quintOut=function(t,b,c,d){
  16085. return c *((t=t / d-1)*t *t *t *t+1)+b;
  16086. }
  16087. Ease.quartIn=function(t,b,c,d){
  16088. return c *(t /=d)*t *t *t+b;
  16089. }
  16090. Ease.quartInOut=function(t,b,c,d){
  16091. if ((t /=d *0.5)< 1)return c *0.5 *t *t *t *t+b;
  16092. return-c *0.5 *((t-=2)*t *t *t-2)+b;
  16093. }
  16094. Ease.quartOut=function(t,b,c,d){
  16095. return-c *((t=t / d-1)*t *t *t-1)+b;
  16096. }
  16097. Ease.cubicIn=function(t,b,c,d){
  16098. return c *(t /=d)*t *t+b;
  16099. }
  16100. Ease.cubicInOut=function(t,b,c,d){
  16101. if ((t /=d *0.5)< 1)return c *0.5 *t *t *t+b;
  16102. return c *0.5 *((t-=2)*t *t+2)+b;
  16103. }
  16104. Ease.cubicOut=function(t,b,c,d){
  16105. return c *((t=t / d-1)*t *t+1)+b;
  16106. }
  16107. Ease.quadIn=function(t,b,c,d){
  16108. return c *(t /=d)*t+b;
  16109. }
  16110. Ease.quadInOut=function(t,b,c,d){
  16111. if ((t /=d *0.5)< 1)return c *0.5 *t *t+b;
  16112. return-c *0.5 *((--t)*(t-2)-1)+b;
  16113. }
  16114. Ease.quadOut=function(t,b,c,d){
  16115. return-c *(t /=d)*(t-2)+b;
  16116. }
  16117. Ease.expoIn=function(t,b,c,d){
  16118. return (t==0)? b :c *Math.pow(2,10 *(t / d-1))+b-c *0.001;
  16119. }
  16120. Ease.expoInOut=function(t,b,c,d){
  16121. if (t==0)return b;
  16122. if (t==d)return b+c;
  16123. if ((t /=d *0.5)< 1)return c *0.5 *Math.pow(2,10 *(t-1))+b;
  16124. return c *0.5 *(-Math.pow(2,-10 *--t)+2)+b;
  16125. }
  16126. Ease.expoOut=function(t,b,c,d){
  16127. return (t==d)? b+c :c *(-Math.pow(2,-10 *t / d)+1)+b;
  16128. }
  16129. Ease.circIn=function(t,b,c,d){
  16130. return-c *(Math.sqrt(1-(t /=d)*t)-1)+b;
  16131. }
  16132. Ease.circInOut=function(t,b,c,d){
  16133. if ((t /=d *0.5)< 1)return-c *0.5 *(Math.sqrt(1-t *t)-1)+b;
  16134. return c *0.5 *(Math.sqrt(1-(t-=2)*t)+1)+b;
  16135. }
  16136. Ease.circOut=function(t,b,c,d){
  16137. return c *Math.sqrt(1-(t=t / d-1)*t)+b;
  16138. }
  16139. Ease.HALF_PI=Math.PI *0.5;
  16140. Ease.PI2=Math.PI *2;
  16141. return Ease;
  16142. })()
  16143. /**
  16144. *@private
  16145. *基于个数的对象缓存管理器
  16146. */
  16147. //class laya.utils.PoolCache
  16148. var PoolCache=(function(){
  16149. function PoolCache(){
  16150. /**
  16151. *对象在Pool中的标识
  16152. */
  16153. this.sign=null;
  16154. /**
  16155. *允许缓存的最大数量
  16156. */
  16157. this.maxCount=1000;
  16158. }
  16159. __class(PoolCache,'laya.utils.PoolCache');
  16160. var __proto=PoolCache.prototype;
  16161. /**
  16162. *获取缓存的对象列表
  16163. *@return
  16164. *
  16165. */
  16166. __proto.getCacheList=function(){
  16167. return Pool.getPoolBySign(this.sign);
  16168. }
  16169. /**
  16170. *尝试清理缓存
  16171. *@param force 是否强制清理
  16172. *
  16173. */
  16174. __proto.tryDispose=function(force){
  16175. var list;
  16176. list=Pool.getPoolBySign(this.sign);
  16177. if (list.length > this.maxCount){
  16178. list.splice(this.maxCount,list.length-this.maxCount);
  16179. }
  16180. }
  16181. PoolCache.addPoolCacheManager=function(sign,maxCount){
  16182. (maxCount===void 0)&& (maxCount=100);
  16183. var cache;
  16184. cache=new PoolCache();
  16185. cache.sign=sign;
  16186. cache.maxCount=maxCount;
  16187. CacheManger.regCacheByFunction(Utils.bind(cache.tryDispose,cache),Utils.bind(cache.getCacheList,cache));
  16188. }
  16189. return PoolCache;
  16190. })()
  16191. //class laya.webgl.utils.MatirxArray
  16192. var MatirxArray=(function(){
  16193. function MatirxArray(){}
  16194. __class(MatirxArray,'laya.webgl.utils.MatirxArray');
  16195. MatirxArray.ArrayMul=function(a,b,o){
  16196. if (!a){
  16197. MatirxArray.copyArray(b,o);
  16198. return;
  16199. }
  16200. if (!b){
  16201. MatirxArray.copyArray(a,o);
  16202. return;
  16203. };
  16204. var ai0=NaN,ai1=NaN,ai2=NaN,ai3=NaN;
  16205. for (var i=0;i < 4;i++){
  16206. ai0=a[i];
  16207. ai1=a[i+4];
  16208. ai2=a[i+8];
  16209. ai3=a[i+12];
  16210. o[i]=ai0 *b[0]+ai1 *b[1]+ai2 *b[2]+ai3 *b[3];
  16211. o[i+4]=ai0 *b[4]+ai1 *b[5]+ai2 *b[6]+ai3 *b[7];
  16212. o[i+8]=ai0 *b[8]+ai1 *b[9]+ai2 *b[10]+ai3 *b[11];
  16213. o[i+12]=ai0 *b[12]+ai1 *b[13]+ai2 *b[14]+ai3 *b[15];
  16214. }
  16215. }
  16216. MatirxArray.copyArray=function(f,t){
  16217. if (!f)return;
  16218. if (!t)return;
  16219. for (var i=0;i < f.length;i++){
  16220. t[i]=f[i];
  16221. }
  16222. }
  16223. return MatirxArray;
  16224. })()
  16225. /**
  16226. *<code>Mouse</code> 类用于控制鼠标光标样式。
  16227. */
  16228. //class laya.utils.Mouse
  16229. var Mouse=(function(){
  16230. function Mouse(){}
  16231. __class(Mouse,'laya.utils.Mouse');
  16232. /**
  16233. *设置鼠标样式
  16234. *@param cursorStr
  16235. *例如auto move no-drop col-resize
  16236. *all-scroll pointer not-allowed row-resize
  16237. *crosshair progress e-resize ne-resize
  16238. *default text n-resize nw-resize
  16239. *help vertical-text s-resize se-resize
  16240. *inherit wait w-resize sw-resize
  16241. */
  16242. __getset(1,Mouse,'cursor',function(){
  16243. return Mouse._style.cursor;
  16244. },function(cursorStr){
  16245. Mouse._style.cursor=cursorStr;
  16246. });
  16247. Mouse.hide=function(){
  16248. if (Mouse.cursor !="none"){
  16249. Mouse._preCursor=Mouse.cursor;
  16250. Mouse.cursor="none";
  16251. }
  16252. }
  16253. Mouse.show=function(){
  16254. if (Mouse.cursor=="none"){
  16255. if (Mouse._preCursor){
  16256. Mouse.cursor=Mouse._preCursor;
  16257. }else {
  16258. Mouse.cursor="auto";
  16259. }
  16260. }
  16261. }
  16262. Mouse._preCursor=null;
  16263. __static(Mouse,
  16264. ['_style',function(){return this._style=Browser.document.body.style;}
  16265. ]);
  16266. return Mouse;
  16267. })()
  16268. /**
  16269. *...
  16270. *@author ...
  16271. */
  16272. //class laya.webgl.VertexArrayObject
  16273. var VertexArrayObject=(function(){
  16274. function VertexArrayObject(){}
  16275. __class(VertexArrayObject,'laya.webgl.VertexArrayObject');
  16276. return VertexArrayObject;
  16277. })()
  16278. /*__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}}}}}());;
  16279. /**
  16280. *WebGLRTMgr 管理WebGLRenderTarget的创建和回收
  16281. */
  16282. //class laya.resource.WebGLRTMgr
  16283. var WebGLRTMgr=(function(){
  16284. function WebGLRTMgr(){}
  16285. __class(WebGLRTMgr,'laya.resource.WebGLRTMgr');
  16286. WebGLRTMgr.getRT=function(w,h){
  16287. w=w | 0;
  16288. h=h | 0;
  16289. if (w >=10000){
  16290. console.error('getRT error! w too big');
  16291. };
  16292. var key=h *10000+w;
  16293. var sw=WebGLRTMgr.dict[key];
  16294. var ret;
  16295. if (sw){
  16296. if (sw.length > 0){
  16297. ret=sw.pop();
  16298. ret._mgrKey=key;
  16299. return ret;
  16300. }
  16301. }
  16302. ret=new RenderTexture2D(w,h,/*laya.resource.BaseTexture.FORMAT_R8G8B8A8*/1,-1);
  16303. ret._mgrKey=key;
  16304. return ret;
  16305. }
  16306. WebGLRTMgr.releaseRT=function(rt){
  16307. if (rt._mgrKey <=0)
  16308. return;
  16309. var sw=WebGLRTMgr.dict[rt._mgrKey];
  16310. !sw && (sw=[],WebGLRTMgr.dict[rt._mgrKey]=sw);
  16311. rt._mgrKey=0;
  16312. sw.push(rt);
  16313. }
  16314. WebGLRTMgr.dict={};
  16315. return WebGLRTMgr;
  16316. })()
  16317. /**
  16318. *<code>Utils</code> 是工具类。
  16319. */
  16320. //class laya.utils.Utils
  16321. var Utils=(function(){
  16322. function Utils(){}
  16323. __class(Utils,'laya.utils.Utils');
  16324. Utils.toRadian=function(angle){
  16325. return angle *Utils._pi2;
  16326. }
  16327. Utils.toAngle=function(radian){
  16328. return radian *Utils._pi;
  16329. }
  16330. Utils.toHexColor=function(color){
  16331. if (color < 0 || isNaN(color))return null;
  16332. var str=color.toString(16);
  16333. while (str.length < 6)str="0"+str;
  16334. return "#"+str;
  16335. }
  16336. Utils.getGID=function(){
  16337. return Utils._gid++;
  16338. }
  16339. Utils.concatArray=function(source,array){
  16340. if (!array)return source;
  16341. if (!source)return array;
  16342. var i=0,len=array.length;
  16343. for (i=0;i < len;i++){
  16344. source.push(array[i]);
  16345. }
  16346. return source;
  16347. }
  16348. Utils.clearArray=function(array){
  16349. if (!array)return array;
  16350. array.length=0;
  16351. return array;
  16352. }
  16353. Utils.copyArray=function(source,array){
  16354. source || (source=[]);
  16355. if (!array)return source;
  16356. source.length=array.length;
  16357. var i=0,len=array.length;
  16358. for (i=0;i < len;i++){
  16359. source[i]=array[i];
  16360. }
  16361. return source;
  16362. }
  16363. Utils.getGlobalRecByPoints=function(sprite,x0,y0,x1,y1){
  16364. var newLTPoint;
  16365. newLTPoint=Point.create().setTo(x0,y0);
  16366. newLTPoint=sprite.localToGlobal(newLTPoint);
  16367. var newRBPoint;
  16368. newRBPoint=Point.create().setTo(x1,y1);
  16369. newRBPoint=sprite.localToGlobal(newRBPoint);
  16370. var rst=Rectangle._getWrapRec([newLTPoint.x,newLTPoint.y,newRBPoint.x,newRBPoint.y]);
  16371. newLTPoint.recover();
  16372. newRBPoint.recover();
  16373. return rst;
  16374. }
  16375. Utils.getGlobalPosAndScale=function(sprite){
  16376. return Utils.getGlobalRecByPoints(sprite,0,0,1,1);
  16377. }
  16378. Utils.bind=function(fun,scope){
  16379. var rst=fun;
  16380. /*__JS__ */rst=fun.bind(scope);;
  16381. return rst;
  16382. }
  16383. Utils.measureText=function(txt,font){
  16384. return RunDriver.measureText(txt,font);
  16385. }
  16386. Utils.updateOrder=function(array){
  16387. if (!array || array.length < 2)return false;
  16388. var i=1,j=0,len=array.length,key=NaN,c;
  16389. while (i < len){
  16390. j=i;
  16391. c=array[j];
  16392. key=array[j]._zOrder;
  16393. while (--j >-1){
  16394. if (array[j]._zOrder > key)array[j+1]=array[j];
  16395. else break ;
  16396. }
  16397. array[j+1]=c;
  16398. i++;
  16399. }
  16400. return true;
  16401. }
  16402. Utils.transPointList=function(points,x,y){
  16403. var i=0,len=points.length;
  16404. for (i=0;i < len;i+=2){
  16405. points[i]+=x;
  16406. points[i+1]+=y;
  16407. }
  16408. }
  16409. Utils.parseInt=function(str,radix){
  16410. (radix===void 0)&& (radix=0);
  16411. var result=Browser.window.parseInt(str,radix);
  16412. if (isNaN(result))return 0;
  16413. return result;
  16414. }
  16415. Utils.getFileExtension=function(path){
  16416. Utils._extReg.lastIndex=path.lastIndexOf(".");
  16417. var result=Utils._extReg.exec(path);
  16418. if (result && result.length > 1){
  16419. return result[1].toLowerCase();
  16420. }
  16421. return null;
  16422. }
  16423. Utils.getTransformRelativeToWindow=function(coordinateSpace,x,y){
  16424. var stage=Laya.stage;
  16425. var globalTransform=laya.utils.Utils.getGlobalPosAndScale(coordinateSpace);
  16426. var canvasMatrix=stage._canvasTransform.clone();
  16427. var canvasLeft=canvasMatrix.tx;
  16428. var canvasTop=canvasMatrix.ty;
  16429. canvasMatrix.rotate(-Math.PI / 180 *Laya.stage.canvasDegree);
  16430. canvasMatrix.scale(Laya.stage.clientScaleX,Laya.stage.clientScaleY);
  16431. var perpendicular=(Laya.stage.canvasDegree % 180 !=0);
  16432. var tx=NaN,ty=NaN;
  16433. if (perpendicular){
  16434. tx=y+globalTransform.y;
  16435. ty=x+globalTransform.x;
  16436. tx *=canvasMatrix.d;
  16437. ty *=canvasMatrix.a;
  16438. if (Laya.stage.canvasDegree==90){
  16439. tx=canvasLeft-tx;
  16440. ty+=canvasTop;
  16441. }
  16442. else {
  16443. tx+=canvasLeft;
  16444. ty=canvasTop-ty;
  16445. }
  16446. }
  16447. else {
  16448. tx=x+globalTransform.x;
  16449. ty=y+globalTransform.y;
  16450. tx *=canvasMatrix.a;
  16451. ty *=canvasMatrix.d;
  16452. tx+=canvasLeft;
  16453. ty+=canvasTop;
  16454. }
  16455. ty+=Laya.stage['_safariOffsetY'];
  16456. var domScaleX=NaN,domScaleY=NaN;
  16457. if (perpendicular){
  16458. domScaleX=canvasMatrix.d *globalTransform.height;
  16459. domScaleY=canvasMatrix.a *globalTransform.width;
  16460. }else {
  16461. domScaleX=canvasMatrix.a *globalTransform.width;
  16462. domScaleY=canvasMatrix.d *globalTransform.height;
  16463. }
  16464. return {x:tx,y:ty,scaleX:domScaleX,scaleY:domScaleY};
  16465. }
  16466. Utils.fitDOMElementInArea=function(dom,coordinateSpace,x,y,width,height){
  16467. if (!dom._fitLayaAirInitialized){
  16468. dom._fitLayaAirInitialized=true;
  16469. dom.style.transformOrigin=dom.style.webKittransformOrigin="left top";
  16470. dom.style.position="absolute"
  16471. };
  16472. var transform=Utils.getTransformRelativeToWindow(coordinateSpace,x,y);
  16473. dom.style.transform=dom.style.webkitTransform="scale("+transform.scaleX+","+transform.scaleY+") rotate("+(Laya.stage.canvasDegree)+"deg)";
  16474. dom.style.width=width+'px';
  16475. dom.style.height=height+'px';
  16476. dom.style.left=transform.x+'px';
  16477. dom.style.top=transform.y+'px';
  16478. }
  16479. Utils.isOkTextureList=function(textureList){
  16480. if (!textureList)return false;
  16481. var i=0,len=textureList.length;
  16482. var tTexture;
  16483. for (i=0;i < len;i++){
  16484. tTexture=textureList[i];
  16485. if (!tTexture || !tTexture._getSource())return false;
  16486. }
  16487. return true;
  16488. }
  16489. Utils.isOKCmdList=function(cmds){
  16490. if (!cmds)return false;
  16491. var i=0,len=cmds.length;
  16492. var cmd;
  16493. var tex;
  16494. for (i=0;i < len;i++){
  16495. cmd=cmds[i];
  16496. }
  16497. return true;
  16498. }
  16499. Utils.getQueryString=function(name){
  16500. if (Browser.onMiniGame)return null;
  16501. if(!window.location || !window.location.search)
  16502. return null;
  16503. var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
  16504. var r=window.location.search.substr(1).match(reg);
  16505. if (r !=null)return unescape(r[2]);
  16506. return null;
  16507. }
  16508. Utils._gid=1;
  16509. Utils._pi=180 / Math.PI;
  16510. Utils._pi2=Math.PI / 180;
  16511. Utils._extReg=/\.(\w+)\??/g;
  16512. Utils.parseXMLFromString=function(value){
  16513. var rst;
  16514. value=value.replace(/>\s+</g,'><');
  16515. /*__JS__ */rst=(new DOMParser()).parseFromString(value,'text/xml');
  16516. if (rst.firstChild.textContent.indexOf("This page contains the following errors")>-1){
  16517. throw new Error(rst.firstChild.firstChild.textContent);
  16518. }
  16519. return rst;
  16520. }
  16521. return Utils;
  16522. })()
  16523. /**
  16524. *Javascript Arabic Reshaper by Louy Alakkad
  16525. *https://github.com/louy/Javascript-Arabic-Reshaper
  16526. *Based on (http://git.io/vsnAd)
  16527. */
  16528. //class laya.webgl.text.ArabicReshaper
  16529. var ArabicReshaper=(function(){
  16530. function ArabicReshaper(){}
  16531. __class(ArabicReshaper,'laya.webgl.text.ArabicReshaper');
  16532. var __proto=ArabicReshaper.prototype;
  16533. //TODO:coverage
  16534. __proto.characterMapContains=function(c){
  16535. for (var i=0;i < ArabicReshaper.charsMap.length;++i){
  16536. if (ArabicReshaper.charsMap[ i][0]===c){
  16537. return true;
  16538. }
  16539. }
  16540. return false;
  16541. }
  16542. //TODO:coverage
  16543. __proto.getCharRep=function(c){
  16544. for (var i=0;i < ArabicReshaper.charsMap.length;++i){
  16545. if (ArabicReshaper.charsMap[ i][0]===c){
  16546. return ArabicReshaper.charsMap[i];
  16547. }
  16548. }
  16549. return false;
  16550. }
  16551. //TODO:coverage
  16552. __proto.getCombCharRep=function(c1,c2){
  16553. for (var i=0;i < ArabicReshaper.combCharsMap.length;++i){
  16554. if (ArabicReshaper.combCharsMap[i][0][0]===c1 && ArabicReshaper.combCharsMap[i][0][1]===c2){
  16555. return ArabicReshaper.combCharsMap[i];
  16556. }
  16557. }
  16558. return false;
  16559. }
  16560. //TODO:coverage
  16561. __proto.isTransparent=function(c){
  16562. for (var i=0;i < ArabicReshaper.transChars.length;++i){
  16563. if (ArabicReshaper.transChars[i]===c){
  16564. return true;
  16565. }
  16566. }
  16567. return false;
  16568. }
  16569. //TODO:coverage
  16570. __proto.getOriginalCharsFromCode=function(code){
  16571. var j=0;
  16572. for (j=0;j < ArabicReshaper.charsMap.length;++j){
  16573. if (ArabicReshaper.charsMap[j].indexOf(code)>-1){
  16574. return String.fromCharCode(ArabicReshaper.charsMap[j][0]);
  16575. }
  16576. }
  16577. for (j=0;j < ArabicReshaper.combCharsMap.length;++j){
  16578. if (ArabicReshaper.combCharsMap[j].indexOf(code)>-1){
  16579. return String.fromCharCode(ArabicReshaper.combCharsMap[j][0][0])+
  16580. String.fromCharCode(ArabicReshaper.combCharsMap[j][0][1]);
  16581. }
  16582. }
  16583. return String.fromCharCode(code);
  16584. }
  16585. //TODO:coverage
  16586. __proto.convertArabic=function(normal){
  16587. var crep,
  16588. combcrep,
  16589. shaped='';
  16590. for (var i=0;i < normal.length;++i){
  16591. var current=normal.charCodeAt(i);
  16592. if (this.characterMapContains(current)){
  16593. var prev=null,
  16594. next=null,
  16595. prevID=i-1,
  16596. nextID=i+1;
  16597. for (;prevID >=0;--prevID){
  16598. if (!this.isTransparent(normal.charCodeAt(prevID))){
  16599. break ;
  16600. }
  16601. }
  16602. prev=(prevID >=0)? normal.charCodeAt(prevID):null;
  16603. crep=prev ? this.getCharRep(prev):false;
  16604. if (!crep || crep[2]==null && crep[3]==null){
  16605. prev=null;
  16606. }
  16607. for (;nextID < normal.length;++nextID){
  16608. if (!this.isTransparent(normal.charCodeAt(nextID))){
  16609. break ;
  16610. }
  16611. }
  16612. next=(nextID < normal.length)? normal.charCodeAt(nextID):null;
  16613. crep=next ? this.getCharRep(next):false;
  16614. if (!crep || crep[3]==null && crep[4]==null){
  16615. next=null;
  16616. }
  16617. if (current===0x0644 && next !=null &&
  16618. (next===0x0622 || next===0x0623 || next===0x0625 || next===0x0627)){
  16619. combcrep=this.getCombCharRep(current,next);
  16620. if (prev !=null){
  16621. shaped+=String.fromCharCode(combcrep[4]);
  16622. }else {
  16623. shaped+=String.fromCharCode(combcrep[1]);
  16624. }
  16625. ++i;
  16626. continue ;
  16627. }
  16628. crep=this.getCharRep(current);
  16629. if (prev !=null && next !=null && crep[3] !=null){
  16630. shaped+=String.fromCharCode(crep[3]);
  16631. continue ;
  16632. }else
  16633. if (prev !=null && crep[4] !=null){
  16634. shaped+=String.fromCharCode(crep[4]);
  16635. continue ;
  16636. }else
  16637. if (next !=null && crep[2] !=null){
  16638. shaped+=String.fromCharCode(crep[2]);
  16639. continue ;
  16640. }else {
  16641. shaped+=String.fromCharCode(crep[1]);
  16642. }
  16643. }else {
  16644. shaped+=String.fromCharCode(current);
  16645. }
  16646. }
  16647. return shaped;
  16648. }
  16649. //TODO:coverage
  16650. __proto.convertArabicBack=function(apfb){
  16651. var toReturn='',
  16652. selectedChar=0;
  16653. var i=0;
  16654. for (i=0;i < apfb.length;++i){
  16655. selectedChar=apfb.charCodeAt(i);
  16656. toReturn+=this.getOriginalCharsFromCode(selectedChar);
  16657. }
  16658. return toReturn;
  16659. }
  16660. __static(ArabicReshaper,
  16661. ['charsMap',function(){return this.charsMap=[
  16662. [0x0621,0xFE80,null,null,null],
  16663. [0x0622,0xFE81,null,null,0xFE82],
  16664. [0x0623,0xFE83,null,null,0xFE84],
  16665. [0x0624,0xFE85,null,null,0xFE86],
  16666. [0x0625,0xFE87,null,null,0xFE88],
  16667. [0x0626,0xFE89,0xFE8B,0xFE8C,0xFE8A],
  16668. [0x0627,0xFE8D,null,null,0xFE8E],
  16669. [0x0628,0xFE8F,0xFE91,0xFE92,0xFE90],
  16670. [0x0629,0xFE93,null,null,0xFE94],
  16671. [0x062A,0xFE95,0xFE97,0xFE98,0xFE96],
  16672. [0x062B,0xFE99,0xFE9B,0xFE9C,0xFE9A],
  16673. [0x062C,0xFE9D,0xFE9F,0xFEA0,0xFE9E],
  16674. [0x062D,0xFEA1,0xFEA3,0xFEA4,0xFEA2],
  16675. [0x062E,0xFEA5,0xFEA7,0xFEA8,0xFEA6],
  16676. [0x062F,0xFEA9,null,null,0xFEAA],
  16677. [0x0630,0xFEAB,null,null,0xFEAC],
  16678. [0x0631,0xFEAD,null,null,0xFEAE],
  16679. [0x0632,0xFEAF,null,null,0xFEB0],
  16680. [0x0633,0xFEB1,0xFEB3,0xFEB4,0xFEB2],
  16681. [0x0634,0xFEB5,0xFEB7,0xFEB8,0xFEB6],
  16682. [0x0635,0xFEB9,0xFEBB,0xFEBC,0xFEBA],
  16683. [0x0636,0xFEBD,0xFEBF,0xFEC0,0xFEBE],
  16684. [0x0637,0xFEC1,0xFEC3,0xFEC4,0xFEC2],
  16685. [0x0638,0xFEC5,0xFEC7,0xFEC8,0xFEC6],
  16686. [0x0639,0xFEC9,0xFECB,0xFECC,0xFECA],
  16687. [0x063A,0xFECD,0xFECF,0xFED0,0xFECE],
  16688. [0x0640,0x0640,0x0640,0x0640,0x0640],
  16689. [0x0641,0xFED1,0xFED3,0xFED4,0xFED2],
  16690. [0x0642,0xFED5,0xFED7,0xFED8,0xFED6],
  16691. [0x0643,0xFED9,0xFEDB,0xFEDC,0xFEDA],
  16692. [0x0644,0xFEDD,0xFEDF,0xFEE0,0xFEDE],
  16693. [0x0645,0xFEE1,0xFEE3,0xFEE4,0xFEE2],
  16694. [0x0646,0xFEE5,0xFEE7,0xFEE8,0xFEE6],
  16695. [0x0647,0xFEE9,0xFEEB,0xFEEC,0xFEEA],
  16696. [0x0648,0xFEED,null,null,0xFEEE],
  16697. [0x0649,0xFEEF,null,null,0xFEF0],
  16698. [0x064A,0xFEF1,0xFEF3,0xFEF4,0xFEF2],
  16699. [0x067E,0xFB56,0xFB58,0xFB59,0xFB57],
  16700. [0x06CC,0xFBFC,0xFBFE,0xFBFF,0xFBFD],
  16701. [0x0686,0xFB7A,0xFB7C,0xFB7D,0xFB7B],
  16702. [0x06A9,0xFB8E,0xFB90,0xFB91,0xFB8F],
  16703. [0x06AF,0xFB92,0xFB94,0xFB95,0xFB93],
  16704. [0x0698,0xFB8A,null,null,0xFB8B],];},'combCharsMap',function(){return this.combCharsMap=[
  16705. [[0x0644,0x0622],0xFEF5,null,null,0xFEF6],
  16706. [[0x0644,0x0623],0xFEF7,null,null,0xFEF8],
  16707. [[0x0644,0x0625],0xFEF9,null,null,0xFEFA],
  16708. [[0x0644,0x0627],0xFEFB,null,null,0xFEFC],];},'transChars',function(){return this.transChars=[
  16709. 0x0610,
  16710. 0x0612,
  16711. 0x0613,
  16712. 0x0614,
  16713. 0x0615,
  16714. 0x064B,
  16715. 0x064C,
  16716. 0x064D,
  16717. 0x064E,
  16718. 0x064F,
  16719. 0x0650,
  16720. 0x0651,
  16721. 0x0652,
  16722. 0x0653,
  16723. 0x0654,
  16724. 0x0655,
  16725. 0x0656,
  16726. 0x0657,
  16727. 0x0658,
  16728. 0x0670,
  16729. 0x06D6,
  16730. 0x06D7,
  16731. 0x06D8,
  16732. 0x06D9,
  16733. 0x06DA,
  16734. 0x06DB,
  16735. 0x06DC,
  16736. 0x06DF,
  16737. 0x06E0,
  16738. 0x06E1,
  16739. 0x06E2,
  16740. 0x06E3,
  16741. 0x06E4,
  16742. 0x06E7,
  16743. 0x06E8,
  16744. 0x06EA,
  16745. 0x06EB,
  16746. 0x06EC,
  16747. 0x06ED,];}
  16748. ]);
  16749. return ArabicReshaper;
  16750. })()
  16751. /**
  16752. *绘制连续曲线
  16753. */
  16754. //class laya.display.cmd.DrawLinesCmd
  16755. var DrawLinesCmd=(function(){
  16756. function DrawLinesCmd(){
  16757. /**
  16758. *开始绘制的X轴位置。
  16759. */
  16760. //this.x=NaN;
  16761. /**
  16762. *开始绘制的Y轴位置。
  16763. */
  16764. //this.y=NaN;
  16765. /**
  16766. *线段的点集合。格式:[x1,y1,x2,y2,x3,y3...]。
  16767. */
  16768. //this.points=null;
  16769. /**
  16770. *线段颜色,或者填充绘图的渐变对象。
  16771. */
  16772. //this.lineColor=null;
  16773. /**
  16774. *(可选)线段宽度。
  16775. */
  16776. //this.lineWidth=NaN;
  16777. /**@private */
  16778. //this.vid=0;
  16779. }
  16780. __class(DrawLinesCmd,'laya.display.cmd.DrawLinesCmd');
  16781. var __proto=DrawLinesCmd.prototype;
  16782. /**
  16783. *回收到对象池
  16784. */
  16785. __proto.recover=function(){
  16786. this.points=null;
  16787. this.lineColor=null;
  16788. Pool.recover("DrawLinesCmd",this);
  16789. }
  16790. /**@private */
  16791. __proto.run=function(context,gx,gy){
  16792. context._drawLines(this.x+gx,this.y+gy,this.points,this.lineColor,this.lineWidth,this.vid);
  16793. }
  16794. /**@private */
  16795. __getset(0,__proto,'cmdID',function(){
  16796. return "DrawLines";
  16797. });
  16798. DrawLinesCmd.create=function(x,y,points,lineColor,lineWidth,vid){
  16799. var cmd=Pool.getItemByClass("DrawLinesCmd",DrawLinesCmd);
  16800. cmd.x=x;
  16801. cmd.y=y;
  16802. cmd.points=points;
  16803. cmd.lineColor=lineColor;
  16804. cmd.lineWidth=lineWidth;
  16805. cmd.vid=vid;
  16806. return cmd;
  16807. }
  16808. DrawLinesCmd.ID="DrawLines";
  16809. return DrawLinesCmd;
  16810. })()
  16811. /**
  16812. *...
  16813. *@author laoxie
  16814. */
  16815. //class laya.webgl.text.CharSubmitCache
  16816. var CharSubmitCache=(function(){
  16817. function CharSubmitCache(){
  16818. this._data=[];
  16819. this._ndata=0;
  16820. this._tex=null;
  16821. this._imgId=0;
  16822. this._clipid=-1;
  16823. this._enbale=false;
  16824. this._colorFiler=null;
  16825. this._clipMatrix=new Matrix();
  16826. }
  16827. __class(CharSubmitCache,'laya.webgl.text.CharSubmitCache');
  16828. var __proto=CharSubmitCache.prototype;
  16829. __proto.clear=function(){
  16830. this._tex=null;
  16831. this._imgId=-1;
  16832. this._ndata=0;
  16833. this._enbale=false;
  16834. this._colorFiler=null;
  16835. }
  16836. __proto.destroy=function(){
  16837. this.clear();
  16838. this._data.length=0;
  16839. this._data=null;
  16840. }
  16841. __proto.add=function(ctx,tex,imgid,pos,uv,color){
  16842. if (this._ndata > 0 && (this._tex !=tex || this._imgId !=imgid ||
  16843. (this._clipid>=0 && this._clipid!=ctx._clipInfoID))){
  16844. this.submit(ctx);
  16845. }
  16846. this._clipid=ctx._clipInfoID;
  16847. ctx._globalClipMatrix.copyTo(this._clipMatrix);
  16848. this._tex=tex;
  16849. this._imgId=imgid;
  16850. this._colorFiler=ctx._colorFiler;
  16851. this._data[this._ndata]=pos;
  16852. this._data[this._ndata+1]=uv;
  16853. this._data[this._ndata+2]=color;
  16854. this._ndata+=3;
  16855. }
  16856. __proto.getPos=function(){
  16857. if (CharSubmitCache.__nPosPool==0)
  16858. return new Array(8);
  16859. return CharSubmitCache.__posPool[--CharSubmitCache.__nPosPool];
  16860. }
  16861. __proto.enable=function(value,ctx){
  16862. if (value===this._enbale)
  16863. return;
  16864. this._enbale=value;
  16865. this._enbale || this.submit(ctx);
  16866. }
  16867. __proto.submit=function(ctx){
  16868. var n=this._ndata;
  16869. if (!n)
  16870. return;
  16871. var _mesh=ctx._mesh;
  16872. var colorFiler=ctx._colorFiler;
  16873. ctx._colorFiler=this._colorFiler;
  16874. var submit=SubmitTexture.create(ctx,_mesh ,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0));
  16875. ctx._submits[ctx._submits._length++]=ctx._curSubmit=submit;
  16876. submit.shaderValue.textureHost=this._tex;
  16877. submit._key.other=this._imgId;
  16878. ctx._colorFiler=colorFiler;
  16879. ctx._copyClipInfo(submit,this._clipMatrix);
  16880. submit.clipInfoID=this._clipid;
  16881. for (var i=0;i < n;i+=3){
  16882. _mesh.addQuad(this._data[i],this._data[i+1] ,this._data [i+2],true);
  16883. CharSubmitCache.__posPool[CharSubmitCache.__nPosPool++]=this._data[i];
  16884. }
  16885. n /=3;
  16886. submit._numEle+=n*6;
  16887. _mesh.indexNum+=n*6;
  16888. _mesh.vertNum+=n*4;
  16889. ctx._drawCount+=n;
  16890. this._ndata=0;
  16891. if (Stat.loopCount % 100==0)
  16892. this._data.length=0;
  16893. }
  16894. CharSubmitCache.__posPool=[];
  16895. CharSubmitCache.__nPosPool=0;
  16896. return CharSubmitCache;
  16897. })()
  16898. /**
  16899. *Config 用于配置一些全局参数。如需更改,请在初始化引擎之前设置。
  16900. */
  16901. //class Config
  16902. var Config=(function(){
  16903. function Config(){}
  16904. __class(Config,'Config');
  16905. Config.animationInterval=50;
  16906. Config.isAntialias=false;
  16907. Config.isAlpha=false;
  16908. Config.premultipliedAlpha=true;
  16909. Config.isStencil=true;
  16910. Config.preserveDrawingBuffer=false;
  16911. Config.webGL2D_MeshAllocMaxMem=true;
  16912. Config.is2DPixelArtGame=false;
  16913. Config.useWebGL2=false;
  16914. Config.useRetinalCanvas=false;
  16915. return Config;
  16916. })()
  16917. /**
  16918. *绘制曲线
  16919. */
  16920. //class laya.display.cmd.DrawCurvesCmd
  16921. var DrawCurvesCmd=(function(){
  16922. function DrawCurvesCmd(){
  16923. /**
  16924. *开始绘制的 X 轴位置。
  16925. */
  16926. //this.x=NaN;
  16927. /**
  16928. *开始绘制的 Y 轴位置。
  16929. */
  16930. //this.y=NaN;
  16931. /**
  16932. *线段的点集合,格式[controlX,controlY,anchorX,anchorY...]。
  16933. */
  16934. //this.points=null;
  16935. /**
  16936. *线段颜色,或者填充绘图的渐变对象。
  16937. */
  16938. //this.lineColor=null;
  16939. /**
  16940. *(可选)线段宽度。
  16941. */
  16942. //this.lineWidth=NaN;
  16943. }
  16944. __class(DrawCurvesCmd,'laya.display.cmd.DrawCurvesCmd');
  16945. var __proto=DrawCurvesCmd.prototype;
  16946. /**
  16947. *回收到对象池
  16948. */
  16949. __proto.recover=function(){
  16950. this.points=null;
  16951. this.lineColor=null;
  16952. Pool.recover("DrawCurvesCmd",this);
  16953. }
  16954. /**@private */
  16955. __proto.run=function(context,gx,gy){
  16956. context.drawCurves(this.x+gx,this.y+gy,this.points,this.lineColor,this.lineWidth);
  16957. }
  16958. /**@private */
  16959. __getset(0,__proto,'cmdID',function(){
  16960. return "DrawCurves";
  16961. });
  16962. DrawCurvesCmd.create=function(x,y,points,lineColor,lineWidth){
  16963. var cmd=Pool.getItemByClass("DrawCurvesCmd",DrawCurvesCmd);
  16964. cmd.x=x;
  16965. cmd.y=y;
  16966. cmd.points=points;
  16967. cmd.lineColor=lineColor;
  16968. cmd.lineWidth=lineWidth;
  16969. return cmd;
  16970. }
  16971. DrawCurvesCmd.ID="DrawCurves";
  16972. return DrawCurvesCmd;
  16973. })()
  16974. /**
  16975. *绘制文字
  16976. */
  16977. //class laya.display.cmd.FillTextCmd
  16978. var FillTextCmd=(function(){
  16979. function FillTextCmd(){
  16980. //this._text=null;
  16981. /**@private */
  16982. this._textIsWorldText=false;
  16983. /**
  16984. *开始绘制文本的 x 坐标位置(相对于画布)。
  16985. */
  16986. //this.x=NaN;
  16987. /**
  16988. *开始绘制文本的 y 坐标位置(相对于画布)。
  16989. */
  16990. //this.y=NaN;
  16991. //this._font=null;
  16992. //this._color=null;
  16993. //this._textAlign=null;
  16994. this._fontColor=0xffffffff;
  16995. this._strokeColor=0;
  16996. this._nTexAlign=0;
  16997. this._fontObj=FillTextCmd._defFontObj;
  16998. }
  16999. __class(FillTextCmd,'laya.display.cmd.FillTextCmd');
  17000. var __proto=FillTextCmd.prototype;
  17001. /**
  17002. *回收到对象池
  17003. */
  17004. __proto.recover=function(){
  17005. Pool.recover("FillTextCmd",this);
  17006. }
  17007. /**@private */
  17008. __proto.run=function(context,gx,gy){
  17009. if(Laya.stage.isGlobalRepaint()){
  17010. this._textIsWorldText && (this._text).cleanCache();
  17011. }
  17012. if (this._textIsWorldText){
  17013. context._fast_filltext((this._text),this.x+gx,this.y+gy,this._fontObj,this._color,null,0,this._nTexAlign,0);
  17014. }else {
  17015. context.drawText(this._text,this.x+gx,this.y+gy,this._font,this._color,this._textAlign);
  17016. }
  17017. }
  17018. /**
  17019. *在画布上输出的文本。
  17020. */
  17021. __getset(0,__proto,'text',function(){
  17022. return this._text;
  17023. },function(value){
  17024. this._text=value;
  17025. this._textIsWorldText=(value instanceof laya.utils.WordText );
  17026. this._textIsWorldText && (this._text).cleanCache();
  17027. });
  17028. /**@private */
  17029. __getset(0,__proto,'cmdID',function(){
  17030. return "FillText";
  17031. });
  17032. /**
  17033. *定义文本颜色,比如"#ff0000"。
  17034. */
  17035. __getset(0,__proto,'color',function(){
  17036. return this._color;
  17037. },function(value){
  17038. this._color=value;
  17039. this._fontColor=ColorUtils.create(value).numColor;
  17040. this._textIsWorldText && (this._text).cleanCache();
  17041. });
  17042. /**
  17043. *定义字号和字体,比如"20px Arial"。
  17044. */
  17045. __getset(0,__proto,'font',function(){
  17046. return this._font;
  17047. },function(value){
  17048. this._font=value;
  17049. this._fontObj=FontInfo.Parse(value);
  17050. this._textIsWorldText && (this._text).cleanCache();
  17051. });
  17052. /**
  17053. *文本对齐方式,可选值:"left","center","right"。
  17054. */
  17055. __getset(0,__proto,'textAlign',function(){
  17056. return this._textAlign;
  17057. },function(value){
  17058. this._textAlign=value;
  17059. switch (value){
  17060. case 'center':
  17061. this._nTexAlign=Context.ENUM_TEXTALIGN_CENTER;
  17062. break ;
  17063. case 'right':
  17064. this._nTexAlign=Context.ENUM_TEXTALIGN_RIGHT;
  17065. break ;
  17066. default :
  17067. this._nTexAlign=Context.ENUM_TEXTALIGN_DEFAULT;
  17068. }
  17069. this._textIsWorldText && (this._text).cleanCache();
  17070. });
  17071. FillTextCmd.create=function(text,x,y,font,color,textAlign){
  17072. var cmd=Pool.getItemByClass("FillTextCmd",FillTextCmd);
  17073. cmd.text=text;
  17074. cmd._textIsWorldText=(text instanceof laya.utils.WordText );
  17075. cmd.x=x;
  17076. cmd.y=y;
  17077. cmd.font=font;
  17078. cmd.color=color;
  17079. cmd.textAlign=textAlign;
  17080. return cmd;
  17081. }
  17082. FillTextCmd.ID="FillText";
  17083. __static(FillTextCmd,
  17084. ['_defFontObj',function(){return this._defFontObj=new FontInfo(null);}
  17085. ]);
  17086. return FillTextCmd;
  17087. })()
  17088. //class laya.webgl.shader.ShaderValue
  17089. var ShaderValue=(function(){
  17090. function ShaderValue(){}
  17091. __class(ShaderValue,'laya.webgl.shader.ShaderValue');
  17092. return ShaderValue;
  17093. })()
  17094. /**
  17095. *<p><code>KeyLocation</code> 类包含表示在键盘或类似键盘的输入设备上按键位置的常量。</p>
  17096. *<p><code>KeyLocation</code> 常数用在键盘事件对象的 <code>keyLocation </code>属性中。</p>
  17097. */
  17098. //class laya.events.KeyLocation
  17099. var KeyLocation=(function(){
  17100. function KeyLocation(){}
  17101. __class(KeyLocation,'laya.events.KeyLocation');
  17102. KeyLocation.STANDARD=0;
  17103. KeyLocation.LEFT=1;
  17104. KeyLocation.RIGHT=2;
  17105. KeyLocation.NUM_PAD=3;
  17106. return KeyLocation;
  17107. })()
  17108. //class laya.webgl.canvas.save.SaveClipRect
  17109. var SaveClipRect=(function(){
  17110. function SaveClipRect(){
  17111. this._clipInfoID=-1;
  17112. this.incache=false;
  17113. this._globalClipMatrix=new Matrix();
  17114. this._clipRect=new Rectangle();
  17115. }
  17116. __class(SaveClipRect,'laya.webgl.canvas.save.SaveClipRect');
  17117. var __proto=SaveClipRect.prototype;
  17118. Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true})
  17119. __proto.isSaveMark=function(){return false;}
  17120. __proto.restore=function(context){
  17121. this._globalClipMatrix.copyTo(context._globalClipMatrix);
  17122. this._clipRect.clone(context._clipRect);
  17123. context._clipInfoID=this._clipInfoID;
  17124. SaveClipRect.POOL[SaveClipRect.POOL._length++]=this;
  17125. context._clipInCache=this.incache;
  17126. }
  17127. SaveClipRect.save=function(context){
  17128. if ((context._saveMark._saveuse & /*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT*/0x20000)==/*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT*/0x20000)return;
  17129. context._saveMark._saveuse |=/*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT*/0x20000;
  17130. var cache=SaveClipRect.POOL;
  17131. var o=cache._length > 0 ? cache[--cache._length] :(new SaveClipRect());
  17132. context._globalClipMatrix.copyTo(o._globalClipMatrix);
  17133. context._clipRect.clone(o._clipRect);
  17134. o._clipInfoID=context._clipInfoID;
  17135. o.incache=context._clipInCache;
  17136. var _save=context._save;
  17137. _save[_save._length++]=o;
  17138. }
  17139. SaveClipRect.POOL=SaveBase._createArray();
  17140. return SaveClipRect;
  17141. })()
  17142. /**
  17143. *@private
  17144. */
  17145. //class laya.filters.GlowFilterGLRender
  17146. var GlowFilterGLRender=(function(){
  17147. function GlowFilterGLRender(){}
  17148. __class(GlowFilterGLRender,'laya.filters.GlowFilterGLRender');
  17149. var __proto=GlowFilterGLRender.prototype;
  17150. __proto.setShaderInfo=function(shader,w,h,data){
  17151. shader.defines.add(data.type);
  17152. var sv=shader;
  17153. sv.u_blurInfo1=data._sv_blurInfo1;
  17154. var info2=data._sv_blurInfo2;
  17155. info2[0]=w;info2[1]=h;
  17156. sv.u_blurInfo2=info2;
  17157. sv.u_color=data.getColor();
  17158. }
  17159. __proto.render=function(rt,ctx,width,height,filter){
  17160. var w=width,h=height;
  17161. var svBlur=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  17162. this.setShaderInfo(svBlur,w,h,filter);
  17163. var svCP=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
  17164. var matI=Matrix.TEMP.identity();
  17165. ctx.drawTarget(rt,0,0,w,h,matI,svBlur);
  17166. ctx.drawTarget(rt,0,0,w,h,matI,svCP);
  17167. }
  17168. return GlowFilterGLRender;
  17169. })()
  17170. /**
  17171. *@private
  17172. */
  17173. //class laya.utils.RunDriver
  17174. var RunDriver=(function(){
  17175. function RunDriver(){}
  17176. __class(RunDriver,'laya.utils.RunDriver');
  17177. RunDriver.createShaderCondition=function(conditionScript){
  17178. var fn="(function() {return "+conditionScript+";})";
  17179. return Laya._runScript(fn);
  17180. }
  17181. RunDriver.fontMap=[];
  17182. RunDriver.measureText=function(txt,font){
  17183. var isChinese=RunDriver.hanzi.test(txt);
  17184. if (isChinese && RunDriver.fontMap[font]){
  17185. return RunDriver.fontMap[font];
  17186. };
  17187. var ctx=Browser.context;
  17188. ctx.font=font;
  17189. var r=ctx.measureText(txt);
  17190. if (isChinese)RunDriver.fontMap[font]=r;
  17191. return r;
  17192. }
  17193. RunDriver.drawToCanvas=function(sprite,_renderType,canvasWidth,canvasHeight,offsetX,offsetY){
  17194. offsetX-=sprite.x;
  17195. offsetY-=sprite.y;
  17196. offsetX |=0;
  17197. offsetY |=0;
  17198. canvasWidth |=0;
  17199. canvasHeight |=0;
  17200. var ctx=new Context();
  17201. ctx.size(canvasWidth,canvasHeight);
  17202. ctx.asBitmap=true;
  17203. ctx._targets.start();
  17204. RenderSprite.renders[_renderType]._fun(sprite,ctx,offsetX,offsetY);
  17205. ctx.flush();
  17206. ctx._targets.end();
  17207. ctx._targets.restore();
  17208. var dt=ctx._targets.getData(0,0,canvasWidth,canvasHeight);
  17209. ctx.destroy();
  17210. var imgdata=/*__JS__ */new ImageData(canvasWidth,canvasHeight);;
  17211. var lineLen=canvasWidth *4;
  17212. var temp=new Uint8Array(lineLen);
  17213. var dst=imgdata.data;
  17214. var y=canvasHeight-1;
  17215. var off=y *lineLen;
  17216. var srcoff=0;
  17217. for (;y >=0;y--){
  17218. dst.set(dt.subarray(srcoff,srcoff+lineLen),off);
  17219. off-=lineLen;
  17220. srcoff+=lineLen;
  17221. };
  17222. var canv=new HTMLCanvas(true);
  17223. canv.size(canvasWidth,canvasHeight);
  17224. var ctx2d=canv.getContext('2d');
  17225. /*__JS__ */ctx2d.putImageData(imgdata,0,0);;
  17226. return canv;
  17227. }
  17228. RunDriver.drawToTexture=function(sprite,_renderType,canvasWidth,canvasHeight,offsetX,offsetY){
  17229. offsetX-=sprite.x;
  17230. offsetY-=sprite.y;
  17231. offsetX |=0;
  17232. offsetY |=0;
  17233. canvasWidth |=0;
  17234. canvasHeight |=0;
  17235. var ctx=new Context();
  17236. ctx.size(canvasWidth,canvasHeight);
  17237. ctx.asBitmap=true;
  17238. ctx._targets.start();
  17239. RenderSprite.renders[_renderType]._fun(sprite,ctx,offsetX,offsetY);
  17240. ctx.flush();
  17241. ctx._targets.end();
  17242. ctx._targets.restore();
  17243. var rtex=new Texture((ctx._targets),Texture.INV_UV);
  17244. ctx.destroy(true);
  17245. return rtex;
  17246. }
  17247. RunDriver.changeWebGLSize=function(w,h){
  17248. WebGL.onStageResize(w,h);
  17249. }
  17250. RunDriver.clear=function(value){
  17251. Context.set2DRenderConfig();
  17252. RenderState2D.worldScissorTest && WebGL.mainContext.disable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11);
  17253. var ctx=Render.context;
  17254. var c=(ctx._submits._length==0 || Config.preserveDrawingBuffer)? ColorUtils.create(value).arrColor :Laya.stage._wgColor;
  17255. if (c)
  17256. ctx.clearBG(c[0],c[1],c[2],c[3]);
  17257. else
  17258. ctx.clearBG(0,0,0,0);
  17259. RenderState2D.clear();
  17260. }
  17261. RunDriver.enableNative=null;
  17262. __static(RunDriver,
  17263. ['hanzi',function(){return this.hanzi=new RegExp("^[\u4E00-\u9FA5]$");}
  17264. ]);
  17265. return RunDriver;
  17266. })()
  17267. /**
  17268. *@private
  17269. */
  17270. //class laya.net.AtlasInfoManager
  17271. var AtlasInfoManager=(function(){
  17272. function AtlasInfoManager(){}
  17273. __class(AtlasInfoManager,'laya.net.AtlasInfoManager');
  17274. AtlasInfoManager.enable=function(infoFile,callback){
  17275. Laya.loader.load(infoFile,Handler.create(null,AtlasInfoManager._onInfoLoaded,[callback]),null,/*laya.net.Loader.JSON*/"json");
  17276. }
  17277. AtlasInfoManager._onInfoLoaded=function(callback,data){
  17278. var tKey;
  17279. var tPrefix;
  17280. var tArr;
  17281. var i=0,len=0;
  17282. for (tKey in data){
  17283. tArr=data[tKey];
  17284. tPrefix=tArr[0];
  17285. tArr=tArr[1];
  17286. len=tArr.length;
  17287. for (i=0;i < len;i++){
  17288. AtlasInfoManager._fileLoadDic[tPrefix+tArr[i]]=tKey;
  17289. }
  17290. }
  17291. callback && callback.run();
  17292. }
  17293. AtlasInfoManager.getFileLoadPath=function(file){
  17294. return AtlasInfoManager._fileLoadDic[file] || file;
  17295. }
  17296. AtlasInfoManager._fileLoadDic={};
  17297. return AtlasInfoManager;
  17298. })()
  17299. //class laya.webgl.canvas.BlendMode
  17300. var BlendMode=(function(){
  17301. function BlendMode(){}
  17302. __class(BlendMode,'laya.webgl.canvas.BlendMode');
  17303. BlendMode._init_=function(gl){
  17304. BlendMode.fns=[BlendMode.BlendNormal,BlendMode.BlendAdd,BlendMode.BlendMultiply,BlendMode.BlendScreen,BlendMode.BlendOverlay,BlendMode.BlendLight,BlendMode.BlendMask,BlendMode.BlendDestinationOut];
  17305. BlendMode.targetFns=[BlendMode.BlendNormalTarget,BlendMode.BlendAddTarget,BlendMode.BlendMultiplyTarget,BlendMode.BlendScreenTarget,BlendMode.BlendOverlayTarget,BlendMode.BlendLightTarget,BlendMode.BlendMask,BlendMode.BlendDestinationOut];
  17306. }
  17307. BlendMode.BlendNormal=function(gl){
  17308. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  17309. }
  17310. BlendMode.BlendAdd=function(gl){
  17311. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.DST_ALPHA*/0x0304);
  17312. }
  17313. BlendMode.BlendMultiply=function(gl){
  17314. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.DST_COLOR*/0x0306,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  17315. }
  17316. BlendMode.BlendScreen=function(gl){
  17317. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1);
  17318. }
  17319. BlendMode.BlendOverlay=function(gl){
  17320. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_COLOR*/0x0301);
  17321. }
  17322. BlendMode.BlendLight=function(gl){
  17323. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1);
  17324. }
  17325. BlendMode.BlendNormalTarget=function(gl){
  17326. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  17327. }
  17328. BlendMode.BlendAddTarget=function(gl){
  17329. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.DST_ALPHA*/0x0304);
  17330. }
  17331. BlendMode.BlendMultiplyTarget=function(gl){
  17332. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.DST_COLOR*/0x0306,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303);
  17333. }
  17334. BlendMode.BlendScreenTarget=function(gl){
  17335. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1);
  17336. }
  17337. BlendMode.BlendOverlayTarget=function(gl){
  17338. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_COLOR*/0x0301);
  17339. }
  17340. BlendMode.BlendLightTarget=function(gl){
  17341. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1);
  17342. }
  17343. BlendMode.BlendMask=function(gl){
  17344. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ZERO*/0,/*laya.webgl.WebGLContext.SRC_ALPHA*/0x0302);
  17345. }
  17346. BlendMode.BlendDestinationOut=function(gl){
  17347. WebGLContext.setBlendFunc(gl,/*laya.webgl.WebGLContext.ZERO*/0,/*laya.webgl.WebGLContext.ZERO*/0);
  17348. }
  17349. BlendMode.activeBlendFunction=null;
  17350. BlendMode.NAMES=["normal","add","multiply","screen","overlay","light","mask","destination-out"];
  17351. BlendMode.TOINT={"normal":0,"add":1,"multiply":2,"screen":3 ,"overlay":4,"light":5,"mask":6,"destination-out":7,"lighter":1 };
  17352. BlendMode.NORMAL="normal";
  17353. BlendMode.ADD="add";
  17354. BlendMode.MULTIPLY="multiply";
  17355. BlendMode.SCREEN="screen";
  17356. BlendMode.OVERLAY="overlay";
  17357. BlendMode.LIGHT="light";
  17358. BlendMode.MASK="mask";
  17359. BlendMode.DESTINATIONOUT="destination-out";
  17360. BlendMode.LIGHTER="lighter";
  17361. BlendMode.fns=[];
  17362. BlendMode.targetFns=[];
  17363. return BlendMode;
  17364. })()
  17365. /**
  17366. *旋转命令
  17367. */
  17368. //class laya.display.cmd.RotateCmd
  17369. var RotateCmd=(function(){
  17370. function RotateCmd(){
  17371. /**
  17372. *旋转角度,以弧度计。
  17373. */
  17374. //this.angle=NaN;
  17375. /**
  17376. *(可选)水平方向轴心点坐标。
  17377. */
  17378. //this.pivotX=NaN;
  17379. /**
  17380. *(可选)垂直方向轴心点坐标。
  17381. */
  17382. //this.pivotY=NaN;
  17383. }
  17384. __class(RotateCmd,'laya.display.cmd.RotateCmd');
  17385. var __proto=RotateCmd.prototype;
  17386. /**
  17387. *回收到对象池
  17388. */
  17389. __proto.recover=function(){
  17390. Pool.recover("RotateCmd",this);
  17391. }
  17392. /**@private */
  17393. __proto.run=function(context,gx,gy){
  17394. context._rotate(this.angle,this.pivotX+gx,this.pivotY+gy);
  17395. }
  17396. /**@private */
  17397. __getset(0,__proto,'cmdID',function(){
  17398. return "Rotate";
  17399. });
  17400. RotateCmd.create=function(angle,pivotX,pivotY){
  17401. var cmd=Pool.getItemByClass("RotateCmd",RotateCmd);
  17402. cmd.angle=angle;
  17403. cmd.pivotX=pivotX;
  17404. cmd.pivotY=pivotY;
  17405. return cmd;
  17406. }
  17407. RotateCmd.ID="Rotate";
  17408. return RotateCmd;
  17409. })()
  17410. //class laya.utils.FontInfo
  17411. var FontInfo=(function(){
  17412. function FontInfo(font){
  17413. //this._id=0;
  17414. this._font="14px Arial";
  17415. this._family="Arial";
  17416. this._size=14;
  17417. this._italic=false;
  17418. this._bold=false;
  17419. this._id=FontInfo._gfontID++;
  17420. this.setFont(font || this._font);
  17421. }
  17422. __class(FontInfo,'laya.utils.FontInfo');
  17423. var __proto=FontInfo.prototype;
  17424. __proto.setFont=function(value){
  17425. this._font=value;
  17426. var _words=value.split(' ');
  17427. var l=_words.length;
  17428. if (l < 2){
  17429. if (l==1){
  17430. if (_words[0].indexOf('px')> 0){
  17431. this._size=parseInt(_words[0]);
  17432. }
  17433. }
  17434. return;
  17435. };
  17436. var szpos=-1;
  17437. for (var i=0;i < l;i++){
  17438. if (_words[i].indexOf('px')> 0 || _words[i].indexOf('pt')> 0){
  17439. szpos=i;
  17440. this._size=parseInt(_words[i]);
  17441. if (this._size <=0){
  17442. console.error('font parse error:'+value);
  17443. this._size=14;
  17444. }
  17445. break ;
  17446. }
  17447. };
  17448. var fpos=szpos+1;
  17449. var familys=_words[fpos];
  17450. fpos++;
  17451. for (;fpos < l;fpos++){
  17452. familys+=' '+_words[fpos];
  17453. }
  17454. this._family=(familys.split(','))[0];
  17455. this._italic=_words.indexOf('italic')>=0;
  17456. this._bold=_words.indexOf('bold')>=0;
  17457. }
  17458. FontInfo.Parse=function(font){
  17459. if (font===FontInfo._lastFont){
  17460. return FontInfo._lastFontInfo;
  17461. };
  17462. var r=FontInfo._cache[font];
  17463. if(!r){
  17464. r=FontInfo._cache[font]=new FontInfo(font);
  17465. }
  17466. FontInfo._lastFont=font;
  17467. FontInfo._lastFontInfo=r;
  17468. return r;
  17469. }
  17470. FontInfo.EMPTY=new FontInfo(null);
  17471. FontInfo._cache={};
  17472. FontInfo._gfontID=0;
  17473. FontInfo._lastFont='';
  17474. FontInfo._lastFontInfo=null;
  17475. return FontInfo;
  17476. })()
  17477. /**
  17478. *@private
  17479. *<code>ShaderCompile</code> 类用于实现Shader编译。
  17480. */
  17481. //class laya.webgl.utils.ShaderCompile
  17482. var ShaderCompile=(function(){
  17483. function ShaderCompile(vs,ps,nameMap,defs){
  17484. //this._nameMap=null;
  17485. //this._VS=null;
  17486. //this._PS=null;
  17487. this._clearCR=new RegExp("\r","g");
  17488. var _$this=this;
  17489. function _compile (script){
  17490. script=script.replace(_$this._clearCR,"");
  17491. var includefiles=[];
  17492. var top=new ShaderNode(includefiles);
  17493. _$this._compileToTree(top,script.split('\n'),0,includefiles,defs);
  17494. return top;
  17495. };
  17496. var startTime=Browser.now();
  17497. this._VS=_compile(vs);
  17498. this._PS=_compile(ps);
  17499. this._nameMap=nameMap;
  17500. if ((Browser.now()-startTime)> 2)
  17501. console.log("ShaderCompile use time:"+(Browser.now()-startTime)+" size:"+vs.length+"/"+ps.length);
  17502. }
  17503. __class(ShaderCompile,'laya.webgl.utils.ShaderCompile');
  17504. var __proto=ShaderCompile.prototype;
  17505. /**
  17506. *@private
  17507. */
  17508. __proto._compileToTree=function(parent,lines,start,includefiles,defs){
  17509. var node,preNode;
  17510. var text,name,fname;
  17511. var ofs=0,words,noUseNode;
  17512. var i=0,n=0,j=0;
  17513. for (i=start;i < lines.length;i++){
  17514. text=lines[i];
  17515. if (text.length < 1)continue ;
  17516. ofs=text.indexOf("//");
  17517. if (ofs===0)continue ;
  17518. if (ofs >=0)text=text.substr(0,ofs);
  17519. node=noUseNode || new ShaderNode(includefiles);
  17520. noUseNode=null;
  17521. node.text=text;
  17522. node.noCompile=true;
  17523. if ((ofs=text.indexOf("#"))>=0){
  17524. name="#";
  17525. for (j=ofs+1,n=text.length;j < n;j++){
  17526. var c=text.charAt(j);
  17527. if (c===' ' || c==='\t' || c==='?')break ;
  17528. name+=c;
  17529. }
  17530. node.name=name;
  17531. switch (name){
  17532. case "#ifdef":
  17533. case "#ifndef":
  17534. node.src=text;
  17535. node.noCompile=text.match(/[!&|()=<>]/)!=null;
  17536. if (!node.noCompile){
  17537. words=text.replace(/^\s*/,'').split(/\s+/);
  17538. node.setCondition(words[1],name==="#ifdef" ? 1 :2);
  17539. node.text="//"+node.text;
  17540. }else {
  17541. console.log("function():Boolean{return "+text.substr(ofs+node.name.length)+"}");
  17542. }
  17543. node.setParent(parent);
  17544. parent=node;
  17545. if (defs){
  17546. words=text.substr(j).split(ShaderCompile._splitToWordExps3);
  17547. for (j=0;j < words.length;j++){
  17548. text=words[j];
  17549. text.length && (defs[text]=true);
  17550. }
  17551. }
  17552. continue ;
  17553. case "#if":
  17554. node.src=text;
  17555. node.noCompile=true;
  17556. node.setParent(parent);
  17557. parent=node;
  17558. if (defs){
  17559. words=text.substr(j).split(ShaderCompile._splitToWordExps3);
  17560. for (j=0;j < words.length;j++){
  17561. text=words[j];
  17562. text.length && text !="defined" && (defs[text]=true);
  17563. }
  17564. }
  17565. continue ;
  17566. case "#else":
  17567. node.src=text;
  17568. parent=parent.parent;
  17569. preNode=parent.childs[parent.childs.length-1];
  17570. node.noCompile=preNode.noCompile;
  17571. if (!node.noCompile){
  17572. node.condition=preNode.condition;
  17573. node.conditionType=preNode.conditionType==1 ? 2 :1;
  17574. node.text="//"+node.text+" "+preNode.text+" "+node.conditionType;
  17575. }
  17576. node.setParent(parent);
  17577. parent=node;
  17578. continue ;
  17579. case "#endif":
  17580. parent=parent.parent;
  17581. preNode=parent.childs[parent.childs.length-1];
  17582. node.noCompile=preNode.noCompile;
  17583. if (!node.noCompile){
  17584. node.text="//"+node.text;
  17585. }
  17586. node.setParent(parent);
  17587. continue ;
  17588. case "#include":
  17589. words=ShaderCompile.splitToWords(text,null);
  17590. var inlcudeFile=ShaderCompile.includes[words[1]];
  17591. if (!inlcudeFile){
  17592. throw "ShaderCompile error no this include file:"+words[1];
  17593. }
  17594. if ((ofs=words[0].indexOf("?"))< 0){
  17595. node.setParent(parent);
  17596. text=inlcudeFile.getWith(words[2]=='with' ? words[3] :null);
  17597. this._compileToTree(node,text.split('\n'),0,includefiles,defs);
  17598. node.text="";
  17599. continue ;
  17600. }
  17601. node.setCondition(words[0].substr(ofs+1),1);
  17602. node.text=inlcudeFile.getWith(words[2]=='with' ? words[3] :null);
  17603. break ;
  17604. case "#import":
  17605. words=ShaderCompile.splitToWords(text,null);
  17606. fname=words[1];
  17607. includefiles.push({node:node,file:ShaderCompile.includes[fname],ofs:node.text.length});
  17608. continue ;
  17609. }
  17610. }else {
  17611. preNode=parent.childs[parent.childs.length-1];
  17612. if (preNode && !preNode.name){
  17613. includefiles.length > 0 && ShaderCompile.splitToWords(text,preNode);
  17614. noUseNode=node;
  17615. preNode.text+="\n"+text;
  17616. continue ;
  17617. }
  17618. includefiles.length > 0 && ShaderCompile.splitToWords(text,node);
  17619. }
  17620. node.setParent(parent);
  17621. }
  17622. }
  17623. __proto.createShader=function(define,shaderName,createShader,bindAttrib){
  17624. var defMap={};
  17625. var defineStr="";
  17626. if (define){
  17627. for (var i in define){
  17628. defineStr+="#define "+i+"\n";
  17629. defMap[i]=true;
  17630. }
  17631. };
  17632. var vs=this._VS.toscript(defMap,[]);
  17633. var ps=this._PS.toscript(defMap,[]);
  17634. return (createShader || Shader.create)(defineStr+vs.join('\n'),defineStr+ps.join('\n'),shaderName,this._nameMap,bindAttrib);
  17635. }
  17636. ShaderCompile._parseOne=function(attributes,uniforms,words,i,word,b){
  17637. var one={type:ShaderCompile.shaderParamsMap[words[i+1]],name:words[i+2],size:isNaN(parseInt(words[i+3]))? 1 :parseInt(words[i+3])};
  17638. if (b){
  17639. if (word=="attribute"){
  17640. attributes.push(one);
  17641. }else {
  17642. uniforms.push(one);
  17643. }
  17644. }
  17645. if (words[i+3]==':'){
  17646. one.type=words[i+4];
  17647. i+=2;
  17648. }
  17649. i+=2;
  17650. return i;
  17651. }
  17652. ShaderCompile.addInclude=function(fileName,txt){
  17653. if (!txt || txt.length===0)
  17654. throw new Error("add shader include file err:"+fileName);
  17655. if (ShaderCompile.includes[fileName])
  17656. throw new Error("add shader include file err, has add:"+fileName);
  17657. ShaderCompile.includes[fileName]=new InlcudeFile(txt);
  17658. }
  17659. ShaderCompile.preGetParams=function(vs,ps){
  17660. var text=[vs,ps];
  17661. var result={};
  17662. var attributes=[];
  17663. var uniforms=[];
  17664. var definesInfo={};
  17665. var definesName=[];
  17666. result.attributes=attributes;
  17667. result.uniforms=uniforms;
  17668. result.defines=definesInfo;
  17669. var i=0,n=0,one;
  17670. for (var s=0;s < 2;s++){
  17671. text[s]=text[s].replace(ShaderCompile._removeAnnotation,"");
  17672. var words=text[s].match(ShaderCompile._reg);
  17673. var tempelse;
  17674. for (i=0,n=words.length;i < n;i++){
  17675. var word=words[i];
  17676. if (word !="attribute" && word !="uniform"){
  17677. if (word=="#define"){
  17678. word=words[++i];
  17679. definesName[word]=1;
  17680. continue ;
  17681. }else if (word=="#ifdef"){
  17682. tempelse=words[++i];
  17683. var def=definesInfo[tempelse]=definesInfo[tempelse] || [];
  17684. for (i++;i < n;i++){
  17685. word=words[i];
  17686. if (word !="attribute" && word !="uniform"){
  17687. if (word=="#else"){
  17688. for (i++;i < n;i++){
  17689. word=words[i];
  17690. if (word !="attribute" && word !="uniform"){
  17691. if (word=="#endif"){
  17692. break ;
  17693. }
  17694. continue ;
  17695. }
  17696. i=ShaderCompile._parseOne(attributes,uniforms,words,i,word,!definesName[tempelse]);
  17697. }
  17698. }
  17699. continue ;
  17700. }
  17701. i=ShaderCompile._parseOne(attributes,uniforms,words,i,word,definesName[tempelse]);
  17702. }
  17703. }
  17704. continue ;
  17705. }
  17706. i=ShaderCompile._parseOne(attributes,uniforms,words,i,word,true);
  17707. }
  17708. }
  17709. return result;
  17710. }
  17711. ShaderCompile.splitToWords=function(str,block){
  17712. var out=[];
  17713. var c;
  17714. var ofs=-1;
  17715. var word;
  17716. for (var i=0,n=str.length;i < n;i++){
  17717. c=str.charAt(i);
  17718. if (" \t=+-*/&%!<>()'\",;".indexOf(c)>=0){
  17719. if (ofs >=0 && (i-ofs)> 1){
  17720. word=str.substr(ofs,i-ofs);
  17721. out.push(word);
  17722. }
  17723. if (c=='"' || c=="'"){
  17724. var ofs2=str.indexOf(c,i+1);
  17725. if (ofs2 < 0){
  17726. throw "Sharder err:"+str;
  17727. }
  17728. out.push(str.substr(i+1,ofs2-i-1));
  17729. i=ofs2;
  17730. ofs=-1;
  17731. continue ;
  17732. }
  17733. if (c=='(' && block && out.length > 0){
  17734. word=out[out.length-1]+";";
  17735. if ("vec4;main;".indexOf(word)< 0)
  17736. block.useFuns+=word;
  17737. }
  17738. ofs=-1;
  17739. continue ;
  17740. }
  17741. if (ofs < 0)ofs=i;
  17742. }
  17743. if (ofs < n && (n-ofs)> 1){
  17744. word=str.substr(ofs,n-ofs);
  17745. out.push(word);
  17746. }
  17747. return out;
  17748. }
  17749. ShaderCompile.IFDEF_NO=0;
  17750. ShaderCompile.IFDEF_YES=1;
  17751. ShaderCompile.IFDEF_ELSE=2;
  17752. ShaderCompile.IFDEF_PARENT=3;
  17753. ShaderCompile._removeAnnotation=new RegExp("(/\\*([^*]|[\\r\\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/)|(//.*)","g");
  17754. ShaderCompile._reg=new RegExp("(\".*\")|('.*')|([#\\w\\*-\\.+/()=<>{}\\\\]+)|([,;:\\\\])","g");
  17755. ShaderCompile._splitToWordExps=new RegExp("[(\".*\")]+|[('.*')]+|([ \\t=\\+\\-*/&%!<>!%\(\),;])","g");
  17756. ShaderCompile.includes={};
  17757. __static(ShaderCompile,
  17758. ['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");}
  17759. ]);
  17760. return ShaderCompile;
  17761. })()
  17762. /**
  17763. *模板,预制件
  17764. */
  17765. //class laya.components.Prefab
  17766. var Prefab=(function(){
  17767. function Prefab(){
  17768. /**@private */
  17769. this.json=null;
  17770. }
  17771. __class(Prefab,'laya.components.Prefab');
  17772. var __proto=Prefab.prototype;
  17773. /**
  17774. *通过预制创建实例
  17775. */
  17776. __proto.create=function(){
  17777. if (this.json)return SceneUtils.createByData(null,this.json);
  17778. return null;
  17779. }
  17780. return Prefab;
  17781. })()
  17782. /**
  17783. *绘制边框
  17784. *@private
  17785. */
  17786. //class laya.display.cmd.FillBorderWordsCmd
  17787. var FillBorderWordsCmd=(function(){
  17788. function FillBorderWordsCmd(){
  17789. /**
  17790. *文字数组
  17791. */
  17792. //this.words=null;
  17793. /**
  17794. *开始绘制文本的 x 坐标位置(相对于画布)。
  17795. */
  17796. //this.x=NaN;
  17797. /**
  17798. *开始绘制文本的 y 坐标位置(相对于画布)。
  17799. */
  17800. //this.y=NaN;
  17801. /**
  17802. *定义字体和字号,比如"20px Arial"。
  17803. */
  17804. //this.font=null;
  17805. /**
  17806. *定义文本颜色,比如"#ff0000"。
  17807. */
  17808. //this.fillColor=null;
  17809. /**
  17810. *定义镶边文本颜色。
  17811. */
  17812. //this.borderColor=null;
  17813. /**
  17814. *镶边线条宽度。
  17815. */
  17816. //this.lineWidth=0;
  17817. }
  17818. __class(FillBorderWordsCmd,'laya.display.cmd.FillBorderWordsCmd');
  17819. var __proto=FillBorderWordsCmd.prototype;
  17820. /**
  17821. *回收到对象池
  17822. */
  17823. __proto.recover=function(){
  17824. this.words=null;
  17825. Pool.recover("FillBorderWordsCmd",this);
  17826. }
  17827. /**@private */
  17828. __proto.run=function(context,gx,gy){
  17829. context.fillBorderWords(this.words,this.x+gx,this.y+gy,this.font,this.fillColor,this.borderColor,this.lineWidth);
  17830. }
  17831. /**@private */
  17832. __getset(0,__proto,'cmdID',function(){
  17833. return "FillBorderWords";
  17834. });
  17835. FillBorderWordsCmd.create=function(words,x,y,font,fillColor,borderColor,lineWidth){
  17836. var cmd=Pool.getItemByClass("FillBorderWordsCmd",FillBorderWordsCmd);
  17837. cmd.words=words;
  17838. cmd.x=x;
  17839. cmd.y=y;
  17840. cmd.font=font;
  17841. cmd.fillColor=fillColor;
  17842. cmd.borderColor=borderColor;
  17843. cmd.lineWidth=lineWidth;
  17844. return cmd;
  17845. }
  17846. FillBorderWordsCmd.ID="FillBorderWords";
  17847. return FillBorderWordsCmd;
  17848. })()
  17849. /**
  17850. *鼠标点击区域,可以设置绘制一系列矢量图作为点击区域和非点击区域(目前只支持圆形,矩形,多边形)
  17851. *
  17852. */
  17853. //class laya.utils.HitArea
  17854. var HitArea=(function(){
  17855. function HitArea(){
  17856. /**@private */
  17857. this._hit=null;
  17858. /**@private */
  17859. this._unHit=null;
  17860. }
  17861. __class(HitArea,'laya.utils.HitArea');
  17862. var __proto=HitArea.prototype;
  17863. /**
  17864. *检测对象是否包含指定的点。
  17865. *@param x 点的 X 轴坐标值(水平位置)。
  17866. *@param y 点的 Y 轴坐标值(垂直位置)。
  17867. *@return 如果包含指定的点,则值为 true;否则为 false。
  17868. */
  17869. __proto.contains=function(x,y){
  17870. if (!HitArea._isHitGraphic(x,y,this.hit))return false;
  17871. return !HitArea._isHitGraphic(x,y,this.unHit);
  17872. }
  17873. /**
  17874. *可点击区域,可以设置绘制一系列矢量图作为点击区域(目前只支持圆形,矩形,多边形)
  17875. */
  17876. __getset(0,__proto,'hit',function(){
  17877. if (!this._hit)this._hit=new Graphics();
  17878. return this._hit;
  17879. },function(value){
  17880. this._hit=value;
  17881. });
  17882. /**
  17883. *不可点击区域,可以设置绘制一系列矢量图作为非点击区域(目前只支持圆形,矩形,多边形)
  17884. */
  17885. __getset(0,__proto,'unHit',function(){
  17886. if (!this._unHit)this._unHit=new Graphics();
  17887. return this._unHit;
  17888. },function(value){
  17889. this._unHit=value;
  17890. });
  17891. HitArea._isHitGraphic=function(x,y,graphic){
  17892. if (!graphic)return false;
  17893. var cmds=graphic.cmds;
  17894. if (!cmds && graphic._one){
  17895. cmds=HitArea._cmds;
  17896. cmds.length=1;
  17897. cmds[0]=graphic._one;
  17898. }
  17899. if (!cmds)return false;
  17900. var i=0,len=0;
  17901. len=cmds.length;
  17902. var cmd;
  17903. for (i=0;i < len;i++){
  17904. cmd=cmds[i];
  17905. if (!cmd)continue ;
  17906. switch (cmd.cmdID){
  17907. case "Translate":
  17908. x-=cmd.tx;
  17909. y-=cmd.ty;
  17910. }
  17911. if (HitArea._isHitCmd(x,y,cmd))return true;
  17912. }
  17913. return false;
  17914. }
  17915. HitArea._isHitCmd=function(x,y,cmd){
  17916. if (!cmd)return false;
  17917. var rst=false;
  17918. switch (cmd.cmdID){
  17919. case "DrawRect":
  17920. HitArea._rect.setTo(cmd.x,cmd.y,cmd.width,cmd.height);
  17921. rst=HitArea._rect.contains(x,y);
  17922. break ;
  17923. case "DrawCircle":;
  17924. var d=NaN;
  17925. x-=cmd.x;
  17926. y-=cmd.y;
  17927. d=x *x+y *y;
  17928. rst=d < cmd.radius *cmd.radius;
  17929. break ;
  17930. case "DrawPoly":
  17931. x-=cmd.x;
  17932. y-=cmd.y;
  17933. rst=HitArea._ptInPolygon(x,y,cmd.points);
  17934. break ;
  17935. }
  17936. return rst;
  17937. }
  17938. HitArea._ptInPolygon=function(x,y,areaPoints){
  17939. var p=HitArea._ptPoint;
  17940. p.setTo(x,y);
  17941. var nCross=0;
  17942. var p1x=NaN,p1y=NaN,p2x=NaN,p2y=NaN;
  17943. var len=0;
  17944. len=areaPoints.length;
  17945. for (var i=0;i < len;i+=2){
  17946. p1x=areaPoints[i];
  17947. p1y=areaPoints[i+1];
  17948. p2x=areaPoints[(i+2)% len];
  17949. p2y=areaPoints[(i+3)% len];
  17950. if (p1y==p2y)continue ;
  17951. if (p.y < Math.min(p1y,p2y))continue ;
  17952. if (p.y >=Math.max(p1y,p2y))continue ;
  17953. var tx=(p.y-p1y)*(p2x-p1x)/ (p2y-p1y)+p1x;
  17954. if (tx > p.x)nCross++;
  17955. }
  17956. return (nCross % 2==1);
  17957. }
  17958. HitArea._cmds=[];
  17959. __static(HitArea,
  17960. ['_rect',function(){return this._rect=new Rectangle();},'_ptPoint',function(){return this._ptPoint=new Point();}
  17961. ]);
  17962. return HitArea;
  17963. })()
  17964. /**
  17965. *<code>SoundManager</code> 是一个声音管理类。提供了对背景音乐、音效的播放控制方法。
  17966. *引擎默认有两套声音方案:WebAudio和H5Audio
  17967. *播放音效,优先使用WebAudio播放声音,如果WebAudio不可用,则用H5Audio播放,H5Audio在部分机器上有兼容问题(比如不能混音,播放有延迟等)。
  17968. *播放背景音乐,则使用H5Audio播放(使用WebAudio会增加特别大的内存,并且要等加载完毕后才能播放,有延迟)
  17969. *建议背景音乐用mp3类型,音效用wav或者mp3类型(如果打包为app,音效只能用wav格式)。
  17970. *详细教程及声音格式请参考:http://ldc2.layabox.com/doc/?nav=ch-as-1-7-0
  17971. */
  17972. //class laya.media.SoundManager
  17973. var SoundManager=(function(){
  17974. function SoundManager(){}
  17975. __class(SoundManager,'laya.media.SoundManager');
  17976. __getset(1,SoundManager,'useAudioMusic',function(){
  17977. return SoundManager._useAudioMusic;
  17978. },function(value){
  17979. SoundManager._useAudioMusic=value;
  17980. if (value){
  17981. SoundManager._musicClass=AudioSound;
  17982. }else{
  17983. SoundManager._musicClass=null;
  17984. }
  17985. });
  17986. /**
  17987. *失去焦点后是否自动停止背景音乐。
  17988. *@param v Boolean 失去焦点后是否自动停止背景音乐。
  17989. *
  17990. */
  17991. /**
  17992. *失去焦点后是否自动停止背景音乐。
  17993. */
  17994. __getset(1,SoundManager,'autoStopMusic',function(){
  17995. return SoundManager._autoStopMusic;
  17996. },function(v){
  17997. Laya.stage.off(/*laya.events.Event.BLUR*/"blur",null,SoundManager._stageOnBlur);
  17998. Laya.stage.off(/*laya.events.Event.FOCUS*/"focus",null,SoundManager._stageOnFocus);
  17999. Laya.stage.off(/*laya.events.Event.VISIBILITY_CHANGE*/"visibilitychange",null,SoundManager._visibilityChange);
  18000. SoundManager._autoStopMusic=v;
  18001. if (v){
  18002. Laya.stage.on(/*laya.events.Event.BLUR*/"blur",null,SoundManager._stageOnBlur);
  18003. Laya.stage.on(/*laya.events.Event.FOCUS*/"focus",null,SoundManager._stageOnFocus);
  18004. Laya.stage.on(/*laya.events.Event.VISIBILITY_CHANGE*/"visibilitychange",null,SoundManager._visibilityChange);
  18005. }
  18006. });
  18007. /**
  18008. *背景音乐和所有音效是否静音。
  18009. */
  18010. __getset(1,SoundManager,'muted',function(){
  18011. return SoundManager._muted;
  18012. },function(value){
  18013. if (value==SoundManager._muted)return;
  18014. if (value){
  18015. SoundManager.stopAllSound();
  18016. }
  18017. SoundManager.musicMuted=value;
  18018. SoundManager._muted=value;
  18019. });
  18020. /**
  18021. *背景音乐(不包括音效)是否静音。
  18022. */
  18023. __getset(1,SoundManager,'musicMuted',function(){
  18024. return SoundManager._musicMuted;
  18025. },function(value){
  18026. if (value==SoundManager._musicMuted)return;
  18027. if (value){
  18028. if (SoundManager._bgMusic){
  18029. if (SoundManager._musicChannel&&!SoundManager._musicChannel.isStopped){
  18030. if (Render.isConchApp){
  18031. /*__JS__ */if (SoundManager._musicChannel._audio)SoundManager._musicChannel._audio.muted=true;;
  18032. }
  18033. else {
  18034. SoundManager._musicChannel.pause();
  18035. }
  18036. }else{
  18037. SoundManager._musicChannel=null;
  18038. }
  18039. }else{
  18040. SoundManager._musicChannel=null;
  18041. }
  18042. SoundManager._musicMuted=value;
  18043. }else {
  18044. SoundManager._musicMuted=value;
  18045. if (SoundManager._bgMusic){
  18046. if (SoundManager._musicChannel){
  18047. if (Render.isConchApp){
  18048. /*__JS__ */if(SoundManager._musicChannel._audio)SoundManager._musicChannel._audio.muted=false;;
  18049. }
  18050. else {
  18051. SoundManager._musicChannel.resume();
  18052. }
  18053. }
  18054. }
  18055. }
  18056. });
  18057. /**
  18058. *所有音效(不包括背景音乐)是否静音。
  18059. */
  18060. __getset(1,SoundManager,'soundMuted',function(){
  18061. return SoundManager._soundMuted;
  18062. },function(value){
  18063. SoundManager._soundMuted=value;
  18064. });
  18065. SoundManager.__init__=function(){
  18066. var win=Browser.window;
  18067. var supportWebAudio=win["AudioContext"] || win["webkitAudioContext"] || win["mozAudioContext"] ? true :false;
  18068. if (supportWebAudio)WebAudioSound.initWebAudio();
  18069. SoundManager._soundClass=supportWebAudio?WebAudioSound:AudioSound;
  18070. AudioSound._initMusicAudio();
  18071. SoundManager._musicClass=AudioSound;
  18072. return supportWebAudio;
  18073. }
  18074. SoundManager.addChannel=function(channel){
  18075. if (SoundManager._channels.indexOf(channel)>=0)return;
  18076. SoundManager._channels.push(channel);
  18077. }
  18078. SoundManager.removeChannel=function(channel){
  18079. var i=0;
  18080. for (i=SoundManager._channels.length-1;i >=0;i--){
  18081. if (SoundManager._channels[i]==channel){
  18082. SoundManager._channels.splice(i,1);
  18083. }
  18084. }
  18085. }
  18086. SoundManager.disposeSoundLater=function(url){
  18087. SoundManager._lastSoundUsedTimeDic[url]=Browser.now();
  18088. if (!SoundManager._isCheckingDispose){
  18089. SoundManager._isCheckingDispose=true;
  18090. Laya.timer.loop(5000,null,SoundManager._checkDisposeSound);
  18091. }
  18092. }
  18093. SoundManager._checkDisposeSound=function(){
  18094. var key;
  18095. var tTime=Browser.now();
  18096. var hasCheck=false;
  18097. for (key in SoundManager._lastSoundUsedTimeDic){
  18098. if (tTime-SoundManager._lastSoundUsedTimeDic[key]>30000){
  18099. delete SoundManager._lastSoundUsedTimeDic[key];
  18100. SoundManager.disposeSoundIfNotUsed(key);
  18101. }else{
  18102. hasCheck=true;
  18103. }
  18104. }
  18105. if (!hasCheck){
  18106. SoundManager._isCheckingDispose=false;
  18107. Laya.timer.clear(null,SoundManager._checkDisposeSound);
  18108. }
  18109. }
  18110. SoundManager.disposeSoundIfNotUsed=function(url){
  18111. var i=0;
  18112. for (i=SoundManager._channels.length-1;i >=0;i--){
  18113. if (SoundManager._channels[i].url==url){
  18114. return;
  18115. }
  18116. }
  18117. SoundManager.destroySound(url);
  18118. }
  18119. SoundManager._visibilityChange=function(){
  18120. if (Laya.stage.isVisibility){
  18121. SoundManager._stageOnFocus();
  18122. }else {
  18123. SoundManager._stageOnBlur();
  18124. }
  18125. }
  18126. SoundManager._stageOnBlur=function(){
  18127. SoundManager._isActive=false;
  18128. if (SoundManager._musicChannel){
  18129. if (!SoundManager._musicChannel.isStopped){
  18130. SoundManager._blurPaused=true;
  18131. SoundManager._musicChannel.pause();
  18132. }
  18133. }
  18134. SoundManager.stopAllSound();
  18135. Laya.stage.once(/*laya.events.Event.MOUSE_DOWN*/"mousedown",null,SoundManager._stageOnFocus);
  18136. }
  18137. SoundManager._recoverWebAudio=function(){
  18138. if(WebAudioSound.ctx&&WebAudioSound.ctx.state!="running"&&WebAudioSound.ctx.resume)
  18139. WebAudioSound.ctx.resume();
  18140. }
  18141. SoundManager._stageOnFocus=function(){
  18142. SoundManager._isActive=true;
  18143. SoundManager._recoverWebAudio();
  18144. Laya.stage.off(/*laya.events.Event.MOUSE_DOWN*/"mousedown",null,SoundManager._stageOnFocus);
  18145. if (SoundManager._blurPaused){
  18146. if (SoundManager._musicChannel && SoundManager._musicChannel.isStopped){
  18147. SoundManager._blurPaused=false;
  18148. SoundManager._musicChannel.resume();
  18149. }
  18150. }
  18151. }
  18152. SoundManager.playSound=function(url,loops,complete,soundClass,startTime){
  18153. (loops===void 0)&& (loops=1);
  18154. (startTime===void 0)&& (startTime=0);
  18155. if (!SoundManager._isActive || !url)return null;
  18156. if (SoundManager._muted)return null;
  18157. SoundManager._recoverWebAudio();
  18158. url=URL.formatURL(url);
  18159. if (url==SoundManager._bgMusic){
  18160. if (SoundManager._musicMuted)return null;
  18161. }else {
  18162. if (Render.isConchApp){
  18163. var ext=Utils.getFileExtension(url);
  18164. if (ext !="wav" && ext !="ogg"){
  18165. alert("The sound only supports wav or ogg format,for optimal performance reason,please refer to the official website document.");
  18166. return null;
  18167. }
  18168. }
  18169. if (SoundManager._soundMuted)return null;
  18170. };
  18171. var tSound;
  18172. if (!Browser.onMiniGame){
  18173. tSound=Laya.loader.getRes(url);
  18174. }
  18175. if (!soundClass)soundClass=SoundManager._soundClass;
  18176. if (!tSound){
  18177. tSound=new soundClass();
  18178. tSound.load(url);
  18179. if (!Browser.onMiniGame){
  18180. Loader.cacheRes(url,tSound);
  18181. }
  18182. };
  18183. var channel;
  18184. channel=tSound.play(startTime,loops);
  18185. if (!channel)return null;
  18186. channel.url=url;
  18187. channel.volume=(url==SoundManager._bgMusic)? SoundManager.musicVolume :SoundManager.soundVolume;
  18188. channel.completeHandler=complete;
  18189. return channel;
  18190. }
  18191. SoundManager.destroySound=function(url){
  18192. var tSound=Laya.loader.getRes(url);
  18193. if (tSound){
  18194. Loader.clearRes(url);
  18195. tSound.dispose();
  18196. }
  18197. }
  18198. SoundManager.playMusic=function(url,loops,complete,startTime){
  18199. (loops===void 0)&& (loops=0);
  18200. (startTime===void 0)&& (startTime=0);
  18201. url=URL.formatURL(url);
  18202. SoundManager._bgMusic=url;
  18203. if (SoundManager._musicChannel)SoundManager._musicChannel.stop();
  18204. return SoundManager._musicChannel=SoundManager.playSound(url,loops,complete,SoundManager._musicClass,startTime);
  18205. }
  18206. SoundManager.stopSound=function(url){
  18207. url=URL.formatURL(url);
  18208. var i=0;
  18209. var channel;
  18210. for (i=SoundManager._channels.length-1;i >=0;i--){
  18211. channel=SoundManager._channels[i];
  18212. if (channel.url==url){
  18213. channel.stop();
  18214. }
  18215. }
  18216. }
  18217. SoundManager.stopAll=function(){
  18218. SoundManager._bgMusic=null;
  18219. var i=0;
  18220. var channel;
  18221. for (i=SoundManager._channels.length-1;i >=0;i--){
  18222. channel=SoundManager._channels[i];
  18223. channel.stop();
  18224. }
  18225. }
  18226. SoundManager.stopAllSound=function(){
  18227. var i=0;
  18228. var channel;
  18229. for (i=SoundManager._channels.length-1;i >=0;i--){
  18230. channel=SoundManager._channels[i];
  18231. if (channel.url !=SoundManager._bgMusic){
  18232. channel.stop();
  18233. }
  18234. }
  18235. }
  18236. SoundManager.stopMusic=function(){
  18237. if (SoundManager._musicChannel)SoundManager._musicChannel.stop();
  18238. SoundManager._bgMusic=null;
  18239. }
  18240. SoundManager.setSoundVolume=function(volume,url){
  18241. if (url){
  18242. url=URL.formatURL(url);
  18243. SoundManager._setVolume(url,volume);
  18244. }else {
  18245. SoundManager.soundVolume=volume;
  18246. var i=0;
  18247. var channel;
  18248. for (i=SoundManager._channels.length-1;i >=0;i--){
  18249. channel=SoundManager._channels[i];
  18250. if (channel.url !=SoundManager._bgMusic){
  18251. channel.volume=volume;
  18252. }
  18253. }
  18254. }
  18255. }
  18256. SoundManager.setMusicVolume=function(volume){
  18257. SoundManager.musicVolume=volume;
  18258. SoundManager._setVolume(SoundManager._bgMusic,volume);
  18259. }
  18260. SoundManager._setVolume=function(url,volume){
  18261. url=URL.formatURL(url);
  18262. var i=0;
  18263. var channel;
  18264. for (i=SoundManager._channels.length-1;i >=0;i--){
  18265. channel=SoundManager._channels[i];
  18266. if (channel.url==url){
  18267. channel.volume=volume;
  18268. }
  18269. }
  18270. }
  18271. SoundManager.musicVolume=1;
  18272. SoundManager.soundVolume=1;
  18273. SoundManager.playbackRate=1;
  18274. SoundManager._useAudioMusic=true;
  18275. SoundManager._muted=false;
  18276. SoundManager._soundMuted=false;
  18277. SoundManager._musicMuted=false;
  18278. SoundManager._bgMusic=null;
  18279. SoundManager._musicChannel=null;
  18280. SoundManager._channels=[];
  18281. SoundManager._autoStopMusic=false;
  18282. SoundManager._blurPaused=false;
  18283. SoundManager._isActive=true;
  18284. SoundManager._soundClass=null;
  18285. SoundManager._musicClass=null;
  18286. SoundManager._lastSoundUsedTimeDic={};
  18287. SoundManager._isCheckingDispose=false;
  18288. SoundManager.autoReleaseSound=true;
  18289. return SoundManager;
  18290. })()
  18291. //class laya.webgl.submit.SubmitTexture extends laya.webgl.submit.Submit
  18292. var SubmitTexture=(function(_super){
  18293. function SubmitTexture(renderType){
  18294. (renderType===void 0)&& (renderType=10000);
  18295. SubmitTexture.__super.call(this,renderType);
  18296. }
  18297. __class(SubmitTexture,'laya.webgl.submit.SubmitTexture',_super);
  18298. var __proto=SubmitTexture.prototype;
  18299. __proto.clone=function(context,mesh,pos){
  18300. var o=SubmitTexture._poolSize ? SubmitTexture.POOL[--SubmitTexture._poolSize] :new SubmitTexture();
  18301. this._cloneInit(o,context,mesh,pos);
  18302. return o;
  18303. }
  18304. __proto.releaseRender=function(){
  18305. if ((--this._ref)< 1){
  18306. SubmitTexture.POOL[SubmitTexture._poolSize++]=this;
  18307. this.shaderValue.release();
  18308. this._mesh=null;
  18309. this._parent && (this._parent.releaseRender(),this._parent=null);
  18310. }
  18311. }
  18312. __proto.renderSubmit=function(){
  18313. if (this._numEle===0)
  18314. return 1;
  18315. var tex=this.shaderValue.textureHost;
  18316. if(tex){
  18317. var source=tex?tex._getSource():null;
  18318. if (!source)return 1;
  18319. };
  18320. var gl=WebGL.mainContext;
  18321. this._mesh.useMesh(gl);
  18322. var lastSubmit=Submit.preRender;
  18323. var prekey=(Submit.preRender)._key;
  18324. if (this._key.blendShader===0 && (this._key.submitType===prekey.submitType && this._key.blendShader===prekey.blendShader)&& BaseShader.activeShader &&
  18325. (Submit.preRender).clipInfoID==this.clipInfoID &&
  18326. lastSubmit.shaderValue.defines._value===this.shaderValue.defines._value &&
  18327. (this.shaderValue.defines._value & ShaderDefines2D.NOOPTMASK)==0){
  18328. (BaseShader.activeShader).uploadTexture2D(source);
  18329. }
  18330. else{
  18331. if (BlendMode.activeBlendFunction!==this._blendFn){
  18332. WebGLContext.setBlend(gl,true);
  18333. this._blendFn(gl);
  18334. BlendMode.activeBlendFunction=this._blendFn;
  18335. }
  18336. this.shaderValue.texture=source;
  18337. this.shaderValue.upload();
  18338. }
  18339. gl.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,this._numEle,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,this._startIdx);
  18340. Stat.renderBatches++;
  18341. Stat.trianglesFaces+=this._numEle / 3;
  18342. return 1;
  18343. }
  18344. SubmitTexture.create=function(context,mesh,sv){
  18345. var o=SubmitTexture._poolSize ? SubmitTexture.POOL[--SubmitTexture._poolSize] :new SubmitTexture(/*laya.webgl.submit.Submit.TYPE_TEXTURE*/10016);
  18346. o._mesh=mesh;
  18347. o._key.clear();
  18348. o._key.submitType=/*laya.webgl.submit.Submit.KEY_DRAWTEXTURE*/2;
  18349. o._ref=1;
  18350. o._startIdx=mesh.indexNum *CONST3D2D.BYTES_PIDX;
  18351. o._numEle=0;
  18352. var blendType=context._nBlendType;
  18353. o._key.blendShader=blendType;
  18354. o._blendFn=context._targets ? BlendMode.targetFns[blendType] :BlendMode.fns[blendType];
  18355. o.shaderValue=sv;
  18356. if (context._colorFiler){
  18357. var ft=context._colorFiler;
  18358. sv.defines.add(ft.type);
  18359. (sv).colorMat=ft._mat;
  18360. (sv).colorAlpha=ft._alpha;
  18361. }
  18362. return o;
  18363. }
  18364. SubmitTexture._poolSize=0;
  18365. SubmitTexture.POOL=[];
  18366. return SubmitTexture;
  18367. })(Submit)
  18368. /**
  18369. *<p><code>ColorFilter</code> 是颜色滤镜。使用 ColorFilter 类可以将 4 x 5 矩阵转换应用于输入图像上的每个像素的 RGBA 颜色和 Alpha 值,以生成具有一组新的 RGBA 颜色和 Alpha 值的结果。该类允许饱和度更改、色相旋转、亮度转 Alpha 以及各种其他效果。您可以将滤镜应用于任何显示对象(即,从 Sprite 类继承的对象)。</p>
  18370. *<p>注意:对于 RGBA 值,最高有效字节代表红色通道值,其后的有效字节分别代表绿色、蓝色和 Alpha 通道值。</p>
  18371. */
  18372. //class laya.filters.ColorFilter extends laya.filters.Filter
  18373. var ColorFilter=(function(_super){
  18374. function ColorFilter(mat){
  18375. /**@private */
  18376. //this._mat=null;
  18377. /**@private */
  18378. //this._alpha=null;
  18379. /**当前使用的矩阵*/
  18380. //this._matrix=null;
  18381. ColorFilter.__super.call(this);
  18382. if (!mat)mat=this._copyMatrix(ColorFilter.IDENTITY_MATRIX);
  18383. this._mat=new Float32Array(16);
  18384. this._alpha=new Float32Array(4);
  18385. this.setByMatrix(mat);
  18386. }
  18387. __class(ColorFilter,'laya.filters.ColorFilter',_super);
  18388. var __proto=ColorFilter.prototype;
  18389. Laya.imps(__proto,{"laya.filters.IFilter":true})
  18390. /**
  18391. *设置为灰色滤镜
  18392. */
  18393. __proto.gray=function(){
  18394. return this.setByMatrix(ColorFilter.GRAY_MATRIX);
  18395. }
  18396. /**
  18397. *设置为变色滤镜
  18398. *@param red 红色增量,范围:0~255
  18399. *@param green 绿色增量,范围:0~255
  18400. *@param blue 蓝色增量,范围:0~255
  18401. *@param alpha alpha,范围:0~1
  18402. */
  18403. __proto.color=function(red,green,blue,alpha){
  18404. (red===void 0)&& (red=0);
  18405. (green===void 0)&& (green=0);
  18406. (blue===void 0)&& (blue=0);
  18407. (alpha===void 0)&& (alpha=1);
  18408. return this.setByMatrix([1,0,0,0,red,0,1,0,0,green,0,0,1,0,blue,0,0,0,1,alpha]);
  18409. }
  18410. /**
  18411. *设置滤镜色
  18412. *@param color 颜色值
  18413. */
  18414. __proto.setColor=function(color){
  18415. var arr=ColorUtils.create(color).arrColor;
  18416. 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];
  18417. return this.setByMatrix(mt);
  18418. }
  18419. /**
  18420. *设置矩阵数据
  18421. *@param matrix 由 20 个项目(排列成 4 x 5 矩阵)组成的数组
  18422. *@return this
  18423. */
  18424. __proto.setByMatrix=function(matrix){
  18425. if (this._matrix !=matrix)this._copyMatrix(matrix);
  18426. var j=0;
  18427. var z=0;
  18428. for (var i=0;i < 20;i++){
  18429. if (i % 5 !=4){
  18430. this._mat[j++]=matrix[i];
  18431. }else {
  18432. this._alpha[z++]=matrix[i];
  18433. }
  18434. }
  18435. return this;
  18436. }
  18437. /**
  18438. *调整颜色,包括亮度,对比度,饱和度和色调
  18439. *@param brightness 亮度,范围:-100~100
  18440. *@param contrast 对比度,范围:-100~100
  18441. *@param saturation 饱和度,范围:-100~100
  18442. *@param hue 色调,范围:-180~180
  18443. *@return this
  18444. */
  18445. __proto.adjustColor=function(brightness,contrast,saturation,hue){
  18446. this.adjustHue(hue);
  18447. this.adjustContrast(contrast);
  18448. this.adjustBrightness(brightness);
  18449. this.adjustSaturation(saturation);
  18450. return this;
  18451. }
  18452. /**
  18453. *调整亮度
  18454. *@param brightness 亮度,范围:-100~100
  18455. *@return this
  18456. */
  18457. __proto.adjustBrightness=function(brightness){
  18458. brightness=this._clampValue(brightness,100);
  18459. if (brightness==0 || isNaN(brightness))return this;
  18460. 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]);
  18461. }
  18462. /**
  18463. *调整对比度
  18464. *@param contrast 对比度,范围:-100~100
  18465. *@return this
  18466. */
  18467. __proto.adjustContrast=function(contrast){
  18468. contrast=this._clampValue(contrast,100);
  18469. if (contrast==0 || isNaN(contrast))return this;
  18470. var x=NaN;
  18471. if (contrast < 0){
  18472. x=127+contrast / 100 *127
  18473. }else {
  18474. x=contrast % 1;
  18475. if (x==0){
  18476. x=ColorFilter.DELTA_INDEX[contrast];
  18477. }else {
  18478. x=ColorFilter.DELTA_INDEX[(contrast << 0)] *(1-x)+ColorFilter.DELTA_INDEX[(contrast << 0)+1] *x;
  18479. }
  18480. x=x *127+127;
  18481. };
  18482. var x1=x / 127;
  18483. var x2=(127-x)*0.5;
  18484. 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]);
  18485. }
  18486. /**
  18487. *调整饱和度
  18488. *@param saturation 饱和度,范围:-100~100
  18489. *@return this
  18490. */
  18491. __proto.adjustSaturation=function(saturation){
  18492. saturation=this._clampValue(saturation,100);
  18493. if (saturation==0 || isNaN(saturation))return this;
  18494. var x=1+((saturation > 0)? 3 *saturation / 100 :saturation / 100);
  18495. var dx=1-x;
  18496. var r=0.3086 *dx;
  18497. var g=0.6094 *dx;
  18498. var b=0.0820 *dx;
  18499. 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]);
  18500. }
  18501. /**
  18502. *调整色调
  18503. *@param hue 色调,范围:-180~180
  18504. *@return this
  18505. */
  18506. __proto.adjustHue=function(hue){
  18507. hue=this._clampValue(hue,180)/ 180 *Math.PI;
  18508. if (hue==0 || isNaN(hue))return this;
  18509. var cos=Math.cos(hue);
  18510. var sin=Math.sin(hue);
  18511. var r=0.213;
  18512. var g=0.715;
  18513. var b=0.072;
  18514. 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]);
  18515. }
  18516. /**
  18517. *重置成单位矩阵,去除滤镜效果
  18518. */
  18519. __proto.reset=function(){
  18520. return this.setByMatrix(this._copyMatrix(ColorFilter.IDENTITY_MATRIX));
  18521. }
  18522. /**
  18523. *矩阵乘法
  18524. *@param matrix
  18525. *@return this
  18526. */
  18527. __proto._multiplyMatrix=function(matrix){
  18528. var col=[];
  18529. this._matrix=this._fixMatrix(this._matrix);
  18530. for (var i=0;i < 5;i++){
  18531. for (var j=0;j < 5;j++){
  18532. col[j]=this._matrix[j+i *5];
  18533. }
  18534. for (j=0;j < 5;j++){
  18535. var val=0;
  18536. for (var k=0;k < 5;k++){
  18537. val+=matrix[j+k *5] *col[k];
  18538. }
  18539. this._matrix[j+i *5]=val;
  18540. }
  18541. }
  18542. return this.setByMatrix(this._matrix);
  18543. }
  18544. /**
  18545. *规范值的范围
  18546. *@param val 当前值
  18547. *@param limit 值的范围-limit~limit
  18548. */
  18549. __proto._clampValue=function(val,limit){
  18550. return Math.min(limit,Math.max(-limit,val));
  18551. }
  18552. /**
  18553. *规范矩阵,将矩阵调整到正确的大小
  18554. *@param matrix 需要调整的矩阵
  18555. */
  18556. __proto._fixMatrix=function(matrix){
  18557. if (matrix==null)return ColorFilter.IDENTITY_MATRIX;
  18558. if (matrix.length < 25)matrix=matrix.slice(0,matrix.length).concat(ColorFilter.IDENTITY_MATRIX.slice(matrix.length,25));
  18559. else if (matrix.length > 25)matrix=matrix.slice(0,25);
  18560. return matrix;
  18561. }
  18562. /**
  18563. *复制矩阵
  18564. */
  18565. __proto._copyMatrix=function(matrix){
  18566. var len=25;
  18567. if (!this._matrix)this._matrix=[];
  18568. for (var i=0;i < len;i++){
  18569. this._matrix[i]=matrix[i];
  18570. }
  18571. return this._matrix;
  18572. }
  18573. /**@private */
  18574. __getset(0,__proto,'type',function(){
  18575. return 0x20;
  18576. });
  18577. ColorFilter.LENGTH=25;
  18578. __static(ColorFilter,
  18579. ['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];}
  18580. ]);
  18581. return ColorFilter;
  18582. })(Filter)
  18583. /**
  18584. *cache as normal 模式下的生成的canvas的渲染。
  18585. */
  18586. //class laya.webgl.submit.SubmitCanvas extends laya.webgl.submit.Submit
  18587. var SubmitCanvas=(function(_super){
  18588. function SubmitCanvas(){
  18589. // 用来计算当前的世界矩阵
  18590. //this.canv=null;
  18591. this._matrix=new Matrix();
  18592. this._matrix4=CONST3D2D.defaultMatrix4.concat();
  18593. SubmitCanvas.__super.call(this,/*laya.webgl.submit.Submit.TYPE_2D*/10000);
  18594. this.shaderValue=new Value2D(0,0);
  18595. }
  18596. __class(SubmitCanvas,'laya.webgl.submit.SubmitCanvas',_super);
  18597. var __proto=SubmitCanvas.prototype;
  18598. __proto.renderSubmit=function(){
  18599. var preAlpha=RenderState2D.worldAlpha;
  18600. var preMatrix4=RenderState2D.worldMatrix4;
  18601. var preMatrix=RenderState2D.worldMatrix;
  18602. var preFilters=RenderState2D.worldFilters;
  18603. var preWorldShaderDefines=RenderState2D.worldShaderDefines;
  18604. var v=this.shaderValue;
  18605. var m=this._matrix;
  18606. var m4=this._matrix4;
  18607. var mout=Matrix.TEMP;
  18608. Matrix.mul(m,preMatrix,mout);
  18609. m4[0]=mout.a;
  18610. m4[1]=mout.b;
  18611. m4[4]=mout.c;
  18612. m4[5]=mout.d;
  18613. m4[12]=mout.tx;
  18614. m4[13]=mout.ty;
  18615. RenderState2D.worldMatrix=mout.clone();
  18616. RenderState2D.worldMatrix4=m4;
  18617. RenderState2D.worldAlpha=RenderState2D.worldAlpha *v.alpha;
  18618. if (v.filters && v.filters.length){
  18619. RenderState2D.worldFilters=v.filters;
  18620. RenderState2D.worldShaderDefines=v.defines;
  18621. }
  18622. this.canv['flushsubmit']();
  18623. RenderState2D.worldAlpha=preAlpha;
  18624. RenderState2D.worldMatrix4=preMatrix4;
  18625. RenderState2D.worldMatrix.destroy();
  18626. RenderState2D.worldMatrix=preMatrix;
  18627. RenderState2D.worldFilters=preFilters;
  18628. RenderState2D.worldShaderDefines=preWorldShaderDefines;
  18629. return 1;
  18630. }
  18631. __proto.releaseRender=function(){
  18632. if((--this._ref)<1){
  18633. var cache=SubmitCanvas.POOL;
  18634. this._mesh=null;
  18635. cache[cache._length++]=this;
  18636. }
  18637. }
  18638. //TODO:coverage
  18639. __proto.clone=function(context,mesh,pos){
  18640. return null;
  18641. }
  18642. //TODO:coverage
  18643. __proto.getRenderType=function(){
  18644. return /*laya.webgl.submit.Submit.TYPE_CANVAS*/10003;
  18645. }
  18646. SubmitCanvas.create=function(canvas,alpha,filters){
  18647. var o=(!SubmitCanvas.POOL._length)? (new SubmitCanvas()):SubmitCanvas.POOL[--SubmitCanvas.POOL._length];
  18648. o.canv=canvas;
  18649. o._ref=1;
  18650. o._numEle=0;
  18651. var v=o.shaderValue;
  18652. v.alpha=alpha;
  18653. v.defines.setValue(0);
  18654. filters && filters.length && v.setFilters(filters);
  18655. return o;
  18656. }
  18657. SubmitCanvas.POOL=[];
  18658. SubmitCanvas.__init$=function(){
  18659. ;;{SubmitCanvas.POOL._length=0};
  18660. }
  18661. return SubmitCanvas;
  18662. })(Submit)
  18663. /**
  18664. *<code>Script</code> 类用于创建脚本的父类,该类为抽象类,不允许实例。
  18665. *组件的生命周期
  18666. */
  18667. //class laya.components.Script extends laya.components.Component
  18668. var Script=(function(_super){
  18669. function Script(){
  18670. Script.__super.call(this);;
  18671. }
  18672. __class(Script,'laya.components.Script',_super);
  18673. var __proto=Script.prototype;
  18674. /**
  18675. *@inheritDoc
  18676. */
  18677. __proto._onAwake=function(){
  18678. this.onAwake();
  18679. if (this.onStart!==laya.components.Script.prototype.onStart){
  18680. Laya.startTimer.callLater(this,this.onStart);
  18681. }
  18682. }
  18683. /**
  18684. *@inheritDoc
  18685. */
  18686. __proto._onEnable=function(){
  18687. var proto=laya.components.Script.prototype;
  18688. if (this.onTriggerEnter!==proto.onTriggerEnter){
  18689. this.owner.on(/*laya.events.Event.TRIGGER_ENTER*/"triggerenter",this,this.onTriggerEnter);
  18690. }
  18691. if (this.onTriggerStay!==proto.onTriggerStay){
  18692. this.owner.on(/*laya.events.Event.TRIGGER_STAY*/"triggerstay",this,this.onTriggerStay);
  18693. }
  18694. if (this.onTriggerExit!==proto.onTriggerExit){
  18695. this.owner.on(/*laya.events.Event.TRIGGER_EXIT*/"triggerexit",this,this.onTriggerExit);
  18696. }
  18697. if (this.onMouseDown!==proto.onMouseDown){
  18698. this.owner.on(/*laya.events.Event.MOUSE_DOWN*/"mousedown",this,this.onMouseDown);
  18699. }
  18700. if (this.onMouseUp!==proto.onMouseUp){
  18701. this.owner.on(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onMouseUp);
  18702. }
  18703. if (this.onClick!==proto.onClick){
  18704. this.owner.on(/*laya.events.Event.CLICK*/"click",this,this.onClick);
  18705. }
  18706. if (this.onStageMouseDown!==proto.onStageMouseDown){
  18707. Laya.stage.on(/*laya.events.Event.MOUSE_DOWN*/"mousedown",this,this.onStageMouseDown);
  18708. }
  18709. if (this.onStageMouseUp!==proto.onStageMouseUp){
  18710. Laya.stage.on(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.onStageMouseUp);
  18711. }
  18712. if (this.onStageClick!==proto.onStageClick){
  18713. Laya.stage.on(/*laya.events.Event.CLICK*/"click",this,this.onStageClick);
  18714. }
  18715. if (this.onStageMouseMove!==proto.onStageMouseMove){
  18716. Laya.stage.on(/*laya.events.Event.MOUSE_MOVE*/"mousemove",this,this.onStageMouseMove);
  18717. }
  18718. if (this.onDoubleClick!==proto.onDoubleClick){
  18719. this.owner.on(/*laya.events.Event.DOUBLE_CLICK*/"doubleclick",this,this.onDoubleClick);
  18720. }
  18721. if (this.onRightClick!==proto.onRightClick){
  18722. this.owner.on(/*laya.events.Event.RIGHT_CLICK*/"rightclick",this,this.onRightClick);
  18723. }
  18724. if (this.onMouseMove!==proto.onMouseMove){
  18725. this.owner.on(/*laya.events.Event.MOUSE_MOVE*/"mousemove",this,this.onMouseMove);
  18726. }
  18727. if (this.onMouseOver!==proto.onMouseOver){
  18728. this.owner.on(/*laya.events.Event.MOUSE_OVER*/"mouseover",this,this.onMouseOver);
  18729. }
  18730. if (this.onMouseOut!==proto.onMouseOut){
  18731. this.owner.on(/*laya.events.Event.MOUSE_OUT*/"mouseout",this,this.onMouseOut);
  18732. }
  18733. if (this.onKeyDown!==proto.onKeyDown){
  18734. Laya.stage.on(/*laya.events.Event.KEY_DOWN*/"keydown",this,this.onKeyDown);
  18735. }
  18736. if (this.onKeyPress!==proto.onKeyPress){
  18737. Laya.stage.on(/*laya.events.Event.KEY_PRESS*/"keypress",this,this.onKeyPress);
  18738. }
  18739. if (this.onKeyUp!==proto.onKeyUp){
  18740. Laya.stage.on(/*laya.events.Event.KEY_UP*/"keyup",this,this.onKeyUp);
  18741. }
  18742. if (this.onUpdate!==proto.onUpdate){
  18743. Laya.updateTimer.frameLoop(1,this,this.onUpdate);
  18744. }
  18745. if (this.onLateUpdate!==proto.onLateUpdate){
  18746. Laya.lateTimer.frameLoop(1,this,this.onLateUpdate);
  18747. }
  18748. if (this.onPreRender!==proto.onPreRender){
  18749. Laya.lateTimer.frameLoop(1,this,this.onPreRender);
  18750. }
  18751. }
  18752. /**
  18753. *@inheritDoc
  18754. */
  18755. __proto._onDisable=function(){
  18756. this.owner.offAllCaller(this);
  18757. Laya.stage.offAllCaller(this);
  18758. Laya.startTimer.clearAll(this);
  18759. Laya.updateTimer.clearAll(this);
  18760. Laya.lateTimer.clearAll(this);
  18761. }
  18762. /**
  18763. *@inheritDoc
  18764. */
  18765. __proto._isScript=function(){
  18766. return true;
  18767. }
  18768. /**
  18769. *@inheritDoc
  18770. */
  18771. __proto._onDestroy=function(){
  18772. this.onDestroy();
  18773. }
  18774. /**
  18775. *组件被激活后执行,此时所有节点和组件均已创建完毕,次方法只执行一次
  18776. *此方法为虚方法,使用时重写覆盖即可
  18777. */
  18778. __proto.onAwake=function(){}
  18779. /**
  18780. *组件被启用后执行,比如节点被添加到舞台后
  18781. *此方法为虚方法,使用时重写覆盖即可
  18782. */
  18783. __proto.onEnable=function(){}
  18784. /**
  18785. *第一次执行update之前执行,只会执行一次
  18786. *此方法为虚方法,使用时重写覆盖即可
  18787. */
  18788. __proto.onStart=function(){}
  18789. /**
  18790. *开始碰撞时执行
  18791. *此方法为虚方法,使用时重写覆盖即可
  18792. */
  18793. __proto.onTriggerEnter=function(other,self,contact){}
  18794. /**
  18795. *持续碰撞时执行
  18796. *此方法为虚方法,使用时重写覆盖即可
  18797. */
  18798. __proto.onTriggerStay=function(other,self,contact){}
  18799. /**
  18800. *结束碰撞时执行
  18801. *此方法为虚方法,使用时重写覆盖即可
  18802. */
  18803. __proto.onTriggerExit=function(other,self,contact){}
  18804. /**
  18805. *鼠标按下时执行
  18806. *此方法为虚方法,使用时重写覆盖即可
  18807. */
  18808. __proto.onMouseDown=function(e){}
  18809. /**
  18810. *鼠标抬起时执行
  18811. *此方法为虚方法,使用时重写覆盖即可
  18812. */
  18813. __proto.onMouseUp=function(e){}
  18814. /**
  18815. *鼠标点击时执行
  18816. *此方法为虚方法,使用时重写覆盖即可
  18817. */
  18818. __proto.onClick=function(e){}
  18819. /**
  18820. *鼠标在舞台按下时执行
  18821. *此方法为虚方法,使用时重写覆盖即可
  18822. */
  18823. __proto.onStageMouseDown=function(e){}
  18824. /**
  18825. *鼠标在舞台抬起时执行
  18826. *此方法为虚方法,使用时重写覆盖即可
  18827. */
  18828. __proto.onStageMouseUp=function(e){}
  18829. /**
  18830. *鼠标在舞台点击时执行
  18831. *此方法为虚方法,使用时重写覆盖即可
  18832. */
  18833. __proto.onStageClick=function(e){}
  18834. /**
  18835. *鼠标在舞台移动时执行
  18836. *此方法为虚方法,使用时重写覆盖即可
  18837. */
  18838. __proto.onStageMouseMove=function(e){}
  18839. /**
  18840. *鼠标双击时执行
  18841. *此方法为虚方法,使用时重写覆盖即可
  18842. */
  18843. __proto.onDoubleClick=function(e){}
  18844. /**
  18845. *鼠标右键点击时执行
  18846. *此方法为虚方法,使用时重写覆盖即可
  18847. */
  18848. __proto.onRightClick=function(e){}
  18849. /**
  18850. *鼠标移动时执行
  18851. *此方法为虚方法,使用时重写覆盖即可
  18852. */
  18853. __proto.onMouseMove=function(e){}
  18854. /**
  18855. *鼠标经过节点时触发
  18856. *此方法为虚方法,使用时重写覆盖即可
  18857. */
  18858. __proto.onMouseOver=function(e){}
  18859. /**
  18860. *鼠标离开节点时触发
  18861. *此方法为虚方法,使用时重写覆盖即可
  18862. */
  18863. __proto.onMouseOut=function(e){}
  18864. /**
  18865. *键盘按下时执行
  18866. *此方法为虚方法,使用时重写覆盖即可
  18867. */
  18868. __proto.onKeyDown=function(e){}
  18869. /**
  18870. *键盘产生一个字符时执行
  18871. *此方法为虚方法,使用时重写覆盖即可
  18872. */
  18873. __proto.onKeyPress=function(e){}
  18874. /**
  18875. *键盘抬起时执行
  18876. *此方法为虚方法,使用时重写覆盖即可
  18877. */
  18878. __proto.onKeyUp=function(e){}
  18879. /**
  18880. *每帧更新时执行,尽量不要在这里写大循环逻辑或者使用getComponent方法
  18881. *此方法为虚方法,使用时重写覆盖即可
  18882. */
  18883. __proto.onUpdate=function(){}
  18884. /**
  18885. *每帧更新时执行,在update之后执行,尽量不要在这里写大循环逻辑或者使用getComponent方法
  18886. *此方法为虚方法,使用时重写覆盖即可
  18887. */
  18888. __proto.onLateUpdate=function(){}
  18889. /**
  18890. *渲染之前执行
  18891. *此方法为虚方法,使用时重写覆盖即可
  18892. */
  18893. __proto.onPreRender=function(){}
  18894. /**
  18895. *渲染之后执行
  18896. *此方法为虚方法,使用时重写覆盖即可
  18897. */
  18898. __proto.onPostRender=function(){}
  18899. /**
  18900. *组件被禁用时执行,比如从节点从舞台移除后
  18901. *此方法为虚方法,使用时重写覆盖即可
  18902. */
  18903. __proto.onDisable=function(){}
  18904. /**
  18905. *手动调用节点销毁时执行
  18906. *此方法为虚方法,使用时重写覆盖即可
  18907. */
  18908. __proto.onDestroy=function(){}
  18909. /**
  18910. *@inheritDoc
  18911. */
  18912. __getset(0,__proto,'isSingleton',function(){
  18913. return false;
  18914. });
  18915. return Script;
  18916. })(Component)
  18917. /**
  18918. *@private
  18919. *使用Audio标签播放声音
  18920. */
  18921. //class laya.media.h5audio.AudioSound extends laya.events.EventDispatcher
  18922. var AudioSound=(function(_super){
  18923. function AudioSound(){
  18924. /**
  18925. *声音URL
  18926. */
  18927. this.url=null;
  18928. /**
  18929. *播放用的audio标签
  18930. */
  18931. this.audio=null;
  18932. /**
  18933. *是否已加载完成
  18934. */
  18935. this.loaded=false;
  18936. AudioSound.__super.call(this);
  18937. }
  18938. __class(AudioSound,'laya.media.h5audio.AudioSound',_super);
  18939. var __proto=AudioSound.prototype;
  18940. /**
  18941. *释放声音
  18942. *
  18943. */
  18944. __proto.dispose=function(){
  18945. var ad=AudioSound._audioCache[this.url];
  18946. Pool.clearBySign("audio:"+this.url);
  18947. if (ad){
  18948. if (!Render.isConchApp){
  18949. ad.src="";
  18950. }
  18951. delete AudioSound._audioCache[this.url];
  18952. }
  18953. }
  18954. /**
  18955. *加载声音
  18956. *@param url
  18957. *
  18958. */
  18959. __proto.load=function(url){
  18960. url=URL.formatURL(url);
  18961. this.url=url;
  18962. var ad;
  18963. if (url==SoundManager._bgMusic){
  18964. AudioSound._initMusicAudio();
  18965. ad=AudioSound._musicAudio;
  18966. if (ad.src !=url){
  18967. AudioSound._audioCache[ad.src]=null;
  18968. ad=null;
  18969. }
  18970. }else{
  18971. ad=AudioSound._audioCache[url];
  18972. }
  18973. if (ad && ad.readyState >=2){
  18974. this.event(/*laya.events.Event.COMPLETE*/"complete");
  18975. return;
  18976. }
  18977. if (!ad){
  18978. if (url==SoundManager._bgMusic){
  18979. AudioSound._initMusicAudio();
  18980. ad=AudioSound._musicAudio;
  18981. }else{
  18982. ad=Browser.createElement("audio");
  18983. }
  18984. AudioSound._audioCache[url]=ad;
  18985. ad.src=url;
  18986. }
  18987. ad.addEventListener("canplaythrough",onLoaded);
  18988. ad.addEventListener("error",onErr);
  18989. var me=this;
  18990. function onLoaded (){
  18991. offs();
  18992. me.loaded=true;
  18993. me.event(/*laya.events.Event.COMPLETE*/"complete");
  18994. }
  18995. function onErr (){
  18996. ad.load=null;
  18997. offs();
  18998. me.event(/*laya.events.Event.ERROR*/"error");
  18999. }
  19000. function offs (){
  19001. ad.removeEventListener("canplaythrough",onLoaded);
  19002. ad.removeEventListener("error",onErr);
  19003. }
  19004. this.audio=ad;
  19005. if (ad.load){
  19006. ad.load();
  19007. }else {
  19008. onErr();
  19009. }
  19010. }
  19011. /**
  19012. *播放声音
  19013. *@param startTime 起始时间
  19014. *@param loops 循环次数
  19015. *@return
  19016. *
  19017. */
  19018. __proto.play=function(startTime,loops){
  19019. (startTime===void 0)&& (startTime=0);
  19020. (loops===void 0)&& (loops=0);
  19021. if (!this.url)return null;
  19022. var ad;
  19023. if (this.url==SoundManager._bgMusic){
  19024. ad=AudioSound._musicAudio;
  19025. }else{
  19026. ad=AudioSound._audioCache[this.url];
  19027. }
  19028. if (!ad)return null;
  19029. var tAd;
  19030. tAd=Pool.getItem("audio:"+this.url);
  19031. if (Render.isConchApp){
  19032. if (!tAd){
  19033. tAd=Browser.createElement("audio");
  19034. tAd.src=this.url;
  19035. }
  19036. }
  19037. else {
  19038. if (this.url==SoundManager._bgMusic){
  19039. AudioSound._initMusicAudio();
  19040. tAd=AudioSound._musicAudio;
  19041. tAd.src=this.url;
  19042. }else{
  19043. tAd=tAd ? tAd :ad.cloneNode(true);
  19044. }
  19045. };
  19046. var channel=new AudioSoundChannel(tAd);
  19047. channel.url=this.url;
  19048. channel.loops=loops;
  19049. channel.startTime=startTime;
  19050. channel.play();
  19051. SoundManager.addChannel(channel);
  19052. return channel;
  19053. }
  19054. /**
  19055. *获取总时间。
  19056. */
  19057. __getset(0,__proto,'duration',function(){
  19058. var ad;
  19059. ad=AudioSound._audioCache[this.url];
  19060. if (!ad)
  19061. return 0;
  19062. return ad.duration;
  19063. });
  19064. AudioSound._initMusicAudio=function(){
  19065. if (AudioSound._musicAudio)return;
  19066. if (!AudioSound._musicAudio)AudioSound._musicAudio=Browser.createElement("audio");
  19067. if (!Render.isConchApp){
  19068. Browser.document.addEventListener("mousedown",AudioSound._makeMusicOK);
  19069. }
  19070. }
  19071. AudioSound._makeMusicOK=function(){
  19072. Browser.document.removeEventListener("mousedown",AudioSound._makeMusicOK);
  19073. if (!AudioSound._musicAudio.src){
  19074. AudioSound._musicAudio.src="";
  19075. AudioSound._musicAudio.load();
  19076. }else{
  19077. AudioSound._musicAudio.play();
  19078. }
  19079. }
  19080. AudioSound._audioCache={};
  19081. AudioSound._musicAudio=null;
  19082. return AudioSound;
  19083. })(EventDispatcher)
  19084. /**
  19085. *<code>Sound</code> 类是用来播放控制声音的类。
  19086. *引擎默认有两套声音方案,优先使用WebAudio播放声音,如果WebAudio不可用,则用H5Audio播放,H5Audio在部分机器上有兼容问题(比如不能混音,播放有延迟等)。
  19087. */
  19088. //class laya.media.Sound extends laya.events.EventDispatcher
  19089. var Sound=(function(_super){
  19090. function Sound(){
  19091. Sound.__super.call(this);;
  19092. }
  19093. __class(Sound,'laya.media.Sound',_super);
  19094. var __proto=Sound.prototype;
  19095. /**
  19096. *加载声音。
  19097. *@param url 地址。
  19098. */
  19099. __proto.load=function(url){}
  19100. /**
  19101. *播放声音。
  19102. *@param startTime 开始时间,单位秒
  19103. *@param loops 循环次数,0表示一直循环
  19104. *@return 声道 SoundChannel 对象。
  19105. */
  19106. __proto.play=function(startTime,loops){
  19107. (startTime===void 0)&& (startTime=0);
  19108. (loops===void 0)&& (loops=0);
  19109. return null;
  19110. }
  19111. /**
  19112. *释放声音资源。
  19113. */
  19114. __proto.dispose=function(){}
  19115. /**
  19116. *获取总时间。
  19117. */
  19118. __getset(0,__proto,'duration',function(){
  19119. return 0;
  19120. });
  19121. return Sound;
  19122. })(EventDispatcher)
  19123. /**
  19124. *drawImage,fillRect等会用到的简单的mesh。每次添加必然是一个四边形。
  19125. */
  19126. //class laya.webgl.utils.MeshParticle2D extends laya.webgl.utils.Mesh2D
  19127. var MeshParticle2D=(function(_super){
  19128. //TODO:coverage
  19129. function MeshParticle2D(maxNum){
  19130. MeshParticle2D.__super.call(this,/*CLASS CONST:laya.webgl.utils.MeshParticle2D.const_stride*/116,maxNum*4*116,4);
  19131. this.canReuse=true;
  19132. this.setAttributes(laya.webgl.utils.MeshParticle2D._fixattriInfo);
  19133. this.createQuadIB(maxNum);
  19134. this._quadNum=maxNum;
  19135. }
  19136. __class(MeshParticle2D,'laya.webgl.utils.MeshParticle2D',_super);
  19137. var __proto=MeshParticle2D.prototype;
  19138. __proto.setMaxParticleNum=function(maxNum){
  19139. this._vb._resizeBuffer(maxNum *4 *116,false);
  19140. this.createQuadIB(maxNum);
  19141. }
  19142. //TODO:coverage
  19143. __proto.releaseMesh=function(){;
  19144. this._vb.setByteLength(0);
  19145. this.vertNum=0;
  19146. this.indexNum=0;
  19147. laya.webgl.utils.MeshParticle2D._POOL.push(this);
  19148. }
  19149. //TODO:coverage
  19150. __proto.destroy=function(){
  19151. this._ib.destroy();
  19152. this._vb.destroy();
  19153. this._vb.deleteBuffer();
  19154. }
  19155. MeshParticle2D.getAMesh=function(maxNum){
  19156. if (laya.webgl.utils.MeshParticle2D._POOL.length){
  19157. var ret=laya.webgl.utils.MeshParticle2D._POOL.pop();
  19158. ret.setMaxParticleNum(maxNum);
  19159. return ret;
  19160. }
  19161. return new MeshParticle2D(maxNum);
  19162. }
  19163. MeshParticle2D.const_stride=116;
  19164. MeshParticle2D._POOL=[];
  19165. __static(MeshParticle2D,
  19166. ['_fixattriInfo',function(){return this._fixattriInfo=[
  19167. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,0,
  19168. /*laya.webgl.WebGLContext.FLOAT*/0x1406,3,16,
  19169. /*laya.webgl.WebGLContext.FLOAT*/0x1406,3,28,
  19170. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,40,
  19171. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,56,
  19172. /*laya.webgl.WebGLContext.FLOAT*/0x1406,3,72,
  19173. /*laya.webgl.WebGLContext.FLOAT*/0x1406,2,84,
  19174. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,92,
  19175. /*laya.webgl.WebGLContext.FLOAT*/0x1406,1,108,
  19176. /*laya.webgl.WebGLContext.FLOAT*/0x1406,1,112];}
  19177. ]);
  19178. return MeshParticle2D;
  19179. })(Mesh2D)
  19180. /**
  19181. *<code>Node</code> 类是可放在显示列表中的所有对象的基类。该显示列表管理 Laya 运行时中显示的所有对象。使用 Node 类排列显示列表中的显示对象。Node 对象可以有子显示对象。
  19182. */
  19183. //class laya.display.Node extends laya.events.EventDispatcher
  19184. var Node=(function(_super){
  19185. function Node(){
  19186. /**@private */
  19187. this._bits=0;
  19188. /**@private 父节点对象*/
  19189. this._parent=null;
  19190. /**节点名称。*/
  19191. this.name="";
  19192. /**[只读]是否已经销毁。对象销毁后不能再使用。*/
  19193. this.destroyed=false;
  19194. /**@private */
  19195. this._conchData=null;
  19196. /**@private */
  19197. this._components=null;
  19198. /**@private */
  19199. this._activeChangeScripts=null;
  19200. /**@private */
  19201. this._scene=null;
  19202. Node.__super.call(this);
  19203. this._children=Node.ARRAY_EMPTY;
  19204. this._extUIChild=Node.ARRAY_EMPTY;
  19205. this.createGLBuffer();
  19206. }
  19207. __class(Node,'laya.display.Node',_super);
  19208. var __proto=Node.prototype;
  19209. /**@private */
  19210. __proto.createGLBuffer=function(){}
  19211. /**@private */
  19212. __proto._setBit=function(type,value){
  19213. if (type===/*laya.Const.DISPLAY*/0x10){
  19214. var preValue=this._getBit(type);
  19215. if (preValue !=value)this._updateDisplayedInstage();
  19216. }
  19217. if (value)this._bits |=type;
  19218. else this._bits &=~type;
  19219. }
  19220. /**@private */
  19221. __proto._getBit=function(type){
  19222. return (this._bits & type)!=0;
  19223. }
  19224. /**@private */
  19225. __proto._setUpNoticeChain=function(){
  19226. if (this._getBit(/*laya.Const.DISPLAY*/0x10))this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  19227. }
  19228. /**@private */
  19229. __proto._setBitUp=function(type){
  19230. var ele=this;
  19231. ele._setBit(type,true);
  19232. ele=ele._parent;
  19233. while (ele){
  19234. if (ele._getBit(type))return;
  19235. ele._setBit(type,true);
  19236. ele=ele._parent;
  19237. }
  19238. }
  19239. /**
  19240. *<p>增加事件侦听器,以使侦听器能够接收事件通知。</p>
  19241. *<p>如果侦听鼠标事件,则会自动设置自己和父亲节点的属性 mouseEnabled 的值为 true(如果父节点mouseEnabled=false,则停止设置父节点mouseEnabled属性)。</p>
  19242. *@param type 事件的类型。
  19243. *@param caller 事件侦听函数的执行域。
  19244. *@param listener 事件侦听函数。
  19245. *@param args (可选)事件侦听函数的回调参数。
  19246. *@return 此 EventDispatcher 对象。
  19247. */
  19248. __proto.on=function(type,caller,listener,args){
  19249. if (type===/*laya.events.Event.DISPLAY*/"display" || type===/*laya.events.Event.UNDISPLAY*/"undisplay"){
  19250. if (!this._getBit(/*laya.Const.DISPLAY*/0x10))this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  19251. }
  19252. return this._createListener(type,caller,listener,args,false);
  19253. }
  19254. /**
  19255. *<p>增加事件侦听器,以使侦听器能够接收事件通知,此侦听事件响应一次后则自动移除侦听。</p>
  19256. *<p>如果侦听鼠标事件,则会自动设置自己和父亲节点的属性 mouseEnabled 的值为 true(如果父节点mouseEnabled=false,则停止设置父节点mouseEnabled属性)。</p>
  19257. *@param type 事件的类型。
  19258. *@param caller 事件侦听函数的执行域。
  19259. *@param listener 事件侦听函数。
  19260. *@param args (可选)事件侦听函数的回调参数。
  19261. *@return 此 EventDispatcher 对象。
  19262. */
  19263. __proto.once=function(type,caller,listener,args){
  19264. if (type===/*laya.events.Event.DISPLAY*/"display" || type===/*laya.events.Event.UNDISPLAY*/"undisplay"){
  19265. if (!this._getBit(/*laya.Const.DISPLAY*/0x10))this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  19266. }
  19267. return this._createListener(type,caller,listener,args,true);
  19268. }
  19269. /**
  19270. *<p>销毁此对象。destroy对象默认会把自己从父节点移除,并且清理自身引用关系,等待js自动垃圾回收机制回收。destroy后不能再使用。</p>
  19271. *<p>destroy时会移除自身的事情监听,自身的timer监听,移除子对象及从父节点移除自己。</p>
  19272. *@param destroyChild (可选)是否同时销毁子节点,若值为true,则销毁子节点,否则不销毁子节点。
  19273. */
  19274. __proto.destroy=function(destroyChild){
  19275. (destroyChild===void 0)&& (destroyChild=true);
  19276. this.destroyed=true;
  19277. this._destroyAllComponent();
  19278. this._parent && this._parent.removeChild(this);
  19279. if (this._children){
  19280. if (destroyChild)this.destroyChildren();
  19281. else this.removeChildren();
  19282. }
  19283. this.onDestroy();
  19284. this._children=null;
  19285. this.offAll();
  19286. }
  19287. /**
  19288. *销毁时执行
  19289. *此方法为虚方法,使用时重写覆盖即可
  19290. */
  19291. __proto.onDestroy=function(){}
  19292. /**
  19293. *销毁所有子对象,不销毁自己本身。
  19294. */
  19295. __proto.destroyChildren=function(){
  19296. if (this._children){
  19297. for (var i=0,n=this._children.length;i < n;i++){
  19298. this._children[0].destroy(true);
  19299. }
  19300. }
  19301. }
  19302. /**
  19303. *添加子节点。
  19304. *@param node 节点对象
  19305. *@return 返回添加的节点
  19306. */
  19307. __proto.addChild=function(node){
  19308. if (!node || this.destroyed || node===this)return node;
  19309. if ((node)._zOrder)this._setBit(/*laya.Const.HAS_ZORDER*/0x20,true);
  19310. if (node._parent===this){
  19311. var index=this.getChildIndex(node);
  19312. if (index!==this._children.length-1){
  19313. this._children.splice(index,1);
  19314. this._children.push(node);
  19315. this._childChanged();
  19316. }
  19317. }else {
  19318. node._parent && node._parent.removeChild(node);
  19319. this._children===Node.ARRAY_EMPTY && (this._children=[]);
  19320. this._children.push(node);
  19321. node._setParent(this);
  19322. this._childChanged();
  19323. }
  19324. return node;
  19325. }
  19326. __proto.addInputChild=function(node){
  19327. if (this._extUIChild==Node.ARRAY_EMPTY){
  19328. this._extUIChild=[node];
  19329. }else {
  19330. if (this._extUIChild.indexOf(node)>=0){
  19331. return null;
  19332. }
  19333. this._extUIChild.push(node);
  19334. }
  19335. return null;
  19336. }
  19337. __proto.removeInputChild=function(node){
  19338. var idx=this._extUIChild.indexOf(node);
  19339. if (idx >=0){
  19340. this._extUIChild.splice(idx,1);
  19341. }
  19342. }
  19343. /**
  19344. *批量增加子节点
  19345. *@param ...args 无数子节点。
  19346. */
  19347. __proto.addChildren=function(__args){
  19348. var args=arguments;
  19349. var i=0,n=args.length;
  19350. while (i < n){
  19351. this.addChild(args[i++]);
  19352. }
  19353. }
  19354. /**
  19355. *添加子节点到指定的索引位置。
  19356. *@param node 节点对象。
  19357. *@param index 索引位置。
  19358. *@return 返回添加的节点。
  19359. */
  19360. __proto.addChildAt=function(node,index){
  19361. if (!node || this.destroyed || node===this)return node;
  19362. if ((node)._zOrder)this._setBit(/*laya.Const.HAS_ZORDER*/0x20,true);
  19363. if (index >=0 && index <=this._children.length){
  19364. if (node._parent===this){
  19365. var oldIndex=this.getChildIndex(node);
  19366. this._children.splice(oldIndex,1);
  19367. this._children.splice(index,0,node);
  19368. this._childChanged();
  19369. }else {
  19370. node._parent && node._parent.removeChild(node);
  19371. this._children===Node.ARRAY_EMPTY && (this._children=[]);
  19372. this._children.splice(index,0,node);
  19373. node._setParent(this);
  19374. }
  19375. return node;
  19376. }else {
  19377. throw new Error("appendChildAt:The index is out of bounds");
  19378. }
  19379. }
  19380. /**
  19381. *根据子节点对象,获取子节点的索引位置。
  19382. *@param node 子节点。
  19383. *@return 子节点所在的索引位置。
  19384. */
  19385. __proto.getChildIndex=function(node){
  19386. return this._children.indexOf(node);
  19387. }
  19388. /**
  19389. *根据子节点的名字,获取子节点对象。
  19390. *@param name 子节点的名字。
  19391. *@return 节点对象。
  19392. */
  19393. __proto.getChildByName=function(name){
  19394. var nodes=this._children;
  19395. if (nodes){
  19396. for (var i=0,n=nodes.length;i < n;i++){
  19397. var node=nodes[i];
  19398. if (node.name===name)return node;
  19399. }
  19400. }
  19401. return null;
  19402. }
  19403. /**
  19404. *根据子节点的索引位置,获取子节点对象。
  19405. *@param index 索引位置
  19406. *@return 子节点
  19407. */
  19408. __proto.getChildAt=function(index){
  19409. return this._children[index] || null;
  19410. }
  19411. /**
  19412. *设置子节点的索引位置。
  19413. *@param node 子节点。
  19414. *@param index 新的索引。
  19415. *@return 返回子节点本身。
  19416. */
  19417. __proto.setChildIndex=function(node,index){
  19418. var childs=this._children;
  19419. if (index < 0 || index >=childs.length){
  19420. throw new Error("setChildIndex:The index is out of bounds.");
  19421. };
  19422. var oldIndex=this.getChildIndex(node);
  19423. if (oldIndex < 0)throw new Error("setChildIndex:node is must child of this object.");
  19424. childs.splice(oldIndex,1);
  19425. childs.splice(index,0,node);
  19426. this._childChanged();
  19427. return node;
  19428. }
  19429. /**
  19430. *子节点发生改变。
  19431. *@private
  19432. *@param child 子节点。
  19433. */
  19434. __proto._childChanged=function(child){}
  19435. /**
  19436. *删除子节点。
  19437. *@param node 子节点
  19438. *@return 被删除的节点
  19439. */
  19440. __proto.removeChild=function(node){
  19441. if (!this._children)return node;
  19442. var index=this._children.indexOf(node);
  19443. return this.removeChildAt(index);
  19444. }
  19445. /**
  19446. *从父容器删除自己,如已经被删除不会抛出异常。
  19447. *@return 当前节点( Node )对象。
  19448. */
  19449. __proto.removeSelf=function(){
  19450. this._parent && this._parent.removeChild(this);
  19451. return this;
  19452. }
  19453. /**
  19454. *根据子节点名字删除对应的子节点对象,如果找不到不会抛出异常。
  19455. *@param name 对象名字。
  19456. *@return 查找到的节点( Node )对象。
  19457. */
  19458. __proto.removeChildByName=function(name){
  19459. var node=this.getChildByName(name);
  19460. node && this.removeChild(node);
  19461. return node;
  19462. }
  19463. /**
  19464. *根据子节点索引位置,删除对应的子节点对象。
  19465. *@param index 节点索引位置。
  19466. *@return 被删除的节点。
  19467. */
  19468. __proto.removeChildAt=function(index){
  19469. var node=this.getChildAt(index);
  19470. if (node){
  19471. this._children.splice(index,1);
  19472. node._setParent(null);
  19473. }
  19474. return node;
  19475. }
  19476. /**
  19477. *删除指定索引区间的所有子对象。
  19478. *@param beginIndex 开始索引。
  19479. *@param endIndex 结束索引。
  19480. *@return 当前节点对象。
  19481. */
  19482. __proto.removeChildren=function(beginIndex,endIndex){
  19483. (beginIndex===void 0)&& (beginIndex=0);
  19484. (endIndex===void 0)&& (endIndex=0x7fffffff);
  19485. if (this._children && this._children.length > 0){
  19486. var childs=this._children;
  19487. if (beginIndex===0 && endIndex >=childs.length-1){
  19488. var arr=childs;
  19489. this._children=Node.ARRAY_EMPTY;
  19490. }else {
  19491. arr=childs.splice(beginIndex,endIndex-beginIndex);
  19492. }
  19493. for (var i=0,n=arr.length;i < n;i++){
  19494. arr[i]._setParent(null);
  19495. }
  19496. }
  19497. return this;
  19498. }
  19499. /**
  19500. *替换子节点。
  19501. *@internal 将传入的新节点对象替换到已有子节点索引位置处。
  19502. *@param newNode 新节点。
  19503. *@param oldNode 老节点。
  19504. *@return 返回新节点。
  19505. */
  19506. __proto.replaceChild=function(newNode,oldNode){
  19507. var index=this._children.indexOf(oldNode);
  19508. if (index >-1){
  19509. this._children.splice(index,1,newNode);
  19510. oldNode._setParent(null);
  19511. newNode._setParent(this);
  19512. return newNode;
  19513. }
  19514. return null;
  19515. }
  19516. /**@private */
  19517. __proto._setParent=function(value){
  19518. if (this._parent!==value){
  19519. if (value){
  19520. this._parent=value;
  19521. this._onAdded();
  19522. this.event(/*laya.events.Event.ADDED*/"added");
  19523. if (this._getBit(/*laya.Const.DISPLAY*/0x10)){
  19524. this._setUpNoticeChain();
  19525. value.displayedInStage && this._displayChild(this,true);
  19526. }
  19527. value._childChanged(this);
  19528. }else {
  19529. this._onRemoved();
  19530. this.event(/*laya.events.Event.REMOVED*/"removed");
  19531. this._parent._childChanged();
  19532. if (this._getBit(/*laya.Const.DISPLAY*/0x10))this._displayChild(this,false);
  19533. this._parent=value;
  19534. }
  19535. }
  19536. }
  19537. /**@private */
  19538. __proto._updateDisplayedInstage=function(){
  19539. var ele;
  19540. ele=this;
  19541. var stage=Laya.stage;
  19542. var displayedInStage=false;
  19543. while (ele){
  19544. if (ele._getBit(/*laya.Const.DISPLAY*/0x10)){
  19545. displayedInStage=ele._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80);
  19546. break ;
  19547. }
  19548. if (ele===stage || ele._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80)){
  19549. displayedInStage=true;
  19550. break ;
  19551. }
  19552. ele=ele._parent;
  19553. }
  19554. this._setBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80,displayedInStage);
  19555. }
  19556. /**@private */
  19557. __proto._setDisplay=function(value){
  19558. if (this._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80)!==value){
  19559. this._setBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80,value);
  19560. if (value)this.event(/*laya.events.Event.DISPLAY*/"display");
  19561. else this.event(/*laya.events.Event.UNDISPLAY*/"undisplay");
  19562. }
  19563. }
  19564. /**
  19565. *设置指定节点对象是否可见(是否在渲染列表中)。
  19566. *@private
  19567. *@param node 节点。
  19568. *@param display 是否可见。
  19569. */
  19570. __proto._displayChild=function(node,display){
  19571. var childs=node._children;
  19572. if (childs){
  19573. for (var i=0,n=childs.length;i < n;i++){
  19574. var child=childs[i];
  19575. if (!child._getBit(/*laya.Const.DISPLAY*/0x10))continue ;
  19576. if (child._children.length > 0){
  19577. this._displayChild(child,display);
  19578. }else {
  19579. child._setDisplay(display);
  19580. }
  19581. }
  19582. }
  19583. node._setDisplay(display);
  19584. }
  19585. /**
  19586. *当前容器是否包含指定的 <code>Node</code> 节点对象 。
  19587. *@param node 指定的 <code>Node</code> 节点对象 。
  19588. *@return 一个布尔值表示是否包含指定的 <code>Node</code> 节点对象 。
  19589. */
  19590. __proto.contains=function(node){
  19591. if (node===this)return true;
  19592. while (node){
  19593. if (node._parent===this)return true;
  19594. node=node._parent;
  19595. }
  19596. return false;
  19597. }
  19598. /**
  19599. *定时重复执行某函数。功能同Laya.timer.timerLoop()。
  19600. *@param delay 间隔时间(单位毫秒)。
  19601. *@param caller 执行域(this)。
  19602. *@param method 结束时的回调方法。
  19603. *@param args (可选)回调参数。
  19604. *@param coverBefore (可选)是否覆盖之前的延迟执行,默认为true。
  19605. *@param jumpFrame 时钟是否跳帧。基于时间的循环回调,单位时间间隔内,如能执行多次回调,出于性能考虑,引擎默认只执行一次,设置jumpFrame=true后,则回调会连续执行多次
  19606. */
  19607. __proto.timerLoop=function(delay,caller,method,args,coverBefore,jumpFrame){
  19608. (coverBefore===void 0)&& (coverBefore=true);
  19609. (jumpFrame===void 0)&& (jumpFrame=false);
  19610. var timer=this.scene ? this.scene.timer :Laya.timer;
  19611. timer.loop(delay,caller,method,args,coverBefore,jumpFrame);
  19612. }
  19613. /**
  19614. *定时执行某函数一次。功能同Laya.timer.timerOnce()。
  19615. *@param delay 延迟时间(单位毫秒)。
  19616. *@param caller 执行域(this)。
  19617. *@param method 结束时的回调方法。
  19618. *@param args (可选)回调参数。
  19619. *@param coverBefore (可选)是否覆盖之前的延迟执行,默认为true。
  19620. */
  19621. __proto.timerOnce=function(delay,caller,method,args,coverBefore){
  19622. (coverBefore===void 0)&& (coverBefore=true);
  19623. var timer=this.scene ? this.scene.timer :Laya.timer;
  19624. timer._create(false,false,delay,caller,method,args,coverBefore);
  19625. }
  19626. /**
  19627. *定时重复执行某函数(基于帧率)。功能同Laya.timer.frameLoop()。
  19628. *@param delay 间隔几帧(单位为帧)。
  19629. *@param caller 执行域(this)。
  19630. *@param method 结束时的回调方法。
  19631. *@param args (可选)回调参数。
  19632. *@param coverBefore (可选)是否覆盖之前的延迟执行,默认为true。
  19633. */
  19634. __proto.frameLoop=function(delay,caller,method,args,coverBefore){
  19635. (coverBefore===void 0)&& (coverBefore=true);
  19636. var timer=this.scene ? this.scene.timer :Laya.timer;
  19637. timer._create(true,true,delay,caller,method,args,coverBefore);
  19638. }
  19639. /**
  19640. *定时执行一次某函数(基于帧率)。功能同Laya.timer.frameOnce()。
  19641. *@param delay 延迟几帧(单位为帧)。
  19642. *@param caller 执行域(this)
  19643. *@param method 结束时的回调方法
  19644. *@param args (可选)回调参数
  19645. *@param coverBefore (可选)是否覆盖之前的延迟执行,默认为true
  19646. */
  19647. __proto.frameOnce=function(delay,caller,method,args,coverBefore){
  19648. (coverBefore===void 0)&& (coverBefore=true);
  19649. var timer=this.scene ? this.scene.timer :Laya.timer;
  19650. timer._create(true,false,delay,caller,method,args,coverBefore);
  19651. }
  19652. /**
  19653. *清理定时器。功能同Laya.timer.clearTimer()。
  19654. *@param caller 执行域(this)。
  19655. *@param method 结束时的回调方法。
  19656. */
  19657. __proto.clearTimer=function(caller,method){
  19658. var timer=this.scene ? this.scene.timer :Laya.timer;
  19659. timer.clear(caller,method);
  19660. }
  19661. /**
  19662. *<p>延迟运行指定的函数。</p>
  19663. *<p>在控件被显示在屏幕之前调用,一般用于延迟计算数据。</p>
  19664. *@param method 要执行的函数的名称。例如,functionName。
  19665. *@param args 传递给 <code>method</code> 函数的可选参数列表。
  19666. *
  19667. *@see #runCallLater()
  19668. */
  19669. __proto.callLater=function(method,args){
  19670. var timer=this.scene ? this.scene.timer :Laya.timer;
  19671. timer.callLater(this,method,args);
  19672. }
  19673. /**
  19674. *<p>如果有需要延迟调用的函数(通过 <code>callLater</code> 函数设置),则立即执行延迟调用函数。</p>
  19675. *@param method 要执行的函数名称。例如,functionName。
  19676. *@see #callLater()
  19677. */
  19678. __proto.runCallLater=function(method){
  19679. var timer=this.scene ? this.scene.timer :Laya.timer;
  19680. timer.runCallLater(this,method);
  19681. }
  19682. /**
  19683. *@private
  19684. */
  19685. __proto._onActive=function(){
  19686. Stat.spriteCount++;
  19687. }
  19688. /**
  19689. *@private
  19690. */
  19691. __proto._onInActive=function(){
  19692. Stat.spriteCount--;
  19693. }
  19694. /**
  19695. *@private
  19696. */
  19697. __proto._onActiveInScene=function(){}
  19698. /**
  19699. *@private
  19700. */
  19701. __proto._onInActiveInScene=function(){}
  19702. /**
  19703. *@private
  19704. */
  19705. __proto._parse=function(data,spriteMap){}
  19706. /**
  19707. *@private
  19708. */
  19709. __proto._setBelongScene=function(scene){
  19710. if (!this._scene){
  19711. this._scene=scene;
  19712. if (this._components){
  19713. for (var i=0,n=this._components.length;i < n;i++)
  19714. this._components[i]._setActiveInScene(true);
  19715. }
  19716. this._onActiveInScene();
  19717. for (i=0,n=this._children.length;i < n;i++)
  19718. this._children[i]._setBelongScene(scene);
  19719. }
  19720. }
  19721. /**
  19722. *@private
  19723. */
  19724. __proto._setUnBelongScene=function(){
  19725. if (this._scene!==this){
  19726. this._onInActiveInScene();
  19727. if (this._components){
  19728. for (var i=0,n=this._components.length;i < n;i++)
  19729. this._components[i]._setActiveInScene(false);
  19730. }
  19731. this._scene=null;
  19732. for (i=0,n=this._children.length;i < n;i++)
  19733. this._children[i]._setUnBelongScene();
  19734. }
  19735. }
  19736. /**
  19737. *组件被激活后执行,此时所有节点和组件均已创建完毕,次方法只执行一次
  19738. *此方法为虚方法,使用时重写覆盖即可
  19739. */
  19740. __proto.onAwake=function(){}
  19741. /**
  19742. *组件被启用后执行,比如节点被添加到舞台后
  19743. *此方法为虚方法,使用时重写覆盖即可
  19744. */
  19745. __proto.onEnable=function(){}
  19746. /**
  19747. *@private
  19748. */
  19749. __proto._processActive=function(){
  19750. (this._activeChangeScripts)|| (this._activeChangeScripts=[]);
  19751. this._activeHierarchy(this._activeChangeScripts);
  19752. this._activeScripts();
  19753. }
  19754. /**
  19755. *@private
  19756. */
  19757. __proto._activeHierarchy=function(activeChangeScripts){
  19758. this._setBit(/*laya.Const.ACTIVE_INHIERARCHY*/0x02,true);
  19759. if (this._components){
  19760. for (var i=0,n=this._components.length;i < n;i++){
  19761. var comp=this._components[i];
  19762. comp._setActive(true);
  19763. (comp._isScript()&& comp._enabled)&& (activeChangeScripts.push(comp));
  19764. }
  19765. }
  19766. this._onActive();
  19767. for (i=0,n=this._children.length;i < n;i++){
  19768. var child=this._children[i];
  19769. (!child._getBit(/*laya.Const.NOT_ACTIVE*/0x01))&& (child._activeHierarchy(activeChangeScripts));
  19770. }
  19771. if (!this._getBit(/*laya.Const.AWAKED*/0x04)){
  19772. this._setBit(/*laya.Const.AWAKED*/0x04,true);
  19773. this.onAwake();
  19774. }
  19775. this.onEnable();
  19776. }
  19777. /**
  19778. *@private
  19779. */
  19780. __proto._activeScripts=function(){
  19781. for (var i=0,n=this._activeChangeScripts.length;i < n;i++)
  19782. this._activeChangeScripts[i].onEnable();
  19783. this._activeChangeScripts.length=0;
  19784. }
  19785. /**
  19786. *@private
  19787. */
  19788. __proto._processInActive=function(){
  19789. (this._activeChangeScripts)|| (this._activeChangeScripts=[]);
  19790. this._inActiveHierarchy(this._activeChangeScripts);
  19791. this._inActiveScripts();
  19792. }
  19793. /**
  19794. *@private
  19795. */
  19796. __proto._inActiveHierarchy=function(activeChangeScripts){
  19797. this._onInActive();
  19798. if (this._components){
  19799. for (var i=0,n=this._components.length;i < n;i++){
  19800. var comp=this._components[i];
  19801. comp._setActive(false);
  19802. (comp._isScript()&& comp._enabled)&& (activeChangeScripts.push(comp));
  19803. }
  19804. }
  19805. this._setBit(/*laya.Const.ACTIVE_INHIERARCHY*/0x02,false);
  19806. for (i=0,n=this._children.length;i < n;i++){
  19807. var child=this._children[i];
  19808. (child && !child._getBit(/*laya.Const.NOT_ACTIVE*/0x01))&& (child._inActiveHierarchy(activeChangeScripts));
  19809. }
  19810. this.onDisable();
  19811. }
  19812. /**
  19813. *@private
  19814. */
  19815. __proto._inActiveScripts=function(){
  19816. for (var i=0,n=this._activeChangeScripts.length;i < n;i++)
  19817. this._activeChangeScripts[i].onDisable();
  19818. this._activeChangeScripts.length=0;
  19819. }
  19820. /**
  19821. *组件被禁用时执行,比如从节点从舞台移除后
  19822. *此方法为虚方法,使用时重写覆盖即可
  19823. */
  19824. __proto.onDisable=function(){}
  19825. /**
  19826. *@private
  19827. */
  19828. __proto._onAdded=function(){
  19829. if (this._activeChangeScripts && this._activeChangeScripts.length!==0){
  19830. 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.";
  19831. }else {
  19832. var parentScene=this._parent.scene;
  19833. parentScene && this._setBelongScene(parentScene);
  19834. (this._parent.activeInHierarchy && this.active)&& this._processActive();
  19835. }
  19836. }
  19837. /**
  19838. *@private
  19839. */
  19840. __proto._onRemoved=function(){
  19841. if (this._activeChangeScripts && this._activeChangeScripts.length!==0){
  19842. 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.";
  19843. }else {
  19844. (this._parent.activeInHierarchy && this.active)&& this._processInActive();
  19845. this._parent.scene && this._setUnBelongScene();
  19846. }
  19847. }
  19848. /**
  19849. *@private
  19850. */
  19851. __proto._addComponentInstance=function(comp){
  19852. this._components=this._components||[];
  19853. this._components.push(comp);
  19854. comp.owner=this;
  19855. comp._onAdded();
  19856. if (this.activeInHierarchy){
  19857. comp._setActive(true);
  19858. (comp._isScript()&& comp._enabled)&& ((comp).onEnable());
  19859. }
  19860. this._scene && comp._setActiveInScene(true);
  19861. }
  19862. /**
  19863. *@private
  19864. */
  19865. __proto._destroyComponent=function(comp){
  19866. if (this._components){
  19867. for (var i=0,n=this._components.length;i < n;i++){
  19868. var item=this._components[i];
  19869. if (item===comp){
  19870. item._destroy();
  19871. this._components.splice(i,1);
  19872. break ;
  19873. }
  19874. }
  19875. }
  19876. }
  19877. /**
  19878. *@private
  19879. */
  19880. __proto._destroyAllComponent=function(){
  19881. if (this._components){
  19882. for (var i=0,n=this._components.length;i < n;i++){
  19883. var item=this._components[i];
  19884. item._destroy();
  19885. }
  19886. this._components.length=0;
  19887. }
  19888. }
  19889. /**
  19890. *@private 克隆。
  19891. *@param destObject 克隆源。
  19892. */
  19893. __proto._cloneTo=function(destObject,srcRoot,dstRoot){
  19894. var destNode=destObject;
  19895. if (this._components){
  19896. for (var i=0,n=this._components.length;i < n;i++){
  19897. var destComponent=destNode.addComponent(this._components[i].constructor);
  19898. this._components[i]._cloneTo(destComponent);
  19899. }
  19900. }
  19901. }
  19902. /**
  19903. *添加组件实例。
  19904. *@param comp 组件实例。
  19905. *@return 组件。
  19906. */
  19907. __proto.addComponentIntance=function(comp){
  19908. if (comp.owner)
  19909. throw "Node:the component has belong to other node.";
  19910. if (comp.isSingleton && this.getComponent((comp).constructor))
  19911. throw "Node:the component is singleton,can't add the second one.";
  19912. this._addComponentInstance(comp);
  19913. return comp;
  19914. }
  19915. /**
  19916. *添加组件。
  19917. *@param type 组件类型。
  19918. *@return 组件。
  19919. */
  19920. __proto.addComponent=function(type){
  19921. var comp=Pool.createByClass(type);
  19922. comp._destroyed=false;
  19923. if (comp.isSingleton && this.getComponent(type))
  19924. throw "无法实例"+type+"组件"+","+type+"组件已存在!";
  19925. this._addComponentInstance(comp);
  19926. return comp;
  19927. }
  19928. /**
  19929. *获得组件实例,如果没有则返回为null
  19930. *@param clas 组建类型
  19931. *@return 返回组件
  19932. */
  19933. __proto.getComponent=function(clas){
  19934. if (this._components){
  19935. for (var i=0,n=this._components.length;i < n;i++){
  19936. var comp=this._components[i];
  19937. if (Laya.__typeof(comp,clas))
  19938. return comp;
  19939. }
  19940. }
  19941. return null;
  19942. }
  19943. /**
  19944. *获得组件实例,如果没有则返回为null
  19945. *@param clas 组建类型
  19946. *@return 返回组件数组
  19947. */
  19948. __proto.getComponents=function(clas){
  19949. var arr;
  19950. if (this._components){
  19951. for (var i=0,n=this._components.length;i < n;i++){
  19952. var comp=this._components[i];
  19953. if (Laya.__typeof(comp,clas)){
  19954. arr=arr||[];
  19955. arr.push(comp);
  19956. }
  19957. }
  19958. }
  19959. return arr;
  19960. }
  19961. /**
  19962. *子对象数量。
  19963. */
  19964. __getset(0,__proto,'numChildren',function(){
  19965. return this._children.length;
  19966. });
  19967. /**父节点。*/
  19968. __getset(0,__proto,'parent',function(){
  19969. return this._parent;
  19970. });
  19971. /**
  19972. *获取在场景中是否激活。
  19973. *@return 在场景中是否激活。
  19974. */
  19975. __getset(0,__proto,'activeInHierarchy',function(){
  19976. return this._getBit(/*laya.Const.ACTIVE_INHIERARCHY*/0x02);
  19977. });
  19978. /**
  19979. *设置是否激活。
  19980. *@param value 是否激活。
  19981. */
  19982. /**
  19983. *获取自身是否激活。
  19984. *@return 自身是否激活。
  19985. */
  19986. __getset(0,__proto,'active',function(){
  19987. return !this._getBit(/*laya.Const.NOT_READY*/0x08)&& !this._getBit(/*laya.Const.NOT_ACTIVE*/0x01);
  19988. },function(value){
  19989. value=!!value;
  19990. if (!this._getBit(/*laya.Const.NOT_ACTIVE*/0x01)!==value){
  19991. if (this._activeChangeScripts && this._activeChangeScripts.length!==0){
  19992. if (value)
  19993. 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.";
  19994. else
  19995. 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.";
  19996. }else {
  19997. this._setBit(/*laya.Const.NOT_ACTIVE*/0x01,!value);
  19998. if (this._parent){
  19999. if (this._parent.activeInHierarchy){
  20000. if (value)this._processActive();
  20001. else this._processInActive();
  20002. }
  20003. }
  20004. }
  20005. }
  20006. });
  20007. /**表示是否在显示列表中显示。*/
  20008. __getset(0,__proto,'displayedInStage',function(){
  20009. if (this._getBit(/*laya.Const.DISPLAY*/0x10))return this._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80);
  20010. this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  20011. return this._getBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80);
  20012. });
  20013. /**
  20014. *获得所属场景。
  20015. *@return 场景。
  20016. */
  20017. __getset(0,__proto,'scene',function(){
  20018. return this._scene;
  20019. });
  20020. /**
  20021. *@private
  20022. *获取timer
  20023. */
  20024. __getset(0,__proto,'timer',function(){
  20025. return this.scene ? this.scene.timer :Laya.timer;
  20026. });
  20027. Node.ARRAY_EMPTY=[];
  20028. return Node;
  20029. })(EventDispatcher)
  20030. /**
  20031. *<p> <code>SoundChannel</code> 用来控制程序中的声音。每个声音均分配给一个声道,而且应用程序可以具有混合在一起的多个声道。</p>
  20032. *<p> <code>SoundChannel</code> 类包含控制声音的播放、暂停、停止、音量的方法,以及获取声音的播放状态、总时间、当前播放时间、总循环次数、播放地址等信息的方法。</p>
  20033. */
  20034. //class laya.media.SoundChannel extends laya.events.EventDispatcher
  20035. var SoundChannel=(function(_super){
  20036. function SoundChannel(){
  20037. /**
  20038. *声音地址。
  20039. */
  20040. this.url=null;
  20041. /**
  20042. *循环次数。
  20043. */
  20044. this.loops=0;
  20045. /**
  20046. *播放声音开始时间。
  20047. */
  20048. this.startTime=NaN;
  20049. /**
  20050. *表示声音是否已暂停。
  20051. */
  20052. this.isStopped=false;
  20053. /**
  20054. *播放完成处理器。
  20055. */
  20056. this.completeHandler=null;
  20057. SoundChannel.__super.call(this);
  20058. }
  20059. __class(SoundChannel,'laya.media.SoundChannel',_super);
  20060. var __proto=SoundChannel.prototype;
  20061. /**
  20062. *播放声音。
  20063. */
  20064. __proto.play=function(){}
  20065. /**
  20066. *停止播放。
  20067. */
  20068. __proto.stop=function(){
  20069. if (this.completeHandler)this.completeHandler.run();
  20070. }
  20071. /**
  20072. *暂停播放。
  20073. */
  20074. __proto.pause=function(){}
  20075. /**
  20076. *继续播放。
  20077. */
  20078. __proto.resume=function(){}
  20079. /**
  20080. *private
  20081. */
  20082. __proto.__runComplete=function(handler){
  20083. if (handler){
  20084. handler.run();
  20085. }
  20086. }
  20087. /**
  20088. *音量范围从 0(静音)至 1(最大音量)。
  20089. */
  20090. __getset(0,__proto,'volume',function(){
  20091. return 1;
  20092. },function(v){
  20093. });
  20094. /**
  20095. *获取当前播放时间,单位是秒。
  20096. */
  20097. __getset(0,__proto,'position',function(){
  20098. return 0;
  20099. });
  20100. /**
  20101. *获取总时间,单位是秒。
  20102. */
  20103. __getset(0,__proto,'duration',function(){
  20104. return 0;
  20105. });
  20106. return SoundChannel;
  20107. })(EventDispatcher)
  20108. /**
  20109. *@private
  20110. *<code>Resource</code> 资源存取类。
  20111. */
  20112. //class laya.resource.Resource extends laya.events.EventDispatcher
  20113. var Resource=(function(_super){
  20114. function Resource(){
  20115. /**@private */
  20116. this._id=0;
  20117. /**@private */
  20118. this._url=null;
  20119. /**@private */
  20120. this._cpuMemory=0;
  20121. /**@private */
  20122. this._gpuMemory=0;
  20123. /**@private */
  20124. this._destroyed=false;
  20125. /**@private */
  20126. this._referenceCount=0;
  20127. /**是否加锁,如果true为不能使用自动释放机制。*/
  20128. this.lock=false;
  20129. /**名称。 */
  20130. this.name=null;
  20131. Resource.__super.call(this);
  20132. this._id=++Resource._uniqueIDCounter;
  20133. this._destroyed=false;
  20134. this._referenceCount=0;
  20135. Resource._idResourcesMap[this.id]=this;
  20136. this.lock=false;
  20137. }
  20138. __class(Resource,'laya.resource.Resource',_super);
  20139. var __proto=Resource.prototype;
  20140. Laya.imps(__proto,{"laya.resource.ICreateResource":true,"laya.resource.IDestroy":true})
  20141. /**
  20142. *@private
  20143. */
  20144. __proto._setCPUMemory=function(value){
  20145. var offsetValue=value-this._cpuMemory;
  20146. this._cpuMemory=value;
  20147. Resource._addCPUMemory(offsetValue);
  20148. }
  20149. /**
  20150. *@private
  20151. */
  20152. __proto._setGPUMemory=function(value){
  20153. var offsetValue=value-this._gpuMemory;
  20154. this._gpuMemory=value;
  20155. Resource._addGPUMemory(offsetValue);
  20156. }
  20157. /**
  20158. *@private
  20159. */
  20160. __proto._setCreateURL=function(url){
  20161. url=URL.formatURL(url);
  20162. if (this._url!==url){
  20163. var resList;
  20164. if (this._url){
  20165. resList=Resource._urlResourcesMap[this._url];
  20166. resList.splice(resList.indexOf(this),1);
  20167. (resList.length===0)&& (delete Resource._urlResourcesMap[this._url]);
  20168. }
  20169. if (url){
  20170. resList=Resource._urlResourcesMap[url];
  20171. (resList)|| (Resource._urlResourcesMap[url]=resList=[]);
  20172. resList.push(this);
  20173. }
  20174. this._url=url;
  20175. }
  20176. }
  20177. /**
  20178. *@private
  20179. */
  20180. __proto._addReference=function(count){
  20181. (count===void 0)&& (count=1);
  20182. this._referenceCount+=count;
  20183. }
  20184. /**
  20185. *@private
  20186. */
  20187. __proto._removeReference=function(count){
  20188. (count===void 0)&& (count=1);
  20189. this._referenceCount-=count;
  20190. }
  20191. /**
  20192. *@private
  20193. */
  20194. __proto._clearReference=function(){
  20195. this._referenceCount=0;
  20196. }
  20197. /**
  20198. *@private
  20199. */
  20200. __proto._recoverResource=function(){}
  20201. /**
  20202. *@private
  20203. */
  20204. __proto._disposeResource=function(){}
  20205. /**
  20206. *@private
  20207. */
  20208. __proto._activeResource=function(){}
  20209. /**
  20210. *销毁资源,销毁后资源不能恢复。
  20211. */
  20212. __proto.destroy=function(){
  20213. if (this._destroyed)
  20214. return;
  20215. this._destroyed=true;
  20216. this.lock=false;
  20217. this._disposeResource();
  20218. delete Resource._idResourcesMap[this.id];
  20219. var resList;
  20220. if (this._url){
  20221. resList=Resource._urlResourcesMap[this._url];
  20222. if (resList){
  20223. resList.splice(resList.indexOf(this),1);
  20224. (resList.length===0)&& (delete Resource._urlResourcesMap[this._url]);
  20225. };
  20226. var resou=Loader.getRes(this._url);
  20227. (resou==this)&& (delete Loader.loadedMap[this._url]);
  20228. }
  20229. }
  20230. /**
  20231. *获取唯一标识ID,通常用于识别。
  20232. */
  20233. __getset(0,__proto,'id',function(){
  20234. return this._id;
  20235. });
  20236. /**
  20237. *显存大小。
  20238. */
  20239. __getset(0,__proto,'gpuMemory',function(){
  20240. return this._gpuMemory;
  20241. });
  20242. /**
  20243. *获取资源的URL地址。
  20244. *@return URL地址。
  20245. */
  20246. __getset(0,__proto,'url',function(){
  20247. return this._url;
  20248. });
  20249. /**
  20250. *内存大小。
  20251. */
  20252. __getset(0,__proto,'cpuMemory',function(){
  20253. return this._cpuMemory;
  20254. });
  20255. /**
  20256. *是否已处理。
  20257. */
  20258. __getset(0,__proto,'destroyed',function(){
  20259. return this._destroyed;
  20260. });
  20261. /**
  20262. *获取资源的引用计数。
  20263. */
  20264. __getset(0,__proto,'referenceCount',function(){
  20265. return this._referenceCount;
  20266. });
  20267. /**
  20268. *当前内存,以字节为单位。
  20269. */
  20270. __getset(1,Resource,'cpuMemory',function(){
  20271. return this._cpuMemory;
  20272. },laya.events.EventDispatcher._$SET_cpuMemory);
  20273. /**
  20274. *当前显存,以字节为单位。
  20275. */
  20276. __getset(1,Resource,'gpuMemory',function(){
  20277. return this._gpuMemory;
  20278. },laya.events.EventDispatcher._$SET_gpuMemory);
  20279. Resource._addCPUMemory=function(size){
  20280. this._cpuMemory+=size;
  20281. }
  20282. Resource._addGPUMemory=function(size){
  20283. this._gpuMemory+=size;
  20284. }
  20285. Resource._addMemory=function(cpuSize,gpuSize){
  20286. this._cpuMemory+=cpuSize;
  20287. this._gpuMemory+=gpuSize;
  20288. }
  20289. Resource.getResourceByID=function(id){
  20290. return Resource._idResourcesMap[id];
  20291. }
  20292. Resource.getResourceByURL=function(url,index){
  20293. (index===void 0)&& (index=0);
  20294. return Resource._urlResourcesMap[url][index];
  20295. }
  20296. Resource.destroyUnusedResources=function(){
  20297. for (var k in Resource._idResourcesMap){
  20298. var res=Resource._idResourcesMap[k];
  20299. if (!res.lock && res._referenceCount===0)
  20300. res.destroy();
  20301. }
  20302. }
  20303. Resource._uniqueIDCounter=0;
  20304. Resource._idResourcesMap={};
  20305. Resource._urlResourcesMap={};
  20306. Resource._cpuMemory=0;
  20307. Resource._gpuMemory=0;
  20308. return Resource;
  20309. })(EventDispatcher)
  20310. /**
  20311. *用来画矢量的mesh。顶点格式固定为 x,y,rgba
  20312. */
  20313. //class laya.webgl.utils.MeshVG extends laya.webgl.utils.Mesh2D
  20314. var MeshVG=(function(_super){
  20315. function MeshVG(){
  20316. MeshVG.__super.call(this,/*CLASS CONST:laya.webgl.utils.MeshVG.const_stride*/12,4,4);
  20317. this.canReuse=true;
  20318. this.setAttributes(laya.webgl.utils.MeshVG._fixattriInfo);
  20319. }
  20320. __class(MeshVG,'laya.webgl.utils.MeshVG',_super);
  20321. var __proto=MeshVG.prototype;
  20322. /**
  20323. *往矢量mesh中添加顶点和index。会把rgba和points在mesh中合并。
  20324. *@param points 顶点数组,只包含x,y。[x,y,x,y...]
  20325. *@param rgba rgba颜色
  20326. *@param ib index数组。
  20327. */
  20328. __proto.addVertAndIBToMesh=function(ctx,points,rgba,ib){
  20329. var startpos=this._vb.needSize(points.length / 2 *12);
  20330. var f32pos=startpos >> 2;
  20331. var vbdata=this._vb._floatArray32 || this._vb.getFloat32Array();
  20332. var vbu32Arr=this._vb._uint32Array;
  20333. var ci=0;
  20334. var sz=points.length / 2;
  20335. for (var i=0;i < sz;i++){
  20336. vbdata[f32pos++]=points[ci];vbdata[f32pos++]=points[ci+1];ci+=2;
  20337. vbu32Arr[f32pos++]=rgba;
  20338. }
  20339. this._vb.setNeedUpload();
  20340. this._ib.append(new Uint16Array(ib));
  20341. this._ib.setNeedUpload();
  20342. this.vertNum+=sz;
  20343. this.indexNum+=ib.length;
  20344. }
  20345. /**
  20346. *把本对象放到回收池中,以便getMesh能用。
  20347. */
  20348. __proto.releaseMesh=function(){
  20349. this._vb.setByteLength(0);
  20350. this._ib.setByteLength(0);
  20351. this.vertNum=0;
  20352. this.indexNum=0;
  20353. laya.webgl.utils.MeshVG._POOL.push(this);
  20354. }
  20355. __proto.destroy=function(){
  20356. this._ib.destroy();
  20357. this._vb.destroy();
  20358. this._ib.disposeResource();
  20359. this._vb.deleteBuffer();
  20360. }
  20361. MeshVG.getAMesh=function(mainctx){
  20362. var ret;
  20363. if (laya.webgl.utils.MeshVG._POOL.length){
  20364. ret=laya.webgl.utils.MeshVG._POOL.pop();
  20365. }else
  20366. ret=new MeshVG();
  20367. mainctx && ret._vb._resizeBuffer(64 *1024 *12,false);
  20368. return ret;
  20369. }
  20370. MeshVG.const_stride=12;
  20371. MeshVG._POOL=[];
  20372. __static(MeshVG,
  20373. ['_fixattriInfo',function(){return this._fixattriInfo=[
  20374. /*laya.webgl.WebGLContext.FLOAT*/0x1406,2,0,
  20375. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,8];}
  20376. ]);
  20377. return MeshVG;
  20378. })(Mesh2D)
  20379. /**
  20380. *<code>TimeLine</code> 是一个用来创建时间轴动画的类。
  20381. */
  20382. //class laya.utils.TimeLine extends laya.events.EventDispatcher
  20383. var TimeLine=(function(_super){
  20384. var tweenData;
  20385. function TimeLine(){
  20386. this._labelDic=null;
  20387. this._tweenDic={};
  20388. this._tweenDataList=[];
  20389. this._endTweenDataList=null;
  20390. //以结束时间进行排序
  20391. this._currTime=0;
  20392. this._lastTime=0;
  20393. this._startTime=0;
  20394. /**当前动画数据播放到第几个了*/
  20395. this._index=0;
  20396. /**为TWEEN创建属于自己的唯一标识,方便管理*/
  20397. this._gidIndex=0;
  20398. /**保留所有对象第一次注册动画时的状态(根据时间跳转时,需要把对象的恢复,再计算接下来的状态)*/
  20399. this._firstTweenDic={};
  20400. /**是否需要排序*/
  20401. this._startTimeSort=false;
  20402. this._endTimeSort=false;
  20403. /**是否循环*/
  20404. this._loopKey=false;
  20405. /**缩放动画播放的速度。*/
  20406. this.scale=1;
  20407. this._frameRate=60;
  20408. this._frameIndex=0;
  20409. this._total=0;
  20410. TimeLine.__super.call(this);
  20411. }
  20412. __class(TimeLine,'laya.utils.TimeLine',_super);
  20413. var __proto=TimeLine.prototype;
  20414. /**
  20415. *控制一个对象,从当前点移动到目标点。
  20416. *@param target 要控制的对象。
  20417. *@param props 要控制对象的属性。
  20418. *@param duration 对象TWEEN的时间。
  20419. *@param ease 缓动类型
  20420. *@param offset 相对于上一个对象,偏移多长时间(单位:毫秒)。
  20421. */
  20422. __proto.to=function(target,props,duration,ease,offset){
  20423. (offset===void 0)&& (offset=0);
  20424. return this._create(target,props,duration,ease,offset,true);
  20425. }
  20426. /**
  20427. *从 props 属性,缓动到当前状态。
  20428. *@param target target 目标对象(即将更改属性值的对象)
  20429. *@param props 要控制对象的属性
  20430. *@param duration 对象TWEEN的时间
  20431. *@param ease 缓动类型
  20432. *@param offset 相对于上一个对象,偏移多长时间(单位:毫秒)
  20433. */
  20434. __proto.from=function(target,props,duration,ease,offset){
  20435. (offset===void 0)&& (offset=0);
  20436. return this._create(target,props,duration,ease,offset,false);
  20437. }
  20438. /**@private */
  20439. __proto._create=function(target,props,duration,ease,offset,isTo){
  20440. var tTweenData=Pool.getItemByClass("tweenData",tweenData);
  20441. tTweenData.isTo=isTo;
  20442. tTweenData.type=0;
  20443. tTweenData.target=target;
  20444. tTweenData.duration=duration;
  20445. tTweenData.data=props;
  20446. tTweenData.startTime=this._startTime+offset;
  20447. tTweenData.endTime=tTweenData.startTime+tTweenData.duration;
  20448. tTweenData.ease=ease;
  20449. this._startTime=Math.max(tTweenData.endTime,this._startTime);
  20450. this._tweenDataList.push(tTweenData);
  20451. this._startTimeSort=true;
  20452. this._endTimeSort=true;
  20453. return this;
  20454. }
  20455. /**
  20456. *在时间队列中加入一个标签。
  20457. *@param label 标签名称。
  20458. *@param offset 标签相对于上个动画的偏移时间(单位:毫秒)。
  20459. */
  20460. __proto.addLabel=function(label,offset){
  20461. var tTweenData=Pool.getItemByClass("tweenData",tweenData);
  20462. tTweenData.type=1;
  20463. tTweenData.data=label;
  20464. tTweenData.endTime=tTweenData.startTime=this._startTime+offset;
  20465. this._labelDic || (this._labelDic={});
  20466. this._labelDic[label]=tTweenData;
  20467. this._tweenDataList.push(tTweenData);
  20468. return this;
  20469. }
  20470. /**
  20471. *移除指定的标签
  20472. *@param label
  20473. */
  20474. __proto.removeLabel=function(label){
  20475. if (this._labelDic && this._labelDic[label]){
  20476. var tTweenData=this._labelDic[label];
  20477. if (tTweenData){
  20478. var tIndex=this._tweenDataList.indexOf(tTweenData);
  20479. if (tIndex >-1){
  20480. this._tweenDataList.splice(tIndex,1);
  20481. }
  20482. }
  20483. delete this._labelDic[label];
  20484. }
  20485. }
  20486. /**
  20487. *动画从整个动画的某一时间开始。
  20488. *@param time(单位:毫秒)。
  20489. */
  20490. __proto.gotoTime=function(time){
  20491. if (this._tweenDataList==null || this._tweenDataList.length==0)return;
  20492. var tTween;
  20493. var tObject;
  20494. for (var p in this._firstTweenDic){
  20495. tObject=this._firstTweenDic[p];
  20496. if (tObject){
  20497. for (var tDataP in tObject){
  20498. if (tObject.diyTarget.hasOwnProperty(tDataP)){
  20499. tObject.diyTarget[tDataP]=tObject[tDataP];
  20500. }
  20501. }
  20502. }
  20503. }
  20504. for (p in this._tweenDic){
  20505. tTween=this._tweenDic[p];
  20506. tTween.clear();
  20507. delete this._tweenDic[p];
  20508. }
  20509. this._index=0;
  20510. this._gidIndex=0;
  20511. this._currTime=time;
  20512. this._lastTime=Browser.now();
  20513. var tTweenDataCopyList;
  20514. if (this._endTweenDataList==null || this._endTimeSort){
  20515. this._endTimeSort=false;
  20516. this._endTweenDataList=tTweenDataCopyList=this._tweenDataList.concat();
  20517. function Compare (paraA,paraB){
  20518. if (paraA.endTime > paraB.endTime){
  20519. return 1;
  20520. }else if (paraA.endTime < paraB.endTime){
  20521. return-1;
  20522. }else {
  20523. return 0;
  20524. }
  20525. }
  20526. tTweenDataCopyList.sort(Compare);
  20527. }else {
  20528. tTweenDataCopyList=this._endTweenDataList
  20529. };
  20530. var tTweenData;
  20531. for (var i=0,n=tTweenDataCopyList.length;i < n;i++){
  20532. tTweenData=tTweenDataCopyList[i];
  20533. if (tTweenData.type==0){
  20534. if (time >=tTweenData.endTime){
  20535. this._index=Math.max(this._index,i+1);
  20536. var props=tTweenData.data;
  20537. if (tTweenData.isTo){
  20538. for (var tP in props){
  20539. tTweenData.target[tP]=props[tP];
  20540. }
  20541. }
  20542. }else {
  20543. break ;
  20544. }
  20545. }
  20546. }
  20547. for (i=0,n=this._tweenDataList.length;i < n;i++){
  20548. tTweenData=this._tweenDataList[i];
  20549. if (tTweenData.type==0){
  20550. if (time >=tTweenData.startTime && time < tTweenData.endTime){
  20551. this._index=Math.max(this._index,i+1);
  20552. this._gidIndex++;
  20553. tTween=Pool.getItemByClass("tween",Tween);
  20554. tTween._create(tTweenData.target,tTweenData.data,tTweenData.duration,tTweenData.ease,Handler.create(this,this._animComplete,[this._gidIndex]),0,false,tTweenData.isTo,true,false);
  20555. tTween.setStartTime(this._currTime-(time-tTweenData.startTime));
  20556. tTween._updateEase(this._currTime);
  20557. tTween.gid=this._gidIndex;
  20558. this._tweenDic[this._gidIndex]=tTween;
  20559. }
  20560. }
  20561. }
  20562. }
  20563. /**
  20564. *从指定的标签开始播。
  20565. *@param Label 标签名。
  20566. */
  20567. __proto.gotoLabel=function(Label){
  20568. if (this._labelDic==null)return;
  20569. var tLabelData=this._labelDic[Label];
  20570. if (tLabelData)this.gotoTime(tLabelData.startTime);
  20571. }
  20572. /**
  20573. *暂停整个动画。
  20574. */
  20575. __proto.pause=function(){
  20576. Laya.timer.clear(this,this._update);
  20577. }
  20578. /**
  20579. *恢复暂停动画的播放。
  20580. */
  20581. __proto.resume=function(){
  20582. this.play(this._currTime,this._loopKey);
  20583. }
  20584. /**
  20585. *播放动画。
  20586. *@param timeOrLabel 开启播放的时间点或标签名。
  20587. *@param loop 是否循环播放。
  20588. */
  20589. __proto.play=function(timeOrLabel,loop){
  20590. (timeOrLabel===void 0)&& (timeOrLabel=0);
  20591. (loop===void 0)&& (loop=false);
  20592. if (!this._tweenDataList)return;
  20593. if (this._startTimeSort){
  20594. this._startTimeSort=false;
  20595. function Compare (paraA,paraB){
  20596. if (paraA.startTime > paraB.startTime){
  20597. return 1;
  20598. }else if (paraA.startTime < paraB.startTime){
  20599. return-1;
  20600. }else {
  20601. return 0;
  20602. }
  20603. }
  20604. this._tweenDataList.sort(Compare);
  20605. for (var i=0,n=this._tweenDataList.length;i < n;i++){
  20606. var tTweenData=this._tweenDataList[i];
  20607. if (tTweenData !=null && tTweenData.type==0){
  20608. var tTarget=tTweenData.target;
  20609. var gid=(tTarget.$_GID || (tTarget.$_GID=Utils.getGID()));
  20610. var tSrcData=null;
  20611. if (this._firstTweenDic[gid]==null){
  20612. tSrcData={};
  20613. tSrcData.diyTarget=tTarget;
  20614. this._firstTweenDic[gid]=tSrcData;
  20615. }else {
  20616. tSrcData=this._firstTweenDic[gid];
  20617. }
  20618. for (var p in tTweenData.data){
  20619. if (tSrcData[p]==null){
  20620. tSrcData[p]=tTarget[p];
  20621. }
  20622. }
  20623. }
  20624. }
  20625. }
  20626. if ((typeof timeOrLabel=='string')){
  20627. this.gotoLabel(timeOrLabel);
  20628. }else {
  20629. this.gotoTime(timeOrLabel);
  20630. }
  20631. this._loopKey=loop;
  20632. this._lastTime=Browser.now();
  20633. Laya.timer.frameLoop(1,this,this._update);
  20634. }
  20635. /**
  20636. *更新当前动画。
  20637. */
  20638. __proto._update=function(){
  20639. if (this._currTime >=this._startTime){
  20640. if (this._loopKey){
  20641. this._complete();
  20642. if (!this._tweenDataList)return;
  20643. this.gotoTime(0);
  20644. }else {
  20645. for (var p in this._tweenDic){
  20646. tTween=this._tweenDic[p];
  20647. tTween.complete();
  20648. }
  20649. this._complete();
  20650. this.pause();
  20651. return;
  20652. }
  20653. };
  20654. var tNow=Browser.now();
  20655. var tFrameTime=tNow-this._lastTime;
  20656. var tCurrTime=this._currTime+=tFrameTime *this.scale;
  20657. this._lastTime=tNow;
  20658. for (p in this._tweenDic){
  20659. tTween=this._tweenDic[p];
  20660. tTween._updateEase(tCurrTime);
  20661. };
  20662. var tTween;
  20663. if (this._tweenDataList.length !=0 && this._index < this._tweenDataList.length){
  20664. var tTweenData=this._tweenDataList[this._index];
  20665. if (tCurrTime >=tTweenData.startTime){
  20666. this._index++;
  20667. if (tTweenData.type==0){
  20668. this._gidIndex++;
  20669. tTween=Pool.getItemByClass("tween",Tween);
  20670. tTween._create(tTweenData.target,tTweenData.data,tTweenData.duration,tTweenData.ease,Handler.create(this,this._animComplete,[this._gidIndex]),0,false,tTweenData.isTo,true,false);
  20671. tTween.setStartTime(tCurrTime);
  20672. tTween.gid=this._gidIndex;
  20673. this._tweenDic[this._gidIndex]=tTween;
  20674. tTween._updateEase(tCurrTime);
  20675. }else {
  20676. this.event(/*laya.events.Event.LABEL*/"label",tTweenData.data);
  20677. }
  20678. }
  20679. }
  20680. }
  20681. /**
  20682. *指定的动画索引处的动画播放完成后,把此动画从列表中删除。
  20683. *@param index
  20684. */
  20685. __proto._animComplete=function(index){
  20686. var tTween=this._tweenDic[index];
  20687. if (tTween)delete this._tweenDic[index];
  20688. }
  20689. /**@private */
  20690. __proto._complete=function(){
  20691. this.event(/*laya.events.Event.COMPLETE*/"complete");
  20692. }
  20693. /**
  20694. *重置所有对象,复用对象的时候使用。
  20695. */
  20696. __proto.reset=function(){
  20697. var p;
  20698. if (this._labelDic){
  20699. for (p in this._labelDic){
  20700. delete this._labelDic[p];
  20701. }
  20702. };
  20703. var tTween;
  20704. for (p in this._tweenDic){
  20705. tTween=this._tweenDic[p];
  20706. tTween.clear();
  20707. delete this._tweenDic[p];
  20708. }
  20709. for (p in this._firstTweenDic){
  20710. delete this._firstTweenDic[p];
  20711. }
  20712. this._endTweenDataList=null;
  20713. if (this._tweenDataList && this._tweenDataList.length){
  20714. var i=0,len=0;
  20715. len=this._tweenDataList.length;
  20716. for (i=0;i < len;i++){
  20717. if(this._tweenDataList[i])
  20718. this._tweenDataList[i].destroy();
  20719. }
  20720. }
  20721. this._tweenDataList.length=0;
  20722. this._currTime=0;
  20723. this._lastTime=0;
  20724. this._startTime=0;
  20725. this._index=0;
  20726. this._gidIndex=0;
  20727. this.scale=1;
  20728. Laya.timer.clear(this,this._update);
  20729. }
  20730. /**
  20731. *彻底销毁此对象。
  20732. */
  20733. __proto.destroy=function(){
  20734. this.reset();
  20735. this._labelDic=null;
  20736. this._tweenDic=null;
  20737. this._tweenDataList=null;
  20738. this._firstTweenDic=null;
  20739. }
  20740. /**
  20741. *@private
  20742. *设置帧索引
  20743. */
  20744. /**
  20745. *@private
  20746. *得到帧索引
  20747. */
  20748. __getset(0,__proto,'index',function(){
  20749. return this._frameIndex;
  20750. },function(value){
  20751. this._frameIndex=value;
  20752. this.gotoTime(this._frameIndex / this._frameRate *1000);
  20753. });
  20754. /**
  20755. *得到总帧数。
  20756. */
  20757. __getset(0,__proto,'total',function(){
  20758. this._total=Math.floor(this._startTime / 1000 *this._frameRate);
  20759. return this._total;
  20760. });
  20761. TimeLine.to=function(target,props,duration,ease,offset){
  20762. (offset===void 0)&& (offset=0);
  20763. return (new TimeLine()).to(target,props,duration,ease,offset);
  20764. }
  20765. TimeLine.from=function(target,props,duration,ease,offset){
  20766. (offset===void 0)&& (offset=0);
  20767. return (new TimeLine()).from(target,props,duration,ease,offset);
  20768. }
  20769. TimeLine.__init$=function(){
  20770. //class tweenData
  20771. tweenData=(function(){
  20772. function tweenData(){
  20773. this.type=0;
  20774. //0代表TWEEN,1代表标签
  20775. this.isTo=true;
  20776. this.startTime=NaN;
  20777. this.endTime=NaN;
  20778. this.target=null;
  20779. this.duration=NaN;
  20780. this.ease=null;
  20781. this.data=null;
  20782. }
  20783. __class(tweenData,'');
  20784. var __proto=tweenData.prototype;
  20785. __proto.destroy=function(){
  20786. this.target=null;
  20787. this.ease=null;
  20788. this.data=null;
  20789. this.isTo=true;
  20790. this.type=0;
  20791. Pool.recover("tweenData",this);
  20792. }
  20793. return tweenData;
  20794. })()
  20795. }
  20796. return TimeLine;
  20797. })(EventDispatcher)
  20798. //class laya.webgl.shader.d2.ShaderDefines2D extends laya.webgl.shader.ShaderDefinesBase
  20799. var ShaderDefines2D=(function(_super){
  20800. function ShaderDefines2D(){
  20801. ShaderDefines2D.__super.call(this,ShaderDefines2D.__name2int,ShaderDefines2D.__int2name,ShaderDefines2D.__int2nameMap);
  20802. }
  20803. __class(ShaderDefines2D,'laya.webgl.shader.d2.ShaderDefines2D',_super);
  20804. ShaderDefines2D.__init__=function(){
  20805. ShaderDefines2D.reg("TEXTURE2D",0x01);
  20806. ShaderDefines2D.reg("PRIMITIVE",0x04);
  20807. ShaderDefines2D.reg("GLOW_FILTER",0x08);
  20808. ShaderDefines2D.reg("BLUR_FILTER",0x10);
  20809. ShaderDefines2D.reg("COLOR_FILTER",0x20);
  20810. ShaderDefines2D.reg("COLOR_ADD",0x40);
  20811. ShaderDefines2D.reg("WORLDMAT",0x80);
  20812. ShaderDefines2D.reg("FILLTEXTURE",0x100);
  20813. ShaderDefines2D.reg("FSHIGHPRECISION",0x400);
  20814. ShaderDefines2D.reg('MVP3D',0x800);
  20815. }
  20816. ShaderDefines2D.reg=function(name,value){
  20817. ShaderDefinesBase._reg(name,value,ShaderDefines2D.__name2int,ShaderDefines2D.__int2name);
  20818. }
  20819. ShaderDefines2D.toText=function(value,int2name,int2nameMap){
  20820. return ShaderDefinesBase._toText(value,int2name,int2nameMap);
  20821. }
  20822. ShaderDefines2D.toInt=function(names){
  20823. return ShaderDefinesBase._toInt(names,ShaderDefines2D.__name2int);
  20824. }
  20825. ShaderDefines2D.TEXTURE2D=0x01;
  20826. ShaderDefines2D.PRIMITIVE=0x04;
  20827. ShaderDefines2D.FILTERGLOW=0x08;
  20828. ShaderDefines2D.FILTERBLUR=0x10;
  20829. ShaderDefines2D.FILTERCOLOR=0x20;
  20830. ShaderDefines2D.COLORADD=0x40;
  20831. ShaderDefines2D.WORLDMAT=0x80;
  20832. ShaderDefines2D.FILLTEXTURE=0x100;
  20833. ShaderDefines2D.SKINMESH=0x200;
  20834. ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION=0x400;
  20835. ShaderDefines2D.MVP3D=0x800;
  20836. ShaderDefines2D.NOOPTMASK=0x08|0x10|0x20|0x100;
  20837. ShaderDefines2D.__name2int={};
  20838. ShaderDefines2D.__int2name=[];
  20839. ShaderDefines2D.__int2nameMap=[];
  20840. return ShaderDefines2D;
  20841. })(ShaderDefinesBase)
  20842. /**
  20843. *<code>Texture</code> 是一个纹理处理类。
  20844. */
  20845. //class laya.resource.Texture extends laya.events.EventDispatcher
  20846. var Texture=(function(_super){
  20847. function Texture(bitmap,uv,sourceWidth,sourceHeight){
  20848. /**@private uv的范围*/
  20849. this.uvrect=[0,0,1,1];
  20850. /**@private */
  20851. this._destroyed=false;
  20852. /**@private */
  20853. //this._bitmap=null;
  20854. /**@private */
  20855. //this._uv=null;
  20856. /**@private */
  20857. this._referenceCount=0;
  20858. /**@private [NATIVE]*/
  20859. //this._nativeObj=null;
  20860. /**@private 唯一ID*/
  20861. this.$_GID=0;
  20862. /**沿 X 轴偏移量。*/
  20863. this.offsetX=0;
  20864. /**沿 Y 轴偏移量。*/
  20865. this.offsetY=0;
  20866. /**@private */
  20867. this._w=0;
  20868. /**@private */
  20869. this._h=0;
  20870. /**原始宽度(包括被裁剪的透明区域)。*/
  20871. this.sourceWidth=0;
  20872. /**原始高度(包括被裁剪的透明区域)。*/
  20873. this.sourceHeight=0;
  20874. /**图片地址*/
  20875. this.url=null;
  20876. /**@private */
  20877. this.scaleRate=1;
  20878. Texture.__super.call(this);
  20879. (sourceWidth===void 0)&& (sourceWidth=0);
  20880. (sourceHeight===void 0)&& (sourceHeight=0);
  20881. this.setTo(bitmap,uv,sourceWidth,sourceHeight);
  20882. }
  20883. __class(Texture,'laya.resource.Texture',_super);
  20884. var __proto=Texture.prototype;
  20885. /**
  20886. *@private
  20887. */
  20888. __proto._addReference=function(){
  20889. this._bitmap && this._bitmap._addReference();
  20890. this._referenceCount++;
  20891. }
  20892. /**
  20893. *@private
  20894. */
  20895. __proto._removeReference=function(){
  20896. this._bitmap && this._bitmap._removeReference();
  20897. this._referenceCount--;
  20898. }
  20899. /**
  20900. *@private
  20901. */
  20902. __proto._getSource=function(cb){
  20903. if (this._destroyed || !this._bitmap)
  20904. return null;
  20905. this.recoverBitmap(cb);
  20906. return this._bitmap.destroyed ? null :this.bitmap._getSource();
  20907. }
  20908. /**
  20909. *@private
  20910. */
  20911. __proto._onLoaded=function(complete,context){
  20912. if (!context){
  20913. }else if (context==this){
  20914. }else if ((context instanceof laya.resource.Texture )){
  20915. var tex=context;
  20916. Texture._create(context,0,0,tex.width,tex.height,0,0,tex.sourceWidth,tex.sourceHeight,this);
  20917. }else {
  20918. this.bitmap=context;
  20919. this.sourceWidth=this._w=context.width;
  20920. this.sourceHeight=this._h=context.height;
  20921. }
  20922. complete && complete.run();
  20923. this.event(/*laya.events.Event.READY*/"ready",this);
  20924. }
  20925. /**
  20926. *获取是否可以使用。
  20927. */
  20928. __proto.getIsReady=function(){
  20929. return this._destroyed ? false :(this._bitmap ? true :false);
  20930. }
  20931. /**
  20932. *设置此对象的位图资源、UV数据信息。
  20933. *@param bitmap 位图资源
  20934. *@param uv UV数据信息
  20935. */
  20936. __proto.setTo=function(bitmap,uv,sourceWidth,sourceHeight){
  20937. (sourceWidth===void 0)&& (sourceWidth=0);
  20938. (sourceHeight===void 0)&& (sourceHeight=0);
  20939. this.bitmap=bitmap;
  20940. this.sourceWidth=sourceWidth;
  20941. this.sourceHeight=sourceHeight;
  20942. if (bitmap){
  20943. this._w=bitmap.width;
  20944. this._h=bitmap.height;
  20945. this.sourceWidth=this.sourceWidth || bitmap.width;
  20946. this.sourceHeight=this.sourceHeight || bitmap.height
  20947. }
  20948. this.uv=uv || Texture.DEF_UV;
  20949. }
  20950. /**
  20951. *加载指定地址的图片。
  20952. *@param url 图片地址。
  20953. *@param complete 加载完成回调
  20954. */
  20955. __proto.load=function(url,complete){
  20956. if (!this._destroyed)
  20957. Laya.loader.load(url,Handler.create(this,this._onLoaded,[complete]),null,"htmlimage",1,false,null,true);
  20958. }
  20959. __proto.getTexturePixels=function(x,y,width,height){
  20960. var st=0,dst=0,i=0;
  20961. var tex2d=this.bitmap;
  20962. var texw=tex2d.width;
  20963. var texh=tex2d.height;
  20964. if (x+width > texw)width-=(x+width)-texw;
  20965. if (y+height > texh)height-=(y+height)-texh;
  20966. if (width <=0 || height <=0)return null;
  20967. var wstride=width *4;
  20968. var pix=null;
  20969. try {
  20970. pix=tex2d.getPixels();
  20971. }catch (e){}
  20972. if (pix){
  20973. if(x==0&&y==0&&width==texw&&height==texh)
  20974. return pix;
  20975. var ret=new Uint8Array(width *height *4);
  20976. wstride=texw *4;
  20977. st=x*4;
  20978. dst=(y+height-1)*wstride+x*4;
  20979. for (i=height-1;i >=0;i--){
  20980. ret.set(dt.slice(dst,dst+width*4),st);
  20981. st+=wstride;
  20982. dst-=wstride;
  20983. }
  20984. return ret;
  20985. };
  20986. var ctx=new Context();
  20987. ctx.size(width,height);
  20988. ctx.asBitmap=true;
  20989. var uv=null;
  20990. if (x !=0 || y !=0 || width !=texw || height !=texh){
  20991. uv=uv.concat();
  20992. var stu=uv[0];
  20993. var stv=uv[1];
  20994. var uvw=uv[2]-stu;
  20995. var uvh=uv[7]-stv;
  20996. var uk=uvw / texw;
  20997. var vk=uvh / texh;
  20998. uv=[
  20999. stu+x *uk,stv+y *vk,
  21000. stu+(x+width)*uk,stv+y *vk,
  21001. stu+(x+width)*uk,stv+(y+height)*vk,
  21002. stu+x *uk,stv+(y+height)*vk,];
  21003. }
  21004. ctx._drawTextureM(this,0,0,width,height,null,1.0,uv);
  21005. ctx._targets.start();
  21006. ctx.flush();
  21007. ctx._targets.end();
  21008. ctx._targets.restore();
  21009. var dt=ctx._targets.getData(0,0,width,height);
  21010. ctx.destroy();
  21011. ret=new Uint8Array(width *height *4);
  21012. st=0;
  21013. dst=(height-1)*wstride;
  21014. for (i=height-1;i >=0;i--){
  21015. ret.set(dt.slice(dst,dst+wstride),st);
  21016. st+=wstride;
  21017. dst-=wstride;
  21018. }
  21019. return ret;
  21020. }
  21021. /**
  21022. *获取Texture上的某个区域的像素点
  21023. *@param x
  21024. *@param y
  21025. *@param width
  21026. *@param height
  21027. *@return 返回像素点集合
  21028. */
  21029. __proto.getPixels=function(x,y,width,height){
  21030. if (Render.isConchApp){
  21031. return this._nativeObj.getImageData(x,y,width,height);
  21032. }else {
  21033. return this.getTexturePixels(x,y,width,height);
  21034. }
  21035. }
  21036. /**
  21037. *通过url强制恢复bitmap。
  21038. */
  21039. __proto.recoverBitmap=function(onok){
  21040. var _$this=this;
  21041. var url=this._bitmap.url;
  21042. if (!this._destroyed && (!this._bitmap || this._bitmap.destroyed)&& url){
  21043. Laya.loader.load(url,Handler.create(this,function(bit){
  21044. _$this.bitmap=bit;
  21045. onok && onok();
  21046. }),null,"htmlimage",1,false,null,true);
  21047. }
  21048. }
  21049. /**
  21050. *强制释放Bitmap,无论是否被引用。
  21051. */
  21052. __proto.disposeBitmap=function(){
  21053. if (!this._destroyed && this._bitmap){
  21054. this._bitmap.destroy();
  21055. }
  21056. }
  21057. /**
  21058. *销毁纹理。
  21059. */
  21060. __proto.destroy=function(force){
  21061. (force===void 0)&& (force=false);
  21062. if (!this._destroyed){
  21063. this._destroyed=true;
  21064. var bit=this._bitmap;
  21065. if (bit){
  21066. bit._removeReference(this._referenceCount);
  21067. if (bit.referenceCount===0||force)
  21068. bit.destroy();
  21069. bit=null;
  21070. }
  21071. if (this.url && this===Laya.loader.getRes(this.url))
  21072. Laya.loader.clearRes(this.url);
  21073. }
  21074. }
  21075. /**实际高度。*/
  21076. __getset(0,__proto,'height',function(){
  21077. if (this._h)
  21078. return this._h;
  21079. if (!this.bitmap)return 0;
  21080. return (this.uv && this.uv!==Texture.DEF_UV)? (this.uv[5]-this.uv[1])*this.bitmap.height :this.bitmap.height;
  21081. },function(value){
  21082. this._h=value;
  21083. this.sourceHeight || (this.sourceHeight=value);
  21084. });
  21085. __getset(0,__proto,'uv',function(){
  21086. return this._uv;
  21087. },function(value){
  21088. this.uvrect[0]=Math.min(value[0],value[2],value[4],value[6]);
  21089. this.uvrect[1]=Math.min(value[1],value[3],value[5],value[7]);
  21090. this.uvrect[2]=Math.max(value[0],value[2],value[4],value[6])-this.uvrect[0];
  21091. this.uvrect[3]=Math.max(value[1],value[3],value[5],value[7])-this.uvrect[1];
  21092. this._uv=value;
  21093. });
  21094. /**实际宽度。*/
  21095. __getset(0,__proto,'width',function(){
  21096. if (this._w)
  21097. return this._w;
  21098. if (!this.bitmap)return 0;
  21099. return (this.uv && this.uv!==Texture.DEF_UV)? (this.uv[2]-this.uv[0])*this.bitmap.width :this.bitmap.width;
  21100. },function(value){
  21101. this._w=value;
  21102. this.sourceWidth || (this.sourceWidth=value);
  21103. });
  21104. /**
  21105. *设置位图。
  21106. *@param 位图。
  21107. */
  21108. /**
  21109. *获取位图。
  21110. *@return 位图。
  21111. */
  21112. __getset(0,__proto,'bitmap',function(){
  21113. return this._bitmap;
  21114. },function(value){
  21115. this._bitmap && this._bitmap._removeReference(this._referenceCount);
  21116. this._bitmap=value;
  21117. value && (value._addReference(this._referenceCount));
  21118. });
  21119. /**
  21120. *获取是否已经销毁。
  21121. *@return 是否已经销毁。
  21122. */
  21123. __getset(0,__proto,'destroyed',function(){
  21124. return this._destroyed;
  21125. });
  21126. Texture.moveUV=function(offsetX,offsetY,uv){
  21127. for (var i=0;i < 8;i+=2){
  21128. uv[i]+=offsetX;
  21129. uv[i+1]+=offsetY;
  21130. }
  21131. return uv;
  21132. }
  21133. Texture.create=function(source,x,y,width,height,offsetX,offsetY,sourceWidth,sourceHeight){
  21134. (offsetX===void 0)&& (offsetX=0);
  21135. (offsetY===void 0)&& (offsetY=0);
  21136. (sourceWidth===void 0)&& (sourceWidth=0);
  21137. (sourceHeight===void 0)&& (sourceHeight=0);
  21138. return Texture._create(source,x,y,width,height,offsetX,offsetY,sourceWidth,sourceHeight);
  21139. }
  21140. Texture._create=function(source,x,y,width,height,offsetX,offsetY,sourceWidth,sourceHeight,outTexture){
  21141. (offsetX===void 0)&& (offsetX=0);
  21142. (offsetY===void 0)&& (offsetY=0);
  21143. (sourceWidth===void 0)&& (sourceWidth=0);
  21144. (sourceHeight===void 0)&& (sourceHeight=0);
  21145. var btex=(source instanceof laya.resource.Texture );
  21146. var uv=btex ? (source).uv :Texture.DEF_UV;
  21147. var bitmap=btex ? (source).bitmap :source;
  21148. if (bitmap.width && (x+width)> bitmap.width)
  21149. width=bitmap.width-x;
  21150. if (bitmap.height && (y+height)> bitmap.height)
  21151. height=bitmap.height-y;
  21152. var tex;
  21153. if (outTexture){
  21154. tex=outTexture;
  21155. tex.setTo(bitmap,null,sourceWidth || width,sourceHeight || height);
  21156. }else {
  21157. tex=new Texture(bitmap,null,sourceWidth || width,sourceHeight || height)
  21158. }
  21159. tex.width=width;
  21160. tex.height=height;
  21161. tex.offsetX=offsetX;
  21162. tex.offsetY=offsetY;
  21163. var dwidth=1 / bitmap.width;
  21164. var dheight=1 / bitmap.height;
  21165. x *=dwidth;
  21166. y *=dheight;
  21167. width *=dwidth;
  21168. height *=dheight;
  21169. var u1=tex.uv[0],v1=tex.uv[1],u2=tex.uv[4],v2=tex.uv[5];
  21170. var inAltasUVWidth=(u2-u1),inAltasUVHeight=(v2-v1);
  21171. var oriUV=Texture.moveUV(uv[0],uv[1],[x,y,x+width,y,x+width,y+height,x,y+height]);
  21172. tex.uv=new Float32Array([
  21173. u1+oriUV[0] *inAltasUVWidth,v1+oriUV[1] *inAltasUVHeight,
  21174. u2-(1-oriUV[2])*inAltasUVWidth,v1+oriUV[3] *inAltasUVHeight,
  21175. u2-(1-oriUV[4])*inAltasUVWidth,v2-(1-oriUV[5])*inAltasUVHeight,
  21176. u1+oriUV[6] *inAltasUVWidth,v2-(1-oriUV[7])*inAltasUVHeight]);
  21177. var bitmapScale=(bitmap).scaleRate;
  21178. if (bitmapScale && bitmapScale !=1){
  21179. tex.sourceWidth /=bitmapScale;
  21180. tex.sourceHeight /=bitmapScale;
  21181. tex.width /=bitmapScale;
  21182. tex.height /=bitmapScale;
  21183. tex.scaleRate=bitmapScale;
  21184. }else {
  21185. tex.scaleRate=1;
  21186. }
  21187. return tex;
  21188. }
  21189. Texture.createFromTexture=function(texture,x,y,width,height){
  21190. var texScaleRate=texture.scaleRate;
  21191. if (texScaleRate !=1){
  21192. x *=texScaleRate;
  21193. y *=texScaleRate;
  21194. width *=texScaleRate;
  21195. height *=texScaleRate;
  21196. };
  21197. var rect=Rectangle.TEMP.setTo(x-texture.offsetX,y-texture.offsetY,width,height);
  21198. var result=rect.intersection(Texture._rect1.setTo(0,0,texture.width,texture.height),Texture._rect2);
  21199. if (result)
  21200. var tex=Texture.create((texture),result.x,result.y,result.width,result.height,result.x-rect.x,result.y-rect.y,width,height);
  21201. else
  21202. return null;
  21203. return tex;
  21204. }
  21205. Texture.DEF_UV=new Float32Array([0,0,1.0,0,1.0,1.0,0,1.0]);
  21206. Texture.NO_UV=new Float32Array([0,0,0,0,0,0,0,0]);
  21207. Texture.INV_UV=new Float32Array([0,1,1.0,1,1.0,0.0,0,0.0]);
  21208. Texture._rect1=new Rectangle();
  21209. Texture._rect2=new Rectangle();
  21210. return Texture;
  21211. })(EventDispatcher)
  21212. /**
  21213. *<p> <code>HttpRequest</code> 通过封装 HTML <code>XMLHttpRequest</code> 对象提供了对 HTTP 协议的完全的访问,包括做出 POST 和 HEAD 请求以及普通的 GET 请求的能力。 <code>HttpRequest</code> 只提供以异步的形式返回 Web 服务器的响应,并且能够以文本或者二进制的形式返回内容。</p>
  21214. *<p><b>注意:</b>建议每次请求都使用新的 <code>HttpRequest</code> 对象,因为每次调用该对象的send方法时,都会清空之前设置的数据,并重置 HTTP 请求的状态,这会导致之前还未返回响应的请求被重置,从而得不到之前请求的响应结果。</p>
  21215. */
  21216. //class laya.net.HttpRequest extends laya.events.EventDispatcher
  21217. var HttpRequest=(function(_super){
  21218. function HttpRequest(){
  21219. /**@private */
  21220. this._responseType=null;
  21221. /**@private */
  21222. this._data=null;
  21223. /**@private */
  21224. this._url=null;
  21225. HttpRequest.__super.call(this);
  21226. this._http=new Browser.window.XMLHttpRequest();
  21227. }
  21228. __class(HttpRequest,'laya.net.HttpRequest',_super);
  21229. var __proto=HttpRequest.prototype;
  21230. /**
  21231. *发送 HTTP 请求。
  21232. *@param url 请求的地址。大多数浏览器实施了一个同源安全策略,并且要求这个 URL 与包含脚本的文本具有相同的主机名和端口。
  21233. *@param data (default=null)发送的数据。
  21234. *@param method (default="get")用于请求的 HTTP 方法。值包括 "get"、"post"、"head"。
  21235. *@param responseType (default="text")Web 服务器的响应类型,可设置为 "text"、"json"、"xml"、"arraybuffer"。
  21236. *@param headers (default=null)HTTP 请求的头部信息。参数形如key-value数组:key是头部的名称,不应该包括空白、冒号或换行;value是头部的值,不应该包括换行。比如["Content-Type","application/json"]。
  21237. */
  21238. __proto.send=function(url,data,method,responseType,headers){
  21239. (method===void 0)&& (method="get");
  21240. (responseType===void 0)&& (responseType="text");
  21241. this._responseType=responseType;
  21242. this._data=null;
  21243. this._url=url;
  21244. var _this=this;
  21245. var http=this._http;
  21246. url=URL.getAdptedFilePath(url);
  21247. http.open(method,url,true);
  21248. if (headers){
  21249. for (var i=0;i < headers.length;i++){
  21250. http.setRequestHeader(headers[i++],headers[i]);
  21251. }
  21252. }else if (!Render.isConchApp){
  21253. if (!data || (typeof data=='string'))http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  21254. else http.setRequestHeader("Content-Type","application/json");
  21255. }
  21256. http.responseType=responseType!=="arraybuffer" ? "text" :"arraybuffer";
  21257. http.onerror=function (e){
  21258. _this._onError(e);
  21259. }
  21260. http.onabort=function (e){
  21261. _this._onAbort(e);
  21262. }
  21263. http.onprogress=function (e){
  21264. _this._onProgress(e);
  21265. }
  21266. http.onload=function (e){
  21267. _this._onLoad(e);
  21268. }
  21269. http.send(data);
  21270. }
  21271. /**
  21272. *@private
  21273. *请求进度的侦听处理函数。
  21274. *@param e 事件对象。
  21275. */
  21276. __proto._onProgress=function(e){
  21277. if (e && e.lengthComputable)this.event(/*laya.events.Event.PROGRESS*/"progress",e.loaded / e.total);
  21278. }
  21279. /**
  21280. *@private
  21281. *请求中断的侦听处理函数。
  21282. *@param e 事件对象。
  21283. */
  21284. __proto._onAbort=function(e){
  21285. this.error("Request was aborted by user");
  21286. }
  21287. /**
  21288. *@private
  21289. *请求出错侦的听处理函数。
  21290. *@param e 事件对象。
  21291. */
  21292. __proto._onError=function(e){
  21293. this.error("Request failed Status:"+this._http.status+" text:"+this._http.statusText);
  21294. }
  21295. /**
  21296. *@private
  21297. *请求消息返回的侦听处理函数。
  21298. *@param e 事件对象。
  21299. */
  21300. __proto._onLoad=function(e){
  21301. var http=this._http;
  21302. var status=http.status!==undefined ? http.status :200;
  21303. if (status===200 || status===204 || status===0){
  21304. this.complete();
  21305. }else {
  21306. this.error("["+http.status+"]"+http.statusText+":"+http.responseURL);
  21307. }
  21308. }
  21309. /**
  21310. *@private
  21311. *请求错误的处理函数。
  21312. *@param message 错误信息。
  21313. */
  21314. __proto.error=function(message){
  21315. this.clear();
  21316. console.warn(this.url,message);
  21317. this.event(/*laya.events.Event.ERROR*/"error",message);
  21318. }
  21319. /**
  21320. *@private
  21321. *请求成功完成的处理函数。
  21322. */
  21323. __proto.complete=function(){
  21324. this.clear();
  21325. var flag=true;
  21326. try {
  21327. if (this._responseType==="json"){
  21328. this._data=JSON.parse(this._http.responseText);
  21329. }else if (this._responseType==="xml"){
  21330. this._data=Utils.parseXMLFromString(this._http.responseText);
  21331. }else {
  21332. this._data=this._http.response || this._http.responseText;
  21333. }
  21334. }catch (e){
  21335. flag=false;
  21336. this.error(e.message);
  21337. }
  21338. flag && this.event(/*laya.events.Event.COMPLETE*/"complete",(this._data instanceof Array)? [this._data] :this._data);
  21339. }
  21340. /**
  21341. *@private
  21342. *清除当前请求。
  21343. */
  21344. __proto.clear=function(){
  21345. var http=this._http;
  21346. http.onerror=http.onabort=http.onprogress=http.onload=null;
  21347. }
  21348. /**请求的地址。*/
  21349. __getset(0,__proto,'url',function(){
  21350. return this._url;
  21351. });
  21352. /**
  21353. *本对象所封装的原生 XMLHttpRequest 引用。
  21354. */
  21355. __getset(0,__proto,'http',function(){
  21356. return this._http;
  21357. });
  21358. /**返回的数据。*/
  21359. __getset(0,__proto,'data',function(){
  21360. return this._data;
  21361. });
  21362. return HttpRequest;
  21363. })(EventDispatcher)
  21364. /**
  21365. *<code>Loader</code> 类可用来加载文本、JSON、XML、二进制、图像等资源。
  21366. */
  21367. //class laya.net.Loader extends laya.events.EventDispatcher
  21368. var Loader=(function(_super){
  21369. function Loader(){
  21370. /**@private 加载后的数据对象,只读*/
  21371. this._data=null;
  21372. /**@private */
  21373. this._url=null;
  21374. /**@private */
  21375. this._type=null;
  21376. /**@private */
  21377. this._cache=false;
  21378. /**@private */
  21379. this._http=null;
  21380. /**@private */
  21381. this._useWorkerLoader=false;
  21382. /**@private 自定义解析不派发complete事件,但会派发loaded事件,手动调用endLoad方法再派发complete事件*/
  21383. this._customParse=false;
  21384. /**@private */
  21385. this._constructParams=null;
  21386. /**@private */
  21387. this._propertyParams=null;
  21388. /**@private */
  21389. this._createCache=false;
  21390. Loader.__super.call(this);
  21391. }
  21392. __class(Loader,'laya.net.Loader',_super);
  21393. var __proto=Loader.prototype;
  21394. /**
  21395. *加载资源。加载错误会派发 Event.ERROR 事件,参数为错误信息。
  21396. *@param url 资源地址。
  21397. *@param type (default=null)资源类型。可选值为:Loader.TEXT、Loader.JSON、Loader.XML、Loader.BUFFER、Loader.IMAGE、Loader.SOUND、Loader.ATLAS、Loader.FONT。如果为null,则根据文件后缀分析类型。
  21398. *@param cache (default=true)是否缓存数据。
  21399. *@param group (default=null)分组名称。
  21400. *@param ignoreCache (default=false)是否忽略缓存,强制重新加载。
  21401. *@param useWorkerLoader(default=false)是否使用worker加载(只针对IMAGE类型和ATLAS类型,并且浏览器支持的情况下生效)
  21402. */
  21403. __proto.load=function(url,type,cache,group,ignoreCache,useWorkerLoader){
  21404. (cache===void 0)&& (cache=true);
  21405. (ignoreCache===void 0)&& (ignoreCache=false);
  21406. (useWorkerLoader===void 0)&& (useWorkerLoader=false);
  21407. if (!url){
  21408. this.onLoaded(null);
  21409. return;
  21410. }
  21411. Loader.setGroup(url,"666");
  21412. this._url=url;
  21413. if (url.indexOf("data:image")===0)type="image";
  21414. else url=URL.formatURL(url);
  21415. this._type=type || (type=Loader.getTypeFromUrl(this._url));
  21416. this._cache=cache;
  21417. this._useWorkerLoader=useWorkerLoader;
  21418. this._data=null;
  21419. if (useWorkerLoader)WorkerLoader.enableWorkerLoader();
  21420. if (!ignoreCache && Loader.loadedMap[url]){
  21421. this._data=Loader.loadedMap[url];
  21422. this.event(/*laya.events.Event.PROGRESS*/"progress",1);
  21423. this.event(/*laya.events.Event.COMPLETE*/"complete",this._data);
  21424. return;
  21425. }
  21426. if (group)Loader.setGroup(url,group);
  21427. if (Loader.parserMap[type] !=null){
  21428. this._customParse=true;
  21429. if (((Loader.parserMap[type])instanceof laya.utils.Handler ))Loader.parserMap[type].runWith(this);
  21430. else Loader.parserMap[type].call(null,this);
  21431. return;
  21432. }
  21433. if (type==="image" || type==="htmlimage" || type==="nativeimage")return this._loadImage(url);
  21434. if (type==="sound")return this._loadSound(url);
  21435. if (type==="ttf")return this._loadTTF(url);
  21436. var contentType;
  21437. switch (type){
  21438. case "atlas":
  21439. case "prefab":
  21440. case "plf":
  21441. contentType="json";
  21442. break ;
  21443. case "font":
  21444. contentType="xml";
  21445. break ;
  21446. case "plfb":
  21447. contentType="arraybuffer";
  21448. break ;
  21449. default :
  21450. contentType=type;
  21451. }
  21452. if (Loader.preLoadedMap[url]){
  21453. this.onLoaded(Loader.preLoadedMap[url]);
  21454. }else {
  21455. if (!this._http){
  21456. this._http=new HttpRequest();
  21457. this._http.on(/*laya.events.Event.PROGRESS*/"progress",this,this.onProgress);
  21458. this._http.on(/*laya.events.Event.ERROR*/"error",this,this.onError);
  21459. this._http.on(/*laya.events.Event.COMPLETE*/"complete",this,this.onLoaded);
  21460. }
  21461. this._http.send(url,null,"get",contentType);
  21462. }
  21463. }
  21464. /**
  21465. *@private
  21466. *加载TTF资源。
  21467. *@param url 资源地址。
  21468. */
  21469. __proto._loadTTF=function(url){
  21470. url=URL.formatURL(url);
  21471. var ttfLoader=new TTFLoader();
  21472. ttfLoader.complete=Handler.create(this,this.onLoaded);
  21473. ttfLoader.load(url);
  21474. }
  21475. /**
  21476. *@private
  21477. *加载图片资源。
  21478. *@param url 资源地址。
  21479. */
  21480. __proto._loadImage=function(url){
  21481. url=URL.formatURL(url);
  21482. var _this=this;
  21483. var image;
  21484. function clear (){
  21485. var img=image;
  21486. if (img){
  21487. img.onload=null;
  21488. img.onerror=null;
  21489. delete Loader._imgCache[url];
  21490. }
  21491. };
  21492. var onerror=function (){
  21493. clear();
  21494. _this.event(/*laya.events.Event.ERROR*/"error","Load image failed");
  21495. }
  21496. if (this._type==="nativeimage"){
  21497. var onload=function (){
  21498. clear();
  21499. _this.onLoaded(image);
  21500. };
  21501. image=new Browser.window.Image();
  21502. image.crossOrigin="";
  21503. image.onload=onload;
  21504. image.onerror=onerror;
  21505. image.src=url;
  21506. Loader._imgCache[url]=image;
  21507. }else {
  21508. var ext=Utils.getFileExtension(url);
  21509. if (ext==="ktx" || ext==="pvr"){
  21510. onload=function (imageData){
  21511. var format=0;
  21512. switch (ext){
  21513. case "ktx":
  21514. format=5;
  21515. break ;
  21516. case "pvr":
  21517. format=12;
  21518. break ;
  21519. }
  21520. image=new Texture2D(0,0,format,false,false);
  21521. image.wrapModeU=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  21522. image.wrapModeV=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  21523. image.setCompressData(imageData);
  21524. image._setCreateURL(url);
  21525. clear();
  21526. _this.onLoaded(image);
  21527. };
  21528. var tempHttp;
  21529. tempHttp=new HttpRequest();
  21530. tempHttp.on(/*laya.events.Event.ERROR*/"error",null,onerror);
  21531. tempHttp.on(/*laya.events.Event.COMPLETE*/"complete",null,onload);
  21532. tempHttp.send(url,null,"get",/*CLASS CONST:laya.net.Loader.BUFFER*/"arraybuffer");
  21533. }else {
  21534. var imageSource=new Browser.window.Image();
  21535. onload=function (){
  21536. var tex=new Texture2D(imageSource.width,imageSource.height,1,false,false);
  21537. tex.wrapModeU=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  21538. tex.wrapModeV=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  21539. tex.loadImageSource(imageSource,true);
  21540. tex._setCreateURL(url);
  21541. clear();
  21542. _this.onLoaded(tex);
  21543. };
  21544. imageSource.crossOrigin="";
  21545. imageSource.onload=onload;
  21546. imageSource.onerror=onerror;
  21547. imageSource.src=url;
  21548. Loader._imgCache[url]=imageSource;
  21549. }
  21550. }
  21551. }
  21552. /**
  21553. *@private
  21554. *加载声音资源。
  21555. *@param url 资源地址。
  21556. */
  21557. __proto._loadSound=function(url){
  21558. var sound=(new SoundManager._soundClass());
  21559. var _this=this;
  21560. sound.on(/*laya.events.Event.COMPLETE*/"complete",this,soundOnload);
  21561. sound.on(/*laya.events.Event.ERROR*/"error",this,soundOnErr);
  21562. sound.load(url);
  21563. function soundOnload (){
  21564. clear();
  21565. _this.onLoaded(sound);
  21566. }
  21567. function soundOnErr (){
  21568. clear();
  21569. sound.dispose();
  21570. _this.event(/*laya.events.Event.ERROR*/"error","Load sound failed");
  21571. }
  21572. function clear (){
  21573. sound.offAll();
  21574. }
  21575. }
  21576. /**@private */
  21577. __proto.onProgress=function(value){
  21578. if (this._type==="atlas")this.event(/*laya.events.Event.PROGRESS*/"progress",value *0.3);
  21579. else this.event(/*laya.events.Event.PROGRESS*/"progress",value);
  21580. }
  21581. /**@private */
  21582. __proto.onError=function(message){
  21583. this.event(/*laya.events.Event.ERROR*/"error",message);
  21584. }
  21585. /**
  21586. *资源加载完成的处理函数。
  21587. *@param data 数据。
  21588. */
  21589. __proto.onLoaded=function(data){
  21590. var type=this._type;
  21591. if (type=="plfb"){
  21592. this.parsePLFBData(data);
  21593. this.complete(data);
  21594. }else
  21595. if (type=="plf"){
  21596. this.parsePLFData(data);
  21597. this.complete(data);
  21598. }else if (type==="image"){
  21599. var tex=new Texture(data);
  21600. tex.url=this._url;
  21601. this.complete(tex);
  21602. }else if (type==="sound" || type==="htmlimage" || type==="nativeimage"){
  21603. this.complete(data);
  21604. }else if (type==="atlas"){
  21605. if (!data.url && !data._setContext){
  21606. if (!this._data){
  21607. this._data=data;
  21608. if (data.meta && data.meta.image){
  21609. var toloadPics=data.meta.image.split(",");
  21610. var split=this._url.indexOf("/")>=0 ? "/" :"\\";
  21611. var idx=this._url.lastIndexOf(split);
  21612. var folderPath=idx >=0 ? this._url.substr(0,idx+1):"";
  21613. var changeType;
  21614. if (Browser.onAndroid && data.meta.compressTextureAndroid){
  21615. changeType=".ktx";
  21616. }
  21617. if (Browser.onIOS && data.meta.compressTextureIOS){
  21618. changeType=".pvr";
  21619. }
  21620. for (var i=0,len=toloadPics.length;i < len;i++){
  21621. if (changeType){
  21622. toloadPics[i]=folderPath+toloadPics[i].replace(".png",changeType);
  21623. }else{
  21624. toloadPics[i]=folderPath+toloadPics[i];
  21625. }
  21626. }
  21627. }else {
  21628. toloadPics=[this._url.replace(".json",".png")];
  21629. }
  21630. toloadPics.reverse();
  21631. data.toLoads=toloadPics;
  21632. data.pics=[];
  21633. }
  21634. this.event(/*laya.events.Event.PROGRESS*/"progress",0.3+1 / toloadPics.length *0.6);
  21635. return this._loadImage(toloadPics.pop());
  21636. }else {
  21637. this._data.pics.push(data);
  21638. if (this._data.toLoads.length > 0){
  21639. this.event(/*laya.events.Event.PROGRESS*/"progress",0.3+1 / this._data.toLoads.length *0.6);
  21640. return this._loadImage(this._data.toLoads.pop());
  21641. };
  21642. var frames=this._data.frames;
  21643. var cleanUrl=this._url.split("?")[0];
  21644. var directory=(this._data.meta && this._data.meta.prefix)? this._data.meta.prefix :cleanUrl.substring(0,cleanUrl.lastIndexOf("."))+"/";
  21645. var pics=this._data.pics;
  21646. var atlasURL=URL.formatURL(this._url);
  21647. var map=Loader.atlasMap[atlasURL] || (Loader.atlasMap[atlasURL]=[]);
  21648. map.dir=directory;
  21649. var scaleRate=1;
  21650. if (this._data.meta && this._data.meta.scale && this._data.meta.scale !=1){
  21651. scaleRate=parseFloat(this._data.meta.scale);
  21652. for (var name in frames){
  21653. var obj=frames[name];
  21654. var tPic=pics[obj.frame.idx ? obj.frame.idx :0];
  21655. var url=URL.formatURL(directory+name);
  21656. (tPic).scaleRate=scaleRate;
  21657. var tTexture;
  21658. 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));
  21659. Loader.cacheRes(url,tTexture);
  21660. tTexture.url=url;
  21661. map.push(url);
  21662. }
  21663. }else {
  21664. for (name in frames){
  21665. obj=frames[name];
  21666. tPic=pics[obj.frame.idx ? obj.frame.idx :0];
  21667. url=URL.formatURL(directory+name);
  21668. 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));
  21669. Loader.cacheRes(url,tTexture);
  21670. tTexture.url=url;
  21671. map.push(url);
  21672. }
  21673. }
  21674. delete this._data.pics;
  21675. this.complete(this._data);
  21676. }
  21677. }else if (type==="font"){
  21678. if (!data._source){
  21679. this._data=data;
  21680. this.event(/*laya.events.Event.PROGRESS*/"progress",0.5);
  21681. return this._loadImage(this._url.replace(".fnt",".png"));
  21682. }else {
  21683. var bFont=new BitmapFont();
  21684. bFont.parseFont(this._data,new Texture(data));
  21685. var tArr=this._url.split(".fnt")[0].split("/");
  21686. var fontName=tArr[tArr.length-1];
  21687. Text.registerBitmapFont(fontName,bFont);
  21688. this._data=bFont;
  21689. this.complete(this._data);
  21690. }
  21691. }else if (type==="prefab"){
  21692. var prefab=new Prefab();
  21693. prefab.json=data;
  21694. this.complete(prefab);
  21695. }else {
  21696. this.complete(data);
  21697. }
  21698. }
  21699. __proto.parsePLFData=function(plfData){
  21700. var type;
  21701. var filePath;
  21702. var fileDic;
  21703. for (type in plfData){
  21704. fileDic=plfData[type];
  21705. switch (type){
  21706. case "json":
  21707. case "text":
  21708. for (filePath in fileDic){
  21709. Loader.preLoadedMap[URL.formatURL(filePath)]=fileDic[filePath]
  21710. }
  21711. break ;
  21712. default :
  21713. for (filePath in fileDic){
  21714. Loader.preLoadedMap[URL.formatURL(filePath)]=fileDic[filePath]
  21715. }
  21716. }
  21717. }
  21718. }
  21719. __proto.parsePLFBData=function(plfData){
  21720. var byte;
  21721. byte=new Byte(plfData);
  21722. var i=0,len=0;
  21723. len=byte.getInt32();
  21724. for (i=0;i < len;i++){
  21725. this.parseOnePLFBFile(byte);
  21726. }
  21727. }
  21728. __proto.parseOnePLFBFile=function(byte){
  21729. var fileLen=0;
  21730. var fileName;
  21731. var fileData;
  21732. fileName=byte.getUTFString();
  21733. fileLen=byte.getInt32();
  21734. fileData=byte.readArrayBuffer(fileLen);
  21735. Loader.preLoadedMap[URL.formatURL(fileName)]=fileData;
  21736. }
  21737. /**
  21738. *加载完成。
  21739. *@param data 加载的数据。
  21740. */
  21741. __proto.complete=function(data){
  21742. this._data=data;
  21743. if (this._customParse){
  21744. this.event(/*laya.events.Event.LOADED*/"loaded",(data instanceof Array)? [data] :data);
  21745. }else {
  21746. Loader._loaders.push(this);
  21747. if (!Loader._isWorking)Loader.checkNext();
  21748. }
  21749. }
  21750. /**
  21751. *结束加载,处理是否缓存及派发完成事件 <code>Event.COMPLETE</code> 。
  21752. *@param content 加载后的数据
  21753. */
  21754. __proto.endLoad=function(content){
  21755. content && (this._data=content);
  21756. if (this._cache)Loader.cacheRes(this._url,this._data);
  21757. this.event(/*laya.events.Event.PROGRESS*/"progress",1);
  21758. this.event(/*laya.events.Event.COMPLETE*/"complete",(this.data instanceof Array)? [this.data] :this.data);
  21759. }
  21760. /**加载地址。*/
  21761. __getset(0,__proto,'url',function(){
  21762. return this._url;
  21763. });
  21764. /**返回的数据。*/
  21765. __getset(0,__proto,'data',function(){
  21766. return this._data;
  21767. });
  21768. /**是否缓存。*/
  21769. __getset(0,__proto,'cache',function(){
  21770. return this._cache;
  21771. });
  21772. /**加载类型。*/
  21773. __getset(0,__proto,'type',function(){
  21774. return this._type;
  21775. });
  21776. Loader.getTypeFromUrl=function(url){
  21777. var type=Utils.getFileExtension(url);
  21778. if (type)return Loader.typeMap[type];
  21779. console.warn("Not recognize the resources suffix",url);
  21780. return "text";
  21781. }
  21782. Loader.checkNext=function(){
  21783. Loader._isWorking=true;
  21784. var startTimer=Browser.now();
  21785. var thisTimer=startTimer;
  21786. while (Loader._startIndex < Loader._loaders.length){
  21787. thisTimer=Browser.now();
  21788. Loader._loaders[Loader._startIndex].endLoad();
  21789. Loader._startIndex++;
  21790. if (Browser.now()-startTimer > Loader.maxTimeOut){
  21791. console.warn("loader callback cost a long time:"+(Browser.now()-startTimer)+" url="+Loader._loaders[Loader._startIndex-1].url);
  21792. Laya.systemTimer.frameOnce(1,null,Loader.checkNext);
  21793. return;
  21794. }
  21795. }
  21796. Loader._loaders.length=0;
  21797. Loader._startIndex=0;
  21798. Loader._isWorking=false;
  21799. }
  21800. Loader.clearRes=function(url){
  21801. url=URL.formatURL(url);
  21802. var arr=Loader.getAtlas(url);
  21803. if (arr){
  21804. for (var i=0,n=arr.length;i < n;i++){
  21805. var resUrl=arr[i];
  21806. var tex=Loader.getRes(resUrl);
  21807. delete Loader.loadedMap[resUrl];
  21808. if (tex)tex.destroy();
  21809. }
  21810. arr.length=0;
  21811. delete Loader.atlasMap[url];
  21812. delete Loader.loadedMap[url];
  21813. }else {
  21814. var res=Loader.loadedMap[url];
  21815. if (res){
  21816. delete Loader.loadedMap[url];
  21817. if ((res instanceof laya.resource.Texture )&& res.bitmap)(res).destroy();
  21818. }
  21819. }
  21820. }
  21821. Loader.clearTextureRes=function(url){
  21822. url=URL.formatURL(url);
  21823. var arr=laya.net.Loader.getAtlas(url);
  21824. var res=(arr && arr.length > 0)? laya.net.Loader.getRes(arr[0]):laya.net.Loader.getRes(url);
  21825. if ((res instanceof laya.resource.Texture ))
  21826. res.disposeBitmap();
  21827. }
  21828. Loader.getRes=function(url){
  21829. return Loader.loadedMap[URL.formatURL(url)];
  21830. }
  21831. Loader.getAtlas=function(url){
  21832. return Loader.atlasMap[URL.formatURL(url)];
  21833. }
  21834. Loader.cacheRes=function(url,data){
  21835. url=URL.formatURL(url);
  21836. if (Loader.loadedMap[url] !=null){
  21837. console.warn("Resources already exist,is repeated loading:",url);
  21838. }else {
  21839. Loader.loadedMap[url]=data;
  21840. }
  21841. }
  21842. Loader.setGroup=function(url,group){
  21843. if (!Loader.groupMap[group])Loader.groupMap[group]=[];
  21844. Loader.groupMap[group].push(url);
  21845. }
  21846. Loader.clearResByGroup=function(group){
  21847. if (!Loader.groupMap[group])return;
  21848. var arr=Loader.groupMap[group],i=0,len=arr.length;
  21849. for (i=0;i < len;i++){
  21850. Loader.clearRes(arr[i]);
  21851. }
  21852. arr.length=0;
  21853. }
  21854. Loader.TEXT="text";
  21855. Loader.JSON="json";
  21856. Loader.PREFAB="prefab";
  21857. Loader.XML="xml";
  21858. Loader.BUFFER="arraybuffer";
  21859. Loader.IMAGE="image";
  21860. Loader.SOUND="sound";
  21861. Loader.ATLAS="atlas";
  21862. Loader.FONT="font";
  21863. Loader.TTF="ttf";
  21864. Loader.PLF="plf";
  21865. Loader.PLFB="plfb";
  21866. Loader.HIERARCHY="HIERARCHY";
  21867. Loader.MESH="MESH";
  21868. Loader.MATERIAL="MATERIAL";
  21869. Loader.TEXTURE2D="TEXTURE2D";
  21870. Loader.TEXTURECUBE="TEXTURECUBE";
  21871. Loader.ANIMATIONCLIP="ANIMATIONCLIP";
  21872. Loader.AVATAR="AVATAR";
  21873. Loader.TERRAINHEIGHTDATA="TERRAINHEIGHTDATA";
  21874. Loader.TERRAINRES="TERRAIN";
  21875. 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"};
  21876. Loader.parserMap={};
  21877. Loader.maxTimeOut=100;
  21878. Loader.groupMap={};
  21879. Loader.loadedMap={};
  21880. Loader.atlasMap={};
  21881. Loader.preLoadedMap={};
  21882. Loader._imgCache={};
  21883. Loader._loaders=[];
  21884. Loader._isWorking=false;
  21885. Loader._startIndex=0;
  21886. return Loader;
  21887. })(EventDispatcher)
  21888. /**
  21889. *模糊滤镜
  21890. */
  21891. //class laya.filters.BlurFilter extends laya.filters.Filter
  21892. var BlurFilter=(function(_super){
  21893. function BlurFilter(strength){
  21894. /**模糊滤镜的强度(值越大,越不清晰 */
  21895. this.strength=NaN;
  21896. this.strength_sig2_2sig2_gauss1=[];
  21897. //给shader用的。避免创建对象
  21898. this.strength_sig2_native=null;
  21899. //给native用的
  21900. this.renderFunc=null;
  21901. BlurFilter.__super.call(this);
  21902. (strength===void 0)&& (strength=4);
  21903. this.strength=strength;
  21904. this._glRender=new BlurFilterGLRender();
  21905. }
  21906. __class(BlurFilter,'laya.filters.BlurFilter',_super);
  21907. var __proto=BlurFilter.prototype;
  21908. __proto.getStrenth_sig2_2sig2_native=function(){
  21909. if (!this.strength_sig2_native){
  21910. this.strength_sig2_native=new Float32Array(4);
  21911. };
  21912. var sigma=this.strength/3.0;
  21913. var sigma2=sigma *sigma;
  21914. this.strength_sig2_native[0]=this.strength;
  21915. this.strength_sig2_native[1]=sigma2;
  21916. this.strength_sig2_native[2]=2.0*sigma2;
  21917. this.strength_sig2_native[3]=1.0 / (2.0 *Math.PI *sigma2);
  21918. return this.strength_sig2_native;
  21919. }
  21920. /**
  21921. *@private
  21922. *当前滤镜的类型
  21923. */
  21924. __getset(0,__proto,'type',function(){
  21925. return 0x10;
  21926. });
  21927. return BlurFilter;
  21928. })(Filter)
  21929. //class laya.webgl.utils.Buffer2D extends laya.webgl.utils.Buffer
  21930. var Buffer2D=(function(_super){
  21931. function Buffer2D(){
  21932. this._maxsize=0;
  21933. this._upload=true;
  21934. this._uploadSize=0;
  21935. this._bufferSize=0;
  21936. this._u8Array=null;
  21937. Buffer2D.__super.call(this);
  21938. }
  21939. __class(Buffer2D,'laya.webgl.utils.Buffer2D',_super);
  21940. var __proto=Buffer2D.prototype;
  21941. __proto.setByteLength=function(value){
  21942. if (this._byteLength!==value){
  21943. value <=this._bufferSize || (this._resizeBuffer(value *2+256,true));
  21944. this._byteLength=value;
  21945. }
  21946. }
  21947. /**
  21948. *在当前的基础上需要多大空间,单位是byte
  21949. *@param sz
  21950. *@return 增加大小之前的写位置。单位是byte
  21951. */
  21952. __proto.needSize=function(sz){
  21953. var old=this._byteLength;
  21954. if (sz){
  21955. var needsz=this._byteLength+sz;
  21956. needsz <=this._bufferSize || (this._resizeBuffer(needsz << 1,true));
  21957. this._byteLength=needsz;
  21958. }
  21959. return old;
  21960. }
  21961. __proto._bufferData=function(){
  21962. this._maxsize=Math.max(this._maxsize,this._byteLength);
  21963. if (Stat.loopCount % 30==0){
  21964. if (this._buffer.byteLength > (this._maxsize+64)){
  21965. this._buffer=this._buffer.slice(0,this._maxsize+64);
  21966. this._bufferSize=this._buffer.byteLength;
  21967. this._checkArrayUse();
  21968. }
  21969. this._maxsize=this._byteLength;
  21970. }
  21971. if (this._uploadSize < this._buffer.byteLength){
  21972. this._uploadSize=this._buffer.byteLength;
  21973. LayaGL.instance.bufferData(this._bufferType,this._uploadSize,this._bufferUsage);
  21974. }
  21975. LayaGL.instance.bufferSubData(this._bufferType,0,new Uint8Array(this._buffer,0,this._byteLength));
  21976. }
  21977. //TODO:coverage
  21978. __proto._bufferSubData=function(offset,dataStart,dataLength){
  21979. (offset===void 0)&& (offset=0);
  21980. (dataStart===void 0)&& (dataStart=0);
  21981. (dataLength===void 0)&& (dataLength=0);
  21982. this._maxsize=Math.max(this._maxsize,this._byteLength);
  21983. if (Stat.loopCount % 30==0){
  21984. if (this._buffer.byteLength > (this._maxsize+64)){
  21985. this._buffer=this._buffer.slice(0,this._maxsize+64);
  21986. this._bufferSize=this._buffer.byteLength;
  21987. this._checkArrayUse();
  21988. }
  21989. this._maxsize=this._byteLength;
  21990. }
  21991. if (this._uploadSize < this._buffer.byteLength){
  21992. this._uploadSize=this._buffer.byteLength;
  21993. LayaGL.instance.bufferData(this._bufferType,this._uploadSize,this._bufferUsage);
  21994. }
  21995. if (dataStart || dataLength){
  21996. var subBuffer=this._buffer.slice(dataStart,dataLength);
  21997. LayaGL.instance.bufferSubData(this._bufferType,offset,subBuffer);
  21998. }else {
  21999. LayaGL.instance.bufferSubData(this._bufferType,offset,this._buffer);
  22000. }
  22001. }
  22002. /**
  22003. *buffer重新分配了,继承类根据需要做相应的处理。
  22004. */
  22005. __proto._checkArrayUse=function(){}
  22006. /**
  22007. *给vao使用的 _bind_upload函数。不要与已经绑定的判断是否相同
  22008. *@return
  22009. */
  22010. __proto._bind_uploadForVAO=function(){
  22011. if (!this._upload)
  22012. return false;
  22013. this._upload=false;
  22014. this._bindForVAO();
  22015. this._bufferData();
  22016. return true;
  22017. }
  22018. __proto._bind_upload=function(){
  22019. if (!this._upload)
  22020. return false;
  22021. this._upload=false;
  22022. this.bind();
  22023. this._bufferData();
  22024. return true;
  22025. }
  22026. //TODO:coverage
  22027. __proto._bind_subUpload=function(offset,dataStart,dataLength){
  22028. (offset===void 0)&& (offset=0);
  22029. (dataStart===void 0)&& (dataStart=0);
  22030. (dataLength===void 0)&& (dataLength=0);
  22031. if (!this._upload)
  22032. return false;
  22033. this._upload=false;
  22034. this.bind();
  22035. this._bufferSubData(offset,dataStart,dataLength);
  22036. return true;
  22037. }
  22038. /**
  22039. *重新分配buffer大小,如果nsz比原来的小则什么都不做。
  22040. *@param nsz buffer大小,单位是byte。
  22041. *@param copy 是否拷贝原来的buffer的数据。
  22042. *@return
  22043. */
  22044. __proto._resizeBuffer=function(nsz,copy){
  22045. var buff=this._buffer;
  22046. if (nsz <=buff.byteLength)
  22047. return this;
  22048. var u8buf=this._u8Array;
  22049. if (copy && buff && buff.byteLength > 0){
  22050. var newbuffer=new ArrayBuffer(nsz);
  22051. var oldU8Arr=(u8buf && u8buf.buffer==buff)?u8buf :new Uint8Array(buff);
  22052. u8buf=this._u8Array=new Uint8Array(newbuffer);
  22053. u8buf.set(oldU8Arr,0);
  22054. buff=this._buffer=newbuffer;
  22055. }else{
  22056. buff=this._buffer=new ArrayBuffer(nsz);
  22057. this._u8Array=null;
  22058. }
  22059. this._checkArrayUse();
  22060. this._upload=true;
  22061. this._bufferSize=buff.byteLength;
  22062. return this;
  22063. }
  22064. __proto.append=function(data){
  22065. this._upload=true;
  22066. var byteLen=0,n;
  22067. byteLen=data.byteLength;
  22068. if ((data instanceof Uint8Array)){
  22069. this._resizeBuffer(this._byteLength+byteLen,true);
  22070. n=new Uint8Array(this._buffer,this._byteLength);
  22071. }else if ((data instanceof Uint16Array)){
  22072. this._resizeBuffer(this._byteLength+byteLen,true);
  22073. n=new Uint16Array(this._buffer,this._byteLength);
  22074. }else if ((data instanceof Float32Array)){
  22075. this._resizeBuffer(this._byteLength+byteLen,true);
  22076. n=new Float32Array(this._buffer,this._byteLength);
  22077. }
  22078. n.set(data,0);
  22079. this._byteLength+=byteLen;
  22080. this._checkArrayUse();
  22081. }
  22082. /**
  22083. *附加Uint16Array的数据。数据长度是len。byte的话要*2
  22084. *@param data
  22085. *@param len
  22086. */
  22087. __proto.appendU16Array=function(data,len){
  22088. this._resizeBuffer(this._byteLength+len*2,true);
  22089. var u=new Uint16Array(this._buffer,this._byteLength,len);
  22090. if (len==6){
  22091. u[0]=data[0];u[1]=data[1];u[2]=data[2];
  22092. u[3]=data[3];u[4]=data[4];u[5]=data[5];
  22093. }else if(len>=100){
  22094. /*__JS__ */u.set(new Uint16Array(data.buffer,0,len));
  22095. }else{
  22096. for (var i=0;i < len;i++){
  22097. u[i]=data[i];
  22098. }
  22099. }
  22100. this._byteLength+=len *2;
  22101. this._checkArrayUse();
  22102. }
  22103. //TODO:coverage
  22104. __proto.appendEx=function(data,type){
  22105. this._upload=true;
  22106. var byteLen=0,n;
  22107. byteLen=data.byteLength;
  22108. this._resizeBuffer(this._byteLength+byteLen,true);
  22109. n=new type(this._buffer,this._byteLength);
  22110. n.set(data,0);
  22111. this._byteLength+=byteLen;
  22112. this._checkArrayUse();
  22113. }
  22114. //TODO:coverage
  22115. __proto.appendEx2=function(data,type,dataLen,perDataLen){
  22116. (perDataLen===void 0)&& (perDataLen=1);
  22117. this._upload=true;
  22118. var byteLen=0,n;
  22119. byteLen=dataLen*perDataLen;
  22120. this._resizeBuffer(this._byteLength+byteLen,true);
  22121. n=new type(this._buffer,this._byteLength);
  22122. var i=0;
  22123. for (i=0;i < dataLen;i++){
  22124. n[i]=data[i];
  22125. }
  22126. this._byteLength+=byteLen;
  22127. this._checkArrayUse();
  22128. }
  22129. //TODO:coverage
  22130. __proto.getBuffer=function(){
  22131. return this._buffer;
  22132. }
  22133. __proto.setNeedUpload=function(){
  22134. this._upload=true;
  22135. }
  22136. //TODO:coverage
  22137. __proto.getNeedUpload=function(){
  22138. return this._upload;
  22139. }
  22140. //TODO:coverage
  22141. __proto.upload=function(){
  22142. var scuess=this._bind_upload();
  22143. LayaGL.instance.bindBuffer(this._bufferType,null);
  22144. if(this._bufferType==/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892)Buffer._bindedVertexBuffer=null;
  22145. if(this._bufferType==/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893)Buffer._bindedIndexBuffer=null;
  22146. BaseShader.activeShader=null
  22147. return scuess;
  22148. }
  22149. //TODO:coverage
  22150. __proto.subUpload=function(offset,dataStart,dataLength){
  22151. (offset===void 0)&& (offset=0);
  22152. (dataStart===void 0)&& (dataStart=0);
  22153. (dataLength===void 0)&& (dataLength=0);
  22154. var scuess=this._bind_subUpload();
  22155. LayaGL.instance.bindBuffer(this._bufferType,null);
  22156. if(this._bufferType==/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892)Buffer._bindedVertexBuffer=null;
  22157. if(this._bufferType==/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893)Buffer._bindedIndexBuffer=null;
  22158. BaseShader.activeShader=null
  22159. return scuess;
  22160. }
  22161. __proto._disposeResource=function(){
  22162. this._upload=true;
  22163. this._uploadSize=0;
  22164. }
  22165. /**
  22166. *清理数据。保留ArrayBuffer
  22167. */
  22168. __proto.clear=function(){
  22169. this._byteLength=0;
  22170. this._upload=true;
  22171. }
  22172. //反正常常要拷贝老的数据,所以保留这个可以提高效率
  22173. __getset(0,__proto,'bufferLength',function(){
  22174. return this._buffer.byteLength;
  22175. });
  22176. __getset(0,__proto,'byteLength',null,function(value){
  22177. this.setByteLength(value);
  22178. });
  22179. Buffer2D.__int__=function(gl){}
  22180. Buffer2D.FLOAT32=4;
  22181. Buffer2D.SHORT=2;
  22182. return Buffer2D;
  22183. })(Buffer)
  22184. /**
  22185. *发光滤镜(也可以当成阴影滤使用)
  22186. */
  22187. //class laya.filters.GlowFilter extends laya.filters.Filter
  22188. var GlowFilter=(function(_super){
  22189. function GlowFilter(color,blur,offX,offY){
  22190. //给shader用
  22191. this._sv_blurInfo2=[0,0,1,0];
  22192. /**滤镜的颜色*/
  22193. this._color=null;
  22194. this._color_native=null;
  22195. this._blurInof1_native=null;
  22196. this._blurInof2_native=null;
  22197. GlowFilter.__super.call(this);
  22198. this._elements=new Float32Array(9);
  22199. this._sv_blurInfo1=new Array(4);
  22200. (blur===void 0)&& (blur=4);
  22201. (offX===void 0)&& (offX=6);
  22202. (offY===void 0)&& (offY=6);
  22203. this._color=new ColorUtils(color);
  22204. this.blur=Math.min(blur,20);
  22205. this.offX=offX;
  22206. this.offY=offY;
  22207. this._sv_blurInfo1[0]=this._sv_blurInfo1[1]=this.blur;this._sv_blurInfo1[2]=offX;this._sv_blurInfo1[3]=-offY;
  22208. this._glRender=new GlowFilterGLRender();
  22209. }
  22210. __class(GlowFilter,'laya.filters.GlowFilter',_super);
  22211. var __proto=GlowFilter.prototype;
  22212. /**@private */
  22213. __proto.getColor=function(){
  22214. return this._color.arrColor;
  22215. }
  22216. __proto.getColorNative=function(){
  22217. if (!this._color_native){
  22218. this._color_native=new Float32Array(4);
  22219. };
  22220. var color=this.getColor();
  22221. this._color_native[0]=color[0];
  22222. this._color_native[1]=color[1];
  22223. this._color_native[2]=color[2];
  22224. this._color_native[3]=color[3];
  22225. return this._color_native;
  22226. }
  22227. __proto.getBlurInfo1Native=function(){
  22228. if (!this._blurInof1_native){
  22229. this._blurInof1_native=new Float32Array(4);
  22230. }
  22231. this._blurInof1_native[0]=this._blurInof1_native[1]=this.blur;
  22232. this._blurInof1_native[2]=this.offX;
  22233. this._blurInof1_native[3]=this.offY;
  22234. return this._blurInof1_native;
  22235. }
  22236. __proto.getBlurInfo2Native=function(){
  22237. if (!this._blurInof2_native){
  22238. this._blurInof2_native=new Float32Array(4);
  22239. }
  22240. this._blurInof2_native[2]=1;
  22241. return this._blurInof2_native;
  22242. }
  22243. /**
  22244. *@private
  22245. *滤镜类型
  22246. */
  22247. __getset(0,__proto,'type',function(){
  22248. return 0x08;
  22249. });
  22250. /**@private */
  22251. /**@private */
  22252. __getset(0,__proto,'offY',function(){
  22253. return this._elements[6];
  22254. },function(value){
  22255. this._elements[6]=value;
  22256. this._sv_blurInfo1[3]=-value;
  22257. });
  22258. /**@private */
  22259. /**@private */
  22260. __getset(0,__proto,'offX',function(){
  22261. return this._elements[5];
  22262. },function(value){
  22263. this._elements[5]=value;
  22264. this._sv_blurInfo1[2]=value;
  22265. });
  22266. /**@private */
  22267. /**@private */
  22268. __getset(0,__proto,'blur',function(){
  22269. return this._elements[4];
  22270. },function(value){
  22271. this._elements[4]=value;
  22272. this._sv_blurInfo1[0]=this._sv_blurInfo1[1]=value;
  22273. });
  22274. return GlowFilter;
  22275. })(Filter)
  22276. /**
  22277. *drawImage,fillRect等会用到的简单的mesh。每次添加必然是一个四边形。
  22278. */
  22279. //class laya.webgl.utils.MeshQuadTexture extends laya.webgl.utils.Mesh2D
  22280. var MeshQuadTexture=(function(_super){
  22281. //private static var _num;
  22282. function MeshQuadTexture(){
  22283. MeshQuadTexture.__super.call(this,/*CLASS CONST:laya.webgl.utils.MeshQuadTexture.const_stride*/24,4,4);
  22284. this.canReuse=true;
  22285. this.setAttributes(laya.webgl.utils.MeshQuadTexture._fixattriInfo);
  22286. if(!laya.webgl.utils.MeshQuadTexture._fixib){
  22287. this.createQuadIB(MeshQuadTexture._maxIB);
  22288. laya.webgl.utils.MeshQuadTexture._fixib=this._ib;
  22289. }else {
  22290. this._ib=laya.webgl.utils.MeshQuadTexture._fixib;
  22291. this._quadNum=MeshQuadTexture._maxIB;
  22292. }
  22293. }
  22294. __class(MeshQuadTexture,'laya.webgl.utils.MeshQuadTexture',_super);
  22295. var __proto=MeshQuadTexture.prototype;
  22296. /**
  22297. *把本对象放到回收池中,以便getMesh能用。
  22298. */
  22299. __proto.releaseMesh=function(){
  22300. this._vb.setByteLength(0);
  22301. this.vertNum=0;
  22302. this.indexNum=0;
  22303. laya.webgl.utils.MeshQuadTexture._POOL.push(this);
  22304. }
  22305. __proto.destroy=function(){
  22306. this._vb.destroy();
  22307. this._vb.deleteBuffer();
  22308. }
  22309. /**
  22310. *
  22311. *@param pos
  22312. *@param uv
  22313. *@param color
  22314. *@param clip ox,oy,xx,xy,yx,yy
  22315. *@param useTex 是否使用贴图。false的话是给fillRect用的
  22316. */
  22317. __proto.addQuad=function(pos,uv,color,useTex){
  22318. var vb=this._vb;
  22319. var vpos=(vb._byteLength >> 2);
  22320. vb.setByteLength((vpos+/*CLASS CONST:laya.webgl.utils.MeshQuadTexture.const_stride*/24)<<2);
  22321. var vbdata=vb._floatArray32 || vb.getFloat32Array();
  22322. var vbu32Arr=vb._uint32Array;
  22323. var cpos=vpos;
  22324. var useTexVal=useTex?0xff:0;
  22325. vbdata[cpos++]=pos[0];vbdata[cpos++]=pos[1];vbdata[cpos++]=uv[0];vbdata[cpos++]=uv[1];vbu32Arr[cpos++]=color;vbu32Arr[cpos++]=useTexVal;
  22326. vbdata[cpos++]=pos[2];vbdata[cpos++]=pos[3];vbdata[cpos++]=uv[2];vbdata[cpos++]=uv[3];vbu32Arr[cpos++]=color;vbu32Arr[cpos++]=useTexVal;
  22327. vbdata[cpos++]=pos[4];vbdata[cpos++]=pos[5];vbdata[cpos++]=uv[4];vbdata[cpos++]=uv[5];vbu32Arr[cpos++]=color;vbu32Arr[cpos++]=useTexVal;
  22328. vbdata[cpos++]=pos[6];vbdata[cpos++]=pos[7];vbdata[cpos++]=uv[6];vbdata[cpos++]=uv[7];vbu32Arr[cpos++]=color;vbu32Arr[cpos++]=useTexVal;
  22329. vb._upload=true;
  22330. }
  22331. MeshQuadTexture.getAMesh=function(mainctx){
  22332. var ret=null;
  22333. if (laya.webgl.utils.MeshQuadTexture._POOL.length){
  22334. ret=laya.webgl.utils.MeshQuadTexture._POOL.pop();
  22335. }else
  22336. ret=new MeshQuadTexture();
  22337. mainctx && ret._vb._resizeBuffer(64 *1024 *24,false);
  22338. return ret;
  22339. }
  22340. MeshQuadTexture.const_stride=24;
  22341. MeshQuadTexture._fixib=null;
  22342. MeshQuadTexture._maxIB=16 *1024;
  22343. MeshQuadTexture._POOL=[];
  22344. __static(MeshQuadTexture,
  22345. ['_fixattriInfo',function(){return this._fixattriInfo=[
  22346. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,0,
  22347. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,16,
  22348. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,20];}
  22349. ]);
  22350. return MeshQuadTexture;
  22351. })(Mesh2D)
  22352. /**
  22353. *@private
  22354. *web audio api方式播放声音
  22355. */
  22356. //class laya.media.webaudio.WebAudioSound extends laya.events.EventDispatcher
  22357. var WebAudioSound=(function(_super){
  22358. function WebAudioSound(){
  22359. /**
  22360. *声音URL
  22361. */
  22362. this.url=null;
  22363. /**
  22364. *是否已加载完成
  22365. */
  22366. this.loaded=false;
  22367. /**
  22368. *声音文件数据
  22369. */
  22370. this.data=null;
  22371. /**
  22372. *声音原始文件数据
  22373. */
  22374. this.audioBuffer=null;
  22375. /**
  22376. *待播放的声音列表
  22377. */
  22378. this.__toPlays=null;
  22379. /**
  22380. *@private
  22381. */
  22382. this._disposed=false;
  22383. WebAudioSound.__super.call(this);
  22384. }
  22385. __class(WebAudioSound,'laya.media.webaudio.WebAudioSound',_super);
  22386. var __proto=WebAudioSound.prototype;
  22387. /**
  22388. *加载声音
  22389. *@param url
  22390. *
  22391. */
  22392. __proto.load=function(url){
  22393. var me=this;
  22394. url=URL.formatURL(url);
  22395. this.url=url;
  22396. this.audioBuffer=WebAudioSound._dataCache[url];
  22397. if (this.audioBuffer){
  22398. this._loaded(this.audioBuffer);
  22399. return;
  22400. }
  22401. WebAudioSound.e.on("loaded:"+url,this,this._loaded);
  22402. WebAudioSound.e.on("err:"+url,this,this._err);
  22403. if (WebAudioSound.__loadingSound[url]){
  22404. return;
  22405. }
  22406. WebAudioSound.__loadingSound[url]=true;
  22407. var request=new Browser.window.XMLHttpRequest();
  22408. request.open("GET",url,true);
  22409. request.responseType="arraybuffer";
  22410. request.onload=function (){
  22411. if (me._disposed){
  22412. me._removeLoadEvents();
  22413. return;
  22414. }
  22415. me.data=request.response;
  22416. WebAudioSound.buffs.push({"buffer":me.data,"url":me.url});
  22417. WebAudioSound.decode();
  22418. };
  22419. request.onerror=function (e){
  22420. me._err();
  22421. }
  22422. request.send();
  22423. }
  22424. __proto._err=function(){
  22425. this._removeLoadEvents();
  22426. WebAudioSound.__loadingSound[this.url]=false;
  22427. this.event(/*laya.events.Event.ERROR*/"error");
  22428. }
  22429. __proto._loaded=function(audioBuffer){
  22430. this._removeLoadEvents();
  22431. if (this._disposed){
  22432. return;
  22433. }
  22434. this.audioBuffer=audioBuffer;
  22435. WebAudioSound._dataCache[this.url]=this.audioBuffer;
  22436. this.loaded=true;
  22437. this.event(/*laya.events.Event.COMPLETE*/"complete");
  22438. }
  22439. __proto._removeLoadEvents=function(){
  22440. WebAudioSound.e.off("loaded:"+this.url,this,this._loaded);
  22441. WebAudioSound.e.off("err:"+this.url,this,this._err);
  22442. }
  22443. __proto.__playAfterLoaded=function(){
  22444. if (!this.__toPlays)return;
  22445. var i=0,len=0;
  22446. var toPlays;
  22447. toPlays=this.__toPlays;
  22448. len=toPlays.length;
  22449. var tParams;
  22450. for (i=0;i < len;i++){
  22451. tParams=toPlays[i];
  22452. if (tParams[2] && !(tParams [2]).isStopped){
  22453. this.play(tParams[0],tParams[1],tParams[2]);
  22454. }
  22455. }
  22456. this.__toPlays.length=0;
  22457. }
  22458. /**
  22459. *播放声音
  22460. *@param startTime 起始时间
  22461. *@param loops 循环次数
  22462. *@return
  22463. *
  22464. */
  22465. __proto.play=function(startTime,loops,channel){
  22466. (startTime===void 0)&& (startTime=0);
  22467. (loops===void 0)&& (loops=0);
  22468. channel=channel ? channel :new WebAudioSoundChannel();
  22469. if (!this.audioBuffer){
  22470. if (this.url){
  22471. if (!this.__toPlays)this.__toPlays=[];
  22472. this.__toPlays.push([startTime,loops,channel]);
  22473. this.once(/*laya.events.Event.COMPLETE*/"complete",this,this.__playAfterLoaded);
  22474. this.load(this.url);
  22475. }
  22476. }
  22477. channel.url=this.url;
  22478. channel.loops=loops;
  22479. channel["audioBuffer"]=this.audioBuffer;
  22480. channel.startTime=startTime;
  22481. channel.play();
  22482. SoundManager.addChannel(channel);
  22483. return channel;
  22484. }
  22485. __proto.dispose=function(){
  22486. this._disposed=true;
  22487. delete WebAudioSound._dataCache[this.url];
  22488. delete WebAudioSound.__loadingSound[this.url];
  22489. this.audioBuffer=null;
  22490. this.data=null;
  22491. this.__toPlays=[];
  22492. }
  22493. __getset(0,__proto,'duration',function(){
  22494. if (this.audioBuffer){
  22495. return this.audioBuffer.duration;
  22496. }
  22497. return 0;
  22498. });
  22499. WebAudioSound.decode=function(){
  22500. if (WebAudioSound.buffs.length <=0 || WebAudioSound.isDecoding){
  22501. return;
  22502. }
  22503. WebAudioSound.isDecoding=true;
  22504. WebAudioSound.tInfo=WebAudioSound.buffs.shift();
  22505. WebAudioSound.ctx.decodeAudioData(WebAudioSound.tInfo["buffer"],WebAudioSound._done,WebAudioSound._fail);
  22506. }
  22507. WebAudioSound._done=function(audioBuffer){
  22508. WebAudioSound.e.event("loaded:"+WebAudioSound.tInfo.url,audioBuffer);
  22509. WebAudioSound.isDecoding=false;
  22510. WebAudioSound.decode();
  22511. }
  22512. WebAudioSound._fail=function(){
  22513. WebAudioSound.e.event("err:"+WebAudioSound.tInfo.url,null);
  22514. WebAudioSound.isDecoding=false;
  22515. WebAudioSound.decode();
  22516. }
  22517. WebAudioSound._playEmptySound=function(){
  22518. if (WebAudioSound.ctx==null){
  22519. return;
  22520. };
  22521. var source=WebAudioSound.ctx.createBufferSource();
  22522. source.buffer=WebAudioSound._miniBuffer;
  22523. source.connect(WebAudioSound.ctx.destination);
  22524. source.start(0,0,0);
  22525. }
  22526. WebAudioSound._unlock=function(){
  22527. if (WebAudioSound._unlocked){
  22528. return;
  22529. }
  22530. WebAudioSound._playEmptySound();
  22531. if (WebAudioSound.ctx.state=="running"){
  22532. Browser.document.removeEventListener("mousedown",WebAudioSound._unlock,true);
  22533. Browser.document.removeEventListener("touchend",WebAudioSound._unlock,true);
  22534. Browser.document.removeEventListener("touchstart",WebAudioSound._unlock,true);
  22535. WebAudioSound._unlocked=true;
  22536. }
  22537. }
  22538. WebAudioSound.initWebAudio=function(){
  22539. if (WebAudioSound.ctx.state !="running"){
  22540. WebAudioSound._unlock();
  22541. Browser.document.addEventListener("mousedown",WebAudioSound._unlock,true);
  22542. Browser.document.addEventListener("touchend",WebAudioSound._unlock,true);
  22543. Browser.document.addEventListener("touchstart",WebAudioSound._unlock,true);
  22544. }
  22545. }
  22546. WebAudioSound._dataCache={};
  22547. WebAudioSound.buffs=[];
  22548. WebAudioSound.isDecoding=false;
  22549. WebAudioSound._unlocked=false;
  22550. WebAudioSound.tInfo=null;
  22551. WebAudioSound.__loadingSound={};
  22552. __static(WebAudioSound,
  22553. ['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();}
  22554. ]);
  22555. return WebAudioSound;
  22556. })(EventDispatcher)
  22557. /**
  22558. *<p> <code>Socket</code> 封装了 HTML5 WebSocket ,允许服务器端与客户端进行全双工(full-duplex)的实时通信,并且允许跨域通信。在建立连接后,服务器和 Browser/Client Agent 都能主动的向对方发送或接收文本和二进制数据。</p>
  22559. *<p>要使用 <code>Socket</code> 类的方法,请先使用构造函数 <code>new Socket</code> 创建一个 <code>Socket</code> 对象。 <code>Socket</code> 以异步方式传输和接收数据。</p>
  22560. */
  22561. //class laya.net.Socket extends laya.events.EventDispatcher
  22562. var Socket=(function(_super){
  22563. function Socket(host,port,byteClass,protocols){
  22564. /**@private */
  22565. this._endian=null;
  22566. /**@private */
  22567. this._socket=null;
  22568. /**@private */
  22569. this._connected=false;
  22570. /**@private */
  22571. this._addInputPosition=0;
  22572. /**@private */
  22573. this._input=null;
  22574. /**@private */
  22575. this._output=null;
  22576. /**
  22577. *不再缓存服务端发来的数据,如果传输的数据为字符串格式,建议设置为true,减少二进制转换消耗。
  22578. */
  22579. this.disableInput=false;
  22580. /**
  22581. *用来发送和接收数据的 <code>Byte</code> 类。
  22582. */
  22583. this._byteClass=null;
  22584. /**
  22585. *<p>子协议名称。子协议名称字符串,或由多个子协议名称字符串构成的数组。必须在调用 connect 或者 connectByUrl 之前进行赋值,否则无效。</p>
  22586. *<p>指定后,只有当服务器选择了其中的某个子协议,连接才能建立成功,否则建立失败,派发 Event.ERROR 事件。</p>
  22587. *@see https://html.spec.whatwg.org/multipage/comms.html#dom-websocket
  22588. */
  22589. this.protocols=[];
  22590. Socket.__super.call(this);
  22591. (port===void 0)&& (port=0);
  22592. this._byteClass=byteClass ? byteClass :Byte;
  22593. this.protocols=protocols;
  22594. this.endian="bigEndian";
  22595. if (host && port > 0 && port < 65535)this.connect(host,port);
  22596. }
  22597. __class(Socket,'laya.net.Socket',_super);
  22598. var __proto=Socket.prototype;
  22599. /**
  22600. *<p>连接到指定的主机和端口。</p>
  22601. *<p>连接成功派发 Event.OPEN 事件;连接失败派发 Event.ERROR 事件;连接被关闭派发 Event.CLOSE 事件;接收到数据派发 Event.MESSAGE 事件; 除了 Event.MESSAGE 事件参数为数据内容,其他事件参数都是原生的 HTML DOM Event 对象。</p>
  22602. *@param host 服务器地址。
  22603. *@param port 服务器端口。
  22604. */
  22605. __proto.connect=function(host,port){
  22606. var url="ws://"+host+":"+port;
  22607. this.connectByUrl(url);
  22608. }
  22609. /**
  22610. *<p>连接到指定的服务端 WebSocket URL。 URL 类似 ws://yourdomain:port。</p>
  22611. *<p>连接成功派发 Event.OPEN 事件;连接失败派发 Event.ERROR 事件;连接被关闭派发 Event.CLOSE 事件;接收到数据派发 Event.MESSAGE 事件; 除了 Event.MESSAGE 事件参数为数据内容,其他事件参数都是原生的 HTML DOM Event 对象。</p>
  22612. *@param url 要连接的服务端 WebSocket URL。 URL 类似 ws://yourdomain:port。
  22613. */
  22614. __proto.connectByUrl=function(url){
  22615. var _$this=this;
  22616. if (this._socket !=null)this.close();
  22617. this._socket && this.cleanSocket();
  22618. if (!this.protocols || this.protocols.length==0){
  22619. this._socket=new Browser.window.WebSocket(url);
  22620. }else {
  22621. this._socket=new Browser.window.WebSocket(url,this.protocols);
  22622. }
  22623. this._socket.binaryType="arraybuffer";
  22624. this._output=new this._byteClass();
  22625. this._output.endian=this.endian;
  22626. this._input=new this._byteClass();
  22627. this._input.endian=this.endian;
  22628. this._addInputPosition=0;
  22629. this._socket.onopen=function (e){
  22630. _$this._onOpen(e);
  22631. };
  22632. this._socket.onmessage=function (msg){
  22633. _$this._onMessage(msg);
  22634. };
  22635. this._socket.onclose=function (e){
  22636. _$this._onClose(e);
  22637. };
  22638. this._socket.onerror=function (e){
  22639. _$this._onError(e);
  22640. };
  22641. }
  22642. /**
  22643. *清理Socket:关闭Socket链接,关闭事件监听,重置Socket
  22644. */
  22645. __proto.cleanSocket=function(){
  22646. this.close();
  22647. this._connected=false;
  22648. this._socket.onopen=null;
  22649. this._socket.onmessage=null;
  22650. this._socket.onclose=null;
  22651. this._socket.onerror=null;
  22652. this._socket=null;
  22653. }
  22654. /**
  22655. *关闭连接。
  22656. */
  22657. __proto.close=function(){
  22658. if (this._socket !=null){
  22659. try {
  22660. this._socket.close();
  22661. }catch (e){}
  22662. }
  22663. }
  22664. /**
  22665. *@private
  22666. *连接建立成功 。
  22667. */
  22668. __proto._onOpen=function(e){
  22669. this._connected=true;
  22670. this.event(/*laya.events.Event.OPEN*/"open",e);
  22671. }
  22672. /**
  22673. *@private
  22674. *接收到数据处理方法。
  22675. *@param msg 数据。
  22676. */
  22677. __proto._onMessage=function(msg){
  22678. if (!msg || !msg.data)return;
  22679. var data=msg.data;
  22680. if (this.disableInput && data){
  22681. this.event(/*laya.events.Event.MESSAGE*/"message",data);
  22682. return;
  22683. }
  22684. if (this._input.length > 0 && this._input.bytesAvailable < 1){
  22685. this._input.clear();
  22686. this._addInputPosition=0;
  22687. };
  22688. var pre=this._input.pos;
  22689. !this._addInputPosition && (this._addInputPosition=0);
  22690. this._input.pos=this._addInputPosition;
  22691. if (data){
  22692. if ((typeof data=='string')){
  22693. this._input.writeUTFBytes(data);
  22694. }else {
  22695. this._input.writeArrayBuffer(data);
  22696. }
  22697. this._addInputPosition=this._input.pos;
  22698. this._input.pos=pre;
  22699. }
  22700. this.event(/*laya.events.Event.MESSAGE*/"message",data);
  22701. }
  22702. /**
  22703. *@private
  22704. *连接被关闭处理方法。
  22705. */
  22706. __proto._onClose=function(e){
  22707. this._connected=false;
  22708. this.event(/*laya.events.Event.CLOSE*/"close",e)
  22709. }
  22710. /**
  22711. *@private
  22712. *出现异常处理方法。
  22713. */
  22714. __proto._onError=function(e){
  22715. this.event(/*laya.events.Event.ERROR*/"error",e)
  22716. }
  22717. /**
  22718. *发送数据到服务器。
  22719. *@param data 需要发送的数据,可以是String或者ArrayBuffer。
  22720. */
  22721. __proto.send=function(data){
  22722. this._socket.send(data);
  22723. }
  22724. /**
  22725. *发送缓冲区中的数据到服务器。
  22726. */
  22727. __proto.flush=function(){
  22728. if (this._output && this._output.length > 0){
  22729. var evt;
  22730. try {
  22731. this._socket && this._socket.send(this._output.__getBuffer().slice(0,this._output.length));
  22732. }catch (e){
  22733. evt=e;
  22734. }
  22735. this._output.endian=this.endian;
  22736. this._output.clear();
  22737. if (evt)this.event(/*laya.events.Event.ERROR*/"error",evt);
  22738. }
  22739. }
  22740. /**
  22741. *缓存的服务端发来的数据。
  22742. */
  22743. __getset(0,__proto,'input',function(){
  22744. return this._input;
  22745. });
  22746. /**
  22747. *表示需要发送至服务端的缓冲区中的数据。
  22748. */
  22749. __getset(0,__proto,'output',function(){
  22750. return this._output;
  22751. });
  22752. /**
  22753. *表示此 Socket 对象目前是否已连接。
  22754. */
  22755. __getset(0,__proto,'connected',function(){
  22756. return this._connected;
  22757. });
  22758. /**
  22759. *<p>主机字节序,是 CPU 存放数据的两种不同顺序,包括小端字节序和大端字节序。</p>
  22760. *<p> LITTLE_ENDIAN :小端字节序,地址低位存储值的低位,地址高位存储值的高位。</p>
  22761. *<p> BIG_ENDIAN :大端字节序,地址低位存储值的高位,地址高位存储值的低位。</p>
  22762. */
  22763. __getset(0,__proto,'endian',function(){
  22764. return this._endian;
  22765. },function(value){
  22766. this._endian=value;
  22767. if (this._input !=null)this._input.endian=value;
  22768. if (this._output !=null)this._output.endian=value;
  22769. });
  22770. Socket.LITTLE_ENDIAN="littleEndian";
  22771. Socket.BIG_ENDIAN="bigEndian";
  22772. return Socket;
  22773. })(EventDispatcher)
  22774. //class laya.webgl.shader.d2.value.TextureSV extends laya.webgl.shader.d2.value.Value2D
  22775. var TextureSV=(function(_super){
  22776. function TextureSV(subID){
  22777. this.u_colorMatrix=null;
  22778. this.strength=0;
  22779. this.blurInfo=null;
  22780. this.colorMat=null;
  22781. this.colorAlpha=null;
  22782. (subID===void 0)&& (subID=0);
  22783. TextureSV.__super.call(this,/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,subID);
  22784. this._attribLocation=['posuv',0,'attribColor',1,'attribFlags',2];
  22785. }
  22786. __class(TextureSV,'laya.webgl.shader.d2.value.TextureSV',_super);
  22787. var __proto=TextureSV.prototype;
  22788. // ,'clipDir',3,'clipRect',4];
  22789. __proto.clear=function(){
  22790. this.texture=null;
  22791. this.shader=null;
  22792. this.defines._value=this.subID+(WebGL.shaderHighPrecision? /*laya.webgl.shader.d2.ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION*/0x400:0);
  22793. }
  22794. return TextureSV;
  22795. })(Value2D)
  22796. /**
  22797. *<code>CommonScript</code> 类用于创建公共脚本类。
  22798. */
  22799. //class laya.components.CommonScript extends laya.components.Component
  22800. var CommonScript=(function(_super){
  22801. function CommonScript(){
  22802. CommonScript.__super.call(this);
  22803. }
  22804. __class(CommonScript,'laya.components.CommonScript',_super);
  22805. var __proto=CommonScript.prototype;
  22806. /**
  22807. *创建后只执行一次
  22808. *此方法为虚方法,使用时重写覆盖即可
  22809. */
  22810. __proto.onAwake=function(){}
  22811. /**
  22812. *每次启动后执行
  22813. *此方法为虚方法,使用时重写覆盖即可
  22814. */
  22815. __proto.onEnable=function(){}
  22816. /**
  22817. *第一次执行update之前执行,只会执行一次
  22818. *此方法为虚方法,使用时重写覆盖即可
  22819. */
  22820. __proto.onStart=function(){}
  22821. /**
  22822. *每帧更新时执行
  22823. *此方法为虚方法,使用时重写覆盖即可
  22824. */
  22825. __proto.onUpdate=function(){}
  22826. /**
  22827. *每帧更新时执行,在update之后执行
  22828. *此方法为虚方法,使用时重写覆盖即可
  22829. */
  22830. __proto.onLateUpdate=function(){}
  22831. /**
  22832. *禁用时执行
  22833. *此方法为虚方法,使用时重写覆盖即可
  22834. */
  22835. __proto.onDisable=function(){}
  22836. /**
  22837. *销毁时执行
  22838. *此方法为虚方法,使用时重写覆盖即可
  22839. */
  22840. __proto.onDestroy=function(){}
  22841. /**
  22842. *@inheritDoc
  22843. */
  22844. __getset(0,__proto,'isSingleton',function(){
  22845. return false;
  22846. });
  22847. return CommonScript;
  22848. })(Component)
  22849. /**
  22850. *<p> <code>LoaderManager</code> 类用于用于批量加载资源。此类是单例,不要手动实例化此类,请通过Laya.loader访问。</p>
  22851. *<p>全部队列加载完成,会派发 Event.COMPLETE 事件;如果队列中任意一个加载失败,会派发 Event.ERROR 事件,事件回调参数值为加载出错的资源地址。</p>
  22852. *<p> <code>LoaderManager</code> 类提供了以下几种功能:<br/>
  22853. *多线程:默认5个加载线程,可以通过maxLoader属性修改线程数量;<br/>
  22854. *多优先级:有0-4共5个优先级,优先级高的优先加载。0最高,4最低;<br/>
  22855. *重复过滤:自动过滤重复加载(不会有多个相同地址的资源同时加载)以及复用缓存资源,防止重复加载;<br/>
  22856. *错误重试:资源加载失败后,会重试加载(以最低优先级插入加载队列),retryNum设定加载失败后重试次数,retryDelay设定加载重试的时间间隔。</p>
  22857. *@see laya.net.Loader
  22858. */
  22859. //class laya.net.LoaderManager extends laya.events.EventDispatcher
  22860. var LoaderManager=(function(_super){
  22861. var ResInfo;
  22862. function LoaderManager(){
  22863. /**加载出错后的重试次数,默认重试一次*/
  22864. this.retryNum=1;
  22865. /**延迟时间多久再进行错误重试,默认立即重试*/
  22866. this.retryDelay=0;
  22867. /**最大下载线程,默认为5个*/
  22868. this.maxLoader=5;
  22869. /**@private */
  22870. this._loaders=[];
  22871. /**@private */
  22872. this._loaderCount=0;
  22873. /**@private */
  22874. this._resInfos=[];
  22875. /**@private */
  22876. this._infoPool=[];
  22877. /**@private */
  22878. this._maxPriority=5;
  22879. /**@private */
  22880. this._failRes={};
  22881. /**@private */
  22882. this._statInfo={count:1,loaded:1};
  22883. LoaderManager.__super.call(this);
  22884. for (var i=0;i < this._maxPriority;i++)this._resInfos[i]=[];
  22885. }
  22886. __class(LoaderManager,'laya.net.LoaderManager',_super);
  22887. var __proto=LoaderManager.prototype;
  22888. /**@private */
  22889. __proto.getProgress=function(){
  22890. return this._statInfo.loaded / this._statInfo.count;
  22891. }
  22892. /**@private */
  22893. __proto.resetProgress=function(){
  22894. this._statInfo.count=this._statInfo.loaded=1;
  22895. }
  22896. /**
  22897. *<p>根据clas类型创建一个未初始化资源的对象,随后进行异步加载,资源加载完成后,初始化对象的资源,并通过此对象派发 Event.LOADED 事件,事件回调参数值为此对象本身。套嵌资源的子资源会保留资源路径"?"后的部分。</p>
  22898. *<p>如果url为数组,返回true;否则返回指定的资源类对象,可以通过侦听此对象的 Event.LOADED 事件来判断资源是否已经加载完毕。</p>
  22899. *<p><b>注意:</b>cache参数只能对文件后缀为atlas的资源进行缓存控制,其他资源会忽略缓存,强制重新加载。</p>
  22900. *@param url 资源地址或者数组。如果url和clas同时指定了资源类型,优先使用url指定的资源类型。参数形如:[{url:xx,clas:xx,priority:xx,params:xx},{url:xx,clas:xx,priority:xx,params:xx}]。
  22901. *@param complete 加载结束回调。根据url类型不同分为2种情况:1. url为String类型,也就是单个资源地址,如果加载成功,则回调参数值为加载完成的资源,否则为null;2. url为数组类型,指定了一组要加载的资源,如果全部加载成功,则回调参数值为true,否则为false。
  22902. *@param progress 资源加载进度回调,回调参数值为当前资源加载的进度信息(0-1)。
  22903. *@param type 资源类型。
  22904. *@param constructParams 资源构造函数参数。
  22905. *@param propertyParams 资源属性参数。
  22906. *@param priority (default=1)加载的优先级,优先级高的优先加载。有0-4共5个优先级,0最高,4最低。
  22907. *@param cache 是否缓存加载的资源。
  22908. *@return 如果url为数组,返回true;否则返回指定的资源类对象。
  22909. */
  22910. __proto.create=function(url,complete,progress,type,constructParams,propertyParams,priority,cache){
  22911. (priority===void 0)&& (priority=1);
  22912. (cache===void 0)&& (cache=true);
  22913. this._create(url,true,complete,progress,type,constructParams,propertyParams,priority,cache);
  22914. }
  22915. /**
  22916. *@private
  22917. */
  22918. __proto._create=function(url,mainResou,complete,progress,type,constructParams,propertyParams,priority,cache){
  22919. (priority===void 0)&& (priority=1);
  22920. (cache===void 0)&& (cache=true);
  22921. if ((url instanceof Array)){
  22922. var allScuess=true;
  22923. var items=url;
  22924. var itemCount=items.length;
  22925. var loadedCount=0;
  22926. if (progress){
  22927. var progress2=Handler.create(progress.caller,progress.method,progress.args,false);
  22928. }
  22929. for (var i=0;i < itemCount;i++){
  22930. var item=items[i];
  22931. if ((typeof item=='string'))
  22932. item=items[i]={url:item};
  22933. item.progress=0;
  22934. }
  22935. for (i=0;i < itemCount;i++){
  22936. item=items[i];
  22937. var progressHandler=progress ? Handler.create(null,onProgress,[item],false):null;
  22938. var completeHandler=(progress || complete)? Handler.create(null,onComplete,[item]):null;
  22939. this._createOne(item.url,mainResou,completeHandler,progressHandler,item.type || type,item.constructParams || constructParams,item.propertyParams || propertyParams,item.priority || priority,cache);
  22940. }
  22941. function onComplete (item,content){
  22942. loadedCount++;
  22943. item.progress=1;
  22944. content || (allScuess=false);
  22945. if (loadedCount===itemCount && complete){
  22946. complete.runWith(allScuess);
  22947. }
  22948. }
  22949. function onProgress (item,value){
  22950. item.progress=value;
  22951. var num=0;
  22952. for (var j=0;j < itemCount;j++){
  22953. var item1=items[j];
  22954. num+=item1.progress;
  22955. };
  22956. var v=num / itemCount;
  22957. progress2.runWith(v);
  22958. }
  22959. }else {
  22960. this._createOne(url,mainResou,complete,progress,type,constructParams,propertyParams,priority,cache);
  22961. }
  22962. }
  22963. /**
  22964. *@private
  22965. */
  22966. __proto._createOne=function(url,mainResou,complete,progress,type,constructParams,propertyParams,priority,cache){
  22967. (priority===void 0)&& (priority=1);
  22968. (cache===void 0)&& (cache=true);
  22969. var item=this.getRes(url);
  22970. if (!item){
  22971. var extension=Utils.getFileExtension(url);
  22972. (type)|| (type=LoaderManager.createMap[extension] ? LoaderManager.createMap[extension][0] :null);
  22973. if (!type){
  22974. this.load(url,complete,progress,type,priority,cache);
  22975. return;
  22976. };
  22977. var parserMap=Loader.parserMap;
  22978. if (!parserMap[type]){
  22979. this.load(url,complete,progress,type,priority,cache);
  22980. return;
  22981. }
  22982. this._createLoad(url,Handler.create(null,onLoaded),progress,type,constructParams,propertyParams,priority,cache,true);
  22983. function onLoaded (createRes){
  22984. if (createRes){
  22985. if (!mainResou && (createRes instanceof laya.resource.Resource ))
  22986. (createRes)._addReference();
  22987. createRes._setCreateURL(url);
  22988. }
  22989. complete && complete.runWith(createRes);
  22990. Laya.loader.event(url);
  22991. };
  22992. }else {
  22993. if (!mainResou && (item instanceof laya.resource.Resource ))
  22994. item._addReference();
  22995. progress && progress.runWith(1);
  22996. complete && complete.runWith(item);
  22997. }
  22998. }
  22999. /**
  23000. *<p>加载资源。资源加载错误时,本对象会派发 Event.ERROR 事件,事件回调参数值为加载出错的资源地址。</p>
  23001. *<p>因为返回值为 LoaderManager 对象本身,所以可以使用如下语法:loaderManager.load(...).load(...);</p>
  23002. *@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}]。
  23003. *@param complete 加载结束回调。根据url类型不同分为2种情况:1. url为String类型,也就是单个资源地址,如果加载成功,则回调参数值为加载完成的资源,否则为null;2. url为数组类型,指定了一组要加载的资源,如果全部加载成功,则回调参数值为true,否则为false。
  23004. *@param progress 加载进度回调。回调参数值为当前资源的加载进度信息(0-1)。
  23005. *@param type 资源类型。比如:Loader.IMAGE。
  23006. *@param priority (default=1)加载的优先级,优先级高的优先加载。有0-4共5个优先级,0最高,4最低。
  23007. *@param cache 是否缓存加载结果。
  23008. *@param group 分组,方便对资源进行管理。
  23009. *@param ignoreCache 是否忽略缓存,强制重新加载。
  23010. *@param useWorkerLoader(default=false)是否使用worker加载(只针对IMAGE类型和ATLAS类型,并且浏览器支持的情况下生效)
  23011. *@return 此 LoaderManager 对象本身。
  23012. */
  23013. __proto.load=function(url,complete,progress,type,priority,cache,group,ignoreCache,useWorkerLoader){
  23014. var _$this=this;
  23015. (priority===void 0)&& (priority=1);
  23016. (cache===void 0)&& (cache=true);
  23017. (ignoreCache===void 0)&& (ignoreCache=false);
  23018. (useWorkerLoader===void 0)&& (useWorkerLoader=false);
  23019. if ((url instanceof Array))return this._loadAssets(url,complete,progress,type,priority,cache,group);
  23020. var content=Loader.getRes(url);
  23021. if (!ignoreCache && content !=null){
  23022. Laya.systemTimer.frameOnce(1,null,function(){
  23023. progress && progress.runWith(1);
  23024. complete && complete.runWith((content instanceof Array)?[content]:content);
  23025. _$this._loaderCount || _$this.event(/*laya.events.Event.COMPLETE*/"complete");
  23026. });
  23027. }else {
  23028. var original;
  23029. original=url;
  23030. url=AtlasInfoManager.getFileLoadPath(url);
  23031. if (url !=original && type!=="nativeimage"){
  23032. type=/*laya.net.Loader.ATLAS*/"atlas";
  23033. }else {
  23034. original=null;
  23035. };
  23036. var info=LoaderManager._resMap[url];
  23037. if (!info){
  23038. info=this._infoPool.length ? this._infoPool.pop():new ResInfo();
  23039. info.url=url;
  23040. info.type=type;
  23041. info.cache=cache;
  23042. info.group=group;
  23043. info.ignoreCache=ignoreCache;
  23044. info.useWorkerLoader=useWorkerLoader;
  23045. info.originalUrl=original;
  23046. complete && info.on(/*laya.events.Event.COMPLETE*/"complete",complete.caller,complete.method,complete.args);
  23047. progress && info.on(/*laya.events.Event.PROGRESS*/"progress",progress.caller,progress.method,progress.args);
  23048. LoaderManager._resMap[url]=info;
  23049. priority=priority < this._maxPriority ? priority :this._maxPriority-1;
  23050. this._resInfos[priority].push(info);
  23051. this._statInfo.count++;
  23052. this.event(/*laya.events.Event.PROGRESS*/"progress",this.getProgress());
  23053. this._next();
  23054. }else {
  23055. if (complete){
  23056. if (original){
  23057. complete && info._createListener(/*laya.events.Event.COMPLETE*/"complete",this,this._resInfoLoaded,[original,complete],false,false);
  23058. }else {
  23059. complete && info._createListener(/*laya.events.Event.COMPLETE*/"complete",complete.caller,complete.method,complete.args,false,false);
  23060. }
  23061. }
  23062. progress && info._createListener(/*laya.events.Event.PROGRESS*/"progress",progress.caller,progress.method,progress.args,false,false);
  23063. }
  23064. }
  23065. return this;
  23066. }
  23067. __proto._resInfoLoaded=function(original,complete){
  23068. complete.runWith(Loader.getRes(original));
  23069. }
  23070. /**
  23071. *@private
  23072. */
  23073. __proto._createLoad=function(url,complete,progress,type,constructParams,propertyParams,priority,cache,ignoreCache){
  23074. var _$this=this;
  23075. (priority===void 0)&& (priority=1);
  23076. (cache===void 0)&& (cache=true);
  23077. (ignoreCache===void 0)&& (ignoreCache=false);
  23078. if ((url instanceof Array))return this._loadAssets(url,complete,progress,type,priority,cache);
  23079. var content=Loader.getRes(url);
  23080. if (content !=null){
  23081. Laya.systemTimer.frameOnce(1,null,function(){
  23082. progress && progress.runWith(1);
  23083. complete && complete.runWith(content);
  23084. _$this._loaderCount || _$this.event(/*laya.events.Event.COMPLETE*/"complete");
  23085. });
  23086. }else {
  23087. var info=LoaderManager._resMap[url];
  23088. if (!info){
  23089. info=this._infoPool.length ? this._infoPool.pop():new ResInfo();
  23090. info.url=url;
  23091. info.type=type;
  23092. info.cache=false;
  23093. info.ignoreCache=ignoreCache;
  23094. info.originalUrl=null;
  23095. info.createCache=cache;
  23096. info.createConstructParams=constructParams;
  23097. info.createPropertyParams=propertyParams;
  23098. complete && info.on(/*laya.events.Event.COMPLETE*/"complete",complete.caller,complete.method,complete.args);
  23099. progress && info.on(/*laya.events.Event.PROGRESS*/"progress",progress.caller,progress.method,progress.args);
  23100. LoaderManager._resMap[url]=info;
  23101. priority=priority < this._maxPriority ? priority :this._maxPriority-1;
  23102. this._resInfos[priority].push(info);
  23103. this._statInfo.count++;
  23104. this.event(/*laya.events.Event.PROGRESS*/"progress",this.getProgress());
  23105. this._next();
  23106. }else {
  23107. complete && info._createListener(/*laya.events.Event.COMPLETE*/"complete",complete.caller,complete.method,complete.args,false,false);
  23108. progress && info._createListener(/*laya.events.Event.PROGRESS*/"progress",progress.caller,progress.method,progress.args,false,false);
  23109. }
  23110. }
  23111. return this;
  23112. }
  23113. __proto._next=function(){
  23114. if (this._loaderCount >=this.maxLoader)return;
  23115. for (var i=0;i < this._maxPriority;i++){
  23116. var infos=this._resInfos[i];
  23117. while (infos.length > 0){
  23118. var info=infos.shift();
  23119. if (info)return this._doLoad(info);
  23120. }
  23121. }
  23122. this._loaderCount || this.event(/*laya.events.Event.COMPLETE*/"complete");
  23123. }
  23124. __proto._doLoad=function(resInfo){
  23125. this._loaderCount++;
  23126. var loader=this._loaders.length ? this._loaders.pop():new Loader();
  23127. loader.on(/*laya.events.Event.COMPLETE*/"complete",null,onLoaded);
  23128. loader.on(/*laya.events.Event.PROGRESS*/"progress",null,function(num){
  23129. resInfo.event(/*laya.events.Event.PROGRESS*/"progress",num);
  23130. });
  23131. loader.on(/*laya.events.Event.ERROR*/"error",null,function(msg){
  23132. onLoaded(null);
  23133. });
  23134. var _me=this;
  23135. function onLoaded (data){
  23136. loader.offAll();
  23137. loader._data=null;
  23138. loader._customParse=false;
  23139. _me._loaders.push(loader);
  23140. _me._endLoad(resInfo,(data instanceof Array)? [data] :data);
  23141. _me._loaderCount--;
  23142. _me._next();
  23143. }
  23144. loader._constructParams=resInfo.createConstructParams;
  23145. loader._propertyParams=resInfo.createPropertyParams;
  23146. loader._createCache=resInfo.createCache;
  23147. loader.load(resInfo.url,resInfo.type,resInfo.cache,resInfo.group,resInfo.ignoreCache,resInfo.useWorkerLoader);
  23148. }
  23149. __proto._endLoad=function(resInfo,content){
  23150. var url=resInfo.url;
  23151. if (content==null){
  23152. var errorCount=this._failRes[url] || 0;
  23153. if (errorCount < this.retryNum){
  23154. console.warn("[warn]Retry to load:",url);
  23155. this._failRes[url]=errorCount+1;
  23156. Laya.systemTimer.once(this.retryDelay,this,this._addReTry,[resInfo],false);
  23157. return;
  23158. }else {
  23159. Loader.clearRes(url);
  23160. console.warn("[error]Failed to load:",url);
  23161. this.event(/*laya.events.Event.ERROR*/"error",url);
  23162. }
  23163. }
  23164. if (this._failRes[url])this._failRes[url]=0;
  23165. delete LoaderManager._resMap[url];
  23166. if (resInfo.originalUrl){
  23167. content=Loader.getRes(resInfo.originalUrl);
  23168. }
  23169. resInfo.event(/*laya.events.Event.COMPLETE*/"complete",content);
  23170. resInfo.offAll();
  23171. this._infoPool.push(resInfo);
  23172. this._statInfo.loaded++;
  23173. this.event(/*laya.events.Event.PROGRESS*/"progress",this.getProgress());
  23174. }
  23175. __proto._addReTry=function(resInfo){
  23176. this._resInfos[this._maxPriority-1].push(resInfo);
  23177. this._next();
  23178. }
  23179. /**
  23180. *清理指定资源地址缓存。
  23181. *@param url 资源地址。
  23182. */
  23183. __proto.clearRes=function(url){
  23184. Loader.clearRes(url);
  23185. }
  23186. /**
  23187. *销毁Texture使用的图片资源,保留texture壳,如果下次渲染的时候,发现texture使用的图片资源不存在,则会自动恢复
  23188. *相比clearRes,clearTextureRes只是清理texture里面使用的图片资源,并不销毁texture,再次使用到的时候会自动恢复图片资源
  23189. *而clearRes会彻底销毁texture,导致不能再使用;clearTextureRes能确保立即销毁图片资源,并且不用担心销毁错误,clearRes则采用引用计数方式销毁
  23190. *【注意】如果图片本身在自动合集里面(默认图片小于512*512),内存是不能被销毁的,此图片被大图合集管理器管理
  23191. *@param url 图集地址或者texture地址,比如 Loader.clearTextureRes("res/atlas/comp.atlas");Loader.clearTextureRes("hall/bg.jpg");
  23192. */
  23193. __proto.clearTextureRes=function(url){
  23194. Loader.clearTextureRes(url);
  23195. }
  23196. /**
  23197. *获取指定资源地址的资源。
  23198. *@param url 资源地址。
  23199. *@return 返回资源。
  23200. */
  23201. __proto.getRes=function(url){
  23202. return Loader.getRes(url);
  23203. }
  23204. /**
  23205. *缓存资源。
  23206. *@param url 资源地址。
  23207. *@param data 要缓存的内容。
  23208. */
  23209. __proto.cacheRes=function(url,data){
  23210. Loader.cacheRes(url,data);
  23211. }
  23212. /**
  23213. *设置资源分组。
  23214. *@param url 资源地址。
  23215. *@param group 分组名
  23216. */
  23217. __proto.setGroup=function(url,group){
  23218. Loader.setGroup(url,group);
  23219. }
  23220. /**
  23221. *根据分组清理资源。
  23222. *@param group 分组名
  23223. */
  23224. __proto.clearResByGroup=function(group){
  23225. Loader.clearResByGroup(group);
  23226. }
  23227. /**清理当前未完成的加载,所有未加载的内容全部停止加载。*/
  23228. __proto.clearUnLoaded=function(){
  23229. for (var i=0;i < this._maxPriority;i++){
  23230. var infos=this._resInfos[i];
  23231. for (var j=infos.length-1;j >-1;j--){
  23232. var info=infos[j];
  23233. if (info){
  23234. info.offAll();
  23235. this._infoPool.push(info);
  23236. }
  23237. }
  23238. infos.length=0;
  23239. }
  23240. this._loaderCount=0;
  23241. LoaderManager._resMap={};
  23242. }
  23243. /**
  23244. *根据地址集合清理掉未加载的内容
  23245. *@param urls 资源地址集合
  23246. */
  23247. __proto.cancelLoadByUrls=function(urls){
  23248. if (!urls)return;
  23249. for (var i=0,n=urls.length;i < n;i++){
  23250. this.cancelLoadByUrl(urls[i]);
  23251. }
  23252. }
  23253. /**
  23254. *根据地址清理掉未加载的内容
  23255. *@param url 资源地址
  23256. */
  23257. __proto.cancelLoadByUrl=function(url){
  23258. for (var i=0;i < this._maxPriority;i++){
  23259. var infos=this._resInfos[i];
  23260. for (var j=infos.length-1;j >-1;j--){
  23261. var info=infos[j];
  23262. if (info && info.url===url){
  23263. infos[j]=null;
  23264. info.offAll();
  23265. this._infoPool.push(info);
  23266. }
  23267. }
  23268. }
  23269. if (LoaderManager._resMap[url])delete LoaderManager._resMap[url];
  23270. }
  23271. /**
  23272. *@private
  23273. *加载数组里面的资源。
  23274. *@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}]*/
  23275. __proto._loadAssets=function(arr,complete,progress,type,priority,cache,group){
  23276. (priority===void 0)&& (priority=1);
  23277. (cache===void 0)&& (cache=true);
  23278. var itemCount=arr.length;
  23279. var loadedCount=0;
  23280. var totalSize=0;
  23281. var items=[];
  23282. var success=true;
  23283. for (var i=0;i < itemCount;i++){
  23284. var item=arr[i];
  23285. if ((typeof item=='string'))item={url:item,type:type,size:1,priority:priority};
  23286. if (!item.size)item.size=1;
  23287. item.progress=0;
  23288. totalSize+=item.size;
  23289. items.push(item);
  23290. var progressHandler=progress ? Handler.create(null,loadProgress,[item],false):null;
  23291. var completeHandler=(complete || progress)? Handler.create(null,loadComplete,[item]):null;
  23292. this.load(item.url,completeHandler,progressHandler,item.type,item.priority || 1,cache,item.group || group,false,item.useWorkerLoader);
  23293. }
  23294. function loadComplete (item,content){
  23295. loadedCount++;
  23296. item.progress=1;
  23297. if (!content)success=false;
  23298. if (loadedCount===itemCount && complete){
  23299. complete.runWith(success);
  23300. }
  23301. }
  23302. function loadProgress (item,value){
  23303. if (progress !=null){
  23304. item.progress=value;
  23305. var num=0;
  23306. for (var j=0;j < items.length;j++){
  23307. var item1=items[j];
  23308. num+=item1.size *item1.progress;
  23309. };
  23310. var v=num / totalSize;
  23311. progress.runWith(v);
  23312. }
  23313. }
  23314. return this;
  23315. }
  23316. //TODO:TESTs
  23317. __proto.decodeBitmaps=function(urls){
  23318. var i=0,len=urls.length;
  23319. var ctx;
  23320. ctx=Render._context;
  23321. for (i=0;i < len;i++){
  23322. var atlas;
  23323. atlas=Loader.getAtlas(urls[i]);
  23324. if (atlas){
  23325. this._decodeTexture(atlas[0],ctx);
  23326. }else {
  23327. var tex;
  23328. tex=this.getRes(urls[i]);
  23329. if (tex && (tex instanceof laya.resource.Texture )){
  23330. this._decodeTexture(tex,ctx);
  23331. }
  23332. }
  23333. }
  23334. }
  23335. __proto._decodeTexture=function(tex,ctx){
  23336. var bitmap=tex.bitmap;
  23337. if (!tex || !bitmap)return;
  23338. var tImg=bitmap.source || bitmap.image;
  23339. if (!tImg)return;
  23340. if (Laya.__typeof(tImg,Browser.window.HTMLImageElement)){
  23341. ctx.drawImage(tImg,0,0,1,1);
  23342. var info=ctx.getImageData(0,0,1,1);
  23343. }
  23344. }
  23345. LoaderManager.cacheRes=function(url,data){
  23346. Loader.cacheRes(url,data);
  23347. }
  23348. LoaderManager._resMap={};
  23349. __static(LoaderManager,
  23350. ['createMap',function(){return this.createMap={atlas:[null,/*laya.net.Loader.ATLAS*/"atlas"]};}
  23351. ]);
  23352. LoaderManager.__init$=function(){
  23353. //class ResInfo extends laya.events.EventDispatcher
  23354. ResInfo=(function(_super){
  23355. function ResInfo(){
  23356. this.url=null;
  23357. this.type=null;
  23358. this.cache=false;
  23359. this.group=null;
  23360. this.ignoreCache=false;
  23361. this.useWorkerLoader=false;
  23362. this.originalUrl=null;
  23363. this.createCache=false;
  23364. this.createConstructParams=null;
  23365. this.createPropertyParams=null;
  23366. ResInfo.__super.call(this);
  23367. }
  23368. __class(ResInfo,'',_super);
  23369. return ResInfo;
  23370. })(EventDispatcher)
  23371. }
  23372. return LoaderManager;
  23373. })(EventDispatcher)
  23374. /**
  23375. *与MeshQuadTexture基本相同。不过index不是固定的
  23376. */
  23377. //class laya.webgl.utils.MeshTexture extends laya.webgl.utils.Mesh2D
  23378. var MeshTexture=(function(_super){
  23379. function MeshTexture(){
  23380. MeshTexture.__super.call(this,/*CLASS CONST:laya.webgl.utils.MeshTexture.const_stride*/24,4,4);
  23381. this.canReuse=true;
  23382. this.setAttributes(laya.webgl.utils.MeshTexture._fixattriInfo);
  23383. }
  23384. __class(MeshTexture,'laya.webgl.utils.MeshTexture',_super);
  23385. var __proto=MeshTexture.prototype;
  23386. __proto.addData=function(vertices,uvs,idx,matrix,rgba){
  23387. var vb=this._vb;
  23388. var ib=this._ib;
  23389. var vertsz=vertices.length >>1;
  23390. var startpos=vb.needSize(vertsz *24);
  23391. var f32pos=startpos >> 2;
  23392. var vbdata=vb._floatArray32 || vb.getFloat32Array();
  23393. var vbu32Arr=vb._uint32Array;
  23394. var ci=0;
  23395. var m00=matrix.a;
  23396. var m01=matrix.b;
  23397. var m10=matrix.c;
  23398. var m11=matrix.d;
  23399. var tx=matrix.tx;
  23400. var ty=matrix.ty;
  23401. var i=0;
  23402. for (i=0;i < vertsz;i++){
  23403. var x=vertices[ci],y=vertices[ci+1];
  23404. vbdata[f32pos]=x *m00+y *m10+tx;
  23405. vbdata[f32pos+1]=x *m01+y *m11+ty;
  23406. vbdata[f32pos+2]=uvs[ci];
  23407. vbdata[f32pos+3]=uvs[ci+1];
  23408. vbu32Arr[f32pos+4]=rgba;
  23409. vbu32Arr[f32pos+5]=0xff;
  23410. f32pos+=6;
  23411. ci+=2;
  23412. }
  23413. vb.setNeedUpload();
  23414. var vertN=this.vertNum;
  23415. var sz=idx.length;
  23416. var stib=ib.needSize(idx.byteLength);
  23417. var cidx=ib.getUint16Array();
  23418. var stibid=stib >> 1;
  23419. if (vertN > 0){
  23420. var end=stibid+sz;
  23421. var si=0;
  23422. for (i=stibid;i < end;i++,si++){
  23423. cidx[i]=idx[si]+vertN;
  23424. }
  23425. }else {
  23426. cidx.set(idx,stibid);
  23427. }
  23428. ib.setNeedUpload();
  23429. this.vertNum+=vertsz;
  23430. this.indexNum+=idx.length;
  23431. }
  23432. /**
  23433. *把本对象放到回收池中,以便getMesh能用。
  23434. */
  23435. __proto.releaseMesh=function(){
  23436. this._vb.setByteLength(0);
  23437. this._ib.setByteLength(0);
  23438. this.vertNum=0;
  23439. this.indexNum=0;
  23440. laya.webgl.utils.MeshTexture._POOL.push(this);
  23441. }
  23442. __proto.destroy=function(){
  23443. this._ib.destroy();
  23444. this._vb.destroy();
  23445. this._ib.disposeResource();
  23446. this._vb.deleteBuffer();
  23447. }
  23448. MeshTexture.getAMesh=function(mainctx){
  23449. var ret;
  23450. if (laya.webgl.utils.MeshTexture._POOL.length){
  23451. ret=laya.webgl.utils.MeshTexture._POOL.pop();
  23452. }
  23453. else ret=new MeshTexture();
  23454. mainctx && ret._vb._resizeBuffer(64 *1024 *24,false);
  23455. return ret;
  23456. }
  23457. MeshTexture.const_stride=24;
  23458. MeshTexture._POOL=[];
  23459. __static(MeshTexture,
  23460. ['_fixattriInfo',function(){return this._fixattriInfo=[
  23461. /*laya.webgl.WebGLContext.FLOAT*/0x1406,4,0,
  23462. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,16,
  23463. /*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,4,20];}
  23464. ]);
  23465. return MeshTexture;
  23466. })(Mesh2D)
  23467. /**
  23468. *@private
  23469. *场景资源加载器
  23470. */
  23471. //class laya.net.SceneLoader extends laya.events.EventDispatcher
  23472. var SceneLoader=(function(_super){
  23473. function SceneLoader(){
  23474. this.totalCount=0;
  23475. this._completeHandler=null;
  23476. this._toLoadList=null;
  23477. this._isLoading=false;
  23478. this._curUrl=null;
  23479. SceneLoader.__super.call(this);
  23480. this._completeHandler=new Handler(this,this.onOneLoadComplete);
  23481. this.reset();
  23482. }
  23483. __class(SceneLoader,'laya.net.SceneLoader',_super);
  23484. var __proto=SceneLoader.prototype;
  23485. __proto.reset=function(){
  23486. this._toLoadList=[];
  23487. this._isLoading=false;
  23488. this.totalCount=0;
  23489. }
  23490. __proto.load=function(url,is3D,ifCheck){
  23491. (is3D===void 0)&& (is3D=false);
  23492. (ifCheck===void 0)&& (ifCheck=true);
  23493. if ((url instanceof Array)){
  23494. var i=0,len=0;
  23495. len=url.length;
  23496. for (i=0;i < len;i++){
  23497. this._addToLoadList(url[i],is3D);
  23498. }
  23499. }else {
  23500. this._addToLoadList(url,is3D);
  23501. }
  23502. if(ifCheck)
  23503. this._checkNext();
  23504. }
  23505. __proto._addToLoadList=function(url,is3D){
  23506. (is3D===void 0)&& (is3D=false);
  23507. if (this._toLoadList.indexOf(url)>=0)return;
  23508. if (Loader.getRes(url))return;
  23509. if (is3D){
  23510. this._toLoadList.push({url:url});
  23511. }else
  23512. this._toLoadList.push(url);
  23513. this.totalCount++;
  23514. }
  23515. __proto._checkNext=function(){
  23516. if (!this._isLoading){
  23517. if (this._toLoadList.length==0){
  23518. this.event(/*laya.events.Event.COMPLETE*/"complete");
  23519. return;
  23520. };
  23521. var tItem;
  23522. tItem=this._toLoadList.pop();
  23523. if ((typeof tItem=='string')){
  23524. this.loadOne(tItem);
  23525. }else{
  23526. this.loadOne(tItem.url,true);
  23527. }
  23528. }
  23529. }
  23530. __proto.loadOne=function(url,is3D){
  23531. (is3D===void 0)&& (is3D=false);
  23532. this._curUrl=url;
  23533. var type=Utils.getFileExtension(this._curUrl);
  23534. if (is3D){
  23535. Laya.loader.create(url,this._completeHandler);
  23536. }else
  23537. if (SceneLoader.LoadableExtensions[type]){
  23538. Laya.loader.load(url,this._completeHandler,null,SceneLoader.LoadableExtensions[type]);
  23539. }else if (url !=AtlasInfoManager.getFileLoadPath(url)|| SceneLoader.No3dLoadTypes[type] || !LoaderManager.createMap[type]){
  23540. Laya.loader.load(url,this._completeHandler);
  23541. }else {
  23542. Laya.loader.create(url,this._completeHandler);
  23543. }
  23544. }
  23545. __proto.onOneLoadComplete=function(){
  23546. this._isLoading=false;
  23547. if (!Loader.getRes(this._curUrl)){
  23548. console.log("Fail to load:",this._curUrl);
  23549. };
  23550. var type=Utils.getFileExtension(this._curUrl);
  23551. if (SceneLoader.LoadableExtensions[type]){
  23552. var dataO;
  23553. dataO=Loader.getRes(this._curUrl);
  23554. if (dataO&&((dataO instanceof laya.components.Prefab ))){
  23555. dataO=dataO.json;
  23556. }
  23557. if (dataO){
  23558. if (dataO.loadList){
  23559. this.load(dataO.loadList,false,false);
  23560. }
  23561. if (dataO.loadList3D){
  23562. this.load(dataO.loadList3D,true,false);
  23563. }
  23564. }
  23565. }
  23566. if (type=="sk"){
  23567. this.load(this._curUrl.replace(".sk",".png"),false,false);
  23568. }
  23569. this.event(/*laya.events.Event.PROGRESS*/"progress",this.getProgress());
  23570. this._checkNext();
  23571. }
  23572. __proto.getProgress=function(){
  23573. return this.loadedCount / this.totalCount;
  23574. }
  23575. __getset(0,__proto,'loadedCount',function(){
  23576. return this.totalCount-this.leftCount;
  23577. });
  23578. __getset(0,__proto,'leftCount',function(){
  23579. if (this._isLoading)return this._toLoadList.length+1;
  23580. return this._toLoadList.length;
  23581. });
  23582. __static(SceneLoader,
  23583. ['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};}
  23584. ]);
  23585. return SceneLoader;
  23586. })(EventDispatcher)
  23587. /**
  23588. *文本的样式类
  23589. */
  23590. //class laya.display.css.TextStyle extends laya.display.css.SpriteStyle
  23591. var TextStyle=(function(_super){
  23592. function TextStyle(){
  23593. /**
  23594. *表示使用此文本格式的文本是否为斜体。
  23595. *@default false
  23596. */
  23597. this.italic=false;
  23598. /**
  23599. *<p>表示使用此文本格式的文本段落的水平对齐方式。</p>
  23600. *@default "left"
  23601. */
  23602. //this.align=null;
  23603. /**
  23604. *<p>表示使用此文本格式的文本字段是否自动换行。</p>
  23605. *如果 wordWrap 的值为 true,则该文本字段自动换行;如果值为 false,则该文本字段不自动换行。
  23606. *@default false。
  23607. */
  23608. //this.wordWrap=false;
  23609. /**
  23610. *<p>垂直行间距(以像素为单位)</p>
  23611. */
  23612. //this.leading=NaN;
  23613. /**
  23614. *<p>默认边距信息</p>
  23615. *<p>[左边距,上边距,右边距,下边距](边距以像素为单位)</p>
  23616. */
  23617. //this.padding=null;
  23618. /**
  23619. *文本背景颜色,以字符串表示。
  23620. */
  23621. //this.bgColor=null;
  23622. /**
  23623. *文本边框背景颜色,以字符串表示。
  23624. */
  23625. //this.borderColor=null;
  23626. /**
  23627. *<p>指定文本字段是否是密码文本字段。</p>
  23628. *如果此属性的值为 true,则文本字段被视为密码文本字段,并使用星号而不是实际字符来隐藏输入的字符。如果为 false,则不会将文本字段视为密码文本字段。
  23629. */
  23630. //this.asPassword=false;
  23631. /**
  23632. *<p>描边宽度(以像素为单位)。</p>
  23633. *默认值0,表示不描边。
  23634. *@default 0
  23635. */
  23636. //this.stroke=NaN;
  23637. /**
  23638. *<p>描边颜色,以字符串表示。</p>
  23639. *@default "#000000";
  23640. */
  23641. //this.strokeColor=null;
  23642. /**是否为粗体*/
  23643. //this.bold=false;
  23644. /**是否显示下划线*/
  23645. //this.underline=false;
  23646. /**下划线颜色*/
  23647. //this.underlineColor=null;
  23648. /**当前使用的位置字体。*/
  23649. //this.currBitmapFont=null;
  23650. TextStyle.__super.call(this);
  23651. }
  23652. __class(TextStyle,'laya.display.css.TextStyle',_super);
  23653. var __proto=TextStyle.prototype;
  23654. __proto.reset=function(){
  23655. _super.prototype.reset.call(this);
  23656. this.italic=false;
  23657. this.align="left";
  23658. this.wordWrap=false;
  23659. this.leading=0;
  23660. this.padding=[0,0,0,0];
  23661. this.bgColor=null;
  23662. this.borderColor=null;
  23663. this.asPassword=false;
  23664. this.stroke=0;
  23665. this.strokeColor="#000000";
  23666. this.bold=false;
  23667. this.underline=false;
  23668. this.underlineColor=null;
  23669. this.currBitmapFont=null;
  23670. return this;
  23671. }
  23672. __proto.recover=function(){
  23673. if (this===TextStyle.EMPTY)
  23674. return;
  23675. Pool.recover("TextStyle",this.reset());
  23676. }
  23677. /**@inheritDoc */
  23678. __proto.render=function(sprite,context,x,y){
  23679. (this.bgColor || this.borderColor)&& context.drawRect(x,y,sprite.width,sprite.height,this.bgColor,this.borderColor,1);
  23680. }
  23681. TextStyle.create=function(){
  23682. return Pool.getItemByClass("TextStyle",TextStyle);
  23683. }
  23684. TextStyle.EMPTY=new TextStyle();
  23685. return TextStyle;
  23686. })(SpriteStyle)
  23687. /**
  23688. *@private
  23689. *Worker Image加载器
  23690. */
  23691. //class laya.net.WorkerLoader extends laya.events.EventDispatcher
  23692. var WorkerLoader=(function(_super){
  23693. function WorkerLoader(){
  23694. /**使用的Worker对象。*/
  23695. this.worker=null;
  23696. /**@private */
  23697. this._useWorkerLoader=false;
  23698. WorkerLoader.__super.call(this);
  23699. var _$this=this;
  23700. this.worker=new Worker(WorkerLoader.workerPath);
  23701. this.worker.onmessage=function (evt){
  23702. _$this.workerMessage(evt.data);
  23703. }
  23704. }
  23705. __class(WorkerLoader,'laya.net.WorkerLoader',_super);
  23706. var __proto=WorkerLoader.prototype;
  23707. /**
  23708. *@private
  23709. */
  23710. __proto.workerMessage=function(data){
  23711. if (data){
  23712. switch (data.type){
  23713. case "Image":
  23714. this.imageLoaded(data);
  23715. break ;
  23716. case "Disable":
  23717. WorkerLoader.enable=false;
  23718. break ;
  23719. }
  23720. }
  23721. }
  23722. /**
  23723. *@private
  23724. */
  23725. __proto.imageLoaded=function(data){
  23726. if (!data.dataType || data.dataType !="imageBitmap"){
  23727. this.event(data.url,null);
  23728. return;
  23729. };
  23730. var canvas=new HTMLCanvas(true);
  23731. var ctx=canvas.source.getContext("2d");
  23732. switch (data.dataType){
  23733. case "imageBitmap":;
  23734. var imageData=data.imageBitmap;
  23735. canvas.size(imageData.width,imageData.height);
  23736. ctx.drawImage(imageData,0,0);
  23737. break ;
  23738. }
  23739. console.log("load:",data.url);
  23740. canvas._setGPUMemory(0);
  23741. var tex=new Texture2D();
  23742. tex.loadImageSource(canvas.source);
  23743. this.event(data.url,tex);
  23744. }
  23745. /**
  23746. *加载图片
  23747. *@param url 图片地址
  23748. */
  23749. __proto.loadImage=function(url){
  23750. this.worker.postMessage(url);
  23751. }
  23752. /**
  23753. *@private
  23754. *加载图片资源。
  23755. *@param url 资源地址。
  23756. */
  23757. __proto._loadImage=function(url){
  23758. var _this=this;
  23759. if (!this._useWorkerLoader || !WorkerLoader._enable){
  23760. WorkerLoader._preLoadFun.call(_this,url);
  23761. return;
  23762. }
  23763. url=URL.formatURL(url);
  23764. function clear (){
  23765. laya.net.WorkerLoader.I.off(url,_this,onload);
  23766. };
  23767. var onload=function (image){
  23768. clear();
  23769. if (image){
  23770. _this["onLoaded"](image);
  23771. }else {
  23772. WorkerLoader._preLoadFun.call(_this,url);
  23773. }
  23774. };
  23775. laya.net.WorkerLoader.I.on(url,_this,onload);
  23776. laya.net.WorkerLoader.I.loadImage(url);
  23777. }
  23778. /**
  23779. *是否启用。
  23780. */
  23781. __getset(1,WorkerLoader,'enable',function(){
  23782. return WorkerLoader._enable;
  23783. },function(value){
  23784. if (WorkerLoader._enable !=value){
  23785. WorkerLoader._enable=value;
  23786. if (value && WorkerLoader._preLoadFun==null)WorkerLoader._enable=WorkerLoader.__init__();
  23787. }
  23788. });
  23789. WorkerLoader.__init__=function(){
  23790. if (WorkerLoader._preLoadFun !=null)return false;
  23791. if (!Worker)return false;
  23792. WorkerLoader._preLoadFun=Loader["prototype"]["_loadImage"];
  23793. Loader["prototype"]["_loadImage"]=WorkerLoader["prototype"]["_loadImage"];
  23794. if (!WorkerLoader.I)WorkerLoader.I=new WorkerLoader();
  23795. return true;
  23796. }
  23797. WorkerLoader.workerSupported=function(){
  23798. return Worker ? true :false;
  23799. }
  23800. WorkerLoader.enableWorkerLoader=function(){
  23801. if (!WorkerLoader._tryEnabled){
  23802. WorkerLoader.enable=true;
  23803. WorkerLoader._tryEnabled=true;
  23804. }
  23805. }
  23806. WorkerLoader.I=null;
  23807. WorkerLoader.workerPath="libs/workerloader.js";
  23808. WorkerLoader._preLoadFun=null;
  23809. WorkerLoader._enable=false;
  23810. WorkerLoader._tryEnabled=false;
  23811. return WorkerLoader;
  23812. })(EventDispatcher)
  23813. /**
  23814. *...
  23815. *@author ...
  23816. */
  23817. //class laya.webgl.BufferState2D extends laya.webgl.BufferStateBase
  23818. var BufferState2D=(function(_super){
  23819. function BufferState2D(){
  23820. BufferState2D.__super.call(this);
  23821. }
  23822. __class(BufferState2D,'laya.webgl.BufferState2D',_super);
  23823. return BufferState2D;
  23824. })(BufferStateBase)
  23825. //class laya.webgl.shader.d2.value.PrimitiveSV extends laya.webgl.shader.d2.value.Value2D
  23826. var PrimitiveSV=(function(_super){
  23827. function PrimitiveSV(args){
  23828. PrimitiveSV.__super.call(this,/*laya.webgl.shader.d2.ShaderDefines2D.PRIMITIVE*/0x04,0);
  23829. this._attribLocation=['position',0,'attribColor',1];
  23830. }
  23831. __class(PrimitiveSV,'laya.webgl.shader.d2.value.PrimitiveSV',_super);
  23832. return PrimitiveSV;
  23833. })(Value2D)
  23834. //class laya.webgl.shader.d2.skinAnishader.SkinSV extends laya.webgl.shader.d2.value.Value2D
  23835. var SkinSV=(function(_super){
  23836. function SkinSV(type){
  23837. this.texcoord=null;
  23838. this.position=null;
  23839. this.offsetX=300;
  23840. this.offsetY=0;
  23841. SkinSV.__super.call(this,/*laya.webgl.shader.d2.ShaderDefines2D.SKINMESH*/0x200,0);
  23842. var _vlen=8 *CONST3D2D.BYTES_PE;
  23843. this.position=[2,/*laya.webgl.WebGLContext.FLOAT*/0x1406,false,_vlen,0];
  23844. this.texcoord=[2,/*laya.webgl.WebGLContext.FLOAT*/0x1406,false,_vlen,2 *CONST3D2D.BYTES_PE];
  23845. this.color=[4,/*laya.webgl.WebGLContext.FLOAT*/0x1406,false,_vlen,4 *CONST3D2D.BYTES_PE];
  23846. }
  23847. __class(SkinSV,'laya.webgl.shader.d2.skinAnishader.SkinSV',_super);
  23848. return SkinSV;
  23849. })(Value2D)
  23850. //class laya.webgl.text.CharRender_Canvas extends laya.webgl.text.ICharRender
  23851. var CharRender_Canvas=(function(_super){
  23852. function CharRender_Canvas(maxw,maxh,scalefont,useImageData,showdbg){
  23853. // HTMLCanvasElement;
  23854. this.ctx=null;
  23855. this.lastScaleX=1.0;
  23856. this.lastScaleY=1.0;
  23857. this.needResetScale=false;
  23858. this.maxTexW=0;
  23859. this.maxTexH=0;
  23860. this.scaleFontSize=true;
  23861. this.showDbgInfo=false;
  23862. this.supportImageData=true;
  23863. CharRender_Canvas.__super.call(this);
  23864. (scalefont===void 0)&& (scalefont=true);
  23865. (useImageData===void 0)&& (useImageData=true);
  23866. (showdbg===void 0)&& (showdbg=false);
  23867. this.maxTexW=maxw;
  23868. this.maxTexH=maxh;
  23869. this.scaleFontSize=scalefont;
  23870. this.supportImageData=useImageData;
  23871. this.showDbgInfo=showdbg;
  23872. if (!CharRender_Canvas.canvas){
  23873. CharRender_Canvas.canvas=window.document.createElement('canvas');
  23874. CharRender_Canvas.canvas.width=1024;
  23875. CharRender_Canvas.canvas.height=512;
  23876. CharRender_Canvas.canvas.style.left="-10000px";
  23877. CharRender_Canvas.canvas.style.position="absolute";
  23878. /*__JS__ */document.body.appendChild(CharRender_Canvas.canvas);;
  23879. this.ctx=CharRender_Canvas.canvas.getContext('2d');
  23880. }
  23881. }
  23882. __class(CharRender_Canvas,'laya.webgl.text.CharRender_Canvas',_super);
  23883. var __proto=CharRender_Canvas.prototype;
  23884. __proto.getWidth=function(font,str){
  23885. if (!this.ctx)return 0;
  23886. if(this.ctx._lastFont!=font){
  23887. this.ctx.font=font;
  23888. this.ctx._lastFont=font;
  23889. }
  23890. return this.ctx.measureText(str).width;
  23891. }
  23892. __proto.scale=function(sx,sy){
  23893. if (!this.supportImageData){
  23894. this.lastScaleX=sx;
  23895. this.lastScaleY=sy;
  23896. return;
  23897. }
  23898. if (this.lastScaleX !=sx || this.lastScaleY !=sy){
  23899. this.ctx.setTransform(sx,0,0,sy,0,0);
  23900. this.lastScaleX=sx;
  23901. this.lastScaleY=sy;
  23902. }
  23903. }
  23904. /**
  23905. *TODO stroke
  23906. *@param char
  23907. *@param font
  23908. *@param cri 修改里面的width。
  23909. *@return
  23910. */
  23911. __proto.getCharBmp=function(char,font,lineWidth,colStr,strokeColStr,cri,margin_left,margin_top,margin_right,margin_bottom,rect){
  23912. if (!this.supportImageData)
  23913. return this.getCharCanvas(char,font,lineWidth,colStr,strokeColStr,cri,margin_left,margin_top,margin_right,margin_bottom);
  23914. var ctx=this.ctx;
  23915. if (ctx.font !=font){
  23916. ctx.font=font;
  23917. ctx._lastFont=font;
  23918. }
  23919. cri.width=ctx.measureText(char).width;
  23920. var w=cri.width *this.lastScaleX;
  23921. var h=cri.height*this.lastScaleY;
  23922. w+=(margin_left+margin_right)*this.lastScaleX;
  23923. h+=(margin_top+margin_bottom)*this.lastScaleY;
  23924. w=Math.ceil(w);
  23925. h=Math.ceil(h);
  23926. w=Math.min(w,laya.webgl.text.CharRender_Canvas.canvas.width);
  23927. h=Math.min(h,laya.webgl.text.CharRender_Canvas.canvas.height);
  23928. var clearW=w+lineWidth *2+1;
  23929. var clearH=h+lineWidth *2+1;
  23930. if (rect){
  23931. clearW=Math.max(clearW,rect[0]+rect[2]+1);
  23932. clearH=Math.max(clearH,rect[1]+rect[3]+1);
  23933. }
  23934. ctx.clearRect(0,0,clearW,clearH);
  23935. ctx.save();
  23936. ctx.textBaseline="top";
  23937. if (lineWidth > 0){
  23938. ctx.strokeStyle=strokeColStr;
  23939. ctx.lineWidth=lineWidth;
  23940. ctx.strokeText(char,margin_left,margin_top);
  23941. }
  23942. ctx.fillStyle=colStr;
  23943. ctx.fillText(char,margin_left,margin_top);
  23944. if (this.showDbgInfo){
  23945. ctx.strokeStyle='#ff0000';
  23946. ctx.strokeRect(0,0,w,h);
  23947. ctx.strokeStyle='#00ff00';
  23948. ctx.strokeRect(margin_left,margin_top,cri.width,cri.height);
  23949. }
  23950. if (rect){
  23951. if (rect[2]==-1)rect[2]=Math.ceil((cri.width+lineWidth*2)*this.lastScaleX);
  23952. };
  23953. var imgdt=rect?(ctx.getImageData(rect[0],rect[1],rect[2],rect[3])):(ctx.getImageData(0,0,w,h));
  23954. ctx.restore();
  23955. cri.bmpWidth=imgdt.width;
  23956. cri.bmpHeight=imgdt.height;
  23957. return imgdt;
  23958. }
  23959. __proto.getCharCanvas=function(char,font,lineWidth,colStr,strokeColStr,cri,margin_left,margin_top,margin_right,margin_bottom){
  23960. var ctx=this.ctx;
  23961. if (ctx.font !=font){
  23962. ctx.font=font;
  23963. ctx._lastFont=font;
  23964. }
  23965. cri.width=ctx.measureText(char).width;
  23966. var w=cri.width *this.lastScaleX;
  23967. var h=cri.height*this.lastScaleY;
  23968. w+=(margin_left+margin_right)*this.lastScaleX;
  23969. h+=((margin_top+margin_bottom)*this.lastScaleY+1);
  23970. w=Math.min(w,this.maxTexW);
  23971. h=Math.min(h,this.maxTexH);
  23972. CharRender_Canvas.canvas.width=Math.min(w+1,this.maxTexW);
  23973. CharRender_Canvas.canvas.height=Math.min(h+1,this.maxTexH);
  23974. ctx.font=font;
  23975. ctx.clearRect(0,0,w+1+lineWidth,h+1+lineWidth);
  23976. ctx.setTransform(1,0,0,1,0,0);
  23977. ctx.save();
  23978. if (this.scaleFontSize){
  23979. ctx.scale(this.lastScaleX,this.lastScaleY);
  23980. }
  23981. ctx.translate(margin_left,margin_top);
  23982. ctx.textAlign="left";
  23983. ctx.textBaseline="top";
  23984. if (lineWidth > 0){
  23985. ctx.strokeStyle=strokeColStr;
  23986. ctx.fillStyle=colStr;
  23987. ctx.lineWidth=lineWidth;
  23988. if (ctx.fillAndStrokeText){
  23989. ctx.fillAndStrokeText(char,0,0);
  23990. }else{
  23991. ctx.strokeText(char,0,0);
  23992. ctx.fillText(char,0,0);
  23993. }
  23994. }else {
  23995. ctx.fillStyle=colStr;
  23996. ctx.fillText(char,0,0);
  23997. }
  23998. if (this.showDbgInfo){
  23999. ctx.strokeStyle='#ff0000';
  24000. ctx.strokeRect(0,0,w,h);
  24001. ctx.strokeStyle='#00ff00';
  24002. ctx.strokeRect(0,0,cri.width,cri.height);
  24003. }
  24004. ctx.restore();
  24005. cri.bmpWidth=CharRender_Canvas.canvas.width;
  24006. cri.bmpHeight=CharRender_Canvas.canvas.height;
  24007. return CharRender_Canvas.canvas;
  24008. }
  24009. __getset(0,__proto,'canvasWidth',function(){
  24010. return CharRender_Canvas.canvas.width;
  24011. },function(w){
  24012. if (CharRender_Canvas.canvas.width==w)
  24013. return;
  24014. CharRender_Canvas.canvas.width=w;
  24015. if (w > 2048){
  24016. console.warn("画文字设置的宽度太大,超过2048了");
  24017. }
  24018. this.ctx.setTransform(1,0,0,1,0,0);
  24019. this.ctx.scale(this.lastScaleX,this.lastScaleY);
  24020. });
  24021. CharRender_Canvas.canvas=null;
  24022. return CharRender_Canvas;
  24023. })(ICharRender)
  24024. //class laya.webgl.text.CharRender_Native extends laya.webgl.text.ICharRender
  24025. var CharRender_Native=(function(_super){
  24026. function CharRender_Native(){
  24027. this.lastFont='';
  24028. CharRender_Native.__super.call(this);
  24029. }
  24030. __class(CharRender_Native,'laya.webgl.text.CharRender_Native',_super);
  24031. var __proto=CharRender_Native.prototype;
  24032. //TODO:coverage
  24033. __proto.getWidth=function(font,str){
  24034. if (!window.conchTextCanvas)return 0;
  24035. window.conchTextCanvas.font=font;
  24036. this.lastFont=font;
  24037. return window.conchTextCanvas.measureText(str).width;
  24038. }
  24039. __proto.scale=function(sx,sy){}
  24040. //TODO:coverage
  24041. __proto.getCharBmp=function(char,font,lineWidth,colStr,strokeColStr,size,margin_left,margin_top,margin_right,margin_bottom,rect){
  24042. if (!window.conchTextCanvas)return null;
  24043. window.conchTextCanvas.font=font;
  24044. this.lastFont=font;
  24045. var w=size.width=window.conchTextCanvas.measureText(char).width;
  24046. var h=size.height;
  24047. w+=(margin_left+margin_right);
  24048. h+=(margin_top+margin_bottom);
  24049. var c1=ColorUtils.create(strokeColStr);
  24050. var nStrokeColor=c1.numColor;
  24051. var c2=ColorUtils.create(colStr);
  24052. var nTextColor=c2.numColor;
  24053. var textInfo=window.conchTextCanvas.getTextBitmapData(char,nTextColor,lineWidth>2?2:lineWidth,nStrokeColor);
  24054. size.bmpWidth=textInfo.width;
  24055. size.bmpHeight=textInfo.height;
  24056. return textInfo;
  24057. }
  24058. return CharRender_Native;
  24059. })(ICharRender)
  24060. /**
  24061. *<p> <code>Sprite</code> 是基本的显示图形的显示列表节点。 <code>Sprite</code> 默认没有宽高,默认不接受鼠标事件。通过 <code>graphics</code> 可以绘制图片或者矢量图,支持旋转,缩放,位移等操作。<code>Sprite</code>同时也是容器类,可用来添加多个子节点。</p>
  24062. *<p>注意: <code>Sprite</code> 默认没有宽高,可以通过<code>getBounds</code>函数获取;也可手动设置宽高;还可以设置<code>autoSize=true</code>,然后再获取宽高。<code>Sprite</code>的宽高一般用于进行碰撞检测和排版,并不影响显示图像大小,如果需要更改显示图像大小,请使用 <code>scaleX</code> , <code>scaleY</code> , <code>scale</code>。</p>
  24063. *<p> <code>Sprite</code> 默认不接受鼠标事件,即<code>mouseEnabled=false</code>,但是只要对其监听任意鼠标事件,会自动打开自己以及所有父对象的<code>mouseEnabled=true</code>。所以一般也无需手动设置<code>mouseEnabled</code>。</p>
  24064. *<p>LayaAir引擎API设计精简巧妙。核心显示类只有一个<code>Sprite</code>。<code>Sprite</code>针对不同的情况做了渲染优化,所以保证一个类实现丰富功能的同时,又达到高性能。</p>
  24065. *
  24066. *@example <caption>创建了一个 <code>Sprite</code> 实例。</caption>
  24067. *package
  24068. *{
  24069. *import laya.display.Sprite;
  24070. *import laya.events.Event;
  24071. *
  24072. *public class Sprite_Example
  24073. *{
  24074. *private var sprite:Sprite;
  24075. *private var shape:Sprite
  24076. *public function Sprite_Example()
  24077. *{
  24078. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  24079. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  24080. *onInit();
  24081. *}
  24082. *private function onInit():void
  24083. *{
  24084. *sprite=new Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24085. *sprite.loadImage("resource/ui/bg.png");//加载并显示图片。
  24086. *sprite.x=200;//设置 sprite 对象相对于父容器的水平方向坐标值。
  24087. *sprite.y=200;//设置 sprite 对象相对于父容器的垂直方向坐标值。
  24088. *sprite.pivotX=0;//设置 sprite 对象的水平方法轴心点坐标。
  24089. *sprite.pivotY=0;//设置 sprite 对象的垂直方法轴心点坐标。
  24090. *Laya.stage.addChild(sprite);//将此 sprite 对象添加到显示列表。
  24091. *sprite.on(Event.CLICK,this,onClickSprite);//给 sprite 对象添加点击事件侦听。
  24092. *shape=new Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24093. *shape.graphics.drawRect(0,0,100,100,"#ccff00","#ff0000",2);//绘制一个有边框的填充矩形。
  24094. *shape.x=400;//设置 shape 对象相对于父容器的水平方向坐标值。
  24095. *shape.y=200;//设置 shape 对象相对于父容器的垂直方向坐标值。
  24096. *shape.width=100;//设置 shape 对象的宽度。
  24097. *shape.height=100;//设置 shape 对象的高度。
  24098. *shape.pivotX=50;//设置 shape 对象的水平方法轴心点坐标。
  24099. *shape.pivotY=50;//设置 shape 对象的垂直方法轴心点坐标。
  24100. *Laya.stage.addChild(shape);//将此 shape 对象添加到显示列表。
  24101. *shape.on(Event.CLICK,this,onClickShape);//给 shape 对象添加点击事件侦听。
  24102. *}
  24103. *private function onClickSprite():void
  24104. *{
  24105. *trace("点击 sprite 对象。");
  24106. *sprite.rotation+=5;//旋转 sprite 对象。
  24107. *}
  24108. *private function onClickShape():void
  24109. *{
  24110. *trace("点击 shape 对象。");
  24111. *shape.rotation+=5;//旋转 shape 对象。
  24112. *}
  24113. *}
  24114. *}
  24115. *
  24116. *@example
  24117. *var sprite;
  24118. *var shape;
  24119. *Sprite_Example();
  24120. *function Sprite_Example()
  24121. *{
  24122. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  24123. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  24124. *onInit();
  24125. *}
  24126. *function onInit()
  24127. *{
  24128. *sprite=new laya.display.Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24129. *sprite.loadImage("resource/ui/bg.png");//加载并显示图片。
  24130. *sprite.x=200;//设置 sprite 对象相对于父容器的水平方向坐标值。
  24131. *sprite.y=200;//设置 sprite 对象相对于父容器的垂直方向坐标值。
  24132. *sprite.pivotX=0;//设置 sprite 对象的水平方法轴心点坐标。
  24133. *sprite.pivotY=0;//设置 sprite 对象的垂直方法轴心点坐标。
  24134. *Laya.stage.addChild(sprite);//将此 sprite 对象添加到显示列表。
  24135. *sprite.on(Event.CLICK,this,onClickSprite);//给 sprite 对象添加点击事件侦听。
  24136. *shape=new laya.display.Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24137. *shape.graphics.drawRect(0,0,100,100,"#ccff00","#ff0000",2);//绘制一个有边框的填充矩形。
  24138. *shape.x=400;//设置 shape 对象相对于父容器的水平方向坐标值。
  24139. *shape.y=200;//设置 shape 对象相对于父容器的垂直方向坐标值。
  24140. *shape.width=100;//设置 shape 对象的宽度。
  24141. *shape.height=100;//设置 shape 对象的高度。
  24142. *shape.pivotX=50;//设置 shape 对象的水平方法轴心点坐标。
  24143. *shape.pivotY=50;//设置 shape 对象的垂直方法轴心点坐标。
  24144. *Laya.stage.addChild(shape);//将此 shape 对象添加到显示列表。
  24145. *shape.on(laya.events.Event.CLICK,this,onClickShape);//给 shape 对象添加点击事件侦听。
  24146. *}
  24147. *function onClickSprite()
  24148. *{
  24149. *console.log("点击 sprite 对象。");
  24150. *sprite.rotation+=5;//旋转 sprite 对象。
  24151. *}
  24152. *function onClickShape()
  24153. *{
  24154. *console.log("点击 shape 对象。");
  24155. *shape.rotation+=5;//旋转 shape 对象。
  24156. *}
  24157. *
  24158. *@example
  24159. *import Sprite=laya.display.Sprite;
  24160. *class Sprite_Example {
  24161. *private sprite:Sprite;
  24162. *private shape:Sprite
  24163. *public Sprite_Example(){
  24164. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  24165. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  24166. *this.onInit();
  24167. *}
  24168. *private onInit():void {
  24169. *this.sprite=new Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24170. *this.sprite.loadImage("resource/ui/bg.png");//加载并显示图片。
  24171. *this.sprite.x=200;//设置 sprite 对象相对于父容器的水平方向坐标值。
  24172. *this.sprite.y=200;//设置 sprite 对象相对于父容器的垂直方向坐标值。
  24173. *this.sprite.pivotX=0;//设置 sprite 对象的水平方法轴心点坐标。
  24174. *this.sprite.pivotY=0;//设置 sprite 对象的垂直方法轴心点坐标。
  24175. *Laya.stage.addChild(this.sprite);//将此 sprite 对象添加到显示列表。
  24176. *this.sprite.on(laya.events.Event.CLICK,this,this.onClickSprite);//给 sprite 对象添加点击事件侦听。
  24177. *this.shape=new Sprite();//创建一个 Sprite 类的实例对象 sprite 。
  24178. *this.shape.graphics.drawRect(0,0,100,100,"#ccff00","#ff0000",2);//绘制一个有边框的填充矩形。
  24179. *this.shape.x=400;//设置 shape 对象相对于父容器的水平方向坐标值。
  24180. *this.shape.y=200;//设置 shape 对象相对于父容器的垂直方向坐标值。
  24181. *this.shape.width=100;//设置 shape 对象的宽度。
  24182. *this.shape.height=100;//设置 shape 对象的高度。
  24183. *this.shape.pivotX=50;//设置 shape 对象的水平方法轴心点坐标。
  24184. *this.shape.pivotY=50;//设置 shape 对象的垂直方法轴心点坐标。
  24185. *Laya.stage.addChild(this.shape);//将此 shape 对象添加到显示列表。
  24186. *this.shape.on(laya.events.Event.CLICK,this,this.onClickShape);//给 shape 对象添加点击事件侦听。
  24187. *}
  24188. *private onClickSprite():void {
  24189. *console.log("点击 sprite 对象。");
  24190. *this.sprite.rotation+=5;//旋转 sprite 对象。
  24191. *}
  24192. *private onClickShape():void {
  24193. *console.log("点击 shape 对象。");
  24194. *this.shape.rotation+=5;//旋转 shape 对象。
  24195. *}
  24196. *}
  24197. */
  24198. //class laya.display.Sprite extends laya.display.Node
  24199. var Sprite=(function(_super){
  24200. function Sprite(){
  24201. /**@private */
  24202. this._x=0;
  24203. /**@private */
  24204. this._y=0;
  24205. /**@private */
  24206. this._width=0;
  24207. /**@private */
  24208. this._height=0;
  24209. /**@private */
  24210. this._visible=true;
  24211. /**@private 鼠标状态,0:auto,1:mouseEnabled=false,2:mouseEnabled=true。*/
  24212. this._mouseState=0;
  24213. /**@private z排序,数值越大越靠前。*/
  24214. this._zOrder=0;
  24215. /**@private */
  24216. this._renderType=0;
  24217. /**@private */
  24218. this._transform=null;
  24219. /**@private */
  24220. this._tfChanged=false;
  24221. /**@private */
  24222. this._texture=null;
  24223. /**@private */
  24224. this._boundStyle=null;
  24225. /**@private */
  24226. this._graphics=null;
  24227. /**
  24228. *<p>鼠标事件与此对象的碰撞检测是否可穿透。碰撞检测发生在鼠标事件的捕获阶段,此阶段引擎会从stage开始递归检测stage及其子对象,直到找到命中的目标对象或者未命中任何对象。</p>
  24229. *<p>穿透表示鼠标事件发生的位置处于本对象绘图区域内时,才算命中,而与对象宽高和值为Rectangle对象的hitArea属性无关。如果sprite.hitArea值是HitArea对象,表示显式声明了此对象的鼠标事件响应区域,而忽略对象的宽高、mouseThrough属性。</p>
  24230. *<p>影响对象鼠标事件响应区域的属性为:width、height、hitArea,优先级顺序为:hitArea(type:HitArea)>hitArea(type:Rectangle)>width/height。</p>
  24231. *@default false 不可穿透,此对象的鼠标响应区域由width、height、hitArea属性决定。</p>
  24232. */
  24233. this.mouseThrough=false;
  24234. /**
  24235. *<p>指定是否自动计算宽高数据。默认值为 false 。</p>
  24236. *<p>Sprite宽高默认为0,并且不会随着绘制内容的变化而变化,如果想根据绘制内容获取宽高,可以设置本属性为true,或者通过getBounds方法获取。设置为true,对性能有一定影响。</p>
  24237. */
  24238. this.autoSize=false;
  24239. /**
  24240. *<p>指定鼠标事件检测是优先检测自身,还是优先检测其子对象。鼠标事件检测发生在鼠标事件的捕获阶段,此阶段引擎会从stage开始递归检测stage及其子对象,直到找到命中的目标对象或者未命中任何对象。</p>
  24241. *<p>如果为false,优先检测子对象,当有子对象被命中时,中断检测,获得命中目标。如果未命中任何子对象,最后再检测此对象;如果为true,则优先检测本对象,如果本对象没有被命中,直接中断检测,表示没有命中目标;如果本对象被命中,则进一步递归检测其子对象,以确认最终的命中目标。</p>
  24242. *<p>合理使用本属性,能减少鼠标事件检测的节点,提高性能。可以设置为true的情况:开发者并不关心此节点的子节点的鼠标事件检测结果,也就是以此节点作为其子节点的鼠标事件检测依据。</p>
  24243. *<p>Stage对象和UI的View组件默认为true。</p>
  24244. *@default false 优先检测此对象的子对象,当递归检测完所有子对象后,仍然没有找到目标对象,最后再检测此对象。
  24245. */
  24246. this.hitTestPrior=false;
  24247. Sprite.__super.call(this);
  24248. this._repaint=/*laya.display.SpriteConst.REPAINT_NONE*/0;
  24249. this._style=SpriteStyle.EMPTY;
  24250. this._cacheStyle=CacheStyle.EMPTY;
  24251. }
  24252. __class(Sprite,'laya.display.Sprite',_super);
  24253. var __proto=Sprite.prototype;
  24254. /**@inheritDoc */
  24255. __proto.destroy=function(destroyChild){
  24256. (destroyChild===void 0)&& (destroyChild=true);
  24257. _super.prototype.destroy.call(this,destroyChild);
  24258. this._style && this._style.recover();
  24259. this._cacheStyle && this._cacheStyle.recover();
  24260. this._boundStyle && this._boundStyle.recover();
  24261. this._style=null;
  24262. this._cacheStyle=null;
  24263. this._boundStyle=null;
  24264. this._transform=null;
  24265. if (this._graphics&&this._graphics.autoDestroy){
  24266. this._graphics.destroy();
  24267. }
  24268. this._graphics=null;
  24269. this.texture=null;
  24270. }
  24271. /**根据zOrder进行重新排序。*/
  24272. __proto.updateZOrder=function(){
  24273. Utils.updateOrder(this._children)&& this.repaint();
  24274. }
  24275. /**
  24276. *@private
  24277. */
  24278. __proto._getBoundsStyle=function(){
  24279. if (!this._boundStyle)this._boundStyle=BoundsStyle.create();
  24280. return this._boundStyle;
  24281. }
  24282. /**@private */
  24283. __proto._setCustomRender=function(){}
  24284. /**@private */
  24285. __proto._setCacheAs=function(value){}
  24286. /**
  24287. *更新_cnavas相关的状态
  24288. */
  24289. __proto._checkCanvasEnable=function(){
  24290. var tEnable=this._cacheStyle.needEnableCanvasRender();
  24291. this._getCacheStyle().enableCanvasRender=tEnable;
  24292. if (tEnable){
  24293. if (this._cacheStyle.needBitmapCache()){
  24294. this._cacheStyle.cacheAs="bitmap";
  24295. }else {
  24296. this._cacheStyle.cacheAs=this._cacheStyle.userSetCache;
  24297. }
  24298. this._cacheStyle.reCache=true;
  24299. this._renderType |=/*laya.display.SpriteConst.CANVAS*/0x08;
  24300. }else {
  24301. this._cacheStyle.cacheAs="none";
  24302. this._cacheStyle.releaseContext();
  24303. this._renderType &=~ /*laya.display.SpriteConst.CANVAS*/0x08;
  24304. }
  24305. this._setCacheAs(this._cacheStyle.cacheAs);
  24306. this._setRenderType(this._renderType);
  24307. }
  24308. /**在设置cacheAs的情况下,调用此方法会重新刷新缓存。*/
  24309. __proto.reCache=function(){
  24310. this._cacheStyle.reCache=true;
  24311. this._repaint |=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02;
  24312. }
  24313. __proto.getRepaint=function(){
  24314. return this._repaint;
  24315. }
  24316. /**@private */
  24317. __proto._setX=function(value){
  24318. this._x=value;
  24319. }
  24320. /**@private */
  24321. __proto._setY=function(value){
  24322. this._y=value;
  24323. }
  24324. /**@private */
  24325. __proto._setWidth=function(texture,value){}
  24326. /**@private */
  24327. __proto._setHeight=function(texture,value){}
  24328. /**
  24329. *设置对象bounds大小,如果有设置,则不再通过getBounds计算,合理使用能提高性能。
  24330. *@param bound bounds矩形区域
  24331. */
  24332. __proto.setSelfBounds=function(bound){
  24333. this._getBoundsStyle().userBounds=bound;
  24334. }
  24335. /**
  24336. *<p>获取本对象在父容器坐标系的矩形显示区域。</p>
  24337. *<p><b>注意:</b>计算量较大,尽量少用。</p>
  24338. *@return 矩形区域。
  24339. */
  24340. __proto.getBounds=function(){
  24341. return this._getBoundsStyle().bounds=Rectangle._getWrapRec(this._boundPointsToParent());
  24342. }
  24343. /**
  24344. *获取本对象在自己坐标系的矩形显示区域。
  24345. *<p><b>注意:</b>计算量较大,尽量少用。</p>
  24346. *@return 矩形区域。
  24347. */
  24348. __proto.getSelfBounds=function(){
  24349. if (this._boundStyle && this._boundStyle.userBounds)return this._boundStyle.userBounds;
  24350. if (!this._graphics && this._children.length===0&&!this._texture)return Rectangle.TEMP.setTo(0,0,0,0);
  24351. return this._getBoundsStyle().bounds=Rectangle._getWrapRec(this._getBoundPointsM(false));
  24352. }
  24353. /**
  24354. *@private
  24355. *获取本对象在父容器坐标系的显示区域多边形顶点列表。
  24356. *当显示对象链中有旋转时,返回多边形顶点列表,无旋转时返回矩形的四个顶点。
  24357. *@param ifRotate (可选)之前的对象链中是否有旋转。
  24358. *@return 顶点列表。结构:[x1,y1,x2,y2,x3,y3,...]。
  24359. */
  24360. __proto._boundPointsToParent=function(ifRotate){
  24361. (ifRotate===void 0)&& (ifRotate=false);
  24362. var pX=0,pY=0;
  24363. if (this._style){
  24364. pX=this.pivotX;
  24365. pY=this.pivotY;
  24366. ifRotate=ifRotate || (this._style.rotation!==0);
  24367. if (this._style.scrollRect){
  24368. pX+=this._style.scrollRect.x;
  24369. pY+=this._style.scrollRect.y;
  24370. }
  24371. };
  24372. var pList=this._getBoundPointsM(ifRotate);
  24373. if (!pList || pList.length < 1)return pList;
  24374. if (pList.length !=8){
  24375. pList=ifRotate ? GrahamScan.scanPList(pList):Rectangle._getWrapRec(pList,Rectangle.TEMP)._getBoundPoints();
  24376. }
  24377. if (!this.transform){
  24378. Utils.transPointList(pList,this._x-pX,this._y-pY);
  24379. return pList;
  24380. };
  24381. var tPoint=Point.TEMP;
  24382. var i=0,len=pList.length;
  24383. for (i=0;i < len;i+=2){
  24384. tPoint.x=pList[i];
  24385. tPoint.y=pList[i+1];
  24386. this.toParentPoint(tPoint);
  24387. pList[i]=tPoint.x;
  24388. pList[i+1]=tPoint.y;
  24389. }
  24390. return pList;
  24391. }
  24392. /**
  24393. *返回此实例中的绘图对象( <code>Graphics</code> )的显示区域,不包括子对象。
  24394. *@param realSize (可选)使用图片的真实大小,默认为false
  24395. *@return 一个 Rectangle 对象,表示获取到的显示区域。
  24396. */
  24397. __proto.getGraphicBounds=function(realSize){
  24398. (realSize===void 0)&& (realSize=false);
  24399. if (!this._graphics)return Rectangle.TEMP.setTo(0,0,0,0);
  24400. return this._graphics.getBounds(realSize);
  24401. }
  24402. /**
  24403. *@private
  24404. *获取自己坐标系的显示区域多边形顶点列表
  24405. *@param ifRotate (可选)当前的显示对象链是否由旋转
  24406. *@return 顶点列表。结构:[x1,y1,x2,y2,x3,y3,...]。
  24407. */
  24408. __proto._getBoundPointsM=function(ifRotate){
  24409. (ifRotate===void 0)&& (ifRotate=false);
  24410. if (this._boundStyle && this._boundStyle.userBounds)return this._boundStyle.userBounds._getBoundPoints();
  24411. if (!this._boundStyle)this._getBoundsStyle();
  24412. if (!this._boundStyle.temBM)this._boundStyle.temBM=[];
  24413. if (this._style.scrollRect){
  24414. var rst=Utils.clearArray(this._boundStyle.temBM);
  24415. var rec=Rectangle.TEMP;
  24416. rec.copyFrom(this._style.scrollRect);
  24417. Utils.concatArray(rst,rec._getBoundPoints());
  24418. return rst;
  24419. };
  24420. var pList;
  24421. if (this._graphics){
  24422. pList=this._graphics.getBoundPoints();
  24423. }else {
  24424. pList=Utils.clearArray(this._boundStyle.temBM);
  24425. if (this._texture){
  24426. rec=Rectangle.TEMP;
  24427. rec.setTo(0,0,this.width||this._texture.width,this.height||this._texture.height);
  24428. Utils.concatArray(pList,rec._getBoundPoints());
  24429. }
  24430. };
  24431. var child;
  24432. var cList;
  24433. var __childs;
  24434. __childs=this._children;
  24435. for (var i=0,n=__childs.length;i < n;i++){
  24436. child=__childs [i];
  24437. if ((child instanceof laya.display.Sprite )&& child._visible===true){
  24438. cList=child._boundPointsToParent(ifRotate);
  24439. if (cList)
  24440. pList=pList ? Utils.concatArray(pList,cList):cList;
  24441. }
  24442. }
  24443. return pList;
  24444. }
  24445. /**
  24446. *@private
  24447. *获取cache数据。
  24448. *@return cache数据 CacheStyle 。
  24449. */
  24450. __proto._getCacheStyle=function(){
  24451. this._cacheStyle===CacheStyle.EMPTY && (this._cacheStyle=CacheStyle.create());
  24452. return this._cacheStyle;
  24453. }
  24454. /**
  24455. *@private
  24456. *获取样式。
  24457. *@return 样式 Style 。
  24458. */
  24459. __proto.getStyle=function(){
  24460. this._style===SpriteStyle.EMPTY && (this._style=SpriteStyle.create());
  24461. return this._style;
  24462. }
  24463. /**
  24464. *@private
  24465. *设置样式。
  24466. *@param value 样式。
  24467. */
  24468. __proto.setStyle=function(value){
  24469. this._style=value;
  24470. }
  24471. /**@private */
  24472. __proto._setScaleX=function(value){
  24473. this._style.scaleX=value;
  24474. }
  24475. /**@private */
  24476. __proto._setScaleY=function(value){
  24477. this._style.scaleY=value;
  24478. }
  24479. /**@private */
  24480. __proto._setRotation=function(value){
  24481. this._style.rotation=value;
  24482. }
  24483. /**@private */
  24484. __proto._setSkewX=function(value){
  24485. this._style.skewX=value;
  24486. }
  24487. /**@private */
  24488. __proto._setSkewY=function(value){
  24489. this._style.skewY=value;
  24490. }
  24491. /**@private */
  24492. __proto._createTransform=function(){
  24493. return Matrix.create();
  24494. }
  24495. /**@private */
  24496. __proto._adjustTransform=function(){
  24497. this._tfChanged=false;
  24498. var style=this._style;
  24499. var sx=style.scaleX,sy=style.scaleY;
  24500. var sskx=style.skewX;
  24501. var ssky=style.skewY;
  24502. var rot=style.rotation;
  24503. var m=this._transform || (this._transform=this._createTransform());
  24504. if (rot || sx!==1 || sy!==1 || sskx!==0 || ssky!==0){
  24505. m._bTransform=true;
  24506. var skx=(rot-sskx)*0.0174532922222222;
  24507. var sky=(rot+ssky)*0.0174532922222222;
  24508. var cx=Math.cos(sky);
  24509. var ssx=Math.sin(sky);
  24510. var cy=Math.sin(skx);
  24511. var ssy=Math.cos(skx);
  24512. m.a=sx *cx;
  24513. m.b=sx *ssx;
  24514. m.c=-sy *cy;
  24515. m.d=sy *ssy;
  24516. m.tx=m.ty=0;
  24517. }else {
  24518. m.identity();
  24519. this._renderType &=~ /*laya.display.SpriteConst.TRANSFORM*/0x02;
  24520. this._setRenderType(this._renderType);
  24521. }
  24522. return m;
  24523. }
  24524. /**@private */
  24525. __proto._setTransform=function(value){}
  24526. /**@private */
  24527. __proto._setPivotX=function(value){
  24528. var style=this.getStyle();
  24529. style.pivotX=value;
  24530. }
  24531. /**@private */
  24532. __proto._getPivotX=function(){
  24533. return this._style.pivotX;
  24534. }
  24535. /**@private */
  24536. __proto._setPivotY=function(value){
  24537. var style=this.getStyle();
  24538. style.pivotY=value;
  24539. }
  24540. /**@private */
  24541. __proto._getPivotY=function(){
  24542. return this._style.pivotY;
  24543. }
  24544. /**@private */
  24545. __proto._setAlpha=function(value){
  24546. if (this._style.alpha!==value){
  24547. var style=this.getStyle();
  24548. style.alpha=value;
  24549. if (value!==1)this._renderType |=/*laya.display.SpriteConst.ALPHA*/0x01;
  24550. else this._renderType &=~ /*laya.display.SpriteConst.ALPHA*/0x01;
  24551. this._setRenderType(this._renderType);
  24552. this.parentRepaint();
  24553. }
  24554. }
  24555. /**@private */
  24556. __proto._getAlpha=function(){
  24557. return this._style.alpha;
  24558. }
  24559. /**@private */
  24560. __proto._setBlendMode=function(value){}
  24561. /**@private */
  24562. __proto._setGraphics=function(value){}
  24563. /**@private */
  24564. __proto._setGraphicsCallBack=function(){}
  24565. /**@private */
  24566. __proto._setScrollRect=function(value){}
  24567. /**
  24568. *<p>设置坐标位置。相当于分别设置x和y属性。</p>
  24569. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.pos(...).scale(...);</p>
  24570. *@param x X轴坐标。
  24571. *@param y Y轴坐标。
  24572. *@param speedMode (可选)是否极速模式,正常是调用this.x=value进行赋值,极速模式直接调用内部函数处理,如果未重写x,y属性,建议设置为急速模式性能更高。
  24573. *@return 返回对象本身。
  24574. */
  24575. __proto.pos=function(x,y,speedMode){
  24576. (speedMode===void 0)&& (speedMode=false);
  24577. if (this._x!==x || this._y!==y){
  24578. if (this.destroyed)return this;
  24579. if (speedMode){
  24580. this._setX(x);
  24581. this._setY(y);
  24582. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  24583. var p=this._cacheStyle.maskParent;
  24584. if (p){
  24585. p.repaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  24586. }
  24587. }else {
  24588. this.x=x;
  24589. this.y=y;
  24590. }
  24591. }
  24592. return this;
  24593. }
  24594. /**
  24595. *<p>设置轴心点。相当于分别设置pivotX和pivotY属性。</p>
  24596. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.pivot(...).pos(50,100);</p>
  24597. *@param x X轴心点。
  24598. *@param y Y轴心点。
  24599. *@return 返回对象本身。
  24600. */
  24601. __proto.pivot=function(x,y){
  24602. this.pivotX=x;
  24603. this.pivotY=y;
  24604. return this;
  24605. }
  24606. /**
  24607. *<p>设置宽高。相当于分别设置width和height属性。</p>
  24608. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.size(...).pos(50,100);</p>
  24609. *@param width 宽度值。
  24610. *@param hegiht 高度值。
  24611. *@return 返回对象本身。
  24612. */
  24613. __proto.size=function(width,height){
  24614. this.width=width;
  24615. this.height=height;
  24616. return this;
  24617. }
  24618. /**
  24619. *<p>设置缩放。相当于分别设置scaleX和scaleY属性。</p>
  24620. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.scale(...).pos(50,100);</p>
  24621. *@param scaleX X轴缩放比例。
  24622. *@param scaleY Y轴缩放比例。
  24623. *@param speedMode (可选)是否极速模式,正常是调用this.scaleX=value进行赋值,极速模式直接调用内部函数处理,如果未重写scaleX,scaleY属性,建议设置为急速模式性能更高。
  24624. *@return 返回对象本身。
  24625. */
  24626. __proto.scale=function(scaleX,scaleY,speedMode){
  24627. (speedMode===void 0)&& (speedMode=false);
  24628. var style=this.getStyle();
  24629. if (style.scaleX !=scaleX || style.scaleY !=scaleY){
  24630. if (this.destroyed)return this;
  24631. if (speedMode){
  24632. this._setScaleX(scaleX);
  24633. this._setScaleY(scaleY);
  24634. this._setTranformChange();
  24635. }else {
  24636. this.scaleX=scaleX;
  24637. this.scaleY=scaleY;
  24638. }
  24639. }
  24640. return this;
  24641. }
  24642. /**
  24643. *<p>设置倾斜角度。相当于分别设置skewX和skewY属性。</p>
  24644. *<p>因为返回值为Sprite对象本身,所以可以使用如下语法:spr.skew(...).pos(50,100);</p>
  24645. *@param skewX 水平倾斜角度。
  24646. *@param skewY 垂直倾斜角度。
  24647. *@return 返回对象本身
  24648. */
  24649. __proto.skew=function(skewX,skewY){
  24650. this.skewX=skewX;
  24651. this.skewY=skewY;
  24652. return this;
  24653. }
  24654. /**
  24655. *更新、呈现显示对象。由系统调用。
  24656. *@param context 渲染的上下文引用。
  24657. *@param x X轴坐标。
  24658. *@param y Y轴坐标。
  24659. */
  24660. __proto.render=function(ctx,x,y){
  24661. RenderSprite.renders[this._renderType]._fun(this,ctx,x+this._x,y+this._y);
  24662. this._repaint=0;
  24663. }
  24664. /**
  24665. *<p>绘制 当前<code>Sprite</code> 到 <code>Canvas</code> 上,并返回一个HtmlCanvas。</p>
  24666. *<p>绘制的结果可以当作图片源,再次绘制到其他Sprite里面,示例:</p>
  24667. *
  24668. *var htmlCanvas:HTMLCanvas=sprite.drawToCanvas(100,100,0,0);//把精灵绘制到canvas上面
  24669. *var sp:Sprite=new Sprite();//创建精灵
  24670. *sp.graphics.drawTexture(htmlCanvas.getTexture());//把截图绘制到精灵上
  24671. *Laya.stage.addChild(sp);//把精灵显示到舞台
  24672. *
  24673. *<p>也可以获取原始图片数据,分享到网上,从而实现截图效果,示例:</p>
  24674. *
  24675. *var htmlCanvas:HTMLCanvas=sprite.drawToCanvas(100,100,0,0);//把精灵绘制到canvas上面
  24676. *htmlCanvas.toBase64("image/png",0.9);//打印图片base64信息,可以发给服务器或者保存为图片
  24677. *
  24678. *@param canvasWidth 画布宽度。
  24679. *@param canvasHeight 画布高度。
  24680. *@param x 绘制的 X 轴偏移量。
  24681. *@param y 绘制的 Y 轴偏移量。
  24682. *@return HTMLCanvas 对象。
  24683. */
  24684. __proto.drawToCanvas=function(canvasWidth,canvasHeight,offsetX,offsetY){
  24685. return RunDriver.drawToCanvas(this,this._renderType,canvasWidth,canvasHeight,offsetX,offsetY);
  24686. }
  24687. __proto.drawToTexture=function(canvasWidth,canvasHeight,offsetX,offsetY){
  24688. return RunDriver.drawToTexture(this,this._renderType,canvasWidth,canvasHeight,offsetX,offsetY);
  24689. }
  24690. /**
  24691. *<p>自定义更新、呈现显示对象。一般用来扩展渲染模式,请合理使用,可能会导致在加速器上无法渲染。</p>
  24692. *<p><b>注意</b>不要在此函数内增加或删除树节点,否则会对树节点遍历造成影响。</p>
  24693. *@param context 渲染的上下文引用。
  24694. *@param x X轴坐标。
  24695. *@param y Y轴坐标。
  24696. */
  24697. __proto.customRender=function(context,x,y){
  24698. this._repaint=/*laya.display.SpriteConst.REPAINT_ALL*/0x03;
  24699. }
  24700. /**
  24701. *@private
  24702. *应用滤镜。
  24703. */
  24704. __proto._applyFilters=function(){}
  24705. /**@private */
  24706. __proto._setColorFilter=function(value){}
  24707. /**
  24708. *@private
  24709. *查看当前原件中是否包含发光滤镜。
  24710. *@return 一个 Boolean 值,表示当前原件中是否包含发光滤镜。
  24711. */
  24712. __proto._isHaveGlowFilter=function(){
  24713. var i=0,len=0;
  24714. if (this.filters){
  24715. for (i=0;i < this.filters.length;i++){
  24716. if (this.filters[i].type==/*laya.filters.Filter.GLOW*/0x08){
  24717. return true;
  24718. }
  24719. }
  24720. }
  24721. for (i=0,len=this._children.length;i < len;i++){
  24722. if (this._children[i]._isHaveGlowFilter()){
  24723. return true;
  24724. }
  24725. }
  24726. return false;
  24727. }
  24728. /**
  24729. *把本地坐标转换为相对stage的全局坐标。
  24730. *@param point 本地坐标点。
  24731. *@param createNewPoint (可选)是否创建一个新的Point对象作为返回值,默认为false,使用输入的point对象返回,减少对象创建开销。
  24732. *@param globalNode global节点,默认为Laya.stage
  24733. *@return 转换后的坐标的点。
  24734. */
  24735. __proto.localToGlobal=function(point,createNewPoint,globalNode){
  24736. (createNewPoint===void 0)&& (createNewPoint=false);
  24737. if (createNewPoint===true){
  24738. point=new Point(point.x,point.y);
  24739. };
  24740. var ele=this;
  24741. globalNode=globalNode || Laya.stage;
  24742. while (ele && !ele.destroyed){
  24743. if (ele==globalNode)break ;
  24744. point=ele.toParentPoint(point);
  24745. ele=ele.parent;
  24746. }
  24747. return point;
  24748. }
  24749. /**
  24750. *把stage的全局坐标转换为本地坐标。
  24751. *@param point 全局坐标点。
  24752. *@param createNewPoint (可选)是否创建一个新的Point对象作为返回值,默认为false,使用输入的point对象返回,减少对象创建开销。
  24753. *@param globalNode global节点,默认为Laya.stage
  24754. *@return 转换后的坐标的点。
  24755. */
  24756. __proto.globalToLocal=function(point,createNewPoint,globalNode){
  24757. (createNewPoint===void 0)&& (createNewPoint=false);
  24758. if (createNewPoint){
  24759. point=new Point(point.x,point.y);
  24760. };
  24761. var ele=this;
  24762. var list=[];
  24763. globalNode=globalNode || Laya.stage;
  24764. while (ele && !ele.destroyed){
  24765. if (ele==globalNode)break ;
  24766. list.push(ele);
  24767. ele=ele.parent;
  24768. };
  24769. var i=list.length-1;
  24770. while (i >=0){
  24771. ele=list[i];
  24772. point=ele.fromParentPoint(point);
  24773. i--;
  24774. }
  24775. return point;
  24776. }
  24777. /**
  24778. *将本地坐标系坐标转转换到父容器坐标系。
  24779. *@param point 本地坐标点。
  24780. *@return 转换后的点。
  24781. */
  24782. __proto.toParentPoint=function(point){
  24783. if (!point)return point;
  24784. point.x-=this.pivotX;
  24785. point.y-=this.pivotY;
  24786. if (this.transform){
  24787. this._transform.transformPoint(point);
  24788. }
  24789. point.x+=this._x;
  24790. point.y+=this._y;
  24791. var scroll=this._style.scrollRect;
  24792. if (scroll){
  24793. point.x-=scroll.x;
  24794. point.y-=scroll.y;
  24795. }
  24796. return point;
  24797. }
  24798. /**
  24799. *将父容器坐标系坐标转换到本地坐标系。
  24800. *@param point 父容器坐标点。
  24801. *@return 转换后的点。
  24802. */
  24803. __proto.fromParentPoint=function(point){
  24804. if (!point)return point;
  24805. point.x-=this._x;
  24806. point.y-=this._y;
  24807. var scroll=this._style.scrollRect;
  24808. if (scroll){
  24809. point.x+=scroll.x;
  24810. point.y+=scroll.y;
  24811. }
  24812. if (this.transform){
  24813. this._transform.invertTransformPoint(point);
  24814. }
  24815. point.x+=this.pivotX;
  24816. point.y+=this.pivotY;
  24817. return point;
  24818. }
  24819. /**
  24820. *将Stage坐标系坐标转换到本地坐标系。
  24821. *@param point 父容器坐标点。
  24822. *@return 转换后的点。
  24823. */
  24824. __proto.fromStagePoint=function(point){
  24825. return point;
  24826. }
  24827. /**
  24828. *<p>增加事件侦听器,以使侦听器能够接收事件通知。</p>
  24829. *<p>如果侦听鼠标事件,则会自动设置自己和父亲节点的属性 mouseEnabled 的值为 true(如果父节点mouseEnabled=false,则停止设置父节点mouseEnabled属性)。</p>
  24830. *@param type 事件的类型。
  24831. *@param caller 事件侦听函数的执行域。
  24832. *@param listener 事件侦听函数。
  24833. *@param args (可选)事件侦听函数的回调参数。
  24834. *@return 此 EventDispatcher 对象。
  24835. */
  24836. __proto.on=function(type,caller,listener,args){
  24837. if (this._mouseState!==1 && this.isMouseEvent(type)){
  24838. this.mouseEnabled=true;
  24839. this._setBit(/*laya.Const.HAS_MOUSE*/0x40,true);
  24840. if (this._parent){
  24841. this._$2__onDisplay();
  24842. }
  24843. return this._createListener(type,caller,listener,args,false);
  24844. }
  24845. return _super.prototype.on.call(this,type,caller,listener,args);
  24846. }
  24847. /**
  24848. *<p>增加事件侦听器,以使侦听器能够接收事件通知,此侦听事件响应一次后则自动移除侦听。</p>
  24849. *<p>如果侦听鼠标事件,则会自动设置自己和父亲节点的属性 mouseEnabled 的值为 true(如果父节点mouseEnabled=false,则停止设置父节点mouseEnabled属性)。</p>
  24850. *@param type 事件的类型。
  24851. *@param caller 事件侦听函数的执行域。
  24852. *@param listener 事件侦听函数。
  24853. *@param args (可选)事件侦听函数的回调参数。
  24854. *@return 此 EventDispatcher 对象。
  24855. */
  24856. __proto.once=function(type,caller,listener,args){
  24857. if (this._mouseState!==1 && this.isMouseEvent(type)){
  24858. this.mouseEnabled=true;
  24859. this._setBit(/*laya.Const.HAS_MOUSE*/0x40,true);
  24860. if (this._parent){
  24861. this._$2__onDisplay();
  24862. }
  24863. return this._createListener(type,caller,listener,args,true);
  24864. }
  24865. return _super.prototype.once.call(this,type,caller,listener,args);
  24866. }
  24867. /**@private */
  24868. __proto._$2__onDisplay=function(){
  24869. if (this._mouseState!==1){
  24870. var ele=this;
  24871. ele=ele.parent;
  24872. while (ele && ele._mouseState!==1){
  24873. if (ele._getBit(/*laya.Const.HAS_MOUSE*/0x40))break ;
  24874. ele.mouseEnabled=true;
  24875. ele._setBit(/*laya.Const.HAS_MOUSE*/0x40,true);
  24876. ele=ele.parent;
  24877. }
  24878. }
  24879. }
  24880. /**@private */
  24881. __proto._setParent=function(value){
  24882. _super.prototype._setParent.call(this,value);
  24883. if (value && this._getBit(/*laya.Const.HAS_MOUSE*/0x40)){
  24884. this._$2__onDisplay();
  24885. }
  24886. }
  24887. /**
  24888. *<p>加载并显示一个图片。相当于加载图片后,设置texture属性</p>
  24889. *<p>注意:2.0改动:多次调用,只会显示一个图片(1.0会显示多个图片),x,y,width,height参数取消。</p>
  24890. *@param url 图片地址。
  24891. *@param complete (可选)加载完成回调。
  24892. *@return 返回精灵对象本身。
  24893. */
  24894. __proto.loadImage=function(url,complete){
  24895. var _$this=this;
  24896. if (url==null){
  24897. this.texture=null;
  24898. loaded();
  24899. }else{
  24900. var tex=Loader.getRes(url);
  24901. if (!tex){
  24902. tex=new Texture();
  24903. tex.load(url);
  24904. Loader.cacheRes(url,tex);
  24905. }
  24906. this.texture=tex;
  24907. if (!tex.getIsReady())tex.once(/*laya.events.Event.READY*/"ready",null,loaded);
  24908. else loaded();
  24909. }
  24910. function loaded (){
  24911. _$this.repaint(/*laya.display.SpriteConst.REPAINT_ALL*/0x03);
  24912. complete && complete.run();
  24913. }
  24914. return this;
  24915. }
  24916. /**cacheAs后,设置自己和父对象缓存失效。*/
  24917. __proto.repaint=function(type){
  24918. (type===void 0)&& (type=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  24919. if (!(this._repaint&type)){
  24920. this._repaint |=type;
  24921. this.parentRepaint(type);
  24922. }
  24923. if (this._cacheStyle && this._cacheStyle.maskParent){
  24924. this._cacheStyle.maskParent.repaint(type);
  24925. }
  24926. }
  24927. /**
  24928. *@private
  24929. *获取是否重新缓存。
  24930. *@return 如果重新缓存值为 true,否则值为 false。
  24931. */
  24932. __proto._needRepaint=function(){
  24933. return (this._repaint& /*laya.display.SpriteConst.REPAINT_CACHE*/0x02)&& this._cacheStyle.enableCanvasRender && this._cacheStyle.reCache;
  24934. }
  24935. /**@private */
  24936. __proto._childChanged=function(child){
  24937. if (this._children.length)this._renderType |=/*laya.display.SpriteConst.CHILDS*/0x2000;
  24938. else this._renderType &=~ /*laya.display.SpriteConst.CHILDS*/0x2000;
  24939. this._setRenderType(this._renderType);
  24940. if (child && this._getBit(/*laya.Const.HAS_ZORDER*/0x20))Laya.systemTimer.callLater(this,this.updateZOrder);
  24941. this.repaint(/*laya.display.SpriteConst.REPAINT_ALL*/0x03);
  24942. }
  24943. /**cacheAs时,设置所有父对象缓存失效。 */
  24944. __proto.parentRepaint=function(type){
  24945. (type===void 0)&& (type=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  24946. var p=this._parent;
  24947. if (p && !(p._repaint&type)){
  24948. p._repaint |=type;
  24949. p.parentRepaint(type);
  24950. }
  24951. }
  24952. /**@private */
  24953. __proto._setMask=function(value){}
  24954. /**
  24955. *开始拖动此对象。
  24956. *@param area (可选)拖动区域,此区域为当前对象注册点活动区域(不包括对象宽高),可选。
  24957. *@param hasInertia (可选)鼠标松开后,是否还惯性滑动,默认为false,可选。
  24958. *@param elasticDistance (可选)橡皮筋效果的距离值,0为无橡皮筋效果,默认为0,可选。
  24959. *@param elasticBackTime (可选)橡皮筋回弹时间,单位为毫秒,默认为300毫秒,可选。
  24960. *@param data (可选)拖动事件携带的数据,可选。
  24961. *@param disableMouseEvent (可选)禁用其他对象的鼠标检测,默认为false,设置为true能提高性能。
  24962. *@param ratio (可选)惯性阻尼系数,影响惯性力度和时长。
  24963. */
  24964. __proto.startDrag=function(area,hasInertia,elasticDistance,elasticBackTime,data,disableMouseEvent,ratio){
  24965. (hasInertia===void 0)&& (hasInertia=false);
  24966. (elasticDistance===void 0)&& (elasticDistance=0);
  24967. (elasticBackTime===void 0)&& (elasticBackTime=300);
  24968. (disableMouseEvent===void 0)&& (disableMouseEvent=false);
  24969. (ratio===void 0)&& (ratio=0.92);
  24970. this._style.dragging || (this.getStyle().dragging=new Dragging());
  24971. this._style.dragging.start(this,area,hasInertia,elasticDistance,elasticBackTime,data,disableMouseEvent,ratio);
  24972. }
  24973. /**停止拖动此对象。*/
  24974. __proto.stopDrag=function(){
  24975. this._style.dragging && this._style.dragging.stop();
  24976. }
  24977. /**@private */
  24978. __proto._setDisplay=function(value){
  24979. if (!value){
  24980. if (this._cacheStyle){
  24981. this._cacheStyle.releaseContext();
  24982. this._cacheStyle.releaseFilterCache();
  24983. if (this._cacheStyle.hasGlowFilter){
  24984. this._cacheStyle.hasGlowFilter=false;
  24985. }
  24986. }
  24987. }
  24988. _super.prototype._setDisplay.call(this,value);
  24989. }
  24990. /**
  24991. *检测某个点是否在此对象内。
  24992. *@param x 全局x坐标。
  24993. *@param y 全局y坐标。
  24994. *@return 表示是否在对象内。
  24995. */
  24996. __proto.hitTestPoint=function(x,y){
  24997. var point=this.globalToLocal(Point.TEMP.setTo(x,y));
  24998. x=point.x;
  24999. y=point.y;
  25000. 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();
  25001. return rect.contains(x,y);
  25002. }
  25003. /**获得相对于本对象上的鼠标坐标信息。*/
  25004. __proto.getMousePoint=function(){
  25005. return this.globalToLocal(Point.TEMP.setTo(Laya.stage.mouseX,Laya.stage.mouseY));
  25006. }
  25007. /**@private */
  25008. __proto._setTexture=function(value){}
  25009. /**@private */
  25010. __proto._setRenderType=function(type){}
  25011. /**@private */
  25012. __proto._setTranformChange=function(){
  25013. this._tfChanged=true;
  25014. this._renderType |=/*laya.display.SpriteConst.TRANSFORM*/0x02;
  25015. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25016. }
  25017. /**@private */
  25018. __proto._setBgStyleColor=function(x,y,width,height,fillColor){}
  25019. /**@private */
  25020. __proto._setBorderStyleColor=function(x,y,width,height,fillColor,borderWidth){}
  25021. /**@private */
  25022. __proto.captureMouseEvent=function(exclusive){
  25023. MouseManager.instance.setCapture(this,exclusive);
  25024. }
  25025. /**@private */
  25026. __proto.releaseMouseEvent=function(){
  25027. MouseManager.instance.releaseCapture();
  25028. }
  25029. /**
  25030. *设置是否开启自定义渲染,只有开启自定义渲染,才能使用customRender函数渲染。
  25031. */
  25032. __getset(0,__proto,'customRenderEnable',null,function(b){
  25033. if (b){
  25034. this._renderType |=/*laya.display.SpriteConst.CUSTOM*/0x800;
  25035. this._setRenderType(this._renderType);
  25036. this._setCustomRender();
  25037. }
  25038. });
  25039. //_dataf32[SpriteConst.POSCACHE]=value=="bitmap"?2:(value=="normal"?1:0);
  25040. /**
  25041. *<p>指定显示对象是否缓存为静态图像,cacheAs时,子对象发生变化,会自动重新缓存,同时也可以手动调用reCache方法更新缓存。</p>
  25042. *<p>建议把不经常变化的“复杂内容”缓存为静态图像,能极大提高渲染性能。cacheAs有"none","normal"和"bitmap"三个值可选。
  25043. *<li>默认为"none",不做任何缓存。</li>
  25044. *<li>当值为"normal"时,canvas模式下进行画布缓存,webgl模式下进行命令缓存。</li>
  25045. *<li>当值为"bitmap"时,canvas模式下进行依然是画布缓存,webgl模式下使用renderTarget缓存。</li></p>
  25046. *<p>webgl下renderTarget缓存模式缺点:会额外创建renderTarget对象,增加内存开销,缓存面积有最大2048限制,不断重绘时会增加CPU开销。优点:大幅减少drawcall,渲染性能最高。
  25047. *webgl下命令缓存模式缺点:只会减少节点遍历及命令组织,不会减少drawcall数,性能中等。优点:没有额外内存开销,无需renderTarget支持。</p>
  25048. */
  25049. __getset(0,__proto,'cacheAs',function(){
  25050. return this._cacheStyle.cacheAs;
  25051. },function(value){
  25052. if (value===this._cacheStyle.userSetCache)return;
  25053. if (this.mask && value==='normal')return;
  25054. this._setCacheAs(value);
  25055. this._getCacheStyle().userSetCache=value;
  25056. this._checkCanvasEnable();
  25057. this.repaint();
  25058. });
  25059. /**
  25060. *获得相对于stage的全局Y轴缩放值(会叠加父亲节点的缩放值)。
  25061. */
  25062. __getset(0,__proto,'globalScaleY',function(){
  25063. var scale=1;
  25064. var ele=this;
  25065. while (ele){
  25066. if (ele===Laya.stage)break ;
  25067. scale *=ele.scaleY;
  25068. ele=ele.parent;
  25069. }
  25070. return scale;
  25071. });
  25072. /**
  25073. *<p>可以设置一个Rectangle区域作为点击区域,或者设置一个<code>HitArea</code>实例作为点击区域,HitArea内可以设置可点击和不可点击区域。</p>
  25074. *<p>如果不设置hitArea,则根据宽高形成的区域进行碰撞。</p>
  25075. */
  25076. __getset(0,__proto,'hitArea',function(){
  25077. return this._style.hitArea;
  25078. },function(value){
  25079. this.getStyle().hitArea=value;
  25080. });
  25081. /**设置cacheAs为非空时此值才有效,staticCache=true时,子对象变化时不会自动更新缓存,只能通过调用reCache方法手动刷新。*/
  25082. __getset(0,__proto,'staticCache',function(){
  25083. return this._cacheStyle.staticCache;
  25084. },function(value){
  25085. this._getCacheStyle().staticCache=value;
  25086. if (!value)this.reCache();
  25087. });
  25088. /**
  25089. *<p>对象的显示宽度(以像素为单位)。</p>
  25090. */
  25091. __getset(0,__proto,'displayWidth',function(){
  25092. return this.width *this.scaleX;
  25093. });
  25094. /**z排序,更改此值,则会按照值的大小对同一容器的所有对象重新排序。值越大,越靠上。默认为0,则根据添加顺序排序。*/
  25095. __getset(0,__proto,'zOrder',function(){
  25096. return this._zOrder;
  25097. },function(value){
  25098. if (this._zOrder !=value){
  25099. this._zOrder=value;
  25100. if (this._parent){
  25101. value && this._parent._setBit(/*laya.Const.HAS_ZORDER*/0x20,true);
  25102. Laya.systemTimer.callLater(this._parent,this.updateZOrder);
  25103. }
  25104. }
  25105. });
  25106. /**旋转角度,默认值为0。以角度为单位。*/
  25107. __getset(0,__proto,'rotation',function(){
  25108. return this._style.rotation;
  25109. },function(value){
  25110. var style=this.getStyle();
  25111. if (style.rotation!==value){
  25112. this._setRotation(value);
  25113. this._setTranformChange();
  25114. }
  25115. });
  25116. /**
  25117. *<p>显示对象的宽度,单位为像素,默认为0。</p>
  25118. *<p>此宽度用于鼠标碰撞检测,并不影响显示对象图像大小。需要对显示对象的图像进行缩放,请使用scale、scaleX、scaleY。</p>
  25119. *<p>可以通过getbounds获取显示对象图像的实际宽度。</p>
  25120. */
  25121. __getset(0,__proto,'width',function(){
  25122. if (!this.autoSize)return this._width || (this.texture?this.texture.width:0);
  25123. if (this.texture)return this.texture.width;
  25124. if (!this._graphics && this._children.length===0)return 0;
  25125. return this.getSelfBounds().width;
  25126. },function(value){
  25127. if (this._width!==value){
  25128. this._width=value;
  25129. this._setWidth(this.texture,value);
  25130. this._setTranformChange();
  25131. }
  25132. });
  25133. /**表示显示对象相对于父容器的水平方向坐标值。*/
  25134. __getset(0,__proto,'x',function(){
  25135. return this._x;
  25136. },function(value){
  25137. if (this.destroyed)return;
  25138. if (this._x!==value){
  25139. this._setX(value);
  25140. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25141. var p=this._cacheStyle.maskParent;
  25142. if (p){
  25143. p.repaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25144. }
  25145. }
  25146. });
  25147. __getset(0,__proto,'drawCallOptimize',function(){
  25148. return this._getBit(/*laya.Const.DRAWCALL_OPTIMIZE*/0x100);
  25149. },function(value){
  25150. this._setBit(/*laya.Const.DRAWCALL_OPTIMIZE*/0x100,value);
  25151. });
  25152. /**
  25153. *设置一个Texture实例,并显示此图片(如果之前有其他绘制,则会被清除掉)。
  25154. *等同于graphics.clear();graphics.drawImage(),但性能更高
  25155. *还可以赋值一个图片地址,则会自动加载图片,然后显示
  25156. */
  25157. __getset(0,__proto,'texture',function(){
  25158. return this._texture;
  25159. },function(value){
  25160. if ((typeof value=='string')){
  25161. this.loadImage(value);
  25162. }else if (this._texture !=value){
  25163. this._texture && this._texture._removeReference();
  25164. this._texture=value;
  25165. value && value._addReference();
  25166. this._setTexture(value);
  25167. this._setWidth(this._texture,this.width);
  25168. this._setHeight(this._texture,this.height);
  25169. if (value)this._renderType |=/*laya.display.SpriteConst.TEXTURE*/0x100;
  25170. else this._renderType &=~ /*laya.display.SpriteConst.TEXTURE*/0x100;
  25171. this._setRenderType(this._renderType);
  25172. this.repaint();
  25173. }
  25174. });
  25175. /**
  25176. *获得相对于stage的全局旋转值(会叠加父亲节点的旋转值)。
  25177. */
  25178. __getset(0,__proto,'globalRotation',function(){
  25179. var angle=0;
  25180. var ele=this;
  25181. while (ele){
  25182. if (ele===Laya.stage)break ;
  25183. angle+=ele.rotation;
  25184. ele=ele.parent;
  25185. }
  25186. return angle;
  25187. });
  25188. /**表示显示对象相对于父容器的垂直方向坐标值。*/
  25189. __getset(0,__proto,'y',function(){
  25190. return this._y;
  25191. },function(value){
  25192. if (this.destroyed)return;
  25193. if (this._y!==value){
  25194. this._setY(value);
  25195. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25196. var p=this._cacheStyle.maskParent;
  25197. if (p){
  25198. p.repaint(/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  25199. }
  25200. }
  25201. });
  25202. /**
  25203. *<p>对象的显示高度(以像素为单位)。</p>
  25204. */
  25205. __getset(0,__proto,'displayHeight',function(){
  25206. return this.height *this.scaleY;
  25207. });
  25208. /**
  25209. *<p>显示对象的高度,单位为像素,默认为0。</p>
  25210. *<p>此高度用于鼠标碰撞检测,并不影响显示对象图像大小。需要对显示对象的图像进行缩放,请使用scale、scaleX、scaleY。</p>
  25211. *<p>可以通过getbounds获取显示对象图像的实际高度。</p>
  25212. */
  25213. __getset(0,__proto,'height',function(){
  25214. if (!this.autoSize)return this._height || (this.texture?this.texture.height:0);
  25215. if (this.texture)return this.texture.height;
  25216. if (!this._graphics && this._children.length===0)return 0;
  25217. return this.getSelfBounds().height;
  25218. },function(value){
  25219. if (this._height!==value){
  25220. this._height=value;
  25221. this._setHeight(this.texture,value);
  25222. this._setTranformChange();
  25223. }
  25224. });
  25225. /**指定要使用的混合模式。目前只支持"lighter"。*/
  25226. __getset(0,__proto,'blendMode',function(){
  25227. return this._style.blendMode;
  25228. },function(value){
  25229. this._setBlendMode(value);
  25230. this.getStyle().blendMode=value;
  25231. if (value && value !="source-over")this._renderType |=/*laya.display.SpriteConst.BLEND*/0x04;
  25232. else this._renderType &=~ /*laya.display.SpriteConst.BLEND*/0x04;
  25233. this._setRenderType(this._renderType);
  25234. this.parentRepaint();
  25235. });
  25236. /**X轴缩放值,默认值为1。设置为负数,可以实现水平反转效果,比如scaleX=-1。*/
  25237. __getset(0,__proto,'scaleX',function(){
  25238. return this._style.scaleX;
  25239. },function(value){
  25240. var style=this.getStyle();
  25241. if (style.scaleX!==value){
  25242. this._setScaleX(value);
  25243. this._setTranformChange();
  25244. }
  25245. });
  25246. /**Y轴缩放值,默认值为1。设置为负数,可以实现垂直反转效果,比如scaleX=-1。*/
  25247. __getset(0,__proto,'scaleY',function(){
  25248. return this._style.scaleY;
  25249. },function(value){
  25250. var style=this.getStyle();
  25251. if (style.scaleY!==value){
  25252. this._setScaleY(value);
  25253. this._setTranformChange();
  25254. }
  25255. });
  25256. /**对舞台 <code>stage</code> 的引用。*/
  25257. __getset(0,__proto,'stage',function(){
  25258. return Laya.stage;
  25259. });
  25260. /**水平倾斜角度,默认值为0。以角度为单位。*/
  25261. __getset(0,__proto,'skewX',function(){
  25262. return this._style.skewX;
  25263. },function(value){
  25264. var style=this.getStyle();
  25265. if (style.skewX!==value){
  25266. this._setSkewX(value);
  25267. this._setTranformChange();
  25268. }
  25269. });
  25270. /**
  25271. *<p>显示对象的滚动矩形范围,具有裁剪效果(如果只想限制子对象渲染区域,请使用viewport)</p>
  25272. *<p> srollRect和viewport的区别:<br/>
  25273. *1.srollRect自带裁剪效果,viewport只影响子对象渲染是否渲染,不具有裁剪效果(性能更高)。<br/>
  25274. *2.设置rect的x,y属性均能实现区域滚动效果,但scrollRect会保持0,0点位置不变。</p>
  25275. */
  25276. __getset(0,__proto,'scrollRect',function(){
  25277. return this._style.scrollRect;
  25278. },function(value){
  25279. this.getStyle().scrollRect=value;
  25280. this._setScrollRect(value);
  25281. this.repaint();
  25282. if (value){
  25283. this._renderType |=/*laya.display.SpriteConst.CLIP*/0x40;
  25284. }else {
  25285. this._renderType &=~ /*laya.display.SpriteConst.CLIP*/0x40;
  25286. }
  25287. this._setRenderType(this._renderType);
  25288. });
  25289. /**垂直倾斜角度,默认值为0。以角度为单位。*/
  25290. __getset(0,__proto,'skewY',function(){
  25291. return this._style.skewY;
  25292. },function(value){
  25293. var style=this.getStyle();
  25294. if (style.skewY!==value){
  25295. this._setSkewY(value);
  25296. this._setTranformChange();
  25297. }
  25298. });
  25299. /**
  25300. *<p>对象的矩阵信息。通过设置矩阵可以实现节点旋转,缩放,位移效果。</p>
  25301. *<p>矩阵更多信息请参考 <code>Matrix</code></p>
  25302. */
  25303. __getset(0,__proto,'transform',function(){
  25304. return this._tfChanged ? this._adjustTransform():this._transform;
  25305. },function(value){
  25306. this._tfChanged=false;
  25307. var m=this._transform || (this._transform=this._createTransform());
  25308. value.copyTo(m);
  25309. this._setTransform(m);
  25310. if (value){
  25311. this._x=m.tx;
  25312. this._y=m.ty;
  25313. m.tx=m.ty=0;
  25314. }
  25315. if (value)this._renderType |=/*laya.display.SpriteConst.TRANSFORM*/0x02;
  25316. else {
  25317. this._renderType &=~ /*laya.display.SpriteConst.TRANSFORM*/0x02;
  25318. }
  25319. this._setRenderType(this._renderType);
  25320. this.parentRepaint();
  25321. });
  25322. /**X轴 轴心点的位置,单位为像素,默认为0。轴心点会影响对象位置,缩放中心,旋转中心。*/
  25323. __getset(0,__proto,'pivotX',function(){
  25324. return this._getPivotX();
  25325. },function(value){
  25326. this._setPivotX(value);
  25327. this.repaint();
  25328. });
  25329. /**Y轴 轴心点的位置,单位为像素,默认为0。轴心点会影响对象位置,缩放中心,旋转中心。*/
  25330. __getset(0,__proto,'pivotY',function(){
  25331. return this._getPivotY();
  25332. },function(value){
  25333. this._setPivotY(value);
  25334. this.repaint();
  25335. });
  25336. /**透明度,值为0-1,默认值为1,表示不透明。更改alpha值会影响drawcall。*/
  25337. __getset(0,__proto,'alpha',function(){
  25338. return this._getAlpha();
  25339. },function(value){
  25340. value=value < 0 ? 0 :(value > 1 ? 1 :value);
  25341. this._setAlpha(value);
  25342. });
  25343. /**表示是否可见,默认为true。如果设置不可见,节点将不被渲染。*/
  25344. __getset(0,__proto,'visible',function(){
  25345. return this._visible;
  25346. },function(value){
  25347. if (this._visible!==value){
  25348. this._visible=value;
  25349. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_ALL*/0x03);
  25350. }
  25351. });
  25352. /**绘图对象。封装了绘制位图和矢量图的接口,Sprite所有的绘图操作都通过Graphics来实现的。*/
  25353. __getset(0,__proto,'graphics',function(){
  25354. if (!this._graphics){
  25355. this.graphics=new Graphics();
  25356. this._graphics.autoDestroy=true;
  25357. }
  25358. return this._graphics;
  25359. },function(value){
  25360. if (this._graphics)this._graphics._sp=null;
  25361. this._graphics=value;
  25362. if (value){
  25363. this._setGraphics(value);
  25364. this._renderType |=/*laya.display.SpriteConst.GRAPHICS*/0x200;
  25365. value._sp=this;
  25366. }else {
  25367. this._renderType &=~ /*laya.display.SpriteConst.GRAPHICS*/0x200;
  25368. }
  25369. this._setRenderType(this._renderType);
  25370. this.repaint();
  25371. });
  25372. /**滤镜集合。可以设置多个滤镜组合。*/
  25373. __getset(0,__proto,'filters',function(){
  25374. return this._cacheStyle.filters;
  25375. },function(value){
  25376. value && value.length===0 && (value=null);
  25377. if (this._cacheStyle.filters==value)return;
  25378. this._getCacheStyle().filters=value ? value.slice():null;
  25379. if (value && value.length){
  25380. this._setColorFilter(value[0]);
  25381. this._renderType |=/*laya.display.SpriteConst.FILTERS*/0x10;
  25382. }else {
  25383. this._setColorFilter(null);
  25384. this._renderType &=~ /*laya.display.SpriteConst.FILTERS*/0x10;
  25385. }
  25386. this._setRenderType(this._renderType);
  25387. if (value && value.length > 0){
  25388. if (!this._getBit(/*laya.Const.DISPLAY*/0x10))this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  25389. if (!(value.length==1 && (((value[0])instanceof laya.filters.ColorFilter )))){
  25390. this._getCacheStyle().cacheForFilters=true;
  25391. this._checkCanvasEnable();
  25392. }
  25393. }else {
  25394. if (this._cacheStyle.cacheForFilters){
  25395. this._cacheStyle.cacheForFilters=false;
  25396. this._checkCanvasEnable();
  25397. }
  25398. }
  25399. this._getCacheStyle().hasGlowFilter=this._isHaveGlowFilter();
  25400. this.repaint();
  25401. });
  25402. /**
  25403. *<p>遮罩,可以设置一个对象(支持位图和矢量图),根据对象形状进行遮罩显示。</p>
  25404. *<p>【注意】遮罩对象坐标系是相对遮罩对象本身的,和Flash机制不同</p>
  25405. */
  25406. __getset(0,__proto,'mask',function(){
  25407. return this._cacheStyle.mask;
  25408. },function(value){
  25409. if (value && this.mask && this.mask._cacheStyle.maskParent)return;
  25410. this._getCacheStyle().mask=value;
  25411. this._setMask(value);
  25412. this._checkCanvasEnable();
  25413. if (value){
  25414. value._getCacheStyle().maskParent=this;
  25415. }else {
  25416. if (this.mask){
  25417. this.mask._getCacheStyle().maskParent=null;
  25418. }
  25419. }
  25420. this._renderType |=/*laya.display.SpriteConst.MASK*/0x20;
  25421. this._setRenderType(this._renderType);
  25422. this.parentRepaint(/*laya.display.SpriteConst.REPAINT_ALL*/0x03);
  25423. });
  25424. /**
  25425. *是否接受鼠标事件。
  25426. *默认为false,如果监听鼠标事件,则会自动设置本对象及父节点的属性 mouseEnable 的值都为 true(如果父节点手动设置为false,则不会更改)。
  25427. **/
  25428. __getset(0,__proto,'mouseEnabled',function(){
  25429. return this._mouseState > 1;
  25430. },function(value){
  25431. this._mouseState=value ? 2 :1;
  25432. });
  25433. /**
  25434. *获得相对于stage的全局X轴缩放值(会叠加父亲节点的缩放值)。
  25435. */
  25436. __getset(0,__proto,'globalScaleX',function(){
  25437. var scale=1;
  25438. var ele=this;
  25439. while (ele){
  25440. if (ele===Laya.stage)break ;
  25441. scale *=ele.scaleX;
  25442. ele=ele.parent;
  25443. }
  25444. return scale;
  25445. });
  25446. /**
  25447. *返回鼠标在此对象坐标系上的 X 轴坐标信息。
  25448. */
  25449. __getset(0,__proto,'mouseX',function(){
  25450. return this.getMousePoint().x;
  25451. });
  25452. /**
  25453. *返回鼠标在此对象坐标系上的 Y 轴坐标信息。
  25454. */
  25455. __getset(0,__proto,'mouseY',function(){
  25456. return this.getMousePoint().y;
  25457. });
  25458. /**
  25459. *<p>视口大小,视口外的子对象,将不被渲染(如果想实现裁剪效果,请使用srollRect),合理使用能提高渲染性能。比如由一个个小图片拼成的地图块,viewport外面的小图片将不渲染</p>
  25460. *<p>srollRect和viewport的区别:<br/>
  25461. *1. srollRect自带裁剪效果,viewport只影响子对象渲染是否渲染,不具有裁剪效果(性能更高)。<br/>
  25462. *2. 设置rect的x,y属性均能实现区域滚动效果,但scrollRect会保持0,0点位置不变。</p>
  25463. *@default null
  25464. */
  25465. __getset(0,__proto,'viewport',function(){
  25466. return this._style.viewport;
  25467. },function(value){
  25468. if ((typeof value=='string')){
  25469. var recArr;
  25470. recArr=(value).split(",");
  25471. if (recArr.length > 3){
  25472. value=new Rectangle(parseFloat(recArr[0]),parseFloat(recArr[1]),parseFloat(recArr[2]),parseFloat(recArr[3]));
  25473. }
  25474. }
  25475. this.getStyle().viewport=value;
  25476. });
  25477. Sprite.fromImage=function(url){
  25478. return new Sprite().loadImage(url);
  25479. }
  25480. return Sprite;
  25481. })(Node)
  25482. /**
  25483. *...
  25484. *@author ...
  25485. */
  25486. //class laya.webgl.shader.BaseShader extends laya.resource.Resource
  25487. var BaseShader=(function(_super){
  25488. //当前绑定的shader
  25489. function BaseShader(){
  25490. BaseShader.__super.call(this);
  25491. }
  25492. __class(BaseShader,'laya.webgl.shader.BaseShader',_super);
  25493. BaseShader.activeShader=null;
  25494. BaseShader.bindShader=null;
  25495. return BaseShader;
  25496. })(Resource)
  25497. /**
  25498. *@private
  25499. *<code>Bitmap</code> 图片资源类。
  25500. */
  25501. //class laya.resource.Bitmap extends laya.resource.Resource
  25502. var Bitmap=(function(_super){
  25503. function Bitmap(){
  25504. /**@private */
  25505. //this._width=0;
  25506. /**@private */
  25507. //this._height=0;
  25508. Bitmap.__super.call(this);
  25509. this._width=-1;
  25510. this._height=-1;
  25511. }
  25512. __class(Bitmap,'laya.resource.Bitmap',_super);
  25513. var __proto=Bitmap.prototype;
  25514. //TODO:coverage
  25515. __proto._getSource=function(){
  25516. throw "Bitmap: must override it.";
  25517. }
  25518. /**
  25519. *获取宽度。
  25520. */
  25521. __getset(0,__proto,'width',function(){
  25522. return this._width;
  25523. });
  25524. /***
  25525. *获取高度。
  25526. */
  25527. __getset(0,__proto,'height',function(){
  25528. return this._height;
  25529. });
  25530. return Bitmap;
  25531. })(Resource)
  25532. //class laya.webgl.text.TextTexture extends laya.resource.Resource
  25533. var TextTexture=(function(_super){
  25534. function TextTexture(textureW,textureH){
  25535. this._source=null;
  25536. // webgl 贴图
  25537. this._texW=0;
  25538. this._texH=0;
  25539. this.__destroyed=false;
  25540. //父类有,但是private
  25541. this._discardTm=0;
  25542. //释放的时间。超过一定时间会被真正删除
  25543. this.genID=0;
  25544. // 这个对象会重新利用,为了能让引用他的人知道自己引用的是否有效,加个id
  25545. this.bitmap={id:0,_glTexture:null};
  25546. //samekey的判断用的
  25547. this.curUsedCovRate=0;
  25548. // 当前使用到的使用率。根据面积算的
  25549. this.curUsedCovRateAtlas=0;
  25550. // 大图集中的占用率。由于大图集分辨率低,所以会浪费一些空间
  25551. this.lastTouchTm=0;
  25552. this.ri=null;
  25553. TextTexture.__super.call(this);
  25554. this._texW=textureW || TextRender.atlasWidth;
  25555. this._texH=textureH || TextRender.atlasWidth;
  25556. this.bitmap.id=this.id;
  25557. this.lock=true;
  25558. }
  25559. __class(TextTexture,'laya.webgl.text.TextTexture',_super);
  25560. var __proto=TextTexture.prototype;
  25561. //防止被资源管理清除
  25562. __proto.recreateResource=function(){
  25563. if (this._source)
  25564. return;
  25565. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  25566. var glTex=this._source=gl.createTexture();
  25567. this.bitmap._glTexture=glTex;
  25568. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,glTex);
  25569. 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);
  25570. gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  25571. gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_MAG_FILTER*/0x2800,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  25572. gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
  25573. gl.texParameteri(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
  25574. if (TextRender.debugUV){
  25575. this.fillWhite();
  25576. }
  25577. }
  25578. /**
  25579. *
  25580. *@param data
  25581. *@param x 拷贝位置。
  25582. *@param y
  25583. *@param uv
  25584. *@return uv数组 如果uv不为空就返回传入的uv,否则new一个数组
  25585. */
  25586. __proto.addChar=function(data,x,y,uv){
  25587. if(TextRender.isWan1Wan){
  25588. return this.addCharCanvas(data ,x,y,uv);
  25589. }
  25590. !this._source && this.recreateResource();
  25591. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  25592. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,this._source);
  25593. !Render.isConchApp && gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,true);
  25594. var dt=data.data;
  25595. if (/*__JS__ */data.data instanceof Uint8ClampedArray)
  25596. dt=new Uint8Array(dt.buffer);
  25597. 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);
  25598. !Render.isConchApp && gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,false);
  25599. var u0=NaN;
  25600. var v0=NaN;
  25601. var u1=NaN;
  25602. var v1=NaN;
  25603. if(Render.isConchApp){
  25604. u0=x / this._texW;
  25605. v0=y / this._texH;
  25606. u1=(x+data.width)/ this._texW;
  25607. v1=(y+data.height)/ this._texH;
  25608. }else{
  25609. u0=(x+1)/ this._texW;
  25610. v0=(y)/ this._texH;
  25611. u1=(x+data.width-1)/ this._texW;
  25612. v1=(y+data.height-1)/ this._texH;
  25613. }
  25614. uv=uv || new Array(8);
  25615. uv[0]=u0,uv[1]=v0;
  25616. uv[2]=u1,uv[3]=v0;
  25617. uv[4]=u1,uv[5]=v1;
  25618. uv[6]=u0,uv[7]=v1;
  25619. return uv;
  25620. }
  25621. /**
  25622. *玩一玩不支持 getImageData
  25623. *@param canv
  25624. *@param x
  25625. *@param y
  25626. */
  25627. __proto.addCharCanvas=function(canv,x,y,uv){
  25628. !this._source && this.recreateResource();
  25629. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  25630. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,this._source);
  25631. !Render.isConchApp && gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,true);
  25632. gl.texSubImage2D(/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,0,x,y,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,canv);
  25633. !Render.isConchApp && gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,false);
  25634. var u0=NaN;
  25635. var v0=NaN;
  25636. var u1=NaN;
  25637. var v1=NaN;
  25638. if(Render.isConchApp){
  25639. u0=x / this._texW;
  25640. v0=y / this._texH;
  25641. u1=(x+canv.width)/ this._texW;
  25642. v1=(y+canv.height)/ this._texH;
  25643. }else{
  25644. u0=(x+1)/ this._texW;
  25645. v0=(y+1)/ this._texH;
  25646. u1=(x+canv.width-1)/ this._texW;
  25647. v1=(y+canv.height-1)/ this._texH;
  25648. }
  25649. uv=uv || new Array(8);
  25650. uv[0]=u0,uv[1]=v0;
  25651. uv[2]=u1,uv[3]=v0;
  25652. uv[4]=u1,uv[5]=v1;
  25653. uv[6]=u0,uv[7]=v1;
  25654. return uv;
  25655. }
  25656. /**
  25657. *填充白色。调试用。
  25658. */
  25659. __proto.fillWhite=function(){
  25660. !this._source && this.recreateResource();
  25661. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  25662. var dt=new Uint8Array(this._texW *this._texH *4);
  25663. (dt).fill(0xff);
  25664. 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);
  25665. }
  25666. __proto.discard=function(){
  25667. if (this._texW !=TextRender.atlasWidth || this._texH !=TextRender.atlasWidth){
  25668. this.destroy();
  25669. return;
  25670. }
  25671. this.genID++;
  25672. if (TextTexture.poolLen >=TextTexture.pool.length){
  25673. TextTexture.pool=TextTexture.pool.concat(new Array(10));
  25674. }
  25675. this._discardTm=Laya.stage.getFrameTm();
  25676. TextTexture.pool[TextTexture.poolLen++]=this;
  25677. }
  25678. __proto.destroy=function(){
  25679. this.__destroyed=true;
  25680. var gl=Render.isConchApp?LayaGL.instance.getDefaultCommandEncoder():WebGL.mainContext;
  25681. this._source && gl.deleteTexture(this._source);
  25682. this._source=null;
  25683. }
  25684. __proto.touchRect=function(ri,curloop){
  25685. if (this.lastTouchTm !=curloop){
  25686. this.curUsedCovRate=0;
  25687. this.curUsedCovRateAtlas=0;
  25688. this.lastTouchTm=curloop;
  25689. };
  25690. var texw2=TextRender.atlasWidth *TextRender.atlasWidth;
  25691. var gridw2=TextAtlas.atlasGridW *TextAtlas.atlasGridW;
  25692. this.curUsedCovRate+=(ri.bmpWidth *ri.bmpHeight)/ texw2;
  25693. this.curUsedCovRateAtlas+=(Math.ceil(ri.bmpWidth / TextAtlas.atlasGridW)*Math.ceil(ri.bmpHeight / TextAtlas.atlasGridW))/ (texw2 / gridw2);
  25694. }
  25695. __proto._getSource=function(){
  25696. return this._source;
  25697. }
  25698. // for debug
  25699. __proto.drawOnScreen=function(x,y){}
  25700. // 为了与当前的文字渲染兼容的补丁
  25701. __getset(0,__proto,'texture',function(){
  25702. return this;
  25703. });
  25704. TextTexture.getTextTexture=function(w,h){
  25705. if (w !=TextRender.atlasWidth || w !=TextRender.atlasWidth)
  25706. return new TextTexture(w,h);
  25707. if (TextTexture.poolLen > 0){
  25708. var ret=TextTexture.pool[--TextTexture.poolLen];
  25709. if (TextTexture.poolLen > 0)
  25710. TextTexture.clean();
  25711. return ret;
  25712. }
  25713. return new TextTexture(w,h);
  25714. }
  25715. TextTexture.clean=function(){
  25716. var curtm=Laya.stage.getFrameTm();
  25717. if (TextTexture.cleanTm===0)TextTexture.cleanTm=curtm;
  25718. if (curtm-TextTexture.cleanTm >=TextRender.checkCleanTextureDt){
  25719. for (var i=0;i < TextTexture.poolLen;i++){
  25720. var p=TextTexture.pool[i];
  25721. if (curtm-p._discardTm >=TextRender.destroyUnusedTextureDt){
  25722. p.destroy();
  25723. TextTexture.pool[i]=TextTexture.pool[TextTexture.poolLen-1];
  25724. TextTexture.poolLen--;
  25725. i--;
  25726. }
  25727. }
  25728. TextTexture.cleanTm=curtm;
  25729. }
  25730. }
  25731. TextTexture.poolLen=0;
  25732. TextTexture.cleanTm=0;
  25733. __static(TextTexture,
  25734. ['pool',function(){return this.pool=new Array(10);}
  25735. ]);
  25736. return TextTexture;
  25737. })(Resource)
  25738. //class laya.webgl.utils.IndexBuffer2D extends laya.webgl.utils.Buffer2D
  25739. var IndexBuffer2D=(function(_super){
  25740. function IndexBuffer2D(bufferUsage){
  25741. this._uint16Array=null;
  25742. (bufferUsage===void 0)&& (bufferUsage=0x88e4);
  25743. IndexBuffer2D.__super.call(this);
  25744. this._bufferUsage=bufferUsage;
  25745. this._bufferType=/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893;
  25746. this._buffer=new ArrayBuffer(8);
  25747. }
  25748. __class(IndexBuffer2D,'laya.webgl.utils.IndexBuffer2D',_super);
  25749. var __proto=IndexBuffer2D.prototype;
  25750. __proto._checkArrayUse=function(){
  25751. this._uint16Array && (this._uint16Array=new Uint16Array(this._buffer));
  25752. }
  25753. __proto.getUint16Array=function(){
  25754. return this._uint16Array || (this._uint16Array=new Uint16Array(this._buffer));
  25755. }
  25756. /**
  25757. *@inheritDoc
  25758. */
  25759. __proto._bindForVAO=function(){
  25760. LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893,this._glBuffer);
  25761. }
  25762. /**
  25763. *@inheritDoc
  25764. */
  25765. __proto.bind=function(){
  25766. if (Buffer._bindedIndexBuffer!==this._glBuffer){
  25767. LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893,this._glBuffer);
  25768. Buffer._bindedIndexBuffer=this._glBuffer;
  25769. return true;
  25770. }
  25771. return false;
  25772. }
  25773. __proto.destory=function(){
  25774. this._uint16Array=null;
  25775. this._buffer=null;
  25776. }
  25777. __proto.disposeResource=function(){
  25778. this._disposeResource();
  25779. }
  25780. IndexBuffer2D.create=function(bufferUsage){
  25781. (bufferUsage===void 0)&& (bufferUsage=0x88e4);
  25782. return new IndexBuffer2D(bufferUsage);
  25783. }
  25784. return IndexBuffer2D;
  25785. })(Buffer2D)
  25786. /**
  25787. *@private
  25788. *web audio api方式播放声音的音轨控制
  25789. */
  25790. //class laya.media.webaudio.WebAudioSoundChannel extends laya.media.SoundChannel
  25791. var WebAudioSoundChannel=(function(_super){
  25792. function WebAudioSoundChannel(){
  25793. /**
  25794. *声音原始文件数据
  25795. */
  25796. this.audioBuffer=null;
  25797. /**
  25798. *gain节点
  25799. */
  25800. this.gain=null;
  25801. /**
  25802. *播放用的数据
  25803. */
  25804. this.bufferSource=null;
  25805. /**
  25806. *当前时间
  25807. */
  25808. this._currentTime=0;
  25809. /**
  25810. *当前音量
  25811. */
  25812. this._volume=1;
  25813. /**
  25814. *播放开始时的时间戳
  25815. */
  25816. this._startTime=0;
  25817. this._pauseTime=0;
  25818. this._onPlayEnd=null;
  25819. this.context=WebAudioSound.ctx;
  25820. WebAudioSoundChannel.__super.call(this);
  25821. this._onPlayEnd=Utils.bind(this.__onPlayEnd,this);
  25822. if (this.context["createGain"]){
  25823. this.gain=this.context["createGain"]();
  25824. }else {
  25825. this.gain=this.context["createGainNode"]();
  25826. }
  25827. }
  25828. __class(WebAudioSoundChannel,'laya.media.webaudio.WebAudioSoundChannel',_super);
  25829. var __proto=WebAudioSoundChannel.prototype;
  25830. /**
  25831. *播放声音
  25832. */
  25833. __proto.play=function(){
  25834. SoundManager.addChannel(this);
  25835. this.isStopped=false;
  25836. this._clearBufferSource();
  25837. if (!this.audioBuffer)return;
  25838. var context=this.context;
  25839. var gain=this.gain;
  25840. var bufferSource=context.createBufferSource();
  25841. this.bufferSource=bufferSource;
  25842. bufferSource.buffer=this.audioBuffer;
  25843. bufferSource.connect(gain);
  25844. if (gain)
  25845. gain.disconnect();
  25846. gain.connect(context.destination);
  25847. bufferSource.onended=this._onPlayEnd;
  25848. if (this.startTime >=this.duration)this.startTime=0;
  25849. this._startTime=Browser.now();
  25850. if (this.gain.gain.setTargetAtTime){
  25851. this.gain.gain.setTargetAtTime(this._volume,this.context.currentTime,0.001);
  25852. }else
  25853. this.gain.gain.value=this._volume;
  25854. if (this.loops==0){
  25855. bufferSource.loop=true;
  25856. }
  25857. if (bufferSource.playbackRate.setTargetAtTime){
  25858. bufferSource.playbackRate.setTargetAtTime(SoundManager.playbackRate,this.context.currentTime,0.001)
  25859. }else
  25860. bufferSource.playbackRate.value=SoundManager.playbackRate;
  25861. bufferSource.start(0,this.startTime);
  25862. this._currentTime=0;
  25863. }
  25864. __proto.__onPlayEnd=function(){
  25865. if (this.loops==1){
  25866. if (this.completeHandler){
  25867. Laya.timer.once(10,this,this.__runComplete,[this.completeHandler],false);
  25868. this.completeHandler=null;
  25869. }
  25870. this.stop();
  25871. this.event(/*laya.events.Event.COMPLETE*/"complete");
  25872. return;
  25873. }
  25874. if (this.loops > 0){
  25875. this.loops--;
  25876. }
  25877. this.startTime=0;
  25878. this.play();
  25879. }
  25880. __proto._clearBufferSource=function(){
  25881. if (this.bufferSource){
  25882. var sourceNode=this.bufferSource;
  25883. if (sourceNode.stop){
  25884. sourceNode.stop(0);
  25885. }else {
  25886. sourceNode.noteOff(0);
  25887. }
  25888. sourceNode.disconnect(0);
  25889. sourceNode.onended=null;
  25890. if (!WebAudioSoundChannel._tryCleanFailed)this._tryClearBuffer(sourceNode);
  25891. this.bufferSource=null;
  25892. }
  25893. }
  25894. __proto._tryClearBuffer=function(sourceNode){
  25895. if (!Browser.onMac){
  25896. try{
  25897. sourceNode.buffer=null;
  25898. }catch (e){
  25899. WebAudioSoundChannel._tryCleanFailed=true;
  25900. }
  25901. return;
  25902. }
  25903. try {sourceNode.buffer=WebAudioSound._miniBuffer;}catch (e){WebAudioSoundChannel._tryCleanFailed=true;}
  25904. }
  25905. /**
  25906. *停止播放
  25907. */
  25908. __proto.stop=function(){
  25909. _super.prototype.stop.call(this);
  25910. this._clearBufferSource();
  25911. this.audioBuffer=null;
  25912. if (this.gain)
  25913. this.gain.disconnect();
  25914. this.isStopped=true;
  25915. SoundManager.removeChannel(this);
  25916. this.completeHandler=null;
  25917. if (SoundManager.autoReleaseSound)
  25918. SoundManager.disposeSoundLater(this.url);
  25919. }
  25920. __proto.pause=function(){
  25921. if (!this.isStopped){
  25922. this._pauseTime=this.position;
  25923. }
  25924. this._clearBufferSource();
  25925. if (this.gain)
  25926. this.gain.disconnect();
  25927. this.isStopped=true;
  25928. SoundManager.removeChannel(this);
  25929. if (SoundManager.autoReleaseSound)
  25930. SoundManager.disposeSoundLater(this.url);
  25931. }
  25932. __proto.resume=function(){
  25933. this.startTime=this._pauseTime;
  25934. this.play();
  25935. }
  25936. /**
  25937. *获取当前播放位置
  25938. */
  25939. __getset(0,__proto,'position',function(){
  25940. if (this.bufferSource){
  25941. return (Browser.now()-this._startTime)/ 1000+this.startTime;
  25942. }
  25943. return 0;
  25944. });
  25945. __getset(0,__proto,'duration',function(){
  25946. if (this.audioBuffer){
  25947. return this.audioBuffer.duration;
  25948. }
  25949. return 0;
  25950. });
  25951. /**
  25952. *设置音量
  25953. */
  25954. /**
  25955. *获取音量
  25956. */
  25957. __getset(0,__proto,'volume',function(){
  25958. return this._volume;
  25959. },function(v){
  25960. this._volume=v;
  25961. if (this.isStopped){
  25962. return;
  25963. }
  25964. if (this.gain.gain.setTargetAtTime){
  25965. this.gain.gain.setTargetAtTime(v,this.context.currentTime,0.001);
  25966. }else
  25967. this.gain.gain.value=v;
  25968. });
  25969. WebAudioSoundChannel._tryCleanFailed=false;
  25970. WebAudioSoundChannel.SetTargetDelay=0.001;
  25971. return WebAudioSoundChannel;
  25972. })(SoundChannel)
  25973. /**
  25974. *@private
  25975. *audio标签播放声音的音轨控制
  25976. */
  25977. //class laya.media.h5audio.AudioSoundChannel extends laya.media.SoundChannel
  25978. var AudioSoundChannel=(function(_super){
  25979. function AudioSoundChannel(audio){
  25980. /**
  25981. *播放用的audio标签
  25982. */
  25983. this._audio=null;
  25984. this._onEnd=null;
  25985. this._resumePlay=null;
  25986. AudioSoundChannel.__super.call(this);
  25987. this._onEnd=Utils.bind(this.__onEnd,this);
  25988. this._resumePlay=Utils.bind(this.__resumePlay,this);
  25989. audio.addEventListener("ended",this._onEnd);
  25990. this._audio=audio;
  25991. }
  25992. __class(AudioSoundChannel,'laya.media.h5audio.AudioSoundChannel',_super);
  25993. var __proto=AudioSoundChannel.prototype;
  25994. __proto.__onEnd=function(){
  25995. if (this.loops==1){
  25996. if (this.completeHandler){
  25997. Laya.systemTimer.once(10,this,this.__runComplete,[this.completeHandler],false);
  25998. this.completeHandler=null;
  25999. }
  26000. this.stop();
  26001. this.event(/*laya.events.Event.COMPLETE*/"complete");
  26002. return;
  26003. }
  26004. if (this.loops > 0){
  26005. this.loops--;
  26006. }
  26007. this.startTime=0;
  26008. this.play();
  26009. }
  26010. __proto.__resumePlay=function(){
  26011. if (this._audio)this._audio.removeEventListener("canplay",this._resumePlay);
  26012. if (this.isStopped)return;
  26013. try {
  26014. this._audio.currentTime=this.startTime;
  26015. Browser.container.appendChild(this._audio);
  26016. this._audio.play();
  26017. }catch (e){
  26018. this.event(/*laya.events.Event.ERROR*/"error");
  26019. }
  26020. }
  26021. /**
  26022. *播放
  26023. */
  26024. __proto.play=function(){
  26025. this.isStopped=false;
  26026. try {
  26027. this._audio.playbackRate=SoundManager.playbackRate;
  26028. this._audio.currentTime=this.startTime;
  26029. }catch (e){
  26030. this._audio.addEventListener("canplay",this._resumePlay);
  26031. return;
  26032. }
  26033. SoundManager.addChannel(this);
  26034. Browser.container.appendChild(this._audio);
  26035. if("play" in this._audio)
  26036. this._audio.play();
  26037. }
  26038. /**
  26039. *停止播放
  26040. *
  26041. */
  26042. __proto.stop=function(){
  26043. _super.prototype.stop.call(this);
  26044. this.isStopped=true;
  26045. SoundManager.removeChannel(this);
  26046. this.completeHandler=null;
  26047. if (!this._audio)
  26048. return;
  26049. if ("pause" in this._audio)
  26050. if (Render.isConchApp){
  26051. this._audio.stop();
  26052. }
  26053. this._audio.pause();
  26054. this._audio.removeEventListener("ended",this._onEnd);
  26055. this._audio.removeEventListener("canplay",this._resumePlay);
  26056. if (!Browser.onIE){
  26057. if (this._audio!=AudioSound._musicAudio){
  26058. Pool.recover("audio:"+this.url,this._audio);
  26059. }
  26060. }
  26061. Browser.removeElement(this._audio);
  26062. this._audio=null;
  26063. }
  26064. __proto.pause=function(){
  26065. this.isStopped=true;
  26066. SoundManager.removeChannel(this);
  26067. if("pause" in this._audio)
  26068. this._audio.pause();
  26069. }
  26070. __proto.resume=function(){
  26071. if (!this._audio)
  26072. return;
  26073. this.isStopped=false;
  26074. SoundManager.addChannel(this);
  26075. if("play" in this._audio)
  26076. this._audio.play();
  26077. }
  26078. /**
  26079. *当前播放到的位置
  26080. *@return
  26081. *
  26082. */
  26083. __getset(0,__proto,'position',function(){
  26084. if (!this._audio)
  26085. return 0;
  26086. return this._audio.currentTime;
  26087. });
  26088. /**
  26089. *获取总时间。
  26090. */
  26091. __getset(0,__proto,'duration',function(){
  26092. if (!this._audio)
  26093. return 0;
  26094. return this._audio.duration;
  26095. });
  26096. /**
  26097. *设置音量
  26098. *@param v
  26099. *
  26100. */
  26101. /**
  26102. *获取音量
  26103. *@return
  26104. *
  26105. */
  26106. __getset(0,__proto,'volume',function(){
  26107. if (!this._audio)return 1;
  26108. return this._audio.volume;
  26109. },function(v){
  26110. if (!this._audio)return;
  26111. this._audio.volume=v;
  26112. });
  26113. return AudioSoundChannel;
  26114. })(SoundChannel)
  26115. //class laya.webgl.utils.VertexBuffer2D extends laya.webgl.utils.Buffer2D
  26116. var VertexBuffer2D=(function(_super){
  26117. function VertexBuffer2D(vertexStride,bufferUsage){
  26118. this._floatArray32=null;
  26119. this._uint32Array=null;
  26120. this._vertexStride=0;
  26121. VertexBuffer2D.__super.call(this);
  26122. this._vertexStride=vertexStride;
  26123. this._bufferUsage=bufferUsage;
  26124. this._bufferType=/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892;
  26125. this._buffer=new ArrayBuffer(8);
  26126. this._floatArray32=new Float32Array(this._buffer);
  26127. this._uint32Array=new Uint32Array(this._buffer);
  26128. }
  26129. __class(VertexBuffer2D,'laya.webgl.utils.VertexBuffer2D',_super);
  26130. var __proto=VertexBuffer2D.prototype;
  26131. __proto.getFloat32Array=function(){
  26132. return this._floatArray32;
  26133. }
  26134. /**
  26135. *在当前位置插入float数组。
  26136. *@param data
  26137. *@param pos
  26138. */
  26139. __proto.appendArray=function(data){
  26140. var oldoff=this._byteLength >> 2;
  26141. this.setByteLength(this._byteLength+data.length *4);
  26142. var vbdata=this.getFloat32Array();
  26143. vbdata.set(data,oldoff);
  26144. this._upload=true;
  26145. }
  26146. __proto._checkArrayUse=function(){
  26147. this._floatArray32 && (this._floatArray32=new Float32Array(this._buffer));
  26148. this._uint32Array && (this._uint32Array=new Uint32Array(this._buffer));
  26149. }
  26150. //只删除buffer,不disableVertexAttribArray
  26151. __proto.deleteBuffer=function(){
  26152. this._disposeResource();
  26153. }
  26154. /**
  26155. *@inheritDoc
  26156. */
  26157. __proto._bindForVAO=function(){
  26158. LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892,this._glBuffer);
  26159. }
  26160. /**
  26161. *@inheritDoc
  26162. */
  26163. __proto.bind=function(){
  26164. if (Buffer._bindedVertexBuffer!==this._glBuffer){
  26165. LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892,this._glBuffer);
  26166. Buffer._bindedVertexBuffer=this._glBuffer;
  26167. return true;
  26168. }
  26169. return false;
  26170. }
  26171. __proto.destroy=function(){
  26172. laya.webgl.utils.Buffer.prototype.destroy.call(this);
  26173. this._byteLength=0;
  26174. this._upload=true;
  26175. this._buffer=null;
  26176. this._floatArray32=null;
  26177. }
  26178. __getset(0,__proto,'vertexStride',function(){
  26179. return this._vertexStride;
  26180. });
  26181. VertexBuffer2D.create=function(vertexStride,bufferUsage){
  26182. (bufferUsage===void 0)&& (bufferUsage=0x88e8);
  26183. return new VertexBuffer2D(vertexStride,bufferUsage);
  26184. }
  26185. return VertexBuffer2D;
  26186. })(Buffer2D)
  26187. /**
  26188. *<p> <code>Text</code> 类用于创建显示对象以显示文本。</p>
  26189. *<p>
  26190. *注意:如果运行时系统找不到设定的字体,则用系统默认的字体渲染文字,从而导致显示异常。(通常电脑上显示正常,在一些移动端因缺少设置的字体而显示异常)。
  26191. *</p>
  26192. *@example
  26193. *package
  26194. *{
  26195. *import laya.display.Text;
  26196. *public class Text_Example
  26197. *{
  26198. *public function Text_Example()
  26199. *{
  26200. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  26201. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  26202. *onInit();
  26203. *}
  26204. *private function onInit():void
  26205. *{
  26206. *var text:Text=new Text();//创建一个 Text 类的实例对象 text 。
  26207. *text.text="这个是一个 Text 文本示例。";
  26208. *text.color="#008fff";//设置 text 的文本颜色。
  26209. *text.font="Arial";//设置 text 的文本字体。
  26210. *text.bold=true;//设置 text 的文本显示为粗体。
  26211. *text.fontSize=30;//设置 text 的字体大小。
  26212. *text.wordWrap=true;//设置 text 的文本自动换行。
  26213. *text.x=100;//设置 text 对象的属性 x 的值,用于控制 text 对象的显示位置。
  26214. *text.y=100;//设置 text 对象的属性 y 的值,用于控制 text 对象的显示位置。
  26215. *text.width=300;//设置 text 的宽度。
  26216. *text.height=200;//设置 text 的高度。
  26217. *text.italic=true;//设置 text 的文本显示为斜体。
  26218. *text.borderColor="#fff000";//设置 text 的文本边框颜色。
  26219. *Laya.stage.addChild(text);//将 text 添加到显示列表。
  26220. *}
  26221. *}
  26222. *}
  26223. *@example
  26224. *Text_Example();
  26225. *function Text_Example()
  26226. *{
  26227. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  26228. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  26229. *onInit();
  26230. *}
  26231. *function onInit()
  26232. *{
  26233. *var text=new laya.display.Text();//创建一个 Text 类的实例对象 text 。
  26234. *text.text="这个是一个 Text 文本示例。";
  26235. *text.color="#008fff";//设置 text 的文本颜色。
  26236. *text.font="Arial";//设置 text 的文本字体。
  26237. *text.bold=true;//设置 text 的文本显示为粗体。
  26238. *text.fontSize=30;//设置 text 的字体大小。
  26239. *text.wordWrap=true;//设置 text 的文本自动换行。
  26240. *text.x=100;//设置 text 对象的属性 x 的值,用于控制 text 对象的显示位置。
  26241. *text.y=100;//设置 text 对象的属性 y 的值,用于控制 text 对象的显示位置。
  26242. *text.width=300;//设置 text 的宽度。
  26243. *text.height=200;//设置 text 的高度。
  26244. *text.italic=true;//设置 text 的文本显示为斜体。
  26245. *text.borderColor="#fff000";//设置 text 的文本边框颜色。
  26246. *Laya.stage.addChild(text);//将 text 添加到显示列表。
  26247. *}
  26248. *@example
  26249. *class Text_Example {
  26250. *constructor(){
  26251. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  26252. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  26253. *this.onInit();
  26254. *}
  26255. *private onInit():void {
  26256. *var text:laya.display.Text=new laya.display.Text();//创建一个 Text 类的实例对象 text 。
  26257. *text.text="这个是一个 Text 文本示例。";
  26258. *text.color="#008fff";//设置 text 的文本颜色。
  26259. *text.font="Arial";//设置 text 的文本字体。
  26260. *text.bold=true;//设置 text 的文本显示为粗体。
  26261. *text.fontSize=30;//设置 text 的字体大小。
  26262. *text.wordWrap=true;//设置 text 的文本自动换行。
  26263. *text.x=100;//设置 text 对象的属性 x 的值,用于控制 text 对象的显示位置。
  26264. *text.y=100;//设置 text 对象的属性 y 的值,用于控制 text 对象的显示位置。
  26265. *text.width=300;//设置 text 的宽度。
  26266. *text.height=200;//设置 text 的高度。
  26267. *text.italic=true;//设置 text 的文本显示为斜体。
  26268. *text.borderColor="#fff000";//设置 text 的文本边框颜色。
  26269. *Laya.stage.addChild(text);//将 text 添加到显示列表。
  26270. *}
  26271. *}
  26272. */
  26273. //class laya.display.Text extends laya.display.Sprite
  26274. var Text=(function(_super){
  26275. function Text(){
  26276. /**@private */
  26277. this._clipPoint=null;
  26278. /**@private 表示文本内容字符串。*/
  26279. this._text=null;
  26280. /**@private 表示文本内容是否发生改变。*/
  26281. this._isChanged=false;
  26282. /**@private 表示文本的宽度,以像素为单位。*/
  26283. this._textWidth=0;
  26284. /**@private 表示文本的高度,以像素为单位。*/
  26285. this._textHeight=0;
  26286. /**@private 存储文字行数信息。*/
  26287. this._lines=[];
  26288. /**@private 保存每行宽度*/
  26289. this._lineWidths=[];
  26290. /**@private 文本的内容位置 X 轴信息。*/
  26291. this._startX=0;
  26292. /**@private 文本的内容位置X轴信息。 */
  26293. this._startY=0;
  26294. /**@private */
  26295. this._words=null;
  26296. /**@private */
  26297. this._charSize={};
  26298. /**@private */
  26299. this._valign="top";
  26300. /**@private */
  26301. this._color="#000000";
  26302. /**@private */
  26303. this._singleCharRender=false;
  26304. Text.__super.call(this);
  26305. this._fontSize=Text.defaultFontSize;
  26306. this._font=Text.defaultFont;
  26307. this.overflow="visible";
  26308. this._style=TextStyle.EMPTY;
  26309. }
  26310. __class(Text,'laya.display.Text',_super);
  26311. var __proto=Text.prototype;
  26312. /**
  26313. *@private
  26314. *获取样式。
  26315. *@return 样式 Style 。
  26316. */
  26317. __proto.getStyle=function(){
  26318. this._style===TextStyle.EMPTY && (this._style=TextStyle.create());
  26319. return this._style;
  26320. }
  26321. __proto._getTextStyle=function(){
  26322. if (this._style===TextStyle.EMPTY){
  26323. this._style=TextStyle.create();
  26324. }
  26325. return this._style;
  26326. }
  26327. /**@inheritDoc */
  26328. __proto.destroy=function(destroyChild){
  26329. (destroyChild===void 0)&& (destroyChild=true);
  26330. _super.prototype.destroy.call(this,destroyChild);
  26331. this._clipPoint=null;
  26332. this._lines=null;
  26333. this._lineWidths=null;
  26334. this._words && this._words.forEach(function(w){
  26335. w.cleanCache();
  26336. });
  26337. this._words=null;
  26338. this._charSize=null;
  26339. }
  26340. /**
  26341. *@private
  26342. *@inheritDoc
  26343. */
  26344. __proto._getBoundPointsM=function(ifRotate){
  26345. (ifRotate===void 0)&& (ifRotate=false);
  26346. var rec=Rectangle.TEMP;
  26347. rec.setTo(0,0,this.width,this.height);
  26348. return rec._getBoundPoints();
  26349. }
  26350. /**
  26351. *@inheritDoc
  26352. */
  26353. __proto.getGraphicBounds=function(realSize){
  26354. (realSize===void 0)&& (realSize=false);
  26355. var rec=Rectangle.TEMP;
  26356. rec.setTo(0,0,this.width,this.height);
  26357. return rec;
  26358. }
  26359. /**
  26360. *@private
  26361. */
  26362. __proto._getCSSStyle=function(){
  26363. return this._style;
  26364. }
  26365. /**
  26366. *<p>根据指定的文本,从语言包中取当前语言的文本内容。并对此文本中的{i}文本进行替换。</p>
  26367. *<p>设置Text.langPacks语言包后,即可使用lang获取里面的语言</p>
  26368. *<p>例如:
  26369. *<li>(1)text 的值为“我的名字”,先取到这个文本对应的当前语言版本里的值“My name”,将“My name”设置为当前文本的内容。</li>
  26370. *<li>(2)text 的值为“恭喜你赢得{0}个钻石,{1}经验。”,arg1 的值为100,arg2 的值为200。
  26371. *则先取到这个文本对应的当前语言版本里的值“Congratulations on your winning {0}diamonds,{1}experience.”,
  26372. *然后将文本里的{0}、{1},依据括号里的数字从0开始替换为 arg1、arg2 的值。
  26373. *将替换处理后的文本“Congratulations on your winning 100 diamonds,200 experience.”设置为当前文本的内容。
  26374. *</li>
  26375. *</p>
  26376. *@param text 文本内容。
  26377. *@param ...args 文本替换参数。
  26378. */
  26379. __proto.lang=function(text,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10){
  26380. text=Text.langPacks && Text.langPacks[text] ? Text.langPacks[text] :text;
  26381. if (arguments.length < 2){
  26382. this._text=text;
  26383. }else {
  26384. for (var i=0,n=arguments.length;i < n;i++){
  26385. text=text.replace("{"+i+"}",arguments[i+1]);
  26386. }
  26387. this._text=text;
  26388. }
  26389. }
  26390. /**
  26391. *@private
  26392. */
  26393. __proto._getContextFont=function(){
  26394. return (this.italic ? "italic " :"")+(this.bold ? "bold " :"")+this.fontSize+"px "+(Browser.onIPhone ? (laya.display.Text.fontFamilyMap[this.font] || this.font):this.font);
  26395. }
  26396. /**
  26397. *@private
  26398. */
  26399. __proto._isPassWordMode=function(){
  26400. var style=this._style;
  26401. var password=style.asPassword;
  26402. if (("prompt" in this)&& this['prompt']==this._text)
  26403. password=false;
  26404. return password;
  26405. }
  26406. /**
  26407. *@private
  26408. */
  26409. __proto._getPassWordTxt=function(txt){
  26410. var len=txt.length;
  26411. var word;
  26412. word="";
  26413. for (var j=len;j > 0;j--){
  26414. word+="●";
  26415. }
  26416. return word;
  26417. }
  26418. /**
  26419. *@private
  26420. *渲染文字。
  26421. *@param begin 开始渲染的行索引。
  26422. *@param visibleLineCount 渲染的行数。
  26423. */
  26424. __proto._renderText=function(){
  26425. var padding=this.padding;
  26426. var visibleLineCount=this._lines.length;
  26427. if (this.overflow !="visible"){
  26428. visibleLineCount=Math.min(visibleLineCount,Math.floor((this.height-padding[0]-padding[2])/ (this.leading+this._charSize.height))+1);
  26429. };
  26430. var beginLine=this.scrollY / (this._charSize.height+this.leading)| 0;
  26431. var graphics=this.graphics;
  26432. graphics.clear(true);
  26433. var ctxFont=this._getContextFont();
  26434. Browser.context.font=ctxFont;
  26435. var startX=padding[3];
  26436. var textAlgin="left";
  26437. var lines=this._lines;
  26438. var lineHeight=this.leading+this._charSize.height;
  26439. var tCurrBitmapFont=(this._style).currBitmapFont;
  26440. if (tCurrBitmapFont){
  26441. lineHeight=this.leading+tCurrBitmapFont.getMaxHeight();
  26442. };
  26443. var startY=padding[0];
  26444. if ((!tCurrBitmapFont)&& this._width > 0 && this._textWidth <=this._width){
  26445. if (this.align=="right"){
  26446. textAlgin="right";
  26447. startX=this._width-padding[1];
  26448. }else if (this.align=="center"){
  26449. textAlgin="center";
  26450. startX=this._width *0.5+padding[3]-padding[1];
  26451. }
  26452. }
  26453. if (this._height > 0){
  26454. var tempVAlign=(this._textHeight > this._height)? "top" :this.valign;
  26455. if (tempVAlign==="middle")
  26456. startY=(this._height-visibleLineCount *lineHeight)*0.5+padding[0]-padding[2];
  26457. else if (tempVAlign==="bottom")
  26458. startY=this._height-visibleLineCount *lineHeight-padding[2];
  26459. };
  26460. var style=this._style;
  26461. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize){
  26462. var bitmapScale=tCurrBitmapFont.fontSize / this.fontSize;
  26463. }
  26464. if (this._clipPoint){
  26465. graphics.save();
  26466. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize){
  26467. var tClipWidth=0;
  26468. var tClipHeight=0;
  26469. this._width ? tClipWidth=(this._width-padding[3]-padding[1]):tClipWidth=this._textWidth;
  26470. this._height ? tClipHeight=(this._height-padding[0]-padding[2]):tClipHeight=this._textHeight;
  26471. tClipWidth *=bitmapScale;
  26472. tClipHeight *=bitmapScale;
  26473. graphics.clipRect(padding[3],padding[0],tClipWidth,tClipHeight);
  26474. }else {
  26475. 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);
  26476. }
  26477. this.repaint();
  26478. };
  26479. var password=style.asPassword;
  26480. if (("prompt" in this)&& this['prompt']==this._text)
  26481. password=false;
  26482. var x=0,y=0;
  26483. var end=Math.min(this._lines.length,visibleLineCount+beginLine)|| 1;
  26484. for (var i=beginLine;i < end;i++){
  26485. var word=lines[i];
  26486. var _word;
  26487. if (password){
  26488. var len=word.length;
  26489. word="";
  26490. for (var j=len;j > 0;j--){
  26491. word+="●";
  26492. }
  26493. }
  26494. if (word==null)word="";
  26495. x=startX-(this._clipPoint ? this._clipPoint.x :0);
  26496. y=startY+lineHeight *i-(this._clipPoint ? this._clipPoint.y :0);
  26497. this.underline && this._drawUnderline(textAlgin,x,y,i);
  26498. if (tCurrBitmapFont){
  26499. var tWidth=this.width;
  26500. if (tCurrBitmapFont.autoScaleSize){
  26501. tWidth=this.width *bitmapScale;
  26502. }
  26503. tCurrBitmapFont._drawText(word,this,x,y,this.align,tWidth);
  26504. }else {
  26505. this._words || (this._words=[]);
  26506. if (this._words.length > (i-beginLine)){
  26507. _word=this._words[i-beginLine];
  26508. }else {
  26509. _word=new WordText();
  26510. this._words.push(_word);
  26511. }
  26512. _word.setText(word);
  26513. (_word).splitRender=this._singleCharRender;
  26514. style.stroke ? graphics.fillBorderText(_word,x,y,ctxFont,this.color,style.strokeColor,style.stroke,textAlgin):graphics.fillText(_word,x,y,ctxFont,this.color,textAlgin);
  26515. }
  26516. }
  26517. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize){
  26518. var tScale=1 / bitmapScale;
  26519. this.scale(tScale,tScale);
  26520. }
  26521. if (this._clipPoint)graphics.restore();
  26522. this._startX=startX;
  26523. this._startY=startY;
  26524. }
  26525. /**
  26526. *@private
  26527. *绘制下划线
  26528. *@param x 本行坐标
  26529. *@param y 本行坐标
  26530. *@param lineIndex 本行索引
  26531. */
  26532. __proto._drawUnderline=function(align,x,y,lineIndex){
  26533. var lineWidth=this._lineWidths[lineIndex];
  26534. switch (align){
  26535. case 'center':
  26536. x-=lineWidth / 2;
  26537. break ;
  26538. case 'right':
  26539. x-=lineWidth;
  26540. break ;
  26541. case 'left':
  26542. default :
  26543. break ;
  26544. }
  26545. y+=this._charSize.height;
  26546. this._graphics.drawLine(x,y,x+lineWidth,y,this.underlineColor || this.color,1);
  26547. }
  26548. /**
  26549. *<p>排版文本。</p>
  26550. *<p>进行宽高计算,渲染、重绘文本。</p>
  26551. */
  26552. __proto.typeset=function(){
  26553. this._isChanged=false;
  26554. if (!this._text){
  26555. this._clipPoint=null;
  26556. this._textWidth=this._textHeight=0;
  26557. this.graphics.clear(true);
  26558. return;
  26559. }
  26560. if (Render.isConchApp){
  26561. /*__JS__ */window.conchTextCanvas.font=this._getContextFont();;
  26562. }else{
  26563. Browser.context.font=this._getContextFont();
  26564. }
  26565. this._lines.length=0;
  26566. this._lineWidths.length=0;
  26567. if (this._isPassWordMode()){
  26568. this._parseLines(this._getPassWordTxt(this._text));
  26569. }else
  26570. this._parseLines(this._text);
  26571. this._evalTextSize();
  26572. if (this._checkEnabledViewportOrNot())this._clipPoint || (this._clipPoint=new Point(0,0));
  26573. else this._clipPoint=null;
  26574. this._renderText();
  26575. }
  26576. /**@private */
  26577. __proto._evalTextSize=function(){
  26578. var nw=NaN,nh=NaN;
  26579. nw=Math.max.apply(this,this._lineWidths);
  26580. if ((this._style).currBitmapFont)
  26581. nh=this._lines.length *((this._style).currBitmapFont.getMaxHeight()+this.leading)+this.padding[0]+this.padding[2];
  26582. else
  26583. nh=this._lines.length *(this._charSize.height+this.leading)+this.padding[0]+this.padding[2];
  26584. if (nw !=this._textWidth || nh !=this._textHeight){
  26585. this._textWidth=nw;
  26586. this._textHeight=nh;
  26587. }
  26588. }
  26589. /**@private */
  26590. __proto._checkEnabledViewportOrNot=function(){
  26591. return this.overflow=="scroll" && ((this._width > 0 && this._textWidth > this._width)|| (this._height > 0 && this._textHeight > this._height));
  26592. }
  26593. /**
  26594. *<p>快速更改显示文本。不进行排版计算,效率较高。</p>
  26595. *<p>如果只更改文字内容,不更改文字样式,建议使用此接口,能提高效率。</p>
  26596. *@param text 文本内容。
  26597. */
  26598. __proto.changeText=function(text){
  26599. if (this._text!==text){
  26600. this.lang(text+"");
  26601. if (this._graphics && this._graphics.replaceText(this._text)){
  26602. }else {
  26603. this.typeset();
  26604. }
  26605. }
  26606. }
  26607. /**
  26608. *@private
  26609. *分析文本换行。
  26610. */
  26611. __proto._parseLines=function(text){
  26612. var needWordWrapOrTruncate=this.wordWrap || this.overflow=="hidden";
  26613. if (needWordWrapOrTruncate){
  26614. var wordWrapWidth=this._getWordWrapWidth();
  26615. };
  26616. var bitmapFont=(this._style).currBitmapFont;
  26617. if (bitmapFont){
  26618. this._charSize.width=bitmapFont.getMaxWidth();
  26619. this._charSize.height=bitmapFont.getMaxHeight();
  26620. }else {
  26621. var measureResult=null;
  26622. if (Render.isConchApp){
  26623. measureResult=/*__JS__ */window.conchTextCanvas.measureText(this._testWord);
  26624. }else {
  26625. measureResult=Browser.context.measureText(Text._testWord);
  26626. }
  26627. if (!measureResult)measureResult={width:100 };
  26628. this._charSize.width=measureResult.width;
  26629. this._charSize.height=(measureResult.height || this.fontSize);
  26630. };
  26631. var lines=text.replace(/\r\n/g,"\n").split("\n");
  26632. for (var i=0,n=lines.length;i < n;i++){
  26633. var line=lines[i];
  26634. if (needWordWrapOrTruncate)
  26635. this._parseLine(line,wordWrapWidth);
  26636. else {
  26637. this._lineWidths.push(this._getTextWidth(line));
  26638. this._lines.push(line);
  26639. }
  26640. }
  26641. }
  26642. /**
  26643. *@private
  26644. *解析行文本。
  26645. *@param line 某行的文本。
  26646. *@param wordWrapWidth 文本的显示宽度。
  26647. */
  26648. __proto._parseLine=function(line,wordWrapWidth){
  26649. var ctx=Browser.context;
  26650. var lines=this._lines;
  26651. var maybeIndex=0;
  26652. var execResult;
  26653. var charsWidth=NaN;
  26654. var wordWidth=NaN;
  26655. var startIndex=0;
  26656. charsWidth=this._getTextWidth(line);
  26657. if (charsWidth <=wordWrapWidth){
  26658. lines.push(line);
  26659. this._lineWidths.push(charsWidth);
  26660. return;
  26661. }
  26662. charsWidth=this._charSize.width;
  26663. maybeIndex=Math.floor(wordWrapWidth / charsWidth);
  26664. (maybeIndex==0)&& (maybeIndex=1);
  26665. charsWidth=this._getTextWidth(line.substring(0,maybeIndex));
  26666. wordWidth=charsWidth;
  26667. for (var j=maybeIndex,m=line.length;j < m;j++){
  26668. charsWidth=this._getTextWidth(line.charAt(j));
  26669. wordWidth+=charsWidth;
  26670. if (wordWidth > wordWrapWidth){
  26671. if (this.wordWrap){
  26672. var newLine=line.substring(startIndex,j);
  26673. if (newLine.charCodeAt(newLine.length-1)< 255){
  26674. execResult=/(?:\w|-)+$/.exec(newLine);
  26675. if (execResult){
  26676. j=execResult.index+startIndex;
  26677. if (execResult.index==0)j+=newLine.length;
  26678. else newLine=line.substring(startIndex,j);
  26679. }
  26680. }
  26681. lines.push(newLine);
  26682. this._lineWidths.push(wordWidth-charsWidth);
  26683. startIndex=j;
  26684. if (j+maybeIndex < m){
  26685. j+=maybeIndex;
  26686. charsWidth=this._getTextWidth(line.substring(startIndex,j));
  26687. wordWidth=charsWidth;
  26688. j--;
  26689. }else {
  26690. lines.push(line.substring(startIndex,m));
  26691. this._lineWidths.push(this._getTextWidth(lines[lines.length-1]));
  26692. startIndex=-1;
  26693. break ;
  26694. }
  26695. }else if (this.overflow=="hidden"){
  26696. lines.push(line.substring(0,j));
  26697. this._lineWidths.push(this._getTextWidth(lines[lines.length-1]));
  26698. return;
  26699. }
  26700. }
  26701. }
  26702. if (this.wordWrap && startIndex !=-1){
  26703. lines.push(line.substring(startIndex,m));
  26704. this._lineWidths.push(this._getTextWidth(lines[lines.length-1]));
  26705. }
  26706. }
  26707. /**@private */
  26708. __proto._getTextWidth=function(text){
  26709. var bitmapFont=(this._style).currBitmapFont;
  26710. if (bitmapFont)return bitmapFont.getTextWidth(text);
  26711. else {
  26712. if (Render.isConchApp){
  26713. return /*__JS__ */window.conchTextCanvas.measureText(text).width;;
  26714. }
  26715. else return Browser.context.measureText(text).width;
  26716. }
  26717. }
  26718. /**
  26719. *@private
  26720. *获取换行所需的宽度。
  26721. */
  26722. __proto._getWordWrapWidth=function(){
  26723. var p=this.padding;
  26724. var w=NaN;
  26725. var bitmapFont=(this._style).currBitmapFont;
  26726. if (bitmapFont && bitmapFont.autoScaleSize)w=this._width *(bitmapFont.fontSize / this.fontSize);
  26727. else w=this._width;
  26728. if (w <=0){
  26729. w=this.wordWrap ? 100 :Browser.width;
  26730. }
  26731. w <=0 && (w=100);
  26732. return w-p[3]-p[1];
  26733. }
  26734. /**
  26735. *返回字符在本类实例的父坐标系下的坐标。
  26736. *@param charIndex 索引位置。
  26737. *@param out (可选)输出的Point引用。
  26738. *@return Point 字符在本类实例的父坐标系下的坐标。如果out参数不为空,则将结果赋值给指定的Point对象,否则创建一个新的Point对象返回。建议使用Point.TEMP作为out参数,可以省去Point对象创建和垃圾回收的开销,尤其是在需要频繁执行的逻辑中,比如帧循环和MOUSE_MOVE事件回调函数里面。
  26739. */
  26740. __proto.getCharPoint=function(charIndex,out){
  26741. this._isChanged && Laya.systemTimer.runCallLater(this,this.typeset);
  26742. var len=0,lines=this._lines,startIndex=0;
  26743. for (var i=0,n=lines.length;i < n;i++){
  26744. len+=lines[i].length;
  26745. if (charIndex < len){
  26746. var line=i;
  26747. break ;
  26748. }
  26749. startIndex=len;
  26750. };
  26751. var ctxFont=(this.italic ? "italic " :"")+(this.bold ? "bold " :"")+this.fontSize+"px "+this.font;
  26752. Browser.context.font=ctxFont;
  26753. var width=this._getTextWidth(this._text.substring(startIndex,charIndex));
  26754. var point=out || new Point();
  26755. 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));
  26756. }
  26757. /**
  26758. *@inheritDoc
  26759. */
  26760. __getset(0,__proto,'width',function(){
  26761. if (this._width)return this._width;
  26762. return this.textWidth+this.padding[1]+this.padding[3];
  26763. },function(value){
  26764. if (value !=this._width){
  26765. Laya.superSet(Sprite,this,'width',value);
  26766. this.isChanged=true;
  26767. if (this.borderColor){
  26768. this._setBorderStyleColor(0,0,this.width,this.height,this.borderColor,1);
  26769. }
  26770. }
  26771. });
  26772. /**
  26773. *表示文本的宽度,以像素为单位。
  26774. */
  26775. __getset(0,__proto,'textWidth',function(){
  26776. this._isChanged && Laya.systemTimer.runCallLater(this,this.typeset);
  26777. return this._textWidth;
  26778. });
  26779. /**
  26780. *@inheritDoc
  26781. */
  26782. __getset(0,__proto,'height',function(){
  26783. if (this._height)return this._height;
  26784. return this.textHeight;
  26785. },function(value){
  26786. if (value !=this._height){
  26787. Laya.superSet(Sprite,this,'height',value);
  26788. this.isChanged=true;
  26789. if (this.borderColor){
  26790. this._setBorderStyleColor(0,0,this.width,this.height,this.borderColor,1);
  26791. }
  26792. }
  26793. });
  26794. /**
  26795. *表示文本的高度,以像素为单位。
  26796. */
  26797. __getset(0,__proto,'textHeight',function(){
  26798. this._isChanged && Laya.systemTimer.runCallLater(this,this.typeset);
  26799. return this._textHeight;
  26800. });
  26801. /**
  26802. *<p>边距信息。</p>
  26803. *<p>数据格式:[上边距,右边距,下边距,左边距](边距以像素为单位)。</p>
  26804. */
  26805. __getset(0,__proto,'padding',function(){
  26806. return (this._style).padding;
  26807. },function(value){
  26808. if ((typeof value=='string')){
  26809. var arr;
  26810. arr=(value).split(",");
  26811. var i=0,len=0;
  26812. len=arr.length;
  26813. while (arr.length < 4){
  26814. arr.push(0);
  26815. }
  26816. for (i=0;i < len;i++){
  26817. arr[i]=parseFloat(arr[i])|| 0;
  26818. }
  26819. value=arr;
  26820. }
  26821. this._getTextStyle().padding=value;
  26822. this.isChanged=true;
  26823. });
  26824. /**
  26825. *<p>指定文本是否为粗体字。</p>
  26826. *<p>默认值为 false,这意味着不使用粗体字。如果值为 true,则文本为粗体字。</p>
  26827. */
  26828. __getset(0,__proto,'bold',function(){
  26829. return (this._style).bold;
  26830. },function(value){
  26831. this._getTextStyle().bold=value;
  26832. this.isChanged=true;
  26833. });
  26834. /**当前文本的内容字符串。*/
  26835. __getset(0,__proto,'text',function(){
  26836. return this._text || "";
  26837. },function(value){
  26838. if (this._text!==value){
  26839. this.lang(value+"");
  26840. this.isChanged=true;
  26841. this.event(/*laya.events.Event.CHANGE*/"change");
  26842. if (this.borderColor){
  26843. this._setBorderStyleColor(0,0,this.width,this.height,this.borderColor,1);
  26844. }
  26845. }
  26846. });
  26847. /**
  26848. *<p>表示文本的颜色值。可以通过 <code>Text.defaultColor</code> 设置默认颜色。</p>
  26849. *<p>默认值为黑色。</p>
  26850. */
  26851. __getset(0,__proto,'color',function(){
  26852. return this._color;
  26853. },function(value){
  26854. if (this._color !=value){
  26855. this._color=value;
  26856. if (!this._isChanged && this._graphics){
  26857. this._graphics.replaceTextColor(this.color)
  26858. }else {
  26859. this.isChanged=true;
  26860. }
  26861. }
  26862. });
  26863. /**
  26864. *<p>文本的字体名称,以字符串形式表示。</p>
  26865. *<p>默认值为:"Arial",可以通过Text.defaultFont设置默认字体。</p>
  26866. *<p>如果运行时系统找不到设定的字体,则用系统默认的字体渲染文字,从而导致显示异常。(通常电脑上显示正常,在一些移动端因缺少设置的字体而显示异常)。</p>
  26867. *@see laya.display.Text#defaultFont
  26868. */
  26869. __getset(0,__proto,'font',function(){
  26870. return this._font;
  26871. },function(value){
  26872. if ((this._style).currBitmapFont){
  26873. this._getTextStyle().currBitmapFont=null;
  26874. this.scale(1,1);
  26875. }
  26876. if (Text._bitmapFonts && Text._bitmapFonts[value]){
  26877. this._getTextStyle().currBitmapFont=Text._bitmapFonts[value];
  26878. }
  26879. this._font=value;
  26880. this.isChanged=true;
  26881. });
  26882. /**
  26883. *<p>指定文本的字体大小(以像素为单位)。</p>
  26884. *<p>默认为20像素,可以通过 <code>Text.defaultFontSize</code> 设置默认大小。</p>
  26885. */
  26886. __getset(0,__proto,'fontSize',function(){
  26887. return this._fontSize;
  26888. },function(value){
  26889. if (this._fontSize !=value){
  26890. this._fontSize=value;
  26891. this.isChanged=true;
  26892. }
  26893. });
  26894. /**
  26895. *<p>表示使用此文本格式的文本是否为斜体。</p>
  26896. *<p>默认值为 false,这意味着不使用斜体。如果值为 true,则文本为斜体。</p>
  26897. */
  26898. __getset(0,__proto,'italic',function(){
  26899. return (this._style).italic;
  26900. },function(value){
  26901. this._getTextStyle().italic=value;
  26902. this.isChanged=true;
  26903. });
  26904. /**
  26905. *<p>表示文本的水平显示方式。</p>
  26906. *<p><b>取值:</b>
  26907. *<li>"left": 居左对齐显示。</li>
  26908. *<li>"center": 居中对齐显示。</li>
  26909. *<li>"right": 居右对齐显示。</li>
  26910. *</p>
  26911. */
  26912. __getset(0,__proto,'align',function(){
  26913. return (this._style).align;
  26914. },function(value){
  26915. this._getTextStyle().align=value;
  26916. this.isChanged=true;
  26917. });
  26918. /**
  26919. *<p>表示文本的垂直显示方式。</p>
  26920. *<p><b>取值:</b>
  26921. *<li>"top": 居顶部对齐显示。</li>
  26922. *<li>"middle": 居中对齐显示。</li>
  26923. *<li>"bottom": 居底部对齐显示。</li>
  26924. *</p>
  26925. */
  26926. __getset(0,__proto,'valign',function(){
  26927. return this._valign;
  26928. },function(value){
  26929. this._valign=value;
  26930. this.isChanged=true;
  26931. });
  26932. /**
  26933. *<p>表示文本是否自动换行,默认为false。</p>
  26934. *<p>若值为true,则自动换行;否则不自动换行。</p>
  26935. */
  26936. __getset(0,__proto,'wordWrap',function(){
  26937. return (this._style).wordWrap;
  26938. },function(value){
  26939. this._getTextStyle().wordWrap=value;
  26940. this.isChanged=true;
  26941. });
  26942. /**设置是否单个字符渲染,如果Textd的内容一直改变,例如是一个增加的数字,就设置这个,防止无效占用缓存 */
  26943. __getset(0,__proto,'singleCharRender',function(){
  26944. return this._singleCharRender;
  26945. },function(value){
  26946. this._singleCharRender=value;
  26947. });
  26948. /**
  26949. *垂直行间距(以像素为单位)。
  26950. */
  26951. __getset(0,__proto,'leading',function(){
  26952. return (this._style).leading;
  26953. },function(value){
  26954. this._getTextStyle().leading=value;
  26955. this.isChanged=true;
  26956. });
  26957. /**
  26958. *文本背景颜色,以字符串表示。
  26959. */
  26960. __getset(0,__proto,'bgColor',function(){
  26961. return (this._style).bgColor;
  26962. },function(value){
  26963. this._getTextStyle().bgColor=value;
  26964. this._renderType |=/*laya.display.SpriteConst.STYLE*/0x80;
  26965. this._setBgStyleColor(0,0,this.width,this.height,value);
  26966. this._setRenderType(this._renderType);
  26967. this.isChanged=true;
  26968. });
  26969. /**
  26970. *文本边框背景颜色,以字符串表示。
  26971. */
  26972. __getset(0,__proto,'borderColor',function(){
  26973. return (this._style).borderColor;
  26974. },function(value){
  26975. this._getTextStyle().borderColor=value;
  26976. this._renderType |=/*laya.display.SpriteConst.STYLE*/0x80;
  26977. this._setBorderStyleColor(0,0,this.width,this.height,value,1);
  26978. this._setRenderType(this._renderType);
  26979. this.isChanged=true;
  26980. });
  26981. /**
  26982. *<p>描边宽度(以像素为单位)。</p>
  26983. *<p>默认值0,表示不描边。</p>
  26984. */
  26985. __getset(0,__proto,'stroke',function(){
  26986. return (this._style).stroke;
  26987. },function(value){
  26988. this._getTextStyle().stroke=value;
  26989. this.isChanged=true;
  26990. });
  26991. /**
  26992. *<p>描边颜色,以字符串表示。</p>
  26993. *<p>默认值为 "#000000"(黑色);</p>
  26994. */
  26995. __getset(0,__proto,'strokeColor',function(){
  26996. return (this._style).strokeColor;
  26997. },function(value){
  26998. this._getTextStyle().strokeColor=value;
  26999. this.isChanged=true;
  27000. });
  27001. /**
  27002. *@private
  27003. *一个布尔值,表示文本的属性是否有改变。若为true表示有改变。
  27004. */
  27005. __getset(0,__proto,'isChanged',null,function(value){
  27006. if (this._isChanged!==value){
  27007. this._isChanged=value;
  27008. value && Laya.systemTimer.callLater(this,this.typeset);
  27009. }
  27010. });
  27011. /**
  27012. *<p>设置横向滚动量。</p>
  27013. *<p>即使设置超出滚动范围的值,也会被自动限制在可能的最大值处。</p>
  27014. */
  27015. /**
  27016. *获取横向滚动量。
  27017. */
  27018. __getset(0,__proto,'scrollX',function(){
  27019. if (!this._clipPoint)return 0;
  27020. return this._clipPoint.x;
  27021. },function(value){
  27022. if (this.overflow !="scroll" || (this.textWidth < this._width || !this._clipPoint))return;
  27023. value=value < this.padding[3] ? this.padding[3] :value;
  27024. var maxScrollX=this._textWidth-this._width;
  27025. value=value > maxScrollX ? maxScrollX :value;
  27026. this._clipPoint.x=value;
  27027. this._renderText();
  27028. });
  27029. /**
  27030. *设置纵向滚动量(px)。即使设置超出滚动范围的值,也会被自动限制在可能的最大值处。
  27031. */
  27032. /**
  27033. *获取纵向滚动量。
  27034. */
  27035. __getset(0,__proto,'scrollY',function(){
  27036. if (!this._clipPoint)return 0;
  27037. return this._clipPoint.y;
  27038. },function(value){
  27039. if (this.overflow !="scroll" || (this.textHeight < this._height || !this._clipPoint))return;
  27040. value=value < this.padding[0] ? this.padding[0] :value;
  27041. var maxScrollY=this._textHeight-this._height;
  27042. value=value > maxScrollY ? maxScrollY :value;
  27043. this._clipPoint.y=value;
  27044. this._renderText();
  27045. });
  27046. /**
  27047. *获取横向可滚动最大值。
  27048. */
  27049. __getset(0,__proto,'maxScrollX',function(){
  27050. return (this.textWidth < this._width)? 0 :this._textWidth-this._width;
  27051. });
  27052. /**
  27053. *获取纵向可滚动最大值。
  27054. */
  27055. __getset(0,__proto,'maxScrollY',function(){
  27056. return (this.textHeight < this._height)? 0 :this._textHeight-this._height;
  27057. });
  27058. /**返回文字行信息*/
  27059. __getset(0,__proto,'lines',function(){
  27060. if (this._isChanged)this.typeset();
  27061. return this._lines;
  27062. });
  27063. /**下划线的颜色,为null则使用字体颜色。*/
  27064. __getset(0,__proto,'underlineColor',function(){
  27065. return (this._style).underlineColor;
  27066. },function(value){
  27067. this._getTextStyle().underlineColor=value;
  27068. if (!this._isChanged)this._renderText();
  27069. });
  27070. /**是否显示下划线。*/
  27071. __getset(0,__proto,'underline',function(){
  27072. return (this._style).underline;
  27073. },function(value){
  27074. this._getTextStyle().underline=value;
  27075. });
  27076. Text.defaultFontStr=function(){
  27077. return Text.defaultFontSize+"px "+Text.defaultFont;
  27078. }
  27079. Text.registerBitmapFont=function(name,bitmapFont){
  27080. Text._bitmapFonts || (Text._bitmapFonts={});
  27081. Text._bitmapFonts[name]=bitmapFont;
  27082. }
  27083. Text.unregisterBitmapFont=function(name,destroy){
  27084. (destroy===void 0)&& (destroy=true);
  27085. if (Text._bitmapFonts && Text._bitmapFonts[name]){
  27086. var tBitmapFont=Text._bitmapFonts[name];
  27087. if (destroy)tBitmapFont.destroy();
  27088. delete Text._bitmapFonts[name];
  27089. }
  27090. }
  27091. Text.VISIBLE="visible";
  27092. Text.SCROLL="scroll";
  27093. Text.HIDDEN="hidden";
  27094. Text.defaultFontSize=12;
  27095. Text.defaultFont="Arial";
  27096. Text.langPacks=null;
  27097. Text.isComplexText=false;
  27098. Text._testWord="游";
  27099. Text._bitmapFonts=null;
  27100. Text.CharacterCache=true;
  27101. Text.RightToLeft=false;
  27102. __static(Text,
  27103. ['fontFamilyMap',function(){return this.fontFamilyMap={"报隶":"报隶-简","黑体":"黑体-简","楷体":"楷体-简","兰亭黑":"兰亭黑-简","隶变":"隶变-简","凌慧体":"凌慧体-简","翩翩体":"翩翩体-简","苹方":"苹方-简","手札体":"手札体-简","宋体":"宋体-简","娃娃体":"娃娃体-简","魏碑":"魏碑-简","行楷":"行楷-简","雅痞":"雅痞-简","圆体":"圆体-简"};}
  27104. ]);
  27105. return Text;
  27106. })(Sprite)
  27107. /**
  27108. *<p>动画基类,提供了基础的动画播放控制方法和帧标签事件相关功能。</p>
  27109. *<p>可以继承此类,但不要直接实例化此类,因为有些方法需要由子类实现。</p>
  27110. */
  27111. //class laya.display.AnimationBase extends laya.display.Sprite
  27112. var AnimationBase=(function(_super){
  27113. function AnimationBase(){
  27114. /**是否循环播放,调用play(...)方法时,会将此值设置为指定的参数值。*/
  27115. this.loop=false;
  27116. /**播放顺序类型:AnimationBase.WRAP_POSITIVE为正序播放(默认值),AnimationBase.WRAP_REVERSE为倒序播放,AnimationBase.WRAP_PINGPONG为pingpong播放(当按指定顺序播放完结尾后,如果继续播发,则会改变播放顺序)。*/
  27117. this.wrapMode=0;
  27118. /**@private */
  27119. this._index=0;
  27120. /**@private */
  27121. this._count=0;
  27122. /**@private */
  27123. this._isPlaying=false;
  27124. /**@private */
  27125. this._labels=null;
  27126. /**是否是逆序播放*/
  27127. this._isReverse=false;
  27128. /**@private */
  27129. this._frameRateChanged=false;
  27130. /**@private */
  27131. this._actionName=null;
  27132. /**@private */
  27133. this._controlNode=null;
  27134. AnimationBase.__super.call(this);
  27135. this._interval=Config.animationInterval;
  27136. this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  27137. }
  27138. __class(AnimationBase,'laya.display.AnimationBase',_super);
  27139. var __proto=AnimationBase.prototype;
  27140. /**
  27141. *<p>开始播放动画。play(...)方法被设计为在创建实例后的任何时候都可以被调用,当相应的资源加载完毕、调用动画帧填充方法(set frames)或者将实例显示在舞台上时,会判断是否正在播放中,如果是,则进行播放。</p>
  27142. *<p>配合wrapMode属性,可设置动画播放顺序类型。</p>
  27143. *@param start (可选)指定动画播放开始的索引(int)或帧标签(String)。帧标签可以通过addLabel(...)和removeLabel(...)进行添加和删除。
  27144. *@param loop (可选)是否循环播放。
  27145. *@param name (可选)动画名称。
  27146. */
  27147. __proto.play=function(start,loop,name){
  27148. (start===void 0)&& (start=0);
  27149. (loop===void 0)&& (loop=true);
  27150. (name===void 0)&& (name="");
  27151. this._isPlaying=true;
  27152. this._actionName=name;
  27153. this.index=((typeof start=='string'))? this._getFrameByLabel(start):start;
  27154. this.loop=loop;
  27155. this._isReverse=this.wrapMode===1;
  27156. if (this.index==0 && this._isReverse){
  27157. this.index=this.count-1;
  27158. }
  27159. if (this.interval > 0)this.timerLoop(this.interval,this,this._frameLoop,null,true,true);
  27160. }
  27161. /**@private */
  27162. __proto._getFrameByLabel=function(label){
  27163. for (var i=0;i < this._count;i++){
  27164. var item=this._labels[i];
  27165. if (item && (item).indexOf(label)>-1)return i;
  27166. }
  27167. return 0;
  27168. }
  27169. /**@private */
  27170. __proto._frameLoop=function(){
  27171. if (this._isReverse){
  27172. this._index--;
  27173. if (this._index < 0){
  27174. if (this.loop){
  27175. if (this.wrapMode==2){
  27176. this._index=this._count > 0 ? 1 :0;
  27177. this._isReverse=false;
  27178. }else {
  27179. this._index=this._count-1;
  27180. }
  27181. this.event(/*laya.events.Event.COMPLETE*/"complete");
  27182. }else {
  27183. this._index=0;
  27184. this.stop();
  27185. this.event(/*laya.events.Event.COMPLETE*/"complete");
  27186. return;
  27187. }
  27188. }
  27189. }else {
  27190. this._index++;
  27191. if (this._index >=this._count){
  27192. if (this.loop){
  27193. if (this.wrapMode==2){
  27194. this._index=this._count-2 >=0 ? this._count-2 :0;
  27195. this._isReverse=true;
  27196. }else {
  27197. this._index=0;
  27198. }
  27199. this.event(/*laya.events.Event.COMPLETE*/"complete");
  27200. }else {
  27201. this._index--;
  27202. this.stop();
  27203. this.event(/*laya.events.Event.COMPLETE*/"complete");
  27204. return;
  27205. }
  27206. }
  27207. }
  27208. this.index=this._index;
  27209. }
  27210. /**@private */
  27211. __proto._setControlNode=function(node){
  27212. if (this._controlNode){
  27213. this._controlNode.off(/*laya.events.Event.DISPLAY*/"display",this,this._resumePlay);
  27214. this._controlNode.off(/*laya.events.Event.UNDISPLAY*/"undisplay",this,this._resumePlay);
  27215. }
  27216. this._controlNode=node;
  27217. if (node && node !=this){
  27218. node.on(/*laya.events.Event.DISPLAY*/"display",this,this._resumePlay);
  27219. node.on(/*laya.events.Event.UNDISPLAY*/"undisplay",this,this._resumePlay);
  27220. }
  27221. }
  27222. /**@private */
  27223. __proto._setDisplay=function(value){
  27224. _super.prototype._setDisplay.call(this,value);
  27225. this._resumePlay();
  27226. }
  27227. /**@private */
  27228. __proto._resumePlay=function(){
  27229. if (this._isPlaying){
  27230. if (this._controlNode.displayedInStage)this.play(this._index,this.loop,this._actionName);
  27231. else this.clearTimer(this,this._frameLoop);
  27232. }
  27233. }
  27234. /**
  27235. *停止动画播放。
  27236. */
  27237. __proto.stop=function(){
  27238. this._isPlaying=false;
  27239. this.clearTimer(this,this._frameLoop);
  27240. }
  27241. /**
  27242. *增加一个帧标签到指定索引的帧上。当动画播放到此索引的帧时会派发Event.LABEL事件,派发事件是在完成当前帧画面更新之后。
  27243. *@param label 帧标签名称
  27244. *@param index 帧索引
  27245. */
  27246. __proto.addLabel=function(label,index){
  27247. if (!this._labels)this._labels={};
  27248. if (!this._labels[index])this._labels[index]=[];
  27249. this._labels[index].push(label);
  27250. }
  27251. /**
  27252. *删除指定的帧标签。
  27253. *@param label 帧标签名称。注意:如果为空,则删除所有帧标签!
  27254. */
  27255. __proto.removeLabel=function(label){
  27256. if (!label)this._labels=null;
  27257. else if (this._labels){
  27258. for (var name in this._labels){
  27259. this._removeLabelFromList(this._labels[name],label);
  27260. }
  27261. }
  27262. }
  27263. /**@private */
  27264. __proto._removeLabelFromList=function(list,label){
  27265. if (!list)return;
  27266. for (var i=list.length-1;i >=0;i--){
  27267. if (list[i]==label){
  27268. list.splice(i,1);
  27269. }
  27270. }
  27271. }
  27272. /**
  27273. *将动画切换到指定帧并停在那里。
  27274. *@param position 帧索引或帧标签
  27275. */
  27276. __proto.gotoAndStop=function(position){
  27277. this.index=((typeof position=='string'))? this._getFrameByLabel(position):position;
  27278. this.stop();
  27279. }
  27280. /**
  27281. *@private
  27282. *显示到某帧
  27283. *@param value 帧索引
  27284. */
  27285. __proto._displayToIndex=function(value){}
  27286. /**
  27287. *停止动画播放,并清理对象属性。之后可存入对象池,方便对象复用。
  27288. *@return 返回对象本身
  27289. */
  27290. __proto.clear=function(){
  27291. this.stop();
  27292. this._labels=null;
  27293. return this;
  27294. }
  27295. /**
  27296. *<p>动画播放的帧间隔时间(单位:毫秒)。默认值依赖于Config.animationInterval=50,通过Config.animationInterval可以修改默认帧间隔时间。</p>
  27297. *<p>要想为某动画设置独立的帧间隔时间,可以使用set interval,注意:如果动画正在播放,设置后会重置帧循环定时器的起始时间为当前时间,也就是说,如果频繁设置interval,会导致动画帧更新的时间间隔会比预想的要慢,甚至不更新。</p>
  27298. */
  27299. __getset(0,__proto,'interval',function(){
  27300. return this._interval;
  27301. },function(value){
  27302. if (this._interval !=value){
  27303. this._frameRateChanged=true;
  27304. this._interval=value;
  27305. if (this._isPlaying && value > 0){
  27306. this.timerLoop(value,this,this._frameLoop,null,true,true);
  27307. }
  27308. }
  27309. });
  27310. /**
  27311. *是否正在播放中。
  27312. */
  27313. __getset(0,__proto,'isPlaying',function(){
  27314. return this._isPlaying;
  27315. });
  27316. /**
  27317. *动画当前帧的索引。
  27318. */
  27319. __getset(0,__proto,'index',function(){
  27320. return this._index;
  27321. },function(value){
  27322. this._index=value;
  27323. this._displayToIndex(value);
  27324. if (this._labels && this._labels[value]){
  27325. var tArr=this._labels[value];
  27326. for (var i=0,len=tArr.length;i < len;i++){
  27327. this.event(/*laya.events.Event.LABEL*/"label",tArr[i]);
  27328. }
  27329. }
  27330. });
  27331. /**
  27332. *当前动画中帧的总数。
  27333. */
  27334. __getset(0,__proto,'count',function(){
  27335. return this._count;
  27336. });
  27337. AnimationBase.WRAP_POSITIVE=0;
  27338. AnimationBase.WRAP_REVERSE=1;
  27339. AnimationBase.WRAP_PINGPONG=2;
  27340. return AnimationBase;
  27341. })(Sprite)
  27342. //class laya.webgl.shader.Shader extends laya.webgl.shader.BaseShader
  27343. var Shader=(function(_super){
  27344. function Shader(vs,ps,saveName,nameMap,bindAttrib){
  27345. //存储预编译结果,可以通过名字获得内容,目前不支持#ifdef嵌套和条件
  27346. this._attribInfo=null;
  27347. this.customCompile=false;
  27348. //this._nameMap=null;
  27349. //shader参数别名,语义
  27350. //this._vs=null;
  27351. //this._ps=null;
  27352. this._curActTexIndex=0;
  27353. //this._reCompile=false;
  27354. //存储一些私有变量
  27355. this.tag={};
  27356. //this._vshader=null;
  27357. //this._pshader=null;
  27358. this._program=null;
  27359. this._params=null;
  27360. this._paramsMap={};
  27361. Shader.__super.call(this);
  27362. if ((!vs)|| (!ps))throw "Shader Error";
  27363. this._attribInfo=bindAttrib;
  27364. this._id=++Shader._count;
  27365. this._vs=vs;
  27366. this._ps=ps;
  27367. this._nameMap=nameMap ? nameMap :{};
  27368. saveName !=null && (Shader.sharders[saveName]=this);
  27369. this.recreateResource();
  27370. this.lock=true;
  27371. }
  27372. __class(Shader,'laya.webgl.shader.Shader',_super);
  27373. var __proto=Shader.prototype;
  27374. __proto.recreateResource=function(){
  27375. this._compile();
  27376. this._setGPUMemory(0);
  27377. }
  27378. //TODO:coverage
  27379. __proto._disposeResource=function(){
  27380. WebGL.mainContext.deleteShader(this._vshader);
  27381. WebGL.mainContext.deleteShader(this._pshader);
  27382. WebGL.mainContext.deleteProgram(this._program);
  27383. this._vshader=this._pshader=this._program=null;
  27384. this._params=null;
  27385. this._paramsMap={};
  27386. this._setGPUMemory(0);
  27387. this._curActTexIndex=0;
  27388. }
  27389. __proto._compile=function(){
  27390. if (!this._vs || !this._ps || this._params)
  27391. return;
  27392. this._reCompile=true;
  27393. this._params=[];
  27394. var result;
  27395. if (this.customCompile)
  27396. result=ShaderCompile.preGetParams(this._vs,this._ps);
  27397. var gl=WebGL.mainContext;
  27398. this._program=gl.createProgram();
  27399. this._vshader=Shader._createShader(gl,this._vs,/*laya.webgl.WebGLContext.VERTEX_SHADER*/0x8B31);
  27400. this._pshader=Shader._createShader(gl,this._ps,/*laya.webgl.WebGLContext.FRAGMENT_SHADER*/0x8B30);
  27401. gl.attachShader(this._program,this._vshader);
  27402. gl.attachShader(this._program,this._pshader);
  27403. var one,i=0,j=0,n=0,location;
  27404. var attribDescNum=this._attribInfo?this._attribInfo.length:0;
  27405. for (i=0;i < attribDescNum;i+=2){
  27406. gl.bindAttribLocation(this._program,this._attribInfo[i+1],this._attribInfo[i]);
  27407. }
  27408. gl.linkProgram(this._program);
  27409. if (!this.customCompile && !gl.getProgramParameter(this._program,/*laya.webgl.WebGLContext.LINK_STATUS*/0x8B82)){
  27410. throw gl.getProgramInfoLog(this._program);
  27411. };
  27412. var nUniformNum=this.customCompile ? result.uniforms.length :gl.getProgramParameter(this._program,/*laya.webgl.WebGLContext.ACTIVE_UNIFORMS*/0x8B86);
  27413. for (i=0;i < nUniformNum;i++){
  27414. var uniform=this.customCompile ? result.uniforms[i] :gl.getActiveUniform(this._program,i);
  27415. location=gl.getUniformLocation(this._program,uniform.name);
  27416. one={vartype:"uniform",glfun:null,ivartype:1,location:location,name:uniform.name,type:uniform.type,isArray:false,isSame:false,preValue:null,indexOfParams:0};
  27417. if (one.name.indexOf('[0]')> 0){
  27418. one.name=one.name.substr(0,one.name.length-3);
  27419. one.isArray=true;
  27420. one.location=gl.getUniformLocation(this._program,one.name);
  27421. }
  27422. this._params.push(one);
  27423. }
  27424. for (i=0,n=this._params.length;i < n;i++){
  27425. one=this._params[i];
  27426. one.indexOfParams=i;
  27427. one.index=1;
  27428. one.value=[one.location,null];
  27429. one.codename=one.name;
  27430. one.name=this._nameMap[one.codename] ? this._nameMap[one.codename] :one.codename;
  27431. this._paramsMap[one.name]=one;
  27432. one._this=this;
  27433. one.uploadedValue=[];
  27434. switch (one.type){
  27435. case /*laya.webgl.WebGLContext.INT*/0x1404:
  27436. one.fun=one.isArray ? this._uniform1iv :this._uniform1i;
  27437. break ;
  27438. case /*laya.webgl.WebGLContext.FLOAT*/0x1406:
  27439. one.fun=one.isArray ? this._uniform1fv :this._uniform1f;
  27440. break ;
  27441. case /*laya.webgl.WebGLContext.FLOAT_VEC2*/0x8B50:
  27442. one.fun=one.isArray ? this._uniform_vec2v:this._uniform_vec2;
  27443. break ;
  27444. case /*laya.webgl.WebGLContext.FLOAT_VEC3*/0x8B51:
  27445. one.fun=one.isArray ? this._uniform_vec3v:this._uniform_vec3;
  27446. break ;
  27447. case /*laya.webgl.WebGLContext.FLOAT_VEC4*/0x8B52:
  27448. one.fun=one.isArray ? this._uniform_vec4v:this._uniform_vec4;
  27449. break ;
  27450. case /*laya.webgl.WebGLContext.SAMPLER_2D*/0x8B5E:
  27451. one.fun=this._uniform_sampler2D;
  27452. break ;
  27453. case /*laya.webgl.WebGLContext.SAMPLER_CUBE*/0x8B60:
  27454. one.fun=this._uniform_samplerCube;
  27455. break ;
  27456. case /*laya.webgl.WebGLContext.FLOAT_MAT4*/0x8B5C:
  27457. one.glfun=gl.uniformMatrix4fv;
  27458. one.fun=this._uniformMatrix4fv;
  27459. break ;
  27460. case /*laya.webgl.WebGLContext.BOOL*/0x8B56:
  27461. one.fun=this._uniform1i;
  27462. break ;
  27463. case /*laya.webgl.WebGLContext.FLOAT_MAT2*/0x8B5A:
  27464. case /*laya.webgl.WebGLContext.FLOAT_MAT3*/0x8B5B:
  27465. throw new Error("compile shader err!");
  27466. default :
  27467. throw new Error("compile shader err!");
  27468. }
  27469. }
  27470. }
  27471. //TODO:coverage
  27472. __proto.getUniform=function(name){
  27473. return this._paramsMap[name];
  27474. }
  27475. //TODO:coverage
  27476. __proto._uniform1f=function(one,value){
  27477. var uploadedValue=one.uploadedValue;
  27478. if (uploadedValue[0]!==value){
  27479. WebGL.mainContext.uniform1f(one.location,uploadedValue[0]=value);
  27480. return 1;
  27481. }
  27482. return 0;
  27483. }
  27484. //TODO:coverage
  27485. __proto._uniform1fv=function(one,value){
  27486. if (value.length < 4){
  27487. var uploadedValue=one.uploadedValue;
  27488. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
  27489. WebGL.mainContext.uniform1fv(one.location,value);
  27490. uploadedValue[0]=value[0];
  27491. uploadedValue[1]=value[1];
  27492. uploadedValue[2]=value[2];
  27493. uploadedValue[3]=value[3];
  27494. return 1;
  27495. }
  27496. return 0;
  27497. }else {
  27498. WebGL.mainContext.uniform1fv(one.location,value);
  27499. return 1;
  27500. }
  27501. }
  27502. __proto._uniform_vec2=function(one,value){
  27503. var uploadedValue=one.uploadedValue;
  27504. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1]){
  27505. WebGL.mainContext.uniform2f(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1]);
  27506. return 1;
  27507. }
  27508. return 0;
  27509. }
  27510. //TODO:coverage
  27511. __proto._uniform_vec2v=function(one,value){
  27512. if (value.length < 2){
  27513. var uploadedValue=one.uploadedValue;
  27514. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
  27515. WebGL.mainContext.uniform2fv(one.location,value);
  27516. uploadedValue[0]=value[0];
  27517. uploadedValue[1]=value[1];
  27518. uploadedValue[2]=value[2];
  27519. uploadedValue[3]=value[3];
  27520. return 1;
  27521. }
  27522. return 0;
  27523. }else {
  27524. WebGL.mainContext.uniform2fv(one.location,value);
  27525. return 1;
  27526. }
  27527. }
  27528. //TODO:coverage
  27529. __proto._uniform_vec3=function(one,value){
  27530. var uploadedValue=one.uploadedValue;
  27531. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2]){
  27532. WebGL.mainContext.uniform3f(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2]);
  27533. return 1;
  27534. }
  27535. return 0;
  27536. }
  27537. //TODO:coverage
  27538. __proto._uniform_vec3v=function(one,value){
  27539. WebGL.mainContext.uniform3fv(one.location,value);
  27540. return 1;
  27541. }
  27542. __proto._uniform_vec4=function(one,value){
  27543. var uploadedValue=one.uploadedValue;
  27544. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
  27545. WebGL.mainContext.uniform4f(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2],uploadedValue[3]=value[3]);
  27546. return 1;
  27547. }
  27548. return 0;
  27549. }
  27550. //TODO:coverage
  27551. __proto._uniform_vec4v=function(one,value){
  27552. WebGL.mainContext.uniform4fv(one.location,value);
  27553. return 1;
  27554. }
  27555. //TODO:coverage
  27556. __proto._uniformMatrix2fv=function(one,value){
  27557. WebGL.mainContext.uniformMatrix2fv(one.location,false,value);
  27558. return 1;
  27559. }
  27560. //TODO:coverage
  27561. __proto._uniformMatrix3fv=function(one,value){
  27562. WebGL.mainContext.uniformMatrix3fv(one.location,false,value);
  27563. return 1;
  27564. }
  27565. __proto._uniformMatrix4fv=function(one,value){
  27566. WebGL.mainContext.uniformMatrix4fv(one.location,false,value);
  27567. return 1;
  27568. }
  27569. //TODO:coverage
  27570. __proto._uniform1i=function(one,value){
  27571. var uploadedValue=one.uploadedValue;
  27572. if (uploadedValue[0]!==value){
  27573. WebGL.mainContext.uniform1i(one.location,uploadedValue[0]=value);
  27574. return 1;
  27575. }
  27576. return 0;
  27577. }
  27578. //TODO:coverage
  27579. __proto._uniform1iv=function(one,value){
  27580. WebGL.mainContext.uniform1iv(one.location,value);
  27581. return 1;
  27582. }
  27583. //TODO:coverage
  27584. __proto._uniform_ivec2=function(one,value){
  27585. var uploadedValue=one.uploadedValue;
  27586. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1]){
  27587. WebGL.mainContext.uniform2i(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1]);
  27588. return 1;
  27589. }
  27590. return 0;
  27591. }
  27592. //TODO:coverage
  27593. __proto._uniform_ivec2v=function(one,value){
  27594. WebGL.mainContext.uniform2iv(one.location,value);
  27595. return 1;
  27596. }
  27597. //TODO:coverage
  27598. __proto._uniform_vec3i=function(one,value){
  27599. var uploadedValue=one.uploadedValue;
  27600. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2]){
  27601. WebGL.mainContext.uniform3i(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2]);
  27602. return 1;
  27603. }
  27604. return 0;
  27605. }
  27606. __proto._uniform_vec3vi=function(one,value){
  27607. WebGL.mainContext.uniform3iv(one.location,value);
  27608. return 1;
  27609. }
  27610. //TODO:coverage
  27611. __proto._uniform_vec4i=function(one,value){
  27612. var uploadedValue=one.uploadedValue;
  27613. if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
  27614. WebGL.mainContext.uniform4i(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2],uploadedValue[3]=value[3]);
  27615. return 1;
  27616. }
  27617. return 0;
  27618. }
  27619. //TODO:coverage
  27620. __proto._uniform_vec4vi=function(one,value){
  27621. WebGL.mainContext.uniform4iv(one.location,value);
  27622. return 1;
  27623. }
  27624. __proto._uniform_sampler2D=function(one,value){
  27625. var gl=WebGL.mainContext;
  27626. var uploadedValue=one.uploadedValue;
  27627. if (uploadedValue[0]==null){
  27628. uploadedValue[0]=this._curActTexIndex;
  27629. gl.uniform1i(one.location,this._curActTexIndex);
  27630. WebGLContext.activeTexture(gl,/*laya.webgl.WebGLContext.TEXTURE0*/0x84C0+this._curActTexIndex);
  27631. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,value);
  27632. this._curActTexIndex++;
  27633. return 1;
  27634. }else {
  27635. WebGLContext.activeTexture(gl,/*laya.webgl.WebGLContext.TEXTURE0*/0x84C0+uploadedValue[0]);
  27636. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,value);
  27637. return 0;
  27638. }
  27639. }
  27640. //TODO:coverage
  27641. __proto._uniform_samplerCube=function(one,value){
  27642. var gl=WebGL.mainContext;
  27643. var uploadedValue=one.uploadedValue;
  27644. if (uploadedValue[0]==null){
  27645. uploadedValue[0]=this._curActTexIndex;
  27646. gl.uniform1i(one.location,this._curActTexIndex);
  27647. WebGLContext.activeTexture(gl,/*laya.webgl.WebGLContext.TEXTURE0*/0x84C0+this._curActTexIndex);
  27648. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP*/0x8513,value);
  27649. this._curActTexIndex++;
  27650. return 1;
  27651. }else {
  27652. WebGLContext.activeTexture(gl,/*laya.webgl.WebGLContext.TEXTURE0*/0x84C0+uploadedValue[0]);
  27653. WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP*/0x8513,value);
  27654. return 0;
  27655. }
  27656. }
  27657. //TODO:coverage
  27658. __proto._noSetValue=function(one){
  27659. console.log("no....:"+one.name);
  27660. }
  27661. //TODO:coverage
  27662. __proto.uploadOne=function(name,value){
  27663. WebGLContext.useProgram(WebGL.mainContext,this._program);
  27664. var one=this._paramsMap[name];
  27665. one.fun.call(this,one,value);
  27666. }
  27667. __proto.uploadTexture2D=function(value){
  27668. var CTX=WebGLContext;
  27669. if(CTX._activeTextures[0]!==value){
  27670. CTX.bindTexture(WebGL.mainContext,CTX.TEXTURE_2D,value);
  27671. CTX._activeTextures[0]=value;
  27672. }
  27673. }
  27674. /**
  27675. *提交shader到GPU
  27676. *@param shaderValue
  27677. */
  27678. __proto.upload=function(shaderValue,params){
  27679. BaseShader.activeShader=BaseShader.bindShader=this;
  27680. var gl=WebGL.mainContext;
  27681. WebGLContext.useProgram(gl,this._program);
  27682. if (this._reCompile){
  27683. params=this._params;
  27684. this._reCompile=false;
  27685. }else {
  27686. params=params || this._params;
  27687. };
  27688. var one,value,n=params.length,shaderCall=0;
  27689. for (var i=0;i < n;i++){
  27690. one=params[i];
  27691. if ((value=shaderValue[one.name])!==null)
  27692. shaderCall+=one.fun.call(this,one,value);
  27693. }
  27694. Stat.shaderCall+=shaderCall;
  27695. }
  27696. //TODO:coverage
  27697. __proto.uploadArray=function(shaderValue,length,_bufferUsage){
  27698. BaseShader.activeShader=this;
  27699. BaseShader.bindShader=this;
  27700. WebGLContext.useProgram(WebGL.mainContext,this._program);
  27701. var params=this._params,value;
  27702. var one,shaderCall=0;
  27703. for (var i=length-2;i >=0;i-=2){
  27704. one=this._paramsMap[shaderValue[i]];
  27705. if (!one)
  27706. continue ;
  27707. value=shaderValue[i+1];
  27708. if (value !=null){
  27709. _bufferUsage && _bufferUsage[one.name] && _bufferUsage[one.name].bind();
  27710. shaderCall+=one.fun.call(this,one,value);
  27711. }
  27712. }
  27713. Stat.shaderCall+=shaderCall;
  27714. }
  27715. //TODO:coverage
  27716. __proto.getParams=function(){
  27717. return this._params;
  27718. }
  27719. //TODO:coverage
  27720. __proto.setAttributesLocation=function(attribDesc){
  27721. this._attribInfo=attribDesc;
  27722. }
  27723. Shader.getShader=function(name){
  27724. return Shader.sharders[name];
  27725. }
  27726. Shader.create=function(vs,ps,saveName,nameMap,bindAttrib){
  27727. return new Shader(vs,ps,saveName,nameMap,bindAttrib);
  27728. }
  27729. Shader.withCompile=function(nameID,define,shaderName,createShader){
  27730. if (shaderName && Shader.sharders[shaderName])
  27731. return Shader.sharders[shaderName];
  27732. var pre=Shader._preCompileShader[0.0002 *nameID];
  27733. if (!pre)
  27734. throw new Error("withCompile shader err!"+nameID);
  27735. return pre.createShader(define,shaderName,createShader,null);
  27736. }
  27737. Shader.withCompile2D=function(nameID,mainID,define,shaderName,createShader,bindAttrib){
  27738. if (shaderName && Shader.sharders[shaderName])
  27739. return Shader.sharders[shaderName];
  27740. var pre=Shader._preCompileShader[0.0002 *nameID+mainID];
  27741. if (!pre)
  27742. throw new Error("withCompile shader err!"+nameID+" "+mainID);
  27743. return pre.createShader(define,shaderName,createShader,bindAttrib);
  27744. }
  27745. Shader.addInclude=function(fileName,txt){
  27746. ShaderCompile.addInclude(fileName,txt);
  27747. }
  27748. Shader.preCompile=function(nameID,vs,ps,nameMap){
  27749. var id=0.0002 *nameID;
  27750. Shader._preCompileShader[id]=new ShaderCompile(vs,ps,nameMap);
  27751. }
  27752. Shader.preCompile2D=function(nameID,mainID,vs,ps,nameMap){
  27753. var id=0.0002 *nameID+mainID;
  27754. Shader._preCompileShader[id]=new ShaderCompile(vs,ps,nameMap);
  27755. }
  27756. Shader._createShader=function(gl,str,type){
  27757. var shader=gl.createShader(type);
  27758. gl.shaderSource(shader,str);
  27759. gl.compileShader(shader);
  27760. if(gl.getShaderParameter(shader,/*laya.webgl.WebGLContext.COMPILE_STATUS*/0x8B81)){
  27761. return shader;
  27762. }else{
  27763. console.log(gl.getShaderInfoLog(shader));
  27764. return null;
  27765. }
  27766. }
  27767. Shader._count=0;
  27768. Shader._preCompileShader={};
  27769. Shader.SHADERNAME2ID=0.0002;
  27770. Shader.sharders=new Array(0x20);
  27771. __static(Shader,
  27772. ['nameKey',function(){return this.nameKey=new StringKey();}
  27773. ]);
  27774. return Shader;
  27775. })(BaseShader)
  27776. /**
  27777. *@private
  27778. */
  27779. //class laya.media.SoundNode extends laya.display.Sprite
  27780. var SoundNode=(function(_super){
  27781. function SoundNode(){
  27782. this.url=null;
  27783. this._channel=null;
  27784. this._tar=null;
  27785. this._playEvents=null;
  27786. this._stopEvents=null;
  27787. SoundNode.__super.call(this);
  27788. this.visible=false;
  27789. this.on(/*laya.events.Event.ADDED*/"added",this,this._onParentChange);
  27790. this.on(/*laya.events.Event.REMOVED*/"removed",this,this._onParentChange);
  27791. }
  27792. __class(SoundNode,'laya.media.SoundNode',_super);
  27793. var __proto=SoundNode.prototype;
  27794. /**@private */
  27795. __proto._onParentChange=function(){
  27796. this.target=this.parent;
  27797. }
  27798. /**
  27799. *播放
  27800. *@param loops 循环次数
  27801. *@param complete 完成回调
  27802. *
  27803. */
  27804. __proto.play=function(loops,complete){
  27805. (loops===void 0)&& (loops=1);
  27806. if (isNaN(loops)){
  27807. loops=1;
  27808. }
  27809. if (!this.url)return;
  27810. this.stop();
  27811. this._channel=SoundManager.playSound(this.url,loops,complete);
  27812. }
  27813. /**
  27814. *停止播放
  27815. *
  27816. */
  27817. __proto.stop=function(){
  27818. if (this._channel && !this._channel.isStopped){
  27819. this._channel.stop();
  27820. }
  27821. this._channel=null;
  27822. }
  27823. /**@private */
  27824. __proto._setPlayAction=function(tar,event,action,add){
  27825. (add===void 0)&& (add=true);
  27826. if (!this[action])return;
  27827. if (!tar)return;
  27828. if (add){
  27829. tar.on(event,this,this[action]);
  27830. }else {
  27831. tar.off(event,this,this[action]);
  27832. }
  27833. }
  27834. /**@private */
  27835. __proto._setPlayActions=function(tar,events,action,add){
  27836. (add===void 0)&& (add=true);
  27837. if (!tar)return;
  27838. if (!events)return;
  27839. var eventArr=events.split(",");
  27840. var i=0,len=0;
  27841. len=eventArr.length;
  27842. for (i=0;i < len;i++){
  27843. this._setPlayAction(tar,eventArr[i],action,add);
  27844. }
  27845. }
  27846. /**
  27847. *设置触发播放的事件
  27848. *@param events
  27849. *
  27850. */
  27851. __getset(0,__proto,'playEvent',null,function(events){
  27852. this._playEvents=events;
  27853. if (!events)return;
  27854. if (this._tar){
  27855. this._setPlayActions(this._tar,events,"play");
  27856. }
  27857. });
  27858. /**
  27859. *设置控制播放的对象
  27860. *@param tar
  27861. *
  27862. */
  27863. __getset(0,__proto,'target',null,function(tar){
  27864. if (this._tar){
  27865. this._setPlayActions(this._tar,this._playEvents,"play",false);
  27866. this._setPlayActions(this._tar,this._stopEvents,"stop",false);
  27867. }
  27868. this._tar=tar;
  27869. if (this._tar){
  27870. this._setPlayActions(this._tar,this._playEvents,"play",true);
  27871. this._setPlayActions(this._tar,this._stopEvents,"stop",true);
  27872. }
  27873. });
  27874. /**
  27875. *设置触发停止的事件
  27876. *@param events
  27877. *
  27878. */
  27879. __getset(0,__proto,'stopEvent',null,function(events){
  27880. this._stopEvents=events;
  27881. if (!events)return;
  27882. if (this._tar){
  27883. this._setPlayActions(this._tar,events,"stop");
  27884. }
  27885. });
  27886. return SoundNode;
  27887. })(Sprite)
  27888. /**
  27889. *<code>BaseTexture</code> 纹理的父类,抽象类,不允许实例。
  27890. */
  27891. //class laya.resource.BaseTexture extends laya.resource.Bitmap
  27892. var BaseTexture=(function(_super){
  27893. function BaseTexture(format,mipMap){
  27894. /**@private */
  27895. //this._readyed=false;
  27896. /**@private */
  27897. //this._glTextureType=0;
  27898. /**@private */
  27899. //this._glTexture=null;
  27900. /**@private */
  27901. //this._format=0;
  27902. /**@private */
  27903. //this._mipmap=false;
  27904. /**@private */
  27905. //this._wrapModeU=0;
  27906. /**@private */
  27907. //this._wrapModeV=0;
  27908. /**@private */
  27909. //this._filterMode=0;
  27910. /**@private */
  27911. //this._anisoLevel=0;
  27912. BaseTexture.__super.call(this);
  27913. this._wrapModeU=/*CLASS CONST:laya.resource.BaseTexture.WARPMODE_REPEAT*/0;
  27914. this._wrapModeV=/*CLASS CONST:laya.resource.BaseTexture.WARPMODE_REPEAT*/0;
  27915. this._filterMode=/*CLASS CONST:laya.resource.BaseTexture.FILTERMODE_BILINEAR*/1;
  27916. this._readyed=false;
  27917. this._width=-1;
  27918. this._height=-1;
  27919. this._format=format;
  27920. this._mipmap=mipMap;
  27921. this._anisoLevel=1;
  27922. this._glTexture=LayaGL.instance.createTexture();
  27923. }
  27924. __class(BaseTexture,'laya.resource.BaseTexture',_super);
  27925. var __proto=BaseTexture.prototype;
  27926. /**
  27927. *@private
  27928. */
  27929. __proto._isPot=function(size){
  27930. return (size & (size-1))===0;
  27931. }
  27932. /**
  27933. *@private
  27934. */
  27935. __proto._getGLFormat=function(){
  27936. var glFormat=0;
  27937. switch (this._format){
  27938. case 0:
  27939. glFormat=/*laya.webgl.WebGLContext.RGB*/0x1907;
  27940. break ;
  27941. case 1:
  27942. glFormat=/*laya.webgl.WebGLContext.RGBA*/0x1908;
  27943. break ;
  27944. case 2:
  27945. glFormat=/*laya.webgl.WebGLContext.ALPHA*/0x1906;
  27946. break ;
  27947. case 3:
  27948. if (WebGLContext._compressedTextureS3tc)
  27949. glFormat=WebGLContext._compressedTextureS3tc.COMPRESSED_RGB_S3TC_DXT1_EXT;
  27950. else
  27951. throw "BaseTexture: not support DXT1 format.";
  27952. break ;
  27953. case 4:
  27954. if (WebGLContext._compressedTextureS3tc)
  27955. glFormat=WebGLContext._compressedTextureS3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  27956. else
  27957. throw "BaseTexture: not support DXT5 format.";
  27958. break ;
  27959. case 5:
  27960. if (WebGLContext._compressedTextureEtc1)
  27961. glFormat=WebGLContext._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL;
  27962. else
  27963. throw "BaseTexture: not support ETC1RGB format.";
  27964. break ;
  27965. case 9:
  27966. if (WebGLContext._compressedTexturePvrtc)
  27967. glFormat=WebGLContext._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  27968. else
  27969. throw "BaseTexture: not support PVRTCRGB_2BPPV format.";
  27970. break ;
  27971. case 10:
  27972. if (WebGLContext._compressedTexturePvrtc)
  27973. glFormat=WebGLContext._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  27974. else
  27975. throw "BaseTexture: not support PVRTCRGBA_2BPPV format.";
  27976. break ;
  27977. case 11:
  27978. if (WebGLContext._compressedTexturePvrtc)
  27979. glFormat=WebGLContext._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  27980. else
  27981. throw "BaseTexture: not support PVRTCRGB_4BPPV format.";
  27982. break ;
  27983. case 12:
  27984. if (WebGLContext._compressedTexturePvrtc)
  27985. glFormat=WebGLContext._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  27986. else
  27987. throw "BaseTexture: not support PVRTCRGBA_4BPPV format.";
  27988. break ;
  27989. default :
  27990. throw "BaseTexture: unknown texture format.";
  27991. }
  27992. return glFormat;
  27993. }
  27994. /**
  27995. *@private
  27996. */
  27997. __proto._setFilterMode=function(value){
  27998. var gl=LayaGL.instance;
  27999. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  28000. switch (value){
  28001. case 0:
  28002. if (this._mipmap)
  28003. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.NEAREST_MIPMAP_NEAREST*/0x2700);
  28004. else
  28005. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.NEAREST*/0x2600);
  28006. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MAG_FILTER*/0x2800,/*laya.webgl.WebGLContext.NEAREST*/0x2600);
  28007. break ;
  28008. case 1:
  28009. if (this._mipmap)
  28010. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR_MIPMAP_NEAREST*/0x2701);
  28011. else
  28012. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  28013. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MAG_FILTER*/0x2800,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  28014. break ;
  28015. case 2:
  28016. if (this._mipmap)
  28017. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR_MIPMAP_LINEAR*/0x2703);
  28018. else
  28019. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MIN_FILTER*/0x2801,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  28020. gl.texParameteri(this._glTextureType,/*laya.webgl.WebGLContext.TEXTURE_MAG_FILTER*/0x2800,/*laya.webgl.WebGLContext.LINEAR*/0x2601);
  28021. break ;
  28022. default :
  28023. throw new Error("BaseTexture:unknown filterMode value.");
  28024. }
  28025. }
  28026. /**
  28027. *@private
  28028. */
  28029. __proto._setWarpMode=function(orientation,mode){
  28030. var gl=LayaGL.instance;
  28031. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  28032. if (this._isPot(this._width)&& this._isPot(this._height)){
  28033. switch (mode){
  28034. case 0:
  28035. gl.texParameteri(this._glTextureType,orientation,/*laya.webgl.WebGLContext.REPEAT*/0x2901);
  28036. break ;
  28037. case 1:
  28038. gl.texParameteri(this._glTextureType,orientation,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
  28039. break ;
  28040. }
  28041. }else {
  28042. gl.texParameteri(this._glTextureType,orientation,/*laya.webgl.WebGLContext.CLAMP_TO_EDGE*/0x812F);
  28043. }
  28044. }
  28045. /**
  28046. *@private
  28047. */
  28048. __proto._setAnisotropy=function(value){
  28049. var anisotropic=WebGLContext._extTextureFilterAnisotropic;
  28050. if (anisotropic && !Browser.onLimixiu){
  28051. value=Math.max(value,1);
  28052. var gl=LayaGL.instance;
  28053. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  28054. value=Math.min(gl.getParameter(anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT),value);
  28055. gl.texParameterf(this._glTextureType,anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,value);
  28056. }
  28057. }
  28058. /**
  28059. *@inheritDoc
  28060. */
  28061. __proto._disposeResource=function(){
  28062. if (this._glTexture){
  28063. LayaGL.instance.deleteTexture(this._glTexture);
  28064. this._glTexture=null;
  28065. this._setGPUMemory(0);
  28066. }
  28067. }
  28068. /**
  28069. *获取纹理资源。
  28070. */
  28071. __proto._getSource=function(){
  28072. if (this._readyed)
  28073. return this._glTexture;
  28074. else
  28075. return null;
  28076. }
  28077. /**
  28078. *通过基础数据生成mipMap。
  28079. */
  28080. __proto.generateMipmap=function(){
  28081. if (this._isPot(this.width)&& this._isPot(this.height))
  28082. LayaGL.instance.generateMipmap(this._glTextureType);
  28083. }
  28084. /**
  28085. *设置纹理横向循环模式。
  28086. */
  28087. /**
  28088. *获取纹理横向循环模式。
  28089. */
  28090. __getset(0,__proto,'wrapModeU',function(){
  28091. return this._wrapModeU;
  28092. },function(value){
  28093. if (this._wrapModeU!==value){
  28094. this._wrapModeU=value;
  28095. (this._width!==-1)&& (this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,value));
  28096. }
  28097. });
  28098. /**
  28099. *是否使用mipLevel
  28100. */
  28101. __getset(0,__proto,'mipmap',function(){
  28102. return this._mipmap;
  28103. });
  28104. /**
  28105. *纹理格式
  28106. */
  28107. __getset(0,__proto,'format',function(){
  28108. return this._format;
  28109. });
  28110. /**
  28111. *设置纹理纵向循环模式。
  28112. */
  28113. /**
  28114. *获取纹理纵向循环模式。
  28115. */
  28116. __getset(0,__proto,'wrapModeV',function(){
  28117. return this._wrapModeV;
  28118. },function(value){
  28119. if (this._wrapModeV!==value){
  28120. this._wrapModeV=value;
  28121. (this._height!==-1)&& (this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,value));
  28122. }
  28123. });
  28124. /**
  28125. *获取默认纹理资源。
  28126. */
  28127. __getset(0,__proto,'defaulteTexture',function(){
  28128. throw "BaseTexture:must override it."
  28129. });
  28130. /**
  28131. *缩小过滤器
  28132. */
  28133. /**
  28134. *缩小过滤器
  28135. */
  28136. __getset(0,__proto,'filterMode',function(){
  28137. return this._filterMode;
  28138. },function(value){
  28139. if (value!==this._filterMode){
  28140. this._filterMode=value;
  28141. ((this._width!==-1)&& (this._height!==-1))&& (this._setFilterMode(value));
  28142. }
  28143. });
  28144. /**
  28145. *各向异性等级
  28146. */
  28147. /**
  28148. *各向异性等级
  28149. */
  28150. __getset(0,__proto,'anisoLevel',function(){
  28151. return this._anisoLevel;
  28152. },function(value){
  28153. if (value!==this._anisoLevel){
  28154. this._anisoLevel=Math.max(1,Math.min(16,value));
  28155. ((this._width!==-1)&& (this._height!==-1))&& (this._setAnisotropy(value));
  28156. }
  28157. });
  28158. BaseTexture.WARPMODE_REPEAT=0;
  28159. BaseTexture.WARPMODE_CLAMP=1;
  28160. BaseTexture.FILTERMODE_POINT=0;
  28161. BaseTexture.FILTERMODE_BILINEAR=1;
  28162. BaseTexture.FILTERMODE_TRILINEAR=2;
  28163. BaseTexture.FORMAT_R8G8B8=0;
  28164. BaseTexture.FORMAT_R8G8B8A8=1;
  28165. BaseTexture.FORMAT_ALPHA8=2;
  28166. BaseTexture.FORMAT_DXT1=3;
  28167. BaseTexture.FORMAT_DXT5=4;
  28168. BaseTexture.FORMAT_ETC1RGB=5;
  28169. BaseTexture.FORMAT_PVRTCRGB_2BPPV=9;
  28170. BaseTexture.FORMAT_PVRTCRGBA_2BPPV=10;
  28171. BaseTexture.FORMAT_PVRTCRGB_4BPPV=11;
  28172. BaseTexture.FORMAT_PVRTCRGBA_4BPPV=12;
  28173. BaseTexture.FORMAT_DEPTH_16=0;
  28174. BaseTexture.FORMAT_STENCIL_8=1;
  28175. BaseTexture.FORMAT_DEPTHSTENCIL_16_8=2;
  28176. BaseTexture.FORMAT_DEPTHSTENCIL_NONE=3;
  28177. return BaseTexture;
  28178. })(Bitmap)
  28179. /**
  28180. *<code>HTMLCanvas</code> 是 Html Canvas 的代理类,封装了 Canvas 的属性和方法。
  28181. */
  28182. //class laya.resource.HTMLCanvas extends laya.resource.Bitmap
  28183. var HTMLCanvas=(function(_super){
  28184. function HTMLCanvas(createCanvas){
  28185. //this._ctx=null;
  28186. //this._source=null;
  28187. //this._texture=null;
  28188. HTMLCanvas.__super.call(this);
  28189. (createCanvas===void 0)&& (createCanvas=false);
  28190. if(createCanvas)
  28191. this._source=Browser.createElement("canvas");
  28192. else {
  28193. this._source=this;
  28194. }
  28195. this.lock=true;
  28196. }
  28197. __class(HTMLCanvas,'laya.resource.HTMLCanvas',_super);
  28198. var __proto=HTMLCanvas.prototype;
  28199. __proto._getSource=function(){
  28200. return this._source;
  28201. }
  28202. /**
  28203. *清空画布内容。
  28204. */
  28205. __proto.clear=function(){
  28206. this._ctx && this._ctx.clear && this._ctx.clear();
  28207. if (this._texture){
  28208. this._texture.destroy();
  28209. this._texture=null;
  28210. }
  28211. }
  28212. /**
  28213. *销毁。
  28214. */
  28215. __proto.destroy=function(){
  28216. laya.resource.Resource.prototype.destroy.call(this);
  28217. this._setCPUMemory(0);
  28218. this._ctx && this._ctx.destroy();
  28219. this._ctx=null;
  28220. }
  28221. /**
  28222. *释放。
  28223. */
  28224. __proto.release=function(){}
  28225. /**
  28226. *@private
  28227. *设置 Canvas 渲染上下文。是webgl用来替换_ctx用的
  28228. *@param context Canvas 渲染上下文。
  28229. */
  28230. __proto._setContext=function(context){
  28231. this._ctx=context;
  28232. }
  28233. /**
  28234. *获取 Canvas 渲染上下文。
  28235. *@param contextID 上下文ID.
  28236. *@param other
  28237. *@return Canvas 渲染上下文 Context 对象。
  28238. */
  28239. __proto.getContext=function(contextID,other){
  28240. return this.context;
  28241. }
  28242. //TODO:coverage
  28243. __proto.getMemSize=function(){
  28244. return 0;
  28245. }
  28246. /**
  28247. *设置宽高。
  28248. *@param w 宽度。
  28249. *@param h 高度。
  28250. */
  28251. __proto.size=function(w,h){
  28252. if (this._width !=w || this._height !=h || (this._source && (this._source.width !=w || this._source.height !=h))){
  28253. this._width=w;
  28254. this._height=h;
  28255. this._setCPUMemory(w *h *4);
  28256. this._ctx && this._ctx.size && this._ctx.size(w,h);
  28257. this._source && (this._source.height=h,this._source.width=w);
  28258. if (this._texture){
  28259. this._texture.destroy();
  28260. this._texture=null;
  28261. }
  28262. }
  28263. }
  28264. /**
  28265. *获取texture实例
  28266. */
  28267. __proto.getTexture=function(){
  28268. if (!this._texture){
  28269. var bitmap=new Texture2D();
  28270. bitmap.loadImageSource(this.source);
  28271. this._texture=new Texture(bitmap);
  28272. }
  28273. return this._texture;
  28274. }
  28275. /**
  28276. *把图片转换为base64信息
  28277. *@param type "image/png"
  28278. *@param encoderOptions 质量参数,取值范围为0-1
  28279. */
  28280. __proto.toBase64=function(type,encoderOptions){
  28281. if (this._source){
  28282. if (Render.isConchApp){
  28283. if (/*__JS__ */conchConfig.threadMode==2){
  28284. throw "native 2 thread mode use toBase64Async";
  28285. };
  28286. var width=this._ctx._targets.sourceWidth;
  28287. var height=this._ctx._targets.sourceHeight;
  28288. var data=this._ctx._targets.getData(0,0,width,height);
  28289. /*__JS__ */return conchToBase64FlipY ? conchToBase64FlipY(type,encoderOptions,data.buffer,width,height):conchToBase64(type,encoderOptions,data.buffer,width,height);
  28290. }
  28291. else {
  28292. return this._source.toDataURL(type,encoderOptions);
  28293. }
  28294. }
  28295. return null;
  28296. }
  28297. //native多线程
  28298. __proto.toBase64Async=function(type,encoderOptions,callBack){
  28299. var width=this._ctx._targets.sourceWidth;
  28300. var height=this._ctx._targets.sourceHeight;
  28301. this._ctx._targets.getDataAsync(0,0,width,height,function(data){
  28302. /*__JS__ */var base64=conchToBase64FlipY ? conchToBase64FlipY(type,encoderOptions,data.buffer,width,height):conchToBase64(type,encoderOptions,data.buffer,width,height);
  28303. /*__JS__ */callBack(base64);
  28304. });
  28305. }
  28306. /**
  28307. *@inheritDoc
  28308. */
  28309. __getset(0,__proto,'source',function(){
  28310. return this._source;
  28311. });
  28312. /**
  28313. *Canvas 渲染上下文。
  28314. */
  28315. __getset(0,__proto,'context',function(){
  28316. if (this._ctx)return this._ctx;
  28317. if (this._source==this){
  28318. this._ctx=new Context();
  28319. }else {
  28320. this._ctx=this._source.getContext(Render.isConchApp?'layagl':'2d');
  28321. }
  28322. this._ctx._canvas=this;
  28323. return this._ctx;
  28324. });
  28325. return HTMLCanvas;
  28326. })(Bitmap)
  28327. /**
  28328. *@private
  28329. *<p> <code>HTMLImage</code> 用于创建 HTML Image 元素。</p>
  28330. *<p>请使用 <code>HTMLImage.create()<code>获取新实例,不要直接使用 <code>new HTMLImage<code> 。</p>
  28331. */
  28332. //class laya.resource.HTMLImage extends laya.resource.Bitmap
  28333. var HTMLImage=(function(_super){
  28334. function HTMLImage(){
  28335. HTMLImage.__super.call(this);;
  28336. }
  28337. __class(HTMLImage,'laya.resource.HTMLImage',_super);
  28338. HTMLImage.create=function(width,height,format){
  28339. var tex=new Texture2D(width,height,format,false,false);
  28340. tex.wrapModeU=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  28341. tex.wrapModeV=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
  28342. return tex;
  28343. }
  28344. return HTMLImage;
  28345. })(Bitmap)
  28346. /**
  28347. *<p> <code>Stage</code> 是舞台类,显示列表的根节点,所有显示对象都在舞台上显示。通过 Laya.stage 单例访问。</p>
  28348. *<p>Stage提供几种适配模式,不同的适配模式会产生不同的画布大小,画布越大,渲染压力越大,所以要选择合适的适配方案。</p>
  28349. *<p>Stage提供不同的帧率模式,帧率越高,渲染压力越大,越费电,合理使用帧率甚至动态更改帧率有利于改进手机耗电。</p>
  28350. */
  28351. //class laya.display.Stage extends laya.display.Sprite
  28352. var Stage=(function(_super){
  28353. function Stage(){
  28354. /**当前焦点对象,此对象会影响当前键盘事件的派发主体。*/
  28355. this.focus=null;
  28356. /**帧率类型,支持三种模式:fast-60帧(默认),slow-30帧,mouse-30帧(鼠标活动后会自动加速到60,鼠标不动2秒后降低为30帧,以节省消耗),sleep-1帧。*/
  28357. this._frameRate="fast";
  28358. /**设计宽度(初始化时设置的宽度Laya.init(width,height))*/
  28359. this.designWidth=0;
  28360. /**设计高度(初始化时设置的高度Laya.init(width,height))*/
  28361. this.designHeight=0;
  28362. /**画布是否发生翻转。*/
  28363. this.canvasRotation=false;
  28364. /**画布的旋转角度。*/
  28365. this.canvasDegree=0;
  28366. /**
  28367. *<p>设置是否渲染,设置为false,可以停止渲染,画面会停留到最后一次渲染上,减少cpu消耗,此设置不影响时钟。</p>
  28368. *<p>比如非激活状态,可以设置renderingEnabled=false以节省消耗。</p>
  28369. **/
  28370. this.renderingEnabled=true;
  28371. /**是否启用屏幕适配,可以适配后,在某个时候关闭屏幕适配,防止某些操作导致的屏幕意外改变*/
  28372. this.screenAdaptationEnabled=true;
  28373. /**@private */
  28374. this._screenMode="none";
  28375. /**@private */
  28376. this._scaleMode="noscale";
  28377. /**@private */
  28378. this._alignV="top";
  28379. /**@private */
  28380. this._alignH="left";
  28381. /**@private */
  28382. this._bgColor="black";
  28383. /**@private */
  28384. this._mouseMoveTime=0;
  28385. /**@private */
  28386. this._renderCount=0;
  28387. /**@private */
  28388. this._safariOffsetY=0;
  28389. /**@private */
  28390. this._frameStartTime=0;
  28391. /**@private */
  28392. this._isFocused=false;
  28393. /**@private */
  28394. this._isVisibility=false;
  28395. /**@private webgl Color*/
  28396. this._wgColor=[0,0,0,1];
  28397. /**@private */
  28398. this._scene3Ds=[];
  28399. /**@private */
  28400. this._globalRepaintSet=false;
  28401. /**@private */
  28402. this._globalRepaintGet=false;
  28403. /**@private */
  28404. this._curUIBase=null;
  28405. /**使用物理分辨率作为canvas大小,会改进渲染效果,但是会降低性能*/
  28406. this.useRetinalCanvas=false;
  28407. Stage.__super.call(this);
  28408. this.offset=new Point();
  28409. this._canvasTransform=new Matrix();
  28410. this._previousOrientation=Browser.window.orientation;
  28411. this._3dUI=[];
  28412. var _$this=this;
  28413. this.transform=this._createTransform();
  28414. this.mouseEnabled=true;
  28415. this.hitTestPrior=true;
  28416. this.autoSize=false;
  28417. this._setBit(/*laya.Const.DISPLAYED_INSTAGE*/0x80,true);
  28418. this._setBit(/*laya.Const.ACTIVE_INHIERARCHY*/0x02,true);
  28419. this._isFocused=true;
  28420. this._isVisibility=true;
  28421. this.useRetinalCanvas=Config.useRetinalCanvas;
  28422. var window=Browser.window;
  28423. var _me=this;
  28424. window.addEventListener("focus",function(){
  28425. _$this._isFocused=true;
  28426. _me.event(/*laya.events.Event.FOCUS*/"focus");
  28427. _me.event(/*laya.events.Event.FOCUS_CHANGE*/"focuschange");
  28428. });
  28429. window.addEventListener("blur",function(){
  28430. _$this._isFocused=false;
  28431. _me.event(/*laya.events.Event.BLUR*/"blur");
  28432. _me.event(/*laya.events.Event.FOCUS_CHANGE*/"focuschange");
  28433. if (_me._isInputting())Input["inputElement"].target.focus=false;
  28434. });
  28435. var hidden="hidden",state="visibilityState",visibilityChange="visibilitychange";
  28436. var document=window.document;
  28437. if (typeof document.hidden!=="undefined"){
  28438. visibilityChange="visibilitychange";
  28439. state="visibilityState";
  28440. }else if (typeof document.mozHidden!=="undefined"){
  28441. visibilityChange="mozvisibilitychange";
  28442. state="mozVisibilityState";
  28443. }else if (typeof document.msHidden!=="undefined"){
  28444. visibilityChange="msvisibilitychange";
  28445. state="msVisibilityState";
  28446. }else if (typeof document.webkitHidden!=="undefined"){
  28447. visibilityChange="webkitvisibilitychange";
  28448. state="webkitVisibilityState";
  28449. }
  28450. window.document.addEventListener(visibilityChange,visibleChangeFun);
  28451. function visibleChangeFun (){
  28452. if (Browser.document[state]=="hidden"){
  28453. _$this._isVisibility=false;
  28454. if (_me._isInputting())Input["inputElement"].target.focus=false;
  28455. }else {
  28456. _$this._isVisibility=true;
  28457. }
  28458. _$this.renderingEnabled=_$this._isVisibility;
  28459. _me.event(/*laya.events.Event.VISIBILITY_CHANGE*/"visibilitychange");
  28460. }
  28461. window.addEventListener("resize",function(){
  28462. var orientation=Browser.window.orientation;
  28463. if (orientation !=null && orientation !=_$this._previousOrientation && _me._isInputting()){
  28464. Input["inputElement"].target.focus=false;
  28465. }
  28466. _$this._previousOrientation=orientation;
  28467. if (_me._isInputting())return;
  28468. if (Browser.onSafari)
  28469. _me._safariOffsetY=(Browser.window.__innerHeight || Browser.document.body.clientHeight || Browser.document.documentElement.clientHeight)-Browser.window.innerHeight;
  28470. _me._resetCanvas();
  28471. });
  28472. window.addEventListener("orientationchange",function(e){
  28473. _me._resetCanvas();
  28474. });
  28475. this.on(/*laya.events.Event.MOUSE_MOVE*/"mousemove",this,this._onmouseMove);
  28476. if (Browser.onMobile)this.on(/*laya.events.Event.MOUSE_DOWN*/"mousedown",this,this._onmouseMove);
  28477. }
  28478. __class(Stage,'laya.display.Stage',_super);
  28479. var __proto=Stage.prototype;
  28480. /**
  28481. *@private
  28482. *在移动端输入时,输入法弹出期间不进行画布尺寸重置。
  28483. */
  28484. __proto._isInputting=function(){
  28485. return (Browser.onMobile && Input.isInputting);
  28486. }
  28487. /**@private */
  28488. __proto._changeCanvasSize=function(){
  28489. this.setScreenSize(Browser.clientWidth *Browser.pixelRatio,Browser.clientHeight *Browser.pixelRatio);
  28490. }
  28491. /**@private */
  28492. __proto._resetCanvas=function(){
  28493. if (!this.screenAdaptationEnabled)return;
  28494. this._changeCanvasSize();
  28495. }
  28496. /**
  28497. *设置屏幕大小,场景会根据屏幕大小进行适配。可以动态调用此方法,来更改游戏显示的大小。
  28498. *@param screenWidth 屏幕宽度。
  28499. *@param screenHeight 屏幕高度。
  28500. */
  28501. __proto.setScreenSize=function(screenWidth,screenHeight){
  28502. var rotation=false;
  28503. if (this._screenMode!=="none"){
  28504. var screenType=screenWidth / screenHeight < 1 ? "vertical" :"horizontal";
  28505. rotation=screenType!==this._screenMode;
  28506. if (rotation){
  28507. var temp=screenHeight;
  28508. screenHeight=screenWidth;
  28509. screenWidth=temp;
  28510. }
  28511. }
  28512. this.canvasRotation=rotation;
  28513. var canvas=Render._mainCanvas;
  28514. var canvasStyle=canvas.source.style;
  28515. var mat=this._canvasTransform.identity();
  28516. var scaleMode=this._scaleMode;
  28517. var scaleX=screenWidth / this.designWidth;
  28518. var scaleY=screenHeight / this.designHeight;
  28519. var canvasWidth=this.useRetinalCanvas?screenWidth:this.designWidth;
  28520. var canvasHeight=this.useRetinalCanvas?screenHeight:this.designHeight;
  28521. var realWidth=screenWidth;
  28522. var realHeight=screenHeight;
  28523. var pixelRatio=Browser.pixelRatio;
  28524. this._width=this.designWidth;
  28525. this._height=this.designHeight;
  28526. switch (scaleMode){
  28527. case "noscale":
  28528. scaleX=scaleY=1;
  28529. realWidth=this.designWidth;
  28530. realHeight=this.designHeight;
  28531. break ;
  28532. case "showall":
  28533. scaleX=scaleY=Math.min(scaleX,scaleY);
  28534. canvasWidth=realWidth=Math.round(this.designWidth *scaleX);
  28535. canvasHeight=realHeight=Math.round(this.designHeight *scaleY);
  28536. break ;
  28537. case "noborder":
  28538. scaleX=scaleY=Math.max(scaleX,scaleY);
  28539. realWidth=Math.round(this.designWidth *scaleX);
  28540. realHeight=Math.round(this.designHeight *scaleY);
  28541. break ;
  28542. case "full":
  28543. scaleX=scaleY=1;
  28544. this._width=canvasWidth=screenWidth;
  28545. this._height=canvasHeight=screenHeight;
  28546. break ;
  28547. case "fixedwidth":
  28548. scaleY=scaleX;
  28549. this._height=canvasHeight=Math.round(screenHeight / scaleX);
  28550. break ;
  28551. case "fixedheight":
  28552. scaleX=scaleY;
  28553. this._width=canvasWidth=Math.round(screenWidth / scaleY);
  28554. break ;
  28555. case "fixedauto":
  28556. if ((screenWidth / screenHeight)< (this.designWidth / this.designHeight)){
  28557. scaleY=scaleX;
  28558. this._height=canvasHeight=Math.round(screenHeight / scaleX);
  28559. }else {
  28560. scaleX=scaleY;
  28561. this._width=canvasWidth=Math.round(screenWidth / scaleY);
  28562. }
  28563. break ;
  28564. }
  28565. if (this.useRetinalCanvas){
  28566. canvasWidth=screenWidth;
  28567. canvasHeight=screenHeight;
  28568. }
  28569. scaleX *=this.scaleX;
  28570. scaleY *=this.scaleY;
  28571. if (scaleX===1 && scaleY===1){
  28572. this.transform.identity();
  28573. }else {
  28574. this.transform.a=this._formatData(scaleX / (realWidth / canvasWidth));
  28575. this.transform.d=this._formatData(scaleY / (realHeight / canvasHeight));
  28576. }
  28577. canvas.size(canvasWidth,canvasHeight);
  28578. RunDriver.changeWebGLSize(canvasWidth,canvasHeight);
  28579. mat.scale(realWidth / canvasWidth / pixelRatio,realHeight / canvasHeight / pixelRatio);
  28580. if (this._alignH==="left")this.offset.x=0;
  28581. else if (this._alignH==="right")this.offset.x=screenWidth-realWidth;
  28582. else this.offset.x=(screenWidth-realWidth)*0.5 / pixelRatio;
  28583. if (this._alignV==="top")this.offset.y=0;
  28584. else if (this._alignV==="bottom")this.offset.y=screenHeight-realHeight;
  28585. else this.offset.y=(screenHeight-realHeight)*0.5 / pixelRatio;
  28586. this.offset.x=Math.round(this.offset.x);
  28587. this.offset.y=Math.round(this.offset.y);
  28588. mat.translate(this.offset.x,this.offset.y);
  28589. if (this._safariOffsetY)mat.translate(0,this._safariOffsetY);
  28590. this.canvasDegree=0;
  28591. if (rotation){
  28592. if (this._screenMode==="horizontal"){
  28593. mat.rotate(Math.PI / 2);
  28594. mat.translate(screenHeight / pixelRatio,0);
  28595. this.canvasDegree=90;
  28596. }else {
  28597. mat.rotate(-Math.PI / 2);
  28598. mat.translate(0,screenWidth / pixelRatio);
  28599. this.canvasDegree=-90;
  28600. }
  28601. }
  28602. mat.a=this._formatData(mat.a);
  28603. mat.d=this._formatData(mat.d);
  28604. mat.tx=this._formatData(mat.tx);
  28605. mat.ty=this._formatData(mat.ty);
  28606. this.transform=this.transform;
  28607. canvasStyle.transformOrigin=canvasStyle.webkitTransformOrigin=canvasStyle.msTransformOrigin=canvasStyle.mozTransformOrigin=canvasStyle.oTransformOrigin="0px 0px 0px";
  28608. canvasStyle.transform=canvasStyle.webkitTransform=canvasStyle.msTransform=canvasStyle.mozTransform=canvasStyle.oTransform="matrix("+mat.toString()+")";
  28609. if (this._safariOffsetY)mat.translate(0,-this._safariOffsetY);
  28610. mat.translate(parseInt(canvasStyle.left)|| 0,parseInt(canvasStyle.top)|| 0);
  28611. this.visible=true;
  28612. this._repaint |=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02;
  28613. this.event(/*laya.events.Event.RESIZE*/"resize");
  28614. }
  28615. /**@private */
  28616. __proto._formatData=function(value){
  28617. if (Math.abs(value)< 0.000001)return 0;
  28618. if (Math.abs(1-value)< 0.001)return value > 0 ? 1 :-1;
  28619. return value;
  28620. }
  28621. /**@inheritDoc */
  28622. __proto.getMousePoint=function(){
  28623. return Point.TEMP.setTo(this.mouseX,this.mouseY);
  28624. }
  28625. /**@inheritDoc */
  28626. __proto.repaint=function(type){
  28627. (type===void 0)&& (type=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  28628. this._repaint |=type;
  28629. }
  28630. /**@inheritDoc */
  28631. __proto.parentRepaint=function(type){
  28632. (type===void 0)&& (type=/*laya.display.SpriteConst.REPAINT_CACHE*/0x02);
  28633. }
  28634. /**@private */
  28635. __proto._loop=function(){
  28636. this._globalRepaintGet=this._globalRepaintSet;
  28637. this._globalRepaintSet=false;
  28638. this.render(Render._context,0,0);
  28639. return true;
  28640. }
  28641. /**@private */
  28642. __proto.getFrameTm=function(){
  28643. return this._frameStartTime;
  28644. }
  28645. /**@private */
  28646. __proto._onmouseMove=function(e){
  28647. this._mouseMoveTime=Browser.now();
  28648. }
  28649. /**
  28650. *<p>获得距当前帧开始后,过了多少时间,单位为毫秒。</p>
  28651. *<p>可以用来判断函数内时间消耗,通过合理控制每帧函数处理消耗时长,避免一帧做事情太多,对复杂计算分帧处理,能有效降低帧率波动。</p>
  28652. */
  28653. __proto.getTimeFromFrameStart=function(){
  28654. return Browser.now()-this._frameStartTime;
  28655. }
  28656. /**@inheritDoc */
  28657. __proto.render=function(context,x,y){
  28658. Stage._dbgSprite.graphics.clear();
  28659. if (this._frameRate==="sleep"){
  28660. var now=Browser.now();
  28661. if (now-this._frameStartTime >=1000)this._frameStartTime=now;
  28662. else return;
  28663. }else {
  28664. if (!this._visible){
  28665. this._renderCount++;
  28666. if (this._renderCount % 5===0){
  28667. CallLater.I._update();
  28668. Stat.loopCount++;
  28669. this._updateTimers();
  28670. }
  28671. return;
  28672. }
  28673. this._frameStartTime=Browser.now();
  28674. }
  28675. this._renderCount++;
  28676. var frameMode=this._frameRate==="mouse" ? (((this._frameStartTime-this._mouseMoveTime)< 2000)? "fast" :"slow"):this._frameRate;
  28677. var isFastMode=(frameMode!=="slow");
  28678. var isDoubleLoop=(this._renderCount % 2===0);
  28679. Stat.renderSlow=!isFastMode;
  28680. if (isFastMode || isDoubleLoop){
  28681. CallLater.I._update();
  28682. Stat.loopCount++;
  28683. if (this.renderingEnabled){
  28684. for (var i=0,n=this._scene3Ds.length;i < n;i++)
  28685. this._scene3Ds[i]._update();
  28686. context.clear();
  28687. _super.prototype.render.call(this,context,x,y);
  28688. Stat._show && Stat._sp && Stat._sp.render(context,x,y);
  28689. }
  28690. }
  28691. Stage._dbgSprite.render(context,0,0);
  28692. if (isFastMode || !isDoubleLoop){
  28693. if (this.renderingEnabled){
  28694. RunDriver.clear(this._bgColor);
  28695. context.flush();
  28696. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  28697. }
  28698. this._updateTimers();
  28699. }
  28700. }
  28701. __proto.renderToNative=function(context,x,y){
  28702. this._renderCount++;
  28703. if (!this._visible){
  28704. if (this._renderCount % 5===0){
  28705. CallLater.I._update();
  28706. Stat.loopCount++;
  28707. this._updateTimers();
  28708. }
  28709. return;
  28710. }
  28711. CallLater.I._update();
  28712. Stat.loopCount++;
  28713. if (this.renderingEnabled){
  28714. for (var i=0,n=this._scene3Ds.length;i < n;i++)
  28715. this._scene3Ds[i]._update();
  28716. context.clear();
  28717. _super.prototype.render.call(this,context,x,y);
  28718. Stat._show && Stat._sp && Stat._sp.render(context,x,y);
  28719. }
  28720. if (this.renderingEnabled){
  28721. RunDriver.clear(this._bgColor);
  28722. context.flush();
  28723. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  28724. }
  28725. this._updateTimers();
  28726. }
  28727. __proto._updateTimers=function(){
  28728. Laya.systemTimer._update();
  28729. Laya.startTimer._update();
  28730. Laya.physicsTimer._update();
  28731. Laya.updateTimer._update();
  28732. Laya.lateTimer._update();
  28733. Laya.timer._update();
  28734. }
  28735. /**@private */
  28736. __proto._requestFullscreen=function(){
  28737. var element=Browser.document.documentElement;
  28738. if (element.requestFullscreen){
  28739. element.requestFullscreen();
  28740. }else if (element.mozRequestFullScreen){
  28741. element.mozRequestFullScreen();
  28742. }else if (element.webkitRequestFullscreen){
  28743. element.webkitRequestFullscreen();
  28744. }else if (element.msRequestFullscreen){
  28745. element.msRequestFullscreen();
  28746. }
  28747. }
  28748. /**@private */
  28749. __proto._fullScreenChanged=function(){
  28750. Laya.stage.event(/*laya.events.Event.FULL_SCREEN_CHANGE*/"fullscreenchange");
  28751. }
  28752. /**退出全屏模式*/
  28753. __proto.exitFullscreen=function(){
  28754. var document=Browser.document;
  28755. if (document.exitFullscreen){
  28756. document.exitFullscreen();
  28757. }else if (document.mozCancelFullScreen){
  28758. document.mozCancelFullScreen();
  28759. }else if (document.webkitExitFullscreen){
  28760. document.webkitExitFullscreen();
  28761. }
  28762. }
  28763. /**@private */
  28764. __proto.isGlobalRepaint=function(){
  28765. return this._globalRepaintGet;
  28766. }
  28767. /**@private */
  28768. __proto.setGlobalRepaint=function(){
  28769. this._globalRepaintSet=true;
  28770. }
  28771. /**@private */
  28772. __proto.add3DUI=function(uibase){
  28773. var uiroot=/*__JS__ */uibase.rootView;
  28774. if (this._3dUI.indexOf(uiroot)>=0)return;
  28775. this._3dUI.push(uiroot);
  28776. }
  28777. /**@private */
  28778. __proto.remove3DUI=function(uibase){
  28779. var uiroot=/*__JS__ */uibase.rootView;
  28780. var p=this._3dUI.indexOf(uiroot);
  28781. if (p >=0){
  28782. this._3dUI.splice(p,1);
  28783. return true;
  28784. }
  28785. return false;
  28786. }
  28787. /**当前视窗由缩放模式导致的 Y 轴缩放系数。*/
  28788. __getset(0,__proto,'clientScaleY',function(){
  28789. return this._transform ? this._transform.getScaleY():1;
  28790. });
  28791. /**@inheritDoc */
  28792. __getset(0,__proto,'width',_super.prototype._$get_width,function(value){
  28793. this.designWidth=value;
  28794. Laya.superSet(Sprite,this,'width',value);
  28795. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  28796. });
  28797. /**
  28798. *舞台是否获得焦点。
  28799. */
  28800. __getset(0,__proto,'isFocused',function(){
  28801. return this._isFocused;
  28802. });
  28803. /**
  28804. *<p>水平对齐方式。默认值为"left"。</p>
  28805. *<p><ul>取值范围:
  28806. *<li>"left" :居左对齐;</li>
  28807. *<li>"center" :居中对齐;</li>
  28808. *<li>"right" :居右对齐;</li>
  28809. *</ul></p>
  28810. */
  28811. __getset(0,__proto,'alignH',function(){
  28812. return this._alignH;
  28813. },function(value){
  28814. this._alignH=value;
  28815. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  28816. });
  28817. /**@inheritDoc */
  28818. __getset(0,__proto,'height',_super.prototype._$get_height,function(value){
  28819. this.designHeight=value;
  28820. Laya.superSet(Sprite,this,'height',value);
  28821. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  28822. });
  28823. /**@inheritDoc */
  28824. __getset(0,__proto,'transform',function(){
  28825. if (this._tfChanged)this._adjustTransform();
  28826. return (this._transform=this._transform || this._createTransform());
  28827. },_super.prototype._$set_transform);
  28828. /**
  28829. *舞台是否处于可见状态(是否进入后台)。
  28830. */
  28831. __getset(0,__proto,'isVisibility',function(){
  28832. return this._isVisibility;
  28833. });
  28834. /**
  28835. *<p>缩放模式。默认值为 "noscale"。</p>
  28836. *<p><ul>取值范围:
  28837. *<li>"noscale" :不缩放;</li>
  28838. *<li>"exactfit" :全屏不等比缩放;</li>
  28839. *<li>"showall" :最小比例缩放;</li>
  28840. *<li>"noborder" :最大比例缩放;</li>
  28841. *<li>"full" :不缩放,stage的宽高等于屏幕宽高;</li>
  28842. *<li>"fixedwidth" :宽度不变,高度根据屏幕比缩放;</li>
  28843. *<li>"fixedheight" :高度不变,宽度根据屏幕比缩放;</li>
  28844. *<li>"fixedauto" :根据宽高比,自动选择使用fixedwidth或fixedheight;</li>
  28845. *</ul></p>
  28846. */
  28847. __getset(0,__proto,'scaleMode',function(){
  28848. return this._scaleMode;
  28849. },function(value){
  28850. this._scaleMode=value;
  28851. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  28852. });
  28853. /**
  28854. *<p>垂直对齐方式。默认值为"top"。</p>
  28855. *<p><ul>取值范围:
  28856. *<li>"top" :居顶部对齐;</li>
  28857. *<li>"middle" :居中对齐;</li>
  28858. *<li>"bottom" :居底部对齐;</li>
  28859. *</ul></p>
  28860. */
  28861. __getset(0,__proto,'alignV',function(){
  28862. return this._alignV;
  28863. },function(value){
  28864. this._alignV=value;
  28865. Laya.systemTimer.callLater(this,this._changeCanvasSize);
  28866. });
  28867. /**舞台的背景颜色,默认为黑色,null为透明。*/
  28868. __getset(0,__proto,'bgColor',function(){
  28869. return this._bgColor;
  28870. },function(value){
  28871. this._bgColor=value;
  28872. if (value)
  28873. this._wgColor=ColorUtils.create(value).arrColor;
  28874. else
  28875. this._wgColor=null;
  28876. if (Browser.onLimixiu){
  28877. this._wgColor=ColorUtils.create(value).arrColor;
  28878. }else if (value){
  28879. Render.canvas.style.background=value;
  28880. }else {
  28881. Render.canvas.style.background="none";
  28882. }
  28883. });
  28884. /**鼠标在 Stage 上的 X 轴坐标。*/
  28885. __getset(0,__proto,'mouseX',function(){
  28886. return Math.round(MouseManager.instance.mouseX / this.clientScaleX);
  28887. });
  28888. /**鼠标在 Stage 上的 Y 轴坐标。*/
  28889. __getset(0,__proto,'mouseY',function(){
  28890. return Math.round(MouseManager.instance.mouseY / this.clientScaleY);
  28891. });
  28892. /**当前视窗由缩放模式导致的 X 轴缩放系数。*/
  28893. __getset(0,__proto,'clientScaleX',function(){
  28894. return this._transform ? this._transform.getScaleX():1;
  28895. });
  28896. /**
  28897. *<p>场景布局类型。</p>
  28898. *<p><ul>取值范围:
  28899. *<li>"none" :不更改屏幕</li>
  28900. *<li>"horizontal" :自动横屏</li>
  28901. *<li>"vertical" :自动竖屏</li>
  28902. *</ul></p>
  28903. */
  28904. __getset(0,__proto,'screenMode',function(){
  28905. return this._screenMode;
  28906. },function(value){
  28907. this._screenMode=value;
  28908. });
  28909. /**@inheritDoc */
  28910. __getset(0,__proto,'visible',_super.prototype._$get_visible,function(value){
  28911. if (this.visible!==value){
  28912. Laya.superSet(Sprite,this,'visible',value);
  28913. var style=Render._mainCanvas.source.style;
  28914. style.visibility=value ? "visible" :"hidden";
  28915. }
  28916. });
  28917. /**
  28918. *<p>是否开启全屏,用户点击后进入全屏。</p>
  28919. *<p>兼容性提示:部分浏览器不允许点击进入全屏,比如Iphone等。</p>
  28920. */
  28921. __getset(0,__proto,'fullScreenEnabled',null,function(value){
  28922. var document=Browser.document;
  28923. var canvas=Render.canvas;
  28924. if (value){
  28925. canvas.addEventListener('mousedown',this._requestFullscreen);
  28926. canvas.addEventListener('touchstart',this._requestFullscreen);
  28927. document.addEventListener("fullscreenchange",this._fullScreenChanged);
  28928. document.addEventListener("mozfullscreenchange",this._fullScreenChanged);
  28929. document.addEventListener("webkitfullscreenchange",this._fullScreenChanged);
  28930. document.addEventListener("msfullscreenchange",this._fullScreenChanged);
  28931. }else {
  28932. canvas.removeEventListener('mousedown',this._requestFullscreen);
  28933. canvas.removeEventListener('touchstart',this._requestFullscreen);
  28934. document.removeEventListener("fullscreenchange",this._fullScreenChanged);
  28935. document.removeEventListener("mozfullscreenchange",this._fullScreenChanged);
  28936. document.removeEventListener("webkitfullscreenchange",this._fullScreenChanged);
  28937. document.removeEventListener("msfullscreenchange",this._fullScreenChanged);
  28938. }
  28939. });
  28940. __getset(0,__proto,'frameRate',function(){
  28941. if (!Render.isConchApp){
  28942. return this._frameRate;
  28943. }else {
  28944. return /*__JS__ */this._frameRateNative;
  28945. }
  28946. },function(value){
  28947. if (!Render.isConchApp){
  28948. this._frameRate=value;
  28949. }else {
  28950. switch (value){
  28951. case "fast":
  28952. window.conch.config.setLimitFPS(60);
  28953. break ;
  28954. case "mouse":
  28955. window.conch.config.setMouseFrame(2000);
  28956. break ;
  28957. case "slow":
  28958. window.conch.config.setSlowFrame(true);
  28959. break ;
  28960. case "sleep":
  28961. window.conch.config.setLimitFPS(1);
  28962. break ;
  28963. }
  28964. /*__JS__ */this._frameRateNative=value;
  28965. }
  28966. });
  28967. Stage.SCALE_NOSCALE="noscale";
  28968. Stage.SCALE_EXACTFIT="exactfit";
  28969. Stage.SCALE_SHOWALL="showall";
  28970. Stage.SCALE_NOBORDER="noborder";
  28971. Stage.SCALE_FULL="full";
  28972. Stage.SCALE_FIXED_WIDTH="fixedwidth";
  28973. Stage.SCALE_FIXED_HEIGHT="fixedheight";
  28974. Stage.SCALE_FIXED_AUTO="fixedauto";
  28975. Stage.ALIGN_LEFT="left";
  28976. Stage.ALIGN_RIGHT="right";
  28977. Stage.ALIGN_CENTER="center";
  28978. Stage.ALIGN_TOP="top";
  28979. Stage.ALIGN_MIDDLE="middle";
  28980. Stage.ALIGN_BOTTOM="bottom";
  28981. Stage.SCREEN_NONE="none";
  28982. Stage.SCREEN_HORIZONTAL="horizontal";
  28983. Stage.SCREEN_VERTICAL="vertical";
  28984. Stage.FRAME_FAST="fast";
  28985. Stage.FRAME_SLOW="slow";
  28986. Stage.FRAME_MOUSE="mouse";
  28987. Stage.FRAME_SLEEP="sleep";
  28988. __static(Stage,
  28989. ['_dbgSprite',function(){return this._dbgSprite=new Sprite();}
  28990. ]);
  28991. return Stage;
  28992. })(Sprite)
  28993. //class laya.utils.PerfHUD extends laya.display.Sprite
  28994. var PerfHUD=(function(_super){
  28995. function PerfHUD(){
  28996. this.datas=[];
  28997. this.hud_width=800;
  28998. this.hud_height=200;
  28999. this.gMinV=0;
  29000. this.gMaxV=100;
  29001. this.textSpace=40;
  29002. this._now=null;
  29003. this.sttm=0;
  29004. PerfHUD.__super.call(this);
  29005. this.xdata=new Array(PerfHUD.DATANUM);
  29006. this.ydata=new Array(PerfHUD.DATANUM);
  29007. PerfHUD.inst=this;
  29008. this._renderType |=/*laya.display.SpriteConst.CUSTOM*/0x800;
  29009. this._setRenderType(this._renderType);
  29010. this._setCustomRender();
  29011. this.addDataDef(0,0xffffff,'frame',1.0);
  29012. this.addDataDef(1,0x00ff00,'update',1.0);
  29013. this.addDataDef(2,0xff0000,'flush',1.0);
  29014. this._now=/*__JS__ */performance?performance.now.bind(performance):Date.now;
  29015. }
  29016. __class(PerfHUD,'laya.utils.PerfHUD',_super);
  29017. var __proto=PerfHUD.prototype;
  29018. //TODO:coverage
  29019. __proto.now=function(){
  29020. return this._now();
  29021. }
  29022. //TODO:coverage
  29023. __proto.start=function(){
  29024. this.sttm=this._now();
  29025. }
  29026. //TODO:coverage
  29027. __proto.end=function(i){
  29028. var dt=this._now()-this.sttm;
  29029. this.updateValue(i,dt);
  29030. }
  29031. //TODO:coverage
  29032. __proto.config=function(w,h){
  29033. this.hud_width=w;
  29034. this.hud_height=h;
  29035. }
  29036. //TODO:coverage
  29037. __proto.addDataDef=function(id,color,name,scale){
  29038. this.datas[id]=new PerfData(id,color,name,scale);
  29039. }
  29040. //TODO:coverage
  29041. __proto.updateValue=function(id,v){
  29042. this.datas[id].addData(v);
  29043. }
  29044. //TODO:coverage
  29045. __proto.v2y=function(v){
  29046. var bb=this._y+this.hud_height *(1-(v-this.gMinV)/ this.gMaxV);
  29047. return this._y+this.hud_height*(1-(v-this.gMinV)/this.gMaxV);
  29048. }
  29049. //TODO:coverage
  29050. __proto.drawHLine=function(ctx,v,color,text){
  29051. var sx=this._x;
  29052. var ex=this._x+this.hud_width;
  29053. var sy=this.v2y(v);
  29054. ctx.fillText(text,sx,sy-6,null,'green',null);
  29055. sx+=this.textSpace;
  29056. ctx.fillStyle=color;
  29057. ctx.fillRect(sx,sy,this._x+this.hud_width,1,null);
  29058. }
  29059. //TODO:coverage
  29060. __proto.customRender=function(ctx,x,y){
  29061. var now=/*__JS__ */performance.now();;
  29062. if (PerfHUD._lastTm <=0)PerfHUD._lastTm=now;
  29063. this.updateValue(0,now-PerfHUD._lastTm);
  29064. PerfHUD._lastTm=now;
  29065. ctx.save();
  29066. ctx.fillRect(this._x,this._y,this.hud_width,this.hud_height+4,'#000000cc');
  29067. ctx.globalAlpha=0.9;
  29068. this.drawHLine(ctx,0,'green',' 0');
  29069. this.drawHLine(ctx,10,'green',' 10');
  29070. this.drawHLine(ctx,16.667,'red',' ');
  29071. this.drawHLine(ctx,20,'green','50|20');
  29072. this.drawHLine(ctx,16.667 *2,'yellow','');
  29073. this.drawHLine(ctx,16.667 *3,'yellow','');
  29074. this.drawHLine(ctx,16.667 *4,'yellow','');
  29075. this.drawHLine(ctx,50,'green','20|50');
  29076. this.drawHLine(ctx,100,'green','10|100');
  29077. for (var di=0,sz=this.datas.length;di < sz;di++){
  29078. var cd=this.datas[di];
  29079. if (!cd)continue ;
  29080. var dtlen=cd.datas.length;
  29081. var dx=(this.hud_width-this.textSpace)/dtlen;
  29082. var cx=cd.datapos;
  29083. var _cx=this._x+this.textSpace;
  29084. ctx.fillStyle=cd.color;
  29085. for (var dtsz=dtlen;cx < dtsz;cx++){
  29086. var sty=this.v2y(cd.datas[cx] *cd.scale);
  29087. ctx.fillRect(_cx,sty,dx,this.hud_height+this._y-sty,null);
  29088. _cx+=dx;
  29089. }
  29090. for (cx=0;cx < cd.datapos;cx++){
  29091. sty=this.v2y(cd.datas[cx] *cd.scale);
  29092. ctx.fillRect(_cx,sty,dx,this.hud_height+this._y-sty,null);
  29093. _cx+=dx;
  29094. }
  29095. }
  29096. ctx.restore();
  29097. }
  29098. PerfHUD._lastTm=0;
  29099. PerfHUD._now=0;
  29100. PerfHUD.DATANUM=300;
  29101. PerfHUD.inst=null;
  29102. PerfHUD.drawTexTm=0;
  29103. return PerfHUD;
  29104. })(Sprite)
  29105. /**
  29106. *场景类,负责场景创建,加载,销毁等功能
  29107. *场景被从节点移除后,并不会被自动垃圾机制回收,如果想回收,请调用destroy接口,可以通过unDestroyedScenes属性查看还未被销毁的场景列表
  29108. */
  29109. //class laya.display.Scene extends laya.display.Sprite
  29110. var Scene=(function(_super){
  29111. function Scene(){
  29112. /**场景被关闭后,是否自动销毁(销毁节点和使用到的资源),默认为false*/
  29113. this.autoDestroyAtClosed=false;
  29114. /**场景地址*/
  29115. this.url=null;
  29116. /**场景时钟*/
  29117. this._timer=null;
  29118. /**@private */
  29119. this._viewCreated=false;
  29120. /**@private */
  29121. this._idMap=null;
  29122. /**@private */
  29123. this._$componentType="Scene";
  29124. Scene.__super.call(this);
  29125. this._setBit(/*laya.Const.NOT_READY*/0x08,true);
  29126. Scene.unDestroyedScenes.push(this);
  29127. this._scene=this;
  29128. this.createChildren();
  29129. }
  29130. __class(Scene,'laya.display.Scene',_super);
  29131. var __proto=Scene.prototype;
  29132. /**
  29133. *@private 兼容老项目
  29134. */
  29135. __proto.createChildren=function(){}
  29136. /**
  29137. *@private 兼容老项目
  29138. *装载场景视图。用于加载模式。
  29139. *@param path 场景地址。
  29140. */
  29141. __proto.loadScene=function(path){
  29142. var url=path.indexOf(".")>-1 ? path :path+".scene";
  29143. var view=Laya.loader.getRes(url);
  29144. if (view){
  29145. this.createView(view);
  29146. }else {
  29147. Laya.loader.resetProgress();
  29148. var loader=new SceneLoader();
  29149. loader.on(/*laya.events.Event.COMPLETE*/"complete",this,this._onSceneLoaded,[url]);
  29150. loader.load(url);
  29151. }
  29152. }
  29153. //Laya.loader.load(url,Handler.create(this,createView),null,Loader.JSON);
  29154. __proto._onSceneLoaded=function(url){
  29155. this.createView(Loader.getRes(url));
  29156. }
  29157. /**
  29158. *@private 兼容老项目
  29159. *通过视图数据创建视图。
  29160. *@param uiView 视图数据信息。
  29161. */
  29162. __proto.createView=function(view){
  29163. if (view && !this._viewCreated){
  29164. this._viewCreated=true;
  29165. SceneUtils.createByData(this,view);
  29166. }
  29167. }
  29168. /**
  29169. *根据IDE内的节点id,获得节点实例
  29170. */
  29171. __proto.getNodeByID=function(id){
  29172. if (this._idMap)return this._idMap[id];
  29173. return null;
  29174. }
  29175. /**
  29176. *打开场景。【注意】被关闭的场景,如果没有设置autoDestroyAtRemoved=true,则资源可能不能被回收,需要自己手动回收
  29177. *@param closeOther 是否关闭其他场景,默认为true(可选)
  29178. *@param param 打开页面的参数,会传递给onOpened方法(可选)
  29179. */
  29180. __proto.open=function(closeOther,param){
  29181. (closeOther===void 0)&& (closeOther=true);
  29182. if (closeOther)Scene.closeAll();
  29183. Scene.root.addChild(this);
  29184. this.onOpened(param);
  29185. }
  29186. /**场景打开完成后,调用此方法(如果有弹出动画,则在动画完成后执行)*/
  29187. __proto.onOpened=function(param){}
  29188. /**
  29189. *关闭场景
  29190. *【注意】被关闭的场景,如果没有设置autoDestroyAtRemoved=true,则资源可能不能被回收,需要自己手动回收
  29191. *@param type 关闭的原因,会传递给onClosed函数
  29192. */
  29193. __proto.close=function(type){
  29194. this.onClosed(type);
  29195. if (this.autoDestroyAtClosed)this.destroy();
  29196. else this.removeSelf();
  29197. }
  29198. /**关闭完成后,调用此方法(如果有关闭动画,则在动画完成后执行)
  29199. *@param type 如果是点击默认关闭按钮触发,则传入关闭按钮的名字(name),否则为null。
  29200. */
  29201. __proto.onClosed=function(type){}
  29202. /**@inheritDoc */
  29203. __proto.destroy=function(destroyChild){
  29204. (destroyChild===void 0)&& (destroyChild=true);
  29205. this._idMap=null;
  29206. _super.prototype.destroy.call(this,destroyChild);
  29207. var list=laya.display.Scene.unDestroyedScenes;
  29208. for (var i=list.length-1;i >-1;i--){
  29209. if (list[i]===this){
  29210. list.splice(i,1);
  29211. return;
  29212. }
  29213. }
  29214. }
  29215. /**@private */
  29216. __proto._sizeChanged=function(){
  29217. this.event(/*laya.events.Event.RESIZE*/"resize");
  29218. }
  29219. /**@inheritDoc */
  29220. __getset(0,__proto,'scaleX',_super.prototype._$get_scaleX,function(value){
  29221. if (Laya.superGet(Sprite,this,'scaleX')==value)return;
  29222. Laya.superSet(Sprite,this,'scaleX',value);
  29223. this.event(/*laya.events.Event.RESIZE*/"resize");
  29224. });
  29225. /**@inheritDoc */
  29226. __getset(0,__proto,'scaleY',_super.prototype._$get_scaleY,function(value){
  29227. if (Laya.superGet(Sprite,this,'scaleY')==value)return;
  29228. Laya.superSet(Sprite,this,'scaleY',value);
  29229. this.event(/*laya.events.Event.RESIZE*/"resize");
  29230. });
  29231. /**@inheritDoc */
  29232. /**@inheritDoc */
  29233. __getset(0,__proto,'width',function(){
  29234. if (this._width)return this._width;
  29235. var max=0;
  29236. for (var i=this.numChildren-1;i >-1;i--){
  29237. var comp=this.getChildAt(i);
  29238. if (comp._visible){
  29239. max=Math.max(comp._x+comp.width *comp.scaleX,max);
  29240. }
  29241. }
  29242. return max;
  29243. },function(value){
  29244. if (Laya.superGet(Sprite,this,'width')==value)return;
  29245. Laya.superSet(Sprite,this,'width',value);
  29246. this.callLater(this._sizeChanged);
  29247. });
  29248. /**场景时钟*/
  29249. __getset(0,__proto,'timer',function(){
  29250. return this._timer || Laya.timer;
  29251. },function(value){
  29252. this._timer=value;
  29253. });
  29254. /**@inheritDoc */
  29255. /**@inheritDoc */
  29256. __getset(0,__proto,'height',function(){
  29257. if (this._height)return this._height;
  29258. var max=0;
  29259. for (var i=this.numChildren-1;i >-1;i--){
  29260. var comp=this.getChildAt(i);
  29261. if (comp._visible){
  29262. max=Math.max(comp._y+comp.height *comp.scaleY,max);
  29263. }
  29264. }
  29265. return max;
  29266. },function(value){
  29267. if (Laya.superGet(Sprite,this,'height')==value)return;
  29268. Laya.superSet(Sprite,this,'height',value);
  29269. this.callLater(this._sizeChanged);
  29270. });
  29271. /**获取场景根容器*/
  29272. __getset(1,Scene,'root',function(){
  29273. if (!Scene._root){
  29274. Scene._root=Laya.stage.addChild(new Sprite());
  29275. Scene._root.name="root";
  29276. Laya.stage.on("resize",null,resize);
  29277. function resize (){
  29278. Scene._root.size(Laya.stage.width,Laya.stage.height);
  29279. Scene._root.event(/*laya.events.Event.RESIZE*/"resize");
  29280. }
  29281. resize();
  29282. }
  29283. return Scene._root;
  29284. },laya.display.Sprite._$SET_root);
  29285. Scene.load=function(url,complete,progress){
  29286. Laya.loader.resetProgress();
  29287. var loader=new SceneLoader();
  29288. loader.on(/*laya.events.Event.PROGRESS*/"progress",null,onProgress);
  29289. loader.once(/*laya.events.Event.COMPLETE*/"complete",null,create);
  29290. loader.load(url);
  29291. function onProgress (value){
  29292. if (Scene._loadPage)Scene._loadPage.event("progress",value);
  29293. progress && progress.runWith(value);
  29294. }
  29295. function create (){
  29296. loader.off(/*laya.events.Event.PROGRESS*/"progress",null,onProgress);
  29297. var obj=Loader.getRes(url);
  29298. if (!obj)throw "Can not find scene:"+url;
  29299. if (!obj.props)throw "Scene data is error:"+url;
  29300. var runtime=obj.props.runtime ? obj.props.runtime :obj.type;
  29301. var clas=ClassUtils.getClass(runtime);
  29302. if (obj.props.renderType=="instance"){
  29303. var scene=clas.instance || (clas.instance=new clas());
  29304. }else {
  29305. scene=new clas();
  29306. }
  29307. if (scene && (scene instanceof laya.display.Node )){
  29308. scene.url=url;
  29309. if (!scene._getBit(/*laya.Const.NOT_READY*/0x08)){
  29310. complete && complete.runWith(scene);
  29311. }else {
  29312. scene.on("onViewCreated",null,function(){
  29313. complete && complete.runWith(scene)
  29314. })
  29315. scene.createView(obj);
  29316. }
  29317. Scene.hideLoadingPage();
  29318. }else {
  29319. throw "Can not find scene:"+runtime;
  29320. }
  29321. }
  29322. }
  29323. Scene.open=function(url,closeOther,param,complete,progress){
  29324. (closeOther===void 0)&& (closeOther=true);
  29325. if ((param instanceof laya.utils.Handler )){
  29326. var temp=complete;
  29327. complete=param;
  29328. param=temp;
  29329. }
  29330. Scene.showLoadingPage();
  29331. Scene.load(url,Handler.create(null,this._onSceneLoaded,[closeOther,complete,param]),progress);
  29332. }
  29333. Scene._onSceneLoaded=function(closeOther,complete,param,scene){
  29334. scene.open(closeOther,param);
  29335. if (complete)complete.runWith(scene);
  29336. }
  29337. Scene.close=function(url,name){
  29338. (name===void 0)&& (name="");
  29339. var flag=false;
  29340. var list=laya.display.Scene.unDestroyedScenes;
  29341. for (var i=0,n=list.length;i < n;i++){
  29342. var scene=list[i];
  29343. if (scene && scene.parent && scene.url===url && scene.name==name){
  29344. scene.close();
  29345. flag=true;
  29346. }
  29347. }
  29348. return flag;
  29349. }
  29350. Scene.closeAll=function(){
  29351. var root=laya.display.Scene.root;
  29352. for (var i=0,n=root.numChildren;i < n;i++){
  29353. var scene=root.getChildAt(0);
  29354. if ((scene instanceof laya.display.Scene ))scene.close();
  29355. else scene.removeSelf();
  29356. }
  29357. }
  29358. Scene.destroy=function(url,name){
  29359. (name===void 0)&& (name="");
  29360. var flag=false;
  29361. var list=laya.display.Scene.unDestroyedScenes;
  29362. for (var i=0,n=list.length;i < n;i++){
  29363. var scene=list[i];
  29364. if (scene.url===url && scene.name==name){
  29365. scene.destroy();
  29366. flag=true;
  29367. }
  29368. }
  29369. return flag;
  29370. }
  29371. Scene.gc=function(){
  29372. Resource.destroyUnusedResources();
  29373. }
  29374. Scene.setLoadingPage=function(loadPage){
  29375. if (Scene._loadPage !=loadPage){
  29376. Scene._loadPage=loadPage;
  29377. }
  29378. }
  29379. Scene.showLoadingPage=function(param,delay){
  29380. (delay===void 0)&& (delay=500);
  29381. if (Scene._loadPage){
  29382. Laya.systemTimer.clear(null,Scene._showLoading);
  29383. Laya.systemTimer.clear(null,Scene._hideLoading);
  29384. Laya.systemTimer.once(delay,null,Scene._showLoading,[param],false);
  29385. }
  29386. }
  29387. Scene._showLoading=function(param){
  29388. Laya.stage.addChild(Scene._loadPage);
  29389. Scene._loadPage.onOpened(param);
  29390. }
  29391. Scene._hideLoading=function(){
  29392. Scene._loadPage.close();
  29393. }
  29394. Scene.hideLoadingPage=function(delay){
  29395. (delay===void 0)&& (delay=500);
  29396. if (Scene._loadPage){
  29397. Laya.systemTimer.clear(null,Scene._showLoading);
  29398. Laya.systemTimer.clear(null,Scene._hideLoading);
  29399. Laya.systemTimer.once(delay,null,Scene._hideLoading);
  29400. }
  29401. }
  29402. Scene.unDestroyedScenes=[];
  29403. Scene._root=null;
  29404. Scene._loadPage=null;
  29405. return Scene;
  29406. })(Sprite)
  29407. /**
  29408. *<p><code>Input</code> 类用于创建显示对象以显示和输入文本。</p>
  29409. *<p>Input 类封装了原生的文本输入框,由于不同浏览器的差异,会导致此对象的默认文本的位置与用户点击输入时的文本的位置有少许的偏差。</p>
  29410. */
  29411. //class laya.display.Input extends laya.display.Text
  29412. var Input=(function(_super){
  29413. function Input(){
  29414. /**@private */
  29415. this._focus=false;
  29416. /**@private */
  29417. this._multiline=false;
  29418. /**@private */
  29419. this._editable=true;
  29420. /**@private */
  29421. this._restrictPattern=null;
  29422. this._type="text";
  29423. /**输入提示符。*/
  29424. this._prompt='';
  29425. /**输入提示符颜色。*/
  29426. this._promptColor="#A9A9A9";
  29427. this._originColor="#000000";
  29428. this._content='';
  29429. Input.__super.call(this);
  29430. this._maxChars=1E5;
  29431. this._width=100;
  29432. this._height=20;
  29433. this.multiline=false;
  29434. this.overflow=/*laya.display.Text.SCROLL*/"scroll";
  29435. this.on(/*laya.events.Event.MOUSE_DOWN*/"mousedown",this,this._onMouseDown);
  29436. this.on(/*laya.events.Event.UNDISPLAY*/"undisplay",this,this._onUnDisplay);
  29437. }
  29438. __class(Input,'laya.display.Input',_super);
  29439. var __proto=Input.prototype;
  29440. /**
  29441. *设置光标位置和选取字符。
  29442. *@param startIndex 光标起始位置。
  29443. *@param endIndex 光标结束位置。
  29444. */
  29445. __proto.setSelection=function(startIndex,endIndex){
  29446. this.focus=true;
  29447. laya.display.Input.inputElement.selectionStart=startIndex;
  29448. laya.display.Input.inputElement.selectionEnd=endIndex;
  29449. }
  29450. __proto._onUnDisplay=function(e){
  29451. this.focus=false;
  29452. }
  29453. __proto._onMouseDown=function(e){
  29454. this.focus=true;
  29455. }
  29456. /**
  29457. *在输入期间,如果 Input 实例的位置改变,调用_syncInputTransform同步输入框的位置。
  29458. */
  29459. __proto._syncInputTransform=function(){
  29460. var inputElement=this.nativeInput;
  29461. var transform=Utils.getTransformRelativeToWindow(this,this.padding[3],this.padding[0]);
  29462. var inputWid=this._width-this.padding[1]-this.padding[3];
  29463. var inputHei=this._height-this.padding[0]-this.padding[2];
  29464. if (Render.isConchApp){
  29465. inputElement.setScale(transform.scaleX,transform.scaleY);
  29466. inputElement.setSize(inputWid,inputHei);
  29467. inputElement.setPos(transform.x,transform.y);
  29468. }else {
  29469. Input.inputContainer.style.transform=Input.inputContainer.style.webkitTransform="scale("+transform.scaleX+","+transform.scaleY+") rotate("+(Laya.stage.canvasDegree)+"deg)";
  29470. inputElement.style.width=inputWid+'px';
  29471. inputElement.style.height=inputHei+'px';
  29472. Input.inputContainer.style.left=transform.x+'px';
  29473. Input.inputContainer.style.top=transform.y+'px';
  29474. }
  29475. }
  29476. /**选中当前实例的所有文本。*/
  29477. __proto.select=function(){
  29478. this.nativeInput.select();
  29479. }
  29480. __proto._setInputMethod=function(){
  29481. Input.input.parentElement && (Input.inputContainer.removeChild(Input.input));
  29482. Input.area.parentElement && (Input.inputContainer.removeChild(Input.area));
  29483. Input.inputElement=(this._multiline ? Input.area :Input.input);
  29484. Input.inputContainer.appendChild(Input.inputElement);
  29485. if (Text.RightToLeft){
  29486. Input.inputElement.style.direction="rtl";
  29487. }
  29488. }
  29489. __proto._focusIn=function(){
  29490. laya.display.Input.isInputting=true;
  29491. var input=this.nativeInput;
  29492. this._focus=true;
  29493. var cssStyle=input.style;
  29494. cssStyle.whiteSpace=(this.wordWrap ? "pre-wrap" :"nowrap");
  29495. this._setPromptColor();
  29496. input.readOnly=!this._editable;
  29497. if (Render.isConchApp){
  29498. input.setType(this._type);
  29499. input.setForbidEdit(!this._editable);
  29500. }
  29501. input.maxLength=this._maxChars;
  29502. var padding=this.padding;
  29503. input.type=this._type;
  29504. input.value=this._content;
  29505. input.placeholder=this._prompt;
  29506. Laya.stage.off(/*laya.events.Event.KEY_DOWN*/"keydown",this,this._onKeyDown);
  29507. Laya.stage.on(/*laya.events.Event.KEY_DOWN*/"keydown",this,this._onKeyDown);
  29508. Laya.stage.focus=this;
  29509. this.event(/*laya.events.Event.FOCUS*/"focus");
  29510. if (Browser.onPC)input.focus();
  29511. if(!Browser.onMiniGame && !Browser.onBDMiniGame && !Browser.onQGMiniGame && !Browser.onKGMiniGame){
  29512. var temp=this._text;
  29513. this._text=null;
  29514. }
  29515. this.typeset();
  29516. input.setColor(this._originColor);
  29517. input.setFontSize(this.fontSize);
  29518. input.setFontFace(Browser.onIPhone ? (Text.fontFamilyMap[this.font] || this.font):this.font);
  29519. if (Render.isConchApp){
  29520. input.setMultiAble && input.setMultiAble(this._multiline);
  29521. }
  29522. cssStyle.lineHeight=(this.leading+this.fontSize)+"px";
  29523. cssStyle.fontStyle=(this.italic ? "italic" :"normal");
  29524. cssStyle.fontWeight=(this.bold ? "bold" :"normal");
  29525. cssStyle.textAlign=this.align;
  29526. cssStyle.padding="0 0";
  29527. this._syncInputTransform();
  29528. if (!Render.isConchApp && Browser.onPC)
  29529. Laya.systemTimer.frameLoop(1,this,this._syncInputTransform);
  29530. }
  29531. // 设置DOM输入框提示符颜色。
  29532. __proto._setPromptColor=function(){
  29533. Input.promptStyleDOM=Browser.getElementById("promptStyle");
  29534. if (!Input.promptStyleDOM){
  29535. Input.promptStyleDOM=Browser.createElement("style");
  29536. Input.promptStyleDOM.setAttribute("id","promptStyle");
  29537. Browser.document.head.appendChild(Input.promptStyleDOM);
  29538. }
  29539. 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+"}";
  29540. }
  29541. /**@private */
  29542. __proto._focusOut=function(){
  29543. laya.display.Input.isInputting=false;
  29544. this._focus=false;
  29545. this._text=null;
  29546. this._content=this.nativeInput.value;
  29547. if (!this._content){
  29548. Laya.superSet(Text,this,'text',this._prompt);
  29549. Laya.superSet(Text,this,'color',this._promptColor);
  29550. }else {
  29551. Laya.superSet(Text,this,'text',this._content);
  29552. Laya.superSet(Text,this,'color',this._originColor);
  29553. }
  29554. Laya.stage.off(/*laya.events.Event.KEY_DOWN*/"keydown",this,this._onKeyDown);
  29555. Laya.stage.focus=null;
  29556. this.event(/*laya.events.Event.BLUR*/"blur");
  29557. this.event(/*laya.events.Event.CHANGE*/"change");
  29558. if (Render.isConchApp)this.nativeInput.blur();
  29559. Browser.onPC && Laya.systemTimer.clear(this,this._syncInputTransform);
  29560. }
  29561. /**@private */
  29562. __proto._onKeyDown=function(e){
  29563. if (e.keyCode===13){
  29564. if (Browser.onMobile && !this._multiline)
  29565. this.focus=false;
  29566. this.event(/*laya.events.Event.ENTER*/"enter");
  29567. }
  29568. }
  29569. __proto.changeText=function(text){
  29570. this._content=text;
  29571. if (this._focus){
  29572. this.nativeInput.value=text || '';
  29573. this.event(/*laya.events.Event.CHANGE*/"change");
  29574. }else
  29575. _super.prototype.changeText.call(this,text);
  29576. }
  29577. /**@inheritDoc */
  29578. __getset(0,__proto,'color',_super.prototype._$get_color,function(value){
  29579. if (this._focus)
  29580. this.nativeInput.setColor(value);
  29581. Laya.superSet(Text,this,'color',this._content?value:this._promptColor);
  29582. this._originColor=value;
  29583. });
  29584. /**表示是否是多行输入框。*/
  29585. __getset(0,__proto,'multiline',function(){
  29586. return this._multiline;
  29587. },function(value){
  29588. this._multiline=value;
  29589. this.valign=value ? "top" :"middle";
  29590. });
  29591. /**
  29592. *<p>字符数量限制,默认为10000。</p>
  29593. *<p>设置字符数量限制时,小于等于0的值将会限制字符数量为10000。</p>
  29594. */
  29595. __getset(0,__proto,'maxChars',function(){
  29596. return this._maxChars;
  29597. },function(value){
  29598. if (value <=0)
  29599. value=1E5;
  29600. this._maxChars=value;
  29601. });
  29602. /**@inheritDoc */
  29603. __getset(0,__proto,'text',function(){
  29604. if (this._focus)
  29605. return this.nativeInput.value;
  29606. else
  29607. return this._content || "";
  29608. },function(value){
  29609. Laya.superSet(Text,this,'color',this._originColor);
  29610. value+='';
  29611. if (this._focus){
  29612. this.nativeInput.value=value || '';
  29613. this.event(/*laya.events.Event.CHANGE*/"change");
  29614. }else {
  29615. if (!this._multiline)
  29616. value=value.replace(/\r?\n/g,'');
  29617. this._content=value;
  29618. if (value)
  29619. Laya.superSet(Text,this,'text',value);
  29620. else {
  29621. Laya.superSet(Text,this,'text',this._prompt);
  29622. Laya.superSet(Text,this,'color',this.promptColor);
  29623. }
  29624. }
  29625. });
  29626. /**
  29627. *获取对输入框的引用实例。
  29628. */
  29629. __getset(0,__proto,'nativeInput',function(){
  29630. return this._multiline ? Input.area :Input.input;
  29631. });
  29632. // 因此 调用focus接口是无法都在移动平台立刻弹出键盘的
  29633. /**
  29634. *表示焦点是否在此实例上。
  29635. */
  29636. __getset(0,__proto,'focus',function(){
  29637. return this._focus;
  29638. },function(value){
  29639. var input=this.nativeInput;
  29640. if (this._focus!==value){
  29641. if (value){
  29642. if (input.target){
  29643. input.target._focusOut();
  29644. }else {
  29645. this._setInputMethod();
  29646. }
  29647. input.target=this;
  29648. this._focusIn();
  29649. }else {
  29650. input.target=null;
  29651. this._focusOut();
  29652. Browser.document.body.scrollTop=0;
  29653. input.blur();
  29654. if (Render.isConchApp)input.setPos(-10000,-10000);
  29655. else if (Input.inputContainer.contains(input))Input.inputContainer.removeChild(input);
  29656. }
  29657. }
  29658. });
  29659. /**
  29660. *是否可编辑。
  29661. */
  29662. __getset(0,__proto,'editable',function(){
  29663. return this._editable;
  29664. },function(value){
  29665. this._editable=value;
  29666. if (Render.isConchApp){
  29667. Input.input.setForbidEdit(!value);
  29668. }
  29669. });
  29670. /**@inheritDoc */
  29671. __getset(0,__proto,'bgColor',_super.prototype._$get_bgColor,function(value){
  29672. Laya.superSet(Text,this,'bgColor',value);
  29673. if(Render.isConchApp)
  29674. this.nativeInput.setBgColor(value);
  29675. });
  29676. /**限制输入的字符。*/
  29677. __getset(0,__proto,'restrict',function(){
  29678. if (this._restrictPattern){
  29679. return this._restrictPattern.source;
  29680. }
  29681. return "";
  29682. },function(pattern){
  29683. if (pattern){
  29684. pattern="[^"+pattern+"]";
  29685. if (pattern.indexOf("^^")>-1)
  29686. pattern=pattern.replace("^^","");
  29687. this._restrictPattern=new RegExp(pattern,"g");
  29688. }else
  29689. this._restrictPattern=null;
  29690. });
  29691. /**
  29692. *设置输入提示符。
  29693. */
  29694. __getset(0,__proto,'prompt',function(){
  29695. return this._prompt;
  29696. },function(value){
  29697. if (!this._text && value)
  29698. Laya.superSet(Text,this,'color',this._promptColor);
  29699. this.promptColor=this._promptColor;
  29700. if (this._text)
  29701. Laya.superSet(Text,this,'text',(this._text==this._prompt)?value:this._text);
  29702. else
  29703. Laya.superSet(Text,this,'text',value);
  29704. this._prompt=Text.langPacks && Text.langPacks[value] ? Text.langPacks[value] :value;
  29705. });
  29706. /**
  29707. *设置输入提示符颜色。
  29708. */
  29709. __getset(0,__proto,'promptColor',function(){
  29710. return this._promptColor;
  29711. },function(value){
  29712. this._promptColor=value;
  29713. if (!this._content)Laya.superSet(Text,this,'color',value);
  29714. });
  29715. /**
  29716. *<p>输入框类型为Input静态常量之一。</p>
  29717. *<ul>
  29718. *<li>TYPE_TEXT</li>
  29719. *<li>TYPE_PASSWORD</li>
  29720. *<li>TYPE_EMAIL</li>
  29721. *<li>TYPE_URL</li>
  29722. *<li>TYPE_NUMBER</li>
  29723. *<li>TYPE_RANGE</li>
  29724. *<li>TYPE_DATE</li>
  29725. *<li>TYPE_MONTH</li>
  29726. *<li>TYPE_WEEK</li>
  29727. *<li>TYPE_TIME</li>
  29728. *<li>TYPE_DATE_TIME</li>
  29729. *<li>TYPE_DATE_TIME_LOCAL</li>
  29730. *</ul>
  29731. *<p>平台兼容性参见http://www.w3school.com.cn/html5/html_5_form_input_types.asp。</p>
  29732. */
  29733. __getset(0,__proto,'type',function(){
  29734. return this._type;
  29735. },function(value){
  29736. if (value==="password")this._getTextStyle().asPassword=true;
  29737. else this._getTextStyle().asPassword=false;
  29738. this._type=value;
  29739. });
  29740. Input.__init__=function(){
  29741. Input._createInputElement();
  29742. if (Browser.onMobile){
  29743. var isTrue=false;
  29744. if(Browser.onMiniGame || Browser.onBDMiniGame || Browser.onQGMiniGame || Browser.onKGMiniGame){
  29745. isTrue=true;
  29746. }
  29747. Render.canvas.addEventListener(Input.IOS_IFRAME ?(isTrue ? "touchend" :"click"):"touchend",Input._popupInputMethod);
  29748. }
  29749. }
  29750. Input._popupInputMethod=function(e){
  29751. if (!laya.display.Input.isInputting)return;
  29752. var input=laya.display.Input.inputElement;
  29753. input.focus();
  29754. }
  29755. Input._createInputElement=function(){
  29756. Input._initInput(Input.area=Browser.createElement("textarea"));
  29757. Input._initInput(Input.input=Browser.createElement("input"));
  29758. Input.inputContainer=Browser.createElement("div");
  29759. Input.inputContainer.style.position="absolute";
  29760. Input.inputContainer.style.zIndex=1E5;
  29761. Browser.container.appendChild(Input.inputContainer);
  29762. Input.inputContainer.setPos=function (x,y){
  29763. Input.inputContainer.style.left=x+'px';
  29764. Input.inputContainer.style.top=y+'px';
  29765. };
  29766. }
  29767. Input._initInput=function(input){
  29768. var style=input.style;
  29769. 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;";
  29770. style.resize='none';
  29771. style.backgroundColor='transparent';
  29772. style.border='none';
  29773. style.outline='none';
  29774. style.zIndex=1;
  29775. input.addEventListener('input',Input._processInputting);
  29776. input.addEventListener('mousemove',Input._stopEvent);
  29777. input.addEventListener('mousedown',Input._stopEvent);
  29778. input.addEventListener('touchmove',Input._stopEvent);
  29779. input.setFontFace=function (fontFace){input.style.fontFamily=fontFace;};
  29780. if(!Render.isConchApp){
  29781. input.setColor=function (color){input.style.color=color;};
  29782. input.setFontSize=function (fontSize){input.style.fontSize=fontSize+'px';};
  29783. }
  29784. }
  29785. Input._processInputting=function(e){
  29786. var input=laya.display.Input.inputElement.target;
  29787. if (!input)return;
  29788. var value=laya.display.Input.inputElement.value;
  29789. if (input._restrictPattern){
  29790. value=value.replace(/\u2006|\x27/g,"");
  29791. if (input._restrictPattern.test(value)){
  29792. value=value.replace(input._restrictPattern,"");
  29793. laya.display.Input.inputElement.value=value;
  29794. }
  29795. }
  29796. input._text=value;
  29797. input.event(/*laya.events.Event.INPUT*/"input");
  29798. }
  29799. Input._stopEvent=function(e){
  29800. if (e.type=='touchmove')
  29801. e.preventDefault();
  29802. e.stopPropagation && e.stopPropagation();
  29803. }
  29804. Input.TYPE_TEXT="text";
  29805. Input.TYPE_PASSWORD="password";
  29806. Input.TYPE_EMAIL="email";
  29807. Input.TYPE_URL="url";
  29808. Input.TYPE_NUMBER="number";
  29809. Input.TYPE_RANGE="range";
  29810. Input.TYPE_DATE="date";
  29811. Input.TYPE_MONTH="month";
  29812. Input.TYPE_WEEK="week";
  29813. Input.TYPE_TIME="time";
  29814. Input.TYPE_DATE_TIME="datetime";
  29815. Input.TYPE_DATE_TIME_LOCAL="datetime-local";
  29816. Input.TYPE_SEARCH="search";
  29817. Input.input=null;
  29818. Input.area=null;
  29819. Input.inputElement=null;
  29820. Input.inputContainer=null;
  29821. Input.confirmButton=null;
  29822. Input.promptStyleDOM=null;
  29823. Input.inputHeight=45;
  29824. Input.isInputting=false;
  29825. Input.stageMatrix=null;
  29826. __static(Input,
  29827. ['IOS_IFRAME',function(){return this.IOS_IFRAME=(Browser.onIOS && Browser.window.top !=Browser.window.self);}
  29828. ]);
  29829. return Input;
  29830. })(Text)
  29831. /**
  29832. *<p> <code>Animation</code> 是Graphics动画类。实现了基于Graphics的动画创建、播放、控制接口。</p>
  29833. *<p>本类使用了动画模版缓存池,它以一定的内存开销来节省CPU开销,当相同的动画模版被多次使用时,相比于每次都创建新的动画模版,使用动画模版缓存池,只需创建一次,缓存之后多次复用,从而节省了动画模版创建的开销。</p>
  29834. *<p>动画模版缓存池,以key-value键值对存储,key可以自定义,也可以从指定的配置文件中读取,value为对应的动画模版,是一个Graphics对象数组,每个Graphics对象对应一个帧图像,动画的播放实质就是定时切换Graphics对象。</p>
  29835. *<p>使用set source、loadImages(...)、loadAtlas(...)、loadAnimation(...)方法可以创建动画模版。使用play(...)可以播放指定动画。</p>
  29836. *@example <caption>以下示例代码,创建了一个 <code>Text</code> 实例。</caption>
  29837. *package
  29838. *{
  29839. *import laya.display.Animation;
  29840. *import laya.net.Loader;
  29841. *import laya.utils.Handler;
  29842. *public class Animation_Example
  29843. *{
  29844. *public function Animation_Example()
  29845. *{
  29846. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  29847. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  29848. *init();//初始化
  29849. *}
  29850. *private function init():void
  29851. *{
  29852. *var animation:Animation=new Animation();//创建一个 Animation 类的实例对象 animation 。
  29853. *animation.loadAtlas("resource/ani/fighter.json");//加载图集并播放
  29854. *animation.x=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29855. *animation.y=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29856. *animation.interval=50;//设置 animation 对象的动画播放间隔时间,单位:毫秒。
  29857. *animation.play();//播放动画。
  29858. *Laya.stage.addChild(animation);//将 animation 对象添加到显示列表。
  29859. *}
  29860. *}
  29861. *}
  29862. *
  29863. *@example
  29864. *Animation_Example();
  29865. *function Animation_Example(){
  29866. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  29867. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  29868. *init();//初始化
  29869. *}
  29870. *function init()
  29871. *{
  29872. *var animation=new Laya.Animation();//创建一个 Animation 类的实例对象 animation 。
  29873. *animation.loadAtlas("resource/ani/fighter.json");//加载图集并播放
  29874. *animation.x=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29875. *animation.y=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29876. *animation.interval=50;//设置 animation 对象的动画播放间隔时间,单位:毫秒。
  29877. *animation.play();//播放动画。
  29878. *Laya.stage.addChild(animation);//将 animation 对象添加到显示列表。
  29879. *}
  29880. *
  29881. *@example
  29882. *import Animation=laya.display.Animation;
  29883. *class Animation_Example {
  29884. *constructor(){
  29885. *Laya.init(640,800);//设置游戏画布宽高、渲染模式。
  29886. *Laya.stage.bgColor="#efefef";//设置画布的背景颜色。
  29887. *this.init();
  29888. *}
  29889. *private init():void {
  29890. *var animation:Animation=new Laya.Animation();//创建一个 Animation 类的实例对象 animation 。
  29891. *animation.loadAtlas("resource/ani/fighter.json");//加载图集并播放
  29892. *animation.x=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29893. *animation.y=200;//设置 animation 对象的属性 x 的值,用于控制 animation 对象的显示位置。
  29894. *animation.interval=50;//设置 animation 对象的动画播放间隔时间,单位:毫秒。
  29895. *animation.play();//播放动画。
  29896. *Laya.stage.addChild(animation);//将 animation 对象添加到显示列表。
  29897. *}
  29898. *}
  29899. *new Animation_Example();
  29900. */
  29901. //class laya.display.Animation extends laya.display.AnimationBase
  29902. var Animation=(function(_super){
  29903. function Animation(){
  29904. /**@private */
  29905. this._frames=null;
  29906. /**@private */
  29907. this._url=null;
  29908. Animation.__super.call(this);
  29909. this._setControlNode(this);
  29910. }
  29911. __class(Animation,'laya.display.Animation',_super);
  29912. var __proto=Animation.prototype;
  29913. /**@inheritDoc */
  29914. __proto.destroy=function(destroyChild){
  29915. (destroyChild===void 0)&& (destroyChild=true);
  29916. this.stop();
  29917. laya.display.Sprite.prototype.destroy.call(this,destroyChild);
  29918. this._frames=null;
  29919. this._labels=null;
  29920. }
  29921. /**
  29922. *<p>开始播放动画。会在动画模版缓存池中查找key值为name的动画模版,存在则用此动画模版初始化当前序列帧, 如果不存在,则使用当前序列帧。</p>
  29923. *<p>play(...)方法被设计为在创建实例后的任何时候都可以被调用,调用后就处于播放状态,当相应的资源加载完毕、调用动画帧填充方法(set frames)或者将实例显示在舞台上时,会判断是否处于播放状态,如果是,则开始播放。</p>
  29924. *<p>配合wrapMode属性,可设置动画播放顺序类型。</p>
  29925. *@param start (可选)指定动画播放开始的索引(int)或帧标签(String)。帧标签可以通过addLabel(...)和removeLabel(...)进行添加和删除。
  29926. *@param loop (可选)是否循环播放。
  29927. *@param name (可选)动画模板在动画模版缓存池中的key,也可认为是动画名称。如果name为空,则播放当前动画序列帧;如果不为空,则在动画模版缓存池中寻找key值为name的动画模版,如果存在则用此动画模版初始化当前序列帧并播放,如果不存在,则仍然播放当前动画序列帧;如果没有当前动画的帧数据,则不播放,但该实例仍然处于播放状态。
  29928. */
  29929. __proto.play=function(start,loop,name){
  29930. (start===void 0)&& (start=0);
  29931. (loop===void 0)&& (loop=true);
  29932. (name===void 0)&& (name="");
  29933. if (name)this._setFramesFromCache(name,true);
  29934. _super.prototype.play.call(this,start,loop,name);
  29935. }
  29936. /**@private */
  29937. __proto._setFramesFromCache=function(name,showWarn){
  29938. (showWarn===void 0)&& (showWarn=false);
  29939. if (this._url)name=this._url+"#"+name;
  29940. if (name && Animation.framesMap[name]){
  29941. var tAniO=Animation.framesMap[name];
  29942. if ((tAniO instanceof Array)){
  29943. this._frames=Animation.framesMap[name];
  29944. this._count=this._frames.length;
  29945. }else {
  29946. if (tAniO.nodeRoot){
  29947. Animation.framesMap[name]=GraphicAnimation.parseAnimationByData(tAniO);
  29948. tAniO=Animation.framesMap[name];
  29949. }
  29950. this._frames=tAniO.frames;
  29951. this._count=this._frames.length;
  29952. if (!this._frameRateChanged)this._interval=tAniO.interval;
  29953. this._labels=this._copyLabels(tAniO.labels);
  29954. }
  29955. return true;
  29956. }else {
  29957. if (showWarn)console.log("ani not found:",name);
  29958. }
  29959. return false;
  29960. }
  29961. /**@private */
  29962. __proto._copyLabels=function(labels){
  29963. if (!labels)return null;
  29964. var rst;
  29965. rst={};
  29966. var key;
  29967. for (key in labels){
  29968. rst[key]=Utils.copyArray([],labels[key]);
  29969. }
  29970. return rst;
  29971. }
  29972. /**@private */
  29973. __proto._frameLoop=function(){
  29974. if (this._visible && this._style.alpha > 0.01 && this._frames){
  29975. _super.prototype._frameLoop.call(this);
  29976. }
  29977. }
  29978. /**@private */
  29979. __proto._displayToIndex=function(value){
  29980. if (this._frames)this.graphics=this._frames[value];
  29981. }
  29982. /**
  29983. *停止动画播放,并清理对象属性。之后可存入对象池,方便对象复用。
  29984. */
  29985. __proto.clear=function(){
  29986. _super.prototype.clear.call(this);
  29987. this.stop();
  29988. this.graphics=null;
  29989. this._frames=null;
  29990. this._labels=null;
  29991. return this;
  29992. }
  29993. /**
  29994. *<p>根据指定的动画模版初始化当前动画序列帧。选择动画模版的过程如下:1. 动画模版缓存池中key为cacheName的动画模版;2. 如果不存在,则加载指定的图片集合并创建动画模版。注意:只有指定不为空的cacheName,才能将创建好的动画模版以此为key缓存到动画模版缓存池,否则不进行缓存。</p>
  29995. *<p>动画模版缓存池是以一定的内存开销来节省CPU开销,当相同的动画模版被多次使用时,相比于每次都创建新的动画模版,使用动画模版缓存池,只需创建一次,缓存之后多次复用,从而节省了动画模版创建的开销。</p>
  29996. *<p>因为返回值为Animation对象本身,所以可以使用如下语法:loadImages(...).loadImages(...).play(...);。</p>
  29997. *@param urls 图片路径集合。需要创建动画模版时,会以此为数据源。参数形如:[url1,url2,url3,...]。
  29998. *@param cacheName (可选)动画模板在动画模版缓存池中的key。如果此参数不为空,表示使用动画模版缓存池。如果动画模版缓存池中存在key为cacheName的动画模版,则使用此模版。否则,创建新的动画模版,如果cacheName不为空,则以cacheName为key缓存到动画模版缓存池中,如果cacheName为空,不进行缓存。
  29999. *@return 返回Animation对象本身。
  30000. */
  30001. __proto.loadImages=function(urls,cacheName){
  30002. (cacheName===void 0)&& (cacheName="");
  30003. this._url="";
  30004. if (!this._setFramesFromCache(cacheName)){
  30005. this.frames=Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] :Animation.createFrames(urls,cacheName);
  30006. }
  30007. return this;
  30008. }
  30009. /**
  30010. *<p>根据指定的动画模版初始化当前动画序列帧。选择动画模版的过程如下:1. 动画模版缓存池中key为cacheName的动画模版;2. 如果不存在,则加载指定的图集并创建动画模版。</p>
  30011. *<p>注意:只有指定不为空的cacheName,才能将创建好的动画模版以此为key缓存到动画模版缓存池,否则不进行缓存。</p>
  30012. *<p>动画模版缓存池是以一定的内存开销来节省CPU开销,当相同的动画模版被多次使用时,相比于每次都创建新的动画模版,使用动画模版缓存池,只需创建一次,缓存之后多次复用,从而节省了动画模版创建的开销。</p>
  30013. *<p>因为返回值为Animation对象本身,所以可以使用如下语法:loadAtlas(...).loadAtlas(...).play(...);。</p>
  30014. *@param url 图集路径。需要创建动画模版时,会以此为数据源。
  30015. *@param loaded (可选)使用指定图集初始化动画完毕的回调。
  30016. *@param cacheName (可选)动画模板在动画模版缓存池中的key。如果此参数不为空,表示使用动画模版缓存池。如果动画模版缓存池中存在key为cacheName的动画模版,则使用此模版。否则,创建新的动画模版,如果cacheName不为空,则以cacheName为key缓存到动画模版缓存池中,如果cacheName为空,不进行缓存。
  30017. *@return 返回动画本身。
  30018. */
  30019. __proto.loadAtlas=function(url,loaded,cacheName){
  30020. (cacheName===void 0)&& (cacheName="");
  30021. this._url="";
  30022. var _this=this;
  30023. if (!_this._setFramesFromCache(cacheName)){
  30024. function onLoaded (loadUrl){
  30025. if (url===loadUrl){
  30026. _this.frames=Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] :Animation.createFrames(url,cacheName);
  30027. if (loaded)loaded.run();
  30028. }
  30029. }
  30030. if (Loader.getAtlas(url))onLoaded(url);
  30031. else Laya.loader.load(url,Handler.create(null,onLoaded,[url]),null,/*laya.net.Loader.ATLAS*/"atlas");
  30032. }
  30033. return this;
  30034. }
  30035. /**
  30036. *<p>加载并解析由LayaAir IDE制作的动画文件,此文件中可能包含多个动画。默认帧率为在IDE中设计的帧率,如果调用过set interval,则使用此帧间隔对应的帧率。加载后创建动画模版,并缓存到动画模版缓存池,key "url#动画名称" 对应相应动画名称的动画模板,key "url#" 对应动画模版集合的默认动画模版。</p>
  30037. *<p>注意:如果调用本方法前,还没有预加载动画使用的图集,请将atlas参数指定为对应的图集路径,否则会导致动画创建失败。</p>
  30038. *<p>动画模版缓存池是以一定的内存开销来节省CPU开销,当相同的动画模版被多次使用时,相比于每次都创建新的动画模版,使用动画模版缓存池,只需创建一次,缓存之后多次复用,从而节省了动画模版创建的开销。</p>
  30039. *<p>因为返回值为Animation对象本身,所以可以使用如下语法:loadAnimation(...).loadAnimation(...).play(...);。</p>
  30040. *@param url 动画文件路径。可由LayaAir IDE创建并发布。
  30041. *@param loaded (可选)使用指定动画资源初始化动画完毕的回调。
  30042. *@param atlas (可选)动画用到的图集地址(可选)。
  30043. *@return 返回动画本身。
  30044. */
  30045. __proto.loadAnimation=function(url,loaded,atlas){
  30046. this._url=url;
  30047. var _this=this;
  30048. if (!this._actionName)this._actionName="";
  30049. if (!_this._setFramesFromCache(this._actionName)){
  30050. if (!atlas || Loader.getAtlas(atlas)){
  30051. this._loadAnimationData(url,loaded,atlas);
  30052. }else {
  30053. Laya.loader.load(atlas,Handler.create(this,this._loadAnimationData,[url,loaded,atlas]),null,/*laya.net.Loader.ATLAS*/"atlas")
  30054. }
  30055. }else {
  30056. _this._setFramesFromCache(this._actionName,true);
  30057. this.index=0;
  30058. if (loaded)loaded.run();
  30059. }
  30060. return this;
  30061. }
  30062. /**@private */
  30063. __proto._loadAnimationData=function(url,loaded,atlas){
  30064. var _$this=this;
  30065. if (atlas && !Loader.getAtlas(atlas)){
  30066. console.warn("atlas load fail:"+atlas);
  30067. return;
  30068. };
  30069. var _this=this;
  30070. function onLoaded (loadUrl){
  30071. if (!Loader.getRes(loadUrl)){
  30072. if (Animation.framesMap[url+"#"]){
  30073. _this._setFramesFromCache(_$this._actionName,true);
  30074. _$this.index=0;
  30075. _$this._resumePlay();
  30076. if (loaded)loaded.run();
  30077. }
  30078. return;
  30079. }
  30080. if (url===loadUrl){
  30081. var tAniO;
  30082. if (!Animation.framesMap[url+"#"]){
  30083. var aniData=GraphicAnimation.parseAnimationData(Loader.getRes(url));
  30084. if (!aniData)return;
  30085. var aniList=aniData.animationList;
  30086. var i=0,len=aniList.length;
  30087. var defaultO;
  30088. for (i=0;i < len;i++){
  30089. tAniO=aniList[i];
  30090. Animation.framesMap[url+"#"+tAniO.name]=tAniO;
  30091. if (!defaultO)defaultO=tAniO;
  30092. }
  30093. if (defaultO){
  30094. Animation.framesMap[url+"#"]=defaultO;
  30095. _this._setFramesFromCache(_$this._actionName,true);
  30096. _$this.index=0;
  30097. }
  30098. _$this._resumePlay();
  30099. }else {
  30100. _this._setFramesFromCache(_$this._actionName,true);
  30101. _$this.index=0;
  30102. _$this._resumePlay();
  30103. }
  30104. if (loaded)loaded.run();
  30105. }
  30106. Loader.clearRes(url);
  30107. }
  30108. if (Loader.getRes(url))onLoaded(url);
  30109. else Laya.loader.load(url,Handler.create(null,onLoaded,[url]),null,/*laya.net.Loader.JSON*/"json");
  30110. }
  30111. /**
  30112. *当前动画的帧图像数组。本类中,每个帧图像是一个Graphics对象,而动画播放就是定时切换Graphics对象的过程。
  30113. */
  30114. __getset(0,__proto,'frames',function(){
  30115. return this._frames;
  30116. },function(value){
  30117. this._frames=value;
  30118. if (value){
  30119. this._count=value.length;
  30120. if (this._actionName)this._setFramesFromCache(this._actionName,true);
  30121. this.index=this._index;
  30122. }
  30123. });
  30124. /**
  30125. *是否自动播放,默认为false。如果设置为true,则动画被创建并添加到舞台后自动播放。
  30126. */
  30127. __getset(0,__proto,'autoPlay',null,function(value){
  30128. if (value)this.play();
  30129. else this.stop();
  30130. });
  30131. /**
  30132. *<p>动画数据源。</p>
  30133. *<p>类型如下:<br/>
  30134. *1. LayaAir IDE动画文件路径:使用此类型需要预加载所需的图集资源,否则会创建失败,如果不想预加载或者需要创建完毕的回调,请使用loadAnimation(...)方法;<br/>
  30135. *2. 图集路径:使用此类型创建的动画模版不会被缓存到动画模版缓存池中,如果需要缓存或者创建完毕的回调,请使用loadAtlas(...)方法;<br/>
  30136. *3. 图片路径集合:使用此类型创建的动画模版不会被缓存到动画模版缓存池中,如果需要缓存,请使用loadImages(...)方法。</p>
  30137. *@param value 数据源。比如:图集:"xx/a1.atlas";图片集合:"a1.png,a2.png,a3.png";LayaAir IDE动画"xx/a1.ani"。
  30138. */
  30139. __getset(0,__proto,'source',null,function(value){
  30140. if (value.indexOf(".ani")>-1)this.loadAnimation(value);
  30141. else if (value.indexOf(".json")>-1 || value.indexOf("als")>-1 || value.indexOf("atlas")>-1)this.loadAtlas(value);
  30142. else this.loadImages(value.split(","));
  30143. });
  30144. /**
  30145. *设置自动播放的动画名称,在LayaAir IDE中可以创建的多个动画组成的动画集合,选择其中一个动画名称进行播放。
  30146. */
  30147. __getset(0,__proto,'autoAnimation',null,function(value){
  30148. this.play(0,true,value);
  30149. });
  30150. Animation.createFrames=function(url,name){
  30151. var arr;
  30152. if ((typeof url=='string')){
  30153. var atlas=Loader.getAtlas(url);
  30154. if (atlas && atlas.length){
  30155. arr=[];
  30156. for (var i=0,n=atlas.length;i < n;i++){
  30157. var g=new Graphics();
  30158. g.drawImage(Loader.getRes(atlas[i]),0,0);
  30159. arr.push(g);
  30160. }
  30161. }
  30162. }else if ((url instanceof Array)){
  30163. arr=[];
  30164. for (i=0,n=url.length;i < n;i++){
  30165. g=new Graphics();
  30166. g.loadImage(url[i],0,0);
  30167. arr.push(g);
  30168. }
  30169. }
  30170. if (name)Animation.framesMap[name]=arr;
  30171. return arr;
  30172. }
  30173. Animation.clearCache=function(key){
  30174. var cache=Animation.framesMap;
  30175. var val;
  30176. var key2=key+"#";
  30177. for (val in cache){
  30178. if (val===key || val.indexOf(key2)===0){
  30179. delete Animation.framesMap[val];
  30180. }
  30181. }
  30182. }
  30183. Animation.framesMap={};
  30184. return Animation;
  30185. })(AnimationBase)
  30186. //class laya.webgl.shader.d2.Shader2X extends laya.webgl.shader.Shader
  30187. var Shader2X=(function(_super){
  30188. function Shader2X(vs,ps,saveName,nameMap,bindAttrib){
  30189. this._params2dQuick2=null;
  30190. this._shaderValueWidth=0;
  30191. this._shaderValueHeight=0;
  30192. Shader2X.__super.call(this,vs,ps,saveName,nameMap,bindAttrib);
  30193. }
  30194. __class(Shader2X,'laya.webgl.shader.d2.Shader2X',_super);
  30195. var __proto=Shader2X.prototype;
  30196. //TODO:coverage
  30197. __proto._disposeResource=function(){
  30198. _super.prototype._disposeResource.call(this);
  30199. this._params2dQuick2=null;
  30200. }
  30201. //TODO:coverage
  30202. __proto.upload2dQuick2=function(shaderValue){
  30203. this.upload(shaderValue,this._params2dQuick2 || this._make2dQuick2());
  30204. }
  30205. //去掉size的所有的uniform
  30206. __proto._make2dQuick2=function(){
  30207. if (!this._params2dQuick2){
  30208. this._params2dQuick2=[];
  30209. var params=this._params,one;
  30210. for (var i=0,n=params.length;i < n;i++){
  30211. one=params[i];
  30212. if (one.name!=="size")this._params2dQuick2.push(one);
  30213. }
  30214. }
  30215. return this._params2dQuick2;
  30216. }
  30217. Shader2X.create=function(vs,ps,saveName,nameMap,bindAttrib){
  30218. return new Shader2X(vs,ps,saveName,nameMap,bindAttrib);
  30219. }
  30220. return Shader2X;
  30221. })(Shader)
  30222. /**
  30223. *节点关键帧动画播放类。解析播放IDE内制作的节点动画。
  30224. */
  30225. //class laya.display.FrameAnimation extends laya.display.AnimationBase
  30226. var FrameAnimation=(function(_super){
  30227. function FrameAnimation(){
  30228. /**@private id对象表*/
  30229. this._targetDic=null;
  30230. /**@private 动画数据*/
  30231. this._animationData=null;
  30232. /**@private */
  30233. this._usedFrames=null;
  30234. FrameAnimation.__super.call(this);
  30235. if (FrameAnimation._sortIndexFun===null){
  30236. FrameAnimation._sortIndexFun=MathUtil.sortByKey("index",false,true);
  30237. }
  30238. }
  30239. __class(FrameAnimation,'laya.display.FrameAnimation',_super);
  30240. var __proto=FrameAnimation.prototype;
  30241. /**
  30242. *@private
  30243. *初始化动画数据
  30244. *@param targetDic 节点ID索引
  30245. *@param animationData 动画数据
  30246. */
  30247. __proto._setUp=function(targetDic,animationData){
  30248. this._targetDic=targetDic;
  30249. this._animationData=animationData;
  30250. this.interval=1000 / animationData.frameRate;
  30251. if (animationData.parsed){
  30252. this._count=animationData.count;
  30253. this._labels=animationData.labels;
  30254. this._usedFrames=animationData.animationNewFrames;
  30255. }else {
  30256. this._usedFrames=[];
  30257. this._calculateDatas();
  30258. animationData.parsed=true;
  30259. animationData.labels=this._labels;
  30260. animationData.count=this._count;
  30261. animationData.animationNewFrames=this._usedFrames;
  30262. }
  30263. }
  30264. /**@inheritDoc */
  30265. __proto.clear=function(){
  30266. _super.prototype.clear.call(this);
  30267. this._targetDic=null;
  30268. this._animationData=null;
  30269. return this;
  30270. }
  30271. /**@inheritDoc */
  30272. __proto._displayToIndex=function(value){
  30273. if (!this._animationData)return;
  30274. if (value < 0)value=0;
  30275. if (value > this._count)value=this._count;
  30276. var nodes=this._animationData.nodes,i=0,len=nodes.length;
  30277. for (i=0;i < len;i++){
  30278. this._displayNodeToFrame(nodes[i],value);
  30279. }
  30280. }
  30281. /**
  30282. *@private
  30283. *将节点设置到某一帧的状态
  30284. *@param node 节点ID
  30285. *@param frame
  30286. *@param targetDic 节点表
  30287. */
  30288. __proto._displayNodeToFrame=function(node,frame,targetDic){
  30289. if (!targetDic)targetDic=this._targetDic;
  30290. var target=targetDic[node.target];
  30291. if (!target){
  30292. return;
  30293. };
  30294. var frames=node.frames,key,propFrames,value;
  30295. var keys=node.keys,i=0,len=keys.length;
  30296. for (i=0;i < len;i++){
  30297. key=keys[i];
  30298. propFrames=frames[key];
  30299. if (propFrames.length > frame){
  30300. value=propFrames[frame];
  30301. }else {
  30302. value=propFrames[propFrames.length-1];
  30303. }
  30304. target[key]=value;
  30305. };
  30306. var funkeys=node.funkeys;
  30307. len=funkeys.length;
  30308. var funFrames;
  30309. if (len==0)return;
  30310. for (i=0;i < len;i++){
  30311. key=funkeys[i];
  30312. funFrames=frames[key];
  30313. if (funFrames[frame]!==undefined){
  30314. target[key]&&target[key].apply(target,funFrames[frame]);
  30315. }
  30316. }
  30317. }
  30318. /**
  30319. *@private
  30320. *计算帧数据
  30321. */
  30322. __proto._calculateDatas=function(){
  30323. if (!this._animationData)return;
  30324. var nodes=this._animationData.nodes,i=0,len=nodes.length,tNode;
  30325. this._count=0;
  30326. for (i=0;i < len;i++){
  30327. tNode=nodes[i];
  30328. this._calculateKeyFrames(tNode);
  30329. }
  30330. this._count+=1;
  30331. }
  30332. /**
  30333. *@private
  30334. *计算某个节点的帧数据
  30335. */
  30336. __proto._calculateKeyFrames=function(node){
  30337. var keyFrames=node.keyframes,key,tKeyFrames,target=node.target;
  30338. if (!node.frames)node.frames={};
  30339. if (!node.keys)node.keys=[];
  30340. else node.keys.length=0;
  30341. if (!node.funkeys)node.funkeys=[];
  30342. else node.funkeys.length=0;
  30343. if (!node.initValues)node.initValues={};
  30344. for (key in keyFrames){
  30345. var isFun=key.indexOf("()")!=-1;
  30346. tKeyFrames=keyFrames[key];
  30347. if (isFun)key=key.substr(0,key.length-2);
  30348. if (!node.frames[key]){
  30349. node.frames[key]=[];
  30350. }
  30351. if (!isFun){
  30352. if (this._targetDic && this._targetDic[target]){
  30353. node.initValues[key]=this._targetDic[target][key];
  30354. }
  30355. tKeyFrames.sort(FrameAnimation._sortIndexFun);
  30356. node.keys.push(key);
  30357. this._calculateNodePropFrames(tKeyFrames,node.frames[key],key,target);
  30358. }
  30359. else{
  30360. node.funkeys.push(key);
  30361. var map=node.frames[key];
  30362. for (var i=0;i < tKeyFrames.length;i++){
  30363. var temp=tKeyFrames[i];
  30364. map[temp.index]=temp.value;
  30365. if (temp.index > this._count)this._count=temp.index;
  30366. }
  30367. }
  30368. }
  30369. }
  30370. /**
  30371. *重置节点,使节点恢复到动画之前的状态,方便其他动画控制
  30372. */
  30373. __proto.resetNodes=function(){
  30374. if (!this._targetDic)return;
  30375. if (!this._animationData)return;
  30376. var nodes=this._animationData.nodes,i=0,len=nodes.length;
  30377. var tNode;
  30378. var initValues;
  30379. for (i=0;i < len;i++){
  30380. tNode=nodes[i];
  30381. initValues=tNode.initValues;
  30382. if (!initValues)continue ;
  30383. var target=this._targetDic[tNode.target];
  30384. if (!target)continue ;
  30385. var key;
  30386. for (key in initValues){
  30387. target[key]=initValues[key];
  30388. }
  30389. }
  30390. }
  30391. /**
  30392. *@private
  30393. *计算节点某个属性的帧数据
  30394. */
  30395. __proto._calculateNodePropFrames=function(keyframes,frames,key,target){
  30396. var i=0,len=keyframes.length-1;
  30397. frames.length=keyframes[len].index+1;
  30398. for (i=0;i < len;i++){
  30399. this._dealKeyFrame(keyframes[i]);
  30400. this._calculateFrameValues(keyframes[i],keyframes[i+1],frames);
  30401. }
  30402. if (len==0){
  30403. frames[0]=keyframes[0].value;
  30404. if (this._usedFrames)this._usedFrames[keyframes[0].index]=true;
  30405. }
  30406. this._dealKeyFrame(keyframes[i]);
  30407. }
  30408. /**
  30409. *@private
  30410. */
  30411. __proto._dealKeyFrame=function(keyFrame){
  30412. if (keyFrame.label && keyFrame.label !="")this.addLabel(keyFrame.label,keyFrame.index);
  30413. }
  30414. /**
  30415. *@private
  30416. *计算两个关键帧直接的帧数据
  30417. */
  30418. __proto._calculateFrameValues=function(startFrame,endFrame,result){
  30419. var i=0,easeFun;
  30420. var start=startFrame.index,end=endFrame.index;
  30421. var startValue=startFrame.value;
  30422. var dValue=endFrame.value-startFrame.value;
  30423. var dLen=end-start;
  30424. var frames=this._usedFrames;
  30425. if (end > this._count)this._count=end;
  30426. if (startFrame.tween){
  30427. easeFun=Ease[startFrame.tweenMethod];
  30428. if (easeFun==null)easeFun=Ease.linearNone;
  30429. for (i=start;i < end;i++){
  30430. result[i]=easeFun(i-start,startValue,dValue,dLen);
  30431. if (frames)frames[i]=true;
  30432. }
  30433. }else {
  30434. for (i=start;i < end;i++){
  30435. result[i]=startValue;
  30436. }
  30437. }
  30438. if (frames){
  30439. frames[startFrame.index]=true;
  30440. frames[endFrame.index]=true;
  30441. }
  30442. result[endFrame.index]=endFrame.value;
  30443. }
  30444. FrameAnimation._sortIndexFun=null;
  30445. return FrameAnimation;
  30446. })(AnimationBase)
  30447. /**
  30448. *<code>Texture2D</code> 类用于生成2D纹理。
  30449. */
  30450. //class laya.resource.Texture2D extends laya.resource.BaseTexture
  30451. var Texture2D=(function(_super){
  30452. function Texture2D(width,height,format,mipmap,canRead){
  30453. /**@private */
  30454. //this._canRead=false;
  30455. /**@private */
  30456. //this._pixels=null;
  30457. /**@private */
  30458. //this._mipmapCount=0;
  30459. (width===void 0)&& (width=0);
  30460. (height===void 0)&& (height=0);
  30461. (format===void 0)&& (format=1);
  30462. (mipmap===void 0)&& (mipmap=true);
  30463. (canRead===void 0)&& (canRead=false);
  30464. Texture2D.__super.call(this,format,mipmap);
  30465. this._glTextureType=/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1;
  30466. this._width=width;
  30467. this._height=height;
  30468. this._canRead=canRead;
  30469. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,this._wrapModeU);
  30470. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,this._wrapModeV);
  30471. this._setFilterMode(this._filterMode);
  30472. this._setAnisotropy(this._anisoLevel);
  30473. if (this._mipmap){
  30474. this._mipmapCount=/*__JS__ */Math.max(Math.ceil(Math.log2(width))+1,Math.ceil(Math.log2(2))+1);
  30475. for (var i=0;i < this._mipmapCount;i++)
  30476. this._setPixels(null,i,Math.max(width >> i,1),Math.max(height >> i,1));
  30477. this._setGPUMemory(width *height *4 *(1+1 / 3));
  30478. }else {
  30479. this._mipmapCount=1;
  30480. this._setGPUMemory(width *height *4);
  30481. }
  30482. }
  30483. __class(Texture2D,'laya.resource.Texture2D',_super);
  30484. var __proto=Texture2D.prototype;
  30485. /**
  30486. *@private
  30487. */
  30488. __proto._getFormatByteCount=function(){
  30489. switch (this._format){
  30490. case 0:
  30491. return 3;
  30492. case 1:
  30493. return 4;
  30494. case 2:
  30495. return 1;
  30496. default :
  30497. throw "Texture2D: unknown format.";
  30498. }
  30499. }
  30500. /**
  30501. *@private
  30502. */
  30503. __proto._setPixels=function(pixels,miplevel,width,height){
  30504. var gl=LayaGL.instance;
  30505. var textureType=this._glTextureType;
  30506. var glFormat=this._getGLFormat();
  30507. WebGLContext.bindTexture(gl,textureType,this._glTexture);
  30508. if (this.format===/*laya.resource.BaseTexture.FORMAT_R8G8B8*/0){
  30509. gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_ALIGNMENT*/0x0CF5,1);
  30510. gl.texImage2D(textureType,miplevel,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  30511. gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_ALIGNMENT*/0x0CF5,4);
  30512. }else {
  30513. gl.texImage2D(textureType,miplevel,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  30514. }
  30515. }
  30516. /**
  30517. *@private
  30518. */
  30519. __proto._calcualatesCompressedDataSize=function(format,width,height){
  30520. switch (format){
  30521. case 3:
  30522. case 5:
  30523. return ((width+3)>> 2)*((height+3)>> 2)*8;
  30524. case 4:
  30525. return ((width+3)>> 2)*((height+3)>> 2)*16;
  30526. case 11:
  30527. case 12:
  30528. return Math.floor((Math.max(width,8)*Math.max(height,8)*4+7)/ 8);
  30529. case 9:
  30530. case 10:
  30531. return Math.floor((Math.max(width,16)*Math.max(height,8)*2+7)/ 8);
  30532. default :
  30533. return 0;
  30534. }
  30535. }
  30536. /**
  30537. *@private
  30538. */
  30539. __proto._pharseDDS=function(arrayBuffer){
  30540. var FOURCC_DXT1=827611204;
  30541. var FOURCC_DXT5=894720068;
  30542. var DDPF_FOURCC=0x4;
  30543. var DDSD_MIPMAPCOUNT=0x20000;
  30544. var DDS_MAGIC=0x20534444;
  30545. var DDS_HEADER_LENGTH=31;
  30546. var DDS_HEADER_MAGIC=0;
  30547. var DDS_HEADER_SIZE=1;
  30548. var DDS_HEADER_FLAGS=2;
  30549. var DDS_HEADER_HEIGHT=3;
  30550. var DDS_HEADER_WIDTH=4;
  30551. var DDS_HEADER_MIPMAPCOUNT=7;
  30552. var DDS_HEADER_PF_FLAGS=20;
  30553. var DDS_HEADER_PF_FOURCC=21;
  30554. var header=new Int32Array(arrayBuffer,0,DDS_HEADER_LENGTH);
  30555. if (header[DDS_HEADER_MAGIC] !=DDS_MAGIC)
  30556. throw "Invalid magic number in DDS header";
  30557. if (!(header[DDS_HEADER_PF_FLAGS] & DDPF_FOURCC))
  30558. throw "Unsupported format, must contain a FourCC code";
  30559. var compressedFormat=header[DDS_HEADER_PF_FOURCC];
  30560. switch (this._format){
  30561. case 3:
  30562. if (compressedFormat!==FOURCC_DXT1)
  30563. throw "the FourCC code is not same with texture format.";
  30564. break ;
  30565. case 4:
  30566. if (compressedFormat!==FOURCC_DXT5)
  30567. throw "the FourCC code is not same with texture format.";
  30568. break ;
  30569. default :
  30570. throw "unknown texture format.";
  30571. };
  30572. var mipLevels=1;
  30573. if (header[DDS_HEADER_FLAGS] & DDSD_MIPMAPCOUNT){
  30574. mipLevels=Math.max(1,header[DDS_HEADER_MIPMAPCOUNT]);
  30575. if (!this._mipmap)
  30576. throw "the mipmap is not same with Texture2D.";
  30577. }else {
  30578. if (this._mipmap)
  30579. throw "the mipmap is not same with Texture2D.";
  30580. };
  30581. var width=header[DDS_HEADER_WIDTH];
  30582. var height=header[DDS_HEADER_HEIGHT];
  30583. this._width=width;
  30584. this._height=height;
  30585. var dataOffset=header[DDS_HEADER_SIZE]+4;
  30586. this._upLoadCompressedTexImage2D(arrayBuffer,width,height,mipLevels,dataOffset,0);
  30587. }
  30588. /**
  30589. *@private
  30590. */
  30591. __proto._pharseKTX=function(arrayBuffer){
  30592. var ETC_HEADER_LENGTH=13;
  30593. var ETC_HEADER_FORMAT=4;
  30594. var ETC_HEADER_HEIGHT=7;
  30595. var ETC_HEADER_WIDTH=6;
  30596. var ETC_HEADER_MIPMAPCOUNT=11;
  30597. var ETC_HEADER_METADATA=12;
  30598. var id=new Uint8Array(arrayBuffer,0,12);
  30599. 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)
  30600. throw("Invalid fileIdentifier in KTX header");
  30601. var header=new Int32Array(id.buffer,id.length,ETC_HEADER_LENGTH);
  30602. var compressedFormat=header[ETC_HEADER_FORMAT];
  30603. switch (compressedFormat){
  30604. case WebGLContext._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL:
  30605. this._format=5;
  30606. break ;
  30607. default :
  30608. throw "unknown texture format.";
  30609. };
  30610. var mipLevels=header[ETC_HEADER_MIPMAPCOUNT];
  30611. var width=header[ETC_HEADER_WIDTH];
  30612. var height=header[ETC_HEADER_HEIGHT];
  30613. this._width=width;
  30614. this._height=height;
  30615. var dataOffset=64+header[ETC_HEADER_METADATA];
  30616. this._upLoadCompressedTexImage2D(arrayBuffer,width,height,mipLevels,dataOffset,4);
  30617. }
  30618. /**
  30619. *@private
  30620. */
  30621. __proto._pharsePVR=function(arrayBuffer){
  30622. var PVR_FORMAT_2BPP_RGB=0;
  30623. var PVR_FORMAT_2BPP_RGBA=1;
  30624. var PVR_FORMAT_4BPP_RGB=2;
  30625. var PVR_FORMAT_4BPP_RGBA=3;
  30626. var PVR_MAGIC=0x03525650;
  30627. var PVR_HEADER_LENGTH=13;
  30628. var PVR_HEADER_MAGIC=0;
  30629. var PVR_HEADER_FORMAT=2;
  30630. var PVR_HEADER_HEIGHT=6;
  30631. var PVR_HEADER_WIDTH=7;
  30632. var PVR_HEADER_MIPMAPCOUNT=11;
  30633. var PVR_HEADER_METADATA=12;
  30634. var header=new Int32Array(arrayBuffer,0,PVR_HEADER_LENGTH);
  30635. if (header[PVR_HEADER_MAGIC] !=PVR_MAGIC)
  30636. throw("Invalid magic number in PVR header");
  30637. var compressedFormat=header[PVR_HEADER_FORMAT];
  30638. switch (compressedFormat){
  30639. case PVR_FORMAT_2BPP_RGB:
  30640. this._format=9;
  30641. break ;
  30642. case PVR_FORMAT_4BPP_RGB:
  30643. this._format=11;
  30644. break ;
  30645. case PVR_FORMAT_2BPP_RGBA:
  30646. this._format=10;
  30647. break ;
  30648. case PVR_FORMAT_4BPP_RGBA:
  30649. this._format=12;
  30650. break ;
  30651. default :
  30652. throw "Texture2D:unknown PVR format.";
  30653. };
  30654. var mipLevels=header[PVR_HEADER_MIPMAPCOUNT];
  30655. var width=header[PVR_HEADER_WIDTH];
  30656. var height=header[PVR_HEADER_HEIGHT];
  30657. this._width=width;
  30658. this._height=height;
  30659. var dataOffset=header[PVR_HEADER_METADATA]+52;
  30660. this._upLoadCompressedTexImage2D(arrayBuffer,width,height,mipLevels,dataOffset,0);
  30661. }
  30662. /**
  30663. *@private
  30664. */
  30665. __proto._upLoadCompressedTexImage2D=function(data,width,height,miplevelCount,dataOffset,imageSizeOffset){
  30666. var gl=LayaGL.instance;
  30667. var textureType=this._glTextureType;
  30668. WebGLContext.bindTexture(gl,textureType,this._glTexture);
  30669. var glFormat=this._getGLFormat();
  30670. var offset=dataOffset;
  30671. for (var i=0;i < miplevelCount;i++){
  30672. offset+=imageSizeOffset;
  30673. var mipDataSize=this._calcualatesCompressedDataSize(this._format,width,height);
  30674. var mipData=new Uint8Array(data,offset,mipDataSize);
  30675. gl.compressedTexImage2D(textureType,i,glFormat,width,height,0,mipData);
  30676. width=Math.max(width >> 1,1.0);
  30677. height=Math.max(height >> 1,1.0);
  30678. offset+=mipDataSize;
  30679. };
  30680. var memory=offset;
  30681. this._setGPUMemory(memory);
  30682. this._readyed=true;
  30683. this._activeResource();
  30684. }
  30685. /**
  30686. *通过图片源填充纹理,可为HTMLImageElement、HTMLCanvasElement、HTMLVideoElement、ImageBitmap、ImageData,
  30687. *设置之后纹理宽高可能会发生变化。
  30688. */
  30689. __proto.loadImageSource=function(source,premultiplyAlpha){
  30690. (premultiplyAlpha===void 0)&& (premultiplyAlpha=false);
  30691. var width=source.width;
  30692. var height=source.height;
  30693. this._width=width;
  30694. this._height=height;
  30695. if (!(this._isPot(width)&& this._isPot(height)))
  30696. this._mipmap=false;
  30697. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,this._wrapModeU);
  30698. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,this._wrapModeV);
  30699. this._setFilterMode(this._filterMode);
  30700. var gl=LayaGL.instance;
  30701. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  30702. var glFormat=this._getGLFormat();
  30703. if (Render.isConchApp){
  30704. if ((source instanceof laya.resource.HTMLCanvas )){
  30705. gl.texImage2D(this._glTextureType,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source);
  30706. }
  30707. else {
  30708. source.setPremultiplyAlpha(premultiplyAlpha);
  30709. gl.texImage2D(this._glTextureType,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source);
  30710. }
  30711. }else {
  30712. (premultiplyAlpha)&& (gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,true));
  30713. gl.texImage2D(this._glTextureType,0,glFormat,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source);
  30714. (premultiplyAlpha)&& (gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,false));
  30715. }
  30716. if (this._mipmap){
  30717. gl.generateMipmap(this._glTextureType);
  30718. this._setGPUMemory(width *height *4 *(1+1 / 3));
  30719. }else {
  30720. this._setGPUMemory(width *height *4);
  30721. }
  30722. if (this._canRead){
  30723. if (Render.isConchApp){
  30724. this._pixels=new Uint8Array(source._nativeObj.getImageData(0,0,width,height));
  30725. }else {
  30726. Browser.canvas.size(width,height);
  30727. Browser.canvas.clear();
  30728. Browser.context.drawImage(source,0,0,width,height);
  30729. this._pixels=new Uint8Array(Browser.context.getImageData(0,0,width,height).data.buffer);
  30730. }
  30731. }
  30732. this._readyed=true;
  30733. this._activeResource();
  30734. }
  30735. /**
  30736. *通过像素填充纹理。
  30737. *@param pixels 像素。
  30738. *@param miplevel 层级。
  30739. */
  30740. __proto.setPixels=function(pixels,miplevel){
  30741. (miplevel===void 0)&& (miplevel=0);
  30742. if (!pixels)
  30743. throw "Texture2D:pixels can't be null.";
  30744. var width=Math.max(this._width >> miplevel,1);
  30745. var height=Math.max(this._height >> miplevel,1);
  30746. var pixelsCount=width *height *this._getFormatByteCount();
  30747. if (pixels.length < pixelsCount)
  30748. throw "Texture2D:pixels length should at least "+pixelsCount+".";
  30749. this._setPixels(pixels,miplevel,width,height);
  30750. if (this._canRead)
  30751. this._pixels=pixels;
  30752. this._readyed=true;
  30753. this._activeResource();
  30754. }
  30755. /**
  30756. *通过像素填充部分纹理。
  30757. *@param x X轴像素起点。
  30758. *@param y Y轴像素起点。
  30759. *@param width 像素宽度。
  30760. *@param height 像素高度。
  30761. *@param pixels 像素数组。
  30762. *@param miplevel 层级。
  30763. */
  30764. __proto.setSubPixels=function(x,y,width,height,pixels,miplevel){
  30765. (miplevel===void 0)&& (miplevel=0);
  30766. if (!pixels)
  30767. throw "Texture2D:pixels can't be null.";
  30768. var gl=LayaGL.instance;
  30769. var textureType=this._glTextureType;
  30770. WebGLContext.bindTexture(gl,textureType,this._glTexture);
  30771. var glFormat=this._getGLFormat();
  30772. if (this._format===/*laya.resource.BaseTexture.FORMAT_R8G8B8*/0){
  30773. gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_ALIGNMENT*/0x0CF5,1);
  30774. gl.texSubImage2D(textureType,miplevel,x,y,width,height,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  30775. gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_ALIGNMENT*/0x0CF5,4);
  30776. }else {
  30777. gl.texSubImage2D(textureType,miplevel,x,y,width,height,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  30778. }
  30779. this._readyed=true;
  30780. this._activeResource();
  30781. }
  30782. /**
  30783. *通过压缩数据填充纹理。
  30784. *@param data 压缩数据。
  30785. *@param miplevel 层级。
  30786. */
  30787. __proto.setCompressData=function(data){
  30788. switch (this._format){
  30789. case 3:
  30790. case 4:
  30791. this._pharseDDS(data);
  30792. break ;
  30793. case 5:
  30794. this._pharseKTX(data);
  30795. break ;
  30796. case 9:
  30797. case 10:
  30798. case 11:
  30799. case 12:
  30800. this._pharsePVR(data);
  30801. break ;
  30802. default :
  30803. throw "Texture2D:unkonwn format.";
  30804. }
  30805. }
  30806. /**
  30807. *@inheritDoc
  30808. */
  30809. __proto._recoverResource=function(){}
  30810. /**
  30811. *返回图片像素。
  30812. *@return 图片像素。
  30813. */
  30814. __proto.getPixels=function(){
  30815. if (this._canRead)
  30816. return this._pixels;
  30817. else
  30818. throw new Error("Texture2D: must set texture canRead is true.");
  30819. }
  30820. /**
  30821. *获取mipmap数量。
  30822. */
  30823. __getset(0,__proto,'mipmapCount',function(){
  30824. return this._mipmapCount;
  30825. });
  30826. /**
  30827. *@inheritDoc
  30828. */
  30829. __getset(0,__proto,'defaulteTexture',function(){
  30830. return laya.resource.Texture2D.grayTexture;
  30831. });
  30832. Texture2D.__init__=function(){
  30833. var pixels=new Uint8Array(3);
  30834. pixels[0]=128;
  30835. pixels[1]=128;
  30836. pixels[2]=128;
  30837. Texture2D.grayTexture=new Texture2D(1,1,0,false,false);
  30838. Texture2D.grayTexture.setPixels(pixels);
  30839. Texture2D.grayTexture.lock=true;
  30840. pixels[0]=255;
  30841. pixels[1]=255;
  30842. pixels[2]=255;
  30843. Texture2D.whiteTexture=new Texture2D(1,1,0,false,false);
  30844. Texture2D.whiteTexture.setPixels(pixels);
  30845. Texture2D.whiteTexture.lock=true;
  30846. pixels[0]=0;
  30847. pixels[1]=0;
  30848. pixels[2]=0;
  30849. Texture2D.blackTexture=new Texture2D(1,1,0,false,false);
  30850. Texture2D.blackTexture.setPixels(pixels);
  30851. Texture2D.blackTexture.lock=true;
  30852. }
  30853. Texture2D._parse=function(data,propertyParams,constructParams){
  30854. var texture=constructParams ? new Texture2D(constructParams[0],constructParams[1],constructParams[2],constructParams[3],constructParams[4]):new Texture2D(0,0);
  30855. if (propertyParams){
  30856. texture.wrapModeU=propertyParams.wrapModeU;
  30857. texture.wrapModeV=propertyParams.wrapModeV;
  30858. texture.filterMode=propertyParams.filterMode;
  30859. texture.anisoLevel=propertyParams.anisoLevel;
  30860. }
  30861. switch (texture._format){
  30862. case 0:
  30863. case 1:
  30864. texture.loadImageSource(data);
  30865. break ;
  30866. case 3:
  30867. case 4:
  30868. case 5:
  30869. case 9:
  30870. case 10:
  30871. case 11:
  30872. case 12:
  30873. texture.setCompressData(data);
  30874. break ;
  30875. default :
  30876. throw "Texture2D:unkonwn format.";
  30877. }
  30878. return texture;
  30879. }
  30880. Texture2D.load=function(url,complete){
  30881. Laya.loader.create(url,complete,null,/*laya.net.Loader.TEXTURE2D*/"TEXTURE2D");
  30882. }
  30883. Texture2D.grayTexture=null;
  30884. Texture2D.whiteTexture=null;
  30885. Texture2D.blackTexture=null;
  30886. return Texture2D;
  30887. })(BaseTexture)
  30888. /**
  30889. *<code>RenderTexture</code> 类用于创建渲染目标。
  30890. */
  30891. //class laya.resource.RenderTexture2D extends laya.resource.BaseTexture
  30892. var RenderTexture2D=(function(_super){
  30893. function RenderTexture2D(width,height,format,depthStencilFormat){
  30894. //this._lastRT=null;
  30895. //this._lastWidth=NaN;
  30896. //this._lastHeight=NaN;
  30897. /**@private */
  30898. //this._frameBuffer=null;
  30899. /**@private */
  30900. //this._depthStencilBuffer=null;
  30901. /**@private */
  30902. //this._depthStencilFormat=0;
  30903. this._mgrKey=0;
  30904. (format===void 0)&& (format=0);
  30905. (depthStencilFormat===void 0)&& (depthStencilFormat=/*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0);
  30906. RenderTexture2D.__super.call(this,format,false);
  30907. this._glTextureType=/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1;
  30908. this._width=width;
  30909. this._height=height;
  30910. this._depthStencilFormat=depthStencilFormat;
  30911. this._create(width,height);
  30912. this.lock=true;
  30913. }
  30914. __class(RenderTexture2D,'laya.resource.RenderTexture2D',_super);
  30915. var __proto=RenderTexture2D.prototype;
  30916. __proto.getIsReady=function(){
  30917. return true;
  30918. }
  30919. /**
  30920. *@private
  30921. */
  30922. __proto._create=function(width,height){
  30923. var gl=LayaGL.instance;
  30924. this._frameBuffer=gl.createFramebuffer();
  30925. WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
  30926. var glFormat=this._getGLFormat();
  30927. gl.texImage2D(this._glTextureType,0,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,null);
  30928. this._setGPUMemory(width *height *4);
  30929. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
  30930. gl.framebufferTexture2D(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.COLOR_ATTACHMENT0*/0x8CE0,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,this._glTexture,0);
  30931. if (this._depthStencilFormat!==/*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_NONE*/3){
  30932. this._depthStencilBuffer=gl.createRenderbuffer();
  30933. gl.bindRenderbuffer(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
  30934. switch (this._depthStencilFormat){
  30935. case /*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0:
  30936. gl.renderbufferStorage(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,/*laya.webgl.WebGLContext.DEPTH_COMPONENT16*/0x81A5,width,height);
  30937. gl.framebufferRenderbuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.DEPTH_ATTACHMENT*/0x8D00,/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
  30938. break ;
  30939. case /*laya.resource.BaseTexture.FORMAT_STENCIL_8*/1:
  30940. gl.renderbufferStorage(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,/*laya.webgl.WebGLContext.STENCIL_INDEX8*/0x8D48,width,height);
  30941. gl.framebufferRenderbuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.STENCIL_ATTACHMENT*/0x8D20,/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
  30942. break ;
  30943. case /*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_16_8*/2:
  30944. gl.renderbufferStorage(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,/*laya.webgl.WebGLContext.DEPTH_STENCIL*/0x84F9,width,height);
  30945. gl.framebufferRenderbuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.DEPTH_STENCIL_ATTACHMENT*/0x821A,/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
  30946. break ;
  30947. default :
  30948. }
  30949. }
  30950. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  30951. gl.bindRenderbuffer(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,null);
  30952. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,this._wrapModeU);
  30953. this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,this._wrapModeV);
  30954. this._setFilterMode(this._filterMode);
  30955. this._setAnisotropy(this._anisoLevel);
  30956. this._readyed=true;
  30957. this._activeResource();
  30958. }
  30959. /**
  30960. *生成mipMap。
  30961. */
  30962. __proto.generateMipmap=function(){
  30963. if (this._isPot(this.width)&& this._isPot(this.height)){
  30964. this._mipmap=true;
  30965. LayaGL.instance.generateMipmap(this._glTextureType);
  30966. this._setFilterMode(this._filterMode);
  30967. this._setGPUMemory(this.width *this.height *4 *(1+1 / 3));
  30968. }else {
  30969. this._mipmap=false;
  30970. this._setGPUMemory(this.width *this.height *4);
  30971. }
  30972. }
  30973. /**
  30974. *开始绑定。
  30975. */
  30976. __proto.start=function(){
  30977. var gl=LayaGL.instance;
  30978. LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
  30979. this._lastRT=RenderTexture2D._currentActive;
  30980. RenderTexture2D._currentActive=this;
  30981. this._readyed=true;
  30982. gl.viewport(0,0,this._width,this._height);
  30983. this._lastWidth=RenderState2D.width;
  30984. this._lastHeight=RenderState2D.height;
  30985. RenderState2D.width=this._width;
  30986. RenderState2D.height=this._height;
  30987. BaseShader.activeShader=null;
  30988. }
  30989. /**
  30990. *结束绑定。
  30991. */
  30992. __proto.end=function(){
  30993. LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  30994. RenderTexture2D._currentActive=null;
  30995. this._readyed=true;
  30996. }
  30997. /**
  30998. *恢复上一次的RenderTarge.由于使用自己保存的,所以如果被外面打断了的话,会出错。
  30999. */
  31000. __proto.restore=function(){
  31001. var gl=LayaGL.instance;
  31002. if (this._lastRT !=RenderTexture2D._currentActive){
  31003. LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._lastRT?this._lastRT._frameBuffer:null);
  31004. RenderTexture2D._currentActive=this._lastRT;
  31005. }
  31006. this._readyed=true;
  31007. gl.viewport(0,0,this._lastWidth,this._lastHeight);
  31008. RenderState2D.width=this._lastWidth;
  31009. RenderState2D.height=this._lastHeight;
  31010. BaseShader.activeShader=null;
  31011. }
  31012. // gl.viewport(0,0,Laya.stage.width,Laya.stage.height);
  31013. __proto.clear=function(r,g,b,a){
  31014. (r===void 0)&& (r=0.0);
  31015. (g===void 0)&& (g=0.0);
  31016. (b===void 0)&& (b=0.0);
  31017. (a===void 0)&& (a=1.0);
  31018. var gl=LayaGL.instance;
  31019. gl.clearColor(r,g,b,a);
  31020. var clearFlag=/*laya.webgl.WebGLContext.COLOR_BUFFER_BIT*/0x00004000;
  31021. switch (this._depthStencilFormat){
  31022. case /*laya.webgl.WebGLContext.DEPTH_COMPONENT16*/0x81A5:
  31023. clearFlag |=/*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100;
  31024. break ;
  31025. case /*laya.webgl.WebGLContext.STENCIL_INDEX8*/0x8D48:
  31026. clearFlag |=/*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400;
  31027. break ;
  31028. case /*laya.webgl.WebGLContext.DEPTH_STENCIL*/0x84F9:
  31029. clearFlag |=/*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100;
  31030. clearFlag |=/*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400
  31031. break ;
  31032. }
  31033. gl.clear(clearFlag);
  31034. }
  31035. /**
  31036. *获得像素数据。
  31037. *@param x X像素坐标。
  31038. *@param y Y像素坐标。
  31039. *@param width 宽度。
  31040. *@param height 高度。
  31041. *@return 像素数据。
  31042. */
  31043. __proto.getData=function(x,y,width,height){
  31044. if (Render.isConchApp && /*__JS__ */conchConfig.threadMode==2){
  31045. throw "native 2 thread mode use getDataAsync";
  31046. };
  31047. var gl=LayaGL.instance;
  31048. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
  31049. var canRead=(gl.checkFramebufferStatus(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40)===/*laya.webgl.WebGLContext.FRAMEBUFFER_COMPLETE*/0x8CD5);
  31050. if (!canRead){
  31051. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  31052. return null;
  31053. };
  31054. var pixels=new Uint8Array(this._width *this._height *4);
  31055. var glFormat=this._getGLFormat();
  31056. gl.readPixels(x,y,width,height,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels);
  31057. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  31058. return pixels;
  31059. }
  31060. /**
  31061. *native多线程
  31062. */
  31063. __proto.getDataAsync=function(x,y,width,height,callBack){
  31064. var gl=LayaGL.instance;
  31065. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
  31066. gl.readPixelsAsync(x,y,width,height,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,function(data){
  31067. /*__JS__ */callBack(new Uint8Array(data));
  31068. });
  31069. gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
  31070. }
  31071. __proto.recycle=function(){}
  31072. /**
  31073. *@inheritDoc
  31074. */
  31075. __proto._disposeResource=function(){
  31076. if (this._frameBuffer){
  31077. var gl=LayaGL.instance;
  31078. gl.deleteTexture(this._glTexture);
  31079. gl.deleteFramebuffer(this._frameBuffer);
  31080. gl.deleteRenderbuffer(this._depthStencilBuffer);
  31081. this._glTexture=null;
  31082. this._frameBuffer=null;
  31083. this._depthStencilBuffer=null;
  31084. this._setGPUMemory(0);
  31085. }
  31086. }
  31087. /**
  31088. *获取深度格式。
  31089. *@return 深度格式。
  31090. */
  31091. __getset(0,__proto,'depthStencilFormat',function(){
  31092. return this._depthStencilFormat;
  31093. });
  31094. /**
  31095. *@inheritDoc
  31096. */
  31097. __getset(0,__proto,'defaulteTexture',function(){
  31098. return Texture2D.grayTexture;
  31099. });
  31100. /**
  31101. *获取宽度。
  31102. */
  31103. __getset(0,__proto,'sourceWidth',function(){
  31104. return this._width;
  31105. });
  31106. /***
  31107. *获取高度。
  31108. */
  31109. __getset(0,__proto,'sourceHeight',function(){
  31110. return this._height;
  31111. });
  31112. /**
  31113. *获取offsetX。
  31114. */
  31115. __getset(0,__proto,'offsetX',function(){
  31116. return 0;
  31117. });
  31118. /***
  31119. *获取offsetY
  31120. */
  31121. __getset(0,__proto,'offsetY',function(){
  31122. return 0;
  31123. });
  31124. /**
  31125. *获取当前激活的Rendertexture
  31126. */
  31127. __getset(1,RenderTexture2D,'currentActive',function(){
  31128. return RenderTexture2D._currentActive;
  31129. },laya.resource.BaseTexture._$SET_currentActive);
  31130. RenderTexture2D.pushRT=function(){
  31131. RenderTexture2D.rtStack.push({rt:RenderTexture2D._currentActive,w:RenderState2D.width,h:RenderState2D.height});
  31132. }
  31133. RenderTexture2D.popRT=function(){
  31134. var gl=LayaGL.instance;
  31135. var top=RenderTexture2D.rtStack.pop();
  31136. if (top){
  31137. if (RenderTexture2D._currentActive !=top.rt){
  31138. LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,top.rt?top.rt._frameBuffer:null);
  31139. RenderTexture2D._currentActive=top.rt;
  31140. }
  31141. gl.viewport(0,0,top.w,top.h);
  31142. RenderState2D.width=top.w;
  31143. RenderState2D.height=top.h;
  31144. }
  31145. }
  31146. RenderTexture2D._currentActive=null;
  31147. RenderTexture2D.rtStack=[];
  31148. __static(RenderTexture2D,
  31149. ['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];}
  31150. ]);
  31151. return RenderTexture2D;
  31152. })(BaseTexture)
  31153. /**
  31154. *Graphics动画解析器
  31155. *@private
  31156. */
  31157. //class laya.utils.GraphicAnimation extends laya.display.FrameAnimation
  31158. var GraphicAnimation=(function(_super){
  31159. var GraphicNode;
  31160. function GraphicAnimation(){
  31161. /**@private */
  31162. this.animationList=null;
  31163. /**@private */
  31164. this.animationDic=null;
  31165. /**@private */
  31166. this._nodeList=null;
  31167. /**@private */
  31168. this._nodeDefaultProps=null;
  31169. /**@private */
  31170. this._gList=null;
  31171. /**@private */
  31172. this._nodeIDAniDic={};
  31173. /**@private */
  31174. this._rootNode=null;
  31175. /**@private */
  31176. this._nodeGDic=null;
  31177. GraphicAnimation.__super.call(this);
  31178. }
  31179. __class(GraphicAnimation,'laya.utils.GraphicAnimation',_super);
  31180. var __proto=GraphicAnimation.prototype;
  31181. /**@private */
  31182. __proto._parseNodeList=function(uiView){
  31183. if (!this._nodeList)this._nodeList=[];
  31184. this._nodeDefaultProps[uiView.compId]=uiView.props;
  31185. if (uiView.compId)this._nodeList.push(uiView.compId);
  31186. var childs=uiView.child;
  31187. if (childs){
  31188. var i=0,len=childs.length;
  31189. for (i=0;i < len;i++){
  31190. this._parseNodeList(childs[i]);
  31191. }
  31192. }
  31193. }
  31194. /**@private */
  31195. __proto._calGraphicData=function(aniData){
  31196. this._setUp(null,aniData);
  31197. this._createGraphicData();
  31198. if (this._nodeIDAniDic){
  31199. var key;
  31200. for (key in this._nodeIDAniDic){
  31201. this._nodeIDAniDic[key]=null;
  31202. }
  31203. }
  31204. }
  31205. /**@private */
  31206. __proto._createGraphicData=function(){
  31207. var gList=[];
  31208. var i=0,len=this.count;
  31209. var animationDataNew=this._usedFrames;
  31210. if (!animationDataNew)animationDataNew=[];
  31211. var preGraphic;
  31212. for (i=0;i < len;i++){
  31213. if (animationDataNew[i] || !preGraphic){
  31214. preGraphic=this._createFrameGraphic(i);
  31215. }
  31216. gList.push(preGraphic);
  31217. }
  31218. this._gList=gList;
  31219. }
  31220. /**@private */
  31221. __proto._createFrameGraphic=function(frame){
  31222. var g=new Graphics();
  31223. if (!GraphicAnimation._rootMatrix)GraphicAnimation._rootMatrix=new Matrix();
  31224. this._updateNodeGraphic(this._rootNode,frame,GraphicAnimation._rootMatrix,g);
  31225. return g;
  31226. }
  31227. __proto._updateNodeGraphic=function(node,frame,parentTransfrom,g,alpha){
  31228. (alpha===void 0)&& (alpha=1);
  31229. var tNodeG;
  31230. tNodeG=this._nodeGDic[node.compId]=this._getNodeGraphicData(node.compId,frame,this._nodeGDic[node.compId]);
  31231. if (!tNodeG.resultTransform)
  31232. tNodeG.resultTransform=new Matrix();
  31233. var tResultTransform;
  31234. tResultTransform=tNodeG.resultTransform;
  31235. Matrix.mul(tNodeG.transform,parentTransfrom,tResultTransform);
  31236. var tTex;
  31237. var tGraphicAlpha=tNodeG.alpha *alpha;
  31238. if (tGraphicAlpha < 0.01)return;
  31239. if (tNodeG.skin){
  31240. tTex=this._getTextureByUrl(tNodeG.skin);
  31241. if (tTex){
  31242. if (tResultTransform._checkTransform()){
  31243. g.drawTexture(tTex,0,0,tNodeG.width,tNodeG.height,tResultTransform,tGraphicAlpha);
  31244. tNodeG.resultTransform=null;
  31245. }else {
  31246. g.drawTexture(tTex,tResultTransform.tx,tResultTransform.ty,tNodeG.width,tNodeG.height,null,tGraphicAlpha);
  31247. }
  31248. }
  31249. };
  31250. var childs=node.child;
  31251. if (!childs)return;
  31252. var i=0,len=0;
  31253. len=childs.length;
  31254. for (i=0;i < len;i++){
  31255. this._updateNodeGraphic(childs[i],frame,tResultTransform,g,tGraphicAlpha);
  31256. }
  31257. }
  31258. __proto._updateNoChilds=function(tNodeG,g){
  31259. if (!tNodeG.skin)return;
  31260. var tTex=this._getTextureByUrl(tNodeG.skin);
  31261. if (!tTex)return;
  31262. var tTransform=tNodeG.transform;
  31263. tTransform._checkTransform();
  31264. var onlyTranslate=false;
  31265. onlyTranslate=!tTransform._bTransform;
  31266. if (!onlyTranslate){
  31267. g.drawTexture(tTex,0,0,tNodeG.width,tNodeG.height,tTransform.clone(),tNodeG.alpha);
  31268. }else {
  31269. g.drawTexture(tTex,tTransform.tx,tTransform.ty,tNodeG.width,tNodeG.height,null,tNodeG.alpha);
  31270. }
  31271. }
  31272. __proto._updateNodeGraphic2=function(node,frame,g){
  31273. var tNodeG;
  31274. tNodeG=this._nodeGDic[node.compId]=this._getNodeGraphicData(node.compId,frame,this._nodeGDic[node.compId]);
  31275. if (!node.child){
  31276. this._updateNoChilds(tNodeG,g);
  31277. return;
  31278. };
  31279. var tTransform=tNodeG.transform;
  31280. tTransform._checkTransform();
  31281. var onlyTranslate=false;
  31282. onlyTranslate=!tTransform._bTransform;
  31283. var hasTrans=false;
  31284. hasTrans=onlyTranslate && (tTransform.tx !=0 || tTransform.ty !=0);
  31285. var ifSave=false;
  31286. ifSave=(tTransform._bTransform)|| tNodeG.alpha !=1;
  31287. if (ifSave)g.save();
  31288. if (tNodeG.alpha !=1)g.alpha(tNodeG.alpha);
  31289. if (!onlyTranslate)g.transform(tTransform.clone());
  31290. else if (hasTrans)g.translate(tTransform.tx,tTransform.ty);
  31291. var childs=node.child;
  31292. var tTex;
  31293. if (tNodeG.skin){
  31294. tTex=this._getTextureByUrl(tNodeG.skin);
  31295. if (tTex){
  31296. g.drawImage(tTex,0,0,tNodeG.width,tNodeG.height);
  31297. }
  31298. }
  31299. if (childs){
  31300. var i=0,len=0;
  31301. len=childs.length;
  31302. for (i=0;i < len;i++){
  31303. this._updateNodeGraphic2(childs[i],frame,g);
  31304. }
  31305. }
  31306. if (ifSave){
  31307. g.restore();
  31308. }else {
  31309. if (!onlyTranslate){
  31310. g.transform(tTransform.clone().invert());
  31311. }else if (hasTrans){
  31312. g.translate(-tTransform.tx,-tTransform.ty);
  31313. }
  31314. }
  31315. }
  31316. /**@private */
  31317. __proto._calculateKeyFrames=function(node){
  31318. _super.prototype._calculateKeyFrames.call(this,node);
  31319. this._nodeIDAniDic[node.target]=node;
  31320. }
  31321. /**@private */
  31322. __proto.getNodeDataByID=function(nodeID){
  31323. return this._nodeIDAniDic[nodeID];
  31324. }
  31325. /**@private */
  31326. __proto._getParams=function(obj,params,frame,obj2){
  31327. var rst=GraphicAnimation._temParam;
  31328. rst.length=params.length;
  31329. var i=0,len=params.length;
  31330. for (i=0;i < len;i++){
  31331. rst[i]=this._getObjVar(obj,params[i][0],frame,params[i][1],obj2);
  31332. }
  31333. return rst;
  31334. }
  31335. /**@private */
  31336. __proto._getObjVar=function(obj,key,frame,noValue,obj2){
  31337. if (obj.hasOwnProperty(key)){
  31338. var vArr=obj[key];
  31339. if (frame >=vArr.length)frame=vArr.length-1;
  31340. return obj[key][frame];
  31341. }
  31342. if (obj2.hasOwnProperty(key)){
  31343. return obj2[key];
  31344. }
  31345. return noValue;
  31346. }
  31347. __proto._getNodeGraphicData=function(nodeID,frame,rst){
  31348. if (!rst)
  31349. rst=new GraphicNode();
  31350. if (!rst.transform){
  31351. rst.transform=new Matrix();
  31352. }else {
  31353. rst.transform.identity();
  31354. };
  31355. var node=this.getNodeDataByID(nodeID);
  31356. if (!node)return rst;
  31357. var frameData=node.frames;
  31358. var params=this._getParams(frameData,GraphicAnimation._drawTextureCmd,frame,this._nodeDefaultProps[nodeID]);
  31359. var url=params[0];
  31360. var width=NaN,height=NaN;
  31361. var px=params[5],py=params[6];
  31362. var aX=params[13],aY=params[14];
  31363. var sx=params[7],sy=params[8];
  31364. var rotate=params[9];
  31365. var skewX=params[11],skewY=params[12]
  31366. width=params[3];
  31367. height=params[4];
  31368. if (width==0 || height==0)url=null;
  31369. if (width==-1)width=0;
  31370. if (height==-1)height=0;
  31371. var tex;
  31372. rst.skin=url;
  31373. rst.width=width;
  31374. rst.height=height;
  31375. if (url){
  31376. tex=this._getTextureByUrl(url);
  31377. if (tex){
  31378. if (!width)
  31379. width=tex.sourceWidth;
  31380. if (!height)
  31381. height=tex.sourceHeight;
  31382. }else {
  31383. console.warn("lost skin:",url,",you may load pics first");
  31384. }
  31385. }
  31386. rst.alpha=params[10];
  31387. var m=rst.transform;
  31388. if (aX !=0){
  31389. px=aX *width;
  31390. }
  31391. if (aY !=0){
  31392. py=aY *height;
  31393. }
  31394. if (px !=0 || py !=0){
  31395. m.translate(-px,-py);
  31396. };
  31397. var tm=null;
  31398. if (rotate || sx!==1 || sy!==1 || skewX || skewY){
  31399. tm=GraphicAnimation._tempMt;
  31400. tm.identity();
  31401. tm._bTransform=true;
  31402. var skx=(rotate-skewX)*0.0174532922222222;
  31403. var sky=(rotate+skewY)*0.0174532922222222;
  31404. var cx=Math.cos(sky);
  31405. var ssx=Math.sin(sky);
  31406. var cy=Math.sin(skx);
  31407. var ssy=Math.cos(skx);
  31408. tm.a=sx *cx;
  31409. tm.b=sx *ssx;
  31410. tm.c=-sy *cy;
  31411. tm.d=sy *ssy;
  31412. tm.tx=tm.ty=0;
  31413. }
  31414. if (tm){
  31415. m=Matrix.mul(m,tm,m);
  31416. }
  31417. m.translate(params[1],params[2]);
  31418. return rst;
  31419. }
  31420. /**@private */
  31421. __proto._getTextureByUrl=function(url){
  31422. return Loader.getRes(url);
  31423. }
  31424. /**@private */
  31425. __proto.setAniData=function(uiView,aniName){
  31426. if (uiView.animations){
  31427. this._nodeDefaultProps={};
  31428. this._nodeGDic={};
  31429. if (this._nodeList)this._nodeList.length=0;
  31430. this._rootNode=uiView;
  31431. this._parseNodeList(uiView);
  31432. var aniDic={};
  31433. var anilist=[];
  31434. var animations=uiView.animations;
  31435. var i=0,len=animations.length;
  31436. var tAniO;
  31437. for (i=0;i < len;i++){
  31438. tAniO=animations[i];
  31439. this._labels=null;
  31440. if (aniName && aniName !=tAniO.name){
  31441. continue ;
  31442. }
  31443. if (!tAniO)
  31444. continue ;
  31445. try {
  31446. this._calGraphicData(tAniO);
  31447. }catch (e){
  31448. console.warn("parse animation fail:"+tAniO.name+",empty animation created");
  31449. this._gList=[];
  31450. };
  31451. var frameO={};
  31452. frameO.interval=1000 / tAniO["frameRate"];
  31453. frameO.frames=this._gList;
  31454. frameO.labels=this._labels;
  31455. frameO.name=tAniO.name;
  31456. anilist.push(frameO);
  31457. aniDic[tAniO.name]=frameO;
  31458. }
  31459. this.animationList=anilist;
  31460. this.animationDic=aniDic;
  31461. }
  31462. GraphicAnimation._temParam.length=0;
  31463. }
  31464. __proto.parseByData=function(aniData){
  31465. var rootNode,aniO;
  31466. rootNode=aniData.nodeRoot;
  31467. aniO=aniData.aniO;
  31468. delete aniData.nodeRoot;
  31469. delete aniData.aniO;
  31470. this._nodeDefaultProps={};
  31471. this._nodeGDic={};
  31472. if (this._nodeList)this._nodeList.length=0;
  31473. this._rootNode=rootNode;
  31474. this._parseNodeList(rootNode);
  31475. this._labels=null;
  31476. try {
  31477. this._calGraphicData(aniO);
  31478. }catch (e){
  31479. console.warn("parse animation fail:"+aniO.name+",empty animation created");
  31480. this._gList=[];
  31481. };
  31482. var frameO=aniData;
  31483. frameO.interval=1000 / aniO["frameRate"];
  31484. frameO.frames=this._gList;
  31485. frameO.labels=this._labels;
  31486. frameO.name=aniO.name;
  31487. return frameO;
  31488. }
  31489. /**@private */
  31490. __proto.setUpAniData=function(uiView){
  31491. if (uiView.animations){
  31492. var aniDic={};
  31493. var anilist=[];
  31494. var animations=uiView.animations;
  31495. var i=0,len=animations.length;
  31496. var tAniO;
  31497. for (i=0;i < len;i++){
  31498. tAniO=animations[i];
  31499. if (!tAniO)continue ;
  31500. var frameO={};
  31501. frameO.name=tAniO.name;
  31502. frameO.aniO=tAniO;
  31503. frameO.nodeRoot=uiView;
  31504. anilist.push(frameO);
  31505. aniDic[tAniO.name]=frameO;
  31506. }
  31507. this.animationList=anilist;
  31508. this.animationDic=aniDic;
  31509. }
  31510. }
  31511. /**@private */
  31512. __proto._clear=function(){
  31513. this.animationList=null;
  31514. this.animationDic=null;
  31515. this._gList=null;
  31516. this._nodeGDic=null;
  31517. }
  31518. GraphicAnimation.parseAnimationByData=function(animationObject){
  31519. if (!GraphicAnimation._I)GraphicAnimation._I=new GraphicAnimation();
  31520. var rst;
  31521. rst=GraphicAnimation._I.parseByData(animationObject);
  31522. GraphicAnimation._I._clear();
  31523. return rst;
  31524. }
  31525. GraphicAnimation.parseAnimationData=function(aniData){
  31526. if (!GraphicAnimation._I)GraphicAnimation._I=new GraphicAnimation();
  31527. GraphicAnimation._I.setUpAniData(aniData);
  31528. var rst;
  31529. rst={};
  31530. rst.animationList=GraphicAnimation._I.animationList;
  31531. rst.animationDic=GraphicAnimation._I.animationDic;
  31532. GraphicAnimation._I._clear();
  31533. return rst;
  31534. }
  31535. GraphicAnimation._temParam=[];
  31536. GraphicAnimation._I=null;
  31537. GraphicAnimation._rootMatrix=null;
  31538. __static(GraphicAnimation,
  31539. ['_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();}
  31540. ]);
  31541. GraphicAnimation.__init$=function(){
  31542. //class GraphicNode
  31543. GraphicNode=(function(){
  31544. function GraphicNode(){
  31545. this.skin=null;
  31546. this.transform=null;
  31547. this.resultTransform=null;
  31548. this.width=NaN;
  31549. this.height=NaN;
  31550. this.alpha=1;
  31551. }
  31552. __class(GraphicNode,'');
  31553. return GraphicNode;
  31554. })()
  31555. }
  31556. return GraphicAnimation;
  31557. })(FrameAnimation)
  31558. /**
  31559. *<p> 动效模板。用于为指定目标对象添加动画效果。每个动效有唯一的目标对象,而同一个对象可以添加多个动效。 当一个动效开始播放时,其他动效会自动停止播放。</p>
  31560. *<p> 可以通过LayaAir IDE创建。 </p>
  31561. */
  31562. //class laya.display.EffectAnimation extends laya.display.FrameAnimation
  31563. var EffectAnimation=(function(_super){
  31564. function EffectAnimation(){
  31565. /**@private */
  31566. this._target=null;
  31567. /**@private */
  31568. this._playEvent=null;
  31569. /**@private */
  31570. this._initData={};
  31571. /**@private */
  31572. this._aniKeys=null;
  31573. /**@private */
  31574. this._effectClass=null;
  31575. EffectAnimation.__super.call(this);
  31576. }
  31577. __class(EffectAnimation,'laya.display.EffectAnimation',_super);
  31578. var __proto=EffectAnimation.prototype;
  31579. /**@private */
  31580. __proto._onOtherBegin=function(effect){
  31581. if (effect===this)return;
  31582. this.stop();
  31583. }
  31584. /**@private */
  31585. __proto._addEvent=function(){
  31586. if (!this._target || !this._playEvent)return;
  31587. this._setControlNode(this._target);
  31588. this._target.on(this._playEvent,this,this._onPlayAction);
  31589. }
  31590. /**@private */
  31591. __proto._onPlayAction=function(){
  31592. this.play(0,false);
  31593. }
  31594. __proto.play=function(start,loop,name){
  31595. (start===void 0)&& (start=0);
  31596. (loop===void 0)&& (loop=true);
  31597. (name===void 0)&& (name="");
  31598. if (!this._target)
  31599. return;
  31600. this._target.event("effectbegin",[this]);
  31601. this._recordInitData();
  31602. laya.display.AnimationBase.prototype.play.call(this,start,loop,name);
  31603. }
  31604. /**@private */
  31605. __proto._recordInitData=function(){
  31606. if (!this._aniKeys)return;
  31607. var i=0,len=0;
  31608. len=this._aniKeys.length;
  31609. var key;
  31610. for (i=0;i < len;i++){
  31611. key=this._aniKeys[i];
  31612. this._initData[key]=this._target[key];
  31613. }
  31614. }
  31615. /**@private */
  31616. __proto._displayToIndex=function(value){
  31617. if (!this._animationData)return;
  31618. if (value < 0)value=0;
  31619. if (value > this._count)value=this._count;
  31620. var nodes=this._animationData.nodes,i=0,len=nodes.length;
  31621. len=len > 1 ? 1 :len;
  31622. for (i=0;i < len;i++){
  31623. this._displayNodeToFrame(nodes[i],value);
  31624. }
  31625. }
  31626. /**@private */
  31627. __proto._displayNodeToFrame=function(node,frame,targetDic){
  31628. if (!this._target)return;
  31629. var target=this._target;
  31630. var frames=node.frames,key,propFrames,value;
  31631. var keys=node.keys,i=0,len=keys.length;
  31632. var secondFrames=node.secondFrames;
  31633. var tSecondFrame=0;
  31634. var easeFun;
  31635. var tKeyFrames;
  31636. var startFrame;
  31637. var endFrame;
  31638. for (i=0;i < len;i++){
  31639. key=keys[i];
  31640. propFrames=frames[key];
  31641. tSecondFrame=secondFrames[key];
  31642. if (tSecondFrame==-1){
  31643. value=this._initData[key];
  31644. }else {
  31645. if (frame < tSecondFrame){
  31646. tKeyFrames=node.keyframes[key];
  31647. startFrame=tKeyFrames[0];
  31648. if (startFrame.tween){
  31649. easeFun=Ease[startFrame.tweenMethod];
  31650. if (easeFun==null)easeFun=Ease.linearNone;
  31651. endFrame=tKeyFrames[1];
  31652. value=easeFun(frame,this._initData[key],endFrame.value-this._initData[key],endFrame.index);
  31653. }else {
  31654. value=this._initData[key];
  31655. }
  31656. }else {
  31657. if (propFrames.length > frame)value=propFrames[frame];
  31658. else value=propFrames[propFrames.length-1];
  31659. }
  31660. }
  31661. target[key]=value;
  31662. }
  31663. }
  31664. /**@private */
  31665. __proto._calculateKeyFrames=function(node){
  31666. _super.prototype._calculateKeyFrames.call(this,node);
  31667. var keyFrames=node.keyframes,key,tKeyFrames,target=node.target;
  31668. var secondFrames={};
  31669. node.secondFrames=secondFrames;
  31670. for (key in keyFrames){
  31671. tKeyFrames=keyFrames[key];
  31672. if (tKeyFrames.length <=1)secondFrames[key]=-1;
  31673. else secondFrames[key]=tKeyFrames[1].index;
  31674. }
  31675. }
  31676. /**
  31677. *本实例的目标对象。通过本实例控制目标对象的属性变化。
  31678. *@param v 指定的目标对象。
  31679. */
  31680. __getset(0,__proto,'target',function(){
  31681. return this._target;
  31682. },function(v){
  31683. if (this._target)this._target.off("effectbegin",this,this._onOtherBegin);
  31684. this._target=v;
  31685. if (this._target)this._target.on("effectbegin",this,this._onOtherBegin);
  31686. this._addEvent();
  31687. });
  31688. /**
  31689. *设置开始播放的事件。本实例会侦听目标对象的指定事件,触发后播放相应动画效果。
  31690. *@param event
  31691. */
  31692. __getset(0,__proto,'playEvent',null,function(event){
  31693. this._playEvent=event;
  31694. if (!event)return;
  31695. this._addEvent();
  31696. });
  31697. /**
  31698. *设置动画数据。
  31699. *@param uiData
  31700. */
  31701. __getset(0,__proto,'effectData',null,function(uiData){
  31702. if (uiData){
  31703. var aniData=uiData["animations"];
  31704. if (aniData && aniData[0]){
  31705. var data=aniData[0];
  31706. this._setUp({},data);
  31707. if (data.nodes && data.nodes[0]){
  31708. this._aniKeys=data.nodes[0].keys;
  31709. }
  31710. }
  31711. }
  31712. });
  31713. /**
  31714. *设置提供数据的类。
  31715. *@param classStr 类路径
  31716. */
  31717. __getset(0,__proto,'effectClass',null,function(classStr){
  31718. this._effectClass=ClassUtils.getClass(classStr);
  31719. if (this._effectClass){
  31720. var uiData=this._effectClass["uiView"];
  31721. if (uiData){
  31722. var aniData=uiData["animations"];
  31723. if (aniData && aniData[0]){
  31724. var data=aniData[0];
  31725. this._setUp({},data);
  31726. if (data.nodes && data.nodes[0]){
  31727. this._aniKeys=data.nodes[0].keys;
  31728. }
  31729. }
  31730. }
  31731. }
  31732. });
  31733. EffectAnimation.EFFECT_BEGIN="effectbegin";
  31734. return EffectAnimation;
  31735. })(FrameAnimation)
  31736. Laya.__init([EventDispatcher,Context,LoaderManager,Path,GraphicAnimation,SceneUtils,Render,SubmitCMD,Timer,CallLater,LocalStorage,SubmitCanvas,SubmitTarget,TimeLine]);
  31737. })(window,document,Laya);
  31738. (function(window,document,Laya){
  31739. var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
  31740. //class LayaMain
  31741. var LayaMain=(function(){
  31742. /*[COMPILER OPTIONS:normal]*/
  31743. function LayaMain(){}
  31744. __class(LayaMain,'LayaMain');
  31745. return LayaMain;
  31746. })()
  31747. /**LayaGameStart**/
  31748. new LayaMain();
  31749. })(window,document,Laya);