diff --git a/SpriteMapEditor/DirectBitmap.cs b/SpriteMapEditor/DirectBitmap.cs new file mode 100644 index 0000000..1141713 --- /dev/null +++ b/SpriteMapEditor/DirectBitmap.cs @@ -0,0 +1,78 @@ +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SpriteMapEditor +{ + [Serializable] + public class DirectBitmap : IDisposable + { + public Bitmap Bitmap { get; private set; } + public Int32[] Bits { get; private set; } + public bool Disposed { get; private set; } + public int Height { get; private set; } + public int Width { get; private set; } + + protected GCHandle BitsHandle { get; private set; } + + public DirectBitmap(int width, int height) + { + Width = width; + Height = height; + Bits = new Int32[width * height]; + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject()); + } + + public DirectBitmap(DirectBitmap original) + { + Width = original.Width; + Height = original.Height; + Bits = (int[])original.Bits.Clone(); + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject()); + } + + public void CopyBitmap(DirectBitmap source) + { + if(Width == source.Width && Height == source.Height) + { + Bits = (int[])source.Bits.Clone(); + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject()); + } + } + + public void SetPixel(int x, int y, Color colour) + { + int index = x + (y * Width); + int col = colour.ToArgb(); + + Bits[index] = col; + } + + public Color GetPixel(int x, int y) + { + int index = x + (y * Width); + int col = Bits[index]; + Color result = Color.FromArgb(col); + + return result; + } + + public void Dispose() + { + if (Disposed) return; + Disposed = true; + Bitmap.Dispose(); + BitsHandle.Free(); + } + } +} diff --git a/SpriteMapEditor/Form1.Designer.cs b/SpriteMapEditor/Form1.Designer.cs index fecbacb..5cea6bb 100644 --- a/SpriteMapEditor/Form1.Designer.cs +++ b/SpriteMapEditor/Form1.Designer.cs @@ -28,14 +28,9 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.spriteList = new System.Windows.Forms.ListBox(); this.addSpriteButton = new System.Windows.Forms.Button(); this.removeSpriteButton = new System.Windows.Forms.Button(); - this.loadSpriteSheetButton = new System.Windows.Forms.Button(); - this.loadMapButton = new System.Windows.Forms.Button(); - this.saveMapButton = new System.Windows.Forms.Button(); - this.filePanel = new System.Windows.Forms.Panel(); this.spriteListPanel = new System.Windows.Forms.Panel(); this.moveDownButton = new System.Windows.Forms.Button(); this.moveUpButton = new System.Windows.Forms.Button(); @@ -61,11 +56,18 @@ this.saveMapDialog = new System.Windows.Forms.SaveFileDialog(); this.fillButton = new System.Windows.Forms.Button(); this.spriteViewerPanel = new System.Windows.Forms.Panel(); - this.spriteSheetViewer = new SpriteMapEditor.PictureBoxWithInterpolationMode(); this.zoomInButton = new System.Windows.Forms.Button(); this.zoomOutButton = new System.Windows.Forms.Button(); this.zoomLabel = new System.Windows.Forms.Label(); - this.filePanel.SuspendLayout(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.loadSpriteSheetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.loadSpriteMapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); + this.saveSpriteMapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveSpriteMapAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.editingOriginCheckBox = new System.Windows.Forms.CheckBox(); + this.spriteSheetViewer = new SpriteMapEditor.PictureBoxWithInterpolationMode(); this.spriteListPanel.SuspendLayout(); this.spritePanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.originYPosBox)).BeginInit(); @@ -75,6 +77,7 @@ ((System.ComponentModel.ISupportInitialize)(this.spriteYPosBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.spriteXPosBox)).BeginInit(); this.spriteViewerPanel.SuspendLayout(); + this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.spriteSheetViewer)).BeginInit(); this.SuspendLayout(); // @@ -108,46 +111,6 @@ this.removeSpriteButton.UseVisualStyleBackColor = true; this.removeSpriteButton.Click += new System.EventHandler(this.removeSpriteButton_Click); // - // loadSpriteSheetButton - // - this.loadSpriteSheetButton.Location = new System.Drawing.Point(3, 3); - this.loadSpriteSheetButton.Name = "loadSpriteSheetButton"; - this.loadSpriteSheetButton.Size = new System.Drawing.Size(185, 23); - this.loadSpriteSheetButton.TabIndex = 4; - this.loadSpriteSheetButton.Text = "Load Sprite Sheet..."; - this.loadSpriteSheetButton.UseVisualStyleBackColor = true; - this.loadSpriteSheetButton.Click += new System.EventHandler(this.loadSpriteSheetButton_Click); - // - // loadMapButton - // - this.loadMapButton.Location = new System.Drawing.Point(3, 32); - this.loadMapButton.Name = "loadMapButton"; - this.loadMapButton.Size = new System.Drawing.Size(92, 23); - this.loadMapButton.TabIndex = 5; - this.loadMapButton.Text = "Load Map..."; - this.loadMapButton.UseVisualStyleBackColor = true; - this.loadMapButton.Click += new System.EventHandler(this.loadMapButton_Click); - // - // saveMapButton - // - this.saveMapButton.Location = new System.Drawing.Point(96, 32); - this.saveMapButton.Name = "saveMapButton"; - this.saveMapButton.Size = new System.Drawing.Size(92, 23); - this.saveMapButton.TabIndex = 6; - this.saveMapButton.Text = "Save Map As..."; - this.saveMapButton.UseVisualStyleBackColor = true; - this.saveMapButton.Click += new System.EventHandler(this.saveMapButton_Click); - // - // filePanel - // - this.filePanel.Controls.Add(this.loadSpriteSheetButton); - this.filePanel.Controls.Add(this.saveMapButton); - this.filePanel.Controls.Add(this.loadMapButton); - this.filePanel.Location = new System.Drawing.Point(2, 2); - this.filePanel.Name = "filePanel"; - this.filePanel.Size = new System.Drawing.Size(190, 62); - this.filePanel.TabIndex = 7; - // // spriteListPanel // this.spriteListPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -160,9 +123,9 @@ this.spriteListPanel.Controls.Add(this.spriteList); this.spriteListPanel.Controls.Add(this.addSpriteButton); this.spriteListPanel.Controls.Add(this.removeSpriteButton); - this.spriteListPanel.Location = new System.Drawing.Point(2, 63); + this.spriteListPanel.Location = new System.Drawing.Point(2, 27); this.spriteListPanel.Name = "spriteListPanel"; - this.spriteListPanel.Size = new System.Drawing.Size(190, 254); + this.spriteListPanel.Size = new System.Drawing.Size(190, 258); this.spriteListPanel.TabIndex = 8; // // moveDownButton @@ -198,6 +161,7 @@ // spritePanel // this.spritePanel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.spritePanel.Controls.Add(this.editingOriginCheckBox); this.spritePanel.Controls.Add(this.originYPosBox); this.spritePanel.Controls.Add(this.originXPosBox); this.spritePanel.Controls.Add(this.originYPosLabel); @@ -213,15 +177,15 @@ this.spritePanel.Controls.Add(this.label2); this.spritePanel.Controls.Add(this.spriteSettingsLabel); this.spritePanel.Controls.Add(this.spriteNameBox); - this.spritePanel.Location = new System.Drawing.Point(2, 323); + this.spritePanel.Location = new System.Drawing.Point(2, 291); this.spritePanel.Name = "spritePanel"; - this.spritePanel.Size = new System.Drawing.Size(190, 140); + this.spritePanel.Size = new System.Drawing.Size(190, 172); this.spritePanel.TabIndex = 9; // // originYPosBox // this.originYPosBox.Enabled = false; - this.originYPosBox.Location = new System.Drawing.Point(143, 108); + this.originYPosBox.Location = new System.Drawing.Point(143, 131); this.originYPosBox.Maximum = new decimal(new int[] { 2147483647, 0, @@ -235,7 +199,7 @@ // originXPosBox // this.originXPosBox.Enabled = false; - this.originXPosBox.Location = new System.Drawing.Point(51, 108); + this.originXPosBox.Location = new System.Drawing.Point(51, 131); this.originXPosBox.Maximum = new decimal(new int[] { 2147483647, 0, @@ -250,7 +214,7 @@ // this.originYPosLabel.AutoSize = true; this.originYPosLabel.Enabled = false; - this.originYPosLabel.Location = new System.Drawing.Point(98, 111); + this.originYPosLabel.Location = new System.Drawing.Point(98, 134); this.originYPosLabel.Name = "originYPosLabel"; this.originYPosLabel.Size = new System.Drawing.Size(44, 13); this.originYPosLabel.TabIndex = 20; @@ -260,7 +224,7 @@ // this.originXPosLabel.AutoSize = true; this.originXPosLabel.Enabled = false; - this.originXPosLabel.Location = new System.Drawing.Point(6, 111); + this.originXPosLabel.Location = new System.Drawing.Point(6, 134); this.originXPosLabel.Name = "originXPosLabel"; this.originXPosLabel.Size = new System.Drawing.Size(44, 13); this.originXPosLabel.TabIndex = 19; @@ -399,7 +363,7 @@ // // fillButton // - this.fillButton.Location = new System.Drawing.Point(454, 5); + this.fillButton.Location = new System.Drawing.Point(461, 30); this.fillButton.Name = "fillButton"; this.fillButton.Size = new System.Drawing.Size(86, 23); this.fillButton.TabIndex = 12; @@ -413,15 +377,110 @@ this.spriteViewerPanel.BackColor = System.Drawing.SystemColors.ControlDark; this.spriteViewerPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.spriteViewerPanel.Controls.Add(this.spriteSheetViewer); - this.spriteViewerPanel.Location = new System.Drawing.Point(199, 34); + this.spriteViewerPanel.Location = new System.Drawing.Point(198, 59); this.spriteViewerPanel.Name = "spriteViewerPanel"; - this.spriteViewerPanel.Size = new System.Drawing.Size(488, 429); + this.spriteViewerPanel.Size = new System.Drawing.Size(488, 404); this.spriteViewerPanel.TabIndex = 14; this.spriteViewerPanel.Scroll += new System.Windows.Forms.ScrollEventHandler(this.spriteViewerPanel_Scroll); // + // zoomInButton + // + this.zoomInButton.Location = new System.Drawing.Point(659, 30); + this.zoomInButton.Name = "zoomInButton"; + this.zoomInButton.Size = new System.Drawing.Size(27, 23); + this.zoomInButton.TabIndex = 5; + this.zoomInButton.Text = "+"; + this.zoomInButton.UseVisualStyleBackColor = true; + this.zoomInButton.Click += new System.EventHandler(this.zoomInButton_Click); + // + // zoomOutButton + // + this.zoomOutButton.Location = new System.Drawing.Point(566, 30); + this.zoomOutButton.Name = "zoomOutButton"; + this.zoomOutButton.Size = new System.Drawing.Size(28, 23); + this.zoomOutButton.TabIndex = 6; + this.zoomOutButton.Text = "-"; + this.zoomOutButton.UseVisualStyleBackColor = true; + this.zoomOutButton.Click += new System.EventHandler(this.zoomOutButton_Click); + // + // zoomLabel + // + this.zoomLabel.AutoSize = true; + this.zoomLabel.Location = new System.Drawing.Point(600, 35); + this.zoomLabel.Name = "zoomLabel"; + this.zoomLabel.Size = new System.Drawing.Size(53, 13); + this.zoomLabel.TabIndex = 15; + this.zoomLabel.Text = "Zoom: 3X"; + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.fileToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(691, 24); + this.menuStrip1.TabIndex = 16; + this.menuStrip1.Text = "menuStrip1"; + // + // fileToolStripMenuItem + // + this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.loadSpriteSheetToolStripMenuItem, + this.loadSpriteMapToolStripMenuItem, + this.toolStripMenuItem1, + this.saveSpriteMapToolStripMenuItem, + this.saveSpriteMapAsToolStripMenuItem}); + this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; + this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); + this.fileToolStripMenuItem.Text = "File"; + // + // loadSpriteSheetToolStripMenuItem + // + this.loadSpriteSheetToolStripMenuItem.Name = "loadSpriteSheetToolStripMenuItem"; + this.loadSpriteSheetToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.loadSpriteSheetToolStripMenuItem.Text = "Load Sprite Sheet..."; + this.loadSpriteSheetToolStripMenuItem.Click += new System.EventHandler(this.loadSpriteSheetToolStripMenuItem_Click); + // + // loadSpriteMapToolStripMenuItem + // + this.loadSpriteMapToolStripMenuItem.Name = "loadSpriteMapToolStripMenuItem"; + this.loadSpriteMapToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.loadSpriteMapToolStripMenuItem.Text = "Load Sprite Map..."; + this.loadSpriteMapToolStripMenuItem.Click += new System.EventHandler(this.loadMapToolStripMenuItem_Click); + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 6); + // + // saveSpriteMapToolStripMenuItem + // + this.saveSpriteMapToolStripMenuItem.Name = "saveSpriteMapToolStripMenuItem"; + this.saveSpriteMapToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.saveSpriteMapToolStripMenuItem.Text = "Save Sprite Map"; + this.saveSpriteMapToolStripMenuItem.Click += new System.EventHandler(this.saveSpriteMapToolStripMenuItem_Click); + // + // saveSpriteMapAsToolStripMenuItem + // + this.saveSpriteMapAsToolStripMenuItem.Name = "saveSpriteMapAsToolStripMenuItem"; + this.saveSpriteMapAsToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.saveSpriteMapAsToolStripMenuItem.Text = "Save Sprite Map As..."; + this.saveSpriteMapAsToolStripMenuItem.Click += new System.EventHandler(this.saveMapAsToolStripMenuItem_Click); + // + // editingOriginCheckBox + // + this.editingOriginCheckBox.AutoSize = true; + this.editingOriginCheckBox.Location = new System.Drawing.Point(9, 108); + this.editingOriginCheckBox.Name = "editingOriginCheckBox"; + this.editingOriginCheckBox.Size = new System.Drawing.Size(107, 17); + this.editingOriginCheckBox.TabIndex = 23; + this.editingOriginCheckBox.Text = "Edit Origin Point?"; + this.editingOriginCheckBox.UseVisualStyleBackColor = true; + this.editingOriginCheckBox.CheckedChanged += new System.EventHandler(this.editingOriginCheckBox_CheckedChanged); + // // spriteSheetViewer // - this.spriteSheetViewer.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("spriteSheetViewer.BackgroundImage"))); + this.spriteSheetViewer.BackgroundImage = global::SpriteMapEditor.Properties.Resources.transparentUI; this.spriteSheetViewer.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; this.spriteSheetViewer.Location = new System.Drawing.Point(0, 0); this.spriteSheetViewer.Margin = new System.Windows.Forms.Padding(0); @@ -436,35 +495,6 @@ this.spriteSheetViewer.MouseMove += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseMove); this.spriteSheetViewer.MouseUp += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseUp); // - // zoomInButton - // - this.zoomInButton.Location = new System.Drawing.Point(652, 5); - this.zoomInButton.Name = "zoomInButton"; - this.zoomInButton.Size = new System.Drawing.Size(27, 23); - this.zoomInButton.TabIndex = 5; - this.zoomInButton.Text = "+"; - this.zoomInButton.UseVisualStyleBackColor = true; - this.zoomInButton.Click += new System.EventHandler(this.zoomInButton_Click); - // - // zoomOutButton - // - this.zoomOutButton.Location = new System.Drawing.Point(559, 5); - this.zoomOutButton.Name = "zoomOutButton"; - this.zoomOutButton.Size = new System.Drawing.Size(28, 23); - this.zoomOutButton.TabIndex = 6; - this.zoomOutButton.Text = "-"; - this.zoomOutButton.UseVisualStyleBackColor = true; - this.zoomOutButton.Click += new System.EventHandler(this.zoomOutButton_Click); - // - // zoomLabel - // - this.zoomLabel.AutoSize = true; - this.zoomLabel.Location = new System.Drawing.Point(593, 10); - this.zoomLabel.Name = "zoomLabel"; - this.zoomLabel.Size = new System.Drawing.Size(53, 13); - this.zoomLabel.TabIndex = 15; - this.zoomLabel.Text = "Zoom: 3X"; - // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -478,10 +508,9 @@ this.Controls.Add(this.fillButton); this.Controls.Add(this.spritePanel); this.Controls.Add(this.spriteListPanel); - this.Controls.Add(this.filePanel); + this.Controls.Add(this.menuStrip1); this.Name = "Form1"; this.Text = "QUROGames Sprite Map Editor"; - this.filePanel.ResumeLayout(false); this.spriteListPanel.ResumeLayout(false); this.spriteListPanel.PerformLayout(); this.spritePanel.ResumeLayout(false); @@ -493,6 +522,8 @@ ((System.ComponentModel.ISupportInitialize)(this.spriteYPosBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.spriteXPosBox)).EndInit(); this.spriteViewerPanel.ResumeLayout(false); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.spriteSheetViewer)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -504,10 +535,6 @@ private System.Windows.Forms.ListBox spriteList; private System.Windows.Forms.Button addSpriteButton; private System.Windows.Forms.Button removeSpriteButton; - private System.Windows.Forms.Button loadSpriteSheetButton; - private System.Windows.Forms.Button loadMapButton; - private System.Windows.Forms.Button saveMapButton; - private System.Windows.Forms.Panel filePanel; private System.Windows.Forms.Panel spriteListPanel; private System.Windows.Forms.Label spritesLabel; private System.Windows.Forms.Panel spritePanel; @@ -537,6 +564,14 @@ private System.Windows.Forms.Label originXPosLabel; private System.Windows.Forms.Button moveDownButton; private System.Windows.Forms.Button moveUpButton; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem loadSpriteSheetToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem loadSpriteMapToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem saveSpriteMapToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveSpriteMapAsToolStripMenuItem; + private System.Windows.Forms.CheckBox editingOriginCheckBox; } } diff --git a/SpriteMapEditor/Form1.cs b/SpriteMapEditor/Form1.cs index e2bf466..5edeadb 100644 --- a/SpriteMapEditor/Form1.cs +++ b/SpriteMapEditor/Form1.cs @@ -27,7 +27,25 @@ namespace SpriteMapEditor private bool loadingSprite = false; private bool movingWithMouse = false; - private bool rearrangingSprites = false; + private bool editingOrigin = false; + + const string TITLE = "QUROGames Sprite Map Editor"; + private string currentSpriteMapFileLocation; + private string CurrentSpriteMapFileLocation + { + get { return currentSpriteMapFileLocation; } + set + { + currentSpriteMapFileLocation = value; + Text = TITLE + " - " + Path.GetFileName(currentSpriteMapFileLocation); + } + } + + Image originPointer_black; + Image originPointer_white; + + DirectBitmap baseMask; + DirectBitmap highlightMask; private Point newPosition; private Point oldPosition; @@ -59,15 +77,20 @@ namespace SpriteMapEditor spriteList.DisplayMember = "Name"; spriteList.ValueMember = "Bounds"; + originPointer_black = Properties.Resources.originPointer_black; + originPointer_white = Properties.Resources.originPointer_white; + LoadSpriteEditorValues(); } - private void loadSpriteSheetButton_Click(object sender, EventArgs e) + private void loadSpriteSheetToolStripMenuItem_Click(object sender, EventArgs e) { if(loadSpriteSheetDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { spriteSheetViewer.Image = Image.FromFile(loadSpriteSheetDialog.FileName); } + + InitializeMask(); } private void spriteSheetViewer_Paint(object sender, PaintEventArgs e) @@ -78,18 +101,35 @@ namespace SpriteMapEditor spriteSheetViewer.Height = spriteSheetViewer.Image.Height * zoomLevel; if (highlight) - SurroundWithTranslucentRects(GetDrawingRect(currentSprite.Bounds, false), Color.Gray, e.Graphics); - DrawHighContrastOutline(GetDrawingRect(currentSprite.Bounds), e.Graphics); - /* - * Origin display code, uncomment when ready to implement - * - using (Brush magentaBrush = new SolidBrush(Color.Magenta)) { - e.Graphics.FillRectangle(magentaBrush, GetOriginDrawingRect(currentSprite)); + //SurroundWithTranslucentRects(GetDrawingRect(currentSprite.Bounds, false), Color.Gray, e.Graphics); + //e.Graphics.DrawImage(highlightMask.Bitmap, Point.Empty); + Rectangle highlightBounds = new Rectangle(0,0, spriteSheetViewer.Bounds.Width + 1, spriteSheetViewer.Bounds.Height + 1); + e.Graphics.DrawImage(highlightMask.Bitmap, highlightBounds); + } + + DrawHighContrastOutline(GetDrawingRect(currentSprite.Bounds), e.Graphics); + + //origin drawing code + if (editingOrigin) + { + var spriteSheet = (Bitmap)spriteSheetViewer.Image; + var colorAtOrigin = spriteSheet.GetPixel((int)(currentSprite.Bounds.X + currentSprite.Origin.X), + (int)(currentSprite.Bounds.Y + currentSprite.Origin.Y)); + + var highContrastPointer = originPointer_black; + if (colorAtOrigin.GetBrightness() < 0.5f) + { + highContrastPointer = originPointer_white; + } + + var drawPoint = GetOriginDrawingPoint(currentSprite); + drawPoint.X -= 5; + drawPoint.Y -= 5; + + e.Graphics.DrawImage(highContrastPointer, drawPoint); } - */ } - base.OnPaint(e); } @@ -137,16 +177,51 @@ namespace SpriteMapEditor return drawingRect; } - private Rectangle GetOriginDrawingRect(SpriteMapRegion sprite) + private Point GetOriginDrawingPoint(SpriteMapRegion sprite) { - var drawingRect = new Rectangle(sprite.Bounds.X, sprite.Bounds.Y, 2, 2); - drawingRect.X = drawingRect.X * zoomLevel - (zoomLevel - 1); - drawingRect.Y = drawingRect.Y * zoomLevel - (zoomLevel - 1); - drawingRect.X += drawingRectangleOffset; - drawingRect.Y += drawingRectangleOffset; - drawingRect.X += (int)sprite.Origin.X * zoomLevel; - drawingRect.Y += (int)sprite.Origin.Y * zoomLevel; - return drawingRect; + var drawingPoint = new Point(sprite.Bounds.X, sprite.Bounds.Y); + drawingPoint.X = drawingPoint.X * zoomLevel - (zoomLevel - 1); + drawingPoint.Y = drawingPoint.Y * zoomLevel - (zoomLevel - 1); + drawingPoint.X += drawingRectangleOffset; + drawingPoint.Y += drawingRectangleOffset; + drawingPoint.X += (int)sprite.Origin.X * zoomLevel; + drawingPoint.Y += (int)sprite.Origin.Y * zoomLevel; + return drawingPoint; + } + + private void UpdateHighlightMask() + { + if (highlight) + { + InitializeMask(); + for (int currentY = 0; currentY < currentSprite.Bounds.Height; currentY++) + { + for (int currentX = 0; currentX < currentSprite.Bounds.Width; currentX++) + { + highlightMask.SetPixel(currentX + currentSprite.Bounds.X, currentY + currentSprite.Bounds.Y, Color.Transparent); + } + } + } + } + + private void InitializeMask() + { + if (baseMask == null) + { + highlightMask = new DirectBitmap(spriteSheetViewer.Image.Width, spriteSheetViewer.Image.Height); + for (int currentY = 0; currentY < highlightMask.Height; currentY++) + { + for (int currentX = 0; currentX < highlightMask.Width; currentX++) + { + highlightMask.SetPixel(currentX, currentY, Color.Gray); + } + } + baseMask = new DirectBitmap(highlightMask); + } + else + { + highlightMask.CopyBitmap(baseMask); + } } private void SurroundWithTranslucentRects(Rectangle rect, Color color, Graphics graphics) @@ -191,7 +266,10 @@ namespace SpriteMapEditor { highlight = !highlight; if (highlight) + { fillButton.Text = "No Highlight"; + UpdateHighlightMask(); + } else fillButton.Text = "Highlight"; spriteSheetViewer.Refresh(); @@ -224,6 +302,7 @@ namespace SpriteMapEditor if (loadingSprite) return; UpdateSpriteBounds(); + UpdateHighlightMask(); spriteSheetViewer.Refresh(); } @@ -232,6 +311,7 @@ namespace SpriteMapEditor if (loadingSprite) return; UpdateSpriteBounds(); + UpdateHighlightMask(); spriteSheetViewer.Refresh(); } @@ -240,6 +320,7 @@ namespace SpriteMapEditor if (loadingSprite) return; UpdateSpriteBounds(); + UpdateHighlightMask(); spriteSheetViewer.Refresh(); } @@ -248,6 +329,7 @@ namespace SpriteMapEditor if (loadingSprite) return; UpdateSpriteBounds(); + UpdateHighlightMask(); spriteSheetViewer.Refresh(); } @@ -276,11 +358,12 @@ namespace SpriteMapEditor { currentSprite = sprites[spriteList.SelectedIndex]; LoadSpriteEditorValues(); + UpdateHighlightMask(); spriteSheetViewer.Refresh(); } } - private void saveMapButton_Click(object sender, EventArgs e) + private void saveMapAsToolStripMenuItem_Click(object sender, EventArgs e) { var exportDict = new Dictionary(); foreach (SpriteMapRegion sprite in sprites) @@ -299,19 +382,51 @@ namespace SpriteMapEditor if (saveMapDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { - using (XmlWriter writer = XmlWriter.Create(saveMapDialog.FileName)) + CurrentSpriteMapFileLocation = saveMapDialog.FileName; + + using (XmlWriter writer = XmlWriter.Create(CurrentSpriteMapFileLocation)) + { + IntermediateSerializer.Serialize(writer, exportDict, null); + } + } + + saveSpriteMapToolStripMenuItem.Enabled = true; + } + + private void saveSpriteMapToolStripMenuItem_Click(object sender, EventArgs e) + { + if (CurrentSpriteMapFileLocation != null) + { + var exportDict = new Dictionary(); + foreach (SpriteMapRegion sprite in sprites) + { + if (exportDict.ContainsKey(sprite.Name)) + { + string errorMessage = "Duplicate names found! Please ensure all sprites have unique names."; + string caption = "Save Aborted"; + MessageBoxButtons saveError = MessageBoxButtons.OK; + + MessageBox.Show(errorMessage, caption, saveError); + return; + } + exportDict.Add(sprite.Name, sprite); + } + + using (XmlWriter writer = XmlWriter.Create(CurrentSpriteMapFileLocation)) { IntermediateSerializer.Serialize(writer, exportDict, null); } } } - private void loadMapButton_Click(object sender, EventArgs e) + private void loadMapToolStripMenuItem_Click(object sender, EventArgs e) { if(loadMapDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { + CurrentSpriteMapFileLocation = loadMapDialog.FileName; + Dictionary loadedSpriteMap; - using (XmlReader xmlRead = XmlReader.Create(loadMapDialog.FileName)) + using (XmlReader xmlRead = XmlReader.Create(CurrentSpriteMapFileLocation)) { loadedSpriteMap = IntermediateSerializer.Deserialize>(xmlRead, null); } @@ -343,13 +458,13 @@ namespace SpriteMapEditor newPosition.Y /= zoomLevel; int differenceX = newPosition.X - oldPosition.X; int differenceY = newPosition.Y - oldPosition.Y; - Console.WriteLine(differenceX + ", " + differenceY); var newBounds = currentSprite.Bounds; newBounds.X += differenceX; newBounds.Y += differenceY; currentSprite.Bounds = newBounds; oldPosition = newPosition; + UpdateHighlightMask(); spriteSheetViewer.Refresh(); LoadSpriteEditorValues(); } @@ -423,5 +538,27 @@ namespace SpriteMapEditor spriteList.SelectedIndex--; } } + + private void editingOriginCheckBox_CheckedChanged(object sender, EventArgs e) + { + editingOrigin = editingOriginCheckBox.Checked; + + if (editingOrigin) + { + originXPosLabel.Enabled = true; + originXPosBox.Enabled = true; + originYPosLabel.Enabled = true; + originYPosBox.Enabled = true; + } + else + { + originXPosLabel.Enabled = false; + originXPosBox.Enabled = false; + originYPosLabel.Enabled = false; + originYPosBox.Enabled = false; + } + + spriteViewerPanel.Refresh(); + } } } diff --git a/SpriteMapEditor/Form1.resx b/SpriteMapEditor/Form1.resx index 622b2df..20e8abd 100644 --- a/SpriteMapEditor/Form1.resx +++ b/SpriteMapEditor/Form1.resx @@ -126,56 +126,7 @@ 325, 17 - - - - iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAACH - DwAAjA8AAP1SAACBQAAAfXkAAOmLAAA85QAAGcxzPIV3AAAKOWlDQ1BQaG90b3Nob3AgSUNDIHByb2Zp - bGUAAEjHnZZ3VFTXFofPvXd6oc0wAlKG3rvAANJ7k15FYZgZYCgDDjM0sSGiAhFFRJoiSFDEgNFQJFZE - sRAUVLAHJAgoMRhFVCxvRtaLrqy89/Ly++Osb+2z97n77L3PWhcAkqcvl5cGSwGQyhPwgzyc6RGRUXTs - AIABHmCAKQBMVka6X7B7CBDJy82FniFyAl8EAfB6WLwCcNPQM4BOB/+fpFnpfIHomAARm7M5GSwRF4g4 - JUuQLrbPipgalyxmGCVmvihBEcuJOWGRDT77LLKjmNmpPLaIxTmns1PZYu4V8bZMIUfEiK+ICzO5nCwR - 3xKxRoowlSviN+LYVA4zAwAUSWwXcFiJIjYRMYkfEuQi4uUA4EgJX3HcVyzgZAvEl3JJS8/hcxMSBXQd - li7d1NqaQffkZKVwBALDACYrmcln013SUtOZvBwAFu/8WTLi2tJFRbY0tba0NDQzMv2qUP91829K3NtF - ehn4uWcQrf+L7a/80h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fhN2VAGasyugRU0c9Uv1BHuEU4lmmfWZP5Jiss60S2 - dDYvuz9HL2d7zmSue+63a1FrWWt78lTzNuWNrXNaV78eWh+3vmeD+oaCDRMbPTYe3kTYlLzpp3yT/LL8 - V5vDN3cXKBVsLBjf4rGlpVCikF84stV2a9021DbutoHt5turtn8sYhddLTYprih+X8IqufqN6TeV33za - Eb9joNSydP9OzE7ezuFdDrsOl0mX5ZaN7/bb3VFOLy8qf7UnZs+VimUVdXsJe4V7Ryt9K7uqNKp2Vr2v - Tqy+XeNc01arWLu9dn4fe9/Qfsf9rXVKdcV17w5wD9yp96jvaNBqqDiIOZh58EljWGPft4xvm5sUmoqb - PhziHRo9HHS4t9mqufmI4pHSFrhF2DJ9NProje9cv+tqNWytb6O1FR8Dx4THnn4f+/3wcZ/jPScYJ1p/ - 0Pyhtp3SXtQBdeR0zHYmdo52RXYNnvQ+2dNt293+o9GPh06pnqo5LXu69AzhTMGZT2dzz86dSz83cz7h - /HhPTM/9CxEXbvUG9g5c9Ll4+ZL7pQt9Tn1nL9tdPnXF5srJq4yrndcsr3X0W/S3/2TxU/uA5UDHdavr - XTesb3QPLh88M+QwdP6m681Lt7xuXbu94vbgcOjwnZHokdE77DtTd1PuvriXeW/h/sYH6AdFD6UeVjxS - fNTws+7PbaOWo6fHXMf6Hwc/vj/OGn/2S8Yv7ycKnpCfVEyqTDZPmU2dmnafvvF05dOJZ+nPFmYKf5X+ - tfa5zvMffnP8rX82YnbiBf/Fp99LXsq/PPRq2aueuYC5R69TXy/MF72Rf3P4LeNt37vwd5MLWe+x7ys/ - 6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAALEwAACxMBAJqcGAAAABxJREFUGFdjOIME/iMB - akpAaTCAyoMB1STOnAEAQTWsIWODQqUAAAAASUVORK5CYII= - - + + 461, 17 + \ No newline at end of file diff --git a/SpriteMapEditor/Properties/Resources.Designer.cs b/SpriteMapEditor/Properties/Resources.Designer.cs index 5d6ac28..366c787 100644 --- a/SpriteMapEditor/Properties/Resources.Designer.cs +++ b/SpriteMapEditor/Properties/Resources.Designer.cs @@ -60,6 +60,26 @@ namespace SpriteMapEditor.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap originPointer_black { + get { + object obj = ResourceManager.GetObject("originPointer_black", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap originPointer_white { + get { + object obj = ResourceManager.GetObject("originPointer_white", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/SpriteMapEditor/Properties/Resources.resx b/SpriteMapEditor/Properties/Resources.resx index 2b94a9d..d7626de 100644 --- a/SpriteMapEditor/Properties/Resources.resx +++ b/SpriteMapEditor/Properties/Resources.resx @@ -118,7 +118,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\originPointer_black.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\originPointer_white.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + - ..\transparentui.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\transparentUI.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/SpriteMapEditor/Resources/originPointer_black.png b/SpriteMapEditor/Resources/originPointer_black.png new file mode 100644 index 0000000..bc98207 Binary files /dev/null and b/SpriteMapEditor/Resources/originPointer_black.png differ diff --git a/SpriteMapEditor/Resources/originPointer_white.png b/SpriteMapEditor/Resources/originPointer_white.png new file mode 100644 index 0000000..25a472d Binary files /dev/null and b/SpriteMapEditor/Resources/originPointer_white.png differ diff --git a/SpriteMapEditor/SpriteMapEditor.csproj b/SpriteMapEditor/SpriteMapEditor.csproj index fdb995a..914dae8 100644 --- a/SpriteMapEditor/SpriteMapEditor.csproj +++ b/SpriteMapEditor/SpriteMapEditor.csproj @@ -51,6 +51,7 @@ + Form @@ -88,17 +89,20 @@ - - - - - - {4581e0c8-b14a-454d-9a7b-52d37535e7e9} QURO + + + + + + + + + \ No newline at end of file diff --git a/SpriteMapEditor/transparentUI.png b/SpriteMapEditor/transparentUI.png deleted file mode 100644 index eb68dbf..0000000 Binary files a/SpriteMapEditor/transparentUI.png and /dev/null differ