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