[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Speaking of hardware cursor clarifications - my local copy of Allegro
has the attached additional function.
It is useful in all cases where you can't use Allegro's software cursor.
Just compare these two program fragments:
allegro_init();
install_mouse();
if (show_os_cursor(MOUSE_CURSOR_ARROW) != 0) need_own_cursor = 1;
set_gfx_mode();
vs.
allegro_init();
install_mouse();
set_gfx_mode();
enable_hardware_cursor();
select_mouse_cursor(MOUSE_CURSOR_ARROW);
show_mouse(screen);
if (!gfx_capabilities & HW_CURSOR) {
need_own_cursor = 1;
show_mouse(NULL);
}
The latter got annoying to me, after using the HW cursor a lot. Not only
is it more (and un-intuitive) code, but it also displays the software
cursor shortly when no hardware cursor is available.
The difference between show_os_cursor and the other functions is simply
the fact that show_os_cursor only deals with hardware cursors, nothing
else. I'm even wondering if we shouldn't completely drop the software
cursor from 4.3.x - or at least find a way to draw it from the main
thread.
Before applying, this patch needs some more work, but I'd like to hear
comments first:
- Make sure all the other mouse state is not affected, and clarify
complete semantics (e.g. I think it should still be possible to display
the software cursor at the same time - since it is completely separate,
and I think it shouldn't affect the gfx_capabilities flags, since it has
nothing to do with the gfx driver)
- I only tested it in X11, not sure if
mouse_driver->select_system_cursor works the same in windows and OSX
- Allow MOUSE_CURSOR_ALLEGRO (to set a custom os cursor)
- Allow MOUSE_CURSOR_NONE (to hide it again)
--
Elias Pschernig
Index: src/mouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/mouse.c,v
retrieving revision 1.32
diff -u -p -r1.32 mouse.c
--- src/mouse.c 12 Mar 2005 03:29:31 -0000 1.32
+++ src/mouse.c 14 Mar 2005 13:03:54 -0000
@@ -517,6 +517,30 @@ void set_mouse_sprite_focus(int x, int y
+/* show_os_cursor:
+ * Tries to display the OS cursor. Returns 0 on success. This is similar to
+ * calling show_mouse(screen) after calling enable_hardware_cursor, but is
+ * easier to use in cases where you don't need Allegro's software cursor
+ * even if no os cursor is available.
+ */
+int show_os_cursor(int cursor)
+{
+ if (!mouse_driver)
+ return -1;
+
+ if (cursor != MOUSE_CURSOR_NONE) {
+ /* Default system cursor? */
+ if (cursor != MOUSE_CURSOR_ALLEGRO) {
+ if (mouse_driver->select_system_cursor) {
+ return !mouse_driver->select_system_cursor(cursor);
+ }
+ }
+ }
+ return -1;
+}
+
+
+
/* show_mouse:
* Tells Allegro to display a mouse pointer. This only works when the timer
* module is active. The mouse pointer will be drawn onto the bitmap bmp,