]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/anim_bitmap.cpp
0559ca834734a15d2d8c8b68e5cdbe8fe9247dcc
[vlc] / modules / gui / skins2 / src / anim_bitmap.cpp
1 /*****************************************************************************
2  * anim_bitmap.cpp
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
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"
29
30
31 AnimBitmap::AnimBitmap( intf_thread_t *pIntf, const GenericBitmap &rBitmap ):
32     SkinObject( pIntf ), m_pImage( NULL ), m_curFrame( 0 ), m_pTimer( NULL ),
33     m_cmdNextFrame( this )
34 {
35     // Build the graphics
36     OSFactory *pOsFactory = OSFactory::instance( pIntf );
37     m_pImage = pOsFactory->createOSGraphics( rBitmap.getWidth(),
38                                              rBitmap.getHeight() );
39     m_pImage->drawBitmap( rBitmap, 0, 0 );
40
41     m_nbFrames = rBitmap.getNbFrames();
42     m_frameRate = rBitmap.getFrameRate();
43
44     // Create the timer
45     m_pTimer = pOsFactory->createOSTimer( m_cmdNextFrame );
46 }
47
48
49 AnimBitmap::~AnimBitmap()
50 {
51     delete m_pImage;
52     delete m_pTimer;
53 }
54
55
56 void AnimBitmap::startAnim()
57 {
58     if( m_nbFrames > 1 && m_frameRate > 0 )
59     {
60         m_pTimer->start( 1000 / m_frameRate, false );
61     }
62 }
63
64
65 void AnimBitmap::stopAnim()
66 {
67     m_pTimer->stop();
68 }
69
70
71 void AnimBitmap::draw( OSGraphics &rImage, int xDest, int yDest )
72 {
73     // Draw the current frame
74     int height = m_pImage->getHeight() / m_nbFrames;
75     int ySrc = height * m_curFrame;
76     rImage.drawGraphics( *m_pImage, 0, ySrc, xDest, yDest,
77                          m_pImage->getWidth(), height );
78 }
79
80
81 bool AnimBitmap::hit( int x, int y ) const
82 {
83     int height = m_pImage->getHeight() / m_nbFrames;
84     if( y >= 0 && y < height )
85     {
86         return m_pImage->hit( x, m_curFrame * height + y );
87     }
88     else
89     {
90         return false;
91     }
92 }
93
94
95 int AnimBitmap::getWidth() const
96 {
97     return m_pImage->getWidth();
98 }
99
100
101 int AnimBitmap::getHeight() const
102 {
103     return m_pImage->getHeight() / m_nbFrames;
104 }
105
106
107 void AnimBitmap::CmdNextFrame::execute()
108 {
109     // Go the next frame
110     m_pParent->m_curFrame = ( m_pParent->m_curFrame + 1 ) %
111         m_pParent->m_nbFrames;
112
113     // Notify the observer so that it can display the next frame
114     m_pParent->notify();
115 }
116