https://github.com/libsdl-org/Maelstrom/commit/294ec555c69cada9e62a92612ae25b8f0a387c09
From 294ec555c69cada9e62a92612ae25b8f0a387c09 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 6 Nov 2011 22:19:48 -0500
Subject: [PATCH] Center the viewport if we got a window bigger than we
expected.
---
screenlib/SDL_FrameBuf.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/screenlib/SDL_FrameBuf.cpp b/screenlib/SDL_FrameBuf.cpp
index 74b4e523..fad485f6 100644
--- a/screenlib/SDL_FrameBuf.cpp
+++ b/screenlib/SDL_FrameBuf.cpp
@@ -44,6 +44,8 @@ int
FrameBuf:: Init(int width, int height, Uint32 window_flags, Uint32 render_flags,
SDL_Color *colors, SDL_Surface *icon)
{
+ int w, h;
+
window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags);
if (!window) {
SetError("Couldn't create %dx%d window: %s",
@@ -63,10 +65,16 @@ FrameBuf:: Init(int width, int height, Uint32 window_flags, Uint32 render_flags,
}
/* Set the UI area */
+ SDL_GetWindowSize(window, &w, &h);
+ rect.x = (w - width) / 2;
+ rect.y = (h - height) / 2;
rect.w = width;
rect.h = height;
+ SDL_RenderSetViewport(renderer, &rect);
/* Set the blit clipping rectangle */
+ rect.x = 0;
+ rect.y = 0;
clip = rect;
/* Copy the image colormap */