mirror of https://github.com/stella-emu/stella.git
Reworked FrameBuffer::update() and FrameBuffer::refresh(). Sometimes the
mediasource and overlay need to redrawn independently of each other. Added mouse and joystick events passing to the debugger. Fixed bug whereby if a settings file didn't exist, the default mapping for a joystick wasn't being done. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@449 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
9887210759
commit
6706fb41f7
|
@ -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.63 2005-05-27 18:00:47 stephena Exp $
|
||||
// $Id: EventHandler.cxx,v 1.64 2005-05-28 17:25:41 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -664,14 +664,15 @@ void EventHandler::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventHandler::handleMouseMotionEvent(SDL_Event& event)
|
||||
{
|
||||
// Take window zooming into account
|
||||
int x = event.motion.x, y = event.motion.y;
|
||||
myOSystem->frameBuffer().translateCoords(&x, &y);
|
||||
|
||||
// Determine which mode we're in, then send the event to the appropriate place
|
||||
switch(myState)
|
||||
{
|
||||
case S_EMULATE:
|
||||
{
|
||||
// Take window zooming into account
|
||||
Int32 x = event.motion.x, y = event.motion.y;
|
||||
myOSystem->frameBuffer().translateCoords(&x, &y);
|
||||
int w = myOSystem->frameBuffer().baseWidth();
|
||||
|
||||
// Grabmouse introduces some lag into the mouse movement,
|
||||
|
@ -684,26 +685,15 @@ void EventHandler::handleMouseMotionEvent(SDL_Event& event)
|
|||
}
|
||||
|
||||
case S_MENU:
|
||||
{
|
||||
// Take window zooming into account
|
||||
Int32 x = event.motion.x, y = event.motion.y;
|
||||
myOSystem->frameBuffer().translateCoords(&x, &y);
|
||||
myOSystem->menu().handleMouseMotionEvent(x, y, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case S_LAUNCHER:
|
||||
{
|
||||
// Take window zooming into account
|
||||
Int32 x = event.motion.x, y = event.motion.y;
|
||||
myOSystem->frameBuffer().translateCoords(&x, &y);
|
||||
myOSystem->launcher().handleMouseMotionEvent(x, y, 0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_DEBUGGER:
|
||||
// Not yet implemented
|
||||
myOSystem->debugger().handleMouseMotionEvent(x, y, 0);
|
||||
break;
|
||||
|
||||
case S_NONE:
|
||||
|
@ -724,6 +714,7 @@ void EventHandler::handleMouseButtonEvent(SDL_Event& event, uInt8 state)
|
|||
|
||||
case S_MENU:
|
||||
case S_LAUNCHER:
|
||||
case S_DEBUGGER:
|
||||
{
|
||||
// Take window zooming into account
|
||||
Int32 x = event.button.x, y = event.button.y;
|
||||
|
@ -757,17 +748,14 @@ void EventHandler::handleMouseButtonEvent(SDL_Event& event, uInt8 state)
|
|||
|
||||
if(myState == S_MENU)
|
||||
myOSystem->menu().handleMouseButtonEvent(button, x, y, state);
|
||||
else
|
||||
else if(myState == S_LAUNCHER)
|
||||
myOSystem->launcher().handleMouseButtonEvent(button, x, y, state);
|
||||
else
|
||||
myOSystem->debugger().handleMouseButtonEvent(button, x, y, state);
|
||||
break;
|
||||
}
|
||||
|
||||
case S_DEBUGGER:
|
||||
// Not yet implemented
|
||||
break;
|
||||
|
||||
case S_NONE:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -792,7 +780,7 @@ void EventHandler::handleJoyEvent(uInt8 stick, uInt32 code, uInt8 state)
|
|||
break;
|
||||
|
||||
case S_DEBUGGER:
|
||||
// Not yet implemented
|
||||
myOSystem->debugger().handleJoyEvent(stick, code, state);
|
||||
break;
|
||||
|
||||
case S_NONE:
|
||||
|
@ -996,18 +984,18 @@ void EventHandler::addKeyMapping(Event::Type event, uInt16 key)
|
|||
return;
|
||||
|
||||
myKeyTable[key] = event;
|
||||
saveKeyMapping();
|
||||
|
||||
setActionMappings();
|
||||
saveMappings();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventHandler::addJoyMapping(Event::Type event, uInt8 stick, uInt32 code)
|
||||
{
|
||||
myJoyTable[stick * kNumJoyButtons + code] = event;
|
||||
saveJoyMapping();
|
||||
|
||||
setActionMappings();
|
||||
saveMappings();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -1017,14 +1005,15 @@ void EventHandler::eraseMapping(Event::Type event)
|
|||
for(Int32 i = 0; i < SDLK_LAST; ++i)
|
||||
if(myKeyTable[i] == event && i != SDLK_TAB && i != SDLK_ESCAPE)
|
||||
myKeyTable[i] = Event::NoType;
|
||||
saveKeyMapping();
|
||||
|
||||
// Erase the JoyEvent array
|
||||
for(Int32 i = 0; i < kNumJoysticks * kNumJoyButtons; ++i)
|
||||
if(myJoyTable[i] == event)
|
||||
myJoyTable[i] = Event::NoType;
|
||||
saveJoyMapping();
|
||||
|
||||
setActionMappings();
|
||||
saveMappings();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -1034,7 +1023,6 @@ void EventHandler::setDefaultMapping()
|
|||
setDefaultJoymap();
|
||||
|
||||
setActionMappings();
|
||||
saveMappings();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -1111,14 +1099,13 @@ void EventHandler::setDefaultKeymap()
|
|||
myKeyTable[ SDLK_BACKQUOTE ] = Event::DebuggerMode;
|
||||
myKeyTable[ SDLK_ESCAPE ] = Event::LauncherMode;
|
||||
|
||||
saveMappings();
|
||||
saveKeyMapping();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventHandler::setDefaultJoymap()
|
||||
{
|
||||
uInt32 i;
|
||||
uInt32 c = kNumJoyButtons - 4; // Upper 4 buttons are the directions
|
||||
|
||||
// Erase all mappings
|
||||
for(i = 0; i < kNumJoysticks * kNumJoyButtons; ++i)
|
||||
|
@ -1126,36 +1113,42 @@ void EventHandler::setDefaultJoymap()
|
|||
|
||||
// Left joystick
|
||||
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;
|
||||
myJoyTable[i + kJAxisUp] = Event::JoystickZeroUp;
|
||||
myJoyTable[i + kJAxisDown] = Event::JoystickZeroDown;
|
||||
myJoyTable[i + kJAxisLeft] = Event::JoystickZeroLeft;
|
||||
myJoyTable[i + kJAxisRight] = Event::JoystickZeroRight;
|
||||
myJoyTable[i + 0] = Event::JoystickZeroFire;
|
||||
|
||||
// Right joystick
|
||||
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;
|
||||
myJoyTable[i + kJAxisUp] = Event::JoystickOneUp;
|
||||
myJoyTable[i + kJAxisDown] = Event::JoystickOneDown;
|
||||
myJoyTable[i + kJAxisLeft] = Event::JoystickOneLeft;
|
||||
myJoyTable[i + kJAxisRight] = Event::JoystickOneRight;
|
||||
myJoyTable[i + 0] = Event::JoystickOneFire;
|
||||
|
||||
saveMappings();
|
||||
saveJoyMapping();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventHandler::saveMappings()
|
||||
void EventHandler::saveKeyMapping()
|
||||
{
|
||||
// Iterate through the keymap table and create a colon-separated list
|
||||
ostringstream keybuf;
|
||||
for(uInt32 i = 0; i < SDLK_LAST; ++i)
|
||||
keybuf << myKeyTable[i] << ":";
|
||||
myOSystem->settings().setString("keymap", keybuf.str());
|
||||
|
||||
myOSystem->settings().setString("keymap", keybuf.str());
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventHandler::saveJoyMapping()
|
||||
{
|
||||
// Iterate through the joymap table and create a colon-separated list
|
||||
ostringstream joybuf;
|
||||
for(Int32 i = 0; i < kNumJoysticks * kNumJoyButtons; ++i)
|
||||
joybuf << myJoyTable[i] << ":";
|
||||
|
||||
myOSystem->settings().setString("joymap", joybuf.str());
|
||||
}
|
||||
|
||||
|
@ -1323,7 +1316,7 @@ cerr << "S_DEBUGGER entered\n";
|
|||
myState = S_DEBUGGER;
|
||||
myOSystem->createFrameBuffer();
|
||||
myOSystem->debugger().reStack();
|
||||
myOSystem->frameBuffer().refresh(); // FIXME - theRedrawEntireFrameIndicator not properly set
|
||||
myOSystem->frameBuffer().refresh();
|
||||
myOSystem->frameBuffer().setCursorState();
|
||||
myEvent->clear();
|
||||
|
||||
|
|
|
@ -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.33 2005-05-27 18:00:48 stephena Exp $
|
||||
// $Id: EventHandler.hxx,v 1.34 2005-05-28 17:25:41 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef EVENTHANDLER_HXX
|
||||
|
@ -74,7 +74,7 @@ struct Stella_Joystick {
|
|||
mapping can take place.
|
||||
|
||||
@author Stephen Anthony
|
||||
@version $Id: EventHandler.hxx,v 1.33 2005-05-27 18:00:48 stephena Exp $
|
||||
@version $Id: EventHandler.hxx,v 1.34 2005-05-28 17:25:41 stephena Exp $
|
||||
*/
|
||||
class EventHandler
|
||||
{
|
||||
|
@ -244,7 +244,8 @@ class EventHandler
|
|||
void setJoymap();
|
||||
void setDefaultKeymap();
|
||||
void setDefaultJoymap();
|
||||
void saveMappings();
|
||||
void saveKeyMapping();
|
||||
void saveJoyMapping();
|
||||
|
||||
bool isValidList(string list, uInt32 length);
|
||||
|
||||
|
|
|
@ -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.39 2005-05-27 18:00:48 stephena Exp $
|
||||
// $Id: FrameBuffer.cxx,v 1.40 2005-05-28 17:25:41 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <sstream>
|
||||
|
@ -44,10 +44,10 @@ FrameBuffer::FrameBuffer(OSystem* osystem)
|
|||
theUseAspectRatioFlag(true),
|
||||
myFrameRate(0),
|
||||
myPauseStatus(false),
|
||||
theMenuChangedIndicator(false),
|
||||
theOverlayChangedIndicator(false),
|
||||
myMessageTime(0),
|
||||
myMessageText(""),
|
||||
myMenuRedraws(2),
|
||||
myOverlayRedraws(2),
|
||||
myNumRedraws(0)
|
||||
{
|
||||
// Fill the GUI colors array
|
||||
|
@ -198,32 +198,31 @@ void FrameBuffer::update()
|
|||
|
||||
case EventHandler::S_MENU:
|
||||
{
|
||||
// Only update the screen if it's been invalidated or the menus have changed
|
||||
if(theRedrawEntireFrameIndicator || theMenuChangedIndicator)
|
||||
{
|
||||
// Only update the screen if it's been invalidated
|
||||
if(theRedrawEntireFrameIndicator)
|
||||
drawMediaSource();
|
||||
|
||||
// Only update the overlay if it's changed
|
||||
if(theOverlayChangedIndicator)
|
||||
{
|
||||
// Then overlay any menu items
|
||||
myOSystem->menu().draw();
|
||||
|
||||
// Now the screen is up to date
|
||||
theRedrawEntireFrameIndicator = false;
|
||||
|
||||
// This is a performance hack to only draw the menus when necessary
|
||||
// This is a performance hack to only draw the overlay when necessary
|
||||
// Software mode is single-buffered, so we don't have to worry
|
||||
// However, OpenGL mode is double-buffered, so we need to draw the
|
||||
// menus at least twice (so they'll be in both buffers)
|
||||
// Otherwise, we get horrible flickering
|
||||
myMenuRedraws--;
|
||||
theMenuChangedIndicator = (myMenuRedraws != 0);
|
||||
myOverlayRedraws--;
|
||||
theOverlayChangedIndicator = (myOverlayRedraws != 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case EventHandler::S_LAUNCHER:
|
||||
{
|
||||
// Only update the screen if it's been invalidated or the menus have changed
|
||||
if(theRedrawEntireFrameIndicator || theMenuChangedIndicator)
|
||||
// Only update the screen if it's been invalidated or the overlay have changed
|
||||
if(theRedrawEntireFrameIndicator || theOverlayChangedIndicator)
|
||||
{
|
||||
// Overlay the ROM launcher
|
||||
myOSystem->launcher().draw();
|
||||
|
@ -231,13 +230,13 @@ void FrameBuffer::update()
|
|||
// Now the screen is up to date
|
||||
theRedrawEntireFrameIndicator = false;
|
||||
|
||||
// This is a performance hack to only draw the menus when necessary
|
||||
// This is a performance hack to only draw the overlay when necessary
|
||||
// Software mode is single-buffered, so we don't have to worry
|
||||
// However, OpenGL mode is double-buffered, so we need to draw the
|
||||
// menus at least twice (so they'll be in both buffers)
|
||||
// Otherwise, we get horrible flickering
|
||||
myMenuRedraws--;
|
||||
theMenuChangedIndicator = (myMenuRedraws != 0);
|
||||
myOverlayRedraws--;
|
||||
theOverlayChangedIndicator = (myOverlayRedraws != 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -247,25 +246,23 @@ void FrameBuffer::update()
|
|||
if(!myPauseStatus)
|
||||
myOSystem->console().mediaSource().update();
|
||||
|
||||
// We always draw the screen, even if the core is paused
|
||||
drawMediaSource();
|
||||
// Only update the screen if it's been invalidated
|
||||
if(theRedrawEntireFrameIndicator)
|
||||
drawMediaSource();
|
||||
|
||||
// Only update the screen if it's been invalidated or the menus have changed
|
||||
if(theRedrawEntireFrameIndicator || theMenuChangedIndicator)
|
||||
// Only update the overlay if it's changed
|
||||
if(theOverlayChangedIndicator)
|
||||
{
|
||||
// Overlay the ROM launcher
|
||||
myOSystem->debugger().draw();
|
||||
|
||||
// Now the screen is up to date
|
||||
theRedrawEntireFrameIndicator = false;
|
||||
|
||||
// This is a performance hack to only draw the menus when necessary
|
||||
// Software mode is single-buffered, so we don't have to worry
|
||||
// However, OpenGL mode is double-buffered, so we need to draw the
|
||||
// menus at least twice (so they'll be in both buffers)
|
||||
// Otherwise, we get horrible flickering
|
||||
myMenuRedraws--;
|
||||
theMenuChangedIndicator = (myMenuRedraws != 0);
|
||||
myOverlayRedraws--;
|
||||
theOverlayChangedIndicator = (myOverlayRedraws != 0);
|
||||
}
|
||||
break; // S_DEBUGGER
|
||||
|
||||
|
|
|
@ -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.34 2005-05-25 23:22:11 stephena Exp $
|
||||
// $Id: FrameBuffer.hxx,v 1.35 2005-05-28 17:25:41 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef FRAMEBUFFER_HXX
|
||||
|
@ -40,7 +40,7 @@ class OSystem;
|
|||
All GUI elements (ala ScummVM) are drawn here as well.
|
||||
|
||||
@author Stephen Anthony
|
||||
@version $Id: FrameBuffer.hxx,v 1.34 2005-05-25 23:22:11 stephena Exp $
|
||||
@version $Id: FrameBuffer.hxx,v 1.35 2005-05-28 17:25:41 stephena Exp $
|
||||
*/
|
||||
class FrameBuffer
|
||||
{
|
||||
|
@ -126,8 +126,8 @@ class FrameBuffer
|
|||
void pause(bool status);
|
||||
|
||||
/**
|
||||
Indicates that a redraw should be done, since the window contents
|
||||
are dirty.
|
||||
Indicates that the window contents are dirty, and certain areas need
|
||||
to be redrawn.
|
||||
|
||||
@param now Determine if the refresh should be done right away or in
|
||||
the next frame
|
||||
|
@ -136,7 +136,8 @@ class FrameBuffer
|
|||
{
|
||||
// cerr << "refresh() " << myNumRedraws++ << endl;
|
||||
theRedrawEntireFrameIndicator = true;
|
||||
myMenuRedraws = 2;
|
||||
theOverlayChangedIndicator = true;
|
||||
myOverlayRedraws = 2;
|
||||
if(now) update();
|
||||
}
|
||||
|
||||
|
@ -241,12 +242,6 @@ class FrameBuffer
|
|||
void frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
|
||||
OverlayColor color);
|
||||
|
||||
/**
|
||||
Indicate that the specified area should be redrawn.
|
||||
Currently we just redraw the entire screen.
|
||||
*/
|
||||
void addDirtyRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h) { refresh(); }
|
||||
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// The following methods are system-specific and must be implemented
|
||||
|
@ -440,7 +435,7 @@ class FrameBuffer
|
|||
bool myPauseStatus;
|
||||
|
||||
// Indicates if the menus should be redrawn
|
||||
bool theMenuChangedIndicator;
|
||||
bool theOverlayChangedIndicator;
|
||||
|
||||
// Message timer
|
||||
Int32 myMessageTime;
|
||||
|
@ -449,7 +444,7 @@ class FrameBuffer
|
|||
string myMessageText;
|
||||
|
||||
// Number of times menu have been drawn
|
||||
uInt32 myMenuRedraws;
|
||||
uInt32 myOverlayRedraws;
|
||||
|
||||
// Indicates how many times the framebuffer has been redrawn
|
||||
// Used only for debugging purposes
|
||||
|
|
Loading…
Reference in New Issue