[gnome-robots/arnaudb/wip/gtk4: 3/33] Use GtkGestureMultiPress.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-robots/arnaudb/wip/gtk4: 3/33] Use GtkGestureMultiPress.
- Date: Mon, 25 May 2020 20:26:20 +0000 (UTC)
commit e42921b12791c8bebf57d0cbea3079f2255f9833
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat May 23 21:40:30 2020 +0200
Use GtkGestureMultiPress.
src/game.c | 14 +++++++++-----
src/game.h | 6 +++++-
src/gnome-robots.c | 5 ++++-
3 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/src/game.c b/src/game.c
index b340ce8..61a3254 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1321,21 +1321,25 @@ get_dir (int ix, int iy, int *odx, int *ody)
*ody = movetable[octant][1];
}
-gboolean
-mouse_cb (GtkWidget * widget, GdkEventButton * e, gpointer data)
+void
+mouse_cb (GtkGestureMultiPress *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
{
int dx, dy;
if (game_state != STATE_PLAYING)
- return TRUE;
+ return;
- get_dir (e->x, e->y, &dx, &dy);
+ get_dir ((int)x, (int)y, &dx, &dy);
if (player_move (dx, dy)) {
move_robots ();
}
- return TRUE;
+ return;
}
gboolean
diff --git a/src/game.h b/src/game.h
index c36c904..8f88184 100644
--- a/src/game.h
+++ b/src/game.h
@@ -28,7 +28,11 @@ void quit_game (void);
void game_keypress (gint);
void show_scores (void);
void start_new_game (void);
-gboolean mouse_cb (GtkWidget * widget, GdkEventButton * e, gpointer data);
+void mouse_cb (GtkGestureMultiPress *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data);
gboolean move_cb (GtkWidget * widget, GdkEventMotion * e, gpointer data);
/**********************************************************************/
diff --git a/src/gnome-robots.c b/src/gnome-robots.c
index 798cd6d..90e24d4 100644
--- a/src/gnome-robots.c
+++ b/src/gnome-robots.c
@@ -352,6 +352,7 @@ activate (GtkApplication *app, gpointer user_data)
GtkSizeGroup *size_group;
GtkStyleContext *style_context;
GamesScoresDirectoryImporter *importer;
+ GtkGesture *click_controller;
if (window != NULL)
{
@@ -385,12 +386,14 @@ activate (GtkApplication *app, gpointer user_data)
game_area = gtk_drawing_area_new ();
gtk_widget_add_events (game_area, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK);
- g_signal_connect (G_OBJECT (game_area), "button-press-event", G_CALLBACK (mouse_cb), NULL);
g_signal_connect (G_OBJECT (game_area), "motion-notify-event", G_CALLBACK (move_cb), NULL);
g_signal_connect (G_OBJECT (game_area), "configure-event", G_CALLBACK (resize_cb), NULL);
g_signal_connect (G_OBJECT (game_area), "draw", G_CALLBACK (draw_cb), NULL);
g_signal_connect (G_OBJECT (game_area), "destroy", G_CALLBACK (gtk_widget_destroyed),
&game_area);
+ click_controller = gtk_gesture_multi_press_new (game_area);
+ g_signal_connect (G_OBJECT (click_controller), "pressed", G_CALLBACK (mouse_cb), NULL);
+
gridframe = GTK_WIDGET (games_grid_frame_new (GAME_WIDTH, GAME_HEIGHT));
gtk_container_add (GTK_CONTAINER (gridframe), game_area);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]