タイトルバーからテキスト編集可能に
守矢諏訪子 <suwako@076.moe>、2026-06-28 22:50
コミット 7e5b0dd0dde2457551a89e97153e0bcb5fe63b59
・親 0133274
・ファイルを見る
5個のファイル、+52 -14
| @@ -37,12 +37,15 @@ | ||
| 37 | 37 | #pragma once |
| 38 | 38 | |
| 39 | 39 | #include <util/types.hh> |
| 40 | +#include <util/structs.hh> | |
| 40 | 41 | |
| 41 | 42 | #include <imgui.h> |
| 42 | 43 | #include <TextEditor.h> |
| 43 | 44 | |
| 44 | 45 | namespace gui { |
| 45 | 46 | enum Languages { |
| 47 | + C, | |
| 48 | + Cs, | |
| 46 | 49 | Glsl, |
| 47 | 50 | Hlsl, |
| 48 | 51 | Lua, |
| @@ -50,7 +53,7 @@ | ||
| 50 | 53 | |
| 51 | 54 | class Editor { |
| 52 | 55 | 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); | |
| 54 | 57 | ~Editor(); |
| 55 | 58 | |
| 56 | 59 | TextEditor &Get() { return m_Editor; } |
| @@ -65,6 +68,7 @@ | ||
| 65 | 68 | void SetTitle(const string &title) { m_Title = title; } |
| 66 | 69 | |
| 67 | 70 | private: |
| 71 | + Info *m_Info; | |
| 68 | 72 | TextEditor m_Editor; |
| 69 | 73 | ImFont *m_CjkFont; |
| 70 | 74 | ImFont *m_MonoFont; |
| @@ -43,6 +43,7 @@ | ||
| 43 | 43 | #include <string> |
| 44 | 44 | #include <cstdint> |
| 45 | 45 | #include <database/shaderdata.hh> |
| 46 | +#include <TextEditor.h> | |
| 46 | 47 | |
| 47 | 48 | namespace gui { |
| 48 | 49 | class ConsoleLog; |
| @@ -67,6 +68,7 @@ | ||
| 67 | 68 | bool showOpenShaderPopup = false; |
| 68 | 69 | bool showSaveAsShaderPopup = false; |
| 69 | 70 | bool viewportFocused = false; |
| 71 | + bool editorFocused = false; | |
| 70 | 72 | bool pendingCompile = false; |
| 71 | 73 | |
| 72 | 74 | std::string version = version::full; |
| @@ -77,6 +79,8 @@ | ||
| 77 | 79 | db::CodeData LUA = {}; |
| 78 | 80 | std::string currentFile = ""; |
| 79 | 81 | Vector4 sceneClearColor = {}; |
| 82 | + vector<TextEditor *> textEditors; | |
| 83 | + TextEditor *activeEditor; | |
| 80 | 84 | |
| 81 | 85 | gui::ConsoleLog *cmd; |
| 82 | 86 | db::Locale *i18n; |
変更
main.cc
| @@ -194,13 +194,16 @@ | ||
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | 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()); | |
| 198 | 199 | |
| 199 | 200 | 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()); | |
| 201 | 203 | |
| 202 | 204 | 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()); | |
| 204 | 207 | |
| 205 | 208 | // シェーダーをコンパイル |
| 206 | 209 | Shader vertexShader(info.VERT.code, GL_VERTEX_SHADER); |
| @@ -37,7 +37,9 @@ | ||
| 37 | 37 | #include <gui/editor.hh> |
| 38 | 38 | |
| 39 | 39 | 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); | |
| 41 | 43 | m_CjkFont = cjkFont; |
| 42 | 44 | m_MonoFont = monoFont; |
| 43 | 45 | m_Title = title; |
| @@ -51,12 +53,15 @@ | ||
| 51 | 53 | } else if (lang == Hlsl) { |
| 52 | 54 | // 現在未対応 |
| 53 | 55 | 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()); | |
| 54 | 62 | } else if (lang == Lua) { |
| 55 | 63 | m_Editor.SetLanguage(TextEditor::Language::Lua()); |
| 56 | 64 | } |
| 57 | - | |
| 58 | - //m_Editor.SetTabSize(2); | |
| 59 | - //m_Editor.SetInsertSpacesOnTabs(true); | |
| 60 | 65 | } |
| 61 | 66 | |
| 62 | 67 | Editor::~Editor() {} |
| @@ -68,6 +73,11 @@ | ||
| 68 | 73 | |
| 69 | 74 | ImGui::PushFont(m_MonoFont); |
| 70 | 75 | m_Editor.Render(m_RenderName.c_str()); |
| 76 | + | |
| 77 | + if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) { | |
| 78 | + m_Info->activeEditor = &m_Editor; | |
| 79 | + } | |
| 80 | + | |
| 71 | 81 | ImGui::PopFont(); |
| 72 | 82 | |
| 73 | 83 | // CTRL + D |
| @@ -156,13 +156,30 @@ | ||
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | 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 | + } | |
| 161 | 165 | 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 | + } | |
| 166 | 183 | ImGui::Separator(); |
| 167 | 184 | if (ImGui::MenuItem(info.i18n->GetWord("settings").c_str(), "Ctrl+,")) { |
| 168 | 185 | info.isSettings = true; |