[nostalgia/core/studio] Fix TileSheet Editor paste bounds checking
This commit is contained in:
parent
415c2574bb
commit
ae80d22769
@ -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 {
|
||||
|
@ -142,33 +142,32 @@ 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final {
|
||||
|
Loading…
Reference in New Issue
Block a user