From 377880eca6d9d0cace2c43a12a131b67661192d3 Mon Sep 17 00:00:00 2001 From: Tametomo Date: Mon, 20 Apr 2009 07:44:26 -0600 Subject: Changed palette colors to be once again stored in a human readable format once again. This was originally reverted because it caused a regression on Windows, but not Linux, which was later found out to be because there's a Linux kernel function which will convert hex strings into an integer format, while Windows doesn't share the same luxury. So, to avoid any issues, this commit adds an atox (ascii to hex) string utility, and uses it when parsing hex strings for colors from the configuration file. Also ensured that people who have colors saved in the old, raw integer format can get their colors converted to hex values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tametomo Signed-off-by: Bjørn Lindeijer --- src/gui/palette.cpp | 16 ++++++++++++++-- src/utils/stringutils.cpp | 11 +++++++++-- src/utils/stringutils.h | 8 ++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 897c7efd..855487d3 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -152,7 +152,11 @@ Palette::~Palette() config.setValue(*configName + "Delay", col->delay); if (col->grad == STATIC || col->grad == PULSE) - config.setValue(*configName, toString(col->getRGB())); + { + char buffer[20]; + sprintf(buffer, "0x%06x", col->getRGB()); + config.setValue(*configName, buffer); + } } } @@ -265,7 +269,15 @@ void Palette::addColor(Palette::ColorType type, int rgb, char c, int delay) { const std::string *configName = &ColorTypeNames[type]; - gcn::Color trueCol = (int) config.getValue(*configName, rgb); + char buffer[20]; + sprintf(buffer, "0x%06x", rgb); + const std::string rgbString = config.getValue(*configName, buffer); + unsigned int rgbValue = 0; + if (rgbString.length() == 8 && rgbString[0] == '0' && rgbString[1] == 'x') + rgbValue = atox(rgbString); + else + rgbValue = atoi(rgbString.c_str()); + gcn::Color trueCol = rgbValue; grad = (GradientType) config.getValue(*configName + "Gradient", grad); delay = (int) config.getValue(*configName + "Delay", delay); mColVector[type].set(type, trueCol, grad, text, c, delay); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 2f9bc9a8..57a0131e 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -30,10 +30,9 @@ std::string &trim(std::string &str) { str.erase(pos + 1); pos = str.find_first_not_of(' '); + if (pos != std::string::npos) - { str.erase(0, pos); - } } else { @@ -49,6 +48,14 @@ std::string &toLower(std::string &str) return str; } +unsigned int atox(const std::string &str) +{ + unsigned int value; + sscanf(str.c_str(), "0x%06x", &value); + + return value; +} + const char *ipToString(int address) { static char asciiIP[16]; diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 872a8f52..3af0bfa5 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -41,6 +41,14 @@ std::string &trim(std::string &str); */ std::string &toLower(std::string &str); +/** + * Converts an ascii hexidecimal string to an integer + * + * @param str the hex string to convert to an int + * @return the integer representation of the hex string + */ +unsigned int atox(const std::string &str); + /** * Converts the given value to a string using std::stringstream. * -- cgit v1.2.3-70-g09d2