[Scummvm-cvs-logs] SF.net SVN: scummvm:[45792] scummvm/trunk/backends/platform/sdl
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Tue Nov 10 00:31:46 CET 2009
Revision: 45792
http://scummvm.svn.sourceforge.net/scummvm/?rev=45792&view=rev
Author: fingolfin
Date: 2009-11-09 23:31:46 +0000 (Mon, 09 Nov 2009)
Log Message:
-----------
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)
Modified Paths:
--------------
scummvm/trunk/backends/platform/sdl/events.cpp
scummvm/trunk/backends/platform/sdl/sdl.cpp
scummvm/trunk/backends/platform/sdl/sdl.h
Modified: scummvm/trunk/backends/platform/sdl/events.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/events.cpp 2009-11-09 23:29:33 UTC (rev 45791)
+++ scummvm/trunk/backends/platform/sdl/events.cpp 2009-11-09 23:31:46 UTC (rev 45792)
@@ -173,8 +173,6 @@
bool OSystem_SDL::pollEvent(Common::Event &event) {
SDL_Event ev;
- int axis;
- byte b = 0;
handleKbdMouse();
@@ -187,9 +185,47 @@
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 @@
displayMessageOnOSD("Windowed mode");
#endif
- break;
+ return false;
}
// Alt-S: Create a screenshot
@@ -218,20 +254,20 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
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 @@
}
}
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 @@
}
}
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 @@
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) {
Modified: scummvm/trunk/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.cpp 2009-11-09 23:29:33 UTC (rev 45791)
+++ scummvm/trunk/backends/platform/sdl/sdl.cpp 2009-11-09 23:31:46 UTC (rev 45792)
@@ -235,7 +235,7 @@
_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 @@
#pragma mark --- Audio ---
#pragma mark -
-#ifdef MIXER_DOUBLE_BUFFERING
+#if MIXER_DOUBLE_BUFFERING
void OSystem_SDL::mixerProducerThread() {
byte nextSoundBuffer;
@@ -745,7 +745,7 @@
_mixer->setOutputRate(_samplesPerSec);
_mixer->setReady(true);
-#ifdef MIXER_DOUBLE_BUFFERING
+#if MIXER_DOUBLE_BUFFERING
initThreadedMixer(_mixer, _obtainedRate.samples * 4);
#endif
@@ -763,7 +763,7 @@
delete _mixer;
_mixer = 0;
-#ifdef MIXER_DOUBLE_BUFFERING
+#if MIXER_DOUBLE_BUFFERING
deinitThreadedMixer();
#endif
Modified: scummvm/trunk/backends/platform/sdl/sdl.h
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.h 2009-11-09 23:29:33 UTC (rev 45791)
+++ scummvm/trunk/backends/platform/sdl/sdl.h 2009-11-09 23:31:46 UTC (rev 45792)
@@ -156,6 +156,25 @@
// 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();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list