diff --git a/src/app-manager.h b/src/app-manager.h index 08f2507..473c922 100644 --- a/src/app-manager.h +++ b/src/app-manager.h @@ -4,6 +4,7 @@ #include "datatypes.h" #include "graph-manager.h" #include "midi-node.h" +#include "mouse.h" #include "node.h" #include "raylib.h" #include "signal-manager.h" @@ -18,13 +19,14 @@ namespace VISEQ::APP { class AppManager{ public: - AppManager() : sm(&gm, &mutex), ui(&sm, &gm) {} + AppManager() : sm(&gm, &mutex), mouse(std::make_shared(gm)), ui(&sm, &gm) {} std::mutex mutex; VISEQ::GRAPH::GraphManager gm; VISEQ::SIGNAL::SignalManager sm; VISEQ::APP::Clipboard cb; + VISEQ::APP::Mouse mouse; std::shared_ptr state = APP::State::get(); diff --git a/src/connectable.h b/src/connectable.h index d7d8e31..fb232b9 100644 --- a/src/connectable.h +++ b/src/connectable.h @@ -1,6 +1,7 @@ #pragma once #include "draggable.h" +#include "state.h" #include namespace VISEQ::BASE { @@ -23,10 +24,12 @@ namespace VISEQ::BASE { } void update() override{ - Draggable::update(); - if(pickedUp()) drag(); - if(released()) putDown(); - is_hovering = hovering(); + if(STATE != IState::DRAG_NODE){ + Draggable::update(); + if(pickedUp()) drag(); + if(released()) putDown(); + // is_hovering = hovering(); + } } void putDown() override { diff --git a/src/draggable.h b/src/draggable.h index 4e7be14..794bb63 100644 --- a/src/draggable.h +++ b/src/draggable.h @@ -56,7 +56,7 @@ namespace VISEQ::BASE { virtual void update() override { if(STATE != IState::HOVER_NODE) select(); - if(hovering() && z_index > z_hovering) z_hovering = z_index; + if((pickedUp() || hovering()) && z_hovering == -1) z_hovering = z_index; if(z_index == z_hovering || selected){ if(pickedUp()){ @@ -67,15 +67,18 @@ namespace VISEQ::BASE { if(STATE != IState::DRAG_NODE){ if(entered()){ STATE = IState::HOVER_NODE; + std::cout << "z_index=" << z_index << " z_hovering=" << z_hovering << std::endl; + is_hovering = true; } if(exited()){ STATE = IState::HOVER_CANVAS; + is_hovering = false; } } if(released() && picked_up){ - std::cout << z_hovering << std::endl; putDown(); STATE = IState::HOVER_CANVAS; + if(hovering()) STATE = IState::HOVER_NODE; } } }; diff --git a/src/graph-manager.h b/src/graph-manager.h index 99137c2..e026a4e 100644 --- a/src/graph-manager.h +++ b/src/graph-manager.h @@ -378,7 +378,7 @@ namespace VISEQ::GRAPH { for(auto n : nodes){ if(KEYS_PRESSED.ctrl && n->hovering()) state->hover_position = n->position; } - BASE::Interactable::is_hovering = false; + BASE::Interactable::z_hovering = -1; for(auto n : nodes){ n->update(); if(n->picked_up) drawNeighborLines(n, mouse_pos, camera); diff --git a/src/interactable.h b/src/interactable.h index a0161b5..e25fc55 100644 --- a/src/interactable.h +++ b/src/interactable.h @@ -5,12 +5,17 @@ namespace VISEQ::BASE { class Interactable{ public: - Interactable() {z_index++;} + Interactable() { + static int _z_index = 0; + z_index = _z_index; + _z_index++; + } + virtual ~Interactable() {} - inline static bool is_hovering = false; + bool is_hovering = false; - inline static int z_index = 0; + int z_index = 0; inline static int z_hovering = 0; virtual bool hovering() = 0; diff --git a/src/midi-node.h b/src/midi-node.h index 0a4658b..13b2539 100644 --- a/src/midi-node.h +++ b/src/midi-node.h @@ -101,7 +101,7 @@ namespace VISEQ::GRAPH::NODES { break;} }; if(midi_note < 0 ) midi_note = VISEQ::MIDI::Notes.size()-1; - if(midi_note >= VISEQ::MIDI::Notes.size() ) midi_note = 0; + if(midi_note >= VISEQ::MIDI::Notes.size()) midi_note = 0; if(midi_cc < 0 ) midi_cc = 127; if(midi_cc > 127 ) midi_cc = 0; diff --git a/src/mouse.h b/src/mouse.h new file mode 100644 index 0000000..539cb29 --- /dev/null +++ b/src/mouse.h @@ -0,0 +1,16 @@ +#pragma once + +#include "graph-manager.h" +#include +namespace VISEQ::APP { + class Mouse { + public: + Mouse(std::shared_ptr gm) : gm(gm) {} + + std::shared_ptr gm; + + void update(){ + auto hovering_nodes = gm->nodes | RANGE_FILTER([](SPTR_Node n) { return n->hovering();}); + } + }; +} diff --git a/src/node.h b/src/node.h index 3ceddd1..008d782 100644 --- a/src/node.h +++ b/src/node.h @@ -69,7 +69,7 @@ namespace VISEQ::GRAPH::NODES { c->update(); } if(free_connectors == 0) addConnector(); - is_hovering = hovering(); + /*is_hovering = hovering();*/ } void draw(Vec2Df mp, Camera2D cam) override {}