Skip to content

Commit

Permalink
Fixed wrong component position when deselecting it after a rotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
vfauth committed Feb 7, 2018
1 parent 73938fd commit 475000c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions PPcurry/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public void SetName(string name)

public void SetIsSelected(bool isSelected)
{
if (isSelected != this.IsSelected)
if (isSelected != this.IsSelected) // Check whether the selected state has changed
{
this.IsSelected = isSelected;
double thickness = Properties.Settings.Default.ComponentBorderThickness;
if (isSelected)
if (isSelected) // The component is selected
{
this.BoardGrid.SetSelectedComponent(this);
this.BorderThickness = new Thickness(thickness);
Expand All @@ -99,7 +99,7 @@ public void SetIsSelected(bool isSelected)
this.Height += thickness * 2;
this.SetComponentPosition(new Point(ComponentPosition.X - thickness, ComponentPosition.Y - thickness));
}
else
else // The component is unselected
{
this.BoardGrid.SetSelectedComponent(null);
this.BorderThickness = new Thickness(0);
Expand All @@ -110,7 +110,6 @@ public void SetIsSelected(bool isSelected)
this.SetComponentPosition(new Point(ComponentPosition.X + thickness, ComponentPosition.Y + thickness));
}
UpdateSize();
UpdatePosition();
}
}

Expand Down Expand Up @@ -160,12 +159,7 @@ public Component(Point position, BoardGrid boardGrid, XElement xmlElement)
boardGrid.AddComponent(this); // Add the component

// Rotation
Rotation = new RotateTransform(0)
{
CenterX = this.Width / 2 + Properties.Settings.Default.ComponentBorderThickness, // To make the component rotate around its center
CenterY = this.Height / 2 + Properties.Settings.Default.ComponentBorderThickness
};
this.RenderTransform = Rotation;
this.Rotation = new RotateTransform(0);

// Anchors
IEnumerable<XElement> xmlAnchors = xmlElement.Element("anchors").Elements("anchor"); // Get all the anchors present in the XML
Expand Down Expand Up @@ -201,6 +195,8 @@ public void RotateLeft()
{
this.Rotation.Angle += 360;
}
this.Rotation.CenterX = this.ComponentSize.X / 2; // To make the component rotate around its center
this.Rotation.CenterY = this.ComponentSize.Y / 2;
this.RenderTransform = this.Rotation;
TransformAnchorsAfterRotation(-90);
ConnectAnchors(); // Reconnect anchors
Expand All @@ -216,6 +212,8 @@ public void RotateRight()
{
this.Rotation.Angle -= 360;
}
this.Rotation.CenterX = this.ComponentSize.X / 2; // To make the component rotate around its center
this.Rotation.CenterY = this.ComponentSize.Y / 2;
this.RenderTransform = this.Rotation;
TransformAnchorsAfterRotation(90);
ConnectAnchors(); // Reconnect anchors
Expand Down Expand Up @@ -260,10 +258,13 @@ public void UpdatePosition()
/// </summary>
public void UpdateSize()
{
this.ImageSize.X = this.Width - this.BorderThickness.Left - this.BorderThickness.Right;
this.ImageSize.Y = this.Height - this.BorderThickness.Top - this.BorderThickness.Bottom;
this.ComponentSize.X = this.Width;
this.ComponentSize.Y = this.Height;

// Reapply the rotation with the new center coordinates
this.Rotation.CenterX = this.ComponentSize.X / 2;
this.Rotation.CenterY = this.ComponentSize.Y / 2;
this.RenderTransform = this.Rotation;
}

/// <summary>
Expand Down

0 comments on commit 475000c

Please sign in to comment.