diff --git a/Library/MeterBar.cpp b/Library/MeterBar.cpp index c81fc0d9..39b5316f 100644 --- a/Library/MeterBar.cpp +++ b/Library/MeterBar.cpp @@ -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); } diff --git a/Library/MeterBitmap.cpp b/Library/MeterBitmap.cpp index a612cb26..babfcb45 100644 --- a/Library/MeterBitmap.cpp +++ b/Library/MeterBitmap.cpp @@ -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); } diff --git a/Library/MeterButton.cpp b/Library/MeterButton.cpp index c34c0d0e..37e8ad83 100644 --- a/Library/MeterButton.cpp +++ b/Library/MeterButton.cpp @@ -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); } diff --git a/Library/MeterHistogram.cpp b/Library/MeterHistogram.cpp index 8a822fe8..e12b30dd 100644 --- a/Library/MeterHistogram.cpp +++ b/Library/MeterHistogram.cpp @@ -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; diff --git a/Library/MeterImage.cpp b/Library/MeterImage.cpp index 18b74356..90846326 100644 --- a/Library/MeterImage.cpp +++ b/Library/MeterImage.cpp @@ -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) diff --git a/Library/MeterImage.h b/Library/MeterImage.h index e3633e88..fd03177f 100644 --- a/Library/MeterImage.h +++ b/Library/MeterImage.h @@ -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; diff --git a/Library/MeterRotator.cpp b/Library/MeterRotator.cpp index e7a3283a..b8105582 100644 --- a/Library/MeterRotator.cpp +++ b/Library/MeterRotator.cpp @@ -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); } diff --git a/Library/TintedImage.cpp b/Library/TintedImage.cpp index fe3d2d45..b78dc8a8 100644 --- a/Library/TintedImage.cpp +++ b/Library/TintedImage.cpp @@ -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; diff --git a/Library/TintedImage.h b/Library/TintedImage.h index 14325b8d..572e736e 100644 --- a/Library/TintedImage.h +++ b/Library/TintedImage.h @@ -22,6 +22,7 @@ #include #include #include +#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;