Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 3c0d846d5e4013fcff52c75d07bcc725ff5aba4e (plain)
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
/*
   mapwidget.cc
   This file is part of the Project::OSiRiON zone editor 
   and is distributed under the terms and conditions of 
   the GNU General Public License version 2
*/

#include <mapwidget.h>

#include <QPainter>
#include <QWheelEvent>

namespace editor
{

MapWidget::MapWidget(QWidget *parent) : QWidget(parent)
{
	setMinimumSize(128,128);
	
	// zoom sucks but it works
	mapwidget_zoom = 4;
}

void MapWidget::wheelEvent(QWheelEvent *event)
{
	if (event->orientation() == Qt::Vertical) {
		mapwidget_zoom += event->delta() / 120;
		if (mapwidget_zoom < 1)
			mapwidget_zoom = 1;
		else if (mapwidget_zoom > 64) {
			mapwidget_zoom = 64;
		}
		repaint();
		event->accept();
	}
}

void MapWidget::paintEvent(QPaintEvent *event)
{
	QPen pen(Qt::blue, 1, Qt::SolidLine);
	QPainter painter(this);
	
	painter.setPen(pen);

	// mapwidget_zoom is used to scale from game units to screen coorinates	
	// 1 grid square is 128 game units
	// gridsize is the size of one grid square in screen coordinates
	int gridsize = 128 / mapwidget_zoom;
	
	int x = width() / 2;
	while (x > 0) {
		painter.drawLine(x, 0, x, height());
		x -= gridsize;
	}
	x = width() / 2 + gridsize;
	while (x <= width()) {
		painter.drawLine(x, 0, x, height());
		x += gridsize;
	}
	
	int y = height() / 2;
	while (y > 0) {
		painter.drawLine(0, y, width(), y);
		y -= gridsize;
	}
	y = height() / 2 + gridsize;
	while (y <= height()) {
		painter.drawLine(0, y, width(), y);
		y += gridsize;
	}
}

}