frodo-wii/main.cpp

105 lines
2.6 KiB
C++
Raw Normal View History

2009-11-23 20:47:01 +01:00
#include <SDL_image.h>
#include <SDL_ttf.h>
2009-11-19 18:59:43 +01:00
#include "menu.hh"
2009-11-26 19:29:10 +01:00
#include "sdl_ttf_font.hh"
2009-11-23 19:52:30 +01:00
#include "utils.hh"
class PrintMenu : public Menu
{
public:
2009-11-26 19:29:10 +01:00
PrintMenu(Font *font) : Menu(font)
2009-11-23 19:52:30 +01:00
{
}
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;
PrintMenu *g_menu;
static void run(void)
{
while(1)
{
SDL_Event ev;
while (SDL_PollEvent(&ev)) {
2009-11-23 19:52:30 +01:00
if (ev.type == SDL_QUIT)
2009-11-23 20:47:01 +01:00
exit(1);
2009-11-23 19:52:30 +01:00
2009-11-23 20:47:01 +01:00
g_menu->pushEvent(&ev);
2009-11-23 19:52:30 +01:00
}
g_menu->runLogic();
2009-11-24 07:36:11 +01:00
g_menu->draw(screen, 80, 80, 400, 400);
2009-11-23 19:52:30 +01:00
2009-11-23 20:33:51 +01:00
SDL_Flip(screen);
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
2009-11-23 19:52:30 +01:00
SDL_Delay(50);
}
}
2009-11-23 20:33:51 +01:00
const char *main_menu_messages[] = {
/*02*/ "File",
/*03*/ "^|Insert|Start",
/*04*/ "States",
/*05*/ "^|Load|Save|Delete",
/*06*/ "Keyboard",
/*07*/ "^|Type|Macro|Bind",
2009-11-24 07:36:11 +01:00
/*08*/ " ",
2009-11-23 20:33:51 +01:00
/*09*/ "Reset the C=64",
/*10*/ "Networking",
/*11*/ "Options",
/*12*/ "Advanced Options",
/*13*/ "Help",
/*15*/ "Quit",
NULL
};
2009-11-23 19:52:30 +01:00
static void init(void)
{
TTF_Font *fnt;
2009-11-26 19:33:42 +01:00
SDL_Surface *bg_left, *bg_right, *bg_middle,
*bg_submenu_left, *bg_submenu_right, *bg_submenu_middle;
2009-11-23 19:52:30 +01:00
screen = SDL_SetVideoMode(640, 480, 16,
SDL_DOUBLEBUF);
panic_if(!screen, "Cannot initialize video: %s\n", SDL_GetError());
2009-11-23 20:33:51 +01:00
2009-11-23 19:52:30 +01:00
TTF_Init();
2009-11-26 19:29:10 +01:00
fnt = read_and_alloc_font("font.ttf", 18);
2009-11-23 19:52:30 +01:00
2009-11-26 19:33:42 +01:00
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,
2009-11-23 20:47:01 +01:00
"bg loading failed\n");
2009-11-26 19:29:10 +01:00
g_menu = new PrintMenu(new Font_TTF(fnt, 255, 255, 255));
2009-11-23 20:33:51 +01:00
g_menu->setText(main_menu_messages);
2009-11-26 18:40:24 +01:00
g_menu->setSelectedBackground(bg_left, bg_middle, bg_right,
2009-11-26 19:33:42 +01:00
bg_submenu_left, bg_submenu_middle, bg_submenu_right);
2009-11-23 19:52:30 +01:00
}
2009-11-19 18:59:43 +01:00
int main(int argc, char *argv[])
{
2009-11-23 19:52:30 +01:00
init();
run();
2009-11-19 18:59:43 +01:00
return 0;
}