Skip to content

Commit 39c0a5c

Browse files
authored
Merge pull request #87 from Simple-Robotics/next
initialize boolean in Visualizer.h, rework file dialog GUI, fix screenshot color, sync cmake submodule
2 parents afa0c6c + 1cdccf4 commit 39c0a5c

File tree

10 files changed

+129
-112
lines changed

10 files changed

+129
-112
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- slightly rework file dialog GUI
13+
14+
### Fixed
15+
16+
- fix screenshot PNG color channel ordering
17+
1018
## [0.6.0] - 2025-06-19
1119

1220
### Changed

cmake

Submodule cmake updated 1 file

examples/Ur5WithSystems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ int main(int argc, char **argv) {
422422
guiAddFileDialog(renderer.window, DialogFileType::IMAGES, scr_filename);
423423
if (ImGui::Button("Take screenshot")) {
424424
if (scr_filename.empty())
425-
scr_filename = generateMediaFilenameFromTimestamp();
425+
generateMediaFilenameFromTimestamp("cdw_screenshot", scr_filename);
426426
screenshot_filename = scr_filename.c_str();
427427
}
428428

src/candlewick/core/FileDialogGui.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ void guiAddFileDialog(SDL_Window *window, DialogFileType dialog_file_type,
6666
ImGui::Text("%s", out.empty() ? "(none)" : out.c_str());
6767
}
6868

69-
std::string generateMediaFilenameFromTimestamp(const char *prefix,
70-
const char *extension,
71-
DialogFileType file_type) {
69+
void generateMediaFilenameFromTimestamp(const char *prefix, std::string &out,
70+
const char *extension,
71+
DialogFileType file_type) {
7272
const std::chrono::time_point now = std::chrono::system_clock::now();
7373
auto time = std::chrono::system_clock::to_time_t(now);
7474
auto tm = std::localtime(&time);
75-
const char *picturesDir =
76-
SDL_GetUserFolder(g_dialog_file_type_folder[int(file_type)]);
7775
std::ostringstream oss;
78-
oss << picturesDir << prefix << " " << std::put_time(tm, "%F %H-%M-%S %z")
79-
<< extension;
80-
return oss.str();
76+
oss << SDL_GetUserFolder(g_dialog_file_type_folder[int(file_type)]) << prefix
77+
<< " " << std::put_time(tm, "%F %H-%M-%S %z") << extension;
78+
std::string_view view = oss.view();
79+
if (!view.empty())
80+
out = view;
8181
}
8282

8383
} // namespace candlewick

src/candlewick/core/GuiSystem.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ void guiAddFileDialog(SDL_Window *window, DialogFileType dialog_file_type,
6363
std::string &filename);
6464
/// \}
6565

66-
std::string generateMediaFilenameFromTimestamp(
67-
const char *prefix = "cdw_screenshot", const char *extension = ".png",
66+
/// \brief Set input/output string to a generated filename computed from a
67+
/// timestamp.
68+
void generateMediaFilenameFromTimestamp(
69+
const char *prefix, std::string &out, const char *extension = ".png",
6870
DialogFileType file_type = DialogFileType::IMAGES);
6971

7072
} // namespace candlewick

src/candlewick/multibody/Visualizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ void Visualizer::displayImpl() {
165165
robotScene.updateTransforms();
166166
this->render();
167167

168-
if (!m_currentScreenshotFilename.empty()) {
168+
if (m_shouldScreenshot) {
169169
this->takeScreenshot(m_currentScreenshotFilename);
170170
m_currentScreenshotFilename.clear();
171+
m_shouldScreenshot = false;
171172
}
172173

173174
#ifdef CANDLEWICK_WITH_FFMPEG_SUPPORT

src/candlewick/multibody/Visualizer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class Visualizer final : public BaseVisualizer {
5656
bool m_showGui = true;
5757
bool m_shouldExit = false;
5858
entt::entity m_grid, m_triad;
59-
std::string m_currentScreenshotFilename{};
6059
RobotDebugSystem *robotDebug = nullptr;
6160
std::vector<entt::entity> m_debug_frame_pos;
6261
std::vector<entt::entity> m_debug_frame_vel;
@@ -179,8 +178,10 @@ class Visualizer final : public BaseVisualizer {
179178

180179
private:
181180
media::TransferBufferPool m_transferBuffers;
181+
std::string m_currentScreenshotFilename;
182+
bool m_shouldScreenshot = false;
182183
#ifdef CANDLEWICK_WITH_FFMPEG_SUPPORT
183-
std::string m_currentVideoFilename{};
184+
std::string m_currentVideoFilename;
184185
media::VideoRecorder m_videoRecorder;
185186
media::VideoRecorder::Settings m_videoSettings;
186187
#endif

src/candlewick/multibody/internal/visualizer_gui.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,6 @@ void guiAddCameraParams(CylindricalCamera &controller,
3030
}
3131
}
3232

33-
static void screenshot_taker_gui(SDL_Window *window, std::string &filename) {
34-
static std::string out;
35-
out.reserve(64ul);
36-
37-
ImGui::BeginChild("screenshot_taker", {0, 0},
38-
ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY);
39-
guiAddFileDialog(window, DialogFileType::IMAGES, out);
40-
if (ImGui::Button("Take screenshot"))
41-
filename = out.empty() ? generateMediaFilenameFromTimestamp() : out;
42-
43-
ImGui::EndChild();
44-
}
45-
4633
void Visualizer::defaultGuiCallback() {
4734

4835
// Verify ABI compatibility between caller code and compiled version of Dear
@@ -111,7 +98,19 @@ void Visualizer::defaultGuiCallback() {
11198
"Screenshots"
11299
#endif
113100
)) {
114-
screenshot_taker_gui(renderer.window, m_currentScreenshotFilename);
101+
ImGui::BeginChild("screenshot_taker", {0, 0},
102+
ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY);
103+
guiAddFileDialog(renderer.window, DialogFileType::IMAGES,
104+
m_currentScreenshotFilename);
105+
if (ImGui::Button("Take screenshot")) {
106+
m_shouldScreenshot = true;
107+
if (m_currentScreenshotFilename.empty()) {
108+
generateMediaFilenameFromTimestamp("cdw_screenshot",
109+
m_currentScreenshotFilename);
110+
}
111+
}
112+
113+
ImGui::EndChild();
115114

116115
#ifdef CANDLEWICK_WITH_FFMPEG_SUPPORT
117116
ImGui::BeginChild("video_record", {0, 0},

0 commit comments

Comments
 (0)