Skip to content

Commit

Permalink
Traktor: Updated CanvasX11 with support for splines.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Jun 10, 2024
1 parent a34edb9 commit 386d2d9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion code/Ui/Graph/Edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
34 changes: 33 additions & 1 deletion code/Ui/X11/CanvasX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 386d2d9

Please sign in to comment.