mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Script bindings for QColor.
This commit is contained in:
parent
ebcb8d00d6
commit
469e31cc05
4 changed files with 33 additions and 2 deletions
|
@ -55,7 +55,7 @@ SharedObjectPointer MetavoxelClientManager::findFirstRaySpannerIntersection(cons
|
|||
return closestSpanner;
|
||||
}
|
||||
|
||||
void MetavoxelClientManager::setSphere(const glm::vec3& center, float radius, QRgb color) {
|
||||
void MetavoxelClientManager::setSphere(const glm::vec3& center, float radius, const QColor& color) {
|
||||
Sphere* sphere = new Sphere();
|
||||
sphere->setTranslation(center);
|
||||
sphere->setScale(radius);
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
SharedObjectPointer findFirstRaySpannerIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
const AttributePointer& attribute, float& distance);
|
||||
|
||||
Q_INVOKABLE void setSphere(const glm::vec3& center, float radius, QRgb color = 0x808080);
|
||||
Q_INVOKABLE void setSphere(const glm::vec3& center, float radius, const QColor& color = QColor(Qt::gray));
|
||||
|
||||
Q_INVOKABLE void setSpanner(const SharedObjectPointer& object, bool reliable = false);
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QColor>
|
||||
|
||||
#include "RegisteredMetaTypes.h"
|
||||
|
||||
static int vec4MetaTypeId = qRegisterMetaType<glm::vec4>();
|
||||
|
@ -25,6 +27,7 @@ void registerMetaTypes(QScriptEngine* engine) {
|
|||
qScriptRegisterMetaType(engine, vec2toScriptValue, vec2FromScriptValue);
|
||||
qScriptRegisterMetaType(engine, quatToScriptValue, quatFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, xColorToScriptValue, xColorFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, qColorToScriptValue, qColorFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, pickRayToScriptValue, pickRayFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, collisionToScriptValue, collisionFromScriptValue);
|
||||
}
|
||||
|
@ -101,6 +104,29 @@ void xColorFromScriptValue(const QScriptValue &object, xColor& color) {
|
|||
color.blue = object.property("blue").toVariant().toInt();
|
||||
}
|
||||
|
||||
QScriptValue qColorToScriptValue(QScriptEngine* engine, const QColor& color) {
|
||||
QScriptValue object = engine->newObject();
|
||||
object.setProperty("red", color.red());
|
||||
object.setProperty("green", color.green());
|
||||
object.setProperty("blue", color.blue());
|
||||
object.setProperty("alpha", color.alpha());
|
||||
return object;
|
||||
}
|
||||
|
||||
void qColorFromScriptValue(const QScriptValue& object, QColor& color) {
|
||||
if (object.isNumber()) {
|
||||
color.setRgb(object.toUInt32());
|
||||
|
||||
} else if (object.isString()) {
|
||||
color.setNamedColor(object.toString());
|
||||
|
||||
} else {
|
||||
QScriptValue alphaValue = object.property("alpha");
|
||||
color.setRgb(object.property("red").toInt32(), object.property("green").toInt32(), object.property("blue").toInt32(),
|
||||
alphaValue.isNumber() ? alphaValue.toInt32() : 255);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay) {
|
||||
QScriptValue obj = engine->newObject();
|
||||
QScriptValue origin = vec3toScriptValue(engine, pickRay.origin);
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "CollisionInfo.h"
|
||||
#include "SharedUtil.h"
|
||||
|
||||
class QColor;
|
||||
|
||||
Q_DECLARE_METATYPE(glm::vec4)
|
||||
Q_DECLARE_METATYPE(glm::vec3)
|
||||
Q_DECLARE_METATYPE(glm::vec2)
|
||||
|
@ -42,6 +44,9 @@ void quatFromScriptValue(const QScriptValue &object, glm::quat& quat);
|
|||
QScriptValue xColorToScriptValue(QScriptEngine* engine, const xColor& color);
|
||||
void xColorFromScriptValue(const QScriptValue &object, xColor& color);
|
||||
|
||||
QScriptValue qColorToScriptValue(QScriptEngine* engine, const QColor& color);
|
||||
void qColorFromScriptValue(const QScriptValue& object, QColor& color);
|
||||
|
||||
class PickRay {
|
||||
public:
|
||||
PickRay() : origin(0), direction(0) { };
|
||||
|
|
Loading…
Reference in a new issue