mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
Added fullscreen funtion
This commit is contained in:
@@ -34,6 +34,7 @@ bool WindowManager::Initialize(GameConfig& config) {
|
|||||||
"创建渲染器失败: %s", SDL_GetError());
|
"创建渲染器失败: %s", SDL_GetError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// 关键设置:启用像素模式
|
||||||
|
|
||||||
// 设置逻辑呈现模式,实现分辨率自适应[3](@ref)
|
// 设置逻辑呈现模式,实现分辨率自适应[3](@ref)
|
||||||
SDL_SetRenderLogicalPresentation(m_renderer,
|
SDL_SetRenderLogicalPresentation(m_renderer,
|
||||||
@@ -67,3 +68,13 @@ SDL_Renderer* WindowManager::GetRenderer() {
|
|||||||
SDL_Window* WindowManager::GetWindow() {
|
SDL_Window* WindowManager::GetWindow() {
|
||||||
return m_window;
|
return m_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WindowManager::setFullscreen(bool isFullscreen) {
|
||||||
|
if (isFullscreen == m_isFullscreen) {
|
||||||
|
return true; // 状态未改变,直接返回
|
||||||
|
}
|
||||||
|
SDL_SetWindowFullscreen(m_window, isFullscreen);
|
||||||
|
m_isFullscreen = isFullscreen;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ public:
|
|||||||
void Clear();
|
void Clear();
|
||||||
//呈现窗口
|
//呈现窗口
|
||||||
void Present();
|
void Present();
|
||||||
|
bool setFullscreen(bool isFullscreen);
|
||||||
|
|
||||||
SDL_Renderer* GetRenderer();
|
SDL_Renderer* GetRenderer();
|
||||||
SDL_Window* GetWindow();
|
SDL_Window* GetWindow();
|
||||||
@@ -25,5 +25,5 @@ private:
|
|||||||
SDL_Renderer* m_renderer;
|
SDL_Renderer* m_renderer;
|
||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
|
bool m_isFullscreen = false;
|
||||||
};
|
};
|
||||||
@@ -24,6 +24,11 @@ SDL_AppResult InputManager::handleInputEvent(const SDL_Event* event) {
|
|||||||
m_currentInputState.mouseCurrentPosition = {static_cast<float>(event->motion.x),
|
m_currentInputState.mouseCurrentPosition = {static_cast<float>(event->motion.x),
|
||||||
static_cast<float>(event->motion.y)};
|
static_cast<float>(event->motion.y)};
|
||||||
break;
|
break;
|
||||||
|
case SDL_EVENT_KEY_DOWN:
|
||||||
|
if (event->key.key == SDLK_F11) {
|
||||||
|
m_currentInputState.isFullscreen = !m_currentInputState.isFullscreen;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ struct InputState
|
|||||||
std::pair<float, float> mouseCilckOn;
|
std::pair<float, float> mouseCilckOn;
|
||||||
bool leftMouseDown = false;
|
bool leftMouseDown = false;
|
||||||
std::pair<float, float> mouseCurrentPosition;
|
std::pair<float, float> mouseCurrentPosition;
|
||||||
|
bool isFullscreen = false;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user