Re: [AD] Using system mouse cursor |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Monday 13 September 2004 09:12, Evert Glebbeek wrote:
> Patch attached.
Revised patch, with some obvious bugfixes. I removed the parameter on the
public function and split the API into two functions: one to enable, one
to disable the hardware cursor.
Added documentation for the two new functions.
Evert
Index: docs/src/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.253
diff -u -r1.253 allegro._tx
--- docs/src/allegro._tx 3 Sep 2004 11:50:46 -0000 1.253
+++ docs/src/allegro._tx 15 Sep 2004 07:23:41 -0000
@@ -2177,6 +2177,19 @@
@xref poll_mouse, install_mouse, mouse_x
Returns TRUE if the current mouse driver is operating in polling mode.
+@@void @enable_hardware_cursor(void);
+@xref install_mouse, get_mouse_mickeys, gfx_capabilities
+ Enables the mouse hardware cursor on platforms where it interferes with
+ getting mouse mickeys. Using get_mouse_mickeys() becomes unreliable after
+ calling this function.
+
+@@void @disable_hardware_cursor(void);
+@xref install_mouse, get_mouse_mickeys, gfx_capabilities
+ Disables the mouse hardware cursor on platforms where it interferes with
+ getting mouse mickeys. Using get_mouse_mickeys() becomes reliable again
+ after calling this function.
+
+
@@extern volatile int @mouse_x;
@@extern volatile int @mouse_y;
@@extern volatile int @mouse_z;
Index: include/xalleg.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/xalleg.h,v
retrieving revision 1.19
diff -u -r1.19 xalleg.h
--- include/xalleg.h 6 Sep 2004 22:52:46 -0000 1.19
+++ include/xalleg.h 15 Sep 2004 07:23:41 -0000
@@ -91,7 +91,7 @@
int virtual_width;
int virtual_height;
-
+
int mouse_warped;
int keycode_to_scancode[256];
Index: include/allegro/mouse.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/mouse.h,v
retrieving revision 1.2
diff -u -r1.2 mouse.h
--- include/allegro/mouse.h 31 Oct 2002 12:56:24 -0000 1.2
+++ include/allegro/mouse.h 15 Sep 2004 07:23:41 -0000
@@ -44,6 +44,7 @@
AL_METHOD(void, set_speed, (int xspeed, int yspeed));
AL_METHOD(void, get_mickeys, (int *mickeyx, int *mickeyy));
AL_METHOD(int, analyse_data, (AL_CONST char *buffer, int size));
+ AL_METHOD(void, enable_hardware_cursor, (AL_CONST int mode));
} MOUSE_DRIVER;
@@ -57,6 +58,9 @@
AL_FUNC(int, poll_mouse, (void));
AL_FUNC(int, mouse_needs_poll, (void));
+AL_FUNC(void, enable_hardware_cursor, (void));
+AL_FUNC(void, disable_hardware_cursor, (void));
+
AL_VAR(struct BITMAP *, mouse_sprite);
AL_VAR(int, mouse_x_focus);
AL_VAR(int, mouse_y_focus);
Index: src/mouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/mouse.c,v
retrieving revision 1.22
diff -u -r1.22 mouse.c
--- src/mouse.c 6 Sep 2004 08:55:30 -0000 1.22
+++ src/mouse.c 15 Sep 2004 07:23:42 -0000
@@ -736,6 +736,41 @@
+/* enable_hardware_cursor:
+ * enabels the hardware cursor on platforms where this needs to be done
+ * explicitly
+ */
+void enable_hardware_cursor(void)
+{
+ if ((mouse_driver) && (mouse_driver->enable_hardware_cursor)) {
+ mouse_driver->enable_hardware_cursor(TRUE);
+ if (is_same_bitmap(_mouse_screen, screen)) {
+ BITMAP *bmp = _mouse_screen;
+ show_mouse(NULL);
+ show_mouse(bmp);
+ }
+ }
+}
+
+
+
+/* disable_hardware_cursor:
+ * disables the hardware cursor on platforms where this interferes with mickeys
+ */
+void disable_hardware_cursor(void)
+{
+ if ((mouse_driver) && (mouse_driver->enable_hardware_cursor)) {
+ mouse_driver->enable_hardware_cursor(FALSE);
+ if (is_same_bitmap(_mouse_screen, screen)) {
+ BITMAP *bmp = _mouse_screen;
+ show_mouse(NULL);
+ show_mouse(bmp);
+ }
+ }
+}
+
+
+
/* poll_mouse:
* Polls the current mouse state, and updates the user-visible information
* accordingly. On some drivers this is actually required to get the
Index: src/beos/bmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/beos/bmouse.c,v
retrieving revision 1.3
diff -u -r1.3 bmouse.c
--- src/beos/bmouse.c 6 Nov 2001 17:16:39 -0000 1.3
+++ src/beos/bmouse.c 15 Sep 2004 07:23:43 -0000
@@ -38,5 +38,6 @@
be_mouse_set_range, // AL_METHOD(void, set_range, (int x1, int y1, int x2, int y2));
be_mouse_set_speed, // AL_METHOD(void, set_speed, (int xspeed, int yspeed));
be_mouse_get_mickeys,// AL_METHOD(void, get_mickeys, (int *mickeyx, int *mickeyy));
- NULL // AL_METHOD(int, analyse_data, (const char *buffer, int size));
+ NULL, // AL_METHOD(int, analyse_data, (const char *buffer, int size));
+ NULL // AL_METHOD(void, enable_hardware_cursor, (AL_CONST int mode));
};
Index: src/dos/dmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/dos/dmouse.c,v
retrieving revision 1.5
diff -u -r1.5 dmouse.c
--- src/dos/dmouse.c 6 Nov 2001 17:16:39 -0000 1.5
+++ src/dos/dmouse.c 15 Sep 2004 07:23:43 -0000
@@ -95,6 +95,7 @@
mick_set_range,
mick_set_speed,
mick_get_mickeys,
+ NULL,
NULL
};
@@ -123,6 +124,7 @@
int33_set_range,
int33_set_speed,
int33_get_mickeys,
+ NULL,
NULL
};
@@ -148,6 +150,7 @@
int33_set_range,
int33_set_speed,
int33_get_mickeys,
+ NULL,
NULL
};
@@ -171,6 +174,7 @@
int33_set_range,
int33_set_speed,
int33_get_mickeys,
+ NULL,
NULL
};
@@ -194,6 +198,7 @@
mick_set_range,
mick_set_speed,
mick_get_mickeys,
+ NULL,
NULL
};
Index: src/macosx/qzmouse.m
===================================================================
RCS file: /cvsroot/alleg/allegro/src/macosx/qzmouse.m,v
retrieving revision 1.11
diff -u -r1.11 qzmouse.m
--- src/macosx/qzmouse.m 4 Jul 2004 13:44:49 -0000 1.11
+++ src/macosx/qzmouse.m 15 Sep 2004 07:23:43 -0000
@@ -46,7 +46,8 @@
osx_mouse_set_range,
NULL, // AL_METHOD(void, set_speed, (int xspeed, int yspeed));
osx_mouse_get_mickeys,
- NULL // AL_METHOD(int, analyse_data, (AL_CONST char *buffer, int size));
+ NULL, // AL_METHOD(int, analyse_data, (AL_CONST char *buffer, int size));
+ NULL // AL_METHOD(void, enable_hardware_cursor, (AL_CONST int mode));
};
Index: src/qnx/qmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/qnx/qmouse.c,v
retrieving revision 1.10
diff -u -r1.10 qmouse.c
--- src/qnx/qmouse.c 3 May 2002 22:34:13 -0000 1.10
+++ src/qnx/qmouse.c 15 Sep 2004 07:23:43 -0000
@@ -48,7 +48,8 @@
qnx_mouse_set_range,
NULL, // AL_METHOD(void, set_speed, (int xspeed, int yspeed));
qnx_mouse_get_mickeys,
- NULL // AL_METHOD(int, analyse_data, (AL_CONST char *buffer, int size));
+ NULL, // AL_METHOD(int, analyse_data, (AL_CONST char *buffer, int size));
+ NULL // AL_METHOD(void, enable_hardware_cursor, (AL_CONST int mode));
};
Index: src/win/wmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wmouse.c,v
retrieving revision 1.34
diff -u -r1.34 wmouse.c
--- src/win/wmouse.c 4 Jul 2004 13:44:50 -0000 1.34
+++ src/win/wmouse.c 15 Sep 2004 07:23:44 -0000
@@ -62,7 +62,8 @@
mouse_directx_set_range,
mouse_directx_set_speed,
mouse_directx_get_mickeys,
- NULL // AL_METHOD(int, analyse_data, (AL_CONST char *buffer, int size));
+ NULL, // AL_METHOD(int, analyse_data, (AL_CONST char *buffer, int size));
+ NULL // AL_METHOD(void, enable_hardware_cursor, (AL_CONST int mode));
};
Index: src/x/xmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xmouse.c,v
retrieving revision 1.5
diff -u -r1.5 xmouse.c
--- src/x/xmouse.c 7 Jul 2003 14:57:14 -0000 1.5
+++ src/x/xmouse.c 15 Sep 2004 07:23:44 -0000
@@ -64,7 +64,8 @@
_xwin_mousedrv_set_range,
_xwin_mousedrv_set_speed,
_xwin_mousedrv_get_mickeys,
- NULL
+ NULL,
+ _xwin_enable_hardware_cursor
};
Index: src/x/xwin.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xwin.c,v
retrieving revision 1.70
diff -u -r1.70 xwin.c
--- src/x/xwin.c 6 Sep 2004 22:52:46 -0000 1.70
+++ src/x/xwin.c 15 Sep 2004 07:23:47 -0000
@@ -430,10 +430,8 @@
#ifdef ALLEGRO_XWINDOWS_WITH_XCURSOR
/* Detect if ARGB cursors are supported */
_xwin.support_argb_cursor = XcursorSupportsARGB(_xwin.display);
- _xwin.hw_cursor_ok = 1;
-#else
- _xwin.hw_cursor_ok = 0;
#endif
+ _xwin.hw_cursor_ok = 0;
return 0;
}
@@ -1529,6 +1527,31 @@
+/* _xwin_enable_hardware_cursor:
+ * enable the hardware cursor; this disables the mouse mickey warping hack
+ */
+void _xwin_enable_hardware_cursor(int mode)
+{
+#ifdef ALLEGRO_XWINDOWS_WITH_XCURSOR
+ if (!_xwin.support_argb_cursor)
+ _xwin.hw_cursor_ok = mode;
+ else
+#endif
+ _xwin.hw_cursor_ok = 0;
+
+ /* Switch to non-warped mode */
+ if (_xwin.hw_cursor_ok) {
+ _xwin.mouse_warped = 0;
+ /* Move X-cursor to Allegro cursor. */
+ XWarpPointer(_xwin.display, _xwin.window, _xwin.window,
+ 0, 0, _xwin.window_width, _xwin.window_height,
+ _mouse_x - (_xwin_mouse_extended_range ? _xwin.scroll_x : 0),
+ _mouse_y - (_xwin_mouse_extended_range ? _xwin.scroll_y : 0));
+ }
+}
+
+
+
#ifdef ALLEGRO_XWINDOWS_WITH_XCURSOR
/* _xwin_set_mouse_sprite:
@@ -1664,8 +1687,6 @@
*/
void _xwin_move_mouse(int x, int y)
{
- _mouse_x = x;
- _mouse_y = y;
}
#endif /* ALLEGRO_XWINDOWS_WITH_XCURSOR */
@@ -2382,14 +2403,6 @@
0, 0, _xwin.window_width, _xwin.window_height,
_mouse_x - (_xwin_mouse_extended_range ? _xwin.scroll_x : 0),
_mouse_y - (_xwin_mouse_extended_range ? _xwin.scroll_y : 0));
- /* Re-enable hardware cursor */
- _xwin.hw_cursor_ok = 1;
-#ifdef ALLEGRO_XWINDOWS_WITH_XCURSOR
- if (_xwin.support_argb_cursor && (_xwin.xcursor_image != None) && is_same_bitmap(_mouse_screen, screen)) {
- show_mouse(_mouse_screen);
- }
-#endif
-
}
/* Flush X-buffers. */
@@ -2461,15 +2474,9 @@
*/
static void _xwin_private_set_warped_mouse_mode(int permanent)
{
- _xwin.mouse_warped = ((permanent) ? 1 : (MOUSE_WARP_DELAY*7/8));
-
- /* Disable hardware cursor in warp mode */
-#ifdef ALLEGRO_XWINDOWS_WITH_XCURSOR
- if (_xwin.hw_cursor_ok && permanent && _xwin.support_argb_cursor && (_xwin.xcursor_image != None) && is_same_bitmap(_mouse_screen, screen)) {
- show_mouse(_mouse_screen);
- }
-#endif
- _xwin.hw_cursor_ok = !permanent;
+ /* Don't enable warp mode if the hardware cursor is being displayed */
+ if (!_xwin.hw_cursor_ok)
+ _xwin.mouse_warped = ((permanent) ? 1 : (MOUSE_WARP_DELAY*7/8));
}
void _xwin_set_warped_mouse_mode(int permanent)
Index: src/x/xwin.h
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xwin.h,v
retrieving revision 1.18
diff -u -r1.18 xwin.h
--- src/x/xwin.h 30 Aug 2004 16:26:21 -0000 1.18
+++ src/x/xwin.h 15 Sep 2004 07:23:47 -0000
@@ -42,7 +42,7 @@
AL_FUNC(void, _xwin_flush_buffers, (void));
AL_FUNC(void, _xwin_vsync, (void));
AL_FUNC(void, _xwin_handle_input, (void));
-AL_FUNC(void, _xwin_set_warped_mouse_mode, (int permanent));
+AL_FUNC(void, _xwin_enable_hardware_cursor, (int mode));
AL_FUNC(void, _xwin_redraw_window, (int x, int y, int w, int h));
AL_FUNC(int, _xwin_scroll_screen, (int x, int y));
AL_FUNC(void, _xwin_update_screen, (int x, int y, int w, int h));