From 3e13a02be92d560a7878d5bc66794b815b4512d5 Mon Sep 17 00:00:00 2001 From: Pawel Kolodziejski Date: Fri, 25 Sep 2020 14:23:30 +0200 Subject: [PATCH] BACKENNDS: Cleanup GFX backend --- backends/events/sdl/sdl-events.h | 4 +- backends/graphics/graphics.h | 14 + backends/graphics/resvm-graphics.h | 7 - .../resvm-openglsdl-graphics.h | 1 - .../graphics/resvm-sdl/resvm-sdl-graphics.cpp | 88 +++- .../graphics/resvm-sdl/resvm-sdl-graphics.h | 213 +++++++- backends/graphics/resvm-sdl/sdl-graphics.cpp | 453 ------------------ backends/graphics/resvm-sdl/sdl-graphics.h | 237 --------- .../resvm-surfacesdl-graphics.cpp | 4 - .../resvm-surfacesdl-graphics.h | 3 +- backends/modular-backend.h | 2 +- backends/module.mk | 1 - backends/platform/sdl/sdl.cpp | 14 +- 13 files changed, 274 insertions(+), 767 deletions(-) delete mode 100644 backends/graphics/resvm-sdl/sdl-graphics.cpp delete mode 100644 backends/graphics/resvm-sdl/sdl-graphics.h diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h index 2e3bd6d1c7f..a15e5d5eaaf 100644 --- a/backends/events/sdl/sdl-events.h +++ b/backends/events/sdl/sdl-events.h @@ -43,7 +43,7 @@ public: SdlEventSource(); virtual ~SdlEventSource(); - void setGraphicsManager(SdlGraphicsManager *gMan) { _graphicsManager = gMan; } + void setGraphicsManager(ResVmSdlGraphicsManager *gMan) { _graphicsManager = gMan; } /** * Gets and processes SDL events. @@ -85,7 +85,7 @@ protected: /** * The associated graphics manager. */ - SdlGraphicsManager *_graphicsManager; + ResVmSdlGraphicsManager *_graphicsManager; /** * Search for a game controller db file and load it. diff --git a/backends/graphics/graphics.h b/backends/graphics/graphics.h index 3842922c428..a5a7c66af60 100644 --- a/backends/graphics/graphics.h +++ b/backends/graphics/graphics.h @@ -111,6 +111,20 @@ public: // Graphics::PaletteManager interface //virtual void setPalette(const byte *colors, uint start, uint num) = 0; //virtual void grabPalette(byte *colors, uint start, uint num) const = 0; + + // ResidualVM specific methods: + virtual void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d) {} + virtual Graphics::PixelBuffer getScreenPixelBuffer() { return Graphics::PixelBuffer(); } + virtual void suggestSideTextures(Graphics::Surface *left, Graphics::Surface *right) {} + virtual void saveScreenshot() {} + virtual bool lockMouse(bool lock) { return false; } + /** + * Checks if mouse is locked or not. + * Avoid to emulate a mouse movement from joystick if locked. + * A (subset) of the graphic manager's state. This is used when switching + * between different SDL graphic managers at runtime. + */ + virtual bool isMouseLocked() const { return false; } }; #endif diff --git a/backends/graphics/resvm-graphics.h b/backends/graphics/resvm-graphics.h index 8814ab1e887..29d88d99bf3 100644 --- a/backends/graphics/resvm-graphics.h +++ b/backends/graphics/resvm-graphics.h @@ -59,13 +59,6 @@ public: virtual void clearFocusRectangle() {} virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) {} virtual void setCursorPalette(const byte *colors, uint start, uint num) {} - - // ResidualVM specific methods - virtual void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d) = 0; - virtual Graphics::PixelBuffer getScreenPixelBuffer() = 0; - virtual void suggestSideTextures(Graphics::Surface *left, Graphics::Surface *right) = 0; - virtual void saveScreenshot() {} - virtual bool lockMouse(bool lock) = 0; }; #endif diff --git a/backends/graphics/resvm-openglsdl/resvm-openglsdl-graphics.h b/backends/graphics/resvm-openglsdl/resvm-openglsdl-graphics.h index 42b5ed27067..872b0703b65 100644 --- a/backends/graphics/resvm-openglsdl/resvm-openglsdl-graphics.h +++ b/backends/graphics/resvm-openglsdl/resvm-openglsdl-graphics.h @@ -136,7 +136,6 @@ protected: Math::Rect2d computeGameRect(bool renderToFrameBuffer, uint gameWidth, uint gameHeight, uint screenWidth, uint screenHeight); - // ResVmSdlGraphicsManager API virtual bool saveScreenshot(const Common::String &filename) const override; virtual int getGraphicsModeScale(int mode) const override { return 1; } diff --git a/backends/graphics/resvm-sdl/resvm-sdl-graphics.cpp b/backends/graphics/resvm-sdl/resvm-sdl-graphics.cpp index 45da0713f60..142f08b3a83 100644 --- a/backends/graphics/resvm-sdl/resvm-sdl-graphics.cpp +++ b/backends/graphics/resvm-sdl/resvm-sdl-graphics.cpp @@ -20,26 +20,25 @@ * */ -#include "backends/graphics/resvm-sdl/sdl-graphics.h" - +#include "backends/graphics/resvm-sdl/resvm-sdl-graphics.h" #include "backends/platform/sdl/sdl-sys.h" #include "backends/events/sdl/resvm-sdl-events.h" #include "backends/platform/sdl/sdl.h" - +#include "backends/keymapper/action.h" +#include "backends/keymapper/keymap.h" #include "common/config-manager.h" +#include "common/fs.h" #include "common/textconsole.h" +#include "common/translation.h" #include "common/file.h" ResVmSdlGraphicsManager::ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window) : - SdlGraphicsManager(source, window) { + _eventSource(source), _window(window) { ConfMan.registerDefault("fullscreen_res", "desktop"); } -ResVmSdlGraphicsManager::~ResVmSdlGraphicsManager() { -} - void ResVmSdlGraphicsManager::activateManager() { - SdlGraphicsManager::activateManager(); + _eventSource->setGraphicsManager(this); // Register the graphics manager as a event observer g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false); @@ -51,7 +50,61 @@ void ResVmSdlGraphicsManager::deactivateManager() { g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this); } - SdlGraphicsManager::deactivateManager(); + _eventSource->setGraphicsManager(0); +} + +ResVmSdlGraphicsManager::State ResVmSdlGraphicsManager::getState() const { + State state; + + state.screenWidth = getWidth(); + state.screenHeight = getHeight(); + state.aspectRatio = getFeatureState(OSystem::kFeatureAspectRatioCorrection); + state.fullscreen = getFeatureState(OSystem::kFeatureFullscreenMode); + state.cursorPalette = getFeatureState(OSystem::kFeatureCursorPalette); +#ifdef USE_RGB_COLOR + state.pixelFormat = getScreenFormat(); +#endif + return state; +} + +bool ResVmSdlGraphicsManager::setState(const State &state) { + beginGFXTransaction(); +#ifdef USE_RGB_COLOR + initSize(state.screenWidth, state.screenHeight, &state.pixelFormat); +#else + initSize(state.screenWidth, state.screenHeight, nullptr); +#endif + setFeatureState(OSystem::kFeatureAspectRatioCorrection, state.aspectRatio); + setFeatureState(OSystem::kFeatureFullscreenMode, state.fullscreen); + setFeatureState(OSystem::kFeatureCursorPalette, state.cursorPalette); + + if (endGFXTransaction() != OSystem::kTransactionSuccess) { + return false; + } else { + return true; + } +} + +Common::Keymap *ResVmSdlGraphicsManager::getKeymap() { + using namespace Common; + + Keymap *keymap = new Keymap(Keymap::kKeymapTypeGlobal, "sdl-graphics", _("Graphics")); + Action *act; + + if (g_system->hasFeature(OSystem::kFeatureFullscreenMode)) { + act = new Action("FULS", _("Toggle fullscreen")); + act->addDefaultInputMapping("A+RETURN"); + act->addDefaultInputMapping("A+KP_ENTER"); + act->setCustomBackendActionEvent(kActionToggleFullscreen); + keymap->addAction(act); + } + + act = new Action("SCRS", _("Save screenshot")); + act->addDefaultInputMapping("A+s"); + act->setCustomBackendActionEvent(kActionSaveScreenshot); + keymap->addAction(act); + + return keymap; } Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() { @@ -103,23 +156,6 @@ bool ResVmSdlGraphicsManager::isMouseLocked() const { #endif } -bool ResVmSdlGraphicsManager::notifyEvent(const Common::Event &event) { - switch ((int)event.type) { - case Common::EVENT_KEYDOWN: - if (event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == Common::KEYCODE_s) { - saveScreenshot(); - return true; - } - break; - case Common::EVENT_KEYUP: - break; - default: - break; - } - - return false; -} - bool ResVmSdlGraphicsManager::notifyMousePosition(Common::Point &mouse) { transformMouseCoordinates(mouse); diff --git a/backends/graphics/resvm-sdl/resvm-sdl-graphics.h b/backends/graphics/resvm-sdl/resvm-sdl-graphics.h index 2cd63424fc5..49284005f6c 100644 --- a/backends/graphics/resvm-sdl/resvm-sdl-graphics.h +++ b/backends/graphics/resvm-sdl/resvm-sdl-graphics.h @@ -20,10 +20,11 @@ * */ -#ifndef BACKENDS_GRAPHICS_SDL_RESVM_SDLGRAPHICS_H -#define BACKENDS_GRAPHICS_SDL_RESVM_SDLGRAPHICS_H +#ifndef BACKENDS_GRAPHICS_RESVM_SDL_SDLGRAPHICS_H +#define BACKENDS_GRAPHICS_RESVM_SDL_SDLGRAPHICS_H -#include "backends/graphics/resvm-sdl/sdl-graphics.h" +#include "backends/graphics/resvm-graphics.h" +#include "backends/platform/sdl/sdl-window.h" #include "common/events.h" #include "common/rect.h" @@ -33,47 +34,207 @@ class SdlEventSource; /** - * Base class for a ResidualVM SDL based graphics manager. - * - * Used to share reusable methods between SDL graphics managers + * Base class for a SDL based graphics manager. */ -class ResVmSdlGraphicsManager : public SdlGraphicsManager { +class ResVmSdlGraphicsManager : virtual public ResVmGraphicsManager, public Common::EventObserver { public: ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window); - ~ResVmSdlGraphicsManager() override; + virtual ~ResVmSdlGraphicsManager() {} - // SdlGraphicsManager API - void activateManager() override; - void deactivateManager() override; - void notifyVideoExpose() override {} - bool notifyMousePosition(Common::Point &mouse) override; + /** + * Makes this graphics manager active. That means it should be ready to + * process inputs now. However, even without being active it should be + * able to query the supported modes and other bits. + */ + virtual void activateManager(); -public: - // GraphicsManager API - Draw methods - void saveScreenshot() override; + /** + * Makes this graphics manager inactive. This should allow another + * graphics manager to become active again. + */ + virtual void deactivateManager(); - // GraphicsManager API - Mouse - bool showMouse(bool visible) override; - bool lockMouse(bool lock) override; // ResidualVM specific method + /** + * Notify the graphics manager that the graphics needs to be redrawn, since + * the application window was modified. + * + * This is basically called when SDL_VIDEOEXPOSE was received. + */ + virtual void notifyVideoExpose() {}; - // Common::EventObserver API - bool notifyEvent(const Common::Event &event) override; + /** + * Notify the graphics manager about a resize event. + * + * It is noteworthy that the requested width/height should actually be set + * up as is and not changed by the graphics manager, since otherwise it may + * lead to odd behavior for certain window managers. + * + * It is only required to overwrite this method in case you want a + * resizable window. The default implementation just does nothing. + * + * @param width Requested window width. + * @param height Requested window height. + */ + virtual void notifyResize(const int width, const int height) {}; + + /** + * Transforms real screen coordinates into the current active screen + * coordinates (may be either game screen or overlay). + * + * @param point Mouse coordinates to transform. + * !! ResidualVM specific: + */ + virtual void transformMouseCoordinates(Common::Point &point) = 0; + + /** + * Notifies the graphics manager about a mouse position change. + * + * The passed point *must* be converted from window coordinates to virtual + * coordinates in order for the event to be processed correctly by the game + * engine. Just use `convertWindowToVirtual` for this unless you need to do + * something special. + * + * @param mouse The mouse position in window coordinates, which must be + * converted synchronously to virtual coordinates. + * @returns true if the mouse was in a valid position for the game and + * should cause the event to be sent to the game. + */ + virtual bool notifyMousePosition(Common::Point &mouse); + + virtual bool showMouse(bool visible) override; + virtual bool lockMouse(bool lock) override; // ResidualVM specific method /** * Checks if mouse is locked or not. * Avoid to emulate a mouse movement from joystick if locked. */ - bool isMouseLocked() const; + virtual bool isMouseLocked() const; -protected: + virtual bool saveScreenshot(const Common::String &filename) const { return false; } + void saveScreenshot(); + + // Override from Common::EventObserver + virtual bool notifyEvent(const Common::Event &event) { return false; }; /** Obtain the user configured fullscreen resolution, or default to the desktop resolution */ - Common::Rect getPreferredFullscreenResolution(); + virtual Common::Rect getPreferredFullscreenResolution(); + + /** + * A (subset) of the graphic manager's state. This is used when switching + * between different SDL graphic managers at runtime. + */ + struct State { + int screenWidth, screenHeight; + bool aspectRatio; + bool fullscreen; + bool cursorPalette; + +#ifdef USE_RGB_COLOR + Graphics::PixelFormat pixelFormat; +#endif + }; + + /** + * Gets the current state of the graphics manager. + */ + State getState() const; + + /** + * Sets up a basic state of the graphics manager. + */ + bool setState(const State &state); + + /** + * @returns the SDL window. + */ + SdlWindow *getWindow() const { return _window; } + +#if 0 // ResidualVM - not used + virtual void initSizeHint(const Graphics::ModeList &modes) override; +#endif + Common::Keymap *getKeymap(); + +protected: + enum CustomEventAction { + kActionToggleFullscreen = 100, + kActionToggleMouseCapture, + kActionSaveScreenshot, + kActionToggleAspectRatioCorrection +#if 0 // ResidualVM - not used + kActionToggleFilteredScaling, + kActionCycleStretchMode, + kActionIncreaseScaleFactor, + kActionDecreaseScaleFactor, + kActionSetScaleFilter1, + kActionSetScaleFilter2, + kActionSetScaleFilter3, + kActionSetScaleFilter4, + kActionSetScaleFilter5, + kActionSetScaleFilter6, + kActionSetScaleFilter7, + kActionSetScaleFilter8 +#endif + }; virtual int getGraphicsModeScale(int mode) const = 0; +#if 0 // ResidualVM - not used - /** Save a screenshot to the specified file */ - virtual bool saveScreenshot(const Common::String &file) const = 0; + bool defaultGraphicsModeConfig() const; + int getGraphicsModeIdByName(const Common::String &name) const; + + /** + * Gets the dimensions of the window directly from SDL instead of from the + * values stored by the graphics manager. + */ + void getWindowSizeFromSdl(int *width, int *height) const { +#if SDL_VERSION_ATLEAST(2, 0, 0) + assert(_window); + SDL_GetWindowSize(_window->getSDLWindow(), width, height); +#else + assert(_hwScreen); + + if (width) { + *width = _hwScreen->w; + } + + if (height) { + *height = _hwScreen->h; + } +#endif + } + + virtual void setSystemMousePosition(const int x, const int y) override; + + virtual void handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) override; +#endif + +#if SDL_VERSION_ATLEAST(2, 0, 0) +public: + void unlockWindowSize() { +#if 0 // ResidualVM - not used + _allowWindowSizeReset = true; + _hintedWidth = 0; + _hintedHeight = 0; +#endif + } + +protected: +#if 0 // ResidualVM - not used + Uint32 _lastFlags; + bool _allowWindowSizeReset; + int _hintedWidth, _hintedHeight; + + bool createOrUpdateWindow(const int width, const int height, const Uint32 flags); +#endif +#endif + + SDL_Surface *_hwScreen; // ResidualVM - not used + SdlEventSource *_eventSource; + SdlWindow *_window; +#if 0 // ResidualVM - not used +private: + void toggleFullScreen(); +#endif }; #endif diff --git a/backends/graphics/resvm-sdl/sdl-graphics.cpp b/backends/graphics/resvm-sdl/sdl-graphics.cpp deleted file mode 100644 index e6cac125b5e..00000000000 --- a/backends/graphics/resvm-sdl/sdl-graphics.cpp +++ /dev/null @@ -1,453 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "backends/graphics/resvm-sdl/sdl-graphics.h" -#include "backends/platform/sdl/sdl-sys.h" -#include "backends/platform/sdl/sdl.h" -#include "backends/events/sdl/resvm-sdl-events.h" -#include "backends/keymapper/action.h" -#include "backends/keymapper/keymap.h" -#include "common/config-manager.h" -#include "common/fs.h" -#include "common/textconsole.h" -#include "common/translation.h" -//#include "graphics/scaler/aspect.h" // ResidualVM -#if 0 // ResidualVM -#ifdef USE_OSD -#include "common/translation.h" -#endif -#endif // ResidualVM - -SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window) - : _eventSource(source), _window(window)// ResidualVM not used: , _hwScreen(nullptr) { -#if 0 // ResidualVM -#if SDL_VERSION_ATLEAST(2, 0, 0) - , _allowWindowSizeReset(false), _hintedWidth(0), _hintedHeight(0), _lastFlags(0) -#endif -#endif // ResidualVM -{ - // ResidualVM - not used: - //SDL_GetMouseState(&_cursorX, &_cursorY); -} - -void SdlGraphicsManager::activateManager() { - _eventSource->setGraphicsManager(this); - - // Register the graphics manager as a event observer - g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false); -} - -void SdlGraphicsManager::deactivateManager() { - // Unregister the event observer - if (g_system->getEventManager()->getEventDispatcher()) { - g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this); - } - - _eventSource->setGraphicsManager(0); -} - -SdlGraphicsManager::State SdlGraphicsManager::getState() const { - State state; - - state.screenWidth = getWidth(); - state.screenHeight = getHeight(); - state.aspectRatio = getFeatureState(OSystem::kFeatureAspectRatioCorrection); - state.fullscreen = getFeatureState(OSystem::kFeatureFullscreenMode); - state.cursorPalette = getFeatureState(OSystem::kFeatureCursorPalette); -#ifdef USE_RGB_COLOR - state.pixelFormat = getScreenFormat(); -#endif - return state; -} - -bool SdlGraphicsManager::setState(const State &state) { - beginGFXTransaction(); -#ifdef USE_RGB_COLOR - initSize(state.screenWidth, state.screenHeight, &state.pixelFormat); -#else - initSize(state.screenWidth, state.screenHeight, nullptr); -#endif - setFeatureState(OSystem::kFeatureAspectRatioCorrection, state.aspectRatio); - setFeatureState(OSystem::kFeatureFullscreenMode, state.fullscreen); - setFeatureState(OSystem::kFeatureCursorPalette, state.cursorPalette); - - if (endGFXTransaction() != OSystem::kTransactionSuccess) { - return false; - } else { - return true; - } -} - -#if 0 // ResidualVM -bool SdlGraphicsManager::defaultGraphicsModeConfig() const { - const Common::ConfigManager::Domain *transientDomain = ConfMan.getDomain(Common::ConfigManager::kTransientDomain); - if (transientDomain && transientDomain->contains("gfx_mode")) { - const Common::String &mode = transientDomain->getVal("gfx_mode"); - if (!mode.equalsIgnoreCase("normal") && !mode.equalsIgnoreCase("default")) { - return false; - } - } - - const Common::ConfigManager::Domain *gameDomain = ConfMan.getActiveDomain(); - if (gameDomain && gameDomain->contains("gfx_mode")) { - const Common::String &mode = gameDomain->getVal("gfx_mode"); - if (!mode.equalsIgnoreCase("normal") && !mode.equalsIgnoreCase("default")) { - return false; - } - } - - return true; -} - -int SdlGraphicsManager::getGraphicsModeIdByName(const Common::String &name) const { - if (name == "normal" || name == "default") { - return getDefaultGraphicsMode(); - } - - const OSystem::GraphicsMode *mode = getSupportedGraphicsModes(); - while (mode && mode->name != nullptr) { - if (name.equalsIgnoreCase(mode->name)) { - return mode->id; - } - ++mode; - } - return -1; -} - -void SdlGraphicsManager::initSizeHint(const Graphics::ModeList &modes) { -#if SDL_VERSION_ATLEAST(2, 0, 0) - const bool useDefault = defaultGraphicsModeConfig(); - - int scale = getGraphicsModeScale(getGraphicsModeIdByName(ConfMan.get("gfx_mode"))); - if (scale == -1) { - warning("Unknown scaler; defaulting to 1"); - scale = 1; - } - - int16 bestWidth = 0, bestHeight = 0; - const Graphics::ModeList::const_iterator end = modes.end(); - for (Graphics::ModeList::const_iterator it = modes.begin(); it != end; ++it) { - int16 width = it->width, height = it->height; - - // TODO: Normalize AR correction by passing a PAR in the mode list - // instead of checking the dimensions here like this, since not all - // 320x200/640x400 uses are with non-square pixels (e.g. DreamWeb). - if (ConfMan.getBool("aspect_ratio")) { - if ((width == 320 && height == 200) || (width == 640 && height == 400)) { - height = real2Aspect(height); - } - } - - if (!useDefault || width <= 320) { - width *= scale; - height *= scale; - } - - if (bestWidth < width) { - bestWidth = width; - } - - if (bestHeight < height) { - bestHeight = height; - } - } - - _hintedWidth = bestWidth; - _hintedHeight = bestHeight; -#endif -} - -bool SdlGraphicsManager::showMouse(bool visible) { - if (visible == _cursorVisible) { - return visible; - } - - int showCursor = SDL_DISABLE; - if (visible) { - // _cursorX and _cursorY are currently always clipped to the active - // area, so we need to ask SDL where the system's mouse cursor is - // instead - int x, y; - SDL_GetMouseState(&x, &y); - if (!_activeArea.drawRect.contains(Common::Point(x, y))) { - showCursor = SDL_ENABLE; - } - } - SDL_ShowCursor(showCursor); - - return WindowedGraphicsManager::showMouse(visible); -} - -bool SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) { - int showCursor = SDL_DISABLE; - bool valid = true; - if (_activeArea.drawRect.contains(mouse)) { - _cursorLastInActiveArea = true; - } else { - mouse.x = CLIP(mouse.x, _activeArea.drawRect.left, _activeArea.drawRect.right - 1); - mouse.y = CLIP(mouse.y, _activeArea.drawRect.top, _activeArea.drawRect.bottom - 1); - - if (_window->mouseIsGrabbed() || - // Keep the mouse inside the game area during dragging to prevent an - // event mismatch where the mouseup event gets lost because it is - // performed outside of the game area - (_cursorLastInActiveArea && SDL_GetMouseState(nullptr, nullptr) != 0)) { - setSystemMousePosition(mouse.x, mouse.y); - } else { - // Allow the in-game mouse to get a final movement event to the edge - // of the window if the mouse was moved out of the game area - if (_cursorLastInActiveArea) { - _cursorLastInActiveArea = false; - } else if (_cursorVisible) { - // Keep sending events to the game if the cursor is invisible, - // since otherwise if a game lets you skip a cutscene by - // clicking and the user moved the mouse outside the active - // area, the clicks wouldn't do anything, which would be - // confusing - valid = false; - } - - if (_cursorVisible) { - showCursor = SDL_ENABLE; - } - } - } - - SDL_ShowCursor(showCursor); - if (valid) { - setMousePosition(mouse.x, mouse.y); - mouse = convertWindowToVirtual(mouse.x, mouse.y); - } - return valid; -} - -void SdlGraphicsManager::setSystemMousePosition(const int x, const int y) { - assert(_window); - if (!_window->warpMouseInWindow(x, y)) { - const Common::Point mouse = convertWindowToVirtual(x, y); - _eventSource->fakeWarpMouse(mouse.x, mouse.y); - } -} - -void SdlGraphicsManager::handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) { - _forceRedraw = true; -} - -#if SDL_VERSION_ATLEAST(2, 0, 0) -bool SdlGraphicsManager::createOrUpdateWindow(int width, int height, const Uint32 flags) { - if (!_window) { - return false; - } - - // We only update the actual window when flags change (which usually means - // fullscreen mode is entered/exited), when updates are forced so that we - // do not reset the window size whenever a game makes a call to change the - // size or pixel format of the internal game surface (since a user may have - // resized the game window), or when the launcher is visible (since a user - // may change the scaler, which should reset the window size) - if (!_window->getSDLWindow() || _lastFlags != flags || _overlayVisible || _allowWindowSizeReset) { - const bool fullscreen = (flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP)) != 0; - if (!fullscreen) { - if (_hintedWidth) { - width = _hintedWidth; - } - if (_hintedHeight) { - height = _hintedHeight; - } - } - - if (!_window->createOrUpdateWindow(width, height, flags)) { - return false; - } - - _lastFlags = flags; - _allowWindowSizeReset = false; - } - - return true; -} -#endif - -void SdlGraphicsManager::saveScreenshot() { - Common::String filename; - - Common::String screenshotsPath; - OSystem_SDL *sdl_g_system = dynamic_cast(g_system); - if (sdl_g_system) - screenshotsPath = sdl_g_system->getScreenshotsPath(); - - // Use the name of the running target as a base for screenshot file names - Common::String currentTarget = ConfMan.getActiveDomainName(); - -#ifdef USE_PNG - const char *extension = "png"; -#else - const char *extension = "bmp"; -#endif - - for (int n = 0;; n++) { - filename = Common::String::format("residualvm%s%s-%05d.%s", currentTarget.empty() ? "" : "-", - currentTarget.c_str(), n, extension); - - Common::FSNode file = Common::FSNode(screenshotsPath + filename); - if (!file.exists()) { - break; - } - } - - if (saveScreenshot(screenshotsPath + filename)) { - if (screenshotsPath.empty()) - debug("Saved screenshot '%s' in current directory", filename.c_str()); - else - debug("Saved screenshot '%s' in directory '%s'", filename.c_str(), screenshotsPath.c_str()); - } else { - if (screenshotsPath.empty()) - warning("Could not save screenshot in current directory"); - else - warning("Could not save screenshot in directory '%s'", screenshotsPath.c_str()); - } -} - -bool SdlGraphicsManager::notifyEvent(const Common::Event &event) { - if (event.type != Common::EVENT_CUSTOM_BACKEND_ACTION_START) { - return false; - } - - switch ((CustomEventAction) event.customType) { - case kActionToggleMouseCapture: - getWindow()->toggleMouseGrab(); - return true; - - case kActionToggleFullscreen: - toggleFullScreen(); - return true; - - case kActionSaveScreenshot: - saveScreenshot(); - return true; - - default: - return false; - } -} - -void SdlGraphicsManager::toggleFullScreen() { - if (!g_system->hasFeature(OSystem::kFeatureFullscreenMode)) - return; - - beginGFXTransaction(); - setFeatureState(OSystem::kFeatureFullscreenMode, !getFeatureState(OSystem::kFeatureFullscreenMode)); - endGFXTransaction(); -#ifdef USE_OSD - if (getFeatureState(OSystem::kFeatureFullscreenMode)) - displayMessageOnOSD(_("Fullscreen mode")); - else - displayMessageOnOSD(_("Windowed mode")); -#endif -} -#endif // ResidualVM -Common::Keymap *SdlGraphicsManager::getKeymap() { - using namespace Common; - - Keymap *keymap = new Keymap(Keymap::kKeymapTypeGlobal, "sdl-graphics", _("Graphics")); - Action *act; - - if (g_system->hasFeature(OSystem::kFeatureFullscreenMode)) { - act = new Action("FULS", _("Toggle fullscreen")); - act->addDefaultInputMapping("A+RETURN"); - act->addDefaultInputMapping("A+KP_ENTER"); - act->setCustomBackendActionEvent(kActionToggleFullscreen); - keymap->addAction(act); - } - - act = new Action("CAPT", _("Toggle mouse capture")); - act->addDefaultInputMapping("C+m"); - act->setCustomBackendActionEvent(kActionToggleMouseCapture); - keymap->addAction(act); - - act = new Action("SCRS", _("Save screenshot")); - act->addDefaultInputMapping("A+s"); - act->setCustomBackendActionEvent(kActionSaveScreenshot); - keymap->addAction(act); - - if (hasFeature(OSystem::kFeatureAspectRatioCorrection)) { - act = new Action("ASPT", _("Toggle aspect ratio correction")); - act->addDefaultInputMapping("C+A+a"); - act->setCustomBackendActionEvent(kActionToggleAspectRatioCorrection); - keymap->addAction(act); - } -#if 0 // ResidualVM: not used - if (hasFeature(OSystem::kFeatureFilteringMode)) { - act = new Action("FILT", _("Toggle linear filtered scaling")); - act->addDefaultInputMapping("C+A+f"); - act->setCustomBackendActionEvent(kActionToggleFilteredScaling); - keymap->addAction(act); - } - - if (hasFeature(OSystem::kFeatureStretchMode)) { - act = new Action("STCH", _("Cycle through stretch modes")); - act->addDefaultInputMapping("C+A+s"); - act->setCustomBackendActionEvent(kActionCycleStretchMode); - keymap->addAction(act); - } - - act = new Action("SCL+", _("Increase the scale factor")); - act->addDefaultInputMapping("C+A+PLUS"); - act->addDefaultInputMapping("C+A+KP_PLUS"); - act->setCustomBackendActionEvent(kActionIncreaseScaleFactor); - keymap->addAction(act); - - act = new Action("SCL-", _("Decrease the scale factor")); - act->addDefaultInputMapping("C+A+MINUS"); - act->addDefaultInputMapping("C+A+KP_MINUS"); - act->setCustomBackendActionEvent(kActionDecreaseScaleFactor); - keymap->addAction(act); - -#ifdef USE_SCALERS - struct ActionEntry { - const char *id; - const char *description; - }; - static const ActionEntry filters[] = { - { "FLT1", _s("Switch to nearest neighbour scaling") }, - { "FLT2", _s("Switch to AdvMame 2x/3x scaling") }, -#ifdef USE_HQ_SCALERS - { "FLT3", _s("Switch to HQ 2x/3x scaling") }, -#endif - { "FLT4", _s("Switch to 2xSai scaling") }, - { "FLT5", _s("Switch to Super2xSai scaling") }, - { "FLT6", _s("Switch to SuperEagle scaling") }, - { "FLT7", _s("Switch to TV 2x scaling") }, - { "FLT8", _s("Switch to DotMatrix scaling") } - }; - - for (uint i = 0; i < ARRAYSIZE(filters); i++) { - act = new Action(filters[i].id, _(filters[i].description)); - act->addDefaultInputMapping(String::format("C+A+%d", i + 1)); - act->addDefaultInputMapping(String::format("C+A+KP%d", i + 1)); - act->setCustomBackendActionEvent(kActionSetScaleFilter1 + i); - keymap->addAction(act); - } -#endif -#endif // ResidualVM - return keymap; -} diff --git a/backends/graphics/resvm-sdl/sdl-graphics.h b/backends/graphics/resvm-sdl/sdl-graphics.h deleted file mode 100644 index 82b23c2c18c..00000000000 --- a/backends/graphics/resvm-sdl/sdl-graphics.h +++ /dev/null @@ -1,237 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H -#define BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H - -#include "backends/graphics/resvm-graphics.h" -#include "backends/platform/sdl/sdl-window.h" - -#include "common/events.h" -#include "common/rect.h" - -class SdlEventSource; - -#if 0 // ResidualVM - not used -#ifndef __SYMBIAN32__ -#define USE_OSD 1 -#endif -#endif -/** - * Base class for a SDL based graphics manager. - */ -class SdlGraphicsManager : virtual public ResVmGraphicsManager, public Common::EventObserver { -public: - SdlGraphicsManager(SdlEventSource *source, SdlWindow *window); - virtual ~SdlGraphicsManager() {} - - /** - * Makes this graphics manager active. That means it should be ready to - * process inputs now. However, even without being active it should be - * able to query the supported modes and other bits. - */ - virtual void activateManager(); - - /** - * Makes this graphics manager inactive. This should allow another - * graphics manager to become active again. - */ - virtual void deactivateManager(); - - /** - * Notify the graphics manager that the graphics needs to be redrawn, since - * the application window was modified. - * - * This is basically called when SDL_VIDEOEXPOSE was received. - */ - virtual void notifyVideoExpose() = 0; - - /** - * Notify the graphics manager about a resize event. - * - * It is noteworthy that the requested width/height should actually be set - * up as is and not changed by the graphics manager, since otherwise it may - * lead to odd behavior for certain window managers. - * - * It is only required to overwrite this method in case you want a - * resizable window. The default implementation just does nothing. - * - * @param width Requested window width. - * @param height Requested window height. - */ - virtual void notifyResize(const int width, const int height) {} - - /** - * Transforms real screen coordinates into the current active screen - * coordinates (may be either game screen or overlay). - * - * @param point Mouse coordinates to transform. - * !! ResidualVM specific: - */ - virtual void transformMouseCoordinates(Common::Point &point) = 0; - - /** - * Notifies the graphics manager about a mouse position change. - * - * The passed point *must* be converted from window coordinates to virtual - * coordinates in order for the event to be processed correctly by the game - * engine. Just use `convertWindowToVirtual` for this unless you need to do - * something special. - * - * @param mouse The mouse position in window coordinates, which must be - * converted synchronously to virtual coordinates. - * @returns true if the mouse was in a valid position for the game and - * should cause the event to be sent to the game. - */ - virtual bool notifyMousePosition(Common::Point &mouse) = 0; // ResidualVM specific - -#if 0 // ResidualVM - not used - virtual bool showMouse(bool visible) override; -#endif - - virtual bool saveScreenshot(const Common::String &filename) const { return false; } - virtual void saveScreenshot() {} // ResidualVM specific - -#if 0 // ResidualVM - not used - // Override from Common::EventObserver - virtual bool notifyEvent(const Common::Event &event) override; -#endif - - /** - * A (subset) of the graphic manager's state. This is used when switching - * between different SDL graphic managers at runtime. - */ - struct State { - int screenWidth, screenHeight; - bool aspectRatio; - bool fullscreen; - bool cursorPalette; - -#ifdef USE_RGB_COLOR - Graphics::PixelFormat pixelFormat; -#endif - }; - - /** - * Gets the current state of the graphics manager. - */ - State getState() const; - - /** - * Sets up a basic state of the graphics manager. - */ - bool setState(const State &state); - - /** - * @returns the SDL window. - */ - SdlWindow *getWindow() const { return _window; } - -#if 0 // ResidualVM - not used - virtual void initSizeHint(const Graphics::ModeList &modes) override; -#endif - Common::Keymap *getKeymap(); - -protected: - enum CustomEventAction { - kActionToggleFullscreen = 100, - kActionToggleMouseCapture, - kActionSaveScreenshot, - kActionToggleAspectRatioCorrection -#if 0 // ResidualVM - not used - kActionToggleFilteredScaling, - kActionCycleStretchMode, - kActionIncreaseScaleFactor, - kActionDecreaseScaleFactor, - kActionSetScaleFilter1, - kActionSetScaleFilter2, - kActionSetScaleFilter3, - kActionSetScaleFilter4, - kActionSetScaleFilter5, - kActionSetScaleFilter6, - kActionSetScaleFilter7, - kActionSetScaleFilter8 -#endif - }; - -#if 0 // ResidualVM - not used - virtual int getGraphicsModeScale(int mode) const = 0; - - bool defaultGraphicsModeConfig() const; - int getGraphicsModeIdByName(const Common::String &name) const; - - /** - * Gets the dimensions of the window directly from SDL instead of from the - * values stored by the graphics manager. - */ - void getWindowSizeFromSdl(int *width, int *height) const { -#if SDL_VERSION_ATLEAST(2, 0, 0) - assert(_window); - SDL_GetWindowSize(_window->getSDLWindow(), width, height); -#else - assert(_hwScreen); - - if (width) { - *width = _hwScreen->w; - } - - if (height) { - *height = _hwScreen->h; - } -#endif - } - - virtual void setSystemMousePosition(const int x, const int y) override; - - virtual void handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) override; -#endif - -#if SDL_VERSION_ATLEAST(2, 0, 0) -public: - void unlockWindowSize() { -#if 0 // ResidualVM - not used - _allowWindowSizeReset = true; - _hintedWidth = 0; - _hintedHeight = 0; -#endif - } - -protected: -#if 0 // ResidualVM - not used - Uint32 _lastFlags; - bool _allowWindowSizeReset; - int _hintedWidth, _hintedHeight; - - bool createOrUpdateWindow(const int width, const int height, const Uint32 flags); -#endif -#endif - - SDL_Surface *_hwScreen; // ResidualVM - not used - SdlEventSource *_eventSource; - SdlWindow *_window; -#if 0 // ResidualVM - not used -private: - void toggleFullScreen(); -#endif -}; - -#endif diff --git a/backends/graphics/resvm-surfacesdl/resvm-surfacesdl-graphics.cpp b/backends/graphics/resvm-surfacesdl/resvm-surfacesdl-graphics.cpp index 5c0f98552b9..6ee78b3d3d2 100644 --- a/backends/graphics/resvm-surfacesdl/resvm-surfacesdl-graphics.cpp +++ b/backends/graphics/resvm-surfacesdl/resvm-surfacesdl-graphics.cpp @@ -555,8 +555,4 @@ bool ResVmSurfaceSdlGraphicsManager::saveScreenshot(const Common::String &filena return success; } -int ResVmSurfaceSdlGraphicsManager::getGraphicsModeScale(int mode) const { - return 1; -} - #endif diff --git a/backends/graphics/resvm-surfacesdl/resvm-surfacesdl-graphics.h b/backends/graphics/resvm-surfacesdl/resvm-surfacesdl-graphics.h index 9a73e873c8e..15b1ba1686d 100644 --- a/backends/graphics/resvm-surfacesdl/resvm-surfacesdl-graphics.h +++ b/backends/graphics/resvm-surfacesdl/resvm-surfacesdl-graphics.h @@ -110,10 +110,9 @@ protected: void drawSideTextures(); void closeOverlay(); - // ResVmSdlGraphicsManager API virtual bool saveScreenshot(const Common::String &filename) const override; - virtual int getGraphicsModeScale(int mode) const override; + virtual int getGraphicsModeScale(int mode) const override { return 1; } }; #endif diff --git a/backends/modular-backend.h b/backends/modular-backend.h index aefa8285404..9199f2b67c5 100644 --- a/backends/modular-backend.h +++ b/backends/modular-backend.h @@ -134,7 +134,7 @@ protected: /** @name Managers variables */ //@{ - ResVmGraphicsManager *_graphicsManager; // ResidualVM: was GraphicsManager + GraphicsManager *_graphicsManager; //@} }; diff --git a/backends/module.mk b/backends/module.mk index aa354ac8d75..5fb0865d680 100644 --- a/backends/module.mk +++ b/backends/module.mk @@ -119,7 +119,6 @@ ifdef SDL_BACKEND MODULE_OBJS += \ events/sdl/sdl-events.o \ events/sdl/resvm-sdl-events.o \ - graphics/resvm-sdl/sdl-graphics.o \ graphics/resvm-sdl/resvm-sdl-graphics.o \ graphics/resvm-surfacesdl/resvm-surfacesdl-graphics.o \ mixer/sdl/sdl-mixer.o \ diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 2a9c6c6cfef..121811b1962 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -109,7 +109,7 @@ OSystem_SDL::~OSystem_SDL() { delete _savefileManager; _savefileManager = 0; if (_graphicsManager) { - dynamic_cast(_graphicsManager)->deactivateManager(); + dynamic_cast(_graphicsManager)->deactivateManager(); } delete _graphicsManager; _graphicsManager = 0; @@ -263,7 +263,7 @@ void OSystem_SDL::initBackend() { #endif if (_graphicsManager == 0) { - _graphicsManager = new ResVmSurfaceSdlGraphicsManager(_eventSource, _window); // ResidualVM specific + _graphicsManager = dynamic_cast(new ResVmSurfaceSdlGraphicsManager(_eventSource, _window)); // ResidualVM specific } } @@ -302,7 +302,7 @@ void OSystem_SDL::initBackend() { // so the virtual keyboard can be initialized, but we have to add the // graphics manager as an event observer after initializing the event // manager. - dynamic_cast(_graphicsManager)->activateManager(); + dynamic_cast(_graphicsManager)->activateManager(); } // ResidualVM specific code - Start @@ -387,7 +387,7 @@ void OSystem_SDL::detectAntiAliasingSupport() { void OSystem_SDL::engineInit() { #if SDL_VERSION_ATLEAST(2, 0, 0) - dynamic_cast(_graphicsManager)->unlockWindowSize(); + dynamic_cast(_graphicsManager)->unlockWindowSize(); // Disable screen saver when engine starts SDL_DisableScreenSaver(); #endif @@ -409,7 +409,7 @@ void OSystem_SDL::engineInit() { void OSystem_SDL::engineDone() { #if SDL_VERSION_ATLEAST(2, 0, 0) - dynamic_cast(_graphicsManager)->unlockWindowSize(); + dynamic_cast(_graphicsManager)->unlockWindowSize(); SDL_EnableScreenSaver(); #endif #ifdef USE_TASKBAR @@ -496,7 +496,7 @@ void OSystem_SDL::setupScreen(uint screenW, uint screenH, bool fullscreen, bool } if (switchedManager) { - SdlGraphicsManager *sdlGraphicsManager = dynamic_cast(_graphicsManager); + ResVmSdlGraphicsManager *sdlGraphicsManager = dynamic_cast(_graphicsManager); sdlGraphicsManager->deactivateManager(); delete _graphicsManager; @@ -541,7 +541,7 @@ void OSystem_SDL::fatalError() { Common::KeymapArray OSystem_SDL::getGlobalKeymaps() { Common::KeymapArray globalMaps = BaseBackend::getGlobalKeymaps(); - SdlGraphicsManager *graphicsManager = dynamic_cast(_graphicsManager); + ResVmSdlGraphicsManager *graphicsManager = dynamic_cast(_graphicsManager); globalMaps.push_back(graphicsManager->getKeymap()); return globalMaps;