Super simple events added. Seems to be a good way for handling interaction. Modified a few base classes.

This commit is contained in:
Sebastian
2024-11-24 03:08:06 +01:00
parent 62a5c53969
commit f04838bffa
14 changed files with 160 additions and 67 deletions
+15 -5
View File
@@ -8,6 +8,7 @@
#include "datatypes.h"
#include "draggable.h"
#include "graph-item.h"
#include "interaction-event.h"
#include "state.h"
#include "vmath.h"
@@ -17,10 +18,9 @@ namespace VISEQ::GRAPH::EDGES{
namespace VISEQ::GRAPH::NODES {
class Node : public BASE::Draggable, public GraphItem{
class Node : public BASE::Draggable, public GraphItem {
public:
using GraphItem::state;
Node() {}
Node(float x, float y) : Draggable(Vec2Df(x, y)) {}
@@ -41,7 +41,7 @@ namespace VISEQ::GRAPH::NODES {
bool config = false;
virtual bool hovering() override {
return STATE != IState::DRAW_SELECTION && CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
return CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
}
void addConnector() {
@@ -59,8 +59,19 @@ namespace VISEQ::GRAPH::NODES {
virtual void trigger() {};
GraphItemType getType() override{
return GraphItemType::NODE;
}
std::shared_ptr<Node> getPtr(){
return std::static_pointer_cast<Node>(shared_from_this());
}
void update() override{
BASE::Draggable::update();
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});
int free_connectors = 0;
for(auto c : connectors){
@@ -69,7 +80,6 @@ namespace VISEQ::GRAPH::NODES {
c->update();
}
if(free_connectors == 0) addConnector();
/*is_hovering = hovering();*/
}
void draw(Vec2Df mp, Camera2D cam) override {}