Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarley Acheson <harley.acheson@gmail.com>2021-01-25 02:16:05 +0300
committerHarley Acheson <harley.acheson@gmail.com>2021-01-25 02:16:05 +0300
commitcf6d17a6aa421e0038fc1f8e60e3f1f708887c3e (patch)
tree30eeb91c88f0c3c4552fcf2255582d439e69b899 /source/blender
parent2fec46c3e614c10cadef945855747d0f3f251fd4 (diff)
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
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c11
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.c14
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c11
-rw-r--r--source/blender/windowmanager/gizmo/WM_gizmo_types.h3
-rw-r--r--source/blender/windowmanager/gizmo/wm_gizmo_fn.h3
5 files changed, 39 insertions, 3 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 eb40500d011..cbca230da7e 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c
@@ -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);
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 2bf63955855..91e5b61a16d 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -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);
}
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
index 59cafd9367f..5a1b24d18cc 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
@@ -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);
}
diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_types.h b/source/blender/windowmanager/gizmo/WM_gizmo_types.h
index 8f84c02be12..0588fd2b2ce 100644
--- a/source/blender/windowmanager/gizmo/WM_gizmo_types.h
+++ b/source/blender/windowmanager/gizmo/WM_gizmo_types.h
@@ -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;
diff --git a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h
index 418e848e35b..4eea7cc6dcf 100644
--- a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h
+++ b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h
@@ -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 *);