[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kimageshop
Subject:    Rotation related to canvas
From:       Lukast dev <lukast.dev () gmail ! com>
Date:       2012-02-23 11:19:20
Message-ID: CAKdU0rMmTwOPVCgvxdoz=3XqEw=d1OYhWei1jXqsDj6t4uyQwQ () mail ! gmail ! com
[Download RAW message or body]

Hello all,

Dmitry, would you please take a look at my patch for bug
https://bugs.kde.org/show_bug.cgi?id=292726

There is one problem in KisToolFreehand::getOutlinePath where I need
to distict between
two states:

a) In hover mode the rotation of the canvas has to be included in the
computation of the brush outline.
In that moment the rotation of the brush engine is not known as we
don't know the state of the
rotation sensors etc.

b) In paint mode the rotation of the canvas is included in the brush
engine rotation and thus we don't
include it again when computing the outline in freehand tool. Problem
is that we need to call paintAt at least once so
that the sensors set the currentRotation of the paintop correctly. So
far I added boolean flag to KisPaintOp::setCurrentRotation
but I wonder we if can do it nicely. I tried to add flag after
doStroke() in freehand tool, but it is threaded and the paintAt call
is scheduled and thus at the beginning of the stroke the outline is wrong.

My question, Dmitry, is if you can see in freehand tool if the paintop
paintAt was executed at least once somehow?

If you have any concerns about the patch, let me know.

Cheers
Lukas

["rotation_to_canvas.patch" (text/x-patch)]

diff --git a/krita/image/brushengine/kis_paintop.cc \
b/krita/image/brushengine/kis_paintop.cc index a550249..8eab16f 100644
--- a/krita/image/brushengine/kis_paintop.cc
+++ b/krita/image/brushengine/kis_paintop.cc
@@ -49,7 +49,7 @@
 
 struct KisPaintOp::Private {
     Private()
-            : dab(0),currentScale(1.0),currentRotation(0) {
+            : dab(0),currentScale(1.0),currentRotation(0),rotationIsSet(false) {
     }
 
     KisFixedPaintDeviceSP dab;
@@ -58,6 +58,7 @@ struct KisPaintOp::Private {
     KisPainter* painter;
     qreal currentScale;
     qreal currentRotation;
+    bool rotationIsSet;
 };
 
 
@@ -212,6 +213,7 @@ qreal KisPaintOp::currentScale() const
 
 void KisPaintOp::setCurrentRotation(qreal rotation)
 {
+    d->rotationIsSet = true;
     d->currentRotation = rotation;
 }
 
@@ -220,3 +222,7 @@ void KisPaintOp::setCurrentScale(qreal scale)
     d->currentScale = scale;
 }
 
+bool KisPaintOp::rotationIsSet() const
+{
+    return d->rotationIsSet;
+}
diff --git a/krita/image/brushengine/kis_paintop.h \
b/krita/image/brushengine/kis_paintop.h index 15b4c9d..56fa70f 100644
--- a/krita/image/brushengine/kis_paintop.h
+++ b/krita/image/brushengine/kis_paintop.h
@@ -106,7 +106,7 @@ public:
      */
     qreal currentScale() const;
     qreal currentRotation() const;
-
+    bool rotationIsSet() const;
 protected:
 
     void setCurrentScale(qreal scale);
diff --git a/krita/image/brushengine/kis_paintop_settings.cpp \
b/krita/image/brushengine/kis_paintop_settings.cpp index 2d09aa7..e53127d 100644
--- a/krita/image/brushengine/kis_paintop_settings.cpp
+++ b/krita/image/brushengine/kis_paintop_settings.cpp
@@ -41,11 +41,13 @@ struct KisPaintOpSettings::Private {
     KisNodeSP node;
     QPointer<KisPaintOpSettingsWidget> settingsWidget;
     QString modelName;
+    qreal canvasRotationAngle;
 };
 
 KisPaintOpSettings::KisPaintOpSettings()
         : d(new Private)
 {
+    d->canvasRotationAngle = 0.0;
 }
 
 KisPaintOpSettings::~KisPaintOpSettings()
@@ -170,3 +172,15 @@ QPainterPath KisPaintOpSettings::ellipseOutline(qreal width, \
qreal height, qreal  path = m.map(path);
     return path;
 }
+
+void KisPaintOpSettings::setCanvasRotation(qreal angle)
+{
+    setProperty("runtimeCanvasRotation", angle);
+    setPropertyNotSaved("runtimeCanvasRotation");
+}
+
+
+qreal KisPaintOpSettings::canvasRotationAngle() const
+{
+    return getDouble("runtimeCanvasRotation");
+}
diff --git a/krita/image/brushengine/kis_paintop_settings.h \
b/krita/image/brushengine/kis_paintop_settings.h index ec713cf..a5600cf 100644
--- a/krita/image/brushengine/kis_paintop_settings.h
+++ b/krita/image/brushengine/kis_paintop_settings.h
@@ -171,6 +171,9 @@ public:
     /// @return loadable state of the settings, by default implementation return the \
same as isValid()  virtual bool isLoadable();
 
+    void setCanvasRotation(qreal angle);
+    qreal canvasRotationAngle() const;
+
 protected:
      /**
      * @return the option widget of the paintop (can be 0 is no option widgets is \
                set)
diff --git a/krita/plugins/paintops/libpaintop/kis_pressure_rotation_option.cpp \
b/krita/plugins/paintops/libpaintop/kis_pressure_rotation_option.cpp index \
                2502322..301e5d8 100644
--- a/krita/plugins/paintops/libpaintop/kis_pressure_rotation_option.cpp
+++ b/krita/plugins/paintops/libpaintop/kis_pressure_rotation_option.cpp
@@ -24,7 +24,7 @@
 #include <KoColorSpace.h>
 
 KisPressureRotationOption::KisPressureRotationOption()
-        : KisCurveOption(i18n("Rotation"), "Rotation", \
KisPaintOpOption::brushCategory(), false) +        : KisCurveOption(i18n("Rotation"), \
"Rotation", KisPaintOpOption::brushCategory(), false), m_defaultAngle(0.0)  {
     setMinimumLabel(i18n("0 °"));
     setMaximumLabel(i18n("360 °"));
@@ -33,6 +33,12 @@ KisPressureRotationOption::KisPressureRotationOption()
 
 double KisPressureRotationOption::apply(const KisPaintInformation & info) const
 {
-    if (!isChecked()) return 0.0;
-    return (1.0 - computeValue(info)) * 2.0 * M_PI;
+    if (!isChecked()) return m_defaultAngle;
+    return fmod( (1.0 - computeValue(info)) * 2.0 * M_PI + m_defaultAngle, 2.0 * \
M_PI); +}
+
+void KisPressureRotationOption::readOptionSetting(const KisPropertiesConfiguration* \
setting) +{
+    m_defaultAngle = setting->getDouble("runtimeCanvasRotation", 0.0) * M_PI / \
180.0; +    KisCurveOption::readOptionSetting(setting);
 }
diff --git a/krita/plugins/paintops/libpaintop/kis_pressure_rotation_option.h \
b/krita/plugins/paintops/libpaintop/kis_pressure_rotation_option.h index \
                b31b80c..a6b60c3 100644
--- a/krita/plugins/paintops/libpaintop/kis_pressure_rotation_option.h
+++ b/krita/plugins/paintops/libpaintop/kis_pressure_rotation_option.h
@@ -34,6 +34,10 @@ public:
     KisPressureRotationOption();
     double apply(const KisPaintInformation & info) const;
 
+    virtual void readOptionSetting(const KisPropertiesConfiguration* setting);
+
+private:
+    qreal m_defaultAngle;
 
 };
 
diff --git a/krita/ui/canvas/kis_canvas2.cpp b/krita/ui/canvas/kis_canvas2.cpp
index 707612d..2509d53 100644
--- a/krita/ui/canvas/kis_canvas2.cpp
+++ b/krita/ui/canvas/kis_canvas2.cpp
@@ -203,6 +203,13 @@ void KisCanvas2::mirrorCanvas(bool enable)
     pan(m_d->coordinatesConverter->updateOffsetAfterTransform());
 }
 
+
+qreal KisCanvas2::rotationAngle() const
+{
+    return m_d->coordinatesConverter->rotationAngle();
+}
+
+
 void KisCanvas2::rotateCanvas(qreal angle, bool updateOffset)
 {
     m_d->coordinatesConverter->rotate(m_d->coordinatesConverter->widgetCenterPoint(), \
                angle);
diff --git a/krita/ui/canvas/kis_canvas2.h b/krita/ui/canvas/kis_canvas2.h
index ccee2d3..2f4cf43 100644
--- a/krita/ui/canvas/kis_canvas2.h
+++ b/krita/ui/canvas/kis_canvas2.h
@@ -178,6 +178,8 @@ public slots:
 
     /// slot for setting the mirroring
     void mirrorCanvas(bool mirror);
+    /// canvas rotation in degrees
+    qreal rotationAngle() const;
     void rotateCanvas(qreal angle, bool updateOffset=true);
     void rotateCanvasRight15();
     void rotateCanvasLeft15();
diff --git a/krita/ui/tool/kis_tool_freehand.cc b/krita/ui/tool/kis_tool_freehand.cc
index 8b25b2c..8bdbc21 100644
--- a/krita/ui/tool/kis_tool_freehand.cc
+++ b/krita/ui/tool/kis_tool_freehand.cc
@@ -171,6 +171,7 @@ void KisToolFreehand::mousePressEvent(KoPointerEvent *e)
     if (mode() == KisTool::PAINT_MODE)
         return;
 
+    currentPaintOpPreset()->settings()->setCanvasRotation( \
static_cast<KisCanvas2*>(canvas())->rotationAngle() );  \
updateOutlineDocPoint(e->point);  
     KisConfig cfg;
@@ -444,6 +445,10 @@ QPainterPath KisToolFreehand::getOutlinePath(const QPointF \
&documentPos,  rotation = paintOp->currentRotation();
     }
 
+    if ( mode() != KisTool::PAINT_MODE || !paintOp || ( mode() == \
KisTool::PAINT_MODE && paintOp && !paintOp->rotationIsSet() ) ) { +        rotation \
+= (static_cast<KisCanvas2*>(canvas())->rotationAngle() * M_PI / 180.0); +    }
+
     QPointF imagePos = currentImage()->documentToPixel(documentPos);
     QPainterPath path = currentPaintOpPreset()->settings()->
             brushOutline(imagePos, outlineMode, scale, rotation);



_______________________________________________
kimageshop mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic