From c8ab71738a29b3801156e103e45e5ee5a3248603 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Fri, 19 Dec 2025 22:46:21 +0800 Subject: [PATCH] Added fullscreen funtion --- src/core/WindowManager.cpp | 11 +++++++++++ src/core/WindowManager.h | 4 ++-- src/input/InputManager.cpp | 5 +++++ src/input/InputState.h | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/WindowManager.cpp b/src/core/WindowManager.cpp index c665543..bbf2db9 100644 --- a/src/core/WindowManager.cpp +++ b/src/core/WindowManager.cpp @@ -34,6 +34,7 @@ bool WindowManager::Initialize(GameConfig& config) { "创建渲染器失败: %s", SDL_GetError()); return false; } + // 关键设置:启用像素模式 // 设置逻辑呈现模式,实现分辨率自适应[3](@ref) SDL_SetRenderLogicalPresentation(m_renderer, @@ -66,4 +67,14 @@ SDL_Renderer* WindowManager::GetRenderer() { SDL_Window* WindowManager::GetWindow() { return m_window; +} + +bool WindowManager::setFullscreen(bool isFullscreen) { + if (isFullscreen == m_isFullscreen) { + return true; // 状态未改变,直接返回 + } + SDL_SetWindowFullscreen(m_window, isFullscreen); + m_isFullscreen = isFullscreen; + + return true; } \ No newline at end of file diff --git a/src/core/WindowManager.h b/src/core/WindowManager.h index 3323395..01ec2bb 100644 --- a/src/core/WindowManager.h +++ b/src/core/WindowManager.h @@ -14,7 +14,7 @@ public: void Clear(); //呈现窗口 void Present(); - + bool setFullscreen(bool isFullscreen); SDL_Renderer* GetRenderer(); SDL_Window* GetWindow(); @@ -25,5 +25,5 @@ private: SDL_Renderer* m_renderer; int m_width; int m_height; - + bool m_isFullscreen = false; }; \ No newline at end of file diff --git a/src/input/InputManager.cpp b/src/input/InputManager.cpp index 5b197de..98e3f33 100644 --- a/src/input/InputManager.cpp +++ b/src/input/InputManager.cpp @@ -24,6 +24,11 @@ SDL_AppResult InputManager::handleInputEvent(const SDL_Event* event) { m_currentInputState.mouseCurrentPosition = {static_cast(event->motion.x), static_cast(event->motion.y)}; break; + case SDL_EVENT_KEY_DOWN: + if (event->key.key == SDLK_F11) { + m_currentInputState.isFullscreen = !m_currentInputState.isFullscreen; + } + break; } return SDL_APP_CONTINUE; } diff --git a/src/input/InputState.h b/src/input/InputState.h index 84007ff..8c33d7f 100644 --- a/src/input/InputState.h +++ b/src/input/InputState.h @@ -5,4 +5,5 @@ struct InputState std::pair mouseCilckOn; bool leftMouseDown = false; std::pair mouseCurrentPosition; + bool isFullscreen = false; };