2019-07-26 20:57:28 +02:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2016-12-07 20:03:54 +01:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_CCHART
|
|
|
|
#define INCLUDED_CCHART
|
|
|
|
|
2019-07-26 20:57:28 +02:00
|
|
|
#include "gui/GUI.h"
|
|
|
|
#include "gui/IGUITextOwner.h"
|
2016-12-07 20:03:54 +01:00
|
|
|
#include "maths/Vector2D.h"
|
2019-07-26 20:57:28 +02:00
|
|
|
|
2016-12-07 20:03:54 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
struct CChartData
|
|
|
|
{
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-10 02:04:17 +02:00
|
|
|
// Avoid copying the container.
|
|
|
|
NONCOPYABLE(CChartData);
|
|
|
|
MOVABLE(CChartData);
|
|
|
|
CChartData() = default;
|
|
|
|
|
2019-07-26 20:57:28 +02:00
|
|
|
CGUIColor m_Color;
|
2016-12-07 20:03:54 +01:00
|
|
|
std::vector<CVector2D> m_Points;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-04-11 14:27:21 +02:00
|
|
|
* Chart for a data visualization as lines or points
|
|
|
|
*
|
|
|
|
* @see IGUIObject
|
|
|
|
*/
|
2018-03-04 13:42:35 +01:00
|
|
|
class CChart : public IGUITextOwner
|
2016-12-07 20:03:54 +01:00
|
|
|
{
|
|
|
|
GUI_OBJECT(CChart)
|
|
|
|
|
|
|
|
public:
|
2019-08-21 12:12:33 +02:00
|
|
|
CChart(CGUI& pGUI);
|
2016-12-07 20:03:54 +01:00
|
|
|
virtual ~CChart();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
2017-04-11 14:27:21 +02:00
|
|
|
* @see IGUIObject#HandleMessage()
|
|
|
|
*/
|
2016-12-07 20:03:54 +01:00
|
|
|
virtual void HandleMessage(SGUIMessage& Message);
|
|
|
|
|
|
|
|
/**
|
2017-04-11 14:27:21 +02:00
|
|
|
* Draws the Chart
|
|
|
|
*/
|
2016-12-07 20:03:54 +01:00
|
|
|
virtual void Draw();
|
|
|
|
|
|
|
|
virtual CRect GetChartRect() const;
|
|
|
|
|
|
|
|
void UpdateSeries();
|
|
|
|
|
2018-03-04 13:42:35 +01:00
|
|
|
void SetupText();
|
|
|
|
|
2016-12-07 20:03:54 +01:00
|
|
|
std::vector<CChartData> m_Series;
|
2017-04-11 14:27:21 +02:00
|
|
|
|
2018-03-04 13:42:35 +01:00
|
|
|
CVector2D m_LeftBottom, m_RightTop;
|
|
|
|
|
|
|
|
CStrW m_FormatX, m_FormatY;
|
|
|
|
|
|
|
|
std::vector<CPos> m_TextPositions;
|
|
|
|
|
|
|
|
float m_AxisWidth;
|
|
|
|
|
|
|
|
bool m_EqualX, m_EqualY;
|
|
|
|
|
2017-04-11 14:27:21 +02:00
|
|
|
private:
|
|
|
|
/**
|
2018-03-04 13:42:35 +01:00
|
|
|
* Helper functions
|
2017-04-11 14:27:21 +02:00
|
|
|
*/
|
2019-07-26 20:57:28 +02:00
|
|
|
void DrawLine(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector<float>& vertices) const;
|
2018-03-04 13:42:35 +01:00
|
|
|
|
|
|
|
// Draws the triangle sequence so that the each next triangle has a common edge with the previous one.
|
|
|
|
// If we need to draw n triangles, we need only n + 2 points.
|
2019-07-26 20:57:28 +02:00
|
|
|
void DrawTriangleStrip(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector<float>& vertices) const;
|
2018-03-04 13:42:35 +01:00
|
|
|
|
|
|
|
// Represents axes as triangles and draws them with DrawTriangleStrip.
|
|
|
|
void DrawAxes(const CShaderProgramPtr& shader) const;
|
|
|
|
|
|
|
|
CSize AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone);
|
|
|
|
|
|
|
|
void UpdateBounds();
|
2016-12-07 20:03:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDED_CCHART
|