00001
00032 #ifndef LL_LLKEYBOARD_H
00033 #define LL_LLKEYBOARD_H
00034
00035 #include <map>
00036
00037 #include "string_table.h"
00038 #include "lltimer.h"
00039 #include "indra_constants.h"
00040
00041 enum EKeystate
00042 {
00043 KEYSTATE_DOWN,
00044 KEYSTATE_LEVEL,
00045 KEYSTATE_UP
00046 };
00047
00048 typedef void (*LLKeyFunc)(EKeystate keystate);
00049
00050 enum EKeyboardInsertMode
00051 {
00052 LL_KIM_INSERT,
00053 LL_KIM_OVERWRITE
00054 };
00055
00056 class LLKeyBinding
00057 {
00058 public:
00059 KEY mKey;
00060 MASK mMask;
00061
00062 LLKeyFunc mFunction;
00063 };
00064
00065 class LLWindowCallbacks;
00066
00067 class LLKeyboard
00068 {
00069 public:
00070 typedef enum e_numpad_distinct
00071 {
00072 ND_NEVER,
00073 ND_NUMLOCK_OFF,
00074 ND_NUMLOCK_ON
00075 } ENumpadDistinct;
00076
00077 public:
00078 LLKeyboard();
00079 virtual ~LLKeyboard();
00080
00081 void resetKeys();
00082
00083
00084 F32 getCurKeyElapsedTime() { return getKeyDown(mCurScanKey) ? getKeyElapsedTime( mCurScanKey ) : 0.f; }
00085 F32 getCurKeyElapsedFrameCount() { return getKeyDown(mCurScanKey) ? (F32)getKeyElapsedFrameCount( mCurScanKey ) : 0.f; }
00086 BOOL getKeyDown(const KEY key) { return mKeyLevel[key]; }
00087 BOOL getKeyRepeated(const KEY key) { return mKeyRepeated[key]; }
00088
00089 BOOL translateKey(const U16 os_key, KEY *translated_key);
00090 U16 inverseTranslateKey(const KEY translated_key);
00091 BOOL handleTranslatedKeyUp(KEY translated_key, U32 translated_mask);
00092 BOOL handleTranslatedKeyDown(KEY translated_key, U32 translated_mask);
00093
00094
00095 virtual BOOL handleKeyUp(const U16 key, MASK mask) = 0;
00096 virtual BOOL handleKeyDown(const U16 key, MASK mask) = 0;
00097
00098
00099
00100 virtual void resetMaskKeys() = 0;
00101 virtual void scanKeyboard() = 0;
00102
00103
00104 virtual MASK currentMask(BOOL for_mouse_event) = 0;
00105 virtual KEY currentKey() { return mCurTranslatedKey; }
00106
00107 EKeyboardInsertMode getInsertMode() { return mInsertMode; }
00108 void toggleInsertMode();
00109
00110 static BOOL maskFromString(const LLString& str, MASK *mask);
00111 static BOOL keyFromString(const LLString& str, KEY *key);
00112 static LLString stringFromKey(KEY key);
00113
00114 e_numpad_distinct getNumpadDistinct() { return mNumpadDistinct; }
00115 void setNumpadDistinct(e_numpad_distinct val) { mNumpadDistinct = val; }
00116
00117 void setCallbacks(LLWindowCallbacks *cbs) { mCallbacks = cbs; }
00118 F32 getKeyElapsedTime( KEY key );
00119 S32 getKeyElapsedFrameCount( KEY key );
00120
00121 protected:
00122 void addKeyName(KEY key, const LLString& name);
00123
00124 protected:
00125 std::map<U16, KEY> mTranslateKeyMap;
00126 std::map<KEY, U16> mInvTranslateKeyMap;
00127 LLWindowCallbacks *mCallbacks;
00128
00129 LLTimer mKeyLevelTimer[KEY_COUNT];
00130 S32 mKeyLevelFrameCount[KEY_COUNT];
00131 BOOL mKeyLevel[KEY_COUNT];
00132 BOOL mKeyRepeated[KEY_COUNT];
00133 BOOL mKeyUp[KEY_COUNT];
00134 BOOL mKeyDown[KEY_COUNT];
00135 KEY mCurTranslatedKey;
00136 KEY mCurScanKey;
00137
00138 e_numpad_distinct mNumpadDistinct;
00139
00140 EKeyboardInsertMode mInsertMode;
00141
00142 static std::map<KEY,LLString> sKeysToNames;
00143 static std::map<LLString,KEY> sNamesToKeys;
00144 };
00145
00146 extern LLKeyboard *gKeyboard;
00147
00148 #endif