Added ImagePath to all meters with general image options. This deprecates the Path option for Image meters.

Also fixes bug in MeterHistogram that crashes Rainmeter when the PrimaryImage is invalid.
Note: For Histogram the option is called PrimaryImagePath, SecondaryImagePath, and BothImagePath
This commit is contained in:
Brian Ferguson 2013-06-07 13:35:36 -06:00
parent c6ec9093b7
commit 136689bcfb
9 changed files with 54 additions and 65 deletions

View File

@ -33,7 +33,7 @@ extern Rainmeter* g_Rainmeter;
**
*/
MeterBar::MeterBar(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
m_Image(L"BarImage"),
m_Image(L"BarImage", nullptr, false, meterWindow),
m_NeedsReload(false),
m_Color(Color::Green),
m_Orientation(VERTICAL),
@ -97,8 +97,6 @@ void MeterBar::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_ImageName = parser.ReadString(section, L"BarImage", L"");
if (!m_ImageName.empty())
{
m_MeterWindow->MakePathAbsolute(m_ImageName);
// Read tinting options
m_Image.ReadOptions(parser, section);
}

View File

@ -33,7 +33,7 @@ extern Rainmeter* g_Rainmeter;
**
*/
MeterBitmap::MeterBitmap(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
m_Image(L"BitmapImage", nullptr, true),
m_Image(L"BitmapImage", nullptr, true, meterWindow),
m_NeedsReload(false),
m_ZeroFrame(false),
m_FrameCount(1),
@ -167,8 +167,6 @@ void MeterBitmap::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_ImageName = parser.ReadString(section, L"BitmapImage", L"");
if (!m_ImageName.empty())
{
m_MeterWindow->MakePathAbsolute(m_ImageName);
// Read tinting options
m_Image.ReadOptions(parser, section);
}

View File

@ -39,7 +39,7 @@ enum BUTTON_STATE
**
*/
MeterButton::MeterButton(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
m_Image(L"ButtonImage", nullptr, true),
m_Image(L"ButtonImage", nullptr, true, meterWindow),
m_NeedsReload(false),
m_Bitmaps(),
m_State(BUTTON_STATE_NORMAL),
@ -139,8 +139,6 @@ void MeterButton::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_ImageName = parser.ReadString(section, L"ButtonImage", L"");
if (!m_ImageName.empty())
{
m_MeterWindow->MakePathAbsolute(m_ImageName);
// Read tinting options
m_Image.ReadOptions(parser, section);
}

View File

@ -42,9 +42,9 @@ MeterHistogram::MeterHistogram(MeterWindow* meterWindow, const WCHAR* name) : Me
m_MeterPos(),
m_Autoscale(false),
m_Flip(false),
m_PrimaryImage(L"PrimaryImage", c_PrimaryOptionArray),
m_SecondaryImage(L"SecondaryImage", c_SecondaryOptionArray),
m_OverlapImage(L"BothImage", c_BothOptionArray),
m_PrimaryImage(L"PrimaryImage", c_PrimaryOptionArray, false, meterWindow),
m_SecondaryImage(L"SecondaryImage", c_SecondaryOptionArray, false, meterWindow),
m_OverlapImage(L"BothImage", c_BothOptionArray, false, meterWindow),
m_PrimaryNeedsReload(false),
m_SecondaryNeedsReload(false),
m_OverlapNeedsReload(false),
@ -212,8 +212,6 @@ void MeterHistogram::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_PrimaryImageName = parser.ReadString(section, L"PrimaryImage", L"");
if (!m_PrimaryImageName.empty())
{
m_MeterWindow->MakePathAbsolute(m_PrimaryImageName);
// Read tinting options
m_PrimaryImage.ReadOptions(parser, section);
}
@ -225,8 +223,6 @@ void MeterHistogram::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_SecondaryImageName = parser.ReadString(section, L"SecondaryImage", L"");
if (!m_SecondaryImageName.empty())
{
m_MeterWindow->MakePathAbsolute(m_SecondaryImageName);
// Read tinting options
m_SecondaryImage.ReadOptions(parser, section);
}
@ -238,8 +234,6 @@ void MeterHistogram::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_OverlapImageName = parser.ReadString(section, L"BothImage", L"");
if (!m_OverlapImageName.empty())
{
m_MeterWindow->MakePathAbsolute(m_OverlapImageName);
// Read tinting options
m_OverlapImage.ReadOptions(parser, section);
}
@ -329,7 +323,7 @@ bool MeterHistogram::Update()
{
int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
if (maxSize > 0) // m_PrimaryValues is not nullptr
if (m_PrimaryValues && maxSize > 0) // m_PrimaryValues must not be nullptr
{
Measure* measure = m_Measures[0];
Measure* secondaryMeasure = (m_Measures.size() >= 2) ? m_Measures[1] : nullptr;

View File

@ -33,6 +33,7 @@ using namespace Gdiplus;
**
*/
MeterImage::MeterImage(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
m_Image(L"ImageName", nullptr, false, meterWindow),
m_NeedsRedraw(false),
m_DrawMode(DRAWMODE_NONE),
m_ScaleMargins()
@ -57,10 +58,7 @@ void MeterImage::Initialize()
if (m_Measures.empty() && !m_DynamicVariables && !m_ImageName.empty())
{
m_ImageNameResult = m_Path;
m_ImageNameResult += m_ImageName;
m_MeterWindow->MakePathAbsolute(m_ImageNameResult);
LoadImage(m_ImageNameResult, true);
LoadImage(m_ImageName, true);
}
}
@ -110,15 +108,6 @@ void MeterImage::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
Meter::ReadOptions(parser, section);
m_Path = parser.ReadString(section, L"Path", L"");
if (!m_Path.empty())
{
if (!System::IsPathSeparator(m_Path[m_Path.length() - 1]))
{
m_Path += L'\\';
}
}
m_ImageName = parser.ReadString(section, L"ImageName", L"");
int mode = parser.ReadInt(section, L"Tile", 0);
@ -147,8 +136,18 @@ void MeterImage::ReadOptions(ConfigParser& parser, const WCHAR* section)
static const RECT defMargins = {0};
m_ScaleMargins = parser.ReadRECT(section, L"ScaleMargins", defMargins);
// Deprecated!
std::wstring path = parser.ReadString(section, L"Path", L"");
if (!path.empty())
{
if (!System::IsPathSeparator(path[path.length() - 1]))
{
path += L'\\';
}
}
// Read tinting options
m_Image.ReadOptions(parser, section);
m_Image.ReadOptions(parser, section, path.c_str());
if (m_Initialized && m_Measures.empty() && !m_DynamicVariables)
{
@ -168,38 +167,26 @@ bool MeterImage::Update()
if (!m_Measures.empty() || m_DynamicVariables)
{
// Store the current values so we know if the image needs to be updated
std::wstring oldResult = m_ImageNameResult;
std::wstring oldResult = m_ImageName;
if (!m_Measures.empty()) // read from the measures
{
if (m_ImageName.empty())
{
m_ImageNameResult = m_Measures[0]->GetStringOrFormattedValue(
AUTOSCALE_OFF, 1, 0, false);
m_ImageName = m_Measures[0]->GetStringOrFormattedValue(AUTOSCALE_OFF, 1, 0, false);
}
else
{
m_ImageNameResult = m_ImageName;
if (!ReplaceMeasures(m_ImageNameResult, AUTOSCALE_OFF))
m_ImageName = m_ImageName;
if (!ReplaceMeasures(m_ImageName, AUTOSCALE_OFF))
{
// ImageName doesn't contain any measures, so use the result of MeasureName.
m_ImageNameResult = m_Measures[0]->GetStringOrFormattedValue(
AUTOSCALE_OFF, 1, 0, false);
m_ImageName = m_Measures[0]->GetStringOrFormattedValue(AUTOSCALE_OFF, 1, 0, false);
}
}
}
else // read from the skin
{
m_ImageNameResult = m_ImageName;
}
if (!m_ImageNameResult.empty())
{
m_ImageNameResult.insert(0, m_Path);
m_MeterWindow->MakePathAbsolute(m_ImageNameResult);
}
LoadImage(m_ImageNameResult, (wcscmp(oldResult.c_str(), m_ImageNameResult.c_str()) != 0));
LoadImage(m_ImageName, (wcscmp(oldResult.c_str(), m_ImageName.c_str()) != 0));
return true;
}
else if (m_NeedsRedraw)

View File

@ -38,7 +38,7 @@ protected:
virtual void ReadOptions(ConfigParser& parser, const WCHAR* section);
virtual void BindMeasures(ConfigParser& parser, const WCHAR* section);
virtual bool IsFixedSize(bool overwrite = false) { return overwrite ? true : m_ImageNameResult.empty(); }
virtual bool IsFixedSize(bool overwrite = false) { return overwrite ? true : m_ImageName.empty(); }
private:
enum DRAWMODE
@ -53,8 +53,6 @@ private:
TintedImage m_Image;
std::wstring m_ImageName;
std::wstring m_ImageNameResult; // Image name as absolute path
std::wstring m_Path;
bool m_NeedsRedraw;
DRAWMODE m_DrawMode;

View File

@ -36,6 +36,7 @@ extern Rainmeter* g_Rainmeter;
**
*/
MeterRotator::MeterRotator(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
m_Image(L"ImageName", nullptr, false, meterWindow),
m_NeedsReload(false),
m_OffsetX(),
m_OffsetY(),
@ -87,8 +88,6 @@ void MeterRotator::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_ImageName = parser.ReadString(section, L"ImageName", L"");
if (!m_ImageName.empty())
{
m_MeterWindow->MakePathAbsolute(m_ImageName);
// Read tinting options
m_Image.ReadOptions(parser, section);
}

View File

@ -151,8 +151,8 @@ TintedImageHelper_DefineOptionArray(TintedImage::c_DefaultOptionArray, L"");
** If disableTransform is true, ImageCrop and ImageRotate are ignored.
**
*/
TintedImage::TintedImage(const WCHAR* name, const WCHAR** optionArray, bool disableTransform) : m_DisableTransform(disableTransform),
m_Name(name ? name : L"Image"),
TintedImage::TintedImage(const WCHAR* name, const WCHAR** optionArray, bool disableTransform, MeterWindow* meterWindow) : m_DisableTransform(disableTransform),
m_Name(name ? name : L"ImageName"),
m_OptionArray(optionArray ? optionArray : c_DefaultOptionArray),
m_Bitmap(),
m_BitmapTint(),
@ -165,7 +165,8 @@ TintedImage::TintedImage(const WCHAR* name, const WCHAR** optionArray, bool disa
m_ColorMatrix(new ColorMatrix(c_IdentityMatrix)),
m_Flip(RotateNoneFlipNone),
m_Rotate(),
m_UseExifOrientation(false)
m_UseExifOrientation(false),
m_MeterWindow(meterWindow)
{
}
@ -315,7 +316,8 @@ void TintedImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
// Load the bitmap if defined
if (!imageName.empty())
{
std::wstring filename = imageName;
std::wstring filename = m_Path + imageName;
if (m_MeterWindow) m_MeterWindow->MakePathAbsolute(filename);
// Check extension and if it is missing, add .png
size_t pos = filename.rfind(L'\\');
@ -615,7 +617,7 @@ void TintedImage::ApplyTransform()
** Read the meter-specific options from the ini-file.
**
*/
void TintedImage::ReadOptions(ConfigParser& parser, const WCHAR* section)
void TintedImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const WCHAR* imagePath)
{
// Store the current values so we know if the image needs to be tinted or transformed
Rect oldCrop = m_Crop;
@ -625,6 +627,15 @@ void TintedImage::ReadOptions(ConfigParser& parser, const WCHAR* section)
RotateFlipType oldFlip = m_Flip;
REAL oldRotate = m_Rotate;
m_Path = parser.ReadString(section, m_OptionArray[OptionIndexImagePath], imagePath);
if (!m_Path.empty())
{
if (!System::IsPathSeparator(m_Path[m_Path.length() - 1]))
{
m_Path += L'\\';
}
}
if (!m_DisableTransform)
{
m_Crop.X = m_Crop.Y = m_Crop.Width = m_Crop.Height = -1;

View File

@ -22,6 +22,7 @@
#include <windows.h>
#include <gdiplus.h>
#include <string>
#include "MeterWindow.h"
/*
** Helper macro to define an array of option names. A prefix must be given.
@ -40,7 +41,8 @@
prefix L"ColorMatrix5", \
prefix L"ImageFlip", \
prefix L"ImageRotate", \
prefix L"UseExifOrientation" \
prefix L"UseExifOrientation", \
prefix L"ImagePath" \
};
class ConfigParser;
@ -62,14 +64,15 @@ public:
OptionIndexImageFlip,
OptionIndexImageRotate,
OptionIndexUseExifOrientation,
OptionIndexImagePath,
OptionCount
};
TintedImage(const WCHAR* name = L"Image", const WCHAR** optionArray = c_DefaultOptionArray, bool disableTransform = false);
TintedImage(const WCHAR* name = L"ImageName", const WCHAR** optionArray = c_DefaultOptionArray, bool disableTransform = false, MeterWindow* meterWindow = nullptr);
~TintedImage();
void ReadOptions(ConfigParser& parser, const WCHAR* section);
void ReadOptions(ConfigParser& parser, const WCHAR* section, const WCHAR* imagePath = L"");
bool IsLoaded() { return (m_Bitmap != nullptr); }
bool IsTinted() { return (m_BitmapTint != nullptr); }
@ -120,9 +123,12 @@ protected:
Gdiplus::RotateFlipType m_Flip;
Gdiplus::REAL m_Rotate;
bool m_UseExifOrientation;
std::wstring m_Path;
std::wstring m_CacheKey;
MeterWindow* m_MeterWindow;
static const Gdiplus::ColorMatrix c_GreyScaleMatrix;
static const Gdiplus::ColorMatrix c_IdentityMatrix;