タイトルバーの関数
守矢諏訪子 <suwako@076.moe>、2026-06-26 02:28
コミット 8ac5aaf9f44c8fbe613c17f2427efa908450035e
・親 d153e8d
・ファイルを見る
5個のファイル、+78 -31
| @@ -35,7 +35,8 @@ | ||
| 35 | 35 | #pragma once |
| 36 | 36 | |
| 37 | 37 | #include <util/types.hh> |
| 38 | +#include <util/structs.hh> | |
| 38 | 39 | |
| 39 | 40 | namespace gui { |
| 40 | - void showTitleBar(); | |
| 41 | + void showTitleBar(GlfwInfo &glfw); | |
| 41 | 42 | } // namespace gui |
| @@ -35,8 +35,12 @@ | ||
| 35 | 35 | #pragma once |
| 36 | 36 | |
| 37 | 37 | #include <util/glfwpp.hh> |
| 38 | +#include <functional> | |
| 38 | 39 | |
| 39 | 40 | struct GlfwInfo { |
| 40 | 41 | glfwpp::Instance *instance; |
| 41 | 42 | glfwpp::Window *window; |
| 43 | + bool isRunning = true; | |
| 44 | + std::function<void()> compile; | |
| 45 | + std::function<void()> save; | |
| 42 | 46 | }; |
変更
main.cc
| @@ -77,7 +77,7 @@ | ||
| 77 | 77 | window.MakeContextCurrent(); |
| 78 | 78 | glfw.SwapInterval(1); |
| 79 | 79 | |
| 80 | - GlfwInfo glfwInfo = { &glfw, &window }; | |
| 80 | + GlfwInfo glfwInfo = { &glfw, &window, true }; | |
| 81 | 81 | |
| 82 | 82 | #ifndef PRODUCTION_BUILD |
| 83 | 83 | bool showDemo = true; |
| @@ -157,8 +157,8 @@ | ||
| 157 | 157 | bool isHold = false; |
| 158 | 158 | |
| 159 | 159 | // メインレンダリングループ |
| 160 | - while (!window.ShouldClose()) { | |
| 161 | - auto compileCommand = [&]() { | |
| 160 | + while (!window.ShouldClose() && glfwInfo.isRunning) { | |
| 161 | + glfwInfo.compile = [&]() { | |
| 162 | 162 | VERT.code = vertEditor.Get().GetText(); |
| 163 | 163 | FRAG.code = fragEditor.Get().GetText(); |
| 164 | 164 | LUA.code = luaEditor.Get().GetText(); |
| @@ -228,7 +228,7 @@ | ||
| 228 | 228 | std::cout << entry.text << std::endl; |
| 229 | 229 | }; |
| 230 | 230 | |
| 231 | - auto saveCommand = [&]() { | |
| 231 | + glfwInfo.save = [&]() { | |
| 232 | 232 | VERT.code = vertEditor.Get().GetText(); |
| 233 | 233 | FRAG.code = fragEditor.Get().GetText(); |
| 234 | 234 | LUA.code = luaEditor.Get().GetText(); |
| @@ -266,17 +266,20 @@ | ||
| 266 | 266 | bool isCompileKey = window.GetKey(GLFW_KEY_F5); |
| 267 | 267 | bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS); |
| 268 | 268 | bool isSaveKey = (window.GetKey(GLFW_KEY_S) == GLFW_PRESS && ctrlMod); |
| 269 | + bool isQuitKey = (window.GetKey(GLFW_KEY_Q) == GLFW_PRESS && ctrlMod); | |
| 269 | 270 | |
| 270 | 271 | if (!isHold) { |
| 271 | 272 | if (isCompileKey) { |
| 272 | - //isHold = true; | |
| 273 | - compileCommand(); | |
| 273 | + glfwInfo.compile(); | |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | if (isSaveKey) { |
| 277 | - //isHold = true; | |
| 278 | - saveCommand(); | |
| 277 | + glfwInfo.save(); | |
| 279 | 278 | } |
| 279 | + | |
| 280 | + if (isQuitKey) { | |
| 281 | + glfwInfo.isRunning = false; | |
| 282 | + } | |
| 280 | 283 | } |
| 281 | 284 | |
| 282 | 285 | isHold = isSaveKey || isCompileKey; |
| @@ -286,7 +289,7 @@ | ||
| 286 | 289 | continue; |
| 287 | 290 | } |
| 288 | 291 | |
| 289 | - gui::showTitleBar(); | |
| 292 | + gui::showTitleBar(glfwInfo); | |
| 290 | 293 | |
| 291 | 294 | #ifndef PRODUCTION_BUILD |
| 292 | 295 | if (showDemo) ImGui::ShowDemoWindow(&showDemo); |
| @@ -304,13 +307,13 @@ | ||
| 304 | 307 | ImGui::Begin("コントロール"); |
| 305 | 308 | |
| 306 | 309 | if (ImGui::Button("コンパイル(F5)")) { |
| 307 | - compileCommand(); | |
| 310 | + glfwInfo.compile(); | |
| 308 | 311 | } |
| 309 | 312 | |
| 310 | 313 | ImGui::SameLine(); |
| 311 | 314 | |
| 312 | 315 | if (ImGui::Button("保存(CTRL + S)")) { |
| 313 | - saveCommand(); | |
| 316 | + glfwInfo.save(); | |
| 314 | 317 | } |
| 315 | 318 | |
| 316 | 319 | ImGui::Text("現在フレームレート: %.3f ms/frame (%.1f FPS)", 1000.0f / ge.GetIO().Framerate, ge.GetIO().Framerate); |
| @@ -63,9 +63,21 @@ | ||
| 63 | 63 | ImGui::PushFont(m_CjkFont); |
| 64 | 64 | ImGui::Begin(m_Title.c_str()); |
| 65 | 65 | ImGui::PopFont(); |
| 66 | + | |
| 66 | 67 | ImGui::PushFont(m_MonoFont); |
| 67 | 68 | m_Editor.Render(m_RenderName.c_str()); |
| 68 | 69 | ImGui::PopFont(); |
| 70 | + | |
| 71 | + // CTRL + D | |
| 72 | + //if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) { | |
| 73 | + // bool ctrl = ImGui::GetIO().KeyCtrl; | |
| 74 | + | |
| 75 | + // if (ctrl && ImGui::IsKeyPressed(ImGuiKey_D, false)) { | |
| 76 | + // auto cursor = m_Editor.GetCurrentCursorPosition(); | |
| 77 | + // auto lines = m_Editor.GetLineText(cursor.line); | |
| 78 | + // } | |
| 79 | + //} | |
| 80 | + | |
| 69 | 81 | //RenderStatusBar(m_Editor); |
| 70 | 82 | ImGui::End(); |
| 71 | 83 | } |
| @@ -39,39 +39,66 @@ | ||
| 39 | 39 | #include <backends/imgui_impl_opengl3.h> |
| 40 | 40 | |
| 41 | 41 | namespace gui { |
| 42 | - void showTitleBar() { | |
| 42 | + void showTitleBar(GlfwInfo &glfw) { | |
| 43 | 43 | ImGui_ImplOpenGL3_NewFrame(); |
| 44 | 44 | ImGui_ImplGlfw_NewFrame(); |
| 45 | 45 | ImGui::NewFrame(); |
| 46 | 46 | |
| 47 | 47 | if (ImGui::BeginMainMenuBar()) { |
| 48 | 48 | if (ImGui::BeginMenu("ファイル")) { |
| 49 | - if (ImGui::MenuItem("新しいファイル")) {} | |
| 50 | - if (ImGui::MenuItem("開く", "Ctrl+O")) {} | |
| 51 | - if (ImGui::BeginMenu("最近使った物")) { | |
| 52 | - ImGui::MenuItem("fish_hat.c"); | |
| 53 | - ImGui::MenuItem("fish_hat.inl"); | |
| 54 | - ImGui::MenuItem("fish_hat.h"); | |
| 55 | - if (ImGui::BeginMenu("もっと見る...")) { | |
| 56 | - ImGui::MenuItem("Hello"); | |
| 57 | - ImGui::MenuItem("Sailor"); | |
| 58 | - ImGui::EndMenu(); | |
| 59 | - } | |
| 60 | - ImGui::EndMenu(); | |
| 49 | + if (ImGui::MenuItem("新しいファイル", "CTRL+N", false, false)) {} | |
| 50 | + if (ImGui::MenuItem("開く", "Ctrl+O", false, false)) {} | |
| 51 | + //if (ImGui::BeginMenu("最近使った物")) { | |
| 52 | + // ImGui::MenuItem("fish_hat.c"); | |
| 53 | + // ImGui::MenuItem("fish_hat.inl"); | |
| 54 | + // ImGui::MenuItem("fish_hat.h"); | |
| 55 | + // if (ImGui::BeginMenu("もっと見る...")) { | |
| 56 | + // ImGui::MenuItem("Hello"); | |
| 57 | + // ImGui::MenuItem("Sailor"); | |
| 58 | + // ImGui::EndMenu(); | |
| 59 | + // } | |
| 60 | + // ImGui::EndMenu(); | |
| 61 | + //} | |
| 62 | + if (ImGui::MenuItem("保存", "Ctrl+S")) { | |
| 63 | + glfw.save(); | |
| 61 | 64 | } |
| 62 | - if (ImGui::MenuItem("保存", "Ctrl+S")) {} | |
| 63 | 65 | |
| 64 | 66 | ImGui::Separator(); |
| 65 | - if (ImGui::MenuItem("終了", "CTRL+Q")) {} | |
| 67 | + if (ImGui::MenuItem("終了", "CTRL+Q")) { | |
| 68 | + glfw.isRunning = false; | |
| 69 | + } | |
| 66 | 70 | ImGui::EndMenu(); |
| 67 | 71 | } |
| 72 | + | |
| 68 | 73 | if (ImGui::BeginMenu("編集")) { |
| 69 | - if (ImGui::MenuItem("元に戻す", "Ctrl+Z")) {} | |
| 74 | + if (ImGui::MenuItem("元に戻す", "Ctrl+Z", false, false)) {} | |
| 70 | 75 | if (ImGui::MenuItem("やり直し", "Ctrl+Y", false, false)) {} |
| 71 | 76 | ImGui::Separator(); |
| 72 | - if (ImGui::MenuItem("切り取り", "Ctrl+X")) {} | |
| 73 | - if (ImGui::MenuItem("コピー", "Ctrl+C")) {} | |
| 74 | - if (ImGui::MenuItem("貼り付け", "Ctrl+V")) {} | |
| 77 | + if (ImGui::MenuItem("切り取り", "Ctrl+X", false, false)) {} | |
| 78 | + if (ImGui::MenuItem("コピー", "Ctrl+C", false, false)) {} | |
| 79 | + if (ImGui::MenuItem("貼り付け", "Ctrl+V", false, false)) {} | |
| 80 | + if (ImGui::MenuItem("行を複製", "Ctrl+D", false, false)) {} | |
| 81 | + ImGui::Separator(); | |
| 82 | + if (ImGui::MenuItem("設定", "Ctrl+,", false, false)) {} | |
| 83 | + ImGui::EndMenu(); | |
| 84 | + } | |
| 85 | + | |
| 86 | + if (ImGui::BeginMenu("ビルド")) { | |
| 87 | + if (ImGui::MenuItem("コンパイル", "F5")) { | |
| 88 | + glfw.compile(); | |
| 89 | + } | |
| 90 | + ImGui::EndMenu(); | |
| 91 | + } | |
| 92 | + | |
| 93 | + if (ImGui::BeginMenu("ヘルプ")) { | |
| 94 | + if (ImGui::MenuItem("マニュアル", "F1")) {} | |
| 95 | + if (ImGui::MenuItem("Shader Playgroundについて", "F12")) {} | |
| 96 | + ImGui::EndMenu(); | |
| 97 | + } | |
| 98 | + | |
| 99 | + if (ImGui::BeginMenu("言語")) { | |
| 100 | + if (ImGui::MenuItem("日本語")) {} | |
| 101 | + if (ImGui::MenuItem("English")) {} | |
| 75 | 102 | ImGui::EndMenu(); |
| 76 | 103 | } |
| 77 | 104 | ImGui::EndMainMenuBar(); |