[gimp/gtk3-port: 188/224] libgimpwidgets: move all GimpOffsetArea members to a private struct



commit cc50140cfda776b9e711d031dc46ef78c0c4dc31
Author: Michael Natterer <mitch gimp org>
Date:   Wed Dec 29 16:49:38 2010 +0100

    libgimpwidgets: move all GimpOffsetArea members to a private struct

 libgimpwidgets/gimpoffsetarea.c |  218 ++++++++++++++++++++++++---------------
 libgimpwidgets/gimpoffsetarea.h |   15 +--
 2 files changed, 136 insertions(+), 97 deletions(-)
---
diff --git a/libgimpwidgets/gimpoffsetarea.c b/libgimpwidgets/gimpoffsetarea.c
index 470feb0..47a5ac2 100644
--- a/libgimpwidgets/gimpoffsetarea.c
+++ b/libgimpwidgets/gimpoffsetarea.c
@@ -48,6 +48,25 @@ enum
 };
 
 
+typedef struct _GimpOffsetAreaPrivate GimpOffsetAreaPrivate;
+
+struct _GimpOffsetAreaPrivate
+{
+  gint    orig_width;
+  gint    orig_height;
+  gint    width;
+  gint    height;
+  gint    offset_x;
+  gint    offset_y;
+  gdouble display_ratio_x;
+  gdouble display_ratio_y;
+};
+
+#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE (obj, \
+                                                      GIMP_TYPE_OFFSET_AREA, \
+                                                      GimpOffsetAreaPrivate)
+
+
 static void      gimp_offset_area_resize        (GimpOffsetArea *area);
 
 static void      gimp_offset_area_realize       (GtkWidget      *widget);
@@ -69,6 +88,7 @@ static guint gimp_offset_area_signals[LAST_SIGNAL] = { 0 };
 static void
 gimp_offset_area_class_init (GimpOffsetAreaClass *klass)
 {
+  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   gimp_offset_area_signals[OFFSETS_CHANGED] =
@@ -86,19 +106,23 @@ gimp_offset_area_class_init (GimpOffsetAreaClass *klass)
   widget_class->realize       = gimp_offset_area_realize;
   widget_class->event         = gimp_offset_area_event;
   widget_class->draw          = gimp_offset_area_draw;
+
+  g_type_class_add_private (object_class, sizeof (GimpOffsetAreaPrivate));
 }
 
 static void
 gimp_offset_area_init (GimpOffsetArea *area)
 {
-  area->orig_width      = 0;
-  area->orig_height     = 0;
-  area->width           = 0;
-  area->height          = 0;
-  area->offset_x        = 0;
-  area->offset_y        = 0;
-  area->display_ratio_x = 1.0;
-  area->display_ratio_y = 1.0;
+  GimpOffsetAreaPrivate *private = GET_PRIVATE (area);
+
+  private->orig_width      = 0;
+  private->orig_height     = 0;
+  private->width           = 0;
+  private->height          = 0;
+  private->offset_x        = 0;
+  private->offset_y        = 0;
+  private->display_ratio_x = 1.0;
+  private->display_ratio_y = 1.0;
 
   gtk_widget_add_events (GTK_WIDGET (area), GDK_BUTTON_PRESS_MASK);
 }
@@ -118,15 +142,18 @@ GtkWidget *
 gimp_offset_area_new (gint orig_width,
                       gint orig_height)
 {
-  GimpOffsetArea *area;
+  GimpOffsetArea        *area;
+  GimpOffsetAreaPrivate *private;
 
   g_return_val_if_fail (orig_width  > 0, NULL);
   g_return_val_if_fail (orig_height > 0, NULL);
 
   area = g_object_new (GIMP_TYPE_OFFSET_AREA, NULL);
 
-  area->orig_width  = area->width  = orig_width;
-  area->orig_height = area->height = orig_height;
+  private = GET_PRIVATE (area);
+
+  private->orig_width  = private->width  = orig_width;
+  private->orig_height = private->height = orig_height;
 
   gimp_offset_area_resize (area);
 
@@ -172,31 +199,39 @@ gimp_offset_area_set_size (GimpOffsetArea *area,
                            gint            width,
                            gint            height)
 {
+  GimpOffsetAreaPrivate *private;
+
   g_return_if_fail (GIMP_IS_OFFSET_AREA (area));
   g_return_if_fail (width > 0 && height > 0);
 
-  if (area->width != width || area->height != height)
+  private = GET_PRIVATE (area);
+
+  if (private->width != width || private->height != height)
     {
       gint offset_x;
       gint offset_y;
 
-      area->width  = width;
-      area->height = height;
+      private->width  = width;
+      private->height = height;
 
-      if (area->orig_width <= area->width)
-        offset_x = CLAMP (area->offset_x, 0, area->width - area->orig_width);
+      if (private->orig_width <= private->width)
+        offset_x = CLAMP (private->offset_x,
+                          0, private->width - private->orig_width);
       else
-        offset_x = CLAMP (area->offset_x, area->width - area->orig_width, 0);
+        offset_x = CLAMP (private->offset_x,
+                          private->width - private->orig_width, 0);
 
-      if (area->orig_height <= area->height)
-        offset_y = CLAMP (area->offset_y, 0, area->height - area->orig_height);
+      if (private->orig_height <= private->height)
+        offset_y = CLAMP (private->offset_y,
+                          0, private->height - private->orig_height);
       else
-        offset_y = CLAMP (area->offset_y, area->height - area->orig_height, 0);
+        offset_y = CLAMP (private->offset_y,
+                          private->height - private->orig_height, 0);
 
-      if (offset_x != area->offset_x || offset_y != area->offset_y)
+      if (offset_x != private->offset_x || offset_y != private->offset_y)
         {
-          area->offset_x = offset_x;
-          area->offset_y = offset_y;
+          private->offset_x = offset_x;
+          private->offset_y = offset_y;
 
           g_signal_emit (area,
                          gimp_offset_area_signals[OFFSETS_CHANGED], 0,
@@ -221,19 +256,27 @@ gimp_offset_area_set_offsets (GimpOffsetArea *area,
                               gint            offset_x,
                               gint            offset_y)
 {
+  GimpOffsetAreaPrivate *private;
+
   g_return_if_fail (GIMP_IS_OFFSET_AREA (area));
 
-  if (area->offset_x != offset_x || area->offset_y != offset_y)
+  private = GET_PRIVATE (area);
+
+  if (private->offset_x != offset_x || private->offset_y != offset_y)
     {
-      if (area->orig_width <= area->width)
-        area->offset_x = CLAMP (offset_x, 0, area->width - area->orig_width);
+      if (private->orig_width <= private->width)
+        private->offset_x = CLAMP (offset_x,
+                                   0, private->width - private->orig_width);
       else
-        area->offset_x = CLAMP (offset_x, area->width - area->orig_width, 0);
+        private->offset_x = CLAMP (offset_x,
+                                   private->width - private->orig_width, 0);
 
-      if (area->orig_height <= area->height)
-        area->offset_y = CLAMP (offset_y, 0, area->height - area->orig_height);
+      if (private->orig_height <= private->height)
+        private->offset_y = CLAMP (offset_y,
+                                   0, private->height - private->orig_height);
       else
-        area->offset_y = CLAMP (offset_y, area->height - area->orig_height, 0);
+        private->offset_y = CLAMP (offset_y,
+                                   private->height - private->orig_height, 0);
 
       gtk_widget_queue_draw (GTK_WIDGET (area));
     }
@@ -242,22 +285,23 @@ gimp_offset_area_set_offsets (GimpOffsetArea *area,
 static void
 gimp_offset_area_resize (GimpOffsetArea *area)
 {
-  gint    width;
-  gint    height;
-  gdouble ratio;
+  GimpOffsetAreaPrivate *private = GET_PRIVATE (area);
+  gint                   width;
+  gint                   height;
+  gdouble                ratio;
 
-  if (area->orig_width == 0 || area->orig_height == 0)
+  if (private->orig_width == 0 || private->orig_height == 0)
     return;
 
-  if (area->orig_width <= area->width)
-    width = area->width;
+  if (private->orig_width <= private->width)
+    width = private->width;
   else
-    width = area->orig_width * 2 - area->width;
+    width = private->orig_width * 2 - private->width;
 
-  if (area->orig_height <= area->height)
-    height = area->height;
+  if (private->orig_height <= private->height)
+    height = private->height;
   else
-    height = area->orig_height * 2 - area->height;
+    height = private->orig_height * 2 - private->height;
 
   ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) MAX (width, height);
 
@@ -272,20 +316,21 @@ static void
 gimp_offset_area_size_allocate (GtkWidget     *widget,
                                 GtkAllocation *allocation)
 {
-  GimpOffsetArea *area = GIMP_OFFSET_AREA (widget);
-  GdkPixbuf      *pixbuf;
+  GimpOffsetArea        *area    = GIMP_OFFSET_AREA (widget);
+  GimpOffsetAreaPrivate *private = GET_PRIVATE (area);
+  GdkPixbuf             *pixbuf;
 
   GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
 
-  area->display_ratio_x = ((gdouble) allocation->width /
-                           ((area->orig_width <= area->width) ?
-                            area->width :
-                            area->orig_width * 2 - area->width));
+  private->display_ratio_x = ((gdouble) allocation->width /
+                              ((private->orig_width <= private->width) ?
+                               private->width :
+                               private->orig_width * 2 - private->width));
 
-  area->display_ratio_y = ((gdouble) allocation->height /
-                           ((area->orig_height <= area->height) ?
-                            area->height :
-                            area->orig_height * 2 - area->height));
+  private->display_ratio_y = ((gdouble) allocation->height /
+                              ((private->orig_height <= private->height) ?
+                               private->height :
+                               private->orig_height * 2 - private->height));
 
   pixbuf = g_object_get_data (G_OBJECT (area), "pixbuf");
 
@@ -295,10 +340,10 @@ gimp_offset_area_size_allocate (GtkWidget     *widget,
       gint       pixbuf_width;
       gint       pixbuf_height;
 
-      pixbuf_width  = area->display_ratio_x * area->orig_width;
+      pixbuf_width  = private->display_ratio_x * private->orig_width;
       pixbuf_width  = MAX (pixbuf_width, 1);
 
-      pixbuf_height = area->display_ratio_y * area->orig_height;
+      pixbuf_height = private->display_ratio_y * private->orig_height;
       pixbuf_height = MAX (pixbuf_height, 1);
 
       copy = g_object_get_data (G_OBJECT (area), "pixbuf-copy");
@@ -343,11 +388,12 @@ gimp_offset_area_event (GtkWidget *widget,
   static gint start_x       = 0;
   static gint start_y       = 0;
 
-  GimpOffsetArea *area = GIMP_OFFSET_AREA (widget);
-  gint            offset_x;
-  gint            offset_y;
+  GimpOffsetArea        *area    = GIMP_OFFSET_AREA (widget);
+  GimpOffsetAreaPrivate *private = GET_PRIVATE (area);
+  gint                   offset_x;
+  gint                   offset_y;
 
-  if (area->orig_width == 0 || area->orig_height == 0)
+  if (private->orig_width == 0 || private->orig_height == 0)
     return FALSE;
 
   switch (event->type)
@@ -358,25 +404,25 @@ gimp_offset_area_event (GtkWidget *widget,
                          GDK_BUTTON_RELEASE_MASK),
                         NULL, NULL, event->button.time);
 
-      orig_offset_x = area->offset_x;
-      orig_offset_y = area->offset_y;
+      orig_offset_x = private->offset_x;
+      orig_offset_y = private->offset_y;
       start_x = event->button.x;
       start_y = event->button.y;
       break;
 
     case GDK_MOTION_NOTIFY:
       offset_x = (orig_offset_x +
-                  (event->motion.x - start_x) / area->display_ratio_x);
+                  (event->motion.x - start_x) / private->display_ratio_x);
       offset_y = (orig_offset_y +
-                  (event->motion.y - start_y) / area->display_ratio_y);
+                  (event->motion.y - start_y) / private->display_ratio_y);
 
-      if (area->offset_x != offset_x || area->offset_y != offset_y)
+      if (private->offset_x != offset_x || private->offset_y != offset_y)
         {
           gimp_offset_area_set_offsets (area, offset_x, offset_y);
 
           g_signal_emit (area,
                          gimp_offset_area_signals[OFFSETS_CHANGED], 0,
-                         area->offset_x, area->offset_y);
+                         private->offset_x, private->offset_y);
         }
       break;
 
@@ -397,29 +443,30 @@ static gboolean
 gimp_offset_area_draw (GtkWidget *widget,
                        cairo_t   *cr)
 {
-  GimpOffsetArea  *area    = GIMP_OFFSET_AREA (widget);
-  GtkStyleContext *context = gtk_widget_get_style_context (widget);
-  GtkAllocation    allocation;
-  GdkPixbuf       *pixbuf;
-  gint             w, h;
-  gint             x, y;
+  GimpOffsetArea        *area    = GIMP_OFFSET_AREA (widget);
+  GimpOffsetAreaPrivate *private = GET_PRIVATE (area);
+  GtkStyleContext       *context = gtk_widget_get_style_context (widget);
+  GtkAllocation          allocation;
+  GdkPixbuf             *pixbuf;
+  gint                   w, h;
+  gint                   x, y;
 
   gtk_widget_get_allocation (widget, &allocation);
 
-  x = (area->display_ratio_x *
-       ((area->orig_width <= area->width) ?
-        area->offset_x :
-        area->offset_x + area->orig_width - area->width));
+  x = (private->display_ratio_x *
+       ((private->orig_width <= private->width) ?
+        private->offset_x :
+        private->offset_x + private->orig_width - private->width));
 
-  y = (area->display_ratio_y *
-       ((area->orig_height <= area->height) ?
-        area->offset_y :
-        area->offset_y + area->orig_height - area->height));
+  y = (private->display_ratio_y *
+       ((private->orig_height <= private->height) ?
+        private->offset_y :
+        private->offset_y + private->orig_height - private->height));
 
-  w = area->display_ratio_x * area->orig_width;
+  w = private->display_ratio_x * private->orig_width;
   w = MAX (w, 1);
 
-  h = area->display_ratio_y * area->orig_height;
+  h = private->display_ratio_y * private->orig_height;
   h = MAX (h, 1);
 
   pixbuf = g_object_get_data (G_OBJECT (widget), "pixbuf-copy");
@@ -439,14 +486,15 @@ gimp_offset_area_draw (GtkWidget *widget,
       gtk_render_frame (context, cr, x, y, w, h);
     }
 
-  if (area->orig_width > area->width || area->orig_height > area->height)
+  if (private->orig_width > private->width ||
+      private->orig_height > private->height)
     {
       gint line_width;
 
-       if (area->orig_width > area->width)
+       if (private->orig_width > private->width)
         {
-          x = area->display_ratio_x * (area->orig_width - area->width);
-          w = area->display_ratio_x * area->width;
+          x = private->display_ratio_x * (private->orig_width - private->width);
+          w = private->display_ratio_x * private->width;
         }
       else
         {
@@ -454,10 +502,10 @@ gimp_offset_area_draw (GtkWidget *widget,
           w = allocation.width + 2;
         }
 
-      if (area->orig_height > area->height)
+      if (private->orig_height > private->height)
         {
-          y = area->display_ratio_y * (area->orig_height - area->height);
-          h = area->display_ratio_y * area->height;
+          y = private->display_ratio_y * (private->orig_height - private->height);
+          h = private->display_ratio_y * private->height;
         }
       else
         {
diff --git a/libgimpwidgets/gimpoffsetarea.h b/libgimpwidgets/gimpoffsetarea.h
index 561d23d..0ed9317 100644
--- a/libgimpwidgets/gimpoffsetarea.h
+++ b/libgimpwidgets/gimpoffsetarea.h
@@ -40,24 +40,15 @@ typedef struct _GimpOffsetAreaClass  GimpOffsetAreaClass;
 struct _GimpOffsetArea
 {
   GtkDrawingArea  parent_instance;
-
-  gint            orig_width;
-  gint            orig_height;
-  gint            width;
-  gint            height;
-  gint            offset_x;
-  gint            offset_y;
-  gdouble         display_ratio_x;
-  gdouble         display_ratio_y;
 };
 
 struct _GimpOffsetAreaClass
 {
   GtkDrawingAreaClass  parent_class;
 
-  void (* offsets_changed)  (GimpOffsetArea *offset_area,
-                             gint            offset_x,
-                             gint            offset_y);
+  void (* offsets_changed) (GimpOffsetArea *offset_area,
+                            gint            offset_x,
+                            gint            offset_y);
 
   /* Padding for future expansion */
   void (* _gimp_reserved1) (void);



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