SDL: Factor code from OSystem_SDL::pollEvent into various new virtual methods, to make it easier to customize these (no code indention changes for easier diffing)
svn-id: r45792
This commit is contained in:
parent
9d816caf56
commit
fc1758f33b
3 changed files with 88 additions and 36 deletions
|
@ -173,8 +173,6 @@ static byte SDLModToOSystemKeyFlags(SDLMod mod) {
|
||||||
|
|
||||||
bool OSystem_SDL::pollEvent(Common::Event &event) {
|
bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
SDL_Event ev;
|
SDL_Event ev;
|
||||||
int axis;
|
|
||||||
byte b = 0;
|
|
||||||
|
|
||||||
handleKbdMouse();
|
handleKbdMouse();
|
||||||
|
|
||||||
|
@ -187,9 +185,47 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
|
|
||||||
while (SDL_PollEvent(&ev)) {
|
while (SDL_PollEvent(&ev)) {
|
||||||
preprocessEvents(&ev);
|
preprocessEvents(&ev);
|
||||||
|
if (dispatchSDLEvent(ev, event))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OSystem_SDL::dispatchSDLEvent(const SDL_Event &ev, Common::Event &event) {
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
case SDL_KEYDOWN:{
|
case SDL_KEYDOWN:
|
||||||
|
return handleKeyDown(ev, event);
|
||||||
|
case SDL_KEYUP:
|
||||||
|
return handleKeyUp(ev, event);
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
return handleMouseMotion(ev, event);
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
return handleMouseButtonDown(ev, event);
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
return handleMouseButtonUp(ev, event);
|
||||||
|
case SDL_JOYBUTTONDOWN:
|
||||||
|
return handleJoyButtonDown(ev, event);
|
||||||
|
case SDL_JOYBUTTONUP:
|
||||||
|
return handleJoyButtonUp(ev, event);
|
||||||
|
case SDL_JOYAXISMOTION:
|
||||||
|
return handleJoyAxisMotion(ev, event);
|
||||||
|
|
||||||
|
case SDL_VIDEOEXPOSE:
|
||||||
|
_forceFull = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_QUIT:
|
||||||
|
event.type = Common::EVENT_QUIT;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool OSystem_SDL::handleKeyDown(const SDL_Event &ev, Common::Event &event) {
|
||||||
|
byte b = 0;
|
||||||
b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState());
|
b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState());
|
||||||
|
|
||||||
// Alt-Return and Alt-Enter toggle full screen mode
|
// Alt-Return and Alt-Enter toggle full screen mode
|
||||||
|
@ -205,7 +241,7 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
displayMessageOnOSD("Windowed mode");
|
displayMessageOnOSD("Windowed mode");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alt-S: Create a screenshot
|
// Alt-S: Create a screenshot
|
||||||
|
@ -218,20 +254,20 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
sprintf(filename, "scummvm%05d.bmp", n);
|
sprintf(filename, "scummvm%05d.bmp", n);
|
||||||
file = SDL_RWFromFile(filename, "r");
|
file = SDL_RWFromFile(filename, "r");
|
||||||
if (!file)
|
if (!file)
|
||||||
break;
|
return false;
|
||||||
SDL_RWclose(file);
|
SDL_RWclose(file);
|
||||||
}
|
}
|
||||||
if (saveScreenshot(filename))
|
if (saveScreenshot(filename))
|
||||||
printf("Saved '%s'\n", filename);
|
printf("Saved '%s'\n", filename);
|
||||||
else
|
else
|
||||||
printf("Could not save screenshot!\n");
|
printf("Could not save screenshot!\n");
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ctrl-m toggles mouse capture
|
// Ctrl-m toggles mouse capture
|
||||||
if (b == Common::KBD_CTRL && ev.key.keysym.sym == 'm') {
|
if (b == Common::KBD_CTRL && ev.key.keysym.sym == 'm') {
|
||||||
toggleMouseGrab();
|
toggleMouseGrab();
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MACOSX)
|
#if defined(MACOSX)
|
||||||
|
@ -263,7 +299,7 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) {
|
if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) {
|
||||||
|
|
||||||
handleScalerHotkeys(ev.key);
|
handleScalerHotkeys(ev.key);
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
const bool event_complete = remapKey(ev, event);
|
const bool event_complete = remapKey(ev, event);
|
||||||
|
|
||||||
|
@ -275,9 +311,10 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
|
event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case SDL_KEYUP:
|
|
||||||
{
|
bool OSystem_SDL::handleKeyUp(const SDL_Event &ev, Common::Event &event) {
|
||||||
|
byte b = 0;
|
||||||
const bool event_complete = remapKey(ev,event);
|
const bool event_complete = remapKey(ev,event);
|
||||||
|
|
||||||
if (event_complete)
|
if (event_complete)
|
||||||
|
@ -291,19 +328,21 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
// Ctrl-Alt-<key> will change the GFX mode
|
// Ctrl-Alt-<key> will change the GFX mode
|
||||||
if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) {
|
if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) {
|
||||||
// Swallow these key up events
|
// Swallow these key up events
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
|
bool OSystem_SDL::handleMouseMotion(const SDL_Event &ev, Common::Event &event) {
|
||||||
event.type = Common::EVENT_MOUSEMOVE;
|
event.type = Common::EVENT_MOUSEMOVE;
|
||||||
fillMouseEvent(event, ev.motion.x, ev.motion.y);
|
fillMouseEvent(event, ev.motion.x, ev.motion.y);
|
||||||
|
|
||||||
setMousePos(event.mouse.x, event.mouse.y);
|
setMousePos(event.mouse.x, event.mouse.y);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
bool OSystem_SDL::handleMouseButtonDown(const SDL_Event &ev, Common::Event &event) {
|
||||||
if (ev.button.button == SDL_BUTTON_LEFT)
|
if (ev.button.button == SDL_BUTTON_LEFT)
|
||||||
event.type = Common::EVENT_LBUTTONDOWN;
|
event.type = Common::EVENT_LBUTTONDOWN;
|
||||||
else if (ev.button.button == SDL_BUTTON_RIGHT)
|
else if (ev.button.button == SDL_BUTTON_RIGHT)
|
||||||
|
@ -319,13 +358,14 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
event.type = Common::EVENT_MBUTTONDOWN;
|
event.type = Common::EVENT_MBUTTONDOWN;
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
break;
|
return false;
|
||||||
|
|
||||||
fillMouseEvent(event, ev.button.x, ev.button.y);
|
fillMouseEvent(event, ev.button.x, ev.button.y);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
bool OSystem_SDL::handleMouseButtonUp(const SDL_Event &ev, Common::Event &event) {
|
||||||
if (ev.button.button == SDL_BUTTON_LEFT)
|
if (ev.button.button == SDL_BUTTON_LEFT)
|
||||||
event.type = Common::EVENT_LBUTTONUP;
|
event.type = Common::EVENT_LBUTTONUP;
|
||||||
else if (ev.button.button == SDL_BUTTON_RIGHT)
|
else if (ev.button.button == SDL_BUTTON_RIGHT)
|
||||||
|
@ -335,12 +375,13 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
event.type = Common::EVENT_MBUTTONUP;
|
event.type = Common::EVENT_MBUTTONUP;
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
break;
|
return false;
|
||||||
fillMouseEvent(event, ev.button.x, ev.button.y);
|
fillMouseEvent(event, ev.button.x, ev.button.y);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
case SDL_JOYBUTTONDOWN:
|
bool OSystem_SDL::handleJoyButtonDown(const SDL_Event &ev, Common::Event &event) {
|
||||||
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
||||||
event.type = Common::EVENT_LBUTTONDOWN;
|
event.type = Common::EVENT_LBUTTONDOWN;
|
||||||
fillMouseEvent(event, _km.x, _km.y);
|
fillMouseEvent(event, _km.x, _km.y);
|
||||||
|
@ -369,8 +410,9 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
case SDL_JOYBUTTONUP:
|
bool OSystem_SDL::handleJoyButtonUp(const SDL_Event &ev, Common::Event &event) {
|
||||||
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
||||||
event.type = Common::EVENT_LBUTTONUP;
|
event.type = Common::EVENT_LBUTTONUP;
|
||||||
fillMouseEvent(event, _km.x, _km.y);
|
fillMouseEvent(event, _km.x, _km.y);
|
||||||
|
@ -399,8 +441,10 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
case SDL_JOYAXISMOTION:
|
bool OSystem_SDL::handleJoyAxisMotion(const SDL_Event &ev, Common::Event &event) {
|
||||||
|
int axis;
|
||||||
axis = ev.jaxis.value;
|
axis = ev.jaxis.value;
|
||||||
if ( axis > JOY_DEADZONE) {
|
if ( axis > JOY_DEADZONE) {
|
||||||
axis -= JOY_DEADZONE;
|
axis -= JOY_DEADZONE;
|
||||||
|
@ -446,17 +490,6 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
|
||||||
fillMouseEvent(event, _km.x, _km.y);
|
fillMouseEvent(event, _km.x, _km.y);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case SDL_VIDEOEXPOSE:
|
|
||||||
_forceFull = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_QUIT:
|
|
||||||
event.type = Common::EVENT_QUIT;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OSystem_SDL::remapKey(const SDL_Event &ev, Common::Event &event) {
|
bool OSystem_SDL::remapKey(const SDL_Event &ev, Common::Event &event) {
|
||||||
|
|
|
@ -235,7 +235,7 @@ OSystem_SDL::OSystem_SDL()
|
||||||
_joystick(0),
|
_joystick(0),
|
||||||
_currentShakePos(0), _newShakePos(0),
|
_currentShakePos(0), _newShakePos(0),
|
||||||
_paletteDirtyStart(0), _paletteDirtyEnd(0),
|
_paletteDirtyStart(0), _paletteDirtyEnd(0),
|
||||||
#ifdef MIXER_DOUBLE_BUFFERING
|
#if MIXER_DOUBLE_BUFFERING
|
||||||
_soundMutex(0), _soundCond(0), _soundThread(0),
|
_soundMutex(0), _soundCond(0), _soundThread(0),
|
||||||
_soundThreadIsRunning(false), _soundThreadShouldQuit(false),
|
_soundThreadIsRunning(false), _soundThreadShouldQuit(false),
|
||||||
#endif
|
#endif
|
||||||
|
@ -595,7 +595,7 @@ void OSystem_SDL::deleteMutex(MutexRef mutex) {
|
||||||
#pragma mark --- Audio ---
|
#pragma mark --- Audio ---
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
#ifdef MIXER_DOUBLE_BUFFERING
|
#if MIXER_DOUBLE_BUFFERING
|
||||||
|
|
||||||
void OSystem_SDL::mixerProducerThread() {
|
void OSystem_SDL::mixerProducerThread() {
|
||||||
byte nextSoundBuffer;
|
byte nextSoundBuffer;
|
||||||
|
@ -745,7 +745,7 @@ void OSystem_SDL::setupMixer() {
|
||||||
_mixer->setOutputRate(_samplesPerSec);
|
_mixer->setOutputRate(_samplesPerSec);
|
||||||
_mixer->setReady(true);
|
_mixer->setReady(true);
|
||||||
|
|
||||||
#ifdef MIXER_DOUBLE_BUFFERING
|
#if MIXER_DOUBLE_BUFFERING
|
||||||
initThreadedMixer(_mixer, _obtainedRate.samples * 4);
|
initThreadedMixer(_mixer, _obtainedRate.samples * 4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -763,7 +763,7 @@ void OSystem_SDL::closeMixer() {
|
||||||
delete _mixer;
|
delete _mixer;
|
||||||
_mixer = 0;
|
_mixer = 0;
|
||||||
|
|
||||||
#ifdef MIXER_DOUBLE_BUFFERING
|
#if MIXER_DOUBLE_BUFFERING
|
||||||
deinitThreadedMixer();
|
deinitThreadedMixer();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,25 @@ public:
|
||||||
// Returns true if an event was retrieved.
|
// Returns true if an event was retrieved.
|
||||||
virtual bool pollEvent(Common::Event &event); // overloaded by CE backend
|
virtual bool pollEvent(Common::Event &event); // overloaded by CE backend
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool dispatchSDLEvent(const SDL_Event &ev, Common::Event &event);
|
||||||
|
|
||||||
|
// Handlers for specific SDL events, called by pollEvent.
|
||||||
|
// This way, if a backend inherits fromt the SDL backend, it can
|
||||||
|
// change the behavior of only a single event, without having to override all
|
||||||
|
// of pollEvent.
|
||||||
|
virtual bool handleKeyDown(const SDL_Event &ev, Common::Event &event);
|
||||||
|
virtual bool handleKeyUp(const SDL_Event &ev, Common::Event &event);
|
||||||
|
virtual bool handleMouseMotion(const SDL_Event &ev, Common::Event &event);
|
||||||
|
virtual bool handleMouseButtonDown(const SDL_Event &ev, Common::Event &event);
|
||||||
|
virtual bool handleMouseButtonUp(const SDL_Event &ev, Common::Event &event);
|
||||||
|
virtual bool handleJoyButtonDown(const SDL_Event &ev, Common::Event &event);
|
||||||
|
virtual bool handleJoyButtonUp(const SDL_Event &ev, Common::Event &event);
|
||||||
|
virtual bool handleJoyAxisMotion(const SDL_Event &ev, Common::Event &event);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
// Define all hardware keys for keymapper
|
// Define all hardware keys for keymapper
|
||||||
virtual Common::HardwareKeySet *getHardwareKeySet();
|
virtual Common::HardwareKeySet *getHardwareKeySet();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue