00001 /* 00002 * KeyMap.h 00003 * 00004 * Part of Fly! Legacy project 00005 * 00006 * Copyright 2003 Chris Wallace 00007 * 00008 * Fly! Legacy is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * Fly! Legacy is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with Fly! Legacy; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 */ 00023 00028 #ifndef KEYMAP_H 00029 #define KEYMAP_H 00030 00031 00032 #include "FlyLegacy.h" 00033 #include <map> 00034 00035 00036 // 00037 // CKeyDefinition represents a single simulator function that can be mapped to 00038 // a keyboard key. 00039 // 00040 class CKeyDefinition : public CStreamObject { 00041 public: 00042 CKeyDefinition (void); 00043 00044 // CStreamObject methods 00045 virtual int Read (SStream *stream, Tag tag); 00046 00047 // CKeyDefinition methods 00048 char* GetName (void); 00049 int GetCode (void); 00050 void Bind (KeyCallbackPtr f); 00051 00052 public: 00053 Tag kyid; // Unique key definition tag 00054 char name[64]; // UI name 00055 int code; // Key code and modifier 00056 bool user; // User definable 00057 bool enab; // Enabled 00058 00059 KeyCallbackPtr cb; // Callback function 00060 }; 00061 00062 00063 // 00064 // CKeySet represents a group of key mappings that relate to a similar group 00065 // of simulator functions. The default key mapping contains key sets for 00066 // "Menu Keys", "Global Keys", 00067 // 00068 class CKeySet : public CStreamObject { 00069 public: 00070 CKeySet (Tag tag); 00071 ~CKeySet (void); 00072 00073 // CStreamObject methods 00074 virtual int Read (SStream *stream, Tag tag); 00075 00076 // CKeySet methods 00077 char* GetName (void); 00078 bool GetUserModifiableState (void); 00079 bool GetEnabledState (void); 00080 int GetNumKeyDefinitions (void); 00081 CKeyDefinition* GetKeyDefinition (int i); 00082 00083 public: 00084 Tag kset; // Key set unique tag 00085 char name[64]; // Key set name 00086 bool user; // User modifiable 00087 bool enab; // Enabled 00088 std::map<Tag,CKeyDefinition*> kkey; // Map of key ids to complete definition 00089 }; 00090 00091 00092 00093 // 00094 // CKeyMap is the application-visible interface class to the keyboard 00095 // mapping system. Typical example usage: 00096 // 00097 // Application init: 00098 // CKeyMappings *keymap = new CKeyMappings ("System\\default.key"); 00099 // keymap->Bind ('blah', func_blah); 00100 // ... 00101 // 00102 // Application detects key press: 00103 // keymap->KeyPress (key, modifiers); 00104 // 00105 class CKeyMap : public CStreamObject { 00106 public: 00107 CKeyMap (const char* keyFilename); 00108 ~CKeyMap (void); 00109 00110 // CStreamObject methods 00111 virtual int Read (SStream *stream, Tag tag); 00112 00113 // CKeyMap methods 00114 void Print (FILE *f); 00115 void KeyPress (EKeyboardKeys key, EKeyboardModifiers mod); 00116 void Bind (Tag id, KeyCallbackPtr f); 00117 int GetNumKeySets (void); 00118 CKeySet* GetKeySet (int i); 00119 00120 private: 00121 CKeyDefinition* FindKeyDefinitionById (Tag id); 00122 00123 protected: 00124 int vers; // Version, currently ignored 00125 std::map<Tag,CKeySet*> kset; // Map of keyset ids 00126 }; 00127 00128 00129 // 00130 // Utility function which formats the keycode into a human-readable string 00131 // 00132 void formatKeyCode (char *s, int code); 00133 00134 #endif // KEYMAP_H 00135
|
|
Documentation generated by
|