pikaConsoleWindow.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //////////////////////////////////////////
  2. //pikaConsoleWindow.cpp
  3. //Luta Vlad(c) 2022
  4. //https://github.com/meemknight/PikaEngine
  5. //////////////////////////////////////////
  6. #include <pikaConfig.h>
  7. #if !PIKA_SHOULD_REMOVE_EDITOR
  8. #include "pikaConsoleWindow.h"
  9. #include <logs/assert.h>
  10. #include <iostream>
  11. namespace pika
  12. {
  13. void ConsoleWindow::init(pika::pikaImgui::ImGuiIdsManager &idManager)
  14. {
  15. imguiId = idManager.getImguiIds();
  16. }
  17. void ConsoleWindow::update(bool &open)
  18. {
  19. //s += buffer->get;
  20. //*buffer = std::streambuf();
  21. //s += std::string{(std::istreambuf_iterator<char>(buffer)),
  22. // std::istreambuf_iterator<char>()};
  23. ImGui::PushID(imguiId);
  24. if (!ImGui::Begin(ICON_NAME, &open))
  25. {
  26. ImGui::End();
  27. ImGui::PopID();
  28. return;
  29. }
  30. ImGui::BeginChild("##console scrolling", ImVec2(0, 0), false);
  31. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
  32. if (wrapped)
  33. {
  34. if(bufferBeginPos <= BUFFER_SIZE - 1)
  35. ImGui::TextWrapped(&buffer[bufferBeginPos + 1]);
  36. //ImGui::SameLine();
  37. ImGui::TextWrapped(buffer);
  38. }
  39. else
  40. {
  41. ImGui::TextWrapped(buffer);
  42. }
  43. //ImGui::TextUnformatted(s.c_str());
  44. ImGui::PopStyleVar();
  45. if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
  46. ImGui::SetScrollHereY(1.0f);
  47. ImGui::EndChild();
  48. ImGui::End();
  49. ImGui::PopID();
  50. }
  51. void ConsoleWindow::write(const char *c)
  52. {
  53. size_t i = 0;
  54. while (c[i] != 0)
  55. {
  56. buffer[bufferBeginPos] = c[i];
  57. i++;
  58. bufferBeginPos++;
  59. if (bufferBeginPos >= BUFFER_SIZE)
  60. {
  61. bufferBeginPos = 0;
  62. wrapped = true;
  63. }
  64. if (wrapped)
  65. {
  66. buffer[bufferBeginPos] = 0;
  67. }
  68. }
  69. }
  70. };
  71. #else
  72. #include "pikaConsoleWindow.h"
  73. //todo log console in production flag
  74. namespace pika
  75. {
  76. void ConsoleWindow::init(pika::pikaImgui::ImGuiIdsManager &idManager)
  77. {
  78. }
  79. void ConsoleWindow::update(bool &open)
  80. {
  81. }
  82. void ConsoleWindow::write(const char *c)
  83. {
  84. }
  85. };
  86. #endif