MeshLib C++ Docs
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 <json/forwards.h>
6#include <filesystem>
7#include <vector>
8#include <array>
9
10namespace MR
11{
12
13// This singleton is born to manage color-themes loading and saving, and apply it to app
14// It can handle scene colors (default mesh colors, etc.) and Dear ImGui colors
16{
17public:
18 MRVIEWER_API static ColorTheme& instance();
19
20 enum class Preset
21 {
22 Dark,
23 Default = Dark,
24 Light,
25 Count
26 };
27 MRVIEWER_API static Preset getPreset();
28 MRVIEWER_API static const char* getPresetName( Preset type );
29
30
31 enum class Type
32 {
33 Default,
34 User
35 };
36
37 MRVIEWER_API static Type getThemeType();
38 MRVIEWER_API static const std::string& getThemeName();
39
40 // Setup this struct
41 MRVIEWER_API static void setupByTypeName( Type type, const std::string& name );
42 MRVIEWER_API static void setupDefaultDark();
43 MRVIEWER_API static void setupDefaultLight();
44 MRVIEWER_API static void setupUserTheme( const std::string& themeName );
45 // Setup this struct from serialized color-theme file
46 MRVIEWER_API static void setupFromFile( const std::filesystem::path& path, Type type = Type::User );
47 // Setup this struct from Json value
48 MRVIEWER_API static void setupFromJson( const Json::Value& value, Type type = Type::User );
49
50 // Setup this struct from current application colors, and serialize them to file
51 // gets scene colors from first ObjectMesh, if it is present
52 // gets active viewport background color
53 MRVIEWER_API static void serializeCurrentToFile( const std::filesystem::path& path );
54 // Setup this struct from current application colors, and serialize them to jsonValue
55 // gets scene colors from first ObjectMesh, if it is present
56 // gets active viewport background color
57 MRVIEWER_API static void serializeCurrentToJson( Json::Value& root );
58
59 // True if this structure is filled with colors, false if empty
60 MRVIEWER_API static bool isInitialized();
61
62 // Color types used in ribbon
141 // Getter and setter for ribbon colors
142 MRVIEWER_API static void setRibbonColor( const Color& color, RibbonColorsType type );
143 MRVIEWER_API static const Color& getRibbonColor( RibbonColorsType type );
144 MRVIEWER_API static const char* getRibbonColorTypeName( RibbonColorsType type );
145
147 {
149 Borders,
150 AxisX,
151 AxisY,
152 AxisZ,
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 static boost::signals2::connection onChanged( const std::function<void()>& slot, boost::signals2::connect_position position = boost::signals2::at_back );
174
175private:
176 ColorTheme() = default;
177 ~ColorTheme() = default;
178
179 // Applies colors stored in this struct to application
180 // really some colors of this theme are applied deferred on next frame because of ImGui::PushStyleColor problem
181 // note that struct should be initialized when apply is called
182 // initialized in this scope means that structure has it's own values for colors
183 MRVIEWER_API static void apply_( const std::vector<Color>& sceneColors );
184
185 bool isInitialized_ = false;
186 Preset themePreset_ = Preset::Dark;
187 std::array<Color, size_t( RibbonColorsType::Count )> newUIColors_;
188 std::array<Color, size_t( ViewportColorsType::Count )> viewportColors_;
189
190 Type type_{ Type::Default };
191 std::string themeName_;
192
193 std::vector<std::string> foundUserThemes_;
194
195 using ChangedSignal = Signal<void()>;
196 ChangedSignal changedSignal_;
197};
198
199}
Definition MRColorTheme.h:16
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 boost::signals2::connection onChanged(const std::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 * getPresetName(Preset type)
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:147
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:21
static MRVIEWER_API const Color & getViewportColor(ViewportColorsType type)
Type
Definition MRColorTheme.h:32
static MRVIEWER_API Type getThemeType()
RibbonColorsType
Definition MRColorTheme.h:64
static MRVIEWER_API void serializeCurrentToJson(Json::Value &root)
static MRVIEWER_API void resetImGuiStyle()
static MRVIEWER_API const std::string & getThemeName()
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh/MRColor.h:9
Definition MRSignal.h:24