From 05a641c8f60073543da40a279b4e559fe8d2f8b7 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Mon, 18 Dec 2017 14:32:15 -0600 Subject: [PATCH] Use SDL's render logical size feature This allows us to work with the pure x/y coordinate system we set when creating the vm_screen. SDL will take care of the translation of those coordinates to whatever the window size is. --- src/vm_screen.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/vm_screen.c b/src/vm_screen.c index c9a1c29..db792ee 100644 --- a/src/vm_screen.c +++ b/src/vm_screen.c @@ -69,6 +69,13 @@ vm_screen_add_window(vm_screen *screen) return ERR_GFXINIT; } + // We plan to draw onto a surface that is xcoords x ycoords in area, + // regardless of the actual size of the window. + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + SDL_RenderSetLogicalSize(screen->render, + screen->xcoords, + screen->ycoords); + vm_screen_set_color(screen, 0, 0, 0, 0); SDL_RenderClear(screen->render); @@ -129,13 +136,12 @@ vm_screen_draw_rect(vm_screen *screen, int xsize, int ysize) { - // We need to scale the position and sizes, since the presumption is - // that we are plotting based on the literal x and y coordinates in - // the screen. - screen->rect.x = xpos * screen->scale; - screen->rect.y = ypos * screen->scale; - screen->rect.w = xsize * screen->scale; - screen->rect.h = ysize * screen->scale; + // The renderer will take care of translating the positions and + // sizes into whatever the window is really at. + screen->rect.x = xpos; + screen->rect.y = ypos; + screen->rect.w = xsize; + screen->rect.h = ysize; SDL_RenderFillRect(screen->render, &screen->rect); }