Commit e779cf0b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

added "has_alpha" to GimpParamSpecRGB. Made the GimpParamSpecRGB struct

2006-04-27  Sven Neumann  <sven@gimp.org>

	* libgimpcolor/gimprgb.[ch]: added "has_alpha" to GimpParamSpecRGB.
	Made the GimpParamSpecRGB struct public. When validating a color,
	only look at the alpha channel if has_alpha is set.

	* libgimpconfig/gimpconfig-params.h: added "has_alpha" to
	GIMP_CONFIG_INSTALL_PROP_RGB macro definition.

	* libgimpconfig/gimpconfig-serialize.c: serialize color values as
	"(rgb r g b)" if the param-spec indicates that the alpha channel
	is meaningless.

	* app/config/gimpconfig-dump.c: take "has_alpha" into account when
	documenting color properties.

	* app/core/gimpcontext.c
	* app/core/gimpgrid.c
	* app/display/gimpdisplayoptions.c
	* app/text/gimptext.c
	* app/widgets/gimpaction.c
	* app/widgets/gimpcolorbar.c
	* libgimpwidgets/gimpcolorarea.c
	* libgimpwidgets/gimpcolorbutton.c: specify whether color properties
	have an alpha channel.

	* tools/pdbgen/app.pl: handle "has_alpha" for color paramaters.

	* tools/pdbgen/pdb/channel.pdb
	* tools/pdbgen/pdb/context.pdb
	* tools/pdbgen/pdb/grid.pdb
	* tools/pdbgen/pdb/image.pdb: set the "has_alpha" flag where
	appropriate.

	* app/pdb/gimp-pdb-compat.c (gimp_pdb_compat_param_spec): set
	"has_alpha" to TRUE for GIMP_PDB_COLOR.

	* app/pdb/channel_cmds.c
	* app/pdb/context_cmds.c
	* app/pdb/gradient_cmds.c
	* app/pdb/grid_cmds.c
	* app/pdb/image_cmds.c
	* app/pdb/palette_cmds.c
	* app/pdb/palettes_cmds.c
	* app/pdb/selection_tools_cmds.c: regenerated.

	* app/config/gimpdisplayconfig.c (gimp_display_config_class_init):
	removed unused code.
parent 5c1d95ce
2006-04-27 Sven Neumann <sven@gimp.org>
* libgimpcolor/gimprgb.[ch]: added "has_alpha" to GimpParamSpecRGB.
Made the GimpParamSpecRGB struct public. When validating a color,
only look at the alpha channel if has_alpha is set.
* libgimpconfig/gimpconfig-params.h: added "has_alpha" to
GIMP_CONFIG_INSTALL_PROP_RGB macro definition.
* libgimpconfig/gimpconfig-serialize.c: serialize color values as
"(rgb r g b)" if the param-spec indicates that the alpha channel
is meaningless.
* app/config/gimpconfig-dump.c: take "has_alpha" into account when
documenting color properties.
* app/core/gimpcontext.c
* app/core/gimpgrid.c
* app/display/gimpdisplayoptions.c
* app/text/gimptext.c
* app/widgets/gimpaction.c
* app/widgets/gimpcolorbar.c
* libgimpwidgets/gimpcolorarea.c
* libgimpwidgets/gimpcolorbutton.c: specify whether color properties
have an alpha channel.
* tools/pdbgen/app.pl: handle "has_alpha" for color paramaters.
* tools/pdbgen/pdb/channel.pdb
* tools/pdbgen/pdb/context.pdb
* tools/pdbgen/pdb/grid.pdb
* tools/pdbgen/pdb/image.pdb: set the "has_alpha" flag where
appropriate.
* app/pdb/gimp-pdb-compat.c (gimp_pdb_compat_param_spec): set
"has_alpha" to TRUE for GIMP_PDB_COLOR.
* app/pdb/channel_cmds.c
* app/pdb/context_cmds.c
* app/pdb/gradient_cmds.c
* app/pdb/grid_cmds.c
* app/pdb/image_cmds.c
* app/pdb/palette_cmds.c
* app/pdb/palettes_cmds.c
* app/pdb/selection_tools_cmds.c: regenerated.
* app/config/gimpdisplayconfig.c (gimp_display_config_class_init):
removed unused code.
2006-04-27 Sven Neumann <sven@gimp.org>
* libgimpcolor/gimprgb.h: indentation.
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpConfig object property dumper.
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
* Copyright (C) 2001-2006 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -322,12 +322,9 @@ static const gchar display_format_description[] =
static gchar *
dump_describe_param (GParamSpec *param_spec)
{
GType type;
const gchar *blurb;
const gchar *blurb = g_param_spec_get_blurb (param_spec);
const gchar *values = NULL;
blurb = g_param_spec_get_blurb (param_spec);
if (!blurb)
{
g_warning ("FIXME: Property '%s' has no blurb.", param_spec->name);
......@@ -336,15 +333,18 @@ dump_describe_param (GParamSpec *param_spec)
param_spec->name);
}
type = param_spec->value_type;
if (g_type_is_a (type, GIMP_TYPE_RGB))
if (GIMP_IS_PARAM_SPEC_RGB (param_spec))
{
values =
"The color is specified in the form (color-rgba red green blue alpha) "
"with channel values as floats between 0.0 and 1.0.";
if (GIMP_PARAM_SPEC_RGB (param_spec)->has_alpha)
values =
"The color is specified in the form (color-rgba red green blue "
"alpha) with channel values as floats between 0.0 and 1.0.";
else
values =
"The color is specified in the form (color-rgb red green blue) "
"with channel values as floats between 0.0 and 1.0.";
}
else if (g_type_is_a (type, GIMP_TYPE_MEMSIZE))
else if (GIMP_IS_PARAM_SPEC_MEMSIZE (param_spec))
{
values =
"The integer size can contain a suffix of 'B', 'K', 'M' or 'G' which "
......@@ -352,7 +352,7 @@ dump_describe_param (GParamSpec *param_spec)
"megabytes or gigabytes. If no suffix is specified the size defaults "
"to being specified in kilobytes.";
}
else if (g_type_is_a (type, GIMP_TYPE_CONFIG_PATH))
else if (GIMP_IS_PARAM_SPEC_CONFIG_PATH (param_spec))
{
switch (gimp_param_spec_config_path_type (param_spec))
{
......@@ -395,19 +395,19 @@ dump_describe_param (GParamSpec *param_spec)
break;
}
}
else if (g_type_is_a (type, GIMP_TYPE_UNIT))
else if (GIMP_IS_PARAM_SPEC_UNIT (param_spec))
{
values =
"The unit can be one inches, millimeters, points or picas plus "
"those in your user units database.";
}
else if (g_type_is_a (type, GIMP_TYPE_CONFIG))
else if (g_type_is_a (param_spec->value_type, GIMP_TYPE_CONFIG))
{
values = "This is a parameter list.";
}
else
{
switch (G_TYPE_FUNDAMENTAL (type))
switch (G_TYPE_FUNDAMENTAL (param_spec->value_type))
{
case G_TYPE_BOOLEAN:
values = "Possible values are yes and no.";
......@@ -442,7 +442,7 @@ dump_describe_param (GParamSpec *param_spec)
GString *str;
gint i;
enum_class = g_type_class_peek (type);
enum_class = g_type_class_peek (param_spec->value_type);
str = g_string_new (blurb);
......@@ -477,7 +477,8 @@ dump_describe_param (GParamSpec *param_spec)
}
if (!values)
g_warning ("FIXME: Can't tell anything about a %s.", g_type_name (type));
g_warning ("FIXME: Can't tell anything about a %s.",
g_type_name (param_spec->value_type));
return g_strdup_printf ("%s %s", blurb, values);
}
......
......@@ -23,7 +23,6 @@
#include <glib-object.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
......@@ -97,16 +96,11 @@ static void
gimp_display_config_class_init (GimpDisplayConfigClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpRGB white;
GimpRGB black;
object_class->finalize = gimp_display_config_finalize;
object_class->set_property = gimp_display_config_set_property;
object_class->get_property = gimp_display_config_get_property;
gimp_rgba_set (&white, 1.0, 1.0, 1.0, 1.0);
gimp_rgba_set (&black, 0.0, 0.0, 0.0, 1.0);
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_TRANSPARENCY_SIZE,
"transparency-size", TRANSPARENCY_SIZE_BLURB,
GIMP_TYPE_CHECK_SIZE,
......
......@@ -580,13 +580,13 @@ gimp_context_class_init (GimpContextClass *klass)
GIMP_CONFIG_INSTALL_PROP_RGB (object_class, GIMP_CONTEXT_PROP_FOREGROUND,
gimp_context_prop_names[GIMP_CONTEXT_PROP_FOREGROUND],
NULL,
FALSE, NULL,
&black,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_RGB (object_class, GIMP_CONTEXT_PROP_BACKGROUND,
gimp_context_prop_names[GIMP_CONTEXT_PROP_BACKGROUND],
NULL,
FALSE, NULL,
&white,
GIMP_PARAM_STATIC_STRINGS);
......
......@@ -89,13 +89,13 @@ gimp_grid_class_init (GimpGridClass *klass)
GIMP_CONFIG_INSTALL_PROP_RGB (object_class, PROP_FGCOLOR,
"fgcolor",
N_("The foreground color of the grid."),
&black,
TRUE, &black,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_RGB (object_class, PROP_BGCOLOR,
"bgcolor",
N_("The background color of the grid; "
"only used in double dashed line style."),
&white,
TRUE, &white,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_XSPACING,
"xspacing",
......
......@@ -135,7 +135,7 @@ gimp_display_options_class_init (GimpDisplayOptionsClass *klass)
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_RGB (object_class, PROP_PADDING_COLOR,
"padding-color", CANVAS_PADDING_COLOR_BLURB,
&white,
FALSE, &white,
GIMP_PARAM_STATIC_STRINGS);
}
......@@ -193,7 +193,7 @@ gimp_display_options_fullscreen_class_init (GimpDisplayOptionsFullscreenClass *k
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_RGB (object_class, PROP_PADDING_COLOR,
"padding-color", CANVAS_PADDING_COLOR_BLURB,
&black,
FALSE, &black,
GIMP_PARAM_STATIC_STRINGS);
}
......
......@@ -290,6 +290,7 @@ channel_get_color_invoker (GimpProcedure *procedure,
if (success)
{
gimp_channel_get_color (channel, &color);
gimp_rgb_set_alpha (&color, 1.0);
}
return_vals = gimp_procedure_get_return_values (procedure, success);
......@@ -378,6 +379,7 @@ register_channel_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The channel compositing color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
......@@ -641,6 +643,7 @@ register_channel_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The channel compositing color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......@@ -669,6 +672,7 @@ register_channel_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The new channel compositing color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......
......@@ -131,6 +131,7 @@ context_get_foreground_invoker (GimpProcedure *procedure,
GimpRGB foreground = { 0.0, 0.0, 0.0, 1.0 };
gimp_context_get_foreground (context, &foreground);
gimp_rgb_set_alpha (&foreground, 1.0);
return_vals = gimp_procedure_get_return_values (procedure, TRUE);
gimp_value_set_rgb (&return_vals->values[1], &foreground);
......@@ -170,6 +171,7 @@ context_get_background_invoker (GimpProcedure *procedure,
GimpRGB background = { 0.0, 0.0, 0.0, 1.0 };
gimp_context_get_background (context, &background);
gimp_rgb_set_alpha (&background, 1.0);
return_vals = gimp_procedure_get_return_values (procedure, TRUE);
gimp_value_set_rgb (&return_vals->values[1], &background);
......@@ -656,6 +658,7 @@ register_context_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("foreground",
"foreground",
"The foreground color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......@@ -678,6 +681,7 @@ register_context_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("foreground",
"foreground",
"The foreground color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......@@ -700,6 +704,7 @@ register_context_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("background",
"background",
"The background color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......@@ -722,6 +727,7 @@ register_context_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("background",
"background",
"The background color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......
......@@ -104,7 +104,7 @@ gimp_pdb_compat_param_spec (Gimp *gimp,
case GIMP_PDB_COLOR:
pspec = gimp_param_spec_rgb (name, name, desc,
NULL,
TRUE, NULL,
G_PARAM_READWRITE);
break;
......
......@@ -1610,6 +1610,7 @@ register_gradient_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The return color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
......@@ -1651,6 +1652,7 @@ register_gradient_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The color to set",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
......@@ -1692,6 +1694,7 @@ register_gradient_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The return color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
......@@ -1733,6 +1736,7 @@ register_gradient_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The color to set",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
......
......@@ -519,6 +519,7 @@ register_grid_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("fgcolor",
"fgcolor",
"The image's grid foreground color",
TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......@@ -547,6 +548,7 @@ register_grid_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("fgcolor",
"fgcolor",
"The new foreground color",
TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......@@ -575,6 +577,7 @@ register_grid_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("bgcolor",
"bgcolor",
"The image's grid background color",
TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......@@ -603,6 +606,7 @@ register_grid_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("bgcolor",
"bgcolor",
"The new background color",
TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......
......@@ -2842,6 +2842,7 @@ register_image_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The return color",
TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......
......@@ -842,6 +842,7 @@ register_palette_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The new entry's color color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
......@@ -912,6 +913,7 @@ register_palette_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The color requested",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......@@ -947,6 +949,7 @@ register_palette_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The new color",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......
......@@ -304,6 +304,7 @@ register_palettes_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The color requested",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
......
......@@ -280,6 +280,7 @@ register_selection_tools_procs (GimpPDB *pdb)
gimp_param_spec_rgb ("color",
"color",
"The color to select",
FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
......
......@@ -156,7 +156,7 @@ gimp_text_class_init (GimpTextClass *klass)
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_RGB (object_class, PROP_COLOR,
"color", NULL,
&black,
FALSE, &black,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_OUTLINE,
"outline", NULL,
......
......@@ -85,7 +85,7 @@ gimp_action_class_init (GimpActionClass *klass)
g_object_class_install_property (object_class, PROP_COLOR,
gimp_param_spec_rgb ("color",
NULL, NULL,
&black,
TRUE, &black,
GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_VIEWABLE,
......
......@@ -77,7 +77,7 @@ gimp_color_bar_class_init (GimpColorBarClass *klass)
g_object_class_install_property (object_class, PROP_COLOR,
gimp_param_spec_rgb ("color",
NULL, NULL,
&white,
FALSE, &white,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_ORIENTATION,
......
......@@ -331,8 +331,6 @@ gimp_rgb_composite (GimpRGB *color1,
const GimpRGB *color2,
GimpRGBCompositeMode mode)
{
gdouble factor;
g_return_if_fail (color1 != NULL);
g_return_if_fail (color2 != NULL);
......@@ -349,7 +347,8 @@ gimp_rgb_composite (GimpRGB *color1,
}
else
{
factor = color1->a * (1.0 - color2->a);
gdouble factor = color1->a * (1.0 - color2->a);
color1->r = color1->r * factor + color2->r * color2->a;
color1->g = color1->g * factor + color2->g * color2->a;
color1->b = color1->b * factor + color2->b * color2->a;
......@@ -361,7 +360,8 @@ gimp_rgb_composite (GimpRGB *color1,
/* put color2 below color1 */
if (color1->a < 1.0)
{
factor = color2->a * (1.0 - color1->a);
gdouble factor = color2->a * (1.0 - color1->a);
color1->r = color2->r * factor + color1->r * color1->a;
color1->g = color2->g * factor + color1->g * color1->a;
color1->b = color2->b * factor + color1->b * color1->a;
......@@ -497,8 +497,6 @@ gimp_rgba_distance (const GimpRGB *rgba1,
* GIMP_TYPE_PARAM_RGB
*/
#define GIMP_PARAM_SPEC_RGB(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_RGB, GimpParamSpecRGB))
static void gimp_param_rgb_class_init (GParamSpecClass *class);
static void gimp_param_rgb_init (GParamSpec *pspec);
static void gimp_param_rgb_set_default (GParamSpec *pspec,
......@@ -509,15 +507,6 @@ static gint gimp_param_rgb_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2);
typedef struct _GimpParamSpecRGB GimpParamSpecRGB;
struct _GimpParamSpecRGB
{
GParamSpecBoxed parent_instance;
GimpRGB default_value;
};
/**
* gimp_param_rgb_get_type:
*
......@@ -583,22 +572,18 @@ static gboolean
gimp_param_rgb_validate (GParamSpec *pspec,
GValue *value)
{
GimpRGB *rgb;
rgb = value->data[0].v_pointer;
GimpRGB *rgb = value->data[0].v_pointer;
if (rgb)
{
GimpRGB oval;
oval = *rgb;
GimpRGB oval = *rgb;
gimp_rgb_clamp (rgb);
return (oval.r != rgb->r ||
oval.g != rgb->g ||
oval.b != rgb->b ||
oval.a != rgb->a);
(GIMP_PARAM_SPEC_RGB (pspec)->has_alpha && oval.a != rgb->a));
}
return FALSE;
......@@ -609,32 +594,47 @@ gimp_param_rgb_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2)
{
GimpRGB *rgb1;
GimpRGB *rgb2;
rgb1 = value1->data[0].v_pointer;
rgb2 = value2->data[0].v_pointer;
GimpRGB *rgb1 = value1->data[0].v_pointer;
GimpRGB *rgb2 = value2->data[0].v_pointer;
/* try to return at least *something*, it's useless anyway... */
if (! rgb1)
return rgb2 != NULL ? -1 : 0;
{
return rgb2 != NULL ? -1 : 0;
}
else if (! rgb2)
return rgb1 != NULL;
{
return rgb1 != NULL;
}
else
{
guint32 int1, int2;
gimp_rgba_get_uchar (rgb1,
((guchar *) &int1) + 0,
((guchar *) &int1) + 1,
((guchar *) &int1) + 2,
((guchar *) &int1) + 3);
gimp_rgba_get_uchar (rgb2,
((guchar *) &int2) + 0,
((guchar *) &int2) + 1,
((guchar *) &int2) + 2,
((guchar *) &int2) + 3);
if (GIMP_PARAM_SPEC_RGB (pspec)->has_alpha)
{
gimp_rgba_get_uchar (rgb1,
((guchar *) &int1) + 0,
((guchar *) &int1) + 1,
((guchar *) &int1) + 2,
((guchar *) &int1) + 3);
gimp_rgba_get_uchar (rgb2,
((guchar *) &int2) + 0,
((guchar *) &int2) + 1,
((guchar *) &int2) + 2,
((guchar *) &int2) + 3);
}
else
{
gimp_rgb_get_uchar (rgb1,
((guchar *) &int1) + 0,
((guchar *) &int1) + 1,
((guchar *) &int1) + 2);
gimp_rgb_get_uchar (rgb2,
((guchar *) &int2) + 0,
((guchar *) &int2) + 1,
((guchar *) &int2) + 2);
}
return int1 - int2;
}
......@@ -645,6 +645,7 @@ gimp_param_rgb_values_cmp (GParamSpec *pspec,
* @name: Canonical name of the param
* @nick: Nickname of the param
* @blurb: Brief desciption of param.
* @has_alpha: %TRUE if the alpha channel has relevance.
* @default_value: Value to use if none is assigned.
* @flags: a combination of #GParamFlags
*
......@@ -659,6 +660,7 @@ GParamSpec *
gimp_param_spec_rgb (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean has_alpha,
const GimpRGB *default_value,
GParamFlags flags)
{
......@@ -667,6 +669,8 @@ gimp_param_spec_rgb (const gchar *name,
cspec = g_param_spec_internal (GIMP_TYPE_PARAM_RGB,
name, nick, blurb, flags);
cspec->has_alpha = has_alpha;
if (default_value)
cspec->default_value = *default_value;
......
......@@ -46,12 +46,25 @@ void gimp_value_set_rgb (GValue *value,
#define GIMP_TYPE_PARAM_RGB (gimp_param_rgb_get_type ())
#define GIMP_IS_PARAM_SPEC_RGB(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_RGB))
#define GIMP_PARAM_SPEC_RGB(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_RGB, GimpParamSpecRGB))
typedef struct _GimpParamSpecRGB GimpParamSpecRGB;
struct _GimpParamSpecRGB
{
GParamSpecBoxed parent_instance;
gboolean has_alpha;
GimpRGB default_value;
};
GType gimp_param_rgb_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_rgb (const gchar *name,
const gchar *nick,
const gchar *blurb,
gboolean has_alpha,
const GimpRGB *default_value,
GParamFlags flags);
......
......@@ -65,10 +65,10 @@ G_BEGIN_DECLS
default,\
flags | GIMP_CONFIG_PARAM_FLAGS))
#define GIMP_CONFIG_INSTALL_PROP_RGB(class, id, name, blurb, default, flags)\
#define GIMP_CONFIG_INSTALL_PROP_RGB(class, id, name, blurb, has_alpha, default, flags) \
g_object_class_install_property (class, id,\
gimp_param_spec_rgb (name, NULL, blurb,\
default,\
has_alpha, default, \
flags | GIMP_CONFIG_PARAM_FLAGS))
#define GIMP_CONFIG_INSTALL_PROP_DOUBLE(class, id, name, blurb, min, max, default, flags)\
......
......@@ -36,6 +36,11 @@
#include "gimpconfig-utils.h"
static gboolean gimp_config_serialize_rgb (const GValue *value,
GString *str,
gboolean has_alpha);
/**
* gimp_config_serialize_properties:
* @config: a #GimpConfig.
......@@ -251,11 +256,20 @@ gimp_config_serialize_property (GimpConfig *config,
gimp_config_writer_revert (writer);
}
}
else if (! G_VALUE_HOLDS_OBJECT (&value))
else
{
GString *str = g_string_new (NULL);
success = gimp_config_serialize_value (&value, str, TRUE);
if (GIMP_VALUE_HOLDS_RGB (&value))
{
gboolean has_alpha = GIMP_PARAM_SPEC_RGB (param_spec)->has_alpha;
success = gimp_config_serialize_rgb (&value, str, has_alpha);
}
else
{
success = gimp_config_serialize_value (&value, str, TRUE);
}
if (success)
{
......@@ -366,19 +380,7 @@ gimp_config_serialize_value (const GValue *value,
if (GIMP_VALUE_HOLDS_RGB (value))
{
GimpRGB *rgb;
gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
rgb = g_value_get_boxed (value);
g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->r);
g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->g);
g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->b);
g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->a);
g_string_append_printf (str, "(color-rgba %s %s %s %s)",
buf[0], buf[1], buf[2], buf[3]);
return TRUE;
return gimp_config_serialize_rgb (value, str, TRUE);
}
if (GIMP_VALUE_HOLDS_MATRIX2 (value))
......@@ -444,3 +446,33 @@ gimp_config_serialize_value (const GValue *value,
return FALSE;
}
static gboolean
gimp_config_serialize_rgb (const GValue *value,
GString *str,
gboolean has_alpha)
{
GimpRGB *rgb;
gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
rgb = g_value_get_boxed (value);
g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->r);
g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->g);
g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", rgb->b);
if (has_alpha)
{