Commit d476ee65 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added signal "color-changed" and emit it in gimp_channel_set_color() and

2004-07-05  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpchannel.[ch]: added signal "color-changed" and emit
	it in gimp_channel_set_color() and gimp_channel_set_opacity().

	* app/core/gimpimage-qmask.[ch]: added new functions
	gimp_image_set,get_qmask_color().

	* app/core/gimpimage.[ch]: install a "color-changed" handler on
	gimage->channels and update gimage->qmask_color when the qmask's
	color changes. Fixes bug #145361.

	* app/actions/qmask-commands.c: use the new qmask color API.
parent f0d560e1
2004-07-05 Michael Natterer <mitch@gimp.org>
* app/core/gimpchannel.[ch]: added signal "color-changed" and emit
it in gimp_channel_set_color() and gimp_channel_set_opacity().
* app/core/gimpimage-qmask.[ch]: added new functions
gimp_image_set,get_qmask_color().
* app/core/gimpimage.[ch]: install a "color-changed" handler on
gimage->channels and update gimage->qmask_color when the qmask's
color changes. Fixes bug #145361.
* app/actions/qmask-commands.c: use the new qmask color API.
2004-07-04 Simon Budig <simon@gimp.org>
* app/actions/dialogs-commands.c
......
......@@ -128,14 +128,17 @@ qmask_channel_query (GimpDisplayShell *shell)
GtkWidget *table;
GtkWidget *opacity_scale;
GtkObject *opacity_scale_data;
GimpRGB color;
gimp_image_get_qmask_color (shell->gdisp->gimage, &color);
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = shell->gdisp->gimage;
options->color_panel = gimp_color_panel_new (_("Edit QuickMask Color"),
&options->gimage->qmask_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
&color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
gimp_get_user_context (options->gimage->gimp));
......@@ -181,9 +184,8 @@ qmask_channel_query (GimpDisplayShell *shell)
gtk_widget_show (table);
/* The opacity scale */
opacity_scale_data =
gtk_adjustment_new (options->gimage->qmask_color.a * 100.0,
0.0, 100.0, 1.0, 1.0, 0.0);
opacity_scale_data = gtk_adjustment_new (color.a * 100.0,
0.0, 100.0, 1.0, 1.0, 0.0);
opacity_scale = gtk_hscale_new (GTK_ADJUSTMENT (opacity_scale_data));
gtk_widget_set_size_request (opacity_scale, 100, -1);
gtk_scale_set_value_pos (GTK_SCALE (opacity_scale), GTK_POS_TOP);
......@@ -215,24 +217,19 @@ qmask_query_response (GtkWidget *widget,
{
if (response_id == GTK_RESPONSE_OK)
{
GimpChannel *channel = gimp_image_get_qmask (options->gimage);
GimpRGB color;
GimpRGB old_color;
GimpRGB new_color;
if (options->gimage && channel)
{
gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
&color);
gimp_image_get_qmask_color (options->gimage, &old_color);
gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
&new_color);
if (gimp_rgba_distance (&color, &channel->color) > 0.0001)
{
gimp_channel_set_color (channel, &color, TRUE);
if (gimp_rgba_distance (&old_color, &new_color) > 0.0001)
{
gimp_image_set_qmask_color (options->gimage, &new_color);
gimp_image_flush (options->gimage);
}
gimp_image_flush (options->gimage);
}
/* update the qmask color no matter what */
options->gimage->qmask_color = color;
}
gtk_widget_destroy (options->query_box);
......
......@@ -128,14 +128,17 @@ qmask_channel_query (GimpDisplayShell *shell)
GtkWidget *table;
GtkWidget *opacity_scale;
GtkObject *opacity_scale_data;
GimpRGB color;
gimp_image_get_qmask_color (shell->gdisp->gimage, &color);
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = shell->gdisp->gimage;
options->color_panel = gimp_color_panel_new (_("Edit QuickMask Color"),
&options->gimage->qmask_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
&color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
gimp_get_user_context (options->gimage->gimp));
......@@ -181,9 +184,8 @@ qmask_channel_query (GimpDisplayShell *shell)
gtk_widget_show (table);
/* The opacity scale */
opacity_scale_data =
gtk_adjustment_new (options->gimage->qmask_color.a * 100.0,
0.0, 100.0, 1.0, 1.0, 0.0);
opacity_scale_data = gtk_adjustment_new (color.a * 100.0,
0.0, 100.0, 1.0, 1.0, 0.0);
opacity_scale = gtk_hscale_new (GTK_ADJUSTMENT (opacity_scale_data));
gtk_widget_set_size_request (opacity_scale, 100, -1);
gtk_scale_set_value_pos (GTK_SCALE (opacity_scale), GTK_POS_TOP);
......@@ -215,24 +217,19 @@ qmask_query_response (GtkWidget *widget,
{
if (response_id == GTK_RESPONSE_OK)
{
GimpChannel *channel = gimp_image_get_qmask (options->gimage);
GimpRGB color;
GimpRGB old_color;
GimpRGB new_color;
if (options->gimage && channel)
{
gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
&color);
gimp_image_get_qmask_color (options->gimage, &old_color);
gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
&new_color);
if (gimp_rgba_distance (&color, &channel->color) > 0.0001)
{
gimp_channel_set_color (channel, &color, TRUE);
if (gimp_rgba_distance (&old_color, &new_color) > 0.0001)
{
gimp_image_set_qmask_color (options->gimage, &new_color);
gimp_image_flush (options->gimage);
}
gimp_image_flush (options->gimage);
}
/* update the qmask color no matter what */
options->gimage->qmask_color = color;
}
gtk_widget_destroy (options->query_box);
......
......@@ -49,12 +49,20 @@
#include "gimpchannel.h"
#include "gimpcontext.h"
#include "gimpdrawable-stroke.h"
#include "gimpmarshal.h"
#include "gimppaintinfo.h"
#include "gimpstrokeoptions.h"
#include "gimp-intl.h"
enum
{
COLOR_CHANGED,
LAST_SIGNAL
};
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
......@@ -197,7 +205,11 @@ static void gimp_channel_validate (TileManager *tm,
Tile *tile);
static GimpDrawableClass * parent_class = NULL;
/* private variables */
static guint channel_signals[LAST_SIGNAL] = { 0 };
static GimpDrawableClass *parent_class = NULL;
GType
......@@ -239,6 +251,15 @@ gimp_channel_class_init (GimpChannelClass *klass)
parent_class = g_type_class_peek_parent (klass);
channel_signals[COLOR_CHANGED] =
g_signal_new ("color-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpChannelClass, color_changed),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->finalize = gimp_channel_finalize;
gimp_object_class->get_memsize = gimp_channel_get_memsize;
......@@ -1517,6 +1538,8 @@ gimp_channel_set_color (GimpChannel *channel,
0, 0,
GIMP_ITEM (channel)->width,
GIMP_ITEM (channel)->height);
g_signal_emit (channel, channel_signals[COLOR_CHANGED], 0);
}
}
......@@ -1564,6 +1587,8 @@ gimp_channel_set_opacity (GimpChannel *channel,
0, 0,
GIMP_ITEM (channel)->width,
GIMP_ITEM (channel)->height);
g_signal_emit (channel, channel_signals[COLOR_CHANGED], 0);
}
}
......
......@@ -60,51 +60,55 @@ struct _GimpChannelClass
{
GimpDrawableClass parent_class;
gboolean (* boundary) (GimpChannel *channel,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
gint y1,
gint x2,
gint y2);
gboolean (* bounds) (GimpChannel *channel,
gint *x1,
gint *y1,
gint *x2,
gint *y2);
gboolean (* is_empty) (GimpChannel *channel);
gint (* value) (GimpChannel *channel,
gint x,
gint y);
void (* feather) (GimpChannel *channel,
gdouble radius_x,
gdouble radius_y,
gboolean push_undo);
void (* sharpen) (GimpChannel *channel,
gboolean push_undo);
void (* clear) (GimpChannel *channel,
const gchar *undo_desc,
gboolean push_undo);
void (* all) (GimpChannel *channel,
gboolean push_undo);
void (* invert) (GimpChannel *channel,
gboolean push_undo);
void (* border) (GimpChannel *channel,
gint radius_x,
gint radius_y,
gboolean push_undo);
void (* grow) (GimpChannel *channel,
gint radius_x,
gint radius_y,
gboolean push_undo);
void (* shrink) (GimpChannel *channel,
gint radius_x,
gint radius_y,
gboolean edge_lock,
gboolean push_undo);
/* signals */
void (* color_changed) (GimpChannel *channel);
/* virtual functions */
gboolean (* boundary) (GimpChannel *channel,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
gint y1,
gint x2,
gint y2);
gboolean (* bounds) (GimpChannel *channel,
gint *x1,
gint *y1,
gint *x2,
gint *y2);
gboolean (* is_empty) (GimpChannel *channel);
gint (* value) (GimpChannel *channel,
gint x,
gint y);
void (* feather) (GimpChannel *channel,
gdouble radius_x,
gdouble radius_y,
gboolean push_undo);
void (* sharpen) (GimpChannel *channel,
gboolean push_undo);
void (* clear) (GimpChannel *channel,
const gchar *undo_desc,
gboolean push_undo);
void (* all) (GimpChannel *channel,
gboolean push_undo);
void (* invert) (GimpChannel *channel,
gboolean push_undo);
void (* border) (GimpChannel *channel,
gint radius_x,
gint radius_y,
gboolean push_undo);
void (* grow) (GimpChannel *channel,
gint radius_x,
gint radius_y,
gboolean push_undo);
void (* shrink) (GimpChannel *channel,
gint radius_x,
gint radius_y,
gboolean edge_lock,
gboolean push_undo);
const gchar *feather_desc;
const gchar *sharpen_desc;
......
......@@ -140,6 +140,33 @@ gimp_image_get_qmask_state (const GimpImage *gimage)
return gimage->qmask_state;
}
void
gimp_image_set_qmask_color (GimpImage *gimage,
const GimpRGB *color)
{
GimpChannel *qmask;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (color != NULL);
qmask = gimp_image_get_qmask (gimage);
if (qmask)
gimp_channel_set_color (qmask, color, TRUE);
else
gimage->qmask_color = *color;
}
void
gimp_image_get_qmask_color (const GimpImage *gimage,
GimpRGB *color)
{
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (color != NULL);
*color = gimage->qmask_color;
}
GimpChannel *
gimp_image_get_qmask (const GimpImage *gimage)
{
......@@ -158,14 +185,7 @@ gimp_image_qmask_invert (GimpImage *gimage)
GimpChannel *qmask = gimp_image_get_qmask (gimage);
if (qmask)
{
gimp_channel_invert (qmask, TRUE);
gimp_drawable_update (GIMP_DRAWABLE (qmask),
0, 0,
GIMP_ITEM (qmask)->width,
GIMP_ITEM (qmask)->height);
}
gimp_channel_invert (qmask, TRUE);
}
gimage->qmask_inverted = ! gimage->qmask_inverted;
......
......@@ -27,6 +27,11 @@ void gimp_image_set_qmask_state (GimpImage *gimage,
gboolean qmask_state);
gboolean gimp_image_get_qmask_state (const GimpImage *gimage);
void gimp_image_set_qmask_color (GimpImage *gimage,
const GimpRGB *color);
void gimp_image_get_qmask_color (const GimpImage *gimage,
GimpRGB *color);
GimpChannel * gimp_image_get_qmask (const GimpImage *gimage);
void gimp_image_qmask_invert (GimpImage *gimage);
......
......@@ -140,6 +140,33 @@ gimp_image_get_qmask_state (const GimpImage *gimage)
return gimage->qmask_state;
}
void
gimp_image_set_qmask_color (GimpImage *gimage,
const GimpRGB *color)
{
GimpChannel *qmask;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (color != NULL);
qmask = gimp_image_get_qmask (gimage);
if (qmask)
gimp_channel_set_color (qmask, color, TRUE);
else
gimage->qmask_color = *color;
}
void
gimp_image_get_qmask_color (const GimpImage *gimage,
GimpRGB *color)
{
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (color != NULL);
*color = gimage->qmask_color;
}
GimpChannel *
gimp_image_get_qmask (const GimpImage *gimage)
{
......@@ -158,14 +185,7 @@ gimp_image_qmask_invert (GimpImage *gimage)
GimpChannel *qmask = gimp_image_get_qmask (gimage);
if (qmask)
{
gimp_channel_invert (qmask, TRUE);
gimp_drawable_update (GIMP_DRAWABLE (qmask),
0, 0,
GIMP_ITEM (qmask)->width,
GIMP_ITEM (qmask)->height);
}
gimp_channel_invert (qmask, TRUE);
}
gimage->qmask_inverted = ! gimage->qmask_inverted;
......
......@@ -27,6 +27,11 @@ void gimp_image_set_qmask_state (GimpImage *gimage,
gboolean qmask_state);
gboolean gimp_image_get_qmask_state (const GimpImage *gimage);
void gimp_image_set_qmask_color (GimpImage *gimage,
const GimpRGB *color);
void gimp_image_get_qmask_color (const GimpImage *gimage,
GimpRGB *color);
GimpChannel * gimp_image_get_qmask (const GimpImage *gimage);
void gimp_image_qmask_invert (GimpImage *gimage);
......
......@@ -151,6 +151,8 @@ static void gimp_image_channel_remove (GimpContainer *container,
GimpImage *gimage);
static void gimp_image_channel_name_changed (GimpChannel *channel,
GimpImage *gimage);
static void gimp_image_channel_color_changed (GimpChannel *channel,
GimpImage *gimage);
static gint valid_combinations[][MAX_CHANNELS + 1] =
......@@ -522,6 +524,10 @@ gimp_image_init (GimpImage *gimage)
gimp_container_add_handler (gimage->channels, "name_changed",
G_CALLBACK (gimp_image_channel_name_changed),
gimage);
gimage->channel_color_changed_handler =
gimp_container_add_handler (gimage->channels, "color_changed",
G_CALLBACK (gimp_image_channel_color_changed),
gimage);
g_signal_connect (gimage->layers, "add",
G_CALLBACK (gimp_image_layer_add),
......@@ -588,6 +594,8 @@ gimp_image_dispose (GObject *object)
gimage->channel_visible_handler);
gimp_container_remove_handler (gimage->channels,
gimage->channel_name_changed_handler);
gimp_container_remove_handler (gimage->channels,
gimage->channel_color_changed_handler);
g_signal_handlers_disconnect_by_func (gimage->layers,
gimp_image_layer_add,
......@@ -1006,6 +1014,17 @@ gimp_image_channel_name_changed (GimpChannel *channel,
}
}
static void
gimp_image_channel_color_changed (GimpChannel *channel,
GimpImage *gimage)
{
if (! strcmp (GIMP_IMAGE_QMASK_NAME,
gimp_object_get_name (GIMP_OBJECT (channel))))
{
gimage->qmask_color = channel->color;
}
}
/* public functions */
......
......@@ -146,6 +146,7 @@ struct _GimpImage
GQuark channel_update_handler;
GQuark channel_visible_handler;
GQuark channel_name_changed_handler;
GQuark channel_color_changed_handler;
GimpLayer *active_layer; /* the active layer */
GimpChannel *active_channel; /* the active channel */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment