Files
z-bar-qt/Plugins/ZShell/Internal/strokecanvasrenderer.cpp
T
zach c102d0e38f
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 11s
Python / lint-format (pull_request) Successful in 16s
Python / test (pull_request) Successful in 31s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m17s
drawing reworked into c++ plugin, moved input handler to Interactions.qml as a PointHandler
2026-06-18 13:48:58 +02:00

62 lines
1.3 KiB
C++

#include "strokecanvasrenderer.hpp"
#include "strokecanvasitem.hpp"
namespace ZShell::internal {
static void drawStroke(
QCanvasPainter *painter,
const QVector<QPointF> &points,
const QColor &color,
float width) {
if (points.isEmpty())
return;
painter->setStrokeStyle(color);
painter->setFillStyle(color);
painter->setLineWidth(width);
painter->setLineCap(QCanvasPainter::LineCap::Round);
painter->setLineJoin(QCanvasPainter::LineJoin::Round);
if (points.size() == 1) {
painter->beginPath();
painter->circle(points.front(), width * 0.5f);
painter->fill();
return;
}
painter->beginPath();
painter->moveTo(points[0]);
for (qsizetype i = 1; i < points.size(); ++i)
painter->lineTo(points[i]);
painter->stroke();
}
void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
auto *canvas = static_cast<StrokeCanvasItem *>(item);
m_penColor = canvas->m_penColor;
m_penWidth = canvas->m_penWidth;
m_strokes = canvas->m_strokes;
m_currentStroke = canvas->m_currentStroke;
}
void StrokeCanvasRenderer::paint(QCanvasPainter *painter) {
painter->clearRect(0, 0, width(), height());
for (const auto &stroke : m_strokes)
drawStroke(painter, stroke.points, stroke.color, stroke.width);
drawStroke(
painter,
m_currentStroke.points,
m_currentStroke.color,
m_currentStroke.width
);
}
};