Added repeat functionality to joystick axis and button events when sending

UI events, similar to multiple key events.  Still TODO is add support for
joystick hats, and make sure these changes actually work in the GP2X port.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1107 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2006-05-25 22:23:39 +00:00
parent 7c4cb48c2e
commit e1da0e1d4c
2 changed files with 68 additions and 57 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: DialogContainer.cxx,v 1.32 2006-05-04 17:45:25 stephena Exp $
// $Id: DialogContainer.cxx,v 1.33 2006-05-25 22:23:39 stephena Exp $
//============================================================================
#include "OSystem.hxx"
@ -54,48 +54,37 @@ void DialogContainer::updateTime(uInt32 time)
// Check for pending continuous events and send them to the active dialog box
Dialog* activeDialog = myDialogStack.top();
// Key still pressed
if(myCurrentKeyDown.keycode != 0 && myKeyRepeatTime < myTime)
{
activeDialog->handleKeyDown(myCurrentKeyDown.ascii, myCurrentKeyDown.keycode,
myCurrentKeyDown.flags);
myKeyRepeatTime = myTime + kKeyRepeatSustainDelay;
myKeyRepeatTime = myTime + kRepeatSustainDelay;
}
// Mouse button still pressed
if(myCurrentMouseDown.button != -1 && myClickRepeatTime < myTime)
{
activeDialog->handleMouseDown(myCurrentMouseDown.x - activeDialog->_x,
myCurrentMouseDown.y - activeDialog->_y,
myCurrentMouseDown.button, 1);
myClickRepeatTime = myTime + kClickRepeatSustainDelay;
myClickRepeatTime = myTime + kRepeatSustainDelay;
}
/* FIXME - make this similar to the key-repeat code above
if(ourEnableJoyMouseFlag && myCurrentAxisDown.stick != -1 &&
myAxisRepeatTime < myTime)
// Joystick button still pressed
if(myCurrentButtonDown.stick != -1 && myButtonRepeatTime < myTime)
{
// The longer an axis event is enabled, the faster it should change
// We do this by decreasing the amount of time between consecutive axis events
// After a certain threshold, send 10 events at a time (this is necessary
// since at some point, we'd like to process more eventss than the
// current framerate allows)
myCurrentAxisDown.count++;
int interval = myCurrentAxisDown.count / 40 + 1;
myAxisRepeatTime = myTime + kAxisRepeatSustainDelay / interval;
if(interval > 3)
{
for(int i = 0; i < 10; ++i)
activeDialog->handleJoyAxis(myCurrentAxisDown.stick, myCurrentAxisDown.axis,
myCurrentAxisDown.value);
myAxisRepeatTime = myTime + kAxisRepeatSustainDelay / 3;
}
else
{
activeDialog->handleJoyAxis(myCurrentAxisDown.stick, myCurrentAxisDown.axis,
myCurrentAxisDown.value);
myAxisRepeatTime = myTime + kAxisRepeatSustainDelay / interval;
}
activeDialog->handleJoyDown(myCurrentButtonDown.stick, myCurrentButtonDown.button);
myButtonRepeatTime = myTime + kRepeatSustainDelay;
}
// Joystick axis still pressed
if(myCurrentAxisDown.stick != -1 && myAxisRepeatTime < myTime)
{
activeDialog->handleJoyAxis(myCurrentAxisDown.stick, myCurrentAxisDown.axis,
myCurrentAxisDown.value);
myAxisRepeatTime = myTime + kRepeatSustainDelay;
}
*/
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -167,7 +156,7 @@ void DialogContainer::handleKeyEvent(int unicode, int key, int mod, uInt8 state)
myCurrentKeyDown.ascii = unicode;
myCurrentKeyDown.keycode = key;
myCurrentKeyDown.flags = mod;
myKeyRepeatTime = myTime + kKeyRepeatInitialDelay;
myKeyRepeatTime = myTime + kRepeatInitialDelay;
activeDialog->handleKeyDown(unicode, key, mod);
}
@ -237,7 +226,7 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, int x, int y, uInt8
myCurrentMouseDown.x = x;
myCurrentMouseDown.y = y;
myCurrentMouseDown.button = button;
myClickRepeatTime = myTime + kClickRepeatInitialDelay;
myClickRepeatTime = myTime + kRepeatInitialDelay;
activeDialog->handleMouseDown(x - activeDialog->_x, y - activeDialog->_y,
button, myLastClick.count);
@ -272,9 +261,21 @@ void DialogContainer::handleJoyEvent(int stick, int button, uInt8 state)
Dialog* activeDialog = myDialogStack.top();
if(state == 1)
{
myCurrentButtonDown.stick = stick;
myCurrentButtonDown.button = button;
myButtonRepeatTime = myTime + kRepeatInitialDelay;
activeDialog->handleJoyDown(stick, button);
}
else
{
// Only stop firing events if it's the current button
if(stick == myCurrentButtonDown.stick)
myCurrentButtonDown.stick = myCurrentButtonDown.button = -1;
activeDialog->handleJoyUp(stick, button);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -297,7 +298,6 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value)
if(myCurrentAxisDown.stick == stick && value == 0)
{
myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1;
myCurrentAxisDown.count = 0;
}
else
{
@ -305,7 +305,7 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value)
myCurrentAxisDown.stick = stick;
myCurrentAxisDown.axis = axis;
myCurrentAxisDown.value = value;
myAxisRepeatTime = myTime + kAxisRepeatInitialDelay;
myAxisRepeatTime = myTime + kRepeatInitialDelay;
}
activeDialog->handleJoyAxis(stick, axis, value);
}
@ -319,7 +319,7 @@ 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();
// FIXME - add speedup processing, similar to axis events
// FIXME - add repeat processing, similar to axis/button events
activeDialog->handleJoyHat(stick, hat, value);
}
@ -332,6 +332,7 @@ void DialogContainer::reset()
myLastClick.time = 0;
myLastClick.count = 0;
myCurrentButtonDown.stick = myCurrentButtonDown.button = -1;
myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1;
myCurrentAxisDown.count = 0;
myCurrentHatDown.stick = myCurrentHatDown.hat = -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: DialogContainer.hxx,v 1.17 2006-05-04 17:45:25 stephena Exp $
// $Id: DialogContainer.hxx,v 1.18 2006-05-25 22:23:39 stephena Exp $
//============================================================================
#ifndef DIALOG_CONTAINER_HXX
@ -26,7 +26,6 @@ class OSystem;
#include "Stack.hxx"
#include "bspf.hxx"
typedef FixedStack<Dialog *> DialogStack;
/**
The base class for groups of dialog boxes. Each dialog box has a
@ -37,7 +36,7 @@ typedef FixedStack<Dialog *> DialogStack;
a stack, and handles their events.
@author Stephen Anthony
@version $Id: DialogContainer.hxx,v 1.17 2006-05-04 17:45:25 stephena Exp $
@version $Id: DialogContainer.hxx,v 1.18 2006-05-25 22:23:39 stephena Exp $
*/
class DialogContainer
{
@ -156,54 +155,65 @@ class DialogContainer
protected:
OSystem* myOSystem;
Dialog* myBaseDialog;
DialogStack myDialogStack;
FixedStack<Dialog *> myDialogStack;
private:
enum {
kDoubleClickDelay = 500,
kKeyRepeatInitialDelay = 400,
kKeyRepeatSustainDelay = 50,
kClickRepeatInitialDelay = kKeyRepeatInitialDelay,
kClickRepeatSustainDelay = kKeyRepeatSustainDelay,
kAxisRepeatInitialDelay = kKeyRepeatInitialDelay,
kAxisRepeatSustainDelay = kKeyRepeatSustainDelay
kDoubleClickDelay = 500,
kRepeatInitialDelay = 400,
kRepeatSustainDelay = 50
};
// Indicates the most current time (in milliseconds) as set by updateTime()
uInt32 myTime;
int myTime;
// Indicates a full refresh of all dialogs is required
bool myRefreshFlag;
// For continuous events (keyDown)
// For continuous 'key down' events
struct {
int ascii;
int keycode;
uInt8 flags;
int flags;
} myCurrentKeyDown;
uInt32 myKeyRepeatTime;
int myKeyRepeatTime;
// For continuous events (mouseDown)
// For continuous 'mouse down' events
struct {
int x;
int y;
int button;
} myCurrentMouseDown;
uInt32 myClickRepeatTime;
int myClickRepeatTime;
// For continuous events (joyaxisDown)
// For continuous 'joy button down' events
struct {
int stick;
int button;
} myCurrentButtonDown;
int myButtonRepeatTime;
// For continuous 'joy axis down' events
struct {
int stick;
int axis;
int value;
int count;
} myCurrentAxisDown;
uInt32 myAxisRepeatTime;
int myAxisRepeatTime;
// For continuous 'joy hat' events
struct {
int stick;
int hat;
int value;
} myCurrentHatDown;
int myHatRepeatTime;
// Position and time of last mouse click (used to detect double clicks)
struct {
int x, y; // Position of mouse when the click occured
uInt32 time; // Time
int count; // How often was it already pressed?
int x, y; // Position of mouse when the click occured
int time; // Time
int count; // How often was it already pressed?
} myLastClick;
};