GPv3: Add get_editable_drawing_at function

This function returns an editable drawing for a given layer at a specific scene time.

Pull Request: https://projects.blender.org/blender/blender/pulls/110295
This commit is contained in:
Falk David
2023-07-20 12:53:38 +02:00
committed by Falk David
parent 549848a0d8
commit 71837fcb04
2 changed files with 28 additions and 0 deletions

View File

@@ -1331,6 +1331,27 @@ void GreasePencil::remove_drawing(const int index_to_remove)
shrink_array<GreasePencilDrawingBase *>(&this->drawing_array, &this->drawing_array_num, 1);
}
blender::bke::greasepencil::Drawing *GreasePencil::get_editable_drawing_at(
const blender::bke::greasepencil::Layer *layer, const int frame_number) const
{
if (layer == nullptr || !layer->is_editable()) {
return nullptr;
}
const int drawing_index = layer->drawing_index_at(frame_number);
if (drawing_index == -1) {
/* No drawing found. */
return nullptr;
}
GreasePencilDrawingBase *drawing_base = this->drawings()[drawing_index];
if (drawing_base->type != GP_DRAWING) {
/* Drawing references are not editable. */
return nullptr;
}
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_base);
return &drawing->wrap();
}
enum ForeachDrawingMode {
VISIBLE,
EDITABLE,

View File

@@ -494,6 +494,13 @@ typedef struct GreasePencil {
void remove_drawing(int index);
/**
* Returns an editable drawing on \a layer at frame \a frame_number or `nullptr` if no such
* drawing exists.
*/
blender::bke::greasepencil::Drawing *get_editable_drawing_at(
const blender::bke::greasepencil::Layer *layer, int frame_number) const;
void foreach_visible_drawing(
int frame, blender::FunctionRef<void(int, blender::bke::greasepencil::Drawing &)> function);
void foreach_editable_drawing(