Skip to content

Commit

Permalink
Updated MoveSelectedTool.cs to convert the selected pixels to 100% op…
Browse files Browse the repository at this point in the history
…acity with a Normal blend mode, since they're going to be merged back into the layer that has its persistent BlendMode and opacity anyway. See issue PintaProject#819.
  • Loading branch information
logiclrd committed May 28, 2024
1 parent 0635255 commit 12be5dd
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions Pinta.Tools/Tools/MoveSelectedTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,37 @@ protected override void OnStartTransform (Document document)
// Copy the selection to the temp layer
document.Layers.CreateSelectionLayer ();
document.Layers.ShowSelectionLayer = true;
// Use same BlendMode, Opacity and Visibility for SelectionLayer
document.Layers.SelectionLayer.BlendMode = document.Layers.CurrentUserLayer.BlendMode;
document.Layers.SelectionLayer.Opacity = document.Layers.CurrentUserLayer.Opacity;
document.Layers.SelectionLayer.Hidden = document.Layers.CurrentUserLayer.Hidden;
// Make the SelectionLayer fully opaque and visible.
document.Layers.SelectionLayer.BlendMode = BlendMode.Normal;
document.Layers.SelectionLayer.Opacity = 1.0;
document.Layers.SelectionLayer.Hidden = false;

var g = new Context (document.Layers.SelectionLayer.Surface);
g.AppendPath (document.Selection.SelectionPath);
g.FillRule = FillRule.EvenOdd;
g.SetSourceSurface (document.Layers.CurrentUserLayer.Surface, 0, 0);
g.Clip ();
g.Paint ();

// Ensure that the pixels we copy have 100% opacity. The layer we're pasting them back into
// still has its opacity (which may be less than 1.0) set as a persistent property, so as
// soon as the move operation is committed, that opacity will apply to them once again.
// Within the context of the layer, we want the pixels to be moved as though they are
// opaque.
var savedOpacity = document.Layers.CurrentUserLayer.Opacity;
var savedBlendMode = document.Layers.CurrentUserLayer.BlendMode;

try
{
document.Layers.CurrentUserLayer.Opacity = 1.0;
document.Layers.CurrentUserLayer.BlendMode = BlendMode.Normal;

g.Clip ();
g.Paint ();
}
finally
{
document.Layers.CurrentUserLayer.Opacity = savedOpacity;
document.Layers.CurrentUserLayer.BlendMode = savedBlendMode;
}

var surf = document.Layers.CurrentUserLayer.Surface;

Expand Down

0 comments on commit 12be5dd

Please sign in to comment.