Fix for the 'twitch' in the GP2X port when navigating the menus. It was

actually a deficiency in the GUI core, whereby joystick button events
were being translated to axis events, but the actual button events were
still being processed as well.  Now, if a button has been translated by
pollEvent(), it is removed from further processing in the main event
loop.

Also cleaned up the DialogContainer event logic a little.  Basically,
the code at that level should never do button to axis translation,
since that's port-specific and will be handled in the OSystemXXX class.

Fixed some errors in Makefile, where spaces were used instead of tabs.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1014 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2006-03-02 13:10:53 +00:00
parent e1995ea8b3
commit 6209912e4a
16 changed files with 92 additions and 178 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: Makefile,v 1.20 2006-03-02 04:55:55 azaballa Exp $
## $Id: Makefile,v 1.21 2006-03-02 13:10:53 stephena Exp $
##
## Based on code from ScummVM - Scumm Interpreter
## Copyright (C) 2002-2004 The ScummVM project

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.150 2006-01-30 01:01:44 stephena Exp $
// $Id: EventHandler.cxx,v 1.151 2006-03-02 13:10:53 stephena Exp $
//============================================================================
#include <sstream>
@ -659,31 +659,10 @@ void EventHandler::poll(uInt32 time)
int button = event.jbutton.button;
int state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
// Account for buttons which represent diagonal movement
// We just generate two equivalent button events representing
// combined movement
switch(button)
{
case kJDirUpLeft:
handleJoyEvent(stick, kJDirUp, state);
handleJoyEvent(stick, kJDirLeft, state);
break;
case kJDirDownLeft:
handleJoyEvent(stick, kJDirDown, state);
handleJoyEvent(stick, kJDirLeft, state);
break;
case kJDirDownRight:
handleJoyEvent(stick, kJDirDown, state);
handleJoyEvent(stick, kJDirRight, state);
break;
case kJDirUpRight:
handleJoyEvent(stick, kJDirUp, state);
handleJoyEvent(stick, kJDirRight, state);
break;
default:
// Filter out buttons handled by OSystem
if(!myOSystem->joyButtonHandled(button))
handleJoyEvent(stick, button, state);
break;
}
break; // Regular button
}

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.78 2006-01-31 17:26:56 stephena Exp $
// $Id: EventHandler.hxx,v 1.79 2006-03-02 13:10:53 stephena Exp $
//============================================================================
#ifndef EVENTHANDLER_HXX
@ -34,32 +34,6 @@ class DialogContainer;
class EventMappingWidget;
class EventStreamer;
// Used for those platforms which implement joystick directions
// as buttons instead of axis (which is a broken design IMHO)
// These are defined as constants vs. using platform-specific methods
// and variables for performance reasons
// Buttons not implemented for specific hardware are represented by numbers < 0,
// since no button can have those values (this isn't the cleanest code, but
// it *is* the fastest)
enum {
#if defined(GP2X)
kJDirUp = 0, kJDirUpLeft = 1,
kJDirLeft = 2, kJDirDownLeft = 3,
kJDirDown = 4, kJDirDownRight = 5,
kJDirRight = 6, kJDirUpRight = 7
#elif defined(PSP)
kJDirUp = 8, kJDirUpLeft = -1,
kJDirLeft = 7, kJDirDownLeft = -2,
kJDirDown = 6, kJDirDownRight = -3,
kJDirRight = 9, kJDirUpRight = -4
#else
kJDirUp = -1, kJDirUpLeft = -2,
kJDirLeft = -3, kJDirDownLeft = -4,
kJDirDown = -5, kJDirDownRight = -6,
kJDirRight = -7, kJDirUpRight = -8
#endif
};
// A wrapper around SDL hat events, so we don't drag SDL
// through all the child classes
enum JoyHat {
@ -133,7 +107,7 @@ struct JoyMouse {
mapping can take place.
@author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.78 2006-01-31 17:26:56 stephena Exp $
@version $Id: EventHandler.hxx,v 1.79 2006-03-02 13:10:53 stephena Exp $
*/
class EventHandler
{

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: OSystem.cxx,v 1.61 2006-02-22 17:38:04 stephena Exp $
// $Id: OSystem.cxx,v 1.62 2006-03-02 13:10:53 stephena Exp $
//============================================================================
#include <cassert>
@ -499,6 +499,14 @@ void OSystem::pollEvent()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystem::joyButtonHandled(int button)
{
// Since we don't do any platform-specific event polling,
// no button is ever handled at this level
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OSystem::OSystem(const OSystem& osystem)
{

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: OSystem.hxx,v 1.38 2006-02-22 17:38:04 stephena Exp $
// $Id: OSystem.hxx,v 1.39 2006-03-02 13:10:53 stephena Exp $
//============================================================================
#ifndef OSYSTEM_HXX
@ -44,7 +44,7 @@ class CheatManager;
other objects belong.
@author Stephen Anthony
@version $Id: OSystem.hxx,v 1.38 2006-02-22 17:38:04 stephena Exp $
@version $Id: OSystem.hxx,v 1.39 2006-03-02 13:10:53 stephena Exp $
*/
class OSystem
{
@ -357,6 +357,13 @@ class OSystem
*/
virtual void pollEvent();
/**
This method answers whether the given button as already been
handled by the pollEvent() method, and as such should be ignored
in the main event handler.
*/
virtual bool joyButtonHandled(int button);
protected:
/**
Set the base directory for all Stella files

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: OSystemGP2X.cxx,v 1.6 2006-02-02 01:04:09 stephena Exp $
// $Id: OSystemGP2X.cxx,v 1.7 2006-03-02 13:10:53 stephena Exp $
// Modified on 2006/01/06 by Alex Zaballa for use on GP2X
//============================================================================
@ -164,10 +164,6 @@ void OSystemGP2X::getScreenDimensions(int& width, int& height)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystemGP2X::setDefaultJoymap()
{
// myEventHandler->setDefaultJoyMapping(Event::JoystickZeroUp, 0, 0); // Up
// myEventHandler->setDefaultJoyMapping(Event::JoystickZeroLeft, 0, 2); // Left
// myEventHandler->setDefaultJoyMapping(Event::JoystickZeroDown, 0, 4); // Down
// myEventHandler->setDefaultJoyMapping(Event::JoystickZeroRight, 0, 6); // Right
myEventHandler->setDefaultJoyMapping(Event::LauncherMode, 0, 8); // Start
myEventHandler->setDefaultJoyMapping(Event::CmdMenuMode, 0, 9); // Select
myEventHandler->setDefaultJoyMapping(Event::ConsoleReset, 0, 10); // L
@ -213,7 +209,6 @@ void OSystemGP2X::pollEvent()
eventA0.axis = 0;
eventA1.axis = 1;
#if 1
bool axisZeroChanged = false, axisOneChanged = false;
axisOneChanged = axisOneChanged || myActiveEvents[kJDirUp];
@ -268,39 +263,11 @@ void OSystemGP2X::pollEvent()
if(axisZeroChanged) SDL_PushEvent((SDL_Event*)&eventA0);
if(axisOneChanged) SDL_PushEvent((SDL_Event*)&eventA1);
#else
if(myCurrentEvents[kJDirUp]) // up
eventA1.value = -32768;
if(myCurrentEvents[kJDirDown]) // down
eventA1.value = 32767;
if(myCurrentEvents[kJDirLeft]) // left
eventA0.value = -32768;
if(myCurrentEvents[kJDirRight]) // right
eventA0.value = 32767;
if(myCurrentEvents[kJDirUpLeft]) // up-left
{
eventA1.value = -16834;
eventA0.value = -16834;
}
if(myCurrentEvents[kJDirUpRight]) // up-right
{
eventA1.value = -16834;
eventA0.value = 16834;
}
if(myCurrentEvents[kJDirDownLeft]) // down-left
{
eventA1.value = 16834;
eventA0.value = -16834;
}
if(myCurrentEvents[kJDirDownRight]) // down-right
{
eventA1.value = 16834;
eventA0.value = 16834;
}
SDL_PushEvent((SDL_Event*)&eventA0);
SDL_PushEvent((SDL_Event*)&eventA1);
#endif
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystemGP2X::joyButtonHandled(int button)
{
return (button < 8);
}

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: OSystemGP2X.hxx,v 1.5 2006-02-02 01:04:09 stephena Exp $
// $Id: OSystemGP2X.hxx,v 1.6 2006-03-02 13:10:53 stephena Exp $
// Modified by Alex Zaballa on 2006/01/04 for use on GP2X
//============================================================================
@ -70,6 +70,13 @@ class OSystemGP2X : public OSystem
*/
void pollEvent();
/**
This method answers whether the given button as already been
handled by the pollEvent() method, and as such should be ignored
in the main event handler.
*/
bool joyButtonHandled(int button);
private:
enum {
kJDirUp = 0, kJDirUpLeft = 1,

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: Dialog.cxx,v 1.42 2006-02-22 17:38:04 stephena Exp $
// $Id: Dialog.cxx,v 1.43 2006-03-02 13:10:53 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -192,12 +192,6 @@ bool Dialog::wantsEvents()
return _focusedWidget && _focusedWidget->wantsEvents();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Dialog::wantsAllEvents()
{
return _focusedWidget && _focusedWidget->wantsAllEvents();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::draw()
{
@ -416,11 +410,10 @@ void Dialog::handleJoyAxis(int stick, int axis, int value)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleJoyHat(int stick, int hat, int value)
bool Dialog::handleJoyHat(int stick, int hat, int value)
{
// Focused widget receives joystick events
if(_focusedWidget)
_focusedWidget->handleJoyHat(stick, hat, value);
return (_focusedWidget && _focusedWidget->handleJoyHat(stick, hat, value));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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: Dialog.hxx,v 1.27 2006-02-22 17:38:04 stephena Exp $
// $Id: Dialog.hxx,v 1.28 2006-03-02 13:10:53 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -36,7 +36,7 @@ class TabWidget;
This is the base class for all dialog boxes.
@author Stephen Anthony
@version $Id: Dialog.hxx,v 1.27 2006-02-22 17:38:04 stephena Exp $
@version $Id: Dialog.hxx,v 1.28 2006-03-02 13:10:53 stephena Exp $
*/
class Dialog : public GuiObject
{
@ -82,16 +82,13 @@ class Dialog : public GuiObject
virtual void handleJoyDown(int stick, int button);
virtual void handleJoyUp(int stick, int button);
virtual void handleJoyAxis(int stick, int axis, int value);
virtual void handleJoyHat(int stick, int hat, int value);
virtual bool handleJoyHat(int stick, int hat, int value);
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
virtual void handleScreenChanged() {}
/** The dialog wants all events except those that have some special function */
/** The dialog wants all events */
virtual bool wantsEvents();
/** The dialog wants all events, without exception */
virtual bool wantsAllEvents();
Widget* findWidget(int x, int y); // Find the widget at pos x,y if any
ButtonWidget* addButton(const GUI::Font& font, int x, int y,

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: DialogContainer.cxx,v 1.30 2006-01-09 19:30:04 stephena Exp $
// $Id: DialogContainer.cxx,v 1.31 2006-03-02 13:10:53 stephena Exp $
//============================================================================
#include "OSystem.hxx"
@ -277,34 +277,6 @@ void DialogContainer::handleJoyEvent(int stick, int button, uInt8 state)
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
// Only preprocess button events if the dialog absolutely doesn't want them
if(!activeDialog->wantsAllEvents())
{
// Some buttons act as directions. In those cases, translate them
// to axis events instead of mouse button events
int value = state > 0 ? 32767 : 0;
bool handled = true;
switch(button)
{
case kJDirUp:
handleJoyAxisEvent(stick, 1, -value); // axis 1, -value ==> UP
break;
case kJDirLeft:
handleJoyAxisEvent(stick, 0, -value); // axis 0, -value ==> LEFT
break;
case kJDirDown:
handleJoyAxisEvent(stick, 1, value); // axis 1, +value ==> DOWN
break;
case kJDirRight:
handleJoyAxisEvent(stick, 0, value); // axis 0, +value ==> RIGHT
break;
default:
handled = false;
}
if(handled)
return;
}
if(activeDialog->wantsEvents())
{
if(state == 1)
@ -395,9 +367,8 @@ void DialogContainer::handleJoyHatEvent(int stick, int hat, int value)
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
// Only preprocess hat events if the dialog absolutely doesn't want them
// Translate to axis events for movement
if(!activeDialog->wantsAllEvents())
if(!(activeDialog->wantsEvents() &&
activeDialog->handleJoyHat(stick, hat, value)))
{
bool handled = true;
switch(value)
@ -424,9 +395,6 @@ void DialogContainer::handleJoyHatEvent(int stick, int hat, int value)
if(handled)
return;
}
if(activeDialog->wantsEvents())
activeDialog->handleJoyHat(stick, hat, value);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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: EventMappingWidget.cxx,v 1.12 2006-02-22 17:38:04 stephena Exp $
// $Id: EventMappingWidget.cxx,v 1.13 2006-03-02 13:10:53 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -135,7 +135,7 @@ void EventMappingWidget::startRemapping()
// Make sure that this widget receives all events,
// and they aren't handled anywhere else
myActionsList->setFlags(WIDGET_WANTS_EVENTS|WIDGET_WTALL_EVENTS);
myActionsList->setFlags(WIDGET_WANTS_EVENTS);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -172,7 +172,7 @@ void EventMappingWidget::stopRemapping()
}
// Widget is now free to process events normally
myActionsList->clearFlags(WIDGET_WANTS_EVENTS|WIDGET_WTALL_EVENTS);
myActionsList->clearFlags(WIDGET_WANTS_EVENTS);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -224,15 +224,22 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingWidget::handleJoyHat(int stick, int hat, int value)
bool EventMappingWidget::handleJoyHat(int stick, int hat, int value)
{
bool result = false;
// Remap joystick hats in remap mode
if(myRemapStatus && myActionSelected >= 0)
{
Event::Type event = EventHandler::ourActionList[ myActionSelected ].event;
if(instance()->eventHandler().addJoyHatMapping(event, stick, hat, value))
{
stopRemapping();
result = true;
}
}
return result;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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: EventMappingWidget.hxx,v 1.7 2006-02-22 17:38:04 stephena Exp $
// $Id: EventMappingWidget.hxx,v 1.8 2006-03-02 13:10:53 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -48,7 +48,7 @@ class EventMappingWidget : public Widget, public CommandSender
virtual bool handleKeyDown(int ascii, int keycode, int modifiers);
virtual void handleJoyDown(int stick, int button);
virtual void handleJoyAxis(int stick, int axis, int value);
virtual void handleJoyHat(int stick, int hat, int value);
virtual bool handleJoyHat(int stick, int hat, int value);
bool remapMode() { return myRemapStatus; }

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: InputDialog.cxx,v 1.11 2006-02-22 17:38:04 stephena Exp $
// $Id: InputDialog.cxx,v 1.12 2006-03-02 13:10:53 stephena Exp $
//============================================================================
#include "OSystem.hxx"
@ -246,13 +246,13 @@ void InputDialog::handleJoyAxis(int stick, int axis, int value)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputDialog::handleJoyHat(int stick, int hat, int value)
bool InputDialog::handleJoyHat(int stick, int hat, int value)
{
// Remap joystick hat in remap mode, otherwise pass to listwidget
if(myEventMapper->remapMode())
myEventMapper->handleJoyHat(stick, hat, value);
return myEventMapper->handleJoyHat(stick, hat, value);
else
Dialog::handleJoyHat(stick, hat, value);
return Dialog::handleJoyHat(stick, hat, value);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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: InputDialog.hxx,v 1.6 2006-02-22 17:38:04 stephena Exp $
// $Id: InputDialog.hxx,v 1.7 2006-03-02 13:10:53 stephena Exp $
//============================================================================
#ifndef INPUT_DIALOG_HXX
@ -42,7 +42,7 @@ class InputDialog : public Dialog
virtual void handleKeyDown(int ascii, int keycode, int modifiers);
virtual void handleJoyDown(int stick, int button);
virtual void handleJoyAxis(int stick, int axis, int value);
virtual void handleJoyHat(int stick, int hat, int value);
virtual bool handleJoyHat(int stick, int hat, int value);
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
void loadConfig();

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: Widget.hxx,v 1.47 2006-02-22 17:38:04 stephena Exp $
// $Id: Widget.hxx,v 1.48 2006-03-02 13:10:53 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -47,8 +47,7 @@ enum {
WIDGET_NODRAW_FOCUS = 1 << 8,
WIDGET_STICKY_FOCUS = 1 << 9,
WIDGET_WANTS_TAB = 1 << 10,
WIDGET_WANTS_EVENTS = 1 << 11,
WIDGET_WTALL_EVENTS = 1 << 12
WIDGET_WANTS_EVENTS = 1 << 11
};
enum {
@ -76,7 +75,7 @@ enum {
This is the base class for all widgets.
@author Stephen Anthony
@version $Id: Widget.hxx,v 1.47 2006-02-22 17:38:04 stephena Exp $
@version $Id: Widget.hxx,v 1.48 2006-03-02 13:10:53 stephena Exp $
*/
class Widget : public GuiObject
{
@ -100,7 +99,7 @@ class Widget : public GuiObject
virtual void handleJoyDown(int stick, int button) {}
virtual void handleJoyUp(int stick, int button) {}
virtual void handleJoyAxis(int stick, int axis, int value) {}
virtual void handleJoyHat(int stick, int hat, int value) {}
virtual bool handleJoyHat(int stick, int hat, int value) { return false; }
void draw();
void receivedFocus();
@ -121,7 +120,6 @@ class Widget : public GuiObject
bool isVisible() const { return !(_flags & WIDGET_INVISIBLE); }
bool isSticky() const { return _flags & WIDGET_STICKY_FOCUS; }
bool wantsEvents() const { return _flags & WIDGET_WANTS_EVENTS; }
bool wantsAllEvents() const { return _flags & WIDGET_WTALL_EVENTS; }
void setID(int id) { _id = id; }
int getID() { return _id; }

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: OSystemPSP.hxx,v 1.3 2006-01-08 02:28:04 stephena Exp $
// $Id: OSystemPSP.hxx,v 1.4 2006-03-02 13:10:53 stephena Exp $
//============================================================================
#ifndef OSYSTEM_PSP_HXX
@ -26,7 +26,7 @@
This class defines PSP-specific settings.
@author Stephen Anthony
@version $Id: OSystemPSP.hxx,v 1.3 2006-01-08 02:28:04 stephena Exp $
@version $Id: OSystemPSP.hxx,v 1.4 2006-03-02 13:10:53 stephena Exp $
*/
class OSystemPSP : public OSystem
{
@ -74,4 +74,13 @@ class OSystemPSP : public OSystem
virtual void getScreenDimensions(int& width, int& height);
};
// FIXME - this doesn't even compile any more ...
/*
kJDirUp = 8, kJDirUpLeft = -1,
kJDirLeft = 7, kJDirDownLeft = -2,
kJDirDown = 6, kJDirDownRight = -3,
kJDirRight = 9, kJDirUpRight = -4
*/
#endif