copy/paste partially. z-index experiments, but not working yet.
This commit is contained in:
+19
-79
@@ -4,14 +4,14 @@
|
||||
#include "datatypes.h"
|
||||
#include "graph-manager.h"
|
||||
#include "midi-node.h"
|
||||
#include "node.h"
|
||||
#include "raylib.h"
|
||||
#include "signal-manager.h"
|
||||
#include "state.h"
|
||||
#include "ui.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
namespace VISEQ::APP {
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace VISEQ::APP {
|
||||
VISEQ::SIGNAL::SignalManager sm;
|
||||
VISEQ::APP::Clipboard cb;
|
||||
|
||||
std::shared_ptr<APP::State> state = APP::State::get();
|
||||
|
||||
UI::AppUI ui;
|
||||
|
||||
void updateMidiPorts(){
|
||||
@@ -42,92 +44,30 @@ namespace VISEQ::APP {
|
||||
}
|
||||
}
|
||||
|
||||
void copyNodesAndConnections(VEC_SPTR_Node nodes, Vec2Df position){
|
||||
|
||||
VEC_SPTR_Edge copy_connections;
|
||||
for(auto c : gm.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 = gm.copyNode(std::dynamic_pointer_cast<MidiNode>(old_node), position + old_node->drag_offset);
|
||||
} else {
|
||||
new_node = gm.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(gm.edges));
|
||||
}
|
||||
|
||||
void removeNodes(VEC_SPTR_Node nodes){
|
||||
|
||||
for(auto n : gm.nodes){
|
||||
n->highlighted = false;
|
||||
}
|
||||
VEC_SPTR_Node adjacent_nodes = gm.getAdjacentNodes(nodes);
|
||||
|
||||
auto erase_connections = gm.edges | RANGE_FILTER([nodes](SPTR_Edge c){ return std::ranges::contains(nodes, c->start) || std::ranges::contains(nodes, c->end);});
|
||||
sm.rerouteSignal(nodes, adjacent_nodes);
|
||||
sm.rebaseSignal(nodes);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
auto reroute_signals = sm.signals | RANGE_FILTER([nodes](SIGNAL::SPTR_Signal s){return std::ranges::contains(nodes, s->next);});
|
||||
|
||||
for(auto s : reroute_signals){
|
||||
float dist = 10000000;
|
||||
SPTR_Node next_node;
|
||||
for(auto n : adjacent_nodes){
|
||||
if(n->position.dist(s->position) < dist) {
|
||||
dist = n->position.dist(s->position);
|
||||
next_node = n;
|
||||
}
|
||||
}
|
||||
s->next = next_node;
|
||||
s->last = next_node;
|
||||
}
|
||||
|
||||
auto rebase_signals = sm.signals | RANGE_FILTER([nodes](SIGNAL::SPTR_Signal s){return std::ranges::contains(nodes, s->start);});
|
||||
|
||||
for(auto s : rebase_signals){
|
||||
s->start = s->next;
|
||||
}
|
||||
|
||||
for(auto n : adjacent_nodes){
|
||||
std::erase_if(n->connections, [n, nodes](VISEQ::GRAPH::EDGES::SPTR_Edge c){ return std::ranges::contains(nodes, c->start) || std::ranges::contains(nodes, c->end);});
|
||||
}
|
||||
|
||||
for(auto n : nodes){
|
||||
std::erase_if(gm.edges, [n](SPTR_Edge c){ return c->start == n || c->end == n;});
|
||||
}
|
||||
std::erase_if(gm.nodes, [nodes](SPTR_Node n){ return std::ranges::contains(nodes, n);});
|
||||
gm.removeNodesAndEdges(nodes);
|
||||
}
|
||||
|
||||
void update(){
|
||||
mutex.lock();
|
||||
updateMidiPorts();
|
||||
mutex.unlock();
|
||||
|
||||
if(KEYS_DOWN.ctrl && IsKeyPressed(KEY_C)){
|
||||
VEC_SPTR_Node selected_nodes = gm.getSelection();
|
||||
if(!selected_nodes.empty()) cb.pushNodes(selected_nodes);
|
||||
}
|
||||
|
||||
if(KEYS_DOWN.ctrl && IsKeyPressed(KEY_V)){
|
||||
VEC_SPTR_Node paste_nodes = cb.pullNodes();
|
||||
if(!paste_nodes.empty()) gm.pasteNodesAndEdges(paste_nodes, MOD_MOUSE);
|
||||
}
|
||||
}
|
||||
|
||||
void draw(Vec2Df mouse_pos, Camera2D camera){
|
||||
|
||||
Reference in New Issue
Block a user