menulist.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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

Generated on Mon Jul 9 14:42:48 2007 for ExultEngine by  doxygen 1.5.1