]> git.sesse.net Git - vlc/commitdiff
skins2: add a 'loop' parameter for animated bitmaps
authorErwan Tulou <erwan10@videolan.org>
Sat, 26 Dec 2009 12:54:16 +0000 (13:54 +0100)
committerErwan Tulou <erwan10@videolan.org>
Sun, 27 Dec 2009 11:05:17 +0000 (12:05 +0100)
This loop parameter is intended to run animated images for a given time
In addition, animation is started again in the following cases :
   - when visibility changes
   - when active layout changes

12 files changed:
modules/gui/skins2/controls/ctrl_button.cpp
modules/gui/skins2/controls/ctrl_button.hpp
modules/gui/skins2/parser/builder.cpp
modules/gui/skins2/parser/builder_data.def
modules/gui/skins2/parser/builder_data.hpp
modules/gui/skins2/parser/skin_parser.cpp
modules/gui/skins2/src/anim_bitmap.cpp
modules/gui/skins2/src/anim_bitmap.hpp
modules/gui/skins2/src/file_bitmap.cpp
modules/gui/skins2/src/file_bitmap.hpp
modules/gui/skins2/src/generic_bitmap.cpp
modules/gui/skins2/src/generic_bitmap.hpp

index f379c40ac69b4152e45b3af42b16899c07b9fff4..071b0ffe46f45977c23c5a4df0882c754317c73c 100644 (file)
@@ -25,6 +25,7 @@
 #include "ctrl_button.hpp"
 #include "../events/evt_generic.hpp"
 #include "../src/generic_bitmap.hpp"
+#include "../src/generic_layout.hpp"
 #include "../src/os_factory.hpp"
 #include "../src/os_graphics.hpp"
 #include "../commands/cmd_generic.hpp"
@@ -80,6 +81,13 @@ CtrlButton::~CtrlButton()
 {
 }
 
+void CtrlButton::setLayout( GenericLayout *pLayout,
+                           const Position &rPosition )
+{
+    CtrlGeneric::setLayout( pLayout, rPosition );
+    m_pLayout->getActiveVar().addObserver( this );
+}
+
 
 void CtrlButton::handleEvent( EvtGeneric &rEvent )
 {
@@ -194,3 +202,19 @@ void CtrlButton::CmdHiddenUp::execute()
     m_pParent->setImage( &m_pParent->m_imgUp );
 }
 
+void CtrlButton::onUpdate( Subject<VarBool> &rVariable, void *arg  )
+{
+    // restart animation
+    if(     &rVariable == m_pVisible
+        ||  &rVariable == &m_pLayout->getActiveVar()
+      )
+    {
+        if( m_pImg )
+        {
+            m_pImg->stopAnim();
+            m_pImg->startAnim();
+        }
+    }
+    CtrlGeneric::onUpdate( rVariable, arg );
+}
+
index 0b259bea232f7e8950e2047ed010e001905a4ad0..f1ef77eb2b0c17dd3c170603cdbb79461a08fe97 100644 (file)
@@ -45,6 +45,10 @@ public:
 
     virtual ~CtrlButton();
 
+    /// Set the position and the associated layout of the control
+    virtual void setLayout( GenericLayout *pLayout,
+                            const Position &rPosition );
+
     /// Handle an event
     virtual void handleEvent( EvtGeneric &rEvent );
 
@@ -88,6 +92,10 @@ private:
 
     /// Method called when an animated bitmap changes
     virtual void onUpdate( Subject<AnimBitmap> &rBitmap, void* );
+
+    /// Method called when visibility or ActiveLayout is updated
+    virtual void onUpdate( Subject<VarBool> &rVariable , void* );
+
 };
 
 
index 5a070671c5c4864b91b83fac46bf3ecc17afd4ce..5db40315b57cbb31d63e230b2910493300c9fe76 100644 (file)
@@ -191,7 +191,7 @@ void Builder::addBitmap( const BuilderData::Bitmap &rData )
     GenericBitmap *pBmp =
         new FileBitmap( getIntf(), m_pImageHandler,
                         getFilePath( rData.m_fileName ), rData.m_alphaColor,
-                        rData.m_nbFrames, rData.m_fps );
+                        rData.m_nbFrames, rData.m_fps, rData.m_nbLoops );
     if( !pBmp->getData() )
     {
         // Invalid bitmap
@@ -217,7 +217,7 @@ void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
     // Copy a region of the parent bitmap to the new one
     BitmapImpl *pBmp =
         new BitmapImpl( getIntf(), rData.m_width, rData.m_height,
-                        rData.m_nbFrames, rData.m_fps );
+                        rData.m_nbFrames, rData.m_fps, rData.m_nbLoops );
     bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,
                                  rData.m_width, rData.m_height );
     if( !res )
index 5a84045ca1af8576c69bf60432adc1776fb775f1..14b0580df4de09f874f4d08564936a9a26192025 100644 (file)
@@ -1,6 +1,6 @@
 Theme tooltipfont:string magnet:int alpha:uint32_t moveAlpha:uint32_t
-Bitmap id:string fileName:string alphaColor:uint32_t nbFrames:int fps:int
-SubBitmap id:string parent:string x:int y:int width:int height:int nbFrames:int fps:int
+Bitmap id:string fileName:string alphaColor:uint32_t nbFrames:int fps:int nbLoops:int
+SubBitmap id:string parent:string x:int y:int width:int height:int nbFrames:int fps:int nbLoops:int
 BitmapFont id:string file:string type:string
 Font id:string fontFile:string size:int
 PopupMenu id:string
index 4e1dd31c0be952e3acc9719e0f21b52cedae0543..6c282e116276d4abd212d74bd89507aaf2ae8610 100644 (file)
@@ -56,14 +56,15 @@ m_tooltipfont( tooltipfont ), m_magnet( magnet ), m_alpha( alpha ), m_moveAlpha(
     /// Type definition
     struct Bitmap
     {
-        Bitmap( const string & id, const string & fileName, uint32_t alphaColor, int nbFrames, int fps ):
-m_id( id ), m_fileName( fileName ), m_alphaColor( alphaColor ), m_nbFrames( nbFrames ), m_fps( fps ) {}
+        Bitmap( const string & id, const string & fileName, uint32_t alphaColor, int nbFrames, int fps, int nbLoops ):
+m_id( id ), m_fileName( fileName ), m_alphaColor( alphaColor ), m_nbFrames( nbFrames ), m_fps( fps ), m_nbLoops( nbLoops ) {}
 
         string m_id;
         string m_fileName;
         uint32_t m_alphaColor;
         int m_nbFrames;
         int m_fps;
+        int m_nbLoops;
     };
     /// List
     list<Bitmap> m_listBitmap;
@@ -71,8 +72,8 @@ m_id( id ), m_fileName( fileName ), m_alphaColor( alphaColor ), m_nbFrames( nbFr
     /// Type definition
     struct SubBitmap
     {
-        SubBitmap( const string & id, const string & parent, int x, int y, int width, int height, int nbFrames, int fps ):
-m_id( id ), m_parent( parent ), m_x( x ), m_y( y ), m_width( width ), m_height( height ), m_nbFrames( nbFrames ), m_fps( fps ) {}
+        SubBitmap( const string & id, const string & parent, int x, int y, int width, int height, int nbFrames, int fps, int nbLoops ):
+m_id( id ), m_parent( parent ), m_x( x ), m_y( y ), m_width( width ), m_height( height ), m_nbFrames( nbFrames ), m_fps( fps ), m_nbLoops( nbLoops ) {}
 
         string m_id;
         string m_parent;
@@ -82,6 +83,7 @@ m_id( id ), m_parent( parent ), m_x( x ), m_y( y ), m_width( width ), m_height(
         int m_height;
         int m_nbFrames;
         int m_fps;
+        int m_nbLoops;
     };
     /// List
     list<SubBitmap> m_listSubBitmap;
index 12e30bd163e1d273dfbcaae760424c8f3f665086..8cae5c512f6cdb27cd15cc81786e942f67de57f7 100644 (file)
@@ -115,11 +115,13 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         RequireAttr( attr, rName, "alphacolor" );
         DefaultAttr( attr, "nbframes", "1" );
         DefaultAttr( attr, "fps", "4" );
+        DefaultAttr( attr, "loop", "0" );
 
         m_curBitmapId = uniqueId( attr["id"] );
         const BuilderData::Bitmap bitmap( m_curBitmapId,
                 attr["file"], convertColor( attr["alphacolor"] ),
-                atoi( attr["nbframes"] ), atoi( attr["fps"] ) );
+                atoi( attr["nbframes"] ), atoi( attr["fps"] ),
+                atoi( attr["loop"] ) );
         m_pData->m_listBitmap.push_back( bitmap );
     }
 
@@ -132,11 +134,13 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         RequireAttr( attr, rName, "height" );
         DefaultAttr( attr, "nbframes", "1" );
         DefaultAttr( attr, "fps", "4" );
+        DefaultAttr( attr, "loop", "0" );
 
         const BuilderData::SubBitmap bitmap( uniqueId( attr["id"] ),
                 m_curBitmapId, atoi( attr["x"] ), atoi( attr["y"] ),
                 atoi( attr["width"] ), atoi( attr["height"] ),
-                atoi( attr["nbframes"] ), atoi( attr["fps"] ) );
+                atoi( attr["nbframes"] ), atoi( attr["fps"] ),
+                atoi( attr["loop"] ) );
         m_pData->m_listSubBitmap.push_back( bitmap );
     }
 
index ff247e803be9f49e20fc2847b97f04a9309ba8e2..f09da66db806d1cfc06b0226f7a25e70b0afafef 100644 (file)
@@ -29,8 +29,8 @@
 
 
 AnimBitmap::AnimBitmap( intf_thread_t *pIntf, const GenericBitmap &rBitmap ):
-    SkinObject( pIntf ), m_pImage( NULL ), m_curFrame( 0 ), m_pTimer( NULL ),
-    m_cmdNextFrame( this ), m_rBitmap( rBitmap )
+    SkinObject( pIntf ), m_pImage( NULL ), m_curFrame( 0 ), m_curLoop( 0 ),
+    m_pTimer( NULL ), m_cmdNextFrame( this ), m_rBitmap( rBitmap )
 {
     // Build the graphics
     OSFactory *pOsFactory = OSFactory::instance( pIntf );
@@ -40,6 +40,7 @@ AnimBitmap::AnimBitmap( intf_thread_t *pIntf, const GenericBitmap &rBitmap ):
 
     m_nbFrames = rBitmap.getNbFrames();
     m_frameRate = rBitmap.getFrameRate();
+    m_nbLoops = rBitmap.getNbLoops();
 
     // Create the timer
     m_pTimer = pOsFactory->createOSTimer( m_cmdNextFrame );
@@ -63,6 +64,8 @@ void AnimBitmap::startAnim()
 void AnimBitmap::stopAnim()
 {
     m_pTimer->stop();
+    m_curLoop = 0;
+    m_curFrame = 0;
 }
 
 
@@ -108,6 +111,17 @@ void AnimBitmap::CmdNextFrame::execute()
     m_pParent->m_curFrame = ( m_pParent->m_curFrame + 1 ) %
         m_pParent->m_nbFrames;
 
+    if( m_pParent->m_nbLoops > 0 && m_pParent->m_curFrame == 0 )
+    {
+        m_pParent->m_curLoop += 1;
+
+        if( m_pParent->m_curLoop == m_pParent->m_nbLoops )
+        {
+            m_pParent->stopAnim();
+            m_pParent->m_curFrame = m_pParent->m_nbFrames - 1;
+        }
+    }
+
     // Notify the observer so that it can display the next frame
     m_pParent->notify();
 }
index 1e783697a91c3c7ecfeb325291bd67eec98c46bb..6667ce118c51b2dd39db824ad985e233231bfb75 100644 (file)
@@ -67,8 +67,12 @@ private:
     int m_nbFrames;
     /// Frame rate
     int m_frameRate;
+    /// Number of Loops
+    int m_nbLoops;
     /// Curent frame
     int m_curFrame;
+    /// Current loop
+    int m_curLoop;
      /// Timer for the animation
     OSTimer *m_pTimer;
 
index 925ad2a6e0a357002488e293baf6af283cab0925..bcefa7bae8553e0b26b3dcd9105f262e4e0256aa 100644 (file)
@@ -32,8 +32,8 @@
 
 FileBitmap::FileBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
                         string fileName, uint32_t aColor, int nbFrames,
-                        int fps ):
-    GenericBitmap( pIntf, nbFrames, fps ), m_width( 0 ), m_height( 0 ),
+                        int fps, int nbLoops ):
+    GenericBitmap( pIntf, nbFrames, fps, nbLoops ), m_width( 0 ), m_height( 0 ),
     m_pData( NULL )
 {
     video_format_t fmt_in = {0}, fmt_out = {0};
index 87f83ac28e86e0cb98bde57b7e794d9ccd4949d9..1b21b77bccd39bfd0ac842129b902a2c882f8094 100644 (file)
@@ -37,7 +37,7 @@ public:
     /// color, in the format 0xRRGGBB
     FileBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
                 string fileName, uint32_t aColor, int nbFrames = 1,
-                int fps = 0 );
+                int fps = 0, int nbLoops = 0 );
 
     virtual ~FileBitmap();
 
index bf26bca12046de177cda27fbff28e5ccb3685607..37818df4cae1d0775ce79c166d62887bc2e4c221 100644 (file)
 #include "generic_bitmap.hpp"
 
 
-GenericBitmap::GenericBitmap( intf_thread_t *pIntf, int nbFrames, int fps ):
-    SkinObject( pIntf ), m_nbFrames( nbFrames ), m_frameRate( fps )
+GenericBitmap::GenericBitmap( intf_thread_t *pIntf,
+                              int nbFrames, int fps, int nbLoops ):
+    SkinObject( pIntf ), m_nbFrames( nbFrames ),
+    m_frameRate( fps ), m_nbLoops( nbLoops )
 {
 }
 
 
 BitmapImpl::BitmapImpl( intf_thread_t *pIntf, int width, int height,
-                        int nbFrames, int fps ):
-    GenericBitmap( pIntf, nbFrames, fps ), m_width( width ),
+                        int nbFrames, int fps, int nbLoops ):
+    GenericBitmap( pIntf, nbFrames, fps, nbLoops ), m_width( width ),
     m_height( height ), m_pData( NULL )
 {
     m_pData = new uint8_t[width * height * 4];
index 17fa9b9f8c9fb5b0a70eaf7d39d8338d91605b5d..800a8a0828b9a2e72f43a42ba775fef0afa10726 100644 (file)
@@ -46,14 +46,19 @@ public:
     /// Get the number of frames per second (for animated bitmaps)
     int getFrameRate() const { return m_frameRate; }
 
+    /// Get the number of Loops (for animated bitmaps)
+    int getNbLoops() const { return m_nbLoops; }
+
 protected:
-    GenericBitmap( intf_thread_t *pIntf, int nbFrames = 1, int fps = 0);
+    GenericBitmap( intf_thread_t *pIntf, int nbFrames = 1, int fps = 0, int nbLoops = 0);
 
 private:
     /// Number of frames
     int m_nbFrames;
     /// Frame rate
     int m_frameRate;
+    /// Number of Loops
+    int m_nbLoops;
 };
 
 
@@ -63,7 +68,7 @@ class BitmapImpl: public GenericBitmap
 public:
     /// Create an empty bitmap of the given size
     BitmapImpl( intf_thread_t *pIntf, int width, int height,
-                int nbFrames = 1, int fps = 0 );
+                int nbFrames = 1, int fps = 0, int nbLoops = 0 );
     ~BitmapImpl();
 
     /// Get the width of the bitmap