Open Source Tomb Raider Engine
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Console.h 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*!
  2. * \file include/Console.h
  3. * \brief Console 'overlay'
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _CONSOLE_H_
  8. #define _CONSOLE_H_
  9. #include <string>
  10. #include <sstream>
  11. #include <vector>
  12. #include "UI.h"
  13. /*!
  14. * \brief Console 'overlay'
  15. */
  16. class Console : public UI {
  17. public:
  18. Console();
  19. ~Console();
  20. template<typename T>
  21. Console &operator<<(const T t) {
  22. printBuffer << t;
  23. if (printBuffer.str().back() == '\n') {
  24. mHistory.push_back(printBuffer.str().substr(0, printBuffer.str().length() - 1));
  25. #ifdef DEBUG
  26. std::cout << printBuffer.str().substr(0, printBuffer.str().length() - 1) << std::endl;
  27. #endif
  28. printBuffer.str("");
  29. }
  30. return (*this);
  31. }
  32. virtual void moveToTop();
  33. virtual void makeInvisible();
  34. virtual void display();
  35. virtual void handleKeyboard(KeyboardButton key, bool pressed);
  36. virtual void handleText(char *text, bool notFinished);
  37. virtual void handleMouseScroll(int xrel, int yrel);
  38. const static char endl = '\n';
  39. private:
  40. void moveInHistory(bool up);
  41. std::string mInputBuffer;
  42. std::string mPartialInput;
  43. std::vector<std::string> mHistory;
  44. size_t mHistoryPointer;
  45. std::vector<std::string> mCommandHistory;
  46. std::string mUnfinishedInput;
  47. unsigned int mLineOffset;
  48. std::ostringstream printBuffer;
  49. };
  50. Console &getConsole();
  51. #endif