- SDL_Event event;
- int ch;
- SDL_Rect rect;
- int ofs=(text[0]-33)*2+1;
- int leftshift;
-
- if (ofs<0) {
- leftshift = 0;
- }
- else {
- leftshift = (Font->CharPos[ofs]-Font->CharPos[ofs-1])/2;
- }
-
- rect.x=x-leftshift;
- rect.y=y;
- rect.w=PixelWidth;
- rect.h=Font->Surface->h;
-
- //SDL_SetAlpha (Dest, SDL_SRCALPHA, 127);
-
- SDL_BlitSurface(Dest, &rect, Back, NULL);
- sprintf(tmp,"%s_",text);
- PutString2(Dest,Font,x,y,tmp);
- SDL_UpdateRect(Dest, x-leftshift, y, PixelWidth, Font->h);
-
- while (SDL_PollEvent(&event) && event.type==SDL_KEYDOWN) {
-
- // Find the character pressed
- ch=event.key.keysym.unicode;
-
- // If backspace and the length of the text > 0, reduce the string by 1 character
- if (ch=='\b') {
- if (strlen(text)>0) {
- text[strlen(text)-1]='\0';
- }
- }
- else {
- sprintf(text,"%s%c",text,ch);
- }
-
- // If the new character would exceed the allowed width
- if (TextWidth2(Font,text)>PixelWidth) {
- text[strlen(text)-1]='\0';
- }
-
- //SDL_SetAlpha (Back, SDL_SRCALPHA, 127);
- SDL_BlitSurface( Back, NULL, Dest, &rect);
- PutString2(Dest, Font, x, y, text);
- if (ofs>0) {
- SDL_UpdateRect(Dest, x-(Font->CharPos[ofs]-Font->CharPos[ofs-1])/2, y, PixelWidth, Font->Surface->h);
- }
-
- }
- //text[strlen(text)-1]='\0';
- if (ch==SDLK_RETURN) {
- SDL_FreeSurface(Back);
- return 1;
- }
- else
- return 0;