Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12513) move icons into the tileset
Home

[Freeciv-Dev] (PR#12513) move icons into the tileset

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12513) move icons into the tileset
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 14 Mar 2005 17:50:33 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch moves the icons (client/include/*.ico) into the tileset. 
This allows tileset authors to edit them (yay) rather than compiling 
them in with the game.  Apply the patch, untar the tarball, and do 'cvs 
rm' of the icon files.  I updated the gtk2 and xaw clients but only 
tested the gtk2 client.

The code to make the icon from the bitmap (in gtk2) was a bit ugly; the 
bitmap was used as the pixmap and the mask.  I renamed the .ico files as 
.xbm, used convert to change them to .png, then edited them with gimp to 
change the white to transparent.  I feel this is the right thing but it 
means the icon is now different: instead of showing up as white it shows 
as black.  I think this is a bugfix.  Of course it's up to tileset 
authors whether to change this icon in general (it could probably use a 
fixup).

Another note is that the citydlg icon, while used in the code, never 
shows up on my window manager.

-jason

? data/misc/cityicon.png
? data/misc/civicon.png
? data/misc/icons.spec
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.266
diff -u -r1.266 tilespec.c
--- client/tilespec.c   13 Mar 2005 17:53:44 -0000      1.266
+++ client/tilespec.c   15 Mar 2005 01:49:45 -0000
@@ -1438,6 +1438,13 @@
     sprites.cursor[i].hot_y = ss->hot_y;
   }
 
+  for (i = 0; i < ICON_COUNT; i++) {
+    const char *names[ICON_COUNT] = {"freeciv", "citydlg"};
+
+    my_snprintf(buffer, sizeof(buffer), "icon.%s", names[i]);
+    SET_SPRITE(icon[i], buffer);
+  }
+
   /* Isolated road graphics are used by roadstyle 0 and 1*/
   if (t->roadstyle == 0 || t->roadstyle == 1) {
     SET_SPRITE(road.isolated, "r.road_isolated");
@@ -3928,6 +3935,20 @@
 }
 
 /****************************************************************************
+  Return a sprite for the given icon.  Icons are used by the operating
+  system/window manager.  Usually freeciv has to tell the OS what icon to
+  use.
+
+  Note that this function will return NULL before the sprites are loaded.
+  The GUI code must be sure to call tileset_load_tiles before setting the
+  top-level icon.
+****************************************************************************/
+struct Sprite *get_icon_sprite(struct tileset *t, enum icon_type icon)
+{
+  return sprites.icon[icon];
+}
+
+/****************************************************************************
   Returns a sprite with the "user-attention" crosshair graphic.
 
   FIXME: This function shouldn't be needed if the attention graphics are
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.127
diff -u -r1.127 tilespec.h
--- client/tilespec.h   11 Mar 2005 17:11:26 -0000      1.127
+++ client/tilespec.h   15 Mar 2005 01:49:45 -0000
@@ -206,12 +206,20 @@
   INDICATOR_COUNT
 };
 
+enum icon_type {
+  ICON_FREECIV,
+  ICON_CITYDLG,
+  ICON_COUNT
+};
+
 struct named_sprites {
   struct Sprite
     *indicator[INDICATOR_COUNT][NUM_TILES_PROGRESS],
     *treaty_thumb[2],     /* 0=disagree, 1=agree */
     *right_arrow,
 
+    *icon[ICON_COUNT],
+
     /* The panel sprites for showing tax % allocations. */
     *tax_luxury, *tax_science, *tax_gold,
     *dither_tile;     /* only used for isometric view */
@@ -365,6 +373,7 @@
 struct sprite_vector *get_unit_explode_animation(void);
 struct Sprite *get_cursor_sprite(enum cursor_type cursor,
                                 int *hot_x, int *hot_y);
+struct Sprite *get_icon_sprite(struct tileset *t, enum icon_type icon);
 struct Sprite *get_attention_crosshair_sprite(void);
 struct Sprite *get_indicator_sprite(enum indicator_type indicator,
                                    int index);
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.118
diff -u -r1.118 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        14 Mar 2005 20:26:24 -0000      1.118
+++ client/gui-gtk-2.0/citydlg.c        15 Mar 2005 01:49:45 -0000
@@ -56,7 +56,6 @@
 #include "wldlg.h"
 #include "log.h"
 #include "text.h"
-#include "cityicon.ico"
 
 #include "citydlg.h"
 
@@ -174,7 +173,6 @@
   bool is_modal;
 };
 
-static GdkBitmap *icon_bitmap;
 static GtkRcStyle *info_label_style[NUM_INFO_STYLES] = { NULL, NULL, NULL };
 
 static struct dialog_list *dialog_list;
@@ -1223,13 +1221,8 @@
 
   gtk_widget_realize(pdialog->shell);
 
-  if (!icon_bitmap) {
-    icon_bitmap = gdk_bitmap_create_from_data(root_window, cityicon_bits,
-                                             cityicon_width,
-                                             cityicon_height);
-  }
-  gdk_window_set_icon(pdialog->shell->window, NULL, icon_bitmap,
-                     icon_bitmap);
+  gtk_window_set_icon(GTK_WINDOW(pdialog->shell),
+               sprite_get_pixbuf(get_icon_sprite(tileset, ICON_CITYDLG)));
 
   /* Set old size. The size isn't saved in any way. */
   if (citydialog_width && citydialog_height) {
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.112
diff -u -r1.112 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       5 Mar 2005 23:51:06 -0000       1.112
+++ client/gui-gtk-2.0/gui_main.c       15 Mar 2005 01:49:46 -0000
@@ -73,8 +73,6 @@
 #include "tilespec.h"
 
 
-#include "freeciv.ico"
-
 const char *client_string = "gui-gtk-2.0";
 
 GtkWidget *map_canvas;                  /* GtkDrawingArea */
@@ -1064,7 +1062,6 @@
 **************************************************************************/
 void ui_main(int argc, char **argv)
 {
-  GdkBitmap *icon_bitmap;
   const gchar *home;
   guint sig;
   GtkStyle *style;
@@ -1114,10 +1111,6 @@
   display_color_type = get_visual();
   init_color_system();
 
-  icon_bitmap = gdk_bitmap_create_from_data(root_window, freeciv_bits,
-                                            freeciv_width, freeciv_height);
-  gdk_window_set_icon(root_window, NULL, icon_bitmap, icon_bitmap);
-
   civ_gc = gdk_gc_new(root_window);
 
   /* font names shouldn't be in spec files! */
@@ -1190,6 +1183,10 @@
 
   tileset_load_tiles(tileset);
 
+  /* Only call this after tileset_load_tiles is called. */
+  gtk_window_set_icon(GTK_WINDOW(toplevel),
+               sprite_get_pixbuf(get_icon_sprite(tileset, ICON_FREECIV)));
+
   setup_widgets();
   load_cursors();
   cma_fe_init();
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.165
diff -u -r1.165 mapview.c
--- client/gui-gtk-2.0/mapview.c        11 Mar 2005 22:40:53 -0000      1.165
+++ client/gui-gtk-2.0/mapview.c        15 Mar 2005 01:49:46 -0000
@@ -1023,4 +1023,7 @@
   reset_city_dialogs();
   reset_unit_table();
   blank_max_unit_size();
+
+  gtk_window_set_icon(GTK_WINDOW(toplevel),
+               sprite_get_pixbuf(get_icon_sprite(tileset, ICON_FREECIV)));
 }
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.106
diff -u -r1.106 gui_main.c
--- client/gui-xaw/gui_main.c   5 Mar 2005 23:51:07 -0000       1.106
+++ client/gui-xaw/gui_main.c   15 Mar 2005 01:49:46 -0000
@@ -65,8 +65,6 @@
 
 #include "gui_main.h"
 
-#include "freeciv.ico"
-
 const char *client_string = "gui-xaw";
 
 const char * const gui_character_encoding = NULL;
@@ -284,7 +282,7 @@
 void ui_main(int argc, char *argv[])
 {
   int i;
-  Pixmap icon_pixmap; 
+  struct Sprite *icon; 
 
   parse_options(argc, argv);
 
@@ -344,12 +342,6 @@
     freelog(LOG_FATAL, _("Only color displays are supported for now..."));
     /*    exit(EXIT_FAILURE); */
   }
-  
-  icon_pixmap = XCreateBitmapFromData(display,
-                                     RootWindowOfScreen(XtScreen(toplevel)),
-                                     freeciv_bits,
-                                     freeciv_width, freeciv_height);
-  XtVaSetValues(toplevel, XtNiconPixmap, icon_pixmap, NULL);
 
   init_color_system();
 
@@ -446,6 +438,10 @@
   load_intro_gfx();
   load_cursors();
 
+  /* FIXME: what about the mask? */
+  icon = get_icon_sprite(tileset, ICON_FREECIV);
+  XtVaSetValues(toplevel, XtNiconPixmap, icon->pixmap, NULL);
+
   XtSetKeyboardFocus(bottom_form, inputline_text);
   XtSetKeyboardFocus(below_menu_form, map_canvas);
 
Index: client/include/cityicon.ico
===================================================================
RCS file: client/include/cityicon.ico
diff -N client/include/cityicon.ico
--- client/include/cityicon.ico 7 Nov 2002 15:04:18 -0000       1.2
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,17 +0,0 @@
-#define cityicon_width 40
-#define cityicon_height 40
-static char cityicon_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x01,0x00,0x00,0x80,0xff,0x07,0x00,0x00,
- 0x00,0x2d,0x06,0x00,0x00,0x00,0x2d,0x06,0x00,0x00,0x80,0xff,0x07,0x00,0x00,
- 0x00,0x2d,0x06,0x00,0x00,0x00,0x2d,0x06,0x00,0x00,0x80,0xff,0x07,0x00,0x00,
- 0x00,0xad,0x07,0x00,0x00,0x00,0xad,0x07,0x00,0x00,0x80,0xff,0x07,0x00,0x00,
- 0x00,0xad,0x07,0xf8,0x03,0x00,0xad,0x07,0xf8,0x03,0x00,0xed,0x07,0xf8,0x03,
- 0x00,0xed,0x07,0xf8,0x03,0x00,0xed,0x07,0xf8,0x03,0x00,0xed,0xff,0xfb,0x03,
- 0x00,0xed,0xff,0xfb,0x03,0x80,0x7f,0x04,0xfa,0x03,0x00,0x7d,0x04,0xfa,0x03,
- 0x00,0xfd,0xff,0xfb,0x03,0x00,0x7d,0x04,0xfa,0x03,0x00,0xfd,0xff,0xfb,0x03,
- 0x00,0xfd,0xff,0xfb,0x03,0x80,0x7f,0x04,0xfa,0x03,0x00,0xfd,0xff,0xfb,0x03,
- 0x00,0xe0,0xff,0xfb,0x03,0xd5,0x6b,0x04,0xfa,0x03,0x55,0xe8,0xff,0xfb,0x03,
- 0xff,0xef,0xff,0xfb,0x03,0x55,0x6b,0x04,0x00,0x00,0x55,0xe8,0x3f,0x04,0xf0,
- 0xff,0xef,0x3f,0x04,0xf0,0x55,0x68,0xe4,0xff,0xff,0x55,0xe8,0x3f,0x04,0xf0,
- 0xff,0xef,0xff,0xff,0xff,0x55,0x68,0x24,0x04,0xf0,0x55,0xe8,0x3f,0x04,0xf0,
- 0xff,0xef,0xff,0xff,0xff};
Index: client/include/freeciv.ico
===================================================================
RCS file: client/include/freeciv.ico
diff -N client/include/freeciv.ico
--- client/include/freeciv.ico  7 Nov 2002 15:04:18 -0000       1.4
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,17 +0,0 @@
-#define freeciv_width 40
-#define freeciv_height 40
-static char freeciv_bits[] = {
- 0x00,0x80,0xff,0x01,0x00,0x00,0xf0,0xd7,0x0f,0x00,0x00,0xbc,0x54,0x3e,0x00,
- 0x00,0x4a,0x92,0x54,0x00,0x80,0x25,0x92,0xa8,0x01,0x40,0x22,0x92,0x48,0x02,
- 0x20,0x11,0x11,0x91,0x04,0x90,0x08,0x11,0x21,0x09,0x90,0x08,0x11,0x21,0x09,
- 0x48,0x08,0x11,0x21,0x12,0x44,0x04,0x11,0x41,0x22,0x24,0x84,0x10,0x42,0x24,
- 0x22,0x84,0x10,0x42,0x44,0x22,0x84,0x10,0x42,0x44,0x22,0x82,0x10,0x82,0x44,
- 0x11,0x82,0x10,0x82,0x88,0x11,0x82,0x10,0x82,0x88,0x11,0x82,0x10,0x82,0x88,
- 0x11,0x82,0x10,0x82,0x88,0x11,0x82,0x10,0x82,0x88,0x11,0x82,0x10,0x82,0x88,
- 0x13,0x82,0x10,0x82,0xc8,0x1d,0x82,0x10,0x82,0xb8,0xf1,0x87,0x10,0xc2,0x8f,
- 0x11,0xfa,0xff,0xbf,0x88,0x22,0x82,0x10,0x82,0x44,0x22,0x84,0x10,0x42,0x44,
- 0x22,0x84,0x10,0x42,0x44,0x24,0x84,0x10,0x42,0x24,0x44,0x04,0x11,0x41,0x22,
- 0x48,0x08,0x11,0x21,0x12,0x90,0x08,0x11,0x21,0x09,0x90,0x08,0x11,0x21,0x09,
- 0x20,0x11,0x11,0x91,0x04,0x40,0x22,0x92,0x48,0x02,0x80,0x25,0x92,0xa8,0x01,
- 0x00,0x4a,0x92,0x54,0x00,0x00,0xbc,0xd4,0x3e,0x00,0x00,0xf0,0xd7,0x0f,0x00,
- 0x00,0x80,0xff,0x01,0x00};
Index: data/isophex.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isophex.tilespec,v
retrieving revision 1.10
diff -u -r1.10 isophex.tilespec
--- data/isophex.tilespec       3 Mar 2005 03:47:32 -0000       1.10
+++ data/isophex.tilespec       15 Mar 2005 01:49:46 -0000
@@ -73,6 +73,7 @@
   "misc/cursors.spec",
   "misc/space.spec",
   "misc/treaty.spec",
+  "misc/icons.spec",
   "isotrident/nuke.spec",
   "isotrident/cities.spec",
   "isophex/gold.spec",
Index: data/isotrident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident.tilespec,v
retrieving revision 1.33
diff -u -r1.33 isotrident.tilespec
--- data/isotrident.tilespec    3 Mar 2005 03:47:32 -0000       1.33
+++ data/isotrident.tilespec    15 Mar 2005 01:49:46 -0000
@@ -65,6 +65,7 @@
   "misc/space.spec",
 ;  "misc/techs.spec",
   "misc/treaty.spec",
+  "misc/icons.spec",
   "isotrident/fog.spec",
   "isotrident/nuke.spec",
   "trident/explosions.spec",
Index: data/trident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident.tilespec,v
retrieving revision 1.33
diff -u -r1.33 trident.tilespec
--- data/trident.tilespec       3 Mar 2005 03:47:32 -0000       1.33
+++ data/trident.tilespec       15 Mar 2005 01:49:46 -0000
@@ -58,6 +58,7 @@
   "misc/space.spec",
 ;  "misc/techs.spec",
   "misc/treaty.spec",
+  "misc/icons.spec",
   "trident/fog.spec",
   "trident/cities.spec",
   "trident/explosions.spec"
Index: data/trident_shields.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident_shields.tilespec,v
retrieving revision 1.24
diff -u -r1.24 trident_shields.tilespec
--- data/trident_shields.tilespec       3 Mar 2005 03:47:32 -0000       1.24
+++ data/trident_shields.tilespec       15 Mar 2005 01:49:46 -0000
@@ -62,6 +62,7 @@
   "misc/space.spec",
 ;  "misc/techs.spec",
   "misc/treaty.spec",
+  "misc/icons.spec",
   "trident/fog.spec",
   "trident/cities.spec",
   "trident/explosions.spec",
Index: data/misc/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/misc/Makefile.am,v
retrieving revision 1.11
diff -u -r1.11 Makefile.am
--- data/misc/Makefile.am       3 Mar 2005 03:47:32 -0000       1.11
+++ data/misc/Makefile.am       15 Mar 2005 01:49:46 -0000
@@ -8,11 +8,14 @@
        buildings.spec  \
        chiefs.png      \
        chiefs.spec     \
+       cityicon.png    \
+       civicon.png     \
        colors.png      \
        colors.spec     \
        cursors.png     \
        cursors.spec    \
        flags.spec      \
+       icons.spec      \
        intro.png       \
        overlays.png    \
        overlays.spec   \

Attachment: icons.tar.gz
Description: Unix tar archive


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12513) move icons into the tileset, Jason Short <=