MeshLib
 
Loading...
Searching...
No Matches
MRColorTheme.h
Go to the documentation of this file.
1#pragma once
2#include "exports.h"
3#include "MRMesh/MRColor.h"
4#include "MRMesh/MRSignal.h"
5#include "MRPch/MRJson.h"
6#include <filesystem>
7#include <vector>
8#include <array>
9#include <optional>
10
11namespace MR
12{
13
14// This singleton is born to manage color-themes loading and saving, and apply it to app
15// It can handle scene colors (default mesh colors, etc.) and Dear ImGui colors
17{
18public:
19 MRVIEWER_API static ColorTheme& instance();
20
21 enum class Preset
22 {
23 Dark,
24 Default = Dark,
25 Light,
26 Count
27 };
28 MRVIEWER_API static Preset getPreset();
29 MRVIEWER_API static const char* getPresetName( Preset type );
30
31
32 enum class Type
33 {
34 Default,
35 User
36 };
37
38 MRVIEWER_API static Type getThemeType();
39 MRVIEWER_API static const std::string& getThemeName();
40
41 // Setup this struct
42 MRVIEWER_API static void setupByTypeName( Type type, const std::string& name );
43 MRVIEWER_API static void setupDefaultDark();
44 MRVIEWER_API static void setupDefaultLight();
45 MRVIEWER_API static void setupUserTheme( const std::string& themeName );
46 // Setup this struct from serialized color-theme file
47 MRVIEWER_API static void setupFromFile( const std::filesystem::path& path, Type type = Type::User );
48 // Setup this struct from Json value
49 MRVIEWER_API static void setupFromJson( const Json::Value& value, Type type = Type::User );
50
51 // Setup this struct from current application colors, and serialize them to file
52 // gets scene colors from first ObjectMesh, if it is present
53 // gets active viewport background color
54 MRVIEWER_API static void serializeCurrentToFile( const std::filesystem::path& path );
55 // Setup this struct from current application colors, and serialize them to jsonValue
56 // gets scene colors from first ObjectMesh, if it is present
57 // gets active viewport background color
58 MRVIEWER_API static void serializeCurrentToJson( Json::Value& root );
59
60 // Applies colors stored in this struct to application
61 // really some colors of this theme are applied deferred on next frame because of ImGui::PushStyleColor problem
62 // note that struct should be initialized when apply is called
63 // initialized in this scope means that structure has it's own values for colors
64 MRVIEWER_API static void apply();
65 // True if this structure is filled with colors, false if empty
66 MRVIEWER_API static bool isInitialized();
67
68 // Color types used in ribbon
144 // Getter and setter for ribbon colors
145 MRVIEWER_API static void setRibbonColor( const Color& color, RibbonColorsType type );
146 MRVIEWER_API static const Color& getRibbonColor( RibbonColorsType type );
147 MRVIEWER_API static const char* getRibbonColorTypeName( RibbonColorsType type );
148
150 {
152 Borders,
153 Count
154 };
155
156 // Getter and setter for viewport colors
157 MRVIEWER_API static void setViewportColor( const Color& color, ViewportColorsType type );
158 MRVIEWER_API static const Color& getViewportColor( ViewportColorsType type );
159 MRVIEWER_API static const char* getViewportColorTypeName( ViewportColorsType type );
160
161 // Returns directory where user's custom themes are stored
162 MRVIEWER_API static std::filesystem::path getUserThemesDirectory();
163
164 // Find available custom themes
165 MRVIEWER_API static void updateUserThemesList();
166 // Return list of found custom themes
167 MRVIEWER_API static std::vector<std::string> foundUserThemes();
168
169 // Reset ImGui style sizes and colors, and apply menu scaling to it
170 MRVIEWER_API static void resetImGuiStyle();
171
173 MRVIEWER_API boost::signals2::connection onChanged( const boost::function<void()> & slot, boost::signals2::connect_position position = boost::signals2::at_back );
174
175private:
176 ColorTheme() = default;
177 ~ColorTheme() = default;
178
179
180 std::vector<Color> sceneColors_;
181 Preset themePreset_ = Preset::Dark;
182 std::array<Color, size_t( RibbonColorsType::Count )> newUIColors_;
183 std::array<Color, size_t( ViewportColorsType::Count )> viewportColors_;
184
185 Type type_{ Type::Default };
186 std::string themeName_;
187
188 std::vector<std::string> foundUserThemes_;
189
190 using ChangedSignal = Signal<void()>;
191 ChangedSignal changedSignal_;
192};
193
194}
Definition MRColorTheme.h:17
static MRVIEWER_API void updateUserThemesList()
static MRVIEWER_API void setupUserTheme(const std::string &themeName)
static MRVIEWER_API bool isInitialized()
static MRVIEWER_API ColorTheme & instance()
static MRVIEWER_API void setupFromJson(const Json::Value &value, Type type=Type::User)
static MRVIEWER_API const char * getPresetName(Preset type)
MRVIEWER_API boost::signals2::connection onChanged(const boost::function< void()> &slot, boost::signals2::connect_position position=boost::signals2::at_back)
Connects given slot to receive signal on every Color Theme change, triggered in apply.
static MRVIEWER_API const char * getRibbonColorTypeName(RibbonColorsType type)
static MRVIEWER_API void setupFromFile(const std::filesystem::path &path, Type type=Type::User)
static MRVIEWER_API void setRibbonColor(const Color &color, RibbonColorsType type)
static MRVIEWER_API std::filesystem::path getUserThemesDirectory()
static MRVIEWER_API std::vector< std::string > foundUserThemes()
static MRVIEWER_API void setupByTypeName(Type type, const std::string &name)
static MRVIEWER_API Preset getPreset()
static MRVIEWER_API void setupDefaultLight()
static MRVIEWER_API void setupDefaultDark()
ViewportColorsType
Definition MRColorTheme.h:150
static MRVIEWER_API void apply()
static MRVIEWER_API const char * getViewportColorTypeName(ViewportColorsType type)
static MRVIEWER_API void serializeCurrentToFile(const std::filesystem::path &path)
static MRVIEWER_API const Color & getRibbonColor(RibbonColorsType type)
static MRVIEWER_API void setViewportColor(const Color &color, ViewportColorsType type)
Preset
Definition MRColorTheme.h:22
static MRVIEWER_API const Color & getViewportColor(ViewportColorsType type)
Type
Definition MRColorTheme.h:33
static MRVIEWER_API Type getThemeType()
RibbonColorsType
Definition MRColorTheme.h:70
static MRVIEWER_API void serializeCurrentToJson(Json::Value &root)
static MRVIEWER_API void resetImGuiStyle()
static MRVIEWER_API const std::string & getThemeName()
Definition MRCameraOrientationPlugin.h:7
Definition MRColor.h:9
Definition MRSignal.h:24