diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 6f767a08..1a6c47e3 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -141,6 +141,7 @@ set(SOURCES src/overlay/help.c src/overlay/config.c src/overlay/msg.c + src/overlay/record.c ) # Force cimgui to build as a static library. diff --git a/client/include/app.h b/client/include/app.h index 9143e02e..1d868461 100644 --- a/client/include/app.h +++ b/client/include/app.h @@ -150,6 +150,8 @@ void app_msgBoxClose(MsgBoxHandle handle); typedef struct KeybindHandle * KeybindHandle; typedef void (*KeybindFn)(int sc, void * opaque); +void app_showRecord(bool show); + /** * Register a handler for the + combination * @param sc The scancode to register diff --git a/client/src/app.c b/client/src/app.c index be050bf8..e894309c 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -673,6 +673,11 @@ void app_msgBoxClose(MsgBoxHandle handle) overlayMsg_close(handle); } +void app_showRecord(bool show) +{ + overlayRecord_show(show); +} + KeybindHandle app_registerKeybind(int sc, KeybindFn callback, void * opaque, const char * description) { // don't allow duplicate binds diff --git a/client/src/main.c b/client/src/main.c index 9f099355..92e912b3 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -1647,6 +1647,7 @@ int main(int argc, char * argv[]) app_registerOverlay(&LGOverlayGraphs, NULL); app_registerOverlay(&LGOverlayHelp , NULL); app_registerOverlay(&LGOverlayMsg , NULL); + app_registerOverlay(&LGOverlayRecord, NULL); // early renderer setup for option registration diff --git a/client/src/overlay/record.c b/client/src/overlay/record.c new file mode 100644 index 00000000..4155fb61 --- /dev/null +++ b/client/src/overlay/record.c @@ -0,0 +1,86 @@ +/** + * Looking Glass + * Copyright © 2017-2022 The Looking Glass Authors + * https://looking-glass.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "interface/overlay.h" +#include "cimgui.h" +#include "overlay_utils.h" + +#include "common/stringutils.h" + +#include "../main.h" + +static bool recordShow = false; +static bool recordToggle = false; +static unsigned long long lastTick = 0; + +static bool record_init(void ** udata, const void * params) +{ + return true; +} + +static void record_free(void * udata) +{} + +static int record_render(void * udata, bool interactive, struct Rect * windowRects, + int maxRects) +{ + if (!recordShow || !recordToggle) + return 0; + + ImVec2 * screen = overlayGetScreenSize(); + ImDrawList_AddCircleFilled(igGetBackgroundDrawList_Nil(), + (ImVec2) { screen->x - 20.0f, 20.0f }, + 5.0f, 0xFF0000FF, 0 + ); + + *windowRects = (struct Rect) { + .x = screen->x - 26, .y = 14, .w = 12, .h = 12 + }; + return 1; +} + +static bool record_tick(void * udata, unsigned long long tickCount) +{ + if (tickCount - lastTick >= 25) + { + recordToggle = !recordToggle; + lastTick = tickCount; + return true; + } + return false; +} + +struct LG_OverlayOps LGOverlayRecord = +{ + .name = "record", + .init = record_init, + .free = record_free, + .render = record_render, + .tick = record_tick, +}; + +void overlayRecord_show(bool show) +{ + if (show == recordShow) + return; + + recordShow = show; + app_invalidateOverlay(true); +} diff --git a/client/src/overlays.h b/client/src/overlays.h index 0bc63e7d..af089c57 100644 --- a/client/src/overlays.h +++ b/client/src/overlays.h @@ -39,6 +39,7 @@ extern struct LG_OverlayOps LGOverlayGraphs; extern struct LG_OverlayOps LGOverlayHelp; extern struct LG_OverlayOps LGOverlayConfig; extern struct LG_OverlayOps LGOverlayMsg; +extern struct LG_OverlayOps LGOverlayRecord; void overlayAlert_show(LG_MsgAlert type, const char * fmt, va_list args); @@ -55,4 +56,6 @@ void overlayConfig_register(const char * title, void overlayConfig_registerTab(const char * title, void (*callback)(void * udata, int * id), void * udata); +void overlayRecord_show(bool show); + #endif