Added special mouse variables

This commit is contained in:
Brian Ferguson 2013-01-15 17:51:02 -07:00
parent e2c88e0946
commit 9da869363d
3 changed files with 135 additions and 32 deletions

View File

@ -4300,7 +4300,7 @@ LRESULT CMeterWindow::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam)
*/ */
bool CMeterWindow::DoAction(int x, int y, MOUSEACTION action, bool test) bool CMeterWindow::DoAction(int x, int y, MOUSEACTION action, bool test)
{ {
const WCHAR* command = NULL; std::wstring command = L"";
// Check if the hitpoint was over some meter // Check if the hitpoint was over some meter
std::vector<CMeter*>::const_reverse_iterator j = m_Meters.rbegin(); std::vector<CMeter*>::const_reverse_iterator j = m_Meters.rbegin();
@ -4309,24 +4309,24 @@ bool CMeterWindow::DoAction(int x, int y, MOUSEACTION action, bool test)
// Hidden meters are ignored // Hidden meters are ignored
if ((*j)->IsHidden()) continue; if ((*j)->IsHidden()) continue;
const WCHAR* meterCommand = (*j)->GetMouse().GetActionCommand(action); std::wstring meterCommand = (*j)->GetMouse().GetActionCommand(action);
if (meterCommand && (*j)->HitTest(x, y)) if (!meterCommand.empty() && (*j)->HitTest(x, y))
{ {
command = meterCommand; command = meterCommand;
break; break;
} }
} }
if (!command && HitTest(x, y)) if (command.empty() && HitTest(x, y))
{ {
command = m_Mouse.GetActionCommand(action); command = m_Mouse.GetActionCommand(action).c_str();
} }
if (command) if (!command.empty())
{ {
if (!test) if (!test)
{ {
Rainmeter->ExecuteCommand(command, this); Rainmeter->ExecuteCommand(command.c_str(), this);
} }
return true; return true;

View File

@ -19,13 +19,15 @@
#include "StdAfx.h" #include "StdAfx.h"
#include "ConfigParser.h" #include "ConfigParser.h"
#include "MeterWindow.h" #include "MeterWindow.h"
#include "Meter.h"
#include "Litestep.h" #include "Litestep.h"
#include "Mouse.h" #include "Mouse.h"
CMouse::CMouse() : CMouse::CMouse() :
m_CursorType(MOUSECURSOR_HAND), m_CursorType(MOUSECURSOR_HAND),
m_CustomCursor(), m_CustomCursor(),
m_CursorState(true) m_CursorState(true),
m_MeterWindow()
{ {
} }
@ -36,6 +38,9 @@ CMouse::~CMouse()
void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section, CMeterWindow* meterWindow) void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section, CMeterWindow* meterWindow)
{ {
m_MeterWindow = meterWindow;
m_MeterName = section;
DestroyCustomCursor(); DestroyCustomCursor();
m_LeftDownAction = parser.ReadString(section, L"LeftMouseDownAction", L"", false); m_LeftDownAction = parser.ReadString(section, L"LeftMouseDownAction", L"", false);
@ -166,90 +171,92 @@ HCURSOR CMouse::GetCursor() const
return LoadCursor(NULL, name); return LoadCursor(NULL, name);
} }
const WCHAR* CMouse::GetActionCommand(MOUSEACTION action) const std::wstring CMouse::GetActionCommand(MOUSEACTION action) const
{ {
const WCHAR* command = NULL; std::wstring command = L"";
switch (action) switch (action)
{ {
case MOUSE_LMB_DOWN: case MOUSE_LMB_DOWN:
command = m_LeftDownAction.c_str(); command = m_LeftDownAction;
break; break;
case MOUSE_LMB_UP: case MOUSE_LMB_UP:
command = m_LeftUpAction.c_str(); command = m_LeftUpAction;
break; break;
case MOUSE_LMB_DBLCLK: case MOUSE_LMB_DBLCLK:
command = m_LeftDoubleClickAction.c_str(); command = m_LeftDoubleClickAction;
break; break;
case MOUSE_RMB_DOWN: case MOUSE_RMB_DOWN:
command = m_RightDownAction.c_str(); command = m_RightDownAction;
break; break;
case MOUSE_RMB_UP: case MOUSE_RMB_UP:
command = m_RightUpAction.c_str(); command = m_RightUpAction;
break; break;
case MOUSE_RMB_DBLCLK: case MOUSE_RMB_DBLCLK:
command = m_RightDoubleClickAction.c_str(); command = m_RightDoubleClickAction;
break; break;
case MOUSE_MMB_DOWN: case MOUSE_MMB_DOWN:
command = m_MiddleDownAction.c_str(); command = m_MiddleDownAction;
break; break;
case MOUSE_MMB_UP: case MOUSE_MMB_UP:
command = m_MiddleUpAction.c_str(); command = m_MiddleUpAction;
break; break;
case MOUSE_MMB_DBLCLK: case MOUSE_MMB_DBLCLK:
command = m_MiddleDoubleClickAction.c_str(); command = m_MiddleDoubleClickAction;
break; break;
case MOUSE_MW_DOWN: case MOUSE_MW_DOWN:
command = m_MouseScrollDownAction.c_str(); command = m_MouseScrollDownAction;
break; break;
case MOUSE_MW_UP: case MOUSE_MW_UP:
command = m_MouseScrollUpAction.c_str(); command = m_MouseScrollUpAction;
break; break;
case MOUSE_MW_LEFT: case MOUSE_MW_LEFT:
command = m_MouseScrollLeftAction.c_str(); command = m_MouseScrollLeftAction;
break; break;
case MOUSE_MW_RIGHT: case MOUSE_MW_RIGHT:
command = m_MouseScrollRightAction.c_str(); command = m_MouseScrollRightAction;
break; break;
case MOUSE_X1MB_DOWN: case MOUSE_X1MB_DOWN:
command = m_X1DownAction.c_str(); command = m_X1DownAction;
break; break;
case MOUSE_X1MB_UP: case MOUSE_X1MB_UP:
command = m_X1UpAction.c_str(); command = m_X1UpAction;
break; break;
case MOUSE_X1MB_DBLCLK: case MOUSE_X1MB_DBLCLK:
command = m_X1DoubleClickAction.c_str(); command = m_X1DoubleClickAction;
break; break;
case MOUSE_X2MB_DOWN: case MOUSE_X2MB_DOWN:
command = m_X2DownAction.c_str(); command = m_X2DownAction;
break; break;
case MOUSE_X2MB_UP: case MOUSE_X2MB_UP:
command = m_X2UpAction.c_str(); command = m_X2UpAction;
break; break;
case MOUSE_X2MB_DBLCLK: case MOUSE_X2MB_DBLCLK:
command = m_X2DoubleClickAction.c_str(); command = m_X2DoubleClickAction;
break; break;
} }
return *command ? command : NULL; ReplaceMouseVariables(command);
return command;
} }
void CMouse::DestroyCustomCursor() void CMouse::DestroyCustomCursor()
@ -259,4 +266,94 @@ void CMouse::DestroyCustomCursor()
DestroyCursor(m_CustomCursor); DestroyCursor(m_CustomCursor);
m_CustomCursor = NULL; m_CustomCursor = NULL;
} }
}
void CMouse::ReplaceMouseVariables(std::wstring& result) const
{
// Check for variables ($VAR$)
size_t start = 0, end;
bool loop = true;
do
{
start = result.find(L'$', start);
if (start != std::wstring::npos)
{
size_t si = start + 1;
end = result.find(L'$', si);
if (end != std::wstring::npos)
{
size_t ei = end - 1;
if (si != ei && result[si] == L'*' && result[ei] == L'*')
{
result.erase(ei, 1);
result.erase(si, 1);
start = ei;
}
else
{
std::wstring strVariable = result.substr(si, end - si);
std::wstring value = GetMouseVariable(strVariable);
if (!value.empty())
{
// Variable found, replace it with the value
result.replace(start, end - start + 1, value);
start += value.length();
}
else
{
start = end;
}
}
}
else
{
loop = false;
}
}
else
{
loop = false;
}
}
while (loop);
}
std::wstring CMouse::GetMouseVariable(std::wstring variable) const
{
std::wstring result = L"";
POINT pt;
GetCursorPos(&pt);
CMeter* meter = m_MeterWindow->GetMeter(m_MeterName);
if (_wcsnicmp(variable.c_str(), L"MOUSEX", 6) == 0)
{
double xOffset = (double)(m_MeterWindow->GetX() + (meter ? meter->GetX() : 0) - 1);
if (_wcsicmp(variable.c_str(), L"MOUSEX:%") == 0)
{
xOffset = ((pt.x - xOffset) / (meter ? meter->GetW() : m_MeterWindow->GetW())) * 100;
result = std::to_wstring((int)xOffset);
}
else
{
result = std::to_wstring((long)(pt.x - xOffset));
}
}
else if (_wcsnicmp(variable.c_str(), L"MOUSEY", 6) == 0)
{
double yOffset = (double)(m_MeterWindow->GetY() + (meter ? meter->GetY() : 0) - 1);
if (_wcsicmp(variable.c_str(), L"MOUSEY:%") == 0)
{
yOffset = ((pt.y - yOffset) / (meter ? meter->GetH() : m_MeterWindow->GetH())) * 100;
result = std::to_wstring((int)yOffset);
}
else
{
result = std::to_wstring((long)(pt.y - yOffset));
}
}
return result;
} }

View File

@ -70,7 +70,7 @@ public:
void DestroyCustomCursor(); void DestroyCustomCursor();
const WCHAR* GetActionCommand(MOUSEACTION action) const; std::wstring GetActionCommand(MOUSEACTION action) const;
const std::wstring& GetRightDownAction() const { return m_RightDownAction; } const std::wstring& GetRightDownAction() const { return m_RightDownAction; }
const std::wstring& GetRightUpAction() const { return m_RightUpAction; } const std::wstring& GetRightUpAction() const { return m_RightUpAction; }
@ -95,6 +95,9 @@ public:
const std::wstring& GetX2DoubleClickAction() const { return m_X2DoubleClickAction; } const std::wstring& GetX2DoubleClickAction() const { return m_X2DoubleClickAction; }
private: private:
void ReplaceMouseVariables(std::wstring& result) const;
std::wstring GetMouseVariable(std::wstring variable) const;
std::wstring m_LeftDownAction; std::wstring m_LeftDownAction;
std::wstring m_RightDownAction; std::wstring m_RightDownAction;
std::wstring m_MiddleDownAction; std::wstring m_MiddleDownAction;
@ -120,6 +123,9 @@ private:
MOUSECURSOR m_CursorType; MOUSECURSOR m_CursorType;
HCURSOR m_CustomCursor; HCURSOR m_CustomCursor;
bool m_CursorState; bool m_CursorState;
CMeterWindow* m_MeterWindow;
std::wstring m_MeterName;
}; };
#endif #endif