From 2985a745bb016c43e837b908fbd873e2daff3440 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Thu, 22 Oct 2020 17:35:48 +0200 Subject: GPencil: Add new parameter to set caps in Cutter The new parameter allows to define if after cutting the stroke the cap of the cut side will be set as flat. Before, the cap shape of the cut side always was equal to the original stroke, and in some situations, the rounded cap was visible. Note: If the angle of the join is very extreme, it's still possible to view some sections of the cut stroke., --- source/blender/editors/gpencil/gpencil_edit.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index d54bdf552eb..7d79e748f75 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -4678,7 +4678,9 @@ typedef bool (*GPencilTestFn)(bGPDstroke *gps, const float diff_mat[4][4], void *user_data); -static void gpencil_cutter_dissolve(bGPDlayer *hit_layer, bGPDstroke *hit_stroke) +static void gpencil_cutter_dissolve(bGPDlayer *hit_layer, + bGPDstroke *hit_stroke, + const bool flat_caps) { bGPDspoint *pt = NULL; bGPDspoint *pt1 = NULL; @@ -4722,6 +4724,17 @@ static void gpencil_cutter_dissolve(bGPDlayer *hit_layer, bGPDstroke *hit_stroke pt->flag &= ~GP_SPOINT_TAG; } } + /* If flat caps mode check extremes. */ + if (flat_caps) { + if (hit_stroke->points[0].flag & GP_SPOINT_TAG) { + hit_stroke->caps[0] = GP_STROKE_CAP_FLAT; + } + + if (hit_stroke->points[hit_stroke->totpoints - 1].flag & GP_SPOINT_TAG) { + hit_stroke->caps[1] = GP_STROKE_CAP_FLAT; + } + } + gpencil_stroke_delete_tagged_points( hit_layer->actframe, hit_stroke, gpsn, GP_SPOINT_TAG, false, 1); } @@ -4736,6 +4749,7 @@ static int gpencil_cutter_lasso_select(bContext *C, ScrArea *area = CTX_wm_area(C); ToolSettings *ts = CTX_data_tool_settings(C); const float scale = ts->gp_sculpt.isect_threshold; + const bool flat_caps = RNA_boolean_get(op->ptr, "flat_caps"); bGPDspoint *pt; GP_SpaceConversion gsc = {NULL}; @@ -4810,7 +4824,7 @@ static int gpencil_cutter_lasso_select(bContext *C, } LISTBASE_FOREACH_MUTABLE (bGPDstroke *, gps, &gpf->strokes) { if (gps->flag & GP_STROKE_SELECT) { - gpencil_cutter_dissolve(gpl, gps); + gpencil_cutter_dissolve(gpl, gps, flat_caps); } } } @@ -4884,6 +4898,8 @@ void GPENCIL_OT_stroke_cutter(wmOperatorType *ot) /* properties */ WM_operator_properties_gesture_lasso(ot); + + RNA_def_boolean(ot->srna, "flat_caps", 0, "Flat Caps", ""); } bool ED_object_gpencil_exit(struct Main *bmain, Object *ob) -- cgit v1.2.3