BARE2D
BARECEGUI.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <GL/glew.h>
4 #include <CEGUI/CEGUI.h>
5 #include <CEGUI/RendererModules/OpenGL/GL3Renderer.h>
6 #include <glm/glm.hpp>
7 #include <SDL2/SDL_events.h>
8 
9 namespace BARE2D {
10 
12  CEGUI::OpenGL3Renderer* renderer = nullptr;
13  CEGUI::GUIContext* context = nullptr;
14  CEGUI::Window* rootWindow = nullptr;
15  };
16 
17  class BARECEGUI
18  {
19  public:
20  static BARECEGUI* getInstance();
21  static void release();
22 
23  /**
24  * @brief Initializes all of the necessary stuff to use CEGUI!
25  * @param resourceDirectory The directory that all of the resources lie in. Should follow CEGUI's specs.
26  * @param numContexts The number of different contexts to create. Each context has the ability to handle input differently.
27  */
28  void init(std::string& resourceDirectory, unsigned int numContexts);
29 
30  /**
31  * @brief Draws the GUI to the screen over top of what's already there.
32  */
33  void draw();
34 
35  /**
36  * @brief Updates the amount of time passed in CEGUI.
37  */
38  void update();
39 
40  /**
41  * @brief Sets the active context
42  * @param contextIndex The index of the context to activate. Must be less than numContexts from init().
43  */
44  void setActiveContext(unsigned int contextIndex);
45 
46  /**
47  * @brief Sets the image of the mouse cursor.
48  * @param imageFile The file to set the mouse cursor's image from.
49  */
50  void setMouseCursor(std::string imageFile);
51 
52  /**
53  * @brief Shows/hides the mouse cursor. Useful for cutscenes!
54  * @param shown True = shows the cursor, false = hides it.
55  */
56  void setMouseCursorShown(bool shown);
57 
58  /**
59  * @brief Handles and propagates input.
60  * @param evnt The SDL_Event to add.
61  */
62  void handleSDLEvent(SDL_Event& evnt);
63 
64  /**
65  * @brief Loads a scheme file from resourceDirectory/schemes
66  * @param schemeFile The file to load from
67  */
68  void loadScheme(std::string schemeFile);
69 
70  /**
71  * @brief Sets the current font to some font.
72  * @param fontFile The file of the font to be loaded.
73  */
74  void setFont(std::string fontFile);
75 
76  /**
77  * @brief Creates a widget of some type.
78  * @param type The type of window - should generally be "[YourScheme]/[Label,Button,FrameWindow,etc.]". These strings are available in the scheme files.
79  * @param destRectPercent The destination+rectangle of the widget, in terms of percentages of the screen.
80  * @param destRectPixels The destination+rectangle of the widget, in terms of pixels.
81  * @param parent The parent window - defaults to nullptr.
82  * @param name The name of the window - defaults to a unique identifier. Only set this if a pointer of the window cannot be retained/propagated as a handle.
83  * @return A pointer to the new CEGUI::Window - can be casted to some child type generally.
84  */
85  CEGUI::Window* createWidget(std::string type, glm::vec4 destRectPercent, glm::vec4 destRectPixels, CEGUI::Window* parent = nullptr, std::string name = "");
86 
87  /**
88  * @return The OpenGL3Renderer that the context "owns"
89  */
90  CEGUI::OpenGL3Renderer* getRenderer();
91  /**
92  * @return The GUIContext that the context "owns"
93  */
94  CEGUI::GUIContext* getContext();
95 
96  private:
97  BARECEGUI();
98  ~BARECEGUI();
99 
101 
102  static bool m_initialized;
103 
104  /**
105  * @brief Frees all necessary memory and unloads resources. Destroys root + children windows.
106  */
107  void destroy();
108 
109  std::vector<CEGUIContextWrapper*> m_contexts;
110  unsigned int m_lastTime = 0;
111  unsigned int m_activeContext = 0;
112  };
113 
114  CEGUI::Key::Scan SDLKeyToCEGUIKey(SDL_Keycode key);
115  CEGUI::MouseButton SDLButtonToCEGUIButton(Uint8 sdlButton);
116 }
117 
BARE2D::BARECEGUI::setActiveContext
void setActiveContext(unsigned int contextIndex)
Sets the active context.
Definition: BARECEGUI.cpp:173
BARE2D::BARECEGUI::update
void update()
Updates the amount of time passed in CEGUI.
Definition: BARECEGUI.cpp:152
BARE2D::BARECEGUI::getRenderer
CEGUI::OpenGL3Renderer * getRenderer()
Definition: BARECEGUI.cpp:273
BARE2D::BARECEGUI::m_initialized
static bool m_initialized
Definition: BARECEGUI.hpp:102
BARE2D
Definition: App.cpp:13
BARE2D::BARECEGUI::setMouseCursorShown
void setMouseCursorShown(bool shown)
Shows/hides the mouse cursor. Useful for cutscenes!
Definition: BARECEGUI.cpp:185
BARE2D::CEGUIContextWrapper::renderer
CEGUI::OpenGL3Renderer * renderer
Definition: BARECEGUI.hpp:12
BARE2D::BARECEGUI::m_instance
static BARECEGUI * m_instance
Definition: BARECEGUI.hpp:100
BARE2D::BARECEGUI::getContext
CEGUI::GUIContext * getContext()
Definition: BARECEGUI.cpp:277
BARE2D::BARECEGUI::~BARECEGUI
~BARECEGUI()
Definition: BARECEGUI.cpp:30
BARE2D::BARECEGUI::handleSDLEvent
void handleSDLEvent(SDL_Event &evnt)
Handles and propagates input.
Definition: BARECEGUI.cpp:193
BARE2D::BARECEGUI::setMouseCursor
void setMouseCursor(std::string imageFile)
Sets the image of the mouse cursor.
Definition: BARECEGUI.cpp:181
BARE2D::BARECEGUI::BARECEGUI
BARECEGUI()
Definition: BARECEGUI.cpp:26
BARE2D::BARECEGUI::loadScheme
void loadScheme(std::string schemeFile)
Loads a scheme file from resourceDirectory/schemes.
Definition: BARECEGUI.cpp:241
BARE2D::BARECEGUI::m_lastTime
unsigned int m_lastTime
Definition: BARECEGUI.hpp:110
BARE2D::BARECEGUI::m_activeContext
unsigned int m_activeContext
Definition: BARECEGUI.hpp:111
BARE2D::CEGUIContextWrapper::rootWindow
CEGUI::Window * rootWindow
Definition: BARECEGUI.hpp:14
BARE2D::BARECEGUI::getInstance
static BARECEGUI * getInstance()
Definition: BARECEGUI.cpp:14
BARE2D::BARECEGUI::setFont
void setFont(std::string fontFile)
Sets the current font to some font.
Definition: BARECEGUI.cpp:246
BARE2D::CEGUIContextWrapper::context
CEGUI::GUIContext * context
Definition: BARECEGUI.hpp:13
BARE2D::BARECEGUI::init
void init(std::string &resourceDirectory, unsigned int numContexts)
Initializes all of the necessary stuff to use CEGUI!
Definition: BARECEGUI.cpp:39
BARE2D::BARECEGUI::release
static void release()
Definition: BARECEGUI.cpp:21
BARE2D::SDLKeyToCEGUIKey
CEGUI::Key::Scan SDLKeyToCEGUIKey(SDL_Keycode key)
Definition: BARECEGUI.cpp:283
BARE2D::BARECEGUI
Definition: BARECEGUI.hpp:17
BARE2D::BARECEGUI::createWidget
CEGUI::Window * createWidget(std::string type, glm::vec4 destRectPercent, glm::vec4 destRectPixels, CEGUI::Window *parent=nullptr, std::string name="")
Creates a widget of some type.
Definition: BARECEGUI.cpp:255
BARE2D::BARECEGUI::m_contexts
std::vector< CEGUIContextWrapper * > m_contexts
Definition: BARECEGUI.hpp:109
BARE2D::CEGUIContextWrapper
Definition: BARECEGUI.hpp:11
BARE2D::BARECEGUI::draw
void draw()
Draws the GUI to the screen over top of what's already there.
Definition: BARECEGUI.cpp:125
BARE2D::BARECEGUI::destroy
void destroy()
Frees all necessary memory and unloads resources. Destroys root + children windows.
Definition: BARECEGUI.cpp:114
BARE2D::SDLButtonToCEGUIButton
CEGUI::MouseButton SDLButtonToCEGUIButton(Uint8 sdlButton)
Definition: BARECEGUI.cpp:477