forked from OpenDDS/OpenDDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Square.cpp
58 lines (48 loc) · 1.3 KB
/
Square.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
#include "Square.hpp"
#include <iostream>
Square::Square(const QRect& bounds,
std::shared_ptr<ShapeDynamics> dynamics,
const QPen& pen,
const QBrush& brush,
bool targeted)
: Shape(bounds, pen, brush, targeted),
dynamics_(dynamics)
{ }
void
Square::update() {
dynamics_->simulate();
}
void
Square::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.drawRect(idx->x() - bounds_.width()/2,
idx->y() - bounds_.height()/2,
bounds_.width(),
bounds_.height());
if (targeted_)
brush = black;
else
brush = white;
painter.setBrush(brush);
int X0 = idx->x();
int Y0 = idx->y();
int W = bounds_.width()/3;
int H = bounds_.height()/3;
painter.setBrush(brush);
painter.drawRect(X0 - W/2,
Y0 - H/2,
W,
H);
painter.setBrush(brush_);
++idx;
}
}
Square::~Square() {
}