diff --git a/scripts/presets/keyconfig/keymap_data/blender_default.py b/scripts/presets/keyconfig/keymap_data/blender_default.py index 8271499c6d9..a9e3881406d 100644 --- a/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -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), ]) diff --git a/scripts/startup/bl_ui/properties_grease_pencil_common.py b/scripts/startup/bl_ui/properties_grease_pencil_common.py index a5df0d0f1e8..7b9d2821600 100644 --- a/scripts/startup/bl_ui/properties_grease_pencil_common.py +++ b/scripts/startup/bl_ui/properties_grease_pencil_common.py @@ -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, ) diff --git a/scripts/startup/bl_ui/space_view3d.py b/scripts/startup/bl_ui/space_view3d.py index 4ff9c3094fe..df90af1f5e4 100644 --- a/scripts/startup/bl_ui/space_view3d.py +++ b/scripts/startup/bl_ui/space_view3d.py @@ -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") diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc index e94aa5ca2df..c3d7b19d93a 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc @@ -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(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); }