Added Drag/Drop Rearrange to SpriteMapEditor

This commit is contained in:
quinnvoker
2018-11-22 16:29:50 -08:00
parent fd24ebaeba
commit acda9d30fc
2 changed files with 54 additions and 6 deletions
+21 -2
View File
@@ -59,6 +59,7 @@
this.zoomOutButton = new System.Windows.Forms.Button();
this.zoomLabel = new System.Windows.Forms.Label();
this.spriteSheetViewer = new SpriteMapEditor.PictureBoxWithInterpolationMode();
this.rearrangeCheckBox = new System.Windows.Forms.CheckBox();
this.filePanel.SuspendLayout();
this.spriteListPanel.SuspendLayout();
this.spritePanel.SuspendLayout();
@@ -72,15 +73,19 @@
//
// spriteList
//
this.spriteList.AllowDrop = true;
this.spriteList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.spriteList.FormattingEnabled = true;
this.spriteList.Location = new System.Drawing.Point(3, 32);
this.spriteList.Name = "spriteList";
this.spriteList.Size = new System.Drawing.Size(185, 251);
this.spriteList.Size = new System.Drawing.Size(185, 225);
this.spriteList.TabIndex = 0;
this.spriteList.SelectedValueChanged += new System.EventHandler(this.spriteList_SelectedValueChanged);
this.spriteList.DragDrop += new System.Windows.Forms.DragEventHandler(this.spriteList_DragDrop);
this.spriteList.DragOver += new System.Windows.Forms.DragEventHandler(this.spriteList_DragOver);
this.spriteList.MouseDown += new System.Windows.Forms.MouseEventHandler(this.spriteList_MouseDown);
//
// addSpriteButton
//
@@ -149,13 +154,14 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.spriteListPanel.AutoSize = true;
this.spriteListPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.spriteListPanel.Controls.Add(this.rearrangeCheckBox);
this.spriteListPanel.Controls.Add(this.spritesLabel);
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.Name = "spriteListPanel";
this.spriteListPanel.Size = new System.Drawing.Size(191, 286);
this.spriteListPanel.Size = new System.Drawing.Size(224, 286);
this.spriteListPanel.TabIndex = 8;
//
// spritesLabel
@@ -385,6 +391,18 @@
this.spriteSheetViewer.MouseMove += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseMove);
this.spriteSheetViewer.MouseUp += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseUp);
//
// rearrangeCheckBox
//
this.rearrangeCheckBox.AutoSize = true;
this.rearrangeCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.rearrangeCheckBox.Location = new System.Drawing.Point(82, 263);
this.rearrangeCheckBox.Name = "rearrangeCheckBox";
this.rearrangeCheckBox.Size = new System.Drawing.Size(106, 17);
this.rearrangeCheckBox.TabIndex = 5;
this.rearrangeCheckBox.Text = "Rearrange Mode";
this.rearrangeCheckBox.UseVisualStyleBackColor = true;
this.rearrangeCheckBox.CheckedChanged += new System.EventHandler(this.rearrangeCheckBox_CheckedChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -449,6 +467,7 @@
private System.Windows.Forms.NumericUpDown spriteYPosBox;
private System.Windows.Forms.NumericUpDown spriteXPosBox;
private System.Windows.Forms.Label zoomLabel;
private System.Windows.Forms.CheckBox rearrangeCheckBox;
}
}
+33 -4
View File
@@ -23,6 +23,7 @@ namespace SpriteMapEditor
private bool loadingSprite = false;
private bool movingWithMouse = false;
private bool rearrangingSprites = false;
private Point newPosition;
private Point oldPosition;
@@ -50,15 +51,11 @@ namespace SpriteMapEditor
currentSprite = sprites[0];
Console.WriteLine(currentSprite.Bounds);
spriteList.DataSource = sprites;
spriteList.DisplayMember = "Name";
spriteList.ValueMember = "Bounds";
LoadSpriteEditorValues();
Console.WriteLine(currentSprite.Bounds);
}
private void loadSpriteSheetButton_Click(object sender, EventArgs e)
@@ -339,5 +336,37 @@ namespace SpriteMapEditor
{
movingWithMouse = false;
}
private void spriteList_MouseDown(object sender, MouseEventArgs e)
{
if (rearrangingSprites)
{
if (spriteList.SelectedItem == null)
return;
spriteList.DoDragDrop(spriteList.SelectedItem, DragDropEffects.Move);
}
}
private void spriteList_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void spriteList_DragDrop(object sender, DragEventArgs e)
{
Point point = spriteList.PointToClient(new Point(e.X, e.Y));
int index = spriteList.IndexFromPoint(point);
if (index < 0)
index = spriteList.Items.Count - 1;
Sprite data = (Sprite)spriteList.SelectedItem;
sprites.Remove(data);
sprites.Insert(index, data);
}
private void rearrangeCheckBox_CheckedChanged(object sender, EventArgs e)
{
rearrangingSprites = rearrangeCheckBox.Checked;
spriteList.AllowDrop = rearrangeCheckBox.Checked;
}
}
}