WIP: GPv3: active_layer operator port #115603

Closed
Clément Busschaert wants to merge 5 commits from SmugRainbowPony/blender:gp_active_layer into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
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,27 @@ 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 obd.layers:
nlop = layout.operator("grease_pencil.layer_add", text="New Layer", icon='ADD')
nlop.new_layer_name = "New Layer"
layout.separator()
tot_layers = len(obd.layers)
i = tot_layers - 1
while i >= 0:
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
i -= 1
class GPENCIL_MT_material_active(Menu):
bl_label = "Change Active Material"
@ -917,6 +938,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,44 @@ 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");
BLI_assert(layer_index >= 0 && layer_index < grease_pencil.layers().size());
const Layer &layer = *grease_pencil.layers()[layer_index];
if (grease_pencil.active_layer == &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 +290,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);
}