PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llsliderctrl.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 156 lines | 102 code | 29 blank | 25 comment | 1 complexity | d2d64c82333ae775c9397e1928ee0a31 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llsliderctrl.h
  3. * @brief Decorated wrapper for a LLSlider.
  4. *
  5. * $LicenseInfo:firstyear=2002&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_LLSLIDERCTRL_H
  27. #define LL_LLSLIDERCTRL_H
  28. #include "lluictrl.h"
  29. #include "v4color.h"
  30. #include "llslider.h"
  31. #include "lltextbox.h"
  32. #include "llrect.h"
  33. #include "lllineeditor.h"
  34. class LLSliderCtrl : public LLF32UICtrl
  35. {
  36. public:
  37. struct Params : public LLInitParam::Block<Params, LLF32UICtrl::Params>
  38. {
  39. Optional<std::string> orientation;
  40. Optional<S32> label_width;
  41. Optional<S32> text_width;
  42. Optional<bool> show_text;
  43. Optional<bool> can_edit_text;
  44. Optional<bool> is_volume_slider;
  45. Optional<S32> decimal_digits;
  46. Optional<LLUIColor> text_color,
  47. text_disabled_color;
  48. Optional<CommitCallbackParam> mouse_down_callback,
  49. mouse_up_callback;
  50. Optional<LLSlider::Params> slider_bar;
  51. Optional<LLLineEditor::Params> value_editor;
  52. Optional<LLTextBox::Params> value_text;
  53. Optional<LLTextBox::Params> slider_label;
  54. Params()
  55. : text_width("text_width"),
  56. label_width("label_width"),
  57. show_text("show_text"),
  58. can_edit_text("can_edit_text"),
  59. is_volume_slider("volume"),
  60. decimal_digits("decimal_digits", 3),
  61. text_color("text_color"),
  62. text_disabled_color("text_disabled_color"),
  63. slider_bar("slider_bar"),
  64. value_editor("value_editor"),
  65. value_text("value_text"),
  66. slider_label("slider_label"),
  67. mouse_down_callback("mouse_down_callback"),
  68. mouse_up_callback("mouse_up_callback"),
  69. orientation("orientation", std::string ("horizontal"))
  70. {}
  71. };
  72. protected:
  73. LLSliderCtrl(const Params&);
  74. friend class LLUICtrlFactory;
  75. public:
  76. virtual ~LLSliderCtrl() {} // Children all cleaned up by default view destructor.
  77. /*virtual*/ F32 getValueF32() const { return mSlider->getValueF32(); }
  78. void setValue(F32 v, BOOL from_event = FALSE);
  79. /*virtual*/ void setValue(const LLSD& value) { setValue((F32)value.asReal(), TRUE); }
  80. /*virtual*/ LLSD getValue() const { return LLSD(getValueF32()); }
  81. /*virtual*/ BOOL setLabelArg( const std::string& key, const LLStringExplicit& text );
  82. BOOL isMouseHeldDown() const { return mSlider->hasMouseCapture(); }
  83. virtual void setPrecision(S32 precision);
  84. /*virtual*/ void setEnabled( BOOL b );
  85. /*virtual*/ void clear();
  86. /*virtual*/ void setMinValue(const LLSD& min_value) { setMinValue((F32)min_value.asReal()); }
  87. /*virtual*/ void setMaxValue(const LLSD& max_value) { setMaxValue((F32)max_value.asReal()); }
  88. /*virtual*/ void setMinValue(F32 min_value) { mSlider->setMinValue(min_value); updateText(); }
  89. /*virtual*/ void setMaxValue(F32 max_value) { mSlider->setMaxValue(max_value); updateText(); }
  90. /*virtual*/ void setIncrement(F32 increment) { mSlider->setIncrement(increment);}
  91. F32 getMinValue() const { return mSlider->getMinValue(); }
  92. F32 getMaxValue() const { return mSlider->getMaxValue(); }
  93. void setLabel(const LLStringExplicit& label) { if (mLabelBox) mLabelBox->setText(label); }
  94. void setLabelColor(const LLColor4& c) { mTextEnabledColor = c; }
  95. void setDisabledLabelColor(const LLColor4& c) { mTextDisabledColor = c; }
  96. boost::signals2::connection setSliderMouseDownCallback( const commit_signal_t::slot_type& cb );
  97. boost::signals2::connection setSliderMouseUpCallback( const commit_signal_t::slot_type& cb );
  98. /*virtual*/ void onTabInto();
  99. /*virtual*/ void setTentative(BOOL b); // marks value as tentative
  100. /*virtual*/ void onCommit(); // mark not tentative, then commit
  101. /*virtual*/ void setControlName(const std::string& control_name, LLView* context)
  102. {
  103. LLUICtrl::setControlName(control_name, context);
  104. mSlider->setControlName(control_name, context);
  105. }
  106. static void onSliderCommit(LLUICtrl* caller, const LLSD& userdata);
  107. static void onEditorCommit(LLUICtrl* ctrl, const LLSD& userdata);
  108. static void onEditorGainFocus(LLFocusableElement* caller, void *userdata);
  109. static void onEditorChangeFocus(LLUICtrl* caller, S32 direction, void *userdata);
  110. private:
  111. void updateText();
  112. void reportInvalidData();
  113. const LLFontGL* mFont;
  114. const LLFontGL* mLabelFont;
  115. BOOL mShowText;
  116. BOOL mCanEditText;
  117. S32 mPrecision;
  118. LLTextBox* mLabelBox;
  119. S32 mLabelWidth;
  120. F32 mValue;
  121. LLSlider* mSlider;
  122. class LLLineEditor* mEditor;
  123. LLTextBox* mTextBox;
  124. LLUIColor mTextEnabledColor;
  125. LLUIColor mTextDisabledColor;
  126. };
  127. #endif // LL_LLSLIDERCTRL_H