[nostalgia/core/studio/paletteeditor] Fix Alt shortcuts to respect keyboard focus
All checks were successful
Build / build (push) Successful in 2m30s
All checks were successful
Build / build (push) Successful in 2m30s
This commit is contained in:
parent
cb16687641
commit
135f0e4ce8
@ -41,31 +41,10 @@ PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringPa
|
||||
m_sctx(sctx),
|
||||
m_tctx(sctx.tctx),
|
||||
m_pal(*keel::readObj<Palette>(keelCtx(m_tctx), itemPath()).unwrapThrow()) {
|
||||
if (keel::ensureValid(m_pal).errCode) {
|
||||
throw OxException(1, "PaletteEditorImGui: invalid Palette object");
|
||||
}
|
||||
undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand);
|
||||
m_pageRename.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage);
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) {
|
||||
if (!down || m_pageRename.isOpen()) {
|
||||
return;
|
||||
}
|
||||
if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) {
|
||||
if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
|
||||
m_page = ox::min<std::size_t>(
|
||||
static_cast<uint32_t>(key - turbine::Key::Num_1), m_pal.pages.size() - 1);
|
||||
}
|
||||
} else if (key == turbine::Key::Num_0) {
|
||||
if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) {
|
||||
m_selectedColorRow =
|
||||
ox::min<std::size_t>(
|
||||
static_cast<uint32_t>(key - turbine::Key::Num_1 + 9), m_pal.pages.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::draw(studio::StudioContext&) noexcept {
|
||||
auto const paneSize = ImGui::GetContentRegionAvail();
|
||||
{
|
||||
@ -98,6 +77,19 @@ void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept {
|
||||
ImGui::Text("%s", txt.c_str());
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::numShortcuts(size_t &val, size_t const sizeRange) noexcept {
|
||||
auto const lastElem = sizeRange - 1;
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_0)) {
|
||||
val = ox::min<size_t>(9, lastElem);
|
||||
} else for (auto i = 9u; i < 10; --i) {
|
||||
auto const key = static_cast<ImGuiKey>(ImGuiKey_1 + i);
|
||||
if (ImGui::IsKeyPressed(key)) {
|
||||
val = ox::min<size_t>(i, lastElem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept {
|
||||
ImGui::InputInt(label.c_str(), &v, 1, 5);
|
||||
inputFocused = inputFocused || ImGui::IsItemFocused();
|
||||
@ -240,10 +232,8 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
|
||||
int g = green16(c);
|
||||
int b = blue16(c);
|
||||
int const a = alpha16(c);
|
||||
auto const¤tName = m_pal.colorNames[m_selectedColorRow];
|
||||
ox::IString<50> name;
|
||||
name = currentName;
|
||||
auto const nameUpdated = ig::InputText("Name", name);
|
||||
auto const newName = ig::InputText<50>(
|
||||
"Name", m_pal.colorNames[m_selectedColorRow]);
|
||||
bool inputFocused = ImGui::IsItemFocused();
|
||||
ImGui::Separator();
|
||||
colorInput("Red", r, inputFocused);
|
||||
@ -253,25 +243,20 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
|
||||
std::ignore = pushCommand<ApplyColorAllPagesCommand>(
|
||||
m_pal, m_page, m_selectedColorRow);
|
||||
}
|
||||
if (!inputFocused && !m_pageRename.isOpen() && !ImGui::IsKeyDown(ImGuiKey_ModAlt)) {
|
||||
auto const lastColor = largestPage(m_pal) - 1;
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_0)) {
|
||||
m_selectedColorRow = ox::min<size_t>(9, lastColor);
|
||||
} else for (auto i = 9u; i < 10; --i) {
|
||||
auto const key = static_cast<ImGuiKey>(ImGuiKey_1 + i);
|
||||
if (ImGui::IsKeyPressed(key)) {
|
||||
m_selectedColorRow = ox::min<size_t>(i, lastColor);
|
||||
break;
|
||||
}
|
||||
if (!inputFocused && !m_pageRename.isOpen()) {
|
||||
if (!ImGui::IsKeyDown(ImGuiKey_ModAlt)) {
|
||||
numShortcuts(m_selectedColorRow, largestPage(m_pal));
|
||||
} else {
|
||||
numShortcuts(m_page, m_pal.pages.size());
|
||||
}
|
||||
}
|
||||
auto const newColor = color16(r, g, b, a);
|
||||
if (c != newColor) {
|
||||
std::ignore = pushCommand<UpdateColorCommand>(m_pal, m_page, m_selectedColorRow, newColor);
|
||||
}
|
||||
if (nameUpdated) {
|
||||
if (newName) {
|
||||
std::ignore = pushCommand<UpdateColorInfoCommand>(
|
||||
m_pal, m_selectedColorRow, ox::String{name});
|
||||
m_pal, m_selectedColorRow, ox::String{newName});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,6 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
public:
|
||||
PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path);
|
||||
|
||||
void keyStateChanged(turbine::Key key, bool down) override;
|
||||
|
||||
void draw(studio::StudioContext&) noexcept final;
|
||||
|
||||
protected:
|
||||
@ -56,6 +54,8 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
drawColumn(ox::itoa(i));
|
||||
}
|
||||
|
||||
static void numShortcuts(size_t &val, size_t sizeRange) noexcept;
|
||||
|
||||
static void colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept;
|
||||
|
||||
void drawColorsEditor() noexcept;
|
||||
|
Loading…
Reference in New Issue
Block a user