From 54f141642f614c9947ce4c95d3ea2f308d6fb7a4 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 27 Aug 2023 10:45:39 +0300 Subject: [PATCH 5/5] gtk4: Add reverse taxrates adjustment Make it possible to adjust taxrates to reverse direction by right click. See osdn #48547 Signed-off-by: Marko Lindqvist --- client/climisc.c | 35 +++++++++++++++++++++++++---------- client/climisc.h | 2 +- client/gui-gtk-3.22/dialogs.c | 5 +++-- client/gui-gtk-3.22/dialogs.h | 2 +- client/gui-gtk-4.0/dialogs.c | 16 +++++++++++++++- client/gui-gtk-4.0/dialogs.h | 4 +++- client/gui-gtk-4.0/gui_main.c | 6 ++++++ 7 files changed, 54 insertions(+), 16 deletions(-) diff --git a/client/climisc.c b/client/climisc.c index 5a4adb4a4a..0c644d8554 100644 --- a/client/climisc.c +++ b/client/climisc.c @@ -1179,7 +1179,7 @@ void cityrep_buy(struct city *pcity) /**********************************************************************//** Switch between tax/sci/lux at given slot. **************************************************************************/ -void common_taxrates_callback(int i) +void common_taxrates_callback(int idx, bool reverse) { int lux_end, sci_end, tax, lux, sci; int delta = 10; @@ -1195,17 +1195,32 @@ void common_taxrates_callback(int i) sci = client.conn.playing->economic.science; tax = client.conn.playing->economic.tax; - i *= 10; - if (i < lux_end) { - lux -= delta; - sci += delta; - } else if (i < sci_end) { - sci -= delta; - tax += delta; + idx *= 10; + + if (reverse) { + if (idx < lux_end) { + lux -= delta; + tax += delta; + } else if (idx < sci_end) { + sci -= delta; + lux += delta; + } else { + tax -= delta; + sci += delta; + } } else { - tax -= delta; - lux += delta; + if (idx < lux_end) { + lux -= delta; + sci += delta; + } else if (idx < sci_end) { + sci -= delta; + tax += delta; + } else { + tax -= delta; + lux += delta; + } } + dsend_packet_player_rates(&client.conn, tax, lux, sci); } diff --git a/client/climisc.h b/client/climisc.h index 11f60c8df9..d10ea0f453 100644 --- a/client/climisc.h +++ b/client/climisc.h @@ -114,7 +114,7 @@ void create_event(struct tile *ptile, enum event_type event, struct city *get_nearest_city(const struct unit *punit, int *sq_dist); void cityrep_buy(struct city *pcity); -void common_taxrates_callback(int i); +void common_taxrates_callback(int idx, bool reverse); bool can_units_do_connect(struct unit_list *punits, enum unit_activity activity, diff --git a/client/gui-gtk-3.22/dialogs.c b/client/gui-gtk-3.22/dialogs.c index 79a7575718..1c3ddde177 100644 --- a/client/gui-gtk-3.22/dialogs.c +++ b/client/gui-gtk-3.22/dialogs.c @@ -1422,9 +1422,10 @@ static void races_response(GtkWidget *w, gint response, gpointer data) /**********************************************************************//** Adjust tax rates from main window **************************************************************************/ -gboolean taxrates_callback(GtkWidget * w, GdkEventButton * ev, gpointer data) +gboolean taxrates_callback(GtkWidget *w, GdkEventButton *ev, gpointer data) { - common_taxrates_callback((size_t) data); + common_taxrates_callback((size_t) data, FALSE); + return TRUE; } diff --git a/client/gui-gtk-3.22/dialogs.h b/client/gui-gtk-3.22/dialogs.h index 8b56510e46..7ad5e2cec6 100644 --- a/client/gui-gtk-3.22/dialogs.h +++ b/client/gui-gtk-3.22/dialogs.h @@ -24,4 +24,4 @@ void message_dialog_button_set_sensitive(GtkWidget *shl, int button, gboolean taxrates_callback(GtkWidget *w, GdkEventButton *ev, gpointer data); void nationset_sync_to_server(const char *nationset); -#endif /* FC__DIALOGS_H */ +#endif /* FC__DIALOGS_H */ diff --git a/client/gui-gtk-4.0/dialogs.c b/client/gui-gtk-4.0/dialogs.c index fa690df687..b78df57ba0 100644 --- a/client/gui-gtk-4.0/dialogs.c +++ b/client/gui-gtk-4.0/dialogs.c @@ -1448,7 +1448,21 @@ gboolean taxrates_callback(GtkGestureClick *gesture, int n_press, GtkWidget *widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)); common_taxrates_callback(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(widget), - "rate_button"))); + "rate_button")), FALSE); + + return TRUE; +} + +/**********************************************************************//** + Adjust tax rates from main window +**************************************************************************/ +gboolean reverse_taxrates_callback(GtkGestureClick *gesture, int n_press, + double x, double y) +{ + GtkWidget *widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)); + + common_taxrates_callback(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(widget), + "rate_button")), TRUE); return TRUE; } diff --git a/client/gui-gtk-4.0/dialogs.h b/client/gui-gtk-4.0/dialogs.h index a96dfda688..0299738b61 100644 --- a/client/gui-gtk-4.0/dialogs.h +++ b/client/gui-gtk-4.0/dialogs.h @@ -23,6 +23,8 @@ void message_dialog_button_set_sensitive(GtkWidget *shl, int button, gboolean state); gboolean taxrates_callback(GtkGestureClick *gesture, int n_press, double x, double y); +gboolean reverse_taxrates_callback(GtkGestureClick *gesture, int n_press, + double x, double y); void nationset_sync_to_server(const char *nationset); -#endif /* FC__DIALOGS_H */ +#endif /* FC__DIALOGS_H */ diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 1bb1628194..1192509280 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -1277,6 +1277,12 @@ static void setup_widgets(void) g_signal_connect(controller, "pressed", G_CALLBACK(taxrates_callback), NULL); gtk_widget_add_controller(econ_label[i], controller); + mc_gesture = gtk_gesture_click_new(); + gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(mc_gesture), 3); + controller = GTK_EVENT_CONTROLLER(mc_gesture); + g_signal_connect(controller, "pressed", + G_CALLBACK(reverse_taxrates_callback), NULL); + gtk_widget_add_controller(econ_label[i], controller); gtk_grid_attach(GTK_GRID(table2), econ_label[i], i, 0, 1, 1); } -- 2.40.1