TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_basic_shapes.hpp
1 
9 #ifndef TurtleBrains_BasicShapes_hpp
10 #define TurtleBrains_BasicShapes_hpp
11 
12 #include <turtle_brains/graphics/implementation/tbi_renderer.hpp>
13 #include <turtle_brains/graphics/tb_graphic.hpp>
14 #include <turtle_brains/math/tb_vector.hpp>
15 
16 #include <vector>
17 
18 namespace TurtleBrains
19 {
20  namespace Graphics
21  {
22  class OutlinedPolygonShape;
23 
27  class PolygonShape : public Graphic
28  {
29  public:
30 
34  PolygonShape(void);
35 
39  PolygonShape(const PolygonShape& other);
40 
44  virtual ~PolygonShape(void);
45 
49  virtual void SetColor(const tbGraphics::Color& newColor) override;
50 
54  virtual PixelSpace GetPixelWidth(void) const override;
55 
59  virtual PixelSpace GetPixelHeight(void) const override;
60 
61  protected:
67  virtual void OnRender(void) const override;
68 
72  virtual void ClearVertices(void);
73 
78  virtual void AddVertex(const tbMath::Vector2& position);
79 
84  void SetAsTriangles(void) { mPrimitiveType = tbImplementation::Renderer::kTriangles; }
85 
91  void SetAsTriangleFan(void) { mPrimitiveType = tbImplementation::Renderer::kTriangleFan; }
92 
98  void SetAsTriangleStrip(void) { mPrimitiveType = tbImplementation::Renderer::kTriangleStrip; }
99 
105  void SetAsLines(void) { mPrimitiveType = tbImplementation::Renderer::kLines; }
106 
111  void SetAsLineStrip(void) { mPrimitiveType = tbImplementation::Renderer::kLineStrip; }
112 
119  void SetAsLineLoop(void) { mPrimitiveType = tbImplementation::Renderer::kLineLoop; }
120 
130  void SetVertexPosition(size_t vertexIndex, const tbMath::Vector2& position);
131 
136  void RecomputeBounds(void);
137 
138  private:
139  friend class OutlinedPolygonShape;
140 
141  std::vector<tbImplementation::Renderer::Vertex2D> mVertices;
142  tbImplementation::Renderer::PrimitiveType mPrimitiveType;
143  tbMath::Vector2 mMinimumBounds;
144  tbMath::Vector2 mMaximumBounds;
145  };
146 
147 
153  {
154  public:
158  OutlinedPolygonShape(void);
159 
164 
168  virtual ~OutlinedPolygonShape(void);
169 
173  virtual void ClearVertices(void) override;
174 
181  void SetFillColor(const tbGraphics::Color& fillColor);
182 
188  void SetOutlineColor(const tbGraphics::Color& outlineColor);
189 
190  protected:
197  void AddOutlineVertex(const tbMath::Vector2& position);
198 
205  void AddShapeVertex(const tbMath::Vector2& position);
206 
213  void AddShapeAndOutlineVertex(const tbMath::Vector2& position);
214 
219  virtual void OnRender(void) const override;
220 
221  private:
222  //Privately overridden to protect from ambiguous SetColor() mistakes, use SetFillColor() or SetOutlineColor().
223  virtual void SetColor(const tbGraphics::Color& color) override;
224 
225  //Privately overridden to protect from ambiguous AddVertex() mistakes, use AddOutlinedVertex(), AddShapeVertex()
226  // or AddShapeAndOutlineVertex() for clarity.
227  virtual void AddVertex(const tbMath::Vector2& position) override;
228 
229  PolygonShape mOutline;
230  };
231 
232 
237  class BoxShape : public PolygonShape
238  {
239  public:
249  explicit BoxShape(const float width = 64.0f, const float height = 64.0f, const tbGraphics::Color& color = tbGraphics::ColorPalette::White,
250  const tbMath::Vector2& position = tbMath::Vector2::Zero());
251 
258  void SetSize(const float width, const float height);
259 
263  virtual ~BoxShape(void);
264  };
265 
266 
272  {
273  public:
284  explicit OutlinedBoxShape(const float width = 64.0f, const float height = 64.0f, const tbGraphics::Color& fillColor = tbGraphics::ColorPalette::White,
286 
290  virtual ~OutlinedBoxShape(void);
291  };
292 
293 
300  class FullScreenQuad : public BoxShape
301  {
302  public:
306  explicit FullScreenQuad(const tbGraphics::Color& color);
307 
311  virtual ~FullScreenQuad(void);
312  };
313 
314 
319  class CircleShape : public PolygonShape
320  {
321  public:
333  explicit CircleShape(const float radius = 64.0f, const tbGraphics::Color& color = tbGraphics::ColorPalette::White,
334  const tbMath::Vector2& position = tbMath::Vector2::Zero(), const int sectionCount = 30);
335 
339  virtual ~CircleShape(void);
340 
352  void SetSize(const float radius, const int sectionCount = 30);
353  };
354 
355 
361  {
362  public:
375  explicit OutlinedCircleShape(const float radius = 64.0f, const tbGraphics::Color& fillColor = tbGraphics::ColorPalette::White,
377  const int sectionCount = 30);
378 
382  virtual ~OutlinedCircleShape(void);
383  };
384 
385  }; /* namespace Graphics */
386 }; /* namespace TurtleBrains */
387 
389 
390 #endif /* TurtleBrains_BasicShapes_hpp */
Definition: tb_vector.hpp:48
virtual void ClearVertices(void) override
Definition: tb_graphic.hpp:61
BoxShape(const float width=64.0f, const float height=64.0f, const tbGraphics::Color &color=tbGraphics::ColorPalette::White, const tbMath::Vector2 &position=tbMath::Vector2::Zero())
OutlinedBoxShape(const float width=64.0f, const float height=64.0f, const tbGraphics::Color &fillColor=tbGraphics::ColorPalette::White, const tbGraphics::Color &outlineColor=tbGraphics::ColorPalette::Black, const tbMath::Vector2 &position=tbMath::Vector2::Zero())
void SetAsTriangles(void)
Definition: tb_basic_shapes.hpp:84
Give the GameScene and Entities something to display, Text, Sprites and AnimatedSprites help bring th...
OutlinedCircleShape(const float radius=64.0f, const tbGraphics::Color &fillColor=tbGraphics::ColorPalette::White, const tbGraphics::Color &outlineColor=tbGraphics::ColorPalette::Black, const tbMath::Vector2 &position=tbMath::Vector2::Zero(), const int sectionCount=30)
void SetFillColor(const tbGraphics::Color &fillColor)
void SetSize(const float width, const float height)
virtual PixelSpace GetPixelHeight(void) const override
void AddShapeVertex(const tbMath::Vector2 &position)
Definition: tb_basic_shapes.hpp:152
void AddOutlineVertex(const tbMath::Vector2 &position)
Definition: tb_basic_shapes.hpp:27
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
static Vector2 Zero(void)
Definition: tb_vector.hpp:54
Definition: tb_basic_shapes.hpp:271
CircleShape(const float radius=64.0f, const tbGraphics::Color &color=tbGraphics::ColorPalette::White, const tbMath::Vector2 &position=tbMath::Vector2::Zero(), const int sectionCount=30)
Definition: tb_color.hpp:24
void SetAsLines(void)
Definition: tb_basic_shapes.hpp:105
FullScreenQuad(const tbGraphics::Color &color)
void SetAsLineStrip(void)
Definition: tb_basic_shapes.hpp:111
void SetAsTriangleFan(void)
Definition: tb_basic_shapes.hpp:91
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.hpp:36
Definition: tb_basic_shapes.hpp:360
void AddShapeAndOutlineVertex(const tbMath::Vector2 &position)
Definition: tb_basic_shapes.hpp:319
virtual void AddVertex(const tbMath::Vector2 &position)
virtual void SetColor(const tbGraphics::Color &newColor) override
Definition: tb_basic_shapes.hpp:300
void SetOutlineColor(const tbGraphics::Color &outlineColor)
void SetAsLineLoop(void)
Definition: tb_basic_shapes.hpp:119
virtual PixelSpace GetPixelWidth(void) const override
void SetAsTriangleStrip(void)
Definition: tb_basic_shapes.hpp:98
virtual void OnRender(void) const override
virtual void OnRender(void) const override
void SetVertexPosition(size_t vertexIndex, const tbMath::Vector2 &position)
void SetSize(const float radius, const int sectionCount=30)
Definition: tb_basic_shapes.hpp:237