From 8303822ca9d945f29aa9fe8dece7db9d02e38ca8 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Wed, 25 Nov 2009 18:14:48 +0000 Subject: [PATCH] Handle kbd input, fix some drawing issues --- main.cpp | 5 ++++- menu.cpp | 9 +++++---- menu.hh | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index a9ed15d..943fb98 100644 --- a/main.cpp +++ b/main.cpp @@ -30,15 +30,18 @@ static void run(void) while(1) { SDL_Event ev; - while (SDL_PollEvent(&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); } } diff --git a/menu.cpp b/menu.cpp index b37929e..df943b2 100644 --- a/menu.cpp +++ b/menu.cpp @@ -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++) { diff --git a/menu.hh b/menu.hh index 1b3f69e..448e287 100644 --- a/menu.hh +++ b/menu.hh @@ -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);