summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/window.cpp23
-rw-r--r--src/window_gui.h1
2 files changed, 23 insertions, 1 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 2c12dbe8e..69fccf9d3 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -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 */
diff --git a/src/window_gui.h b/src/window_gui.h
index 5d15d8f5a..7fc0ebe72 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -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 {