タイトルバーの関数

守矢諏訪子 <suwako@076.moe>、2026-06-26 02:28
コミット 8ac5aaf9f44c8fbe613c17f2427efa908450035e ・親 d153e8d ・ファイルを見る

5個のファイル、+78 -31

@@ -35,7 +35,8 @@
3535 #pragma once
3636
3737 #include <util/types.hh>
38+#include <util/structs.hh>
3839
3940 namespace gui {
40- void showTitleBar();
41+ void showTitleBar(GlfwInfo &glfw);
4142 } // namespace gui
@@ -35,8 +35,12 @@
3535 #pragma once
3636
3737 #include <util/glfwpp.hh>
38+#include <functional>
3839
3940 struct GlfwInfo {
4041 glfwpp::Instance *instance;
4142 glfwpp::Window *window;
43+ bool isRunning = true;
44+ std::function<void()> compile;
45+ std::function<void()> save;
4246 };
変更 main.cc
@@ -77,7 +77,7 @@
7777 window.MakeContextCurrent();
7878 glfw.SwapInterval(1);
7979
80- GlfwInfo glfwInfo = { &glfw, &window };
80+ GlfwInfo glfwInfo = { &glfw, &window, true };
8181
8282 #ifndef PRODUCTION_BUILD
8383 bool showDemo = true;
@@ -157,8 +157,8 @@
157157 bool isHold = false;
158158
159159 // メインレンダリングループ
160- while (!window.ShouldClose()) {
161- auto compileCommand = [&]() {
160+ while (!window.ShouldClose() && glfwInfo.isRunning) {
161+ glfwInfo.compile = [&]() {
162162 VERT.code = vertEditor.Get().GetText();
163163 FRAG.code = fragEditor.Get().GetText();
164164 LUA.code = luaEditor.Get().GetText();
@@ -228,7 +228,7 @@
228228 std::cout << entry.text << std::endl;
229229 };
230230
231- auto saveCommand = [&]() {
231+ glfwInfo.save = [&]() {
232232 VERT.code = vertEditor.Get().GetText();
233233 FRAG.code = fragEditor.Get().GetText();
234234 LUA.code = luaEditor.Get().GetText();
@@ -266,17 +266,20 @@
266266 bool isCompileKey = window.GetKey(GLFW_KEY_F5);
267267 bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS);
268268 bool isSaveKey = (window.GetKey(GLFW_KEY_S) == GLFW_PRESS && ctrlMod);
269+ bool isQuitKey = (window.GetKey(GLFW_KEY_Q) == GLFW_PRESS && ctrlMod);
269270
270271 if (!isHold) {
271272 if (isCompileKey) {
272- //isHold = true;
273- compileCommand();
273+ glfwInfo.compile();
274274 }
275275
276276 if (isSaveKey) {
277- //isHold = true;
278- saveCommand();
277+ glfwInfo.save();
279278 }
279+
280+ if (isQuitKey) {
281+ glfwInfo.isRunning = false;
282+ }
280283 }
281284
282285 isHold = isSaveKey || isCompileKey;
@@ -286,7 +289,7 @@
286289 continue;
287290 }
288291
289- gui::showTitleBar();
292+ gui::showTitleBar(glfwInfo);
290293
291294 #ifndef PRODUCTION_BUILD
292295 if (showDemo) ImGui::ShowDemoWindow(&showDemo);
@@ -304,13 +307,13 @@
304307 ImGui::Begin("コントロール");
305308
306309 if (ImGui::Button("コンパイル(F5)")) {
307- compileCommand();
310+ glfwInfo.compile();
308311 }
309312
310313 ImGui::SameLine();
311314
312315 if (ImGui::Button("保存(CTRL + S)")) {
313- saveCommand();
316+ glfwInfo.save();
314317 }
315318
316319 ImGui::Text("現在フレームレート: %.3f ms/frame (%.1f FPS)", 1000.0f / ge.GetIO().Framerate, ge.GetIO().Framerate);
@@ -63,9 +63,21 @@
6363 ImGui::PushFont(m_CjkFont);
6464 ImGui::Begin(m_Title.c_str());
6565 ImGui::PopFont();
66+
6667 ImGui::PushFont(m_MonoFont);
6768 m_Editor.Render(m_RenderName.c_str());
6869 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+
6981 //RenderStatusBar(m_Editor);
7082 ImGui::End();
7183 }
@@ -39,39 +39,66 @@
3939 #include <backends/imgui_impl_opengl3.h>
4040
4141 namespace gui {
42- void showTitleBar() {
42+ void showTitleBar(GlfwInfo &glfw) {
4343 ImGui_ImplOpenGL3_NewFrame();
4444 ImGui_ImplGlfw_NewFrame();
4545 ImGui::NewFrame();
4646
4747 if (ImGui::BeginMainMenuBar()) {
4848 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();
6164 }
62- if (ImGui::MenuItem("保存", "Ctrl+S")) {}
6365
6466 ImGui::Separator();
65- if (ImGui::MenuItem("終了", "CTRL+Q")) {}
67+ if (ImGui::MenuItem("終了", "CTRL+Q")) {
68+ glfw.isRunning = false;
69+ }
6670 ImGui::EndMenu();
6771 }
72+
6873 if (ImGui::BeginMenu("編集")) {
69- if (ImGui::MenuItem("元に戻す", "Ctrl+Z")) {}
74+ if (ImGui::MenuItem("元に戻す", "Ctrl+Z", false, false)) {}
7075 if (ImGui::MenuItem("やり直し", "Ctrl+Y", false, false)) {}
7176 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")) {}
75102 ImGui::EndMenu();
76103 }
77104 ImGui::EndMainMenuBar();