Merge pull request #225 from wheremyfoodat/tsc
[Touchscreen] Properly handle "dragging" stylus across screen
This commit is contained in:
@@ -142,4 +142,6 @@ class HIDService {
|
|||||||
void releaseTouchScreen() {
|
void releaseTouchScreen() {
|
||||||
touchScreenPressed = false;
|
touchScreenPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isTouchScreenPressed() { return touchScreenPressed; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -316,19 +316,36 @@ void Emulator::run() {
|
|||||||
|
|
||||||
// Detect mouse motion events for gyroscope emulation
|
// Detect mouse motion events for gyroscope emulation
|
||||||
case SDL_MOUSEMOTION: {
|
case SDL_MOUSEMOTION: {
|
||||||
|
if (romType == ROMType::None) break;
|
||||||
|
|
||||||
|
// Handle "dragging" across the touchscreen
|
||||||
|
if (hid.isTouchScreenPressed()) {
|
||||||
|
const s32 x = event.motion.x;
|
||||||
|
const s32 y = event.motion.y;
|
||||||
|
|
||||||
|
// Check if touch falls in the touch screen area and register the new touch screen position
|
||||||
|
if (y >= 240 && y <= 480 && x >= 40 && x < 40 + 320) {
|
||||||
|
// Convert to 3DS coordinates
|
||||||
|
u16 x_converted = static_cast<u16>(x) - 40;
|
||||||
|
u16 y_converted = static_cast<u16>(y) - 240;
|
||||||
|
|
||||||
|
hid.setTouchScreenPress(x_converted, y_converted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We use right click to indicate we want to rotate the console. If right click is not held, then this is not a gyroscope rotation
|
// We use right click to indicate we want to rotate the console. If right click is not held, then this is not a gyroscope rotation
|
||||||
if (romType == ROMType::None || !holdingRightClick) break;
|
if (holdingRightClick) {
|
||||||
|
// Relative motion since last mouse motion event
|
||||||
|
const s32 motionX = event.motion.xrel;
|
||||||
|
const s32 motionY = event.motion.yrel;
|
||||||
|
|
||||||
// Relative motion since last mouse motion event
|
// The gyroscope involves lots of weird math I don't want to bother with atm
|
||||||
const s32 motionX = event.motion.xrel;
|
// So up until then, we will set the gyroscope euler angles to fixed values based on the direction of the relative motion
|
||||||
const s32 motionY = event.motion.yrel;
|
const s32 roll = motionX > 0 ? 0x7f : -0x7f;
|
||||||
|
const s32 pitch = motionY > 0 ? 0x7f : -0x7f;
|
||||||
// The gyroscope involves lots of weird math I don't want to bother with atm
|
hid.setRoll(roll);
|
||||||
// So up until then, we will set the gyroscope euler angles to fixed values based on the direction of the relative motion
|
hid.setPitch(pitch);
|
||||||
const s32 roll = motionX > 0 ? 0x7f : -0x7f;
|
}
|
||||||
const s32 pitch = motionY > 0 ? 0x7f : -0x7f;
|
|
||||||
hid.setRoll(roll);
|
|
||||||
hid.setPitch(pitch);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user