[nostalgia/core/studio] Fix tile insert to work on last tile
All checks were successful
Build / build (push) Successful in 3m9s

This commit is contained in:
Gary Talent 2025-01-11 15:23:57 -06:00
parent d259770f32
commit eb4cd7106d
2 changed files with 14 additions and 8 deletions

View File

@ -6,7 +6,7 @@
namespace nostalgia::core {
core::InsertTilesCommand::InsertTilesCommand(
InsertTilesCommand::InsertTilesCommand(
TileSheet &img,
TileSheet::SubSheetIdx idx,
std::size_t tileIdx,
@ -31,9 +31,11 @@ ox::Error InsertTilesCommand::redo() noexcept {
auto &s = getSubSheet(m_img, m_idx);
auto &p = s.pixels;
auto dstPos = m_insertPos + m_insertCnt;
auto const dst = &p[dstPos];
auto const src = &p[m_insertPos];
if (dstPos < p.size()) {
auto const dst = &p[dstPos];
ox::memmove(dst, src, p.size() - dstPos);
}
ox::memset(src, 0, m_insertCnt * sizeof(decltype(p[0])));
return {};
}
@ -41,12 +43,14 @@ ox::Error InsertTilesCommand::redo() noexcept {
ox::Error InsertTilesCommand::undo() noexcept {
auto &s = getSubSheet(m_img, m_idx);
auto &p = s.pixels;
auto const srcIdx = m_insertPos + m_insertCnt;
auto const src = &p[srcIdx];
auto const dst1 = &p[m_insertPos];
auto const dst2 = &p[p.size() - m_insertCnt];
auto const srcIdx = m_insertPos + m_insertCnt;
if (srcIdx < p.size()) {
auto const sz = p.size() - srcIdx;
auto const src = &p[srcIdx];
ox::memmove(dst1, src, sz);
}
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
return {};
}

View File

@ -56,8 +56,10 @@ void TileSheetEditorView::scrollH(ox::Vec2 const&paneSz, float wheelh) noexcept
}
void TileSheetEditorView::insertTile(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept {
auto const pt = clickPoint(paneSize, clickPos);
auto pt = clickPoint(paneSize, clickPos);
auto const&s = m_model.activeSubSheet();
pt.x = ox::min(pt.x, s.columns * TileWidth);
pt.y = ox::min(pt.y, s.rows * TileHeight);
auto const tileIdx = ptToIdx(pt, s.columns) / PixelsPerTile;
m_model.insertTiles(m_model.activeSubSheetIdx(), tileIdx, 1);
}