Skip to content

Commit

Permalink
allow drawing lines by holding shift while painting
Browse files Browse the repository at this point in the history
Allows starting to draw, holding shift to preview a straight line,
and releasing to draw it. This is enabled by the addition of a
PaintStartSet state. Pressing right click during StartSet or
PaintStartSet cancels the operation and returns to Free.

closes mapeditor#3642
  • Loading branch information
kdx2a committed Jun 14, 2024
1 parent 9de4b79 commit dc2e89d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
40 changes: 30 additions & 10 deletions src/tiled/stampbrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void StampBrush::mousePressed(QGraphicsSceneMouseEvent *event)
if (brushItem()->isVisible()) {
if (event->button() == Qt::LeftButton) {
switch (mBrushState) {
case BrushState::PaintStartSet: // shouldn't occur
case BrushState::StartSet:
doPaint();
mStampReference = tilePosition();
Expand All @@ -134,19 +135,26 @@ void StampBrush::mousePressed(QGraphicsSceneMouseEvent *event)
case BrushBehavior::Line:
case BrushBehavior::Circle:
mStampReference = tilePosition();
mBrushState = BrushState::StartSet;
if (mBrushState == BrushState::Paint)
mBrushState = BrushState::PaintStartSet;
else
mBrushState = BrushState::StartSet;
break;
}
break;
case BrushState::Capture:
break;
}
return;
} else if (event->button() == Qt::RightButton &&
!(event->modifiers() & Qt::ControlModifier))
{
beginCapture();
return;
} else if (event->button() == Qt::RightButton) {
if (mBrushState == BrushState::StartSet || mBrushState == BrushState::PaintStartSet) {
mBrushState = BrushState::Free;
updatePreview();
return;
} else if (!(event->modifiers() & Qt::ControlModifier)) {
beginCapture();
return;
}
}
}

Expand All @@ -156,11 +164,14 @@ void StampBrush::mousePressed(QGraphicsSceneMouseEvent *event)
void StampBrush::mouseReleased(QGraphicsSceneMouseEvent *event)
{
switch (mBrushState) {
case BrushState::PaintStartSet:
case BrushState::StartSet:
if (event->button() == Qt::LeftButton) {
if (mStampReference != tilePosition()) {
doPaint();
mBrushState = BrushState::Free;
} else {
mBrushState = BrushState::StartSet;
}
}
break;
Expand All @@ -178,8 +189,7 @@ void StampBrush::mouseReleased(QGraphicsSceneMouseEvent *event)
updatePreview();
}
break;
default:
// do nothing?
case BrushState::Free:
break;
}
}
Expand All @@ -196,14 +206,23 @@ void StampBrush::updateBrushBehavior()
BrushState brushState = mBrushState;

if (mModifiers & Qt::ShiftModifier) {
if (mModifiers & Qt::ControlModifier)
if (mModifiers & Qt::ControlModifier) {
brushBehavior = BrushBehavior::Circle;
else
} else {
brushBehavior = BrushBehavior::Line;
}
if (brushState == BrushState::Paint) {
mStampReference = tilePosition();
brushState = BrushState::PaintStartSet;
}
} else {
brushBehavior = BrushBehavior::Neutral;
if (brushState == BrushState::StartSet)
brushState = BrushState::Free;
else if (brushState == BrushState::PaintStartSet) {
doPaint();
brushState = BrushState::Paint;
}
}

if (brushBehavior != mBrushBehavior || brushState != mBrushState) {
Expand Down Expand Up @@ -602,6 +621,7 @@ void StampBrush::updatePreview(QPoint tilePos)
} else {
switch (mBrushState) {
case BrushState::StartSet:
case BrushState::PaintStartSet:
if (mBrushBehavior == BrushBehavior::Circle) {
drawPreviewLayer(pointsOnEllipse(mStampReference,
qAbs(mStampReference.x() - tilePos.x()),
Expand Down
3 changes: 2 additions & 1 deletion src/tiled/stampbrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ public slots:
// preview of the selection
Capture, // right mouse pressed: capture a rectangle
Paint, // left mouse pressed: free painting
StartSet // when you have defined a starting point,
StartSet, // when you have defined a starting point,
// cancel with right click
PaintStartSet // starting point set while painting
};

/**
Expand Down

0 comments on commit dc2e89d

Please sign in to comment.