PageRenderTime 49ms CodeModel.GetById 13ms app.highlight 31ms RepoModel.GetById 1ms 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
  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
 27#ifndef LL_LLSLIDERCTRL_H
 28#define LL_LLSLIDERCTRL_H
 29
 30#include "lluictrl.h"
 31#include "v4color.h"
 32#include "llslider.h"
 33#include "lltextbox.h"
 34#include "llrect.h"
 35#include "lllineeditor.h"
 36
 37
 38class LLSliderCtrl : public LLF32UICtrl
 39{
 40public:
 41	struct Params : public LLInitParam::Block<Params, LLF32UICtrl::Params>
 42	{
 43		Optional<std::string>   orientation;
 44		Optional<S32>			label_width;
 45		Optional<S32>			text_width;
 46		Optional<bool>			show_text;
 47		Optional<bool>			can_edit_text;
 48		Optional<bool>			is_volume_slider;
 49		Optional<S32>			decimal_digits;
 50
 51		Optional<LLUIColor>		text_color,
 52								text_disabled_color;
 53
 54		Optional<CommitCallbackParam>	mouse_down_callback,
 55										mouse_up_callback;
 56
 57		Optional<LLSlider::Params>		slider_bar;
 58		Optional<LLLineEditor::Params>	value_editor;
 59		Optional<LLTextBox::Params>		value_text;
 60		Optional<LLTextBox::Params>		slider_label;
 61
 62		Params()
 63		:	text_width("text_width"),
 64			label_width("label_width"),
 65			show_text("show_text"),
 66			can_edit_text("can_edit_text"),
 67			is_volume_slider("volume"),
 68			decimal_digits("decimal_digits", 3),
 69			text_color("text_color"),
 70			text_disabled_color("text_disabled_color"),
 71			slider_bar("slider_bar"),
 72			value_editor("value_editor"),
 73			value_text("value_text"),
 74			slider_label("slider_label"),
 75			mouse_down_callback("mouse_down_callback"),
 76			mouse_up_callback("mouse_up_callback"),
 77			orientation("orientation", std::string ("horizontal"))
 78		{}
 79	};
 80protected:
 81	LLSliderCtrl(const Params&);
 82	friend class LLUICtrlFactory;
 83public:
 84	virtual ~LLSliderCtrl() {} // Children all cleaned up by default view destructor.
 85
 86	/*virtual*/ F32	getValueF32() const { return mSlider->getValueF32(); }
 87	void			setValue(F32 v, BOOL from_event = FALSE);
 88
 89	/*virtual*/ void	setValue(const LLSD& value)	{ setValue((F32)value.asReal(), TRUE); }
 90	/*virtual*/ LLSD	getValue() const			{ return LLSD(getValueF32()); }
 91	/*virtual*/ BOOL	setLabelArg( const std::string& key, const LLStringExplicit& text );
 92
 93	BOOL			isMouseHeldDown() const { return mSlider->hasMouseCapture(); }
 94
 95	virtual void	setPrecision(S32 precision);
 96
 97	/*virtual*/ void    setEnabled( BOOL b );
 98	/*virtual*/ void	clear();
 99
100	/*virtual*/ void	setMinValue(const LLSD& min_value)  { setMinValue((F32)min_value.asReal()); }
101	/*virtual*/ void	setMaxValue(const LLSD& max_value)  { setMaxValue((F32)max_value.asReal()); }
102	/*virtual*/ void	setMinValue(F32 min_value)  { mSlider->setMinValue(min_value); updateText(); }
103	/*virtual*/ void	setMaxValue(F32 max_value)  { mSlider->setMaxValue(max_value); updateText(); }
104	/*virtual*/ void	setIncrement(F32 increment) { mSlider->setIncrement(increment);}
105
106	F32				getMinValue() const { return mSlider->getMinValue(); }
107	F32				getMaxValue() const { return mSlider->getMaxValue(); }
108
109	void			setLabel(const LLStringExplicit& label)		{ if (mLabelBox) mLabelBox->setText(label); }
110	void			setLabelColor(const LLColor4& c)			{ mTextEnabledColor = c; }
111	void			setDisabledLabelColor(const LLColor4& c)	{ mTextDisabledColor = c; }
112
113	boost::signals2::connection setSliderMouseDownCallback(	const commit_signal_t::slot_type& cb );
114	boost::signals2::connection setSliderMouseUpCallback( const commit_signal_t::slot_type& cb );
115
116	/*virtual*/ void	onTabInto();
117
118	/*virtual*/ void	setTentative(BOOL b);			// marks value as tentative
119	/*virtual*/ void	onCommit();						// mark not tentative, then commit
120
121	/*virtual*/ void	setControlName(const std::string& control_name, LLView* context)
122	{
123		LLUICtrl::setControlName(control_name, context);
124		mSlider->setControlName(control_name, context);
125	}
126
127	static void		onSliderCommit(LLUICtrl* caller, const LLSD& userdata);
128	
129	static void		onEditorCommit(LLUICtrl* ctrl, const LLSD& userdata);
130	static void		onEditorGainFocus(LLFocusableElement* caller, void *userdata);
131	static void		onEditorChangeFocus(LLUICtrl* caller, S32 direction, void *userdata);
132
133private:
134	void			updateText();
135	void			reportInvalidData();
136
137	const LLFontGL*	mFont;
138	const LLFontGL*	mLabelFont;
139	BOOL			mShowText;
140	BOOL			mCanEditText;
141	
142	S32				mPrecision;
143	LLTextBox*		mLabelBox;
144	S32				mLabelWidth;
145	
146	F32				mValue;
147	LLSlider*		mSlider;
148	class LLLineEditor*	mEditor;
149	LLTextBox*		mTextBox;
150
151	LLUIColor	mTextEnabledColor;
152	LLUIColor	mTextDisabledColor;
153};
154
155#endif  // LL_LLSLIDERCTRL_H
156