Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSv. Lockal <lockalsash@gmail.com>2013-07-20 14:24:16 +0400
committerSv. Lockal <lockalsash@gmail.com>2013-07-20 14:24:16 +0400
commit3de1458cdf5221923b04f0019cc1e6ad7de1809a (patch)
tree794e16a5a0c6eec69810bc2feb78393ce9c8ce48 /source/blender/editors/mask/mask_select.c
parent363b04d15e89e6757b37f11742bcdcaaab9d0b1e (diff)
Select more/less tool for mask splines
Diffstat (limited to 'source/blender/editors/mask/mask_select.c')
-rw-r--r--source/blender/editors/mask/mask_select.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c
index 997f170c9f9..774a920f366 100644
--- a/source/blender/editors/mask/mask_select.c
+++ b/source/blender/editors/mask/mask_select.c
@@ -793,3 +793,115 @@ void MASK_OT_select_linked(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+
+/**************** Select more/less **************/
+
+static int mask_select_more_less(bContext *C, bool more)
+{
+ Mask *mask = CTX_data_edit_mask(C);
+ MaskLayer *masklay;
+
+ for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+ MaskSpline *spline;
+
+ if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
+ continue;
+ }
+
+ for (spline = masklay->splines.first; spline; spline = spline->next) {
+ int i;
+ bool start_sel, end_sel, prev_sel, cur_sel, cyclic = spline->flag & MASK_SPLINE_CYCLIC;
+
+ // reselect point if any handle is selected to make the result more predictable
+ for (i = 0; i < spline->tot_point; i++) {
+ BKE_mask_point_select_set(spline->points + i, MASKPOINT_ISSEL_ANY(spline->points + i));
+ }
+
+ // select more/less does not affect empty/single point splines
+ if (spline->tot_point < 2) {
+ continue;
+ }
+
+ if (cyclic) {
+ start_sel = !!MASKPOINT_ISSEL_KNOT(spline->points);
+ end_sel = !!MASKPOINT_ISSEL_KNOT(&spline->points[spline->tot_point - 1]);
+ }
+
+ for (i = 0; i < spline->tot_point; i++) {
+ if (i == 0 && !cyclic) {
+ continue;
+ }
+
+ prev_sel = (i > 0) ? !!MASKPOINT_ISSEL_KNOT(&spline->points[i - 1]) : end_sel;
+ cur_sel = !!MASKPOINT_ISSEL_KNOT(&spline->points[i]);
+
+ if (cur_sel != more) {
+ if (prev_sel == more) {
+ BKE_mask_point_select_set(&spline->points[i], more);
+ }
+ i++;
+ }
+ }
+
+ for (i = spline->tot_point - 1; i >= 0; i--) {
+ if (i == spline->tot_point - 1 && !cyclic) {
+ continue;
+ }
+
+ prev_sel = (i < spline->tot_point - 1) ? !!MASKPOINT_ISSEL_KNOT(&spline->points[i + 1]) : start_sel;
+ cur_sel = !!MASKPOINT_ISSEL_KNOT(&spline->points[i]);
+
+ if (cur_sel != more) {
+ if (prev_sel == more) {
+ BKE_mask_point_select_set(&spline->points[i], more);
+ }
+ i--;
+ }
+ }
+ }
+ }
+
+ WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
+
+ return OPERATOR_FINISHED;
+}
+
+static int mask_select_more_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ return mask_select_more_less(C, true);
+}
+
+void MASK_OT_select_more(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Select More";
+ ot->idname = "MASK_OT_select_more";
+ ot->description = "Select more spline points connected to initial selection";
+
+ /* api callbacks */
+ ot->exec = mask_select_more_exec;
+ ot->poll = ED_maskedit_mask_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int mask_select_less_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ return mask_select_more_less(C, false);
+}
+
+void MASK_OT_select_less(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Select Less";
+ ot->idname = "MASK_OT_select_less";
+ ot->description = "Deselect spline points at the boundary of each selection region";
+
+ /* api callbacks */
+ ot->exec = mask_select_less_exec;
+ ot->poll = ED_maskedit_mask_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}