Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapwidget.cc')
-rw-r--r--src/mapwidget.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/mapwidget.cc b/src/mapwidget.cc
new file mode 100644
index 0000000..3c0d846
--- /dev/null
+++ b/src/mapwidget.cc
@@ -0,0 +1,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;
+ }
+}
+
+}