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

@ -147,7 +147,7 @@ SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags);
* *
* \returns the number of arguments processed (i.e. 1 for --fullscreen, 2 for --video [videodriver], or -1 on error. * \returns the number of arguments processed (i.e. 1 for --fullscreen, 2 for --video [videodriver], or -1 on error.
*/ */
int SDLTest_CommonArg(SDLTest_CommonState * state, int index); int SDLTest_CommonArg(SDLTest_CommonState *state, int index);
/** /**
@ -162,7 +162,7 @@ int SDLTest_CommonArg(SDLTest_CommonState * state, int index);
* \param argv0 argv[0], as passed to main/SDL_main. * \param argv0 argv[0], as passed to main/SDL_main.
* \param options an array of strings for application specific options. The last element of the array should be NULL. * \param options an array of strings for application specific options. The last element of the array should be NULL.
*/ */
void SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, const char **options); void SDLTest_CommonLogUsage(SDLTest_CommonState *state, const char *argv0, const char **options);
/** /**
* \brief Returns common usage information * \brief Returns common usage information
@ -175,7 +175,7 @@ void SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, cons
* \param state The common state describing the test window to create. * \param state The common state describing the test window to create.
* \returns a string with usage information * \returns a string with usage information
*/ */
const char *SDLTest_CommonUsage(SDLTest_CommonState * state); const char *SDLTest_CommonUsage(SDLTest_CommonState *state);
/** /**
* \brief Open test window. * \brief Open test window.
@ -184,7 +184,7 @@ const char *SDLTest_CommonUsage(SDLTest_CommonState * state);
* *
* \returns SDL_TRUE if initialization succeeded, false otherwise * \returns SDL_TRUE if initialization succeeded, false otherwise
*/ */
SDL_bool SDLTest_CommonInit(SDLTest_CommonState * state); SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state);
/** /**
* \brief Easy argument handling when test app doesn't need any custom args. * \brief Easy argument handling when test app doesn't need any custom args.
@ -195,7 +195,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState * state);
* *
* \returns SDL_FALSE if app should quit, true otherwise. * \returns SDL_FALSE if app should quit, true otherwise.
*/ */
SDL_bool SDLTest_CommonDefaultArgs(SDLTest_CommonState * state, const int argc, char **argv); SDL_bool SDLTest_CommonDefaultArgs(SDLTest_CommonState *state, const int argc, char **argv);
/** /**
* \brief Common event handler for test windows. * \brief Common event handler for test windows.
@ -205,7 +205,7 @@ SDL_bool SDLTest_CommonDefaultArgs(SDLTest_CommonState * state, const int argc,
* \param done Flag indicating we are done. * \param done Flag indicating we are done.
* *
*/ */
void SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done); void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done);
/** /**
* \brief Close test window. * \brief Close test window.
@ -213,7 +213,7 @@ void SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *do
* \param state The common state used to create test window. * \param state The common state used to create test window.
* *
*/ */
void SDLTest_CommonQuit(SDLTest_CommonState * state); void SDLTest_CommonQuit(SDLTest_CommonState *state);
/** /**
* \brief Draws various window information (position, size, etc.) to the renderer. * \brief Draws various window information (position, size, etc.) to the renderer.
@ -223,7 +223,7 @@ void SDLTest_CommonQuit(SDLTest_CommonState * state);
* \param usedHeight Returns the height used, so the caller can draw more below. * \param usedHeight Returns the height used, so the caller can draw more below.
* *
*/ */
void SDLTest_CommonDrawWindowInfo(SDL_Renderer * renderer, SDL_Window * window, int * usedHeight); void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, float *usedHeight);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -79,7 +79,7 @@ extern "C" {
* \returns 0 for OK, -1 on error * \returns 0 for OK, -1 on error
* *
*/ */
int SDLTest_Crc32Init(SDLTest_Crc32Context * crcContext); int SDLTest_Crc32Init(SDLTest_Crc32Context *crcContext);
/** /**
@ -93,12 +93,12 @@ extern "C" {
* \returns 0 for OK, -1 on error * \returns 0 for OK, -1 on error
* *
*/ */
int SDLTest_Crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32); int SDLTest_Crc32Calc(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
/* Same routine broken down into three steps */ /* Same routine broken down into three steps */
int SDLTest_Crc32CalcStart(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32); int SDLTest_Crc32CalcStart(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32);
int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32); int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32);
int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32); int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
/** /**
@ -110,7 +110,7 @@ int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf,
* *
*/ */
int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext); int SDLTest_Crc32Done(SDLTest_Crc32Context *crcContext);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */

View file

@ -51,7 +51,7 @@ extern "C" {
* *
* \returns 0 on success, -1 on failure. * \returns 0 on success, -1 on failure.
*/ */
int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c); int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c);
/** /**
* \brief Draw a UTF-8 string in the currently set font. * \brief Draw a UTF-8 string in the currently set font.
@ -65,14 +65,14 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c);
* *
* \returns 0 on success, -1 on failure. * \returns 0 on success, -1 on failure.
*/ */
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);
/** /**
* \brief Data used for multi-line text output * \brief Data used for multi-line text output
*/ */
typedef struct SDLTest_TextWindow typedef struct SDLTest_TextWindow
{ {
SDL_Rect rect; SDL_FRect rect;
int current; int current;
int numlines; int numlines;
char **lines; char **lines;
@ -90,7 +90,7 @@ typedef struct SDLTest_TextWindow
* *
* \since This function is available since SDL 2.24.0 * \since This function is available since SDL 2.24.0
*/ */
SDLTest_TextWindow *SDLTest_TextWindowCreate(int x, int y, int w, int h); SDLTest_TextWindow *SDLTest_TextWindowCreate(float x, float y, float w, float h);
/** /**
* \brief Display a multi-line text output window * \brief Display a multi-line text output window

View file

@ -338,7 +338,7 @@ Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max);
* *
* \returns a newly allocated random string; or NULL if length was invalid or string could not be allocated. * \returns a newly allocated random string; or NULL if length was invalid or string could not be allocated.
*/ */
char * SDLTest_RandomAsciiString(void); char *SDLTest_RandomAsciiString(void);
/** /**
@ -352,7 +352,7 @@ char * SDLTest_RandomAsciiString(void);
* *
* \returns a newly allocated random string; or NULL if maxLength was invalid or string could not be allocated. * \returns a newly allocated random string; or NULL if maxLength was invalid or string could not be allocated.
*/ */
char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength); char *SDLTest_RandomAsciiStringWithMaximumLength(int maxLength);
/** /**
@ -366,7 +366,7 @@ char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength);
* *
* \returns a newly allocated random string; or NULL if size was invalid or string could not be allocated. * \returns a newly allocated random string; or NULL if size was invalid or string could not be allocated.
*/ */
char * SDLTest_RandomAsciiStringOfSize(int size); char *SDLTest_RandomAsciiStringOfSize(int size);
/** /**
* Get the invocation count for the fuzzer since last ...FuzzerInit. * Get the invocation count for the fuzzer since last ...FuzzerInit.

View file

@ -86,7 +86,7 @@ extern "C" {
* mdContext. Call before each new use of the context - * mdContext. Call before each new use of the context -
* all fields are set to zero. * all fields are set to zero.
*/ */
void SDLTest_Md5Init(SDLTest_Md5Context * mdContext); void SDLTest_Md5Init(SDLTest_Md5Context *mdContext);
/** /**
@ -101,7 +101,7 @@ extern "C" {
* in the message whose digest is being computed. * in the message whose digest is being computed.
*/ */
void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf, void SDLTest_Md5Update(SDLTest_Md5Context *mdContext, unsigned char *inBuf,
unsigned int inLen); unsigned int inLen);
@ -115,7 +115,7 @@ extern "C" {
* Always call before using the digest[] variable. * Always call before using the digest[] variable.
*/ */
void SDLTest_Md5Final(SDLTest_Md5Context * mdContext); void SDLTest_Md5Final(SDLTest_Md5Context *mdContext);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */

View file

@ -78,8 +78,7 @@ extern "C" {
* \param ci integer that defines the random sequence * \param ci integer that defines the random sequence
* *
*/ */
void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi, void SDLTest_RandomInit(SDLTest_RandomContext *rndContext, unsigned int xi, unsigned int ci);
unsigned int ci);
/** /**
* \brief Initialize random number generator based on current system time. * \brief Initialize random number generator based on current system time.

View file

@ -2164,10 +2164,10 @@ void SDLTest_CommonQuit(SDLTest_CommonState *state)
SDLTest_LogAllocations(); SDLTest_LogAllocations();
} }
void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, int *usedHeight) void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, float *usedHeight)
{ {
char text[1024]; char text[1024];
int textY = 0; float textY = 0.0f;
const int lineHeight = 10; const int lineHeight = 10;
int x, y, w, h; int x, y, w, h;
float fx, fy; float fx, fy;
@ -2182,135 +2182,135 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
/* Video */ /* Video */
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_DrawString(renderer, 0, textY, "-- Video --"); SDLTest_DrawString(renderer, 0.0f, textY, "-- Video --");
textY += lineHeight; textY += lineHeight;
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255); SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
(void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentVideoDriver: %s", SDL_GetCurrentVideoDriver()); (void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentVideoDriver: %s", SDL_GetCurrentVideoDriver());
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
/* Renderer */ /* Renderer */
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_DrawString(renderer, 0, textY, "-- Renderer --"); SDLTest_DrawString(renderer, 0.0f, textY, "-- Renderer --");
textY += lineHeight; textY += lineHeight;
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255); SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
if (0 == SDL_GetRendererInfo(renderer, &info)) { if (0 == SDL_GetRendererInfo(renderer, &info)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetRendererInfo: name: %s", info.name); (void)SDL_snprintf(text, sizeof text, "SDL_GetRendererInfo: name: %s", info.name);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
} }
if (0 == SDL_GetRendererOutputSize(renderer, &w, &h)) { if (0 == SDL_GetRendererOutputSize(renderer, &w, &h)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetRendererOutputSize: %dx%d", w, h); (void)SDL_snprintf(text, sizeof text, "SDL_GetRendererOutputSize: %dx%d", w, h);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
} }
SDL_GetRenderViewport(renderer, &rect); SDL_GetRenderViewport(renderer, &rect);
(void)SDL_snprintf(text, sizeof text, "SDL_GetRenderViewport: %d,%d, %dx%d", (void)SDL_snprintf(text, sizeof text, "SDL_GetRenderViewport: %d,%d, %dx%d",
rect.x, rect.y, rect.w, rect.h); rect.x, rect.y, rect.w, rect.h);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
SDL_GetRenderScale(renderer, &scaleX, &scaleY); SDL_GetRenderScale(renderer, &scaleX, &scaleY);
(void)SDL_snprintf(text, sizeof text, "SDL_GetRenderScale: %f,%f", (void)SDL_snprintf(text, sizeof text, "SDL_GetRenderScale: %f,%f",
scaleX, scaleY); scaleX, scaleY);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
SDL_GetRenderLogicalSize(renderer, &w, &h); SDL_GetRenderLogicalSize(renderer, &w, &h);
(void)SDL_snprintf(text, sizeof text, "SDL_GetRenderLogicalSize: %dx%d", w, h); (void)SDL_snprintf(text, sizeof text, "SDL_GetRenderLogicalSize: %dx%d", w, h);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
/* Window */ /* Window */
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_DrawString(renderer, 0, textY, "-- Window --"); SDLTest_DrawString(renderer, 0.0f, textY, "-- Window --");
textY += lineHeight; textY += lineHeight;
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255); SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
SDL_GetWindowPosition(window, &x, &y); SDL_GetWindowPosition(window, &x, &y);
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowPosition: %d,%d", x, y); (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowPosition: %d,%d", x, y);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSize(window, &w, &h);
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowSize: %dx%d", w, h); (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowSize: %dx%d", w, h);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowFlags: "); (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowFlags: ");
SDLTest_PrintWindowFlags(text, sizeof text, SDL_GetWindowFlags(window)); SDLTest_PrintWindowFlags(text, sizeof text, SDL_GetWindowFlags(window));
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
if (0 == SDL_GetWindowDisplayMode(window, &mode)) { if (0 == SDL_GetWindowDisplayMode(window, &mode)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayMode: %dx%d@%gHz (%s)", (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayMode: %dx%d@%gHz (%s)",
mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format)); mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format));
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
} }
/* Display */ /* Display */
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_DrawString(renderer, 0, textY, "-- Display --"); SDLTest_DrawString(renderer, 0.0f, textY, "-- Display --");
textY += lineHeight; textY += lineHeight;
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255); SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayIndex: %d", windowDisplayIndex); (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayIndex: %d", windowDisplayIndex);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayName: %s", SDL_GetDisplayName(windowDisplayIndex)); (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayName: %s", SDL_GetDisplayName(windowDisplayIndex));
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
if (0 == SDL_GetDisplayBounds(windowDisplayIndex, &rect)) { if (0 == SDL_GetDisplayBounds(windowDisplayIndex, &rect)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayBounds: %d,%d, %dx%d", (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayBounds: %d,%d, %dx%d",
rect.x, rect.y, rect.w, rect.h); rect.x, rect.y, rect.w, rect.h);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
} }
if (0 == SDL_GetCurrentDisplayMode(windowDisplayIndex, &mode)) { if (0 == SDL_GetCurrentDisplayMode(windowDisplayIndex, &mode)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentDisplayMode: %dx%d@%gHz (%s)", (void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentDisplayMode: %dx%d@%gHz (%s)",
mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format)); mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format));
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
} }
if (0 == SDL_GetDesktopDisplayMode(windowDisplayIndex, &mode)) { if (0 == SDL_GetDesktopDisplayMode(windowDisplayIndex, &mode)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetDesktopDisplayMode: %dx%d@%gHz (%s)", (void)SDL_snprintf(text, sizeof text, "SDL_GetDesktopDisplayMode: %dx%d@%gHz (%s)",
mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format)); mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format));
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
} }
if (0 == SDL_GetDisplayDPI(windowDisplayIndex, &ddpi, &hdpi, &vdpi)) { if (0 == SDL_GetDisplayDPI(windowDisplayIndex, &ddpi, &hdpi, &vdpi)) {
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayDPI: ddpi: %f, hdpi: %f, vdpi: %f", (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayDPI: ddpi: %f, hdpi: %f, vdpi: %f",
ddpi, hdpi, vdpi); ddpi, hdpi, vdpi);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
} }
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayOrientation: "); (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayOrientation: ");
SDLTest_PrintDisplayOrientation(text, sizeof text, SDL_GetDisplayOrientation(windowDisplayIndex)); SDLTest_PrintDisplayOrientation(text, sizeof text, SDL_GetDisplayOrientation(windowDisplayIndex));
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
/* Mouse */ /* Mouse */
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_DrawString(renderer, 0, textY, "-- Mouse --"); SDLTest_DrawString(renderer, 0.0f, textY, "-- Mouse --");
textY += lineHeight; textY += lineHeight;
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255); SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
@ -2318,13 +2318,13 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
flags = SDL_GetMouseState(&fx, &fy); flags = SDL_GetMouseState(&fx, &fy);
(void)SDL_snprintf(text, sizeof text, "SDL_GetMouseState: %g,%g ", fx, fy); (void)SDL_snprintf(text, sizeof text, "SDL_GetMouseState: %g,%g ", fx, fy);
SDLTest_PrintButtonMask(text, sizeof text, flags); SDLTest_PrintButtonMask(text, sizeof text, flags);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
flags = SDL_GetGlobalMouseState(&fx, &fy); flags = SDL_GetGlobalMouseState(&fx, &fy);
(void)SDL_snprintf(text, sizeof text, "SDL_GetGlobalMouseState: %g,%g ", fx, fy); (void)SDL_snprintf(text, sizeof text, "SDL_GetGlobalMouseState: %g,%g ", fx, fy);
SDLTest_PrintButtonMask(text, sizeof text, flags); SDLTest_PrintButtonMask(text, sizeof text, flags);
SDLTest_DrawString(renderer, 0, textY, text); SDLTest_DrawString(renderer, 0.0f, textY, text);
textY += lineHeight; textY += lineHeight;
if (usedHeight) { if (usedHeight) {

View file

@ -3126,7 +3126,7 @@ struct SDLTest_CharTextureCache
*/ */
static struct SDLTest_CharTextureCache *SDLTest_CharTextureCacheList; 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 charWidth = FONT_CHARACTER_SIZE;
const Uint32 charHeight = 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 * Setup destination rectangle
*/ */
drect.x = (float)x; drect.x = x;
drect.y = (float)y; drect.y = y;
drect.w = (float)charWidth; drect.w = (float)charWidth;
drect.h = (float)charHeight; 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) #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; const Uint32 charWidth = FONT_CHARACTER_SIZE;
int result = 0; int result = 0;
int curx = x; float curx = x;
int cury = y; float cury = y;
size_t len = SDL_strlen(s); size_t len = SDL_strlen(s);
while (len > 0 && !result) { while (len > 0 && !result) {
@ -3350,7 +3350,7 @@ int SDLTest_DrawString(SDL_Renderer *renderer, int x, int y, const char *s)
return result; 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)); 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.w = w;
textwin->rect.h = h; textwin->rect.h = h;
textwin->current = 0; 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)); textwin->lines = (char **)SDL_calloc(textwin->numlines, sizeof(*textwin->lines));
if (!textwin->lines) { if (!textwin->lines) {
SDL_free(textwin); 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) 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) { for (y = textwin->rect.y, i = 0; i < textwin->numlines; ++i, y += FONT_LINE_HEIGHT) {
if (textwin->lines[i]) { if (textwin->lines[i]) {

View file

@ -52,7 +52,7 @@ quit(int rc)
/* Draws the modes menu, and stores the mode index under the mouse in highlighted_mode */ /* Draws the modes menu, and stores the mode index under the mouse in highlighted_mode */
static void static void
draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport) draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
{ {
SDL_DisplayMode mode; SDL_DisplayMode mode;
char text[1024]; char text[1024];
@ -62,8 +62,8 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
int i; int i;
int column_chars = 0; int column_chars = 0;
int text_length; int text_length;
int x, y; float x, y;
int table_top; float table_top;
SDL_FPoint mouse_pos = { -1.0f, -1.0f }; SDL_FPoint mouse_pos = { -1.0f, -1.0f };
/* Get mouse position */ /* Get mouse position */
@ -78,7 +78,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
mouse_pos.y = logical_y; mouse_pos.y = logical_y;
} }
x = 0; x = 0.0f;
y = viewport.y; y = viewport.y;
y += lineHeight; y += lineHeight;
@ -115,8 +115,8 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
column_chars = SDL_max(column_chars, text_length); column_chars = SDL_max(column_chars, text_length);
/* Check if under mouse */ /* Check if under mouse */
cell_rect.x = (float)x; cell_rect.x = x;
cell_rect.y = (float)y; cell_rect.y = y;
cell_rect.w = (float)(text_length * FONT_CHARACTER_SIZE); cell_rect.w = (float)(text_length * FONT_CHARACTER_SIZE);
cell_rect.h = (float)lineHeight; cell_rect.h = (float)lineHeight;
@ -134,7 +134,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
SDLTest_DrawString(renderer, x, y, text); SDLTest_DrawString(renderer, x, y, text);
y += lineHeight; y += lineHeight;
if (y + lineHeight > (viewport.y + viewport.h)) { if ((y + lineHeight) > (viewport.y + viewport.h)) {
/* Advance to next column */ /* Advance to next column */
x += (column_chars + 1) * FONT_CHARACTER_SIZE; x += (column_chars + 1) * FONT_CHARACTER_SIZE;
y = table_top; y = table_top;
@ -222,8 +222,9 @@ void loop()
SDL_Window *window = state->windows[i]; SDL_Window *window = state->windows[i];
SDL_Renderer *renderer = state->renderers[i]; SDL_Renderer *renderer = state->renderers[i];
if (window != NULL && renderer != NULL) { if (window != NULL && renderer != NULL) {
int y = 0; float y = 0.0f;
SDL_Rect viewport, menurect; SDL_Rect viewport;
SDL_FRect menurect;
SDL_GetRenderViewport(renderer, &viewport); SDL_GetRenderViewport(renderer, &viewport);
@ -233,10 +234,10 @@ void loop()
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_CommonDrawWindowInfo(renderer, state->windows[i], &y); SDLTest_CommonDrawWindowInfo(renderer, state->windows[i], &y);
menurect.x = 0; menurect.x = 0.0f;
menurect.y = y; menurect.y = y;
menurect.w = viewport.w; menurect.w = (float)viewport.w;
menurect.h = viewport.h - y; menurect.h = (float)viewport.h - y;
draw_modes_menu(window, renderer, menurect); draw_modes_menu(window, renderer, menurect);
SDL_Delay(16); SDL_Delay(16);