Re: [AD] Using system mouse cursor

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


Next iteration attached. I think this implements most of the behavior that 
was discussed earlier: passing NULL selects the system default (or 
Allegro's if that is not available) cursor.
What I haven't changed is the behavior of show_mouse(): this will not draw 
a new cursor even if the requested surface is a memory bitmap if the 
hardware cursor is being displayed. I don't think that would really make 
much sense.

Evert

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	1 Oct 2004 20:50:30 -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_ALLEGRO     0
+#define MOUSE_CURSOR_NONE        0
+#define MOUSE_CURSOR_ARROW       1
+#define MOUSE_CURSOR_BUSY        2
+#define MOUSE_CURSOR_QUESTION    3
+#define MOUSE_CURSOR_EDIT        4
+#define NUM_MOUSE_CURSORS        5
+
 AL_VAR(struct BITMAP *, mouse_sprite);
 AL_VAR(int, mouse_x_focus);
 AL_VAR(int, mouse_y_focus);
@@ -92,10 +102,12 @@
 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, set_mouse_cursor, (AL_CONST int cursor, 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.26
diff -u -r1.26 mouse.c
--- src/mouse.c	1 Oct 2004 14:07:56 -0000	1.26
+++ src/mouse.c	1 Oct 2004 20:50:31 -0000
@@ -71,27 +71,49 @@
 #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] =
+
+static char mouse_arrow_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 }
+   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] =
+{
+   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,6 +123,9 @@
 
 BITMAP *_mouse_screen = NULL;          /* where to draw the pointer */
 
+static BITMAP *cursors[NUM_MOUSE_CURSORS];
+
+static int use_system_cursor = FALSE;      /* Use native cursor? */
 static int got_hw_cursor = FALSE;      /* hardware pointer available? */
 static int hw_cursor_dirty = FALSE;    /* need to set a new pointer? */
 
@@ -366,7 +391,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;
@@ -376,7 +401,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;
@@ -396,12 +421,23 @@
  */
 void set_mouse_sprite(struct BITMAP *sprite)
 {
+   set_mouse_cursor(MOUSE_CURSOR_ALLEGRO, sprite);
+}
+
+
+
+/* _set_mouse_sprite:
+ *  Sets the sprite to be used for the mouse pointer. If the sprite is
+ *  NULL, restores the default arrow.
+ */
+static void _set_mouse_sprite(BITMAP *sprite, char *data)
+{
    BITMAP *old_mouse_screen = _mouse_screen;
 
    if (!mouse_driver)
       return;
 
-   if (_mouse_screen)
+   if (_mouse_screen && !(gfx_capabilities & GFX_HW_CURSOR))
       show_mouse(NULL);
 
    if (sprite)
@@ -409,7 +445,7 @@
    else {
       if (_mouse_pointer)
 	 destroy_bitmap(_mouse_pointer);
-      _mouse_pointer = create_mouse_pointer();
+      _mouse_pointer = create_mouse_pointer(data);
       mouse_sprite = _mouse_pointer;
    }
 
@@ -435,12 +471,57 @@
 
    hw_cursor_dirty = TRUE;
 
-   if (old_mouse_screen)
+   if (old_mouse_screen && !(gfx_capabilities & GFX_HW_CURSOR))
       show_mouse(old_mouse_screen);
 }
 
 
 
+/* set_mouse_cursor:
+ *  Sets the default cursor shape. If this is NULL, the hardware cursor
+ *  will be used instead.
+ */
+void set_mouse_cursor(AL_CONST int cursor, BITMAP *sprite)
+{
+   ASSERT(cursor < NUM_MOUSE_CURSORS);
+   
+   cursors[cursor] = sprite;
+}
+
+
+
+
+/* select_mouse_cursor:
+ *  Selects the shape of the mouse cursor.
+ */
+void select_mouse_cursor(AL_CONST int cursor)
+{
+   ASSERT(cursor < NUM_MOUSE_CURSORS);
+   
+   use_system_cursor = 0;
+   if (!cursors[cursor] || cursor != MOUSE_CURSOR_ALLEGRO) {
+      /* Use default system cursor */
+      if (mouse_driver && mouse_driver->select_system_cursor) {
+         use_system_cursor = mouse_driver->select_system_cursor(cursor);
+         if (use_system_cursor)
+            gfx_capabilities |= GFX_HW_CURSOR;
+      }
+   }
+   
+   if (!use_system_cursor) {
+      switch(cursor) {
+         case MOUSE_CURSOR_BUSY:
+            _set_mouse_sprite(cursors[cursor], mouse_busy_data);
+            break;
+         default:
+            _set_mouse_sprite(cursors[cursor], mouse_arrow_data);
+      }
+   }
+}
+
+
+
+
 /* 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.
@@ -463,13 +544,11 @@
  *  module is active. The mouse pointer will be drawn onto the bitmap bmp, 
  *  which should normally be the hardware screen. To turn off the mouse 
  *  pointer, which you must do before you draw anything onto the screen, call 
- *  show_mouse(NULL). If you forget to turn off the mouse pointer when 
- *  drawing something, the SVGA bank switching code will become confused and 
- *  will produce garbage all over the screen.
+ *  show_mouse(NULL).
  */
 void show_mouse(BITMAP *bmp)
 {
-   if (!mouse_driver)
+   if (!mouse_driver || use_system_cursor)
       return;
 
    remove_int(mouse_move);
@@ -871,7 +950,8 @@
    LOCK_VARIABLE(mouse_x_focus);
    LOCK_VARIABLE(mouse_y_focus);
    LOCK_VARIABLE(mouse_sprite);
-   LOCK_VARIABLE(mouse_pointer_data);
+   LOCK_VARIABLE(mouse_arrow_data);
+   LOCK_VARIABLE(mouse_busy_data);
    LOCK_VARIABLE(_mouse_pointer);
    LOCK_VARIABLE(_mouse_screen);
    LOCK_VARIABLE(mx);
@@ -880,6 +960,7 @@
    LOCK_VARIABLE(mtemp);
    LOCK_VARIABLE(mouse_polled);
    LOCK_VARIABLE(mouse_semaphore);
+   LOCK_VARIABLE(use_system_cursor);
    LOCK_FUNCTION(draw_mouse_doublebuffer);
    LOCK_FUNCTION(draw_mouse);
    LOCK_FUNCTION(update_mouse);
@@ -941,6 +1022,9 @@
    else {
       emulate_three = FALSE;
    }
+   
+   for (i=0; i<NUM_MOUSE_CURSORS; i++)
+      cursors[i] = NULL;
 
    mouse_polled = (mouse_driver->poll) ? TRUE : FALSE;
 
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	1 Oct 2004 20:50:31 -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	1 Oct 2004 20:50:32 -0000
@@ -96,6 +96,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	1 Oct 2004 20:50:32 -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	1 Oct 2004 20:50:32 -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	1 Oct 2004 20:50:33 -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	1 Oct 2004 20:50:33 -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	1 Oct 2004 20:50:33 -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	1 Oct 2004 20:50:34 -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.12
diff -u -r1.12 qzmouse.m
--- src/macosx/qzmouse.m	25 Sep 2004 08:16:59 -0000	1.12
+++ src/macosx/qzmouse.m	1 Oct 2004 20:50:34 -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	1 Oct 2004 20:50:34 -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	1 Oct 2004 20:50:34 -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.36
diff -u -r1.36 wmouse.c
--- src/win/wmouse.c	25 Sep 2004 08:23:15 -0000	1.36
+++ src/win/wmouse.c	1 Oct 2004 20:50:35 -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
 };
 
 
@@ -748,3 +749,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	1 Oct 2004 20:50:35 -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;
+}
Index: tools/grabber.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tools/grabber.c,v
retrieving revision 1.72
diff -u -r1.72 grabber.c
--- tools/grabber.c	2 Jul 2004 09:46:28 -0000	1.72
+++ tools/grabber.c	1 Oct 2004 20:50:38 -0000
@@ -376,14 +376,14 @@
 /* starts outputting a progress message */
 static void box_start(void)
 {
-   show_mouse(NULL);
+   scare_mouse();
 
    rectfill(screen, BOX_L, BOX_T, BOX_R, BOX_B, gui_bg_color);
    rect(screen, BOX_L-1, BOX_T-1, BOX_R+1, BOX_B+1, gui_fg_color);
    hline(screen, BOX_L, BOX_B+2, BOX_R+1, gui_fg_color);
    vline(screen, BOX_R+2, BOX_T, BOX_B+2, gui_fg_color);
 
-   show_mouse(screen);
+   unscare_mouse();
 
    box_x = box_y = 0;
    box_active = TRUE;
@@ -397,8 +397,7 @@
    BITMAP *mouse_screen = _mouse_screen;
 
    if (box_active) {
-      if (mouse_screen)
-	 show_mouse(NULL);
+      scare_mouse();
 
       set_clip_rect(screen, BOX_L+8, BOX_T+1, BOX_R-8, BOX_B-1);
 
@@ -406,8 +405,7 @@
 
       set_clip_rect(screen, 0, 0, SCREEN_W-1, SCREEN_H-1);
 
-      if (mouse_screen)
-	 show_mouse(mouse_screen);
+      unscare_mouse();
 
       box_x += strlen(msg);
    }
@@ -425,14 +423,12 @@
       box_y++;
 
       if ((box_y+2)*8 >= BOX_H) {
-	 if (mouse_screen)
-	    show_mouse(NULL);
+         scare_mouse();
 
 	 blit(screen, screen, BOX_L+8, BOX_T+16, BOX_L+8, BOX_T+8, BOX_W-16, BOX_H-24);
 	 rectfill(screen, BOX_L+8, BOX_T+BOX_H-16, BOX_L+BOX_W-8, BOX_T+BOX_H-8, gui_bg_color);
 
-	 if (mouse_screen)
-	    show_mouse(mouse_screen);
+	 unscare_mouse();
 
 	 box_y--;
       }
@@ -828,64 +824,15 @@
 
 
 
-static char my_mouse_pointer_data[256] =
-{
-   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 my_busy_pointer_data[256] =
-{
-   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
-};
-
-
-
-static BITMAP *my_mouse_pointer = NULL;
-static BITMAP *my_busy_pointer = NULL;
-
-
-
 /* changes the mouse pointer */
 static void set_busy_mouse(int busy)
 {
    if (busy) {
-      set_mouse_sprite(my_busy_pointer);
+      select_mouse_cursor(MOUSE_CURSOR_BUSY);
       busy_mouse = TRUE;
    }
    else {
-      set_mouse_sprite(my_mouse_pointer);
+      select_mouse_cursor(MOUSE_CURSOR_ARROW);
       busy_mouse = FALSE;
    }
 }
@@ -912,29 +859,8 @@
    main_dlg[DLG_FIRSTWHITE].proc = proc;
    set_dialog_color(main_dlg+DLG_FIRSTWHITE, gui_fg_color, gui_bg_color);
 
-   if (!my_mouse_pointer)
-      my_mouse_pointer = create_bitmap(16, 16);
-
-   if (!my_busy_pointer)
-      my_busy_pointer = create_bitmap(16, 16);
-
-   for (y=0; y<16; y++) {
-      for (x=0; x<16; x++) {
-	 switch (my_mouse_pointer_data[x+y*16]) {
-	    case 1:  c = gui_fg_color; break;
-	    case 2:  c = gui_bg_color; break;
-	    default: c = screen->vtable->mask_color; break;
-	 }
-	 putpixel(my_mouse_pointer, x, y, c);
-
-	 switch (my_busy_pointer_data[x+y*16]) {
-	    case 1:  c = gui_fg_color; break;
-	    case 2:  c = gui_bg_color; break;
-	    default: c = screen->vtable->mask_color; break;
-	 }
-	 putpixel(my_busy_pointer, x, y, c);
-      }
-   }
+   set_mouse_cursor(MOUSE_CURSOR_BUSY, NULL);
+   set_mouse_cursor(MOUSE_CURSOR_ARROW, NULL);
 
    set_busy_mouse(FALSE);
 }
@@ -3361,10 +3287,6 @@
    install_timer();
 
    if (set_gfx_mode(autodetect_card, oldw, oldh, 0, 0) != 0) {
-      destroy_bitmap(my_mouse_pointer);
-      my_mouse_pointer = NULL;
-      destroy_bitmap(my_busy_pointer);
-      my_busy_pointer = NULL;
       set_gfx_mode(GFX_SAFE, 320, 200, 0, 0);
       sel_palette(datedit_current_palette);
       alert("bad, Bad, BAD error!", "Unable to restore the graphics mode...", NULL, "Shit", NULL, 13, 0);
@@ -3429,14 +3351,14 @@
    vsprintf(buf, fmt, args);
    va_end(args);
 
-   show_mouse(NULL);
+   scare_mouse();
    acquire_screen();
 
    box_out(buf);
    box_eol();
 
    release_screen();
-   show_mouse(screen);
+   unscare_mouse();
 }
 
 
@@ -3466,14 +3388,14 @@
    vsprintf(buf, fmt, args);
    va_end(args);
 
-   show_mouse(NULL);
+   scare_mouse();
    acquire_screen();
 
    box_out(buf);
    box_eol();
 
    release_screen();
-   show_mouse(screen);
+   unscare_mouse();
 }
 
 
@@ -3488,12 +3410,12 @@
    vsprintf(buf, fmt, args);
    va_end(args);
 
-   set_mouse_sprite(my_mouse_pointer);
+   select_mouse_cursor(MOUSE_CURSOR_ARROW);
 
    alert(buf, NULL, NULL, "Oh dear", NULL, 13, 0);
 
    if (busy_mouse)
-      set_mouse_sprite(my_busy_pointer);
+      select_mouse_cursor(MOUSE_CURSOR_BUSY);
 }
 
 
@@ -3511,12 +3433,12 @@
 
    strcat(buf, "?");
 
-   set_mouse_sprite(my_mouse_pointer);
+   select_mouse_cursor(MOUSE_CURSOR_ARROW);
 
    ret = alert(buf, NULL, NULL, "Yes", "Cancel", 'y', 27);
 
    if (busy_mouse)
-      set_mouse_sprite(my_busy_pointer);
+      select_mouse_cursor(MOUSE_CURSOR_BUSY);
 
    if (ret == 1)
       return 'y';


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