UI.cpp 1.8 KB

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