added in basic ellipse algorithm

This commit is contained in:
uid68803 2004-01-08 22:14:41 +00:00
parent ca91c49140
commit 4b5d14c86a
3 changed files with 36 additions and 2 deletions

View file

@ -1275,7 +1275,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image_override,
}
}
if((grid_ || show_unit_colour) && srcrect.w >= 1) {
if(grid_ && srcrect.w >= 1) {
SDL_Rect rect = dstrect;
if(j == ypos || j == yend-1) {
SDL_FillRect(dst,&rect,grid_colour);
@ -1289,6 +1289,10 @@ 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)
@ -2205,6 +2209,7 @@ void display::draw_unit(int x, int y, SDL_Surface* image,
bool reverse, bool upside_down,
double alpha, Pixel blendto, double submerged)
{
std::cerr << "drawing unit submerged at " << submerged << "\n";
//the alpha value to use for submerged units
static const double unit_submerged_alpha = 0.2;
@ -2224,7 +2229,7 @@ void display::draw_unit(int x, int y, SDL_Surface* image,
surface_lock srclock(image);
const Pixel* src = srclock.pixels();
const int height = image->h; //*(1.0 - submerged);
const int height = image->h;
const int submerge_height = y + image->h*(1.0 - submerged);
const int endy = (y + height) < h ? (y + height) : h;

View file

@ -12,6 +12,7 @@
*/
#include <algorithm>
#include <cmath>
#include <iostream>
#include "game.hpp"
@ -27,6 +28,32 @@ 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)
{
const double centerx = xloc + double(width)*0.5;
const double centery = yloc + double(height)*0.5;
const double r = double(width)*0.5;
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 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) {
SDL_Rect rect = {xit,yit,1,1};
SDL_FillRect(surf,&rect,colour);
}
}
last_y = y;
}
}
SDL_Surface* clone_surface(SDL_Surface* surface)
{
if(surface == NULL)

View file

@ -41,6 +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);
SDL_Surface* clone_surface(SDL_Surface* surface);
SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h);