[gimp/gtk3-port: 65/226] modules: port to GtkWidget::draw()



commit 1299880ad6053b9d2ba2cf890a140358a2427f29
Author: Michael Natterer <mitch gimp org>
Date:   Thu Oct 21 12:49:13 2010 +0200

    modules: port to GtkWidget::draw()

 modules/color-selector-water.c |   44 ++++++++++++++++++++--------------------
 1 files changed, 22 insertions(+), 22 deletions(-)
---
diff --git a/modules/color-selector-water.c b/modules/color-selector-water.c
index d810f9f..eb33d05 100644
--- a/modules/color-selector-water.c
+++ b/modules/color-selector-water.c
@@ -61,8 +61,8 @@ struct _ColorselWaterClass
 
 static GType      colorsel_water_get_type (void);
 
-static gboolean   select_area_expose      (GtkWidget          *widget,
-                                           GdkEventExpose     *event);
+static gboolean   select_area_draw        (GtkWidget          *widget,
+                                           cairo_t            *cr);
 static gboolean   button_press_event      (GtkWidget          *widget,
                                            GdkEventButton     *event,
                                            ColorselWater      *water);
@@ -147,8 +147,8 @@ colorsel_water_init (ColorselWater *water)
 
   area = gtk_drawing_area_new ();
   gtk_container_add (GTK_CONTAINER (frame), area);
-  g_signal_connect (area, "expose-event",
-                    G_CALLBACK (select_area_expose),
+  g_signal_connect (area, "draw",
+                    G_CALLBACK (select_area_draw),
                     NULL);
 
   /* Event signals */
@@ -203,11 +203,12 @@ calc (gdouble x,
 }
 
 static gboolean
-select_area_expose (GtkWidget      *widget,
-                    GdkEventExpose *event)
+select_area_draw (GtkWidget *widget,
+                  cairo_t   *cr)
 {
-  cairo_t         *cr;
+  GdkRectangle     area;
   GtkAllocation    allocation;
+  gdouble          x1, y1, x2, y2;
   gdouble          dx;
   gdouble          dy;
   cairo_surface_t *surface;
@@ -215,10 +216,12 @@ select_area_expose (GtkWidget      *widget,
   gdouble          y;
   gint             j;
 
-  cr = gdk_cairo_create (event->window);
+  cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
 
-  gdk_cairo_region (cr, event->region);
-  cairo_clip (cr);
+  area.x      = floor (x1);
+  area.y      = floor (y1);
+  area.width  = ceil (x2) - area.x;
+  area.height = ceil (y2) - area.y;
 
   gtk_widget_get_allocation (widget, &allocation);
 
@@ -226,13 +229,13 @@ select_area_expose (GtkWidget      *widget,
   dy = 1.0 / allocation.height;
 
   surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
-                                        event->area.width,
-                                        event->area.height);
+                                        area.width,
+                                        area.height);
 
   dest = cairo_image_surface_get_data (surface);
 
-  for (j = 0, y = event->area.y / allocation.height;
-       j < event->area.height;
+  for (j = 0, y = area.y / allocation.height;
+       j < area.height;
        j++, y += dy)
     {
       guchar  *d  = dest;
@@ -247,11 +250,11 @@ select_area_expose (GtkWidget      *widget,
 
       gint     i;
 
-      r += event->area.x * dr;
-      g += event->area.x * dg;
-      b += event->area.x * db;
+      r += area.x * dr;
+      g += area.x * dg;
+      b += area.x * db;
 
-      for (i = 0; i < event->area.width; i++)
+      for (i = 0; i < area.width; i++)
         {
           GIMP_CAIRO_RGB24_SET_PIXEL (d,
                                       CLAMP ((gint) r, 0, 255),
@@ -269,14 +272,11 @@ select_area_expose (GtkWidget      *widget,
     }
 
   cairo_surface_mark_dirty (surface);
-  cairo_set_source_surface (cr, surface,
-                            event->area.x, event->area.y);
+  cairo_set_source_surface (cr, surface, area.x, area.y);
   cairo_surface_destroy (surface);
 
   cairo_paint (cr);
 
-  cairo_destroy (cr);
-
   return FALSE;
 }
 


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