00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef GUI_SPRITE_HPP
00011 #define GUI_SPRITE_HPP
00012
00013 #include <utils.hpp>
00014 #include <utils_refptr.hpp>
00015 #include <utils_wptr.hpp>
00016 #include <array>
00017 #include <vector>
00018
00019 #include "gui_vector2.hpp"
00020 #include "gui_color.hpp"
00021
00022 namespace gui
00023 {
00024 class manager;
00025 class render_target;
00026 class material;
00027
00028 struct vertex
00029 {
00030 vertex();
00031 vertex(const vector2f& mPos, const vector2f& mUV, const color& mCol);
00032
00033 vector2f pos;
00034 vector2f uvs;
00035 color col;
00036 };
00037
00038 enum blend_mode
00039 {
00040 BLEND_NORMAL,
00041 BLEND_ADD,
00042 BLEND_MUL
00043 };
00044
00045 struct quad
00046 {
00047 std::array<vertex, 4> v;
00048 utils::refptr<material> mat;
00049 blend_mode blend;
00050 };
00051
00053
00063 class sprite
00064 {
00065 public :
00066
00068 sprite(const manager* pManager, utils::refptr<material> pMat);
00069
00071 sprite(const manager* pManager, utils::refptr<material> pMat, float fWidth, float fHeight);
00072
00074 sprite(const manager* pManager, utils::refptr<material> pMat, float fU, float fV, float fWidth, float fHeight);
00075
00077 virtual ~sprite();
00078
00080
00084 virtual void render(float fX, float fY) const;
00085
00087
00095 virtual void render_ex(float fX, float fY,
00096 float fRot,
00097 float fHScale = 1.0f, float fVScale = 1.0f) const;
00098
00100
00107 virtual void render_2v(float fX1, float fY1,
00108 float fX3, float fY3);
00109
00111
00122 virtual void render_4v(float fX1, float fY1,
00123 float fX2, float fY2,
00124 float fX3, float fY3,
00125 float fX4, float fY4);
00126
00128
00131 virtual void render_static() const;
00132
00134
00140 virtual void render_quads(const std::vector<std::array<vertex,4>>& lQuadsArray) const;
00141
00143
00147 virtual void set_quad(const std::array<vertex,4>& lVertexArray);
00148
00150
00156 virtual void set_color(const color& mColor, uint uiIndex = (uint)(-1));
00157
00159
00163 virtual void set_desaturated(bool bDesaturated);
00164
00166
00169 virtual void set_blend_mode(blend_mode mBlendMode);
00170
00172
00177 virtual void set_hot_spot(const vector2f& mHotSpot);
00178
00180
00186 virtual void set_hot_spot(float fX, float fY);
00187
00189
00195 virtual void set_texture_rect(const std::array<float,4>& lTextureRect, bool bNormalized = false);
00196
00198
00207 virtual void set_texture_rect(float fX1, float fY1, float fX3, float fY3, bool bNormalized = false);
00208
00210
00216 virtual void set_texture_coords(const std::array<float,8>& lTextureCoords, bool bNormalized = false);
00217
00219
00232 virtual void set_texture_coords(float fX1, float fY1,
00233 float fX2, float fY2,
00234 float fX3, float fY3,
00235 float fX4, float fY4,
00236 bool bNormalized = false);
00237
00239
00244 virtual void set_dimensions(float fWidth, float fHeight);
00245
00247
00249 virtual float get_width() const;
00250
00252
00254 virtual float get_height() const;
00255
00257
00259 virtual color get_color() const;
00260
00262
00264 virtual blend_mode get_blend_mode() const;
00265
00267
00269 virtual std::array<float,4> get_texture_rect() const;
00270
00272
00275 virtual std::array<float,8> get_texture_coords(bool bNormalized = false) const;
00276
00277 private :
00278
00279 const manager* pManager_;
00280
00281 mutable quad mQuad_;
00282 vector2f mHotSpot_;
00283 float fWidth_, fHeight_;
00284 };
00285 }
00286
00287 #endif