diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-05 10:37:33 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-05 10:39:56 +0300 |
commit | caacedd861fea49086d6ec531acbaf79a775c62b (patch) | |
tree | 3fb1c44941122247d65d7f34eef83bc60527a4f6 /source/blender | |
parent | b8ef725497e45648ac7214927294e3ab60b71bc2 (diff) |
GP: move select all into a utility function
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_select.c | 85 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_utils.c | 89 | ||||
-rw-r--r-- | source/blender/editors/include/ED_gpencil.h | 2 |
3 files changed, 92 insertions, 84 deletions
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index 720e3656b0c..e3d4b42e359 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -102,90 +102,7 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /* for "toggle", test for existing selected strokes */ - if (action == SEL_TOGGLE) { - action = SEL_SELECT; - - CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) - { - if (gps->flag & GP_STROKE_SELECT) { - action = SEL_DESELECT; - break; // XXX: this only gets out of the inner loop... - } - } - CTX_DATA_END; - } - - /* if deselecting, we need to deselect strokes across all frames - * - Currently, an exception is only given for deselection - * Selecting and toggling should only affect what's visible, - * while deselecting helps clean up unintended/forgotten - * stuff on other frames - */ - if (action == SEL_DESELECT) { - /* deselect strokes across editable layers - * NOTE: we limit ourselves to editable layers, since once a layer is "locked/hidden - * nothing should be able to touch it - */ - CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers) - { - bGPDframe *gpf; - - /* deselect all strokes on all frames */ - for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { - bGPDstroke *gps; - - for (gps = gpf->strokes.first; gps; gps = gps->next) { - bGPDspoint *pt; - int i; - - /* only edit strokes that are valid in this view... */ - if (ED_gpencil_stroke_can_use(C, gps)) { - for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { - pt->flag &= ~GP_SPOINT_SELECT; - } - - gps->flag &= ~GP_STROKE_SELECT; - } - } - } - } - CTX_DATA_END; - } - else { - /* select or deselect all strokes */ - CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) - { - bGPDspoint *pt; - int i; - bool selected = false; - - /* Change selection status of all points, then make the stroke match */ - for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { - switch (action) { - case SEL_SELECT: - pt->flag |= GP_SPOINT_SELECT; - break; - //case SEL_DESELECT: - // pt->flag &= ~GP_SPOINT_SELECT; - // break; - case SEL_INVERT: - pt->flag ^= GP_SPOINT_SELECT; - break; - } - - if (pt->flag & GP_SPOINT_SELECT) - selected = true; - } - - /* Change status of stroke */ - if (selected) - gps->flag |= GP_STROKE_SELECT; - else - gps->flag &= ~GP_STROKE_SELECT; - } - CTX_DATA_END; - } + ED_gpencil_select_toggle_all(C, action); /* updates */ DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY); diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index a727e2cc5de..d17e83677d7 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -71,6 +71,7 @@ #include "ED_view3d.h" #include "ED_object.h" #include "ED_screen.h" +#include "ED_select_utils.h" #include "GPU_immediate.h" #include "GPU_immediate_util.h" @@ -2351,3 +2352,91 @@ int ED_gpencil_select_stroke_segment( return 0; } } + +void ED_gpencil_select_toggle_all(bContext *C, int action) +{ + /* for "toggle", test for existing selected strokes */ + if (action == SEL_TOGGLE) { + action = SEL_SELECT; + + CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) + { + if (gps->flag & GP_STROKE_SELECT) { + action = SEL_DESELECT; + break; // XXX: this only gets out of the inner loop... + } + } + CTX_DATA_END; + } + + /* if deselecting, we need to deselect strokes across all frames + * - Currently, an exception is only given for deselection + * Selecting and toggling should only affect what's visible, + * while deselecting helps clean up unintended/forgotten + * stuff on other frames + */ + if (action == SEL_DESELECT) { + /* deselect strokes across editable layers + * NOTE: we limit ourselves to editable layers, since once a layer is "locked/hidden + * nothing should be able to touch it + */ + CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers) + { + bGPDframe *gpf; + + /* deselect all strokes on all frames */ + for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { + bGPDstroke *gps; + + for (gps = gpf->strokes.first; gps; gps = gps->next) { + bGPDspoint *pt; + int i; + + /* only edit strokes that are valid in this view... */ + if (ED_gpencil_stroke_can_use(C, gps)) { + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + pt->flag &= ~GP_SPOINT_SELECT; + } + + gps->flag &= ~GP_STROKE_SELECT; + } + } + } + } + CTX_DATA_END; + } + else { + /* select or deselect all strokes */ + CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) + { + bGPDspoint *pt; + int i; + bool selected = false; + + /* Change selection status of all points, then make the stroke match */ + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + switch (action) { + case SEL_SELECT: + pt->flag |= GP_SPOINT_SELECT; + break; + //case SEL_DESELECT: + // pt->flag &= ~GP_SPOINT_SELECT; + // break; + case SEL_INVERT: + pt->flag ^= GP_SPOINT_SELECT; + break; + } + + if (pt->flag & GP_SPOINT_SELECT) + selected = true; + } + + /* Change status of stroke */ + if (selected) + gps->flag |= GP_STROKE_SELECT; + else + gps->flag &= ~GP_STROKE_SELECT; + } + CTX_DATA_END; + } +} diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h index 666cf55cac3..e331032bd6e 100644 --- a/source/blender/editors/include/ED_gpencil.h +++ b/source/blender/editors/include/ED_gpencil.h @@ -266,4 +266,6 @@ int ED_gpencil_select_stroke_segment( bool select, bool insert, const float scale, float r_hita[3], float r_hitb[3]); +void ED_gpencil_select_toggle_all(struct bContext *C, int action); + #endif /* __ED_GPENCIL_H__ */ |