summaryrefslogtreecommitdiff
path: root/src/config/ConfigManager.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-10-16 22:23:10 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-10-16 22:26:02 +0100
commit58375bc87a189c915d12ad93d202462427e239ac (patch)
tree32ba3c74fbf2efe12d5cf13559da13f005797b49 /src/config/ConfigManager.cpp
parent83d99ce5bde97733025ef33f2341d29282393376 (diff)
Add support for rgba() and rgb() colors in the config
Diffstat (limited to 'src/config/ConfigManager.cpp')
-rw-r--r--src/config/ConfigManager.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index 738abcb0..8c015675 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -311,6 +311,31 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
// Values with 0x are hex
const auto VALUEWITHOUTHEX = VALUE.substr(2);
CONFIGENTRY->intValue = stol(VALUEWITHOUTHEX, nullptr, 16);
+ } else if (VALUE.find("rgba(") == 0 && VALUE.find(")") == VALUE.length() - 1) {
+ const auto VALUEWITHOUTFUNC = VALUE.substr(5, VALUE.length() - 6);
+
+ if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 8) {
+ Debug::log(WARN, "invalid length %i for rgba", VALUEWITHOUTFUNC.length());
+ parseError = "rgba() expects length of 8 characters (4 bytes)";
+ return;
+ }
+
+ const auto RGBA = std::stol(VALUEWITHOUTFUNC, nullptr, 16);
+
+ // now we need to RGBA -> ARGB. The config holds ARGB only.
+ CONFIGENTRY->intValue = (RGBA >> 8) + 0x1000000 * (RGBA & 0xFF);
+ } else if (VALUE.find("rgb(") == 0 && VALUE.find(")") == VALUE.length() - 1) {
+ const auto VALUEWITHOUTFUNC = VALUE.substr(4, VALUE.length() - 5);
+
+ if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 6) {
+ Debug::log(WARN, "invalid length %i for rgb", VALUEWITHOUTFUNC.length());
+ parseError = "rgb() expects length of 6 characters (3 bytes)";
+ return;
+ }
+
+ const auto RGB = std::stol(VALUEWITHOUTFUNC, nullptr, 16);
+
+ CONFIGENTRY->intValue = RGB + 0xFF000000; // 0xFF for opaque
} else if (VALUE.find("true") == 0 || VALUE.find("on") == 0 || VALUE.find("yes") == 0) {
CONFIGENTRY->intValue = 1;
} else if (VALUE.find("false") == 0 || VALUE.find("off") == 0 || VALUE.find("no") == 0) {