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,8 +365,9 @@ 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();
|
||||||
m_MaxSecondaryValue = 0.0;
|
m_MaxSecondaryValue = 0.0;
|
||||||
@ -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,63 +450,157 @@ 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)
|
||||||
{
|
{
|
||||||
double value = (m_MaxPrimaryValue == 0.0) ?
|
startValue = m_W - 1;
|
||||||
0.0
|
endValueLHS = &endValue;
|
||||||
: m_PrimaryValues[(i + m_MeterPos) % m_W] / m_MaxPrimaryValue;
|
endValueRHS = &i;
|
||||||
value -= m_MinPrimaryValue;
|
step = -1;
|
||||||
int primaryBarHeight = (int)(m_H * value);
|
}
|
||||||
primaryBarHeight = min(m_H, primaryBarHeight);
|
else if (m_GraphHorizontalOrientation && !m_Flip)
|
||||||
primaryBarHeight = max(0, primaryBarHeight);
|
{
|
||||||
|
endValueRHS = &m_H;
|
||||||
|
}
|
||||||
|
else if (m_GraphHorizontalOrientation && m_Flip)
|
||||||
|
{
|
||||||
|
startValue = m_H - 1;
|
||||||
|
endValueLHS = &endValue;
|
||||||
|
endValueRHS = &i;
|
||||||
|
step = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_SecondaryMeasure)
|
// Horizontal or Vertical graph
|
||||||
|
if (m_GraphHorizontalOrientation)
|
||||||
|
{
|
||||||
|
for (i = startValue; *endValueLHS < *endValueRHS; i += step)
|
||||||
{
|
{
|
||||||
value = (m_MaxSecondaryValue == 0.0) ?
|
double value = (m_MaxPrimaryValue == 0.0) ?
|
||||||
0.0
|
0.0
|
||||||
: m_SecondaryValues[(i + m_MeterPos) % m_W] / m_MaxSecondaryValue;
|
: m_PrimaryValues[(i + (m_MeterPos % m_H)) % m_H] / m_MaxPrimaryValue;
|
||||||
value -= m_MinSecondaryValue;
|
value -= m_MinPrimaryValue;
|
||||||
int secondaryBarHeight = (int)(m_H * value);
|
int primaryBarHeight = (int)(m_W * value);
|
||||||
secondaryBarHeight = min(m_H, secondaryBarHeight);
|
primaryBarHeight = min(m_W, primaryBarHeight);
|
||||||
secondaryBarHeight = max(0, secondaryBarHeight);
|
primaryBarHeight = max(0, primaryBarHeight);
|
||||||
|
|
||||||
// Check which measured value is higher
|
if (m_SecondaryMeasure)
|
||||||
int bothBarHeight = min(primaryBarHeight, secondaryBarHeight);
|
|
||||||
|
|
||||||
// Cache image/color rectangle for the both lines
|
|
||||||
{
|
{
|
||||||
Rect& r = (m_Flip) ?
|
value = (m_MaxSecondaryValue == 0.0) ?
|
||||||
Rect(x + i, y, 1, bothBarHeight)
|
0.0
|
||||||
: Rect(x + i, y + m_H - bothBarHeight, 1, bothBarHeight);
|
: 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);
|
||||||
|
|
||||||
bothPath.AddRectangle(r); // cache
|
// Check which measured value is higher
|
||||||
}
|
int bothBarHeight = min(primaryBarHeight, secondaryBarHeight);
|
||||||
|
|
||||||
// Cache the image/color rectangle for the rest
|
// Cache image/color rectangle for the both lines
|
||||||
if (secondaryBarHeight > primaryBarHeight)
|
{
|
||||||
{
|
Rect& r = m_GraphStartLeft ?
|
||||||
Rect& r = (m_Flip) ?
|
Rect(x, y + startValue + (step * i), bothBarHeight, 1)
|
||||||
Rect(x + i, y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight)
|
: Rect(x + m_W - bothBarHeight, y + startValue + (step * i), bothBarHeight, 1);
|
||||||
: Rect(x + i, y + m_H - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight);
|
|
||||||
|
|
||||||
secondaryPath.AddRectangle(r); // cache
|
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
|
else
|
||||||
{
|
{
|
||||||
Rect& r = (m_Flip) ?
|
Rect& r = m_GraphStartLeft ?
|
||||||
Rect(x + i, y + bothBarHeight, 1, primaryBarHeight - bothBarHeight)
|
Rect(x, y + startValue + (step * i), primaryBarHeight, 1)
|
||||||
: Rect(x + i, y + m_H - primaryBarHeight, 1, primaryBarHeight - bothBarHeight);
|
: Rect(x + m_W - primaryBarHeight, y + startValue + (step * i), primaryBarHeight, 1);
|
||||||
|
|
||||||
primaryPath.AddRectangle(r); // cache
|
primaryPath.AddRectangle(r); // cache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else // GraphOrientation=Vertical
|
||||||
|
{
|
||||||
|
for (i = startValue; *endValueLHS < *endValueRHS; i += step)
|
||||||
{
|
{
|
||||||
Rect& r = (m_Flip) ?
|
double value = (m_MaxPrimaryValue == 0.0) ?
|
||||||
Rect(x + i, y, 1, primaryBarHeight)
|
0.0
|
||||||
: Rect(x + i, y + m_H - primaryBarHeight, 1, primaryBarHeight);
|
: m_PrimaryValues[(i + m_MeterPos) % m_W] / m_MaxPrimaryValue;
|
||||||
|
value -= m_MinPrimaryValue;
|
||||||
|
int primaryBarHeight = (int)(m_H * value);
|
||||||
|
primaryBarHeight = min(m_H, primaryBarHeight);
|
||||||
|
primaryBarHeight = max(0, primaryBarHeight);
|
||||||
|
|
||||||
primaryPath.AddRectangle(r); // cache
|
if (m_SecondaryMeasure)
|
||||||
|
{
|
||||||
|
value = (m_MaxSecondaryValue == 0.0) ?
|
||||||
|
0.0
|
||||||
|
: m_SecondaryValues[(i + m_MeterPos) % m_W] / m_MaxSecondaryValue;
|
||||||
|
value -= m_MinSecondaryValue;
|
||||||
|
int secondaryBarHeight = (int)(m_H * value);
|
||||||
|
secondaryBarHeight = min(m_H, 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_Flip ?
|
||||||
|
Rect(x + startValue + (step * i), y, 1, bothBarHeight)
|
||||||
|
: Rect(x + startValue + (step * i), y + m_H - bothBarHeight, 1, bothBarHeight);
|
||||||
|
|
||||||
|
bothPath.AddRectangle(r); // cache
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache the image/color rectangle for the rest
|
||||||
|
if (secondaryBarHeight > primaryBarHeight)
|
||||||
|
{
|
||||||
|
Rect& r = m_Flip ?
|
||||||
|
Rect(x + startValue + (step * i), y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight)
|
||||||
|
: Rect(x + startValue + (step * i), y + m_H - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight);
|
||||||
|
|
||||||
|
secondaryPath.AddRectangle(r); // cache
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Rect& r = m_Flip ?
|
||||||
|
Rect(x + startValue + (step * i), y + bothBarHeight, 1, primaryBarHeight - bothBarHeight)
|
||||||
|
: Rect(x + startValue + (step * i), y + m_H - primaryBarHeight, 1, primaryBarHeight - bothBarHeight);
|
||||||
|
|
||||||
|
primaryPath.AddRectangle(r); // cache
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Rect& r = m_Flip ?
|
||||||
|
Rect(x + startValue + (step * i), y, 1, primaryBarHeight)
|
||||||
|
: Rect(x + startValue + (step * i), y + m_H - primaryBarHeight, 1, primaryBarHeight);
|
||||||
|
|
||||||
|
primaryPath.AddRectangle(r); // cache
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,18 +42,18 @@ private:
|
|||||||
void DisposeBuffer();
|
void DisposeBuffer();
|
||||||
|
|
||||||
std::wstring m_SecondaryMeasureName; // Name of the secondary measure
|
std::wstring m_SecondaryMeasureName; // Name of the secondary measure
|
||||||
CMeasure* m_SecondaryMeasure; // Pointer ot the secondary measure
|
CMeasure* m_SecondaryMeasure; // Pointer ot the secondary measure
|
||||||
Gdiplus::Color m_PrimaryColor; // Color of the primary histogram
|
Gdiplus::Color m_PrimaryColor; // Color of the primary histogram
|
||||||
Gdiplus::Color m_SecondaryColor; // Color of the secondary histogram
|
Gdiplus::Color m_SecondaryColor; // Color of the secondary histogram
|
||||||
Gdiplus::Color m_BothColor; // Color when the both histograms overlap
|
Gdiplus::Color m_BothColor; // Color when the both histograms overlap
|
||||||
|
|
||||||
int m_MeterPos; // Position of the meter (i.e. where the new value should be placed)
|
int m_MeterPos; // Position of the meter (i.e. where the new value should be placed)
|
||||||
bool m_Autoscale;
|
bool m_Autoscale;
|
||||||
bool m_Flip;
|
bool m_Flip;
|
||||||
|
|
||||||
std::wstring m_PrimaryImageName; // Name of the primary image for bitmap histograms
|
std::wstring m_PrimaryImageName; // Name of the primary image for bitmap histograms
|
||||||
std::wstring m_SecondaryImageName; // Name of the secondary image for bitmap histograms
|
std::wstring m_SecondaryImageName; // Name of the secondary image for bitmap histograms
|
||||||
std::wstring m_BothImageName; // Name of the image for overlapping histograms
|
std::wstring m_BothImageName; // Name of the image for overlapping histograms
|
||||||
|
|
||||||
CTintedImage m_PrimaryImage; // The primary bitmap
|
CTintedImage m_PrimaryImage; // The primary bitmap
|
||||||
CTintedImage m_SecondaryImage; // The secondary bitmap
|
CTintedImage m_SecondaryImage; // The secondary bitmap
|
||||||
@ -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,46 +346,136 @@ bool CMeterLine::Draw(Graphics& graphics)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw all the lines
|
// Draw all the lines
|
||||||
const REAL H = m_H - 1.0f;
|
|
||||||
counter = 0;
|
if (m_GraphHorizontalOrientation)
|
||||||
std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
|
|
||||||
for (; i != m_AllValues.end(); ++i)
|
|
||||||
{
|
{
|
||||||
// Draw a line
|
const REAL W = m_W - 1.0f;
|
||||||
REAL Y, oldY;
|
counter = 0;
|
||||||
|
std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
|
||||||
const double scale = m_ScaleValues[counter] * H / maxValue;
|
for (; i != m_AllValues.end(); ++i)
|
||||||
|
|
||||||
int pos = m_CurrentPos;
|
|
||||||
|
|
||||||
oldY = (REAL)((*i)[pos] * scale);
|
|
||||||
oldY = min(oldY, H);
|
|
||||||
oldY = max(oldY, 0.0f);
|
|
||||||
oldY = y + ((m_Flip) ? oldY : H - oldY);
|
|
||||||
|
|
||||||
// Cache all lines
|
|
||||||
GraphicsPath path;
|
|
||||||
for (int j = x + 1, R = x + m_W; j < R; ++j)
|
|
||||||
{
|
{
|
||||||
++pos;
|
// Draw a line
|
||||||
if (pos >= m_W) pos = 0;
|
REAL X, oldX;
|
||||||
|
|
||||||
Y = (REAL)((*i)[pos] * scale);
|
const double scale = m_ScaleValues[counter] * W / maxValue;
|
||||||
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);
|
int pos = m_CurrentPos;
|
||||||
|
|
||||||
oldY = Y;
|
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;
|
||||||
|
counter = 0;
|
||||||
|
std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
|
||||||
|
for (; i != m_AllValues.end(); ++i)
|
||||||
|
{
|
||||||
|
// Draw a line
|
||||||
|
REAL Y, oldY;
|
||||||
|
|
||||||
// Draw cached lines
|
const double scale = m_ScaleValues[counter] * H / maxValue;
|
||||||
Pen pen(m_Colors[counter], (REAL)m_LineWidth);
|
|
||||||
pen.SetLineJoin(LineJoinBevel);
|
|
||||||
graphics.DrawPath(&pen, &path);
|
|
||||||
|
|
||||||
++counter;
|
int pos = m_CurrentPos;
|
||||||
|
|
||||||
|
oldY = (REAL)((*i)[pos] * scale);
|
||||||
|
oldY = min(oldY, H);
|
||||||
|
oldY = max(oldY, 0.0f);
|
||||||
|
oldY = y + (m_Flip ? oldY : H - oldY);
|
||||||
|
|
||||||
|
// Cache all lines
|
||||||
|
GraphicsPath path;
|
||||||
|
|
||||||
|
if (!m_GraphStartLeft)
|
||||||
|
{
|
||||||
|
for (int j = x + 1, R = x + m_W; 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, 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
|
||||||
|
Pen pen(m_Colors[counter], (REAL)m_LineWidth);
|
||||||
|
pen.SetLineJoin(LineJoinBevel);
|
||||||
|
graphics.DrawPath(&pen, &path);
|
||||||
|
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -48,10 +48,13 @@ private:
|
|||||||
bool m_HorizontalLines; // If true, horizontal lines will ba drawn on the meter
|
bool m_HorizontalLines; // If true, horizontal lines will ba drawn on the meter
|
||||||
bool m_Flip;
|
bool m_Flip;
|
||||||
double m_LineWidth;
|
double m_LineWidth;
|
||||||
Gdiplus::Color m_HorizontalColor; // Color of the horizontal lines
|
Gdiplus::Color m_HorizontalColor; // Color of the horizontal lines
|
||||||
|
|
||||||
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