[nostalgia/core/studio] Add ability to select pixels for copy/paste

This commit is contained in:
2022-03-10 02:39:22 -06:00
parent 3486734b50
commit b502b8cc30
9 changed files with 147 additions and 33 deletions
@@ -65,18 +65,48 @@ void TileSheetEditorModel::setActiveSubsheet(const TileSheet::SubSheetIdx &idx)
this->activeSubsheetChanged.emit(m_activeSubsSheetIdx);
}
void TileSheetEditorModel::select(const geo::Point &pt) noexcept {
if (!m_selectionOngoing) {
m_selectionPt1 = pt;
m_selectionOngoing = true;
}
if (m_selectionPt2 != pt) {
m_selectionPt2 = pt;
m_selectionBounds = {m_selectionPt1, m_selectionPt2};
m_updated = true;
}
}
void TileSheetEditorModel::completeSelection() noexcept {
m_selectionOngoing = false;
}
void TileSheetEditorModel::clearSelection() noexcept {
m_updated = true;
m_selectionPt1 = {-1, -1};
m_selectionPt2 = {-1, -1};
m_selectionBounds = {m_selectionPt1, m_selectionPt2};
}
bool TileSheetEditorModel::updated() const noexcept {
return m_updated;
}
ox::Error TileSheetEditorModel::markUpdated(int cmdId) noexcept {
m_updated = true;
if (cmdId == CommandId::AddSubSheet || cmdId == CommandId::RmSubSheet) {
// make sure the current active SubSheet is still valid
auto idx = m_img.validateSubSheetIdx(m_activeSubsSheetIdx);
if (idx != m_activeSubsSheetIdx) {
setActiveSubsheet(idx);
switch (static_cast<CommandId>(cmdId)) {
case CommandId::AddSubSheet:
case CommandId::RmSubSheet: {
// make sure the current active SubSheet is still valid
auto idx = m_img.validateSubSheetIdx(m_activeSubsSheetIdx);
if (idx != m_activeSubsSheetIdx) {
setActiveSubsheet(idx);
}
break;
}
case CommandId::Draw:
case CommandId::UpdateSubSheet:
break;
}
return OxError(0);
}
@@ -91,6 +121,12 @@ ox::Error TileSheetEditorModel::saveFile() noexcept {
return m_ctx->assetManager.setAsset(m_path, m_img).error;
}
bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {
auto s = activeSubSheet();
auto pt = idxToPt(idx, s->columns);
return m_selectionBounds.contains(pt);
}
void TileSheetEditorModel::getFillPixels(bool *pixels, const geo::Point &pt, int oldColor) const noexcept {
auto &activeSubSheet = *this->activeSubSheet();
const auto tileIdx = [activeSubSheet](const geo::Point &pt) noexcept {