Changeset - r28546:63fce19369a1
[Not reviewed]
master
0 1 0
Patric Stout - 3 months ago 2024-01-21 20:52:44
truebrain@openttd.org
Fix: smooth-scrolling large distances didn't got smoothly in one direction (#11861)
1 file changed with 14 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/viewport.cpp
Show inline comments
 
@@ -1894,9 +1894,20 @@ void UpdateViewportPosition(Window *w)
 
		if (delta_x != 0 || delta_y != 0) {
 
			if (_settings_client.gui.smooth_scroll) {
 
				int max_scroll = Map::ScaleBySize1D(512 * ZOOM_LVL_BASE);
 
				/* Not at our desired position yet... */
 
				w->viewport->scrollpos_x += Clamp(DivAwayFromZero(delta_x, 4), -max_scroll, max_scroll);
 
				w->viewport->scrollpos_y += Clamp(DivAwayFromZero(delta_y, 4), -max_scroll, max_scroll);
 

	
 
				int delta_x_clamped;
 
				int delta_y_clamped;
 

	
 
				if (abs(delta_x) > abs(delta_y)) {
 
					delta_x_clamped = Clamp(DivAwayFromZero(delta_x, 4), -max_scroll, max_scroll);
 
					delta_y_clamped = delta_y * delta_x_clamped / delta_x;
 
				} else {
 
					delta_y_clamped = Clamp(DivAwayFromZero(delta_y, 4), -max_scroll, max_scroll);
 
					delta_x_clamped = delta_x * delta_y_clamped / delta_y;
 
				}
 

	
 
				w->viewport->scrollpos_x += delta_x_clamped;
 
				w->viewport->scrollpos_y += delta_y_clamped;
 
			} else {
 
				w->viewport->scrollpos_x = w->viewport->dest_scrollpos_x;
 
				w->viewport->scrollpos_y = w->viewport->dest_scrollpos_y;
0 comments (0 inline, 0 general)