/*************************************************************************** * Copyright (C) 2006 by Massimiliano Torromeo * * massimiliano.torromeo@gmail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include #include #include "inputmanager.h" #include "utilities.h" using namespace std; InputManager::InputManager() {} InputManager::~InputManager() { for (uint x=0; x values; while (getline(inf, line, '\n')) { pos = line.find("="); name = trim(line.substr(0,pos)); value = trim(line.substr(pos+1,line.length())); int action = -1; if (name=="up") action = ACTION_UP; else if (name=="down") action = ACTION_DOWN; else if (name=="left") action = ACTION_LEFT; else if (name=="right") action = ACTION_RIGHT; else if (name=="a") action = ACTION_A; else if (name=="b") action = ACTION_B; else if (name=="x") action = ACTION_X; else if (name=="y") action = ACTION_Y; else if (name=="l") action = ACTION_L; else if (name=="r") action = ACTION_R; else if (name=="start") action = ACTION_START; else if (name=="select") action = ACTION_SELECT; else if (name=="volup") action = ACTION_VOLUP; else if (name=="voldown") action = ACTION_VOLDOWN; if (action >= 0) { split(values, value, ","); if (values.size() >= 2) { if (values[0] == "joystickbutton" && values.size()==3) { InputMap map; map.type = InputManager::MAPPING_TYPE_BUTTON; map.num = atoi(values[1].c_str()); map.value = atoi(values[2].c_str()); map.treshold = 0; mappings[action].push_back(map); } else if (values[0] == "joystickaxys" && values.size()==4) { InputMap map; map.type = InputManager::MAPPING_TYPE_AXYS; map.num = atoi(values[1].c_str()); 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); } } } } inf.close(); } } } void InputManager::setActionsCount(int count) { actions.clear(); actionTick.clear(); interval.clear(); for (int x=0; xinterval[x]) { actions[x] = true; actionTick[x] = tick; } } else { actionTick[x] = 0; } } } int InputManager::count() { return actions.size(); } void InputManager::setInterval(int ms, int action) { if (action<0) for (uint x=0; x=actions.size()) return false; return actions[action]; } bool InputManager::isActive(int action) { for (uint x=0; x0 && axyspos > map.treshold) return true; } break; case InputManager::MAPPING_TYPE_KEYPRESS: for (uint ex=0; ex