From 874794ea584588457dfde7ef17c447e2a0eb46bb Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Sun, 4 Aug 2024 21:00:10 -0400 Subject: Add LLUIColorTable debug-settings-like floater for easing skin design --- indra/llui/llconsole.cpp | 3 +- indra/llui/llstatgraph.cpp | 4 +-- indra/llui/lluicolortable.cpp | 68 ++++++++++++++++++++++++++++++++++++++----- indra/llui/lluicolortable.h | 7 +++++ 4 files changed, 71 insertions(+), 11 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llconsole.cpp b/indra/llui/llconsole.cpp index 4f52f5936d..91e6f281da 100644 --- a/indra/llui/llconsole.cpp +++ b/indra/llui/llconsole.cpp @@ -183,7 +183,8 @@ void LLConsole::draw() static LLCachedControl console_bg_opacity(*LLUI::getInstance()->mSettingGroups["config"], "ConsoleBackgroundOpacity", 0.7f); F32 console_opacity = llclamp(console_bg_opacity(), 0.f, 1.f); - static LLColor4 color = LLUIColorTable::instance().getColor("ConsoleBackground"); + static LLUIColor console_color = LLUIColorTable::instance().getColor("ConsoleBackground"); + LLColor4 color = console_color; color.mV[VALPHA] *= console_opacity; F32 line_height = (F32)mFont->getLineHeight(); diff --git a/indra/llui/llstatgraph.cpp b/indra/llui/llstatgraph.cpp index 28b4d387f1..d97051247e 100644 --- a/indra/llui/llstatgraph.cpp +++ b/indra/llui/llstatgraph.cpp @@ -100,8 +100,8 @@ void LLStatGraph::draw() it--; } - static LLColor4 default_color = LLUIColorTable::instance().getColor( "MenuDefaultBgColor" ); - gGL.color4fv(default_color.mV); + static LLUIColor default_color = LLUIColorTable::instance().getColor( "MenuDefaultBgColor" ); + gGL.color4fv(default_color.get().mV); gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, true); gGL.color4fv(LLColor4::black.mV); diff --git a/indra/llui/lluicolortable.cpp b/indra/llui/lluicolortable.cpp index 3279926786..a792cb8103 100644 --- a/indra/llui/lluicolortable.cpp +++ b/indra/llui/lluicolortable.cpp @@ -198,7 +198,61 @@ LLUIColor LLUIColorTable::getColor(std::string_view name, const LLColor4& defaul // update user color, loaded colors are parsed on initialization void LLUIColorTable::setColor(std::string_view name, const LLColor4& color) { - setColor(name, color, mUserSetColors); + auto it = mUserSetColors.lower_bound(name); + if(it != mUserSetColors.end() && !(mUserSetColors.key_comp()(name, it->first))) + { + it->second = color; + } + else + { + string_color_map_t::iterator base_iter = mLoadedColors.find(name); + if (base_iter != mLoadedColors.end()) + { + LLColor4 original_color = base_iter->second.get(); + auto color_handle = mLoadedColors.extract(base_iter); + auto new_color_pair = mUserSetColors.insert(std::move(color_handle)); + new_color_pair.position->second = color; + mLoadedColors.emplace(name, LLUIColor(original_color)); + } + else + { + mUserSetColors.insert(it, std::make_pair(name, color)); + } + } +} + +bool LLUIColorTable::isDefault(std::string_view name) const +{ + string_color_map_t::const_iterator base_iter = mLoadedColors.find(name); + string_color_map_t::const_iterator user_iter = mUserSetColors.find(name); + if (base_iter != mLoadedColors.end()) + { + if(user_iter != mUserSetColors.end()) + return user_iter->second == base_iter->second; + + return true; + } + else if (user_iter != mUserSetColors.end()) // user only color ??? + { + return true; + } + + return false; +} + +void LLUIColorTable::resetToDefault(std::string_view name) +{ + string_color_map_t::iterator iter = mUserSetColors.find(name); + + if (iter != mUserSetColors.end()) + { + auto default_iter = mLoadedColors.find(name); + + if (default_iter != mLoadedColors.end()) + { + iter->second = default_iter->second.get(); + } + } } bool LLUIColorTable::loadFromSettings() @@ -223,18 +277,16 @@ void LLUIColorTable::saveUserSettings() const { Params params; - for(string_color_map_t::const_iterator it = mUserSetColors.begin(); - it != mUserSetColors.end(); - ++it) + for (const auto& color_pair : mUserSetColors) { // Compare user color value with the default value, skip if equal - string_color_map_t::const_iterator itd = mLoadedColors.find(it->first); - if(itd != mLoadedColors.end() && itd->second == it->second) + string_color_map_t::const_iterator itd = mLoadedColors.find(color_pair.first); + if(itd != mLoadedColors.end() && itd->second == color_pair.second) continue; ColorEntryParams color_entry; - color_entry.name = it->first; - color_entry.color.value = it->second; + color_entry.name = color_pair.first; + color_entry.color.value = color_pair.second; params.color_entries.add(color_entry); } diff --git a/indra/llui/lluicolortable.h b/indra/llui/lluicolortable.h index ca1ca9eaa7..0c6286e5eb 100644 --- a/indra/llui/lluicolortable.h +++ b/indra/llui/lluicolortable.h @@ -83,12 +83,19 @@ public: // returns true if color_name exists in the table bool colorExists(std::string_view color_name) const; + bool isDefault(std::string_view color_name) const; + + void resetToDefault(std::string_view color_name); + // loads colors from settings files bool loadFromSettings(); // saves colors specified by the user to the users skin directory void saveUserSettings() const; + const auto& getLoadedColors() { return mLoadedColors; } + const auto& getUserColors() { return mUserSetColors; } + private: bool loadFromFilename(const std::string& filename, string_color_map_t& table); -- cgit v1.2.3