Complete.Org: Mailing Lists: Archives: freeciv-dev: July 1999:
[Freeciv-Dev] patch: makes city dialog units scrollable (PR#79)
Home

[Freeciv-Dev] patch: makes city dialog units scrollable (PR#79)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] patch: makes city dialog units scrollable (PR#79)
From: pejean.lists@xxxxxxxxx
Date: Wed, 28 Jul 1999 22:12:22 -0700 (PDT)

This is a multi-part message in MIME format.
--------------154C2CDA2BFDFDA2E4432C48
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Currently, in the city dialog, only 12 supported units
and 12 present units can be shown.

This patch allows the player to see more of them and
adds a scroll bar under the supported units list and/or
the present units list when there isn't enough place to
show them all.

It works with the gtk client of the latest cvs.
--------------154C2CDA2BFDFDA2E4432C48
Content-Type: text/plain; charset=us-ascii;
 name="citydlg.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="citydlg.c.diff"

Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.16
diff -u -r1.16 citydlg.c
--- citydlg.c   1999/07/20 11:50:02     1.16
+++ citydlg.c   1999/07/28 20:41:42
@@ -52,7 +52,7 @@
 
 extern GtkStyle *city_dialog_style;
 
-#define NUM_UNITS_SHOWN  12
+#define NUM_UNITS_SHOWN  50
 #define NUM_CITIZENS_SHOWN 25
 
 
@@ -75,9 +75,11 @@
   GtkWidget *building_label, *progress_label, *buy_command, *change_command;
   GtkWidget *improvement_viewport, *improvement_list;
   GtkWidget *support_unit_label;
+  GtkWidget *support_unit_box;
   GtkWidget *support_unit_boxes                [NUM_UNITS_SHOWN];
   GtkWidget *support_unit_pixmaps      [NUM_UNITS_SHOWN];
   GtkWidget *present_unit_label;
+  GtkWidget *present_unit_box;
   GtkWidget *present_unit_boxes                [NUM_UNITS_SHOWN];
   GtkWidget *present_unit_pixmaps      [NUM_UNITS_SHOWN];
   GtkWidget *change_list;
@@ -293,11 +295,23 @@
 /****************************************************************
 ...
 *****************************************************************/
+void unit_scrollbar_callback (GtkAdjustment *adj, GtkWidget *scrollbar) {
+  if (adj->page_size < adj->upper && adj->page_size != 1)
+    gtk_widget_show (scrollbar);
+  else
+    gtk_widget_hide (scrollbar);
+}
+
+/****************************************************************
+...
+*****************************************************************/
 struct city_dialog *create_city_dialog(struct city *pcity, int make_modal)
 {
   int i;
   struct city_dialog *pdialog;
   GtkWidget *box, *table, *frame, *vbox, *scrolled;
+  GtkWidget *viewport, *support_units_scrollbar, *present_units_scrollbar;
+  GtkAdjustment *adjustment;
   GtkAccelGroup *accel=gtk_accel_group_new();
 
   pdialog=fc_malloc(sizeof(struct city_dialog));
@@ -438,30 +452,28 @@
        FALSE, FALSE, 0);
   gtk_widget_realize(pdialog->support_unit_label);
 
-  box=gtk_hbox_new(TRUE, 1);
+  box = gtk_vbox_new (FALSE, 1);
   gtk_container_add(GTK_CONTAINER(pdialog->support_unit_label),box);
   gtk_widget_realize(box);
 
-  for(i=0; i<NUM_UNITS_SHOWN; i++) {
-    pdialog->support_unit_boxes[i]=gtk_event_box_new();
-    gtk_widget_set_events(pdialog->support_unit_boxes[i],
-       GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK);
-
-    gtk_box_pack_start(GTK_BOX(box), pdialog->support_unit_boxes[i],
-                      TRUE, FALSE, 0);
-    gtk_widget_show(pdialog->support_unit_boxes[i]);
-
-    pdialog->support_unit_pixmaps[i]=
-     gtk_new_pixmap(NORMAL_TILE_WIDTH, 
NORMAL_TILE_HEIGHT+NORMAL_TILE_HEIGHT/2);
-    gtk_container_add(GTK_CONTAINER(pdialog->support_unit_boxes[i]),
-       pdialog->support_unit_pixmaps[i]);
+  viewport = gtk_viewport_new (NULL, NULL);
+  gtk_widget_set_usize (viewport,
+          NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT + NORMAL_TILE_HEIGHT / 2);
+  gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
+  gtk_box_pack_start (GTK_BOX (box), viewport, FALSE, FALSE, 0);
+
+  pdialog->support_unit_box = gtk_hbox_new (FALSE, 4);
+  gtk_container_add (GTK_CONTAINER (viewport), pdialog->support_unit_box);
+
+  adjustment = gtk_viewport_get_hadjustment (GTK_VIEWPORT (viewport));
+
+  support_units_scrollbar = gtk_hscrollbar_new (adjustment);
+  gtk_box_pack_start (GTK_BOX (box), support_units_scrollbar,
+          FALSE, FALSE, 0);
 
-    pdialog->support_unit_ids[i]=-1;
+  gtk_signal_connect (GTK_OBJECT (adjustment), "changed",
+          GTK_SIGNAL_FUNC (unit_scrollbar_callback), support_units_scrollbar);
 
-    if(pcity->owner != game.player_idx)
-      gtk_widget_set_sensitive(pdialog->support_unit_boxes[i], FALSE);    
-  }
-
 
   /* "present units" frame */
   pdialog->present_unit_label=gtk_frame_new("Units present");
@@ -469,29 +481,27 @@
        FALSE, FALSE, 0);
   gtk_widget_realize(pdialog->present_unit_label);
 
-  box=gtk_hbox_new(TRUE, 1);
+  box = gtk_vbox_new (FALSE, 1);
   gtk_container_add(GTK_CONTAINER(pdialog->present_unit_label),box);
   gtk_widget_realize(box);
 
-  for(i=0; i<NUM_UNITS_SHOWN; i++) {
-    pdialog->present_unit_boxes[i]=gtk_event_box_new();
-    gtk_widget_set_events(pdialog->present_unit_boxes[i],
-       GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK);
-
-    gtk_box_pack_start(GTK_BOX(box), pdialog->present_unit_boxes[i],
-                      TRUE, FALSE, 0);
-    gtk_widget_show(pdialog->present_unit_boxes[i]);
-
-    pdialog->present_unit_pixmaps[i]=
-     gtk_new_pixmap(NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
-    gtk_container_add(GTK_CONTAINER(pdialog->present_unit_boxes[i]),
-       pdialog->present_unit_pixmaps[i]);
+  viewport = gtk_viewport_new (NULL, NULL);
+  gtk_widget_set_usize (viewport, NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
+  gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
+  gtk_box_pack_start (GTK_BOX (box), viewport, FALSE, FALSE, 0);
+
+  pdialog->present_unit_box = gtk_hbox_new (FALSE, 4);
+  gtk_container_add (GTK_CONTAINER (viewport), pdialog->present_unit_box);
+
+  adjustment = gtk_viewport_get_hadjustment (GTK_VIEWPORT (viewport));
+
+  present_units_scrollbar = gtk_hscrollbar_new (adjustment);
+  gtk_box_pack_start (GTK_BOX (box), present_units_scrollbar,
+          FALSE, FALSE, 0);
 
-    pdialog->present_unit_ids[i]=-1;
+  gtk_signal_connect (GTK_OBJECT (adjustment), "changed",
+          GTK_SIGNAL_FUNC (unit_scrollbar_callback), present_units_scrollbar);
 
-    if(pcity->owner != game.player_idx)
-      gtk_widget_set_sensitive(pdialog->present_unit_boxes[i], FALSE);    
-  }
 
   /* "action area" buttons */
   pdialog->close_command=gtk_accelbutton_new("C_lose", accel);
@@ -559,6 +569,9 @@
   for(i=0; i<NUM_CITIZENS_SHOWN; i++)
     pdialog->citizen_type[i]=-1;
 
+  for(i=0; i<NUM_UNITS_SHOWN; i++)
+    pdialog->support_unit_ids[i] = pdialog->present_unit_ids[i] = -1;
+
   refresh_city_dialog(pdialog->pcity);
 
   if(make_modal)
@@ -570,6 +583,9 @@
   gtk_widget_show_all(GTK_DIALOG(pdialog->shell)->vbox);
   gtk_widget_show_all(GTK_DIALOG(pdialog->shell)->action_area);
 
+  gtk_widget_hide (support_units_scrollbar);
+  gtk_widget_hide (present_units_scrollbar);
+
   gtk_signal_connect(GTK_OBJECT(pdialog->map_canvas), "expose_event",
        GTK_SIGNAL_FUNC(city_map_canvas_expose), pdialog);
   gtk_signal_connect(GTK_OBJECT(pdialog->map_canvas), "button_press_event",
@@ -1186,6 +1202,26 @@
     if(unitid && punit->id!=unitid)
       continue;
 
+    if (pdialog->support_unit_ids[i] >= 0) {
+      gtk_clear_pixmap (pdialog->support_unit_pixmaps[i]);
+      gtk_signal_handlers_destroy (GTK_OBJECT 
(pdialog->support_unit_boxes[i]));
+    }
+
+    else {
+      pdialog->support_unit_boxes[i] = gtk_event_box_new();
+      gtk_widget_set_events (pdialog->support_unit_boxes[i],
+              GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
+      gtk_box_pack_start (GTK_BOX (pdialog->support_unit_box),
+              pdialog->support_unit_boxes[i], FALSE, FALSE, 0);
+      gtk_widget_show (pdialog->support_unit_boxes[i]);
+
+      pdialog->support_unit_pixmaps[i] = gtk_new_pixmap (
+              NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT + NORMAL_TILE_HEIGHT / 2);
+      gtk_container_add (GTK_CONTAINER (pdialog->support_unit_boxes[i]),
+              pdialog->support_unit_pixmaps[i]);
+      gtk_widget_show (pdialog->support_unit_pixmaps[i]);
+    }
+
     if (flags_are_transparent)
       gtk_clear_pixmap(pdialog->support_unit_pixmaps[i]); /* STG */
 
@@ -1198,26 +1234,23 @@
 
     pdialog->support_unit_ids[i]=punit->id;
 
-    gtk_signal_handlers_destroy(GTK_OBJECT(pdialog->support_unit_boxes[i]));
     gtk_signal_connect(GTK_OBJECT(pdialog->support_unit_boxes[i]),
        "button_press_event",
        GTK_SIGNAL_FUNC(support_units_callback), (gpointer)punit->id);
     gtk_signal_connect(GTK_OBJECT(pdialog->support_unit_boxes[i]),
        "button_release_event",
        GTK_SIGNAL_FUNC(s_units_middle_callback), (gpointer)punit->id);
-    gtk_widget_set_sensitive(pdialog->support_unit_boxes[i], TRUE);
   }
     
   for(; i<NUM_UNITS_SHOWN; i++) {
-    gtk_clear_pixmap(pdialog->support_unit_pixmaps[i]);
-    pdialog->support_unit_ids[i]=0;
-    gtk_widget_set_sensitive(pdialog->support_unit_boxes[i], FALSE);
+    if (pdialog->support_unit_ids[i] < 0)
+      break;
+    gtk_widget_destroy (pdialog->support_unit_boxes[i]);
+    pdialog->support_unit_ids[i] = -1;
   }
 
-  for(i=0; i<NUM_UNITS_SHOWN; i++) {
-    gtk_widget_hide(pdialog->support_unit_boxes[i]);
-    gtk_widget_show(pdialog->support_unit_boxes[i]);
-  }
+  gtk_widget_hide (pdialog->support_unit_box);
+  gtk_widget_show (pdialog->support_unit_box);
 }
 
 /****************************************************************
@@ -1246,6 +1279,26 @@
     if(unitid && punit->id!=unitid)
       continue;
 
+    if (pdialog->present_unit_ids[i] >= 0) {
+      gtk_clear_pixmap (pdialog->present_unit_pixmaps[i]);
+      gtk_signal_handlers_destroy (GTK_OBJECT 
(pdialog->present_unit_boxes[i]));
+    }
+
+    else {
+      pdialog->present_unit_boxes[i] = gtk_event_box_new();
+      gtk_widget_set_events (pdialog->present_unit_boxes[i],
+              GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
+      gtk_box_pack_start (GTK_BOX (pdialog->present_unit_box),
+              pdialog->present_unit_boxes[i], FALSE, FALSE, 0);
+      gtk_widget_show (pdialog->present_unit_boxes[i]);
+
+      pdialog->present_unit_pixmaps[i] = gtk_new_pixmap (
+              NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
+      gtk_container_add (GTK_CONTAINER (pdialog->present_unit_boxes[i]),
+              pdialog->present_unit_pixmaps[i]);
+      gtk_widget_show (pdialog->present_unit_pixmaps[i]);
+    }
+
     if (flags_are_transparent)
       gtk_clear_pixmap(pdialog->present_unit_pixmaps[i]); /* STG */
 
@@ -1258,25 +1311,23 @@
 
     pdialog->present_unit_ids[i]=punit->id;
 
-    gtk_signal_handlers_destroy(GTK_OBJECT(pdialog->present_unit_boxes[i]));
     gtk_signal_connect(GTK_OBJECT(pdialog->present_unit_boxes[i]),
        "button_press_event",
        GTK_SIGNAL_FUNC(present_units_callback), (gpointer)punit->id);
     gtk_signal_connect(GTK_OBJECT(pdialog->present_unit_boxes[i]),
        "button_release_event",
        GTK_SIGNAL_FUNC(p_units_middle_callback), (gpointer)punit->id);
-    gtk_widget_set_sensitive(pdialog->present_unit_boxes[i], TRUE);
   }
+
   for(; i<NUM_UNITS_SHOWN; i++) {
-    gtk_clear_pixmap(pdialog->present_unit_pixmaps[i]);
-    pdialog->present_unit_ids[i]=0;
-    gtk_widget_set_sensitive(pdialog->present_unit_boxes[i], FALSE);
+    if (pdialog->present_unit_ids[i] < 0)
+      break;
+    gtk_widget_destroy (pdialog->present_unit_boxes[i]);
+    pdialog->present_unit_ids[i] = -1;
   }
 
-  for(i=0; i<NUM_UNITS_SHOWN; i++) {
-    gtk_widget_hide(pdialog->present_unit_boxes[i]);
-    gtk_widget_show(pdialog->present_unit_boxes[i]);
-  }
+  gtk_widget_hide (pdialog->present_unit_box);
+  gtk_widget_show (pdialog->present_unit_box);
 }
 
 /****************************************************************



--------------154C2CDA2BFDFDA2E4432C48--



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