Running again after weak_ptr refactoring. No connecting of nodes atm. Copy/Paste might not work, too.

This commit is contained in:
Sebastian
2024-12-04 01:43:06 +01:00
parent 1fde652495
commit 036c6f4723
11 changed files with 150 additions and 104 deletions
+16 -17
View File
@@ -52,11 +52,12 @@ namespace VISEQ::INTERACTION{
class InteractionManager{
public:
InteractionManager(GRAPH::GraphManager *gm, SIGNAL::SignalManager *sm, std::shared_ptr<APP::CANVAS::Canvas> canvas) : canvas(canvas), gm(gm), sm(sm) {}
InteractionManager() {}
InteractionManager(std::shared_ptr<GRAPH::GraphManager> gm, std::shared_ptr<SIGNAL::SignalManager> sm, std::shared_ptr<APP::CANVAS::Canvas> canvas) : canvas(canvas), gm(gm), sm(sm) {}
std::shared_ptr<APP::CANVAS::Canvas> canvas;
GraphManager *gm;
SIGNAL::SignalManager *sm;
std::shared_ptr<GraphManager> gm;
std::shared_ptr<SIGNAL::SignalManager> sm;
VISEQ::APP::Clipboard cb;
std::shared_ptr<APP::State> state = APP::State::get();
@@ -66,7 +67,7 @@ namespace VISEQ::INTERACTION{
void update(){
if(KEYS_DOWN.ctrl && IsKeyPressed(KEY_C)){
VEC_WPTR_Node selected_nodes = gm->getSelection();
VEC_SPTR_Node selected_nodes = gm->getCopiesOfSelectedNodes();
if(!selected_nodes.empty()) cb.copyNodes(selected_nodes);
}
@@ -76,7 +77,7 @@ namespace VISEQ::INTERACTION{
}
if(IsKeyPressed(KEY_DELETE)){
removeNodes(gm->selected_nodes | std::ranges::to<VEC_SPTR_Node>());
removeNodes(gm->getSelection());
}
if(IsKeyPressed(KEY_TAB)) {
@@ -88,7 +89,7 @@ namespace VISEQ::INTERACTION{
void draw(){
doInteraction();
scaleSelection();
if(!gm->selected_nodes.empty()){
if(!gm->getSelection().empty()){
DrawRectangleRoundedLines(state->bounding_box, 0.1f, 3, VS_COLOR_LIGHTGREY);
scale_handle->draw();
}
@@ -96,7 +97,7 @@ namespace VISEQ::INTERACTION{
void removeNodes(VEC_SPTR_Node nodes){
VEC_SPTR_Node adjacent_nodes = gm->getAdjacentNodes(nodes);
VEC_WPTR_Node adjacent_nodes = gm->getAdjacentNodes(nodes);
sm->rerouteSignal(nodes, adjacent_nodes);
sm->rebaseSignal(nodes);
@@ -105,14 +106,14 @@ namespace VISEQ::INTERACTION{
}
void scaleSelection(){
if(!gm->selected_nodes.empty()){
if(!gm->getSelection().empty()){
float offset = 30;
Vec2Df corner_tl = {50000, 50000};
Vec2Df corner_br = {-50000, -50000};
std::shared_ptr<Node> node_tl;
std::shared_ptr<Node> node_br;
for(auto n : gm->selected_nodes){
for(auto n : gm->getSelection()){
float x = n->position.x;
float y = n->position.y;
@@ -132,7 +133,7 @@ namespace VISEQ::INTERACTION{
if(scale_handle->clicked()){
scale_start = (corner_br - corner_tl);
for(auto n : gm->selected_nodes){
for(auto n : gm->getSelection()){
n->drag_offset = n->position - node_tl->position;
}
}
@@ -140,7 +141,7 @@ namespace VISEQ::INTERACTION{
Vec2Df scale = (scale_handle->position - corner_tl) / scale_start;
if(IsKeyDown(KEY_LEFT_SHIFT)) scale.y = scale.x;
DrawText(std::format("{:.2f} {:.2f}", scale.x, scale.y).c_str(), corner_br.x+5, corner_br.y+5, 10, RED);
for(auto n : gm->selected_nodes){
for(auto n : gm->getSelection()){
n->position = node_tl->position + (n->drag_offset * scale);
}
} else {
@@ -185,13 +186,11 @@ namespace VISEQ::INTERACTION{
while(APP::event_queue.size() > 0 && !exit){
auto e = APP::event_queue.front();
//std::cout << e.item->getType() << " " << e.action << std::endl;
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);
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));
std::cout << "connector use count: " << connector->getPtr().use_count() << std::endl;
connect_once = true;
}
@@ -214,7 +213,7 @@ namespace VISEQ::INTERACTION{
if(e.action == APP::Interaction::PICKUP) {
node->pickUp();
if(node->selected){
for(auto s : gm->selected_nodes){
for(auto s : gm->getSelection()){
s->pickUp(node->position);
}
}
@@ -228,7 +227,7 @@ namespace VISEQ::INTERACTION{
else node->drag(MOD_MOUSE + node->drag_offset);
if(node->selected){
for(auto s : gm->selected_nodes){
for(auto s : gm->getSelection()){
s->drag(MOD_MOUSE + s->drag_offset);
}
}
@@ -237,7 +236,7 @@ namespace VISEQ::INTERACTION{
if(e.action == APP::Interaction::PUTDOWN) {
node->putDown();
if(node->selected){
for(auto s : gm->selected_nodes){
for(auto s : gm->getSelection()){
s->putDown();
}
}