Source Code (Use browser search to find items of interest.)
Class Index
amor'AmorAnim (./kdetoys/amor/amoranim.h:26)
class AmorAnim
{
public:
AmorAnim(KConfigBase &config);
virtual ~AmorAnim();
void reset()
{ mCurrent = 0; }
bool next()
{ return (++mCurrent < mSequence.count()); }
int frameNum() const
{ return mCurrent; }
bool validFrame() const
{ return (mCurrent < mSequence.count()); }
int totalMovement() const
{ return mTotalMovement; }
QSize maximumSize() const
{ return mMaximumSize; }
int delay() const
{ return (validFrame() ? mDelay[mCurrent] : 100); }
QPoint hotspot() const
{ return (validFrame() ? mHotspot[mCurrent] : QPoint(16,16)); }
int movement() const
{ return (validFrame() ? mMovement[mCurrent] : 0); }
const QPixmap *frame();
protected:
void readConfig(KConfigBase &config);
protected:
unsigned int mCurrent; // current frame in sequence
QStrList mSequence; // sequence of images to display
QArray<int> mDelay; // delay between frames
QArray<QPoint> mHotspot; // the hotspot in a frame
QArray<int> mMovement; // the distance to move between frames
int mTotalMovement; // the total distance this animation moves
QSize mMaximumSize; // the maximum size of any frame
};
//---------------------------------------------------------------------------
amor'AmorAnim::AmorAnim() (./kdetoys/amor/amoranim.cpp:22)
AmorAnim::AmorAnim(KConfigBase &config)
: mMaximumSize(0, 0)
{
mCurrent = 0;
mTotalMovement = 0;
readConfig(config);
}
//---------------------------------------------------------------------------
//
// Destructor
//
amor'AmorAnim::~AmorAnim() (./kdetoys/amor/amoranim.cpp:34)
AmorAnim::~AmorAnim()
{
}
//---------------------------------------------------------------------------
//
// Get the Pixmap for the current frame.
//
amor'AmorAnim::frame() (./kdetoys/amor/amoranim.cpp:42)
const QPixmap *AmorAnim::frame()
{
const QPixmap *pixmap = 0;
if (validFrame())
{
pixmap = AmorPixmapManager::manager()->pixmap(mSequence.at(mCurrent));
}
return pixmap;
}
//---------------------------------------------------------------------------
//
// Read a single animation's parameters. The config class should already
// have its group set to the animation that is to be read.
//
amor'AmorAnim::readConfig() (./kdetoys/amor/amoranim.cpp:59)
void AmorAnim::readConfig(KConfigBase &config)
{
// Read the list of frames to display and load them into the pixmap
// manager.
int frames = config.readListEntry("Sequence",mSequence);
for (int i = 0; i < frames; i++)
{
const QPixmap *pixmap =
AmorPixmapManager::manager()->load(mSequence.at(i));
if (pixmap)
{
mMaximumSize = mMaximumSize.expandedTo(pixmap->size());
}
}
// Read the delays between frames.
QStrList list;
int entries = config.readListEntry("Delay",list);
mDelay.resize(frames);
for (int i = 0; i < entries && i < frames; i++)
{
mDelay[i] = atoi(list.at(i));
}
// Read the distance to move between frames and calculate the total
// distance that this aniamtion moves from its starting position.
entries = config.readListEntry("Movement",list);
mMovement.resize(frames);
for (int i = 0; i < entries; i++)
{
mMovement[i] = atoi(list.at(i));
mTotalMovement += mMovement[i];
}
// Read the hotspot for each frame.
entries = config.readListEntry("HotspotX",list);
mHotspot.resize(frames);
for (int i = 0; i < entries && i < frames; i++)
{
mHotspot[i].setX(atoi(list.at(i)));
}
entries = config.readListEntry("HotspotY",list);
for (int i = 0; i < entries && i < frames; i++)
{
mHotspot[i].setY(atoi(list.at(i)));
}
// Add the overlap of the last frame to the total movement.
const QPoint &lastHotspot = mHotspot[mHotspot.size()-1];
if (mTotalMovement >= 0)
{
const QPixmap *lastFrame =
AmorPixmapManager::manager()->pixmap(mSequence.getLast());
if (lastFrame)
{
mTotalMovement += (lastFrame->width() - lastHotspot.x());
}
}
else
{
mTotalMovement -= lastHotspot.x();
}
}
//===========================================================================