Add more flexibility to clip_rect_setter:

- Allow to disable previous clipping

- Add a flag for easier toggling
This commit is contained in:
Ali El Gariani 2010-05-18 17:42:43 +00:00
parent 8eb001c684
commit c7f242a04d
16 changed files with 41 additions and 49 deletions

View file

@ -306,7 +306,7 @@ void show_about(display &disp, const std::string &campaign)
{
// clip to keep text into the frame (thus the new code block)
clip_rect_setter set_clip_rect(screen, text_rect);
clip_rect_setter set_clip_rect(screen, &text_rect);
do {
// draw the text (with ellipsis if needed)
// update the max_text_width for future cleaning

View file

@ -352,8 +352,7 @@ void save_preview_pane::draw_contents()
SDL_Rect const &loc = location();
const SDL_Rect area = { loc.x + save_preview_border, loc.y + save_preview_border,
loc.w - save_preview_border * 2, loc.h - save_preview_border * 2 };
SDL_Rect clip_area = area;
const clip_rect_setter clipper(screen,clip_area);
const clip_rect_setter clipper(screen, &area);
int ypos = area.y;
@ -725,8 +724,7 @@ void unit_preview_pane::draw_contents()
SDL_Rect const &loc = location();
const SDL_Rect area = { loc.x + unit_preview_border, loc.y + unit_preview_border,
loc.w - unit_preview_border * 2, loc.h - unit_preview_border * 2 };
SDL_Rect clip_area = area;
const clip_rect_setter clipper(screen,clip_area);
const clip_rect_setter clipper(screen, &area);
surface unit_image = det.image;
if (!left_)

View file

@ -707,8 +707,8 @@ std::vector<surface> display::get_terrain_images(const map_location &loc,
void display::drawing_buffer_commit()
{
SDL_Rect clip_rect = map_area();
surface const dst(get_screen_surface());
clip_rect_setter set_clip_rect(dst, clip_rect);
const surface screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, &clip_rect);
/*
* Info regarding the rendering algorithm.
@ -800,10 +800,10 @@ void display::drawing_buffer_commit()
SDL_Rect srcrect = blit_itor->clip;
SDL_BlitSurface(*surface_itor,
&srcrect, dst, &dstrect);
&srcrect, screen, &dstrect);
} else {
SDL_BlitSurface(*surface_itor,
NULL, dst, &dstrect);
NULL, screen, &dstrect);
}
}
update_rect(blit_itor->x, blit_itor->y, zoom_, zoom_);
@ -1181,7 +1181,7 @@ bool display::draw_init()
// Full redraw of the background
const SDL_Rect clip_rect = map_outside_area();
const surface screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, clip_rect);
clip_rect_setter set_clip_rect(screen, &clip_rect);
draw_background(screen, clip_rect, theme_.border().background_image);
update_rect(clip_rect);
@ -1366,7 +1366,7 @@ void display::draw_minimap()
}
const surface screen(screen_.getSurface());
clip_rect_setter clip_setter(screen, area);
clip_rect_setter clip_setter(screen, &area);
SDL_Color back_color = {31,31,23,255};
draw_centered_on_background(minimap_, area, back_color, screen);
@ -1945,7 +1945,7 @@ void display::draw_invalidated() {
// log_scope("display::draw_invalidated");
SDL_Rect clip_rect = get_clip_rect();
surface screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, clip_rect);
clip_rect_setter set_clip_rect(screen, &clip_rect);
foreach (map_location loc, invalidated_) {
int xpos = get_location_x(loc);
int ypos = get_location_y(loc);

View file

@ -1078,7 +1078,7 @@ void floating_label::draw(surface screen)
}
SDL_Rect rect = {xpos(surf_->w),int(ypos_),surf_->w,surf_->h};
const clip_rect_setter clip_setter(screen,clip_rect_);
const clip_rect_setter clip_setter(screen, &clip_rect_);
SDL_BlitSurface(screen,&rect,buf_,NULL);
SDL_BlitSurface(surf_,NULL,screen,&rect);
@ -1092,7 +1092,7 @@ void floating_label::undraw(surface screen)
}
SDL_Rect rect = {xpos(surf_->w),int(ypos_),surf_->w,surf_->h};
const clip_rect_setter clip_setter(screen,clip_rect_);
const clip_rect_setter clip_setter(screen, &clip_rect_);
SDL_BlitSurface(buf_,NULL,screen,&rect);
update_rect(rect);

View file

@ -254,7 +254,7 @@ void twidget::draw_background(surface& frame_buffer)
assert(visible_ == VISIBLE);
if(drawing_action_ == PARTLY_DRAWN) {
clip_rect_setter clip(frame_buffer, clip_rect_);
clip_rect_setter clip(frame_buffer, &clip_rect_);
draw_debug_border(frame_buffer);
impl_draw_background(frame_buffer);
} else {
@ -268,7 +268,7 @@ void twidget::draw_children(surface& frame_buffer)
assert(visible_ == VISIBLE);
if(drawing_action_ == PARTLY_DRAWN) {
clip_rect_setter clip(frame_buffer, clip_rect_);
clip_rect_setter clip(frame_buffer, &clip_rect_);
impl_draw_children(frame_buffer);
} else {
impl_draw_children(frame_buffer);
@ -280,7 +280,7 @@ void twidget::draw_foreground(surface& frame_buffer)
assert(visible_ == VISIBLE);
if(drawing_action_ == PARTLY_DRAWN) {
clip_rect_setter clip(frame_buffer, clip_rect_);
clip_rect_setter clip(frame_buffer, &clip_rect_);
impl_draw_foreground(frame_buffer);
} else {
impl_draw_foreground(frame_buffer);

View file

@ -624,7 +624,7 @@ void twindow::draw()
dirty_list_.push_back(std::vector<twidget*>(1, this));
update_rect(screen_area());
#else
clip_rect_setter clip(frame_buffer, dirty_rect);
clip_rect_setter clip(frame_buffer, &dirty_rect);
#endif
/*

View file

@ -193,7 +193,7 @@ bool effect::render()
surface const screen = disp->get_screen_surface();
const clip_rect_setter clip_setter(screen,clip_rect);
const clip_rect_setter clip_setter(screen, &clip_rect);
if(buffer_ == NULL || buffer_->w != rect.w || buffer_->h != rect.h) {
SDL_Rect rect = rect_;
buffer_.assign(get_surface_portion(screen,rect));
@ -218,7 +218,7 @@ void effect::unrender()
surface const screen = disp->get_screen_surface();
SDL_Rect clip_rect = disp->map_outside_area();
const clip_rect_setter clip_setter(screen,clip_rect);
const clip_rect_setter clip_setter(screen, &clip_rect);
// Due to scrolling, the location of the rendered halo
// might have changed; recalculate

View file

@ -2626,7 +2626,7 @@ void help_text_area::draw_contents()
SDL_Rect const &loc = inner_location();
bg_restore();
surface const screen = video().getSurface();
clip_rect_setter clip_rect_set(screen, loc);
clip_rect_setter clip_rect_set(screen, &loc);
for(std::list<item>::const_iterator it = items_.begin(), end = items_.end(); it != end; ++it) {
SDL_Rect dst = it->rect;
dst.y -= get_position();

View file

@ -71,8 +71,7 @@ void wait::leader_preview_pane::draw_contents()
SDL_Rect const &loc = location();
const SDL_Rect area = { loc.x + leader_pane_border, loc.y + leader_pane_border,
loc.w - leader_pane_border * 2, loc.h - leader_pane_border * 2 };
SDL_Rect clip_area = area;
const clip_rect_setter clipper(screen,clip_area);
const clip_rect_setter clipper(screen, &area);
if(selection_ < side_list_.size()) {
const config& side = *side_list_[selection_];

View file

@ -1819,7 +1819,7 @@ void draw_solid_tinted_rectangle(int x, int y, int w, int h,
void draw_centered_on_background(surface surf, const SDL_Rect& rect, const SDL_Color& color, surface target)
{
clip_rect_setter clip_setter(target, rect);
clip_rect_setter clip_setter(target, &rect);
Uint32 col = SDL_MapRGBA(target->format, color.r, color.g, color.b, color.unused);
//TODO: only draw background outside the image

View file

@ -342,17 +342,24 @@ private:
struct clip_rect_setter
{
clip_rect_setter(const surface &surf, const SDL_Rect& r) : surface_(surf), rect()
// if r is NULL, clip to the full size of the surface.
clip_rect_setter(const surface &surf, const SDL_Rect* r, bool operate = true) : surface_(surf), rect_(), operate_(operate)
{
SDL_GetClipRect(surface_,&rect);
SDL_SetClipRect(surface_,&r);
if(operate_){
SDL_GetClipRect(surface_, &rect_);
SDL_SetClipRect(surface_, r);
}
}
~clip_rect_setter() { SDL_SetClipRect(surface_,&rect); }
~clip_rect_setter() {
if (operate_)
SDL_SetClipRect(surface_, &rect_);
}
private:
surface surface_;
SDL_Rect rect;
SDL_Rect rect_;
const bool operate_;
};

View file

@ -328,12 +328,8 @@ void CVideo::blit_surface(int x, int y, surface surf, SDL_Rect* srcrect, SDL_Rec
const surface target(getSurface());
SDL_Rect dst = {x,y,0,0};
if(clip_rect != NULL) {
const clip_rect_setter clip_setter(target,*clip_rect);
SDL_BlitSurface(surf,srcrect,target,&dst);
} else {
SDL_BlitSurface(surf,srcrect,target,&dst);
}
const clip_rect_setter clip_setter(target, clip_rect, clip_rect != NULL);
SDL_BlitSurface(surf,srcrect,target,&dst);
}
void CVideo::make_fake()

View file

@ -1018,9 +1018,7 @@ void menu::draw()
bg_restore();
util::scoped_ptr<clip_rect_setter> clipper(NULL);
if(clip_rect())
clipper.assign(new clip_rect_setter(video().getSurface(), *clip_rect()));
clip_rect_setter(video().getSurface(), clip_rect(), clip_rect() != NULL);
draw_contents();

View file

@ -89,7 +89,7 @@ void progress_bar::draw_contents()
selected_text_location.w = inner_area.w;
selected_text_location.h = inner_area.h;
{
clip_rect_setter clippy(surf, selected_text_location);
clip_rect_setter clippy(surf, &selected_text_location);
font::draw_text(
&video(),
selected_text_location,

View file

@ -176,7 +176,7 @@ void textbox::draw_contents()
SDL_Rect rect = { loc.x + startx, loc.y + starty - src.y, right - startx, line_height_ };
const clip_rect_setter clipper(surf, loc);
const clip_rect_setter clipper(surf, &loc);
Uint32 colour = SDL_MapRGB(surf->format, 0, 0, 160);
fill_rect_alpha(rect, colour, 140, surf);

View file

@ -251,9 +251,7 @@ void widget::bg_update()
void widget::bg_restore() const
{
util::scoped_ptr<clip_rect_setter> clipper(NULL);
if (clip_)
clipper.assign(new clip_rect_setter(video().getSurface(), clip_rect_));
clip_rect_setter clipper(video().getSurface(), &clip_rect_, clip_);
if (needs_restore_) {
for(std::vector< surface_restorer >::const_iterator i = restorer_.begin(),
@ -269,9 +267,7 @@ void widget::bg_restore() const
void widget::bg_restore(SDL_Rect const &rect) const
{
util::scoped_ptr<clip_rect_setter> clipper(NULL);
if (clip_)
clipper.assign(new clip_rect_setter(video().getSurface(), clip_rect_));
clip_rect_setter clipper(video().getSurface(), &clip_rect_, clip_);
for(std::vector< surface_restorer >::const_iterator i = restorer_.begin(),
i_end = restorer_.end(); i != i_end; ++i)
@ -292,9 +288,7 @@ void widget::draw()
bg_restore();
util::scoped_ptr<clip_rect_setter> clipper(NULL);
if (clip_)
clipper.assign(new clip_rect_setter(video().getSurface(), clip_rect_));
clip_rect_setter clipper(video().getSurface(), &clip_rect_, clip_);
draw_contents();