UI.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "UI.h"
  2. #include "AppGLFW.h"
  3. #include "Config.h"
  4. #include "FileSystem.h"
  5. #include "Window.h"
  6. #include "imgui_impl_glfw.h"
  7. namespace gameplay
  8. {
  9. struct UI::Impl
  10. {
  11. };
  12. UI::UI()
  13. {
  14. _impl = std::make_unique<UI::Impl>();
  15. }
  16. UI::~UI()
  17. {
  18. }
  19. void UI::startup()
  20. {
  21. // setup imgui for ui
  22. IMGUI_CHECKVERSION();
  23. ImGui::CreateContext();
  24. ImGuiIO& io = ImGui::GetIO();
  25. io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
  26. io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
  27. io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
  28. io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
  29. //io.ConfigViewportsNoAutoMerge = true;
  30. //io.ConfigViewportsNoTaskBarIcon = true;
  31. ImGui::StyleColorsDark();
  32. ImGuiStyle& style = ImGui::GetStyle();
  33. if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
  34. {
  35. style.WindowRounding = 0.0f;
  36. style.Colors[ImGuiCol_WindowBg].w = 1.0f;
  37. }
  38. auto window = App::get_app()->get_window();
  39. ImGui_ImplGlfw_InitForVulkan(window->handle->glfwWindow, true);
  40. // load the system fonts
  41. auto config = App::get_app()->get_config();
  42. std::string defaultFont = config->get_string("ui.defaultFont", "");
  43. if (defaultFont.size() > 0 && App::get_app()->resolve_resource_path(defaultFont))
  44. {
  45. auto fs = App::get_app()->get_file_system();
  46. if (fs->exists(defaultFont.c_str()))
  47. {
  48. io.Fonts->AddFontFromFileTTF(defaultFont.c_str(), 16.0f);
  49. }
  50. }
  51. }
  52. void UI::shutdown()
  53. {
  54. ImGui_ImplGlfw_Shutdown();
  55. ImGui::DestroyContext();
  56. }
  57. void UI::update()
  58. {
  59. ImGui_ImplGlfw_NewFrame();
  60. ImGui::NewFrame();
  61. // sample content directly with imgui for now...
  62. static bool show_demo_window = true;
  63. if (show_demo_window)
  64. {
  65. ImGui::ShowDemoWindow(&show_demo_window);
  66. }
  67. ImGui::Render();
  68. }
  69. }