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



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

    app: port to GtkWidget::draw()

 app/widgets/gimpfgbgeditor.c |   36 +++++++++++++-----------------------
 app/widgets/gimpfgbgview.c   |   42 ++++++++++++++----------------------------
 2 files changed, 27 insertions(+), 51 deletions(-)
---
diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c
index 845bc45..71b5447 100644
--- a/app/widgets/gimpfgbgeditor.c
+++ b/app/widgets/gimpfgbgeditor.c
@@ -75,10 +75,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,
@@ -129,8 +128,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;
@@ -229,25 +228,22 @@ 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);
 
   g_clear_object (&editor->default_icon);
   g_clear_object (&editor->swap_icon);
 }
 
 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;
@@ -259,10 +255,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;
@@ -365,10 +357,10 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
         }
     }
 
-  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,
                     allocation.x + (width - rect_w),
                     allocation.y + (height - rect_h),
                     rect_w, rect_h);
@@ -415,16 +407,14 @@ gimp_fg_bg_editor_expose (GtkWidget      *widget,
         }
     }
 
-  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,
                     allocation.x,
                     allocation.y,
                     rect_w, rect_h);
 
-  cairo_destroy (cr);
-
   return TRUE;
 }
 
diff --git a/app/widgets/gimpfgbgview.c b/app/widgets/gimpfgbgview.c
index 8f6900a..06b1872 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]