Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2018-11-04 22:56:38 +0300
committerAntonioya <blendergit@gmail.com>2018-11-04 22:56:38 +0300
commit8d9d473eec3c57e08d252edfd52376de1e1a4351 (patch)
treee13602bc0030c06477472315a363fc422b704007 /source/blender/makesrna/intern/rna_gpencil.c
parentbbb348afc1fab2c118e2ac68673f1aee6ea578b5 (diff)
GP: New API to move layers in layer list
This can be required in som production scripts
Diffstat (limited to 'source/blender/makesrna/intern/rna_gpencil.c')
-rw-r--r--source/blender/makesrna/intern/rna_gpencil.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 1dbca8b27c9..806133c71c2 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -72,6 +72,12 @@ static EnumPropertyItem rna_enum_gpencil_onion_modes_items[] = {
{ 0, NULL, 0, NULL, NULL }
};
+const EnumPropertyItem rna_enum_gplayer_move_type_items[] = {
+ { -1, "UP", 0, "Up", ""},
+ { 1, "DOWN", 0, "Down", ""},
+ { 0, NULL, 0, NULL, NULL}
+};
+
#endif
#ifdef RNA_RUNTIME
@@ -670,6 +676,25 @@ static void rna_GPencil_layer_remove(bGPdata *gpd, ReportList *reports, PointerR
WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
}
+static void rna_GPencil_layer_move(bGPdata *gpd, ReportList *reports, PointerRNA *layer_ptr, int type)
+{
+ bGPDlayer *gpl = layer_ptr->data;
+ if (BLI_findindex(&gpd->layers, gpl) == -1) {
+ BKE_report(reports, RPT_ERROR, "Layer not found in grease pencil data");
+ return;
+ }
+
+ BLI_assert(ELEM(type, -1, 0, 1)); /* we use value below */
+
+ const int direction = type * -1;
+
+ if (BLI_listbase_link_move(&gpd->layers, gpl, direction)) {
+ DEG_id_tag_update(&gpd->id, OB_RECALC_OB | OB_RECALC_DATA);
+ }
+
+ WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+}
+
static void rna_GPencil_frame_clear(bGPDframe *frame)
{
BKE_gpencil_free_strokes(frame);
@@ -1254,6 +1279,15 @@ static void rna_def_gpencil_layers_api(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+ func = RNA_def_function(srna, "move", "rna_GPencil_layer_move");
+ RNA_def_function_ui_description(func, "Move a grease pencil layer in the layer stack");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "layer", "GPencilLayer", "", "The layer to move");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+ parm = RNA_def_enum(func, "type", rna_enum_gplayer_move_type_items, 1, "", "Direction of movement");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "GPencilLayer");
RNA_def_property_pointer_funcs(prop, "rna_GPencil_active_layer_get", "rna_GPencil_active_layer_set", NULL, NULL);