PageRenderTime 38ms CodeModel.GetById 7ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llui/llscrolllistitem.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 150 lines | 92 code | 27 blank | 31 comment | 10 complexity | 5bf7cd6ca409c993d12032ee5737a243 MD5 | raw file
  1/** 
  2 * @file llscrolllistitem.cpp
  3 * @brief Scroll lists are composed of rows (items), each of which 
  4 * contains columns (cells).
  5 *
  6 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include "linden_common.h"
 29
 30#include "llscrolllistitem.h"
 31
 32#include "llrect.h"
 33#include "llui.h"
 34
 35
 36//---------------------------------------------------------------------------
 37// LLScrollListItem
 38//---------------------------------------------------------------------------
 39
 40LLScrollListItem::LLScrollListItem( const Params& p )
 41:	mSelected(FALSE),
 42	mHighlighted(FALSE),
 43	mEnabled(p.enabled),
 44	mUserdata(p.userdata),
 45	mItemValue(p.value)
 46{
 47}
 48
 49
 50LLScrollListItem::~LLScrollListItem()
 51{
 52	std::for_each(mColumns.begin(), mColumns.end(), DeletePointer());
 53}
 54
 55void LLScrollListItem::addColumn(const LLScrollListCell::Params& p)
 56{
 57	mColumns.push_back(LLScrollListCell::create(p));
 58}
 59
 60void LLScrollListItem::setNumColumns(S32 columns)
 61{
 62	S32 prev_columns = mColumns.size();
 63	if (columns < prev_columns)
 64	{
 65		std::for_each(mColumns.begin()+columns, mColumns.end(), DeletePointer());
 66	}
 67	
 68	mColumns.resize(columns);
 69
 70	for (S32 col = prev_columns; col < columns; ++col)
 71	{
 72		mColumns[col] = NULL;
 73	}
 74}
 75
 76void LLScrollListItem::setColumn( S32 column, LLScrollListCell *cell )
 77{
 78	if (column < (S32)mColumns.size())
 79	{
 80		delete mColumns[column];
 81		mColumns[column] = cell;
 82	}
 83	else
 84	{
 85		llerrs << "LLScrollListItem::setColumn: bad column: " << column << llendl;
 86	}
 87}
 88
 89
 90S32 LLScrollListItem::getNumColumns() const
 91{
 92	return mColumns.size();
 93}
 94
 95LLScrollListCell* LLScrollListItem::getColumn(const S32 i) const
 96{
 97	if (0 <= i && i < (S32)mColumns.size())
 98	{
 99		return mColumns[i];
100	} 
101	return NULL;
102}
103
104std::string LLScrollListItem::getContentsCSV() const
105{
106	std::string ret;
107
108	S32 count = getNumColumns();
109	for (S32 i=0; i<count; ++i)
110	{
111		ret += getColumn(i)->getValue().asString();
112		if (i < count-1)
113		{
114			ret += ", ";
115		}
116	}
117
118	return ret;
119}
120
121
122void LLScrollListItem::draw(const LLRect& rect, const LLColor4& fg_color, const LLColor4& bg_color, const LLColor4& highlight_color, S32 column_padding)
123{
124	// draw background rect
125	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
126	LLRect bg_rect = rect;
127	gl_rect_2d( bg_rect, bg_color );
128
129	S32 cur_x = rect.mLeft;
130	S32 num_cols = getNumColumns();
131	S32 cur_col = 0;
132
133	for (LLScrollListCell* cell = getColumn(0); cur_col < num_cols; cell = getColumn(++cur_col))
134	{
135		// Two ways a cell could be hidden
136		if (cell->getWidth() < 0
137			|| !cell->getVisible()) continue;
138
139		LLUI::pushMatrix();
140		{
141			LLUI::translate((F32) cur_x, (F32) rect.mBottom, 0.0f);
142
143			cell->draw( fg_color, highlight_color );
144		}
145		LLUI::popMatrix();
146		
147		cur_x += cell->getWidth() + column_padding;
148	}
149}
150