Added rect around the display name with proper size, paying attention to

QFontMetrics data
Fully wired up the message sending and receiving from server
This commit is contained in:
Jose Carlos 2014-02-15 01:05:21 +01:00
parent 04c59b825e
commit 19cb20f0cd
5 changed files with 41 additions and 16 deletions

View file

@ -782,7 +782,7 @@ void Menu::editPreferences() {
skeletonURLEdit->setPlaceholderText(DEFAULT_BODY_MODEL_URL.toString());
form->addRow("Skeleton URL:", skeletonURLEdit);
QString displayNameString = applicationInstance->getAvatar()->getDisplayNameStr();
QString displayNameString = applicationInstance->getAvatar()->getDisplayName();
QLineEdit* displayNameEdit = new QLineEdit(displayNameString);
displayNameEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH);
form->addRow("Display name:", displayNameEdit);

View file

@ -270,7 +270,7 @@ void Avatar::renderDisplayName() {
QString displayName;
if (_displayName.isEmpty()) {
displayName = "test string";
displayName = "test string"; // just for debugging
} else {
displayName = _displayName;
}
@ -278,7 +278,12 @@ void Avatar::renderDisplayName() {
glm::vec3 textPosition = getPosition() + getBodyUpDirection() * getHeight(); // Scale is already considered in getHeight
glPushMatrix();
glDepthMask(false);
glDisable(GL_LIGHTING);
// Set the correct modelview matrix: set the identity matrix in the rotation part
// [R|t1] = current modelview matrix (the camera rotation and translation)
// [I|t2] = the translation for the text
// We want this final model view matrix: [I | t1 + R*t2]
glm::dmat4 modelViewMatrix2;
glGetDoublev(GL_MODELVIEW_MATRIX, (GLdouble*)&modelViewMatrix2);
glTranslatef(textPosition.x, textPosition.y, textPosition.z);
@ -293,7 +298,7 @@ void Avatar::renderDisplayName() {
modelViewMatrix[2][0] = modelViewMatrix[2][1] = 0.0;
glLoadMatrixd((GLdouble*)&modelViewMatrix); // Override current matrix with our own
glScalef(1.0, -1.0, 1.0); // TextRenderer::draw paints the text upside down. This fixes that
// We need to compute the scale factor such as the text remains with fixed size respect to window coordinates
// We project y = 0 and y = 1 and check the difference in projection coordinates
@ -320,22 +325,36 @@ void Avatar::renderDisplayName() {
if (success) {
double textWindowHeight = abs(result1[1] - result0[1]);
float textScale = 1.0;
float scaleFactor = 1.0;
if (textWindowHeight > EPSILON) {
scaleFactor = textScale / textWindowHeight;
}
float scaleFactor = (textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f;
glScalef(scaleFactor, scaleFactor, 1.0);
glScalef(scaleFactor, scaleFactor, 1.0);
// draw a gray background so that we can actually see what we're typing
QFontMetrics metrics = displayNameTextRenderer()->metrics();
int bottom = -metrics.descent(), top = bottom + metrics.height();
int left = -_displayNameWidth/2, right = _displayNameWidth/2;
int border = 5;
bottom -= border;
left -= border;
top += border;
right += border;
glColor3f((GLfloat)0.93, (GLfloat)0.93, (GLfloat)0.93);
glColor3f(0.2f, 0.2f, 0.2f);
glBegin(GL_QUADS);
glVertex2f(left, bottom);
glVertex2f(right, bottom);
glVertex2f(right, top);
glVertex2f(left, top);
glEnd();
// TextRenderer, based on QT opengl text rendering functions
glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis
glColor3f(0.93f, 0.93f, 0.93f);
QByteArray ba = displayName.toLocal8Bit();
const char *text = ba.data();
displayNameTextRenderer()->draw(-_displayNameWidth/2.0, 0, text);
}
glEnable(GL_LIGHTING);
glDepthMask(true);
glPopMatrix();
}

View file

@ -187,8 +187,9 @@ void AvatarManager::processAvatarIdentityPacket(const QByteArray &packet) {
while (!identityStream.atEnd()) {
QUrl faceMeshURL, skeletonURL;
identityStream >> nodeUUID >> faceMeshURL >> skeletonURL;
QString displayName;
identityStream >> nodeUUID >> faceMeshURL >> skeletonURL >> displayName;
// mesh URL for a UUID, find avatar in our list
AvatarSharedPointer matchingAvatar = _avatarHash.value(nodeUUID);
if (matchingAvatar) {
@ -201,6 +202,10 @@ void AvatarManager::processAvatarIdentityPacket(const QByteArray &packet) {
if (avatar->getSkeletonModelURL() != skeletonURL) {
avatar->setSkeletonModelURL(skeletonURL);
}
if (avatar->getDisplayName() != displayName) {
avatar->setDisplayName(displayName);
}
}
}
}

View file

@ -300,7 +300,7 @@ bool AvatarData::hasIdentityChangedAfterParsing(const QByteArray &packet) {
QByteArray AvatarData::identityByteArray() {
QByteArray identityData;
QDataStream identityStream(&identityData, QIODevice::Append);
identityStream << QUuid() << _faceModelURL << _skeletonModelURL << _displayName;
return identityData;
@ -319,8 +319,9 @@ void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) {
}
void AvatarData::setDisplayName(const QString& displayName) {
qDebug() << "Changing display name for avatar to" << displayName;
_displayName = displayName;
qDebug() << "Changing display name for avatar to" << displayName;
}

View file

@ -148,7 +148,7 @@ public:
const QUrl& getFaceModelURL() const { return _faceModelURL; }
const QUrl& getSkeletonModelURL() const { return _skeletonModelURL; }
const QString& getDisplayNameStr() const { return _displayName; }
const QString& getDisplayName() const { return _displayName; }
virtual void setFaceModelURL(const QUrl& faceModelURL);
virtual void setSkeletonModelURL(const QUrl& skeletonModelURL);
virtual void setDisplayName(const QString& displayName);