1999-07-07 11:18:54 +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.
|
|
|
|
*/
|
1999-09-06 08:07:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-01-24 02:49:44 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 02:49:44 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
#include "gui-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2002-12-04 06:16:56 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpimage.h"
|
2001-11-30 22:41:56 +08:00
|
|
|
#include "core/gimpimage-qmask.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-04-11 09:13:53 +08:00
|
|
|
#include "widgets/gimpcolorpanel.h"
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2002-08-31 05:00:42 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
2001-04-11 09:13:53 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-11-11 03:10:28 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
#include "qmask-commands.h"
|
1999-07-07 11:18:54 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
1999-07-07 11:18:54 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
typedef struct _EditQmaskOptions EditQmaskOptions;
|
|
|
|
|
1999-08-08 04:55:26 +08:00
|
|
|
struct _EditQmaskOptions
|
|
|
|
{
|
2001-07-08 06:49:01 +08:00
|
|
|
GtkWidget *query_box;
|
|
|
|
GtkWidget *name_entry;
|
|
|
|
GtkWidget *color_panel;
|
1999-08-08 04:55:26 +08:00
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
GimpImage *gimage;
|
1999-08-08 04:55:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-11-11 03:10:28 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
static void qmask_channel_query (GimpDisplayShell *shell);
|
2003-08-22 09:42:57 +08:00
|
|
|
static void qmask_query_ok_callback (GtkWidget *widget,
|
2003-01-11 01:55:53 +08:00
|
|
|
gpointer client_data);
|
|
|
|
static void qmask_query_scale_update (GtkAdjustment *adjustment,
|
|
|
|
gpointer data);
|
|
|
|
static void qmask_query_color_changed (GimpColorButton *button,
|
|
|
|
gpointer data);
|
2001-11-30 22:41:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functionss */
|
|
|
|
|
|
|
|
void
|
|
|
|
qmask_toggle_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data,
|
|
|
|
guint action)
|
1999-08-08 04:55:26 +08:00
|
|
|
{
|
2001-11-30 22:41:56 +08:00
|
|
|
GimpDisplayShell *shell;
|
2001-01-15 12:37:01 +08:00
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (data);
|
1999-08-08 04:55:26 +08:00
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
if (GTK_CHECK_MENU_ITEM (widget)->active != shell->gdisp->gimage->qmask_state)
|
|
|
|
{
|
|
|
|
gimp_image_set_qmask_state (shell->gdisp->gimage,
|
|
|
|
GTK_CHECK_MENU_ITEM (widget)->active);
|
2001-07-31 01:17:36 +08:00
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
gimp_image_flush (shell->gdisp->gimage);
|
|
|
|
}
|
1999-08-08 04:55:26 +08:00
|
|
|
}
|
|
|
|
|
1999-07-07 11:18:54 +08:00
|
|
|
void
|
2001-11-30 22:41:56 +08:00
|
|
|
qmask_invert_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data,
|
|
|
|
guint action)
|
1999-07-07 11:18:54 +08:00
|
|
|
{
|
2001-11-30 22:41:56 +08:00
|
|
|
GimpDisplayShell *shell;
|
1999-07-07 11:18:54 +08:00
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (data);
|
2001-11-30 00:44:51 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
if (GTK_CHECK_MENU_ITEM (widget)->active)
|
1999-09-28 01:58:10 +08:00
|
|
|
{
|
2003-01-11 01:55:53 +08:00
|
|
|
if (action != shell->gdisp->gimage->qmask_inverted)
|
|
|
|
{
|
|
|
|
gimp_image_qmask_invert (shell->gdisp->gimage);
|
2001-11-10 22:17:01 +08:00
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
if (shell->gdisp->gimage->qmask_state)
|
|
|
|
gimp_image_flush (shell->gdisp->gimage);
|
|
|
|
}
|
2001-11-30 22:41:56 +08:00
|
|
|
}
|
|
|
|
}
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
void
|
|
|
|
qmask_configure_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data,
|
|
|
|
guint action)
|
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
2000-06-08 06:51:23 +08:00
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (data);
|
2001-01-20 21:21:49 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
qmask_channel_query (shell);
|
|
|
|
}
|
2001-07-07 20:17:23 +08:00
|
|
|
|
2001-11-11 03:10:28 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
1999-08-08 04:55:26 +08:00
|
|
|
static void
|
2001-11-30 22:41:56 +08:00
|
|
|
qmask_channel_query (GimpDisplayShell *shell)
|
1999-08-08 04:55:26 +08:00
|
|
|
{
|
|
|
|
EditQmaskOptions *options;
|
2001-01-15 12:37:01 +08:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *opacity_scale;
|
|
|
|
GtkObject *opacity_scale_data;
|
1999-08-08 04:55:26 +08:00
|
|
|
|
|
|
|
/* the new options structure */
|
2001-01-20 21:21:49 +08:00
|
|
|
options = g_new0 (EditQmaskOptions, 1);
|
1999-08-08 04:55:26 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
options->gimage = shell->gdisp->gimage;
|
2001-01-21 21:41:07 +08:00
|
|
|
options->color_panel = gimp_color_panel_new (_("Edit Qmask Color"),
|
|
|
|
&options->gimage->qmask_color,
|
2003-08-22 09:42:57 +08:00
|
|
|
GIMP_COLOR_AREA_LARGE_CHECKS,
|
2001-01-15 14:24:24 +08:00
|
|
|
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));
|
1999-08-08 04:55:26 +08:00
|
|
|
|
|
|
|
/* The dialog */
|
1999-09-28 01:58:10 +08:00
|
|
|
options->query_box =
|
2002-08-31 05:00:42 +08:00
|
|
|
gimp_viewable_dialog_new (GIMP_VIEWABLE (shell->gdisp->gimage),
|
|
|
|
_("Qmask Attributes"), "edit_qmask_attributes",
|
|
|
|
GIMP_STOCK_QMASK_ON,
|
|
|
|
_("Edit QuickMask Attributes"),
|
|
|
|
gimp_standard_help_func,
|
2003-08-22 09:42:57 +08:00
|
|
|
GIMP_HELP_QMASK_EDIT,
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2002-09-08 20:18:23 +08:00
|
|
|
GTK_STOCK_CANCEL, gtk_widget_destroy,
|
|
|
|
NULL, 1, NULL, FALSE, TRUE,
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
GTK_STOCK_OK, qmask_query_ok_callback,
|
|
|
|
options, NULL, NULL, TRUE, FALSE,
|
2001-11-24 07:04:49 +08:00
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
NULL);
|
1999-08-08 04:55:26 +08:00
|
|
|
|
2002-09-08 20:18:23 +08:00
|
|
|
g_object_weak_ref (G_OBJECT (options->query_box),
|
2003-01-05 09:30:33 +08:00
|
|
|
(GWeakNotify) g_free, options);
|
2002-09-08 20:18:23 +08:00
|
|
|
|
1999-08-08 04:55:26 +08:00
|
|
|
/* The main hbox */
|
2001-07-31 01:17:36 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
1999-08-08 04:55:26 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
|
|
|
|
hbox);
|
2001-07-31 01:17:36 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
1999-08-08 04:55:26 +08:00
|
|
|
/* The vbox */
|
|
|
|
vbox = gtk_vbox_new (FALSE, 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
|
2001-07-31 01:17:36 +08:00
|
|
|
gtk_widget_show (vbox);
|
1999-08-08 04:55:26 +08:00
|
|
|
|
|
|
|
/* The table */
|
2001-07-31 01:17:36 +08:00
|
|
|
table = gtk_table_new (1, 2, FALSE);
|
1999-08-08 04:55:26 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
2001-07-31 01:17:36 +08:00
|
|
|
gtk_widget_show (table);
|
1999-08-08 04:55:26 +08:00
|
|
|
|
|
|
|
/* The opacity scale */
|
|
|
|
opacity_scale_data =
|
2003-08-22 09:42:57 +08:00
|
|
|
gtk_adjustment_new (options->gimage->qmask_color.a * 100.0,
|
2001-01-15 14:24:24 +08:00
|
|
|
0.0, 100.0, 1.0, 1.0, 0.0);
|
1999-08-08 04:55:26 +08:00
|
|
|
opacity_scale = gtk_hscale_new (GTK_ADJUSTMENT (opacity_scale_data));
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_set_size_request (opacity_scale, 100, -1);
|
1999-08-08 04:55:26 +08:00
|
|
|
gtk_scale_set_value_pos (GTK_SCALE (opacity_scale), GTK_POS_TOP);
|
2001-07-31 01:17:36 +08:00
|
|
|
|
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Mask Opacity:"), 1.0, 1.0,
|
|
|
|
opacity_scale, 1, FALSE);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (opacity_scale_data, "value_changed",
|
2001-07-31 01:17:36 +08:00
|
|
|
G_CALLBACK (qmask_query_scale_update),
|
|
|
|
options->color_panel);
|
1999-08-08 04:55:26 +08:00
|
|
|
|
|
|
|
/* The color panel */
|
2001-01-15 14:24:24 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
|
1999-08-08 04:55:26 +08:00
|
|
|
TRUE, TRUE, 0);
|
2001-01-15 14:24:24 +08:00
|
|
|
gtk_widget_show (options->color_panel);
|
1999-08-08 04:55:26 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (options->color_panel, "color_changed",
|
2001-11-30 22:41:56 +08:00
|
|
|
G_CALLBACK (qmask_query_color_changed),
|
2003-08-22 09:42:57 +08:00
|
|
|
opacity_scale_data);
|
2001-07-31 01:17:36 +08:00
|
|
|
|
1999-08-08 04:55:26 +08:00
|
|
|
gtk_widget_show (options->query_box);
|
|
|
|
}
|
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
static void
|
|
|
|
qmask_query_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1999-08-08 04:55:26 +08:00
|
|
|
{
|
|
|
|
EditQmaskOptions *options;
|
2001-01-29 10:45:02 +08:00
|
|
|
GimpChannel *channel;
|
2001-01-15 14:24:24 +08:00
|
|
|
GimpRGB color;
|
2001-01-15 09:48:53 +08:00
|
|
|
|
2001-01-20 21:21:49 +08:00
|
|
|
options = (EditQmaskOptions *) data;
|
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
|
2001-01-15 09:48:53 +08:00
|
|
|
|
2001-01-15 12:37:01 +08:00
|
|
|
if (options->gimage && channel)
|
|
|
|
{
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_button_get_color (GIMP_COLOR_BUTTON (options->color_panel),
|
|
|
|
&color);
|
|
|
|
|
|
|
|
if (gimp_rgba_distance (&color, &channel->color) > 0.0001)
|
2001-01-15 09:48:53 +08:00
|
|
|
{
|
2003-03-17 10:25:39 +08:00
|
|
|
gimp_channel_set_color (channel, &color, TRUE);
|
2001-01-30 01:54:02 +08:00
|
|
|
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (options->gimage);
|
2000-01-21 01:10:49 +08:00
|
|
|
}
|
1999-08-08 04:55:26 +08:00
|
|
|
}
|
2001-01-15 09:48:53 +08:00
|
|
|
|
1999-08-08 04:55:26 +08:00
|
|
|
/* update the qmask color no matter what */
|
2001-01-15 14:24:24 +08:00
|
|
|
options->gimage->qmask_color = color;
|
1999-08-08 04:55:26 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (options->query_box);
|
|
|
|
}
|
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
static void
|
|
|
|
qmask_query_scale_update (GtkAdjustment *adjustment,
|
2001-11-11 03:10:28 +08:00
|
|
|
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
|
2001-11-30 22:41:56 +08:00
|
|
|
qmask_query_color_changed (GimpColorButton *button,
|
|
|
|
gpointer data)
|
2001-11-11 03:10:28 +08:00
|
|
|
{
|
|
|
|
GtkAdjustment *adj = GTK_ADJUSTMENT (data);
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
gimp_color_button_get_color (button, &color);
|
|
|
|
gtk_adjustment_set_value (adj, color.a * 100.0);
|
|
|
|
}
|