diff --git a/Makefile b/Makefile index bed0329..05b78b6 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ LDFLAGS = -L$(DEVKITPRO)/SDL/lib -g $(MACHDEP) -Wl,-Map,$(notdir $@).map #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- -LIBS := -lSDL_image -ljpeg -lpng -lz -lSDL -lfat -lwiiuse -lbte -logc -lm +LIBS := -lSDL_image -lSDL_ttf -ljpeg -lpng -lz -lSDL -lfreetype -lfat -lwiiuse -lbte -logc -lm #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing diff --git a/Src/C64.h b/Src/C64.h index c218a2f..8f220f8 100644 --- a/Src/C64.h +++ b/Src/C64.h @@ -155,7 +155,7 @@ public: #endif #ifdef HAVE_SDL menu_t main_menu; - Font *menu_font; + TTF_Font *menu_font; const char *base_dir; bool fake_key_sequence; diff --git a/Src/C64_SDL.i b/Src/C64_SDL.i index 4956e34..18f5a1c 100644 --- a/Src/C64_SDL.i +++ b/Src/C64_SDL.i @@ -68,7 +68,22 @@ void C64::c64_ctor1(void) this->fake_key_keytime = 5; this->fake_key_type = 0; - this->menu_font = new Font("/apps/frodo/fonts.bmp"); + SDL_RWops *rw; + + Uint8 *data = (Uint8*)malloc(1 * 1024*1024); + FILE *fp = fopen("/apps/frodo/FreeMono.ttf", "r"); + if (!fp) { + fprintf(stderr, "Could not open font\n"); + exit(1); + } + fread(data, 1, 1 * 1024 * 1024, fp); + rw = SDL_RWFromMem(data, 1 * 1024 * 1024); + if (!rw) { + fprintf(stderr, "Could not create RW: %s\n", SDL_GetError()); + exit(1); + } + + this->menu_font = TTF_OpenFontRW(rw, 1, 20); if (!this->menu_font) { fprintf(stderr, "Unable to open font\n" ); @@ -372,7 +387,7 @@ uint8 C64::poll_joystick(int port) j &= 0xef; // Button if (held & WPAD_BUTTON_HOME) this->enter_menu(); - if (held & WPAD_BUTTON_A) + if (held & WPAD_BUTTON_B) exit(1); if ( (held & WPAD_BUTTON_A) && ThePrefs.JoystickKeyBinding[0]) diff --git a/Src/main_wii.i b/Src/main_wii.i index 836bc0d..cce294b 100644 --- a/Src/main_wii.i +++ b/Src/main_wii.i @@ -40,6 +40,12 @@ extern "C" int main(int argc, char **argv) fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError()); return 0; } + if (TTF_Init() < 0) + { + fprintf(stderr, "Unable to init TTF: %s\n", TTF_GetError() ); + return 0; + } + if (WPAD_Init() != WPAD_ERR_NONE) { fprintf(stderr, "Failed initializing controllers\n"); diff --git a/Src/menu.cpp b/Src/menu.cpp index 8f50c68..3a9c27e 100644 --- a/Src/menu.cpp +++ b/Src/menu.cpp @@ -12,8 +12,6 @@ #include #include -#include "bitmap-font.h" - #if defined(GEKKO) # include #endif @@ -44,11 +42,14 @@ static submenu_t *find_submenu(menu_t *p_menu, int index) return NULL; } -static void print_font(SDL_Surface *screen, Font *font, int type, +static void print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b, int x, int y, char *msg) { + SDL_Surface *font_surf; + SDL_Rect dst = {x, y, 0, 0}; + SDL_Color color = {r, g, b}; char buf[255]; - unsigned int i; + int i; memset(buf, 0, sizeof(buf)); strncpy(buf, msg, 254); @@ -60,7 +61,17 @@ static void print_font(SDL_Surface *screen, Font *font, int type, buf[i] = ' '; } - font->ShowText(buf, type, x, y, screen); + font_surf = TTF_RenderText_Solid(font, buf, + color); + if (!font_surf) + { + fprintf(stderr, "%s\n", TTF_GetError()); + exit(1); + } + + SDL_BlitSurface(font_surf, NULL, screen, &dst); + + SDL_FreeSurface(font_surf); } @@ -68,7 +79,7 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu) { int x_start = p_menu->x1 + (p_menu->x2 - p_menu->x1) / 2 - p_menu->text_w / 2; int y_start = p_menu->y1 + (p_menu->y2 - p_menu->y1) / 2 - p_menu->text_h / 2; - int font_height = p_menu->p_font->GetHeight(); + int font_height = TTF_FontHeight(p_menu->p_font); int line_height = (font_height + font_height / 4); int cur_y = p_menu->cur_sel * line_height; int entries_visible = p_menu->y2 / line_height; @@ -87,13 +98,13 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu) int y = (i - p_menu->start_entry_visible) * line_height; if ((p_menu->available_options & (1<p_font, 2, x_start, + print_font(screen, p_menu->p_font, 128,128,128, x_start, y_start + y, msg); else if (p_menu->cur_sel == i) /* Selected - color */ - print_font(screen, p_menu->p_font, 3, x_start, + print_font(screen, p_menu->p_font, 255,255,0, x_start, y_start + y, msg); else /* Otherwise white */ - print_font(screen, p_menu->p_font, 0, x_start, + print_font(screen, p_menu->p_font, 255,255,255, x_start, y_start + y, msg); if (IS_SUBMENU(msg)) { @@ -114,8 +125,14 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu) if (p_submenu->sel == n_pipe-1) { SDL_Rect r; - int w = p_menu->p_font->GetWidth(); - int h = p_menu->p_font->GetHeight(); + int w; + int h; + + if (TTF_SizeText(p_menu->p_font, "X", &w, &h) < 0) + { + fprintf(stderr, "%s\n", TTF_GetError()); + exit(1); + } r = (SDL_Rect) { x_start + (n+1) * w-1, y_start + (i+1 - p_menu->start_entry_visible) * ((h + h/4)-1), @@ -163,7 +180,7 @@ static int is_submenu_title(menu_t *p_menu, int n) } -void menu_init(menu_t *p_menu, Font *p_font, char **pp_msgs, +void menu_init(menu_t *p_menu, TTF_Font *p_font, char **pp_msgs, int16_t x1, int16_t y1, int16_t x2, int16_t y2) { int i; @@ -192,11 +209,15 @@ void menu_init(menu_t *p_menu, Font *p_font, char **pp_msgs, continue; /* Length of submenus is unimportant */ } - text_w_font = p_menu->p_font->GetWidth(); + if (TTF_SizeText(p_font, p_menu->pp_msgs[p_menu->n_entries], &text_w_font, NULL) != 0) + { + fprintf(stderr, "%s\n", TTF_GetError()); + exit(1); + } if (text_w_font > p_menu->text_w) p_menu->text_w = text_w_font; } - if ( !(p_menu->p_submenus = (submenu_t*)malloc(sizeof(submenu_t) * p_menu->n_submenus)) ) + if ( !(p_menu->p_submenus = (submenu_t *)malloc(sizeof(submenu_t) * p_menu->n_submenus)) ) { perror("malloc failed!\n"); exit(1); @@ -223,7 +244,7 @@ void menu_init(menu_t *p_menu, Font *p_font, char **pp_msgs, } } } - p_menu->text_h = p_menu->n_entries * (p_font->GetHeight() + p_font->GetHeight() / 4); + p_menu->text_h = p_menu->n_entries * (TTF_FontHeight(p_font) + TTF_FontHeight(p_font) / 4); } void menu_fini(menu_t *p_menu) @@ -243,7 +264,7 @@ static uint32_t wait_key_press(void) Uint32 remote_keys; WPAD_ScanPads(); - remote_keys = WPAD_ButtonsDown(WPAD_CHAN_0) | WPAD_ButtonsDown(WPAD_CHAN_1); + remote_keys = WPAD_ButtonsDown(WPAD_CHAN_0); if (remote_keys & WPAD_BUTTON_DOWN) keys |= KEY_DOWN; @@ -306,7 +327,9 @@ static uint32_t wait_key_press(void) } break; } - SDL_Delay(10); + if (keys != 0) + return keys; + SDL_Delay(100); } return keys; diff --git a/Src/menu.h b/Src/menu.h index bfb8c97..1d54fb4 100644 --- a/Src/menu.h +++ b/Src/menu.h @@ -14,7 +14,6 @@ #include #include -#include "bitmap-font.h" #include #if defined(__cplusplus) @@ -32,7 +31,7 @@ typedef struct typedef struct { char **pp_msgs; - Font *p_font; + TTF_Font *p_font; int x1,y1; int x2,y2; int text_w; @@ -47,7 +46,7 @@ typedef struct int n_entries; } menu_t; -void menu_init(menu_t *p_menu, Font *p_font, char **pp_msgs, +void menu_init(menu_t *p_menu, TTF_Font *p_font, char **pp_msgs, int16_t x1, int16_t y1, int16_t x2, int16_t y2); void menu_fini(menu_t *p_menu);