Commit 905bb370 authored by Michael Natterer's avatar Michael Natterer 😴

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.
parent bbbfe5ca
......@@ -21,6 +21,7 @@
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
......@@ -53,22 +54,28 @@
/* local function prototypes */
static void select_feather_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_border_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_grow_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_shrink_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_feather_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_border_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_grow_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_shrink_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_fill_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpFillOptions *options,
gpointer data);
/* public functions */
......@@ -407,12 +414,18 @@ select_fill_cmd_callback (GtkAction *action,
if (! dialog)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
dialog = fill_dialog_new (GIMP_ITEM (gimp_image_get_mask (image)),
drawable,
action_data_get_context (data),
_("Fill Selection Outline"),
GIMP_STOCK_TOOL_BUCKET_FILL,
GIMP_HELP_SELECTION_FILL,
widget);
widget,
config->fill_options,
select_fill_callback,
NULL);
dialogs_attach_dialog (G_OBJECT (drawable), FILL_DIALOG_KEY, dialog);
}
......@@ -718,3 +731,34 @@ select_shrink_callback (GtkWidget *widget,
TRUE);
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,
const gchar *vectors_name,
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,
gint response_id,
VectorsImportDialog *dialog);
......@@ -412,12 +418,18 @@ vectors_fill_cmd_callback (GtkAction *action,
if (! dialog)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
dialog = fill_dialog_new (GIMP_ITEM (vectors),
drawable,
action_data_get_context (data),
_("Fill Path"),
GIMP_STOCK_TOOL_BUCKET_FILL,
GIMP_HELP_PATH_FILL,
widget);
widget,
config->fill_options,
vectors_fill_callback,
NULL);
dialogs_attach_dialog (G_OBJECT (drawable), FILL_DIALOG_KEY, dialog);
}
......@@ -825,6 +837,37 @@ vectors_edit_attributes_callback (GtkWidget *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
vectors_import_response (GtkWidget *widget,
gint response_id,
......
......@@ -28,11 +28,7 @@
#include "dialogs-types.h"
#include "config/gimpdialogconfig.h"
#include "core/gimp.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpfilloptions.h"
#include "widgets/gimpfilleditor.h"
......@@ -46,41 +42,63 @@
#define RESPONSE_RESET 1
/* local functions */
typedef struct
{
GimpItem *item;
GimpDrawable *drawable;
GimpContext *context;
GimpFillOptions *options;
GimpFillCallback callback;
gpointer user_data;
} FillDialog;
/* local function prototypes */
static void fill_dialog_response (GtkWidget *widget,
gint response_id,
GtkWidget *dialog);
static void fill_dialog_response (GtkWidget *dialog,
gint response_id,
FillDialog *private);
static void fill_dialog_free (FillDialog *private);
/* public function */
GtkWidget *
fill_dialog_new (GimpItem *item,
GimpContext *context,
const gchar *title,
const gchar *icon_name,
const gchar *help_id,
GtkWidget *parent)
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)
{
GimpDialogConfig *config;
GimpFillOptions *options;
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *fill_editor;
FillDialog *private;
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *fill_editor;
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_FILL_OPTIONS (options), NULL);
g_return_val_if_fail (icon_name != NULL, NULL);
g_return_val_if_fail (help_id != NULL, 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),
G_OBJECT (options), 0);
gimp_config_sync (G_OBJECT (options),
G_OBJECT (private->options), 0);
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (item), context,
title, "gimp-fill-options",
......@@ -104,13 +122,12 @@ fill_dialog_new (GimpItem *item,
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_CALLBACK (fill_dialog_response),
dialog);
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);
private);
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 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);
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_widget_show (fill_editor);
......@@ -129,62 +146,35 @@ fill_dialog_new (GimpItem *item,
/* private functions */
static void
fill_dialog_response (GtkWidget *widget,
fill_dialog_response (GtkWidget *dialog,
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)
{
case RESPONSE_RESET:
gimp_config_reset (GIMP_CONFIG (options));
gimp_config_reset (GIMP_CONFIG (private->options));
break;
case GTK_RESPONSE_OK:
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (context->gimp->config);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GError *error = NULL;
if (! drawable)
{
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 */
private->callback (dialog,
private->item,
private->drawable,
private->context,
private->options,
private->user_data);
break;
default:
gtk_widget_destroy (dialog);
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__
GtkWidget * fill_dialog_new (GimpItem *item,
GimpContext *context,
const gchar *title,
const gchar *icon_name,
const gchar *help_id,
GtkWidget *parent);
typedef void (* GimpFillCallback) (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpFillOptions *options,
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__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment