GPv3: Add operator to reorder the active layer
This operator will reorder the active layer (if there is one) to be above or below the target layer (specified by name). Pull Request: https://projects.blender.org/blender/blender/pulls/109369
This commit is contained in:
@@ -51,7 +51,6 @@ static int grease_pencil_layer_add_exec(bContext *C, wmOperator *op)
|
||||
|
||||
static void GREASE_PENCIL_OT_layer_add(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
/* identifiers */
|
||||
ot->name = "Add New Layer";
|
||||
ot->idname = "GREASE_PENCIL_OT_layer_add";
|
||||
@@ -63,7 +62,7 @@ static void GREASE_PENCIL_OT_layer_add(wmOperatorType *ot)
|
||||
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
prop = RNA_def_string(
|
||||
PropertyRNA *prop = RNA_def_string(
|
||||
ot->srna, "new_layer_name", "GP_Layer", INT16_MAX, "Name", "Name of the new layer");
|
||||
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
ot->prop = prop;
|
||||
@@ -101,6 +100,79 @@ static void GREASE_PENCIL_OT_layer_remove(wmOperatorType *ot)
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
static const EnumPropertyItem prop_layer_reorder_location[] = {
|
||||
{LAYER_REORDER_ABOVE, "ABOVE", 0, "Above", ""},
|
||||
{LAYER_REORDER_BELOW, "BELOW", 0, "Below", ""},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
static int grease_pencil_layer_reorder_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
Object *object = CTX_data_active_object(C);
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
|
||||
|
||||
int target_layer_name_length;
|
||||
char *target_layer_name = RNA_string_get_alloc(
|
||||
op->ptr, "target_layer_name", nullptr, 0, &target_layer_name_length);
|
||||
const int reorder_location = RNA_enum_get(op->ptr, "location");
|
||||
|
||||
if (!grease_pencil.has_active_layer()) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
Layer *target_layer = grease_pencil.find_layer_by_name(target_layer_name);
|
||||
if (!target_layer) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
Layer *active_layer = grease_pencil.get_active_layer_for_write();
|
||||
active_layer->parent_group().unlink_layer(active_layer);
|
||||
|
||||
switch (reorder_location) {
|
||||
case LAYER_REORDER_ABOVE: {
|
||||
/* Note: The layers are stored from bottom to top, so inserting above (visually), means
|
||||
* inserting the link after the target. */
|
||||
target_layer->parent_group().add_layer_after(active_layer, target_layer);
|
||||
break;
|
||||
}
|
||||
case LAYER_REORDER_BELOW: {
|
||||
/* Note: The layers are stored from bottom to top, so inserting below (visually), means
|
||||
* inserting the link before the target. */
|
||||
target_layer->parent_group().add_layer_before(active_layer, target_layer);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static void GREASE_PENCIL_OT_layer_reorder(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Reorder Layer";
|
||||
ot->idname = "GREASE_PENCIL_OT_layer_reorder";
|
||||
ot->description = "Reorder the active Grease Pencil layer";
|
||||
|
||||
/* callbacks */
|
||||
ot->exec = grease_pencil_layer_reorder_exec;
|
||||
ot->poll = active_grease_pencil_poll;
|
||||
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
PropertyRNA *prop = RNA_def_string(
|
||||
ot->srna, "target_layer_name", "GP_Layer", INT16_MAX, "Target Name", "Name of the target layer");
|
||||
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
|
||||
RNA_def_enum(
|
||||
ot->srna, "location", prop_layer_reorder_location, LAYER_REORDER_ABOVE, "Location", "");
|
||||
}
|
||||
|
||||
} // namespace blender::ed::greasepencil
|
||||
|
||||
void ED_operatortypes_grease_pencil_layers(void)
|
||||
@@ -108,4 +180,5 @@ void ED_operatortypes_grease_pencil_layers(void)
|
||||
using namespace blender::ed::greasepencil;
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_layer_add);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_layer_remove);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_layer_reorder);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,11 @@ struct wmKeyConfig;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
LAYER_REORDER_ABOVE,
|
||||
LAYER_REORDER_BELOW,
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name C Wrappers
|
||||
* \{ */
|
||||
|
||||
Reference in New Issue
Block a user