From d488764a7b2a22e861a46d5797a55ccbb428daa4 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Mon, 23 Nov 2009 06:14:38 +0000 Subject: [PATCH] Fix some build issues --- Makefile | 8 ++++++-- menu.cpp | 35 +++++++++++++++++++++-------------- menu.hh | 2 +- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 549573f..a0b0977 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ -OBJS=menu.o +OBJS=menu.oo + +%.oo: %.cpp + g++ `sdl-config --cflags` -o $@ $< + menu: $(OBJS) - g++ -lsdl -lsdl_image -lsdl_ttf -o $@ $+ + g++ `sdl-config --libs` -lsdl -lsdl_image -lsdl_ttf -o $@ $+ diff --git a/menu.cpp b/menu.cpp index 09a1ca5..5396791 100644 --- a/menu.cpp +++ b/menu.cpp @@ -65,37 +65,44 @@ void Menu::printText(SDL_Surface *where, const char *msg, SDL_Color clr, SDL_FreeSurface(font_surf); } -void Menu::highlightBackground(int x, int y, int w, int h) +void Menu::highlightBackground(SDL_Surface *where, int x, int y, int w, int h) { + SDL_Rect dst; + /* Can't highlight without images */ if (!this->text_bg_left || !this->text_bg_middle || !this->text_bg_right) return; + int font_height = TTF_FontHeight(this->font); int bg_y_start = y + font_height / 2 - this->text_bg_left->h / 2; - int bg_x_start = x - this->text_bg_right / 2; + int bg_x_start = x - this->text_bg_right->w / 2; int bg_x_end = x + w - - this->text_bg_right / 2; + this->text_bg_right->w / 2; int n_mid = this->text_bg_left->w + this->text_bg_right->w - this->text_bg_middle->w; + dst = (SDL_Rect){bg_x_start, bg_y_start, 0,0}; SDL_BlitSurface(this->text_bg_left, NULL, - where, (SDL_Rect){bg_x_start, bg_y_start, 0,0}); + where, &dst); for (int i = 1; i < n_mid; i++) + { + dst = (SDL_Rect){bg_x_start + i * this->text_bg_middle->w, + bg_y_start, 0,0}; SDL_BlitSurface(this->text_bg_middle, NULL, - where, - (SDL_Rect){bg_x_start + i * this->text_bg_middle->w, - bg_y_start, 0,0}); + where, &dst); + } + dst = (SDL_Rect){bg_x_end, bg_y_start, 0,0}; SDL_BlitSurface(this->text_bg_right, NULL, - where, (SDL_Rect){bg_x_end, bg_y_start, 0,0}); + where, &dst); } void Menu::draw(SDL_Surface *where, int x, int y, int w, int h) { - int font_height = TTF_FontHeight(this->p_font); + int font_height = TTF_FontHeight(this->font); int line_height = (font_height + font_height / 4); int x_start = x; int y_start = y + line_height; @@ -117,7 +124,7 @@ void Menu::draw(SDL_Surface *where, int x, int y, int w, int h) else if ( this->cur_sel < this->start_entry_visible ) this->start_entry_visible = this->cur_sel; - for (i = this->start_entry_visible; + for (int i = this->start_entry_visible; i <= this->start_entry_visible + entries_visible; i++) { const char *msg = this->pp_msgs[i]; @@ -133,12 +140,12 @@ void Menu::draw(SDL_Surface *where, int x, int y, int w, int h) int tw, th; TTF_SizeText(this->font, msg, &tw, &th); - this->highlightBackground(x_start, cur_y, tw, th); + this->highlightBackground(where, x_start, cur_y, tw, th); } /* And print the text on top */ - this->printText(msg, this->text_color, - x_start, y_start + y, w); + this->printText(where, msg, this->text_color, + x_start, y_start + y, w, h); if (IS_SUBMENU(msg)) { @@ -167,7 +174,7 @@ void Menu::draw(SDL_Surface *where, int x, int y, int w, int h) break; } - p = xmalloc(total_chars + 1); + p = (char*)xmalloc(total_chars + 1); strncpy(p, msg, total_chars); TTF_SizeText(this->font, p, &tw_first, &th_first); diff --git a/menu.hh b/menu.hh index e0b5b7f..bdef133 100644 --- a/menu.hh +++ b/menu.hh @@ -65,7 +65,7 @@ public: ~Menu(); protected: - void highlightBackground(int x, int y, int w, int h); + void highlightBackground(SDL_Surface *where, int x, int y, int w, int h); void printText(SDL_Surface *where, const char *msg, SDL_Color clr, int x, int y, int w, int h);