llscrollbar.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * @file llscrollbar.h
  3. * @brief Scrollbar UI widget
  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. #ifndef LL_SCROLLBAR_H
  33. #define LL_SCROLLBAR_H
  34. #include "llcolor4.h"
  35. #include "lluictrl.h"
  36. constexpr S32 SCROLLBAR_SIZE = 16;
  37. class LLScrollbar : public LLUICtrl
  38. {
  39. public:
  40. enum ORIENTATION { HORIZONTAL, VERTICAL };
  41. LLScrollbar(const std::string& name, LLRect rect, ORIENTATION orientation,
  42. S32 doc_size, S32 doc_pos, S32 page_size,
  43. void (*change_callback)(S32, LLScrollbar*, void*),
  44. void* callback_user_data = NULL, S32 step_size = 1);
  45. ~LLScrollbar() override;
  46. void setValue(const LLSD& value) override;
  47. // Overrides from LLView
  48. bool handleKeyHere(KEY key, MASK mask) override;
  49. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  50. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  51. bool handleHover(S32 x, S32 y, MASK mask) override;
  52. bool handleScrollWheel(S32 x, S32 y, S32 clicks) override;
  53. bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  54. EDragAndDropType cargo_type,
  55. void* cargo_data, EAcceptance* accept,
  56. std::string& tooltip_msg) override;
  57. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  58. void draw() override;
  59. // How long the "document" is.
  60. void setDocSize(S32 size);
  61. LL_INLINE S32 getDocSize() const { return mDocSize; }
  62. // How many "lines" the "document" has scrolled.
  63. // 0 <= DocPos <= DocSize - DocVisibile
  64. void setDocPos(S32 pos, bool update_thumb = true);
  65. S32 getDocPos() const { return mDocPos; }
  66. // Setting both at once.
  67. void setDocParams(S32 size, S32 pos);
  68. // How many "lines" of the "document" is can appear on a page.
  69. void setPageSize(S32 page_size);
  70. LL_INLINE S32 getPageSize() const { return mPageSize; }
  71. // The farthest the document can be scrolled (top of the last page).
  72. LL_INLINE S32 getDocPosMax() const { return llmax(0, mDocSize - mPageSize); }
  73. void pageUp(S32 overlap);
  74. void pageDown(S32 overlap);
  75. LL_INLINE bool isAtBeginning() { return mDocPos == 0; }
  76. LL_INLINE bool isAtEnd() { return mDocPos == getDocPosMax(); }
  77. static void onLineUpBtnPressed(void* userdata);
  78. static void onLineDownBtnPressed(void* userdata);
  79. LL_INLINE void setTrackColor(const LLColor4& c) { mTrackColor = c; }
  80. LL_INLINE void setThumbColor(const LLColor4& c) { mThumbColor = c; }
  81. LL_INLINE void setHighlightColor(const LLColor4& c) { mHighlightColor = c; }
  82. LL_INLINE void setShadowColor(const LLColor4& c) { mShadowColor = c; }
  83. LL_INLINE void setOnScrollEndCallback(void (*callback)(void*), void* data)
  84. {
  85. mOnScrollEndCallback = callback;
  86. mOnScrollEndData = data;
  87. }
  88. private:
  89. void updateThumbRect();
  90. void changeLine(S32 delta, bool update_thumb);
  91. private:
  92. void (*mChangeCallback)(S32 new_pos, LLScrollbar* self,
  93. void* userdata);
  94. void* mCallbackUserData;
  95. void (*mOnScrollEndCallback)(void*);
  96. void* mOnScrollEndData;
  97. const ORIENTATION mOrientation;
  98. // Size of the document that the scrollbar is modeling. Units depend on the
  99. // user. 0 <= mDocSize.
  100. S32 mDocSize;
  101. // Position within the doc that the scrollbar is modeling, in "lines" (user
  102. // size)
  103. S32 mDocPos;
  104. // Maximum number of lines that can be seen at one time.
  105. S32 mPageSize;
  106. S32 mStepSize;
  107. LLRect mThumbRect;
  108. S32 mDragStartX;
  109. S32 mDragStartY;
  110. F32 mHoverGlowStrength;
  111. F32 mCurGlowStrength;
  112. LLRect mOrigRect;
  113. S32 mLastDelta;
  114. LLColor4 mTrackColor;
  115. LLColor4 mThumbColor;
  116. LLColor4 mFocusColor;
  117. LLColor4 mHighlightColor;
  118. LLColor4 mShadowColor;
  119. bool mDocChanged;
  120. };
  121. #endif // LL_SCROLLBAR_H