Update drag info
This commit is contained in:
parent
a415e89cd0
commit
7dea96b266
7
SpriteLibrary/SpriteEntryForm.Designer.cs
generated
7
SpriteLibrary/SpriteEntryForm.Designer.cs
generated
@ -81,6 +81,9 @@
|
|||||||
this.pbImageField.Size = new System.Drawing.Size(213, 306);
|
this.pbImageField.Size = new System.Drawing.Size(213, 306);
|
||||||
this.pbImageField.TabIndex = 0;
|
this.pbImageField.TabIndex = 0;
|
||||||
this.pbImageField.TabStop = false;
|
this.pbImageField.TabStop = false;
|
||||||
|
this.pbImageField.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbImageField_MouseDown);
|
||||||
|
this.pbImageField.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pbImageField_MouseMove);
|
||||||
|
this.pbImageField.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pbImageField_MouseUp);
|
||||||
//
|
//
|
||||||
// cbStartingImage
|
// cbStartingImage
|
||||||
//
|
//
|
||||||
@ -105,9 +108,9 @@
|
|||||||
this.lblChosenArea.AutoSize = true;
|
this.lblChosenArea.AutoSize = true;
|
||||||
this.lblChosenArea.Location = new System.Drawing.Point(129, 44);
|
this.lblChosenArea.Location = new System.Drawing.Point(129, 44);
|
||||||
this.lblChosenArea.Name = "lblChosenArea";
|
this.lblChosenArea.Name = "lblChosenArea";
|
||||||
this.lblChosenArea.Size = new System.Drawing.Size(46, 17);
|
this.lblChosenArea.Size = new System.Drawing.Size(86, 17);
|
||||||
this.lblChosenArea.TabIndex = 3;
|
this.lblChosenArea.TabIndex = 3;
|
||||||
this.lblChosenArea.Text = "label2";
|
this.lblChosenArea.Text = "ChosenArea";
|
||||||
//
|
//
|
||||||
// tbNumFrames
|
// tbNumFrames
|
||||||
//
|
//
|
||||||
|
@ -27,6 +27,10 @@ namespace SpriteLibrary
|
|||||||
int CurrentSIIndex = -1; //The information item we are editing. -1 means it is a new one.
|
int CurrentSIIndex = -1; //The information item we are editing. -1 means it is a new one.
|
||||||
int CurrentSIAnimation = -1;
|
int CurrentSIAnimation = -1;
|
||||||
|
|
||||||
|
bool WeAreDragging = false;
|
||||||
|
Point DragStart = new Point(-1, -1);
|
||||||
|
Rectangle ChosenArea = new Rectangle(1,1,100,100);
|
||||||
|
|
||||||
internal SpriteEntryForm(SpriteDatabase theDatabase, List<SpriteInfo> ListToWorkOn, Size GridSize)
|
internal SpriteEntryForm(SpriteDatabase theDatabase, List<SpriteInfo> ListToWorkOn, Size GridSize)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -109,9 +113,15 @@ namespace SpriteLibrary
|
|||||||
if (!TCTabPages.TabPages.Contains(tpMirrorRotate))
|
if (!TCTabPages.TabPages.Contains(tpMirrorRotate))
|
||||||
TCTabPages.TabPages.Add(tpMirrorRotate);
|
TCTabPages.TabPages.Add(tpMirrorRotate);
|
||||||
}
|
}
|
||||||
|
UpdateChosenAreaLabel();
|
||||||
ResumeLayout();
|
ResumeLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateChosenAreaLabel()
|
||||||
|
{
|
||||||
|
lblChosenArea.Text = ChosenArea.X + "," + ChosenArea.Y + "," + ChosenArea.Width + "," + ChosenArea.Height;
|
||||||
|
}
|
||||||
|
|
||||||
private void SetUpEmptyInfo()
|
private void SetUpEmptyInfo()
|
||||||
{
|
{
|
||||||
TempInformation = new SpriteInfo();
|
TempInformation = new SpriteInfo();
|
||||||
@ -176,9 +186,63 @@ namespace SpriteLibrary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Given two locations that we have clicked on, find the area we have selected
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Start"></param>
|
||||||
|
/// <param name="End"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private Rectangle AreaFromGridPoints(Point Start, Point End)
|
||||||
|
{
|
||||||
|
//Get the points translated from locations on the picturebox
|
||||||
|
Point OneImagePoint = MyController.ReturnPointAdjustedForImage(Start);
|
||||||
|
Point TwoImagePoint = MyController.ReturnPointAdjustedForImage(End);
|
||||||
|
//Now, shrink them to figure out which grid points we have chosen
|
||||||
|
Point OneGridPoint = new Point(OneImagePoint.X / SnapGridSize.Width, OneImagePoint.Y / SnapGridSize.Height);
|
||||||
|
Point TwoGridPoint = new Point(TwoImagePoint.X / SnapGridSize.Width, TwoImagePoint.Y / SnapGridSize.Height);
|
||||||
|
//Find the top-left point and the bottom-right point
|
||||||
|
Point StartGridPoint = new Point(Math.Min(OneGridPoint.X, TwoGridPoint.X), Math.Min(OneGridPoint.Y, TwoGridPoint.Y));
|
||||||
|
Point EndGridPoint = new Point(Math.Max(OneGridPoint.X, TwoGridPoint.X), Math.Max(OneGridPoint.Y, TwoGridPoint.Y));
|
||||||
|
//Translate them back into points on the image
|
||||||
|
Point ReturnSPoint = new Point(StartGridPoint.X * SnapGridSize.Width, StartGridPoint.Y * SnapGridSize.Height);
|
||||||
|
Point ReturnEPoint = new Point((EndGridPoint.X +1) * SnapGridSize.Width, (EndGridPoint.Y +1) * SnapGridSize.Height);
|
||||||
|
//Change it into a rectangle and return it
|
||||||
|
Rectangle ReturnRec = new Rectangle(ReturnSPoint.X, ReturnSPoint.Y, ReturnEPoint.X - ReturnSPoint.X, ReturnEPoint.Y - ReturnSPoint.Y);
|
||||||
|
return ReturnRec;
|
||||||
|
}
|
||||||
|
|
||||||
private void SpriteEntryForm_FormClosing(object sender, FormClosingEventArgs e)
|
private void SpriteEntryForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
myDatabase.Save(); //try saving the file
|
myDatabase.Save(); //try saving the file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void pbImageField_MouseMove(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
//If we are dragging, process the dragging
|
||||||
|
if (WeAreDragging)
|
||||||
|
{
|
||||||
|
ChosenArea = AreaFromGridPoints(DragStart, e.Location);
|
||||||
|
UpdateChosenAreaLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pbImageField_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
//When the mouse goes down, we note that we are trying to drag
|
||||||
|
WeAreDragging = true;
|
||||||
|
DragStart = e.Location;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pbImageField_MouseUp(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
//When the mouse goes up, stop dragging and update
|
||||||
|
if(WeAreDragging)
|
||||||
|
{
|
||||||
|
ChosenArea = AreaFromGridPoints(DragStart, e.Location);
|
||||||
|
UpdateChosenAreaLabel();
|
||||||
|
}
|
||||||
|
WeAreDragging = false;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user