summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-10-13 08:34:10 +0000
committerfrosch <frosch@openttd.org>2012-10-13 08:34:10 +0000
commit2abe4ac280dd0495bceee34cf94bab2c6d3d3230 (patch)
tree62f44c444cb835a9f4c934f9206dfabddf6f3cb5 /src
parent9d877e888aaefcbd62b9371b898a28afab434dcf (diff)
downloadopenttd-2abe4ac280dd0495bceee34cf94bab2c6d3d3230.tar.xz
(svn r24589) -Codechange: Return early in HandleAutoscroll() instead of nesting ifs.
Diffstat (limited to 'src')
-rw-r--r--src/window.cpp48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/window.cpp b/src/window.cpp
index ad04818ee..1abf143f2 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -2290,31 +2290,33 @@ static int _input_events_this_tick = 0;
*/
static void HandleAutoscroll()
{
- if (_settings_client.gui.autoscroll && _game_mode != GM_MENU && !HasModalProgress()) {
- int x = _cursor.pos.x;
- int y = _cursor.pos.y;
- Window *w = FindWindowFromPt(x, y);
- if (w == NULL || w->flags & WF_DISABLE_VP_SCROLL) return;
- ViewPort *vp = IsPtInWindowViewport(w, x, y);
- if (vp != NULL) {
- x -= vp->left;
- y -= vp->top;
-
- /* here allows scrolling in both x and y axis */
+ if (_game_mode == GM_MENU || HasModalProgress()) return;
+ if (!_settings_client.gui.autoscroll) return;
+
+ int x = _cursor.pos.x;
+ int y = _cursor.pos.y;
+ Window *w = FindWindowFromPt(x, y);
+ if (w == NULL || w->flags & WF_DISABLE_VP_SCROLL) return;
+
+ ViewPort *vp = IsPtInWindowViewport(w, x, y);
+ if (vp == NULL) return;
+
+ x -= vp->left;
+ y -= vp->top;
+
+ /* here allows scrolling in both x and y axis */
#define scrollspeed 3
- if (x - 15 < 0) {
- w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom);
- } else if (15 - (vp->width - x) > 0) {
- w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom);
- }
- if (y - 15 < 0) {
- w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom);
- } else if (15 - (vp->height - y) > 0) {
- w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom);
- }
-#undef scrollspeed
- }
+ if (x - 15 < 0) {
+ w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom);
+ } else if (15 - (vp->width - x) > 0) {
+ w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom);
+ }
+ if (y - 15 < 0) {
+ w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom);
+ } else if (15 - (vp->height - y) > 0) {
+ w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom);
}
+#undef scrollspeed
}
enum MouseClick {