diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-05-30 12:40:27 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2012-09-08 16:14:27 (GMT) |
commit | fe8a8aa031da734f3112184420b372021d9e10c7 (patch) | |
tree | 9f8e0b7d11d7612eb25a8682cf940fa647ca67f2 /Swiften/Elements/Whiteboard | |
parent | 0174723efbc1f612433d45c6916a2ad4596b96ba (diff) | |
download | swift-fe8a8aa031da734f3112184420b372021d9e10c7.zip swift-fe8a8aa031da734f3112184420b372021d9e10c7.tar.bz2 |
Support whiteboarding.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/Elements/Whiteboard')
14 files changed, 692 insertions, 0 deletions
diff --git a/Swiften/Elements/Whiteboard/WhiteboardColor.cpp b/Swiften/Elements/Whiteboard/WhiteboardColor.cpp new file mode 100644 index 0000000..f4ff01a --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardColor.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Elements/Whiteboard/WhiteboardColor.h> +#include <Swiften/Base/String.h> +#include <cstdio> +#include <iomanip> +#include <sstream> +#include <iostream> + +namespace Swift { + WhiteboardColor::WhiteboardColor() : red_(0), green_(0), blue_(0), alpha_(255) { + } + + WhiteboardColor::WhiteboardColor(int red, int green, int blue, int alpha) : red_(red), green_(green), blue_(blue), alpha_(alpha) { + } + + WhiteboardColor::WhiteboardColor(const std::string& hex) : alpha_(255) { + int value = String::convertHexStringToInt(hex.substr(1)); + red_ = (value >> 16)&0xFF; + green_ = (value >> 8)&0xFF; + blue_ = value&0xFF; + } + + std::string WhiteboardColor::toHex() const { + std::string value = String::convertIntToHexString((red_ << 16) + (green_ << 8) + blue_); + while (value.size() < 6) { + value.insert(0, "0"); + } + return "#"+value; + } + + int WhiteboardColor::getRed() const { + return red_; + } + + int WhiteboardColor::getGreen() const { + return green_; + } + + int WhiteboardColor::getBlue() const { + return blue_; + } + + int WhiteboardColor::getAlpha() const { + return alpha_; + } + + void WhiteboardColor::setAlpha(int alpha) { + alpha_ = alpha; + } +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardColor.h b/Swiften/Elements/Whiteboard/WhiteboardColor.h new file mode 100644 index 0000000..a940338 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardColor.h @@ -0,0 +1,28 @@ +/* + * 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 WhiteboardColor { + public: + WhiteboardColor(); + WhiteboardColor(int red, int green, int blue, int alpha = 255); + WhiteboardColor(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: + int red_, green_, blue_; + int alpha_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardDeleteOperation.h b/Swiften/Elements/Whiteboard/WhiteboardDeleteOperation.h new file mode 100644 index 0000000..091ee30 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardDeleteOperation.h @@ -0,0 +1,32 @@ +/* + * 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/Elements/Whiteboard/WhiteboardOperation.h> + +#include <Swiften/Elements/Whiteboard/WhiteboardElement.h> + +namespace Swift { + class WhiteboardDeleteOperation : public WhiteboardOperation { + public: + typedef boost::shared_ptr<WhiteboardDeleteOperation> ref; + public: + ~WhiteboardDeleteOperation() { + } + + std::string getElementID() const { + return elementID_; + } + + void setElementID(const std::string& elementID) { + elementID_ = elementID; + } + + private: + std::string elementID_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardElement.h b/Swiften/Elements/Whiteboard/WhiteboardElement.h new file mode 100644 index 0000000..df774d9 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardElement.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> +#include <Swiften/Elements/Whiteboard/WhiteboardElementVisitor.h> + +namespace Swift { + class WhiteboardElement { + public: + typedef boost::shared_ptr<WhiteboardElement> ref; + + public: + virtual ~WhiteboardElement() {} + virtual void accept(WhiteboardElementVisitor& visitor) = 0; + + const std::string& getID() const { + return id_; + } + + void setID(const std::string& id) { + id_ = id; + } + + private: + std::string id_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardElementVisitor.h b/Swiften/Elements/Whiteboard/WhiteboardElementVisitor.h new file mode 100644 index 0000000..413d6cf --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardElementVisitor.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +namespace Swift { + class WhiteboardLineElement; + class WhiteboardFreehandPathElement; + class WhiteboardRectElement; + class WhiteboardPolygonElement; + class WhiteboardTextElement; + class WhiteboardEllipseElement; + + class WhiteboardElementVisitor { + public: + virtual ~WhiteboardElementVisitor() {} + virtual void visit(WhiteboardLineElement& /*element*/) = 0; + virtual void visit(WhiteboardFreehandPathElement& /*element*/) = 0; + 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/Elements/Whiteboard/WhiteboardEllipseElement.h b/Swiften/Elements/Whiteboard/WhiteboardEllipseElement.h new file mode 100644 index 0000000..0078479 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardEllipseElement.h @@ -0,0 +1,74 @@ +/* + * 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/Elements/Whiteboard/WhiteboardElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardColor.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 WhiteboardColor& getPenColor() const { + return penColor_; + } + + void setPenColor(const WhiteboardColor& color) { + penColor_ = color; + } + + const WhiteboardColor& getBrushColor() const { + return brushColor_; + } + + void setBrushColor(const WhiteboardColor& color) { + brushColor_ = color; + } + + 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_; + WhiteboardColor penColor_; + WhiteboardColor brushColor_; + int penWidth_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardFreehandPathElement.h b/Swiften/Elements/Whiteboard/WhiteboardFreehandPathElement.h new file mode 100644 index 0000000..bcf3bf9 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardFreehandPathElement.h @@ -0,0 +1,57 @@ +/* + * 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/Elements/Whiteboard/WhiteboardElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardColor.h> + +#include <vector> +#include <utility> + +namespace Swift { + class WhiteboardFreehandPathElement : public WhiteboardElement { + typedef std::pair<int, int> Point; + public: + typedef boost::shared_ptr<WhiteboardFreehandPathElement> ref; + public: + WhiteboardFreehandPathElement() { + } + + void setPoints(const std::vector<Point>& points) { + points_ = points; + } + + const std::vector<Point>& getPoints() const { + return points_; + } + + const WhiteboardColor& getColor() const { + return color_; + } + + void setColor(const WhiteboardColor& color) { + color_ = color; + } + + int getPenWidth() const { + return penWidth_; + } + + void setPenWidth(const int penWidth) { + penWidth_ = penWidth; + } + + void accept(WhiteboardElementVisitor& visitor) { + visitor.visit(*this); + } + + private: + std::vector<Point> points_; + WhiteboardColor color_; + int penWidth_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardInsertOperation.h b/Swiften/Elements/Whiteboard/WhiteboardInsertOperation.h new file mode 100644 index 0000000..8c20044 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardInsertOperation.h @@ -0,0 +1,32 @@ +/* + * 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/Elements/Whiteboard/WhiteboardOperation.h> + +#include <Swiften/Elements/Whiteboard/WhiteboardElement.h> + +namespace Swift { + class WhiteboardInsertOperation : public WhiteboardOperation { + public: + typedef boost::shared_ptr<WhiteboardInsertOperation> ref; + public: + ~WhiteboardInsertOperation() { + } + + WhiteboardElement::ref getElement() const { + return element_; + } + + void setElement(WhiteboardElement::ref element) { + element_ = element; + } + + private: + WhiteboardElement::ref element_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardLineElement.h b/Swiften/Elements/Whiteboard/WhiteboardLineElement.h new file mode 100644 index 0000000..3c63afc --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardLineElement.h @@ -0,0 +1,65 @@ +/* + * 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/Elements/Whiteboard/WhiteboardElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardColor.h> + +namespace Swift { + class WhiteboardLineElement : public WhiteboardElement { + public: + typedef boost::shared_ptr<WhiteboardLineElement> ref; + public: + WhiteboardLineElement(int x1, int y1, int x2, int y2) { + x1_ = x1; + y1_ = y1; + x2_ = x2; + y2_ = y2; + } + + int x1() const { + return x1_; + } + + int y1() const { + return y1_; + } + + int x2() const { + return x2_; + } + + int y2() const { + return y2_; + } + + const WhiteboardColor& getColor() const { + return color_; + } + + void setColor(const WhiteboardColor& color) { + color_ = color; + } + + 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_; + WhiteboardColor color_; + int penWidth_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardOperation.h b/Swiften/Elements/Whiteboard/WhiteboardOperation.h new file mode 100644 index 0000000..02c6438 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardOperation.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <boost/smart_ptr/shared_ptr.hpp> +#include <string> + +namespace Swift { + class WhiteboardOperation { + public: + typedef boost::shared_ptr<WhiteboardOperation> ref; + public: + virtual ~WhiteboardOperation(){}; + + std::string getID() const { + return id_; + } + + void setID(const std::string& id) { + id_ = id; + } + + std::string getParentID() const { + return parentID_; + } + + void setParentID(const std::string& parentID) { + parentID_ = parentID; + } + + int getPos() const { + return pos_; + } + + void setPos(int pos) { + pos_ = pos; + } + + private: + std::string id_; + std::string parentID_; + int pos_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardPolygonElement.h b/Swiften/Elements/Whiteboard/WhiteboardPolygonElement.h new file mode 100644 index 0000000..679ac01 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardPolygonElement.h @@ -0,0 +1,63 @@ +/* + * 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/Elements/Whiteboard/WhiteboardElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardColor.h> + +namespace Swift { + class WhiteboardPolygonElement : public WhiteboardElement { + typedef std::pair<int, int> Point; + public: + typedef boost::shared_ptr<WhiteboardPolygonElement> ref; + public: + WhiteboardPolygonElement() { + } + + const std::vector<Point>& getPoints() const { + return points_; + } + + void setPoints(const std::vector<Point>& points) { + points_ = points; + } + + const WhiteboardColor& getPenColor() const { + return penColor_; + } + + void setPenColor(const WhiteboardColor& color) { + penColor_ = color; + } + + const WhiteboardColor& getBrushColor() const { + return brushColor_; + } + + void setBrushColor(const WhiteboardColor& color) { + brushColor_ = color; + } + + int getPenWidth() const { + return penWidth_; + } + + void setPenWidth(const int penWidth) { + penWidth_ = penWidth; + } + + void accept(WhiteboardElementVisitor& visitor) { + visitor.visit(*this); + } + + private: + std::vector<Point> points_; + WhiteboardColor penColor_; + WhiteboardColor brushColor_; + int penWidth_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardRectElement.h b/Swiften/Elements/Whiteboard/WhiteboardRectElement.h new file mode 100644 index 0000000..233b3fa --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardRectElement.h @@ -0,0 +1,74 @@ +/* + * 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/Elements/Whiteboard/WhiteboardElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardColor.h> + +namespace Swift { + class WhiteboardRectElement : public WhiteboardElement { + public: + typedef boost::shared_ptr<WhiteboardRectElement> ref; + public: + WhiteboardRectElement(int x, int y, int width, int height) { + x_ = x; + y_ = y; + width_ = width; + height_ = height; + } + + int getX() const { + return x_; + } + + int getY() const { + return y_; + } + + int getWidth() const { + return width_; + } + + int getHeight() const { + return height_; + } + + const WhiteboardColor& getPenColor() const { + return penColor_; + } + + void setPenColor(const WhiteboardColor& color) { + penColor_ = color; + } + + const WhiteboardColor& getBrushColor() const { + return brushColor_; + } + + void setBrushColor(const WhiteboardColor& color) { + brushColor_ = color; + } + + int getPenWidth() const { + return penWidth_; + } + + void setPenWidth(const int penWidth) { + penWidth_ = penWidth; + } + + void accept(WhiteboardElementVisitor& visitor) { + visitor.visit(*this); + } + + private: + int x_, y_, width_, height_; + WhiteboardColor penColor_; + WhiteboardColor brushColor_; + int penWidth_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardTextElement.h b/Swiften/Elements/Whiteboard/WhiteboardTextElement.h new file mode 100644 index 0000000..7118ac9 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardTextElement.h @@ -0,0 +1,64 @@ +/* + * 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/Elements/Whiteboard/WhiteboardElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardColor.h> + +namespace Swift { + class WhiteboardTextElement : public WhiteboardElement { + public: + typedef boost::shared_ptr<WhiteboardTextElement> ref; + public: + WhiteboardTextElement(int x, int y) { + x_ = x; + y_ = y; + } + + void setText(const std::string text) { + text_ = text; + } + + const std::string& getText() const { + return text_; + } + + int getX() const { + return x_; + } + + int getY() const { + return y_; + } + + const WhiteboardColor& getColor() const { + return color_; + } + + void setColor(const WhiteboardColor& color) { + color_ = color; + } + + int getSize() const { + return size_; + } + + void setSize(const int size) { + size_ = size; + } + + void accept(WhiteboardElementVisitor& visitor) { + visitor.visit(*this); + } + + private: + int x_, y_; + int size_; + std::string text_; + WhiteboardColor color_; + }; +} diff --git a/Swiften/Elements/Whiteboard/WhiteboardUpdateOperation.h b/Swiften/Elements/Whiteboard/WhiteboardUpdateOperation.h new file mode 100644 index 0000000..a52a341 --- /dev/null +++ b/Swiften/Elements/Whiteboard/WhiteboardUpdateOperation.h @@ -0,0 +1,41 @@ +/* + * 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/Elements/Whiteboard/WhiteboardOperation.h> + +#include <Swiften/Elements/Whiteboard/WhiteboardElement.h> + +namespace Swift { + class WhiteboardUpdateOperation : public WhiteboardOperation { + public: + typedef boost::shared_ptr<WhiteboardUpdateOperation> ref; + public: + ~WhiteboardUpdateOperation() { + } + + WhiteboardElement::ref getElement() const { + return element_; + } + + void setElement(WhiteboardElement::ref element) { + element_ = element; + } + + int getNewPos() const { + return newPos_; + } + + void setNewPos(int newPos) { + newPos_ = newPos; + } + + private: + WhiteboardElement::ref element_; + int newPos_; + }; +} |