GPv3: "Set Active Layer" operator and menu

Resolves #113915 .

Ports the `layer_active` operator to set the active layer from an index.
Adds the menu to set the active layer from a list.

Pull Request: https://projects.blender.org/blender/blender/pulls/115606
This commit is contained in:
Clément Busschaert
2023-11-30 16:10:06 +01:00
committed by Falk David
parent 6023a6a423
commit 671f428ead
4 changed files with 75 additions and 1 deletions

View File

@@ -4575,6 +4575,9 @@ def km_grease_pencil_paint(_params):
{"properties": [("mode", 'INVERT')]}),
("grease_pencil.brush_stroke", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True},
{"properties": [("mode", 'SMOOTH')]}),
# Active layer
op_menu("GREASE_PENCIL_MT_layer_active", {"type": 'Y', "value": 'PRESS'}),
])
return keymap
@@ -4623,6 +4626,9 @@ def km_grease_pencil_edit(params):
("grease_pencil.cyclical_set", {"type": 'C', "value": 'PRESS',
"alt": True}, {"properties": [("type", "TOGGLE")]}),
# Active layer
op_menu("GREASE_PENCIL_MT_layer_active", {"type": 'Y', "value": 'PRESS'}),
# Context menu
*_template_items_context_menu("VIEW3D_MT_greasepencil_edit_context_menu", params.context_menu_event),
])

View File

@@ -273,6 +273,28 @@ class GPENCIL_MT_layer_active(Menu):
layout.operator("gpencil.layer_active", text=gpl.info, icon=icon).layer = i
i -= 1
class GREASE_PENCIL_MT_layer_active(Menu):
bl_label = "Change Active Layer"
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
obd = context.active_object.data
if not obd.layers:
return
nlop = layout.operator("grease_pencil.layer_add", text="New Layer", icon='ADD')
nlop.new_layer_name = "Layer"
layout.separator()
for i in range(len(obd.layers) - 1, -1, -1):
layer = obd.layers[i]
if layer == obd.layers.active:
icon = 'GREASEPENCIL'
else:
icon = 'NONE'
layout.operator("grease_pencil.layer_active", text=layer.name, icon=icon).layer = i
class GPENCIL_MT_material_active(Menu):
bl_label = "Change Active Material"
@@ -917,6 +939,8 @@ classes = (
GPENCIL_UL_layer,
GPENCIL_UL_masks,
GREASE_PENCIL_MT_layer_active,
GreasePencilFlipTintColors,
)

View File

@@ -2166,7 +2166,9 @@ class VIEW3D_MT_paint_grease_pencil(Menu):
bl_label = "Paint"
def draw(self, _context):
pass
layout = self.layout
layout.menu("GREASE_PENCIL_MT_layer_active", text="Active Layer")
class VIEW3D_MT_paint_gpencil(Menu):
@@ -5811,6 +5813,10 @@ class VIEW3D_MT_edit_greasepencil(Menu):
layout.separator()
layout.menu("GREASE_PENCIL_MT_layer_active", text="Active Layer")
layout.separator()
layout.menu("VIEW3D_MT_edit_greasepencil_delete")

View File

@@ -197,6 +197,43 @@ static void GREASE_PENCIL_OT_layer_reorder(wmOperatorType *ot)
ot->srna, "location", prop_layer_reorder_location, LAYER_REORDER_ABOVE, "Location", "");
}
static int grease_pencil_layer_active_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 layer_index = RNA_int_get(op->ptr, "layer");
const Layer &layer = *grease_pencil.layers()[layer_index];
if (grease_pencil.is_layer_active(&layer)) {
return OPERATOR_CANCELLED;
}
grease_pencil.set_active_layer(&layer);
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_SELECTED, &grease_pencil);
return OPERATOR_FINISHED;
}
static void GREASE_PENCIL_OT_layer_active(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Set Active Layer";
ot->idname = "GREASE_PENCIL_OT_layer_active";
ot->description = "Set the active Grease Pencil layer";
/* callbacks */
ot->exec = grease_pencil_layer_active_exec;
ot->poll = active_grease_pencil_poll;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
PropertyRNA *prop = RNA_def_int(
ot->srna, "layer", 0, 0, INT_MAX, "Grease Pencil Layer", "", 0, INT_MAX);
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
static int grease_pencil_layer_group_add_exec(bContext *C, wmOperator *op)
{
using namespace blender::bke::greasepencil;
@@ -252,6 +289,7 @@ void ED_operatortypes_grease_pencil_layers()
WM_operatortype_append(GREASE_PENCIL_OT_layer_add);
WM_operatortype_append(GREASE_PENCIL_OT_layer_remove);
WM_operatortype_append(GREASE_PENCIL_OT_layer_reorder);
WM_operatortype_append(GREASE_PENCIL_OT_layer_active);
WM_operatortype_append(GREASE_PENCIL_OT_layer_group_add);
}