Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Curve.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 #ifndef GF_CURVE_H
22 #define GF_CURVE_H
23 
24 #include <cstddef>
25 
26 #include "Portability.h"
27 #include "Rect.h"
28 #include "Transformable.h"
29 #include "Vector.h"
30 #include "VertexArray.h"
31 #include "VertexBuffer.h"
32 
33 namespace gf {
34 #ifndef DOXYGEN_SHOULD_SKIP_THIS
35 inline namespace v1 {
36 #endif
37 
52  class GF_API Curve : public Transformable {
53  public:
57  enum Type {
60  };
61 
65  Curve();
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 
207  RectF getLocalBounds() const;
208 
219  void setAnchor(Anchor anchor);
220 
229  VertexBuffer commitGeometry() const;
230 
239  VertexBuffer commitOutlineGeometry() const;
240 
241  virtual void draw(RenderTarget& target, const RenderStates& states) override;
242 
243  protected:
251  void updateGeometry();
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
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
An outlined curve.
Definition: Curve.h:59
A set of primitives.
Definition: VertexArray.h:65
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:66
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
Data in the graphics memory.
Definition: VertexBuffer.h:70
A curve is a one dimension object.
Definition: Curve.h:52
A simple curve with no outline.
Definition: Curve.h:58
The namespace for gf classes.
Definition: Action.h:35
const Color4f & getOutlineColor() const
Get the outline color of the curve.
Definition: Curve.h:145
const Color4f & getColor() const
Get the fill color of the curve.
Definition: Curve.h:107
Type getType() const noexcept
Return the type of the curve.
Definition: Curve.h:81
Anchor
An anchor of a box.
Definition: Anchor.h:38
float getWidth() const
Get the width of the curve.
Definition: Curve.h:123
Type
The type of the curve.
Definition: Curve.h:57
float getOutlineThickness() const
Get the outline thickness of the curve.
Definition: Curve.h:167