Changeset - r22878:6f6e7b4ccd3c
[Not reviewed]
master
0 1 0
Alexander Weiss - 6 years ago 2018-05-29 08:44:33
ik@alexanderweiss.nl
Fix: [OSX] Minor 2D scrolling fixes (#6793)

* Codechange: Check for scrollwheel_scrolling first when scrolling viewport instead of first setting normal values and then overwriting them.

* Fix #6558: [OSX] Reset 2D scrolling values when not scrolling to prevent unintended window focus changes

* Change: [OSX] Include initial scrolling movement when using 2D scrolling to make it more responsive

* Fix: [OSX] 2D scrolling not working when setting viewport scroll behaviour to use left mouse button
1 file changed with 26 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/window.cpp
Show inline comments
 
@@ -2454,26 +2454,26 @@ static EventState HandleViewportScroll()
 
		const Vehicle *veh = Vehicle::Get(_last_scroll_window->viewport->follow_vehicle);
 
		ScrollMainWindowTo(veh->x_pos, veh->y_pos, veh->z_pos, true); // This also resets follow_vehicle
 
		return ES_NOT_HANDLED;
 
	}
 

	
 
	Point delta;
 
	if (_settings_client.gui.scroll_mode != VSM_VIEWPORT_RMB_FIXED) {
 
		delta.x = -_cursor.delta.x;
 
		delta.y = -_cursor.delta.y;
 
	} else {
 
		delta.x = _cursor.delta.x;
 
		delta.y = _cursor.delta.y;
 
	}
 

	
 
	if (scrollwheel_scrolling) {
 
		/* We are using scrollwheels for scrolling */
 
		delta.x = _cursor.h_wheel;
 
		delta.y = _cursor.v_wheel;
 
		_cursor.v_wheel = 0;
 
		_cursor.h_wheel = 0;
 
	} else {
 
		if (_settings_client.gui.scroll_mode != VSM_VIEWPORT_RMB_FIXED) {
 
			delta.x = -_cursor.delta.x;
 
			delta.y = -_cursor.delta.y;
 
		} else {
 
			delta.x = _cursor.delta.x;
 
			delta.y = _cursor.delta.y;
 
		}
 
	}
 

	
 
	/* Create a scroll-event and send it to the window */
 
	if (delta.x != 0 || delta.y != 0) _last_scroll_window->OnScroll(delta);
 

	
 
	_cursor.delta.x = 0;
 
@@ -2863,13 +2863,18 @@ static void MouseLoop(MouseClick click, 
 

	
 
		/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
 
		if (vp == NULL) DispatchMouseWheelEvent(w, w->nested_root->GetWidgetFromPos(x - w->left, y - w->top), mousewheel);
 
	}
 

	
 
	if (vp != NULL) {
 
		if (scrollwheel_scrolling) click = MC_RIGHT; // we are using the scrollwheel in a viewport, so we emulate right mouse button
 
		if (scrollwheel_scrolling && !(w->flags & WF_DISABLE_VP_SCROLL)) {
 
			_scrolling_viewport = true;
 
			_cursor.fix_at = true;
 
			return;
 
		}
 

	
 
		switch (click) {
 
			case MC_DOUBLE_LEFT:
 
			case MC_LEFT:
 
				if (HandleViewportClicked(vp, x, y)) return;
 
				if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
 
						_settings_client.gui.scroll_mode == VSM_MAP_LMB) {
 
@@ -2882,16 +2887,12 @@ static void MouseLoop(MouseClick click, 
 
			case MC_RIGHT:
 
				if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
 
						_settings_client.gui.scroll_mode != VSM_MAP_LMB) {
 
					_scrolling_viewport = true;
 
					_cursor.fix_at = (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED ||
 
							_settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED);
 

	
 
					/* clear 2D scrolling caches before we start a 2D scroll */
 
					_cursor.h_wheel = 0;
 
					_cursor.v_wheel = 0;
 
					return;
 
				}
 
				break;
 

	
 
			default:
 
				break;
 
@@ -2900,25 +2901,33 @@ static void MouseLoop(MouseClick click, 
 

	
 
	if (vp == NULL || (w->flags & WF_DISABLE_VP_SCROLL)) {
 
		switch (click) {
 
			case MC_LEFT:
 
			case MC_DOUBLE_LEFT:
 
				DispatchLeftClickEvent(w, x - w->left, y - w->top, click == MC_DOUBLE_LEFT ? 2 : 1);
 
				break;
 
				return;
 

	
 
			default:
 
				if (!scrollwheel_scrolling || w == NULL || w->window_class != WC_SMALLMAP) break;
 
				/* We try to use the scrollwheel to scroll since we didn't touch any of the buttons.
 
				 * Simulate a right button click so we can get started. */
 
				FALLTHROUGH;
 

	
 
			case MC_RIGHT: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
 

	
 
			case MC_HOVER: DispatchHoverEvent(w, x - w->left, y - w->top); break;
 
			case MC_RIGHT:
 
				DispatchRightClickEvent(w, x - w->left, y - w->top);
 
				return;
 

	
 
			case MC_HOVER:
 
				DispatchHoverEvent(w, x - w->left, y - w->top);
 
				break;
 
		}
 
	}
 

	
 
	/* We're not doing anything with 2D scrolling, so reset the value.  */
 
	_cursor.h_wheel = 0;
 
	_cursor.v_wheel = 0;
 
}
 

	
 
/**
 
 * Handle a mouse event from the video driver
 
 */
 
void HandleMouseEvents()
0 comments (0 inline, 0 general)