Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2005:
[Freeciv-Dev] Re: (PR#14817) gui-sdl cursor sprites
Home

[Freeciv-Dev] Re: (PR#14817) gui-sdl cursor sprites

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#14817) gui-sdl cursor sprites
From: "Christian Prochaska" <cp.ml.freeciv.dev@xxxxxxxxxxxxxx>
Date: Sun, 11 Dec 2005 00:02:52 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14817 >

On 12/10/05, Jason Short <jdorje@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=14817 >
>
> gui-sdl shouldn't use its own cursor sprites.  Use the cursor sprites in
> the main tileset.  If you like animated sprites then put your vote in
> favor of Andreas' cursor-animation patch.
>
> -jason
>

Patch attached. I suggest replacing the cursors.png file with the one
in the attachment, because the current one cannot be converted
correctly by the SDL client.

diff -urN -X devel/diff_ignore devel_distclean/client/gui-sdl/graphics.c 
devel/client/gui-sdl/graphics.c
--- devel_distclean/client/gui-sdl/graphics.c   2005-12-11 01:54:41.000000000 
+0100
+++ devel/client/gui-sdl/graphics.c     2005-12-11 08:23:05.000000000 +0100
@@ -3478,27 +3478,24 @@
 **************************************************************************/
 void load_cursors(void)
 {
-  struct sprite *cursor_sprite;
-  int hot_x, hot_y;
-    
-  /* standart */
+  enum cursor_type cursor;  
+  int frame;
+  SDL_Surface *pSurf;
+
   pStd_Cursor = SDL_GetCursor();
+    
+  for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
+    for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
+      int hot_x, hot_y;
+      struct sprite *sprite
+       = get_cursor_sprite(tileset, cursor, &hot_x, &hot_y, frame);
+      
+      pSurf = GET_SURF(sprite);
+      SDL_SetColorKey(pSurf, SDL_SRCCOLORKEY, 0);
 
-  /* goto */
-  cursor_sprite = get_cursor_sprite(tileset, CURSOR_GOTO, &hot_x, &hot_y);
-  pGoto_Cursor = SurfaceToCursor(GET_SURF(cursor_sprite), hot_x, hot_y);
-
-  /* drop */
-  cursor_sprite = get_cursor_sprite(tileset, CURSOR_PARADROP, &hot_x, &hot_y);
-  pDrop_Cursor = SurfaceToCursor(GET_SURF(cursor_sprite), hot_x, hot_y);
-
-  /* nuke */
-  cursor_sprite = get_cursor_sprite(tileset, CURSOR_NUKE, &hot_x, &hot_y);  
-  pNuke_Cursor = SurfaceToCursor(GET_SURF(cursor_sprite), hot_x, hot_y);
-
-  /* patrol */
-  cursor_sprite = get_cursor_sprite(tileset, CURSOR_PATROL, &hot_x, &hot_y);  
-  pPatrol_Cursor = SurfaceToCursor(GET_SURF(cursor_sprite), hot_x, hot_y);
+      fc_cursors[cursor][frame] = SurfaceToCursor(pSurf, hot_x, hot_y);
+    }
+  }
 }
 
 /**************************************************************************
diff -urN -X devel/diff_ignore devel_distclean/client/gui-sdl/gui_main.c 
devel/client/gui-sdl/gui_main.c
--- devel_distclean/client/gui-sdl/gui_main.c   2005-12-11 01:54:41.000000000 
+0100
+++ devel/client/gui-sdl/gui_main.c     2005-12-11 08:25:59.000000000 +0100
@@ -112,13 +112,13 @@
 bool RCTRL;
 bool LALT;
 bool do_focus_animation = TRUE;
-SDL_Cursor **pAnimCursor = NULL;
+enum cursor_type mouse_cursor_type = CURSOR_DEFAULT;
+bool mouse_cursor_changed = FALSE;
 bool do_cursor_animation = TRUE;
 int city_names_font_size = 12;
 int city_productions_font_size = 12;
 
 /* ================================ Private ============================ */
-static SDL_Cursor **pStoreAnimCursor = NULL;
 static int net_socket = -1;
 static bool autoconnect = FALSE;
 static bool is_map_scrolling = FALSE;
@@ -411,19 +411,16 @@
     } else {
       if (get_client_state() == CLIENT_GAME_RUNNING_STATE) {
         static SDL_Rect rect;
+          
+        handle_mouse_cursor(canvas_pos_to_tile(pMotionEvent->x, 
pMotionEvent->y));
                   
         rect.x = rect.y = 0;
         rect.w = SCROLL_MAP_AREA;
         rect.h = Main.map->h;
+
         if (is_in_rect_area(pMotionEvent->x, pMotionEvent->y, rect)) {
          is_map_scrolling = TRUE;
          if (scroll_dir != DIR8_WEST) {
-           pStoreAnimCursor = pAnimCursor;
-           if (do_cursor_animation && 
pAnim->Cursors.MapScroll[SCROLL_WEST][1]) {
-             pAnimCursor = pAnim->Cursors.MapScroll[SCROLL_WEST];
-           } else {
-             SDL_SetCursor(pAnim->Cursors.MapScroll[SCROLL_WEST][0]);
-           }
            scroll_dir = DIR8_WEST;
          }
         } else {
@@ -431,12 +428,6 @@
          if (is_in_rect_area(pMotionEvent->x, pMotionEvent->y, rect)) {
            is_map_scrolling = TRUE;
            if (scroll_dir != DIR8_EAST) {
-             pStoreAnimCursor = pAnimCursor;
-             if (do_cursor_animation && 
pAnim->Cursors.MapScroll[SCROLL_EAST][1]) {
-               pAnimCursor = pAnim->Cursors.MapScroll[SCROLL_EAST];
-             } else {
-               SDL_SetCursor(pAnim->Cursors.MapScroll[SCROLL_EAST][0]);
-             }
              scroll_dir = DIR8_EAST;
            }
           } else {
@@ -446,12 +437,6 @@
            if (is_in_rect_area(pMotionEvent->x, pMotionEvent->y, rect)) {
              is_map_scrolling = TRUE;
              if (scroll_dir != DIR8_NORTH) {
-               pStoreAnimCursor = pAnimCursor;
-               if (do_cursor_animation && 
pAnim->Cursors.MapScroll[SCROLL_NORTH][1]) {
-                 pAnimCursor = pAnim->Cursors.MapScroll[SCROLL_NORTH];
-               } else {
-                 SDL_SetCursor(pAnim->Cursors.MapScroll[SCROLL_NORTH][0]);
-               }
                scroll_dir = DIR8_NORTH;
              }
             } else {
@@ -459,24 +444,9 @@
              if (is_in_rect_area(pMotionEvent->x, pMotionEvent->y, rect)) {
                is_map_scrolling = TRUE;
                if (scroll_dir != DIR8_SOUTH) {
-                 pStoreAnimCursor = pAnimCursor;
-                 if (do_cursor_animation && 
pAnim->Cursors.MapScroll[SCROLL_SOUTH][1]) {
-                   pAnimCursor = pAnim->Cursors.MapScroll[SCROLL_SOUTH];
-                 } else {
-                   SDL_SetCursor(pAnim->Cursors.MapScroll[SCROLL_SOUTH][0]);
-                 }
                  scroll_dir = DIR8_SOUTH;
                }
               } else {
-               if (is_map_scrolling) {
-                 if (pStoreAnimCursor) {
-                   pAnimCursor = pStoreAnimCursor;
-                 } else {
-                   SDL_SetCursor(pStd_Cursor);
-                   pAnimCursor = NULL;
-                 }
-               }
-               pStoreAnimCursor = NULL;
                is_map_scrolling = FALSE;
              }
            } 
@@ -538,12 +508,21 @@
 
 static void game_cursors_anim(void)
 {
-  static int cursor_anim_frame = 0;
-  if(do_cursor_animation && pAnimCursor && pAnimCursor[1]) {
-    SDL_SetCursor(pAnimCursor[cursor_anim_frame++]);
-    if (!pAnimCursor[cursor_anim_frame]) {
-      cursor_anim_frame = 0;
+  static int cursor_frame = 0;
+
+  if (!mouse_cursor_changed) {
+    return;
+  }
+  
+  if (mouse_cursor_type == CURSOR_DEFAULT) {
+    SDL_SetCursor(pStd_Cursor);
+    mouse_cursor_changed = FALSE;
+  } else {
+    if (!do_cursor_animation || (cursor_frame == NUM_CURSOR_FRAMES)) {
+      cursor_frame = 0;
     }
+  
+    SDL_SetCursor(fc_cursors[mouse_cursor_type][cursor_frame++]);    
   }
 }
 
@@ -1072,11 +1051,7 @@
   freelog(LOG_DEBUG, "Connection DOWN... ");
   disable_focus_animation();
   draw_goto_patrol_lines = FALSE;
-  if (pAnimCursor) {
-    SDL_SetCursor(pStd_Cursor);
-    pAnimCursor = NULL;
-    pStoreAnimCursor = NULL;
-  }
+  SDL_SetCursor(pStd_Cursor);
 }
 
 /****************************************************************************
diff -urN -X devel/diff_ignore devel_distclean/client/gui-sdl/gui_tilespec.c 
devel/client/gui-sdl/gui_tilespec.c
--- devel_distclean/client/gui-sdl/gui_tilespec.c       2005-12-11 
01:54:41.000000000 +0100
+++ devel/client/gui-sdl/gui_tilespec.c 2005-12-11 08:32:31.000000000 +0100
@@ -481,84 +481,6 @@
         return cursor;
 }
 
-#define load_cursor(iter, num, pSpr, image, cBuf, Type, Tag, x, y, center) \
-do { \
-  iter = 0;    \
-  my_snprintf(cBuf , sizeof(cBuf), "%s_%d", Tag, iter);        \
-    while(themeset_lookup_sprite_tag_alt(themeset, cBuf, "", FALSE, "", "")) { 
\
-    iter++;    \
-    my_snprintf(cBuf , sizeof(cBuf), "%s_%d", Tag, iter);      \
-  }    \
-  num = iter;  \
-  if (num) {   \
-    pAnim->Cursors.Type = CALLOC(num + 1, sizeof(SDL_Cursor *));       \
-    for( iter=0; iter<num; iter++) {   \
-      my_snprintf(cBuf,sizeof(cBuf), "%s_%d", Tag, iter);      \
-      pSpr = themeset_lookup_sprite_tag_alt(themeset, cBuf, "", FALSE, "", 
""); \
-      image = (pSpr ? GET_SURF(pSpr) : NULL);  \
-      assert(image != NULL);   \
-      if (center) {    \
-        pAnim->Cursors.Type[iter] = SurfaceToCursor(image, image->w/2, 
image->h/2);    \
-      } else { \
-       pAnim->Cursors.Type[iter] = SurfaceToCursor(image, x, y);       \
-      }        \
-    }  \
-  }    \
-} while(0)
-
-/*
- *     Alloc and fill Animation struct
- */
-void tilespec_setup_anim(void)
-{
-  char buf[32];        /* I hope this is enought :) */
-  struct sprite *pSpr = NULL;
-  SDL_Surface *image = NULL;
-  int i, num;
-  pAnim = MALLOC(sizeof(struct Animation));
-    
-  /* load cursors */
-  load_cursor(i, num, pSpr, image, buf, Patrol, "anim.patrol_cursor", 0, 0, 
TRUE);
-  load_cursor(i, num, pSpr, image, buf, Goto, "anim.goto_cursor", 0, 0, TRUE);
-  load_cursor(i, num, pSpr, image, buf, Connect, "anim.connect_cursor", 0, 0, 
TRUE);
-  load_cursor(i, num, pSpr, image, buf, Nuke, "anim.nuke_cursor", 0, 0, TRUE);
-  load_cursor(i, num, pSpr, image, buf, Paradrop, "anim.paradrop_cursor", 0, 
0, TRUE);
-  
-  load_cursor(i, num, pSpr, image, buf, MapScroll[SCROLL_NORTH], 
"anim.scroll_north_cursor", 20, 3, FALSE);
-  load_cursor(i, num, pSpr, image, buf, MapScroll[SCROLL_SOUTH], 
"anim.scroll_south_cursor", 20, 37, FALSE);
-  load_cursor(i, num, pSpr, image, buf, MapScroll[SCROLL_EAST], 
"anim.scroll_east_cursor", 37, 20, FALSE);
-  load_cursor(i, num, pSpr, image, buf, MapScroll[SCROLL_WEST], 
"anim.scroll_west_cursor", 3, 20, FALSE);
-  
-}
-
-void tilespec_free_anim(void)
-{
-  int i,j;
-  
-  for(i=0; pAnim->Cursors.Patrol[i]; i++) {
-    SDL_FreeCursor(pAnim->Cursors.Patrol[i]);
-  }
-  for(i=0; pAnim->Cursors.Goto[i]; i++) {
-    SDL_FreeCursor(pAnim->Cursors.Goto[i]);
-  }
-  for(i=0; pAnim->Cursors.Connect[i]; i++) {
-    SDL_FreeCursor(pAnim->Cursors.Connect[i]);
-  }
-  for(i=0; pAnim->Cursors.Nuke[i]; i++) {
-    SDL_FreeCursor(pAnim->Cursors.Nuke[i]);
-  }
-  for(i=0; pAnim->Cursors.Paradrop[i]; i++) {
-    SDL_FreeCursor(pAnim->Cursors.Paradrop[i]);
-  }
-  for (i = 0; i < SCROLL_LAST; i++) {
-    for (j = 0; pAnim->Cursors.MapScroll[i][j]; j++) {
-      SDL_FreeCursor(pAnim->Cursors.MapScroll[i][j]);
-    }
-  }
-  
-  FREE(pAnim);
-}
-
 /*
  *     Free memmory
  */
diff -urN -X devel/diff_ignore devel_distclean/client/gui-sdl/gui_tilespec.h 
devel/client/gui-sdl/gui_tilespec.h
--- devel_distclean/client/gui-sdl/gui_tilespec.h       2005-12-11 
01:54:41.000000000 +0100
+++ devel/client/gui-sdl/gui_tilespec.h 2005-12-11 08:09:48.000000000 +0100
@@ -24,6 +24,8 @@
 
 #include <SDL/SDL.h>
 
+#include "tilespec.h"
+
 #include "citydlg_common.h"    /* struct citizen_type */
   
 struct Theme {
@@ -140,18 +142,6 @@
   SCROLL_LAST
 };
 
-struct Animation {
-  struct {
-    SDL_Cursor **Patrol;
-    SDL_Cursor **Goto;
-    SDL_Cursor **Connect;
-    SDL_Cursor **Nuke;
-    SDL_Cursor **Paradrop;
-    SDL_Cursor **MapScroll[SCROLL_LAST];
-  } Cursors;
-  
-} *pAnim;
-
 void tilespec_setup_anim(void);
 void tilespec_free_anim(void);
 
@@ -203,6 +193,8 @@
 
 SDL_Surface *pCity_Surf;
 
+SDL_Cursor *fc_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES];
+
 void tilespec_setup_city_gfx(void);
   
 void tilespec_setup_city_icons(void);
diff -urN -X devel/diff_ignore devel_distclean/client/gui-sdl/mapview.c 
devel/client/gui-sdl/mapview.c
--- devel_distclean/client/gui-sdl/mapview.c    2005-11-27 01:35:27.000000000 
+0100
+++ devel/client/gui-sdl/mapview.c      2005-12-11 08:27:33.000000000 +0100
@@ -77,7 +77,8 @@
 #include "mapview.h"
 
 extern SDL_Event *pFlush_User_Event;
-extern SDL_Cursor **pAnimCursor;
+extern enum cursor_type mouse_cursor_type;
+extern bool mouse_cursor_changed;
 extern bool do_cursor_animation;
 
 int OVERVIEW_START_X;
@@ -1148,8 +1149,6 @@
 **************************************************************************/
 void update_unit_info_label(struct unit *pUnit)
 {
-  static bool mutant = FALSE;
-   
   if (get_client_state() != CLIENT_GAME_RUNNING_STATE) {
     return;
   }
@@ -1167,71 +1166,52 @@
     }
     switch (hover_state) {
     case HOVER_NONE:
-      if (mutant) {
-       SDL_SetCursor(pStd_Cursor);
-       pAnimCursor = NULL;
-       mutant = FALSE;
-      }
+      if (action_state == CURSOR_ACTION_SELECT) {
+        mouse_cursor_type = CURSOR_SELECT; 
+      } else if (action_state == CURSOR_ACTION_PARATROOPER) {
+        mouse_cursor_type = CURSOR_PARADROP;  
+      } else if (action_state == CURSOR_ACTION_NUKE) {
+        mouse_cursor_type = CURSOR_NUKE;
+      } else {
+        mouse_cursor_type = CURSOR_DEFAULT;
+      }  
+      mouse_cursor_changed = TRUE;      
       break;
-    case HOVER_PATROL:
-      if (pAnim->Cursors.Patrol) {
-       if (do_cursor_animation && pAnim->Cursors.Patrol[1]) {
-         pAnimCursor = pAnim->Cursors.Patrol;
-       } else {
-         SDL_SetCursor(pAnim->Cursors.Patrol[0]);
-       }
+    case HOVER_GOTO:
+      if (action_state == CURSOR_ACTION_GOTO) {
+        mouse_cursor_type = CURSOR_GOTO;
+      } else if (action_state == CURSOR_ACTION_DEFAULT) {
+        mouse_cursor_type = CURSOR_DEFAULT;
+      } else if (action_state == CURSOR_ACTION_ATTACK) {
+        mouse_cursor_type = CURSOR_ATTACK;  
       } else {
-        SDL_SetCursor(pPatrol_Cursor);
+        mouse_cursor_type = CURSOR_INVALID;  
       }
-      mutant = TRUE;
+      mouse_cursor_changed = TRUE;
       break;
-    case HOVER_GOTO:
-      if (pAnim->Cursors.Goto) {
-       if (do_cursor_animation && pAnim->Cursors.Goto[1]) {
-         pAnimCursor = pAnim->Cursors.Goto;
-       } else {
-         SDL_SetCursor(pAnim->Cursors.Goto[0]);
-       }
+    case HOVER_PATROL:
+      if (action_state == CURSOR_ACTION_INVALID) {
+        mouse_cursor_type = CURSOR_INVALID;
       } else {
-        SDL_SetCursor(pGoto_Cursor);
+        mouse_cursor_type = CURSOR_PATROL;
       }
-      mutant = TRUE;
+      mouse_cursor_changed = TRUE;
       break;
     case HOVER_CONNECT:
-      if (pAnim->Cursors.Connect) {
-       if (do_cursor_animation && pAnim->Cursors.Connect[1]) {
-         pAnimCursor = pAnim->Cursors.Connect;
-       } else {
-         SDL_SetCursor(pAnim->Cursors.Connect[0]);
-       }
+      if (action_state == CURSOR_ACTION_INVALID) {
+        mouse_cursor_type = CURSOR_INVALID;
       } else {
-        SDL_SetCursor(pGoto_Cursor);
+        mouse_cursor_type = CURSOR_GOTO;
       }
-      mutant = TRUE;
+      mouse_cursor_changed = TRUE;
       break;
     case HOVER_NUKE:
-      if (pAnim->Cursors.Nuke) {
-       if (do_cursor_animation && pAnim->Cursors.Nuke[1]) {
-         pAnimCursor = pAnim->Cursors.Nuke;
-       } else {
-         SDL_SetCursor(pAnim->Cursors.Nuke[0]);
-       }
-      } else {
-        SDL_SetCursor(pNuke_Cursor);
-      }
-      mutant = TRUE;
+      mouse_cursor_type = CURSOR_NUKE;
+      mouse_cursor_changed = TRUE;
       break;
     case HOVER_PARADROP:
-      if (pAnim->Cursors.Paradrop) {
-       if (do_cursor_animation && pAnim->Cursors.Paradrop[1]) {
-         pAnimCursor = pAnim->Cursors.Paradrop;
-       } else {
-         SDL_SetCursor(pAnim->Cursors.Paradrop[0]);
-       }
-      } else {
-        SDL_SetCursor(pDrop_Cursor);
-      }
-      mutant = TRUE;
+      mouse_cursor_type = CURSOR_PARADROP;        
+      mouse_cursor_changed = TRUE;
       break;
     }
   } else {
diff -urN -X devel/diff_ignore devel_distclean/client/gui-sdl/themespec.c 
devel/client/gui-sdl/themespec.c
--- devel_distclean/client/gui-sdl/themespec.c  2005-12-11 01:54:41.000000000 
+0100
+++ devel/client/gui-sdl/themespec.c    2005-12-11 08:12:25.000000000 +0100
@@ -891,7 +891,6 @@
    * functions in gui_tilespec.c instead */
   
   tilespec_setup_theme();
-  tilespec_setup_anim();
   tilespec_setup_city_gfx();
   tilespec_setup_city_icons();
 }
@@ -1049,6 +1048,5 @@
    * functions in gui_tilespec.c instead */
 
   tilespec_free_theme();
-  tilespec_free_anim();
   tilespec_free_city_icons();
 }

PNG image


[Prev in Thread] Current Thread [Next in Thread]