Commit a0f5957a authored by Erwan Tulou's avatar Erwan Tulou

skins2: add a 'loop' parameter for animated bitmaps

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