Changeset 6876 for code/branches/chat2/src
- Timestamp:
- May 10, 2010, 3:18:14 PM (15 years ago)
- Location:
- code/branches/chat2/src/orxonox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/chat2/src/orxonox/ChatInputHandler.cc
r6870 r6876 44 44 /* singleton */ 45 45 ManageScopedSingleton( ChatInputHandler, ScopeID::Graphics, false ); 46 47 /* add commands to console */ 46 48 SetConsoleCommandAlias( ChatInputHandler, activate_static, "startchat", 47 49 true ); … … 49 51 "startchat_small", true ); 50 52 51 52 53 /* constructor */ 53 54 ChatInputHandler::ChatInputHandler() … … 58 59 /* create necessary objects */ 59 60 this->inpbuf = new InputBuffer(); 61 this->disp_offset = 0; 60 62 assert( this->inpbuf != NULL ); 61 63 … … 133 135 InputManager::getInstance().leaveState("chatinput"); 134 136 135 /* MARK add un-spawning of chat widget stuff here.*/137 /* un-spawning of chat widget stuff */ 136 138 GUIManager::getInstance().hideGUI( "ChatBox" ); 137 139 GUIManager::getInstance().hideGUI( "ChatBox-inputonly" ); 138 140 } 139 141 142 void ChatInputHandler::sub_adjust_dispoffset( int maxlen, int cursorpos, int inplen ) 143 { 144 /* already start offsetting 5 characters before end */ 145 if( cursorpos+5 > maxlen ) 146 { 147 /* always stay 5 characters ahead of end, looks better */ 148 ((disp_offset = cursorpos-maxlen+5) >= 0) ? 1 : disp_offset = 0; 149 150 /* enforce visibility of cursor */ 151 (disp_offset > cursorpos ) ? disp_offset = 0 : 1; 152 } 153 154 /* make sure we don't die at substr */ 155 if( inplen <= disp_offset ) disp_offset = 0; 156 } 157 140 158 /* callbacks for InputBuffer */ 141 159 void ChatInputHandler::inputChanged() … … 143 161 /* update the cursor and the window */ 144 162 std::string raw = this->inpbuf->get(); 163 int cursorpos = this->inpbuf->getCursorPosition(); 145 164 146 165 /* get string before cursor */ 147 std::string left = raw.substr( 0, this->inpbuf->getCursorPosition());166 std::string left = raw.substr( 0, cursorpos ); 148 167 149 168 /* see if there's a string after the cursor */ 150 169 std::string right = ""; 151 170 if( raw.length() >= left.length()+1 ) 152 right = raw.substr( this->inpbuf->getCursorPosition());171 right = raw.substr( cursorpos ); 153 172 154 173 /* set the text */ 155 this->input->setProperty( "Text", left + "|" + right ); 156 this->inputonly->setProperty( "Text", left + "|" + right ); 174 std::string assembled = "$ " + left + "|" + right; 175 176 /* adjust curser position - magic number 5 for font width */ 177 sub_adjust_dispoffset( (this->input->getUnclippedInnerRect().getWidth()/6), 178 cursorpos, assembled.length() ); 179 this->input->setProperty( "Text", assembled.substr( disp_offset ) ); 180 181 /* reset display offset */ 182 disp_offset = 0; 183 184 /* adjust curser position - magic number 5 for font width */ 185 sub_adjust_dispoffset( (this->inputonly->getUnclippedInnerRect().getWidth()/6), 186 cursorpos, assembled.length() ); 187 this->inputonly->setProperty( "Text", assembled.substr( disp_offset) ); 188 189 /* reset display offset */ 190 disp_offset = 0; 157 191 } 158 192 -
code/branches/chat2/src/orxonox/ChatInputHandler.h
r6870 r6876 62 62 */ 63 63 InputBuffer *inpbuf; 64 int disp_offset, width; 64 65 65 66 /** input state */ … … 68 69 /** setup input buffer, the constructor calls this */ 69 70 void configureInputBuffer(); 71 72 /** adjust display offset depending on cursor position */ 73 void sub_adjust_dispoffset( int maxlen, int cursorpos, int inplen ); 70 74 71 75 /* singleton pointer */
Note: See TracChangeset
for help on using the changeset viewer.