Use the frodo menu instead

This commit is contained in:
simon.kagstrom 2009-11-28 08:43:37 +00:00
parent 0af525b4f9
commit a554c546fa
4 changed files with 40 additions and 80 deletions

View File

@ -55,8 +55,10 @@ Gui::Gui()
this->bg_submenu_left = NULL;
this->bg_submenu_middle = NULL;
this->bg_submenu_right = NULL;
this->background = NULL;
this->main_font = NULL;
this->main_menu = new MainMenu(NULL);
}
@ -69,6 +71,8 @@ bool Gui::setTheme(const char *path)
this->bg_submenu_middle = this->loadThemeImage(path, "bg_submenu_middle.png");
this->bg_submenu_right = this->loadThemeImage(path, "bg_submenu_right.png");
this->background = this->loadThemeImage(path, "background.png");
this->main_font = this->loadThemeFont(path, "font.ttf");
if (!this->bg_left || !this->bg_right || !this->bg_middle ||
@ -82,6 +86,7 @@ bool Gui::setTheme(const char *path)
SDL_FreeSurface(this->bg_submenu_left);
SDL_FreeSurface(this->bg_submenu_middle);
SDL_FreeSurface(this->bg_submenu_right);
SDL_FreeSurface(this->background);
if (this->main_font)
delete this->main_font;
@ -90,6 +95,8 @@ bool Gui::setTheme(const char *path)
}
this->main_menu->setSelectedBackground(bg_left, bg_middle, bg_right,
bg_submenu_left, bg_submenu_middle, bg_submenu_right);
this->main_menu->setFont(this->main_font);
this->focus = this->main_menu;
return true;
}
@ -98,6 +105,7 @@ void Gui::runLogic(void)
{
if (!this->is_active)
return;
this->main_menu->runLogic();
}
void Gui::setView(GuiView view)
@ -115,6 +123,19 @@ void Gui::draw(SDL_Surface *where)
{
if (!this->is_active)
return;
SDL_BlitSurface(this->background, NULL, screen, NULL);
this->main_menu->draw(where, 50, 100, 300, 400);
}
void Gui::activate()
{
this->is_active = true;
}
void Gui::deActivate()
{
this->is_active = false;
}
const char *Gui::getThemePath(const char *dir, const char *what)

View File

@ -8,7 +8,7 @@
enum GuiView
{
main,
main_menu,
insert_disc,
select_state,
virtual_keyboard,
@ -26,15 +26,9 @@ public:
bool setTheme(const char *path);
void activate()
{
this->is_active = true;
}
void activate();
void deActivate()
{
this->is_active = false;
}
void deActivate();
void runLogic(void);

View File

@ -1,31 +1,11 @@
#include <SDL_image.h>
#include <SDL_ttf.h>
#include "menu.hh"
#include "sdl_ttf_font.hh"
#include "frodo_menu.hh"
#include "utils.hh"
class PrintMenu : public Menu
{
public:
PrintMenu(Font *font) : Menu(font)
{
}
virtual void selectCallback(int which)
{
printf("entry %d selected: %s\n", which, this->pp_msgs[which]);
}
virtual void escapeCallback(int which)
{
printf("entry %d escaped: %s\n", which, this->pp_msgs[which]);
}
};
SDL_Surface *screen;
SDL_Surface *g_background;
PrintMenu *g_menu;
static Gui *g_gui;
static void run(void)
{
@ -37,67 +17,27 @@ static void run(void)
if (ev.type == SDL_QUIT)
exit(1);
g_menu->pushEvent(&ev);
g_gui->pushEvent(&ev);
}
g_menu->runLogic();
g_menu->draw(screen, 80, 80, 400, 400);
g_gui->runLogic();
g_gui->draw(screen);
SDL_Flip(screen);
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
SDL_BlitSurface(g_background, NULL, screen, NULL);
SDL_Delay(50);
}
}
const char *main_menu_messages[] = {
/*02*/ "File",
/*03*/ "^|Insert|Start",
/*04*/ "States",
/*05*/ "^|Load|Save|Delete",
/*06*/ "Keyboard",
/*07*/ "^|Type|Macro|Bind",
/*08*/ " ",
/*09*/ "Reset the C=64",
/*10*/ "Networking",
/*11*/ "Options",
/*12*/ "Advanced Options",
/*13*/ "Help",
/*15*/ "Quit",
NULL
};
static void init(void)
{
TTF_Font *fnt;
SDL_Surface *bg_left, *bg_right, *bg_middle,
*bg_submenu_left, *bg_submenu_right, *bg_submenu_middle;
screen = SDL_SetVideoMode(640, 480, 16,
SDL_DOUBLEBUF);
panic_if(!screen, "Cannot initialize video: %s\n", SDL_GetError());
TTF_Init();
fnt = read_and_alloc_font("themes/default/font.ttf", 18);
g_background = IMG_Load("themes/default/background.png");
bg_left = IMG_Load("themes/default/bg_left.png");
bg_right = IMG_Load("themes/default/bg_right.png");
bg_middle = IMG_Load("themes/default/bg_middle.png");
bg_submenu_left = IMG_Load("themes/default/bg_submenu_left.png");
bg_submenu_right = IMG_Load("themes/default/bg_submenu_right.png");
bg_submenu_middle = IMG_Load("themes/default/bg_submenu_middle.png");
panic_if( !bg_left || !bg_right || !bg_middle ||
!bg_submenu_left || !bg_submenu_right || !bg_submenu_middle,
"bg loading failed\n");
g_menu = new PrintMenu(new Font_TTF(fnt, 255, 255, 255));
g_menu->setText(main_menu_messages);
g_menu->setSelectedBackground(bg_left, bg_middle, bg_right,
bg_submenu_left, bg_submenu_middle, bg_submenu_right);
g_gui = new Gui();
panic_if(!g_gui->setTheme("themes/default"),
"Setting theme failed\n");
g_gui->activate();
}
int main(int argc, char *argv[])

View File

@ -46,6 +46,13 @@ class Menu
public:
Menu(Font *font);
~Menu();
void setFont(Font *font)
{
this->font = font;
}
void setTextColor(SDL_Color clr);
void setSelectedBackground(SDL_Surface *left, SDL_Surface *middle, SDL_Surface *right,
@ -69,8 +76,6 @@ public:
void draw(SDL_Surface *where,
int x, int y, int w, int h);
~Menu();
protected:
void highlightBackground(SDL_Surface *where,
SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right,