シェーダーの開く

守矢諏訪子 <suwako@076.moe>、2026-06-28 04:55
コミット 203abc7755a14765124fc940760d108351079ed5 ・親 5bb9aad ・ファイルを見る

5個のファイル、+87 -9

@@ -63,9 +63,11 @@
6363 bool isLangChange = false;
6464
6565 bool showNewShaderPopup = false;
66+ bool showOpenShaderPopup = false;
6667 bool showSaveAsShaderPopup = false;
6768 bool viewportFocused = false;
6869 bool pendingCompile = false;
70+ bool closePopup = false;
6971
7072 std::string version = version::full;
7173 uint32_t shaderId = 0;
@@ -81,5 +83,6 @@
8183 std::function<void()> compile;
8284 std::function<void()> save;
8385 std::function<void()> create;
86+ std::function<void()> open;
8487 std::function<void()> saveAs;
8588 };
変更 main.cc
@@ -335,12 +335,7 @@
335335
336336 info.save = [&]() {
337337 if (info.shaderId == 0) {
338- gui::LogEntry entry;
339- entry.type = gui::LogType::Warning;
340- std::cout << entry.text << std::endl;
341- entry.text = "TODO: 保存ダイアログボックス関数は開発中・・・";
342- info.cmd->Add(entry);
343- std::cout << entry.text << std::endl;
338+ info.showSaveAsShaderPopup = true;
344339 return;
345340 }
346341
@@ -391,6 +386,64 @@
391386 }
392387 };
393388
389+ info.open = [&]() {
390+ static i32 selectedId = -1;
391+ ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
392+ if (ImGui::BeginPopupModal(info.i18n->GetWord("fileopenshader").c_str(), nullptr)) {
393+ vector <db::ShaderData > shdrs = db::GetAllShaders(db);
394+ ImGui::BeginChild("ShaderList", ImVec2(0, 300), true);
395+
396+ for (const auto &s : shdrs) {
397+ bool sel = (selectedId == s.id);
398+
399+ if (ImGui::Selectable(s.name.c_str(), sel)) {
400+ selectedId = s.id;
401+ }
402+ }
403+
404+ ImGui::EndChild();
405+ ImGui::Separator();
406+
407+ if (ImGui::Button(info.i18n->GetWord("cancel").c_str())) {
408+ ImGui::CloseCurrentPopup();
409+ }
410+
411+ ImGui::SameLine();
412+
413+ if (ImGui::Button(info.i18n->GetWord("fileopen").c_str())) {
414+ if (selectedId != -1) {
415+ db::ShaderData shaderData = db::GetShader(db, selectedId);
416+ info.shaderId = shaderData.id;
417+ info.shaderName = shaderData.name;
418+ info.VERT = shaderData.vertexShader;
419+ info.FRAG = shaderData.fragmentShader;
420+ info.LUA = shaderData.luaCode;
421+
422+ vertEditor.SetCode(info.VERT.code);
423+ fragEditor.SetCode(info.FRAG.code);
424+ luaEditor.SetCode(info.LUA.code);
425+
426+ vertEditor.SetCode(info.VERT.code);
427+ string nTit = info.shaderName + "(" + info.i18n->GetWord("editorvertshader") + ")";
428+ vertEditor.SetTitle(nTit + "###VertexEditor");
429+
430+ fragEditor.SetCode(info.FRAG.code);
431+ nTit = info.shaderName + "(" + info.i18n->GetWord("editorfragshader") + ")";
432+ fragEditor.SetTitle(nTit + "###FragmentEditor");
433+
434+ luaEditor.SetCode(info.LUA.code);
435+ nTit = info.shaderName + "(" + info.i18n->GetWord("editorlua") + ")";
436+ luaEditor.SetTitle(nTit + "###LuaEditor");
437+
438+ info.pendingCompile = true;
439+ }
440+ ImGui::CloseCurrentPopup();
441+ }
442+
443+ ImGui::EndPopup();
444+ }
445+ };
446+
394447 info.saveAs = [&]() {
395448 if (ImGui::BeginPopupModal(info.i18n->GetWord("filesaveasshader").c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
396449 ImGui::Text(info.i18n->GetWord("fileshadername").c_str());
@@ -539,6 +592,8 @@
539592 bool isManualKey = window.GetKey(GLFW_KEY_F1);
540593 bool isCompileKey = window.GetKey(GLFW_KEY_F5);
541594
595+ bool isEscKey = window.GetKey(GLFW_KEY_ESCAPE);
596+
542597 bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS);
543598 bool shiftMod = (window.GetKey(GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS);
544599 //bool altMod = (window.GetKey(GLFW_KEY_LEFT_ALT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_ALT) == GLFW_PRESS);
@@ -560,7 +615,9 @@
560615 info.showNewShaderPopup = true;
561616 }
562617
563- if (isOpenKey) {}
618+ if (isOpenKey) {
619+ info.showOpenShaderPopup = true;
620+ }
564621
565622 if (isSaveAsKey) {
566623 info.showSaveAsShaderPopup = true;
@@ -571,6 +628,10 @@
571628 else info.save();
572629 }
573630
631+ if (isEscKey) {
632+ info.closePopup = true;
633+ }
634+
574635 if (isManualKey) {
575636 info.isManual = true;
576637 }
@@ -619,12 +680,18 @@
619680 info.showSaveAsShaderPopup = false;
620681 }
621682
683+ if (info.showOpenShaderPopup) {
684+ ImGui::OpenPopup(info.i18n->GetWord("fileopenshader").c_str());
685+ info.showOpenShaderPopup = false;
686+ }
687+
622688 if (info.showNewShaderPopup) {
623689 ImGui::OpenPopup(info.i18n->GetWord("filenewcreateshader").c_str());
624690 info.showNewShaderPopup = false;
625691 }
626692
627693 info.create();
694+ info.open();
628695 info.saveAs();
629696 info.compile();
630697
@@ -190,6 +190,8 @@
190190 createWord(db, 2, "filenewsceneshader", "Scene Shader");
191191 createWord(db, 1, "fileopen", "開く(O)...");
192192 createWord(db, 2, "fileopen", "Open...");
193+ createWord(db, 1, "fileopenshader", "シェーダーの開く");
194+ createWord(db, 2, "fileopenshader", "Open Shader");
193195 createWord(db, 1, "filesave", "保存(S)");
194196 createWord(db, 2, "filesave", "Save");
195197 createWord(db, 1, "filesaveas", "名前を付けて保存(A)...");
@@ -46,6 +46,7 @@
4646
4747 ImGui::SetNextWindowSize({ 600, 700 }, ImGuiCond_Appearing);
4848 ImGui::Begin(info.i18n->GetWord("helpmanual").c_str(), &info.isManual, flags);
49+ //if (info.closePopup) ImGui::CloseW
4950
5051 if (ImGui::BeginTabBar("ManualTabs")) {
5152 if (ImGui::BeginTabItem(info.i18n->GetWord("helpmanualoverview").c_str())) {
@@ -125,9 +125,11 @@
125125 if (ImGui::BeginMainMenuBar()) {
126126 if (ImGui::BeginMenu(info.i18n->GetWord("file").c_str())) {
127127 if (ImGui::MenuItem(info.i18n->GetWord("filenew").c_str(), "CTRL+N")) {
128- info.create();
128+ info.showNewShaderPopup = true;
129129 }
130- if (ImGui::MenuItem(info.i18n->GetWord("fileopen").c_str(), "Ctrl+O", false, false)) {}
130+ if (ImGui::MenuItem(info.i18n->GetWord("fileopen").c_str(), "Ctrl+O")) {
131+ info.showOpenShaderPopup = true;
132+ }
131133 //if (ImGui::BeginMenu("最近使った物")) {
132134 // ImGui::MenuItem("fish_hat.c");
133135 // ImGui::MenuItem("fish_hat.inl");
@@ -141,6 +143,9 @@
141143 //}
142144 if (ImGui::MenuItem(info.i18n->GetWord("filesave").c_str(), "Ctrl+S")) {
143145 info.save();
146+ }
147+ if (ImGui::MenuItem(info.i18n->GetWord("filesaveas").c_str(), "Ctrl+Shift+S")) {
148+ info.showSaveAsShaderPopup = true;
144149 }
145150
146151 ImGui::Separator();