-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.cpp
More file actions
71 lines (59 loc) · 1.23 KB
/
grid.cpp
File metadata and controls
71 lines (59 loc) · 1.23 KB
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
#include "grid.h"
#include <QPainter>
#include <QPaintEvent>
/**
* Author: Yunus Rahbar
* Date: 6/10/13
*
*/
/**
* Grid
* Class for displaying a grid on the game view
*
*/
Grid::Grid(int len, QWidget *parent) :
QLabel(parent), gridLength(len), resized(true), offsetX(0), offsetY(0)
{
}
/**
* Render the grid to the game view
*/
void Grid::paintEvent(QPaintEvent *ev)
{
//if (resized) {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 1));
for (int x=offsetX;x<this->width();x+=gridLength) {
painter.drawLine(QPoint(x,0),QPoint(x,this->height()));
}
for (int y=offsetY;y<this->width();y+=gridLength) {
painter.drawLine(QPoint(0,y),QPoint(this->width(),y));
}
//}
resized = false;
}
void Grid::resizeEvent(QResizeEvent *)
{
resized = true;
}
void Grid::showEvent(QShowEvent *)
{
resized = true;
}
qint32 Grid::gridSize()
{
return gridLength;
}
void Grid::setGridSize(int n)
{
gridLength = n;
resized = true;
}
void Grid::setOffset(QPoint p) {
offsetX = p.x();
offsetY = p.y();
}
QPoint Grid::offset() {
return QPoint(offsetX,offsetY);
}