diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-04-19 10:17:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-04-19 10:17:49 +0300 |
commit | 9175911ffabefcd00f15d847ffdf8afe5efadb10 (patch) | |
tree | 3fb02af6d086fcdba0725010f93a20e8ae4486d9 /source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c | |
parent | 063c9938f1ecb52ddb697096918974485ef81da3 (diff) |
Fix spin-gizmo button tool-tip placement
gizmo_button2d_bounds result wasn't valid when the gizmo was part
of a 3D gizmo group.
Regression in cf6d17a6aa421e0038fc1f8e60e3f1f708887c3e
Diffstat (limited to 'source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c')
-rw-r--r-- | source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c index f4c4e4eb2ac..d99ce25451c 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c @@ -320,14 +320,44 @@ static int gizmo_button2d_cursor_get(wmGizmo *gz) return WM_CURSOR_DEFAULT; } -static void gizmo_button2d_bounds(bContext *C, wmGizmo *gz, rcti *r_bounding_box) +static bool gizmo_button2d_bounds(bContext *C, wmGizmo *gz, rcti *r_bounding_box) { ScrArea *area = CTX_wm_area(C); float rad = CIRCLE_RESOLUTION * U.dpi_fac / 2.0f; - r_bounding_box->xmin = gz->matrix_basis[3][0] + area->totrct.xmin - rad; - r_bounding_box->ymin = gz->matrix_basis[3][1] + area->totrct.ymin - rad; - r_bounding_box->xmax = r_bounding_box->xmin + rad; - r_bounding_box->ymax = r_bounding_box->ymin + rad; + const float *co = NULL; + float matrix_final[4][4]; + float co_proj[3]; + WM_gizmo_calc_matrix_final(gz, matrix_final); + + if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) { + ARegion *region = CTX_wm_region(C); + if (ED_view3d_project_float_global(region, matrix_final[3], co_proj, V3D_PROJ_TEST_NOP) == + V3D_PROJ_RET_OK) { + float matrix_final_no_offset[4][4]; + const RegionView3D *rv3d = region->regiondata; + WM_gizmo_calc_matrix_final_no_offset(gz, matrix_final_no_offset); + const float factor = ED_view3d_pixel_size_no_ui_scale(rv3d, matrix_final_no_offset[3]) / + ED_view3d_pixel_size_no_ui_scale(rv3d, matrix_final[3]); + /* It's possible (although unlikely) `matrix_final_no_offset` is behind the view. + * `matrix_final` has already been projected so both can't be negative. */ + if (factor > 0.0f) { + rad *= factor; + } + co = co_proj; + } + } + else { + co = matrix_final[3]; + } + + if (co != NULL) { + r_bounding_box->xmin = co[0] + area->totrct.xmin - rad; + r_bounding_box->ymin = co[1] + area->totrct.ymin - rad; + r_bounding_box->xmax = r_bounding_box->xmin + rad; + r_bounding_box->ymax = r_bounding_box->ymin + rad; + return true; + } + return false; } static void gizmo_button2d_free(wmGizmo *gz) |