/* $Id: splashscreen.cpp,v 1.11 2005/06/28 13:55:24 chfreund Exp $ */ #include "splashscreen.hpp" #include "global.hpp" #include "loader.hpp" #include "wopsettings.hpp" SplashScreen::SplashScreen() { m_logo = Loader::getInstance()->getImage( "images/gui/wop_logo_1.png", false, true ); m_alpha = 0; SDL_SetAlpha( m_logo, SDL_SRCALPHA | SDL_RLEACCEL, 0 ); } SplashScreen::~SplashScreen() { INFO( "SplashScreen::~SplashScreen()\n" ); // prevent segfault in SplashScreen::update routine // when destructor is already called SDL_RemoveTimer( m_timer ); SDL_Delay( 200 ); // wait for 0.2 s } void SplashScreen::draw( SDL_Surface* surface ) { LOG( 5 ) INFO( "SplashScreen::draw: drawing logo with alpha %d\n", m_alpha ); SDL_Rect rect; rect.x = _pos_x; rect.y = _pos_y; SDL_BlitSurface( m_logo, NULL, surface, &rect ); } void SplashScreen::startAnimation() { m_startTicks = SDL_GetTicks(); m_timer = SDL_AddTimer( 40, splashScreenUpdateWrapper, this ); } void SplashScreen::update() { if ( m_alpha < 255 ) { if ( SDL_GetTicks() - m_startTicks > 2500 ) { m_alpha += 5; LOG( 5 ) INFO( "SplashScreen::update: setting alpha to %d\n", m_alpha ); SDL_SetAlpha( m_logo, SDL_SRCALPHA | SDL_RLEACCEL, m_alpha ); } } else { SDL_RemoveTimer( m_timer ); } } Uint32 splashScreenUpdateWrapper( Uint32 interval, void* data ) { Uint32 ticksBefore = SDL_GetTicks(); SplashScreen* splashScreen = static_cast( data ); splashScreen->update(); Uint32 ticksAfter = SDL_GetTicks(); Uint32 duration = ticksAfter - ticksBefore; Uint32 newInterval = ( duration >= 40 ) ? 1 : 40 - duration; return newInterval; }