mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 04:24:08 +02: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
interface/src/ui/overlays
|
@ -17,8 +17,6 @@
|
|||
#include <RenderDeferredTask.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 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
|
||||
|
@ -26,24 +24,15 @@ const float LINE_SCALE_RATIO = 1.2f;
|
|||
|
||||
QString const Text3DOverlay::TYPE = "text3d";
|
||||
|
||||
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)
|
||||
{
|
||||
Text3DOverlay::Text3DOverlay() {
|
||||
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||
_alpha = _backgroundAlpha;
|
||||
}
|
||||
|
||||
Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
||||
Billboard3DOverlay(text3DOverlay),
|
||||
_text(text3DOverlay->_text),
|
||||
_backgroundColor(text3DOverlay->_backgroundColor),
|
||||
_backgroundAlpha(text3DOverlay->_backgroundAlpha),
|
||||
_textAlpha(text3DOverlay->_textAlpha),
|
||||
_lineHeight(text3DOverlay->_lineHeight),
|
||||
_leftMargin(text3DOverlay->_leftMargin),
|
||||
_topMargin(text3DOverlay->_topMargin),
|
||||
|
@ -51,7 +40,6 @@ Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
|||
_bottomMargin(text3DOverlay->_bottomMargin)
|
||||
{
|
||||
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||
_alpha = _backgroundAlpha;
|
||||
}
|
||||
|
||||
Text3DOverlay::~Text3DOverlay() {
|
||||
|
@ -122,7 +110,7 @@ void Text3DOverlay::render(RenderArgs* args) {
|
|||
batch.setModelTransform(transform);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -142,6 +130,11 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
setText(text.toVariant().toString());
|
||||
}
|
||||
|
||||
QScriptValue textAlpha = properties.property("textAlpha");
|
||||
if (textAlpha.isValid()) {
|
||||
setTextAlpha(textAlpha.toVariant().toFloat());
|
||||
}
|
||||
|
||||
QScriptValue backgroundColor = properties.property("backgroundColor");
|
||||
if (backgroundColor.isValid()) {
|
||||
QScriptValue red = backgroundColor.property("red");
|
||||
|
@ -155,8 +148,7 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
|
||||
if (properties.property("backgroundAlpha").isValid()) {
|
||||
_backgroundAlpha = properties.property("backgroundAlpha").toVariant().toFloat();
|
||||
_alpha = _backgroundAlpha;
|
||||
setAlpha(properties.property("backgroundAlpha").toVariant().toFloat());
|
||||
}
|
||||
|
||||
if (properties.property("lineHeight").isValid()) {
|
||||
|
@ -184,11 +176,14 @@ QScriptValue Text3DOverlay::getProperty(const QString& property) {
|
|||
if (property == "text") {
|
||||
return _text;
|
||||
}
|
||||
if (property == "textAlpha") {
|
||||
return _textAlpha;
|
||||
}
|
||||
if (property == "backgroundColor") {
|
||||
return xColorToScriptValue(_scriptEngine, _backgroundColor);
|
||||
}
|
||||
if (property == "backgroundAlpha") {
|
||||
return _backgroundAlpha;
|
||||
return Billboard3DOverlay::getProperty("alpha");
|
||||
}
|
||||
if (property == "lineHeight") {
|
||||
return _lineHeight;
|
||||
|
|
|
@ -41,10 +41,12 @@ public:
|
|||
float getRightMargin() const { return _rightMargin; }
|
||||
float getBottomMargin() const { return _bottomMargin; }
|
||||
xColor getBackgroundColor();
|
||||
float getBackgroundAlpha() const { return _backgroundAlpha; }
|
||||
float getTextAlpha() { return _textAlpha; }
|
||||
float getBackgroundAlpha() { return getAlpha(); }
|
||||
|
||||
// setters
|
||||
void setText(const QString& text) { _text = text; }
|
||||
void setTextAlpha(float alpha) { _textAlpha = alpha; }
|
||||
void setLineHeight(float value) { _lineHeight = value; }
|
||||
void setLeftMargin(float margin) { _leftMargin = margin; }
|
||||
void setTopMargin(float margin) { _topMargin = margin; }
|
||||
|
@ -65,13 +67,13 @@ private:
|
|||
TextRenderer3D* _textRenderer = nullptr;
|
||||
|
||||
QString _text;
|
||||
xColor _backgroundColor;
|
||||
float _backgroundAlpha;
|
||||
float _lineHeight;
|
||||
float _leftMargin;
|
||||
float _topMargin;
|
||||
float _rightMargin;
|
||||
float _bottomMargin;
|
||||
xColor _backgroundColor = xColor{ 0, 0, 0 };
|
||||
float _textAlpha{ 1.0f };
|
||||
float _lineHeight{ 1.0f };
|
||||
float _leftMargin{ 0.1f };
|
||||
float _topMargin{ 0.1f };
|
||||
float _rightMargin{ 0.1f };
|
||||
float _bottomMargin{ 0.1f };
|
||||
};
|
||||
|
||||
#endif // hifi_Text3DOverlay_h
|
||||
|
|
Loading…
Reference in a new issue