ESCキーでウィンドウを閉じる様に

守矢諏訪子 <suwako@076.moe>、2026-06-28 18:39
コミット 997e0305c3e8e451ba4ca50fe64673f689e31217 ・親 41edc88 ・ファイルを見る

8個のファイル、+23 -14

@@ -52,6 +52,8 @@
5252 GuiEngine(glfwpp::Window *window);
5353 ~GuiEngine();
5454
55+ static bool ShouldCloseWindowOnEscape();
56+
5557 ImGuiIO &GetIO() const { return ImGui::GetIO(); }
5658 ImFont *GetCjkFont() const { return m_CjkFont; }
5759 ImFont *GetMonoFont() const { return m_MonoFont; }
@@ -67,7 +67,6 @@
6767 bool showSaveAsShaderPopup = false;
6868 bool viewportFocused = false;
6969 bool pendingCompile = false;
70- bool closePopup = false;
7170
7271 std::string version = version::full;
7372 uint32_t shaderId = 0;
変更 main.cc
@@ -390,6 +390,8 @@
390390 static i32 selectedId = -1;
391391 ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
392392 if (ImGui::BeginPopupModal(info.i18n->GetWord("fileopenshader").c_str(), nullptr)) {
393+ if (ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup();
394+
393395 vector <db::ShaderData > shdrs = db::GetAllShaders(db);
394396 ImGui::BeginChild("ShaderList", ImVec2(0, 300), true);
395397
@@ -442,10 +444,12 @@
442444
443445 info.saveAs = [&]() {
444446 if (ImGui::BeginPopupModal(info.i18n->GetWord("filesaveasshader").c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
447+ if (ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup();
448+
445449 ImGui::Text(info.i18n->GetWord("fileshadername").c_str());
446450 ImGui::SameLine();
447451 static char str0[128] = "new";
448- ImGui::InputText("input text", str0, IM_COUNTOF(str0));
452+ ImGui::InputText("##SaveInput", str0, IM_COUNTOF(str0));
449453
450454 ImGui::Separator();
451455
@@ -453,6 +457,8 @@
453457 ImGui::CloseCurrentPopup();
454458 }
455459
460+ ImGui::SameLine();
461+
456462 if (ImGui::Button(info.i18n->GetWord("filesave").c_str())) {
457463 info.shaderName = string(str0);
458464 info.VERT.code = vertEditor.Get().GetText();
@@ -486,6 +492,8 @@
486492
487493 info.create = [&]() {
488494 if (ImGui::BeginPopupModal(info.i18n->GetWord("filenewcreateshader").c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
495+ if (ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup();
496+
489497 if (ImGui::Button(info.i18n->GetWord("filenew2dshader").c_str(), ImVec2(200, 0))) {
490498 gui::NewShader newShader(&info);
491499 auto shdr = newShader.Make(gui::ShaderType::Simple2D);
@@ -598,8 +606,6 @@
598606 bool isManualKey = window.GetKey(GLFW_KEY_F1);
599607 bool isCompileKey = window.GetKey(GLFW_KEY_F5);
600608
601- bool isEscKey = window.GetKey(GLFW_KEY_ESCAPE);
602-
603609 bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS);
604610 bool shiftMod = (window.GetKey(GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS);
605611 //bool altMod = (window.GetKey(GLFW_KEY_LEFT_ALT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_ALT) == GLFW_PRESS);
@@ -632,10 +638,6 @@
632638 if (isSaveKey) {
633639 if (info.shaderId == 0) info.showSaveAsShaderPopup = true;
634640 else info.save();
635- }
636-
637- if (isEscKey) {
638- info.closePopup = true;
639641 }
640642
641643 if (isManualKey) {
@@ -37,6 +37,7 @@
3737 #include <gui/about.hh>
3838 #include <imgui.h>
3939 #include <database/locale.hh>
40+#include <gui/guiengine.hh>
4041
4142 namespace gui {
4243 void About::Draw(Info &info) {
@@ -45,6 +46,7 @@
4546 ImGuiWindowFlags flags = 0;
4647 ImGui::SetNextWindowSize({400, 300}, ImGuiCond_Appearing);
4748 ImGui::Begin(info.i18n->GetWord("helpabout").c_str(), &info.isAbout, flags);
49+ if (GuiEngine::ShouldCloseWindowOnEscape()) info.isAbout = false;
4850 string name = "Shader Playground " + info.version;
4951 string copyright;
5052 string developer;
@@ -71,4 +71,10 @@
7171 ImGui_ImplGlfw_Shutdown();
7272 ImGui::DestroyContext();
7373 }
74+
75+ bool GuiEngine::ShouldCloseWindowOnEscape() {
76+ return ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)
77+ && !ImGui::GetIO().WantTextInput
78+ && ImGui::IsKeyPressed(ImGuiKey_Escape);
79+ }
7480 } // namespace gui
@@ -37,6 +37,7 @@
3737 #include <gui/manual.hh>
3838 #include <imgui.h>
3939 #include <database/locale.hh>
40+#include <gui/guiengine.hh>
4041
4142 namespace gui {
4243 void Manual::Draw(Info &info) {
@@ -46,7 +47,7 @@
4647
4748 ImGui::SetNextWindowSize({ 600, 700 }, ImGuiCond_Appearing);
4849 ImGui::Begin(info.i18n->GetWord("helpmanual").c_str(), &info.isManual, flags);
49- //if (info.closePopup) ImGui::CloseW
50+ if (GuiEngine::ShouldCloseWindowOnEscape()) info.isManual = false;
5051
5152 if (ImGui::BeginTabBar("ManualTabs")) {
5253 if (ImGui::BeginTabItem(info.i18n->GetWord("helpmanualoverview").c_str())) {
@@ -57,10 +57,5 @@
5757 saveShader.luaCode.code = m_Info->LUA.code;
5858
5959 db::SaveNewShader(db, saveShader);
60-
61- LogEntry entry;
62- entry.text = saveShader.name;
63- entry.type = LogType::Normal;
64- m_Info->cmd->Add(entry);
6560 }
6661 } // namespace gui
@@ -39,6 +39,7 @@
3939 #include <util/structs.hh>
4040 #include <database/locale.hh>
4141 #include <imgui.h>
42+#include <gui/guiengine.hh>
4243
4344 namespace gui {
4445 void Settings::Draw(Info &info) {
@@ -47,6 +48,7 @@
4748 ImGuiWindowFlags flags = 0;
4849 ImGui::SetNextWindowSize({ 400, 300 }, ImGuiCond_Appearing);
4950 ImGui::Begin(info.i18n->GetWord("settings").c_str(), &info.isSettings, flags);
51+ if (GuiEngine::ShouldCloseWindowOnEscape()) info.isSettings = false;
5052
5153 ImGui::Text("言語 / Language");
5254 ImGui::SameLine();