Rather than Xs, use a "solid block" pseudo-character to draw a bar. Tweaked

the colors to indicate the pressed key again.
This commit is contained in:
Andrzej Kapolka 2013-04-30 11:06:23 -07:00
parent ccdc1146a2
commit 39a70ce9e7
4 changed files with 18 additions and 8 deletions

View file

@ -736,7 +736,7 @@ void Avatar::render(bool lookingInMirror) {
glTranslatef(_position.x, _position.y + chatMessageHeight, _position.z);
glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PI, 0, 1, 0);
glColor3f(0, 1, 0);
glColor3f(0, 0.8, 0);
glRotatef(180, 0, 0, 1);
glScalef(chatMessageScale, chatMessageScale, 1.0f);
@ -752,6 +752,7 @@ void Avatar::render(bool lookingInMirror) {
_chatMessage[lastIndex] = '\0';
textRenderer()->draw(-width/2, 0, _chatMessage.c_str());
_chatMessage[lastIndex] = lastChar;
glColor3f(0, 1, 0);
textRenderer()->draw(width/2 - lastWidth, 0, _chatMessage.c_str() + lastIndex);
}
glEnable(GL_LIGHTING);

View file

@ -65,6 +65,7 @@
#include "ui/MenuRow.h"
#include "ui/MenuColumn.h"
#include "ui/Menu.h"
#include "ui/TextRenderer.h"
#include "Camera.h"
#include "Avatar.h"
@ -1333,7 +1334,7 @@ void key(unsigned char k, int x, int y)
if (chatEntry.key(k)) {
myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete
DELETE_KEY_DOWN : INSERT_KEY_DOWN);
myAvatar.setChatMessage(string(chatEntry.getContents().size(), 'X'));
myAvatar.setChatMessage(string(chatEntry.getContents().size(), SOLID_BLOCK_CHAR));
} else {
myAvatar.setChatMessage(chatEntry.getContents());

View file

@ -89,9 +89,11 @@ const Glyph& TextRenderer::getGlyph(char c) {
if (glyph.isValid()) {
return glyph;
}
QRect bounds = _metrics.boundingRect(c);
// we use 'J' as a representative size for the solid block character
QChar ch = (c == SOLID_BLOCK_CHAR) ? QChar('J') : QChar(c);
QRect bounds = _metrics.boundingRect(ch);
if (bounds.isEmpty()) {
glyph = Glyph(0, QPoint(), QRect(), _metrics.width(c));
glyph = Glyph(0, QPoint(), QRect(), _metrics.width(ch));
return glyph;
}
@ -116,16 +118,19 @@ const Glyph& TextRenderer::getGlyph(char c) {
}
// render the glyph into an image and copy it into the texture
QImage image(bounds.width(), bounds.height(), QImage::Format_ARGB32);
image.fill(0);
{
if (c == SOLID_BLOCK_CHAR) {
image.fill(QColor(255, 255, 255));
} else {
image.fill(0);
QPainter painter(&image);
painter.setFont(_font);
painter.setPen(QColor(255, 255, 255));
painter.drawText(-bounds.x(), -bounds.y(), QChar(c));
painter.drawText(-bounds.x(), -bounds.y(), ch);
}
glTexSubImage2D(GL_TEXTURE_2D, 0, _x, _y, bounds.width(), bounds.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.constBits());
glyph = Glyph(_currentTextureID, QPoint(_x, _y), bounds, _metrics.width(c));
glyph = Glyph(_currentTextureID, QPoint(_x, _y), bounds, _metrics.width(ch));
_x += bounds.width();
_rowHeight = qMax(_rowHeight, bounds.height());

View file

@ -15,6 +15,9 @@
#include <QImage>
#include <QVector>
// a special "character" that renders as a solid block
const char SOLID_BLOCK_CHAR = 127;
class Glyph;
class TextRenderer {