1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-09-29 11:55:01 +00:00

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.
This commit is contained in:
Peter Evans 2017-12-18 14:32:15 -06:00
parent f3966dc010
commit 05a641c8f6

View File

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