Shkyera Engine
Easy to use, game engine for Python
UI.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <memory>
10 #include <vector>
11 
12 #include "imgui.h"
13 #include <GLFW/glfw3.h>
14 
15 #include "game/Game.hpp"
16 #include "renderer/Renderer.hpp"
17 #include "ui/Widget.hpp"
18 
19 namespace shkyera {
20 
26 class UI {
27  public:
33  UI(std::shared_ptr<Game> game);
34 
38  void initialize();
39 
43  void draw();
44 
48  void close();
49 
55  bool shouldClose() const;
56 
57  /******** FONTS ********/
58  static ImFont *NORMAL_FONT;
59  static ImFont *BIG_FONT;
60  static ImFont *HUGE_FONT;
61  static ImFont *SMALL_FONT;
62 
63  /******** COLORS *********/
64  inline static ImVec4 BACKGROUND_COLOR = ImVec4(0.17f, 0.17f, 0.17f, 1.0f);
65  inline static ImVec4 TEXT_COLOR = ImVec4(0.86f, 0.86f, 0.86f, 1.0f);
66  inline static ImVec4 DISABLED_TEXT_COLOR = ImVec4(0.86f, 0.93f, 0.89f, 0.28f);
67  inline static ImVec4 ACCENT_COLOR = ImVec4(0.4f, 0.05f, 0.7f, 1.0f);
68  inline static ImVec4 STRONG_ACCENT_COLOR = ImVec4(0.5f, 0.06f, 0.82f, 1.0f);
69  inline static ImVec4 GREY = ImVec4(0.3f, 0.3f, 0.3f, 1.0f);
70  inline static ImVec4 LIGHT_GREY = ImVec4(0.8f, 0.8f, 0.8f, 1.0f);
71  inline static ImVec4 DARK_ACCENT = ImVec4(0.1f, 0.1f, 0.1f, 1.0f);
72  inline static ImVec4 BLACK = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
73 
74  private:
78  void initializeImgui();
79 
83  void initializeWidgets();
84 
88  void initializeAssets();
89 
93  void initializeInterpreter();
94 
98  void styleImgui();
99 
103  void beginFrame();
104 
108  void renderFrame();
109 
113  void endFrame();
114 
115  std::shared_ptr<Game> _game;
116  std::shared_ptr<Renderer> _renderer;
117 
118  bool _open;
119  GLFWwindow *_window;
120 
121  std::vector<std::unique_ptr<Widget>> _widgets;
122 };
123 
124 } // namespace shkyera
Contains the declaration of the Game class, representing the game environment.
Contains the declaration of the Widget class, an abstract base class for GUI widgets.
A class responsible for managing the user interface (UI) of the application.
Definition: UI.hpp:26
std::vector< std::unique_ptr< Widget > > _widgets
A collection of UI widgets.
Definition: UI.hpp:121
static ImFont * BIG_FONT
A larger font used in the UI.
Definition: UI.hpp:59
void draw()
Render the UI.
Definition: UI.cpp:307
static ImVec4 DISABLED_TEXT_COLOR
Disabled text color.
Definition: UI.hpp:66
bool _open
Flag indicating if the UI is open.
Definition: UI.hpp:118
static ImFont * SMALL_FONT
A smaller font used in the UI.
Definition: UI.hpp:61
void initializeImgui()
Initialize ImGui and other UI elements.
Definition: UI.cpp:43
void styleImgui()
Apply styling to ImGui elements.
Definition: UI.cpp:133
static ImFont * NORMAL_FONT
The normal font used in the UI.
Definition: UI.hpp:58
static ImVec4 DARK_ACCENT
Dark accent color.
Definition: UI.hpp:71
static ImFont * HUGE_FONT
An even larger font used in the UI.
Definition: UI.hpp:60
static ImVec4 LIGHT_GREY
Light grey color.
Definition: UI.hpp:70
static ImVec4 STRONG_ACCENT_COLOR
Strong accent color.
Definition: UI.hpp:68
bool shouldClose() const
Check if the UI should be closed.
Definition: UI.cpp:327
static ImVec4 ACCENT_COLOR
Accent color.
Definition: UI.hpp:67
void initializeInterpreter()
Initialize the Python interpreter.
Definition: UI.cpp:131
std::shared_ptr< Renderer > _renderer
A shared pointer to the renderer.
Definition: UI.hpp:116
void beginFrame()
Begin a UI frame.
Definition: UI.cpp:209
static ImVec4 GREY
Grey color.
Definition: UI.hpp:69
GLFWwindow * _window
The UI window.
Definition: UI.hpp:119
void initialize()
Initialize the UI, including ImGui, widgets, and assets.
Definition: UI.cpp:32
void renderFrame()
Render the UI frame.
Definition: UI.cpp:266
void initializeWidgets()
Initialize UI widgets.
Definition: UI.cpp:91
void endFrame()
End the UI frame.
Definition: UI.cpp:293
UI(std::shared_ptr< Game > game)
Constructor to create a UI manager for the specified game.
Definition: UI.cpp:26
void close()
Close and clean up the UI.
Definition: UI.cpp:318
void initializeAssets()
Initialize UI assets.
Definition: UI.cpp:111
static ImVec4 BLACK
Black color.
Definition: UI.hpp:72
static ImVec4 BACKGROUND_COLOR
Background color.
Definition: UI.hpp:64
static ImVec4 TEXT_COLOR
Text color.
Definition: UI.hpp:65
std::shared_ptr< Game > _game
A shared pointer to the associated game.
Definition: UI.hpp:115
Definition: Entity.cpp:3