Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12220) fixes to set_indicator_icons and client_xxx_spr
Home

[Freeciv-Dev] (PR#12220) fixes to set_indicator_icons and client_xxx_spr

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12220) fixes to set_indicator_icons and client_xxx_sprite
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 11 Feb 2005 14:02:57 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch:

- Changes set_indicator_icons() so it takes sprites not arbitrary integers.
- Changes client_xxx_sprite so it returns a sprite not an arbitrary integer.
- Adds a client_government_sprite() that returns the sprite for the 
current government (or a fallback).

It depends on the PR#12206 patch.

-jason

Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.151
diff -u -r1.151 climisc.c
--- client/climisc.c    4 Feb 2005 23:00:02 -0000       1.151
+++ client/climisc.c    11 Feb 2005 22:00:40 -0000
@@ -30,6 +30,7 @@
 #include "diptreaty.h"
 #include "fcintl.h"
 #include "game.h"
+#include "government.h"
 #include "log.h"
 #include "map.h"
 #include "packets.h"
@@ -298,19 +299,24 @@
 }
 
 /**************************************************************************
-Return the sprite index for the research indicator.
+  Return the sprite for the research indicator.
 **************************************************************************/
-int client_research_sprite(void)
+struct Sprite *client_research_sprite(void)
 {
-  return (NUM_TILES_PROGRESS *
-         game.player_ptr->research.bulbs_researched) /
-      (total_bulbs_required(game.player_ptr) + 1);
+  int index = (NUM_TILES_PROGRESS
+              * game.player_ptr->research.bulbs_researched)
+    / (total_bulbs_required(game.player_ptr) + 1);
+
+  /* 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 the sprite index for the global-warming indicator.
+  Return the sprite for the global-warming indicator.
 **************************************************************************/
-int client_warming_sprite(void)
+struct Sprite *client_warming_sprite(void)
 {
   int index;
   if ((game.globalwarming <= 0) &&
@@ -321,13 +327,16 @@
                (MAX(0, 4 + game.globalwarming) / 5) +
                ((NUM_TILES_PROGRESS / 2) - 1));
   }
-  return index;
+
+  /* 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 the sprite index for the global-cooling indicator.
+  Return the sprite for the global-cooling indicator.
 **************************************************************************/
-int client_cooling_sprite(void)
+struct Sprite *client_cooling_sprite(void)
 {
   int index;
   if ((game.nuclearwinter <= 0) &&
@@ -338,7 +347,26 @@
                (MAX(0, 4 + game.nuclearwinter) / 5) +
                ((NUM_TILES_PROGRESS / 2) - 1));
   }
-  return index;
+
+  /* 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 the sprite for the government indicator.
+**************************************************************************/
+struct Sprite *client_government_sprite(void)
+{
+  if (game.government_count == 0) {
+    /* HACK: the UNHAPPY citizen is used for the government
+     * when we don't know any better. */
+    struct citizen_type c = {.type = CITIZEN_UNHAPPY};
+
+    return get_citizen_sprite(c, 0, NULL);
+  } else {
+    return get_government(game.player_ptr->government)->sprite;
+  }
 }
 
 /**************************************************************************
Index: client/climisc.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.h,v
retrieving revision 1.53
diff -u -r1.53 climisc.h
--- client/climisc.h    25 Dec 2004 20:38:14 -0000      1.53
+++ client/climisc.h    11 Feb 2005 22:00:40 -0000
@@ -36,9 +36,10 @@
 void client_diplomacy_clause_string(char *buf, int bufsiz,
                                    struct Clause *pclause);
 
-int client_research_sprite(void);
-int client_warming_sprite(void);
-int client_cooling_sprite(void);
+struct Sprite *client_research_sprite(void);
+struct Sprite *client_warming_sprite(void);
+struct Sprite *client_cooling_sprite(void);
+struct Sprite *client_government_sprite(void);
 
 void center_on_something(void);
 
Index: client/gui-ftwl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/mapview.c,v
retrieving revision 1.13
diff -u -r1.13 mapview.c
--- client/gui-ftwl/mapview.c   22 Jan 2005 19:45:39 -0000      1.13
+++ client/gui-ftwl/mapview.c   11 Feb 2005 22:00:40 -0000
@@ -226,7 +226,8 @@
   client window.  The parameters tell which sprite to use for the
   indicator.
 **************************************************************************/
-void set_indicator_icons(int bulb, int sol, int flake, int gov)
+void set_indicator_icons(struct Sprite *bulb, struct Sprite *sol,
+                        struct Sprite *flake, struct Sprite *gov)
 {
   /* PORTME */
 }
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.233
diff -u -r1.233 mapview.c
--- client/gui-gtk/mapview.c    11 Oct 2004 01:52:16 -0000      1.233
+++ client/gui-gtk/mapview.c    11 Feb 2005 22:00:41 -0000
@@ -128,7 +128,7 @@
   set_indicator_icons(client_research_sprite(),
                      client_warming_sprite(),
                      client_cooling_sprite(),
-                     game.player_ptr->government);
+                     client_government_sprite());
 
   d=0;
   for (; d < game.player_ptr->economic.luxury /10; d++) {
@@ -228,31 +228,18 @@
   return sprites.treaty_thumb[BOOL_VAL(onoff)]->pixmap;
 }
 
-/**************************************************************************
-...
-**************************************************************************/
-void set_indicator_icons(int bulb, int sol, int flake, int gov)
+/****************************************************************************
+  Set information for the indicator icons typically shown in the main
+  client window.  The parameters tell which sprite to use for the
+  indicator.
+****************************************************************************/
+void set_indicator_icons(struct Sprite *bulb, struct Sprite *sol,
+                        struct Sprite *flake, struct Sprite *gov)
 {
-  struct Sprite *gov_sprite;
-
-  bulb = CLIP(0, bulb, NUM_TILES_PROGRESS-1);
-  sol = CLIP(0, sol, NUM_TILES_PROGRESS-1);
-  flake = CLIP(0, flake, NUM_TILES_PROGRESS-1);
-
-  gtk_pixmap_set(GTK_PIXMAP(bulb_label), sprites.bulb[bulb]->pixmap, NULL);
-  gtk_pixmap_set(GTK_PIXMAP(sun_label), sprites.warming[sol]->pixmap, NULL);
-  gtk_pixmap_set(GTK_PIXMAP(flake_label), sprites.cooling[flake]->pixmap, 
NULL);
-
-  if (game.government_count==0) {
-    /* HACK: the UNHAPPY citizen is used for the government
-     * when we don't know any better. */
-    struct citizen_type c = {.type = CITIZEN_UNHAPPY};
-
-    gov_sprite = get_citizen_sprite(c, 0, NULL);
-  } else {
-    gov_sprite = get_government(gov)->sprite;
-  }
-  gtk_pixmap_set(GTK_PIXMAP(government_label), gov_sprite->pixmap, NULL);
+  gtk_pixmap_set(GTK_PIXMAP(bulb_label), bulb->pixmap, bulb->mask);
+  gtk_pixmap_set(GTK_PIXMAP(sun_label), sol->pixmap, sol->mask);
+  gtk_pixmap_set(GTK_PIXMAP(flake_label), flake->pixmap, flake->mask);
+  gtk_pixmap_set(GTK_PIXMAP(government_label), gov->pixmap, gov->mask);
 }
 
 /**************************************************************************
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.157
diff -u -r1.157 mapview.c
--- client/gui-gtk-2.0/mapview.c        5 Feb 2005 07:41:53 -0000       1.157
+++ client/gui-gtk-2.0/mapview.c        11 Feb 2005 22:00:41 -0000
@@ -108,7 +108,6 @@
 void update_info_label( void )
 {
   int  d;
-  int  sol, flake;
   GtkWidget *label;
 
   label = gtk_frame_get_label_widget(GTK_FRAME(main_frame_civ_name));
@@ -117,12 +116,10 @@
 
   gtk_label_set_text(GTK_LABEL(main_label_info), get_info_label_text());
 
-  sol = client_warming_sprite();
-  flake = client_cooling_sprite();
   set_indicator_icons(client_research_sprite(),
-                     sol,
-                     flake,
-                     game.player_ptr->government);
+                     client_warming_sprite(),
+                     client_cooling_sprite(),
+                     client_government_sprite());
 
   d=0;
   for (; d < game.player_ptr->economic.luxury /10; d++) {
@@ -221,35 +218,22 @@
   return sprite_get_pixbuf(sprites.treaty_thumb[BOOL_VAL(onoff)]);
 }
 
-/**************************************************************************
-...
-**************************************************************************/
-void set_indicator_icons(int bulb, int sol, int flake, int gov)
+/****************************************************************************
+  Set information for the indicator icons typically shown in the main
+  client window.  The parameters tell which sprite to use for the
+  indicator.
+****************************************************************************/
+void set_indicator_icons(struct Sprite *bulb, struct Sprite *sol,
+                        struct Sprite *flake, struct Sprite *gov)
 {
-  struct Sprite *gov_sprite;
-
-  bulb = CLIP(0, bulb, NUM_TILES_PROGRESS-1);
-  sol = CLIP(0, sol, NUM_TILES_PROGRESS-1);
-  flake = CLIP(0, flake, NUM_TILES_PROGRESS-1);
-
   gtk_image_set_from_pixbuf(GTK_IMAGE(bulb_label),
-                           sprite_get_pixbuf(sprites.bulb[bulb]));
+                           sprite_get_pixbuf(bulb));
   gtk_image_set_from_pixbuf(GTK_IMAGE(sun_label),
-                           sprite_get_pixbuf(sprites.warming[sol]));
+                           sprite_get_pixbuf(sol));
   gtk_image_set_from_pixbuf(GTK_IMAGE(flake_label),
-                           sprite_get_pixbuf(sprites.cooling[flake]));
-
-  if (game.government_count==0) {
-    /* HACK: the UNHAPPY citizen is used for the government
-     * when we don't know any better. */
-    struct citizen_type c = {.type = CITIZEN_UNHAPPY};
-
-    gov_sprite = get_citizen_sprite(c, 0, NULL);
-  } else {
-    gov_sprite = get_government(gov)->sprite;
-  }
+                           sprite_get_pixbuf(flake));
   gtk_image_set_from_pixbuf(GTK_IMAGE(government_label),
-                           sprite_get_pixbuf(gov_sprite));
+                           sprite_get_pixbuf(gov));
 }
 
 /**************************************************************************
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.76
diff -u -r1.76 mapview.c
--- client/gui-sdl/mapview.c    10 Feb 2005 18:35:17 -0000      1.76
+++ client/gui-sdl/mapview.c    11 Feb 2005 22:00:41 -0000
@@ -377,21 +377,18 @@
   client window.  The parameters tell which sprite to use for the
   indicator.
 **************************************************************************/
-void set_indicator_icons(int bulb, int sol, int flake, int gov)
+void set_indicator_icons(struct Sprite *bulb, struct Sprite *sol,
+                        struct Sprite *flake, struct Sprite *gov)
 {
   struct GUI *pBuf = NULL;
   char cBuf[128];
   
-  bulb = CLIP(0, bulb, NUM_TILES_PROGRESS - 1);
-  sol = CLIP(0, sol, NUM_TILES_PROGRESS - 1);
-  flake = CLIP(0, flake, NUM_TILES_PROGRESS - 1);
-
   pBuf = get_widget_pointer_form_main_list(ID_WARMING_ICON);
-  pBuf->theme = GET_SURF(sprites.warming[sol]);
+  pBuf->theme = GET_SURF(sol);
   redraw_label(pBuf);
     
   pBuf = get_widget_pointer_form_main_list(ID_COOLING_ICON);
-  pBuf->theme = GET_SURF(sprites.cooling[flake]);
+  pBuf->theme = GET_SURF(flake);
   redraw_label(pBuf);
     
   putframe(pBuf->dst, pBuf->size.x - pBuf->size.w - 1,
@@ -404,19 +401,8 @@
              2 * pBuf->size.w + 2, 2 * pBuf->size.h + 2);
 
   if (SDL_Client_Flags & CF_REVOLUTION) {
-    struct Sprite *sprite = NULL;
-    if (game.government_count == 0) {
-      /* HACK: the UNHAPPY citizen is used for the government
-       * when we don't know any better. */
-      struct citizen_type c = {.type = CITIZEN_UNHAPPY};
-
-      sprite = get_citizen_sprite(c, 0, NULL);
-    } else {
-      sprite = get_government(gov)->sprite;
-    }
-
     pBuf = get_revolution_widget();
-    set_new_icon2_theme(pBuf, GET_SURF(sprite), FALSE);
+    set_new_icon2_theme(pBuf, GET_SURF(gov), FALSE);
     
     my_snprintf(cBuf, sizeof(cBuf), _("Revolution (Shift + R)\n%s"),
                                get_gov_pplayer(game.player_ptr)->name);
@@ -459,7 +445,7 @@
 
   copy_chars_to_string16(pBuf->string16, cBuf);
   
-  set_new_icon2_theme(pBuf, GET_SURF(sprites.bulb[bulb]), FALSE);
+  set_new_icon2_theme(pBuf, GET_SURF(bulb), FALSE);
   redraw_widget(pBuf);
   sdl_dirty_rect(pBuf->size);
   
@@ -538,7 +524,7 @@
   set_indicator_icons(client_research_sprite(),
                      client_warming_sprite(),
                      client_cooling_sprite(),
-                     game.player_ptr->government);
+                     client_government_sprite());
 
   update_timeout_label();
 
Index: client/gui-stub/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/mapview.c,v
retrieving revision 1.48
diff -u -r1.48 mapview.c
--- client/gui-stub/mapview.c   20 Oct 2004 17:58:38 -0000      1.48
+++ client/gui-stub/mapview.c   11 Feb 2005 22:00:41 -0000
@@ -104,7 +104,8 @@
   client window.  The parameters tell which sprite to use for the
   indicator.
 ****************************************************************************/
-void set_indicator_icons(int bulb, int sol, int flake, int gov)
+void set_indicator_icons(struct Sprite *bulb, struct Sprite *sol,
+                        struct Sprite *flake, struct Sprite *gov)
 {
   /* PORTME */
 }
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.138
diff -u -r1.138 mapview.c
--- client/gui-win32/mapview.c  6 Feb 2005 04:16:14 -0000       1.138
+++ client/gui-win32/mapview.c  11 Feb 2005 22:00:41 -0000
@@ -240,7 +240,7 @@
   set_indicator_icons(client_research_sprite(),
                      client_warming_sprite(),
                       client_cooling_sprite(),
-                      game.player_ptr->government);
+                     client_government_sprite());
   
   hdc=GetDC(root_window);
   draw_rates(hdc);
@@ -314,30 +314,22 @@
   }
 }
 
-/**************************************************************************
-
-**************************************************************************/
-void
-set_indicator_icons(int bulb, int sol, int flake, int gov)
+/****************************************************************************
+  Set information for the indicator icons typically shown in the main
+  client window.  The parameters tell which sprite to use for the
+  indicator.
+****************************************************************************/
+void set_indicator_icons(struct Sprite *bulb, struct Sprite *sol,
+                        struct Sprite *flake, struct Sprite *gov)
 {
   int i;
   HDC hdc;
   
-  bulb = CLIP(0, bulb, NUM_TILES_PROGRESS-1);
-  sol = CLIP(0, sol, NUM_TILES_PROGRESS-1);
-  flake = CLIP(0, flake, NUM_TILES_PROGRESS-1);     
-  indicator_sprite[0]=sprites.bulb[bulb];
-  indicator_sprite[1]=sprites.warming[sol];
-  indicator_sprite[2]=sprites.cooling[flake];
-  if (game.government_count==0) {
-    /* HACK: the UNHAPPY citizen is used for the government
-     * when we don't know any better. */
-    struct citizen_type c = {.type = CITIZEN_UNHAPPY};
+  indicator_sprite[0] = bulb;
+  indicator_sprite[1] = sol;
+  indicator_sprite[2] = flake;
+  indicator_sprite[3] = gov;
 
-    indicator_sprite[3] = get_citizen_sprite(c, 0, NULL);
-  } else {
-    indicator_sprite[3] = get_government(gov)->sprite;    
-  }
   hdc=GetDC(root_window);
   for(i=0;i<4;i++)
     draw_sprite(indicator_sprite[i],hdc,i*SMALL_TILE_WIDTH,indicator_y); 
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.101
diff -u -r1.101 gui_main.c
--- client/gui-xaw/gui_main.c   11 Feb 2005 16:58:00 -0000      1.101
+++ client/gui-xaw/gui_main.c   11 Feb 2005 22:00:42 -0000
@@ -486,7 +486,10 @@
                                       UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT, 
                                       display_depth);  
 
-  set_indicator_icons(0, 0, 0, 0);
+  set_indicator_icons(client_research_sprite(),
+                     client_warming_sprite(),
+                     client_cooling_sprite(),
+                     client_government_sprite());
 
   wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", 0);
   XSetWMProtocols(display, XtWindow(toplevel), &wm_delete_window, 1);
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.187
diff -u -r1.187 mapview.c
--- client/gui-xaw/mapview.c    8 Feb 2005 18:14:13 -0000       1.187
+++ client/gui-xaw/mapview.c    11 Feb 2005 22:00:42 -0000
@@ -172,7 +172,7 @@
   set_indicator_icons(client_research_sprite(),
                      client_warming_sprite(),
                      client_cooling_sprite(),
-                     game.player_ptr->government);
+                     client_government_sprite());
 
   d=0;
   for(;d<(game.player_ptr->economic.luxury)/10;d++)
@@ -257,28 +257,13 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void set_indicator_icons(int bulb, int sol, int flake, int gov)
+void set_indicator_icons(struct Sprite *bulb, struct Sprite *sol,
+                        struct Sprite *flake, struct Sprite *gov)
 {
-  struct Sprite *gov_sprite;
-
-  bulb = CLIP(0, bulb, NUM_TILES_PROGRESS-1);
-  sol = CLIP(0, sol, NUM_TILES_PROGRESS-1);
-  flake = CLIP(0, flake, NUM_TILES_PROGRESS-1);
-
-  xaw_set_bitmap(bulb_label, sprites.bulb[bulb]->pixmap);
-  xaw_set_bitmap(sun_label, sprites.warming[sol]->pixmap);
-  xaw_set_bitmap(flake_label, sprites.cooling[flake]->pixmap);
-
-  if (game.government_count==0) {
-    /* HACK: the UNHAPPY citizen is used for the government
-     * when we don't know any better. */
-    struct citizen_type c = {.type = CITIZEN_UNHAPPY};
-
-    gov_sprite = get_citizen_sprite(c, 0, NULL);
-  } else {
-    gov_sprite = get_government(gov)->sprite;
-  }
-  xaw_set_bitmap(government_label, gov_sprite->pixmap);
+  xaw_set_bitmap(bulb_label, bulb->pixmap);
+  xaw_set_bitmap(sun_label, sol->pixmap);
+  xaw_set_bitmap(flake_label, flake->pixmap);
+  xaw_set_bitmap(government_label, gov->pixmap);
 }
 
 /**************************************************************************
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.58
diff -u -r1.58 mapview_g.h
--- client/include/mapview_g.h  29 Sep 2004 02:24:22 -0000      1.58
+++ client/include/mapview_g.h  11 Feb 2005 22:00:42 -0000
@@ -26,7 +26,8 @@
 void update_timeout_label(void);
 void update_turn_done_button(bool do_restore);
 void update_city_descriptions(void);
-void set_indicator_icons(int bulb, int sol, int flake, int gov);
+void set_indicator_icons(struct Sprite *bulb, struct Sprite *sol,
+                        struct Sprite *flake, struct Sprite *gov);
 
 void map_size_changed(void);
 struct canvas *canvas_create(int width, int height);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12220) fixes to set_indicator_icons and client_xxx_sprite, Jason Short <=