fixes for other avatar receive stats rendering

This commit is contained in:
Stephen Birarda 2015-05-13 14:43:31 -07:00
parent 8102e534dd
commit 57fa3d8c53

View file

@ -655,7 +655,9 @@ float Avatar::calculateDisplayNameScaleFactor(const glm::vec3& textPosition, boo
void Avatar::renderDisplayName() {
if (_displayName.isEmpty() || _displayNameAlpha == 0.0f) {
bool shouldShowReceiveStats = DependencyManager::get<AvatarManager>()->shouldShowReceiveStats();
if ((_displayName.isEmpty() && !shouldShowReceiveStats) || _displayNameAlpha == 0.0f) {
return;
}
@ -688,14 +690,40 @@ void Avatar::renderDisplayName() {
float scaleFactor = calculateDisplayNameScaleFactor(textPosition, inHMD);
glScalef(scaleFactor, -scaleFactor, scaleFactor); // TextRenderer::draw paints the text upside down in y axis
int text_x = -_displayNameBoundingRect.width() / 2;
int text_y = -_displayNameBoundingRect.height() / 2;
// optionally render timing stats for this avatar with the display name
QString renderedDisplayName = _displayName;
QRect nameDynamicRect = _displayNameBoundingRect;
if (shouldShowReceiveStats) {
float kilobitsPerSecond = getAverageBytesReceivedPerSecond() / (float) BYTES_PER_KILOBIT;
QString statsFormat = QString("(%1 Kbps, %2 Hz)");
if (!renderedDisplayName.isEmpty()) {
statsFormat.prepend(" - ");
}
QString statsText = statsFormat.arg(QString::number(kilobitsPerSecond, 'f', 2)).arg(getReceiveRate());
glm::vec2 extent = textRenderer(DISPLAYNAME)->computeExtent(statsText);
// add the extent required for the stats to whatever was calculated for the display name
nameDynamicRect.setWidth(nameDynamicRect.width() + extent.x);
if (extent.y > nameDynamicRect.height()) {
nameDynamicRect.setHeight(extent.y);
}
renderedDisplayName += statsText;
}
int text_x = -nameDynamicRect.width() / 2;
int text_y = -nameDynamicRect.height() / 2;
// draw a gray background
int left = text_x + _displayNameBoundingRect.x();
int right = left + _displayNameBoundingRect.width();
int bottom = text_y + _displayNameBoundingRect.y();
int top = bottom + _displayNameBoundingRect.height();
int left = text_x + nameDynamicRect.x();
int right = left + nameDynamicRect.width();
int bottom = text_y + nameDynamicRect.y();
int top = bottom + nameDynamicRect.height();
const int border = 8;
bottom -= border;
left -= border;
@ -711,17 +739,6 @@ void Avatar::renderDisplayName() {
glm::vec4 color(0.93f, 0.93f, 0.93f, _displayNameAlpha);
// optionally render timing stats for this avatar with the display name
QString renderedDisplayName = _displayName;
if (DependencyManager::get<AvatarManager>()->shouldShowReceiveStats()) {
float kilobitsPerSecond = getAverageBytesReceivedPerSecond() / (float) BYTES_PER_KILOBIT;
renderedDisplayName += QString(" - (%1 Kbps, %2 Hz)")
.arg(QString::number(kilobitsPerSecond, 'f', 2))
.arg(getReceiveRate());
}
QByteArray nameUTF8 = renderedDisplayName.toLocal8Bit();
glDisable(GL_POLYGON_OFFSET_FILL);
@ -932,7 +949,7 @@ void Avatar::setDisplayName(const QString& displayName) {
AvatarData::setDisplayName(displayName);
// FIXME is this a sufficient replacement for tightBoundingRect?
glm::vec2 extent = textRenderer(DISPLAYNAME)->computeExtent(displayName);
_displayNameBoundingRect = QRect(QPoint(0, 0), QPoint((int)extent.x, (int)extent.y));
_displayNameBoundingRect = QRect(0, 0, (int)extent.x, (int)extent.y);
}
void Avatar::setBillboard(const QByteArray& billboard) {