changed drawing routines to use more SDL routines, ...
...and less direct manipulation of surfaces
This commit is contained in:
parent
85761bb72f
commit
e28a726d77
6 changed files with 38 additions and 60 deletions
Binary file not shown.
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 12 KiB |
Binary file not shown.
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 13 KiB |
|
@ -1287,8 +1287,6 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image_override,
|
|||
highlight_ratio = deadAmount_;
|
||||
}
|
||||
|
||||
const int xpad = is_odd(surface->w);
|
||||
|
||||
SDL_Surface* const dst = screen_.getSurface();
|
||||
|
||||
Pixel grid_colour = SDL_MapRGB(dst->format,0,0,0);
|
||||
|
@ -1342,70 +1340,52 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image_override,
|
|||
const int srcy = minimum<int>(yloc,surface->h-1);
|
||||
assert(srcy >= 0);
|
||||
|
||||
surface_lock srclock(surface);
|
||||
const int diff = maximum<int>(0,srcy*(surface->w+xpad) + maximum<int>(xoffset,xsrc));
|
||||
short* startsrc = srclock.pixels() + diff;
|
||||
len = minimum<int>(len,(surface->w+xpad)*surface->h - diff);
|
||||
const int diff = maximum<int>(0,srcy*surface->w + maximum<int>(xoffset,xsrc));
|
||||
len = minimum<int>(len,surface->w*surface->h - diff);
|
||||
if(len <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
short* endsrc = startsrc + len;
|
||||
SDL_Rect srcrect = { maximum<int>(xoffset,xsrc), srcy, len, 1 };
|
||||
SDL_Rect dstrect = { xdst, j, 0, 0 };
|
||||
|
||||
if(!(startsrc >= srclock.pixels() &&
|
||||
endsrc <= srclock.pixels() + (surface->w+xpad)*surface->h)) {
|
||||
std::cerr << "CRITICAL ERROR: overwrite at " << __FILE__ << ","
|
||||
<< __LINE__ << "\n"
|
||||
<< "len: " << len << "\n"
|
||||
<< "width: " << surface->w << "\n"
|
||||
<< "x: " << x << "\n"
|
||||
<< "y: " << y << "\n";
|
||||
}
|
||||
|
||||
surface_lock dstlock(dst);
|
||||
short* startdst = dstlock.pixels() + j*dst->w + xdst;
|
||||
std::copy(startsrc,endsrc,startdst);
|
||||
SDL_BlitSurface(surface,&srcrect,dst,&dstrect);
|
||||
|
||||
int extra = 0;
|
||||
|
||||
SDL_Rect end_srcrect = { srcrect.x + srcrect.w - 1, srcrect.y, 1, 1 };
|
||||
|
||||
//if the line didn't make it to the next hex, then fill in with the
|
||||
//last pixel up to the next hex
|
||||
if(ne_ypos > 0 && xdst + len < minoffset && len > 0) {
|
||||
extra = minimum(minoffset-(xdst + len),map_area().x+map_area().w-(xdst+len));
|
||||
std::fill(startdst+len,startdst+len+extra,startsrc[len-1]);
|
||||
SDL_Rect rect = { dstrect.x + len, dstrect.y, 1, 1 };
|
||||
for(int n = 0; n != extra; ++n, ++rect.x) {
|
||||
SDL_BlitSurface(surface,&end_srcrect,dst,&rect);
|
||||
}
|
||||
}
|
||||
|
||||
//copy any overlapping tiles on
|
||||
for(std::vector<SDL_Surface*>::const_iterator ov = overlaps.begin();
|
||||
ov != overlaps.end(); ++ov) {
|
||||
const int srcy = minimum<int>(yloc,(*ov)->h-1);
|
||||
const int w = (*ov)->w + is_odd((*ov)->w);
|
||||
SDL_BlitSurface(*ov,&srcrect,dst,&dstrect);
|
||||
|
||||
surface_lock overlap_lock(*ov);
|
||||
short* beg = overlap_lock.pixels() +
|
||||
srcy*w + (xoffset > xsrc ? xoffset:xsrc);
|
||||
short* end = beg + len;
|
||||
short* dst = startdst;
|
||||
|
||||
while(beg != end) {
|
||||
if(*beg != 0) {
|
||||
*dst = *beg;
|
||||
}
|
||||
|
||||
++dst;
|
||||
++beg;
|
||||
for(int i = 0; i != extra; ++i) {
|
||||
SDL_Rect rect = { dstrect.x + len + i, dstrect.y, 1, 1 };
|
||||
SDL_BlitSurface(*ov,&end_srcrect,dst,&rect);
|
||||
}
|
||||
|
||||
//fill in any extra pixels on the end
|
||||
if(extra > 0 && len > 0 && beg[-1] != 0)
|
||||
std::fill(dst,dst+extra,beg[-1]);
|
||||
}
|
||||
|
||||
if((grid_ || show_unit_colour) && startsrc < endsrc) {
|
||||
*startdst = grid_colour;
|
||||
*(startdst+len-1) = grid_colour;
|
||||
if(j == ypos || j == yend-1) {
|
||||
std::fill(startdst,startdst+len,grid_colour);
|
||||
if((grid_ || show_unit_colour) && dstrect.w >= 1) {
|
||||
SDL_Rect rect = dstrect;
|
||||
if(j == ypos || j == yend-1) {
|
||||
SDL_FillRect(dst,&rect,grid_colour);
|
||||
} else {
|
||||
rect.w = 1;
|
||||
rect.h = 1;
|
||||
SDL_FillRect(dst,&rect,grid_colour);
|
||||
rect.x += rect.w-1;
|
||||
SDL_FillRect(dst,&rect,grid_colour);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ SDL_Surface* get_tinted(const std::string& filename, TINT tint)
|
|||
base->format->Gmask,
|
||||
base->format->Bmask,
|
||||
base->format->Amask);
|
||||
SDL_SetColorKey(surface,SDL_SRCCOLORKEY,SDL_MapRGB(surface->format,0,0,0));
|
||||
|
||||
images.insert(std::pair<std::string,SDL_Surface*>(filename,surface));
|
||||
|
||||
|
@ -234,6 +235,8 @@ SDL_Surface* get_image(const std::string& filename,TYPE type)
|
|||
surf = conv;
|
||||
}
|
||||
|
||||
SDL_SetColorKey(surf,SDL_SRCCOLORKEY,SDL_MapRGB(surf->format,0,0,0));
|
||||
|
||||
i = images_.insert(std::pair<std::string,SDL_Surface*>(filename,surf)).first;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,41 +32,35 @@ SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h)
|
|||
if(surface == NULL)
|
||||
return NULL;
|
||||
|
||||
SDL_Surface* const dest = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,
|
||||
SDL_Surface* dest = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,
|
||||
surface->format->BitsPerPixel,
|
||||
surface->format->Rmask,
|
||||
surface->format->Gmask,
|
||||
surface->format->Bmask,
|
||||
surface->format->Amask);
|
||||
|
||||
if(dest == NULL) {
|
||||
std::cerr << "Could not create surface to scale onto\n";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_SetColorKey(dest,SDL_SRCCOLORKEY,SDL_MapRGB(dest->format,0,0,0));
|
||||
|
||||
const double xratio = static_cast<double>(surface->w)/
|
||||
static_cast<double>(w);
|
||||
const double yratio = static_cast<double>(surface->h)/
|
||||
static_cast<double>(h);
|
||||
|
||||
const int srcxpad = is_odd(surface->w) ? 1:0;
|
||||
const int dstxpad = is_odd(dest->w) ? 1:0;
|
||||
|
||||
surface_lock dstlock(dest);
|
||||
surface_lock srclock(surface);
|
||||
|
||||
double ysrc = 0.0;
|
||||
for(int ydst = 0; ydst != h; ++ydst, ysrc += yratio) {
|
||||
double xsrc = 0.0;
|
||||
for(int xdst = 0; xdst != w; ++xdst, xsrc += xratio) {
|
||||
int xsrcint = static_cast<int>(xsrc);
|
||||
const int xsrcint = static_cast<int>(xsrc);
|
||||
const int ysrcint = static_cast<int>(ysrc);
|
||||
|
||||
xsrcint += srcxpad*ysrcint;
|
||||
|
||||
const int dstpad = dstxpad*ydst;
|
||||
|
||||
dstlock.pixels()[ydst*w + xdst + dstpad] =
|
||||
srclock.pixels()[ysrcint*surface->w + xsrcint];
|
||||
SDL_Rect srcrect = { xsrcint, ysrcint, 1, 1 };
|
||||
SDL_Rect dstrect = { xdst, ydst, 1, 1 };
|
||||
SDL_BlitSurface(surface,&srcrect,dest,&dstrect);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ button::button(display& disp, const std::string& label, button::TYPE type,
|
|||
pressedImage_.assign(scale_surface(pressed_image,w_,h_));
|
||||
activeImage_.assign(scale_surface(active_image,w_,h_));
|
||||
pressedActiveImage_.assign(scale_surface(pressed_active_image,w_,h_));
|
||||
|
||||
} else {
|
||||
w_ = horizontal_padding + textRect_.w + button_image->w;
|
||||
image_.assign(scale_surface(button_image,button_image->w,button_image->h));
|
||||
|
|
Loading…
Add table
Reference in a new issue