mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 15:41:15 +00:00
(svn r20118) -Add: Detect if the mouse has been hovering over the same point.
This commit is contained in:
parent
dd5bf70f20
commit
9aef7b8c3d
@ -59,6 +59,7 @@ byte _scroller_click_timeout;
|
||||
|
||||
bool _scrolling_scrollbar; ///< A scrollbar is being scrolled with the mouse.
|
||||
bool _scrolling_viewport; ///< A viewport is being scrolled with the mouse.
|
||||
bool _mouse_hovering; ///< The mouse is hovering over the same point.
|
||||
|
||||
SpecialMouseMode _special_mouse_mode; ///< Mode of the mouse.
|
||||
|
||||
@ -1287,6 +1288,7 @@ void InitWindowSystem()
|
||||
_focused_window = NULL;
|
||||
_mouseover_last_w = NULL;
|
||||
_scrolling_viewport = false;
|
||||
_mouse_hovering = false;
|
||||
|
||||
NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
|
||||
}
|
||||
@ -2019,11 +2021,13 @@ enum MouseClick {
|
||||
MC_LEFT,
|
||||
MC_RIGHT,
|
||||
MC_DOUBLE_LEFT,
|
||||
MC_HOVER,
|
||||
|
||||
MAX_OFFSET_DOUBLE_CLICK = 5, ///< How much the mouse is allowed to move to call it a double click
|
||||
TIME_BETWEEN_DOUBLE_CLICK = 500, ///< Time between 2 left clicks before it becoming a double click, in ms
|
||||
MAX_OFFSET_HOVER = 5, ///< Maximum mouse movement before stopping a hover event.
|
||||
TIME_HOVER = 1000, ///< Time required to activate a hover event, in ms.
|
||||
};
|
||||
|
||||
extern EventState VpHandlePlaceSizingDrag();
|
||||
|
||||
static void ScrollMainViewport(int x, int y)
|
||||
@ -2216,6 +2220,23 @@ void HandleMouseEvents()
|
||||
_input_events_this_tick++;
|
||||
}
|
||||
|
||||
static int hover_time = 0;
|
||||
static Point hover_pos = {0, 0};
|
||||
|
||||
if (click != MC_NONE || mousewheel != 0 || _left_button_down || _right_button_down ||
|
||||
hover_pos.x == 0 || abs(_cursor.pos.x - hover_pos.x) >= MAX_OFFSET_HOVER ||
|
||||
hover_pos.y == 0 || abs(_cursor.pos.y - hover_pos.y) >= MAX_OFFSET_HOVER) {
|
||||
hover_pos = _cursor.pos;
|
||||
hover_time = _realtime_tick;
|
||||
_mouse_hovering = false;
|
||||
} else {
|
||||
if (hover_time != 0 && _realtime_tick - hover_time > TIME_HOVER) {
|
||||
click = MC_HOVER;
|
||||
_input_events_this_tick++;
|
||||
_mouse_hovering = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle sprite picker before any GUI interaction */
|
||||
if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW && _newgrf_debug_sprite_picker.click_time != _realtime_tick) {
|
||||
/* Next realtime tick? Then redraw has finished */
|
||||
|
@ -913,6 +913,7 @@ extern byte _scroller_click_timeout;
|
||||
|
||||
extern bool _scrolling_scrollbar;
|
||||
extern bool _scrolling_viewport;
|
||||
extern bool _mouse_hovering;
|
||||
|
||||
/** Mouse modes. */
|
||||
enum SpecialMouseMode {
|
||||
|
Loading…
Reference in New Issue
Block a user