diff --git a/src/display.cpp b/src/display.cpp index cbd86d868a7..2db0a8419a0 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -546,18 +546,18 @@ void display::redraw_everything() namespace { -void draw_panel(display& disp, const theme::panel& panel, std::vector& buttons) +void draw_panel(CVideo& video, const theme::panel& panel, std::vector& buttons) { //log_scope("draw panel"); surface surf(image::get_image(panel.image(),image::UNSCALED)); - const SDL_Rect screen = disp.screen_area(); + const SDL_Rect screen = screen_area(); SDL_Rect& loc = panel.location(screen); if(surf->w != loc.w || surf->h != loc.h) { surf.assign(scale_surface(surf,loc.w,loc.h)); } - disp.blit_surface(loc.x,loc.y,surf); + video.blit_surface(loc.x,loc.y,surf); update_rect(loc); for(std::vector::iterator b = buttons.begin(); b != buttons.end(); ++b) { @@ -608,7 +608,7 @@ void display::draw(bool update,bool force) const std::vector& panels = theme_.panels(); for(std::vector::const_iterator p = panels.begin(); p != panels.end(); ++p) { - draw_panel(*this,*p,buttons_); + draw_panel(video(),*p,buttons_); } const std::vector& labels = theme_.labels(); @@ -1301,7 +1301,7 @@ void display::draw_unit_on_tile(int x, int y, surface unit_image_override, surface crown(image::get_image("misc/leader-crown.png",image::SCALED,image::NO_ADJUST_COLOUR)); if(!crown.null()) { SDL_Rect r = {0, 0, crown->w, crown->h}; - blit_surface(xpos,ypos,crown,&r); + video().blit_surface(xpos,ypos,crown,&r); } } @@ -1342,8 +1342,8 @@ void display::draw_bar(const std::string& image, int xpos, int ypos, size_t heig SDL_Rect bot = {0,bar_loc.y+skip_rows,surf->w,0}; bot.h = surf->w - bot.y; - blit_surface(xpos,ypos,surf,&top); - blit_surface(xpos,ypos+top.h,surf,&bot); + video().blit_surface(xpos,ypos,surf,&top); + video().blit_surface(xpos,ypos+top.h,surf,&bot); const size_t unfilled = (const size_t)(height*(1.0 - filled)); @@ -1775,19 +1775,6 @@ surface display::get_flag(gamemap::TERRAIN terrain, int x, int y) return surface(NULL); } -void display::blit_surface(int x, int y, surface surf, SDL_Rect* srcrect, SDL_Rect* clip_rect) -{ - const surface target(video().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); - } -} - surface display::get_minimap(int w, int h) { if(minimap_ != NULL && (minimap_->w != w || minimap_->h != h)) { @@ -1884,7 +1871,7 @@ void display::draw_unit(int x, int y, surface image, SDL_Rect clip_rect = map_area(); SDL_Rect srcrect = {0,0,surf->w,submerge_height}; - blit_surface(x,y,surf,&srcrect,&clip_rect); + video().blit_surface(x,y,surf,&srcrect,&clip_rect); if(submerge_height != surf->h) { surf.assign(adjust_surface_alpha(surf,ftofxp(0.2))); @@ -1893,7 +1880,7 @@ void display::draw_unit(int x, int y, surface image, srcrect.h = surf->h-submerge_height; y += submerge_height; - blit_surface(x,y,surf,&srcrect,&clip_rect); + video().blit_surface(x,y,surf,&srcrect,&clip_rect); } if(ellipse_front != NULL) { diff --git a/src/display.hpp b/src/display.hpp index f3f7b998cbb..cad79f7d9a2 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -14,7 +14,6 @@ #define DISPLAY_H_INCLUDED class config; -class CVideo; #include "gamestatus.hpp" #include "image.hpp" #include "key.hpp" @@ -26,6 +25,7 @@ class CVideo; #include "team.hpp" #include "theme.hpp" #include "unit.hpp" +#include "video.hpp" #include "widgets/button.hpp" #include "SDL.h" @@ -206,9 +206,6 @@ public: //gets the underlying screen object. CVideo& video() { return screen_; } - //blits a surface with black as alpha - void blit_surface(int x, int y, surface surface, SDL_Rect* srcrect=NULL, SDL_Rect* clip_rect=NULL); - //function to invalidate all tiles. void invalidate_all(); diff --git a/src/show_dialog.cpp b/src/show_dialog.cpp index 455045a5f15..1970715fed0 100644 --- a/src/show_dialog.cpp +++ b/src/show_dialog.cpp @@ -117,25 +117,25 @@ void draw_dialog_frame(int x, int y, int w, int h, display& disp, const std::str surface top_image(scale_surface(top,w,top->h)); if(top_image != NULL) { - disp.blit_surface(x,y-top->h,top_image); + disp.video().blit_surface(x,y-top->h,top_image); } surface bot_image(scale_surface(bot,w,bot->h)); if(bot_image != NULL) { - disp.blit_surface(x,y+h,bot_image); + disp.video().blit_surface(x,y+h,bot_image); } surface left_image(scale_surface(left,left->w,h)); if(left_image != NULL) { - disp.blit_surface(x-left->w,y,left_image); + disp.video().blit_surface(x-left->w,y,left_image); } surface right_image(scale_surface(right,right->w,h)); if(right_image != NULL) { - disp.blit_surface(x+w,y,right_image); + disp.video().blit_surface(x+w,y,right_image); } update_rect(x-left->w,y-top->h,w+left->w+right->w,h+top->h+bot->h); @@ -148,10 +148,10 @@ void draw_dialog_frame(int x, int y, int w, int h, display& disp, const std::str return; } - disp.blit_surface(x-top_left->w,y-top_left->h,top_left); - disp.blit_surface(x-bot_left->w,y+h,bot_left); - disp.blit_surface(x+w,y-top_right->h,top_right); - disp.blit_surface(x+w,y+h,bot_right); + disp.video().blit_surface(x-top_left->w,y-top_left->h,top_left); + disp.video().blit_surface(x-bot_left->w,y+h,bot_left); + disp.video().blit_surface(x+w,y-top_right->h,top_right); + disp.video().blit_surface(x+w,y+h,bot_right); } void draw_dialog_background(int x, int y, int w, int h, display& disp, const std::string& style) @@ -711,7 +711,7 @@ int show_dialog(display& disp, surface image, const int x = xloc + left_padding; const int y = yloc + top_padding; - disp.blit_surface(x,y,image); + disp.video().blit_surface(x,y,image); font::draw_text(&disp.video(), clipRect, caption_font_size, font::NORMAL_COLOUR, caption, diff --git a/src/titlescreen.cpp b/src/titlescreen.cpp index c625eabd392..ad75a9f978a 100644 --- a/src/titlescreen.cpp +++ b/src/titlescreen.cpp @@ -154,7 +154,7 @@ TITLE_RESULT show_title(display& screen, config& tips_of_day, int* ntip) if(title_surface == NULL) { ERR_DP << "Could not find title image\n"; } else { - screen.blit_surface(0,0,title_surface); + screen.video().blit_surface(0,0,title_surface); update_rect(screen_area()); LOG_DP << "displayed title image\n"; diff --git a/src/video.cpp b/src/video.cpp index a75b41652c5..525d2788311 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -235,6 +235,19 @@ CVideo::~CVideo() LOG_DP << "called SDL_Quit()\n"; } +void CVideo::blit_surface(int x, int y, surface surf, SDL_Rect* srcrect, SDL_Rect* clip_rect) +{ + 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); + } +} + void CVideo::make_fake() { fake_screen = true; diff --git a/src/video.hpp b/src/video.hpp index 431d6e019e8..93772ce0651 100644 --- a/src/video.hpp +++ b/src/video.hpp @@ -60,6 +60,8 @@ class CVideo { void unlock(); int mustLock(); + //blits a surface with black as alpha + void blit_surface(int x, int y, surface surf, SDL_Rect* srcrect=NULL, SDL_Rect* clip_rect=NULL); void flip(); surface getSurface( void ); diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index cf11f117fea..df4ed872228 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -170,7 +170,7 @@ void button::draw_contents() if (!enabled_) image = greyscale_image(image); - disp().blit_surface(loc.x, loc.y, image); + video().blit_surface(loc.x, loc.y, image); const std::string etext = font::make_text_ellipsis(label_, font_size, loc.w); font::draw_text(&video(), clipArea, font_size, font::BUTTON_COLOUR, etext, textx, texty); diff --git a/src/widgets/menu.cpp b/src/widgets/menu.cpp index a74817c2124..688ce50921f 100644 --- a/src/widgets/menu.cpp +++ b/src/widgets/menu.cpp @@ -421,7 +421,7 @@ void menu::draw_item(int item) if(img != NULL && (xpos - rect.x) + img->w < max_width && rect.y + img->h < area.h) { const size_t y = rect.y + (rect.h - img->h)/2; - disp().blit_surface(xpos,y,img); + video().blit_surface(xpos,y,img); xpos += img->w + 5; } } else { diff --git a/src/widgets/scrollbar.cpp b/src/widgets/scrollbar.cpp index 2e610401833..40653557658 100644 --- a/src/widgets/scrollbar.cpp +++ b/src/widgets/scrollbar.cpp @@ -239,14 +239,14 @@ void scrollbar::draw_contents() surface const screen = video().getSurface(); // draw scrollbar "groove" - disp().blit_surface(groove.x, groove.y, top_grv); - disp().blit_surface(groove.x, groove.y + top_grv->h, groove_scaled_); - disp().blit_surface(groove.x, groove.y + top_grv->h + groove_height, bottom_grv); + video().blit_surface(groove.x, groove.y, top_grv); + video().blit_surface(groove.x, groove.y + top_grv->h, groove_scaled_); + video().blit_surface(groove.x, groove.y + top_grv->h + groove_height, bottom_grv); // draw scrollbar "grip" - disp().blit_surface(grip.x, grip.y, top_img); - disp().blit_surface(grip.x, grip.y + top_img->h, mid_scaled_); - disp().blit_surface(grip.x, grip.y + top_img->h + mid_height, bottom_img); + video().blit_surface(grip.x, grip.y, top_img); + video().blit_surface(grip.x, grip.y + top_img->h, mid_scaled_); + video().blit_surface(grip.x, grip.y + top_img->h + mid_height, bottom_img); update_rect(groove); } diff --git a/src/widgets/slider.cpp b/src/widgets/slider.cpp index 1c723f63825..7e841decc93 100644 --- a/src/widgets/slider.cpp +++ b/src/widgets/slider.cpp @@ -126,7 +126,7 @@ void slider::draw_contents() SDL_FillRect(screen, &line_rect, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_Rect const &slider = slider_area(); - disp().blit_surface(slider.x, slider.y, image); + video().blit_surface(slider.x, slider.y, image); } void slider::set_slider_position(int x)