1 // 2 // PaletteManager.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 Gtk; 29 using Cairo; 30 31 namespace Pinta.Core 32 { 33 public class PaletteManager 34 { 35 private Color primary; 36 private Color secondary; 37 private Palette palette; 38 39 public Color PrimaryColor { 40 get { return primary; } 41 set { 42 if (!primary.Equals (value)) { 43 primary = value; 44 OnPrimaryColorChanged (); 45 } 46 } 47 } 48 49 public Color SecondaryColor { 50 get { return secondary; } 51 set { 52 if (!secondary.Equals (value)) { 53 secondary = value; 54 OnSecondaryColorChanged (); 55 } 56 } 57 } 58 59 public Palette CurrentPalette { 60 get { 61 if (palette == null) { 62 palette = Palette.GetDefault (); 63 } 64 65 return palette; 66 } 67 } 68 PaletteManager()69 public PaletteManager () 70 { 71 PrimaryColor = new Color (0, 0, 0); 72 SecondaryColor = new Color (1, 1, 1); 73 } 74 DoKeyPress(object o, KeyPressEventArgs e)75 public void DoKeyPress (object o, KeyPressEventArgs e) 76 { 77 if (e.Event.State.FilterModifierKeys() == Gdk.ModifierType.None && e.Event.Key.ToUpper() == Gdk.Key.X) { 78 Color temp = PintaCore.Palette.PrimaryColor; 79 PintaCore.Palette.PrimaryColor = PintaCore.Palette.SecondaryColor; 80 PintaCore.Palette.SecondaryColor = temp; 81 82 e.RetVal = true; 83 } 84 } 85 86 #region Protected Methods OnPrimaryColorChanged()87 protected void OnPrimaryColorChanged () 88 { 89 if (PrimaryColorChanged != null) 90 PrimaryColorChanged.Invoke (this, EventArgs.Empty); 91 } 92 OnSecondaryColorChanged()93 protected void OnSecondaryColorChanged () 94 { 95 if (SecondaryColorChanged != null) 96 SecondaryColorChanged.Invoke (this, EventArgs.Empty); 97 } 98 #endregion 99 100 #region Events 101 public event EventHandler PrimaryColorChanged; 102 public event EventHandler SecondaryColorChanged; 103 #endregion 104 } 105 } 106