initial implementation of unit ellipses

This commit is contained in:
uid68803 2004-01-09 05:01:56 +00:00
parent d7bb834d60
commit f25376565a
3 changed files with 33 additions and 27 deletions

View file

@ -1190,8 +1190,6 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image_override,
const Pixel grid_colour = SDL_MapRGB(dst->format,0,0,0);
const bool show_unit_colour = preferences::show_side_colours() && !fogged(x,y) && it != units_.end();
int j;
for(j = ypos; j != yend; ++j) {
@ -1316,6 +1314,15 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image_override,
draw_unit(xpos-xsrc,ypos-ysrc - height_adjust,unit_image,face_left,false,
highlight_ratio,blend_with,submerge);
//the circle around the base of the unit
if(preferences::show_side_colours() && !fogged(x,y) && it != units_.end()) {
const SDL_Color& col = font::get_side_colour(it->second.side());
const short colour = SDL_MapRGB(dst->format,col.r,col.g,col.b);
SDL_Rect clip = {xpos,ypos,xend-xpos,yend-ypos};
draw_unit_ellipse(dst,colour,clip,xpos-xsrc,ypos-ysrc-height_adjust,unit_image,!face_left);
}
}
const bool energy_uses_alpha = highlight_ratio < 1.0 && blend_with == 0;
@ -1378,14 +1385,6 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image_override,
}
}
}
if(show_unit_colour && unit_image != NULL) {
const SDL_Color& col = font::get_side_colour(it->second.side());
const short colour = SDL_MapRGB(dst->format,col.r,col.g,col.b);
SDL_Rect clip = {xpos,ypos,xend-xpos,yend-ypos};
draw_ellipse(dst,colour,clip,xpos-xsrc+zoom_/4,ypos-ysrc + zoom_*0.66,zoom_*0.6,zoom_/8,unit_image);
}
}
void display::draw_footstep(const gamemap::location& loc, int xloc, int yloc)

View file

@ -28,18 +28,23 @@ int sdl_add_ref(SDL_Surface* surface)
return 0;
}
void draw_ellipse(SDL_Surface* surf, short colour, const SDL_Rect& clip, int xloc, int yloc, int width, int height,
SDL_Surface* behind)
void draw_unit_ellipse(SDL_Surface* target, short colour, const SDL_Rect& clip, int unitx, int unity,
SDL_Surface* behind, bool image_reverse)
{
const int xloc = unitx + (behind->w*2)/10;
const int yloc = unity + (behind->h*7)/10;
const int width = (behind->w*6)/10;
const int height = behind->h/6;
const double centerx = xloc + double(width)*0.5;
const double centery = yloc + double(height)*0.5;
const double r = double(width)*0.5;
const double yratio = double(height)/double(width);
surface_lock lock(surf);
surface_lock lock(behind);
const short* const pixels = lock.pixels();
const int pad = is_odd(surf->w) ? 1 : 0;
const int pad = is_odd(behind->w) ? 1 : 0;
int last_y = 0;
for(int xit = xloc; xit != xloc+width; ++xit) {
@ -51,22 +56,24 @@ void draw_ellipse(SDL_Surface* surf, short colour, const SDL_Rect& clip, int xlo
const int direction = y > last_y ? 1 : -1;
for(int i = last_y; i != y+direction; i += direction) {
int yit = yloc+height/2-y;
const int xpos = xit - xloc;
int ypos = yit - yloc;
if(xit >= clip.x && yit >= clip.x && xit < clip.x + clip.w && yit < clip.y + clip.h &&
xpos >= 0 && ypos >= 0 && xpos < surf->w && ypos < surf->h &&
pixels[ypos*(surf->w+pad) + xpos] == 0) {
int xpos = xit - unitx;
if(image_reverse)
xpos = behind->w - xpos - 1;
int ypos = yit - unity;
if(xit >= clip.x && yit >= clip.y && xit < clip.x + clip.w && yit < clip.y + clip.h &&
xpos >= 0 && ypos >= 0 && xpos < behind->w && ypos < behind->h &&
pixels[ypos*(behind->w+pad) + xpos] == 0) {
SDL_Rect rect = {xit,yit,1,1};
SDL_FillRect(surf,&rect,colour);
SDL_FillRect(target,&rect,colour);
}
yit = yloc+height/2+y;
ypos = yit - yloc;
if(xit >= clip.x && yit >= clip.x && xit < clip.x + clip.w && yit < clip.y + clip.h &&
xpos >= 0 && ypos >= 0 && xpos < surf->w && ypos < surf->h) {
// pixels[ypos*(surf->w+pad) + xpos] == 0) {
ypos = yit - unity;
if(xit >= clip.x && yit >= clip.y && xit < clip.x + clip.w && yit < clip.y + clip.h &&
xpos >= 0 && ypos >= 0 && xpos < behind->w && ypos < behind->h) {
SDL_Rect rect = {xit,yit,1,1};
SDL_FillRect(surf,&rect,colour);
SDL_FillRect(target,&rect,colour);
}
}

View file

@ -41,8 +41,8 @@ int sdl_add_ref(SDL_Surface* surface);
typedef util::scoped_resource<SDL_Surface*,free_sdl_surface> scoped_sdl_surface;
void draw_ellipse(SDL_Surface* surf, short colour, const SDL_Rect& clip, int xloc, int yloc, int width, int height,
SDL_Surface* behind);
void draw_unit_ellipse(SDL_Surface* surf, short colour, const SDL_Rect& clip, int unitx, int unity,
SDL_Surface* behind, bool image_reverse);
SDL_Surface* clone_surface(SDL_Surface* surface);
SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h);