[nostalgia/core/studio] Fix TileSheet Editor paste bounds checking

This commit is contained in:
Gary Talent 2022-03-11 02:11:58 -06:00
parent 415c2574bb
commit ae80d22769
2 changed files with 12 additions and 11 deletions

View File

@ -71,8 +71,10 @@ void TileSheetEditorModel::paste() {
oxErrf("Could not read clipboard: {}", toStr(err));
return;
}
const auto pt = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin;
pushCommand(new PasteCommand(&m_img, m_activeSubsSheetIdx, pt, cb));
const auto s = activeSubSheet();
const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin;
const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight);
pushCommand(new PasteCommand(&m_img, m_activeSubsSheetIdx, pt1, pt2, cb));
}
void TileSheetEditorModel::drawCommand(const geo::Point &pt, std::size_t palIdx) noexcept {

View File

@ -142,31 +142,30 @@ struct PasteCommand: public studio::UndoCommand {
ox::Vector<Change> m_changes;
public:
constexpr PasteCommand(TileSheet *img, const TileSheet::SubSheetIdx &subSheetIdx, const geo::Point &dst, const TileSheetClipboard &cb) noexcept {
constexpr PasteCommand(TileSheet *img, const TileSheet::SubSheetIdx &subSheetIdx, const geo::Point &dstStart, const geo::Point &dstEnd, const TileSheetClipboard &cb) noexcept {
m_img = img;
m_subSheetIdx = subSheetIdx;
const auto &subsheet = m_img->getSubSheet(subSheetIdx);
for (const auto &p : cb.pixels()) {
const auto idx = subsheet.idx(p.pt + dst);
m_changes.emplace_back(idx, p.colorIdx, subsheet.getPixel(m_img->bpp, idx));
const auto dstPt = p.pt + dstStart;
if (dstPt.x <= dstEnd.x && dstPt.y <= dstEnd.y) {
const auto idx = subsheet.idx(dstPt);
m_changes.emplace_back(idx, p.colorIdx, subsheet.getPixel(m_img->bpp, idx));
}
}
}
void redo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) {
if (c.idx < subsheet.pixelCnt(m_img->bpp)) {
subsheet.setPixel(m_img->bpp, c.idx, c.newPalIdx);
}
subsheet.setPixel(m_img->bpp, c.idx, c.newPalIdx);
}
}
void undo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) {
if (c.idx < subsheet.pixelCnt(m_img->bpp)) {
subsheet.setPixel(m_img->bpp, c.idx, c.oldPalIdx);
}
subsheet.setPixel(m_img->bpp, c.idx, c.oldPalIdx);
}
}