summaryrefslogtreecommitdiff
path: root/video/win32_v.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-03-24 00:42:35 +0000
committerDarkvater <darkvater@openttd.org>2006-03-24 00:42:35 +0000
commitea1adebe31673917c957f455d3588b6486142128 (patch)
treef10f7be93e3ce5d8a676824b0bec3535d8c3dfe6 /video/win32_v.c
parent10936e70345e4d462517e35511f0e56b69c444e9 (diff)
downloadopenttd-ea1adebe31673917c957f455d3588b6486142128.tar.xz
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Diffstat (limited to 'video/win32_v.c')
-rw-r--r--video/win32_v.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/video/win32_v.c b/video/win32_v.c
index 3ecda2528..aff4f2526 100644
--- a/video/win32_v.c
+++ b/video/win32_v.c
@@ -184,9 +184,40 @@ int RedrawScreenDebug(void)
}
#endif
+/* Windows 95 will not have a WM_MOUSELEAVE message, so define it if
+ * needed. There is no such event as WM_MOUSEENTER, we just made this up :) */
+#define WM_MOUSEENTER WM_USER + 1
+#if !defined(WM_MOUSELEAVE)
+#define WM_MOUSELEAVE 0x02A3
+#endif
+#define TID_POLLMOUSE 1
+#define MOUSE_POLL_DELAY 75
+
+static void CALLBACK TrackMouseTimerProc(HWND hwnd, UINT msg, UINT event, DWORD time)
+{
+ RECT rc;
+ POINT pt;
+
+ /* Get the rectangle of our window and translate it to screen coordinates.
+ * Compare this with the current screen coordinates of the mouse and if it
+ * falls outside of the area or our window we have left the window. */
+ GetClientRect(hwnd, &rc);
+ MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)&rc, 2);
+ GetCursorPos(&pt);
+
+ if (!PtInRect(&rc, pt) || (WindowFromPoint(pt) != hwnd)) {
+ KillTimer(hwnd, event);
+ PostMessage(hwnd, WM_MOUSELEAVE, 0, 0L);
+ }
+}
+
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
+ case WM_CREATE:
+ SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc);
+ break;
+
case WM_PAINT: {
PAINTSTRUCT ps;
HDC dc,dc2;
@@ -259,11 +290,33 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
_right_button_down = false;
return 0;
+ case WM_MOUSEENTER:
+ printf("enter\n");
+ _cursor.in_window = true;
+ DrawMouseCursor();
+ break;
+
+ case WM_MOUSELEAVE:
+ printf("enter\n");
+ UndrawMouseCursor();
+ _cursor.in_window = false;
+ break;
+
case WM_MOUSEMOVE: {
int x = (int16)LOWORD(lParam);
int y = (int16)HIWORD(lParam);
POINT pt;
+ /* If the mouse was not in the window and it has moved it means it has
+ * come into the window, so send a WM_MOUSEENTER message. Also start
+ * tracking the mouse for exiting the window */
+ if (!_cursor.in_window) {
+ _cursor.in_window = true;
+ SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc);
+
+ if (hwnd != GetCapture()) PostMessage(hwnd, WM_MOUSEENTER, 0, 0L);
+ }
+
if (_wnd.double_size) {
x /= 2;
y /= 2;