app: add a callback to the fill dialog
and move the actual filling code to select-commands.c and vectors-commands.c. Remember the active drawable so the fill always happens on the drawable the dialog was invoked with.
This commit is contained in:
@ -21,6 +21,7 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include "libgimpmath/gimpmath.h"
|
#include "libgimpmath/gimpmath.h"
|
||||||
|
#include "libgimpconfig/gimpconfig.h"
|
||||||
#include "libgimpwidgets/gimpwidgets.h"
|
#include "libgimpwidgets/gimpwidgets.h"
|
||||||
|
|
||||||
#include "actions-types.h"
|
#include "actions-types.h"
|
||||||
@ -53,22 +54,28 @@
|
|||||||
|
|
||||||
/* 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,
|
||||||
|
GimpItem *item,
|
||||||
|
GimpDrawable *drawable,
|
||||||
|
GimpContext *context,
|
||||||
|
GimpFillOptions *options,
|
||||||
|
gpointer data);
|
||||||
|
|
||||||
|
|
||||||
/* public functions */
|
/* public functions */
|
||||||
@ -407,12 +414,18 @@ select_fill_cmd_callback (GtkAction *action,
|
|||||||
|
|
||||||
if (! dialog)
|
if (! dialog)
|
||||||
{
|
{
|
||||||
|
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
|
||||||
|
|
||||||
dialog = fill_dialog_new (GIMP_ITEM (gimp_image_get_mask (image)),
|
dialog = fill_dialog_new (GIMP_ITEM (gimp_image_get_mask (image)),
|
||||||
|
drawable,
|
||||||
action_data_get_context (data),
|
action_data_get_context (data),
|
||||||
_("Fill Selection Outline"),
|
_("Fill Selection Outline"),
|
||||||
GIMP_STOCK_TOOL_BUCKET_FILL,
|
GIMP_STOCK_TOOL_BUCKET_FILL,
|
||||||
GIMP_HELP_SELECTION_FILL,
|
GIMP_HELP_SELECTION_FILL,
|
||||||
widget);
|
widget,
|
||||||
|
config->fill_options,
|
||||||
|
select_fill_callback,
|
||||||
|
NULL);
|
||||||
|
|
||||||
dialogs_attach_dialog (G_OBJECT (drawable), FILL_DIALOG_KEY, dialog);
|
dialogs_attach_dialog (G_OBJECT (drawable), FILL_DIALOG_KEY, dialog);
|
||||||
}
|
}
|
||||||
@ -718,3 +731,34 @@ select_shrink_callback (GtkWidget *widget,
|
|||||||
TRUE);
|
TRUE);
|
||||||
gimp_image_flush (image);
|
gimp_image_flush (image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
select_fill_callback (GtkWidget *dialog,
|
||||||
|
GimpItem *item,
|
||||||
|
GimpDrawable *drawable,
|
||||||
|
GimpContext *context,
|
||||||
|
GimpFillOptions *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->fill_options), 0);
|
||||||
|
|
||||||
|
if (! gimp_item_fill (item, drawable, options, 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);
|
||||||
|
}
|
||||||
|
@ -84,6 +84,12 @@ static void vectors_edit_attributes_callback (GtkWidget *dialog,
|
|||||||
GimpVectors *vectors,
|
GimpVectors *vectors,
|
||||||
const gchar *vectors_name,
|
const gchar *vectors_name,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
static void vectors_fill_callback (GtkWidget *dialog,
|
||||||
|
GimpItem *item,
|
||||||
|
GimpDrawable *drawable,
|
||||||
|
GimpContext *context,
|
||||||
|
GimpFillOptions *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);
|
||||||
@ -412,12 +418,18 @@ vectors_fill_cmd_callback (GtkAction *action,
|
|||||||
|
|
||||||
if (! dialog)
|
if (! dialog)
|
||||||
{
|
{
|
||||||
|
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
|
||||||
|
|
||||||
dialog = fill_dialog_new (GIMP_ITEM (vectors),
|
dialog = fill_dialog_new (GIMP_ITEM (vectors),
|
||||||
|
drawable,
|
||||||
action_data_get_context (data),
|
action_data_get_context (data),
|
||||||
_("Fill Path"),
|
_("Fill Path"),
|
||||||
GIMP_STOCK_TOOL_BUCKET_FILL,
|
GIMP_STOCK_TOOL_BUCKET_FILL,
|
||||||
GIMP_HELP_PATH_FILL,
|
GIMP_HELP_PATH_FILL,
|
||||||
widget);
|
widget,
|
||||||
|
config->fill_options,
|
||||||
|
vectors_fill_callback,
|
||||||
|
NULL);
|
||||||
|
|
||||||
dialogs_attach_dialog (G_OBJECT (drawable), FILL_DIALOG_KEY, dialog);
|
dialogs_attach_dialog (G_OBJECT (drawable), FILL_DIALOG_KEY, dialog);
|
||||||
}
|
}
|
||||||
@ -825,6 +837,37 @@ vectors_edit_attributes_callback (GtkWidget *dialog,
|
|||||||
gtk_widget_destroy (dialog);
|
gtk_widget_destroy (dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vectors_fill_callback (GtkWidget *dialog,
|
||||||
|
GimpItem *item,
|
||||||
|
GimpDrawable *drawable,
|
||||||
|
GimpContext *context,
|
||||||
|
GimpFillOptions *options,
|
||||||
|
gpointer user_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->fill_options), 0);
|
||||||
|
|
||||||
|
if (! gimp_item_fill (item, drawable, options, 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,
|
||||||
|
@ -28,11 +28,7 @@
|
|||||||
|
|
||||||
#include "dialogs-types.h"
|
#include "dialogs-types.h"
|
||||||
|
|
||||||
#include "config/gimpdialogconfig.h"
|
|
||||||
|
|
||||||
#include "core/gimp.h"
|
|
||||||
#include "core/gimpdrawable.h"
|
#include "core/gimpdrawable.h"
|
||||||
#include "core/gimpimage.h"
|
|
||||||
#include "core/gimpfilloptions.h"
|
#include "core/gimpfilloptions.h"
|
||||||
|
|
||||||
#include "widgets/gimpfilleditor.h"
|
#include "widgets/gimpfilleditor.h"
|
||||||
@ -46,41 +42,63 @@
|
|||||||
#define RESPONSE_RESET 1
|
#define RESPONSE_RESET 1
|
||||||
|
|
||||||
|
|
||||||
/* local functions */
|
typedef struct
|
||||||
|
{
|
||||||
|
GimpItem *item;
|
||||||
|
GimpDrawable *drawable;
|
||||||
|
GimpContext *context;
|
||||||
|
GimpFillOptions *options;
|
||||||
|
GimpFillCallback callback;
|
||||||
|
gpointer user_data;
|
||||||
|
} FillDialog;
|
||||||
|
|
||||||
static void fill_dialog_response (GtkWidget *widget,
|
|
||||||
gint response_id,
|
/* local function prototypes */
|
||||||
GtkWidget *dialog);
|
|
||||||
|
static void fill_dialog_response (GtkWidget *dialog,
|
||||||
|
gint response_id,
|
||||||
|
FillDialog *private);
|
||||||
|
static void fill_dialog_free (FillDialog *private);
|
||||||
|
|
||||||
|
|
||||||
/* public function */
|
/* public function */
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
fill_dialog_new (GimpItem *item,
|
fill_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,
|
||||||
|
GimpFillOptions *options,
|
||||||
|
GimpFillCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GimpDialogConfig *config;
|
FillDialog *private;
|
||||||
GimpFillOptions *options;
|
GtkWidget *dialog;
|
||||||
GtkWidget *dialog;
|
GtkWidget *main_vbox;
|
||||||
GtkWidget *main_vbox;
|
GtkWidget *fill_editor;
|
||||||
GtkWidget *fill_editor;
|
|
||||||
|
|
||||||
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 (GIMP_IS_FILL_OPTIONS (options), 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);
|
||||||
|
|
||||||
config = GIMP_DIALOG_CONFIG (context->gimp->config);
|
private = g_slice_new0 (FillDialog);
|
||||||
|
|
||||||
options = gimp_fill_options_new (context->gimp, context, TRUE);
|
private->item = item;
|
||||||
|
private->drawable = drawable;
|
||||||
|
private->context = context;
|
||||||
|
private->options = gimp_fill_options_new (context->gimp, context, TRUE);
|
||||||
|
private->callback = callback;
|
||||||
|
private->user_data = user_data;
|
||||||
|
|
||||||
gimp_config_sync (G_OBJECT (config->fill_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-fill-options",
|
title, "gimp-fill-options",
|
||||||
@ -104,13 +122,12 @@ fill_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) fill_dialog_free, private);
|
||||||
|
|
||||||
g_signal_connect (dialog, "response",
|
g_signal_connect (dialog, "response",
|
||||||
G_CALLBACK (fill_dialog_response),
|
G_CALLBACK (fill_dialog_response),
|
||||||
dialog);
|
private);
|
||||||
|
|
||||||
g_object_set_data (G_OBJECT (dialog), "gimp-item", item);
|
|
||||||
g_object_set_data_full (G_OBJECT (dialog), "gimp-fill-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);
|
||||||
@ -118,7 +135,7 @@ fill_dialog_new (GimpItem *item,
|
|||||||
main_vbox, TRUE, TRUE, 0);
|
main_vbox, TRUE, TRUE, 0);
|
||||||
gtk_widget_show (main_vbox);
|
gtk_widget_show (main_vbox);
|
||||||
|
|
||||||
fill_editor = gimp_fill_editor_new (options, FALSE);
|
fill_editor = gimp_fill_editor_new (private->options, FALSE);
|
||||||
gtk_box_pack_start (GTK_BOX (main_vbox), fill_editor, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (main_vbox), fill_editor, FALSE, FALSE, 0);
|
||||||
gtk_widget_show (fill_editor);
|
gtk_widget_show (fill_editor);
|
||||||
|
|
||||||
@ -129,62 +146,35 @@ fill_dialog_new (GimpItem *item,
|
|||||||
/* private functions */
|
/* private functions */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fill_dialog_response (GtkWidget *widget,
|
fill_dialog_response (GtkWidget *dialog,
|
||||||
gint response_id,
|
gint response_id,
|
||||||
GtkWidget *dialog)
|
FillDialog *private)
|
||||||
{
|
{
|
||||||
GimpFillOptions *options;
|
|
||||||
GimpItem *item;
|
|
||||||
GimpImage *image;
|
|
||||||
GimpContext *context;
|
|
||||||
|
|
||||||
item = g_object_get_data (G_OBJECT (dialog), "gimp-item");
|
|
||||||
options = g_object_get_data (G_OBJECT (dialog), "gimp-fill-options");
|
|
||||||
|
|
||||||
image = gimp_item_get_image (item);
|
|
||||||
context = GIMP_VIEWABLE_DIALOG (dialog)->context;
|
|
||||||
|
|
||||||
switch (response_id)
|
switch (response_id)
|
||||||
{
|
{
|
||||||
case RESPONSE_RESET:
|
case RESPONSE_RESET:
|
||||||
gimp_config_reset (GIMP_CONFIG (options));
|
gimp_config_reset (GIMP_CONFIG (private->options));
|
||||||
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 fill."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gimp_config_sync (G_OBJECT (options),
|
|
||||||
G_OBJECT (config->fill_options), 0);
|
|
||||||
|
|
||||||
if (! gimp_item_fill (item, drawable, options, 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
|
||||||
|
fill_dialog_free (FillDialog *private)
|
||||||
|
{
|
||||||
|
g_object_unref (private->options);
|
||||||
|
|
||||||
|
g_slice_free (FillDialog, private);
|
||||||
|
}
|
||||||
|
@ -22,12 +22,24 @@
|
|||||||
#define __FILL_DIALOG_H__
|
#define __FILL_DIALOG_H__
|
||||||
|
|
||||||
|
|
||||||
GtkWidget * fill_dialog_new (GimpItem *item,
|
typedef void (* GimpFillCallback) (GtkWidget *dialog,
|
||||||
GimpContext *context,
|
GimpItem *item,
|
||||||
const gchar *title,
|
GimpDrawable *drawable,
|
||||||
const gchar *icon_name,
|
GimpContext *context,
|
||||||
const gchar *help_id,
|
GimpFillOptions *options,
|
||||||
GtkWidget *parent);
|
gpointer user_data);
|
||||||
|
|
||||||
|
|
||||||
|
GtkWidget * fill_dialog_new (GimpItem *item,
|
||||||
|
GimpDrawable *drawable,
|
||||||
|
GimpContext *context,
|
||||||
|
const gchar *title,
|
||||||
|
const gchar *icon_name,
|
||||||
|
const gchar *help_id,
|
||||||
|
GtkWidget *parent,
|
||||||
|
GimpFillOptions *options,
|
||||||
|
GimpFillCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __FILL_DIALOG_H__ */
|
#endif /* __FILL_DIALOG_H__ */
|
||||||
|
Reference in New Issue
Block a user