Commit e1e77f88 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: change gimp_edit_fill() to take a GimpFillOptions

instead of a long list of parameters. Get rid of gimp_edit_fill_full().
parent 00932b57
......@@ -32,6 +32,7 @@
#include "core/gimpbuffer.h"
#include "core/gimpcontainer.h"
#include "core/gimpdrawable.h"
#include "core/gimpfilloptions.h"
#include "core/gimplayer.h"
#include "core/gimplayer-new.h"
#include "core/gimpimage.h"
......@@ -495,18 +496,22 @@ edit_fill_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
GimpFillType fill_type;
GError *error = NULL;
GimpImage *image;
GimpDrawable *drawable;
GimpFillType fill_type;
GimpFillOptions *options;
GError *error = NULL;
return_if_no_drawable (image, drawable, data);
fill_type = (GimpFillType) value;
if (gimp_edit_fill (image, drawable, action_data_get_context (data),
fill_type, GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE,
&error))
options = gimp_fill_options_new (action_data_get_gimp (data));
if (gimp_fill_options_set_by_fill_type (options,
action_data_get_context (data),
fill_type, &error))
{
gimp_edit_fill (image, drawable, options, NULL);
gimp_image_flush (image);
}
else
......@@ -515,6 +520,8 @@ edit_fill_cmd_callback (GtkAction *action,
error->message);
g_clear_error (&error);
}
g_object_unref (options);
}
......
......@@ -36,6 +36,7 @@
#include "gimpbuffer.h"
#include "gimpchannel.h"
#include "gimpcontext.h"
#include "gimpfilloptions.h"
#include "gimpdrawableundo.h"
#include "gimpimage.h"
#include "gimpimage-undo.h"
......@@ -399,99 +400,62 @@ gimp_edit_clear (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context)
{
GimpRGB background;
GimpLayerModeEffects paint_mode;
GimpFillOptions *options;
gboolean success;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
gimp_context_get_background (context, &background);
options = gimp_fill_options_new (context->gimp);
if (gimp_drawable_has_alpha (drawable))
paint_mode = GIMP_ERASE_MODE;
gimp_fill_options_set_by_fill_type (options, context,
GIMP_FILL_TRANSPARENT, NULL);
else
paint_mode = GIMP_NORMAL_MODE;
gimp_fill_options_set_by_fill_type (options, context,
GIMP_FILL_BACKGROUND, NULL);
return gimp_edit_fill_full (image, drawable,
&background, NULL,
GIMP_OPACITY_OPAQUE, paint_mode,
C_("undo-type", "Clear"));
success = gimp_edit_fill (image, drawable, options,
C_("undo-type", "Clear"));
g_object_unref (options);
return success;
}
gboolean
gimp_edit_fill (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context,
GimpFillType fill_type,
gdouble opacity,
GimpLayerModeEffects paint_mode,
GError **error)
gimp_edit_fill (GimpImage *image,
GimpDrawable *drawable,
GimpFillOptions *options,
const gchar *undo_desc)
{
GeglBuffer *dest_buffer;
GimpPattern *pattern = NULL;
GimpRGB color;
GimpPattern *pattern;
const gchar *undo_desc = NULL;
const Babl *format;
gint x, y, width, height;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (GIMP_IS_FILL_OPTIONS (options), FALSE);
if (! gimp_get_fill_params (context, fill_type, &color, &pattern, error))
return FALSE;
if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
return TRUE; /* nothing to do, but the fill succeeded */
switch (fill_type)
switch (gimp_fill_options_get_style (options))
{
case GIMP_FILL_FOREGROUND:
undo_desc = C_("undo-type", "Fill with Foreground Color");
break;
case GIMP_FILL_BACKGROUND:
undo_desc = C_("undo-type", "Fill with Background Color");
case GIMP_FILL_STYLE_SOLID:
gimp_context_get_foreground (GIMP_CONTEXT (options), &color);
break;
case GIMP_FILL_WHITE:
undo_desc = C_("undo-type", "Fill with White");
break;
case GIMP_FILL_TRANSPARENT:
undo_desc = C_("undo-type", "Fill with Transparency");
break;
case GIMP_FILL_PATTERN:
undo_desc = C_("undo-type", "Fill with Pattern");
case GIMP_FILL_STYLE_PATTERN:
pattern = gimp_context_get_pattern (GIMP_CONTEXT (options));
break;
}
return gimp_edit_fill_full (image, drawable,
&color, pattern,
opacity, paint_mode,
undo_desc);
}
gboolean
gimp_edit_fill_full (GimpImage *image,
GimpDrawable *drawable,
const GimpRGB *color,
GimpPattern *pattern,
gdouble opacity,
GimpLayerModeEffects paint_mode,
const gchar *undo_desc)
{
GeglBuffer *dest_buffer;
const Babl *format;
gint x, y, width, height;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
g_return_val_if_fail (color != NULL || pattern != NULL, FALSE);
if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
return TRUE; /* nothing to do, but the fill succeeded */
if (pattern &&
babl_format_has_alpha (gimp_temp_buf_get_format (pattern->mask)) &&
! gimp_drawable_has_alpha (drawable))
......@@ -515,16 +479,20 @@ gimp_edit_fill_full (GimpImage *image,
}
else
{
GeglColor *gegl_color = gimp_gegl_color_new (color);
GeglColor *gegl_color = gimp_gegl_color_new (&color);
gegl_buffer_set_color (dest_buffer, NULL, gegl_color);
g_object_unref (gegl_color);
}
if (! undo_desc)
undo_desc = gimp_fill_options_get_undo_desc (options);
gimp_drawable_apply_buffer (drawable, dest_buffer,
GEGL_RECTANGLE (0, 0, width, height),
TRUE, undo_desc,
opacity, paint_mode,
gimp_context_get_opacity (GIMP_CONTEXT (options)),
gimp_context_get_paint_mode (GIMP_CONTEXT (options)),
NULL, x, y);
g_object_unref (dest_buffer);
......
......@@ -19,62 +19,51 @@
#define __GIMP_EDIT_H__
const GimpBuffer * gimp_edit_cut (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context,
GError **error);
const GimpBuffer * gimp_edit_copy (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context,
GError **error);
const GimpBuffer * gimp_edit_copy_visible (GimpImage *image,
GimpContext *context,
GError **error);
GimpLayer * gimp_edit_paste (GimpImage *image,
GimpDrawable *drawable,
GimpBuffer *paste,
gboolean paste_into,
gint viewport_x,
gint viewport_y,
gint viewport_width,
gint viewport_height);
const GimpBuffer * gimp_edit_cut (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context,
GError **error);
const GimpBuffer * gimp_edit_copy (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context,
GError **error);
const GimpBuffer * gimp_edit_copy_visible (GimpImage *image,
GimpContext *context,
GError **error);
GimpLayer * gimp_edit_paste (GimpImage *image,
GimpDrawable *drawable,
GimpBuffer *paste,
gboolean paste_into,
gint viewport_x,
gint viewport_y,
gint viewport_width,
gint viewport_height);
const gchar * gimp_edit_named_cut (GimpImage *image,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context,
GError **error);
const gchar * gimp_edit_named_copy (GimpImage *image,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context,
GError **error);
const gchar * gimp_edit_named_copy_visible (GimpImage *image,
const gchar *name,
GimpContext *context,
GError **error);
const gchar * gimp_edit_named_cut (GimpImage *image,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context,
GError **error);
const gchar * gimp_edit_named_copy (GimpImage *image,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context,
GError **error);
const gchar * gimp_edit_named_copy_visible (GimpImage *image,
const gchar *name,
GimpContext *context,
GError **error);
gboolean gimp_edit_clear (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context);
gboolean gimp_edit_fill (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context,
GimpFillType fill_type,
gdouble opacity,
GimpLayerModeEffects paint_mode,
GError **error);
gboolean gimp_edit_clear (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context);
gboolean gimp_edit_fill (GimpImage *image,
GimpDrawable *drawable,
GimpFillOptions *options,
const gchar *undo_desc);
gboolean gimp_edit_fill_full (GimpImage *image,
GimpDrawable *drawable,
const GimpRGB *color,
GimpPattern *pattern,
gdouble opacity,
GimpLayerModeEffects paint_mode,
const gchar *undo_desc);
gboolean gimp_edit_fade (GimpImage *image,
GimpContext *context);
gboolean gimp_edit_fade (GimpImage *image,
GimpContext *context);
#endif /* __GIMP_EDIT_H__ */
......@@ -32,6 +32,7 @@
#include "core/gimpbuffer.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpfilloptions.h"
#include "core/gimpimage.h"
#include "core/gimpimage-merge.h"
#include "core/gimpimage-new.h"
......@@ -382,12 +383,24 @@ gimp_display_shell_dnd_fill (GimpDisplayShell *shell,
}
else
{
gimp_edit_fill_full (image, drawable,
color, pattern,
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE,
pattern ?
C_("undo-type", "Drop pattern to layer") :
C_("undo-type", "Drop color to layer"));
GimpFillOptions *options = gimp_fill_options_new (image->gimp);
if (color)
{
gimp_context_set_foreground (GIMP_CONTEXT (options), color);
}
else
{
gimp_fill_options_set_style (options, GIMP_FILL_STYLE_PATTERN);
gimp_context_set_pattern (GIMP_CONTEXT (options), pattern);
}
gimp_edit_fill (image, drawable, options,
pattern ?
C_("undo-type", "Drop pattern to layer") :
C_("undo-type", "Drop color to layer"));
g_object_unref (options);
}
gimp_display_shell_dnd_flush (shell, image);
......
......@@ -553,12 +553,16 @@ edit_fill_invoker (GimpProcedure *procedure,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpFillOptions *options = gimp_fill_options_new (gimp);
success = gimp_fill_options_set_by_fill_type (options, context,
fill_type, error);
success = gimp_edit_fill (image, drawable, context,
(GimpFillType) fill_type,
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE,
error);
if (success)
success = gimp_edit_fill (image, drawable, options, NULL);
g_object_unref (options);
}
else
success = FALSE;
......@@ -601,36 +605,48 @@ edit_bucket_fill_invoker (GimpProcedure *procedure,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpFillType fill_type;
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
switch (fill_mode)
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
{
default:
case GIMP_BUCKET_FILL_FG:
fill_type = GIMP_FILL_FOREGROUND;
break;
GimpFillOptions *options = gimp_fill_options_new (gimp);
case GIMP_BUCKET_FILL_BG:
fill_type = GIMP_FILL_BACKGROUND;
break;
success = gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error);
case GIMP_BUCKET_FILL_PATTERN:
fill_type = GIMP_FILL_PATTERN;
break;
}
if (success)
{
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
{
success = gimp_edit_fill (image, drawable, context, fill_type,
opacity / 100.0, paint_mode,
error);
success = gimp_edit_fill (image, drawable, options, NULL);
}
g_object_unref (options);
}
else
{
GimpFillType fill_type;
switch (fill_mode)
{
default:
case GIMP_BUCKET_FILL_FG:
fill_type = GIMP_FILL_FOREGROUND;
break;
case GIMP_BUCKET_FILL_BG:
fill_type = GIMP_FILL_BACKGROUND;
break;
case GIMP_BUCKET_FILL_PATTERN:
fill_type = GIMP_FILL_PATTERN;
break;
}
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
paint_mode, opacity / 100.0,
FALSE /* don't fill transparent */,
......@@ -687,37 +703,49 @@ edit_bucket_fill_full_invoker (GimpProcedure *procedure,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpFillType fill_type;
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
switch (fill_mode)
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
{
default:
case GIMP_BUCKET_FILL_FG:
fill_type = GIMP_FILL_FOREGROUND;
break;
GimpFillOptions *options = gimp_fill_options_new (gimp);
case GIMP_BUCKET_FILL_BG:
fill_type = GIMP_FILL_BACKGROUND;
break;
success = gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error);
case GIMP_BUCKET_FILL_PATTERN:
fill_type = GIMP_FILL_PATTERN;
break;
}
if (success)
{
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
{
success = gimp_edit_fill (image, drawable, context, fill_type,
opacity / 100.0, paint_mode,
error);
success = gimp_edit_fill (image, drawable, options, NULL);
}
g_object_unref (options);
}
else
{
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
GimpFillType fill_type;
switch (fill_mode)
{
default:
case GIMP_BUCKET_FILL_FG:
fill_type = GIMP_FILL_FOREGROUND;
break;
case GIMP_BUCKET_FILL_BG:
fill_type = GIMP_FILL_BACKGROUND;
break;
case GIMP_BUCKET_FILL_PATTERN:
fill_type = GIMP_FILL_PATTERN;
break;
}
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
paint_mode, opacity / 100.0,
fill_transparent,
select_criterion,
......
......@@ -28,6 +28,7 @@
#include "core/gimp-edit.h"
#include "core/gimpdrawable-bucket-fill.h"
#include "core/gimperror.h"
#include "core/gimpfilloptions.h"
#include "core/gimpimage.h"
#include "core/gimpitem.h"
#include "core/gimppickable.h"
......@@ -173,47 +174,61 @@ gimp_bucket_fill_tool_button_release (GimpTool *tool,
{
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GimpContext *context = GIMP_CONTEXT (options);
GimpFillType fill_type;
gint x, y;
gboolean success;
GError *error = NULL;
switch (options->fill_mode)
if (options->fill_selection)
{
default:
case GIMP_BUCKET_FILL_FG:
fill_type = GIMP_FILL_FOREGROUND;
break;
case GIMP_BUCKET_FILL_BG:
fill_type = GIMP_FILL_BACKGROUND;
break;
case GIMP_BUCKET_FILL_PATTERN:
fill_type = GIMP_FILL_PATTERN;
break;
}
GimpFillOptions *fill_options = gimp_fill_options_new (image->gimp);
x = coords->x;
y = coords->y;
success = gimp_fill_options_set_by_fill_mode (fill_options, context,
options->fill_mode,
&error);
if (! options->sample_merged)
{
gint off_x, off_y;
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
if (success)
{
gimp_context_set_opacity (GIMP_CONTEXT (fill_options),
gimp_context_get_opacity (context));
gimp_context_set_paint_mode (GIMP_CONTEXT (fill_options),
gimp_context_get_paint_mode (context));
x -= off_x;
y -= off_y;
}
success = gimp_edit_fill (image, drawable, fill_options, NULL);
}
if (options->fill_selection)
{
success = gimp_edit_fill (image, drawable, context, fill_type,
gimp_context_get_opacity (context),
gimp_context_get_paint_mode (context),
&error);
g_object_unref (fill_options);
}
else
{
GimpFillType fill_type;
gint x, y;
x = coords->x;
y = coords->y;
switch (options->fill_mode)
{
default:
case GIMP_BUCKET_FILL_FG:
fill_type = GIMP_FILL_FOREGROUND;
break;
case GIMP_BUCKET_FILL_BG:
fill_type = GIMP_FILL_BACKGROUND;
break;
case GIMP_BUCKET_FILL_PATTERN:
fill_type = GIMP_FILL_PATTERN;
break;
}
if (! options->sample_merged)
{
gint off_x, off_y;
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
x -= off_x;
y -= off_y;
}
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
gimp_context_get_paint_mode (context),
gimp_context_get_opacity (context),
......
......@@ -31,6 +31,7 @@
#include "core/gimp-edit.h"