1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "libgimpbase/gimpbase.h"
24
#include "libgimpwidgets/gimpwidgets.h"
26
#include "dialogs-types.h"
28
#include "core/gimp-edit.h"
29
#include "core/gimpcontext.h"
30
#include "core/gimpimage.h"
31
#include "core/gimpimage-undo.h"
32
#include "core/gimpdrawable.h"
33
#include "core/gimpdrawableundo.h"
34
#include "core/gimpundostack.h"
36
#include "widgets/gimppropwidgets.h"
37
#include "widgets/gimphelp-ids.h"
38
#include "widgets/gimpviewabledialog.h"
40
#include "fade-dialog.h"
42
#include "gimp-intl.h"
45
typedef struct _FadeDialog FadeDialog;
50
GimpDrawable *drawable;
54
GimpLayerModeEffects orig_paint_mode;
59
static void fade_dialog_response (GtkWidget *dialog,
63
static void fade_dialog_context_changed (FadeDialog *private);
66
/* public functions */
69
fade_dialog_new (GimpImage *image,
73
GimpDrawableUndo *undo;
74
GimpDrawable *drawable;
85
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
86
g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
88
undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image));
90
if (! (undo && undo->src2_tiles))
93
item = GIMP_ITEM_UNDO (undo)->item;
94
drawable = GIMP_DRAWABLE (item);
96
private = g_new0 (FadeDialog, 1);
98
private->image = image;
99
private->drawable = drawable;
100
private->context = gimp_context_new (image->gimp,
101
"fade-dialog", NULL);
102
private->applied = FALSE;
103
private->orig_paint_mode = undo->paint_mode;
104
private->orig_opacity = undo->opacity;
106
g_object_set (private->context,
107
"paint-mode", undo->paint_mode,
108
"opacity", undo->opacity,
111
title = g_strdup_printf (_("Fade %s"),
112
gimp_object_get_name (GIMP_OBJECT (undo)));
115
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (drawable),
117
title, "gimp-edit-fade",
118
GTK_STOCK_UNDO, title,
120
gimp_standard_help_func,
123
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
124
_("_Fade"), GTK_RESPONSE_OK,
130
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
131
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
136
g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) g_free, private);
138
g_signal_connect (dialog, "response",
139
G_CALLBACK (fade_dialog_response),
142
main_vbox = gtk_vbox_new (FALSE, 12);
143
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
144
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
145
gtk_widget_show (main_vbox);
147
table = gtk_table_new (3, 3, FALSE);
148
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
149
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
150
gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
151
gtk_widget_show (table);
153
/* the paint mode menu */
154
menu = gimp_prop_paint_mode_menu_new (G_OBJECT (private->context),
155
"paint-mode", TRUE, TRUE);
156
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, table_row++,
157
_("_Mode:"), 0.0, 0.5,
160
/* the opacity scale */
161
gimp_prop_opacity_entry_new (G_OBJECT (private->context), "opacity",
162
GTK_TABLE (table), 0, table_row++,
165
g_signal_connect_swapped (private->context, "paint-mode-changed",
166
G_CALLBACK (fade_dialog_context_changed),
168
g_signal_connect_swapped (private->context, "opacity-changed",
169
G_CALLBACK (fade_dialog_context_changed),
176
/* private functions */
179
fade_dialog_response (GtkWidget *dialog,
183
g_signal_handlers_disconnect_by_func (private->context,
184
fade_dialog_context_changed,
187
if (response_id != GTK_RESPONSE_OK && private->applied)
189
g_object_set (private->context,
190
"paint-mode", private->orig_paint_mode,
191
"opacity", private->orig_opacity,
194
fade_dialog_context_changed (private);
197
g_object_unref (private->context);
198
gtk_widget_destroy (dialog);
202
fade_dialog_context_changed (FadeDialog *private)
204
if (gimp_edit_fade (private->image, private->context))
206
private->applied = TRUE;
207
gimp_image_flush (private->image);