[graphics/krita] libs/ui/tool: Change paintedCircleCanvasPreview return logic to be more logical

Emmet O'Neill <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 93ddac07fa5e9f3324faa9c6e1fcb1210737c509 by Emmet O'Neill, on behalf of Dat Le.
Committed on 13/08/2026 at 23:16.
Pushed by emmetoneill into branch 'master'.

Change paintedCircleCanvasPreview return logic to be more logical

M  +9    -7    libs/ui/tool/KisAsyncColorSamplerHelper.cpp
M  +1    -2    libs/ui/tool/KisAsyncColorSamplerHelper.h

https://invent.kde.org/graphics/krita/-/commit/93ddac07fa5e9f3324faa9c6e1fcb1210737c509

diff --git a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
index 2248a24ac66..8dd11defc2c 100644
--- a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
+++ b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
@@ -674,9 +674,11 @@ void KisAsyncColorSamplerHelper::paintCircle(QPainter &gc,
         zoomDocRectF.setSize(zoomDocRectF.size() / m_d->circleZoomPreviewScale);
         zoomDocRectF.moveCenter(m_d->sampleDocPoint);
 
-        bool paintLater = paintCircleCanvasPreview(cachePainter, cacheRect, zoomDocRectF, tf.map(m_d->cacheCircleInnerClip));
+        bool isPainted = paintCircleCanvasPreview(cachePainter, cacheRect, zoomDocRectF, tf.map(m_d->cacheCircleInnerClip));
 
-        if (!paintLater) {
+        // This is only false for the very first frame, when canvas preview is not yet available, leave the center hollow for better visual
+        // the gray flickering otherwise would be an eyesore
+        if (isPainted) {
             paintCircleReferenceImagePreview(cachePainter, cacheRect, zoomDocRectF, tf.map(m_d->cacheCircleInnerClip));
 
             // Draw crosshair if preview is offseted
@@ -754,6 +756,7 @@ QImage KisAsyncColorSamplerHelper::cacheCanvasImage(QRect &canvasPixelRect) {
         if (!m_d->oldCanvasPixelRect.isNull()) canvasPixelRect = m_d->oldCanvasPixelRect;
         return m_d->cacheCanvasPreviewImage;
     }
+
     canvasPixelRect.translate(-m_d->cacheCanvasPreviewRect.topLeft());
     m_d->oldCanvasPixelRect = canvasPixelRect;
 
@@ -774,10 +777,9 @@ bool KisAsyncColorSamplerHelper::paintCircleCanvasPreview(QPainter &gc, const QR
     canvasPixelRect.moveCenter(image->documentToImagePixelFloored(zoomDocRectF.center()));
 
     QImage cachedImage = cacheCanvasImage(canvasPixelRect);
-    // A null QImage and a null canvasPixelRect => No need to paint canvas
-    // A null QImage and a not null canvasPixelRect => Cache miss, skip painting and paint later when canvas image is ready
-    bool paintLater = cachedImage.isNull() && !canvasPixelRect.isNull();
-    if (cachedImage.isNull()) return paintLater;
+    // If cachedImage and canvasPixelRect is null, painting is not needed
+    // If cachedImage is null and canvasPixelRect is not null, painting was deferred
+    if (cachedImage.isNull()) return canvasPixelRect.isNull();
 
     gc.save();
     gc.setCompositionMode(QPainter::CompositionMode_SourceOver);
@@ -791,7 +793,7 @@ bool KisAsyncColorSamplerHelper::paintCircleCanvasPreview(QPainter &gc, const QR
 
     gc.restore();
 
-    return false;
+    return true;
 }
 
 // Preview won't respect opacity because the color sampled doesn't respect opacity either
diff --git a/libs/ui/tool/KisAsyncColorSamplerHelper.h b/libs/ui/tool/KisAsyncColorSamplerHelper.h
index 074489ba649..528d7797566 100644
--- a/libs/ui/tool/KisAsyncColorSamplerHelper.h
+++ b/libs/ui/tool/KisAsyncColorSamplerHelper.h
@@ -83,8 +83,7 @@ private:
     void paintCircle(QPainter &gc, const QRectF &viewRectF, const QColor &currentColor, const QColor &baseColor);
 
     void paintCircleCrosshair(QPainter &gc, const QRectF &viewRectF, const QColor &currentColor);
-    // Return true if cache miss, will repaint later when canvas image is fetched
-    // Return false if cache hit, and painted
+    // Returns true if painted or not needed, returns false if painting was deferred
     bool paintCircleCanvasPreview(QPainter &gc, const QRectF &viewRectF, const QRectF &zoomDocRectF, const QPainterPath &clip);
     void paintCircleReferenceImagePreview(QPainter &gc, const QRectF &viewRectF, const QRectF &zoomDocRectF, const QPainterPath &clip);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.