From 747734ae26322616353791d87aca27c94f0ff18f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 27 Aug 2023 10:45:39 +0300 Subject: [PATCH 3/3] 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.0/dialogs.c | 3 ++- client/gui-gtk-3.0/dialogs.h | 7 ++++--- 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 ++++++ 9 files changed, 60 insertions(+), 20 deletions(-) diff --git a/client/climisc.c b/client/climisc.c index 92eb2cf510..b4af1574c3 100644 --- a/client/climisc.c +++ b/client/climisc.c @@ -1173,7 +1173,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; @@ -1189,17 +1189,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.0/dialogs.c b/client/gui-gtk-3.0/dialogs.c index 6e22890f8f..7fef1675c2 100644 --- a/client/gui-gtk-3.0/dialogs.c +++ b/client/gui-gtk-3.0/dialogs.c @@ -1433,7 +1433,8 @@ static void races_response(GtkWidget *w, gint response, 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.0/dialogs.h b/client/gui-gtk-3.0/dialogs.h index c6c4e74f4c..fbaa7c1ae2 100644 --- a/client/gui-gtk-3.0/dialogs.h +++ b/client/gui-gtk-3.0/dialogs.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,12 +15,13 @@ #include +/* client */ #include "dialogs_g.h" void popup_revolution_dialog(struct government *government); void message_dialog_button_set_sensitive(GtkWidget *shl, int button, - gboolean state); + gboolean state); 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-3.22/dialogs.c b/client/gui-gtk-3.22/dialogs.c index 947be7f7b8..92d4c3d249 100644 --- a/client/gui-gtk-3.22/dialogs.c +++ b/client/gui-gtk-3.22/dialogs.c @@ -1419,9 +1419,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 115c3199f1..e218bcc0c9 100644 --- a/client/gui-gtk-4.0/dialogs.c +++ b/client/gui-gtk-4.0/dialogs.c @@ -1443,7 +1443,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 ef04293d12..99b73957d0 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -1221,6 +1221,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