Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] (PR#3712) City choose production dialog
Home

[Freeciv-Dev] (PR#3712) City choose production dialog

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: dspeyer@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#3712) City choose production dialog
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Thu, 1 Apr 2004 14:16:36 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=3712 >

> [vasc - Thu Apr 01 21:24:53 2004]:
> Even better, add icons instead. It would still be nice to make redundant
> buildings and obsolete wonders be displayed differently, say, using an
> italic font. This patch adds icon support.

In this one, the redundant buildings and obsolete wonders should be
displayed with strikethrough text. I also made the cell height constant,
rather than the height of each icon.

Index: client/gui-gtk-2.0/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.c,v
retrieving revision 1.24
diff -u -r1.24 graphics.c
--- client/gui-gtk-2.0/graphics.c       24 Mar 2004 06:18:18 -0000      1.24
+++ client/gui-gtk-2.0/graphics.c       1 Apr 2004 22:13:54 -0000
@@ -382,7 +382,7 @@
 /***************************************************************************
  ...
 ***************************************************************************/
-void create_overlay_unit(GtkWidget *pixcomm, int i)
+void create_overlay_unit(struct canvas *pcanvas, int i)
 {
   enum color_std bg_color;
   
@@ -394,23 +394,23 @@
     case AIR_MOVING:  bg_color = COLOR_STD_CYAN;   break;
     default:         bg_color = COLOR_STD_BLACK;  break;
   }
-  gtk_pixcomm_freeze(GTK_PIXCOMM(pixcomm));
-  gtk_pixcomm_fill(GTK_PIXCOMM(pixcomm), colors_standard[bg_color]);
+  canvas_put_rectangle(pcanvas, bg_color,
+      0, 0, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
 
+ 
   /* If we're using flags, put one on the tile */
   if(!solid_color_behind_units)  {
     struct Sprite *flag=get_nation_by_plr(game.player_ptr)->flag_sprite;
 
-    gtk_pixcomm_copyto(GTK_PIXCOMM(pixcomm), flag, 0, 0);
+    canvas_put_sprite_full(pcanvas, 0, 0, flag);
   }
 
   /* Finally, put a picture of the unit in the tile */
   if(i<game.num_unit_types) {
     struct Sprite *s=get_unit_type(i)->sprite;
 
-    gtk_pixcomm_copyto(GTK_PIXCOMM(pixcomm), s, 0, 0);
+    canvas_put_sprite_full(pcanvas, 0, 0, s);
   }
-  gtk_pixcomm_thaw(GTK_PIXCOMM(pixcomm));
 }
 
 /***************************************************************************
Index: client/gui-gtk-2.0/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.h,v
retrieving revision 1.7
diff -u -r1.7 graphics.h
--- client/gui-gtk-2.0/graphics.h       19 Jul 2003 02:04:30 -0000      1.7
+++ client/gui-gtk-2.0/graphics.h       1 Apr 2004 22:13:54 -0000
@@ -16,6 +16,7 @@
 #include <gtk/gtk.h>
 
 #include "graphics_g.h"
+#include "mapview_common.h"
 
 struct Sprite
 {
@@ -30,7 +31,7 @@
 
 typedef struct Sprite SPRITE;
 
-void   create_overlay_unit     (GtkWidget *pixcomm, int i);
+void create_overlay_unit(struct canvas *pcanvas, int i);
 
 extern SPRITE *    intro_gfx_sprite;
 extern SPRITE *    radar_gfx_sprite;
Index: client/gui-gtk-2.0/helpdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/helpdlg.c,v
retrieving revision 1.28
diff -u -r1.28 helpdlg.c
--- client/gui-gtk-2.0/helpdlg.c        25 Feb 2004 20:09:50 -0000      1.28
+++ client/gui-gtk-2.0/helpdlg.c        1 Apr 2004 22:14:02 -0000
@@ -800,8 +800,15 @@
     gtk_text_buffer_set_text(help_text, buf, -1);
     gtk_widget_show(help_text_sw);
 
-    create_overlay_unit(unit_tile
-    , i);
+    gtk_pixcomm_freeze(GTK_PIXCOMM(unit_tile));
+    {
+      struct canvas store;
+
+      store.type = CANVAS_PIXCOMM;
+      store.v.pixcomm = GTK_PIXCOMM(unit_tile);
+      create_overlay_unit(&store, i);
+    }
+    gtk_pixcomm_thaw(GTK_PIXCOMM(unit_tile));
     gtk_widget_show(unit_tile);
   }
   else {
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.112
diff -u -r1.112 mapview.c
--- client/gui-gtk-2.0/mapview.c        31 Mar 2004 18:42:45 -0000      1.112
+++ client/gui-gtk-2.0/mapview.c        1 Apr 2004 22:14:02 -0000
@@ -794,7 +794,8 @@
       break;
     case CANVAS_PIXBUF:
       gdk_pixbuf_fill(pcanvas->v.pixbuf,
-         col->red >> 24 | col->green >> 16 | col->blue >> 8 | 0xFF);
+         ((guint32)(col->red & 0xff00) << 16)
+         | ((col->green & 0xff00) << 8) | (col->blue & 0xff00) | 0xff);
       break;
     default:
       break;
Index: client/gui-gtk-2.0/wldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/wldlg.c,v
retrieving revision 1.28
diff -u -r1.28 wldlg.c
--- client/gui-gtk-2.0/wldlg.c  23 Nov 2003 18:56:57 -0000      1.28
+++ client/gui-gtk-2.0/wldlg.c  1 Apr 2004 22:14:02 -0000
@@ -37,6 +37,7 @@
 #include "climisc.h"
 #include "clinet.h"
 #include "options.h"
+#include "tilespec.h"
 
 #include "wldlg.h"
 #include "citydlg.h"
@@ -777,27 +778,105 @@
                             GtkTreeModel *model, GtkTreeIter *it,
                             gpointer data)
 {
-  struct city **pcity;
-  gint column;
-  char *row[4];
-  char  buf[4][64];
-  gint  cid;
-  int   i;
-  bool  is_unit;
+  gint cid, id;
+  bool is_unit;
 
-  pcity = (struct city **) data;
-  column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(rend), "column"));
+  gtk_tree_model_get(model, it, 0, &cid, -1);
+  is_unit = cid_is_unit(cid);
+  id = cid_id(cid);
+
+  if (GTK_IS_CELL_RENDERER_PIXBUF(rend)) {
+    GdkPixbuf *pix;
+
+    if (is_unit) {
+      struct canvas store;
+
+      pix = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
+         UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
+
+      store.type = CANVAS_PIXBUF;
+      store.v.pixbuf = pix;
+      create_overlay_unit(&store, id);
+
+      g_object_set(rend, "pixbuf", pix, NULL);
+      g_object_unref(pix);
+    } else {
+      struct impr_type *impr = get_improvement_type(id);
 
-  for (i = 0; i < ARRAY_SIZE(row); i++) {
-    row[i] = buf[i];
+      pix = sprite_get_pixbuf(impr->sprite);
+      g_object_set(rend, "pixbuf", pix, NULL);
+    }
+  } else {
+    struct city **pcity;
+    struct player *plr;
+    gint column;
+    char *row[4];
+    char  buf[4][64];
+    int   i;
+    gboolean useless;
+
+    pcity = (struct city **) data;
+
+    for (i = 0; i < ARRAY_SIZE(row); i++) {
+      row[i] = buf[i];
+    }
+    column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(rend), "column"));
+
+    get_city_dialog_production_row(row, sizeof(buf[0]), id, is_unit, *pcity);
+    g_object_set(rend, "text", row[column], NULL);
+
+    plr = city_owner(*pcity);
+    useless = improvement_obsolete(plr, id)
+      || improvement_redundant(plr, *pcity, id, FALSE);
+    g_object_set(rend, "strikethrough", useless, NULL);
   }
+}
 
-  gtk_tree_model_get(model, it, 0, &cid, -1);
-  is_unit = cid_is_unit(cid);
+/****************************************************************
+...
+*****************************************************************/
+static void populate_view(GtkTreeView *view, struct city **ppcity,
+                         GtkTreeViewColumn **pcol)
+{
+  static char *titles[] =
+  { N_("Type"), N_("Name"), N_("Info"), N_("Cost"), N_("Turns") };
+
+  static bool titles_done;
+  gint i;
+
+
+  intl_slist(ARRAY_SIZE(titles), titles, &titles_done);
+
+  for (i = 0; i < ARRAY_SIZE(titles); i++) {
+    GtkCellRenderer *rend;
+    GtkTreeViewColumn *col;
+
+    if (i == 0) {
+      rend = gtk_cell_renderer_pixbuf_new();
+
+      gtk_tree_view_insert_column_with_data_func(view,
+         i, titles[i], rend, cell_render_func, ppcity, NULL);
+    } else {
+      gint pos = i-1;
+
+      rend = gtk_cell_renderer_text_new();
+      g_object_set_data(G_OBJECT(rend), "column", GINT_TO_POINTER(pos));
 
-  get_city_dialog_production_row(row, sizeof(buf[0]), cid_id(cid),
-                                is_unit, *pcity);
-  g_object_set(rend, "text", row[column], NULL);
+      gtk_tree_view_insert_column_with_data_func(view,
+         i, titles[i], rend, cell_render_func, ppcity, NULL); 
+      col = gtk_tree_view_get_column(view, i);
+
+      if (pos >= 2) {
+       g_object_set(G_OBJECT(rend), "xalign", 1.0, NULL);
+       gtk_tree_view_column_set_alignment(col, 1.0);
+      }
+
+      if (pos == 3) {
+       *pcol = col;
+      }
+    }
+    g_object_set(rend, "height", UNIT_TILE_HEIGHT, NULL);
+  }
 }
 
 /****************************************************************
@@ -813,12 +892,6 @@
 
   GtkListStore *src_store, *dst_store;
 
-  static char *titles[] =
-  { N_("Type"), N_("Info"), N_("Cost"), N_("Turns") };
-
-  static bool titles_done;
-  gint i;
-
   struct worklist_data *ptr;
 
 
@@ -834,8 +907,6 @@
   ptr->future = FALSE;
 
 
-  intl_slist(ARRAY_SIZE(titles), titles, &titles_done);
-
   /* create shell. */ 
   editor = gtk_vbox_new(FALSE, 6);
   g_signal_connect(editor, "destroy", G_CALLBACK(worklist_destroy), ptr);
@@ -861,29 +932,7 @@
   g_object_unref(src_store);
   gtk_size_group_add_widget(group, src_view);
 
-  for (i = 0; i < ARRAY_SIZE(titles); i++) {
-    GtkCellRenderer *rend;
-    GtkTreeViewColumn *col;
-
-    rend = gtk_cell_renderer_text_new();
-    g_object_set_data(G_OBJECT(rend), "column", GINT_TO_POINTER(i));
-
-    gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(src_view),
-                                              i, titles[i], rend,
-                                              cell_render_func,
-                                              &ptr->pcity, NULL);
-
-    col = gtk_tree_view_get_column(GTK_TREE_VIEW(src_view), i);
-
-    if (i >= 2) {
-      g_object_set(G_OBJECT(rend), "xalign", 1.0, NULL);
-      gtk_tree_view_column_set_alignment(col, 1.0);
-    }
-
-    if (i == 3) {
-      ptr->src_col = col;
-    }
-  }
+  populate_view(GTK_TREE_VIEW(src_view), &ptr->pcity, &ptr->src_col);
   gtk_container_add(GTK_CONTAINER(sw), src_view);
 
   label = g_object_new(GTK_TYPE_LABEL,
@@ -920,29 +969,7 @@
   g_object_unref(dst_store);
   gtk_size_group_add_widget(group, dst_view);
 
-  for (i = 0; i < ARRAY_SIZE(titles); i++) {
-    GtkCellRenderer *rend;
-    GtkTreeViewColumn *col;
-
-    rend = gtk_cell_renderer_text_new();
-    g_object_set_data(G_OBJECT(rend), "column", GINT_TO_POINTER(i));
-
-    gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(dst_view),
-                                              i, titles[i], rend,
-                                              cell_render_func,
-                                              &ptr->pcity, NULL);
-
-    col = gtk_tree_view_get_column(GTK_TREE_VIEW(dst_view), i);
-
-    if (i >= 2) {
-      g_object_set(G_OBJECT(rend), "xalign", 1.0, NULL);
-      gtk_tree_view_column_set_alignment(col, 1.0);
-    }
-
-    if (i == 3) {
-      ptr->dst_col = col;
-    }
-  }
+  populate_view(GTK_TREE_VIEW(dst_view), &ptr->pcity, &ptr->dst_col);
   gtk_container_add(GTK_CONTAINER(sw), dst_view);
 
   label = g_object_new(GTK_TYPE_LABEL,

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