resizeable window

This commit is contained in:
Logan McNaughton
2023-10-12 12:21:58 -06:00
parent 0224d75bea
commit 6fa2292fe4
2 changed files with 34 additions and 1 deletions
+33 -1
View File
@@ -201,6 +201,38 @@ void set_sdl_window(void *_window)
SDL_SetEventFilter(sdl_event_filter, nullptr);
}
static void calculate_viewport(float *x, float *y, float *width, float *height)
{
bool window_widescreen = false;
int32_t display_width = (window_widescreen ? 854 : 640);
int32_t display_height = 480;
int w, h;
SDL_GetWindowSize(window, &w, &h);
*width = w;
*height = h;
*x = 0;
*y = 0;
int32_t hw = display_height * *width;
int32_t wh = display_width * *height;
// add letterboxes or pillarboxes if the window has a different aspect ratio
// than the current display mode
if (hw > wh)
{
int32_t w_max = wh / display_height;
*x += (*width - w_max) / 2;
*width = w_max;
}
else if (hw < wh)
{
int32_t h_max = hw / display_width;
*y += (*height - h_max) / 2;
*height = h_max;
}
}
static void render_frame(Vulkan::Device &device)
{
RDP::ScanoutOptions options = {};
@@ -225,7 +257,7 @@ static void render_frame(Vulkan::Device &device)
cmd->begin_render_pass(rp);
VkViewport vp = cmd->get_viewport();
// Adjust the viewport here for aspect ratio correction.
calculate_viewport(&vp.x, &vp.y, &vp.width, &vp.height);
cmd->set_program(program);
+1
View File
@@ -25,6 +25,7 @@ impl Ui {
.window("gopher64", 640, 480)
.position_centered()
.vulkan()
.resizable()
.build()
.unwrap();
Ui {