[nostalgia/core/studio] Put TileSheetEditor draw command in UndoCommand

This commit is contained in:
2022-02-13 23:23:59 -06:00
parent 4f69f027ef
commit d792e4c515
7 changed files with 123 additions and 43 deletions

View File

@@ -46,7 +46,7 @@ void TileSheetEditorImGui::draw(core::Context*) noexcept {
const auto paneSize = ImGui::GetContentRegionAvail();
const auto tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y);
const auto fbSize = geo::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16);
ImGui::BeginChild("child1", ImVec2(tileSheetParentSize.x, tileSheetParentSize.y), true);
ImGui::BeginChild("child1", tileSheetParentSize, true);
drawTileSheet(fbSize);
ImGui::EndChild();
ImGui::SameLine();
@@ -75,8 +75,9 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
ImGui::Image(reinterpret_cast<void*>(m_framebuffer.color.id), static_cast<ImVec2>(fbSize), ImVec2(0, 1), ImVec2(1, 0));
// handle input, this must come after drawing
const auto &io = ImGui::GetIO();
const auto mousePos = geo::Vec2(io.MousePos);
if (ImGui::IsItemHovered()) {
const auto &io = ImGui::GetIO();
const auto wheel = io.MouseWheel;
const auto wheelh = io.MouseWheelH;
if (wheel != 0) {
@@ -87,13 +88,16 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
m_tileSheetEditor.scrollH(fbSize, wheelh);
}
if (io.MouseDown[0]) {
auto clickPos = geo::Vec2(io.MousePos);
auto clickPos = mousePos;
const auto &winPos = ImGui::GetWindowPos();
clickPos.x -= winPos.x + 10;
clickPos.y -= winPos.y + 10;
m_tileSheetEditor.clickPixel(fbSize, clickPos);
m_tileSheetEditor.hitPixel(fbSize, clickPos);
}
}
if (io.MouseReleased[0]) {
m_tileSheetEditor.releaseMouseButton();
}
}
void TileSheetEditorImGui::drawPalettePicker() const noexcept {