2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-10-19 17:17:37 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-10-19 17:17:37 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-10-19 17:17:37 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-10-19 17:17:37 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2004-10-19 17:17:37 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "dialogs-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
|
|
|
#include "widgets/gimpcolorpanel.h"
|
2016-10-08 23:00:38 +08:00
|
|
|
#include "widgets/gimpspinscale.h"
|
2004-10-19 17:17:37 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
|
|
|
|
|
|
|
#include "channel-options-dialog.h"
|
2016-10-26 22:51:56 +08:00
|
|
|
#include "item-options-dialog.h"
|
2004-10-19 17:17:37 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2016-09-25 04:10:32 +08:00
|
|
|
typedef struct _ChannelOptionsDialog ChannelOptionsDialog;
|
|
|
|
|
|
|
|
struct _ChannelOptionsDialog
|
|
|
|
{
|
|
|
|
GimpChannelOptionsCallback callback;
|
|
|
|
gpointer user_data;
|
|
|
|
|
|
|
|
GtkWidget *color_panel;
|
2016-10-26 22:51:56 +08:00
|
|
|
GtkWidget *save_sel_toggle;
|
2016-09-25 04:10:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-10-19 17:17:37 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2016-10-26 22:51:56 +08:00
|
|
|
static void channel_options_dialog_free (ChannelOptionsDialog *private);
|
|
|
|
static void channel_options_dialog_callback (GtkWidget *dialog,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item,
|
|
|
|
GimpContext *context,
|
|
|
|
const gchar *item_name,
|
|
|
|
gboolean item_visible,
|
|
|
|
gboolean item_linked,
|
2016-10-29 22:50:13 +08:00
|
|
|
GimpColorTag item_color_tag,
|
2016-10-26 22:51:56 +08:00
|
|
|
gboolean item_lock_content,
|
|
|
|
gboolean item_lock_position,
|
|
|
|
gpointer user_data);
|
|
|
|
static void channel_options_opacity_changed (GtkAdjustment *adjustment,
|
2016-09-25 04:10:32 +08:00
|
|
|
GimpColorButton *color_button);
|
|
|
|
static void channel_options_color_changed (GimpColorButton *color_button,
|
|
|
|
GtkAdjustment *adjustment);
|
2004-10-19 17:17:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2016-09-25 04:10:32 +08:00
|
|
|
GtkWidget *
|
|
|
|
channel_options_dialog_new (GimpImage *image,
|
|
|
|
GimpChannel *channel,
|
|
|
|
GimpContext *context,
|
|
|
|
GtkWidget *parent,
|
|
|
|
const gchar *title,
|
|
|
|
const gchar *role,
|
|
|
|
const gchar *icon_name,
|
|
|
|
const gchar *desc,
|
|
|
|
const gchar *help_id,
|
|
|
|
const gchar *color_label,
|
|
|
|
const gchar *opacity_label,
|
|
|
|
gboolean show_from_sel,
|
2016-10-26 22:51:56 +08:00
|
|
|
const gchar *channel_name,
|
|
|
|
const GimpRGB *channel_color,
|
|
|
|
gboolean channel_visible,
|
|
|
|
gboolean channel_linked,
|
2016-10-29 22:50:13 +08:00
|
|
|
GimpColorTag channel_color_tag,
|
2016-10-26 22:51:56 +08:00
|
|
|
gboolean channel_lock_content,
|
|
|
|
gboolean channel_lock_position,
|
2016-09-25 04:10:32 +08:00
|
|
|
GimpChannelOptionsCallback callback,
|
|
|
|
gpointer user_data)
|
2004-10-19 17:17:37 +08:00
|
|
|
{
|
2016-09-25 04:10:32 +08:00
|
|
|
ChannelOptionsDialog *private;
|
|
|
|
GtkWidget *dialog;
|
2016-10-08 23:00:38 +08:00
|
|
|
GtkAdjustment *opacity_adj;
|
|
|
|
GtkWidget *scale;
|
2004-10-19 17:17:37 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2004-10-19 17:17:37 +08:00
|
|
|
g_return_val_if_fail (channel == NULL || GIMP_IS_CHANNEL (channel), NULL);
|
2006-09-01 19:26:54 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2004-10-19 17:17:37 +08:00
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
|
|
|
|
g_return_val_if_fail (title != NULL, NULL);
|
|
|
|
g_return_val_if_fail (role != NULL, NULL);
|
2014-05-07 21:30:38 +08:00
|
|
|
g_return_val_if_fail (icon_name != NULL, NULL);
|
2004-10-19 17:17:37 +08:00
|
|
|
g_return_val_if_fail (desc != NULL, NULL);
|
|
|
|
g_return_val_if_fail (help_id != NULL, NULL);
|
2016-09-24 22:04:13 +08:00
|
|
|
g_return_val_if_fail (channel_color != NULL, NULL);
|
2004-10-19 17:17:37 +08:00
|
|
|
g_return_val_if_fail (color_label != NULL, NULL);
|
|
|
|
g_return_val_if_fail (opacity_label != NULL, NULL);
|
2016-09-25 04:10:32 +08:00
|
|
|
g_return_val_if_fail (callback != NULL, NULL);
|
2004-10-19 17:17:37 +08:00
|
|
|
|
2016-09-25 04:10:32 +08:00
|
|
|
private = g_slice_new0 (ChannelOptionsDialog);
|
2004-10-19 17:17:37 +08:00
|
|
|
|
2016-09-25 04:10:32 +08:00
|
|
|
private->callback = callback;
|
|
|
|
private->user_data = user_data;
|
2004-10-19 17:17:37 +08:00
|
|
|
|
2016-10-26 22:51:56 +08:00
|
|
|
dialog = item_options_dialog_new (image, GIMP_ITEM (channel), context,
|
|
|
|
parent, title, role,
|
|
|
|
icon_name, desc, help_id,
|
|
|
|
channel_name ? _("Channel _name:") : NULL,
|
2017-03-05 23:01:59 +08:00
|
|
|
GIMP_ICON_TOOL_PAINTBRUSH,
|
2016-10-26 22:51:56 +08:00
|
|
|
_("Lock _pixels"),
|
|
|
|
_("Lock position and _size"),
|
|
|
|
channel_name,
|
|
|
|
channel_visible,
|
|
|
|
channel_linked,
|
2016-10-29 22:50:13 +08:00
|
|
|
channel_color_tag,
|
2016-10-26 22:51:56 +08:00
|
|
|
channel_lock_content,
|
|
|
|
channel_lock_position,
|
|
|
|
channel_options_dialog_callback,
|
|
|
|
private);
|
2005-02-09 04:40:33 +08:00
|
|
|
|
2016-09-25 04:10:32 +08:00
|
|
|
g_object_weak_ref (G_OBJECT (dialog),
|
|
|
|
(GWeakNotify) channel_options_dialog_free, private);
|
|
|
|
|
2016-10-08 23:00:38 +08:00
|
|
|
opacity_adj = (GtkAdjustment *)
|
|
|
|
gtk_adjustment_new (channel_color->a * 100.0,
|
|
|
|
0.0, 100.0, 1.0, 10.0, 0);
|
2016-10-26 22:51:56 +08:00
|
|
|
scale = gimp_spin_scale_new (opacity_adj, NULL, 1);
|
2016-10-08 23:00:38 +08:00
|
|
|
gtk_widget_set_size_request (scale, 200, -1);
|
2016-10-26 22:51:56 +08:00
|
|
|
item_options_dialog_add_widget (dialog,
|
|
|
|
opacity_label, scale);
|
2004-10-19 17:17:37 +08:00
|
|
|
|
2016-09-25 04:10:32 +08:00
|
|
|
private->color_panel = gimp_color_panel_new (color_label,
|
|
|
|
channel_color,
|
|
|
|
GIMP_COLOR_AREA_LARGE_CHECKS,
|
2016-10-26 22:51:56 +08:00
|
|
|
24, 24);
|
2016-09-25 04:10:32 +08:00
|
|
|
gimp_color_panel_set_context (GIMP_COLOR_PANEL (private->color_panel),
|
|
|
|
context);
|
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (opacity_adj, "value-changed",
|
2016-10-26 22:51:56 +08:00
|
|
|
G_CALLBACK (channel_options_opacity_changed),
|
2016-09-25 04:10:32 +08:00
|
|
|
private->color_panel);
|
2004-10-19 17:17:37 +08:00
|
|
|
|
2016-09-25 04:10:32 +08:00
|
|
|
g_signal_connect (private->color_panel, "color-changed",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_CALLBACK (channel_options_color_changed),
|
|
|
|
opacity_adj);
|
2004-10-19 17:17:37 +08:00
|
|
|
|
2016-10-26 22:51:56 +08:00
|
|
|
item_options_dialog_add_widget (dialog,
|
|
|
|
NULL, private->color_panel);
|
|
|
|
|
2005-05-26 12:12:31 +08:00
|
|
|
if (show_from_sel)
|
|
|
|
{
|
2016-10-26 22:51:56 +08:00
|
|
|
private->save_sel_toggle =
|
2005-05-26 18:01:04 +08:00
|
|
|
gtk_check_button_new_with_mnemonic (_("Initialize from _selection"));
|
2005-05-26 12:12:31 +08:00
|
|
|
|
2016-10-26 22:51:56 +08:00
|
|
|
item_options_dialog_add_widget (dialog,
|
|
|
|
NULL, private->save_sel_toggle);
|
2005-05-26 12:12:31 +08:00
|
|
|
}
|
2005-05-26 18:01:04 +08:00
|
|
|
|
2016-09-25 04:10:32 +08:00
|
|
|
return dialog;
|
2004-10-19 17:17:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2016-10-26 22:51:56 +08:00
|
|
|
channel_options_dialog_free (ChannelOptionsDialog *private)
|
2016-09-25 04:10:32 +08:00
|
|
|
{
|
2016-10-26 22:51:56 +08:00
|
|
|
g_slice_free (ChannelOptionsDialog, private);
|
2016-09-25 04:10:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-10-29 22:50:13 +08:00
|
|
|
channel_options_dialog_callback (GtkWidget *dialog,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item,
|
|
|
|
GimpContext *context,
|
|
|
|
const gchar *item_name,
|
|
|
|
gboolean item_visible,
|
|
|
|
gboolean item_linked,
|
|
|
|
GimpColorTag item_color_tag,
|
|
|
|
gboolean item_lock_content,
|
|
|
|
gboolean item_lock_position,
|
|
|
|
gpointer user_data)
|
2004-10-19 17:17:37 +08:00
|
|
|
{
|
2016-10-26 22:51:56 +08:00
|
|
|
ChannelOptionsDialog *private = user_data;
|
|
|
|
GimpRGB color;
|
|
|
|
gboolean save_selection = FALSE;
|
|
|
|
|
|
|
|
gimp_color_button_get_color (GIMP_COLOR_BUTTON (private->color_panel),
|
|
|
|
&color);
|
|
|
|
|
|
|
|
if (private->save_sel_toggle)
|
|
|
|
save_selection =
|
|
|
|
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (private->save_sel_toggle));
|
|
|
|
|
|
|
|
private->callback (dialog,
|
|
|
|
image,
|
|
|
|
GIMP_CHANNEL (item),
|
|
|
|
context,
|
|
|
|
item_name,
|
|
|
|
&color,
|
|
|
|
save_selection,
|
|
|
|
item_visible,
|
|
|
|
item_linked,
|
2016-10-29 22:50:13 +08:00
|
|
|
item_color_tag,
|
2016-10-26 22:51:56 +08:00
|
|
|
item_lock_content,
|
|
|
|
item_lock_position,
|
|
|
|
private->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
channel_options_opacity_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpColorButton *color_button)
|
|
|
|
{
|
|
|
|
GimpRGB color;
|
2004-10-19 17:17:37 +08:00
|
|
|
|
2016-09-25 04:10:32 +08:00
|
|
|
gimp_color_button_get_color (color_button, &color);
|
2008-06-29 21:41:24 +08:00
|
|
|
gimp_rgb_set_alpha (&color, gtk_adjustment_get_value (adjustment) / 100.0);
|
2016-09-25 04:10:32 +08:00
|
|
|
gimp_color_button_set_color (color_button, &color);
|
2004-10-19 17:17:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
channel_options_color_changed (GimpColorButton *button,
|
2016-09-25 04:10:32 +08:00
|
|
|
GtkAdjustment *adjustment)
|
2004-10-19 17:17:37 +08:00
|
|
|
{
|
2016-10-26 22:51:56 +08:00
|
|
|
GimpRGB color;
|
2004-10-19 17:17:37 +08:00
|
|
|
|
|
|
|
gimp_color_button_get_color (button, &color);
|
2016-09-25 04:10:32 +08:00
|
|
|
gtk_adjustment_set_value (adjustment, color.a * 100.0);
|
2004-10-19 17:17:37 +08:00
|
|
|
}
|