Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Curve.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 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_CURVE_H
22#define GF_CURVE_H
23
24#include <cstddef>
25
26#include "GraphicsApi.h"
27#include "Rect.h"
28#include "Transformable.h"
29#include "Vector.h"
30#include "VertexArray.h"
31#include "VertexBuffer.h"
32
33namespace gf {
34#ifndef DOXYGEN_SHOULD_SKIP_THIS
35inline namespace v1 {
36#endif
37
52 class GF_GRAPHICS_API Curve : public Transformable {
53 public:
57 enum Type {
60 };
61
66
74 void setType(Type type);
75
81 Type getType() const noexcept {
82 return m_type;
83 }
84
98 void setColor(const Color4f& color);
99
107 const Color4f& getColor() const {
108 return m_color;
109 }
110
116 void setWidth(float width);
117
123 float getWidth() const {
124 return m_width;
125 }
126
136 void setOutlineColor(const Color4f& color);
137
145 const Color4f& getOutlineColor() const {
146 return m_outlineColor;
147 }
148
158 void setOutlineThickness(float thickness);
159
167 float getOutlineThickness() const {
168 return m_outlineThickness;
169 }
170
177 virtual std::size_t getPointCount() const = 0;
178
194 virtual Vector2f getPoint(std::size_t index) const = 0;
195
208
219 void setAnchor(Anchor anchor);
220
230
240
241 virtual void draw(RenderTarget& target, const RenderStates& states) override;
242
243 protected:
252
262 void setClosed(bool closed = true);
263
264 private:
265 void updateColors();
266 void updateOutline();
267 void updateOutlineColors();
268
269 void computeVertices(VertexArray& vertices, float halfWidth);
270 private:
271 Type m_type;
272 bool m_closed;
273
274 Color4f m_color;
275 float m_width;
276 VertexArray m_vertices;
277 RectF m_bounds;
278
279 Color4f m_outlineColor;
280 float m_outlineThickness;
281 VertexArray m_outlineVertices;
282 };
283
284#ifndef DOXYGEN_SHOULD_SKIP_THIS
285}
286#endif
287}
288
289#endif // GF_CURVE_H
A curve is a one dimension object.
Definition: Curve.h:52
VertexBuffer commitGeometry() const
Create a buffer with the current geometry.
virtual void draw(RenderTarget &target, const RenderStates &states) override
Draw the object to a render target.
const Color4f & getColor() const
Get the fill color of the curve.
Definition: Curve.h:107
Type
The type of the curve.
Definition: Curve.h:57
@ Simple
A simple curve with no outline.
Definition: Curve.h:58
@ Outlined
An outlined curve.
Definition: Curve.h:59
void updateGeometry()
Recompute the internal geometry of the curve.
RectF getLocalBounds() const
Get the local bounding rectangle of the entity.
void setColor(const Color4f &color)
Set the fill color of the curve.
void setWidth(float width)
Set the width of the curve.
Curve()
Default constructor.
float getOutlineThickness() const
Get the outline thickness of the curve.
Definition: Curve.h:167
const Color4f & getOutlineColor() const
Get the outline color of the curve.
Definition: Curve.h:145
float getWidth() const
Get the width of the curve.
Definition: Curve.h:123
virtual Vector2f getPoint(std::size_t index) const =0
Get a point of the curve.
VertexBuffer commitOutlineGeometry() const
Create a buffer with the current outline geometry.
Type getType() const noexcept
Return the type of the curve.
Definition: Curve.h:81
void setClosed(bool closed=true)
Set the curve closed.
void setOutlineThickness(float thickness)
Set the thickness of the curve's outline.
void setOutlineColor(const Color4f &color)
Set the outline color of the curve.
virtual std::size_t getPointCount() const =0
Get the total number of points of the curve.
void setAnchor(Anchor anchor)
Set the anchor origin of the entity.
void setType(Type type)
Set the type of the curve.
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
Data in the graphics memory.
Definition: VertexBuffer.h:81
Anchor
An anchor of a box.
Definition: Anchor.h:38
The namespace for gf classes.
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
A 4D vector.
Definition: Vector.h:852