From f252e784cbccedaa0b31a6db25e40ce769af1daa Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 19 Jul 2020 20:54:52 +0000 Subject: Added right click menu. --- SpriteEd/NSSpriteEdit.cs | 213 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 212 insertions(+), 1 deletion(-) 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; /// /// 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; } + + /// + /// Called for right click menu Flip Horizontal. + /// + /// The event sender. + /// The event args. + 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; + } + + /// + /// Called for right click menu Flip Vertical. + /// + /// The event sender. + /// The event args. + 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; + } + + /// + /// Called for right click menu Scroll Up. + /// + /// The event sender. + /// The event args. + 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; + } + + /// + /// Called for right click menu Scroll Down. + /// + /// The event sender. + /// The event args. + 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; + } + + /// + /// Called for right click menu Scroll Left. + /// + /// The event sender. + /// The event args. + 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; + } + + /// + /// Called for right click menu Scroll Right. + /// + /// The event sender. + /// The event args. + 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; + } + + /// + /// Called for right click menu Drop Shadow. + /// + /// The event sender. + /// The event args. + 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; + } + + /// + /// Called for right click menu Edge. + /// + /// The event sender. + /// The event args. + 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; + } } } -- cgit v1.2.3