diff --git a/app/operations/gimpcolorizeconfig.c b/app/operations/gimpcolorizeconfig.c index 0e9241ee88..02975d601c 100644 --- a/app/operations/gimpcolorizeconfig.c +++ b/app/operations/gimpcolorizeconfig.c @@ -37,7 +37,8 @@ enum PROP_0, PROP_HUE, PROP_SATURATION, - PROP_LIGHTNESS + PROP_LIGHTNESS, + PROP_COLOR }; @@ -63,6 +64,8 @@ gimp_colorize_config_class_init (GimpColorizeConfigClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass); + GimpHSL hsl; + GimpRGB rgb; object_class->set_property = gimp_colorize_config_set_property; object_class->get_property = gimp_colorize_config_get_property; @@ -83,6 +86,17 @@ gimp_colorize_config_class_init (GimpColorizeConfigClass *klass) "lightness", "Lightness", -1.0, 1.0, 0.0, 0); + + gimp_hsl_set (&hsl, 0.5, 0.5, 0.5); + gimp_hsl_to_rgb (&hsl, &rgb); + gimp_rgb_set_alpha (&rgb, 1.0); + + g_object_class_install_property (object_class, PROP_COLOR, + gimp_param_spec_rgb ("color", + "Color", + "The color", + FALSE, &rgb, + G_PARAM_READWRITE)); } static void @@ -112,6 +126,21 @@ gimp_colorize_config_get_property (GObject *object, g_value_set_double (value, self->lightness); break; + case PROP_COLOR: + { + GimpHSL hsl; + GimpRGB rgb; + + gimp_hsl_set (&hsl, + self->hue, + self->saturation, + (self->lightness + 1.0) / 2.0); + gimp_hsl_to_rgb (&hsl, &rgb); + gimp_rgb_set_alpha (&rgb, 1.0); + gimp_value_set_rgb (value, &rgb); + } + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -130,14 +159,39 @@ gimp_colorize_config_set_property (GObject *object, { case PROP_HUE: self->hue = g_value_get_double (value); + g_object_notify (object, "color"); break; case PROP_SATURATION: self->saturation = g_value_get_double (value); + g_object_notify (object, "color"); break; case PROP_LIGHTNESS: self->lightness = g_value_get_double (value); + g_object_notify (object, "color"); + break; + + case PROP_COLOR: + { + GimpRGB rgb; + GimpHSL hsl; + + gimp_value_get_rgb (value, &rgb); + gimp_rgb_to_hsl (&rgb, &hsl); + + if (hsl.h == -1) + hsl.h = self->hue; + + if (hsl.l == 0.0 || hsl.l == 1.0) + hsl.s = self->saturation; + + g_object_set (self, + "hue", hsl.h, + "saturation", hsl.s, + "lightness", hsl.l * 2.0 - 1.0, + NULL); + } break; default: @@ -145,47 +199,3 @@ gimp_colorize_config_set_property (GObject *object, break; } } - - -/* public functions */ - -void -gimp_colorize_config_get_color (GimpColorizeConfig *config, - GimpRGB *color) -{ - GimpHSL hsl; - - g_return_if_fail (GIMP_IS_COLORIZE_CONFIG (config)); - g_return_if_fail (color != NULL); - - gimp_hsl_set (&hsl, - config->hue, - config->saturation, - (config->lightness + 1.0) / 2.0); - gimp_hsl_to_rgb (&hsl, color); - gimp_rgb_set_alpha (color, 1.0); -} - -void -gimp_colorize_config_set_color (GimpColorizeConfig *config, - const GimpRGB *color) -{ - GimpHSL hsl; - - g_return_if_fail (GIMP_IS_COLORIZE_CONFIG (config)); - g_return_if_fail (color != NULL); - - gimp_rgb_to_hsl (color, &hsl); - - if (hsl.h == -1) - hsl.h = config->hue; - - if (hsl.l == 0.0 || hsl.l == 1.0) - hsl.s = config->saturation; - - g_object_set (config, - "hue", hsl.h, - "saturation", hsl.s, - "lightness", hsl.l * 2.0 - 1.0, - NULL); -} diff --git a/app/operations/gimpcolorizeconfig.h b/app/operations/gimpcolorizeconfig.h index 2fbaf15fe5..17e159b4c8 100644 --- a/app/operations/gimpcolorizeconfig.h +++ b/app/operations/gimpcolorizeconfig.h @@ -50,12 +50,7 @@ struct _GimpColorizeConfigClass }; -GType gimp_colorize_config_get_type (void) G_GNUC_CONST; - -void gimp_colorize_config_get_color (GimpColorizeConfig *config, - GimpRGB *color); -void gimp_colorize_config_set_color (GimpColorizeConfig *config, - const GimpRGB *color); +GType gimp_colorize_config_get_type (void) G_GNUC_CONST; #endif /* __GIMP_COLORIZE_CONFIG_H__ */ diff --git a/app/tools/gimpcolorizetool.c b/app/tools/gimpcolorizetool.c index 45cef66924..7ff64adbf6 100644 --- a/app/tools/gimpcolorizetool.c +++ b/app/tools/gimpcolorizetool.c @@ -61,13 +61,6 @@ static void gimp_colorize_tool_color_picked (GimpImageMapTool *im_tool, const Babl *sample_format, const GimpRGB *color); -static void gimp_colorize_tool_config_notify (GObject *object, - GParamSpec *pspec, - GimpColorizeTool *col_tool); - -static void colorize_color_changed (GtkWidget *button, - GimpColorizeTool *col_tool); - G_DEFINE_TYPE (GimpColorizeTool, gimp_colorize_tool, GIMP_TYPE_IMAGE_MAP_TOOL) @@ -140,19 +133,11 @@ gimp_colorize_tool_get_operation (GimpImageMapTool *im_tool, GObject **config, gchar **undo_desc) { - GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (im_tool); - - col_tool->config = g_object_new (GIMP_TYPE_COLORIZE_CONFIG, NULL); - - g_signal_connect_object (col_tool->config, "notify", - G_CALLBACK (gimp_colorize_tool_config_notify), - G_OBJECT (col_tool), 0); - - *config = G_OBJECT (col_tool->config); + *config = g_object_new (GIMP_TYPE_COLORIZE_CONFIG, NULL); return gegl_node_new_child (NULL, "operation", "gimp:colorize", - "config", col_tool->config, + "config", *config, NULL); } @@ -171,7 +156,6 @@ gimp_colorize_tool_dialog (GimpImageMapTool *image_map_tool) GtkWidget *scale; GtkWidget *hbox; GtkWidget *button; - GimpRGB color; main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool); @@ -209,22 +193,15 @@ gimp_colorize_tool_dialog (GimpImageMapTool *image_map_tool) gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); - gimp_colorize_config_get_color (col_tool->config, &color); - - col_tool->color_button = gimp_color_panel_new (_("Colorize Color"), - &color, - GIMP_COLOR_AREA_FLAT, - 128, 24); - gimp_color_button_set_update (GIMP_COLOR_BUTTON (col_tool->color_button), - TRUE); - gimp_color_panel_set_context (GIMP_COLOR_PANEL (col_tool->color_button), + button = gimp_prop_color_button_new (image_map_tool->config, "color", + _("Colorize Color"), + 128, 24, + GIMP_COLOR_AREA_FLAT); + gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE); + gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), GIMP_CONTEXT (GIMP_TOOL_GET_OPTIONS (col_tool))); - gtk_box_pack_start (GTK_BOX (hbox), col_tool->color_button, TRUE, TRUE, 0); - gtk_widget_show (col_tool->color_button); - - g_signal_connect (col_tool->color_button, "color-changed", - G_CALLBACK (colorize_color_changed), - col_tool); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + gtk_widget_show (button); button = gimp_image_map_tool_add_color_picker (image_map_tool, "colorize", @@ -240,32 +217,5 @@ gimp_colorize_tool_color_picked (GimpImageMapTool *im_tool, const Babl *sample_format, const GimpRGB *color) { - GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (im_tool); - - gimp_colorize_config_set_color (col_tool->config, color); -} - -static void -gimp_colorize_tool_config_notify (GObject *object, - GParamSpec *pspec, - GimpColorizeTool *col_tool) -{ - GimpRGB color; - - if (! col_tool->color_button) - return; - - gimp_colorize_config_get_color (col_tool->config, &color); - gimp_color_button_set_color (GIMP_COLOR_BUTTON (col_tool->color_button), - &color); -} - -static void -colorize_color_changed (GtkWidget *button, - GimpColorizeTool *col_tool) -{ - GimpRGB color; - - gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &color); - gimp_colorize_config_set_color (col_tool->config, &color); + g_object_set (im_tool->config, "color", color, NULL); } diff --git a/app/tools/gimpcolorizetool.h b/app/tools/gimpcolorizetool.h index 8d3c4a7fd7..16c6080755 100644 --- a/app/tools/gimpcolorizetool.h +++ b/app/tools/gimpcolorizetool.h @@ -35,12 +35,7 @@ typedef struct _GimpColorizeToolClass GimpColorizeToolClass; struct _GimpColorizeTool { - GimpImageMapTool parent_instance; - - GimpColorizeConfig *config; - - /* dialog */ - GtkWidget *color_button; + GimpImageMapTool parent_instance; }; struct _GimpColorizeToolClass