Brenta Engine 1.2
Loading...
Searching...
No Matches
gui.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#ifndef BRENTA_NO_IMGUI
9
10#include <brenta/subsystem.hpp>
11
12#include <imgui.h>
13#include <imgui_impl_glfw.h>
14#include <imgui_impl_opengl3.h>
15
16#include <filesystem>
17
18class ImFont;
19
20namespace brenta
21{
22
23class FrameBuffer;
24
25//
26// Gui class
27// ---------
28//
29// This class contains some utilities for working with GUI. It's a
30// wrapper around imgui, providing common functions to initialize,
31// update and delete the gui. This is not meant to be a replacement
32// for ImGui's API, but a shortcut to some some common operations
33// that may take many keystrokes to type out.
34//
35class Gui : public Subsystem
36{
37public:
38
39 class Builder;
40
41 // Subsystem interface
42 static const std::string subsystem_name;
43 std::expected<void, Subsystem::Error> initialize() override;
44 std::expected<void, Subsystem::Error> terminate() override;
45 std::string name() override;
46 bool is_initialized() override;
47
48 // Member functions
49
50 static Gui &instance();
51
52 static void new_frame(tenno::shared_ptr<FrameBuffer> fb,
53 std::string name = "Game");
54 static void render();
55 static void load_font(const std::filesystem::path &path = "examples/assets/fonts/Inconsolata-Regular.ttf",
56 float size = 25.0f);
57 static void push_font(ImFont* f = font);
58 static void pop_font();
59 static void debug_stats();
60
61private:
62
63 static bool initialized;
64 static ImFont *font;
65
66 // Private constructors / destructors for singleton
67 Gui() = default;
68 ~Gui() = default;
69
70};
71
73{
74public:
75
76 Builder() = default;
77 ~Builder() = default;
78
79 brenta::Subsystem &build() override;
80
81};
82
83} // namespace brenta
84
85#endif // BRENTA_NO_IMGUI