00001 #include "SdlArs.h"
00002
00003 namespace Ars
00004 {
00005
00006 XImage::XImage( void )
00007 : id( -1 ) , fade( 255 )
00008 {
00009 }
00010
00011 XImage::~XImage( void )
00012 {
00013 }
00014
00015 void XImage::Init( icstring &aStr )
00016 {
00017 XBox::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 tmp = Rsrc::FindCrdOf( aStr , "fade" );
00025 fade = Rsrc::GetInt( tmp , fade );
00026 }
00027
00028 const bool XImage::SetupWindow( const Message &msg )
00029 {
00030 XBox::SetupWindow( msg );
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
00039 Graf::Img( id , static_cast<XRect *>( this ) );
00040 clientRect = *this;
00041 return true;
00042 }
00043
00044 void XImage::ChangeImage( const std::string &aFilename )
00045 {
00046 int previd = id;
00047 id = Graf::LoadImg( aFilename );
00048 Graf::Img( id , static_cast<XRect *>( this ) );
00049 clientRect = *this;
00050 if( previd != id )
00051 SetDirty();
00052 UpdateWindow();
00053 }
00054
00055 void XImage::ChangeImage( const std::string &aSection , const std::string &aId , std::string aFilename )
00056 {
00057 int previd = id;
00058 id = Graf::LoadImg( aSection , aId , aFilename );
00059 Graf::Img( id , static_cast<XRect *>( this ) );
00060 clientRect = *this;
00061 if( previd != id )
00062 SetDirty();
00063 UpdateWindow();
00064 }
00065
00066 void XImage::SetImageId( const int aId )
00067 {
00068 int previd = id;
00069 id = aId;
00070
00071 Graf::Img( id , static_cast<XRect *>( this ) );
00072 clientRect = *this;
00073
00074 if( previd != id )
00075 SetDirty();
00076 UpdateWindow();
00077 }
00078
00079 void XImage::Draw( void )
00080 {
00081 XBox::Draw();
00082 XRect dst( GetWindowRect() );
00083 SDL_Surface *sfc = Graf::Img( id );
00084 if( sfc )
00085 {
00086 SDL_SetAlpha( sfc , SDL_SRCALPHA , fade );
00087 Graf::SDL_StretchBlt( sfc , 0 , GetGDI() , &dst , false );
00088
00089 }
00090 }
00091
00092 }