PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llviewerkeyboard.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 117 lines | 68 code | 23 blank | 26 comment | 0 complexity | 81163e5a1258629f2f54de443f538754 MD5 | raw file
  1/** 
  2 * @file llviewerkeyboard.h
  3 * @brief LLViewerKeyboard class header file
  4 *
  5 * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLVIEWERKEYBOARD_H
 28#define LL_LLVIEWERKEYBOARD_H
 29
 30#include "llkeyboard.h" // For EKeystate
 31#include "llinitparam.h"
 32
 33const S32 MAX_NAMED_FUNCTIONS = 100;
 34const S32 MAX_KEY_BINDINGS = 128; // was 60
 35
 36class LLNamedFunction
 37{
 38public:
 39	LLNamedFunction() : mFunction(NULL) { };
 40	~LLNamedFunction() { };
 41
 42	std::string	mName;
 43	LLKeyFunc	mFunction;
 44};
 45
 46typedef enum e_keyboard_mode
 47{
 48	MODE_FIRST_PERSON,
 49	MODE_THIRD_PERSON,
 50	MODE_EDIT,
 51	MODE_EDIT_AVATAR,
 52	MODE_SITTING,
 53	MODE_COUNT
 54} EKeyboardMode;
 55
 56
 57void bind_keyboard_functions();
 58
 59class LLViewerKeyboard
 60{
 61public:
 62	struct KeyBinding : public LLInitParam::Block<KeyBinding>
 63	{
 64		Mandatory<std::string>	key,
 65								mask,
 66								command;
 67
 68		KeyBinding();
 69	};
 70
 71	struct KeyMode : public LLInitParam::Block<KeyMode>
 72	{
 73		Multiple<KeyBinding>		bindings;
 74		EKeyboardMode				mode;
 75		KeyMode(EKeyboardMode mode);
 76	};
 77
 78	struct Keys : public LLInitParam::Block<Keys>
 79	{
 80		Optional<KeyMode>	first_person,
 81							third_person,
 82							edit,
 83							sitting,
 84							edit_avatar;
 85
 86		Keys();
 87	};
 88
 89	LLViewerKeyboard();
 90
 91	BOOL			handleKey(KEY key, MASK mask, BOOL repeated);
 92
 93	S32				loadBindings(const std::string& filename);										// returns number bound, 0 on error
 94	S32				loadBindingsXML(const std::string& filename);										// returns number bound, 0 on error
 95	EKeyboardMode	getMode();
 96
 97	BOOL			modeFromString(const std::string& string, S32 *mode);			// False on failure
 98
 99	void			scanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level);
100
101private:
102	S32				loadBindingMode(const LLViewerKeyboard::KeyMode& keymode);
103	BOOL			bindKey(const S32 mode, const KEY key, const MASK mask, const std::string& function_name);
104
105	// Hold all the ugly stuff torn out to make LLKeyboard non-viewer-specific here
106	S32				mBindingCount[MODE_COUNT];
107	LLKeyBinding	mBindings[MODE_COUNT][MAX_KEY_BINDINGS];
108
109	typedef std::map<U32, U32> key_remap_t;
110	key_remap_t		mRemapKeys[MODE_COUNT];
111	std::set<KEY>	mKeysSkippedByUI;
112	BOOL			mKeyHandledByUI[KEY_COUNT];		// key processed successfully by UI
113};
114
115extern LLViewerKeyboard gViewerKeyboard;
116
117#endif // LL_LLVIEWERKEYBOARD_H