Added transparency to nodes

This commit is contained in:
Anna Rose 2011-06-22 18:24:20 -04:00
parent fc08adcade
commit fc8a76c1db
3 changed files with 19 additions and 1 deletions

View File

@ -87,3 +87,13 @@ void DrawUtils::draw_line(Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint16 wid
cy += dy;
}
}
bool DrawUtils::transpare(SDL_Surface* surface, int r, int g, int b)
{
if (surface == NULL) return false;
SDL_SetColorKey(surface, SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB(surface->format, r, g, b));
return true;
}

View File

@ -13,10 +13,14 @@ class DrawUtils
public:
DrawUtils() {}
static SDL_Surface* load(string file);
static bool draw(SDL_Surface* dest, SDL_Surface* drawable, int x, int y);
static bool draw(SDL_Surface* dest, SDL_Surface* drawable, int x, int y,
int x2, int y2, int w, int h);
static void draw_line(Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint16 width, Uint32 colour, SDL_Surface* dest);
// transpare (v) - to make transparent
static bool transpare(SDL_Surface* surface, int r, int g, int b);
};
#endif

View File

@ -47,7 +47,9 @@ bool GameCore::init()
}
background = DrawUtils::load("background.bmp");
node = DrawUtils::load("node.bmp");
DrawUtils::transpare(node, 255, 0, 255);
if (background == NULL || node == NULL)
{
@ -63,6 +65,8 @@ bool GameCore::init()
void GameCore::render()
{
DrawUtils::draw(display, background, 0, 0);
list<Vertex> vertices = graph.get_vertices();
list<Edge> edges = graph.get_edges();
@ -77,7 +81,7 @@ void GameCore::render()
cursor != edges.end(); cursor++)
{
Edge e = *cursor;
DrawUtils::draw_line(e.a.x, e.a.y, e.b.x, e.b.y, 2, 0xffffff, display);
DrawUtils::draw_line(e.a.x, e.a.y, e.b.x, e.b.y, 2, 0x000000, display);
}
SDL_Flip(display);