Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Shapes.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  *
21  * Part of this file comes from SFML, with the same license:
22  * Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23  */
24 #ifndef GF_SHAPES_H
25 #define GF_SHAPES_H
26 
27 #include <cstddef>
28 #include <vector>
29 
30 #include "Circ.h"
31 #include "Polygon.h"
32 #include "Portability.h"
33 #include "Rect.h"
34 #include "Shape.h"
35 #include "Vector.h"
36 
37 namespace gf {
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 inline namespace v1 {
40 #endif
41 
64  class GF_API RectangleShape : public Shape {
65  public:
71  RectangleShape(Vector2f size = Vector2f{ 0.0f, 0.0f });
72 
81  explicit RectangleShape(const RectF& rect);
82 
90  void setSize(Vector2f size);
91 
99  Vector2f getSize() const {
100  return m_size;
101  }
102 
103  virtual std::size_t getPointCount() const override;
104  virtual Vector2f getPoint(std::size_t index) const override;
105 
106  private:
107  Vector2f m_size;
108  };
109 
141  class GF_API CircleShape : public Shape {
142  public:
149  CircleShape(float radius = 0, std::size_t pointCount = 30);
150 
160  explicit CircleShape(const CircF& circ, std::size_t pointCount = 30);
161 
169  void setRadius(float radius);
170 
178  float getRadius() const {
179  return m_radius;
180  }
181 
189  void setPointCount(std::size_t pointCount);
190 
191  virtual std::size_t getPointCount() const override;
192  virtual Vector2f getPoint(std::size_t index) const override;
193 
194  private:
195  float m_radius;
196  std::size_t m_pointCount;
197  };
198 
229  class GF_API ConvexShape : public Shape {
230  public:
236  ConvexShape(std::size_t pointCount);
237 
243  ConvexShape(const Polygon& polygon);
244 
254  void setPointCount(std::size_t pointCount);
255 
263  void setPoint(std::size_t index, Vector2f point);
264 
265  virtual std::size_t getPointCount() const override;
266  virtual Vector2f getPoint(std::size_t index) const override;
267 
268  private:
269  std::vector<Vector2f> m_points;
270  };
271 
272 
297  class GF_API StarShape : public Shape {
298  public:
306  StarShape(float minRadius = 0, float maxRadius = 0, std::size_t branches = 7);
307 
314  void setMinRadius(float minRadius);
315 
322  float getMinRadius() const {
323  return m_minRadius;
324  }
325 
332  void setMaxRadius(float maxRadius);
333 
340  float getMaxRadius() const {
341  return m_maxRadius;
342  }
343 
350  void setBranches(std::size_t branches);
351 
358  std::size_t getBranches() const {
359  return m_branches;
360  }
361 
362  virtual std::size_t getPointCount() const override;
363  virtual Vector2f getPoint(std::size_t index) const override;
364 
365  private:
366  float m_minRadius;
367  float m_maxRadius;
368  std::size_t m_branches;
369  };
370 
371 
395  class GF_API RoundedRectangleShape : public Shape {
396  public:
404  RoundedRectangleShape(Vector2f size = Vector2f{ 0.0f, 0.0f }, float radius = 0.0f, std::size_t cornerPointCount = 8);
405 
416  explicit RoundedRectangleShape(const RectF& rect, float radius = 0.0f, std::size_t cornerPointCount = 8);
417 
425  void setSize(Vector2f size);
426 
434  Vector2f getSize() const {
435  return m_size;
436  }
437 
445  void setRadius(float radius);
446 
454  float getRadius() const {
455  return m_radius;
456  }
457 
465  void setCornerPointCount(std::size_t cornerPointCount);
466 
467  virtual std::size_t getPointCount() const override;
468  virtual Vector2f getPoint(std::size_t index) const override;
469 
470  private:
471  Vector2f m_size;
472  float m_radius;
473  std::size_t m_cornerPointCount;
474  };
475 
476 
477 #ifndef DOXYGEN_SHOULD_SKIP_THIS
478 }
479 #endif
480 }
481 
482 #endif // GF_SHAPES_H
Base class for textured shapes with outline.
Definition: Shape.h:73
Specialized shape representing a rounded rectangle.
Definition: Shapes.h:395
Specialized shape representing a rectangle.
Definition: Shapes.h:64
float getMinRadius() const
Get the minimum radius.
Definition: Shapes.h:322
float getMaxRadius() const
Get the maximum radius.
Definition: Shapes.h:340
The namespace for gf classes.
Definition: Action.h:35
Specialized shape representing a circle.
Definition: Shapes.h:141
Vector2f getSize() const
Get the size of the rectangle.
Definition: Shapes.h:99
float getRadius() const
Get the radius of the corner.
Definition: Shapes.h:454
A convex polygon.
Definition: Polygon.h:46
Specialized shape representing a star.
Definition: Shapes.h:297
Vector2f getSize() const
Get the size of the rectangle.
Definition: Shapes.h:434
Specialized shape representing a convex polygon.
Definition: Shapes.h:229
std::size_t getBranches() const
Get the number of branches.
Definition: Shapes.h:358
float getRadius() const
Get the radius of the circle.
Definition: Shapes.h:178