summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SpriteEd/AppDelegate.cs94
-rw-r--r--SpriteEd/CodePoints.cs2
-rw-r--r--SpriteEd/Main.storyboard267
-rw-r--r--SpriteEd/SpriteEd.csproj2
-rw-r--r--SpriteEd/SpriteSet.cs80
-rw-r--r--SpriteEd/SpriteSetController.cs211
-rw-r--r--SpriteEd/SpriteSetController.designer.cs146
-rw-r--r--SpriteEd/Util.cs46
-rw-r--r--SpriteEd/ViewController.cs84
-rw-r--r--SpriteEd/ViewController.designer.cs21
10 files changed, 899 insertions, 54 deletions
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 <http://www.gnu.org/licenses/>.
//
+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 @@
<menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
<connections>
<action selector="newDocument:" target="Ady-hI-5gd" id="4Si-XN-c54"/>
+ <segue destination="Drs-be-wgu" kind="modal" id="Yb8-Xl-2Xg"/>
</connections>
</menuItem>
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
@@ -206,6 +207,234 @@
</objects>
<point key="canvasLocation" x="75" y="250"/>
</scene>
+ <!--Sprite Set Controller-->
+ <scene sceneID="hra-Sh-xqL">
+ <objects>
+ <viewController storyboardIdentifier="SpriteSetDialog" id="Drs-be-wgu" customClass="SpriteSetController" sceneMemberID="viewController">
+ <view key="view" id="KET-CI-J02">
+ <rect key="frame" x="0.0" y="0.0" width="450" height="260"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <subviews>
+ <popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VT8-FL-1XV">
+ <rect key="frame" x="18" y="216" width="404" height="25"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <popUpButtonCell key="cell" type="push" title="Custom" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="BFK-dy-bO3" id="j38-ZK-6QK">
+ <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
+ <font key="font" metaFont="system"/>
+ <menu key="menu" id="bmm-FC-wcl">
+ <items>
+ <menuItem title="Custom" state="on" id="BFK-dy-bO3"/>
+ <menuItem title="Generic 8x8 Mono Sprites" tag="1" id="bZ0-P4-xqg"/>
+ <menuItem title="Generic 16x16 Mono Sprites" tag="2" id="0eU-9R-tWF">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ </menuItem>
+ <menuItem title="C64 Character Set" tag="3" id="UT1-B7-U4B">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ </menuItem>
+ <menuItem title="C64 Mono Sprites" tag="4" id="D8Z-nP-2YD"/>
+ <menuItem title="C64 Colour Sprites" tag="5" id="lDX-nh-hex">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ </menuItem>
+ </items>
+ </menu>
+ <connections>
+ <action selector="OnSetType:" target="Drs-be-wgu" id="lgU-oV-aUH"/>
+ </connections>
+ </popUpButtonCell>
+ </popUpButton>
+ <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GUU-WS-YNR">
+ <rect key="frame" x="366" y="13" width="59" height="32"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="f8Q-Tr-LnY">
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+ <font key="font" metaFont="system"/>
+ <string key="keyEquivalent" base64-UTF8="YES">
+DQ
+</string>
+ </buttonCell>
+ <connections>
+ <action selector="OnOK:" target="Drs-be-wgu" id="URa-Tt-1tI"/>
+ </connections>
+ </button>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="yfY-2H-ACw">
+ <rect key="frame" x="18" y="195" width="40" height="16"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" lineBreakMode="clipping" title="Width" id="2nA-Hc-h9Y">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jjz-mG-zhc">
+ <rect key="frame" x="62" y="192" width="55" height="21"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="jBI-8r-4wu">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="SXa-JU-ImF">
+ <rect key="frame" x="202" y="192" width="55" height="21"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="yGr-DB-MhE">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4nC-qy-pwB">
+ <rect key="frame" x="18" y="168" width="143" height="18"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <buttonCell key="cell" type="check" title="Double Width Pixels" bezelStyle="regularSquare" imagePosition="left" inset="2" id="bWr-WT-Gab">
+ <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+ <font key="font" metaFont="system"/>
+ </buttonCell>
+ </button>
+ <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zfb-J2-N6L">
+ <rect key="frame" x="175" y="168" width="148" height="18"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <buttonCell key="cell" type="check" title="Double Height Pixels" bezelStyle="regularSquare" imagePosition="left" inset="2" id="F4A-WC-dEt">
+ <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+ <font key="font" metaFont="system"/>
+ </buttonCell>
+ </button>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hcn-Ph-Fz7">
+ <rect key="frame" x="18" y="146" width="76" height="16"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" lineBreakMode="clipping" title="Palette Size" id="iJN-6H-xbR">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Zfk-QG-gyF">
+ <rect key="frame" x="100" y="143" width="55" height="21"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="kJF-32-OWQ">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jiv-da-XAB">
+ <rect key="frame" x="17" y="113" width="19" height="28"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <stepperCell key="cell" continuous="YES" alignment="left" maxValue="100" id="bgk-cI-YTi"/>
+ <connections>
+ <action selector="OnPaletteStepper:" target="Drs-be-wgu" id="3cG-hq-RkY"/>
+ </connections>
+ </stepper>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zll-pz-rRz">
+ <rect key="frame" x="41" y="119" width="55" height="16"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" lineBreakMode="clipping" title="0" id="Bhr-cK-4GW">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <colorWell fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="CH6-Wc-BcY">
+ <rect key="frame" x="20" y="88" width="44" height="23"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+ <connections>
+ <action selector="OnColourWell:" target="Drs-be-wgu" id="K7Q-rV-VBT"/>
+ </connections>
+ </colorWell>
+ <popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="TE2-Sp-dFf">
+ <rect key="frame" x="102" y="58" width="320" height="25"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <popUpButtonCell key="cell" type="push" title="ASCII" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="2dw-5F-xEF" id="tWh-VJ-cRh">
+ <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
+ <font key="font" metaFont="system"/>
+ <menu key="menu" id="sFa-r6-HXd">
+ <items>
+ <menuItem title="ASCII" state="on" id="2dw-5F-xEF"/>
+ <menuItem title="C64 Screen Codes" tag="1" id="ByE-kR-m8c"/>
+ </items>
+ </menu>
+ </popUpButtonCell>
+ </popUpButton>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NeE-5s-Xez">
+ <rect key="frame" x="20" y="64" width="78" height="16"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" lineBreakMode="clipping" title="Code Points" id="Y6l-oZ-5xy">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Pvs-TF-V9o">
+ <rect key="frame" x="284" y="13" width="82" height="32"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="aRs-qH-Jtl">
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+ <font key="font" metaFont="system"/>
+ <string key="keyEquivalent" base64-UTF8="YES">
+Gw
+</string>
+ <connections>
+ <action selector="OnCancel:" target="Drs-be-wgu" id="7Ke-rK-PA6"/>
+ </connections>
+ </buttonCell>
+ </button>
+ <stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="w2C-jY-Ad9">
+ <rect key="frame" x="122" y="188" width="19" height="28"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <stepperCell key="cell" continuous="YES" alignment="left" minValue="1" maxValue="64" doubleValue="8" id="3NZ-rB-dBf"/>
+ <connections>
+ <action selector="OnWidthStepper:" target="Drs-be-wgu" id="zTK-Wg-sxQ"/>
+ </connections>
+ </stepper>
+ <stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="nUG-p1-6V6">
+ <rect key="frame" x="262" y="188" width="19" height="28"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <stepperCell key="cell" continuous="YES" alignment="left" minValue="1" maxValue="64" doubleValue="8" id="kbT-Dw-Kvv"/>
+ <connections>
+ <action selector="OnHeightStepper:" target="Drs-be-wgu" id="6xw-Jo-8pI"/>
+ </connections>
+ </stepper>
+ <stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="T6r-Pg-z3D">
+ <rect key="frame" x="160" y="139" width="19" height="28"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <stepperCell key="cell" continuous="YES" alignment="left" minValue="2" maxValue="256" doubleValue="2" id="EGB-FJ-uRC"/>
+ <connections>
+ <action selector="OnPaletteSizeStepper:" target="Drs-be-wgu" id="uMI-aQ-GKi"/>
+ </connections>
+ </stepper>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="TpZ-2l-0iA">
+ <rect key="frame" x="151" y="194" width="45" height="16"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" lineBreakMode="clipping" title="Height" id="S7k-U8-fhY">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ </subviews>
+ </view>
+ <connections>
+ <outlet property="OnSetType" destination="j38-ZK-6QK" id="q8X-hY-aZD"/>
+ <outlet property="m_CodePoints" destination="TE2-Sp-dFf" id="1Te-rp-XuY"/>
+ <outlet property="m_ColourWell" destination="CH6-Wc-BcY" id="SZW-m2-o7G"/>
+ <outlet property="m_DoubleHeight" destination="zfb-J2-N6L" id="lfV-p5-sOk"/>
+ <outlet property="m_DoubleWidth" destination="4nC-qy-pwB" id="MLS-fU-RfO"/>
+ <outlet property="m_Height" destination="SXa-JU-ImF" id="b36-b0-HUI"/>
+ <outlet property="m_HeightStepper" destination="nUG-p1-6V6" id="bvt-jD-1fR"/>
+ <outlet property="m_OKButton" destination="GUU-WS-YNR" id="l4K-MC-XL7"/>
+ <outlet property="m_PaletteNumber" destination="zll-pz-rRz" id="TTG-Wt-Fpj"/>
+ <outlet property="m_PaletteSize" destination="Zfk-QG-gyF" id="btM-HG-XiM"/>
+ <outlet property="m_PaletteSizeStepper" destination="T6r-Pg-z3D" id="L2U-pE-SGZ"/>
+ <outlet property="m_PaletteStepper" destination="Jiv-da-XAB" id="d0e-4U-vXS"/>
+ <outlet property="m_Width" destination="jjz-mG-zhc" id="cqV-xc-spz"/>
+ <outlet property="m_WidthStepper" destination="w2C-jY-Ad9" id="8Px-ke-G6L"/>
+ </connections>
+ </viewController>
+ <customObject id="pSF-6s-Sz5" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="983" y="332"/>
+ </scene>
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
@@ -224,7 +453,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OOh-QE-F3j">
- <rect key="frame" x="88" y="561" width="315" height="16"/>
+ <rect key="frame" x="88" y="561" width="279" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Code description" id="kKb-aN-vLt">
<font key="font" metaFont="system"/>
@@ -244,7 +473,7 @@
</connections>
</stepper>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iXZ-D0-tCL">
- <rect key="frame" x="707" y="559" width="41" height="21"/>
+ <rect key="frame" x="666" y="559" width="41" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="uD4-8J-1jJ">
<font key="font" metaFont="system"/>
@@ -253,7 +482,7 @@
</textFieldCell>
</textField>
<stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FGJ-Vk-aSZ">
- <rect key="frame" x="753" y="555" width="19" height="28"/>
+ <rect key="frame" x="712" y="555" width="19" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<stepperCell key="cell" continuous="YES" alignment="left" maxValue="100" id="6Ed-My-HbU"/>
<connections>
@@ -261,7 +490,7 @@
</connections>
</stepper>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7k9-2M-yvh">
- <rect key="frame" x="656" y="561" width="45" height="16"/>
+ <rect key="frame" x="615" y="561" width="45" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Colour" id="ai2-Hw-vQI">
<font key="font" metaFont="system"/>
@@ -269,17 +498,8 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
- <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="n1P-N7-3af">
- <rect key="frame" x="412" y="562" width="92" height="16"/>
- <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
- <textFieldCell key="cell" lineBreakMode="clipping" title="Drawing Mode" id="uxJ-en-Zkt">
- <font key="font" metaFont="system"/>
- <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
- <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
- </textFieldCell>
- </textField>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hCT-dA-Ray">
- <rect key="frame" x="508" y="556" width="145" height="25"/>
+ <rect key="frame" x="467" y="556" width="145" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Point" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="4oB-U5-ere" id="yQ6-sF-FRH">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
@@ -314,6 +534,23 @@
<action selector="OnDrawingMode:" target="XfG-lQ-9wD" id="OSG-SN-lRu"/>
</connections>
</popUpButton>
+ <colorWell fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2y9-oi-Ene">
+ <rect key="frame" x="736" y="558" width="44" height="23"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+ <connections>
+ <action selector="OnColourWell:" target="XfG-lQ-9wD" id="dOV-Y1-ddf"/>
+ </connections>
+ </colorWell>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="n1P-N7-3af">
+ <rect key="frame" x="371" y="562" width="92" height="16"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" lineBreakMode="clipping" title="Drawing Mode" id="uxJ-en-Zkt">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="lP9-z2-hEq" secondAttribute="trailing" constant="20" id="CVb-3j-Tmy"/>
@@ -324,9 +561,9 @@
</view>
<connections>
<outlet property="m_CodeLabel" destination="OOh-QE-F3j" id="lDS-Pw-WU2"/>
- <outlet property="m_ColourLabel" destination="7k9-2M-yvh" id="8AR-Od-bNf"/>
<outlet property="m_ColourNumber" destination="iXZ-D0-tCL" id="WmO-5c-JnK"/>
<outlet property="m_ColourStepper" destination="FGJ-Vk-aSZ" id="tD6-1U-5C7"/>
+ <outlet property="m_ColourWell" destination="2y9-oi-Ene" id="dEq-Vy-kVZ"/>
<outlet property="m_SpriteEdit" destination="lP9-z2-hEq" id="mYk-Ot-hkR"/>
<outlet property="m_SpriteNumber" destination="Vru-p3-CZW" id="0e9-Xv-W5Q"/>
<outlet property="m_SpriteStepper" destination="6aS-x3-0ku" id="Kfe-FD-nLY"/>
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 @@
<Compile Include="SpriteSet.cs" />
<Compile Include="SpriteEdException.cs" />
<Compile Include="CodePoints.cs" />
+ <Compile Include="SpriteSetController.cs" />
+ <Compile Include="SpriteSetController.designer.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Main.storyboard" />
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 <http://www.gnu.org/licenses/>.
//
using System;
+using System.Collections.Generic;
using System.IO;
namespace SpriteEd
@@ -24,12 +25,53 @@ namespace SpriteEd
/// </summary>
public class SpriteSet
{
+ /// <summary>
+ /// The sprite set type. The default is Custom.
+ /// </summary>
+ public enum SetType
+ {
+ /// <summary>
+ /// A custom sprite set.
+ /// </summary>
+ Custom,
+
+ /// <summary>
+ /// A generic 8x8 mono sprite set.
+ /// </summary>
+ Mono8x8,
+
+ /// <summary>
+ /// A generic 16x16 mono sprite set.
+ /// </summary>
+ Mono16x16,
+
+ /// <summary>
+ /// Commodore 64 character set.
+ /// </summary>
+ C64CharacterSet,
+
+ /// <summary>
+ /// Commodore 64 mono sprites.
+ /// </summary>
+ C64MonoSprite,
+
+ /// <summary>
+ /// Commodore 64 colour sprites.
+ /// </summary>
+ C64ColourSprite
+ }
+
private const uint SET_SIZE = 256;
private const uint MAGIC = 0x5d75537d + SET_SIZE;
private Sprite[] m_sprite;
/// <summary>
+ /// The type of sprite set.
+ /// </summary>
+ public SetType Type {get; private set;}
+
+ /// <summary>
/// The palette associated with the sprite set.
/// </summary>
public Palette Palette {get; private set;}
@@ -55,20 +97,34 @@ namespace SpriteEd
public bool DoubleHeight {get; private set;}
/// <summary>
+ /// The code set (textual descriptions for sprite numbers).
+ /// </summary>
+ public Dictionary<int, string> CodeSet {get; private set;}
+
+ /// <summary>
/// Construct a sprite set.
/// </summary>
+ /// <param name="type">The type of sprite set. This is just informational.</param>
/// <param name="width">The width of each sprite.</param>
/// <param name="height">The height of each sprite.</param>
/// <param name="pal">The palette for the sprites.</param>
/// <param name="double_width">Whether the psrite has a double width pixel.</param>
/// <param name="double_height">Whether the sprite has a double height pixel.</param>
- 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<int, string> 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<int, string> codeset = new Dictionary<int, string>();
+ 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<int, string> 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 <http://www.gnu.org/licenses/>.
+//
+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
{
@@ -80,6 +82,33 @@ namespace SpriteEd
}
/// <summary>
+ /// Write a string to a stream.
+ /// </summary>
+ /// <param name="s">The stream.</param>
+ /// <param name="str">The string.</param>
+ 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);
+ }
+
+ /// <summary>
+ /// Read a string from a stream.
+ /// </summary>
+ /// <param name="s">The stream.</param>
+ /// <returns>The string.</returns>
+ 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);
+ }
+ /// <summary>
/// Display an error alert.
/// </summary>
/// <param name="title">The title for the alert.</param>
@@ -107,6 +136,23 @@ namespace SpriteEd
}
/// <summary>
+ /// Convert an NSColor into a Colour.
+ /// </summary>
+ /// <param name="c">The colour.</param>
+ /// <returns></returns>
+ 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)
+ );
+ }
+
+ /// <summary>
/// Convert a Colour into a CGColor.
/// </summary>
/// <param name="c">The colour.</param>
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 <http://www.gnu.org/licenses/>.
//
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<int, string> 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
@@ -16,15 +16,15 @@ namespace SpriteEd
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; }
[Outlet]
@@ -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;
}
}
}