[gnome-robots/arnaudb/wip/gtk4: 26/36] Adapt to DrawingArea API.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-robots/arnaudb/wip/gtk4: 26/36] Adapt to DrawingArea API.
- Date: Tue, 15 Sep 2020 14:29:39 +0000 (UTC)
commit 5da9d319278582e5ec623aaec821be664b62c091
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon May 25 20:45:46 2020 +0200
Adapt to DrawingArea API.
src/gnome-robots.c | 4 +---
src/graphics.c | 22 ++++++++++++----------
src/graphics.h | 7 +++++--
3 files changed, 18 insertions(+), 15 deletions(-)
---
diff --git a/src/gnome-robots.c b/src/gnome-robots.c
index c7c458e..65686e9 100644
--- a/src/gnome-robots.c
+++ b/src/gnome-robots.c
@@ -390,9 +390,7 @@ activate (GtkApplication *app, gpointer user_data)
make_cursors ();
game_area = gtk_drawing_area_new ();
- 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);
+ gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (game_area), draw_cb, NULL, NULL);
click_controller = gtk_gesture_click_new ();
g_signal_connect (G_OBJECT (click_controller), "pressed", G_CALLBACK (mouse_cb), NULL);
diff --git a/src/graphics.c b/src/graphics.c
index fcbd2ab..fa1a23f 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -95,29 +95,33 @@ render_graphics (void)
rerender_needed = FALSE;
}
-gboolean
-resize_cb (GtkWidget * w, GdkEventConfigure * e, gpointer data)
+void
+resize_if_needed (int width, int height)
{
gint trial_width;
gint trial_height;
- trial_width = e->width / GAME_WIDTH;
- trial_height = e->height / GAME_HEIGHT;
+ trial_width = width / GAME_WIDTH;
+ trial_height = height / GAME_HEIGHT;
if ((trial_width != tile_width) || (trial_height != tile_height)) {
tile_width = trial_width;
tile_height = trial_height;
rerender_needed = TRUE;
}
-
- return FALSE;
}
-gboolean
-draw_cb (GtkWidget * w, cairo_t * cr, gpointer data)
+void
+draw_cb (GtkDrawingArea *drawing_area,
+ cairo_t *cr,
+ int width,
+ int height,
+ gpointer user_data)
{
int i, j;
+ resize_if_needed (width, height);
+
for (j = 0; j < GAME_HEIGHT; j++) {
for (i = 0; i < GAME_WIDTH; i++) {
draw_object (i, j, arena[i][j], cr);
@@ -125,8 +129,6 @@ draw_cb (GtkWidget * w, cairo_t * cr, gpointer data)
}
draw_bubble (cr);
-
- return TRUE;
}
/**
diff --git a/src/graphics.h b/src/graphics.h
index 5ed44e2..ba327dd 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -10,8 +10,11 @@ extern gint tile_height;
/**********************************************************************/
/* Exported functions */
/**********************************************************************/
-gboolean resize_cb (GtkWidget * w, GdkEventConfigure * e, gpointer data);
-gboolean draw_cb (GtkWidget * w, cairo_t * cr, gpointer data);
+void draw_cb (GtkDrawingArea *drawing_area,
+ cairo_t *cr,
+ int width,
+ int height,
+ gpointer user_data);
gboolean load_game_graphics (void);
gboolean free_game_graphics (void);
gint num_game_graphics (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]