summaryrefslogtreecommitdiff
path: root/src/transform.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-07-11 01:54:20 (GMT)
committerMarius Kintel <marius@kintel.net>2011-07-11 01:54:20 (GMT)
commit21ac6c05d16e9b2eca360dbbe684335ee2431af6 (patch)
tree7c5c3215565f872d83af4190437c38a6edd3d760 /src/transform.cc
parent65a5df881092d89e90e71e180c689a711770c801 (diff)
parent381a31199755a205189534fe727a9e8167f0715c (diff)
merged in recent changes in master
Diffstat (limited to 'src/transform.cc')
-rw-r--r--src/transform.cc49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/transform.cc b/src/transform.cc
index 4238250..d75c6a7 100644
--- a/src/transform.cc
+++ b/src/transform.cc
@@ -35,6 +35,7 @@
#include "printutils.h"
#include "visitor.h"
#include <sstream>
+#include <vector>
#include <assert.h>
enum transform_type_e {
@@ -54,6 +55,31 @@ public:
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
};
+using std::string;
+using std::vector;
+
+static vector<string> split(const string &str, const string &delim)
+{
+ assert(delim.size() > 0);
+
+ vector<string> strvec;
+ size_t start = 0, end = 0;
+ while (end != string::npos) {
+ end = str.find(delim, start);
+ // If at end, use length=maxLength. Else use length=end-start.
+ strvec.push_back(str.substr(start, (end == string::npos) ? string::npos : end - start));
+ // If at end, use start=maxSize. Else use start=end+delimiter.
+ start = ((end > (string::npos - delim.size())) ? string::npos : end + delim.size());
+ }
+ return strvec;
+}
+
+template <class T> static bool from_string(T &t, const string &s)
+{
+ std::istringstream iss(s);
+ return !(iss >> t).fail();
+}
+
AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const
{
TransformNode *node = new TransformNode(inst);
@@ -222,6 +248,25 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
if (v.type == Value::VECTOR) {
for (int i = 0; i < 4; i++)
node->matrix[16+i] = i < v.vec.size() ? v.vec[i]->num : 1.0;
+// FIXME: Port to non-Qt
+#if 0
+ } else if (v.type == Value::STRING) {
+ double alpha = 1.0;
+ vector<string> chunks = split(v.text, ",");
+ string colorname = chunks[0];
+ if (chunks.size() < 2 || !from_string(alpha, chunks[1])) alpha = 1.0;
+ QColor color;
+ color.setNamedColor(colorname);
+ if (color.isValid()) {
+ node->m[16+0] = color.redF();
+ node->m[16+1] = color.greenF();
+ node->m[16+2] = color.blueF();
+ node->m[16+3] = alpha;
+ } else {
+ PRINTF_NOCACHE("WARNING: Color name \"%s\" unknown. Please see",v.text.toUtf8().data());
+ PRINTF_NOCACHE("WARNING: http://en.wikipedia.org/wiki/Web_colors");
+ }
+#endif
}
}
@@ -234,7 +279,7 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
return node;
}
-std::string TransformNode::toString() const
+string TransformNode::toString() const
{
std::stringstream stream;
@@ -259,7 +304,7 @@ std::string TransformNode::toString() const
return stream.str();
}
-std::string TransformNode::name() const
+string TransformNode::name() const
{
return "transform";
}
contact: Jan Huwald // Impressum