llviewborder.cpp

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

Generated on Fri May 16 08:33:01 2008 for SecondLife by  doxygen 1.5.5