FifeGUI 0.2.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#include "fifechan/point.hpp"
9#include "fifechan/widget.hpp"
10
11namespace fcn
12{
13 class Graphics;
14
24 class FIFEGUI_API CurveGraph : public Widget
25 {
26 public:
29
31 explicit CurveGraph(PointVector data);
32
33 ~CurveGraph() override = default;
34
35 CurveGraph(CurveGraph const &) = delete;
36 CurveGraph& operator=(CurveGraph const &) = delete;
37 CurveGraph(CurveGraph&&) = delete;
38 CurveGraph& operator=(CurveGraph&&) = delete;
39
41 void setPointVector(PointVector const & data);
42
44 PointVector const & getPointVector() const;
45
47 void resetPointVector();
48
50 void setThickness(unsigned int thickness);
51
53 unsigned int getThickness() const;
54
56 void setAutomaticControlPoints(bool acp);
57
59 bool isAutomaticControlPoints() const;
60
66 void setOpaque(bool opaque);
67
71 bool isOpaque() const;
72
76 void draw(Graphics* graphics) override;
77
78 protected:
81 void update();
82
85 Point getBezierPoint(PointVector const & points, int elements, float t);
86
89 void addControlPoints(PointVector const & points, PointVector& newPoints);
90
92 bool m_opaque{false};
93
95 bool m_acp{true};
96
98 bool m_needUpdate{false};
99
101 unsigned int m_thickness{1};
102
104 PointVector m_data;
105
107 PointVector m_curveData;
108 };
109}; // namespace fcn
110
111#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.
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.
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:57
Represents a 2D coordinate (X, Y).
Definition point.hpp:29
Widget()
Constructor.
Definition widget.cpp:36