Fix T62875: Tooltips behave erratically with view gizmos

Improvements to behavior for gizmo tool-tips.

- 2D gizmos no longer cancel tool-tips on cursor motion
  (matching the behavior of UI widgets).

- 3D gizmos still close on motion since 3D gizmos may have a large
  on-screen area which would cause them to stay visible even after the
  cursor has been moved a large distance. The motion threshold is used
  so they don't close on unintended cursor motion.

- Changing highlighted gizmo now cancels the tool-tip & resets the timer.
This commit is contained in:
2019-06-11 11:43:48 +10:00
parent a0608340ae
commit 6868202899
4 changed files with 32 additions and 7 deletions

View File

@@ -787,6 +787,8 @@ typedef struct wmTooltipState {
bool *r_exit_on_event);
/** Exit on any event, not needed for buttons since their highlight state is used. */
bool exit_on_event;
/** Cursor location at the point of tooltip creation. */
int event_xy[2];
/** Pass, use when we want multiple tips, count down to zero. */
int pass;
} wmTooltipState;

View File

@@ -1144,10 +1144,15 @@ struct ARegion *WM_gizmomap_tooltip_init(struct bContext *C,
bool *r_exit_on_event)
{
wmGizmoMap *gzmap = ar->gizmo_map;
*r_exit_on_event = true;
*r_exit_on_event = false;
if (gzmap) {
wmGizmo *gz = gzmap->gzmap_context.highlight;
if (gz) {
wmGizmoGroup *gzgroup = gz->parent_gzgroup;
if ((gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) != 0) {
/* On screen area of 3D gizmos may be large, exit on cursor motion. */
*r_exit_on_event = true;
}
return UI_tooltip_create_from_gizmo(C, gz);
}
}

View File

@@ -2784,11 +2784,25 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
}
if (handle_highlight) {
int part;
struct {
wmGizmo *gz;
int part;
} prev = {
.gz = gz,
.part = gz ? gz->highlight_part : 0,
};
int part = -1;
gz = wm_gizmomap_highlight_find(gzmap, C, event, &part);
if (wm_gizmomap_highlight_set(gzmap, C, gz, part) && gz != NULL) {
if (U.flag & USER_TOOLTIPS) {
WM_tooltip_timer_init(C, CTX_wm_window(C), region, WM_gizmomap_tooltip_init);
if ((gz == NULL) || (prev.gz != gz) || (prev.part != part)) {
WM_tooltip_clear(C, CTX_wm_window(C));
}
if (wm_gizmomap_highlight_set(gzmap, C, gz, part)) {
if (gz != NULL) {
if (U.flag & USER_TOOLTIPS) {
WM_tooltip_timer_init(C, CTX_wm_window(C), region, WM_gizmomap_tooltip_init);
}
}
}
}
@@ -3278,8 +3292,10 @@ void wm_event_do_handlers(bContext *C)
/* Clear tool-tip on mouse move. */
if (screen->tool_tip && screen->tool_tip->exit_on_event) {
if (ISMOUSE(event->type)) {
WM_tooltip_clear(C, win);
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
if (len_manhattan_v2v2_int(screen->tool_tip->event_xy, &event->x) > U.move_threshold) {
WM_tooltip_clear(C, win);
}
}
}

View File

@@ -22,6 +22,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
@@ -116,6 +117,7 @@ void WM_tooltip_init(bContext *C, wmWindow *win)
&screen->tool_tip->pass,
&pass_delay,
&screen->tool_tip->exit_on_event);
copy_v2_v2_int(screen->tool_tip->event_xy, &win->eventstate->x);
if (pass_prev != screen->tool_tip->pass) {
/* The pass changed, add timer for next pass. */
wmWindowManager *wm = CTX_wm_manager(C);