summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Whiteboard')
-rw-r--r--Swiften/Whiteboard/Elements/Color.cpp82
-rw-r--r--Swiften/Whiteboard/Elements/Color.h30
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardLineElement.h29
3 files changed, 140 insertions, 1 deletions
diff --git a/Swiften/Whiteboard/Elements/Color.cpp b/Swiften/Whiteboard/Elements/Color.cpp
new file mode 100644
index 0000000..b614a2a
--- /dev/null
+++ b/Swiften/Whiteboard/Elements/Color.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Whiteboard/Elements/Color.h>
+#include <cstdio>
+#include <iomanip>
+#include <sstream>
+#include <iostream>
+
+namespace Swift {
+ Color::Color() : red_(0), green_(0), blue_(0), alpha_(255) {
+ }
+
+ Color::Color(int red, int green, int blue, int alpha) : red_(red), green_(green), blue_(blue), alpha_(alpha) {
+ }
+
+ 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_);
+ }
+ }
+
+ 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";
+ }
+ result += hex;
+ return result;
+ }
+
+ int Color::getRed() const {
+ return red_;
+ }
+
+ int Color::getGreen() const {
+ return green_;
+ }
+
+ int Color::getBlue() const {
+ return blue_;
+ }
+
+ int Color::getAlpha() const {
+ return alpha_;
+ }
+
+ 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
new file mode 100644
index 0000000..b7cca5a
--- /dev/null
+++ b/Swiften/Whiteboard/Elements/Color.h
@@ -0,0 +1,30 @@
+/*
+ * 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 Color {
+ public:
+ Color();
+ Color(int red, int green, int blue, int alpha = 255);
+ Color(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:
+ std::string intToStr(int t, int base = 10) const;
+
+ int red_, green_, blue_;
+ int alpha_;
+ };
+}
diff --git a/Swiften/Whiteboard/Elements/WhiteboardLineElement.h b/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
index b64e397..0088189 100644
--- a/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
+++ b/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
@@ -7,6 +7,7 @@
#pragma once
#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
+#include <Swiften/Whiteboard/Elements/Color.h>
namespace Swift {
class WhiteboardLineElement : public WhiteboardElement {
@@ -36,12 +37,38 @@ namespace Swift {
return y2_;
}
+ 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:
int x1_, y1_, x2_, y2_;
- std::string id;
+ Color color_;
+ int penWidth_;
+ std::string id_;
};
}