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:
committed by
Falk David
parent
6023a6a423
commit
671f428ead
@@ -4575,6 +4575,9 @@ def km_grease_pencil_paint(_params):
|
|||||||
{"properties": [("mode", 'INVERT')]}),
|
{"properties": [("mode", 'INVERT')]}),
|
||||||
("grease_pencil.brush_stroke", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True},
|
("grease_pencil.brush_stroke", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True},
|
||||||
{"properties": [("mode", 'SMOOTH')]}),
|
{"properties": [("mode", 'SMOOTH')]}),
|
||||||
|
|
||||||
|
# Active layer
|
||||||
|
op_menu("GREASE_PENCIL_MT_layer_active", {"type": 'Y', "value": 'PRESS'}),
|
||||||
])
|
])
|
||||||
|
|
||||||
return keymap
|
return keymap
|
||||||
@@ -4623,6 +4626,9 @@ def km_grease_pencil_edit(params):
|
|||||||
("grease_pencil.cyclical_set", {"type": 'C', "value": 'PRESS',
|
("grease_pencil.cyclical_set", {"type": 'C', "value": 'PRESS',
|
||||||
"alt": True}, {"properties": [("type", "TOGGLE")]}),
|
"alt": True}, {"properties": [("type", "TOGGLE")]}),
|
||||||
|
|
||||||
|
# Active layer
|
||||||
|
op_menu("GREASE_PENCIL_MT_layer_active", {"type": 'Y', "value": 'PRESS'}),
|
||||||
|
|
||||||
# Context menu
|
# Context menu
|
||||||
*_template_items_context_menu("VIEW3D_MT_greasepencil_edit_context_menu", params.context_menu_event),
|
*_template_items_context_menu("VIEW3D_MT_greasepencil_edit_context_menu", params.context_menu_event),
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -273,6 +273,28 @@ class GPENCIL_MT_layer_active(Menu):
|
|||||||
layout.operator("gpencil.layer_active", text=gpl.info, icon=icon).layer = i
|
layout.operator("gpencil.layer_active", text=gpl.info, icon=icon).layer = i
|
||||||
i -= 1
|
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):
|
class GPENCIL_MT_material_active(Menu):
|
||||||
bl_label = "Change Active Material"
|
bl_label = "Change Active Material"
|
||||||
@@ -917,6 +939,8 @@ classes = (
|
|||||||
GPENCIL_UL_layer,
|
GPENCIL_UL_layer,
|
||||||
GPENCIL_UL_masks,
|
GPENCIL_UL_masks,
|
||||||
|
|
||||||
|
GREASE_PENCIL_MT_layer_active,
|
||||||
|
|
||||||
GreasePencilFlipTintColors,
|
GreasePencilFlipTintColors,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2166,7 +2166,9 @@ class VIEW3D_MT_paint_grease_pencil(Menu):
|
|||||||
bl_label = "Paint"
|
bl_label = "Paint"
|
||||||
|
|
||||||
def draw(self, _context):
|
def draw(self, _context):
|
||||||
pass
|
layout = self.layout
|
||||||
|
|
||||||
|
layout.menu("GREASE_PENCIL_MT_layer_active", text="Active Layer")
|
||||||
|
|
||||||
|
|
||||||
class VIEW3D_MT_paint_gpencil(Menu):
|
class VIEW3D_MT_paint_gpencil(Menu):
|
||||||
@@ -5811,6 +5813,10 @@ class VIEW3D_MT_edit_greasepencil(Menu):
|
|||||||
|
|
||||||
layout.separator()
|
layout.separator()
|
||||||
|
|
||||||
|
layout.menu("GREASE_PENCIL_MT_layer_active", text="Active Layer")
|
||||||
|
|
||||||
|
layout.separator()
|
||||||
|
|
||||||
layout.menu("VIEW3D_MT_edit_greasepencil_delete")
|
layout.menu("VIEW3D_MT_edit_greasepencil_delete")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -197,6 +197,43 @@ static void GREASE_PENCIL_OT_layer_reorder(wmOperatorType *ot)
|
|||||||
ot->srna, "location", prop_layer_reorder_location, LAYER_REORDER_ABOVE, "Location", "");
|
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)
|
static int grease_pencil_layer_group_add_exec(bContext *C, wmOperator *op)
|
||||||
{
|
{
|
||||||
using namespace blender::bke::greasepencil;
|
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_add);
|
||||||
WM_operatortype_append(GREASE_PENCIL_OT_layer_remove);
|
WM_operatortype_append(GREASE_PENCIL_OT_layer_remove);
|
||||||
WM_operatortype_append(GREASE_PENCIL_OT_layer_reorder);
|
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);
|
WM_operatortype_append(GREASE_PENCIL_OT_layer_group_add);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user