#include #include #include void dibujar(SDL_Surface *imagen, SDL_Surface *imagen2, int opcion); void limpiar(SDL_Surface *screen); SDL_Surface *screen; SDL_Surface *fondo; SDL_Surface *imagen; SDL_Surface *imagen2; SDL_Event event; int filas = 6; int columnas = 16; int i, x; char *data[] = { "Opcasdfaion1", "Oasfd", "Opcion lol", "Opcion lolafd", "opcion rlz" }; int main(int argc, char *argv[]) { // El espacio es el 32 y de ahí para alante int opcion = 0; if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1) { printf("No se ha iniciado SDL"); } screen = SDL_SetVideoMode(320, 240, 16, SDL_SWSURFACE); SDL_WM_SetCaption("Escribir palabras en pantalla", NULL); imagen = SDL_LoadBMP("letras.bmp"); // Apagadas imagen2 = SDL_LoadBMP("letras2.bmp"); // Iluminadas if (imagen == NULL) SDL_Quit(); dibujar(imagen, imagen2, 0); while (SDL_WaitEvent(&event)) { if (event.type == SDL_QUIT) break; else if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_UP) { if (opcion != 0) opcion--; else opcion = (sizeof(data) / sizeof(char *) -1); } else if (event.key.keysym.sym == SDLK_DOWN) { if (opcion != (sizeof(data) / sizeof(char *) -1)) opcion++; else opcion = 0; } } else { continue; } limpiar(screen); dibujar(imagen, imagen2, opcion); } SDL_Quit(); return 0; } void dibujar(SDL_Surface *imagen, SDL_Surface *imagen2, int opcion) { int lancho = imagen->w/columnas; int lalto = imagen->h/filas; int letra, maxx = 0; SDL_Rect dstrect = {0, 0, 0, 0}; for (x = 0; x < sizeof(data) / sizeof(char *); x++) { for (i = 0; i < strlen(data[x]); i++) { letra = data[x][i] - 32; SDL_Rect letrarect = {letra % columnas * lancho, letra / columnas * lalto + 2, lancho, lalto}; if (x == opcion) { SDL_BlitSurface(imagen, &letrarect, screen, &dstrect); } else { SDL_BlitSurface(imagen2, &letrarect, screen, &dstrect); } dstrect.x += lancho; } if (dstrect.x > 0) maxx = dstrect.x; dstrect.x = 0; dstrect.y += lalto + 1; } SDL_UpdateRect(screen, 0, 0, 320, 240); } void limpiar(SDL_Surface *screen) { Uint32 c = SDL_MapRGB(screen->format, 0, 0, 0); SDL_FillRect(screen, NULL, c); }