Skip to content

Commit

Permalink
small usability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bb1950328 committed Oct 28, 2023
1 parent 7bb08f2 commit 2bab13d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/connection/connection_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace bricksim::connection {
}
void BaseConnectorGrouping::addUngendered(const std::shared_ptr<Connector>& connector) {
const auto absDir = transformation * glm::vec4(connector->direction, 0.f);
const auto dirIdx = directions.gendered.getIndex(absDir);
const auto dirIdx = directions.ungendered.getIndex(absDir);
updateContainers();
ungendered[dirIdx].push_back(connector);
}
Expand Down
9 changes: 4 additions & 5 deletions src/connection/connector/finger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ namespace bricksim::connection {
}
std::shared_ptr<Connector> FingerConnector::transform(const glm::mat4& transformation) {
const auto [radiusFactor, lengthFactor] = getRadiusAndLengthFactorFromTransformation(transformation, direction);
const auto lengthFactorX = lengthFactor;//workaround for clang bug https://www.reddit.com/r/LLVM/comments/s0ykcj/comment/jazmf9m/?utm_source=share&utm_medium=web2x&context=3
std::vector<float> resultFingerWidths;
std::transform(fingerWidths.cbegin(),
fingerWidths.cend(),
resultFingerWidths.begin(),
[lengthFactorX](auto w) { return lengthFactorX * w; });
resultFingerWidths.reserve(fingerWidths.size());
for (const auto& w: fingerWidths) {
resultFingerWidths.push_back(lengthFactor * w);
}
return std::make_shared<FingerConnector>(group,
glm::vec4(start, 1.f) * transformation,
glm::vec4(direction, 0.f) * transformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ namespace bricksim::connection::visualization {
labelLines.push_back(fmt::format("<img src=\"{}\" />", filename));
}
if (params.node.showTitle) {
labelLines.push_back(ldrFile->metaInfo.title);
labelLines.push_back(stringutil::escapeXml(ldrFile->metaInfo.title));
}
if (params.node.showName) {
labelLines.push_back(ldrFile->metaInfo.name);
labelLines.push_back(stringutil::escapeXml(ldrFile->metaInfo.name));
}
if (params.node.showLocation) {
const auto location = glm::row(node->getAbsoluteTransformation(), 3);
Expand Down
21 changes: 15 additions & 6 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ namespace bricksim::controller {
if (!config::get(config::ENABLE_VSYNC)) {
glfwSwapInterval(0);
}
glfwSetFramebufferSizeCallback(window, window_size_callback);
glfwSetScrollCallback(window, scroll_callback);
glfwSetFramebufferSizeCallback(window, windowSizeCallback);
glfwSetScrollCallback(window, scrollCallback);
glfwSetKeyCallback(window, keyCallback);

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
Expand Down Expand Up @@ -188,12 +188,14 @@ namespace bricksim::controller {

graphics::opengl_native_or_replacement::initialize();

glfwSetDropCallback(window, dropCallback);

spdlog::info("OpenGL initialized");
openGlInitialized = true;
return true;
}

void window_size_callback([[maybe_unused]] GLFWwindow* _, int width, int height) {
void windowSizeCallback([[maybe_unused]] GLFWwindow* _, int width, int height) {
if (windowWidth != static_cast<unsigned int>(width) || windowHeight != static_cast<unsigned int>(height)) {
windowWidth = width;
windowHeight = height;
Expand All @@ -203,18 +205,25 @@ namespace bricksim::controller {
}
}

void dropCallback(GLFWwindow* _, int count, const char** paths) {
for (int i = 0; i < count; ++i) {
std::filesystem::path p = paths[i];
if (std::filesystem::is_regular_file(p)) {
openFile(p);
}
}
}

void keyCallback([[maybe_unused]] GLFWwindow* _, int key, [[maybe_unused]] int scancode, int action, int mods) {
keyboard_shortcut_manager::shortcutPressed(key, action, static_cast<keyboard_shortcut_manager::modifier_t>(mods), gui::areKeysCaptured());
}

void scroll_callback([[maybe_unused]] GLFWwindow* _, [[maybe_unused]] double xoffset, double yoffset) {
void scrollCallback([[maybe_unused]] GLFWwindow* _, [[maybe_unused]] double xoffset, double yoffset) {
//todo use xoffset to do something, maybe pan?
gui::setLastScrollDeltaY(yoffset);
if (ImGui::GetIO().WantCaptureMouse) {
return;
}
//todo find out on which window the mouse is
//camera->moveForwardBackward((float)yoffset);
}

void checkForFinishedBackgroundTasks() {
Expand Down
5 changes: 3 additions & 2 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
namespace bricksim::controller {
namespace {
bool initializeGL();
void window_size_callback(GLFWwindow* window, int width, int height);
void windowSizeCallback(GLFWwindow* window, int width, int height);
void dropCallback(GLFWwindow* _, int count, const char** paths);
void setWindowSize(unsigned int width, unsigned int height);
void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void scrollCallback(GLFWwindow* window, double xoffset, double yoffset);
void checkForFinishedBackgroundTasks();
void glfwErrorCallback(int code, const char* message);
bool initialize();
Expand Down
12 changes: 11 additions & 1 deletion src/gui/windows/window_connection_visualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,17 @@ namespace bricksim::gui::windows::connection_visualization {
}
}
}
ImGui::SetItemTooltip("Save image as");
ImGui::SetItemTooltip("Save rendered image as");

if (ImGui::Button(ICON_FA_CAMERA, buttonSize)) {
const auto path = dialogs::showSaveImageDialog("Render Connection Visualization with GraphViz");
if (path) {
controller::getForegroundTasks().emplace("Rerender Connection Graph with GraphViz", [&path](auto* progress) {
graphviz_wrapper::renderDot(*path, graphvizCode.dotCode);
});
}
}
ImGui::SetItemTooltip("Rerender image and save as");

if (ImGui::Button(ICON_FA_FILE_CODE, buttonSize)) {
const auto path = dialogs::showSaveDotFileDialog("Save Connection Visualization .dot Code");
Expand Down
14 changes: 14 additions & 0 deletions src/helpers/stringutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,18 @@ namespace bricksim::stringutil {
utf8::utf16to8(u16without.begin(), u16without.end(), std::back_inserter(result));
return result;
}
std::string escapeXml(const std::string& str) {
std::string result;
for (const auto& ch: str) {
switch (ch) {
case '&': result += "&amp;"; break;
case '\'': result += "&apos;"; break;
case '"': result += "&quot;"; break;
case '<': result += "&lt;"; break;
case '>': result += "&gt;"; break;
default: result += ch; break;
}
}
return result;
}
}
2 changes: 2 additions & 0 deletions src/helpers/stringutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace bricksim::stringutil {
std::vector<std::string_view> splitByChar(std::string_view string, char delimiter);
std::string repeat(const std::string& str, unsigned int times);

std::string escapeXml(const std::string& str);

template<glm::length_t L, typename T>
std::string formatGLM(const glm::vec<L, T>& vec);
template<typename T>
Expand Down

0 comments on commit 2bab13d

Please sign in to comment.