Mercurial > hg > openttd
changeset 17241:93cee045fcfb draft
(svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
author | frosch <frosch@openttd.org> |
---|---|
date | Sat, 05 Feb 2011 17:53:29 +0000 |
parents | b62138a80b9a |
children | d4e5d46b857a |
files | src/console_gui.cpp |
diffstat | 1 files changed, 15 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -189,6 +189,17 @@ _iconsole_mode = ICONSOLE_CLOSED; } + /** + * Scroll the content of the console. + * @param amount Number of lines to scroll back. + */ + void Scroll(int amount) + { + int max_scroll = max<int>(0, IConsoleLine::size + 1 - this->height / this->line_height); + IConsoleWindow::scroll = Clamp<int>(IConsoleWindow::scroll + amount, 0, max_scroll); + this->SetDirty(); + } + virtual void OnPaint() { const int right = this->width - 5; @@ -245,39 +256,19 @@ break; case WKC_SHIFT | WKC_PAGEDOWN: - if (IConsoleWindow::scroll - scroll_height < 0) { - IConsoleWindow::scroll = 0; - } else { - IConsoleWindow::scroll -= scroll_height; - } - this->SetDirty(); + this->Scroll(-scroll_height); break; case WKC_SHIFT | WKC_PAGEUP: - if (IConsoleWindow::scroll + scroll_height > IConsoleLine::size - scroll_height) { - IConsoleWindow::scroll = IConsoleLine::size - scroll_height; - } else { - IConsoleWindow::scroll += scroll_height; - } - this->SetDirty(); + this->Scroll(scroll_height); break; case WKC_SHIFT | WKC_DOWN: - if (IConsoleWindow::scroll <= 0) { - IConsoleWindow::scroll = 0; - } else { - --IConsoleWindow::scroll; - } - this->SetDirty(); + this->Scroll(-1); break; case WKC_SHIFT | WKC_UP: - if (IConsoleWindow::scroll >= IConsoleLine::size) { - IConsoleWindow::scroll = IConsoleLine::size; - } else { - ++IConsoleWindow::scroll; - } - this->SetDirty(); + this->Scroll(1); break; case WKC_BACKQUOTE: