Improving constness of surface: forbid to blit on a const surface.

This commit is contained in:
Ali El Gariani 2010-10-01 01:43:16 +00:00
parent 33d1de9cf0
commit c63a7d97ae
15 changed files with 27 additions and 25 deletions

View file

@ -367,7 +367,7 @@ void save_preview_pane::draw_contents()
}
}
surface const screen = video().getSurface();
surface screen = video().getSurface();
SDL_Rect const &loc = location();
const SDL_Rect area = create_rect(loc.x + save_preview_border
@ -746,7 +746,7 @@ void unit_preview_pane::draw_contents()
const bool right_align = left_side();
surface const screen = video().getSurface();
surface screen = video().getSurface();
SDL_Rect const &loc = location();
const SDL_Rect area = create_rect(loc.x + unit_preview_border

View file

@ -889,7 +889,7 @@ void display::drawing_buffer_commit()
drawing_buffer_.sort();
SDL_Rect clip_rect = map_area();
const surface screen = get_screen_surface();
surface screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, &clip_rect);
/*
@ -948,7 +948,7 @@ void display::flip()
return;
}
const surface frameBuffer = get_video_surface();
surface frameBuffer = get_video_surface();
// This is just the debug function "sunset" to progressively darken the map area
static size_t sunset_timer = 0;
@ -2039,7 +2039,7 @@ const map_labels& display::labels() const
void display::clear_screen()
{
surface const disp(screen_.getSurface());
surface disp(screen_.getSurface());
SDL_Rect area = screen_area();
sdl_fill_rect(disp, &area, SDL_MapRGB(disp->format, 0, 0, 0));
}

View file

@ -192,7 +192,7 @@ bool effect::render()
return false;
}
surface const screen = disp->get_screen_surface();
surface screen = disp->get_screen_surface();
const clip_rect_setter clip_setter(screen, &clip_rect);
if(buffer_ == NULL || buffer_->w != rect.w || buffer_->h != rect.h) {
@ -216,7 +216,7 @@ void effect::unrender()
return;
}
surface const screen = disp->get_screen_surface();
surface screen = disp->get_screen_surface();
SDL_Rect clip_rect = disp->map_outside_area();
const clip_rect_setter clip_setter(screen, &clip_rect);

View file

@ -2616,7 +2616,7 @@ void help_text_area::draw_contents()
{
SDL_Rect const &loc = inner_location();
bg_restore();
surface const screen = video().getSurface();
surface screen = video().getSurface();
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;

View file

@ -413,7 +413,7 @@ static std::string get_localized_path (const std::string& file, const std::strin
}
// Load overlay image and compose it with the original surface.
static void add_localized_overlay (const std::string& ovr_file, const surface &orig_surf)
static void add_localized_overlay (const std::string& ovr_file, surface &orig_surf)
{
surface ovr_surf = IMG_Load(ovr_file.c_str());
if (ovr_surf.null()) {

View file

@ -106,7 +106,7 @@ void loadscreen::draw_screen(const std::string &text)
// Height of the lighting line.
int lightning_thickness = 2;
surface const gdis = screen_.getSurface();
surface gdis = screen_.getSurface();
SDL_Rect area;
// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
@ -192,7 +192,7 @@ void loadscreen::clear_screen()
int scrx = screen_.getx(); //< Screen width.
int scry = screen_.gety(); //< Screen height.
SDL_Rect area = create_rect(0, 0, scrx, scry); // Screen area.
surface const disp(screen_.getSurface()); // Screen surface.
surface disp(screen_.getSurface()); // Screen surface.
// Make everything black.
sdl_fill_rect(disp,&area,SDL_MapRGB(disp->format,0,0,0));
update_whole_screen();

View file

@ -68,7 +68,7 @@ void wait::leader_preview_pane::draw_contents()
{
bg_restore();
surface const screen = video().getSurface();
surface screen = video().getSurface();
SDL_Rect const &loc = location();
const SDL_Rect area = create_rect(loc.x + leader_pane_border

View file

@ -1752,7 +1752,7 @@ void blit_surface(const surface& src,
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, const surface &target)
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, surface &target)
{
if(alpha == SDL_ALPHA_OPAQUE) {
sdl_fill_rect(target,&rect,color);

View file

@ -126,11 +126,11 @@ private:
bool operator<(const surface& a, const surface& b);
inline void sdl_blit(const surface& src, SDL_Rect* src_rect, const surface& dst, SDL_Rect* dst_rect){
inline void sdl_blit(const surface& src, SDL_Rect* src_rect, surface& dst, SDL_Rect* dst_rect){
SDL_BlitSurface(src, src_rect, dst, dst_rect);
}
inline void sdl_fill_rect(const surface& dst, SDL_Rect* dst_rect, const Uint32 color){
inline void sdl_fill_rect(surface& dst, SDL_Rect* dst_rect, const Uint32 color){
SDL_FillRect(dst, dst_rect, color);
}
@ -305,7 +305,7 @@ surface create_compatible_surface(const surface &surf, int width = -1, int heigh
void blit_surface(const surface& src,
const SDL_Rect* srcrect, surface& dst, const SDL_Rect* dstrect);
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, const surface &target);
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, surface &target);
SDL_Rect get_non_transparent_portion(const surface &surf);

View file

@ -18,9 +18,11 @@
#include "../video.hpp"
#include "../sdl_utils.hpp"
surface CVideo::getSurface()
static surface dummy_screen_surface(NULL);
surface& CVideo::getSurface()
{
return NULL;
return dummy_screen_surface;
}
void update_rect(const SDL_Rect&)

View file

@ -326,7 +326,7 @@ CVideo::~CVideo()
void CVideo::blit_surface(int x, int y, surface surf, SDL_Rect* srcrect, SDL_Rect* clip_rect)
{
const surface target(getSurface());
surface target(getSurface());
SDL_Rect dst = create_rect(x, y, 0, 0);
const clip_rect_setter clip_setter(target, clip_rect, clip_rect != NULL);
@ -437,7 +437,7 @@ bool CVideo::update_locked() const
return updatesLocked_ > 0;
}
surface CVideo::getSurface()
surface& CVideo::getSurface()
{
return frameBuffer;
}

View file

@ -64,7 +64,7 @@ class CVideo : private boost::noncopyable {
void blit_surface(int x, int y, surface surf, SDL_Rect* srcrect=NULL, SDL_Rect* clip_rect=NULL);
void flip();
surface getSurface();
surface& getSurface();
bool isFullScreen() const;

View file

@ -42,7 +42,7 @@ void progress_bar::set_text(const std::string& text)
void progress_bar::draw_contents()
{
surface const surf = video().getSurface();
surface surf = video().getSurface();
SDL_Rect area = location();
if(area.w >= 2 && area.h >= 2) {

View file

@ -147,7 +147,7 @@ void slider::draw_contents()
if (image->w >= loc.w)
return;
surface const screen = video().getSurface();
surface screen = video().getSurface();
SDL_Rect line_rect = create_rect(loc.x + image->w / 2
, loc.y + loc.h / 2

View file

@ -95,7 +95,7 @@ void textbox::append_text(const std::string& text, bool auto_scroll, const SDL_C
const wide_string& wtext = utils::string_to_wstring(text);
const surface new_text = add_text_line(wtext, color);
const surface new_surface = create_compatible_surface(text_image_,std::max<size_t>(text_image_->w,new_text->w),text_image_->h+new_text->h);
surface new_surface = create_compatible_surface(text_image_,std::max<size_t>(text_image_->w,new_text->w),text_image_->h+new_text->h);
SDL_SetAlpha(new_text.get(),0,0);
SDL_SetAlpha(text_image_.get(),0,0);
@ -140,7 +140,7 @@ void textbox::draw_cursor(int pos, CVideo &video) const
, 1
, location().h);
surface const frame_buffer = video.getSurface();
surface frame_buffer = video.getSurface();
sdl_fill_rect(frame_buffer,&rect,SDL_MapRGB(frame_buffer->format,255,255,255));
}
}