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 d2fd3f9
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions Pinta.Tools/Tools/MoveSelectedTool.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// MoveSelectedTool.cs
//
//
// Author:
// Jonathan Pobst <[email protected]>
//
//
// Copyright (c) 2010 Jonathan Pobst
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down 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 d2fd3f9

Please sign in to comment.