#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"
{
}
+void CtrlButton::setLayout( GenericLayout *pLayout,
+ const Position &rPosition )
+{
+ CtrlGeneric::setLayout( pLayout, rPosition );
+ m_pLayout->getActiveVar().addObserver( this );
+}
+
void CtrlButton::handleEvent( EvtGeneric &rEvent )
{
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 );
+}
+
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 );
/// 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* );
+
};
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
// 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 )
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
/// 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;
/// 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;
int m_height;
int m_nbFrames;
int m_fps;
+ int m_nbLoops;
};
/// List
list<SubBitmap> m_listSubBitmap;
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 );
}
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 );
}
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 );
m_nbFrames = rBitmap.getNbFrames();
m_frameRate = rBitmap.getFrameRate();
+ m_nbLoops = rBitmap.getNbLoops();
// Create the timer
m_pTimer = pOsFactory->createOSTimer( m_cmdNextFrame );
void AnimBitmap::stopAnim()
{
m_pTimer->stop();
+ m_curLoop = 0;
+ m_curFrame = 0;
}
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();
}
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;
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};
/// 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();
#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];
/// 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;
};
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