TrueType font input

sge_tt_input

These functions handle keyboard input and shows the result on screen.

SDL_Surface *screen - The screen pointer.
sge_TTFont *font - The font to render the text with.
char *string or Uint16 *string - The Latin-1/Unicode text string to put the result into.
Uint8 flags - Flags (may be ORed, eg. SGE_IBG|SGE_IDEL).
0 - Default
SGE_IBG - Keeps background, else bye bye background
SGE_IDEL - Delete text on exit
SGE_INOKR - No keyrepeat (you can then use SDL_EnableKeyRepeat())
int pos - Set this to zero if you don't want a default text (see below).
int len - The max numbers of chars editable, string should have at least len+1 elements allocated.
Sint16 x, Sint16 y - The leftmost point of the baseline for the text.
Uint32 fcolor or Uint8 fR, Uint8 fG, Uint8 fB - The color of the font.
Uint32 bcolor or Uint8 bR, Uint8 bG, Uint8 bB - The background color (see below).
int Alpha - Sets the transparency of the text (0-255).

The text can be edited with [Backspace], [Delete], [Left arrow] and [Right arrow]. Text input is terminated when [Return] or [Enter] is pressed, or if a quit event is received. Puts the result in 'string'.

If you want a 'default' text you can copy it to string before call and set pos to the first empty element in string - ex. "Hello" => pos=5. If not, set pos to zero.

You can use sge_TTF_AAOn(), sge_TTF_AAOff() and sge_TTF_AA_Alpha() to control how the text is rendered. If you use antialiasing, the background color must be set to the background color of the area where you will render the text. If the background has more than one color it might be better to use sge_TTF_AA_Alpha().
Does lock and update the surface. Does respect clipping.

Note: This function will block your program! Use the text classes if you want more control (see the example).

Returns int:
Zero or above - the length of the string
-1 - received a quit event
-2 - invalid indata
-3 - out of memory

Example

#include <iostream>
#include <string.h>
#include "SDL.h"
#include "sge.h"

using namespace std;

...

//Init font engine and exit on error
if(sge_TTF_Init()!=0){
cerr << "TT error: " << SDL_GetError() << endl;
exit(1);
}
//Open font and exit on error
sge_TTFont *font=sge_TTF_OpenFont("font.ttf", 25);
if(!font){
cerr << "TT error: " << SDL_GetError() << endl;
exit(1);
}
sge_TTF_AA_Alpha(); //Nice alpha rendering

char string[52];
strcpy(string,"Edit Me!"); //The default text
int ret;

//Let the user edit the text
ret=sge_tt_input( screen, font, string, SGE_IBG, 8, 50, 10,100, 0,0,255, 0,0,0, SDL_ALPHA_OPAQUE );
if(ret>0)
cout << string << endl; //print the text
sge_TTF_CloseFont(font);





Copyright © 1999-2001 Anders Lindström
Last updated 010628