feat: floating edge cubic bezier, additional memory guards
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "gui/network/SocketGraphic.h"
|
||||
#include <iostream>
|
||||
#include <qgraphicsitem.h>
|
||||
#include <algorithm>
|
||||
|
||||
FloatingEdgeGraphic::FloatingEdgeGraphic(SocketGraphic* socket1, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), socket1_{socket1}
|
||||
@@ -29,7 +30,19 @@ void FloatingEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsIte
|
||||
|
||||
pen.setCapStyle(Qt::RoundCap);
|
||||
painter->setPen(pen);
|
||||
painter->drawLine(socket1_->scenePos(),floatPos_);
|
||||
// painter->drawLine(socket1_->scenePos(),floatPos_);
|
||||
|
||||
QPointF pos1 = socket1_->getIO()==SocketGraphic::SocketType::Input ? socket1_->scenePos() : floatPos_;
|
||||
QPointF pos2 = socket1_->getIO()==SocketGraphic::SocketType::Input ? floatPos_ : socket1_->scenePos();
|
||||
float dist = std::sqrt(std::pow(pos1.x()-pos2.x(),2)+std::pow(pos1.y()-pos2.y(),2));
|
||||
std::cout << "dist: " << dist << "\n";
|
||||
float cubicStrength = dist*0.5;
|
||||
cubicStrength = std::clamp(cubicStrength, 0.0f, 40.0f);
|
||||
QPainterPath path;
|
||||
path.moveTo(pos1);
|
||||
path.cubicTo(pos1-QPoint(0,cubicStrength), pos2+QPoint(0,cubicStrength), pos2);
|
||||
painter->drawPath(path);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user