Commit 8fa7bc36 authored by Michael Natterer's avatar Michael Natterer 😴

Bug 314379 - Allow stroking as outline (not with a paint tool) via the PDB

Add new PDB procedures gimp-context-get/set-stroke-method and honor
the new setting in gimp-edit-stroke and gimp-edit-stroke-vectors.

Internally, keep a GimpStrokeOptions around in GimpPDBContext to keep
track of the newly added PDB state, and use it for the stroke
operations instead of creating a scratch GimpStrokeOptions.
parent 701bc8f7
......@@ -179,6 +179,57 @@ context_set_paint_method_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GimpValueArray *
context_get_stroke_method_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
GimpValueArray *return_vals;
gint32 stroke_method = 0;
GimpStrokeOptions *options =
gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
g_object_get (options,
"method", &stroke_method,
NULL);
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
g_value_set_enum (gimp_value_array_index (return_vals, 1), stroke_method);
return return_vals;
}
static GimpValueArray *
context_set_stroke_method_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
gint32 stroke_method;
stroke_method = g_value_get_enum (gimp_value_array_index (args, 0));
if (success)
{
GimpStrokeOptions *options =
gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
g_object_set (options,
"method", stroke_method,
NULL);
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
context_get_foreground_invoker (GimpProcedure *procedure,
Gimp *gimp,
......@@ -2372,6 +2423,54 @@ register_context_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-get-stroke-method
*/
procedure = gimp_procedure_new (context_get_stroke_method_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-get-stroke-method");
gimp_procedure_set_static_strings (procedure,
"gimp-context-get-stroke-method",
"Retrieve the currently active stroke method.",
"This procedure returns the currently active stroke method.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2015",
NULL);
gimp_procedure_add_return_value (procedure,
g_param_spec_enum ("stroke-method",
"stroke method",
"The active stroke method",
GIMP_TYPE_STROKE_METHOD,
GIMP_STROKE_LINE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-set-stroke-method
*/
procedure = gimp_procedure_new (context_set_stroke_method_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-set-stroke-method");
gimp_procedure_set_static_strings (procedure,
"gimp-context-set-stroke-method",
"Set the specified stroke method as the active stroke method.",
"This procedure set the specified stroke method as the active stroke method. The new method will be used in all subsequent stroke operations.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2015",
NULL);
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("stroke-method",
"stroke method",
"The new stroke method",
GIMP_TYPE_STROKE_METHOD,
GIMP_STROKE_LINE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-get-foreground
*/
......
......@@ -861,13 +861,10 @@ edit_stroke_invoker (GimpProcedure *procedure,
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpStrokeOptions *options = gimp_stroke_options_new (gimp, context, TRUE);
GimpStrokeOptions *options;
GimpPaintOptions *paint_options;
options = gimp_stroke_options_new (gimp, context, TRUE);
g_object_set (options,
"method", GIMP_STROKE_PAINT_METHOD,
NULL);
options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
paint_options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
......@@ -877,7 +874,6 @@ edit_stroke_invoker (GimpProcedure *procedure,
drawable, context, options, paint_options,
TRUE, progress, error);
g_object_unref (options);
g_object_unref (paint_options);
}
else
......@@ -915,10 +911,7 @@ edit_stroke_vectors_invoker (GimpProcedure *procedure,
GimpStrokeOptions *options;
GimpPaintOptions *paint_options;
options = gimp_stroke_options_new (gimp, context, TRUE);
g_object_set (options,
"method", GIMP_STROKE_PAINT_METHOD,
NULL);
options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
paint_options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
......@@ -928,7 +921,6 @@ edit_stroke_vectors_invoker (GimpProcedure *procedure,
drawable, context, options, paint_options,
TRUE, progress, error);
g_object_unref (options);
g_object_unref (paint_options);
}
else
......
......@@ -31,6 +31,7 @@
#include "core/gimp.h"
#include "core/gimplist.h"
#include "core/gimppaintinfo.h"
#include "core/gimpstrokeoptions.h"
#include "paint/gimpbrushcore.h"
#include "paint/gimppaintoptions.h"
......@@ -155,12 +156,26 @@ gimp_pdb_context_init (GimpPDBContext *context)
static void
gimp_pdb_context_constructed (GObject *object)
{
GimpPDBContext *context = GIMP_PDB_CONTEXT (object);
GimpInterpolationType interpolation;
gint threshold;
GParamSpec *pspec;
G_OBJECT_CLASS (parent_class)->constructed (object);
context->stroke_options = gimp_stroke_options_new (GIMP_CONTEXT (context)->gimp,
GIMP_CONTEXT (context),
TRUE);
/* preserve the traditional PDB default */
g_object_set (context->stroke_options,
"method", GIMP_STROKE_PAINT_METHOD,
NULL);
g_object_bind_property (G_OBJECT (context), "antialias",
G_OBJECT (context->stroke_options), "antialias",
G_BINDING_SYNC_CREATE);
/* get default interpolation from gimprc */
interpolation = GIMP_CONTEXT (object)->gimp->config->interpolation_type;
......@@ -197,6 +212,12 @@ gimp_pdb_context_finalize (GObject *object)
context->paint_options_list = NULL;
}
if (context->stroke_options)
{
g_object_unref (context->stroke_options);
context->stroke_options = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......@@ -404,3 +425,11 @@ gimp_pdb_context_get_brush_options (GimpPDBContext *context)
return g_list_reverse (brush_options);
}
GimpStrokeOptions *
gimp_pdb_context_get_stroke_options (GimpPDBContext *context)
{
g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
return context->stroke_options;
}
......@@ -53,6 +53,7 @@ struct _GimpPDBContext
GimpTransformResize transform_resize;
GimpContainer *paint_options_list;
GimpStrokeOptions *stroke_options;
};
struct _GimpPDBContextClass
......@@ -61,15 +62,17 @@ struct _GimpPDBContextClass
};
GType gimp_pdb_context_get_type (void) G_GNUC_CONST;
GType gimp_pdb_context_get_type (void) G_GNUC_CONST;
GimpContext * gimp_pdb_context_new (Gimp *gimp,
GimpContext *parent,
gboolean set_parent);
GimpContext * gimp_pdb_context_new (Gimp *gimp,
GimpContext *parent,
gboolean set_parent);
GimpPaintOptions * gimp_pdb_context_get_paint_options (GimpPDBContext *context,
const gchar *name);
GList * gimp_pdb_context_get_brush_options (GimpPDBContext *context);
GimpPaintOptions * gimp_pdb_context_get_paint_options (GimpPDBContext *context,
const gchar *name);
GList * gimp_pdb_context_get_brush_options (GimpPDBContext *context);
GimpStrokeOptions * gimp_pdb_context_get_stroke_options (GimpPDBContext *context);
#endif /* __GIMP_PDB_CONTEXT_H__ */
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 773 procedures registered total */
/* 775 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -102,6 +102,7 @@ EXPORTS
gimp_context_get_sample_threshold
gimp_context_get_sample_threshold_int
gimp_context_get_sample_transparent
gimp_context_get_stroke_method
gimp_context_get_transform_direction
gimp_context_get_transform_recursion
gimp_context_get_transform_resize
......@@ -147,6 +148,7 @@ EXPORTS
gimp_context_set_sample_threshold
gimp_context_set_sample_threshold_int
gimp_context_set_sample_transparent
gimp_context_set_stroke_method
gimp_context_set_transform_direction
gimp_context_set_transform_recursion
gimp_context_set_transform_resize
......
......@@ -245,6 +245,69 @@ gimp_context_set_paint_method (const gchar *name)
return success;
}
/**
* gimp_context_get_stroke_method:
*
* Retrieve the currently active stroke method.
*
* This procedure returns the currently active stroke method.
*
* Returns: The active stroke method.
*
* Since: 2.10
**/
GimpStrokeMethod
gimp_context_get_stroke_method (void)
{
GimpParam *return_vals;
gint nreturn_vals;
GimpStrokeMethod stroke_method = 0;
return_vals = gimp_run_procedure ("gimp-context-get-stroke-method",
&nreturn_vals,
GIMP_PDB_END);
if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
stroke_method = return_vals[1].data.d_int32;
gimp_destroy_params (return_vals, nreturn_vals);
return stroke_method;
}
/**
* gimp_context_set_stroke_method:
* @stroke_method: The new stroke method.
*
* Set the specified stroke method as the active stroke method.
*
* This procedure set the specified stroke method as the active stroke
* method. The new method will be used in all subsequent stroke
* operations.
*
* Returns: TRUE on success.
*
* Since: 2.10
**/
gboolean
gimp_context_set_stroke_method (GimpStrokeMethod stroke_method)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-context-set-stroke-method",
&nreturn_vals,
GIMP_PDB_INT32, stroke_method,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* gimp_context_get_foreground:
* @foreground: The foreground color.
......
......@@ -39,6 +39,8 @@ gboolean gimp_context_list_paint_methods (gint
gchar ***paint_methods);
gchar* gimp_context_get_paint_method (void);
gboolean gimp_context_set_paint_method (const gchar *name);
GimpStrokeMethod gimp_context_get_stroke_method (void);
gboolean gimp_context_set_stroke_method (GimpStrokeMethod stroke_method);
gboolean gimp_context_get_foreground (GimpRGB *foreground);
gboolean gimp_context_set_foreground (const GimpRGB *foreground);
gboolean gimp_context_get_background (GimpRGB *background);
......
......@@ -184,6 +184,63 @@ CODE
);
}
sub context_get_stroke_method {
$blurb = 'Retrieve the currently active stroke method.';
$help = <<'HELP';
This procedure returns the currently active stroke method.
HELP
&mitch_pdb_misc('2015', '2.10');
@outargs = (
{ name => 'stroke_method', type => 'enum GimpStrokeMethod',
desc => 'The active stroke method' }
);
%invoke = (
code => <<'CODE'
{
GimpStrokeOptions *options =
gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
g_object_get (options,
"method", &stroke_method,
NULL);
}
CODE
);
}
sub context_set_stroke_method {
$blurb = 'Set the specified stroke method as the active stroke method.';
$help = <<'HELP';
This procedure set the specified stroke method as the active stroke
method. The new method will be used in all subsequent stroke
operations.
HELP
&mitch_pdb_misc('2015', '2.10');
@inargs = (
{ name => 'stroke_method', type => 'enum GimpStrokeMethod',
desc => 'The new stroke method' }
);
%invoke = (
code => <<'CODE'
{
GimpStrokeOptions *options =
gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
g_object_set (options,
"method", stroke_method,
NULL);
}
CODE
);
}
sub context_get_foreground {
$blurb = "Get the current GIMP foreground color.";
......@@ -2430,6 +2487,7 @@ CODE
@procs = qw(context_push context_pop context_set_defaults
context_list_paint_methods
context_get_paint_method context_set_paint_method
context_get_stroke_method context_set_stroke_method
context_get_foreground context_set_foreground
context_get_background context_set_background
context_set_default_colors
......
......@@ -938,13 +938,10 @@ HELP
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpStrokeOptions *options = gimp_stroke_options_new (gimp, context, TRUE);
GimpStrokeOptions *options;
GimpPaintOptions *paint_options;
options = gimp_stroke_options_new (gimp, context, TRUE);
g_object_set (options,
"method", GIMP_STROKE_PAINT_METHOD,
NULL);
options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
paint_options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
......@@ -954,7 +951,6 @@ HELP
drawable, context, options, paint_options,
TRUE, progress, error);
g_object_unref (options);
g_object_unref (paint_options);
}
else
......@@ -995,10 +991,7 @@ HELP
GimpStrokeOptions *options;
GimpPaintOptions *paint_options;
options = gimp_stroke_options_new (gimp, context, TRUE);
g_object_set (options,
"method", GIMP_STROKE_PAINT_METHOD,
NULL);
options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
paint_options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
......@@ -1008,7 +1001,6 @@ HELP
drawable, context, options, paint_options,
TRUE, progress, error);
g_object_unref (options);
g_object_unref (paint_options);
}
else
......
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