Commit d71f53df authored by Michael Natterer's avatar Michael Natterer 😴

app: change gimp_drawable_bucket_fill() to use GimpFillOptions

and get rid of gimp_drawable_bucket_fill_internal().
parent a95fa4cd
......@@ -39,6 +39,7 @@
#include "gimpcontext.h"
#include "gimpdrawable.h"
#include "gimpdrawable-bucket-fill.h"
#include "gimpfilloptions.h"
#include "gimpimage.h"
#include "gimppattern.h"
#include "gimppickable.h"
......@@ -47,85 +48,25 @@
#include "gimp-intl.h"
static void gimp_drawable_bucket_fill_internal (GimpDrawable *drawable,
GimpFillType fill_type,
gint paint_mode,
gdouble opacity,
gboolean fill_transparent,
GimpSelectCriterion fill_criterion,
gdouble threshold,
gboolean sample_merged,
gboolean diagonal_neighbors,
gdouble x,
gdouble y,
const GimpRGB *color,
GimpPattern *pattern);
/* public functions */
gboolean
void
gimp_drawable_bucket_fill (GimpDrawable *drawable,
GimpContext *context,
GimpFillType fill_type,
gint paint_mode,
gdouble opacity,
GimpFillOptions *options,
gboolean fill_transparent,
GimpSelectCriterion fill_criterion,
gdouble threshold,
gboolean sample_merged,
gboolean diagonal_neighbors,
gdouble x,
gdouble y,
GError **error)
{
GimpPattern *pattern;
GimpRGB color;
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);
if (! gimp_get_fill_params (context, fill_type, &color, &pattern, error))
return FALSE;
gimp_palettes_add_color_history (context->gimp,
&color);
gimp_drawable_bucket_fill_internal (drawable,
fill_type,
paint_mode, opacity,
fill_transparent, fill_criterion,
threshold, sample_merged,
diagonal_neighbors, x, y,
&color, pattern);
return TRUE;
}
/* private functions */
static void
gimp_drawable_bucket_fill_internal (GimpDrawable *drawable,
GimpFillType fill_type,
gint paint_mode,
gdouble opacity,
gboolean fill_transparent,
GimpSelectCriterion fill_criterion,
gdouble threshold,
gboolean sample_merged,
gboolean diagonal_neighbors,
gdouble x,
gdouble y,
const GimpRGB *color,
GimpPattern *pattern)
gdouble y)
{
GimpImage *image;
GimpPickable *pickable;
GeglBuffer *buffer;
GeglBuffer *mask_buffer;
GimpPattern *pattern = NULL;
GimpRGB color;
gint x1, y1, x2, y2;
gint mask_offset_x = 0;
gint mask_offset_y = 0;
......@@ -133,10 +74,7 @@ gimp_drawable_bucket_fill_internal (GimpDrawable *drawable,
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
g_return_if_fail (fill_type != GIMP_FILL_PATTERN ||
GIMP_IS_PATTERN (pattern));
g_return_if_fail (fill_type == GIMP_FILL_PATTERN ||
color != NULL);
g_return_if_fail (GIMP_IS_FILL_OPTIONS (options));
image = gimp_item_get_image (GIMP_ITEM (drawable));
......@@ -216,30 +154,34 @@ gimp_drawable_bucket_fill_internal (GimpDrawable *drawable,
buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, x2 - x1, y2 - y1),
gimp_drawable_get_format_with_alpha (drawable));
switch (fill_type)
switch (gimp_fill_options_get_style (options))
{
case GIMP_FILL_FOREGROUND:
case GIMP_FILL_BACKGROUND:
case GIMP_FILL_WHITE:
case GIMP_FILL_TRANSPARENT:
{
GeglColor *gegl_color = gimp_gegl_color_new (color);
gegl_buffer_set_color (buffer, NULL, gegl_color);
g_object_unref (gegl_color);
}
case GIMP_FILL_STYLE_SOLID:
gimp_context_get_foreground (GIMP_CONTEXT (options), &color);
break;
case GIMP_FILL_PATTERN:
{
GeglBuffer *pattern_buffer = gimp_pattern_create_buffer (pattern);
gegl_buffer_set_pattern (buffer, NULL, pattern_buffer, -x1, -y1);
g_object_unref (pattern_buffer);
}
case GIMP_FILL_STYLE_PATTERN:
pattern = gimp_context_get_pattern (GIMP_CONTEXT (options));
break;
}
if (pattern)
{
GeglBuffer *pattern_buffer = gimp_pattern_create_buffer (pattern);
gegl_buffer_set_pattern (buffer, NULL, pattern_buffer, -x1, -y1);
g_object_unref (pattern_buffer);
}
else
{
GeglColor *gegl_color = gimp_gegl_color_new (&color);
gegl_buffer_set_color (buffer, NULL, gegl_color);
g_object_unref (gegl_color);
gimp_palettes_add_color_history (image->gimp, &color);
}
gimp_gegl_apply_opacity (buffer, NULL, NULL, buffer,
mask_buffer,
-mask_offset_x,
......@@ -251,7 +193,8 @@ gimp_drawable_bucket_fill_internal (GimpDrawable *drawable,
gimp_drawable_apply_buffer (drawable, buffer,
GEGL_RECTANGLE (0, 0, x2 - x1, y2 - y1),
TRUE, C_("undo-type", "Bucket Fill"),
opacity, paint_mode,
gimp_context_get_opacity (GIMP_CONTEXT (options)),
gimp_context_get_paint_mode (GIMP_CONTEXT (options)),
NULL, x1, y1);
g_object_unref (buffer);
......
......@@ -19,19 +19,15 @@
#define __GIMP_DRAWABLE_BUCKET_FILL_H__
gboolean gimp_drawable_bucket_fill (GimpDrawable *drawable,
GimpContext *context,
GimpFillType fill_type,
gint paint_mode,
gdouble opacity,
gboolean fill_transparent,
GimpSelectCriterion fill_criterion,
gdouble threshold,
gboolean sample_merged,
gboolean diagonal_neighbors,
gdouble x,
gdouble y,
GError **error);
void gimp_drawable_bucket_fill (GimpDrawable *drawable,
GimpFillOptions *options,
gboolean fill_transparent,
GimpSelectCriterion fill_criterion,
gdouble threshold,
gboolean sample_merged,
gboolean diagonal_neighbors,
gdouble x,
gdouble y);
#endif /* __GIMP_DRAWABLE_BUCKET_FILL_H__ */
......@@ -19,8 +19,6 @@
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
......@@ -605,58 +603,37 @@ 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));
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpFillOptions *options = gimp_fill_options_new (gimp);
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
if (gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error))
{
GimpFillOptions *options = gimp_fill_options_new (gimp);
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
success = gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error);
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
if (success)
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
{
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
success = gimp_edit_fill (image, drawable, options, NULL);
}
g_object_unref (options);
else
{
gimp_drawable_bucket_fill (drawable, options,
FALSE /* don't fill transparent */,
GIMP_SELECT_CRITERION_COMPOSITE,
threshold / 255.0,
sample_merged,
FALSE /* no diagonal neighbors */,
x, y);
}
}
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 = FALSE;
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
paint_mode, opacity / 100.0,
FALSE /* don't fill transparent */,
GIMP_SELECT_CRITERION_COMPOSITE,
threshold / 255.0,
sample_merged,
FALSE /* no diagonal neighbors */,
x, y,
error);
}
g_object_unref (options);
}
else
success = FALSE;
......@@ -703,58 +680,37 @@ 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));
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpFillOptions *options = gimp_fill_options_new (gimp);
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
if (gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error))
{
GimpFillOptions *options = gimp_fill_options_new (gimp);
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
success = gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error);
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
if (success)
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
{
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
success = gimp_edit_fill (image, drawable, options, NULL);
}
g_object_unref (options);
else
{
gimp_drawable_bucket_fill (drawable, options,
fill_transparent,
select_criterion,
threshold / 255.0,
sample_merged,
FALSE /* no diagonal neighbors */,
x, y);
}
}
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 = FALSE;
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
paint_mode, opacity / 100.0,
fill_transparent,
select_criterion,
threshold / 255.0,
sample_merged,
FALSE /* no diagonal neighbors */,
x, y,
error);
}
g_object_unref (options);
}
else
success = FALSE;
......
......@@ -172,74 +172,56 @@ gimp_bucket_fill_tool_button_release (GimpTool *tool,
gimp_image_coords_in_active_pickable (image, coords,
options->sample_merged, TRUE))
{
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GimpContext *context = GIMP_CONTEXT (options);
gboolean success;
GError *error = NULL;
if (options->fill_selection)
{
GimpFillOptions *fill_options = gimp_fill_options_new (image->gimp);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GimpContext *context = GIMP_CONTEXT (options);
GimpFillOptions *fill_options;
gboolean success;
GError *error = NULL;
success = gimp_fill_options_set_by_fill_mode (fill_options, context,
options->fill_mode,
&error);
fill_options = gimp_fill_options_new (image->gimp);
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));
success = gimp_edit_fill (image, drawable, fill_options, NULL);
}
success = gimp_fill_options_set_by_fill_mode (fill_options, context,
options->fill_mode,
&error);
g_object_unref (fill_options);
}
else
if (success)
{
GimpFillType fill_type;
gint x, y;
x = coords->x;
y = coords->y;
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));
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;
success = gimp_edit_fill (image, drawable, fill_options, NULL);
}
if (! options->sample_merged)
else
{
gint off_x, off_y;
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
x -= off_x;
y -= off_y;
gint x = coords->x;
gint y = coords->y;
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;
}
gimp_drawable_bucket_fill (drawable, fill_options,
options->fill_transparent,
options->fill_criterion,
options->threshold / 255.0,
options->sample_merged,
options->diagonal_neighbors,
x, y);
}
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
gimp_context_get_paint_mode (context),
gimp_context_get_opacity (context),
options->fill_transparent,
options->fill_criterion,
options->threshold / 255.0,
options->sample_merged,
options->diagonal_neighbors,
x, y, &error);
}
g_object_unref (fill_options);
if (success)
{
gimp_image_flush (image);
......
......@@ -641,58 +641,37 @@ HELP
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpFillOptions *options = gimp_fill_options_new (gimp);
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
if (gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error))
{
GimpFillOptions *options = gimp_fill_options_new (gimp);
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
success = gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error);
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
if (success)
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
{
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
success = gimp_edit_fill (image, drawable, options, NULL);
}
g_object_unref (options);
else
{
gimp_drawable_bucket_fill (drawable, options,
FALSE /* don't fill transparent */,
GIMP_SELECT_CRITERION_COMPOSITE,
threshold / 255.0,
sample_merged,
FALSE /* no diagonal neighbors */,
x, y);
}
}
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 = FALSE;
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
paint_mode, opacity / 100.0,
FALSE /* don't fill transparent */,
GIMP_SELECT_CRITERION_COMPOSITE,
threshold / 255.0,
sample_merged,
FALSE /* no diagonal neighbors */,
x, y,
error);
}
g_object_unref (options);
}
else
success = FALSE;
......@@ -767,58 +746,37 @@ HELP
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpFillOptions *options = gimp_fill_options_new (gimp);
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
if (gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error))
{
GimpFillOptions *options = gimp_fill_options_new (gimp);
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
success = gimp_fill_options_set_by_fill_mode (options, context,
fill_mode, error);
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
if (success)
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
{
gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
success = gimp_edit_fill (image, drawable, options, NULL);
}
g_object_unref (options);
else
{
gimp_drawable_bucket_fill (drawable, options,
fill_transparent,
select_criterion,
threshold / 255.0,
sample_merged,
FALSE /* no diagonal neighbors */,
x, y);
}
}
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 = FALSE;
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
paint_mode, opacity / 100.0,
fill_transparent,
select_criterion,
threshold / 255.0,
sample_merged,
FALSE /* no diagonal neighbors */,
x, y,
error);
}
g_object_unref (options);
}
else
success = FALSE;
......@@ -1043,8 +1001,7 @@ CODE
}
@headers = qw(<string.h>
"libgimpconfig/gimpconfig.h"
@headers = qw("libgimpconfig/gimpconfig.h"
"core/gimp.h"
"core/gimp-edit.h"
"core/gimpimage.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