[gimp/gtk3-port: 159/233] libgimpwidgets: move all GimpColorScale members to a private struct
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gtk3-port: 159/233] libgimpwidgets: move all GimpColorScale members to a private struct
- Date: Thu, 8 Sep 2016 17:45:16 +0000 (UTC)
commit b5758a00ce9832106b8626f7d1c3db7a84ddf126
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 | 259 +++++++++++++++++++++------------------
libgimpwidgets/gimpcolorscale.h | 16 +--
2 files changed, 144 insertions(+), 131 deletions(-)
---
diff --git a/libgimpwidgets/gimpcolorscale.c b/libgimpwidgets/gimpcolorscale.c
index d8f51a2..315ffed 100644
--- a/libgimpwidgets/gimpcolorscale.c
+++ b/libgimpwidgets/gimpcolorscale.c
@@ -58,8 +58,19 @@ typedef struct _GimpColorScalePrivate GimpColorScalePrivate;
struct _GimpColorScalePrivate
{
- GimpColorConfig *config;
- GimpColorTransform *transform;
+ GimpColorConfig *config;
+ GimpColorTransform *transform;
+
+ GimpColorSelectorChannel channel;
+ GimpRGB rgb;
+ GimpHSV hsv;
+
+ guchar *buf;
+ guint width;
+ guint height;
+ guint rowstride;
+
+ gboolean needs_render;
};
#define GET_PRIVATE(obj) \
@@ -138,33 +149,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),
@@ -172,17 +174,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);
@@ -194,12 +206,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:
@@ -232,13 +244,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,
@@ -280,17 +292,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;
}
}
@@ -301,7 +313,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)
@@ -374,7 +386,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);
@@ -406,14 +418,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));
@@ -427,37 +439,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)))
@@ -596,13 +608,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");
@@ -622,14 +638,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));
}
@@ -705,29 +725,30 @@ should_invert (GtkRange *range)
static void
gimp_color_scale_render (GimpColorScale *scale)
{
- GtkRange *range = GTK_RANGE (scale);
- GimpRGB rgb;
- GimpHSV hsv;
- guint x, y;
- gdouble *channel_value = NULL; /* shut up compiler */
- gboolean to_rgb = FALSE;
- gboolean invert;
- guchar *buf;
- guchar *d;
-
- if ((buf = scale->buf) == NULL)
+ GimpColorScalePrivate *priv = GET_PRIVATE (scale);
+ GtkRange *range = GTK_RANGE (scale);
+ GimpRGB rgb;
+ GimpHSV hsv;
+ guint x, y;
+ gdouble *channel_value = NULL; /* shut up compiler */
+ gboolean to_rgb = FALSE;
+ gboolean invert;
+ guchar *buf;
+ guchar *d;
+
+ 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;
- 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;
@@ -738,7 +759,7 @@ gimp_color_scale_render (GimpColorScale *scale)
case GIMP_COLOR_SELECTOR_ALPHA: channel_value = &rgb.a; break;
}
- switch (scale->channel)
+ switch (priv->channel)
{
case GIMP_COLOR_SELECTOR_HUE:
case GIMP_COLOR_SELECTOR_SATURATION:
@@ -755,9 +776,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 / (gdouble) (scale->width - 1);
+ gdouble value = (gdouble) x / (gdouble) (priv->width - 1);
guchar r, g, b;
if (invert)
@@ -773,18 +794,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 / (gdouble) (scale->height - 1);
+ gdouble value = (gdouble) y / (gdouble) (priv->height - 1);
guchar r, g, b;
if (invert)
@@ -797,12 +818,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;
}
@@ -811,18 +832,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)))
{
@@ -833,10 +855,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)
{
@@ -847,7 +869,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;
@@ -871,15 +893,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;
@@ -889,9 +911,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;
@@ -912,7 +934,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)
{
@@ -942,13 +964,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;
-
- if ((buf = scale->buf) == NULL)
+ 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 = priv->buf) == NULL)
return;
gtk_style_context_get_background_color (context,
@@ -958,11 +983,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];
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]