Gamedev Framework (gf) 0.21.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
32namespace gf {
33#ifndef DOXYGEN_SHOULD_SKIP_THIS
34inline namespace v1 {
35#endif
36
45 Opaque,
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
75
77
79
80 void setActive(bool active = true) {
81 m_active = active;
82 }
83
84 bool isActive() const {
85 return m_active;
86 }
87
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
Light shape.
Definition: LightShape.h:54
void draw(RenderTarget &target, const RenderStates &states) override
Draw the object to a render target.
void setActive(bool active=true)
Definition: LightShape.h:80
Vector2f getPrevPoint(std::size_t index) const
Color4f getColor() const
bool isActive() const
Definition: LightShape.h:84
std::size_t getPointCount() const
RectF getLocalBounds() const
Vector2f getPoint(std::size_t index) const
Vector2f getNextPoint(std::size_t index) const
LightShape(const RectF &rect, LightShapeVisibility visibility=LightShapeVisibility::Apparent)
LightShapeVisibility getVisibility() const
void setColor(const Color4f &color)
LightShape(const Polygon &polygon, LightShapeVisibility visibility=LightShapeVisibility::Apparent)
LightShape(Polygon &&polygon, LightShapeVisibility visibility=LightShapeVisibility::Apparent)
LightShape(const CircF &circ, LightShapeVisibility visibility=LightShapeVisibility::Apparent)
void setVisibility(LightShapeVisibility visibility)
void setAnchor(Anchor anchor)
A convex polygon.
Definition: Polygon.h:47
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:102
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
A set of primitives.
Definition: VertexArray.h:65
Anchor
An anchor of a box.
Definition: Anchor.h:38
LightShapeVisibility
Light shape visibility.
Definition: LightShape.h:43
The namespace for gf classes.
Definition: Action.h:35
Utility class for manipulating circles.
Definition: Circ.h:61
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
A 4D vector.
Definition: Vector.h:852