mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 08:38:20 +00:00
[client] app: move all alert management into overlay/alert.c
This commit is contained in:
parent
db2e38ae4d
commit
ad6fa5a504
@ -39,8 +39,6 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define ALERT_TIMEOUT 2000000
|
|
||||||
|
|
||||||
bool app_isRunning(void)
|
bool app_isRunning(void)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
@ -552,15 +550,6 @@ void app_handleRenderEvent(const uint64_t timeUs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_state.alertShow)
|
|
||||||
if (g_state.alertTimeout < timeUs)
|
|
||||||
{
|
|
||||||
g_state.alertShow = false;
|
|
||||||
free(g_state.alertMessage);
|
|
||||||
g_state.alertMessage = NULL;
|
|
||||||
invalidate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (invalidate)
|
if (invalidate)
|
||||||
app_invalidateWindow(false);
|
app_invalidateWindow(false);
|
||||||
}
|
}
|
||||||
@ -629,19 +618,11 @@ void app_alert(LG_MsgAlert type, const char * fmt, ...)
|
|||||||
if (!g_state.lgr || !g_params.showAlerts)
|
if (!g_state.lgr || !g_params.showAlerts)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char * buffer;
|
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
valloc_sprintf(&buffer, fmt, args);
|
overlayAlert_show(type, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
free(g_state.alertMessage);
|
|
||||||
g_state.alertMessage = buffer;
|
|
||||||
g_state.alertTimeout = microtime() + ALERT_TIMEOUT;
|
|
||||||
g_state.alertType = type;
|
|
||||||
g_state.alertShow = true;
|
|
||||||
|
|
||||||
g_state.renderImGuiTwice = true;
|
g_state.renderImGuiTwice = true;
|
||||||
app_invalidateWindow(false);
|
app_invalidateWindow(false);
|
||||||
}
|
}
|
||||||
|
@ -63,11 +63,6 @@ struct AppState
|
|||||||
uint64_t lastImGuiFrame;
|
uint64_t lastImGuiFrame;
|
||||||
bool renderImGuiTwice;
|
bool renderImGuiTwice;
|
||||||
|
|
||||||
bool alertShow;
|
|
||||||
char * alertMessage;
|
|
||||||
LG_MsgAlert alertType;
|
|
||||||
uint64_t alertTimeout;
|
|
||||||
|
|
||||||
struct LG_DisplayServerOps * ds;
|
struct LG_DisplayServerOps * ds;
|
||||||
bool dsInitialized;
|
bool dsInitialized;
|
||||||
bool jitRender;
|
bool jitRender;
|
||||||
|
@ -22,8 +22,23 @@
|
|||||||
#include "cimgui.h"
|
#include "cimgui.h"
|
||||||
#include "overlay_utils.h"
|
#include "overlay_utils.h"
|
||||||
|
|
||||||
|
#include "common/stringutils.h"
|
||||||
|
|
||||||
#include "../main.h"
|
#include "../main.h"
|
||||||
|
|
||||||
|
#define ALERT_TIMEOUT (2000 / (1000/25))
|
||||||
|
|
||||||
|
struct AlertState
|
||||||
|
{
|
||||||
|
bool show;
|
||||||
|
char * message;
|
||||||
|
LG_MsgAlert type;
|
||||||
|
uint64_t timeout;
|
||||||
|
bool redraw;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AlertState l_alert = { 0 };
|
||||||
|
|
||||||
static bool alert_init(void ** udata, const void * params)
|
static bool alert_init(void ** udata, const void * params)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@ -31,6 +46,8 @@ static bool alert_init(void ** udata, const void * params)
|
|||||||
|
|
||||||
static void alert_free(void * udata)
|
static void alert_free(void * udata)
|
||||||
{
|
{
|
||||||
|
free(l_alert.message);
|
||||||
|
l_alert.message = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const uint32_t colours[] =
|
static const uint32_t colours[] =
|
||||||
@ -44,14 +61,14 @@ static const uint32_t colours[] =
|
|||||||
static int alert_render(void * udata, bool interactive, struct Rect * windowRects,
|
static int alert_render(void * udata, bool interactive, struct Rect * windowRects,
|
||||||
int maxRects)
|
int maxRects)
|
||||||
{
|
{
|
||||||
if (!g_state.alertShow)
|
if (!l_alert.show)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ImVec2 * screen = overlayGetScreenSize();
|
ImVec2 * screen = overlayGetScreenSize();
|
||||||
igSetNextWindowBgAlpha(0.8f);
|
igSetNextWindowBgAlpha(0.8f);
|
||||||
igSetNextWindowPos((ImVec2) { screen->x / 2.0f, screen->y / 2.0f }, 0,
|
igSetNextWindowPos((ImVec2) { screen->x / 2.0f, screen->y / 2.0f }, 0,
|
||||||
(ImVec2) { 0.5f, 0.5f });
|
(ImVec2) { 0.5f, 0.5f });
|
||||||
igPushStyleColor_U32(ImGuiCol_WindowBg, colours[g_state.alertType]);
|
igPushStyleColor_U32(ImGuiCol_WindowBg, colours[l_alert.type]);
|
||||||
igPushStyleVar_Vec2(ImGuiStyleVar_WindowPadding, (ImVec2) { 4.0f , 4.0f });
|
igPushStyleVar_Vec2(ImGuiStyleVar_WindowPadding, (ImVec2) { 4.0f , 4.0f });
|
||||||
igPushStyleVar_Vec2(ImGuiStyleVar_WindowMinSize, (ImVec2) { 0.0f , 0.0f });
|
igPushStyleVar_Vec2(ImGuiStyleVar_WindowMinSize, (ImVec2) { 0.0f , 0.0f });
|
||||||
|
|
||||||
@ -64,7 +81,7 @@ static int alert_render(void * udata, bool interactive, struct Rect * windowRect
|
|||||||
);
|
);
|
||||||
|
|
||||||
igPushFont(g_state.fontLarge);
|
igPushFont(g_state.fontLarge);
|
||||||
igText("%s", g_state.alertMessage);
|
igText("%s", l_alert.message);
|
||||||
igPopFont();
|
igPopFont();
|
||||||
|
|
||||||
overlayGetImGuiRect(windowRects);
|
overlayGetImGuiRect(windowRects);
|
||||||
@ -76,10 +93,42 @@ static int alert_render(void * udata, bool interactive, struct Rect * windowRect
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool alert_tick(void * udata, unsigned long long tickCount)
|
||||||
|
{
|
||||||
|
if (l_alert.show && l_alert.timeout-- == 0)
|
||||||
|
{
|
||||||
|
l_alert.show = false;
|
||||||
|
l_alert.redraw = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!l_alert.redraw)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
l_alert.redraw = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
struct LG_OverlayOps LGOverlayAlert =
|
struct LG_OverlayOps LGOverlayAlert =
|
||||||
{
|
{
|
||||||
.name = "alert",
|
.name = "alert",
|
||||||
.init = alert_init,
|
.init = alert_init,
|
||||||
.free = alert_free,
|
.free = alert_free,
|
||||||
.render = alert_render
|
.render = alert_render,
|
||||||
|
.tick = alert_tick,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void overlayAlert_show(LG_MsgAlert type, const char * fmt, va_list args)
|
||||||
|
{
|
||||||
|
if (!g_state.lgr || !g_params.showAlerts)
|
||||||
|
return;
|
||||||
|
|
||||||
|
char * buffer;
|
||||||
|
valloc_sprintf(&buffer, fmt, args);
|
||||||
|
|
||||||
|
free(l_alert.message);
|
||||||
|
l_alert.message = buffer;
|
||||||
|
l_alert.timeout = ALERT_TIMEOUT;
|
||||||
|
l_alert.type = type;
|
||||||
|
l_alert.show = true;
|
||||||
|
l_alert.redraw = true;
|
||||||
|
}
|
||||||
|
@ -38,6 +38,8 @@ extern struct LG_OverlayOps LGOverlayGraphs;
|
|||||||
extern struct LG_OverlayOps LGOverlayHelp;
|
extern struct LG_OverlayOps LGOverlayHelp;
|
||||||
extern struct LG_OverlayOps LGOverlayConfig;
|
extern struct LG_OverlayOps LGOverlayConfig;
|
||||||
|
|
||||||
|
void overlayAlert_show(LG_MsgAlert type, const char * fmt, va_list args);
|
||||||
|
|
||||||
GraphHandle overlayGraph_register(const char * name, RingBuffer buffer,
|
GraphHandle overlayGraph_register(const char * name, RingBuffer buffer,
|
||||||
float min, float max);
|
float min, float max);
|
||||||
void overlayGraph_unregister();
|
void overlayGraph_unregister();
|
||||||
|
Loading…
Reference in New Issue
Block a user