Line data Source code
1 : /* Copyright (C) 2026 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 : 21 : #include "gui/CGUISetting.h" 22 : #include "gui/ObjectBases/IGUIObject.h" 23 : #include "gui/ObjectBases/IGUITextOwner.h" 24 : #include "gui/SettingTypes/CGUIColor.h" 25 : #include "gui/SettingTypes/CGUIList.h" 26 : #include "gui/SettingTypes/CGUISeries.h" 27 : #include "lib/code_annotation.h" 28 : #include "maths/Vector2D.h" 29 : #include "ps/CStr.h" 30 : 31 : #include <vector> 32 : 33 : class CCanvas2D; 34 : class CGUI; 35 : class CRect; 36 : class CSize2D; 37 : 38 0 : struct CChartData 39 : { 40 : // Avoid copying the container. 41 : NONCOPYABLE(CChartData); 42 0 : MOVABLE(CChartData); 43 0 : CChartData() = default; 44 : 45 : CGUIColor m_Color; 46 : std::vector<CVector2D> m_Points; 47 : }; 48 : 49 : /** 50 : * Chart for a data visualization as lines or points 51 : */ 52 : class CChart : public IGUIObject, public IGUITextOwner 53 : { 54 0 : GUI_OBJECT(CChart) 55 : 56 : public: 57 : CChart(CGUI& pGUI); 58 : 59 : protected: 60 : /** 61 : * @see IGUIObject#HandleSizeChanged() 62 : */ 63 : void HandleSizeChanged(); 64 : 65 : /** 66 : * @see IGUIObject#HandleMessage() 67 : */ 68 : virtual void HandleMessage(SGUIMessage& Message); 69 : 70 : /** 71 : * Draws the Chart 72 : */ 73 : virtual void Draw(CCanvas2D& canvas); 74 : 75 : virtual CRect GetChartRect() const; 76 : 77 : void UpdateSeries(); 78 : 79 : void SetupText(); 80 : 81 : std::vector<CChartData> m_Series; 82 : 83 : CVector2D m_LeftBottom, m_RightTop; 84 : 85 : std::vector<CVector2D> m_TextPositions; 86 : 87 : bool m_EqualX, m_EqualY; 88 : 89 : // Settings 90 : CGUISimpleSetting<CGUIColor> m_AxisColor; 91 : CGUISimpleSetting<float> m_AxisWidth; 92 : CGUISimpleSetting<float> m_BufferZone; 93 : CGUISimpleSetting<CStrW> m_Font; 94 : CGUISimpleSetting<CStrW> m_FormatX; 95 : CGUISimpleSetting<CStrW> m_FormatY; 96 : CGUISimpleSetting<CGUIList> m_SeriesColor; 97 : CGUISimpleSetting<CGUISeries> m_SeriesSetting; 98 : 99 : private: 100 : void DrawAxes(CCanvas2D& canvas) const; 101 : 102 : CSize2D AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone); 103 : 104 : void UpdateBounds(); 105 : }; 106 : 107 : #endif // INCLUDED_CCHART