-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnextbox.cpp
52 lines (44 loc) · 1.39 KB
/
nextbox.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
#include "nextbox.h"
NextBox::NextBox(QWidget *parent) : QWidget(parent){
nextBlock.clear();
int w = 30*4 + 4*(4-1);
int h = 30*4 + 4*(4-1);
setFixedSize(w, h);
}
void NextBox::updateNextTetris(Tetris tetris){
nextBlock = tetris.getNextBlock();
for (int i = 0; i < 4; i++){
nextBlock.setX(i, nextBlock.getX(i)-3);
nextBlock.setY(i, nextBlock.getY(i)+3);
}
repaint();
}
void NextBox::paintEvent(QPaintEvent *event){
QPainter painter(this);
painter.setPen(Qt::black);
painter.drawRect(this->rect().x(),this->rect().y(),this->rect().width()-1,this->rect().height()-1);
painter.setPen(Qt::white);
int w = 30*4 + 4*(4-1);
int h = 30*4 + 4*(4-1);
setPalette(QPalette(Qt::black));
setAutoFillBackground(true);
for (int i = 1; i < 4; i++){
painter.drawLine(i*34-2, 0, i*34-2, h);
}
for (int i = 1; i < 4; i++){
painter.drawLine(0, i*34-2, w, i*34-2);
}
QPen nextBlockPen;
QBrush nextBlockBrush;
nextBlockPen.setStyle(Qt::SolidLine);
nextBlockPen.setColor(Qt::gray);
nextBlockBrush.setStyle(Qt::SolidPattern);
nextBlockBrush.setColor(nextBlock.getColor());
painter.setPen(nextBlockPen);
painter.setBrush(nextBlockBrush);
for (int i = 0; i < 4; i++){
int x = nextBlock.getX(i);
int y = nextBlock.getY(i);
painter.drawRect(x*34, y*34, 30, 30);
}
}