mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-22 19:39:24 +01:00
Simplified menu code
This commit is contained in:
parent
1646301ba4
commit
a2725ef19f
@ -183,7 +183,6 @@ public:
|
|||||||
double speed_index;
|
double speed_index;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SDL
|
#ifdef HAVE_SDL
|
||||||
menu_t main_menu;
|
|
||||||
VirtualKeyboard *virtual_keyboard;
|
VirtualKeyboard *virtual_keyboard;
|
||||||
TTF_Font *menu_font;
|
TTF_Font *menu_font;
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct timeval tv_start;
|
static struct timeval tv_start;
|
||||||
static int MENU_SIZE_X, MENU_SIZE_Y;
|
|
||||||
static const char *main_menu_messages[] = {
|
static const char *main_menu_messages[] = {
|
||||||
"Invoke key sequence", /* 0 */
|
"Invoke key sequence", /* 0 */
|
||||||
"Insert disc or tape", /* 1 */
|
"Insert disc or tape", /* 1 */
|
||||||
@ -78,9 +77,6 @@ void C64::c64_ctor1(void)
|
|||||||
memset(this->save_game_name, 0, sizeof(this->save_game_name));
|
memset(this->save_game_name, 0, sizeof(this->save_game_name));
|
||||||
strcpy(this->save_game_name, "unknown");
|
strcpy(this->save_game_name, "unknown");
|
||||||
|
|
||||||
MENU_SIZE_X = FULL_DISPLAY_X - FULL_DISPLAY_X / 4;
|
|
||||||
MENU_SIZE_Y = FULL_DISPLAY_Y - FULL_DISPLAY_Y / 4;
|
|
||||||
|
|
||||||
SDL_RWops *rw;
|
SDL_RWops *rw;
|
||||||
|
|
||||||
Uint8 *data = (Uint8*)malloc(1 * 1024*1024);
|
Uint8 *data = (Uint8*)malloc(1 * 1024*1024);
|
||||||
@ -102,8 +98,6 @@ void C64::c64_ctor1(void)
|
|||||||
fprintf(stderr, "Unable to open font\n" );
|
fprintf(stderr, "Unable to open font\n" );
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
menu_init(&this->main_menu, this->menu_font, main_menu_messages,
|
|
||||||
32, 32, MENU_SIZE_X, MENU_SIZE_Y);
|
|
||||||
|
|
||||||
this->virtual_keyboard = new VirtualKeyboard(real_screen, this->menu_font);
|
this->virtual_keyboard = new VirtualKeyboard(real_screen, this->menu_font);
|
||||||
}
|
}
|
||||||
@ -120,7 +114,6 @@ void C64::c64_ctor2(void)
|
|||||||
|
|
||||||
void C64::c64_dtor(void)
|
void C64::c64_dtor(void)
|
||||||
{
|
{
|
||||||
menu_fini(&this->main_menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmpstringp(const void *p1, const void *p2)
|
static int cmpstringp(const void *p1, const void *p2)
|
||||||
@ -189,14 +182,12 @@ static const char **get_file_list(const char *base_dir)
|
|||||||
void C64::select_disc(Prefs *np)
|
void C64::select_disc(Prefs *np)
|
||||||
{
|
{
|
||||||
const char **file_list = get_file_list(IMAGE_PATH);
|
const char **file_list = get_file_list(IMAGE_PATH);
|
||||||
menu_t select_disc_menu;
|
|
||||||
|
|
||||||
if (file_list == NULL)
|
if (file_list == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
menu_init(&select_disc_menu, this->menu_font, file_list,
|
int opt = menu_select(real_screen, this->menu_font,
|
||||||
32, 32, MENU_SIZE_X, MENU_SIZE_Y);
|
file_list, NULL);
|
||||||
int opt = menu_select(real_screen, &select_disc_menu, NULL);
|
|
||||||
if (opt >= 0)
|
if (opt >= 0)
|
||||||
{
|
{
|
||||||
const char *name = file_list[opt];
|
const char *name = file_list[opt];
|
||||||
@ -247,7 +238,6 @@ void C64::select_disc(Prefs *np)
|
|||||||
}
|
}
|
||||||
this->prefs_changed = true;
|
this->prefs_changed = true;
|
||||||
}
|
}
|
||||||
menu_fini(&select_disc_menu);
|
|
||||||
|
|
||||||
/* Cleanup everything */
|
/* Cleanup everything */
|
||||||
for ( int i = 0; file_list[i]; i++ )
|
for ( int i = 0; file_list[i]; i++ )
|
||||||
@ -275,8 +265,6 @@ void C64::bind_keys(Prefs *np)
|
|||||||
{
|
{
|
||||||
const char *bind_key_messages[N_WIIMOTE_BINDINGS + 1];
|
const char *bind_key_messages[N_WIIMOTE_BINDINGS + 1];
|
||||||
bool has_classic_controller = false;
|
bool has_classic_controller = false;
|
||||||
menu_t bind_key_menu;
|
|
||||||
menu_t key_menu;
|
|
||||||
|
|
||||||
#if defined(GEKKO)
|
#if defined(GEKKO)
|
||||||
WPADData *wpad, *wpad_other;
|
WPADData *wpad, *wpad_other;
|
||||||
@ -294,9 +282,8 @@ void C64::bind_keys(Prefs *np)
|
|||||||
for (int i = 0; i < (has_classic_controller ? N_WIIMOTE_BINDINGS : 5); i++)
|
for (int i = 0; i < (has_classic_controller ? N_WIIMOTE_BINDINGS : 5); i++)
|
||||||
bind_key_messages[i] = this->bind_one_key(np, i);
|
bind_key_messages[i] = this->bind_one_key(np, i);
|
||||||
|
|
||||||
menu_init(&bind_key_menu, this->menu_font, bind_key_messages,
|
int opt = menu_select(real_screen, this->menu_font,
|
||||||
32, 32, MENU_SIZE_X, MENU_SIZE_Y);
|
bind_key_messages, NULL);
|
||||||
int opt = menu_select(real_screen, &bind_key_menu, NULL);
|
|
||||||
if (opt >= 0)
|
if (opt >= 0)
|
||||||
{
|
{
|
||||||
int key;
|
int key;
|
||||||
@ -310,12 +297,10 @@ void C64::bind_keys(Prefs *np)
|
|||||||
np->JoystickKeyBinding[opt] = key;
|
np->JoystickKeyBinding[opt] = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu_fini(&bind_key_menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void C64::other_options(Prefs *np)
|
void C64::other_options(Prefs *np)
|
||||||
{
|
{
|
||||||
menu_t display_menu;
|
|
||||||
int submenus[3] = { np->DisplayOption, 0, !np->Emul1541Proc };
|
int submenus[3] = { np->DisplayOption, 0, !np->Emul1541Proc };
|
||||||
|
|
||||||
#define SPEED_95 33
|
#define SPEED_95 33
|
||||||
@ -332,9 +317,8 @@ void C64::other_options(Prefs *np)
|
|||||||
/* If it has some other value... */
|
/* If it has some other value... */
|
||||||
submenus[1] = 1; break;
|
submenus[1] = 1; break;
|
||||||
}
|
}
|
||||||
menu_init(&display_menu, this->menu_font, other_options_messages,
|
int opt = menu_select(real_screen, this->menu_font,
|
||||||
32, 32, MENU_SIZE_X, MENU_SIZE_Y);
|
other_options_messages, submenus);
|
||||||
int opt = menu_select(real_screen, &display_menu, submenus);
|
|
||||||
if (opt >= 0)
|
if (opt >= 0)
|
||||||
{
|
{
|
||||||
np->DisplayOption = submenus[0];
|
np->DisplayOption = submenus[0];
|
||||||
@ -352,7 +336,6 @@ void C64::other_options(Prefs *np)
|
|||||||
}
|
}
|
||||||
this->prefs_changed = true;
|
this->prefs_changed = true;
|
||||||
}
|
}
|
||||||
menu_fini(&display_menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* From dreamcast port but heavily modified */
|
/* From dreamcast port but heavily modified */
|
||||||
@ -398,14 +381,10 @@ void C64::select_fake_key_sequence(Prefs *np)
|
|||||||
"10 PRINT \"HELLO WORLD\" and 20 GOTO 10",
|
"10 PRINT \"HELLO WORLD\" and 20 GOTO 10",
|
||||||
"Type with virtual keyboard",
|
"Type with virtual keyboard",
|
||||||
NULL};
|
NULL};
|
||||||
menu_t fake_key_menu;
|
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
menu_init(&fake_key_menu, this->menu_font, fake_key_messages,
|
opt = menu_select(real_screen, this->menu_font,
|
||||||
32, 32, MENU_SIZE_X, MENU_SIZE_Y);
|
fake_key_messages, NULL);
|
||||||
|
|
||||||
opt = menu_select(real_screen, &fake_key_menu, NULL);
|
|
||||||
menu_fini(&fake_key_menu);
|
|
||||||
if (opt < 0)
|
if (opt < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -422,12 +401,8 @@ void C64::select_fake_key_sequence(Prefs *np)
|
|||||||
|
|
||||||
void C64::save_load_state(Prefs *np)
|
void C64::save_load_state(Prefs *np)
|
||||||
{
|
{
|
||||||
menu_t save_load_menu;
|
int opt = menu_select(real_screen, this->menu_font,
|
||||||
menu_t select_saves_menu;
|
save_load_state_messages, NULL);
|
||||||
|
|
||||||
menu_init(&save_load_menu, this->menu_font, save_load_state_messages,
|
|
||||||
32, 32, MENU_SIZE_X, MENU_SIZE_Y);
|
|
||||||
int opt = menu_select(real_screen, &save_load_menu, NULL);
|
|
||||||
switch(opt)
|
switch(opt)
|
||||||
{
|
{
|
||||||
case 1: /* save */
|
case 1: /* save */
|
||||||
@ -449,9 +424,8 @@ void C64::save_load_state(Prefs *np)
|
|||||||
|
|
||||||
if (file_list == NULL)
|
if (file_list == NULL)
|
||||||
break;
|
break;
|
||||||
menu_init(&select_saves_menu, this->menu_font, file_list,
|
int save = menu_select(real_screen, this->menu_font,
|
||||||
32, 32, MENU_SIZE_X, MENU_SIZE_Y);
|
file_list, NULL);
|
||||||
int save = menu_select(real_screen, &select_saves_menu, NULL);
|
|
||||||
if (save >= 0)
|
if (save >= 0)
|
||||||
{
|
{
|
||||||
char save_buf[255];
|
char save_buf[255];
|
||||||
@ -471,7 +445,6 @@ void C64::save_load_state(Prefs *np)
|
|||||||
this->prefs_changed = true;
|
this->prefs_changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu_fini(&select_saves_menu);
|
|
||||||
|
|
||||||
/* Cleanup everything */
|
/* Cleanup everything */
|
||||||
for ( int i = 0; file_list[i]; i++ )
|
for ( int i = 0; file_list[i]; i++ )
|
||||||
@ -481,7 +454,6 @@ void C64::save_load_state(Prefs *np)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
menu_fini(&save_load_menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -575,7 +547,8 @@ void C64::VBlank(bool draw_frame)
|
|||||||
|
|
||||||
TheSID->PauseSound();
|
TheSID->PauseSound();
|
||||||
submenus[0] = old_swap;
|
submenus[0] = old_swap;
|
||||||
opt = menu_select(real_screen, &this->main_menu, submenus);
|
opt = menu_select(real_screen, this->menu_font,
|
||||||
|
main_menu_messages, submenus);
|
||||||
|
|
||||||
switch(opt)
|
switch(opt)
|
||||||
{
|
{
|
||||||
|
51
Src/menu.cpp
51
Src/menu.cpp
@ -16,8 +16,35 @@
|
|||||||
# include <wiiuse/wpad.h>
|
# include <wiiuse/wpad.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "sysdeps.h"
|
||||||
|
#include "Display.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int n_entries;
|
||||||
|
int index;
|
||||||
|
int sel;
|
||||||
|
} submenu_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
const char **pp_msgs;
|
||||||
|
TTF_Font *p_font;
|
||||||
|
int x1,y1;
|
||||||
|
int x2,y2;
|
||||||
|
int text_w;
|
||||||
|
int text_h;
|
||||||
|
|
||||||
|
int n_submenus;
|
||||||
|
submenu_t *p_submenus;
|
||||||
|
|
||||||
|
int cur_sel; /* Main selection */
|
||||||
|
int start_entry_visible;
|
||||||
|
int n_entries;
|
||||||
|
} menu_t;
|
||||||
|
|
||||||
#define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' )
|
#define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' )
|
||||||
|
|
||||||
static submenu_t *find_submenu(menu_t *p_menu, int index)
|
static submenu_t *find_submenu(menu_t *p_menu, int index)
|
||||||
@ -173,7 +200,7 @@ static int is_submenu_title(menu_t *p_menu, int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void menu_init(menu_t *p_menu, TTF_Font *p_font, const char **pp_msgs,
|
static void menu_init(menu_t *p_menu, TTF_Font *p_font, const char **pp_msgs,
|
||||||
int16_t x1, int16_t y1, int16_t x2, int16_t y2)
|
int16_t x1, int16_t y1, int16_t x2, int16_t y2)
|
||||||
{
|
{
|
||||||
int submenu;
|
int submenu;
|
||||||
@ -242,7 +269,7 @@ void menu_init(menu_t *p_menu, TTF_Font *p_font, const char **pp_msgs,
|
|||||||
p_menu->text_h = p_menu->n_entries * (TTF_FontHeight(p_font) + TTF_FontHeight(p_font) / 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)
|
static void menu_fini(menu_t *p_menu)
|
||||||
{
|
{
|
||||||
free(p_menu->p_submenus);
|
free(p_menu->p_submenus);
|
||||||
}
|
}
|
||||||
@ -359,8 +386,8 @@ uint32_t menu_wait_key_press(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int menu_select(SDL_Surface *screen, menu_t *p_menu,
|
static int menu_select_internal(SDL_Surface *screen,
|
||||||
int *p_submenus)
|
menu_t *p_menu, int *p_submenus)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -407,6 +434,22 @@ int menu_select(SDL_Surface *screen, menu_t *p_menu,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int menu_select(SDL_Surface *screen, TTF_Font *font, const char **msgs,
|
||||||
|
int *submenus)
|
||||||
|
{
|
||||||
|
menu_t menu;
|
||||||
|
int out;
|
||||||
|
|
||||||
|
menu_init(&menu, font, msgs,
|
||||||
|
32, 32, FULL_DISPLAY_X - FULL_DISPLAY_X / 4,
|
||||||
|
FULL_DISPLAY_Y - FULL_DISPLAY_Y / 4);
|
||||||
|
out = menu_select_internal(screen, &menu, submenus);
|
||||||
|
menu_fini(&menu);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(TEST_MENU)
|
#if defined(TEST_MENU)
|
||||||
char *main_menu[] = {
|
char *main_menu[] = {
|
||||||
"Insert disc",
|
"Insert disc",
|
||||||
|
31
Src/menu.h
31
Src/menu.h
@ -29,39 +29,10 @@ extern "C" {
|
|||||||
#define KEY_PAGEDOWN 64
|
#define KEY_PAGEDOWN 64
|
||||||
#define KEY_PAGEUP 128
|
#define KEY_PAGEUP 128
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int n_entries;
|
|
||||||
int index;
|
|
||||||
int sel;
|
|
||||||
} submenu_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
const char **pp_msgs;
|
|
||||||
TTF_Font *p_font;
|
|
||||||
int x1,y1;
|
|
||||||
int x2,y2;
|
|
||||||
int text_w;
|
|
||||||
int text_h;
|
|
||||||
|
|
||||||
int n_submenus;
|
|
||||||
submenu_t *p_submenus;
|
|
||||||
|
|
||||||
int cur_sel; /* Main selection */
|
|
||||||
int start_entry_visible;
|
|
||||||
int n_entries;
|
|
||||||
} menu_t;
|
|
||||||
|
|
||||||
void menu_print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b,
|
void menu_print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b,
|
||||||
int x, int y, const char *msg);
|
int x, int y, const char *msg);
|
||||||
|
|
||||||
void menu_init(menu_t *p_menu, TTF_Font *p_font, const char **pp_msgs,
|
int menu_select(SDL_Surface *screen, TTF_Font *font, const char **pp_msgs,
|
||||||
int16_t x1, int16_t y1, int16_t x2, int16_t y2);
|
|
||||||
void menu_fini(menu_t *p_menu);
|
|
||||||
|
|
||||||
int menu_select(SDL_Surface *screen, menu_t *p_menu,
|
|
||||||
int *p_submenus);
|
int *p_submenus);
|
||||||
|
|
||||||
uint32_t menu_wait_key_press(void);
|
uint32_t menu_wait_key_press(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user