1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "anim_bitmap.hpp"
25 #include "generic_bitmap.hpp"
26 #include "os_factory.hpp"
27 #include "os_graphics.hpp"
28 #include "os_timer.hpp"
31 AnimBitmap::AnimBitmap( intf_thread_t *pIntf, const GenericBitmap &rBitmap ):
32 SkinObject( pIntf ), m_pImage( NULL ), m_curFrame( 0 ), m_curLoop( 0 ),
33 m_pTimer( NULL ), m_cmdNextFrame( this ), m_rBitmap( rBitmap )
36 OSFactory *pOsFactory = OSFactory::instance( pIntf );
37 m_pImage = pOsFactory->createOSGraphics( rBitmap.getWidth(),
38 rBitmap.getHeight() );
39 m_pImage->drawBitmap( rBitmap, 0, 0 );
41 m_nbFrames = rBitmap.getNbFrames();
42 m_frameRate = rBitmap.getFrameRate();
43 m_nbLoops = rBitmap.getNbLoops();
46 m_pTimer = pOsFactory->createOSTimer( m_cmdNextFrame );
50 AnimBitmap::~AnimBitmap()
57 void AnimBitmap::startAnim()
59 if( m_nbFrames > 1 && m_frameRate > 0 )
60 m_pTimer->start( 1000 / m_frameRate, false );
64 void AnimBitmap::stopAnim()
72 void AnimBitmap::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h,
73 int xOffset, int yOffset )
75 // Draw the current frame
76 int height = m_pImage->getHeight() / m_nbFrames;
77 int ySrc = height * m_curFrame;
79 // The old way .... transparency was not taken care of
80 // rImage.drawGraphics( *m_pImage, 0, ySrc, xDest, yDest,
81 // m_pImage->getWidth(), height );
83 rImage.drawBitmap( m_rBitmap,
84 xOffset, ySrc + yOffset,
85 xDest, yDest, w, h, true );
89 bool AnimBitmap::hit( int x, int y ) const
91 int height = m_pImage->getHeight() / m_nbFrames;
92 return y >= 0 && y < height &&
93 m_pImage->hit( x, m_curFrame * height + y );
97 int AnimBitmap::getWidth() const
99 return m_pImage->getWidth();
103 int AnimBitmap::getHeight() const
105 return m_pImage->getHeight() / m_nbFrames;
109 void AnimBitmap::CmdNextFrame::execute()
112 m_pParent->m_curFrame = ( m_pParent->m_curFrame + 1 ) %
113 m_pParent->m_nbFrames;
115 if( m_pParent->m_nbLoops > 0 && m_pParent->m_curFrame == 0 )
117 m_pParent->m_curLoop += 1;
119 if( m_pParent->m_curLoop == m_pParent->m_nbLoops )
121 m_pParent->stopAnim();
122 m_pParent->m_curFrame = m_pParent->m_nbFrames - 1;
126 // Notify the observer so that it can display the next frame