Added code for drawing a circle around selected vertex

This commit is contained in:
Anna Rose 2011-07-01 17:44:43 -04:00
parent 7fd7f90770
commit d15e6590ec
3 changed files with 38 additions and 2 deletions

View File

@ -173,8 +173,6 @@ void DrawUtils::draw_text(SDL_Surface* display, string text, int x, int y,
return;
}
transpare(surface);
/* Blit the surface */
dest.x = (center_x ? (display->w - surface->w) / 2 : x);
dest.y = (center_y ? (display->h - surface->h) / 2 : y);
@ -184,3 +182,33 @@ void DrawUtils::draw_text(SDL_Surface* display, string text, int x, int y,
SDL_BlitSurface(surface, NULL, display, &dest);
SDL_FreeSurface(surface);
}
void DrawUtils::draw_circle(SDL_Surface* dest, Sint16 int_x, Sint16 int_y,
Uint16 int_r, Uint32 colour)
{
float x = static_cast<float> (int_x);
float y = static_cast<float> (int_y);
float r = static_cast<float> (int_r);
SDL_Rect pen;
float i;
for (i=0; i < 6.28318531; i += 0.0034906585)
{
pen.x = static_cast<int> (x + cos(i) * r);
pen.y = static_cast<int> (y + sin(i) * r);
int w = 2;
int h = 2;
if (pen.x >= dest->clip_rect.x &&
pen.y >= dest->clip_rect.y &&
pen.x + pen.w <= dest->clip_rect.w &&
pen.y + pen.h <= dest->clip_rect.h)
SDL_FillRect(dest, &pen,
SDL_MapRGBA(dest->format,
(colour >> 16) & 0xff,
(colour >> 8) & 0xff,
colour & 0xff, 1));
}
}

View File

@ -21,6 +21,7 @@ class DrawUtils
int x2, int y2, int w, int h);
static void draw_line(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint16 width, Uint32 colour);
static void draw_circle(SDL_Surface* dest, Sint16 x, Sint16 y, Uint16 r, Uint32 colour);
static void draw_circle_filled(SDL_Surface* dest, Sint16 x, Sint16 y, Uint16 r, Uint32 colour);
static void draw_text(SDL_Surface* display, string text, int x, int y,

View File

@ -99,6 +99,13 @@ void Game::render()
}
}
// Finally, ring the selected vertex
if (data.get_current_vertex() != NULL)
{
Vertex* v = data.get_current_vertex();
DrawUtils::draw_circle(display, v->x, v->y, v->r + 5, 0x000000);
}
SDL_Flip(display);
}