Skip to content

Commit

Permalink
Add scroll bars to the virtual mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyjodon committed May 27, 2024
1 parent fbb9c1d commit 8395b14
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Binary file modified 3ds/gfx/touchpad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 18 additions & 3 deletions src/input/n3ds/MouseTouchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void MouseTouchHandler::_handle_touch_down(touchPosition touch) {
if (touch.py < 175) {
previous_x = touch.px;
previous_y = touch.py;
if (touch.px > 285) {
v_scroll = true;
} else if (touch.py < 35) {
h_scroll = true;
}
} else if (touch.px > 160) {
mouse_button = BUTTON_RIGHT;
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_RIGHT);
Expand All @@ -53,15 +58,25 @@ void MouseTouchHandler::_handle_touch_up(touchPosition touch) {
mouse_button = -1;
previous_x = -1;
previous_y = -1;
v_scroll = false;
h_scroll = false;
}

void MouseTouchHandler::_handle_touch_hold(touchPosition touch) {
if (previous_x == -1) {
return;
}
short deltaX = N3DS_MOUSEPAD_SENSITIVITY * (touch.px - previous_x);
short deltaY = N3DS_MOUSEPAD_SENSITIVITY * (touch.py - previous_y);
short deltaX = touch.px - previous_x;
short deltaY = touch.py - previous_y;
previous_x = touch.px;
previous_y = touch.py;
LiSendMouseMoveEvent(deltaX, deltaY);

if (v_scroll) {
LiSendScrollEvent(-1 * deltaY);
} else if (h_scroll) {
LiSendHScrollEvent(deltaX);
} else {
LiSendMouseMoveEvent(N3DS_MOUSEPAD_SENSITIVITY * deltaX,
N3DS_MOUSEPAD_SENSITIVITY * deltaY);
}
}
2 changes: 2 additions & 0 deletions src/input/n3ds/N3dsTouchscreenInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class MouseTouchHandler : public TouchHandlerBase {
int mouse_button = -1;
int previous_x = 0;
int previous_y = 0;
bool v_scroll = false;
bool h_scroll = false;
};

enum KeyState { KEY_DISABLED, KEY_TEMPORARY, KEY_LOCKED, KEY_SHIFT };
Expand Down

0 comments on commit 8395b14

Please sign in to comment.