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
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BACKENDS_GRAPHICS_WINDOWED_H
|
|
|
|
#define BACKENDS_GRAPHICS_WINDOWED_H
|
|
|
|
|
|
|
|
#include "backends/graphics/graphics.h"
|
|
|
|
#include "common/frac.h"
|
|
|
|
#include "common/rect.h"
|
2018-05-12 19:57:21 +01:00
|
|
|
#include "common/config-manager.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 "common/textconsole.h"
|
|
|
|
#include "graphics/scaler/aspect.h"
|
|
|
|
|
2018-05-12 19:57:21 +01:00
|
|
|
enum {
|
|
|
|
STRETCH_CENTER = 0,
|
|
|
|
STRETCH_INTEGRAL = 1,
|
|
|
|
STRETCH_FIT = 2,
|
|
|
|
STRETCH_STRETCH = 3
|
|
|
|
};
|
|
|
|
|
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
|
|
|
class WindowedGraphicsManager : virtual public GraphicsManager {
|
|
|
|
public:
|
|
|
|
WindowedGraphicsManager() :
|
|
|
|
_windowWidth(0),
|
|
|
|
_windowHeight(0),
|
|
|
|
_overlayVisible(false),
|
|
|
|
_forceRedraw(false),
|
2017-09-13 00:43:56 -05:00
|
|
|
_cursorVisible(false),
|
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
|
|
|
_cursorX(0),
|
|
|
|
_cursorY(0),
|
2017-09-13 19:55:14 -05:00
|
|
|
_cursorNeedsRedraw(false),
|
|
|
|
_cursorLastInActiveArea(true) {}
|
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 showOverlay() override {
|
|
|
|
if (_overlayVisible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_activeArea.drawRect = _overlayDrawRect;
|
|
|
|
_activeArea.width = getOverlayWidth();
|
|
|
|
_activeArea.height = getOverlayHeight();
|
|
|
|
_overlayVisible = true;
|
|
|
|
_forceRedraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void hideOverlay() override {
|
|
|
|
if (!_overlayVisible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_activeArea.drawRect = _gameDrawRect;
|
|
|
|
_activeArea.width = getWidth();
|
|
|
|
_activeArea.height = getHeight();
|
|
|
|
_overlayVisible = false;
|
|
|
|
_forceRedraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @returns whether or not the game screen must have aspect ratio correction
|
|
|
|
* applied for correct rendering.
|
|
|
|
*/
|
|
|
|
virtual bool gameNeedsAspectRatioCorrection() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Backend-specific implementation for updating internal surfaces that need
|
|
|
|
* to reflect the new window size.
|
|
|
|
*/
|
|
|
|
virtual void handleResizeImpl(const int width, const int height) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the given point from the active virtual screen's coordinate
|
|
|
|
* space to the window's coordinate space (i.e. game-to-window or
|
|
|
|
* overlay-to-window).
|
|
|
|
*/
|
|
|
|
Common::Point convertVirtualToWindow(const int x, const int y) const {
|
|
|
|
const int targetX = _activeArea.drawRect.left;
|
|
|
|
const int targetY = _activeArea.drawRect.top;
|
|
|
|
const int targetWidth = _activeArea.drawRect.width();
|
|
|
|
const int targetHeight = _activeArea.drawRect.height();
|
|
|
|
const int sourceWidth = _activeArea.width;
|
|
|
|
const int sourceHeight = _activeArea.height;
|
|
|
|
|
|
|
|
if (sourceWidth == 0 || sourceHeight == 0) {
|
|
|
|
error("convertVirtualToWindow called without a valid draw rect");
|
|
|
|
}
|
|
|
|
|
2018-01-12 22:43:00 -06:00
|
|
|
return Common::Point(targetX + (x * targetWidth + sourceWidth / 2) / sourceWidth,
|
|
|
|
targetY + (y * targetHeight + sourceHeight / 2) / sourceHeight);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the given point from the window's coordinate space to the
|
|
|
|
* active virtual screen's coordinate space (i.e. window-to-game or
|
|
|
|
* window-to-overlay).
|
|
|
|
*/
|
|
|
|
Common::Point convertWindowToVirtual(int x, int y) const {
|
|
|
|
const int sourceX = _activeArea.drawRect.left;
|
|
|
|
const int sourceY = _activeArea.drawRect.top;
|
|
|
|
const int sourceMaxX = _activeArea.drawRect.right - 1;
|
|
|
|
const int sourceMaxY = _activeArea.drawRect.bottom - 1;
|
|
|
|
const int sourceWidth = _activeArea.drawRect.width();
|
|
|
|
const int sourceHeight = _activeArea.drawRect.height();
|
|
|
|
const int targetWidth = _activeArea.width;
|
|
|
|
const int targetHeight = _activeArea.height;
|
|
|
|
|
|
|
|
if (sourceWidth == 0 || sourceHeight == 0) {
|
|
|
|
error("convertWindowToVirtual called without a valid draw rect");
|
|
|
|
}
|
|
|
|
|
|
|
|
x = CLIP<int>(x, sourceX, sourceMaxX);
|
|
|
|
y = CLIP<int>(y, sourceY, sourceMaxY);
|
|
|
|
|
2018-01-12 22:43:00 -06:00
|
|
|
return Common::Point(((x - sourceX) * targetWidth + sourceWidth / 2) / sourceWidth,
|
|
|
|
((y - sourceY) * targetHeight + sourceHeight / 2) / sourceHeight);
|
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 desired aspect ratio of the game surface.
|
|
|
|
*/
|
|
|
|
frac_t getDesiredGameAspectRatio() const {
|
|
|
|
if (getHeight() == 0 || gameNeedsAspectRatioCorrection()) {
|
|
|
|
return intToFrac(4) / 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return intToFrac(getWidth()) / getHeight();
|
|
|
|
}
|
|
|
|
|
2018-05-12 19:57:21 +01:00
|
|
|
/**
|
|
|
|
* @returns the scale used between the game size and the surface on which it is rendered.
|
|
|
|
*/
|
|
|
|
virtual int getGameRenderScale() const {
|
|
|
|
return 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
|
|
|
/**
|
|
|
|
* Called after the window has been updated with new dimensions.
|
|
|
|
*
|
|
|
|
* @param width The new width of the window, excluding window decoration.
|
|
|
|
* @param height The new height of the window, excluding window decoration.
|
|
|
|
*/
|
|
|
|
void handleResize(const int width, const int height) {
|
|
|
|
_windowWidth = width;
|
|
|
|
_windowHeight = height;
|
|
|
|
handleResizeImpl(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recalculates the display areas for the game and overlay surfaces within
|
|
|
|
* the window.
|
|
|
|
*/
|
|
|
|
virtual void recalculateDisplayAreas() {
|
|
|
|
if (_windowHeight == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-12 19:57:21 +01:00
|
|
|
populateDisplayAreaDrawRect(getDesiredGameAspectRatio(), getWidth() * getGameRenderScale(), _gameDrawRect);
|
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
|
|
|
|
|
|
|
if (getOverlayHeight()) {
|
|
|
|
const frac_t overlayAspect = intToFrac(getOverlayWidth()) / getOverlayHeight();
|
2018-05-12 19:57:21 +01:00
|
|
|
populateDisplayAreaDrawRect(overlayAspect, getOverlayWidth(), _overlayDrawRect);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (_overlayVisible) {
|
|
|
|
_activeArea.drawRect = _overlayDrawRect;
|
|
|
|
_activeArea.width = getOverlayWidth();
|
|
|
|
_activeArea.height = getOverlayHeight();
|
|
|
|
} else {
|
|
|
|
_activeArea.drawRect = _gameDrawRect;
|
|
|
|
_activeArea.width = getWidth();
|
|
|
|
_activeArea.height = getHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Sets the position of the hardware mouse cursor in the host system,
|
|
|
|
* relative to the window.
|
|
|
|
*
|
|
|
|
* @param x X coordinate in window coordinates.
|
|
|
|
* @param y Y coordinate in window coordinates.
|
|
|
|
*/
|
|
|
|
virtual void setSystemMousePosition(const int x, const int y) = 0;
|
|
|
|
|
2017-09-13 00:43:56 -05:00
|
|
|
virtual bool showMouse(const bool visible) override {
|
|
|
|
if (_cursorVisible == visible) {
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool last = _cursorVisible;
|
|
|
|
_cursorVisible = visible;
|
|
|
|
_cursorNeedsRedraw = true;
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Move ("warp") the mouse cursor to the specified position.
|
|
|
|
*
|
|
|
|
* @param x The new X position of the mouse in virtual screen coordinates.
|
|
|
|
* @param y The new Y position of the mouse in virtual screen coordinates.
|
|
|
|
*/
|
2018-03-28 11:58:35 +02:00
|
|
|
void warpMouse(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
|
|
|
// Check active coordinate instead of window coordinate to avoid warping
|
|
|
|
// the mouse if it is still within the same virtual pixel
|
|
|
|
const Common::Point virtualCursor = convertWindowToVirtual(_cursorX, _cursorY);
|
|
|
|
if (virtualCursor.x != x || virtualCursor.y != y) {
|
|
|
|
// Warping the mouse in SDL generates a mouse movement event, so
|
|
|
|
// `setMousePosition` would be called eventually through the
|
|
|
|
// `notifyMousePosition` callback if we *only* set the system mouse
|
|
|
|
// position here. However, this can cause problems with some games.
|
|
|
|
// For example, the cannon script in CoMI calls to warp the mouse
|
|
|
|
// twice each time the cannon is reloaded, and unless we update the
|
|
|
|
// mouse position immediately, the second call is ignored, which
|
|
|
|
// causes the cannon to change its aim.
|
|
|
|
const Common::Point windowCursor = convertVirtualToWindow(x, y);
|
|
|
|
setMousePosition(windowCursor.x, windowCursor.y);
|
|
|
|
setSystemMousePosition(windowCursor.x, windowCursor.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the position of the rendered mouse cursor in the window.
|
|
|
|
*
|
|
|
|
* @param x X coordinate in window coordinates.
|
|
|
|
* @param y Y coordinate in window coordinates.
|
|
|
|
*/
|
|
|
|
void setMousePosition(int x, int y) {
|
|
|
|
if (_cursorX != x || _cursorY != y) {
|
|
|
|
_cursorNeedsRedraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cursorX = x;
|
|
|
|
_cursorY = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The width of the window, excluding window decoration.
|
|
|
|
*/
|
|
|
|
int _windowWidth;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of the window, excluding window decoration.
|
|
|
|
*/
|
|
|
|
int _windowHeight;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the overlay (i.e. launcher, including the out-of-game launcher)
|
|
|
|
* is visible or not.
|
|
|
|
*/
|
|
|
|
bool _overlayVisible;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The scaled draw rectangle for the game surface within the window.
|
|
|
|
*/
|
|
|
|
Common::Rect _gameDrawRect;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The scaled draw rectangle for the overlay (launcher) surface within the
|
|
|
|
* window.
|
|
|
|
*/
|
|
|
|
Common::Rect _overlayDrawRect;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data about the display area of a virtual screen.
|
|
|
|
*/
|
|
|
|
struct DisplayArea {
|
|
|
|
/**
|
|
|
|
* The scaled area where the virtual screen is drawn within the window.
|
|
|
|
*/
|
|
|
|
Common::Rect drawRect;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The width of the virtual screen's unscaled coordinate space.
|
|
|
|
*/
|
|
|
|
int width;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of the virtual screen's unscaled coordinate space.
|
|
|
|
*/
|
|
|
|
int height;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display area information about the currently active virtual screen. This
|
|
|
|
* will be the overlay screen when the overlay is active, and the game
|
|
|
|
* screen otherwise.
|
|
|
|
*/
|
|
|
|
DisplayArea _activeArea;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the screen must be redrawn on the next frame.
|
|
|
|
*/
|
|
|
|
bool _forceRedraw;
|
|
|
|
|
2017-09-13 00:43:56 -05:00
|
|
|
/**
|
|
|
|
* Whether the cursor is actually visible.
|
|
|
|
*/
|
|
|
|
bool _cursorVisible;
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Whether the mouse cursor needs to be redrawn on the next frame.
|
|
|
|
*/
|
|
|
|
bool _cursorNeedsRedraw;
|
|
|
|
|
2017-09-13 19:55:14 -05:00
|
|
|
/**
|
|
|
|
* Whether the last position of the system cursor was within the active area
|
|
|
|
* of the window.
|
|
|
|
*/
|
|
|
|
bool _cursorLastInActiveArea;
|
|
|
|
|
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 position of the mouse cursor, in window coordinates.
|
|
|
|
*/
|
|
|
|
int _cursorX, _cursorY;
|
|
|
|
|
|
|
|
private:
|
2018-05-12 19:57:21 +01:00
|
|
|
void populateDisplayAreaDrawRect(const frac_t displayAspect, int originalWidth, Common::Rect &drawRect) const {
|
|
|
|
int mode = getStretchMode();
|
|
|
|
// Mode Center = use original size, or divide by an integral amount if window is smaller than game surface
|
|
|
|
// Mode Integral = scale by an integral amount.
|
|
|
|
// Mode Fit = scale to fit the window while respecting the aspect ratio
|
|
|
|
// Mode Stretch = scale and stretch to fit the window without respecting the aspect ratio
|
|
|
|
|
|
|
|
int width = 0, height = 0;
|
|
|
|
if (mode == STRETCH_CENTER || mode == STRETCH_INTEGRAL) {
|
|
|
|
width = originalWidth;
|
|
|
|
height = intToFrac(width) / displayAspect;
|
|
|
|
if (width > _windowWidth || height > _windowHeight) {
|
|
|
|
int fac = 1 + MAX((width - 1) / _windowWidth, (height - 1) / _windowHeight);
|
|
|
|
width /= fac;
|
|
|
|
height /= fac;
|
|
|
|
} else if (mode == STRETCH_INTEGRAL) {
|
|
|
|
int fac = MIN(_windowWidth / width, _windowHeight / height);
|
|
|
|
width *= fac;
|
|
|
|
height *= fac;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
frac_t windowAspect = intToFrac(_windowWidth) / _windowHeight;
|
|
|
|
width = _windowWidth;
|
|
|
|
height = _windowHeight;
|
|
|
|
if (mode != STRETCH_STRETCH) {
|
|
|
|
if (windowAspect < displayAspect)
|
|
|
|
height = intToFrac(width) / displayAspect;
|
|
|
|
else if (windowAspect > displayAspect)
|
|
|
|
width = fracToInt(height * displayAspect);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
drawRect.left = (_windowWidth - width) / 2;
|
|
|
|
drawRect.top = (_windowHeight - height) / 2;
|
|
|
|
drawRect.setWidth(width);
|
|
|
|
drawRect.setHeight(height);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|