00001 00002 00003 #ifndef MOD_MENUITEM_H 00004 #define MOD_MENUITEM_H 00005 00006 //Licence: LGPL 00007 //Copyright: Visti Andresen 00008 00009 #include <SDL.h> 00010 #include <iostream> 00011 #include <fstream> 00012 #include <string> 00013 00014 using namespace std; 00015 00016 /**A class defining everything you can do with a menu item, note that at 00017 Menu is itself a MenuItem*/ 00018 class MenuItem 00019 { 00020 public: 00021 enum Type { 00022 MENU ///A menu or submenu. 00023 ,CONTROL ///Some sort of control. 00024 ,BACK_BUTTON ///Special control, returns the focus to the parent menu. 00025 }; 00026 /**Destructor*/ 00027 virtual ~MenuItem(){}; 00028 00029 /**Reads the configuration for the MenuItem from any position within the 00030 file 00031 00032 Hint: Use findLoadPosition to find you entry in the file*/ 00033 virtual void load(ifstream &file){}; 00034 00035 /**Saves the MenuItem at the current position in the file. 00036 00037 Entrys must look like "name=value\n".*/ 00038 virtual void save(ofstream &file){}; 00039 00040 /**Draws the MenuItem at x,y with a zoom factor of zoom 00041 (2 equals double size). 00042 00043 The MenuItem may decide not to apply the scale or to only support some zoom 00044 steps, always check getWidth and getHeight if you need the excact size. 00045 */ 00046 virtual void draw(float x, float y, float zoom)=0; 00047 00048 /**Returns the Type of this control.*/ 00049 virtual Type getType()=0; 00050 00051 /**Returns the width of this MenuItem at zoom factor zoom, must be excact*/ 00052 virtual float getWidth(float zoom)=0; 00053 00054 /**Returns the height of this MenuItem at zoom factor zoom, must be excact*/ 00055 virtual float getHeight(float zoom)=0; 00056 00057 /**Returns the name of the MenuItem used when save is called. 00058 00059 The name may not contain a =.*/ 00060 virtual string &getName()=0; 00061 00062 /**Called when a key press/release event occurs, return true if the 00063 MenuItem has handled the event. 00064 00065 If true is returned the event handling will stop.*/ 00066 virtual bool handleKeyEvent(SDL_Event *event)=0; 00067 00068 protected: 00069 /**Finds a "name=value" pair in the stream, the stream pointer is left so that 00070 value can be read directly. 00071 00072 Returns true if the "name=value" pair was found*/ 00073 bool findLoadPosition(const string &name, ifstream &file); 00074 }; 00075 00076 #endif