[gimp/gtk3-port: 228/230] app: port GimpCircle and subclasses to GTK+ 3



commit 8e8a4d7d6b9477b4a92d5a61ca40e753ff28febe
Author: Michael Natterer <mitch gimp org>
Date:   Fri May 30 02:37:25 2014 +0200

    app: port GimpCircle and subclasses to GTK+ 3

 app/widgets/gimpcircle.c |  116 ++++++++++++++++++++++++---------------------
 app/widgets/gimpdial.c   |   53 +++++++++------------
 app/widgets/gimppolar.c  |   49 ++++++++-----------
 3 files changed, 106 insertions(+), 112 deletions(-)
---
diff --git a/app/widgets/gimpcircle.c b/app/widgets/gimpcircle.c
index 95d9a03..59d271b 100644
--- a/app/widgets/gimpcircle.c
+++ b/app/widgets/gimpcircle.c
@@ -56,35 +56,39 @@ struct _GimpCirclePrivate
 };
 
 
-static void        gimp_circle_dispose         (GObject              *object);
-static void        gimp_circle_set_property    (GObject              *object,
-                                                guint                 property_id,
-                                                const GValue         *value,
-                                                GParamSpec           *pspec);
-static void        gimp_circle_get_property    (GObject              *object,
-                                                guint                 property_id,
-                                                GValue               *value,
-                                                GParamSpec           *pspec);
-
-static void        gimp_circle_realize         (GtkWidget            *widget);
-static void        gimp_circle_unrealize       (GtkWidget            *widget);
-static void        gimp_circle_map             (GtkWidget            *widget);
-static void        gimp_circle_unmap           (GtkWidget            *widget);
-static void        gimp_circle_size_request    (GtkWidget            *widget,
-                                                GtkRequisition       *requisition);
-static void        gimp_circle_size_allocate   (GtkWidget            *widget,
-                                                GtkAllocation        *allocation);
-static gboolean    gimp_circle_expose_event    (GtkWidget            *widget,
-                                                GdkEventExpose       *event);
-
-static void        gimp_circle_background_hsv  (gdouble               angle,
-                                                gdouble               distance,
-                                                guchar               *rgb);
-
-static void        gimp_circle_draw_background (GimpCircle           *circle,
-                                                cairo_t              *cr,
-                                                gint                  size,
-                                                GimpCircleBackground  background);
+static void        gimp_circle_dispose              (GObject              *object);
+static void        gimp_circle_set_property         (GObject              *object,
+                                                     guint                 property_id,
+                                                     const GValue         *value,
+                                                     GParamSpec           *pspec);
+static void        gimp_circle_get_property         (GObject              *object,
+                                                     guint                 property_id,
+                                                     GValue               *value,
+                                                     GParamSpec           *pspec);
+
+static void        gimp_circle_realize              (GtkWidget            *widget);
+static void        gimp_circle_unrealize            (GtkWidget            *widget);
+static void        gimp_circle_map                  (GtkWidget            *widget);
+static void        gimp_circle_unmap                (GtkWidget            *widget);
+static void        gimp_circle_get_preferred_width  (GtkWidget            *widget,
+                                                     gint                 *minimum_width,
+                                                     gint                 *natural_width);
+static void        gimp_circle_get_preferred_height (GtkWidget            *widget,
+                                                     gint                 *minimum_height,
+                                                     gint                 *natural_height);
+static void        gimp_circle_size_allocate        (GtkWidget            *widget,
+                                                     GtkAllocation        *allocation);
+static gboolean    gimp_circle_draw                 (GtkWidget            *widget,
+                                                     cairo_t              *cr);
+
+static void        gimp_circle_background_hsv       (gdouble               angle,
+                                                     gdouble               distance,
+                                                     guchar               *rgb);
+
+static void        gimp_circle_draw_background      (GimpCircle           *circle,
+                                                     cairo_t              *cr,
+                                                     gint                  size,
+                                                     GimpCircleBackground  background);
 
 
 G_DEFINE_TYPE (GimpCircle, gimp_circle, GTK_TYPE_WIDGET)
@@ -106,9 +110,10 @@ gimp_circle_class_init (GimpCircleClass *klass)
   widget_class->unrealize            = gimp_circle_unrealize;
   widget_class->map                  = gimp_circle_map;
   widget_class->unmap                = gimp_circle_unmap;
-  widget_class->size_request         = gimp_circle_size_request;
+  widget_class->get_preferred_width  = gimp_circle_get_preferred_width;
+  widget_class->get_preferred_height = gimp_circle_get_preferred_height;
   widget_class->size_allocate        = gimp_circle_size_allocate;
-  widget_class->expose_event         = gimp_circle_expose_event;
+  widget_class->draw                 = gimp_circle_draw;
 
   g_object_class_install_property (object_class, PROP_SIZE,
                                    g_param_spec_int ("size",
@@ -288,13 +293,23 @@ gimp_circle_unmap (GtkWidget *widget)
 }
 
 static void
-gimp_circle_size_request (GtkWidget      *widget,
-                        GtkRequisition *requisition)
+gimp_circle_get_preferred_width (GtkWidget *widget,
+                                 gint      *minimum_width,
+                                 gint      *natural_width)
 {
   GimpCircle *circle = GIMP_CIRCLE (widget);
 
-  requisition->width  = 2 * circle->priv->border_width + circle->priv->size;
-  requisition->height = 2 * circle->priv->border_width + circle->priv->size;
+  *minimum_width = *natural_width = 2 * circle->priv->border_width + circle->priv->size;
+}
+
+static void
+gimp_circle_get_preferred_height (GtkWidget *widget,
+                                  gint      *minimum_height,
+                                  gint      *natural_height)
+{
+  GimpCircle *circle = GIMP_CIRCLE (widget);
+
+  *minimum_height = *natural_height = 2 * circle->priv->border_width + circle->priv->size;
 }
 
 static void
@@ -320,31 +335,24 @@ gimp_circle_size_allocate (GtkWidget     *widget,
 }
 
 static gboolean
-gimp_circle_expose_event (GtkWidget      *widget,
-                          GdkEventExpose *event)
+gimp_circle_draw (GtkWidget *widget,
+                  cairo_t   *cr)
 {
-  GimpCircle *circle = GIMP_CIRCLE (widget);
-
-  if (gtk_widget_is_drawable (widget))
-    {
-      GtkAllocation  allocation;
-      gint           size = circle->priv->size;
-      cairo_t       *cr;
+  GimpCircle    *circle = GIMP_CIRCLE (widget);
+  GtkAllocation  allocation;
+  gint           size = circle->priv->size;
 
-      cr = gdk_cairo_create (event->window);
-      gdk_cairo_region (cr, event->region);
-      cairo_clip (cr);
+  gtk_widget_get_allocation (widget, &allocation);
 
-      gtk_widget_get_allocation (widget, &allocation);
+  cairo_save (cr);
 
-      cairo_translate (cr,
-                       allocation.x + (allocation.width  - size) / 2,
-                       allocation.y + (allocation.height - size) / 2);
+  cairo_translate (cr,
+                   (allocation.width  - size) / 2,
+                   (allocation.height - size) / 2);
 
-      gimp_circle_draw_background (circle, cr, size, circle->priv->background);
+  gimp_circle_draw_background (circle, cr, size, circle->priv->background);
 
-      cairo_destroy (cr);
-    }
+  cairo_restore (cr);
 
   return FALSE;
 }
diff --git a/app/widgets/gimpdial.c b/app/widgets/gimpdial.c
index 02342aa..4b0301a 100644
--- a/app/widgets/gimpdial.c
+++ b/app/widgets/gimpdial.c
@@ -83,8 +83,8 @@ static void        gimp_dial_get_property         (GObject            *object,
                                                    GParamSpec         *pspec);
 
 static void        gimp_dial_unmap                (GtkWidget          *widget);
-static gboolean    gimp_dial_expose_event         (GtkWidget          *widget,
-                                                   GdkEventExpose     *event);
+static gboolean    gimp_dial_draw                 (GtkWidget          *widget,
+                                                   cairo_t            *cr);
 static gboolean    gimp_dial_button_press_event   (GtkWidget          *widget,
                                                    GdkEventButton     *bevent);
 static gboolean    gimp_dial_button_release_event (GtkWidget          *widget,
@@ -127,7 +127,7 @@ gimp_dial_class_init (GimpDialClass *klass)
   object_class->set_property         = gimp_dial_set_property;
 
   widget_class->unmap                = gimp_dial_unmap;
-  widget_class->expose_event         = gimp_dial_expose_event;
+  widget_class->draw                 = gimp_dial_draw;
   widget_class->button_press_event   = gimp_dial_button_press_event;
   widget_class->button_release_event = gimp_dial_button_release_event;
   widget_class->motion_notify_event  = gimp_dial_motion_notify_event;
@@ -264,41 +264,34 @@ gimp_dial_unmap (GtkWidget *widget)
 }
 
 static gboolean
-gimp_dial_expose_event (GtkWidget      *widget,
-                        GdkEventExpose *event)
+gimp_dial_draw (GtkWidget *widget,
+                cairo_t   *cr)
 {
-  GimpDial *dial = GIMP_DIAL (widget);
-
-  GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+  GimpDial      *dial = GIMP_DIAL (widget);
+  GtkAllocation  allocation;
+  gint           size;
 
-  if (gtk_widget_is_drawable (widget))
-    {
-      GtkAllocation  allocation;
-      gint           size;
-      cairo_t       *cr;
+  GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
 
-      g_object_get (widget,
-                    "size", &size,
-                    NULL);
+  g_object_get (widget,
+                "size", &size,
+                NULL);
 
-      cr = gdk_cairo_create (event->window);
-      gdk_cairo_region (cr, event->region);
-      cairo_clip (cr);
+  gtk_widget_get_allocation (widget, &allocation);
 
-      gtk_widget_get_allocation (widget, &allocation);
+  cairo_save (cr);
 
-      cairo_translate (cr,
-                       (gdouble) allocation.x + (allocation.width  - size) / 2.0,
-                       (gdouble) allocation.y + (allocation.height - size) / 2.0);
+  cairo_translate (cr,
+                   (allocation.width  - size) / 2.0,
+                   (allocation.height - size) / 2.0);
 
-      gimp_dial_draw_arrows (cr, size,
-                             dial->priv->alpha, dial->priv->beta,
-                             dial->priv->clockwise,
-                             dial->priv->target,
-                             dial->priv->draw_beta);
+  gimp_dial_draw_arrows (cr, size,
+                         dial->priv->alpha, dial->priv->beta,
+                         dial->priv->clockwise,
+                         dial->priv->target,
+                         dial->priv->draw_beta);
 
-      cairo_destroy (cr);
-    }
+  cairo_restore (cr);
 
   return FALSE;
 }
diff --git a/app/widgets/gimppolar.c b/app/widgets/gimppolar.c
index acd544f..06909e9 100644
--- a/app/widgets/gimppolar.c
+++ b/app/widgets/gimppolar.c
@@ -76,8 +76,8 @@ static void        gimp_polar_get_property         (GObject            *object,
                                                     GParamSpec         *pspec);
 
 static void        gimp_polar_unmap                (GtkWidget          *widget);
-static gboolean    gimp_polar_expose_event         (GtkWidget          *widget,
-                                                    GdkEventExpose     *event);
+static gboolean    gimp_polar_draw                 (GtkWidget          *widget,
+                                                    cairo_t            *cr);
 static gboolean    gimp_polar_button_press_event   (GtkWidget          *widget,
                                                     GdkEventButton     *bevent);
 static gboolean    gimp_polar_button_release_event (GtkWidget          *widget,
@@ -118,7 +118,7 @@ gimp_polar_class_init (GimpPolarClass *klass)
   object_class->set_property         = gimp_polar_set_property;
 
   widget_class->unmap                = gimp_polar_unmap;
-  widget_class->expose_event         = gimp_polar_expose_event;
+  widget_class->draw                 = gimp_polar_draw;
   widget_class->button_press_event   = gimp_polar_button_press_event;
   widget_class->button_release_event = gimp_polar_button_release_event;
   widget_class->motion_notify_event  = gimp_polar_motion_notify_event;
@@ -223,39 +223,32 @@ gimp_polar_unmap (GtkWidget *widget)
 }
 
 static gboolean
-gimp_polar_expose_event (GtkWidget      *widget,
-                         GdkEventExpose *event)
+gimp_polar_draw (GtkWidget *widget,
+                 cairo_t   *cr)
 {
-  GimpPolar *polar = GIMP_POLAR (widget);
-
-  GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+  GimpPolar     *polar = GIMP_POLAR (widget);
+  GtkAllocation  allocation;
+  gint           size;
 
-  if (gtk_widget_is_drawable (widget))
-    {
-      GtkAllocation  allocation;
-      gint           size;
-      cairo_t       *cr;
+  GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
 
-      g_object_get (widget,
-                    "size", &size,
-                    NULL);
+  g_object_get (widget,
+                "size", &size,
+                NULL);
 
-      cr = gdk_cairo_create (event->window);
-      gdk_cairo_region (cr, event->region);
-      cairo_clip (cr);
+  gtk_widget_get_allocation (widget, &allocation);
 
-      gtk_widget_get_allocation (widget, &allocation);
+  cairo_save (cr);
 
-      cairo_translate (cr,
-                       (gdouble) allocation.x + (allocation.width  - size) / 2.0,
-                       (gdouble) allocation.y + (allocation.height - size) / 2.0);
+  cairo_translate (cr,
+                   (allocation.width  - size) / 2.0,
+                   (allocation.height - size) / 2.0);
 
-      gimp_polar_draw_circle (cr, size,
-                              polar->priv->angle, polar->priv->radius,
-                              polar->priv->target);
+  gimp_polar_draw_circle (cr, size,
+                          polar->priv->angle, polar->priv->radius,
+                          polar->priv->target);
 
-      cairo_destroy (cr);
-    }
+  cairo_restore (cr);
 
   return FALSE;
 }


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