From 26212f0e5549e19c1932223a945ffbb2a5cd48a9 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 15 May 2022 05:41:33 +0300 Subject: [PATCH 42/42] gtk4: Implement overview events See osdn #44570 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/gui_main.c | 19 ++++++++++---- client/gui-gtk-4.0/mapctrl.c | 48 ++++++++++++++++++++++------------- client/gui-gtk-4.0/mapctrl.h | 8 ++++-- 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 610a1f8db0..34620d1c35 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -1239,11 +1239,20 @@ static void setup_widgets(void) gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(overview_canvas), overview_canvas_draw, NULL, NULL); - g_signal_connect(overview_canvas, "motion_notify_event", - G_CALLBACK(move_overviewcanvas), NULL); - - g_signal_connect(overview_canvas, "button_press_event", - G_CALLBACK(butt_down_overviewcanvas), NULL); + mc_controller = GTK_EVENT_CONTROLLER(gtk_gesture_click_new()); + g_signal_connect(mc_controller, "pressed", + G_CALLBACK(left_butt_down_overviewcanvas), NULL); + gtk_widget_add_controller(overview_canvas, mc_controller); + mc_gesture = gtk_gesture_click_new(); + gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(mc_gesture), 3); + mc_controller = GTK_EVENT_CONTROLLER(mc_gesture); + g_signal_connect(mc_controller, "pressed", + G_CALLBACK(right_butt_down_overviewcanvas), NULL); + gtk_widget_add_controller(overview_canvas, mc_controller); + mc_controller = gtk_event_controller_motion_new(); + g_signal_connect(mc_controller, "motion", + G_CALLBACK(move_overviewcanvas), NULL); + gtk_widget_add_controller(overview_canvas, mc_controller); /* The rest */ diff --git a/client/gui-gtk-4.0/mapctrl.c b/client/gui-gtk-4.0/mapctrl.c index 27fd9b994c..312dbf677f 100644 --- a/client/gui-gtk-4.0/mapctrl.c +++ b/client/gui-gtk-4.0/mapctrl.c @@ -449,39 +449,32 @@ gboolean leave_mapcanvas(GtkEventControllerMotion *controller, /**********************************************************************//** Overview canvas moved **************************************************************************/ -gboolean move_overviewcanvas(GtkWidget *w, GdkEvent *ev, gpointer data) +gboolean move_overviewcanvas(GtkEventControllerMotion *controller, + gdouble x, gdouble y, gpointer data) { - gdouble e_x, e_y; - - gdk_event_get_position(ev, &e_x, &e_y); - overview_update_line(e_x, e_y); + overview_update_line(x, y); return TRUE; } /**********************************************************************//** - Button pressed at overview + Left button pressed at overview **************************************************************************/ -gboolean butt_down_overviewcanvas(GtkWidget *w, GdkEvent *ev, gpointer data) +gboolean left_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press, + double x, double y) { int xtile, ytile; - gdouble e_x, e_y; - guint button; - if (gdk_event_get_event_type(ev) != GDK_BUTTON_PRESS) { + if (n_press != 1) { return TRUE; /* Double-clicks? Triple-clicks? No thanks! */ } - gdk_event_get_position(ev, &e_x, &e_y); - overview_to_map_pos(&xtile, &ytile, e_x, e_y); + overview_to_map_pos(&xtile, &ytile, x, y); - button = gdk_button_event_get_button(ev); - if (can_client_change_view() && (button == 3)) { - center_tile_mapcanvas(map_pos_to_tile(&(wld.map), xtile, ytile)); - } else if (can_client_issue_orders() && (button == 1)) { + if (can_client_issue_orders()) { GdkModifierType state; - state = gdk_event_get_modifier_state(ev); + state = gtk_event_controller_get_current_event_state(GTK_EVENT_CONTROLLER(gesture)); do_map_click(map_pos_to_tile(&(wld.map), xtile, ytile), (state & GDK_SHIFT_MASK) ? SELECT_APPEND : SELECT_POPUP); } @@ -489,6 +482,27 @@ gboolean butt_down_overviewcanvas(GtkWidget *w, GdkEvent *ev, gpointer data) return TRUE; } +/**********************************************************************//** + Right button pressed at overview +**************************************************************************/ +gboolean right_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press, + double x, double y) +{ + int xtile, ytile; + + if (n_press != 1) { + return TRUE; /* Double-clicks? Triple-clicks? No thanks! */ + } + + overview_to_map_pos(&xtile, &ytile, x, y); + + if (can_client_change_view()) { + center_tile_mapcanvas(map_pos_to_tile(&(wld.map), xtile, ytile)); + } + + return TRUE; +} + /**********************************************************************//** Best effort to center the map on the currently selected unit(s) **************************************************************************/ diff --git a/client/gui-gtk-4.0/mapctrl.h b/client/gui-gtk-4.0/mapctrl.h index 208dd1e368..f998085697 100644 --- a/client/gui-gtk-4.0/mapctrl.h +++ b/client/gui-gtk-4.0/mapctrl.h @@ -31,12 +31,16 @@ gboolean right_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press, double x, double y); gboolean middle_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press, double x, double y); -gboolean butt_down_overviewcanvas(GtkWidget *w, GdkEvent *ev, gpointer data); +gboolean left_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press, + double x, double y); +gboolean right_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press, + double x, double y); gboolean move_mapcanvas(GtkEventControllerMotion *controller, gdouble x, gdouble y, gpointer data); gboolean leave_mapcanvas(GtkEventControllerMotion *controller, gpointer data); -gboolean move_overviewcanvas(GtkWidget *w, GdkEvent *ev, gpointer data); +gboolean move_overviewcanvas(GtkEventControllerMotion *controller, + gdouble x, gdouble y, gpointer data); void center_on_unit(void); -- 2.35.1