feat: Add window class

This commit is contained in:
2026-10-17 16:25:09 +02:00
parent 67c685a158
commit 89a168f76d
9 changed files with 513 additions and 36 deletions
+1
View File
@@ -37,6 +37,7 @@ private:
// LightkeeperDebugUi.cpp
void updateDebugUi();
void drawDebugMenuBar();
void drawWindowMenu();
void drawTestWindow();
void spawnBall();
void saveCurrentScene();
+5
View File
@@ -68,6 +68,11 @@ void LightKeeper::customUpdate(float dt)
{
camera.Update(dt);
}
if (InputManager::GetInstance().WasKeyPressed(SDL_SCANCODE_F11))
{
window.ToggleFullscreen();
}
SceneManager::GetInstance().Update(dt);
SceneManager::GetInstance().LateUpdate(dt);
+72
View File
@@ -158,9 +158,81 @@ void LightKeeper::drawDebugMenuBar()
ImGui::EndMenu();
}
drawWindowMenu();
ImGui::EndMainMenuBar();
}
void LightKeeper::drawWindowMenu()
{
if (!ImGui::BeginMenu("Window")) {
return;
}
const WindowMode mode = window.GetMode();
const bool fullscreen = window.IsFullscreen();
const bool maximized = window.IsMaximized();
if (ImGui::MenuItem("Fullscreen", "F11", fullscreen)) {
window.ToggleFullscreen();
}
if (ImGui::BeginMenu("Mode")) {
if (ImGui::MenuItem("Windowed", nullptr, mode == WindowMode::Windowed)) {
window.SetMode(WindowMode::Windowed);
}
if (ImGui::MenuItem("Borderless Fullscreen", nullptr, mode == WindowMode::BorderlessFullscreen)) {
window.SetMode(WindowMode::BorderlessFullscreen);
}
if (ImGui::MenuItem("Exclusive Fullscreen", nullptr, mode == WindowMode::Fullscreen)) {
window.SetMode(WindowMode::Fullscreen);
}
ImGui::EndMenu();
}
ImGui::Separator();
if (ImGui::MenuItem(maximized ? "Restore" : "Maximize", nullptr, false, !fullscreen)) {
window.ToggleMaximized();
}
if (ImGui::MenuItem("Minimize", nullptr, false, !fullscreen)) {
window.Minimize();
}
if (ImGui::MenuItem("Center", nullptr, false, !fullscreen && !maximized)) {
window.Center();
}
if (ImGui::BeginMenu("Size", !fullscreen)) {
const glm::ivec2 sizes[] = {glm::ivec2{1280, 720}, glm::ivec2{1600, 900}, glm::ivec2{1920, 1080}};
for (const glm::ivec2& size : sizes) {
const std::string label = std::to_string(size.x) + " x " + std::to_string(size.y);
if (ImGui::MenuItem(label.c_str(), nullptr, window.GetSize() == size)) {
if (maximized) {
window.Restore();
}
window.SetSize(size);
window.Center();
}
}
ImGui::EndMenu();
}
ImGui::Separator();
if (bool resizable = window.IsResizable(); ImGui::MenuItem("Resizable", nullptr, &resizable, !fullscreen)) {
window.SetResizable(resizable);
}
if (bool bordered = window.IsBordered(); ImGui::MenuItem("Bordered", nullptr, &bordered, !fullscreen)) {
window.SetBordered(bordered);
}
ImGui::Separator();
const glm::ivec2 drawableSize = window.GetDrawableSize();
ImGui::TextDisabled("Drawable: %d x %d", drawableSize.x, drawableSize.y);
ImGui::EndMenu();
}
void LightKeeper::saveCurrentScene()
{
try {
@@ -43,8 +43,7 @@ void InteractableButton::Interact(GameObject& interactor)
void InteractableButton::ApplyColor()
{
const auto* meshRenderer = GetGameObject()->GetComponent<MeshRendererComponent>();
if (meshRenderer == nullptr || meshRenderer->GetMaterialID() == NULL_MATERIAL_ID ||
!GameState::GetInstance().HasRenderer()) {
if (meshRenderer == nullptr || meshRenderer->GetMaterialID() == NULL_MATERIAL_ID || !GameState::GetInstance().HasRenderer()) {
return;
}