frodo-wii/menu.hh

125 lines
2.4 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-20 18:09:06 +01:00
Menu(TTF_Font *font);
void setTextColor(SDL_Color clr);
2009-11-26 18:40:24 +01:00
void setSelectedBackground(SDL_Surface *left, SDL_Surface *middle, SDL_Surface *right,
SDL_Surface *submenu_left, SDL_Surface *submenu_middle, SDL_Surface *submenu_right)
2009-11-20 21:28:48 +01:00
{
this->text_bg_left = left;
this->text_bg_middle = middle;
this->text_bg_right = right;
2009-11-26 18:40:24 +01:00
this->submenu_bg_left = submenu_left;
this->submenu_bg_middle = submenu_middle;
this->submenu_bg_right = submenu_right;
2009-11-20 21:28:48 +01:00
}
2009-11-19 18:42:02 +01:00
void setText(const char **messages, int *submenu_defaults = NULL);
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,
2009-11-20 18:09:06 +01:00
int x, int y, int w, int h);
2009-11-19 18:42:02 +01:00
~Menu();
2009-11-19 21:05:06 +01:00
protected:
2009-11-25 19:27:12 +01:00
void highlightBackground(SDL_Surface *where,
SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right,
int x, int y, int w, int h);
2009-11-20 21:28:48 +01:00
void printText(SDL_Surface *where, const char *msg, SDL_Color clr,
int x, int y, int w, int h);
2009-11-20 18:09:06 +01:00
2009-11-23 19:52:30 +01:00
virtual void selectCallback(int which) = 0;
2009-11-19 21:05:06 +01:00
2009-11-23 19:52:30 +01:00
virtual void escapeCallback(int which) = 0;
2009-11-19 21:05:06 +01:00
2009-11-19 21:18:45 +01:00
submenu_t *findSubmenu(int index);
2009-11-19 21:05:06 +01:00
int getNextEntry(int dy);
2009-11-20 07:11:57 +01:00
void selectOne(int which);
2009-11-19 21:05:06 +01:00
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-26 18:40:24 +01:00
2009-11-20 21:28:48 +01:00
SDL_Surface *text_bg_left;
SDL_Surface *text_bg_right;
SDL_Surface *text_bg_middle;
2009-11-19 18:59:43 +01:00
2009-11-26 18:40:24 +01:00
SDL_Surface *submenu_bg_left;
SDL_Surface *submenu_bg_right;
SDL_Surface *submenu_bg_middle;
2009-11-19 18:59:43 +01:00
/* Relative to this menu */
2009-11-20 18:09:06 +01:00
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 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__ */