diff --git a/scripts/presets/keyconfig/keymap_data/blender_default.py b/scripts/presets/keyconfig/keymap_data/blender_default.py index e652fc1fb1a..dba98cb1d1f 100644 --- a/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -4508,6 +4508,8 @@ def km_grease_pencil_edit(params): items.extend([ *_template_items_select_actions(params, "grease_pencil.select_all"), + ("grease_pencil.select_more", {"type": 'NUMPAD_PLUS', "value": 'PRESS', "ctrl": True, "repeat": True}, None), + ("grease_pencil.select_less", {"type": 'NUMPAD_MINUS', "value": 'PRESS', "ctrl": True, "repeat": True}, None), ]) return keymap diff --git a/scripts/startup/bl_ui/space_view3d.py b/scripts/startup/bl_ui/space_view3d.py index e96c3ed2793..1d1b0f572a5 100644 --- a/scripts/startup/bl_ui/space_view3d.py +++ b/scripts/startup/bl_ui/space_view3d.py @@ -2030,6 +2030,9 @@ class VIEW3D_MT_select_edit_gpencil(Menu): layout.separator() + layout.operator("grease_pencil.select_more") + layout.operator("grease_pencil.select_less") + class VIEW3D_MT_select_paint_mask(Menu): bl_label = "Select" diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc index ce4f7dc1996..61634053e3b 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc @@ -76,6 +76,71 @@ static void GREASE_PENCIL_OT_select_all(wmOperatorType *ot) WM_operator_properties_select_all(ot); } +static int select_more_exec(bContext *C, wmOperator * /*op*/) +{ + Scene *scene = CTX_data_scene(C); + Object *object = CTX_data_active_object(C); + GreasePencil &grease_pencil = *static_cast(object->data); + + grease_pencil.foreach_editable_drawing( + scene->r.cfra, [](int /*drawing_index*/, GreasePencilDrawing &drawing) { + // TODO: Support different selection domains. + blender::ed::curves::select_adjacent(drawing.geometry.wrap(), false); + }); + + /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic + * attribute for now. */ + 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_select_more(wmOperatorType *ot) +{ + ot->name = "Select More"; + ot->idname = "GREASE_PENCIL_OT_select_more"; + ot->description = "Grow the selection by one point"; + + ot->exec = select_more_exec; + ot->poll = editable_grease_pencil_poll; + + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +static int select_less_exec(bContext *C, wmOperator * /*op*/) +{ + Scene *scene = CTX_data_scene(C); + Object *object = CTX_data_active_object(C); + GreasePencil &grease_pencil = *static_cast(object->data); + + grease_pencil.foreach_editable_drawing( + scene->r.cfra, [](int /*drawing_index*/, GreasePencilDrawing &drawing) { + // TODO: Support different selection domains. + blender::ed::curves::select_adjacent(drawing.geometry.wrap(), true); + }); + + /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic + * attribute for now. */ + 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_select_less(wmOperatorType *ot) +{ + ot->name = "Select Less"; + ot->idname = "GREASE_PENCIL_OT_select_less"; + ot->description = "Shrink the selection by one point"; + + ot->exec = select_less_exec; + ot->poll = editable_grease_pencil_poll; + + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + static void keymap_grease_pencil_editing(wmKeyConfig *keyconf) { wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Edit Mode", 0, 0); @@ -88,6 +153,8 @@ void ED_operatortypes_grease_pencil(void) { using namespace blender::ed::greasepencil; WM_operatortype_append(GREASE_PENCIL_OT_select_all); + WM_operatortype_append(GREASE_PENCIL_OT_select_more); + WM_operatortype_append(GREASE_PENCIL_OT_select_less); } void ED_keymap_grease_pencil(wmKeyConfig *keyconf)