TGUI  1.3-dev
Loading...
Searching...
No Matches
ThemeLoader.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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
26#ifndef TGUI_THEME_LOADER_HPP
27#define TGUI_THEME_LOADER_HPP
28
29
30#include <TGUI/String.hpp>
31#include <TGUI/Loading/DataIO.hpp>
32
33#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
34 #include <memory>
35 #include <string>
36 #include <vector>
37 #include <map>
38 #include <set>
39#endif
40
42
43TGUI_MODULE_EXPORT namespace tgui
44{
48 class TGUI_API BaseThemeLoader
49 {
50 public:
51
55 virtual ~BaseThemeLoader() = default;
56
57
63 virtual void preload(const String& primary);
64
65
75 TGUI_NODISCARD virtual std::map<String, String> getGlobalProperties(const String& primary);
76
77
88 TGUI_NODISCARD virtual const std::map<String, String>& load(const String& primary, const String& secondary) = 0;
89
90
101 TGUI_NODISCARD virtual bool canLoad(const String& primary, const String& secondary) = 0;
102
103
105 protected:
106
107
109 // Turns texture and font filenames into paths relative to the theme file
111 void injectThemePath(const std::unique_ptr<DataIO::Node>& node, const String& path) const;
112
113
115 // Resolves references to sections
117 void resolveReferences(std::map<String, std::reference_wrapper<const std::unique_ptr<DataIO::Node>>>& sections,
118 const std::map<String, String>& globalProperties,
119 const std::unique_ptr<DataIO::Node>& node) const;
120
121
123 };
124
125
134 class TGUI_API DefaultThemeLoader : public BaseThemeLoader
135 {
136 public:
137
145 void preload(const String& filename) override;
146
147
155 TGUI_NODISCARD std::map<String, String> getGlobalProperties(const String& filename) override;
156
157
169 TGUI_NODISCARD const std::map<String, String>& load(const String& filename, const String& section) override;
170
171
180 TGUI_NODISCARD bool canLoad(const String& filename, const String& section) override;
181
182
192 static void flushCache(const String& filename = "");
193
194
196 protected:
197
205 TGUI_NODISCARD virtual std::unique_ptr<DataIO::Node> readFile(const String& filename) const;
206
207
209 protected:
210 static std::map<String, std::map<String, std::map<String, String>>> m_propertiesCache;
211 static std::map<String, std::map<String, String>> m_globalPropertiesCache;
212 };
213
214
216}
217
219
220#endif // TGUI_THEME_LOADER_HPP
Base class for theme loader implementations.
Definition ThemeLoader.hpp:49
virtual TGUI_NODISCARD const std::map< String, String > & load(const String &primary, const String &secondary)=0
Loads the property-value pairs from the theme.
virtual void preload(const String &primary)
Optionally already do some work when only the primary parameter is known yet.
virtual TGUI_NODISCARD bool canLoad(const String &primary, const String &secondary)=0
Check if the requested property-value pairs are available.
virtual ~BaseThemeLoader()=default
Virtual destructor.
virtual TGUI_NODISCARD std::map< String, String > getGlobalProperties(const String &primary)
Loads the global property-value pairs from the theme.
Default implementation for theme loading.
Definition ThemeLoader.hpp:135
static void flushCache(const String &filename="")
Empties the caches and force files to be reloaded.
TGUI_NODISCARD const std::map< String, String > & load(const String &filename, const String &section) override
Loads the property-value pairs from the theme file.
TGUI_NODISCARD std::map< String, String > getGlobalProperties(const String &filename) override
Loads the global property-value pairs from the theme.
virtual TGUI_NODISCARD std::unique_ptr< DataIO::Node > readFile(const String &filename) const
Reads and return the contents of the entire file.
TGUI_NODISCARD bool canLoad(const String &filename, const String &section) override
Check if the requested property-value pairs are available.
void preload(const String &filename) override
Loads the theme file in cache.
Wrapper class to store strings.
Definition String.hpp:101
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39