ESCキーでウィンドウを閉じる様に
守矢諏訪子 <suwako@076.moe>、2026-06-28 18:39
コミット 997e0305c3e8e451ba4ca50fe64673f689e31217
・親 41edc88
・ファイルを見る
8個のファイル、+23 -14
| @@ -52,6 +52,8 @@ | ||
| 52 | 52 | GuiEngine(glfwpp::Window *window); |
| 53 | 53 | ~GuiEngine(); |
| 54 | 54 | |
| 55 | + static bool ShouldCloseWindowOnEscape(); | |
| 56 | + | |
| 55 | 57 | ImGuiIO &GetIO() const { return ImGui::GetIO(); } |
| 56 | 58 | ImFont *GetCjkFont() const { return m_CjkFont; } |
| 57 | 59 | ImFont *GetMonoFont() const { return m_MonoFont; } |
| @@ -67,7 +67,6 @@ | ||
| 67 | 67 | bool showSaveAsShaderPopup = false; |
| 68 | 68 | bool viewportFocused = false; |
| 69 | 69 | bool pendingCompile = false; |
| 70 | - bool closePopup = false; | |
| 71 | 70 | |
| 72 | 71 | std::string version = version::full; |
| 73 | 72 | uint32_t shaderId = 0; |
変更
main.cc
| @@ -390,6 +390,8 @@ | ||
| 390 | 390 | static i32 selectedId = -1; |
| 391 | 391 | ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver); |
| 392 | 392 | if (ImGui::BeginPopupModal(info.i18n->GetWord("fileopenshader").c_str(), nullptr)) { |
| 393 | + if (ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup(); | |
| 394 | + | |
| 393 | 395 | vector <db::ShaderData > shdrs = db::GetAllShaders(db); |
| 394 | 396 | ImGui::BeginChild("ShaderList", ImVec2(0, 300), true); |
| 395 | 397 | |
| @@ -442,10 +444,12 @@ | ||
| 442 | 444 | |
| 443 | 445 | info.saveAs = [&]() { |
| 444 | 446 | if (ImGui::BeginPopupModal(info.i18n->GetWord("filesaveasshader").c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { |
| 447 | + if (ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup(); | |
| 448 | + | |
| 445 | 449 | ImGui::Text(info.i18n->GetWord("fileshadername").c_str()); |
| 446 | 450 | ImGui::SameLine(); |
| 447 | 451 | static char str0[128] = "new"; |
| 448 | - ImGui::InputText("input text", str0, IM_COUNTOF(str0)); | |
| 452 | + ImGui::InputText("##SaveInput", str0, IM_COUNTOF(str0)); | |
| 449 | 453 | |
| 450 | 454 | ImGui::Separator(); |
| 451 | 455 | |
| @@ -453,6 +457,8 @@ | ||
| 453 | 457 | ImGui::CloseCurrentPopup(); |
| 454 | 458 | } |
| 455 | 459 | |
| 460 | + ImGui::SameLine(); | |
| 461 | + | |
| 456 | 462 | if (ImGui::Button(info.i18n->GetWord("filesave").c_str())) { |
| 457 | 463 | info.shaderName = string(str0); |
| 458 | 464 | info.VERT.code = vertEditor.Get().GetText(); |
| @@ -486,6 +492,8 @@ | ||
| 486 | 492 | |
| 487 | 493 | info.create = [&]() { |
| 488 | 494 | if (ImGui::BeginPopupModal(info.i18n->GetWord("filenewcreateshader").c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { |
| 495 | + if (ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup(); | |
| 496 | + | |
| 489 | 497 | if (ImGui::Button(info.i18n->GetWord("filenew2dshader").c_str(), ImVec2(200, 0))) { |
| 490 | 498 | gui::NewShader newShader(&info); |
| 491 | 499 | auto shdr = newShader.Make(gui::ShaderType::Simple2D); |
| @@ -598,8 +606,6 @@ | ||
| 598 | 606 | bool isManualKey = window.GetKey(GLFW_KEY_F1); |
| 599 | 607 | bool isCompileKey = window.GetKey(GLFW_KEY_F5); |
| 600 | 608 | |
| 601 | - bool isEscKey = window.GetKey(GLFW_KEY_ESCAPE); | |
| 602 | - | |
| 603 | 609 | bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS); |
| 604 | 610 | bool shiftMod = (window.GetKey(GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS); |
| 605 | 611 | //bool altMod = (window.GetKey(GLFW_KEY_LEFT_ALT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_ALT) == GLFW_PRESS); |
| @@ -632,10 +638,6 @@ | ||
| 632 | 638 | if (isSaveKey) { |
| 633 | 639 | if (info.shaderId == 0) info.showSaveAsShaderPopup = true; |
| 634 | 640 | else info.save(); |
| 635 | - } | |
| 636 | - | |
| 637 | - if (isEscKey) { | |
| 638 | - info.closePopup = true; | |
| 639 | 641 | } |
| 640 | 642 | |
| 641 | 643 | if (isManualKey) { |
| @@ -37,6 +37,7 @@ | ||
| 37 | 37 | #include <gui/about.hh> |
| 38 | 38 | #include <imgui.h> |
| 39 | 39 | #include <database/locale.hh> |
| 40 | +#include <gui/guiengine.hh> | |
| 40 | 41 | |
| 41 | 42 | namespace gui { |
| 42 | 43 | void About::Draw(Info &info) { |
| @@ -45,6 +46,7 @@ | ||
| 45 | 46 | ImGuiWindowFlags flags = 0; |
| 46 | 47 | ImGui::SetNextWindowSize({400, 300}, ImGuiCond_Appearing); |
| 47 | 48 | ImGui::Begin(info.i18n->GetWord("helpabout").c_str(), &info.isAbout, flags); |
| 49 | + if (GuiEngine::ShouldCloseWindowOnEscape()) info.isAbout = false; | |
| 48 | 50 | string name = "Shader Playground " + info.version; |
| 49 | 51 | string copyright; |
| 50 | 52 | string developer; |
| @@ -71,4 +71,10 @@ | ||
| 71 | 71 | ImGui_ImplGlfw_Shutdown(); |
| 72 | 72 | ImGui::DestroyContext(); |
| 73 | 73 | } |
| 74 | + | |
| 75 | + bool GuiEngine::ShouldCloseWindowOnEscape() { | |
| 76 | + return ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) | |
| 77 | + && !ImGui::GetIO().WantTextInput | |
| 78 | + && ImGui::IsKeyPressed(ImGuiKey_Escape); | |
| 79 | + } | |
| 74 | 80 | } // namespace gui |
| @@ -37,6 +37,7 @@ | ||
| 37 | 37 | #include <gui/manual.hh> |
| 38 | 38 | #include <imgui.h> |
| 39 | 39 | #include <database/locale.hh> |
| 40 | +#include <gui/guiengine.hh> | |
| 40 | 41 | |
| 41 | 42 | namespace gui { |
| 42 | 43 | void Manual::Draw(Info &info) { |
| @@ -46,7 +47,7 @@ | ||
| 46 | 47 | |
| 47 | 48 | ImGui::SetNextWindowSize({ 600, 700 }, ImGuiCond_Appearing); |
| 48 | 49 | ImGui::Begin(info.i18n->GetWord("helpmanual").c_str(), &info.isManual, flags); |
| 49 | - //if (info.closePopup) ImGui::CloseW | |
| 50 | + if (GuiEngine::ShouldCloseWindowOnEscape()) info.isManual = false; | |
| 50 | 51 | |
| 51 | 52 | if (ImGui::BeginTabBar("ManualTabs")) { |
| 52 | 53 | if (ImGui::BeginTabItem(info.i18n->GetWord("helpmanualoverview").c_str())) { |
| @@ -57,10 +57,5 @@ | ||
| 57 | 57 | saveShader.luaCode.code = m_Info->LUA.code; |
| 58 | 58 | |
| 59 | 59 | db::SaveNewShader(db, saveShader); |
| 60 | - | |
| 61 | - LogEntry entry; | |
| 62 | - entry.text = saveShader.name; | |
| 63 | - entry.type = LogType::Normal; | |
| 64 | - m_Info->cmd->Add(entry); | |
| 65 | 60 | } |
| 66 | 61 | } // namespace gui |
| @@ -39,6 +39,7 @@ | ||
| 39 | 39 | #include <util/structs.hh> |
| 40 | 40 | #include <database/locale.hh> |
| 41 | 41 | #include <imgui.h> |
| 42 | +#include <gui/guiengine.hh> | |
| 42 | 43 | |
| 43 | 44 | namespace gui { |
| 44 | 45 | void Settings::Draw(Info &info) { |
| @@ -47,6 +48,7 @@ | ||
| 47 | 48 | ImGuiWindowFlags flags = 0; |
| 48 | 49 | ImGui::SetNextWindowSize({ 400, 300 }, ImGuiCond_Appearing); |
| 49 | 50 | ImGui::Begin(info.i18n->GetWord("settings").c_str(), &info.isSettings, flags); |
| 51 | + if (GuiEngine::ShouldCloseWindowOnEscape()) info.isSettings = false; | |
| 50 | 52 | |
| 51 | 53 | ImGui::Text("言語 / Language"); |
| 52 | 54 | ImGui::SameLine(); |