diff options
author | frosch <frosch@openttd.org> | 2021-05-09 16:42:36 +0200 |
---|---|---|
committer | frosch <github@elsenhans.name> | 2021-05-12 23:22:41 +0200 |
commit | 22567a1f43d29a7596b9ef88441d5a65776fa2c8 (patch) | |
tree | d20fd1334d03c74a65a3778638da39c34c49c340 /src/viewport.cpp | |
parent | aba239479b6e75990cc914331bd2d735b8918628 (diff) | |
download | openttd-22567a1f43d29a7596b9ef88441d5a65776fa2c8.tar.xz |
Codechange: use iterators instead of 'subranges' when iterating from a specific window.
Using iterators makes it easier to include or exclude the start window in the iteration.
Diffstat (limited to 'src/viewport.cpp')
-rw-r--r-- | src/viewport.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/viewport.cpp b/src/viewport.cpp index 303e02760..3e4c2d273 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -266,35 +266,36 @@ void InitializeWindowViewport(Window *w, int x, int y, static Point _vp_move_offs; -static void DoSetViewportPosition(const Window *w, int left, int top, int width, int height) +static void DoSetViewportPosition(Window::IteratorToFront it, int left, int top, int width, int height) { - for (const Window *w : Window::IterateFromBack(w)) { + for (; !it.IsEnd(); ++it) { + const Window *w = *it; if (left + width > w->left && w->left + w->width > left && top + height > w->top && w->top + w->height > top) { if (left < w->left) { - DoSetViewportPosition(w, left, top, w->left - left, height); - DoSetViewportPosition(w, left + (w->left - left), top, width - (w->left - left), height); + DoSetViewportPosition(it, left, top, w->left - left, height); + DoSetViewportPosition(it, left + (w->left - left), top, width - (w->left - left), height); return; } if (left + width > w->left + w->width) { - DoSetViewportPosition(w, left, top, (w->left + w->width - left), height); - DoSetViewportPosition(w, left + (w->left + w->width - left), top, width - (w->left + w->width - left), height); + DoSetViewportPosition(it, left, top, (w->left + w->width - left), height); + DoSetViewportPosition(it, left + (w->left + w->width - left), top, width - (w->left + w->width - left), height); return; } if (top < w->top) { - DoSetViewportPosition(w, left, top, width, (w->top - top)); - DoSetViewportPosition(w, left, top + (w->top - top), width, height - (w->top - top)); + DoSetViewportPosition(it, left, top, width, (w->top - top)); + DoSetViewportPosition(it, left, top + (w->top - top), width, height - (w->top - top)); return; } if (top + height > w->top + w->height) { - DoSetViewportPosition(w, left, top, width, (w->top + w->height - top)); - DoSetViewportPosition(w, left, top + (w->top + w->height - top), width, height - (w->top + w->height - top)); + DoSetViewportPosition(it, left, top, width, (w->top + w->height - top)); + DoSetViewportPosition(it, left, top + (w->top + w->height - top), width, height - (w->top + w->height - top)); return; } @@ -380,7 +381,11 @@ static void SetViewportPosition(Window *w, int x, int y) i = top + height - _screen.height; if (i >= 0) height -= i; - if (height > 0) DoSetViewportPosition(w->z_front, left, top, width, height); + if (height > 0) { + Window::IteratorToFront it(w); + ++it; + DoSetViewportPosition(it, left, top, width, height); + } } } |