diff options
author | Ian C <ianc@noddybox.co.uk> | 2020-07-07 21:49:44 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2020-07-07 21:49:44 +0000 |
commit | febb3c2f720678e077b2d23316e1bfa7664861a3 (patch) | |
tree | 1f1503ec1ec56c2a7d0007f57aeb423416a7b24a | |
parent | 0e8e2b3ee188e7c1e54b8f9c6e8781ffdc501906 (diff) |
Added cut/copy/paste. Hopefully fixed up code to get current view controller.
-rw-r--r-- | SpriteEd/AppDelegate.cs | 71 | ||||
-rw-r--r-- | SpriteEd/NSSpriteEdit.cs | 5 | ||||
-rw-r--r-- | SpriteEd/ViewController.cs | 86 |
3 files changed, 152 insertions, 10 deletions
diff --git a/SpriteEd/AppDelegate.cs b/SpriteEd/AppDelegate.cs index 3756e70..c213a25 100644 --- a/SpriteEd/AppDelegate.cs +++ b/SpriteEd/AppDelegate.cs @@ -24,34 +24,46 @@ namespace SpriteEd [Register("AppDelegate")] public class AppDelegate : NSApplicationDelegate { + private Sprite m_copy; + + /// <summary> + /// Default constructor. + /// </summary> public AppDelegate() { } + /// <summary> + /// Initialise the application/ + /// </summary> + /// <param name="notification">The notification.</param> public override void DidFinishLaunching(NSNotification notification) { - // Insert code here to initialize your application } + /// <summary> + /// Tear-down the application. + /// </summary> + /// <param name="notification">The notification.</param> public override void WillTerminate(NSNotification notification) { - // Insert code here to tear down your application } + /// <summary> + /// Get the current view controller. + /// </summary> private ViewController ViewController { get { - NSWindowController controller = NSApplication.SharedApplication.KeyWindow.WindowController as NSWindowController; - return controller.ContentViewController as ViewController; + return NSApplication.SharedApplication.KeyWindow.ContentViewController as ViewController; } } - [Export("newDocument:")] - private void OnNewDocument(NSObject sender) - { - } - + /// <summary> + /// Handle Save Document As. + /// </summary> + /// <param name="sender">The event sender.</param> [Export("saveDocumentAs:")] private void OnSaveDocumentAs(NSObject sender) { @@ -80,6 +92,10 @@ namespace SpriteEd } } + /// <summary> + /// Handle Save Document. + /// </summary> + /// <param name="sender">The event sender.</param> [Export("saveDocument:")] private void OnSaveDocument(NSObject sender) { @@ -104,6 +120,10 @@ namespace SpriteEd } } + /// <summary> + /// Handle Open Document. + /// </summary> + /// <param name="sender">The event sender.</param> [Export("openDocument:")] private void OnOpenDocument(NSObject sender) { @@ -136,5 +156,38 @@ namespace SpriteEd } } } + + /// <summary> + /// Handle Cut. + /// </summary> + /// <param name="sender">The event sender.</param> + [Export("cut:")] + private void OnCut(NSObject sender) + { + m_copy = ViewController.CutOrCopy(true); + } + + /// <summary> + /// Handle Copy. + /// </summary> + /// <param name="sender">The event sender.</param> + [Export("copy:")] + private void OnCopy(NSObject sender) + { + m_copy = ViewController.CutOrCopy(false); + } + + /// <summary> + /// Handle Paste. + /// </summary> + /// <param name="sender">The event sender.</param> + [Export("paste:")] + private void OnPaste(NSObject sender) + { + if (m_copy != null) + { + ViewController.Paste(m_copy); + } + } } } diff --git a/SpriteEd/NSSpriteEdit.cs b/SpriteEd/NSSpriteEdit.cs index f5d5dc5..8d9a41f 100644 --- a/SpriteEd/NSSpriteEdit.cs +++ b/SpriteEd/NSSpriteEdit.cs @@ -99,6 +99,11 @@ namespace SpriteEd ClearUndo(); NeedsDisplay = true; } + + get + { + return m_sprite; + } } /// <summary> diff --git a/SpriteEd/ViewController.cs b/SpriteEd/ViewController.cs index 43fdc64..588f9d8 100644 --- a/SpriteEd/ViewController.cs +++ b/SpriteEd/ViewController.cs @@ -22,14 +22,22 @@ namespace SpriteEd { public partial class ViewController : NSViewController { + private static int m_Untitled = 1; + private SpriteSet m_SpriteSet; private NSUrl m_Url; - private static int m_Untitled = 1; + /// <summary> + /// Constructor. + /// </summary> + /// <param name="handle">The handle.</param> public ViewController(IntPtr handle) : base(handle) { } + /// <summary> + /// Called when view loaded. + /// </summary> public override void ViewDidLoad() { base.ViewDidLoad(); @@ -43,6 +51,9 @@ namespace SpriteEd SpriteSet = new SpriteSet(SpriteSet.SetType.C64CharacterSet, 8, 8, palette, false, false, CodePoints.C64); } + /// <summary> + /// Called when view appears on screen. I think. + /// </summary> public override void ViewDidAppear() { base.ViewDidAppear(); @@ -63,6 +74,9 @@ namespace SpriteEd } } + /// <summary> + /// Get/set the represented object. + /// </summary> public override NSObject RepresentedObject { get @@ -76,6 +90,9 @@ namespace SpriteEd } } + /// <summary> + /// Get/set the SpriteSet being edited. + /// </summary> public SpriteSet SpriteSet { get @@ -99,6 +116,9 @@ namespace SpriteEd } } + /// <summary> + /// Get/set the file URL associated with the sprite set. + /// </summary> public NSUrl Url { get @@ -114,8 +134,15 @@ namespace SpriteEd } } + /// <summary> + /// Whether the view is untitled. + /// </summary> public bool Untitled {get;set;} + /// <summary> + /// Called when the sprite stepper is pressed. + /// </summary> + /// <param name="sender">The event sender.</param> partial void OnSpriteStepper(NSObject sender) { NSStepper stepper = sender as NSStepper; @@ -136,6 +163,10 @@ namespace SpriteEd } } + /// <summary> + /// Called when the colour stepper is pressed. + /// </summary> + /// <param name="sender">The event sender.</param> partial void OnColourStepper(NSObject sender) { NSStepper stepper = sender as NSStepper; @@ -152,12 +183,20 @@ namespace SpriteEd } } + /// <summary> + /// Called when the colour well is interacted with. + /// </summary> + /// <param name="sender">The event sender.</param> partial void OnColourWell(NSObject sender) { m_SpriteSet.Palette[(uint)m_ColourStepper.IntValue] = Util.ColourNS(m_ColourWell.Color); m_SpriteEdit.NeedsDisplay = true; } + /// <summary> + /// Called when the drawing mode pop-up button is interacted with. + /// </summary> + /// <param name="sender">The event sender.</param> partial void OnDrawingMode(NSObject sender) { NSPopUpButton button = sender as NSPopUpButton; @@ -167,5 +206,50 @@ namespace SpriteEd m_SpriteEdit.Mode = (NSSpriteEdit.DrawingMode)(int)button.SelectedTag; } } + + /// <summary> + /// Called to perform a cut or copy operation on the sprite. + /// </summary> + /// <param name="cut">True if it's a cut.</param> + /// <returns>The sprite data.</returns> + public Sprite CutOrCopy(bool cut) + { + Sprite copy = new Sprite(m_SpriteEdit.Sprite); + + if (cut) + { + for(uint x = 0; x < m_SpriteEdit.Sprite.Width; x++) + { + for(uint y = 0; y < m_SpriteEdit.Sprite.Height; y++) + { + m_SpriteEdit.Sprite[x,y] = 0; + } + } + + m_SpriteEdit.NeedsDisplay = true; + } + + return copy; + } + + /// <summary> + /// Called to perform a paste operation on the sprite from the passed sprite. + /// </summary> + /// <param name="paste">The sprite to paste from.</param> + public void Paste(Sprite paste) + { + uint mw = Math.Min(paste.Width, m_SpriteEdit.Sprite.Width); + uint mh = Math.Min(paste.Height, m_SpriteEdit.Sprite.Height); + + for(uint x = 0; x < mw; x++) + { + for(uint y = 0; y < mh; y++) + { + m_SpriteEdit.Sprite[x,y] = paste[x,y]; + } + } + + m_SpriteEdit.NeedsDisplay = true; + } } } |