diff options
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 20 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_intern.h | 39 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_select.c | 18 |
3 files changed, 40 insertions, 37 deletions
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index cb735b69ec2..383b4335f3b 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -2883,7 +2883,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) // TODO: For deforming geometry workflow, create new frames? /* Go through each editable + selected stroke, adjusting each of its points one by one... */ - GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) + GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) { if (gps->flag & GP_STROKE_SELECT) { bGPDspoint *pt; @@ -2892,7 +2892,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) /* Compute inverse matrix for unapplying parenting once instead of doing per-point */ /* TODO: add this bit to the iteration macro? */ - invert_m4_m4(inverse_diff_mat, diff_mat); + invert_m4_m4(inverse_diff_mat, gpstroke_iter.diff_mat); /* Adjust each point */ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { @@ -2904,7 +2904,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) * artifacts in the final points. */ bGPDspoint pt2; - gp_point_to_parent_space(pt, diff_mat, &pt2); + gp_point_to_parent_space(pt, gpstroke_iter.diff_mat, &pt2); gp_point_to_xy_fl(&gsc, gps, &pt2, &xy[0], &xy[1]); /* Project stroke in the axis locked */ @@ -2953,7 +2953,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) } } } - GP_EDITABLE_STROKES_END; + GP_EDITABLE_STROKES_END(gpstroke_iter); DEG_id_tag_update(&gpd->id, OB_RECALC_OB | OB_RECALC_DATA); WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); @@ -3028,7 +3028,7 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* Go through each editable + selected stroke */ - GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) + GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) { if (gps->flag & GP_STROKE_SELECT) { /* loop as many times as cuts */ @@ -3126,7 +3126,7 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op) } } } - GP_EDITABLE_STROKES_END; + GP_EDITABLE_STROKES_END(gpstroke_iter); /* notifiers */ DEG_id_tag_update(&gpd->id, OB_RECALC_OB | OB_RECALC_DATA); @@ -3169,14 +3169,14 @@ static int gp_stroke_simplify_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* Go through each editable + selected stroke */ - GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) + GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) { if (gps->flag & GP_STROKE_SELECT) { /* simplify stroke using Ramer-Douglas-Peucker algorithm */ BKE_gpencil_simplify_stroke(gps, factor); } } - GP_EDITABLE_STROKES_END; + GP_EDITABLE_STROKES_END(gpstroke_iter); /* notifiers */ DEG_id_tag_update(&gpd->id, OB_RECALC_OB | OB_RECALC_DATA); @@ -3218,7 +3218,7 @@ static int gp_stroke_simplify_fixed_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* Go through each editable + selected stroke */ - GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) + GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) { if (gps->flag & GP_STROKE_SELECT) { for (int i = 0; i < steps; i++) { @@ -3226,7 +3226,7 @@ static int gp_stroke_simplify_fixed_exec(bContext *C, wmOperator *op) } } } - GP_EDITABLE_STROKES_END; + GP_EDITABLE_STROKES_END(gpstroke_iter); /* notifiers */ DEG_id_tag_update(&gpd->id, OB_RECALC_OB | OB_RECALC_DATA); diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h index a17591b87cc..d94b5d49add 100644 --- a/source/blender/editors/gpencil/gpencil_intern.h +++ b/source/blender/editors/gpencil/gpencil_intern.h @@ -474,6 +474,10 @@ typedef enum ACTCONT_TYPES { /* ****************************************************** */ /* Stroke Iteration Utilities */ +struct GP_EditableStrokes_Iter { + float diff_mat[4][4]; +}; + /** * Iterate over all editable strokes in the current context, * stopping on each usable layer + stroke pair (i.e. gpl and gps) @@ -484,37 +488,36 @@ typedef enum ACTCONT_TYPES { * \param gps The identifier to use for current stroke being processed. * Choose a suitable value to avoid name clashes. */ -#define GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) \ +#define GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) \ { \ + struct GP_EditableStrokes_Iter gpstroke_iter = {0}; \ Depsgraph *depsgraph_ = CTX_data_depsgraph(C); \ - Object *obact_ = CTX_data_active_object(C); \ - bGPdata *gpd_ = CTX_data_gpencil_data(C); \ - const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd_); \ - CTX_DATA_BEGIN(C, bGPDlayer*, gpl, editable_gpencil_layers) \ + Object *obact_ = CTX_data_active_object(C); \ + bGPdata *gpd_ = CTX_data_gpencil_data(C); \ + const bool is_multiedit_ = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd_); \ + CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers) \ { \ - bGPDframe *init_gpf = gpl->actframe; \ - if (is_multiedit) { \ - init_gpf = gpl->frames.first; \ - } \ - for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { \ - if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { \ - /* calculate difference matrix */ \ - float diff_mat[4][4]; \ - ED_gpencil_parent_location(depsgraph_, obact_, gpd_, gpl, diff_mat); \ + bGPDframe *init_gpf_ = gpl->actframe; \ + if (is_multiedit_) { \ + init_gpf_ = gpl->frames.first; \ + } \ + for (bGPDframe *gpf_ = init_gpf_; gpf_; gpf_ = gpf_->next) { \ + if ((gpf_ == gpl->actframe) || ((gpf_->flag & GP_FRAME_SELECT) && is_multiedit_)) { \ + ED_gpencil_parent_location(depsgraph_, obact_, gpd_, gpl, gpstroke_iter.diff_mat); \ /* loop over strokes */ \ - for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { \ + for (bGPDstroke *gps = gpf_->strokes.first; gps; gps = gps->next) { \ /* skip strokes that are invalid for current view */ \ if (ED_gpencil_stroke_can_use(C, gps) == false) \ continue; \ /* check if the color is editable */ \ - if (ED_gpencil_stroke_color_use(obact_, gpl, gps) == false) \ + if (ED_gpencil_stroke_color_use(obact_, gpl, gps) == false) \ continue; \ /* ... Do Stuff With Strokes ... */ -#define GP_EDITABLE_STROKES_END \ +#define GP_EDITABLE_STROKES_END(gpstroke_iter) \ } \ } \ - if (!is_multiedit) { \ + if (!is_multiedit_) { \ break; \ } \ } \ diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index c2a5c5cfc38..815f420f532 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -1001,12 +1001,12 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op) /* find visible strokes, and select if hit */ - GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) + GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) { changed |= gp_stroke_do_circle_sel( - gps, &gsc, mx, my, radius, select, &rect, diff_mat, selectmode); + gps, &gsc, mx, my, radius, select, &rect, gpstroke_iter.diff_mat, selectmode); } - GP_EDITABLE_STROKES_END; + GP_EDITABLE_STROKES_END(gpstroke_iter); /* updates */ if (changed) { @@ -1099,7 +1099,7 @@ static int gpencil_generic_select_exec( } /* select/deselect points */ - GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) + GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) { bGPDspoint *pt; @@ -1107,7 +1107,7 @@ static int gpencil_generic_select_exec( bool hit = false; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { /* convert point coords to screenspace */ - const bool is_inside = is_inside_fn(gps, pt, &gsc, diff_mat, user_data); + const bool is_inside = is_inside_fn(gps, pt, &gsc, gpstroke_iter.diff_mat, user_data); if (strokemode == false) { const bool is_select = (pt->flag & GP_SPOINT_SELECT) != 0; @@ -1146,7 +1146,7 @@ static int gpencil_generic_select_exec( /* Ensure that stroke selection is in sync with its points */ BKE_gpencil_stroke_sync_selection(gps); } - GP_EDITABLE_STROKES_END; + GP_EDITABLE_STROKES_END(gpstroke_iter); /* if paint mode,delete selected points */ if (gpd->flag & GP_DATA_STROKE_PAINTMODE) { @@ -1341,7 +1341,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) /* First Pass: Find stroke point which gets hit */ /* XXX: maybe we should go from the top of the stack down instead... */ - GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) + GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) { bGPDspoint *pt; int i; @@ -1351,7 +1351,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) int xy[2]; bGPDspoint pt2; - gp_point_to_parent_space(pt, diff_mat, &pt2); + gp_point_to_parent_space(pt, gpstroke_iter.diff_mat, &pt2); gp_point_to_xy(&gsc, gps, &pt2, &xy[0], &xy[1]); /* do boundbox check first */ @@ -1370,7 +1370,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) } } } - GP_EDITABLE_STROKES_END; + GP_EDITABLE_STROKES_END(gpstroke_iter); /* Abort if nothing hit... */ if (ELEM(NULL, hit_stroke, hit_point)) { |