diff options
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp | 75 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h | 7 |
2 files changed, 68 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) { diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h index 25642d0..4251cca 100644 --- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h @@ -9,6 +9,9 @@ #include <Swiften/Elements/WhiteboardPayload.h> #include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h> +#include <Swiften/Whiteboard/Elements/WhiteboardRectElement.h> +#include <Swiften/Whiteboard/Elements/WhiteboardPolygonElement.h> +#include <Swiften/Whiteboard/Elements/WhiteboardTextElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h> #include <Swiften/Serializer/GenericPayloadSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> @@ -18,10 +21,14 @@ namespace Swift { public: void visit(WhiteboardLineElement& line); void visit(WhiteboardFreehandPathElement& path); + void visit(WhiteboardRectElement& rect); + void visit(WhiteboardPolygonElement& polygon); + void visit(WhiteboardTextElement& text); XMLElement::ref getResult() const; private: std::string intToStr(const int t) const; + std::string alphaToOpacity(int alpha) const; XMLElement::ref element; }; |