mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2025-02-16 20:39:15 +01:00
Make speed configurable, fixed menu bug
This commit is contained in:
parent
fb75a3b5a7
commit
51274ed2f3
@ -1,4 +1,9 @@
|
||||
version 3:
|
||||
* Fixed a bug in the menu code which was triggered when there
|
||||
is more than one submenu
|
||||
|
||||
* Make speed configurable and change the menus a bit
|
||||
|
||||
* Skip SDL_Delay and SDL_GetTicks() which seem to give strange
|
||||
results. Use gettime and usleep instead.
|
||||
|
||||
|
@ -171,7 +171,7 @@ public:
|
||||
|
||||
void select_disc(Prefs *np);
|
||||
void bind_key(Prefs *np);
|
||||
void display_options(Prefs *np);
|
||||
void other_options(Prefs *np);
|
||||
void save_load_state(Prefs *np);
|
||||
#endif
|
||||
|
||||
|
@ -23,7 +23,6 @@
|
||||
#define IMAGE_PATH "images"
|
||||
#define TMP_PATH "tmp"
|
||||
#endif
|
||||
#define MS_PER_FRAME 38
|
||||
|
||||
static struct timeval tv_start;
|
||||
static int MENU_SIZE_X, MENU_SIZE_Y;
|
||||
@ -32,7 +31,7 @@ static const char *main_menu_messages[] = {
|
||||
"Load disc or tape", /* 1 */
|
||||
"Reset C64", /* 2 */
|
||||
"Bind key to joystick",/* 3 */
|
||||
"Display options", /* 4 */
|
||||
"Other options", /* 4 */
|
||||
"Controller 1 joystick port", /* 5 */
|
||||
"^|1|2",
|
||||
"Save/Load state", /* 7 */
|
||||
@ -41,9 +40,11 @@ static const char *main_menu_messages[] = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const char *display_option_messages[] = {
|
||||
"double resolution, centered", /* 0 */
|
||||
"full-screen stretched", /* 1 */
|
||||
static const char *other_options_messages[] = {
|
||||
"Display resolution", /* 0 */
|
||||
"^|double-center|stretched",
|
||||
"Speed (approx)", /* 2 */
|
||||
"^|95|100|110",
|
||||
NULL,
|
||||
};
|
||||
|
||||
@ -339,16 +340,36 @@ void C64::bind_key(Prefs *np)
|
||||
free(bind_key_messages);
|
||||
}
|
||||
|
||||
void C64::display_options(Prefs *np)
|
||||
void C64::other_options(Prefs *np)
|
||||
{
|
||||
menu_t display_menu;
|
||||
int submenus[2] = { np->DisplayOption};
|
||||
|
||||
menu_init(&display_menu, this->menu_font, display_option_messages,
|
||||
switch (np->MsPerFrame)
|
||||
{
|
||||
case 36:
|
||||
submenus[1] = 0; break;
|
||||
case 38:
|
||||
submenus[1] = 1; break;
|
||||
default:
|
||||
submenus[1] = 2; break;
|
||||
}
|
||||
menu_init(&display_menu, this->menu_font, other_options_messages,
|
||||
32, 32, MENU_SIZE_X, MENU_SIZE_Y);
|
||||
int opt = menu_select(real_screen, &display_menu, NULL);
|
||||
int opt = menu_select(real_screen, &display_menu, submenus);
|
||||
if (opt >= 0)
|
||||
{
|
||||
np->DisplayOption = opt;
|
||||
np->DisplayOption = submenus[0];
|
||||
switch(submenus[1])
|
||||
{
|
||||
case 0:
|
||||
np->MsPerFrame = 36; break;
|
||||
case 1:
|
||||
np->MsPerFrame = 38; break;
|
||||
case 2:
|
||||
default:
|
||||
np->MsPerFrame = 39; break;
|
||||
}
|
||||
this->prefs_changed = true;
|
||||
}
|
||||
menu_fini(&display_menu);
|
||||
@ -543,8 +564,8 @@ void C64::VBlank(bool draw_frame)
|
||||
case 3: /* Bind keys to joystick */
|
||||
this->bind_key(&np);
|
||||
break;
|
||||
case 4: /* Display options */
|
||||
this->display_options(&np);
|
||||
case 4: /* Other options */
|
||||
this->other_options(&np);
|
||||
break;
|
||||
case 5: /* Swap joysticks */
|
||||
break;
|
||||
@ -585,8 +606,8 @@ void C64::VBlank(bool draw_frame)
|
||||
uint32_t now = SDL_GetTicks();
|
||||
#endif
|
||||
|
||||
if ( (now - lastFrame) < MS_PER_FRAME ) {
|
||||
usleep( (MS_PER_FRAME - (now - lastFrame)) * 1000);
|
||||
if ( (now - lastFrame) < ThePrefs.MsPerFrame) {
|
||||
usleep( (ThePrefs.MsPerFrame - (now - lastFrame)) * 1000);
|
||||
}
|
||||
lastFrame = now;
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ Prefs::Prefs()
|
||||
this->JoystickKeyBinding[i] = -1;
|
||||
|
||||
this->DisplayOption = 0;
|
||||
this->MsPerFrame = 38;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -148,6 +149,7 @@ bool Prefs::operator==(const Prefs &rhs) const
|
||||
&& this->JoystickKeyBinding[11] == rhs.JoystickKeyBinding[11]
|
||||
&& this->JoystickKeyBinding[12] == rhs.JoystickKeyBinding[12]
|
||||
&& this->DisplayOption == rhs.DisplayOption
|
||||
&& this->MsPerFrame == rhs.MsPerFrame
|
||||
#endif
|
||||
);
|
||||
}
|
||||
@ -342,6 +344,8 @@ void Prefs::Load(char *filename)
|
||||
JoystickKeyBinding[12] = atoi(value);
|
||||
else if (!strcmp(keyword, "DisplayOption"))
|
||||
DisplayOption = atoi(value);
|
||||
else if (!strcmp(keyword, "MsPerFrame"))
|
||||
MsPerFrame = atoi(value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -445,6 +449,7 @@ bool Prefs::Save(char *filename)
|
||||
i, JoystickKeyBinding[i]);
|
||||
|
||||
fprintf(file, "DisplayOption = %d\n", DisplayOption);
|
||||
fprintf(file, "MsPerFrame = %d\n", MsPerFrame);
|
||||
#endif
|
||||
fclose(file);
|
||||
ThePrefsOnDisk = *this;
|
||||
|
@ -136,6 +136,7 @@ private:
|
||||
#ifdef HAVE_SDL
|
||||
int JoystickKeyBinding[N_WIIMOTE_BINDINGS];
|
||||
int DisplayOption;
|
||||
int MsPerFrame;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
111
Src/menu.cpp
111
Src/menu.cpp
@ -185,71 +185,70 @@ 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,
|
||||
int16_t x1, int16_t y1, int16_t x2, int16_t y2)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int submenu;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
memset(p_menu, 0, sizeof(menu_t));
|
||||
memset(p_menu, 0, sizeof(menu_t));
|
||||
|
||||
p_menu->pp_msgs = pp_msgs;
|
||||
p_menu->p_font = p_font;
|
||||
p_menu->x1 = x1;
|
||||
p_menu->y1 = y1;
|
||||
p_menu->x2 = x2;
|
||||
p_menu->y2 = y2;
|
||||
p_menu->pp_msgs = pp_msgs;
|
||||
p_menu->p_font = p_font;
|
||||
p_menu->x1 = x1;
|
||||
p_menu->y1 = y1;
|
||||
p_menu->x2 = x2;
|
||||
p_menu->y2 = y2;
|
||||
|
||||
p_menu->text_w = 0;
|
||||
p_menu->n_submenus = 0;
|
||||
p_menu->text_w = 0;
|
||||
p_menu->n_submenus = 0;
|
||||
|
||||
for (p_menu->n_entries = 0; p_menu->pp_msgs[p_menu->n_entries]; p_menu->n_entries++)
|
||||
{
|
||||
int text_w_font;
|
||||
|
||||
/* Is this a submenu? */
|
||||
if (IS_SUBMENU(p_menu->pp_msgs[p_menu->n_entries]))
|
||||
for (p_menu->n_entries = 0; p_menu->pp_msgs[p_menu->n_entries]; p_menu->n_entries++)
|
||||
{
|
||||
p_menu->n_submenus++;
|
||||
continue; /* Length of submenus is unimportant */
|
||||
}
|
||||
int text_w_font;
|
||||
|
||||
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->text_w > p_menu->x2 - p_menu->x1)
|
||||
p_menu->text_w = p_menu->x2 - p_menu->x1;
|
||||
|
||||
if ( !(p_menu->p_submenus = (submenu_t *)malloc(sizeof(submenu_t) * p_menu->n_submenus)) )
|
||||
{
|
||||
perror("malloc failed!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
j=0;
|
||||
for (i=0; i<p_menu->n_submenus; i++)
|
||||
{
|
||||
|
||||
for (; j < p_menu->n_entries; j++)
|
||||
{
|
||||
if (IS_SUBMENU(p_menu->pp_msgs[j]))
|
||||
{
|
||||
int n;
|
||||
|
||||
p_menu->p_submenus[i].index = j;
|
||||
p_menu->p_submenus[i].sel = 0;
|
||||
p_menu->p_submenus[i].n_entries = 0;
|
||||
for (n=0; p_menu->pp_msgs[j][n] != '\0'; n++)
|
||||
/* Is this a submenu? */
|
||||
if (IS_SUBMENU(p_menu->pp_msgs[p_menu->n_entries]))
|
||||
{
|
||||
if (p_menu->pp_msgs[j][n] == '|')
|
||||
p_menu->p_submenus[i].n_entries++;
|
||||
p_menu->n_submenus++;
|
||||
continue; /* Length of submenus is unimportant */
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
p_menu->text_h = p_menu->n_entries * (TTF_FontHeight(p_font) + TTF_FontHeight(p_font) / 4);
|
||||
if (p_menu->text_w > p_menu->x2 - p_menu->x1)
|
||||
p_menu->text_w = p_menu->x2 - p_menu->x1;
|
||||
|
||||
if ( !(p_menu->p_submenus = (submenu_t *)malloc(sizeof(submenu_t) * p_menu->n_submenus)) )
|
||||
{
|
||||
perror("malloc failed!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
j=0;
|
||||
submenu = 0;
|
||||
for (; j < p_menu->n_entries; j++)
|
||||
{
|
||||
if (IS_SUBMENU(p_menu->pp_msgs[j]))
|
||||
{
|
||||
int n;
|
||||
|
||||
p_menu->p_submenus[submenu].index = j;
|
||||
p_menu->p_submenus[submenu].sel = 0;
|
||||
p_menu->p_submenus[submenu].n_entries = 0;
|
||||
for (n=0; p_menu->pp_msgs[j][n] != '\0'; n++)
|
||||
{
|
||||
if (p_menu->pp_msgs[j][n] == '|')
|
||||
p_menu->p_submenus[submenu].n_entries++;
|
||||
}
|
||||
submenu++;
|
||||
}
|
||||
}
|
||||
p_menu->text_h = p_menu->n_entries * (TTF_FontHeight(p_font) + TTF_FontHeight(p_font) / 4);
|
||||
}
|
||||
|
||||
void menu_fini(menu_t *p_menu)
|
||||
|
Loading…
x
Reference in New Issue
Block a user