mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Alias text3d's backgroundAlpha to alpha
getAlpha(), across 3d overlays, refers to the behavior of the overlay as a whole. This conforms text3d, and adds a new property, textAlpha, to replace the old alpha semantic.
This commit is contained in:
parent
4faeea7c3f
commit
f2b716f90a
2 changed files with 23 additions and 26 deletions
|
@ -17,8 +17,6 @@
|
||||||
#include <RenderDeferredTask.h>
|
#include <RenderDeferredTask.h>
|
||||||
#include <TextRenderer3D.h>
|
#include <TextRenderer3D.h>
|
||||||
|
|
||||||
const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 };
|
|
||||||
const float DEFAULT_BACKGROUND_ALPHA = 0.7f;
|
|
||||||
const float DEFAULT_MARGIN = 0.1f;
|
const float DEFAULT_MARGIN = 0.1f;
|
||||||
const int FIXED_FONT_POINT_SIZE = 40;
|
const int FIXED_FONT_POINT_SIZE = 40;
|
||||||
const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 80.0f; // this is a ratio determined through experimentation
|
const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 80.0f; // this is a ratio determined through experimentation
|
||||||
|
@ -26,24 +24,15 @@ const float LINE_SCALE_RATIO = 1.2f;
|
||||||
|
|
||||||
QString const Text3DOverlay::TYPE = "text3d";
|
QString const Text3DOverlay::TYPE = "text3d";
|
||||||
|
|
||||||
Text3DOverlay::Text3DOverlay() :
|
Text3DOverlay::Text3DOverlay() {
|
||||||
_backgroundColor(DEFAULT_BACKGROUND_COLOR),
|
|
||||||
_backgroundAlpha(DEFAULT_BACKGROUND_ALPHA),
|
|
||||||
_lineHeight(0.1f),
|
|
||||||
_leftMargin(DEFAULT_MARGIN),
|
|
||||||
_topMargin(DEFAULT_MARGIN),
|
|
||||||
_rightMargin(DEFAULT_MARGIN),
|
|
||||||
_bottomMargin(DEFAULT_MARGIN)
|
|
||||||
{
|
|
||||||
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||||
_alpha = _backgroundAlpha;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
||||||
Billboard3DOverlay(text3DOverlay),
|
Billboard3DOverlay(text3DOverlay),
|
||||||
_text(text3DOverlay->_text),
|
_text(text3DOverlay->_text),
|
||||||
_backgroundColor(text3DOverlay->_backgroundColor),
|
_backgroundColor(text3DOverlay->_backgroundColor),
|
||||||
_backgroundAlpha(text3DOverlay->_backgroundAlpha),
|
_textAlpha(text3DOverlay->_textAlpha),
|
||||||
_lineHeight(text3DOverlay->_lineHeight),
|
_lineHeight(text3DOverlay->_lineHeight),
|
||||||
_leftMargin(text3DOverlay->_leftMargin),
|
_leftMargin(text3DOverlay->_leftMargin),
|
||||||
_topMargin(text3DOverlay->_topMargin),
|
_topMargin(text3DOverlay->_topMargin),
|
||||||
|
@ -51,7 +40,6 @@ Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
||||||
_bottomMargin(text3DOverlay->_bottomMargin)
|
_bottomMargin(text3DOverlay->_bottomMargin)
|
||||||
{
|
{
|
||||||
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||||
_alpha = _backgroundAlpha;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text3DOverlay::~Text3DOverlay() {
|
Text3DOverlay::~Text3DOverlay() {
|
||||||
|
@ -122,7 +110,7 @@ void Text3DOverlay::render(RenderArgs* args) {
|
||||||
batch.setModelTransform(transform);
|
batch.setModelTransform(transform);
|
||||||
|
|
||||||
glm::vec4 textColor = { _color.red / MAX_COLOR, _color.green / MAX_COLOR,
|
glm::vec4 textColor = { _color.red / MAX_COLOR, _color.green / MAX_COLOR,
|
||||||
_color.blue / MAX_COLOR, getAlpha() };
|
_color.blue / MAX_COLOR, getTextAlpha() };
|
||||||
_textRenderer->draw(batch, 0, 0, _text, textColor, glm::vec2(-1.0f), getDrawInFront());
|
_textRenderer->draw(batch, 0, 0, _text, textColor, glm::vec2(-1.0f), getDrawInFront());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +130,11 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
||||||
setText(text.toVariant().toString());
|
setText(text.toVariant().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QScriptValue textAlpha = properties.property("textAlpha");
|
||||||
|
if (textAlpha.isValid()) {
|
||||||
|
setTextAlpha(textAlpha.toVariant().toFloat());
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue backgroundColor = properties.property("backgroundColor");
|
QScriptValue backgroundColor = properties.property("backgroundColor");
|
||||||
if (backgroundColor.isValid()) {
|
if (backgroundColor.isValid()) {
|
||||||
QScriptValue red = backgroundColor.property("red");
|
QScriptValue red = backgroundColor.property("red");
|
||||||
|
@ -155,8 +148,7 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (properties.property("backgroundAlpha").isValid()) {
|
if (properties.property("backgroundAlpha").isValid()) {
|
||||||
_backgroundAlpha = properties.property("backgroundAlpha").toVariant().toFloat();
|
setAlpha(properties.property("backgroundAlpha").toVariant().toFloat());
|
||||||
_alpha = _backgroundAlpha;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (properties.property("lineHeight").isValid()) {
|
if (properties.property("lineHeight").isValid()) {
|
||||||
|
@ -184,11 +176,14 @@ QScriptValue Text3DOverlay::getProperty(const QString& property) {
|
||||||
if (property == "text") {
|
if (property == "text") {
|
||||||
return _text;
|
return _text;
|
||||||
}
|
}
|
||||||
|
if (property == "textAlpha") {
|
||||||
|
return _textAlpha;
|
||||||
|
}
|
||||||
if (property == "backgroundColor") {
|
if (property == "backgroundColor") {
|
||||||
return xColorToScriptValue(_scriptEngine, _backgroundColor);
|
return xColorToScriptValue(_scriptEngine, _backgroundColor);
|
||||||
}
|
}
|
||||||
if (property == "backgroundAlpha") {
|
if (property == "backgroundAlpha") {
|
||||||
return _backgroundAlpha;
|
return Billboard3DOverlay::getProperty("alpha");
|
||||||
}
|
}
|
||||||
if (property == "lineHeight") {
|
if (property == "lineHeight") {
|
||||||
return _lineHeight;
|
return _lineHeight;
|
||||||
|
|
|
@ -41,10 +41,12 @@ public:
|
||||||
float getRightMargin() const { return _rightMargin; }
|
float getRightMargin() const { return _rightMargin; }
|
||||||
float getBottomMargin() const { return _bottomMargin; }
|
float getBottomMargin() const { return _bottomMargin; }
|
||||||
xColor getBackgroundColor();
|
xColor getBackgroundColor();
|
||||||
float getBackgroundAlpha() const { return _backgroundAlpha; }
|
float getTextAlpha() { return _textAlpha; }
|
||||||
|
float getBackgroundAlpha() { return getAlpha(); }
|
||||||
|
|
||||||
// setters
|
// setters
|
||||||
void setText(const QString& text) { _text = text; }
|
void setText(const QString& text) { _text = text; }
|
||||||
|
void setTextAlpha(float alpha) { _textAlpha = alpha; }
|
||||||
void setLineHeight(float value) { _lineHeight = value; }
|
void setLineHeight(float value) { _lineHeight = value; }
|
||||||
void setLeftMargin(float margin) { _leftMargin = margin; }
|
void setLeftMargin(float margin) { _leftMargin = margin; }
|
||||||
void setTopMargin(float margin) { _topMargin = margin; }
|
void setTopMargin(float margin) { _topMargin = margin; }
|
||||||
|
@ -65,13 +67,13 @@ private:
|
||||||
TextRenderer3D* _textRenderer = nullptr;
|
TextRenderer3D* _textRenderer = nullptr;
|
||||||
|
|
||||||
QString _text;
|
QString _text;
|
||||||
xColor _backgroundColor;
|
xColor _backgroundColor = xColor{ 0, 0, 0 };
|
||||||
float _backgroundAlpha;
|
float _textAlpha{ 1.0f };
|
||||||
float _lineHeight;
|
float _lineHeight{ 1.0f };
|
||||||
float _leftMargin;
|
float _leftMargin{ 0.1f };
|
||||||
float _topMargin;
|
float _topMargin{ 0.1f };
|
||||||
float _rightMargin;
|
float _rightMargin{ 0.1f };
|
||||||
float _bottomMargin;
|
float _bottomMargin{ 0.1f };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_Text3DOverlay_h
|
#endif // hifi_Text3DOverlay_h
|
||||||
|
|
Loading…
Reference in a new issue