diff --git a/src/app-manager.h b/src/app-manager.h index 8ef75c7..aa537a8 100644 --- a/src/app-manager.h +++ b/src/app-manager.h @@ -12,6 +12,7 @@ #include "mouse.h" #include "node.h" #include "raylib.h" +#include "selectable.h" #include "signal-manager.h" #include "state.h" #include "ui.h" @@ -163,41 +164,55 @@ namespace VISEQ::APP { void doInteraction(){ bool exit = false; + bool once = false; + state->mouse_z = canvas->z_index; + while(event_queue.size() > 0 && !exit){ auto e = event_queue.front(); std::cout << e.item->getType() << " " << e.action << std::endl; + if(e.action == Interaction::HOVER){ + state->mouse_z = e.item->z_index; + std::cout << state->mouse_z << std::endl; + } + if(e.item->getType() == GraphItemType::CANVAS) { if(e.action == Interaction::SELECT) { gm.select(); - std::cout << gm.selected_nodes.size() << std::endl; + std::cout << "app canvas select" << std::endl; canvas->clearSelectionRect(); } - if(e.action == Interaction::DESELECT) gm.deselect(); + if(e.action == Interaction::DESELECT) { + std::cout << "app canvas deselect" << std::endl; + gm.deselect(); + } } - if(e.item->getType() == GraphItemType::NODE){ + if(!once && e.item->getType() == GraphItemType::NODE){ + auto node = std::dynamic_pointer_cast(e.item); if(e.action == Interaction::PICKUP) { - e.item->pickUp(); - if(std::dynamic_pointer_cast(e.item)->selected){ + node->pickUp(); + if(node->selected){ for(auto s : gm.selected_nodes){ - s->pickUp(std::dynamic_pointer_cast(e.item)->position); + s->pickUp(node->position); } } - exit = true; + once = true; } if(e.action == Interaction::DRAG) { - e.item->drag(); - if(std::dynamic_pointer_cast(e.item)->selected){ + if(KEYS_DOWN.ctrl) node->drag(MOD_MOUSE); + else node->drag(MOD_MOUSE + node->drag_offset); + + if(node->selected){ for(auto s : gm.selected_nodes){ - s->drag(); + s->drag(MOD_MOUSE + s->drag_offset); } } - exit = true; + once = true; } if(e.action == Interaction::PUTDOWN) { - e.item->putDown(); - if(std::dynamic_pointer_cast(e.item)->selected){ + node->putDown(); + if(node->selected){ for(auto s : gm.selected_nodes){ s->putDown(); } @@ -206,18 +221,18 @@ namespace VISEQ::APP { } if(exit) break; - if(e.item->getType() == GraphItemType::CONNECTOR || e.item->getType() == GraphItemType::CANVAS) { + if(!once && (e.item->getType() == GraphItemType::CONNECTOR || e.item->getType() == GraphItemType::CANVAS)) { switch(e.action){ case VISEQ::APP::Interaction::PICKUP: { e.item->pickUp(); - exit = true; + once = true; break; } case VISEQ::APP::Interaction::DRAG: { - e.item->drag(); - exit = true; + e.item->drag(MOD_MOUSE); + once = true; break; } case VISEQ::APP::Interaction::PUTDOWN: diff --git a/src/canvas.h b/src/canvas.h index e871425..6c90620 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -7,6 +7,7 @@ #include "draggable.h" #include "raylib.h" #include "raymath.h" +#include "vmath.h" #include namespace VISEQ::APP::CANVAS { @@ -19,22 +20,24 @@ namespace VISEQ::APP::CANVAS { Vec2Df select_start; virtual bool hovering() override { - return true; + return state->mouse_z == z_index; } - virtual void drag() override { + virtual void drag(Vec2Df position) override { Vec2Df select1 = {SCREEN_MOUSE.x > select_start.x ? select_start.x : SCREEN_MOUSE.x, SCREEN_MOUSE.y > select_start.y ? select_start.y : SCREEN_MOUSE.y}; Vec2Df select2 = {SCREEN_MOUSE.x > select_start.x ? SCREEN_MOUSE.x - select_start.x : select_start.x - SCREEN_MOUSE.x, SCREEN_MOUSE.y > select_start.y ? SCREEN_MOUSE.y - select_start.y : select_start.y - SCREEN_MOUSE.y}; state->selection = (Rectangle){select1.x, select1.y, select2.x, select2.y}; } virtual void pickUp() override { + std::cout << "canvas pickUp" << std::endl; BASE::Draggable::pickUp(); select_start = SCREEN_MOUSE; state->pushEvent({getPtr(), Interaction::DESELECT}); } virtual void putDown() override { + std::cout << "canvas putDown" << std::endl; BASE::Draggable::putDown(); state->pushEvent({getPtr(), Interaction::SELECT}); } diff --git a/src/connectable.h b/src/connectable.h index f8f3ebb..d1c7231 100644 --- a/src/connectable.h +++ b/src/connectable.h @@ -1,7 +1,7 @@ #pragma once #include "draggable.h" -#include "state.h" +#include "vmath.h" #include namespace VISEQ::BASE { @@ -19,8 +19,8 @@ namespace VISEQ::BASE { connectables.emplace_back(this); } - virtual void drag() override { - DrawLineV(position, MOD_MOUSE, (Color){229, 181, 103, 255}); + virtual void drag(Vec2Df new_position) override { + DrawLineV(position, new_position, (Color){229, 181, 103, 255}); } void putDown() override { diff --git a/src/connector.h b/src/connector.h index de4a056..c3f17ed 100644 --- a/src/connector.h +++ b/src/connector.h @@ -3,10 +3,12 @@ #include "connectable.h" #include "datatypes.h" #include "graph-item.h" +#include "interaction-event.h" #include "moveable.h" #include "raymath.h" #include "state.h" #include "vmath.h" +#include namespace VISEQ::GRAPH { class Connector : public BASE::Connectable, public GraphItem{ @@ -50,6 +52,7 @@ namespace VISEQ::GRAPH { } 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}); diff --git a/src/draggable.h b/src/draggable.h index 89bd484..018ff43 100644 --- a/src/draggable.h +++ b/src/draggable.h @@ -33,25 +33,17 @@ namespace VISEQ::BASE { } virtual void pickUp() override { - picked_up = true; - drag_offset = position - SCREEN_MOUSE; - } - - virtual void pickUp(Vec2Df selection_origin) override { - picked_up = true; - drag_offset = position - selection_origin; + picked_up = true; + drag_offset = position - SCREEN_MOUSE; } - virtual void drag() override { -// state->selection_origin = position; - /*if(KEYS_PRESSED.ctrl){*/ - /* selection_offset = position - state->selection_origin;*/ - /*}*/ - /*if(KEYS_DOWN.ctrl){*/ - /* position = MOD_MOUSE + selection_offset;*/ - /*} else {*/ - position = MOD_MOUSE + drag_offset; - /*}*/ + virtual void pickUp(Vec2Df selection_origin) override { + picked_up = true; + drag_offset = position - selection_origin; + } + + virtual void drag(Vec2Df new_position) override { + position = new_position; } virtual void putDown() override { @@ -59,8 +51,6 @@ namespace VISEQ::BASE { } virtual bool select() override { - /*in_selection_rect = */ - /*if(MOUSE_LEFT.released) selected = (KEYS_DOWN.shift && selected) || in_selection_rect;*/ return CheckCollisionPointRec(position, state->selection); } diff --git a/src/graph-manager.h b/src/graph-manager.h index 9e8e446..0829a34 100644 --- a/src/graph-manager.h +++ b/src/graph-manager.h @@ -65,6 +65,7 @@ namespace VISEQ::GRAPH { } 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()); @@ -72,6 +73,7 @@ namespace VISEQ::GRAPH { } void deselect(){ + std::cout << "deselect" << std::endl; for(auto s : selected_nodes){ s->selected = false; } @@ -268,6 +270,8 @@ namespace VISEQ::GRAPH { new_node->copied = false; new_node->selected = true; + + //TODO copy connectors for(auto c : copy_connections){ if(c->start == old_node) { diff --git a/src/interactable.h b/src/interactable.h index 15ac897..dbc8a53 100644 --- a/src/interactable.h +++ b/src/interactable.h @@ -39,7 +39,7 @@ namespace VISEQ::BASE { virtual GRAPH::GraphItemType getType() = 0; virtual void pickUp() = 0; virtual void pickUp(Vec2Df position) = 0; - virtual void drag() = 0; + virtual void drag(Vec2Df position) = 0; virtual void putDown() = 0; }; diff --git a/src/node.h b/src/node.h index 01c75c4..4398902 100644 --- a/src/node.h +++ b/src/node.h @@ -25,6 +25,16 @@ namespace VISEQ::GRAPH::NODES { Node() {} Node(float x, float y) : Draggable(Vec2Df(x, y)) {} Node(Vec2Df p) : Draggable(p) {} + + /*Node(const Node& n){*/ + /* distributionMode = n.distributionMode;*/ + /* radius = n.radius;*/ + /* config = n.config;*/ + /* position = n.position;*/ + /* for(auto c : n.connectors){*/ + /* connectors.emplace_back(std::make_shared(*c));*/ + /* }*/ + /*}*/ NodeType nodeType; @@ -68,6 +78,7 @@ namespace VISEQ::GRAPH::NODES { } 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}); diff --git a/src/state.h b/src/state.h index d38d203..e38fb1a 100644 --- a/src/state.h +++ b/src/state.h @@ -67,6 +67,8 @@ namespace VISEQ::APP{ bool hovering = false; + int mouse_z = 0; + MouseState mouse_left; MouseState mouse_right; MouseState mouse_middle;