00001
00032 #ifndef LL_LLSLIDERCTRL_H
00033 #define LL_LLSLIDERCTRL_H
00034
00035 #include "lluictrl.h"
00036 #include "v4color.h"
00037 #include "llslider.h"
00038 #include "lltextbox.h"
00039 #include "llrect.h"
00040
00041
00042
00043
00044 const S32 SLIDERCTRL_SPACING = 4;
00045 const S32 SLIDERCTRL_HEIGHT = 16;
00046
00047
00048 class LLSliderCtrl : public LLUICtrl
00049 {
00050 public:
00051 LLSliderCtrl(const LLString& name,
00052 const LLRect& rect,
00053 const LLString& label,
00054 const LLFontGL* font,
00055 S32 slider_left,
00056 S32 text_left,
00057 BOOL show_text,
00058 BOOL can_edit_text,
00059 BOOL volume,
00060 void (*commit_callback)(LLUICtrl*, void*),
00061 void* callback_userdata,
00062 F32 initial_value, F32 min_value, F32 max_value, F32 increment,
00063 const LLString& control_which = LLString::null );
00064
00065 virtual ~LLSliderCtrl() {}
00066
00067 virtual LLXMLNodePtr getXML(bool save_children = true) const;
00068 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00069
00070 F32 getValueF32() const { return mSlider->getValueF32(); }
00071 void setValue(F32 v, BOOL from_event = FALSE);
00072
00073 virtual void setValue(const LLSD& value) { setValue((F32)value.asReal(), TRUE); }
00074 virtual LLSD getValue() const { return LLSD(getValueF32()); }
00075 virtual BOOL setLabelArg( const LLString& key, const LLStringExplicit& text );
00076
00077 virtual void setMinValue(LLSD min_value) { setMinValue((F32)min_value.asReal()); }
00078 virtual void setMaxValue(LLSD max_value) { setMaxValue((F32)max_value.asReal()); }
00079
00080 BOOL isMouseHeldDown() const { return mSlider->hasMouseCapture(); }
00081
00082 virtual void setEnabled( BOOL b );
00083 virtual void clear();
00084 virtual void setPrecision(S32 precision);
00085 void setMinValue(F32 min_value) { mSlider->setMinValue(min_value); updateText(); }
00086 void setMaxValue(F32 max_value) { mSlider->setMaxValue(max_value); updateText(); }
00087 void setIncrement(F32 increment) { mSlider->setIncrement(increment);}
00088
00089 F32 getMinValue() { return mSlider->getMinValue(); }
00090 F32 getMaxValue() { return mSlider->getMaxValue(); }
00091
00092 void setLabel(const LLStringExplicit& label) { if (mLabelBox) mLabelBox->setText(label); }
00093 void setLabelColor(const LLColor4& c) { mTextEnabledColor = c; }
00094 void setDisabledLabelColor(const LLColor4& c) { mTextDisabledColor = c; }
00095
00096 void setSliderMouseDownCallback( void (*slider_mousedown_callback)(LLUICtrl* caller, void* userdata) );
00097 void setSliderMouseUpCallback( void (*slider_mouseup_callback)(LLUICtrl* caller, void* userdata) );
00098
00099 virtual void onTabInto();
00100
00101 virtual void setTentative(BOOL b);
00102 virtual void onCommit();
00103
00104 virtual void setControlName(const LLString& control_name, LLView* context)
00105 {
00106 LLView::setControlName(control_name, context);
00107 mSlider->setControlName(control_name, context);
00108 }
00109
00110 virtual LLString getControlName() const { return mSlider->getControlName(); }
00111
00112 static void onSliderCommit(LLUICtrl* caller, void* userdata);
00113 static void onSliderMouseDown(LLUICtrl* caller,void* userdata);
00114 static void onSliderMouseUp(LLUICtrl* caller,void* userdata);
00115
00116 static void onEditorCommit(LLUICtrl* caller, void* userdata);
00117 static void onEditorGainFocus(LLFocusableElement* caller, void *userdata);
00118 static void onEditorChangeFocus(LLUICtrl* caller, S32 direction, void *userdata);
00119
00120 private:
00121 void updateText();
00122 void reportInvalidData();
00123
00124 const LLFontGL* mFont;
00125 BOOL mShowText;
00126 BOOL mCanEditText;
00127 BOOL mVolumeSlider;
00128
00129 S32 mPrecision;
00130 LLTextBox* mLabelBox;
00131 S32 mLabelWidth;
00132
00133 F32 mValue;
00134 LLSlider* mSlider;
00135 class LLLineEditor* mEditor;
00136 LLTextBox* mTextBox;
00137
00138 LLColor4 mTextEnabledColor;
00139 LLColor4 mTextDisabledColor;
00140
00141 void (*mSliderMouseUpCallback)( LLUICtrl* ctrl, void* userdata );
00142 void (*mSliderMouseDownCallback)( LLUICtrl* ctrl, void* userdata );
00143 };
00144
00145 #endif // LL_LLSLIDERCTRL_H