summaryrefslogtreecommitdiffstats
path: root/Tools/QtBiomeVisualiser/BiomeView.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-10-06 17:38:42 +0200
committerHowaner <franzi.moos@googlemail.com>2014-10-06 17:38:42 +0200
commita59f2d15fbaa934f517d9bb5fbe4737078188f9d (patch)
tree3e54201e4cffb6b9675eb6a1584925b911f924f8 /Tools/QtBiomeVisualiser/BiomeView.cpp
parentBetter StreamNextChunk() method (diff)
parentFixed crash in ForEachEntityInBox API. (diff)
downloadcuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.gz
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.bz2
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.lz
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.xz
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.zst
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.zip
Diffstat (limited to 'Tools/QtBiomeVisualiser/BiomeView.cpp')
-rw-r--r--Tools/QtBiomeVisualiser/BiomeView.cpp97
1 files changed, 42 insertions, 55 deletions
diff --git a/Tools/QtBiomeVisualiser/BiomeView.cpp b/Tools/QtBiomeVisualiser/BiomeView.cpp
index ce5a870cd..b44b935d7 100644
--- a/Tools/QtBiomeVisualiser/BiomeView.cpp
+++ b/Tools/QtBiomeVisualiser/BiomeView.cpp
@@ -42,8 +42,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:
+ // Allow mouse and keyboard interaction:
setFocusPolicy(Qt::StrongFocus);
+ setMouseTracking(true);
}
@@ -80,6 +81,27 @@ void BiomeView::setChunkSource(std::shared_ptr<ChunkSource> a_ChunkSource)
+void BiomeView::setPosition(int a_BlockX, int a_BlockZ)
+{
+ m_X = a_BlockX;
+ m_Z = a_BlockZ;
+ redraw();
+}
+
+
+
+
+
+void BiomeView::setZoomLevel(double a_ZoomLevel)
+{
+ m_Zoom = a_ZoomLevel;
+ redraw();
+}
+
+
+
+
+
void BiomeView::redraw()
{
if (!hasData())
@@ -275,6 +297,12 @@ void BiomeView::mousePressEvent(QMouseEvent * a_Event)
void BiomeView::mouseMoveEvent(QMouseEvent * a_Event)
{
+ // If there's no data displayed, bail out:
+ if (!hasData())
+ {
+ return;
+ }
+
if (m_IsMouseDragging)
{
// The user is dragging the mouse, move the view around:
@@ -286,7 +314,15 @@ void BiomeView::mouseMoveEvent(QMouseEvent * a_Event)
return;
}
- // TODO: Update the status bar info for the biome currently pointed at
+ // Update the status bar info text:
+ int blockX = floor((a_Event->x() - width() / 2) / m_Zoom + m_X);
+ int blockZ = floor((a_Event->y() - height() / 2) / m_Zoom + m_Z);
+ int chunkX, chunkZ;
+ int relX = blockX, relY, relZ = blockZ;
+ cChunkDef::AbsoluteToRelative(relX, relY, relZ, chunkX, chunkZ);
+ auto chunk = m_Cache.fetch(chunkX, chunkZ);
+ int biome = (chunk.get() != nullptr) ? chunk->getBiome(relX, relZ) : biInvalidBiome;
+ emit hoverChanged(blockX, blockZ, biome);
}
@@ -307,12 +343,12 @@ void BiomeView::wheelEvent(QWheelEvent * a_Event)
m_MouseWheelDelta += a_Event->delta();
while (m_MouseWheelDelta >= DELTA_STEP)
{
- increaseZoom();
+ emit wheelUp();
m_MouseWheelDelta -= DELTA_STEP;
}
while (m_MouseWheelDelta <= -DELTA_STEP)
{
- decreaseZoom();
+ emit wheelDown();
m_MouseWheelDelta += DELTA_STEP;
}
}
@@ -360,14 +396,14 @@ void BiomeView::keyPressEvent(QKeyEvent * a_Event)
case Qt::Key_PageUp:
case Qt::Key_Q:
{
- increaseZoom();
+ emit increaseZoom();
break;
}
case Qt::Key_PageDown:
case Qt::Key_E:
{
- decreaseZoom();
+ emit decreaseZoom();
break;
}
}
@@ -376,52 +412,3 @@ 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();
-}
-
-
-
-