74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
|
|
#include "node.h"
|
||
|
|
|
||
|
|
#include <memory>
|
||
|
|
#include <raylib.h>
|
||
|
|
|
||
|
|
#include "connector.h"
|
||
|
|
#include "datatypes.h"
|
||
|
|
#include "interaction-event.h"
|
||
|
|
#include "state.h"
|
||
|
|
#include "vmath.h"
|
||
|
|
|
||
|
|
namespace VISEQ::GRAPH::NODES {
|
||
|
|
void Node::setMode(int _mode) {mode = _mode;}
|
||
|
|
|
||
|
|
std::shared_ptr<Node> Node::getPtr(){
|
||
|
|
return shared_from_this();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool Node::hovering() {
|
||
|
|
return CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
|
||
|
|
}
|
||
|
|
|
||
|
|
void Node::addConnector() {
|
||
|
|
connectors.emplace_back(std::make_shared<Connector>(getPtr(), position, radius + 5.0f));
|
||
|
|
}
|
||
|
|
|
||
|
|
void Node::removeConnector(std::weak_ptr<Connector> connector){
|
||
|
|
std::erase(connectors, connector.lock());
|
||
|
|
}
|
||
|
|
|
||
|
|
NodeType Node::getNodeType() const {return nodeType;}
|
||
|
|
|
||
|
|
void Node::deselect() {
|
||
|
|
selected = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
GraphItemType Node::getType() {
|
||
|
|
return GraphItemType::NODE;
|
||
|
|
}
|
||
|
|
|
||
|
|
void Node::clearConnectors(){
|
||
|
|
connectors.clear();
|
||
|
|
update();
|
||
|
|
}
|
||
|
|
|
||
|
|
void Node::update() {
|
||
|
|
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});
|
||
|
|
if(hovering() && MOUSE_RIGHT.clicked) {
|
||
|
|
selected = true;
|
||
|
|
config = true;
|
||
|
|
state->pushEvent({getPtr(), APP::Interaction::RIGHTCLICK});
|
||
|
|
}
|
||
|
|
int free_connectors = 0;
|
||
|
|
for(auto c : connectors){
|
||
|
|
if(c->partner.expired()) free_connectors++;
|
||
|
|
c->setPosition(position);
|
||
|
|
c->setOrbit(radius + 8.0f);
|
||
|
|
c->update();
|
||
|
|
}
|
||
|
|
if(free_connectors == 0) addConnector();
|
||
|
|
}
|
||
|
|
|
||
|
|
void Node::draw(Vec2Df mp, Camera2D cam) {}
|
||
|
|
|
||
|
|
void Node::draw() {
|
||
|
|
for(auto c : connectors){
|
||
|
|
c->draw();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|