From 27f91ec00fa7ff1bb34ae94fa8863649a9e74bd5 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Wed, 27 Dec 2017 16:47:26 -0600 Subject: [PATCH] Use vm_area with bitfont_offset This should further standardize on vm_area. --- include/vm_bitfont.h | 2 +- src/vm_bitfont.c | 27 ++++++++++++++------------- tests/vm_bitfont.c | 9 ++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/vm_bitfont.h b/include/vm_bitfont.h index 507770c..6c1975c 100644 --- a/include/vm_bitfont.h +++ b/include/vm_bitfont.h @@ -18,6 +18,6 @@ typedef struct { extern int vm_bitfont_render(vm_bitfont *, vm_screen *, vm_area *, char); extern vm_bitfont *vm_bitfont_create(vm_screen *, const char *, int, int, char); extern void vm_bitfont_free(vm_bitfont *); -extern void vm_bitfont_offset(vm_bitfont *, char, int *, int *); +extern void vm_bitfont_offset(vm_bitfont *, char, vm_area *); #endif diff --git a/src/vm_bitfont.c b/src/vm_bitfont.c index 7e2a188..5ad9c40 100644 --- a/src/vm_bitfont.c +++ b/src/vm_bitfont.c @@ -67,13 +67,13 @@ vm_bitfont_free(vm_bitfont *font) * value. */ void -vm_bitfont_offset(vm_bitfont *font, char ch, int *xcoord, int *ycoord) +vm_bitfont_offset(vm_bitfont *font, char ch, vm_area *area) { int row = (ch & 0xf0) >> 4; int col = ch & 0x0f; - *xcoord = col * font->width; - *ycoord = row * font->height; + area->xoff = col * font->width; + area->yoff = row * font->height; } /* @@ -86,8 +86,7 @@ vm_bitfont_render(vm_bitfont *font, vm_area *dest, char ch) { - SDL_Rect src_rect; - SDL_Rect dest_rect; + vm_area src; // Our bitmap font may not be able to support all 256 possible // values that a character can hold; the cmask will limit us to @@ -96,17 +95,19 @@ vm_bitfont_render(vm_bitfont *font, // The width and height of the glyph are as indicated by the font // struct - src_rect.w = font->width; - src_rect.h = font->height; - - // Bring the destination attributes into the SDL_Rect we need to - // pass into SDL_RenderCopy(). - SET_SDL_RECT(dest_rect, *dest); + src.width = font->width; + src.height = font->height; // Get the spot in the bitmap where the glyph is found - vm_bitfont_offset(font, ch, &src_rect.x, &src_rect.y); + vm_bitfont_offset(font, ch, &src); - log_critical("src.x = %d, src.y = %d", src_rect.x, src_rect.y); + log_critical("src.xoff = %d, src.yoff = %d", src.xoff, src.yoff); + + // Bring the destination attributes into the SDL_Rect we need to + // pass into SDL_RenderCopy(). Also bring in the src attributes + // we've built earlier. + MAKE_SDL_RECT(dest_rect, *dest); + MAKE_SDL_RECT(src_rect, src); if (SDL_RenderCopy(screen->render, font->texture, &src_rect, &dest_rect) < 0) { log_critical("Failed to render glyph: %s", SDL_GetError()); diff --git a/tests/vm_bitfont.c b/tests/vm_bitfont.c index bf3632b..6945a42 100644 --- a/tests/vm_bitfont.c +++ b/tests/vm_bitfont.c @@ -40,13 +40,12 @@ Test(vm_bitfont, create) Test(vm_bitfont, offset) { char ch = 'p'; - int x = 0; - int y = 0; + vm_area area; - vm_bitfont_offset(font, ch, &x, &y); + vm_bitfont_offset(font, ch, &area); - cr_assert_eq(x, (ch & 0x0f) * font->width); - cr_assert_eq(y, (ch >> 4) * font->height); + cr_assert_eq(area.xoff, (ch & 0x0f) * font->width); + cr_assert_eq(area.yoff, (ch >> 4) * font->height); } /*