llgesture.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @file llgesture.h
  3. * @brief A gesture is a combination of a triggering chat phrase or
  4. * key, a sound, an animation, and a chat string.
  5. *
  6. * $LicenseInfo:firstyear=2002&license=viewergpl$
  7. *
  8. * Copyright (c) 2002-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLGESTURE_H
  34. #define LL_LLGESTURE_H
  35. #include <vector>
  36. #include "llanimationstates.h"
  37. #include "llstring.h"
  38. #include "lluuid.h"
  39. class LLGesture
  40. {
  41. protected:
  42. LOG_CLASS(LLGesture);
  43. public:
  44. LLGesture();
  45. LLGesture(KEY key, MASK mask, const std::string& trigger,
  46. const LLUUID& sound_item_id, const std::string& animation,
  47. const std::string& output_string);
  48. LLGesture(U8** buffer, S32 max_size); // Deserializes, advances buffer
  49. LLGesture(const LLGesture& gesture);
  50. const LLGesture& operator=(const LLGesture& rhs);
  51. virtual ~LLGesture() = default;
  52. // Accessors
  53. LL_INLINE KEY getKey() const { return mKey; }
  54. LL_INLINE MASK getMask() const { return mMask; }
  55. LL_INLINE const std::string& getTrigger() const { return mTrigger; }
  56. LL_INLINE const LLUUID& getSound() const { return mSoundItemID; }
  57. LL_INLINE const std::string& getAnimation() const { return mAnimation; }
  58. LL_INLINE const std::string& getOutputString() const { return mOutputString; }
  59. // Triggers if a key/mask matches it
  60. virtual bool trigger(KEY key, MASK mask);
  61. // Triggers if case-insensitive substring matches (assumes string is
  62. // lowercase)
  63. virtual bool trigger(const std::string& string);
  64. // Non-endian-neutral serialization
  65. U8* serialize(U8* buffer) const;
  66. U8* deserialize(U8* buffer, S32 max_size);
  67. static S32 getMaxSerialSize();
  68. protected:
  69. KEY mKey; // usually a function key
  70. MASK mMask; // usually MASK_NONE, or MASK_SHIFT
  71. std::string mTrigger; // string, no whitespace allowed
  72. std::string mTriggerLower; // lowercase version of mTrigger
  73. LLUUID mSoundItemID; // ItemID of sound to play, LLUUID::null if none
  74. std::string mAnimation; // canonical name of animation or face animation
  75. std::string mOutputString; // string to say
  76. // For allocating serialization buffers; need to be updated when members
  77. // change
  78. static constexpr S32 MAX_SERIAL_SIZE = sizeof(KEY) + sizeof(MASK) +
  79. 16 + 26 + 41 + 41;
  80. };
  81. class LLGestureList
  82. {
  83. protected:
  84. LOG_CLASS(LLGestureList);
  85. public:
  86. LLGestureList();
  87. virtual ~LLGestureList();
  88. // Triggers if a key/mask matches one in the list
  89. bool trigger(KEY key, MASK mask);
  90. // Triggers if substring matches and generates revised string.
  91. bool triggerAndReviseString(const std::string& string,
  92. std::string* revised_string);
  93. // Used for construction from UI
  94. LL_INLINE S32 count() const { return mList.size(); }
  95. virtual LLGesture* get(S32 i) const { return mList[i]; }
  96. virtual void put(LLGesture* gesture) { mList.push_back(gesture); }
  97. void deleteAll();
  98. // non-endian-neutral serialization
  99. U8* serialize(U8* buffer) const;
  100. U8* deserialize(U8* buffer, S32 max_size);
  101. S32 getMaxSerialSize();
  102. protected:
  103. // overridden by child class to use local LLGesture implementation
  104. virtual LLGesture *create_gesture(U8** buffer, S32 max_size);
  105. protected:
  106. std::vector<LLGesture*> mList;
  107. // For allocating serialization buffers; need to be updated when members
  108. // change
  109. static constexpr S32 SERIAL_HEADER_SIZE = sizeof(S32);
  110. };
  111. #endif