Gamedev Framework (gf)  0.20.0
A C++17 framework for 2D games
LightShape.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2021 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 #ifndef GF_LIGHT_SHAPE_H
22 #define GF_LIGHT_SHAPE_H
23 
24 #include "Circ.h"
25 #include "GraphicsApi.h"
26 #include "Polygon.h"
27 #include "Rect.h"
28 #include "Transformable.h"
29 #include "Vector.h"
30 #include "VertexArray.h"
31 
32 namespace gf {
33 #ifndef DOXYGEN_SHOULD_SKIP_THIS
34 inline namespace v1 {
35 #endif
36 
46  };
47 
54  class GF_GRAPHICS_API LightShape : public Transformable {
55  public:
57 
59 
61 
63 
64  std::size_t getPointCount() const;
65 
66  Vector2f getPoint(std::size_t index) const;
67 
68  Vector2f getPrevPoint(std::size_t index) const;
69 
70  Vector2f getNextPoint(std::size_t index) const;
71 
72  void setColor(const Color4f& color);
73 
74  Color4f getColor() const;
75 
76  void setVisibility(LightShapeVisibility visibility);
77 
78  LightShapeVisibility getVisibility() const;
79 
80  void setActive(bool active = true) {
81  m_active = active;
82  }
83 
84  bool isActive() const {
85  return m_active;
86  }
87 
88  RectF getLocalBounds() const;
89 
90  void setAnchor(Anchor anchor);
91 
92  void draw(RenderTarget& target, const RenderStates& states) override;
93 
94  private:
95  void updateGeometry();
96  void updateColors();
97 
98  private:
99  Polygon m_polygon;
100  Color4f m_color;
101  LightShapeVisibility m_visibility;
102  bool m_active = true;
103 
104  VertexArray m_vertices;
105  RectF m_bounds;
106  };
107 
108 
109 
110 #ifndef DOXYGEN_SHOULD_SKIP_THIS
111 }
112 #endif
113 }
114 
115 #endif // GF_LIGHT_SHAPE_H
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
A set of primitives.
Definition: VertexArray.h:65
Light shape.
Definition: LightShape.h:54
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:102
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
bool isActive() const
Definition: LightShape.h:84
Utility class for manipulating circles.
Definition: Circ.h:61
The namespace for gf classes.
Definition: Action.h:35
A 4D vector.
Definition: Vector.h:852
A convex polygon.
Definition: Polygon.h:47
void setActive(bool active=true)
Definition: LightShape.h:80
Anchor
An anchor of a box.
Definition: Anchor.h:38
LightShapeVisibility
Light shape visibility.
Definition: LightShape.h:43
Definition: LightShape.h:45
General purpose math vector.
Definition: Vector.h:61
Definition: LightShape.h:44