diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 87b791a3..e923d975 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -109,6 +109,15 @@ CMeterWindow::CMeterWindow(const std::wstring& path, const std::wstring& config, m_BackgroundSize.cx = 0; m_BackgroundSize.cy = 0; + m_BackgroundMargins.left = 0; + m_BackgroundMargins.top = 0; + m_BackgroundMargins.right = 0; + m_BackgroundMargins.bottom = 0; + m_DragMargins.left = 0; + m_DragMargins.top = 0; + m_DragMargins.right = 0; + m_DragMargins.bottom = 0; + m_FadeStartTime = 0; m_FadeStartValue = 0; m_FadeEndValue = 0; @@ -1736,13 +1745,9 @@ bool CMeterWindow::ReadSkin() m_BackgroundName = m_Parser.ReadString(L"Rainmeter", L"Background", L""); m_BackgroundName = MakePathAbsolute(m_BackgroundName); - m_BackgroundMargins = m_Parser.ReadRect(L"Rainmeter", L"BackgroundMargins", Rect(0,0,0,0)); - m_BackgroundMargins.Width -= m_BackgroundMargins.X; - m_BackgroundMargins.Height -= m_BackgroundMargins.Y; - - m_DragMargins = m_Parser.ReadRect(L"Rainmeter", L"DragMargins", Rect(0,0,0,0)); - m_DragMargins.Width -= m_DragMargins.X; - m_DragMargins.Height -= m_DragMargins.Y; + static const RECT defMargins = {0}; + m_BackgroundMargins = m_Parser.ReadRECT(L"Rainmeter", L"BackgroundMargins", defMargins); + m_DragMargins = m_Parser.ReadRECT(L"Rainmeter", L"DragMargins", defMargins); m_BackgroundMode = (BGMODE)m_Parser.ReadInt(L"Rainmeter", L"BackgroundMode", BGMODE_IMAGE); m_SolidBevel = (BEVELTYPE)m_Parser.ReadInt(L"Rainmeter", L"BevelType", BEVELTYPE_NONE); @@ -2066,8 +2071,8 @@ void CMeterWindow::InitializeMeters() */ bool CMeterWindow::ResizeWindow(bool reset) { - int w = m_BackgroundMargins.GetLeft(); - int h = m_BackgroundMargins.GetTop(); + int w = m_BackgroundMargins.left; + int h = m_BackgroundMargins.top; // Get the largest meter point std::list::const_iterator j = m_Meters.begin(); @@ -2079,8 +2084,8 @@ bool CMeterWindow::ResizeWindow(bool reset) h = max(h, mb); } - w += m_BackgroundMargins.GetRight(); - h += m_BackgroundMargins.GetBottom(); + w += m_BackgroundMargins.right; + h += m_BackgroundMargins.bottom; w = max(w, m_BackgroundSize.cx); h = max(h, m_BackgroundSize.cy); @@ -2139,7 +2144,7 @@ bool CMeterWindow::ResizeWindow(bool reset) if (m_BackgroundMode == BGMODE_SCALED_IMAGE) { - RECT m = {m_BackgroundMargins.GetLeft(), m_BackgroundMargins.GetTop(), m_BackgroundMargins.GetRight(), m_BackgroundMargins.GetBottom()}; + const RECT& m = m_BackgroundMargins; if (m.top > 0) { @@ -3509,10 +3514,10 @@ LRESULT CMeterWindow::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam) pos.y = (SHORT)HIWORD(lParam); MapWindowPoints(NULL, m_Window, &pos, 1); - int x1 = m_DragMargins.GetLeft(); - int x2 = m_WindowW - m_DragMargins.GetRight(); - int y1 = m_DragMargins.GetTop(); - int y2 = m_WindowH - m_DragMargins.GetBottom(); + int x1 = m_DragMargins.left; + int x2 = m_WindowW - m_DragMargins.right; + int y1 = m_DragMargins.top; + int y2 = m_WindowH - m_DragMargins.bottom; if (x1 < 0) x1 += m_WindowW; if (y1 < 0) y1 += m_WindowH; diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index f8994a62..07c87096 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -297,8 +297,8 @@ private: std::wstring m_Author; // Skin's author std::wstring m_ConfigGroup; std::wstring m_BackgroundName; // Name of the background image - Gdiplus::Rect m_BackgroundMargins; - Gdiplus::Rect m_DragMargins; + RECT m_BackgroundMargins; + RECT m_DragMargins; std::wstring m_WindowX; // Window's X-position in config file std::wstring m_WindowY; // Window's Y-position in config file std::wstring m_AnchorX; // Anchor's X-position in config file diff --git a/Library/TintedImage.h b/Library/TintedImage.h index ab909a33..3069083c 100644 --- a/Library/TintedImage.h +++ b/Library/TintedImage.h @@ -22,15 +22,6 @@ #include "Meter.h" #include "MeterWindow.h" -enum CROPMODE -{ - CROPMODE_TL = 1, - CROPMODE_TR, - CROPMODE_BR, - CROPMODE_BL, - CROPMODE_C -}; - class CTintedImage { public: @@ -53,6 +44,15 @@ public: void LoadImage(const std::wstring& imageName, bool bLoadAlways); protected: + enum CROPMODE + { + CROPMODE_TL = 1, + CROPMODE_TR, + CROPMODE_BR, + CROPMODE_BL, + CROPMODE_C + }; + void ApplyCrop(); void ApplyTint(); void ApplyTransform(); diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index 762402cc..9e303e8a 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -291,6 +291,9 @@ HICON CTrayWindow::CreateTrayIcon(double value) void CTrayWindow::ReadConfig(CConfigParser& parser) { + delete m_Measure; + m_Measure = NULL; + for (size_t i = 0; i < m_TrayIcons.size(); ++i) { DestroyIcon(m_TrayIcons[i]); @@ -299,15 +302,29 @@ void CTrayWindow::ReadConfig(CConfigParser& parser) std::wstring measureName = parser.ReadString(L"TrayMeasure", L"Measure", L""); - CConfigParser* oldParser = Rainmeter->GetCurrentParser(); - Rainmeter->SetCurrentParser(&parser); if (!measureName.empty()) { - m_Measure = CMeasure::Create(measureName.c_str(), NULL); - m_Measure->SetName(L"TrayMeasure"); - m_Measure->ReadConfig(parser, L"TrayMeasure"); + CConfigParser* oldParser = Rainmeter->GetCurrentParser(); + Rainmeter->SetCurrentParser(&parser); + + try + { + m_Measure = CMeasure::Create(measureName.c_str(), NULL); + if (m_Measure) + { + m_Measure->SetName(L"TrayMeasure"); + m_Measure->ReadConfig(parser, L"TrayMeasure"); + } + } + catch (CError& error) + { + delete m_Measure; + m_Measure = NULL; + MessageBox(m_Window, error.GetString().c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); + } + + Rainmeter->SetCurrentParser(oldParser); } - Rainmeter->SetCurrentParser(oldParser); m_MeterType = TRAY_METER_TYPE_NONE;