1
1
mirror of https://gitlab.gnome.org/GNOME/gimp.git synced 2025-10-05 21:02:42 +02:00

pdb, libgimp: Add PDB get/set for fade-length and fade-repeat

This patch adds PDB functions to get and set the PaintOptions
fade-length and fade-repeat properties. This settings can be
used together with gimp_context_set_emulate_brush_dynamics ()
to further control how the paint strokes are drawn in a script
or plug-in.
This commit is contained in:
Alx Sa
2025-08-22 17:43:40 +00:00
parent f02910d00f
commit 2c91604509
6 changed files with 514 additions and 9 deletions

View File

@@ -1451,18 +1451,25 @@ context_get_emulate_brush_dynamics_invoker (GimpProcedure *procedure,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gboolean emulate_dynamics = FALSE;
GimpStrokeOptions *options =
gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
g_object_get (options,
"emulate-brush-dynamics", &emulate_dynamics,
NULL);
if (options)
g_object_get (options,
"emulate-brush-dynamics", &emulate_dynamics,
NULL);
else
success = FALSE;
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
g_value_set_boolean (gimp_value_array_index (return_vals, 1), emulate_dynamics);
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_boolean (gimp_value_array_index (return_vals, 1), emulate_dynamics);
return return_vals;
}
@@ -1883,6 +1890,125 @@ context_set_gradient_reverse_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GimpValueArray *
context_get_paint_fade_length_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gdouble fade_length = 0.0;
GimpPaintOptions *options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
"gimp-paintbrush");
if (options)
g_object_get (options,
"fade-length", &fade_length,
NULL);
else
success = FALSE;
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_double (gimp_value_array_index (return_vals, 1), fade_length);
return return_vals;
}
static GimpValueArray *
context_set_paint_fade_length_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
gdouble fade_length;
fade_length = g_value_get_double (gimp_value_array_index (args, 0));
if (success)
{
GimpPaintOptions *options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
"gimp-paintbrush");
g_object_set (options,
"fade-length", fade_length,
NULL);
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
context_get_paint_fade_repeat_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gint fade_repeat = 0;
GimpPaintOptions *options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
"gimp-paintbrush");
if (options)
g_object_get (options,
"fade-repeat", &fade_repeat,
NULL);
else
success = FALSE;
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_enum (gimp_value_array_index (return_vals, 1), fade_repeat);
return return_vals;
}
static GimpValueArray *
context_set_paint_fade_repeat_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
gint fade_repeat;
fade_repeat = g_value_get_enum (gimp_value_array_index (args, 0));
if (success)
{
GimpPaintOptions *options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
"gimp-paintbrush");
g_object_set (options,
"fade-repeat", fade_repeat,
NULL);
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
context_get_palette_invoker (GimpProcedure *procedure,
Gimp *gimp,
@@ -4736,6 +4862,100 @@ register_context_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-get-paint-fade-length
*/
procedure = gimp_procedure_new (context_get_paint_fade_length_invoker, FALSE);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-get-paint-fade-length");
gimp_procedure_set_static_help (procedure,
"Get the paint fade length.",
"Get the paint fade length for paint tools and the gradient tool.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Alx Sa.",
"Alx Sa.",
"2025");
gimp_procedure_add_return_value (procedure,
g_param_spec_double ("fade-length",
"fade length",
"The paint fade length setting",
0.0, 32767.0, 0.0,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-set-paint-fade-length
*/
procedure = gimp_procedure_new (context_set_paint_fade_length_invoker, FALSE);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-set-paint-fade-length");
gimp_procedure_set_static_help (procedure,
"Set the paint fade length.",
"Set the paint fade length for paint tools and the gradient tool.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Alx Sa.",
"Alx Sa.",
"2025");
gimp_procedure_add_argument (procedure,
g_param_spec_double ("fade-length",
"fade length",
"The paint fade length setting",
0.0, 32767.0, 0.0,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-get-paint-fade-repeat
*/
procedure = gimp_procedure_new (context_get_paint_fade_repeat_invoker, FALSE);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-get-paint-fade-repeat");
gimp_procedure_set_static_help (procedure,
"Get the paint fade repeat type.",
"Get the paint fade repeat type for paint tools and the gradient tool.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Alx Sa.",
"Alx Sa.",
"2025");
gimp_procedure_add_return_value (procedure,
g_param_spec_enum ("fade-repeat",
"fade repeat",
"The paint fade repeat type setting",
GIMP_TYPE_REPEAT_MODE,
GIMP_REPEAT_NONE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-set-paint-fade-repeat
*/
procedure = gimp_procedure_new (context_set_paint_fade_repeat_invoker, FALSE);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-set-paint-fade-repeat");
gimp_procedure_set_static_help (procedure,
"Set the paint fade repeat type.",
"Set the paint fade repeat type for paint tools and the gradient tool.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Alx Sa.",
"Alx Sa.",
"2025");
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("fade-repeat",
"fade repeat",
"The paint fade repeat type setting",
GIMP_TYPE_REPEAT_MODE,
GIMP_REPEAT_NONE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-get-palette
*/

View File

@@ -30,7 +30,7 @@
#include "internal-procs.h"
/* 725 procedures registered total */
/* 729 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View File

@@ -99,6 +99,8 @@ EXPORTS
gimp_context_get_line_width_unit
gimp_context_get_mypaint_brush
gimp_context_get_opacity
gimp_context_get_paint_fade_length
gimp_context_get_paint_fade_repeat
gimp_context_get_paint_method
gimp_context_get_paint_mode
gimp_context_get_palette
@@ -162,6 +164,8 @@ EXPORTS
gimp_context_set_line_width_unit
gimp_context_set_mypaint_brush
gimp_context_set_opacity
gimp_context_set_paint_fade_length
gimp_context_set_paint_fade_repeat
gimp_context_set_paint_method
gimp_context_set_paint_mode
gimp_context_set_palette

View File

@@ -2590,6 +2590,146 @@ gimp_context_set_gradient_reverse (gboolean reverse)
return success;
}
/**
* gimp_context_get_paint_fade_length:
*
* Get the paint fade length.
*
* Get the paint fade length for paint tools and the gradient tool.
*
* Returns: The paint fade length setting.
*
* Since: 3.2
**/
gdouble
gimp_context_get_paint_fade_length (void)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gdouble fade_length = 0.0;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_NONE);
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-context-get-paint-fade-length",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
fade_length = GIMP_VALUES_GET_DOUBLE (return_vals, 1);
gimp_value_array_unref (return_vals);
return fade_length;
}
/**
* gimp_context_set_paint_fade_length:
* @fade_length: The paint fade length setting.
*
* Set the paint fade length.
*
* Set the paint fade length for paint tools and the gradient tool.
*
* Returns: TRUE on success.
*
* Since: 3.2
**/
gboolean
gimp_context_set_paint_fade_length (gdouble fade_length)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean success = TRUE;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_DOUBLE, fade_length,
G_TYPE_NONE);
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-context-set-paint-fade-length",
args);
gimp_value_array_unref (args);
success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
gimp_value_array_unref (return_vals);
return success;
}
/**
* gimp_context_get_paint_fade_repeat:
*
* Get the paint fade repeat type.
*
* Get the paint fade repeat type for paint tools and the gradient
* tool.
*
* Returns: The paint fade repeat type setting.
*
* Since: 3.2
**/
GimpRepeatMode
gimp_context_get_paint_fade_repeat (void)
{
GimpValueArray *args;
GimpValueArray *return_vals;
GimpRepeatMode fade_repeat = 0;
args = gimp_value_array_new_from_types (NULL,
G_TYPE_NONE);
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-context-get-paint-fade-repeat",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
fade_repeat = GIMP_VALUES_GET_ENUM (return_vals, 1);
gimp_value_array_unref (return_vals);
return fade_repeat;
}
/**
* gimp_context_set_paint_fade_repeat:
* @fade_repeat: The paint fade repeat type setting.
*
* Set the paint fade repeat type.
*
* Set the paint fade repeat type for paint tools and the gradient
* tool.
*
* Returns: TRUE on success.
*
* Since: 3.2
**/
gboolean
gimp_context_set_paint_fade_repeat (GimpRepeatMode fade_repeat)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean success = TRUE;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_REPEAT_MODE, fade_repeat,
G_TYPE_NONE);
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-context-set-paint-fade-repeat",
args);
gimp_value_array_unref (args);
success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
gimp_value_array_unref (return_vals);
return success;
}
/**
* gimp_context_get_palette:
*

View File

@@ -105,6 +105,10 @@ GimpRepeatMode gimp_context_get_gradient_repeat_mode (void)
gboolean gimp_context_set_gradient_repeat_mode (GimpRepeatMode repeat_mode);
gboolean gimp_context_get_gradient_reverse (void);
gboolean gimp_context_set_gradient_reverse (gboolean reverse);
gdouble gimp_context_get_paint_fade_length (void);
gboolean gimp_context_set_paint_fade_length (gdouble fade_length);
GimpRepeatMode gimp_context_get_paint_fade_repeat (void);
gboolean gimp_context_set_paint_fade_repeat (GimpRepeatMode fade_repeat);
GimpPalette* gimp_context_get_palette (void);
gboolean gimp_context_set_palette (GimpPalette *palette);
GimpFont* gimp_context_get_font (void);

View File

@@ -1589,9 +1589,12 @@ HELP
GimpStrokeOptions *options =
gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
g_object_get (options,
"emulate-brush-dynamics", &emulate_dynamics,
NULL);
if (options)
g_object_get (options,
"emulate-brush-dynamics", &emulate_dynamics,
NULL);
else
success = FALSE;
}
CODE
);
@@ -1630,6 +1633,138 @@ CODE
);
}
sub context_get_paint_fade_length {
$blurb = 'Get the paint fade length.';
$help = <<'HELP';
Get the paint fade length for paint tools and the gradient tool.
HELP
$author = 'Alx Sa.';
$copyright = 'Alx Sa.';
$date = '2025';
$since = '3.2';
@outargs = (
{ name => 'fade_length', type => '0.0 <= double <= 32767.0',
desc => 'The paint fade length setting' }
);
%invoke = (
code => <<'CODE'
{
GimpPaintOptions *options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
"gimp-paintbrush");
if (options)
g_object_get (options,
"fade-length", &fade_length,
NULL);
else
success = FALSE;
}
CODE
);
}
sub context_set_paint_fade_length {
$blurb = 'Set the paint fade length.';
$help = <<'HELP';
Set the paint fade length for paint tools and the gradient tool.
HELP
$author = 'Alx Sa.';
$copyright = 'Alx Sa.';
$date = '2025';
$since = '3.2';
@inargs = (
{ name => 'fade_length', type => '0.0 <= double <= 32767.0',
desc => 'The paint fade length setting' }
);
%invoke = (
code => <<'CODE'
{
GimpPaintOptions *options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
"gimp-paintbrush");
g_object_set (options,
"fade-length", fade_length,
NULL);
}
CODE
);
}
sub context_get_paint_fade_repeat {
$blurb = 'Get the paint fade repeat type.';
$help = <<'HELP';
Get the paint fade repeat type for paint tools and the gradient tool.
HELP
$author = 'Alx Sa.';
$copyright = 'Alx Sa.';
$date = '2025';
$since = '3.2';
@outargs = (
{ name => 'fade_repeat', type => 'enum GimpRepeatMode',
desc => 'The paint fade repeat type setting' }
);
%invoke = (
code => <<'CODE'
{
GimpPaintOptions *options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
"gimp-paintbrush");
if (options)
g_object_get (options,
"fade-repeat", &fade_repeat,
NULL);
else
success = FALSE;
}
CODE
);
}
sub context_set_paint_fade_repeat {
$blurb = 'Set the paint fade repeat type.';
$help = <<'HELP';
Set the paint fade repeat type for paint tools and the gradient tool.
HELP
$author = 'Alx Sa.';
$copyright = 'Alx Sa.';
$date = '2025';
$since = '3.2';
@inargs = (
{ name => 'fade_repeat', type => 'enum GimpRepeatMode',
desc => 'The paint fade repeat type setting' }
);
%invoke = (
code => <<'CODE'
{
GimpPaintOptions *options =
gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
"gimp-paintbrush");
g_object_set (options,
"fade-repeat", fade_repeat,
NULL);
}
CODE
);
}
sub context_get_mypaint_brush {
$blurb = 'Get the currently active MyPaint brush.';
@@ -3534,6 +3669,8 @@ CODE
context_get_gradient_blend_color_space context_set_gradient_blend_color_space
context_get_gradient_repeat_mode context_set_gradient_repeat_mode
context_get_gradient_reverse context_set_gradient_reverse
context_get_paint_fade_length context_set_paint_fade_length
context_get_paint_fade_repeat context_set_paint_fade_repeat
context_get_palette context_set_palette
context_get_font context_set_font
context_get_antialias context_set_antialias