2011-08-08 21:43:53 +02:00
|
|
|
/* 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.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2011-08-08 21:43:53 +02:00
|
|
|
* 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.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2011-08-08 21:43:53 +02:00
|
|
|
* 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
|
|
|
|
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
#include "backends/graphics/windowed.h"
|
2015-02-16 00:49:42 +01:00
|
|
|
#include "backends/platform/sdl/sdl-window.h"
|
2013-10-24 00:03:09 +02:00
|
|
|
|
2019-03-10 16:25:25 +00:00
|
|
|
#include "common/events.h"
|
2011-08-08 21:43:53 +02:00
|
|
|
#include "common/rect.h"
|
|
|
|
|
|
|
|
class SdlEventSource;
|
|
|
|
|
2019-11-10 16:34:25 +00:00
|
|
|
#ifndef __SYMBIAN32__
|
2019-03-10 16:25:25 +00:00
|
|
|
#define USE_OSD 1
|
|
|
|
#endif
|
|
|
|
|
2011-08-08 21:43:53 +02:00
|
|
|
/**
|
|
|
|
* Base class for a SDL based graphics manager.
|
|
|
|
*/
|
2019-03-10 16:25:25 +00:00
|
|
|
class SdlGraphicsManager : virtual public WindowedGraphicsManager, public Common::EventObserver {
|
2011-08-08 21:43:53 +02:00
|
|
|
public:
|
2015-02-16 00:49:42 +01:00
|
|
|
SdlGraphicsManager(SdlEventSource *source, SdlWindow *window);
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
virtual ~SdlGraphicsManager() {}
|
2011-08-08 21:43:53 +02:00
|
|
|
|
2013-10-24 00:06:32 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-10-24 00:09:17 +02:00
|
|
|
virtual void activateManager();
|
2013-10-24 00:06:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes this graphics manager inactive. This should allow another
|
|
|
|
* graphics manager to become active again.
|
|
|
|
*/
|
2013-10-24 00:09:17 +02:00
|
|
|
virtual void deactivateManager();
|
2013-10-24 00:06:32 +02:00
|
|
|
|
2011-08-08 21:43:53 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/**
|
2017-09-03 16:31:16 -05:00
|
|
|
* Notify the graphics manager about a resize event.
|
2011-08-08 21:43:53 +02:00
|
|
|
*
|
|
|
|
* It is noteworthy that the requested width/height should actually be set
|
2017-09-03 16:31:16 -05:00
|
|
|
* up as is and not changed by the graphics manager, since otherwise it may
|
2011-08-08 21:43:53 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
virtual void notifyResize(const int width, const int height) {}
|
2011-08-08 21:43:53 +02:00
|
|
|
|
|
|
|
/**
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
* Notifies the graphics manager about a mouse position change.
|
2011-08-08 21:43:53 +02:00
|
|
|
*
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
* 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.
|
2011-08-08 21:43:53 +02:00
|
|
|
*
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
* @param mouse The mouse position in window coordinates, which must be
|
|
|
|
* converted synchronously to virtual coordinates.
|
2017-09-13 19:55:14 -05:00
|
|
|
* @returns true if the mouse was in a valid position for the game and
|
|
|
|
* should cause the event to be sent to the game.
|
2011-08-08 21:43:53 +02:00
|
|
|
*/
|
2017-09-13 19:55:14 -05:00
|
|
|
virtual bool notifyMousePosition(Common::Point &mouse);
|
2011-08-08 21:43:53 +02:00
|
|
|
|
2020-05-30 06:49:09 +01:00
|
|
|
virtual bool showMouse(bool visible) override;
|
2020-10-13 20:31:10 +01:00
|
|
|
virtual bool lockMouse(bool lock) override;
|
2017-09-13 00:43:56 -05:00
|
|
|
|
2019-03-10 16:25:25 +00:00
|
|
|
virtual bool saveScreenshot(const Common::String &filename) const { return false; }
|
2020-10-09 19:04:07 +02:00
|
|
|
void saveScreenshot() override;
|
2019-03-10 16:25:25 +00:00
|
|
|
|
|
|
|
// Override from Common::EventObserver
|
|
|
|
virtual bool notifyEvent(const Common::Event &event) override;
|
|
|
|
|
2015-01-25 19:23:06 +01:00
|
|
|
/**
|
|
|
|
* A (subset) of the graphic manager's state. This is used when switching
|
2017-09-03 16:31:16 -05:00
|
|
|
* between different SDL graphic managers at runtime.
|
2015-01-25 19:23:06 +01:00
|
|
|
*/
|
|
|
|
struct State {
|
|
|
|
int screenWidth, screenHeight;
|
|
|
|
bool aspectRatio;
|
|
|
|
bool fullscreen;
|
|
|
|
bool cursorPalette;
|
|
|
|
|
|
|
|
#ifdef USE_RGB_COLOR
|
|
|
|
Graphics::PixelFormat pixelFormat;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
* Gets the current state of the graphics manager.
|
2015-01-25 19:23:06 +01:00
|
|
|
*/
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
State getState() const;
|
2015-01-25 19:23:06 +01:00
|
|
|
|
|
|
|
/**
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
* Sets up a basic state of the graphics manager.
|
2015-01-25 19:23:06 +01:00
|
|
|
*/
|
|
|
|
bool setState(const State &state);
|
|
|
|
|
2015-02-16 00:49:42 +01:00
|
|
|
/**
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
* @returns the SDL window.
|
2015-02-16 00:49:42 +01:00
|
|
|
*/
|
|
|
|
SdlWindow *getWindow() const { return _window; }
|
|
|
|
|
2017-10-01 16:23:22 -05:00
|
|
|
virtual void initSizeHint(const Graphics::ModeList &modes) override;
|
|
|
|
|
2017-08-15 14:35:26 +02:00
|
|
|
Common::Keymap *getKeymap();
|
|
|
|
|
2011-08-08 21:43:53 +02:00
|
|
|
protected:
|
2017-08-15 15:48:40 +02:00
|
|
|
enum CustomEventAction {
|
|
|
|
kActionToggleFullscreen = 100,
|
|
|
|
kActionToggleMouseCapture,
|
|
|
|
kActionSaveScreenshot,
|
|
|
|
kActionToggleAspectRatioCorrection,
|
|
|
|
kActionToggleFilteredScaling,
|
|
|
|
kActionCycleStretchMode,
|
|
|
|
kActionIncreaseScaleFactor,
|
|
|
|
kActionDecreaseScaleFactor,
|
2020-07-02 13:27:25 +01:00
|
|
|
kActionNextScaleFilter,
|
|
|
|
kActionPreviousScaleFilter
|
2017-08-15 15:48:40 +02:00
|
|
|
};
|
|
|
|
|
2021-04-09 23:32:45 +01:00
|
|
|
/** Obtain the user configured fullscreen resolution, or default to the desktop resolution */
|
|
|
|
Common::Rect getPreferredFullscreenResolution();
|
|
|
|
|
2017-10-01 16:23:22 -05:00
|
|
|
virtual int getGraphicsModeScale(int mode) const = 0;
|
|
|
|
|
|
|
|
bool defaultGraphicsModeConfig() const;
|
|
|
|
int getGraphicsModeIdByName(const Common::String &name) const;
|
|
|
|
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
/**
|
|
|
|
* 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);
|
2020-10-29 19:12:24 +01:00
|
|
|
SDL_GL_GetDrawableSize(_window->getSDLWindow(), width, height);
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
#else
|
|
|
|
assert(_hwScreen);
|
|
|
|
|
|
|
|
if (width) {
|
|
|
|
*width = _hwScreen->w;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height) {
|
|
|
|
*height = _hwScreen->h;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2020-10-29 19:12:24 +01:00
|
|
|
/**
|
|
|
|
* Gets the display index that the ScummVM window is on
|
|
|
|
*/
|
|
|
|
void getWindowDisplayIndexFromSdl(int *index) const {
|
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
assert(_window);
|
|
|
|
*index = SDL_GetWindowDisplayIndex(_window->getSDLWindow());
|
|
|
|
#else
|
|
|
|
*index = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void getDisplayDpiFromSdl(float *dpi, float *defaultDpi) const {
|
|
|
|
const float systemDpi =
|
|
|
|
#ifdef __APPLE__
|
|
|
|
72.0f;
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
96.0f;
|
|
|
|
#else
|
|
|
|
90.0f; // ScummVM default
|
|
|
|
#endif
|
|
|
|
if (defaultDpi)
|
|
|
|
*defaultDpi = systemDpi;
|
2021-04-13 19:27:31 +01:00
|
|
|
|
|
|
|
if (dpi) {
|
2021-04-13 17:18:29 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 4)
|
2021-04-13 19:27:31 +01:00
|
|
|
int displayIndex = 0;
|
|
|
|
getWindowDisplayIndexFromSdl(&displayIndex);
|
2020-10-29 19:12:24 +01:00
|
|
|
|
2021-04-13 19:27:31 +01:00
|
|
|
if (SDL_GetDisplayDPI(displayIndex, NULL, dpi, NULL) != 0) {
|
|
|
|
*dpi = systemDpi;
|
|
|
|
}
|
2020-10-29 19:12:24 +01:00
|
|
|
#else
|
2021-04-13 19:27:31 +01:00
|
|
|
*dpi = systemDpi;
|
2020-10-29 19:12:24 +01:00
|
|
|
#endif
|
2021-04-13 19:27:31 +01:00
|
|
|
}
|
2020-10-29 19:12:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the scaling mode based on the display DPI
|
|
|
|
*/
|
|
|
|
void getDpiScalingFactor(uint *scale) const {
|
|
|
|
float dpi, defaultDpi, ratio;
|
|
|
|
|
|
|
|
getDisplayDpiFromSdl(&dpi, &defaultDpi);
|
|
|
|
debug(4, "dpi: %g default: %g", dpi, defaultDpi);
|
|
|
|
ratio = dpi / defaultDpi;
|
2020-12-31 13:38:14 +01:00
|
|
|
if (ratio >= 1.5f) {
|
2020-10-29 19:12:24 +01:00
|
|
|
*scale = 2;
|
|
|
|
} else {
|
|
|
|
*scale = 1;
|
|
|
|
}
|
|
|
|
}
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
|
2017-09-15 22:59:18 -05:00
|
|
|
virtual void setSystemMousePosition(const int x, const int y) override;
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
|
2020-10-29 17:30:05 +00:00
|
|
|
virtual void handleResizeImpl(const int width, const int height) override;
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
|
2017-08-27 22:21:05 -05:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
public:
|
2017-10-01 16:23:22 -05:00
|
|
|
void unlockWindowSize() {
|
|
|
|
_allowWindowSizeReset = true;
|
|
|
|
_hintedWidth = 0;
|
|
|
|
_hintedHeight = 0;
|
|
|
|
}
|
2017-08-27 22:21:05 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Uint32 _lastFlags;
|
|
|
|
bool _allowWindowSizeReset;
|
2017-10-01 16:23:22 -05:00
|
|
|
int _hintedWidth, _hintedHeight;
|
2017-08-27 22:21:05 -05:00
|
|
|
|
|
|
|
bool createOrUpdateWindow(const int width, const int height, const Uint32 flags);
|
|
|
|
#endif
|
|
|
|
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
SDL_Surface *_hwScreen;
|
2011-08-08 21:43:53 +02:00
|
|
|
SdlEventSource *_eventSource;
|
2015-02-16 00:49:42 +01:00
|
|
|
SdlWindow *_window;
|
2019-03-10 18:32:13 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void toggleFullScreen();
|
2011-08-08 21:43:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|