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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
using namespace Gdiplus;
|
|
|
|
|
|
|
|
extern CRainmeter* Rainmeter;
|
|
|
|
|
2011-02-07 09:38:27 +00:00
|
|
|
CTintedImageHelper_DefineConfigArray(CMeterHistogram::c_PrimaryConfigArray, L"Primary");
|
|
|
|
CTintedImageHelper_DefineConfigArray(CMeterHistogram::c_SecondaryConfigArray, L"Secondary");
|
|
|
|
CTintedImageHelper_DefineConfigArray(CMeterHistogram::c_BothConfigArray, L"Both");
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
** CMeterHistogram
|
|
|
|
**
|
|
|
|
** The constructor
|
|
|
|
**
|
|
|
|
*/
|
2011-02-15 16:26:54 +00:00
|
|
|
CMeterHistogram::CMeterHistogram(CMeterWindow* meterWindow, const WCHAR* name) : CMeter(meterWindow, name),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_SecondaryMeasure(),
|
2010-11-11 20:24:59 +00:00
|
|
|
m_PrimaryColor(Color::Green),
|
|
|
|
m_SecondaryColor(Color::Red),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_BothColor(Color::Yellow),
|
|
|
|
m_MeterPos(),
|
|
|
|
m_Autoscale(false),
|
|
|
|
m_Flip(false),
|
2011-02-07 09:38:27 +00:00
|
|
|
m_PrimaryImage(L"PrimaryImage", c_PrimaryConfigArray),
|
|
|
|
m_SecondaryImage(L"SecondaryImage", c_SecondaryConfigArray),
|
|
|
|
m_BothImage(L"BothImage", c_BothConfigArray),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_PrimaryNeedsReload(false),
|
|
|
|
m_SecondaryNeedsReload(false),
|
|
|
|
m_BothNeedsReload(false),
|
|
|
|
m_PrimaryValues(),
|
|
|
|
m_SecondaryValues(),
|
|
|
|
m_MaxPrimaryValue(1.0),
|
|
|
|
m_MinPrimaryValue(),
|
|
|
|
m_MaxSecondaryValue(1.0),
|
|
|
|
m_MinSecondaryValue(),
|
|
|
|
m_WidthChanged(true)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ~CMeterHistogram
|
|
|
|
**
|
|
|
|
** The destructor
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
CMeterHistogram::~CMeterHistogram()
|
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
DisposeBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** DisposeBuffer
|
|
|
|
**
|
|
|
|
** Disposes the buffers.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CMeterHistogram::DisposeBuffer()
|
|
|
|
{
|
|
|
|
// Reset current position
|
|
|
|
m_MeterPos = 0;
|
|
|
|
|
|
|
|
// Delete buffers
|
2011-11-08 10:32:57 +00:00
|
|
|
delete [] m_PrimaryValues;
|
|
|
|
m_PrimaryValues = NULL;
|
|
|
|
|
|
|
|
delete [] m_SecondaryValues;
|
|
|
|
m_SecondaryValues = NULL;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Initialize
|
|
|
|
**
|
|
|
|
** Load the images and calculate the dimensions of the meter from them.
|
|
|
|
** Or create the brushes if solid color histogram is used.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CMeterHistogram::Initialize()
|
|
|
|
{
|
|
|
|
CMeter::Initialize();
|
|
|
|
|
2010-11-26 20:22:13 +00:00
|
|
|
// A sanity check
|
|
|
|
if (m_SecondaryMeasure && !m_PrimaryImageName.empty() && (m_BothImageName.empty() || m_SecondaryImageName.empty()))
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-09-09 16:31:55 +00:00
|
|
|
Log(LOG_WARNING, 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();
|
|
|
|
m_BothImage.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
|
|
|
{
|
|
|
|
int oldW = m_W;
|
|
|
|
|
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
|
|
|
|
2010-11-26 20:22:13 +00:00
|
|
|
if (oldW != m_W)
|
|
|
|
{
|
|
|
|
m_WidthChanged = true;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
if (!m_BothImageName.empty())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
m_BothImage.LoadImage(m_BothImageName, m_BothNeedsReload);
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
2010-11-27 19:53:23 +00:00
|
|
|
else if (m_BothImage.IsLoaded())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
m_BothImage.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()) ||
|
|
|
|
(!m_BothImageName.empty() && !m_BothImage.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
|
|
|
|
|
|
|
m_WidthChanged = false;
|
|
|
|
}
|
|
|
|
else if (m_WidthChanged)
|
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
DisposeBuffer();
|
2010-06-08 23:09:18 +00:00
|
|
|
|
2010-06-03 14:14:53 +00:00
|
|
|
// Create buffers for values
|
2010-06-08 23:09:18 +00:00
|
|
|
if (m_W > 0)
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2010-06-08 23:09:18 +00:00
|
|
|
m_PrimaryValues = new double[m_W];
|
|
|
|
memset(m_PrimaryValues, 0, sizeof(double) * m_W);
|
|
|
|
if (m_SecondaryMeasure)
|
|
|
|
{
|
|
|
|
m_SecondaryValues = new double[m_W];
|
|
|
|
memset(m_SecondaryValues, 0, sizeof(double) * m_W);
|
|
|
|
}
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_WidthChanged = false;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ReadConfig
|
|
|
|
**
|
|
|
|
** Read the meter-specific configs from the ini-file.
|
|
|
|
**
|
|
|
|
*/
|
2011-02-15 16:26:54 +00:00
|
|
|
void CMeterHistogram::ReadConfig(CConfigParser& 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;
|
|
|
|
std::wstring oldBothImageName = m_BothImageName;
|
|
|
|
int oldW = m_W;
|
|
|
|
int oldH = m_H;
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
// Read common configs
|
2011-02-15 16:26:54 +00:00
|
|
|
CMeter::ReadConfig(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);
|
|
|
|
m_BothColor = parser.ReadColor(section, L"BothColor", Color::Yellow);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-12-04 15:07:28 +00:00
|
|
|
if (!m_Initialized && !m_MeasureName.empty())
|
2010-08-10 15:37:35 +00:00
|
|
|
{
|
2010-12-04 15:07:28 +00:00
|
|
|
m_SecondaryMeasureName = parser.ReadString(section, L"MeasureName2", L"");
|
|
|
|
if (m_SecondaryMeasureName.empty())
|
|
|
|
{
|
|
|
|
m_SecondaryMeasureName = parser.ReadString(section, L"SecondaryMeasureName", L"");
|
|
|
|
}
|
2010-08-10 15:37:35 +00:00
|
|
|
}
|
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())
|
|
|
|
{
|
2011-11-28 14:13:20 +00:00
|
|
|
m_MeterWindow->MakePathAbsolute(m_PrimaryImageName);
|
2010-11-27 19:53:23 +00:00
|
|
|
|
|
|
|
// Read tinting configs
|
|
|
|
m_PrimaryImage.ReadConfig(parser, section);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_PrimaryImage.ClearConfigFlags();
|
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())
|
|
|
|
{
|
2011-11-28 14:13:20 +00:00
|
|
|
m_MeterWindow->MakePathAbsolute(m_SecondaryImageName);
|
2010-11-27 19:53:23 +00:00
|
|
|
|
|
|
|
// Read tinting configs
|
|
|
|
m_SecondaryImage.ReadConfig(parser, section);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_SecondaryImage.ClearConfigFlags();
|
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_BothImageName = parser.ReadString(section, L"BothImage", L"");
|
2010-11-25 22:00:34 +00:00
|
|
|
if (!m_BothImageName.empty())
|
|
|
|
{
|
2011-11-28 14:13:20 +00:00
|
|
|
m_MeterWindow->MakePathAbsolute(m_BothImageName);
|
2010-11-27 19:53:23 +00:00
|
|
|
|
|
|
|
// Read tinting configs
|
|
|
|
m_BothImage.ReadConfig(parser, section);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_BothImage.ClearConfigFlags();
|
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
|
|
|
|
|
|
|
if (m_Initialized)
|
|
|
|
{
|
|
|
|
if (m_PrimaryImageName.empty())
|
|
|
|
{
|
|
|
|
if (oldW != m_W)
|
|
|
|
{
|
|
|
|
m_WidthChanged = true;
|
|
|
|
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);
|
|
|
|
m_BothNeedsReload = (wcscmp(oldBothImageName.c_str(), m_BothImageName.c_str()) != 0);
|
2010-11-27 19:53:23 +00:00
|
|
|
|
|
|
|
if (m_PrimaryNeedsReload ||
|
|
|
|
m_SecondaryNeedsReload ||
|
|
|
|
m_BothNeedsReload ||
|
|
|
|
m_PrimaryImage.IsConfigsChanged() ||
|
|
|
|
m_SecondaryImage.IsConfigsChanged() ||
|
|
|
|
m_BothImage.IsConfigsChanged())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
|
|
|
Initialize(); // Reload the image
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Update
|
|
|
|
**
|
|
|
|
** Updates the value(s) from the measures.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
bool CMeterHistogram::Update()
|
|
|
|
{
|
2010-06-03 14:14:53 +00:00
|
|
|
if (CMeter::Update() && m_Measure && m_PrimaryValues)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
// Gather values
|
|
|
|
m_PrimaryValues[m_MeterPos] = m_Measure->GetValue();
|
|
|
|
|
2010-06-03 14:14:53 +00:00
|
|
|
if (m_SecondaryMeasure && m_SecondaryValues)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_SecondaryValues[m_MeterPos] = m_SecondaryMeasure->GetValue();
|
|
|
|
}
|
|
|
|
|
2010-03-30 22:37:05 +00:00
|
|
|
++m_MeterPos;
|
2009-02-10 18:37:48 +00:00
|
|
|
m_MeterPos %= m_W;
|
|
|
|
|
|
|
|
m_MaxPrimaryValue = m_Measure->GetMaxValue();
|
|
|
|
m_MinPrimaryValue = m_Measure->GetMinValue();
|
2010-11-27 19:53:23 +00:00
|
|
|
m_MaxSecondaryValue = 0.0;
|
|
|
|
m_MinSecondaryValue = 0.0;
|
2009-02-10 18:37:48 +00:00
|
|
|
if (m_SecondaryMeasure)
|
|
|
|
{
|
|
|
|
m_MaxSecondaryValue = m_SecondaryMeasure->GetMaxValue();
|
|
|
|
m_MinSecondaryValue = m_SecondaryMeasure->GetMinValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Autoscale)
|
|
|
|
{
|
|
|
|
// Go through all values and find the max
|
|
|
|
|
2010-11-26 20:22:13 +00:00
|
|
|
double newValue = 0.0;
|
2010-11-11 20:24:59 +00:00
|
|
|
for (int i = 0; i < m_W; ++i)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
newValue = max(newValue, m_PrimaryValues[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2010-11-11 20:24:59 +00:00
|
|
|
m_MaxPrimaryValue = DBL_MAX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_MaxPrimaryValue = 2.0;
|
|
|
|
while (m_MaxPrimaryValue < newValue)
|
|
|
|
{
|
|
|
|
m_MaxPrimaryValue *= 2.0;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 14:14:53 +00:00
|
|
|
if (m_SecondaryMeasure && m_SecondaryValues)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-11-11 20:24:59 +00:00
|
|
|
for (int i = 0; i < m_W; ++i)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
newValue = max(newValue, m_SecondaryValues[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2010-11-11 20:24:59 +00:00
|
|
|
m_MaxSecondaryValue = DBL_MAX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_MaxSecondaryValue = 2.0;
|
|
|
|
while (m_MaxSecondaryValue < newValue)
|
|
|
|
{
|
|
|
|
m_MaxSecondaryValue *= 2.0;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Draw
|
|
|
|
**
|
|
|
|
** Draws the meter on the double buffer
|
|
|
|
**
|
|
|
|
*/
|
2009-07-27 11:48:57 +00:00
|
|
|
bool CMeterHistogram::Draw(Graphics& graphics)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
if (!CMeter::Draw(graphics) ||
|
2010-06-03 14:14:53 +00:00
|
|
|
(m_Measure && !m_PrimaryValues) ||
|
|
|
|
(m_SecondaryMeasure && !m_SecondaryValues)) return false;
|
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();
|
|
|
|
Bitmap* bothBitmap = m_BothImage.GetImage();
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
int x = GetX();
|
|
|
|
int y = GetY();
|
|
|
|
|
2010-03-30 22:37:05 +00:00
|
|
|
for (int i = 0; i < m_W; ++i)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
double value = (m_MaxPrimaryValue == 0.0) ?
|
|
|
|
0.0
|
|
|
|
: m_PrimaryValues[(i + m_MeterPos) % m_W] / m_MaxPrimaryValue;
|
2009-02-10 18:37:48 +00:00
|
|
|
value -= m_MinPrimaryValue;
|
|
|
|
int primaryBarHeight = (int)(m_H * value);
|
|
|
|
primaryBarHeight = min(m_H, primaryBarHeight);
|
|
|
|
primaryBarHeight = max(0, primaryBarHeight);
|
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
if (m_SecondaryMeasure)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
value = (m_MaxSecondaryValue == 0.0) ?
|
|
|
|
0.0
|
|
|
|
: m_SecondaryValues[(i + m_MeterPos) % m_W] / m_MaxSecondaryValue;
|
2009-02-10 18:37:48 +00:00
|
|
|
value -= m_MinSecondaryValue;
|
|
|
|
int secondaryBarHeight = (int)(m_H * value);
|
|
|
|
secondaryBarHeight = min(m_H, secondaryBarHeight);
|
|
|
|
secondaryBarHeight = max(0, secondaryBarHeight);
|
|
|
|
|
|
|
|
// Check which measured value is higher
|
2010-11-11 20:24:59 +00:00
|
|
|
int bothBarHeight = min(primaryBarHeight, secondaryBarHeight);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
// Cache image/color rectangle for the both lines
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
Rect& r = (m_Flip) ?
|
2010-11-27 20:54:21 +00:00
|
|
|
Rect(x + i, y, 1, bothBarHeight)
|
2010-11-26 20:22:13 +00:00
|
|
|
: Rect(x + i, y + m_H - bothBarHeight, 1, bothBarHeight);
|
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
bothPath.AddRectangle(r); // cache
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
// Cache the image/color rectangle for the rest
|
2009-02-10 18:37:48 +00:00
|
|
|
if (secondaryBarHeight > primaryBarHeight)
|
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
Rect& r = (m_Flip) ?
|
2010-11-27 20:54:21 +00:00
|
|
|
Rect(x + i, y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight)
|
2010-11-26 20:22:13 +00:00
|
|
|
: Rect(x + i, y + m_H - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight);
|
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
secondaryPath.AddRectangle(r); // cache
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
Rect& r = (m_Flip) ?
|
2010-11-27 20:54:21 +00:00
|
|
|
Rect(x + i, y + bothBarHeight, 1, primaryBarHeight - bothBarHeight)
|
2010-11-26 20:22:13 +00:00
|
|
|
: Rect(x + i, y + m_H - primaryBarHeight, 1, primaryBarHeight - bothBarHeight);
|
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
primaryPath.AddRectangle(r); // cache
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-26 20:22:13 +00:00
|
|
|
Rect& r = (m_Flip) ?
|
2010-11-27 20:54:21 +00:00
|
|
|
Rect(x + i, y, 1, primaryBarHeight)
|
2010-11-26 20:22:13 +00:00
|
|
|
: Rect(x + i, y + m_H - primaryBarHeight, 1, primaryBarHeight);
|
|
|
|
|
2010-11-27 19:53:23 +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);
|
|
|
|
}
|
|
|
|
if (m_SecondaryMeasure)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
SolidBrush brush(m_BothColor);
|
|
|
|
graphics.FillPath(&brush, &bothPath);
|
|
|
|
}
|
2010-11-26 20:22:13 +00:00
|
|
|
}
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** BindMeasure
|
|
|
|
**
|
|
|
|
** Overwritten method to handle the secondary measure binding.
|
|
|
|
**
|
|
|
|
*/
|
2010-11-19 07:33:58 +00:00
|
|
|
void CMeterHistogram::BindMeasure(const std::list<CMeasure*>& measures)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
CMeter::BindMeasure(measures);
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
if (!m_SecondaryMeasureName.empty())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
// Go through the list and check it there is a secondary measure for us
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* name = m_SecondaryMeasureName.c_str();
|
2010-03-30 22:37:05 +00:00
|
|
|
std::list<CMeasure*>::const_iterator i = measures.begin();
|
2011-03-29 19:21:57 +00:00
|
|
|
for ( ; i != measures.end(); ++i)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-11-16 16:47:20 +00:00
|
|
|
if (_wcsicmp((*i)->GetName(), name) == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_SecondaryMeasure = (*i);
|
2010-09-10 17:29:30 +00:00
|
|
|
CMeter::SetAllMeasures(m_SecondaryMeasure);
|
2009-02-10 18:37:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-25 22:00:34 +00:00
|
|
|
std::wstring error = L"The meter [" + m_Name;
|
2010-11-25 15:34:49 +00:00
|
|
|
error += L"] cannot be bound with [";
|
|
|
|
error += m_SecondaryMeasureName;
|
2011-12-04 22:18:40 +00:00
|
|
|
error += L']';
|
2011-11-09 09:27:06 +00:00
|
|
|
throw CError(error);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|