diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp index 43174a17..bf6a557e 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp @@ -87,7 +87,8 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept { if (wheelh != 0) { m_tileSheetEditor.scrollH(fbSize, wheelh); } - if (io.MouseDown[0]) { + if (io.MouseDown[0] && m_prevMouseDownPos != mousePos) { + m_prevMouseDownPos = mousePos; auto clickPos = mousePos; const auto &winPos = ImGui::GetWindowPos(); clickPos.x -= winPos.x + 10; @@ -96,6 +97,7 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept { } } if (io.MouseReleased[0]) { + m_prevMouseDownPos = {-1, -1}; m_tileSheetEditor.releaseMouseButton(); } } diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp index c2120e14..cf18f835 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp @@ -26,6 +26,7 @@ class TileSheetEditorImGui: public studio::Editor { glutils::FrameBuffer m_framebuffer; TileSheetEditor m_tileSheetEditor; float m_palViewWidth = 200; + geo::Vec2 m_prevMouseDownPos; public: TileSheetEditorImGui(Context *ctx, const ox::String &path); diff --git a/src/nostalgia/core/studio/tilesheeteditor.hpp b/src/nostalgia/core/studio/tilesheeteditor.hpp index 088ce515..2126e6f0 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor.hpp @@ -17,6 +17,25 @@ namespace nostalgia::core { +enum class TileSheetTool: int { + Select, + Draw, + Fill, +}; + +[[nodiscard]] +constexpr auto toString(TileSheetTool t) noexcept { + switch (t) { + case TileSheetTool::Select: + return "Select"; + case TileSheetTool::Draw: + return "Draw"; + case TileSheetTool::Fill: + return "Fill"; + } + return ""; +} + class TileSheetEditor { private: diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.hpp b/src/nostalgia/core/studio/tilesheeteditormodel.hpp index 22bee50a..3efb93cc 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.hpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.hpp @@ -23,32 +23,6 @@ enum class CommandId { ClipboardPaste = 5, }; -enum class TileSheetTool: int { - Select, - Draw, - Fill, -}; - -[[nodiscard]] -constexpr auto toString(TileSheetTool t) noexcept { - switch (t) { - case TileSheetTool::Select: - return "Select"; - case TileSheetTool::Draw: - return "Draw"; - case TileSheetTool::Fill: - return "Fill"; - } - return ""; -} - -struct PixelChunk { - static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.PixelChunk"; - static constexpr auto TypeVersion = 1; - geo::Point pt; - int size = 0; -}; - struct DrawCommand: public studio::UndoCommand { private: struct Change { @@ -62,18 +36,18 @@ struct DrawCommand: public studio::UndoCommand { public: constexpr DrawCommand(NostalgiaGraphic *img, std::size_t idx, int palIdx) noexcept { m_img = img; - m_changes.emplace_back(idx, m_img->pixels[idx]); + m_changes.emplace_back(idx, m_img->getPixel(idx)); m_palIdx = palIdx; } constexpr bool append(std::size_t idx) noexcept { - if (m_changes.back().value.idx != idx) { + if (m_changes.back().value.idx != idx && m_img->getPixel(idx) != m_palIdx) { // duplicate entries are bad auto existing = std::find_if(m_changes.cbegin(), m_changes.cend(), [idx](const auto &c) { return c.idx == idx; }); if (existing == m_changes.cend()) { - m_changes.emplace_back(idx, m_img->pixels[idx]); + m_changes.emplace_back(idx, m_img->getPixel(idx)); m_img->setPixel(idx, m_palIdx); return true; } @@ -82,24 +56,19 @@ struct DrawCommand: public studio::UndoCommand { } void redo() noexcept override { - for (auto c : m_changes) { + for (const auto &c : m_changes) { m_img->setPixel(c.idx, m_palIdx); } } void undo() noexcept override { - for (auto c : m_changes) { + for (const auto &c : m_changes) { m_img->setPixel(c.idx, c.oldPalIdx); } } }; -oxModelBegin(PixelChunk) - oxModelField(pt) - oxModelField(size) -oxModelEnd() - struct TileSheetClipboard { static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard"; static constexpr auto TypeVersion = 1;