More work on the EventHandler and EventMappingDialog classes. The

EventHandler class now contains string mappings for all possible SDL
keys, which should hopefully take care of our international users.

Added 'Map', 'Erase' and 'Cancel' buttons to the EventMappingDialog.
They still don't do much, but it will now be an easy matter to add the
hooks into EventHandler.  You *are* able to scroll through the list
and see which keys are bound to which actions, though.

This approach is *much* cleaner than in previous code.  Now the EventHandler
actually does the remapping; the EventMappingDialog only collects the
events and associated actions and passes them on.  This is much cleaner
than before, when (for example) the FrameBuffer was doing remapping!  What
the hell did the framebuffer have to do with event mapping???


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@391 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-04-05 00:40:55 +00:00
parent 9fe7eb8894
commit c2aba6aa6f
6 changed files with 469 additions and 360 deletions

View File

@ -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.41 2005-04-04 02:19:20 stephena Exp $
// $Id: EventHandler.cxx,v 1.42 2005-04-05 00:40:54 stephena Exp $
//============================================================================
#include <algorithm>
@ -53,11 +53,10 @@ EventHandler::EventHandler(OSystem* osystem)
myEvent = new Event();
// Erase the KeyEvent arrays
for(Int32 i = 0; i < 256; ++i)
for(Int32 i = 0; i < SDLK_LAST; ++i)
{
myKeyTable[i] = Event::NoType;
myAltKeyTable[i] = Event::NoType;
myCtrlKeyTable[i] = Event::NoType;
ourSDLMapping[i] = "";
}
// Erase the JoyEvent array
@ -76,8 +75,12 @@ EventHandler::EventHandler(OSystem* osystem)
ourMessageTable[Event::ConsoleRightDifficultyA] = "Right Difficulty A";
ourMessageTable[Event::ConsoleRightDifficultyB] = "Right Difficulty B";
// Make sure the event/action mappings are correctly set,
// and fill the ActionList structure with valid values
setSDLMappings();
setKeymap();
setJoymap();
setActionMappings();
myGrabMouseFlag = myOSystem->settings().getBool("grabmouse");
}
@ -513,6 +516,94 @@ void EventHandler::handleEvent(Event::Type event, Int32 state)
myEvent->set(event, state);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setActionMappings()
{
// Fill the ActionList with the current key and joystick mappings
for(Int32 i = 0; i < 58; ++i)
{
Event::Type event = ourActionList[i].event;
ourActionList[i].key = "None";
string key = "";
for(uInt32 j = 0; j < SDLK_LAST; ++j) // size of myKeyTable
{
if(myKeyTable[j] == event)
{
if(key == "")
key = key + ourSDLMapping[j];
else
key = key + ", " + ourSDLMapping[j];
}
}
/* FIXME
for(uInt32 j = 0; j < myJoyTableSize; ++j)
{
if(myJoyTable[j] == event)
{
ostringstream joyevent;
uInt32 stick = j / StellaEvent::LastJCODE;
uInt32 button = j % StellaEvent::LastJCODE;
switch(button)
{
case StellaEvent::JAXIS_UP:
joyevent << "J" << stick << " UP";
break;
case StellaEvent::JAXIS_DOWN:
joyevent << "J" << stick << " DOWN";
break;
case StellaEvent::JAXIS_LEFT:
joyevent << "J" << stick << " LEFT";
break;
case StellaEvent::JAXIS_RIGHT:
joyevent << "J" << stick << " RIGHT";
break;
default:
joyevent << "J" << stick << " B" << (button-4);
break;
}
if(key == "")
key = key + joyevent.str();
else
key = key + ", " + joyevent.str();
}
}
*/
// There are some keys which are hardcoded. These should be represented too.
string prepend = "";
if(event == Event::Quit)
prepend = "Ctrl Q"; // FIXME for OSX
// else if ...
if(key == "")
key = prepend;
else if(prepend != "")
key = prepend + ", " + key;
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());
*/
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setKeymap()
{
@ -521,13 +612,13 @@ void EventHandler::setKeymap()
string list = myOSystem->settings().getString("keymap");
replace(list.begin(), list.end(), ':', ' ');
if(isValidList(list, StellaEvent::LastKCODE))
if(isValidList(list, SDLK_LAST))
{
istringstream buf(list);
string key;
// Fill the keymap table with events
for(Int32 i = 0; i < StellaEvent::LastKCODE; ++i)
for(Int32 i = 0; i < SDLK_LAST; ++i)
{
buf >> key;
myKeyTable[i] = (Event::Type) atoi(key.c_str());
@ -540,6 +631,8 @@ void EventHandler::setKeymap()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setJoymap()
{
// FIXME
/*
// Since istringstream swallows whitespace, we have to make the
// delimiters be spaces
string list = myOSystem->settings().getString("joymap");
@ -559,20 +652,7 @@ void EventHandler::setJoymap()
}
else
setDefaultJoymap();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::getKeymapArray(Event::Type** array, uInt32* size)
{
*array = myKeyTable;
*size = StellaEvent::LastKCODE;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::getJoymapArray(Event::Type** array, uInt32* size)
{
*array = myJoyTable;
*size = StellaEvent::LastJSTICK * StellaEvent::LastJCODE;
*/
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -640,7 +720,6 @@ void EventHandler::setDefaultKeymap()
myKeyTable[ SDLK_F10 ] = Event::ChangeState;
myKeyTable[ SDLK_F11 ] = Event::LoadState;
myKeyTable[ SDLK_F12 ] = Event::TakeSnapshot;
myKeyTable[ SDLK_PAUSE ] = Event::Pause;
#ifndef MAC_OSX
myKeyTable[ SDLK_ESCAPE ] = Event::ExitGame;
@ -648,7 +727,7 @@ void EventHandler::setDefaultKeymap()
// Iterate through the keymap table and create a colon-separated list
ostringstream keybuf;
for(uInt32 i = 0; i < 256; ++i)
for(uInt32 i = 0; i < SDLK_LAST; ++i)
keybuf << myKeyTable[i] << ":";
myOSystem->settings().setString("keymap", keybuf.str());
}
@ -791,7 +870,7 @@ void EventHandler::takeSnapshot()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setPaddleMode(Int8 num)
void EventHandler::setPaddleMode(uInt32 num)
{
myPaddleMode = num;
@ -802,16 +881,252 @@ void EventHandler::setPaddleMode(Int8 num)
myOSystem->settings().setInt("paddle", myPaddleMode);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setSDLMappings()
{
ourSDLMapping[ SDLK_BACKSPACE ] = "BACKSPACE";
ourSDLMapping[ SDLK_TAB ] = "TAB";
ourSDLMapping[ SDLK_CLEAR ] = "CLEAR";
ourSDLMapping[ SDLK_RETURN ] = "RETURN";
ourSDLMapping[ SDLK_PAUSE ] = "PAUSE";
ourSDLMapping[ SDLK_ESCAPE ] = "ESCAPE";
ourSDLMapping[ SDLK_SPACE ] = "SPACE";
ourSDLMapping[ SDLK_EXCLAIM ] = "EXCLAIM";
ourSDLMapping[ SDLK_QUOTEDBL ] = "QUOTEDBL";
ourSDLMapping[ SDLK_HASH ] = "HASH";
ourSDLMapping[ SDLK_DOLLAR ] = "DOLLAR";
ourSDLMapping[ SDLK_AMPERSAND ] = "AMPERSAND";
ourSDLMapping[ SDLK_QUOTE ] = "QUOTE";
ourSDLMapping[ SDLK_LEFTPAREN ] = "LEFTPAREN";
ourSDLMapping[ SDLK_RIGHTPAREN ] = "RIGHTPAREN";
ourSDLMapping[ SDLK_ASTERISK ] = "ASTERISK";
ourSDLMapping[ SDLK_PLUS ] = "PLUS";
ourSDLMapping[ SDLK_COMMA ] = "COMMA";
ourSDLMapping[ SDLK_MINUS ] = "MINUS";
ourSDLMapping[ SDLK_PERIOD ] = "PERIOD";
ourSDLMapping[ SDLK_SLASH ] = "SLASH";
ourSDLMapping[ SDLK_0 ] = "0";
ourSDLMapping[ SDLK_1 ] = "1";
ourSDLMapping[ SDLK_2 ] = "2";
ourSDLMapping[ SDLK_3 ] = "3";
ourSDLMapping[ SDLK_4 ] = "4";
ourSDLMapping[ SDLK_5 ] = "5";
ourSDLMapping[ SDLK_6 ] = "6";
ourSDLMapping[ SDLK_7 ] = "7";
ourSDLMapping[ SDLK_8 ] = "8";
ourSDLMapping[ SDLK_9 ] = "9";
ourSDLMapping[ SDLK_COLON ] = "COLON";
ourSDLMapping[ SDLK_SEMICOLON ] = "SEMICOLON";
ourSDLMapping[ SDLK_LESS ] = "LESS";
ourSDLMapping[ SDLK_EQUALS ] = "EQUALS";
ourSDLMapping[ SDLK_GREATER ] = "GREATER";
ourSDLMapping[ SDLK_QUESTION ] = "QUESTION";
ourSDLMapping[ SDLK_AT ] = "AT";
ourSDLMapping[ SDLK_LEFTBRACKET ] = "LEFTBRACKET";
ourSDLMapping[ SDLK_BACKSLASH ] = "BACKSLASH";
ourSDLMapping[ SDLK_RIGHTBRACKET ] = "RIGHTBRACKET";
ourSDLMapping[ SDLK_CARET ] = "CARET";
ourSDLMapping[ SDLK_UNDERSCORE ] = "UNDERSCORE";
ourSDLMapping[ SDLK_BACKQUOTE ] = "BACKQUOTE";
ourSDLMapping[ SDLK_a ] = "A";
ourSDLMapping[ SDLK_b ] = "B";
ourSDLMapping[ SDLK_c ] = "C";
ourSDLMapping[ SDLK_d ] = "D";
ourSDLMapping[ SDLK_e ] = "E";
ourSDLMapping[ SDLK_f ] = "F";
ourSDLMapping[ SDLK_g ] = "G";
ourSDLMapping[ SDLK_h ] = "H";
ourSDLMapping[ SDLK_i ] = "I";
ourSDLMapping[ SDLK_j ] = "J";
ourSDLMapping[ SDLK_k ] = "K";
ourSDLMapping[ SDLK_l ] = "L";
ourSDLMapping[ SDLK_m ] = "M";
ourSDLMapping[ SDLK_n ] = "N";
ourSDLMapping[ SDLK_o ] = "O";
ourSDLMapping[ SDLK_p ] = "P";
ourSDLMapping[ SDLK_q ] = "Q";
ourSDLMapping[ SDLK_r ] = "R";
ourSDLMapping[ SDLK_s ] = "S";
ourSDLMapping[ SDLK_t ] = "T";
ourSDLMapping[ SDLK_u ] = "U";
ourSDLMapping[ SDLK_v ] = "V";
ourSDLMapping[ SDLK_w ] = "W";
ourSDLMapping[ SDLK_x ] = "X";
ourSDLMapping[ SDLK_y ] = "Y";
ourSDLMapping[ SDLK_z ] = "Z";
ourSDLMapping[ SDLK_DELETE ] = "DELETE";
ourSDLMapping[ SDLK_WORLD_0 ] = "WORLD_0";
ourSDLMapping[ SDLK_WORLD_1 ] = "WORLD_1";
ourSDLMapping[ SDLK_WORLD_2 ] = "WORLD_2";
ourSDLMapping[ SDLK_WORLD_3 ] = "WORLD_3";
ourSDLMapping[ SDLK_WORLD_4 ] = "WORLD_4";
ourSDLMapping[ SDLK_WORLD_5 ] = "WORLD_5";
ourSDLMapping[ SDLK_WORLD_6 ] = "WORLD_6";
ourSDLMapping[ SDLK_WORLD_7 ] = "WORLD_7";
ourSDLMapping[ SDLK_WORLD_8 ] = "WORLD_8";
ourSDLMapping[ SDLK_WORLD_9 ] = "WORLD_9";
ourSDLMapping[ SDLK_WORLD_10 ] = "WORLD_10";
ourSDLMapping[ SDLK_WORLD_11 ] = "WORLD_11";
ourSDLMapping[ SDLK_WORLD_12 ] = "WORLD_12";
ourSDLMapping[ SDLK_WORLD_13 ] = "WORLD_13";
ourSDLMapping[ SDLK_WORLD_14 ] = "WORLD_14";
ourSDLMapping[ SDLK_WORLD_15 ] = "WORLD_15";
ourSDLMapping[ SDLK_WORLD_16 ] = "WORLD_16";
ourSDLMapping[ SDLK_WORLD_17 ] = "WORLD_17";
ourSDLMapping[ SDLK_WORLD_18 ] = "WORLD_18";
ourSDLMapping[ SDLK_WORLD_19 ] = "WORLD_19";
ourSDLMapping[ SDLK_WORLD_20 ] = "WORLD_20";
ourSDLMapping[ SDLK_WORLD_21 ] = "WORLD_21";
ourSDLMapping[ SDLK_WORLD_22 ] = "WORLD_22";
ourSDLMapping[ SDLK_WORLD_23 ] = "WORLD_23";
ourSDLMapping[ SDLK_WORLD_24 ] = "WORLD_24";
ourSDLMapping[ SDLK_WORLD_25 ] = "WORLD_25";
ourSDLMapping[ SDLK_WORLD_26 ] = "WORLD_26";
ourSDLMapping[ SDLK_WORLD_27 ] = "WORLD_27";
ourSDLMapping[ SDLK_WORLD_28 ] = "WORLD_28";
ourSDLMapping[ SDLK_WORLD_29 ] = "WORLD_29";
ourSDLMapping[ SDLK_WORLD_30 ] = "WORLD_30";
ourSDLMapping[ SDLK_WORLD_31 ] = "WORLD_31";
ourSDLMapping[ SDLK_WORLD_32 ] = "WORLD_32";
ourSDLMapping[ SDLK_WORLD_33 ] = "WORLD_33";
ourSDLMapping[ SDLK_WORLD_34 ] = "WORLD_34";
ourSDLMapping[ SDLK_WORLD_35 ] = "WORLD_35";
ourSDLMapping[ SDLK_WORLD_36 ] = "WORLD_36";
ourSDLMapping[ SDLK_WORLD_37 ] = "WORLD_37";
ourSDLMapping[ SDLK_WORLD_38 ] = "WORLD_38";
ourSDLMapping[ SDLK_WORLD_39 ] = "WORLD_39";
ourSDLMapping[ SDLK_WORLD_40 ] = "WORLD_40";
ourSDLMapping[ SDLK_WORLD_41 ] = "WORLD_41";
ourSDLMapping[ SDLK_WORLD_42 ] = "WORLD_42";
ourSDLMapping[ SDLK_WORLD_43 ] = "WORLD_43";
ourSDLMapping[ SDLK_WORLD_44 ] = "WORLD_44";
ourSDLMapping[ SDLK_WORLD_45 ] = "WORLD_45";
ourSDLMapping[ SDLK_WORLD_46 ] = "WORLD_46";
ourSDLMapping[ SDLK_WORLD_47 ] = "WORLD_47";
ourSDLMapping[ SDLK_WORLD_48 ] = "WORLD_48";
ourSDLMapping[ SDLK_WORLD_49 ] = "WORLD_49";
ourSDLMapping[ SDLK_WORLD_50 ] = "WORLD_50";
ourSDLMapping[ SDLK_WORLD_51 ] = "WORLD_51";
ourSDLMapping[ SDLK_WORLD_52 ] = "WORLD_52";
ourSDLMapping[ SDLK_WORLD_53 ] = "WORLD_53";
ourSDLMapping[ SDLK_WORLD_54 ] = "WORLD_54";
ourSDLMapping[ SDLK_WORLD_55 ] = "WORLD_55";
ourSDLMapping[ SDLK_WORLD_56 ] = "WORLD_56";
ourSDLMapping[ SDLK_WORLD_57 ] = "WORLD_57";
ourSDLMapping[ SDLK_WORLD_58 ] = "WORLD_58";
ourSDLMapping[ SDLK_WORLD_59 ] = "WORLD_59";
ourSDLMapping[ SDLK_WORLD_60 ] = "WORLD_60";
ourSDLMapping[ SDLK_WORLD_61 ] = "WORLD_61";
ourSDLMapping[ SDLK_WORLD_62 ] = "WORLD_62";
ourSDLMapping[ SDLK_WORLD_63 ] = "WORLD_63";
ourSDLMapping[ SDLK_WORLD_64 ] = "WORLD_64";
ourSDLMapping[ SDLK_WORLD_65 ] = "WORLD_65";
ourSDLMapping[ SDLK_WORLD_66 ] = "WORLD_66";
ourSDLMapping[ SDLK_WORLD_67 ] = "WORLD_67";
ourSDLMapping[ SDLK_WORLD_68 ] = "WORLD_68";
ourSDLMapping[ SDLK_WORLD_69 ] = "WORLD_69";
ourSDLMapping[ SDLK_WORLD_70 ] = "WORLD_70";
ourSDLMapping[ SDLK_WORLD_71 ] = "WORLD_71";
ourSDLMapping[ SDLK_WORLD_72 ] = "WORLD_72";
ourSDLMapping[ SDLK_WORLD_73 ] = "WORLD_73";
ourSDLMapping[ SDLK_WORLD_74 ] = "WORLD_74";
ourSDLMapping[ SDLK_WORLD_75 ] = "WORLD_75";
ourSDLMapping[ SDLK_WORLD_76 ] = "WORLD_76";
ourSDLMapping[ SDLK_WORLD_77 ] = "WORLD_77";
ourSDLMapping[ SDLK_WORLD_78 ] = "WORLD_78";
ourSDLMapping[ SDLK_WORLD_79 ] = "WORLD_79";
ourSDLMapping[ SDLK_WORLD_80 ] = "WORLD_80";
ourSDLMapping[ SDLK_WORLD_81 ] = "WORLD_81";
ourSDLMapping[ SDLK_WORLD_82 ] = "WORLD_82";
ourSDLMapping[ SDLK_WORLD_83 ] = "WORLD_83";
ourSDLMapping[ SDLK_WORLD_84 ] = "WORLD_84";
ourSDLMapping[ SDLK_WORLD_85 ] = "WORLD_85";
ourSDLMapping[ SDLK_WORLD_86 ] = "WORLD_86";
ourSDLMapping[ SDLK_WORLD_87 ] = "WORLD_87";
ourSDLMapping[ SDLK_WORLD_88 ] = "WORLD_88";
ourSDLMapping[ SDLK_WORLD_89 ] = "WORLD_89";
ourSDLMapping[ SDLK_WORLD_90 ] = "WORLD_90";
ourSDLMapping[ SDLK_WORLD_91 ] = "WORLD_91";
ourSDLMapping[ SDLK_WORLD_92 ] = "WORLD_92";
ourSDLMapping[ SDLK_WORLD_93 ] = "WORLD_93";
ourSDLMapping[ SDLK_WORLD_94 ] = "WORLD_94";
ourSDLMapping[ SDLK_WORLD_95 ] = "WORLD_95";
ourSDLMapping[ SDLK_KP0 ] = "KP0";
ourSDLMapping[ SDLK_KP1 ] = "KP1";
ourSDLMapping[ SDLK_KP2 ] = "KP2";
ourSDLMapping[ SDLK_KP3 ] = "KP3";
ourSDLMapping[ SDLK_KP4 ] = "KP4";
ourSDLMapping[ SDLK_KP5 ] = "KP5";
ourSDLMapping[ SDLK_KP6 ] = "KP6";
ourSDLMapping[ SDLK_KP7 ] = "KP7";
ourSDLMapping[ SDLK_KP8 ] = "KP8";
ourSDLMapping[ SDLK_KP9 ] = "KP9";
ourSDLMapping[ SDLK_KP_PERIOD ] = "KP_PERIOD";
ourSDLMapping[ SDLK_KP_DIVIDE ] = "KP_DIVIDE";
ourSDLMapping[ SDLK_KP_MULTIPLY ] = "KP_MULTIPLY";
ourSDLMapping[ SDLK_KP_MINUS ] = "KP_MINUS";
ourSDLMapping[ SDLK_KP_PLUS ] = "KP_PLUS";
ourSDLMapping[ SDLK_KP_ENTER ] = "KP_ENTER";
ourSDLMapping[ SDLK_KP_EQUALS ] = "KP_EQUALS";
ourSDLMapping[ SDLK_UP ] = "UP";
ourSDLMapping[ SDLK_DOWN ] = "DOWN";
ourSDLMapping[ SDLK_RIGHT ] = "RIGHT";
ourSDLMapping[ SDLK_LEFT ] = "LEFT";
ourSDLMapping[ SDLK_INSERT ] = "INSERT";
ourSDLMapping[ SDLK_HOME ] = "HOME";
ourSDLMapping[ SDLK_END ] = "END";
ourSDLMapping[ SDLK_PAGEUP ] = "PAGEUP";
ourSDLMapping[ SDLK_PAGEDOWN ] = "PAGEDOWN";
ourSDLMapping[ SDLK_F1 ] = "F1";
ourSDLMapping[ SDLK_F2 ] = "F2";
ourSDLMapping[ SDLK_F3 ] = "F3";
ourSDLMapping[ SDLK_F4 ] = "F4";
ourSDLMapping[ SDLK_F5 ] = "F5";
ourSDLMapping[ SDLK_F6 ] = "F6";
ourSDLMapping[ SDLK_F7 ] = "F7";
ourSDLMapping[ SDLK_F8 ] = "F8";
ourSDLMapping[ SDLK_F9 ] = "F9";
ourSDLMapping[ SDLK_F10 ] = "F10";
ourSDLMapping[ SDLK_F11 ] = "F11";
ourSDLMapping[ SDLK_F12 ] = "F12";
ourSDLMapping[ SDLK_F13 ] = "F13";
ourSDLMapping[ SDLK_F14 ] = "F14";
ourSDLMapping[ SDLK_F15 ] = "F15";
ourSDLMapping[ SDLK_NUMLOCK ] = "NUMLOCK";
ourSDLMapping[ SDLK_CAPSLOCK ] = "CAPSLOCK";
ourSDLMapping[ SDLK_SCROLLOCK ] = "SCROLLOCK";
ourSDLMapping[ SDLK_RSHIFT ] = "RSHIFT";
ourSDLMapping[ SDLK_LSHIFT ] = "LSHIFT";
ourSDLMapping[ SDLK_RCTRL ] = "RCTRL";
ourSDLMapping[ SDLK_LCTRL ] = "LCTRL";
ourSDLMapping[ SDLK_RALT ] = "RALT";
ourSDLMapping[ SDLK_LALT ] = "LALT";
ourSDLMapping[ SDLK_RMETA ] = "RMETA";
ourSDLMapping[ SDLK_LMETA ] = "LMETA";
ourSDLMapping[ SDLK_LSUPER ] = "LSUPER";
ourSDLMapping[ SDLK_RSUPER ] = "RSUPER";
ourSDLMapping[ SDLK_MODE ] = "MODE";
ourSDLMapping[ SDLK_COMPOSE ] = "COMPOSE";
ourSDLMapping[ SDLK_HELP ] = "HELP";
ourSDLMapping[ SDLK_PRINT ] = "PRINT";
ourSDLMapping[ SDLK_SYSREQ ] = "SYSREQ";
ourSDLMapping[ SDLK_BREAK ] = "BREAK";
ourSDLMapping[ SDLK_MENU ] = "MENU";
ourSDLMapping[ SDLK_POWER ] = "POWER";
ourSDLMapping[ SDLK_EURO ] = "EURO";
ourSDLMapping[ SDLK_UNDO ] = "UNDO";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ActionList EventHandler::ourActionList[58] = {
{ Event::ConsoleSelect, "Select", "" },
{ Event::ConsoleReset, "Reset", "" },
{ Event::ConsoleColor, "Color TV", "" },
{ Event::ConsoleBlackWhite, "Black & White TV", "" },
{ Event::ConsoleLeftDifficultyB, "Left Difficulty B", "" },
{ Event::ConsoleLeftDifficultyA, "Left Difficulty A", "" },
{ Event::ConsoleRightDifficultyB, "Right Difficulty B", "" },
{ Event::ConsoleLeftDifficultyB, "Left Difficulty B", "" },
{ Event::ConsoleRightDifficultyA, "Right Difficulty A", "" },
{ Event::ConsoleRightDifficultyB, "Right Difficulty B", "" },
{ Event::SaveState, "Save State", "" },
{ Event::ChangeState, "Change State", "" },
{ Event::LoadState, "Load State", "" },

View File

@ -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.21 2005-04-04 02:19:21 stephena Exp $
// $Id: EventHandler.hxx,v 1.22 2005-04-05 00:40:54 stephena Exp $
//============================================================================
#ifndef EVENTHANDLER_HXX
@ -41,7 +41,7 @@ enum MouseButton {
struct ActionList {
Event::Type event;
string action;
string keys;
string key;
};
/**
@ -57,7 +57,7 @@ struct ActionList {
mapping can take place.
@author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.21 2005-04-04 02:19:21 stephena Exp $
@version $Id: EventHandler.hxx,v 1.22 2005-04-05 00:40:54 stephena Exp $
*/
class EventHandler
{
@ -121,9 +121,6 @@ class EventHandler
// Holds static strings for the remap menu
static ActionList ourActionList[58];
void getKeymapArray(Event::Type** array, uInt32* size);
void getJoymapArray(Event::Type** array, uInt32* size);
private:
/**
Send an event directly to the event handler.
@ -168,12 +165,17 @@ class EventHandler
Int32 state);
/**
Sets the mouse to act as paddle 'which'
Sets the mouse to act as paddle 'num'
@param which The paddle which the mouse should emulate
@param num The paddle which the mouse should emulate
*/
void setPaddleMode(Int8 which);
void setPaddleMode(uInt32 num);
/**
The following methods take care of assigning action mappings.
*/
void setActionMappings();
void setSDLMappings();
void setKeymap();
void setJoymap();
void setDefaultKeymap();
@ -191,13 +193,7 @@ class EventHandler
OSystem* myOSystem;
// Array of key events, indexed by SDLKey
Event::Type myKeyTable[256];
// Array of alt-key events, indexed by SDLKey
Event::Type myAltKeyTable[256];
// Array of ctrl-key events, indexed by SDLKey
Event::Type myCtrlKeyTable[256];
Event::Type myKeyTable[SDLK_LAST];
// Array of joystick events
Event::Type myJoyTable[StellaEvent::LastJSTICK*StellaEvent::LastJCODE];
@ -205,6 +201,9 @@ class EventHandler
// Array of messages for each Event
string ourMessageTable[Event::LastType];
// Array of strings which correspond to the given SDL key
string ourSDLMapping[SDLK_LAST];
// Indicates the current state of the system (ie, which mode is current)
State myState;

View File

@ -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.24 2005-04-04 02:19:21 stephena Exp $
// $Id: FrameBuffer.cxx,v 1.25 2005-04-05 00:40:54 stephena Exp $
//============================================================================
#include <sstream>
@ -531,106 +531,6 @@ void FrameBuffer::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
}
/*
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::showMenu(bool show)
{
myMenuMode = show;
myCurrentWidget = show ? MAIN_MENU : W_NONE;
myRemapEventSelectedFlag = false;
mySelectedEvent = Event::NoType;
theRedrawEntireFrameIndicator = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline void FrameBuffer::drawMainMenu()
{
uInt32 x, y, width, height, i, xpos, ypos;
width = 16*FONTWIDTH + (FONTWIDTH << 1);
height = myMainMenuItems*LINEOFFSET + (FONTHEIGHT << 1);
x = (myWidth >> 1) - (width >> 1);
y = (myHeight >> 1) - (height >> 1);
// Draw the bounded box and text, leaving a little room for arrows
xpos = x + XBOXOFFSET;
box(x-2, y-2, width+3, height+3, kColor, kBGColor); //FIXME
for(i = 0; i < myMainMenuItems; i++)
drawText(xpos, LINEOFFSET*i + y + YBOXOFFSET, ourMainMenu[i].action);
// Now draw the selection arrow around the currently selected item
ypos = LINEOFFSET*myMainMenuIndex + y + YBOXOFFSET;
drawChar(x, ypos, LEFTARROW);
drawChar(x + width - FONTWIDTH, ypos, RIGHTARROW);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline void FrameBuffer::drawRemapMenu()
{
uInt32 x, y, width, height, xpos, ypos;
width = (myWidth >> 3) * FONTWIDTH - (FONTWIDTH << 1);
height = myMaxRows*LINEOFFSET + (FONTHEIGHT << 1);
x = (myWidth >> 1) - (width >> 1);
y = (myHeight >> 1) - (height >> 1);
// Draw the bounded box and text, leaving a little room for arrows
box(x-2, y-2, width+3, height+3, kColor, kBGColor); //FIXME
for(Int32 i = myRemapMenuLowIndex; i < myRemapMenuHighIndex; i++)
{
ypos = LINEOFFSET*(i-myRemapMenuLowIndex) + y + YBOXOFFSET;
drawText(x + XBOXOFFSET, ypos, ourRemapMenu[i].action);
xpos = width - ourRemapMenu[i].key.length() * FONTWIDTH;
drawText(xpos, ypos, ourRemapMenu[i].key);
}
// Normally draw an arrow indicating the current line,
// otherwise highlight the currently selected item for remapping
if(!myRemapEventSelectedFlag)
{
ypos = LINEOFFSET*(myRemapMenuIndex-myRemapMenuLowIndex) + y + YBOXOFFSET;
drawChar(x, ypos, LEFTARROW);
drawChar(x + width - FONTWIDTH, ypos, RIGHTARROW);
}
else
{
ypos = LINEOFFSET*(myRemapMenuIndex-myRemapMenuLowIndex) + y + YBOXOFFSET;
// Left marker is at the beginning of event name text
xpos = width - ourRemapMenu[myRemapMenuIndex].key.length() * FONTWIDTH - FONTWIDTH;
drawChar(xpos, ypos, LEFTMARKER);
// Right marker is at the end of the line
drawChar(x + width - FONTWIDTH, ypos, RIGHTMARKER);
}
// Finally, indicate that there are more items to the top or bottom
xpos = (width >> 1) - (FONTWIDTH >> 1);
if(myRemapMenuHighIndex - myMaxRows > 0)
drawChar(xpos, y, UPARROW);
if(myRemapMenuLowIndex + myMaxRows < myRemapMenuItems)
drawChar(xpos, height - (FONTWIDTH >> 1), DOWNARROW);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline void FrameBuffer::drawInfoMenu()
{
uInt32 x, y, width, height, i, xpos;
width = myInfoMenuWidth*FONTWIDTH + (FONTWIDTH << 1);
height = 9*LINEOFFSET + (FONTHEIGHT << 1);
x = (myWidth >> 1) - (width >> 1);
y = (myHeight >> 1) - (height >> 1);
// Draw the bounded box and text
xpos = x + XBOXOFFSET;
box(x, y, width, height, kColor, kBGColor); //FIXME
for(i = 0; i < 9; i++)
drawText(xpos, LINEOFFSET*i + y + YBOXOFFSET, ourPropertiesInfo[i]);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::sendKeyEvent(StellaEvent::KeyCode key, Int32 state)
{
@ -752,188 +652,6 @@ void FrameBuffer::sendJoyEvent(StellaEvent::JoyStick stick,
*/
/*
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBuffer::Widget FrameBuffer::currentSelectedWidget()
{
if(myMainMenuIndex >= 0 && myMainMenuIndex < myMainMenuItems)
return ourMainMenu[myMainMenuIndex].widget;
else
return W_NONE;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type FrameBuffer::currentSelectedEvent()
{
if(myRemapMenuIndex >= 0 && myRemapMenuIndex < myRemapMenuItems)
return ourRemapMenu[myRemapMenuIndex].event;
else
return Event::NoType;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::moveCursorUp(uInt32 amt)
{
switch(myCurrentWidget)
{
case MAIN_MENU:
if(myMainMenuIndex > 0)
myMainMenuIndex--;
break;
case REMAP_MENU:
// First move cursor up by the given amt
myRemapMenuIndex -= amt;
// Move up the boundaries
if(myRemapMenuIndex < myRemapMenuLowIndex)
{
Int32 x = myRemapMenuLowIndex - myRemapMenuIndex;
myRemapMenuLowIndex -= x;
myRemapMenuHighIndex -= x;
}
// Then scale back down, if necessary
if(myRemapMenuLowIndex < 0)
{
Int32 x = 0 - myRemapMenuLowIndex;
myRemapMenuIndex += x;
myRemapMenuLowIndex += x;
myRemapMenuHighIndex += x;
}
break;
default: // This should never happen
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::moveCursorDown(uInt32 amt)
{
switch(myCurrentWidget)
{
case MAIN_MENU:
if(myMainMenuIndex < myMainMenuItems - 1)
myMainMenuIndex++;
break;
case REMAP_MENU:
// First move cursor down by the given amount
myRemapMenuIndex += amt;
// Move down the boundaries
if(myRemapMenuIndex >= myRemapMenuHighIndex)
{
Int32 x = myRemapMenuIndex - myRemapMenuHighIndex + 1;
myRemapMenuLowIndex += x;
myRemapMenuHighIndex += x;
}
// Then scale back up, if necessary
if(myRemapMenuHighIndex >= myRemapMenuItems)
{
Int32 x = myRemapMenuHighIndex - myRemapMenuItems;
myRemapMenuIndex -= x;
myRemapMenuLowIndex -= x;
myRemapMenuHighIndex -= x;
}
break;
default: // This should never happen
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::loadRemapMenu()
{
// Fill the remap menu with the current key and joystick mappings
for(Int32 i = 0; i < myRemapMenuItems; ++i)
{
Event::Type event = ourRemapMenu[i].event;
ourRemapMenu[i].key = "None";
string key = "";
for(uInt32 j = 0; j < myKeyTableSize; ++j)
{
if(myKeyTable[j] == event)
{
if(key == "")
key = key + ourEventName[j];
else
key = key + ", " + ourEventName[j];
}
}
for(uInt32 j = 0; j < myJoyTableSize; ++j)
{
if(myJoyTable[j] == event)
{
ostringstream joyevent;
uInt32 stick = j / StellaEvent::LastJCODE;
uInt32 button = j % StellaEvent::LastJCODE;
switch(button)
{
case StellaEvent::JAXIS_UP:
joyevent << "J" << stick << " UP";
break;
case StellaEvent::JAXIS_DOWN:
joyevent << "J" << stick << " DOWN";
break;
case StellaEvent::JAXIS_LEFT:
joyevent << "J" << stick << " LEFT";
break;
case StellaEvent::JAXIS_RIGHT:
joyevent << "J" << stick << " RIGHT";
break;
default:
joyevent << "J" << stick << " B" << (button-4);
break;
}
if(key == "")
key = key + joyevent.str();
else
key = key + ", " + joyevent.str();
}
}
if(key != "")
{
// 19 is the max size of the event names, and 2 is for the space in between
// (this could probably be cleaner ...)
uInt32 len = myMaxColumns - 19 - 2;
if(key.length() > len)
{
ourRemapMenu[i].key = key.substr(0, len - 3) + "...";
}
else
ourRemapMenu[i].key = key;
}
}
// 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());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::addKeyBinding(Event::Type event, StellaEvent::KeyCode key)
{

View File

@ -13,17 +13,20 @@
// 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.1 2005-04-04 02:19:22 stephena Exp $
// $Id: EventMappingDialog.cxx,v 1.2 2005-04-05 00:40:55 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include <sstream>
#include "OSystem.hxx"
#include "Widget.hxx"
#include "ListWidget.hxx"
#include "Dialog.hxx"
#include "GuiUtils.hxx"
#include "Event.hxx"
#include "EventHandler.hxx"
#include "EventMappingDialog.hxx"
@ -32,26 +35,27 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventMappingDialog::EventMappingDialog(OSystem* osystem, uInt16 x, uInt16 y,
uInt16 w, uInt16 h)
: Dialog(osystem, x, y, w, h)
: Dialog(osystem, x, y, w, h),
myActionSelected(-1),
myRemapStatus(false)
{
// Add Previous, Next and Close buttons
addButton(10, h - 24, "Defaults", kDefaultsCmd, 0);
addButton(w - (kButtonWidth + 10), h - 24, "OK", kCloseCmd, 0);
// Add Default and OK buttons
myDefaultsButton = addButton(10, h - 24, "Defaults", kDefaultsCmd, 0);
myOKButton = addButton(w - (kButtonWidth + 10), h - 24, "OK", kCloseCmd, 0);
new StaticTextWidget(this, 10, 8, 200, 16, "Select an event to remap:", kTextAlignCenter);
myActionsList = new ListWidget(this, 10, 20, 200, 100);
myActionsList->setNumberingMode(kListNumberingOff);
string title = "Hello Test!";
myActionTitle = new StaticTextWidget(this, 10, 125, 200, 16, title, kTextAlignCenter);
myKeyMapping = new StaticTextWidget(this, 10, 130, 200, 16, "", kTextAlignCenter);
myActionTitle->setFlags(WIDGET_CLEARBG);
myKeyMapping = new StaticTextWidget(this, 10, 125, w - 20, 16,
"Key(s) : ", kTextAlignLeft);
myKeyMapping->setFlags(WIDGET_CLEARBG);
// Add remap and erase buttons
addButton(220, 30, "Map", kMapCmd, 0);
addButton(220, 50, "Erase", kEraseCmd, 0);
myMapButton = addButton(220, 30, "Map", kStartMapCmd, 0);
myEraseButton = addButton(220, 50, "Erase", kEraseCmd, 0);
myCancelMapButton = addButton(220, 70, "Cancel", kStopMapCmd, 0);
myCancelMapButton->setEnabled(false);
// Get actions names
StringList l;
@ -60,9 +64,6 @@ EventMappingDialog::EventMappingDialog(OSystem* osystem, uInt16 x, uInt16 y,
l.push_back(EventHandler::ourActionList[i].action);
myActionsList->setList(l);
myActionSelected = -1;
// CEActions::Instance()->beginMapping(false);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -70,10 +71,68 @@ EventMappingDialog::~EventMappingDialog()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingDialog::startRemapping()
{
if(myActionSelected < 0 || myRemapStatus)
return;
// Set the flags for the next event that arrives
myRemapStatus = true;
// Disable all other widgets while in remap mode, except enable 'Cancel'
myActionsList->setEnabled(false);
myMapButton->setEnabled(false);
myEraseButton->setEnabled(false);
myDefaultsButton->setEnabled(false);
myOKButton->setEnabled(false);
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());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingDialog::eraseRemapping()
{
if(myActionSelected < 0)
return;
else
cerr << "Erase item: " << myActionSelected << endl;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingDialog::stopRemapping()
{
// Turn off remap mode
myRemapStatus = false;
// And re-enable all the widgets
myActionsList->setEnabled(true);
myMapButton->setEnabled(true);
myEraseButton->setEnabled(true);
myDefaultsButton->setEnabled(true);
myOKButton->setEnabled(true);
myCancelMapButton->setEnabled(false);
// 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());
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingDialog::handleKeyDown(uInt16 ascii, Int32 keycode, Int32 modifiers)
{
cerr << "EventMappingDialog::handleKeyDown received: " << ascii << endl;
// cerr << "EventMappingDialog::handleKeyDown received: " << ascii << endl;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -84,23 +143,25 @@ void EventMappingDialog::handleCommand(CommandSender* sender, uInt32 cmd, uInt32
case kListSelectionChangedCmd:
if(myActionsList->getSelected() >= 0)
{
cerr << "Item selected: " << myActionsList->getSelected() << endl;
myActionSelected = myActionsList->getSelected();
ostringstream buf;
buf << "Key(s) : "
<< EventHandler::ourActionList[ myActionSelected ].key;
/* char selection[100];
sprintf(selection, "Associated key : %s", CEDevice::getKeyName(CEActions::Instance()->getMapping((ActionType)(_actionsList->getSelected() + 1))).c_str());
_keyMapping->setLabel(selection);
_keyMapping->draw();
*/
myKeyMapping->setLabel(buf.str());
}
break;
case kMapCmd:
cerr << "Remap item: " << myActionsList->getSelected() << endl;
case kStartMapCmd:
startRemapping();
break;
case kEraseCmd:
cerr << "Erase item: " << myActionsList->getSelected() << endl;
eraseRemapping();
break;
case kStopMapCmd:
stopRemapping();
break;
case kDefaultsCmd:

View File

@ -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.1 2005-04-04 02:19:22 stephena Exp $
// $Id: EventMappingDialog.hxx,v 1.2 2005-04-05 00:40:55 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -39,19 +39,35 @@ class EventMappingDialog : public Dialog
virtual void handleKeyDown(uInt16 ascii, Int32 keycode, Int32 modifiers);
protected:
ButtonWidget* myMapButton;
ButtonWidget* myCancelMapButton;
ButtonWidget* myEraseButton;
ButtonWidget* myOKButton;
ButtonWidget* myDefaultsButton;
ListWidget* myActionsList;
StaticTextWidget* myActionTitle;
StaticTextWidget* myKeyMapping;
Int32 myActionSelected;
private:
enum {
kStartMapCmd = 'map ',
kEraseCmd = 'eras',
kStopMapCmd = 'smap'
};
virtual void handleCommand(CommandSender* sender, uInt32 cmd, uInt32 data);
enum {
kMapCmd = 'map ',
kEraseCmd = 'eras'
};
void startRemapping();
void eraseRemapping();
void stopRemapping();
// void loadConfig() { }
private:
// Indicates the event that is currently selected
Int32 myActionSelected;
// Indicates if we're currently in remap mode
// In this mode, the next event received is remapped to some action
bool myRemapStatus;
};
#endif

View File

@ -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: OptionsDialog.cxx,v 1.9 2005-04-04 02:19:22 stephena Exp $
// $Id: OptionsDialog.cxx,v 1.10 2005-04-05 00:40:55 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -86,7 +86,7 @@ OptionsDialog::OptionsDialog(OSystem* osystem)
checkBounds(fbWidth, fbHeight, &x, &y, &w, &h);
myAudioDialog = new AudioDialog(myOSystem, x, y, w, h);
w = 280; h = 180;
w = 280; h = 170;
checkBounds(fbWidth, fbHeight, &x, &y, &w, &h);
myEventMappingDialog = new EventMappingDialog(myOSystem, x, y, w, h);