From ec07d8e980ccaa99192b71a4599b4dec038d0499 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 22 Jun 2022 17:25:34 +0300 Subject: [PATCH 36/36] 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.0/gui_main.c | 29 ++++++++++++++++------------- client/gui-gtk-3.22/gui_main.c | 29 ++++++++++++++++------------- client/gui-gtk-4.0/gui_main.c | 25 ++++++++++++++----------- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index cab1f44ef8..5827322d92 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -856,7 +856,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. @@ -867,10 +867,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 @@ -878,7 +882,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); } @@ -889,8 +893,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); @@ -907,9 +910,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], @@ -922,7 +925,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); @@ -948,11 +951,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 1f4f88d137..9cf8ee8cbd 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -870,7 +870,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. @@ -881,10 +881,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 @@ -892,7 +896,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); } @@ -903,8 +907,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); @@ -921,9 +924,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], @@ -936,7 +939,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); @@ -965,11 +968,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 0be2a35fd2..83c3400cdc 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -834,7 +834,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. @@ -845,10 +845,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 @@ -856,7 +860,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); } @@ -865,7 +869,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), @@ -876,8 +880,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), @@ -888,7 +891,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); @@ -910,11 +913,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