1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/* Class Ball, BallWidget
*
* Online rendered balls with caching + animation widget
*
* Supported static effects
* - ball color
* - ripple texture
*
* Supported animation sequences for now:
* - Color Blending
* - Texture rotate
*
* April 1999, Josef Weidendorfer
*/
#ifndef _BALL_H_
#define _BALL_H_
#include <qpixmap.h>
#include <qimage.h>
#include <qcolor.h>
#include <qwidget.h>
#include <qptrlist.h>
/* textures for balls */
#define TEX_FLAT 0
#define TEX_RIPPLE 1
class Ball {
public:
Ball(const QColor& c, double a = 0.0, int t=TEX_RIPPLE );
~Ball();
QPixmap* pixmap();
double angle() { return an; }
QColor ballColor() { return bColor; }
void setSpecials(double z, double f, double l)
{ zoom = z, flip=f, limit=l; }
static int w() { return sizeX; }
static int h() { return sizeY; }
static void setSize(int x,int y);
static void setLight(int x=5, int y=3, int z=10,
const QColor& c = QColor(200,230,255) );
static void setTexture(double c=13., double d=.2);
private:
void render();
static void invalidate();
//static QImage back;
static int sizeX, sizeY;
static double lightX, lightY, lightZ;
static QColor lightColor;
static double rippleCount, rippleDepth;
QPixmap pm;
QColor bColor;
double an, sina, cosa;
double zoom, flip, limit;
int tex;
Ball *next;
static Ball* first;
};
class BallAnimation {
public:
BallAnimation(int s, Ball*, Ball*);
int steps;
QPtrList<Ball> balls;
};
#define ANIMATION_STOPPED 0
#define ANIMATION_FORWARD 1
#define ANIMATION_BACK 2
#define ANIMATION_LOOP 3
#define ANIMATION_CYCLE 4
class BallPosition {
public:
BallPosition(int xp,int yp, Ball* d);
int x, y, actStep, actDir, actType;
Ball* def;
BallAnimation* actAnimation;
};
#define MAX_POSITION 130
#define MAX_ANIMATION 20
class BallWidget : public QWidget
{
Q_OBJECT
public:
BallWidget(int _freq, 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:
QMemArray<BallPosition*> positions;
QMemArray<BallAnimation*> animations;
private:
int freq;
int xStart, yStart, realSize, ballFraction;
bool isRunning;
QTimer *timer;
};
/* Ball Test */
class BallTest: public BallWidget
{
Q_OBJECT
public:
BallTest(QWidget *parent=0, const char *name=0 );
protected:
void mousePressEvent( QMouseEvent * );
void mouseReleaseEvent( QMouseEvent * );
};
#endif // _BALL_H_
|