Add property getting for all 2D overlays
This commit is contained in:
parent
8c3bedae9d
commit
725d56d41f
@ -168,7 +168,19 @@ var clipboardPreview = Overlays.addOverlay("clipboard", {
|
||||
|
||||
// Demonstrate retrieving overlay properties
|
||||
print("Text overlay text property value =\n" + Overlays.getProperty(text, "text"));
|
||||
print("Text overlay unknown property vale =\n" + Overlays.getProperty(text, "unknown")); // value = undefined
|
||||
print("Text overlay alpha =\n" + Overlays.getProperty(text, "alpha"));
|
||||
print("Text overlay visible =\n" + Overlays.getProperty(text, "visible"));
|
||||
print("Text overlay font size =\n" + Overlays.getProperty(text, "font").size);
|
||||
print("Text overlay anchor =\n" + Overlays.getProperty(text, "anchor"));
|
||||
print("Text overlay unknown property value =\n" + Overlays.getProperty(text, "unknown")); // value = undefined
|
||||
var sliderBounds = Overlays.getProperty(slider, "bounds");
|
||||
print("Slider overlay bounds =\n"
|
||||
+ "x: " + sliderBounds.x + "\n"
|
||||
+ "y: " + sliderBounds.y + "\n"
|
||||
+ "width: " + sliderBounds.width + "\n"
|
||||
+ "height: " + sliderBounds.height
|
||||
);
|
||||
|
||||
var cubePosition = Overlays.getProperty(cube, "position");
|
||||
print("Cube overlay position =\n"
|
||||
+ "x: " + cubePosition.x + "\n"
|
||||
|
@ -151,4 +151,18 @@ void ImageOverlay::setProperties(const QScriptValue& properties) {
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue ImageOverlay::getProperty(const QString& property) {
|
||||
if (property == "subImage") {
|
||||
QScriptValue subImage = _scriptEngine->newObject();
|
||||
subImage.setProperty("x", _fromImage.x());
|
||||
subImage.setProperty("y", _fromImage.y());
|
||||
subImage.setProperty("width", _fromImage.width());
|
||||
subImage.setProperty("height", _fromImage.height());
|
||||
return subImage;
|
||||
}
|
||||
if (property == "imageURL") {
|
||||
return _imageURL.toString();
|
||||
}
|
||||
|
||||
return Overlay2D::getProperty(property);
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; _wantClipFromImage = true; }
|
||||
void setImageURL(const QUrl& url);
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
private slots:
|
||||
void replyFinished(); // we actually want to hide this...
|
||||
|
@ -109,6 +109,37 @@ QScriptValue Overlay::getProperty(const QString& property) {
|
||||
if (property == "color") {
|
||||
return xColorToScriptValue(_scriptEngine, _color);
|
||||
}
|
||||
if (property == "alpha") {
|
||||
return _alpha;
|
||||
}
|
||||
if (property == "glowLevel") {
|
||||
return _glowLevel;
|
||||
}
|
||||
if (property == "pulseMax") {
|
||||
return _pulseMax;
|
||||
}
|
||||
if (property == "pulseMin") {
|
||||
return _pulseMin;
|
||||
}
|
||||
if (property == "pulsePeriod") {
|
||||
return _pulsePeriod;
|
||||
}
|
||||
if (property == "glowLevelPulse") {
|
||||
return _glowLevelPulse;
|
||||
}
|
||||
if (property == "alphaPulse") {
|
||||
return _alphaPulse;
|
||||
}
|
||||
if (property == "colorPulse") {
|
||||
return _colorPulse;
|
||||
}
|
||||
if (property == "visible") {
|
||||
return _visible;
|
||||
}
|
||||
if (property == "anchor") {
|
||||
return _anchor == MY_AVATAR ? "MyAvatar" : "";
|
||||
}
|
||||
|
||||
return QScriptValue();
|
||||
}
|
||||
|
||||
|
@ -66,5 +66,26 @@ void Overlay2D::setProperties(const QScriptValue& properties) {
|
||||
}
|
||||
|
||||
QScriptValue Overlay2D::getProperty(const QString& property) {
|
||||
if (property == "bounds") {
|
||||
QScriptValue bounds = _scriptEngine->newObject();
|
||||
bounds.setProperty("x", _bounds.x());
|
||||
bounds.setProperty("y", _bounds.y());
|
||||
bounds.setProperty("width", _bounds.width());
|
||||
bounds.setProperty("height", _bounds.height());
|
||||
return bounds;
|
||||
}
|
||||
if (property == "x") {
|
||||
return _bounds.x();
|
||||
}
|
||||
if (property == "y") {
|
||||
return _bounds.y();
|
||||
}
|
||||
if (property == "width") {
|
||||
return _bounds.width();
|
||||
}
|
||||
if (property == "height") {
|
||||
return _bounds.height();
|
||||
}
|
||||
|
||||
return Overlay::getProperty(property);
|
||||
}
|
||||
|
@ -125,13 +125,26 @@ void TextOverlay::setProperties(const QScriptValue& properties) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QScriptValue TextOverlay::getProperty(const QString& property) {
|
||||
if (property == "font") {
|
||||
QScriptValue font = _scriptEngine->newObject();
|
||||
font.setProperty("size", _fontSize);
|
||||
return font;
|
||||
}
|
||||
if (property == "text") {
|
||||
return _text;
|
||||
}
|
||||
if (property == "backgroundColor") {
|
||||
return xColorToScriptValue(_scriptEngine, _backgroundColor);
|
||||
}
|
||||
if (property == "leftMargin") {
|
||||
return _leftMargin;
|
||||
}
|
||||
if (property == "topMargin") {
|
||||
return _topMargin;
|
||||
}
|
||||
|
||||
return Overlay::getProperty(property);
|
||||
return Overlay2D::getProperty(property);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user