summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2020-07-19 20:54:52 +0000
committerIan C <ianc@noddybox.co.uk>2020-07-19 20:54:52 +0000
commitf252e784cbccedaa0b31a6db25e40ce769af1daa (patch)
tree144fc87053e6f43452adcd9dce7993473e84c5d5
parentdd2c2594ee5194f5496d3fec40f292dbf281d068 (diff)
Added right click menu.
-rw-r--r--SpriteEd/NSSpriteEdit.cs213
1 files changed, 212 insertions, 1 deletions
diff --git a/SpriteEd/NSSpriteEdit.cs b/SpriteEd/NSSpriteEdit.cs
index 27a67c3..c679b7f 100644
--- a/SpriteEd/NSSpriteEdit.cs
+++ b/SpriteEd/NSSpriteEdit.cs
@@ -87,6 +87,7 @@ namespace SpriteEd
private uint m_sy;
private uint m_ex;
private uint m_ey;
+ private NSMenu m_menu;
/// <summary>
/// The sprite being edited.
@@ -186,6 +187,19 @@ namespace SpriteEd
m_sy = uint.MaxValue;
m_ex = uint.MaxValue;
m_ey = uint.MaxValue;
+
+ m_menu = new NSMenu();
+ m_menu.AddItem(new NSMenuItem("Flip Horizontal", OnMenuFlipHorizontal));
+ m_menu.AddItem(new NSMenuItem("Flip Vertical", OnMenuFlipVertical));
+ m_menu.AddItem(new NSMenuItem("Scroll Up", OnMenuScrollUp));
+ m_menu.AddItem(new NSMenuItem("Scroll Down", OnMenuScrollDown));
+ m_menu.AddItem(new NSMenuItem("Scroll Left", OnMenuScrollLeft));
+ m_menu.AddItem(new NSMenuItem("Scroll Right", OnMenuScrollRight));
+ m_menu.AddItem(new NSMenuItem("Drop Shadow", OnMenuDropShadow));
+ m_menu.AddItem(new NSMenuItem("Edge", OnMenuEdge));
+
+ Menu = m_menu;
+
WantsLayer = true;
LayerContentsRedrawPolicy = NSViewLayerContentsRedrawPolicy.OnSetNeedsDisplay;
}
@@ -698,7 +712,7 @@ namespace SpriteEd
{
bool ret = false;
- var point = ConvertPointFromView(theEvent.LocationInWindow, null);
+ CGPoint point = ConvertPointFromView(theEvent.LocationInWindow, null);
x = (uint)point.X / BlockSizeX;
y = (uint)(Frame.Height - point.Y) / BlockSizeY;
@@ -837,5 +851,202 @@ namespace SpriteEd
m_ey = uint.MaxValue;
NeedsDisplay = true;
}
+
+ /// <summary>
+ /// Called for right click menu Flip Horizontal.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event args.</param>
+ private void OnMenuFlipHorizontal(object sender, EventArgs e)
+ {
+ SaveUndo("flip horizontal");
+
+ Sprite s = new Sprite(m_sprite);
+
+ for(uint y = 0; y < m_sprite.Height; y++)
+ {
+ for(uint x = 0; x < m_sprite.Width; x++)
+ {
+ m_sprite[m_sprite.Width - x - 1, y] = s[x, y];
+ }
+ }
+
+ NeedsDisplay = true;
+ }
+
+ /// <summary>
+ /// Called for right click menu Flip Vertical.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event args.</param>
+ private void OnMenuFlipVertical(object sender, EventArgs e)
+ {
+ SaveUndo("flip vertical");
+
+ Sprite s = new Sprite(m_sprite);
+
+ for(uint y = 0; y < m_sprite.Height; y++)
+ {
+ for(uint x = 0; x < m_sprite.Width; x++)
+ {
+ m_sprite[x, y] = s[x, m_sprite.Height - y - 1];
+ }
+ }
+
+ NeedsDisplay = true;
+ }
+
+ /// <summary>
+ /// Called for right click menu Scroll Up.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event args.</param>
+ private void OnMenuScrollUp(object sender, EventArgs e)
+ {
+ SaveUndo("scroll up");
+
+ Sprite s = new Sprite(m_sprite);
+
+ for(uint y = 0; y < m_sprite.Height; y++)
+ {
+ for(uint x = 0; x < m_sprite.Width; x++)
+ {
+ m_sprite[x, y] = s[x, (y + 1) % m_sprite.Height];
+ }
+ }
+
+ NeedsDisplay = true;
+ }
+
+ /// <summary>
+ /// Called for right click menu Scroll Down.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event args.</param>
+ private void OnMenuScrollDown(object sender, EventArgs e)
+ {
+ SaveUndo("scroll down");
+
+ Sprite s = new Sprite(m_sprite);
+
+ for(uint y = 0; y < m_sprite.Height; y++)
+ {
+ for(uint x = 0; x < m_sprite.Width; x++)
+ {
+ m_sprite[x, (y + 1) % m_sprite.Height] = s[x, y];
+ }
+ }
+
+ NeedsDisplay = true;
+ }
+
+ /// <summary>
+ /// Called for right click menu Scroll Left.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event args.</param>
+ private void OnMenuScrollLeft(object sender, EventArgs e)
+ {
+ SaveUndo("scroll left");
+
+ Sprite s = new Sprite(m_sprite);
+
+ for(uint y = 0; y < m_sprite.Height; y++)
+ {
+ for(uint x = 0; x < m_sprite.Width; x++)
+ {
+ m_sprite[x, y] = s[(x + 1) % m_sprite.Width, y];
+ }
+ }
+
+ NeedsDisplay = true;
+ }
+
+ /// <summary>
+ /// Called for right click menu Scroll Right.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event args.</param>
+ private void OnMenuScrollRight(object sender, EventArgs e)
+ {
+ SaveUndo("scroll right");
+
+ Sprite s = new Sprite(m_sprite);
+
+ for(uint y = 0; y < m_sprite.Height; y++)
+ {
+ for(uint x = 0; x < m_sprite.Width; x++)
+ {
+ m_sprite[(x + 1) % m_sprite.Width, y] = s[x, y];
+ }
+ }
+
+ NeedsDisplay = true;
+ }
+
+ /// <summary>
+ /// Called for right click menu Drop Shadow.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event args.</param>
+ private void OnMenuDropShadow(object sender, EventArgs e)
+ {
+ SaveUndo("drop shadow");
+
+ Sprite s = new Sprite(m_sprite);
+
+ for(uint y = 1; y < m_sprite.Height; y++)
+ {
+ for(uint x = 1; x < m_sprite.Width; x++)
+ {
+ if (s[x, y] == 0 && s[x - 1, y - 1] != 0)
+ {
+ m_sprite[x, y] = Colour;
+ }
+ }
+ }
+
+ NeedsDisplay = true;
+ }
+
+ /// <summary>
+ /// Called for right click menu Edge.
+ /// </summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event args.</param>
+ private void OnMenuEdge(object sender, EventArgs e)
+ {
+ SaveUndo("edge");
+
+ Sprite s = new Sprite(m_sprite);
+
+ for(uint y = 0; y < m_sprite.Height; y++)
+ {
+ for(uint x = 0; x < m_sprite.Width; x++)
+ {
+ if (s[x, y] != 0)
+ {
+ for(int sx = -1; sx < 2; sx++)
+ {
+ if (x + sx > -1 && x + sx < m_sprite.Width)
+ {
+ for(int sy = -1; sy < 2; sy++)
+ {
+ if (y + sy > -1 && y + sy < m_sprite.Height)
+ {
+ if (s[(uint)(x + sx), (uint)(y + sy)] == 0)
+ {
+ m_sprite[(uint)(x + sx), (uint)(y + sy)] = Colour;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ NeedsDisplay = true;
+ }
}
}