Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Terrain Brush fill full tiles mode toggle-able #3407

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Unreleased

* Added button to toggle Terrain Brush to full tile mode (by Finlay Pearson, #3407)

### Tiled 1.10.2 (4 August 2023)

* Added support for setting custom properties on the project (#2903)
Expand Down
26 changes: 26 additions & 0 deletions src/tiled/resources/images/scalable/fill-full-tiles.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion src/tiled/wangbrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "mapscene.h"
#include "painttilelayer.h"
#include "tilelayer.h"
#include "actionmanager.h"

#include <QStyleOptionGraphicsItem>
#include <QtMath>
Expand Down Expand Up @@ -88,6 +89,21 @@ WangBrush::WangBrush(QObject *parent)
new WangBrushItem,
parent)
{
// Set up toolbar action for toggling fill full tiles mode,
// which basically makes the brush bigger.

QIcon fillFullTilesIcon(QLatin1String(":images/scalable/fill-full-tiles.svg"));

mToggleFillFullTiles = new QAction(this);
mToggleFillFullTiles->setCheckable(true);
mToggleFillFullTiles->setIcon(fillFullTilesIcon);
mToggleFillFullTiles->setText(tr("Fill Full Tiles"));

ActionManager::registerAction(mToggleFillFullTiles, "ToggleFillFullTiles");
connect(mToggleFillFullTiles, &QAction::toggled, this, [this](bool checked) {
mIsTileMode = checked;
stateChanged();
});
}

WangBrush::~WangBrush()
Expand Down Expand Up @@ -151,7 +167,8 @@ void WangBrush::mouseReleased(QGraphicsSceneMouseEvent *event)

void WangBrush::modifiersChanged(Qt::KeyboardModifiers modifiers)
{
const bool isTileMode = modifiers & Qt::ControlModifier;
const bool isControlPressed = modifiers & Qt::ControlModifier;
const bool isTileMode = isControlPressed != mToggleFillFullTiles->isChecked();
const bool rotationalSymmetry = modifiers & Qt::AltModifier;
const bool lineMode = modifiers & Qt::ShiftModifier;

Expand Down Expand Up @@ -179,6 +196,7 @@ void WangBrush::modifiersChanged(Qt::KeyboardModifiers modifiers)
void WangBrush::languageChanged()
{
setName(tr("Terrain Brush"));
mToggleFillFullTiles->setText(tr("Fill Full Tiles"));
}

void WangBrush::setColor(int color)
Expand Down Expand Up @@ -670,6 +688,11 @@ void WangBrush::updateBrushAt(WangFiller &filler, QPoint pos)
}
}

void WangBrush::populateToolBar(QToolBar *toolbar)
{
toolbar->addAction(mToggleFillFullTiles);
}

} // namespace Tiled

#include "moc_wangbrush.cpp"
5 changes: 5 additions & 0 deletions src/tiled/wangbrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "wangfiller.h"
#include "wangset.h"

#include <QToolBar>

namespace Tiled {

class WangBrushItem : public BrushItem
Expand Down Expand Up @@ -74,6 +76,8 @@ class WangBrush : public AbstractTileTool

void setColor(int color);

void populateToolBar(QToolBar *toolbar) override;

signals:
void colorCaptured(int color);

Expand Down Expand Up @@ -120,6 +124,7 @@ public slots:
bool mRotationalSymmetry = false;
bool mLineStartSet = false;
BrushBehavior mBrushBehavior = Free;
QAction *mToggleFillFullTiles;
};

} // namespace Tiled
Loading