Native cursor fixes

This commit is contained in:
momo5502 2016-01-01 15:17:59 +01:00
parent f3fef92c46
commit 4bc3ec10b1
2 changed files with 69 additions and 8 deletions

View File

@ -8,6 +8,59 @@ namespace Components
HWND Window::MainWindow = 0; HWND Window::MainWindow = 0;
BOOL Window::CursorVisible = TRUE; BOOL Window::CursorVisible = TRUE;
int Window::Width()
{
return Window::Width(Window::MainWindow);
}
int Window::Height()
{
return Window::Height(Window::MainWindow);
}
int Window::Width(HWND window)
{
RECT rect;
Window::Dimension(window, &rect);
return (rect.right - rect.left);
}
int Window::Height(HWND window)
{
RECT rect;
Window::Dimension(window, &rect);
return (rect.bottom - rect.top);
}
void Window::Dimension(RECT* rect)
{
Window::Dimension(Window::MainWindow, rect);
}
void Window::Dimension(HWND window, RECT* rect)
{
if (rect)
{
ZeroMemory(rect, sizeof(RECT));
if (window && IsWindow(window))
{
GetWindowRect(window, rect);
}
}
}
bool Window::IsCursorWithin(HWND window)
{
RECT rect;
POINT point;
Window::Dimension(window, &rect);
GetCursorPos(&point);
return ((point.x - rect.left) > 0 && (point.y - rect.top) > 0 && (rect.right - point.x) > 0 && (rect.bottom - point.y) > 0);
}
void __declspec(naked) Window::StyleHookStub() void __declspec(naked) Window::StyleHookStub()
{ {
if (Window::NoBorder.Get<bool>()) if (Window::NoBorder.Get<bool>())
@ -36,7 +89,7 @@ namespace Components
int WINAPI Window::ShowCursorHook(BOOL show) int WINAPI Window::ShowCursorHook(BOOL show)
{ {
if (Window::NativeCursor.Get<bool>() && GetForegroundWindow() == Window::MainWindow) if (Window::NativeCursor.Get<bool>() && GetForegroundWindow() == Window::MainWindow && Window::IsCursorWithin(Window::MainWindow))
{ {
static int count = 0; static int count = 0;
(show ? ++count : --count); (show ? ++count : --count);
@ -76,7 +129,7 @@ namespace Components
// Draw the cursor if necessary // Draw the cursor if necessary
Renderer::OnFrame([] () Renderer::OnFrame([] ()
{ {
if (Window::NativeCursor.Get<bool>() && GetForegroundWindow() == Window::MainWindow) if (Window::NativeCursor.Get<bool>() && GetForegroundWindow() == Window::MainWindow && Window::IsCursorWithin(Window::MainWindow))
{ {
int value = 0; int value = 0;

View File

@ -6,18 +6,26 @@ namespace Components
Window(); Window();
const char* GetName() { return "Window"; }; const char* GetName() { return "Window"; };
static Dvar::Var NoBorder; static int Width();
static Dvar::Var NativeCursor; static int Height();
static void Window::StyleHookStub(); static int Width(HWND window);
static int Height(HWND window);
static void Dimension(RECT* rect);
static void Dimension(HWND window, RECT* rect);
static bool IsCursorWithin(HWND window);
private: private:
static BOOL CursorVisible; static BOOL CursorVisible;
static Dvar::Var NoBorder;
static int WINAPI ShowCursorHook(BOOL show); static Dvar::Var NativeCursor;
static void DrawCursorStub(void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Game::Material *material);
static HWND MainWindow; static HWND MainWindow;
static int WINAPI ShowCursorHook(BOOL show);
static void DrawCursorStub(void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Game::Material *material);
static void StyleHookStub();
static HWND WINAPI CreateMainWindow(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam); static HWND WINAPI CreateMainWindow(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
}; };
} }