From 1134a1e8e926033d426e480fc99e34d4b4d92a41 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 14 Jul 2020 13:24:53 +0000 Subject: Fixed palette size on New form when using mutli-coloured sprites. --- SpriteEd/AppDelegate.cs | 150 ++++++++++++++++++++++++++++++++++++++++ SpriteEd/Main.storyboard | 26 +++++++ SpriteEd/SpriteSet.cs | 11 +++ SpriteEd/SpriteSetController.cs | 4 ++ 4 files changed, 191 insertions(+) diff --git a/SpriteEd/AppDelegate.cs b/SpriteEd/AppDelegate.cs index 073bfc9..3e51178 100644 --- a/SpriteEd/AppDelegate.cs +++ b/SpriteEd/AppDelegate.cs @@ -49,6 +49,11 @@ namespace SpriteEd { } + /// + /// Called to see if the app should terminate. + /// + /// The sending application. + /// public override NSApplicationTerminateReply ApplicationShouldTerminate(NSApplication sender) { NSApplicationTerminateReply reply = NSApplicationTerminateReply.Cancel; @@ -248,5 +253,150 @@ namespace SpriteEd ViewController.Paste(m_copy); } } + + /// + /// Is a sprite blank (all background colour). + /// + /// The sprite. + /// True if the sprite is blank. + private bool IsSpriteBlank(Sprite s) + { + for(uint x = 0; x < s.Width; x++) + { + for(uint y = 0; y < s.Height; y++) + { + if (s[x, y] != 0) + { + return false; + } + } + } + + return true; + } + + /// + /// Convert a mono sprite into a byte. + /// + /// The sprite. + /// The starting X co-ord. + /// The Y co-ord. + /// + private uint SpriteData(Sprite s, uint x, uint y) + { + uint b = 0; + uint bit = 128; + + for(uint sx = 0; sx < 8; sx++) + { + if (s[x + sx, y] == 1) + { + b |= bit; + } + + bit = bit >> 1; + } + + return b; + } + + /// + /// Handle export binary. + /// + /// The event sender. + [Export("exportBinary:")] + private void ExportBinary(NSObject sender) + { + NSSavePanel fsel = new NSSavePanel(); + ViewController view = ViewController; + bool export_blank = false; + bool export_mono = false; + + fsel.Title = "Export binary"; + fsel.ShowsTagField = false; + + if (fsel.RunModal() == 1) + { + try + { + export_blank = view.SpriteSet.Type == SpriteSet.SetType.C64CharacterSet; + export_mono = view.SpriteSet.Palette.Size == 2; + + FileStream stream = File.Create(fsel.Url.Path); + + if (export_mono) + { + for(byte f = 0; f < view.SpriteSet.Size; f++) + { + if (export_blank || !IsSpriteBlank(view.SpriteSet[f])) + { + } + } + } + + stream.Close(); + } + catch (Exception e) + { + Util.DisplayAlert("Error exporting sprite set", e.Message); + } + } + } + + /// + /// Handle export assembly. + /// + /// The event sender. + [Export("exportAssembly:")] + private void ExportAssembly(NSObject sender) + { + NSSavePanel fsel = new NSSavePanel(); + ViewController view = ViewController; + + fsel.Title = "Export assembly"; + fsel.AllowedFileTypes = new string[] {"asm"}; + fsel.ShowsTagField = false; + + if (fsel.RunModal() == 1) + { + try + { + FileStream stream = File.Create(fsel.Url.Path); + stream.Close(); + } + catch (Exception e) + { + Util.DisplayAlert("Error exporting sprite set", e.Message); + } + } + } + + /// + /// Handle export C. + /// + /// The event sender. + [Export("exportC:")] + private void ExportC(NSObject sender) + { + NSSavePanel fsel = new NSSavePanel(); + ViewController view = ViewController; + + fsel.Title = "Export C"; + fsel.AllowedFileTypes = new string[] {"c"}; + fsel.ShowsTagField = false; + + if (fsel.RunModal() == 1) + { + try + { + FileStream stream = File.Create(fsel.Url.Path); + stream.Close(); + } + catch (Exception e) + { + Util.DisplayAlert("Error exporting sprite set", e.Message); + } + } + } } } diff --git a/SpriteEd/Main.storyboard b/SpriteEd/Main.storyboard index 23625aa..e67a0aa 100644 --- a/SpriteEd/Main.storyboard +++ b/SpriteEd/Main.storyboard @@ -135,6 +135,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SpriteEd/SpriteSet.cs b/SpriteEd/SpriteSet.cs index aa7fac3..2f2c570 100644 --- a/SpriteEd/SpriteSet.cs +++ b/SpriteEd/SpriteSet.cs @@ -101,6 +101,17 @@ namespace SpriteEd /// public Dictionary CodeSet {get; private set;} + /// + /// Get the size of the sprite set. + /// + public uint Size + { + get + { + return SET_SIZE; + } + } + /// /// Construct a sprite set. /// diff --git a/SpriteEd/SpriteSetController.cs b/SpriteEd/SpriteSetController.cs index 3bf4ed9..f8fed80 100644 --- a/SpriteEd/SpriteSetController.cs +++ b/SpriteEd/SpriteSetController.cs @@ -94,6 +94,8 @@ namespace SpriteEd m_palette = new Palette(2); m_palette[0] = new Colour(); m_palette[1] = new Colour(255, 255, 255); + m_PaletteSize.IntValue = (int)m_palette.Size; + m_PaletteSizeStepper.IntValue = m_PaletteSize.IntValue; m_PaletteStepper.MaxValue = m_palette.Size - 1; OnPaletteStepper(m_PaletteStepper); } @@ -105,6 +107,8 @@ namespace SpriteEd 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_PaletteSize.IntValue = (int)m_palette.Size; + m_PaletteSizeStepper.IntValue = m_PaletteSize.IntValue; m_PaletteStepper.MaxValue = m_palette.Size - 1; OnPaletteStepper(m_PaletteStepper); } -- cgit v1.2.3