lltexturectrl.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /**
  2. * @file lltexturectrl.h
  3. * @author Richard Nelson, James Cook
  4. * @brief LLTextureCtrl class header file including related functions
  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_LLTEXTURECTRL_H
  34. #define LL_LLTEXTURECTRL_H
  35. #include "llcoord.h"
  36. #include "llfloater.h"
  37. #include "llpermissionsflags.h"
  38. #include "llstring.h"
  39. #include "lluictrl.h"
  40. class LLFloaterTexturePicker;
  41. class LLInventoryItem;
  42. class LLTextBox;
  43. class LLViewBorder;
  44. class LLViewerFetchedTexture;
  45. // Used for setting drag & drop callbacks.
  46. typedef bool (*drag_n_drop_callback)(LLUICtrl*, LLInventoryItem*, void*);
  47. class LLTextureCtrl final : public LLUICtrl
  48. {
  49. protected:
  50. LOG_CLASS(LLTextureCtrl);
  51. public:
  52. typedef enum e_texture_pick_op
  53. {
  54. TEXTURE_CHANGE,
  55. TEXTURE_SELECT,
  56. TEXTURE_CANCEL
  57. } ETexturePickOp;
  58. public:
  59. LLTextureCtrl(const std::string& name, const LLRect& rect,
  60. const std::string& label, const LLUUID& image_id,
  61. const LLUUID& default_image_id,
  62. const std::string& default_image_name);
  63. ~LLTextureCtrl() override;
  64. // LLView interface
  65. const std::string& getTag() const override;
  66. LLXMLNodePtr getXML(bool save_children = true) const override;
  67. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  68. LLUICtrlFactory* factory);
  69. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  70. bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  71. EDragAndDropType cargo_type, void* cargo_data,
  72. EAcceptance* accept, std::string& tooltip) override;
  73. bool handleHover(S32 x, S32 y, MASK mask) override;
  74. bool handleUnicodeCharHere(llwchar uni_char) override;
  75. void setVisible(bool visible) override;
  76. void setEnabled(bool enabled) override;
  77. void draw() override;
  78. LL_INLINE bool isDirty() const override { return mDirty; }
  79. LL_INLINE void resetDirty() override { mDirty = false; }
  80. // LLUICtrl interface
  81. void clear() override;
  82. // Takes a UUID, wraps get/setImageAssetID
  83. void setValue(const LLSD& value) override;
  84. LLSD getValue() const override;
  85. // LLTextureCtrl interface
  86. void setValid(bool valid);
  87. void showPicker(bool take_focus);
  88. LL_INLINE bool isPickerShown() { return !mFloaterHandle.isDead(); }
  89. void setLabel(const std::string& label);
  90. LL_INLINE const std::string& getLabel() const { return mLabel; }
  91. LL_INLINE void setAllowNoTexture(bool b) { mAllowNoTexture = b; }
  92. LL_INLINE bool getAllowNoTexture() const { return mAllowNoTexture; }
  93. LL_INLINE void setAllowInvisibleTexture(bool b) { mAllowInvisibleTexture = b; }
  94. LL_INLINE bool getAllowInvisibleTexture() const { return mAllowInvisibleTexture; }
  95. LL_INLINE void setAllowLocalTexture(bool b) { mAllowLocalTexture = b; }
  96. LL_INLINE bool getAllowLocalTexture() const { return mAllowLocalTexture; }
  97. LL_INLINE const LLUUID& getImageItemID() { return mImageItemID; }
  98. void setImageAssetID(const LLUUID& image_asset_id);
  99. LL_INLINE const LLUUID& getImageAssetID() const { return mImageAssetID; }
  100. LL_INLINE void setDefaultImageAssetID(const LLUUID& id) { mDefaultImageAssetID = id; }
  101. LL_INLINE const LLUUID& getDefaultImageAssetID() const { return mDefaultImageAssetID; }
  102. LL_INLINE void setBlankImageAssetID(const LLUUID& id) { mBlankImageAssetID = id; }
  103. LL_INLINE const LLUUID& getBlankImageAssetID() const { return mBlankImageAssetID; }
  104. LL_INLINE const std::string& getDefaultImageName() const
  105. {
  106. return mDefaultImageName;
  107. }
  108. void setFallbackImageName(const std::string& name);
  109. void setCaption(const std::string& caption);
  110. LL_INLINE void setCaptionAlwaysEnabled(bool b = true) { mCaptionAlwaysEnabled = b; }
  111. void setCanApplyImmediately(bool b);
  112. void setBakeTextureEnabled(bool b);
  113. void setImmediateFilterPermMask(PermissionMask mask);
  114. LL_INLINE void setNonImmediateFilterPermMask(PermissionMask mask)
  115. {
  116. mNonImmediateFilterPermMask = mask;
  117. }
  118. LL_INLINE PermissionMask getImmediateFilterPermMask()
  119. {
  120. return mImmediateFilterPermMask;
  121. }
  122. LL_INLINE PermissionMask getNonImmediateFilterPermMask()
  123. {
  124. return mNonImmediateFilterPermMask;
  125. }
  126. void closeFloater();
  127. void onFloaterClose();
  128. void onFloaterCommit(ETexturePickOp op, const LLUUID& id = LLUUID::null,
  129. const LLUUID& tracking_id = LLUUID::null);
  130. // This call is returned when a drag is detected. Your callback should
  131. // return true if the drag is acceptable.
  132. LL_INLINE void setDragCallback(drag_n_drop_callback cb) { mDragCallback = cb; }
  133. // This callback is called when the drop happens. Return true if the drop
  134. // happened - resulting in an on commit callback, but not necessariliy any
  135. // other change.
  136. LL_INLINE void setDropCallback(drag_n_drop_callback cb) { mDropCallback = cb; }
  137. LL_INLINE void setOnCancelCallback(LLUICtrlCallback cb) { mOnCancelCallback = cb; }
  138. LL_INLINE void setOnCloseCallback(LLUICtrlCallback cb) { mOnCloseCallback = cb; }
  139. LL_INLINE void setOnSelectCallback(LLUICtrlCallback cb) { mOnSelectCallback = cb; }
  140. LL_INLINE void setShowLoadingPlaceholder(bool b) { mShowLoadingPlaceholder = b; }
  141. LL_INLINE void setDisplayRatio(F32 ratio) { mDisplayRatio = ratio; }
  142. LL_INLINE bool isImageLocal() const { return mLocalTrackingID.notNull(); }
  143. LL_INLINE const LLUUID& getLocalTrackingID() const { return mLocalTrackingID; }
  144. private:
  145. bool allowDrop(LLInventoryItem* item);
  146. bool doDrop(LLInventoryItem* item);
  147. private:
  148. LLHandle<LLFloater> mFloaterHandle;
  149. drag_n_drop_callback mDragCallback;
  150. drag_n_drop_callback mDropCallback;
  151. LLUICtrlCallback mOnCancelCallback;
  152. LLUICtrlCallback mOnCloseCallback;
  153. LLUICtrlCallback mOnSelectCallback;
  154. LLPointer<LLViewerFetchedTexture> mTexturep;
  155. // What to show if currently selected texture is null:
  156. LLPointer<LLViewerFetchedTexture> mFallbackImagep;
  157. LLColor4 mBorderColor;
  158. LLUUID mImageItemID;
  159. LLUUID mImageAssetID;
  160. LLUUID mDefaultImageAssetID;
  161. LLUUID mBlankImageAssetID;
  162. LLUUID mLocalTrackingID;
  163. LLTextBox* mCaption;
  164. LLViewBorder* mBorder;
  165. LLTextBox* mTentativeLabel;
  166. std::string mFallbackImageName;
  167. std::string mDefaultImageName;
  168. std::string mLabel;
  169. LLWString mLoadingPlaceholderString;
  170. LLCoordGL mLastFloaterLeftTop;
  171. F32 mDisplayRatio;
  172. PermissionMask mImmediateFilterPermMask;
  173. PermissionMask mNonImmediateFilterPermMask;
  174. // If true, the user can select "none" as an option:
  175. bool mAllowNoTexture;
  176. // If true, the user can select "Invisible" as an option:
  177. bool mAllowInvisibleTexture;
  178. bool mCanApplyImmediately;
  179. bool mAllowLocalTexture;
  180. bool mValid;
  181. bool mDirty;
  182. bool mEnabled;
  183. bool mCaptionAlwaysEnabled;
  184. bool mShowLoadingPlaceholder;
  185. bool mBakeTextureEnabled;
  186. };
  187. #endif // LL_LLTEXTURECTRL_H