Added fullscreen funtion

This commit is contained in:
2025-12-19 22:46:21 +08:00
parent 551999c142
commit c8ab71738a
4 changed files with 19 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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;
};

View File

@@ -24,6 +24,11 @@ SDL_AppResult InputManager::handleInputEvent(const SDL_Event* event) {
m_currentInputState.mouseCurrentPosition = {static_cast<float>(event->motion.x),
static_cast<float>(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;
}

View File

@@ -5,4 +5,5 @@ struct InputState
std::pair<float, float> mouseCilckOn;
bool leftMouseDown = false;
std::pair<float, float> mouseCurrentPosition;
bool isFullscreen = false;
};