Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/ObjectTypes/CChart.cpp
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | void CChart::DrawTriangleStrip(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector<float>& vertices) const | ||||
shader->AssertPointersBound(); | shader->AssertPointersBound(); | ||||
if (!g_Renderer.DoSkipSubmit()) | if (!g_Renderer.DoSkipSubmit()) | ||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size() / 3); | glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size() / 3); | ||||
} | } | ||||
void CChart::DrawAxes(const CShaderProgramPtr& shader) const | void CChart::DrawAxes(const CShaderProgramPtr& shader) const | ||||
{ | { | ||||
const float bz = GetBufferedZ(); | |||||
CRect rect = GetChartRect(); | CRect rect = GetChartRect(); | ||||
std::vector<float> vertices; | std::vector<float> vertices; | ||||
vertices.reserve(30); | vertices.reserve(30); | ||||
#define ADD(x, y) vertices.push_back(x); vertices.push_back(y); vertices.push_back(bz + 0.5f); | #define ADD(x, y) vertices.push_back(x); vertices.push_back(y); vertices.push_back(0.0f); | ||||
ADD(m_CachedActualSize.right, m_CachedActualSize.bottom); | ADD(m_CachedActualSize.right, m_CachedActualSize.bottom); | ||||
ADD(rect.right + m_AxisWidth, rect.bottom); | ADD(rect.right + m_AxisWidth, rect.bottom); | ||||
ADD(m_CachedActualSize.left, m_CachedActualSize.bottom); | ADD(m_CachedActualSize.left, m_CachedActualSize.bottom); | ||||
ADD(rect.left, rect.bottom); | ADD(rect.left, rect.bottom); | ||||
ADD(m_CachedActualSize.left, m_CachedActualSize.top); | ADD(m_CachedActualSize.left, m_CachedActualSize.top); | ||||
ADD(rect.left, rect.top - m_AxisWidth); | ADD(rect.left, rect.top - m_AxisWidth); | ||||
#undef ADD | #undef ADD | ||||
DrawTriangleStrip(shader, m_AxisColor, vertices); | DrawTriangleStrip(shader, m_AxisColor, vertices); | ||||
} | } | ||||
void CChart::Draw() | void CChart::Draw() | ||||
{ | { | ||||
PROFILE3("render chart"); | PROFILE3("render chart"); | ||||
if (m_Series.empty()) | if (m_Series.empty()) | ||||
return; | return; | ||||
const float bz = GetBufferedZ(); | |||||
CRect rect = GetChartRect(); | CRect rect = GetChartRect(); | ||||
const float width = rect.GetWidth(); | const float width = rect.GetWidth(); | ||||
const float height = rect.GetHeight(); | const float height = rect.GetHeight(); | ||||
// Setup the render state | // Setup the render state | ||||
CMatrix3D transform = GetDefaultGuiMatrix(); | CMatrix3D transform = GetDefaultGuiMatrix(); | ||||
CShaderDefines lineDefines; | CShaderDefines lineDefines; | ||||
CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid, g_Renderer.GetSystemShaderDefines(), lineDefines); | CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid, g_Renderer.GetSystemShaderDefines(), lineDefines); | ||||
Show All 9 Lines | for (const CChartData& data : m_Series) | ||||
std::vector<float> vertices; | std::vector<float> vertices; | ||||
for (const CVector2D& point : data.m_Points) | for (const CVector2D& point : data.m_Points) | ||||
{ | { | ||||
if (fabs(point.X) != std::numeric_limits<float>::infinity() && fabs(point.Y) != std::numeric_limits<float>::infinity()) | if (fabs(point.X) != std::numeric_limits<float>::infinity() && fabs(point.Y) != std::numeric_limits<float>::infinity()) | ||||
{ | { | ||||
vertices.push_back(rect.left + (point.X - m_LeftBottom.X) * scale.X); | vertices.push_back(rect.left + (point.X - m_LeftBottom.X) * scale.X); | ||||
vertices.push_back(rect.bottom - (point.Y - m_LeftBottom.Y) * scale.Y); | vertices.push_back(rect.bottom - (point.Y - m_LeftBottom.Y) * scale.Y); | ||||
vertices.push_back(bz + 0.5f); | vertices.push_back(0.0f); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
DrawLine(shader, data.m_Color, vertices); | DrawLine(shader, data.m_Color, vertices); | ||||
vertices.clear(); | vertices.clear(); | ||||
} | } | ||||
} | } | ||||
if (!vertices.empty()) | if (!vertices.empty()) | ||||
DrawLine(shader, data.m_Color, vertices); | DrawLine(shader, data.m_Color, vertices); | ||||
} | } | ||||
if (m_AxisWidth > 0) | if (m_AxisWidth > 0) | ||||
DrawAxes(shader); | DrawAxes(shader); | ||||
tech->EndPass(); | tech->EndPass(); | ||||
for (size_t i = 0; i < m_TextPositions.size(); ++i) | for (size_t i = 0; i < m_TextPositions.size(); ++i) | ||||
DrawText(i, CGUIColor(1.f, 1.f, 1.f, 1.f), m_TextPositions[i], bz + 0.5f); | DrawText(i, CGUIColor(1.f, 1.f, 1.f, 1.f), m_TextPositions[i]); | ||||
} | } | ||||
CRect CChart::GetChartRect() const | CRect CChart::GetChartRect() const | ||||
{ | { | ||||
return CRect( | return CRect( | ||||
m_CachedActualSize.TopLeft() + CVector2D(m_AxisWidth, m_AxisWidth), | m_CachedActualSize.TopLeft() + CVector2D(m_AxisWidth, m_AxisWidth), | ||||
m_CachedActualSize.BottomRight() - CVector2D(m_AxisWidth, m_AxisWidth) | m_CachedActualSize.BottomRight() - CVector2D(m_AxisWidth, m_AxisWidth) | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator