From ed9ea73e6b41c085d2e4ca1e355b8ec893b7dd77 Mon Sep 17 00:00:00 2001 From: spx Date: Tue, 16 Jul 2013 12:26:31 +0900 Subject: [PATCH] Changed Button meter behavior. Now ignores transparent area of the button when mouseover. --- Library/MeterButton.cpp | 35 ++++++++++++++--------------------- Library/MeterButton.h | 4 ++-- Library/MeterWindow.cpp | 22 +++++++++++++++++----- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Library/MeterButton.cpp b/Library/MeterButton.cpp index 5c9c1bc5..0f5c7530 100644 --- a/Library/MeterButton.cpp +++ b/Library/MeterButton.cpp @@ -210,7 +210,7 @@ void MeterButton::BindMeasures(ConfigParser& parser, const WCHAR* section) ** Checks if the given point is inside the button. ** */ -bool MeterButton::HitTest2(int px, int py, bool checkAlpha) +bool MeterButton::HitTest2(int px, int py) { int x = GetX(); int y = GetY(); @@ -219,24 +219,17 @@ bool MeterButton::HitTest2(int px, int py, bool checkAlpha) px >= x && px < x + m_W && py >= y && py < y + m_H) { - if (checkAlpha) + if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0) { - if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0) - { - return true; - } + return true; + } - // Check transparent pixels - if (m_Image.IsLoaded()) - { - Color color; - Status status = m_Image.GetImage()->GetPixel(px - x + m_W * m_State, py - y, &color); - if (status != Ok || color.GetA() != 0) - { - return true; - } - } - else + // Check transparent pixels + if (m_Image.IsLoaded()) + { + Color color; + Status status = m_Image.GetImage()->GetPixel(px - x + m_W * m_State, py - y, &color); + if (status != Ok || color.GetA() != 0) { return true; } @@ -253,7 +246,7 @@ bool MeterButton::MouseUp(POINT pos, bool execute) { if (m_State == BUTTON_STATE_DOWN) { - if (execute && m_Clicked && m_Focus && HitTest2(pos.x, pos.y, true)) + if (execute && m_Clicked && m_Focus && HitTest2(pos.x, pos.y)) { GetRainmeter().ExecuteCommand(m_Command.c_str(), m_MeterWindow); } @@ -268,7 +261,7 @@ bool MeterButton::MouseUp(POINT pos, bool execute) bool MeterButton::MouseDown(POINT pos) { - if (m_Focus && HitTest2(pos.x, pos.y, true)) + if (m_Focus && HitTest2(pos.x, pos.y)) { m_State = BUTTON_STATE_DOWN; m_Clicked = true; @@ -281,7 +274,7 @@ bool MeterButton::MouseMove(POINT pos) { if (m_Clicked) { - if (HitTest2(pos.x, pos.y, true)) + if (HitTest2(pos.x, pos.y)) { if (m_State == BUTTON_STATE_NORMAL) { @@ -306,7 +299,7 @@ bool MeterButton::MouseMove(POINT pos) } else { - if (HitTest2(pos.x, pos.y, false)) + if (HitTest2(pos.x, pos.y)) { if (m_State == BUTTON_STATE_NORMAL) { diff --git a/Library/MeterButton.h b/Library/MeterButton.h index 41c901b1..99511b8b 100644 --- a/Library/MeterButton.h +++ b/Library/MeterButton.h @@ -42,6 +42,8 @@ public: void SetFocus(bool f) { m_Focus = f; } + bool HitTest2(int px, int py); + protected: virtual void ReadOptions(ConfigParser& parser, const WCHAR* section); virtual void BindMeasures(ConfigParser& parser, const WCHAR* section); @@ -49,8 +51,6 @@ protected: virtual bool IsFixedSize(bool overwrite = false) { return overwrite; } private: - bool HitTest2(int px, int py, bool checkAlpha); - TintedImage m_Image; std::wstring m_ImageName; bool m_NeedsReload; diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index d4b101e7..0f014f77 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -3181,12 +3181,24 @@ void MeterWindow::HandleButtons(POINT pos, BUTTONPROC proc, bool execute) } } - if (!cursor && - ((*j)->HasMouseAction() || button) && - (*j)->GetMouse().GetCursorState() && - (*j)->HitTest(pos.x, pos.y)) + // Get cursor if required + if (!cursor && (*j)->GetMouse().GetCursorState()) { - cursor = (*j)->GetMouse().GetCursor(); + if ((*j)->HasMouseAction()) + { + if ((*j)->HitTest(pos.x, pos.y)) + { + cursor = (*j)->GetMouse().GetCursor(); + } + } + else + { + // Special case for Button meter: reacts only on valid pixel in button image + if (button && button->HitTest2(pos.x, pos.y)) + { + cursor = (*j)->GetMouse().GetCursor(); + } + } } }