keys.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 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 KEYS_H
00020 #define KEYS_H
00021 
00022 #include "SDL_events.h"
00023 #include "game.h"
00024 
00025 #include <vector>
00026 #include <map>
00027 #include <string>
00028 
00029 const int c_maxparams = 4;
00030 
00031 struct Action;
00032 struct ActionType {
00033   const Action* action;
00034   int params[c_maxparams];
00035 };
00036 
00037 struct ltSDLkeysym
00038 {
00039   bool operator()(SDL_keysym k1, SDL_keysym k2) const
00040   {
00041     if (k1.sym == k2.sym)
00042       return k1.mod < k2.mod;
00043     else
00044       return k1.sym < k2.sym;
00045   }
00046 };
00047 
00048 typedef std::map<SDL_keysym, ActionType, ltSDLkeysym>   KeyMap;
00049 
00050 class KeyBinder {
00051  private:
00052   KeyMap bindings;
00053   
00054   std::vector<std::string> keyhelp;
00055   std::vector<std::string> cheathelp;
00056  public:
00057   KeyBinder();
00058   ~KeyBinder();
00059   /* Add keybinding */
00060   void AddKeyBinding(SDLKey sym, int mod, const Action* action,
00061              int nparams, int* params);
00062   
00063   /* Delete keybinding */
00064   void DelKeyBinding(SDLKey sym, int mod);
00065   
00066   /* Other methods */
00067   void Flush() { bindings.clear(); keyhelp.clear(); cheathelp.clear(); }
00068   bool DoAction(ActionType action, bool press);
00069   bool HandleEvent(SDL_Event &ev);
00070   
00071   void LoadFromFile(const char* filename);
00072   void LoadDefaults();
00073   
00074   void ShowHelp();
00075   void ShowCheatHelp();
00076   
00077  private:
00078   void ParseText(char *text, int len);
00079   void ParseLine(char *line);
00080   void FillParseMaps();
00081 };
00082 
00083 #endif /* KEYS_H */

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