silly connection of edges

main
Brett 2024-07-30 03:16:58 -04:00
parent 780c8ac25a
commit e164a1537c
3 changed files with 30 additions and 7 deletions

View File

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

View File

@ -46,7 +46,9 @@ struct bounding_box
class graph_t class graph_t
{ {
friend struct loader_t; friend struct loader_t;
friend class selector_t; friend class selector_t;
private: private:
std::vector<node_t> nodes; std::vector<node_t> nodes;
blt::hashmap_t<std::string, blt::u64> names_to_node; blt::hashmap_t<std::string, blt::u64> names_to_node;
@ -100,6 +102,18 @@ class graph_t
edges.insert({n1, n2}); edges.insert({n1, n2});
} }
void disconnect(const blt::u64 n1, const blt::u64 n2)
{
connected_nodes[n1].erase(n2);
connected_nodes[n2].erase(n1);
edges.erase({n1, n2});
}
bool is_connected(const blt::u64 n1, const blt::u64 n2)
{
return edges.contains({n1, n2});
}
void connect(const edge_t& edge) void connect(const edge_t& edge)
{ {
connected_nodes[edge.getFirst()].insert(edge.getSecond()); connected_nodes[edge.getFirst()].insert(edge.getSecond());
@ -188,7 +202,7 @@ class engine_t
friend struct loader_t; friend struct loader_t;
private: private:
graph_t graph; graph_t graph;
selector_t selector {graph}; selector_t selector{graph};
void draw_gui(const blt::gfx::window_data& data); void draw_gui(const blt::gfx::window_data& data);

View File

@ -114,11 +114,20 @@ void selector_t::process_keyboard(blt::i32 width, blt::i32 height)
if (blt::gfx::keyPressedLastFrame()) if (blt::gfx::keyPressedLastFrame())
{ {
if (blt::gfx::isKeyPressed(GLFW_KEY_C)) if (blt::gfx::isKeyPressed(GLFW_KEY_C))
{
if (primary_selection != -1 && secondary_selection != -1)
{
if (graph.is_connected(primary_selection, secondary_selection))
graph.disconnect(primary_selection, secondary_selection);
else
graph.connect(primary_selection, secondary_selection);
} else
{ {
if (placement) if (placement)
destroy_node(primary_selection); destroy_node(primary_selection);
else else
create_placement_node(mouse_pos); create_placement_node(mouse_pos);
}
} else if (blt::gfx::isKeyPressed(GLFW_KEY_X)) } else if (blt::gfx::isKeyPressed(GLFW_KEY_X))
{ {
if (primary_selection != -1) if (primary_selection != -1)