2001-04-21 10:11:12 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2002-03-28 08:10:56 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-10-13 20:52:30 +08:00
|
|
|
#include "gui-types.h"
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpchannel.h"
|
2003-10-06 20:17:11 +08:00
|
|
|
#include "core/gimpchannel-select.h"
|
2002-02-27 00:30:14 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2003-02-13 19:23:50 +08:00
|
|
|
#include "core/gimpimage-undo.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
#include "widgets/gimpcolorpanel.h"
|
2003-03-13 01:12:01 +08:00
|
|
|
#include "widgets/gimpcomponenteditor.h"
|
2003-08-21 23:54:47 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2003-03-16 19:14:29 +08:00
|
|
|
#include "widgets/gimpitemtreeview.h"
|
2002-08-31 05:00:42 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2002-12-11 00:38:16 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
#include "channels-commands.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-04-21 10:11:12 +08:00
|
|
|
|
|
|
|
|
2002-02-27 00:30:14 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static void channels_opacity_update (GtkAdjustment *adjustment,
|
|
|
|
gpointer data);
|
|
|
|
static void channels_color_changed (GimpColorButton *button,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
|
2002-12-11 00:38:16 +08:00
|
|
|
#define return_if_no_image(gimage,data) \
|
2003-01-12 20:35:00 +08:00
|
|
|
if (GIMP_IS_DISPLAY (data)) \
|
|
|
|
gimage = ((GimpDisplay *) data)->gimage; \
|
|
|
|
else if (GIMP_IS_GIMP (data)) \
|
|
|
|
gimage = gimp_context_get_image (gimp_get_user_context (GIMP (data))); \
|
2003-03-13 01:12:01 +08:00
|
|
|
else if (GIMP_IS_COMPONENT_EDITOR (data)) \
|
|
|
|
gimage = ((GimpImageEditor *) data)->gimage; \
|
2003-03-16 19:14:29 +08:00
|
|
|
else if (GIMP_IS_ITEM_TREE_VIEW (data)) \
|
|
|
|
gimage = ((GimpItemTreeView *) data)->gimage; \
|
2003-01-12 20:35:00 +08:00
|
|
|
else \
|
|
|
|
gimage = NULL; \
|
|
|
|
\
|
2002-02-27 00:30:14 +08:00
|
|
|
if (! gimage) \
|
|
|
|
return
|
|
|
|
|
2002-12-11 00:38:16 +08:00
|
|
|
#define return_if_no_channel(gimage,channel,data) \
|
|
|
|
return_if_no_image (gimage,data); \
|
2002-02-27 00:30:14 +08:00
|
|
|
channel = gimp_image_get_active_channel (gimage); \
|
|
|
|
if (! channel) \
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2001-11-28 03:27:55 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
void
|
2003-08-21 23:54:47 +08:00
|
|
|
channels_new_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
2002-12-11 00:38:16 +08:00
|
|
|
return_if_no_image (gimage, data);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-08 23:29:47 +08:00
|
|
|
channels_new_channel_query (gimage, NULL, TRUE, widget);
|
2001-04-21 10:11:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-21 23:54:47 +08:00
|
|
|
channels_raise_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
2002-02-27 00:30:14 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
GimpChannel *active_channel;
|
2002-12-11 00:38:16 +08:00
|
|
|
return_if_no_channel (gimage, active_channel, data);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2002-02-27 00:30:14 +08:00
|
|
|
gimp_image_raise_channel (gimage, active_channel);
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (gimage);
|
2001-04-21 10:11:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-21 23:54:47 +08:00
|
|
|
channels_lower_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
2002-02-27 00:30:14 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
GimpChannel *active_channel;
|
2002-12-11 00:38:16 +08:00
|
|
|
return_if_no_channel (gimage, active_channel, data);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2002-02-27 00:30:14 +08:00
|
|
|
gimp_image_lower_channel (gimage, active_channel);
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (gimage);
|
2001-04-21 10:11:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-21 23:54:47 +08:00
|
|
|
channels_duplicate_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
|
|
|
GimpChannel *new_channel;
|
|
|
|
|
2003-03-13 01:12:01 +08:00
|
|
|
if (GIMP_IS_COMPONENT_EDITOR (data))
|
|
|
|
{
|
|
|
|
GimpRGB color;
|
|
|
|
GimpChannelType component;
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
GEnumValue *enum_value;
|
|
|
|
gchar *name;
|
|
|
|
return_if_no_image (gimage, data);
|
|
|
|
|
|
|
|
gimp_rgba_set (&color, 0, 0, 0, 0.5);
|
|
|
|
|
|
|
|
component = GIMP_COMPONENT_EDITOR (data)->clicked_component;
|
|
|
|
|
|
|
|
enum_class = g_type_class_ref (GIMP_TYPE_CHANNEL_TYPE);
|
|
|
|
enum_value = g_enum_get_value (enum_class, component);
|
|
|
|
g_type_class_unref (enum_class);
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2003-03-14 00:49:37 +08:00
|
|
|
name = g_strdup_printf (_("%s Channel Copy"),
|
2003-03-13 01:12:01 +08:00
|
|
|
gettext (enum_value->value_name));
|
|
|
|
|
|
|
|
new_channel = gimp_channel_new_from_component (gimage, component,
|
|
|
|
name, &color);
|
|
|
|
|
2003-08-21 23:54:47 +08:00
|
|
|
/* copied components are invisible by default so subsequent copies
|
|
|
|
* of components don't affect each other
|
|
|
|
*/
|
2003-09-12 03:52:29 +08:00
|
|
|
gimp_item_set_visible (GIMP_ITEM (new_channel), FALSE, FALSE);
|
2003-08-21 23:54:47 +08:00
|
|
|
|
2003-03-13 01:12:01 +08:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpChannel *active_channel;
|
|
|
|
return_if_no_channel (gimage, active_channel, data);
|
|
|
|
|
|
|
|
new_channel =
|
|
|
|
GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (active_channel),
|
|
|
|
G_TYPE_FROM_INSTANCE (active_channel),
|
|
|
|
TRUE));
|
|
|
|
}
|
|
|
|
|
2002-02-27 00:30:14 +08:00
|
|
|
gimp_image_add_channel (gimage, new_channel, -1);
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (gimage);
|
2001-04-21 10:11:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-21 23:54:47 +08:00
|
|
|
channels_delete_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
|
|
|
GimpChannel *active_channel;
|
2002-12-11 00:38:16 +08:00
|
|
|
return_if_no_channel (gimage, active_channel, data);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2002-02-27 00:30:14 +08:00
|
|
|
gimp_image_remove_channel (gimage, active_channel);
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (gimage);
|
2001-04-21 10:11:12 +08:00
|
|
|
}
|
|
|
|
|
2003-08-27 08:52:00 +08:00
|
|
|
void
|
|
|
|
channels_to_selection_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data,
|
|
|
|
guint action)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
2003-08-27 08:52:00 +08:00
|
|
|
GimpChannelOps op;
|
|
|
|
GimpImage *gimage;
|
|
|
|
|
|
|
|
op = (GimpChannelOps) action;
|
2003-03-13 01:12:01 +08:00
|
|
|
|
|
|
|
if (GIMP_IS_COMPONENT_EDITOR (data))
|
|
|
|
{
|
|
|
|
GimpChannelType component;
|
|
|
|
return_if_no_image (gimage, data);
|
|
|
|
|
|
|
|
component = GIMP_COMPONENT_EDITOR (data)->clicked_component;
|
|
|
|
|
2003-10-06 20:17:11 +08:00
|
|
|
gimp_channel_select_component (gimp_image_get_mask (gimage), component,
|
|
|
|
op, FALSE, 0.0, 0.0);
|
2003-03-13 01:12:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-08-21 23:54:47 +08:00
|
|
|
GimpChannel *channel;
|
2003-03-13 01:12:01 +08:00
|
|
|
return_if_no_channel (gimage, channel, data);
|
2003-08-21 23:54:47 +08:00
|
|
|
|
2003-10-06 20:17:11 +08:00
|
|
|
gimp_channel_select_channel (gimp_image_get_mask (gimage),
|
|
|
|
_("Channel to Selection"),
|
|
|
|
channel, 0, 0,
|
|
|
|
op, FALSE, 0.0, 0.0);
|
2003-03-13 01:12:01 +08:00
|
|
|
}
|
2002-02-27 00:30:14 +08:00
|
|
|
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (gimage);
|
2001-04-21 10:11:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-21 23:54:47 +08:00
|
|
|
channels_edit_attributes_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
|
|
|
GimpChannel *active_channel;
|
2002-12-11 00:38:16 +08:00
|
|
|
return_if_no_channel (gimage, active_channel, data);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-08 23:29:47 +08:00
|
|
|
channels_edit_channel_query (active_channel, widget);
|
2001-04-21 10:11:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************/
|
|
|
|
/* The new channel query dialog */
|
|
|
|
/**********************************/
|
|
|
|
|
|
|
|
typedef struct _NewChannelOptions NewChannelOptions;
|
|
|
|
|
|
|
|
struct _NewChannelOptions
|
|
|
|
{
|
|
|
|
GtkWidget *query_box;
|
|
|
|
GtkWidget *name_entry;
|
|
|
|
GtkWidget *color_panel;
|
|
|
|
|
|
|
|
GimpImage *gimage;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gchar *channel_name = NULL;
|
|
|
|
static GimpRGB channel_color = { 0.0, 0.0, 0.0, 0.5 };
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-11-06 23:27:05 +08:00
|
|
|
new_channel_query_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
NewChannelOptions *options)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
2003-11-06 23:27:05 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
2003-11-06 23:27:05 +08:00
|
|
|
GimpChannel *new_channel;
|
|
|
|
GimpImage *gimage;
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (channel_name)
|
|
|
|
g_free (channel_name);
|
|
|
|
channel_name =
|
|
|
|
g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if ((gimage = options->gimage))
|
|
|
|
{
|
|
|
|
gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
|
|
|
|
&channel_color);
|
|
|
|
new_channel = gimp_channel_new (gimage, gimage->width, gimage->height,
|
|
|
|
channel_name,
|
|
|
|
&channel_color);
|
|
|
|
|
|
|
|
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel),
|
|
|
|
gimp_get_user_context (gimage->gimp),
|
|
|
|
GIMP_TRANSPARENT_FILL);
|
|
|
|
|
|
|
|
gimp_image_add_channel (gimage, new_channel, -1);
|
|
|
|
gimp_image_flush (gimage);
|
|
|
|
}
|
2001-04-21 10:11:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (options->query_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-12-17 21:41:23 +08:00
|
|
|
channels_new_channel_query (GimpImage *gimage,
|
2002-09-02 22:39:08 +08:00
|
|
|
GimpChannel *template,
|
2003-11-08 23:29:47 +08:00
|
|
|
gboolean interactive,
|
|
|
|
GtkWidget *parent)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
|
|
|
NewChannelOptions *options;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkObject *opacity_scale_data;
|
|
|
|
|
2001-12-17 21:41:23 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
g_return_if_fail (! template || GIMP_IS_CHANNEL (template));
|
|
|
|
|
2002-09-02 22:39:08 +08:00
|
|
|
if (template || ! interactive)
|
2001-12-17 21:41:23 +08:00
|
|
|
{
|
|
|
|
GimpChannel *new_channel;
|
|
|
|
gint width, height;
|
2002-09-02 22:39:08 +08:00
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
if (template)
|
|
|
|
{
|
2003-05-08 21:12:46 +08:00
|
|
|
width = gimp_item_width (GIMP_ITEM (template));
|
|
|
|
height = gimp_item_height (GIMP_ITEM (template));
|
2002-09-02 22:39:08 +08:00
|
|
|
color = template->color;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = gimp_image_get_width (gimage);
|
|
|
|
height = gimp_image_get_height (gimage);
|
|
|
|
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.5);
|
|
|
|
}
|
2001-12-17 21:41:23 +08:00
|
|
|
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
|
|
|
|
_("New Channel"));
|
2001-12-17 21:41:23 +08:00
|
|
|
|
|
|
|
new_channel = gimp_channel_new (gimage,
|
|
|
|
width, height,
|
|
|
|
_("Empty Channel Copy"),
|
2002-09-02 22:39:08 +08:00
|
|
|
&color);
|
|
|
|
|
|
|
|
if (template)
|
2003-05-09 21:05:37 +08:00
|
|
|
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel),
|
|
|
|
gimp_get_user_context (gimage->gimp),
|
|
|
|
GIMP_TRANSPARENT_FILL);
|
2001-12-17 21:41:23 +08:00
|
|
|
|
|
|
|
gimp_image_add_channel (gimage, new_channel, -1);
|
|
|
|
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2001-12-17 21:41:23 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
/* the new options structure */
|
|
|
|
options = g_new (NewChannelOptions, 1);
|
|
|
|
options->gimage = gimage;
|
|
|
|
options->color_panel = gimp_color_panel_new (_("New Channel Color"),
|
|
|
|
&channel_color,
|
|
|
|
GIMP_COLOR_AREA_LARGE_CHECKS,
|
|
|
|
48, 64);
|
2002-12-04 06:16:56 +08:00
|
|
|
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
|
|
|
|
gimp_get_user_context (gimage->gimp));
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
/* The dialog */
|
|
|
|
options->query_box =
|
2002-08-31 05:00:42 +08:00
|
|
|
gimp_viewable_dialog_new (GIMP_VIEWABLE (gimage),
|
2003-11-08 01:29:02 +08:00
|
|
|
_("New Channel"), "gimp-channel-new",
|
2003-03-27 22:25:18 +08:00
|
|
|
GIMP_STOCK_CHANNEL,
|
2002-08-31 05:00:42 +08:00
|
|
|
_("New Channel Options"),
|
2003-11-08 23:29:47 +08:00
|
|
|
parent,
|
2002-08-31 05:00:42 +08:00
|
|
|
gimp_standard_help_func,
|
2003-08-21 23:54:47 +08:00
|
|
|
GIMP_HELP_CHANNEL_NEW,
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2001-11-24 07:04:49 +08:00
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
NULL);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2001-08-12 05:10:44 +08:00
|
|
|
g_object_weak_ref (G_OBJECT (options->query_box),
|
|
|
|
(GWeakNotify) g_free,
|
|
|
|
options);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (options->query_box, "response",
|
|
|
|
G_CALLBACK (new_channel_query_response),
|
|
|
|
options);
|
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
/* The main hbox */
|
2003-11-06 23:27:05 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
|
2001-04-21 10:11:12 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
|
|
|
|
hbox);
|
|
|
|
|
|
|
|
/* The vbox */
|
|
|
|
vbox = gtk_vbox_new (FALSE, 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
/* The table */
|
|
|
|
table = gtk_table_new (2, 3, FALSE);
|
2002-03-09 02:30:40 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
|
2001-04-21 10:11:12 +08:00
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
|
|
|
|
2002-03-09 02:30:40 +08:00
|
|
|
/* The name entry */
|
2001-04-21 10:11:12 +08:00
|
|
|
options->name_entry = gtk_entry_new ();
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (options->name_entry),
|
|
|
|
(channel_name ? channel_name : _("New Channel")));
|
2002-03-09 02:30:40 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Channel Name:"), 1.0, 0.5,
|
|
|
|
options->name_entry, 2, FALSE);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
|
|
|
/* The opacity scale */
|
2002-03-09 02:30:40 +08:00
|
|
|
opacity_scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
2002-09-08 20:18:23 +08:00
|
|
|
_("Fill Opacity:"), 100, -1,
|
2002-03-09 02:30:40 +08:00
|
|
|
channel_color.a * 100.0,
|
|
|
|
0.0, 100.0, 1.0, 10.0, 1,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (opacity_scale_data, "value_changed",
|
2001-07-25 08:42:47 +08:00
|
|
|
G_CALLBACK (channels_opacity_update),
|
|
|
|
options->color_panel);
|
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
/* The color panel */
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
|
|
|
|
TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (options->color_panel);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (options->color_panel, "color_changed",
|
2001-07-25 08:42:47 +08:00
|
|
|
G_CALLBACK (channels_color_changed),
|
|
|
|
opacity_scale_data);
|
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
gtk_widget_show (table);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
gtk_widget_show (options->query_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/* The edit channel attributes dialog */
|
|
|
|
/****************************************/
|
|
|
|
|
|
|
|
typedef struct _EditChannelOptions EditChannelOptions;
|
|
|
|
|
|
|
|
struct _EditChannelOptions
|
|
|
|
{
|
|
|
|
GtkWidget *query_box;
|
|
|
|
GtkWidget *name_entry;
|
|
|
|
GtkWidget *color_panel;
|
|
|
|
|
|
|
|
GimpChannel *channel;
|
|
|
|
GimpImage *gimage;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2003-11-06 23:27:05 +08:00
|
|
|
edit_channel_query_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
EditChannelOptions *options)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
2003-11-06 23:27:05 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
2003-11-06 23:27:05 +08:00
|
|
|
GimpChannel *channel = options->channel;
|
2002-02-26 08:04:55 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (options->gimage)
|
|
|
|
{
|
|
|
|
const gchar *new_name;
|
|
|
|
GimpRGB color;
|
|
|
|
gboolean name_changed = FALSE;
|
|
|
|
gboolean color_changed = FALSE;
|
2002-02-26 08:04:55 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
new_name = gtk_entry_get_text (GTK_ENTRY (options->name_entry));
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
|
|
|
|
&color);
|
2003-03-17 10:25:39 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (strcmp (new_name, gimp_object_get_name (GIMP_OBJECT (channel))))
|
|
|
|
name_changed = TRUE;
|
2003-03-17 10:25:39 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (gimp_rgba_distance (&color, &channel->color) > 0.0001)
|
|
|
|
color_changed = TRUE;
|
2003-03-17 10:25:39 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (name_changed && color_changed)
|
|
|
|
gimp_image_undo_group_start (options->gimage,
|
|
|
|
GIMP_UNDO_GROUP_ITEM_PROPERTIES,
|
|
|
|
_("Channel Attributes"));
|
2003-03-17 10:25:39 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (name_changed)
|
|
|
|
gimp_item_rename (GIMP_ITEM (channel), new_name);
|
2003-03-17 10:25:39 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (color_changed)
|
|
|
|
gimp_channel_set_color (channel, &color, TRUE);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (name_changed && color_changed)
|
|
|
|
gimp_image_undo_group_end (options->gimage);
|
|
|
|
|
|
|
|
if (name_changed || color_changed)
|
|
|
|
gimp_image_flush (options->gimage);
|
|
|
|
}
|
2001-04-21 10:11:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (options->query_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-11-08 23:29:47 +08:00
|
|
|
channels_edit_channel_query (GimpChannel *channel,
|
|
|
|
GtkWidget *parent)
|
2001-04-21 10:11:12 +08:00
|
|
|
{
|
|
|
|
EditChannelOptions *options;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkObject *opacity_scale_data;
|
|
|
|
|
|
|
|
options = g_new0 (EditChannelOptions, 1);
|
|
|
|
|
|
|
|
options->channel = channel;
|
2002-02-26 01:58:50 +08:00
|
|
|
options->gimage = gimp_item_get_image (GIMP_ITEM (channel));
|
2001-04-21 10:11:12 +08:00
|
|
|
|
|
|
|
channel_color = channel->color;
|
|
|
|
|
|
|
|
options->color_panel = gimp_color_panel_new (_("Edit Channel Color"),
|
|
|
|
&channel_color,
|
|
|
|
GIMP_COLOR_AREA_LARGE_CHECKS,
|
|
|
|
48, 64);
|
2002-12-04 06:16:56 +08:00
|
|
|
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
|
|
|
|
gimp_get_user_context (options->gimage->gimp));
|
2001-04-21 10:11:12 +08:00
|
|
|
|
|
|
|
/* The dialog */
|
|
|
|
options->query_box =
|
2002-08-31 05:00:42 +08:00
|
|
|
gimp_viewable_dialog_new (GIMP_VIEWABLE (channel),
|
2003-11-08 01:29:02 +08:00
|
|
|
_("Channel Attributes"), "gimp-channel-edit",
|
2002-08-31 05:00:42 +08:00
|
|
|
GIMP_STOCK_EDIT,
|
|
|
|
_("Edit Channel Attributes"),
|
2003-11-08 23:29:47 +08:00
|
|
|
parent,
|
2002-08-31 05:00:42 +08:00
|
|
|
gimp_standard_help_func,
|
2003-08-21 23:54:47 +08:00
|
|
|
GIMP_HELP_CHANNEL_EDIT,
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2001-11-24 07:04:49 +08:00
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
NULL);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2001-08-12 05:10:44 +08:00
|
|
|
g_object_weak_ref (G_OBJECT (options->query_box),
|
|
|
|
(GWeakNotify) g_free,
|
|
|
|
options);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (options->query_box, "response",
|
|
|
|
G_CALLBACK (edit_channel_query_response),
|
|
|
|
options);
|
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
/* The main hbox */
|
2003-11-06 23:27:05 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
|
2001-04-21 10:11:12 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
|
|
|
|
hbox);
|
|
|
|
|
|
|
|
/* The vbox */
|
|
|
|
vbox = gtk_vbox_new (FALSE, 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
/* The table */
|
|
|
|
table = gtk_table_new (2, 3, FALSE);
|
2002-03-09 02:30:40 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
|
2001-04-21 10:11:12 +08:00
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* The name entry */
|
|
|
|
options->name_entry = gtk_entry_new ();
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (options->name_entry),
|
|
|
|
gimp_object_get_name (GIMP_OBJECT (channel)));
|
2002-03-09 02:30:40 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Channel Name:"), 1.0, 0.5,
|
|
|
|
options->name_entry, 2, FALSE);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
|
|
|
/* The opacity scale */
|
2002-03-09 02:30:40 +08:00
|
|
|
opacity_scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
2002-09-08 20:18:23 +08:00
|
|
|
_("Fill Opacity:"), 100, -1,
|
2002-03-09 02:30:40 +08:00
|
|
|
channel_color.a * 100.0,
|
|
|
|
0.0, 100.0, 1.0, 10.0, 1,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL);
|
2001-04-21 10:11:12 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (opacity_scale_data, "value_changed",
|
2001-07-25 08:42:47 +08:00
|
|
|
G_CALLBACK (channels_opacity_update),
|
|
|
|
options->color_panel);
|
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
/* The color panel */
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
|
|
|
|
TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (options->color_panel);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (options->color_panel, "color_changed",
|
2001-07-25 08:42:47 +08:00
|
|
|
G_CALLBACK (channels_color_changed),
|
2003-09-12 03:52:29 +08:00
|
|
|
opacity_scale_data);
|
2001-07-25 08:42:47 +08:00
|
|
|
|
2001-04-21 10:11:12 +08:00
|
|
|
gtk_widget_show (table);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
gtk_widget_show (options->query_box);
|
|
|
|
}
|
2001-04-29 23:23:01 +08:00
|
|
|
|
2002-02-27 00:30:14 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
channels_opacity_update (GtkAdjustment *adjustment,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
gimp_color_button_get_color (GIMP_COLOR_BUTTON (data), &color);
|
|
|
|
gimp_rgb_set_alpha (&color, adjustment->value / 100.0);
|
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (data), &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
channels_color_changed (GimpColorButton *button,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj = GTK_ADJUSTMENT (data);
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
gimp_color_button_get_color (button, &color);
|
|
|
|
gtk_adjustment_set_value (adj, color.a * 100.0);
|
|
|
|
}
|
|
|
|
|