Pyrogenesis  trunk
CChart.h
Go to the documentation of this file.
1 /* Copyright (C) 2021 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_CCHART
19 #define INCLUDED_CCHART
20 
26 #include "maths/Size2D.h"
27 #include "maths/Vector2D.h"
28 
29 #include <vector>
30 
31 struct CChartData
32 {
33  // Avoid copying the container.
36  CChartData() = default;
37 
39  std::vector<CVector2D> m_Points;
40 };
41 
42 /**
43  * Chart for a data visualization as lines or points
44  */
45 class CChart : public IGUIObject, public IGUITextOwner
46 {
48 
49 public:
50  CChart(CGUI& pGUI);
51  virtual ~CChart();
52 
53 protected:
54  /**
55  * @see IGUIObject#UpdateCachedSize()
56  */
57  void UpdateCachedSize();
58 
59  /**
60  * @see IGUIObject#HandleMessage()
61  */
62  virtual void HandleMessage(SGUIMessage& Message);
63 
64  /**
65  * Draws the Chart
66  */
67  virtual void Draw(CCanvas2D& canvas);
68 
69  virtual CRect GetChartRect() const;
70 
71  void UpdateSeries();
72 
73  void SetupText();
74 
75  std::vector<CChartData> m_Series;
76 
77  CVector2D m_LeftBottom, m_RightTop;
78 
79  std::vector<CVector2D> m_TextPositions;
80 
81  bool m_EqualX, m_EqualY;
82 
83  // Settings
92 
93 private:
94  void DrawAxes(CCanvas2D& canvas) const;
95 
96  CSize2D AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone);
97 
98  void UpdateBounds();
99 };
100 
101 #endif // INCLUDED_CCHART
CGUISimpleSetting< CGUIColor > m_AxisColor
Definition: CChart.h:84
NONCOPYABLE(CChartData)
Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yel...
Definition: CGUIColor.h:29
void Draw(DrawCalls &Calls, CCanvas2D &canvas)
Definition: GUIRenderer.cpp:314
std::vector< CVector2D > m_Points
Definition: CChart.h:39
GUI object such as a button or an input-box.
Definition: IGUIObject.h:59
CGUISimpleSetting< CStrW > m_FormatX
Definition: CChart.h:88
The main object that represents a whole GUI page.
Definition: CGUI.h:60
Definition: Size2D.h:24
bool m_EqualY
Definition: CChart.h:81
MOVABLE(CChartData)
Framework for handling Output text.
Definition: IGUITextOwner.h:52
CGUISimpleSetting< CGUIList > m_SeriesColor
Definition: CChart.h:90
CGUISimpleSetting< CGUISeries > m_SeriesSetting
Definition: CChart.h:91
Definition: Canvas2D.h:35
std::vector< CChartData > m_Series
Definition: CChart.h:75
std::vector< CVector2D > m_TextPositions
Definition: CChart.h:79
Definition: Vector2D.h:31
CVector2D m_RightTop
Definition: CChart.h:77
Chart for a data visualization as lines or points.
Definition: CChart.h:45
CGUISimpleSetting< float > m_AxisWidth
Definition: CChart.h:85
CGUISimpleSetting< float > m_BufferZone
Definition: CChart.h:86
CGUIColor m_Color
Definition: CChart.h:38
Definition: CChart.h:31
#define GUI_OBJECT(obj)
Definition: IGUIObject.h:50
CGUISimpleSetting< CStrW > m_FormatY
Definition: CChart.h:89
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: SGUIMessage.h:67
CGUISimpleSetting< CStrW > m_Font
Definition: CChart.h:87
CChartData()=default
Rectangle class used for screen rectangles.
Definition: Rect.h:30