Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#13034) remove player_color from the color enumeration
Home

[Freeciv-Dev] (PR#13034) remove player_color from the color enumeration

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13034) remove player_color from the color enumeration
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 10 May 2005 14:46:47 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch removes the player color from the color_std enumeration.

1.  player_color() is moved into colors_common and renamed as
get_player_color for consistency.  It returns a color not an
enumeration.  This will allow easy addition of new colors.

2.  Internally, a separate enumeration of player colors is used in
colors_common.

3.  The COLOR_STD_RACEX enumeration names are *not* changed.  Fixing the
color enumeration will be a substantial task.  The colors should be
enumerated for specific tasks rather than given color names like "Red".
 Thus we will have something like COLOR_OVERVIEW_FOGGED_OCEAN.  The
tileset author will then be able to set an exact RGB value for each
color role.  But as I said that will be a more substantial change.

This patch itself is pretty simple.

-jason

Index: client/colors_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/colors_common.c,v
retrieving revision 1.1
diff -u -r1.1 colors_common.c
--- client/colors_common.c      9 May 2005 18:44:33 -0000       1.1
+++ client/colors_common.c      10 May 2005 21:43:40 -0000
@@ -19,16 +19,17 @@
 
 #include "shared.h"
 
+#include "player.h"
+
 #include "colors_g.h"
 
 #include "colors_common.h"
 
-
-static struct color *colors[COLOR_STD_LAST];
-
-static struct rgbtriple {
+struct rgbtriple {
   int r, g, b;
-} colors_standard_rgb[COLOR_STD_LAST] = {
+};
+
+struct rgbtriple colors_standard_rgb[COLOR_STD_LAST] = {
   {  0,   0,   0},  /* Black */
   {255, 255, 255},  /* White */
   {255,   0,   0},  /* Red */
@@ -37,6 +38,8 @@
   {  0, 200,   0},  /* Ground (green) */
   {  0,   0, 200},  /* Ocean (blue) */
   { 86,  86,  86},  /* Background (gray) */
+
+  /* TODO: Rename these appropriately. */
   {128,   0,   0},  /* race0 */
   {128, 255, 255},  /* race1 */
   {255,   0,   0},  /* race2 */
@@ -53,6 +56,26 @@
   {198, 198, 198},  /* race13 */
 };
 
+struct rgbtriple colors_player_rgb[] = {
+  {128,   0,   0},  /* race0 */
+  {128, 255, 255},  /* race1 */
+  {255,   0,   0},  /* race2 */
+  {255,   0, 128},  /* race3 */
+  {  0,   0, 128},  /* race4 */
+  {255,   0, 255},  /* race5 */
+  {255, 128,   0},  /* race6 */
+  {255, 255, 128},  /* race7 */
+  {255, 128, 128},  /* race8 */
+  {  0,   0, 255},  /* race9 */
+  {  0, 255,   0},  /* race10 */
+  {  0, 128, 128},  /* race11 */
+  {  0,  64,  64},  /* race12 */
+  {198, 198, 198},  /* race13 */
+};
+
+static struct color *colors[COLOR_STD_LAST];
+static struct color *player_colors[ARRAY_SIZE(colors_player_rgb)];
+
 static bool initted = FALSE;
 
 /****************************************************************************
@@ -73,6 +96,12 @@
                            colors_standard_rgb[i].g,
                            colors_standard_rgb[i].b);
   }
+
+  for (i = 0; i < ARRAY_SIZE(player_colors); i++) {
+    player_colors[i] = color_alloc(colors_player_rgb[i].r,
+                                  colors_player_rgb[i].g,
+                                  colors_player_rgb[i].b);
+  }
 }
 
 /****************************************************************************
@@ -88,6 +117,9 @@
   for (i = 0; i < COLOR_STD_LAST; i++) {
     color_free(colors[i]);
   }
+  for (i = 0; i < ARRAY_SIZE(player_colors); i++) {
+    color_free(player_colors[i]);
+  }
 }
 
 /****************************************************************************
@@ -97,3 +129,26 @@
 {
   return colors[color];
 }
+
+/**********************************************************************
+  Not sure which module to put this in...
+  It used to be that each nation had a color, when there was
+  fixed number of nations.  Now base on player number instead,
+  since still limited to less than 14.  Could possibly improve
+  to allow players to choose their preferred color etc.
+  A hack added to avoid returning more that COLOR_STD_RACE13.
+  But really there should be more colors available -- jk.
+***********************************************************************/
+struct color *get_player_color(const struct player *pplayer)
+{
+  if (pplayer) {
+    int index = pplayer->player_no;
+
+    assert(index >= 0);
+    index %= ARRAY_SIZE(player_colors);
+    return player_colors[index];
+  } else {
+    assert(0);
+    return NULL;
+  }
+}
Index: client/colors_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/colors_common.h,v
retrieving revision 1.1
diff -u -r1.1 colors_common.h
--- client/colors_common.h      9 May 2005 18:44:33 -0000       1.1
+++ client/colors_common.h      10 May 2005 21:43:40 -0000
@@ -14,6 +14,8 @@
 #ifndef FC__COLORS_COMMON_H
 #define FC__COLORS_COMMON_H
 
+#include "fc_types.h"
+
 /* The color system is designed on the assumption that almost, but
  * not quite, all displays will be truecolor. */
 
@@ -37,5 +39,6 @@
 void color_free_system(void);
 
 struct color *get_color(enum color_std color);
+struct color *get_player_color(const struct player *pplayer);
 
 #endif /* FC__COLORS_COMMON_H */
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.234
diff -u -r1.234 mapview_common.c
--- client/mapview_common.c     10 May 2005 20:02:07 -0000      1.234
+++ client/mapview_common.c     10 May 2005 21:43:41 -0000
@@ -1251,7 +1251,8 @@
   const bool line2 = ((draw_city_productions || draw_city_growth)
                      && pcity->owner == game.info.player_idx);
   static char name[512], growth[32], prod[512], size[32];
-  enum color_std growth_color, owner_color;
+  enum color_std growth_color;
+  struct color *owner_color;
   struct {
     int x, y, w, h;
   } name_rect = {0, 0, 0, 0}, growth_rect = {0, 0, 0, 0},
@@ -1363,17 +1364,17 @@
                        bg, 0, 0, *width - x, *height - y);
     }
   }
-  owner_color = player_color(city_owner(pcity));
+  owner_color = get_player_color(city_owner(pcity));
   if (line1) {
     canvas_put_sprite_full(pcanvas, flag_rect.x, flag_rect.y, flag);
-    canvas_put_line(pcanvas, get_color(owner_color), LINE_NORMAL,
+    canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
                    flag_rect.x + flag_rect.w - 1, canvas_y,
                    0, height1);
     canvas_put_sprite_full(pcanvas, occupy_rect.x, occupy_rect.y, occupy);
     canvas_put_text(pcanvas, name_rect.x, name_rect.y,
                    FONT_CITY_NAME, get_color(COLOR_STD_WHITE), name);
 
-    canvas_put_rectangle(pcanvas, get_color(owner_color),
+    canvas_put_rectangle(pcanvas, owner_color,
                         size_rect.x - border / 2, canvas_y,
                         size_rect.w + border, height1);
     canvas_put_text(pcanvas, size_rect.x, size_rect.y,
@@ -1388,20 +1389,20 @@
     canvas_put_text(pcanvas, growth_rect.x, growth_rect.y,
                    FONT_CITY_PROD, get_color(growth_color), growth);
   }
-  canvas_put_line(pcanvas, get_color(owner_color), LINE_NORMAL,
+  canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
                  canvas_x - *width / 2, canvas_y,
                  *width, 0);
-  canvas_put_line(pcanvas, get_color(owner_color), LINE_NORMAL,
+  canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
                  canvas_x - *width / 2, canvas_y,
                  0, *height);
-  canvas_put_line(pcanvas, get_color(owner_color), LINE_NORMAL,
+  canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
                  canvas_x - *width / 2, canvas_y + *height - 1,
                  *width, 0);
-  canvas_put_line(pcanvas, get_color(owner_color), LINE_NORMAL,
+  canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
                  canvas_x - *width / 2 + *width, canvas_y,
                  0, *height);
   if (line1 && line2) {
-    canvas_put_line(pcanvas, get_color(owner_color), LINE_NORMAL,
+    canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
                    canvas_x - *width / 2, canvas_y + height1 - 1,
                    *width, 0);
   }
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.303
diff -u -r1.303 tilespec.c
--- client/tilespec.c   10 May 2005 17:01:23 -0000      1.303
+++ client/tilespec.c   10 May 2005 21:43:42 -0000
@@ -4120,22 +4120,6 @@
   t->sprites.city.tile = NULL;
 }
 
-/**********************************************************************
-  Not sure which module to put this in...
-  It used to be that each nation had a color, when there was
-  fixed number of nations.  Now base on player number instead,
-  since still limited to less than 14.  Could possibly improve
-  to allow players to choose their preferred color etc.
-  A hack added to avoid returning more that COLOR_STD_RACE13.
-  But really there should be more colors available -- jk.
-***********************************************************************/
-enum color_std player_color(const struct player *pplayer)
-{
-  return COLOR_STD_RACE0 +
-    (pplayer->player_no %
-     (COLOR_STD_RACE13 - COLOR_STD_RACE0 + 1));
-}
-
 /****************************************************************************
   Return the amount of time between calls to toggle_focus_unit_state.
   The main loop needs to call toggle_focus_unit_state about this often
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.151
diff -u -r1.151 tilespec.h
--- client/tilespec.h   30 Apr 2005 17:09:25 -0000      1.151
+++ client/tilespec.h   10 May 2005 21:43:42 -0000
@@ -21,7 +21,6 @@
 #include "fc_types.h"
 
 #include "citydlg_common.h"    /* enum citizen_type */
-#include "colors_g.h"
 #include "options.h"
 
 struct sprite;                 /* opaque; gui-dep */
@@ -133,8 +132,6 @@
                      const struct unit *punit, const struct city *pcity,
                      const struct city *citymode);
 
-enum color_std player_color(const struct player *pplayer);
-
 double get_focus_unit_toggle_timeout(const struct tileset *t);
 void reset_focus_unit_state(struct tileset *t);
 void toggle_focus_unit_state(struct tileset *t);
Index: client/gui-gtk-2.0/plrdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/plrdlg.c,v
retrieving revision 1.59
diff -u -r1.59 plrdlg.c
--- client/gui-gtk-2.0/plrdlg.c 9 May 2005 18:42:19 -0000       1.59
+++ client/gui-gtk-2.0/plrdlg.c 10 May 2005 21:43:42 -0000
@@ -113,7 +113,7 @@
   gdk_gc_set_foreground(civ_gc, &get_color(COLOR_STD_BLACK)->color);
   gdk_draw_rectangle(pixmap, civ_gc, TRUE, 0, 0, width, height);
 
-  gdk_gc_set_foreground(civ_gc, &get_color(player_color(plr))->color);
+  gdk_gc_set_foreground(civ_gc, &get_player_color(plr)->color);
   gdk_draw_rectangle(pixmap, civ_gc, TRUE, 1, 1, width - 2, height - 2);
 
   tmp = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13034) remove player_color from the color enumeration, Jason Short <=