mirror of https://github.com/stella-emu/stella.git
Tweaked navigating the UI with a joystick, particularly with analog
axes. It shouldn't be nearly as sensitive now. Cleaned up handling of joystick hats, and fixed continuous events (so that holding down a hat now sends continuous events until the hat is centered again). Fixed bug in prune_snapshots script; it didn't work with a snapshot directory name containing a space. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2062 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
d217b49f88
commit
e0376c85d2
|
@ -713,7 +713,6 @@ void EventHandler::poll(uInt64 time)
|
|||
// (only pass on the event if the state has changed)
|
||||
if(value != myAxisLastValue[stick][axis])
|
||||
{
|
||||
// cerr << value << " @ " << COUNTER++ << "(" << stick << "/" << axis << ")" << endl;
|
||||
myOverlay->handleJoyAxisEvent(stick, axis, value);
|
||||
myAxisLastValue[stick][axis] = value;
|
||||
}
|
||||
|
@ -750,17 +749,17 @@ void EventHandler::poll(uInt64 time)
|
|||
// Generate two equivalent hat events representing combined direction
|
||||
// when we get a diagonal hat event
|
||||
if(value == SDL_HAT_CENTERED)
|
||||
handleJoyHatEvent(stick, hat, kJHatCentered);
|
||||
handleJoyHatEvent(stick, hat, EVENT_HATCENTER);
|
||||
else
|
||||
{
|
||||
if(value & SDL_HAT_UP)
|
||||
handleJoyHatEvent(stick, hat, kJHatUp);
|
||||
handleJoyHatEvent(stick, hat, EVENT_HATUP);
|
||||
if(value & SDL_HAT_RIGHT)
|
||||
handleJoyHatEvent(stick, hat, kJHatRight);
|
||||
handleJoyHatEvent(stick, hat, EVENT_HATRIGHT);
|
||||
if(value & SDL_HAT_DOWN)
|
||||
handleJoyHatEvent(stick, hat, kJHatDown);
|
||||
handleJoyHatEvent(stick, hat, EVENT_HATDOWN);
|
||||
if(value & SDL_HAT_LEFT)
|
||||
handleJoyHatEvent(stick, hat, kJHatLeft);
|
||||
handleJoyHatEvent(stick, hat, EVENT_HATLEFT);
|
||||
}
|
||||
break; // SDL_JOYHATMOTION
|
||||
}
|
||||
|
@ -928,19 +927,19 @@ void EventHandler::handleJoyAxisEvent(int stick, int axis, int value)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventHandler::handleJoyHatEvent(int stick, int hat, int value)
|
||||
void EventHandler::handleJoyHatEvent(int stick, int hat, JoyHat value)
|
||||
{
|
||||
#ifdef JOYSTICK_SUPPORT
|
||||
if(myState == S_EMULATE)
|
||||
{
|
||||
if(value == kJHatCentered)
|
||||
if(value == EVENT_HATCENTER)
|
||||
{
|
||||
// Turn off all associated events, since we don't know exactly
|
||||
// which one was previously activated.
|
||||
handleEvent(myJoyHatTable[stick][hat][0][kEmulationMode], 0);
|
||||
handleEvent(myJoyHatTable[stick][hat][1][kEmulationMode], 0);
|
||||
handleEvent(myJoyHatTable[stick][hat][2][kEmulationMode], 0);
|
||||
handleEvent(myJoyHatTable[stick][hat][3][kEmulationMode], 0);
|
||||
handleEvent(myJoyHatTable[stick][hat][EVENT_HATUP] [kEmulationMode], 0);
|
||||
handleEvent(myJoyHatTable[stick][hat][EVENT_HATDOWN] [kEmulationMode], 0);
|
||||
handleEvent(myJoyHatTable[stick][hat][EVENT_HATLEFT] [kEmulationMode], 0);
|
||||
handleEvent(myJoyHatTable[stick][hat][EVENT_HATRIGHT][kEmulationMode], 0);
|
||||
}
|
||||
else
|
||||
handleEvent(myJoyHatTable[stick][hat][value][kEmulationMode], 1);
|
||||
|
@ -1221,10 +1220,10 @@ void EventHandler::setActionMappings(EventMode mode)
|
|||
buf << "J" << stick << " hat " << hat;
|
||||
switch(dir)
|
||||
{
|
||||
case kJHatUp: buf << " up"; break;
|
||||
case kJHatDown: buf << " down"; break;
|
||||
case kJHatLeft: buf << " left"; break;
|
||||
case kJHatRight: buf << " right"; break;
|
||||
case EVENT_HATUP: buf << " up"; break;
|
||||
case EVENT_HATDOWN: buf << " down"; break;
|
||||
case EVENT_HATLEFT: buf << " left"; break;
|
||||
case EVENT_HATRIGHT: buf << " right"; break;
|
||||
}
|
||||
if(key == "")
|
||||
key = key + buf.str();
|
||||
|
@ -1440,17 +1439,10 @@ void EventHandler::setDefaultJoyHatMapping(Event::Type event, EventMode mode,
|
|||
{
|
||||
if(stick >= 0 && stick < kNumJoysticks &&
|
||||
hat >= 0 && hat < kNumJoyHats &&
|
||||
event >= 0 && event < Event::LastType)
|
||||
event >= 0 && event < Event::LastType &&
|
||||
value != EVENT_HATCENTER)
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case kJHatUp:
|
||||
case kJHatDown:
|
||||
case kJHatLeft:
|
||||
case kJHatRight:
|
||||
myJoyHatTable[stick][hat][value][mode] = event;
|
||||
break;
|
||||
}
|
||||
myJoyHatTable[stick][hat][value][mode] = event;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,14 @@ enum MouseButton {
|
|||
EVENT_WHEELUP
|
||||
};
|
||||
|
||||
enum JoyHat {
|
||||
EVENT_HATUP = 0, // make sure these are set correctly,
|
||||
EVENT_HATDOWN = 1, // since they'll be used as array indices
|
||||
EVENT_HATLEFT = 2,
|
||||
EVENT_HATRIGHT = 3,
|
||||
EVENT_HATCENTER = 4
|
||||
};
|
||||
|
||||
enum EventMode {
|
||||
kEmulationMode = 0, // make sure these are set correctly,
|
||||
kMenuMode = 1, // since they'll be used as array indices
|
||||
|
@ -353,10 +361,10 @@ class EventHandler
|
|||
Send a joystick hat event to the handler
|
||||
|
||||
@param stick The joystick number
|
||||
@param axis The joystick hat
|
||||
@param hat The joystick hat
|
||||
@param value The value on the given hat
|
||||
*/
|
||||
void handleJoyHatEvent(int stick, int hat, int value);
|
||||
void handleJoyHatEvent(int stick, int hat, JoyHat value);
|
||||
|
||||
/**
|
||||
Detects and changes the eventhandler state
|
||||
|
@ -436,13 +444,6 @@ class EventHandler
|
|||
JoyType type;
|
||||
string name;
|
||||
};
|
||||
enum JoyHat {
|
||||
kJHatUp,
|
||||
kJHatDown,
|
||||
kJHatLeft,
|
||||
kJHatRight,
|
||||
kJHatCentered
|
||||
};
|
||||
struct JoyMouse { // Used for joystick to mouse emulation
|
||||
bool active;
|
||||
int x, y, x_amt, y_amt, amt, val, old_val;
|
||||
|
@ -467,6 +468,8 @@ class EventHandler
|
|||
Event::Type myJoyAxisTable[kNumJoysticks][kNumJoyAxis][2][kNumModes];
|
||||
|
||||
// Array of joystick hat events (we don't record diagonals)
|
||||
// Note that the array contains 4 directions, as defined in the JoyHat enum
|
||||
// (the center isn't considered a direction)
|
||||
Event::Type myJoyHatTable[kNumJoysticks][kNumJoyHats][4][kNumModes];
|
||||
|
||||
// Array of messages for each Event
|
||||
|
|
|
@ -756,7 +756,7 @@ uInt8* OSystem::openROM(string file, string& md5, uInt32& size)
|
|||
if(strlen(filename) >= 4)
|
||||
{
|
||||
// Grab 3-character extension
|
||||
char* ext = filename + strlen(filename) - 4;
|
||||
const char* ext = filename + strlen(filename) - 4;
|
||||
|
||||
if(BSPF_equalsIgnoreCase(ext, ".a26") || BSPF_equalsIgnoreCase(ext, ".bin") ||
|
||||
BSPF_equalsIgnoreCase(ext, ".rom"))
|
||||
|
@ -782,7 +782,7 @@ uInt8* OSystem::openROM(string file, string& md5, uInt32& size)
|
|||
|
||||
// We don't have to check for any return errors from these functions,
|
||||
// since if there are, 'image' will not contain a valid ROM and the
|
||||
// calling method can take of it
|
||||
// calling method can take care of it
|
||||
unzOpenCurrentFile(tz);
|
||||
unzReadCurrentFile(tz, image, size);
|
||||
unzCloseCurrentFile(tz);
|
||||
|
@ -865,6 +865,12 @@ void OSystem::setDefaultJoymap()
|
|||
myEventHandler->setDefaultJoyMapping(Event::JoystickZeroFire1, mode, 0, 0);
|
||||
// Right joystick (assume joystick one, button zero)
|
||||
myEventHandler->setDefaultJoyMapping(Event::JoystickOneFire1, mode, 1, 0);
|
||||
|
||||
mode = kMenuMode; // Default menu/UI events
|
||||
// Left joystick (assume joystick zero, button zero)
|
||||
myEventHandler->setDefaultJoyMapping(Event::UISelect, mode, 0, 0);
|
||||
// Right joystick (assume joystick one, button zero)
|
||||
myEventHandler->setDefaultJoyMapping(Event::UISelect, mode, 1, 0);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -896,14 +902,21 @@ void OSystem::setDefaultJoyAxisMap()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void OSystem::setDefaultJoyHatMap()
|
||||
{
|
||||
// FIXME - add emulation events
|
||||
EventMode mode;
|
||||
|
||||
mode = kEmulationMode; // Default emulation events
|
||||
// Left joystick left/right directions (assume joystick zero and hat 0)
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::JoystickZeroLeft, mode, 0, 0, EVENT_HATLEFT);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::JoystickZeroRight, mode, 0, 0, EVENT_HATRIGHT);
|
||||
// Left joystick up/down directions (assume joystick zero and hat 0)
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::JoystickZeroUp, mode, 0, 0, EVENT_HATUP);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::JoystickZeroDown, mode, 0, 0, EVENT_HATDOWN);
|
||||
|
||||
mode = kMenuMode; // Default menu/UI events
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UILeft, mode, 0, 0, 2);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UIRight, mode, 0, 0, 3);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UIUp, mode, 0, 0, 0);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UIDown, mode, 0, 0, 1);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UILeft, mode, 0, 0, EVENT_HATLEFT);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UIRight, mode, 0, 0, EVENT_HATRIGHT);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UIUp, mode, 0, 0, EVENT_HATUP);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UIDown, mode, 0, 0, EVENT_HATDOWN);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -310,13 +310,13 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void DialogContainer::handleJoyHatEvent(int stick, int hat, int value)
|
||||
void DialogContainer::handleJoyHatEvent(int stick, int hat, JoyHat value)
|
||||
{
|
||||
if(myDialogStack.empty())
|
||||
return;
|
||||
|
||||
// Only stop firing events if it's the current stick
|
||||
if(myCurrentHatDown.stick == stick && value == 0)
|
||||
if(myCurrentHatDown.stick == stick && value == EVENT_HATCENTER)
|
||||
{
|
||||
myCurrentHatDown.stick = myCurrentHatDown.hat = -1;
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ class DialogContainer
|
|||
@param axis The joystick hat
|
||||
@param value Value associated with given hat
|
||||
*/
|
||||
void handleJoyHatEvent(int stick, int hat, int value);
|
||||
void handleJoyHatEvent(int stick, int hat, JoyHat value);
|
||||
|
||||
/**
|
||||
Draw the stack of menus (full indicates to redraw all items).
|
||||
|
|
|
@ -221,13 +221,11 @@ bool TabWidget::handleEvent(Event::Type event)
|
|||
|
||||
switch (event)
|
||||
{
|
||||
case Event::UIDown:
|
||||
case Event::UIRight:
|
||||
case Event::UIPgDown:
|
||||
cycleTab(1);
|
||||
handled = true;
|
||||
break;
|
||||
case Event::UIUp:
|
||||
case Event::UILeft:
|
||||
case Event::UIPgUp:
|
||||
cycleTab(-1);
|
||||
|
|
|
@ -618,13 +618,11 @@ bool SliderWidget::handleEvent(Event::Type e)
|
|||
|
||||
switch(e)
|
||||
{
|
||||
case Event::UILeft:
|
||||
case Event::UIDown:
|
||||
case Event::UIPgDown:
|
||||
setValue(_value - _stepValue);
|
||||
break;
|
||||
|
||||
case Event::UIRight:
|
||||
case Event::UIUp:
|
||||
case Event::UIPgUp:
|
||||
setValue(_value + _stepValue);
|
||||
|
|
|
@ -28,7 +28,7 @@ close(INFILE);
|
|||
|
||||
# Get all snapshot files from the actual directory (second commandline arg)
|
||||
# We use a hashmap to get constant lookup time
|
||||
my @files = <$ARGV[1]/*>;
|
||||
my @files = <"$ARGV[1]/*">;
|
||||
foreach $file (@files)
|
||||
{
|
||||
($base,$path,$type) = fileparse($file);
|
||||
|
|
Loading…
Reference in New Issue