mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 02:33:09 +02:00
Fleshing out the chat entry widget.
This commit is contained in:
parent
9d4fded901
commit
1a79bbd80d
3 changed files with 72 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -9,12 +9,24 @@
|
|||
#ifndef __interface__ChatEntry__
|
||||
#define __interface__ChatEntry__
|
||||
|
||||
#include <string>
|
||||
|
||||
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__) */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue