[gimp/gtk3-port: 159/235] libgimpwidgets: move all GimpColorScale members to a private struct



commit 64edda814506456953c07db7c2fd9bb74c17d4ff
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jan 2 02:39:12 2011 +0100

    libgimpwidgets: move all GimpColorScale members to a private struct

 libgimpwidgets/gimpcolorscale.c |  240 +++++++++++++++++++++------------------
 libgimpwidgets/gimpcolorscale.h |   16 +---
 2 files changed, 134 insertions(+), 122 deletions(-)
---
diff --git a/libgimpwidgets/gimpcolorscale.c b/libgimpwidgets/gimpcolorscale.c
index c59fcb8..20ad9eb 100644
--- a/libgimpwidgets/gimpcolorscale.c
+++ b/libgimpwidgets/gimpcolorscale.c
@@ -66,9 +66,20 @@ typedef struct _GimpColorScalePrivate GimpColorScalePrivate;
 
 struct _GimpColorScalePrivate
 {
-  GimpColorConfig    *config;
-  GimpColorTransform *transform;
-  guchar              oog_color[3];
+  GimpColorConfig          *config;
+  GimpColorTransform       *transform;
+  guchar                    oog_color[3];
+
+  GimpColorSelectorChannel  channel;
+  GimpRGB                   rgb;
+  GimpHSV                   hsv;
+
+  guchar                   *buf;
+  guint                     width;
+  guint                     height;
+  guint                     rowstride;
+
+  gboolean                  needs_render;
 };
 
 #define GET_PRIVATE(obj) \
@@ -163,33 +174,24 @@ gimp_color_scale_class_init (GimpColorScaleClass *klass)
 }
 
 static void
-gimp_color_scale_dispose (GObject *object)
-{
-  GimpColorScale *scale = GIMP_COLOR_SCALE (object);
-
-  gimp_color_scale_set_color_config (scale, NULL);
-
-  G_OBJECT_CLASS (parent_class)->dispose (object);
-}
-
-static void
 gimp_color_scale_init (GimpColorScale *scale)
 {
-  GtkRange *range = GTK_RANGE (scale);
+  GimpColorScalePrivate *priv  = GET_PRIVATE (scale);
+  GtkRange              *range = GTK_RANGE (scale);
 
   gtk_range_set_slider_size_fixed (range, TRUE);
   gtk_range_set_flippable (GTK_RANGE (scale), TRUE);
 
   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
 
-  scale->channel      = GIMP_COLOR_SELECTOR_VALUE;
-  scale->needs_render = TRUE;
+  priv->channel      = GIMP_COLOR_SELECTOR_VALUE;
+  priv->needs_render = TRUE;
 
   gtk_orientable_set_orientation (GTK_ORIENTABLE (range),
                                   GTK_ORIENTATION_HORIZONTAL);
 
-  gimp_rgba_set (&scale->rgb, 0.0, 0.0, 0.0, 1.0);
-  gimp_rgb_to_hsv (&scale->rgb, &scale->hsv);
+  gimp_rgba_set (&priv->rgb, 0.0, 0.0, 0.0, 1.0);
+  gimp_rgb_to_hsv (&priv->rgb, &priv->hsv);
 
   gimp_widget_track_monitor (GTK_WIDGET (scale),
                              G_CALLBACK (gimp_color_scale_destroy_transform),
@@ -197,17 +199,27 @@ gimp_color_scale_init (GimpColorScale *scale)
 }
 
 static void
-gimp_color_scale_finalize (GObject *object)
+gimp_color_scale_dispose (GObject *object)
 {
   GimpColorScale *scale = GIMP_COLOR_SCALE (object);
 
-  if (scale->buf)
+  gimp_color_scale_set_color_config (scale, NULL);
+
+  G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+gimp_color_scale_finalize (GObject *object)
+{
+  GimpColorScalePrivate *priv = GET_PRIVATE (object);
+
+  if (priv->buf)
     {
-      g_free (scale->buf);
-      scale->buf       = NULL;
-      scale->width     = 0;
-      scale->height    = 0;
-      scale->rowstride = 0;
+      g_free (priv->buf);
+      priv->buf       = NULL;
+      priv->width     = 0;
+      priv->height    = 0;
+      priv->rowstride = 0;
     }
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -219,12 +231,12 @@ gimp_color_scale_get_property (GObject    *object,
                                GValue     *value,
                                GParamSpec *pspec)
 {
-  GimpColorScale *scale = GIMP_COLOR_SCALE (object);
+  GimpColorScalePrivate *priv = GET_PRIVATE (object);
 
   switch (property_id)
     {
     case PROP_CHANNEL:
-      g_value_set_enum (value, scale->channel);
+      g_value_set_enum (value, priv->channel);
       break;
 
     default:
@@ -257,13 +269,13 @@ static void
 gimp_color_scale_size_allocate (GtkWidget     *widget,
                                 GtkAllocation *allocation)
 {
-  GimpColorScale *scale = GIMP_COLOR_SCALE (widget);
-  GtkRange       *range = GTK_RANGE (widget);
-  GdkRectangle    range_rect;
-  gint            focus = 0;
-  gint            trough_border;
-  gint            scale_width;
-  gint            scale_height;
+  GimpColorScalePrivate *priv  = GET_PRIVATE (widget);
+  GtkRange              *range = GTK_RANGE (widget);
+  GdkRectangle           range_rect;
+  gint                   focus = 0;
+  gint                   trough_border;
+  gint                   scale_width;
+  gint                   scale_height;
 
   gtk_widget_style_get (widget,
                         "trough-border", &trough_border,
@@ -305,17 +317,17 @@ gimp_color_scale_size_allocate (GtkWidget     *widget,
       break;
     }
 
-  if (scale_width != scale->width || scale_height != scale->height)
+  if (scale_width != priv->width || scale_height != priv->height)
     {
-      scale->width  = scale_width;
-      scale->height = scale_height;
+      priv->width  = scale_width;
+      priv->height = scale_height;
 
-      scale->rowstride = scale->width * 4;
+      priv->rowstride = priv->width * 4;
 
-      g_free (scale->buf);
-      scale->buf = g_new (guchar, scale->rowstride * scale->height);
+      g_free (priv->buf);
+      priv->buf = g_new (guchar, priv->rowstride * priv->height);
 
-      scale->needs_render = TRUE;
+      priv->needs_render = TRUE;
     }
 }
 
@@ -326,7 +338,7 @@ gimp_color_scale_state_flags_changed (GtkWidget     *widget,
   if ((gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_INSENSITIVE) !=
       (previous_state & GTK_STATE_FLAG_INSENSITIVE))
     {
-      GIMP_COLOR_SCALE (widget)->needs_render = TRUE;
+      GET_PRIVATE (widget)->needs_render = TRUE;
     }
 
   if (GTK_WIDGET_CLASS (parent_class)->state_flags_changed)
@@ -435,7 +447,7 @@ gimp_color_scale_draw (GtkWidget *widget,
   gint                   x, y;
   gint                   w, h;
 
-  if (! scale->buf)
+  if (! priv->buf)
     return FALSE;
 
   gtk_style_context_save (context);
@@ -467,14 +479,14 @@ gimp_color_scale_draw (GtkWidget *widget,
 
   slider_size = gtk_range_get_min_slider_size (range) / 2;
 
-  if (scale->needs_render)
+  if (priv->needs_render)
     {
       gimp_color_scale_render (scale);
 
       if (! sensitive)
         gimp_color_scale_render_stipple (scale);
 
-      scale->needs_render = FALSE;
+      priv->needs_render = FALSE;
     }
 
   gtk_style_context_set_state (context, gtk_widget_get_state_flags (widget));
@@ -488,37 +500,37 @@ gimp_color_scale_draw (GtkWidget *widget,
   if (priv->transform)
     {
       const Babl *format = babl_format ("cairo-RGB24");
-      guchar     *buf    = g_new (guchar, scale->rowstride * scale->height);
-      guchar     *src    = scale->buf;
+      guchar     *buf    = g_new (guchar, priv->rowstride * priv->height);
+      guchar     *src    = priv->buf;
       guchar     *dest   = buf;
       gint        i;
 
-      for (i = 0; i < scale->height; i++)
+      for (i = 0; i < priv->height; i++)
         {
           gimp_color_transform_process_pixels (priv->transform,
                                                format, src,
                                                format, dest,
-                                               scale->width);
+                                               priv->width);
 
-          src  += scale->rowstride;
-          dest += scale->rowstride;
+          src  += priv->rowstride;
+          dest += priv->rowstride;
         }
 
       buffer = cairo_image_surface_create_for_data (buf,
                                                     CAIRO_FORMAT_RGB24,
-                                                    scale->width,
-                                                    scale->height,
-                                                    scale->rowstride);
+                                                    priv->width,
+                                                    priv->height,
+                                                    priv->rowstride);
       cairo_surface_set_user_data (buffer, NULL,
                                    buf, (cairo_destroy_func_t) g_free);
     }
   else
     {
-      buffer = cairo_image_surface_create_for_data (scale->buf,
+      buffer = cairo_image_surface_create_for_data (priv->buf,
                                                     CAIRO_FORMAT_RGB24,
-                                                    scale->width,
-                                                    scale->height,
-                                                    scale->rowstride);
+                                                    priv->width,
+                                                    priv->height,
+                                                    priv->rowstride);
     }
 
   switch (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)))
@@ -657,13 +669,17 @@ void
 gimp_color_scale_set_channel (GimpColorScale           *scale,
                               GimpColorSelectorChannel  channel)
 {
+  GimpColorScalePrivate *priv;
+
   g_return_if_fail (GIMP_IS_COLOR_SCALE (scale));
 
-  if (channel != scale->channel)
+  priv = GET_PRIVATE (scale);
+
+  if (channel != priv->channel)
     {
-      scale->channel = channel;
+      priv->channel = channel;
 
-      scale->needs_render = TRUE;
+      priv->needs_render = TRUE;
       gtk_widget_queue_draw (GTK_WIDGET (scale));
 
       g_object_notify (G_OBJECT (scale), "channel");
@@ -683,14 +699,18 @@ gimp_color_scale_set_color (GimpColorScale *scale,
                             const GimpRGB  *rgb,
                             const GimpHSV  *hsv)
 {
+  GimpColorScalePrivate *priv;
+
   g_return_if_fail (GIMP_IS_COLOR_SCALE (scale));
   g_return_if_fail (rgb != NULL);
   g_return_if_fail (hsv != NULL);
 
-  scale->rgb = *rgb;
-  scale->hsv = *hsv;
+  priv = GET_PRIVATE (scale);
+
+  priv->rgb = *rgb;
+  priv->hsv = *hsv;
 
-  scale->needs_render = TRUE;
+  priv->needs_render = TRUE;
   gtk_widget_queue_draw (GTK_WIDGET (scale));
 }
 
@@ -782,20 +802,20 @@ gimp_color_scale_render (GimpColorScale *scale)
   guchar                *buf;
   guchar                *d;
 
-  if ((buf = scale->buf) == NULL)
+  if ((buf = priv->buf) == NULL)
     return;
 
-  if (scale->channel == GIMP_COLOR_SELECTOR_ALPHA)
+  if (priv->channel == GIMP_COLOR_SELECTOR_ALPHA)
     {
       gimp_color_scale_render_alpha (scale);
       return;
     }
 
-  rgb = scale->rgb;
-  hsv = scale->hsv;
+  rgb = priv->rgb;
+  hsv = priv->hsv;
   babl_process (fish_rgb_to_lch, &rgb, &lch, 1);
 
-  switch (scale->channel)
+  switch (priv->channel)
     {
     case GIMP_COLOR_SELECTOR_HUE:        channel_value = &hsv.h; break;
     case GIMP_COLOR_SELECTOR_SATURATION: channel_value = &hsv.s; break;
@@ -811,7 +831,7 @@ gimp_color_scale_render (GimpColorScale *scale)
     case GIMP_COLOR_SELECTOR_LCH_HUE:       channel_value = &lch.h; break;
     }
 
-  switch (scale->channel)
+  switch (priv->channel)
     {
     case GIMP_COLOR_SELECTOR_HUE:
     case GIMP_COLOR_SELECTOR_SATURATION:
@@ -841,9 +861,9 @@ gimp_color_scale_render (GimpColorScale *scale)
   switch (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)))
     {
     case GTK_ORIENTATION_HORIZONTAL:
-      for (x = 0, d = buf; x < scale->width; x++, d += 4)
+      for (x = 0, d = buf; x < priv->width; x++, d += 4)
         {
-          gdouble value = (gdouble) x * multiplier / (gdouble) (scale->width - 1);
+          gdouble value = (gdouble) x * multiplier / (gdouble) (priv->width - 1);
           guchar  r, g, b;
 
           if (invert)
@@ -872,18 +892,18 @@ gimp_color_scale_render (GimpColorScale *scale)
           GIMP_CAIRO_RGB24_SET_PIXEL (d, r, g, b);
         }
 
-      d = buf + scale->rowstride;
-      for (y = 1; y < scale->height; y++)
+      d = buf + priv->rowstride;
+      for (y = 1; y < priv->height; y++)
         {
-          memcpy (d, buf, scale->rowstride);
-          d += scale->rowstride;
+          memcpy (d, buf, priv->rowstride);
+          d += priv->rowstride;
         }
       break;
 
     case GTK_ORIENTATION_VERTICAL:
-      for (y = 0; y < scale->height; y++)
+      for (y = 0; y < priv->height; y++)
         {
-          gdouble value = (gdouble) y * multiplier / (gdouble) (scale->height - 1);
+          gdouble value = (gdouble) y * multiplier / (gdouble) (priv->height - 1);
           guchar  r, g, b;
 
           if (invert)
@@ -909,12 +929,12 @@ gimp_color_scale_render (GimpColorScale *scale)
               gimp_rgb_get_uchar (&rgb, &r, &g, &b);
             }
 
-          for (x = 0, d = buf; x < scale->width; x++, d += 4)
+          for (x = 0, d = buf; x < priv->width; x++, d += 4)
             {
               GIMP_CAIRO_RGB24_SET_PIXEL (d, r, g, b);
             }
 
-          buf += scale->rowstride;
+          buf += priv->rowstride;
         }
       break;
     }
@@ -923,18 +943,19 @@ gimp_color_scale_render (GimpColorScale *scale)
 static void
 gimp_color_scale_render_alpha (GimpColorScale *scale)
 {
-  GtkRange *range = GTK_RANGE (scale);
-  GimpRGB   rgb;
-  gboolean  invert;
-  gdouble   a;
-  guint     x, y;
-  guchar   *buf;
-  guchar   *d, *l;
+  GimpColorScalePrivate *priv  = GET_PRIVATE (scale);
+  GtkRange              *range = GTK_RANGE (scale);
+  GimpRGB                rgb;
+  gboolean               invert;
+  gdouble                a;
+  guint                  x, y;
+  guchar                *buf;
+  guchar                *d, *l;
 
   invert = should_invert (range);
 
-  buf = scale->buf;
-  rgb = scale->rgb;
+  buf = priv->buf;
+  rgb = priv->rgb;
 
   switch (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)))
     {
@@ -945,10 +966,10 @@ gimp_color_scale_render_alpha (GimpColorScale *scale)
 
         light = buf;
         /* this won't work correctly for very thin scales */
-        dark  = (scale->height > GIMP_CHECK_SIZE_SM ?
-                 buf + GIMP_CHECK_SIZE_SM * scale->rowstride : light);
+        dark  = (priv->height > GIMP_CHECK_SIZE_SM ?
+                 buf + GIMP_CHECK_SIZE_SM * priv->rowstride : light);
 
-        for (x = 0, d = light, l = dark; x < scale->width; x++)
+        for (x = 0, d = light, l = dark; x < priv->width; x++)
           {
             if ((x % GIMP_CHECK_SIZE_SM) == 0)
               {
@@ -959,7 +980,7 @@ gimp_color_scale_render_alpha (GimpColorScale *scale)
                 l = t;
               }
 
-            a = (gdouble) x / (gdouble) (scale->width - 1);
+            a = (gdouble) x / (gdouble) (priv->width - 1);
 
             if (invert)
               a = 1.0 - a;
@@ -983,15 +1004,15 @@ gimp_color_scale_render_alpha (GimpColorScale *scale)
             d += 4;
           }
 
-        for (y = 0, d = buf; y < scale->height; y++, d += scale->rowstride)
+        for (y = 0, d = buf; y < priv->height; y++, d += priv->rowstride)
           {
             if (y == 0 || y == GIMP_CHECK_SIZE_SM)
               continue;
 
             if ((y / GIMP_CHECK_SIZE_SM) & 1)
-              memcpy (d, dark, scale->rowstride);
+              memcpy (d, dark, priv->rowstride);
             else
-              memcpy (d, light, scale->rowstride);
+              memcpy (d, light, priv->rowstride);
           }
       }
       break;
@@ -1001,9 +1022,9 @@ gimp_color_scale_render_alpha (GimpColorScale *scale)
         guchar  light[4] = {0xff, 0xff, 0xff, 0xff};
         guchar  dark[4] = {0xff, 0xff, 0xff, 0xff};
 
-        for (y = 0, d = buf; y < scale->height; y++, d += scale->rowstride)
+        for (y = 0, d = buf; y < priv->height; y++, d += priv->rowstride)
           {
-            a = (gdouble) y / (gdouble) (scale->height - 1);
+            a = (gdouble) y / (gdouble) (priv->height - 1);
 
             if (invert)
               a = 1.0 - a;
@@ -1024,7 +1045,7 @@ gimp_color_scale_render_alpha (GimpColorScale *scale)
                                         (GIMP_CHECK_DARK +
                                          (rgb.b - GIMP_CHECK_DARK) * a) * 255.999);
 
-            for (x = 0, l = d; x < scale->width; x++, l += 4)
+            for (x = 0, l = d; x < priv->width; x++, l += 4)
               {
                 if (((x / GIMP_CHECK_SIZE_SM) ^ (y / GIMP_CHECK_SIZE_SM)) & 1)
                   {
@@ -1054,13 +1075,16 @@ gimp_color_scale_render_alpha (GimpColorScale *scale)
 static void
 gimp_color_scale_render_stipple (GimpColorScale *scale)
 {
-  GtkWidget *widget = GTK_WIDGET (scale);
-  GtkStyle  *style  = gtk_widget_get_style (widget);
-  guchar    *buf;
-  guchar     insensitive[4] = {0xff, 0xff, 0xff, 0xff};
-  guint      x, y;
+  GimpColorScalePrivate *priv    = GET_PRIVATE (scale);
+  GtkWidget             *widget  = GTK_WIDGET (scale);
+  GtkStyleContext       *context = gtk_widget_get_style_context (widget);
+  GdkRGBA                color;
+  guchar                 r, g, b;
+  guchar                *buf;
+  guchar                 insensitive[4];
+  guint                  x, y;
 
-  if ((buf = scale->buf) == NULL)
+  if ((buf = priv->buf) == NULL)
     return;
 
   gtk_style_context_get_background_color (context,
@@ -1070,11 +1094,11 @@ gimp_color_scale_render_stipple (GimpColorScale *scale)
 
   GIMP_CAIRO_RGB24_SET_PIXEL (insensitive, r, g, b);
 
-  for (y = 0; y < scale->height; y++, buf += scale->rowstride)
+  for (y = 0; y < priv->height; y++, buf += priv->rowstride)
     {
       guchar *d = buf + 4 * (y % 2);
 
-      for (x = 0; x < scale->width - (y % 2); x += 2, d += 8)
+      for (x = 0; x < priv->width - (y % 2); x += 2, d += 8)
         {
           d[0] = insensitive[0];
           d[1] = insensitive[1];
@@ -1133,5 +1157,5 @@ gimp_color_scale_notify_config (GimpColorConfig  *config,
                       priv->oog_color,
                       priv->oog_color + 1,
                       priv->oog_color + 2);
-  scale->needs_render = TRUE;
+  priv->needs_render = TRUE;
 }
diff --git a/libgimpwidgets/gimpcolorscale.h b/libgimpwidgets/gimpcolorscale.h
index e6e1c3e..aede7cd 100644
--- a/libgimpwidgets/gimpcolorscale.h
+++ b/libgimpwidgets/gimpcolorscale.h
@@ -42,24 +42,12 @@ typedef struct _GimpColorScaleClass  GimpColorScaleClass;
 
 struct _GimpColorScale
 {
-  GtkScale                  parent_instance;
-
-  /*< private >*/
-  GimpColorSelectorChannel  channel;
-  GimpRGB                   rgb;
-  GimpHSV                   hsv;
-
-  guchar                   *buf;
-  guint                     width;
-  guint                     height;
-  guint                     rowstride;
-
-  gboolean                  needs_render;
+  GtkScale  parent_instance;
 };
 
 struct _GimpColorScaleClass
 {
-  GtkScaleClass             parent_class;
+  GtkScaleClass  parent_class;
 
   /* Padding for future expansion */
   void (* _gimp_reserved1) (void);


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