summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-06-21 18:05:56 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-06-21 18:05:56 (GMT)
commit286a3d119ec95b235b09935296450ec36e640aeb (patch)
tree9146c0ebb21745bb985d24378829929ce92529e2 /Swiften/Whiteboard/Elements
parente0c79b3b885f126a2a2a34cb0d5df90796821130 (diff)
downloadswift-contrib-286a3d119ec95b235b09935296450ec36e640aeb.zip
swift-contrib-286a3d119ec95b235b09935296450ec36e640aeb.tar.bz2
Added parsing and serialization of freehand path element
Diffstat (limited to 'Swiften/Whiteboard/Elements')
-rw-r--r--Swiften/Whiteboard/Elements/Color.cpp45
-rw-r--r--Swiften/Whiteboard/Elements/Color.h2
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h4
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h67
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardLineElement.h2
5 files changed, 80 insertions, 40 deletions
diff --git a/Swiften/Whiteboard/Elements/Color.cpp b/Swiften/Whiteboard/Elements/Color.cpp
index b614a2a..51b8460 100644
--- a/Swiften/Whiteboard/Elements/Color.cpp
+++ b/Swiften/Whiteboard/Elements/Color.cpp
@@ -5,6 +5,7 @@
*/
#include <Swiften/Whiteboard/Elements/Color.h>
+#include <Swiften/Base/String.cpp>
#include <cstdio>
#include <iomanip>
#include <sstream>
@@ -18,39 +19,18 @@ namespace Swift {
}
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_);
- }
+ int value = String::convertHexStringToInt(hex.substr(1));
+ red_ = (value >> 16)&0xFF;
+ green_ = (value >> 8)&0xFF;
+ blue_ = value&0xFF;
}
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";
+ std::string value = String::convertIntToHexString((red_ << 16) + (green_ << 8) + blue_);
+ while (value.size() < 6) {
+ value.insert(0, "0");
}
- result += hex;
- return result;
+ return "#"+value;
}
int Color::getRed() const {
@@ -72,11 +52,4 @@ namespace Swift {
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
index b7cca5a..7227eca 100644
--- a/Swiften/Whiteboard/Elements/Color.h
+++ b/Swiften/Whiteboard/Elements/Color.h
@@ -22,8 +22,6 @@ namespace Swift {
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/WhiteboardElementVisitor.h b/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h
index b5fd546..d546e7f 100644
--- a/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h
+++ b/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h
@@ -8,10 +8,12 @@
namespace Swift {
class WhiteboardLineElement;
+ class WhiteboardFreehandPathElement;
class WhiteboardElementVisitor {
public:
virtual ~WhiteboardElementVisitor() {}
- virtual void visit(const WhiteboardLineElement* /*element*/) = 0;
+ virtual void visit(WhiteboardLineElement& /*element*/) = 0;
+ virtual void visit(WhiteboardFreehandPathElement& /*element*/) = 0;
};
}
diff --git a/Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h b/Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h
new file mode 100644
index 0000000..9b69dc4
--- /dev/null
+++ b/Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h
@@ -0,0 +1,67 @@
+/*
+ * 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>
+
+#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 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:
+
+ std::vector<Point> points_;
+ Color color_;
+ int penWidth_;
+ std::string id_;
+ };
+}
diff --git a/Swiften/Whiteboard/Elements/WhiteboardLineElement.h b/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
index 0088189..20455b6 100644
--- a/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
+++ b/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
@@ -62,7 +62,7 @@ namespace Swift {
}
void accept(WhiteboardElementVisitor& visitor) {
- visitor.visit(this);
+ visitor.visit(*this);
}
private: