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.cpp 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*!
  2. * \file src/Console.cpp
  3. * \brief Console class
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "Log.h"
  9. #include "UI.h"
  10. #include "commands/Command.h"
  11. #include "Console.h"
  12. char Console::buffer[bufferLength] = "";
  13. bool Console::scrollToBottom = false;
  14. bool Console::focusInput = false;
  15. unsigned long Console::lastLogLength = 0;
  16. void Console::display() {
  17. if (ImGui::Begin("Console", NULL, ImVec2(600, 400), -1.0f)) {
  18. if (lastLogLength != getLog().size()) {
  19. lastLogLength = getLog().size();
  20. scrollToBottom = true;
  21. }
  22. ImGui::BeginChild("ConsoleText", ImVec2(ImGui::GetWindowWidth(), ImGui::GetWindowSize().y - 70));
  23. for (unsigned long i = 0; i < getLog().size(); i++) {
  24. ImGui::Text("%s", getLog().get(i).c_str());
  25. }
  26. if (scrollToBottom) {
  27. ImGui::SetScrollPosHere();
  28. scrollToBottom = false;
  29. }
  30. ImGui::EndChild();
  31. if (focusInput) {
  32. ImGui::SetKeyboardFocusHere();
  33. focusInput = false;
  34. }
  35. if (ImGui::InputText("Command", buffer, bufferLength,
  36. ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue)) {
  37. getLog() << "> " << buffer << Log::endl;
  38. int error = Command::command(buffer);
  39. if (error != 0) {
  40. getLog() << "Error code: " << error << Log::endl;
  41. }
  42. buffer[0] = '\0';
  43. scrollToBottom = true;
  44. focusInput = true;
  45. }
  46. }
  47. ImGui::End();
  48. }