diff options
Diffstat (limited to 'source/blender/editors/mask/mask_ops.c')
-rw-r--r-- | source/blender/editors/mask/mask_ops.c | 111 |
1 files changed, 58 insertions, 53 deletions
diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index 1f825c0bb31..5a7a84dbbc8 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -31,6 +31,7 @@ #include "BKE_mask.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "DNA_scene_types.h" #include "DNA_mask_types.h" @@ -65,7 +66,7 @@ static void mask_point_scaled_handle(/*const*/ MaskSplinePoint *point, } MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, - Mask *mask, + Mask *mask_orig, const float normal_co[2], const float threshold, MaskLayer **masklay_r, @@ -76,7 +77,6 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); - MaskLayer *masklay; MaskLayer *point_masklay = NULL; MaskSpline *point_spline = NULL; MaskSplinePoint *point = NULL; @@ -86,29 +86,35 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, eMaskWhichHandle which_handle = MASK_WHICH_HANDLE_NONE; int width, height; + Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); + Mask *mask_eval = (Mask *)DEG_get_evaluated_id(depsgraph, &mask_orig->id); + ED_mask_get_size(sa, &width, &height); ED_mask_pixelspace_factor(sa, ar, &scalex, &scaley); co[0] = normal_co[0] * scalex; co[1] = normal_co[1] * scaley; - for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { - MaskSpline *spline; + for (MaskLayer *masklay_orig = mask_orig->masklayers.first, + *masklay_eval = mask_eval->masklayers.first; + masklay_orig != NULL; + masklay_orig = masklay_orig->next, masklay_eval = masklay_eval->next) { - if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { + if (masklay_orig->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { continue; } - for (spline = masklay->splines.first; spline; spline = spline->next) { - MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); - - int i; + for (MaskSpline *spline_orig = masklay_orig->splines.first, + *spline_eval = masklay_eval->splines.first; + spline_orig != NULL; + spline_orig = spline_orig->next, spline_eval = spline_eval->next) { + MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline_eval); - for (i = 0; i < spline->tot_point; i++) { - MaskSplinePoint *cur_point = &spline->points[i]; - MaskSplinePoint *cur_point_deform = &points_array[i]; + for (int i = 0; i < spline_orig->tot_point; i++) { + MaskSplinePoint *cur_point_orig = &spline_orig->points[i]; + MaskSplinePoint *cur_point_deform_eval = &points_array[i]; eMaskWhichHandle cur_which_handle = MASK_WHICH_HANDLE_NONE; - BezTriple *bezt = &cur_point_deform->bezt; + BezTriple *bezt = &cur_point_deform_eval->bezt; float cur_len_sq, vec[2]; vec[0] = bezt->vec[1][0] * scalex; @@ -117,17 +123,17 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, cur_len_sq = len_squared_v2v2(co, vec); if (cur_len_sq < len_sq) { - point_spline = spline; - point_masklay = masklay; - point = cur_point; + point_spline = spline_orig; + point_masklay = masklay_orig; + point = cur_point_orig; len_sq = cur_len_sq; which_handle = MASK_WHICH_HANDLE_NONE; } - if (BKE_mask_point_handles_mode_get(cur_point_deform) == MASK_HANDLE_MODE_STICK) { + if (BKE_mask_point_handles_mode_get(cur_point_deform_eval) == MASK_HANDLE_MODE_STICK) { float handle[2]; mask_point_scaled_handle( - cur_point_deform, MASK_WHICH_HANDLE_STICK, scalex, scaley, handle); + cur_point_deform_eval, MASK_WHICH_HANDLE_STICK, scalex, scaley, handle); cur_len_sq = len_squared_v2v2(co, handle); cur_which_handle = MASK_WHICH_HANDLE_STICK; } @@ -135,9 +141,9 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, float handle_left[2], handle_right[2]; float len_left_sq, len_right_sq; mask_point_scaled_handle( - cur_point_deform, MASK_WHICH_HANDLE_LEFT, scalex, scaley, handle_left); + cur_point_deform_eval, MASK_WHICH_HANDLE_LEFT, scalex, scaley, handle_left); mask_point_scaled_handle( - cur_point_deform, MASK_WHICH_HANDLE_RIGHT, scalex, scaley, handle_right); + cur_point_deform_eval, MASK_WHICH_HANDLE_RIGHT, scalex, scaley, handle_right); len_left_sq = len_squared_v2v2(co, handle_left); len_right_sq = len_squared_v2v2(co, handle_right); @@ -168,9 +174,9 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, } if (cur_len_sq <= len_sq && cur_which_handle != MASK_WHICH_HANDLE_NONE) { - point_masklay = masklay; - point_spline = spline; - point = cur_point; + point_masklay = masklay_orig; + point_spline = spline_orig; + point = cur_point_orig; len_sq = cur_len_sq; which_handle = cur_which_handle; } @@ -214,7 +220,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, } bool ED_mask_feather_find_nearest(const bContext *C, - Mask *mask, + Mask *mask_orig, const float normal_co[2], const float threshold, MaskLayer **masklay_r, @@ -226,7 +232,7 @@ bool ED_mask_feather_find_nearest(const bContext *C, ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); - MaskLayer *masklay, *point_masklay = NULL; + MaskLayer *point_masklay = NULL; MaskSpline *point_spline = NULL; MaskSplinePoint *point = NULL; MaskSplinePointUW *uw = NULL; @@ -235,32 +241,41 @@ bool ED_mask_feather_find_nearest(const bContext *C, float scalex, scaley; int width, height; + Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); + Mask *mask_eval = (Mask *)DEG_get_evaluated_id(depsgraph, &mask_orig->id); + ED_mask_get_size(sa, &width, &height); ED_mask_pixelspace_factor(sa, ar, &scalex, &scaley); co[0] = normal_co[0] * scalex; co[1] = normal_co[1] * scaley; - for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { - MaskSpline *spline; + for (MaskLayer *masklay_orig = mask_orig->masklayers.first, + *masklay_eval = mask_eval->masklayers.first; + masklay_orig != NULL; + masklay_orig = masklay_orig->next, masklay_eval = masklay_eval->next) { - for (spline = masklay->splines.first; spline; spline = spline->next) { + for (MaskSpline *spline_orig = masklay_orig->splines.first, + *spline_eval = masklay_eval->splines.first; + spline_orig != NULL; + spline_orig = spline_orig->next, spline_eval = spline_eval->next) { // MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); int i, tot_feather_point; float(*feather_points)[2], (*fp)[2]; - if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { + if (masklay_orig->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { continue; } - feather_points = fp = BKE_mask_spline_feather_points(spline, &tot_feather_point); + feather_points = fp = BKE_mask_spline_feather_points(spline_eval, &tot_feather_point); - for (i = 0; i < spline->tot_point; i++) { + for (i = 0; i < spline_orig->tot_point; i++) { int j; - MaskSplinePoint *cur_point = &spline->points[i]; + MaskSplinePoint *cur_point_orig = &spline_orig->points[i]; + MaskSplinePoint *cur_point_eval = &spline_eval->points[i]; - for (j = 0; j <= cur_point->tot_uw; j++) { + for (j = 0; j <= cur_point_eval->tot_uw; j++) { float cur_len_sq, vec[2]; vec[0] = (*fp)[0] * scalex; @@ -273,12 +288,12 @@ bool ED_mask_feather_find_nearest(const bContext *C, uw = NULL; } else { - uw = &cur_point->uw[j - 1]; + uw = &cur_point_eval->uw[j - 1]; } - point_masklay = masklay; - point_spline = spline; - point = cur_point; + point_masklay = masklay_orig; + point_spline = spline_orig; + point = cur_point_orig; len = cur_len_sq; } @@ -1648,7 +1663,6 @@ static void delete_feather_points(MaskSplinePoint *point) static int delete_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; bool changed = false; @@ -1743,8 +1757,7 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; } - /* TODO: only update edited splines */ - BKE_mask_update_display(mask, CFRA); + DEG_id_tag_update(&mask->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); @@ -1801,8 +1814,7 @@ static int mask_switch_direction_exec(bContext *C, wmOperator *UNUSED(op)) } if (changed) { - /* TODO: only update this spline */ - BKE_mask_update_display(mask, CFRA); + DEG_id_tag_update(&mask->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); @@ -1867,8 +1879,7 @@ static int mask_normals_make_consistent_exec(bContext *C, wmOperator *UNUSED(op) } if (changed) { - /* TODO: only update this spline */ - BKE_mask_update_display(mask, CFRA); + DEG_id_tag_update(&mask->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); @@ -2094,7 +2105,6 @@ void MASK_OT_hide_view_set(wmOperatorType *ot) static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; bool changed = false; @@ -2121,8 +2131,7 @@ static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op)) } if (changed) { - /* TODO: only update edited splines */ - BKE_mask_update_display(mask, CFRA); + DEG_id_tag_update(&mask->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_MASK | ND_DRAW, mask); DEG_id_tag_update(&mask->id, 0); @@ -2234,7 +2243,6 @@ void MASK_OT_layer_move(wmOperatorType *ot) static int mask_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *mask_layer; @@ -2324,8 +2332,7 @@ static int mask_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) } } - /* TODO: only update edited splines */ - BKE_mask_update_display(mask, CFRA); + DEG_id_tag_update(&mask->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); @@ -2391,7 +2398,6 @@ static bool paste_splines_poll(bContext *C) static int paste_splines_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene *scene = CTX_data_scene(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *mask_layer = BKE_mask_layer_active(mask); @@ -2401,8 +2407,7 @@ static int paste_splines_exec(bContext *C, wmOperator *UNUSED(op)) BKE_mask_clipboard_paste_to_layer(CTX_data_main(C), mask_layer); - /* TODO: only update edited splines */ - BKE_mask_update_display(mask, CFRA); + DEG_id_tag_update(&mask->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); |