/* ** digit.c for in /home/gayot_o/prog/lib/sdl-digit ** ** Made by olivier gayot ** Login ** ** Started on Mon Apr 23 08:16:00 2012 olivier gayot ** Last update Mon Apr 23 08:16:00 2012 olivier gayot */ #include #include "sdl_digit.h" #include "draw.h" int draw_digit(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color, char d) { void (*f_ptr[256])(SDL_Surface *, SDL_Rect *, int, Uint32); memset((void *)f_ptr, 0, sizeof(f_ptr)); f_ptr[(int)'0'] = &draw_0; f_ptr[(int)'1'] = &draw_1; f_ptr[(int)'2'] = &draw_2; f_ptr[(int)'3'] = &draw_3; f_ptr[(int)'4'] = &draw_4; f_ptr[(int)'5'] = &draw_5; f_ptr[(int)'6'] = &draw_6; f_ptr[(int)'7'] = &draw_7; f_ptr[(int)'8'] = &draw_8; f_ptr[(int)'9'] = &draw_9; f_ptr[(int)'-'] = &draw_hyphen; f_ptr[(int)' '] = &draw_space; f_ptr[(int)'a'] = &draw_A; f_ptr[(int)'A'] = &draw_A; f_ptr[(int)'b'] = &draw_B; f_ptr[(int)'B'] = &draw_B; f_ptr[(int)'c'] = &draw_C; f_ptr[(int)'C'] = &draw_C; f_ptr[(int)'d'] = &draw_D; f_ptr[(int)'D'] = &draw_D; f_ptr[(int)'e'] = &draw_E; f_ptr[(int)'E'] = &draw_E; f_ptr[(int)'f'] = &draw_F; f_ptr[(int)'F'] = &draw_F; f_ptr[(int)'g'] = &draw_G; f_ptr[(int)'G'] = &draw_G; f_ptr[(int)'h'] = &draw_H; f_ptr[(int)'H'] = &draw_H; f_ptr[(int)'i'] = &draw_I; f_ptr[(int)'I'] = &draw_I; f_ptr[(int)'j'] = &draw_J; f_ptr[(int)'J'] = &draw_J; f_ptr[(int)'K'] = &draw_K; f_ptr[(int)'k'] = &draw_K; f_ptr[(int)'l'] = &draw_L; f_ptr[(int)'L'] = &draw_L; f_ptr[(int)'m'] = &draw_M; f_ptr[(int)'M'] = &draw_M; f_ptr[(int)'n'] = &draw_N; f_ptr[(int)'N'] = &draw_N; f_ptr[(int)'o'] = &draw_O; f_ptr[(int)'O'] = &draw_O; f_ptr[(int)'p'] = &draw_P; f_ptr[(int)'P'] = &draw_P; f_ptr[(int)'q'] = &draw_Q; f_ptr[(int)'Q'] = &draw_Q; f_ptr[(int)'r'] = &draw_R; f_ptr[(int)'R'] = &draw_R; f_ptr[(int)'s'] = &draw_S; f_ptr[(int)'S'] = &draw_S; f_ptr[(int)'t'] = &draw_T; f_ptr[(int)'T'] = &draw_T; f_ptr[(int)'u'] = &draw_U; f_ptr[(int)'U'] = &draw_U; f_ptr[(int)'V'] = &draw_V; f_ptr[(int)'v'] = &draw_V; f_ptr[(int)'w'] = &draw_W; f_ptr[(int)'W'] = &draw_W; f_ptr[(int)'x'] = &draw_X; f_ptr[(int)'X'] = &draw_X; f_ptr[(int)'y'] = &draw_Y; f_ptr[(int)'Y'] = &draw_Y; f_ptr[(int)'z'] = &draw_Z; f_ptr[(int)'Z'] = &draw_Z; if (!f_ptr[(int)d]) return 0; f_ptr[(int)d](surf, rect, size, color); return 1; } static void draw_0(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); } static void draw_1(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 5); } static void draw_2(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 6); } static void draw_3(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); } static void draw_4(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 5); } static void draw_5(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); } static void draw_6(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); } static void draw_7(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 5); } static void draw_8(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); } static void draw_9(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); } static void draw_hyphen(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 3); } static void draw_space(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { (void)surf; (void)rect; (void)size; (void)color; } static void draw_A(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); } static void draw_B(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); draw_bar_id(surf, rect, size, color, 11); draw_bar_id(surf, rect, size, color, 12); draw_bar_id(surf, rect, size, color, 14); } static void draw_C(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 6); } static void draw_D(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); draw_bar_id(surf, rect, size, color, 11); draw_bar_id(surf, rect, size, color, 12); } static void draw_E(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 6); } static void draw_F(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 4); } static void draw_G(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); draw_bar_id(surf, rect, size, color, 14); } static void draw_H(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); } static void draw_I(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 11); draw_bar_id(surf, rect, size, color, 12); } static void draw_J(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); } static void draw_K(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 7); draw_bar_id(surf, rect, size, color, 10); } static void draw_L(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 6); } static void draw_M(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 15); draw_bar_id(surf, rect, size, color, 16); } static void draw_N(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 15); draw_bar_id(surf, rect, size, color, 18); } static void draw_O(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_0(surf, rect, size, color); } static void draw_P(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 4); } static void draw_Q(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); draw_bar_id(surf, rect, size, color, 18); } static void draw_R(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 18); } static void draw_S(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_5(surf, rect, size, color); } static void draw_T(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 11); draw_bar_id(surf, rect, size, color, 12); } static void draw_U(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); } static void draw_V(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 19); draw_bar_id(surf, rect, size, color, 20); } static void draw_W(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 4); draw_bar_id(surf, rect, size, color, 5); draw_bar_id(surf, rect, size, color, 6); draw_bar_id(surf, rect, size, color, 12); } static void draw_X(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 15); draw_bar_id(surf, rect, size, color, 16); draw_bar_id(surf, rect, size, color, 17); draw_bar_id(surf, rect, size, color, 18); } static void draw_Y(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 1); draw_bar_id(surf, rect, size, color, 2); draw_bar_id(surf, rect, size, color, 3); draw_bar_id(surf, rect, size, color, 12); } static void draw_Z(SDL_Surface *surf, SDL_Rect *rect, int size, Uint32 color) { draw_bar_id(surf, rect, size, color, 0); draw_bar_id(surf, rect, size, color, 16); draw_bar_id(surf, rect, size, color, 17); draw_bar_id(surf, rect, size, color, 6); }