/* * File: tilebuf.h * Created by: ennewalker on Sat Jan 5 01:33:53 2008 UTC * * Modified for Crawl Reference by $Author: ennewalker $ on $Date: 2008-03-07 $ */ #ifndef TILEBUF_H #define TILEBUF_H class FTFont; class formatted_string; class GenericTexture; class TilesTexture; #include #include struct VColour { VColour() {} VColour(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a = 255) : r(_r), g(_g), b(_b), a(_a) {} unsigned char r; unsigned char g; unsigned char b; unsigned char a; static VColour white; static VColour black; static VColour transparent; }; struct PTCVert { float pos_x; float pos_y; float tex_x; float tex_y; VColour col; }; struct PTVert { float pos_x; float pos_y; float tex_x; float tex_y; }; struct PCVert { float pos_x; float pos_y; VColour col; }; // V: vertex data template class VertBuffer { public: VertBuffer(const GenericTexture *tex, int prim); void add(const V& vert); V& get_next(); void draw() const; void clear(); protected: std::vector m_verts; const GenericTexture *m_tex; int m_prim; }; class FontBuffer : public VertBuffer { public: FontBuffer(FTFont *font); void add(const formatted_string &fs, float x, float y); void add(const std::string &s, const VColour &col, float x, float y); protected: FTFont *m_font; }; class TileBuffer : public VertBuffer { public: TileBuffer(const TilesTexture *tex); void add(int idx, float x, float y); // Note: this could invalidate previous additions if they were // from a different texture. void set_tex(const TilesTexture *tex); }; class ShapeBuffer : public VertBuffer { public: ShapeBuffer(); void add(float sx, float sy, float ex, float ey, const VColour &c); }; class LineBuffer : public VertBuffer { public: LineBuffer(); void add(float sx, float sy, float ex, float ey, const VColour &c); void add_square(float sx, float sy, float ex, float ey, const VColour &c); }; ///////////////////////////////////////////////////////////////////////////// // template implementation template inline VertBuffer::VertBuffer(const GenericTexture *tex, int prim) : m_tex(tex), m_prim(prim) { } template inline void VertBuffer::add(const V& vert) { m_verts.push_back(vert); } template inline V& VertBuffer::get_next() { int last = m_verts.size(); m_verts.resize(last + 1); return (m_verts[last]); } template inline void VertBuffer::clear() { m_verts.clear(); } #endif