-
Notifications
You must be signed in to change notification settings - Fork 7
/
widget.h
79 lines (60 loc) · 1.75 KB
/
widget.h
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
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QTimer>
#include <QTime>
static const int RIPPLE_RAD = 3;
static const int DELAY = 30; // delay is desired animation FPS
namespace Ui {
class Widget;
}
//!
//! \brief The Widget class - this widget implements the Water Ripple effect, the idea
//! and some of the code were copied from: http://agilerepose.weebly.com/water-ripple.html
//! I kept some of the original coments on the code...
//!
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = nullptr);
~Widget();
// QWidget interface
protected:
bool eventFilter(QObject *obj, QEvent *event);
private slots:
void on_pushButton_clicked();
void update();
private:
// -------------------------------------------------------
// Drop something in the water at location: dx, dy
// -------------------------------------------------------
void dropAt(int dx, int dy);
// -------------------------------------------------------
// Create the next frame of the ripple effect
// -------------------------------------------------------
void processFrame();
private:
Ui::Widget *ui;
//!
//! \brief _timer - the event timer to control animation loop
//!
QTimer* _timer;
//!
//! \brief _clock - used to control the random drop event
//!
QTime* _clock;
int _width;
int _height;
int _half_width;
int _half_height;
int _size; // space for 2 images (old and new), +2 to cover ripple radius <= 3
int _last_index;
int _current_index; // +2 from above size calc +1 more to get to 2nd image
int _map_index;
int *_ripple_map;
int *_last_map;
QImage* _texture;
QImage* _ripple;
};
#endif // WIDGET_H