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
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-10 18:37:48 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-07 16:45:14 +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
|
|
|
extern Rainmeter* g_Rainmeter;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
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),
|
2010-11-11 20:24:59 +00:00
|
|
|
m_PrimaryColor(Color::Green),
|
|
|
|
m_SecondaryColor(Color::Red),
|
2012-05-20 17:57:12 +00:00
|
|
|
m_OverlapColor(Color::Yellow),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_MeterPos(),
|
|
|
|
m_Autoscale(false),
|
|
|
|
m_Flip(false),
|
2013-06-07 19:35:36 +00:00
|
|
|
m_PrimaryImage(L"PrimaryImage", c_PrimaryOptionArray, false, meterWindow),
|
|
|
|
m_SecondaryImage(L"SecondaryImage", c_SecondaryOptionArray, false, meterWindow),
|
|
|
|
m_OverlapImage(L"BothImage", c_BothOptionArray, false, meterWindow),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_PrimaryNeedsReload(false),
|
|
|
|
m_SecondaryNeedsReload(false),
|
2012-05-20 17:57:12 +00:00
|
|
|
m_OverlapNeedsReload(false),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_PrimaryValues(),
|
|
|
|
m_SecondaryValues(),
|
|
|
|
m_MaxPrimaryValue(1.0),
|
|
|
|
m_MinPrimaryValue(),
|
|
|
|
m_MaxSecondaryValue(1.0),
|
|
|
|
m_MinSecondaryValue(),
|
2012-05-11 16:48:03 +00:00
|
|
|
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
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
DisposeBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Disposes the buffers.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void MeterHistogram::DisposeBuffer()
|
2010-11-26 20:22:13 +00:00
|
|
|
{
|
|
|
|
// Reset current position
|
|
|
|
m_MeterPos = 0;
|
|
|
|
|
|
|
|
// Delete buffers
|
2011-11-08 10:32:57 +00:00
|
|
|
delete [] m_PrimaryValues;
|
2013-05-31 14:28:39 +00:00
|
|
|
m_PrimaryValues = nullptr;
|
2011-11-08 10:32:57 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2010-11-26 20:22:13 +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
|
|
|
{
|
2013-05-30 14:19:42 +00:00
|
|
|
LogWarning(L"Histogram: SecondaryImage and BothImage not defined");
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
m_PrimaryImage.DisposeImage();
|
|
|
|
m_SecondaryImage.DisposeImage();
|
2012-05-20 17:57:12 +00:00
|
|
|
m_OverlapImage.DisposeImage();
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
// Load the bitmaps if defined
|
2010-11-27 19:53:23 +00:00
|
|
|
if (!m_PrimaryImageName.empty())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
m_PrimaryImage.LoadImage(m_PrimaryImageName, m_PrimaryNeedsReload);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
if (m_PrimaryImage.IsLoaded())
|
2010-11-26 20:22:13 +00:00
|
|
|
{
|
2012-12-22 22:05:46 +00:00
|
|
|
int oldSize = m_GraphHorizontalOrientation ? m_H : m_W;
|
2010-11-26 20:22:13 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
Bitmap* bitmap = m_PrimaryImage.GetImage();
|
|
|
|
|
|
|
|
m_W = bitmap->GetWidth();
|
|
|
|
m_H = bitmap->GetHeight();
|
2010-06-03 14:14:53 +00:00
|
|
|
|
2012-12-22 22:05:46 +00:00
|
|
|
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
|
|
|
|
if (oldSize != maxSize)
|
2010-11-26 20:22:13 +00:00
|
|
|
{
|
2012-05-11 16:48:03 +00:00
|
|
|
m_SizeChanged = true;
|
2010-11-26 20:22:13 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
2010-11-27 19:53:23 +00:00
|
|
|
else if (m_PrimaryImage.IsLoaded())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
m_PrimaryImage.DisposeImage();
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
if (!m_SecondaryImageName.empty())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
m_SecondaryImage.LoadImage(m_SecondaryImageName, m_SecondaryNeedsReload);
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
2010-11-27 19:53:23 +00:00
|
|
|
else if (m_SecondaryImage.IsLoaded())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
m_SecondaryImage.DisposeImage();
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2012-05-20 17:57:12 +00:00
|
|
|
if (!m_OverlapImageName.empty())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2012-05-20 17:57:12 +00:00
|
|
|
m_OverlapImage.LoadImage(m_OverlapImageName, m_OverlapNeedsReload);
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
2012-05-20 17:57:12 +00:00
|
|
|
else if (m_OverlapImage.IsLoaded())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2012-05-20 17:57:12 +00:00
|
|
|
m_OverlapImage.DisposeImage();
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 19:53:23 +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
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
DisposeBuffer();
|
2010-06-03 14:14:53 +00:00
|
|
|
|
2012-05-11 16:48:03 +00:00
|
|
|
m_SizeChanged = false;
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
2012-05-11 16:48:03 +00:00
|
|
|
else if (m_SizeChanged)
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2012-12-22 22:05:46 +00:00
|
|
|
CreateBuffer();
|
2010-06-03 14:14:53 +00:00
|
|
|
|
2012-05-11 16:48:03 +00:00
|
|
|
m_SizeChanged = false;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-06-01 13:06:36 +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
|
|
|
{
|
2010-06-03 14:14:53 +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;
|
2010-06-03 14:14:53 +00:00
|
|
|
int oldW = m_W;
|
|
|
|
int oldH = m_H;
|
2012-12-22 22:05:46 +00:00
|
|
|
bool oldGraphHorizontalOrientation = m_GraphHorizontalOrientation;
|
2010-06-03 14:14:53 +00:00
|
|
|
|
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())
|
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
// Read tinting options
|
2012-05-30 18:53:44 +00:00
|
|
|
m_PrimaryImage.ReadOptions(parser, section);
|
2010-11-27 19:53:23 +00:00
|
|
|
}
|
|
|
|
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())
|
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
// Read tinting options
|
2012-05-30 18:53:44 +00:00
|
|
|
m_SecondaryImage.ReadOptions(parser, section);
|
2010-11-27 19:53:23 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
// Read tinting options
|
2012-05-30 18:53:44 +00:00
|
|
|
m_OverlapImage.ReadOptions(parser, section);
|
2010-11-27 19:53:23 +00:00
|
|
|
}
|
|
|
|
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);
|
2010-06-03 14:14:53 +00:00
|
|
|
|
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
|
|
|
|
{
|
2013-05-30 14:19:42 +00:00
|
|
|
LogErrorF(L"GraphStart=%s is not valid in [%s]", graph, m_Name.c_str());
|
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
|
|
|
|
{
|
2013-05-30 14:19:42 +00:00
|
|
|
LogErrorF(L"GraphOrientation=%s is not valid in [%s]", graph, m_Name.c_str());
|
2012-12-22 22:05:46 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 14:14:53 +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)
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2012-05-11 16:48:03 +00:00
|
|
|
m_SizeChanged = true;
|
2010-06-03 14:14:53 +00:00
|
|
|
Initialize(); // Reload the image
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Reset to old dimensions
|
|
|
|
m_W = oldW;
|
|
|
|
m_H = oldH;
|
|
|
|
|
2011-11-27 08:30:39 +00:00
|
|
|
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);
|
2010-11-27 19:53:23 +00:00
|
|
|
|
|
|
|
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())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
|
|
|
Initialize(); // Reload the image
|
|
|
|
}
|
2012-12-22 22:05:46 +00:00
|
|
|
else if (m_SizeChanged)
|
2012-05-11 16:48:03 +00:00
|
|
|
{
|
2012-12-22 22:05:46 +00:00
|
|
|
CreateBuffer();
|
2012-05-11 16:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2012-05-11 16:48:03 +00:00
|
|
|
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-06-07 19:35:36 +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;
|
2012-05-11 16:48:03 +00:00
|
|
|
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
|
2010-11-11 20:24:59 +00:00
|
|
|
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;
|
2010-11-11 20:24:59 +00:00
|
|
|
}
|
|
|
|
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
|
2010-11-11 20:24:59 +00:00
|
|
|
{
|
2012-12-22 22:05:46 +00:00
|
|
|
m_MaxSecondaryValue = 2.0;
|
|
|
|
while (m_MaxSecondaryValue < newValue)
|
|
|
|
{
|
|
|
|
m_MaxSecondaryValue *= 2.0;
|
|
|
|
}
|
2010-11-11 20:24:59 +00:00
|
|
|
}
|
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
|
|
|
|
2010-11-26 20:22:13 +00:00
|
|
|
GraphicsPath primaryPath;
|
|
|
|
GraphicsPath secondaryPath;
|
|
|
|
GraphicsPath bothPath;
|
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
Bitmap* primaryBitmap = m_PrimaryImage.GetImage();
|
|
|
|
Bitmap* secondaryBitmap = m_SecondaryImage.GetImage();
|
2012-05-20 17:57:12 +00:00
|
|
|
Bitmap* bothBitmap = m_OverlapImage.GetImage();
|
2010-11-27 19:53:23 +00:00
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
int x = GetX();
|
|
|
|
int y = GetY();
|
|
|
|
|
2012-05-11 16:48:03 +00:00
|
|
|
// 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
|
2012-12-27 07:47:44 +00:00
|
|
|
if (!m_GraphHorizontalOrientation)
|
2012-05-11 16:48:03 +00:00
|
|
|
{
|
2012-12-27 07:47:44 +00:00
|
|
|
if (m_GraphStartLeft)
|
|
|
|
{
|
|
|
|
startValue = m_W - 1;
|
|
|
|
endValueLHS = &endValue;
|
|
|
|
endValueRHS = &i;
|
|
|
|
step = -1;
|
|
|
|
}
|
2012-05-11 16:48:03 +00:00
|
|
|
}
|
2012-12-27 07:47:44 +00:00
|
|
|
else
|
2012-05-11 16:48:03 +00:00
|
|
|
{
|
2012-12-27 07:47:44 +00:00
|
|
|
if (!m_Flip)
|
|
|
|
{
|
|
|
|
endValueRHS = &m_H;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
startValue = m_H - 1;
|
|
|
|
endValueLHS = &endValue;
|
|
|
|
endValueRHS = &i;
|
|
|
|
step = -1;
|
|
|
|
}
|
2012-05-11 16:48:03 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-05-11 16:48:03 +00:00
|
|
|
// Horizontal or Vertical graph
|
|
|
|
if (m_GraphHorizontalOrientation)
|
|
|
|
{
|
|
|
|
for (i = startValue; *endValueLHS < *endValueRHS; i += step)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-11 16:48:03 +00:00
|
|
|
double value = (m_MaxPrimaryValue == 0.0) ?
|
2010-11-26 20:22:13 +00:00
|
|
|
0.0
|
2012-05-11 16:48:03 +00:00
|
|
|
: 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);
|
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
|
|
|
{
|
2012-05-11 16:48:03 +00:00
|
|
|
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);
|
2010-11-26 20:22:13 +00:00
|
|
|
|
2012-05-11 16:48:03 +00:00
|
|
|
bothPath.AddRectangle(r); // cache
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-05-11 16:48:03 +00:00
|
|
|
// 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);
|
2010-11-26 20:22:13 +00:00
|
|
|
|
2012-05-11 16:48:03 +00:00
|
|
|
primaryPath.AddRectangle(r); // cache
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-11 16:48:03 +00:00
|
|
|
Rect& r = m_GraphStartLeft ?
|
|
|
|
Rect(x, y + startValue + (step * i), primaryBarHeight, 1)
|
|
|
|
: Rect(x + m_W - primaryBarHeight, y + startValue + (step * i), primaryBarHeight, 1);
|
2010-11-26 20:22:13 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
primaryPath.AddRectangle(r); // cache
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-11 16:48:03 +00:00
|
|
|
}
|
|
|
|
else // GraphOrientation=Vertical
|
|
|
|
{
|
|
|
|
for (i = startValue; *endValueLHS < *endValueRHS; i += step)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-11 16:48:03 +00:00
|
|
|
double value = (m_MaxPrimaryValue == 0.0) ?
|
|
|
|
0.0
|
|
|
|
: 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);
|
|
|
|
|
2012-07-17 07:37:53 +00:00
|
|
|
if (secondaryMeasure)
|
2012-05-11 16:48:03 +00:00
|
|
|
{
|
|
|
|
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);
|
2010-11-26 20:22:13 +00:00
|
|
|
|
2012-05-11 16:48:03 +00:00
|
|
|
primaryPath.AddRectangle(r); // cache
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-26 20:22:13 +00:00
|
|
|
// Draw cached rectangles
|
2010-11-27 19:53:23 +00:00
|
|
|
if (primaryBitmap)
|
2010-11-26 20:22:13 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
Rect r(x, 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)
|
2010-11-27 19:53:23 +00:00
|
|
|
{
|
|
|
|
if (secondaryBitmap)
|
2010-11-26 20:22:13 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
Rect r(x, y, secondaryBitmap->GetWidth(), secondaryBitmap->GetHeight());
|
|
|
|
|
|
|
|
graphics.SetClip(&secondaryPath);
|
|
|
|
graphics.DrawImage(secondaryBitmap, r, 0, 0, r.Width, r.Height, UnitPixel);
|
|
|
|
graphics.ResetClip();
|
2010-11-26 20:22:13 +00:00
|
|
|
}
|
2010-11-27 19:53:23 +00:00
|
|
|
else
|
2010-11-26 20:22:13 +00:00
|
|
|
{
|
|
|
|
SolidBrush brush(m_SecondaryColor);
|
|
|
|
graphics.FillPath(&brush, &secondaryPath);
|
|
|
|
}
|
2010-11-27 19:53:23 +00:00
|
|
|
if (bothBitmap)
|
|
|
|
{
|
|
|
|
Rect r(x, 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);
|
2010-11-27 19:53:23 +00:00
|
|
|
graphics.FillPath(&brush, &bothPath);
|
|
|
|
}
|
2010-11-26 20:22:13 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|