diff options
author | Don Bright <hugh.m.bright@gmail.com> | 2011-07-04 21:22:43 (GMT) |
---|---|---|
committer | Giles Bathgate <gilesbathgate@gmail.com> | 2011-07-04 21:22:43 (GMT) |
commit | 5f8021e3e677d13b2ebc15dcd8229e1cf5944d8c (patch) | |
tree | a1c7e27e048309a5dadc646ba34dce86cdd7e53b /src/transform.cc | |
parent | 61b41fcb8e6c9632695e1fe794ac70f912e70f31 (diff) |
Allow the color() command to use names as well as numbers.
With fix for a bug where alpha of 0.0 was mishandled applied.
Diffstat (limited to 'src/transform.cc')
-rw-r--r-- | src/transform.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/transform.cc b/src/transform.cc index e841ef0..01bd808 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -227,6 +227,27 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti if (v.type == Value::VECTOR) { for (int i = 0; i < 4; i++) node->m[16+i] = i < v.vec.size() ? v.vec[i]->num : 1.0; + } else if (v.type == Value::STRING) { + double alpha = 1.0; + QString colorname = v.text; + if (v.text.contains(",")) { + QStringList chunks = v.text.split(","); + colorname = chunks[0]; + bool parseok; + alpha = chunks[1].toDouble(&parseok); + if (!parseok) 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"); + } } } |