From ade33b06083c1a1c82207ecaabc5a39a074e8acd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 5 Dec 2024 23:39:01 +0100 Subject: [PATCH] Context menu is back, but not quite yet. --- src/graph-manager.h | 7 ++++++- src/interaction-event.h | 2 +- src/interaction-manager.h | 7 ++++++- src/node.h | 11 ++++++++++- src/state.h | 3 ++- src/ui.h | 9 +++++---- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/graph-manager.h b/src/graph-manager.h index 5be79b8..0ec83f7 100644 --- a/src/graph-manager.h +++ b/src/graph-manager.h @@ -87,8 +87,12 @@ namespace VISEQ::GRAPH { } } + void addToSelection(){ + auto temp_nodes = nodes | RANGE_FILTER([](SPTR_Node n){return n->selected;}) | std::ranges::to(); + selected_nodes.insert(selected_nodes.end(), temp_nodes.begin(), temp_nodes.end()); + } + void select(){ - std::cout << "select" << std::endl; auto temp_nodes = nodes | RANGE_FILTER([](SPTR_Node n){return n->select();}) | std::ranges::to(); if(!KEYS_DOWN.shift) selected_nodes.clear(); selected_nodes.insert(selected_nodes.end(), temp_nodes.begin(), temp_nodes.end()); @@ -143,6 +147,7 @@ namespace VISEQ::GRAPH { SPTR_Node copyNode(std::shared_ptr n, Vec2Df position){ std::cout << "copy midinode" << std::endl; nodes.insert(nodes.end(), std::make_shared(*n)); + nodes.back()->clearConnectors(); nodes.back()->setPosition(position); return nodes.back(); } diff --git a/src/interaction-event.h b/src/interaction-event.h index 8668147..5431f20 100644 --- a/src/interaction-event.h +++ b/src/interaction-event.h @@ -6,7 +6,7 @@ namespace VISEQ::APP{ - enum Interaction {NONE, HOVER, CLICK, HOLD, RELEASE, PICKUP, DRAG, PUTDOWN, SELECT, DESELECT, CONNECT}; + enum Interaction {NONE, HOVER, CLICK, RIGHTCLICK, HOLD, RELEASE, PICKUP, DRAG, PUTDOWN, SELECT, DESELECT, CONNECT}; struct InteractionEvent{ std::shared_ptr item; diff --git a/src/interaction-manager.h b/src/interaction-manager.h index ef7c010..8632a55 100644 --- a/src/interaction-manager.h +++ b/src/interaction-manager.h @@ -210,7 +210,12 @@ namespace VISEQ::INTERACTION{ while(APP::event_queue.size() > 0 && !exit){ auto e = APP::event_queue.front(); - + if(e.action == APP::Interaction::RIGHTCLICK){ + gm->addToSelection(); + state->context_menu = !state->context_menu; + } + if(state->context_menu) break; + if(e.action == APP::Interaction::HOVER){ state->mouse_z = e.item->z_index; } diff --git a/src/node.h b/src/node.h index a599a97..230404e 100644 --- a/src/node.h +++ b/src/node.h @@ -67,12 +67,21 @@ namespace VISEQ::GRAPH::NODES { return GraphItemType::NODE; } + void clearConnectors(){ + connectors.clear(); + update(); + } + void update() override{ if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER}); 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(hovering() && MOUSE_RIGHT.clicked) { + selected = true; + config = true; + state->pushEvent({getPtr(), APP::Interaction::RIGHTCLICK}); + } int free_connectors = 0; for(auto c : connectors){ if(c->partner.expired()) free_connectors++; diff --git a/src/state.h b/src/state.h index 14c38f1..fb5208a 100644 --- a/src/state.h +++ b/src/state.h @@ -64,7 +64,8 @@ namespace VISEQ::APP{ InteractionState old_istate = HOVER_CANVAS; int node_mode = 0; - + bool context_menu = false; + bool hovering = false; int mouse_z = 0; diff --git a/src/ui.h b/src/ui.h index 5e3b669..992e0ba 100644 --- a/src/ui.h +++ b/src/ui.h @@ -103,11 +103,12 @@ namespace VISEQ::APP::UI{ DrawText(text.c_str(), position.x-offset/2.0f, position.y-(float)size/2.0f+1, size, color ); } - void drawPerNodeConfig(Camera2D camera){ - for(auto& n : gm->getSelection() | std::views::filter([](std::shared_ptr n){ return n->config; })){ + void drawContextMenu(Camera2D camera){ + for(auto n : gm->getSelection() | std::views::filter([](std::shared_ptr n){ return n->config; })){ Vector2 np = GetWorldToScreen2D((Vector2){n->position.x, n->position.y}, camera); - n->config = !GuiWindowBox((Rectangle){np.x + 10, np.y + 10, 240, 440}, "config"); + state->context_menu = !GuiWindowBox((Rectangle){np.x + 10, np.y + 10, 240, 440}, "config"); + n->config = state->context_menu; int option = n->distributionMode; GuiToggleGroup((Rectangle){ np.x + 20, np.y + 40, 73, 20 }, "GEO;RR;RAND", &option); @@ -195,7 +196,7 @@ namespace VISEQ::APP::UI{ void draw(Vec2Df mouse_pos, Camera2D camera){ drawSideBar(); - drawPerNodeConfig(camera); + if(state->context_menu) drawContextMenu(camera); } };