lldraghandle.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @file lldraghandle.h
  3. * @brief LLDragHandle base class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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. // A widget for dragging a view around the screen using the mouse.
  33. #ifndef LL_DRAGHANDLE_H
  34. #define LL_DRAGHANDLE_H
  35. #include "llcoord.h"
  36. #include "llrect.h"
  37. #include "llview.h"
  38. #include "llcolor4.h"
  39. class LLFontGL;
  40. class LLTextBox;
  41. class LLDragHandle : public LLView
  42. {
  43. public:
  44. LLDragHandle(const std::string& name, const LLRect& rect,
  45. const std::string& title);
  46. ~LLDragHandle() override;
  47. void setValue(const LLSD& value) override;
  48. LL_INLINE void setForeground(bool b) { mForeground = b; }
  49. LL_INLINE bool getForeground() const { return mForeground; }
  50. LL_INLINE void setMaxTitleWidth(S32 w) { mMaxTitleWidth = llmin(w, mMaxTitleWidth); }
  51. LL_INLINE S32 getMaxTitleWidth() const { return mMaxTitleWidth; }
  52. void setTitleVisible(bool visible);
  53. virtual void setTitle(const std::string& title) = 0;
  54. virtual const std::string& getTitle() const = 0;
  55. bool handleHover(S32 x, S32 y, MASK mask) override;
  56. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  57. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  58. // Mouse click (left mouse button down then up) special callback
  59. LL_INLINE void setClickedCallback(void (*cb)(S32, S32, void*),
  60. void* data = NULL)
  61. {
  62. mClickedCallback = cb;
  63. mCallbackUserData = data;
  64. }
  65. protected:
  66. void setTitleBox(LLTextBox* titlep);
  67. protected:
  68. S32 mDragLastScreenX;
  69. S32 mDragLastScreenY;
  70. S32 mLastMouseScreenX;
  71. S32 mLastMouseScreenY;
  72. S32 mMaxTitleWidth;
  73. LLTextBox* mTitleBox;
  74. LLCoordGL mLastMouseDir;
  75. void (*mClickedCallback)(S32 x, S32 y, void* data);
  76. void* mCallbackUserData;
  77. bool mForeground;
  78. };
  79. // Use this one for traditional top-of-window draggers
  80. class LLDragHandleTop : public LLDragHandle
  81. {
  82. public:
  83. LLDragHandleTop(const std::string& name,
  84. const LLRect& rect,
  85. const std::string& title);
  86. void setTitle(const std::string& title) override;
  87. const std::string& getTitle() const override;
  88. void draw() override;
  89. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  90. private:
  91. void reshapeTitleBox();
  92. private:
  93. LLFontGL* mFont;
  94. };
  95. // Use this for left-side, vertical text draggers
  96. class LLDragHandleLeft : public LLDragHandle
  97. {
  98. public:
  99. LLDragHandleLeft(const std::string& name,
  100. const LLRect& rect,
  101. const std::string& title);
  102. void setTitle(const std::string& title) override;
  103. const std::string& getTitle() const override;
  104. void draw() override;
  105. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  106. };
  107. constexpr S32 DRAG_HANDLE_HEIGHT = 16;
  108. constexpr S32 DRAG_HANDLE_WIDTH = 16;
  109. #endif // LL_DRAGHANDLE_H