Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion source/MRCommonPlugins/ViewerButtons/MRAddCustomTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ std::string AddCustomThemePlugin::save_()
}

ColorTheme::setupUserTheme( themeName_ );
ColorTheme::apply();
if ( !applyToNewObjectsOnly_ )
{
auto visualObjs = getAllObjectsInTree<VisualObject>( &SceneRoot::get() );
Expand Down
37 changes: 15 additions & 22 deletions source/MRViewer/MRColorTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ EMSCRIPTEN_KEEPALIVE int emsChangeColorTheme( int theme )
ColorTheme::setupDefaultDark();
else
ColorTheme::setupDefaultLight();
ColorTheme::apply();
return 1;
}

Expand Down Expand Up @@ -83,23 +82,20 @@ void ColorTheme::setupFromJson( const Json::Value& root, Type type )
instance.themePreset_ = themePreset;
instance.type_ = type;

std::vector<Color> sceneColors;
if ( valid )
{
if ( instance.sceneColors_.size() < SceneColors::Count )
instance.sceneColors_.resize( SceneColors::Count );
sceneColors.resize( SceneColors::Count );

for ( int i = 0; i < SceneColors::Count; ++i )
{
auto name = SceneColors::getName( SceneColors::Type( i ) );
if ( root[name].isObject() )
deserializeFromJson( root[name], instance.sceneColors_[i] );
deserializeFromJson( root[name], sceneColors[i] );
else
defined = false;
}
}

if ( valid )
{
if ( root["Ribbon Colors"].isObject() )
{
const auto& ribColors = root["Ribbon Colors"];
Expand Down Expand Up @@ -137,7 +133,12 @@ void ColorTheme::setupFromJson( const Json::Value& root, Type type )
if ( !valid || ( type == Type::Default && !defined ) )
{
spdlog::error( "Color theme deserialization failed: invalid json schema." );
instance.sceneColors_.clear();
instance.isInitialized_ = false;
}
else
{
instance.isInitialized_ = true;
apply_( sceneColors );
}
}

Expand Down Expand Up @@ -166,18 +167,16 @@ void ColorTheme::serializeCurrentToJson( Json::Value& root )
assert( ImGui::GetCurrentContext() );
auto& instance = ColorTheme::instance();

if ( instance.sceneColors_.size() < SceneColors::Count )
instance.sceneColors_.resize( SceneColors::Count );

std::vector<Color> sceneColors( SceneColors::Count );
for ( int i = 0; i < SceneColors::Count; ++i )
instance.sceneColors_[i] = SceneColors::get( SceneColors::Type( i ) );
sceneColors[i] = SceneColors::get( SceneColors::Type( i ) );

const auto& vpParams = Viewer::instanceRef().viewport().getParameters();
setViewportColor( vpParams.backgroundColor, ViewportColorsType::Background );
setViewportColor( vpParams.borderColor, ViewportColorsType::Borders );

for ( int i = 0; i < SceneColors::Count; ++i )
serializeToJson( instance.sceneColors_[i], root[SceneColors::getName( SceneColors::Type( i ) )] );
serializeToJson( sceneColors[i], root[SceneColors::getName( SceneColors::Type( i ) )] );

root["ImGuiPreset"] = getPresetName( instance.themePreset_ );

Expand All @@ -190,20 +189,14 @@ void ColorTheme::serializeCurrentToJson( Json::Value& root )
serializeToJson( instance.viewportColors_[i], vieportColors[getViewportColorTypeName( ViewportColorsType( i ) )] );
}

void ColorTheme::apply()
void ColorTheme::apply_( const std::vector<Color>& sceneColors )
{
if ( !ColorTheme::isInitialized() )
{
spdlog::warn( "Color theme is not initialized" );
return;
}

spdlog::info( "Apply color theme." );

const auto& instance = ColorTheme::instance();

for ( int i = 0; i < SceneColors::Count; ++i )
SceneColors::set( SceneColors::Type( i ), instance.sceneColors_[i] );
SceneColors::set( SceneColors::Type( i ), sceneColors[i] );

RibbonButtonDrawer::InitGradientTexture();
UI::init();
Expand All @@ -228,7 +221,7 @@ void ColorTheme::apply()

bool ColorTheme::isInitialized()
{
return !ColorTheme::instance().sceneColors_.empty();
return ColorTheme::instance().isInitialized_;
}

void ColorTheme::setRibbonColor( const Color& color, RibbonColorsType type )
Expand Down
12 changes: 6 additions & 6 deletions source/MRViewer/MRColorTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ class ColorTheme
// gets active viewport background color
MRVIEWER_API static void serializeCurrentToJson( Json::Value& root );

// Applies colors stored in this struct to application
// really some colors of this theme are applied deferred on next frame because of ImGui::PushStyleColor problem
// note that struct should be initialized when apply is called
// initialized in this scope means that structure has it's own values for colors
MRVIEWER_API static void apply();
// True if this structure is filled with colors, false if empty
MRVIEWER_API static bool isInitialized();

Expand Down Expand Up @@ -182,8 +177,13 @@ class ColorTheme
ColorTheme() = default;
~ColorTheme() = default;

// Applies colors stored in this struct to application
// really some colors of this theme are applied deferred on next frame because of ImGui::PushStyleColor problem
// note that struct should be initialized when apply is called
// initialized in this scope means that structure has it's own values for colors
MRVIEWER_API static void apply_( const std::vector<Color>& sceneColors );

std::vector<Color> sceneColors_;
bool isInitialized_ = false;
Preset themePreset_ = Preset::Dark;
std::array<Color, size_t( RibbonColorsType::Count )> newUIColors_;
std::array<Color, size_t( ViewportColorsType::Count )> viewportColors_;
Expand Down
3 changes: 0 additions & 3 deletions source/MRViewer/MRRibbonLayoutConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ void applyRibbonConfig( const RibbonConfig& config )
ribbonMenu->getRibbonButtonDrawer().setMonochrome( config.monochromeRibbonIcons );

if ( config.colorTheme )
{
ColorTheme::setupFromJson( *config.colorTheme );
ColorTheme::apply();
}

if ( config.ribbonStructure || config.ribbonItemsOverrides )
{
Expand Down
2 changes: 0 additions & 2 deletions source/MRViewer/MRViewerSettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ void ViewerSettingsManager::resetSettings( Viewer& viewer )
#else
ColorTheme::setupByTypeName( ColorTheme::Type::Default, ColorTheme::getPresetName( ColorTheme::getPreset() ) );
#endif
ColorTheme::apply();

// lastExtentions_.clear();

Expand Down Expand Up @@ -412,7 +411,6 @@ void ViewerSettingsManager::loadSettings( Viewer& viewer )
// setup default in this case
ColorTheme::setupByTypeName( ColorTheme::Type::Default, ColorTheme::getPresetName( ColorTheme::Preset::Default ) );
}
ColorTheme::apply();

Json::Value lastExtentions = cfg.getJsonValue( lastExtensionsParamKey );
if ( lastExtentions.isArray() )
Expand Down
1 change: 0 additions & 1 deletion source/MRViewer/MRViewerSettingsPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,6 @@ void ViewerSettingsPlugin::drawThemeSelector_()
showError( "This theme is not valid." );
}
backgroundColor_ = Vector4f( ColorTheme::getViewportColor( ColorTheme::ViewportColorsType::Background ) );
ColorTheme::apply();
}
auto item = RibbonSchemaHolder::schema().items.find( "Add custom theme" );
if ( item != RibbonSchemaHolder::schema().items.end() )
Expand Down
Loading