From 6fc0c69b2e7979eb4671c881050d08405032bca4 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 12 Jan 2022 09:35:09 +1100 Subject: [PATCH] [client] overlay/msg: provide a method to close messages from code --- client/include/app.h | 4 +++- client/src/app.c | 15 +++++++++++++-- client/src/overlay/msg.c | 12 +++++++++++- client/src/overlays.h | 4 +--- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/client/include/app.h b/client/include/app.h index 1c6db185..128fecc7 100644 --- a/client/include/app.h +++ b/client/include/app.h @@ -134,7 +134,9 @@ void app_clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque); */ void app_alert(LG_MsgAlert type, const char * fmt, ...); -void app_msgBox(const char * caption, const char * fmt, ...); +typedef void * MsgBoxHandle; +MsgBoxHandle app_msgBox(const char * caption, const char * fmt, ...); +void app_msgBoxClose(MsgBoxHandle * handle); typedef struct KeybindHandle * KeybindHandle; typedef void (*KeybindFn)(int sc, void * opaque); diff --git a/client/src/app.c b/client/src/app.c index e8de8f84..7961284c 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -637,14 +637,25 @@ void app_alert(LG_MsgAlert type, const char * fmt, ...) va_end(args); } -void app_msgBox(const char * caption, const char * fmt, ...) +MsgBoxHandle app_msgBox(const char * caption, const char * fmt, ...) { va_list args; va_start(args, fmt); - overlayMsg_show(caption, fmt, args); + MsgBoxHandle handle = + overlayMsg_show(caption, fmt, args); va_end(args); core_updateOverlayState(); + + return handle; +} + +void app_msgBoxClose(MsgBoxHandle * handle) +{ + if (!handle) + return; + + overlayMsg_close(handle); } KeybindHandle app_registerKeybind(int sc, KeybindFn callback, void * opaque, const char * description) diff --git a/client/src/overlay/msg.c b/client/src/overlay/msg.c index bc8e2a21..96c7f42f 100644 --- a/client/src/overlay/msg.c +++ b/client/src/overlay/msg.c @@ -18,6 +18,7 @@ * Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "msg.h" #include "interface/overlay.h" #include "cimgui.h" #include "overlay_utils.h" @@ -148,7 +149,8 @@ bool overlayMsg_modal(void) return ll_count(l_msg.messages) > 0; } -void overlayMsg_show(const char * caption, const char * fmt, va_list args) +MsgBoxHandle overlayMsg_show( + const char * caption, const char * fmt, va_list args) { struct Msg * msg = malloc(sizeof(*msg)); msg->caption = strdup(caption); @@ -174,4 +176,12 @@ void overlayMsg_show(const char * caption, const char * fmt, va_list args) ll_push(l_msg.messages, msg); app_invalidateOverlay(false); + + return (MsgBoxHandle)msg; +} + +void overlayMsg_close(MsgBoxHandle * handle) +{ + if (ll_removeData(l_msg.messages, handle)) + freeMsg((struct Msg *)handle); } diff --git a/client/src/overlays.h b/client/src/overlays.h index e8f6a242..54dd08be 100644 --- a/client/src/overlays.h +++ b/client/src/overlays.h @@ -22,6 +22,7 @@ #define _H_OVERLAYS_H #include "interface/overlay.h" +#include "overlay/msg.h" struct Overlay { @@ -41,9 +42,6 @@ extern struct LG_OverlayOps LGOverlayMsg; void overlayAlert_show(LG_MsgAlert type, const char * fmt, va_list args); -bool overlayMsg_modal(void); -void overlayMsg_show(const char * caption, const char * fmt, va_list args); - GraphHandle overlayGraph_register(const char * name, RingBuffer buffer, float min, float max); void overlayGraph_unregister();