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: Wed, 12 May 2004 01:19:40 -0700
Reply-to: rt@xxxxxxxxxxx

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

I haven't forgotten this -- I just had to do class-work for a month or 
so.  I'm back now.

Vasco Alexandre da Silva Costa wrote:

><URL: http://rt.freeciv.org/Ticket/Display.html?id=8482 >
>
>On Sat, 10 Apr 2004, Daniel L Speyer wrote:
>
>  
>
>><URL: http://rt.freeciv.org/Ticket/Display.html?id=8482 >
>>
>>The current setup of the worklist windows (NORMAL_TILE_HEIGHT whether it
>>needs it or not) in gtk2 uses an awful lot of empty space.  It makes it
>>more necessary to scroll and is (IMHO) ugly.  This patch auto-detects
>>units' actual heights and uses them.
>>    
>>
>
>I looked at your patch again and noticed it does not have a fixed row
>height.
>
>The row height is fixed for a reason: if the size is fixed you can
>predictably point and click at something without looking well at it. It is
>user disturbing and counter productive to have a chaotic misaligned user
>interface. At best I may compromise and provide for a gamut of different
>fixed sub-category heights. i.e. a fixed height for buildings, another
>for units. But doing it more or less randomly on each unit is
>sub-optimal.
>  
>
I'm not convinced on the usability angle (thunderbird, in which I'm 
writing this, has uneven toolbars, as does almost everything else that 
isn't built out of square icons) but I'll grant it on aesthetics, and I 
don't care all that much, so here's a version with constant height.  It 
calculates the relevant height and width once whenever a tileset is 
initialized.  Works well under any circumstance I can think of.

--Daniel Speyer

>---
>Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa
>
>
>  
>


--- 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);
+
   }
 }
 
--- wldlg.c.old 2004-05-11 19:23:40.000000000 -0400
+++ wldlg.c     2004-05-11 21:18:54.000000000 -0400
@@ -55,10 +55,31 @@
 
 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 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 +916,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 +1012,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-11 21:27:46.000000000 -0400
@@ -33,4 +33,6 @@
 
 void add_worklist_dnd_target(GtkWidget *w);
 
+void update_max_unit_size(void);
+
 #endif                         /* FC__WLDLG_H */

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