Connecting works again (almost). Connectors need to be copied when splitting edges.
This commit is contained in:
+3
-10
@@ -63,7 +63,7 @@ namespace VISEQ::APP {
|
||||
json graph = json::parse(f);
|
||||
|
||||
for(auto n : graph.at("gm").at("nodes")){
|
||||
gm->addNodeAndUpdate(n.template get<std::shared_ptr<MidiNode>>());
|
||||
gm->addNode(n.template get<std::shared_ptr<MidiNode>>());
|
||||
}
|
||||
|
||||
int highest_id = 0;
|
||||
@@ -82,13 +82,6 @@ namespace VISEQ::APP {
|
||||
}
|
||||
}
|
||||
|
||||
for(auto n : graph.at("gm").at("nodes")){
|
||||
std::shared_ptr<MidiNode> mn = n;
|
||||
gm->addNode(mn);
|
||||
//app.gm->nodes.push_back(mn);
|
||||
std::cout << std::format("adding node {}", mn->id) << std::endl;
|
||||
}
|
||||
|
||||
for(auto e : graph.at("gm").at("edges")){
|
||||
int start_id = e.at("start").get<int>();
|
||||
int end_id = e.at("end").get<int>();
|
||||
@@ -126,10 +119,10 @@ namespace VISEQ::APP {
|
||||
|
||||
} else {
|
||||
for(int i = 0; i < 4; ++i){
|
||||
gm->addMidiNode(Vec2Df{(float)i * state->settings.grid*4 + 7 * state->settings.grid, 2 * state->settings.grid*4});
|
||||
gm->createMidiNode(Vec2Df{(float)i * state->settings.grid*4 + 7 * state->settings.grid, 2 * state->settings.grid*4});
|
||||
}
|
||||
for(int i = 3; i >= 0; --i){
|
||||
gm->addMidiNode(Vec2Df{(float)i * state->settings.grid*4 + 7 * state->settings.grid, 3 * state->settings.grid*4});
|
||||
gm->createMidiNode(Vec2Df{(float)i * state->settings.grid*4 + 7 * state->settings.grid, 3 * state->settings.grid*4});
|
||||
}
|
||||
|
||||
for(int i = 0; i < 8; ++i){
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace VISEQ::BASE {
|
||||
|
||||
bool new_partner = false;
|
||||
bool connecting = false;
|
||||
bool connected = false;
|
||||
|
||||
Vec2Df connecting_position;
|
||||
|
||||
virtual void drag(Vec2Df new_position) override {
|
||||
@@ -29,6 +31,7 @@ namespace VISEQ::BASE {
|
||||
virtual void connect() {
|
||||
if(picked_up){
|
||||
connecting = false;
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -20,7 +20,7 @@ namespace VISEQ::GRAPH {
|
||||
setParent(parent);
|
||||
}
|
||||
|
||||
std::shared_ptr<GraphItem> parent;
|
||||
std::weak_ptr<GraphItem> parent;
|
||||
|
||||
bool passable = false;
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace VISEQ::GRAPH {
|
||||
}
|
||||
|
||||
virtual bool hovering() override {
|
||||
return !partner.expired() && CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
|
||||
return partner.expired() && CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
|
||||
}
|
||||
|
||||
void setParent(std::shared_ptr<GraphItem> _parent){
|
||||
@@ -53,6 +53,10 @@ namespace VISEQ::GRAPH {
|
||||
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
|
||||
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
|
||||
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::PUTDOWN});
|
||||
if(connected) {
|
||||
state->pushEvent({getPtr(), APP::Interaction::CONNECT});
|
||||
connected = false;
|
||||
}
|
||||
|
||||
if(partner.expired()) position = center_position - ((center_position - SCREEN_MOUSE)).norm() * (radius + orbit);
|
||||
if(!partner.expired()) position = center_position - ((center_position - partner.lock()->position)).norm() * (radius + orbit);
|
||||
|
||||
+3
-6
@@ -59,8 +59,9 @@ namespace VISEQ::GRAPH {
|
||||
return nodes.size();
|
||||
}
|
||||
|
||||
void addMidiNode(Vec2Df position){
|
||||
void createMidiNode(Vec2Df position){
|
||||
nodes.emplace_back(std::make_shared<MidiNode>(position));
|
||||
nodes.back()->update();
|
||||
}
|
||||
|
||||
void setMidiPortForAll(int number, bool _state){
|
||||
@@ -71,10 +72,6 @@ namespace VISEQ::GRAPH {
|
||||
|
||||
void addNode(SPTR_Node node){
|
||||
nodes.insert(nodes.end(), node);
|
||||
}
|
||||
|
||||
void addNodeAndUpdate(SPTR_Node node){
|
||||
addNode(node);
|
||||
node->update();
|
||||
}
|
||||
|
||||
@@ -242,7 +239,7 @@ namespace VISEQ::GRAPH {
|
||||
void splitEdges(){
|
||||
for(auto s : split_edges){
|
||||
Vec2Df center = s.lock()->end.lock()->position.center(s.lock()->start.lock()->position);
|
||||
SPTR_Node cn = copyNode(std::dynamic_pointer_cast<MidiNode>(s.lock()->start.lock()), center);
|
||||
SPTR_Node cn = copyNode(std::dynamic_pointer_cast<MidiNode>(s.lock()->start.lock()), center); // TODO: copy connectors
|
||||
addConnection(s.lock()->start.lock(), cn);
|
||||
addConnection(cn, s.lock()->end.lock());
|
||||
remove_edges.push_back(s);
|
||||
|
||||
@@ -13,5 +13,9 @@ namespace VISEQ::APP{
|
||||
Interaction action;
|
||||
};
|
||||
|
||||
inline static std::deque<VISEQ::APP::InteractionEvent> event_queue;
|
||||
inline bool operator==(const InteractionEvent& lhs, const InteractionEvent& rhs){
|
||||
return lhs.item == rhs.item;
|
||||
}
|
||||
|
||||
inline static std::deque<APP::InteractionEvent> event_queue;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "state.h"
|
||||
#include "canvas.h"
|
||||
#include <algorithm>
|
||||
#include <execution>
|
||||
#include <memory>
|
||||
|
||||
namespace VISEQ::INTERACTION{
|
||||
@@ -184,15 +185,31 @@ namespace VISEQ::INTERACTION{
|
||||
|
||||
state->mouse_z = canvas->z_index;
|
||||
|
||||
while(APP::event_queue.size() > 0 && !exit){
|
||||
auto e = APP::event_queue.front();
|
||||
|
||||
for(auto e : APP::event_queue){
|
||||
if(!connect_once && e.action == APP::Interaction::CONNECT){
|
||||
APP::InteractionEvent partner;
|
||||
bool found = false;
|
||||
for(auto ei : APP::event_queue){
|
||||
if(ei.action == APP::Interaction::HOVER && ei.item->getType() == GraphItemType::CONNECTOR) {
|
||||
std::cout << "YEAH" << std::endl;
|
||||
partner = ei;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found && partner != e){
|
||||
auto connector = std::dynamic_pointer_cast<Connector>(e.item);
|
||||
auto connector_to = std::dynamic_pointer_cast<Connector>(connector->partner.lock());
|
||||
gm->addConnection(std::dynamic_pointer_cast<Node>(connector->parent), std::dynamic_pointer_cast<Node>(connector_to->parent));
|
||||
auto connector_to = std::dynamic_pointer_cast<Connector>(partner.item);
|
||||
connector->partner = connector_to;
|
||||
connector_to->partner = connector;
|
||||
gm->addConnection(std::dynamic_pointer_cast<Node>(connector->parent.lock()), std::dynamic_pointer_cast<Node>(connector_to->parent.lock()));
|
||||
connect_once = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while(APP::event_queue.size() > 0 && !exit){
|
||||
auto e = APP::event_queue.front();
|
||||
|
||||
if(e.action == APP::Interaction::HOVER){
|
||||
state->mouse_z = e.item->z_index;
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace VISEQ::APP::UI{
|
||||
int s_nodes = s_signal + 70 + signal_configs*20;
|
||||
GuiLabel((Rectangle){20, (float)s_nodes + 30, 240, 20}, "NODES");
|
||||
if(GuiButton((Rectangle){20, (float)s_nodes + 60, 240, 20}, "ADD RANDOM NODE")){
|
||||
gm->addMidiNode(Vec2Df{200.0f, 200.0f});
|
||||
gm->createMidiNode(Vec2Df{200.0f, 200.0f});
|
||||
}
|
||||
DrawText(std::format("{}", gm->getNodesSize()).c_str(), 20, state->settings.height - 70, 15, VS_COLOR_WHITE);
|
||||
DrawFPS(20, state->settings.height - 30);
|
||||
|
||||
Reference in New Issue
Block a user