diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-04-13 12:27:10 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-04-13 12:30:43 +0300 |
commit | 890e533c7695927212a6164c0ca86ff7a314bf5f (patch) | |
tree | 911dfafe24573f685935eb30b5451c0c97d107a9 /source/blender/editors/sculpt_paint/paint_curve.c | |
parent | 176ed5bfe280ef2151f93c0940d54498aaf00d71 (diff) |
Fix adding to paint-curves from the first point
- add_index now works when selecting the first point.
- sliding now selects the correct handle.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_curve.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_curve.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c index 439c2a639bd..8c754d7adf3 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.c +++ b/source/blender/editors/sculpt_paint/paint_curve.c @@ -222,6 +222,28 @@ static int paintcurve_point_co_index(char sel) return i; } +static char paintcurve_point_side_index(const BezTriple *bezt, const bool is_first, const char fallback) +{ + /* when matching, guess based on endpoint side */ + if (BEZSELECTED(bezt)) { + if ((bezt->f1 & SELECT) == (bezt->f3 & SELECT)) { + return is_first ? SEL_F1 : SEL_F3; + } + else if (bezt->f1 & SELECT) { + return SEL_F1; + } + else if (bezt->f3 & SELECT) { + return SEL_F3; + } + else { + return fallback; + } + } + else { + return 0; + } +} + /******************* Operators *********************************/ static int paintcurve_new_exec(bContext *C, wmOperator *UNUSED(op)) @@ -295,10 +317,17 @@ static void paintcurve_point_add(bContext *C, wmOperator *op, const int loc[2]) for (i = 0; i < pc->tot_points; i++) { pcp[i].bez.f1 = pcp[i].bez.f2 = pcp[i].bez.f3 = 0; } - pcp[add_index].bez.f3 = SELECT; - pcp[add_index].bez.h2 = HD_ALIGN; - pc->add_index = add_index + 1; + BKE_paint_curve_clamp_endpoint_add_index(pc, add_index); + + if (pc->add_index != 0) { + pcp[add_index].bez.f3 = SELECT; + pcp[add_index].bez.h2 = HD_ALIGN; + } + else { + pcp[add_index].bez.f1 = SELECT; + pcp[add_index].bez.h1 = HD_ALIGN; + } WM_paint_cursor_tag_redraw(window, ar); } @@ -384,7 +413,7 @@ static int paintcurve_delete_point_exec(bContext *C, wmOperator *op) points_new[j] = pc->points[i]; if ((i + 1) == pc->add_index) { - pc->add_index = j + 1; + BKE_paint_curve_clamp_endpoint_add_index(pc, j); } j++; } @@ -469,7 +498,7 @@ static bool paintcurve_point_select(bContext *C, wmOperator *op, const int loc[2 pcp = paintcurve_point_get_closest(pc, loc_fl, false, PAINT_CURVE_SELECT_THRESHOLD, &selflag); if (pcp) { - pc->add_index = (pcp - pc->points) + 1; + BKE_paint_curve_clamp_endpoint_add_index(pc, pcp - pc->points); if (selflag == SEL_F2) { if (extend) @@ -599,9 +628,8 @@ static int paintcurve_slide_invoke(bContext *C, wmOperator *op, const wmEvent *e pcp = NULL; /* just find first selected point */ for (i = 0; i < pc->tot_points; i++) { - if (pc->points[i].bez.f1 || pc->points[i].bez.f2 || pc->points[i].bez.f3) { + if ((select = paintcurve_point_side_index(&pc->points[i].bez, i == 0, SEL_F3))) { pcp = &pc->points[i]; - select = SEL_F3; break; } } @@ -631,7 +659,7 @@ static int paintcurve_slide_invoke(bContext *C, wmOperator *op, const wmEvent *e /* only select the active point */ PAINT_CURVE_POINT_SELECT(pcp, psd->select); - pc->add_index = (pcp - pc->points) + 1; + BKE_paint_curve_clamp_endpoint_add_index(pc, pcp - pc->points); WM_event_add_modal_handler(C, op); WM_paint_cursor_tag_redraw(window, ar); |