Skip to content

Commit

Permalink
Move Document layer functionality to DocumentLayers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Dec 25, 2020
1 parent 7d984e2 commit a494722
Show file tree
Hide file tree
Showing 41 changed files with 667 additions and 609 deletions.
20 changes: 10 additions & 10 deletions Pinta.Core/Actions/EditActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ private void HandlePintaCoreActionsEditFillSelectionActivated (object sender, Ev

PintaCore.Tools.Commit ();

Cairo.ImageSurface old = doc.CurrentUserLayer.Surface.Clone ();
Cairo.ImageSurface old = doc.Layers.CurrentUserLayer.Surface.Clone ();

using (var g = new Cairo.Context (doc.CurrentUserLayer.Surface)) {
using (var g = new Cairo.Context (doc.Layers.CurrentUserLayer.Surface)) {
g.AppendPath (doc.Selection.SelectionPath);
g.FillRule = FillRule.EvenOdd;

Expand All @@ -206,7 +206,7 @@ private void HandlePintaCoreActionsEditFillSelectionActivated (object sender, Ev
}

doc.Workspace.Invalidate ();
doc.History.PushNewItem (new SimpleHistoryItem (Resources.Icons.EditSelectionFill, Translations.GetString ("Fill Selection"), old, doc.CurrentUserLayerIndex));
doc.History.PushNewItem (new SimpleHistoryItem (Resources.Icons.EditSelectionFill, Translations.GetString ("Fill Selection"), old, doc.Layers.CurrentUserLayerIndex));
}

private void HandlePintaCoreActionsEditSelectAllActivated (object sender, EventArgs e)
Expand All @@ -231,9 +231,9 @@ private void HandlePintaCoreActionsEditEraseSelectionActivated (object sender, E

PintaCore.Tools.Commit ();

Cairo.ImageSurface old = doc.CurrentUserLayer.Surface.Clone ();
Cairo.ImageSurface old = doc.Layers.CurrentUserLayer.Surface.Clone ();

using (var g = new Cairo.Context (doc.CurrentUserLayer.Surface)) {
using (var g = new Cairo.Context (doc.Layers.CurrentUserLayer.Surface)) {
g.AppendPath (doc.Selection.SelectionPath);
g.FillRule = FillRule.EvenOdd;

Expand All @@ -244,9 +244,9 @@ private void HandlePintaCoreActionsEditEraseSelectionActivated (object sender, E
doc.Workspace.Invalidate ();

if (sender is string && (sender as string) == "Cut")
doc.History.PushNewItem (new SimpleHistoryItem (Resources.StandardIcons.EditCut, Translations.GetString ("Cut"), old, doc.CurrentUserLayerIndex));
doc.History.PushNewItem (new SimpleHistoryItem (Resources.StandardIcons.EditCut, Translations.GetString ("Cut"), old, doc.Layers.CurrentUserLayerIndex));
else
doc.History.PushNewItem (new SimpleHistoryItem (Resources.Icons.EditSelectionErase, Translations.GetString ("Erase Selection"), old, doc.CurrentUserLayerIndex));
doc.History.PushNewItem (new SimpleHistoryItem (Resources.Icons.EditSelectionErase, Translations.GetString ("Erase Selection"), old, doc.Layers.CurrentUserLayerIndex));
}

private void HandlePintaCoreActionsEditDeselectActivated (object sender, EventArgs e)
Expand Down Expand Up @@ -274,7 +274,7 @@ private void HandlerPintaCoreActionsEditCopyActivated (object sender, EventArgs

PintaCore.Tools.Commit ();

using (ImageSurface src = doc.GetClippedLayer (doc.CurrentUserLayerIndex)) {
using (ImageSurface src = doc.Layers.GetClippedLayer (doc.Layers.CurrentUserLayerIndex)) {

Gdk.Rectangle rect = doc.GetSelectedBounds (true);
if (rect.Width == 0 || rect.Height == 0)
Expand Down Expand Up @@ -431,13 +431,13 @@ void HandleInvertSelectionActivated (object sender, EventArgs e)
Document doc = PintaCore.Workspace.ActiveDocument;

// Clear the selection resize handles if necessary.
doc.ToolLayer.Clear ();
doc.Layers.ToolLayer.Clear ();

SelectionHistoryItem historyItem = new SelectionHistoryItem (Resources.Icons.EditSelectionInvert,
Translations.GetString ("Invert Selection"));
historyItem.TakeSnapshot ();

doc.Selection.Invert (doc.SelectionLayer.Surface, doc.ImageSize);
doc.Selection.Invert (doc.Layers.SelectionLayer.Surface, doc.ImageSize);

doc.History.PushNewItem (historyItem);
doc.Workspace.Invalidate ();
Expand Down
10 changes: 5 additions & 5 deletions Pinta.Core/Actions/ImageActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ private void HandlePintaCoreActionsImageFlattenActivated (object sender, EventAr

PintaCore.Tools.Commit ();

var oldBottomSurface = doc.UserLayers[0].Surface.Clone ();
var oldBottomSurface = doc.Layers.UserLayers[0].Surface.Clone ();

CompoundHistoryItem hist = new CompoundHistoryItem (Resources.Icons.ImageFlatten, Translations.GetString ("Flatten"));

for (int i = doc.UserLayers.Count - 1; i >= 1; i--)
hist.Push (new DeleteLayerHistoryItem (string.Empty, string.Empty, doc.UserLayers[i], i));
for (int i = doc.Layers.UserLayers.Count - 1; i >= 1; i--)
hist.Push (new DeleteLayerHistoryItem (string.Empty, string.Empty, doc.Layers.UserLayers[i], i));

doc.FlattenImage ();
doc.Layers.FlattenLayers ();

hist.Push (new SimpleHistoryItem (string.Empty, string.Empty, oldBottomSurface, 0));
doc.History.PushNewItem (hist);
Expand Down Expand Up @@ -306,7 +306,7 @@ static void CropImageToRectangle (Document doc, Gdk.Rectangle rect, Path? select

doc.Workspace.Canvas.Window.ThawUpdates();

foreach (var layer in doc.UserLayers)
foreach (var layer in doc.Layers.UserLayers)
layer.Crop (rect, selection);

hist.FinishSnapshotOfImage();
Expand Down
52 changes: 26 additions & 26 deletions Pinta.Core/Actions/LayerActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,23 @@ public void RegisterHandlers ()
#region Action Handlers
private void EnableOrDisableLayerActions (object? sender, EventArgs e)
{
if (PintaCore.Workspace.HasOpenDocuments && PintaCore.Workspace.ActiveDocument.UserLayers.Count > 1) {
if (PintaCore.Workspace.HasOpenDocuments && PintaCore.Workspace.ActiveDocument.Layers.UserLayers.Count > 1) {
PintaCore.Actions.Layers.DeleteLayer.Sensitive = true;
PintaCore.Actions.Image.Flatten.Sensitive = true;
} else {
PintaCore.Actions.Layers.DeleteLayer.Sensitive = false;
PintaCore.Actions.Image.Flatten.Sensitive = false;
}

if (PintaCore.Workspace.HasOpenDocuments && PintaCore.Workspace.ActiveDocument.CurrentUserLayerIndex > 0) {
if (PintaCore.Workspace.HasOpenDocuments && PintaCore.Workspace.ActiveDocument.Layers.CurrentUserLayerIndex > 0) {
PintaCore.Actions.Layers.MergeLayerDown.Sensitive = true;
PintaCore.Actions.Layers.MoveLayerDown.Sensitive = true;
} else {
PintaCore.Actions.Layers.MergeLayerDown.Sensitive = false;
PintaCore.Actions.Layers.MoveLayerDown.Sensitive = false;
}

if (PintaCore.Workspace.HasOpenDocuments && PintaCore.Workspace.ActiveDocument.CurrentUserLayerIndex < PintaCore.Workspace.ActiveDocument.UserLayers.Count - 1)
if (PintaCore.Workspace.HasOpenDocuments && PintaCore.Workspace.ActiveDocument.Layers.CurrentUserLayerIndex < PintaCore.Workspace.ActiveDocument.Layers.UserLayers.Count - 1)
PintaCore.Actions.Layers.MoveLayerUp.Sensitive = true;
else
PintaCore.Actions.Layers.MoveLayerUp.Sensitive = false;
Expand Down Expand Up @@ -175,7 +175,7 @@ private void HandlePintaCoreActionsLayersImportFromFileActivated (object sender,
PintaCore.System.LastDialogDirectory = fcd.CurrentFolder;

// Open the image and add it to the layers
UserLayer layer = doc.AddNewLayer(System.IO.Path.GetFileName(file));
UserLayer layer = doc.Layers.AddNewLayer (System.IO.Path.GetFileName(file));

using (var fs = new FileStream(file, FileMode.Open))
using (Pixbuf bg = new Pixbuf(fs))
Expand All @@ -185,9 +185,9 @@ private void HandlePintaCoreActionsLayersImportFromFileActivated (object sender,
g.Paint();
}

doc.SetCurrentUserLayer(layer);
doc.Layers.SetCurrentUserLayer (layer);

AddLayerHistoryItem hist = new AddLayerHistoryItem(Resources.Icons.LayerImport, Translations.GetString("Import From File"), doc.UserLayers.IndexOf(layer));
AddLayerHistoryItem hist = new AddLayerHistoryItem(Resources.Icons.LayerImport, Translations.GetString("Import From File"), doc.Layers.IndexOf(layer));
doc.History.PushNewItem(hist);

doc.Workspace.Invalidate();
Expand All @@ -200,29 +200,29 @@ private void HandlePintaCoreActionsLayersFlipVerticalActivated (object sender, E
Document doc = PintaCore.Workspace.ActiveDocument;
PintaCore.Tools.Commit ();

doc.CurrentUserLayer.FlipVertical ();
doc.Layers.CurrentUserLayer.FlipVertical ();
doc.Workspace.Invalidate ();
doc.History.PushNewItem (new InvertHistoryItem (InvertType.FlipLayerVertical, doc.CurrentUserLayerIndex));
doc.History.PushNewItem (new InvertHistoryItem (InvertType.FlipLayerVertical, doc.Layers.CurrentUserLayerIndex));
}

private void HandlePintaCoreActionsLayersFlipHorizontalActivated (object sender, EventArgs e)
{
Document doc = PintaCore.Workspace.ActiveDocument;
PintaCore.Tools.Commit ();

doc.CurrentUserLayer.FlipHorizontal ();
doc.Layers.CurrentUserLayer.FlipHorizontal ();
doc.Workspace.Invalidate ();
doc.History.PushNewItem (new InvertHistoryItem (InvertType.FlipLayerHorizontal, doc.CurrentUserLayerIndex));
doc.History.PushNewItem (new InvertHistoryItem (InvertType.FlipLayerHorizontal, doc.Layers.CurrentUserLayerIndex));
}

private void HandlePintaCoreActionsLayersMoveLayerUpActivated (object sender, EventArgs e)
{
Document doc = PintaCore.Workspace.ActiveDocument;
PintaCore.Tools.Commit ();

SwapLayersHistoryItem hist = new SwapLayersHistoryItem (Resources.Icons.LayerMoveUp, Translations.GetString ("Move Layer Up"), doc.CurrentUserLayerIndex, doc.CurrentUserLayerIndex + 1);
SwapLayersHistoryItem hist = new SwapLayersHistoryItem (Resources.Icons.LayerMoveUp, Translations.GetString ("Move Layer Up"), doc.Layers.CurrentUserLayerIndex, doc.Layers.CurrentUserLayerIndex + 1);

doc.MoveCurrentLayerUp ();
doc.Layers.MoveCurrentLayerUp ();
doc.History.PushNewItem (hist);
}

Expand All @@ -231,9 +231,9 @@ private void HandlePintaCoreActionsLayersMoveLayerDownActivated (object sender,
Document doc = PintaCore.Workspace.ActiveDocument;
PintaCore.Tools.Commit ();

SwapLayersHistoryItem hist = new SwapLayersHistoryItem (Resources.Icons.LayerMoveDown, Translations.GetString ("Move Layer Down"), doc.CurrentUserLayerIndex, doc.CurrentUserLayerIndex - 1);
SwapLayersHistoryItem hist = new SwapLayersHistoryItem (Resources.Icons.LayerMoveDown, Translations.GetString ("Move Layer Down"), doc.Layers.CurrentUserLayerIndex, doc.Layers.CurrentUserLayerIndex - 1);

doc.MoveCurrentLayerDown ();
doc.Layers.MoveCurrentLayerDown ();
doc.History.PushNewItem (hist);
}

Expand All @@ -242,13 +242,13 @@ private void HandlePintaCoreActionsLayersMergeLayerDownActivated (object sender,
Document doc = PintaCore.Workspace.ActiveDocument;
PintaCore.Tools.Commit ();

int bottomLayerIndex = doc.CurrentUserLayerIndex - 1;
var oldBottomSurface = doc.UserLayers[bottomLayerIndex].Surface.Clone ();
int bottomLayerIndex = doc.Layers.CurrentUserLayerIndex - 1;
var oldBottomSurface = doc.Layers.UserLayers[bottomLayerIndex].Surface.Clone ();

CompoundHistoryItem hist = new CompoundHistoryItem (Resources.Icons.LayerMergeDown, Translations.GetString ("Merge Layer Down"));
DeleteLayerHistoryItem h1 = new DeleteLayerHistoryItem (string.Empty, string.Empty, doc.CurrentUserLayer, doc.CurrentUserLayerIndex);
DeleteLayerHistoryItem h1 = new DeleteLayerHistoryItem (string.Empty, string.Empty, doc.Layers.CurrentUserLayer, doc.Layers.CurrentUserLayerIndex);

doc.MergeCurrentLayerDown ();
doc.Layers.MergeCurrentLayerDown ();

SimpleHistoryItem h2 = new SimpleHistoryItem (string.Empty, string.Empty, oldBottomSurface, bottomLayerIndex);
hist.Push (h1);
Expand All @@ -262,12 +262,12 @@ private void HandlePintaCoreActionsLayersDuplicateLayerActivated (object sender,
Document doc = PintaCore.Workspace.ActiveDocument;
PintaCore.Tools.Commit ();

UserLayer l = doc.DuplicateCurrentLayer();
UserLayer l = doc.Layers.DuplicateCurrentLayer();

// Make new layer the current layer
doc.SetCurrentUserLayer (l);
doc.Layers.SetCurrentUserLayer (l);

AddLayerHistoryItem hist = new AddLayerHistoryItem (Resources.Icons.LayerDuplicate, Translations.GetString ("Duplicate Layer"), doc.UserLayers.IndexOf (l));
AddLayerHistoryItem hist = new AddLayerHistoryItem (Resources.Icons.LayerDuplicate, Translations.GetString ("Duplicate Layer"), doc.Layers.IndexOf (l));
doc.History.PushNewItem (hist);
}

Expand All @@ -276,9 +276,9 @@ private void HandlePintaCoreActionsLayersDeleteLayerActivated (object sender, Ev
Document doc = PintaCore.Workspace.ActiveDocument;
PintaCore.Tools.Commit ();

DeleteLayerHistoryItem hist = new DeleteLayerHistoryItem (Resources.Icons.LayerDelete, Translations.GetString ("Delete Layer"), doc.CurrentUserLayer, doc.CurrentUserLayerIndex);
DeleteLayerHistoryItem hist = new DeleteLayerHistoryItem (Resources.Icons.LayerDelete, Translations.GetString ("Delete Layer"), doc.Layers.CurrentUserLayer, doc.Layers.CurrentUserLayerIndex);

doc.DeleteLayer (doc.CurrentUserLayerIndex, false);
doc.Layers.DeleteLayer (doc.Layers.CurrentUserLayerIndex, false);

doc.History.PushNewItem (hist);
}
Expand All @@ -288,12 +288,12 @@ private void HandlePintaCoreActionsLayersAddNewLayerActivated (object sender, Ev
Document doc = PintaCore.Workspace.ActiveDocument;
PintaCore.Tools.Commit ();

UserLayer l = doc.AddNewLayer(string.Empty);
UserLayer l = doc.Layers.AddNewLayer (string.Empty);

// Make new layer the current layer
doc.SetCurrentUserLayer (l);
doc.Layers.SetCurrentUserLayer (l);

AddLayerHistoryItem hist = new AddLayerHistoryItem (Resources.Icons.LayerNew, Translations.GetString ("Add New Layer"), doc.UserLayers.IndexOf (l));
AddLayerHistoryItem hist = new AddLayerHistoryItem (Resources.Icons.LayerNew, Translations.GetString ("Add New Layer"), doc.Layers.IndexOf (l));
doc.History.PushNewItem (hist);
}
#endregion
Expand Down
Loading

0 comments on commit a494722

Please sign in to comment.