Skip to content

Commit

Permalink
[palette] added layout for Bend
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Jul 10, 2023
1 parent 20438db commit c1f1f99
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 106 deletions.
109 changes: 3 additions & 106 deletions src/engraving/layout/pal/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,113 +260,10 @@ void TLayout::layout1(Beam*, LayoutContext&)
//BeamLayout::layout1(item, ctx);
}

void TLayout::layout(Bend* item, LayoutContext& ctx)
void TLayout::layout(Bend*, LayoutContext&)
{
// during mtest, there may be no score. If so, exit.
if (!ctx.isValid()) {
return;
}

double _spatium = item->spatium();

if (item->staff() && !item->staff()->isTabStaff(item->tick())) {
if (!item->explicitParent()) {
item->setNoteWidth(-_spatium * 2);
item->setNotePos(PointF(0.0, _spatium * 3));
}
}

double _lw = item->lineWidth();
Note* note = toNote(item->explicitParent());
if (note == 0) {
item->setNoteWidth(0.0);
item->setNotePos(PointF());
} else {
PointF notePos = note->pos();
notePos.ry() = std::max(notePos.y(), 0.0);

item->setNoteWidth(note->width());
item->setNotePos(notePos);
}
RectF bb;

mu::draw::FontMetrics fm(item->font(_spatium));

size_t n = item->points().size();
double x = item->noteWidth();
double y = -_spatium * .8;
double x2, y2;

double aw = _spatium * .5;
PolygonF arrowUp;
arrowUp << PointF(0, 0) << PointF(aw * .5, aw) << PointF(-aw * .5, aw);
PolygonF arrowDown;
arrowDown << PointF(0, 0) << PointF(aw * .5, -aw) << PointF(-aw * .5, -aw);

for (size_t pt = 0; pt < n; ++pt) {
if (pt == (n - 1)) {
break;
}
int pitch = item->points().at(pt).pitch;
if (pt == 0 && pitch) {
y2 = -item->notePos().y() - _spatium * 2;
x2 = x;
bb.unite(RectF(x, y, x2 - x, y2 - y));

bb.unite(arrowUp.translated(x2, y2 + _spatium * .2).boundingRect());

int idx = (pitch + 12) / 25;
const char* l = Bend::label[idx];
bb.unite(fm.boundingRect(RectF(x2, y2, 0, 0),
draw::AlignHCenter | draw::AlignBottom | draw::TextDontClip,
String::fromAscii(l)));
y = y2;
}
if (pitch == item->points().at(pt + 1).pitch) {
if (pt == (n - 2)) {
break;
}
x2 = x + _spatium;
y2 = y;
bb.unite(RectF(x, y, x2 - x, y2 - y));
} else if (pitch < item->points().at(pt + 1).pitch) {
// up
x2 = x + _spatium * .5;
y2 = -item->notePos().y() - _spatium * 2;
double dx = x2 - x;
double dy = y2 - y;

PainterPath path;
path.moveTo(x, y);
path.cubicTo(x + dx / 2, y, x2, y + dy / 4, x2, y2);
bb.unite(path.boundingRect());
bb.unite(arrowUp.translated(x2, y2 + _spatium * .2).boundingRect());

int idx = (item->points().at(pt + 1).pitch + 12) / 25;
const char* l = Bend::label[idx];
bb.unite(fm.boundingRect(RectF(x2, y2, 0, 0),
draw::AlignHCenter | draw::AlignBottom | draw::TextDontClip,
String::fromAscii(l)));
} else {
// down
x2 = x + _spatium * .5;
y2 = y + _spatium * 3;
double dx = x2 - x;
double dy = y2 - y;

PainterPath path;
path.moveTo(x, y);
path.cubicTo(x + dx / 2, y, x2, y + dy / 4, x2, y2);
bb.unite(path.boundingRect());

bb.unite(arrowDown.translated(x2, y2 - _spatium * .2).boundingRect());
}
x = x2;
y = y2;
}
bb.adjust(-_lw, -_lw, _lw, _lw);
item->setbbox(bb);
item->setPos(0.0, 0.0);
//! NOTE Moved to PaletteLayout
UNREACHABLE;
}

using BoxTypes = rtti::TypeList<HBox, VBox, FBox, TBox>;
Expand Down
92 changes: 92 additions & 0 deletions src/palette/internal/palettelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "engraving/libmscore/articulation.h"
#include "engraving/libmscore/bagpembell.h"
#include "engraving/libmscore/barline.h"
#include "engraving/libmscore/bend.h"
#include "engraving/libmscore/bracket.h"
#include "engraving/libmscore/breath.h"
#include "engraving/libmscore/capo.h"
Expand Down Expand Up @@ -106,6 +107,8 @@ void PaletteLayout::layoutItem(EngravingItem* item)
break;
case ElementType::BAR_LINE: layout(toBarLine(item), ctx);
break;
case ElementType::BEND: layout(toBend(item), ctx);
break;
case ElementType::BRACKET: layout(toBracket(item), ctx);
break;
case ElementType::BREATH: layout(toBreath(item), ctx);
Expand Down Expand Up @@ -443,6 +446,95 @@ void PaletteLayout::layout(BarLine* item, const Context& ctx)
item->setbbox(bbox);
}

void PaletteLayout::layout(Bend* item, const Context&)
{
double spatium = item->spatium();
double lw = item->lineWidth();

item->setNoteWidth(0.0);
item->setNotePos(PointF());

RectF bb;

mu::draw::FontMetrics fm(item->font(spatium));

size_t n = item->points().size();
double x = item->noteWidth();
double y = -spatium * .8;
double x2, y2;

double aw = spatium * .5;
PolygonF arrowUp;
arrowUp << PointF(0, 0) << PointF(aw * .5, aw) << PointF(-aw * .5, aw);
PolygonF arrowDown;
arrowDown << PointF(0, 0) << PointF(aw * .5, -aw) << PointF(-aw * .5, -aw);

for (size_t pt = 0; pt < n; ++pt) {
if (pt == (n - 1)) {
break;
}
int pitch = item->points().at(pt).pitch;
if (pt == 0 && pitch) {
y2 = -item->notePos().y() - spatium * 2;
x2 = x;
bb.unite(RectF(x, y, x2 - x, y2 - y));

bb.unite(arrowUp.translated(x2, y2 + spatium * .2).boundingRect());

int idx = (pitch + 12) / 25;
const char* l = Bend::label[idx];
bb.unite(fm.boundingRect(RectF(x2, y2, 0, 0),
draw::AlignHCenter | draw::AlignBottom | draw::TextDontClip,
String::fromAscii(l)));
y = y2;
}
if (pitch == item->points().at(pt + 1).pitch) {
if (pt == (n - 2)) {
break;
}
x2 = x + spatium;
y2 = y;
bb.unite(RectF(x, y, x2 - x, y2 - y));
} else if (pitch < item->points().at(pt + 1).pitch) {
// up
x2 = x + spatium * .5;
y2 = -item->notePos().y() - spatium * 2;
double dx = x2 - x;
double dy = y2 - y;

PainterPath path;
path.moveTo(x, y);
path.cubicTo(x + dx / 2, y, x2, y + dy / 4, x2, y2);
bb.unite(path.boundingRect());
bb.unite(arrowUp.translated(x2, y2 + spatium * .2).boundingRect());

int idx = (item->points().at(pt + 1).pitch + 12) / 25;
const char* l = Bend::label[idx];
bb.unite(fm.boundingRect(RectF(x2, y2, 0, 0),
draw::AlignHCenter | draw::AlignBottom | draw::TextDontClip,
String::fromAscii(l)));
} else {
// down
x2 = x + spatium * .5;
y2 = y + spatium * 3;
double dx = x2 - x;
double dy = y2 - y;

PainterPath path;
path.moveTo(x, y);
path.cubicTo(x + dx / 2, y, x2, y + dy / 4, x2, y2);
bb.unite(path.boundingRect());

bb.unite(arrowDown.translated(x2, y2 - spatium * .2).boundingRect());
}
x = x2;
y = y2;
}
bb.adjust(-lw, -lw, lw, lw);
item->setbbox(bb);
item->setPos(0.0, 0.0);
}

void PaletteLayout::layout(Bracket* item, const Context& ctx)
{
Shape shape;
Expand Down
2 changes: 2 additions & 0 deletions src/palette/internal/palettelayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Articulation;

class BagpipeEmbellishment;
class BarLine;
class Bend;
class Bracket;
class Breath;

Expand Down Expand Up @@ -140,6 +141,7 @@ class PaletteLayout

static void layout(engraving::BagpipeEmbellishment* item, const Context& ctx);
static void layout(engraving::BarLine* item, const Context& ctx);
static void layout(engraving::Bend* item, const Context& ctx);
static void layout(engraving::Bracket* item, const Context& ctx);
static void layout(engraving::Breath* item, const Context&);

Expand Down

0 comments on commit c1f1f99

Please sign in to comment.