TGUI  0.7.4
Global.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2017 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_DEFINES_HPP
26 #define TGUI_DEFINES_HPP
27 
29 
30 #include <TGUI/Config.hpp>
31 #include <TGUI/Borders.hpp>
32 #include <TGUI/Exception.hpp>
33 
34 #include <SFML/Graphics.hpp>
35 
36 #include <iostream>
37 #include <string>
38 #include <sstream>
39 #include <memory>
40 #include <locale>
41 
43 
45 namespace tgui
46 {
47  class Texture;
48 
50  extern TGUI_API bool TGUI_TabKeyUsageEnabled;
51 
53 
54  const float pi = 3.14159265358979f;
55 
57 
58  template <typename T>
59  std::string to_string(T value)
60  {
61  std::ostringstream oss;
62  oss.imbue(std::locale::classic());
63  oss << value;
64  return oss.str();
65  }
66 
67 
72  TGUI_API void enableTabKeyUsage();
73 
74 
79  TGUI_API void disableTabKeyUsage();
80 
81 
90  TGUI_API void setResourcePath(const std::string& path);
91 
92 
101  TGUI_API const std::string& getResourcePath();
102 
103 
106  // Check if two floats are equal, with regard to a small epsilon margin.
108  TGUI_API bool compareFloats(float x, float y);
109 
110 
113  // Check if a character is a whitespace character.
115  TGUI_API bool isWhitespace(char character);
116 
117 
120  // Convert a string to an integer. Acts like std::stoi which isn't supported in MinGW TDM.
122  TGUI_API int stoi(const std::string& value);
123 
124 
127  // Convert a string to a float. Acts like std::stof which isn't supported in MinGW TDM.
129  TGUI_API float stof(const std::string& value);
130 
131 
134  // Extract a bool from a string value.
136  TGUI_API bool extractBoolFromString(const std::string& property, const std::string& value);
137 
138 
141  // Move the iterator forward until no more whitespace is found
143  TGUI_API bool removeWhitespace(const std::string& line, std::string::const_iterator& c);
144 
145 
148  // Converts a string to lowercase.
150  TGUI_API std::string toLower(std::string str);
151 
152 
155  // Trim the whitespace from a string.
157  TGUI_API std::string trim(std::string str);
158 
159 
162  // Splits a string.
164  TGUI_API std::vector<std::string> split(const std::string& str, char delim);
165 
166 
169  // Returns the color with its alpha channel multiplied with the alpha parameter
171  TGUI_API sf::Color calcColorOpacity(const sf::Color& color, float alpha);
172 
173 
176  // The line spacing returned by sfml is correct but there is extra space on top.
177  // The text has to be moved up so that the line spacing really corresponds with the height of every line.
178  // This function returns the offset that the text has to be moved.
180  float getTextVerticalCorrection(const std::shared_ptr<sf::Font>& font, unsigned int characterSize, sf::Uint32 style = 0);
181 
182 
192  unsigned int findBestTextSize(const std::shared_ptr<sf::Font>& font, float height, int fit = 0);
193 
194 
196 }
197 
199 
200 #endif // TGUI_DEFINES_HPP
201 
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
TGUI_API void enableTabKeyUsage()
While tab key usage is enabled (default), pressing tab will focus another widget. ...
TGUI_API void disableTabKeyUsage()
When disabling the tab key usage, pressing tab will no longer focus another widget.
TGUI_API const std::string & getResourcePath()
Return the resource path.
TGUI_API void setResourcePath(const std::string &path)
Set a new resource path.