Skip to content
Permalink
Browse files

3DS: Rework mouse cursor movement

- Fix clipping the cursor position
- Ensure the mouse has the same vertical and horizontal speed

(cherry picked from commit 652722e)
  • Loading branch information...
bgK committed Nov 7, 2019
1 parent 01876ad commit f89ecdc149de8d31e0ee12d3d4e815ddb8e6f752
@@ -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);
}
}

@@ -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) {
@@ -111,6 +111,7 @@ class OSystem_3DS : public EventsBaseBackend, public PaletteManager {
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 @@ class OSystem_3DS : public EventsBaseBackend, public PaletteManager {

// 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);

@@ -54,10 +54,10 @@ class Sprite : public Graphics::Surface {
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;

0 comments on commit f89ecdc

Please sign in to comment.
You can’t perform that action at this time.