[client] imgui: add mode to forward mouse input to imgui

This commit is contained in:
Quantum
2021-07-26 17:27:47 -04:00
committed by Geoffrey McRae
parent 6c64965703
commit 065d90c3f7
3 changed files with 59 additions and 6 deletions

View File

@@ -68,6 +68,9 @@ void app_updateCursorPos(double x, double y)
g_cursor.pos.x = x;
g_cursor.pos.y = y;
g_cursor.valid = true;
if (g_state.overlayInput)
g_state.io->MousePos = (ImVec2) { x * g_state.windowScale, y * g_state.windowScale };
}
void app_handleFocusEvent(bool focused)
@@ -214,10 +217,34 @@ void spiceClipboardNotice(const SpiceDataType type)
g_state.ds->cbNotice(cb_spiceTypeToLGType(type));
}
static int mapSpiceToImGuiButton(uint32_t button)
{
switch (button)
{
case 1: // SPICE_MOUSE_BUTTON_LEFT
return ImGuiMouseButton_Left;
case 2: // SPICE_MOUSE_BUTTON_MIDDLE
return ImGuiMouseButton_Middle;
case 3: // SPICE_MOUSE_BUTTON_RIGHT
return ImGuiMouseButton_Right;
}
return -1;
}
void app_handleButtonPress(int button)
{
g_cursor.buttons |= (1U << button);
if (g_state.overlayInput)
{
int igButton = mapSpiceToImGuiButton(button);
if (igButton != -1)
g_state.io->MouseDown[igButton] = true;
if (g_state.io->WantCaptureMouse)
return;
}
if (!core_inputEnabled() || !g_cursor.inView)
return;
@@ -229,6 +256,15 @@ void app_handleButtonRelease(int button)
{
g_cursor.buttons &= ~(1U << button);
if (g_state.overlayInput)
{
int igButton = mapSpiceToImGuiButton(button);
if (igButton != -1)
g_state.io->MouseDown[igButton] = false;
if (g_state.io->WantCaptureMouse)
return;
}
if (!core_inputEnabled())
return;