diff --git a/CMakeLists.txt b/CMakeLists.txt index 627e01c..898cf16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/config.h b/include/config.h index 14a8ab9..ad1bae0 100644 --- a/include/config.h +++ b/include/config.h @@ -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); diff --git a/include/graph_base.h b/include/graph_base.h index 7d74243..c81dc72 100644 --- a/include/graph_base.h +++ b/include/graph_base.h @@ -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) diff --git a/lib/BLT-With-Graphics-Template b/lib/BLT-With-Graphics-Template index ff2c8e3..c01cb75 160000 --- a/lib/BLT-With-Graphics-Template +++ b/lib/BLT-With-Graphics-Template @@ -1 +1 @@ -Subproject commit ff2c8e3be8aea2c3324cd9d7c2575085a7f1b56e +Subproject commit c01cb757a1d19fa8e06292dcb61a5b5769979f11 diff --git a/res/jim.jpg b/res/jim.jpg new file mode 100644 index 0000000..d7f28e4 Binary files /dev/null and b/res/jim.jpg differ diff --git a/src/loader.cpp b/src/loader.cpp index 053c7a4..0a2014c 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -71,11 +71,24 @@ std::optional loader_t::load_for(engine_t& engine, const blt::gfx::win auto size = static_cast(load_with_default(node, "size", static_cast(conf::POINT_SIZE))); auto name = load_with_default(node, "name", get_name()); auto texture = load_with_default(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(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(outline_color[0].get()); + auto g = static_cast(outline_color[1].get()); + auto b = static_cast(outline_color[2].get()); + if (outline_color > 3) + graph.nodes.back().outline_color = blt::vec4{r, g, b, static_cast(outline_color[3].get())}; + 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}, diff --git a/src/main.cpp b/src/main.cpp index 2ac514c..7920c31 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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")) { diff --git a/src/selector.cpp b/src/selector.cpp index 52f7798..5677897 100644 --- a/src/selector.cpp +++ b/src/selector.cpp @@ -89,8 +89,11 @@ void selector_t::process_mouse(blt::i32 width, blt::i32 height) { set_drag_selection(static_cast(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(primary_selection), static_cast(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};