summaryrefslogtreecommitdiff
path: root/indra/llui/llviewborder.cpp
blob: a5b09671bbd952a5aae6d7bda83aa54551c208b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/** 
 * @file llviewborder.cpp
 *
 * $LicenseInfo:firstyear=2001&license=viewergpl$
 * 
 * Copyright (c) 2001-2009, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at
 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include "linden_common.h"
#include "llviewborder.h"
#include "llrender.h"
#include "llfocusmgr.h"
#include "lluictrlfactory.h"

static LLDefaultWidgetRegistry::Register<LLViewBorder> r("view_border");

void LLViewBorder::BevelValues::declareValues()
{
	declare("in", LLViewBorder::BEVEL_IN);
	declare("out", LLViewBorder::BEVEL_OUT);
	declare("bright", LLViewBorder::BEVEL_BRIGHT);
	declare("none", LLViewBorder::BEVEL_NONE);
}

void LLViewBorder::StyleValues::declareValues()
{
	declare("line", LLViewBorder::STYLE_LINE);
	declare("texture", LLViewBorder::STYLE_TEXTURE);
}

LLViewBorder::Params::Params()
:	bevel_type("bevel_style", BEVEL_OUT),
	render_style("border_style", STYLE_LINE),
	border_thickness("border_thickness"),
	highlight_light_color("highlight_light_color"),
	highlight_dark_color("highlight_dark_color"),
	shadow_light_color("shadow_light_color"),
	shadow_dark_color("shadow_dark_color")
{
	name = "view_border";
	mouse_opaque = false;
	follows.flags = FOLLOWS_ALL;
}


LLViewBorder::LLViewBorder(const LLViewBorder::Params& p)
:	LLView(p),
	mTexture( NULL ),
	mHasKeyboardFocus( FALSE ),
	mBorderWidth(p.border_thickness),
	mHighlightLight(p.highlight_light_color()),
	mHighlightDark(p.highlight_dark_color()),
	mShadowLight(p.shadow_light_color()),
	mShadowDark(p.shadow_dark_color()),
	mBevel(p.bevel_type),
	mStyle(p.render_style)
{}

void LLViewBorder::setColors( const LLColor4& shadow_dark, const LLColor4& highlight_light )
{
	mShadowDark = shadow_dark;
	mHighlightLight = highlight_light;
}

void LLViewBorder::setColorsExtended( const LLColor4& shadow_light, const LLColor4& shadow_dark,
				  			   const LLColor4& highlight_light, const LLColor4& highlight_dark )
{
	mShadowDark = shadow_dark;
	mShadowLight = shadow_light;
	mHighlightLight = highlight_light;
	mHighlightDark = highlight_dark;
}

void LLViewBorder::setTexture( const LLUUID &image_id )
{
	mTexture = LLUI::getUIImageByID(image_id);
}


void LLViewBorder::draw()
{
	if( STYLE_LINE == mStyle )
	{
		if( 0 == mBorderWidth )
		{
			// no visible border
		}
		else
		if( 1 == mBorderWidth )
		{
			drawOnePixelLines();
		}
		else
		if( 2 == mBorderWidth )
		{
			drawTwoPixelLines();
		}
		else
		{
			llassert( FALSE );  // not implemented
		}
	}
	else
	if( STYLE_TEXTURE == mStyle )
	{
		if( mTexture )
		{
			drawTextures();
		}
	}

	// draw the children
	LLView::draw();

}

void LLViewBorder::drawOnePixelLines()
{
	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);

	LLColor4 top_color = mHighlightLight.get();
	LLColor4 bottom_color = mHighlightLight.get();
	switch( mBevel )
	{
	case BEVEL_OUT:
		top_color		= mHighlightLight.get();
		bottom_color	= mShadowDark.get();
		break;
	case BEVEL_IN:
		top_color		= mShadowDark.get();
		bottom_color	= mHighlightLight.get();
		break;
	case BEVEL_NONE:
		// use defaults
		break;
	default:
		llassert(0);
	}

	if( mHasKeyboardFocus )
	{
		top_color = gFocusMgr.getFocusColor();
		bottom_color = top_color;

		LLUI::setLineWidth(lerp(1.f, 3.f, gFocusMgr.getFocusFlashAmt()));
	}

	S32 left	= 0;
	S32 top		= getRect().getHeight();
	S32 right	= getRect().getWidth();
	S32 bottom	= 0;

	gGL.color4fv( top_color.mV );
	gl_line_2d(left, bottom, left, top);
	gl_line_2d(left, top, right, top);

	gGL.color4fv( bottom_color.mV );
	gl_line_2d(right, top, right, bottom);
	gl_line_2d(left, bottom, right, bottom);

	LLUI::setLineWidth(1.f);
}

void LLViewBorder::drawTwoPixelLines()
{
	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
	
	LLColor4 focus_color = gFocusMgr.getFocusColor();

	LLColor4 top_in_color;
	LLColor4 top_out_color;
	LLColor4 bottom_in_color;
	LLColor4 bottom_out_color;

	switch( mBevel )
	{
	case BEVEL_OUT:
		top_in_color		= mHighlightLight.get();
		top_out_color		= mHighlightDark.get();
		bottom_in_color		= mShadowLight.get();
		bottom_out_color	= mShadowDark.get();
		break;
	case BEVEL_IN:
		top_in_color		= mShadowDark.get();
		top_out_color		= mShadowLight.get();
		bottom_in_color		= mHighlightDark.get();
		bottom_out_color	= mHighlightLight.get();
		break;
	case BEVEL_BRIGHT:
		top_in_color		= mHighlightLight.get();
		top_out_color		= mHighlightLight.get();
		bottom_in_color		= mHighlightLight.get();
		bottom_out_color	= mHighlightLight.get();
		break;
	case BEVEL_NONE:
		top_in_color		= mShadowDark.get();
		top_out_color		= mShadowDark.get();
		bottom_in_color		= mShadowDark.get();
		bottom_out_color	= mShadowDark.get();
		// use defaults
		break;
	default:
		llassert(0);
	}

	if( mHasKeyboardFocus )
	{
		top_out_color = focus_color;
		bottom_out_color = focus_color;
	}

	S32 left	= 0;
	S32 top		= getRect().getHeight();
	S32 right	= getRect().getWidth();
	S32 bottom	= 0;

	// draw borders
	gGL.color3fv( top_out_color.mV );
	gl_line_2d(left, bottom, left, top-1);
	gl_line_2d(left, top-1, right, top-1);

	gGL.color3fv( top_in_color.mV );
	gl_line_2d(left+1, bottom+1, left+1, top-2);
	gl_line_2d(left+1, top-2, right-1, top-2);

	gGL.color3fv( bottom_out_color.mV );
	gl_line_2d(right-1, top-1, right-1, bottom);
	gl_line_2d(left, bottom, right, bottom);

	gGL.color3fv( bottom_in_color.mV );
	gl_line_2d(right-2, top-2, right-2, bottom+1);
	gl_line_2d(left+1, bottom+1, right-1, bottom+1);
}

void LLViewBorder::drawTextures()
{
	//LLGLSUIDefault gls_ui;

	//llassert( FALSE );  // TODO: finish implementing

	//gGL.color4fv(UI_VERTEX_COLOR.mV);

	//gGL.getTexUnit(0)->bind(mTexture);
	//gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_WRAP);

	//drawTextureTrapezoid(   0.f, mBorderWidth, getRect().getWidth(),  0,					0 );
	//drawTextureTrapezoid(  90.f, mBorderWidth, getRect().getHeight(), (F32)getRect().getWidth(),0 );
	//drawTextureTrapezoid( 180.f, mBorderWidth, getRect().getWidth(),  (F32)getRect().getWidth(),(F32)getRect().getHeight() );
	//drawTextureTrapezoid( 270.f, mBorderWidth, getRect().getHeight(), 0,					(F32)getRect().getHeight() );
}


void LLViewBorder::drawTextureTrapezoid( F32 degrees, S32 width, S32 length, F32 start_x, F32 start_y )
{
	gGL.pushMatrix();
	{
		gGL.translatef(start_x, start_y, 0.f);
		glRotatef( degrees, 0, 0, 1 );

		gGL.begin(LLRender::QUADS);
		{
			//      width, width   /---------\ length-width, width		//
			//	   			      /           \							//
			//				     /			   \						//
			//				    /---------------\						//
			//    			0,0					  length, 0				//

			gGL.texCoord2f( 0, 0 );
			gGL.vertex2i( 0, 0 );

			gGL.texCoord2f( (GLfloat)length, 0 );
			gGL.vertex2i( length, 0 );

			gGL.texCoord2f( (GLfloat)(length - width), (GLfloat)width );
			gGL.vertex2i( length - width, width );

			gGL.texCoord2f( (GLfloat)width, (GLfloat)width );
			gGL.vertex2i( width, width );
		}
		gGL.end();
	}
	gGL.popMatrix();
}

BOOL LLViewBorder::getBevelFromAttribute(LLXMLNodePtr node, LLViewBorder::EBevel& bevel_style)
{
	if (node->hasAttribute("bevel_style"))
	{
		std::string bevel_string;
		node->getAttributeString("bevel_style", bevel_string);
		LLStringUtil::toLower(bevel_string);

		if (bevel_string == "none")
		{
			bevel_style = LLViewBorder::BEVEL_NONE;
		}
		else if (bevel_string == "in")
		{
			bevel_style = LLViewBorder::BEVEL_IN;
		}
		else if (bevel_string == "out")
		{
			bevel_style = LLViewBorder::BEVEL_OUT;
		}
		else if (bevel_string == "bright")
		{
			bevel_style = LLViewBorder::BEVEL_BRIGHT;
		}
		return TRUE;
	}
	return FALSE;
}