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 "MeterString.h"
|
|
|
|
#include "Rainmeter.h"
|
|
|
|
#include "Measure.h"
|
|
|
|
#include "Error.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;
|
|
|
|
|
2011-06-06 12:27:19 +00:00
|
|
|
#define PI (3.14159265f)
|
|
|
|
#define CONVERT_TO_DEGREES(X) ((X) * (180.0f / PI))
|
|
|
|
|
2010-11-05 03:25:21 +00:00
|
|
|
void StringToUpper(std::wstring& str)
|
|
|
|
{
|
2012-05-13 09:17:00 +00:00
|
|
|
WCHAR* srcAndDest = &str[0];
|
|
|
|
int strAndDestLen = (int)str.length();
|
|
|
|
LCMapString(LOCALE_USER_DEFAULT, LCMAP_UPPERCASE, srcAndDest, strAndDestLen, srcAndDest, strAndDestLen);
|
2010-11-05 03:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StringToLower(std::wstring& str)
|
|
|
|
{
|
2012-05-13 09:17:00 +00:00
|
|
|
WCHAR* srcAndDest = &str[0];
|
|
|
|
int strAndDestLen = (int)str.length();
|
|
|
|
LCMapString(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, srcAndDest, strAndDestLen, srcAndDest, strAndDestLen);
|
2010-11-05 03:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StringToProper(std::wstring& str)
|
|
|
|
{
|
|
|
|
if (!str.empty())
|
|
|
|
{
|
2012-05-13 09:30:20 +00:00
|
|
|
WCHAR* srcAndDest = &str[0];
|
|
|
|
LCMapString(LOCALE_USER_DEFAULT, LCMAP_UPPERCASE, srcAndDest, 1, srcAndDest, 1);
|
2010-11-05 03:25:21 +00:00
|
|
|
|
|
|
|
for (size_t i = 1; i < str.length(); ++i)
|
|
|
|
{
|
2012-05-13 09:30:20 +00:00
|
|
|
srcAndDest = &str[i];
|
2013-04-18 17:19:21 +00:00
|
|
|
LCMapString(LOCALE_USER_DEFAULT, (iswspace(str[i - 1]) > 0) ? LCMAP_UPPERCASE : LCMAP_LOWERCASE, srcAndDest, 1, srcAndDest, 1);
|
2010-11-05 03:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-18 19:48:14 +00:00
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
** The constructor
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterString::MeterString(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
|
2010-11-11 20:24:59 +00:00
|
|
|
m_Color(Color::White),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_EffectColor(Color::Black),
|
|
|
|
m_AutoScale(AUTOSCALE_OFF),
|
|
|
|
m_Style(NORMAL),
|
|
|
|
m_Effect(EFFECT_NONE),
|
2012-05-20 17:57:12 +00:00
|
|
|
m_Case(TEXTCASE_NONE),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_FontSize(10),
|
|
|
|
m_Scale(1.0),
|
|
|
|
m_NoDecimals(true),
|
|
|
|
m_Percentual(true),
|
2013-01-23 18:57:01 +00:00
|
|
|
m_ClipType(CLIP_OFF),
|
|
|
|
m_NeedsClipping(false),
|
|
|
|
m_ClipStringW(-1),
|
|
|
|
m_ClipStringH(-1),
|
2013-03-25 15:42:18 +00:00
|
|
|
m_TextFormat(meterWindow->GetCanvas().CreateTextFormat()),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_NumOfDecimals(-1),
|
|
|
|
m_Angle()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The destructor
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterString::~MeterString()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
delete m_TextFormat;
|
2013-05-31 14:28:39 +00:00
|
|
|
m_TextFormat = nullptr;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Returns the X-coordinate of the meter
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
int MeterString::GetX(bool abs)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
int x = Meter::GetX();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
if (!abs)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
switch (m_TextFormat->GetHorizontalAlignment())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
case Gfx::HorizontalAlignment::Center:
|
2011-11-10 13:44:19 +00:00
|
|
|
x -= m_W / 2;
|
2009-02-10 18:37:48 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-25 15:42:18 +00:00
|
|
|
case Gfx::HorizontalAlignment::Right:
|
2009-02-10 18:37:48 +00:00
|
|
|
x -= m_W;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2012-05-16 18:02:31 +00:00
|
|
|
/*
|
|
|
|
** Returns the Y-coordinate of the meter
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
int MeterString::GetY(bool abs)
|
2012-05-16 18:02:31 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
int y = Meter::GetY();
|
2012-05-16 18:02:31 +00:00
|
|
|
|
|
|
|
if (!abs)
|
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
switch (m_TextFormat->GetVerticalAlignment())
|
2012-05-16 18:02:31 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
case Gfx::VerticalAlignment::Center:
|
2012-05-16 18:02:31 +00:00
|
|
|
y -= m_H / 2;
|
|
|
|
break;
|
|
|
|
|
2013-03-25 15:42:18 +00:00
|
|
|
case Gfx::VerticalAlignment::Bottom:
|
2012-05-16 18:02:31 +00:00
|
|
|
y -= m_H;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Create the font that is used to draw the text.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void MeterString::Initialize()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
Meter::Initialize();
|
2012-09-27 01:47:25 +00:00
|
|
|
|
2013-03-25 15:42:18 +00:00
|
|
|
m_TextFormat->SetProperties(
|
|
|
|
m_FontFace.c_str(),
|
|
|
|
m_FontSize,
|
|
|
|
m_Style & BOLD,
|
2013-03-28 13:09:46 +00:00
|
|
|
m_Style & ITALIC,
|
2013-04-09 17:35:49 +00:00
|
|
|
m_MeterWindow->GetFontCollection());
|
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 MeterString::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2009-08-27 17:05:10 +00:00
|
|
|
// Store the current font values so we know if the font needs to be updated
|
|
|
|
std::wstring oldFontFace = m_FontFace;
|
|
|
|
int oldFontSize = m_FontSize;
|
|
|
|
TEXTSTYLE oldStyle = m_Style;
|
|
|
|
|
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_Color = parser.ReadColor(section, L"FontColor", Color::Black);
|
|
|
|
m_EffectColor = parser.ReadColor(section, L"FontEffectColor", Color::Black);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-07-03 13:57:46 +00:00
|
|
|
m_Prefix = parser.ReadString(section, L"Prefix", L"");
|
|
|
|
m_Postfix = parser.ReadString(section, L"Postfix", L"");
|
|
|
|
m_Text = parser.ReadString(section, L"Text", L"");
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-07-31 10:36:53 +00:00
|
|
|
m_Percentual = parser.ReadBool(section, L"Percentual", false);
|
2013-01-23 18:57:01 +00:00
|
|
|
|
2013-01-26 04:05:47 +00:00
|
|
|
int clipping = parser.ReadInt(section, L"ClipString", 0);
|
|
|
|
switch (clipping)
|
2013-01-23 18:57:01 +00:00
|
|
|
{
|
2013-01-26 04:05:47 +00:00
|
|
|
case 2:
|
2013-01-23 18:57:01 +00:00
|
|
|
m_ClipType = CLIP_AUTO;
|
|
|
|
|
2013-01-23 20:24:25 +00:00
|
|
|
m_ClipStringW = parser.ReadInt(section, L"ClipStringW", -1);
|
|
|
|
m_ClipStringH = parser.ReadInt(section, L"ClipStringH", -1);
|
2013-01-26 04:05:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
m_ClipType = CLIP_ON;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
m_ClipType = CLIP_OFF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-06-29 16:59:18 +00:00
|
|
|
LogErrorF(this, L"ClipString=%s is not valid", clipping);
|
2013-01-23 20:24:25 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-01-17 22:39:40 +00:00
|
|
|
m_FontFace = parser.ReadString(section, L"FontFace", L"Arial");
|
|
|
|
if (m_FontFace.empty())
|
|
|
|
{
|
|
|
|
m_FontFace = L"Arial";
|
|
|
|
}
|
2010-02-08 14:12:47 +00:00
|
|
|
|
2013-02-06 10:12:16 +00:00
|
|
|
m_FontSize = parser.ReadInt(section, L"FontSize", 10);
|
2010-02-08 14:12:47 +00:00
|
|
|
if (m_FontSize < 0)
|
|
|
|
{
|
|
|
|
m_FontSize = 10;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:37:51 +00:00
|
|
|
m_NumOfDecimals = parser.ReadInt(section, L"NumOfDecimals", -1);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-04-06 12:16:54 +00:00
|
|
|
m_Angle = (Gdiplus::REAL)parser.ReadFloat(section, L"Angle", 0.0);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-01-24 10:15:05 +00:00
|
|
|
const std::wstring& autoscale = parser.ReadString(section, L"AutoScale", L"0");
|
2011-01-19 15:31:45 +00:00
|
|
|
int autoscaleValue = _wtoi(autoscale.c_str());
|
|
|
|
if (autoscaleValue == 0)
|
|
|
|
{
|
|
|
|
m_AutoScale = AUTOSCALE_OFF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (autoscale.find_last_of(L"kK") == std::wstring::npos)
|
|
|
|
{
|
|
|
|
m_AutoScale = (autoscaleValue == 2) ? AUTOSCALE_1000 : AUTOSCALE_1024;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_AutoScale = (autoscaleValue == 2) ? AUTOSCALE_1000K : AUTOSCALE_1024K;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-24 10:15:05 +00:00
|
|
|
const std::wstring& scale = parser.ReadString(section, L"Scale", L"1");
|
2012-04-06 12:16:54 +00:00
|
|
|
m_NoDecimals = (scale.find(L'.') == std::wstring::npos);
|
|
|
|
m_Scale = parser.ParseDouble(scale.c_str(), 1);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-03-25 15:42:18 +00:00
|
|
|
const WCHAR* hAlign = parser.ReadString(section, L"StringAlign", L"LEFT").c_str();
|
2013-05-31 14:28:39 +00:00
|
|
|
const WCHAR* vAlign = nullptr;
|
2013-03-25 15:42:18 +00:00
|
|
|
if (_wcsnicmp(hAlign, L"LEFT", 4) == 0)
|
2012-05-16 18:02:31 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
m_TextFormat->SetHorizontalAlignment(Gfx::HorizontalAlignment::Left);
|
|
|
|
vAlign = hAlign + 4;
|
2012-05-16 18:02:31 +00:00
|
|
|
}
|
2013-03-25 15:42:18 +00:00
|
|
|
else if (_wcsnicmp(hAlign, L"RIGHT", 5) == 0)
|
2012-05-16 18:02:31 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
m_TextFormat->SetHorizontalAlignment(Gfx::HorizontalAlignment::Right);
|
|
|
|
vAlign = hAlign + 5;
|
2012-05-16 18:02:31 +00:00
|
|
|
}
|
2013-03-25 15:42:18 +00:00
|
|
|
else if (_wcsnicmp(hAlign, L"CENTER", 6) == 0)
|
2012-05-16 18:02:31 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
m_TextFormat->SetHorizontalAlignment(Gfx::HorizontalAlignment::Center);
|
|
|
|
vAlign = hAlign + 6;
|
2012-05-16 18:02:31 +00:00
|
|
|
}
|
2013-03-25 15:42:18 +00:00
|
|
|
|
|
|
|
if (!vAlign || _wcsicmp(vAlign, L"TOP") == 0)
|
2012-05-16 18:02:31 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
m_TextFormat->SetVerticalAlignment(Gfx::VerticalAlignment::Top);
|
2012-05-16 18:02:31 +00:00
|
|
|
}
|
2013-03-25 15:42:18 +00:00
|
|
|
else if (_wcsicmp(vAlign, L"BOTTOM") == 0)
|
2012-05-16 18:02:31 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
m_TextFormat->SetVerticalAlignment(Gfx::VerticalAlignment::Bottom);
|
2012-05-16 18:02:31 +00:00
|
|
|
}
|
2013-03-25 15:42:18 +00:00
|
|
|
else if (_wcsicmp(vAlign, L"CENTER") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
m_TextFormat->SetVerticalAlignment(Gfx::VerticalAlignment::Center);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* stringCase = parser.ReadString(section, L"StringCase", L"NONE").c_str();
|
|
|
|
if (_wcsicmp(stringCase, L"NONE") == 0)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
2012-05-20 17:57:12 +00:00
|
|
|
m_Case = TEXTCASE_NONE;
|
2010-03-18 19:48:14 +00:00
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(stringCase, L"UPPER") == 0)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
2012-05-20 17:57:12 +00:00
|
|
|
m_Case = TEXTCASE_UPPER;
|
2010-03-18 19:48:14 +00:00
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(stringCase, L"LOWER") == 0)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
2012-05-20 17:57:12 +00:00
|
|
|
m_Case = TEXTCASE_LOWER;
|
2010-03-18 19:48:14 +00:00
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(stringCase, L"PROPER") == 0)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
2012-05-20 17:57:12 +00:00
|
|
|
m_Case = TEXTCASE_PROPER;
|
2010-03-18 19:48:14 +00:00
|
|
|
}
|
2010-09-21 16:45:29 +00:00
|
|
|
else
|
|
|
|
{
|
2013-06-29 16:59:18 +00:00
|
|
|
LogErrorF(this, L"StringCase=%s is not valid", stringCase);
|
2010-09-21 16:45:29 +00:00
|
|
|
}
|
2010-03-18 19:48:14 +00:00
|
|
|
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* style = parser.ReadString(section, L"StringStyle", L"NORMAL").c_str();
|
|
|
|
if (_wcsicmp(style, L"NORMAL") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Style = NORMAL;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(style, L"BOLD") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Style = BOLD;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(style, L"ITALIC") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Style = ITALIC;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(style, L"BOLDITALIC") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Style = BOLDITALIC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-29 16:59:18 +00:00
|
|
|
LogErrorF(this, L"StringStyle=%s is not valid", style);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* effect = parser.ReadString(section, L"StringEffect", L"NONE").c_str();
|
|
|
|
if (_wcsicmp(effect, L"NONE") == 0)
|
2009-07-29 12:54:05 +00:00
|
|
|
{
|
|
|
|
m_Effect = EFFECT_NONE;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(effect, L"SHADOW") == 0)
|
2009-07-29 12:54:05 +00:00
|
|
|
{
|
|
|
|
m_Effect = EFFECT_SHADOW;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(effect, L"BORDER") == 0)
|
2009-07-29 12:54:05 +00:00
|
|
|
{
|
|
|
|
m_Effect = EFFECT_BORDER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-29 16:59:18 +00:00
|
|
|
LogErrorF(this, L"StringEffect=%s is not valid", effect);
|
2009-07-29 12:54:05 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 17:05:10 +00:00
|
|
|
if (m_Initialized &&
|
2011-11-27 08:30:39 +00:00
|
|
|
(wcscmp(oldFontFace.c_str(), m_FontFace.c_str()) != 0 ||
|
2009-08-27 17:05:10 +00:00
|
|
|
oldFontSize != m_FontSize ||
|
|
|
|
oldStyle != m_Style))
|
|
|
|
{
|
|
|
|
Initialize(); // Recreate the font
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Updates the value(s) from the measures.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
bool MeterString::Update()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
if (Meter::Update())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-01-19 15:31:45 +00:00
|
|
|
int decimals = (m_NumOfDecimals != -1) ? m_NumOfDecimals : (m_NoDecimals && (m_Percentual || m_AutoScale == AUTOSCALE_OFF)) ? 0 : 1;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-07-03 13:57:46 +00:00
|
|
|
// Create the text
|
|
|
|
m_String = m_Prefix;
|
2012-07-17 07:57:28 +00:00
|
|
|
if (!m_Measures.empty())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-07-17 07:57:28 +00:00
|
|
|
if (m_Text.empty())
|
2012-07-03 13:57:46 +00:00
|
|
|
{
|
2013-04-10 15:59:41 +00:00
|
|
|
m_String += m_Measures[0]->GetStringOrFormattedValue(
|
|
|
|
m_AutoScale, m_Scale, decimals, m_Percentual);
|
2012-07-17 07:57:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::wstring tmpText = m_Text;
|
|
|
|
ReplaceMeasures(tmpText, m_AutoScale, m_Scale, decimals, m_Percentual);
|
|
|
|
m_String += tmpText;
|
2012-07-03 13:57:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_String += m_Text;
|
2010-11-19 07:33:58 +00:00
|
|
|
}
|
2012-07-03 13:57:46 +00:00
|
|
|
if (!m_Postfix.empty()) m_String += m_Postfix;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-05-20 17:57:12 +00:00
|
|
|
switch (m_Case)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
|
|
|
case TEXTCASE_UPPER:
|
2010-11-05 03:25:21 +00:00
|
|
|
StringToUpper(m_String);
|
2010-03-18 19:48:14 +00:00
|
|
|
break;
|
|
|
|
case TEXTCASE_LOWER:
|
2010-11-05 03:25:21 +00:00
|
|
|
StringToLower(m_String);
|
2010-03-18 19:48:14 +00:00
|
|
|
break;
|
|
|
|
case TEXTCASE_PROPER:
|
2010-11-05 03:25:21 +00:00
|
|
|
StringToProper(m_String);
|
2010-03-18 19:48:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-01 06:01:12 +00:00
|
|
|
if (!m_WDefined || !m_HDefined)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
// Calculate the text size
|
|
|
|
RectF rect;
|
2013-03-25 15:42:18 +00:00
|
|
|
if (DrawString(m_MeterWindow->GetCanvas(), &rect))
|
2010-02-08 14:12:47 +00:00
|
|
|
{
|
2013-07-20 16:07:51 +00:00
|
|
|
m_W = (int)rect.Width + GetWidthPadding();
|
|
|
|
m_H = (int)rect.Height + GetHeightPadding();
|
2010-02-08 14:12:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-21 15:49:16 +00:00
|
|
|
m_W = 1;
|
|
|
|
m_H = 1;
|
2010-02-08 14:12:47 +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 MeterString::Draw(Gfx::Canvas& canvas)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
if (!Meter::Draw(canvas)) return false;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
return DrawString(canvas, nullptr);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Draws the string or calculates it's size
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
bool MeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
if (!m_TextFormat->IsInitialized()) return false;
|
2010-02-08 14:12:47 +00:00
|
|
|
|
2011-06-06 12:27:19 +00:00
|
|
|
LPCWSTR string = m_String.c_str();
|
2013-03-25 15:42:18 +00:00
|
|
|
UINT stringLen = (UINT)m_String.length();
|
2012-05-16 18:02:31 +00:00
|
|
|
|
2013-03-25 15:42:18 +00:00
|
|
|
canvas.SetTextAntiAliasing(m_AntiAlias);
|
2012-05-16 18:02:31 +00:00
|
|
|
|
2013-03-25 15:42:18 +00:00
|
|
|
m_TextFormat->SetTrimming(
|
|
|
|
m_ClipType == CLIP_ON ||
|
|
|
|
(m_ClipType == CLIP_AUTO && (m_NeedsClipping || (m_WDefined && m_HDefined))));
|
2010-11-05 03:25:21 +00:00
|
|
|
|
2013-07-20 16:07:51 +00:00
|
|
|
Gdiplus::Rect meterRect = GetMeterRectPadding();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
if (rect)
|
|
|
|
{
|
2013-07-20 16:07:51 +00:00
|
|
|
rect->X = (REAL)meterRect.X;
|
|
|
|
rect->Y = (REAL)meterRect.Y;
|
2013-03-25 15:42:18 +00:00
|
|
|
if (canvas.MeasureTextW(string, stringLen, *m_TextFormat, *rect) &&
|
|
|
|
m_ClipType == CLIP_AUTO)
|
2013-01-23 18:57:01 +00:00
|
|
|
{
|
|
|
|
// Set initial clipping
|
|
|
|
m_NeedsClipping = false;
|
|
|
|
|
|
|
|
REAL w, h;
|
|
|
|
bool updateSize = true;
|
|
|
|
|
|
|
|
if (m_WDefined)
|
|
|
|
{
|
2013-07-20 16:07:51 +00:00
|
|
|
w = (REAL)meterRect.Width;
|
2013-01-23 18:57:01 +00:00
|
|
|
h = rect->Height;
|
|
|
|
m_NeedsClipping = true;
|
|
|
|
}
|
|
|
|
else if (m_HDefined)
|
|
|
|
{
|
|
|
|
if (m_ClipStringW == -1)
|
|
|
|
{
|
2013-01-28 07:38:26 +00:00
|
|
|
// Text does not fit in defined height, clip it
|
2013-07-20 16:07:51 +00:00
|
|
|
if (rect->Height > (REAL)meterRect.Height)
|
2013-01-28 07:38:26 +00:00
|
|
|
{
|
|
|
|
m_NeedsClipping = true;
|
|
|
|
}
|
|
|
|
|
2013-07-20 16:07:51 +00:00
|
|
|
rect->Height = (REAL)meterRect.Height;
|
2013-01-23 18:57:01 +00:00
|
|
|
updateSize = false;
|
2013-01-28 07:38:26 +00:00
|
|
|
|
2013-01-23 18:57:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-20 16:07:51 +00:00
|
|
|
if (rect->Width > (REAL)m_ClipStringW)
|
2013-01-23 18:57:01 +00:00
|
|
|
{
|
|
|
|
w = (REAL)m_ClipStringW;
|
|
|
|
m_NeedsClipping = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w = rect->Width;
|
|
|
|
}
|
|
|
|
|
2013-07-20 16:07:51 +00:00
|
|
|
h = (REAL)meterRect.Height;
|
2013-01-23 18:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_ClipStringW == -1)
|
|
|
|
{
|
2013-01-28 07:38:26 +00:00
|
|
|
// Clip text if already larger than ClipStringH
|
|
|
|
if (m_ClipStringH != -1 && rect->Height > (REAL)m_ClipStringH)
|
|
|
|
{
|
|
|
|
m_NeedsClipping = true;
|
|
|
|
rect->Height = (REAL)m_ClipStringH;
|
|
|
|
}
|
|
|
|
|
2013-01-23 18:57:01 +00:00
|
|
|
updateSize = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-20 16:07:51 +00:00
|
|
|
if (rect->Width > (REAL)m_ClipStringW)
|
2013-01-23 18:57:01 +00:00
|
|
|
{
|
|
|
|
w = (REAL)m_ClipStringW;
|
|
|
|
m_NeedsClipping = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w = rect->Width;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = rect->Height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateSize)
|
|
|
|
{
|
2013-03-25 15:42:18 +00:00
|
|
|
UINT lines = 0;
|
2013-07-20 16:07:51 +00:00
|
|
|
RectF layout((REAL)meterRect.X, (REAL)meterRect.Y, w, h);
|
2013-03-25 15:42:18 +00:00
|
|
|
if (canvas.MeasureTextLinesW(string, stringLen, *m_TextFormat, layout, lines) &&
|
|
|
|
lines != 0)
|
2013-01-23 18:57:01 +00:00
|
|
|
{
|
|
|
|
rect->Width = w;
|
2013-01-28 07:38:26 +00:00
|
|
|
rect->Height = layout.Height;
|
2013-01-23 18:57:01 +00:00
|
|
|
|
2013-07-20 16:07:51 +00:00
|
|
|
if (m_HDefined || (m_ClipStringH != -1 && rect->Height > (REAL)m_ClipStringH))
|
2013-01-23 18:57:01 +00:00
|
|
|
{
|
2013-07-20 16:07:51 +00:00
|
|
|
rect->Height = m_HDefined ? (REAL)meterRect.Height : (REAL)m_ClipStringH;
|
2013-01-23 18:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-20 16:07:51 +00:00
|
|
|
RectF rcDest((REAL)meterRect.X, (REAL)meterRect.Y, (REAL)meterRect.Width, (REAL)meterRect.Height);
|
2011-06-06 12:27:19 +00:00
|
|
|
m_Rect = rcDest;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-11-05 03:25:21 +00:00
|
|
|
if (m_Angle != 0.0f)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-09 16:05:46 +00:00
|
|
|
const float baseX = (float)Meter::GetX();
|
2013-07-20 16:07:51 +00:00
|
|
|
canvas.RotateTransform(CONVERT_TO_DEGREES(m_Angle), baseX, (REAL)meterRect.Y, -baseX, -(REAL)meterRect.Y);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 04:56:46 +00:00
|
|
|
if (m_Effect != EFFECT_NONE)
|
2010-11-11 20:24:59 +00:00
|
|
|
{
|
|
|
|
SolidBrush solidBrush(m_EffectColor);
|
2011-06-06 12:27:19 +00:00
|
|
|
RectF rcEffect(rcDest);
|
|
|
|
|
|
|
|
if (m_Effect == EFFECT_SHADOW)
|
|
|
|
{
|
|
|
|
rcEffect.Offset(1, 1);
|
2013-03-25 15:42:18 +00:00
|
|
|
canvas.DrawTextW(string, (UINT)stringLen, *m_TextFormat, rcEffect, solidBrush);
|
2011-06-06 12:27:19 +00:00
|
|
|
}
|
|
|
|
else //if (m_Effect == EFFECT_BORDER)
|
|
|
|
{
|
|
|
|
rcEffect.Offset(0, 1);
|
2013-03-25 15:42:18 +00:00
|
|
|
canvas.DrawTextW(string, (UINT)stringLen, *m_TextFormat, rcEffect, solidBrush);
|
2011-06-06 12:27:19 +00:00
|
|
|
rcEffect.Offset(1, -1);
|
2013-03-25 15:42:18 +00:00
|
|
|
canvas.DrawTextW(string, (UINT)stringLen, *m_TextFormat, rcEffect, solidBrush);
|
2011-06-06 12:27:19 +00:00
|
|
|
rcEffect.Offset(-1, -1);
|
2013-03-25 15:42:18 +00:00
|
|
|
canvas.DrawTextW(string, (UINT)stringLen, *m_TextFormat, rcEffect, solidBrush);
|
2011-06-06 12:27:19 +00:00
|
|
|
rcEffect.Offset(-1, 1);
|
2013-03-25 15:42:18 +00:00
|
|
|
canvas.DrawTextW(string, (UINT)stringLen, *m_TextFormat, rcEffect, solidBrush);
|
2011-06-06 12:27:19 +00:00
|
|
|
}
|
2009-07-29 12:54:05 +00:00
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-07-29 12:54:05 +00:00
|
|
|
SolidBrush solidBrush(m_Color);
|
2013-03-25 15:42:18 +00:00
|
|
|
canvas.DrawTextW(string, (UINT)stringLen, *m_TextFormat, rcDest, solidBrush);
|
2009-07-27 11:48:57 +00:00
|
|
|
|
2010-11-05 03:25:21 +00:00
|
|
|
if (m_Angle != 0.0f)
|
|
|
|
{
|
2013-03-29 11:33:11 +00:00
|
|
|
canvas.ResetTransform();
|
2010-11-05 03:25:21 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Overridden method. The string meters need not to be bound on anything
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void MeterString::BindMeasures(ConfigParser& parser, const WCHAR* section)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-07-17 07:37:53 +00:00
|
|
|
if (BindPrimaryMeasure(parser, section, true))
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-07-17 07:37:53 +00:00
|
|
|
BindSecondaryMeasures(parser, section);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-07 16:45:14 +00:00
|
|
|
|
2010-03-20 19:40:30 +00:00
|
|
|
/*
|
|
|
|
** Static helper to log all installed font families.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void MeterString::EnumerateInstalledFontFamilies()
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
INT fontCount;
|
|
|
|
InstalledFontCollection fontCollection;
|
|
|
|
|
|
|
|
if (Ok == fontCollection.GetLastStatus())
|
|
|
|
{
|
|
|
|
fontCount = fontCollection.GetFamilyCount();
|
|
|
|
if (fontCount > 0)
|
|
|
|
{
|
|
|
|
INT fontFound;
|
|
|
|
|
|
|
|
FontFamily* fontFamilies = new FontFamily[fontCount];
|
|
|
|
|
|
|
|
if (Ok == fontCollection.GetFamilies(fontCount, fontFamilies, &fontFound))
|
|
|
|
{
|
|
|
|
std::wstring fonts;
|
2010-03-30 22:37:05 +00:00
|
|
|
for (INT i = 0; i < fontCount; ++i)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
WCHAR familyName[LF_FACESIZE];
|
|
|
|
if (Ok == fontFamilies[i].GetFamilyName(familyName))
|
|
|
|
{
|
|
|
|
fonts += familyName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fonts += L"***";
|
|
|
|
}
|
|
|
|
fonts += L", ";
|
|
|
|
}
|
2013-05-30 14:19:42 +00:00
|
|
|
LogWarning(fonts.c_str());
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-30 14:19:42 +00:00
|
|
|
LogError(L"Font enumeration: GetFamilies failed");
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete [] fontFamilies;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-30 14:19:42 +00:00
|
|
|
LogWarning(L"No installed fonts");
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-30 14:19:42 +00:00
|
|
|
LogError(L"Font enumeration: InstalledFontCollection failed");
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
2012-11-12 02:10:40 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void MeterString::InitializeStatic()
|
2012-11-12 02:10:40 +00:00
|
|
|
{
|
2013-06-13 14:20:27 +00:00
|
|
|
if (GetRainmeter().GetDebug())
|
2012-11-12 02:10:40 +00:00
|
|
|
{
|
2013-05-30 14:19:42 +00:00
|
|
|
LogDebug(L"------------------------------");
|
|
|
|
LogDebug(L"* Font families:");
|
2012-11-12 02:10:40 +00:00
|
|
|
EnumerateInstalledFontFamilies();
|
2013-05-30 14:19:42 +00:00
|
|
|
LogDebug(L"------------------------------");
|
2012-11-12 02:10:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
void MeterString::FinalizeStatic()
|
2012-11-12 02:10:40 +00:00
|
|
|
{
|
|
|
|
}
|