[nostalgia/core/studio] Fix paste command to never paste beyond target dimensions
All checks were successful
Build / build (push) Successful in 2m40s
All checks were successful
Build / build (push) Successful in 2m40s
This commit is contained in:
parent
8a9ff971a1
commit
72f4db3d5e
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user