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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. bool enter = false;
  31. ImGui::InputText("Command", buffer, bufferLength, ImGuiInputTextFlags_AutoSelectAll, &enter);
  32. if (enter) {
  33. getLog() << "> " << buffer << Log::endl;
  34. int error = Command::command(buffer);
  35. if (error != 0) {
  36. getLog() << "Error code: " << error << Log::endl;
  37. }
  38. buffer[0] = '\0';
  39. scrollToBottom = true;
  40. }
  41. }
  42. ImGui::End();
  43. }