some problems fixed
This commit is contained in:
@ -130,6 +130,8 @@ void RenderManager::setViewport(int x, int y, int width, int height) {
|
||||
|
||||
SDL_Rect viewport = { x, y, width, height };
|
||||
SDL_SetRenderViewport(m_renderer, &viewport);
|
||||
// Keep cached logical viewport in sync if this matches our computed logical scale
|
||||
m_logicalVP = viewport;
|
||||
}
|
||||
|
||||
void RenderManager::setScale(float scaleX, float scaleY) {
|
||||
@ -147,6 +149,7 @@ void RenderManager::resetViewport() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset to full window viewport and recompute logical scale/viewport
|
||||
SDL_SetRenderViewport(m_renderer, nullptr);
|
||||
updateLogicalScale();
|
||||
}
|
||||
@ -281,7 +284,15 @@ void RenderManager::updateLogicalScale() {
|
||||
}
|
||||
|
||||
setScale(scale, scale);
|
||||
// Compute centered logical viewport that preserves aspect ratio and is centered in window
|
||||
int vpW = static_cast<int>(m_logicalWidth * scale);
|
||||
int vpH = static_cast<int>(m_logicalHeight * scale);
|
||||
int vpX = (m_windowWidth - vpW) / 2;
|
||||
int vpY = (m_windowHeight - vpH) / 2;
|
||||
SDL_Rect vp{ vpX, vpY, vpW, vpH };
|
||||
SDL_SetRenderViewport(m_renderer, &vp);
|
||||
|
||||
// Set viewport to fill the entire window
|
||||
setViewport(0, 0, m_windowWidth, m_windowHeight);
|
||||
// Cache logical viewport and scale for callers
|
||||
m_logicalVP = vp;
|
||||
m_logicalScale = scale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user