mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-12-03 06:38:14 +00:00
[client] overlay: move keybinds and config into the overlays
This adds a new `earlyInit` call which allows the overlay to register options before actually being intialized. Also the keybind handling and state tracking for each overlay has been moved internal to the overlay itself.
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "../main.h"
|
||||
|
||||
static bool alert_init(void ** udata, void * params)
|
||||
static bool alert_init(void ** udata, const void * params)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ OverlayConfig;
|
||||
|
||||
static OverlayConfig cfg = { 0 };
|
||||
|
||||
static bool config_init(void ** udata, void * params)
|
||||
static bool config_init(void ** udata, const void * params)
|
||||
{
|
||||
cfg.callbacks = ll_new();
|
||||
if (!cfg.callbacks)
|
||||
|
||||
@@ -22,10 +22,39 @@
|
||||
#include "cimgui.h"
|
||||
#include "overlay_utils.h"
|
||||
|
||||
#include "common/option.h"
|
||||
|
||||
#include "../main.h"
|
||||
|
||||
static bool fps_init(void ** udata, void * params)
|
||||
static bool showFPS;
|
||||
|
||||
static void showFPSKeybind(int sc, void * opaque)
|
||||
{
|
||||
showFPS ^= true;
|
||||
app_invalidateWindow();
|
||||
}
|
||||
|
||||
static void fps_earlyInit(void)
|
||||
{
|
||||
static struct Option options[] =
|
||||
{
|
||||
{
|
||||
.module = "win",
|
||||
.name = "showFPS",
|
||||
.description = "Enable the FPS & UPS display",
|
||||
.shortopt = 'k',
|
||||
.type = OPTION_TYPE_BOOL,
|
||||
.value.x_bool = false,
|
||||
},
|
||||
{ 0 }
|
||||
};
|
||||
option_register(options);
|
||||
}
|
||||
|
||||
static bool fps_init(void ** udata, const void * params)
|
||||
{
|
||||
app_registerKeybind(KEY_D, showFPSKeybind, NULL, "FPS display toggle");
|
||||
showFPS = option_get_bool("win", "showFPS");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -36,7 +65,7 @@ static void fps_free(void * udata)
|
||||
static int fps_render(void * udata, bool interactive, struct Rect * windowRects,
|
||||
int maxRects)
|
||||
{
|
||||
if (!g_state.showFPS)
|
||||
if (!showFPS)
|
||||
return 0;
|
||||
|
||||
ImVec2 pos = {0.0f, 0.0f};
|
||||
@@ -68,6 +97,7 @@ static int fps_render(void * udata, bool interactive, struct Rect * windowRects,
|
||||
struct LG_OverlayOps LGOverlayFPS =
|
||||
{
|
||||
.name = "FPS",
|
||||
.earlyInit = fps_earlyInit,
|
||||
.init = fps_init,
|
||||
.free = fps_free,
|
||||
.render = fps_render
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
struct GraphState
|
||||
{
|
||||
bool show;
|
||||
struct ll * graphs;
|
||||
};
|
||||
|
||||
@@ -46,7 +47,7 @@ struct OverlayGraph
|
||||
|
||||
static void configCallback(void * udata)
|
||||
{
|
||||
igCheckbox("Show Timing Graphs", &g_state.showTiming);
|
||||
igCheckbox("Show Timing Graphs", &gs.show);
|
||||
igSeparator();
|
||||
|
||||
igBeginTable("split", 2, 0, (ImVec2){}, 0);
|
||||
@@ -61,10 +62,18 @@ static void configCallback(void * udata)
|
||||
igEndTable();
|
||||
}
|
||||
|
||||
static bool graphs_init(void ** udata, void * params)
|
||||
static void showTimingKeybind(int sc, void * opaque)
|
||||
{
|
||||
gs.show ^= true;
|
||||
app_invalidateWindow();
|
||||
}
|
||||
|
||||
static bool graphs_init(void ** udata, const void * params)
|
||||
{
|
||||
gs.graphs = ll_new();
|
||||
app_overlayConfigRegister("Performance Metrics", configCallback, NULL);
|
||||
app_registerKeybind(KEY_T, showTimingKeybind, NULL,
|
||||
"Show frame timing information");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -111,7 +120,7 @@ static bool rbCalcMetrics(int index, void * value_, void * udata_)
|
||||
static int graphs_render(void * udata, bool interactive,
|
||||
struct Rect * windowRects, int maxRects)
|
||||
{
|
||||
if (!g_state.showTiming)
|
||||
if (!gs.show)
|
||||
return 0;
|
||||
|
||||
float fontSize = igGetFontSize();
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "../kb.h"
|
||||
#include "../main.h"
|
||||
|
||||
static bool help_init(void ** udata, void * params)
|
||||
static bool help_init(void ** udata, const void * params)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user