# TrueType font input

## sge_tt_input

- int sge_tt_input(SDL_Surface *screen, sge_TTFont *font, char *string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y, Uint32 fcol, Uint32 bcol, int Alpha)
- int sge_tt_input(SDL_Surface *screen, sge_TTFont *font, char *string, Uint8 flags, int pos,int len,Sint16 x,Sint16 y, Uint8 fR, Uint8 fG, Uint8 fB, Uint8 bR, Uint8 bG, Uint8 bB, int Alpha)
- int sge_tt_input_UNI(SDL_Surface *screen, sge_TTFont *font, Uint16 *string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y, Uint32 fcol, Uint32 bcol, int Alpha)
- int sge_tt_input_UNI(SDL_Surface *screen, sge_TTFont *font, Uint16 *string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y, Uint8 fR, Uint8 fG, Uint8 fB, Uint8 bR, Uint8 bG, Uint8 bB, int Alpha)

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 the background, use this if the background has more colors than the background color.
  SGE_IDEL - Delete text on screen on exit.
  SGE_INOKR - No keyrepeat (you can then use SDL_EnableKeyRepeat() yourself).
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], [Enter] or [Escape] is pressed, or if a quit event is received. Puts the result in "string" (null terminated).
If you want a 'default' text then copy a null (\0) terminated string into the argument "string" before calling this function. Set "pos" to any other value than zero to indicate this.
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 (i.e. [Return] or [Enter] was pressed).
-1 - received a quit event, but everything else was handled as normal.
-2 - [Escape] was pressed, but everything else was handled as normal.
-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, 1, 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);
To the TTF setup functions>>

Copyright © 1999-2003 Anders Lindström
Last updated 030808