PageRenderTime 30ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llscrollbar.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 165 lines | 94 code | 36 blank | 35 comment | 0 complexity | 7dfb60865b1d8f97ca58967e80ea031f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llscrollbar.h
  3. * @brief Scrollbar UI widget
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_SCROLLBAR_H
  27. #define LL_SCROLLBAR_H
  28. #include "stdtypes.h"
  29. #include "lluictrl.h"
  30. #include "v4color.h"
  31. #include "llbutton.h"
  32. //
  33. // Classes
  34. //
  35. class LLScrollbar
  36. : public LLUICtrl
  37. {
  38. public:
  39. enum ORIENTATION { HORIZONTAL, VERTICAL };
  40. typedef boost::function<void (S32, LLScrollbar*)> callback_t;
  41. struct Params
  42. : public LLInitParam::Block<Params, LLUICtrl::Params>
  43. {
  44. Mandatory<ORIENTATION> orientation;
  45. Mandatory<S32> doc_size;
  46. Mandatory<S32> doc_pos;
  47. Mandatory<S32> page_size;
  48. Optional<callback_t> change_callback;
  49. Optional<S32> step_size;
  50. Optional<S32> thickness;
  51. Optional<LLUIImage*> thumb_image_vertical,
  52. thumb_image_horizontal,
  53. track_image_horizontal,
  54. track_image_vertical;
  55. Optional<bool> bg_visible;
  56. Optional<LLUIColor> track_color,
  57. thumb_color,
  58. bg_color;
  59. Optional<LLButton::Params> up_button;
  60. Optional<LLButton::Params> down_button;
  61. Optional<LLButton::Params> left_button;
  62. Optional<LLButton::Params> right_button;
  63. Params();
  64. };
  65. protected:
  66. LLScrollbar (const Params & p);
  67. friend class LLUICtrlFactory;
  68. public:
  69. virtual ~LLScrollbar();
  70. virtual void setValue(const LLSD& value);
  71. // Overrides from LLView
  72. virtual BOOL handleKeyHere(KEY key, MASK mask);
  73. virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  74. virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask);
  75. virtual BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
  76. virtual BOOL handleHover(S32 x, S32 y, MASK mask);
  77. virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks);
  78. virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
  79. EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string &tooltip_msg);
  80. virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  81. virtual void draw();
  82. // How long the "document" is.
  83. void setDocSize( S32 size );
  84. S32 getDocSize() const { return mDocSize; }
  85. // How many "lines" the "document" has scrolled.
  86. // 0 <= DocPos <= DocSize - DocVisibile
  87. bool setDocPos( S32 pos, BOOL update_thumb = TRUE );
  88. S32 getDocPos() const { return mDocPos; }
  89. BOOL isAtBeginning();
  90. BOOL isAtEnd();
  91. // Setting both at once.
  92. void setDocParams( S32 size, S32 pos );
  93. // How many "lines" of the "document" is can appear on a page.
  94. void setPageSize( S32 page_size );
  95. S32 getPageSize() const { return mPageSize; }
  96. // The farthest the document can be scrolled (top of the last page).
  97. S32 getDocPosMax() const { return llmax( 0, mDocSize - mPageSize); }
  98. void pageUp(S32 overlap);
  99. void pageDown(S32 overlap);
  100. void onLineUpBtnPressed(const LLSD& data);
  101. void onLineDownBtnPressed(const LLSD& data);
  102. private:
  103. void updateThumbRect();
  104. bool changeLine(S32 delta, BOOL update_thumb );
  105. callback_t mChangeCallback;
  106. const ORIENTATION mOrientation;
  107. S32 mDocSize; // Size of the document that the scrollbar is modeling. Units depend on the user. 0 <= mDocSize.
  108. S32 mDocPos; // Position within the doc that the scrollbar is modeling, in "lines" (user size)
  109. S32 mPageSize; // Maximum number of lines that can be seen at one time.
  110. S32 mStepSize;
  111. BOOL mDocChanged;
  112. LLRect mThumbRect;
  113. S32 mDragStartX;
  114. S32 mDragStartY;
  115. F32 mHoverGlowStrength;
  116. F32 mCurGlowStrength;
  117. LLRect mOrigRect;
  118. S32 mLastDelta;
  119. LLUIColor mTrackColor;
  120. LLUIColor mThumbColor;
  121. LLUIColor mBGColor;
  122. bool mBGVisible;
  123. LLUIImagePtr mThumbImageV;
  124. LLUIImagePtr mThumbImageH;
  125. LLUIImagePtr mTrackImageV;
  126. LLUIImagePtr mTrackImageH;
  127. S32 mThickness;
  128. };
  129. #endif // LL_SCROLLBAR_H