From 5c5f8e748ac0212580efa47ff9c189ff3a44ad77 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 17 May 2022 21:24:20 -0500 Subject: [PATCH] [nostalgia/core/studio] Add key shortcuts for changing the selected color --- .../core/studio/tilesheeteditor-imgui.cpp | 14 ++++++++++++++ .../core/studio/tilesheeteditor-imgui.hpp | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp index 13ba7a14..cbbbb990 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.cpp @@ -55,6 +55,20 @@ void TileSheetEditorImGui::paste() { model()->paste(); } +void TileSheetEditorImGui::keyStateChanged(core::Key key, bool down) { + if (!down) { + return; + } + const auto colorCnt = model()->pal().colors.size(); + if (key >= core::Key::Num_1 && key <= core::Key::Num_0 + colorCnt) { + auto idx = ox::min(key - core::Key::Num_1, colorCnt - 1); + m_tileSheetEditor.setPalIdx(idx); + } else if (key == core::Key::Num_0 && colorCnt >= 10) { + auto idx = ox::min(key - core::Key::Num_1 + 9, colorCnt - 1); + m_tileSheetEditor.setPalIdx(idx); + } +} + void TileSheetEditorImGui::draw(core::Context*) noexcept { const auto paneSize = ImGui::GetContentRegionAvail(); const auto tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y); diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp index 7d3f6562..83e5834d 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp @@ -70,6 +70,8 @@ class TileSheetEditorImGui: public studio::BaseEditor { void paste() override; + void keyStateChanged(core::Key key, bool down) override; + void draw(core::Context*) noexcept override; void drawSubsheetSelector(TileSheet::SubSheet*, TileSheet::SubSheetIdx *path) noexcept;