Skip to content

Commit

Permalink
[Fixes bug #1176847] Display the selection layer on top of the active
Browse files Browse the repository at this point in the history
layer in the layers list widget.

This solution fixes the original issue (bug #1175733), and I reverted
the changes that caused a regression (bug #1176847).
  • Loading branch information
cameronwhite committed Jun 2, 2013
1 parent eca4cbc commit d628f2e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
11 changes: 4 additions & 7 deletions Pinta.Core/Classes/Document.cs
Expand Up @@ -388,7 +388,7 @@ public UserLayer DuplicateCurrentLayer()
return layer;
}

public void FinishSelection (CompoundHistoryItem compoundAction)
public void FinishSelection ()
{
// We don't have an uncommitted layer, abort
if (!ShowSelectionLayer)
Expand All @@ -406,11 +406,7 @@ public void FinishSelection (CompoundHistoryItem compoundAction)
DestroySelectionLayer ();
Workspace.Invalidate ();

if (compoundAction != null) {
compoundAction.Push (hist);
} else {
Workspace.History.PushNewItem (hist);
}
Workspace.History.PushNewItem (hist);
}

// Flatten image
Expand Down Expand Up @@ -838,8 +834,9 @@ public void Paste (bool toNewLayer, int x = 0, int y = 0)
new Cairo.Rectangle (x, y, cbImage.Width, cbImage.Height));
ShowSelection = true;

Workspace.Invalidate ();

paste_action.Push (new PasteHistoryItem (cbImage, old_selection, old_show_selection));
FinishSelection(paste_action);
History.PushNewItem (paste_action);
}

Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Managers/LayerManager.cs
Expand Up @@ -97,7 +97,7 @@ public void SetCurrentLayer(UserLayer layer)

public void FinishSelection ()
{
PintaCore.Workspace.ActiveDocument.FinishSelection (null);
PintaCore.Workspace.ActiveDocument.FinishSelection ();
}

// Adds a new layer above the current one
Expand Down
32 changes: 30 additions & 2 deletions Pinta.Gui.Widgets/Widgets/Layers/LayersListWidget.cs
Expand Up @@ -40,6 +40,11 @@ public class LayersListWidget : ScrolledWindow
{
private TreeView tree;
private TreeStore store;

// For the active layer, we also draw the selection layer on top of it,
// so we can't directly use that layer's surface.
private Cairo.ImageSurface active_layer_surface;
private CanvasRenderer canvas_renderer = new CanvasRenderer (false);

private const int store_index_thumbnail = 0;
private const int store_index_name = 1;
Expand Down Expand Up @@ -194,11 +199,34 @@ public void Reset ()
{
store.Clear ();

if (active_layer_surface != null) {
active_layer_surface.Dispose ();
active_layer_surface = null;
}

if (!PintaCore.Workspace.HasOpenDocuments)
return;

var doc = PintaCore.Workspace.ActiveDocument;

foreach (var layer in (PintaCore.Workspace.ActiveDocument.UserLayers as IEnumerable<Layer>).Reverse ())
store.AppendValues (layer.Surface, layer.Name, !layer.Hidden, layer);
foreach (var layer in (doc.UserLayers as IEnumerable<Layer>).Reverse ()) {
var surf = layer.Surface;

// Draw the selection layer on top of the active layer.
if (layer == doc.CurrentUserLayer && doc.ShowSelectionLayer) {
active_layer_surface = new Cairo.ImageSurface (Cairo.Format.Argb32, thumbnail_width,
thumbnail_height);
canvas_renderer.Initialize (doc.ImageSize,
new Gdk.Size (thumbnail_width, thumbnail_height));

var layers = new List<Layer> { layer, doc.SelectionLayer };
canvas_renderer.Render (layers, active_layer_surface, Gdk.Point.Zero);

surf = active_layer_surface;
}

store.AppendValues (surf, layer.Name, !layer.Hidden, layer);
}

SelectLayerInTreeView (PintaCore.Layers.Count - PintaCore.Layers.CurrentLayerIndex - 1);
}
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Tools/Tools/MoveSelectedTool.cs
Expand Up @@ -141,7 +141,7 @@ protected override void OnFinishTransform ()
protected override void OnCommit ()
{
try {
PintaCore.Workspace.ActiveDocument.FinishSelection (null);
PintaCore.Workspace.ActiveDocument.FinishSelection ();
} catch (Exception) {
// Ignore an error where ActiveDocument fails.
}
Expand All @@ -152,7 +152,7 @@ protected override void OnDeactivated ()
base.OnDeactivated ();

if (PintaCore.Workspace.HasOpenDocuments) {
PintaCore.Workspace.ActiveDocument.FinishSelection (null);
PintaCore.Workspace.ActiveDocument.FinishSelection ();
}
}
}
Expand Down

0 comments on commit d628f2e

Please sign in to comment.