frodo-wii/menu.hh

97 lines
1.5 KiB
C++
Raw Normal View History

2009-01-13 19:46:42 +01:00
/*********************************************************************
*
* Copyright (C) 2004, 2008, Simon Kagstrom
*
* Filename: menu.h
* Author: Simon Kagstrom <simon.kagstrom@gmail.com>
* Description:
*
* $Id$
*
********************************************************************/
#ifndef __MENU_H__
#define __MENU_H__
#include <SDL.h>
#include <SDL_ttf.h>
#include <stdint.h>
2009-11-19 18:59:43 +01:00
enum {
2009-11-19 20:23:37 +01:00
EVENT_NONE = 0,
KEY_UP = 1,
KEY_DOWN = 2,
KEY_LEFT = 4,
KEY_RIGHT = 8,
KEY_SELECT = 16,
KEY_ESCAPE = 32,
KEY_PAGEDOWN = 64,
KEY_PAGEUP = 128,
KEY_HELP = 256,
2009-11-19 18:59:43 +01:00
};
2009-01-22 21:34:33 +01:00
typedef struct
{
int n_entries;
int index;
int sel;
} submenu_t;
2009-11-19 20:23:37 +01:00
typedef int event_t;
2009-11-19 18:42:02 +01:00
class Menu
{
public:
2009-11-19 18:59:43 +01:00
Menu(TTF_Font *font, SDL_Color clr, int w, int h);
2009-11-19 18:42:02 +01:00
2009-11-19 18:59:43 +01:00
void setText(const char **messages);
2009-11-19 18:42:02 +01:00
void pushEvent(SDL_Event *ev);
void runLogic();
2009-11-19 18:59:43 +01:00
void draw(SDL_Surface *where,
int x, int y);
2009-11-19 18:42:02 +01:00
~Menu();
2009-11-19 21:05:06 +01:00
protected:
virtual void selectCallback(int which);
virtual void escapeCallback(int which);
int getNextEntry(int dy);
void selectNext(int dx, int dy);
void selectNext(event_t ev);
2009-11-19 20:23:37 +01:00
void pushEvent(event_t ev);
event_t popEvent();
2009-11-19 18:42:02 +01:00
const char *title;
const char **pp_msgs;
2009-11-19 18:59:43 +01:00
TTF_Font *font;
2009-11-19 18:42:02 +01:00
SDL_Color text_color;
2009-11-19 18:59:43 +01:00
/* Width and height */
int w, h;
/* Relative to this menu */
int mouse_x, mouse_y;
2009-11-19 18:42:02 +01:00
int n_submenus;
submenu_t *p_submenus;
int cur_sel; /* Main selection */
int start_entry_visible;
int n_entries;
2009-11-19 20:23:37 +01:00
int ev_head, ev_tail;
event_t event_stack[8];
2009-11-19 18:59:43 +01:00
};
2009-02-13 08:58:33 +01:00
2009-01-13 19:46:42 +01:00
#endif /* !__MENU_H__ */