From b53020f70457c059f5028073df493cfc25a5876a Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Sun, 3 Sep 2017 16:31:16 -0500 Subject: BACKENDS: Fix some comment typos --- backends/graphics/opengl/opengl-graphics.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index e02137bba7..cbf68d9cf1 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -241,7 +241,7 @@ private: }; /** - * The currently setup video state. + * The currently set up video state. */ VideoState _currentState; @@ -444,7 +444,7 @@ private: Surface *_cursor; /** - * X coordinate of the cursor in phyiscal coordinates. + * X coordinate of the cursor in physical coordinates. */ int _cursorX; -- cgit v1.2.3 From de2bbe3b9738ef95b2529db989570770ef434f9d Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Wed, 19 Jul 2017 19:15:12 -0500 Subject: BACKENDS: Refactor OpenGL & SDL graphics backends This patch refactors the OpenGL and SDL graphics backends, primarily to unify window scaling and mouse handling, and to fix coordinate mapping between the ScummVM window and the virtual game screen when they have different aspect ratios. Unified code for these two backends has been moved to a new header-only WindowedGraphicsManager class, so named because it contains code for managing graphics managers that interact with a windowing system and render virtual screens within a larger physical content window. The biggest behavioral change here is with the coordinate system mapping: Previously, mouse offsets were converted by mapping the whole space within the window as input to the virtual game screen without maintaining aspect ratio. This was done to prevent 'stickiness' when the mouse cursor was within the window but outside of the virtual game screen, but it caused noticeable distortion of mouse movement speed on the axis with blank space. Instead of introducing mouse speed distortion to prevent stickiness, this patch changes coordinate transformation to show the system cursor when the mouse moves outside of the virtual game screen when mouse grab is off, or by holding the mouse inside the virtual game screen (instead of the entire window) when mouse grab is on. This patch also improves some other properties of the GraphicsManager/PaletteManager interfaces: * Nullipotent operations (getWidth, getHeight, etc.) of the PaletteManager/GraphicsManager interfaces are now const * Methods marked `virtual` but not inherited by any subclass have been de-virtualized * Extra unnecessary calculations of hardware height in SurfaceSdlGraphicsManager have been removed * Methods have been renamed where appropriate for clarity (setWindowSize -> handleResize, etc.) * C++11 support improved with `override` specifier added on overridden virtual methods in subclasses (primarily to avoid myself accidentally creating new methods in the subclasses by changing types/names during refactoring) Additional refactoring can and should be done at some point to continue to deduplicate code between the OpenGL and SDL backends. Since the primary goal here was to improve the coordinate mapping, full refactoring of these backends was not completed here. --- backends/graphics/opengl/opengl-graphics.h | 228 +++++++---------------------- 1 file changed, 55 insertions(+), 173 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index cbf68d9cf1..92bb988a5e 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -25,7 +25,7 @@ #include "backends/graphics/opengl/opengl-sys.h" #include "backends/graphics/opengl/framebuffer.h" -#include "backends/graphics/graphics.h" +#include "backends/graphics/windowed.h" #include "common/frac.h" #include "common/mutex.h" @@ -53,74 +53,70 @@ enum { GFX_OPENGL = 0 }; -class OpenGLGraphicsManager : virtual public GraphicsManager { +class OpenGLGraphicsManager : virtual public WindowedGraphicsManager { public: OpenGLGraphicsManager(); virtual ~OpenGLGraphicsManager(); // GraphicsManager API - virtual bool hasFeature(OSystem::Feature f); - virtual void setFeatureState(OSystem::Feature f, bool enable); - virtual bool getFeatureState(OSystem::Feature f); + virtual bool hasFeature(OSystem::Feature f) const override; + virtual void setFeatureState(OSystem::Feature f, bool enable) override; + virtual bool getFeatureState(OSystem::Feature f) const override; - virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const; - virtual int getDefaultGraphicsMode() const; - virtual bool setGraphicsMode(int mode); - virtual int getGraphicsMode() const; + virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const override; + virtual int getDefaultGraphicsMode() const override; + virtual bool setGraphicsMode(int mode) override; + virtual int getGraphicsMode() const override; - virtual void resetGraphicsScale() {} + virtual void resetGraphicsScale() override {} #ifdef USE_RGB_COLOR - virtual Graphics::PixelFormat getScreenFormat() const; - virtual Common::List getSupportedFormats() const = 0; + virtual Graphics::PixelFormat getScreenFormat() const override; + virtual Common::List getSupportedFormats() const override = 0; #endif - virtual void beginGFXTransaction(); - virtual OSystem::TransactionError endGFXTransaction(); + virtual void beginGFXTransaction() override; + virtual OSystem::TransactionError endGFXTransaction() override; - virtual int getScreenChangeID() const; + virtual int getScreenChangeID() const override; - virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format); + virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format) override; - virtual int16 getWidth(); - virtual int16 getHeight(); + virtual int16 getWidth() const override; + virtual int16 getHeight() const override; - virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h); - virtual void fillScreen(uint32 col); + virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override; + virtual void fillScreen(uint32 col) override; - virtual void setShakePos(int shakeOffset); + virtual void setShakePos(int shakeOffset) override; - virtual void updateScreen(); + virtual void updateScreen() override; - virtual Graphics::Surface *lockScreen(); - virtual void unlockScreen(); + virtual Graphics::Surface *lockScreen() override; + virtual void unlockScreen() override; - virtual void setFocusRectangle(const Common::Rect& rect); - virtual void clearFocusRectangle(); + virtual void setFocusRectangle(const Common::Rect& rect) override; + virtual void clearFocusRectangle() override; - virtual int16 getOverlayWidth(); - virtual int16 getOverlayHeight(); + virtual int16 getOverlayWidth() const override; + virtual int16 getOverlayHeight() const override; - virtual void showOverlay(); - virtual void hideOverlay(); + virtual Graphics::PixelFormat getOverlayFormat() const override; - virtual Graphics::PixelFormat getOverlayFormat() const; + virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) override; + virtual void clearOverlay() override; + virtual void grabOverlay(void *buf, int pitch) const override; - virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h); - virtual void clearOverlay(); - virtual void grabOverlay(void *buf, int pitch); + virtual bool showMouse(bool visible) override; + virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) override; + virtual void setCursorPalette(const byte *colors, uint start, uint num) override; - virtual bool showMouse(bool visible); - virtual void warpMouse(int x, int y); - virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format); - virtual void setCursorPalette(const byte *colors, uint start, uint num); - - virtual void displayMessageOnOSD(const char *msg); - virtual void displayActivityIconOnOSD(const Graphics::Surface *icon); + virtual void displayMessageOnOSD(const char *msg) override; + virtual void displayActivityIconOnOSD(const Graphics::Surface *icon) override; // PaletteManager interface - virtual void setPalette(const byte *colors, uint start, uint num); - virtual void grabPalette(byte *colors, uint start, uint num); + virtual void setPalette(const byte *colors, uint start, uint num) override; + virtual void grabPalette(byte *colors, uint start, uint num) const override; protected: /** @@ -128,15 +124,6 @@ protected: */ bool isGLESContext() const { return g_context.type == kContextGLES || g_context.type == kContextGLES2; } - /** - * Set up the actual screen size available for the OpenGL code to do any - * drawing. - * - * @param width The width of the screen. - * @param height The height of the screen. - */ - void setActualScreenSize(uint width, uint height); - /** * Sets the OpenGL (ES) type the graphics manager shall work with. * @@ -166,33 +153,6 @@ protected: */ void notifyContextDestroy(); - /** - * Adjust the physical mouse coordinates according to the currently visible screen. - */ - void adjustMousePosition(int16 &x, int16 &y); - - /** - * Set up the mouse position for graphics output. - * - * @param x X coordinate in physical coordinates. - * @param y Y coordinate in physical coordinates. - */ - void setMousePosition(int x, int y); - - /** - * Query the mouse position in physical coordinates. - */ - void getMousePosition(int16 &x, int16 &y) const { x = _cursorX; y = _cursorY; } - - /** - * Set up the mouse position for the (event) system. - * - * @param x X coordinate in physical coordinates. - * @param y Y coordinate in physical coordinates. - */ - virtual void setInternalMousePosition(int x, int y) = 0; - -private: /** * Create a surface with the specified pixel format. * @@ -292,8 +252,7 @@ protected: virtual void refreshScreen() = 0; /** - * Save a screenshot of the full display as BMP to the given file. This - * uses Common::DumpFile for writing the screenshot. + * Saves a screenshot of the entire window, excluding window decorations. * * @param filename The output filename. * @return true on success, false otherwise @@ -334,7 +293,6 @@ protected: */ virtual void *getProcAddress(const char *name) const = 0; -private: /** * Try to determine the internal parameters for a given pixel format. * @@ -342,49 +300,9 @@ private: */ bool getGLPixelFormat(const Graphics::PixelFormat &pixelFormat, GLenum &glIntFormat, GLenum &glFormat, GLenum &glType) const; - // - // Actual hardware screen - // - - /** - * The width of the physical output. - */ - uint _outputScreenWidth; - - /** - * The height of the physical output. - */ - uint _outputScreenHeight; - - /** - * @return The desired aspect of the game screen. - */ - frac_t getDesiredGameScreenAspect() const; - - /** - * Recalculates the area used to display the game screen. - */ - void recalculateDisplayArea(); - - /** - * The X coordinate of the game screen. - */ - uint _displayX; - - /** - * The Y coordinate of the game screen. - */ - uint _displayY; - - /** - * The width of the game screen in physical coordinates. - */ - uint _displayWidth; - - /** - * The height of the game screen in physical coordinates. - */ - uint _displayHeight; + virtual bool gameNeedsAspectRatioCorrection() const override; + virtual void recalculateDisplayAreas() override; + virtual void handleResizeImpl(const int width, const int height) override; /** * The default pixel format of the backend. @@ -396,12 +314,8 @@ private: */ Graphics::PixelFormat _defaultFormatAlpha; - // - // Game screen - // - /** - * The virtual game screen. + * The rendering surface for the virtual game screen. */ Surface *_gameScreen; @@ -420,15 +334,10 @@ private: // /** - * The overlay screen. + * The rendering surface for the overlay. */ Surface *_overlay; - /** - * Whether the overlay is visible or not. - */ - bool _overlayVisible; - // // Cursor // @@ -439,37 +348,17 @@ private: void updateCursorPalette(); /** - * The cursor image. + * The rendering surface for the mouse cursor. */ Surface *_cursor; /** - * X coordinate of the cursor in physical coordinates. - */ - int _cursorX; - - /** - * Y coordinate of the cursor in physical coordinates. - */ - int _cursorY; - - /** - * X coordinate used for drawing the cursor. - */ - int _cursorDisplayX; - - /** - * Y coordinate used for drawing the cursor. - */ - int _cursorDisplayY; - - /** - * The X offset for the cursor hotspot in unscaled coordinates. + * The X offset for the cursor hotspot in unscaled game coordinates. */ int _cursorHotspotX; /** - * The Y offset for the cursor hotspot in unscaled coordinates. + * The Y offset for the cursor hotspot in unscaled game coordinates. */ int _cursorHotspotY; @@ -480,22 +369,24 @@ private: void recalculateCursorScaling(); /** - * The X offset for the cursor hotspot in scaled coordinates. + * The X offset for the cursor hotspot in scaled game display area + * coordinates. */ int _cursorHotspotXScaled; /** - * The Y offset for the cursor hotspot in scaled coordinates. + * The Y offset for the cursor hotspot in scaled game display area + * coordinates. */ int _cursorHotspotYScaled; /** - * The width of the cursor scaled coordinates. + * The width of the cursor in scaled game display area coordinates. */ uint _cursorWidthScaled; /** - * The height of the cursor scaled coordinates. + * The height of the cursor in scaled game display area coordinates. */ uint _cursorHeightScaled; @@ -524,15 +415,6 @@ private: */ byte _cursorPalette[3 * 256]; - // - // Misc - // - - /** - * Whether the screen contents shall be forced to redrawn. - */ - bool _forceRedraw; - #ifdef USE_OSD // // OSD @@ -541,7 +423,7 @@ protected: /** * Returns the font used for on screen display */ - virtual const Graphics::Font *getFontOSD(); + virtual const Graphics::Font *getFontOSD() const; private: /** -- cgit v1.2.3 From da0a8db704f610994d665dfd7c080b49476ce76d Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Wed, 13 Sep 2017 00:43:56 -0500 Subject: BACKENDS: Also hide mouse cursor outside game area when an engine has hidden the cursor The only reason we show the system cursor outside the game area is to show users where their mouse is when the window is resized and the mouse is outside the game area. If the game cannot be interacted with, then the mouse also does not need to be shown in the black areas. --- backends/graphics/opengl/opengl-graphics.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'backends/graphics/opengl/opengl-graphics.h') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 92bb988a5e..df968aa67e 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -107,7 +107,6 @@ public: virtual void clearOverlay() override; virtual void grabOverlay(void *buf, int pitch) const override; - virtual bool showMouse(bool visible) override; virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) override; virtual void setCursorPalette(const byte *colors, uint start, uint num) override; @@ -395,11 +394,6 @@ protected: */ uint32 _cursorKeyColor; - /** - * Whether the cursor is actually visible. - */ - bool _cursorVisible; - /** * Whether no cursor scaling should be applied. */ -- cgit v1.2.3