11#ifdef IMGUI_IMPL_OPENGL_LOADER_GL3W
16 #include <imgui_internal.h>
17 #include <imgui_node_editor.h>
18 #include <imgui_node_editor_internal.h>
19 #include <imgui_canvas.h>
35std::string plotScreenshotImPlotStyleFile =
"implot-light.json";
36bool copyScreenshotsToClipboard =
true;
40ImRect _screenshotNavigateRect;
41ImRect _screenshotCaptureRect;
42bool _showScreenshotCaptureRect =
false;
43bool _printScreenshotSaveLocation =
true;
44size_t _screenshotFrameCnt = 0;
49void NAV::gui::windows::ShowScreenshotter(
bool* show )
51 if (_screenshotFrameCnt > 0)
53 _screenshotFrameCnt++;
55 if (_screenshotFrameCnt == 4)
57 ImGuiIO& io = ImGui::GetIO();
58 ImGuiScreenshotImageBuf Output(
static_cast<int>(_screenshotCaptureRect.Min.x),
59 static_cast<int>(io.DisplaySize.y) -
static_cast<int>(_screenshotCaptureRect.Max.y),
60 static_cast<size_t>(_screenshotCaptureRect.GetWidth()),
61 static_cast<size_t>(_screenshotCaptureRect.GetHeight()));
63 std::time_t t = std::time(
nullptr);
64 std::tm* now = std::localtime(&t);
66 auto savePath = flow::GetOutputPath()
67 / fmt::format(
"Screenshot_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}-{:02d}.png",
68 now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec);
69 Output.SaveFile(savePath.c_str());
70 if (_printScreenshotSaveLocation)
72 LOG_INFO(
"Screenshot saved as: {}", savePath);
75 if (copyScreenshotsToClipboard)
77 CopyFileToClipboard(savePath.c_str());
79 _screenshotFrameCnt = 0;
85 if (_showScreenshotCaptureRect)
87 constexpr float thickness = 1.0F;
88 auto rect = _screenshotCaptureRect;
89 rect.Expand(thickness);
90 ImGui::GetForegroundDrawList()->AddRect(rect.Min, rect.Max, ImColor(255, 0, 0),
91 0.0F, ImDrawFlags_None, thickness);
94 if (!ImGui::Begin(
"Screenshotter", show, ImGuiWindowFlags_AlwaysAutoResize))
100 const float ITEM_WIDTH = 200.0F * NodeEditorApplication::defaultFontRatio();
101 const float ITEM_WIDTH_HALF = (ITEM_WIDTH - ImGui::GetStyle().ItemInnerSpacing.x) / 2.0F;
103 ImGui::TextUnformatted(
"Plot screenshot style: ");
105 ImGui::SetNextItemWidth(100.0F * NodeEditorApplication::defaultFontRatio());
106 if (widgets::FileDialogLoad(plotScreenshotImPlotStyleFile,
"Plot screenshot config file",
".json", {
".json" },
107 flow::GetConfigPath(), 1,
"ImPlotStyleEditorScreenshot"))
109 LOG_DEBUG(
"Plot screenshot config file changed to: {}", plotScreenshotImPlotStyleFile);
112 ImGui::Checkbox(
"Copy screenshots to clipboard", ©ScreenshotsToClipboard);
114 if (ImGui::Checkbox(
"Light mode", &nodeEditorLightMode))
117 flow::ApplyChanges();
120 bool showGridLines = ed::GetStyle().Colors[ed::StyleColor_Grid].w != 0.0F;
121 if (ImGui::Checkbox(
"Grid lines", &showGridLines))
123 ed::GetStyle().Colors[ed::StyleColor_Grid].w = showGridLines ? ed::Style().Colors[ed::StyleColor_Grid].w : 0.0F;
124 flow::ApplyChanges();
127 bool transparentWindows = ImGui::GetStyle().Colors[ImGuiCol_WindowBg].w != 1.0F;
128 if (ImGui::Checkbox(
"Transparent windows", &transparentWindows))
130 ImGui::GetStyle().Colors[ImGuiCol_WindowBg].w = transparentWindows ? ImGuiStyle().Colors[ImGuiCol_WindowBg].w : 1.0F;
131 flow::ApplyChanges();
134 if (ImGui::Checkbox(
"Hide left pane", &NodeEditorApplication::hideLeftPane))
136 flow::ApplyChanges();
138 if (!NodeEditorApplication::hideLeftPane)
141 ImGui::SetNextItemWidth(ITEM_WIDTH_HALF);
142 ImGui::DragFloat(
"Left pane width", &NodeEditorApplication::leftPaneWidth);
144 if (ImGui::Checkbox(
"Hide FPS count", &NodeEditorApplication::hideFPS))
146 flow::ApplyChanges();
149 ImGui::Checkbox(
"Print save location", &_printScreenshotSaveLocation);
153 auto* editor =
reinterpret_cast<ed::Detail::EditorContext*
>(ed::GetCurrentEditor());
154 if (_screenshotNavigateRect.GetArea() == 0.0F) { _screenshotNavigateRect = editor->GetContentBounds(); }
156 ImGui::SetNextItemOpen(
true, ImGuiCond_Once);
157 if (ImGui::TreeNode(
"Screenshot navigate area"))
159 ImGui::TextUnformatted(fmt::format(
"Current Content Bounds: Min({},{}), Max({},{})",
160 editor->GetContentBounds().Min.x, editor->GetContentBounds().Min.y,
161 editor->GetContentBounds().Max.x, editor->GetContentBounds().Max.y)
163 ImGui::TextUnformatted(fmt::format(
"Current View: Min({},{}), Max({},{})",
164 editor->GetViewRect().Min.x, editor->GetViewRect().Min.y,
165 editor->GetViewRect().Max.x, editor->GetViewRect().Max.y)
168 if (ImGui::Button(
"Set area to content")) { _screenshotNavigateRect = editor->GetContentBounds(); }
170 if (ImGui::Button(
"Set area to current view"))
172 _screenshotNavigateRect = editor->GetViewRect();
174 auto extend = ImMax(_screenshotNavigateRect.GetWidth(), _screenshotNavigateRect.GetHeight());
175 constexpr float c_NavigationZoomMargin = 0.1F;
176 _screenshotNavigateRect.Expand(-extend * c_NavigationZoomMargin * 0.5F);
179 ImGui::SetNextItemWidth(ITEM_WIDTH);
180 ImGui::DragFloat2(
"Min##Nav area", &_screenshotNavigateRect.Min.x);
181 ImGui::SetNextItemWidth(ITEM_WIDTH);
182 ImGui::DragFloat2(
"Max##Nav area", &_screenshotNavigateRect.Max.x);
184 if (ImGui::Button(
"Navigate to area"))
186 editor->NavigateTo(_screenshotNavigateRect,
true);
190 static float zoomFactor = editor->GetView().Scale;
191 if (ImGui::Button(
"Zoom"))
193 auto targetRect = editor->GetCanvas().CalcViewRect(ImGuiEx::CanvasView(editor->GetView().Origin, zoomFactor));
194 editor->NavigateTo(targetRect,
true, 0.15F);
197 ImGui::SetNextItemWidth(ITEM_WIDTH_HALF / 2.F);
198 ImGui::InputFloat(
"##Zoom Factor", &zoomFactor);
200 ImGui::TextUnformatted(fmt::format(
"Current: {:.3f}", editor->GetView().Scale).c_str());
205 ImGuiIO& io = ImGui::GetIO();
206 if (_screenshotCaptureRect.GetArea() == 0.0F && ImGui::GetFrameCount() > 10) { _screenshotCaptureRect.Max = io.DisplaySize; }
208 ImGui::SetNextItemOpen(
true, ImGuiCond_Once);
209 if (ImGui::TreeNode(
"Screenshot capture area"))
211 if (ImGui::Button(
"Set to display size"))
213 _screenshotCaptureRect.Min = ImVec2();
214 _screenshotCaptureRect.Max = io.DisplaySize;
217 ImGui::SetNextItemWidth(ITEM_WIDTH_HALF);
218 if (ImGui::BeginCombo(
"##Window list",
"Set to window"))
220 ImVector<ImGuiWindow*>& windows = ImGui::GetCurrentContext()->Windows;
221 for (ImGuiWindow* window : windows)
223 std::string windowName = window->Name;
224 if (!window->WasActive || windowName.find(
'#') != std::string::npos || windowName.starts_with(
"Content")) {
continue; }
225 const bool is_selected = window->Rect().Min == _screenshotCaptureRect.Min && window->Rect().Max == _screenshotCaptureRect.Max;
226 if (ImGui::Selectable(window->Name, is_selected))
228 _screenshotCaptureRect = window->Rect();
232 if (is_selected) { ImGui::SetItemDefaultFocus(); }
238 ImGui::Checkbox(
"Show Capture rect", &_showScreenshotCaptureRect);
240 ImGui::SetNextItemWidth(ITEM_WIDTH_HALF);
241 ImGui::DragFloat(
"##Min Capture area x", &_screenshotCaptureRect.Min.x, 1.0F, 0.0F, io.DisplaySize.x - 1);
243 ImGui::SetCursorPosX(ImGui::GetCursorPosX() - ImGui::GetStyle().ItemSpacing.x + ImGui::GetStyle().ItemInnerSpacing.x);
244 ImGui::SetNextItemWidth(ITEM_WIDTH_HALF);
245 ImGui::DragFloat(
"Min##Capture area y", &_screenshotCaptureRect.Min.y, 1.0F, 0.0F, io.DisplaySize.y - 1);
247 ImGui::SetNextItemWidth(ITEM_WIDTH_HALF);
248 ImGui::DragFloat(
"##Max Capture area x", &_screenshotCaptureRect.Max.x, 1.0F, _screenshotCaptureRect.Min.x + 1, io.DisplaySize.x);
250 ImGui::SetCursorPosX(ImGui::GetCursorPosX() - ImGui::GetStyle().ItemSpacing.x + ImGui::GetStyle().ItemInnerSpacing.x);
251 ImGui::SetNextItemWidth(ITEM_WIDTH_HALF);
252 ImGui::DragFloat(
"Max##Capture area y", &_screenshotCaptureRect.Max.y, 1.0F, _screenshotCaptureRect.Min.y + 1, io.DisplaySize.y);
254 if (ImGui::Button(
"Take screenshot"))
256 _screenshotFrameCnt = 1;
265void NAV::gui::windows::CopyFileToClipboard(
const char* path)
268 [[maybe_unused]]
int exitCode = system(fmt::format(
"command -v xclip > /dev/null 2>&1 && xclip -selection clipboard -target image/png -i {} && exit 0"
269 "|| command -v wl-copy > /dev/null 2>&1 && wl-copy < {}",
Utility class for logging to console and file.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
#define LOG_INFO
Info to the user on the state of the program.
void ApplyDarkLightMode(std::vector< ImVec4 > &colors)