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.,
This commit is contained in:
Antonio Vazquez 2020-10-22 17:35:48 +02:00
parent 90eab4a25d
commit 2985a745bb
Notes: blender-bot 2023-02-13 22:37:44 +01:00
Referenced by issue #81234, GPencil: Add parameter to Cutter tool to set cap Flat
2 changed files with 24 additions and 2 deletions

View File

@ -1814,6 +1814,11 @@ class _defs_gpencil_paint:
@ToolDef.from_fn
def cutter():
def draw_settings(context, layout, tool):
props = tool.operator_properties("gpencil.stroke_cutter")
row = layout.row()
row.use_property_split = False
row.prop(props, "flat_caps")
return dict(
idname="builtin.cutter",
label="Cutter",
@ -1821,6 +1826,7 @@ class _defs_gpencil_paint:
cursor='KNIFE',
widget=None,
keymap=(),
draw_settings=draw_settings,
)
@ToolDef.from_fn

View File

@ -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)