Add backgroundAlpha property to 2D and 3D text overlays

This commit is contained in:
David Rowe 2014-12-05 11:08:00 -08:00
parent dbf64b2de7
commit f5a1c26492
5 changed files with 27 additions and 1 deletions

View file

@ -69,7 +69,8 @@ var text = Overlays.addOverlay("text", {
topMargin: 4,
leftMargin: 4,
text: "Here is some text.\nAnd a second line.",
alpha: 0.7
alpha: 0.7,
backgroundAlpha: 0.5
});
// This will create an image overlay, which starts out as invisible
@ -170,6 +171,7 @@ var clipboardPreview = Overlays.addOverlay("clipboard", {
// Demonstrate retrieving overlay properties
print("Text overlay text property value =\n" + Overlays.getProperty(text, "text"));
print("Text overlay alpha =\n" + Overlays.getProperty(text, "alpha"));
print("Text overlay background alpha =\n" + Overlays.getProperty(text, "backgroundAlpha"));
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"));

View file

@ -16,12 +16,14 @@
#include "ui/TextRenderer.h"
const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 };
const float DEFAULT_BACKGROUND_ALPHA = 0.7f;
const float DEFAULT_MARGIN = 0.1f;
const int FIXED_FONT_POINT_SIZE = 40;
const float LINE_SCALE_RATIO = 1.2f;
Text3DOverlay::Text3DOverlay() :
_backgroundColor(DEFAULT_BACKGROUND_COLOR),
_backgroundAlpha(DEFAULT_BACKGROUND_ALPHA),
_lineHeight(0.1f),
_leftMargin(DEFAULT_MARGIN),
_topMargin(DEFAULT_MARGIN),
@ -35,6 +37,7 @@ Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
Planar3DOverlay(text3DOverlay),
_text(text3DOverlay->_text),
_backgroundColor(text3DOverlay->_backgroundColor),
_backgroundAlpha(text3DOverlay->_backgroundAlpha),
_lineHeight(text3DOverlay->_lineHeight),
_leftMargin(text3DOverlay->_leftMargin),
_topMargin(text3DOverlay->_topMargin),
@ -166,6 +169,10 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
}
}
if (properties.property("backgroundAlpha").isValid()) {
_backgroundAlpha = properties.property("backgroundAlpha").toVariant().toFloat();
}
if (properties.property("lineHeight").isValid()) {
setLineHeight(properties.property("lineHeight").toVariant().toFloat());
}
@ -200,6 +207,9 @@ QScriptValue Text3DOverlay::getProperty(const QString& property) {
if (property == "backgroundColor") {
return xColorToScriptValue(_scriptEngine, _backgroundColor);
}
if (property == "backgroundAlpha") {
return _backgroundAlpha;
}
if (property == "lineHeight") {
return _lineHeight;
}

View file

@ -37,6 +37,7 @@ public:
float getBottomMargin() const { return _bottomMargin; }
bool getIsFacingAvatar() const { return _isFacingAvatar; }
xColor getBackgroundColor();
float getBackgroundAlpha() const { return _backgroundAlpha; }
// setters
void setText(const QString& text) { _text = text; }
@ -59,6 +60,7 @@ private:
QString _text;
xColor _backgroundColor;
float _backgroundAlpha;
float _lineHeight;
float _leftMargin;
float _topMargin;

View file

@ -19,6 +19,7 @@
TextOverlay::TextOverlay() :
_backgroundColor(DEFAULT_BACKGROUND_COLOR),
_backgroundAlpha(DEFAULT_BACKGROUND_ALPHA),
_leftMargin(DEFAULT_MARGIN),
_topMargin(DEFAULT_MARGIN),
_fontSize(DEFAULT_FONTSIZE)
@ -29,6 +30,7 @@ TextOverlay::TextOverlay(const TextOverlay* textOverlay) :
Overlay2D(textOverlay),
_text(textOverlay->_text),
_backgroundColor(textOverlay->_backgroundColor),
_backgroundAlpha(textOverlay->_backgroundAlpha),
_leftMargin(textOverlay->_leftMargin),
_topMargin(textOverlay->_topMargin),
_fontSize(textOverlay->_fontSize)
@ -125,6 +127,10 @@ void TextOverlay::setProperties(const QScriptValue& properties) {
}
}
if (properties.property("backgroundAlpha").isValid()) {
_backgroundAlpha = properties.property("backgroundAlpha").toVariant().toFloat();
}
if (properties.property("leftMargin").isValid()) {
setLeftMargin(properties.property("leftMargin").toVariant().toInt());
}
@ -150,6 +156,9 @@ QScriptValue TextOverlay::getProperty(const QString& property) {
if (property == "backgroundColor") {
return xColorToScriptValue(_scriptEngine, _backgroundColor);
}
if (property == "backgroundAlpha") {
return _backgroundAlpha;
}
if (property == "leftMargin") {
return _leftMargin;
}

View file

@ -28,6 +28,7 @@
#include "Overlay2D.h"
const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 };
const float DEFAULT_BACKGROUND_ALPHA = 0.7f;
const int DEFAULT_MARGIN = 10;
const int DEFAULT_FONTSIZE = 11;
const int DEFAULT_FONT_WEIGHT = 50;
@ -46,6 +47,7 @@ public:
int getLeftMargin() const { return _leftMargin; }
int getTopMargin() const { return _topMargin; }
xColor getBackgroundColor();
float getBackgroundAlpha() const { return _backgroundAlpha; }
// setters
void setText(const QString& text) { _text = text; }
@ -62,6 +64,7 @@ public:
private:
QString _text;
xColor _backgroundColor;
float _backgroundAlpha;
int _leftMargin;
int _topMargin;
int _fontSize;