Merge pull request #31 from invisiblek/master

Add support for PAGEUP and PAGEDOWN, contributed by invisiblek.
This commit is contained in:
Aloshi 2012-11-11 18:57:51 -08:00
commit 431958f629
4 changed files with 32 additions and 5 deletions

View file

@ -58,6 +58,12 @@ void InputManager::processEvent(SDL_Event* event)
case SDLK_DOWN: case SDLK_DOWN:
button = DOWN; button = DOWN;
break; break;
case SDLK_PAGEUP:
button = PAGEUP;
break;
case SDLK_PAGEDOWN:
button = PAGEDOWN;
break;
case SDLK_RETURN: case SDLK_RETURN:
button = BUTTON1; button = BUTTON1;
break; break;

View file

@ -17,7 +17,7 @@ namespace InputManager {
void loadConfig(); void loadConfig();
//enum for identifying input, regardless of configuration //enum for identifying input, regardless of configuration
enum InputButton { UNKNOWN, UP, DOWN, LEFT, RIGHT, BUTTON1, BUTTON2, MENU, SELECT}; enum InputButton { UNKNOWN, UP, DOWN, PAGEUP, PAGEDOWN, LEFT, RIGHT, BUTTON1, BUTTON2, MENU, SELECT};
void processEvent(SDL_Event* event); void processEvent(SDL_Event* event);

View file

@ -4,7 +4,7 @@
#include <fstream> #include <fstream>
std::string GuiInputConfig::sConfigPath = "./input.cfg"; std::string GuiInputConfig::sConfigPath = "./input.cfg";
std::string GuiInputConfig::sInputs[] = { "UNKNOWN", "UP", "DOWN", "LEFT", "RIGHT", "BUTTON1 (Accept)", "BUTTON2 (Back)", "START (Menu)", "SELECT (Jump-to-letter)" }; //must be same order as InputManager::InputButton enum std::string GuiInputConfig::sInputs[] = { "UNKNOWN", "UP", "DOWN", "PAGEUP", "PAGEDOWN", "LEFT", "RIGHT", "BUTTON1 (Accept)", "BUTTON2 (Back)", "START (Menu)", "SELECT (Jump-to-letter)" }; //must be same order as InputManager::InputButton enum
int GuiInputConfig::sInputCount = 9; int GuiInputConfig::sInputCount = 9;
GuiInputConfig::GuiInputConfig() GuiInputConfig::GuiInputConfig()

View file

@ -101,8 +101,19 @@ void GuiList<listType>::onInput(InputManager::InputButton button, bool keyDown)
mScrollDir = -1; mScrollDir = -1;
scroll(); scroll();
} }
if(button == InputManager::PAGEDOWN)
{
mScrollDir = 10;
scroll();
}
if(button == InputManager::PAGEUP)
{
mScrollDir = -10;
scroll();
}
}else{ }else{
if((button == InputManager::DOWN && mScrollDir > 0) || (button == InputManager::UP && mScrollDir < 0)) if((button == InputManager::DOWN && mScrollDir > 0) || (button == InputManager::PAGEDOWN && mScrollDir > 0) || (button == InputManager::UP && mScrollDir < 0) || (button == InputManager::PAGEUP && mScrollDir < 0))
{ {
stopScrolling(); stopScrolling();
} }
@ -154,9 +165,19 @@ void GuiList<listType>::scroll()
mSelection += mScrollDir; mSelection += mScrollDir;
if(mSelection < 0) if(mSelection < 0)
{
if(mScrollDir == -10)
mSelection = 0;
else
mSelection += mRowVector.size(); mSelection += mRowVector.size();
}
if(mSelection >= (int)mRowVector.size()) if(mSelection >= (int)mRowVector.size())
{
if(mScrollDir == 10)
mSelection = (int)mRowVector.size() - 1;
else
mSelection -= mRowVector.size(); mSelection -= mRowVector.size();
}
if(mScrollSound) if(mScrollSound)
mScrollSound->play(); mScrollSound->play();