summaryrefslogtreecommitdiffstats
path: root/kdirstat/kpacman.h
blob: 6294061c51924c1a0104d9e03697ade3ec41a4b4 (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
 *   File name:	kpacman.h
 *   Summary:	PacMan animation inside widgets
 *   License:	LGPL - See file COPYING.LIB for details.
 *   Author:	Stefan Hundhammer <sh@suse.de>
 *
 *   Updated:	2004-03-29
 */


#ifndef KPacMan_h
#define KPacMan_h

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <tqwidget.h>
#include <tqpainter.h>
#include <tqcolor.h>
#include <tqdatetime.h>


#ifndef NOT_USED
#    define NOT_USED(PARAM)	( (void) (PARAM) )
#endif

class TQTimer;


/**
 * Helper class to display a PacMan animation inside a widget.
 * Note that this is not a widget itself, it needs to be placed inside a widget
 * - which fact makes it suitable for use inside non-widget objects such as
 * @ref TQListViewItem.
 *
 * If you are looking for a widget that can do all that self-contained, see
 * @ref KPacMan.
 *
 * @short PacMan animation
 **/
class KPacManAnimation
{
public:
    /**
     * Constructor.
     *
     * Create a PacMan sprite in 'widget' of 'size' pixels diameter.  Start at
     * a random position and move in random direction if 'randomStart' is true.
     **/
    KPacManAnimation( TQWidget *	widget,
		      int	size,
		      bool	randomStart );

    /**
     * Destructor.
     **/
    virtual ~KPacManAnimation();

    /**
     * Animate PacMan inside this rectangle.
     * Call this frequently enough (e.g. by a timer) to get fluid motion.
     * Set up the painter prior to calling this; the entire rectangle will be
     * cleared with the current brush, and PacMan's outline will be drawn with
     * the current pen.
     *
     * PacMan moves from the left side of this rectangle to the right, turning
     * around when it (he?) reaches the right edge. It (he?) is centered
     * vertically.
     *
     * My, what is the sex of that thing? ;-)
     **/
    void animate( TQPainter *	painter,
		  TQRect		rect );

    /**
     * Restart - reset to initial position and direction.
     **/
    void restart();

    /**
     * Return the rectangle where the last PacMan was painted.
     **/
    TQRect lastPacMan()					{ return _pacManRect; }

    /**
     * Set the animation interval in milliseconds.
     **/
    void	setInterval( int intervalMilliSec ) 	{ _interval = intervalMilliSec; }
    int		interval() const			{ return _interval; }

    /**
     * Number of pixels to move for each phase.
     **/
    int		speed() const				{ return _speed; }
    void	setSpeed( int speed )			{ _speed = speed; }

    /**
     * Brush to draw PacMan's inside. Bright yellow by default.
     **/
    TQBrush	brush() const				{ return _brush; }
    void	setBrush( const TQBrush & brush )	{ _brush = brush; }

    /**
     * Number of degrees PacMan's mouth opens or closes for each animation.
     **/
    int		mouthOpenInc() const			{ return _mouthInc; }
    void	setMouthOpenInc( int deg ) 		{ _mouthInc = deg; }

    /**
     * Minimum angle in degrees that PacMan's mouth opens.
     **/
    int		minMouthOpenAngle() const		{ return _minMouth;	}
    void 	setMinMouthOpenAngle( int deg )		{ _minMouth = deg;	}

    /**
     * Maximum angle in degrees that PacMan's mouth opens.
     **/
    int		maxMouthOpenAngle() const		{ return _maxMouth;	}
    void	setMaxMouthOpenAngle( int deg )		{ _maxMouth = deg;	}

protected:

    TQWidget *	_widget;
    TQBrush	_brush;
    TQTime	_time;
    TQRect	_pacManRect;
    int		_size;
    bool	_randomStart;
    int		_speed;

    int		_minMouth;
    int		_maxMouth;
    int		_mouthInc;
    int		_interval;	// milliseconds


    // Current values

    int		_pos;
    int		_mouth;
    bool	_justStarted;
    bool	_goingRight;
};



/**
 * Widget that displays a PacMan animation.
 *
 * @short PacMan widget
 **/
class KPacMan: public TQWidget
{
    TQ_OBJECT
  

public:

    /**
     * Constructor.
     *
     * @param pacManSize	size of the PacMan sprite
     * @param randomStart	random start position and direction if true
     **/
    KPacMan( TQWidget * 	parent		= 0,
	     int 	pacManSize	= 16,
	     bool	randomStart	= false,
	     const char * widgetName	= 0 );

    /**
     * Destructor.
     **/
    virtual ~KPacMan();

    /**
     * Access to the internal @ref PacManAnimation to avoid duplicating all its
     * methods.
     **/
    KPacManAnimation * pacMan() 	{ return _pacMan; }

    /**
     * Access to the internal @ref TQPainter to avoid duplicating all its
     * methods. Change this painter in order to change the visual appearance of
     * the PacMan sprite.
     **/
    TQPainter *	painter() 		{ return _painter; }

    /**
     * Returns the animation interval in milliseconds.
     **/
    int		interval() const	{ return _interval; }

    /**
     * Set the animation interval in milliseconds.
     **/
    void 	setInterval( int intervalMilliSec );

    /**
     * Return the (left and right) margin.
     **/
    int		margin() 		{ return _margin; }

    /**
     * Set the (left and right) margin - a place PacMan never goes.
     **/
    void	setMargin( int margin )	{ _margin = margin; }

    /**
     * Returns the widget's preferred size.
     *
     * Reimplemented from @ref TQWidget.
     **/
    virtual TQSize sizeHint() const;


public slots:

    /**
     * Start the animation.
     **/
    void	start();

    /**
     * Stop the animation and clear the widget.
     **/
    void 	stop();

    /**
     * Do one animation. Triggered by timer.
     **/
    void	animate();


protected:

    /**
     * Actually do the painting.
     *
     * Reimplemented from @ref TQWidget.
     **/
    virtual void paintEvent( TQPaintEvent *ev );

    /**
     * Stop animation on mouse click.
     *
     * Reimplemented from @ref TQWidget.
     **/
    virtual void mouseReleaseEvent ( TQMouseEvent *ev );


protected:

    KPacManAnimation *	_pacMan;
    TQPainter *		_painter;
    TQTimer *		_timer;
    int			_interval;	// millisec
    bool		_active;
    int			_margin;
    int			_pacManSize;
};

#endif // KPacMan_h


// EOF