[gimp/gtk3-port: 76/130] libgimpwidgets: port to GtkWidget::draw()



commit b081e19a3a4be58edc49b61e224bbf0a4f3073da
Author: Michael Natterer <mitch gimp org>
Date:   Tue Oct 19 19:07:49 2010 +0200

    libgimpwidgets: port to GtkWidget::draw()

 libgimpwidgets/gimppreviewarea.c |   46 ++++++++++++++++---------------------
 1 files changed, 20 insertions(+), 26 deletions(-)
---
diff --git a/libgimpwidgets/gimppreviewarea.c b/libgimpwidgets/gimppreviewarea.c
index fa9a1d8..25a15a1 100644
--- a/libgimpwidgets/gimppreviewarea.c
+++ b/libgimpwidgets/gimppreviewarea.c
@@ -69,8 +69,8 @@ static void      gimp_preview_area_get_property     (GObject         *object,
 
 static void      gimp_preview_area_size_allocate    (GtkWidget       *widget,
                                                      GtkAllocation   *allocation);
-static gboolean  gimp_preview_area_expose           (GtkWidget       *widget,
-                                                     GdkEventExpose  *event);
+static gboolean  gimp_preview_area_widget_draw      (GtkWidget       *widget,
+                                                     cairo_t         *cr);
 
 static void      gimp_preview_area_queue_draw       (GimpPreviewArea *area,
                                                      gint             x,
@@ -96,7 +96,7 @@ gimp_preview_area_class_init (GimpPreviewAreaClass *klass)
   object_class->get_property  = gimp_preview_area_get_property;
 
   widget_class->size_allocate = gimp_preview_area_size_allocate;
-  widget_class->expose_event  = gimp_preview_area_expose;
+  widget_class->draw          = gimp_preview_area_widget_draw;
 
   g_object_class_install_property (object_class, PROP_CHECK_SIZE,
                                    g_param_spec_enum ("check-size",
@@ -226,13 +226,13 @@ gimp_preview_area_size_allocate (GtkWidget     *widget,
 }
 
 static gboolean
-gimp_preview_area_expose (GtkWidget      *widget,
-                          GdkEventExpose *event)
+gimp_preview_area_widget_draw (GtkWidget *widget,
+                               cairo_t   *cr)
 {
-  GimpPreviewArea *area = GIMP_PREVIEW_AREA (widget);
+  GimpPreviewArea *area  = GIMP_PREVIEW_AREA (widget);
   GtkAllocation    allocation;
+  GdkPixbuf       *pixbuf;
   GdkRectangle     rect;
-  GdkRectangle     render;
 
   if (! area->buf)
     return FALSE;
@@ -244,25 +244,19 @@ gimp_preview_area_expose (GtkWidget      *widget,
   rect.width  = area->width;
   rect.height = area->height;
 
-  if (gdk_rectangle_intersect (&rect, &event->area, &render))
-    {
-      GtkStyle *style = gtk_widget_get_style (widget);
-      gint      x     = render.x - rect.x;
-      gint      y     = render.y - rect.y;
-      guchar   *buf   = area->buf + x * 3 + y * area->rowstride;
-
-      gdk_draw_rgb_image_dithalign (gtk_widget_get_window (widget),
-                                    style->fg_gc[gtk_widget_get_state (widget)],
-                                    render.x,
-                                    render.y,
-                                    render.width,
-                                    render.height,
-                                    GDK_RGB_DITHER_MAX,
-                                    buf,
-                                    area->rowstride,
-                                    area->offset_x - render.x,
-                                    area->offset_y - render.y);
-    }
+  pixbuf = gdk_pixbuf_new_from_data (area->buf,
+                                     GDK_COLORSPACE_RGB,
+                                     FALSE,
+                                     8,
+                                     rect.width,
+                                     rect.height,
+                                     area->rowstride,
+                                     NULL, NULL);
+
+  gdk_cairo_set_source_pixbuf (cr, pixbuf, rect.x, rect.y);
+  cairo_paint (cr);
+
+  g_object_unref (pixbuf);
 
   return FALSE;
 }



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