[PATCH] pass correct time events to mypaint brush engine

Martin Renold martinxyz at gmx.ch
Mon Dec 27 12:23:40 CET 2010


Use the event time, instead of the time when the line is rendered.
Reset the brush engine properly between strokes, since we don't have
access to motion events without pressure.
---
 krita/plugins/paintops/mypaint/mypaint_paintop.cpp |   49 +++++++++-----------
 krita/plugins/paintops/mypaint/mypaint_paintop.h   |    3 +-
 2 files changed, 23 insertions(+), 29 deletions(-)

diff --git a/krita/plugins/paintops/mypaint/mypaint_paintop.cpp b/krita/plugins/paintops/mypaint/mypaint_paintop.cpp
index c1705e9..c155753 100644
--- a/krita/plugins/paintops/mypaint/mypaint_paintop.cpp
+++ b/krita/plugins/paintops/mypaint/mypaint_paintop.cpp
@@ -41,13 +41,11 @@ MyPaint::MyPaint(const MyPaintSettings *settings, KisPainter * painter, KisImage
     MyPaintFactory *factory = static_cast<MyPaintFactory*>(KisPaintOpRegistry::instance()->get("mypaintbrush"));
     m_brush = factory->brush(settings->getString("filename"));
     m_brush->set_base_value(BRUSH_RADIUS_LOGARITHMIC, settings->getFloat("radius_logarithmic"));
-    m_brush->new_stroke();
     QColor c = painter->paintColor().toQColor();
     qreal h, s, v, a;
     c.getHsvF(&h, &s, &v, &a);
     m_brush->set_color_hsv((float)h, (float)s, (float)v);
-    m_mypaintThinksStrokeHasEnded = false;
-    m_eventTime.start(); // GTK puts timestamps in its events, Qt doesn't, so fake it.
+    m_mustEndPreviousStroke = true;
 }
 
 MyPaint::~MyPaint()
@@ -57,16 +55,8 @@ MyPaint::~MyPaint()
 
 qreal MyPaint::paintAt(const KisPaintInformation& info)
 {
-    if (m_mypaintThinksStrokeHasEnded) {
-        m_settings->brush()->new_stroke();
-    }
-    m_mypaintThinksStrokeHasEnded =
-                        m_brush->stroke_to(m_surface,
-                                           info.pos().x(),
-                                           info.pos().y(),
-                                           info.pressure(),
-                                           qreal(m_eventTime.elapsed()) / 1000);
-    m_eventTime.restart();
+    // never called?
+    Q_UNUSED(info);
     return 1.0;
 }
 
@@ -76,22 +66,27 @@ KisDistanceInformation MyPaint::paintLine(const KisPaintInformation &pi1, const
 
     if (!painter()) return KisDistanceInformation();
 
-    if (m_mypaintThinksStrokeHasEnded) {
-        m_brush->new_stroke();
-    }
-    m_mypaintThinksStrokeHasEnded = m_brush->stroke_to(m_surface,
-                                                       pi1.pos().x(), pi1.pos().y(),
-                                                       0,
-                                                       0);
-    if (m_mypaintThinksStrokeHasEnded) {
-        m_brush->new_stroke();
+    // The MyPaint brush engine is expecting motion events in-between
+    // the strokes. Those are used to update the speed and smudge
+    // filters. We have to do a workaround since we don't have access
+    // to those events. Of course, the start of each stroke can look
+    // different from MyPaint because of this, especially for brushes
+    // with strong speed dynamics.
+
+    if (m_mustEndPreviousStroke) {
+      m_mustEndPreviousStroke = false;
+      // End the previous stroke by telling the brush engine that we
+      // didn't receive any motion events for more than 5 seconds.
+      m_brush->stroke_to(m_surface,
+                         pi1.pos().x(), pi1.pos().y(),
+                         0.0,
+                         10.0);
     }
-    m_mypaintThinksStrokeHasEnded = m_brush->stroke_to(m_surface,
-                                                       pi2.pos().x(), pi2.pos().y(),
-                                                       pi2.pressure(),
-                                                       qreal(m_eventTime.elapsed()) / 1000);
 
-    m_eventTime.restart();
+    m_brush->stroke_to(m_surface,
+                       pi2.pos().x(), pi2.pos().y(),
+                       pi2.pressure(),
+                       qreal(pi2.currentTime() - pi1.currentTime()) / 1000);
 
     // not sure what to do with these...
     KisVector2D end = toKisVector2D(pi2.pos());
diff --git a/krita/plugins/paintops/mypaint/mypaint_paintop.h b/krita/plugins/paintops/mypaint/mypaint_paintop.h
index a715515..8043fe8 100644
--- a/krita/plugins/paintops/mypaint/mypaint_paintop.h
+++ b/krita/plugins/paintops/mypaint/mypaint_paintop.h
@@ -47,8 +47,7 @@ public:
 
 private:
 
-    QTime m_eventTime;
-    bool m_mypaintThinksStrokeHasEnded;
+    bool m_mustEndPreviousStroke;
     MyPaintSurface* m_surface;
     const MyPaintSettings* m_settings;
     MyPaintBrushResource *m_brush;
-- 
1.7.2.3


--3V7upXqbjpZ4EhLz--


More information about the kimageshop mailing list