Changeset 6177 for code/branches/presentation2/src/libraries/core
- Timestamp:
- Nov 29, 2009, 2:47:54 PM (15 years ago)
- Location:
- code/branches/presentation2/src/libraries/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/core/IOConsole.cc
r6172 r6177 33 33 #include <iostream> 34 34 35 #include "util/Clock.h" 35 36 #include "util/Math.h" 36 37 #include "core/Game.h" … … 61 62 } 62 63 63 inline bool IOConsole::willPrintStatusLines()64 {65 return !this->statusLineWidths_.empty()66 && this->terminalWidth_ >= this->statusLineMaxWidth_67 && this->terminalHeight_ >= (this->minOutputLines_ + this->statusLineWidths_.size());68 }69 70 64 // ############################### 71 65 // ### ShellListener methods ### … … 78 72 // or when scrolling. But scrolling is disabled and the output 79 73 // is already in std::cout when we start the IOConsole 80 }81 82 //! Called if the text in the input-line has changed83 void IOConsole::inputChanged()84 {85 this->printInputLine();86 this->cout_.flush();87 }88 89 //! Called if the position of the cursor in the input-line has changed90 void IOConsole::cursorChanged()91 {92 this->printInputLine();93 this->cout_.flush();94 74 } 95 75 … … 131 111 , buffer_(shell_->getInputBuffer()) 132 112 , cout_(std::cout.rdbuf()) 113 , promptString_("orxonox # ") 133 114 , bStatusPrinted_(false) 134 , promptString_("orxonox # ")135 115 , originalTerminalSettings_(0) 136 116 { … … 304 284 } 305 285 306 void IOConsole::print LogText(const std::string& text)286 void IOConsole::printOutputLine(const std::string& text) 307 287 { 308 288 std::string output = text; … … 419 399 } 420 400 401 inline bool IOConsole::willPrintStatusLines() 402 { 403 return !this->statusLineWidths_.empty() 404 && this->terminalWidth_ >= this->statusLineMaxWidth_ 405 && this->terminalHeight_ >= (this->minOutputLines_ + this->statusLineWidths_.size()); 406 } 407 421 408 // ############################### 422 409 // ### ShellListener methods ### … … 431 418 this->cout_ << "\033[K"; 432 419 // Reprint the last output line 433 this->print LogText(*(this->shell_->getNewestLineIterator()));420 this->printOutputLine(*(this->shell_->getNewestLineIterator())); 434 421 // Restore cursor 435 422 this->cout_ << "\033[u"; … … 449 436 // Print the new output lines 450 437 for (int i = 0; i < newLines; ++i) 451 this->print LogText(this->shell_->getNewestLineIterator()->substr(i*this->terminalWidth_, this->terminalWidth_));438 this->printOutputLine(this->shell_->getNewestLineIterator()->substr(i*this->terminalWidth_, this->terminalWidth_)); 452 439 // Move cursor down 453 440 this->cout_ << "\033[1B\033[1G"; … … 457 444 this->cout_.flush(); 458 445 } 446 447 //! Called if the text in the input-line has changed 448 void IOConsole::inputChanged() 449 { 450 this->printInputLine(); 451 this->cout_.flush(); 452 } 453 454 //! Called if the position of the cursor in the input-line has changed 455 void IOConsole::cursorChanged() 456 { 457 this->printInputLine(); 458 this->cout_.flush(); 459 } 459 460 } 460 461 … … 472 473 , buffer_(shell_->getInputBuffer()) 473 474 , cout_(std::cout.rdbuf()) 474 , bStatusPrinted_(false)475 475 , promptString_("orxonox # ") 476 { 477 this->setTerminalMode(); 478 this->shell_->registerListener(this); 479 480 // Manually set the widths of the individual status lines 481 this->statusLineWidths_.push_back(29); 482 this->statusLineMaxWidth_ = 29; 483 484 this->getTerminalSize(); 485 this->lastTerminalWidth_ = this->terminalWidth_; 486 this->lastTerminalHeight_ = this->terminalHeight_; 487 476 , statusLines_(1) 477 , inputLineHeight_(1) 478 , lastOutputLineHeight_(1) 479 { 488 480 // Disable standard this->cout_ logging 489 481 OutputHandler::getInstance().disableCout(); … … 492 484 std::cout.rdbuf(this->origCout_.rdbuf()); 493 485 494 // Make sure we make way for the status lines 486 this->setTerminalMode(); 487 CONSOLE_SCREEN_BUFFER_INFO screenBufferInfo; 488 GetConsoleScreenBufferInfo(this->stdOutHandle_, &screenBufferInfo); 489 this->terminalWidth_ = screenBufferInfo.dwSize.X; 490 this->terminalHeight_ = screenBufferInfo.dwSize.Y; 491 this->lastTerminalWidth_ = this->terminalWidth_; 492 this->lastTerminalHeight_ = this->terminalHeight_; 493 // Determines where we are in respect to output already written with std::cout 494 this->inputLineRow_ = screenBufferInfo.dwCursorPosition.Y; 495 496 // Cursor already at the end of the screen buffer? 497 // (assuming the current input line height is 1) 498 if (this->inputLineRow_ >= (int)this->terminalHeight_ - (int)this->statusLines_) 499 this->moveCursor(0, -this->inputLineRow_ + this->terminalHeight_ - this->statusLines_ - 1); 500 501 // Prevent input line from overflowing 502 int maxInputLength = (this->terminalHeight_ - this->statusLines_) * this->terminalWidth_ - 1 - this->promptString_.size(); 503 // Consider that the echo of a command might include the command plus some other characters (assumed max 80) 504 // Also put a minimum so the config file parser is not overwhelmed with the command history 505 this->shell_->getInputBuffer()->setMaxLength(std::min(8192, (maxInputLength - 80) / 2)); 506 507 // Print input and status line and position cursor 508 this->lastRefreshTime_ = Game::getInstance().getGameClock().getRealMicroseconds(); 495 509 this->update(Game::getInstance().getGameClock()); 510 this->inputChanged(); 511 this->cursorChanged(); 512 513 this->shell_->registerListener(this); 496 514 } 497 515 498 516 IOConsole::~IOConsole() 499 517 { 518 this->shell_->unregisterListener(this); 500 519 // Empty all buffers 501 520 this->update(Game::getInstance().getGameClock()); 502 521 503 resetTerminalMode(); 504 this->shell_->destroy(); 522 // Erase input and status lines 523 COORD pos = {0, this->inputLineRow_}; 524 this->writeText(std::string((this->inputLineHeight_ + this->statusLines_) * this->terminalWidth_, ' '), pos); 525 // Move cursor to the beginning of the line 526 SetConsoleCursorPosition(stdOutHandle_, pos); 505 527 506 528 // Restore this->cout_ redirection … … 508 530 // Enable standard this->cout_ logging again 509 531 OutputHandler::getInstance().enableCout(); 532 533 resetTerminalMode(); 534 this->shell_->destroy(); 510 535 } 511 536 512 537 void IOConsole::update(const Clock& time) 513 538 { 539 // Process input 514 540 while (true) 515 541 { … … 539 565 { 540 566 case VK_BACK: this->buffer_->buttonPressed(KeyEvent(KeyCode::Back, asciiChar, modifiersOut)); break; 541 case VK_TAB: this->buffer_->buttonPressed(KeyEvent(KeyCode:: Back,asciiChar, modifiersOut)); break;542 case VK_RETURN: this->buffer_->buttonPressed(KeyEvent(KeyCode:: Back,asciiChar, modifiersOut)); break;567 case VK_TAB: this->buffer_->buttonPressed(KeyEvent(KeyCode::Tab, asciiChar, modifiersOut)); break; 568 case VK_RETURN: this->buffer_->buttonPressed(KeyEvent(KeyCode::Return, asciiChar, modifiersOut)); break; 543 569 case VK_PAUSE: this->buffer_->buttonPressed(KeyEvent(KeyCode::Pause, asciiChar, modifiersOut)); break; 544 570 case VK_ESCAPE: this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, asciiChar, modifiersOut)); break; … … 559 585 } 560 586 561 // Get info about cursor and terminal size 562 this->getTerminalSize(); 563 564 // Refresh status line 565 this->printStatusLines(); 587 // TODO: Respect screen buffer size changes 588 // The user can manually adjust the screen buffer size on Windows 589 // And we don't want to screw the console because of that 590 //this->lastTerminalWidth_ = this->terminalWidth_; 591 //this->lastTerminalHeight_ = this->terminalHeight_; 592 //this->getTerminalSize(); // Also sets this->inputLineRow_ according to the cursor position 593 // Is there still enough space below the cursor for the status line(s)? 594 //if (this->inputLineRow_ >= this->terminalHeight_ - this->statusLines_) 595 // this->moveCursor(0, -this->inputLineRow_ + this->terminalHeight_ - this->statusLines_ - 1); 596 597 // Refresh status line 5 times per second 598 if (time.getMicroseconds() > this->lastRefreshTime_ + 1000000) 599 { 600 this->printStatusLines(); 601 this->lastRefreshTime_ = time.getMicroseconds(); 602 } 566 603 567 604 // Process output written to std::cout … … 571 608 this->origCout_.str(""); 572 609 } 573 this->cout_.flush(); 574 } 575 576 void IOConsole::printLogText(const std::string& text) 610 } 611 612 void IOConsole::printOutputLine(const std::string& text, const COORD& pos) 577 613 { 578 614 std::string output = text; … … 580 616 581 617 // Colour line 618 WORD colour = 0; 582 619 switch (level) 583 620 { 584 case 1: SetConsoleTextAttribute(stdOutHandle_, FOREGROUND_RED | FOREGROUND_INTENSITY); break;585 case 2: SetConsoleTextAttribute(stdOutHandle_, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY); break;586 case 3: SetConsoleTextAttribute(stdOutHandle_, FOREGROUND_INTENSITY); break;587 case 4: SetConsoleTextAttribute(stdOutHandle_, FOREGROUND_INTENSITY); break;588 default: break;621 case 1: colour = FOREGROUND_RED | FOREGROUND_INTENSITY; break; 622 case 2: colour = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY; break; 623 case 3: colour = FOREGROUND_INTENSITY; break; 624 case 4: colour = FOREGROUND_INTENSITY; break; 625 default: colour = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN; break; 589 626 } 590 627 591 628 // Print output line 592 this->cout_ << output; 593 594 // Reset colour to white 595 SetConsoleTextAttribute(stdOutHandle_, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); 596 } 597 598 void IOConsole::printInputLine() 599 { 600 SetConsoleTextAttribute(stdOutHandle_, FOREGROUND_GREEN | FOREGROUND_INTENSITY); 601 this->moveCursorYAndHome(0); 602 this->clearCurrentLine(); 603 this->cout_ << this->promptString_ << this->shell_->getInput(); 604 this->moveCursorYAndHome(0); 605 this->moveCursor(this->promptString_.size() + this->buffer_->getCursorPosition(), 0); 606 SetConsoleTextAttribute(stdOutHandle_, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); 629 this->writeText(output, pos, colour); 607 630 } 608 631 609 632 void IOConsole::printStatusLines() 610 633 { 611 if (this->willPrintStatusLines()) 612 { 613 SetConsoleTextAttribute(stdOutHandle_, FOREGROUND_GREEN); 614 this->bStatusPrinted_ = true; 615 // Put cursor on home position, one line down the input line 616 this->moveCursorYAndHome(1); 617 this->cout_ << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, "; 618 this->cout_ << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms tick time"; 619 // Clear rest of the line 620 CONSOLE_SCREEN_BUFFER_INFO info; 621 GetConsoleScreenBufferInfo(this->stdOutHandle_, &info); 622 this->cout_ << std::string(info.dwSize.X - info.dwCursorPosition.X - 1, ' '); 623 // Restore cursor position 624 this->moveCursorYAndHome(-1); 625 this->moveCursor(this->promptString_.size() + this->buffer_->getCursorPosition(), 0); 626 SetConsoleTextAttribute(stdOutHandle_, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); 627 } 628 else 629 this->bStatusPrinted_ = false; 634 // Prepare text to be written 635 std::ostringstream oss; 636 oss << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, "; 637 oss << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms tick time"; 638 // Clear rest of the line by inserting spaces 639 oss << std::string(this->terminalWidth_ - oss.str().size(), ' '); 640 COORD pos = {0, this->inputLineRow_ + this->inputLineHeight_}; 641 this->writeText(oss.str(), pos, FOREGROUND_GREEN); 630 642 } 631 643 … … 650 662 } 651 663 652 //! Moves the console cursor around and inserts new lines when reaching the end. 653 //! Moving out on the right is just clamped though. 664 //! Moves the console cursor around and clamps its position to fit into the screen buffer 654 665 void IOConsole::moveCursor(int dx, int dy) 655 666 { … … 659 670 x = clamp(x + dx, 0, info.dwSize.X - 1); 660 671 SHORT& y = info.dwCursorPosition.Y; 661 if (y + dy >= info.dwSize.Y) 662 { 663 // Insert new lines 664 this->cout_ << std::string(y + dy - info.dwSize.Y + 1, 'n'); 665 y = info.dwSize.Y - 1; 666 } 667 else if (y < 0) 668 y = 0; 669 else 670 y += dy; 672 y = clamp(y + dy, 0, info.dwSize.Y - 1); 671 673 SetConsoleCursorPosition(this->stdOutHandle_, info.dwCursorPosition); 672 }673 674 void IOConsole::moveCursorYAndHome(int dy)675 {676 CONSOLE_SCREEN_BUFFER_INFO info;677 GetConsoleScreenBufferInfo(this->stdOutHandle_, &info);678 this->moveCursor(-info.dwCursorPosition.X, dy);679 }680 681 void IOConsole::clearCurrentLine()682 {683 CONSOLE_SCREEN_BUFFER_INFO info;684 GetConsoleScreenBufferInfo(this->stdOutHandle_, &info);685 info.dwCursorPosition.X = 0;686 DWORD count;687 FillConsoleOutputCharacter(this->stdOutHandle_, ' ', info.dwSize.X, info.dwCursorPosition, &count);;688 674 } 689 675 … … 692 678 CONSOLE_SCREEN_BUFFER_INFO screenBufferInfo; 693 679 GetConsoleScreenBufferInfo(this->stdOutHandle_, &screenBufferInfo); 694 // dwSize is the maximum size. If you resize you will simply see scroll bars.695 // And if you want to write outside these boundaries, you can't.696 680 this->terminalWidth_ = screenBufferInfo.dwSize.X; 697 681 this->terminalHeight_ = screenBufferInfo.dwSize.Y; 682 } 683 684 void IOConsole::writeText(const std::string& text, const COORD& coord, WORD attributes) 685 { 686 DWORD count; 687 WriteConsoleOutputCharacter(stdOutHandle_, text.c_str(), text.size(), coord, &count); 688 WORD* attributeBuf = new WORD[text.size()]; 689 for (unsigned int i = 0; i < text.size(); ++i) 690 attributeBuf[i] = attributes; 691 WriteConsoleOutputAttribute(stdOutHandle_, attributeBuf, text.size(), coord, &count); 692 } 693 694 void IOConsole::createNewOutputLines(unsigned int lines) 695 { 696 CHAR_INFO fillChar = {' ', FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED}; 697 // Check whether we're already at the bottom 698 if (this->inputLineRow_ + lines > this->terminalHeight_ - this->statusLines_ - this->inputLineHeight_) 699 { 700 // Scroll output up 701 SMALL_RECT oldRect = {0, lines, this->terminalWidth_ - 1, this->inputLineRow_ - 1}; 702 COORD newPos = {0, 0}; 703 ScrollConsoleScreenBuffer(stdOutHandle_, &oldRect, NULL, newPos, &fillChar); 704 } 705 else 706 { 707 // Scroll input and status lines down 708 SMALL_RECT oldRect = {0, this->inputLineRow_, this->terminalWidth_ - 1, this->inputLineRow_ + this->statusLines_ + this->inputLineHeight_ - 1}; 709 this->inputLineRow_ += lines; 710 COORD newPos = {0, this->inputLineRow_}; 711 ScrollConsoleScreenBuffer(stdOutHandle_, &oldRect, NULL, newPos, &fillChar); 712 // Move cursor down to the new bottom so the user can see the status lines 713 COORD pos = {0, this->inputLineRow_ + this->inputLineHeight_ - 1 + this->statusLines_}; 714 SetConsoleCursorPosition(stdOutHandle_, pos); 715 // Get cursor back to the right position 716 this->cursorChanged(); 717 } 698 718 } 699 719 … … 702 722 // ############################### 703 723 724 //! Called if the text in the input-line has changed 725 void IOConsole::inputChanged() 726 { 727 int inputLineLength = this->promptString_.size() + this->shell_->getInput().size(); 728 int lineHeight = 1 + inputLineLength / this->terminalWidth_; 729 int newLines = lineHeight - this->inputLineHeight_; 730 if (newLines > 0) 731 { 732 // Abuse this function to scroll the console 733 this->createNewOutputLines(newLines); 734 this->inputLineRow_ -= newLines; // Undo 735 } 736 else if (newLines < 0) 737 { 738 // Scroll status lines up 739 SMALL_RECT oldRect = {0, this->inputLineRow_ + this->inputLineHeight_, this->terminalWidth_ - 1, this->inputLineRow_ + this->inputLineHeight_ + this->statusLines_}; 740 COORD newPos = {0, this->inputLineRow_ + this->inputLineHeight_ + newLines}; 741 CHAR_INFO fillChar = {' ', FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED}; 742 ScrollConsoleScreenBuffer(stdOutHandle_, &oldRect, NULL, newPos, &fillChar); 743 // Clear potential leftovers 744 if (-newLines - this->statusLines_ > 0) 745 { 746 COORD pos = {0, this->inputLineRow_ + lineHeight + this->statusLines_}; 747 this->writeText(std::string((-newLines - this->statusLines_) * this->terminalWidth_, ' '), pos); 748 } 749 } 750 this->inputLineHeight_ = lineHeight; 751 752 // Print the whole line, including spaces to erase leftovers 753 COORD pos = {0, this->inputLineRow_}; 754 WORD colour = FOREGROUND_GREEN | FOREGROUND_INTENSITY; 755 this->writeText(this->promptString_ + this->shell_->getInput() + std::string(this->terminalWidth_ - inputLineLength % this->terminalWidth_, ' '), pos, colour); 756 // If necessary, move cursor 757 if (newLines != 0) 758 this->cursorChanged(); 759 } 760 761 //! Called if the position of the cursor in the input-line has changed 762 void IOConsole::cursorChanged() 763 { 764 COORD pos; 765 unsigned int total = this->promptString_.size() + this->buffer_->getCursorPosition(); 766 // Compensate for cursor further to the right than the terminal width 767 pos.X = total % this->terminalWidth_; 768 pos.Y = this->inputLineRow_ + total / this->terminalWidth_; 769 SetConsoleCursorPosition(stdOutHandle_, pos); 770 } 771 704 772 //! Called if only the last output-line has changed 705 773 void IOConsole::onlyLastLineChanged() 706 774 { 707 this->moveCursorYAndHome(-1); 708 this->clearCurrentLine(); 709 this->printLogText(*(this->shell_->getNewestLineIterator())); 710 this->moveCursorYAndHome(1); 711 this->moveCursor(this->promptString_.size() + this->shell_->getInput().size(), 0); 712 this->cout_.flush(); 775 int lineHeight = 1 + this->shell_->getNewestLineIterator()->size() / this->terminalWidth_; 776 int newLines = lineHeight - this->lastOutputLineHeight_; 777 this->lastOutputLineHeight_ = lineHeight; 778 if (newLines > 0) 779 this->createNewOutputLines(newLines); 780 // Write text (assuming it is longer than the previous text) 781 assert(newLines >= 0); 782 COORD pos = {0, this->inputLineRow_ - lineHeight}; 783 this->printOutputLine(*(this->shell_->getNewestLineIterator()), pos); 713 784 } 714 785 … … 716 787 void IOConsole::lineAdded() 717 788 { 718 // Move cursor to the beginning of the new (last) output line 719 this->moveCursorYAndHome(0); 720 // Print the new output lines 721 this->printLogText(*(this->shell_->getNewestLineIterator())); 722 // Move cursor down 723 this->moveCursorYAndHome(1); 724 // Print status and input lines 725 this->printInputLine(); 726 this->printStatusLines(); 727 this->cout_.flush(); 789 this->lastOutputLineHeight_ = 1 + this->shell_->getNewestLineIterator()->size() / this->terminalWidth_; 790 if (this->lastOutputLineHeight_ > 0) 791 this->createNewOutputLines(this->lastOutputLineHeight_); 792 // Write the text 793 COORD pos = {0, this->inputLineRow_ - this->lastOutputLineHeight_}; 794 this->printOutputLine(*(this->shell_->getNewestLineIterator()), pos); 728 795 } 729 796 } -
code/branches/presentation2/src/libraries/core/IOConsole.h
r6172 r6177 43 43 #elif defined(ORXONOX_PLATFORM_WINDOWS) 44 44 #define WIN32_LEAN_AND_MEAN 45 #define NOMINMAX 45 46 #include <windows.h> 46 47 #endif … … 60 61 private: 61 62 void setTerminalMode(); 62 static void resetTerminalMode();63 63 void getTerminalSize(); 64 bool willPrintStatusLines();65 64 int extractLogLevel(std::string* text); 66 65 67 void printLogText(const std::string& line);68 void printInputLine();69 66 void printStatusLines(); 70 67 … … 85 82 unsigned int lastTerminalWidth_; 86 83 unsigned int lastTerminalHeight_; 84 const std::string promptString_; 85 86 #ifdef ORXONOX_PLATFORM_UNIX 87 bool willPrintStatusLines(); 88 void printOutputLine(const std::string& line); 89 void printInputLine(); 90 static void resetTerminalMode(); 91 87 92 bool bPrintStatusLine_; 88 93 bool bStatusPrinted_; 89 94 std::vector<unsigned> statusLineWidths_; 90 95 unsigned int statusLineMaxWidth_; 91 const std::string promptString_;92 96 static const unsigned minOutputLines_ = 3; 97 termios* originalTerminalSettings_; 93 98 94 #ifdef ORXONOX_PLATFORM_UNIX95 termios* originalTerminalSettings_;96 99 #elif defined(ORXONOX_PLATFORM_WINDOWS) 100 void resetTerminalMode(); 97 101 void moveCursor(int dx, int dy); 98 void moveCursorYAndHome(int dy); 99 void clearCurrentLine(); 102 void writeText(const std::string& text, const COORD& pos, WORD attributes = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); 103 void createNewOutputLines(unsigned int lines); 104 void printOutputLine(const std::string& line, const COORD& pos); 100 105 101 106 DWORD originalTerminalSettings_; 102 107 HANDLE stdInHandle_; 103 108 HANDLE stdOutHandle_; 109 int inputLineRow_; 110 unsigned int inputLineHeight_; 111 const unsigned int statusLines_; 112 unsigned int lastOutputLineHeight_; 113 uint64_t lastRefreshTime_; 104 114 #endif 105 115 -
code/branches/presentation2/src/libraries/core/input/InputBuffer.cc
r6105 r6177 41 41 this->buffer_ = ""; 42 42 this->cursor_ = 0; 43 this->maxLength_ = 1024; 43 44 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyz \ 44 45 ABCDEFGHIJKLMNOPQRSTUVWXYZ \ … … 59 60 RegisterRootObject(InputBuffer); 60 61 62 this->maxLength_ = 1024; 61 63 this->allowedChars_ = allowedChars; 62 64 this->buffer_ = ""; … … 93 95 } 94 96 97 void InputBuffer::setMaxLength(unsigned int length) 98 { 99 this->maxLength_ = length; 100 if (this->buffer_.size() > length) 101 this->buffer_.resize(length); 102 } 103 95 104 void InputBuffer::set(const std::string& input, bool update) 96 105 { … … 117 126 if (this->charIsAllowed(input)) 118 127 { 128 if (this->buffer_.size() >= this->maxLength_) 129 return; 119 130 this->buffer_.insert(this->cursor_, 1, input); 120 131 ++this->cursor_; -
code/branches/presentation2/src/libraries/core/input/InputBuffer.h
r6105 r6177 82 82 83 83 void setConfigValues(); 84 85 unsigned int getMaxLength() const { return this->maxLength_; } 86 void setMaxLength(unsigned int length); 84 87 85 88 template <class T> … … 175 178 std::list<BaseInputBufferListenerTuple*> listeners_; 176 179 std::string allowedChars_; 180 unsigned int maxLength_; 177 181 unsigned int cursor_; 178 182
Note: See TracChangeset
for help on using the changeset viewer.