diff options
author | ennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-10-16 00:09:45 +0000 |
---|---|---|
committer | ennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-10-16 00:09:45 +0000 |
commit | 42f25ae23ee34f9ae3a0e31fc0039258deab2bc3 (patch) | |
tree | cb46297c71d456fe35854a23918518b900207089 /crawl-ref/source/tilebuf.h | |
parent | 84789445f8c4937c2930a0d67e602408c2605201 (diff) | |
download | crawl-ref-42f25ae23ee34f9ae3a0e31fc0039258deab2bc3.tar.gz crawl-ref-42f25ae23ee34f9ae3a0e31fc0039258deab2bc3.zip |
Support for inline graphics and mouse input on menus.
Menus in the console version should be unchanged. Let me know if this is not the case.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7258 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/tilebuf.h')
-rw-r--r-- | crawl-ref/source/tilebuf.h | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/crawl-ref/source/tilebuf.h b/crawl-ref/source/tilebuf.h new file mode 100644 index 0000000000..9368f1eb2b --- /dev/null +++ b/crawl-ref/source/tilebuf.h @@ -0,0 +1,141 @@ +/* + * 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 <vector> + +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 V> +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<V> m_verts; + const GenericTexture *m_tex; + int m_prim; +}; + +class FontBuffer : public VertBuffer<PTCVert> +{ +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<PTVert> +{ +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<PCVert> +{ +public: + ShapeBuffer(); + void add(float sx, float sy, float ex, float ey, const VColour &c); +}; + +class LineBuffer : public VertBuffer<PCVert> +{ +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<class V> +inline VertBuffer<V>::VertBuffer(const GenericTexture *tex, int prim) : + m_tex(tex), m_prim(prim) +{ +} + +template<class V> +inline void VertBuffer<V>::add(const V& vert) +{ + m_verts.push_back(vert); +} + +template<class V> +inline V& VertBuffer<V>::get_next() +{ + int last = m_verts.size(); + m_verts.resize(last + 1); + return (m_verts[last]); +} + +template<class V> +inline void VertBuffer<V>::clear() +{ + m_verts.clear(); +} + +#endif |