Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ default/

# clangd cache
.cache/
compile_commands.json

# Mac stuff
*.DS_Store
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Allow changing the values of number inputs using expressions (with dogboydog, #4234)
* Added support for SVG 1.2 / CSS blending modes to layers (#3932)
* Added button to toggle Terrain Brush to full tile mode (by Finlay Pearson, #3407)
* Added square selection and expand-from-center to Rectangular Select tool (#4201)
* Added status bar info for various Stamp Brush modes (#3092)
* Added export plugin for Remixed Dungeon (by Mikhael Danilov, #4158)
* Added "World > World Properties" menu action (with dogboydog, #4190)
* Scripting: Added API for custom property types (with dogboydog, #3971)
Expand Down
20 changes: 15 additions & 5 deletions docs/manual/editing-tile-layers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,27 @@ There are various tile selection tools that all work in similar fashion:
- |stock-tool-by-color-select| **Select Same Tile** allows selection of
same-tiles across the entire layer (shortcut: ``S``)

By default, each of these tools replaces the currently selected area.
The following modifiers can be used to change this behavior:
By default, each of these tools replaces the currently selected area. The
following modifiers can be used to change the selection mode before starting
the selection:

- Holding ``Shift`` expands the current selection with the new area
- Holding ``Ctrl`` subtracts the new area from the current selection
- Holding ``Ctrl`` and ``Shift`` selects the intersection of the new
- Hold ``Shift`` to expand the current selection with the new area
- Hold ``Ctrl`` to subtract the new area from the current selection
- Hold ``Ctrl`` and ``Shift`` to select the intersection of the new
area with the current selection

You can also lock into one of these modes (Add, Subtract or Intersect)
by clicking on one of the tool buttons in the Tool Options toolbar.

.. raw:: html

<div class="new">Since Tiled 1.12</div>

While selecting an area, the following modifiers can be used:

- Hold ``Shift`` to constrain the selection to a square.
- Hold ``Ctrl`` to expand the selection from the starting location.

Managing Tile Stamps
--------------------

Expand Down
55 changes: 49 additions & 6 deletions src/tiled/stampbrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ StampBrush::StampBrush(QObject *parent)
[this] { emit stampChanged(mStamp.rotated(RotateRight)); });
}

StampBrush::~StampBrush()
{
}
StampBrush::~StampBrush() = default;

void StampBrush::activate(MapScene *scene)
{
Expand Down Expand Up @@ -114,6 +112,45 @@ void StampBrush::tilePositionChanged(QPoint pos)
mPrevTilePosition = pos;
}

void StampBrush::updateStatusInfo()
{
if (!isBrushVisible()) {
AbstractTileTool::updateStatusInfo();
return;
}

const QPoint pos = tilePosition();
QString actionText;

if (mBrushState == BrushState::Capture) {
const QRect area = mCaptureStampHelper.capturedArea(pos);
actionText = tr("Capture area (%3 x %4)")
.arg(area.width())
.arg(area.height());
} else if (mBrushState == BrushState::StartSet) {
if (mBrushBehavior == BrushBehavior::Line) {
const int length = std::max(std::abs(pos.x() - mStampReference.x()),
std::abs(pos.y() - mStampReference.y())) + 1;
actionText = tr("Draw line (length: %3)").arg(length);
} else if (mBrushBehavior == BrushBehavior::Circle) {
const int rx = std::abs(pos.x() - mStampReference.x());
const int ry = std::abs(pos.y() - mStampReference.y());
const int w = rx * 2 + 1;
const int h = ry * 2 + 1;
actionText = tr("Draw ellipse (size: %3 x %4)").arg(w).arg(h);
}
}

if (!actionText.isEmpty()) {
setStatusInfo(tr("%1, %2 - %3")
.arg(pos.x()).arg(pos.y())
.arg(actionText));
return;
}

AbstractTileTool::updateStatusInfo();
}

void StampBrush::mousePressed(QGraphicsSceneMouseEvent *event)
{
if (brushItem()->isVisible()) {
Expand All @@ -135,16 +172,18 @@ void StampBrush::mousePressed(QGraphicsSceneMouseEvent *event)
case BrushBehavior::Circle:
mStampReference = tilePosition();
mBrushState = BrushState::StartSet;
updateStatusInfo();
break;
}
break;
case BrushState::Capture:
break;
}
return;
} else if (event->button() == Qt::RightButton &&
!(event->modifiers() & Qt::ControlModifier))
{
}

if (event->button() == Qt::RightButton &&
!(event->modifiers() & Qt::ControlModifier)) {
beginCapture();
return;
}
Expand All @@ -161,6 +200,7 @@ void StampBrush::mouseReleased(QGraphicsSceneMouseEvent *event)
if (mStampReference != tilePosition()) {
doPaint();
mBrushState = BrushState::Free;
updateStatusInfo();
}
}
break;
Expand Down Expand Up @@ -210,6 +250,7 @@ void StampBrush::updateBrushBehavior()
mBrushBehavior = brushBehavior;
mBrushState = brushState;
updatePreview();
updateStatusInfo();
}
}

Expand Down Expand Up @@ -333,6 +374,8 @@ void StampBrush::endCapture()
emit stampChanged(stamp);
else
updatePreview();

updateStatusInfo(); // restore default status info
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/stampbrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public slots:
protected:
void tilePositionChanged(QPoint tilePos) override;

void updateStatusInfo() override;

void mapDocumentChanged(MapDocument *oldDocument,
MapDocument *newDocument) override;

Expand Down
60 changes: 53 additions & 7 deletions src/tiled/tileselectiontool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@

#include "brushitem.h"
#include "changeselectedarea.h"
#include "map.h"
#include "mapdocument.h"
#include "mapscene.h"
#include "tilelayer.h"

#include <QApplication>

Expand All @@ -38,8 +36,6 @@ TileSelectionTool::TileSelectionTool(QObject *parent)
":images/22/stock-tool-rect-select.png")),
QKeySequence(Qt::Key_R),
parent)
, mMouseDown(false)
, mSelecting(false)
{
setTilePositionMethod(OnTiles);
}
Expand Down Expand Up @@ -86,6 +82,8 @@ void TileSelectionTool::mousePressed(QGraphicsSceneMouseEvent *event)

if (button == Qt::LeftButton) {
mMouseDown = true;
mForceSquare = false;
mExpandFromCenter = false;
mMouseScreenStart = event->screenPos();
mSelectionStart = tilePosition();
brushItem()->setTileRegion(QRegion());
Expand All @@ -99,7 +97,9 @@ void TileSelectionTool::mousePressed(QGraphicsSceneMouseEvent *event)
mMouseDown = false; // Avoid restarting select on move
brushItem()->setTileRegion(QRegion());
return;
} else if (event->modifiers() == Qt::NoModifier) {
}

if (event->modifiers() == Qt::NoModifier) {
clearSelection();
return;
}
Expand Down Expand Up @@ -142,6 +142,38 @@ void TileSelectionTool::mouseReleased(QGraphicsSceneMouseEvent *event)
mMouseDown = false;
}

void TileSelectionTool::modifiersChanged(Qt::KeyboardModifiers modifiers)
{
if (mMouseDown) {
// When the mouse is down, we no longer change the selection mode. Instead:
//
// * The Shift modifier can be used to force a 1:1 aspect ratio
// * The Control modifier can be used to expand from the center
//
// Only a change in modifier state has an effect because we don't want
// modifiers that were already held when starting the selection to
// affect these options, since at that point they were used to set the
// selection mode.

const bool shift = modifiers & Qt::ShiftModifier;
const bool ctrl = modifiers & Qt::ControlModifier;

if (shift != (mLastModifiers & Qt::ShiftModifier))
mForceSquare = shift;

if (ctrl != (mLastModifiers & Qt::ControlModifier))
mExpandFromCenter = ctrl;

tilePositionChanged(tilePosition());
updateStatusInfo();

} else {
AbstractTileSelectionTool::modifiersChanged(modifiers);
}

mLastModifiers = modifiers;
}

void TileSelectionTool::languageChanged()
{
setName(tr("Rectangular Select"));
Expand All @@ -151,15 +183,29 @@ void TileSelectionTool::languageChanged()

QRect TileSelectionTool::selectedArea() const
{
QPoint startPos = mSelectionStart;
QPoint endPos = tilePosition();
QPoint delta = endPos - startPos;

if (mForceSquare) {
const int size = qMax(qAbs(delta.x()), qAbs(delta.y()));
delta.setX((delta.x() < 0) ? -size : size);
delta.setY((delta.y() < 0) ? -size : size);
endPos = startPos + delta;
}

if (mExpandFromCenter)
startPos -= delta;

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRect area = QRect(mSelectionStart, tilePosition()).normalized();
QRect area = QRect(startPos, endPos).normalized();
if (area.width() == 0)
area.adjust(-1, 0, 1, 0);
if (area.height() == 0)
area.adjust(0, -1, 0, 1);
return area;
#else
return QRect::span(mSelectionStart, tilePosition());
return QRect::span(startPos, endPos);
#endif
}

Expand Down
9 changes: 7 additions & 2 deletions src/tiled/tileselectiontool.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class TileSelectionTool : public AbstractTileSelectionTool
void mousePressed(QGraphicsSceneMouseEvent *event) override;
void mouseReleased(QGraphicsSceneMouseEvent *event) override;

void modifiersChanged(Qt::KeyboardModifiers modifiers) override;

void languageChanged() override;

protected:
Expand All @@ -49,8 +51,11 @@ class TileSelectionTool : public AbstractTileSelectionTool

QPoint mMouseScreenStart;
QPoint mSelectionStart;
bool mMouseDown;
bool mSelecting;
bool mMouseDown = false;
bool mSelecting = false;
bool mForceSquare = false;
bool mExpandFromCenter = false;
Qt::KeyboardModifiers mLastModifiers = Qt::NoModifier;
};

} // namespace Tiled
Loading