[gimp/gtk3-port: 73/249] libgimpwidgets: port the ruler to GTK+ 3.0



commit 9e4cb09c539cf8d4329725ed507e994ed47d3a44
Author: Michael Natterer <mitch gimp org>
Date:   Tue Oct 19 18:59:50 2010 +0200

    libgimpwidgets: port the ruler to GTK+ 3.0

 libgimpwidgets/gimpruler.c |   62 +++++++++++++++++--------------------------
 1 files changed, 25 insertions(+), 37 deletions(-)
---
diff --git a/libgimpwidgets/gimpruler.c b/libgimpwidgets/gimpruler.c
index 74db7fc..1f6129a 100644
--- a/libgimpwidgets/gimpruler.c
+++ b/libgimpwidgets/gimpruler.c
@@ -112,8 +112,8 @@ static void          gimp_ruler_style_set     (GtkWidget      *widget,
                                                GtkStyle       *prev_style);
 static gboolean      gimp_ruler_motion_notify (GtkWidget      *widget,
                                                GdkEventMotion *event);
-static gboolean      gimp_ruler_expose        (GtkWidget      *widget,
-                                               GdkEventExpose *event);
+static gboolean      gimp_ruler_draw          (GtkWidget      *widget,
+                                               cairo_t        *cr);
 
 static void          gimp_ruler_draw_ticks    (GimpRuler      *ruler);
 static void          gimp_ruler_draw_pos      (GimpRuler      *ruler);
@@ -144,7 +144,7 @@ gimp_ruler_class_init (GimpRulerClass *klass)
   widget_class->size_request        = gimp_ruler_size_request;
   widget_class->style_set           = gimp_ruler_style_set;
   widget_class->motion_notify_event = gimp_ruler_motion_notify;
-  widget_class->expose_event        = gimp_ruler_expose;
+  widget_class->draw                = gimp_ruler_draw;
 
   g_type_class_add_private (object_class, sizeof (GimpRulerPrivate));
 
@@ -781,7 +781,14 @@ static void
 gimp_ruler_size_allocate (GtkWidget     *widget,
                           GtkAllocation *allocation)
 {
-  GimpRuler *ruler = GIMP_RULER (widget);
+  GimpRuler     *ruler = GIMP_RULER (widget);
+  GtkAllocation  widget_allocation;
+  gboolean       resized;
+
+  gtk_widget_get_allocation (widget, &widget_allocation);
+
+  resized = (widget_allocation.width  != allocation->width ||
+             widget_allocation.height != allocation->height);
 
   gtk_widget_set_allocation (widget, allocation);
 
@@ -791,7 +798,8 @@ gimp_ruler_size_allocate (GtkWidget     *widget,
                               allocation->x, allocation->y,
                               allocation->width, allocation->height);
 
-      gimp_ruler_make_pixmap (ruler);
+      if (resized)
+        gimp_ruler_make_pixmap (ruler);
     }
 }
 
@@ -855,28 +863,18 @@ gimp_ruler_motion_notify (GtkWidget      *widget,
 }
 
 static gboolean
-gimp_ruler_expose (GtkWidget      *widget,
-                   GdkEventExpose *event)
+gimp_ruler_draw (GtkWidget *widget,
+                 cairo_t   *cr)
 {
-  if (gtk_widget_is_drawable (widget))
-    {
-      GimpRuler        *ruler = GIMP_RULER (widget);
-      GimpRulerPrivate *priv  = GIMP_RULER_GET_PRIVATE (ruler);
-      cairo_t          *cr;
-
-      gimp_ruler_draw_ticks (ruler);
-
-      cr = gdk_cairo_create (gtk_widget_get_window (widget));
-      gdk_cairo_region (cr, event->region);
-      cairo_clip (cr);
+  GimpRuler        *ruler = GIMP_RULER (widget);
+  GimpRulerPrivate *priv  = GIMP_RULER_GET_PRIVATE (ruler);
 
-      cairo_set_source_surface (cr, priv->backing_store, 0, 0);
-      cairo_paint (cr);
+  gimp_ruler_draw_ticks (ruler);
 
-      gimp_ruler_draw_pos (ruler);
+  cairo_set_source_surface (cr, priv->backing_store, 0, 0);
+  cairo_paint (cr);
 
-      cairo_destroy (cr);
-    }
+  gimp_ruler_draw_pos (ruler);
 
   return FALSE;
 }
@@ -1107,7 +1105,6 @@ gimp_ruler_draw_ticks (GimpRuler *ruler)
                                      pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset));
                       pango_cairo_show_layout (cr, layout);
 #endif
-
                     }
                 }
             }
@@ -1176,7 +1173,6 @@ gimp_ruler_draw_pos (GimpRuler *ruler)
           cairo_fill (cr);
         }
 
-
       position = gimp_ruler_get_position (ruler);
 
       gimp_ruler_get_range (ruler, &lower, &upper, NULL);
@@ -1226,27 +1222,19 @@ gimp_ruler_make_pixmap (GimpRuler *ruler)
   GtkWidget        *widget = GTK_WIDGET (ruler);
   GimpRulerPrivate *priv   = GIMP_RULER_GET_PRIVATE (ruler);
   GtkAllocation     allocation;
-  cairo_t          *cr;
-  cairo_surface_t  *surface;
 
   gtk_widget_get_allocation (widget, &allocation);
 
   if (priv->backing_store)
     cairo_surface_destroy (priv->backing_store);
 
-  cr = gdk_cairo_create (gtk_widget_get_window (widget));
-  surface = cairo_get_target (cr);
-
   priv->backing_store =
-    cairo_surface_create_similar (surface,
-                                  CAIRO_CONTENT_COLOR,
-                                  allocation.width,
-                                  allocation.height);
-
-  cairo_destroy (cr);
+    gdk_window_create_similar_surface (gtk_widget_get_window (widget),
+                                       CAIRO_CONTENT_COLOR,
+                                       allocation.width,
+                                       allocation.height);
 }
 
-
 static PangoLayout *
 gimp_ruler_create_layout (GtkWidget   *widget,
                           const gchar *text)



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