llviewerkeyboard.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * @file llviewerkeyboard.h
  3. * @brief LLViewerKeyboard class header file
  4. *
  5. * $LicenseInfo:firstyear=2005&license=viewergpl$
  6. *
  7. * Copyright (c) 2005-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVIEWERKEYBOARD_H
  33. #define LL_LLVIEWERKEYBOARD_H
  34. #include "llkeyboard.h" // For EKeystate
  35. constexpr S32 MAX_NAMED_FUNCTIONS = 100;
  36. constexpr S32 MAX_KEY_BINDINGS = 128; // was 60
  37. class LLNamedFunction
  38. {
  39. public:
  40. LLNamedFunction() : mFunction(NULL) {}
  41. ~LLNamedFunction() {}
  42. std::string mName;
  43. LLKeyFunc mFunction;
  44. };
  45. typedef enum e_keyboard_mode
  46. {
  47. MODE_FIRST_PERSON,
  48. MODE_THIRD_PERSON,
  49. MODE_EDIT,
  50. MODE_EDIT_AVATAR,
  51. MODE_SITTING,
  52. MODE_COUNT
  53. } EKeyboardMode;
  54. void bind_keyboard_functions();
  55. class LLViewerKeyboard
  56. {
  57. protected:
  58. LOG_CLASS(LLViewerKeyboard);
  59. public:
  60. LLViewerKeyboard();
  61. bool handleKey(KEY key, MASK mask, bool repeated);
  62. bool handleKeyUp(KEY key, MASK mask);
  63. void bindNamedFunction(const std::string& name, LLKeyFunc func);
  64. // Returns number bound, 0 on error
  65. S32 loadBindings(const std::string& filename);
  66. EKeyboardMode getMode();
  67. // false on failure
  68. bool modeFromString(const std::string& string, S32* mode);
  69. void scanKey(KEY key, bool key_down, bool key_up, bool key_level);
  70. protected:
  71. bool bindKey(S32 mode, KEY key, MASK mask, const std::string& func_name);
  72. protected:
  73. S32 mNamedFunctionCount;
  74. LLNamedFunction mNamedFunctions[MAX_NAMED_FUNCTIONS];
  75. // Hold all the ugly stuff torn out to make LLKeyboard non-viewer-specific
  76. // here
  77. S32 mBindingCount[MODE_COUNT];
  78. LLKeyBinding mBindings[MODE_COUNT][MAX_KEY_BINDINGS];
  79. typedef std::map<U32, U32> key_remap_t;
  80. key_remap_t mRemapKeys[MODE_COUNT];
  81. std::set<KEY> mKeysSkippedByUI;
  82. // Key processed successfully by UI
  83. bool mKeyHandledByUI[KEY_COUNT];
  84. };
  85. extern LLViewerKeyboard gViewerKeyboard;
  86. #endif // LL_LLVIEWERKEYBOARD_H