llmultisliderctrl.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /**
  2. * @file llmultisliderctrl.h
  3. * @brief LLMultiSliderCtrl base class
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-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_MULTI_SLIDERCTRL_H
  33. #define LL_MULTI_SLIDERCTRL_H
  34. #include "llcolor4.h"
  35. #include "lluictrl.h"
  36. class LLFontGL;
  37. class LLLineEditor;
  38. class LLTextBox;
  39. class LLUICtrlFactory;
  40. // Used to be in its own llmultislider.h/cpp module, and to be declared as a
  41. // "multi_slider_bar" UI control, but only actually used internally by
  42. // LLMultiSliderCtrl for which it acts as a slider sub-element of the full UI
  43. // control. HB
  44. class LLMultiSlider final : public LLUICtrl
  45. {
  46. // Only LLMultiSliderCtrl is allowed to use this class ! HB
  47. friend class LLMultiSliderCtrl;
  48. protected:
  49. LOG_CLASS(LLMultiSlider);
  50. LLMultiSlider(const std::string& name, const LLRect& rect,
  51. void (*on_commit_callback)(LLUICtrl*, void*), void* userdata,
  52. F32 initial_value, F32 min_value, F32 max_value,
  53. F32 increment, S32 max_sliders, F32 overlap_threshold,
  54. bool allow_overlap, bool loop_overlap, bool draw_track,
  55. bool use_triangle, bool vertical,
  56. const char* control_name = NULL);
  57. void setSliderValue(const std::string& name, F32 value,
  58. bool from_event = false);
  59. F32 getSliderValue(const std::string& name) const;
  60. F32 getSliderValueFromPos(S32 xpos, S32 ypos) const;
  61. LL_INLINE const std::string& getCurSlider() const
  62. {
  63. return mCurSlider;
  64. }
  65. LL_INLINE F32 getCurSliderValue() const { return getSliderValue(mCurSlider); }
  66. void setCurSlider(const std::string& name);
  67. LL_INLINE void setCurSliderValue(F32 val, bool from_event = false)
  68. {
  69. setSliderValue(mCurSlider, val, from_event);
  70. }
  71. void setValue(const LLSD& value) override;
  72. LL_INLINE LLSD getValue() const override { return mValue; }
  73. LL_INLINE void resetCurSlider() { mCurSlider.clear(); }
  74. LL_INLINE void setMinValue(LLSD min_value) override
  75. {
  76. setMinValue((F32)min_value.asReal());
  77. }
  78. LL_INLINE void setMaxValue(LLSD max_value) override
  79. {
  80. setMaxValue((F32)max_value.asReal());
  81. }
  82. LL_INLINE F32 getInitialValue() const { return mInitialValue; }
  83. LL_INLINE F32 getMinValue() const { return mMinValue; }
  84. LL_INLINE F32 getMaxValue() const { return mMaxValue; }
  85. LL_INLINE F32 getIncrement() const { return mIncrement; }
  86. LL_INLINE void setMinValue(F32 min_value) { mMinValue = min_value; }
  87. LL_INLINE void setMaxValue(F32 max_value) { mMaxValue = max_value; }
  88. LL_INLINE void setIncrement(F32 increment) { mIncrement = increment; }
  89. LL_INLINE S32 getMaxNumSliders() { return mMaxNumSliders; }
  90. LL_INLINE S32 getCurNumSliders() { return mValue.size(); }
  91. LL_INLINE bool canAddSliders() { return mValue.size() < mMaxNumSliders; }
  92. LL_INLINE void setMouseDownCallback(void (*cb)(S32 x, S32 y, void*))
  93. {
  94. mMouseDownCallback = cb;
  95. }
  96. LL_INLINE void setMouseUpCallback(void (*cb)(S32 x, S32 y, void*))
  97. {
  98. mMouseUpCallback = cb;
  99. }
  100. bool findUnusedValue(F32& init_val);
  101. const std::string& addSlider(F32 val);
  102. LL_INLINE const std::string& addSlider() { return addSlider(mInitialValue); }
  103. bool addSlider(F32 val, const std::string& name);
  104. void deleteSlider(const std::string& name);
  105. LL_INLINE void deleteCurSlider() { deleteSlider(mCurSlider); }
  106. void clear() override;
  107. bool handleHover(S32 x, S32 y, MASK mask) override;
  108. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  109. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  110. bool handleKeyHere(KEY key, MASK mask) override;
  111. void draw() override;
  112. protected:
  113. size_t mMaxNumSliders;
  114. F32 mInitialValue;
  115. F32 mMinValue;
  116. F32 mMaxValue;
  117. F32 mIncrement;
  118. S32 mMouseOffset;
  119. F32 mOverlapThreshold;
  120. void (*mMouseDownCallback)(S32 x, S32 y, void* userdata);
  121. void (*mMouseUpCallback)(S32 x, S32 y, void* userdata);
  122. LLRect mDragStartThumbRect;
  123. LLSD mValue;
  124. typedef std::map<std::string, LLRect> rect_map_t;
  125. rect_map_t mThumbRects;
  126. std::string mCurSlider;
  127. bool mAllowOverlap;
  128. bool mLoopOverlap;
  129. bool mDrawTrack;
  130. bool mUseTriangle; // Hacked in toggle to use a triangle
  131. bool mVertical;
  132. static S32 mNameCounter;
  133. };
  134. // LLMultiSliderCtrl class proper
  135. class LLMultiSliderCtrl : public LLUICtrl
  136. {
  137. protected:
  138. LOG_CLASS(LLMultiSliderCtrl);
  139. public:
  140. LLMultiSliderCtrl(const std::string& name, const LLRect& rect,
  141. const std::string& label, const LLFontGL* fontp,
  142. S32 slider_left, S32 text_left, bool show_text,
  143. bool can_edit_text,
  144. void (*commit_callback)(LLUICtrl*, void*),
  145. void* callback_userdata, F32 initial_value,
  146. F32 min_value, F32 max_value, F32 increment,
  147. S32 max_sliders, F32 overlap_threshold,
  148. bool allow_overlap, bool loop_overlap,
  149. bool draw_track, bool use_triangle, bool vertical,
  150. const char* ctrl_name = NULL);
  151. ~LLMultiSliderCtrl() override;
  152. const std::string& getTag() const override;
  153. LLXMLNodePtr getXML(bool save_children = true) const override;
  154. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  155. LLUICtrlFactory* factory);
  156. LL_INLINE F32 getSliderValue(const std::string& name) const
  157. {
  158. return mMultiSlider->getSliderValue(name);
  159. }
  160. void setSliderValue(const std::string& name, F32 value,
  161. bool from_event = false);
  162. void setValue(const LLSD& value) override;
  163. LL_INLINE LLSD getValue() const override { return mMultiSlider->getValue(); }
  164. void setLabel(const std::string& label);
  165. bool setLabelArg(const std::string& key, const std::string& text) override;
  166. LL_INLINE const std::string& getCurSlider() const
  167. {
  168. return mMultiSlider->getCurSlider();
  169. }
  170. LL_INLINE F32 getCurSliderValue() const { return mCurValue; }
  171. void setCurSlider(const std::string& name);
  172. LL_INLINE void setCurSliderValue(F32 val, bool from_event = false)
  173. {
  174. setSliderValue(mMultiSlider->getCurSlider(), val, from_event);
  175. }
  176. LL_INLINE void setMinValue(LLSD v) override { setMinValue((F32)v.asReal()); }
  177. LL_INLINE void setMaxValue(LLSD v) override { setMaxValue((F32)v.asReal()); }
  178. LL_INLINE void resetCurSlider() { mMultiSlider->resetCurSlider(); }
  179. bool isMouseHeldDown();
  180. void setEnabled(bool b) override;
  181. void clear() override;
  182. void setPrecision(S32 precision);
  183. LL_INLINE void setMinValue(F32 min_value) { mMultiSlider->setMinValue(min_value); }
  184. LL_INLINE void setMaxValue(F32 max_value) { mMultiSlider->setMaxValue(max_value); }
  185. LL_INLINE void setIncrement(F32 increment) { mMultiSlider->setIncrement(increment); }
  186. LL_INLINE F32 getSliderValueFromPos(S32 x, S32 y) const
  187. {
  188. return mMultiSlider->getSliderValueFromPos(x, y);
  189. }
  190. // For adding and deleting sliders
  191. LL_INLINE S32 getMaxNumSliders() { return mMultiSlider->getMaxNumSliders(); }
  192. LL_INLINE S32 getCurNumSliders() { return mMultiSlider->getCurNumSliders(); }
  193. LL_INLINE bool canAddSliders() { return mMultiSlider->canAddSliders(); }
  194. const std::string& addSlider();
  195. const std::string& addSlider(F32 val);
  196. bool addSlider(F32 val, const std::string& name);
  197. void deleteSlider(const std::string& name);
  198. LL_INLINE void deleteCurSlider() { deleteSlider(mMultiSlider->getCurSlider()); }
  199. LL_INLINE F32 getMinValue() { return mMultiSlider->getMinValue(); }
  200. LL_INLINE F32 getMaxValue() { return mMultiSlider->getMaxValue(); }
  201. LL_INLINE F32 getIncrement() { return mMultiSlider->getIncrement(); }
  202. LL_INLINE void setLabelColor(const LLColor4& c) { mTextEnabledColor = c; }
  203. LL_INLINE void setDisabledLabelColor(const LLColor4& c)
  204. {
  205. mTextDisabledColor = c;
  206. }
  207. void setSliderMouseDownCallback(void (*cb)(S32, S32, void*));
  208. void setSliderMouseUpCallback(void (*cb)(S32, S32, void*));
  209. void onTabInto() override;
  210. void setTentative(bool b) override; // Marks value as tentative
  211. void onCommit() override; // Marks not tentative, then commit
  212. void setControlName(const char* name, LLView* context) override;
  213. const std::string& getControlName() const override;
  214. static void onSliderCommit(LLUICtrl* caller, void* userdata);
  215. static void onSliderMouseDown(S32 x, S32 y, void* userdata);
  216. static void onSliderMouseUp(S32 x, S32 y, void* userdata);
  217. static void onEditorCommit(LLUICtrl* caller, void* userdata);
  218. static void onEditorGainFocus(LLFocusableElement* caller, void* userdata);
  219. static void onEditorChangeFocus(LLUICtrl* caller, S32 direction,
  220. void* userdata);
  221. private:
  222. void updateText();
  223. void reportInvalidData();
  224. private:
  225. const LLFontGL* mFont;
  226. F32 mCurValue;
  227. S32 mPrecision;
  228. S32 mLabelWidth;
  229. LLMultiSlider* mMultiSlider;
  230. LLLineEditor* mEditor;
  231. LLTextBox* mLabelBox;
  232. LLTextBox* mTextBox;
  233. void (*mSliderMouseUpCallback)(S32 x, S32 y, void* userdata);
  234. void (*mSliderMouseDownCallback)(S32 x, S32 y, void* userdata);
  235. LLColor4 mTextEnabledColor;
  236. LLColor4 mTextDisabledColor;
  237. bool mShowText;
  238. bool mCanEditText;
  239. };
  240. #endif // LL_MULTI_SLIDERCTRL_H