QtBiomeVisualiser: Extended zoom down below 100%.
This commit is contained in:
parent
69b46aeb27
commit
ddf130f849
@ -8,11 +8,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static const int DELTA_STEP = 120; // The normal per-notch wheel delta
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BiomeView::BiomeView(QWidget * parent) :
|
BiomeView::BiomeView(QWidget * parent) :
|
||||||
super(parent),
|
super(parent),
|
||||||
m_X(0),
|
m_X(0),
|
||||||
m_Z(0),
|
m_Z(0),
|
||||||
m_Zoom(1)
|
m_Zoom(1),
|
||||||
|
m_IsMouseDragging(false),
|
||||||
|
m_MouseWheelDelta(0)
|
||||||
{
|
{
|
||||||
// Create the image used for undefined chunks:
|
// Create the image used for undefined chunks:
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@ -281,9 +289,17 @@ void BiomeView::mouseReleaseEvent(QMouseEvent *)
|
|||||||
|
|
||||||
void BiomeView::wheelEvent(QWheelEvent * a_Event)
|
void BiomeView::wheelEvent(QWheelEvent * a_Event)
|
||||||
{
|
{
|
||||||
m_Zoom += floor(a_Event->delta() / 90.0);
|
m_MouseWheelDelta += a_Event->delta();
|
||||||
m_Zoom = Clamp(m_Zoom, 1.0, 20.0);
|
while (m_MouseWheelDelta >= DELTA_STEP)
|
||||||
redraw();
|
{
|
||||||
|
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_PageUp:
|
||||||
case Qt::Key_Q:
|
case Qt::Key_Q:
|
||||||
{
|
{
|
||||||
m_Zoom++;
|
increaseZoom();
|
||||||
if (m_Zoom > 20.0)
|
|
||||||
{
|
|
||||||
m_Zoom = 20.0;
|
|
||||||
}
|
|
||||||
redraw();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Qt::Key_PageDown:
|
case Qt::Key_PageDown:
|
||||||
case Qt::Key_E:
|
case Qt::Key_E:
|
||||||
{
|
{
|
||||||
m_Zoom--;
|
decreaseZoom();
|
||||||
if (m_Zoom < 1.0)
|
|
||||||
{
|
|
||||||
m_Zoom = 1.0;
|
|
||||||
}
|
|
||||||
redraw();
|
|
||||||
break;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,6 +49,9 @@ protected:
|
|||||||
/** Set to true when the user has a mouse button depressed, and is dragging the view. */
|
/** Set to true when the user has a mouse button depressed, and is dragging the view. */
|
||||||
bool m_IsMouseDragging;
|
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 */
|
/** Data used for rendering a chunk that hasn't been loaded yet */
|
||||||
uchar m_EmptyChunkImage[16 * 16 * 4];
|
uchar m_EmptyChunkImage[16 * 16 * 4];
|
||||||
|
|
||||||
@ -79,6 +82,12 @@ protected:
|
|||||||
|
|
||||||
/** Called when the user presses a key. */
|
/** Called when the user presses a key. */
|
||||||
virtual void keyPressEvent(QKeyEvent * a_Event) override;
|
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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user