~mantas/pinta/stable

« back to all changes in this revision

Viewing changes to Pinta.Core/HistoryItems/SwapLayersHistoryItem.cs

  • Committer: Iain Lane
  • Date: 2010-02-19 15:33:30 UTC
  • Revision ID: git-v1:92cc09614a4e2801bfe39cd971f6b31e694a500b
Imported Upstream version 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// SwapLayersHistoryItem.cs
 
3
//  
 
4
// Author:
 
5
//       Jonathan Pobst <monkey@jpobst.com>
 
6
// 
 
7
// Copyright (c) 2010 Jonathan Pobst
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
 
 
29
namespace Pinta.Core
 
30
{
 
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
 
34
        {
 
35
                private int layer_index_1;
 
36
                private int layer_index_2;
 
37
 
 
38
                public SwapLayersHistoryItem (string icon, string text, int layer1, int layer2) : base (icon, text)
 
39
                {
 
40
                        layer_index_1 = layer1;
 
41
                        layer_index_2 = layer2;
 
42
                }
 
43
                
 
44
                public override void Undo ()
 
45
                {
 
46
                        Swap ();
 
47
                }
 
48
 
 
49
                public override void Redo ()
 
50
                {
 
51
                        Swap ();
 
52
                }
 
53
 
 
54
                private void Swap ()
 
55
                {
 
56
                        int selected = PintaCore.Layers.CurrentLayerIndex;
 
57
                        
 
58
                        int l1 = Math.Min (layer_index_1, layer_index_2);
 
59
                        int l2 = Math.Max (layer_index_1, layer_index_2);
 
60
 
 
61
                        Layer layer1 = PintaCore.Layers[l1];
 
62
                        Layer layer2 = PintaCore.Layers[l2];
 
63
 
 
64
                        PintaCore.Layers.DeleteLayer (l1, false);
 
65
                        PintaCore.Layers.DeleteLayer (l2 - 1, false);
 
66
 
 
67
                        PintaCore.Layers.Insert (layer2, l1);
 
68
                        PintaCore.Layers.Insert (layer1, l2);
 
69
                        
 
70
                        PintaCore.Layers.SetCurrentLayer (selected);
 
71
                }
 
72
        }
 
73
}