PageRenderTime 72ms CodeModel.GetById 13ms app.highlight 54ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llbutton.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 387 lines | 242 code | 89 blank | 56 comment | 0 complexity | f6601dd6c0344afc8e74e087f2d5f45c MD5 | raw file
  1/** 
  2 * @file llbutton.h
  3 * @brief Header for buttons
  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
 27#ifndef LL_LLBUTTON_H
 28#define LL_LLBUTTON_H
 29
 30#include "lluuid.h"
 31#include "llbadgeowner.h"
 32#include "llcontrol.h"
 33#include "lluictrl.h"
 34#include "v4color.h"
 35#include "llframetimer.h"
 36#include "llfontgl.h"
 37#include "lluiimage.h"
 38#include "lluistring.h"
 39
 40//
 41// Constants
 42//
 43
 44// PLEASE please use these "constants" when building your own buttons.
 45// They are loaded from settings.xml at run time.
 46extern S32	LLBUTTON_H_PAD;
 47extern S32	BTN_HEIGHT_SMALL;
 48extern S32	BTN_HEIGHT;
 49
 50//
 51// Helpful functions
 52//
 53S32 round_up(S32 grid, S32 value);
 54
 55
 56class LLUICtrlFactory;
 57
 58//
 59// Classes
 60//
 61
 62class LLButton
 63: public LLUICtrl, public LLBadgeOwner
 64{
 65public:
 66	struct Params 
 67	:	public LLInitParam::Block<Params, LLUICtrl::Params>
 68	{
 69		// text label
 70		Optional<std::string>	label_selected;
 71		Optional<bool>			label_shadow;
 72		Optional<bool>			auto_resize;
 73		Optional<bool>			use_ellipses;
 74
 75		// images
 76		Optional<LLUIImage*>	image_unselected,
 77								image_selected,
 78								image_hover_selected,
 79								image_hover_unselected,
 80								image_disabled_selected,
 81								image_disabled,
 82								image_flash,
 83								image_pressed,
 84								image_pressed_selected,
 85								image_overlay;
 86
 87		Optional<std::string>	image_overlay_alignment;
 88		
 89		// colors
 90		Optional<LLUIColor>		label_color,
 91								label_color_selected,
 92								label_color_disabled,
 93								label_color_disabled_selected,
 94								image_color,
 95								image_color_disabled,
 96								image_overlay_color,
 97								image_overlay_selected_color,
 98								image_overlay_disabled_color,
 99								flash_color;
100
101		// layout
102		Optional<S32>			pad_right;
103		Optional<S32>			pad_left;
104		Optional<S32>			pad_bottom; // under text label
105		
106		//image overlay paddings
107		Optional<S32>			image_top_pad;
108		Optional<S32>			image_bottom_pad;
109
110		/**
111		 * Space between image_overlay and label
112		 */
113		Optional<S32>			imgoverlay_label_space;
114
115		// callbacks
116		Optional<CommitCallbackParam>	click_callback, // alias -> commit_callback
117										mouse_down_callback,
118										mouse_up_callback,
119										mouse_held_callback;
120		
121		// misc
122		Optional<bool>			is_toggle,
123								scale_image,
124								commit_on_return,
125								display_pressed_state;
126		
127		Optional<F32>				hover_glow_amount;
128		Optional<TimeIntervalParam>	held_down_delay;
129
130		Optional<bool>				use_draw_context_alpha;
131		
132		Optional<LLBadge::Params>	badge;
133
134		Optional<bool>				handle_right_mouse;
135
136		Optional<S32>				button_flash_count;
137		Optional<F32>				button_flash_rate;
138
139		Params();
140	};
141	
142protected:
143	friend class LLUICtrlFactory;
144	LLButton(const Params&);
145
146public:
147
148	~LLButton();
149	// For backward compatability only
150	typedef boost::function<void(void*)> button_callback_t;
151
152	void			addImageAttributeToXML(LLXMLNodePtr node, const std::string& imageName,
153										const LLUUID&	imageID,const std::string&	xmlTagName) const;
154	virtual BOOL	handleUnicodeCharHere(llwchar uni_char);
155	virtual BOOL	handleKeyHere(KEY key, MASK mask);
156	virtual BOOL	handleMouseDown(S32 x, S32 y, MASK mask);
157	virtual BOOL	handleMouseUp(S32 x, S32 y, MASK mask);
158	virtual BOOL	handleHover(S32 x, S32 y, MASK mask);
159	virtual BOOL	handleRightMouseDown(S32 x, S32 y, MASK mask);
160	virtual BOOL	handleRightMouseUp(S32 x, S32 y, MASK mask);	
161	virtual BOOL	handleDoubleClick(S32 x, S32 y, MASK mask);
162	virtual void	draw();
163	/*virtual*/ BOOL postBuild();
164
165	virtual void	onMouseLeave(S32 x, S32 y, MASK mask);
166	virtual void	onMouseCaptureLost();
167
168	virtual void	onCommit();
169
170	void			setUnselectedLabelColor( const LLColor4& c )		{ mUnselectedLabelColor = c; }
171	void			setSelectedLabelColor( const LLColor4& c )			{ mSelectedLabelColor = c; }
172	void			setUseEllipses( BOOL use_ellipses )					{ mUseEllipses = use_ellipses; }
173
174
175	boost::signals2::connection setClickedCallback(const CommitCallbackParam& cb);
176	boost::signals2::connection setMouseDownCallback(const CommitCallbackParam& cb);
177	boost::signals2::connection setMouseUpCallback(const CommitCallbackParam& cb);
178	boost::signals2::connection setHeldDownCallback(const CommitCallbackParam& cb);
179
180	boost::signals2::connection setClickedCallback( const commit_signal_t::slot_type& cb ); // mouse down and up within button
181	boost::signals2::connection setMouseDownCallback( const commit_signal_t::slot_type& cb );
182	boost::signals2::connection setMouseUpCallback( const commit_signal_t::slot_type& cb ); // mouse up, EVEN IF NOT IN BUTTON
183	// Passes a 'count' parameter in the commit param payload, i.e. param["count"])
184	boost::signals2::connection setHeldDownCallback( const commit_signal_t::slot_type& cb ); // Mouse button held down and in button
185
186	
187	// *TODO: Deprecate (for backwards compatability only)
188	boost::signals2::connection setClickedCallback( button_callback_t cb, void* data );
189	boost::signals2::connection setMouseDownCallback( button_callback_t cb, void* data );
190	boost::signals2::connection setMouseUpCallback( button_callback_t cb, void* data );
191	boost::signals2::connection setHeldDownCallback( button_callback_t cb, void* data );
192		
193	void			setHeldDownDelay( F32 seconds, S32 frames = 0)		{ mHeldDownDelay = seconds; mHeldDownFrameDelay = frames; }
194	
195	F32				getHeldDownTime() const								{ return mMouseDownTimer.getElapsedTimeF32(); }
196
197	BOOL			toggleState();
198	BOOL			getToggleState() const;
199	void			setToggleState(BOOL b);
200
201	void			setHighlight(bool b);
202	void			setFlashing( BOOL b );
203	BOOL			getFlashing() const		{ return mFlashing; }
204
205	void			setHAlign( LLFontGL::HAlign align )		{ mHAlign = align; }
206	LLFontGL::HAlign getHAlign() const						{ return mHAlign; }
207	void			setLeftHPad( S32 pad )					{ mLeftHPad = pad; }
208	void			setRightHPad( S32 pad )					{ mRightHPad = pad; }
209
210	void 			setImageOverlayTopPad( S32 pad )			{ mImageOverlayTopPad = pad; }
211	S32 			getImageOverlayTopPad() const				{ return mImageOverlayTopPad; }
212	void 			setImageOverlayBottomPad( S32 pad )			{ mImageOverlayBottomPad = pad; }
213	S32 			getImageOverlayBottomPad() const			{ return mImageOverlayBottomPad; }
214
215	const std::string	getLabelUnselected() const { return wstring_to_utf8str(mUnselectedLabel); }
216	const std::string	getLabelSelected() const { return wstring_to_utf8str(mSelectedLabel); }
217
218	void			setImageColor(const std::string& color_control);
219	void			setImageColor(const LLColor4& c);
220	/*virtual*/ void	setColor(const LLColor4& c);
221
222	void			setImages(const std::string &image_name, const std::string &selected_name);
223	
224	void			setDisabledImageColor(const LLColor4& c)		{ mDisabledImageColor = c; }
225
226	void			setDisabledSelectedLabelColor( const LLColor4& c )	{ mDisabledSelectedLabelColor = c; }
227
228	void			setImageOverlay(const std::string& image_name, LLFontGL::HAlign alignment = LLFontGL::HCENTER, const LLColor4& color = LLColor4::white);
229	void 			setImageOverlay(const LLUUID& image_id, LLFontGL::HAlign alignment = LLFontGL::HCENTER, const LLColor4& color = LLColor4::white);
230	LLPointer<LLUIImage> getImageOverlay() { return mImageOverlay; }
231	LLFontGL::HAlign getImageOverlayHAlign() const	{ return mImageOverlayAlignment; }
232	
233	void            autoResize();	// resize with label of current btn state 
234	void            resize(LLUIString label); // resize with label input
235	void			setLabel( const LLStringExplicit& label);
236	virtual BOOL	setLabelArg( const std::string& key, const LLStringExplicit& text );
237	void			setLabelUnselected(const LLStringExplicit& label);
238	void			setLabelSelected(const LLStringExplicit& label);
239	void			setDisabledLabelColor( const LLColor4& c )		{ mDisabledLabelColor = c; }
240	
241	void			setFont(const LLFontGL *font)		
242		{ mGLFont = ( font ? font : LLFontGL::getFontSansSerif()); }
243	const LLFontGL* getFont() const { return mGLFont; }
244
245
246	S32				getLastDrawCharsCount() const { return mLastDrawCharsCount; }
247	bool			labelIsTruncated() const;
248	const LLUIString&	getCurrentLabel() const;
249
250	void			setScaleImage(BOOL scale)			{ mScaleImage = scale; }
251	BOOL			getScaleImage() const				{ return mScaleImage; }
252
253	void			setDropShadowedText(BOOL b)			{ mDropShadowedText = b; }
254
255	void			setBorderEnabled(BOOL b)					{ mBorderEnabled = b; }
256
257	void			setHoverGlowStrength(F32 strength) { mHoverGlowStrength = strength; }
258
259	void			setImageUnselected(LLPointer<LLUIImage> image);
260	void			setImageSelected(LLPointer<LLUIImage> image);
261	void			setImageHoverSelected(LLPointer<LLUIImage> image);
262	void			setImageHoverUnselected(LLPointer<LLUIImage> image);
263	void			setImageDisabled(LLPointer<LLUIImage> image);
264	void			setImageDisabledSelected(LLPointer<LLUIImage> image);
265	void			setImageFlash(LLPointer<LLUIImage> image);
266	void			setImagePressed(LLPointer<LLUIImage> image);
267	
268	void			setCommitOnReturn(BOOL commit) { mCommitOnReturn = commit; }
269	BOOL			getCommitOnReturn() const { return mCommitOnReturn; }
270
271	static void		onHeldDown(void *userdata);  // to be called by gIdleCallbacks
272	static void		toggleFloaterAndSetToggleState(LLUICtrl* ctrl, const LLSD& sdname);
273	static void		setFloaterToggle(LLUICtrl* ctrl, const LLSD& sdname);
274	static void		setDockableFloaterToggle(LLUICtrl* ctrl, const LLSD& sdname);
275	static void		showHelp(LLUICtrl* ctrl, const LLSD& sdname);
276
277	void		setForcePressedState(bool b) { mForcePressedState = b; }
278	
279	void 		setAutoResize(bool auto_resize) { mAutoResize = auto_resize; }
280
281protected:
282	LLPointer<LLUIImage> getImageUnselected() const	{ return mImageUnselected; }
283	LLPointer<LLUIImage> getImageSelected() const	{ return mImageSelected; }
284	void getOverlayImageSize(S32& overlay_width, S32& overlay_height);
285
286	LLFrameTimer	mMouseDownTimer;
287	bool			mNeedsHighlight;
288	S32				mButtonFlashCount;
289	F32				mButtonFlashRate;
290
291	void			drawBorder(LLUIImage* imagep, const LLColor4& color, S32 size);
292	void			resetMouseDownTimer();
293
294	commit_signal_t* 			mMouseDownSignal;
295	commit_signal_t* 			mMouseUpSignal;
296	commit_signal_t* 			mHeldDownSignal;
297	
298	const LLFontGL*				mGLFont;
299	
300	S32							mMouseDownFrame;
301	S32 						mMouseHeldDownCount; 	// Counter for parameter passed to held-down callback
302	F32							mHeldDownDelay;			// seconds, after which held-down callbacks get called
303	S32							mHeldDownFrameDelay;	// frames, after which held-down callbacks get called
304	S32							mLastDrawCharsCount;
305
306	LLPointer<LLUIImage>		mImageOverlay;
307	LLFontGL::HAlign			mImageOverlayAlignment;
308	LLUIColor					mImageOverlayColor;
309	LLUIColor					mImageOverlaySelectedColor;
310	LLUIColor					mImageOverlayDisabledColor;
311
312	LLPointer<LLUIImage>		mImageUnselected;
313	LLUIString					mUnselectedLabel;
314	LLUIColor					mUnselectedLabelColor;
315
316	LLPointer<LLUIImage>		mImageSelected;
317	LLUIString					mSelectedLabel;
318	LLUIColor					mSelectedLabelColor;
319
320	LLPointer<LLUIImage>		mImageHoverSelected;
321
322	LLPointer<LLUIImage>		mImageHoverUnselected;
323
324	LLPointer<LLUIImage>		mImageDisabled;
325	LLUIColor					mDisabledLabelColor;
326
327	LLPointer<LLUIImage>		mImageDisabledSelected;
328	LLUIString					mDisabledSelectedLabel;
329	LLUIColor					mDisabledSelectedLabelColor;
330
331	LLPointer<LLUIImage>		mImagePressed;
332	LLPointer<LLUIImage>		mImagePressedSelected;
333
334	/* There are two ways an image can flash- by making changes in color according to flash_color attribute
335	   or by changing icon from current to the one specified in image_flash. Second way is used only if
336	   flash icon name is set in attributes(by default it isn't). First way is used otherwise. */
337	LLPointer<LLUIImage>		mImageFlash;
338
339	LLUIColor					mFlashBgColor;
340
341	LLUIColor					mImageColor;
342	LLUIColor					mDisabledImageColor;
343
344	bool						mIsToggle;
345	bool						mScaleImage;
346
347	bool						mDropShadowedText;
348	bool						mAutoResize;
349	bool						mUseEllipses;
350	bool						mBorderEnabled;
351	bool						mFlashing;
352
353	LLFontGL::HAlign			mHAlign;
354	S32							mLeftHPad;
355	S32							mRightHPad;
356	S32							mBottomVPad;	// under text label
357
358	S32							mImageOverlayTopPad;
359	S32							mImageOverlayBottomPad;
360
361	bool						mUseDrawContextAlpha;
362
363	/*
364	 * Space between image_overlay and label
365	 */
366	S32							mImgOverlayLabelSpace;
367
368	F32							mHoverGlowStrength;
369	F32							mCurGlowStrength;
370
371	bool						mCommitOnReturn;
372	bool						mFadeWhenDisabled;
373	bool						mForcePressedState;
374	bool						mDisplayPressedState;
375
376	LLFrameTimer				mFlashingTimer;
377
378	bool						mHandleRightMouse;
379};
380
381// Build time optimization, generate once in .cpp file
382#ifndef LLBUTTON_CPP
383extern template class LLButton* LLView::getChild<class LLButton>(
384	const std::string& name, BOOL recurse) const;
385#endif
386
387#endif  // LL_LLBUTTON_H