From fbc622959b22893237047b7dcb010ee6d2820010 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 5 Jul 2020 21:58:23 +0000 Subject: Added new, open and save. --- SpriteEd/AppDelegate.cs | 94 +++++++++++ SpriteEd/CodePoints.cs | 2 +- SpriteEd/Main.storyboard | 267 +++++++++++++++++++++++++++++-- SpriteEd/SpriteEd.csproj | 2 + SpriteEd/SpriteSet.cs | 80 ++++++++- SpriteEd/SpriteSetController.cs | 211 ++++++++++++++++++++++++ SpriteEd/SpriteSetController.designer.cs | 146 +++++++++++++++++ SpriteEd/Util.cs | 46 ++++++ SpriteEd/ViewController.cs | 84 ++++++---- SpriteEd/ViewController.designer.cs | 21 +-- 10 files changed, 899 insertions(+), 54 deletions(-) create mode 100644 SpriteEd/SpriteSetController.cs create mode 100644 SpriteEd/SpriteSetController.designer.cs diff --git a/SpriteEd/AppDelegate.cs b/SpriteEd/AppDelegate.cs index 9264787..eb40bd7 100644 --- a/SpriteEd/AppDelegate.cs +++ b/SpriteEd/AppDelegate.cs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // +using System; +using System.IO; using AppKit; using Foundation; @@ -35,5 +37,97 @@ namespace SpriteEd { // Insert code here to tear down your application } + + [Export("newDocument:")] + private void OnNewDocument(NSObject sender) + { + } + + [Export("saveDocumentAs:")] + private void OnSaveDocumentAs(NSObject sender) + { + NSWindowController controller = NSApplication.SharedApplication.KeyWindow.WindowController as NSWindowController; + ViewController view = controller.ContentViewController as ViewController; + + NSSavePanel fsel = new NSSavePanel(); + + fsel.Title = "Save Sprite Set"; + fsel.AllowedFileTypes = new string[] {"sprset"}; + fsel.ShowsTagField = false; + + if (fsel.RunModal() == 1) + { + view.Url = fsel.Url; + + try + { + FileStream stream = File.Create(view.Url.Path); + view.SpriteSet.Save(stream); + stream.Close(); + } + catch (Exception e) + { + Util.DisplayAlert("Error saving sprite set", e.Message); + } + } + } + + [Export("saveDocument:")] + private void OnSaveDocument(NSObject sender) + { + NSWindowController controller = NSApplication.SharedApplication.KeyWindow.WindowController as NSWindowController; + ViewController view = controller.ContentViewController as ViewController; + + if (view.Untitled) + { + OnSaveDocumentAs(sender); + } + else + { + try + { + FileStream stream = File.Create(view.Url.Path); + view.SpriteSet.Save(stream); + stream.Close(); + } + catch (Exception e) + { + Util.DisplayAlert("Error saving sprite set", e.Message); + } + } + } + + [Export("openDocument:")] + private void OnOpenDocument(NSObject sender) + { + NSOpenPanel fsel = new NSOpenPanel(); + + fsel.Title = "Open Sprite Set"; + fsel.AllowedFileTypes = new string[] {"sprset"}; + + if (fsel.RunModal() == 1) + { + try + { + FileStream stream = File.OpenRead(fsel.Url.Path); + SpriteSet set = SpriteSet.Load(stream); + stream.Close(); + + NSStoryboard storyboard = NSStoryboard.FromName("Main", null); + NSWindowController controller = storyboard.InstantiateInitialController() as NSWindowController; + + controller.ShowWindow(this); + + ViewController view = controller.ContentViewController as ViewController; + + view.SpriteSet = set; + view.Url = fsel.Url; + } + catch (Exception e) + { + Util.DisplayAlert("Error loading sprite set", e.Message); + } + } + } } } diff --git a/SpriteEd/CodePoints.cs b/SpriteEd/CodePoints.cs index 3bcef29..90620d9 100644 --- a/SpriteEd/CodePoints.cs +++ b/SpriteEd/CodePoints.cs @@ -154,7 +154,7 @@ namespace SpriteEd {29, "]"}, {30, "^"}, {31, "\\"}, - {32, " "}, + {32, "Space"}, {33, "!"}, {34, "\""}, {35, "#"}, diff --git a/SpriteEd/Main.storyboard b/SpriteEd/Main.storyboard index 096251c..23625aa 100644 --- a/SpriteEd/Main.storyboard +++ b/SpriteEd/Main.storyboard @@ -62,6 +62,7 @@ + @@ -206,6 +207,234 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -224,7 +453,7 @@ - + @@ -244,7 +473,7 @@ - + @@ -253,7 +482,7 @@ - + @@ -261,7 +490,7 @@ - + @@ -269,17 +498,8 @@ - - - - - - - - - - + @@ -314,6 +534,23 @@ + + + + + + + + + + + + + + + + + @@ -324,9 +561,9 @@ - + diff --git a/SpriteEd/SpriteEd.csproj b/SpriteEd/SpriteEd.csproj index 0e58c25..1fa7dc2 100644 --- a/SpriteEd/SpriteEd.csproj +++ b/SpriteEd/SpriteEd.csproj @@ -86,6 +86,8 @@ + + diff --git a/SpriteEd/SpriteSet.cs b/SpriteEd/SpriteSet.cs index cbc5c05..aa7fac3 100644 --- a/SpriteEd/SpriteSet.cs +++ b/SpriteEd/SpriteSet.cs @@ -15,6 +15,7 @@ // along with this program. If not, see . // using System; +using System.Collections.Generic; using System.IO; namespace SpriteEd @@ -24,11 +25,52 @@ namespace SpriteEd /// public class SpriteSet { + /// + /// The sprite set type. The default is Custom. + /// + public enum SetType + { + /// + /// A custom sprite set. + /// + Custom, + + /// + /// A generic 8x8 mono sprite set. + /// + Mono8x8, + + /// + /// A generic 16x16 mono sprite set. + /// + Mono16x16, + + /// + /// Commodore 64 character set. + /// + C64CharacterSet, + + /// + /// Commodore 64 mono sprites. + /// + C64MonoSprite, + + /// + /// Commodore 64 colour sprites. + /// + C64ColourSprite + } + private const uint SET_SIZE = 256; private const uint MAGIC = 0x5d75537d + SET_SIZE; private Sprite[] m_sprite; + /// + /// The type of sprite set. + /// + public SetType Type {get; private set;} + /// /// The palette associated with the sprite set. /// @@ -54,21 +96,35 @@ namespace SpriteEd /// public bool DoubleHeight {get; private set;} + /// + /// The code set (textual descriptions for sprite numbers). + /// + public Dictionary CodeSet {get; private set;} + /// /// Construct a sprite set. /// + /// The type of sprite set. This is just informational. /// The width of each sprite. /// The height of each sprite. /// The palette for the sprites. /// Whether the psrite has a double width pixel. /// Whether the sprite has a double height pixel. - public SpriteSet(uint width, uint height, Palette pal, bool double_width, bool double_height) + public SpriteSet(SetType type, + uint width, + uint height, + Palette pal, + bool double_width, + bool double_height, + Dictionary codeset) { + Type = type; Palette = pal; Width = width; Height = height; DoubleWidth = double_width; DoubleHeight = double_height; + CodeSet = codeset; m_sprite = new Sprite[SET_SIZE]; @@ -107,13 +163,24 @@ namespace SpriteEd throw new SpriteEdException("Not a sprite set file"); } + SetType type = (SetType)Util.ReadUint(s); Palette pal = Palette.Load(s); uint width = Util.ReadUint(s); uint height = Util.ReadUint(s); bool double_width = Util.ReadBool(s); bool double_height = Util.ReadBool(s); - sprset = new SpriteSet(width, height, pal, double_width, double_height); + Dictionary codeset = new Dictionary(); + uint count = Util.ReadUint(s); + + for(uint f = 0; f < count; f++) + { + int no = (int)Util.ReadUint(s); + string str = Util.ReadString(s); + codeset[no] = str; + } + + sprset = new SpriteSet(type, width, height, pal, double_width, double_height, codeset); for(uint f = 0; f < SET_SIZE; f++) { @@ -138,12 +205,21 @@ namespace SpriteEd { Util.WriteUint(s, MAGIC); + Util.WriteUint(s, (uint)Type); Palette.Save(s); Util.WriteUint(s, Width); Util.WriteUint(s, Height); Util.WriteBool(s, DoubleWidth); Util.WriteBool(s, DoubleHeight); + Util.WriteUint(s, (uint)CodeSet.Count); + + foreach (KeyValuePair f in CodeSet) + { + Util.WriteUint(s, (uint)f.Key); + Util.WriteString(s, f.Value); + } + for(uint f = 0; f < SET_SIZE; f++) { m_sprite[f].Save(s); diff --git a/SpriteEd/SpriteSetController.cs b/SpriteEd/SpriteSetController.cs new file mode 100644 index 0000000..3bf4ed9 --- /dev/null +++ b/SpriteEd/SpriteSetController.cs @@ -0,0 +1,211 @@ +// SpriteEd - Simple sprite editor +// Copyright 2020 Ian Cowburn +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +using System; +using System.Collections.Generic; +using AppKit; +using Foundation; + +namespace SpriteEd +{ + public partial class SpriteSetController : NSViewController + { + private Palette m_palette; + private SpriteSet.SetType m_type; + + public SpriteSetController(IntPtr handle) : base(handle) + { + } + + public override void ViewDidLoad() + { + base.ViewDidLoad(); + m_Width.IntValue = m_WidthStepper.IntValue; + m_Height.IntValue = m_HeightStepper.IntValue; + m_PaletteSize.IntValue = m_PaletteSizeStepper.IntValue; + m_palette = new Palette(2); + m_palette[0] = new Colour(); + m_palette[1] = new Colour(255, 255, 255); + m_PaletteStepper.MaxValue = m_palette.Size - 1; + OnPaletteStepper(m_PaletteStepper); + } + + public override NSObject RepresentedObject + { + get + { + return base.RepresentedObject; + } + set + { + base.RepresentedObject = value; + // Update the view, if already loaded. + } + } + + partial void OnOK(NSObject sender) + { + View.Window.Close(); + + NSStoryboard storyboard = NSStoryboard.FromName("Main", null); + NSWindowController controller = storyboard.InstantiateInitialController() as NSWindowController; + + controller.ShowWindow(this); + + ViewController view = controller.ContentViewController as ViewController; + + view.SpriteSet = new SpriteSet(m_type, + (uint)m_Width.IntValue, + (uint)m_Height.IntValue, + m_palette, + m_DoubleWidth.State == NSCellStateValue.On, + m_DoubleHeight.State == NSCellStateValue.On, + m_CodePoints.SelectedTag == 1 ? CodePoints.C64 : CodePoints.Ascii); + } + + partial void OnCancel(NSObject sender) + { + View.Window.Close(); + } + + private void SetSize(int width, int height) + { + m_WidthStepper.IntValue = width; + m_HeightStepper.IntValue = height; + OnWidthStepper(m_WidthStepper); + OnHeightStepper(m_WidthStepper); + } + + private void SetMonoPalette() + { + m_palette = new Palette(2); + m_palette[0] = new Colour(); + m_palette[1] = new Colour(255, 255, 255); + m_PaletteStepper.MaxValue = m_palette.Size - 1; + OnPaletteStepper(m_PaletteStepper); + } + + private void SetColourPalette() + { + m_palette = new Palette(4); + m_palette[0] = new Colour(); + m_palette[1] = new Colour(255, 0, 0); + m_palette[2] = new Colour(0, 0, 255); + m_palette[3] = new Colour(255, 255, 255); + m_PaletteStepper.MaxValue = m_palette.Size - 1; + OnPaletteStepper(m_PaletteStepper); + } + + partial void OnSetType(NSObject sender) + { + NSPopUpButton button = sender as NSPopUpButton; + + m_type = (SpriteSet.SetType)(int)button.SelectedTag; + + switch(m_type) + { + case SpriteSet.SetType.Custom: + break; + + case SpriteSet.SetType.Mono8x8: + SetSize(8,8); + SetMonoPalette(); + m_CodePoints.SelectItem(0); + m_DoubleWidth.State = NSCellStateValue.Off; + m_DoubleHeight.State = NSCellStateValue.Off; + break; + + case SpriteSet.SetType.Mono16x16: + SetSize(16, 16); + SetMonoPalette(); + m_CodePoints.SelectItem(0); + m_DoubleWidth.State = NSCellStateValue.Off; + m_DoubleHeight.State = NSCellStateValue.Off; + break; + + case SpriteSet.SetType.C64CharacterSet: + SetSize(8, 8); + SetMonoPalette(); + m_CodePoints.SelectItem(1); + m_DoubleWidth.State = NSCellStateValue.Off; + m_DoubleHeight.State = NSCellStateValue.Off; + break; + + case SpriteSet.SetType.C64MonoSprite: + SetSize(24, 21); + SetMonoPalette(); + m_CodePoints.SelectItem(1); + m_DoubleWidth.State = NSCellStateValue.Off; + m_DoubleHeight.State = NSCellStateValue.Off; + break; + + case SpriteSet.SetType.C64ColourSprite: + SetSize(12, 21); + SetColourPalette(); + m_CodePoints.SelectItem(1); + m_DoubleWidth.State = NSCellStateValue.On; + m_DoubleHeight.State = NSCellStateValue.Off; + break; + } + } + + partial void OnWidthStepper(NSObject sender) + { + m_Width.IntValue = m_WidthStepper.IntValue; + } + + partial void OnHeightStepper(NSObject sender) + { + m_Height.IntValue = m_HeightStepper.IntValue; + } + + partial void OnPaletteSizeStepper(NSObject sender) + { + m_PaletteSize.IntValue = m_PaletteSizeStepper.IntValue; + + Palette oldPalette = m_palette; + m_palette = new Palette((uint)m_PaletteSize.IntValue); + + for(uint f = 0; f < m_PaletteSize.IntValue; f++) + { + m_palette[f] = oldPalette[f]; + } + + if (m_palette.Size > oldPalette.Size) + { + m_palette[m_palette.Size - 1] = new Colour(255, 255, 255); + } + + m_PaletteStepper.MaxValue = m_palette.Size - 1; + OnPaletteStepper(m_PaletteStepper); + } + + partial void OnPaletteStepper(NSObject sender) + { + m_PaletteNumber.IntValue = m_PaletteStepper.IntValue; + + using (NSColor colour = Util.ColourNS(m_palette[(uint)m_PaletteNumber.IntValue])) + { + m_ColourWell.Color = colour; + } + } + + partial void OnColourWell(NSObject sender) + { + m_palette[(uint)m_PaletteNumber.IntValue] = Util.ColourNS(m_ColourWell.Color); + } + } +} diff --git a/SpriteEd/SpriteSetController.designer.cs b/SpriteEd/SpriteSetController.designer.cs new file mode 100644 index 0000000..3a541f0 --- /dev/null +++ b/SpriteEd/SpriteSetController.designer.cs @@ -0,0 +1,146 @@ +// WARNING +// +// This file has been generated automatically by Visual Studio to store outlets and +// actions made in the UI designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. +// +using Foundation; +using System.CodeDom.Compiler; + +namespace SpriteEd +{ + [Register ("SpriteSetController")] + partial class SpriteSetController + { + [Outlet] + AppKit.NSPopUpButton m_CodePoints { get; set; } + + [Outlet] + AppKit.NSColorWell m_ColourWell { get; set; } + + [Outlet] + AppKit.NSButton m_DoubleHeight { get; set; } + + [Outlet] + AppKit.NSButton m_DoubleWidth { get; set; } + + [Outlet] + AppKit.NSTextField m_Height { get; set; } + + [Outlet] + AppKit.NSStepper m_HeightStepper { get; set; } + + [Outlet] + AppKit.NSButton m_OKButton { get; set; } + + [Outlet] + AppKit.NSTextField m_PaletteNumber { get; set; } + + [Outlet] + AppKit.NSTextField m_PaletteSize { get; set; } + + [Outlet] + AppKit.NSStepper m_PaletteSizeStepper { get; set; } + + [Outlet] + AppKit.NSStepper m_PaletteStepper { get; set; } + + [Outlet] + AppKit.NSTextField m_Width { get; set; } + + [Outlet] + AppKit.NSStepper m_WidthStepper { get; set; } + + [Action ("OnCancel:")] + partial void OnCancel (Foundation.NSObject sender); + + [Action ("OnColourWell:")] + partial void OnColourWell (Foundation.NSObject sender); + + [Action ("OnHeightStepper:")] + partial void OnHeightStepper (Foundation.NSObject sender); + + [Action ("OnOK:")] + partial void OnOK (Foundation.NSObject sender); + + [Action ("OnPaletteSizeStepper:")] + partial void OnPaletteSizeStepper (Foundation.NSObject sender); + + [Action ("OnPaletteStepper:")] + partial void OnPaletteStepper (Foundation.NSObject sender); + + [Action ("OnSetType:")] + partial void OnSetType (Foundation.NSObject sender); + + [Action ("OnWidthStepper:")] + partial void OnWidthStepper (Foundation.NSObject sender); + + void ReleaseDesignerOutlets () + { + if (m_CodePoints != null) { + m_CodePoints.Dispose (); + m_CodePoints = null; + } + + if (m_ColourWell != null) { + m_ColourWell.Dispose (); + m_ColourWell = null; + } + + if (m_DoubleHeight != null) { + m_DoubleHeight.Dispose (); + m_DoubleHeight = null; + } + + if (m_DoubleWidth != null) { + m_DoubleWidth.Dispose (); + m_DoubleWidth = null; + } + + if (m_Height != null) { + m_Height.Dispose (); + m_Height = null; + } + + if (m_HeightStepper != null) { + m_HeightStepper.Dispose (); + m_HeightStepper = null; + } + + if (m_OKButton != null) { + m_OKButton.Dispose (); + m_OKButton = null; + } + + if (m_PaletteNumber != null) { + m_PaletteNumber.Dispose (); + m_PaletteNumber = null; + } + + if (m_PaletteSize != null) { + m_PaletteSize.Dispose (); + m_PaletteSize = null; + } + + if (m_PaletteSizeStepper != null) { + m_PaletteSizeStepper.Dispose (); + m_PaletteSizeStepper = null; + } + + if (m_PaletteStepper != null) { + m_PaletteStepper.Dispose (); + m_PaletteStepper = null; + } + + if (m_Width != null) { + m_Width.Dispose (); + m_Width = null; + } + + if (m_WidthStepper != null) { + m_WidthStepper.Dispose (); + m_WidthStepper = null; + } + } + } +} diff --git a/SpriteEd/Util.cs b/SpriteEd/Util.cs index dff6e3e..23fdc43 100644 --- a/SpriteEd/Util.cs +++ b/SpriteEd/Util.cs @@ -16,8 +16,10 @@ // using System; using System.IO; +using System.Text; using AppKit; using CoreGraphics; +using CoreImage; namespace SpriteEd { @@ -79,6 +81,33 @@ namespace SpriteEd return s.ReadByte() == 255; } + /// + /// Write a string to a stream. + /// + /// The stream. + /// The string. + public static void WriteString(Stream s, string str) + { + byte[] b=Encoding.UTF8.GetBytes(str); + + WriteUint(s, (uint)b.Length); + s.Write(b,0,b.Length); + } + + /// + /// Read a string from a stream. + /// + /// The stream. + /// The string. + public static string ReadString(Stream s) + { + uint len = ReadUint(s); + byte[] b = new byte[len]; + + s.Read(b, 0, b.Length); + + return Encoding.UTF8.GetString(b); + } /// /// Display an error alert. /// @@ -106,6 +135,23 @@ namespace SpriteEd return NSColor.FromDeviceRgb(c.Red, c.Green, c.Blue); } + /// + /// Convert an NSColor into a Colour. + /// + /// The colour. + /// + public static Colour ColourNS(NSColor c) + { + CIColor col = new CIColor(c); + + return new Colour + ( + (byte)(col.Red * 255.0f), + (byte)(col.Green * 255.0f), + (byte)(col.Blue * 255.0f) + ); + } + /// /// Convert a Colour into a CGColor. /// diff --git a/SpriteEd/ViewController.cs b/SpriteEd/ViewController.cs index 7abceff..12a503f 100644 --- a/SpriteEd/ViewController.cs +++ b/SpriteEd/ViewController.cs @@ -15,7 +15,6 @@ // along with this program. If not, see . // using System; -using System.Collections.Generic; using AppKit; using Foundation; @@ -23,9 +22,8 @@ namespace SpriteEd { public partial class ViewController : NSViewController { - private Palette m_Palette; private SpriteSet m_SpriteSet; - private Dictionary m_CodeSet; + private NSUrl m_Url; public ViewController(IntPtr handle) : base(handle) { @@ -35,28 +33,14 @@ namespace SpriteEd { base.ViewDidLoad(); - m_SpriteStepper.IntValue = 0; + Palette palette = new Palette(2); + palette[0] = new Colour(0, 0, 0); + palette[1] = new Colour(255, 255, 255); - m_Palette = new Palette(2); - m_Palette[0] = new Colour(0, 0, 0); - m_Palette[1] = new Colour(255, 255, 255); + Title = "Untitled"; + Untitled = true; - m_ColourStepper.IntValue = 1; - - m_ColourStepper.MaxValue = m_Palette.Size - 1; - - m_SpriteSet = new SpriteSet(8, 8, m_Palette, false, false); - - m_SpriteEdit.Palette = m_Palette; - m_SpriteEdit.DoubleWidth = m_SpriteSet.DoubleWidth; - m_SpriteEdit.DoubleHeight = m_SpriteSet.DoubleHeight; - m_SpriteEdit.Sprite = m_SpriteSet[(byte)m_SpriteNumber.IntValue]; - m_SpriteEdit.Mode = NSSpriteEdit.DrawingMode.Point; - - m_CodeSet = CodePoints.C64; - - OnColourStepper(m_ColourStepper); - OnSpriteStepper(m_SpriteStepper); + SpriteSet = new SpriteSet(SpriteSet.SetType.C64CharacterSet, 8, 8, palette, false, false, CodePoints.C64); } public override NSObject RepresentedObject @@ -72,6 +56,46 @@ namespace SpriteEd } } + public SpriteSet SpriteSet + { + get + { + return m_SpriteSet; + } + + set + { + m_SpriteSet = value; + m_ColourStepper.IntValue = 1; + m_SpriteStepper.IntValue = 0; + m_ColourStepper.MaxValue = m_SpriteSet.Palette.Size - 1; + m_SpriteEdit.Palette = m_SpriteSet.Palette; + m_SpriteEdit.DoubleWidth = m_SpriteSet.DoubleWidth; + m_SpriteEdit.DoubleHeight = m_SpriteSet.DoubleHeight; + m_SpriteEdit.Sprite = m_SpriteSet[(byte)m_SpriteNumber.IntValue]; + m_SpriteEdit.Mode = NSSpriteEdit.DrawingMode.Point; + OnSpriteStepper(m_SpriteStepper); + OnColourStepper(m_ColourStepper); + } + } + + public NSUrl Url + { + get + { + return m_Url; + } + + set + { + m_Url = value; + View.Window.Title = m_Url.Path; + Untitled = false; + } + } + + public bool Untitled {get;set;} + partial void OnSpriteStepper(NSObject sender) { NSStepper stepper = sender as NSStepper; @@ -81,9 +105,9 @@ namespace SpriteEd m_SpriteNumber.IntValue = stepper.IntValue; m_SpriteEdit.Sprite = m_SpriteSet[(byte)stepper.IntValue]; - if (m_CodeSet.ContainsKey(stepper.IntValue)) + if (m_SpriteSet.CodeSet.ContainsKey(stepper.IntValue)) { - m_CodeLabel.StringValue = m_CodeSet[stepper.IntValue]; + m_CodeLabel.StringValue = m_SpriteSet.CodeSet[stepper.IntValue]; } else { @@ -101,13 +125,19 @@ namespace SpriteEd m_ColourNumber.IntValue = stepper.IntValue; m_SpriteEdit.Colour = (uint)stepper.IntValue; - using (NSColor c = Util.ColourNS(m_Palette[(uint)stepper.IntValue])) + using (NSColor c = Util.ColourNS(m_SpriteSet.Palette[(uint)stepper.IntValue])) { - m_ColourLabel.TextColor = c; + m_ColourWell.Color = c; } } } + partial void OnColourWell(NSObject sender) + { + m_SpriteSet.Palette[(uint)m_ColourStepper.IntValue] = Util.ColourNS(m_ColourWell.Color); + m_SpriteEdit.NeedsDisplay = true; + } + partial void OnDrawingMode(NSObject sender) { NSPopUpButton button = sender as NSPopUpButton; diff --git a/SpriteEd/ViewController.designer.cs b/SpriteEd/ViewController.designer.cs index 032ae7f..9116f3d 100644 --- a/SpriteEd/ViewController.designer.cs +++ b/SpriteEd/ViewController.designer.cs @@ -15,15 +15,15 @@ namespace SpriteEd [Outlet] AppKit.NSTextField m_CodeLabel { get; set; } - [Outlet] - AppKit.NSTextField m_ColourLabel { get; set; } - [Outlet] AppKit.NSTextField m_ColourNumber { get; set; } [Outlet] AppKit.NSStepper m_ColourStepper { get; set; } + [Outlet] + AppKit.NSColorWell m_ColourWell { get; set; } + [Outlet] SpriteEd.NSSpriteEdit m_SpriteEdit { get; set; } @@ -36,6 +36,9 @@ namespace SpriteEd [Action ("OnColourStepper:")] partial void OnColourStepper (Foundation.NSObject sender); + [Action ("OnColourWell:")] + partial void OnColourWell (Foundation.NSObject sender); + [Action ("OnDrawingMode:")] partial void OnDrawingMode (Foundation.NSObject sender); @@ -44,9 +47,9 @@ namespace SpriteEd void ReleaseDesignerOutlets () { - if (m_ColourLabel != null) { - m_ColourLabel.Dispose (); - m_ColourLabel = null; + if (m_CodeLabel != null) { + m_CodeLabel.Dispose (); + m_CodeLabel = null; } if (m_ColourNumber != null) { @@ -74,9 +77,9 @@ namespace SpriteEd m_SpriteStepper = null; } - if (m_CodeLabel != null) { - m_CodeLabel.Dispose (); - m_CodeLabel = null; + if (m_ColourWell != null) { + m_ColourWell.Dispose (); + m_ColourWell = null; } } } -- cgit v1.2.3