pdb, libgimp: add gimp_context_set/get_mypaint_brush()

This commit is contained in:
Michael Natterer 2016-01-02 13:40:38 +01:00
parent 72f9bea765
commit 80f713c9b8
8 changed files with 276 additions and 1 deletions

View File

@ -1396,6 +1396,61 @@ context_set_dynamics_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GimpValueArray *
context_get_mypaint_brush_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
gchar *name = NULL;
GimpMybrush *brush = gimp_context_get_mybrush (context);
if (brush)
name = g_strdup (gimp_object_get_name (brush));
else
success = FALSE;
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_take_string (gimp_value_array_index (return_vals, 1), name);
return return_vals;
}
static GimpValueArray *
context_set_mypaint_brush_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
const gchar *name;
name = g_value_get_string (gimp_value_array_index (args, 0));
if (success)
{
GimpMybrush *brush = gimp_pdb_get_mybrush (gimp, name, FALSE, error);
if (brush)
gimp_context_set_mybrush (context, brush);
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
context_get_pattern_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -3840,6 +3895,54 @@ register_context_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-get-mypaint-brush
*/
procedure = gimp_procedure_new (context_get_mypaint_brush_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-get-mypaint-brush");
gimp_procedure_set_static_strings (procedure,
"gimp-context-get-mypaint-brush",
"Retrieve the currently active MyPaint brush.",
"This procedure returns the name of the currently active MyPaint brush.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2016",
NULL);
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("name",
"name",
"The name of the active MyPaint brush",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-set-mypaint-brush
*/
procedure = gimp_procedure_new (context_set_mypaint_brush_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-context-set-mypaint-brush");
gimp_procedure_set_static_strings (procedure,
"gimp-context-set-mypaint-brush",
"Set the specified MyPaint brush as the active MyPaint brush.",
"This procedure allows the active MyPaint brush to be set by specifying its name. The name is simply a string which corresponds to one of the names of the installed MyPaint brushes. If there is no matching MyPaint brush found, this procedure will return an error. Otherwise, the specified MyPaint brush becomes active and will be used in all subsequent MyPaint paint operations.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2016",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("name",
"name",
"The name of the MyPaint brush",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-context-get-pattern
*/

View File

@ -154,6 +154,41 @@ gimp_pdb_get_dynamics (Gimp *gimp,
return dynamics;
}
GimpMybrush *
gimp_pdb_get_mybrush (Gimp *gimp,
const gchar *name,
gboolean writable,
GError **error)
{
GimpMybrush *brush;
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_ERROR_INVALID_ARGUMENT,
_("Invalid empty MyPaint brush name"));
return NULL;
}
brush = (GimpMybrush *) gimp_pdb_get_data_factory_item (gimp->mybrush_factory, name);
if (! brush)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
_("MyPaint brush '%s' not found"), name);
}
else if (writable && ! gimp_data_is_writable (GIMP_DATA (brush)))
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
_("MyPaint brush '%s' is not editable"), name);
return NULL;
}
return brush;
}
GimpPattern *
gimp_pdb_get_pattern (Gimp *gimp,
const gchar *name,

View File

@ -31,6 +31,10 @@ GimpDynamics * gimp_pdb_get_dynamics (Gimp *gimp,
const gchar *name,
gboolean writable,
GError **error);
GimpMybrush * gimp_pdb_get_mybrush (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"
/* 791 procedures registered total */
/* 793 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View File

@ -99,6 +99,7 @@ EXPORTS
gimp_context_get_line_miter_limit
gimp_context_get_line_width
gimp_context_get_line_width_unit
gimp_context_get_mypaint_brush
gimp_context_get_opacity
gimp_context_get_paint_method
gimp_context_get_paint_mode
@ -152,6 +153,7 @@ EXPORTS
gimp_context_set_line_miter_limit
gimp_context_set_line_width
gimp_context_set_line_width_unit
gimp_context_set_mypaint_brush
gimp_context_set_opacity
gimp_context_set_paint_method
gimp_context_set_paint_mode

View File

@ -1698,6 +1698,73 @@ gimp_context_set_dynamics (const gchar *name)
return success;
}
/**
* gimp_context_get_mypaint_brush:
*
* Retrieve the currently active MyPaint brush.
*
* This procedure returns the name of the currently active MyPaint
* brush.
*
* Returns: The name of the active MyPaint brush.
*
* Since: 2.10
**/
gchar *
gimp_context_get_mypaint_brush (void)
{
GimpParam *return_vals;
gint nreturn_vals;
gchar *name = NULL;
return_vals = gimp_run_procedure ("gimp-context-get-mypaint-brush",
&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_mypaint_brush:
* @name: The name of the MyPaint brush.
*
* Set the specified MyPaint brush as the active MyPaint brush.
*
* This procedure allows the active MyPaint brush to be set by
* specifying its name. The name is simply a string which corresponds
* to one of the names of the installed MyPaint brushes. If there is no
* matching MyPaint brush found, this procedure will return an error.
* Otherwise, the specified MyPaint brush becomes active and will be
* used in all subsequent MyPaint paint operations.
*
* Returns: TRUE on success.
*
* Since: 2.10
**/
gboolean
gimp_context_set_mypaint_brush (const gchar *name)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-context-set-mypaint-brush",
&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

@ -86,6 +86,8 @@ gdouble gimp_context_get_brush_force (void);
gboolean gimp_context_set_brush_force (gdouble force);
gchar* gimp_context_get_dynamics (void);
gboolean gimp_context_set_dynamics (const gchar *name);
gchar* gimp_context_get_mypaint_brush (void);
gboolean gimp_context_set_mypaint_brush (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

@ -1507,6 +1507,67 @@ CODE
);
}
sub context_get_mypaint_brush {
$blurb = 'Retrieve the currently active MyPaint brush.';
$help = <<'HELP';
This procedure returns the name of the currently active MyPaint brush.
HELP
&mitch_pdb_misc('2016', '2.10');
@outargs = (
{ name => 'name', type => 'string',
desc => 'The name of the active MyPaint brush' }
);
%invoke = (
code => <<'CODE'
{
GimpMybrush *brush = gimp_context_get_mybrush (context);
if (brush)
name = g_strdup (gimp_object_get_name (brush));
else
success = FALSE;
}
CODE
);
}
sub context_set_mypaint_brush {
$blurb = 'Set the specified MyPaint brush as the active MyPaint brush.';
$help = <<'HELP';
This procedure allows the active MyPaint brush to be set by
specifying its name. The name is simply a string which corresponds to
one of the names of the installed MyPaint brushes. If there is no
matching MyPaint brush found, this procedure will return an error.
Otherwise, the specified MyPaint brush becomes active and will be
used in all subsequent MyPaint paint operations.
HELP
&mitch_pdb_misc('2016', '2.10');
@inargs = (
{ name => 'name', type => 'string', non_empty => 1,
desc => 'The name of the MyPaint brush' }
);
%invoke = (
code => <<'CODE'
{
GimpMybrush *brush = gimp_pdb_get_mybrush (gimp, name, FALSE, error);
if (brush)
gimp_context_set_mybrush (context, brush);
else
success = FALSE;
}
CODE
);
}
sub context_get_pattern {
$blurb = 'Retrieve the currently active pattern.';
@ -2947,6 +3008,7 @@ CODE
context_get_brush_force
context_set_brush_force
context_get_dynamics context_set_dynamics
context_get_mypaint_brush context_set_mypaint_brush
context_get_pattern context_set_pattern
context_get_gradient context_set_gradient
context_get_palette context_set_palette