mirror of https://github.com/GNOME/gimp.git
libgimp, pdb, app: new gimp_image_get_selected_drawables() function.
This commit is contained in:
parent
0f323d0279
commit
bd199fa0c2
|
@ -2027,6 +2027,51 @@ image_set_selected_layers_invoker (GimpProcedure *procedure,
|
|||
error ? *error : NULL);
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
image_get_selected_drawables_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
GimpContext *context,
|
||||
GimpProgress *progress,
|
||||
const GimpValueArray *args,
|
||||
GError **error)
|
||||
{
|
||||
gboolean success = TRUE;
|
||||
GimpValueArray *return_vals;
|
||||
GimpImage *image;
|
||||
gint num_drawables = 0;
|
||||
GimpItem **drawables = NULL;
|
||||
|
||||
image = g_value_get_object (gimp_value_array_index (args, 0));
|
||||
|
||||
if (success)
|
||||
{
|
||||
GList *list = gimp_image_get_selected_drawables (image);
|
||||
|
||||
num_drawables = g_list_length (list);
|
||||
|
||||
if (num_drawables)
|
||||
{
|
||||
gint i;
|
||||
|
||||
drawables = g_new (GimpItem *, num_drawables);
|
||||
|
||||
for (i = 0; i < num_drawables; i++, list = g_list_next (list))
|
||||
drawables[i] = g_object_ref (list->data);
|
||||
}
|
||||
}
|
||||
|
||||
return_vals = gimp_procedure_get_return_values (procedure, success,
|
||||
error ? *error : NULL);
|
||||
|
||||
if (success)
|
||||
{
|
||||
g_value_set_int (gimp_value_array_index (return_vals, 1), num_drawables);
|
||||
gimp_value_take_object_array (gimp_value_array_index (return_vals, 2), GIMP_TYPE_ITEM, (GObject **) drawables, num_drawables);
|
||||
}
|
||||
|
||||
return return_vals;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
image_get_selection_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -4774,6 +4819,42 @@ register_image_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-image-get-selected-drawables
|
||||
*/
|
||||
procedure = gimp_procedure_new (image_get_selected_drawables_invoker);
|
||||
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
||||
"gimp-image-get-selected-drawables");
|
||||
gimp_procedure_set_static_help (procedure,
|
||||
"Get the image's selected drawables",
|
||||
"This procedure returns the list of selected drawable in the specified image. This can be either layers, channels, or a layer mask.\n"
|
||||
"The active drawables are the active image channels. If there are none, these are the active image layers. If the active image layer has a layer mask and the layer mask is in edit mode, then the layer mask is the active drawable.",
|
||||
NULL);
|
||||
gimp_procedure_set_static_attribution (procedure,
|
||||
"Jehan",
|
||||
"Jehan",
|
||||
"2022");
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_image ("image",
|
||||
"image",
|
||||
"The image",
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_return_value (procedure,
|
||||
g_param_spec_int ("num-drawables",
|
||||
"num drawables",
|
||||
"The number of selected drawables in the image",
|
||||
0, G_MAXINT32, 0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_return_value (procedure,
|
||||
gimp_param_spec_object_array ("drawables",
|
||||
"drawables",
|
||||
"The list of selected drawables in the image.",
|
||||
GIMP_TYPE_ITEM,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-image-get-selection
|
||||
*/
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "internal-procs.h"
|
||||
|
||||
|
||||
/* 764 procedures registered total */
|
||||
/* 765 procedures registered total */
|
||||
|
||||
void
|
||||
internal_procs_init (GimpPDB *pdb)
|
||||
|
|
|
@ -418,6 +418,7 @@ EXPORTS
|
|||
gimp_image_get_precision
|
||||
gimp_image_get_resolution
|
||||
gimp_image_get_sample_point_position
|
||||
gimp_image_get_selected_drawables
|
||||
gimp_image_get_selected_layers
|
||||
gimp_image_get_selection
|
||||
gimp_image_get_simulation_profile
|
||||
|
|
|
@ -2396,6 +2396,57 @@ gimp_image_set_selected_layers (GimpImage *image,
|
|||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_image_get_selected_drawables:
|
||||
* @image: The image.
|
||||
* @num_drawables: (out): The number of selected drawables in the image.
|
||||
*
|
||||
* Get the image's selected drawables
|
||||
*
|
||||
* This procedure returns the list of selected drawable in the
|
||||
* specified image. This can be either layers, channels, or a layer
|
||||
* mask.
|
||||
* The active drawables are the active image channels. If there are
|
||||
* none, these are the active image layers. If the active image layer
|
||||
* has a layer mask and the layer mask is in edit mode, then the layer
|
||||
* mask is the active drawable.
|
||||
*
|
||||
* Returns: (array length=num_drawables) (element-type GimpItem) (transfer container):
|
||||
* The list of selected drawables in the image.
|
||||
* The returned value must be freed with g_free().
|
||||
*
|
||||
* Since: 3.0.0
|
||||
**/
|
||||
GimpItem **
|
||||
gimp_image_get_selected_drawables (GimpImage *image,
|
||||
gint *num_drawables)
|
||||
{
|
||||
GimpValueArray *args;
|
||||
GimpValueArray *return_vals;
|
||||
GimpItem **drawables = NULL;
|
||||
|
||||
args = gimp_value_array_new_from_types (NULL,
|
||||
GIMP_TYPE_IMAGE, image,
|
||||
G_TYPE_NONE);
|
||||
|
||||
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
||||
"gimp-image-get-selected-drawables",
|
||||
args);
|
||||
gimp_value_array_unref (args);
|
||||
|
||||
*num_drawables = 0;
|
||||
|
||||
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
*num_drawables = GIMP_VALUES_GET_INT (return_vals, 1);
|
||||
{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) drawables = g_memdup2 (a->data, a->length * sizeof (gpointer)); };
|
||||
}
|
||||
|
||||
gimp_value_array_unref (return_vals);
|
||||
|
||||
return drawables;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_image_get_selection:
|
||||
* @image: The image.
|
||||
|
|
|
@ -148,6 +148,8 @@ GimpLayer** gimp_image_get_selected_layers (GimpImage
|
|||
gboolean gimp_image_set_selected_layers (GimpImage *image,
|
||||
gint num_layers,
|
||||
const GimpLayer **layers);
|
||||
GimpItem** gimp_image_get_selected_drawables (GimpImage *image,
|
||||
gint *num_drawables);
|
||||
GimpSelection* gimp_image_get_selection (GimpImage *image);
|
||||
gboolean gimp_image_get_component_active (GimpImage *image,
|
||||
GimpChannelType component);
|
||||
|
|
|
@ -2086,6 +2086,54 @@ CODE
|
|||
);
|
||||
}
|
||||
|
||||
sub image_get_selected_drawables {
|
||||
$blurb = "Get the image's selected drawables";
|
||||
|
||||
$help = <<'HELP';
|
||||
This procedure returns the list of selected drawable in the specified image.
|
||||
This can be either layers, channels, or a layer mask.
|
||||
|
||||
The active drawables are the active image channels. If there are none,
|
||||
these are the active image layers. If the active image layer has a layer
|
||||
mask and the layer mask is in edit mode, then the layer mask is the
|
||||
active drawable.
|
||||
HELP
|
||||
|
||||
&jehan_pdb_misc('2022', '3.0.0');
|
||||
|
||||
@inargs = (
|
||||
{ name => 'image', type => 'image',
|
||||
desc => 'The image' }
|
||||
);
|
||||
|
||||
@outargs = (
|
||||
{ name => 'drawables', type => 'itemarray',
|
||||
desc => 'The list of selected drawables in the image.',
|
||||
array => { name => 'num_drawables',
|
||||
desc => 'The number of selected drawables in the image' } }
|
||||
);
|
||||
|
||||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
GList *list = gimp_image_get_selected_drawables (image);
|
||||
|
||||
num_drawables = g_list_length (list);
|
||||
|
||||
if (num_drawables)
|
||||
{
|
||||
gint i;
|
||||
|
||||
drawables = g_new (GimpItem *, num_drawables);
|
||||
|
||||
for (i = 0; i < num_drawables; i++, list = g_list_next (list))
|
||||
drawables[i] = g_object_ref (list->data);
|
||||
}
|
||||
}
|
||||
CODE
|
||||
);
|
||||
}
|
||||
|
||||
sub image_get_selection {
|
||||
$blurb = "Returns the specified image's selection.";
|
||||
|
||||
|
@ -3173,6 +3221,7 @@ CODE
|
|||
image_get_active_channel image_set_active_channel
|
||||
image_get_active_vectors image_set_active_vectors
|
||||
image_get_selected_layers image_set_selected_layers
|
||||
image_get_selected_drawables
|
||||
image_get_selection
|
||||
image_get_component_active image_set_component_active
|
||||
image_get_component_visible image_set_component_visible
|
||||
|
|
Loading…
Reference in New Issue