id is not set correctly, fix needed
This commit is contained in:
@@ -142,6 +142,12 @@ namespace VISEQ::GRAPH {
|
|||||||
return possible_connections.at(return_path)->getNextNode(current);
|
return possible_connections.at(return_path)->getNextNode(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SPTR_Node getClosestNode(Vec2Df position){
|
||||||
|
auto neighbors = nodes | RANGE_FILTER([](SPTR_Node n){ return !n->dragging;}) | std::ranges::to<VEC_SPTR_Node>();
|
||||||
|
std::sort(neighbors.begin(), neighbors.end(), [position](SPTR_Node na, SPTR_Node nb){ return na->position.dist(position) < nb->position.dist(position);});
|
||||||
|
return neighbors.front();
|
||||||
|
}
|
||||||
|
|
||||||
void addConnection(SPTR_Node from, SPTR_Node to){
|
void addConnection(SPTR_Node from, SPTR_Node to){
|
||||||
if(from != to) {
|
if(from != to) {
|
||||||
edges.emplace_back(std::make_shared<Edge>());
|
edges.emplace_back(std::make_shared<Edge>());
|
||||||
|
|||||||
+25
-4
@@ -86,9 +86,15 @@ int main(){
|
|||||||
app.settings = graph.at("settings");
|
app.settings = graph.at("settings");
|
||||||
|
|
||||||
// app.gm = graph["graphmanager"].get<VISEQ::GRAPH::GraphManager>();
|
// app.gm = graph["graphmanager"].get<VISEQ::GRAPH::GraphManager>();
|
||||||
|
int highest_id = 0;
|
||||||
|
std::shared_ptr<Node> hid;
|
||||||
for(auto n : graph.at("graphmanager").at("nodes")){
|
for(auto n : graph.at("graphmanager").at("nodes")){
|
||||||
std::shared_ptr<MidiNode> mn = n;
|
std::shared_ptr<MidiNode> mn = n;
|
||||||
app.gm.nodes.push_back(mn);
|
app.gm.nodes.push_back(mn);
|
||||||
|
if(mn->id > highest_id) {
|
||||||
|
highest_id = mn->id;
|
||||||
|
hid = mn;
|
||||||
|
}
|
||||||
std::cout << std::format("adding node {}", mn->id) << std::endl;
|
std::cout << std::format("adding node {}", mn->id) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,9 +318,25 @@ int main(){
|
|||||||
case InteractionState::CONNECT_NODE:
|
case InteractionState::CONNECT_NODE:
|
||||||
{
|
{
|
||||||
Vec2Df connector_position = connecting_nodes.front()->position - ((connecting_nodes.front()->position - mouse_pos)).norm() * (connecting_nodes.front()->radius + 14.0f);
|
Vec2Df connector_position = connecting_nodes.front()->position - ((connecting_nodes.front()->position - mouse_pos)).norm() * (connecting_nodes.front()->radius + 14.0f);
|
||||||
|
Vec2Df target_position = mouse_pos;
|
||||||
|
|
||||||
|
if(IsKeyDown(KEY_LEFT_CONTROL)) {
|
||||||
|
target_position.x = round((mouse_pos.x) / app.settings.grid) * app.settings.grid;
|
||||||
|
target_position.y = round((mouse_pos.y) / app.settings.grid) * app.settings.grid;
|
||||||
|
} else if(IsKeyDown(KEY_LEFT_SHIFT)){
|
||||||
|
std::shared_ptr<Node> closest = app.gm.getClosestNode(mouse_pos);
|
||||||
|
float steps = round((closest->position.dist(mouse_pos)) / app.settings.grid) * app.settings.grid;
|
||||||
|
float pol_r = steps;
|
||||||
|
float pol_theta = Vector2Angle(Vec2Df{1,0},(mouse_pos - closest->position));
|
||||||
|
|
||||||
|
Vec2Df polar = VISEQ::VMATH::polarToCartesian(pol_r, pol_theta);
|
||||||
|
target_position = closest->position + polar;
|
||||||
|
} else {
|
||||||
|
target_position = mouse_pos;
|
||||||
|
}
|
||||||
|
|
||||||
if(connecting_nodes.front()->connecting && mouse_down){
|
if(connecting_nodes.front()->connecting && mouse_down){
|
||||||
DrawLine(connector_position.x, connector_position.y, mouse_pos.x, mouse_pos.y, (Color){229, 181, 103, 255});
|
DrawLine(connector_position.x, connector_position.y, target_position.x, target_position.y, (Color){229, 181, 103, 255});
|
||||||
connecting_nodes.front()->hovering = true;
|
connecting_nodes.front()->hovering = true;
|
||||||
connecting_nodes.front()->hover_connect = true;
|
connecting_nodes.front()->hover_connect = true;
|
||||||
}
|
}
|
||||||
@@ -332,8 +354,7 @@ int main(){
|
|||||||
} else if(!hovering_connectors.empty()){
|
} else if(!hovering_connectors.empty()){
|
||||||
app.gm.addConnection(connecting_nodes.front(), hovering_connectors.front());
|
app.gm.addConnection(connecting_nodes.front(), hovering_connectors.front());
|
||||||
} else {
|
} else {
|
||||||
//SPTR_Node new_node = app.gm.addMidiNode(mouse_pos);
|
SPTR_Node new_node = app.gm.copyNode(std::dynamic_pointer_cast<MidiNode>(connecting_nodes.front()), target_position);
|
||||||
SPTR_Node new_node = app.gm.copyNode(std::dynamic_pointer_cast<MidiNode>(connecting_nodes.front()), mouse_pos);
|
|
||||||
new_node->connecting = false;
|
new_node->connecting = false;
|
||||||
app.gm.addConnection(connecting_nodes.front(), new_node);
|
app.gm.addConnection(connecting_nodes.front(), new_node);
|
||||||
}
|
}
|
||||||
@@ -422,7 +443,7 @@ int main(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(hovering_nodes.empty()){
|
if(!IsKeyDown(KEY_LEFT_SHIFT) && !IsKeyDown(KEY_LEFT_CONTROL) && !IsKeyDown(KEY_LEFT_ALT)){
|
||||||
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
|
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
|
||||||
camera.offset = GetMousePosition();
|
camera.offset = GetMousePosition();
|
||||||
camera.target = mouseWorldPos;
|
camera.target = mouseWorldPos;
|
||||||
|
|||||||
Reference in New Issue
Block a user