mirror of https://github.com/stella-emu/stella.git
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:
parent
8a74c4776e
commit
2a8d708620
|
@ -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.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>
|
||||
|
@ -126,9 +126,6 @@ EventHandler::EventHandler(OSystem* osystem)
|
|||
setPaddleMode(myOSystem->settings().getInt("paddle"), 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
|
||||
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);
|
||||
}
|
||||
setPaddleSpeed(0, myOSystem->settings().getInt("p1speed"));
|
||||
|
@ -189,9 +186,9 @@ void EventHandler::reset(State state)
|
|||
void EventHandler::refreshDisplay()
|
||||
{
|
||||
// These are reset each time the display changes size
|
||||
myJoyMouse.x_max = myOSystem->frameBuffer().imageWidth();
|
||||
myJoyMouse.y_max = myOSystem->frameBuffer().imageHeight();
|
||||
myJoyMouse.amt = myOSystem->frameBuffer().zoomLevel() * 3;
|
||||
DialogContainer::ourJoyMouse.x_max = myOSystem->frameBuffer().imageWidth();
|
||||
DialogContainer::ourJoyMouse.y_max = myOSystem->frameBuffer().imageHeight();
|
||||
DialogContainer::ourJoyMouse.amt = myOSystem->frameBuffer().zoomLevel() * 3;
|
||||
|
||||
switch(myState)
|
||||
{
|
||||
|
@ -766,7 +763,7 @@ void EventHandler::poll(uInt32 time)
|
|||
|
||||
// Update the current dialog container at regular intervals
|
||||
// Used to implement continuous events
|
||||
if(myOverlay)
|
||||
if(myState != S_EMULATE && myOverlay)
|
||||
myOverlay->updateTime(time);
|
||||
|
||||
#ifdef CHEATCODE_SUPPORT
|
||||
|
@ -785,91 +782,60 @@ void EventHandler::handleMouseMotionEvent(SDL_Event& event)
|
|||
{
|
||||
// Take window zooming into account
|
||||
int x = event.motion.x, y = event.motion.y;
|
||||
myJoyMouse.x = x;
|
||||
myJoyMouse.y = y;
|
||||
DialogContainer::ourJoyMouse.x = x;
|
||||
DialogContainer::ourJoyMouse.y = y;
|
||||
|
||||
myOSystem->frameBuffer().translateCoords(&x, &y);
|
||||
|
||||
// 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,
|
||||
// so we need to fudge the numbers a bit
|
||||
if(myGrabMouseFlag) x = MIN(w, (int) (x * 1.5));
|
||||
// Grabmouse introduces some lag into the mouse movement,
|
||||
// so we need to fudge the numbers a bit
|
||||
if(myGrabMouseFlag) x = MIN(w, (int) (x * 1.5));
|
||||
|
||||
int resistance = (int)(1000000.0 * (w - x) / w);
|
||||
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;
|
||||
int resistance = (int)(1000000.0 * (w - x) / w);
|
||||
myEvent->set(Paddle_Resistance[myPaddleMode], resistance);
|
||||
}
|
||||
else if(myOverlay)
|
||||
myOverlay->handleMouseMotionEvent(x, y, 0);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventHandler::handleMouseButtonEvent(SDL_Event& event, int state)
|
||||
{
|
||||
// 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:
|
||||
handleEvent(Paddle_Button[myPaddleMode], state);
|
||||
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;
|
||||
// Take window zooming into account
|
||||
Int32 x = event.button.x, y = event.button.y;
|
||||
//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;
|
||||
MouseButton button;
|
||||
MouseButton button;
|
||||
|
||||
if(state == 1)
|
||||
{
|
||||
if(event.button.button == SDL_BUTTON_LEFT)
|
||||
button = EVENT_LBUTTONDOWN;
|
||||
else if(event.button.button == SDL_BUTTON_RIGHT)
|
||||
button = EVENT_RBUTTONDOWN;
|
||||
else if(event.button.button == SDL_BUTTON_WHEELUP)
|
||||
button = EVENT_WHEELUP;
|
||||
else if(event.button.button == SDL_BUTTON_WHEELDOWN)
|
||||
button = EVENT_WHEELDOWN;
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(event.button.button == SDL_BUTTON_LEFT)
|
||||
button = EVENT_LBUTTONUP;
|
||||
else if(event.button.button == SDL_BUTTON_RIGHT)
|
||||
button = EVENT_RBUTTONUP;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
myOverlay->handleMouseButtonEvent(button, x, y, state);
|
||||
break;
|
||||
switch(event.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:
|
||||
button = state ? EVENT_LBUTTONDOWN : EVENT_LBUTTONUP;
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
button = state ? EVENT_RBUTTONDOWN : EVENT_RBUTTONUP;
|
||||
break;
|
||||
case SDL_BUTTON_WHEELDOWN:
|
||||
button = EVENT_WHEELDOWN;
|
||||
break;
|
||||
case SDL_BUTTON_WHEELUP:
|
||||
button = EVENT_WHEELUP;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
myOverlay->handleMouseButtonEvent(button, x, y, state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1107,6 +1073,26 @@ bool EventHandler::eventStateChange(Event::Type type)
|
|||
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()
|
||||
{
|
||||
|
@ -1275,7 +1261,7 @@ void EventHandler::addJoyAxisMapping(Event::Type event, int stick, int axis,
|
|||
int value)
|
||||
{
|
||||
// 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))
|
||||
myJoyAxisTable[stick][axis][0] = myJoyAxisTable[stick][axis][1] = event;
|
||||
else
|
||||
|
|
|
@ -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.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
|
||||
|
@ -79,6 +79,14 @@ struct Stella_Joystick {
|
|||
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
|
||||
Stella core, as well as keeping track of the current 'mode'.
|
||||
|
@ -92,7 +100,7 @@ struct Stella_Joystick {
|
|||
mapping can take place.
|
||||
|
||||
@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
|
||||
{
|
||||
|
@ -302,15 +310,24 @@ class EventHandler
|
|||
|
||||
inline bool frying() { return myFryingFlag; }
|
||||
|
||||
private:
|
||||
// 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;
|
||||
};
|
||||
/**
|
||||
Create a synthetic SDL mouse motion 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
|
||||
*/
|
||||
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.
|
||||
|
||||
|
@ -449,7 +466,7 @@ class EventHandler
|
|||
// The current joymap in string form
|
||||
string myJoymapString;
|
||||
|
||||
JoyMouse myJoyMouse;
|
||||
// Used for paddle emulation by keyboard or joystick
|
||||
JoyMouse myPaddle[4];
|
||||
|
||||
// How far the joystick will move the mouse on each frame tick
|
||||
|
|
|
@ -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: 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
|
||||
// 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 handleCommand(CommandSender* sender, int cmd, int data, int id);
|
||||
|
||||
virtual bool wantsEvents() { return true; }
|
||||
|
||||
private:
|
||||
int mySelectedItem;
|
||||
};
|
||||
|
|
|
@ -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: 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"
|
||||
|
@ -24,6 +24,9 @@
|
|||
CommandMenu::CommandMenu(OSystem* 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;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -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.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
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -186,6 +186,12 @@ void Dialog::redrawFocus()
|
|||
_focusedWidget = Widget::setFocusForChain(this, getFocusList(), _focusedWidget, 0);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool Dialog::wantsEvents()
|
||||
{
|
||||
return _focusedWidget && _focusedWidget->wantsEvents();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void Dialog::draw()
|
||||
{
|
||||
|
@ -274,8 +280,10 @@ void Dialog::handleMouseWheel(int x, int y, int direction)
|
|||
if(!w)
|
||||
w = _focusedWidget;
|
||||
if (w)
|
||||
{cerr << w << endl;
|
||||
w->handleMouseWheel(x, y, direction);
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void Dialog::handleKeyDown(int ascii, int keycode, int modifiers)
|
||||
|
|
|
@ -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.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
|
||||
// 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.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
|
||||
{
|
||||
|
@ -84,6 +84,8 @@ class Dialog : public GuiObject
|
|||
virtual void handleJoyAxis(int stick, int axis, int value);
|
||||
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id);
|
||||
virtual void handleScreenChanged() {}
|
||||
|
||||
virtual bool wantsEvents();
|
||||
|
||||
Widget* findWidget(int x, int y); // Find the widget at pos x,y if any
|
||||
|
||||
|
|
|
@ -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.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"
|
||||
|
@ -23,18 +23,20 @@
|
|||
#include "bspf.hxx"
|
||||
#include "DialogContainer.hxx"
|
||||
|
||||
#define JOY_DEADZONE 3200
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
DialogContainer::DialogContainer(OSystem* osystem)
|
||||
: myOSystem(osystem),
|
||||
myBaseDialog(NULL),
|
||||
myTime(0),
|
||||
myRefreshFlag(false)
|
||||
myRefreshFlag(false),
|
||||
myEmulateMouseFlag(true)
|
||||
{
|
||||
myCurrentKeyDown.keycode = 0;
|
||||
myCurrentMouseDown.button = -1;
|
||||
myLastClick.x = myLastClick.y = 0;
|
||||
myLastClick.time = 0;
|
||||
myLastClick.count = 0;
|
||||
memset(&ourJoyMouse, 0, sizeof(JoyMouse));
|
||||
ourJoyMouse.delay_time = 25;
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -70,6 +72,9 @@ void DialogContainer::updateTime(uInt32 time)
|
|||
myCurrentMouseDown.button, 1);
|
||||
myClickRepeatTime = myTime + kClickRepeatSustainDelay;
|
||||
}
|
||||
|
||||
// Update joy to mouse events
|
||||
handleJoyMouse(time);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -125,11 +130,7 @@ void DialogContainer::reStack()
|
|||
myOSystem->frameBuffer().hideMessage();
|
||||
|
||||
// Reset all continuous events
|
||||
myCurrentKeyDown.keycode = 0;
|
||||
myCurrentMouseDown.button = -1;
|
||||
myLastClick.x = myLastClick.y = 0;
|
||||
myLastClick.time = 0;
|
||||
myLastClick.count = 0;
|
||||
reset();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -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
|
||||
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
|
||||
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())
|
||||
return;
|
||||
|
||||
// Send the event to the dialog box on the top of the stack
|
||||
Dialog* activeDialog = myDialogStack.top();
|
||||
activeDialog->handleJoyAxis(stick, axis, value);
|
||||
if(myEmulateMouseFlag)
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -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.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
|
||||
|
@ -37,10 +37,12 @@ typedef FixedStack<Dialog *> DialogStack;
|
|||
a stack, and handles their events.
|
||||
|
||||
@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
|
||||
{
|
||||
friend class EventHandler;
|
||||
|
||||
public:
|
||||
/**
|
||||
Create a new DialogContainer stack
|
||||
|
@ -139,6 +141,13 @@ class DialogContainer
|
|||
*/
|
||||
virtual void initialize() = 0;
|
||||
|
||||
// Emulation of mouse using joystick axis events
|
||||
static JoyMouse ourJoyMouse;
|
||||
|
||||
private:
|
||||
void handleJoyMouse(uInt32);
|
||||
void reset();
|
||||
|
||||
protected:
|
||||
OSystem* myOSystem;
|
||||
Dialog* myBaseDialog;
|
||||
|
@ -158,6 +167,9 @@ class DialogContainer
|
|||
// Indicates a full refresh of all dialogs is required
|
||||
bool myRefreshFlag;
|
||||
|
||||
// Indicates if we should emulate mouse motion events for this container
|
||||
bool myEmulateMouseFlag;
|
||||
|
||||
// For continuous events (keyDown)
|
||||
struct {
|
||||
int ascii;
|
||||
|
|
|
@ -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.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
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -124,6 +124,10 @@ void EventMappingWidget::startRemapping()
|
|||
"' event";
|
||||
myKeyMapping->setColor(kTextColorEm);
|
||||
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);
|
||||
myEraseButton->setEnabled(true);
|
||||
}
|
||||
|
||||
// Widget is now free to process events normally
|
||||
myActionsList->clearFlags(WIDGET_WANTS_EVENTS);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -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.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
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -47,7 +47,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);
|
||||
|
||||
|
||||
bool remapMode() { return myRemapStatus; }
|
||||
|
||||
protected:
|
||||
|
|
|
@ -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.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
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -44,7 +44,8 @@ enum {
|
|||
WIDGET_TRACK_MOUSE = 1 << 6,
|
||||
WIDGET_RETAIN_FOCUS = 1 << 7,
|
||||
WIDGET_NODRAW_FOCUS = 1 << 8,
|
||||
WIDGET_WANTS_TAB = 1 << 9
|
||||
WIDGET_WANTS_TAB = 1 << 9,
|
||||
WIDGET_WANTS_EVENTS = 1 << 10
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -72,7 +73,7 @@ enum {
|
|||
This is the base class for all widgets.
|
||||
|
||||
@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
|
||||
{
|
||||
|
@ -103,7 +104,7 @@ class Widget : public GuiObject
|
|||
void addFocusWidget(Widget* w) { _focusList.push_back(w); }
|
||||
|
||||
virtual GUI::Rect getRect() const;
|
||||
virtual bool wantsFocus() { return false; };
|
||||
virtual bool wantsFocus() { return false; }
|
||||
|
||||
/** Set/clear WIDGET_ENABLED flag and immediately redraw */
|
||||
void setEnabled(bool e);
|
||||
|
@ -114,6 +115,7 @@ class Widget : public GuiObject
|
|||
|
||||
bool isEnabled() const { return _flags & WIDGET_ENABLED; }
|
||||
bool isVisible() const { return !(_flags & WIDGET_INVISIBLE); }
|
||||
bool wantsEvents() const { return _flags & WIDGET_WANTS_EVENTS; }
|
||||
|
||||
void setID(int id) { _id = id; }
|
||||
int getID() { return _id; }
|
||||
|
|
Loading…
Reference in New Issue