Mercurial > otakunoraifu
diff window/picture.cc @ 60:e16e13d8cd68
Replaced SATURATE -> ADD, implemented objComposite, corrected minor things
author | Thibaut GIRKA <thib@sitedethib.com> |
---|---|
date | Fri, 18 Dec 2009 20:41:38 +0100 |
parents | ddbcbd000206 |
children | 4416cfac86ae |
line wrap: on
line diff
--- a/window/picture.cc +++ b/window/picture.cc @@ -41,10 +41,9 @@ using namespace std; -int print_blit = 0; /* render.cc */ void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect); -void DSurfaceBlitSaturate(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect, unsigned char alpha); +void DSurfaceBlitAdd(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect, unsigned char alpha); void DSurfaceBlitMultiply(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect); void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a=0xff); // クリア #if 0 /* DEBUG */ @@ -180,13 +179,9 @@ void PicBase::ExecReBlit(const Rect& rpo Rect rpos = rpos_c; Rect abs_r = QueryAbsPos(rpos); Rect ppos = parent_pos(rpos); -if(print_blit) fprintf(stderr,"back."); if (parent) parent->BlitBack(z_pos, ppos); -if(print_blit) fprintf(stderr,"self."); if (!is_hidden_now) Blit(rpos); -if(print_blit) fprintf(stderr,"front."); if (parent) parent->BlitFront(z_pos, ppos); -if(print_blit) fprintf(stderr,"end."); } void PicBase::ZMove(PicBase* move_to) { @@ -324,7 +319,7 @@ void PicBase::SetSurfaceAlpha(const unsi void PicBase::SetSurfaceColorKey(int r, int g, int b) { surface_alpha = 0; surface_alpha_rect = Rect(0,0); - attribute &= ~(BLIT_SATURATE | BLIT_MULTIPLY); + attribute &= ~(BLIT_ADD | BLIT_MULTIPLY); if (surface_own) { int key = SDL_MapRGB( ((SDL_Surface*)surface_own)->format, r, g, b); key |= 0xff000000; @@ -402,7 +397,7 @@ void PicBase::SetSurface(Surface* new_su if (surface_own != NULL && (attribute & SURFACE_FREE)) { root->DeleteSurface(surface_own); } - attribute &= ~(SURFACE_FREE | BLIT_SATURATE | BLIT_MULTIPLY | NO_PICTURE | SOLID); + attribute &= ~(SURFACE_FREE | BLIT_ADD | BLIT_MULTIPLY | NO_PICTURE | SOLID); attribute |= new_attr; surface_own = new_surface; surface_x = x; @@ -469,9 +464,9 @@ void PicBase::SetClipArea(const Rect& r) } void PicBase::SetSurfaceAttribute(int new_attribute) { - attribute &= ~(BLIT_SATURATE | BLIT_MULTIPLY); - attribute |= new_attribute & (BLIT_SATURATE | BLIT_MULTIPLY); - if (new_attribute & (BLIT_SATURATE | BLIT_MULTIPLY)) { + attribute &= ~(BLIT_ADD | BLIT_MULTIPLY); + attribute |= new_attribute & (BLIT_ADD | BLIT_MULTIPLY); + if (new_attribute & (BLIT_ADD | BLIT_MULTIPLY)) { rel_solid_area = Rect(0,0); } } @@ -539,19 +534,16 @@ void PicContainer::BlitBack(iterator z, Rect cpos = child_pos(rpos, *z); Rect apos = (*z)->QueryAbsPos(cpos); Rect draw_rpos = (*z)->parent_pos(cpos); -if(print_blit) fprintf(stderr,"cahce."); root->BlitSurface(surface_back, draw_rpos, root->surface, apos); goto self_redraw; } parent_redraw: if (parent) { Rect ppos = parent_pos(rpos); -if(print_blit) fprintf(stderr,"parent-back."); parent->BlitBack(z_pos, ppos); } if (is_hidden_now) return; self_redraw: -if(print_blit) fprintf(stderr,"back-self."); BlitSelf(rpos); // 子は描画せず、自分だけ描画 children_redraw: for (; it != z; it++) { @@ -564,10 +556,8 @@ children_redraw: } void PicContainer::BlitChildren(Rect rpos) { -if (print_blit) fprintf(stderr,"bc."); iterator end = children.end(); for (iterator it = children.begin(); it != end; it++) { -if ( (*it)->is_hidden_now) if(print_blit) fprintf(stderr,"bch %p;",*it); if ( (*it)->is_hidden_now) continue; if ( (*it)->rel_pos.is_crossed(rpos)) { Rect cpos = child_pos(rpos, *it); @@ -601,7 +591,6 @@ void PicContainer::BlitSelf(Rect rpos) { if (rpos.empty()) return; Rect apos = QueryAbsPos(rpos); // 必要に応じて保存、描画 -if(print_blit) fprintf(stderr,"self-back."); if (attribute & CACHE_BACK) root->BlitSurface(root->surface, apos, surface_back, rpos); if (! (attribute & NO_PICTURE)) { rpos.rmove(surface_x, surface_y); @@ -610,7 +599,6 @@ if(print_blit) fprintf(stderr,"self-back clip.rmove(rpos.lx, rpos.ty); rpos.intersect(clip); } -if(print_blit) fprintf(stderr,"self-blit."); root->BlitSurface(surface_own, rpos, surface_alpha, surface_alpha_rect, root->surface, apos, attribute); } else if (parent == NULL) { // 親がいないなら背景消去の責任をもつ DSurfaceFill(root->surface, apos, 0, 0, 0); @@ -894,14 +882,6 @@ void PicRoot::ExecUpdate(void) { vector<UpdateItem>::iterator it; vector<UpdateItem>::iterator end = update_rects.end(); -if(print_blit){ - fprintf(stderr,"ExecUpdate Start: \n\t"); - for (it=update_rects.begin(); it != end; it++) { - fprintf(stderr,"(%d,%d,%d,%d), ",it->apos.lx,it->apos.ty,it->apos.rx,it->apos.by); - } - fprintf(stderr,"\n"); -} - for (it=update_rects.begin(); it != end; it++) { if (it->rpos.width() == 0) continue; @@ -925,14 +905,6 @@ if(print_blit){ } } -if(print_blit){ - fprintf(stderr,"->\t"); - for (it=update_rects.begin(); it != end; it++) { - fprintf(stderr,"(%d,%d,%d,%d), ",it->apos.lx,it->apos.ty,it->apos.rx,it->apos.by); - } - fprintf(stderr,"\n"); -} - int num = update_rects.size(); SDL_Rect* r = new SDL_Rect[num]; Rect confine = Rect(0, 0, surface->w, surface->h); @@ -942,10 +914,9 @@ if(print_blit){ UpdateItem& item = update_rects[i]; Rect& ur = item.apos; if (ur.width() == 0) continue; -if(print_blit)fprintf(stderr,"%p: %d,%d,%d,%d",item.pic, item.apos.lx, item.apos.ty, item.apos.rx, item.apos.by); item.pic->ExecReBlit(item.rpos); -if(print_blit)fprintf(stderr,"\n"); + ur.intersect(confine); r[n].x = ur.lx; r[n].y = ur.ty; @@ -954,7 +925,7 @@ if(print_blit)fprintf(stderr,"\n"); if (surface != hw_surface) SDL_BlitSurface(surface, &r[n], hw_surface, &r[n]); n++; } -if(print_blit)fprintf(stderr,"\n"); + SDL_UpdateRects(hw_surface, n, r); delete[] r; update_rects.clear(); @@ -1016,36 +987,36 @@ inline SDL_Rect SDLed(const Rect& rect) #ifndef ALPHA_MAX #define ALPHA_MAX 255 #endif -void PicRoot::BlitSurface(Surface* src, const Rect& src_r, const unsigned char* alpha, const Rect& alpha_r, Surface* dest, const Rect& dest_r, int attribute) const { -if (print_blit) fprintf(stderr," s %p %d:%d:%d:%d;",src, dest_r.lx, dest_r.ty, dest_r.rx, dest_r.by); +void PicRoot::BlitSurface(Surface* src, const Rect& src_r, const unsigned char* alpha, const Rect& alpha_r, + Surface* dest, const Rect& dest_r, int attribute) const +{ SDL_Rect sr = SDLed(src_r); SDL_Rect dr = SDLed(dest_r); - if (attribute & PicBase::BLIT_MULTIPLY) { -if (print_blit) fprintf(stderr,"M"); + if (attribute & PicBase::BLIT_MULTIPLY) + { DSurfaceBlitMultiply(src, src_r, dest, dest_r); return; - } else if (attribute & PicBase::BLIT_SATURATE && src->format->Amask == 0) { -if (print_blit) fprintf(stderr,"S"); + } + else if (attribute & PicBase::BLIT_ADD) + { unsigned char a = 255; - if (alpha && alpha_r.width() >= 1 && alpha_r.height() >= 1) a = *alpha; - DSurfaceBlitSaturate(src, src_r, dest, dest_r, a); + if (alpha != NULL && alpha_r.width() >= 1 && alpha_r.height() >= 1) + a = *alpha; + DSurfaceBlitAdd(src, src_r, dest, dest_r, a); return; } -if (print_blit) fprintf(stderr,"N"); - if (alpha == NULL || alpha_r.width() == 0) { // simple blit -if (print_blit) fprintf(stderr,"X"); + if (alpha == NULL || alpha_r.width() == 0) // simple blit + { SDL_BlitSurface(src, &sr, dest, &dr); return; } if (alpha_r.width() == 1 && alpha_r.height() == 1) { if (*alpha == 255) { -if (print_blit) fprintf(stderr,"Y"); SDL_BlitSurface(src, &sr, dest, &dr); return; } if (src->format->Amask == 0) { // use per-surface alpha -if (print_blit) fprintf(stderr,"Z"); SDL_SetAlpha(src, SDL_SRCALPHA, *alpha); SDL_BlitSurface(src, &sr, dest, &dr); SDL_SetAlpha(src, 0, 0); @@ -1053,9 +1024,7 @@ if (print_blit) fprintf(stderr,"Z"); } } // generic alpha blit -if (print_blit) fprintf(stderr,"W"); DSurfaceBlitAlpha(src, src_r, dest, dest_r, alpha, alpha_r); - return; } bool PicRoot::with_mask(Surface* s) {