Skip to content

Commit

Permalink
Properly apply opacity to non-editable fills
Browse files Browse the repository at this point in the history
They previewed correctly, but then got applied with 100% opacity
instead.
  • Loading branch information
askmeaboutlo0m committed Oct 23, 2024
1 parent b781302 commit 877f171
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/libclient/tools/floodfill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ void FloodFill::fillAt(const QPointF &point, int activeLayerId, bool editable)
m_lastActiveLayerId = activeLayerId;
m_originalLayerId = activeLayerId;
m_originalBlendMode = m_blendMode;
m_originalOpacity = m_opacity;

QColor fillColor = m_blendMode == DP_BLEND_MODE_ERASE
? Qt::black
Expand Down Expand Up @@ -366,7 +367,7 @@ void FloodFill::previewPending()
disposePending();
}
} else {
adjustPendingImage(false);
adjustPendingImage(true, false);
canvas->paintEngine()->previewFill(
layerId, m_blendMode, m_opacity, m_pendingPos.x(),
m_pendingPos.y(), m_pendingImage);
Expand All @@ -391,9 +392,7 @@ void FloodFill::flushPending()
.data(canvas::LayerListModel::IsGroupRole)
.toBool();
if(canFill) {
if(m_pendingEditable) {
adjustPendingImage(true);
}
adjustPendingImage(m_pendingEditable, true);
net::Client *client = m_owner.client();
uint8_t contextId = client->myId();
net::MessageList msgs;
Expand Down Expand Up @@ -421,12 +420,13 @@ void FloodFill::disposePending()
}
}

void FloodFill::adjustPendingImage(bool adjustOpacity)
void FloodFill::adjustPendingImage(bool adjustColor, bool adjustOpacity)
{
QColor color = m_owner.foregroundColor();
bool needsColorChange =
m_blendMode != DP_BLEND_MODE_ERASE && m_pendingColor != color;
bool needsOpacityChange = adjustOpacity && m_opacity < 1.0;
qreal opacity = m_pendingEditable ? m_opacity : m_originalOpacity;
bool needsColorChange = adjustColor && m_blendMode != DP_BLEND_MODE_ERASE &&
m_pendingColor != color;
bool needsOpacityChange = adjustOpacity && opacity < 1.0;
if(needsColorChange || needsOpacityChange) {
QPainter painter(&m_pendingImage);
QRect rect = m_pendingImage.rect();
Expand All @@ -437,7 +437,7 @@ void FloodFill::adjustPendingImage(bool adjustOpacity)
}
if(needsOpacityChange) {
painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
painter.setOpacity(m_opacity);
painter.setOpacity(opacity);
painter.fillRect(rect, Qt::black);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/libclient/tools/floodfill.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FloodFill final : public Tool {
void flushPending();
void disposePending();

void adjustPendingImage(bool adjustOpacity);
void adjustPendingImage(bool adjustColor, bool adjustOpacity);

void emitFloodFillStateChanged();

Expand Down Expand Up @@ -87,6 +87,7 @@ class FloodFill final : public Tool {
QColor m_pendingColor;
int m_originalLayerId = 0;
int m_originalBlendMode;
qreal m_originalOpacity;
QCursor m_bucketCursor;
QCursor m_pendingCursor;
QCursor m_confirmCursor;
Expand Down

0 comments on commit 877f171

Please sign in to comment.