Skip to content

Commit d2285bf

Browse files
authored
Merge pull request #84 from alanjian85/master
SDL: Allow window resizing
2 parents 78eb2a0 + 4f8597c commit d2285bf

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

docs/syscall.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ These system calls are solely for the convenience of accessing the [SDL library]
9898

9999
If a window does not already exist, one will be created with the specified `width` and `height`. The `screen` buffer will replace the content of the framebuffer, passing a different `width` or `height` compared to the size of the window is undefined behavior. This system call additionally polls events from the SDL library, and, if necessary, update the internal input specific event queue.
100100

101+
The width and height are merely the virutal dimensions of the screen; they are unrelated to the window's real size. The system call would deal with resizing events internally when they occurred.
102+
101103
### `setup_queue` - Setup input system's dedicated event and submission queue
102104

103105
**system call number**: `0xC0DE`

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);
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)