Test text rendering APIs take floating point coordinates

This commit is contained in:
Sam Lantinga 2023-01-04 16:22:40 -08:00
parent 0901657278
commit 0bbf6cc379
9 changed files with 74 additions and 73 deletions

View file

@ -3126,7 +3126,7 @@ struct SDLTest_CharTextureCache
*/
static struct SDLTest_CharTextureCache *SDLTest_CharTextureCacheList;
int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c)
int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c)
{
const Uint32 charWidth = FONT_CHARACTER_SIZE;
const Uint32 charHeight = FONT_CHARACTER_SIZE;
@ -3155,8 +3155,8 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c)
/*
* Setup destination rectangle
*/
drect.x = (float)x;
drect.y = (float)y;
drect.x = x;
drect.y = y;
drect.w = (float)charWidth;
drect.h = (float)charHeight;
@ -3328,12 +3328,12 @@ static Uint32 UTF8_getch(const char *src, size_t srclen, int *inc)
#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
int SDLTest_DrawString(SDL_Renderer *renderer, int x, int y, const char *s)
int SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s)
{
const Uint32 charWidth = FONT_CHARACTER_SIZE;
int result = 0;
int curx = x;
int cury = y;
float curx = x;
float cury = y;
size_t len = SDL_strlen(s);
while (len > 0 && !result) {
@ -3350,7 +3350,7 @@ int SDLTest_DrawString(SDL_Renderer *renderer, int x, int y, const char *s)
return result;
}
SDLTest_TextWindow *SDLTest_TextWindowCreate(int x, int y, int w, int h)
SDLTest_TextWindow *SDLTest_TextWindowCreate(float x, float y, float w, float h)
{
SDLTest_TextWindow *textwin = (SDLTest_TextWindow *)SDL_malloc(sizeof(*textwin));
@ -3363,7 +3363,7 @@ SDLTest_TextWindow *SDLTest_TextWindowCreate(int x, int y, int w, int h)
textwin->rect.w = w;
textwin->rect.h = h;
textwin->current = 0;
textwin->numlines = (h / FONT_LINE_HEIGHT);
textwin->numlines = (int)SDL_ceilf(h / FONT_LINE_HEIGHT);
textwin->lines = (char **)SDL_calloc(textwin->numlines, sizeof(*textwin->lines));
if (!textwin->lines) {
SDL_free(textwin);
@ -3374,7 +3374,8 @@ SDLTest_TextWindow *SDLTest_TextWindowCreate(int x, int y, int w, int h)
void SDLTest_TextWindowDisplay(SDLTest_TextWindow *textwin, SDL_Renderer *renderer)
{
int i, y;
int i;
float y;
for (y = textwin->rect.y, i = 0; i < textwin->numlines; ++i, y += FONT_LINE_HEIGHT) {
if (textwin->lines[i]) {