Next post: SSE instructions

SDL Text and Dialogs

For one of my recent projects, I wanted dialogs in an sdl program. This small library draws simple "dialogs" to ask the user for text or a number.



// where SDL_Surface* pSurface is the screen surface.

// ask the user for a string
char * s; 
s = Dialog_GetText("Enter your name:", "Fred", pSurface);
Dialog_Messagef(pSurface, "Welcome, %s", s);
free(s);

// ask the user for a floating point number
double val = 1.5;
Dialog_GetDouble("Enter a value", pSurface, &val);

// ask the user for an integer
int n = 1;
Dialog_GetInt("Enter a number.", pSurface, &n);

// ask the user yes or no
bool b = Dialog_GetBool("Yes or no?", pSurface);

// show a modal message
Dialog_Message("Goodbye", pSurface);
freeFonts();



The source is on GitHub here, under the GPLv3.