mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2025-04-07 05:56:41 +02:00
Fixed the menu and display options (almost finished now!)
This commit is contained in:
parent
2a1f0637d6
commit
1e333171c6
@ -163,9 +163,9 @@ public:
|
||||
int fake_key_index;
|
||||
int fake_key_keytime;
|
||||
|
||||
void select_disc();
|
||||
void bind_key();
|
||||
void display_options();
|
||||
void select_disc(Prefs *np);
|
||||
void bind_key(Prefs *np);
|
||||
void display_options(Prefs *np);
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -22,10 +22,9 @@ static char *main_menu_messages[] = {
|
||||
"Reset C64", /* 2 */
|
||||
"Bind key to joystick",/* 3 */
|
||||
"Display options", /* 4 */
|
||||
"^|1|2",
|
||||
"Swap joysticks", /* 6 */
|
||||
"Swap joysticks", /* 5 */
|
||||
" ",
|
||||
"Quit", /* 8 */
|
||||
"Quit", /* 7 */
|
||||
NULL,
|
||||
};
|
||||
|
||||
@ -90,7 +89,7 @@ void C64::c64_ctor1(void)
|
||||
exit(1);
|
||||
}
|
||||
menu_init(&this->main_menu, this->menu_font, main_menu_messages,
|
||||
0, 0, DISPLAY_X, DISPLAY_Y);
|
||||
0, 0, FULL_DISPLAY_X, FULL_DISPLAY_Y);
|
||||
}
|
||||
|
||||
void C64::c64_ctor2(void)
|
||||
@ -108,7 +107,7 @@ void C64::c64_dtor(void)
|
||||
menu_fini(&this->main_menu);
|
||||
}
|
||||
|
||||
void C64::select_disc()
|
||||
void C64::select_disc(Prefs *np)
|
||||
{
|
||||
DIR *d = opendir(this->base_dir);
|
||||
char **file_list;
|
||||
@ -150,13 +149,12 @@ void C64::select_disc()
|
||||
closedir(d);
|
||||
|
||||
menu_init(&select_disc_menu, this->menu_font, file_list,
|
||||
0, 0, DISPLAY_X, DISPLAY_Y);
|
||||
int opt = menu_select(screen, &select_disc_menu, ~0, NULL);
|
||||
0, 0, FULL_DISPLAY_X, FULL_DISPLAY_Y);
|
||||
int opt = menu_select(real_screen, &select_disc_menu, ~0, NULL);
|
||||
if (opt >= 0)
|
||||
{
|
||||
char *name = file_list[opt];
|
||||
|
||||
Prefs *np = Frodo::reload_prefs();
|
||||
if (strcmp(file_list[opt], "None") == 0)
|
||||
{
|
||||
strcpy(np->DrivePath[0], "\0");
|
||||
@ -168,9 +166,9 @@ void C64::select_disc()
|
||||
np->DriveType[0] = DRVTYPE_D64;
|
||||
else
|
||||
np->DriveType[0] = DRVTYPE_T64;
|
||||
NewPrefs(np);
|
||||
ThePrefs = *np;
|
||||
}
|
||||
NewPrefs(np);
|
||||
ThePrefs = *np;
|
||||
}
|
||||
menu_fini(&select_disc_menu);
|
||||
|
||||
@ -182,7 +180,7 @@ void C64::select_disc()
|
||||
|
||||
#define MATRIX(a,b) (((a) << 3) | (b))
|
||||
|
||||
void C64::bind_key()
|
||||
void C64::bind_key(Prefs *np)
|
||||
{
|
||||
menu_t bind_key_menu;
|
||||
menu_t key_menu;
|
||||
@ -201,31 +199,31 @@ void C64::bind_key()
|
||||
MATRIX(1, 1), MATRIX(2, 7), MATRIX(3, 1), MATRIX(1, 4) };
|
||||
|
||||
menu_init(&bind_key_menu, this->menu_font, bind_key_messages,
|
||||
0, 0, DISPLAY_X, DISPLAY_Y);
|
||||
0, 0, FULL_DISPLAY_X, FULL_DISPLAY_Y);
|
||||
menu_init(&key_menu, this->menu_font, keys,
|
||||
0, 0, DISPLAY_X, DISPLAY_Y);
|
||||
int opt = menu_select(screen, &bind_key_menu, ~0, NULL);
|
||||
0, 0, FULL_DISPLAY_X, FULL_DISPLAY_Y);
|
||||
int opt = menu_select(real_screen, &bind_key_menu, ~0, NULL);
|
||||
if (opt >= 0)
|
||||
{
|
||||
int key = menu_select(screen, &key_menu, ~0, NULL);
|
||||
int key = menu_select(real_screen, &key_menu, ~0, NULL);
|
||||
|
||||
#if defined(GEKKO)
|
||||
ThePrefs.JoystickKeyBinding[opt] = kcs[key];
|
||||
np->JoystickKeyBinding[opt] = kcs[key];
|
||||
#endif
|
||||
}
|
||||
menu_fini(&bind_key_menu);
|
||||
menu_fini(&key_menu);
|
||||
}
|
||||
|
||||
void C64::display_options()
|
||||
void C64::display_options(Prefs *np)
|
||||
{
|
||||
menu_t display_menu;
|
||||
|
||||
menu_init(&display_menu, this->menu_font, display_option_messages,
|
||||
0, 0, DISPLAY_X, DISPLAY_Y);
|
||||
int opt = menu_select(screen, &display_menu, ~0, NULL);
|
||||
0, 0, FULL_DISPLAY_X, FULL_DISPLAY_Y);
|
||||
int opt = menu_select(real_screen, &display_menu, ~0, NULL);
|
||||
if (opt >= 0)
|
||||
ThePrefs.DisplayOption = opt;
|
||||
np->DisplayOption = opt;
|
||||
menu_fini(&display_menu);
|
||||
}
|
||||
|
||||
@ -321,8 +319,8 @@ void C64::VBlank(bool draw_frame)
|
||||
}
|
||||
uint32_t now = SDL_GetTicks();
|
||||
|
||||
if ( (now - lastFrame) < 30 ) {
|
||||
SDL_Delay( 30 - (now - lastFrame) );
|
||||
if ( (now - lastFrame) < 20 ) {
|
||||
SDL_Delay( 20 - (now - lastFrame) );
|
||||
}
|
||||
lastFrame = now;
|
||||
}
|
||||
@ -375,20 +373,18 @@ uint8 C64::poll_joystick(int port)
|
||||
Uint32 held = WPAD_ButtonsHeld(port);
|
||||
uint8 j = 0xff;
|
||||
|
||||
if (held & WPAD_BUTTON_LEFT)
|
||||
j &= 0xfb; // Left
|
||||
if (held & WPAD_BUTTON_RIGHT)
|
||||
j &= 0xf7; // Right
|
||||
if (held & WPAD_BUTTON_UP)
|
||||
j &= 0xfe; // Up
|
||||
j &= 0xfb; // Left
|
||||
if (held & WPAD_BUTTON_DOWN)
|
||||
j &= 0xf7; // Right
|
||||
if (held & WPAD_BUTTON_RIGHT)
|
||||
j &= 0xfe; // Up
|
||||
if (held & WPAD_BUTTON_LEFT)
|
||||
j &= 0xfd; // Down
|
||||
if (held & WPAD_BUTTON_2)
|
||||
j &= 0xef; // Button
|
||||
if (held & WPAD_BUTTON_HOME)
|
||||
this->enter_menu();
|
||||
if (held & WPAD_BUTTON_B)
|
||||
exit(1);
|
||||
|
||||
if ( (held & WPAD_BUTTON_A) && ThePrefs.JoystickKeyBinding[0])
|
||||
TheDisplay->FakeKeyPress(ThePrefs.JoystickKeyBinding[0],
|
||||
@ -507,12 +503,13 @@ void C64::thread_func(void)
|
||||
linecnt++;
|
||||
if (this->have_a_break) {
|
||||
int submenus[1];
|
||||
int opt = menu_select(screen, &this->main_menu, ~0, submenus);
|
||||
int opt = menu_select(real_screen, &this->main_menu, ~0, submenus);
|
||||
|
||||
Prefs *np = Frodo::reload_prefs();
|
||||
switch(opt)
|
||||
{
|
||||
case 0: /* Insert disc/tape */
|
||||
this->select_disc();
|
||||
this->select_disc(np);
|
||||
break;
|
||||
case 1: /* Load disc/tape */
|
||||
this->fake_key_sequence = true;
|
||||
@ -521,26 +518,28 @@ void C64::thread_func(void)
|
||||
Reset();
|
||||
break;
|
||||
case 3: /* Bind keys to joystick */
|
||||
this->bind_key();
|
||||
this->bind_key(np);
|
||||
break;
|
||||
case 4: /* Display options */
|
||||
this->display_options();
|
||||
this->display_options(np);
|
||||
break;
|
||||
case 6: /* Swap joysticks */
|
||||
case 5: /* Swap joysticks */
|
||||
{
|
||||
uint8 tmp = TheCIA1->Joystick1;
|
||||
TheCIA1->Joystick1 = TheCIA1->Joystick2;
|
||||
TheCIA1->Joystick2 = tmp;
|
||||
} break;
|
||||
case 8: /* Quit */
|
||||
case 7: /* Quit */
|
||||
quit_thyself = true;
|
||||
break;
|
||||
case -1:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this->have_a_break = false;
|
||||
|
||||
ThePrefs = *np;
|
||||
|
||||
this->have_a_break = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#ifdef HAVE_SDL
|
||||
struct SDL_Surface;
|
||||
extern SDL_Surface *screen;
|
||||
extern SDL_Surface *real_screen;
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
@ -38,6 +39,10 @@ const int DISPLAY_X = 0x180;
|
||||
const int DISPLAY_Y = 0x110;
|
||||
#endif
|
||||
|
||||
#if defined(GEKKO)
|
||||
const int FULL_DISPLAY_X = 640;
|
||||
const int FULL_DISPLAY_Y = 480;
|
||||
#endif
|
||||
|
||||
class C64Window;
|
||||
class C64Screen;
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
// Display surface
|
||||
SDL_Surface *screen = NULL;
|
||||
SDL_Surface *real_screen = NULL;
|
||||
|
||||
// Keyboard
|
||||
static bool num_locked = false;
|
||||
@ -60,12 +61,31 @@ enum {
|
||||
|
||||
int init_graphics(void)
|
||||
{
|
||||
Uint32 rmask, gmask, bmask, amask;
|
||||
|
||||
/* SDL interprets each pixel as a 32-bit number, so our masks must depend
|
||||
on the endianness (byte order) of the machine */
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
rmask = 0xff000000;
|
||||
gmask = 0x00ff0000;
|
||||
bmask = 0x0000ff00;
|
||||
amask = 0x000000ff;
|
||||
#else
|
||||
rmask = 0x000000ff;
|
||||
gmask = 0x0000ff00;
|
||||
bmask = 0x00ff0000;
|
||||
amask = 0xff000000;
|
||||
#endif
|
||||
|
||||
// Open window
|
||||
SDL_WM_SetCaption(VERSION_STRING, "Frodo");
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
screen = SDL_SetVideoMode(640, 480, 8,
|
||||
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, DISPLAY_X, DISPLAY_Y + 17, 8,
|
||||
rmask, gmask, bmask, amask);
|
||||
real_screen = SDL_SetVideoMode(640, 480, 8,
|
||||
SDL_DOUBLEBUF | SDL_FULLSCREEN);
|
||||
|
||||
#if 0
|
||||
screen = SDL_SetVideoMode(DISPLAY_X, DISPLAY_Y + 17, 8,
|
||||
SDL_DOUBLEBUF | SDL_FULLSCREEN);
|
||||
@ -182,7 +202,25 @@ void C64Display::Update(void)
|
||||
draw_string(screen, 24, DISPLAY_Y + 4, speedometer_string, black, fill_gray);
|
||||
|
||||
// Update display
|
||||
SDL_Flip(screen);
|
||||
SDL_Rect srcrect, dstrect;
|
||||
|
||||
if (ThePrefs.DisplayOption == 0) {
|
||||
/* Normal */
|
||||
srcrect = (SDL_Rect){0, 0, DISPLAY_X, DISPLAY_Y+17};
|
||||
dstrect = (SDL_Rect){0, 0, DISPLAY_X, DISPLAY_Y+17};
|
||||
}
|
||||
else if (ThePrefs.DisplayOption == 1) {
|
||||
/* Center, double size */
|
||||
srcrect = (SDL_Rect){28, 14, FULL_DISPLAY_X / 2, FULL_DISPLAY_Y / 2};
|
||||
dstrect = (SDL_Rect){0, 0, FULL_DISPLAY_X, FULL_DISPLAY_Y};
|
||||
}
|
||||
else {
|
||||
/* Stretch */
|
||||
srcrect = (SDL_Rect){0, 0, DISPLAY_X, DISPLAY_Y};
|
||||
dstrect = (SDL_Rect){0, 0, FULL_DISPLAY_X, FULL_DISPLAY_Y};
|
||||
}
|
||||
SDL_SoftStretch(screen, &srcrect, real_screen, &dstrect);
|
||||
SDL_Flip(real_screen);
|
||||
}
|
||||
|
||||
|
||||
@ -541,6 +579,8 @@ void C64Display::InitColors(uint8 *colors)
|
||||
palette[green].g = 0xf0;
|
||||
palette[green].r = palette[green].b = 0;
|
||||
SDL_SetColors(screen, palette, 0, PALETTE_SIZE);
|
||||
SDL_SetColors(real_screen, palette, 0, PALETTE_SIZE);
|
||||
|
||||
|
||||
for (int i=0; i<256; i++)
|
||||
colors[i] = i & 0x0f;
|
||||
|
85
Src/menu.cpp
85
Src/menu.cpp
@ -49,7 +49,7 @@ static void print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b,
|
||||
SDL_Rect dst = {x, y, 0, 0};
|
||||
SDL_Color color = {r, g, b};
|
||||
char buf[255];
|
||||
int i;
|
||||
unsigned int i;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strncpy(buf, msg, 254);
|
||||
@ -81,7 +81,6 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu)
|
||||
int y_start = p_menu->y1 + (p_menu->y2 - p_menu->y1) / 2 - p_menu->text_h / 2;
|
||||
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;
|
||||
int i;
|
||||
|
||||
@ -267,18 +266,18 @@ static uint32_t wait_key_press(void)
|
||||
remote_keys = WPAD_ButtonsDown(WPAD_CHAN_0);
|
||||
|
||||
if (remote_keys & WPAD_BUTTON_DOWN)
|
||||
keys |= KEY_DOWN;
|
||||
if (remote_keys & WPAD_BUTTON_UP)
|
||||
keys |= KEY_UP;
|
||||
if (remote_keys & WPAD_BUTTON_LEFT)
|
||||
keys |= KEY_LEFT;
|
||||
if (remote_keys & WPAD_BUTTON_RIGHT)
|
||||
keys |= KEY_RIGHT;
|
||||
if (remote_keys & WPAD_BUTTON_UP)
|
||||
keys |= KEY_LEFT;
|
||||
if (remote_keys & WPAD_BUTTON_LEFT)
|
||||
keys |= KEY_DOWN;
|
||||
if (remote_keys & WPAD_BUTTON_RIGHT)
|
||||
keys |= KEY_UP;
|
||||
if (remote_keys & WPAD_BUTTON_PLUS)
|
||||
keys |= KEY_PAGEUP;
|
||||
if (remote_keys & WPAD_BUTTON_MINUS)
|
||||
keys |= KEY_PAGEDOWN;
|
||||
if (remote_keys & (WPAD_BUTTON_A | WPAD_BUTTON_1) )
|
||||
if (remote_keys & (WPAD_BUTTON_A | WPAD_BUTTON_2) )
|
||||
keys |= KEY_SELECT;
|
||||
if (remote_keys & (WPAD_BUTTON_1 | WPAD_BUTTON_HOME) )
|
||||
keys |= KEY_ESCAPE;
|
||||
@ -339,46 +338,48 @@ static uint32_t wait_key_press(void)
|
||||
int menu_select(SDL_Surface *screen, menu_t *p_menu,
|
||||
uint32_t available_options, int *p_submenus)
|
||||
{
|
||||
p_menu->available_options = available_options;
|
||||
int ret = -1;
|
||||
|
||||
while(1)
|
||||
{
|
||||
uint32_t keys;
|
||||
p_menu->available_options = available_options;
|
||||
|
||||
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
|
||||
menu_draw(screen, p_menu);
|
||||
SDL_Flip(screen);
|
||||
|
||||
keys = wait_key_press();
|
||||
|
||||
if (keys & KEY_UP)
|
||||
select_next(p_menu, 0, -1);
|
||||
else if (keys & KEY_DOWN)
|
||||
select_next(p_menu, 0, 1);
|
||||
else if (keys & KEY_LEFT)
|
||||
select_next(p_menu, -1, 0);
|
||||
else if (keys & KEY_RIGHT)
|
||||
select_next(p_menu, 1, 0);
|
||||
else if (keys & KEY_ESCAPE)
|
||||
return -1;
|
||||
else if (keys & KEY_SELECT)
|
||||
while(1)
|
||||
{
|
||||
int ret = p_menu->cur_sel;
|
||||
int i;
|
||||
uint32_t keys;
|
||||
|
||||
if (!is_submenu_title(p_menu, ret))
|
||||
{
|
||||
for (i=0; i<p_menu->n_submenus; i++)
|
||||
p_submenus[i] = p_menu->p_submenus[i].sel;
|
||||
p_menu->cur_sel = 0;
|
||||
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
|
||||
return ret;
|
||||
}
|
||||
menu_draw(screen, p_menu);
|
||||
SDL_Flip(screen);
|
||||
|
||||
keys = wait_key_press();
|
||||
|
||||
if (keys & KEY_UP)
|
||||
select_next(p_menu, 0, -1);
|
||||
else if (keys & KEY_DOWN)
|
||||
select_next(p_menu, 0, 1);
|
||||
else if (keys & KEY_LEFT)
|
||||
select_next(p_menu, -1, 0);
|
||||
else if (keys & KEY_RIGHT)
|
||||
select_next(p_menu, 1, 0);
|
||||
else if (keys & KEY_ESCAPE)
|
||||
break;
|
||||
else if (keys & KEY_SELECT)
|
||||
{
|
||||
ret = p_menu->cur_sel;
|
||||
int i;
|
||||
|
||||
if (!is_submenu_title(p_menu, ret))
|
||||
{
|
||||
for (i=0; i<p_menu->n_submenus; i++)
|
||||
p_submenus[i] = p_menu->p_submenus[i].sel;
|
||||
p_menu->cur_sel = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(TEST_MENU)
|
||||
|
Loading…
x
Reference in New Issue
Block a user