Context menu is back, but not quite yet.

This commit is contained in:
Sebastian
2024-12-05 23:39:01 +01:00
parent 638df54ee6
commit ade33b0608
6 changed files with 30 additions and 9 deletions
+6 -1
View File
@@ -87,8 +87,12 @@ namespace VISEQ::GRAPH {
}
}
void addToSelection(){
auto temp_nodes = nodes | RANGE_FILTER([](SPTR_Node n){return n->selected;}) | std::ranges::to<VEC_SPTR_Node>();
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<VEC_SPTR_Node>();
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<MidiNode> n, Vec2Df position){
std::cout << "copy midinode" << std::endl;
nodes.insert(nodes.end(), std::make_shared<MidiNode>(*n));
nodes.back()->clearConnectors();
nodes.back()->setPosition(position);
return nodes.back();
}
+1 -1
View File
@@ -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<BASE::Interactable> item;
+6 -1
View File
@@ -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;
}
+10 -1
View File
@@ -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++;
+2 -1
View File
@@ -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;
+5 -4
View File
@@ -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<Node> n){ return n->config; })){
void drawContextMenu(Camera2D camera){
for(auto n : gm->getSelection() | std::views::filter([](std::shared_ptr<Node> 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);
}
};