PageRenderTime 79ms CodeModel.GetById 29ms app.highlight 46ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/llscrollingpanellist.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 218 lines | 151 code | 33 blank | 34 comment | 24 complexity | c7097b76bd503093937f2c3cd687635b MD5 | raw file
  1/** 
  2 * @file llscrollingpanellist.cpp
  3 * @brief 
  4 *
  5 * $LicenseInfo:firstyear=2006&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#include "linden_common.h"
 28#include "llstl.h"
 29
 30#include "llscrollingpanellist.h"
 31
 32static LLDefaultChildRegistry::Register<LLScrollingPanelList> r("scrolling_panel_list");
 33
 34
 35/////////////////////////////////////////////////////////////////////
 36// LLScrollingPanelList
 37
 38// This could probably be integrated with LLScrollContainer -SJB
 39
 40void LLScrollingPanelList::clearPanels()
 41{
 42	deleteAllChildren();
 43	mPanelList.clear();
 44
 45	LLRect rc = getRect();
 46	rc.setLeftTopAndSize(rc.mLeft, rc.mTop, 1, 1);
 47	setRect(rc);
 48
 49	notifySizeChanged(rc.getHeight());
 50}
 51
 52S32 LLScrollingPanelList::addPanel( LLScrollingPanel* panel )
 53{
 54	addChildInBack( panel );
 55	mPanelList.push_front( panel );
 56
 57	// Resize this view
 58	S32 total_height = 0;
 59	S32 max_width = 0;
 60	S32 cur_gap = 0;
 61	for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
 62		 iter != mPanelList.end(); ++iter)
 63	{
 64		LLScrollingPanel *childp = *iter;
 65		total_height += childp->getRect().getHeight() + cur_gap;
 66		max_width = llmax( max_width, childp->getRect().getWidth() );
 67		cur_gap = GAP_BETWEEN_PANELS;
 68	}
 69 	LLRect rc = getRect();
 70 	rc.setLeftTopAndSize(rc.mLeft, rc.mTop, max_width, total_height);
 71 	setRect(rc);
 72
 73	notifySizeChanged(rc.getHeight());
 74
 75	// Reposition each of the child views
 76	S32 cur_y = total_height;
 77	for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
 78		 iter != mPanelList.end(); ++iter)
 79	{
 80		LLScrollingPanel *childp = *iter;
 81		cur_y -= childp->getRect().getHeight();
 82		childp->translate( -childp->getRect().mLeft, cur_y - childp->getRect().mBottom);
 83		cur_y -= GAP_BETWEEN_PANELS;
 84	}
 85
 86	return total_height;
 87}
 88
 89void LLScrollingPanelList::removePanel(LLScrollingPanel* panel) 
 90{
 91	U32 index = 0;
 92	LLScrollingPanelList::panel_list_t::const_iterator iter;
 93
 94	if (!mPanelList.empty()) 
 95	{
 96		for (iter = mPanelList.begin(); iter != mPanelList.end(); ++iter, ++index) 
 97		{
 98			if (*iter == panel) 
 99			{
100				break;
101			}
102		}
103		if(iter != mPanelList.end())
104		{
105			removePanel(index);
106		}
107	}
108}
109
110void LLScrollingPanelList::removePanel( U32 panel_index )
111{
112	if ( mPanelList.empty() || panel_index >= mPanelList.size() )
113	{
114		llwarns << "Panel index " << panel_index << " is out of range!" << llendl;
115		return;
116	}
117	else
118	{
119		removeChild( mPanelList.at(panel_index) );
120		mPanelList.erase( mPanelList.begin() + panel_index );
121	}
122
123	const S32 GAP_BETWEEN_PANELS = 6;
124
125	// Resize this view
126	S32 total_height = 0;
127	S32 max_width = 0;
128	S32 cur_gap = 0;
129	for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
130		 iter != mPanelList.end(); ++iter)
131	{
132		LLScrollingPanel *childp = *iter;
133		total_height += childp->getRect().getHeight() + cur_gap;
134		max_width = llmax( max_width, childp->getRect().getWidth() );
135		cur_gap = GAP_BETWEEN_PANELS;
136	}
137	LLRect rc = getRect();
138	rc.setLeftTopAndSize(rc.mLeft, rc.mTop, max_width, total_height);
139	setRect(rc);
140
141	notifySizeChanged(rc.getHeight());
142
143	// Reposition each of the child views
144	S32 cur_y = total_height;
145	for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
146		 iter != mPanelList.end(); ++iter)
147	{
148		LLScrollingPanel *childp = *iter;
149		cur_y -= childp->getRect().getHeight();
150		childp->translate( -childp->getRect().mLeft, cur_y - childp->getRect().mBottom);
151		cur_y -= GAP_BETWEEN_PANELS;
152	}
153}
154
155void LLScrollingPanelList::updatePanels(BOOL allow_modify)
156{
157    for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
158		 iter != mPanelList.end(); ++iter)
159    {
160		LLScrollingPanel *childp = *iter;
161		childp->updatePanel(allow_modify);
162    }
163}
164
165void LLScrollingPanelList::updatePanelVisiblilty()
166{
167	// Determine visibility of children.
168	S32 BORDER_WIDTH = 2;  // HACK
169
170	LLRect parent_local_rect = getParent()->getRect();
171	parent_local_rect.stretch( -BORDER_WIDTH );
172	
173	LLRect parent_screen_rect;
174	getParent()->localPointToScreen( 
175		BORDER_WIDTH, 0, 
176		&parent_screen_rect.mLeft, &parent_screen_rect.mBottom );
177	getParent()->localPointToScreen( 
178		parent_local_rect.getWidth() - BORDER_WIDTH, parent_local_rect.getHeight() - BORDER_WIDTH,
179		&parent_screen_rect.mRight, &parent_screen_rect.mTop );
180
181	for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
182		 iter != mPanelList.end(); ++iter)
183	{
184		LLScrollingPanel *childp = *iter;
185		const LLRect& local_rect = childp->getRect();
186		LLRect screen_rect;
187		childp->localPointToScreen( 
188			0, 0, 
189			&screen_rect.mLeft, &screen_rect.mBottom );
190		childp->localPointToScreen(
191			local_rect.getWidth(), local_rect.getHeight(),
192			&screen_rect.mRight, &screen_rect.mTop );
193
194		BOOL intersects = 
195			( (screen_rect.mRight > parent_screen_rect.mLeft) && (screen_rect.mLeft < parent_screen_rect.mRight) ) && 
196			( (screen_rect.mTop > parent_screen_rect.mBottom) && (screen_rect.mBottom < parent_screen_rect.mTop) );
197
198		childp->setVisible( intersects );
199	}
200}
201
202
203void LLScrollingPanelList::draw()
204{
205	updatePanelVisiblilty();
206
207	LLUICtrl::draw();
208}
209
210void LLScrollingPanelList::notifySizeChanged(S32 height)
211{
212	LLSD info;
213	info["action"] = "size_changes";
214	info["height"] = height;
215	notifyParent(info);
216}
217
218// EOF