diff --git a/stella/src/emucore/EventHandler.cxx b/stella/src/emucore/EventHandler.cxx index c58bc03d7..122a1ef63 100644 --- a/stella/src/emucore/EventHandler.cxx +++ b/stella/src/emucore/EventHandler.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: EventHandler.cxx,v 1.42 2005-04-05 00:40:54 stephena Exp $ +// $Id: EventHandler.cxx,v 1.43 2005-04-06 23:47:06 stephena Exp $ //============================================================================ #include <algorithm> @@ -587,21 +587,6 @@ void EventHandler::setActionMappings() if(key != "") ourActionList[i].key = key; } - -/* FIXME - add this to addXXXBinding and deleteBinding ... - // Save the new bindings - ostringstream keybuf, joybuf; - - // Iterate through the keymap table and create a colon-separated list - for(uInt32 i = 0; i < StellaEvent::LastKCODE; ++i) - keybuf << myKeyTable[i] << ":"; - myOSystem->settings().setString("keymap", keybuf.str()); - - // Iterate through the joymap table and create a colon-separated list - for(uInt32 i = 0; i < StellaEvent::LastJSTICK*StellaEvent::LastJCODE; ++i) - joybuf << myJoyTable[i] << ":"; - myOSystem->settings().setString("joymap", joybuf.str()); -*/ } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -655,9 +640,61 @@ void EventHandler::setJoymap() */ } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void EventHandler::addKeyMapping(Event::Type event, uInt16 key) +{ + myKeyTable[key] = event; + + setActionMappings(); + saveMappings(); +} + +/* FIXME +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void EventHandler::addJoyMapping(Event::Type event, + StellaEvent::JoyStick stick, StellaEvent::JoyCode code) +{ + myJoyTable[stick * StellaEvent::LastJCODE + code] = event; + + setActionMappings(); + saveMappings(); +} +*/ + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void EventHandler::eraseMapping(Event::Type event) +{ + // Erase the KeyEvent arrays + for(Int32 i = 0; i < SDLK_LAST; ++i) + if(myKeyTable[i] == event) + myKeyTable[i] = Event::NoType; + + // Erase the JoyEvent array + for(Int32 i = 0; i < StellaEvent::LastJSTICK*StellaEvent::LastJCODE; ++i) + if(myJoyTable[i] == event) + myJoyTable[i] = Event::NoType; + + setActionMappings(); + saveMappings(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void EventHandler::setDefaultMapping() +{ + setDefaultKeymap(); + setDefaultJoymap(); + + setActionMappings(); + saveMappings(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventHandler::setDefaultKeymap() { + // Erase all mappings + for(Int32 i = 0; i < SDLK_LAST; ++i) + myKeyTable[i] = Event::NoType; + myKeyTable[ SDLK_1 ] = Event::KeyboardZero1; myKeyTable[ SDLK_2 ] = Event::KeyboardZero2; myKeyTable[ SDLK_3 ] = Event::KeyboardZero3; @@ -725,16 +762,16 @@ void EventHandler::setDefaultKeymap() myKeyTable[ SDLK_ESCAPE ] = Event::ExitGame; #endif - // Iterate through the keymap table and create a colon-separated list - ostringstream keybuf; - for(uInt32 i = 0; i < SDLK_LAST; ++i) - keybuf << myKeyTable[i] << ":"; - myOSystem->settings().setString("keymap", keybuf.str()); + saveMappings(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventHandler::setDefaultJoymap() { + // Erase all mappings + for(Int32 i = 0; i < StellaEvent::LastJSTICK*StellaEvent::LastJCODE; ++i) + myJoyTable[i] = Event::NoType; + // Left joystick uInt32 i = StellaEvent::JSTICK_0 * StellaEvent::LastJCODE; myJoyTable[i + StellaEvent::JAXIS_UP] = Event::JoystickZeroUp; @@ -750,6 +787,24 @@ void EventHandler::setDefaultJoymap() myJoyTable[i + StellaEvent::JAXIS_LEFT] = Event::JoystickOneLeft; myJoyTable[i + StellaEvent::JAXIS_RIGHT] = Event::JoystickOneRight; myJoyTable[i + StellaEvent::JBUTTON_0] = Event::JoystickOneFire; + + saveMappings(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void EventHandler::saveMappings() +{ + // Iterate through the keymap table and create a colon-separated list + ostringstream keybuf; + for(uInt32 i = 0; i < SDLK_LAST; ++i) + keybuf << myKeyTable[i] << ":"; + myOSystem->settings().setString("keymap", keybuf.str()); + + // Iterate through the joymap table and create a colon-separated list + ostringstream joybuf; + for(Int32 i = 0; i < StellaEvent::LastJSTICK*StellaEvent::LastJCODE; ++i) + joybuf << myJoyTable[i] << ":"; + myOSystem->settings().setString("joymap", joybuf.str()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/emucore/EventHandler.hxx b/stella/src/emucore/EventHandler.hxx index c4d536b29..b4cbe25b0 100644 --- a/stella/src/emucore/EventHandler.hxx +++ b/stella/src/emucore/EventHandler.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: EventHandler.hxx,v 1.22 2005-04-05 00:40:54 stephena Exp $ +// $Id: EventHandler.hxx,v 1.23 2005-04-06 23:47:07 stephena Exp $ //============================================================================ #ifndef EVENTHANDLER_HXX @@ -57,7 +57,7 @@ struct ActionList { mapping can take place. @author Stephen Anthony - @version $Id: EventHandler.hxx,v 1.22 2005-04-05 00:40:54 stephena Exp $ + @version $Id: EventHandler.hxx,v 1.23 2005-04-06 23:47:07 stephena Exp $ */ class EventHandler { @@ -88,6 +88,26 @@ class EventHandler */ void poll(); + /** + Bind a key to an event/action + + @event The event we are remapping + @key The key to bind to this event + */ + void addKeyMapping(Event::Type event, uInt16 key); + + /** + Erase the specified mapping + + @event The event for which we erase all mappings + */ + void eraseMapping(Event::Type event); + + /** + Resets the event mappings to default values + */ + void setDefaultMapping(); + /** Returns the current state of the EventHandler @@ -102,7 +122,6 @@ class EventHandler */ void reset(State state); - /** This method indicates whether a pause event has been received. */ @@ -180,6 +199,7 @@ class EventHandler void setJoymap(); void setDefaultKeymap(); void setDefaultJoymap(); + void saveMappings(); bool isValidList(string list, uInt32 length); diff --git a/stella/src/emucore/FrameBuffer.cxx b/stella/src/emucore/FrameBuffer.cxx index 7ab20718c..e4459b283 100644 --- a/stella/src/emucore/FrameBuffer.cxx +++ b/stella/src/emucore/FrameBuffer.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBuffer.cxx,v 1.25 2005-04-05 00:40:54 stephena Exp $ +// $Id: FrameBuffer.cxx,v 1.26 2005-04-06 23:47:07 stephena Exp $ //============================================================================ #include <sstream> @@ -650,71 +650,3 @@ void FrameBuffer::sendJoyEvent(StellaEvent::JoyStick stick, } } */ - -/* -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FrameBuffer::addKeyBinding(Event::Type event, StellaEvent::KeyCode key) -{ - myKeyTable[key] = event; - - loadRemapMenu(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FrameBuffer::addJoyBinding(Event::Type event, - StellaEvent::JoyStick stick, StellaEvent::JoyCode code) -{ - myJoyTable[stick * StellaEvent::LastJCODE + code] = event; - - loadRemapMenu(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FrameBuffer::deleteBinding(Event::Type event) -{ - for(uInt32 i = 0; i < myKeyTableSize; ++i) - if(myKeyTable[i] == event) - myKeyTable[i] = Event::NoType; - - for(uInt32 j = 0; j < myJoyTableSize; ++j) - if(myJoyTable[j] == event) - myJoyTable[j] = Event::NoType; - - loadRemapMenu(); -} - -*/ - -#if 0 -/** - This array must be initialized in a specific order, matching - their initialization in StellaEvent::KeyCode. - - The other option would be to create an array of structures - (in StellaEvent.hxx) containing event/string pairs. - This would eliminate the use of enumerations and slow down - lookups. So I do it this way instead. - */ -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const char* FrameBuffer::ourEventName[StellaEvent::LastKCODE] = { - "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", - "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", - - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", - - "KP 0", "KP 1", "KP 2", "KP 3", "KP 4", "KP 5", "KP 6", "KP 7", "KP 8", - "KP 9", "KP .", "KP /", "KP *", "KP -", "KP +", "KP ENTER", "KP =", - - "BACKSP", "TAB", "CLEAR", "ENTER", "ESC", "SPACE", ",", "-", ".", - "/", "\\", ";", "=", "\"", "`", "[", "]", - - "PRT SCRN", "SCR LOCK", "PAUSE", "INS", "HOME", "PGUP", - "DEL", "END", "PGDN", - - "LCTRL", "RCTRL", "LALT", "RALT", "LWIN", "RWIN", "MENU", - "UP", "DOWN", "LEFT", "RIGHT", - - "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", - "F11", "F12", "F13", "F14", "F15", -}; -#endif diff --git a/stella/src/gui/EventMappingDialog.cxx b/stella/src/gui/EventMappingDialog.cxx index 25fe00174..deb0ecb4f 100644 --- a/stella/src/gui/EventMappingDialog.cxx +++ b/stella/src/gui/EventMappingDialog.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: EventMappingDialog.cxx,v 1.3 2005-04-06 19:50:12 stephena Exp $ +// $Id: EventMappingDialog.cxx,v 1.4 2005-04-06 23:47:07 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -97,11 +97,7 @@ void EventMappingDialog::startRemapping() myCancelMapButton->setEnabled(true); // And show a message indicating which key is being remapped - ostringstream buf; - buf << "Select a new event for the '" - << EventHandler::ourActionList[ myActionSelected ].action - << "' action"; - myKeyMapping->setLabel(buf.str()); + drawKeyMapping(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -109,8 +105,11 @@ void EventMappingDialog::eraseRemapping() { if(myActionSelected < 0) return; - else - cerr << "Erase item: " << myActionSelected << endl; + + Event::Type event = EventHandler::ourActionList[ myActionSelected ].event; + instance()->eventHandler().eraseMapping(event); + + drawKeyMapping(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -130,20 +129,37 @@ void EventMappingDialog::stopRemapping() // Make sure the list widget is in a known state if(myActionSelected >= 0) { - ostringstream buf; - buf << "Key(s) : " - << EventHandler::ourActionList[ myActionSelected ].key; - myKeyMapping->setLabel(buf.str()); - + drawKeyMapping(); myMapButton->setEnabled(true); myEraseButton->setEnabled(true); } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void EventMappingDialog::drawKeyMapping() +{ + if(myActionSelected >= 0) + { + ostringstream buf; + buf << "Key(s) : " + << EventHandler::ourActionList[ myActionSelected ].key; + myKeyMapping->setLabel(buf.str()); + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventMappingDialog::handleKeyDown(uInt16 ascii, Int32 keycode, Int32 modifiers) { -// cerr << "EventMappingDialog::handleKeyDown received: " << ascii << endl; + // Remap keys in remap mode, otherwise pass to listwidget + if(myRemapStatus && myActionSelected >= 0) + { + Event::Type event = EventHandler::ourActionList[ myActionSelected ].event; + instance()->eventHandler().addKeyMapping(event, ascii); + + stopRemapping(); + } + else + myActionsList->handleKeyDown(ascii, keycode, modifiers); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -155,11 +171,7 @@ void EventMappingDialog::handleCommand(CommandSender* sender, uInt32 cmd, uInt32 if(myActionsList->getSelected() >= 0) { myActionSelected = myActionsList->getSelected(); - ostringstream buf; - buf << "Key(s) : " - << EventHandler::ourActionList[ myActionSelected ].key; - - myKeyMapping->setLabel(buf.str()); + drawKeyMapping(); myMapButton->setEnabled(true); myEraseButton->setEnabled(true); myCancelMapButton->setEnabled(false); @@ -179,7 +191,9 @@ void EventMappingDialog::handleCommand(CommandSender* sender, uInt32 cmd, uInt32 break; case kDefaultsCmd: -cerr << "Set default mapping\n"; + instance()->eventHandler().setDefaultMapping(); + drawKeyMapping(); + break; default: diff --git a/stella/src/gui/EventMappingDialog.hxx b/stella/src/gui/EventMappingDialog.hxx index 7bd247a87..2691541c8 100644 --- a/stella/src/gui/EventMappingDialog.hxx +++ b/stella/src/gui/EventMappingDialog.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: EventMappingDialog.hxx,v 1.3 2005-04-06 19:50:12 stephena Exp $ +// $Id: EventMappingDialog.hxx,v 1.4 2005-04-06 23:47:08 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -61,6 +61,8 @@ class EventMappingDialog : public Dialog void stopRemapping(); void loadConfig(); + void drawKeyMapping(); + private: // Indicates the event that is currently selected Int32 myActionSelected;