GPv3: Python API: Add function to get current frame on a layer

This adds the `layer.current_frame()` function which will get the frame
at the current scene time on this layer.

In the lagacy API this was the property `layer.active_frame`. Since we don't cache the visible
frame anymore, we use the current context to get the current scene time.

Pull Request: https://projects.blender.org/blender/blender/pulls/125892
This commit is contained in:
Falk David
2024-08-05 13:28:06 +02:00
committed by Falk David
parent 0e6d9c355c
commit 5ae70519b2

View File

@@ -24,6 +24,7 @@ const EnumPropertyItem rna_enum_tree_node_move_type_items[] = {
#ifdef RNA_RUNTIME
# include "BKE_attribute.hh"
# include "BKE_context.hh"
# include "BKE_grease_pencil.hh"
# include "BKE_report.hh"
@@ -175,6 +176,14 @@ static GreasePencilFrame *rna_GreasePencilLayer_get_frame_at(GreasePencilLayer *
return static_cast<Layer *>(layer)->frame_at(frame_number);
}
static GreasePencilFrame *rna_GreasePencilLayer_current_frame(GreasePencilLayer *layer,
bContext *C)
{
using namespace blender::bke::greasepencil;
Scene *scene = CTX_data_scene(C);
return static_cast<Layer *>(layer)->frame_at(scene->r.cfra);
}
static GreasePencilLayer *rna_GreasePencil_layer_new(GreasePencil *grease_pencil,
const char *name,
const bool set_active,
@@ -524,6 +533,13 @@ void RNA_api_grease_pencil_layer(StructRNA *srna)
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_pointer(func, "frame", "GreasePencilFrame", "Frame", "");
RNA_def_function_return(func, parm);
func = RNA_def_function(srna, "current_frame", "rna_GreasePencilLayer_current_frame");
RNA_def_function_ui_description(
func, "The Grease Pencil frame at the current scene time on this layer");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
parm = RNA_def_pointer(func, "frame", "GreasePencilFrame", "", "");
RNA_def_function_return(func, parm);
}
void RNA_api_grease_pencil_layers(StructRNA *srna)