From 386d2d94446a6afd95a95e643351468b9b54daf6 Mon Sep 17 00:00:00 2001 From: Anders Pistol Date: Mon, 10 Jun 2024 22:14:37 +0200 Subject: [PATCH] Traktor: Updated CanvasX11 with support for splines. --- code/Ui/Graph/Edge.cpp | 2 +- code/Ui/X11/CanvasX11.cpp | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/code/Ui/Graph/Edge.cpp b/code/Ui/Graph/Edge.cpp index f79a74e1ab..e956e4ff00 100644 --- a/code/Ui/Graph/Edge.cpp +++ b/code/Ui/Graph/Edge.cpp @@ -227,7 +227,7 @@ void Edge::paint(GraphControl* graph, GraphCanvas* canvas, const Size& offset, I canvas->setBackground(color); const Point s = graph->pixel(m_source->getPosition()) + offset; - const Point d = graph->pixel(m_destination->getPosition()) + offset; + const Point d = graph->pixel(m_destination->getPosition() - UnitSize(8_ut, 0_ut)) + offset; // calculateLinearSpline(graph, s, d, m_spline); // canvas->drawLines(m_spline, graph->pixel(hot ? 4_ut : m_thickness)); diff --git a/code/Ui/X11/CanvasX11.cpp b/code/Ui/X11/CanvasX11.cpp index be909b3b37..4e84053cf3 100644 --- a/code/Ui/X11/CanvasX11.cpp +++ b/code/Ui/X11/CanvasX11.cpp @@ -18,6 +18,15 @@ namespace traktor::ui { + namespace + { + +Vector2 pnt2vec(const Point& pt) +{ + return Vector2(pt.x, pt.y); +} + + } CanvasX11::CanvasX11(cairo_t* cr, int32_t dpi) : m_cr(cr) @@ -144,7 +153,30 @@ void CanvasX11::drawEllipticArc(int x, int y, int w, int h, float start, float e void CanvasX11::drawSpline(const Point* pnts, int npnts) { - log::info << L"CanvasX11::drawSpline NI" << Endl; + setSourceColor(m_foreground); + + for (int32_t i = 0; i <= npnts - 4; ++i) + { + const Bezier3rd b = Bezier3rd::fromCatmullRom( + pnt2vec(pnts[i + 0]), + pnt2vec(pnts[i + 1]), + pnt2vec(pnts[i + 2]), + pnt2vec(pnts[i + 3]), + 1.0f + ); + + if (i == 0) + cairo_move_to(m_cr, b.cp0.x, b.cp0.y); + + cairo_curve_to( + m_cr, + b.cp1.x, b.cp1.y, + b.cp2.x, b.cp2.y, + b.cp3.x, b.cp3.y + ); + } + + cairo_stroke(m_cr); } void CanvasX11::fillRect(const Rect& rc)