From 71a3f61d25d6998c07db899148bd0bac48ad0026 Mon Sep 17 00:00:00 2001 From: infirit Date: Sun, 12 Jul 2015 14:33:00 +0200 Subject: popsquares: Use cairo for Gtk+2 --- savers/gste-popsquares.c | 70 +++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 49 deletions(-) (limited to 'savers') diff --git a/savers/gste-popsquares.c b/savers/gste-popsquares.c index db7c36f..245be48 100644 --- a/savers/gste-popsquares.c +++ b/savers/gste-popsquares.c @@ -51,9 +51,6 @@ struct GSTEPopsquaresPrivate int ncolors; int subdivision; -#if !GTK_CHECK_VERSION (3, 0, 0) - GdkGC *gc; -#endif GdkColor *colors; square *squares; @@ -433,14 +430,6 @@ setup_colors (GSTEPopsquares *pop) set_colors (window, &fg, &bg); -#if !GTK_CHECK_VERSION (3, 0, 0) - if (pop->priv->gc) - { - g_object_unref (pop->priv->gc); - } - pop->priv->gc = gdk_gc_new (window); -#endif - if (pop->priv->colors) { g_free (pop->priv->colors); @@ -491,31 +480,26 @@ static gboolean #if GTK_CHECK_VERSION (3, 0, 0) gste_popsquares_real_draw (GtkWidget *widget, cairo_t *cr) +{ + if (GTK_WIDGET_CLASS (parent_class)->draw) { + GTK_WIDGET_CLASS (parent_class)->draw (widget, cr); + } #else gste_popsquares_real_expose (GtkWidget *widget, GdkEventExpose *event) -#endif { - gboolean handled = FALSE; - - /* draw */ - - /* FIXME: should double buffer? */ - -#if GTK_CHECK_VERSION (3, 0, 0) - if (GTK_WIDGET_CLASS (parent_class)->draw) - { - handled = GTK_WIDGET_CLASS (parent_class)->draw (widget, cr); - } - draw_frame (GSTE_POPSQUARES (widget), cr); -#else - if (GTK_WIDGET_CLASS (parent_class)->expose_event) - { - handled = GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event); + if (GTK_WIDGET_CLASS (parent_class)->expose_event) { + GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event); } + cairo_t *cr = gdk_cairo_create (event->window); #endif - return handled; + draw_frame (GSTE_POPSQUARES (widget), cr); + +#if !GTK_CHECK_VERSION (3, 0, 0) + cairo_destroy (cr); +#endif + return TRUE; } static gboolean @@ -565,17 +549,10 @@ gste_popsquares_class_init (GSTEPopsquaresClass *klass) g_type_class_add_private (klass, sizeof (GSTEPopsquaresPrivate)); } -static gboolean -draw_iter (GSTEPopsquares *pop) -#if GTK_CHECK_VERSION (3, 0, 0) -{ - gtk_widget_queue_draw (GTK_WIDGET (pop)); - return TRUE; -} static void -draw_frame (GSTEPopsquares *pop, cairo_t *cr) -#endif +draw_frame (GSTEPopsquares *pop, + cairo_t *cr) { int border = 1; gboolean twitch = FALSE; @@ -609,18 +586,11 @@ draw_frame (GSTEPopsquares *pop, cairo_t *cr) { square *s = (square *) &pop->priv->squares [gw * y + x]; -#if GTK_CHECK_VERSION (3, 0, 0) gdk_cairo_set_source_color (cr, &(pop->priv->colors [s->color])); cairo_rectangle (cr, s->x, s->y, border ? s->w - border : s->w, border ? s->h - border : s->h); cairo_fill (cr); -#else - gdk_gc_set_foreground (pop->priv->gc, &(pop->priv->colors [s->color])); - gdk_draw_rectangle (window, pop->priv->gc, TRUE, s->x, s->y, - border ? s->w - border : s->w, - border ? s->h - border : s->h); -#endif s->color++; if (s->color == pop->priv->ncolors) @@ -636,8 +606,13 @@ draw_frame (GSTEPopsquares *pop, cairo_t *cr) } } } +} - return; +static gboolean +draw_iter (GSTEPopsquares *pop) +{ + gtk_widget_queue_draw (GTK_WIDGET (pop)); + return TRUE; } static void @@ -674,9 +649,6 @@ gste_popsquares_finalize (GObject *object) g_free (pop->priv->squares); g_free (pop->priv->colors); -#if !GTK_CHECK_VERSION (3, 0, 0) - g_object_unref (pop->priv->gc); -#endif G_OBJECT_CLASS (parent_class)->finalize (object); } -- cgit v1.2.1