aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl
diff options
context:
space:
mode:
authorMax Horn2009-11-09 23:31:46 +0000
committerMax Horn2009-11-09 23:31:46 +0000
commitfc1758f33b31a9cbc5630643cf7c4017923fac7f (patch)
tree60f12ba04a9ae87028b7f0c8f15875efa77cce63 /backends/platform/sdl
parent9d816caf560bd53c8be6b1f804f97d0a4d658df2 (diff)
downloadscummvm-rg350-fc1758f33b31a9cbc5630643cf7c4017923fac7f.tar.gz
scummvm-rg350-fc1758f33b31a9cbc5630643cf7c4017923fac7f.tar.bz2
scummvm-rg350-fc1758f33b31a9cbc5630643cf7c4017923fac7f.zip
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
Diffstat (limited to 'backends/platform/sdl')
-rw-r--r--backends/platform/sdl/events.cpp97
-rw-r--r--backends/platform/sdl/sdl.cpp8
-rw-r--r--backends/platform/sdl/sdl.h19
3 files changed, 88 insertions, 36 deletions
diff --git a/backends/platform/sdl/events.cpp b/backends/platform/sdl/events.cpp
index e5d0c1687c..3dc9649c9a 100644
--- a/backends/platform/sdl/events.cpp
+++ b/backends/platform/sdl/events.cpp
@@ -173,8 +173,6 @@ static byte SDLModToOSystemKeyFlags(SDLMod mod) {
bool OSystem_SDL::pollEvent(Common::Event &event) {
SDL_Event ev;
- int axis;
- byte b = 0;
handleKbdMouse();
@@ -187,9 +185,47 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
while (SDL_PollEvent(&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) {
- 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());
// Alt-Return and Alt-Enter toggle full screen mode
@@ -205,7 +241,7 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
displayMessageOnOSD("Windowed mode");
#endif
- break;
+ return false;
}
// Alt-S: Create a screenshot
@@ -218,20 +254,20 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
sprintf(filename, "scummvm%05d.bmp", n);
file = SDL_RWFromFile(filename, "r");
if (!file)
- break;
+ return false;
SDL_RWclose(file);
}
if (saveScreenshot(filename))
printf("Saved '%s'\n", filename);
else
printf("Could not save screenshot!\n");
- break;
+ return false;
}
// Ctrl-m toggles mouse capture
if (b == Common::KBD_CTRL && ev.key.keysym.sym == 'm') {
toggleMouseGrab();
- break;
+ return false;
}
#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)) {
handleScalerHotkeys(ev.key);
- break;
+ return false;
}
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);
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);
if (event_complete)
@@ -291,19 +328,21 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
// Ctrl-Alt-<key> will change the GFX mode
if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) {
// Swallow these key up events
- break;
+ return false;
}
return true;
- }
- case SDL_MOUSEMOTION:
+}
+
+bool OSystem_SDL::handleMouseMotion(const SDL_Event &ev, Common::Event &event) {
event.type = Common::EVENT_MOUSEMOVE;
fillMouseEvent(event, ev.motion.x, ev.motion.y);
setMousePos(event.mouse.x, event.mouse.y);
return true;
+}
- case SDL_MOUSEBUTTONDOWN:
+bool OSystem_SDL::handleMouseButtonDown(const SDL_Event &ev, Common::Event &event) {
if (ev.button.button == SDL_BUTTON_LEFT)
event.type = Common::EVENT_LBUTTONDOWN;
else if (ev.button.button == SDL_BUTTON_RIGHT)
@@ -319,13 +358,14 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
event.type = Common::EVENT_MBUTTONDOWN;
#endif
else
- break;
+ return false;
fillMouseEvent(event, ev.button.x, ev.button.y);
return true;
+}
- case SDL_MOUSEBUTTONUP:
+bool OSystem_SDL::handleMouseButtonUp(const SDL_Event &ev, Common::Event &event) {
if (ev.button.button == SDL_BUTTON_LEFT)
event.type = Common::EVENT_LBUTTONUP;
else if (ev.button.button == SDL_BUTTON_RIGHT)
@@ -335,12 +375,13 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
event.type = Common::EVENT_MBUTTONUP;
#endif
else
- break;
+ return false;
fillMouseEvent(event, ev.button.x, ev.button.y);
return true;
+}
- case SDL_JOYBUTTONDOWN:
+bool OSystem_SDL::handleJoyButtonDown(const SDL_Event &ev, Common::Event &event) {
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
event.type = Common::EVENT_LBUTTONDOWN;
fillMouseEvent(event, _km.x, _km.y);
@@ -369,8 +410,9 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
}
}
return true;
+}
- case SDL_JOYBUTTONUP:
+bool OSystem_SDL::handleJoyButtonUp(const SDL_Event &ev, Common::Event &event) {
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
event.type = Common::EVENT_LBUTTONUP;
fillMouseEvent(event, _km.x, _km.y);
@@ -399,8 +441,10 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
}
}
return true;
+}
- case SDL_JOYAXISMOTION:
+bool OSystem_SDL::handleJoyAxisMotion(const SDL_Event &ev, Common::Event &event) {
+ int axis;
axis = ev.jaxis.value;
if ( axis > JOY_DEADZONE) {
axis -= JOY_DEADZONE;
@@ -446,17 +490,6 @@ bool OSystem_SDL::pollEvent(Common::Event &event) {
fillMouseEvent(event, _km.x, _km.y);
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) {
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 28c0c92ebf..e3e8947daa 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -235,7 +235,7 @@ OSystem_SDL::OSystem_SDL()
_joystick(0),
_currentShakePos(0), _newShakePos(0),
_paletteDirtyStart(0), _paletteDirtyEnd(0),
-#ifdef MIXER_DOUBLE_BUFFERING
+#if MIXER_DOUBLE_BUFFERING
_soundMutex(0), _soundCond(0), _soundThread(0),
_soundThreadIsRunning(false), _soundThreadShouldQuit(false),
#endif
@@ -595,7 +595,7 @@ void OSystem_SDL::deleteMutex(MutexRef mutex) {
#pragma mark --- Audio ---
#pragma mark -
-#ifdef MIXER_DOUBLE_BUFFERING
+#if MIXER_DOUBLE_BUFFERING
void OSystem_SDL::mixerProducerThread() {
byte nextSoundBuffer;
@@ -745,7 +745,7 @@ void OSystem_SDL::setupMixer() {
_mixer->setOutputRate(_samplesPerSec);
_mixer->setReady(true);
-#ifdef MIXER_DOUBLE_BUFFERING
+#if MIXER_DOUBLE_BUFFERING
initThreadedMixer(_mixer, _obtainedRate.samples * 4);
#endif
@@ -763,7 +763,7 @@ void OSystem_SDL::closeMixer() {
delete _mixer;
_mixer = 0;
-#ifdef MIXER_DOUBLE_BUFFERING
+#if MIXER_DOUBLE_BUFFERING
deinitThreadedMixer();
#endif
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index e76d68766c..e17cd5c086 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -156,6 +156,25 @@ public:
// Returns true if an event was retrieved.
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
virtual Common::HardwareKeySet *getHardwareKeySet();