From e54f88f092865cb1239c3fb65a13cb2f9c50fcba Mon Sep 17 00:00:00 2001 From: Yevgeny Makarov Date: Wed, 3 Feb 2021 17:01:14 +0100 Subject: macOS: trackpad scroll direction reversed in list views The 'ui_pan_to_scroll' uses 'WM_event_absolute_delta_y'. For scrolling the List View we need to invert the direction to respect "natural scroll direction" system preferences. Differential Revision: https://developer.blender.org/D10291 --- source/blender/editors/interface/interface_handlers.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index b5aeee3d3bc..97d9b225d3c 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -9005,6 +9005,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi { int retval = WM_UI_HANDLER_CONTINUE; int type = event->type, val = event->val; + int scroll_dir = 1; bool redraw = false; uiList *ui_list = listbox->custom_data; @@ -9021,6 +9022,11 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi if (type == MOUSEPAN) { ui_pan_to_scroll(event, &type, &val); + /* 'ui_pan_to_scroll' gives the absolute direction. */ + if (event->is_direction_inverted) { + scroll_dir = -1; + } + /* If type still is mouse-pan, we call it handled, since delta-y accumulate. */ /* also see wm_event_system.c do_wheel_ui hack */ if (type == MOUSEPAN) { @@ -9115,7 +9121,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi else if (ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE)) { if (dyn_data->height > dyn_data->visual_height) { /* list template will clamp */ - ui_list->list_scroll += (type == WHEELUPMOUSE) ? -1 : 1; + ui_list->list_scroll += scroll_dir * ((type == WHEELUPMOUSE) ? -1 : 1); redraw = true; retval = WM_UI_HANDLER_BREAK; -- cgit v1.2.3 From 8c7b78672e73bf3aadf0f436859eea3d6fd8daeb Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Wed, 3 Feb 2021 13:57:22 -0300 Subject: Fix 'getViewVector' returning inverted vector Despite the wrong value, this change is harmless since the direction of the vector is not really required. --- source/blender/editors/transform/transform_generics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 5b41f6b51bf..504a15b520c 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -69,7 +69,7 @@ void getViewVector(const TransInfo *t, const float coord[3], float vec[3]) { if (t->persp != RV3D_ORTHO) { - sub_v3_v3v3(vec, coord, t->viewinv[3]); + sub_v3_v3v3(vec, t->viewinv[3], coord); } else { copy_v3_v3(vec, t->viewinv[2]); -- cgit v1.2.3 From 9042532085ad8f9d08a94b210c92f89a1cb58013 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Wed, 3 Feb 2021 14:01:40 -0300 Subject: Cleanup: Move and rename 'getViewVector' utility This function is only being used by the constraint code. --- source/blender/editors/transform/transform.h | 2 -- .../blender/editors/transform/transform_constraints.c | 19 +++++++++++++++---- source/blender/editors/transform/transform_generics.c | 13 ------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 91bf2bf8aac..fff7d47cc5b 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -722,8 +722,6 @@ bool calculateCenterActive(TransInfo *t, bool select_only, float r_center[3]); void calculatePropRatio(TransInfo *t); -void getViewVector(const TransInfo *t, const float coord[3], float vec[3]); - void transform_data_ext_rotate(TransData *td, float mat[3][3], bool use_drot); void freeCustomNormalArray(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data); diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 78d3f213102..96671697dc4 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -79,6 +79,17 @@ static void projection_matrix_calc(const TransInfo *t, float r_pmtx[3][3]) mul_m3_m3m3(r_pmtx, t->spacemtx, mat); } +static void view_vector_calc(const TransInfo *t, const float focus[3], float r_vec[3]) +{ + if (t->persp != RV3D_ORTHO) { + sub_v3_v3v3(r_vec, t->viewinv[3], focus); + } + else { + copy_v3_v3(r_vec, t->viewinv[2]); + } + normalize_v3(r_vec); +} + /* ************************** CONSTRAINTS ************************* */ #define CONSTRAIN_EPSILON 0.0001f @@ -218,14 +229,14 @@ static void axisProjection(const TransInfo *t, float norm_center[3]; float plane[3]; - getViewVector(t, t_con_center, norm_center); + view_vector_calc(t, t_con_center, norm_center); cross_v3_v3v3(plane, norm_center, axis); project_v3_v3v3(vec, in, plane); sub_v3_v3v3(vec, in, vec); add_v3_v3v3(v, vec, t_con_center); - getViewVector(t, v, norm); + view_vector_calc(t, v, norm); /* give arbitrary large value if projection is impossible */ factor = dot_v3v3(axis, norm); @@ -342,7 +353,7 @@ static bool isPlaneProjectionViewAligned(const TransInfo *t, const float plane[4 { const float eps = 0.001f; float view_to_plane[3]; - getViewVector(t, t->center_global, view_to_plane); + view_vector_calc(t, t->center_global, view_to_plane); float factor = dot_v3v3(plane, view_to_plane); return fabsf(factor) < eps; @@ -353,7 +364,7 @@ static void planeProjection(const TransInfo *t, const float in[3], float out[3]) float vec[3], factor, norm[3]; add_v3_v3v3(vec, in, t->center_global); - getViewVector(t, vec, norm); + view_vector_calc(t, vec, norm); sub_v3_v3v3(vec, out, in); diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 504a15b520c..f648369bc31 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -64,19 +64,6 @@ #include "transform_orientations.h" #include "transform_snap.h" -/* ************************** Functions *************************** */ - -void getViewVector(const TransInfo *t, const float coord[3], float vec[3]) -{ - if (t->persp != RV3D_ORTHO) { - sub_v3_v3v3(vec, t->viewinv[3], coord); - } - else { - copy_v3_v3(vec, t->viewinv[2]); - } - normalize_v3(vec); -} - /* ************************** GENERICS **************************** */ void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis, short options) -- cgit v1.2.3 From bbd74e9fd4ce014cc98c76eae03563dd0c0d1727 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Wed, 3 Feb 2021 14:34:19 -0300 Subject: Fix T85340: Gizmo rotation inverted (in some perspective angles) This is an old bug (strange not to have been reported before). To define the direction of rotation, the View Vector is used. However, only the projection matrix was being considered, but in perspective mode, the position of the pivot also matters. --- source/blender/editors/transform/transform_constraints.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 96671697dc4..007ef7fd5c2 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -573,7 +573,9 @@ static void constraints_rotation_imp(TransInfo *t, } /* don't flip axis if asked to or if num input */ if (r_angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) { - if (dot_v3v3(r_vec, t->viewinv[2]) > 0.0f) { + float view_vector[3]; + view_vector_calc(t, t->center_global, view_vector); + if (dot_v3v3(r_vec, view_vector) > 0.0f) { *r_angle = -(*r_angle); } } -- cgit v1.2.3 From 5eb5a7f4b7d7c5228ec9596b35e7f2e317aad97d Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Wed, 3 Feb 2021 14:48:08 -0300 Subject: Fix unreported: Rotation Gizmo "C" influenced by custom orientation The white rotation Gizmo should always use the View orientation. Before, if you set an orientation for the gizmo other than the default, that gizmo would behave like the contraint Z Gizmo. --- source/blender/editors/transform/transform_gizmo_3d.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 166fded5209..be29c1cda02 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -1865,7 +1865,10 @@ static void WIDGETGROUP_gizmo_invoke_prepare(const bContext *C, PropertyRNA *prop_orient_type = RNA_struct_find_property(ptr, "orient_type"); const TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get_from_flag( scene, ggd->twtype_init); - if (orient_slot == &scene->orientation_slots[SCE_ORIENT_DEFAULT]) { + if ((gz == ggd->gizmos[MAN_AXIS_ROT_C]) || + (orient_slot == &scene->orientation_slots[SCE_ORIENT_DEFAULT])) { + /* #MAN_AXIS_ROT_C always uses the #V3D_ORIENT_VIEW orientation, + * optionally we could set this orientation instead of unset the property. */ RNA_property_unset(ptr, prop_orient_type); } else { -- cgit v1.2.3