Added joystick is mouse navigation back, but placed it in DialogContainer

(where it really belongs).  So the GUI is fully navigable using the joystick.
Joystick axes emulate mouse movement, and joystick buttons emulate a left
mouse click.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@924 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-12-24 22:09:36 +00:00
parent 8a74c4776e
commit 2a8d708620
11 changed files with 321 additions and 119 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventHandler.cxx,v 1.133 2005-12-20 00:56:31 stephena Exp $ // $Id: EventHandler.cxx,v 1.134 2005-12-24 22:09:36 stephena Exp $
//============================================================================ //============================================================================
#include <sstream> #include <sstream>
@ -126,9 +126,6 @@ EventHandler::EventHandler(OSystem* osystem)
setPaddleMode(myOSystem->settings().getInt("paddle"), false); setPaddleMode(myOSystem->settings().getInt("paddle"), false);
myFryingFlag = false; myFryingFlag = false;
memset(&myJoyMouse, 0, sizeof(myJoyMouse));
myJoyMouse.delay_time = 25;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -176,7 +173,7 @@ void EventHandler::reset(State state)
// Start paddle emulation in a known state // Start paddle emulation in a known state
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
{ {
memset(&myPaddle[i], 0, sizeof(myJoyMouse)); memset(&myPaddle[i], 0, sizeof(JoyMouse));
myEvent->set(Paddle_Resistance[i], 1000000); myEvent->set(Paddle_Resistance[i], 1000000);
} }
setPaddleSpeed(0, myOSystem->settings().getInt("p1speed")); setPaddleSpeed(0, myOSystem->settings().getInt("p1speed"));
@ -189,9 +186,9 @@ void EventHandler::reset(State state)
void EventHandler::refreshDisplay() void EventHandler::refreshDisplay()
{ {
// These are reset each time the display changes size // These are reset each time the display changes size
myJoyMouse.x_max = myOSystem->frameBuffer().imageWidth(); DialogContainer::ourJoyMouse.x_max = myOSystem->frameBuffer().imageWidth();
myJoyMouse.y_max = myOSystem->frameBuffer().imageHeight(); DialogContainer::ourJoyMouse.y_max = myOSystem->frameBuffer().imageHeight();
myJoyMouse.amt = myOSystem->frameBuffer().zoomLevel() * 3; DialogContainer::ourJoyMouse.amt = myOSystem->frameBuffer().zoomLevel() * 3;
switch(myState) switch(myState)
{ {
@ -766,7 +763,7 @@ void EventHandler::poll(uInt32 time)
// Update the current dialog container at regular intervals // Update the current dialog container at regular intervals
// Used to implement continuous events // Used to implement continuous events
if(myOverlay) if(myState != S_EMULATE && myOverlay)
myOverlay->updateTime(time); myOverlay->updateTime(time);
#ifdef CHEATCODE_SUPPORT #ifdef CHEATCODE_SUPPORT
@ -785,91 +782,60 @@ void EventHandler::handleMouseMotionEvent(SDL_Event& event)
{ {
// Take window zooming into account // Take window zooming into account
int x = event.motion.x, y = event.motion.y; int x = event.motion.x, y = event.motion.y;
myJoyMouse.x = x; DialogContainer::ourJoyMouse.x = x;
myJoyMouse.y = y; DialogContainer::ourJoyMouse.y = y;
myOSystem->frameBuffer().translateCoords(&x, &y); myOSystem->frameBuffer().translateCoords(&x, &y);
// Determine which mode we're in, then send the event to the appropriate place // Determine which mode we're in, then send the event to the appropriate place
switch(myState) if(myState == S_EMULATE)
{ {
case S_EMULATE: int w = myOSystem->frameBuffer().baseWidth();
{
int w = myOSystem->frameBuffer().baseWidth();
// Grabmouse introduces some lag into the mouse movement, // Grabmouse introduces some lag into the mouse movement,
// so we need to fudge the numbers a bit // so we need to fudge the numbers a bit
if(myGrabMouseFlag) x = MIN(w, (int) (x * 1.5)); if(myGrabMouseFlag) x = MIN(w, (int) (x * 1.5));
int resistance = (int)(1000000.0 * (w - x) / w); int resistance = (int)(1000000.0 * (w - x) / w);
myEvent->set(Paddle_Resistance[myPaddleMode], resistance); myEvent->set(Paddle_Resistance[myPaddleMode], resistance);
break;
}
case S_MENU:
case S_CMDMENU:
case S_LAUNCHER:
case S_DEBUGGER:
myOverlay->handleMouseMotionEvent(x, y, 0);
break;
default:
return;
break;
} }
else if(myOverlay)
myOverlay->handleMouseMotionEvent(x, y, 0);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleMouseButtonEvent(SDL_Event& event, int state) void EventHandler::handleMouseButtonEvent(SDL_Event& event, int state)
{ {
// Determine which mode we're in, then send the event to the appropriate place // Determine which mode we're in, then send the event to the appropriate place
switch(myState) if(myState == S_EMULATE)
myEvent->set(Paddle_Button[myPaddleMode], state);
else if(myOverlay)
{ {
case S_EMULATE: // Take window zooming into account
handleEvent(Paddle_Button[myPaddleMode], state); Int32 x = event.button.x, y = event.button.y;
break;
case S_MENU:
case S_CMDMENU:
case S_LAUNCHER:
case S_DEBUGGER:
{
// Take window zooming into account
Int32 x = event.button.x, y = event.button.y;
//if (state) cerr << "B: x = " << x << ", y = " << y << endl; //if (state) cerr << "B: x = " << x << ", y = " << y << endl;
myOSystem->frameBuffer().translateCoords(&x, &y); myOSystem->frameBuffer().translateCoords(&x, &y);
//if (state) cerr << "A: x = " << x << ", y = " << y << endl << endl; //if (state) cerr << "A: x = " << x << ", y = " << y << endl << endl;
MouseButton button; MouseButton button;
if(state == 1) switch(event.button.button)
{ {
if(event.button.button == SDL_BUTTON_LEFT) case SDL_BUTTON_LEFT:
button = EVENT_LBUTTONDOWN; button = state ? EVENT_LBUTTONDOWN : EVENT_LBUTTONUP;
else if(event.button.button == SDL_BUTTON_RIGHT) break;
button = EVENT_RBUTTONDOWN; case SDL_BUTTON_RIGHT:
else if(event.button.button == SDL_BUTTON_WHEELUP) button = state ? EVENT_RBUTTONDOWN : EVENT_RBUTTONUP;
button = EVENT_WHEELUP; break;
else if(event.button.button == SDL_BUTTON_WHEELDOWN) case SDL_BUTTON_WHEELDOWN:
button = EVENT_WHEELDOWN; button = EVENT_WHEELDOWN;
else break;
break; case SDL_BUTTON_WHEELUP:
} button = EVENT_WHEELUP;
else break;
{ default:
if(event.button.button == SDL_BUTTON_LEFT) return;
button = EVENT_LBUTTONUP;
else if(event.button.button == SDL_BUTTON_RIGHT)
button = EVENT_RBUTTONUP;
else
break;
}
myOverlay->handleMouseButtonEvent(button, x, y, state);
break;
} }
myOverlay->handleMouseButtonEvent(button, x, y, state);
default:
break;
} }
} }
@ -1107,6 +1073,26 @@ bool EventHandler::eventStateChange(Event::Type type)
return handled; return handled;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::createMouseMotionEvent(int x, int y)
{
SDL_WarpMouse(x, y);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::createMouseButtonEvent(int x, int y, int state)
{
// Synthesize an left mouse button press/release event
SDL_MouseButtonEvent mouseEvent;
mouseEvent.type = state ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
mouseEvent.button = SDL_BUTTON_LEFT;
mouseEvent.state = state ? SDL_PRESSED : SDL_RELEASED;
mouseEvent.x = x;
mouseEvent.y = y;
handleMouseButtonEvent((SDL_Event&)mouseEvent, state);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setActionMappings() void EventHandler::setActionMappings()
{ {
@ -1275,7 +1261,7 @@ void EventHandler::addJoyAxisMapping(Event::Type event, int stick, int axis,
int value) int value)
{ {
// This confusing code is because each axis has two associated values, // This confusing code is because each axis has two associated values,
// but analog events only affect on of the axis. // but analog events only affect one of the axis.
if(eventIsAnalog(event)) if(eventIsAnalog(event))
myJoyAxisTable[stick][axis][0] = myJoyAxisTable[stick][axis][1] = event; myJoyAxisTable[stick][axis][0] = myJoyAxisTable[stick][axis][1] = event;
else else

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventHandler.hxx,v 1.68 2005-12-19 02:19:49 stephena Exp $ // $Id: EventHandler.hxx,v 1.69 2005-12-24 22:09:36 stephena Exp $
//============================================================================ //============================================================================
#ifndef EVENTHANDLER_HXX #ifndef EVENTHANDLER_HXX
@ -79,6 +79,14 @@ struct Stella_Joystick {
string name; string name;
}; };
// Used for joystick to mouse emulation
struct JoyMouse {
bool active;
int x, y, x_vel, y_vel, x_max, y_max, x_amt, y_amt, amt,
x_down_count, y_down_count;
unsigned int last_time, delay_time, x_down_time, y_down_time;
};
/** /**
This class takes care of event remapping and dispatching for the This class takes care of event remapping and dispatching for the
Stella core, as well as keeping track of the current 'mode'. Stella core, as well as keeping track of the current 'mode'.
@ -92,7 +100,7 @@ struct Stella_Joystick {
mapping can take place. mapping can take place.
@author Stephen Anthony @author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.68 2005-12-19 02:19:49 stephena Exp $ @version $Id: EventHandler.hxx,v 1.69 2005-12-24 22:09:36 stephena Exp $
*/ */
class EventHandler class EventHandler
{ {
@ -302,15 +310,24 @@ class EventHandler
inline bool frying() { return myFryingFlag; } inline bool frying() { return myFryingFlag; }
private: /**
// Used for joystick to mouse emulation Create a synthetic SDL mouse motion event based on the given x,y values.
struct JoyMouse {
bool active;
int x, y, x_vel, y_vel, x_max, y_max, x_amt, y_amt, amt,
x_down_count, y_down_count;
unsigned int last_time, delay_time, x_down_time, y_down_time;
};
@param x The x coordinate of motion, scaled in value
@param y The y coordinate of motion, scaled in value
*/
void createMouseMotionEvent(int x, int y);
/**
Create a synthetic SDL mouse button event based on the given x,y values.
@param x The x coordinate of motion, scaled in value
@param y The y coordinate of motion, scaled in value
@param state The state of the button click (on or off)
*/
void createMouseButtonEvent(int x, int y, int state);
private:
/** /**
Send a mouse motion event to the handler. Send a mouse motion event to the handler.
@ -449,7 +466,7 @@ class EventHandler
// The current joymap in string form // The current joymap in string form
string myJoymapString; string myJoymapString;
JoyMouse myJoyMouse; // Used for paddle emulation by keyboard or joystick
JoyMouse myPaddle[4]; JoyMouse myPaddle[4];
// How far the joystick will move the mouse on each frame tick // How far the joystick will move the mouse on each frame tick

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CommandDialog.hxx,v 1.2 2005-12-19 02:19:49 stephena Exp $ // $Id: CommandDialog.hxx,v 1.3 2005-12-24 22:09:36 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -40,6 +40,8 @@ class CommandDialog : public Dialog
virtual void handleJoyAxis(int stick, int axis, int value); virtual void handleJoyAxis(int stick, int axis, int value);
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
virtual bool wantsEvents() { return true; }
private: private:
int mySelectedItem; int mySelectedItem;
}; };

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CommandMenu.cxx,v 1.1 2005-08-29 18:36:42 stephena Exp $ // $Id: CommandMenu.cxx,v 1.2 2005-12-24 22:09:36 stephena Exp $
//============================================================================ //============================================================================
#include "Dialog.hxx" #include "Dialog.hxx"
@ -24,6 +24,9 @@
CommandMenu::CommandMenu(OSystem* osystem) CommandMenu::CommandMenu(OSystem* osystem)
: DialogContainer(osystem) : DialogContainer(osystem)
{ {
// Tell the DialogContainer that we don't want to emulate mouse motion
// with the joystick axis, since we want to directly receive axis events
myEmulateMouseFlag = false;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Dialog.cxx,v 1.37 2005-12-21 01:50:16 stephena Exp $ // $Id: Dialog.cxx,v 1.38 2005-12-24 22:09:36 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -186,6 +186,12 @@ void Dialog::redrawFocus()
_focusedWidget = Widget::setFocusForChain(this, getFocusList(), _focusedWidget, 0); _focusedWidget = Widget::setFocusForChain(this, getFocusList(), _focusedWidget, 0);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Dialog::wantsEvents()
{
return _focusedWidget && _focusedWidget->wantsEvents();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::draw() void Dialog::draw()
{ {
@ -274,8 +280,10 @@ void Dialog::handleMouseWheel(int x, int y, int direction)
if(!w) if(!w)
w = _focusedWidget; w = _focusedWidget;
if (w) if (w)
{cerr << w << endl;
w->handleMouseWheel(x, y, direction); w->handleMouseWheel(x, y, direction);
} }
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleKeyDown(int ascii, int keycode, int modifiers) void Dialog::handleKeyDown(int ascii, int keycode, int modifiers)

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Dialog.hxx,v 1.23 2005-12-19 02:19:49 stephena Exp $ // $Id: Dialog.hxx,v 1.24 2005-12-24 22:09:36 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -36,7 +36,7 @@ class TabWidget;
This is the base class for all dialog boxes. This is the base class for all dialog boxes.
@author Stephen Anthony @author Stephen Anthony
@version $Id: Dialog.hxx,v 1.23 2005-12-19 02:19:49 stephena Exp $ @version $Id: Dialog.hxx,v 1.24 2005-12-24 22:09:36 stephena Exp $
*/ */
class Dialog : public GuiObject class Dialog : public GuiObject
{ {
@ -85,6 +85,8 @@ class Dialog : public GuiObject
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
virtual void handleScreenChanged() {} virtual void handleScreenChanged() {}
virtual bool wantsEvents();
Widget* findWidget(int x, int y); // Find the widget at pos x,y if any Widget* findWidget(int x, int y); // Find the widget at pos x,y if any
ButtonWidget* addButton(int x, int y, const string& label, int cmd, char hotkey); ButtonWidget* addButton(int x, int y, const string& label, int cmd, char hotkey);

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: DialogContainer.cxx,v 1.20 2005-12-07 20:46:49 stephena Exp $ // $Id: DialogContainer.cxx,v 1.21 2005-12-24 22:09:36 stephena Exp $
//============================================================================ //============================================================================
#include "OSystem.hxx" #include "OSystem.hxx"
@ -23,18 +23,20 @@
#include "bspf.hxx" #include "bspf.hxx"
#include "DialogContainer.hxx" #include "DialogContainer.hxx"
#define JOY_DEADZONE 3200
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DialogContainer::DialogContainer(OSystem* osystem) DialogContainer::DialogContainer(OSystem* osystem)
: myOSystem(osystem), : myOSystem(osystem),
myBaseDialog(NULL), myBaseDialog(NULL),
myTime(0), myTime(0),
myRefreshFlag(false) myRefreshFlag(false),
myEmulateMouseFlag(true)
{ {
myCurrentKeyDown.keycode = 0; memset(&ourJoyMouse, 0, sizeof(JoyMouse));
myCurrentMouseDown.button = -1; ourJoyMouse.delay_time = 25;
myLastClick.x = myLastClick.y = 0;
myLastClick.time = 0; reset();
myLastClick.count = 0;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -70,6 +72,9 @@ void DialogContainer::updateTime(uInt32 time)
myCurrentMouseDown.button, 1); myCurrentMouseDown.button, 1);
myClickRepeatTime = myTime + kClickRepeatSustainDelay; myClickRepeatTime = myTime + kClickRepeatSustainDelay;
} }
// Update joy to mouse events
handleJoyMouse(time);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -125,11 +130,7 @@ void DialogContainer::reStack()
myOSystem->frameBuffer().hideMessage(); myOSystem->frameBuffer().hideMessage();
// Reset all continuous events // Reset all continuous events
myCurrentKeyDown.keycode = 0; reset();
myCurrentMouseDown.button = -1;
myLastClick.x = myLastClick.y = 0;
myLastClick.time = 0;
myLastClick.count = 0;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -248,10 +249,17 @@ void DialogContainer::handleJoyEvent(int stick, int button, uInt8 state)
// Send the event to the dialog box on the top of the stack // Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top(); Dialog* activeDialog = myDialogStack.top();
if(state == 1)
activeDialog->handleJoyDown(stick, button); if(activeDialog->wantsEvents())
{
if(state == 1)
activeDialog->handleJoyDown(stick, button);
else
activeDialog->handleJoyUp(stick, button);
}
else else
activeDialog->handleJoyUp(stick, button); myOSystem->eventHandler().createMouseButtonEvent(
ourJoyMouse.x, ourJoyMouse.y, state);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -260,7 +268,162 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value)
if(myDialogStack.empty()) if(myDialogStack.empty())
return; return;
// Send the event to the dialog box on the top of the stack if(myEmulateMouseFlag)
Dialog* activeDialog = myDialogStack.top(); {
activeDialog->handleJoyAxis(stick, axis, value); if(value > JOY_DEADZONE)
value -= JOY_DEADZONE;
else if(value < -JOY_DEADZONE )
value += JOY_DEADZONE;
else
value = 0;
if(axis % 2 == 0) // x-direction
{
if(value != 0)
{
ourJoyMouse.x_vel = (value > 0) ? 1 : -1;
ourJoyMouse.x_down_count = 1;
}
else
{
ourJoyMouse.x_vel = 0;
ourJoyMouse.x_down_count = 0;
}
}
else // y-direction
{
value = -value;
if(value != 0)
{
ourJoyMouse.y_vel = (-value > 0) ? 1 : -1;
ourJoyMouse.y_down_count = 1;
}
else
{
ourJoyMouse.y_vel = 0;
ourJoyMouse.y_down_count = 0;
}
}
}
else
{
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
activeDialog->handleJoyAxis(stick, axis, value);
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::handleJoyMouse(uInt32 time)
{
bool mouseAccel = true;//false; // TODO - make this a commandline option
int oldX = ourJoyMouse.x, oldY = ourJoyMouse.y;
if(time >= ourJoyMouse.last_time + ourJoyMouse.delay_time)
{
ourJoyMouse.last_time = time;
if(ourJoyMouse.x_down_count == 1)
{
ourJoyMouse.x_down_time = time;
ourJoyMouse.x_down_count = 2;
}
if(ourJoyMouse.y_down_count == 1)
{
ourJoyMouse.y_down_time = time;
ourJoyMouse.y_down_count = 2;
}
if(ourJoyMouse.x_vel || ourJoyMouse.y_vel)
{
if(ourJoyMouse.x_down_count)
{
if(mouseAccel && time > ourJoyMouse.x_down_time + ourJoyMouse.delay_time * 12)
{
if(ourJoyMouse.x_vel > 0)
ourJoyMouse.x_vel++;
else
ourJoyMouse.x_vel--;
}
else if(time > ourJoyMouse.x_down_time + ourJoyMouse.delay_time * 8)
{
if(ourJoyMouse.x_vel > 0)
ourJoyMouse.x_vel = ourJoyMouse.amt;
else
ourJoyMouse.x_vel = -ourJoyMouse.amt;
}
}
if(ourJoyMouse.y_down_count)
{
if(mouseAccel && time > ourJoyMouse.y_down_time + ourJoyMouse.delay_time * 12)
{
if(ourJoyMouse.y_vel > 0)
ourJoyMouse.y_vel++;
else
ourJoyMouse.y_vel--;
}
else if(time > ourJoyMouse.y_down_time + ourJoyMouse.delay_time * 8)
{
if(ourJoyMouse.y_vel > 0)
ourJoyMouse.y_vel = ourJoyMouse.amt;
else
ourJoyMouse.y_vel = -ourJoyMouse.amt;
}
}
ourJoyMouse.x += ourJoyMouse.x_vel;
ourJoyMouse.y += ourJoyMouse.y_vel;
if(ourJoyMouse.x < 0)
{
ourJoyMouse.x = 0;
ourJoyMouse.x_vel = -1;
ourJoyMouse.x_down_count = 1;
}
else if(ourJoyMouse.x > ourJoyMouse.x_max)
{
ourJoyMouse.x = ourJoyMouse.x_max;
ourJoyMouse.x_vel = 1;
ourJoyMouse.x_down_count = 1;
}
if(ourJoyMouse.y < 0)
{
ourJoyMouse.y = 0;
ourJoyMouse.y_vel = -1;
ourJoyMouse.y_down_count = 1;
}
else if(ourJoyMouse.y > ourJoyMouse.y_max)
{
ourJoyMouse.y = ourJoyMouse.y_max;
ourJoyMouse.y_vel = 1;
ourJoyMouse.y_down_count = 1;
}
if(oldX != ourJoyMouse.x || oldY != ourJoyMouse.y)
myOSystem->eventHandler().createMouseMotionEvent(ourJoyMouse.x, ourJoyMouse.y);
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::reset()
{
myCurrentKeyDown.keycode = 0;
myCurrentMouseDown.button = -1;
myLastClick.x = myLastClick.y = 0;
myLastClick.time = 0;
myLastClick.count = 0;
int oldX = ourJoyMouse.x, oldY = ourJoyMouse.y;
if(ourJoyMouse.x > ourJoyMouse.x_max)
ourJoyMouse.x = ourJoyMouse.x_max;
if(ourJoyMouse.y > ourJoyMouse.y_max)
ourJoyMouse.y = ourJoyMouse.y_max;
if(oldX != ourJoyMouse.x || oldY != ourJoyMouse.y)
myOSystem->eventHandler().createMouseMotionEvent(ourJoyMouse.x, ourJoyMouse.y);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
JoyMouse DialogContainer::ourJoyMouse;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: DialogContainer.hxx,v 1.10 2005-12-19 02:19:49 stephena Exp $ // $Id: DialogContainer.hxx,v 1.11 2005-12-24 22:09:36 stephena Exp $
//============================================================================ //============================================================================
#ifndef DIALOG_CONTAINER_HXX #ifndef DIALOG_CONTAINER_HXX
@ -37,10 +37,12 @@ typedef FixedStack<Dialog *> DialogStack;
a stack, and handles their events. a stack, and handles their events.
@author Stephen Anthony @author Stephen Anthony
@version $Id: DialogContainer.hxx,v 1.10 2005-12-19 02:19:49 stephena Exp $ @version $Id: DialogContainer.hxx,v 1.11 2005-12-24 22:09:36 stephena Exp $
*/ */
class DialogContainer class DialogContainer
{ {
friend class EventHandler;
public: public:
/** /**
Create a new DialogContainer stack Create a new DialogContainer stack
@ -139,6 +141,13 @@ class DialogContainer
*/ */
virtual void initialize() = 0; virtual void initialize() = 0;
// Emulation of mouse using joystick axis events
static JoyMouse ourJoyMouse;
private:
void handleJoyMouse(uInt32);
void reset();
protected: protected:
OSystem* myOSystem; OSystem* myOSystem;
Dialog* myBaseDialog; Dialog* myBaseDialog;
@ -158,6 +167,9 @@ class DialogContainer
// Indicates a full refresh of all dialogs is required // Indicates a full refresh of all dialogs is required
bool myRefreshFlag; bool myRefreshFlag;
// Indicates if we should emulate mouse motion events for this container
bool myEmulateMouseFlag;
// For continuous events (keyDown) // For continuous events (keyDown)
struct { struct {
int ascii; int ascii;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventMappingWidget.cxx,v 1.5 2005-12-21 19:31:18 stephena Exp $ // $Id: EventMappingWidget.cxx,v 1.6 2005-12-24 22:09:36 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -124,6 +124,10 @@ void EventMappingWidget::startRemapping()
"' event"; "' event";
myKeyMapping->setColor(kTextColorEm); myKeyMapping->setColor(kTextColorEm);
myKeyMapping->setLabel(buf); myKeyMapping->setLabel(buf);
// Make sure that this widget receives all events,
// and they aren't handled anywhere else
myActionsList->setFlags(WIDGET_WANTS_EVENTS);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -158,6 +162,9 @@ void EventMappingWidget::stopRemapping()
myMapButton->setEnabled(true); myMapButton->setEnabled(true);
myEraseButton->setEnabled(true); myEraseButton->setEnabled(true);
} }
// Widget is now free to process events normally
myActionsList->clearFlags(WIDGET_WANTS_EVENTS);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventMappingWidget.hxx,v 1.3 2005-12-20 19:05:16 stephena Exp $ // $Id: EventMappingWidget.hxx,v 1.4 2005-12-24 22:09:36 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Widget.hxx,v 1.42 2005-12-21 01:50:16 stephena Exp $ // $Id: Widget.hxx,v 1.43 2005-12-24 22:09:36 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -44,7 +44,8 @@ enum {
WIDGET_TRACK_MOUSE = 1 << 6, WIDGET_TRACK_MOUSE = 1 << 6,
WIDGET_RETAIN_FOCUS = 1 << 7, WIDGET_RETAIN_FOCUS = 1 << 7,
WIDGET_NODRAW_FOCUS = 1 << 8, WIDGET_NODRAW_FOCUS = 1 << 8,
WIDGET_WANTS_TAB = 1 << 9 WIDGET_WANTS_TAB = 1 << 9,
WIDGET_WANTS_EVENTS = 1 << 10
}; };
enum { enum {
@ -72,7 +73,7 @@ enum {
This is the base class for all widgets. This is the base class for all widgets.
@author Stephen Anthony @author Stephen Anthony
@version $Id: Widget.hxx,v 1.42 2005-12-21 01:50:16 stephena Exp $ @version $Id: Widget.hxx,v 1.43 2005-12-24 22:09:36 stephena Exp $
*/ */
class Widget : public GuiObject class Widget : public GuiObject
{ {
@ -103,7 +104,7 @@ class Widget : public GuiObject
void addFocusWidget(Widget* w) { _focusList.push_back(w); } void addFocusWidget(Widget* w) { _focusList.push_back(w); }
virtual GUI::Rect getRect() const; virtual GUI::Rect getRect() const;
virtual bool wantsFocus() { return false; }; virtual bool wantsFocus() { return false; }
/** Set/clear WIDGET_ENABLED flag and immediately redraw */ /** Set/clear WIDGET_ENABLED flag and immediately redraw */
void setEnabled(bool e); void setEnabled(bool e);
@ -114,6 +115,7 @@ class Widget : public GuiObject
bool isEnabled() const { return _flags & WIDGET_ENABLED; } bool isEnabled() const { return _flags & WIDGET_ENABLED; }
bool isVisible() const { return !(_flags & WIDGET_INVISIBLE); } bool isVisible() const { return !(_flags & WIDGET_INVISIBLE); }
bool wantsEvents() const { return _flags & WIDGET_WANTS_EVENTS; }
void setID(int id) { _id = id; } void setID(int id) { _id = id; }
int getID() { return _id; } int getID() { return _id; }