Skip to content

Commit

Permalink
Merge pull request #339 from pgilfernandez/new_null-object_types
Browse files Browse the repository at this point in the history
New null object type + bug fix
  • Loading branch information
rodlie authored Nov 29, 2024
2 parents 4c3cfdc + 6d03845 commit 617facf
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/core/Boxes/nullobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class NullObjectType : public ComboBoxProperty {
enum class Type {
square, circle, triangle
square, circle, triangle, crosshair
};
public:
NullObjectType(ColorAnimator* const color,
Expand All @@ -53,12 +53,15 @@ NullObjectType::NullObjectType(ColorAnimator* const color,
QrealAnimator* const size) :
ComboBoxProperty("type", QStringList() << "square" <<
"circle" <<
"triangle"),
"triangle" <<
"crosshair"),
mColor(color), mSize(size) {
prp_setDrawingOnCanvasEnabled(true);

connect(this, &ComboBoxProperty::prp_currentFrameChanged,
this, &NullObjectType::updatePath);
connect(this, &ComboBoxProperty::prp_pathChanged,
this, &NullObjectType::updatePath);
connect(mSize, &QrealAnimator::prp_currentFrameChanged,
this, &NullObjectType::updatePath);
updatePath();
Expand Down Expand Up @@ -113,6 +116,24 @@ void NullObjectType::updatePath() {
mCurrentPath.moveTo(ten, -ten);
mCurrentPath.lineTo(-ten, ten);
break;
case Type::crosshair: {
const qreal circleRadius = ten * 7/8;
mCurrentPath.addCircle(0, 0, circleRadius);
const qreal lineLength = 2 * ten / 8;
mCurrentPath.moveTo(-circleRadius - lineLength, 0);
mCurrentPath.lineTo(-circleRadius + lineLength, 0);
mCurrentPath.moveTo(circleRadius - lineLength, 0);
mCurrentPath.lineTo(circleRadius + lineLength, 0);
mCurrentPath.moveTo(0, -circleRadius + lineLength);
mCurrentPath.lineTo(0, -circleRadius - lineLength);
mCurrentPath.moveTo(0, circleRadius + lineLength);
mCurrentPath.lineTo(0, circleRadius - lineLength);
mCurrentPath.moveTo(lineLength/2, 0);
mCurrentPath.lineTo(-lineLength/2, 0);
mCurrentPath.moveTo(0, + lineLength/2);
mCurrentPath.lineTo(0, - lineLength/2);
break;
}
case Type::triangle:
const qreal a = 3*ten/sqrt(3);
const qreal h = ten + a*sqrt(3)/6;
Expand Down Expand Up @@ -143,6 +164,10 @@ bool NullObjectType::relPointInsidePath(const QPointF& relPos) {
QPainterPath path;
path.addEllipse({0., 0.}, ten, ten);
return path.contains(relPos);
} case Type::crosshair: {
QPainterPath path;
path.addEllipse({0., 0.}, ten, ten);
return path.contains(relPos);
} case Type::triangle:
const qreal a = 3*ten/sqrt(3);
const qreal h = ten + a*sqrt(3)/6;
Expand Down

0 comments on commit 617facf

Please sign in to comment.