Source Code (Use browser search to find items of interest.)
Class Index
kabalone'BallWidget (./kdegames/kabalone/Ball.h:97)
class BallWidget : public QWidget
{
Q_OBJECT
public:
BallWidget(int hz, int bFr, QWidget *parent = 0, const char *name = 0);
~BallWidget();
void createBlending(int, int, Ball* , Ball* );
void createBallPosition(int, int x, int y, Ball*);
void startAnimation(int pos, int anim, int type=ANIMATION_FORWARD);
void stopAnimation(int pos);
void paint(QPaintDevice *);
virtual void resizeEvent(QResizeEvent *);
virtual void paintEvent(QPaintEvent *);
signals:
void animationFinished(int);
void animationsFinished(void);
protected:
void drawBackground();
private slots:
void animate();
protected:
QArray<BallPosition*> positions;
QArray<BallAnimation*> animations;
private:
int freq;
int xStart, yStart, realSize, ballFraction;
QTimer *timer;
};
/* Ball Test */
kabalone'BallWidget::BallWidget() (./kdegames/kabalone/Ball.cpp:216)
BallWidget::BallWidget( int hz, int bFr, QWidget *parent, const char *name )
: QWidget(parent,name), positions(MAX_POSITION), animations(MAX_ANIMATION)
{
int i;
for(i=0;i<MAX_POSITION;i++)
positions[i] = 0;
for(i=0;i<MAX_ANIMATION;i++)
animations[i] = 0;
freq = hz;
ballFraction = bFr;
realSize = -1;
timer = new QTimer(this);
connect( timer, SIGNAL(timeout()), SLOT(animate()) );
}
kabalone'BallWidget::~BallWidget() (./kdegames/kabalone/Ball.cpp:234)
BallWidget::~BallWidget()
{
if (timer !=0)
delete timer;
}
kabalone'BallWidget::createBlending() (./kdegames/kabalone/Ball.cpp:240)
void BallWidget::createBlending(int no, int s, Ball* b1, Ball* b2)
{
if (no<0 || no>= MAX_ANIMATION) return;
if (animations[no] !=0)
delete animations[no];
animations[no] = new BallAnimation(s,b1,b2);
}
/* X, Y are coordinates in a virtual 1000x1000 area */
kabalone'BallWidget::createBallPosition() (./kdegames/kabalone/Ball.cpp:252)
void BallWidget::createBallPosition(int no, int x, int y, Ball* def)
{
if (no<0 || no>= MAX_POSITION) return;
if (positions[no] !=0)
delete positions[no];
positions[no] = new BallPosition(x,y, def);
}
kabalone'BallWidget::startAnimation() (./kdegames/kabalone/Ball.cpp:262)
void BallWidget::startAnimation(int pos, int anim, int type)
{
BallPosition *p;
if (pos<0 || pos>=MAX_POSITION || positions[pos]==0) return;
if (anim<0 || anim>=MAX_ANIMATION || animations[anim]==0) return;
p = positions.at(pos);
p->actAnimation = animations.at(anim);
/* One step *BEFORE* start */
p->actStep = -1;
p->actDir = 1;
p->actType = type;
if (!timer->isActive())
timer->start( 1000 / freq );
}
/* If LOOP: Set to ONESHOT, otherwise set to last frame */
kabalone'BallWidget::stopAnimation() (./kdegames/kabalone/Ball.cpp:282)
void BallWidget::stopAnimation(int pos)
{
BallPosition *p;
if (pos<0 || pos>=MAX_POSITION || positions[pos]==0) return;
p = positions.at(pos);
if (p->actType == ANIMATION_STOPPED ||
p->actAnimation == 0) return;
if (p->actType == ANIMATION_LOOP ||
p->actType == ANIMATION_CYCLE) {
p->actType = ANIMATION_FORWARD;
return;
}
/* Set last step: animate() does the rest */
p->actDir = 1;
p->actStep = p->actAnimation->steps;
}
kabalone'BallWidget::resizeEvent() (./kdegames/kabalone/Ball.cpp:302)
void BallWidget::resizeEvent(QResizeEvent *)
{
int w = width() *10/12, h = height();
realSize = (w>h) ? h:w;
Ball::setSize( realSize/ballFraction, realSize/ballFraction );
repaint();
}
kabalone'BallWidget::paintEvent() (./kdegames/kabalone/Ball.cpp:312)
void BallWidget::paintEvent(QPaintEvent *)
{
paint(this);
}
kabalone'BallWidget::paint() (./kdegames/kabalone/Ball.cpp:318)
void BallWidget::paint(QPaintDevice *pd)
{
int i;
BallPosition *p;
int xReal, yReal;
int w = width(), h = height();
if (realSize<0) return;
for(i=0;i<MAX_POSITION;i++) {
p = positions.at(i);
if (p==0) continue;
xReal = (w + p->x * realSize / 500 - Ball::w() )/2;
yReal = (h + p->y * realSize / 500 - Ball::h() )/2;
if (p->actAnimation==0 || p->actStep==-1) {
if (p->def !=0 )
bitBlt( pd, xReal, yReal, p->def->pixmap() );
}
else {
int s = p->actStep;
if (s>= p->actAnimation->steps)
s = p->actAnimation->steps-1;
Ball* b = p->actAnimation->balls.at(s);
bitBlt( pd, xReal, yReal, b->pixmap() );
}
}
}
kabalone'BallWidget::animate() (./kdegames/kabalone/Ball.cpp:349)
void BallWidget::animate()
{
bool doAnimation = false;
int i;
BallPosition *p;
for(i=0;i<MAX_POSITION;i++) {
p = positions.at(i);
if (p==0) continue;
if (p->actType == ANIMATION_STOPPED ||
p->actAnimation ==0) continue;
p->actStep += p->actDir;
if (p->actStep <= -1) {
p->actDir = 1;
p->actStep = 1;
doAnimation = true;
}
else if (p->actStep >= p->actAnimation->steps) {
if (p->actType == ANIMATION_CYCLE) {
p->actDir = -1;
p->actStep = p->actAnimation->steps -2;
doAnimation = true;
}
else if (p->actType == ANIMATION_LOOP) {
p->actStep = 1; /*skip first frame for smooth animation */
doAnimation = true;
}
else {
p->actType = ANIMATION_STOPPED;
p->actAnimation = 0;
emit animationFinished(i);
}
}
else {
doAnimation = true;
}
}
if (!doAnimation) {
timer->stop();
emit animationsFinished();
}
repaint( false );
}
/* Ball Test */