rainmeter-studio/Library/MeterHistogram.cpp

660 lines
18 KiB
C++
Raw Normal View History

2009-02-10 18:37:48 +00:00
/*
Copyright (C) 2001 Kimmo Pekkola
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2009-02-10 18:37:48 +00:00
*/
#include "StdAfx.h"
2009-02-10 18:37:48 +00:00
#include "MeterHistogram.h"
#include "Measure.h"
#include "Error.h"
#include "Rainmeter.h"
2013-03-25 15:42:18 +00:00
#include "../Common/Gfx/Canvas.h"
2009-02-10 18:37:48 +00:00
using namespace Gdiplus;
2013-05-31 14:18:52 +00:00
TintedImageHelper_DefineOptionArray(MeterHistogram::c_PrimaryOptionArray, L"Primary");
TintedImageHelper_DefineOptionArray(MeterHistogram::c_SecondaryOptionArray, L"Secondary");
TintedImageHelper_DefineOptionArray(MeterHistogram::c_BothOptionArray, L"Both");
2011-02-07 09:38:27 +00:00
2009-02-10 18:37:48 +00:00
/*
** The constructor
**
*/
2013-05-31 14:18:52 +00:00
MeterHistogram::MeterHistogram(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
m_PrimaryColor(Color::Green),
m_SecondaryColor(Color::Red),
2012-05-20 17:57:12 +00:00
m_OverlapColor(Color::Yellow),
m_MeterPos(),
m_Autoscale(false),
m_Flip(false),
m_PrimaryImage(L"PrimaryImage", c_PrimaryOptionArray, false, meterWindow),
m_SecondaryImage(L"SecondaryImage", c_SecondaryOptionArray, false, meterWindow),
m_OverlapImage(L"BothImage", c_BothOptionArray, false, meterWindow),
m_PrimaryNeedsReload(false),
m_SecondaryNeedsReload(false),
2012-05-20 17:57:12 +00:00
m_OverlapNeedsReload(false),
m_PrimaryValues(),
m_SecondaryValues(),
m_MaxPrimaryValue(1.0),
m_MinPrimaryValue(),
m_MaxSecondaryValue(1.0),
m_MinSecondaryValue(),
m_SizeChanged(true),
m_GraphStartLeft(false),
m_GraphHorizontalOrientation(false)
2009-02-10 18:37:48 +00:00
{
}
/*
** The destructor
**
*/
2013-05-31 14:18:52 +00:00
MeterHistogram::~MeterHistogram()
2009-02-10 18:37:48 +00:00
{
DisposeBuffer();
}
/*
** Disposes the buffers.
**
*/
2013-05-31 14:18:52 +00:00
void MeterHistogram::DisposeBuffer()
{
// Reset current position
m_MeterPos = 0;
// Delete buffers
delete [] m_PrimaryValues;
2013-05-31 14:28:39 +00:00
m_PrimaryValues = nullptr;
delete [] m_SecondaryValues;
2013-05-31 14:28:39 +00:00
m_SecondaryValues = nullptr;
2009-02-10 18:37:48 +00:00
}
2012-12-22 22:05:46 +00:00
/*
** Creates the buffers.
**
*/
2013-05-31 14:18:52 +00:00
void MeterHistogram::CreateBuffer()
2012-12-22 22:05:46 +00:00
{
DisposeBuffer();
// Create buffers for values
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
if (maxSize > 0)
{
m_PrimaryValues = new double[maxSize]();
if (m_Measures.size() >= 2)
{
m_SecondaryValues = new double[maxSize]();
}
}
}
2009-02-10 18:37:48 +00:00
/*
** Load the images and calculate the dimensions of the meter from them.
** Or create the brushes if solid color histogram is used.
**
*/
2013-05-31 14:18:52 +00:00
void MeterHistogram::Initialize()
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
Meter::Initialize();
2009-02-10 18:37:48 +00:00
2013-05-31 14:28:39 +00:00
Measure* secondaryMeasure = (m_Measures.size() >= 2) ? m_Measures[1] : nullptr;
2012-07-17 07:37:53 +00:00
// A sanity check
2012-07-17 07:37:53 +00:00
if (secondaryMeasure && !m_PrimaryImageName.empty() && (m_OverlapImageName.empty() || m_SecondaryImageName.empty()))
2009-02-10 18:37:48 +00:00
{
LogWarningF(this, L"Histogram: SecondaryImage and BothImage not defined");
2009-02-10 18:37:48 +00:00
m_PrimaryImage.DisposeImage();
m_SecondaryImage.DisposeImage();
2012-05-20 17:57:12 +00:00
m_OverlapImage.DisposeImage();
}
else
{
// Load the bitmaps if defined
if (!m_PrimaryImageName.empty())
{
m_PrimaryImage.LoadImage(m_PrimaryImageName, m_PrimaryNeedsReload);
2009-02-10 18:37:48 +00:00
if (m_PrimaryImage.IsLoaded())
{
2012-12-22 22:05:46 +00:00
int oldSize = m_GraphHorizontalOrientation ? m_H : m_W;
Bitmap* bitmap = m_PrimaryImage.GetImage();
m_W = bitmap->GetWidth();
m_H = bitmap->GetHeight();
2012-12-22 22:05:46 +00:00
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
if (oldSize != maxSize)
{
m_SizeChanged = true;
}
m_W += GetWidthPadding();
m_H += GetHeightPadding();
}
}
else if (m_PrimaryImage.IsLoaded())
{
m_PrimaryImage.DisposeImage();
2009-02-10 18:37:48 +00:00
}
if (!m_SecondaryImageName.empty())
2009-02-10 18:37:48 +00:00
{
m_SecondaryImage.LoadImage(m_SecondaryImageName, m_SecondaryNeedsReload);
}
else if (m_SecondaryImage.IsLoaded())
{
m_SecondaryImage.DisposeImage();
2009-02-10 18:37:48 +00:00
}
2012-05-20 17:57:12 +00:00
if (!m_OverlapImageName.empty())
{
2012-05-20 17:57:12 +00:00
m_OverlapImage.LoadImage(m_OverlapImageName, m_OverlapNeedsReload);
}
2012-05-20 17:57:12 +00:00
else if (m_OverlapImage.IsLoaded())
{
2012-05-20 17:57:12 +00:00
m_OverlapImage.DisposeImage();
}
2009-02-10 18:37:48 +00:00
}
if ((!m_PrimaryImageName.empty() && !m_PrimaryImage.IsLoaded()) ||
(!m_SecondaryImageName.empty() && !m_SecondaryImage.IsLoaded()) ||
2012-05-20 17:57:12 +00:00
(!m_OverlapImageName.empty() && !m_OverlapImage.IsLoaded()))
2009-02-10 18:37:48 +00:00
{
DisposeBuffer();
m_SizeChanged = false;
}
else if (m_SizeChanged)
{
2012-12-22 22:05:46 +00:00
CreateBuffer();
m_SizeChanged = false;
2009-02-10 18:37:48 +00:00
}
}
/*
** Read the options specified in the ini file.
2009-02-10 18:37:48 +00:00
**
*/
2013-05-31 14:18:52 +00:00
void MeterHistogram::ReadOptions(ConfigParser& parser, const WCHAR* section)
2009-02-10 18:37:48 +00:00
{
// Store the current values so we know if the image needs to be updated
std::wstring oldPrimaryImageName = m_PrimaryImageName;
std::wstring oldSecondaryImageName = m_SecondaryImageName;
2012-05-20 17:57:12 +00:00
std::wstring oldBothImageName = m_OverlapImageName;
int oldW = m_W;
int oldH = m_H;
2012-12-22 22:05:46 +00:00
bool oldGraphHorizontalOrientation = m_GraphHorizontalOrientation;
2013-05-31 14:18:52 +00:00
Meter::ReadOptions(parser, section);
2009-02-10 18:37:48 +00:00
2009-09-04 16:37:51 +00:00
m_PrimaryColor = parser.ReadColor(section, L"PrimaryColor", Color::Green);
m_SecondaryColor = parser.ReadColor(section, L"SecondaryColor", Color::Red);
2012-05-20 17:57:12 +00:00
m_OverlapColor = parser.ReadColor(section, L"BothColor", Color::Yellow);
2009-02-10 18:37:48 +00:00
2009-09-04 16:37:51 +00:00
m_PrimaryImageName = parser.ReadString(section, L"PrimaryImage", L"");
2010-11-25 22:00:34 +00:00
if (!m_PrimaryImageName.empty())
{
// Read tinting options
2012-05-30 18:53:44 +00:00
m_PrimaryImage.ReadOptions(parser, section);
}
else
{
2012-05-30 18:51:06 +00:00
m_PrimaryImage.ClearOptionFlags();
2010-11-25 22:00:34 +00:00
}
2009-02-10 18:37:48 +00:00
2009-09-04 16:37:51 +00:00
m_SecondaryImageName = parser.ReadString(section, L"SecondaryImage", L"");
2010-11-25 22:00:34 +00:00
if (!m_SecondaryImageName.empty())
{
// Read tinting options
2012-05-30 18:53:44 +00:00
m_SecondaryImage.ReadOptions(parser, section);
}
else
{
2012-05-30 18:51:06 +00:00
m_SecondaryImage.ClearOptionFlags();
2010-11-25 22:00:34 +00:00
}
2009-02-10 18:37:48 +00:00
2012-05-20 17:57:12 +00:00
m_OverlapImageName = parser.ReadString(section, L"BothImage", L"");
if (!m_OverlapImageName.empty())
2010-11-25 22:00:34 +00:00
{
// Read tinting options
2012-05-30 18:53:44 +00:00
m_OverlapImage.ReadOptions(parser, section);
}
else
{
2012-05-30 18:51:06 +00:00
m_OverlapImage.ClearOptionFlags();
2010-11-25 22:00:34 +00:00
}
2009-02-10 18:37:48 +00:00
2009-09-04 16:37:51 +00:00
m_Autoscale = 0!=parser.ReadInt(section, L"AutoScale", 0);
2009-02-10 18:37:48 +00:00
m_Flip = 0!=parser.ReadInt(section, L"Flip", 0);
2012-12-22 22:05:46 +00:00
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
{
LogErrorF(this, L"GraphStart=%s is not valid", graph);
2012-12-22 22:05:46 +00:00
}
graph = parser.ReadString(section, L"GraphOrientation", L"VERTICAL").c_str();
if (_wcsicmp(graph, L"VERTICAL") == 0)
{
m_GraphHorizontalOrientation = false;
}
else if (_wcsicmp(graph, L"HORIZONTAL") == 0)
{
m_GraphHorizontalOrientation = true;
}
else
{
LogErrorF(this, L"GraphOrientation=%s is not valid", graph);
2012-12-22 22:05:46 +00:00
}
if (m_Initialized)
{
if (m_PrimaryImageName.empty())
{
2012-12-22 22:05:46 +00:00
int oldSize = oldGraphHorizontalOrientation ? oldH : oldW;
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
if (oldSize != maxSize || oldGraphHorizontalOrientation != m_GraphHorizontalOrientation)
{
m_SizeChanged = true;
Initialize(); // Reload the image
}
}
else
{
// Reset to old dimensions
m_W = oldW;
m_H = oldH;
m_PrimaryNeedsReload = (wcscmp(oldPrimaryImageName.c_str(), m_PrimaryImageName.c_str()) != 0);
m_SecondaryNeedsReload = (wcscmp(oldSecondaryImageName.c_str(), m_SecondaryImageName.c_str()) != 0);
2012-05-20 17:57:12 +00:00
m_OverlapNeedsReload = (wcscmp(oldBothImageName.c_str(), m_OverlapImageName.c_str()) != 0);
2012-12-22 22:05:46 +00:00
m_SizeChanged = (oldGraphHorizontalOrientation != m_GraphHorizontalOrientation);
if (m_PrimaryNeedsReload ||
m_SecondaryNeedsReload ||
2012-05-20 17:57:12 +00:00
m_OverlapNeedsReload ||
2012-05-30 18:51:06 +00:00
m_PrimaryImage.IsOptionsChanged() ||
m_SecondaryImage.IsOptionsChanged() ||
m_OverlapImage.IsOptionsChanged())
{
Initialize(); // Reload the image
}
2012-12-22 22:05:46 +00:00
else if (m_SizeChanged)
{
2012-12-22 22:05:46 +00:00
CreateBuffer();
}
}
}
2009-02-10 18:37:48 +00:00
}
/*
** Updates the value(s) from the measures.
**
*/
2013-05-31 14:18:52 +00:00
bool MeterHistogram::Update()
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
if (Meter::Update() && !m_Measures.empty())
2009-02-10 18:37:48 +00:00
{
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
2009-02-10 18:37:48 +00:00
if (m_PrimaryValues && maxSize > 0) // m_PrimaryValues must not be nullptr
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
Measure* measure = m_Measures[0];
2013-05-31 14:28:39 +00:00
Measure* secondaryMeasure = (m_Measures.size() >= 2) ? m_Measures[1] : nullptr;
2012-12-22 22:05:46 +00:00
// Gather values
m_PrimaryValues[m_MeterPos] = measure->GetValue();
2009-02-10 18:37:48 +00:00
2012-12-22 22:05:46 +00:00
if (secondaryMeasure && m_SecondaryValues)
2009-02-10 18:37:48 +00:00
{
2012-12-22 22:05:46 +00:00
m_SecondaryValues[m_MeterPos] = secondaryMeasure->GetValue();
2009-02-10 18:37:48 +00:00
}
2012-12-22 22:05:46 +00:00
++m_MeterPos;
m_MeterPos %= maxSize;
m_MaxPrimaryValue = measure->GetMaxValue();
m_MinPrimaryValue = measure->GetMinValue();
m_MaxSecondaryValue = 0.0;
m_MinSecondaryValue = 0.0;
if (secondaryMeasure)
2009-02-10 18:37:48 +00:00
{
2012-12-22 22:05:46 +00:00
m_MaxSecondaryValue = secondaryMeasure->GetMaxValue();
m_MinSecondaryValue = secondaryMeasure->GetMinValue();
2009-02-10 18:37:48 +00:00
}
2012-12-22 22:05:46 +00:00
if (m_Autoscale)
2009-02-10 18:37:48 +00:00
{
2012-12-22 22:05:46 +00:00
// Go through all values and find the max
double newValue = 0.0;
for (int i = 0; i < maxSize; ++i)
2009-02-10 18:37:48 +00:00
{
2012-12-22 22:05:46 +00:00
newValue = max(newValue, m_PrimaryValues[i]);
2009-02-10 18:37:48 +00:00
}
// Scale the value up to nearest power of 2
if (newValue > DBL_MAX / 2.0)
2009-02-10 18:37:48 +00:00
{
2012-12-22 22:05:46 +00:00
m_MaxPrimaryValue = DBL_MAX;
}
else
{
2012-12-22 22:05:46 +00:00
m_MaxPrimaryValue = 2.0;
while (m_MaxPrimaryValue < newValue)
{
m_MaxPrimaryValue *= 2.0;
}
}
if (secondaryMeasure && m_SecondaryValues)
{
for (int i = 0; i < maxSize; ++i)
{
newValue = max(newValue, m_SecondaryValues[i]);
}
// Scale the value up to nearest power of 2
if (newValue > DBL_MAX / 2.0)
{
m_MaxSecondaryValue = DBL_MAX;
}
else
{
2012-12-22 22:05:46 +00:00
m_MaxSecondaryValue = 2.0;
while (m_MaxSecondaryValue < newValue)
{
m_MaxSecondaryValue *= 2.0;
}
}
2009-02-10 18:37:48 +00:00
}
}
}
return true;
}
return false;
}
/*
** Draws the meter on the double buffer
**
*/
2013-05-31 14:18:52 +00:00
bool MeterHistogram::Draw(Gfx::Canvas& canvas)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
if (!Meter::Draw(canvas) ||
2012-07-17 07:37:53 +00:00
(m_Measures.size() >= 1 && !m_PrimaryValues) ||
(m_Measures.size() >= 2 && !m_SecondaryValues)) return false;
2013-03-25 15:42:18 +00:00
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
2013-05-31 14:28:39 +00:00
Measure* secondaryMeasure = (m_Measures.size() >= 2) ? m_Measures[1] : nullptr;
2009-02-10 18:37:48 +00:00
GraphicsPath primaryPath;
GraphicsPath secondaryPath;
GraphicsPath bothPath;
Bitmap* primaryBitmap = m_PrimaryImage.GetImage();
Bitmap* secondaryBitmap = m_SecondaryImage.GetImage();
2012-05-20 17:57:12 +00:00
Bitmap* bothBitmap = m_OverlapImage.GetImage();
Gdiplus::Rect meterRect = GetMeterRectPadding();
2009-02-10 18:37:48 +00:00
// Default values (GraphStart=Right, GraphOrientation=Vertical)
int i;
int startValue = 0;
int* endValueLHS = &i;
int* endValueRHS = &meterRect.Width;
int step = 1;
int endValue = -1; //(should be 0, but need to simulate <=)
// GraphStart=Left, GraphOrientation=Vertical
2012-12-27 07:47:44 +00:00
if (!m_GraphHorizontalOrientation)
{
2012-12-27 07:47:44 +00:00
if (m_GraphStartLeft)
{
startValue = meterRect.Width - 1;
2012-12-27 07:47:44 +00:00
endValueLHS = &endValue;
endValueRHS = &i;
step = -1;
}
}
2012-12-27 07:47:44 +00:00
else
{
2012-12-27 07:47:44 +00:00
if (!m_Flip)
{
endValueRHS = &meterRect.Height;
2012-12-27 07:47:44 +00:00
}
else
{
startValue = meterRect.Height - 1;
2012-12-27 07:47:44 +00:00
endValueLHS = &endValue;
endValueRHS = &i;
step = -1;
}
}
2009-02-10 18:37:48 +00:00
// Horizontal or Vertical graph
if (m_GraphHorizontalOrientation)
{
for (i = startValue; *endValueLHS < *endValueRHS; i += step)
2009-02-10 18:37:48 +00:00
{
double value = (m_MaxPrimaryValue == 0.0) ?
0.0
: m_PrimaryValues[(i + (m_MeterPos % meterRect.Height)) % meterRect.Height] / m_MaxPrimaryValue;
value -= m_MinPrimaryValue;
int primaryBarHeight = (int)(meterRect.Width * value);
primaryBarHeight = min(meterRect.Width, primaryBarHeight);
primaryBarHeight = max(0, primaryBarHeight);
2009-02-10 18:37:48 +00:00
2012-07-17 07:37:53 +00:00
if (secondaryMeasure)
2009-02-10 18:37:48 +00:00
{
value = (m_MaxSecondaryValue == 0.0) ?
0.0
: m_SecondaryValues[(i + m_MeterPos) % meterRect.Height] / m_MaxSecondaryValue;
value -= m_MinSecondaryValue;
int secondaryBarHeight = (int)(meterRect.Width * value);
secondaryBarHeight = min(meterRect.Width, 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(meterRect.X, meterRect.Y + startValue + (step * i), bothBarHeight, 1)
: Rect(meterRect.X + meterRect.Width - bothBarHeight, meterRect.Y + startValue + (step * i), bothBarHeight, 1);
bothPath.AddRectangle(r); // cache
}
2009-02-10 18:37:48 +00:00
// Cache the image/color rectangle for the rest
if (secondaryBarHeight > primaryBarHeight)
{
Rect& r = m_GraphStartLeft ?
Rect(meterRect.X + bothBarHeight, meterRect.Y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1)
: Rect(meterRect.X + meterRect.Width - secondaryBarHeight, meterRect.Y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1);
secondaryPath.AddRectangle(r); // cache
}
else
{
Rect& r = m_GraphStartLeft ?
Rect(meterRect.X + bothBarHeight, meterRect.Y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1)
: Rect(meterRect.X + meterRect.Width - primaryBarHeight, meterRect.Y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1);
primaryPath.AddRectangle(r); // cache
}
2009-02-10 18:37:48 +00:00
}
else
{
Rect& r = m_GraphStartLeft ?
Rect(meterRect.X, meterRect.Y + startValue + (step * i), primaryBarHeight, 1)
: Rect(meterRect.X + meterRect.Width - primaryBarHeight, meterRect.Y + startValue + (step * i), primaryBarHeight, 1);
primaryPath.AddRectangle(r); // cache
2009-02-10 18:37:48 +00:00
}
}
}
else // GraphOrientation=Vertical
{
for (i = startValue; *endValueLHS < *endValueRHS; i += step)
2009-02-10 18:37:48 +00:00
{
double value = (m_MaxPrimaryValue == 0.0) ?
0.0
: m_PrimaryValues[(i + m_MeterPos) % meterRect.Width] / m_MaxPrimaryValue;
value -= m_MinPrimaryValue;
int primaryBarHeight = (int)(meterRect.Height * value);
primaryBarHeight = min(meterRect.Height, primaryBarHeight);
primaryBarHeight = max(0, primaryBarHeight);
2012-07-17 07:37:53 +00:00
if (secondaryMeasure)
{
value = (m_MaxSecondaryValue == 0.0) ?
0.0
: m_SecondaryValues[(i + m_MeterPos) % meterRect.Width] / m_MaxSecondaryValue;
value -= m_MinSecondaryValue;
int secondaryBarHeight = (int)(meterRect.Height * value);
secondaryBarHeight = min(meterRect.Height, 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(meterRect.X + startValue + (step * i), meterRect.Y, 1, bothBarHeight)
: Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - bothBarHeight, 1, bothBarHeight);
bothPath.AddRectangle(r); // cache
}
// Cache the image/color rectangle for the rest
if (secondaryBarHeight > primaryBarHeight)
{
Rect& r = m_Flip ?
Rect(meterRect.X + startValue + (step * i), meterRect.Y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight)
: Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight);
secondaryPath.AddRectangle(r); // cache
}
else
{
Rect& r = m_Flip ?
Rect(meterRect.X + startValue + (step * i), meterRect.Y + bothBarHeight, 1, primaryBarHeight - bothBarHeight)
: Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - primaryBarHeight, 1, primaryBarHeight - bothBarHeight);
primaryPath.AddRectangle(r); // cache
}
}
else
{
Rect& r = m_Flip ?
Rect(meterRect.X + startValue + (step * i), meterRect.Y, 1, primaryBarHeight)
: Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - primaryBarHeight, 1, primaryBarHeight);
primaryPath.AddRectangle(r); // cache
}
2009-02-10 18:37:48 +00:00
}
}
// Draw cached rectangles
if (primaryBitmap)
{
Rect r(meterRect.X, meterRect.Y, primaryBitmap->GetWidth(), primaryBitmap->GetHeight());
graphics.SetClip(&primaryPath);
graphics.DrawImage(primaryBitmap, r, 0, 0, r.Width, r.Height, UnitPixel);
graphics.ResetClip();
}
else
{
SolidBrush brush(m_PrimaryColor);
graphics.FillPath(&brush, &primaryPath);
}
2012-07-17 07:37:53 +00:00
if (secondaryMeasure)
{
if (secondaryBitmap)
{
Rect r(meterRect.X, meterRect.Y, secondaryBitmap->GetWidth(), secondaryBitmap->GetHeight());
graphics.SetClip(&secondaryPath);
graphics.DrawImage(secondaryBitmap, r, 0, 0, r.Width, r.Height, UnitPixel);
graphics.ResetClip();
}
else
{
SolidBrush brush(m_SecondaryColor);
graphics.FillPath(&brush, &secondaryPath);
}
if (bothBitmap)
{
Rect r(meterRect.X, meterRect.Y, bothBitmap->GetWidth(), bothBitmap->GetHeight());
graphics.SetClip(&bothPath);
graphics.DrawImage(bothBitmap, r, 0, 0, r.Width, r.Height, UnitPixel);
graphics.ResetClip();
}
else
{
2012-05-20 17:57:12 +00:00
SolidBrush brush(m_OverlapColor);
graphics.FillPath(&brush, &bothPath);
}
}
2013-03-25 15:42:18 +00:00
canvas.EndGdiplusContext();
2009-02-10 18:37:48 +00:00
return true;
}
/*
** Overwritten method to handle the secondary measure binding.
**
*/
2013-05-31 14:18:52 +00:00
void MeterHistogram::BindMeasures(ConfigParser& parser, const WCHAR* section)
2009-02-10 18:37:48 +00:00
{
2012-07-17 19:07:57 +00:00
if (BindPrimaryMeasure(parser, section, false))
2009-02-10 18:37:48 +00:00
{
2012-07-17 07:37:53 +00:00
const std::wstring* secondaryMeasure = &parser.ReadString(section, L"MeasureName2", L"");
if (secondaryMeasure->empty())
2009-02-10 18:37:48 +00:00
{
2012-07-17 07:37:53 +00:00
// For backwards compatibility.
secondaryMeasure = &parser.ReadString(section, L"SecondaryMeasureName", L"");
2009-02-10 18:37:48 +00:00
}
2013-05-31 14:18:52 +00:00
Measure* measure = parser.GetMeasure(*secondaryMeasure);
2012-07-17 07:37:53 +00:00
if (measure)
{
m_Measures.push_back(measure);
}
2009-02-10 18:37:48 +00:00
}
}