Re: [AD] 4.1.17

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Wednesday 01 December 2004 23:22, Evert Glebbeek wrote:
> > Hm, so today in freeze, and release tomorrow. I'll try out your system
> > cursor patch later,
> 
> I tried it last night and it doesn't work, even after cleanup. It 
crashes. 
> I'm going to burn some of the midnight oil on it tonight (ugh... tomorrow 
> is going to suck) and see if I can fix it. I realized yesterday that I 
was 
> mixing up two ideas in the implementation of it that somehow managed to 
> screw it completely.

Ok, done. Hopefully more-or-less final version (for a while at least) is 
attached. This adds teh constants
MOUSE_CURSOR_NONE, MOUSE_CURSOR_ALLEGRO, MOUSE_CURSOR_ARROW, 
MOUSE_CURSOR_BUSY, MOUSE_CURSOR_QUESTION and MOUSE_CURSOR_EDIT to be pased 
to the function void select_mouse_cursor(AL_CONST int cursor). No cursor 
is displayed until show_mouse(screen) is called and to hide the mouse, 
call show_mouse(NULL).
The set_mouse_sprite() will have no effect except on the Allegro cursor 
(MOUSE_CURSOR_ALLEGRO, the default). I don't think we actually need 
MOUSE_CURSOR_NONE, so I may remove it before applying the final version 
(right now, select_mouse_cursor(NONE) does the same as show_mouse(NULL)).

Allegro will try to use the system (window manager) default cursors if any 
of ARROW, BUSY, QUESTION or EDIT is passed. If that fails, it will fall 
back on its own default cursors (the normal arrow and hour glass, the 
other ones should probably be added too, although they should be rarely 
needed). You'll know that you have the OS default cursor if 
gfx_capabilites includes the new GFX_SYSTEM_CURSOR flag after calling 
show_mouse().

Apart from the above cursors that need to be added, the documentation 
should be updated (I have my old draft still lying around, I'll polish 
that and repost it here) and the GUI and Grabber should probably be 
updated so that they can take advantage of the new patch.

Actually, for the GUI, we need to know wether it's allowed to change the 
mouse cursor. I wouldn't like it changing my custom cursor with a default 
one without my consent ;), so lets just leave that for now.

Oh yeah, patch tested with the test program in Linux (XFree86 4.3).

Evert
Index: include/allegro/gfx.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/gfx.h,v
retrieving revision 1.13
diff -u -r1.13 gfx.h
--- include/allegro/gfx.h	16 Oct 2004 19:45:31 -0000	1.13
+++ include/allegro/gfx.h	2 Dec 2004 01:15:53 -0000
@@ -124,6 +124,7 @@
 #define GFX_HW_MEM_BLIT_MASKED            0x00080000
 #define GFX_HW_SYS_TO_VRAM_BLIT           0x00100000
 #define GFX_HW_SYS_TO_VRAM_BLIT_MASKED    0x00200000
+#define GFX_SYSTEM_CURSOR                 0x00400000
 
 
 AL_VAR(int, gfx_capabilities);   /* current driver capabilities */
Index: include/allegro/mouse.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/mouse.h,v
retrieving revision 1.3
diff -u -r1.3 mouse.h
--- include/allegro/mouse.h	25 Sep 2004 08:17:01 -0000	1.3
+++ include/allegro/mouse.h	2 Dec 2004 01:15:53 -0000
@@ -44,7 +44,8 @@
    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));
+   AL_METHOD(void, enable_hardware_cursor, (AL_CONST int mode));
+   AL_METHOD(int,  select_system_cursor, (AL_CONST int cursor));
 } MOUSE_DRIVER;
 
 
@@ -61,6 +62,15 @@
 AL_FUNC(void, enable_hardware_cursor, (void));
 AL_FUNC(void, disable_hardware_cursor, (void));
 
+/* Mouse cursors */
+#define MOUSE_CURSOR_NONE        0
+#define MOUSE_CURSOR_ALLEGRO     1
+#define MOUSE_CURSOR_ARROW       2
+#define MOUSE_CURSOR_BUSY        3
+#define MOUSE_CURSOR_QUESTION    4
+#define MOUSE_CURSOR_EDIT        5
+#define NUM_MOUSE_CURSORS        6
+
 AL_VAR(struct BITMAP *, mouse_sprite);
 AL_VAR(int, mouse_x_focus);
 AL_VAR(int, mouse_y_focus);
@@ -92,10 +102,10 @@
 AL_FUNC(void, position_mouse_z, (int z));
 AL_FUNC(void, set_mouse_range, (int x1, int y1, int x2, int y2));
 AL_FUNC(void, set_mouse_speed, (int xspeed, int yspeed));
-AL_FUNC(void, set_mouse_sprite, (struct BITMAP *sprite));
+AL_FUNC(void, select_mouse_cursor, (AL_CONST int cursor));
 AL_FUNC(void, set_mouse_sprite_focus, (int x, int y));
 AL_FUNC(void, get_mouse_mickeys, (int *mickeyx, int *mickeyy));
-
+AL_FUNC(void, set_mouse_sprite, (struct BITMAP *sprite));
 #ifdef __cplusplus
    }
 #endif
Index: src/mouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/mouse.c,v
retrieving revision 1.28
diff -u -r1.28 mouse.c
--- src/mouse.c	29 Nov 2004 21:22:03 -0000	1.28
+++ src/mouse.c	2 Dec 2004 01:15:55 -0000
@@ -71,27 +71,50 @@
 #define MOUSE_OFFSCREEN    -4096       /* somewhere to put unwanted cursors */
 
 
-#define DEFAULT_SPRITE_W   10          /* default arrow cursor */
+/* default mouse cursor sizes */
+#define DEFAULT_SPRITE_W   16
 #define DEFAULT_SPRITE_H   16
 
-static char mouse_pointer_data[DEFAULT_SPRITE_H][DEFAULT_SPRITE_W] =
+/* Default cursor shapes */
+/* TODO: add other shapes! */
+static char mouse_arrow_data[DEFAULT_SPRITE_H * DEFAULT_SPRITE_W] =
+{
+   2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 
+   2, 1, 1, 1, 1, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 1, 2, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+   2, 1, 2, 0, 2, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 
+   0, 2, 0, 0, 2, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 
+   0, 0, 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 
+   0, 0, 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 
+   0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+static char mouse_busy_data[DEFAULT_SPRITE_H * DEFAULT_SPRITE_W] =
 {
-   { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
-   { 1, 2, 1, 0, 0, 0, 0, 0, 0, 0 },
-   { 1, 2, 2, 1, 0, 0, 0, 0, 0, 0 },
-   { 1, 2, 2, 2, 1, 0, 0, 0, 0, 0 },
-   { 1, 2, 2, 2, 2, 1, 0, 0, 0, 0 },
-   { 1, 2, 2, 2, 2, 2, 1, 0, 0, 0 },
-   { 1, 2, 2, 2, 2, 2, 2, 1, 0, 0 },
-   { 1, 2, 2, 2, 2, 2, 2, 2, 1, 0 },
-   { 1, 2, 2, 2, 2, 2, 2, 2, 2, 1 },
-   { 1, 2, 2, 2, 2, 2, 1, 1, 1, 0 },
-   { 1, 2, 2, 1, 2, 2, 1, 0, 0, 0 },
-   { 1, 2, 1, 0, 1, 2, 2, 1, 0, 0 },
-   { 0, 1, 0, 0, 1, 2, 2, 1, 0, 0 },
-   { 0, 0, 0, 0, 0, 1, 2, 2, 1, 0 },
-   { 0, 0, 0, 0, 0, 1, 2, 2, 1, 0 },
-   { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 }
+   0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0, 0, 2, 2, 1, 1, 2, 2, 0, 0, 0, 0, 0,
+   0, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0,
+   0, 0, 0, 2, 1, 1, 1, 0, 0, 1, 1, 1, 2, 0, 0, 0,
+   0, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 0, 0,
+   0, 2, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 2, 0,
+   0, 2, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 2, 0,
+   2, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 2,
+   2, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 2,
+   0, 2, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 2, 0,
+   0, 2, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 2, 0,
+   0, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 0, 0,
+   0, 0, 0, 2, 1, 1, 1, 0, 0, 1, 1, 1, 2, 0, 0, 0,
+   0, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0,
+   0, 0, 0, 0, 0, 2, 2, 1, 1, 2, 2, 0, 0, 0, 0, 0,
+   0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0
 };
 
 
@@ -101,8 +124,12 @@
 
 BITMAP *_mouse_screen = NULL;          /* where to draw the pointer */
 
+static BITMAP *cursors[NUM_MOUSE_CURSORS];
+
+static int use_system_cursor = FALSE;  /* Use native OS cursor? */
 static int got_hw_cursor = FALSE;      /* hardware pointer available? */
 static int hw_cursor_dirty = FALSE;    /* need to set a new pointer? */
+static int current_cursor = MOUSE_CURSOR_ALLEGRO;
 
 static int mx, my;                     /* previous mouse pointer position */
 static BITMAP *ms = NULL;              /* previous screen data */
@@ -204,7 +231,7 @@
 
       if (add) {
 	 blit(_mouse_screen, ms, newmx-mouse_x_focus, newmy-mouse_y_focus, 0, 0, mouse_sprite->w, mouse_sprite->h);
-	 draw_sprite(_mouse_screen, mouse_sprite, newmx-mouse_x_focus, newmy-mouse_y_focus);
+	 draw_sprite(_mouse_screen, cursors[current_cursor], newmx-mouse_x_focus, newmy-mouse_y_focus);
       }
    }
    else
@@ -368,7 +395,7 @@
  *  Creates the default arrow mouse sprite using the current color depth
  *  and palette.
  */
-static BITMAP *create_mouse_pointer(void)
+static BITMAP *create_mouse_pointer(char *data)
 {
    BITMAP *bmp;
    int x, y;
@@ -378,7 +405,7 @@
 
    for (y=0; y<DEFAULT_SPRITE_H; y++) {
       for (x=0; x<DEFAULT_SPRITE_W; x++) {
-	 switch (mouse_pointer_data[y][x]) {
+	 switch (data[x+y*DEFAULT_SPRITE_W]) {
 	    case 1:  col = makecol(255, 255, 255);  break;
 	    case 2:  col = makecol(0, 0, 0);        break;
 	    default: col = bmp->vtable->mask_color; break;
@@ -399,11 +426,12 @@
 void set_mouse_sprite(struct BITMAP *sprite)
 {
    BITMAP *old_mouse_screen = _mouse_screen;
+   int am_using_sys_cursor = use_system_cursor;
 
    if (!mouse_driver)
       return;
 
-   if (_mouse_screen)
+   if (_mouse_screen && !am_using_sys_cursor)
       show_mouse(NULL);
 
    if (sprite)
@@ -411,10 +439,12 @@
    else {
       if (_mouse_pointer)
 	 destroy_bitmap(_mouse_pointer);
-      _mouse_pointer = create_mouse_pointer();
+      _mouse_pointer = create_mouse_pointer(mouse_arrow_data);
       mouse_sprite = _mouse_pointer;
    }
 
+   cursors[MOUSE_CURSOR_ALLEGRO] = mouse_sprite;
+   
    lock_bitmap((struct BITMAP*)mouse_sprite);
 
    /* make sure the ms bitmap is big enough */
@@ -435,14 +465,27 @@
    mouse_x_focus = 1;
    mouse_y_focus = 1;
 
-   hw_cursor_dirty = TRUE;
+   if (!am_using_sys_cursor)
+      hw_cursor_dirty = TRUE;
 
-   if (old_mouse_screen)
+   if (old_mouse_screen && !am_using_sys_cursor)
       show_mouse(old_mouse_screen);
 }
 
 
 
+/* select_mouse_cursor:
+ *  Selects the shape of the mouse cursor.
+ */
+void select_mouse_cursor(AL_CONST int cursor)
+{
+   ASSERT(cursor < NUM_MOUSE_CURSORS);
+
+   current_cursor = cursor;
+}
+
+
+
 /* set_mouse_sprite_focus:
  *  Sets co-ordinate (x, y) in the sprite to be the mouse location.
  *  Call after set_mouse_sprite(). Doesn't redraw the sprite.
@@ -476,12 +519,13 @@
 
    remove_int(mouse_move);
 
+   /* Remove the mouse cursor */
    if (_mouse_screen) {
       acquire_bitmap(_mouse_screen);
 
       if (gfx_capabilities & GFX_HW_CURSOR) {
 	 gfx_driver->hide_mouse();
-	 gfx_capabilities &= ~GFX_HW_CURSOR;
+	 gfx_capabilities &= ~(GFX_HW_CURSOR|GFX_SYSTEM_CURSOR);
       }
       else
 	 draw_mouse(TRUE, FALSE);
@@ -491,9 +535,24 @@
 
    _mouse_screen = bmp;
 
-   if (bmp) {
+   if (bmp && (current_cursor!=MOUSE_CURSOR_NONE)) {
       acquire_bitmap(_mouse_screen);
 
+      /* Default system cursor? */
+      if (current_cursor != MOUSE_CURSOR_ALLEGRO) {
+         if (mouse_driver && mouse_driver->select_system_cursor) {
+            use_system_cursor = mouse_driver->select_system_cursor(current_cursor);
+            if (use_system_cursor) {
+               gfx_capabilities |= GFX_HW_CURSOR|GFX_SYSTEM_CURSOR;
+               hw_cursor_dirty = FALSE;
+               got_hw_cursor = TRUE;
+            }
+         }
+      } else {
+         use_system_cursor = FALSE;
+      }
+
+      /* Custom hardware cursor? */
       if (hw_cursor_dirty) {
 	 got_hw_cursor = FALSE;
 
@@ -503,13 +562,17 @@
 
 	 hw_cursor_dirty = FALSE;
       }
-
+      
+      /* Try to display hardware (custom or system) cursor */
       if ((got_hw_cursor) && (is_same_bitmap(bmp, screen)))
 	 if (gfx_driver->show_mouse(bmp, mx=mouse_x, my=mouse_y) == 0)
 	    gfx_capabilities |= GFX_HW_CURSOR;
 
-      if (!(gfx_capabilities & GFX_HW_CURSOR))
+      /* Draw cursor manually if we can't do that */
+      if (!(gfx_capabilities & GFX_HW_CURSOR)) {
 	 draw_mouse(FALSE, TRUE);
+         use_system_cursor = FALSE;
+      }
 
       release_bitmap(_mouse_screen);
 
@@ -882,6 +945,7 @@
    LOCK_VARIABLE(mtemp);
    LOCK_VARIABLE(mouse_polled);
    LOCK_VARIABLE(mouse_semaphore);
+   LOCK_VARIABLE(cursors);
    LOCK_FUNCTION(draw_mouse_doublebuffer);
    LOCK_FUNCTION(draw_mouse);
    LOCK_FUNCTION(update_mouse);
@@ -889,6 +953,16 @@
    LOCK_FUNCTION(poll_mouse);
    LOCK_FUNCTION(mouse_needs_poll);
    LOCK_FUNCTION(_handle_mouse_input);
+   
+   /* Construct mouse pointers */
+   if (!cursors[MOUSE_CURSOR_ARROW])
+      cursors[MOUSE_CURSOR_ARROW] = create_mouse_pointer(mouse_arrow_data);
+   if (!cursors[MOUSE_CURSOR_BUSY])
+      cursors[MOUSE_CURSOR_BUSY] = create_mouse_pointer(mouse_busy_data);
+   if (!cursors[MOUSE_CURSOR_QUESTION])
+      cursors[MOUSE_CURSOR_QUESTION] = create_mouse_pointer(mouse_arrow_data);
+   if (!cursors[MOUSE_CURSOR_EDIT])
+      cursors[MOUSE_CURSOR_EDIT] = create_mouse_pointer(mouse_arrow_data);
 
    if (system_driver->mouse_drivers)
       driver_list = system_driver->mouse_drivers();
Index: src/beos/bmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/beos/bmouse.c,v
retrieving revision 1.4
diff -u -r1.4 bmouse.c
--- src/beos/bmouse.c	25 Sep 2004 08:16:58 -0000	1.4
+++ src/beos/bmouse.c	2 Dec 2004 01:15:56 -0000
@@ -39,5 +39,6 @@
    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(void,  enable_hardware_cursor, (AL_CONST int mode));
+   NULL,                // AL_METHOD(void,  enable_hardware_cursor, (AL_CONST int mode));
+   NULL                 // AL_METHOD(int,  select_system_cursor, (AL_CONST int cursor));
 };
Index: src/dos/dmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/dos/dmouse.c,v
retrieving revision 1.6
diff -u -r1.6 dmouse.c
--- src/dos/dmouse.c	25 Sep 2004 08:16:59 -0000	1.6
+++ src/dos/dmouse.c	2 Dec 2004 01:15:56 -0000
@@ -96,6 +96,7 @@
    mick_set_speed,
    mick_get_mickeys,
    NULL,
+   NULL,
    NULL
 };
 
@@ -199,6 +200,7 @@
    mick_set_speed,
    mick_get_mickeys,
    NULL,
+   NULL,
    NULL
 };
 
Index: src/linux/lmseev.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lmseev.c,v
retrieving revision 1.7
diff -u -r1.7 lmseev.c
--- src/linux/lmseev.c	1 Oct 2004 14:16:13 -0000	1.7
+++ src/linux/lmseev.c	2 Dec 2004 01:15:56 -0000
@@ -682,7 +682,8 @@
    mouse_set_speed,
    mouse_get_mickeys,
    analyse_data,
-	NULL /* enable_hardware_cursor */
+   NULL, /* enable_hardware_cursor */
+   NULL
 };
 
 #endif
Index: src/linux/lmsegpmd.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lmsegpmd.c,v
retrieving revision 1.12
diff -u -r1.12 lmsegpmd.c
--- src/linux/lmsegpmd.c	1 Oct 2004 14:16:13 -0000	1.12
+++ src/linux/lmsegpmd.c	2 Dec 2004 01:15:57 -0000
@@ -141,6 +141,7 @@
 	__al_linux_mouse_set_speed,
 	__al_linux_mouse_get_mickeys,
 	NULL,  /* analyse_data */
-	NULL
+	NULL,
+       NULL
 };
 
Index: src/linux/lmsems.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lmsems.c,v
retrieving revision 1.13
diff -u -r1.13 lmsems.c
--- src/linux/lmsems.c	1 Oct 2004 14:16:13 -0000	1.13
+++ src/linux/lmsems.c	2 Dec 2004 01:15:57 -0000
@@ -224,7 +224,8 @@
 	__al_linux_mouse_set_speed,
 	__al_linux_mouse_get_mickeys,
 	analyse_data,
-	NULL /* enable_hardware_cursor */
+	NULL, /* enable_hardware_cursor */
+       NULL
 };
 
 MOUSE_DRIVER mousedrv_linux_ims =
Index: src/linux/lmseps2.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/lmseps2.c,v
retrieving revision 1.16
diff -u -r1.16 lmseps2.c
--- src/linux/lmseps2.c	1 Oct 2004 14:16:13 -0000	1.16
+++ src/linux/lmseps2.c	2 Dec 2004 01:15:57 -0000
@@ -241,7 +241,8 @@
 	__al_linux_mouse_set_speed,
 	__al_linux_mouse_get_mickeys,
 	analyse_data,
-	NULL /* enable_hardware_cursor */
+	NULL, /* enable_hardware_cursor */
+       NULL
 };
 
 MOUSE_DRIVER mousedrv_linux_ips2 =
Index: src/mac/madb.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/mac/madb.c,v
retrieving revision 1.4
diff -u -r1.4 madb.c
--- src/mac/madb.c	6 Nov 2001 17:16:40 -0000	1.4
+++ src/mac/madb.c	2 Dec 2004 01:15:57 -0000
@@ -90,6 +90,7 @@
       mouse_adb_set_range,
       NULL,
       mouse_adb_get_mickeys,
+      NULL,
       NULL
 };
 
Index: src/mac/msys.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/mac/msys.c,v
retrieving revision 1.14
diff -u -r1.14 msys.c
--- src/mac/msys.c	2 Jul 2004 16:25:41 -0000	1.14
+++ src/mac/msys.c	2 Dec 2004 01:15:58 -0000
@@ -122,6 +122,7 @@
    NULL,
    NULL,
    NULL,
+   NULL,
    NULL
 };
 
Index: src/macosx/qzmouse.m
===================================================================
RCS file: /cvsroot/alleg/allegro/src/macosx/qzmouse.m,v
retrieving revision 1.13
diff -u -r1.13 qzmouse.m
--- src/macosx/qzmouse.m	29 Nov 2004 21:22:06 -0000	1.13
+++ src/macosx/qzmouse.m	2 Dec 2004 01:15:58 -0000
@@ -47,7 +47,8 @@
    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(void,  enable_hardware_cursor, (AL_CONST int mode));
+   NULL,       // AL_METHOD(void,  enable_hardware_cursor, (AL_CONST int mode));
+   NULL        // AL_METHOD(int,  select_system_cursor, (AL_CONST int cursor));
 };
 
 
Index: src/qnx/qmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/qnx/qmouse.c,v
retrieving revision 1.11
diff -u -r1.11 qmouse.c
--- src/qnx/qmouse.c	25 Sep 2004 08:17:00 -0000	1.11
+++ src/qnx/qmouse.c	2 Dec 2004 01:15:58 -0000
@@ -49,7 +49,8 @@
    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(void,  enable_hardware_cursor, (AL_CONST int mode));
+   NULL,       // AL_METHOD(void,  enable_hardware_cursor, (AL_CONST int mode));
+   NULL        // AL_METHOD(int,  select_system_cursor, (AL_CONST int cursor));
 };
 
 
Index: src/win/wddraw.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wddraw.c,v
retrieving revision 1.33
diff -u -r1.33 wddraw.c
--- src/win/wddraw.c	25 Sep 2004 08:23:15 -0000	1.33
+++ src/win/wddraw.c	2 Dec 2004 01:15:59 -0000
@@ -384,6 +384,8 @@
    HBITMAP hOldXorMaskBitmap;
 
    if (hcursor) {
+      if (_win_hcursor == hcursor)
+         _win_hcursor = NULL;
       DestroyIcon(hcursor);
       hcursor = NULL;
    }
Index: src/win/wmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wmouse.c,v
retrieving revision 1.38
diff -u -r1.38 wmouse.c
--- src/win/wmouse.c	1 Dec 2004 23:03:57 -0000	1.38
+++ src/win/wmouse.c	2 Dec 2004 01:15:59 -0000
@@ -46,7 +46,7 @@
 static void mouse_directx_set_range(int x1, int y1, int x2, int y2);
 static void mouse_directx_set_speed(int xspeed, int yspeed);
 static void mouse_directx_get_mickeys(int *mickeyx, int *mickeyy);
-
+static int mouse_directx_select_system_cursor(AL_CONST int cursor);
 
 MOUSE_DRIVER mouse_directx =
 {
@@ -63,7 +63,8 @@
    mouse_directx_set_speed,
    mouse_directx_get_mickeys,
    NULL,                       // AL_METHOD(int, analyse_data, (AL_CONST char *buffer, int size));
-   NULL                        // AL_METHOD(void,  enable_hardware_cursor, (AL_CONST int mode));
+   NULL,                       // AL_METHOD(void,  enable_hardware_cursor, (AL_CONST int mode));
+   mouse_directx_select_system_cursor
 };
 
 
@@ -765,3 +766,36 @@
    *mickeyy = temp_y;
 }
 
+
+
+/* mouse_directx_select_system_cursor:
+ *  Select an OS native cursor 
+ */
+static int mouse_directx_select_system_cursor (AL_CONST int cursor)
+{
+   HCURSOR wc;
+   
+   wc = NULL;
+   switch(cursor) {
+      case MOUSE_CURSOR_ARROW:
+         wc = LoadCursor(NULL, IDC_ARROW);
+         break;
+      case MOUSE_CURSOR_BUSY:
+         wc = LoadCursor(NULL, IDC_WAIT);
+         break;
+      case MOUSE_CURSOR_QUESTION:
+         wc = LoadCursor(NULL, IDC_HELP);
+         break;
+      case MOUSE_CURSOR_EDIT:
+         wc = LoadCursor(NULL, IDC_IBEAM);
+         break;
+      default:
+         return 0;
+   }
+
+   _win_hcursor = wc;
+   SetCursor(_win_hcursor);
+   PostMessage(allegro_wnd, WM_MOUSEMOVE, 0, 0);
+   
+   return cursor;
+}
Index: src/x/xmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xmouse.c,v
retrieving revision 1.7
diff -u -r1.7 xmouse.c
--- src/x/xmouse.c	25 Sep 2004 08:33:31 -0000	1.7
+++ src/x/xmouse.c	2 Dec 2004 01:15:59 -0000
@@ -20,7 +20,7 @@
 #include "allegro/internal/aintern.h"
 #include "allegro/platform/aintunix.h"
 #include "xwin.h"
-
+#include <X11/cursorfont.h>
 
 /* TRUE if the requested mouse range extends beyond the regular
  * (0, 0, SCREEN_W-1, SCREEN_H-1) range. This is aimed at detecting
@@ -48,7 +48,7 @@
 static void _xwin_mousedrv_set_range(int x1, int y1, int x2, int y2);
 static void _xwin_mousedrv_set_speed(int xspeed, int yspeed);
 static void _xwin_mousedrv_get_mickeys(int *mickeyx, int *mickeyy);
-
+static int _xwin_select_system_cursor(AL_CONST int cursor);
 
 static MOUSE_DRIVER mouse_xwin =
 {
@@ -65,7 +65,8 @@
    _xwin_mousedrv_set_speed,
    _xwin_mousedrv_get_mickeys,
    NULL,
-   _xwin_enable_hardware_cursor
+   _xwin_enable_hardware_cursor,
+   _xwin_select_system_cursor
 };
 
 
@@ -214,3 +215,37 @@
    _xwin_set_warped_mouse_mode(TRUE);
 }
 
+
+
+/* _xwin_select_system_cursor:
+ *  Select an OS native cursor 
+ */
+static int _xwin_select_system_cursor(AL_CONST int cursor)
+{
+   switch(cursor) {
+      case MOUSE_CURSOR_ARROW:
+         _xwin.cursor_shape = XC_left_ptr;
+         break;
+      case MOUSE_CURSOR_BUSY:
+         _xwin.cursor_shape = XC_watch;
+         break;
+      case MOUSE_CURSOR_QUESTION:
+         _xwin.cursor_shape = XC_question_arrow;
+         break;
+      case MOUSE_CURSOR_EDIT:
+         _xwin.cursor_shape = XC_xterm;
+         break;
+      default:
+         return 0;
+   }
+   
+   if (_xwin.cursor != None) {
+      XUndefineCursor(_xwin.display, _xwin.window);
+      XFreeCursor(_xwin.display, _xwin.cursor);
+   }   
+
+   _xwin.cursor = XCreateFontCursor(_xwin.display, _xwin.cursor_shape);
+   XDefineCursor(_xwin.display, _xwin.window, _xwin.cursor);
+   
+   return cursor;
+}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/