1 /* Copyright (C) 2018 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.h" 22 #include "IGUITextOwner.h" 23 #include "graphics/Color.h" 24 #include "maths/Vector2D.h" 25 #include <vector> 26 27 28 struct CChartData 29 { 30 CColor m_Color; 31 std::vector<CVector2D> m_Points; 32 }; 33 34 /** 35 * Chart for a data visualization as lines or points 36 * 37 * @see IGUIObject 38 */ 39 class CChart : public IGUITextOwner 40 { 41 GUI_OBJECT(CChart) 42 43 public: 44 CChart(); 45 virtual ~CChart(); 46 47 protected: 48 /** 49 * @see IGUIObject#HandleMessage() 50 */ 51 virtual void HandleMessage(SGUIMessage& Message); 52 53 /** 54 * Draws the Chart 55 */ 56 virtual void Draw(); 57 58 virtual CRect GetChartRect() const; 59 60 void UpdateSeries(); 61 62 void SetupText(); 63 64 std::vector<CChartData> m_Series; 65 66 CVector2D m_LeftBottom, m_RightTop; 67 68 CStrW m_FormatX, m_FormatY; 69 70 std::vector<CPos> m_TextPositions; 71 72 float m_AxisWidth; 73 74 bool m_EqualX, m_EqualY; 75 76 private: 77 /** 78 * Helper functions 79 */ 80 void DrawLine(const CShaderProgramPtr& shader, const CColor& color, const std::vector<float>& vertices) const; 81 82 // Draws the triangle sequence so that the each next triangle has a common edge with the previous one. 83 // If we need to draw n triangles, we need only n + 2 points. 84 void DrawTriangleStrip(const CShaderProgramPtr& shader, const CColor& color, const std::vector<float>& vertices) const; 85 86 // Represents axes as triangles and draws them with DrawTriangleStrip. 87 void DrawAxes(const CShaderProgramPtr& shader) const; 88 89 CSize AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone); 90 91 void UpdateBounds(); 92 }; 93 94 #endif // INCLUDED_CCHART 95