summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp')
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp75
1 files changed, 61 insertions, 14 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
index b5a4c49..5ce8c20 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
@@ -21,13 +21,7 @@ namespace Swift {
element->setAttribute("id", line.getID());
element->setAttribute("stroke", line.getColor().toHex());
element->setAttribute("stroke-width", boost::lexical_cast<std::string>(line.getPenWidth()));
- int alpha = line.getColor().getAlpha();
- int opacity = 100*alpha/254;
- if (opacity == 100) {
- element->setAttribute("opacity", "1");
- } else {
- element->setAttribute("opacity", "."+boost::lexical_cast<std::string>(opacity));
- }
+ element->setAttribute("opacity", alphaToOpacity(line.getColor().getAlpha()));
} catch (boost::bad_lexical_cast&) {
}
}
@@ -38,13 +32,7 @@ namespace Swift {
element->setAttribute("stroke", path.getColor().toHex());
try {
element->setAttribute("stroke-width", boost::lexical_cast<std::string>(path.getPenWidth()));
- int alpha = path.getColor().getAlpha();
- int opacity = 100*alpha/254;
- if (opacity == 100) {
- element->setAttribute("opacity", "1");
- } else {
- element->setAttribute("opacity", "."+boost::lexical_cast<std::string>(opacity));
- }
+ element->setAttribute("opacity", alphaToOpacity(path.getColor().getAlpha()));
std::string pathData;
if (path.getPoints().size() != 0) {
std::vector<std::pair<int, int> >::const_iterator it = path.getPoints().begin();
@@ -58,6 +46,56 @@ namespace Swift {
}
}
+ void WhiteboardElementSerializingVisitor::visit(WhiteboardRectElement& rect) {
+ element = boost::make_shared<XMLElement>("rect");
+ try {
+ element->setAttribute("x", boost::lexical_cast<std::string>(rect.getX()));
+ element->setAttribute("y", boost::lexical_cast<std::string>(rect.getY()));
+ element->setAttribute("width", boost::lexical_cast<std::string>(rect.getWidth()));
+ element->setAttribute("height", boost::lexical_cast<std::string>(rect.getHeight()));
+ element->setAttribute("id", rect.getID());
+ element->setAttribute("stroke", rect.getPenColor().toHex());
+ element->setAttribute("fill", rect.getBrushColor().toHex());;
+ element->setAttribute("stroke-width", boost::lexical_cast<std::string>(rect.getPenWidth()));
+ element->setAttribute("opacity", alphaToOpacity(rect.getPenColor().getAlpha()));
+ element->setAttribute("fill-opacity", alphaToOpacity(rect.getBrushColor().getAlpha()));
+ } catch (boost::bad_lexical_cast&) {
+ }
+ }
+
+ void WhiteboardElementSerializingVisitor::visit(WhiteboardPolygonElement& polygon) {
+ element = boost::make_shared<XMLElement>("polygon");
+ try {
+ element->setAttribute("id", polygon.getID());
+ element->setAttribute("stroke", polygon.getPenColor().toHex());
+ element->setAttribute("fill", polygon.getBrushColor().toHex());;
+ element->setAttribute("stroke-width", boost::lexical_cast<std::string>(polygon.getPenWidth()));
+ element->setAttribute("opacity", alphaToOpacity(polygon.getPenColor().getAlpha()));
+ element->setAttribute("fill-opacity", alphaToOpacity(polygon.getBrushColor().getAlpha()));
+ std::string points;
+ std::vector<std::pair<int, int> >::const_iterator it = polygon.getPoints().begin();
+ for (; it != polygon.getPoints().end(); ++it) {
+ points += boost::lexical_cast<std::string>(it->first)+","+boost::lexical_cast<std::string>(it->second)+" ";
+ }
+ element->setAttribute("points", points);
+ } catch (boost::bad_lexical_cast&) {
+ }
+ }
+
+ void WhiteboardElementSerializingVisitor::visit(WhiteboardTextElement& text) {
+ element = boost::make_shared<XMLElement>("text");
+ try {
+ element->setAttribute("x", boost::lexical_cast<std::string>(text.getX()));
+ element->setAttribute("y", boost::lexical_cast<std::string>(text.getY()));
+ element->setAttribute("font-size", boost::lexical_cast<std::string>(text.getSize()));
+ element->setAttribute("id", text.getID());
+ element->setAttribute("fill", text.getColor().toHex());
+ element->setAttribute("opacity", alphaToOpacity(text.getColor().getAlpha()));
+ element->addNode(boost::make_shared<XMLTextNode>(text.getText()));
+ } catch (boost::bad_lexical_cast&) {
+ }
+ }
+
std::string WhiteboardElementSerializingVisitor::intToStr(const int t) const {
std::stringstream ss;
ss << t;
@@ -68,6 +106,15 @@ namespace Swift {
return element;
}
+ std::string WhiteboardElementSerializingVisitor::alphaToOpacity(int alpha) const {
+ int opacity = 100*alpha/254;
+ if (opacity == 100) {
+ return "1";
+ } else {
+ return "."+boost::lexical_cast<std::string>(opacity);
+ }
+ }
+
std::string WhiteboardSerializer::serializePayload(boost::shared_ptr<WhiteboardPayload> payload) const {
XMLElement element("wb");
if (payload->getType() == WhiteboardPayload::Data) {