Commit 0932386d authored by Michael Natterer's avatar Michael Natterer 😴

app: add a callback to the stroke dialog

and move the actual stroking code to select-commands.c,
vectors-commands.c and gimpvectorstool.c. Remember the active drawable
so the stroke always happens on the drawable the dialog was invoked
with.
parent 81603eaa
...@@ -54,28 +54,34 @@ ...@@ -54,28 +54,34 @@
/* local function prototypes */ /* local function prototypes */
static void select_feather_callback (GtkWidget *widget, static void select_feather_callback (GtkWidget *widget,
gdouble size, gdouble size,
GimpUnit unit, GimpUnit unit,
gpointer data); gpointer data);
static void select_border_callback (GtkWidget *widget, static void select_border_callback (GtkWidget *widget,
gdouble size, gdouble size,
GimpUnit unit, GimpUnit unit,
gpointer data); gpointer data);
static void select_grow_callback (GtkWidget *widget, static void select_grow_callback (GtkWidget *widget,
gdouble size, gdouble size,
GimpUnit unit, GimpUnit unit,
gpointer data); gpointer data);
static void select_shrink_callback (GtkWidget *widget, static void select_shrink_callback (GtkWidget *widget,
gdouble size, gdouble size,
GimpUnit unit, GimpUnit unit,
gpointer data); gpointer data);
static void select_fill_callback (GtkWidget *dialog, static void select_fill_callback (GtkWidget *dialog,
GimpItem *item, GimpItem *item,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpContext *context, GimpContext *context,
GimpFillOptions *options, GimpFillOptions *options,
gpointer data); gpointer data);
static void select_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data);
/* public functions */ /* public functions */
...@@ -498,12 +504,18 @@ select_stroke_cmd_callback (GtkAction *action, ...@@ -498,12 +504,18 @@ select_stroke_cmd_callback (GtkAction *action,
if (! dialog) if (! dialog)
{ {
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
dialog = stroke_dialog_new (GIMP_ITEM (gimp_image_get_mask (image)), dialog = stroke_dialog_new (GIMP_ITEM (gimp_image_get_mask (image)),
drawable,
action_data_get_context (data), action_data_get_context (data),
_("Stroke Selection"), _("Stroke Selection"),
GIMP_STOCK_SELECTION_STROKE, GIMP_STOCK_SELECTION_STROKE,
GIMP_HELP_SELECTION_STROKE, GIMP_HELP_SELECTION_STROKE,
widget); widget,
config->stroke_options,
select_stroke_callback,
NULL);
dialogs_attach_dialog (G_OBJECT (drawable), STROKE_DIALOG_KEY, dialog); dialogs_attach_dialog (G_OBJECT (drawable), STROKE_DIALOG_KEY, dialog);
} }
...@@ -762,3 +774,35 @@ select_fill_callback (GtkWidget *dialog, ...@@ -762,3 +774,35 @@ select_fill_callback (GtkWidget *dialog,
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
} }
static void
select_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (context->gimp->config);
GimpImage *image = gimp_item_get_image (item);
GError *error = NULL;
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->stroke_options), 0);
if (! gimp_item_stroke (item, drawable, context, options, NULL,
TRUE, NULL, &error))
{
gimp_message_literal (context->gimp,
G_OBJECT (dialog),
GIMP_MESSAGE_WARNING,
error ? error->message : "NULL");
g_clear_error (&error);
return;
}
gimp_image_flush (image);
gtk_widget_destroy (dialog);
}
...@@ -90,6 +90,12 @@ static void vectors_fill_callback (GtkWidget *dialog, ...@@ -90,6 +90,12 @@ static void vectors_fill_callback (GtkWidget *dialog,
GimpContext *context, GimpContext *context,
GimpFillOptions *options, GimpFillOptions *options,
gpointer user_data); gpointer user_data);
static void vectors_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer user_data);
static void vectors_import_response (GtkWidget *widget, static void vectors_import_response (GtkWidget *widget,
gint response_id, gint response_id,
VectorsImportDialog *dialog); VectorsImportDialog *dialog);
...@@ -503,12 +509,18 @@ vectors_stroke_cmd_callback (GtkAction *action, ...@@ -503,12 +509,18 @@ vectors_stroke_cmd_callback (GtkAction *action,
if (! dialog) if (! dialog)
{ {
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
dialog = stroke_dialog_new (GIMP_ITEM (vectors), dialog = stroke_dialog_new (GIMP_ITEM (vectors),
drawable,
action_data_get_context (data), action_data_get_context (data),
_("Stroke Path"), _("Stroke Path"),
GIMP_STOCK_PATH_STROKE, GIMP_STOCK_PATH_STROKE,
GIMP_HELP_PATH_STROKE, GIMP_HELP_PATH_STROKE,
widget); widget,
config->stroke_options,
vectors_stroke_callback,
NULL);
dialogs_attach_dialog (G_OBJECT (drawable), STROKE_DIALOG_KEY, dialog); dialogs_attach_dialog (G_OBJECT (drawable), STROKE_DIALOG_KEY, dialog);
} }
...@@ -868,6 +880,39 @@ vectors_fill_callback (GtkWidget *dialog, ...@@ -868,6 +880,39 @@ vectors_fill_callback (GtkWidget *dialog,
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
} }
static void
vectors_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (context->gimp->config);
GimpImage *image = gimp_item_get_image (item);
GError *error = NULL;
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->stroke_options), 0);
if (! gimp_item_stroke (item, drawable, context, options, NULL,
TRUE, NULL, &error))
{
gimp_message_literal (context->gimp,
G_OBJECT (dialog),
GIMP_MESSAGE_WARNING,
error ? error->message : "NULL");
g_clear_error (&error);
return;
}
gimp_image_flush (image);
gtk_widget_destroy (dialog);
}
static void static void
vectors_import_response (GtkWidget *widget, vectors_import_response (GtkWidget *widget,
gint response_id, gint response_id,
......
...@@ -87,6 +87,7 @@ fill_dialog_new (GimpItem *item, ...@@ -87,6 +87,7 @@ fill_dialog_new (GimpItem *item,
g_return_val_if_fail (icon_name != NULL, NULL); g_return_val_if_fail (icon_name != NULL, NULL);
g_return_val_if_fail (help_id != NULL, NULL); g_return_val_if_fail (help_id != NULL, NULL);
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL); g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
g_return_val_if_fail (callback != NULL, NULL);
private = g_slice_new0 (FillDialog); private = g_slice_new0 (FillDialog);
......
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#include "dialogs-types.h" #include "dialogs-types.h"
#include "config/gimpdialogconfig.h"
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimpdrawable.h" #include "core/gimpdrawable.h"
#include "core/gimpimage.h" #include "core/gimpimage.h"
...@@ -49,48 +47,72 @@ ...@@ -49,48 +47,72 @@
#define RESPONSE_RESET 1 #define RESPONSE_RESET 1
typedef struct
{
GimpItem *item;
GimpDrawable *drawable;
GimpContext *context;
GimpStrokeOptions *options;
GimpStrokeCallback callback;
gpointer user_data;
GtkWidget *tool_combo;
} StrokeDialog;
/* local functions */ /* local functions */
static void stroke_dialog_response (GtkWidget *widget, static void stroke_dialog_response (GtkWidget *dialog,
gint response_id, gint response_id,
GtkWidget *dialog); StrokeDialog *private);
static void stroke_dialog_free (StrokeDialog *private);
/* public function */ /* public function */
GtkWidget * GtkWidget *
stroke_dialog_new (GimpItem *item, stroke_dialog_new (GimpItem *item,
GimpContext *context, GimpDrawable *drawable,
const gchar *title, GimpContext *context,
const gchar *icon_name, const gchar *title,
const gchar *help_id, const gchar *icon_name,
GtkWidget *parent) const gchar *help_id,
GtkWidget *parent,
GimpStrokeOptions *options,
GimpStrokeCallback callback,
gpointer user_data)
{ {
GimpDialogConfig *config; StrokeDialog *private;
GimpStrokeOptions *options; GimpImage *image;
GimpImage *image; GtkWidget *dialog;
GtkWidget *dialog; GtkWidget *main_vbox;
GtkWidget *main_vbox; GtkWidget *radio_box;
GtkWidget *radio_box; GtkWidget *cairo_radio;
GtkWidget *cairo_radio; GtkWidget *paint_radio;
GtkWidget *paint_radio; GSList *group;
GSList *group; GtkWidget *frame;
GtkWidget *frame;
g_return_val_if_fail (GIMP_IS_ITEM (item), NULL); g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (icon_name != NULL, NULL); g_return_val_if_fail (icon_name != NULL, NULL);
g_return_val_if_fail (help_id != NULL, NULL); g_return_val_if_fail (help_id != NULL, NULL);
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL); g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
g_return_val_if_fail (callback != NULL, NULL);
image = gimp_item_get_image (item); image = gimp_item_get_image (item);
config = GIMP_DIALOG_CONFIG (context->gimp->config); private = g_slice_new0 (StrokeDialog);
options = gimp_stroke_options_new (context->gimp, context, TRUE); private->item = item;
private->drawable = drawable;
private->context = context;
private->options = gimp_stroke_options_new (context->gimp, context, TRUE);
private->callback = callback;
private->user_data = user_data;
gimp_config_sync (G_OBJECT (config->stroke_options), gimp_config_sync (G_OBJECT (options),
G_OBJECT (options), 0); G_OBJECT (private->options), 0);
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (item), context, dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (item), context,
title, "gimp-stroke-options", title, "gimp-stroke-options",
...@@ -114,13 +136,12 @@ stroke_dialog_new (GimpItem *item, ...@@ -114,13 +136,12 @@ stroke_dialog_new (GimpItem *item,
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
g_object_weak_ref (G_OBJECT (dialog),
(GWeakNotify) stroke_dialog_free, private);
g_signal_connect (dialog, "response", g_signal_connect (dialog, "response",
G_CALLBACK (stroke_dialog_response), G_CALLBACK (stroke_dialog_response),
dialog); private);
g_object_set_data (G_OBJECT (dialog), "gimp-item", item);
g_object_set_data_full (G_OBJECT (dialog), "gimp-stroke-options", options,
(GDestroyNotify) g_object_unref);
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
...@@ -128,8 +149,8 @@ stroke_dialog_new (GimpItem *item, ...@@ -128,8 +149,8 @@ stroke_dialog_new (GimpItem *item,
main_vbox, TRUE, TRUE, 0); main_vbox, TRUE, TRUE, 0);
gtk_widget_show (main_vbox); gtk_widget_show (main_vbox);
radio_box = gimp_prop_enum_radio_box_new (G_OBJECT (options), "method", radio_box = gimp_prop_enum_radio_box_new (G_OBJECT (private->options),
-1, -1); "method", -1, -1);
group = gtk_radio_button_get_group (g_object_get_data (G_OBJECT (radio_box), group = gtk_radio_button_get_group (g_object_get_data (G_OBJECT (radio_box),
"radio-button")); "radio-button"));
...@@ -174,7 +195,7 @@ stroke_dialog_new (GimpItem *item, ...@@ -174,7 +195,7 @@ stroke_dialog_new (GimpItem *item,
gimp_image_get_resolution (image, &xres, &yres); gimp_image_get_resolution (image, &xres, &yres);
stroke_editor = gimp_stroke_editor_new (options, yres, FALSE); stroke_editor = gimp_stroke_editor_new (private->options, yres, FALSE);
gtk_container_add (GTK_CONTAINER (frame), stroke_editor); gtk_container_add (GTK_CONTAINER (frame), stroke_editor);
gtk_widget_show (stroke_editor); gtk_widget_show (stroke_editor);
...@@ -217,14 +238,14 @@ stroke_dialog_new (GimpItem *item, ...@@ -217,14 +238,14 @@ stroke_dialog_new (GimpItem *item,
gtk_widget_show (label); gtk_widget_show (label);
combo = gimp_container_combo_box_new (image->gimp->paint_info_list, combo = gimp_container_combo_box_new (image->gimp->paint_info_list,
GIMP_CONTEXT (options), GIMP_CONTEXT (private->options),
16, 0); 16, 0);
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
gtk_widget_show (combo); gtk_widget_show (combo);
g_object_set_data (G_OBJECT (dialog), "gimp-tool-menu", combo); private->tool_combo = combo;
button = gimp_prop_check_button_new (G_OBJECT (options), button = gimp_prop_check_button_new (G_OBJECT (private->options),
"emulate-brush-dynamics", "emulate-brush-dynamics",
_("_Emulate brush dynamics")); _("_Emulate brush dynamics"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
...@@ -238,73 +259,43 @@ stroke_dialog_new (GimpItem *item, ...@@ -238,73 +259,43 @@ stroke_dialog_new (GimpItem *item,
/* private functions */ /* private functions */
static void static void
stroke_dialog_response (GtkWidget *widget, stroke_dialog_response (GtkWidget *dialog,
gint response_id, gint response_id,
GtkWidget *dialog) StrokeDialog *private)
{ {
GimpStrokeOptions *options;
GimpItem *item;
GimpImage *image;
GimpContext *context;
GtkWidget *combo;
item = g_object_get_data (G_OBJECT (dialog), "gimp-item");
options = g_object_get_data (G_OBJECT (dialog), "gimp-stroke-options");
combo = g_object_get_data (G_OBJECT (dialog), "gimp-tool-menu");
image = gimp_item_get_image (item);
context = GIMP_VIEWABLE_DIALOG (dialog)->context;
switch (response_id) switch (response_id)
{ {
case RESPONSE_RESET: case RESPONSE_RESET:
{ {
GimpToolInfo *tool_info = gimp_context_get_tool (context); GimpToolInfo *tool_info = gimp_context_get_tool (private->context);
gimp_config_reset (GIMP_CONFIG (options)); gimp_config_reset (GIMP_CONFIG (private->options));
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (combo), gimp_container_view_select_item (GIMP_CONTAINER_VIEW (private->tool_combo),
GIMP_VIEWABLE (tool_info->paint_info)); GIMP_VIEWABLE (tool_info->paint_info));
} }
break; break;
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
{ private->callback (dialog,
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (context->gimp->config); private->item,
GimpDrawable *drawable = gimp_image_get_active_drawable (image); private->drawable,
GError *error = NULL; private->context,
private->options,
if (! drawable) private->user_data);
{ break;
gimp_message_literal (context->gimp, G_OBJECT (widget),
GIMP_MESSAGE_WARNING,
_("There is no active layer or channel "
"to stroke to."));
return;
}
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->stroke_options), 0);
if (! gimp_item_stroke (item, drawable, context, options, NULL,
TRUE, NULL, &error))
{
gimp_message_literal (context->gimp,
G_OBJECT (widget),
GIMP_MESSAGE_WARNING,
error ? error->message : "NULL");
g_clear_error (&error);
return;
}
gimp_image_flush (image);
}
/* fallthrough */
default: default:
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
break; break;
} }
} }
static void
stroke_dialog_free (StrokeDialog *private)
{
g_object_unref (private->options);
g_slice_free (StrokeDialog, private);
}
...@@ -21,12 +21,24 @@ ...@@ -21,12 +21,24 @@
#define __STROKE_DIALOG_H__ #define __STROKE_DIALOG_H__
GtkWidget * stroke_dialog_new (GimpItem *item, typedef void (* GimpStrokeCallback) (GtkWidget *dialog,
GimpContext *context, GimpItem *item,
const gchar *title, GimpDrawable *drawable,
const gchar *icon_name, GimpContext *context,
const gchar *help_id, GimpStrokeOptions *options,
GtkWidget *parent); gpointer user_data);
GtkWidget * stroke_dialog_new (GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
const gchar *title,
const gchar *icon_name,
const gchar *help_id,
GtkWidget *parent,
GimpStrokeOptions *options,
GimpStrokeCallback callback,
gpointer user_data);
#endif /* __STROKE_DIALOG_H__ */ #endif /* __STROKE_DIALOG_H__ */
...@@ -25,10 +25,13 @@ ...@@ -25,10 +25,13 @@
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include "libgimpbase/gimpbase.h" #include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h" #include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h" #include "tools-types.h"
#include "config/gimpdialogconfig.h"
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimpcontext.h" #include "core/gimpcontext.h"
#include "core/gimpimage.h" #include "core/gimpimage.h"
...@@ -139,6 +142,12 @@ static void gimp_vector_tool_to_selection_extended ...@@ -139,6 +142,12 @@ static void gimp_vector_tool_to_selection_extended
gint state); gint state);
static void gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool, static void gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
GtkWidget *button); GtkWidget *button);
static void gimp_vector_tool_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data);
G_DEFINE_TYPE (GimpVectorTool, gimp_vector_tool, GIMP_TYPE_DRAW_TOOL) G_DEFINE_TYPE (GimpVectorTool, gimp_vector_tool, GIMP_TYPE_DRAW_TOOL)
...@@ -1953,18 +1962,21 @@ static void ...@@ -1953,18 +1962,21 @@ static void
gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool, gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
GtkWidget *button) GtkWidget *button)
{ {
GimpImage *image; GimpDialogConfig *config;
GimpDrawable *active_drawable; GimpImage *image;
GtkWidget *dialog; GimpDrawable *drawable;
GtkWidget *dialog;
if (! vector_tool->vectors) if (! vector_tool->vectors)
return; return;
image = gimp_item_get_image (GIMP_ITEM (vector_tool->vectors)); image = gimp_item_get_image (GIMP_ITEM (vector_tool->vectors));
active_drawable = gimp_image_get_active_drawable (image); config = GIMP_DIALOG_CONFIG (image->gimp->config);
drawable = gimp_image_get_active_drawable (image);
if (! active_drawable) if (! drawable)
{ {
gimp_tool_message (GIMP_TOOL (vector_tool), gimp_tool_message (GIMP_TOOL (vector_tool),
GIMP_TOOL (vector_tool)->display, GIMP_TOOL (vector_tool)->display,
...@@ -1973,10 +1985,46 @@ gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool, ...@@ -1973,10 +1985,46 @@ gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
} }
dialog = stroke_dialog_new (GIMP_ITEM (vector_tool->vectors), dialog = stroke_dialog_new (GIMP_ITEM (vector_tool->vectors),
drawable,
GIMP_CONTEXT (GIMP_TOOL_GET_OPTIONS (vector_tool)), GIMP_CONTEXT (GIMP_TOOL_GET_OPTIONS (vector_tool)),
_("Stroke Path"), _("Stroke Path"),
GIMP_STOCK_PATH_STROKE, GIMP_STOCK_PATH_STROKE,
GIMP_HELP_PATH_STROKE, GIMP_HELP_PATH_STROKE,
button); button,
config->stroke_options,
gimp_vector_tool_stroke_callback,
vector_tool);
gtk_widget_show (dialog); gtk_widget_show (dialog);
} }
static void
gimp_vector_tool_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (context->gimp->config);
GimpImage *image = gimp_item_get_image (item);
GError *error = NULL;
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->stroke_options), 0);