Changeset - r17231:8af772e3e4b6
[Not reviewed]
master
0 1 0
frosch - 14 years ago 2011-02-05 17:53:29
frosch@openttd.org
(svn r21981) -Codechange: Deduplicate the code and unify the bounds of console scrolling.
1 file changed with 15 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/console_gui.cpp
Show inline comments
 
@@ -189,6 +189,17 @@ struct IConsoleWindow : Window
 
		_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 @@ struct IConsoleWindow : Window
 
				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:
0 comments (0 inline, 0 general)