From 3d411fbeabc4dabfdb7837f5d3d217379ffa79fc Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 22 Jun 2022 17:25:34 +0300 Subject: [PATCH 54/54] 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-3.22/gui_main.c | 29 ++++++++++++++++------------- client/gui-gtk-4.0/gui_main.c | 25 ++++++++++++++----------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index 5fbe596595..4845bb781c 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -923,7 +923,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. @@ -934,10 +934,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 @@ -945,7 +949,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); } @@ -956,8 +960,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); @@ -974,9 +977,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], @@ -989,7 +992,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); @@ -1018,11 +1021,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-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 469d627bf3..f8ae4b373a 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -886,7 +886,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. @@ -897,10 +897,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 @@ -908,7 +912,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); } @@ -917,7 +921,7 @@ static void populate_unit_image_table(void) * in reset_unit_table. */ unit_image = gtk_image_new(); g_object_ref(unit_image); - gtk_widget_set_size_request(unit_image, tileset_tile_width(tileset), -1); + gtk_widget_set_size_request(unit_image, ttw, -1); gtk_grid_attach(GTK_GRID(table), unit_image, 0, 0, 1, 1); g_signal_connect(unit_image, "button_press_event", G_CALLBACK(select_unit_image_callback), @@ -928,8 +932,7 @@ static void populate_unit_image_table(void) for (i = 0; i < num_units_below; i++) { unit_below_image[i] = gtk_image_new(); g_object_ref(unit_below_image[i]); - gtk_widget_set_size_request(unit_below_image[i], - tileset_tile_width(tileset), -1); + gtk_widget_set_size_request(unit_below_image[i], ttw, -1); g_signal_connect(unit_below_image[i], "button_press_event", G_CALLBACK(select_unit_image_callback), @@ -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); @@ -962,11 +965,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(table); -- 2.35.1