UI: Gizmo Tooltip Positioning

Position Gizmo tooltips below their bounds so they do not obscure the content.

Differential Revision: https://developer.blender.org/D9793

Reviewed by Julian Eisel
This commit is contained in:
Harley Acheson 2021-01-24 15:16:05 -08:00
parent 2fec46c3e6
commit cf6d17a6aa
Notes: blender-bot 2023-02-14 04:10:15 +01:00
Referenced by commit 9175911ffa, Fix spin-gizmo button tool-tip placement
Referenced by issue #87390, Regression: Quad View Gizmo Tooltips at wrong position
Referenced by issue #86880, Cycles: Bevel node stop working after changing world shader
Referenced by issue #86880, Cycles: Bevel node stop working after changing world shader
Referenced by issue #85426, VSE: Speed Strip - Stretch to Input Strip Length has no effect
Referenced by issue #85054, UNDO/REDO system is broken(Python handlers are swapped)
5 changed files with 39 additions and 3 deletions

View File

@ -320,6 +320,16 @@ 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)
{
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;
}
static void gizmo_button2d_free(wmGizmo *gz)
{
ButtonGizmo2D *shape = (ButtonGizmo2D *)gz;
@ -346,6 +356,7 @@ static void GIZMO_GT_button_2d(wmGizmoType *gzt)
gzt->draw_select = gizmo_button2d_draw_select;
gzt->test_select = gizmo_button2d_test_select;
gzt->cursor_get = gizmo_button2d_cursor_get;
gzt->screen_bounds_get = gizmo_button2d_bounds;
gzt->free = gizmo_button2d_free;
gzt->struct_size = sizeof(ButtonGizmo2D);

View File

@ -1456,15 +1456,23 @@ ARegion *UI_tooltip_create_from_gizmo(bContext *C, wmGizmo *gz)
{
wmWindow *win = CTX_wm_window(C);
const float aspect = 1.0f;
float init_position[2];
float init_position[2] = {win->eventstate->x, win->eventstate->y};
uiTooltipData *data = ui_tooltip_data_from_gizmo(C, gz);
if (data == NULL) {
return NULL;
}
init_position[0] = win->eventstate->x;
init_position[1] = win->eventstate->y;
/* TODO(harley):
* Julian preferred that the gizmo callback return the 3D bounding box
* which we then project to 2D here. Would make a nice improvement.
*/
if (gz->type->screen_bounds_get) {
rcti bounds;
gz->type->screen_bounds_get(C, gz, &bounds);
init_position[0] = bounds.xmin;
init_position[1] = bounds.ymin;
}
return ui_tooltip_create_with_data(C, data, init_position, NULL, aspect);
}

View File

@ -352,6 +352,16 @@ static int gizmo_axis_cursor_get(wmGizmo *UNUSED(gz))
return WM_CURSOR_DEFAULT;
}
static void gizmo_axis_bounds(bContext *C, wmGizmo *gz, rcti *r_bounding_box)
{
ScrArea *area = CTX_wm_area(C);
const float rad = (40.0f * U.dpi_fac);
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;
}
void VIEW3D_GT_navigate_rotate(wmGizmoType *gzt)
{
/* identifiers */
@ -361,6 +371,7 @@ void VIEW3D_GT_navigate_rotate(wmGizmoType *gzt)
gzt->draw = gizmo_axis_draw;
gzt->test_select = gizmo_axis_test_select;
gzt->cursor_get = gizmo_axis_cursor_get;
gzt->screen_bounds_get = gizmo_axis_bounds;
gzt->struct_size = sizeof(wmGizmo);
}

View File

@ -371,6 +371,9 @@ typedef struct wmGizmoType {
*/
wmGizmoFnMatrixBasisGet matrix_basis_get;
/** Returns screen-space bounding box. Needed for nice tooltip placement. */
wmGizmoFnScreenBoundsGet screen_bounds_get;
/** Activate a gizmo state when the user clicks on it. */
wmGizmoFnInvoke invoke;

View File

@ -59,6 +59,9 @@ typedef int (*wmGizmoFnModal)(struct bContext *,
eWM_GizmoFlagTweak);
typedef void (*wmGizmoFnPropertyUpdate)(struct wmGizmo *, struct wmGizmoProperty *);
typedef void (*wmGizmoFnMatrixBasisGet)(const struct wmGizmo *, float[4][4]);
typedef void (*wmGizmoFnScreenBoundsGet)(struct bContext *,
struct wmGizmo *,
rcti *r_bounding_box);
typedef int (*wmGizmoFnInvoke)(struct bContext *, struct wmGizmo *, const struct wmEvent *);
typedef void (*wmGizmoFnExit)(struct bContext *, struct wmGizmo *, const bool);
typedef int (*wmGizmoFnCursorGet)(struct wmGizmo *);