Skip to content

Commit

Permalink
Try to fix seams appearing in Qt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStevns committed Sep 28, 2023
1 parent 25624da commit 70fb576
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
27 changes: 18 additions & 9 deletions core_lib/src/canvaspainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ void CanvasPainter::reset()
{
mPostLayersPixmap = QPixmap(mCanvas.size());
mPreLayersPixmap = QPixmap(mCanvas.size());
mCurrentLayerPixmap = QPixmap(mCanvas.size());
mOnionSkinPixmap = QPixmap(mCanvas.size());
mPreLayersPixmap.fill(Qt::transparent);
mCanvas.fill(Qt::transparent);
mCurrentLayerPixmap = QPixmap(mCanvas.size());
mCurrentLayerPixmap.fill(Qt::transparent);
mPostLayersPixmap.fill(Qt::transparent);
mOnionSkinPixmap = QPixmap(mCanvas.size());
mOnionSkinPixmap.fill(Qt::transparent);
mCurrentLayerPixmap.setDevicePixelRatio(mCanvas.devicePixelRatioF());
mPreLayersPixmap.setDevicePixelRatio(mCanvas.devicePixelRatioF());
mPostLayersPixmap.setDevicePixelRatio(mCanvas.devicePixelRatioF());
mOnionSkinPixmap.setDevicePixelRatio(mCanvas.devicePixelRatioF());
}

void CanvasPainter::setViewTransform(const QTransform view, const QTransform viewInverse)
Expand Down Expand Up @@ -93,7 +97,7 @@ void CanvasPainter::paintCached(const QRect& blitRect)
QPainter mainPainter;
initializePainter(mainPainter, mCanvas, blitRect);
mainPainter.setWorldMatrixEnabled(false);
mainPainter.drawPixmap(blitRect, mPreLayersPixmap, blitRect);
mainPainter.drawPixmap(QPointF(), mPreLayersPixmap);
mainPainter.setWorldMatrixEnabled(true);

paintCurrentFrame(mainPainter, blitRect, mCurrentLayerIndex, mCurrentLayerIndex);
Expand All @@ -108,7 +112,7 @@ void CanvasPainter::paintCached(const QRect& blitRect)
}

mainPainter.setWorldMatrixEnabled(false);
mainPainter.drawPixmap(blitRect, mPostLayersPixmap, blitRect);
mainPainter.drawPixmap(QPointF(), mPostLayersPixmap);
mainPainter.setWorldMatrixEnabled(true);
}

Expand All @@ -122,6 +126,9 @@ void CanvasPainter::initializePainter(QPainter& painter, QPaintDevice& device, c
{
painter.begin(&device);

// Only draw inside the clipped rectangle
painter.setClipRect(blitRect);

// Clear the area that's about to be painted again, to avoid painting on top of existing pixels
// causing artifacts.
painter.setCompositionMode(QPainter::CompositionMode_Clear);
Expand Down Expand Up @@ -177,7 +184,7 @@ void CanvasPainter::paint(const QRect& blitRect)
preLayerPainter.end();

mainPainter.setWorldMatrixEnabled(false);
mainPainter.drawPixmap(blitRect, mPreLayersPixmap, blitRect);
mainPainter.drawPixmap(QPointF(), mPreLayersPixmap);
mainPainter.setWorldMatrixEnabled(true);

paintCurrentFrame(mainPainter, blitRect, mCurrentLayerIndex, mCurrentLayerIndex);
Expand All @@ -187,7 +194,7 @@ void CanvasPainter::paint(const QRect& blitRect)
postLayerPainter.end();

mainPainter.setWorldMatrixEnabled(false);
mainPainter.drawPixmap(blitRect, mPostLayersPixmap, blitRect);
mainPainter.drawPixmap(QPointF(), mPostLayersPixmap);
mainPainter.setWorldMatrixEnabled(true);

mPreLayersPixmapCacheValid = true;
Expand Down Expand Up @@ -273,7 +280,7 @@ void CanvasPainter::paintOnionSkinFrame(QPainter& painter, QPainter& onionSkinPa
onionSkinPainter.setBrush(colorBrush);
onionSkinPainter.drawRect(painter.viewport());
}
painter.drawPixmap(blitRect, mOnionSkinPixmap, blitRect);
painter.drawPixmap(QPointF(), mOnionSkinPixmap);
}

void CanvasPainter::paintCurrentBitmapFrame(QPainter& painter, const QRect& blitRect, Layer* layer, bool isCurrentLayer)
Expand Down Expand Up @@ -320,7 +327,8 @@ void CanvasPainter::paintCurrentBitmapFrame(QPainter& painter, const QRect& blit
paintTransformedSelection(currentBitmapPainter, paintedImage, mSelection);
}

painter.drawPixmap(blitRect, mCurrentLayerPixmap, blitRect);
// painter.setClipRect(blitRect);
painter.drawPixmap(QPointF(), mCurrentLayerPixmap);
}

void CanvasPainter::paintCurrentVectorFrame(QPainter& painter, const QRect& blitRect, Layer* layer, bool isCurrentLayer)
Expand Down Expand Up @@ -357,9 +365,10 @@ void CanvasPainter::paintCurrentVectorFrame(QPainter& painter, const QRect& blit
painter.setWorldMatrixEnabled(false);
painter.setTransform(QTransform());

// painter.setClipRect(blitRect);
// Remember to adjust opacity based on additional opacity value from the keyframe
painter.setOpacity(vectorImage->getOpacity() - (1.0-painter.opacity()));
painter.drawPixmap(blitRect, mCurrentLayerPixmap, blitRect);
painter.drawPixmap(QPointF(), mCurrentLayerPixmap);
}

void CanvasPainter::paintTransformedSelection(QPainter& painter, BitmapImage* bitmapImage, const QRect& selection) const
Expand Down
7 changes: 3 additions & 4 deletions core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void ScribbleArea::onTileUpdated(TiledBuffer* tiledBuffer, Tile* tile)
{
Q_UNUSED(tiledBuffer);
const QRectF& mappedRect = mEditor->view()->getView().mapRect(QRectF(tile->bounds()));
update(mappedRect.toRect());
update(mappedRect.toAlignedRect());
}

void ScribbleArea::onTileCreated(TiledBuffer* tiledBuffer, Tile* tile)
Expand All @@ -213,7 +213,7 @@ void ScribbleArea::onTileCreated(TiledBuffer* tiledBuffer, Tile* tile)
}

const QRectF& mappedRect = mEditor->view()->getView().mapRect(QRectF(tile->bounds()));
update(mappedRect.toRect());
update(mappedRect.toAlignedRect());
}

void ScribbleArea::updateFrame()
Expand Down Expand Up @@ -819,7 +819,7 @@ void ScribbleArea::resizeEvent(QResizeEvent* event)
QWidget::resizeEvent(event);
mDevicePixelRatio = devicePixelRatioF();
mCanvas = QPixmap(QSizeF(size() * mDevicePixelRatio).toSize());

mCanvas.setDevicePixelRatio(mDevicePixelRatio);
mEditor->view()->setCanvasSize(size());

invalidateCacheForFrame(mEditor->currentFrame());
Expand Down Expand Up @@ -1236,7 +1236,6 @@ void ScribbleArea::prepCanvas(int frame, QRect rect)

void ScribbleArea::drawCanvas(int frame, QRect rect)
{
mCanvas.setDevicePixelRatio(mDevicePixelRatio);
prepCanvas(frame, rect);
prepCameraPainter(frame);
prepOverlays(frame);
Expand Down

0 comments on commit 70fb576

Please sign in to comment.