This commit is contained in:
@@ -5,14 +5,15 @@
|
||||
#include "cutpastecommand.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
TileSheetClipboard::Pixel::Pixel(
|
||||
uint16_t const pColorIdx,
|
||||
uint8_t const pColorIdx,
|
||||
ox::Point const pPt) noexcept:
|
||||
colorIdx(pColorIdx),
|
||||
pt(pPt) {}
|
||||
|
||||
|
||||
void TileSheetClipboard::addPixel(ox::Point const &pt, uint16_t colorIdx) noexcept {
|
||||
void TileSheetClipboard::addPixel(ox::Point const &pt, uint8_t colorIdx) noexcept {
|
||||
m_pixels.emplace_back(colorIdx, pt);
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ const ox::Vector<TileSheetClipboard::Pixel> &TileSheetClipboard::pixels() const
|
||||
|
||||
|
||||
CutPasteCommand::CutPasteCommand(
|
||||
CommandId commandId,
|
||||
CommandId const commandId,
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::Point const &dstStart,
|
||||
@@ -41,24 +42,18 @@ CutPasteCommand::CutPasteCommand(
|
||||
auto const dstPt = p.pt + dstStart;
|
||||
if (dstPt.x <= dstEnd.x && dstPt.y <= dstEnd.y) {
|
||||
auto const idx = gfx::idx(ss, dstPt);
|
||||
m_changes.emplace_back(static_cast<uint32_t>(idx), p.colorIdx, getPixel(ss, idx));
|
||||
m_changes.emplace_back(static_cast<uint32_t>(idx), p.colorIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error CutPasteCommand::redo() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (auto const &c : m_changes) {
|
||||
subsheet.pixels[c.idx] = static_cast<uint8_t>(c.newPalIdx);
|
||||
}
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error CutPasteCommand::undo() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (auto const &c : m_changes) {
|
||||
subsheet.pixels[c.idx] = static_cast<uint8_t>(c.oldPalIdx);
|
||||
}
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -70,4 +65,11 @@ TileSheet::SubSheetIdx const &CutPasteCommand::subsheetIdx() const noexcept {
|
||||
return m_subSheetIdx;
|
||||
}
|
||||
|
||||
void CutPasteCommand::swap() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (auto &c : m_changes) {
|
||||
std::swap(subsheet.pixels[c.idx], c.palIdx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> {
|
||||
struct Pixel {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.studio.TileSheetClipboard.Pixel";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
uint16_t colorIdx = 0;
|
||||
uint8_t colorIdx = 0;
|
||||
ox::Point pt;
|
||||
Pixel(uint16_t pColorIdx, ox::Point pPt) noexcept;
|
||||
Pixel(uint8_t pColorIdx, ox::Point pPt) noexcept;
|
||||
};
|
||||
protected:
|
||||
ox::Vector<Pixel> m_pixels;
|
||||
|
||||
public:
|
||||
void addPixel(ox::Point const &pt, uint16_t colorIdx) noexcept;
|
||||
void addPixel(ox::Point const &pt, uint8_t colorIdx) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<Pixel> const &pixels() const noexcept;
|
||||
@@ -49,12 +49,10 @@ class CutPasteCommand: public TileSheetCommand {
|
||||
private:
|
||||
struct Change {
|
||||
uint32_t idx = 0;
|
||||
uint16_t newPalIdx = 0;
|
||||
uint16_t oldPalIdx = 0;
|
||||
constexpr Change(uint32_t pIdx, uint16_t pNewPalIdx, uint16_t pOldPalIdx) noexcept {
|
||||
uint8_t palIdx = 0;
|
||||
constexpr Change(uint32_t const pIdx, uint8_t const pPalIdx) noexcept {
|
||||
idx = pIdx;
|
||||
newPalIdx = pNewPalIdx;
|
||||
oldPalIdx = pOldPalIdx;
|
||||
palIdx = pPalIdx;
|
||||
}
|
||||
};
|
||||
CommandId m_commandId;
|
||||
@@ -81,6 +79,9 @@ class CutPasteCommand: public TileSheetCommand {
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
private:
|
||||
void swap() noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user