summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-09-14 22:05:10 +0200
committerMattes D <github@xoft.cz>2014-09-14 22:05:10 +0200
commit69b46aeb27ecfbf87fec5945993a9a441cb89fc7 (patch)
tree17193cfa0ad4dfad2d20f92caa34f01c29f6215f
parentQtBiomeVisualiser: Removed build-specific variables. (diff)
downloadcuberite-69b46aeb27ecfbf87fec5945993a9a441cb89fc7.tar
cuberite-69b46aeb27ecfbf87fec5945993a9a441cb89fc7.tar.gz
cuberite-69b46aeb27ecfbf87fec5945993a9a441cb89fc7.tar.bz2
cuberite-69b46aeb27ecfbf87fec5945993a9a441cb89fc7.tar.lz
cuberite-69b46aeb27ecfbf87fec5945993a9a441cb89fc7.tar.xz
cuberite-69b46aeb27ecfbf87fec5945993a9a441cb89fc7.tar.zst
cuberite-69b46aeb27ecfbf87fec5945993a9a441cb89fc7.zip
-rw-r--r--Tools/QtBiomeVisualiser/BiomeView.cpp113
-rw-r--r--Tools/QtBiomeVisualiser/BiomeView.h28
2 files changed, 137 insertions, 4 deletions
diff --git a/Tools/QtBiomeVisualiser/BiomeView.cpp b/Tools/QtBiomeVisualiser/BiomeView.cpp
index be01fd104..3d24ed126 100644
--- a/Tools/QtBiomeVisualiser/BiomeView.cpp
+++ b/Tools/QtBiomeVisualiser/BiomeView.cpp
@@ -33,6 +33,9 @@ BiomeView::BiomeView(QWidget * parent) :
// Add a chunk-update callback mechanism:
connect(&m_Cache, SIGNAL(chunkAvailable(int, int)), this, SLOT(chunkAvailable(int, int)));
+
+ // Allow keyboard interaction:
+ setFocusPolicy(Qt::StrongFocus);
}
@@ -236,9 +239,117 @@ void BiomeView::paintEvent(QPaintEvent * a_Event)
-void BiomeView::queueChunkRender(ChunkPtr a_Chunk)
+void BiomeView::mousePressEvent(QMouseEvent * a_Event)
+{
+ m_LastX = a_Event->x();
+ m_LastY = a_Event->y();
+ m_IsMouseDragging = true;
+}
+
+
+
+
+
+void BiomeView::mouseMoveEvent(QMouseEvent * a_Event)
+{
+ if (m_IsMouseDragging)
+ {
+ // The user is dragging the mouse, move the view around:
+ m_X += (m_LastX - a_Event->x()) / m_Zoom;
+ m_Z += (m_LastY - a_Event->y()) / m_Zoom;
+ m_LastX = a_Event->x();
+ m_LastY = a_Event->y();
+ redraw();
+ return;
+ }
+
+ // TODO: Update the status bar info for the biome currently pointed at
+}
+
+
+
+
+
+void BiomeView::mouseReleaseEvent(QMouseEvent *)
+{
+ m_IsMouseDragging = false;
+}
+
+
+
+
+
+void BiomeView::wheelEvent(QWheelEvent * a_Event)
+{
+ m_Zoom += floor(a_Event->delta() / 90.0);
+ m_Zoom = Clamp(m_Zoom, 1.0, 20.0);
+ redraw();
+}
+
+
+
+
+
+void BiomeView::keyPressEvent(QKeyEvent * a_Event)
{
+ switch (a_Event->key())
+ {
+ case Qt::Key_Up:
+ case Qt::Key_W:
+ {
+ m_Z -= 10.0 / m_Zoom;
+ redraw();
+ break;
+ }
+
+ case Qt::Key_Down:
+ case Qt::Key_S:
+ {
+ m_Z += 10.0 / m_Zoom;
+ redraw();
+ break;
+ }
+
+ case Qt::Key_Left:
+ case Qt::Key_A:
+ {
+ m_X -= 10.0 / m_Zoom;
+ redraw();
+ break;
+ }
+
+ case Qt::Key_Right:
+ case Qt::Key_D:
+ {
+ m_X += 10.0 / m_Zoom;
+ redraw();
+ break;
+ }
+
+ case Qt::Key_PageUp:
+ case Qt::Key_Q:
+ {
+ m_Zoom++;
+ if (m_Zoom > 20.0)
+ {
+ m_Zoom = 20.0;
+ }
+ redraw();
+ break;
+ }
+ case Qt::Key_PageDown:
+ case Qt::Key_E:
+ {
+ m_Zoom--;
+ if (m_Zoom < 1.0)
+ {
+ m_Zoom = 1.0;
+ }
+ redraw();
+ break;
+ }
+ }
}
diff --git a/Tools/QtBiomeVisualiser/BiomeView.h b/Tools/QtBiomeVisualiser/BiomeView.h
index c54c66491..8aae43df0 100644
--- a/Tools/QtBiomeVisualiser/BiomeView.h
+++ b/Tools/QtBiomeVisualiser/BiomeView.h
@@ -35,10 +35,20 @@ public slots:
protected:
double m_X, m_Z;
- int m_Zoom;
+ double m_Zoom;
+
+ /** Cache for the loaded chunk data. */
ChunkCache m_Cache;
+
+ /** The entire view's contents in an offscreen image. */
QImage m_Image;
+ /** Coords of the mouse for the previous position, used while dragging. */
+ int m_LastX, m_LastY;
+
+ /** Set to true when the user has a mouse button depressed, and is dragging the view. */
+ bool m_IsMouseDragging;
+
/** Data used for rendering a chunk that hasn't been loaded yet */
uchar m_EmptyChunkImage[16 * 16 * 4];
@@ -55,8 +65,20 @@ protected:
/** Paints the entire widget */
virtual void paintEvent(QPaintEvent *) override;
- /** Queues the chunk for rendering. */
- void queueChunkRender(ChunkPtr a_Chunk);
+ /** Called when the user presses any mouse button. */
+ virtual void mousePressEvent(QMouseEvent * a_Event);
+
+ /** Called when the user moves the mouse. */
+ virtual void mouseMoveEvent(QMouseEvent * a_Event);
+
+ /** Called when the user releases a previously held mouse button. */
+ virtual void mouseReleaseEvent(QMouseEvent * a_Event) override;
+
+ /** Called when the user rotates the mouse wheel. */
+ virtual void wheelEvent(QWheelEvent * a_Event) override;
+
+ /** Called when the user presses a key. */
+ virtual void keyPressEvent(QKeyEvent * a_Event) override;
};