forked from OpenDDS/OpenDDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle.cpp
68 lines (57 loc) · 1.58 KB
/
Circle.cpp
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
// Tell GCC to ignore implicitly declared copy methods as long as
// Qt is not compliant.
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-copy"
#endif
#include <QtGui/qpainter.h>
#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif
#include <vector>
#include "Circle.hpp"
Circle::Circle(const QRect& bounds,
std::shared_ptr<ShapeDynamics> dynamics,
const QPen& pen,
const QBrush& brush,
bool targeted)
: Shape(bounds, pen, brush, targeted),
dynamics_(dynamics)
{ }
void
Circle::update() {
dynamics_->simulate();
}
void
Circle::paint(QPainter& painter) {
painter.setBrush(brush_);
painter.setPen(pen_);
std::vector<QPoint> plist = dynamics_->getPositionList();
std::vector<QPoint>::iterator idx = plist.begin();
QBrush black( QColor(0x33, 0x33, 0x33), Qt::SolidPattern);
QBrush white( QColor(0xFF, 0xFF, 0xFF), Qt::SolidPattern);
QBrush brush;
while (idx != plist.end()) {
painter.drawEllipse(idx->x() - bounds_.width()/2,
idx->y() - bounds_.height()/2,
bounds_.width(),
bounds_.height());
if (targeted_)
brush = black;
else
brush = white;
int X0 = idx->x();
int Y0 = idx->y();
int W = bounds_.width()/3;
int H = bounds_.height()/3;
painter.setBrush(brush);
painter.drawEllipse(X0 - W/2,
Y0 - H/2,
W,
H);
painter.setBrush(brush_);
++idx;
}
}
Circle::~Circle() {
}