Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

Key.h

00001 00002 00003 #ifndef MOD_KEY_H 00004 #define MOD_KEY_H 00005 00006 //Licence: LGPL 00007 //Copyright: Visti Andresen 00008 00009 #include "MenuItem.h" 00010 #include "Font.h" 00011 00012 /**A class for configuring keyboard control and handling the keyboard input.*/ 00013 class Key : public MenuItem 00014 { 00015 public: 00016 /**Constructor 00017 00018 lable is the name the user can see on screen. 00019 00020 name is the name of the TextEntry in the config file. 00021 00022 font is the Font to use when rendering. 00023 00024 defaultValue is the SDLKey to use when no configration is loaded. 00025 */ 00026 Key(const string &label, const string &name, Font *font, 00027 SDLKey defaultValue = SDLK_SPACE); 00028 ~Key(); 00029 00030 void load(ifstream &file); 00031 00032 void save(ofstream &file); 00033 void draw(float x, float y, float zoom); 00034 Type getType(){return CONTROL;} 00035 float getWidth(float zoom); 00036 float getHeight(float zoom); 00037 string &getName(); 00038 00039 /**Returns true if the key is currently pressed.*/ 00040 bool isPressed(); 00041 /**Returns true if the key has been pressed since the last time keyPress 00042 has been called.*/ 00043 bool keyPress(); 00044 00045 /**Call this in your event loop with the events to make the key register 00046 the keyboard events (Otherwise isPressed and keyPress won't work)*/ 00047 void handleGameKeyboardEvent(SDL_Event *event); 00048 bool handleKeyEvent(SDL_Event *event); 00049 private: 00050 string getStringRepresentation(); 00051 00052 string name_; 00053 string label_; 00054 SDLKey thisKey_; 00055 bool state_; 00056 bool press_; 00057 bool grabbingKey_; 00058 00059 Font *font_; 00060 }; 00061 00062 #endif

Generated on Wed Sep 1 14:46:57 2004 by doxygen 1.3.7