[client] imgui: ask display server to display cursors

This commit is contained in:
Quantum 2021-07-29 17:36:28 -04:00 committed by Geoffrey McRae
parent 11a5864969
commit 0402dd521a
4 changed files with 49 additions and 6 deletions

View File

@ -661,6 +661,35 @@ static inline void mergeRect(struct Rect * dest, const struct Rect * a, const st
dest->h = y2 - dest->y; dest->h = y2 - dest->y;
} }
static inline LG_DSPointer mapImGuiCursor(ImGuiMouseCursor cursor)
{
switch (cursor)
{
case ImGuiMouseCursor_None:
return LG_POINTER_NONE;
case ImGuiMouseCursor_Arrow:
return LG_POINTER_ARROW;
case ImGuiMouseCursor_TextInput:
return LG_POINTER_INPUT;
case ImGuiMouseCursor_ResizeAll:
return LG_POINTER_MOVE;
case ImGuiMouseCursor_ResizeNS:
return LG_POINTER_RESIZE_NS;
case ImGuiMouseCursor_ResizeEW:
return LG_POINTER_RESIZE_EW;
case ImGuiMouseCursor_ResizeNESW:
return LG_POINTER_RESIZE_NESW;
case ImGuiMouseCursor_ResizeNWSE:
return LG_POINTER_RESIZE_NWSE;
case ImGuiMouseCursor_Hand:
return LG_POINTER_HAND;
case ImGuiMouseCursor_NotAllowed:
return LG_POINTER_NOT_ALLOWED;
default:
return LG_POINTER_ARROW;
}
}
int app_renderOverlay(struct Rect * rects, int maxRects) int app_renderOverlay(struct Rect * rects, int maxRects)
{ {
int totalRects = 0; int totalRects = 0;
@ -675,6 +704,16 @@ int app_renderOverlay(struct Rect * rects, int maxRects)
totalDamage = true; totalDamage = true;
ImDrawList_AddRectFilled(igGetBackgroundDrawListNil(), (ImVec2) { 0.0f , 0.0f }, ImDrawList_AddRectFilled(igGetBackgroundDrawListNil(), (ImVec2) { 0.0f , 0.0f },
g_state.io->DisplaySize, 0xCC000000, 0, 0); g_state.io->DisplaySize, 0xCC000000, 0, 0);
bool test;
igShowDemoWindow(&test);
ImGuiMouseCursor cursor = igGetMouseCursor();
if (cursor != g_state.cursorLast)
{
g_state.ds->setPointer(mapImGuiCursor(cursor));
g_state.cursorLast = cursor;
}
} }
// render the overlays // render the overlays

View File

@ -136,6 +136,7 @@ static void bind_passthrough(int sc, void * opaque)
static void bind_toggleOverlay(int sc, void * opaque) static void bind_toggleOverlay(int sc, void * opaque)
{ {
g_state.overlayInput ^= true; g_state.overlayInput ^= true;
g_state.cursorLast = -2;
if (g_state.overlayInput) if (g_state.overlayInput)
{ {
g_state.io->ConfigFlags &= ~ImGuiConfigFlags_NoMouse; g_state.io->ConfigFlags &= ~ImGuiConfigFlags_NoMouse;

View File

@ -780,6 +780,8 @@ static int lg_run(void)
g_state.io = igGetIO(); g_state.io = igGetIO();
g_state.style = igGetStyle(); g_state.style = igGetStyle();
g_state.io->BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
g_state.windowScale = 1.0; g_state.windowScale = 1.0;
g_state.fontName = util_getUIFont(g_params.uiFont); g_state.fontName = util_getUIFont(g_params.uiFont);
DEBUG_INFO("Using font: %s", g_state.fontName); DEBUG_INFO("Using font: %s", g_state.fontName);

View File

@ -48,12 +48,13 @@ struct AppState
{ {
enum RunState state; enum RunState state;
ImGuiIO * io; ImGuiIO * io;
ImGuiStyle * style; ImGuiStyle * style;
struct ll * overlays; struct ll * overlays;
char * fontName; char * fontName;
ImFont * fontLarge; ImFont * fontLarge;
bool overlayInput; bool overlayInput;
ImGuiMouseCursor cursorLast;
bool alertShow; bool alertShow;
char * alertMessage; char * alertMessage;