Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12440) encapsulate indicator icon sprites
Home

[Freeciv-Dev] (PR#12440) encapsulate indicator icon sprites

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12440) encapsulate indicator icon sprites
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 5 Mar 2005 16:19:48 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch add an accessor for reading the indicator icon sprites.  An 
enumeration of indicator icons is added to simplify the data structures 
and interface.

-jason

Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.155
diff -u -r1.155 climisc.c
--- client/climisc.c    19 Feb 2005 17:15:13 -0000      1.155
+++ client/climisc.c    6 Mar 2005 00:08:01 -0000
@@ -313,9 +313,9 @@
     /* This clipping can be necessary since we can end up with excess
      * research. */
     index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
-    return sprites.bulb[index];
+    return get_indicator_sprite(INDICATOR_BULB, index);
   } else {
-    return sprites.bulb[0];
+    return get_indicator_sprite(INDICATOR_BULB, 0);
   }
 }
 
@@ -338,9 +338,9 @@
 
     /* The clipping is needed because the above math is a little fuzzy. */
     index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
-    return sprites.warming[index];
+    return get_indicator_sprite(INDICATOR_WARMING, index);
   } else {
-    return sprites.warming[0];
+    return get_indicator_sprite(INDICATOR_WARMING, 0);
   }
 }
 
@@ -363,9 +363,9 @@
 
     /* The clipping is needed because the above math is a little fuzzy. */
     index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
-    return sprites.cooling[index];
+    return get_indicator_sprite(INDICATOR_COOLING, index);
   } else {
-    return sprites.cooling[0];
+    return get_indicator_sprite(INDICATOR_COOLING, 0);
   }
 }
 
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.258
diff -u -r1.258 tilespec.c
--- client/tilespec.c   5 Mar 2005 23:51:05 -0000       1.258
+++ client/tilespec.c   6 Mar 2005 00:08:02 -0000
@@ -1388,20 +1388,20 @@
   char buffer[512];
   const char dir_char[] = "nsew";
   const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
-  int i;
+  int i, j;
   
   assert(t->sprite_hash != NULL);
 
   SET_SPRITE(treaty_thumb[0], "treaty.disagree_thumb_down");
   SET_SPRITE(treaty_thumb[1], "treaty.agree_thumb_up");
 
-  for(i=0; i<NUM_TILES_PROGRESS; i++) {
-    my_snprintf(buffer, sizeof(buffer), "s.science_bulb_%d", i);
-    SET_SPRITE(bulb[i], buffer);
-    my_snprintf(buffer, sizeof(buffer), "s.warming_sun_%d", i);
-    SET_SPRITE(warming[i], buffer);
-    my_snprintf(buffer, sizeof(buffer), "s.cooling_flake_%d", i);
-    SET_SPRITE(cooling[i], buffer);
+  for (j = 0; j < INDICATOR_COUNT; j++) {
+    const char *names[] = {"science_bulb", "warming_sun", "cooling_flake"};
+
+    for (i = 0; i < NUM_TILES_PROGRESS; i++) {
+      my_snprintf(buffer, sizeof(buffer), "s.%s_%d", names[j], i);
+      SET_SPRITE(indicator[j][i], buffer);
+    }
   }
 
   SET_SPRITE(right_arrow, "s.right_arrow");
@@ -3811,6 +3811,18 @@
   return sprites.user.attention;
 }
 
+/****************************************************************************
+  Returns a sprite for the given indicator with the given index.  The
+  index should be in [0, NUM_TILES_PROGRESS).
+****************************************************************************/
+struct Sprite *get_indicator_sprite(enum indicator_type indicator,
+                                   int index)
+{
+  index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
+  assert(indicator >= 0 && indicator < INDICATOR_COUNT);
+  return sprites.indicator[indicator][index];
+}
+
 /**************************************************************************
   Loads the sprite. If the sprite is already loaded a reference
   counter is increased. Can return NULL if the sprite couldn't be
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.121
diff -u -r1.121 tilespec.h
--- client/tilespec.h   5 Mar 2005 23:51:05 -0000       1.121
+++ client/tilespec.h   6 Mar 2005 00:08:02 -0000
@@ -216,11 +216,16 @@
   CURSOR_LAST
 };
 
+enum indicator_type {
+  INDICATOR_BULB,
+  INDICATOR_WARMING,
+  INDICATOR_COOLING,
+  INDICATOR_COUNT
+};
+
 struct named_sprites {
   struct Sprite
-    *bulb[NUM_TILES_PROGRESS],
-    *warming[NUM_TILES_PROGRESS],
-    *cooling[NUM_TILES_PROGRESS],
+    *indicator[INDICATOR_COUNT][NUM_TILES_PROGRESS],
     *treaty_thumb[2],     /* 0=disagree, 1=agree */
     *right_arrow,
 
@@ -374,6 +379,8 @@
 struct Sprite *get_cursor_sprite(enum cursor_type cursor,
                                 int *hot_x, int *hot_y);
 struct Sprite *get_attention_crosshair_sprite(void);
+struct Sprite *get_indicator_sprite(enum indicator_type indicator,
+                                   int index);
 
 /* These variables contain the size of the tiles used within the game.
  *

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12440) encapsulate indicator icon sprites, Jason Short <=