From fa490acb8d27dc8ac466f3864fc84c2fe276c983 Mon Sep 17 00:00:00 2001 From: Jose Carlos Date: Thu, 20 Feb 2014 20:45:32 +0100 Subject: [PATCH 1/3] Changed the display name background alpha to 0.2 (was 0.95) --- interface/src/avatar/Avatar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 9ff1ec8cb1..f3229ce450 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -59,6 +59,7 @@ const float CHAT_MESSAGE_HEIGHT = 0.1f; const float DISPLAYNAME_FADE_TIME = 0.5f; const float DISPLAYNAME_FADE_FACTOR = pow(0.01f, 1.0f / DISPLAYNAME_FADE_TIME); const float DISPLAYNAME_ALPHA = 0.95f; +const float DISPLAYNAME_BACKGROUND_ALPHA = 0.2f; Avatar::Avatar() : AvatarData(), @@ -353,7 +354,7 @@ void Avatar::renderDisplayName() { glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f, 1.0f); - glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha); + glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA); glBegin(GL_QUADS); glVertex2f(left, bottom); glVertex2f(right, bottom); From 354c9bff099bb575437c8f1839d25296fe086de0 Mon Sep 17 00:00:00 2001 From: Jose Carlos Date: Fri, 21 Feb 2014 00:29:52 +0100 Subject: [PATCH 2/3] Correct text position for default and non default meshes Bounding box for text background is now text dependent, much nicer now --- interface/src/avatar/Avatar.cpp | 35 +++++++++++++++++----------- libraries/avatars/src/AvatarData.cpp | 2 +- libraries/avatars/src/AvatarData.h | 3 ++- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index f3229ce450..54a0dc5654 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -59,7 +59,7 @@ const float CHAT_MESSAGE_HEIGHT = 0.1f; const float DISPLAYNAME_FADE_TIME = 0.5f; const float DISPLAYNAME_FADE_FACTOR = pow(0.01f, 1.0f / DISPLAYNAME_FADE_TIME); const float DISPLAYNAME_ALPHA = 0.95f; -const float DISPLAYNAME_BACKGROUND_ALPHA = 0.2f; +const float DISPLAYNAME_BACKGROUND_ALPHA = 0.4f; Avatar::Avatar() : AvatarData(), @@ -218,7 +218,7 @@ void Avatar::render(bool forceRenderHead) { glPopMatrix(); } } - const float DISPLAYNAME_DISTANCE = 4.0f; + const float DISPLAYNAME_DISTANCE = 10.0f; setShowDisplayName(lengthToTarget < DISPLAYNAME_DISTANCE); renderDisplayName(); @@ -301,7 +301,10 @@ void Avatar::renderDisplayName() { glDisable(GL_LIGHTING); glPushMatrix(); - glm::vec3 textPosition = getPosition() + getBodyUpDirection() * ((getSkeletonHeight() + getHeadHeight()) / 1.5f); + glm::vec3 textPosition; + getSkeletonModel().getNeckPosition(textPosition); + textPosition += getBodyUpDirection() * getHeadHeight() * 1.1f; + glTranslatef(textPosition.x, textPosition.y, textPosition.z); // we need "always facing camera": we must remove the camera rotation from the stack @@ -340,11 +343,19 @@ void Avatar::renderDisplayName() { float scaleFactor = (textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f; glScalef(scaleFactor, scaleFactor, 1.0); + glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis + + int text_x = -_displayNameBoundingRect.width() / 2; + int text_y = -_displayNameBoundingRect.height() / 2; + // draw a gray background - QFontMetrics metrics = textRenderer(DISPLAYNAME)->metrics(); - int bottom = -metrics.descent(), top = bottom + metrics.height(); - int left = -_displayNameWidth/2, right = _displayNameWidth/2; - const int border = 5; + QRect rect = textRenderer(DISPLAYNAME)->metrics().tightBoundingRect(_displayName); + + int left = text_x + rect.x(); + int right = left + rect.width(); + int bottom = text_y + rect.y(); + int top = bottom + rect.height(); + const int border = 8; bottom -= border; left -= border; top += border; @@ -362,14 +373,14 @@ void Avatar::renderDisplayName() { glVertex2f(left, top); glEnd(); - glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis + glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); QByteArray ba = _displayName.toLocal8Bit(); const char* text = ba.data(); glDisable(GL_POLYGON_OFFSET_FILL); - textRenderer(DISPLAYNAME)->draw(-_displayNameWidth / 2, 0, text); + textRenderer(DISPLAYNAME)->draw(text_x, text_y, text); } @@ -490,11 +501,7 @@ void Avatar::setSkeletonModelURL(const QUrl &skeletonModelURL) { void Avatar::setDisplayName(const QString& displayName) { AvatarData::setDisplayName(displayName); - int width = 0; - for (int i = 0; i < displayName.size(); i++) { - width += (textRenderer(DISPLAYNAME)->computeWidth(displayName[i].toLatin1())); - } - _displayNameWidth = width; + _displayNameBoundingRect = textRenderer(DISPLAYNAME)->metrics().tightBoundingRect(displayName); } int Avatar::parseData(const QByteArray& packet) { diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 8e9eb430e8..da176f3fd9 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -36,7 +36,7 @@ AvatarData::AvatarData() : _isChatCirclingEnabled(false), _headData(NULL), _handData(NULL), - _displayNameWidth(0), + _displayNameBoundingRect(), _displayNameTargetAlpha(0.0f), _displayNameAlpha(0.0f) { diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index a889b52bd0..1345a69f8e 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -33,6 +33,7 @@ typedef unsigned long long quint64; #include #include #include +#include #include #include @@ -187,7 +188,7 @@ protected: QUrl _skeletonModelURL; QString _displayName; - int _displayNameWidth; + QRect _displayNameBoundingRect; float _displayNameTargetAlpha; float _displayNameAlpha; From 10c9b902b9fd2b5e36972fe90083b46f9650ef95 Mon Sep 17 00:00:00 2001 From: Jose Carlos Date: Fri, 21 Feb 2014 00:37:29 +0100 Subject: [PATCH 3/3] Removed duplicated calculation of bounding rect for display name --- interface/src/avatar/Avatar.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 54a0dc5654..dcecd0258d 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -349,12 +349,10 @@ void Avatar::renderDisplayName() { int text_y = -_displayNameBoundingRect.height() / 2; // draw a gray background - QRect rect = textRenderer(DISPLAYNAME)->metrics().tightBoundingRect(_displayName); - - int left = text_x + rect.x(); - int right = left + rect.width(); - int bottom = text_y + rect.y(); - int top = bottom + rect.height(); + int left = text_x + _displayNameBoundingRect.x(); + int right = left + _displayNameBoundingRect.width(); + int bottom = text_y + _displayNameBoundingRect.y(); + int top = bottom + _displayNameBoundingRect.height(); const int border = 8; bottom -= border; left -= border;