Test text rendering APIs take floating point coordinates
This commit is contained in:
parent
0901657278
commit
0bbf6cc379
@ -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.
|
||||
*/
|
||||
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 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
|
||||
@ -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.
|
||||
* \returns a string with usage information
|
||||
*/
|
||||
const char *SDLTest_CommonUsage(SDLTest_CommonState * state);
|
||||
const char *SDLTest_CommonUsage(SDLTest_CommonState *state);
|
||||
|
||||
/**
|
||||
* \brief Open test window.
|
||||
@ -184,7 +184,7 @@ const char *SDLTest_CommonUsage(SDLTest_CommonState * state);
|
||||
*
|
||||
* \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.
|
||||
@ -195,7 +195,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState * state);
|
||||
*
|
||||
* \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.
|
||||
@ -205,7 +205,7 @@ SDL_bool SDLTest_CommonDefaultArgs(SDLTest_CommonState * state, const int argc,
|
||||
* \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.
|
||||
@ -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.
|
||||
*
|
||||
*/
|
||||
void SDLTest_CommonQuit(SDLTest_CommonState * state);
|
||||
void SDLTest_CommonQuit(SDLTest_CommonState *state);
|
||||
|
||||
/**
|
||||
* \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.
|
||||
*
|
||||
*/
|
||||
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++ */
|
||||
#ifdef __cplusplus
|
||||
|
@ -79,7 +79,7 @@ extern "C" {
|
||||
* \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
|
||||
*
|
||||
*/
|
||||
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 */
|
||||
int SDLTest_Crc32CalcStart(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_Crc32CalcStart(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);
|
||||
|
||||
|
||||
/**
|
||||
@ -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++ */
|
||||
|
@ -51,7 +51,7 @@ extern "C" {
|
||||
*
|
||||
* \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.
|
||||
@ -65,14 +65,14 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c);
|
||||
*
|
||||
* \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
|
||||
*/
|
||||
typedef struct SDLTest_TextWindow
|
||||
{
|
||||
SDL_Rect rect;
|
||||
SDL_FRect rect;
|
||||
int current;
|
||||
int numlines;
|
||||
char **lines;
|
||||
@ -90,7 +90,7 @@ typedef struct SDLTest_TextWindow
|
||||
*
|
||||
* \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
|
||||
|
@ -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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
char * SDLTest_RandomAsciiStringOfSize(int size);
|
||||
char *SDLTest_RandomAsciiStringOfSize(int size);
|
||||
|
||||
/**
|
||||
* Get the invocation count for the fuzzer since last ...FuzzerInit.
|
||||
|
@ -86,7 +86,7 @@ extern "C" {
|
||||
* mdContext. Call before each new use of the context -
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
|
||||
void SDLTest_Md5Update(SDLTest_Md5Context *mdContext, unsigned char *inBuf,
|
||||
unsigned int inLen);
|
||||
|
||||
|
||||
@ -115,7 +115,7 @@ extern "C" {
|
||||
* 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++ */
|
||||
|
@ -78,8 +78,7 @@ extern "C" {
|
||||
* \param ci integer that defines the random sequence
|
||||
*
|
||||
*/
|
||||
void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi,
|
||||
unsigned int ci);
|
||||
void SDLTest_RandomInit(SDLTest_RandomContext *rndContext, unsigned int xi, unsigned int ci);
|
||||
|
||||
/**
|
||||
* \brief Initialize random number generator based on current system time.
|
||||
|
@ -2164,10 +2164,10 @@ void SDLTest_CommonQuit(SDLTest_CommonState *state)
|
||||
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];
|
||||
int textY = 0;
|
||||
float textY = 0.0f;
|
||||
const int lineHeight = 10;
|
||||
int x, y, w, h;
|
||||
float fx, fy;
|
||||
@ -2182,135 +2182,135 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
|
||||
/* Video */
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_DrawString(renderer, 0, textY, "-- Video --");
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, "-- Video --");
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
|
||||
(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;
|
||||
|
||||
/* Renderer */
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_DrawString(renderer, 0, textY, "-- Renderer --");
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, "-- Renderer --");
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
|
||||
if (0 == SDL_GetRendererInfo(renderer, &info)) {
|
||||
(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;
|
||||
}
|
||||
|
||||
if (0 == SDL_GetRendererOutputSize(renderer, &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;
|
||||
}
|
||||
|
||||
SDL_GetRenderViewport(renderer, &rect);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetRenderViewport: %d,%d, %dx%d",
|
||||
rect.x, rect.y, rect.w, rect.h);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_GetRenderScale(renderer, &scaleX, &scaleY);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetRenderScale: %f,%f",
|
||||
scaleX, scaleY);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_GetRenderLogicalSize(renderer, &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;
|
||||
|
||||
/* Window */
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_DrawString(renderer, 0, textY, "-- Window --");
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, "-- Window --");
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
|
||||
SDL_GetWindowPosition(window, &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;
|
||||
|
||||
SDL_GetWindowSize(window, &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;
|
||||
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowFlags: ");
|
||||
SDLTest_PrintWindowFlags(text, sizeof text, SDL_GetWindowFlags(window));
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
if (0 == SDL_GetWindowDisplayMode(window, &mode)) {
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayMode: %dx%d@%gHz (%s)",
|
||||
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;
|
||||
}
|
||||
|
||||
/* Display */
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_DrawString(renderer, 0, textY, "-- Display --");
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, "-- Display --");
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
|
||||
(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;
|
||||
|
||||
(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;
|
||||
|
||||
if (0 == SDL_GetDisplayBounds(windowDisplayIndex, &rect)) {
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayBounds: %d,%d, %dx%d",
|
||||
rect.x, rect.y, rect.w, rect.h);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
if (0 == SDL_GetCurrentDisplayMode(windowDisplayIndex, &mode)) {
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentDisplayMode: %dx%d@%gHz (%s)",
|
||||
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;
|
||||
}
|
||||
|
||||
if (0 == SDL_GetDesktopDisplayMode(windowDisplayIndex, &mode)) {
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetDesktopDisplayMode: %dx%d@%gHz (%s)",
|
||||
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;
|
||||
}
|
||||
|
||||
if (0 == SDL_GetDisplayDPI(windowDisplayIndex, &ddpi, &hdpi, &vdpi)) {
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayDPI: ddpi: %f, hdpi: %f, vdpi: %f",
|
||||
ddpi, hdpi, vdpi);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayOrientation: ");
|
||||
SDLTest_PrintDisplayOrientation(text, sizeof text, SDL_GetDisplayOrientation(windowDisplayIndex));
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
/* Mouse */
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_DrawString(renderer, 0, textY, "-- Mouse --");
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, "-- Mouse --");
|
||||
textY += lineHeight;
|
||||
|
||||
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);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetMouseState: %g,%g ", fx, fy);
|
||||
SDLTest_PrintButtonMask(text, sizeof text, flags);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
flags = SDL_GetGlobalMouseState(&fx, &fy);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetGlobalMouseState: %g,%g ", fx, fy);
|
||||
SDLTest_PrintButtonMask(text, sizeof text, flags);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
if (usedHeight) {
|
||||
|
@ -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]) {
|
||||
|
@ -52,7 +52,7 @@ quit(int rc)
|
||||
|
||||
/* Draws the modes menu, and stores the mode index under the mouse in highlighted_mode */
|
||||
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;
|
||||
char text[1024];
|
||||
@ -62,8 +62,8 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
|
||||
int i;
|
||||
int column_chars = 0;
|
||||
int text_length;
|
||||
int x, y;
|
||||
int table_top;
|
||||
float x, y;
|
||||
float table_top;
|
||||
SDL_FPoint mouse_pos = { -1.0f, -1.0f };
|
||||
|
||||
/* Get mouse position */
|
||||
@ -78,7 +78,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
|
||||
mouse_pos.y = logical_y;
|
||||
}
|
||||
|
||||
x = 0;
|
||||
x = 0.0f;
|
||||
y = viewport.y;
|
||||
|
||||
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);
|
||||
|
||||
/* Check if under mouse */
|
||||
cell_rect.x = (float)x;
|
||||
cell_rect.y = (float)y;
|
||||
cell_rect.x = x;
|
||||
cell_rect.y = y;
|
||||
cell_rect.w = (float)(text_length * FONT_CHARACTER_SIZE);
|
||||
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);
|
||||
y += lineHeight;
|
||||
|
||||
if (y + lineHeight > (viewport.y + viewport.h)) {
|
||||
if ((y + lineHeight) > (viewport.y + viewport.h)) {
|
||||
/* Advance to next column */
|
||||
x += (column_chars + 1) * FONT_CHARACTER_SIZE;
|
||||
y = table_top;
|
||||
@ -222,8 +222,9 @@ void loop()
|
||||
SDL_Window *window = state->windows[i];
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (window != NULL && renderer != NULL) {
|
||||
int y = 0;
|
||||
SDL_Rect viewport, menurect;
|
||||
float y = 0.0f;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect menurect;
|
||||
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
|
||||
@ -233,10 +234,10 @@ void loop()
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_CommonDrawWindowInfo(renderer, state->windows[i], &y);
|
||||
|
||||
menurect.x = 0;
|
||||
menurect.x = 0.0f;
|
||||
menurect.y = y;
|
||||
menurect.w = viewport.w;
|
||||
menurect.h = viewport.h - y;
|
||||
menurect.w = (float)viewport.w;
|
||||
menurect.h = (float)viewport.h - y;
|
||||
draw_modes_menu(window, renderer, menurect);
|
||||
|
||||
SDL_Delay(16);
|
||||
|
Loading…
x
Reference in New Issue
Block a user