diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-21 18:05:56 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-21 18:05:56 (GMT) |
commit | 286a3d119ec95b235b09935296450ec36e640aeb (patch) | |
tree | 9146c0ebb21745bb985d24378829929ce92529e2 /Swiften/Whiteboard/Elements/Color.cpp | |
parent | e0c79b3b885f126a2a2a34cb0d5df90796821130 (diff) | |
download | swift-contrib-286a3d119ec95b235b09935296450ec36e640aeb.zip swift-contrib-286a3d119ec95b235b09935296450ec36e640aeb.tar.bz2 |
Added parsing and serialization of freehand path element
Diffstat (limited to 'Swiften/Whiteboard/Elements/Color.cpp')
-rw-r--r-- | Swiften/Whiteboard/Elements/Color.cpp | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/Swiften/Whiteboard/Elements/Color.cpp b/Swiften/Whiteboard/Elements/Color.cpp index b614a2a..51b8460 100644 --- a/Swiften/Whiteboard/Elements/Color.cpp +++ b/Swiften/Whiteboard/Elements/Color.cpp @@ -5,6 +5,7 @@ */ #include <Swiften/Whiteboard/Elements/Color.h> +#include <Swiften/Base/String.cpp> #include <cstdio> #include <iomanip> #include <sstream> @@ -18,39 +19,18 @@ namespace Swift { } Color::Color(const std::string& hex) : alpha_(255) { - if (hex.size() == 7) { - char temp[3]; - hex.copy(temp, 2, 1); - temp[2] = 0; - std::sscanf(temp, "%x", &red_); - hex.copy(temp, 2, 3); - temp[2] = 0; - std::sscanf(temp, "%x", &green_); - hex.copy(temp, 2, 5); - temp[2] = 0; - std::sscanf(temp, "%x", &blue_); - } + int value = String::convertHexStringToInt(hex.substr(1)); + red_ = (value >> 16)&0xFF; + green_ = (value >> 8)&0xFF; + blue_ = value&0xFF; } std::string Color::toHex() const { - std::string result = "#"; - std::string hex; - hex = intToStr(red_, 16); - if (hex.size() == 1) { - result += "0"; - } - result += hex; - hex = intToStr(green_, 16); - if (hex.size() == 1) { - result += "0"; - } - result += hex; - hex = intToStr(blue_, 16); - if (hex.size() == 1) { - result += "0"; + std::string value = String::convertIntToHexString((red_ << 16) + (green_ << 8) + blue_); + while (value.size() < 6) { + value.insert(0, "0"); } - result += hex; - return result; + return "#"+value; } int Color::getRed() const { @@ -72,11 +52,4 @@ namespace Swift { void Color::setAlpha(int alpha) { alpha_ = alpha; } - - std::string Color::intToStr(int t, int base) const { - std::stringstream ss; - ss << std::setbase(base); - ss << t; - return ss.str(); - } } |