Implement mousewheel vertical scroll and hover in ImGui integration

This commit is contained in:
Henrik Rydgård 2024-11-06 21:27:13 +01:00
parent 673c22a9c4
commit dff7f5704a
5 changed files with 42 additions and 21 deletions

View File

@ -180,6 +180,11 @@ struct KeyInput {
int unicodeChar; // for KEY_CHAR
};
int flags;
// Used by mousewheel events. The delta is packed in the upper 16 bits of flags.
int Delta() const {
return flags >> 16;
}
};
struct AxisInput {

View File

@ -1413,6 +1413,7 @@ bool TriggerButton::Touch(const TouchInput &input) {
down_ |= 1 << input.id;
}
}
if (input.flags & TOUCH_MOVE) {
if (contains)
down_ |= 1 << input.id;

View File

@ -680,7 +680,7 @@ namespace MainWindow
float y = (float)cursorY * g_display.dpi_scale_y;
WindowsRawInput::SetMousePos(x, y);
if (wParam & (MK_LBUTTON | MK_RBUTTON)) {
// Mouse moves now happen also when no button is pressed.
TouchInput touch{};
touch.flags = TOUCH_MOVE | TOUCH_MOUSE;
if (wParam & MK_LBUTTON) {
@ -693,7 +693,6 @@ namespace MainWindow
touch.y = y;
NativeTouch(touch);
}
}
break;
case WM_LBUTTONUP:

View File

@ -156,6 +156,7 @@ namespace WindowsRawInput {
{ VK_OEM_5, NKCODE_BACKSLASH },
{ VK_OEM_6, NKCODE_RIGHT_BRACKET },
{ VK_OEM_7, NKCODE_APOSTROPHE },
{ VK_OEM_8, NKCODE_GRAVE }, // Key left of 1 (above Q) on a lot of layouts.
{ VK_RETURN, NKCODE_ENTER },
{ VK_APPS, NKCODE_MENU }, // Context menu key, let's call this "menu".
{ VK_PAUSE, NKCODE_BREAK },

View File

@ -11,10 +11,25 @@ void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) {
ImGuiIO& io = ImGui::GetIO();
if (key.flags & KEY_DOWN) {
// Specially handle scroll events and any other special keys.
switch (key.keyCode) {
case NKCODE_EXT_MOUSEWHEEL_UP:
io.AddMouseWheelEvent(0, key.Delta() * 0.010f);
break;
case NKCODE_EXT_MOUSEWHEEL_DOWN:
io.AddMouseWheelEvent(0, -key.Delta() * 0.010f);
break;
default:
{
ImGuiKey keyCode = KeyCodeToImGui(key.keyCode);
if (keyCode != ImGuiKey_None) {
if (keyCode == ImGuiKey_None) {
WARN_LOG(Log::System, "Unmapped ImGui keycode conversion from %d", key.keyCode);
} else {
io.AddKeyEvent(keyCode, true);
}
break;
}
}
}
if (key.flags & KEY_UP) {
ImGuiKey keyCode = KeyCodeToImGui(key.keyCode);