Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
GUIInterface.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_GUI_INTERFACE_H_
34#define DVD_GUI_INTERFACE_H_
35
36#include "GUIElement.h"
38
39namespace CEGUI {
40 class String;
41};
42
43namespace Divide {
44
45class GUI;
46class GUIText;
47class GUIFlash;
48class GUIButton;
49class GUIMessageBox;
50
52public:
53 using GUIMap = hashMap<U64, std::pair<GUIElement*, bool/*last state*/>>;
55
56public:
57 explicit GUIInterface(GUI& context);
58 virtual ~GUIInterface();
59
60 void onLanguageChange(std::string_view newLanguage);
61
62 GUI& getParentContext() noexcept { return *_context; }
63 const GUI& getParentContext() const noexcept { return *_context; }
65 template <typename T> requires std::is_base_of_v<GUIElement, T>
66 T* getGUIElement(const U64 elementName) const {
67 return static_cast<T*>(getGUIElementImpl(elementName, T::Type));
68 }
69
70 template <typename T> requires std::is_base_of_v<GUIElement, T>
71 T* getGUIElement(const I64 elementID) const {
72 return static_cast<T*>(getGUIElementImpl(elementID, T::Type));
73 }
74
75 virtual GUIText* addText(const char* name,
76 const RelativePosition2D& position,
77 const string& font,
78 const UColour4& colour,
79 const string& text,
80 bool multiLine = false,
81 U8 fontSize = 16u);
82
83 virtual GUIText* modifyText(const char* name, const string& text, bool multiLine);
84
85 virtual GUIMessageBox* addMsgBox(const char* name,
86 const string& title,
87 const string& message,
88 vec2<I32> offsetFromCentre = vec2<I32>(0));
89
90 virtual GUIButton* addButton(const char* name,
91 const string& text,
92 const RelativePosition2D& offset,
93 const RelativeScale2D& size,
94 const string& rootSheetID = "");
95
96 virtual GUIFlash* addFlash(const char* name,
97 const RelativePosition2D& position,
98 const RelativeScale2D& size);
99
100 virtual CEGUI::Window* createWindow(const CEGUI::String& type, const CEGUI::String& name);
101 virtual CEGUI::Window* loadWindowFromLayoutFile(const char* layoutFileName);
102 virtual bool unloadWindow(CEGUI::Window*& window);
103
104protected:
105 void addElement(U64 id, GUIElement* element);
106 virtual GUIElement* getGUIElementImpl(U64 elementName, GUIType type) const;
107 virtual GUIElement* getGUIElementImpl(I64 elementID, GUIType type) const;
108
109protected:
111
113};
114
115}; //namespace Divide
116
117#endif //DVD_GUI_INTERFACE_H_
Graphical User Interface.
Definition: GUI.h:81
virtual GUIMessageBox * addMsgBox(const char *name, const string &title, const string &message, vec2< I32 > offsetFromCentre=vec2< I32 >(0))
virtual CEGUI::Window * createWindow(const CEGUI::String &type, const CEGUI::String &name)
void onLanguageChange(std::string_view newLanguage)
const GUI & getParentContext() const noexcept
Definition: GUIInterface.h:63
T * getGUIElement(const I64 elementID) const
Definition: GUIInterface.h:71
virtual GUIFlash * addFlash(const char *name, const RelativePosition2D &position, const RelativeScale2D &size)
virtual CEGUI::Window * loadWindowFromLayoutFile(const char *layoutFileName)
virtual GUIText * addText(const char *name, const RelativePosition2D &position, const string &font, const UColour4 &colour, const string &text, bool multiLine=false, U8 fontSize=16u)
DELEGATE< void, I64 > ButtonCallback
Definition: GUIInterface.h:54
virtual GUIElement * getGUIElementImpl(U64 elementName, GUIType type) const
T * getGUIElement(const U64 elementName) const
Get a pointer to an element by name/id.
Definition: GUIInterface.h:66
virtual GUIButton * addButton(const char *name, const string &text, const RelativePosition2D &offset, const RelativeScale2D &size, const string &rootSheetID="")
virtual bool unloadWindow(CEGUI::Window *&window)
hashMap< U64, std::pair< GUIElement *, bool > > GUIMap
Definition: GUIInterface.h:53
void addElement(U64 id, GUIElement *element)
virtual GUIText * modifyText(const char *name, const string &text, bool multiLine)
std::array< GUIMap, to_base(GUIType::COUNT)> _guiElements
Definition: GUIInterface.h:112
GUI & getParentContext() noexcept
Definition: GUIInterface.h:62
constexpr Optick::Category::Type GUI
Definition: Profiler.h:64
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
DELEGATE_STD< Ret, Args... > DELEGATE
uint8_t U8
hashAlg::unordered_map< K, V, HashFun, Predicate > hashMap
Definition: HashMap.h:55
int64_t I64
uint64_t U64
constexpr auto to_base(const Type value) -> Type