PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llscrollbar.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 165 lines | 94 code | 36 blank | 35 comment | 0 complexity | 7dfb60865b1d8f97ca58967e80ea031f MD5 | raw file
  1/** 
  2 * @file llscrollbar.h
  3 * @brief Scrollbar UI widget
  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_SCROLLBAR_H
 28#define LL_SCROLLBAR_H
 29
 30#include "stdtypes.h"
 31#include "lluictrl.h"
 32#include "v4color.h"
 33#include "llbutton.h"
 34
 35//
 36// Classes
 37//
 38class LLScrollbar
 39: public LLUICtrl
 40{
 41public:
 42
 43	enum ORIENTATION { HORIZONTAL, VERTICAL };
 44	
 45	typedef boost::function<void (S32, LLScrollbar*)> callback_t;
 46	struct Params 
 47	:	public LLInitParam::Block<Params, LLUICtrl::Params>
 48	{
 49		Mandatory<ORIENTATION>			orientation;
 50		Mandatory<S32>					doc_size;
 51		Mandatory<S32>					doc_pos;
 52		Mandatory<S32>					page_size;
 53
 54		Optional<callback_t> 			change_callback;
 55		Optional<S32>					step_size;
 56		Optional<S32>					thickness;
 57
 58		Optional<LLUIImage*>			thumb_image_vertical,
 59										thumb_image_horizontal,
 60										track_image_horizontal,
 61										track_image_vertical;
 62
 63		Optional<bool>					bg_visible;
 64
 65		Optional<LLUIColor>				track_color,
 66										thumb_color,
 67										bg_color;
 68
 69		Optional<LLButton::Params>		up_button;
 70		Optional<LLButton::Params>		down_button;
 71		Optional<LLButton::Params>		left_button;
 72		Optional<LLButton::Params>		right_button;
 73
 74		Params();
 75	};
 76
 77protected:
 78	LLScrollbar (const Params & p);
 79	friend class LLUICtrlFactory;
 80
 81public:
 82	virtual ~LLScrollbar();
 83
 84	virtual void setValue(const LLSD& value);
 85
 86	// Overrides from LLView
 87	virtual BOOL	handleKeyHere(KEY key, MASK mask);
 88	virtual BOOL	handleMouseDown(S32 x, S32 y, MASK mask);
 89	virtual BOOL	handleMouseUp(S32 x, S32 y, MASK mask);
 90	virtual BOOL	handleDoubleClick(S32 x, S32 y, MASK mask);
 91	virtual BOOL	handleHover(S32 x, S32 y, MASK mask);
 92	virtual BOOL	handleScrollWheel(S32 x, S32 y, S32 clicks);
 93	virtual BOOL	handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, 
 94		EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string &tooltip_msg);
 95
 96	virtual void	reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
 97
 98	virtual void	draw();
 99
100	// How long the "document" is.
101	void				setDocSize( S32 size );
102	S32					getDocSize() const		{ return mDocSize; }
103
104	// How many "lines" the "document" has scrolled.
105	// 0 <= DocPos <= DocSize - DocVisibile
106	bool				setDocPos( S32 pos, BOOL update_thumb = TRUE );
107	S32					getDocPos() const		{ return mDocPos; }
108
109	BOOL				isAtBeginning();
110	BOOL				isAtEnd();
111
112	// Setting both at once.
113	void				setDocParams( S32 size, S32 pos );
114
115	// How many "lines" of the "document" is can appear on a page.
116	void				setPageSize( S32 page_size );
117	S32					getPageSize() const		{ return mPageSize; }
118	
119	// The farthest the document can be scrolled (top of the last page).
120	S32					getDocPosMax() const	{ return llmax( 0, mDocSize - mPageSize); }
121
122	void				pageUp(S32 overlap);
123	void				pageDown(S32 overlap);
124
125	void				onLineUpBtnPressed(const LLSD& data);
126	void				onLineDownBtnPressed(const LLSD& data);
127
128private:
129	void				updateThumbRect();
130	bool				changeLine(S32 delta, BOOL update_thumb );
131
132	callback_t			mChangeCallback;
133
134	const ORIENTATION	mOrientation;	
135	S32					mDocSize;		// Size of the document that the scrollbar is modeling.  Units depend on the user.  0 <= mDocSize.
136	S32					mDocPos;		// Position within the doc that the scrollbar is modeling, in "lines" (user size)
137	S32					mPageSize;		// Maximum number of lines that can be seen at one time.
138	S32					mStepSize;
139	BOOL				mDocChanged;
140
141	LLRect				mThumbRect;
142	S32					mDragStartX;
143	S32					mDragStartY;
144	F32					mHoverGlowStrength;
145	F32					mCurGlowStrength;
146
147	LLRect				mOrigRect;
148	S32					mLastDelta;
149
150	LLUIColor			mTrackColor;
151	LLUIColor			mThumbColor;
152	LLUIColor			mBGColor;
153
154	bool				mBGVisible;
155
156	LLUIImagePtr		mThumbImageV;
157	LLUIImagePtr		mThumbImageH;
158	LLUIImagePtr		mTrackImageV;
159	LLUIImagePtr		mTrackImageH;
160
161	S32					mThickness;
162};
163
164
165#endif  // LL_SCROLLBAR_H