Merge pull request #16078 from mike-spa/fixStaffLinesBoundingBox

The clickable bounding box of a item should not necessarily coincide with the engraving bounding box
This commit is contained in:
RomanPudashkin 2023-03-22 16:22:47 +02:00 committed by GitHub
commit 94d381372a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 10 deletions

View file

@ -800,6 +800,16 @@ bool EngravingItem::intersects(const RectF& rr) const
return shape().intersects(rr.translated(-pagePos()));
}
bool EngravingItem::hitShapeContains(const PointF& p) const
{
return hitShape().contains(p - pagePos());
}
bool EngravingItem::hitShapeIntersects(const RectF& rr) const
{
return hitShape().intersects(rr.translated(-pagePos()));
}
//---------------------------------------------------------
// writeProperties
//---------------------------------------------------------

View file

@ -320,6 +320,11 @@ public:
virtual Shape shape() const { return Shape(bbox(), this); }
virtual double baseLine() const { return -height(); }
virtual mu::RectF hitBBox() const { return _bbox; }
virtual Shape hitShape() const { return shape(); }
bool hitShapeContains(const PointF& p) const;
bool hitShapeIntersects(const mu::RectF& rr) const;
virtual int subtype() const { return -1; } // for select gui
virtual void draw(mu::draw::Painter*) const {}

View file

@ -123,13 +123,6 @@ void StaffLines::layoutForWidth(double w)
double y = pos().y();
bbox().setRect(x1, -lw * .5 + y, w, (_lines - 1) * dist + lw);
if (_lines == 1) {
double extraSize = _spatium;
bbox().adjust(0, -extraSize, 0, extraSize);
} else if (_lines == 0) {
bbox().adjust(0, -2 * dist, 0, 2 * dist);
}
lines.clear();
for (int i = 0; i < _lines; ++i) {
lines.push_back(LineF(x1, y, x2, y));
@ -184,6 +177,20 @@ void StaffLines::layoutPartialWidth(double w, double wPartial, bool alignRight)
}
}
RectF StaffLines::hitBBox() const
{
double clickablePadding = spatium();
if (lines.size() <= 1) {
return bbox().adjusted(0.0, -clickablePadding, 0.0, clickablePadding);
}
return bbox();
}
Shape StaffLines::hitShape() const
{
return Shape(hitBBox(), this);
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------

View file

@ -60,6 +60,8 @@ public:
double y1() const;
void layoutForWidth(double width);
void layoutPartialWidth(double w, double wPartial, bool alignLeft);
RectF hitBBox() const override;
Shape hitShape() const override;
};
}

View file

@ -600,7 +600,7 @@ std::vector<mu::engraving::EngravingItem*> NotationInteraction::hitElements(cons
continue;
}
if (element->contains(p)) {
if (element->hitShapeContains(p)) {
ll.push_back(element);
}
}
@ -618,7 +618,7 @@ std::vector<mu::engraving::EngravingItem*> NotationInteraction::hitElements(cons
continue;
}
if (element->intersects(r)) {
if (element->hitShapeIntersects(r)) {
ll.push_back(element);
}
}
@ -644,7 +644,7 @@ NotationInteraction::HitMeasureData NotationInteraction::hitMeasure(const PointF
Measure* measure = score()->pos2measure(pos, &staffIndex, 0, &segment, &offset);
HitMeasureData result;
if (measure && measure->staffLines(staffIndex)->canvasBoundingRect().contains(pos)) {
if (measure && measure->staffLines(staffIndex)->hitShapeContains(pos)) {
result.measure = measure;
result.staff = score()->staff(staffIndex);
}

Binary file not shown.