-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDrawPainter.cpp
74 lines (62 loc) · 2.63 KB
/
DrawPainter.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
69
70
71
72
73
74
#include "DrawPainter.h"
//colot parameter setting
enum Color {
Black1 = 58,
Black2 = 64,
White = 238
};
DrawPainter::DrawPainter(QPaintDevice *parent) : QPainter(parent) {
}
void DrawPainter::init() {
//set color and anti-aliasing
this->setPen(Qt::black);
this->setRenderHint(QPainter::Antialiasing, true);
}
void DrawPainter::DrawBoard() {
//draw board grid line
for(int i = Board_start_X; i<= Board_end_X; i += Grid_Width) {
this->drawLine(Board_start_X, i, Board_end_X, i);
this->drawLine(i, Board_start_Y, i, Board_end_Y);
}
//draw board frame
this->drawRect(Board_start_X - 7, Board_start_Y - 7, Board_Width + 14, Board_Width + 14);
}
void DrawPainter::DrawPieces(const GoBangBoard& c) {
this->setPen(Qt::NoPen);
QRadialGradient radi;
//traverse board and draw pieces
for(int i = 0; i < Grid_num; i++) {
for(int j = 0; j < Grid_num; j++) {
int now_player_id = c.getBoardPositionID(i, j);
int black_player_id = c.getBlackPlayerID();
if(now_player_id != No_Player) {
if(now_player_id == black_player_id) {
radi.setColorAt(0, qRgb(Black1, Black1, Black1));
this->setBrush(radi);
this->drawEllipse(Board_start_X + Grid_Width * i - Chess_Piece_Radius, Board_start_X + Grid_Width * j - Chess_Piece_Radius, Chess_Piece_Radius * 2, Chess_Piece_Radius * 2);
}
else {
radi.setColorAt(0, qRgb(Black2, Black2, Black2));
this->setBrush(radi);
this->drawEllipse(Board_start_X + Grid_Width * i - Chess_Piece_Radius, Board_start_X + Grid_Width * j - Chess_Piece_Radius, Chess_Piece_Radius * 2, Chess_Piece_Radius * 2);
radi.setColorAt(0, qRgb(White, White, White));
this->setBrush(radi);
this->drawEllipse(Board_start_X + Grid_Width * i - Chess_Piece_Radius, Board_start_X + Grid_Width * j - Chess_Piece_Radius, Chess_Piece_Radius * 2, Chess_Piece_Radius * 2);
}
}
}
}
}
void DrawPainter::DrawLastMove(const Point& c, bool is_black) {
QPen prev_pen = this->pen();
QRadialGradient radi;
if(is_black) {
radi.setColorAt(0, qRgb(Black1, Black1, Black1));
this->setPen(qRgb(Black1, Black1, Black1));
}
else
radi.setColorAt(0, qRgb(White, White, White));
this->setBrush(radi);
this->drawEllipse(Board_start_X + Grid_Width * c.x - Mark_Radius, Board_start_X + Grid_Width * c.y - Mark_Radius, 2 * Mark_Radius, 2 * Mark_Radius);
this->setPen(prev_pen);
}