Add frodo_menu class (not finished)

This commit is contained in:
simon.kagstrom 2009-11-28 08:22:19 +00:00
parent 0379a21a55
commit 0af525b4f9
3 changed files with 214 additions and 1 deletions

View File

@ -1,4 +1,4 @@
OBJS=menu.oo main.oo utils.oo
OBJS=menu.oo main.oo utils.oo frodo_menu.oo
all: menu
@ -7,6 +7,8 @@ all: menu
menu.oo: menu.cpp menu.hh utils.hh font.hh Makefile
frodo_menu.oo: frodo_menu.cpp frodo_menu.hh font.hh menu.hh Makefile
utils.oo: utils.cpp utils.hh Makefile
main.oo: menu.hh utils.hh sdl_ttf_font.hh Makefile

145
frodo_menu.cpp Normal file
View File

@ -0,0 +1,145 @@
#include <SDL_image.h>
#include <SDL_ttf.h>
#include "menu.hh"
#include "frodo_menu.hh"
#include "sdl_ttf_font.hh"
#include "utils.hh"
extern SDL_Surface *screen;
class MainMenu : public Menu
{
public:
MainMenu(Font *font) : Menu(font)
{
static const char *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
};
this->setText(messages);
}
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]);
}
};
Gui::Gui()
{
this->focus = NULL;
this->bg_left = NULL;
this->bg_middle = NULL;
this->bg_right = NULL;
this->bg_submenu_left = NULL;
this->bg_submenu_middle = NULL;
this->bg_submenu_right = NULL;
this->main_font = NULL;
}
bool Gui::setTheme(const char *path)
{
this->bg_left = this->loadThemeImage(path, "bg_left.png");
this->bg_middle = this->loadThemeImage(path, "bg_middle.png");
this->bg_right = this->loadThemeImage(path, "bg_right.png");
this->bg_submenu_left = this->loadThemeImage(path, "bg_submenu_left.png");
this->bg_submenu_middle = this->loadThemeImage(path, "bg_submenu_middle.png");
this->bg_submenu_right = this->loadThemeImage(path, "bg_submenu_right.png");
this->main_font = this->loadThemeFont(path, "font.ttf");
if (!this->bg_left || !this->bg_right || !this->bg_middle ||
!this->bg_submenu_left || !this->bg_submenu_right ||
!this->bg_submenu_middle ||
!this->main_font)
{
SDL_FreeSurface(this->bg_left);
SDL_FreeSurface(this->bg_middle);
SDL_FreeSurface(this->bg_right);
SDL_FreeSurface(this->bg_submenu_left);
SDL_FreeSurface(this->bg_submenu_middle);
SDL_FreeSurface(this->bg_submenu_right);
if (this->main_font)
delete this->main_font;
return false;
}
this->main_menu->setSelectedBackground(bg_left, bg_middle, bg_right,
bg_submenu_left, bg_submenu_middle, bg_submenu_right);
return true;
}
void Gui::runLogic(void)
{
if (!this->is_active)
return;
}
void Gui::setView(GuiView view)
{
}
void Gui::pushEvent(SDL_Event *ev)
{
if (this->is_active && this->focus)
this->focus->pushEvent(ev);
}
void Gui::draw(SDL_Surface *where)
{
if (!this->is_active)
return;
}
const char *Gui::getThemePath(const char *dir, const char *what)
{
static char buf[255];
memset(buf, 0, sizeof(buf));
snprintf(buf, 254, "%s/%s",
dir, what);
return buf;
}
SDL_Surface *Gui::loadThemeImage(const char *dir, const char *what)
{
return IMG_Load(this->getThemePath(dir, what));
}
Font *Gui::loadThemeFont(const char *dir, const char *what)
{
TTF_Font *fnt;
fnt = read_and_alloc_font(this->getThemePath(dir, what), 18);
if (!fnt)
return NULL;
return new Font_TTF(fnt, 255,255,255);
}

66
frodo_menu.hh Normal file
View File

@ -0,0 +1,66 @@
#ifndef __GUI_HH__
#define __GUI_HH__
#include <SDL.h>
#include "menu.hh"
#include "font.hh"
enum GuiView
{
main,
insert_disc,
select_state,
virtual_keyboard,
networking,
options,
help,
};
class Gui
{
public:
Gui();
~Gui();
bool setTheme(const char *path);
void activate()
{
this->is_active = true;
}
void deActivate()
{
this->is_active = false;
}
void runLogic(void);
void setView(GuiView view);
void pushEvent(SDL_Event *ev);
void draw(SDL_Surface *where);
private:
const char *getThemePath(const char *dir, const char *what);
SDL_Surface *loadThemeImage(const char *dir, const char *what);
Font *loadThemeFont(const char *dir, const char *what);
bool is_active;
Menu *focus; /* Where the focus goes */
SDL_Surface *background;
Menu *main_menu;
SDL_Surface *bg_left, *bg_right, *bg_middle,
*bg_submenu_left, *bg_submenu_right, *bg_submenu_middle;
Font *main_font;
};
#endif /* GUI_HH */