Changeset 5969 for code/branches/console
- Timestamp:
- Oct 20, 2009, 6:47:40 PM (15 years ago)
- Location:
- code/branches/console/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/Shell.cc
r5929 r5969 35 35 #include "Core.h" 36 36 #include "ConsoleCommand.h" 37 38 #define SHELL_UPDATE_LISTENERS(function) \39 for (std::list<ShellListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) \40 (*(it++))->function()41 37 42 38 namespace orxonox … … 153 149 void Shell::registerListener(ShellListener* listener) 154 150 { 155 this->listeners_. insert(this->listeners_.end(),listener);151 this->listeners_.push_back(listener); 156 152 } 157 153 … … 161 157 { 162 158 if ((*it) == listener) 163 this->listeners_.erase(it++);159 it = this->listeners_.erase(it); 164 160 else 165 161 ++it; … … 170 166 { 171 167 this->inputBuffer_->setCursorPosition(cursor); 172 SHELL_UPDATE_LISTENERS(cursorChanged);168 this->updateListeners<&ShellListener::cursorChanged>(); 173 169 } 174 170 … … 199 195 this->finishedLastLine_ = true; 200 196 201 SHELL_UPDATE_LISTENERS(linesChanged);197 this->updateListeners<&ShellListener::linesChanged>(); 202 198 } 203 199 … … 258 254 if (!this->scrollPosition_) 259 255 { 260 SHELL_UPDATE_LISTENERS(lineAdded);256 this->updateListeners<&ShellListener::lineAdded>(); 261 257 } 262 258 } … … 265 261 (*this->lines_.begin()) += output; 266 262 this->finishedLastLine_ = newline; 267 SHELL_UPDATE_LISTENERS(onlyLastLineChanged);263 this->updateListeners<&ShellListener::onlyLastLineChanged>(); 268 264 } 269 265 … … 273 269 void Shell::inputChanged() 274 270 { 275 SHELL_UPDATE_LISTENERS(inputChanged);276 SHELL_UPDATE_LISTENERS(cursorChanged);271 this->updateListeners<&ShellListener::inputChanged>(); 272 this->updateListeners<&ShellListener::cursorChanged>(); 277 273 } 278 274 … … 299 295 { 300 296 this->inputBuffer_->removeBehindCursor(); 301 SHELL_UPDATE_LISTENERS(inputChanged);302 SHELL_UPDATE_LISTENERS(cursorChanged);297 this->updateListeners<&ShellListener::inputChanged>(); 298 this->updateListeners<&ShellListener::cursorChanged>(); 303 299 } 304 300 … … 306 302 { 307 303 this->inputBuffer_->removeAtCursor(); 308 SHELL_UPDATE_LISTENERS(inputChanged);304 this->updateListeners<&ShellListener::inputChanged>(); 309 305 } 310 306 … … 313 309 this->inputBuffer_->clear(); 314 310 this->historyPosition_ = 0; 315 SHELL_UPDATE_LISTENERS(inputChanged);316 SHELL_UPDATE_LISTENERS(cursorChanged);311 this->updateListeners<&ShellListener::inputChanged>(); 312 this->updateListeners<&ShellListener::cursorChanged>(); 317 313 } 318 314 … … 320 316 { 321 317 this->inputBuffer_->increaseCursor(); 322 SHELL_UPDATE_LISTENERS(cursorChanged);318 this->updateListeners<&ShellListener::cursorChanged>(); 323 319 } 324 320 … … 326 322 { 327 323 this->inputBuffer_->decreaseCursor(); 328 SHELL_UPDATE_LISTENERS(cursorChanged);324 this->updateListeners<&ShellListener::cursorChanged>(); 329 325 } 330 326 … … 332 328 { 333 329 this->inputBuffer_->setCursorToEnd(); 334 SHELL_UPDATE_LISTENERS(cursorChanged);330 this->updateListeners<&ShellListener::cursorChanged>(); 335 331 } 336 332 … … 338 334 { 339 335 this->inputBuffer_->setCursorToBegin(); 340 SHELL_UPDATE_LISTENERS(cursorChanged);336 this->updateListeners<&ShellListener::cursorChanged>(); 341 337 } 342 338 … … 366 362 ++this->scrollPosition_; 367 363 368 SHELL_UPDATE_LISTENERS(linesChanged);364 this->updateListeners<&ShellListener::linesChanged>(); 369 365 } 370 366 } … … 377 373 --this->scrollPosition_; 378 374 379 SHELL_UPDATE_LISTENERS(linesChanged);375 this->updateListeners<&ShellListener::linesChanged>(); 380 376 } 381 377 } … … 393 389 this->scrollIterator_ = this->lines_.begin(); 394 390 395 SHELL_UPDATE_LISTENERS(exit);391 this->updateListeners<&ShellListener::exit>(); 396 392 } 397 393 } -
code/branches/console/src/libraries/core/Shell.h
r5781 r5969 132 132 void exit(); 133 133 134 template <void (ShellListener::*F)()> 135 void updateListeners() 136 { 137 for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) 138 ((*(it++))->*F)(); 139 } 140 134 141 std::list<ShellListener*> listeners_; 135 142 InputBuffer* inputBuffer_; -
code/branches/console/src/orxonox/overlays/InGameConsole.cc
r5929 r5969 68 68 */ 69 69 InGameConsole::InGameConsole() 70 : consoleOverlay_(0) 70 : shell_(Shell::getInstance()) 71 , consoleOverlay_(0) 71 72 , consoleOverlayContainer_(0) 72 73 , consoleOverlayNoise_(0) … … 174 175 // create the corresponding input state 175 176 inputState_ = InputManager::getInstance().createInputState("console", false, false, InputStatePriority::Console); 176 inputState_->setKeyHandler( Shell::getInstance().getInputBuffer());177 inputState_->setKeyHandler(this->shell_.getInputBuffer()); 177 178 bHidesAllInputChanged(); 178 179 … … 252 253 this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight); 253 254 254 Shell::getInstance().addOutputLevel(true);255 this->shell_.addOutputLevel(true); 255 256 256 257 COUT(4) << "Info: InGameConsole initialized" << std::endl; … … 266 267 void InGameConsole::linesChanged() 267 268 { 268 std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator();269 std::list<std::string>::const_iterator it = this->shell_.getNewestLineIterator(); 269 270 int max = 0; 270 271 for (int i = 1; i < LINES; ++i) 271 272 { 272 if (it != Shell::getInstance().getEndIterator())273 if (it != this->shell_.getEndIterator()) 273 274 { 274 275 ++it; … … 295 296 { 296 297 if (LINES > 1) 297 this->print(* Shell::getInstance().getNewestLineIterator(), 1);298 this->print(*this->shell_.getNewestLineIterator(), 1); 298 299 } 299 300 … … 314 315 { 315 316 if (LINES > 0) 316 this->print( Shell::getInstance().getInput(), 0);317 318 if ( Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0)317 this->print(this->shell_.getInput(), 0); 318 319 if (this->shell_.getInput() == "" || this->shell_.getInput().size() == 0) 319 320 this->inputWindowStart_ = 0; 320 321 } … … 325 326 void InGameConsole::cursorChanged() 326 327 { 327 unsigned int pos = Shell::getInstance().getCursorPosition() - inputWindowStart_;328 unsigned int pos = this->shell_.getCursorPosition() - inputWindowStart_; 328 329 if (pos > maxCharsPerLine_) 329 330 pos = maxCharsPerLine_; … … 482 483 if (output.size() > this->maxCharsPerLine_) 483 484 { 484 if ( Shell::getInstance().getInputBuffer()->getCursorPosition() < this->inputWindowStart_)485 this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition();486 else if ( Shell::getInstance().getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))487 this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;485 if (this->shell_.getInputBuffer()->getCursorPosition() < this->inputWindowStart_) 486 this->inputWindowStart_ = this->shell_.getInputBuffer()->getCursorPosition(); 487 else if (this->shell_.getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1)) 488 this->inputWindowStart_ = this->shell_.getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1; 488 489 489 490 output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_); … … 506 507 this->bActive_ = true; 507 508 InputManager::getInstance().enterState("console"); 508 Shell::getInstance().registerListener(this);509 this->shell_.registerListener(this); 509 510 510 511 this->windowResized(this->windowW_, this->windowH_); … … 528 529 this->bActive_ = false; 529 530 InputManager::getInstance().leaveState("console"); 530 Shell::getInstance().unregisterListener(this);531 this->shell_.unregisterListener(this); 531 532 532 533 // scroll up -
code/branches/console/src/orxonox/overlays/InGameConsole.h
r5929 r5969 81 81 82 82 private: // variables 83 Shell& shell_; 83 84 bool bActive_; 84 85 int windowW_;
Note: See TracChangeset
for help on using the changeset viewer.