mirror of
https://github.com/overte-org/overte.git
synced 2025-06-05 07:22:27 +02:00
Support HTML colors in overlays
This commit is contained in:
parent
817c4147d6
commit
54b7a063e2
2 changed files with 18 additions and 13 deletions
|
@ -66,16 +66,7 @@ Overlay::~Overlay() {
|
||||||
|
|
||||||
void Overlay::setProperties(const QScriptValue& properties) {
|
void Overlay::setProperties(const QScriptValue& properties) {
|
||||||
QScriptValue color = properties.property("color");
|
QScriptValue color = properties.property("color");
|
||||||
if (color.isValid()) {
|
xColorFromScriptValue(properties.property("color"), _color);
|
||||||
QScriptValue red = color.property("red");
|
|
||||||
QScriptValue green = color.property("green");
|
|
||||||
QScriptValue blue = color.property("blue");
|
|
||||||
if (red.isValid() && green.isValid() && blue.isValid()) {
|
|
||||||
_color.red = red.toVariant().toInt();
|
|
||||||
_color.green = green.toVariant().toInt();
|
|
||||||
_color.blue = blue.toVariant().toInt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (properties.property("alpha").isValid()) {
|
if (properties.property("alpha").isValid()) {
|
||||||
setAlpha(properties.property("alpha").toVariant().toFloat());
|
setAlpha(properties.property("alpha").toVariant().toFloat());
|
||||||
|
|
|
@ -197,9 +197,23 @@ QScriptValue xColorToScriptValue(QScriptEngine *engine, const xColor& color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void xColorFromScriptValue(const QScriptValue &object, xColor& color) {
|
void xColorFromScriptValue(const QScriptValue &object, xColor& color) {
|
||||||
color.red = object.property("red").toVariant().toInt();
|
if (!object.isValid()) {
|
||||||
color.green = object.property("green").toVariant().toInt();
|
return;
|
||||||
color.blue = object.property("blue").toVariant().toInt();
|
}
|
||||||
|
if (object.isNumber()) {
|
||||||
|
color.red = color.green = color.blue = (uint8_t)object.toUInt32();
|
||||||
|
} else if (object.isString()) {
|
||||||
|
QColor qcolor(object.toString());
|
||||||
|
if (qcolor.isValid()) {
|
||||||
|
color.red = (uint8_t)qcolor.red();
|
||||||
|
color.blue = (uint8_t)qcolor.blue();
|
||||||
|
color.green = (uint8_t)qcolor.green();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
color.red = object.property("red").toVariant().toInt();
|
||||||
|
color.green = object.property("green").toVariant().toInt();
|
||||||
|
color.blue = object.property("blue").toVariant().toInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue qColorToScriptValue(QScriptEngine* engine, const QColor& color) {
|
QScriptValue qColorToScriptValue(QScriptEngine* engine, const QColor& color) {
|
||||||
|
|
Loading…
Reference in a new issue