mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-14 03:20:22 +00:00
[client] app: implement new overlay rendering framework
This change set implements a framework for overlays to be registered that make use of ImGui. See `overlay/fps` for a simple implementation example.
This commit is contained in:
79
client/src/overlay/fps.c
Normal file
79
client/src/overlay/fps.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright (C) 2017-2021 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 "../main.h"
|
||||
|
||||
static bool fps_init(void ** udata, void * params)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static void fps_free(void * udata)
|
||||
{
|
||||
}
|
||||
|
||||
static int fps_getWindowCount(void * udata, bool interactive)
|
||||
{
|
||||
return g_state.showFPS ? 1 : 0;
|
||||
}
|
||||
|
||||
static void fps_render(void * udata, bool interactive, struct Rect * windowRects)
|
||||
{
|
||||
const ImVec2 pos = {0.0f, 0.0f};
|
||||
igSetNextWindowBgAlpha(0.6f);
|
||||
igSetNextWindowPos(pos, 0, pos);
|
||||
|
||||
igBegin(
|
||||
"FPS",
|
||||
NULL,
|
||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
|
||||
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing |
|
||||
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoTitleBar
|
||||
);
|
||||
|
||||
igText("FPS:%4.2f UPS:%4.2f",
|
||||
atomic_load_explicit(&g_state.fps, memory_order_relaxed),
|
||||
atomic_load_explicit(&g_state.ups, memory_order_relaxed));
|
||||
|
||||
if (windowRects)
|
||||
{
|
||||
ImVec2 pos, size;
|
||||
igGetWindowPos(&pos);
|
||||
igGetWindowSize(&size);
|
||||
windowRects[0].x = pos.x;
|
||||
windowRects[0].y = pos.y;
|
||||
windowRects[0].w = size.x;
|
||||
windowRects[0].h = size.y;
|
||||
}
|
||||
|
||||
igEnd();
|
||||
}
|
||||
|
||||
struct LG_OverlayOps LGOverlayFPS =
|
||||
{
|
||||
.name = "FPS",
|
||||
.init = fps_init,
|
||||
.free = fps_free,
|
||||
.getWindowCount = fps_getWindowCount,
|
||||
.render = fps_render
|
||||
};
|
Reference in New Issue
Block a user