Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/mask/mask_select.c
| Show All 17 Lines | |||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup edmask | * \ingroup edmask | ||||
| */ | */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_blenlib.h" | |||||
| #include "BLI_lasso_2d.h" | #include "BLI_lasso_2d.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_rect.h" | #include "BLI_rect.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_mask.h" | #include "BKE_mask.h" | ||||
| Show All 34 Lines | |||||
| } | } | ||||
| bool ED_mask_layer_select_check(const MaskLayer *mask_layer) | bool ED_mask_layer_select_check(const MaskLayer *mask_layer) | ||||
| { | { | ||||
| if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| for (const MaskSpline *spline = mask_layer->splines.first; spline; spline = spline->next) { | LISTBASE_FOREACH (const MaskSpline *, spline, &mask_layer->splines) { | ||||
| if (ED_mask_spline_select_check(spline)) { | if (ED_mask_spline_select_check(spline)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool ED_mask_select_check(const Mask *mask) | bool ED_mask_select_check(const Mask *mask) | ||||
| { | { | ||||
| for (const MaskLayer *mask_layer = mask->masklayers.first; mask_layer; | LISTBASE_FOREACH (const MaskLayer *, mask_layer, &mask->masklayers) { | ||||
| mask_layer = mask_layer->next) { | |||||
| if (ED_mask_layer_select_check(mask_layer)) { | if (ED_mask_layer_select_check(mask_layer)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 19 Lines | |||||
| void ED_mask_layer_select_set(MaskLayer *mask_layer, const bool do_select) | void ED_mask_layer_select_set(MaskLayer *mask_layer, const bool do_select) | ||||
| { | { | ||||
| if (mask_layer->restrictflag & MASK_RESTRICT_SELECT) { | if (mask_layer->restrictflag & MASK_RESTRICT_SELECT) { | ||||
| if (do_select == true) { | if (do_select == true) { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| for (MaskSpline *spline = mask_layer->splines.first; spline; spline = spline->next) { | LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { | ||||
| ED_mask_spline_select_set(spline, do_select); | ED_mask_spline_select_set(spline, do_select); | ||||
| } | } | ||||
| } | } | ||||
| void ED_mask_select_toggle_all(Mask *mask, int action) | void ED_mask_select_toggle_all(Mask *mask, int action) | ||||
| { | { | ||||
| if (action == SEL_TOGGLE) { | if (action == SEL_TOGGLE) { | ||||
| if (ED_mask_select_check(mask)) { | if (ED_mask_select_check(mask)) { | ||||
| action = SEL_DESELECT; | action = SEL_DESELECT; | ||||
| } | } | ||||
| else { | else { | ||||
| action = SEL_SELECT; | action = SEL_SELECT; | ||||
| } | } | ||||
| } | } | ||||
| for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { | LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { | ||||
| if (mask_layer->restrictflag & MASK_RESTRICT_VIEW) { | if (mask_layer->restrictflag & MASK_RESTRICT_VIEW) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (action == SEL_INVERT) { | if (action == SEL_INVERT) { | ||||
| /* we don't have generic functions for this, its restricted to this operator | /* we don't have generic functions for this, its restricted to this operator | ||||
| * if one day we need to re-use such functionality, they can be split out */ | * if one day we need to re-use such functionality, they can be split out */ | ||||
| if (mask_layer->restrictflag & MASK_RESTRICT_SELECT) { | if (mask_layer->restrictflag & MASK_RESTRICT_SELECT) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (MaskSpline *spline = mask_layer->splines.first; spline; spline = spline->next) { | LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { | ||||
| int i; | int i; | ||||
| for (i = 0; i < spline->tot_point; i++) { | for (i = 0; i < spline->tot_point; i++) { | ||||
| MaskSplinePoint *point = &spline->points[i]; | MaskSplinePoint *point = &spline->points[i]; | ||||
| BKE_mask_point_select_set(point, !MASKPOINT_ISSEL_ANY(point)); | BKE_mask_point_select_set(point, !MASKPOINT_ISSEL_ANY(point)); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| ED_mask_layer_select_set(mask_layer, (action == SEL_SELECT) ? true : false); | ED_mask_layer_select_set(mask_layer, (action == SEL_SELECT) ? true : false); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void ED_mask_select_flush_all(Mask *mask) | void ED_mask_select_flush_all(Mask *mask) | ||||
| { | { | ||||
| for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { | LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { | ||||
| for (MaskSpline *spline = mask_layer->splines.first; spline; spline = spline->next) { | LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { | ||||
| spline->flag &= ~SELECT; | spline->flag &= ~SELECT; | ||||
| /* intentionally _dont_ do this in the mask layer loop | /* intentionally _dont_ do this in the mask layer loop | ||||
| * so we clear flags on all splines */ | * so we clear flags on all splines */ | ||||
| if (mask_layer->restrictflag & MASK_RESTRICT_VIEW) { | if (mask_layer->restrictflag & MASK_RESTRICT_VIEW) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | static int box_select_exec(bContext *C, wmOperator *op) | ||||
| /* get rectangle from operator */ | /* get rectangle from operator */ | ||||
| WM_operator_properties_border_to_rcti(op, &rect); | WM_operator_properties_border_to_rcti(op, &rect); | ||||
| ED_mask_point_pos(area, region, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); | ED_mask_point_pos(area, region, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); | ||||
| ED_mask_point_pos(area, region, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); | ED_mask_point_pos(area, region, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); | ||||
| /* do actual selection */ | /* do actual selection */ | ||||
| for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { | LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { | ||||
| if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (MaskSpline *spline = mask_layer->splines.first; spline; spline = spline->next) { | LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { | ||||
| MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); | MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); | ||||
| for (int i = 0; i < spline->tot_point; i++) { | for (int i = 0; i < spline->tot_point; i++) { | ||||
| MaskSplinePoint *point = &spline->points[i]; | MaskSplinePoint *point = &spline->points[i]; | ||||
| MaskSplinePoint *point_deform = &points_array[i]; | MaskSplinePoint *point_deform = &points_array[i]; | ||||
| /* TODO: handles? */ | /* TODO: handles? */ | ||||
| /* TODO: uw? */ | /* TODO: uw? */ | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | if (SEL_OP_USE_PRE_DESELECT(sel_op)) { | ||||
| ED_mask_select_toggle_all(mask, SEL_DESELECT); | ED_mask_select_toggle_all(mask, SEL_DESELECT); | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| /* get rectangle from operator */ | /* get rectangle from operator */ | ||||
| BLI_lasso_boundbox(&rect, mcords, moves); | BLI_lasso_boundbox(&rect, mcords, moves); | ||||
| /* do actual selection */ | /* do actual selection */ | ||||
| for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { | LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { | ||||
| if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (MaskSpline *spline = mask_layer->splines.first; spline; spline = spline->next) { | LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { | ||||
| MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); | MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); | ||||
| for (int i = 0; i < spline->tot_point; i++) { | for (int i = 0; i < spline->tot_point; i++) { | ||||
| MaskSplinePoint *point = &spline->points[i]; | MaskSplinePoint *point = &spline->points[i]; | ||||
| MaskSplinePoint *point_deform = &points_array[i]; | MaskSplinePoint *point_deform = &points_array[i]; | ||||
| /* TODO: handles? */ | /* TODO: handles? */ | ||||
| /* TODO: uw? */ | /* TODO: uw? */ | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | const eSelectOp sel_op = ED_select_op_modal(RNA_enum_get(op->ptr, "mode"), | ||||
| WM_gesture_is_modal_first(op->customdata)); | WM_gesture_is_modal_first(op->customdata)); | ||||
| const bool select = (sel_op != SEL_OP_SUB); | const bool select = (sel_op != SEL_OP_SUB); | ||||
| if (SEL_OP_USE_PRE_DESELECT(sel_op)) { | if (SEL_OP_USE_PRE_DESELECT(sel_op)) { | ||||
| ED_mask_select_toggle_all(mask, SEL_DESELECT); | ED_mask_select_toggle_all(mask, SEL_DESELECT); | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| /* do actual selection */ | /* do actual selection */ | ||||
| for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { | LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { | ||||
| if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (MaskSpline *spline = mask_layer->splines.first; spline; spline = spline->next) { | LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { | ||||
| MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); | MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); | ||||
| for (i = 0; i < spline->tot_point; i++) { | for (i = 0; i < spline->tot_point; i++) { | ||||
| MaskSplinePoint *point = &spline->points[i]; | MaskSplinePoint *point = &spline->points[i]; | ||||
| MaskSplinePoint *point_deform = &points_array[i]; | MaskSplinePoint *point_deform = &points_array[i]; | ||||
| if (mask_spline_point_inside_ellipse(&point_deform->bezt, offset, ellipse)) { | if (mask_spline_point_inside_ellipse(&point_deform->bezt, offset, ellipse)) { | ||||
| BKE_mask_point_select_set(point, select); | BKE_mask_point_select_set(point, select); | ||||
| ▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
| static int mask_select_linked_exec(bContext *C, wmOperator *UNUSED(op)) | static int mask_select_linked_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Mask *mask = CTX_data_edit_mask(C); | Mask *mask = CTX_data_edit_mask(C); | ||||
| bool changed = false; | bool changed = false; | ||||
| /* do actual selection */ | /* do actual selection */ | ||||
| for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { | LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { | ||||
| if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (MaskSpline *spline = mask_layer->splines.first; spline; spline = spline->next) { | LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { | ||||
| if (ED_mask_spline_select_check(spline)) { | if (ED_mask_spline_select_check(spline)) { | ||||
| ED_mask_spline_select_set(spline, true); | ED_mask_spline_select_set(spline, true); | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (changed) { | if (changed) { | ||||
| Show All 28 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Select More/Less Operators | /** \name Select More/Less Operators | ||||
| * \{ */ | * \{ */ | ||||
| static int mask_select_more_less(bContext *C, bool more) | static int mask_select_more_less(bContext *C, bool more) | ||||
| { | { | ||||
| Mask *mask = CTX_data_edit_mask(C); | Mask *mask = CTX_data_edit_mask(C); | ||||
| for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { | LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { | ||||
| if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (MaskSpline *spline = mask_layer->splines.first; spline; spline = spline->next) { | LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { | ||||
| const bool cyclic = (spline->flag & MASK_SPLINE_CYCLIC) != 0; | const bool cyclic = (spline->flag & MASK_SPLINE_CYCLIC) != 0; | ||||
| bool start_sel, end_sel, prev_sel, cur_sel; | bool start_sel, end_sel, prev_sel, cur_sel; | ||||
| int i; | int i; | ||||
| /* reselect point if any handle is selected to make the result more predictable */ | /* reselect point if any handle is selected to make the result more predictable */ | ||||
| for (i = 0; i < spline->tot_point; i++) { | for (i = 0; i < spline->tot_point; i++) { | ||||
| BKE_mask_point_select_set(spline->points + i, MASKPOINT_ISSEL_ANY(spline->points + i)); | BKE_mask_point_select_set(spline->points + i, MASKPOINT_ISSEL_ANY(spline->points + i)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines | |||||