/** * Returns a new stamp where all variations have been rotated in the given * \a direction. */ TileStamp TileStamp::rotated(RotateDirection direction) const { TileStamp rotated(*this); rotated.d.detach(); for (const TileStampVariation &variation : rotated.variations()) { const QRect mapRect(QPoint(), variation.map->size()); QSize rotatedSize; for (auto layer : variation.map->tileLayers()) { TileLayer *tileLayer = static_cast<TileLayer*>(layer); // Synchronize tile layer size to map size (assumes map contains all layers) if (tileLayer->rect() != mapRect) { tileLayer->resize(mapRect.size(), tileLayer->position()); tileLayer->setPosition(0, 0); } if (variation.map->orientation() == Map::Hexagonal) tileLayer->rotateHexagonal(direction, variation.map); else tileLayer->rotate(direction); rotatedSize = tileLayer->size(); } variation.map->setWidth(rotatedSize.width()); variation.map->setHeight(rotatedSize.height()); } return rotated; }
Layer *TileLayer::mergedWith(Layer *other) const { Q_ASSERT(canMergeWith(other)); const TileLayer *o = static_cast<TileLayer*>(other); const QRect unitedBounds = bounds().united(o->bounds()); const QPoint offset = position() - unitedBounds.topLeft(); TileLayer *merged = static_cast<TileLayer*>(clone()); merged->resize(unitedBounds.size(), offset); merged->merge(o->position() - unitedBounds.topLeft(), o); return merged; }
/** * Returns a new stamp where all variations have been flipped in the given * \a direction. */ TileStamp TileStamp::flipped(FlipDirection direction) const { TileStamp flipped(*this); flipped.d.detach(); for (const TileStampVariation &variation : flipped.variations()) { const QRect mapRect(QPoint(), variation.map->size()); for (auto layer : variation.map->tileLayers()) { TileLayer *tileLayer = static_cast<TileLayer*>(layer); // Synchronize tile layer size to map size (assumes map contains all layers) if (tileLayer->rect() != mapRect) { tileLayer->resize(mapRect.size(), tileLayer->position()); tileLayer->setPosition(0, 0); } if (variation.map->orientation() == Map::Hexagonal) tileLayer->flipHexagonal(direction); else tileLayer->flip(direction); } if (variation.map->isStaggered()) { Map::StaggerAxis staggerAxis = variation.map->staggerAxis(); if (staggerAxis == Map::StaggerY) { if ((direction == FlipVertically && !(variation.map->height() & 1)) || direction == FlipHorizontally) variation.map->invertStaggerIndex(); } else { if ((direction == FlipHorizontally && !(variation.map->width() & 1)) || direction == FlipVertically) variation.map->invertStaggerIndex(); } } } return flipped; }