Introduction of mouse.h for z-index mouse events

This commit is contained in:
Sebastian
2024-11-21 23:58:35 +01:00
parent bfc14d5f6e
commit a6b6ff1d16
8 changed files with 42 additions and 13 deletions
+3 -1
View File
@@ -4,6 +4,7 @@
#include "datatypes.h" #include "datatypes.h"
#include "graph-manager.h" #include "graph-manager.h"
#include "midi-node.h" #include "midi-node.h"
#include "mouse.h"
#include "node.h" #include "node.h"
#include "raylib.h" #include "raylib.h"
#include "signal-manager.h" #include "signal-manager.h"
@@ -18,13 +19,14 @@ namespace VISEQ::APP {
class AppManager{ class AppManager{
public: public:
AppManager() : sm(&gm, &mutex), ui(&sm, &gm) {} AppManager() : sm(&gm, &mutex), mouse(std::make_shared<GraphManager>(gm)), ui(&sm, &gm) {}
std::mutex mutex; std::mutex mutex;
VISEQ::GRAPH::GraphManager gm; VISEQ::GRAPH::GraphManager gm;
VISEQ::SIGNAL::SignalManager sm; VISEQ::SIGNAL::SignalManager sm;
VISEQ::APP::Clipboard cb; VISEQ::APP::Clipboard cb;
VISEQ::APP::Mouse mouse;
std::shared_ptr<APP::State> state = APP::State::get(); std::shared_ptr<APP::State> state = APP::State::get();
+4 -1
View File
@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "draggable.h" #include "draggable.h"
#include "state.h"
#include <memory> #include <memory>
namespace VISEQ::BASE { namespace VISEQ::BASE {
@@ -23,10 +24,12 @@ namespace VISEQ::BASE {
} }
void update() override{ void update() override{
if(STATE != IState::DRAG_NODE){
Draggable::update(); Draggable::update();
if(pickedUp()) drag(); if(pickedUp()) drag();
if(released()) putDown(); if(released()) putDown();
is_hovering = hovering(); // is_hovering = hovering();
}
} }
void putDown() override { void putDown() override {
+5 -2
View File
@@ -56,7 +56,7 @@ namespace VISEQ::BASE {
virtual void update() override { virtual void update() override {
if(STATE != IState::HOVER_NODE) select(); 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(z_index == z_hovering || selected){
if(pickedUp()){ if(pickedUp()){
@@ -67,15 +67,18 @@ namespace VISEQ::BASE {
if(STATE != IState::DRAG_NODE){ if(STATE != IState::DRAG_NODE){
if(entered()){ if(entered()){
STATE = IState::HOVER_NODE; STATE = IState::HOVER_NODE;
std::cout << "z_index=" << z_index << " z_hovering=" << z_hovering << std::endl;
is_hovering = true;
} }
if(exited()){ if(exited()){
STATE = IState::HOVER_CANVAS; STATE = IState::HOVER_CANVAS;
is_hovering = false;
} }
} }
if(released() && picked_up){ if(released() && picked_up){
std::cout << z_hovering << std::endl;
putDown(); putDown();
STATE = IState::HOVER_CANVAS; STATE = IState::HOVER_CANVAS;
if(hovering()) STATE = IState::HOVER_NODE;
} }
} }
}; };
+1 -1
View File
@@ -378,7 +378,7 @@ namespace VISEQ::GRAPH {
for(auto n : nodes){ for(auto n : nodes){
if(KEYS_PRESSED.ctrl && n->hovering()) state->hover_position = n->position; 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){ for(auto n : nodes){
n->update(); n->update();
if(n->picked_up) drawNeighborLines(n, mouse_pos, camera); if(n->picked_up) drawNeighborLines(n, mouse_pos, camera);
+8 -3
View File
@@ -5,12 +5,17 @@ namespace VISEQ::BASE {
class Interactable{ class Interactable{
public: public:
Interactable() {z_index++;} Interactable() {
static int _z_index = 0;
z_index = _z_index;
_z_index++;
}
virtual ~Interactable() {} 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; inline static int z_hovering = 0;
virtual bool hovering() = 0; virtual bool hovering() = 0;
+1 -1
View File
@@ -101,7 +101,7 @@ namespace VISEQ::GRAPH::NODES {
break;} break;}
}; };
if(midi_note < 0 ) midi_note = VISEQ::MIDI::Notes.size()-1; 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 < 0 ) midi_cc = 127;
if(midi_cc > 127 ) midi_cc = 0; if(midi_cc > 127 ) midi_cc = 0;
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include "graph-manager.h"
#include <memory>
namespace VISEQ::APP {
class Mouse {
public:
Mouse(std::shared_ptr<GRAPH::GraphManager> gm) : gm(gm) {}
std::shared_ptr<GraphManager> gm;
void update(){
auto hovering_nodes = gm->nodes | RANGE_FILTER([](SPTR_Node n) { return n->hovering();});
}
};
}
+1 -1
View File
@@ -69,7 +69,7 @@ namespace VISEQ::GRAPH::NODES {
c->update(); c->update();
} }
if(free_connectors == 0) addConnector(); if(free_connectors == 0) addConnector();
is_hovering = hovering(); /*is_hovering = hovering();*/
} }
void draw(Vec2Df mp, Camera2D cam) override {} void draw(Vec2Df mp, Camera2D cam) override {}