GameKit  0.0.1a
C++ gamedev tools
RectangleShape.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: RectangleShape.hpp
5  *
6  * Description:
7  *
8  * Created: 27/09/2014 17:06:48
9  *
10  * Author: Quentin Bazin, <gnidmoo@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_RECTANGLESHAPE_HPP_
15 #define GK_RECTANGLESHAPE_HPP_
16 
17 #include <array>
18 
19 #include "gk/graphics/Color.hpp"
20 #include "gk/gl/IDrawable.hpp"
21 #include "gk/gl/Transformable.hpp"
22 #include "gk/gl/VertexBuffer.hpp"
23 
24 namespace gk {
25 
26 class RectangleShape : public IDrawable, public Transformable {
27  public:
29  RectangleShape(float width, float height, const Color &color = Color::White);
30 
31  const Color &color() const { return m_color; }
33 
34  void setWireframeMode(bool wireframeMode) { m_wireframeMode = wireframeMode; }
35 
36  float width() const { return m_width; }
37  float height() const { return m_height; }
38 
39  Vector2f getSize() const { return Vector2f{m_width, m_height}; }
40 
41  void setSize(float width, float height) { m_width = width; m_height = height; updateVertexBuffer(); }
42 
44  void setOutlineThickness(int outlineThickness) { m_outlineThickness = outlineThickness; updateVertexBuffer(); }
45 
46  private:
47  void updateVertexBuffer() const;
48 
49  void draw(RenderTarget &target, RenderStates states) const override;
50 
52 
53  bool m_wireframeMode = false;
54 
55  float m_width = 0;
56  float m_height = 0;
57 
59 
62 
63  std::array<GLubyte, 6 * 5> m_indices{
64  0, 1, 3,
65  3, 1, 2
66  };
67 };
68 
69 } // namespace gk
70 
71 #endif // GK_RECTANGLESHAPE_HPP_
void setOutlineThickness(int outlineThickness)
Utility class for manipulating RGBA colors.
Definition: Color.hpp:25
void draw(RenderTarget &target, RenderStates states) const override
Draw the object to a render target.
float height() const
void setColor(const Color &color)
float width() const
static const Color White
White predefined color.
Definition: Color.hpp:117
void setOutlineColor(const Color &color)
std::array< GLubyte, 6 *5 > m_indices
Vector2f getSize() const
void setSize(float width, float height)
const Color & color() const
void updateVertexBuffer() const
Abstract base class for objects that can be drawn to a render target.
Definition: IDrawable.hpp:25
void setWireframeMode(bool wireframeMode)