From 8d0eb205c0d4a7486a18f95eb106a83bb0fb0875 Mon Sep 17 00:00:00 2001 From: Fabian Gundlach Date: Mon, 15 Feb 2021 22:23:09 +0100 Subject: [PATCH] Brute force redrawing --- src/renderer.cpp | 18 +++++++++++------- src/renderer.h | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/renderer.cpp b/src/renderer.cpp index 46c12cf..d1dbd33 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -75,6 +75,14 @@ void DrawingLayerPicture::stroke_added(ptr_Stroke stroke) { draw_stroke(stroke); } +void DrawingLayerPicture::redraw(QRect rect) { + cr->rectangle(rect.left(), rect.top(), rect.width(), rect.height()); + cr->clip(); + set_transparent(); + draw_strokes(); + emit update(rect); +} + void DrawingLayerPicture::stroke_deleted(ptr_Stroke stroke) { CairoGroup cg(cr); PathStroke* path_stroke = convert_variant(stroke); @@ -85,11 +93,7 @@ void DrawingLayerPicture::stroke_deleted(ptr_Stroke stroke) { // Forget the deleted path cr->begin_new_path(); // Clip to only redraw the bounding rectangle of the deleted stroke. - cr->rectangle(rect.left(), rect.top(), rect.width(), rect.height()); - cr->clip(); - set_transparent(); - draw_strokes(); - emit update(rect); + redraw(rect); } void DrawingLayerPicture::setup_stroke(ptr_Stroke stroke) { @@ -126,8 +130,8 @@ void DrawingLayerPicture::draw_line(Point a, Point b, ptr_Stroke stroke) { cr->move_to(a.x * unit2pixel, a.y * unit2pixel); cr->line_to(b.x * unit2pixel, b.y * unit2pixel); QRect rect = stroke_extents(); - cr->stroke(); - emit update(rect); + cr->begin_new_path(); + redraw(rect); } QRect DrawingLayerPicture::stroke_extents() { diff --git a/src/renderer.h b/src/renderer.h index 4c1c0c6..ae182a6 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -85,6 +85,7 @@ class DrawingLayerPicture : public LayerPicture { private: void stroke_added(ptr_Stroke stroke); + void redraw(QRect rect); void stroke_deleted(ptr_Stroke stroke); std::variant m_layer;