moved blit_surface() from display to video, more cleanup of deps against display

This commit is contained in:
Yann Dirson 2005-03-15 22:14:04 +00:00
parent ad0e5691b1
commit b456d80a34
10 changed files with 44 additions and 45 deletions

View file

@ -546,18 +546,18 @@ void display::redraw_everything()
namespace {
void draw_panel(display& disp, const theme::panel& panel, std::vector<gui::button>& buttons)
void draw_panel(CVideo& video, const theme::panel& panel, std::vector<gui::button>& 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<gui::button>::iterator b = buttons.begin(); b != buttons.end(); ++b) {
@ -608,7 +608,7 @@ void display::draw(bool update,bool force)
const std::vector<theme::panel>& panels = theme_.panels();
for(std::vector<theme::panel>::const_iterator p = panels.begin(); p != panels.end(); ++p) {
draw_panel(*this,*p,buttons_);
draw_panel(video(),*p,buttons_);
}
const std::vector<theme::label>& 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) {

View file

@ -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();

View file

@ -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,

View file

@ -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";

View file

@ -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;

View file

@ -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 );

View file

@ -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);

View file

@ -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 {

View file

@ -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);
}

View file

@ -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)