[gimp/gtk3-port: 22/234] app: port to GtkWidget::draw()



commit 8b54898de7ece7e6c086a42eb6fd25dd7a05c30c
Author: Michael Natterer <mitch gimp org>
Date:   Fri Oct 15 14:15:07 2010 +0200

    app: port to GtkWidget::draw()

 app/widgets/gimpfgbgeditor.c |   37 +++++++++++++------------------------
 app/widgets/gimpfgbgview.c   |   42 ++++++++++++++----------------------------
 2 files changed, 27 insertions(+), 52 deletions(-)
---
diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c
index 320c5bc..8848ebf 100644
--- a/app/widgets/gimpfgbgeditor.c
+++ b/app/widgets/gimpfgbgeditor.c
@@ -74,10 +74,9 @@ static void     gimp_fg_bg_editor_get_property      (GObject          *object,
                                                      GValue           *value,
                                                      GParamSpec       *pspec);
 
-static void     gimp_fg_bg_editor_style_set         (GtkWidget        *widget,
-                                                     GtkStyle         *prev_style);
-static gboolean gimp_fg_bg_editor_expose            (GtkWidget        *widget,
-                                                     GdkEventExpose   *eevent);
+static void     gimp_fg_bg_editor_style_updated     (GtkWidget        *widget);
+static gboolean gimp_fg_bg_editor_draw              (GtkWidget        *widget,
+                                                     cairo_t          *cr);
 static gboolean gimp_fg_bg_editor_button_press      (GtkWidget        *widget,
                                                      GdkEventButton   *bevent);
 static gboolean gimp_fg_bg_editor_button_release    (GtkWidget        *widget,
@@ -128,8 +127,8 @@ gimp_fg_bg_editor_class_init (GimpFgBgEditorClass *klass)
   object_class->set_property         = gimp_fg_bg_editor_set_property;
   object_class->get_property         = gimp_fg_bg_editor_get_property;
 
-  widget_class->style_set            = gimp_fg_bg_editor_style_set;
-  widget_class->expose_event         = gimp_fg_bg_editor_expose;
+  widget_class->style_updated        = gimp_fg_bg_editor_style_updated;
+  widget_class->draw                 = gimp_fg_bg_editor_draw;
   widget_class->button_press_event   = gimp_fg_bg_editor_button_press;
   widget_class->button_release_event = gimp_fg_bg_editor_button_release;
   widget_class->drag_motion          = gimp_fg_bg_editor_drag_motion;
@@ -235,12 +234,11 @@ gimp_fg_bg_editor_get_property (GObject    *object,
 }
 
 static void
-gimp_fg_bg_editor_style_set (GtkWidget *widget,
-                             GtkStyle  *prev_style)
+gimp_fg_bg_editor_style_updated (GtkWidget *widget)
 {
   GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
 
-  GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
+  GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
 
   if (editor->default_icon)
     {
@@ -256,13 +254,11 @@ gimp_fg_bg_editor_style_set (GtkWidget *widget,
 }
 
 static gboolean
-gimp_fg_bg_editor_expose (GtkWidget      *widget,
-                          GdkEventExpose *eevent)
+gimp_fg_bg_editor_draw (GtkWidget *widget,
+                        cairo_t   *cr)
 {
   GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
   GtkStyle       *style  = gtk_widget_get_style (widget);
-  GdkWindow      *window = gtk_widget_get_window (widget);
-  cairo_t        *cr;
   GtkAllocation   allocation;
   gint            width, height;
   gint            default_w, default_h;
@@ -273,11 +269,6 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
   if (! gtk_widget_is_drawable (widget))
     return FALSE;
 
-  cr = gdk_cairo_create (eevent->window);
-
-  gdk_cairo_region (cr, eevent->region);
-  cairo_clip (cr);
-
   gtk_widget_get_allocation (widget, &allocation);
 
   width  = allocation.width;
@@ -359,10 +350,10 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
       cairo_fill (cr);
     }
 
-  gtk_paint_shadow (style, window, GTK_STATE_NORMAL,
+  gtk_paint_shadow (style, cr, GTK_STATE_NORMAL,
                     editor->active_color == GIMP_ACTIVE_COLOR_FOREGROUND ?
                     GTK_SHADOW_OUT : GTK_SHADOW_IN,
-                    NULL, widget, NULL,
+                    widget, NULL,
                     (width - rect_w),
                     (height - rect_h),
                     rect_w, rect_h);
@@ -390,15 +381,13 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
       cairo_fill (cr);
     }
 
-  gtk_paint_shadow (style, window, GTK_STATE_NORMAL,
+  gtk_paint_shadow (style, cr, GTK_STATE_NORMAL,
                     editor->active_color == GIMP_ACTIVE_COLOR_BACKGROUND ?
                     GTK_SHADOW_OUT : GTK_SHADOW_IN,
-                    NULL, widget, NULL,
+                    widget, NULL,
                     0, 0,
                     rect_w, rect_h);
 
-  cairo_destroy (cr);
-
   return TRUE;
 }
 
diff --git a/app/widgets/gimpfgbgview.c b/app/widgets/gimpfgbgview.c
index f893100..9c8ac1f 100644
--- a/app/widgets/gimpfgbgview.c
+++ b/app/widgets/gimpfgbgview.c
@@ -57,8 +57,8 @@ static void     gimp_fg_bg_view_get_property      (GObject        *object,
                                                    GValue         *value,
                                                    GParamSpec     *pspec);
 
-static gboolean gimp_fg_bg_view_expose            (GtkWidget      *widget,
-                                                   GdkEventExpose *eevent);
+static gboolean gimp_fg_bg_view_draw              (GtkWidget      *widget,
+                                                   cairo_t        *cr);
 
 static void     gimp_fg_bg_view_create_transform  (GimpFgBgView   *view);
 static void     gimp_fg_bg_view_destroy_transform (GimpFgBgView   *view);
@@ -79,7 +79,7 @@ gimp_fg_bg_view_class_init (GimpFgBgViewClass *klass)
   object_class->set_property = gimp_fg_bg_view_set_property;
   object_class->get_property = gimp_fg_bg_view_get_property;
 
-  widget_class->expose_event = gimp_fg_bg_view_expose;
+  widget_class->draw         = gimp_fg_bg_view_draw;
 
   g_object_class_install_property (object_class, PROP_CONTEXT,
                                    g_param_spec_object ("context",
@@ -150,29 +150,17 @@ gimp_fg_bg_view_get_property (GObject    *object,
 }
 
 static gboolean
-gimp_fg_bg_view_expose (GtkWidget      *widget,
-                        GdkEventExpose *eevent)
+gimp_fg_bg_view_draw (GtkWidget *widget,
+                      cairo_t   *cr)
 {
-  GimpFgBgView *view   = GIMP_FG_BG_VIEW (widget);
-  GtkStyle     *style  = gtk_widget_get_style (widget);
-  GdkWindow    *window = gtk_widget_get_window (widget);
-  cairo_t      *cr;
+  GimpFgBgView *view  = GIMP_FG_BG_VIEW (widget);
+  GtkStyle     *style = gtk_widget_get_style (widget);
   GtkAllocation allocation;
   gint          rect_w, rect_h;
   GimpRGB       color;
 
-  if (! gtk_widget_is_drawable (widget))
-    return FALSE;
-
-  cr = gdk_cairo_create (eevent->window);
-
-  gdk_cairo_region (cr, eevent->region);
-  cairo_clip (cr);
-
   gtk_widget_get_allocation (widget, &allocation);
 
-  cairo_translate (cr, allocation.x, allocation.y);
-
   rect_w = allocation.width  * 3 / 4;
   rect_h = allocation.height * 3 / 4;
 
@@ -203,11 +191,11 @@ gimp_fg_bg_view_expose (GtkWidget      *widget,
       cairo_fill (cr);
     }
 
-  gtk_paint_shadow (style, window, GTK_STATE_NORMAL,
+  gtk_paint_shadow (style, cr, GTK_STATE_NORMAL,
                     GTK_SHADOW_IN,
-                    NULL, widget, NULL,
-                    allocation.x + allocation.width  - rect_w,
-                    allocation.y + allocation.height - rect_h,
+                    widget, NULL,
+                    allocation.width  - rect_w,
+                    allocation.height - rect_h,
                     rect_w, rect_h);
 
   /*  draw the foreground area  */
@@ -230,12 +218,10 @@ gimp_fg_bg_view_expose (GtkWidget      *widget,
       cairo_fill (cr);
     }
 
-  gtk_paint_shadow (style, window, GTK_STATE_NORMAL,
+  gtk_paint_shadow (style, cr, GTK_STATE_NORMAL,
                     GTK_SHADOW_OUT,
-                    NULL, widget, NULL,
-                    allocation.x, allocation.y, rect_w, rect_h);
-
-  cairo_destroy (cr);
+                    widget, NULL,
+                    0, 0, rect_w, rect_h);
 
   return TRUE;
 }


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