silly connection of edges
parent
780c8ac25a
commit
e164a1537c
|
@ -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)
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -115,10 +115,19 @@ void selector_t::process_keyboard(blt::i32 width, blt::i32 height)
|
||||||
{
|
{
|
||||||
if (blt::gfx::isKeyPressed(GLFW_KEY_C))
|
if (blt::gfx::isKeyPressed(GLFW_KEY_C))
|
||||||
{
|
{
|
||||||
if (placement)
|
if (primary_selection != -1 && secondary_selection != -1)
|
||||||
destroy_node(primary_selection);
|
{
|
||||||
else
|
if (graph.is_connected(primary_selection, secondary_selection))
|
||||||
create_placement_node(mouse_pos);
|
graph.disconnect(primary_selection, secondary_selection);
|
||||||
|
else
|
||||||
|
graph.connect(primary_selection, secondary_selection);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if (placement)
|
||||||
|
destroy_node(primary_selection);
|
||||||
|
else
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in New Issue