diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-26 10:18:33 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-26 10:20:55 (GMT) |
commit | 99bc38e1d21b0081618485e49b0ab1bcd5bef22f (patch) | |
tree | 36a15ffaaa09832234d4296d926b3244a5952bfd /Swiften | |
parent | 06bbc72598ece3e62b82471e474b0753d5439f00 (diff) | |
download | swift-contrib-99bc38e1d21b0081618485e49b0ab1bcd5bef22f.zip swift-contrib-99bc38e1d21b0081618485e49b0ab1bcd5bef22f.tar.bz2 |
Added handling of circles(ellipses)
Diffstat (limited to 'Swiften')
5 files changed, 135 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp index d1d57a0..b5cfa7b 100644 --- a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp @@ -9,6 +9,7 @@ #include <Swiften/Whiteboard/Elements/WhiteboardRectElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardTextElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardPolygonElement.h> +#include <Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h> #include <Swiften/Whiteboard/Elements/Color.h> #include <boost/optional.hpp> @@ -168,6 +169,36 @@ namespace Swift { } else if (element == "text") { WhiteboardTextElement::ref whiteboardElement = boost::make_shared<WhiteboardTextElement>(0,0); getPayloadInternal()->setElement(whiteboardElement); + } else if (element == "ellipse") { + int cx = 0; + int cy = 0; + int rx = 0; + int ry = 0; + try { + cx = boost::lexical_cast<int>(attributes.getAttributeValue("cx").get_value_or("0")); + cy = boost::lexical_cast<int>(attributes.getAttributeValue("cy").get_value_or("0")); + rx = boost::lexical_cast<int>(attributes.getAttributeValue("rx").get_value_or("0")); + ry = boost::lexical_cast<int>(attributes.getAttributeValue("ry").get_value_or("0")); + } catch (boost::bad_lexical_cast&) { + } + + WhiteboardEllipseElement::ref whiteboardElement = boost::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry); + + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); + + Color penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); + Color brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); + penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); + whiteboardElement->setPenColor(penColor); + whiteboardElement->setBrushColor(brushColor); + + getPayloadInternal()->setElement(whiteboardElement); } } ++level_; diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp index 5ce8c20..a15d7ae 100644 --- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp @@ -96,6 +96,23 @@ namespace Swift { } } + void WhiteboardElementSerializingVisitor::visit(WhiteboardEllipseElement& ellipse) { + element = boost::make_shared<XMLElement>("ellipse"); + try { + element->setAttribute("cx", boost::lexical_cast<std::string>(ellipse.getCX())); + element->setAttribute("cy", boost::lexical_cast<std::string>(ellipse.getCY())); + element->setAttribute("rx", boost::lexical_cast<std::string>(ellipse.getRX())); + element->setAttribute("ry", boost::lexical_cast<std::string>(ellipse.getRY())); + element->setAttribute("id", ellipse.getID()); + element->setAttribute("stroke", ellipse.getPenColor().toHex()); + element->setAttribute("fill", ellipse.getBrushColor().toHex());; + element->setAttribute("stroke-width", boost::lexical_cast<std::string>(ellipse.getPenWidth())); + element->setAttribute("opacity", alphaToOpacity(ellipse.getPenColor().getAlpha())); + element->setAttribute("fill-opacity", alphaToOpacity(ellipse.getBrushColor().getAlpha())); + } catch (boost::bad_lexical_cast&) { + } + } + std::string WhiteboardElementSerializingVisitor::intToStr(const int t) const { std::stringstream ss; ss << t; diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h index 4251cca..cc25bd1 100644 --- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h @@ -12,6 +12,7 @@ #include <Swiften/Whiteboard/Elements/WhiteboardRectElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardPolygonElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardTextElement.h> +#include <Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h> #include <Swiften/Serializer/GenericPayloadSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> @@ -24,6 +25,7 @@ namespace Swift { void visit(WhiteboardRectElement& rect); void visit(WhiteboardPolygonElement& polygon); void visit(WhiteboardTextElement& text); + void visit(WhiteboardEllipseElement& ellipse); XMLElement::ref getResult() const; private: diff --git a/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h b/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h index 7244ad1..413d6cf 100644 --- a/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h +++ b/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h @@ -12,6 +12,7 @@ namespace Swift { class WhiteboardRectElement; class WhiteboardPolygonElement; class WhiteboardTextElement; + class WhiteboardEllipseElement; class WhiteboardElementVisitor { public: @@ -21,5 +22,6 @@ namespace Swift { virtual void visit(WhiteboardRectElement& /*element*/) = 0; virtual void visit(WhiteboardPolygonElement& /*element*/) = 0; virtual void visit(WhiteboardTextElement& /*element*/) = 0; + virtual void visit(WhiteboardEllipseElement& /*element*/) = 0; }; } diff --git a/Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h b/Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h new file mode 100644 index 0000000..8c74561 --- /dev/null +++ b/Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Whiteboard/Elements/WhiteboardElement.h> +#include <Swiften/Whiteboard/Elements/Color.h> + +namespace Swift { + class WhiteboardEllipseElement : public WhiteboardElement { + public: + typedef boost::shared_ptr<WhiteboardEllipseElement> ref; + public: + WhiteboardEllipseElement(int cx, int cy, int rx, int ry) { + cx_ = cx; + cy_ = cy; + rx_ = rx; + ry_ = ry; + } + + int getCX() const { + return cx_; + } + + int getCY() const { + return cy_; + } + + int getRX() const { + return rx_; + } + + int getRY() const { + return ry_; + } + + const Color& getPenColor() const { + return penColor_; + } + + void setPenColor(const Color& color) { + penColor_ = color; + } + + const Color& getBrushColor() const { + return brushColor_; + } + + void setBrushColor(const Color& color) { + brushColor_ = 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 cx_, cy_, rx_, ry_; + Color penColor_; + Color brushColor_; + int penWidth_; + std::string id_; + }; +} |