diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp index c5c89642608..81719296279 100644 --- a/backends/events/sdl/sdl-events.cpp +++ b/backends/events/sdl/sdl-events.cpp @@ -52,6 +52,7 @@ SdlEventManager::SdlEventManager(Common::EventSource *boss) : _scrollLock(false), _joystick(0), + _lastScreenID(0), DefaultEventManager(boss) { // reset mouse state @@ -104,12 +105,7 @@ void SdlEventManager::fillMouseEvent(Common::Event &event, int x, int y) { _km.y = y; // Adjust for the screen scaling - /*if (!_overlayVisible) { // FIXME - event.mouse.x /= _videoMode.scaleFactor; - event.mouse.y /= _videoMode.scaleFactor; - if (_videoMode.aspectRatioCorrection) - event.mouse.y = aspect2Real(event.mouse.y); - }*/ + ((OSystem_SDL *)g_system)->getGraphicsManager()->adjustMouseEvent(event); } void SdlEventManager::handleKbdMouse() { @@ -211,12 +207,13 @@ bool SdlEventManager::pollSdlEvent(Common::Event &event) { handleKbdMouse(); - // If the screen mode changed, send an Common::EVENT_SCREEN_CHANGED - /*if (_graphicsManager->_modeChanged) { // TODO: use getScreenChangeID - _graphicsManager->_modeChanged = false; + // If the screen changed, send an Common::EVENT_SCREEN_CHANGED + int screenID = ((OSystem_SDL *)g_system)->getGraphicsManager()->getScreenChangeID(); + if (screenID != _lastScreenID) { + _lastScreenID = screenID; event.type = Common::EVENT_SCREEN_CHANGED; return true; - }*/ + } while (SDL_PollEvent(&ev)) { preprocessEvents(&ev); @@ -271,24 +268,13 @@ bool SdlEventManager::handleKeyDown(SDL_Event &ev, Common::Event &event) { event.kbd.flags |= Common::KBD_SCRL; // Alt-Return and Alt-Enter toggle full screen mode - // TODO: make a function in graphics manager for this - /*if (event.kbd.hasFlags(Common::KBD_ALT) && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_KP_ENTER)) { - beginGFXTransaction(); - setFullscreenMode(!_videoMode.fullscreen); - endGFXTransaction(); -#ifdef USE_OSD - if (_videoMode.fullscreen) - displayMessageOnOSD("Fullscreen mode"); - else - displayMessageOnOSD("Windowed mode"); -#endif - + if (event.kbd.hasFlags(Common::KBD_ALT) && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_KP_ENTER)) { + ((OSystem_SDL *) g_system)->getGraphicsManager()->toggleFullScreen(); return false; - }*/ + } // Alt-S: Create a screenshot - // TODO: make a function in graphics manager for this - /*if (event.kbd.hasFlags(Common::KBD_ALT) && ev.key.keysym.sym == 's') { + if (event.kbd.hasFlags(Common::KBD_ALT) && ev.key.keysym.sym == 's') { char filename[20]; for (int n = 0;; n++) { @@ -300,12 +286,12 @@ bool SdlEventManager::handleKeyDown(SDL_Event &ev, Common::Event &event) { break; SDL_RWclose(file); } - if (saveScreenshot(filename)) + if (((OSystem_SDL *) g_system)->getGraphicsManager()->saveScreenshot(filename)) printf("Saved '%s'\n", filename); else printf("Could not save screenshot!\n"); return false; - }*/ + } // Ctrl-m toggles mouse capture if (event.kbd.hasFlags(Common::KBD_CTRL) && ev.key.keysym.sym == 'm') { @@ -608,4 +594,11 @@ void SdlEventManager::toggleMouseGrab() { SDL_WM_GrabInput(SDL_GRAB_OFF); } +void SdlEventManager::resetKeyboadEmulation(int16 x_max, int16 y_max) { + _km.x_max = x_max; + _km.y_max = y_max; + _km.delay_time = 25; + _km.last_time = 0; +} + #endif diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h index 49b040dc8fa..8dd2840e1d9 100644 --- a/backends/events/sdl/sdl-events.h +++ b/backends/events/sdl/sdl-events.h @@ -41,6 +41,8 @@ public: virtual bool pollSdlEvent(Common::Event &event); + void resetKeyboadEmulation(int16 x_max, int16 y_max); + protected: virtual void preprocessEvents(SDL_Event *event) {} @@ -80,6 +82,8 @@ protected: void handleKbdMouse(); virtual bool remapKey(SDL_Event &ev, Common::Event &event); + + int _lastScreenID; }; #endif diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index 206e04166cf..e5d4c7521b0 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -26,6 +26,7 @@ #if defined(WIN32) || defined(UNIX) || defined(MACOSX) #include "backends/graphics/sdl/sdl-graphics.h" +#include "common/system.h" #include "common/config-manager.h" #include "common/mutex.h" #include "common/util.h" @@ -37,7 +38,7 @@ #include "graphics/scaler.h" #include "graphics/scaler/aspect.h" #include "graphics/surface.h" -#include "backends/events/default/default-events.h" +#include "backends/events/sdl/sdl-events.h" static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { {"1x", "Normal (no scaling)", GFX_NORMAL}, @@ -790,11 +791,9 @@ bool SdlGraphicsManager::loadGFXMode() { SDL_SetColorKey(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kOSDColorKey); #endif - // keyboard cursor control, some other better place for it? - FIXME - /*_km.x_max = _videoMode.screenWidth * _videoMode.scaleFactor - 1; - _km.y_max = effectiveScreenHeight() - 1; - _km.delay_time = 25; - _km.last_time = 0;*/ + ((SdlEventManager *)g_system->getEventManager())->resetKeyboadEmulation( + _videoMode.screenWidth * _videoMode.scaleFactor - 1, + effectiveScreenHeight() - 1); // Distinguish 555 and 565 mode if (_hwscreen->format->Rmask == 0x7C00) @@ -1964,11 +1963,6 @@ void SdlGraphicsManager::displayMessageOnOSD(const char *msg) { } #endif - -#pragma mark - -#pragma mark --- Misc --- -#pragma mark - - bool SdlGraphicsManager::handleScalerHotkeys(const SDL_KeyboardEvent &key) { // Ctrl-Alt-a toggles aspect ratio correction if (key.keysym.sym == 'a') { @@ -2074,4 +2068,25 @@ void SdlGraphicsManager::forceFullRedraw() { _forceFull = true; } +void SdlGraphicsManager::adjustMouseEvent(Common::Event &event) { + if (!_overlayVisible) { + event.mouse.x /= _videoMode.scaleFactor; + event.mouse.y /= _videoMode.scaleFactor; + if (_videoMode.aspectRatioCorrection) + event.mouse.y = aspect2Real(event.mouse.y); + } +} + +void SdlGraphicsManager::toggleFullScreen() { + beginGFXTransaction(); + setFullscreenMode(!_videoMode.fullscreen); + endGFXTransaction(); +#ifdef USE_OSD + if (_videoMode.fullscreen) + displayMessageOnOSD("Fullscreen mode"); + else + displayMessageOnOSD("Windowed mode"); +#endif +} + #endif diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 84bb439783a..04f95ff7213 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -128,10 +128,13 @@ public: void forceFullRedraw(); - bool handleScalerHotkeys(const SDL_KeyboardEvent &key); // Move this? - bool isScalerHotkey(const Common::Event &event); // Move this? + bool handleScalerHotkeys(const SDL_KeyboardEvent &key); + bool isScalerHotkey(const Common::Event &event); + void adjustMouseEvent(Common::Event &event); void setMousePos(int x, int y); + void toggleFullScreen(); + virtual bool saveScreenshot(const char *filename); // overloaded by CE backend protected: #ifdef USE_OSD @@ -203,7 +206,7 @@ protected: virtual void setGraphicsModeIntern(); // overloaded by CE backend - /** Force full redraw on next updateScreen */ + // Force full redraw on next updateScreen bool _forceFull; ScalerProc *_scalerProc; @@ -299,8 +302,6 @@ protected: void setFullscreenMode(bool enable); void setAspectRatioCorrection(bool enable); - virtual bool saveScreenshot(const char *filename); // overloaded by CE backend - int effectiveScreenHeight() const; };