Shader Playgroundについてウィンドウ、レイアウト、ビューポート
守矢諏訪子 <suwako@076.moe>、2026-06-26 04:37
コミット a28100b5241912838d1e68efc64a34866cc2ab48
・親 d917edd
・ファイルを見る
17個のファイル、+422 -105
バイナリファイル
バイナリファイル
| @@ -0,0 +1,11 @@ | ||
| 1 | +#pragma once | |
| 2 | + | |
| 3 | +#include <util/types.hh> | |
| 4 | +#include <util/structs.hh> | |
| 5 | + | |
| 6 | +namespace gui { | |
| 7 | + class About { | |
| 8 | + public: | |
| 9 | + void Draw(GlfwInfo &glfw); | |
| 10 | + }; // class About | |
| 11 | +} // namespace gui |
| @@ -0,0 +1,6 @@ | ||
| 1 | +#pragma once | |
| 2 | + | |
| 3 | +#include <util/types.hh> | |
| 4 | + | |
| 5 | +namespace gui { | |
| 6 | +} // namespace gui |
| @@ -0,0 +1,6 @@ | ||
| 1 | +#pragma once | |
| 2 | + | |
| 3 | +#include <util/types.hh> | |
| 4 | + | |
| 5 | +namespace gui { | |
| 6 | +} // namespace gui |
削除
include/gui/view.hh
| @@ -1,40 +0,0 @@ | ||
| 1 | -/* | |
| 2 | -Copyright (c) テクニカル諏訪子 | |
| 3 | - | |
| 4 | -Permission is hereby granted to any person obtaining a copy of the software | |
| 5 | -Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 6 | -sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 7 | - | |
| 8 | - 1. **Origin Attribution**: | |
| 9 | - - You must not misrepresent the origin of the Software; you must not claim | |
| 10 | - you created the original Software. | |
| 11 | - - If the Software is used in a product, you must either: | |
| 12 | - a. Provide clear attribution in the product's documentation, user interface, | |
| 13 | - or other visible areas, **OR** | |
| 14 | - b. Pay the original developers a fee they specify in writing. | |
| 15 | - 2. **Usage Restriction**: | |
| 16 | - - The Software, or any derivative works, dependencies, or libraries | |
| 17 | - incorporating it, must not be used for censorship or to suppress freedom of | |
| 18 | - speech, expression, or creativity. Prohibited uses include, but are not | |
| 19 | - limited to: | |
| 20 | - - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 21 | - ideas, or objective reality. | |
| 22 | - - Tools or systems designed to restrict access to information or | |
| 23 | - artistic works. | |
| 24 | - 3. **Notice Preservation**: | |
| 25 | - - This license and the above copyright notice must remain intact in all copies | |
| 26 | - of the source code. | |
| 27 | - | |
| 28 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 29 | -INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 30 | -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 31 | -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 32 | -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 33 | -OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 34 | -*/ | |
| 35 | -#pragma once | |
| 36 | - | |
| 37 | -#include <util/types.hh> | |
| 38 | - | |
| 39 | -namespace gui { | |
| 40 | -} // namespace gui |
| @@ -0,0 +1,60 @@ | ||
| 1 | +/* | |
| 2 | +Copyright (c) テクニカル諏訪子 | |
| 3 | + | |
| 4 | +Permission is hereby granted to any person obtaining a copy of the software | |
| 5 | +Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 6 | +sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 7 | + | |
| 8 | + 1. **Origin Attribution**: | |
| 9 | + - You must not misrepresent the origin of the Software; you must not claim | |
| 10 | + you created the original Software. | |
| 11 | + - If the Software is used in a product, you must either: | |
| 12 | + a. Provide clear attribution in the product's documentation, user interface, | |
| 13 | + or other visible areas, **OR** | |
| 14 | + b. Pay the original developers a fee they specify in writing. | |
| 15 | + 2. **Usage Restriction**: | |
| 16 | + - The Software, or any derivative works, dependencies, or libraries | |
| 17 | + incorporating it, must not be used for censorship or to suppress freedom of | |
| 18 | + speech, expression, or creativity. Prohibited uses include, but are not | |
| 19 | + limited to: | |
| 20 | + - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 21 | + ideas, or objective reality. | |
| 22 | + - Tools or systems designed to restrict access to information or | |
| 23 | + artistic works. | |
| 24 | + 3. **Notice Preservation**: | |
| 25 | + - This license and the above copyright notice must remain intact in all copies | |
| 26 | + of the source code. | |
| 27 | + | |
| 28 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 29 | +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 30 | +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 31 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 32 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 33 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 34 | +*/ | |
| 35 | +#pragma once | |
| 36 | + | |
| 37 | +#include <util/types.hh> | |
| 38 | +#include <util/structs.hh> | |
| 39 | + | |
| 40 | +namespace gui { | |
| 41 | + class ViewPort { | |
| 42 | + public: | |
| 43 | + void Init(); | |
| 44 | + void Resize(i32 width, i32 height); | |
| 45 | + void Draw(GlfwInfo &glfw); | |
| 46 | + | |
| 47 | + u32 GetFBO() const { return m_FBO; } | |
| 48 | + u32 GetTexture() const { return m_Texture; } | |
| 49 | + i32 GetWidth() const { return m_Width; } | |
| 50 | + i32 GetHeight() const { return m_Height; } | |
| 51 | + | |
| 52 | + private: | |
| 53 | + u32 m_FBO = 0; | |
| 54 | + u32 m_Texture = 0; | |
| 55 | + u32 m_RBO = 0; | |
| 56 | + | |
| 57 | + i32 m_Width = 1280; | |
| 58 | + i32 m_Height = 720; | |
| 59 | + }; // class View | |
| 60 | +} // namespace gui |
| @@ -35,12 +35,19 @@ | ||
| 35 | 35 | #pragma once |
| 36 | 36 | |
| 37 | 37 | #include <util/glfwpp.hh> |
| 38 | +#include <version.hh> | |
| 38 | 39 | #include <functional> |
| 40 | +#include <string> | |
| 39 | 41 | |
| 40 | 42 | struct GlfwInfo { |
| 41 | 43 | glfwpp::Instance *instance; |
| 42 | 44 | glfwpp::Window *window; |
| 45 | + | |
| 43 | 46 | bool isRunning = true; |
| 47 | + bool isAbout = false; | |
| 48 | + | |
| 49 | + std::string version = version::full; | |
| 50 | + | |
| 44 | 51 | std::function<void()> compile; |
| 45 | 52 | std::function<void()> save; |
| 46 | 53 | }; |
変更
main.cc
| @@ -48,6 +48,8 @@ | ||
| 48 | 48 | #include <gui/guiengine.hh> |
| 49 | 49 | #include <gui/titlebar.hh> |
| 50 | 50 | #include <gui/editor.hh> |
| 51 | +#include <gui/viewport.hh> | |
| 52 | +#include <gui/about.hh> | |
| 51 | 53 | #include <gui/consolelog.hh> |
| 52 | 54 | |
| 53 | 55 | #include <imgui.h> |
| @@ -77,7 +79,7 @@ | ||
| 77 | 79 | window.MakeContextCurrent(); |
| 78 | 80 | glfw.SwapInterval(1); |
| 79 | 81 | |
| 80 | - GlfwInfo glfwInfo = { &glfw, &window, true }; | |
| 82 | + GlfwInfo glfwInfo = { &glfw, &window, true, false }; | |
| 81 | 83 | |
| 82 | 84 | #ifndef PRODUCTION_BUILD |
| 83 | 85 | bool showDemo = true; |
| @@ -97,11 +99,20 @@ | ||
| 97 | 99 | |
| 98 | 100 | // データベースが未だ存在しなければ、初期設定 |
| 99 | 101 | sqlite::Instance db; |
| 100 | - db::Initialize(db); | |
| 102 | + try { | |
| 103 | + db::Initialize(db); | |
| 104 | + } catch (const std::exception &e) { | |
| 105 | + std::cerr << e.what() << std::endl; | |
| 106 | + return -1; | |
| 107 | + } | |
| 101 | 108 | |
| 102 | 109 | // コンソール |
| 103 | 110 | gui::ConsoleLog cmd; |
| 104 | 111 | |
| 112 | + // ビューポート | |
| 113 | + gui::ViewPort viewport; | |
| 114 | + viewport.Init(); | |
| 115 | + | |
| 105 | 116 | // データベースからシェーダーとLuaコードの受け取り |
| 106 | 117 | vector<db::ShaderData> codeMap = db::GetAllShaders(db); |
| 107 | 118 | u32 shaderId; |
| @@ -119,13 +130,13 @@ | ||
| 119 | 130 | } |
| 120 | 131 | |
| 121 | 132 | string title = shaderName + "(頂点シェーダー)"; |
| 122 | - gui::Editor vertEditor(title, "VertexEditor", VERT.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 133 | + gui::Editor vertEditor((title + "###VertexEditor").c_str(), "VertexEditor", VERT.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 123 | 134 | |
| 124 | 135 | title = shaderName + "(フラグメントシェーダー)"; |
| 125 | - gui::Editor fragEditor(title, "FragmentEditor", FRAG.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 136 | + gui::Editor fragEditor((title + "###FragmentEditor").c_str(), "FragmentEditor", FRAG.code, gui::Glsl, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 126 | 137 | |
| 127 | 138 | title = shaderName + "(Luaエディター)"; |
| 128 | - gui::Editor luaEditor(title, "LuaEditor", LUA.code, gui::Lua, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 139 | + gui::Editor luaEditor((title + "###LuaEditor").c_str(), "LuaEditor", LUA.code, gui::Lua, ge.GetCjkFont(), ge.GetMonoFont()); | |
| 129 | 140 | |
| 130 | 141 | // シェーダーをコンパイル |
| 131 | 142 | Shader vertexShader(VERT.code, GL_VERTEX_SHADER); |
| @@ -155,6 +166,7 @@ | ||
| 155 | 166 | } |
| 156 | 167 | |
| 157 | 168 | bool isHold = false; |
| 169 | + gui::About about; | |
| 158 | 170 | |
| 159 | 171 | // メインレンダリングループ |
| 160 | 172 | while (!window.ShouldClose() && glfwInfo.isRunning) { |
| @@ -267,12 +279,17 @@ | ||
| 267 | 279 | bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS); |
| 268 | 280 | bool isSaveKey = (window.GetKey(GLFW_KEY_S) == GLFW_PRESS && ctrlMod); |
| 269 | 281 | bool isQuitKey = (window.GetKey(GLFW_KEY_Q) == GLFW_PRESS && ctrlMod); |
| 282 | + bool isAboutKey = (window.GetKey(GLFW_KEY_H) == GLFW_PRESS && ctrlMod); | |
| 270 | 283 | |
| 271 | 284 | if (!isHold) { |
| 272 | 285 | if (isCompileKey) { |
| 273 | 286 | glfwInfo.compile(); |
| 274 | 287 | } |
| 275 | 288 | |
| 289 | + if (isAboutKey) { | |
| 290 | + glfwInfo.isAbout = true; | |
| 291 | + } | |
| 292 | + | |
| 276 | 293 | if (isSaveKey) { |
| 277 | 294 | glfwInfo.save(); |
| 278 | 295 | } |
| @@ -282,7 +299,7 @@ | ||
| 282 | 299 | } |
| 283 | 300 | } |
| 284 | 301 | |
| 285 | - isHold = isSaveKey || isCompileKey; | |
| 302 | + isHold = isSaveKey || isCompileKey || isAboutKey || isQuitKey; | |
| 286 | 303 | |
| 287 | 304 | if (window.GetAttrib(glfwpp::Attributes::Iconified) != 0) { |
| 288 | 305 | ImGui_ImplGlfw_Sleep(10); |
| @@ -299,30 +316,15 @@ | ||
| 299 | 316 | fragEditor.Render(); |
| 300 | 317 | luaEditor.Render(); |
| 301 | 318 | cmd.Draw(); |
| 319 | + about.Draw(glfwInfo); | |
| 302 | 320 | |
| 303 | - { | |
| 304 | - static float f = 0.0f; | |
| 305 | - static int counter = 0; | |
| 321 | + viewport.Draw(glfwInfo); | |
| 306 | 322 | |
| 307 | - ImGui::Begin("コントロール"); | |
| 308 | - | |
| 309 | - if (ImGui::Button("コンパイル(F5)")) { | |
| 310 | - glfwInfo.compile(); | |
| 311 | - } | |
| 312 | - | |
| 313 | - ImGui::SameLine(); | |
| 314 | - | |
| 315 | - if (ImGui::Button("保存(CTRL + S)")) { | |
| 316 | - glfwInfo.save(); | |
| 317 | - } | |
| 318 | - | |
| 319 | - ImGui::Text("現在フレームレート: %.3f ms/frame (%.1f FPS)", 1000.0f / ge.GetIO().Framerate, ge.GetIO().Framerate); | |
| 320 | - ImGui::End(); | |
| 321 | - } | |
| 322 | - | |
| 323 | 323 | ImGui::Render(); |
| 324 | 324 | |
| 325 | 325 | // 画面をクリア |
| 326 | + glBindFramebuffer(GL_FRAMEBUFFER, viewport.GetFBO()); | |
| 327 | + glViewport(0, 0, viewport.GetWidth(), viewport.GetHeight()); | |
| 326 | 328 | shaderProgram.ClearColor(0.f, 0.f, 0.f, 1.f); |
| 327 | 329 | shaderProgram.Clear(); |
| 328 | 330 | |
| @@ -333,9 +335,19 @@ | ||
| 333 | 335 | // クアッドを描画 |
| 334 | 336 | VAO.BindVertexArray(); |
| 335 | 337 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); |
| 338 | + glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| 336 | 339 | |
| 337 | 340 | // バッファをスワップし、イベントを処理 |
| 338 | 341 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); |
| 342 | + if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { | |
| 343 | + GLFWwindow *backup_current_context = glfwGetCurrentContext(); | |
| 344 | + | |
| 345 | + ImGui::UpdatePlatformWindows(); | |
| 346 | + ImGui::RenderPlatformWindowsDefault(); | |
| 347 | + | |
| 348 | + glfwMakeContextCurrent(backup_current_context); | |
| 349 | + } | |
| 350 | + | |
| 339 | 351 | window.SwapBuffers(); |
| 340 | 352 | } |
| 341 | 353 |
| @@ -0,0 +1,70 @@ | ||
| 1 | +/* | |
| 2 | +Copyright (c) テクニカル諏訪子 | |
| 3 | + | |
| 4 | +Permission is hereby granted to any person obtaining a copy of the software | |
| 5 | +Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 6 | +sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 7 | + | |
| 8 | + 1. **Origin Attribution**: | |
| 9 | + - You must not misrepresent the origin of the Software; you must not claim | |
| 10 | + you created the original Software. | |
| 11 | + - If the Software is used in a product, you must either: | |
| 12 | + a. Provide clear attribution in the product's documentation, user interface, | |
| 13 | + or other visible areas, **OR** | |
| 14 | + b. Pay the original developers a fee they specify in writing. | |
| 15 | + 2. **Usage Restriction**: | |
| 16 | + - The Software, or any derivative works, dependencies, or libraries | |
| 17 | + incorporating it, must not be used for censorship or to suppress freedom of | |
| 18 | + speech, expression, or creativity. Prohibited uses include, but are not | |
| 19 | + limited to: | |
| 20 | + - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 21 | + ideas, or objective reality. | |
| 22 | + - Tools or systems designed to restrict access to information or | |
| 23 | + artistic works. | |
| 24 | + 3. **Notice Preservation**: | |
| 25 | + - This license and the above copyright notice must remain intact in all copies | |
| 26 | + of the source code. | |
| 27 | + | |
| 28 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 29 | +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 30 | +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 31 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 32 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 33 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 34 | +*/ | |
| 35 | +#include <gui/about.hh> | |
| 36 | +#include <imgui.h> | |
| 37 | + | |
| 38 | +namespace gui { | |
| 39 | + void About::Draw(GlfwInfo &glfw) { | |
| 40 | + if (!glfw.isAbout) return; | |
| 41 | + | |
| 42 | + ImGuiWindowFlags flags = 0; | |
| 43 | + ImGui::SetNextWindowSize({800, 600}, ImGuiCond_FirstUseEver); | |
| 44 | + ImGui::Begin("Shader Playgroundについて", &glfw.isAbout, flags); | |
| 45 | + string name = "Shader Playground " + glfw.version; | |
| 46 | + string copyright = "© 2026 - 076スタジオ合同会社"; | |
| 47 | + string developer = "開発者:テクニカル諏訪子"; | |
| 48 | + | |
| 49 | + ImGui::SetWindowFontScale(1.8f); | |
| 50 | + ImGui::Text(name.c_str()); | |
| 51 | + ImGui::SetWindowFontScale(1.2f); | |
| 52 | + ImGui::Separator(); | |
| 53 | + ImGui::Text(copyright.c_str()); | |
| 54 | + ImGui::Text(developer.c_str()); | |
| 55 | + | |
| 56 | + f32 btnW = 80.f; | |
| 57 | + f32 btnH = 0.f; | |
| 58 | + | |
| 59 | + ImVec2 winSize = ImGui::GetWindowSize(); | |
| 60 | + ImVec2 cursorPos = ImGui::GetCursorPos(); | |
| 61 | + | |
| 62 | + ImGui::SetCursorPos({ | |
| 63 | + (winSize.x - btnW) * .5f, | |
| 64 | + winSize.y - 40.f | |
| 65 | + }); | |
| 66 | + | |
| 67 | + if (ImGui::Button("OK", { btnW, btnH })) glfw.isAbout = false; | |
| 68 | + ImGui::End(); | |
| 69 | + } | |
| 70 | +} // namespace gui |
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | void ConsoleLog::Draw(cstr title) { |
| 44 | - ImGui::Begin(title); | |
| 44 | + ImGui::Begin((string(title) + "###Console").c_str()); | |
| 45 | 45 | if (ImGui::Button("消す")) Clear(); |
| 46 | 46 | ImGui::Separator(); |
| 47 | 47 | for (const auto &line : m_Lines) { |
| @@ -46,6 +46,8 @@ | ||
| 46 | 46 | m_MonoFont = io.Fonts->AddFontFromFileTTF("NotoMono-Regular.ttf", 16.f, nullptr, io.Fonts->GetGlyphRangesJapanese()); |
| 47 | 47 | io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; |
| 48 | 48 | io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; |
| 49 | + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; | |
| 50 | + io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; | |
| 49 | 51 | |
| 50 | 52 | ImGui::StyleColorsDark(); |
| 51 | 53 |
| @@ -0,0 +1,4 @@ | ||
| 1 | +#include <gui/manual.hh> | |
| 2 | + | |
| 3 | +namespace gui { | |
| 4 | +} // namespace gui |
| @@ -0,0 +1,4 @@ | ||
| 1 | +#include <gui/settings.hh> | |
| 2 | + | |
| 3 | +namespace gui { | |
| 4 | +} // namespace gui |
| @@ -33,10 +33,13 @@ | ||
| 33 | 33 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 34 | 34 | */ |
| 35 | 35 | #include <gui/titlebar.hh> |
| 36 | +#include <gui/about.hh> | |
| 36 | 37 | |
| 37 | 38 | #include <imgui.h> |
| 39 | +#include <imgui_internal.h> | |
| 38 | 40 | #include <backends/imgui_impl_glfw.h> |
| 39 | 41 | #include <backends/imgui_impl_opengl3.h> |
| 42 | +#include <ctime> | |
| 40 | 43 | |
| 41 | 44 | namespace gui { |
| 42 | 45 | void showTitleBar(GlfwInfo &glfw) { |
| @@ -44,6 +47,75 @@ | ||
| 44 | 47 | ImGui_ImplGlfw_NewFrame(); |
| 45 | 48 | ImGui::NewFrame(); |
| 46 | 49 | |
| 50 | + ImGuiWindowFlags window_flags = | |
| 51 | + ImGuiWindowFlags_MenuBar | | |
| 52 | + ImGuiWindowFlags_NoDocking; | |
| 53 | + | |
| 54 | + const ImGuiViewport *viewport = ImGui::GetMainViewport(); | |
| 55 | + ImGui::SetNextWindowPos(viewport->WorkPos); | |
| 56 | + ImGui::SetNextWindowSize(viewport->WorkSize); | |
| 57 | + ImGui::SetNextWindowViewport(viewport->ID); | |
| 58 | + | |
| 59 | + window_flags |= ImGuiWindowFlags_NoTitleBar; | |
| 60 | + window_flags |= ImGuiWindowFlags_NoCollapse; | |
| 61 | + window_flags |= ImGuiWindowFlags_NoResize; | |
| 62 | + window_flags |= ImGuiWindowFlags_NoMove; | |
| 63 | + window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus; | |
| 64 | + window_flags |= ImGuiWindowFlags_NoNavFocus; | |
| 65 | + | |
| 66 | + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); | |
| 67 | + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); | |
| 68 | + | |
| 69 | + ImGui::Begin("MainDockSpace", nullptr, window_flags); | |
| 70 | + | |
| 71 | + ImGui::PopStyleVar(2); | |
| 72 | + | |
| 73 | + ImGuiID dockspace_id = ImGui::GetID("DockSpace"); | |
| 74 | + ImGui::DockSpace(dockspace_id); | |
| 75 | + | |
| 76 | + static bool firstLayout = true; | |
| 77 | + if (firstLayout) { | |
| 78 | + firstLayout = false; | |
| 79 | + | |
| 80 | + ImGui::DockBuilderRemoveNode(dockspace_id); | |
| 81 | + ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace); | |
| 82 | + | |
| 83 | + const ImGuiViewport *viewport = ImGui::GetMainViewport(); | |
| 84 | + ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size); | |
| 85 | + | |
| 86 | + ImGuiID dock_main = dockspace_id; | |
| 87 | + ImGuiID dock_right = 0; | |
| 88 | + ImGuiID dock_bottom = 0; | |
| 89 | + | |
| 90 | + dock_bottom = ImGui::DockBuilderSplitNode( | |
| 91 | + dock_main, | |
| 92 | + ImGuiDir_Down, | |
| 93 | + 0.25f, | |
| 94 | + nullptr, | |
| 95 | + &dock_main | |
| 96 | + ); | |
| 97 | + | |
| 98 | + dock_right = ImGui::DockBuilderSplitNode( | |
| 99 | + dock_main, | |
| 100 | + ImGuiDir_Right, | |
| 101 | + 0.45f, | |
| 102 | + nullptr, | |
| 103 | + &dock_main | |
| 104 | + ); | |
| 105 | + | |
| 106 | + ImGui::DockBuilderDockWindow("View", dock_main); | |
| 107 | + | |
| 108 | + ImGui::DockBuilderDockWindow("VertexEditor", dock_right); | |
| 109 | + ImGui::DockBuilderDockWindow("FragmentEditor", dock_right); | |
| 110 | + ImGui::DockBuilderDockWindow("LuaEditor", dock_right); | |
| 111 | + | |
| 112 | + ImGui::DockBuilderDockWindow("Console", dock_bottom); | |
| 113 | + | |
| 114 | + ImGui::DockBuilderFinish(dockspace_id); | |
| 115 | + } | |
| 116 | + | |
| 117 | + ImGui::End(); | |
| 118 | + | |
| 47 | 119 | if (ImGui::BeginMainMenuBar()) { |
| 48 | 120 | if (ImGui::BeginMenu("ファイル")) { |
| 49 | 121 | if (ImGui::MenuItem("新しいファイル", "CTRL+N", false, false)) {} |
| @@ -92,7 +164,9 @@ | ||
| 92 | 164 | |
| 93 | 165 | if (ImGui::BeginMenu("ヘルプ")) { |
| 94 | 166 | if (ImGui::MenuItem("マニュアル", "F1")) {} |
| 95 | - if (ImGui::MenuItem("Shader Playgroundについて", "F12")) {} | |
| 167 | + if (ImGui::MenuItem("Shader Playgroundについて", "CTRL+H")) { | |
| 168 | + glfw.isAbout = true; | |
| 169 | + } | |
| 96 | 170 | ImGui::EndMenu(); |
| 97 | 171 | } |
| 98 | 172 | |
| @@ -101,6 +175,20 @@ | ||
| 101 | 175 | if (ImGui::MenuItem("English")) {} |
| 102 | 176 | ImGui::EndMenu(); |
| 103 | 177 | } |
| 178 | + | |
| 179 | + ImGui::SameLine(); | |
| 180 | + | |
| 181 | + f32 rightW = ImGui::GetContentRegionAvail().x; | |
| 182 | + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + rightW - 400.f); | |
| 183 | + ImGui::Text("現在フレームレート: %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); | |
| 184 | + | |
| 185 | + ImGui::SameLine(); | |
| 186 | + char timeBuf[64]; | |
| 187 | + time_t now = time(nullptr); | |
| 188 | + tm *local = localtime(&now); | |
| 189 | + strftime(timeBuf, sizeof(timeBuf), "%Y年%m月日%d日 %H:%M:%S", local); | |
| 190 | + ImGui::Text(" | %s", timeBuf); | |
| 191 | + | |
| 104 | 192 | ImGui::EndMainMenuBar(); |
| 105 | 193 | } |
| 106 | 194 | } |
削除
src/gui/view.cc
| @@ -1,38 +0,0 @@ | ||
| 1 | -/* | |
| 2 | -Copyright (c) テクニカル諏訪子 | |
| 3 | - | |
| 4 | -Permission is hereby granted to any person obtaining a copy of the software | |
| 5 | -Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 6 | -sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 7 | - | |
| 8 | - 1. **Origin Attribution**: | |
| 9 | - - You must not misrepresent the origin of the Software; you must not claim | |
| 10 | - you created the original Software. | |
| 11 | - - If the Software is used in a product, you must either: | |
| 12 | - a. Provide clear attribution in the product's documentation, user interface, | |
| 13 | - or other visible areas, **OR** | |
| 14 | - b. Pay the original developers a fee they specify in writing. | |
| 15 | - 2. **Usage Restriction**: | |
| 16 | - - The Software, or any derivative works, dependencies, or libraries | |
| 17 | - incorporating it, must not be used for censorship or to suppress freedom of | |
| 18 | - speech, expression, or creativity. Prohibited uses include, but are not | |
| 19 | - limited to: | |
| 20 | - - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 21 | - ideas, or objective reality. | |
| 22 | - - Tools or systems designed to restrict access to information or | |
| 23 | - artistic works. | |
| 24 | - 3. **Notice Preservation**: | |
| 25 | - - This license and the above copyright notice must remain intact in all copies | |
| 26 | - of the source code. | |
| 27 | - | |
| 28 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 29 | -INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 30 | -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 31 | -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 32 | -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 33 | -OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 34 | -*/ | |
| 35 | -#include <gui/view.hh> | |
| 36 | - | |
| 37 | -namespace gui { | |
| 38 | -} // namespace gui |
| @@ -0,0 +1,125 @@ | ||
| 1 | +/* | |
| 2 | +Copyright (c) テクニカル諏訪子 | |
| 3 | + | |
| 4 | +Permission is hereby granted to any person obtaining a copy of the software | |
| 5 | +Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute, | |
| 6 | +sublicense, and/or sell copies of the Software, subject to the following conditions: | |
| 7 | + | |
| 8 | + 1. **Origin Attribution**: | |
| 9 | + - You must not misrepresent the origin of the Software; you must not claim | |
| 10 | + you created the original Software. | |
| 11 | + - If the Software is used in a product, you must either: | |
| 12 | + a. Provide clear attribution in the product's documentation, user interface, | |
| 13 | + or other visible areas, **OR** | |
| 14 | + b. Pay the original developers a fee they specify in writing. | |
| 15 | + 2. **Usage Restriction**: | |
| 16 | + - The Software, or any derivative works, dependencies, or libraries | |
| 17 | + incorporating it, must not be used for censorship or to suppress freedom of | |
| 18 | + speech, expression, or creativity. Prohibited uses include, but are not | |
| 19 | + limited to: | |
| 20 | + - Censorship of so-called "hate speech", visuals, non-mainstream opinions, | |
| 21 | + ideas, or objective reality. | |
| 22 | + - Tools or systems designed to restrict access to information or | |
| 23 | + artistic works. | |
| 24 | + 3. **Notice Preservation**: | |
| 25 | + - This license and the above copyright notice must remain intact in all copies | |
| 26 | + of the source code. | |
| 27 | + | |
| 28 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
| 29 | +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |
| 30 | +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 31 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 32 | +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
| 33 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 34 | +*/ | |
| 35 | +#include <glad/glad.h> | |
| 36 | +#include <gui/viewport.hh> | |
| 37 | +#include <imgui.h> | |
| 38 | + | |
| 39 | +namespace gui { | |
| 40 | + void ViewPort::Init() { | |
| 41 | + glGenFramebuffers(1, &m_FBO); | |
| 42 | + glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); | |
| 43 | + | |
| 44 | + glGenTextures(1, &m_Texture); | |
| 45 | + glBindTexture(GL_TEXTURE_2D, m_Texture); | |
| 46 | + glTexImage2D( | |
| 47 | + GL_TEXTURE_2D, | |
| 48 | + 0, | |
| 49 | + GL_RGB, | |
| 50 | + m_Width, | |
| 51 | + m_Height, | |
| 52 | + 0, | |
| 53 | + GL_RGB, | |
| 54 | + GL_UNSIGNED_BYTE, | |
| 55 | + nullptr | |
| 56 | + ); | |
| 57 | + | |
| 58 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 59 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
| 60 | + | |
| 61 | + glFramebufferTexture2D( | |
| 62 | + GL_FRAMEBUFFER, | |
| 63 | + GL_COLOR_ATTACHMENT0, | |
| 64 | + GL_TEXTURE_2D, | |
| 65 | + m_Texture, | |
| 66 | + 0 | |
| 67 | + ); | |
| 68 | + | |
| 69 | + glGenRenderbuffers(1, &m_RBO); | |
| 70 | + glBindRenderbuffer(GL_RENDERBUFFER, m_RBO); | |
| 71 | + glRenderbufferStorage( | |
| 72 | + GL_RENDERBUFFER, | |
| 73 | + GL_DEPTH24_STENCIL8, | |
| 74 | + m_Width, | |
| 75 | + m_Height | |
| 76 | + ); | |
| 77 | + | |
| 78 | + glFramebufferRenderbuffer( | |
| 79 | + GL_FRAMEBUFFER, | |
| 80 | + GL_DEPTH_STENCIL_ATTACHMENT, | |
| 81 | + GL_RENDERBUFFER, | |
| 82 | + m_RBO | |
| 83 | + ); | |
| 84 | + | |
| 85 | + glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| 86 | + } | |
| 87 | + | |
| 88 | + void ViewPort::Resize(i32 width, i32 height) { | |
| 89 | + m_Width = width; | |
| 90 | + m_Height = height; | |
| 91 | + | |
| 92 | + glBindTexture(GL_TEXTURE_2D, m_Texture); | |
| 93 | + glTexImage2D( | |
| 94 | + GL_TEXTURE_2D, | |
| 95 | + 0, | |
| 96 | + GL_RGB, | |
| 97 | + width, | |
| 98 | + height, | |
| 99 | + 0, | |
| 100 | + GL_RGB, | |
| 101 | + GL_UNSIGNED_BYTE, | |
| 102 | + nullptr | |
| 103 | + ); | |
| 104 | + | |
| 105 | + glBindRenderbuffer(GL_RENDERBUFFER, m_RBO); | |
| 106 | + glRenderbufferStorage( | |
| 107 | + GL_RENDERBUFFER, | |
| 108 | + GL_DEPTH24_STENCIL8, | |
| 109 | + width, | |
| 110 | + height | |
| 111 | + ); | |
| 112 | + } | |
| 113 | + | |
| 114 | + void ViewPort::Draw(GlfwInfo &glfw) { | |
| 115 | + ImGui::Begin("ビューポート###View"); | |
| 116 | + | |
| 117 | + ImVec2 avail = ImGui::GetContentRegionAvail(); | |
| 118 | + if ((i32)avail.x != m_Width || (i32)avail.y != m_Height) { | |
| 119 | + Resize((i32)avail.x, (i32)avail.y); | |
| 120 | + } | |
| 121 | + | |
| 122 | + ImGui::Image((ImTextureID)(intptr_t)m_Texture, avail, ImVec2(0, 1), ImVec2(1, 0)); | |
| 123 | + ImGui::End(); | |
| 124 | + } | |
| 125 | +} // namespace gui |