設定ウィンドウの追加

守矢諏訪子 <suwako@076.moe>、2026-06-27 01:31
コミット fb7bf6873f44be6046215c3a3f4c16ff3a284254 ・親 bab9c87 ・ファイルを見る

15個のファイル、+127 -51

@@ -43,4 +43,4 @@
4343 #include <gui/about.hh>
4444 #include <gui/consolelog.hh>
4545 #include <gui/manual.hh>
46-// #include <gui/settings.hh>
46+ #include <gui/settings.hh>
@@ -42,6 +42,6 @@
4242 namespace gui {
4343 class About {
4444 public:
45- void Draw(GlfwInfo &glfw);
45+ void Draw(GlfwInfo &glfw);
4646 }; // class About
4747 } // namespace gui
@@ -37,7 +37,11 @@
3737 #pragma once
3838
3939 #include <util/types.hh>
40-#include <util/structs.hh>
40+
41+struct GlfwInfo;
42+namespace db {
43+ class Locale;
44+} // namespace db
4145
4246 namespace gui {
4347 enum class LogType {
@@ -37,6 +37,11 @@
3737 #pragma once
3838
3939 #include <util/types.hh>
40+#include <util/structs.hh>
4041
4142 namespace gui {
43+ class Settings {
44+ public:
45+ void Draw(GlfwInfo &glfw);
46+ }; // class Settings
4247 } // namespace gui
@@ -65,7 +65,7 @@
6565
6666 class LuaEngine {
6767 public:
68- LuaEngine(const string &code, Program *prog, GlfwInfo *glfwInfo, gui::ConsoleLog *cmd = nullptr);
68+ LuaEngine(const string &code, Program *prog, GlfwInfo *glfwInfo);
6969 ~LuaEngine();
7070
7171 public:
@@ -79,7 +79,6 @@
7979
8080 public:
8181 void SetProgram(Program *prog) { m_Program = prog; }
82- void SetConsole(gui::ConsoleLog *cmd) { m_Console = cmd; }
8382 string GetApiVersion() const { return m_ApiVersion; }
8483
8584 private:
@@ -97,7 +96,6 @@
9796 sol::state m_Lua;
9897 string m_Code;
9998 Program *m_Program = nullptr;
100- gui::ConsoleLog *m_Console = nullptr;
10199 GlfwInfo *m_GlfwInfo = {};
102100 string m_ApiVersion = "1.0.0";
103101 f32 m_LastTime = 0.f;
@@ -37,11 +37,18 @@
3737 #pragma once
3838
3939 #include <util/glfwpp.hh>
40-#include <database/locale.hh>
4140 #include <version.hh>
4241 #include <functional>
4342 #include <string>
4443
44+namespace gui {
45+ class ConsoleLog;
46+} // namespace gui
47+
48+namespace db {
49+ class Locale;
50+} // namespace db
51+
4552 struct GlfwInfo {
4653 glfwpp::Instance *instance;
4754 glfwpp::Window *window;
@@ -54,6 +61,7 @@
5461
5562 std::string version = version::full;
5663
64+ gui::ConsoleLog *cmd;
5765 db::Locale *i18n;
5866
5967 std::function<void()> compile;
変更 main.cc
@@ -108,6 +108,7 @@
108108
109109 // コンソール
110110 gui::ConsoleLog cmd;
111+ glfwInfo.cmd = &cmd;
111112
112113 // ビューポート
113114 gui::ViewPort viewport;
@@ -149,7 +150,7 @@
149150 Program shaderProgram(vertexShader, fragmentShader);
150151
151152 // 頂点データはLuaから受け取る
152- lua::LuaEngine luaEngine(LUA.code, &shaderProgram, &glfwInfo, &cmd);
153+ lua::LuaEngine luaEngine(LUA.code, &shaderProgram, &glfwInfo);
153154 auto &mesh = luaEngine.GetMesh();
154155
155156 VertexArrays VAO(1);
@@ -170,6 +171,7 @@
170171
171172 bool isHold = false;
172173 gui::About about;
174+ gui::Settings settings;
173175
174176 // メインレンダリングループ
175177 while (!window.ShouldClose() && glfwInfo.isRunning) {
@@ -184,7 +186,7 @@
184186 gui::LogEntry entry;
185187 entry.type = gui::LogType::Error;
186188 entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidcomp");
187- cmd.Add(entry);
189+ glfwInfo.cmd->Add(entry);
188190 std::cerr << entry.text << std::endl;
189191 return;
190192 }
@@ -192,10 +194,10 @@
192194 gui::LogEntry entry;
193195 entry.type = gui::LogType::Error;
194196 entry.text = e.what();
195- cmd.Add(entry);
197+ glfwInfo.cmd->Add(entry);
196198 std::cerr << entry.text << std::endl;
197199 entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidcomp");
198- cmd.Add(entry);
200+ glfwInfo.cmd->Add(entry);
199201 std::cerr << entry.text << std::endl;
200202 return;
201203 }
@@ -236,16 +238,16 @@
236238 gui::LogEntry entry;
237239 entry.type = gui::LogType::Info;
238240 entry.text = glfwInfo.i18n->GetWord("consoleloginfocompileok");
239- cmd.Add(entry);
241+ glfwInfo.cmd->Add(entry);
240242 std::cout << entry.text << std::endl;
241243 } catch (const std::exception &e) {
242244 gui::LogEntry entry;
243245 entry.type = gui::LogType::Error;
244246 entry.text = e.what();
245- cmd.Add(entry);
247+ glfwInfo.cmd->Add(entry);
246248 std::cerr << entry.text << std::endl;
247249 entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidcomp");
248- cmd.Add(entry);
250+ glfwInfo.cmd->Add(entry);
249251 std::cerr << entry.text << std::endl;
250252 }
251253 };
@@ -261,7 +263,7 @@
261263 gui::LogEntry entry;
262264 entry.type = gui::LogType::Error;
263265 entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidsave");
264- cmd.Add(entry);
266+ glfwInfo.cmd->Add(entry);
265267 std::cout << entry.text << std::endl;
266268 return;
267269 }
@@ -269,10 +271,10 @@
269271 gui::LogEntry entry;
270272 entry.type = gui::LogType::Error;
271273 entry.text = e.what();
272- cmd.Add(entry);
274+ glfwInfo.cmd->Add(entry);
273275 std::cout << entry.text << std::endl;
274276 entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidsave");
275- cmd.Add(entry);
277+ glfwInfo.cmd->Add(entry);
276278 std::cout << entry.text << std::endl;
277279 return;
278280 }
@@ -284,16 +286,16 @@
284286 gui::LogEntry entry;
285287 entry.type = gui::LogType::Info;
286288 entry.text = glfwInfo.i18n->GetWord("consoleloginfosaveok");
287- cmd.Add(entry);
289+ glfwInfo.cmd->Add(entry);
288290 std::cout << entry.text << std::endl;
289291 } catch (const std::exception &e) {
290292 gui::LogEntry entry;
291293 entry.type = gui::LogType::Error;
292294 entry.text = e.what();
293- cmd.Add(entry);
295+ glfwInfo.cmd->Add(entry);
294296 std::cout << entry.text << std::endl;
295297 entry.text = glfwInfo.i18n->GetWord("consolelogerrorluainvalidsave");
296- cmd.Add(entry);
298+ glfwInfo.cmd->Add(entry);
297299 std::cout << entry.text << std::endl;
298300 }
299301 };
@@ -360,8 +362,9 @@
360362 vertEditor.Render();
361363 fragEditor.Render();
362364 luaEditor.Render();
363- cmd.Draw(glfwInfo, glfwInfo.i18n->GetWord("editorconsole").c_str());
365+ glfwInfo.cmd->Draw(glfwInfo, glfwInfo.i18n->GetWord("editorconsole").c_str());
364366 about.Draw(glfwInfo);
367+ settings.Draw(glfwInfo);
365368 manual.Draw(glfwInfo);
366369
367370 viewport.Draw(glfwInfo);
@@ -234,8 +234,6 @@
234234 createWord(db, 2, "helpabout", "About Shader Playground");
235235 createWord(db, 1, "currentfps", "現在フレームレート");
236236 createWord(db, 2, "currentfps", "Current Frame Rate");
237- createWord(db, 1, "dateformat", "%Y年%m月%d日 %H:%M:%S");
238- createWord(db, 2, "dateformat", "%Y/%m/%d %H:%M:%S");
239237 createWord(db, 1, "consolelogerrorluainvalidcomp", "Luaコードが不正ですので、コンパイル出来ませんでした。");
240238 createWord(db, 2, "consolelogerrorluainvalidcomp", "Your Lua code is invalid, so it could not be compiled.");
241239 createWord(db, 1, "consolelogerrorluainvalidsave", "Luaコードが不正ですので、保存出来ませんでした。");
@@ -244,6 +242,8 @@
244242 createWord(db, 2, "consoleloginfocompileok", "Shaders got compiled successfully.");
245243 createWord(db, 1, "consoleloginfosaveok", "シェーダー及びLuaを保存しました。");
246244 createWord(db, 2, "consoleloginfosaveok", "Shaders and Lua have been saved.");
245+ createWord(db, 1, "consoleloginfolangchangeok", "言語を変更しました。");
246+ createWord(db, 2, "consoleloginfolangchangeok", "Language has been changed.");
247247 }
248248
249249 i64 shaderId = 0;
@@ -36,6 +36,7 @@
3636 */
3737 #include <gui/about.hh>
3838 #include <imgui.h>
39+#include <database/locale.hh>
3940
4041 namespace gui {
4142 void About::Draw(GlfwInfo &glfw) {
@@ -35,6 +35,8 @@
3535 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3636 */
3737 #include <gui/consolelog.hh>
38+#include <database/locale.hh>
39+#include <util/structs.hh>
3840 #include <imgui.h>
3941
4042 namespace gui {
@@ -36,9 +36,9 @@
3636 */
3737 #include <gui/manual.hh>
3838 #include <imgui.h>
39+#include <database/locale.hh>
3940
4041 namespace gui {
41-
4242 void Manual::Draw(GlfwInfo &glfw) {
4343 if (!glfw.isManual) return;
4444
@@ -35,6 +35,60 @@
3535 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3636 */
3737 #include <gui/settings.hh>
38+#include <gui/consolelog.hh>
39+#include <util/structs.hh>
40+#include <database/locale.hh>
41+#include <imgui.h>
3842
3943 namespace gui {
44+ void Settings::Draw(GlfwInfo &glfw) {
45+ if (!glfw.isSettings) return;
46+
47+ ImGuiWindowFlags flags = 0;
48+ ImGui::SetNextWindowSize({ 400, 300 }, ImGuiCond_Appearing);
49+ ImGui::Begin(glfw.i18n->GetWord("settings").c_str(), &glfw.isSettings, flags);
50+
51+ ImGui::Text("言語 / Language");
52+ ImGui::SameLine();
53+ cstr items[] = { "日本語 (ja_JP)", "English (en_US)" };
54+ const i32 itemCount = IM_COUNTOF(items);
55+ i32 curId = glfw.i18n->GetCurrentLanguage().id;
56+ static i32 sel = (curId >= 1) ? curId - 1 : 0;
57+
58+ sel = (curId >= 1 && curId <= itemCount) ? curId - 1 : 0;
59+
60+ const char *preview = items[sel];
61+ if (ImGui::BeginCombo("##Language", preview)) {
62+ for (int n = 0; n < itemCount; ++n) {
63+ const bool isSel = (sel == n);
64+ if (ImGui::Selectable(items[n], isSel)) {
65+ sel = n;
66+ glfw.i18n->SetLanguage(n + 1);
67+ gui::LogEntry entry;
68+ entry.type = gui::LogType::Info;
69+ entry.text = glfw.i18n->GetWord("consoleloginfolangchangeok");
70+ glfw.cmd->Add(entry);
71+ }
72+
73+ if (isSel) {
74+ ImGui::SetItemDefaultFocus();
75+ }
76+ }
77+ ImGui::EndCombo();
78+ }
79+
80+ f32 btnW = 80.f;
81+ f32 btnH = 0.f;
82+
83+ ImVec2 winSize = ImGui::GetWindowSize();
84+ ImVec2 cursorPos = ImGui::GetCursorPos();
85+
86+ ImGui::SetCursorPos({
87+ (winSize.x - btnW) * .5f,
88+ winSize.y - 40.f
89+ });
90+
91+ if (ImGui::Button("OK", { btnW, btnH })) glfw.isSettings = false;
92+ ImGui::End();
93+ }
4094 } // namespace gui
@@ -35,12 +35,12 @@
3535 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3636 */
3737 #include <gui/titlebar.hh>
38-#include <gui/about.hh>
3938
4039 #include <imgui.h>
4140 #include <imgui_internal.h>
4241 #include <backends/imgui_impl_glfw.h>
4342 #include <backends/imgui_impl_opengl3.h>
43+#include <database/locale.hh>
4444 #include <ctime>
4545
4646 namespace gui {
@@ -50,6 +50,7 @@
5050 ImGui::NewFrame();
5151
5252 ImGuiWindowFlags window_flags =
53+ ImGuiWindowFlags_NoCollapse |
5354 ImGuiWindowFlags_MenuBar |
5455 ImGuiWindowFlags_NoDocking;
5556
@@ -68,6 +69,9 @@
6869 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
6970 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
7071
72+ ImGui::GetIO().ConfigDockingWithShift = true;
73+ ImGui::GetStyle().WindowMenuButtonPosition = ImGuiDir_None;
74+
7175 ImGui::Begin("MainDockSpace", nullptr, window_flags);
7276
7377 ImGui::PopStyleVar(2);
@@ -153,7 +157,7 @@
153157 if (ImGui::MenuItem(glfw.i18n->GetWord("editpaste").c_str(), "Ctrl+V", false, false)) {}
154158 if (ImGui::MenuItem(glfw.i18n->GetWord("editduplicate").c_str(), "Ctrl+D", false, false)) {}
155159 ImGui::Separator();
156- if (ImGui::MenuItem(glfw.i18n->GetWord("settings").c_str(), "Ctrl+,", false, false)) {
160+ if (ImGui::MenuItem(glfw.i18n->GetWord("settings").c_str(), "Ctrl+,")) {
157161 glfw.isSettings = true;
158162 }
159163 ImGui::EndMenu();
@@ -176,31 +180,27 @@
176180 ImGui::EndMenu();
177181 }
178182
179- if (ImGui::BeginMenu("言語/Language")) {
180- if (ImGui::MenuItem("日本語")) {
181- glfw.i18n->SetLanguage(1);
182- glfw.isLangChange = true;
183- }
184- if (ImGui::MenuItem("English")) {
185- glfw.i18n->SetLanguage(2);
186- glfw.isLangChange = true;
187- }
188- ImGui::EndMenu();
189- }
190-
191183 ImGui::SameLine();
192184
193- f32 rightW = ImGui::GetContentRegionAvail().x;
194- ImGui::SetCursorPosX(ImGui::GetCursorPosX() + rightW - 400.f);
185+ f32 side;
186+ if (glfw.i18n->GetCurrentLanguage().code == "ja_JP") side = 379.f;
187+ else side = 380.f;
188+
189+ ImGui::SetCursorPosX(ImGui::GetWindowWidth() - side);
190+
195191 string fmt = glfw.i18n->GetWord("currentfps") + ": %.3f ms/frame (%.1f FPS)";
196192 ImGui::Text(fmt.c_str(), 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
197193
198194 ImGui::SameLine();
195+ ImGui::Text(" | ");
196+ ImGui::SameLine();
197+
199198 char timeBuf[64];
200199 time_t now = time(nullptr);
201200 tm *local = localtime(&now);
202- strftime(timeBuf, sizeof(timeBuf), glfw.i18n->GetWord("dateformat").c_str(), local);
203- ImGui::Text(" | %s", timeBuf);
201+
202+ strftime(timeBuf, sizeof(timeBuf), "%Y/%m/%d %H:%M:%S", local);
203+ ImGui::Text("%s", timeBuf);
204204
205205 ImGui::EndMainMenuBar();
206206 }
@@ -37,6 +37,7 @@
3737 #include <glad/glad.h>
3838 #include <gui/viewport.hh>
3939 #include <imgui.h>
40+#include <database/locale.hh>
4041
4142 namespace gui {
4243 void ViewPort::Init() {
@@ -39,16 +39,16 @@
3939 #include <shader/shader.hh>
4040 #include <glfw/glfw3.h>
4141 #include <util/glfwpp.hh>
42-#include <gui/consolelog.hh>
4342 #include <util/vector.hh>
4443 #include <util/random.hh>
44+#include <database/locale.hh>
45+#include <gui/consolelog.hh>
4546
4647 namespace lua {
47- LuaEngine::LuaEngine(const string &code, Program *prog, GlfwInfo *glfwInfo, gui::ConsoleLog *cmd)
48+ LuaEngine::LuaEngine(const string &code, Program *prog, GlfwInfo *glfwInfo)
4849 : m_Code(code)
4950 , m_Program(prog)
5051 , m_GlfwInfo(glfwInfo)
51- , m_Console(cmd)
5252 {
5353 m_Lua = MakeAPI();
5454 Execute(m_Lua);
@@ -105,16 +105,16 @@
105105 gui::LogEntry entry = {};
106106 entry.type = gui::LogType::Error;
107107 entry.text = err.what();
108- if (m_Console) m_Console->Add(entry);
109- else std::cerr << err.what() << std::endl;
108+ m_GlfwInfo->cmd->Add(entry);
109+ std::cerr << err.what() << std::endl;
110110 }
111111
112112 void LuaEngine::LogError(const std::exception &err) {
113113 gui::LogEntry entry = {};
114114 entry.type = gui::LogType::Error;
115115 entry.text = err.what();
116- if (m_Console) m_Console->Add(entry);
117- else std::cerr << err.what() << std::endl;
116+ m_GlfwInfo->cmd->Add(entry);
117+ std::cerr << err.what() << std::endl;
118118 }
119119
120120 sol::state LuaEngine::MakeAPI() {
@@ -402,8 +402,8 @@
402402 gui::LogEntry entry = {};
403403 entry.type = gui::LogType::Normal;
404404 entry.text = out;
405- if (m_Console) m_Console->Add(entry);
406- else std::cerr << entry.text << std::endl;
405+ m_GlfwInfo->cmd->Add(entry); (entry);
406+ std::cerr << entry.text << std::endl;
407407 };
408408 }
409409