[Bf-blender-cvs] [914efb8] GPencil_EditStrokes: Replaced inline GP stroke-looping logic with macro-based iterators
Joshua Leung
noreply at git.blender.org
Sun Sep 28 17:26:55 CEST 2014
Commit: 914efb853d4ae6cb64bf9cd8dd4b34fbf7df2308
Author: Joshua Leung
Date: Sun Sep 28 04:03:59 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rB914efb853d4ae6cb64bf9cd8dd4b34fbf7df2308
Replaced inline GP stroke-looping logic with macro-based iterators
These are quite rough, and we may yet just dump this info in Context instead
using the standard techniques...
===================================================================
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_select.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index a4e2f5a..3b2ed2f 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -47,6 +47,8 @@ struct wmOperatorType;
/* ***************************************************** */
/* Internal API */
+/* Stroke Coordinates API ------------------------------ */
+
/**
* Check whether a given stroke segment is inside a circular brush
*
@@ -70,6 +72,29 @@ bool gp_stroke_inside_circle(const int mval[2], const int UNUSED(mvalo[2]),
/* gpencil_paint.c */
void gp_point_to_xy(struct ARegion *ar, struct View2D *v2d, struct rctf *subrect, struct bGPDstroke *gps, struct bGPDspoint *pt,
int *r_x, int *r_y);
+
+/* Stroke Loopers -------------------------------------- */
+
+/* Loop over all visible and selectable strokes
+ * - gpd: (bGPdata *) Grease Pencil datablock in use
+ * - gps: (bGPDstroke *) identifier for the stroke found
+ */
+#define GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps) \
+ { \
+ bGPDlayer *gpl; \
+ for (gpl = (gpd)->layers.first; gpl; gpl = gpl->next) { \
+ if (!(gpl->flag & GP_LAYER_HIDE) && (gpl->actframe)) { \
+ bGPDframe *gpf = gpl->actframe; \
+ bGPDstroke *gps; \
+ for (gps = gpf->strokes.first; gps; gps = gps->next) {
+
+ /* ... code for operating on this stroke ... */
+
+#define GP_STROKES_ITER_END \
+ } \
+ } \
+ } \
+ } (void)0
/* ***************************************************** */
/* Operator Defines */
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 2b20d12..fe5fc23 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -94,53 +94,40 @@ static int gpencil_select_poll(bContext *C)
static int gpencil_select_all_exec(bContext *C, wmOperator *op)
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
- bGPDlayer *gpl;
int action = RNA_enum_get(op->ptr, "action");
/* for "toggle", test for existing selected strokes */
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
- for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
- if (!(gpl->flag & GP_LAYER_HIDE) && (gpl->actframe)) {
- bGPDframe *gpf = gpl->actframe;
- bGPDstroke *gps;
+ GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps)
+ {
+ if (gps->flag & GP_STROKE_SELECT) {
+ action = SEL_DESELECT;
- for (gps = gpf->strokes.first; gps; gps = gps->next) {
- if (gps->flag & GP_STROKE_SELECT) {
- action = SEL_DESELECT;
- break;
- }
- }
- }
-
- if (action != SEL_SELECT)
+ gpl = NULL; /* XXX: hack to stop iterating further, since we've found our target... */
break;
+ }
}
+ GP_STROKES_ITER_END;
}
/* select or deselect all strokes */
- // xxx: refactor this into a proper looper
- for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
- if (!(gpl->flag & GP_LAYER_HIDE) && (gpl->actframe)) {
- bGPDframe *gpf = gpl->actframe;
- bGPDstroke *gps;
-
- for (gps = gpf->strokes.first; gps; gps = gps->next) {
- switch (action) {
- case SEL_SELECT:
- gps->flag |= GP_STROKE_SELECT;
- break;
- case SEL_DESELECT:
- gps->flag &= ~GP_STROKE_SELECT;
- break;
- case SEL_INVERT:
- gps->flag ^= GP_STROKE_SELECT;
- break;
- }
- }
+ GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps)
+ {
+ switch (action) {
+ case SEL_SELECT:
+ gps->flag |= GP_STROKE_SELECT;
+ break;
+ case SEL_DESELECT:
+ gps->flag &= ~GP_STROKE_SELECT;
+ break;
+ case SEL_INVERT:
+ gps->flag ^= GP_STROKE_SELECT;
+ break;
}
}
+ GP_STROKES_ITER_END;
/* updates */
WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL);
@@ -243,7 +230,6 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
bGPdata *gpd = ED_gpencil_data_get_active(C);
- bGPDlayer *gpl;
const int mx = RNA_int_get(op->ptr, "x");
const int my = RNA_int_get(op->ptr, "y");
@@ -290,18 +276,12 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op)
/* find visible strokes, and select if hit */
- // XXX: replace this looper with a proper method
- for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
- if (!(gpl->flag & GP_LAYER_HIDE) && (gpl->actframe)) {
- bGPDframe *gpf = gpl->actframe;
- bGPDstroke *gps;
-
- for (gps = gpf->strokes.first; gps; gps = gps->next) {
- changed |= gp_stroke_do_circle_sel(gps, ar, &ar->v2d, subrect,
- mx, my, radius, select, &rect);
- }
- }
+ GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps)
+ {
+ changed |= gp_stroke_do_circle_sel(gps, ar, &ar->v2d, subrect,
+ mx, my, radius, select, &rect);
}
+ GP_STROKES_ITER_END;
/* updates */
//if (changed)
More information about the Bf-blender-cvs
mailing list