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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. unsigned long Console::lastLogLength = 0;
  15. void Console::display() {
  16. if (ImGui::Begin("Console", NULL, ImVec2(600, 400), -1.0f)) {
  17. if (lastLogLength != getLog().size()) {
  18. lastLogLength = getLog().size();
  19. scrollToBottom = true;
  20. }
  21. ImGui::BeginChild("ConsoleText", ImVec2(ImGui::GetWindowWidth(), ImGui::GetWindowSize().y - 70));
  22. for (unsigned long i = 0; i < getLog().size(); i++) {
  23. ImGui::Text("%s", getLog().get(i).c_str());
  24. }
  25. if (scrollToBottom) {
  26. ImGui::SetScrollPosHere();
  27. scrollToBottom = false;
  28. }
  29. ImGui::EndChild();
  30. if (ImGui::InputText("Command", buffer, bufferLength,
  31. ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue)) {
  32. getLog() << "> " << buffer << Log::endl;
  33. int error = Command::command(buffer);
  34. if (error != 0) {
  35. getLog() << "Error code: " << error << Log::endl;
  36. }
  37. buffer[0] = '\0';
  38. scrollToBottom = true;
  39. }
  40. }
  41. ImGui::End();
  42. }