[empathy: 2/4] rounded-rectangle: use the 'draw' signal



commit 532a1f7c653866c50589d37fb20b13e1f71738cf
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Fri Mar 9 09:21:40 2012 +0100

    rounded-rectangle: use the 'draw' signal
    
    Looks like that's the right way to do it since Clutter 1.8
    
    https://bugzilla.gnome.org/show_bug.cgi?id=669673

 configure.ac                    |    6 +++---
 src/empathy-rounded-rectangle.c |   29 ++++++++++++++++++++---------
 2 files changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 70ca492..6e5caec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,9 +45,9 @@ GTK_REQUIRED=3.0.2
 AC_DEFINE(GDK_VERSION_MIN_REQUIRED, GDK_VERSION_3_0, [Ignore post 3.0 deprecations])
 AC_DEFINE(GDK_VERSION_MAX_REQUIRED, GDK_VERSION_3_0, [Prevent post 3.0 APIs])
 
-CLUTTER_REQUIRED=1.7.14
-AC_DEFINE(CLUTTER_VERSION_MIN_REQUIRED, CLUTTER_VERSION_1_6, [Ignore post 1.6 deprecations])
-AC_DEFINE(CLUTTER_VERSION_MAX, CLUTTER_VERSION_1_6, [Prevent post 1.6 APIs])
+CLUTTER_REQUIRED=1.8.0
+AC_DEFINE(CLUTTER_VERSION_MIN_REQUIRED, CLUTTER_VERSION_1_8, [Ignore post 1.8 deprecations])
+AC_DEFINE(CLUTTER_VERSION_MAX, CLUTTER_VERSION_1_8, [Prevent post 1.8 APIs])
 
 CLUTTER_GTK_REQUIRED=0.90.3
 
diff --git a/src/empathy-rounded-rectangle.c b/src/empathy-rounded-rectangle.c
index 8e6dab3..6024615 100644
--- a/src/empathy-rounded-rectangle.c
+++ b/src/empathy-rounded-rectangle.c
@@ -37,12 +37,13 @@ struct _EmpathyRoundedRectanglePriv
   guint border_width;
 };
 
-static void
-empathy_rounded_rectangle_paint (EmpathyRoundedRectangle *self)
+static gboolean
+draw_cb (ClutterCairoTexture *canvas,
+    cairo_t *cr)
 {
+  EmpathyRoundedRectangle *self = EMPATHY_ROUNDED_RECTANGLE (canvas);
   guint width, height;
   guint tmp_alpha;
-  cairo_t *cr;
 
 #define RADIUS (height / 8.)
 
@@ -55,8 +56,6 @@ empathy_rounded_rectangle_paint (EmpathyRoundedRectangle *self)
             * self->priv->border_color.alpha
             / 255;
 
-  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (self));
-
   cairo_set_source_rgba (cr,
       self->priv->border_color.red,
       self->priv->border_color.green,
@@ -84,9 +83,9 @@ empathy_rounded_rectangle_paint (EmpathyRoundedRectangle *self)
   cairo_close_path (cr);
 
   cairo_stroke (cr);
-  cairo_destroy (cr);
 
 #undef RADIUS
+  return TRUE;
 }
 
 static void
@@ -99,8 +98,18 @@ empathy_rounded_rectangle_init (EmpathyRoundedRectangle *self)
 }
 
 static void
+empathy_rounded_rectangle_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (empathy_rounded_rectangle_parent_class)->finalize (object);
+}
+
+static void
 empathy_rounded_rectangle_class_init (EmpathyRoundedRectangleClass *klass)
 {
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->finalize = empathy_rounded_rectangle_finalize;
+
   g_type_class_add_private (klass, sizeof (EmpathyRoundedRectanglePriv));
 }
 
@@ -123,8 +132,10 @@ empathy_rounded_rectangle_new (guint width,
   self->priv->width = width;
   self->priv->height = height;
 
+  g_signal_connect (self, "draw", G_CALLBACK (draw_cb), NULL);
+
   empathy_rounded_rectangle_update_surface_size (self);
-  empathy_rounded_rectangle_paint (self);
+  clutter_cairo_texture_invalidate (CLUTTER_CAIRO_TEXTURE (self));
 
   return CLUTTER_ACTOR (self);
 }
@@ -136,7 +147,7 @@ empathy_rounded_rectangle_set_border_width (EmpathyRoundedRectangle *self,
   self->priv->border_width = border_width;
 
   empathy_rounded_rectangle_update_surface_size (self);
-  empathy_rounded_rectangle_paint (self);
+  clutter_cairo_texture_invalidate (CLUTTER_CAIRO_TEXTURE (self));
 }
 
 void
@@ -145,5 +156,5 @@ empathy_rounded_rectangle_set_border_color (EmpathyRoundedRectangle *self,
 {
   self->priv->border_color = *color;
 
-  empathy_rounded_rectangle_paint (self);
+  clutter_cairo_texture_invalidate (CLUTTER_CAIRO_TEXTURE (self));
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]