TGUI 1.13
Loading...
Searching...
No Matches
Global.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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 <TGUI/Config.hpp>
31
32#include <TGUI/Duration.hpp>
33#include <TGUI/Exception.hpp>
34#include <TGUI/Filesystem.hpp>
35#include <TGUI/Font.hpp>
36#include <TGUI/String.hpp>
37
38#include <cstdint>
39#include <memory>
40
42
44namespace tgui
45{
49#if defined(__cpp_lib_smart_ptr_for_overwrite) && (__cpp_lib_smart_ptr_for_overwrite >= 202002L)
50 template <typename T>
51 const auto MakeUniqueForOverwrite = std::make_unique_for_overwrite<T>;
52#else
53 template <typename T>
54 [[nodiscard]] std::unique_ptr<T> MakeUniqueForOverwrite(const std::size_t size)
55 {
56 return std::unique_ptr<T>(new typename std::remove_extent_t<T>[size]);
57 }
58#endif
59
60 template <typename T>
61 TGUI_DEPRECATED("Use std::clamp instead")
62 [[nodiscard]] constexpr const T& clamp(const T& v, const T& lo, const T& hi)
63 {
64 return std::clamp(v, lo, hi);
65 }
66
77 TGUI_API void setTextInputUsesTextCursorByDefault(bool useIBeam);
78
87 [[nodiscard]] TGUI_API bool getTextInputUsesTextCursorByDefault();
88
92 TGUI_API void setGlobalTextSize(unsigned int textSize);
93
97 [[nodiscard]] TGUI_API unsigned int getGlobalTextSize();
98
102 TGUI_API void setDoubleClickTime(Duration duration);
103
107 [[nodiscard]] TGUI_API Duration getDoubleClickTime();
108
116 TGUI_API void setResourcePath(const Filesystem::Path& path);
117
125 TGUI_API void setResourcePath(const String& path);
126
134 [[nodiscard]] TGUI_API const Filesystem::Path& getResourcePath();
135
139 TGUI_API void setEditCursorBlinkRate(Duration blinkRate);
140
144 [[nodiscard]] TGUI_API Duration getEditCursorBlinkRate();
145
156 [[nodiscard]] TGUI_API std::unique_ptr<std::uint8_t[]> readFileToMemory(const String& filename, std::size_t& fileSize);
157
166 TGUI_API bool writeFile(const String& filename, const std::stringstream& textToWrite);
167
176 TGUI_API bool writeFile(const String& filename, CharStringView textToWrite);
177
181 template <typename To, typename From>
182 To downcast(From& base)
183 {
184 TGUI_ASSERT(dynamic_cast<std::remove_reference_t<To>*>(&base), "Downcasting to wrong type");
185 return static_cast<To>(base);
186 }
187
191 template <typename To, typename From>
192 To downcast(From* base)
193 {
194 TGUI_ASSERT(dynamic_cast<To>(base), "Downcasting to wrong type");
195 return static_cast<To>(base);
196 }
197
201 template <typename To, typename From>
202 std::shared_ptr<To> downcast(std::shared_ptr<From> base)
203 {
204 TGUI_ASSERT(std::dynamic_pointer_cast<To>(base), "Downcasting to wrong type");
205 return std::static_pointer_cast<To>(base);
206 }
207
209} // namespace tgui
210
212
213#endif // TGUI_GLOBAL_HPP
Wrapper for durations.
Definition Duration.hpp:52
Object to represent paths on a filesystem.
Definition Filesystem.hpp:55
Wrapper class to store strings.
Definition String.hpp:94
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
TGUI_API void setDoubleClickTime(Duration duration)
Sets the double-click time for the mouse.
TGUI_API const Filesystem::Path & getResourcePath()
Returns the resource path.
TGUI_API void setTextInputUsesTextCursorByDefault(bool useIBeam)
Changes the default mouse cursor of EditBox and TextArea widgets from an arrow to the I-beam cursor.
TGUI_API void setGlobalTextSize(unsigned int textSize)
Sets the default text size for all widgets created after calling the function.
TGUI_API void setEditCursorBlinkRate(Duration blinkRate)
Changes the blink rate of the cursor in edit fields such as EditBox and TextArea.
TGUI_API void setResourcePath(const Filesystem::Path &path)
Sets a new resource path.
TGUI_API Duration getDoubleClickTime()
Retrieves the double-click time for the mouse.
TGUI_API bool getTextInputUsesTextCursorByDefault()
Returns whether the default mouse cursor of EditBox and TextArea widgets is an I-beam instead of an a...
TGUI_API std::unique_ptr< std::uint8_t[]> readFileToMemory(const String &filename, std::size_t &fileSize)
Opens a file and reads its contents into memory.
TGUI_API Duration getEditCursorBlinkRate()
Returns the blink rate of the cursor in edit fields such as EditBox and TextArea.
std::unique_ptr< T > MakeUniqueForOverwrite(const std::size_t size)
Create a unique_ptr containing an uninitialized array.
Definition Global.hpp:54
TGUI_API bool writeFile(const String &filename, const std::stringstream &textToWrite)
Opens a file and writes the given contents to it.
To downcast(From &base)
Cast from a reference of a base class to a reference of a derived class.
Definition Global.hpp:182
TGUI_API unsigned int getGlobalTextSize()
Retrieves the default text size used for all new widgets.