[Bf-blender-cvs] [944d2f1b81b] soc-2020-greasepencil-curve: GPencil: Add curve iteration macro
Falk David
noreply at git.blender.org
Wed Jun 17 23:02:18 CEST 2020
Commit: 944d2f1b81b34b5340b1c671152d986ff2ac1a8a
Author: Falk David
Date: Wed Jun 17 22:59:49 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rB944d2f1b81b34b5340b1c671152d986ff2ac1a8a
GPencil: Add curve iteration macro
===================================================================
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_select.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/makesdna/DNA_gpencil_types.h
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index dec06e68909..3bc7a39c1d9 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -684,6 +684,55 @@ struct GP_EditableStrokes_Iter {
} \
(void)0
+/**
+ * Iterate over all editable editcurves in the current context,
+ * stopping on each usable layer + stroke + curve pair (i.e. gpl, gps and gpc)
+ * to perform some operations on the curve.
+ *
+ * \param gpl: The identifier to use for the layer of the stroke being processed.
+ * Choose a suitable value to avoid name clashes.
+ * \param gps: The identifier to use for current stroke being processed.
+ * Choose a suitable value to avoid name clashes.
+ * \param gpc: The identifier to use for current editcurve being processed.
+ * Choose a suitable value to avoid name clashes.
+ */
+#define GP_EDITABLE_CURVES_BEGIN(gpstroke_iter, C, gpl, gps, gpc) \
+ { \
+ struct GP_EditableStrokes_Iter gpstroke_iter = {{{0}}}; \
+ Depsgraph *depsgraph_ = CTX_data_ensure_evaluated_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) { \
+ bGPDframe *init_gpf_ = (is_multiedit_) ? gpl->frames.first : gpl->actframe; \
+ for (bGPDframe *gpf_ = init_gpf_; gpf_; gpf_ = gpf_->next) { \
+ if ((gpf_ == gpl->actframe) || ((gpf_->flag & GP_FRAME_SELECT) && is_multiedit_)) { \
+ BKE_gpencil_parent_matrix_get(depsgraph_, obact_, gpl, gpstroke_iter.diff_mat); \
+ invert_m4_m4(gpstroke_iter.inverse_diff_mat, gpstroke_iter.diff_mat); \
+ /* loop over strokes */ \
+ bGPDstroke *gpsn_; \
+ for (bGPDstroke *gps = gpf_->strokes.first; gps; gps = gpsn_) { \
+ gpsn_ = gps->next; \
+ /* skip strokes that are invalid for current view */ \
+ if (ED_gpencil_stroke_can_use(C, gps) == false) \
+ continue; \
+ if (gps->editcurve == NULL) \
+ continue; \
+ bGPDcurve *gpc = gps->editcurve;\
+ /* ... Do Stuff With Strokes ... */
+
+#define GP_EDITABLE_CURVES_END(gpstroke_iter) \
+ } \
+ } \
+ if (!is_multiedit_) { \
+ break; \
+ } \
+ } \
+ } \
+ CTX_DATA_END; \
+ } \
+ (void)0
+
/**
* Iterate over all editable strokes using evaluated data in the current context,
* stopping on each usable layer + stroke pair (i.e. gpl and gps)
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 3e3fffe55b3..b104cf5f0e4 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -272,16 +272,18 @@ static int gpencil_select_linked_exec(bContext *C, wmOperator *op)
}
if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
- CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
- if (gps->editcurve != NULL && gps->flag & GP_STROKE_SELECT) {
- bGPDcurve *gpc = gps->editcurve;
+ GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
+ {
+ if (gpc->flag & GP_CURVE_SELECT) {
for (int i = 0; i < gpc->tot_curve_points; i++) {
- BezTriple *bezt = &gpc->curve_points[i].bezt;
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ BezTriple *bezt = &gpc_pt->bezt;
+ gpc_pt->flag |= GP_CURVE_POINT_SELECT;
BEZT_SEL_ALL(bezt);
}
}
}
- CTX_DATA_END;
+ GP_EDITABLE_CURVES_END(gps_iter);
}
else {
/* select all points in selected strokes */
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 52274520176..6899d904dfd 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2616,26 +2616,27 @@ void ED_gpencil_select_curve_toggle_all(bContext *C, int action, float error_thr
/* if toggle, check if we need to select or deselect */
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
- GP_EDITABLE_STROKES_BEGIN (gps_iter, C, gpl, gps) {
- if (gps->editcurve != NULL && gps->flag & GP_STROKE_SELECT) {
+ GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
+ {
+ if (gpc->flag & GP_CURVE_SELECT) {
action = SEL_DESELECT;
}
}
- GP_EDITABLE_STROKES_END(gps_iter);
+ GP_EDITABLE_CURVES_END(gps_iter);
}
if (action == SEL_DESELECT) {
- GP_EDITABLE_STROKES_BEGIN (gps_iter, C, gpl, gps) {
- if (gps->editcurve != NULL) {
- bGPDcurve *gpc = gps->editcurve;
- for (int i = 0; i < gpc->tot_curve_points; i++) {
- BezTriple *bezt = &gpc->curve_points[i].bezt;
- BEZT_DESEL_ALL(bezt);
- }
- gps->flag &= ~GP_STROKE_SELECT;
+ GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
+ {
+ for (int i = 0; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ BezTriple *bezt = &gpc_pt->bezt;
+ gpc_pt->flag |= GP_CURVE_POINT_SELECT;
+ BEZT_DESEL_ALL(bezt);
}
+ gpc->flag &= ~GP_CURVE_SELECT;
}
- GP_EDITABLE_STROKES_END(gps_iter);
+ GP_EDITABLE_CURVES_END(gps_iter);
}
else {
CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
@@ -2653,28 +2654,31 @@ void ED_gpencil_select_curve_toggle_all(bContext *C, int action, float error_thr
bGPDcurve *gpc = gps->editcurve;
for (int i = 0; i < gpc->tot_curve_points; i++) {
- BezTriple *bezt = &gpc->curve_points[i].bezt;
+ bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+ BezTriple *bezt = &gpc_pt->bezt;
switch (action) {
case SEL_SELECT:
+ gpc_pt->flag |= GP_CURVE_POINT_SELECT;
BEZT_SEL_ALL(bezt);
break;
case SEL_INVERT:
+ gpc_pt->flag ^= GP_CURVE_POINT_SELECT;
BEZT_SEL_INVERT(bezt);
break;
default:
break;
}
- if (BEZT_ISSEL_ANY(bezt)) {
+ if (gpc_pt->flag & GP_CURVE_POINT_SELECT) {
selected = true;
}
}
if (selected) {
- gps->flag |= GP_STROKE_SELECT;
+ gpc->flag |= GP_CURVE_SELECT;
}
else {
- gps->flag &= ~GP_STROKE_SELECT;
+ gpc->flag &= ~GP_CURVE_SELECT;
}
}
CTX_DATA_END;
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index e6800cad8f1..4c578b0376f 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -223,6 +223,8 @@ typedef struct bGPDcurve {
typedef enum bGPDcurve_Flag {
/* Curve requires recalc of the Bezier editing data. */
GP_CURVE_RECALC_GEOMETRY = (1 << 0),
+ /* Curve is selected */
+ GP_CURVE_SELECT = (1 << 1),
} bGPDcurve_Flag;
/* ***************************************** */
More information about the Bf-blender-cvs
mailing list