Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CChart.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * 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/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#ifndef INCLUDED_CCHART | #ifndef INCLUDED_CCHART | ||||
#define INCLUDED_CCHART | #define INCLUDED_CCHART | ||||
#include "GUI.h" | #include "GUI.h" | ||||
#include "IGUITextOwner.h" | |||||
#include "graphics/Color.h" | #include "graphics/Color.h" | ||||
#include "maths/Vector2D.h" | #include "maths/Vector2D.h" | ||||
#include <vector> | #include <vector> | ||||
struct CChartData | struct CChartData | ||||
{ | { | ||||
CColor m_Color; | CColor m_Color; | ||||
std::vector<CVector2D> m_Points; | std::vector<CVector2D> m_Points; | ||||
}; | }; | ||||
/** | /** | ||||
* Chart for a data visualization as lines or points | * Chart for a data visualization as lines or points | ||||
* | * | ||||
* @see IGUIObject | * @see IGUIObject | ||||
*/ | */ | ||||
class CChart : public IGUIObject | class CChart : public IGUITextOwner | ||||
{ | { | ||||
GUI_OBJECT(CChart) | GUI_OBJECT(CChart) | ||||
public: | public: | ||||
CChart(); | CChart(); | ||||
virtual ~CChart(); | virtual ~CChart(); | ||||
protected: | protected: | ||||
/** | /** | ||||
* @see IGUIObject#HandleMessage() | * @see IGUIObject#HandleMessage() | ||||
*/ | */ | ||||
virtual void HandleMessage(SGUIMessage& Message); | virtual void HandleMessage(SGUIMessage& Message); | ||||
/** | /** | ||||
* Draws the Chart | * Draws the Chart | ||||
*/ | */ | ||||
virtual void Draw(); | virtual void Draw(); | ||||
virtual CRect GetChartRect() const; | virtual CRect GetChartRect() const; | ||||
void UpdateSeries(); | void UpdateSeries(); | ||||
void SetupText(); | |||||
std::vector<CChartData> m_Series; | std::vector<CChartData> m_Series; | ||||
CVector2D m_LeftBottom, m_RightTop; | |||||
CStrW m_FormatX, m_FormatY; | |||||
std::vector<CPos> m_TextPositions; | |||||
float m_AxisWidth; | |||||
bool m_EqualX, m_EqualY; | |||||
private: | private: | ||||
/** | /** | ||||
* Helper function | * Helper functions | ||||
*/ | */ | ||||
void DrawLine(const CShaderProgramPtr& shader, const CColor& color, const std::vector<float>& vertices) const; | void DrawLine(const CShaderProgramPtr& shader, const CColor& color, const std::vector<float>& vertices) const; | ||||
s0600204: This function is only used to draw the axes lines, right? So why is it not part of the… | |||||
Not Done Inline ActionsBecause, as @elexis many time suggested to split it for the easy stack trace parsing. I agree, that comment would be useful. vladislavbelov: Because, as @elexis many time suggested to split it for the easy stack trace parsing.
I agree… | |||||
Not Done Inline ActionsI don't recall saying anything about this function in particular, but it's not bad to have it split IMO. elexis: I don't recall saying anything about this function in particular, but it's not bad to have it… | |||||
Not Done Inline ActionsThere was something in the CinemaManager. vladislavbelov: There was something in the `CinemaManager`. | |||||
// 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. | |||||
void DrawTriangleStrip(const CShaderProgramPtr& shader, const CColor& color, const std::vector<float>& vertices) const; | |||||
Not Done Inline ActionsAddFormattedValue s0600204: AddForma**tt**edValue | |||||
Not Done Inline ActionsTrue. vladislavbelov: True. | |||||
// 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(); | |||||
}; | }; | ||||
#endif // INCLUDED_CCHART | #endif // INCLUDED_CCHART |
Wildfire Games · Phabricator
This function is only used to draw the axes lines, right? So why is it not part of the DrawAxes function?
My point is that it is unclear from the function name what this is used for, and there's no accompanying comment to explain why a line-graph-chart would want or need to draw a strip of triangles. And as this private function is only called in one place in this class, then why not merge it? Neither function is particularly long.