From 1713bebb64257b3146bd945011f44bf87264f24c Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 25 Apr 2013 17:36:47 -0700 Subject: [PATCH] Added the basic key press/message composition display. --- interface/src/Audio.cpp | 1 + interface/src/Avatar.cpp | 19 +++++++++++++++++-- interface/src/main.cpp | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 4b522d5823..1959b5ae33 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -517,6 +517,7 @@ float Audio::getInputLoudness() const { void Audio::render(int screenWidth, int screenHeight) { if (initialized) { + glLineWidth(3); glBegin(GL_LINES); glColor3f(1,1,1); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 621a4bd512..3a2d9f83cf 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -652,8 +652,9 @@ void Avatar::render(bool lookingInMirror) { if (!_chatMessage.empty()) { float width = 0; + float lastWidth; for (string::iterator it = _chatMessage.begin(); it != _chatMessage.end(); it++) { - width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*chatMessageScale; + width += (lastWidth = glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*chatMessageScale); } glPushMatrix(); @@ -668,7 +669,21 @@ void Avatar::render(bool lookingInMirror) { glTranslatef(width * 0.5, 0, 0); glDisable(GL_LIGHTING); - drawtext(0, 0, chatMessageScale, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0); + if (_keyState == NoKeyDown) { + drawtext(0, 0, chatMessageScale, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0); + + } else { + // rather than using substr and allocating a new string, just replace the last + // character with a null, then restore it + int lastIndex = _chatMessage.size() - 1; + char lastChar = _chatMessage[lastIndex]; + _chatMessage[lastIndex] = '\0'; + drawtext(0, 0, chatMessageScale, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0); + _chatMessage[lastIndex] = lastChar; + glTranslatef(lastWidth - width, 0, 0); + drawtext(0, 0, chatMessageScale, 180, 3.0, + 0, _chatMessage.c_str() + lastIndex, 0, 1, 0); + } glEnable(GL_LIGHTING); glPopMatrix(); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index dc716cfe41..b803ff0ce8 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1381,6 +1381,7 @@ void key(unsigned char k, int x, int y) if (chatEntry.key(k)) { myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete AvatarData::DeleteKeyDown : AvatarData::InsertKeyDown); + myAvatar.setChatMessage(string(chatEntry.getContents().size(), 'X')); } else { myAvatar.setChatMessage(chatEntry.getContents());