Skip to content

Commit

Permalink
[palette] added layout for Expression
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Jun 28, 2023
1 parent e4c7049 commit a625838
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 67 deletions.
68 changes: 5 additions & 63 deletions src/engraving/layout/pal/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,69 +775,10 @@ void TLayout::layout(Dynamic*, LayoutContext&)
UNREACHABLE;
}

void TLayout::layout(Expression* item, LayoutContext& ctx)
void TLayout::layout(Expression*, LayoutContext&)
{
layoutTextBase(item, ctx);

Segment* segment = item->explicitParent() ? toSegment(item->explicitParent()) : nullptr;
if (!segment) {
return;
}

if (item->align().horizontal != AlignH::LEFT) {
Chord* chordToAlign = nullptr;
// Look for chord in this staff
track_idx_t startTrack = track2staff(item->staffIdx());
track_idx_t endTrack = startTrack + VOICES;
for (track_idx_t track = startTrack; track < endTrack; ++track) {
EngravingItem* engravingItem = segment->elementAt(track);
if (engravingItem && engravingItem->isChord()) {
chordToAlign = toChord(item);
break;
}
}

if (chordToAlign) {
Note* note = chordToAlign->notes().at(0);
double headWidth = note->headWidth();
bool center = item->align().horizontal == AlignH::HCENTER;
item->movePosX(headWidth * (center ? 0.5 : 1));
}
}

item->setSnappedDynamic(nullptr);

if (!item->autoplace() || !item->snapToDynamics()) {
return;
}

Dynamic* dynamic = toDynamic(segment->findAnnotation(ElementType::DYNAMIC, item->track(), item->track()));
if (!dynamic || dynamic->placeAbove() != item->placeAbove()) {
item->autoplaceSegmentElement();
return;
}

item->setSnappedDynamic(dynamic);
dynamic->setSnappedExpression(item);

// If there is a dynamic on same segment and track, lock this expression to it
double padding = item->computeDynamicExpressionDistance();
double dynamicRight = dynamic->shape().translate(dynamic->pos()).right();
double expressionLeft = item->bbox().translated(item->pos()).left();
double difference = expressionLeft - dynamicRight - padding;
item->movePosX(-difference);

// Keep expression and dynamic vertically aligned
item->autoplaceSegmentElement();
bool above = item->placeAbove();
double yExpression = item->pos().y();
double yDynamic = dynamic->pos().y();
bool expressionIsOuter = above ? yExpression < yDynamic : yExpression > yDynamic;
if (expressionIsOuter) {
dynamic->movePosY((yExpression - yDynamic));
} else {
item->movePosY((yDynamic - yExpression));
}
//! NOTE Moved to PaletteLayout
UNREACHABLE;
}

void TLayout::layout(Fermata* item, LayoutContext& ctx)
Expand Down Expand Up @@ -1941,6 +1882,7 @@ void TLayout::layout(InstrumentChange*, LayoutContext&)

void TLayout::layout(InstrumentName* item, LayoutContext& ctx)
{
UNREACHABLE;
layoutTextBase(item, ctx);
}

Expand Down Expand Up @@ -2879,8 +2821,8 @@ void TLayout::layout(StemSlash* item, LayoutContext& ctx)

void TLayout::layout(Sticking* item, LayoutContext& ctx)
{
UNREACHABLE;
layoutTextBase(item, ctx);
item->autoplaceSegmentElement();
}

void TLayout::layout(StretchedBend* item, LayoutContext& ctx)
Expand Down
13 changes: 9 additions & 4 deletions src/palette/internal/palettelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "engraving/libmscore/capo.h"
#include "engraving/libmscore/clef.h"
#include "engraving/libmscore/dynamic.h"
#include "engraving/libmscore/expression.h"
#include "engraving/libmscore/fingering.h"
#include "engraving/libmscore/fret.h"
#include "engraving/libmscore/harppedaldiagram.h"
Expand Down Expand Up @@ -91,6 +92,8 @@ void PaletteLayout::layoutItem(EngravingItem* item)
break;
case ElementType::DYNAMIC: layout(toDynamic(item), ctx);
break;
case ElementType::EXPRESSION: layout(toExpression(item), ctx);
break;
case ElementType::FINGERING: layout(toFingering(item), ctx);
break;
case ElementType::FRET_DIAGRAM: layout(toFretDiagram(item), ctx);
Expand Down Expand Up @@ -121,10 +124,7 @@ void PaletteLayout::layoutItem(EngravingItem* item)
break;
default:
//! TODO Still need
LOGD() << item->typeName();
// if (std::string("Symbol") == item->typeName()) {
// int k = -1;
// }
// LOGD() << item->typeName();
layout::pal::TLayout::layoutItem(item, ctxpal);
break;
}
Expand Down Expand Up @@ -457,6 +457,11 @@ void PaletteLayout::layout(Clef* item, const Context& ctx)
item->setbbox(bbox);
}

void PaletteLayout::layout(Expression* item, const Context& ctx)
{
layoutTextBase(item, ctx);
}

void PaletteLayout::layout(Fingering* item, const Context& ctx)
{
layoutTextBase(item, ctx);
Expand Down
4 changes: 4 additions & 0 deletions src/palette/internal/palettelayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Clef;

class Dynamic;

class Expression;

class Fingering;
class FretDiagram;

Expand Down Expand Up @@ -105,6 +107,8 @@ class PaletteLayout

static void layout(engraving::Dynamic* item, const Context& ctx);

static void layout(engraving::Expression* item, const Context& ctx);

static void layout(engraving::Fingering* item, const Context& ctx);
static void layout(engraving::FretDiagram* item, const Context& ctx);

Expand Down

0 comments on commit a625838

Please sign in to comment.