2003-09-27 10:34:18 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Henrik Brix Andersen <brix@gimp.org>
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "gui-types.h"
|
|
|
|
|
|
|
|
#include "config/gimpconfig.h"
|
2003-11-13 20:56:24 +08:00
|
|
|
#include "config/gimpconfig-utils.h"
|
2003-09-27 10:34:18 +08:00
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
2003-12-31 00:32:07 +08:00
|
|
|
#include "core/gimppaintinfo.h"
|
2003-09-27 10:34:18 +08:00
|
|
|
#include "core/gimpstrokeoptions.h"
|
2003-09-27 21:46:30 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
#include "widgets/gimpcontainermenuimpl.h"
|
2003-09-27 10:34:18 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
|
|
|
#include "widgets/gimpstrokeeditor.h"
|
|
|
|
|
|
|
|
#include "stroke-dialog.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
#define RESPONSE_RESET 1
|
|
|
|
|
|
|
|
|
2003-09-27 10:34:18 +08:00
|
|
|
/* local functions */
|
|
|
|
|
2003-11-13 20:56:24 +08:00
|
|
|
static void stroke_dialog_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
GtkWidget *dialog);
|
|
|
|
static void stroke_dialog_paint_info_selected (GtkWidget *menu,
|
|
|
|
GimpViewable *viewable,
|
2004-04-15 21:10:51 +08:00
|
|
|
gpointer insert_data,
|
2003-11-13 20:56:24 +08:00
|
|
|
GtkWidget *dialog);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public function */
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *
|
2003-09-27 22:41:10 +08:00
|
|
|
stroke_dialog_new (GimpItem *item,
|
|
|
|
const gchar *stock_id,
|
2003-11-08 23:29:47 +08:00
|
|
|
const gchar *help_id,
|
|
|
|
GtkWidget *parent)
|
2003-09-27 10:34:18 +08:00
|
|
|
{
|
2003-11-19 08:48:52 +08:00
|
|
|
GimpContext *context;
|
2003-11-13 20:56:24 +08:00
|
|
|
GimpStrokeOptions *options;
|
|
|
|
GimpStrokeOptions *saved_options;
|
2003-09-27 22:41:10 +08:00
|
|
|
GimpImage *image;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
GSList *group;
|
|
|
|
GtkWidget *frame;
|
2003-12-31 00:32:07 +08:00
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
gboolean libart_stroking = TRUE;
|
|
|
|
|
2003-09-27 22:41:10 +08:00
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
|
|
|
|
g_return_val_if_fail (stock_id != NULL, NULL);
|
|
|
|
g_return_val_if_fail (help_id != NULL, NULL);
|
2003-11-08 23:29:47 +08:00
|
|
|
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-12-31 00:32:07 +08:00
|
|
|
image = gimp_item_get_image (item);
|
|
|
|
context = gimp_get_user_context (image->gimp);
|
|
|
|
tool_info = gimp_context_get_tool (context);
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2003-11-13 20:56:24 +08:00
|
|
|
options = g_object_new (GIMP_TYPE_STROKE_OPTIONS,
|
|
|
|
"gimp", image->gimp,
|
|
|
|
NULL);
|
2003-12-31 00:32:07 +08:00
|
|
|
g_object_set_data (G_OBJECT (options), "libart-stroking",
|
|
|
|
GINT_TO_POINTER (libart_stroking));
|
|
|
|
g_object_set_data (G_OBJECT (options), "gimp-paint-info",
|
|
|
|
gimp_context_get_tool (context)->paint_info);
|
2003-11-13 20:56:24 +08:00
|
|
|
|
2003-11-19 08:48:52 +08:00
|
|
|
saved_options = g_object_get_data (G_OBJECT (context),
|
2003-11-13 20:56:24 +08:00
|
|
|
"saved-stroke-options");
|
|
|
|
if (saved_options)
|
2003-12-31 00:32:07 +08:00
|
|
|
{
|
|
|
|
gimp_config_sync (GIMP_CONFIG (saved_options), GIMP_CONFIG (options), 0);
|
|
|
|
libart_stroking = GPOINTER_TO_INT (g_object_get_data
|
|
|
|
(G_OBJECT (saved_options),
|
|
|
|
"libart-stroking"));
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (options), "libart-stroking",
|
|
|
|
GINT_TO_POINTER (libart_stroking));
|
|
|
|
g_object_set_data (G_OBJECT (options), "gimp-paint-info",
|
|
|
|
g_object_get_data (G_OBJECT (saved_options),
|
|
|
|
"gimp-paint-info"));
|
|
|
|
}
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-11-19 08:48:52 +08:00
|
|
|
gimp_context_set_parent (GIMP_CONTEXT (options), context);
|
2003-09-28 04:04:07 +08:00
|
|
|
gimp_context_define_properties (GIMP_CONTEXT (options),
|
|
|
|
GIMP_CONTEXT_FOREGROUND_MASK |
|
|
|
|
GIMP_CONTEXT_PATTERN_MASK,
|
|
|
|
FALSE);
|
|
|
|
|
2003-09-27 10:34:18 +08:00
|
|
|
/* the dialog */
|
2003-09-27 21:46:30 +08:00
|
|
|
dialog =
|
2003-09-27 22:41:10 +08:00
|
|
|
gimp_viewable_dialog_new (GIMP_VIEWABLE (item),
|
2003-11-08 01:29:02 +08:00
|
|
|
_("Stroke Options"), "gimp-stroke-options",
|
2003-09-27 21:46:30 +08:00
|
|
|
stock_id,
|
|
|
|
_("Choose Stroke Style"),
|
2003-11-08 23:29:47 +08:00
|
|
|
parent,
|
2003-09-27 21:46:30 +08:00
|
|
|
gimp_standard_help_func,
|
|
|
|
help_id,
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
GIMP_STOCK_RESET, RESPONSE_RESET,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2003-09-27 21:46:30 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (stroke_dialog_response),
|
|
|
|
dialog);
|
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-item", item);
|
2003-11-13 20:56:24 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (dialog), "gimp-stroke-options", options,
|
|
|
|
(GDestroyNotify) g_object_unref);
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2004-05-04 08:15:49 +08:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
|
|
|
|
2004-05-03 23:37:56 +08:00
|
|
|
main_vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
2003-09-27 21:46:30 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
|
|
|
|
gtk_widget_show (main_vbox);
|
|
|
|
|
2003-09-27 22:41:10 +08:00
|
|
|
|
|
|
|
/* the stroke frame */
|
|
|
|
|
2004-05-03 23:37:56 +08:00
|
|
|
frame = gimp_frame_new (NULL);
|
2003-09-27 21:46:30 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2004-05-04 08:15:49 +08:00
|
|
|
button = gtk_radio_button_new_with_label (NULL, _("Stroke Line"));
|
2003-09-27 21:46:30 +08:00
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
|
|
|
|
gtk_frame_set_label_widget (GTK_FRAME (frame), button);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_signal_connect (button, "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_sensitive_update),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-stroke-button", button);
|
|
|
|
|
|
|
|
{
|
|
|
|
GtkWidget *stroke_editor;
|
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
stroke_editor = gimp_stroke_editor_new (options, image->yresolution);
|
2003-09-27 21:46:30 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (stroke_editor), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), stroke_editor);
|
|
|
|
gtk_widget_show (stroke_editor);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (button), "set_sensitive", stroke_editor);
|
|
|
|
}
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-12-31 00:32:07 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), libart_stroking);
|
2003-09-27 22:41:10 +08:00
|
|
|
|
|
|
|
/* the paint tool frame */
|
|
|
|
|
2004-05-03 23:37:56 +08:00
|
|
|
frame = gimp_frame_new (NULL);
|
2003-09-27 21:46:30 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
button = gtk_radio_button_new_with_label (group,
|
2004-05-04 08:15:49 +08:00
|
|
|
_("Stroke With a Paint Tool"));
|
2003-09-27 21:46:30 +08:00
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
|
|
|
|
gtk_frame_set_label_widget (GTK_FRAME (frame), button);
|
|
|
|
gtk_widget_show (button);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
g_signal_connect (button, "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_sensitive_update),
|
|
|
|
NULL);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
{
|
2003-12-31 00:32:07 +08:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *optionmenu;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GimpPaintInfo *paint_info;
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), hbox);
|
|
|
|
gtk_widget_show (hbox);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (hbox), FALSE);
|
|
|
|
g_object_set_data (G_OBJECT (button), "set_sensitive", hbox);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
label = gtk_label_new (_("Paint Tool:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
optionmenu = gtk_option_menu_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), optionmenu, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (optionmenu);
|
|
|
|
|
|
|
|
menu = gimp_container_menu_new (image->gimp->paint_info_list, NULL,
|
|
|
|
16, 0);
|
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu);
|
|
|
|
gtk_widget_show (menu);
|
|
|
|
|
|
|
|
g_signal_connect (menu, "select_item",
|
|
|
|
G_CALLBACK (stroke_dialog_paint_info_selected),
|
|
|
|
dialog);
|
|
|
|
|
2003-12-31 00:32:07 +08:00
|
|
|
paint_info = GIMP_PAINT_INFO (g_object_get_data (G_OBJECT (options),
|
|
|
|
"gimp-paint-info"));
|
2003-09-27 21:46:30 +08:00
|
|
|
gimp_container_menu_select_item (GIMP_CONTAINER_MENU (menu),
|
2003-12-31 00:32:07 +08:00
|
|
|
GIMP_VIEWABLE (paint_info));
|
2003-09-27 21:46:30 +08:00
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-tool-menu", menu);
|
2003-12-31 00:32:07 +08:00
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-paint-info", paint_info);
|
2003-09-27 21:46:30 +08:00
|
|
|
}
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-12-31 00:32:07 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), !libart_stroking);
|
|
|
|
|
2003-09-27 10:34:18 +08:00
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-27 22:41:10 +08:00
|
|
|
/* private functions */
|
2003-09-27 10:34:18 +08:00
|
|
|
|
|
|
|
static void
|
2003-11-06 23:27:05 +08:00
|
|
|
stroke_dialog_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
GtkWidget *dialog)
|
2003-09-27 10:34:18 +08:00
|
|
|
{
|
2003-11-19 08:48:52 +08:00
|
|
|
GimpContext *context;
|
|
|
|
GimpItem *item;
|
|
|
|
GtkWidget *button;
|
|
|
|
GimpImage *image;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
item = g_object_get_data (G_OBJECT (dialog), "gimp-item");
|
|
|
|
button = g_object_get_data (G_OBJECT (dialog), "gimp-stroke-button");
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2003-11-19 08:48:52 +08:00
|
|
|
image = gimp_item_get_image (item);
|
|
|
|
context = gimp_get_user_context (image->gimp);
|
2003-09-27 22:41:10 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
switch (response_id)
|
|
|
|
{
|
|
|
|
case RESPONSE_RESET:
|
|
|
|
{
|
|
|
|
GObject *options;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
|
|
|
|
options = g_object_get_data (G_OBJECT (dialog), "gimp-stroke-options");
|
|
|
|
menu = g_object_get_data (G_OBJECT (dialog), "gimp-tool-menu");
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2003-11-19 08:48:52 +08:00
|
|
|
tool_info = gimp_context_get_tool (context);
|
2003-10-11 22:30:18 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
|
|
|
|
gimp_container_menu_select_item (GIMP_CONTAINER_MENU (menu),
|
|
|
|
GIMP_VIEWABLE (tool_info->paint_info));
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_config_reset (GIMP_CONFIG (options));
|
|
|
|
}
|
|
|
|
break;
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
case GTK_RESPONSE_OK:
|
|
|
|
{
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
GimpObject *options;
|
2003-12-31 00:32:07 +08:00
|
|
|
GObject *saved_options;
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
drawable = gimp_image_active_drawable (image);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (! drawable)
|
|
|
|
{
|
2003-11-14 23:33:40 +08:00
|
|
|
g_message (_("There is no active layer or channel to stroke to."));
|
2003-11-06 23:27:05 +08:00
|
|
|
return;
|
|
|
|
}
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-12-31 00:32:07 +08:00
|
|
|
saved_options = g_object_get_data (G_OBJECT (context),
|
|
|
|
"saved-stroke-options");
|
|
|
|
options = g_object_get_data (G_OBJECT (dialog),
|
|
|
|
"gimp-stroke-options");
|
|
|
|
|
|
|
|
if (saved_options)
|
|
|
|
{
|
|
|
|
gimp_config_sync (GIMP_CONFIG (options),
|
|
|
|
GIMP_CONFIG (saved_options), 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_set_data_full (G_OBJECT (context),
|
|
|
|
"saved-stroke-options",
|
|
|
|
g_object_ref (options),
|
|
|
|
(GDestroyNotify) g_object_unref);
|
|
|
|
saved_options = G_OBJECT (options);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_set_data (saved_options, "gimp-paint-info",
|
|
|
|
g_object_get_data (G_OBJECT (dialog),
|
|
|
|
"gimp-paint-info"));
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
|
2003-11-13 20:56:24 +08:00
|
|
|
{
|
2003-12-31 00:32:07 +08:00
|
|
|
g_object_set_data (saved_options, "libart-stroking",
|
|
|
|
GINT_TO_POINTER (TRUE));
|
2003-11-13 20:56:24 +08:00
|
|
|
}
|
2003-11-06 23:27:05 +08:00
|
|
|
else
|
2003-11-13 20:56:24 +08:00
|
|
|
{
|
2003-12-31 00:32:07 +08:00
|
|
|
g_object_set_data (saved_options, "libart-stroking",
|
|
|
|
GINT_TO_POINTER (FALSE));
|
2003-11-13 20:56:24 +08:00
|
|
|
options = g_object_get_data (G_OBJECT (dialog), "gimp-paint-info");
|
|
|
|
}
|
2003-09-27 22:41:10 +08:00
|
|
|
|
2004-04-15 21:10:51 +08:00
|
|
|
gimp_item_stroke (item, drawable, context, options, FALSE);
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
2003-11-13 20:56:24 +08:00
|
|
|
/* fallthrough */
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
break;
|
|
|
|
}
|
2003-09-27 10:34:18 +08:00
|
|
|
}
|
2003-09-27 21:46:30 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
stroke_dialog_paint_info_selected (GtkWidget *menu,
|
|
|
|
GimpViewable *viewable,
|
2004-04-15 21:10:51 +08:00
|
|
|
gpointer insert_data,
|
2003-09-27 21:46:30 +08:00
|
|
|
GtkWidget *dialog)
|
|
|
|
{
|
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-paint-info", viewable);
|
|
|
|
}
|