Fix T102163: GPencil:Set start point Operator make stroke deleted
There were two problems: * The stroke was deleted if the last point was selected. Now the stroke is flipped because is faster. * If the second point was selected, the first point was removed because the internal api, removed one point strokes by default. This was done becaus ethe tools that used this API did not need one point strokes as result. Now this optional and keep one point strokes.
This commit is contained in:
parent
77749eff87
commit
da365bc2ad
Notes:
blender-bot
2023-02-13 14:08:40 +01:00
Referenced by issue #102163, GPencil: Set start point Operator make stroke deleted
|
@ -332,8 +332,12 @@ bool BKE_gpencil_stroke_stretch(struct bGPDstroke *gps,
|
|||
* \param gps: Target stroke.
|
||||
* \param index_from: the index of the first point to be used in the trimmed result.
|
||||
* \param index_to: the index of the last point to be used in the trimmed result.
|
||||
* \param keep_point: Keep strokes with one point. False remove the single points strokes
|
||||
*/
|
||||
bool BKE_gpencil_stroke_trim_points(struct bGPDstroke *gps, int index_from, int index_to);
|
||||
bool BKE_gpencil_stroke_trim_points(struct bGPDstroke *gps,
|
||||
int index_from,
|
||||
int index_to,
|
||||
const bool keep_point);
|
||||
/**
|
||||
* Split the given stroke into several new strokes, partitioning
|
||||
* it based on whether the stroke points have a particular flag
|
||||
|
|
|
@ -789,7 +789,10 @@ bool BKE_gpencil_stroke_stretch(bGPDstroke *gps,
|
|||
/** \name Stroke Trim
|
||||
* \{ */
|
||||
|
||||
bool BKE_gpencil_stroke_trim_points(bGPDstroke *gps, const int index_from, const int index_to)
|
||||
bool BKE_gpencil_stroke_trim_points(bGPDstroke *gps,
|
||||
const int index_from,
|
||||
const int index_to,
|
||||
const bool keep_point)
|
||||
{
|
||||
bGPDspoint *pt = gps->points, *new_pt;
|
||||
MDeformVert *dv, *new_dv;
|
||||
|
@ -800,7 +803,7 @@ bool BKE_gpencil_stroke_trim_points(bGPDstroke *gps, const int index_from, const
|
|||
return false;
|
||||
}
|
||||
|
||||
if (new_count == 1) {
|
||||
if ((!keep_point) && (new_count == 1)) {
|
||||
if (gps->dvert) {
|
||||
BKE_gpencil_free_stroke_weights(gps);
|
||||
MEM_freeN(gps->dvert);
|
||||
|
@ -894,7 +897,7 @@ bool BKE_gpencil_stroke_split(bGPdata *gpd,
|
|||
/* Trim the original stroke into a shorter one.
|
||||
* Keep the end point. */
|
||||
|
||||
BKE_gpencil_stroke_trim_points(gps, 0, old_count);
|
||||
BKE_gpencil_stroke_trim_points(gps, 0, old_count, false);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
return true;
|
||||
}
|
||||
|
@ -917,7 +920,7 @@ bool BKE_gpencil_stroke_shrink(bGPDstroke *gps, const float dist, const short mo
|
|||
if (gps->totpoints == 1) {
|
||||
second_last = &pt[1];
|
||||
if (len_v3v3(&second_last->x, &pt->x) < dist) {
|
||||
BKE_gpencil_stroke_trim_points(gps, 0, 0);
|
||||
BKE_gpencil_stroke_trim_points(gps, 0, 0, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -969,7 +972,7 @@ bool BKE_gpencil_stroke_shrink(bGPDstroke *gps, const float dist, const short mo
|
|||
index_start = index_end = 0; /* no length left to cut */
|
||||
}
|
||||
|
||||
BKE_gpencil_stroke_trim_points(gps, index_start, index_end);
|
||||
BKE_gpencil_stroke_trim_points(gps, index_start, index_end, false);
|
||||
|
||||
if (gps->totpoints == 0) {
|
||||
return false;
|
||||
|
@ -3562,8 +3565,8 @@ void BKE_gpencil_stroke_start_set(bGPDstroke *gps, int start_idx)
|
|||
}
|
||||
|
||||
bGPDstroke *gps_b = BKE_gpencil_stroke_duplicate(gps, true, false);
|
||||
BKE_gpencil_stroke_trim_points(gps_b, 0, start_idx - 1);
|
||||
BKE_gpencil_stroke_trim_points(gps, start_idx, gps->totpoints - 1);
|
||||
BKE_gpencil_stroke_trim_points(gps_b, 0, start_idx - 1, true);
|
||||
BKE_gpencil_stroke_trim_points(gps, start_idx, gps->totpoints - 1, true);
|
||||
|
||||
/* Join both strokes. */
|
||||
BKE_gpencil_stroke_join(gps, gps_b, false, false, false, false);
|
||||
|
|
|
@ -3848,7 +3848,12 @@ static int gpencil_stroke_start_set_exec(bContext *C, wmOperator *op)
|
|||
for (int i = 0; i < gps->totpoints; i++) {
|
||||
pt = &gps->points[i];
|
||||
if (pt->flag & GP_SPOINT_SELECT) {
|
||||
BKE_gpencil_stroke_start_set(gps, i);
|
||||
if (i == gps->totpoints - 1) {
|
||||
BKE_gpencil_stroke_flip(gps);
|
||||
}
|
||||
else {
|
||||
BKE_gpencil_stroke_start_set(gps, i);
|
||||
}
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
changed = true;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue