Handle kbd input, fix some drawing issues

This commit is contained in:
simon.kagstrom 2009-11-25 18:14:48 +00:00
parent 1adedb732a
commit 8303822ca9
3 changed files with 10 additions and 6 deletions

View File

@ -30,15 +30,18 @@ static void run(void)
while(1)
{
SDL_Event ev;
while (SDL_PollEvent(&ev)) {
if (ev.type == SDL_QUIT)
exit(1);
g_menu->pushEvent(&ev);
}
g_menu->runLogic();
g_menu->draw(screen, 80, 80, 400, 400);
SDL_Flip(screen);
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
SDL_Delay(50);
}
}

View File

@ -170,10 +170,11 @@ void Menu::draw(SDL_Surface *where, int x, int y, int w, int h)
}
p = (char*)xmalloc(total_chars + 1);
strncpy(p, msg, total_chars);
strncpy(p, msg, n + 1);
TTF_SizeText(this->font, p, &tw_first, &th_first);
strncpy(p, msg + n, n_chars);
memset(p, 0, total_chars + 1);
strncpy(p, msg + n, n_chars - 1);
TTF_SizeText(this->font, p, &tw, &th);
this->highlightBackground(where, x_start + tw_first,
@ -354,7 +355,7 @@ void Menu::pushEvent(SDL_Event *ev)
}
}
void Menu::setText(const char **messages)
void Menu::setText(const char **messages, int *submenu_defaults)
{
int submenu;
@ -386,7 +387,7 @@ void Menu::setText(const char **messages)
int n;
this->p_submenus[submenu].index = i;
this->p_submenus[submenu].sel = 0;
this->p_submenus[submenu].sel = submenu_defaults ? submenu_defaults[submenu] : 0;
this->p_submenus[submenu].n_entries = 0;
for (n = 0; this->pp_msgs[i][n] != '\0'; n++)
{

View File

@ -53,7 +53,7 @@ public:
this->text_bg_right = right;
}
void setText(const char **messages);
void setText(const char **messages, int *submenu_defaults = NULL);
void pushEvent(SDL_Event *ev);