PageRenderTime 70ms CodeModel.GetById 20ms app.highlight 46ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llui/llviewborder.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 270 lines | 208 code | 34 blank | 28 comment | 22 complexity | 5b3b8749cd13269b6cbfec22eded1281 MD5 | raw file
  1/** 
  2 * @file llviewborder.cpp
  3 *
  4 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5 * Second Life Viewer Source Code
  6 * Copyright (C) 2010, Linden Research, Inc.
  7 * 
  8 * This library is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU Lesser General Public
 10 * License as published by the Free Software Foundation;
 11 * version 2.1 of the License only.
 12 * 
 13 * This library is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16 * Lesser General Public License for more details.
 17 * 
 18 * You should have received a copy of the GNU Lesser General Public
 19 * License along with this library; if not, write to the Free Software
 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 21 * 
 22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 23 * $/LicenseInfo$
 24 */
 25
 26#include "linden_common.h"
 27#include "llviewborder.h"
 28#include "llrender.h"
 29#include "llfocusmgr.h"
 30#include "lluictrlfactory.h"
 31#include "lluiimage.h"
 32
 33static LLDefaultChildRegistry::Register<LLViewBorder> r("view_border");
 34
 35void LLViewBorder::BevelValues::declareValues()
 36{
 37	declare("in", LLViewBorder::BEVEL_IN);
 38	declare("out", LLViewBorder::BEVEL_OUT);
 39	declare("bright", LLViewBorder::BEVEL_BRIGHT);
 40	declare("none", LLViewBorder::BEVEL_NONE);
 41}
 42
 43void LLViewBorder::StyleValues::declareValues()
 44{
 45	declare("line", LLViewBorder::STYLE_LINE);
 46	declare("texture", LLViewBorder::STYLE_TEXTURE);
 47}
 48
 49LLViewBorder::Params::Params()
 50:	bevel_style("bevel_style", BEVEL_OUT),
 51	render_style("border_style", STYLE_LINE),
 52	border_thickness("border_thickness"),
 53	highlight_light_color("highlight_light_color"),
 54	highlight_dark_color("highlight_dark_color"),
 55	shadow_light_color("shadow_light_color"),
 56	shadow_dark_color("shadow_dark_color")
 57{
 58	addSynonym(border_thickness, "thickness");
 59	addSynonym(render_style, "style");
 60}
 61
 62
 63LLViewBorder::LLViewBorder(const LLViewBorder::Params& p)
 64:	LLView(p),
 65	mTexture( NULL ),
 66	mHasKeyboardFocus( FALSE ),
 67	mBorderWidth(p.border_thickness),
 68	mHighlightLight(p.highlight_light_color()),
 69	mHighlightDark(p.highlight_dark_color()),
 70	mShadowLight(p.shadow_light_color()),
 71	mShadowDark(p.shadow_dark_color()),
 72	mBevel(p.bevel_style),
 73	mStyle(p.render_style)
 74{}
 75
 76void LLViewBorder::setColors( const LLColor4& shadow_dark, const LLColor4& highlight_light )
 77{
 78	mShadowDark = shadow_dark;
 79	mHighlightLight = highlight_light;
 80}
 81
 82void LLViewBorder::setColorsExtended( const LLColor4& shadow_light, const LLColor4& shadow_dark,
 83				  			   const LLColor4& highlight_light, const LLColor4& highlight_dark )
 84{
 85	mShadowDark = shadow_dark;
 86	mShadowLight = shadow_light;
 87	mHighlightLight = highlight_light;
 88	mHighlightDark = highlight_dark;
 89}
 90
 91void LLViewBorder::setTexture( const LLUUID &image_id )
 92{
 93	mTexture = LLUI::getUIImageByID(image_id);
 94}
 95
 96
 97void LLViewBorder::draw()
 98{
 99	if( STYLE_LINE == mStyle )
100	{
101		if( 0 == mBorderWidth )
102		{
103			// no visible border
104		}
105		else
106		if( 1 == mBorderWidth )
107		{
108			drawOnePixelLines();
109		}
110		else
111		if( 2 == mBorderWidth )
112		{
113			drawTwoPixelLines();
114		}
115		else
116		{
117			llassert( FALSE );  // not implemented
118		}
119	}
120
121	LLView::draw();
122}
123
124void LLViewBorder::drawOnePixelLines()
125{
126	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
127
128	LLColor4 top_color = mHighlightLight.get();
129	LLColor4 bottom_color = mHighlightLight.get();
130	switch( mBevel )
131	{
132	case BEVEL_OUT:
133		top_color		= mHighlightLight.get();
134		bottom_color	= mShadowDark.get();
135		break;
136	case BEVEL_IN:
137		top_color		= mShadowDark.get();
138		bottom_color	= mHighlightLight.get();
139		break;
140	case BEVEL_NONE:
141		// use defaults
142		break;
143	default:
144		llassert(0);
145	}
146
147	if( mHasKeyboardFocus )
148	{
149		top_color = gFocusMgr.getFocusColor();
150		bottom_color = top_color;
151
152		LLUI::setLineWidth(lerp(1.f, 3.f, gFocusMgr.getFocusFlashAmt()));
153	}
154
155	S32 left	= 0;
156	S32 top		= getRect().getHeight();
157	S32 right	= getRect().getWidth();
158	S32 bottom	= 0;
159
160	gGL.color4fv( top_color.mV );
161	gl_line_2d(left, bottom, left, top);
162	gl_line_2d(left, top, right, top);
163
164	gGL.color4fv( bottom_color.mV );
165	gl_line_2d(right, top, right, bottom);
166	gl_line_2d(left, bottom, right, bottom);
167
168	LLUI::setLineWidth(1.f);
169}
170
171void LLViewBorder::drawTwoPixelLines()
172{
173	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
174	
175	LLColor4 focus_color = gFocusMgr.getFocusColor();
176
177	LLColor4 top_in_color;
178	LLColor4 top_out_color;
179	LLColor4 bottom_in_color;
180	LLColor4 bottom_out_color;
181
182	switch( mBevel )
183	{
184	case BEVEL_OUT:
185		top_in_color		= mHighlightLight.get();
186		top_out_color		= mHighlightDark.get();
187		bottom_in_color		= mShadowLight.get();
188		bottom_out_color	= mShadowDark.get();
189		break;
190	case BEVEL_IN:
191		top_in_color		= mShadowDark.get();
192		top_out_color		= mShadowLight.get();
193		bottom_in_color		= mHighlightDark.get();
194		bottom_out_color	= mHighlightLight.get();
195		break;
196	case BEVEL_BRIGHT:
197		top_in_color		= mHighlightLight.get();
198		top_out_color		= mHighlightLight.get();
199		bottom_in_color		= mHighlightLight.get();
200		bottom_out_color	= mHighlightLight.get();
201		break;
202	case BEVEL_NONE:
203		top_in_color		= mShadowDark.get();
204		top_out_color		= mShadowDark.get();
205		bottom_in_color		= mShadowDark.get();
206		bottom_out_color	= mShadowDark.get();
207		// use defaults
208		break;
209	default:
210		llassert(0);
211	}
212
213	if( mHasKeyboardFocus )
214	{
215		top_out_color = focus_color;
216		bottom_out_color = focus_color;
217	}
218
219	S32 left	= 0;
220	S32 top		= getRect().getHeight();
221	S32 right	= getRect().getWidth();
222	S32 bottom	= 0;
223
224	// draw borders
225	gGL.color3fv( top_out_color.mV );
226	gl_line_2d(left, bottom, left, top-1);
227	gl_line_2d(left, top-1, right, top-1);
228
229	gGL.color3fv( top_in_color.mV );
230	gl_line_2d(left+1, bottom+1, left+1, top-2);
231	gl_line_2d(left+1, top-2, right-1, top-2);
232
233	gGL.color3fv( bottom_out_color.mV );
234	gl_line_2d(right-1, top-1, right-1, bottom);
235	gl_line_2d(left, bottom, right, bottom);
236
237	gGL.color3fv( bottom_in_color.mV );
238	gl_line_2d(right-2, top-2, right-2, bottom+1);
239	gl_line_2d(left+1, bottom+1, right-1, bottom+1);
240}
241
242BOOL LLViewBorder::getBevelFromAttribute(LLXMLNodePtr node, LLViewBorder::EBevel& bevel_style)
243{
244	if (node->hasAttribute("bevel_style"))
245	{
246		std::string bevel_string;
247		node->getAttributeString("bevel_style", bevel_string);
248		LLStringUtil::toLower(bevel_string);
249
250		if (bevel_string == "none")
251		{
252			bevel_style = LLViewBorder::BEVEL_NONE;
253		}
254		else if (bevel_string == "in")
255		{
256			bevel_style = LLViewBorder::BEVEL_IN;
257		}
258		else if (bevel_string == "out")
259		{
260			bevel_style = LLViewBorder::BEVEL_OUT;
261		}
262		else if (bevel_string == "bright")
263		{
264			bevel_style = LLViewBorder::BEVEL_BRIGHT;
265		}
266		return TRUE;
267	}
268	return FALSE;
269}
270