copy/paste partially. z-index experiments, but not working yet.

This commit is contained in:
Sebastian
2024-11-21 02:03:32 +01:00
parent df91a1b107
commit bfc14d5f6e
10 changed files with 172 additions and 139 deletions
+75 -3
View File
@@ -2,6 +2,7 @@
#include "datatypes.h"
#include "draggable.h"
#include "state.h"
#include "vmath.h"
#include "raylib.h"
@@ -62,7 +63,11 @@ namespace VISEQ::GRAPH {
std::ranges::sample(edges, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
return std::dynamic_pointer_cast<VISEQ::GRAPH::EDGES::Edge>(o.front());
}
VEC_SPTR_Node getSelection(){
return nodes | RANGE_FILTER([](SPTR_Node n){return n->selected;}) | std::ranges::to<VEC_SPTR_Node>();
}
void addNode(SPTR_Node node){
nodes.insert(nodes.end(), node);
nodes.back()->init();
@@ -197,6 +202,72 @@ namespace VISEQ::GRAPH {
remove_edges.clear();
}
VEC_SPTR_Node getAdjacentNodes(VEC_SPTR_Node selected_nodes){
for(auto n : nodes){
n->highlighted = false;
}
auto erase_connections = edges | RANGE_FILTER([selected_nodes](SPTR_Edge c){ return std::ranges::contains(selected_nodes, c->start) || std::ranges::contains(selected_nodes, c->end);});
VEC_SPTR_Node adjacent_nodes;
for(auto c : erase_connections){
if(!c->start->selected) adjacent_nodes.push_back(c->start);
if(!c->end->selected) adjacent_nodes.push_back(c->end);
}
return adjacent_nodes;
}
void removeNodesAndEdges(VEC_SPTR_Node selected_nodes){
VEC_SPTR_Node adjacent_nodes = getAdjacentNodes(selected_nodes);
for(auto n : adjacent_nodes){
std::erase_if(n->connections, [n, selected_nodes](VISEQ::GRAPH::EDGES::SPTR_Edge c){ return std::ranges::contains(selected_nodes, c->start) || std::ranges::contains(selected_nodes, c->end);});
}
for(auto n : selected_nodes){
std::erase_if(this->edges, [n](SPTR_Edge c){ return c->start == n || c->end == n;});
}
std::erase_if(this->nodes, [selected_nodes](SPTR_Node n){ return std::ranges::contains(selected_nodes, n);});
}
void pasteNodesAndEdges(VEC_SPTR_Node nodes, Vec2Df position){
VEC_SPTR_Edge copy_connections;
for(auto c : edges){
if(std::ranges::contains(nodes, c->start) && std::ranges::contains(nodes, c->end)) {
copy_connections.push_back(std::make_shared<Edge>(*c));
}
}
std::cout << copy_connections.size() << std::endl;
for(auto old_node : nodes){
SPTR_Node new_node;
if(old_node->getNodeType() == NodeType::MIDINODE) {
new_node = copyNode(std::dynamic_pointer_cast<MidiNode>(old_node), position + old_node->drag_offset);
} else {
new_node = copyNode(old_node, position + old_node->drag_offset);
}
new_node->copied = false;
new_node->selected = true;
for(auto c : copy_connections){
if(c->start == old_node) {
c->start = new_node;
c->start->connections.push_back(c);
}
if(c->end == old_node) {
c->end = new_node;
c->end->connections.push_back(c);
}
}
}
std::ranges::copy(copy_connections.begin(), copy_connections.end(), std::back_inserter(edges));
}
void drawEdges(Vec2Df mouse_pos, Camera2D cam){
if(!remove_edges.empty()) removeEdges();
if(!split_edges.empty()) splitEdges();
@@ -205,8 +276,8 @@ namespace VISEQ::GRAPH {
Vec2Df v2_position = c->end->position - ((c->end->position - c->start->position)).norm() * (c->end->radius + c->connector_offset);
float v1_v2_distance = v1_position.dist(&v2_position);
float midi_gate_v1 = Clamp((4.f / 1000.f) * c->start->GGate(), 1.f, 4.f);
float midi_gate_v2 = Clamp((4.f / 1000.f) * c->end->GGate(), 1.f, 4.f);
float midi_gate_v1 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast<MidiNode>(c->start)->GGate(), 1.f, 4.f);
float midi_gate_v2 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast<MidiNode>(c->end)->GGate(), 1.f, 4.f);
// Line with small connector circles
Color col = {229, 181, 103, 255};
@@ -307,6 +378,7 @@ namespace VISEQ::GRAPH {
for(auto n : nodes){
if(KEYS_PRESSED.ctrl && n->hovering()) state->hover_position = n->position;
}
BASE::Interactable::is_hovering = false;
for(auto n : nodes){
n->update();
if(n->picked_up) drawNeighborLines(n, mouse_pos, camera);