aboutsummaryrefslogtreecommitdiff
path: root/backends/events/sdl
diff options
context:
space:
mode:
authorAlejandro Marzini2010-06-30 04:46:55 +0000
committerAlejandro Marzini2010-06-30 04:46:55 +0000
commitc174d5327bfaf55d998cf67f3e4f49a0eaf2ed39 (patch)
treeb642082f28dd9de53c95f64aba19a4a789bd2bfc /backends/events/sdl
parentafd2a2c01d4bf3686a54c631d1cd4228ba1d710c (diff)
downloadscummvm-rg350-c174d5327bfaf55d998cf67f3e4f49a0eaf2ed39.tar.gz
scummvm-rg350-c174d5327bfaf55d998cf67f3e4f49a0eaf2ed39.tar.bz2
scummvm-rg350-c174d5327bfaf55d998cf67f3e4f49a0eaf2ed39.zip
Modularized GP2XWIZ backend.
svn-id: r50514
Diffstat (limited to 'backends/events/sdl')
-rw-r--r--backends/events/sdl/sdl-events.cpp24
-rw-r--r--backends/events/sdl/sdl-events.h16
2 files changed, 21 insertions, 19 deletions
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 8171929627..c66e45395b 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -55,23 +55,22 @@ SdlEventManager::SdlEventManager(Common::EventSource *boss)
_lastScreenID(0),
DefaultEventManager(boss) {
- // reset mouse state
+ // Reset mouse state
memset(&_km, 0, sizeof(_km));
int joystick_num = ConfMan.getInt("joystick_num");
-
if (joystick_num > -1) {
+ // Initialize SDL joystick subsystem
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) {
error("Could not initialize SDL: %s", SDL_GetError());
}
- }
- // enable joystick
- if (joystick_num > -1 && SDL_NumJoysticks() > 0) {
- printf("Using joystick: %s\n", SDL_JoystickName(0));
- _joystick = SDL_JoystickOpen(joystick_num);
+ // Enable joystick
+ if (SDL_NumJoysticks() > 0) {
+ printf("Using joystick: %s\n", SDL_JoystickName(0));
+ _joystick = SDL_JoystickOpen(joystick_num);
+ }
}
-
}
SdlEventManager::~SdlEventManager() {
@@ -79,7 +78,7 @@ SdlEventManager::~SdlEventManager() {
SDL_JoystickClose(_joystick);
}
-static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) {
+int SdlEventManager::mapKey(SDLKey key, SDLMod mod, Uint16 unicode) {
if (key >= SDLK_F1 && key <= SDLK_F9) {
return key - SDLK_F1 + Common::ASCII_F1;
} else if (key >= SDLK_KP0 && key <= SDLK_KP9) {
@@ -177,7 +176,7 @@ void SdlEventManager::handleKbdMouse() {
}
}
-static void SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event) {
+void SdlEventManager::SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event) {
event.kbd.flags = 0;
@@ -203,8 +202,6 @@ static void SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event) {
}
bool SdlEventManager::pollSdlEvent(Common::Event &event) {
- SDL_Event ev;
-
handleKbdMouse();
// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
@@ -215,6 +212,7 @@ bool SdlEventManager::pollSdlEvent(Common::Event &event) {
return true;
}
+ SDL_Event ev;
while (SDL_PollEvent(&ev)) {
preprocessEvents(&ev);
if (dispatchSDLEvent(ev, event))
@@ -484,7 +482,7 @@ bool SdlEventManager::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
if ( ev.jaxis.axis == JOY_XAXIS) {
#ifdef JOY_ANALOG
- _km.x_vel = axis/2000;
+ _km.x_vel = axis / 2000;
_km.x_down_count = 0;
#else
if (axis != 0) {
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index 0f6cb998a8..3b3098dc29 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -46,8 +46,6 @@ public:
virtual void toggleMouseGrab();
protected:
- virtual void preprocessEvents(SDL_Event *event) {}
-
// Keyboard mouse emulation. Disabled by fingolfin 2004-12-18.
// I am keeping the rest of the code in for now, since the joystick
// code (or rather, "hack") uses it, too.
@@ -55,19 +53,24 @@ protected:
int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count;
uint32 last_time, delay_time, x_down_time, y_down_time;
};
-
KbdMouse _km;
// Scroll lock state - since SDL doesn't track it
bool _scrollLock;
- // joystick
+ // Joystick
SDL_Joystick *_joystick;
+ int _lastScreenID;
+
+ // Pre process an event before it is dispatched.
+ virtual void preprocessEvents(SDL_Event *event) {}
+
+ // Dispatchs SDL events for each handler.
virtual bool dispatchSDLEvent(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
+ // This way, if a managers inherits fromt this SDL events manager, it can
// change the behavior of only a single event, without having to override all
// of pollEvent.
virtual bool handleKeyDown(SDL_Event &ev, Common::Event &event);
@@ -84,7 +87,8 @@ protected:
virtual void handleKbdMouse();
virtual bool remapKey(SDL_Event &ev, Common::Event &event);
- int _lastScreenID;
+ virtual int mapKey(SDLKey key, SDLMod mod, Uint16 unicode);
+ virtual void SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event);
};
#endif