pdb: add dynamics accessors to the context procedures

This commit is contained in:
Michael Natterer 2011-10-31 21:07:08 +01:00
parent 5144e7e47c
commit 01344f811d
8 changed files with 279 additions and 1 deletions

View File

@ -423,6 +423,61 @@ context_set_brush_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GValueArray *
context_get_dynamics_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error)
{
gboolean success = TRUE;
GValueArray *return_vals;
gchar *name = NULL;
GimpDynamics *dynamics = gimp_context_get_dynamics (context);
if (dynamics)
name = g_strdup (gimp_object_get_name (dynamics));
else
success = FALSE;
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_take_string (&return_vals->values[1], name);
return return_vals;
}
static GValueArray *
context_set_dynamics_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error)
{
gboolean success = TRUE;
const gchar *name;
name = g_value_get_string (&args->values[0]);
if (success)
{
GimpDynamics *dynamics = gimp_pdb_get_dynamics (gimp, name, FALSE, error);
if (dynamics)
gimp_context_set_dynamics (context, dynamics);
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GValueArray *
context_get_pattern_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -1598,6 +1653,54 @@ register_context_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-get-dynamics
*/
procedure = gimp_procedure_new (context_get_dynamics_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-get-dynamics");
gimp_procedure_set_static_strings (procedure,
"gimp-context-get-dynamics",
"Retrieve the currently active paint dynamics.",
"This procedure returns the name of the currently active paint dynamics. All paint operations and stroke operations use this paint dynamics to control the application of paint to the image.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2011",
NULL);
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("name",
"name",
"The name of the active paint dynamics",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-set-dynamics
*/
procedure = gimp_procedure_new (context_set_dynamics_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-set-dynamics");
gimp_procedure_set_static_strings (procedure,
"gimp-context-set-dynamics",
"Set the specified paint dynamics as the active paint dynamics.",
"This procedure allows the active paint dynamics to be set by specifying its name. The name is simply a string which corresponds to one of the names of the installed paint dynamics. If there is no matching paint dynamics found, this procedure will return an error. Otherwise, the specified paint dynamics becomes active and will be used in all subsequent paint operations.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2011",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("name",
"name",
"The name of the paint dynamics",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-get-pattern
*/

View File

@ -117,6 +117,41 @@ gimp_pdb_get_generated_brush (Gimp *gimp,
return brush;
}
GimpDynamics *
gimp_pdb_get_dynamics (Gimp *gimp,
const gchar *name,
gboolean writable,
GError **error)
{
GimpDynamics *dynamics;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (! name || ! strlen (name))
{
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
_("Invalid empty paint dynamics name"));
return NULL;
}
dynamics = (GimpDynamics *) gimp_pdb_get_data_factory_item (gimp->dynamics_factory, name);
if (! dynamics)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
_("Paint dynamics '%s' not found"), name);
}
else if (writable && ! gimp_data_is_writable (GIMP_DATA (dynamics)))
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
_("Paint dynamics '%s' is not editable"), name);
return NULL;
}
return dynamics;
}
GimpPattern *
gimp_pdb_get_pattern (Gimp *gimp,
const gchar *name,

View File

@ -27,6 +27,10 @@ GimpBrush * gimp_pdb_get_generated_brush (Gimp *gimp,
const gchar *name,
gboolean writable,
GError **error);
GimpDynamics * gimp_pdb_get_dynamics (Gimp *gimp,
const gchar *name,
gboolean writable,
GError **error);
GimpPattern * gimp_pdb_get_pattern (Gimp *gimp,
const gchar *name,
GError **error);

View File

@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 636 procedures registered total */
/* 638 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View File

@ -72,6 +72,7 @@ EXPORTS
gimp_context_get_antialias
gimp_context_get_background
gimp_context_get_brush
gimp_context_get_dynamics
gimp_context_get_feather
gimp_context_get_feather_radius
gimp_context_get_font
@ -99,6 +100,7 @@ EXPORTS
gimp_context_set_brush
gimp_context_set_default_colors
gimp_context_set_defaults
gimp_context_set_dynamics
gimp_context_set_feather
gimp_context_set_feather_radius
gimp_context_set_font

View File

@ -634,6 +634,74 @@ gimp_context_set_brush (const gchar *name)
return success;
}
/**
* gimp_context_get_dynamics:
*
* Retrieve the currently active paint dynamics.
*
* This procedure returns the name of the currently active paint
* dynamics. All paint operations and stroke operations use this paint
* dynamics to control the application of paint to the image.
*
* Returns: The name of the active paint dynamics.
*
* Since: GIMP 2.8
**/
gchar *
gimp_context_get_dynamics (void)
{
GimpParam *return_vals;
gint nreturn_vals;
gchar *name = NULL;
return_vals = gimp_run_procedure ("gimp-context-get-dynamics",
&nreturn_vals,
GIMP_PDB_END);
if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
name = g_strdup (return_vals[1].data.d_string);
gimp_destroy_params (return_vals, nreturn_vals);
return name;
}
/**
* gimp_context_set_dynamics:
* @name: The name of the paint dynamics.
*
* Set the specified paint dynamics as the active paint dynamics.
*
* This procedure allows the active paint dynamics to be set by
* specifying its name. The name is simply a string which corresponds
* to one of the names of the installed paint dynamics. If there is no
* matching paint dynamics found, this procedure will return an error.
* Otherwise, the specified paint dynamics becomes active and will be
* used in all subsequent paint operations.
*
* Returns: TRUE on success.
*
* Since: GIMP 2.8
**/
gboolean
gimp_context_set_dynamics (const gchar *name)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-context-set-dynamics",
&nreturn_vals,
GIMP_PDB_STRING, name,
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_pattern:
*

View File

@ -51,6 +51,8 @@ GimpLayerModeEffects gimp_context_get_paint_mode (void);
gboolean gimp_context_set_paint_mode (GimpLayerModeEffects paint_mode);
gchar* gimp_context_get_brush (void);
gboolean gimp_context_set_brush (const gchar *name);
gchar* gimp_context_get_dynamics (void);
gboolean gimp_context_set_dynamics (const gchar *name);
gchar* gimp_context_get_pattern (void);
gboolean gimp_context_set_pattern (const gchar *name);
gchar* gimp_context_get_gradient (void);

View File

@ -487,6 +487,69 @@ CODE
);
}
sub context_get_dynamics {
$blurb = 'Retrieve the currently active paint dynamics.';
$help = <<'HELP';
This procedure returns the name of the currently active paint
dynamics. All paint operations and stroke operations use this paint
dynamics to control the application of paint to the image.
HELP
&mitch_pdb_misc('2011', '2.8');
@outargs = (
{ name => 'name', type => 'string',
desc => 'The name of the active paint dynamics' }
);
%invoke = (
code => <<'CODE'
{
GimpDynamics *dynamics = gimp_context_get_dynamics (context);
if (dynamics)
name = g_strdup (gimp_object_get_name (dynamics));
else
success = FALSE;
}
CODE
);
}
sub context_set_dynamics {
$blurb = 'Set the specified paint dynamics as the active paint dynamics.';
$help = <<'HELP';
This procedure allows the active paint dynamics to be set by
specifying its name. The name is simply a string which corresponds to
one of the names of the installed paint dynamics. If there is no
matching paint dynamics found, this procedure will return an error.
Otherwise, the specified paint dynamics becomes active and will be
used in all subsequent paint operations.
HELP
&mitch_pdb_misc('2011', '2.8');
@inargs = (
{ name => 'name', type => 'string', non_empty => 1,
desc => 'The name of the paint dynamics' }
);
%invoke = (
code => <<'CODE'
{
GimpDynamics *dynamics = gimp_pdb_get_dynamics (gimp, name, FALSE, error);
if (dynamics)
gimp_context_set_dynamics (context, dynamics);
else
success = FALSE;
}
CODE
);
}
sub context_get_pattern {
$blurb = 'Retrieve the currently active pattern.';
@ -1452,6 +1515,7 @@ CODE
context_get_opacity context_set_opacity
context_get_paint_mode context_set_paint_mode
context_get_brush context_set_brush
context_get_dynamics context_set_dynamics
context_get_pattern context_set_pattern
context_get_gradient context_set_gradient
context_get_palette context_set_palette