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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "backends/graphics/sdl/sdl-graphics.h"
|
2015-01-24 23:42:12 +01:00
|
|
|
#include "backends/platform/sdl/sdl-sys.h"
|
2019-03-10 16:25:25 +00:00
|
|
|
#include "backends/platform/sdl/sdl.h"
|
2011-08-08 21:43:53 +02:00
|
|
|
#include "backends/events/sdl/sdl-events.h"
|
2017-10-01 16:23:22 -05:00
|
|
|
#include "common/config-manager.h"
|
2015-01-24 23:42:12 +01:00
|
|
|
#include "common/textconsole.h"
|
2017-10-01 16:23:22 -05:00
|
|
|
#include "graphics/scaler/aspect.h"
|
2019-03-10 16:25:25 +00:00
|
|
|
#ifdef USE_OSD
|
|
|
|
#include "common/translation.h"
|
|
|
|
#endif
|
2011-08-08 21:43:53 +02:00
|
|
|
|
2015-02-16 00:49:42 +01:00
|
|
|
SdlGraphicsManager::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
|
|
|
: _eventSource(source), _window(window), _hwScreen(nullptr)
|
2017-08-27 22:21:05 -05:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2017-10-01 16:23:22 -05:00
|
|
|
, _allowWindowSizeReset(false), _hintedWidth(0), _hintedHeight(0), _lastFlags(0)
|
2017-08-27 22:21:05 -05:00
|
|
|
#endif
|
2017-11-11 00:15:13 +00:00
|
|
|
{
|
|
|
|
SDL_GetMouseState(&_cursorX, &_cursorY);
|
|
|
|
}
|
2011-08-08 21:43:53 +02:00
|
|
|
|
2013-10-24 00:09:17 +02:00
|
|
|
void SdlGraphicsManager::activateManager() {
|
2013-10-20 22:27:50 +02:00
|
|
|
_eventSource->setGraphicsManager(this);
|
|
|
|
}
|
|
|
|
|
2013-10-24 00:09:17 +02:00
|
|
|
void SdlGraphicsManager::deactivateManager() {
|
2013-10-20 22:27:50 +02:00
|
|
|
_eventSource->setGraphicsManager(0);
|
|
|
|
}
|
2015-01-24 23:42:12 +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
|
|
|
SdlGraphicsManager::State SdlGraphicsManager::getState() const {
|
2015-01-25 19:23:06 +01:00
|
|
|
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
|
2017-10-01 16:23:22 -05:00
|
|
|
initSize(state.screenWidth, state.screenHeight, nullptr);
|
2015-01-25 19:23:06 +01:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
}
|
2015-01-25 01:34:57 +01:00
|
|
|
|
2017-10-01 16:23:22 -05:00
|
|
|
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 {
|
2017-11-07 21:30:49 -06:00
|
|
|
if (name == "normal" || name == "default") {
|
|
|
|
return getDefaultGraphicsMode();
|
|
|
|
}
|
|
|
|
|
2017-10-01 16:23:22 -05:00
|
|
|
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) {
|
2017-08-27 22:21:05 -05:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2017-10-01 16:23:22 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-09-13 00:43:56 -05:00
|
|
|
bool SdlGraphicsManager::showMouse(const 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);
|
|
|
|
}
|
|
|
|
|
2017-09-13 19:55:14 -05:00
|
|
|
bool SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
|
2017-09-13 00:43:56 -05:00
|
|
|
int showCursor = SDL_DISABLE;
|
2017-09-13 19:55:14 -05:00
|
|
|
bool valid = true;
|
|
|
|
if (_activeArea.drawRect.contains(mouse)) {
|
|
|
|
_cursorLastInActiveArea = true;
|
|
|
|
} else {
|
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
|
|
|
mouse.x = CLIP<int>(mouse.x, _activeArea.drawRect.left, _activeArea.drawRect.right - 1);
|
|
|
|
mouse.y = CLIP<int>(mouse.y, _activeArea.drawRect.top, _activeArea.drawRect.bottom - 1);
|
|
|
|
|
2017-09-13 19:55:14 -05:00
|
|
|
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)) {
|
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
|
|
|
setSystemMousePosition(mouse.x, mouse.y);
|
2017-09-13 19:55:14 -05:00
|
|
|
} 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;
|
|
|
|
}
|
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_ShowCursor(showCursor);
|
2017-09-13 19:55:14 -05:00
|
|
|
if (valid) {
|
|
|
|
setMousePosition(mouse.x, mouse.y);
|
|
|
|
mouse = convertWindowToVirtual(mouse.x, mouse.y);
|
|
|
|
}
|
|
|
|
return valid;
|
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
|
|
|
void SdlGraphicsManager::setSystemMousePosition(const int x, const int y) {
|
|
|
|
assert(_window);
|
|
|
|
if (!_window->warpMouseInWindow(x, y)) {
|
2017-11-27 20:30:35 -06:00
|
|
|
const Common::Point mouse = convertWindowToVirtual(x, y);
|
|
|
|
_eventSource->fakeWarpMouse(mouse.x, mouse.y);
|
2017-09-15 22:59:18 -05: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
|
|
|
void SdlGraphicsManager::handleResizeImpl(const int width, const int height) {
|
|
|
|
_eventSource->resetKeyboardEmulation(width - 1, height - 1);
|
|
|
|
_forceRedraw = true;
|
|
|
|
}
|
|
|
|
|
2017-10-01 16:23:22 -05:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
bool SdlGraphicsManager::createOrUpdateWindow(int width, int height, const Uint32 flags) {
|
2017-08-27 22:21:05 -05:00
|
|
|
if (!_window) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We only update the actual window when flags change (which usually means
|
2017-09-17 14:32:25 -05:00
|
|
|
// fullscreen mode is entered/exited), when updates are forced so that we
|
2017-08-27 22:21:05 -05:00
|
|
|
// 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
|
2017-09-17 14:32:25 -05:00
|
|
|
// 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) {
|
2017-11-29 21:01:47 +01:00
|
|
|
const bool fullscreen = (flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP)) != 0;
|
|
|
|
if (!fullscreen) {
|
|
|
|
if (_hintedWidth) {
|
|
|
|
width = _hintedWidth;
|
|
|
|
}
|
|
|
|
if (_hintedHeight) {
|
|
|
|
height = _hintedHeight;
|
|
|
|
}
|
2017-10-01 16:23:22 -05:00
|
|
|
}
|
|
|
|
|
2017-08-27 22:21:05 -05:00
|
|
|
if (!_window->createOrUpdateWindow(width, height, flags)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_lastFlags = flags;
|
|
|
|
_allowWindowSizeReset = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2019-03-10 16:25:25 +00:00
|
|
|
|
|
|
|
void SdlGraphicsManager::saveScreenshot() {
|
|
|
|
Common::String filename;
|
|
|
|
|
|
|
|
Common::String screenshotsPath;
|
|
|
|
OSystem_SDL *sdl_g_system = dynamic_cast<OSystem_SDL*>(g_system);
|
|
|
|
if (sdl_g_system)
|
|
|
|
screenshotsPath = sdl_g_system->getScreenshotsPath();
|
|
|
|
|
|
|
|
for (int n = 0;; n++) {
|
|
|
|
SDL_RWops *file;
|
|
|
|
|
|
|
|
#ifdef USE_PNG
|
|
|
|
filename = Common::String::format("scummvm%05d.png", n);
|
|
|
|
#else
|
|
|
|
filename = Common::String::format("scummvm%05d.bmp", n);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
file = SDL_RWFromFile((screenshotsPath + filename).c_str(), "r");
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
break;
|
|
|
|
SDL_RWclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
switch ((int)event.type) {
|
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
// Alt-Return and Alt-Enter toggle full screen mode
|
|
|
|
if (event.kbd.hasFlags(Common::KBD_ALT) &&
|
|
|
|
(event.kbd.keycode == Common::KEYCODE_RETURN ||
|
2019-04-02 22:41:21 +01:00
|
|
|
event.kbd.keycode == Common::KEYCODE_KP_ENTER)) {
|
2019-03-10 18:32:13 +02:00
|
|
|
toggleFullScreen();
|
2019-03-10 16:25:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Alt-S: Create a screenshot
|
|
|
|
if (event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == 's') {
|
|
|
|
saveScreenshot();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_KEYUP:
|
|
|
|
if (event.kbd.hasFlags(Common::KBD_ALT)) {
|
|
|
|
return event.kbd.keycode == Common::KEYCODE_RETURN
|
2019-04-02 22:41:21 +01:00
|
|
|
|| event.kbd.keycode == Common::KEYCODE_KP_ENTER
|
2019-03-10 16:25:25 +00:00
|
|
|
|| event.kbd.keycode == Common::KEYCODE_s;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-10 18:32:13 +02:00
|
|
|
|
|
|
|
void SdlGraphicsManager::toggleFullScreen() {
|
|
|
|
beginGFXTransaction();
|
|
|
|
setFeatureState(OSystem::kFeatureFullscreenMode, !getFeatureState(OSystem::kFeatureFullscreenMode));
|
|
|
|
endGFXTransaction();
|
|
|
|
#ifdef USE_OSD
|
|
|
|
if (getFeatureState(OSystem::kFeatureFullscreenMode))
|
|
|
|
displayMessageOnOSD(_("Fullscreen mode"));
|
|
|
|
else
|
|
|
|
displayMessageOnOSD(_("Windowed mode"));
|
|
|
|
#endif
|
|
|
|
}
|