ugh silly

main
Brett 2024-07-30 21:35:59 -04:00
parent e164a1537c
commit 80dee921b4
8 changed files with 46 additions and 6 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
project(graphs VERSION 0.1.9)
project(graphs VERSION 0.1.10)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

View File

@ -29,7 +29,8 @@ namespace conf
inline constexpr float DEFAULT_SPRING_LENGTH = 175.0;
inline constexpr float DEFAULT_INITIAL_TEMPERATURE = 100;
inline constexpr float POINT_SIZE = 35;
inline constexpr float POINT_SIZE = 75;
inline constexpr float OUTLINE_SCALE = 1.25f;
inline constexpr auto DEFAULT_IMAGE = "unknown";
inline constexpr auto POINT_OUTLINE_COLOR = blt::make_color(0, 0.6, 0.6);
inline constexpr auto POINT_HIGHLIGHT_COLOR = blt::make_color(0, 1.0, 1.0);

View File

@ -40,7 +40,7 @@ struct node_t
blt::gfx::point2d_t point;
blt::vec2 velocity;
float outline_scale = 1.25f;
float outline_scale = conf::OUTLINE_SCALE;
blt::color4 outline_color = conf::POINT_OUTLINE_COLOR;
explicit node_t(const blt::gfx::point2d_t& point): name(get_name()), point(point)

@ -1 +1 @@
Subproject commit ff2c8e3be8aea2c3324cd9d7c2575085a7f1b56e
Subproject commit c01cb757a1d19fa8e06292dcb61a5b5769979f11

BIN
res/jim.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

View File

@ -71,11 +71,24 @@ std::optional<loader_t> loader_t::load_for(engine_t& engine, const blt::gfx::win
auto size = static_cast<blt::f32>(load_with_default(node, "size", static_cast<blt::f64>(conf::POINT_SIZE)));
auto name = load_with_default<std::string>(node, "name", get_name());
auto texture = load_with_default<std::string>(node, "texture", conf::DEFAULT_IMAGE);
auto outline_scale = load_with_default(node, "scale", conf::OUTLINE_SCALE);
auto outline_color = load_with_default(node, "color", json::array());
BLT_ASSERT(!graph.names_to_node.contains(name) && "Graph node name must be unique!");
graph.names_to_node.insert({name, static_cast<blt::u64>(graph.nodes.size())});
graph.nodes.emplace_back(blt::gfx::point2d_t{x, y, size}, std::move(name));
graph.nodes.back().texture = std::move(texture);
graph.nodes.back().outline_scale = outline_scale;
if (outline_color.is_array() && outline_color.size() >= 3)
{
auto r = static_cast<float>(outline_color[0].get<double>());
auto g = static_cast<float>(outline_color[1].get<double>());
auto b = static_cast<float>(outline_color[2].get<double>());
if (outline_color > 3)
graph.nodes.back().outline_color = blt::vec4{r, g, b, static_cast<float>(outline_color[3].get<double>())};
else
graph.nodes.back().outline_color = blt::make_color(r, g, b);
}
}
}
@ -158,12 +171,15 @@ void loader_t::save_for(engine_t& engine, const loader_t& loader, std::string_vi
for (const auto& node : graph.nodes)
{
const auto& color = node.outline_color;
data["nodes"].push_back(json{
{"name", node.name},
{"texture", node.texture},
{"size", node.getRenderObj().scale},
{"x", node.getPosition().x()},
{"y", node.getPosition().y()},
{"scale", node.outline_scale},
{"color", json::array({color.x(), color.y(), color.z(), color.w()})}
});
data["descriptions"].push_back(json{
{"name", node.name},

View File

@ -61,6 +61,7 @@ void init(const blt::gfx::window_data& data)
resources.enqueue("res/ben.jpg", "ben");
resources.enqueue("res/no_image.jpg", "unknown");
resources.enqueue("res/me.png", "me");
resources.enqueue("res/jim.jpg", "jim");
if (auto loader = loader_t::load_for(engine, data, "default.json", "save.json"))
{

View File

@ -89,8 +89,11 @@ void selector_t::process_mouse(blt::i32 width, blt::i32 height)
{
set_drag_selection(static_cast<blt::i64>(index));
if (blt::gfx::isKeyPressed(GLFW_KEY_LEFT_SHIFT))
{
if (secondary_selection != -1)
set_primary_selection(secondary_selection);
set_secondary_selection(drag_selection);
else
} else
{
set_primary_selection(drag_selection);
set_secondary_selection(-1);
@ -146,9 +149,28 @@ void selector_t::draw_gui(blt::i32 width, blt::i32 height)
{
if (secondary_selection >= 0)
{
auto edge_i = graph.edges.find({static_cast<blt::u64>(primary_selection), static_cast<blt::u64>(secondary_selection)});
if (edge_i == graph.edges.end())
return;
auto edge = *edge_i;
bool changed = false;
changed |= im::SliderFloat("Ideal Length", &edge.ideal_spring_length, conf::POINT_SIZE, conf::DEFAULT_SPRING_LENGTH * 4);
callback_data_t description_data{edge.description, description_input};
changed |= im::InputTextMultiline("Description", description_input.data(), description_input.size(), {},
ImGuiInputTextFlags_CallbackResize | ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_CallbackCompletion,
text_input_callback, &description_data);
if (changed)
{
graph.edges.erase(edge_i);
graph.edges.insert(edge);
}
} else
{
im::InputFloat("Size", &graph.nodes[primary_selection].point.scale);
im::SliderFloat("Size", &graph.nodes[primary_selection].point.scale, 1, 100);
im::ColorPicker4("Color", graph.nodes[primary_selection].outline_color.data());
im::SliderFloat("Scale", &graph.nodes[primary_selection].outline_scale, 1, 2);
callback_data_t name_data{graph.nodes[primary_selection].name, name_input};
callback_data_t texture_data{graph.nodes[primary_selection].texture, texture_input};
callback_data_t description_data{graph.nodes[primary_selection].description, description_input};