rainmeter-studio/Library/Meter.cpp

729 lines
17 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 "Error.h"
#include "Meter.h"
#include "MeterBitmap.h"
#include "MeterBar.h"
#include "MeterHistogram.h"
#include "MeterString.h"
#include "MeterImage.h"
#include "MeterLine.h"
#include "MeterRoundLine.h"
#include "MeterRotator.h"
#include "MeterButton.h"
#include "Measure.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;
/*
** The constructor
**
*/
2013-05-31 14:18:52 +00:00
Meter::Meter(MeterWindow* meterWindow, const WCHAR* name) : Section(meterWindow, name),
m_X(),
m_Y(),
m_W(0),
m_H(0),
m_Hidden(false),
2011-11-01 04:56:46 +00:00
m_WDefined(false),
m_HDefined(false),
m_RelativeMeter(),
2011-11-04 12:48:03 +00:00
m_Transformation(),
m_ToolTipWidth(),
m_ToolTipType(false),
m_ToolTipHidden(meterWindow->GetMeterToolTipHidden()),
m_ToolTipHandle(),
2013-01-16 10:23:42 +00:00
m_Mouse(meterWindow, this),
m_HasMouseAction(false),
m_MouseOver(false),
m_RelativeX(POSITION_ABSOLUTE),
m_RelativeY(POSITION_ABSOLUTE),
m_SolidBevel(BEVELTYPE_NONE),
m_SolidAngle(),
m_AntiAlias(false),
m_Initialized(false)
2009-02-10 18:37:48 +00:00
{
}
/*
** The destructor
**
*/
2013-05-31 14:18:52 +00:00
Meter::~Meter()
2009-02-10 18:37:48 +00:00
{
2011-11-04 12:48:03 +00:00
delete m_Transformation;
2013-05-31 14:28:39 +00:00
if (m_ToolTipHandle != nullptr)
2010-10-19 22:03:32 +00:00
{
DestroyWindow(m_ToolTipHandle);
}
2009-02-10 18:37:48 +00:00
}
/*
2012-07-17 14:47:34 +00:00
** Initializes the meter. Usually this method is overwritten by the inherited
** classes, which load bitmaps and such things during initialization.
2009-02-10 18:37:48 +00:00
**
*/
2013-05-31 14:18:52 +00:00
void Meter::Initialize()
2009-02-10 18:37:48 +00:00
{
m_Initialized = true;
2009-02-10 18:37:48 +00:00
}
/*
** Returns the X-position of the meter.
**
*/
2013-05-31 14:18:52 +00:00
int Meter::GetX(bool abs)
2009-02-10 18:37:48 +00:00
{
2012-07-17 14:47:34 +00:00
if (m_RelativeX != POSITION_ABSOLUTE && m_RelativeMeter)
2009-02-10 18:37:48 +00:00
{
2012-07-17 14:47:34 +00:00
if (m_RelativeX == POSITION_RELATIVE_TL)
2009-02-10 18:37:48 +00:00
{
2012-07-17 14:47:34 +00:00
return m_RelativeMeter->GetX(true) + m_X;
2009-02-10 18:37:48 +00:00
}
else
{
2012-07-17 14:47:34 +00:00
return m_RelativeMeter->GetX(true) + m_RelativeMeter->GetW() + m_X;
2009-02-10 18:37:48 +00:00
}
}
2011-03-29 19:21:57 +00:00
return m_X;
2009-02-10 18:37:48 +00:00
}
/*
** Returns the Y-position of the meter.
**
*/
2013-05-31 14:18:52 +00:00
int Meter::GetY(bool abs)
2009-02-10 18:37:48 +00:00
{
2012-07-17 14:47:34 +00:00
if (m_RelativeY != POSITION_ABSOLUTE && m_RelativeMeter)
2009-02-10 18:37:48 +00:00
{
2012-07-17 14:47:34 +00:00
if (m_RelativeY == POSITION_RELATIVE_TL)
2009-02-10 18:37:48 +00:00
{
return m_RelativeMeter->GetY(true) + m_Y;
2009-02-10 18:37:48 +00:00
}
else
{
return m_RelativeMeter->GetY(true) + m_RelativeMeter->GetH() + m_Y;
2009-02-10 18:37:48 +00:00
}
}
2011-03-29 19:21:57 +00:00
return m_Y;
2009-02-10 18:37:48 +00:00
}
2013-05-31 14:18:52 +00:00
void Meter::SetX(int x)
{
m_X = x;
m_RelativeX = POSITION_ABSOLUTE;
// Change the option as well to avoid reset in ReadOptions().
WCHAR buffer[32];
_itow_s(x, buffer, 10);
m_MeterWindow->GetParser().SetValue(m_Name, L"X", buffer);
}
2013-05-31 14:18:52 +00:00
void Meter::SetY(int y)
{
m_Y = y;
m_RelativeY = POSITION_ABSOLUTE;
// Change the option as well to avoid reset in ReadOptions().
WCHAR buffer[32];
_itow_s(y, buffer, 10);
m_MeterWindow->GetParser().SetValue(m_Name, L"Y", buffer);
}
/*
** Returns a RECT containing the dimensions of the meter within the MeterWindow
**
*/
2013-05-31 14:18:52 +00:00
RECT Meter::GetMeterRect()
{
RECT meterRect;
meterRect.left = GetX();
meterRect.top = GetY();
2010-10-19 22:03:32 +00:00
meterRect.right = meterRect.left + m_W;
meterRect.bottom = meterRect.top + m_H;
return meterRect;
}
2009-02-10 18:37:48 +00:00
/*
** Checks if the given point is inside the meter.
2013-02-06 10:12:16 +00:00
** This function doesn't check Hidden state, so check it before calling this function if needed.
2009-02-10 18:37:48 +00:00
**
*/
2013-05-31 14:18:52 +00:00
bool Meter::HitTest(int x, int y)
2009-02-10 18:37:48 +00:00
{
2013-02-06 10:12:16 +00:00
int p;
return (x >= (p = GetX()) && x < p + m_W && y >= (p = GetY()) && y < p + m_H);
2009-02-10 18:37:48 +00:00
}
2010-10-19 22:03:32 +00:00
/*
** Shows the meter and tooltip.
**
*/
2013-05-31 14:18:52 +00:00
void Meter::Show()
2010-10-19 22:03:32 +00:00
{
m_Hidden = false;
// Change the option as well to avoid reset in ReadOptions().
m_MeterWindow->GetParser().SetValue(m_Name, L"Hidden", L"0");
2013-05-31 14:28:39 +00:00
if (m_ToolTipHandle != nullptr)
2010-10-19 22:03:32 +00:00
{
if (!m_ToolTipHidden)
{
2013-05-31 14:28:39 +00:00
SendMessage(m_ToolTipHandle, TTM_ACTIVATE, TRUE, 0);
2010-10-19 22:03:32 +00:00
}
}
}
/*
** Hides the meter and tooltip.
**
*/
2013-05-31 14:18:52 +00:00
void Meter::Hide()
2010-10-19 22:03:32 +00:00
{
m_Hidden = true;
// Change the option as well to avoid reset in ReadOptions().
m_MeterWindow->GetParser().SetValue(m_Name, L"Hidden", L"1");
2013-05-31 14:28:39 +00:00
if (m_ToolTipHandle != nullptr)
2010-10-19 22:03:32 +00:00
{
2013-05-31 14:28:39 +00:00
SendMessage(m_ToolTipHandle, TTM_ACTIVATE, FALSE, 0);
2010-10-19 22:03:32 +00:00
}
}
2009-02-10 18:37:48 +00:00
/*
** Read the common options specified in the ini file. The inherited classes must
** call this base implementation if they overwrite this method.
2009-02-10 18:37:48 +00:00
**
*/
2013-05-31 14:18:52 +00:00
void Meter::ReadOptions(ConfigParser& parser, const WCHAR* section)
2009-02-10 18:37:48 +00:00
{
// The MeterStyle defines a template where the values are read if the meter doesn't have it itself
const std::wstring& style = parser.ReadString(section, L"MeterStyle", L"");
if (!style.empty())
{
parser.SetStyleTemplate(style);
}
2013-05-31 14:18:52 +00:00
Section::ReadOptions(parser, section);
2013-02-06 10:12:16 +00:00
BindMeasures(parser, section);
2012-07-17 19:15:06 +00:00
int oldX = m_X;
std::wstring& x = (std::wstring&)parser.ReadString(section, L"X", L"0");
if (!x.empty())
2009-02-10 18:37:48 +00:00
{
WCHAR lastChar = x[x.size() - 1];
if (lastChar == L'r')
2009-02-10 18:37:48 +00:00
{
m_RelativeX = POSITION_RELATIVE_TL;
x.pop_back();
}
else if (lastChar == L'R')
{
m_RelativeX = POSITION_RELATIVE_BR;
x.pop_back();
2009-02-10 18:37:48 +00:00
}
else
{
m_RelativeX = POSITION_ABSOLUTE;
}
m_X = parser.ParseInt(x.c_str(), 0);
}
else
{
m_X = 0;
m_RelativeX = POSITION_ABSOLUTE;
2009-02-10 18:37:48 +00:00
}
2012-07-17 19:15:06 +00:00
int oldY = m_Y;
std::wstring& y = (std::wstring&)parser.ReadString(section, L"Y", L"0");
if (!y.empty())
2009-02-10 18:37:48 +00:00
{
WCHAR lastChar = y[y.size() - 1];
if (lastChar == L'r')
2009-02-10 18:37:48 +00:00
{
m_RelativeY = POSITION_RELATIVE_TL;
y.pop_back();
}
else if (lastChar == L'R')
{
m_RelativeY = POSITION_RELATIVE_BR;
y.pop_back();
}
else
{
m_RelativeY = POSITION_ABSOLUTE;
}
m_Y = parser.ParseInt(y.c_str(), 0);
}
else
{
m_Y = 0;
m_RelativeY = POSITION_ABSOLUTE;
}
bool oldWDefined = m_WDefined;
2012-08-05 00:29:25 +00:00
int w = parser.ReadInt(section, L"W", m_W);
m_WDefined = parser.GetLastValueDefined();
2012-08-05 00:29:25 +00:00
if (IsFixedSize(true)) m_W = w;
if (!m_WDefined && oldWDefined && IsFixedSize())
{
m_W = 0;
}
2012-08-01 21:47:10 +00:00
bool oldHDefined = m_HDefined;
2012-08-05 00:29:25 +00:00
int h = parser.ReadInt(section, L"H", m_H);
2011-11-01 04:56:46 +00:00
m_HDefined = parser.GetLastValueDefined();
2012-08-05 00:29:25 +00:00
if (IsFixedSize(true)) m_H = h;
if (!m_HDefined && oldHDefined && IsFixedSize())
{
m_H = 0;
}
2012-07-17 19:15:06 +00:00
bool oldHidden = m_Hidden;
m_Hidden = 0!=parser.ReadInt(section, L"Hidden", 0);
2012-07-17 19:15:06 +00:00
if (oldX != m_X || oldY != m_Y || oldHidden != m_Hidden)
{
m_MeterWindow->SetResizeWindowMode(RESIZEMODE_CHECK); // Need to recalculate the window size
}
m_SolidBevel = (BEVELTYPE)parser.ReadInt(section, L"BevelType", BEVELTYPE_NONE);
2009-02-10 18:37:48 +00:00
2011-11-28 14:13:20 +00:00
m_SolidColor = parser.ReadColor(section, L"SolidColor", Color::MakeARGB(0, 0, 0, 0));
m_SolidColor2 = parser.ReadColor(section, L"SolidColor2", m_SolidColor.GetValue());
2009-09-04 16:37:51 +00:00
m_SolidAngle = (Gdiplus::REAL)parser.ReadFloat(section, L"GradientAngle", 0.0);
2009-02-10 18:37:48 +00:00
2013-01-16 10:23:42 +00:00
m_Mouse.ReadOptions(parser, section);
m_HasMouseAction = m_Mouse.HasButtonAction() || m_Mouse.HasScrollAction();
2011-11-03 00:13:42 +00:00
m_ToolTipText = parser.ReadString(section, L"ToolTipText", L"");
m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L"");
m_ToolTipIcon = parser.ReadString(section, L"ToolTipIcon", L"");
2013-02-06 10:12:16 +00:00
m_ToolTipWidth = parser.ReadInt(section, L"ToolTipWidth", 1000);
m_ToolTipType = 0!=parser.ReadInt(section, L"ToolTipType", 0);
m_ToolTipHidden = 0!=parser.ReadInt(section, L"ToolTipHidden", m_MeterWindow->GetMeterToolTipHidden());
2009-09-04 16:37:51 +00:00
m_AntiAlias = 0!=parser.ReadInt(section, L"AntiAlias", 0);
2009-02-10 18:37:48 +00:00
std::vector<Gdiplus::REAL> matrix = parser.ReadFloats(section, L"TransformationMatrix");
if (matrix.size() == 6)
{
2011-11-04 12:48:03 +00:00
if (m_Transformation)
{
m_Transformation->SetElements(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
}
else
{
m_Transformation = new Matrix(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
}
}
else if (!matrix.empty())
{
delete m_Transformation;
2013-05-31 14:28:39 +00:00
m_Transformation = nullptr;
2013-05-30 14:19:42 +00:00
LogErrorF(L"Meter: Incorrect number of values in TransformationMatrix=%s", parser.ReadString(section, L"TransformationMatrix", L"").c_str());
}
2009-02-10 18:37:48 +00:00
}
/*
** Binds this meter to the given measure. The same measure can be bound to
** several meters but one meter and only be bound to one measure.
**
*/
2013-05-31 14:18:52 +00:00
void Meter::BindMeasures(ConfigParser& parser, const WCHAR* section)
2009-02-10 18:37:48 +00:00
{
2012-07-17 07:37:53 +00:00
BindPrimaryMeasure(parser, section, false);
2009-02-10 18:37:48 +00:00
}
/*
** Creates the given meter. This is the factory method for the meters.
** If new meters are implemented this method needs to be updated.
**
*/
2013-05-31 14:18:52 +00:00
Meter* Meter::Create(const WCHAR* meter, MeterWindow* meterWindow, const WCHAR* name)
2009-02-10 18:37:48 +00:00
{
if (_wcsicmp(L"STRING", meter) == 0)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
return new MeterString(meterWindow, name);
2011-03-29 19:21:57 +00:00
}
else if (_wcsicmp(L"IMAGE", meter) == 0)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
return new MeterImage(meterWindow, name);
}
else if (_wcsicmp(L"HISTOGRAM", meter) == 0)
{
2013-05-31 14:18:52 +00:00
return new MeterHistogram(meterWindow, name);
2011-03-29 19:21:57 +00:00
}
else if (_wcsicmp(L"BAR", meter) == 0)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
return new MeterBar(meterWindow, name);
2011-03-29 19:21:57 +00:00
}
else if (_wcsicmp(L"BITMAP", meter) == 0)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
return new MeterBitmap(meterWindow, name);
2011-03-29 19:21:57 +00:00
}
else if (_wcsicmp(L"LINE", meter) == 0)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
return new MeterLine(meterWindow, name);
2011-03-29 19:21:57 +00:00
}
else if (_wcsicmp(L"ROUNDLINE", meter) == 0)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
return new MeterRoundLine(meterWindow, name);
2011-03-29 19:21:57 +00:00
}
else if (_wcsicmp(L"ROTATOR", meter) == 0)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
return new MeterRotator(meterWindow, name);
2011-03-29 19:21:57 +00:00
}
else if (_wcsicmp(L"BUTTON", meter) == 0)
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:18:52 +00:00
return new MeterButton(meterWindow, name);
2011-03-29 19:21:57 +00:00
}
2009-02-10 18:37:48 +00:00
2013-05-30 14:19:42 +00:00
LogErrorF(L"Meter=%s is not valid in [%s]", meter, name);
2009-02-10 18:37:48 +00:00
2013-05-31 14:28:39 +00:00
return nullptr;
2009-02-10 18:37:48 +00:00
}
/*
** Updates the value(s) from the measures. Derived classes should
** only update if this returns true;
*/
2013-05-31 14:18:52 +00:00
bool Meter::Update()
2009-02-10 18:37:48 +00:00
{
// Only update the meter's value when the divider is equal to the counter
2013-02-06 10:12:16 +00:00
return UpdateCounter();
2009-02-10 18:37:48 +00:00
}
/*
** Reads and binds the primary MeasureName. This must always be called in overridden
** BindMeasures() implementations.
2012-07-17 07:37:53 +00:00
**
2010-09-17 08:47:22 +00:00
*/
2013-05-31 14:18:52 +00:00
bool Meter::BindPrimaryMeasure(ConfigParser& parser, const WCHAR* section, bool optional)
{
m_Measures.clear();
2012-07-17 07:37:53 +00:00
const std::wstring& measureName = parser.ReadString(section, L"MeasureName", L"");
2013-05-31 14:18:52 +00:00
Measure* measure = parser.GetMeasure(measureName);
2012-07-17 07:37:53 +00:00
if (measure)
{
m_Measures.push_back(measure);
return true;
}
else if (!optional)
{
2013-05-30 14:19:42 +00:00
LogErrorF(L"MeasureName=%s is not valid in [%s]", measureName.c_str(), section);
}
2012-07-17 07:37:53 +00:00
return false;
}
/*
2012-07-17 07:37:53 +00:00
** Reads and binds secondary measures (MeasureName2 - MeasureNameN).
**
*/
2013-05-31 14:18:52 +00:00
void Meter::BindSecondaryMeasures(ConfigParser& parser, const WCHAR* section)
{
2012-07-17 07:37:53 +00:00
if (!m_Measures.empty())
{
2012-07-17 07:37:53 +00:00
WCHAR tmpName[64];
int i = 2;
do
{
2012-07-17 07:37:53 +00:00
_snwprintf_s(tmpName, _TRUNCATE, L"MeasureName%i", i);
const std::wstring& measureName = parser.ReadString(section, tmpName, L"");
2013-05-31 14:18:52 +00:00
Measure* measure = parser.GetMeasure(measureName);
2012-07-17 07:37:53 +00:00
if (measure)
{
m_Measures.push_back(measure);
}
else
{
if (!measureName.empty())
{
2013-05-30 14:19:42 +00:00
LogErrorF(L"MeasureName%i=%s is not valid in [%s]", i, measureName.c_str(), section);
2012-07-17 07:37:53 +00:00
}
break;
}
++i;
}
2012-07-17 07:37:53 +00:00
while (true);
}
}
/*
2012-07-17 07:57:28 +00:00
** Replaces %1, %2, ... with the corresponding measure value.
**
*/
2013-05-31 14:18:52 +00:00
bool Meter::ReplaceMeasures(std::wstring& str, AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
bool replaced = false;
if (str.find(L'%') != std::wstring::npos)
{
WCHAR buffer[64];
2012-07-17 07:57:28 +00:00
for (size_t i = m_Measures.size(); i > 0; --i)
{
2011-12-09 08:40:19 +00:00
size_t len = _snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i);
2011-12-09 03:28:19 +00:00
size_t start = 0, pos;
2012-07-17 07:57:28 +00:00
const WCHAR* measureValue = m_Measures[i - 1]->GetStringOrFormattedValue(
autoScale, scale, decimals, percentual);
2012-07-17 07:57:28 +00:00
int measureValueLen = wcslen(measureValue);
2011-03-29 19:21:57 +00:00
do
{
2011-12-09 03:28:19 +00:00
pos = str.find(buffer, start, len);
if (pos != std::wstring::npos)
{
2012-07-17 07:57:28 +00:00
str.replace(pos, len, measureValue, measureValueLen);
start = pos + measureValueLen;
replaced = true;
}
}
while (pos != std::wstring::npos);
}
}
return replaced;
}
/*
** Does the initial construction of the ToolTip for the meter
*/
2013-05-31 14:18:52 +00:00
void Meter::CreateToolTip(MeterWindow* meterWindow)
{
HWND hMeterWindow = m_MeterWindow->GetWindow();
HINSTANCE hInstance = GetRainmeter().GetModuleInstance();
2010-09-17 08:47:22 +00:00
DWORD style = WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP;
if (m_ToolTipType)
{
2010-09-17 08:47:22 +00:00
style |= TTS_BALLOON;
}
2010-09-17 08:47:22 +00:00
HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST,
2011-03-29 19:21:57 +00:00
TOOLTIPS_CLASS,
2013-05-31 14:28:39 +00:00
nullptr,
2010-09-17 08:47:22 +00:00
style,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hMeterWindow,
2013-05-31 14:28:39 +00:00
nullptr,
hInstance,
2013-05-31 14:28:39 +00:00
nullptr);
2010-09-17 08:47:22 +00:00
if (hwndTT)
{
2010-09-17 08:47:22 +00:00
SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
TOOLINFO ti = {sizeof(TOOLINFO), TTF_SUBCLASS, hMeterWindow, 0, GetMeterRect(), hInstance};
2013-05-31 14:28:39 +00:00
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM)&ti);
2010-09-17 08:47:22 +00:00
m_ToolTipHandle = hwndTT;
UpdateToolTip();
}
}
/*
** Updates the ToolTip to match new values
*/
2013-05-31 14:18:52 +00:00
void Meter::UpdateToolTip()
{
HWND hwndTT = m_ToolTipHandle;
2010-09-17 08:47:22 +00:00
TOOLINFO ti = {sizeof(TOOLINFO)};
ti.hwnd = m_MeterWindow->GetWindow();
2013-05-31 14:28:39 +00:00
SendMessage(hwndTT, TTM_GETTOOLINFO, 0, (LPARAM)&ti);
std::wstring text = m_ToolTipText;
2012-07-17 07:57:28 +00:00
ReplaceMeasures(text);
2011-11-08 19:11:31 +00:00
ti.lpszText = (LPTSTR)text.c_str();
ti.rect = GetMeterRect();
2013-05-31 14:28:39 +00:00
SendMessage(hwndTT, TTM_SETTOOLINFO, 0, (LPARAM)&ti);
SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, m_ToolTipWidth);
if (!m_ToolTipTitle.empty())
{
2013-05-31 14:28:39 +00:00
HICON hIcon = nullptr;
2010-09-17 08:47:22 +00:00
bool destroy = false;
if (!m_ToolTipIcon.empty())
{
2011-11-16 16:47:20 +00:00
const WCHAR* tipIcon = m_ToolTipIcon.c_str();
if (_wcsicmp(tipIcon, L"INFO") == 0)
{
2011-11-08 19:11:31 +00:00
hIcon = (HICON)TTI_INFO;
}
2011-11-16 16:47:20 +00:00
else if (_wcsicmp(tipIcon, L"WARNING") == 0)
{
2011-11-08 19:11:31 +00:00
hIcon = (HICON)TTI_WARNING;
}
2011-11-16 16:47:20 +00:00
else if (_wcsicmp(tipIcon, L"ERROR") == 0)
{
2011-11-08 19:11:31 +00:00
hIcon = (HICON)TTI_ERROR;
}
2011-11-16 16:47:20 +00:00
else if (_wcsicmp(tipIcon, L"QUESTION") == 0)
{
2013-05-31 14:28:39 +00:00
hIcon = LoadIcon(nullptr, IDI_QUESTION);
}
2011-11-16 16:47:20 +00:00
else if (_wcsicmp(tipIcon, L"SHIELD") == 0)
{
2013-05-31 14:28:39 +00:00
hIcon = LoadIcon(nullptr, IDI_SHIELD);
}
else
{
2013-05-31 14:28:39 +00:00
hIcon = (HICON)LoadImage(nullptr, tipIcon, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
2010-09-17 08:47:22 +00:00
destroy = true;
}
}
2010-09-17 08:47:22 +00:00
text = m_ToolTipTitle;
2012-07-17 07:57:28 +00:00
ReplaceMeasures(text);
2013-05-31 14:28:39 +00:00
SendMessage(hwndTT, TTM_SETTITLE, (WPARAM)hIcon, (LPARAM)text.c_str());
2010-09-17 08:47:22 +00:00
if (destroy)
{
DestroyIcon(hIcon);
}
}
if (m_ToolTipHidden)
{
2013-05-31 14:28:39 +00:00
SendMessage(hwndTT, TTM_ACTIVATE, FALSE, 0);
}
else
{
2013-05-31 14:28:39 +00:00
SendMessage(hwndTT, TTM_ACTIVATE, !IsHidden(), 0);
}
}
2009-02-10 18:37:48 +00:00
/*
** Draws the solid background & bevel if such are defined
*/
2013-05-31 14:18:52 +00:00
bool Meter::Draw(Gfx::Canvas& canvas)
2009-02-10 18:37:48 +00:00
{
if (IsHidden()) return false;
2013-03-25 15:42:18 +00:00
canvas.SetAntiAliasing(m_AntiAlias);
2009-02-10 18:37:48 +00:00
if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0)
{
int x = GetX();
int y = GetY();
Rect r(x, y, m_W, m_H);
2009-02-10 18:37:48 +00:00
if (m_SolidColor.GetValue() == m_SolidColor2.GetValue())
{
SolidBrush solid(m_SolidColor);
2013-03-25 15:42:18 +00:00
canvas.FillRectangle(r, solid);
2009-02-10 18:37:48 +00:00
}
else
{
2013-03-25 15:42:18 +00:00
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
if (!m_AntiAlias)
{
// Fix the tiling issue in some GradientAngle values
graphics.SetPixelOffsetMode(PixelOffsetModeHalf);
}
2009-02-10 18:37:48 +00:00
LinearGradientBrush gradient(r, m_SolidColor, m_SolidColor2, m_SolidAngle, TRUE);
graphics.FillRectangle(&gradient, r);
if (!m_AntiAlias)
{
graphics.SetPixelOffsetMode(PixelOffsetModeDefault);
}
2013-03-25 15:42:18 +00:00
canvas.EndGdiplusContext();
2009-02-10 18:37:48 +00:00
}
}
if (m_SolidBevel != BEVELTYPE_NONE)
{
2013-03-25 15:42:18 +00:00
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
2009-02-10 18:37:48 +00:00
int x = GetX();
int y = GetY();
Color lightColor(255, 255, 255, 255);
Color darkColor(255, 0, 0, 0);
2009-02-10 18:37:48 +00:00
if (m_SolidBevel == BEVELTYPE_DOWN)
{
lightColor.SetValue(Color::MakeARGB(255, 0, 0, 0));
darkColor.SetValue(Color::MakeARGB(255, 255, 255, 255));
2009-02-10 18:37:48 +00:00
}
Pen light(lightColor);
Pen dark(darkColor);
2009-02-10 18:37:48 +00:00
// The bevel is drawn outside the meter
2011-03-29 19:21:57 +00:00
Rect rect(x - 2, y - 2, m_W + 4, m_H + 4);
2009-02-10 18:37:48 +00:00
DrawBevel(graphics, rect, light, dark);
2013-03-25 15:42:18 +00:00
canvas.EndGdiplusContext();
2009-02-10 18:37:48 +00:00
}
return true;
}
/*
** Draws a bevel inside the given area
*/
2013-05-31 14:18:52 +00:00
void Meter::DrawBevel(Graphics& graphics, const Rect& rect, const Pen& light, const Pen& dark)
2009-02-10 18:37:48 +00:00
{
int l = rect.GetLeft();
int r = rect.GetRight() - 1;
int t = rect.GetTop();
int b = rect.GetBottom() - 1;
graphics.DrawLine(&light, l, t, l, b);
graphics.DrawLine(&light, l, t, r, t);
graphics.DrawLine(&light, l + 1, t + 1, l + 1, b - 1);
graphics.DrawLine(&light, l + 1, t + 1, r - 1, t + 1);
2009-02-10 18:37:48 +00:00
graphics.DrawLine(&dark, l, b, r, b);
graphics.DrawLine(&dark, r, t, r, b);
graphics.DrawLine(&dark, l + 1, b - 1, r - 1, b - 1);
graphics.DrawLine(&dark, r - 1, t + 1, r - 1, b - 1);
}