[nostalgia/core/studio] Fix paste command to never paste beyond target dimensions
All checks were successful
Build / build (push) Successful in 2m40s

This commit is contained in:
Gary Talent 2024-11-15 01:39:57 -06:00
parent 8a9ff971a1
commit 72f4db3d5e
2 changed files with 13 additions and 11 deletions

View File

@ -12,7 +12,7 @@ TileSheetClipboard::Pixel::Pixel(uint16_t pColorIdx, ox::Point pPt) noexcept {
} }
void TileSheetClipboard::addPixel(const ox::Point &pt, uint16_t colorIdx) noexcept { void TileSheetClipboard::addPixel(ox::Point const&pt, uint16_t colorIdx) noexcept {
m_pixels.emplace_back(colorIdx, pt); m_pixels.emplace_back(colorIdx, pt);
} }
@ -25,18 +25,20 @@ CutPasteCommand::CutPasteCommand(
CommandId commandId, CommandId commandId,
TileSheet &img, TileSheet &img,
TileSheet::SubSheetIdx subSheetIdx, TileSheet::SubSheetIdx subSheetIdx,
const ox::Point &dstStart, ox::Point const&dstStart,
const ox::Point &dstEnd, ox::Point dstEnd,
const TileSheetClipboard &cb) noexcept: TileSheetClipboard const&cb) noexcept:
m_commandId(commandId), m_commandId(commandId),
m_img(img), m_img(img),
m_subSheetIdx(std::move(subSheetIdx)) { m_subSheetIdx(std::move(subSheetIdx)) {
const auto &subsheet = getSubSheet(m_img, m_subSheetIdx); auto const&ss = getSubSheet(m_img, m_subSheetIdx);
for (const auto &p : cb.pixels()) { dstEnd.x = std::min(ss.columns * TileWidth - 1, dstEnd.x);
const auto dstPt = p.pt + dstStart; dstEnd.y = std::min(ss.rows * TileHeight - 1, dstEnd.y);
for (auto const&p : cb.pixels()) {
auto const dstPt = p.pt + dstStart;
if (dstPt.x <= dstEnd.x && dstPt.y <= dstEnd.y) { if (dstPt.x <= dstEnd.x && dstPt.y <= dstEnd.y) {
const auto idx = core::idx(subsheet, dstPt); auto const idx = core::idx(ss, dstPt);
m_changes.emplace_back(static_cast<uint32_t>(idx), p.colorIdx, getPixel(subsheet, m_img.bpp, idx)); m_changes.emplace_back(static_cast<uint32_t>(idx), p.colorIdx, getPixel(ss, m_img.bpp, idx));
} }
} }
} }

View File

@ -68,7 +68,7 @@ class CutPasteCommand: public TileSheetCommand {
TileSheet &img, TileSheet &img,
TileSheet::SubSheetIdx subSheetIdx, TileSheet::SubSheetIdx subSheetIdx,
ox::Point const&dstStart, ox::Point const&dstStart,
ox::Point const&dstEnd, ox::Point dstEnd,
TileSheetClipboard const&cb) noexcept; TileSheetClipboard const&cb) noexcept;
ox::Error redo() noexcept final; ox::Error redo() noexcept final;