aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/llviewborder.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llui/llviewborder.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/llui/llviewborder.cpp356
1 files changed, 356 insertions, 0 deletions
diff --git a/linden/indra/llui/llviewborder.cpp b/linden/indra/llui/llviewborder.cpp
new file mode 100644
index 0000000..c26a818
--- /dev/null
+++ b/linden/indra/llui/llviewborder.cpp
@@ -0,0 +1,356 @@
1/**
2 * @file llviewborder.cpp
3 * @brief LLViewBorder base class
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28// A customizable decorative border. Does not interact with mouse events.
29
30#include "linden_common.h"
31
32#include "llviewborder.h"
33
34#include "llgl.h"
35#include "llui.h"
36#include "llimagegl.h"
37//#include "llviewerimagelist.h"
38#include "llcontrol.h"
39#include "llglheaders.h"
40#include "v2math.h"
41#include "llfocusmgr.h"
42
43LLViewBorder::LLViewBorder( const LLString& name, const LLRect& rect, EBevel bevel, EStyle style, S32 width )
44 :
45 LLView( name, rect, FALSE ),
46 mBevel( bevel ),
47 mStyle( style ),
48 mHighlightLight( LLUI::sColorsGroup->getColor( "DefaultHighlightLight" ) ),
49 mHighlightDark( LLUI::sColorsGroup->getColor( "DefaultHighlightDark" ) ),
50 mShadowLight( LLUI::sColorsGroup->getColor( "DefaultShadowLight" ) ),
51 mShadowDark( LLUI::sColorsGroup->getColor( "DefaultShadowDark" ) ),
52// mKeyboardFocusColor(LLUI::sColorsGroup->getColor( "FocusColor" ) ),
53 mBorderWidth( width ),
54 mTexture( NULL ),
55 mHasKeyboardFocus( FALSE )
56{
57 setFollowsAll();
58}
59
60// virtual
61BOOL LLViewBorder::isCtrl()
62{
63 return FALSE;
64}
65
66void LLViewBorder::setColors( const LLColor4& shadow_dark, const LLColor4& highlight_light )
67{
68 mShadowDark = shadow_dark;
69 mHighlightLight = highlight_light;
70}
71
72void LLViewBorder::setColorsExtended( const LLColor4& shadow_light, const LLColor4& shadow_dark,
73 const LLColor4& highlight_light, const LLColor4& highlight_dark )
74{
75 mShadowDark = shadow_dark;
76 mShadowLight = shadow_light;
77 mHighlightLight = highlight_light;
78 mHighlightDark = highlight_dark;
79}
80
81void LLViewBorder::setTexture( const LLUUID &image_id )
82{
83 mTexture = LLUI::sImageProvider->getUIImageByID(image_id);
84}
85
86
87void LLViewBorder::draw()
88{
89 if( getVisible() )
90 {
91 if( STYLE_LINE == mStyle )
92 {
93 if( 0 == mBorderWidth )
94 {
95 // no visible border
96 }
97 else
98 if( 1 == mBorderWidth )
99 {
100 drawOnePixelLines();
101 }
102 else
103 if( 2 == mBorderWidth )
104 {
105 drawTwoPixelLines();
106 }
107 else
108 {
109 llassert( FALSE ); // not implemented
110 }
111 }
112 else
113 if( STYLE_TEXTURE == mStyle )
114 {
115 if( mTexture )
116 {
117 drawTextures();
118 }
119 }
120
121 // draw the children
122 LLView::draw();
123 }
124}
125
126void LLViewBorder::drawOnePixelLines()
127{
128 LLGLSNoTexture uiNoTexture;
129
130 LLColor4 top_color = mHighlightLight;
131 LLColor4 bottom_color = mHighlightLight;
132 switch( mBevel )
133 {
134 case BEVEL_OUT:
135 top_color = mHighlightLight;
136 bottom_color = mShadowDark;
137 break;
138 case BEVEL_IN:
139 top_color = mShadowDark;
140 bottom_color = mHighlightLight;
141 break;
142 case BEVEL_NONE:
143 // use defaults
144 break;
145 default:
146 llassert(0);
147 }
148
149 if( mHasKeyboardFocus )
150 {
151 F32 lerp_amt = gFocusMgr.getFocusFlashAmt();
152 top_color = gFocusMgr.getFocusColor();
153 bottom_color = top_color;
154
155 LLUI::setLineWidth(lerp(1.f, 3.f, lerp_amt));
156 }
157
158 S32 left = 0;
159 S32 top = mRect.getHeight();
160 S32 right = mRect.getWidth();
161 S32 bottom = 0;
162
163 glColor4fv( top_color.mV );
164 gl_line_2d(left, bottom, left, top);
165 gl_line_2d(left, top, right, top);
166
167 glColor4fv( bottom_color.mV );
168 gl_line_2d(right, top, right, bottom);
169 gl_line_2d(left, bottom, right, bottom);
170
171 LLUI::setLineWidth(1.f);
172}
173
174void LLViewBorder::drawTwoPixelLines()
175{
176 LLGLSNoTexture no_texture;
177
178 LLColor4 focus_color = gFocusMgr.getFocusColor();
179
180 F32* top_in_color = mShadowDark.mV;
181 F32* top_out_color = mShadowDark.mV;
182 F32* bottom_in_color = mShadowDark.mV;
183 F32* bottom_out_color = mShadowDark.mV;
184 switch( mBevel )
185 {
186 case BEVEL_OUT:
187 top_in_color = mHighlightLight.mV;
188 top_out_color = mHighlightDark.mV;
189 bottom_in_color = mShadowLight.mV;
190 bottom_out_color = mShadowDark.mV;
191 break;
192 case BEVEL_IN:
193 top_in_color = mShadowDark.mV;
194 top_out_color = mShadowLight.mV;
195 bottom_in_color = mHighlightDark.mV;
196 bottom_out_color = mHighlightLight.mV;
197 break;
198 case BEVEL_BRIGHT:
199 top_in_color = mHighlightLight.mV;
200 top_out_color = mHighlightLight.mV;
201 bottom_in_color = mHighlightLight.mV;
202 bottom_out_color = mHighlightLight.mV;
203 break;
204 case BEVEL_NONE:
205 // use defaults
206 break;
207 default:
208 llassert(0);
209 }
210
211 if( mHasKeyboardFocus )
212 {
213 top_out_color = focus_color.mV;
214 bottom_out_color = focus_color.mV;
215 }
216
217 S32 left = 0;
218 S32 top = mRect.getHeight();
219 S32 right = mRect.getWidth();
220 S32 bottom = 0;
221
222 // draw borders
223 glColor3fv( top_out_color );
224 gl_line_2d(left, bottom, left, top-1);
225 gl_line_2d(left, top-1, right, top-1);
226
227 glColor3fv( top_in_color );
228 gl_line_2d(left+1, bottom+1, left+1, top-2);
229 gl_line_2d(left+1, top-2, right-1, top-2);
230
231 glColor3fv( bottom_out_color );
232 gl_line_2d(right-1, top-1, right-1, bottom);
233 gl_line_2d(left, bottom, right, bottom);
234
235 glColor3fv( bottom_in_color );
236 gl_line_2d(right-2, top-2, right-2, bottom+1);
237 gl_line_2d(left+1, bottom+1, right-1, bottom+1);
238}
239
240void LLViewBorder::drawTextures()
241{
242 LLGLSUIDefault gls_ui;
243
244 llassert( FALSE ); // TODO: finish implementing
245
246 glColor4fv(UI_VERTEX_COLOR.mV);
247
248 mTexture->bind();
249 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
250 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
251
252 drawTextureTrapezoid( 0.f, mBorderWidth, mRect.getWidth(), 0, 0 );
253 drawTextureTrapezoid( 90.f, mBorderWidth, mRect.getHeight(), (F32)mRect.getWidth(),0 );
254 drawTextureTrapezoid( 180.f, mBorderWidth, mRect.getWidth(), (F32)mRect.getWidth(),(F32)mRect.getHeight() );
255 drawTextureTrapezoid( 270.f, mBorderWidth, mRect.getHeight(), 0, (F32)mRect.getHeight() );
256}
257
258
259void LLViewBorder::drawTextureTrapezoid( F32 degrees, S32 width, S32 length, F32 start_x, F32 start_y )
260{
261 glPushMatrix();
262 {
263 glTranslatef(start_x, start_y, 0.f);
264 glRotatef( degrees, 0, 0, 1 );
265
266 glBegin(GL_QUADS);
267 {
268 // width, width /---------\ length-width, width //
269 // / \ //
270 // / \ //
271 // /---------------\ //
272 // 0,0 length, 0 //
273
274 glTexCoord2f( 0, 0 );
275 glVertex2i( 0, 0 );
276
277 glTexCoord2f( (GLfloat)length, 0 );
278 glVertex2i( length, 0 );
279
280 glTexCoord2f( (GLfloat)(length - width), (GLfloat)width );
281 glVertex2i( length - width, width );
282
283 glTexCoord2f( (GLfloat)width, (GLfloat)width );
284 glVertex2i( width, width );
285 }
286 glEnd();
287 }
288 glPopMatrix();
289}
290
291bool LLViewBorder::getBevelFromAttribute(LLXMLNodePtr node, LLViewBorder::EBevel& bevel_style)
292{
293 if (node->hasAttribute("bevel_style"))
294 {
295 LLString bevel_string;
296 node->getAttributeString("bevel_style", bevel_string);
297 LLString::toLower(bevel_string);
298
299 if (bevel_string == "none")
300 {
301 bevel_style = LLViewBorder::BEVEL_NONE;
302 }
303 else if (bevel_string == "in")
304 {
305 bevel_style = LLViewBorder::BEVEL_IN;
306 }
307 else if (bevel_string == "out")
308 {
309 bevel_style = LLViewBorder::BEVEL_OUT;
310 }
311 else if (bevel_string == "bright")
312 {
313 bevel_style = LLViewBorder::BEVEL_BRIGHT;
314 }
315 return true;
316 }
317 return false;
318}
319
320void LLViewBorder::setValue(const LLSD& val)
321{
322 setRect(LLRect(val));
323}
324
325EWidgetType LLViewBorder::getWidgetType() const
326{
327 return WIDGET_TYPE_VIEW_BORDER;
328}
329
330LLString LLViewBorder::getWidgetTag() const
331{
332 return LL_VIEW_BORDER_TAG;
333}
334
335// static
336LLView* LLViewBorder::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
337{
338 LLString name("view_border");
339 node->getAttributeString("name", name);
340
341 LLViewBorder::EBevel bevel_style = LLViewBorder::BEVEL_IN;
342 getBevelFromAttribute(node, bevel_style);
343
344 S32 border_thickness = 1;
345 node->getAttributeS32("border_thickness", border_thickness);
346
347 LLViewBorder* border = new LLViewBorder(name,
348 LLRect(),
349 bevel_style,
350 LLViewBorder::STYLE_LINE,
351 border_thickness);
352
353 border->initFromXML(node, parent);
354
355 return border;
356}