Simple SFML GUI  0.2a
GUIManager.hpp
1 /*
2  * GUIManager.hpp
3  *
4  * Created on: 02.06.2017
5  * Author: jakub
6  */
7 
8 #ifndef SSG_GUIMANAGER_HPP_
9 #define SSG_GUIMANAGER_HPP_
10 
11 #include <SFML/Graphics.hpp>
12 #include <SFML/System/Mutex.hpp>
13 #include <SFML/System/Lock.hpp>
14 
15 #include <vector>
16 #include <map>
17 #include <memory>
18 #include "Panel.hpp"
19 #include "HaveContextMenu.hpp"
20 #include "TextLabel.hpp"
21 
24  inited(false),
25  focus(false),
26  fullScreen(false),
27  verticalSync(true),
28  frameLimit(0)
29  {}
30 
31  bool inited;
32  bool focus;
33  bool fullScreen;
34  bool verticalSync;
35  size_t frameLimit;
36  sf::Vector2u fullScreenSize;
37  sf::IntRect area;
38  sf::String title;
39  sf::ContextSettings settings;
40 };
41 
43  DebugRectangle(const sf::RectangleShape& rect, size_t ttl, const sf::RenderTarget* target, size_t uid):
44  rect(rect),
45  ttl(ttl),
46  uid(uid),
47  target(target) {
48  if(ttl == 0) {
49  immortal = true;
50  } else {
51  immortal = false;
52  }
53  }
54 
55  sf::RectangleShape rect;
56  size_t ttl;
57  size_t uid;
58  const sf::RenderTarget* target;
59  bool immortal;
60 
61 };
62 
63 class GUIManager {
64 public:
65  static bool update(
66  sf::RenderWindow& rw,
67  sf::Vector2f mp = sf::Vector2f(0.f,0.f),
68  bool pressLeft = false,
69  bool pressRight = false,
70  bool aboveHover = false
71  );
72  static void draw(sf::RenderTarget& target, const sf::RenderStates& states);
73  static size_t drawDebugRectangle(
74  const sf::RectangleShape& rect,
75  size_t ttl=0,
76  const sf::RenderTarget* target = nullptr
77  );
78  static void clearDebugRectangles();
79  static bool removeDebugRectangle(size_t uid);
80  static void addDialog(const std::shared_ptr<Element>& dialog);
81  static void addWindow(const std::shared_ptr<Element>& window);
82  static bool removeDialog(const sf::String& name);
83  static bool removeWindow(const sf::String& name);
84  static bool removeDialog(const Element* id);
85  static bool removeWindow(const Element* id);
86  static bool dialogExist(const sf::String& name);
87  static bool windowExist(const sf::String& name);
88  static size_t dialogCount();
89  static size_t windowCount();
90  static std::pair<size_t, size_t> count();
91  static bool& getWindowFocus(sf::Window* windowPtr);
92  static void setMainWindow(sf::Window* value);
93  static sf::Mutex& getMainWindowMutex();
94  static bool setActiveMainWindow(bool active);
95  static void closeApplication();
96  static void closeWindow(sf::Window* windowPtr);
97  static bool toggleFullscreen(sf::RenderWindow& rw, bool failSafe = true);
98  static bool recreateWindow(sf::RenderWindow& rw, bool failSafe = true);
99  static WindowParameters getParameters(const sf::Window* rw = nullptr);
100  static void setFramerateLimit(sf::Window* rw, size_t limit);
101  static void setVerticalSync(sf::Window* rw, bool sync);
102  static bool setFullScreenResolution(sf::Window* rw, sf::Vector2u size);
103  static sf::VideoMode nextFullScreenMode(sf::RenderWindow& rw);
104  static sf::VideoMode previousFullScreenMode(sf::RenderWindow& rw);
105  static void windowReposition(sf::RenderWindow& rw);
106  static std::shared_ptr<sf::RenderWindow> createWindow(
107  sf::String title,
108  sf::ContextSettings settings = sf::ContextSettings()
109  );
110  static void showTooltip(const HaveHover*, const sf::String& text, sf::Vector2f position);
111  static void hideTooltip(const HaveHover*);
112  static Panel& getTooltipPanel();
113  static TextLabel& getTooltipLabel();
114  static sf::String getMainWindowTitle();
115  static sf::Vector2i getWindowDrift();
116  static void setMaxTooltipWidth(float value);
117 
118 private:
119  GUIManager() {}
120  static bool mainWindowInit(sf::RenderWindow& rw);
121  static void windowInit(WindowParameters& window, sf::RenderWindow& rw);
122  static void initTooltipLabel();
123 
124  static bool closeApplicationFlag;
125  static float maxTooltipWidth;
126  static sf::Window* mainWindow;
127  static sf::Mutex mainWindowMutex;
128  static std::vector<std::shared_ptr<Element>> dialogs;
129  static std::vector<std::shared_ptr<Element>> windows;
130  static std::vector<DebugRectangle> debugRectangles;
131  static std::vector<const Element*> destroyedDialogs;
132  static std::set<sf::Window*> closedWindows;
133  static std::vector<std::shared_ptr<Element>> newDialogs;
134  static Panel referenceElement;
135  static Panel tooltipPanel;
136  static TextLabel* tooltipLabel;
137  static std::map<const sf::Window*, WindowParameters> windowMap;
138  static const HaveHover* lastTooltipOwner;
139  static sf::Vector2i windowDrift;
140 };
141 
142 #endif /* SSG_GUIMANAGER_HPP_ */
Definition: Panel.hpp:29
Definition: GUIManager.hpp:42
Definition: TextLabel.hpp:26
Definition: HaveHover.hpp:16
Definition: GUIManager.hpp:22
Definition: Element.hpp:22
Definition: GUIManager.hpp:63