Skip to content

Commit

Permalink
Added diagonal mirroring mode to terrain brush
Browse files Browse the repository at this point in the history
When holding the Alt modifier while using the terrain brush, the
modifications will be mirrored diagonally (top-left / bottom-right).

In general, there could also be horizontal or vertical mirroring as well
as a combination of those, but that will require adding a tool-specific
configuration panel somewhere (will have to be done eventually).

Thanks to 'Peter' for pushing for this feature.
  • Loading branch information
bjorn committed Jan 17, 2017
1 parent 036a3ca commit f32e836
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/tiled/terrainbrush.cpp
Expand Up @@ -51,6 +51,7 @@ TerrainBrush::TerrainBrush(QObject *parent)
, mPaintX(0), mPaintY(0)
, mIsActive(false)
, mBrushBehavior(Free)
, mMirrorDiagonally(false)
, mLineReferenceX(0)
, mLineReferenceY(0)
{
Expand Down Expand Up @@ -150,6 +151,8 @@ void TerrainBrush::modifiersChanged(Qt::KeyboardModifiers modifiers)
mBrushBehavior = lineMode ? Line : Free;
}

mMirrorDiagonally = modifiers & Qt::AltModifier;

setBrushMode((modifiers & Qt::ControlModifier) ? PaintVertex : PaintTile);
updateBrush(tilePosition());
}
Expand Down Expand Up @@ -349,20 +352,23 @@ void TerrainBrush::updateBrush(QPoint cursorPos, const QVector<QPoint> *list)
memset(checked, 0, numTiles);

// create a consideration list, and push the start points
QList<QPoint> transitionList;
int initialTiles = 0;

if (list) {
// if we were supplied a list of start points
foreach (const QPoint &p, *list) {
transitionList.append(p);
++initialTiles;
}
} else {
QVector<QPoint> transitionList;

if (list) // if we were supplied a list of start points
transitionList = *list;
else
transitionList.append(cursorPos);
initialTiles = 1;

if (mMirrorDiagonally) {
for (int i = 0, e = transitionList.size(); i < e; ++i) {
const auto &p = transitionList.at(i);
transitionList.append(QPoint(currentLayer->height() - p.y() - 1,
currentLayer->width() - p.x() - 1));
}
}

int initialTiles = transitionList.size();

QRect brushRect(cursorPos, cursorPos);

// produce terrain with transitions using a simple, relative naive approach (considers each tile once, and doesn't allow re-consideration if selection was bad)
Expand Down
1 change: 1 addition & 0 deletions src/tiled/terrainbrush.h
Expand Up @@ -133,6 +133,7 @@ class TerrainBrush : public AbstractTileTool
*/
BrushBehavior mBrushBehavior;
BrushMode mBrushMode;
bool mMirrorDiagonally;

/**
* The starting position needed for drawing lines and circles.
Expand Down

0 comments on commit f32e836

Please sign in to comment.