Double connections fixed

This commit is contained in:
Sebastian
2024-11-30 12:47:33 +01:00
parent c7e76ae7ac
commit c63ee3eabe
5 changed files with 34 additions and 18 deletions
+9 -1
View File
@@ -15,13 +15,16 @@ namespace VISEQ::BASE {
std::shared_ptr<Connectable> partner;
bool new_partner = false;
bool connecting = false;
Vec2Df connecting_position;
virtual void init() {
connectables.emplace_back(this);
}
virtual void drag(Vec2Df new_position) override {
DrawLineV(position, new_position, (Color){229, 181, 103, 255});
connecting = true;
connecting_position = new_position;
}
void putDown() override {
@@ -40,8 +43,13 @@ namespace VISEQ::BASE {
break;
}
}
connecting = false;
}
}
virtual void draw(){
if(connecting) DrawLineV(position, connecting_position, (Color){229, 181, 103, 255});
}
};
}
+5 -5
View File
@@ -35,7 +35,7 @@ namespace VISEQ::GRAPH {
}
virtual bool hovering() override {
return CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
return !partner && CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
}
void setParent(std::shared_ptr<GraphItem> _parent){
@@ -55,18 +55,18 @@ namespace VISEQ::GRAPH {
if(!partner) position = center_position - ((center_position - SCREEN_MOUSE)).norm() * (radius + orbit);
if(partner) position = center_position - ((center_position - partner->position)).norm() * (radius + orbit);
if(new_partner) {
//TODO what happens if a new partner is connected?
new_partner = false;
state->pushEvent({getPtr(), APP::Interaction::CONNECT});
}
}
void draw() override {
BASE::Connectable::draw();
float opacity = 150.0f - Clamp(position.dist(SCREEN_MOUSE), 0.0f, 150.0f);
if(partner){
DrawLineV(position, partner->position, VS_COLOR_RED);
}
/*if(partner){*/
/* DrawLineV(position, partner->position, VS_COLOR_RED);*/
/*}*/
if(hovering()){
DrawCircle(position.x, position.y, 8.0f, (Color){108, 203, 237, 255});
+3
View File
@@ -17,6 +17,9 @@ namespace VISEQ::GRAPH::EDGES {
std::shared_ptr<NODES::Node> start;
std::shared_ptr<NODES::Node> end;
std::shared_ptr<Connector> start_conn;
std::shared_ptr<Connector> end_conn;
EdgeType edgeType;
bool pass_forward = true;
+4
View File
@@ -73,6 +73,8 @@ namespace VISEQ::GRAPH {
edges.back()->end = to;
from->connections.push_back(edges.back());
to->connections.push_back(edges.back());
edges.back()->start_conn = from->connectors.back();
edges.back()->end_conn = to->connectors.back();
}
}
@@ -221,6 +223,8 @@ namespace VISEQ::GRAPH {
void removeEdges(){
for(auto edge : remove_edges){
std::erase(edge->start->connectors, edge->start_conn);
std::erase(edge->end->connectors, edge->end_conn);
std::erase(edge->start->connections, edge);
std::erase(edge->end->connections, edge);
std::erase(edges, edge);
+13 -12
View File
@@ -63,7 +63,6 @@ namespace VISEQ::INTERACTION{
std::shared_ptr<ScaleHandle> scale_handle = std::make_shared<ScaleHandle>();
void update(){
doInteraction();
if(KEYS_DOWN.ctrl && IsKeyPressed(KEY_C)){
VEC_SPTR_Node selected_nodes = gm->getSelection();
if(!selected_nodes.empty()) cb.pushNodes(selected_nodes);
@@ -82,7 +81,15 @@ namespace VISEQ::INTERACTION{
state->node_mode = (state->node_mode + 1) % 3;
}
}
void draw(){
doInteraction();
scaleSelection();
if(!gm->selected_nodes.empty()){
DrawRectangleRoundedLines(state->bounding_box, 0.1f, 3, VS_COLOR_LIGHTGREY);
scale_handle->draw();
}
}
void removeNodes(VEC_SPTR_Node nodes){
@@ -170,31 +177,31 @@ namespace VISEQ::INTERACTION{
void doInteraction(){
bool exit = false;
bool once = false;
bool connect_once = false;
state->mouse_z = canvas->z_index;
while(APP::event_queue.size() > 0 && !exit){
auto e = APP::event_queue.front();
std::cout << e.item->getType() << " " << e.action << std::endl;
//std::cout << e.item->getType() << " " << e.action << std::endl;
if(e.action == APP::Interaction::CONNECT){
if(!connect_once && e.action == APP::Interaction::CONNECT){
auto connector = std::dynamic_pointer_cast<Connector>(e.item);
auto connector_to = std::dynamic_pointer_cast<Connector>(connector->partner);
gm->addConnection(std::dynamic_pointer_cast<Node>(connector->parent), std::dynamic_pointer_cast<Node>(connector_to->parent));
connect_once = true;
}
if(e.action == APP::Interaction::HOVER){
state->mouse_z = e.item->z_index;
std::cout << state->mouse_z << std::endl;
}
if(e.item->getType() == GraphItemType::CANVAS) {
if(e.action == APP::Interaction::SELECT) {
gm->select();
std::cout << "app canvas select" << std::endl;
canvas->clearSelectionRect();
}
if(e.action == APP::Interaction::DESELECT) {
std::cout << "app canvas deselect" << std::endl;
gm->deselect();
}
}
@@ -264,11 +271,5 @@ namespace VISEQ::INTERACTION{
APP::event_queue.clear();
}
void draw(){
if(!gm->selected_nodes.empty()){
DrawRectangleRoundedLines(state->bounding_box, 0.1f, 3, VS_COLOR_LIGHTGREY);
scale_handle->draw();
}
}
};
}