2
// SwapLayersHistoryItem.cs
5
// Jonathan Pobst <monkey@jpobst.com>
7
// Copyright (c) 2010 Jonathan Pobst
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31
// These are actions that can be undone by simply repeating
32
// the action: invert colors, rotate 180 degrees, etc
33
public class SwapLayersHistoryItem : BaseHistoryItem
35
private int layer_index_1;
36
private int layer_index_2;
38
public SwapLayersHistoryItem (string icon, string text, int layer1, int layer2) : base (icon, text)
40
layer_index_1 = layer1;
41
layer_index_2 = layer2;
44
public override void Undo ()
49
public override void Redo ()
56
int selected = PintaCore.Layers.CurrentLayerIndex;
58
int l1 = Math.Min (layer_index_1, layer_index_2);
59
int l2 = Math.Max (layer_index_1, layer_index_2);
61
Layer layer1 = PintaCore.Layers[l1];
62
Layer layer2 = PintaCore.Layers[l2];
64
PintaCore.Layers.DeleteLayer (l1, false);
65
PintaCore.Layers.DeleteLayer (l2 - 1, false);
67
PintaCore.Layers.Insert (layer2, l1);
68
PintaCore.Layers.Insert (layer1, l2);
70
PintaCore.Layers.SetCurrentLayer (selected);