ellipse improvements

This commit is contained in:
uid68803 2004-01-08 23:59:19 +00:00
parent adcb921369
commit fc284c17f3
3 changed files with 35 additions and 14 deletions

View file

@ -1188,13 +1188,9 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image_override,
SDL_Surface* const dst = screen_.getSurface();
Pixel grid_colour = SDL_MapRGB(dst->format,0,0,0);
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();
if(show_unit_colour) {
const SDL_Color& colour = font::get_side_colour(it->second.side());
grid_colour = SDL_MapRGB(dst->format,colour.r,colour.g,colour.b);
}
int j;
for(j = ypos; j != yend; ++j) {
@ -1289,10 +1285,6 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image_override,
}
}
if(show_unit_colour) {
draw_ellipse(dst,grid_colour,xpos,ypos,zoom_,zoom_);
}
if(game_config::debug && debugHighlights_.count(gamemap::location(x,y))) {
const scoped_sdl_surface cross(image::get_image(game_config::cross_image));
if(cross != NULL)
@ -1386,6 +1378,14 @@ 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,colour.r,colour.g,colour.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,23 +28,43 @@ int sdl_add_ref(SDL_Surface* surface)
return 0;
}
void draw_ellipse(SDL_Surface* surf, short colour, int xloc, int yloc, int width, int height, const SDL_Rect& clip)
void draw_ellipse(SDL_Surface* surf, short colour, const SDL_Rect& clip, int xloc, int yloc, int width, int height,
SDL_Surface* behind)
{
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);
const short* const pixels = lock.pixels();
const int pad = is_odd(surf->w) ? 1 : 0;
int last_y = 0;
for(int xit = xloc; xit != xloc+width; ++xit) {
//r^2 = x^2 + y^2
//y^2 = r^2 - x^2
const double x = double(xit) - centerx;
const int y = int(sqrt(r*r - x*x));
const int y = int(sqrt(r*r - x*x)*yratio);
const int direction = y > last_y ? 1 : -1;
for(int i = last_y; i != y+direction; i += direction) {
const int yit = yloc+height/2-y;
if(xit >= 0 && yit >= 0 && xit < surf->w && yit < surf->h) {
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) {
SDL_Rect rect = {xit,yit,1,1};
SDL_FillRect(surf,&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) {
SDL_Rect rect = {xit,yit,1,1};
SDL_FillRect(surf,&rect,colour);
}

View file

@ -41,7 +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, int xloc, int yloc, int width, int height);
void draw_ellipse(SDL_Surface* surf, short colour, const SDL_Rect& clip, int xloc, int yloc, int width, int height,
SDL_Surface* behind);
SDL_Surface* clone_surface(SDL_Surface* surface);
SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h);