Skip to content

Commit

Permalink
Added keyboard support
Browse files Browse the repository at this point in the history
git-svn-id: https://gmenu2x.svn.sourceforge.net/svnroot/gmenu2x@149 bad23c4b-591a-0410-b480-ec8053e4ca07
  • Loading branch information
mtorromeo committed Nov 10, 2008
1 parent 07da6da commit 19d1ec1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
3 changes: 2 additions & 1 deletion pandora/gmenu2x.conf
Expand Up @@ -12,6 +12,7 @@ link=0
globalVolume=0
globalVolume=67
saveSelection=1
globalVolume=0
globalVolume=0
gamma=10
globalVolume=0
videoBpp=24
9 changes: 9 additions & 0 deletions pandora/input.conf.xbox360
@@ -1,14 +1,23 @@
a=joystickbutton,0,2
b=joystickbutton,0,1
b=keyboard,13
b=keyboard,271
x=joystickbutton,0,0
x=keyboard,8
y=joystickbutton,0,3
l=joystickbutton,0,4
l=keyboard,49
r=joystickbutton,0,5
r=keyboard,50
select=joystickbutton,0,10
start=joystickbutton,0,6
volup=joystickaxys,0,5,10000
voldown=joystickaxys,0,2,10000
up=joystickaxys,0,1,-10000
up=keyboard,273
down=joystickaxys,0,1,10000
down=keyboard,274
left=joystickaxys,0,0,-10000
left=keyboard,276
right=joystickaxys,0,0,10000
right=keyboard,275
10 changes: 5 additions & 5 deletions pandora/skins/Default/skin.conf
@@ -1,9 +1,9 @@
messageBoxBorder=#505050ff
topBarBg=#ffffff82
selectionBg=#ffffff82
messageBoxBg=#ffffffff
messageBoxSelection=#a0a0a0ff
bottomBarBg=#ffffff82
topBarBg=#ffffff80
selectionBg=#ffffff80
messageBoxBg=#00000080
messageBoxSelection=#fffffff80
bottomBarBg=#ffffff80
topBarHeight=50
linkHeight=50
linkWidth=80
26 changes: 23 additions & 3 deletions src/inputmanager.cpp
Expand Up @@ -84,9 +84,9 @@ void InputManager::init(string conffile) {

if (action >= 0) {
split(values, value, ",");
if (values.size() >= 3) {
if (values.size() >= 2) {

if (values[0] == "joystickbutton") {
if (values[0] == "joystickbutton" && values.size()==3) {
InputMap map;
map.type = InputManager::MAPPING_TYPE_BUTTON;
map.num = atoi(values[1].c_str());
Expand All @@ -100,6 +100,11 @@ void InputManager::init(string conffile) {
map.value = atoi(values[2].c_str());
map.treshold = atoi(values[3].c_str());
mappings[action].push_back(map);
} else if (values[0] == "keyboard") {
InputMap map;
map.type = InputManager::MAPPING_TYPE_KEYPRESS;
map.value = atoi(values[1].c_str());
mappings[action].push_back(map);
}

}
Expand All @@ -125,6 +130,14 @@ void InputManager::setActionsCount(int count) {

void InputManager::update() {
SDL_JoystickUpdate();

events.clear();
SDL_Event event;
while (SDL_PollEvent(&event)) {
SDL_Event evcopy = event;
events.push_back(evcopy);
}

Uint32 tick = SDL_GetTicks();
for (uint x=0; x<actions.size(); x++) {
actions[x] = false;
Expand Down Expand Up @@ -162,7 +175,8 @@ bool InputManager::isActive(int action) {

switch (map.type) {
case InputManager::MAPPING_TYPE_BUTTON:
return map.num < joysticks.size() && SDL_JoystickGetButton(joysticks[map.num], map.value);
if (map.num < joysticks.size() && SDL_JoystickGetButton(joysticks[map.num], map.value))
return true;
break;
case InputManager::MAPPING_TYPE_AXYS:
if (map.num < joysticks.size()) {
Expand All @@ -171,6 +185,12 @@ bool InputManager::isActive(int action) {
if (map.treshold>0 && axyspos > map.treshold) return true;
}
break;
case InputManager::MAPPING_TYPE_KEYPRESS:
for (uint ex=0; ex<events.size(); ex++) {
if (events[ex].type == SDL_KEYDOWN && events[ex].key.keysym.sym == map.value)
return true;
}
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/inputmanager.h
Expand Up @@ -51,6 +51,7 @@ typedef struct {
} InputMap;

typedef vector<InputMap> MappingList;
typedef vector<SDL_Event> SDLEventList;

/**
Manages all input peripherals
Expand All @@ -61,6 +62,7 @@ class InputManager {
InputMap getInputMapping(int action);
vector<Uint32> actionTick;
vector<Uint32> interval;
SDLEventList events;

public:
static const int MAPPING_TYPE_UNDEFINED = -1;
Expand Down

0 comments on commit 19d1ec1

Please sign in to comment.