From f538e2bdbce625c27e29a6aa868aec4bdfa9d047 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 24 Apr 2013 17:06:55 -0700 Subject: [PATCH 1/7] Added key state to avatar data, started on chat entry field. --- interface/src/ChatEntry.cpp | 12 ++++++++++++ interface/src/ChatEntry.h | 20 ++++++++++++++++++++ interface/src/main.cpp | 14 ++++++++++++++ libraries/avatars/src/AvatarData.cpp | 7 +++++++ libraries/avatars/src/AvatarData.h | 7 +++++++ 5 files changed, 60 insertions(+) create mode 100644 interface/src/ChatEntry.cpp create mode 100644 interface/src/ChatEntry.h diff --git a/interface/src/ChatEntry.cpp b/interface/src/ChatEntry.cpp new file mode 100644 index 0000000000..575674bb01 --- /dev/null +++ b/interface/src/ChatEntry.cpp @@ -0,0 +1,12 @@ +// +// ChatEntry.cpp +// interface +// +// Created by Andrzej Kapolka on 4/24/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. + +#include "ChatEntry.h" + +void ChatEntry::render(int screenWidth, int screenHeight) { + +} diff --git a/interface/src/ChatEntry.h b/interface/src/ChatEntry.h new file mode 100644 index 0000000000..4a5bab717b --- /dev/null +++ b/interface/src/ChatEntry.h @@ -0,0 +1,20 @@ +// +// ChatEntry.h +// interface +// +// Created by Andrzej Kapolka on 4/24/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__ChatEntry__ +#define __interface__ChatEntry__ + +class ChatEntry { +public: + + void render(int screenWidth, int screenHeight); + +private: +}; + +#endif /* defined(__interface__ChatEntry__) */ diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 41ffdc1e92..adb5bdbed7 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -64,6 +64,7 @@ #include "MenuColumn.h" #include "Menu.h" #include "Camera.h" +#include "ChatEntry.h" #include "Head.h" #include "Particle.h" #include "Texture.h" @@ -178,6 +179,9 @@ int mousePressed = 0; // true if mouse has been pressed (clear when finished) Menu menu; // main menu int menuOn = 1; // Whether to show onscreen menu +ChatEntry chatEntry; // chat entry field +bool chatEntryOn = false; // Whether to show the chat entry + struct HandController { bool enabled; @@ -976,6 +980,11 @@ void display(void) menu.render(WIDTH,HEIGHT); } + // Show chat entry field + if (::chatEntryOn) { + chatEntry.render(WIDTH, HEIGHT); + } + // Stats at upper right of screen about who domain server is telling us about glPointSize(1.0f); char agents[100]; @@ -1350,6 +1359,10 @@ void keyUp(unsigned char k, int x, int y) { void key(unsigned char k, int x, int y) { + if (::chatEntryOn) { + + return; + } // Process keypresses if (k == 'q' || k == 'Q') ::terminate(); @@ -1416,6 +1429,7 @@ void key(unsigned char k, int x, int y) if (k == 'g') renderPitchRate += KEYBOARD_PITCH_RATE; if (k == 'a') myAvatar.setDriveKeys(ROT_LEFT, 1); if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 1); + if (k == '\r') ::chatEntryOn = true; } // Receive packets from other agents/servers and decide what to do with them! diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index fd20e099c0..bbdcca9d19 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -112,6 +112,9 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { memcpy(destinationBuffer, &_cameraFarClip, sizeof(_cameraFarClip)); destinationBuffer += sizeof(_cameraFarClip); + // Key State + memcpy(destinationBuffer, &_keyState, sizeof(char)); + destinationBuffer += sizeof(char); return destinationBuffer - bufferStart; } @@ -168,6 +171,10 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { memcpy(&_cameraFarClip, sourceBuffer, sizeof(_cameraFarClip)); sourceBuffer += sizeof(_cameraFarClip); + // Key State + memcpy(&_keyState, sourceBuffer, sizeof(char)); + sourceBuffer += sizeof(char); + return sourceBuffer - startPosition; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index cb2171cbe5..13436d15df 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -74,6 +74,10 @@ public: void setCameraNearClip(float nearClip) { _cameraNearClip = nearClip; } void setCameraFarClip(float farClip) { _cameraFarClip = farClip; } + // Key state + void setKeyState(char s) { _keyState = s; } + char keyState() const { return _keyState; } + protected: glm::vec3 _position; glm::vec3 _handPosition; @@ -105,6 +109,9 @@ protected: float _cameraAspectRatio; float _cameraNearClip; float _cameraFarClip; + + // Key state (nothing, down, up, backspace) + char _keyState; }; #endif /* defined(__hifi__AvatarData__) */ From 1a79bbd80d590578bbc7a823cb32ca2514be964f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 24 Apr 2013 18:30:46 -0700 Subject: [PATCH 2/7] Fleshing out the chat entry widget. --- interface/src/ChatEntry.cpp | 51 +++++++++++++++++++++++++++++++++++++ interface/src/ChatEntry.h | 12 +++++++++ interface/src/main.cpp | 10 +++++++- 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/interface/src/ChatEntry.cpp b/interface/src/ChatEntry.cpp index 575674bb01..39d82d6f16 100644 --- a/interface/src/ChatEntry.cpp +++ b/interface/src/ChatEntry.cpp @@ -5,8 +5,59 @@ // Created by Andrzej Kapolka on 4/24/13. // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +#include "InterfaceConfig.h" + #include "ChatEntry.h" +#include "Util.h" + +using namespace std; + +bool ChatEntry::key(unsigned char k) { + switch (k) { + case '\r': + return false; + + case '\b': + if (cursorPos != 0) { + contents.erase(cursorPos - 1, 1); + cursorPos--; + } + return true; + + default: + contents.insert(cursorPos, 1, k); + cursorPos++; + return true; + } +} + +void ChatEntry::specialKey(unsigned char k) { + switch (k) { + case GLUT_KEY_LEFT: + if (cursorPos != 0) { + cursorPos--; + } + break; + + case GLUT_KEY_RIGHT: + if (cursorPos != contents.size()) { + cursorPos++; + } + break; + } +} void ChatEntry::render(int screenWidth, int screenHeight) { + drawtext(20, screenHeight - 150, 0.10, 0, 1.0, 0, contents.c_str(), 1, 1, 1); + float width = 0; + for (string::iterator it = contents.begin(), end = it + cursorPos; it != end; it++) { + width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*0.10; + } + glDisable(GL_LINE_SMOOTH); + glBegin(GL_LINE_STRIP); + glVertex2f(20 + width, screenHeight - 165); + glVertex2f(20 + width, screenHeight - 150); + glEnd(); + glEnable(GL_LINE_SMOOTH); } diff --git a/interface/src/ChatEntry.h b/interface/src/ChatEntry.h index 4a5bab717b..da91c847fe 100644 --- a/interface/src/ChatEntry.h +++ b/interface/src/ChatEntry.h @@ -9,12 +9,24 @@ #ifndef __interface__ChatEntry__ #define __interface__ChatEntry__ +#include + class ChatEntry { public: + const std::string& getContents () const { return contents; } + + bool key(unsigned char k); + + void specialKey(unsigned char k); + void render(int screenWidth, int screenHeight); private: + + std::string contents; + + int cursorPos; }; #endif /* defined(__interface__ChatEntry__) */ diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 485e55411b..497b4b31b5 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1331,6 +1331,11 @@ void specialkeyUp(int k, int x, int y) { void specialkey(int k, int x, int y) { + if (::chatEntryOn) { + chatEntry.specialKey(k); + return; + } + if (k == GLUT_KEY_UP || k == GLUT_KEY_DOWN || k == GLUT_KEY_LEFT || k == GLUT_KEY_RIGHT) { if (k == GLUT_KEY_UP) { if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myAvatar.setDriveKeys(UP, 1); @@ -1368,7 +1373,10 @@ void keyUp(unsigned char k, int x, int y) { void key(unsigned char k, int x, int y) { if (::chatEntryOn) { - + if (!chatEntry.key()) { + + ::chatEntryOn = false; + } return; } From 675d06e4b9cc80fc2711c51f2451c106fa3d2bf0 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 25 Apr 2013 14:03:31 -0700 Subject: [PATCH 3/7] More chat bits; basic functionality now working. --- avatar-mixer/src/main.cpp | 7 ++++++- interface/src/Avatar.cpp | 29 ++++++++++++++++++++++++++++ interface/src/ChatEntry.cpp | 13 +++++++++++-- interface/src/ChatEntry.h | 2 ++ interface/src/main.cpp | 12 +++++++++--- libraries/avatars/src/AvatarData.cpp | 21 ++++++++++++++------ libraries/avatars/src/AvatarData.h | 21 +++++++++++++++----- 7 files changed, 88 insertions(+), 17 deletions(-) diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 1d446f40f4..21c8967b2f 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -51,9 +51,14 @@ void attachAvatarDataToAgent(Agent *newAgent) { } } -int main(int argc, char* argv[]) +int main(int argc, const char* argv[]) { AgentList *agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT); + if (cmdOptionExists(argc, argv, "--local")) { + printf("Local Domain MODE!\n"); + int ip = getLocalAddress(); + sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF)); + } setvbuf(stdout, NULL, _IOLBF, 0); agentList->linkedDataCreateCallback = attachAvatarDataToAgent; diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 9f9d1febba..5ab16bfe7b 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -653,6 +653,35 @@ void Avatar::render(bool lookingInMirror) { glEnd(); } } + + if (!_chatMessage.empty()) { + float width = 0; + for (string::iterator it = _chatMessage.begin(); it != _chatMessage.end(); it++) { + width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*0.0005; + } + glPushMatrix(); + + // extract the view direction from the modelview matrix: transform (0, 0, 1) by the + // transpose of the modelview to get its direction in world space, then use the X/Z + // components to determine the angle + float modelview[16]; + glGetFloatv(GL_MODELVIEW_MATRIX, modelview); + + glTranslatef(_position.x, _position.y + 0.7, _position.z); + glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PI, 0, 1, 0); + glTranslatef(width * 0.5, 0, 0); + + // TODO: For no apparent reason, OpenGL is hiding the first character. This fixes it (it + // gets hidden instead), but we should find and fix the underlying problem. + glBegin(GL_LINE_STRIP); + glVertex2f(0, 0); + glVertex2f(0, 0); + glEnd(); + + drawtext(0, 0, 0.0005, 180, 1.0, 0, _chatMessage.c_str(), 1, 1, 1); + + glPopMatrix(); + } } diff --git a/interface/src/ChatEntry.cpp b/interface/src/ChatEntry.cpp index 39d82d6f16..370c68538f 100644 --- a/interface/src/ChatEntry.cpp +++ b/interface/src/ChatEntry.cpp @@ -12,6 +12,13 @@ using namespace std; +const int MAX_CONTENT_LENGTH = 140; + +void ChatEntry::clear () { + contents.clear(); + cursorPos = 0; +} + bool ChatEntry::key(unsigned char k) { switch (k) { case '\r': @@ -25,8 +32,10 @@ bool ChatEntry::key(unsigned char k) { return true; default: - contents.insert(cursorPos, 1, k); - cursorPos++; + if (contents.size() != MAX_CONTENT_LENGTH) { + contents.insert(cursorPos, 1, k); + cursorPos++; + } return true; } } diff --git a/interface/src/ChatEntry.h b/interface/src/ChatEntry.h index da91c847fe..b71a3d1b96 100644 --- a/interface/src/ChatEntry.h +++ b/interface/src/ChatEntry.h @@ -16,6 +16,8 @@ public: const std::string& getContents () const { return contents; } + void clear (); + bool key(unsigned char k); void specialKey(unsigned char k); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 497b4b31b5..8c2efed563 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1373,8 +1373,9 @@ void keyUp(unsigned char k, int x, int y) { void key(unsigned char k, int x, int y) { if (::chatEntryOn) { - if (!chatEntry.key()) { - + if (!chatEntry.key(k)) { + myAvatar.setChatMessage(chatEntry.getContents()); + chatEntry.clear(); ::chatEntryOn = false; } return; @@ -1656,7 +1657,12 @@ int main(int argc, const char * argv[]) return EXIT_SUCCESS; } - AgentList::createInstance(AGENT_TYPE_AVATAR); + unsigned int listenPort = AGENT_SOCKET_LISTEN_PORT; + const char* portStr = getCmdOption(argc, argv, "--listenPort"); + if (portStr) { + listenPort = atoi(portStr); + } + AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort); gettimeofday(&applicationStartupTime, NULL); const char* domainIP = getCmdOption(argc, argv, "--domain"); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index bbdcca9d19..853b69b611 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -16,6 +16,7 @@ #include "AvatarData.h" #include "avatars_Log.h" +using namespace std; using avatars_lib::printLog; @@ -112,10 +113,14 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { memcpy(destinationBuffer, &_cameraFarClip, sizeof(_cameraFarClip)); destinationBuffer += sizeof(_cameraFarClip); - // Key State - memcpy(destinationBuffer, &_keyState, sizeof(char)); - destinationBuffer += sizeof(char); + // key state + *destinationBuffer++ = _keyState; + // chat message + *destinationBuffer++ = _chatMessage.size(); + memcpy(destinationBuffer, _chatMessage.data(), _chatMessage.size() * sizeof(char)); + destinationBuffer += _chatMessage.size() * sizeof(char); + return destinationBuffer - bufferStart; } @@ -171,9 +176,13 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { memcpy(&_cameraFarClip, sourceBuffer, sizeof(_cameraFarClip)); sourceBuffer += sizeof(_cameraFarClip); - // Key State - memcpy(&_keyState, sourceBuffer, sizeof(char)); - sourceBuffer += sizeof(char); + // key state + _keyState = (KeyState)*sourceBuffer++; + + // the rest is a chat message + int chatMessageSize = *sourceBuffer++; + _chatMessage = string((char*)sourceBuffer, chatMessageSize); + sourceBuffer += chatMessageSize * sizeof(char); return sourceBuffer - startPosition; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 13436d15df..34c33832d6 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -9,6 +9,8 @@ #ifndef __hifi__AvatarData__ #define __hifi__AvatarData__ +#include + #include #include @@ -74,9 +76,15 @@ public: void setCameraNearClip(float nearClip) { _cameraNearClip = nearClip; } void setCameraFarClip(float farClip) { _cameraFarClip = farClip; } - // Key state - void setKeyState(char s) { _keyState = s; } - char keyState() const { return _keyState; } + enum KeyState { NoKey, KeyDown, KeyUp, DeleteKey }; + + // key state + void setKeyState(KeyState s) { _keyState = s; } + KeyState keyState() const { return _keyState; } + + // chat message + void setChatMessage(const std::string& msg) { _chatMessage = msg; } + const std::string& chatMessage () const { return _chatMessage; } protected: glm::vec3 _position; @@ -110,8 +118,11 @@ protected: float _cameraNearClip; float _cameraFarClip; - // Key state (nothing, down, up, backspace) - char _keyState; + // key state (nothing, down, up, backspace) + KeyState _keyState; + + // chat message + std::string _chatMessage; }; #endif /* defined(__hifi__AvatarData__) */ From d041072d408378a3beb7dad09632cec280b7d8af Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 25 Apr 2013 15:26:05 -0700 Subject: [PATCH 4/7] Delete support (though the one on my numeric keypad doesn't work?), sending key states. --- interface/src/Avatar.cpp | 4 ++-- interface/src/ChatEntry.cpp | 6 ++++++ interface/src/main.cpp | 11 ++++++++++- libraries/avatars/src/AvatarData.cpp | 3 ++- libraries/avatars/src/AvatarData.h | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 5ab16bfe7b..965de70822 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -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(); } diff --git a/interface/src/ChatEntry.cpp b/interface/src/ChatEntry.cpp index 370c68538f..b658cbaefd 100644 --- a/interface/src/ChatEntry.cpp +++ b/interface/src/ChatEntry.cpp @@ -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) { diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 8c2efed563..1d7d8b1481 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -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; diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 853b69b611..58d4943b97 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -50,7 +50,8 @@ AvatarData::AvatarData() : _cameraFov(0.0f), _cameraAspectRatio(0.0f), _cameraNearClip(0.0f), - _cameraFarClip(0.0f) { + _cameraFarClip(0.0f), + _keyState(NoKeyDown) { } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 34c33832d6..94b68f7e04 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -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; } From 620e1c728c6dbb37f9389e6873ba6a2c62d3bcaf Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 25 Apr 2013 15:41:09 -0700 Subject: [PATCH 5/7] Removed kludge; it turned out lighting was enabled. --- interface/src/Avatar.cpp | 15 ++++++--------- interface/src/ChatEntry.h | 1 - interface/src/main.cpp | 7 ++++++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 965de70822..b6be2e072d 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -37,6 +37,8 @@ bool usingBigSphereCollisionTest = true; char iris_texture_file[] = "resources/images/green_eye.png"; +float chatMessageScale = 0.00025; + vector iris_texture; unsigned int iris_texture_width = 512; unsigned int iris_texture_height = 256; @@ -657,7 +659,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.00025; + width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*chatMessageScale; } glPushMatrix(); @@ -671,14 +673,9 @@ void Avatar::render(bool lookingInMirror) { glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PI, 0, 1, 0); glTranslatef(width * 0.5, 0, 0); - // TODO: For no apparent reason, OpenGL is hiding the first character. This fixes it (it - // gets hidden instead), but we should find and fix the underlying problem. - glBegin(GL_LINE_STRIP); - glVertex2f(0, 0); - glVertex2f(0, 0); - glEnd(); - - drawtext(0, 0, 0.00025, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0); + glDisable(GL_LIGHTING); + drawtext(0, 0, chatMessageScale, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0); + glEnable(GL_LIGHTING); glPopMatrix(); } diff --git a/interface/src/ChatEntry.h b/interface/src/ChatEntry.h index b71a3d1b96..ea9fc8eb77 100644 --- a/interface/src/ChatEntry.h +++ b/interface/src/ChatEntry.h @@ -19,7 +19,6 @@ public: void clear (); bool key(unsigned char k); - void specialKey(unsigned char k); void render(int screenWidth, int screenHeight); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 1d7d8b1481..dc716cfe41 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1455,7 +1455,12 @@ void key(unsigned char k, int x, int y) if (k == 'g') renderPitchRate += KEYBOARD_PITCH_RATE; if (k == 'a') myAvatar.setDriveKeys(ROT_LEFT, 1); if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 1); - if (k == '\r') ::chatEntryOn = true; + + if (k == '\r') { + ::chatEntryOn = true; + myAvatar.setKeyState(AvatarData::NoKeyDown); + myAvatar.setChatMessage(string()); + } } // Receive packets from other agents/servers and decide what to do with them! From 1713bebb64257b3146bd945011f44bf87264f24c Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 25 Apr 2013 17:36:47 -0700 Subject: [PATCH 6/7] 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()); From c6661e8b8e869f0d8a6bf44a01615e5a07e97261 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 25 Apr 2013 17:48:47 -0700 Subject: [PATCH 7/7] Lowered the chat message height and put it in a variable. --- interface/src/Avatar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 093e51fdff..305555577b 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -38,6 +38,7 @@ bool usingBigSphereCollisionTest = true; char iris_texture_file[] = "resources/images/green_eye.png"; float chatMessageScale = 0.00025; +float chatMessageHeight = 0.4; vector iris_texture; unsigned int iris_texture_width = 512; @@ -648,7 +649,7 @@ void Avatar::render(bool lookingInMirror) { float modelview[16]; glGetFloatv(GL_MODELVIEW_MATRIX, modelview); - glTranslatef(_position.x, _position.y + 0.7, _position.z); + glTranslatef(_position.x, _position.y + chatMessageHeight, _position.z); glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PI, 0, 1, 0); glTranslatef(width * 0.5, 0, 0);