aboutsummaryrefslogtreecommitdiff
path: root/backends/platform
diff options
context:
space:
mode:
authorBastien Bouclet2019-11-07 11:02:00 +0100
committerBastien Bouclet2019-11-07 11:02:00 +0100
commit652722e760fab2959c74e2fa65452f334c8b8478 (patch)
tree5c03f9e31bcfe9d73292d66a2eaaaa3738e41de8 /backends/platform
parent6901ee0242c128d3b6026f83a10da4ca90e265e0 (diff)
downloadscummvm-rg350-652722e760fab2959c74e2fa65452f334c8b8478.tar.gz
scummvm-rg350-652722e760fab2959c74e2fa65452f334c8b8478.tar.bz2
scummvm-rg350-652722e760fab2959c74e2fa65452f334c8b8478.zip
3DS: Rework mouse cursor movement
- Fix clipping the cursor position - Ensure the mouse has the same vertical and horizontal speed
Diffstat (limited to 'backends/platform')
-rw-r--r--backends/platform/3ds/osystem-events.cpp35
-rw-r--r--backends/platform/3ds/osystem-graphics.cpp25
-rw-r--r--backends/platform/3ds/osystem.h3
-rw-r--r--backends/platform/3ds/sprite.h8
4 files changed, 43 insertions, 28 deletions
diff --git a/backends/platform/3ds/osystem-events.cpp b/backends/platform/3ds/osystem-events.cpp
index fb30d665a0..1ee550ed66 100644
--- a/backends/platform/3ds/osystem-events.cpp
+++ b/backends/platform/3ds/osystem-events.cpp
@@ -51,8 +51,6 @@ static void eventThreadFunc(void *arg) {
uint32 touchStartTime = osys->getMillis();
touchPosition lastTouch = {0, 0};
bool isRightClick = false;
- float cursorX = 0;
- float cursorY = 0;
float cursorDeltaX = 0;
float cursorDeltaY = 0;
int circleDeadzone = 20;
@@ -93,8 +91,7 @@ static void eventThreadFunc(void *arg) {
if (touch.py > 239 - borderSnapZone)
touch.py = 239;
}
- cursorX = touch.px;
- cursorY = touch.py;
+
osys->transformPoint(touch);
osys->warpMouse(touch.px, touch.py);
@@ -130,16 +127,14 @@ static void eventThreadFunc(void *arg) {
pushEventQueue(eventQueue, event);
}
} else if (cursorDeltaX != 0 || cursorDeltaY != 0) {
- cursorX += cursorDeltaX;
- cursorY -= cursorDeltaY;
- if (cursorX < 0) cursorX = 0;
- if (cursorY < 0) cursorY = 0;
- if (cursorX > 320) cursorX = 320;
- if (cursorY > 240) cursorY = 240;
- lastTouch.px = cursorX;
- lastTouch.py = cursorY;
- osys->transformPoint(lastTouch);
+ float scaleRatio = osys->getScaleRatio();
+
+ lastTouch.px += cursorDeltaX / scaleRatio;
+ lastTouch.py -= cursorDeltaY / scaleRatio;
+
+ osys->clipPoint(lastTouch);
osys->warpMouse(lastTouch.px, lastTouch.py);
+
event.mouse.x = lastTouch.px;
event.mouse.y = lastTouch.py;
event.type = Common::EVENT_MOUSEMOVE;
@@ -312,10 +307,18 @@ void OSystem_3DS::transformPoint(touchPosition &point) {
if (!_overlayVisible) {
point.px = static_cast<float>(point.px) / _gameBottomTexture.getScaleX() - _gameBottomTexture.getPosX();
point.py = static_cast<float>(point.py) / _gameBottomTexture.getScaleY() - _gameBottomTexture.getPosY();
+ }
+
+ clipPoint(point);
+}
+
+void OSystem_3DS::clipPoint(touchPosition &point) {
+ if (_overlayVisible) {
+ point.px = CLIP<uint16>(point.px, 0, getOverlayWidth() - 1);
+ point.py = CLIP<uint16>(point.py, 0, getOverlayHeight() - 1);
} else {
- if (config.screen == kScreenTop) {
- point.px = (uint32) point.px * 400 / 320; // TODO: Fix horizontal speed
- }
+ point.px = CLIP<uint16>(point.px, 0, _gameTopTexture.actualWidth - 1);
+ point.py = CLIP<uint16>(point.py, 0, _gameTopTexture.actualHeight - 1);
}
}
diff --git a/backends/platform/3ds/osystem-graphics.cpp b/backends/platform/3ds/osystem-graphics.cpp
index 8fb92f4d48..c3864c143f 100644
--- a/backends/platform/3ds/osystem-graphics.cpp
+++ b/backends/platform/3ds/osystem-graphics.cpp
@@ -233,6 +233,16 @@ OSystem::TransactionError OSystem_3DS::endGFXTransaction() {
return OSystem::kTransactionSuccess;
}
+float OSystem_3DS::getScaleRatio() const {
+ if (_overlayVisible) {
+ return 1.0;
+ } else if (config.screen == kScreenTop) {
+ return _gameTopTexture.getScaleX();
+ } else {
+ return _gameBottomTexture.getScaleX();
+ }
+}
+
void OSystem_3DS::setPalette(const byte *colors, uint start, uint num) {
assert(start + num <= 256);
memcpy(_palette + 3 * start, colors, 3 * num);
@@ -578,18 +588,17 @@ void OSystem_3DS::warpMouse(int x, int y) {
_cursorY = y;
// TODO: adjust for _cursorScalable ?
- int offsetx = 0;
- int offsety = 0;
x -= _cursorHotspotX;
y -= _cursorHotspotY;
+
+ int offsetx = 0;
+ int offsety = 0;
if (!_overlayVisible) {
- offsetx += config.screen == kScreenTop ? _gameTopX : _gameBottomX;
- offsety += config.screen == kScreenTop ? _gameTopY : _gameBottomY;
+ offsetx = config.screen == kScreenTop ? _gameTopTexture.getPosX() : _gameBottomTexture.getPosX();
+ offsety = config.screen == kScreenTop ? _gameTopTexture.getPosY() : _gameBottomTexture.getPosY();
}
- float scalex = config.screen == kScreenTop ? (float)_gameTopTexture.actualWidth / _gameWidth : 1.f;
- float scaley = config.screen == kScreenTop ? (float)_gameTopTexture.actualHeight / _gameHeight : 1.f;
- _cursorTexture.setPosition(scalex * x + offsetx,
- scaley * y + offsety);
+
+ _cursorTexture.setPosition(x + offsetx, y + offsety);
}
void OSystem_3DS::setCursorDelta(float deltaX, float deltaY) {
diff --git a/backends/platform/3ds/osystem.h b/backends/platform/3ds/osystem.h
index 70cd475cf9..c15c353c24 100644
--- a/backends/platform/3ds/osystem.h
+++ b/backends/platform/3ds/osystem.h
@@ -111,6 +111,7 @@ public:
OSystem::TransactionError endGFXTransaction();
int16 getHeight(){ return _gameHeight; }
int16 getWidth(){ return _gameWidth; }
+ float getScaleRatio() const;
void setPalette(const byte *colors, uint start, uint num);
void grabPalette(byte *colors, uint start, uint num) const;
void copyRectToScreen(const void *buf, int pitch, int x, int y, int w,
@@ -142,6 +143,8 @@ public:
// Transform point from touchscreen coords into gamescreen coords
void transformPoint(touchPosition &point);
+ // Clip point to gamescreen coords
+ void clipPoint(touchPosition &point);
void setCursorDelta(float deltaX, float deltaY);
diff --git a/backends/platform/3ds/sprite.h b/backends/platform/3ds/sprite.h
index a7d8b77842..7bb4d36c3a 100644
--- a/backends/platform/3ds/sprite.h
+++ b/backends/platform/3ds/sprite.h
@@ -54,10 +54,10 @@ public:
void setPosition(int x, int y);
void setOffset(uint16 x, uint16 y);
void setScale(float x, float y);
- float getScaleX(){ return scaleX; }
- float getScaleY(){ return scaleY; }
- int getPosX(){ return posX; }
- int getPosY(){ return posY; }
+ float getScaleX() const { return scaleX; }
+ float getScaleY() const { return scaleY; }
+ int getPosX() const { return posX; }
+ int getPosY() const { return posY; }
C3D_Mtx* getMatrix();
uint16 actualWidth;