Might be a better way to handle hovering, dragging and mouse interaction in general

This commit is contained in:
Sebastian
2024-11-22 00:24:31 +01:00
parent a6b6ff1d16
commit b12f1d0f9d
2 changed files with 11 additions and 4 deletions
+2 -1
View File
@@ -19,7 +19,7 @@ namespace VISEQ::APP {
class AppManager{
public:
AppManager() : sm(&gm, &mutex), mouse(std::make_shared<GraphManager>(gm)), ui(&sm, &gm) {}
AppManager() : sm(&gm, &mutex), mouse(&gm), ui(&sm, &gm) {}
std::mutex mutex;
@@ -60,6 +60,7 @@ namespace VISEQ::APP {
mutex.lock();
updateMidiPorts();
mutex.unlock();
mouse.update();
if(KEYS_DOWN.ctrl && IsKeyPressed(KEY_C)){
VEC_SPTR_Node selected_nodes = gm.getSelection();
+9 -3
View File
@@ -1,16 +1,22 @@
#pragma once
#include "draggable.h"
#include "graph-manager.h"
#include <memory>
namespace VISEQ::APP {
class Mouse {
public:
Mouse(std::shared_ptr<GRAPH::GraphManager> gm) : gm(gm) {}
Mouse() {}
Mouse(GraphManager *gm) : gm(gm) {}
std::shared_ptr<GraphManager> gm;
GraphManager *gm;
void update(){
auto hovering_nodes = gm->nodes | RANGE_FILTER([](SPTR_Node n) { return n->hovering();});
auto hovering_nodes = gm->nodes | RANGE_FILTER([](SPTR_Node n) { return n->is_hovering;}) | std::ranges::to<std::vector<std::shared_ptr<BASE::Draggable>>>();
if(!hovering_nodes.empty()){
hovering_nodes.front()->selected = true;
}
}
};
}