summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Parser/PayloadParsers/WhiteboardParser.cpp14
-rw-r--r--Swiften/SConscript1
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp12
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h4
-rw-r--r--Swiften/Whiteboard/Elements/Color.cpp82
-rw-r--r--Swiften/Whiteboard/Elements/Color.h30
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardLineElement.h29
7 files changed, 168 insertions, 4 deletions
diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
index ef3c119..d0fa9f9 100644
--- a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
+++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
@@ -6,6 +6,7 @@
#include <Swiften/Parser/PayloadParsers/WhiteboardParser.h>
#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h>
+#include <Swiften/Whiteboard/Elements/Color.h>
#include <boost/optional.hpp>
#include <boost/smart_ptr/make_shared.hpp>
@@ -23,6 +24,19 @@ namespace Swift {
int x2 = std::atoi(attributes.getAttributeValue("x2").get_value_or("0").c_str());
int y2 = std::atoi(attributes.getAttributeValue("y2").get_value_or("0").c_str());
WhiteboardLineElement::ref whiteboardElement = boost::make_shared<WhiteboardLineElement>(x1, y1, x2, y2);
+ Color color(attributes.getAttributeValue("stroke").get_value_or("#00000"));
+
+ std::string opacity = attributes.getAttributeValue("opacity").get_value_or("1");
+ if (opacity.find('.') != std::string::npos) {
+ opacity = opacity.substr(opacity.find('.')+1, 2);
+ color.setAlpha(std::atoi(opacity.c_str())*255/100);
+ }
+
+ whiteboardElement->setColor(color);
+
+ int penWidth = std::atoi(attributes.getAttributeValue("stroke-width").get_value_or("1").c_str());
+ whiteboardElement->setPenWidth(penWidth);
+
getPayloadInternal()->setElement(whiteboardElement);
}
}
diff --git a/Swiften/SConscript b/Swiften/SConscript
index 1fa47ca..140f696 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -206,6 +206,7 @@ if env["SCONS_STAGE"] == "build" :
"Whiteboard/IncomingWhiteboardSession.cpp",
"Whiteboard/OutgoingWhiteboardSession.cpp",
"Whiteboard/WhiteboardSessionManager.cpp",
+ "Whiteboard/Elements/Color.cpp",
]
SConscript(dirs = [
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
index def21b1..f02791c 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
@@ -16,9 +16,19 @@ namespace Swift {
element->setAttribute("y1", intToStr(line->y1()));
element->setAttribute("x2", intToStr(line->x2()));
element->setAttribute("y2", intToStr(line->y2()));
+ element->setAttribute("id", line->getID());
+ element->setAttribute("stroke", line->getColor().toHex());
+ element->setAttribute("stroke-width", intToStr(line->getPenWidth()));
+ int alpha = line->getColor().getAlpha();
+ int opacity = 100*alpha/254;
+ if (opacity == 100) {
+ element->setAttribute("opacity", "1");
+ } else {
+ element->setAttribute("opacity", "."+intToStr(opacity));
+ }
}
- std::string WhiteboardElementSerializingVisitor::intToStr(const int t) {
+ std::string WhiteboardElementSerializingVisitor::intToStr(const int t) const {
std::stringstream ss;
ss << t;
return ss.str();
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
index 219ebcc..50cf252 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
@@ -19,8 +19,8 @@ namespace Swift {
XMLElement::ref getResult() const;
private:
- std::string intToStr(const int t);
-
+ std::string intToStr(const int t) const;
+
XMLElement::ref element;
};
diff --git a/Swiften/Whiteboard/Elements/Color.cpp b/Swiften/Whiteboard/Elements/Color.cpp
new file mode 100644
index 0000000..b614a2a
--- /dev/null
+++ b/Swiften/Whiteboard/Elements/Color.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Whiteboard/Elements/Color.h>
+#include <cstdio>
+#include <iomanip>
+#include <sstream>
+#include <iostream>
+
+namespace Swift {
+ Color::Color() : red_(0), green_(0), blue_(0), alpha_(255) {
+ }
+
+ Color::Color(int red, int green, int blue, int alpha) : red_(red), green_(green), blue_(blue), alpha_(alpha) {
+ }
+
+ 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_);
+ }
+ }
+
+ 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";
+ }
+ result += hex;
+ return result;
+ }
+
+ int Color::getRed() const {
+ return red_;
+ }
+
+ int Color::getGreen() const {
+ return green_;
+ }
+
+ int Color::getBlue() const {
+ return blue_;
+ }
+
+ int Color::getAlpha() const {
+ return alpha_;
+ }
+
+ 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();
+ }
+}
diff --git a/Swiften/Whiteboard/Elements/Color.h b/Swiften/Whiteboard/Elements/Color.h
new file mode 100644
index 0000000..b7cca5a
--- /dev/null
+++ b/Swiften/Whiteboard/Elements/Color.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <string>
+
+namespace Swift {
+ class Color {
+ public:
+ Color();
+ Color(int red, int green, int blue, int alpha = 255);
+ Color(const std::string& hex);
+ std::string toHex() const;
+ int getRed() const;
+ int getGreen() const;
+ int getBlue() const;
+ int getAlpha() const;
+ void setAlpha(int alpha);
+
+ private:
+ std::string intToStr(int t, int base = 10) const;
+
+ int red_, green_, blue_;
+ int alpha_;
+ };
+}
diff --git a/Swiften/Whiteboard/Elements/WhiteboardLineElement.h b/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
index b64e397..0088189 100644
--- a/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
+++ b/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
@@ -7,6 +7,7 @@
#pragma once
#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
+#include <Swiften/Whiteboard/Elements/Color.h>
namespace Swift {
class WhiteboardLineElement : public WhiteboardElement {
@@ -36,12 +37,38 @@ namespace Swift {
return y2_;
}
+ const Color& getColor() const {
+ return color_;
+ }
+
+ void setColor(const Color& color) {
+ color_ = color;
+ }
+
+ std::string getID() const {
+ return id_;
+ }
+
+ void setID(const std::string& id) {
+ id_ = id;
+ }
+
+ int getPenWidth() const {
+ return penWidth_;
+ }
+
+ void setPenWidth(const int penWidth) {
+ penWidth_ = penWidth;
+ }
+
void accept(WhiteboardElementVisitor& visitor) {
visitor.visit(this);
}
private:
int x1_, y1_, x2_, y2_;
- std::string id;
+ Color color_;
+ int penWidth_;
+ std::string id_;
};
}