00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MENULIST_H
00020 #define MENULIST_H
00021
00022 #include <string>
00023 #include <vector>
00024 #include "SDL_events.h"
00025
00026 class Game_window;
00027 class Shape_frame;
00028 class Font;
00029 class Mouse;
00030
00031 class MenuObject {
00032 public:
00033 Shape_frame ;
00034 int x, y, x1, y1, x2, y2;
00035 bool selected;
00036 bool dirty;
00037
00038 MenuObject() { };
00039 virtual ~MenuObject() { }
00040
00041 void set_selected(bool sel) {
00042 dirty |= (selected != sel);
00043 selected = sel;
00044 }
00045 bool is_selected() { return selected; }
00046 bool is_mouse_over(int mx, int my)
00047 { return ((mx>=x1)&&(mx<=x2)&&(my>=y1)&&(my<=y2)); };
00048
00049 virtual void paint(Game_window *gwin) =0;
00050 virtual bool handle_event(SDL_Event& event) =0;
00051 };
00052
00053 class MenuEntry: public MenuObject {
00054 public:
00055 MenuEntry(Shape_frame *on, Shape_frame *off, int xpos, int ypos);
00056 virtual ~MenuEntry() { }
00057
00058 virtual void paint(Game_window *gwin);
00059 virtual bool handle_event(SDL_Event& event);
00060 };
00061
00062 class MenuChoice: public MenuObject {
00063 private:
00064 std::vector<std::string> *choices;
00065 int choice;
00066 Font *font;
00067 int max_choice_width;
00068 public:
00069 MenuChoice(Shape_frame *on, Shape_frame *off, int xpos, int ypos, Font *fnt);
00070 virtual ~MenuChoice() { delete choices; }
00071 void add_choice(const char *s);
00072 int get_choice() { return choice; }
00073 void set_choice(int c) { choice = c; }
00074
00075 virtual void paint(Game_window *gwin);
00076 virtual bool handle_event(SDL_Event& event);
00077 };
00078
00079 class MenuList {
00080 private:
00081 std::vector<MenuObject*> *entries;
00082 bool selected;
00083 int selection;
00084 public:
00085 MenuList(): selected(false), selection(0) { entries = new std::vector<MenuObject*>(); }
00086 ~MenuList();
00087 int add_entry(MenuObject *entry) { entries->push_back(entry); return (entries->size()-1);}
00088 void paint(Game_window *gwin);
00089 int handle_events(Game_window *gwin, Mouse *mouse);
00090 int get_selection() { return selection; }
00091 void set_selection(int sel);
00092 void set_selection(int x, int y);
00093 };
00094
00095 #endif