From 1064bf58c3e8fd28d55a09632046a3c008ca1f03 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 16 Jun 2022 16:23:24 +1000 Subject: Cleanup: differentiate region/screen relative coordinates - Avoid ambiguity which caused these values to be confused, use `mval` for region relative mouse coordinates, otherwise `event_xy`. - Pass region relative coordinates to sample_detail_dyntopo & sample_detail_voxel as there is no reason to use screen-space values. - Rename invalid use of mval for screen-space coordinates. --- .../blender/editors/sculpt_paint/sculpt_detail.c | 37 +++++++++++----------- 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'source/blender/editors/sculpt_paint/sculpt_detail.c') diff --git a/source/blender/editors/sculpt_paint/sculpt_detail.c b/source/blender/editors/sculpt_paint/sculpt_detail.c index 0f4ef41f80e..00503087e39 100644 --- a/source/blender/editors/sculpt_paint/sculpt_detail.c +++ b/source/blender/editors/sculpt_paint/sculpt_detail.c @@ -158,7 +158,7 @@ static EnumPropertyItem prop_sculpt_sample_detail_mode_types[] = { {0, NULL, 0, NULL, NULL}, }; -static void sample_detail_voxel(bContext *C, ViewContext *vc, int mx, int my) +static void sample_detail_voxel(bContext *C, ViewContext *vc, const int mval[2]) { Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Object *ob = vc->obact; @@ -169,8 +169,8 @@ static void sample_detail_voxel(bContext *C, ViewContext *vc, int mx, int my) SCULPT_vertex_random_access_ensure(ss); /* Update the active vertex. */ - const float mouse[2] = {mx - vc->region->winrct.xmin, my - vc->region->winrct.ymin}; - SCULPT_cursor_geometry_info_update(C, &sgi, mouse, false); + const float mval_fl[2] = {UNPACK2(mval)}; + SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false); BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, false); /* Average the edge length of the connected edges to the active vertex. */ @@ -201,7 +201,7 @@ static void sculpt_raycast_detail_cb(PBVHNode *node, void *data_v, float *tmin) } } -static void sample_detail_dyntopo(bContext *C, ViewContext *vc, ARegion *region, int mx, int my) +static void sample_detail_dyntopo(bContext *C, ViewContext *vc, const int mval[2]) { Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob = vc->obact; @@ -209,9 +209,9 @@ static void sample_detail_dyntopo(bContext *C, ViewContext *vc, ARegion *region, SCULPT_stroke_modifiers_check(C, ob, brush); - const float mouse[2] = {mx - region->winrct.xmin, my - region->winrct.ymin}; + const float mval_fl[2] = {UNPACK2(mval)}; float ray_start[3], ray_end[3], ray_normal[3]; - float depth = SCULPT_raycast_init(vc, mouse, ray_start, ray_end, ray_normal, false); + float depth = SCULPT_raycast_init(vc, mval_fl, ray_start, ray_end, ray_normal, false); SculptDetailRaycastData srd; srd.hit = 0; @@ -228,14 +228,12 @@ static void sample_detail_dyntopo(bContext *C, ViewContext *vc, ARegion *region, } } -static int sample_detail(bContext *C, int mx, int my, int mode) +static int sample_detail(bContext *C, const int event_xy[2], int mode) { /* Find 3D view to pick from. */ bScreen *screen = CTX_wm_screen(C); - ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_VIEW3D, (const int[2]){mx, my}); - ARegion *region = (area) ? - BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, (const int[2]){mx, my}) : - NULL; + ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_VIEW3D, event_xy); + ARegion *region = (area) ? BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, event_xy) : NULL; if (region == NULL) { return OPERATOR_CANCELLED; } @@ -260,6 +258,11 @@ static int sample_detail(bContext *C, int mx, int my, int mode) return OPERATOR_CANCELLED; } + const int mval[2] = { + event_xy[0] - region->winrct.xmin, + event_xy[1] - region->winrct.ymin, + }; + /* Pick sample detail. */ switch (mode) { case SAMPLE_DETAIL_DYNTOPO: @@ -268,7 +271,7 @@ static int sample_detail(bContext *C, int mx, int my, int mode) CTX_wm_region_set(C, prev_region); return OPERATOR_CANCELLED; } - sample_detail_dyntopo(C, &vc, region, mx, my); + sample_detail_dyntopo(C, &vc, mval); break; case SAMPLE_DETAIL_VOXEL: if (BKE_pbvh_type(ss->pbvh) != PBVH_FACES) { @@ -276,7 +279,7 @@ static int sample_detail(bContext *C, int mx, int my, int mode) CTX_wm_region_set(C, prev_region); return OPERATOR_CANCELLED; } - sample_detail_voxel(C, &vc, mx, my); + sample_detail_voxel(C, &vc, mval); break; } @@ -292,7 +295,7 @@ static int sculpt_sample_detail_size_exec(bContext *C, wmOperator *op) int ss_co[2]; RNA_int_get_array(op->ptr, "location", ss_co); int mode = RNA_enum_get(op->ptr, "mode"); - return sample_detail(C, ss_co[0], ss_co[1], mode); + return sample_detail(C, ss_co, mode); } static int sculpt_sample_detail_size_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e)) @@ -308,12 +311,10 @@ static int sculpt_sample_detail_size_modal(bContext *C, wmOperator *op, const wm switch (event->type) { case LEFTMOUSE: if (event->val == KM_PRESS) { - const int ss_co[2] = {event->xy[0], event->xy[1]}; - int mode = RNA_enum_get(op->ptr, "mode"); - sample_detail(C, ss_co[0], ss_co[1], mode); + sample_detail(C, event->xy, mode); - RNA_int_set_array(op->ptr, "location", ss_co); + RNA_int_set_array(op->ptr, "location", event->xy); WM_cursor_modal_restore(CTX_wm_window(C)); ED_workspace_status_text(C, NULL); WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL); -- cgit v1.2.3