summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SpriteEd/AppDelegate.cs150
-rw-r--r--SpriteEd/Main.storyboard26
-rw-r--r--SpriteEd/SpriteSet.cs11
-rw-r--r--SpriteEd/SpriteSetController.cs4
4 files changed, 191 insertions, 0 deletions
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
{
}
+ /// <summary>
+ /// Called to see if the app should terminate.
+ /// </summary>
+ /// <param name="sender">The sending application.</param>
+ /// <returns></returns>
public override NSApplicationTerminateReply ApplicationShouldTerminate(NSApplication sender)
{
NSApplicationTerminateReply reply = NSApplicationTerminateReply.Cancel;
@@ -248,5 +253,150 @@ namespace SpriteEd
ViewController.Paste(m_copy);
}
}
+
+ /// <summary>
+ /// Is a sprite blank (all background colour).
+ /// </summary>
+ /// <param name="s">The sprite.</param>
+ /// <returns>True if the sprite is blank.</returns>
+ 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;
+ }
+
+ /// <summary>
+ /// Convert a mono sprite into a byte.
+ /// </summary>
+ /// <param name="s">The sprite.</param>
+ /// <param name="x">The starting X co-ord.</param>
+ /// <param name="y">The Y co-ord.</param>
+ /// <returns></returns>
+ 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;
+ }
+
+ /// <summary>
+ /// Handle export binary.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ [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);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Handle export assembly.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ [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);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Handle export C.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ [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 @@
</items>
</menu>
</menuItem>
+ <menuItem title="Export" state="on" id="2kv-cu-g83">
+ <attributedString key="attributedTitle"/>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Export" id="hai-ZQ-Tff">
+ <items>
+ <menuItem title="Binary File" id="3c1-gj-MYm">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="exportBinary:" target="Ady-hI-5gd" id="KCf-7a-hZF"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Assembly Source" id="PV4-8m-ZwG">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="exportAssembly:" target="Ady-hI-5gd" id="qHd-8n-sIZ"/>
+ </connections>
+ </menuItem>
+ <menuItem title="C Source" id="Z7k-rh-cTR">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="exportC:" target="Ady-hI-5gd" id="dEr-FT-PPK"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
<menuItem title="Window" id="aUF-d1-5bR">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
diff --git a/SpriteEd/SpriteSet.cs b/SpriteEd/SpriteSet.cs
index aa7fac3..2f2c570 100644
--- a/SpriteEd/SpriteSet.cs
+++ b/SpriteEd/SpriteSet.cs
@@ -102,6 +102,17 @@ namespace SpriteEd
public Dictionary<int, string> CodeSet {get; private set;}
/// <summary>
+ /// Get the size of the sprite set.
+ /// </summary>
+ public uint Size
+ {
+ get
+ {
+ return SET_SIZE;
+ }
+ }
+
+ /// <summary>
/// Construct a sprite set.
/// </summary>
/// <param name="type">The type of sprite set. This is just informational.</param>
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);
}