master
ブランチ master
ShaderPlayground / src / gui / titlebar.cc
8.2 KB、231行 生 Blame 履歴
1/*
2# 076 License
3
4Copyright (c) 076 Studio LLC
5
6Permission is hereby granted to any person obtaining a copy of the software
7Shader Playground (the "Software") to use, modify, merge, copy, publish, distribute,
8sublicense, and/or sell copies of the Software, subject to the following conditions:
9
10 1. **Origin Attribution**:
11 - You must not misrepresent the origin of the Software; you must not claim
12 you created the original Software.
13 - If the Software is used in a product, you must either:
14 a. Provide clear attribution in the product's documentation, user interface,
15 or other visible areas, **OR**
16 b. Pay the original developers a fee they specify in writing.
17 2. **Usage Restriction**:
18 - The Software, or any derivative works, dependencies, or libraries
19 incorporating it, must not be used for censorship or to suppress freedom of
20 speech, expression, or creativity. Prohibited uses include, but are not
21 limited to:
22 - Censorship of so-called "hate speech", visuals, non-mainstream opinions,
23 ideas, or objective reality.
24 - Tools or systems designed to restrict access to information or
25 artistic works.
26 3. **Notice Preservation**:
27 - This license and the above copyright notice must remain intact in all copies
28 of the source code.
29
30THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
31INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
34CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
35OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36*/
37#include <gui/titlebar.hh>
38
39#include <imgui.h>
40#include <imgui_internal.h>
41#include <backends/imgui_impl_glfw.h>
42#include <backends/imgui_impl_opengl3.h>
43#include <database/locale.hh>
44//#include <gui/guiengine.hh>
45#include <ctime>
46
47namespace gui {
48 void showTitleBar(Info &info) {
49 ImGui_ImplOpenGL3_NewFrame();
50 ImGui_ImplGlfw_NewFrame();
51 ImGui::NewFrame();
52
53 ImGuiWindowFlags window_flags =
54 ImGuiWindowFlags_NoCollapse |
55 ImGuiWindowFlags_MenuBar |
56 ImGuiWindowFlags_NoDocking;
57
58 const ImGuiViewport *viewport = ImGui::GetMainViewport();
59 ImGui::SetNextWindowPos(viewport->WorkPos);
60 ImGui::SetNextWindowSize(viewport->WorkSize);
61 ImGui::SetNextWindowViewport(viewport->ID);
62
63 window_flags |= ImGuiWindowFlags_NoTitleBar;
64 window_flags |= ImGuiWindowFlags_NoCollapse;
65 window_flags |= ImGuiWindowFlags_NoResize;
66 window_flags |= ImGuiWindowFlags_NoMove;
67 window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus;
68 window_flags |= ImGuiWindowFlags_NoNavFocus;
69
70 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
71 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
72
73 ImGui::GetIO().ConfigDockingWithShift = true;
74 ImGui::GetStyle().WindowMenuButtonPosition = ImGuiDir_None;
75
76 ImGui::Begin("MainDockSpace", nullptr, window_flags);
77
78 ImGui::PopStyleVar(2);
79
80 ImGuiID dockspace_id = ImGui::GetID("DockSpace");
81 ImGui::DockSpace(dockspace_id);
82
83 static bool firstLayout = true;
84 if (firstLayout) {
85 firstLayout = false;
86
87 ImGui::DockBuilderRemoveNode(dockspace_id);
88 ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace);
89
90 const ImGuiViewport *viewport = ImGui::GetMainViewport();
91 ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size);
92
93 ImGuiID dock_main = dockspace_id;
94 ImGuiID dock_right = 0;
95 ImGuiID dock_bottom = 0;
96
97 dock_bottom = ImGui::DockBuilderSplitNode(
98 dock_main,
99 ImGuiDir_Down,
100 0.25f,
101 nullptr,
102 &dock_main
103 );
104
105 dock_right = ImGui::DockBuilderSplitNode(
106 dock_main,
107 ImGuiDir_Right,
108 0.35f,
109 nullptr,
110 &dock_main
111 );
112
113 ImGui::DockBuilderDockWindow("View", dock_main);
114
115 ImGui::DockBuilderDockWindow("VertexEditor", dock_right);
116 ImGui::DockBuilderDockWindow("FragmentEditor", dock_right);
117 ImGui::DockBuilderDockWindow("LuaEditor", dock_right);
118
119 ImGui::DockBuilderDockWindow("Console", dock_bottom);
120
121 ImGui::DockBuilderFinish(dockspace_id);
122 }
123
124 ImGui::End();
125
126 if (ImGui::BeginMainMenuBar()) {
127 if (ImGui::BeginMenu(info.i18n->GetWord("file").c_str())) {
128 if (ImGui::MenuItem(info.i18n->GetWord("filenew").c_str(), "CTRL+N")) {
129 info.showNewShaderPopup = true;
130 }
131 if (ImGui::MenuItem(info.i18n->GetWord("fileopen").c_str(), "Ctrl+O")) {
132 info.showOpenShaderPopup = true;
133 }
134 //if (ImGui::BeginMenu("最近使った物")) {
135 // ImGui::MenuItem("fish_hat.c");
136 // ImGui::MenuItem("fish_hat.inl");
137 // ImGui::MenuItem("fish_hat.h");
138 // if (ImGui::BeginMenu("もっと見る...")) {
139 // ImGui::MenuItem("Hello");
140 // ImGui::MenuItem("Sailor");
141 // ImGui::EndMenu();
142 // }
143 // ImGui::EndMenu();
144 //}
145 if (ImGui::MenuItem(info.i18n->GetWord("filesave").c_str(), "Ctrl+S")) {
146 info.save();
147 }
148 if (ImGui::MenuItem(info.i18n->GetWord("filesaveas").c_str(), "Ctrl+Shift+S")) {
149 info.showSaveAsShaderPopup = true;
150 }
151
152 ImGui::Separator();
153 if (ImGui::MenuItem(info.i18n->GetWord("quit").c_str(), "CTRL+Q")) {
154 info.isRunning = false;
155 }
156 ImGui::EndMenu();
157 }
158
159 if (ImGui::BeginMenu(info.i18n->GetWord("edit").c_str())) {
160 if (ImGui::MenuItem(info.i18n->GetWord("editundo").c_str(), "Ctrl+Z", false, info.activeEditor && info.activeEditor->CanUndo())) {
161 info.activeEditor->Undo();
162 }
163 if (ImGui::MenuItem(info.i18n->GetWord("editredo").c_str(), "Ctrl+Y", false, info.activeEditor && info.activeEditor->CanRedo())) {
164 info.activeEditor->Redo();
165 }
166 ImGui::Separator();
167 if (ImGui::MenuItem(info.i18n->GetWord("editcut").c_str(), "Ctrl+X", false, info.activeEditor)) {
168 info.activeEditor->Cut();
169 }
170 if (ImGui::MenuItem(info.i18n->GetWord("editcopy").c_str(), "Ctrl+C", false, info.activeEditor)) {
171 info.activeEditor->Copy();
172 }
173 if (ImGui::MenuItem(info.i18n->GetWord("editpaste").c_str(), "Ctrl+V", false, info.activeEditor)) {
174 info.activeEditor->Paste();
175 }
176 if (ImGui::MenuItem(info.i18n->GetWord("editselectall").c_str(), "Ctrl+A", false, info.activeEditor)) {
177 info.activeEditor->SelectAll();
178 }
179 //if (ImGui::MenuItem(info.i18n->GetWord("editduplicate").c_str(), "Ctrl+D", false, info.activeEditor)) {
180 // DuplicateLine(*info.activeEditor);
181 //}
182 ImGui::Separator();
183 if (ImGui::MenuItem(info.i18n->GetWord("settings").c_str(), "Ctrl+,")) {
184 info.isSettings = true;
185 }
186 ImGui::EndMenu();
187 }
188
189 if (ImGui::BeginMenu(info.i18n->GetWord("build").c_str())) {
190 if (ImGui::MenuItem(info.i18n->GetWord("buildcompile").c_str(), "F5")) {
191 info.compile();
192 }
193 ImGui::EndMenu();
194 }
195
196 if (ImGui::BeginMenu(info.i18n->GetWord("help").c_str())) {
197 if (ImGui::MenuItem(info.i18n->GetWord("helpmanual").c_str(), "F1")) {
198 info.isManual = true;
199 }
200 if (ImGui::MenuItem(info.i18n->GetWord("helpabout").c_str(), "CTRL+H")) {
201 info.isAbout = true;
202 }
203 ImGui::EndMenu();
204 }
205
206 ImGui::SameLine();
207
208 f32 side;
209 if (info.i18n->GetCurrentLanguage().code == "ja_JP") side = 379.f;
210 else side = 380.f;
211
212 ImGui::SetCursorPosX(ImGui::GetWindowWidth() - side);
213
214 string fmt = info.i18n->GetWord("currentfps") + ": %.3f ms/frame (%.1f FPS)";
215 ImGui::Text(fmt.c_str(), 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
216
217 ImGui::SameLine();
218 ImGui::Text(" | ");
219 ImGui::SameLine();
220
221 char timeBuf[64];
222 time_t now = time(nullptr);
223 tm *local = localtime(&now);
224
225 strftime(timeBuf, sizeof(timeBuf), "%Y/%m/%d %H:%M:%S", local);
226 ImGui::Text("%s", timeBuf);
227
228 ImGui::EndMainMenuBar();
229 }
230 }
231} // namespace gui