GPv3: Add wrapper class for DrawingReference

Adds a simple C++ wrapper so we don't have to use
`MEM_dupallocN`, `MEM_freeN` etc.
This commit is contained in:
Falk David
2023-10-18 11:24:51 +02:00
parent b3460a6b2c
commit 74facf9841
3 changed files with 43 additions and 3 deletions

View File

@@ -110,6 +110,13 @@ class Drawing : public ::GreasePencilDrawing {
bool has_users() const;
};
class DrawingReference : public ::GreasePencilDrawingReference {
public:
DrawingReference();
DrawingReference(const DrawingReference &other);
~DrawingReference();
};
class LayerGroup;
class Layer;
@@ -705,6 +712,16 @@ inline const blender::bke::greasepencil::Drawing &GreasePencilDrawing::wrap() co
return *reinterpret_cast<const blender::bke::greasepencil::Drawing *>(this);
}
inline blender::bke::greasepencil::DrawingReference &GreasePencilDrawingReference::wrap()
{
return *reinterpret_cast<blender::bke::greasepencil::DrawingReference *>(this);
}
inline const blender::bke::greasepencil::DrawingReference &GreasePencilDrawingReference::wrap()
const
{
return *reinterpret_cast<const blender::bke::greasepencil::DrawingReference *>(this);
}
inline GreasePencilFrame GreasePencilFrame::null()
{
return GreasePencilFrame{-1, 0, 0};

View File

@@ -113,7 +113,7 @@ static void grease_pencil_copy_data(Main * /*bmain*/,
const GreasePencilDrawingReference *src_drawing_reference =
reinterpret_cast<const GreasePencilDrawingReference *>(src_drawing_base);
grease_pencil_dst->drawing_array[i] = reinterpret_cast<GreasePencilDrawingBase *>(
MEM_dupallocN(src_drawing_reference));
MEM_new<bke::greasepencil::DrawingReference>(__func__, src_drawing_reference->wrap()));
break;
}
}
@@ -432,6 +432,24 @@ void Drawing::tag_topology_changed()
this->tag_positions_changed();
}
DrawingReference::DrawingReference()
{
this->base.type = GP_DRAWING_REFERENCE;
this->base.flag = 0;
this->id_reference = nullptr;
}
DrawingReference::DrawingReference(const DrawingReference &other)
{
this->base.type = GP_DRAWING_REFERENCE;
this->base.flag = other.base.flag;
this->id_reference = other.id_reference;
}
DrawingReference::~DrawingReference() {}
const Drawing *get_eval_grease_pencil_layer_drawing(const GreasePencil &grease_pencil,
const int layer_index)
{
@@ -1643,7 +1661,7 @@ static void remove_drawings_unchecked(GreasePencil &grease_pencil,
case GP_DRAWING_REFERENCE: {
GreasePencilDrawingReference *drawing_reference_to_remove =
reinterpret_cast<GreasePencilDrawingReference *>(drawing_base_to_remove);
MEM_freeN(drawing_reference_to_remove);
MEM_delete(&drawing_reference_to_remove->wrap());
break;
}
}
@@ -2518,7 +2536,7 @@ static void free_drawing_array(GreasePencil &grease_pencil)
case GP_DRAWING_REFERENCE: {
GreasePencilDrawingReference *drawing_reference =
reinterpret_cast<GreasePencilDrawingReference *>(drawing_base);
MEM_freeN(drawing_reference);
MEM_delete(&drawing_reference->wrap());
break;
}
}

View File

@@ -28,6 +28,7 @@ class GreasePencilDrawingRuntime;
namespace greasepencil {
class DrawingRuntime;
class Drawing;
class DrawingReference;
class TreeNode;
class Layer;
class LayerRuntime;
@@ -120,6 +121,10 @@ typedef struct GreasePencilDrawingReference {
* See the note in `GreasePencilLayer->frames()` for a detailed explanation of this.
*/
struct GreasePencil *id_reference;
#ifdef __cplusplus
blender::bke::greasepencil::DrawingReference &wrap();
const blender::bke::greasepencil::DrawingReference &wrap() const;
#endif
} GreasePencilDrawingReference;
/**