mirror of
https://github.com/slendidev/lunar.git
synced 2025-12-16 03:59:52 +02:00
@@ -33,6 +33,8 @@ Application::Application()
|
||||
|
||||
m_renderer = std::make_unique<VulkanRenderer>(m_window, m_logger);
|
||||
|
||||
mouse_captured(true);
|
||||
|
||||
m_logger.info("App init done!");
|
||||
}
|
||||
|
||||
@@ -71,6 +73,11 @@ auto Application::run() -> void
|
||||
SDL_GetWindowSize(m_window, &width, &height);
|
||||
m_renderer->resize(static_cast<uint32_t>(width),
|
||||
static_cast<uint32_t>(height));
|
||||
} else if (e.type == SDL_EVENT_KEY_DOWN && e.key.repeat == false) {
|
||||
if (e.key.key == SDLK_F11 && e.key.mod & SDL_KMOD_LCTRL) {
|
||||
mouse_captured(!mouse_captured());
|
||||
m_show_imgui = mouse_captured();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui_ImplSDL3_ProcessEvent(&e);
|
||||
@@ -81,18 +88,20 @@ auto Application::run() -> void
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::ShowDemoWindow();
|
||||
if (m_show_imgui) {
|
||||
ImGui::ShowDemoWindow();
|
||||
|
||||
ImGui::SetNextWindowSize({ 100, 50 });
|
||||
ImGui::SetNextWindowPos({ 0, 0 });
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 { 0, 0, 0, 0.5f });
|
||||
if (ImGui::Begin("Debug Info", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize)) {
|
||||
defer(ImGui::End());
|
||||
ImGui::SetNextWindowSize({ 100, 50 });
|
||||
ImGui::SetNextWindowPos({ 0, 0 });
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 { 0, 0, 0, 0.5f });
|
||||
if (ImGui::Begin("Debug Info", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize)) {
|
||||
defer(ImGui::End());
|
||||
|
||||
ImGui::Text("%s", std::format("FPS: {:.2f}", fps).c_str());
|
||||
ImGui::Text("%s", std::format("FPS: {:.2f}", fps).c_str());
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
@@ -100,4 +109,11 @@ auto Application::run() -> void
|
||||
}
|
||||
}
|
||||
|
||||
auto Application::mouse_captured(bool new_state) -> void
|
||||
{
|
||||
SDL_CaptureMouse(new_state);
|
||||
|
||||
m_mouse_captured = new_state;
|
||||
}
|
||||
|
||||
} // namespace Lunar
|
||||
|
||||
@@ -17,6 +17,9 @@ struct Application {
|
||||
~Application();
|
||||
|
||||
auto run() -> void;
|
||||
auto mouse_captured(bool new_state) -> void;
|
||||
auto mouse_captured() const -> bool { return m_mouse_captured; }
|
||||
auto toggle_mouse_captured() -> void { mouse_captured(!m_mouse_captured); }
|
||||
|
||||
private:
|
||||
SDL_Window *m_window { nullptr };
|
||||
@@ -24,6 +27,8 @@ private:
|
||||
std::unique_ptr<VulkanRenderer> m_renderer;
|
||||
|
||||
bool m_running { true };
|
||||
bool m_mouse_captured { false };
|
||||
bool m_show_imgui { false };
|
||||
};
|
||||
|
||||
} // namespace Lunar
|
||||
|
||||
Reference in New Issue
Block a user