00001
00032
00033
00034 #include "linden_common.h"
00035
00036 #include "llviewborder.h"
00037
00038 #include "llgl.h"
00039 #include "llui.h"
00040 #include "llimagegl.h"
00041
00042 #include "llcontrol.h"
00043 #include "llglheaders.h"
00044 #include "v2math.h"
00045 #include "llfocusmgr.h"
00046
00047 LLViewBorder::LLViewBorder( const LLString& name, const LLRect& rect, EBevel bevel, EStyle style, S32 width )
00048 :
00049 LLView( name, rect, FALSE ),
00050 mBevel( bevel ),
00051 mStyle( style ),
00052 mHighlightLight( LLUI::sColorsGroup->getColor( "DefaultHighlightLight" ) ),
00053 mHighlightDark( LLUI::sColorsGroup->getColor( "DefaultHighlightDark" ) ),
00054 mShadowLight( LLUI::sColorsGroup->getColor( "DefaultShadowLight" ) ),
00055 mShadowDark( LLUI::sColorsGroup->getColor( "DefaultShadowDark" ) ),
00056
00057 mBorderWidth( width ),
00058 mTexture( NULL ),
00059 mHasKeyboardFocus( FALSE )
00060 {
00061 setFollowsAll();
00062 }
00063
00064
00065 BOOL LLViewBorder::isCtrl() const
00066 {
00067 return FALSE;
00068 }
00069
00070 void LLViewBorder::setColors( const LLColor4& shadow_dark, const LLColor4& highlight_light )
00071 {
00072 mShadowDark = shadow_dark;
00073 mHighlightLight = highlight_light;
00074 }
00075
00076 void LLViewBorder::setColorsExtended( const LLColor4& shadow_light, const LLColor4& shadow_dark,
00077 const LLColor4& highlight_light, const LLColor4& highlight_dark )
00078 {
00079 mShadowDark = shadow_dark;
00080 mShadowLight = shadow_light;
00081 mHighlightLight = highlight_light;
00082 mHighlightDark = highlight_dark;
00083 }
00084
00085 void LLViewBorder::setTexture( const LLUUID &image_id )
00086 {
00087 mTexture = LLUI::sImageProvider->getUIImageByID(image_id);
00088 }
00089
00090
00091 void LLViewBorder::draw()
00092 {
00093 if( getVisible() )
00094 {
00095 if( STYLE_LINE == mStyle )
00096 {
00097 if( 0 == mBorderWidth )
00098 {
00099
00100 }
00101 else
00102 if( 1 == mBorderWidth )
00103 {
00104 drawOnePixelLines();
00105 }
00106 else
00107 if( 2 == mBorderWidth )
00108 {
00109 drawTwoPixelLines();
00110 }
00111 else
00112 {
00113 llassert( FALSE );
00114 }
00115 }
00116 else
00117 if( STYLE_TEXTURE == mStyle )
00118 {
00119 if( mTexture )
00120 {
00121 drawTextures();
00122 }
00123 }
00124
00125
00126 LLView::draw();
00127 }
00128 }
00129
00130 void LLViewBorder::drawOnePixelLines()
00131 {
00132 LLGLSNoTexture uiNoTexture;
00133
00134 LLColor4 top_color = mHighlightLight;
00135 LLColor4 bottom_color = mHighlightLight;
00136 switch( mBevel )
00137 {
00138 case BEVEL_OUT:
00139 top_color = mHighlightLight;
00140 bottom_color = mShadowDark;
00141 break;
00142 case BEVEL_IN:
00143 top_color = mShadowDark;
00144 bottom_color = mHighlightLight;
00145 break;
00146 case BEVEL_NONE:
00147
00148 break;
00149 default:
00150 llassert(0);
00151 }
00152
00153 if( mHasKeyboardFocus )
00154 {
00155 F32 lerp_amt = gFocusMgr.getFocusFlashAmt();
00156 top_color = gFocusMgr.getFocusColor();
00157 bottom_color = top_color;
00158
00159 LLUI::setLineWidth(lerp(1.f, 3.f, lerp_amt));
00160 }
00161
00162 S32 left = 0;
00163 S32 top = mRect.getHeight();
00164 S32 right = mRect.getWidth();
00165 S32 bottom = 0;
00166
00167 glColor4fv( top_color.mV );
00168 gl_line_2d(left, bottom, left, top);
00169 gl_line_2d(left, top, right, top);
00170
00171 glColor4fv( bottom_color.mV );
00172 gl_line_2d(right, top, right, bottom);
00173 gl_line_2d(left, bottom, right, bottom);
00174
00175 LLUI::setLineWidth(1.f);
00176 }
00177
00178 void LLViewBorder::drawTwoPixelLines()
00179 {
00180 LLGLSNoTexture no_texture;
00181
00182 LLColor4 focus_color = gFocusMgr.getFocusColor();
00183
00184 F32* top_in_color = mShadowDark.mV;
00185 F32* top_out_color = mShadowDark.mV;
00186 F32* bottom_in_color = mShadowDark.mV;
00187 F32* bottom_out_color = mShadowDark.mV;
00188 switch( mBevel )
00189 {
00190 case BEVEL_OUT:
00191 top_in_color = mHighlightLight.mV;
00192 top_out_color = mHighlightDark.mV;
00193 bottom_in_color = mShadowLight.mV;
00194 bottom_out_color = mShadowDark.mV;
00195 break;
00196 case BEVEL_IN:
00197 top_in_color = mShadowDark.mV;
00198 top_out_color = mShadowLight.mV;
00199 bottom_in_color = mHighlightDark.mV;
00200 bottom_out_color = mHighlightLight.mV;
00201 break;
00202 case BEVEL_BRIGHT:
00203 top_in_color = mHighlightLight.mV;
00204 top_out_color = mHighlightLight.mV;
00205 bottom_in_color = mHighlightLight.mV;
00206 bottom_out_color = mHighlightLight.mV;
00207 break;
00208 case BEVEL_NONE:
00209
00210 break;
00211 default:
00212 llassert(0);
00213 }
00214
00215 if( mHasKeyboardFocus )
00216 {
00217 top_out_color = focus_color.mV;
00218 bottom_out_color = focus_color.mV;
00219 }
00220
00221 S32 left = 0;
00222 S32 top = mRect.getHeight();
00223 S32 right = mRect.getWidth();
00224 S32 bottom = 0;
00225
00226
00227 glColor3fv( top_out_color );
00228 gl_line_2d(left, bottom, left, top-1);
00229 gl_line_2d(left, top-1, right, top-1);
00230
00231 glColor3fv( top_in_color );
00232 gl_line_2d(left+1, bottom+1, left+1, top-2);
00233 gl_line_2d(left+1, top-2, right-1, top-2);
00234
00235 glColor3fv( bottom_out_color );
00236 gl_line_2d(right-1, top-1, right-1, bottom);
00237 gl_line_2d(left, bottom, right, bottom);
00238
00239 glColor3fv( bottom_in_color );
00240 gl_line_2d(right-2, top-2, right-2, bottom+1);
00241 gl_line_2d(left+1, bottom+1, right-1, bottom+1);
00242 }
00243
00244 void LLViewBorder::drawTextures()
00245 {
00246 LLGLSUIDefault gls_ui;
00247
00248 llassert( FALSE );
00249
00250 glColor4fv(UI_VERTEX_COLOR.mV);
00251
00252 mTexture->bind();
00253 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
00254 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
00255
00256 drawTextureTrapezoid( 0.f, mBorderWidth, mRect.getWidth(), 0, 0 );
00257 drawTextureTrapezoid( 90.f, mBorderWidth, mRect.getHeight(), (F32)mRect.getWidth(),0 );
00258 drawTextureTrapezoid( 180.f, mBorderWidth, mRect.getWidth(), (F32)mRect.getWidth(),(F32)mRect.getHeight() );
00259 drawTextureTrapezoid( 270.f, mBorderWidth, mRect.getHeight(), 0, (F32)mRect.getHeight() );
00260 }
00261
00262
00263 void LLViewBorder::drawTextureTrapezoid( F32 degrees, S32 width, S32 length, F32 start_x, F32 start_y )
00264 {
00265 glPushMatrix();
00266 {
00267 glTranslatef(start_x, start_y, 0.f);
00268 glRotatef( degrees, 0, 0, 1 );
00269
00270 glBegin(GL_QUADS);
00271 {
00272
00273
00274
00275
00276
00277
00278 glTexCoord2f( 0, 0 );
00279 glVertex2i( 0, 0 );
00280
00281 glTexCoord2f( (GLfloat)length, 0 );
00282 glVertex2i( length, 0 );
00283
00284 glTexCoord2f( (GLfloat)(length - width), (GLfloat)width );
00285 glVertex2i( length - width, width );
00286
00287 glTexCoord2f( (GLfloat)width, (GLfloat)width );
00288 glVertex2i( width, width );
00289 }
00290 glEnd();
00291 }
00292 glPopMatrix();
00293 }
00294
00295 bool LLViewBorder::getBevelFromAttribute(LLXMLNodePtr node, LLViewBorder::EBevel& bevel_style)
00296 {
00297 if (node->hasAttribute("bevel_style"))
00298 {
00299 LLString bevel_string;
00300 node->getAttributeString("bevel_style", bevel_string);
00301 LLString::toLower(bevel_string);
00302
00303 if (bevel_string == "none")
00304 {
00305 bevel_style = LLViewBorder::BEVEL_NONE;
00306 }
00307 else if (bevel_string == "in")
00308 {
00309 bevel_style = LLViewBorder::BEVEL_IN;
00310 }
00311 else if (bevel_string == "out")
00312 {
00313 bevel_style = LLViewBorder::BEVEL_OUT;
00314 }
00315 else if (bevel_string == "bright")
00316 {
00317 bevel_style = LLViewBorder::BEVEL_BRIGHT;
00318 }
00319 return true;
00320 }
00321 return false;
00322 }
00323
00324 void LLViewBorder::setValue(const LLSD& val)
00325 {
00326 setRect(LLRect(val));
00327 }
00328
00329 EWidgetType LLViewBorder::getWidgetType() const
00330 {
00331 return WIDGET_TYPE_VIEW_BORDER;
00332 }
00333
00334 LLString LLViewBorder::getWidgetTag() const
00335 {
00336 return LL_VIEW_BORDER_TAG;
00337 }
00338
00339
00340 LLView* LLViewBorder::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
00341 {
00342 LLString name("view_border");
00343 node->getAttributeString("name", name);
00344
00345 LLViewBorder::EBevel bevel_style = LLViewBorder::BEVEL_IN;
00346 getBevelFromAttribute(node, bevel_style);
00347
00348 S32 border_thickness = 1;
00349 node->getAttributeS32("border_thickness", border_thickness);
00350
00351 LLViewBorder* border = new LLViewBorder(name,
00352 LLRect(),
00353 bevel_style,
00354 LLViewBorder::STYLE_LINE,
00355 border_thickness);
00356
00357 border->initFromXML(node, parent);
00358
00359 return border;
00360 }