TGUI  v0.6.10
Global.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef TGUI_GLOBAL_HPP
26 #define TGUI_GLOBAL_HPP
27 
29 
30 #include <iostream>
31 #include <string>
32 #include <sstream>
33 
34 #include <SFML/Graphics.hpp>
35 
36 #include <TGUI/Config.hpp>
37 #include <TGUI/Borders.hpp>
38 
39 #include <TGUI/TextureManager.hpp>
40 
42 
43 #ifndef TGUI_OUTPUT
44  #define TGUI_OUTPUT(x) sf::err() << x << std::endl;
45 #endif
46 
47 #define TGUI_MINIMUM(x, y) ((x < y) ? x : y)
48 
49 #define TGUI_MAXIMUM(x, y) ((x > y) ? x : y)
50 
52 
54 namespace tgui
55 {
57 
58  template <typename T>
59  std::string to_string(T value)
60  {
61  std::ostringstream oss;
62  oss << value;
63  return oss.str();
64  }
65 
67 
68  enum WidgetPhase
69  {
70  WidgetPhase_Hover = 1,
71  WidgetPhase_MouseDown = 2,
72  WidgetPhase_Focused = 4,
73  WidgetPhase_Selected = 8
74  };
75 
76 
81  {
82  Type_Unknown,
83  Type_ClickableWidget,
84  Type_Picture,
85  Type_Button,
86  Type_Checkbox,
87  Type_RadioButton,
88  Type_Label,
89  Type_EditBox,
90  Type_ListBox,
91  Type_ComboBox,
92  Type_Slider,
93  Type_Scrollbar,
94  Type_LoadingBar,
95  Type_TextBox,
96  Type_SpriteSheet,
97  Type_AnimatedPicture,
98  Type_SpinButton,
99  Type_Slider2d,
100  Type_Tab,
101  Type_MenuBar,
102  Type_ChatBox,
103  Type_Knob,
104  Type_Canvas,
105  Type_Panel,
106  Type_ChildWindow,
107  Type_Grid,
108  Type_MessageBox
109  };
110 }
111 
113 
114 namespace tgui
115 {
120  TGUI_API void enableTabKeyUsage();
121 
122 
127  TGUI_API void disableTabKeyUsage();
128 
129 
138  TGUI_API void setResourcePath(const std::string& path);
139 
140 
149  TGUI_API const std::string& getResourcePath();
150 }
151 
153 
154 namespace tgui
155 {
157  extern TGUI_API TextureManager TGUI_TextureManager;
158 
160  class Clipboard;
161  extern TGUI_API Clipboard TGUI_Clipboard;
162 
164  extern TGUI_API bool TGUI_TabKeyUsageEnabled;
165 
167  extern TGUI_API std::string TGUI_ResourcePath;
168 
169 
172  // Get a sf::Color from a string. The string must look like: "(r, g, b)" or "(r, g, b, a)".
173  // When this function fails then it will return black.
175  TGUI_API sf::Color extractColor(std::string string);
176 
177 
180  // This function does exactly the opposite of extractColor.
181  // The returned string will be "(r,g,b)" when a=255 or "(r,g,b,a)" when a<255.
183  TGUI_API std::string convertColorToString(const sf::Color& color);
184 
185 
188  // Get a sf::Vector2f from a string. The string must look like: "(x, y)".
190  TGUI_API bool extractVector2f(std::string string, sf::Vector2f& vector);
191 
192 
195  // Get a sf::Vector2u from a string. The string must look like: "(x, y)".
197  TGUI_API bool extractVector2u(std::string string, sf::Vector2u& vector);
198 
199 
202  // Get a tgui::Borders from a string. The string must look like: "(left, top, right, bottom)".
204  TGUI_API bool extractBorders(std::string string, Borders& borders);
205 
206 
209  // Converts a string containing e.g. newlines and tabs into a compact string.
210  // The original string can be obtained by callig the decodeString on the resulting string.
212  void encodeString(const std::string& origString, std::string& encodedString);
213 
214 
217  // Converts an encoded string back into the original string.
219  void decodeString(const std::string& encodedString, std::string& decodedString);
220 
221 
224  // Turns a list of strings into a string. Use the decodeList function to get the list back.
226  TGUI_API void encodeList(const std::vector<sf::String>& list, std::string& encodedString);
227 
228 
231  // Turns a list of strings into a string. Use the decodeList function to get the list back.
233  TGUI_API void decodeList(const std::string& encodedString, std::vector<sf::String>& list);
234 
235 
238  // Converts a string to lowercase.
240  std::string toLower(std::string str);
241 
242 }
243 
245 
246 #endif // TGUI_GLOBAL_HPP
247 
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
WidgetTypes
A list of all widget types.
Definition: Global.hpp:80
Definition: TextureManager.hpp:71
TGUI_API void enableTabKeyUsage()
While tab key usage is enabled (default), pressing tab will focus another widget. ...
Definition: Clipboard.hpp:38
TGUI_API void disableTabKeyUsage()
When disabling the tab key usage, pressing tab will no longer focus another widget.
Definition: Borders.hpp:35
TGUI_API const std::string & getResourcePath()
Return the resource path.
TGUI_API void setResourcePath(const std::string &path)
Set a new resource path.