(Untested) refactor menu code a bit - move stuff to menu.c instead

This commit is contained in:
simon.kagstrom 2009-11-02 06:36:25 +00:00
parent 2ee1b5a907
commit 45ee58ac8d
3 changed files with 35 additions and 9 deletions

View File

@ -1072,12 +1072,6 @@ network_connection_error_t Network::WaitForPeerList()
return SERVER_GARBAGE_ERROR;
pi = (NetworkUpdateListPeers *)this->ud->data;
msgs = (const char**)calloc(pi->n_peers + 2, sizeof(const char*));
msgs[0] = "None (wait for peer to connect)";
printf("Got %d peers\n", pi->n_peers);
for (int i = 0; i < pi->n_peers; i++) {
msgs[i + 1] = (const char*)pi->peers[i].name;
#if 0
if (pi->peers[i].version != FRODO_NETWORK_PROTOCOL_VERSION)
{
@ -1085,9 +1079,7 @@ network_connection_error_t Network::WaitForPeerList()
return VERSION_ERROR;
}
#endif
}
int sel = menu_select(msgs, NULL);
free(msgs);
int sel = menu_select_peer(pi->peers, pi->n_peers);
/* FIXME! What to do here??? */
if (sel < 0)

View File

@ -18,6 +18,7 @@
#include "sysdeps.h"
#include "Display.h"
#include "Network.h"
#include "menu.h"
#include "menutexts.h"
@ -45,6 +46,9 @@ typedef struct
int cur_sel; /* Main selection */
int start_entry_visible;
int n_entries;
NetworkUpdatePeerInfo *peers;
int n_peers;
} menu_t;
#define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' )
@ -606,6 +610,8 @@ static void menu_init(menu_t *p_menu, const char *title, TTF_Font *p_font, const
p_menu->text_w = 0;
p_menu->n_submenus = 0;
p_menu->peers = NULL;
p_menu->n_peers = 0;
strcpy(p_menu->title, title);
for (p_menu->n_entries = 0; p_menu->pp_msgs[p_menu->n_entries]; p_menu->n_entries++)
@ -878,6 +884,33 @@ int menu_select(const char **msgs, int *submenus)
return menu_select("", msgs, submenus);
}
int menu_select_peer(NetworkUpdatePeerInfo *peers, int n_peers)
{
menu_t menu;
int out;
const char **msgs;
msgs = (const char**)calloc(n_peers + 2, sizeof(const char*));
msgs[0] = "None (wait for peer to connect)";
printf("Got %d peers\n", n_peers);
for (int i = 0; i < n_peers; i++)
msgs[i + 1] = (const char*)peers[i].name;
menu_init(&menu, "", menu_font, msgs,
32, 32, FULL_DISPLAY_X-32, FULL_DISPLAY_Y-64);
menu.peers = peers;
menu.n_peers = n_peers;
out = menu_select_internal(real_screen, &menu, NULL, 0,
NULL, NULL);
menu_fini(&menu);
free(msgs);
return out;
}
extern "C" const char **DirD64(const char *FileName);
static void d64_list_cb(menu_t *p, void *data)

View File

@ -36,6 +36,7 @@ int menu_select_sized(char *title, const char **msgs, int *submenus,
int x, int y, int w, int h);
const char *menu_select_file(const char *dir_path);
const char *menu_select_file_start(const char *dir_path, const char **d64_name);
int menu_select_peer(NetworkUpdatePeerInfo *peers, int n_peers);
uint32_t menu_wait_key_press(void);