[nostalgia/core/studio] Fix tile insert to work on last tile
All checks were successful
Build / build (push) Successful in 3m9s
All checks were successful
Build / build (push) Successful in 3m9s
This commit is contained in:
parent
d259770f32
commit
eb4cd7106d
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
core::InsertTilesCommand::InsertTilesCommand(
|
InsertTilesCommand::InsertTilesCommand(
|
||||||
TileSheet &img,
|
TileSheet &img,
|
||||||
TileSheet::SubSheetIdx idx,
|
TileSheet::SubSheetIdx idx,
|
||||||
std::size_t tileIdx,
|
std::size_t tileIdx,
|
||||||
@ -31,9 +31,11 @@ ox::Error InsertTilesCommand::redo() noexcept {
|
|||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
auto dstPos = m_insertPos + m_insertCnt;
|
auto dstPos = m_insertPos + m_insertCnt;
|
||||||
auto const dst = &p[dstPos];
|
|
||||||
auto const src = &p[m_insertPos];
|
auto const src = &p[m_insertPos];
|
||||||
ox::memmove(dst, src, p.size() - dstPos);
|
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])));
|
ox::memset(src, 0, m_insertCnt * sizeof(decltype(p[0])));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -41,12 +43,14 @@ ox::Error InsertTilesCommand::redo() noexcept {
|
|||||||
ox::Error InsertTilesCommand::undo() noexcept {
|
ox::Error InsertTilesCommand::undo() noexcept {
|
||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
auto const srcIdx = m_insertPos + m_insertCnt;
|
|
||||||
auto const src = &p[srcIdx];
|
|
||||||
auto const dst1 = &p[m_insertPos];
|
auto const dst1 = &p[m_insertPos];
|
||||||
auto const dst2 = &p[p.size() - m_insertCnt];
|
auto const dst2 = &p[p.size() - m_insertCnt];
|
||||||
auto const sz = p.size() - srcIdx;
|
auto const srcIdx = m_insertPos + m_insertCnt;
|
||||||
ox::memmove(dst1, src, sz);
|
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());
|
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
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();
|
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;
|
auto const tileIdx = ptToIdx(pt, s.columns) / PixelsPerTile;
|
||||||
m_model.insertTiles(m_model.activeSubSheetIdx(), tileIdx, 1);
|
m_model.insertTiles(m_model.activeSubSheetIdx(), tileIdx, 1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user