X-Git-Url: http://royale.zerezo.com/git/?p=zeRace;a=blobdiff_plain;f=sdl.c;h=99891f0e792a0c5b6f8ad9ad5012e7e8495815ce;hp=0661854abaf989ab9ef7183adba1accf1cfbfcba;hb=HEAD;hpb=f3b6b880f4b72504090898ab825f38f091a68168 diff --git a/sdl.c b/sdl.c index 0661854..99891f0 100644 --- a/sdl.c +++ b/sdl.c @@ -2,13 +2,13 @@ SDL_Surface *font=NULL; +/* prints a message using the bitmap font */ void print(SDL_Surface *dst,int x,int y,unsigned char *text) { SDL_Rect srcpos,dstpos; + /* on the first call, load the font picture */ if (!font) if ((font=IMG_Load("sprites/font.png"))==NULL) - { - fprintf(stderr,"could not load font file\n",SDL_GetError()); - } + fprintf(stderr,"could not load font file\n"); while (*text!='\0') { if (*text>=' ' && *text<' '+16*10) @@ -24,6 +24,51 @@ void print(SDL_Surface *dst,int x,int y,unsigned char *text) } } +/* reads a string into the "text" variable */ +void readstring(SDL_Surface *dst,int x,int y,unsigned char *text,int limit) +{ + SDL_Event event; + int shift=0; + + SDL_EnableUNICODE(1); + for (;;) + { + while (SDL_PollEvent(&event)) switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + case SDLK_RETURN: + return; + case SDLK_LSHIFT: + case SDLK_RSHIFT: + shift=1; + break; + case SDLK_BACKSPACE: + if (strlen(text)) + { + text[strlen(text)-1]='\0'; + print(dst,x+strlen(text)*10,y," "); + } + break; + default: + if ((event.key.keysym.unicode & 0xff80)==0 && strlen(text)format, r, g, b ); - - /* How we draw the pixel depends on the bitdepth */ - switch(screen->format->BytesPerPixel) { - case 1: - ubuff8 = (Uint8*) screen->pixels; - ubuff8 += (y * screen->pitch) + x; - *ubuff8 = (Uint8) color; - break; - case 2: - ubuff16 = (Uint16*) screen->pixels; - ubuff16 += ((y * screen->pitch)>>2) + x; - *ubuff16 = (Uint16) color; - break; - case 3: - ubuff8 = (Uint8*) screen->pixels; - ubuff8 += (y * screen->pitch) + x; - - r = (color>>screen->format->Rshift)&0xFF; - g = (color>>screen->format->Gshift)&0xFF; - b = (color>>screen->format->Bshift)&0xFF; - - ubuff8[0] = r; - ubuff8[1] = g; - ubuff8[2] = b; - break; - - case 4: - ubuff32 = (Uint32*) screen->pixels; - ubuff32 += ((y*screen->pitch)>>2) + x; - *ubuff32 = color; - break; - - default: - fprintf(stderr, "Error: Unknown bitdepth!\n"); - } - - /* Unlock the screen if needed */ - if(SDL_MUSTLOCK(screen)) { - SDL_UnlockSurface(screen); - } -}