[nostalgia/core/studio] Cleanup TileSheet selection, fix copy/paste bug
This commit is contained in:
@ -18,6 +18,11 @@ struct Selection {
|
||||
constexpr ox::Size size() const noexcept {
|
||||
return {b.x - a.x, b.y - a.y};
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr bool contains(ox::Point const&pt) const noexcept {
|
||||
return a.x <= pt.x && a.y <= pt.y
|
||||
&& b.x >= pt.x && b.y >= pt.y;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr auto iterateSelection(studio::Selection const&sel, auto const&cb) {
|
||||
@ -36,6 +41,22 @@ constexpr auto iterateSelection(studio::Selection const&sel, auto const&cb) {
|
||||
}
|
||||
};
|
||||
|
||||
constexpr auto iterateSelectionRows(studio::Selection const&sel, auto const&cb) {
|
||||
constexpr auto retErr = ox::is_same_v<decltype(cb(0, 0)), ox::Error>;
|
||||
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
|
||||
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
|
||||
if constexpr(retErr) {
|
||||
oxReturnError(cb(x, y));
|
||||
} else {
|
||||
cb(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
if constexpr(retErr) {
|
||||
return ox::Error{};
|
||||
}
|
||||
};
|
||||
|
||||
class SelectionTracker {
|
||||
private:
|
||||
bool m_selectionOngoing{};
|
||||
@ -53,14 +74,23 @@ class SelectionTracker {
|
||||
m_selectionOngoing = true;
|
||||
}
|
||||
|
||||
constexpr void updateCursorPoint(ox::Point cursor, bool allowStart = true) noexcept {
|
||||
/**
|
||||
*
|
||||
* @param cursor
|
||||
* @param allowStart
|
||||
* @return true if changed, false otherwise
|
||||
*/
|
||||
constexpr bool updateCursorPoint(ox::Point cursor, bool allowStart = true) noexcept {
|
||||
auto changed = false;
|
||||
if (!m_selectionOngoing && allowStart) {
|
||||
m_pointA = cursor;
|
||||
m_selectionOngoing = true;
|
||||
}
|
||||
if (m_selectionOngoing) {
|
||||
m_pointB = cursor;
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
constexpr void updateCursorPoint(ox::Vec2 cursor, bool allowStart = true) noexcept {
|
||||
|
Reference in New Issue
Block a user