From 41906acb990895831e3b2c39102f41c9b580ae10 Mon Sep 17 00:00:00 2001 From: Dennis Friis Date: Thu, 8 May 2008 00:39:29 +0000 Subject: Allow page up and page down to scroll the chat window, based on patch by fate. --- src/game.cpp | 16 ++++++++++++++++ src/gui/chat.cpp | 27 +++++++++++++++++++++------ src/gui/chat.h | 19 +++++++++++++++---- 3 files changed, 52 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 8096ada4..b12b114f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -532,6 +532,22 @@ void Game::handleInput() } switch (event.key.keysym.sym) { + case SDLK_PAGEUP: + if (chatWindow->isVisible()) + { + chatWindow->scroll(-DEFAULT_CHAT_WINDOW_SCROLL); + used = true; + } + break; + + case SDLK_PAGEDOWN: + if (chatWindow->isVisible()) + { + chatWindow->scroll(DEFAULT_CHAT_WINDOW_SCROLL); + used = true; + } + break; + case SDLK_F1: // In-game Help if (helpWindow->isVisible()) diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 8b53ef98..5e3aaf60 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -410,6 +410,19 @@ ChatWindow::const_msg(CHATSKILL act) return msg; } +void +ChatWindow::scroll(int amount) +{ + if (!isVisible()) + return; + + int range = mScrollArea->getHeight() / 8 * amount; + gcn::Rectangle scr; + scr.y = mScrollArea->getVerticalScrollAmount() + range; + scr.height = abs(range); + mTextOutput->showPart(scr); +} + void ChatWindow::keyPressed(gcn::KeyEvent &event) { @@ -446,11 +459,13 @@ ChatWindow::setInputText(std::string input_str) void ChatWindow::setVisible(bool isVisible) { - Window::setVisible(isVisible); + Window::setVisible(isVisible); - /* - * For whatever reason, if setVisible is called, the mTmpVisible effect - * should be disabled. - */ - mTmpVisible = false; + /* + * For whatever reason, if setVisible is called, the mTmpVisible effect + * should be disabled. + */ + + mTmpVisible = false; } + diff --git a/src/gui/chat.h b/src/gui/chat.h index f2e018a6..0bdc76f1 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -44,7 +44,7 @@ class ScrollArea; #define BY_SERVER 3 #define ACT_WHISPER 4 // getting whispered at -#define ACT_IS 5 // equivalent to "/me" in irc +#define ACT_IS 5 // equivalent to "/me" on IRC #define BY_LOGGER 6 @@ -99,7 +99,9 @@ class ScrollArea; #define RFAIL_GENERIC 0x0a /** should always be zero if failed */ -#define SKILL_FAILED 0x00 +#define SKILL_FAILED 0x00 + +#define DEFAULT_CHAT_WINDOW_SCROLL 7 // 1 means `1/8th of the window size'. struct CHATSKILL { @@ -157,7 +159,7 @@ class ChatWindow : public Window, public gcn::ActionListener, */ bool isInputFocused(); - /* + /** * Determines whether to send a command or an ordinary message, then * contructs packets & sends them. * @@ -196,6 +198,16 @@ class ChatWindow : public Window, public gcn::ActionListener, void setVisible(bool visible); + /** + * Scrolls the chat window + * + * @param amount direction and amount to scroll. Negative numbers scroll + * up, positive numbers scroll down. The absolute amount indicates the + * amount of 1/8ths of chat window real estate that should be scrolled. + */ + void + scroll(int amount); + private: Network *mNetwork; bool mTmpVisible; @@ -224,4 +236,3 @@ class ChatWindow : public Window, public gcn::ActionListener, extern ChatWindow *chatWindow; #endif - -- cgit v1.2.3-60-g2f50