[SDL] Small problem

Sean Middleditch sean.middleditch at iname.com
Sat Apr 14 11:39:55 PDT 2001


Here, the problem is:
if(event.type = SDL_KEYDOWN) {

That should be:
if(event.type == SDL_KEYDOWN) {

You were setting the event.type TO SDL_KEYDOWN, instead of checking
whether it WAS SDL_KEYDOWN.  Big difference.  ^,^

On 14 Apr 2001 20:02:05 +0100, skinncode wrote:
> 
> Hello everybody,
> 
> I have a small problem. Hope you guys help me to solve it out...
> So i have two functions one to output text, another for input. Look at the input function. I do isalnum(int) to filter all unneeded keysyms but if i move mouse during the input it segfaults me. Any ideas? Also feel free to remark some things in this source that are badly done or coud be done better.
> TIA.
> --skinncode
> 
> int skOutText(SDL_Surface *dsrc, char *message, char *font, int size, int x, int y, SDL_Color color)
> {
>   SDL_Surface *text;
>   SDL_Rect r_tdest;
>   TTF_Font *myfont;
> 
>   myfont = TTF_OpenFont (font, size);
>   text = TTF_RenderText (myfont, message, cl_white, cl_black);
> 
>   SDL_SetAlpha (text, SDL_SRCALPHA | SDL_RLEACCEL, 100);
>   SDL_SetColorKey (text, SDL_SRCCOLORKEY | SDL_RLEACCEL,SDL_MapRGB (text->format, 0, 0, 0));
>   r_tdest.x = x;
>   r_tdest.y = y;
>   r_tdest.w = text->w;
>   r_tdest.h = text->h;
>   SDL_UpperBlit(text, NULL, dsrc, &r_tdest);
>   SDL_UpdateRects (dsrc, 1, &r_tdest);
>   SDL_FreeSurface (text);
>   TTF_CloseFont (myfont);
>   return 0;
> }
> 
> char *skTextIn(SDL_Surface *scr, char *font, int size, int posx, int posy, int length) {
>         char *text, *letter;
>         SDL_Event event;
>         Uint8 *keys;
>           int done = 0, len;
>         while(done != 1) {
>                 if(SDL_PollEvent(&event) == 0) {
>                 } else {
>                         if(event.type = SDL_KEYDOWN) {
>                                 keys = SDL_GetKeyState(NULL);
>                                 if(SDL_PRESSED || keys[SDLK_RETURN] == SDL_PRESSED) { done = 1; }
>                                 if(isalnum(event.key.keysym.sym) && len<length) {
>                                         sprintf(letter, "%c", event.key.keysym.sym);
>                                         skOutText(scr, letter, font, size, posx, posy, cl_white);
>                                         posx += 10;
>                                         len++;
>                                         }
> 
>                                 }
>                 }
>         }
> 
>         return text;
> }
> 
> 

-- 
Sean Middleditch
  of
AwesomePlay Productions, Inc.




More information about the SDL mailing list