Node interactions working again, graph editing functions not complete yet
This commit is contained in:
+9
-116
@@ -2,17 +2,15 @@
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include "interaction-manager.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "clipboard.h"
|
||||
#include "datatypes.h"
|
||||
#include "canvas.h"
|
||||
#include "graph-manager.h"
|
||||
#include "interaction-event.h"
|
||||
#include "midi-node.h"
|
||||
#include "mouse.h"
|
||||
#include "node.h"
|
||||
#include "raylib.h"
|
||||
#include "selectable.h"
|
||||
#include "signal-manager.h"
|
||||
#include "state.h"
|
||||
#include "ui.h"
|
||||
@@ -30,18 +28,18 @@ namespace VISEQ::APP {
|
||||
class AppManager{
|
||||
public:
|
||||
|
||||
AppManager() : sm(&gm, &mutex), mouse(&gm), ui(&sm, &gm) {}
|
||||
AppManager() : sm(&gm, &mutex), im(&gm, &sm, canvas), mouse(&gm), ui(&sm, &gm) {}
|
||||
|
||||
std::mutex mutex;
|
||||
|
||||
std::shared_ptr<APP::State> state = APP::State::get();
|
||||
|
||||
std::shared_ptr<CANVAS::Canvas> canvas = std::make_shared<CANVAS::Canvas>();
|
||||
VISEQ::GRAPH::GraphManager gm;
|
||||
VISEQ::SIGNAL::SignalManager sm;
|
||||
VISEQ::APP::Clipboard cb;
|
||||
VISEQ::INTERACTION::InteractionManager im;
|
||||
VISEQ::APP::Mouse mouse;
|
||||
|
||||
std::shared_ptr<APP::State> state = APP::State::get();
|
||||
|
||||
UI::AppUI ui;
|
||||
|
||||
void init(){
|
||||
@@ -60,7 +58,7 @@ namespace VISEQ::APP {
|
||||
void startSignals(){
|
||||
sm.startSignalThread();
|
||||
}
|
||||
|
||||
|
||||
void loadState(){
|
||||
if(std::filesystem::exists("state.json")){
|
||||
std::ifstream f("state.json");
|
||||
@@ -152,104 +150,6 @@ namespace VISEQ::APP {
|
||||
}
|
||||
}
|
||||
|
||||
void removeNodes(VEC_SPTR_Node nodes){
|
||||
|
||||
VEC_SPTR_Node adjacent_nodes = gm.getAdjacentNodes(nodes);
|
||||
|
||||
sm.rerouteSignal(nodes, adjacent_nodes);
|
||||
sm.rebaseSignal(nodes);
|
||||
|
||||
gm.removeNodesAndEdges(nodes);
|
||||
}
|
||||
|
||||
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 << "app canvas select" << std::endl;
|
||||
canvas->clearSelectionRect();
|
||||
}
|
||||
if(e.action == Interaction::DESELECT) {
|
||||
std::cout << "app canvas deselect" << std::endl;
|
||||
gm.deselect();
|
||||
}
|
||||
}
|
||||
|
||||
if(!once && e.item->getType() == GraphItemType::NODE){
|
||||
auto node = std::dynamic_pointer_cast<Node>(e.item);
|
||||
if(e.action == Interaction::PICKUP) {
|
||||
node->pickUp();
|
||||
if(node->selected){
|
||||
for(auto s : gm.selected_nodes){
|
||||
s->pickUp(node->position);
|
||||
}
|
||||
}
|
||||
once = true;
|
||||
}
|
||||
if(e.action == Interaction::DRAG) {
|
||||
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(MOD_MOUSE + s->drag_offset);
|
||||
}
|
||||
}
|
||||
once = true;
|
||||
}
|
||||
if(e.action == Interaction::PUTDOWN) {
|
||||
node->putDown();
|
||||
if(node->selected){
|
||||
for(auto s : gm.selected_nodes){
|
||||
s->putDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(exit) break;
|
||||
|
||||
if(!once && (e.item->getType() == GraphItemType::CONNECTOR || e.item->getType() == GraphItemType::CANVAS)) {
|
||||
switch(e.action){
|
||||
case VISEQ::APP::Interaction::PICKUP:
|
||||
{
|
||||
e.item->pickUp();
|
||||
once = true;
|
||||
break;
|
||||
}
|
||||
case VISEQ::APP::Interaction::DRAG:
|
||||
{
|
||||
e.item->drag(MOD_MOUSE);
|
||||
once = true;
|
||||
break;
|
||||
}
|
||||
case VISEQ::APP::Interaction::PUTDOWN:
|
||||
{
|
||||
e.item->putDown();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
event_queue.pop_front();
|
||||
}
|
||||
event_queue.clear();
|
||||
}
|
||||
|
||||
void update(){
|
||||
state->update(canvas->camera);
|
||||
canvas->update();
|
||||
@@ -258,18 +158,9 @@ namespace VISEQ::APP {
|
||||
updateMidiPorts();
|
||||
mutex.unlock();
|
||||
|
||||
doInteraction();
|
||||
mouse.update();
|
||||
im.update();
|
||||
|
||||
if(KEYS_DOWN.ctrl && IsKeyPressed(KEY_C)){
|
||||
VEC_SPTR_Node selected_nodes = gm.getSelection();
|
||||
if(!selected_nodes.empty()) cb.pushNodes(selected_nodes);
|
||||
}
|
||||
|
||||
if(KEYS_DOWN.ctrl && IsKeyPressed(KEY_V)){
|
||||
VEC_SPTR_Node paste_nodes = cb.pullNodes();
|
||||
if(!paste_nodes.empty()) gm.pasteNodesAndEdges(paste_nodes, MOD_MOUSE);
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
@@ -282,6 +173,8 @@ namespace VISEQ::APP {
|
||||
gm.drawEdges(SCREEN_MOUSE, canvas->camera);
|
||||
sm.drawSignals(SCREEN_MOUSE, canvas->camera);
|
||||
|
||||
im.draw();
|
||||
|
||||
canvas->drawEnd();
|
||||
drawUI();
|
||||
EndDrawing();
|
||||
|
||||
Reference in New Issue
Block a user