Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] Re: (PR#8482) heights in gtk2 production dialog
Home

[Freeciv-Dev] Re: (PR#8482) heights in gtk2 production dialog

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8482) heights in gtk2 production dialog
From: "Daniel L Speyer" <dspeyer@xxxxxxxxxxx>
Date: Sat, 22 May 2004 11:38:56 -0700
Reply-to: rt@xxxxxxxxxxx

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

Vasco Alexandre da Silva Costa wrote:

><URL: http://rt.freeciv.org/Ticket/Display.html?id=8482 >
>[snip]
>
>Haven't had the time to properly read your code yet. But I assume it
>handles disconnects and reconnects (hence re-sending ruleset data), plus
>possible variations in improvement and unit gfx size. If it doesn't, it
>should.
>
>  
>
This version handles ruleset changes.  I had to create a special ruleset 
and tileset to test it, but you're right that we need to support the 
possibility of it mattering.

Any other features needed?

--Daniel Speyer


--- dialogs.c.old       2004-05-22 14:11:51.000000000 -0400
+++ dialogs.c   2004-05-22 14:23:43.000000000 -0400
@@ -1953,8 +1953,12 @@
   if (races_shell) {
     gtk_widget_destroy(races_shell);
   }
+  /* We're probably starting a new game, maybe with a new ruleset
+     So we warn the worklist dialog */
+  blank_max_unit_size();
 }
 
+
 /****************************************************************
   ...
  *****************************************************************/
--- graphics.c.old      2004-05-11 19:22:49.000000000 -0400
+++ graphics.c  2004-05-11 21:47:50.000000000 -0400
@@ -385,7 +385,19 @@
 void create_overlay_unit(struct canvas *pcanvas, int i)
 {
   enum color_std bg_color;
-  
+  int x1,x2,y1,y2;
+  int width,height;
+
+  sprite_get_bounding_box(get_unit_type(i)->sprite,&x1,&y1,&x2,&y2);
+  if (pcanvas->type==CANVAS_PIXBUF) {
+    width=gdk_pixbuf_get_width(pcanvas->v.pixbuf);
+    height=gdk_pixbuf_get_height(pcanvas->v.pixbuf);
+  } else {
+    /*Guess*/
+    width=NORMAL_TILE_WIDTH;
+    height=UNIT_TILE_HEIGHT;
+  }
+
   /* Give tile a background color, based on the type of unit */
   switch (get_unit_type(i)->move_type) {
     case LAND_MOVING: bg_color = COLOR_STD_GROUND; break;
@@ -395,21 +407,17 @@
     default:         bg_color = COLOR_STD_BLACK;  break;
   }
   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;
-
-    canvas_put_sprite_full(pcanvas, 0, 0, flag);
-  }
+      0, 0, width, height);
 
   /* Finally, put a picture of the unit in the tile */
   if(i<game.num_unit_types) {
     struct Sprite *s=get_unit_type(i)->sprite;
 
-    canvas_put_sprite_full(pcanvas, 0, 0, s);
+    canvas_put_sprite(pcanvas, 0, 0, s, 
+                     (x2+x1-width)/2, (y1+y2-height)/2, 
+                     NORMAL_TILE_WIDTH-(x2+x1-width)/2, 
+                     UNIT_TILE_HEIGHT-(y1+y2-height)/2);
+
   }
 }
 
--- mapview.c.old       2004-05-11 21:27:06.000000000 -0400
+++ mapview.c   2004-05-22 14:23:54.000000000 -0400
@@ -1106,4 +1106,5 @@
 {
   reset_city_dialogs();
   reset_unit_table();
+  blank_max_unit_size();
 }
--- wldlg.c.old 2004-05-11 19:23:40.000000000 -0400
+++ wldlg.c     2004-05-22 14:22:38.000000000 -0400
@@ -55,10 +55,36 @@
 
 static GtkListStore *worklists_store;
 
+static int max_unit_height=-1, max_unit_width=-1;
 
 static void popup_worklist(struct worklist *pwl);
 static void popdown_worklist(struct worklist *pwl);
 
+void blank_max_unit_size(){
+  max_unit_height=-1;
+  max_unit_width=-1;
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static void update_max_unit_size(){
+  max_unit_height=0;
+  max_unit_width=0;
+  unit_type_iterate(i){
+    int x1,x2,y1,y2;
+    sprite_get_bounding_box(get_unit_type(i)->sprite,&x1,&y1,&x2,&y2);
+    if (max_unit_width<x2-x1)
+      max_unit_width=x2-x1;
+    if (max_unit_height<y2-y1)
+      max_unit_height=y2-y1;
+  }unit_type_iterate_end;
+  impr_type_iterate(i){
+    if (max_unit_width<get_improvement_type(i)->sprite->width)
+      max_unit_width=get_improvement_type(i)->sprite->width;
+  }impr_type_iterate_end;
+}
+
 
 /****************************************************************
 ...
@@ -895,8 +921,11 @@
     if (is_unit) {
       struct canvas store;
 
+      if (max_unit_width==-1 || max_unit_height==-1)
+       update_max_unit_size();
+
       pix = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
-         UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
+         max_unit_width+4, max_unit_height+4);
 
       store.type = CANVAS_PIXBUF;
       store.v.pixbuf = pix;
@@ -988,9 +1017,6 @@
        *pcol = col;
       }
     }
-    if (show_task_icons) {
-      g_object_set(rend, "height", UNIT_TILE_HEIGHT, NULL);
-    }
   }
 }
 
--- wldlg.h.old 2004-05-11 19:23:43.000000000 -0400
+++ wldlg.h     2004-05-22 14:22:48.000000000 -0400
@@ -33,4 +33,6 @@
 
 void add_worklist_dnd_target(GtkWidget *w);
 
+void blank_max_unit_size(void);
+
 #endif                         /* FC__WLDLG_H */

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