From 0b9ca33b0e4144dff2eb68438f3cbe3169d10515 Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Sun, 7 Jan 2024 22:28:25 +0100 Subject: [PATCH] Handle rotation offset when rendering layer elements --- include/vrv/staff.h | 1 + src/facsimilefunctor.cpp | 2 +- src/staff.cpp | 6 ++++++ src/view_element.cpp | 15 ++++++++++++--- src/view_neume.cpp | 20 ++++++++++---------- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/include/vrv/staff.h b/include/vrv/staff.h index 7e78484308c..3bda856b577 100644 --- a/include/vrv/staff.h +++ b/include/vrv/staff.h @@ -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); ///@} /** diff --git a/src/facsimilefunctor.cpp b/src/facsimilefunctor.cpp index 0287275a7fc..436939cf0cf 100644 --- a/src/facsimilefunctor.cpp +++ b/src/facsimilefunctor.cpp @@ -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) diff --git a/src/staff.cpp b/src/staff.cpp index 1a37ab7ead0..1e3c1f00a52 100644 --- a/src/staff.cpp +++ b/src/staff.cpp @@ -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(); diff --git a/src/view_element.cpp b/src/view_element.cpp index 82ba0443207..63e20bb66c2 100644 --- a/src/view_element.cpp +++ b/src/view_element.cpp @@ -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( @@ -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); @@ -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); diff --git a/src/view_neume.cpp b/src/view_neume.cpp index eeeaed614b1..0d6e312ad75 100644 --- a/src/view_neume.cpp +++ b/src/view_neume.cpp @@ -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()) { @@ -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++) { @@ -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);