aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/opengl
diff options
context:
space:
mode:
authorJohannes Schickel2011-03-17 17:37:42 +0100
committerJohannes Schickel2011-03-17 17:37:42 +0100
commite08683d939d621f20b0376f9da561f06c4944e31 (patch)
tree416eaeaa5c5ac6c149ce8d2fc424f1fbb8973cc9 /backends/graphics/opengl
parentcb6f02f7ef6c5c81892cd8f8bd2f5e323e388fa4 (diff)
downloadscummvm-rg350-e08683d939d621f20b0376f9da561f06c4944e31.tar.gz
scummvm-rg350-e08683d939d621f20b0376f9da561f06c4944e31.tar.bz2
scummvm-rg350-e08683d939d621f20b0376f9da561f06c4944e31.zip
OPENGL: Refactor warpMouse.
Now subclasses will not need to worry about the scaling logic themselves, but just need to implement setInternalMousePosition, which should handles setting the system's mouse coordinates.
Diffstat (limited to 'backends/graphics/opengl')
-rw-r--r--backends/graphics/opengl/opengl-graphics.cpp58
-rw-r--r--backends/graphics/opengl/opengl-graphics.h10
2 files changed, 59 insertions, 9 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 9a2efe3eec..6bd790237a 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -540,13 +540,53 @@ bool OpenGLGraphicsManager::showMouse(bool visible) {
return last;
}
-void OpenGLGraphicsManager::setMousePos(int x, int y) {
- _cursorState.x = x;
- _cursorState.y = y;
-}
-
void OpenGLGraphicsManager::warpMouse(int x, int y) {
- setMousePos(x, y);
+ int scaledX = x;
+ int scaledY = y;
+
+ int16 currentX = _cursorState.x;
+ int16 currentY = _cursorState.y;
+
+ adjustMousePosition(currentX, currentY);
+
+ // Do not adjust the real screen position, when the current game / overlay
+ // coordinates match the requested coordinates. This avoids a slight
+ // movement which might occur otherwise when the mouse is at a subpixel
+ // position.
+ if (x == currentX && y == currentY)
+ return;
+
+ if (_videoMode.mode == OpenGL::GFX_NORMAL) {
+ if (_videoMode.hardwareWidth != _videoMode.overlayWidth)
+ scaledX = scaledX * _videoMode.hardwareWidth / _videoMode.overlayWidth;
+ if (_videoMode.hardwareHeight != _videoMode.overlayHeight)
+ scaledY = scaledY * _videoMode.hardwareHeight / _videoMode.overlayHeight;
+
+ if (!_overlayVisible) {
+ scaledX *= _videoMode.scaleFactor;
+ scaledY *= _videoMode.scaleFactor;
+ }
+ } else {
+ if (_overlayVisible) {
+ if (_displayWidth != _videoMode.overlayWidth)
+ scaledX = scaledX * _displayWidth / _videoMode.overlayWidth;
+ if (_displayHeight != _videoMode.overlayHeight)
+ scaledY = scaledY * _displayHeight / _videoMode.overlayHeight;
+ } else {
+ if (_displayWidth != _videoMode.screenWidth)
+ scaledX = scaledX * _displayWidth / _videoMode.screenWidth;
+ if (_displayHeight != _videoMode.screenHeight)
+ scaledY = scaledY * _displayHeight / _videoMode.screenHeight;
+ }
+
+ scaledX += _displayX;
+ scaledY += _displayY;
+ }
+
+ setInternalMousePosition(scaledX, scaledY);
+
+ _cursorState.x = scaledX;
+ _cursorState.y = scaledY;
}
void OpenGLGraphicsManager::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
@@ -1249,8 +1289,10 @@ void OpenGLGraphicsManager::adjustMousePosition(int16 &x, int16 &y) {
bool OpenGLGraphicsManager::notifyEvent(const Common::Event &event) {
switch (event.type) {
case Common::EVENT_MOUSEMOVE:
- if (!event.synthetic)
- setMousePos(event.mouse.x, event.mouse.y);
+ if (!event.synthetic) {
+ _cursorState.x = event.mouse.x;
+ _cursorState.y = event.mouse.y;
+ }
case Common::EVENT_LBUTTONDOWN:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_WHEELUP:
diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h
index b4084e8e41..d048c91593 100644
--- a/backends/graphics/opengl/opengl-graphics.h
+++ b/backends/graphics/opengl/opengl-graphics.h
@@ -272,6 +272,15 @@ protected:
virtual void refreshCursor();
virtual void refreshCursorScale();
+
+ /**
+ * Set up the mouse position for the (event) system.
+ *
+ * @param x X coordinate in native coordinates.
+ * @param y Y coordinate in native coordinates.
+ */
+ virtual void setInternalMousePosition(int x, int y) = 0;
+
/**
* Adjusts hardware screen coordinates to either overlay or game screen
* coordinates depending on whether the overlay is visible or not.
@@ -280,7 +289,6 @@ protected:
* @param y Y coordinate of the mouse position.
*/
virtual void adjustMousePosition(int16 &x, int16 &y);
- virtual void setMousePos(int x, int y);
//
// Misc