[AD] Windows system cursor fix

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


http://www.allegro.cc/forums/view_thread.php?_id=513662

Attached are two patches: the second one fixes the reported problem about 
the mouse cursor not being changed when switching to a system cursor. It's 
pretty ugly if you ask me, but maybe it's not such a bad thing at all.

The first one is an unapplied patch I found lying around (it doesn't apply 
cleanly along with the second one though). It makes the hardware cursor in 
Windows only be used in windowed mode, which is all that it works in 
anyway. I can't see why it's needed (it should simply fail as it is now 
too) but I recall someone somewhere once said that they had a problem. I 
can't find the original reference either in the mailing list or the 
forums, so I'm posting it here mostly to ask if anyone remembers what it's 
about. Otherwise I think I'll just drop it if it really doesn't matter or 
apply it anyway since it doesn't actually hurt, depending on how I feel at 
that time.

Evert
Index: src/win/wddraw.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wddraw.c,v
retrieving revision 1.38
diff -u -r1.38 wddraw.c
--- src/win/wddraw.c	11 Jun 2005 17:17:25 -0000	1.38
+++ src/win/wddraw.c	29 Jul 2005 10:33:36 -0000
@@ -468,9 +468,12 @@
 int gfx_directx_show_mouse(struct BITMAP *bmp, int x, int y)
 {
    if (hcursor) {
-      POINT p;
       _win_hcursor = hcursor;
-      SetCursor(hcursor);
+   }
+   if (_win_hcursor) {
+      POINT p;
+
+      SetCursor(_win_hcursor);
       /* Windows is too stupid to actually display the mouse pointer when we
        * change it and waits until it is moved, so we have to generate a fake
        * mouse move to actually show the cursor.
@@ -489,8 +492,24 @@
  */
 void gfx_directx_hide_mouse(void)
 {
+   POINT p;
+
+   /* We need to destroy the custom cursor image too, otherwise Allegro will
+    * get confused when we try to display a system cursor.
+    */
+   if (hcursor) {
+      DestroyIcon(hcursor);
+      hcursor = NULL;
+   }
    _win_hcursor = NULL;
    SetCursor(NULL);
+
+   /* Windows is too stupid to actually display the mouse pointer when we
+    * change it and waits until it is moved, so we have to generate a fake
+    * mouse move to actually show the cursor.
+    */
+   GetCursorPos(&p);
+   SetCursorPos(p.x, p.y);
 }
 
 
Index: wddraw.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wddraw.c,v
retrieving revision 1.36
diff -u -r1.36 wddraw.c
--- wddraw.c	19 Mar 2005 11:15:06 -0000	1.36
+++ wddraw.c	25 Apr 2005 17:39:38 -0000
@@ -465,7 +465,7 @@
  */
 int gfx_directx_show_mouse(struct BITMAP *bmp, int x, int y)
 {
-   if (hcursor) {
+   if (hcursor && is_windowed_mode()) {
       _win_hcursor = hcursor;
       SetCursor(hcursor);
       return 0;
Index: wmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/win/wmouse.c,v
retrieving revision 1.44
diff -u -r1.44 wmouse.c
--- wmouse.c	14 Mar 2005 11:29:15 -0000	1.44
+++ wmouse.c	25 Apr 2005 17:39:38 -0000
@@ -798,6 +798,10 @@
 {
    HCURSOR wc;
    
+   /* Only available in windowed mode */
+   if (!is_windowed_mode())
+      return 0;
+   
    wc = NULL;
    switch(cursor) {
       case MOUSE_CURSOR_ARROW:


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