Skip to content

Commit

Permalink
Cleanup, add right-click support to UI framework
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Nov 5, 2024
1 parent caf27a5 commit 19f4b22
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 17 deletions.
4 changes: 3 additions & 1 deletion Common/Input/InputState.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ enum {
TOUCH_UP = 1 << 2,
TOUCH_CANCEL = 1 << 3, // Sent by scrollviews to their children when they detect a scroll
TOUCH_WHEEL = 1 << 4, // Scrollwheel event. Usually only affects Y but can potentially affect X.
TOUCH_MOUSE = 1 << 5, // Identifies that this touch event came from a mouse
TOUCH_MOUSE = 1 << 5, // Identifies that this touch event came from a mouse. Id is now set to the mouse button for DOWN/UP commands.
TOUCH_RELEASE_ALL = 1 << 6, // Useful for app focus switches when events may be lost.
TOUCH_HOVER = 1 << 7,

// These are the Android getToolType() codes, shifted by 10.
TOUCH_TOOL_MASK = 7 << 10,
Expand All @@ -153,6 +154,7 @@ struct TouchInput {
float x;
float y;
int id; // Needs to be <= GestureDetector::MAX_PTRS (10.)
int buttons; // bit mask
int flags;
double timestamp;
};
Expand Down
5 changes: 5 additions & 0 deletions Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ bool Clickable::Touch(const TouchInput &input) {
return contains;
}

// Ignore buttons other than the left one.
if ((input.flags & TOUCH_MOUSE) && input.id != 0) {
return contains;
}

if (input.flags & TOUCH_DOWN) {
if (bounds_.Contains(input.x, input.y)) {
if (IsFocusMovementEnabled())
Expand Down
7 changes: 3 additions & 4 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,15 +954,14 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) {
if (UI::IsFocusMovementEnabled() || (imguiVisible_ && imguiInited_)) {
// Note: Allow some Vkeys through, so we can toggle the imgui for example (since we actually block the control mapper otherwise in imgui mode).
// We need to manually implement it here :/
if (imguiVisible_ && imguiInited_ && (key.flags & KEY_DOWN)) {
if (imguiVisible_ && imguiInited_) {
InputMapping mapping(key.deviceId, key.keyCode);
std::vector<int> pspButtons;
bool mappingFound = KeyMap::InputMappingToPspButton(mapping, &pspButtons);
if (mappingFound) {
for (auto b : pspButtons) {
if (b == VIRTKEY_TOGGLE_DEBUGGER) {
imguiVisible_ = false;
return true;
if (b == VIRTKEY_TOGGLE_DEBUGGER || b == VIRTKEY_PAUSE) {
return controlMapper_.Key(key, &pauseTrigger_);
}
}
}
Expand Down
53 changes: 43 additions & 10 deletions Windows/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,9 @@ namespace MainWindow
float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
WindowsRawInput::SetMousePos(x, y);

TouchInput touch;
touch.id = 0;
touch.flags = TOUCH_DOWN;
TouchInput touch{};
touch.flags = TOUCH_DOWN | TOUCH_MOUSE;
touch.buttons = 1;
touch.x = x;
touch.y = y;
NativeTouch(touch);
Expand Down Expand Up @@ -680,10 +680,15 @@ namespace MainWindow
float y = (float)cursorY * g_display.dpi_scale_y;
WindowsRawInput::SetMousePos(x, y);

if (wParam & MK_LBUTTON) {
TouchInput touch;
touch.id = 0;
touch.flags = TOUCH_MOVE;
if (wParam & (MK_LBUTTON | MK_RBUTTON)) {
TouchInput touch{};
touch.flags = TOUCH_MOVE | TOUCH_MOUSE;
if (wParam & MK_LBUTTON) {
touch.buttons |= 1;
}
if (wParam & MK_RBUTTON) {
touch.buttons |= 2;
}
touch.x = x;
touch.y = y;
NativeTouch(touch);
Expand All @@ -702,9 +707,9 @@ namespace MainWindow
float y = (float)GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
WindowsRawInput::SetMousePos(x, y);

TouchInput touch;
touch.id = 0;
touch.flags = TOUCH_UP;
TouchInput touch{};
touch.buttons = 1;
touch.flags = TOUCH_UP | TOUCH_MOUSE;
touch.x = x;
touch.y = y;
NativeTouch(touch);
Expand All @@ -716,6 +721,34 @@ namespace MainWindow
touchHandler.handleTouchEvent(hWnd, message, wParam, lParam);
return 0;

case WM_RBUTTONDOWN:
{
float x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;

TouchInput touch{};
touch.buttons = 2;
touch.flags = TOUCH_DOWN | TOUCH_MOUSE;
touch.x = x;
touch.y = y;
NativeTouch(touch);
break;
}

case WM_RBUTTONUP:
{
float x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;

TouchInput touch{};
touch.buttons = 2;
touch.flags = TOUCH_UP | TOUCH_MOUSE;
touch.x = x;
touch.y = y;
NativeTouch(touch);
break;
}

default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
Expand Down
10 changes: 8 additions & 2 deletions ext/imgui/imgui_impl_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ void ImGui_ImplPlatform_TouchEvent(const TouchInput &touch) {
}
if (touch.flags & TOUCH_DOWN) {
io.AddMousePosEvent(x, y);
io.AddMouseButtonEvent(0, true);
if (touch.buttons & 1)
io.AddMouseButtonEvent(0, true);
if (touch.buttons & 2)
io.AddMouseButtonEvent(1, true);
}
if (touch.flags & TOUCH_UP) {
io.AddMousePosEvent(x, y);
io.AddMouseButtonEvent(0, false);
if (touch.buttons & 1)
io.AddMouseButtonEvent(0, false);
if (touch.buttons & 2)
io.AddMouseButtonEvent(1, false);
}
}

Expand Down

0 comments on commit 19f4b22

Please sign in to comment.