2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-09-27 10:34:18 +08:00
|
|
|
* 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"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2003-09-27 10:34:18 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2003-09-27 10:34:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
#include "dialogs-types.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
|
|
|
|
2004-05-12 00:01:00 +08:00
|
|
|
#include "widgets/gimpcontainercombobox.h"
|
|
|
|
#include "widgets/gimpcontainerview.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 */
|
|
|
|
|
2004-05-12 00:01:00 +08:00
|
|
|
static void stroke_dialog_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
GtkWidget *dialog);
|
|
|
|
static void stroke_dialog_paint_info_selected (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data,
|
2008-10-24 15:37:46 +08:00
|
|
|
GimpStrokeOptions *options);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public function */
|
|
|
|
|
|
|
|
GtkWidget *
|
2003-09-27 22:41:10 +08:00
|
|
|
stroke_dialog_new (GimpItem *item,
|
2006-09-01 19:26:54 +08:00
|
|
|
GimpContext *context,
|
2004-10-23 18:28:56 +08:00
|
|
|
const gchar *title,
|
2003-09-27 22:41:10 +08:00
|
|
|
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
|
|
|
{
|
2008-10-24 15:37:46 +08:00
|
|
|
GimpStrokeOptions *options;
|
|
|
|
GimpStrokeOptions *saved_options;
|
|
|
|
GimpImage *image;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *radio_box;
|
|
|
|
GtkWidget *libart_radio;
|
|
|
|
GtkWidget *paint_radio;
|
|
|
|
GSList *group;
|
|
|
|
GtkWidget *frame;
|
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);
|
2006-09-01 19:26:54 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2003-09-27 21:46:30 +08:00
|
|
|
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
|
|
|
|
2006-09-01 19:26:54 +08:00
|
|
|
image = gimp_item_get_image (item);
|
2004-10-22 20:32:31 +08:00
|
|
|
|
2008-10-25 16:52:20 +08:00
|
|
|
options = gimp_stroke_options_new (context->gimp, context, TRUE);
|
2004-10-22 20:32:31 +08:00
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
saved_options = g_object_get_data (G_OBJECT (context->gimp),
|
|
|
|
"saved-stroke-options");
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
if (saved_options)
|
|
|
|
gimp_config_sync (G_OBJECT (saved_options), G_OBJECT (options), 0);
|
2003-09-28 04:04:07 +08:00
|
|
|
|
2006-09-01 19:26:54 +08:00
|
|
|
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (item), context,
|
2004-10-23 18:28:56 +08:00
|
|
|
title, "gimp-stroke-options",
|
|
|
|
stock_id,
|
|
|
|
_("Choose Stroke Style"),
|
|
|
|
parent,
|
|
|
|
gimp_standard_help_func,
|
|
|
|
help_id,
|
|
|
|
|
|
|
|
GIMP_STOCK_RESET, RESPONSE_RESET,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
stock_id, GTK_RESPONSE_OK,
|
|
|
|
|
|
|
|
NULL);
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2005-02-09 04:40:33 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
RESPONSE_RESET,
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2004-10-24 03:01:26 +08:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
|
|
|
|
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);
|
2008-10-24 15:37:46 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (dialog), "gimp-stroke-options", options,
|
2003-11-13 20:56:24 +08:00
|
|
|
(GDestroyNotify) g_object_unref);
|
2003-09-27 21:46:30 +08:00
|
|
|
|
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);
|
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
radio_box = gimp_prop_enum_radio_box_new (G_OBJECT (options), "method",
|
|
|
|
-1, -1);
|
2004-10-22 20:32:31 +08:00
|
|
|
|
|
|
|
group = gtk_radio_button_get_group (g_object_get_data (G_OBJECT (radio_box),
|
|
|
|
"radio-button"));
|
|
|
|
|
|
|
|
libart_radio = g_object_ref (group->next->data);
|
|
|
|
gtk_container_remove (GTK_CONTAINER (radio_box), libart_radio);
|
|
|
|
|
2005-09-07 00:00:36 +08:00
|
|
|
paint_radio = g_object_ref (group->data);
|
2004-10-22 20:32:31 +08:00
|
|
|
gtk_container_remove (GTK_CONTAINER (radio_box), paint_radio);
|
|
|
|
|
2006-07-05 21:40:47 +08:00
|
|
|
g_object_ref_sink (radio_box);
|
|
|
|
g_object_unref (radio_box);
|
2004-10-22 20:32:31 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
|
|
|
|
font_desc = pango_font_description_new ();
|
|
|
|
pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
|
|
|
|
|
2008-03-13 00:58:28 +08:00
|
|
|
gtk_widget_modify_font (gtk_bin_get_child (GTK_BIN (libart_radio)),
|
|
|
|
font_desc);
|
|
|
|
gtk_widget_modify_font (gtk_bin_get_child (GTK_BIN (paint_radio)),
|
|
|
|
font_desc);
|
2004-10-22 20:32:31 +08:00
|
|
|
|
|
|
|
pango_font_description_free (font_desc);
|
|
|
|
}
|
|
|
|
|
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-10-22 20:32:31 +08:00
|
|
|
gtk_frame_set_label_widget (GTK_FRAME (frame), libart_radio);
|
|
|
|
g_object_unref (libart_radio);
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2004-10-22 20:32:31 +08:00
|
|
|
g_signal_connect (libart_radio, "toggled",
|
2003-09-27 21:46:30 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_sensitive_update),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
{
|
|
|
|
GtkWidget *stroke_editor;
|
2007-12-27 01:33:41 +08:00
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2007-12-27 01:33:41 +08:00
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
|
2008-10-25 06:34:24 +08:00
|
|
|
stroke_editor = gimp_stroke_editor_new (options, yres, FALSE);
|
2003-09-27 21:46:30 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), stroke_editor);
|
|
|
|
gtk_widget_show (stroke_editor);
|
|
|
|
|
2004-10-22 20:32:31 +08:00
|
|
|
gtk_widget_set_sensitive (stroke_editor,
|
2008-10-24 15:37:46 +08:00
|
|
|
options->method == GIMP_STROKE_METHOD_LIBART);
|
2004-10-22 20:32:31 +08:00
|
|
|
g_object_set_data (G_OBJECT (libart_radio), "set_sensitive", stroke_editor);
|
2003-09-27 21:46:30 +08:00
|
|
|
}
|
2003-09-27 10:34:18 +08:00
|
|
|
|
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
|
|
|
|
2004-10-22 20:32:31 +08:00
|
|
|
gtk_frame_set_label_widget (GTK_FRAME (frame), paint_radio);
|
|
|
|
g_object_unref (paint_radio);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2004-10-22 20:32:31 +08:00
|
|
|
g_signal_connect (paint_radio, "toggled",
|
2003-09-27 21:46:30 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_sensitive_update),
|
|
|
|
NULL);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-09-27 21:46:30 +08:00
|
|
|
{
|
2008-07-21 23:45:53 +08:00
|
|
|
GtkWidget *vbox;
|
2004-10-22 20:32:31 +08:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *combo;
|
2008-07-21 23:45:53 +08:00
|
|
|
GtkWidget *button;
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2008-07-21 23:45:53 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 6);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2008-07-21 23:45:53 +08:00
|
|
|
gtk_widget_set_sensitive (vbox,
|
2008-10-24 15:37:46 +08:00
|
|
|
options->method == GIMP_STROKE_METHOD_PAINT_CORE);
|
2008-07-21 23:45:53 +08:00
|
|
|
g_object_set_data (G_OBJECT (paint_radio), "set_sensitive", vbox);
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2005-08-23 07:39:12 +08:00
|
|
|
label = gtk_label_new (_("Paint tool:"));
|
2003-09-27 21:46:30 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2006-09-11 22:17:43 +08:00
|
|
|
combo = gimp_container_combo_box_new (image->gimp->paint_info_list,
|
|
|
|
context,
|
2004-05-12 00:01:00 +08:00
|
|
|
16, 0);
|
2004-10-22 20:32:31 +08:00
|
|
|
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (combo),
|
2008-10-24 15:37:46 +08:00
|
|
|
GIMP_VIEWABLE (GIMP_CONTEXT (options)->paint_info));
|
2004-05-26 21:39:23 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
|
2004-05-12 00:01:00 +08:00
|
|
|
gtk_widget_show (combo);
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2005-05-28 08:21:58 +08:00
|
|
|
g_signal_connect (combo, "select-item",
|
2003-09-27 21:46:30 +08:00
|
|
|
G_CALLBACK (stroke_dialog_paint_info_selected),
|
2008-10-24 15:37:46 +08:00
|
|
|
options);
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2004-10-22 20:32:31 +08:00
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-tool-menu", combo);
|
2008-07-21 23:45:53 +08:00
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
button = gimp_prop_check_button_new (G_OBJECT (options),
|
2008-07-21 23:45:53 +08:00
|
|
|
"emulate-brush-dynamics",
|
|
|
|
_("_Emulate brush dynamics"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
2003-09-27 21:46:30 +08:00
|
|
|
}
|
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
|
|
|
{
|
2008-10-24 15:37:46 +08:00
|
|
|
GimpStrokeOptions *options;
|
|
|
|
GimpItem *item;
|
|
|
|
GimpImage *image;
|
|
|
|
GimpContext *context;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2004-10-22 20:32:31 +08:00
|
|
|
item = g_object_get_data (G_OBJECT (dialog), "gimp-item");
|
2008-10-24 15:37:46 +08:00
|
|
|
options = g_object_get_data (G_OBJECT (dialog), "gimp-stroke-options");
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2003-11-19 08:48:52 +08:00
|
|
|
image = gimp_item_get_image (item);
|
2006-10-01 19:13:00 +08:00
|
|
|
context = GIMP_VIEWABLE_DIALOG (dialog)->context;
|
2003-09-27 22:41:10 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
switch (response_id)
|
|
|
|
{
|
|
|
|
case RESPONSE_RESET:
|
|
|
|
{
|
2004-10-22 20:32:31 +08:00
|
|
|
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
|
|
|
GtkWidget *combo = g_object_get_data (G_OBJECT (dialog),
|
|
|
|
"gimp-tool-menu");;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
gimp_config_reset (GIMP_CONFIG (options));
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2004-05-12 00:01:00 +08:00
|
|
|
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (combo),
|
2003-11-06 23:27:05 +08:00
|
|
|
GIMP_VIEWABLE (tool_info->paint_info));
|
2003-09-27 10:34:18 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
}
|
|
|
|
break;
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
case GTK_RESPONSE_OK:
|
|
|
|
{
|
2008-10-24 15:37:46 +08:00
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
|
|
|
GimpStrokeOptions *saved_options;
|
|
|
|
GError *error = NULL;
|
2003-09-27 21:46:30 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (! drawable)
|
|
|
|
{
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (context->gimp, G_OBJECT (widget),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
_("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
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
saved_options = g_object_get_data (G_OBJECT (context->gimp),
|
|
|
|
"saved-stroke-options");
|
2003-12-31 00:32:07 +08:00
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
if (saved_options)
|
|
|
|
g_object_ref (saved_options);
|
2003-12-31 00:32:07 +08:00
|
|
|
else
|
2008-10-25 16:52:20 +08:00
|
|
|
saved_options = gimp_stroke_options_new (context->gimp, context, TRUE);
|
2003-12-31 00:32:07 +08:00
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
gimp_config_sync (G_OBJECT (options), G_OBJECT (saved_options), 0);
|
2003-12-31 00:32:07 +08:00
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (context->gimp), "saved-stroke-options",
|
|
|
|
saved_options,
|
2004-10-22 20:32:31 +08:00
|
|
|
(GDestroyNotify) g_object_unref);
|
2003-09-27 22:41:10 +08:00
|
|
|
|
2008-10-24 15:37:46 +08:00
|
|
|
if (! gimp_item_stroke (item, drawable, context, options, FALSE, NULL,
|
2007-12-07 02:40:12 +08:00
|
|
|
&error))
|
|
|
|
{
|
|
|
|
gimp_message (context->gimp, G_OBJECT (widget),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
2004-05-12 00:01:00 +08:00
|
|
|
stroke_dialog_paint_info_selected (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data,
|
2008-10-24 15:37:46 +08:00
|
|
|
GimpStrokeOptions *options)
|
2003-09-27 21:46:30 +08:00
|
|
|
{
|
2008-10-24 15:37:46 +08:00
|
|
|
g_object_set (options, "paint-info", viewable, NULL);
|
2003-09-27 21:46:30 +08:00
|
|
|
}
|