Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Console.h 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /*!
  13. * \brief Console 'overlay'
  14. */
  15. class Console {
  16. public:
  17. /*!
  18. * \brief Constructs an object of Console
  19. */
  20. Console();
  21. void setVisible(bool visible);
  22. bool isVisible();
  23. template<typename T>
  24. Console &operator<<(const T t) {
  25. printBuffer << t;
  26. if (printBuffer.str().back() == '\n') {
  27. mHistory.push_back(printBuffer.str().substr(0, printBuffer.str().length() - 1));
  28. #ifdef DEBUG
  29. std::cout << printBuffer.str().substr(0, printBuffer.str().length() - 1) << std::endl;
  30. #endif
  31. printBuffer.str("");
  32. }
  33. return (*this);
  34. }
  35. void display();
  36. void handleKeyboard(KeyboardButton key, bool pressed);
  37. void handleText(char *text, bool notFinished);
  38. void handleMouseScroll(int xrel, int yrel);
  39. const static char endl = '\n';
  40. private:
  41. void moveInHistory(bool up);
  42. bool mVisible;
  43. std::string mInputBuffer;
  44. std::string mPartialInput;
  45. std::vector<std::string> mHistory;
  46. size_t mHistoryPointer;
  47. std::vector<std::string> mCommandHistory;
  48. std::string mUnfinishedInput;
  49. unsigned int mLineOffset;
  50. std::ostringstream printBuffer;
  51. };
  52. Console &getConsole();
  53. #endif