1 // 2 // InvertHistoryItem.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 using Mono.Unix; 29 30 namespace Pinta.Core 31 { 32 // These are actions that can be undone by simply repeating 33 // the action: invert colors, rotate 180 degrees, etc 34 public class InvertHistoryItem : BaseHistoryItem 35 { 36 private InvertType type; 37 private int layer_index; 38 InvertHistoryItem(InvertType type)39 public InvertHistoryItem (InvertType type) 40 { 41 this.type = type; 42 43 switch (type) { 44 // Invert is disabled because it creates a new history item 45 //case InvertType.InvertColors: 46 // Text = Mono.Unix.Catalog.GetString ("Invert Colors"); 47 // Icon = "Menu.Adjustments.InvertColors.png"; 48 // break; 49 case InvertType.Rotate180: 50 Text = Catalog.GetString ("Rotate 180°"); 51 Icon = "Menu.Image.Rotate180CW.png"; 52 break; 53 case InvertType.FlipHorizontal: 54 Text = Catalog.GetString ("Flip Image Horizontal"); 55 Icon = "Menu.Image.FlipHorizontal.png"; 56 break; 57 case InvertType.FlipVertical: 58 Text = Catalog.GetString ("Flip Image Vertical"); 59 Icon = "Menu.Image.FlipVertical.png"; 60 break; 61 case InvertType.Rotate90CW: 62 Text = Catalog.GetString ("Rotate 90° Clockwise"); 63 Icon = "Menu.Image.Rotate90CW.png"; 64 break; 65 case InvertType.Rotate90CCW: 66 Text = Catalog.GetString ("Rotate 90° Counter-Clockwise"); 67 Icon = "Menu.Image.Rotate90CCW.png"; 68 break; 69 } 70 } 71 InvertHistoryItem(InvertType type, int layerIndex)72 public InvertHistoryItem (InvertType type, int layerIndex) 73 { 74 this.type = type; 75 this.layer_index = layerIndex; 76 77 switch (type) { 78 case InvertType.FlipLayerHorizontal: 79 Text = Catalog.GetString ("Flip Layer Horizontal"); 80 Icon = "Menu.Image.FlipHorizontal.png"; 81 break; 82 case InvertType.FlipLayerVertical: 83 Text = Catalog.GetString ("Flip Layer Vertical"); 84 Icon = "Menu.Image.FlipVertical.png"; 85 break; 86 } 87 } 88 Undo()89 public override void Undo () 90 { 91 switch (type) { 92 //case InvertType.InvertColors: 93 // PintaCore.Actions.Adjustments.InvertColors.Activate (); 94 // break; 95 case InvertType.Rotate180: 96 PintaCore.Layers.RotateImage180 (); 97 break; 98 case InvertType.FlipHorizontal: 99 PintaCore.Layers.FlipImageHorizontal (); 100 break; 101 case InvertType.FlipVertical: 102 PintaCore.Layers.FlipImageVertical (); 103 break; 104 case InvertType.Rotate90CW: 105 PintaCore.Layers.RotateImageCCW (); 106 break; 107 case InvertType.Rotate90CCW: 108 PintaCore.Layers.RotateImageCW (); 109 break; 110 case InvertType.FlipLayerHorizontal: 111 PintaCore.Workspace.ActiveDocument.UserLayers[layer_index].FlipHorizontal (); 112 PintaCore.Workspace.Invalidate (); 113 break; 114 case InvertType.FlipLayerVertical: 115 PintaCore.Workspace.ActiveDocument.UserLayers[layer_index].FlipVertical (); 116 PintaCore.Workspace.Invalidate (); 117 break; 118 } 119 } 120 Redo()121 public override void Redo () 122 { 123 switch (type) { 124 //case InvertType.InvertColors: 125 // PintaCore.Actions.Adjustments.InvertColors.Activate (); 126 // break; 127 case InvertType.Rotate180: 128 PintaCore.Layers.RotateImage180 (); 129 break; 130 case InvertType.FlipHorizontal: 131 PintaCore.Layers.FlipImageHorizontal (); 132 break; 133 case InvertType.FlipVertical: 134 PintaCore.Layers.FlipImageVertical (); 135 break; 136 case InvertType.Rotate90CW: 137 PintaCore.Layers.RotateImageCW (); 138 break; 139 case InvertType.Rotate90CCW: 140 PintaCore.Layers.RotateImageCCW (); 141 break; 142 case InvertType.FlipLayerHorizontal: 143 PintaCore.Workspace.ActiveDocument.UserLayers[layer_index].FlipHorizontal (); 144 PintaCore.Workspace.Invalidate (); 145 break; 146 case InvertType.FlipLayerVertical: 147 PintaCore.Workspace.ActiveDocument.UserLayers[layer_index].FlipVertical (); 148 PintaCore.Workspace.Invalidate (); 149 break; 150 } 151 } 152 } 153 154 public enum InvertType 155 { 156 InvertColors, 157 Rotate180, 158 FlipHorizontal, 159 FlipVertical, 160 Rotate90CW, 161 Rotate90CCW, 162 FlipLayerHorizontal, 163 FlipLayerVertical 164 } 165 } 166