<div dir="ltr"><div><div><div><div></div>Hi, Juan!<br><br></div>I checked IRC backlog for 22.01 where you were asking about backporting your patches. Your patches are really good! I like the new ants' look!<br><br></div>
<div>You can freely backport the first patch to 2.8 right now. About the second one (with the option box), I would wait for Boud's/translators' approval, because it adds a new string. I'm not sure I know the process of pinging translators about new strings.<br>
</div><br></div>If you like, I can do the backporting for you today. I have two calligra checkouts for that :)<br><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 22, 2014 at 9:50 PM, Juan Palacios <span dir="ltr"><<a href="mailto:jpalaciosdev@gmail.com" target="_blank">jpalaciosdev@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Git commit 436b00539f7a5c94523af6e93bd98d3b72c00d1b by Juan Palacios.<br>
Committed on 22/01/2014 at 17:23.<br>
Pushed by jpalacios into branch 'master'.<br>
<br>
Change selection outline decoration<br>
<br>
The old selection outline draw method was implemented using the<br>
technique of Bill Atkinson. This method has the disadvantage of not<br>
looking like marching ants with selection borders that aren't parallel<br>
to the coordinate axes.<br>
<br>
The new method uses a QPen with a dash pattern to draw the ants, so they<br>
are always displayed as dashes, no matter the angle that borders has.<br>
It is draw in two passes. The first one uses a QPen configured<br>
to draw the selection outline in white. Then, the selection outline is<br>
draw again above the white outline, but this time using other QPen<br>
configured to draw the ants in black.<br>
<br>
Also, the outline is drawed without antialiasing.<br>
<br>
M  +32   -26   krita/ui/kis_selection_decoration.cc<br>
M  +3    -2    krita/ui/kis_selection_decoration.h<br>
<br>
<a href="http://commits.kde.org/calligra/436b00539f7a5c94523af6e93bd98d3b72c00d1b" target="_blank">http://commits.kde.org/calligra/436b00539f7a5c94523af6e93bd98d3b72c00d1b</a><br>
<br>
diff --git a/krita/ui/kis_selection_decoration.cc b/krita/ui/kis_selection_decoration.cc<br>
index 78a05d2..902c2a4 100644<br>
--- a/krita/ui/kis_selection_decoration.cc<br>
+++ b/krita/ui/kis_selection_decoration.cc<br>
@@ -35,31 +35,30 @@<br>
 #include "kis_canvas_resource_provider.h"<br>
 #include "kis_coordinates_converter.h"<br>
<br>
+static const unsigned int ANT_LENGTH = 4;<br>
+static const unsigned int ANT_SPACE = 4;<br>
+static const unsigned int ANT_ADVANCE_WIDTH = ANT_LENGTH + ANT_SPACE;<br>
+<br>
 KisSelectionDecoration::KisSelectionDecoration(KisView2* view)<br>
     : KisCanvasDecoration("selection", i18n("Selection decoration"), view),<br>
       m_signalCompressor(500 /*ms*/, KisSignalCompressor::FIRST_INACTIVE),<br>
+      m_outlinePath(),<br>
+      m_offset(0),<br>
+      m_antsPen(Qt::CustomDashLine),<br>
+      m_outlinePen(Qt::SolidLine),<br>
       m_mode(Ants)<br>
 {<br>
-    m_offset = 0;<br>
-<br>
-    QRgb white = QColor(Qt::white).rgb();<br>
-    QRgb black = QColor(Qt::black).rgb();<br>
-<br>
-    for (int i = 0; i < 8; i++) {<br>
-        QImage texture(8, 8, QImage::Format_RGB32);<br>
-        for (int y = 0; y < 8; y++) {<br>
-            QRgb *pixel = reinterpret_cast<QRgb *>(texture.scanLine(y));<br>
-            for (int x = 0; x < 8; x++) {<br>
-                pixel[x] = ((x + y + i) % 8 < 4) ? black : white;<br>
-            }<br>
-        }<br>
-        QBrush brush;<br>
-        brush.setTextureImage(texture);<br>
-        m_brushes << brush;<br>
-    }<br>
+    QVector<qreal> antDashPattern;<br>
+    antDashPattern << ANT_LENGTH << ANT_SPACE;<br>
+    m_antsPen.setDashPattern(antDashPattern);<br>
+    m_antsPen.setCosmetic(true);<br>
+    m_antsPen.setColor(Qt::black);<br>
+<br>
+    m_outlinePen.setCosmetic(true);<br>
+    m_outlinePen.setColor(Qt::white);<br>
<br>
     m_antsTimer = new QTimer(this);<br>
-    m_antsTimer->setInterval(300);<br>
+    m_antsTimer->setInterval(150);<br>
     m_antsTimer->setSingleShot(false);<br>
     connect(m_antsTimer, SIGNAL(timeout()), SLOT(antsAttackEvent()));<br>
<br>
@@ -123,7 +122,8 @@ void KisSelectionDecoration::antsAttackEvent()<br>
     if (!selection) return;<br>
<br>
     if (selectionIsActive()) {<br>
-        m_offset = (m_offset + 1) % 8;<br>
+        m_offset = (m_offset + 1) % ANT_ADVANCE_WIDTH;<br>
+        m_antsPen.setDashOffset(m_offset);<br>
         view()->canvasBase()->updateCanvas();<br>
     }<br>
 }<br>
@@ -135,20 +135,26 @@ void KisSelectionDecoration::drawDecoration(QPainter& gc, const QRectF& updateRe<br>
     Q_ASSERT_X(m_mode == Ants, "KisSelectionDecoration.cc", "MASK MODE NOT SUPPORTED YET!");<br>
<br>
     if (!selectionIsActive()) return;<br>
-    KisSelectionSP selection = view()->selection();<br>
+    if (m_outlinePath.isEmpty()) return;<br>
<br>
     gc.save();<br>
     gc.setTransform(QTransform(), false);<br>
-    gc.setRenderHints(0);<br>
<br>
-    QPen pen(m_brushes[m_offset], 0);<br>
+    // Disable antialiasing. This allow us to draw the selection outline with a consistent look in all zoom levels.<br>
+    // Reason: The selection outline is 1 pixel width. Antialiasing will produce a fuzzy gray line of 2 pixels in most cases,<br>
+    // but sometimes can produce a clear line of 1 pixel, while still producing other fuzzy lines at the same time! Thus,<br>
+    // the overall look is not consistent if antialiasing is enabled for 1 pixel width lines.<br>
+    gc.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, false);<br>
+<br>
     QTransform transform = converter->imageToWidgetTransform();<br>
<br>
-    gc.setPen(pen);<br>
+    // render selection outline in white<br>
+    gc.setPen(m_outlinePen);<br>
+    gc.drawPath(transform.map(m_outlinePath));<br>
<br>
-    if (!m_outlinePath.isEmpty()) {<br>
-        gc.drawPath(transform.map(m_outlinePath));<br>
-    }<br>
+    // render marching ants in black (above the white outline)<br>
+    gc.setPen(m_antsPen);<br>
+    gc.drawPath(transform.map(m_outlinePath));<br>
<br>
     gc.restore();<br>
 }<br>
diff --git a/krita/ui/kis_selection_decoration.h b/krita/ui/kis_selection_decoration.h<br>
index 3e3deca..a65f15a 100644<br>
--- a/krita/ui/kis_selection_decoration.h<br>
+++ b/krita/ui/kis_selection_decoration.h<br>
@@ -20,7 +20,7 @@<br>
<br>
 #include <QTimer><br>
 #include <QPolygon><br>
-#include <QBrush><br>
+#include <QPen><br>
<br>
 #include <kis_signal_compressor.h><br>
 #include "canvas/kis_canvas_decoration.h"<br>
@@ -58,7 +58,8 @@ private:<br>
     QTimer* m_antsTimer;<br>
     int m_offset;<br>
<br>
-    QList<QBrush> m_brushes;<br>
+    QPen m_antsPen;<br>
+    QPen m_outlinePen;<br>
     Mode m_mode;<br>
 };<br>
<br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>Dmitry Kazakov
</div>