Re-added joystick support.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@438 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-05-25 23:22:11 +00:00
parent 6d53a85e58
commit 46f3e463d9
13 changed files with 401 additions and 210 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: mainSDL.cxx,v 1.40 2005-05-25 17:17:33 stephena Exp $
// $Id: mainSDL.cxx,v 1.41 2005-05-25 23:22:10 stephena Exp $
//============================================================================
#include <fstream>
@ -87,18 +87,6 @@ void SetupProperties(PropertiesSet& set)
*/
void Cleanup()
{
/* FIXME
#ifdef JOYSTICK_SUPPORT
if(SDL_WasInit(SDL_INIT_JOYSTICK) & SDL_INIT_JOYSTICK)
{
for(uInt32 i = 0; i < StellaEvent::LastJSTICK; i++)
{
if(SDL_JoystickOpened(i))
SDL_JoystickClose(theJoysticks[i].stick);
}
}
#endif
*/
if(theOSystem)
delete theOSystem;
@ -165,14 +153,7 @@ int main(int argc, char* argv[])
theOSystem->createSound();
// Setup the SDL joysticks (must be done after FrameBuffer is created)
/* FIXME - don't exit if joysticks can't be initialized
if(!theOSystem->eventHandler().setupJoystick()) // move this into eventhandler
{
cerr << "ERROR: Couldn't set up joysticks.\n";
Cleanup();
return 0;
}
*/
theOSystem->eventHandler().setupJoysticks();
//// Main loop ////
// First we check if a ROM is specified on the commandline. If so, and if

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.60 2005-05-25 17:17:35 stephena Exp $
// $Id: EventHandler.cxx,v 1.61 2005-05-25 23:22:11 stephena Exp $
//============================================================================
#include <algorithm>
@ -24,15 +24,14 @@
#include "EventHandler.hxx"
#include "FSNode.hxx"
#include "Settings.hxx"
#include "StellaEvent.hxx"
#include "System.hxx"
#include "FrameBuffer.hxx"
#include "Sound.hxx"
#include "OSystem.hxx"
#include "Menu.hxx"
#include "Launcher.hxx"
#include "bspf.hxx"
#include "GuiUtils.hxx"
#include "bspf.hxx"
#ifdef SNAPSHOT_SUPPORT
#include "Snapshot.hxx"
@ -63,7 +62,7 @@ EventHandler::EventHandler(OSystem* osystem)
}
// Erase the JoyEvent array
for(Int32 i = 0; i < StellaEvent::LastJSTICK*StellaEvent::LastJCODE; ++i)
for(Int32 i = 0; i < kNumJoysticks * kNumJoyButtons; ++i)
myJoyTable[i] = Event::NoType;
// Erase the Message array
@ -93,6 +92,17 @@ EventHandler::~EventHandler()
{
if(myEvent)
delete myEvent;
#ifdef JOYSTICK_SUPPORT
if(SDL_WasInit(SDL_INIT_JOYSTICK) & SDL_INIT_JOYSTICK)
{
for(uInt32 i = 0; i < kNumJoysticks; i++)
{
if(SDL_JoystickOpened(i))
SDL_JoystickClose(ourJoysticks[i].stick);
}
}
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -134,6 +144,83 @@ void EventHandler::reset(State state)
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setupJoysticks()
{
#ifdef JOYSTICK_SUPPORT
bool showinfo = myOSystem->settings().getBool("showinfo");
// Keep track of how many Stelladaptors we've found
uInt8 saCount = 0;
// First clear the joystick array
for(uInt32 i = 0; i < kNumJoysticks; i++)
{
ourJoysticks[i].stick = (SDL_Joystick*) NULL;
ourJoysticks[i].type = JT_NONE;
}
// Initialize the joystick subsystem
if((SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) || (SDL_NumJoysticks() <= 0))
{
if(showinfo)
cout << "No joysticks present, use the keyboard." << endl;
return;
}
// Open up to 6 regular joysticks and 2 Stelladaptor devices
uInt32 limit = SDL_NumJoysticks() <= kNumJoysticks ?
SDL_NumJoysticks() : kNumJoysticks;
for(uInt32 i = 0; i < limit; i++)
{
string name = SDL_JoystickName(i);
ourJoysticks[i].stick = SDL_JoystickOpen(i);
// Skip if we couldn't open it for any reason
if(ourJoysticks[i].stick == NULL)
{
ourJoysticks[i].type = JT_NONE;
continue;
}
// Figure out what type of joystick this is
if(name.find("Stelladaptor", 0) != string::npos)
{
saCount++;
if(saCount > 2) // Ignore more than 2 Stelladaptors
{
ourJoysticks[i].type = JT_NONE;
continue;
}
else if(saCount == 1)
{
name = "Left Stelladaptor (Left joystick, Paddles 0 and 1, Left driving controller)";
ourJoysticks[i].type = JT_STELLADAPTOR_1;
}
else if(saCount == 2)
{
name = "Right Stelladaptor (Right joystick, Paddles 2 and 3, Right driving controller)";
ourJoysticks[i].type = JT_STELLADAPTOR_2;
}
if(showinfo)
cout << "Joystick " << i << ": " << name << endl;
}
else
{
ourJoysticks[i].type = JT_REGULAR;
if(showinfo)
cout << "Joystick " << i << ": " << SDL_JoystickName(i)
<< " with " << SDL_JoystickNumButtons(ourJoysticks[i].stick)
<< " buttons." << endl;
}
if(showinfo)
cout << endl;
}
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::poll()
{
@ -240,10 +327,132 @@ void EventHandler::poll()
break; // SDL_VIDEOEXPOSE
}
// FIXME - joystick stuff goes here
#ifdef JOYSTICK_SUPPORT
// Read joystick events and modify event states
uInt8 stick;
uInt32 code;
uInt8 state;
Uint8 axis;
Uint8 button;
Int32 resistance;
Sint16 value;
JoyType type;
if(event.jbutton.which >= kNumJoysticks)
return;
stick = event.jbutton.which;
type = ourJoysticks[stick].type;
// Figure put what type of joystick we're dealing with
// Stelladaptors behave differently, and can't be remapped
switch(type)
{
case JT_NONE:
break;
case JT_REGULAR:
switch(event.type)
{
case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
if(event.jbutton.button >= kNumJoyButtons-4)
return;
code = event.jbutton.button;
state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
handleJoyEvent(stick, code, state);
break;
case SDL_JOYAXISMOTION:
axis = event.jaxis.axis;
value = event.jaxis.value;
if(axis == 0) // x-axis
{
handleJoyEvent(stick, kJAxisLeft, (value < -16384) ? 1 : 0);
handleJoyEvent(stick, kJAxisRight, (value > 16384) ? 1 : 0);
}
else if(axis == 1) // y-axis
{
handleJoyEvent(stick, kJAxisUp, (value < -16384) ? 1 : 0);
handleJoyEvent(stick, kJAxisDown, (value > 16384) ? 1 : 0);
}
break;
}
break; // Regular joystick
case JT_STELLADAPTOR_1:
case JT_STELLADAPTOR_2:
switch(event.type)
{
case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
button = event.jbutton.button;
state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
// Send button events for the joysticks/paddles/driving controllers
if(button == 0)
{
if(type == JT_STELLADAPTOR_1)
{
handleEvent(Event::JoystickZeroFire, state);
handleEvent(Event::DrivingZeroFire, state);
handleEvent(Event::PaddleZeroFire, state);
}
else
{
handleEvent(Event::JoystickOneFire, state);
handleEvent(Event::DrivingOneFire, state);
handleEvent(Event::PaddleTwoFire, state);
}
}
else if(button == 1)
{
if(type == JT_STELLADAPTOR_1)
handleEvent(Event::PaddleOneFire, state);
else
handleEvent(Event::PaddleThreeFire, state);
}
break;
case SDL_JOYAXISMOTION:
axis = event.jaxis.axis;
value = event.jaxis.value;
// Send axis events for the joysticks
handleEvent(SA_Axis[type-2][axis][0], (value < -16384) ? 1 : 0);
handleEvent(SA_Axis[type-2][axis][1], (value > 16384) ? 1 : 0);
// Send axis events for the paddles
resistance = (Int32) (1000000.0 * (32767 - value) / 65534);
handleEvent(SA_Axis[type-2][axis][2], resistance);
// Send events for the driving controllers
if(axis == 1)
{
if(value <= -16384-4096)
handleEvent(SA_DrivingValue[type-2],2);
else if(value > 16384+4096)
handleEvent(SA_DrivingValue[type-2],1);
else if(value >= 16384-4096)
handleEvent(SA_DrivingValue[type-2],0);
else
handleEvent(SA_DrivingValue[type-2],3);
}
break;
}
break; // Stelladaptor joystick
default:
break;
}
#endif
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state)
{
@ -541,18 +750,33 @@ void EventHandler::handleMouseButtonEvent(SDL_Event& event, uInt8 state)
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::sendJoyEvent(StellaEvent::JoyStick stick,
StellaEvent::JoyCode code, Int32 state)
void EventHandler::handleJoyEvent(uInt8 stick, uInt32 code, uInt8 state)
{
// FIXME
/*
// Determine where the event should be sent
if(myMenuStatus)
myOSystem->frameBuffer().sendJoyEvent(stick, code, state);
else
handleEvent(myJoyTable[stick*StellaEvent::LastJCODE + code], state);
*/
// Determine which mode we're in, then send the event to the appropriate place
switch(myState)
{
case S_EMULATE:
handleEvent(myJoyTable[stick*kNumJoyButtons + code], state);
break;
case S_MENU:
myOSystem->menu().handleJoyEvent(0, 0, stick, code, state); // FIXME - get x,y
break;
case S_LAUNCHER:
myOSystem->launcher().handleJoyEvent(0, 0, stick, code, state); // FIXME - get x,y
break;
case S_DEBUGGER:
// Not yet implemented
break;
case S_NONE:
return;
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -637,35 +861,34 @@ void EventHandler::setActionMappings()
key = key + ", " + ourSDLMapping[j];
}
}
/* FIXME
for(uInt32 j = 0; j < myJoyTableSize; ++j)
for(uInt32 j = 0; j < kNumJoysticks * kNumJoyButtons; ++j)
{
if(myJoyTable[j] == event)
{
ostringstream joyevent;
uInt32 stick = j / StellaEvent::LastJCODE;
uInt32 button = j % StellaEvent::LastJCODE;
uInt32 stick = j / kNumJoyButtons;
uInt32 button = j % kNumJoyButtons;
switch(button)
{
case StellaEvent::JAXIS_UP:
case kJAxisUp:
joyevent << "J" << stick << " UP";
break;
case StellaEvent::JAXIS_DOWN:
case kJAxisDown:
joyevent << "J" << stick << " DOWN";
break;
case StellaEvent::JAXIS_LEFT:
case kJAxisLeft:
joyevent << "J" << stick << " LEFT";
break;
case StellaEvent::JAXIS_RIGHT:
case kJAxisRight:
joyevent << "J" << stick << " RIGHT";
break;
default:
joyevent << "J" << stick << " B" << (button-4);
joyevent << "J" << stick << " B" << button;
break;
}
if(key == "")
@ -674,7 +897,7 @@ void EventHandler::setActionMappings()
key = key + ", " + joyevent.str();
}
}
*/
// There are some keys which are hardcoded. These should be represented too.
string prepend = "";
if(event == Event::Quit)
@ -722,20 +945,18 @@ void EventHandler::setKeymap()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setJoymap()
{
// FIXME
/*
// Since istringstream swallows whitespace, we have to make the
// delimiters be spaces
string list = myOSystem->settings().getString("joymap");
replace(list.begin(), list.end(), ':', ' ');
if(isValidList(list, StellaEvent::LastJSTICK*StellaEvent::LastJCODE))
if(isValidList(list, kNumJoysticks*kNumJoyButtons))
{
istringstream buf(list);
string key;
// Fill the joymap table with events
for(Int32 i = 0; i < StellaEvent::LastJSTICK*StellaEvent::LastJCODE; ++i)
for(Int32 i = 0; i < kNumJoysticks*kNumJoyButtons; ++i)
{
buf >> key;
myJoyTable[i] = (Event::Type) atoi(key.c_str());
@ -743,7 +964,6 @@ void EventHandler::setJoymap()
}
else
setDefaultJoymap();
*/
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -759,17 +979,14 @@ void EventHandler::addKeyMapping(Event::Type event, uInt16 key)
saveMappings();
}
/* FIXME
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::addJoyMapping(Event::Type event,
StellaEvent::JoyStick stick, StellaEvent::JoyCode code)
void EventHandler::addJoyMapping(Event::Type event, uInt8 stick, uInt32 code)
{
myJoyTable[stick * StellaEvent::LastJCODE + code] = event;
myJoyTable[stick * kNumJoyButtons + code] = event;
setActionMappings();
saveMappings();
}
*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::eraseMapping(Event::Type event)
@ -780,8 +997,8 @@ void EventHandler::eraseMapping(Event::Type event)
myKeyTable[i] = Event::NoType;
// Erase the JoyEvent array
for(Int32 i = 0; i < StellaEvent::LastJSTICK*StellaEvent::LastJCODE; ++i)
if(myJoyTable[i] == event && i != SDLK_TAB && i != SDLK_ESCAPE)
for(Int32 i = 0; i < kNumJoysticks * kNumJoyButtons; ++i)
if(myJoyTable[i] == event)
myJoyTable[i] = Event::NoType;
setActionMappings();
@ -878,26 +1095,27 @@ void EventHandler::setDefaultKeymap()
void EventHandler::setDefaultJoymap()
{
uInt32 i;
uInt32 c = kNumJoyButtons - 4; // Upper 4 buttons are the directions
// Erase all mappings
for(i = 0; i < StellaEvent::LastJSTICK*StellaEvent::LastJCODE; ++i)
for(i = 0; i < kNumJoysticks * kNumJoyButtons; ++i)
myJoyTable[i] = Event::NoType;
// Left joystick
i = StellaEvent::JSTICK_0 * StellaEvent::LastJCODE;
myJoyTable[i + StellaEvent::JAXIS_UP] = Event::JoystickZeroUp;
myJoyTable[i + StellaEvent::JAXIS_DOWN] = Event::JoystickZeroDown;
myJoyTable[i + StellaEvent::JAXIS_LEFT] = Event::JoystickZeroLeft;
myJoyTable[i + StellaEvent::JAXIS_RIGHT] = Event::JoystickZeroRight;
myJoyTable[i + StellaEvent::JBUTTON_0] = Event::JoystickZeroFire;
i = 0 * kNumJoyButtons;
myJoyTable[i + c + 0] = Event::JoystickZeroUp;
myJoyTable[i + c + 1] = Event::JoystickZeroDown;
myJoyTable[i + c + 2] = Event::JoystickZeroLeft;
myJoyTable[i + c + 3] = Event::JoystickZeroRight;
myJoyTable[i + 0] = Event::JoystickZeroFire;
// Right joystick
i = StellaEvent::JSTICK_1 * StellaEvent::LastJCODE;
myJoyTable[i + StellaEvent::JAXIS_UP] = Event::JoystickOneUp;
myJoyTable[i + StellaEvent::JAXIS_DOWN] = Event::JoystickOneDown;
myJoyTable[i + StellaEvent::JAXIS_LEFT] = Event::JoystickOneLeft;
myJoyTable[i + StellaEvent::JAXIS_RIGHT] = Event::JoystickOneRight;
myJoyTable[i + StellaEvent::JBUTTON_0] = Event::JoystickOneFire;
i = 1 * kNumJoyButtons;
myJoyTable[i + c + 0] = Event::JoystickOneUp;
myJoyTable[i + c + 1] = Event::JoystickOneDown;
myJoyTable[i + c + 2] = Event::JoystickOneLeft;
myJoyTable[i + c + 3] = Event::JoystickOneRight;
myJoyTable[i + 0] = Event::JoystickOneFire;
saveMappings();
}
@ -913,7 +1131,7 @@ void EventHandler::saveMappings()
// Iterate through the joymap table and create a colon-separated list
ostringstream joybuf;
for(Int32 i = 0; i < StellaEvent::LastJSTICK*StellaEvent::LastJCODE; ++i)
for(Int32 i = 0; i < kNumJoysticks * kNumJoyButtons; ++i)
joybuf << myJoyTable[i] << ":";
myOSystem->settings().setString("joymap", joybuf.str());
}
@ -1364,20 +1582,19 @@ ActionList EventHandler::ourActionList[61] = {
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type EventHandler::Paddle_Resistance[4] = {
const Event::Type EventHandler::Paddle_Resistance[4] = {
Event::PaddleZeroResistance, Event::PaddleOneResistance,
Event::PaddleTwoResistance, Event::PaddleThreeResistance
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type EventHandler::Paddle_Button[4] = {
const Event::Type EventHandler::Paddle_Button[4] = {
Event::PaddleZeroFire, Event::PaddleOneFire,
Event::PaddleTwoFire, Event::PaddleThreeFire
};
#ifdef JOYSTICK_SUPPORT
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type EventHandler::SA_Axis[2][2][3] = {
const Event::Type EventHandler::SA_Axis[2][2][3] = {
{ {Event::JoystickZeroLeft, Event::JoystickZeroRight, Event::PaddleZeroResistance},
{Event::JoystickZeroUp, Event::JoystickZeroDown, Event::PaddleOneResistance } },
{ {Event::JoystickOneLeft, Event::JoystickOneRight, Event::PaddleTwoResistance},
@ -1385,7 +1602,6 @@ Event::Type EventHandler::SA_Axis[2][2][3] = {
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type EventHandler::SA_DrivingValue[2] = {
const Event::Type EventHandler::SA_DrivingValue[2] = {
Event::DrivingZeroValue, Event::DrivingOneValue
};
#endif

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.30 2005-05-25 17:17:37 stephena Exp $
// $Id: EventHandler.hxx,v 1.31 2005-05-25 23:22:11 stephena Exp $
//============================================================================
#ifndef EVENTHANDLER_HXX
@ -23,7 +23,6 @@
#include "bspf.hxx"
#include "Event.hxx"
#include "StellaEvent.hxx"
class Console;
class OSystem;
@ -44,6 +43,24 @@ struct ActionList {
string key;
};
// Joystick related items
enum {
kNumJoysticks = 8,
kNumJoyButtons = 24,
kJAxisUp = kNumJoyButtons - 4, // Upper 4 buttons are actually
kJAxisDown = kNumJoyButtons - 3, // directions
kJAxisLeft = kNumJoyButtons - 2,
kJAxisRight = kNumJoyButtons - 1
};
enum JoyType { JT_NONE, JT_REGULAR, JT_STELLADAPTOR_1, JT_STELLADAPTOR_2 };
struct Stella_Joystick {
SDL_Joystick* stick;
JoyType type;
};
/**
This class takes care of event remapping and dispatching for the
Stella core, as well as keeping track of the current 'mode'.
@ -57,7 +74,7 @@ struct ActionList {
mapping can take place.
@author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.30 2005-05-25 17:17:37 stephena Exp $
@version $Id: EventHandler.hxx,v 1.31 2005-05-25 23:22:11 stephena Exp $
*/
class EventHandler
{
@ -82,6 +99,13 @@ class EventHandler
*/
Event* event();
/**
Set up any joysticks on the system. This must be called *after* the
framebuffer has been created, since SDL requires the video to be
intialized before joysticks can be probed.
*/
void setupJoysticks();
/**
Collects and dispatches any pending events. This method should be
called regularly (at X times per second, where X is the game framerate).
@ -91,11 +115,20 @@ class EventHandler
/**
Bind a key to an event/action
@event The event we are remapping
@key The key to bind to this event
@param event The event we are remapping
@param key The key to bind to this event
*/
void addKeyMapping(Event::Type event, uInt16 key);
/**
Bind a joystick button/direction to an event/action
@param event The event we are remapping
@param stick The joystick number and button
@param code to bind to this event
*/
void addJoyMapping(Event::Type event, uInt8 stick, uInt32 code);
/**
Erase the specified mapping
@ -118,7 +151,7 @@ class EventHandler
/**
Resets the state machine of the EventHandler to the defaults
@param The current state to set
@param state The current state to set
*/
void reset(State state);
@ -149,16 +182,14 @@ class EventHandler
static ActionList ourActionList[61];
// Lookup table for paddle resistance events
static Event::Type Paddle_Resistance[4];
static const Event::Type Paddle_Resistance[4];
// Lookup table for paddle button events
static Event::Type Paddle_Button[4];
static const Event::Type Paddle_Button[4];
#ifdef JOYSTICK_SUPPORT
// Static lookup tables for Stelladaptor axis support
static Event::Type SA_Axis[2][2][3];
static Event::Type SA_DrivingValue[2];
#endif
static const Event::Type SA_Axis[2][2][3];
static const Event::Type SA_DrivingValue[2];
private:
/**
@ -194,14 +225,13 @@ class EventHandler
void handleMouseButtonEvent(SDL_Event& event, uInt8 state);
/**
Send a joystick button event to the handler.
Send a joystick event to the handler (directions are encoded as buttons)
@param stick The joystick activated
@param code The StellaEvent joystick code
@param state The StellaEvent state
@param stick SDL joystick
@param code Event code
@param state state of code (pressed/released)
*/
void sendJoyEvent(StellaEvent::JoyStick stick, StellaEvent::JoyCode code,
Int32 state);
void handleJoyEvent(uInt8 stick, uInt32 code, uInt8 state);
/**
The following methods take care of assigning action mappings.
@ -229,7 +259,7 @@ class EventHandler
Event::Type myKeyTable[SDLK_LAST];
// Array of joystick events
Event::Type myJoyTable[StellaEvent::LastJSTICK*StellaEvent::LastJCODE];
Event::Type myJoyTable[kNumJoysticks * kNumJoyButtons];
// Array of messages for each Event
string ourMessageTable[Event::LastType];
@ -237,6 +267,9 @@ class EventHandler
// Array of strings which correspond to the given SDL key
string ourSDLMapping[SDLK_LAST];
// Array of joysticks available to Stella
Stella_Joystick ourJoysticks[kNumJoysticks];
// Indicates the current state of the system (ie, which mode is current)
State myState;

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: FrameBuffer.cxx,v 1.37 2005-05-16 00:02:31 stephena Exp $
// $Id: FrameBuffer.cxx,v 1.38 2005-05-25 23:22:11 stephena Exp $
//============================================================================
#include <sstream>
@ -22,7 +22,6 @@
#include "Console.hxx"
#include "Event.hxx"
#include "EventHandler.hxx"
#include "StellaEvent.hxx"
#include "Settings.hxx"
#include "MediaSrc.hxx"
#include "FrameBuffer.hxx"

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: FrameBuffer.hxx,v 1.33 2005-05-17 18:42:22 stephena Exp $
// $Id: FrameBuffer.hxx,v 1.34 2005-05-25 23:22:11 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_HXX
@ -26,7 +26,6 @@
#include "Event.hxx"
#include "MediaSrc.hxx"
#include "StellaFont.hxx"
#include "StellaEvent.hxx"
#include "GuiUtils.hxx"
class StellaFont;
@ -41,7 +40,7 @@ class OSystem;
All GUI elements (ala ScummVM) are drawn here as well.
@author Stephen Anthony
@version $Id: FrameBuffer.hxx,v 1.33 2005-05-17 18:42:22 stephena Exp $
@version $Id: FrameBuffer.hxx,v 1.34 2005-05-25 23:22:11 stephena Exp $
*/
class FrameBuffer
{

View File

@ -1,97 +0,0 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-1998 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: StellaEvent.hxx,v 1.9 2004-05-06 00:06:19 stephena Exp $
//============================================================================
#ifndef STELLAEVENT_HXX
#define STELLAEVENT_HXX
/**
This file defines the global STELLA events that the frontends
will use to communicate with the Event Handler.
Only the standard keys are defined here. Function and
navigation (HOME, END, etc) keys are special and must be handled
by the frontends directly.
@author Stephen Anthony
@version $Id: StellaEvent.hxx,v 1.9 2004-05-06 00:06:19 stephena Exp $
*/
class StellaEvent
{
public:
/**
Enumeration of keyboard keycodes
Note that the order of these codes is related to
UserInterface::ourEventName. If these are ever changed or rearranged,
that array must be updated as well.
*/
enum KeyCode
{
KCODE_a, KCODE_b, KCODE_c, KCODE_d, KCODE_e, KCODE_f, KCODE_g, KCODE_h,
KCODE_i, KCODE_j, KCODE_k, KCODE_l, KCODE_m, KCODE_n, KCODE_o, KCODE_p,
KCODE_q, KCODE_r, KCODE_s, KCODE_t, KCODE_u, KCODE_v, KCODE_w, KCODE_x,
KCODE_y, KCODE_z,
KCODE_0, KCODE_1, KCODE_2, KCODE_3, KCODE_4, KCODE_5, KCODE_6, KCODE_7,
KCODE_8, KCODE_9,
KCODE_KP0, KCODE_KP1, KCODE_KP2, KCODE_KP3, KCODE_KP4, KCODE_KP5, KCODE_KP6,
KCODE_KP7, KCODE_KP8, KCODE_KP9, KCODE_KP_PERIOD, KCODE_KP_DIVIDE,
KCODE_KP_MULTIPLY, KCODE_KP_MINUS, KCODE_KP_PLUS, KCODE_KP_ENTER,
KCODE_KP_EQUALS,
KCODE_BACKSPACE, KCODE_TAB, KCODE_CLEAR, KCODE_RETURN,
KCODE_ESCAPE, KCODE_SPACE, KCODE_COMMA, KCODE_MINUS, KCODE_PERIOD,
KCODE_SLASH, KCODE_BACKSLASH, KCODE_SEMICOLON, KCODE_EQUALS,
KCODE_QUOTE, KCODE_BACKQUOTE, KCODE_LEFTBRACKET, KCODE_RIGHTBRACKET,
KCODE_PRTSCREEN, KCODE_SCRLOCK, KCODE_PAUSE,
KCODE_INSERT, KCODE_HOME, KCODE_PAGEUP,
KCODE_DELETE, KCODE_END, KCODE_PAGEDOWN,
KCODE_LCTRL, KCODE_RCTRL, KCODE_LALT, KCODE_RALT, KCODE_LWIN,
KCODE_RWIN, KCODE_MENU, KCODE_UP, KCODE_DOWN, KCODE_LEFT, KCODE_RIGHT,
KCODE_F1, KCODE_F2, KCODE_F3, KCODE_F4, KCODE_F5, KCODE_F6, KCODE_F7,
KCODE_F8, KCODE_F9, KCODE_F10, KCODE_F11, KCODE_F12, KCODE_F13,
KCODE_F14, KCODE_F15,
LastKCODE
};
/**
Enumeration of joystick codes and states
*/
enum JoyStick
{
JSTICK_0, JSTICK_1, JSTICK_2, JSTICK_3, JSTICK_4, JSTICK_5,
LastJSTICK
};
enum JoyCode
{
JAXIS_UP, JAXIS_DOWN, JAXIS_LEFT, JAXIS_RIGHT,
JBUTTON_0, JBUTTON_1, JBUTTON_2, JBUTTON_3, JBUTTON_4,
JBUTTON_5, JBUTTON_6, JBUTTON_7, JBUTTON_8, JBUTTON_9,
JBUTTON_10, JBUTTON_11, JBUTTON_12, JBUTTON_13, JBUTTON_14,
JBUTTON_15, JBUTTON_16, JBUTTON_17, JBUTTON_18, JBUTTON_19,
LastJCODE
};
};
#endif

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.15 2005-05-16 15:37:30 stephena Exp $
// $Id: Dialog.cxx,v 1.16 2005-05-25 23:22:11 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -283,6 +283,22 @@ void Dialog::handleMouseMoved(int x, int y, int button)
w->handleMouseMoved(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleJoyDown(int x, int y, int stick, int button)
{
// Focused widget receives joystick events
if(_focusedWidget)
_focusedWidget->handleJoyDown(x, y, stick, button);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleJoyUp(int x, int y, int stick, int button)
{
// Focused widget receives joystick events
if(_focusedWidget)
_focusedWidget->handleJoyUp(x, y, stick, button);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleTickle()
{

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.13 2005-05-16 15:37:30 stephena Exp $
// $Id: Dialog.hxx,v 1.14 2005-05-25 23:22:11 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -35,7 +35,7 @@ class DialogContainer;
This is the base class for all dialog boxes.
@author Stephen Anthony
@version $Id: Dialog.hxx,v 1.13 2005-05-16 15:37:30 stephena Exp $
@version $Id: Dialog.hxx,v 1.14 2005-05-25 23:22:11 stephena Exp $
*/
class Dialog : public GuiObject
{
@ -68,6 +68,8 @@ class Dialog : public GuiObject
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
virtual void handleMouseMoved(int x, int y, int button);
virtual void handleJoyDown(int x, int y, int stick, int button);
virtual void handleJoyUp(int x, int y, int stick, int button);
virtual void handleCommand(CommandSender* sender, int cmd, int data);
virtual void handleScreenChanged() {}

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.5 2005-05-16 15:37:30 stephena Exp $
// $Id: DialogContainer.cxx,v 1.6 2005-05-25 23:22:11 stephena Exp $
//============================================================================
#include "OSystem.hxx"
@ -163,3 +163,18 @@ void DialogContainer::handleMouseButtonEvent(MouseButton b, int x, int y, uInt8
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::handleJoyEvent(int x, int y, int stick, int button,
uInt8 state)
{
if(myDialogStack.empty())
return;
// Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top();
if(state == 1)
activeDialog->handleJoyDown(x, y, stick, button);
else
activeDialog->handleJoyUp(x, y, stick, 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: DialogContainer.hxx,v 1.2 2005-05-13 18:28:05 stephena Exp $
// $Id: DialogContainer.hxx,v 1.3 2005-05-25 23:22:11 stephena Exp $
//============================================================================
#ifndef DIALOG_CONTAINER_HXX
@ -37,7 +37,7 @@ typedef FixedStack<Dialog *> DialogStack;
a stack, and handles their events.
@author Stephen Anthony
@version $Id: DialogContainer.hxx,v 1.2 2005-05-13 18:28:05 stephena Exp $
@version $Id: DialogContainer.hxx,v 1.3 2005-05-25 23:22:11 stephena Exp $
*/
class DialogContainer
{
@ -81,7 +81,16 @@ class DialogContainer
*/
void handleMouseButtonEvent(MouseButton b, int x, int y, uInt8 state);
// FIXME - add joystick handler
/**
Handle a joystick button event.
@param x The x location
@param y The y location
@param stick The joystick number
@param button The joystick button
@param state The state (pressed or released)
*/
void handleJoyEvent(int x, int y, int stick, int button, uInt8 state);
/**
Draw the stack of menus.

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: EventMappingDialog.cxx,v 1.10 2005-05-16 00:02:32 stephena Exp $
// $Id: EventMappingDialog.cxx,v 1.11 2005-05-25 23:22:11 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -190,6 +190,21 @@ void EventMappingDialog::handleKeyDown(int ascii, int keycode, int modifiers)
myActionsList->handleKeyDown(ascii, keycode, modifiers);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingDialog::handleJoyDown(int x, int y, int stick, int button)
{
// Remap joystick buttons in remap mode, otherwise pass to listwidget
if(myRemapStatus && myActionSelected >= 0)
{
Event::Type event = EventHandler::ourActionList[ myActionSelected ].event;
instance()->eventHandler().addJoyMapping(event, stick, button);
stopRemapping();
}
else
myActionsList->handleJoyDown(x, y, stick, button);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingDialog::handleCommand(CommandSender* sender, int cmd, int data)
{

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: EventMappingDialog.hxx,v 1.7 2005-05-16 00:02:32 stephena Exp $
// $Id: EventMappingDialog.hxx,v 1.8 2005-05-25 23:22:11 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -40,6 +40,7 @@ class EventMappingDialog : public Dialog
~EventMappingDialog();
virtual void handleKeyDown(int ascii, int keycode, int modifiers);
virtual void handleJoyDown(int x, int y, int stick, int button);
protected:
ButtonWidget* myMapButton;

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.11 2005-05-18 22:54:01 stephena Exp $
// $Id: Widget.hxx,v 1.12 2005-05-25 23:22:11 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -65,7 +65,7 @@ enum {
This is the base class for all widgets.
@author Stephen Anthony
@version $Id: Widget.hxx,v 1.11 2005-05-18 22:54:01 stephena Exp $
@version $Id: Widget.hxx,v 1.12 2005-05-25 23:22:11 stephena Exp $
*/
class Widget : public GuiObject
{
@ -86,6 +86,8 @@ class Widget : public GuiObject
virtual void handleMouseWheel(int x, int y, int direction) {}
virtual bool handleKeyDown(int ascii, int keycode, int modifiers) { return false; }
virtual bool handleKeyUp(int ascii, int keycode, int modifiers) { return false; }
virtual void handleJoyDown(int x, int y, int stick, int button) {}
virtual void handleJoyUp(int x, int y, int stick, int button) {}
virtual void handleTickle() {}
void draw();