タイトルバーからテキスト編集可能に

守矢諏訪子 <suwako@076.moe>、2026-06-28 22:50
コミット 7e5b0dd0dde2457551a89e97153e0bcb5fe63b59 ・親 0133274 ・ファイルを見る

5個のファイル、+52 -14

@@ -37,12 +37,15 @@
3737 #pragma once
3838
3939 #include <util/types.hh>
40+#include <util/structs.hh>
4041
4142 #include <imgui.h>
4243 #include <TextEditor.h>
4344
4445 namespace gui {
4546 enum Languages {
47+ C,
48+ Cs,
4649 Glsl,
4750 Hlsl,
4851 Lua,
@@ -50,7 +53,7 @@
5053
5154 class Editor {
5255 public:
53- Editor(string title, string renderName, string code, Languages lang, ImFont *cjkFont, ImFont *monoFont);
56+ Editor(Info *info, string title, string renderName, string code, Languages lang, ImFont *cjkFont, ImFont *monoFont);
5457 ~Editor();
5558
5659 TextEditor &Get() { return m_Editor; }
@@ -65,6 +68,7 @@
6568 void SetTitle(const string &title) { m_Title = title; }
6669
6770 private:
71+ Info *m_Info;
6872 TextEditor m_Editor;
6973 ImFont *m_CjkFont;
7074 ImFont *m_MonoFont;
@@ -43,6 +43,7 @@
4343 #include <string>
4444 #include <cstdint>
4545 #include <database/shaderdata.hh>
46+#include <TextEditor.h>
4647
4748 namespace gui {
4849 class ConsoleLog;
@@ -67,6 +68,7 @@
6768 bool showOpenShaderPopup = false;
6869 bool showSaveAsShaderPopup = false;
6970 bool viewportFocused = false;
71+ bool editorFocused = false;
7072 bool pendingCompile = false;
7173
7274 std::string version = version::full;
@@ -77,6 +79,8 @@
7779 db::CodeData LUA = {};
7880 std::string currentFile = "";
7981 Vector4 sceneClearColor = {};
82+ vector<TextEditor *> textEditors;
83+ TextEditor *activeEditor;
8084
8185 gui::ConsoleLog *cmd;
8286 db::Locale *i18n;
変更 main.cc
@@ -194,13 +194,16 @@
194194 }
195195
196196 string title = info.shaderName + "(" + info.i18n->GetWord("editorvertshader") + ")";
197- gui::Editor vertEditor((title + "###VertexEditor").c_str(), "VertexEditor", info.VERT.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont());
197+ gui::Editor vertEditor(&info, (title + "###VertexEditor").c_str(), "VertexEditor", info.VERT.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont());
198+ info.textEditors.emplace_back(&vertEditor.Get());
198199
199200 title = info.shaderName + "(" + info.i18n->GetWord("editorfragshader") + ")";
200- gui::Editor fragEditor((title + "###FragmentEditor").c_str(), "FragmentEditor", info.FRAG.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont());
201+ gui::Editor fragEditor(&info, (title + "###FragmentEditor").c_str(), "FragmentEditor", info.FRAG.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont());
202+ info.textEditors.emplace_back(&fragEditor.Get());
201203
202204 title = info.shaderName + "(" + info.i18n->GetWord("editorlua") + ")";
203- gui::Editor luaEditor((title + "###LuaEditor").c_str(), "LuaEditor", info.LUA.code, gui::Lua, ge.GetCjkFont(), ge.GetMonoFont());
205+ gui::Editor luaEditor(&info, (title + "###LuaEditor").c_str(), "LuaEditor", info.LUA.code, gui::Lua, ge.GetCjkFont(), ge.GetMonoFont());
206+ info.textEditors.emplace_back(&luaEditor.Get());
204207
205208 // シェーダーをコンパイル
206209 Shader vertexShader(info.VERT.code, GL_VERTEX_SHADER);
@@ -37,7 +37,9 @@
3737 #include <gui/editor.hh>
3838
3939 namespace gui {
40- Editor::Editor(string title, string renderName, string code, Languages lang, ImFont *cjkFont, ImFont *monoFont) {
40+ Editor::Editor(Info *info, string title, string renderName, string code, Languages lang, ImFont *cjkFont, ImFont *monoFont) : m_Info(info) {
41+ m_Editor.SetTabSize(2);
42+ m_Editor.SetInsertSpacesOnTabs(true);
4143 m_CjkFont = cjkFont;
4244 m_MonoFont = monoFont;
4345 m_Title = title;
@@ -51,12 +53,15 @@
5153 } else if (lang == Hlsl) {
5254 // 現在未対応
5355 m_Editor.SetLanguage(TextEditor::Language::Hlsl());
56+ } else if (lang == C) {
57+ // 現在未対応
58+ m_Editor.SetLanguage(TextEditor::Language::C());
59+ } else if (lang == Cs) {
60+ // 現在未対応
61+ m_Editor.SetLanguage(TextEditor::Language::Cs());
5462 } else if (lang == Lua) {
5563 m_Editor.SetLanguage(TextEditor::Language::Lua());
5664 }
57-
58- //m_Editor.SetTabSize(2);
59- //m_Editor.SetInsertSpacesOnTabs(true);
6065 }
6166
6267 Editor::~Editor() {}
@@ -68,6 +73,11 @@
6873
6974 ImGui::PushFont(m_MonoFont);
7075 m_Editor.Render(m_RenderName.c_str());
76+
77+ if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) {
78+ m_Info->activeEditor = &m_Editor;
79+ }
80+
7181 ImGui::PopFont();
7282
7383 // CTRL + D
@@ -156,13 +156,30 @@
156156 }
157157
158158 if (ImGui::BeginMenu(info.i18n->GetWord("edit").c_str())) {
159- if (ImGui::MenuItem(info.i18n->GetWord("editundo").c_str(), "Ctrl+Z", false, false)) {}
160- if (ImGui::MenuItem(info.i18n->GetWord("editredo").c_str(), "Ctrl+Y", false, false)) {}
159+ if (ImGui::MenuItem(info.i18n->GetWord("editundo").c_str(), "Ctrl+Z", false, info.activeEditor && info.activeEditor->CanUndo())) {
160+ info.activeEditor->Undo();
161+ }
162+ if (ImGui::MenuItem(info.i18n->GetWord("editredo").c_str(), "Ctrl+Y", false, info.activeEditor && info.activeEditor->CanRedo())) {
163+ info.activeEditor->Redo();
164+ }
161165 ImGui::Separator();
162- if (ImGui::MenuItem(info.i18n->GetWord("editcut").c_str(), "Ctrl+X", false, false)) {}
163- if (ImGui::MenuItem(info.i18n->GetWord("editcopy").c_str(), "Ctrl+C", false, false)) {}
164- if (ImGui::MenuItem(info.i18n->GetWord("editpaste").c_str(), "Ctrl+V", false, false)) {}
165- if (ImGui::MenuItem(info.i18n->GetWord("editduplicate").c_str(), "Ctrl+D", false, false)) {}
166+ if (ImGui::MenuItem(info.i18n->GetWord("editcut").c_str(), "Ctrl+X", false, info.activeEditor)) {
167+ info.activeEditor->Cut();
168+ }
169+ if (ImGui::MenuItem(info.i18n->GetWord("editcopy").c_str(), "Ctrl+C", false, info.activeEditor)) {
170+ info.activeEditor->Copy();
171+ }
172+ if (ImGui::MenuItem(info.i18n->GetWord("editpaste").c_str(), "Ctrl+V", false, info.activeEditor)) {
173+ info.activeEditor->Paste();
174+ }
175+ if (ImGui::MenuItem(info.i18n->GetWord("editselectall").c_str(), "Ctrl+A", false, info.activeEditor)) {
176+ info.activeEditor->SelectAll();
177+ }
178+ if (ImGui::MenuItem(info.i18n->GetWord("editduplicate").c_str(), "Ctrl+D", false, info.activeEditor)) {
179+ //info.activeEditor->GetLineText(info.activeEditor->GetLineHeight());
180+ //info.activeEditor->Copy();
181+ //info.activeEditor->Paste();
182+ }
166183 ImGui::Separator();
167184 if (ImGui::MenuItem(info.i18n->GetWord("settings").c_str(), "Ctrl+,")) {
168185 info.isSettings = true;