[Scummvm-cvs-logs] scummvm master -> cbc517f14f339cbf709797192e1d8d48ff2313de

lordhoto lordhoto at gmail.com
Sun Dec 13 15:45:24 CET 2015


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
cbc517f14f SDL: Fix warpMouse for SDL2.


Commit: cbc517f14f339cbf709797192e1d8d48ff2313de
    https://github.com/scummvm/scummvm/commit/cbc517f14f339cbf709797192e1d8d48ff2313de
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-13T15:44:42+01:00

Commit Message:
SDL: Fix warpMouse for SDL2.

Thanks to bgK for noticing.

Changed paths:
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.h



diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index e45773e..7d666bd 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -125,7 +125,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
 	_hwscreen(0),
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 	_renderer(nullptr), _screenTexture(nullptr),
-	_viewportX(0), _viewportY(0), _mouseScaleX(1.0f), _mouseScaleY(1.0f),
+	_viewportX(0), _viewportY(0), _renderScaleX(1.0f), _renderScaleY(1.0f), _mouseScaleX(1.0f), _mouseScaleY(1.0f),
 #else
 	_originalBitsPerPixel(0),
 #endif
@@ -1757,22 +1757,28 @@ void SurfaceSdlGraphicsManager::setMousePos(int x, int y) {
 }
 
 void SurfaceSdlGraphicsManager::warpMouse(int x, int y) {
-	int y1 = y;
-
 	// Don't change actual mouse position, when mouse is outside of our window (in case of windowed mode)
 	if (!_window->hasMouseFocus()) {
 		setMousePos(x, y); // but change game cursor position
 		return;
 	}
 
+	int x1 = x, y1 = y;
 	if (_videoMode.aspectRatioCorrection && !_overlayVisible)
-		y1 = real2Aspect(y);
+		y1 = real2Aspect(y1);
 
 	if (_mouseCurState.x != x || _mouseCurState.y != y) {
-		if (!_overlayVisible)
-			_window->warpMouseInWindow(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor);
-		else
-			_window->warpMouseInWindow(x, y1);
+		if (!_overlayVisible) {
+			x1 *= _videoMode.scaleFactor;
+			y1 *= _videoMode.scaleFactor;
+		}
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+		x1 = (int)((x1 + _viewportX) * _renderScaleX);
+		y1 = (int)((y1 + _viewportY) * _renderScaleY);
+#endif
+
+		_window->warpMouseInWindow(x1, y1);
 
 		// SDL_WarpMouse() generates a mouse movement event, so
 		// setMousePos() would be called eventually. However, the
@@ -2414,13 +2420,12 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height,
 	// obtain the actual window size and the internal renderer scaling.
 	// Based on this we calculate scale factors to scale received mouse
 	// coordinates into actual screen area coordinates.
-	float scaleX = 0, scaleY = 0;
-	SDL_RenderGetScale(_renderer, &scaleX, &scaleY);
+	SDL_RenderGetScale(_renderer, &_renderScaleX, &_renderScaleY);
 	int windowWidth = 1, windowHeight = 1;
 	SDL_GetWindowSize(_window->getSDLWindow(), &windowWidth, &windowHeight);
 
-	_mouseScaleX = (width  * scaleX) / windowWidth;
-	_mouseScaleY = (height * scaleY) / windowHeight;
+	_mouseScaleX = (width  * _renderScaleX) / windowWidth;
+	_mouseScaleY = (height * _renderScaleY) / windowHeight;
 
 	// Obtain viewport top left coordinates to transform received coordinates
 	// into visible area coordinates (i.e. including black borders).
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index 07ff4e5..4d74ec5 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -172,6 +172,7 @@ protected:
 	SDL_Renderer *_renderer;
 	SDL_Texture *_screenTexture;
 	int _viewportX, _viewportY;
+	float _renderScaleX, _renderScaleY;
 	float _mouseScaleX, _mouseScaleY;
 	void deinitializeRenderer();
 






More information about the Scummvm-git-logs mailing list