Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

xbuttonimage.cpp

Go to the documentation of this file.
00001 #include "SdlArs.h"
00002 
00003 namespace Ars
00004 {
00005 
00006 XButtonImage::XButtonImage( void )
00007 : id( -1 )
00008 {
00009 }
00010 
00011 XButtonImage::~XButtonImage( void )
00012 {
00013 }
00014 
00015 void XButtonImage::Init( icstring &aStr )
00016 {
00017         XButton::Init( aStr );
00018 
00019         icstring        tmp = Rsrc::FindCrdOf( aStr , "cfg" );
00020 
00021         sct = Rsrc::GetStr( tmp );
00022         key = Rsrc::GetStr( tmp );
00023         fname = Rsrc::GetStr( tmp );
00024 }
00025 
00026 const bool XButtonImage::SetupWindow( const Message &msg )
00027 {
00028         XButton::SetupWindow( msg );
00029 
00030         if( !sct.empty() || !key.empty() || !fname.empty() )
00031         {
00032                 if( id == -1 )
00033                         if( key.empty() )
00034                                 id = Graf::LoadImg( fname.empty() ? sct : fname );
00035                         else
00036                                 id = Graf::LoadImg( sct , key , fname );
00037 
00038                 Graf::ButtonImg( id , static_cast<XRect &>( *this ) );
00039                 clientRect = *this;
00040         }
00041 
00042         return true;
00043 }
00044 
00045 void XButtonImage::ChangeImage( const std::string &aFilename )
00046 {
00047         id = Graf::LoadImg( aFilename );
00048         Graf::ButtonImg( id , static_cast<XRect &>( *this ) );
00049         clientRect = *this;
00050 }
00051 
00052 void XButtonImage::ChangeImage( const std::string &aSection , const std::string &aId , std::string aFilename )
00053 {
00054         id = Graf::LoadImg( aSection , aId , aFilename );
00055         Graf::ButtonImg( id , static_cast<XRect &>( *this ) );
00056         clientRect = *this;
00057 }
00058 
00059 void XButtonImage::SetImage( SDL_Surface *aImage )
00060 {
00061         id = Graf::AddImage( aImage );
00062         Graf::ButtonImg( id , static_cast<XRect &>( *this ) );
00063         clientRect = *this;
00064 }
00065 
00066 void XButtonImage::Draw( void )
00067 {
00068         if( id == -1 )
00069                 XButton::Draw();
00070         else
00071         {
00072                 XRect   dst( GetWindowRect() );
00073                 SDL_Surface     *sfc = Graf::ButtonImg( id , dst ) , *bkgnd = 0;
00074                 
00075                 if( GetStates() & S_DISABLED )
00076                         bkgnd = Graf::ButtonImg( Graf::Dark , dst );
00077                 else if( (GetStates() & (S_SELECTED|S_HIGHLIGHT|S_FOCUS)) != 0 )
00078                         bkgnd = Graf::ButtonImg( Graf::Light , dst );
00079                         
00080                 if( bkgnd )
00081                         SDL_BlitSurface( bkgnd , NULL , GetGDI() , &dst );
00082                         
00083                 if( (GetStates() & S_SELECTED) != 0 )
00084                         SDL_SetAlpha( sfc , SDL_SRCALPHA , 100 );
00085                 else if( GetStates() & S_DISABLED )
00086                         SDL_SetAlpha( sfc , SDL_SRCALPHA , 100 );
00087                 else if( (GetStates() & (S_HIGHLIGHT|S_FOCUS)) != 0 )
00088                         SDL_SetAlpha( sfc , SDL_SRCALPHA , 160 );
00089                 else
00090                         SDL_SetAlpha( sfc , SDL_SRCALPHA , 192 );
00091 
00092                 SDL_BlitSurface( sfc , 0 , GetGDI() , &dst );
00093 
00094                 if( !GetWindowText().empty() )
00095                 {
00096                         XPoint  box = GetTextSize( GetWindowText() );
00097                         XRect   bak = GetWindowRect();
00098                         XRect   &wnd = *this;
00099                         XPoint  center = bak.Center();
00100                         const unsigned long     stateBak = GetStates();
00101                         if( GetStates() & S_ALIGN_TOP )
00102                         {
00103                                 wnd = wnd - XPoint( 0, box.y + GetFontSize() );
00104                                 wnd.x = center.x - box.x / 2;
00105                         }
00106                         else if( GetStates() & S_ALIGN_BOTTOM )
00107                         {
00108                                 wnd = wnd + XPoint( 0, wnd.h + GetFontSize() );
00109                                 wnd.x = center.x - box.x / 2;
00110                         }
00111                         else if( GetStates() & S_ALIGN_RIGHT )
00112                         {
00113                                 wnd = wnd + XPoint( wnd.w + GetFontSize() , 0 );
00114                                 wnd.y = center.y - box.y / 2;
00115                         }
00116                         else if( GetStates() & S_ALIGN_LEFT )
00117                         {
00118                                 wnd = wnd - XPoint( box.x + GetFontSize() , 0 );
00119                                 wnd.y = center.y - box.y / 2;
00120                         }
00121                         wnd.w = box.x;
00122                         wnd.h = box.y;
00123                         ResetState( VALIGN_MASK|HALIGN_MASK );
00124                         Grow( GetFontSize() / 2 );
00125                         DrawBG();
00126                         XButton::Draw();
00127                         SetState( stateBak );
00128                         SDL_UpdateRect( GetGDI() , x , y , w + 1 , h + 1 );
00129                         static_cast<XRect &>( *this ) = bak;
00130                 }
00131         }
00132 }
00133 
00134 }
00135 
00136 

Generated on Fri Dec 5 04:06:00 2003 for Borqueror by doxygen 1.3.3