From 04ab0e58b4142bf58db2180a2bac6897821d069f Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 8 Aug 2011 23:56:54 +0200 Subject: SDL: Take advantage of SdlGraphicsManager. This gets rid of the hacks, where SdlEventSource added events with custom type numbers to pass SDL_VIDEOEXPOSE and SDL_VIDEORESIZE to the graphics manager. Furthermore it get rids of the uninituitive and hard to trace way of assigning the proper mouse coordinates to mouse related events. Formerly it passed the real screen coordinates through the even dispatching api to the graphics manager (at least hopefully ;-) and let that handle creating a new event with the proper coordinates. Now instead SdlEventSource handles the proper coordinate setup itself. Since this is a behavior change and I can not test all the SDL based small devices ports this commit might break compilation for them and more serve it might also break mouse position behavior. If any of that occurs I am sorry about it. --- backends/events/sdl/sdl-events.cpp | 39 ++++++++++++++++++++------------------ backends/events/sdl/sdl-events.h | 13 +++++++++++-- 2 files changed, 32 insertions(+), 20 deletions(-) (limited to 'backends/events/sdl') diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp index d4f40958fe..9d235e9044 100644 --- a/backends/events/sdl/sdl-events.cpp +++ b/backends/events/sdl/sdl-events.cpp @@ -50,7 +50,7 @@ #define JOY_BUT_F5 5 SdlEventSource::SdlEventSource() - : _scrollLock(false), _joystick(0), _lastScreenID(0), EventSource() { + : EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0) { // Reset mouse state memset(&_km, 0, sizeof(_km)); @@ -91,10 +91,15 @@ int SdlEventSource::mapKey(SDLKey key, SDLMod mod, Uint16 unicode) { return key; } -void SdlEventSource::fillMouseEvent(Common::Event &event, int x, int y) { +void SdlEventSource::processMouseEvent(Common::Event &event, int x, int y) { event.mouse.x = x; event.mouse.y = y; + if (_graphicsManager) { + _graphicsManager->notifyMousePos(Common::Point(x, y)); + _graphicsManager->transformMouseCoordinates(event.mouse); + } + // Update the "keyboard mouse" coords _km.x = x; _km.y = y; @@ -377,16 +382,14 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) { return handleJoyAxisMotion(ev, event); case SDL_VIDEOEXPOSE: - // HACK: Send a fake event, handled by SdlGraphicsManager - event.type = (Common::EventType)OSystem_SDL::kSdlEventExpose; - return true; + if (_graphicsManager) + _graphicsManager->notifyVideoExpose(); + return false; case SDL_VIDEORESIZE: - // HACK: Send a fake event, handled by OpenGLSdlGraphicsManager - event.type = (Common::EventType)OSystem_SDL::kSdlEventResize; - event.mouse.x = ev.resize.w; - event.mouse.y = ev.resize.h; - return true; + if (_graphicsManager) + _graphicsManager->notifyResize(ev.resize.w, ev.resize.h); + return false; case SDL_QUIT: event.type = Common::EVENT_QUIT; @@ -504,7 +507,7 @@ bool SdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) { bool SdlEventSource::handleMouseMotion(SDL_Event &ev, Common::Event &event) { event.type = Common::EVENT_MOUSEMOVE; - fillMouseEvent(event, ev.motion.x, ev.motion.y); + processMouseEvent(event, ev.motion.x, ev.motion.y); return true; } @@ -527,7 +530,7 @@ bool SdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) else return false; - fillMouseEvent(event, ev.button.x, ev.button.y); + processMouseEvent(event, ev.button.x, ev.button.y); return true; } @@ -543,7 +546,7 @@ bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { #endif else return false; - fillMouseEvent(event, ev.button.x, ev.button.y); + processMouseEvent(event, ev.button.x, ev.button.y); return true; } @@ -551,10 +554,10 @@ bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) { if (ev.jbutton.button == JOY_BUT_LMOUSE) { event.type = Common::EVENT_LBUTTONDOWN; - fillMouseEvent(event, _km.x, _km.y); + processMouseEvent(event, _km.x, _km.y); } else if (ev.jbutton.button == JOY_BUT_RMOUSE) { event.type = Common::EVENT_RBUTTONDOWN; - fillMouseEvent(event, _km.x, _km.y); + processMouseEvent(event, _km.x, _km.y); } else { event.type = Common::EVENT_KEYDOWN; switch (ev.jbutton.button) { @@ -582,10 +585,10 @@ bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) { bool SdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) { if (ev.jbutton.button == JOY_BUT_LMOUSE) { event.type = Common::EVENT_LBUTTONUP; - fillMouseEvent(event, _km.x, _km.y); + processMouseEvent(event, _km.x, _km.y); } else if (ev.jbutton.button == JOY_BUT_RMOUSE) { event.type = Common::EVENT_RBUTTONUP; - fillMouseEvent(event, _km.x, _km.y); + processMouseEvent(event, _km.x, _km.y); } else { event.type = Common::EVENT_KEYUP; switch (ev.jbutton.button) { @@ -653,7 +656,7 @@ bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) { #endif } - fillMouseEvent(event, _km.x, _km.y); + processMouseEvent(event, _km.x, _km.y); return true; } diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h index 9122692a8e..2ba88c702b 100644 --- a/backends/events/sdl/sdl-events.h +++ b/backends/events/sdl/sdl-events.h @@ -24,6 +24,7 @@ #define BACKEND_EVENTS_SDL_H #include "backends/platform/sdl/sdl-sys.h" +#include "backends/graphics/sdl/sdl-graphics.h" #include "common/events.h" @@ -36,6 +37,8 @@ public: SdlEventSource(); virtual ~SdlEventSource(); + void setGraphicsManager(SdlGraphicsManager *gMan) { _graphicsManager = gMan; } + /** * Gets and processes SDL events. */ @@ -76,6 +79,11 @@ protected: /** Last screen id for checking if it was modified */ int _lastScreenID; + /** + * The associated graphics manager. + */ + SdlGraphicsManager *_graphicsManager; + /** * Pre process an event before it is dispatched. */ @@ -108,9 +116,10 @@ protected: //@} /** - * Assigns the mouse coords to the mouse event + * Assigns the mouse coords to the mouse event. Furthermore notify the + * graphics manager about the position change. */ - virtual void fillMouseEvent(Common::Event &event, int x, int y); + virtual void processMouseEvent(Common::Event &event, int x, int y); /** * Remaps key events. This allows platforms to configure -- cgit v1.2.3