mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2025-02-16 20:39:15 +01:00
Add some font stuff
This commit is contained in:
parent
2bf6893441
commit
ad22d34aa1
30
font.hh
Normal file
30
font.hh
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef __FONT_HH__
|
||||
#define __FONT_HH__
|
||||
|
||||
class Font
|
||||
{
|
||||
public:
|
||||
virtual int getHeight(const char *str) = 0;
|
||||
|
||||
virtual int getHeight(const char c)
|
||||
{
|
||||
char buf[2] = {c, '\0'};
|
||||
|
||||
return this->getHeight(buf);
|
||||
}
|
||||
|
||||
virtual int getWidth(const char *str) = 0;
|
||||
|
||||
virtual int getWidth(const char c)
|
||||
{
|
||||
char buf[2] = {c, '\0'};
|
||||
|
||||
return this->getWidth(buf);
|
||||
}
|
||||
|
||||
virtual void draw(int x, int y, int w, int h) = 0;
|
||||
|
||||
virtual void draw(int x, int y, int w, int h, int r, int g, int b) = 0;
|
||||
};
|
||||
|
||||
#endif /* __FONT_HH__ */
|
3
main.cpp
3
main.cpp
@ -86,7 +86,8 @@ static void init(void)
|
||||
|
||||
g_menu = new PrintMenu(fnt);
|
||||
g_menu->setText(main_menu_messages);
|
||||
g_menu->setSelectedBackground(bg_left, bg_middle, bg_right);
|
||||
g_menu->setSelectedBackground(bg_left, bg_middle, bg_right,
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
8
menu.cpp
8
menu.cpp
@ -78,8 +78,7 @@ void Menu::highlightBackground(SDL_Surface *where,
|
||||
int bg_y_start = y + font_height / 2 -
|
||||
bg_left->h / 2;
|
||||
int bg_x_start = x - bg_left->w / 3;
|
||||
int bg_x_end = x + w -
|
||||
(2 * bg_right->w) / 3;
|
||||
int bg_x_end = x + w - (2 * bg_right->w) / 3;
|
||||
int n_mid = (bg_x_end - bg_x_start) / bg_middle->w;
|
||||
|
||||
/* Left */
|
||||
@ -183,7 +182,7 @@ void Menu::draw(SDL_Surface *where, int x, int y, int w, int h)
|
||||
TTF_SizeText(this->font, p, &tw, &th);
|
||||
|
||||
this->highlightBackground(where,
|
||||
this->text_bg_left, this->text_bg_middle, this->text_bg_right,
|
||||
this->submenu_bg_left, this->submenu_bg_middle, this->submenu_bg_right,
|
||||
x_start + tw_first, cur_y, tw, th);
|
||||
free(p);
|
||||
}
|
||||
@ -416,6 +415,9 @@ Menu::Menu(TTF_Font *font)
|
||||
this->text_bg_left = NULL;
|
||||
this->text_bg_middle = NULL;
|
||||
this->text_bg_right = NULL;
|
||||
this->submenu_bg_left = NULL;
|
||||
this->submenu_bg_middle = NULL;
|
||||
this->submenu_bg_right = NULL;
|
||||
|
||||
this->pp_msgs = NULL;
|
||||
this->n_entries = 0;
|
||||
|
12
menu.hh
12
menu.hh
@ -46,11 +46,16 @@ public:
|
||||
|
||||
void setTextColor(SDL_Color clr);
|
||||
|
||||
void setSelectedBackground(SDL_Surface *left, SDL_Surface *middle, SDL_Surface *right)
|
||||
void setSelectedBackground(SDL_Surface *left, SDL_Surface *middle, SDL_Surface *right,
|
||||
SDL_Surface *submenu_left, SDL_Surface *submenu_middle, SDL_Surface *submenu_right)
|
||||
{
|
||||
this->text_bg_left = left;
|
||||
this->text_bg_middle = middle;
|
||||
this->text_bg_right = right;
|
||||
|
||||
this->submenu_bg_left = submenu_left;
|
||||
this->submenu_bg_middle = submenu_middle;
|
||||
this->submenu_bg_right = submenu_right;
|
||||
}
|
||||
|
||||
void setText(const char **messages, int *submenu_defaults = NULL);
|
||||
@ -94,10 +99,15 @@ protected:
|
||||
const char **pp_msgs;
|
||||
TTF_Font *font;
|
||||
SDL_Color text_color;
|
||||
|
||||
SDL_Surface *text_bg_left;
|
||||
SDL_Surface *text_bg_right;
|
||||
SDL_Surface *text_bg_middle;
|
||||
|
||||
SDL_Surface *submenu_bg_left;
|
||||
SDL_Surface *submenu_bg_right;
|
||||
SDL_Surface *submenu_bg_middle;
|
||||
|
||||
/* Relative to this menu */
|
||||
int mouse_x, mouse_y;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user