Code cleanup

This commit is contained in:
spx 2012-12-27 16:47:44 +09:00
parent 47e130a6ff
commit 5576f7d5a0
2 changed files with 54 additions and 60 deletions

View File

@ -438,24 +438,30 @@ bool CMeterHistogram::Draw(Graphics& graphics)
int endValue = -1; //(should be 0, but need to simulate <=) int endValue = -1; //(should be 0, but need to simulate <=)
// GraphStart=Left, GraphOrientation=Vertical // GraphStart=Left, GraphOrientation=Vertical
if (m_GraphStartLeft && !m_GraphHorizontalOrientation) if (!m_GraphHorizontalOrientation)
{
if (m_GraphStartLeft)
{ {
startValue = m_W - 1; startValue = m_W - 1;
endValueLHS = &endValue; endValueLHS = &endValue;
endValueRHS = &i; endValueRHS = &i;
step = -1; step = -1;
} }
else if (m_GraphHorizontalOrientation && !m_Flip) }
else
{
if (!m_Flip)
{ {
endValueRHS = &m_H; endValueRHS = &m_H;
} }
else if (m_GraphHorizontalOrientation && m_Flip) else
{ {
startValue = m_H - 1; startValue = m_H - 1;
endValueLHS = &endValue; endValueLHS = &endValue;
endValueRHS = &i; endValueRHS = &i;
step = -1; step = -1;
} }
}
// Horizontal or Vertical graph // Horizontal or Vertical graph
if (m_GraphHorizontalOrientation) if (m_GraphHorizontalOrientation)

View File

@ -207,7 +207,7 @@ bool CMeterLine::Update()
} }
++m_CurrentPos; ++m_CurrentPos;
if (m_CurrentPos >= maxSize) m_CurrentPos = 0; m_CurrentPos %= maxSize;
} }
return true; return true;
} }
@ -230,13 +230,11 @@ bool CMeterLine::Draw(Graphics& graphics)
if (m_Autoscale) if (m_Autoscale)
{ {
double newValue = 0; double newValue = 0;
std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
counter = 0; counter = 0;
for (; i != m_AllValues.end(); ++i) for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
{ {
double scale = m_ScaleValues[counter]; double scale = m_ScaleValues[counter];
std::vector<double>::const_iterator j = (*i).begin(); for (auto j = (*i).cbegin(); j != (*i).cend(); ++j)
for (; j != (*i).end(); ++j)
{ {
double val = (*j) * scale; double val = (*j) * scale;
newValue = max(newValue, val); newValue = max(newValue, val);
@ -260,17 +258,11 @@ bool CMeterLine::Draw(Graphics& graphics)
} }
else else
{ {
if (!m_Measures.empty()) for (auto i = m_Measures.cbegin(); i != m_Measures.cend(); ++i)
{
maxValue = m_Measures[0]->GetMaxValue();
std::vector<CMeasure*>::const_iterator i = m_Measures.begin();
for (; i != m_Measures.end(); ++i)
{ {
double val = (*i)->GetMaxValue(); double val = (*i)->GetMaxValue();
maxValue = max(maxValue, val); maxValue = max(maxValue, val);
} }
}
if (maxValue == 0.0) if (maxValue == 0.0)
{ {
@ -314,8 +306,7 @@ bool CMeterLine::Draw(Graphics& graphics)
{ {
const REAL W = m_W - 1.0f; const REAL W = m_W - 1.0f;
counter = 0; counter = 0;
std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin(); for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
for (; i != m_AllValues.end(); ++i)
{ {
// Draw a line // Draw a line
REAL X, oldX; REAL X, oldX;
@ -324,10 +315,15 @@ bool CMeterLine::Draw(Graphics& graphics)
int pos = m_CurrentPos; int pos = m_CurrentPos;
oldX = (REAL)((*i)[pos] * scale); auto calcX = [&](REAL& _x)
oldX = min(oldX, W); {
oldX = max(oldX, 0.0f); _x = (REAL)((*i)[pos] * scale);
oldX = x + (m_GraphStartLeft ? oldX : W - oldX); _x = min(_x, W);
_x = max(_x, 0.0f);
_x = x + (m_GraphStartLeft ? _x : W - _x);
};
calcX(oldX);
// Cache all lines // Cache all lines
GraphicsPath path; GraphicsPath path;
@ -337,12 +333,9 @@ bool CMeterLine::Draw(Graphics& graphics)
for (int j = y + 1, R = y + m_H; j < R; ++j) for (int j = y + 1, R = y + m_H; j < R; ++j)
{ {
++pos; ++pos;
if (pos >= m_H) pos = 0; pos %= m_H;
X = (REAL)((*i)[pos] * scale); calcX(X);
X = min(X, W);
X = max(X, 0.0f);
X = x + (m_GraphStartLeft ? X : W - X);
path.AddLine(oldX, (REAL)(j - 1), X, (REAL)j); path.AddLine(oldX, (REAL)(j - 1), X, (REAL)j);
@ -354,12 +347,9 @@ bool CMeterLine::Draw(Graphics& graphics)
for (int j = y + m_H, R = y + 1; j > R; --j) for (int j = y + m_H, R = y + 1; j > R; --j)
{ {
++pos; ++pos;
if (pos >= m_H) pos = 0; pos %= m_H;
X = (REAL)((*i)[pos] * scale); calcX(X);
X = min(X, W);
X = max(X, 0.0f);
X = x + (m_GraphStartLeft ? X : W - X);
path.AddLine(oldX, (REAL)(j - 1), X, (REAL)(j - 2)); path.AddLine(oldX, (REAL)(j - 1), X, (REAL)(j - 2));
@ -379,8 +369,7 @@ bool CMeterLine::Draw(Graphics& graphics)
{ {
const REAL H = m_H - 1.0f; const REAL H = m_H - 1.0f;
counter = 0; counter = 0;
std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin(); for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
for (; i != m_AllValues.end(); ++i)
{ {
// Draw a line // Draw a line
REAL Y, oldY; REAL Y, oldY;
@ -389,10 +378,15 @@ bool CMeterLine::Draw(Graphics& graphics)
int pos = m_CurrentPos; int pos = m_CurrentPos;
oldY = (REAL)((*i)[pos] * scale); auto calcY = [&](REAL& _y)
oldY = min(oldY, H); {
oldY = max(oldY, 0.0f); _y = (REAL)((*i)[pos] * scale);
oldY = y + (m_Flip ? oldY : H - oldY); _y = min(_y, H);
_y = max(_y, 0.0f);
_y = y + (m_Flip ? _y : H - _y);
};
calcY(oldY);
// Cache all lines // Cache all lines
GraphicsPath path; GraphicsPath path;
@ -402,12 +396,9 @@ bool CMeterLine::Draw(Graphics& graphics)
for (int j = x + 1, R = x + m_W; j < R; ++j) for (int j = x + 1, R = x + m_W; j < R; ++j)
{ {
++pos; ++pos;
if (pos >= m_W) pos = 0; pos %= m_W;
Y = (REAL)((*i)[pos] * scale); calcY(Y);
Y = min(Y, H);
Y = max(Y, 0.0f);
Y = y + (m_Flip ? Y : H - Y);
path.AddLine((REAL)(j - 1), oldY, (REAL)j, Y); path.AddLine((REAL)(j - 1), oldY, (REAL)j, Y);
@ -419,12 +410,9 @@ bool CMeterLine::Draw(Graphics& graphics)
for (int j = x + m_W, R = x + 1; j > R; --j) for (int j = x + m_W, R = x + 1; j > R; --j)
{ {
++pos; ++pos;
if (pos >= m_W) pos = 0; pos %= m_W;
Y = (REAL)((*i)[pos] * scale); calcY(Y);
Y = min(Y, H);
Y = max(Y, 0.0f);
Y = y + (m_Flip ? Y : H - Y);
path.AddLine((REAL)(j - 1), oldY, (REAL)(j - 2), Y); path.AddLine((REAL)(j - 1), oldY, (REAL)(j - 2), Y);