diff --git a/client/include/overlay_utils.h b/client/include/overlay_utils.h index d0c93e74..18916c91 100644 --- a/client/include/overlay_utils.h +++ b/client/include/overlay_utils.h @@ -21,11 +21,15 @@ #ifndef _H_LG_OVERLAY_UTILS_ #define _H_LG_OVERLAY_UTILS_ +#include + #include "common/types.h" typedef struct ImVec2 ImVec2; void overlayGetImGuiRect(struct Rect * rect); ImVec2 * overlayGetScreenSize(void); +void overlayTextURL(const char * url, const char * text); +void overlayTextMaybeURL(const char * text, bool wrapped); #endif diff --git a/client/src/overlay_utils.c b/client/src/overlay_utils.c index 7bc06afc..95130178 100644 --- a/client/src/overlay_utils.c +++ b/client/src/overlay_utils.c @@ -20,6 +20,9 @@ #include "overlay_utils.h" +#include + +#include "common/open.h" #include "cimgui.h" #include "main.h" @@ -41,3 +44,36 @@ ImVec2 * overlayGetScreenSize(void) { return &g_state.io->DisplaySize; } + +static void overlayAddUnderline(ImU32 color) +{ + ImVec2 min, max; + igGetItemRectMin(&min); + igGetItemRectMax(&max); + min.y = max.y; + ImDrawList_AddLine(igGetWindowDrawList(), min, max, color, 1.0f); +} + +void overlayTextURL(const char * url, const char * text) +{ + igText(text ? text : url); + + if (igIsItemHovered(ImGuiHoveredFlags_None)) + { + if (igIsItemClicked(ImGuiMouseButton_Left)) + lgOpenURL(url); + overlayAddUnderline(igGetColorU32Vec4(*igGetStyleColorVec4(ImGuiCol_ButtonHovered))); + igSetMouseCursor(ImGuiMouseCursor_Hand); + igSetTooltip("Open in browser: %s", url); + } +} + +void overlayTextMaybeURL(const char * text, bool wrapped) +{ + if (strncmp(text, "https://", 8) == 0) + overlayTextURL(text, NULL); + else if (wrapped) + igTextWrapped(text); + else + igText(text); +}