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) while(1)
{ {
SDL_Event ev; SDL_Event ev;
while (SDL_PollEvent(&ev)) { while (SDL_PollEvent(&ev)) {
if (ev.type == SDL_QUIT) if (ev.type == SDL_QUIT)
exit(1); exit(1);
g_menu->pushEvent(&ev); g_menu->pushEvent(&ev);
} }
g_menu->runLogic();
g_menu->draw(screen, 80, 80, 400, 400); g_menu->draw(screen, 80, 80, 400, 400);
SDL_Flip(screen); SDL_Flip(screen);
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
SDL_Delay(50); 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); 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); 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); TTF_SizeText(this->font, p, &tw, &th);
this->highlightBackground(where, x_start + tw_first, 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; int submenu;
@ -386,7 +387,7 @@ void Menu::setText(const char **messages)
int n; int n;
this->p_submenus[submenu].index = i; 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; this->p_submenus[submenu].n_entries = 0;
for (n = 0; this->pp_msgs[i][n] != '\0'; n++) for (n = 0; this->pp_msgs[i][n] != '\0'; n++)
{ {

View File

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