Delete support (though the one on my numeric keypad doesn't work?),

sending key states.
This commit is contained in:
Andrzej Kapolka 2013-04-25 15:26:05 -07:00
parent 675d06e4b9
commit d041072d40
5 changed files with 21 additions and 5 deletions

View file

@ -657,7 +657,7 @@ void Avatar::render(bool lookingInMirror) {
if (!_chatMessage.empty()) {
float width = 0;
for (string::iterator it = _chatMessage.begin(); it != _chatMessage.end(); it++) {
width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*0.0005;
width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*0.00025;
}
glPushMatrix();
@ -678,7 +678,7 @@ void Avatar::render(bool lookingInMirror) {
glVertex2f(0, 0);
glEnd();
drawtext(0, 0, 0.0005, 180, 1.0, 0, _chatMessage.c_str(), 1, 1, 1);
drawtext(0, 0, 0.00025, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0);
glPopMatrix();
}

View file

@ -30,6 +30,12 @@ bool ChatEntry::key(unsigned char k) {
cursorPos--;
}
return true;
case 127: // delete
if (cursorPos < contents.size()) {
contents.erase(cursorPos, 1);
}
return true;
default:
if (contents.size() != MAX_CONTENT_LENGTH) {

View file

@ -1361,6 +1361,11 @@ void specialkey(int k, int x, int y)
void keyUp(unsigned char k, int x, int y) {
if (::chatEntryOn) {
myAvatar.setKeyState(AvatarData::NoKeyDown);
return;
}
if (k == 'e') myAvatar.setDriveKeys(UP, 0);
if (k == 'c') myAvatar.setDriveKeys(DOWN, 0);
if (k == 'w') myAvatar.setDriveKeys(FWD, 0);
@ -1373,7 +1378,11 @@ void keyUp(unsigned char k, int x, int y) {
void key(unsigned char k, int x, int y)
{
if (::chatEntryOn) {
if (!chatEntry.key(k)) {
if (chatEntry.key(k)) {
myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete
AvatarData::DeleteKeyDown : AvatarData::InsertKeyDown);
} else {
myAvatar.setChatMessage(chatEntry.getContents());
chatEntry.clear();
::chatEntryOn = false;

View file

@ -50,7 +50,8 @@ AvatarData::AvatarData() :
_cameraFov(0.0f),
_cameraAspectRatio(0.0f),
_cameraNearClip(0.0f),
_cameraFarClip(0.0f) {
_cameraFarClip(0.0f),
_keyState(NoKeyDown) {
}

View file

@ -76,7 +76,7 @@ public:
void setCameraNearClip(float nearClip) { _cameraNearClip = nearClip; }
void setCameraFarClip(float farClip) { _cameraFarClip = farClip; }
enum KeyState { NoKey, KeyDown, KeyUp, DeleteKey };
enum KeyState { NoKeyDown, InsertKeyDown, DeleteKeyDown };
// key state
void setKeyState(KeyState s) { _keyState = s; }