mirror of https://github.com/OpenTTD/OpenTTD
Change: Use floats for tracking 2D scrolling
This ensures the smoothest experience possible when dragging map around with 2D scrolling.pull/13172/head
parent
25cf382971
commit
32dfb37b9d
|
@ -127,10 +127,10 @@ struct CursorVars {
|
|||
int wheel; ///< mouse wheel movement
|
||||
bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling)
|
||||
|
||||
/* We need two different vars to keep track of how far the scrollwheel moved.
|
||||
* OSX uses this for scrolling around the map. */
|
||||
int v_wheel;
|
||||
int h_wheel;
|
||||
/* 2D wheel scrolling for moving around the map */
|
||||
bool wheel_moved;
|
||||
float v_wheel;
|
||||
float h_wheel;
|
||||
|
||||
/* Mouse appearance */
|
||||
std::vector<CursorSprite> sprites; ///< Sprites comprising cursor.
|
||||
|
|
|
@ -763,8 +763,9 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
|||
deltaY = [ event deltaY ] * 5;
|
||||
}
|
||||
|
||||
_cursor.h_wheel -= (int)(deltaX * _settings_client.gui.scrollwheel_multiplier);
|
||||
_cursor.v_wheel -= (int)(deltaY * _settings_client.gui.scrollwheel_multiplier);
|
||||
_cursor.h_wheel -= static_cast<float>(deltaX * _settings_client.gui.scrollwheel_multiplier);
|
||||
_cursor.v_wheel -= static_cast<float>(deltaY * _settings_client.gui.scrollwheel_multiplier);
|
||||
_cursor.wheel_moved = true;
|
||||
}
|
||||
|
||||
- (void)magnifyWithEvent:(NSEvent *)event
|
||||
|
|
|
@ -2355,7 +2355,7 @@ static EventState HandleActiveWidget()
|
|||
*/
|
||||
static EventState HandleViewportScroll()
|
||||
{
|
||||
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
|
||||
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && _cursor.wheel_moved;
|
||||
|
||||
if (!_scrolling_viewport) return ES_NOT_HANDLED;
|
||||
|
||||
|
@ -2381,10 +2381,13 @@ static EventState HandleViewportScroll()
|
|||
Point delta;
|
||||
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;
|
||||
/* Use the integer part for movement */
|
||||
delta.x = static_cast<int>(_cursor.h_wheel);
|
||||
delta.y = static_cast<int>(_cursor.v_wheel);
|
||||
/* Keep the fractional part so that subtle movement is accumulated */
|
||||
float temp;
|
||||
_cursor.v_wheel = std::modf(_cursor.v_wheel, &temp);
|
||||
_cursor.h_wheel = std::modf(_cursor.h_wheel, &temp);
|
||||
} else {
|
||||
if (_settings_client.gui.scroll_mode != VSM_VIEWPORT_RMB_FIXED) {
|
||||
delta.x = -_cursor.delta.x;
|
||||
|
@ -2400,6 +2403,7 @@ static EventState HandleViewportScroll()
|
|||
|
||||
_cursor.delta.x = 0;
|
||||
_cursor.delta.y = 0;
|
||||
_cursor.wheel_moved = false;
|
||||
return ES_HANDLED;
|
||||
}
|
||||
|
||||
|
@ -2791,7 +2795,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
|||
|
||||
HandleMouseOver();
|
||||
|
||||
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
|
||||
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && _cursor.wheel_moved;
|
||||
if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return;
|
||||
|
||||
int x = _cursor.pos.x;
|
||||
|
@ -2870,8 +2874,9 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
|||
}
|
||||
|
||||
/* We're not doing anything with 2D scrolling, so reset the value. */
|
||||
_cursor.h_wheel = 0;
|
||||
_cursor.v_wheel = 0;
|
||||
_cursor.h_wheel = 0.0f;
|
||||
_cursor.v_wheel = 0.0f;
|
||||
_cursor.wheel_moved = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue