Skip to content

Commit

Permalink
Handle rotation offset when rendering layer elements
Browse files Browse the repository at this point in the history
  • Loading branch information
lpugin committed Jan 7, 2024
1 parent 9302ad4 commit 0b9ca33
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions include/vrv/staff.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Staff : public Object,
void SetDrawingRotation(double drawingRotation) { m_drawingRotation = drawingRotation; }
double GetDrawingRotation() const { return m_drawingRotation; }
bool HasDrawingRotation() const { return (m_drawingRotation != 0.0); }
int GetDrawingRotationOffsetFor(int x);
///@}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/facsimilefunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ FunctorCode SyncFromFacsimileFunctor::VisitStaff(Staff *staff)
m_currentNeumeLine->m_drawingFacsX2 = m_view.ToLogicalX(zone->GetLrx() * DEFINITION_FACTOR);
m_staffZones[staff] = zone;

// The staff slope is going up. The y left postion needs to be adjusted accordingly
// The staff slope is going up. The y left position needs to be adjusted accordingly
if (zone->GetRotate() < 0) {
staff->m_drawingFacsY = staff->m_drawingFacsY
+ (m_currentNeumeLine->m_drawingFacsX2 - m_currentNeumeLine->m_drawingFacsX1)
Expand Down
6 changes: 6 additions & 0 deletions src/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ void Staff::CloneReset()
m_drawingRotation = 0.0;
}

int Staff::GetDrawingRotationOffsetFor(int x)
{
int xDiff = x - this->GetDrawingX();
return int(xDiff * tan(this->GetDrawingRotation() * M_PI / 180.0));
}

void Staff::ClearLedgerLines()
{
m_ledgerLinesAbove.clear();
Expand Down
15 changes: 12 additions & 3 deletions src/view_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,19 @@ void View::DrawAccid(DeviceContext *dc, LayerElement *element, Layer *layer, Sta
}

if (notationType == NOTATIONTYPE_neume) {
int rotateOffset = 0;
int rotationOffset = 0;
if (m_doc->IsFacs() && (staff->GetDrawingRotate() != 0)) {
double deg = staff->GetDrawingRotate();
int xDiff = x - staff->GetDrawingX();
rotateOffset = int(xDiff * tan(deg * M_PI / 180.0));
rotationOffset = int(xDiff * tan(deg * M_PI / 180.0));
}
else if (staff->HasDrawingRotation()) {
rotationOffset = staff->GetDrawingRotationOffsetFor(x);
}
if (accid->HasFacs() && m_doc->IsFacs()) {
y = ToLogicalY(y);
}
y -= rotateOffset;
y -= rotationOffset;
}

this->DrawSmuflString(
Expand Down Expand Up @@ -676,6 +679,9 @@ void View::DrawClef(DeviceContext *dc, LayerElement *element, Layer *layer, Staf
int xDiff = x - staff->GetDrawingX();
y -= int(xDiff * tan(deg * M_PI / 180.0));
}
else if (staff->HasDrawingRotation()) {
y -= staff->GetDrawingRotationOffsetFor(x);
}
}
else if (clef->GetShape() == CLEFSHAPE_perc) {
y -= m_doc->GetDrawingUnit(staff->m_drawingStaffSize) * (staff->m_drawingLines - 1);
Expand Down Expand Up @@ -782,6 +788,9 @@ void View::DrawCustos(DeviceContext *dc, LayerElement *element, Layer *layer, St
int xDiff = x - staff->GetDrawingX();
y -= int(xDiff * tan(deg * M_PI / 180.0));
}
else if (staff->HasDrawingRotation()) {
y -= staff->GetDrawingRotationOffsetFor(x);
}

this->DrawSmuflCode(dc, x, y, sym, staff->m_drawingStaffSize, false, true);

Expand Down
20 changes: 10 additions & 10 deletions src/view_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ void View::DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
clefOctave += (clef->GetDisPlace() == STAFFREL_basic_above ? 1 : -1) * (clef->GetDis() / 7);
}
int octaveOffset = (nc->GetOct() - clefOctave) * ((staffSize / 2) * 7);
int rotateOffset;
int rotationOffset = 0;
if (m_doc->IsFacs() && (staff->GetDrawingRotate() != 0)) {
double deg = staff->GetDrawingRotate();
int xDiff = noteX - staff->GetDrawingX();
rotateOffset = int(xDiff * tan(deg * M_PI / 180.0));
rotationOffset = int(xDiff * tan(deg * M_PI / 180.0));
}
else {
rotateOffset = 0;
else if (staff->HasDrawingRotation()) {
rotationOffset = staff->GetDrawingRotationOffsetFor(noteX);
}

if (nc->HasLoc()) {
Expand All @@ -248,7 +248,7 @@ void View::DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
else if (clef->GetShape() == CLEFSHAPE_F) {
pitchOffset = (nc->GetPname() - 4) * (staffSize / 2);
}
yValue = clefYPosition + pitchOffset + octaveOffset - rotateOffset;
yValue = clefYPosition + pitchOffset + octaveOffset - rotationOffset;
}

for (auto it = params.begin(); it != params.end(); it++) {
Expand Down Expand Up @@ -392,17 +392,17 @@ void View::DrawDivLine(DeviceContext *dc, LayerElement *element, Layer *layer, S

y -= (m_doc->GetDrawingUnit(staff->m_drawingStaffSize)) * 3;

int rotateOffset;
int rotationOffset = 0;
if (m_doc->IsFacs() && (staff->GetDrawingRotate() != 0)) {
double deg = staff->GetDrawingRotate();
int xDiff = x - staff->GetDrawingX();
rotateOffset = int(xDiff * tan(deg * M_PI / 180.0));
rotationOffset = int(xDiff * tan(deg * M_PI / 180.0));
}
else {
rotateOffset = 0;
else if (staff->HasDrawingRotation()) {
rotationOffset = staff->GetDrawingRotationOffsetFor(x);
}

y -= rotateOffset;
y -= rotationOffset;

DrawSmuflCode(dc, x, y, sym, staff->m_drawingStaffSize, false, true);

Expand Down

0 comments on commit 0b9ca33

Please sign in to comment.