mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Added GraphOrientation and GraphStart to Line and Histogram meters
This commit is contained in:
parent
62d60cba90
commit
5ac6f94f3b
@ -54,7 +54,9 @@ CMeterHistogram::CMeterHistogram(CMeterWindow* meterWindow, const WCHAR* name) :
|
|||||||
m_MinPrimaryValue(),
|
m_MinPrimaryValue(),
|
||||||
m_MaxSecondaryValue(1.0),
|
m_MaxSecondaryValue(1.0),
|
||||||
m_MinSecondaryValue(),
|
m_MinSecondaryValue(),
|
||||||
m_WidthChanged(true)
|
m_SizeChanged(true),
|
||||||
|
m_GraphStartLeft(false),
|
||||||
|
m_GraphHorizontalOrientation(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,15 +114,16 @@ void CMeterHistogram::Initialize()
|
|||||||
if (m_PrimaryImage.IsLoaded())
|
if (m_PrimaryImage.IsLoaded())
|
||||||
{
|
{
|
||||||
int oldW = m_W;
|
int oldW = m_W;
|
||||||
|
int oldH = m_H;
|
||||||
|
|
||||||
Bitmap* bitmap = m_PrimaryImage.GetImage();
|
Bitmap* bitmap = m_PrimaryImage.GetImage();
|
||||||
|
|
||||||
m_W = bitmap->GetWidth();
|
m_W = bitmap->GetWidth();
|
||||||
m_H = bitmap->GetHeight();
|
m_H = bitmap->GetHeight();
|
||||||
|
|
||||||
if (oldW != m_W)
|
if (oldW != m_W || oldH != m_H)
|
||||||
{
|
{
|
||||||
m_WidthChanged = true;
|
m_SizeChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,25 +157,24 @@ void CMeterHistogram::Initialize()
|
|||||||
{
|
{
|
||||||
DisposeBuffer();
|
DisposeBuffer();
|
||||||
|
|
||||||
m_WidthChanged = false;
|
m_SizeChanged = false;
|
||||||
}
|
}
|
||||||
else if (m_WidthChanged)
|
else if (m_SizeChanged)
|
||||||
{
|
{
|
||||||
DisposeBuffer();
|
DisposeBuffer();
|
||||||
|
|
||||||
// Create buffers for values
|
// Create buffers for values
|
||||||
if (m_W > 0)
|
if (m_W > 0 || m_H > 0)
|
||||||
{
|
{
|
||||||
m_PrimaryValues = new double[m_W];
|
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
|
||||||
memset(m_PrimaryValues, 0, sizeof(double) * m_W);
|
m_PrimaryValues = new double[maxSize]();
|
||||||
if (m_SecondaryMeasure)
|
if (m_SecondaryMeasure)
|
||||||
{
|
{
|
||||||
m_SecondaryValues = new double[m_W];
|
m_SecondaryValues = new double[maxSize]();
|
||||||
memset(m_SecondaryValues, 0, sizeof(double) * m_W);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_WidthChanged = false;
|
m_SizeChanged = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,9 +253,9 @@ void CMeterHistogram::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
|||||||
{
|
{
|
||||||
if (m_PrimaryImageName.empty())
|
if (m_PrimaryImageName.empty())
|
||||||
{
|
{
|
||||||
if (oldW != m_W)
|
if (oldW != m_W || oldH != m_H)
|
||||||
{
|
{
|
||||||
m_WidthChanged = true;
|
m_SizeChanged = true;
|
||||||
Initialize(); // Reload the image
|
Initialize(); // Reload the image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,6 +280,72 @@ void CMeterHistogram::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const WCHAR* graph = parser.ReadString(section, L"GraphStart", L"RIGHT").c_str();
|
||||||
|
if (_wcsicmp(graph, L"RIGHT") == 0)
|
||||||
|
{
|
||||||
|
m_GraphStartLeft = false;
|
||||||
|
}
|
||||||
|
else if (_wcsicmp(graph, L"LEFT") == 0)
|
||||||
|
{
|
||||||
|
m_GraphStartLeft = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogWithArgs(LOG_ERROR, L"GraphStart=%s is not valid in [%s]", graph, m_Name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
graph = parser.ReadString(section, L"GraphOrientation", L"VERTICAL").c_str();
|
||||||
|
if (_wcsicmp(graph, L"VERTICAL") == 0)
|
||||||
|
{
|
||||||
|
// Restart graph
|
||||||
|
if (m_GraphHorizontalOrientation)
|
||||||
|
{
|
||||||
|
m_GraphHorizontalOrientation = false;
|
||||||
|
DisposeBuffer();
|
||||||
|
|
||||||
|
// Create buffers for values
|
||||||
|
if (m_W > 0)
|
||||||
|
{
|
||||||
|
m_PrimaryValues = new double[m_W]();
|
||||||
|
if (m_SecondaryMeasure)
|
||||||
|
{
|
||||||
|
m_SecondaryValues = new double[m_W]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_GraphHorizontalOrientation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_wcsicmp(graph, L"HORIZONTAL") == 0)
|
||||||
|
{
|
||||||
|
// Restart graph
|
||||||
|
if (!m_GraphHorizontalOrientation)
|
||||||
|
{
|
||||||
|
m_GraphHorizontalOrientation = true;
|
||||||
|
DisposeBuffer();
|
||||||
|
|
||||||
|
// Create buffers for values
|
||||||
|
if (m_H > 0)
|
||||||
|
{
|
||||||
|
m_PrimaryValues = new double[m_H]();
|
||||||
|
if (m_SecondaryMeasure)
|
||||||
|
{
|
||||||
|
m_SecondaryValues = new double[m_H]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_GraphHorizontalOrientation = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogWithArgs(LOG_ERROR, L"GraphOrientation=%s is not valid in [%s]", graph, m_Name.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -297,7 +365,8 @@ bool CMeterHistogram::Update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
++m_MeterPos;
|
++m_MeterPos;
|
||||||
m_MeterPos %= m_W;
|
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
|
||||||
|
m_MeterPos %= maxSize;
|
||||||
|
|
||||||
m_MaxPrimaryValue = m_Measure->GetMaxValue();
|
m_MaxPrimaryValue = m_Measure->GetMaxValue();
|
||||||
m_MinPrimaryValue = m_Measure->GetMinValue();
|
m_MinPrimaryValue = m_Measure->GetMinValue();
|
||||||
@ -314,7 +383,7 @@ bool CMeterHistogram::Update()
|
|||||||
// Go through all values and find the max
|
// Go through all values and find the max
|
||||||
|
|
||||||
double newValue = 0.0;
|
double newValue = 0.0;
|
||||||
for (int i = 0; i < m_W; ++i)
|
for (int i = 0; i < maxSize; ++i)
|
||||||
{
|
{
|
||||||
newValue = max(newValue, m_PrimaryValues[i]);
|
newValue = max(newValue, m_PrimaryValues[i]);
|
||||||
}
|
}
|
||||||
@ -335,7 +404,7 @@ bool CMeterHistogram::Update()
|
|||||||
|
|
||||||
if (m_SecondaryMeasure && m_SecondaryValues)
|
if (m_SecondaryMeasure && m_SecondaryValues)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_W; ++i)
|
for (int i = 0; i < maxSize; ++i)
|
||||||
{
|
{
|
||||||
newValue = max(newValue, m_SecondaryValues[i]);
|
newValue = max(newValue, m_SecondaryValues[i]);
|
||||||
}
|
}
|
||||||
@ -381,7 +450,100 @@ bool CMeterHistogram::Draw(Graphics& graphics)
|
|||||||
int x = GetX();
|
int x = GetX();
|
||||||
int y = GetY();
|
int y = GetY();
|
||||||
|
|
||||||
for (int i = 0; i < m_W; ++i)
|
// Default values (GraphStart=Right, GraphOrientation=Vertical)
|
||||||
|
int i;
|
||||||
|
int startValue = 0;
|
||||||
|
int* endValueLHS = &i;
|
||||||
|
int* endValueRHS = &m_W;
|
||||||
|
int step = 1;
|
||||||
|
int endValue = -1; //(should be 0, but need to simulate <=)
|
||||||
|
|
||||||
|
// GraphStart=Left, GraphOrientation=Vertical
|
||||||
|
if (m_GraphStartLeft && !m_GraphHorizontalOrientation)
|
||||||
|
{
|
||||||
|
startValue = m_W - 1;
|
||||||
|
endValueLHS = &endValue;
|
||||||
|
endValueRHS = &i;
|
||||||
|
step = -1;
|
||||||
|
}
|
||||||
|
else if (m_GraphHorizontalOrientation && !m_Flip)
|
||||||
|
{
|
||||||
|
endValueRHS = &m_H;
|
||||||
|
}
|
||||||
|
else if (m_GraphHorizontalOrientation && m_Flip)
|
||||||
|
{
|
||||||
|
startValue = m_H - 1;
|
||||||
|
endValueLHS = &endValue;
|
||||||
|
endValueRHS = &i;
|
||||||
|
step = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Horizontal or Vertical graph
|
||||||
|
if (m_GraphHorizontalOrientation)
|
||||||
|
{
|
||||||
|
for (i = startValue; *endValueLHS < *endValueRHS; i += step)
|
||||||
|
{
|
||||||
|
double value = (m_MaxPrimaryValue == 0.0) ?
|
||||||
|
0.0
|
||||||
|
: m_PrimaryValues[(i + (m_MeterPos % m_H)) % m_H] / m_MaxPrimaryValue;
|
||||||
|
value -= m_MinPrimaryValue;
|
||||||
|
int primaryBarHeight = (int)(m_W * value);
|
||||||
|
primaryBarHeight = min(m_W, primaryBarHeight);
|
||||||
|
primaryBarHeight = max(0, primaryBarHeight);
|
||||||
|
|
||||||
|
if (m_SecondaryMeasure)
|
||||||
|
{
|
||||||
|
value = (m_MaxSecondaryValue == 0.0) ?
|
||||||
|
0.0
|
||||||
|
: m_SecondaryValues[(i + m_MeterPos) % m_H] / m_MaxSecondaryValue;
|
||||||
|
value -= m_MinSecondaryValue;
|
||||||
|
int secondaryBarHeight = (int)(m_W * value);
|
||||||
|
secondaryBarHeight = min(m_W, secondaryBarHeight);
|
||||||
|
secondaryBarHeight = max(0, secondaryBarHeight);
|
||||||
|
|
||||||
|
// Check which measured value is higher
|
||||||
|
int bothBarHeight = min(primaryBarHeight, secondaryBarHeight);
|
||||||
|
|
||||||
|
// Cache image/color rectangle for the both lines
|
||||||
|
{
|
||||||
|
Rect& r = m_GraphStartLeft ?
|
||||||
|
Rect(x, y + startValue + (step * i), bothBarHeight, 1)
|
||||||
|
: Rect(x + m_W - bothBarHeight, y + startValue + (step * i), bothBarHeight, 1);
|
||||||
|
|
||||||
|
bothPath.AddRectangle(r); // cache
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache the image/color rectangle for the rest
|
||||||
|
if (secondaryBarHeight > primaryBarHeight)
|
||||||
|
{
|
||||||
|
Rect& r = m_GraphStartLeft ?
|
||||||
|
Rect(x + bothBarHeight, y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1)
|
||||||
|
: Rect(x + m_W - secondaryBarHeight, y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1);
|
||||||
|
|
||||||
|
secondaryPath.AddRectangle(r); // cache
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Rect& r = m_GraphStartLeft ?
|
||||||
|
Rect(x + bothBarHeight, y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1)
|
||||||
|
: Rect(x + m_W - primaryBarHeight, y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1);
|
||||||
|
|
||||||
|
primaryPath.AddRectangle(r); // cache
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Rect& r = m_GraphStartLeft ?
|
||||||
|
Rect(x, y + startValue + (step * i), primaryBarHeight, 1)
|
||||||
|
: Rect(x + m_W - primaryBarHeight, y + startValue + (step * i), primaryBarHeight, 1);
|
||||||
|
|
||||||
|
primaryPath.AddRectangle(r); // cache
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // GraphOrientation=Vertical
|
||||||
|
{
|
||||||
|
for (i = startValue; *endValueLHS < *endValueRHS; i += step)
|
||||||
{
|
{
|
||||||
double value = (m_MaxPrimaryValue == 0.0) ?
|
double value = (m_MaxPrimaryValue == 0.0) ?
|
||||||
0.0
|
0.0
|
||||||
@ -406,9 +568,9 @@ bool CMeterHistogram::Draw(Graphics& graphics)
|
|||||||
|
|
||||||
// Cache image/color rectangle for the both lines
|
// Cache image/color rectangle for the both lines
|
||||||
{
|
{
|
||||||
Rect& r = (m_Flip) ?
|
Rect& r = m_Flip ?
|
||||||
Rect(x + i, y, 1, bothBarHeight)
|
Rect(x + startValue + (step * i), y, 1, bothBarHeight)
|
||||||
: Rect(x + i, y + m_H - bothBarHeight, 1, bothBarHeight);
|
: Rect(x + startValue + (step * i), y + m_H - bothBarHeight, 1, bothBarHeight);
|
||||||
|
|
||||||
bothPath.AddRectangle(r); // cache
|
bothPath.AddRectangle(r); // cache
|
||||||
}
|
}
|
||||||
@ -416,30 +578,31 @@ bool CMeterHistogram::Draw(Graphics& graphics)
|
|||||||
// Cache the image/color rectangle for the rest
|
// Cache the image/color rectangle for the rest
|
||||||
if (secondaryBarHeight > primaryBarHeight)
|
if (secondaryBarHeight > primaryBarHeight)
|
||||||
{
|
{
|
||||||
Rect& r = (m_Flip) ?
|
Rect& r = m_Flip ?
|
||||||
Rect(x + i, y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight)
|
Rect(x + startValue + (step * i), y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight)
|
||||||
: Rect(x + i, y + m_H - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight);
|
: Rect(x + startValue + (step * i), y + m_H - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight);
|
||||||
|
|
||||||
secondaryPath.AddRectangle(r); // cache
|
secondaryPath.AddRectangle(r); // cache
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Rect& r = (m_Flip) ?
|
Rect& r = m_Flip ?
|
||||||
Rect(x + i, y + bothBarHeight, 1, primaryBarHeight - bothBarHeight)
|
Rect(x + startValue + (step * i), y + bothBarHeight, 1, primaryBarHeight - bothBarHeight)
|
||||||
: Rect(x + i, y + m_H - primaryBarHeight, 1, primaryBarHeight - bothBarHeight);
|
: Rect(x + startValue + (step * i), y + m_H - primaryBarHeight, 1, primaryBarHeight - bothBarHeight);
|
||||||
|
|
||||||
primaryPath.AddRectangle(r); // cache
|
primaryPath.AddRectangle(r); // cache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Rect& r = (m_Flip) ?
|
Rect& r = m_Flip ?
|
||||||
Rect(x + i, y, 1, primaryBarHeight)
|
Rect(x + startValue + (step * i), y, 1, primaryBarHeight)
|
||||||
: Rect(x + i, y + m_H - primaryBarHeight, 1, primaryBarHeight);
|
: Rect(x + startValue + (step * i), y + m_H - primaryBarHeight, 1, primaryBarHeight);
|
||||||
|
|
||||||
primaryPath.AddRectangle(r); // cache
|
primaryPath.AddRectangle(r); // cache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Draw cached rectangles
|
// Draw cached rectangles
|
||||||
if (primaryBitmap)
|
if (primaryBitmap)
|
||||||
|
@ -71,7 +71,10 @@ private:
|
|||||||
double m_MaxSecondaryValue;
|
double m_MaxSecondaryValue;
|
||||||
double m_MinSecondaryValue;
|
double m_MinSecondaryValue;
|
||||||
|
|
||||||
bool m_WidthChanged;
|
bool m_SizeChanged;
|
||||||
|
|
||||||
|
bool m_GraphStartLeft; // Start graph to the Left or Right(default)
|
||||||
|
bool m_GraphHorizontalOrientation; // Horizontal or Vertical(default)
|
||||||
|
|
||||||
static const WCHAR* c_PrimaryConfigArray[CTintedImage::ConfigCount];
|
static const WCHAR* c_PrimaryConfigArray[CTintedImage::ConfigCount];
|
||||||
static const WCHAR* c_SecondaryConfigArray[CTintedImage::ConfigCount];
|
static const WCHAR* c_SecondaryConfigArray[CTintedImage::ConfigCount];
|
||||||
|
@ -33,7 +33,9 @@ CMeterLine::CMeterLine(CMeterWindow* meterWindow, const WCHAR* name) : CMeter(me
|
|||||||
m_Flip(false),
|
m_Flip(false),
|
||||||
m_LineWidth(1.0),
|
m_LineWidth(1.0),
|
||||||
m_HorizontalColor(Color::Black),
|
m_HorizontalColor(Color::Black),
|
||||||
m_CurrentPos()
|
m_CurrentPos(),
|
||||||
|
m_GraphStartLeft(false),
|
||||||
|
m_GraphHorizontalOrientation(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +58,7 @@ void CMeterLine::Initialize()
|
|||||||
size_t colorsSize = m_Colors.size();
|
size_t colorsSize = m_Colors.size();
|
||||||
size_t allValuesSize = m_AllValues.size();
|
size_t allValuesSize = m_AllValues.size();
|
||||||
size_t num = (allValuesSize > 0) ? m_AllValues[0].size() : 0;
|
size_t num = (allValuesSize > 0) ? m_AllValues[0].size() : 0;
|
||||||
|
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
|
||||||
|
|
||||||
if (colorsSize != allValuesSize)
|
if (colorsSize != allValuesSize)
|
||||||
{
|
{
|
||||||
@ -65,9 +68,9 @@ void CMeterLine::Initialize()
|
|||||||
{
|
{
|
||||||
m_AllValues.push_back(std::vector<double>());
|
m_AllValues.push_back(std::vector<double>());
|
||||||
|
|
||||||
if (m_W > 0)
|
if (maxSize > 0)
|
||||||
{
|
{
|
||||||
m_AllValues.back().assign(m_W, 0.0);
|
m_AllValues.back().assign(maxSize, 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,11 +80,11 @@ void CMeterLine::Initialize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_W < 0 || num != (size_t)m_W)
|
if (maxSize < 0 || num != (size_t)maxSize)
|
||||||
{
|
{
|
||||||
if (m_CurrentPos >= m_W) m_CurrentPos = 0;
|
if (m_CurrentPos >= maxSize) m_CurrentPos = 0;
|
||||||
|
|
||||||
num = (m_W < 0) ? 0 : m_W;
|
num = (maxSize < 0) ? 0 : maxSize;
|
||||||
for (size_t i = 0; i < allValuesSize; ++i)
|
for (size_t i = 0; i < allValuesSize; ++i)
|
||||||
{
|
{
|
||||||
if (num != m_AllValues[i].size())
|
if (num != m_AllValues[i].size())
|
||||||
@ -154,11 +157,60 @@ void CMeterLine::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
|||||||
m_HorizontalColor = parser.ReadColor(section, L"HorizontalLineColor", color); // This is what it should be
|
m_HorizontalColor = parser.ReadColor(section, L"HorizontalLineColor", color); // This is what it should be
|
||||||
|
|
||||||
if (m_Initialized &&
|
if (m_Initialized &&
|
||||||
(oldLineCount != lineCount ||
|
(oldLineCount != lineCount || oldW != m_W))
|
||||||
oldW != m_W))
|
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const WCHAR* graph = parser.ReadString(section, L"GraphStart", L"RIGHT").c_str();
|
||||||
|
if (_wcsicmp(graph, L"RIGHT") == 0)
|
||||||
|
{
|
||||||
|
m_GraphStartLeft = false;
|
||||||
|
}
|
||||||
|
else if (_wcsicmp(graph, L"LEFT") == 0)
|
||||||
|
{
|
||||||
|
m_GraphStartLeft = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogWithArgs(LOG_ERROR, L"StartFrom=%s is not valid in [%s]", graph, m_Name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
graph = parser.ReadString(section, L"GraphOrientation", L"VERTICAL").c_str();
|
||||||
|
if (_wcsicmp(graph, L"VERTICAL") == 0)
|
||||||
|
{
|
||||||
|
// Restart graph
|
||||||
|
if (m_GraphHorizontalOrientation)
|
||||||
|
{
|
||||||
|
m_GraphHorizontalOrientation = false;
|
||||||
|
m_AllValues.clear();
|
||||||
|
Initialize();
|
||||||
|
m_CurrentPos = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_GraphHorizontalOrientation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_wcsicmp(graph, L"HORIZONTAL") == 0)
|
||||||
|
{
|
||||||
|
// Restart graph
|
||||||
|
if (!m_GraphHorizontalOrientation)
|
||||||
|
{
|
||||||
|
m_GraphHorizontalOrientation = true;
|
||||||
|
m_AllValues.clear();
|
||||||
|
Initialize();
|
||||||
|
m_CurrentPos = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_GraphHorizontalOrientation = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogWithArgs(LOG_ERROR, L"GraphOrientation=%s is not valid in [%s]", graph, m_Name.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -169,7 +221,9 @@ bool CMeterLine::Update()
|
|||||||
{
|
{
|
||||||
if (CMeter::Update() && m_Measure)
|
if (CMeter::Update() && m_Measure)
|
||||||
{
|
{
|
||||||
if (m_W > 0)
|
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
|
||||||
|
|
||||||
|
if (maxSize > 0)
|
||||||
{
|
{
|
||||||
// Collect the values
|
// Collect the values
|
||||||
if (!m_Measure->IsDisabled())
|
if (!m_Measure->IsDisabled())
|
||||||
@ -190,7 +244,7 @@ bool CMeterLine::Update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
++m_CurrentPos;
|
++m_CurrentPos;
|
||||||
if (m_CurrentPos >= m_W) m_CurrentPos = 0;
|
if (m_CurrentPos >= maxSize) m_CurrentPos = 0;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -203,7 +257,8 @@ bool CMeterLine::Update()
|
|||||||
*/
|
*/
|
||||||
bool CMeterLine::Draw(Graphics& graphics)
|
bool CMeterLine::Draw(Graphics& graphics)
|
||||||
{
|
{
|
||||||
if (!CMeter::Draw(graphics) || m_W <= 0) return false;
|
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
|
||||||
|
if (!CMeter::Draw(graphics) || maxSize <= 0) return false;
|
||||||
|
|
||||||
double maxValue = 0.0;
|
double maxValue = 0.0;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
@ -291,6 +346,74 @@ bool CMeterLine::Draw(Graphics& graphics)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw all the lines
|
// Draw all the lines
|
||||||
|
|
||||||
|
if (m_GraphHorizontalOrientation)
|
||||||
|
{
|
||||||
|
const REAL W = m_W - 1.0f;
|
||||||
|
counter = 0;
|
||||||
|
std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
|
||||||
|
for (; i != m_AllValues.end(); ++i)
|
||||||
|
{
|
||||||
|
// Draw a line
|
||||||
|
REAL X, oldX;
|
||||||
|
|
||||||
|
const double scale = m_ScaleValues[counter] * W / maxValue;
|
||||||
|
|
||||||
|
int pos = m_CurrentPos;
|
||||||
|
|
||||||
|
oldX = (REAL)((*i)[pos] * scale);
|
||||||
|
oldX = min(oldX, W);
|
||||||
|
oldX = max(oldX, 0.0f);
|
||||||
|
oldX = x + (m_GraphStartLeft ? oldX : W - oldX);
|
||||||
|
|
||||||
|
// Cache all lines
|
||||||
|
GraphicsPath path;
|
||||||
|
|
||||||
|
if (!m_Flip)
|
||||||
|
{
|
||||||
|
for (int j = y + 1, R = y + m_H; j < R; ++j)
|
||||||
|
{
|
||||||
|
++pos;
|
||||||
|
if (pos >= m_H) pos = 0;
|
||||||
|
|
||||||
|
X = (REAL)((*i)[pos] * scale);
|
||||||
|
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);
|
||||||
|
|
||||||
|
oldX = X;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int j = y + m_H, R = y + 1; j > R; --j)
|
||||||
|
{
|
||||||
|
++pos;
|
||||||
|
if (pos >= m_H) pos = 0;
|
||||||
|
|
||||||
|
X = (REAL)((*i)[pos] * scale);
|
||||||
|
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));
|
||||||
|
|
||||||
|
oldX = X;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw cached lines
|
||||||
|
Pen pen(m_Colors[counter], (REAL)m_LineWidth);
|
||||||
|
pen.SetLineJoin(LineJoinBevel);
|
||||||
|
graphics.DrawPath(&pen, &path);
|
||||||
|
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
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();
|
std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
|
||||||
@ -306,10 +429,13 @@ bool CMeterLine::Draw(Graphics& graphics)
|
|||||||
oldY = (REAL)((*i)[pos] * scale);
|
oldY = (REAL)((*i)[pos] * scale);
|
||||||
oldY = min(oldY, H);
|
oldY = min(oldY, H);
|
||||||
oldY = max(oldY, 0.0f);
|
oldY = max(oldY, 0.0f);
|
||||||
oldY = y + ((m_Flip) ? oldY : H - oldY);
|
oldY = y + (m_Flip ? oldY : H - oldY);
|
||||||
|
|
||||||
// Cache all lines
|
// Cache all lines
|
||||||
GraphicsPath path;
|
GraphicsPath path;
|
||||||
|
|
||||||
|
if (!m_GraphStartLeft)
|
||||||
|
{
|
||||||
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;
|
||||||
@ -318,12 +444,30 @@ bool CMeterLine::Draw(Graphics& graphics)
|
|||||||
Y = (REAL)((*i)[pos] * scale);
|
Y = (REAL)((*i)[pos] * scale);
|
||||||
Y = min(Y, H);
|
Y = min(Y, H);
|
||||||
Y = max(Y, 0.0f);
|
Y = max(Y, 0.0f);
|
||||||
Y = y + ((m_Flip) ? Y : H - Y);
|
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);
|
||||||
|
|
||||||
oldY = Y;
|
oldY = Y;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int j = x + m_W, R = x + 1; j > R; --j)
|
||||||
|
{
|
||||||
|
++pos;
|
||||||
|
if (pos >= m_W) pos = 0;
|
||||||
|
|
||||||
|
Y = (REAL)((*i)[pos] * scale);
|
||||||
|
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);
|
||||||
|
|
||||||
|
oldY = Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Draw cached lines
|
// Draw cached lines
|
||||||
Pen pen(m_Colors[counter], (REAL)m_LineWidth);
|
Pen pen(m_Colors[counter], (REAL)m_LineWidth);
|
||||||
@ -332,6 +476,7 @@ bool CMeterLine::Draw(Graphics& graphics)
|
|||||||
|
|
||||||
++counter;
|
++counter;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,9 @@ private:
|
|||||||
|
|
||||||
std::vector< std::vector<double> > m_AllValues; // All the values to be drawn
|
std::vector< std::vector<double> > m_AllValues; // All the values to be drawn
|
||||||
int m_CurrentPos; // Place of the current value
|
int m_CurrentPos; // Place of the current value
|
||||||
|
|
||||||
|
bool m_GraphStartLeft; // Start graph to the Left or Right(default)
|
||||||
|
bool m_GraphHorizontalOrientation; // Horizontal or Vertical(default)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user