From d2c36b8449247e00a97822bd53b1a39d9316e235 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 4 Aug 2021 10:27:47 +1000 Subject: [PATCH] [client] overlay: add new configuration overlay [wip] --- client/CMakeLists.txt | 1 + client/src/main.c | 1 + client/src/overlay/graphs.c | 19 ++++++++++++++++--- client/src/overlays.h | 6 +++++- common/CMakeLists.txt | 1 + common/include/common/types.h | 7 +++++++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index fb5c3773..d3514384 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -118,6 +118,7 @@ set(SOURCES src/overlay/fps.c src/overlay/graphs.c src/overlay/help.c + src/overlay/config.c ) # Force cimgui to build as a static library. diff --git a/client/src/main.c b/client/src/main.c index 8d793431..f6c6abd8 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -825,6 +825,7 @@ static int lg_run(void) app_registerOverlay(&LGOverlayFPS , NULL); app_registerOverlay(&LGOverlayGraphs, NULL); app_registerOverlay(&LGOverlayHelp , NULL); + app_registerOverlay(&LGOverlayConfig, NULL); // initialize metrics ringbuffers g_state.renderTimings = ringbuffer_new(256, sizeof(float)); diff --git a/client/src/overlay/graphs.c b/client/src/overlay/graphs.c index 932476ca..93e773d6 100644 --- a/client/src/overlay/graphs.c +++ b/client/src/overlay/graphs.c @@ -97,13 +97,19 @@ static int graphs_render(void * udata, bool interactive, float fontSize = igGetFontSize(); + GraphHandle graph; + int graphCount = 0; + for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); ) + if (graph->enabled) + ++graphCount; + ImVec2 pos = {0.0f, 0.0f}; igSetNextWindowBgAlpha(0.4f); igSetNextWindowPos(pos, ImGuiCond_FirstUseEver, pos); igSetNextWindowSize( (ImVec2){ 28.0f * fontSize, - 7.0f * fontSize * ll_count(gs.graphs) + 7.0f * fontSize * graphCount }, ImGuiCond_FirstUseEver); @@ -115,10 +121,9 @@ static int graphs_render(void * udata, bool interactive, ImVec2 winSize; igGetContentRegionAvail(&winSize); - const float height = (winSize.y / ll_count(gs.graphs)) + const float height = (winSize.y / graphCount) - igGetStyle()->ItemSpacing.y; - GraphHandle graph; for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); ) { if (!graph->enabled) @@ -179,3 +184,11 @@ void overlayGraph_unregister(GraphHandle handle) { handle->enabled = false; } + +void overlayGraph_iterate(void (*callback)(GraphHandle handle, const char * name, + bool * enabled, void * udata), void * udata) +{ + GraphHandle graph; + for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); ) + callback(graph, graph->name, &graph->enabled, udata); +} diff --git a/client/src/overlays.h b/client/src/overlays.h index 9c3c20ad..6d37d9a9 100644 --- a/client/src/overlays.h +++ b/client/src/overlays.h @@ -27,8 +27,12 @@ extern struct LG_OverlayOps LGOverlayAlert; extern struct LG_OverlayOps LGOverlayFPS; extern struct LG_OverlayOps LGOverlayGraphs; extern struct LG_OverlayOps LGOverlayHelp; +extern struct LG_OverlayOps LGOverlayConfig; -GraphHandle overlayGraph_register(const char * name, RingBuffer buffer, float min, float max); +GraphHandle overlayGraph_register(const char * name, RingBuffer buffer, + float min, float max); void overlayGraph_unregister(); +void overlayGraph_iterate(void (*callback)(GraphHandle handle, const char * name, + bool * enabled, void * udata), void * udata); #endif diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 8f2ceffe..08ca65fb 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -22,6 +22,7 @@ endif() add_subdirectory(src/platform) set(COMMON_SOURCES + src/appstrings.c src/stringutils.c src/stringlist.c src/option.c diff --git a/common/include/common/types.h b/common/include/common/types.h index d067883c..8cb8efa3 100644 --- a/common/include/common/types.h +++ b/common/include/common/types.h @@ -87,4 +87,11 @@ typedef enum CursorType } CursorType; +typedef struct StringPair +{ + const char * name; + const char * value; +} +StringPair; + #endif