summaryrefslogtreecommitdiffstats
path: root/kenolaba/Ball.h
blob: dfeb29da4ff3c37676cd31c72569ef24b0a97da7 (plain)
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
156
157
/* 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 <tqpixmap.h>
#include <tqimage.h>
#include <tqcolor.h>
#include <tqwidget.h>
#include <tqptrlist.h>

/* textures for balls */
#define TEX_FLAT   0
#define TEX_RIPPLE 1

class Ball {
  
 public:
  Ball(const TQColor& c, double a = 0.0, int t=TEX_RIPPLE );
  ~Ball();

  TQPixmap* pixmap();

  double angle() { return an; }
  TQColor 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 TQColor& c = TQColor(200,230,255) );
  static void setTexture(double c=13., double d=.2);

 private:

  void render();
  static void invalidate();

  //static TQImage back;
  static int sizeX, sizeY;
  static double lightX, lightY, lightZ;
  static TQColor lightColor;
  static double rippleCount, rippleDepth;

  TQPixmap pm;
  TQColor 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;
  TQPtrList<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 TQWidget
{
  TQ_OBJECT
  

 public:
  BallWidget(int _freq, int bFr, TQWidget *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(TQPaintDevice *);
  
  virtual void resizeEvent(TQResizeEvent *);
  virtual void paintEvent(TQPaintEvent *);

 signals:
  void animationFinished(int);
  void animationsFinished(void);

 protected:
  void drawBackground();

 private slots:
  void animate();

 protected:
  TQMemArray<BallPosition*> positions;
  TQMemArray<BallAnimation*> animations;

 private:
  int freq;
  int xStart, yStart, realSize, ballFraction;
  bool isRunning;
  TQTimer *timer;
};


/* Ball Test */

class BallTest: public BallWidget
{
  TQ_OBJECT
  
public:
  BallTest(TQWidget *parent=0, const char *name=0 );
protected:
  void mousePressEvent( TQMouseEvent * );
  void mouseReleaseEvent( TQMouseEvent * );


};




#endif // _BALL_H_