|
|
|
@ -2,14 +2,15 @@
|
|
|
|
|
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <ox/claw/read.hpp>
|
|
|
|
|
|
|
|
|
|
#include <nostalgia/core/clipboard.hpp>
|
|
|
|
|
#include <nostalgia/core/media.hpp>
|
|
|
|
|
#include <ox/claw/read.hpp>
|
|
|
|
|
#include <ox/std/algorithm.hpp>
|
|
|
|
|
#include <ox/std/buffer.hpp>
|
|
|
|
|
#include <ox/std/memory.hpp>
|
|
|
|
|
|
|
|
|
|
#include <nostalgia/core/clipboard.hpp>
|
|
|
|
|
#include <nostalgia/core/media.hpp>
|
|
|
|
|
|
|
|
|
|
#include "tilesheeteditormodel.hpp"
|
|
|
|
|
|
|
|
|
|
namespace nostalgia::core {
|
|
|
|
@ -102,7 +103,7 @@ class DrawCommand: public TileSheetCommand {
|
|
|
|
|
m_img = img;
|
|
|
|
|
auto &subsheet = m_img->getSubSheet(subSheetIdx);
|
|
|
|
|
m_subSheetIdx = subSheetIdx;
|
|
|
|
|
m_changes.emplace_back(idx, subsheet.getPixel(m_img->bpp, idx));
|
|
|
|
|
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img->bpp, idx));
|
|
|
|
|
m_palIdx = palIdx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -111,7 +112,7 @@ class DrawCommand: public TileSheetCommand {
|
|
|
|
|
auto &subsheet = m_img->getSubSheet(subSheetIdx);
|
|
|
|
|
m_subSheetIdx = subSheetIdx;
|
|
|
|
|
for (const auto idx : idxList) {
|
|
|
|
|
m_changes.emplace_back(idx, subsheet.getPixel(m_img->bpp, idx));
|
|
|
|
|
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img->bpp, idx));
|
|
|
|
|
}
|
|
|
|
|
m_palIdx = palIdx;
|
|
|
|
|
}
|
|
|
|
@ -124,7 +125,7 @@ class DrawCommand: public TileSheetCommand {
|
|
|
|
|
return c.idx == idx;
|
|
|
|
|
});
|
|
|
|
|
if (existing == m_changes.cend()) {
|
|
|
|
|
m_changes.emplace_back(idx, subsheet.getPixel(m_img->bpp, idx));
|
|
|
|
|
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img->bpp, idx));
|
|
|
|
|
subsheet.setPixel(m_img->bpp, idx, m_palIdx);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -192,7 +193,7 @@ class CutPasteCommand: public TileSheetCommand {
|
|
|
|
|
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));
|
|
|
|
|
m_changes.emplace_back(static_cast<uint32_t>(idx), p.colorIdx, subsheet.getPixel(m_img->bpp, idx));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -240,7 +241,7 @@ class AddSubSheetCommand: public TileSheetCommand {
|
|
|
|
|
m_addedSheets.push_back(idx);
|
|
|
|
|
} else {
|
|
|
|
|
auto idx = m_parentIdx;
|
|
|
|
|
idx.emplace_back(0);
|
|
|
|
|
idx.emplace_back(0u);
|
|
|
|
|
m_addedSheets.push_back(idx);
|
|
|
|
|
idx.back().value = 1;
|
|
|
|
|
m_addedSheets.push_back(idx);
|
|
|
|
@ -562,7 +563,7 @@ void TileSheetEditorModel::cut() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TileSheetEditorModel::copy() {
|
|
|
|
|
auto cb = ox::make_unique<TileSheetClipboard>();;
|
|
|
|
|
auto cb = ox::make_unique<TileSheetClipboard>();
|
|
|
|
|
for (int y = m_selectionBounds.y; y <= m_selectionBounds.y2(); ++y) {
|
|
|
|
|
for (int x = m_selectionBounds.x; x <= m_selectionBounds.x2(); ++x) {
|
|
|
|
|
auto pt = geo::Point(x, y);
|
|
|
|
@ -608,7 +609,7 @@ void TileSheetEditorModel::drawCommand(const geo::Point &pt, std::size_t palIdx)
|
|
|
|
|
if (m_ongoingDrawCommand) {
|
|
|
|
|
m_updated = m_updated || m_ongoingDrawCommand->append(idx);
|
|
|
|
|
} else if (activeSubSheet.getPixel(m_img.bpp, idx) != palIdx) {
|
|
|
|
|
pushCommand(new DrawCommand(&m_img, m_activeSubsSheetIdx, idx, palIdx));
|
|
|
|
|
pushCommand(new DrawCommand(&m_img, m_activeSubsSheetIdx, idx, static_cast<int>(palIdx)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -729,7 +730,7 @@ ox::Error TileSheetEditorModel::saveFile() noexcept {
|
|
|
|
|
|
|
|
|
|
bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {
|
|
|
|
|
const auto s = activeSubSheet();
|
|
|
|
|
const auto pt = idxToPt(idx, s->columns);
|
|
|
|
|
const auto pt = idxToPt(static_cast<int>(idx), s->columns);
|
|
|
|
|
return m_selectionBounds.contains(pt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|