FifeGUI 0.3.0
A C++ GUI library designed for games.
curvegraph.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_WIDGETS_CURVEGRAPH_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_CURVEGRAPH_HPP_
7
8// Project headers (subdirs before local)
9#include "fifechan/point.hpp"
10#include "fifechan/widget.hpp"
11
12namespace fcn
13{
14 class Graphics;
15
25 class FIFEGUI_API CurveGraph : public Widget
26 {
27 public:
30
36 explicit CurveGraph(PointVector data);
37
38 ~CurveGraph() override = default;
39
40 CurveGraph(CurveGraph const &) = delete;
41 CurveGraph& operator=(CurveGraph const &) = delete;
42 CurveGraph(CurveGraph&&) = delete;
43 CurveGraph& operator=(CurveGraph&&) = delete;
44
50 void setPointVector(PointVector const & data);
51
53 PointVector const & getPointVector() const;
54
56 void resetPointVector();
57
63 void setThickness(unsigned int thickness);
64
66 unsigned int getThickness() const;
67
73 void setAutomaticControlPoints(bool acp);
74
76 bool isAutomaticControlPoints() const;
77
83 void setOpaque(bool opaque);
84
88 bool isOpaque() const;
89
95 void draw(Graphics* graphics) override;
96
97 protected:
101 void update();
102
110 static Point getBezierPoint(PointVector const & points, int elements, float t);
111
118 static void addControlPoints(PointVector const & points, PointVector& newPoints);
119
121 bool m_opaque{false};
122
124 bool m_acp{true};
125
127 bool m_needUpdate{false};
128
130 unsigned int m_thickness{1};
131
134
137 };
138}; // namespace fcn
139
140#endif // INCLUDE_FIFECHAN_WIDGETS_CURVEGRAPH_HPP_
unsigned int m_thickness
Stroke thickness in pixels.
unsigned int getThickness() const
Get stroke thickness in pixels.
PointVector m_data
Raw input point data.
bool m_opaque
True if the curve is drawn opaque.
bool m_acp
Whether automatic control points are enabled.
PointVector const & getPointVector() const
Get the current point vector.
void setOpaque(bool opaque)
Sets the opacity of the graph.
void setThickness(unsigned int thickness)
Set stroke thickness in pixels.
static Point getBezierPoint(PointVector const &points, int elements, float t)
Helper that returns an interpolated Point.
void setAutomaticControlPoints(bool acp)
Enable/disable automatic computation of bezier control points.
bool m_needUpdate
Internal flag marking that the precalculated curve data needs update.
bool isOpaque() const
bool isAutomaticControlPoints() const
Return whether automatic control points are enabled.
static void addControlPoints(PointVector const &points, PointVector &newPoints)
Helper that adds the control points for bezier curves.
CurveGraph()
Default constructor.
void draw(Graphics *graphics) override
Draws this widget.
void setPointVector(PointVector const &data)
Set the raw point vector used to draw the curve.
void update()
Precalculate bezier curve.
void resetPointVector()
Reset the stored data to an empty vector.
PointVector m_curveData
Precalculated curve points (bezier/interpolated).
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
Represents a 2D coordinate (X, Y).
Definition point.hpp:34
Widget()
Constructor.
Definition widget.cpp:52
Used replacement tokens by configure_file():
std::vector< Point > PointVector
A list of points.
Definition point.hpp:331