From 7a918112c7a260bb9cab4847e3714d487f385211 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 22 Jun 2022 17:38:49 +0300 Subject: [PATCH 22/22] gtk: Set more-units-arrow to correct column of the grid Set arrow to actual last column (depending on screen size), and not to MAX_NUM_UNITS_BELOW column. Other populate_unit_image_table() cleanup made in the process. See osdn #44905 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/gui_main.c | 26 ++++++++++++++------------ client/gui-gtk-3.0/gui_main.c | 29 ++++++++++++++++------------- client/gui-gtk-3.22/gui_main.c | 29 ++++++++++++++++------------- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/client/gui-gtk-2.0/gui_main.c b/client/gui-gtk-2.0/gui_main.c index 8e2b619dc1..a7d1dfa65a 100644 --- a/client/gui-gtk-2.0/gui_main.c +++ b/client/gui-gtk-2.0/gui_main.c @@ -799,7 +799,7 @@ static GtkWidget *detached_widget_fill(GtkWidget *tearbox) } /************************************************************************** - Called to build the unit_below pixmap table. This is the table on the + Called to build the unit_below pixmap table. This is the table on the left of the screen that shows all of the inactive units in the current tile. @@ -810,9 +810,10 @@ static void populate_unit_pixmap_table(void) int i, width; GtkWidget *table = unit_pixmap_table; - /* get width of the overview window */ - width = (overview_canvas_store_width > GUI_GTK_OVERVIEW_MIN_XSIZE) ? overview_canvas_store_width - : GUI_GTK_OVERVIEW_MIN_XSIZE; + /* Get width of the overview window */ + width = (overview_canvas_store_width > GUI_GTK_OVERVIEW_MIN_XSIZE) + ? overview_canvas_store_width + : GUI_GTK_OVERVIEW_MIN_XSIZE; if (gui_options.gui_gtk2_small_display_layout) { /* We want arrow to appear if there is other units in addition @@ -824,12 +825,13 @@ static void populate_unit_pixmap_table(void) num_units_below = CLIP(1, num_units_below, MAX_NUM_UNITS_BELOW); } - gtk_table_resize(GTK_TABLE(table), 2, MAX(1,num_units_below)); + gtk_table_resize(GTK_TABLE(table), 2, MAX(1, num_units_below)); /* Top row: the active unit. */ /* Note, we ref this and other widgets here so that we can unref them * in reset_unit_table. */ - unit_pixmap = gtk_pixcomm_new(tileset_unit_width(tileset), tileset_unit_height(tileset)); + unit_pixmap = gtk_pixcomm_new(tileset_unit_width(tileset), + tileset_unit_height(tileset)); g_object_ref(unit_pixmap); gtk_pixcomm_clear(GTK_PIXCOMM(unit_pixmap)); unit_pixmap_button = gtk_event_box_new(); @@ -837,8 +839,8 @@ static void populate_unit_pixmap_table(void) gtk_container_add(GTK_CONTAINER(unit_pixmap_button), unit_pixmap); gtk_table_attach_defaults(GTK_TABLE(table), unit_pixmap_button, 0, 1, 0, 1); g_signal_connect(unit_pixmap_button, "button_press_event", - G_CALLBACK(select_unit_pixmap_callback), - GINT_TO_POINTER(-1)); + G_CALLBACK(select_unit_pixmap_callback), + GINT_TO_POINTER(-1)); if (!gui_options.gui_gtk2_small_display_layout) { /* Bottom row: other units in the same tile. */ @@ -861,7 +863,7 @@ static void populate_unit_pixmap_table(void) } } - /* create arrow (popup for all units on the selected tile) */ + /* Create arrow (popup for all units on the selected tile) */ { GdkPixbuf *more_arrow = sprite_get_pixbuf(get_arrow_sprite(tileset, ARROW_RIGHT)); @@ -890,11 +892,11 @@ static void populate_unit_pixmap_table(void) if (!gui_options.gui_gtk2_small_display_layout) { /* Display on bottom row. */ gtk_table_attach_defaults(GTK_TABLE(table), more_arrow_pixmap_container, - MAX_NUM_UNITS_BELOW, MAX_NUM_UNITS_BELOW+1, 1, 2); + num_units_below, num_units_below + 1, 1, 2); } else { /* Display on top row (there is no bottom row). */ gtk_table_attach_defaults(GTK_TABLE(table), more_arrow_pixmap_container, - MAX_NUM_UNITS_BELOW, MAX_NUM_UNITS_BELOW+1, 0, 1); + 1, 1 + 1, 0, 1); } gtk_widget_show_all(table); @@ -1822,7 +1824,7 @@ void real_focus_units_changed(void) these are the units on the same tile as the focus unit. **************************************************************************/ static gboolean select_unit_pixmap_callback(GtkWidget *w, GdkEvent *ev, - gpointer data) + gpointer data) { int i = GPOINTER_TO_INT(data); struct unit *punit; diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index 984df41b8a..c4beff6fd4 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -859,7 +859,7 @@ static GtkWidget *detached_widget_fill(GtkWidget *tearbox) } /************************************************************************** - Called to build the unit_below pixmap table. This is the table on the + Called to build the unit_below pixmap table. This is the table on the left of the screen that shows all of the inactive units in the current tile. @@ -870,10 +870,14 @@ static void populate_unit_image_table(void) int i, width; GtkWidget *table = unit_image_table; GdkPixbuf *pix; + int ttw; - /* get width of the overview window */ - width = (overview_canvas_store_width > GUI_GTK_OVERVIEW_MIN_XSIZE) ? overview_canvas_store_width - : GUI_GTK_OVERVIEW_MIN_XSIZE; + /* Get width of the overview window */ + width = (overview_canvas_store_width > GUI_GTK_OVERVIEW_MIN_XSIZE) + ? overview_canvas_store_width + : GUI_GTK_OVERVIEW_MIN_XSIZE; + + ttw = tileset_tile_width(tileset); if (GUI_GTK_OPTION(small_display_layout)) { /* We want arrow to appear if there is other units in addition @@ -881,7 +885,7 @@ static void populate_unit_image_table(void) can be 0 other units to not to display arrow. */ num_units_below = 1 - 1; } else { - num_units_below = width / (int) tileset_tile_width(tileset); + num_units_below = width / ttw; num_units_below = CLIP(1, num_units_below, MAX_NUM_UNITS_BELOW); } @@ -892,8 +896,7 @@ static void populate_unit_image_table(void) gtk_widget_add_events(unit_image, GDK_BUTTON_PRESS_MASK); g_object_ref(unit_image); unit_image_button = gtk_event_box_new(); - gtk_widget_set_size_request(unit_image_button, - tileset_tile_width(tileset), -1); + gtk_widget_set_size_request(unit_image_button, ttw, -1); gtk_event_box_set_visible_window(GTK_EVENT_BOX(unit_image_button), FALSE); g_object_ref(unit_image_button); gtk_container_add(GTK_CONTAINER(unit_image_button), unit_image); @@ -910,9 +913,9 @@ static void populate_unit_image_table(void) gtk_widget_add_events(unit_below_image[i], GDK_BUTTON_PRESS_MASK); unit_below_image_button[i] = gtk_event_box_new(); g_object_ref(unit_below_image_button[i]); - gtk_widget_set_size_request(unit_below_image_button[i], - tileset_tile_width(tileset), -1); - gtk_event_box_set_visible_window(GTK_EVENT_BOX(unit_below_image_button[i]), FALSE); + gtk_widget_set_size_request(unit_below_image_button[i], ttw, -1); + gtk_event_box_set_visible_window(GTK_EVENT_BOX(unit_below_image_button[i]), + FALSE); gtk_container_add(GTK_CONTAINER(unit_below_image_button[i]), unit_below_image[i]); g_signal_connect(unit_below_image_button[i], @@ -925,7 +928,7 @@ static void populate_unit_image_table(void) } } - /* create arrow (popup for all units on the selected tile) */ + /* Create arrow (popup for all units on the selected tile) */ pix = sprite_get_pixbuf(get_arrow_sprite(tileset, ARROW_RIGHT)); more_arrow_pixmap = gtk_image_new_from_pixbuf(pix); g_object_ref(more_arrow_pixmap); @@ -951,11 +954,11 @@ static void populate_unit_image_table(void) if (!GUI_GTK_OPTION(small_display_layout)) { /* Display on bottom row. */ gtk_grid_attach(GTK_GRID(table), more_arrow_pixmap_container, - MAX_NUM_UNITS_BELOW, 1, 1, 1); + num_units_below, 1, 1, 1); } else { /* Display on top row (there is no bottom row). */ gtk_grid_attach(GTK_GRID(table), more_arrow_pixmap_container, - MAX_NUM_UNITS_BELOW, 0, 1, 1); + 1, 0, 1, 1); } gtk_widget_show_all(table); diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index 031726b809..4a48f3952a 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -874,7 +874,7 @@ static GtkWidget *detached_widget_fill(GtkWidget *tearbox) } /************************************************************************** - Called to build the unit_below pixmap table. This is the table on the + Called to build the unit_below pixmap table. This is the table on the left of the screen that shows all of the inactive units in the current tile. @@ -885,10 +885,14 @@ static void populate_unit_image_table(void) int i, width; GtkWidget *table = unit_image_table; GdkPixbuf *pix; + int ttw; - /* get width of the overview window */ - width = (overview_canvas_store_width > GUI_GTK_OVERVIEW_MIN_XSIZE) ? overview_canvas_store_width - : GUI_GTK_OVERVIEW_MIN_XSIZE; + /* Get width of the overview window */ + width = (overview_canvas_store_width > GUI_GTK_OVERVIEW_MIN_XSIZE) + ? overview_canvas_store_width + : GUI_GTK_OVERVIEW_MIN_XSIZE; + + ttw = tileset_tile_width(tileset); if (GUI_GTK_OPTION(small_display_layout)) { /* We want arrow to appear if there is other units in addition @@ -896,7 +900,7 @@ static void populate_unit_image_table(void) can be 0 other units to not to display arrow. */ num_units_below = 1 - 1; } else { - num_units_below = width / (int) tileset_tile_width(tileset); + num_units_below = width / ttw; num_units_below = CLIP(1, num_units_below, MAX_NUM_UNITS_BELOW); } @@ -907,8 +911,7 @@ static void populate_unit_image_table(void) gtk_widget_add_events(unit_image, GDK_BUTTON_PRESS_MASK); g_object_ref(unit_image); unit_image_button = gtk_event_box_new(); - gtk_widget_set_size_request(unit_image_button, - tileset_tile_width(tileset), -1); + gtk_widget_set_size_request(unit_image_button, ttw, -1); gtk_event_box_set_visible_window(GTK_EVENT_BOX(unit_image_button), FALSE); g_object_ref(unit_image_button); gtk_container_add(GTK_CONTAINER(unit_image_button), unit_image); @@ -925,9 +928,9 @@ static void populate_unit_image_table(void) gtk_widget_add_events(unit_below_image[i], GDK_BUTTON_PRESS_MASK); unit_below_image_button[i] = gtk_event_box_new(); g_object_ref(unit_below_image_button[i]); - gtk_widget_set_size_request(unit_below_image_button[i], - tileset_tile_width(tileset), -1); - gtk_event_box_set_visible_window(GTK_EVENT_BOX(unit_below_image_button[i]), FALSE); + gtk_widget_set_size_request(unit_below_image_button[i], ttw, -1); + gtk_event_box_set_visible_window(GTK_EVENT_BOX(unit_below_image_button[i]), + FALSE); gtk_container_add(GTK_CONTAINER(unit_below_image_button[i]), unit_below_image[i]); g_signal_connect(unit_below_image_button[i], @@ -940,7 +943,7 @@ static void populate_unit_image_table(void) } } - /* create arrow (popup for all units on the selected tile) */ + /* Create arrow (popup for all units on the selected tile) */ pix = sprite_get_pixbuf(get_arrow_sprite(tileset, ARROW_RIGHT)); more_arrow_pixmap = gtk_image_new_from_pixbuf(pix); g_object_ref(more_arrow_pixmap); @@ -969,11 +972,11 @@ static void populate_unit_image_table(void) if (!GUI_GTK_OPTION(small_display_layout)) { /* Display on bottom row. */ gtk_grid_attach(GTK_GRID(table), more_arrow_pixmap_container, - MAX_NUM_UNITS_BELOW, 1, 1, 1); + num_units_below, 1, 1, 1); } else { /* Display on top row (there is no bottom row). */ gtk_grid_attach(GTK_GRID(table), more_arrow_pixmap_container, - MAX_NUM_UNITS_BELOW, 0, 1, 1); + 1, 0, 1, 1); } gtk_widget_show_all(table); -- 2.35.1