[accounts-dialog] Port the croparea code to GTK+ 2.91



commit 6165618d0dbdb9e16e3b9bcb48855513222457b2
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Oct 14 00:29:20 2010 -0400

    Port the croparea code to GTK+ 2.91

 src/um-crop-area.c |   99 +++++++++-------------------------------------------
 1 files changed, 17 insertions(+), 82 deletions(-)
---
diff --git a/src/um-crop-area.c b/src/um-crop-area.c
index 70b637f..e9fd708 100644
--- a/src/um-crop-area.c
+++ b/src/um-crop-area.c
@@ -184,16 +184,13 @@ typedef enum {
 } Location;
 
 static gboolean
-um_crop_area_expose (GtkWidget      *widget,
-                     GdkEventExpose *event)
+um_crop_area_draw (GtkWidget *widget,
+                   cairo_t   *cr)
 {
-        cairo_t *cr;
         GdkRectangle area;
         GdkRectangle crop;
         gint width, height;
         UmCropArea *uarea = UM_CROP_AREA (widget);
-        GtkStyle *style;
-        GdkWindow *window;
 
         if (uarea->priv->browse_pixbuf == NULL)
                 return FALSE;
@@ -204,80 +201,20 @@ um_crop_area_expose (GtkWidget      *widget,
         height = gdk_pixbuf_get_height (uarea->priv->pixbuf);
         crop_to_widget (uarea, &crop);
 
-        area.x = 0;
-        area.y = 0;
-        area.width = width;
-        area.height = crop.y;
-        gdk_rectangle_intersect (&area, &event->area, &area);
-        style = gtk_widget_get_style (widget);
-        window = gtk_widget_get_window (widget);
-        gdk_draw_pixbuf (window,
-                         style->fg_gc[gtk_widget_get_state (widget)],
-                         uarea->priv->color_shifted,
-                         area.x, area.y,
-                         area.x, area.y,
-                         area.width, area.height,
-                         GDK_RGB_DITHER_NONE, 0, 0);
-
-        area.x = 0;
-        area.y = crop.y;
-        area.width = crop.x;
-        area.height = crop.height;
-        gdk_rectangle_intersect (&area, &event->area, &area);
-        gdk_draw_pixbuf (window,
-                         style->fg_gc[gtk_widget_get_state (widget)],
-                         uarea->priv->color_shifted,
-                         area.x, area.y,
-                         area.x, area.y,
-                         area.width, area.height,
-                         GDK_RGB_DITHER_NONE, 0, 0);
-
-        area.x = crop.x;
-        area.y = crop.y;
-        area.width = crop.width;
-        area.height = crop.height;
-        gdk_rectangle_intersect (&area, &event->area, &area);
-        gdk_draw_pixbuf (window,
-                         style->fg_gc[gtk_widget_get_state (widget)],
-                         uarea->priv->pixbuf,
-                         area.x, area.y,
-                         area.x, area.y,
-                         area.width, area.height,
-                         GDK_RGB_DITHER_NONE, 0, 0);
-
-        area.x = crop.x + crop.width;
-        area.y = crop.y;
-        area.width = width - area.x;
-        area.height = crop.height;
-        gdk_rectangle_intersect (&area, &event->area, &area);
-        gdk_draw_pixbuf (window,
-                         style->fg_gc[gtk_widget_get_state (widget)],
-                         uarea->priv->color_shifted,
-                         area.x, area.y,
-                         area.x, area.y,
-                         area.width, area.height,
-                         GDK_RGB_DITHER_NONE, 0, 0);
-
-        area.x = 0;
-        area.y = crop.y + crop.height;
-        area.width = width;
-        area.height = height - area.y;
-        gdk_rectangle_intersect (&area, &event->area, &area);
-        gdk_draw_pixbuf (window,
-                         style->fg_gc[gtk_widget_get_state (widget)],
-                         uarea->priv->color_shifted,
-                         area.x, area.y,
-                         area.x, area.y,
-                         area.width, area.height,
-                         GDK_RGB_DITHER_NONE, 0, 0);
-
-        cr = gdk_cairo_create (window);
-        gdk_cairo_rectangle (cr, &event->area);
-        cairo_clip (cr);
+        gdk_cairo_set_source_pixbuf (cr, uarea->priv->color_shifted, 0, 0);
+        cairo_rectangle (cr, 0, 0, width, crop.y);
+        cairo_rectangle (cr, 0, crop.y, crop.x, height);
+        cairo_rectangle (cr, crop.x + crop.width, crop.y, width - area.x, crop.height);
+        cairo_rectangle (cr, 0, crop.y + crop.height, width, height - area.y);
+        cairo_fill (cr);
+
+        gdk_cairo_set_source_pixbuf (cr, uarea->priv->pixbuf, 0, 0);
+        cairo_rectangle (cr, crop.x, crop.y, crop.width, crop.height);
+        cairo_fill (cr);
 
         if (uarea->priv->active_region != OUTSIDE) {
                 gint x1, x2, y1, y2;
-                gdk_cairo_set_source_color (cr, &style->white);
+                cairo_set_source_rgb (cr, 1, 1, 1);
                 cairo_set_line_width (cr, 1.0);
                 x1 = crop.x + crop.width / 3.0;
                 x2 = crop.x + 2 * crop.width / 3.0;
@@ -298,7 +235,7 @@ um_crop_area_expose (GtkWidget      *widget,
                 cairo_stroke (cr);
         }
 
-        gdk_cairo_set_source_color (cr, &style->black);
+        cairo_set_source_rgb (cr,  0, 0, 0);
         cairo_set_line_width (cr, 1.0);
         cairo_rectangle (cr,
                          crop.x + 0.5,
@@ -307,7 +244,7 @@ um_crop_area_expose (GtkWidget      *widget,
                          crop.height - 1.0);
         cairo_stroke (cr);
 
-        gdk_cairo_set_source_color (cr, &style->white);
+        cairo_set_source_rgb (cr, 1, 1, 1);
         cairo_set_line_width (cr, 2.0);
         cairo_rectangle (cr,
                          crop.x + 2.0,
@@ -316,8 +253,6 @@ um_crop_area_expose (GtkWidget      *widget,
                          crop.height - 4.0);
         cairo_stroke (cr);
 
-        cairo_destroy (cr);
-
         return FALSE;
 }
 
@@ -769,8 +704,8 @@ um_crop_area_class_init (UmCropAreaClass *klass)
         GObjectClass   *object_class = G_OBJECT_CLASS (klass);
         GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-        object_class->finalize     = um_crop_area_finalize;
-        widget_class->expose_event = um_crop_area_expose;
+        object_class->finalize = um_crop_area_finalize;
+        widget_class->draw = um_crop_area_draw;
         widget_class->button_press_event = um_crop_area_button_press_event;
         widget_class->button_release_event = um_crop_area_button_release_event;
         widget_class->motion_notify_event = um_crop_area_motion_notify_event;



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