Changeset 6846 for code/branches/chat2/src
- Timestamp:
- May 3, 2010, 4:46:00 PM (15 years ago)
- Location:
- code/branches/chat2/src/orxonox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/chat2/src/orxonox/ChatHistory.cc
r6836 r6846 80 80 std::string text; 81 81 82 COUT(0) << "Meow.\n";82 //COUT(0) << "Meow.\n"; 83 83 84 84 #ifndef CHATTEST -
code/branches/chat2/src/orxonox/ChatInputHandler.cc
r6837 r6846 31 31 #include "core/ConsoleCommand.h" 32 32 #include "core/CoreIncludes.h" 33 #include "core/GUIManager.h" 34 #include "core/CorePrereqs.h" 35 #include <CEGUIWindow.h> 36 #include <CEGUI/elements/CEGUIListbox.h> 37 #include <CEGUI/elements/CEGUIListboxItem.h> 38 #include <CEGUI/elements/CEGUIListboxTextItem.h> 39 #include <CEGUIWindowManager.h> 33 40 #include <string> 34 41 … … 40 47 true ); 41 48 49 42 50 /* constructor */ 43 51 ChatInputHandler::ChatInputHandler() … … 48 56 /* create necessary objects */ 49 57 this->inpbuf = new InputBuffer(); 58 assert( this->inpbuf != NULL ); 59 60 /* MARK add generation of ChatBox thingy here */ 61 GUIManager::getInstance().loadGUI( "ChatBox" ); 50 62 51 63 /* configure the input buffer */ … … 62 74 void ChatInputHandler::configureInputBuffer() 63 75 { 64 76 /* input has changed */ 65 77 this->inpbuf->registerListener(this, &ChatInputHandler::inputChanged, true); 66 67 78 79 /* add a line */ 68 80 this->inpbuf->registerListener(this, &ChatInputHandler::addline, '\r', false); 69 81 this->inpbuf->registerListener(this, &ChatInputHandler::addline, '\n', false); 70 82 71 83 /* backspace */ 72 84 this->inpbuf->registerListener(this, &ChatInputHandler::backspace, '\b', true); 73 85 this->inpbuf->registerListener(this, &ChatInputHandler::backspace, '\177', true); 74 86 75 87 /* exit the chatinputhandler thingy (tbd) */ 76 88 this->inpbuf->registerListener(this, &ChatInputHandler::exit, '\033', true); // escape 77 89 78 90 /* delete character */ 79 91 this->inpbuf->registerListener(this, &ChatInputHandler::deleteChar, KeyCode::Delete); 80 92 81 93 /* cursor movement */ 82 94 this->inpbuf->registerListener(this, &ChatInputHandler::cursorRight, KeyCode::Right); 83 95 this->inpbuf->registerListener(this, &ChatInputHandler::cursorLeft, KeyCode::Left); 84 96 this->inpbuf->registerListener(this, &ChatInputHandler::cursorEnd, KeyCode::End); 85 97 this->inpbuf->registerListener(this, &ChatInputHandler::cursorHome, KeyCode::Home); 98 99 /* get window pointers */ 100 input = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/input" ); 101 CEGUI::Window *history = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/history" ); 102 lb_history = dynamic_cast<CEGUI::Listbox*>(history); 103 104 /* assert wee */ 105 assert( lb_history ); 86 106 } 87 107 … … 94 114 { 95 115 /* start listening */ 96 COUT(0) << "chatinput activated." << std::endl;116 //COUT(0) << "chatinput activated." << std::endl; 97 117 InputManager::getInstance().enterState("chatinput"); 118 119 /* MARK add spawning of chat widget stuff here.*/ 120 GUIManager::getInstance().showGUI( "ChatBox" ); 98 121 } 99 122 … … 102 125 /* stop listening */ 103 126 InputManager::getInstance().leaveState("chatinput"); 104 } 105 106 127 128 /* MARK add un-spawning of chat widget stuff here. */ 129 GUIManager::getInstance().hideGUI( "ChatBox" ); 130 } 107 131 108 132 /* callbacks for InputBuffer */ 109 133 void ChatInputHandler::inputChanged() 110 134 { 111 135 /* update the cursor and the window */ 136 std::string raw = this->inpbuf->get(); 137 138 /* get string before cursor */ 139 std::string left = raw.substr( 0, this->inpbuf->getCursorPosition() ); 140 141 /* see if there's a string after the cursor */ 142 std::string right = ""; 143 if( raw.length() >= left.length()+1 ) 144 right = raw.substr( this->inpbuf->getCursorPosition() ); 145 146 /* set the text */ 147 this->input->setProperty( "Text", left + "|" + right ); 112 148 } 113 149 114 150 void ChatInputHandler::addline() 115 151 { 116 /* MARK MARK */117 118 152 /* actually do send what was input */ 119 153 /* a) get the string out of the inputbuffer */ 120 154 std::string msgtosend = this->inpbuf->get(); 121 155 156 if( msgtosend.length() == 0 ) 157 { this->deactivate(); 158 return; 159 } 160 122 161 /* b) clear the input buffer */ 123 162 if (this->inpbuf->getSize() > 0) … … 129 168 /* d) stop listening to input */ 130 169 this->deactivate(); 170 171 /* e) create item and add to history */ 172 CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( msgtosend ); 173 this->lb_history->addItem( dynamic_cast<CEGUI::ListboxItem*>(toadd) ); 174 this->lb_history->ensureItemIsVisible( dynamic_cast<CEGUI::ListboxItem*>(toadd) ); 175 176 /* f) make sure the history handles it */ 177 this->lb_history->handleUpdatedItemData(); 131 178 } 132 179 133 180 void ChatInputHandler::backspace() 134 { 135 this->inpbuf->removeBehindCursor(); 136 } 181 { this->inpbuf->removeBehindCursor(); } 137 182 138 183 void ChatInputHandler::deleteChar() 139 { 140 this->inpbuf->removeAtCursor(); 141 } 184 { this->inpbuf->removeAtCursor(); } 142 185 143 186 void ChatInputHandler::cursorRight() 144 { 145 this->inpbuf->increaseCursor(); 146 } 187 { this->inpbuf->increaseCursor(); } 147 188 148 189 void ChatInputHandler::cursorLeft() 149 { 150 this->inpbuf->decreaseCursor(); 151 } 190 { this->inpbuf->decreaseCursor(); } 152 191 153 192 void ChatInputHandler::cursorEnd() 154 { 155 this->inpbuf->setCursorToEnd(); 156 } 193 { this->inpbuf->setCursorToEnd(); } 157 194 158 195 void ChatInputHandler::cursorHome() 159 { 160 this->inpbuf->setCursorToBegin(); 161 } 196 { this->inpbuf->setCursorToBegin(); } 162 197 163 198 void ChatInputHandler::exit() 164 { 165 166 } 199 { } 167 200 168 201 } -
code/branches/chat2/src/orxonox/ChatInputHandler.h
r6836 r6846 36 36 #include <iostream> 37 37 #include <cassert> 38 #include <CEGUIForwardRefs.h> 38 39 39 40 /* project includes */ … … 71 72 static ChatInputHandler* singletonPtr_s; 72 73 74 /* cegui stuff */ 75 CEGUI::Window *input; 76 CEGUI::Listbox *lb_history; 77 73 78 public: 74 79 /** constructor */
Note: See TracChangeset
for help on using the changeset viewer.