aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llwindow/llkeyboard.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llwindow/llkeyboard.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llwindow/llkeyboard.h')
-rw-r--r--linden/indra/llwindow/llkeyboard.h144
1 files changed, 144 insertions, 0 deletions
diff --git a/linden/indra/llwindow/llkeyboard.h b/linden/indra/llwindow/llkeyboard.h
new file mode 100644
index 0000000..e262ab6
--- /dev/null
+++ b/linden/indra/llwindow/llkeyboard.h
@@ -0,0 +1,144 @@
1/**
2 * @file llkeyboard.h
3 * @brief Handler for assignable key bindings
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LLKEYBOARD_H
29#define LL_LLKEYBOARD_H
30
31#include <map>
32
33#include "string_table.h"
34#include "lltimer.h"
35#include "indra_constants.h"
36
37enum EKeystate
38{
39 KEYSTATE_DOWN,
40 KEYSTATE_LEVEL,
41 KEYSTATE_UP
42};
43
44typedef void (*LLKeyFunc)(EKeystate keystate);
45
46enum EKeyboardInsertMode
47{
48 LL_KIM_INSERT,
49 LL_KIM_OVERWRITE
50};
51
52class LLKeyBinding
53{
54public:
55 KEY mKey;
56 MASK mMask;
57// const char *mName; // unused
58 LLKeyFunc mFunction;
59};
60
61class LLWindowCallbacks;
62
63class LLKeyboard
64{
65public:
66 typedef enum e_numpad_distinct
67 {
68 ND_NEVER,
69 ND_NUMLOCK_OFF,
70 ND_NUMLOCK_ON
71 } ENumpadDistinct;
72
73public:
74 LLKeyboard();
75 virtual ~LLKeyboard();
76
77 void resetKeys();
78
79
80 F32 getCurKeyElapsedTime() { return getKeyDown(mCurScanKey) ? getKeyElapsedTime( mCurScanKey ) : 0.f; }
81 F32 getCurKeyElapsedFrameCount() { return getKeyDown(mCurScanKey) ? (F32)getKeyElapsedFrameCount( mCurScanKey ) : 0.f; }
82 BOOL getKeyDown(const KEY key) { return mKeyLevel[key]; }
83 BOOL getKeyRepeated(const KEY key) { return mKeyRepeated[key]; }
84
85 BOOL translateKey(const U16 os_key, KEY *translated_key);
86 U16 inverseTranslateKey(const KEY translated_key);
87 BOOL handleTranslatedKeyUp(KEY translated_key, U32 translated_mask); // Translated into "Linden" keycodes
88 BOOL handleTranslatedKeyDown(KEY translated_key, U32 translated_mask); // Translated into "Linden" keycodes
89
90
91 virtual BOOL handleKeyUp(const U16 key, MASK mask) = 0;
92 virtual BOOL handleKeyDown(const U16 key, MASK mask) = 0;
93
94 // Asynchronously poll the control, alt, and shift keys and set the
95 // appropriate internal key masks.
96 virtual void resetMaskKeys() = 0;
97 virtual void scanKeyboard() = 0; // scans keyboard, calls functions as necessary
98 // Mac must differentiate between Command = Control for keyboard events
99 // and Command != Control for mouse events.
100 virtual MASK currentMask(BOOL for_mouse_event) = 0;
101 virtual KEY currentKey() { return mCurTranslatedKey; }
102
103 EKeyboardInsertMode getInsertMode() { return mInsertMode; }
104 void toggleInsertMode();
105
106 static BOOL maskFromString(const LLString& str, MASK *mask); // False on failure
107 static BOOL keyFromString(const LLString& str, KEY *key); // False on failure
108 static LLString stringFromKey(KEY key);
109
110 e_numpad_distinct getNumpadDistinct() { return mNumpadDistinct; }
111 void setNumpadDistinct(e_numpad_distinct val) { mNumpadDistinct = val; }
112
113 void setCallbacks(LLWindowCallbacks *cbs) { mCallbacks = cbs; }
114 F32 getKeyElapsedTime( KEY key ); // Returns time in seconds since key was pressed.
115 S32 getKeyElapsedFrameCount( KEY key ); // Returns time in frames since key was pressed.
116
117protected:
118 void addKeyName(KEY key, const LLString& name);
119
120protected:
121 std::map<U16, KEY> mTranslateKeyMap; // Map of translations from OS keys to Linden KEYs
122 std::map<KEY, U16> mInvTranslateKeyMap; // Map of translations from Linden KEYs to OS keys
123 LLWindowCallbacks *mCallbacks;
124
125 LLTimer mKeyLevelTimer[KEY_COUNT]; // Time since level was set
126 S32 mKeyLevelFrameCount[KEY_COUNT]; // Frames since level was set
127 BOOL mKeyLevel[KEY_COUNT]; // Levels
128 BOOL mKeyRepeated[KEY_COUNT]; // Key was repeated
129 BOOL mKeyUp[KEY_COUNT]; // Up edge
130 BOOL mKeyDown[KEY_COUNT]; // Down edge
131 KEY mCurTranslatedKey;
132 KEY mCurScanKey; // Used during the scanKeyboard()
133
134 e_numpad_distinct mNumpadDistinct;
135
136 EKeyboardInsertMode mInsertMode;
137
138 static std::map<KEY,LLString> sKeysToNames;
139 static std::map<LLString,KEY> sNamesToKeys;
140};
141
142extern LLKeyboard *gKeyboard;
143
144#endif