Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/mask/mask_ops.c
| Show First 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | typedef struct SlidePointData { | ||||
| MaskLayer *mask_layer; | MaskLayer *mask_layer; | ||||
| MaskSpline *spline, *orig_spline; | MaskSpline *spline, *orig_spline; | ||||
| MaskSplinePoint *point; | MaskSplinePoint *point; | ||||
| MaskSplinePointUW *uw; | MaskSplinePointUW *uw; | ||||
| eMaskWhichHandle which_handle; | eMaskWhichHandle which_handle; | ||||
| int width, height; | int width, height; | ||||
| float prev_mouse_coord[2]; | float prev_mouse_coord[2]; | ||||
| /* Previous clip coordinate which was resolved from mouse position (0, 0). | |||||
| * Is used to compansate for view offste moving in-between of mouse events when | |||||
| * lock-to-selection is enabled. */ | |||||
| float prev_zero_coord[2]; | |||||
| float no[2]; | float no[2]; | ||||
| bool is_curvature_only, is_accurate, is_initial_feather, is_overall_feather; | bool is_curvature_only, is_accurate, is_initial_feather, is_overall_feather; | ||||
| bool is_sliding_new_point; | bool is_sliding_new_point; | ||||
| /* Data needed to restre the state. */ | /* Data needed to restre the state. */ | ||||
| float vec[3][3]; | float vec[3][3]; | ||||
| ▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | static void *slide_point_customdata(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| MaskSplinePoint *point, *cv_point, *feather_point; | MaskSplinePoint *point, *cv_point, *feather_point; | ||||
| MaskSplinePointUW *uw = NULL; | MaskSplinePointUW *uw = NULL; | ||||
| int width, height, action = SLIDE_ACTION_NONE; | int width, height, action = SLIDE_ACTION_NONE; | ||||
| const bool slide_feather = RNA_boolean_get(op->ptr, "slide_feather"); | const bool slide_feather = RNA_boolean_get(op->ptr, "slide_feather"); | ||||
| float co[2], cv_score, feather_score; | float co[2], cv_score, feather_score; | ||||
| const float threshold = 19; | const float threshold = 19; | ||||
| eMaskWhichHandle which_handle; | eMaskWhichHandle which_handle; | ||||
| MaskViewLockState lock_state; | |||||
| ED_mask_view_lock_state_store(C, &lock_state); | |||||
| ED_mask_mouse_pos(area, region, event->mval, co); | ED_mask_mouse_pos(area, region, event->mval, co); | ||||
| ED_mask_get_size(area, &width, &height); | ED_mask_get_size(area, &width, &height); | ||||
| cv_point = ED_mask_point_find_nearest( | cv_point = ED_mask_point_find_nearest( | ||||
| C, mask, co, threshold, &cv_mask_layer, &cv_spline, &which_handle, &cv_score); | C, mask, co, threshold, &cv_mask_layer, &cv_spline, &which_handle, &cv_score); | ||||
| if (ED_mask_feather_find_nearest(C, | if (ED_mask_feather_find_nearest(C, | ||||
| mask, | mask, | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | if (customdata->action != SLIDE_ACTION_SPLINE) { | ||||
| copy_m3_m3(customdata->vec, point->bezt.vec); | copy_m3_m3(customdata->vec, point->bezt.vec); | ||||
| if (which_handle != MASK_WHICH_HANDLE_NONE) { | if (which_handle != MASK_WHICH_HANDLE_NONE) { | ||||
| BKE_mask_point_handle(point, which_handle, customdata->orig_handle_coord); | BKE_mask_point_handle(point, which_handle, customdata->orig_handle_coord); | ||||
| copy_v2_v2(customdata->prev_handle_coord, customdata->orig_handle_coord); | copy_v2_v2(customdata->prev_handle_coord, customdata->orig_handle_coord); | ||||
| } | } | ||||
| } | } | ||||
| customdata->which_handle = which_handle; | customdata->which_handle = which_handle; | ||||
| { | |||||
| WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); | |||||
| DEG_id_tag_update(&mask->id, 0); | |||||
| ED_mask_view_lock_state_restore_no_jump(C, &lock_state); | |||||
| } | |||||
| ED_mask_mouse_pos(area, region, event->mval, customdata->prev_mouse_coord); | ED_mask_mouse_pos(area, region, event->mval, customdata->prev_mouse_coord); | ||||
| ED_mask_mouse_pos(area, region, (int[2]){0, 0}, customdata->prev_zero_coord); | |||||
| } | } | ||||
| return customdata; | return customdata; | ||||
| } | } | ||||
| static int slide_point_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int slide_point_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| Mask *mask = CTX_data_edit_mask(C); | Mask *mask = CTX_data_edit_mask(C); | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | case EVT_RIGHTSHIFTKEY: | ||||
| ATTR_FALLTHROUGH; /* update CV position */ | ATTR_FALLTHROUGH; /* update CV position */ | ||||
| case MOUSEMOVE: { | case MOUSEMOVE: { | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| float delta[2]; | float delta[2]; | ||||
| ED_mask_mouse_pos(area, region, event->mval, co); | ED_mask_mouse_pos(area, region, event->mval, co); | ||||
| sub_v2_v2v2(delta, co, data->prev_mouse_coord); | sub_v2_v2v2(delta, co, data->prev_mouse_coord); | ||||
| copy_v2_v2(data->prev_mouse_coord, co); | |||||
| /* Compensate for possibly moved view offset since the last event. | |||||
| * The idea is to see how mapping of a fixed and known position did change. */ | |||||
| { | |||||
| float zero_coord[2]; | |||||
| ED_mask_mouse_pos(area, region, (int[2]){0, 0}, zero_coord); | |||||
| float zero_delta[2]; | |||||
| sub_v2_v2v2(zero_delta, zero_coord, data->prev_zero_coord); | |||||
| sub_v2_v2(delta, zero_delta); | |||||
| copy_v2_v2(data->prev_zero_coord, zero_coord); | |||||
| } | |||||
| if (data->is_accurate) { | if (data->is_accurate) { | ||||
| mul_v2_fl(delta, 0.2f); | mul_v2_fl(delta, 0.2f); | ||||
| } | } | ||||
| copy_v2_v2(data->prev_mouse_coord, co); | |||||
| if (data->action == SLIDE_ACTION_HANDLE) { | if (data->action == SLIDE_ACTION_HANDLE) { | ||||
| float new_handle[2]; | float new_handle[2]; | ||||
| if (data->is_sliding_new_point && data->which_handle == MASK_WHICH_HANDLE_STICK) { | if (data->is_sliding_new_point && data->which_handle == MASK_WHICH_HANDLE_STICK) { | ||||
| if (ELEM(data->point, | if (ELEM(data->point, | ||||
| &data->spline->points[0], | &data->spline->points[0], | ||||
| &data->spline->points[data->spline->tot_point - 1])) { | &data->spline->points[data->spline->tot_point - 1])) { | ||||
| ▲ Show 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | static SlideSplineCurvatureData *slide_spline_curvature_customdata(bContext *C, | ||||
| Mask *mask = CTX_data_edit_mask(C); | Mask *mask = CTX_data_edit_mask(C); | ||||
| SlideSplineCurvatureData *slide_data; | SlideSplineCurvatureData *slide_data; | ||||
| MaskLayer *mask_layer; | MaskLayer *mask_layer; | ||||
| MaskSpline *spline; | MaskSpline *spline; | ||||
| MaskSplinePoint *point; | MaskSplinePoint *point; | ||||
| float u, co[2]; | float u, co[2]; | ||||
| BezTriple *next_bezt; | BezTriple *next_bezt; | ||||
| MaskViewLockState lock_state; | |||||
| ED_mask_view_lock_state_store(C, &lock_state); | |||||
| ED_mask_mouse_pos(CTX_wm_area(C), CTX_wm_region(C), event->mval, co); | ED_mask_mouse_pos(CTX_wm_area(C), CTX_wm_region(C), event->mval, co); | ||||
| if (!ED_mask_find_nearest_diff_point(C, | if (!ED_mask_find_nearest_diff_point(C, | ||||
| mask, | mask, | ||||
| co, | co, | ||||
| threshold, | threshold, | ||||
| false, | false, | ||||
| NULL, | NULL, | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | static SlideSplineCurvatureData *slide_spline_curvature_customdata(bContext *C, | ||||
| else { | else { | ||||
| slide_data->adjust_bezt->f1 |= SELECT; | slide_data->adjust_bezt->f1 |= SELECT; | ||||
| slide_data->other_bezt->f3 |= SELECT; | slide_data->other_bezt->f3 |= SELECT; | ||||
| } | } | ||||
| mask_layer->act_spline = spline; | mask_layer->act_spline = spline; | ||||
| mask_layer->act_point = point; | mask_layer->act_point = point; | ||||
| ED_mask_select_flush_all(mask); | ED_mask_select_flush_all(mask); | ||||
| DEG_id_tag_update(&mask->id, 0); | |||||
| ED_mask_view_lock_state_restore_no_jump(C, &lock_state); | |||||
| return slide_data; | return slide_data; | ||||
| } | } | ||||
| static int slide_spline_curvature_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int slide_spline_curvature_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| Mask *mask = CTX_data_edit_mask(C); | Mask *mask = CTX_data_edit_mask(C); | ||||
| SlideSplineCurvatureData *slide_data; | SlideSplineCurvatureData *slide_data; | ||||
| ▲ Show 20 Lines • Show All 1,042 Lines • Show Last 20 Lines | |||||