draw selection rect only if mouse has moved

This commit is contained in:
2026-08-14 22:20:35 +02:00
parent d36e59fd26
commit 1cf7c264c1
5 changed files with 41 additions and 4 deletions

View File

@@ -148,6 +148,7 @@ GameWorldView::GameWorldView(Simulation* sim, const GameConfig* config,
, m_debugDraw(false)
, m_rng(std::random_device{}())
, m_boxSelecting(false)
, m_boxDragMoved(false)
, m_gameOverShown(false)
, m_schematicChoiceShown(false)
{
@@ -300,6 +301,10 @@ void GameWorldView::onFrame()
{
m_boxCurrentTile =
getCoordinates().widgetToTile(mapFromGlobal(QCursor::pos()));
// The cursor has not travelled a pixel, so the drag threshold above never
// trips; but the scroll has grown the box past the tile it started on,
// which has to become visible.
if (m_boxCurrentTile != m_boxStartTile) { m_boxDragMoved = true; }
}
}
@@ -420,8 +425,9 @@ void GameWorldView::paintGL()
WorldRenderFrame GameWorldView::makeRenderFrame() const
{
return WorldRenderFrame{m_selection, m_buildMode, m_activeBeams, m_boxSelecting,
m_boxStartTile, m_boxCurrentTile, m_debugDraw};
return WorldRenderFrame{m_selection, m_buildMode, m_activeBeams,
m_boxSelecting, m_boxDragMoved, m_boxStartTile,
m_boxCurrentTile, m_debugDraw};
}
// ---------------------------------------------------------------------------
@@ -1224,6 +1230,8 @@ void GameWorldView::mousePressEvent(QMouseEvent* event)
m_boxSelecting = true;
m_boxStartTile = tile;
m_boxCurrentTile = tile;
m_boxStartPos = event->pos();
m_boxDragMoved = false;
break;
case ControlAction::Select:
@@ -1238,6 +1246,8 @@ void GameWorldView::mousePressEvent(QMouseEvent* event)
m_boxSelecting = true;
m_boxStartTile = tile;
m_boxCurrentTile = tile;
m_boxStartPos = event->pos();
m_boxDragMoved = false;
}
break;
@@ -1349,6 +1359,14 @@ void GameWorldView::mouseMoveEvent(QMouseEvent* event)
const QPoint tile = coordinates.widgetToTile(event->pos());
m_cursorWorldPos = coordinates.widgetToWorld(event->pos());
// A press is a drag once the cursor has travelled far enough from it; below that
// it stays a click and shows no rectangle (REQ-UI-MULTI-SELECT).
if (m_boxSelecting
&& (event->pos() - m_boxStartPos).manhattanLength() >= kBoxDragThresholdPixels)
{
m_boxDragMoved = true;
}
if (m_buildMode.isBuilderMode())
{
m_buildMode.setGhostTile(tile);