Skip to content

Commit 88650df

Browse files
committed
Allow window resizing
Support window resizing by automatically updating the saved width/height of the window and rendering with that size without the need of reallocating the internal texture. Resolze #73
1 parent e33382f commit 88650df

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/syscall_sdl.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
141141
}
142142
window = SDL_CreateWindow("rv32emu", SDL_WINDOWPOS_UNDEFINED,
143143
SDL_WINDOWPOS_UNDEFINED, width, height,
144-
0 /* flags */);
144+
SDL_WINDOW_RESIZABLE /* flags */);
145145
if (!window) {
146146
fprintf(stderr, "Window could not be created! SDL_Error: %s\n",
147147
SDL_GetError());
@@ -231,7 +231,10 @@ void syscall_draw_frame(struct riscv_t *rv)
231231
memory_read(s->mem, pixels_ptr, screen, width * height * 4);
232232
SDL_UnlockTexture(texture);
233233

234-
SDL_RenderCopy(renderer, texture, NULL, &(SDL_Rect){0, 0, width, height});
234+
int actual_width, actual_height;
235+
SDL_GetWindowSize(window, &actual_width, &actual_height);
236+
SDL_RenderCopy(renderer, texture, NULL,
237+
&(SDL_Rect){0, 0, actual_width, actual_height});
235238
SDL_RenderPresent(renderer);
236239
}
237240

0 commit comments

Comments
 (0)