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
|
|
|
|
2009-11-26 19:29:10 +01:00
|
|
|
#include "font.hh"
|
2009-12-19 16:46:15 +01:00
|
|
|
#include "widget.hh"
|
2009-11-19 19:23:12 +01:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int n_entries;
|
|
|
|
int index;
|
|
|
|
int sel;
|
|
|
|
} submenu_t;
|
|
|
|
|
2009-11-19 20:23:37 +01:00
|
|
|
|
2009-12-19 16:46:15 +01:00
|
|
|
class Menu : public Widget
|
2009-11-19 18:42:02 +01:00
|
|
|
{
|
|
|
|
public:
|
2009-11-26 19:29:10 +01:00
|
|
|
Menu(Font *font);
|
2009-11-20 18:09:06 +01:00
|
|
|
|
2009-11-28 09:43:37 +01:00
|
|
|
~Menu();
|
|
|
|
|
|
|
|
void setFont(Font *font)
|
|
|
|
{
|
|
|
|
this->font = font;
|
|
|
|
}
|
|
|
|
|
2009-11-20 18:09:06 +01:00
|
|
|
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
|
|
|
|
2009-11-25 19:14:48 +01:00
|
|
|
void setText(const char **messages, int *submenu_defaults = NULL);
|
2009-11-19 18:42:02 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2009-11-19 21:05:06 +01:00
|
|
|
protected:
|
2009-11-22 10:59:23 +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-12-04 19:01:59 +01:00
|
|
|
virtual void hoverCallback(int which) = 0;
|
|
|
|
|
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
|
|
|
|
2009-12-05 13:04:00 +01:00
|
|
|
public:
|
|
|
|
virtual int getNextEntry(int dy);
|
2009-11-19 21:05:06 +01:00
|
|
|
|
2009-12-05 13:04:00 +01:00
|
|
|
virtual int selectOne(int which);
|
2009-11-20 07:11:57 +01:00
|
|
|
|
2009-12-05 13:04:00 +01:00
|
|
|
virtual int selectNext(int dx, int dy);
|
2009-11-19 21:05:06 +01:00
|
|
|
|
2009-12-05 13:04:00 +01:00
|
|
|
virtual int selectNext(event_t ev);
|
2009-11-19 21:05:06 +01:00
|
|
|
|
2009-12-05 13:04:00 +01:00
|
|
|
protected:
|
|
|
|
|
2009-11-19 18:42:02 +01:00
|
|
|
const char **pp_msgs;
|
2009-11-26 19:29:10 +01:00
|
|
|
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 18:59:43 +01:00
|
|
|
};
|
2009-02-13 08:58:33 +01:00
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
#endif /* !__MENU_H__ */
|