#include #include #include #include #include AxisManipulator::AxisManipulator(Ptr transform, std::string out) : output(out), transform(transform) { } AxisManipulator & AxisManipulator::input(std::string in) { inputs.push_back(in); return *this; } EventSheet::~EventSheet() { // Delete every ActionSignal instance from the out map for(OutMap::iterator i=outmap.begin(); i!=outmap.end(); i++) delete i->second; } void EventSheet::map(const char *action, const ActionSlot & slot) { OutMap::iterator i = outmap.find(action); ActionSignal *sig; if (i == outmap.end()) { sig = new ActionSignal; outmap[action] = sig; } else { sig = i->second; } sig->connect(slot); } bool EventSheet::triggerAction(const char * action) { OutMap::iterator o = outmap.find( action ); if (o != outmap.end()) { //ls_message("emitting action %s.\n", action); o->second->emit(); return true; } //ls_warning("EventSheet::triggerAction('%s') : no handler found.\n", action); return false; } std::string EventRemapper::Button::getFriendlyName() const { std::ostringstream out; switch(type) { case KEYBOARD_KEY: if (device != 0 ) out << "keyboard "; break; case MOUSE_BUTTON: out << "mouse "; break; case JOYSTICK_BUTTON: out << "joystick "; break; } if (device != 0) { out << "#" << (device+1) << " "; } switch(type) { case KEYBOARD_KEY: out << "key "; break; case MOUSE_BUTTON: out << "button "; break; case JOYSTICK_BUTTON: { if (button < 256) { out << "button "; } else { out << "hat "; if (button >= 260) { // coolie hat number > 1 out << ((button-256)/4)+1 << " "; } } break; } } switch(type) { case KEYBOARD_KEY: out << button << " (" << SDL_GetKeyName((SDLKey)button) << ")"; break; case MOUSE_BUTTON: out << button; break; case JOYSTICK_BUTTON: { if (button < 256) { out << (button+1); } else { int direction = (button-256) % 4; switch (direction) { case 0: out << "up"; break; case 1: out << "right"; break; case 2: out << "down"; break; case 3: out << "left"; break; } } } } return out.str(); } EventRemapper::EventRemapper() { controls = new DataNode; // default sheet event_sheets.push_back(new EventSheet()); } EventRemapper::~EventRemapper() { } void EventRemapper::clearButtonMappings() { button_map.clear(); } void EventRemapper::clearEventFilters() { event_filters.clear(); } void EventRemapper::clearAxisManipulators() { axismanips.clear(); } void EventRemapper::clearJoystickAxisMappings() { joystick_axis_map.clear(); } std::vector EventRemapper::getActions() { typedef std::vector Actions; Actions actions; for(ButtonMap::iterator i=button_map.begin(); i!=button_map.end(); ++i) { actions.push_back(i->second); } std::sort(actions.begin(), actions.end()); Actions::iterator new_end = std::unique(actions.begin(), actions.end()); actions.resize(new_end - actions.begin()); return actions; } std::vector EventRemapper::getButtonsForAction(const char *action) { std::vector