summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-09-14 22:20:16 +0200
committerMattes D <github@xoft.cz>2014-09-14 22:20:16 +0200
commitddf130f849f81670254ea2baf79fd06adcc0f302 (patch)
tree7dda9ba798ba6ce8d20ec98d987e69a29b287018
parentQtBiomeVisualiser: Added mouse and keyboard view control. (diff)
downloadcuberite-ddf130f849f81670254ea2baf79fd06adcc0f302.tar
cuberite-ddf130f849f81670254ea2baf79fd06adcc0f302.tar.gz
cuberite-ddf130f849f81670254ea2baf79fd06adcc0f302.tar.bz2
cuberite-ddf130f849f81670254ea2baf79fd06adcc0f302.tar.lz
cuberite-ddf130f849f81670254ea2baf79fd06adcc0f302.tar.xz
cuberite-ddf130f849f81670254ea2baf79fd06adcc0f302.tar.zst
cuberite-ddf130f849f81670254ea2baf79fd06adcc0f302.zip
-rw-r--r--Tools/QtBiomeVisualiser/BiomeView.cpp87
-rw-r--r--Tools/QtBiomeVisualiser/BiomeView.h9
2 files changed, 80 insertions, 16 deletions
diff --git a/Tools/QtBiomeVisualiser/BiomeView.cpp b/Tools/QtBiomeVisualiser/BiomeView.cpp
index 3d24ed126..671942440 100644
--- a/Tools/QtBiomeVisualiser/BiomeView.cpp
+++ b/Tools/QtBiomeVisualiser/BiomeView.cpp
@@ -8,11 +8,19 @@
+static const int DELTA_STEP = 120; // The normal per-notch wheel delta
+
+
+
+
+
BiomeView::BiomeView(QWidget * parent) :
super(parent),
m_X(0),
m_Z(0),
- m_Zoom(1)
+ m_Zoom(1),
+ m_IsMouseDragging(false),
+ m_MouseWheelDelta(0)
{
// Create the image used for undefined chunks:
int offset = 0;
@@ -281,9 +289,17 @@ void BiomeView::mouseReleaseEvent(QMouseEvent *)
void BiomeView::wheelEvent(QWheelEvent * a_Event)
{
- m_Zoom += floor(a_Event->delta() / 90.0);
- m_Zoom = Clamp(m_Zoom, 1.0, 20.0);
- redraw();
+ m_MouseWheelDelta += a_Event->delta();
+ while (m_MouseWheelDelta >= DELTA_STEP)
+ {
+ increaseZoom();
+ m_MouseWheelDelta -= DELTA_STEP;
+ }
+ while (m_MouseWheelDelta <= -DELTA_STEP)
+ {
+ decreaseZoom();
+ m_MouseWheelDelta += DELTA_STEP;
+ }
}
@@ -329,24 +345,14 @@ void BiomeView::keyPressEvent(QKeyEvent * a_Event)
case Qt::Key_PageUp:
case Qt::Key_Q:
{
- m_Zoom++;
- if (m_Zoom > 20.0)
- {
- m_Zoom = 20.0;
- }
- redraw();
+ increaseZoom();
break;
}
case Qt::Key_PageDown:
case Qt::Key_E:
{
- m_Zoom--;
- if (m_Zoom < 1.0)
- {
- m_Zoom = 1.0;
- }
- redraw();
+ decreaseZoom();
break;
}
}
@@ -355,3 +361,52 @@ void BiomeView::keyPressEvent(QKeyEvent * a_Event)
+
+void BiomeView::decreaseZoom()
+{
+ if (m_Zoom > 1.001)
+ {
+ m_Zoom--;
+ if (m_Zoom < 1.0)
+ {
+ // Just crossed the 100%, fixate the 100% threshold:
+ m_Zoom = 1.0;
+ }
+ }
+ else if (m_Zoom > 0.01)
+ {
+ m_Zoom = m_Zoom / 2;
+ }
+ redraw();
+}
+
+
+
+
+
+void BiomeView::increaseZoom()
+{
+ if (m_Zoom > 0.99)
+ {
+ if (m_Zoom > 20.0)
+ {
+ // Zoom too large
+ return;
+ }
+ m_Zoom++;
+ }
+ else
+ {
+ m_Zoom = m_Zoom * 2;
+ if (m_Zoom > 1.0)
+ {
+ // Just crossed the 100%, fixate the 100% threshold:
+ m_Zoom = 1.0;
+ }
+ }
+ redraw();
+}
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/BiomeView.h b/Tools/QtBiomeVisualiser/BiomeView.h
index 8aae43df0..61bda45c2 100644
--- a/Tools/QtBiomeVisualiser/BiomeView.h
+++ b/Tools/QtBiomeVisualiser/BiomeView.h
@@ -49,6 +49,9 @@ protected:
/** Set to true when the user has a mouse button depressed, and is dragging the view. */
bool m_IsMouseDragging;
+ /** Accumulator for the mouse wheel's delta. When the accumulator hits a threshold, the view zooms. */
+ int m_MouseWheelDelta;
+
/** Data used for rendering a chunk that hasn't been loaded yet */
uchar m_EmptyChunkImage[16 * 16 * 4];
@@ -79,6 +82,12 @@ protected:
/** Called when the user presses a key. */
virtual void keyPressEvent(QKeyEvent * a_Event) override;
+
+ /** Decreases the zoom level and queues a redraw. */
+ void decreaseZoom();
+
+ /** Increases the zoom level and queues a redraw. */
+ void increaseZoom();
};