mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-03 19:54:13 +13:00
Added proportional resizing with resize node support
This commit is contained in:
parent
1ba381e251
commit
8d41315c47
5 changed files with 54 additions and 11 deletions
|
@ -100,6 +100,7 @@ private set
|
||||||
protected AnnotationOptions AnnotationOptions => Manager.Options.AnnotationOptions;
|
protected AnnotationOptions AnnotationOptions => Manager.Options.AnnotationOptions;
|
||||||
|
|
||||||
private Point tempNodePos, tempStartPos, tempEndPos;
|
private Point tempNodePos, tempStartPos, tempEndPos;
|
||||||
|
private Rectangle tempRectangle;
|
||||||
|
|
||||||
public virtual bool Intersects(Point position)
|
public virtual bool Intersects(Point position)
|
||||||
{
|
{
|
||||||
|
@ -167,7 +168,10 @@ public virtual void OnCreating()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnCreated() { }
|
public virtual void OnCreated()
|
||||||
|
{
|
||||||
|
InitialSize = Rectangle.Size;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void OnMoving() { }
|
public virtual void OnMoving() { }
|
||||||
|
|
||||||
|
@ -256,8 +260,9 @@ public virtual void OnNodeUpdate()
|
||||||
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
||||||
{
|
{
|
||||||
tempNodePos = node.Position;
|
tempNodePos = node.Position;
|
||||||
tempStartPos = Rectangle.Location;
|
tempStartPos = StartPosition;
|
||||||
tempEndPos = new Point(Rectangle.X + Rectangle.Width - 1, Rectangle.Y + Rectangle.Height - 1);
|
tempEndPos = EndPosition;
|
||||||
|
tempRectangle = Rectangle;
|
||||||
|
|
||||||
OnResizing();
|
OnResizing();
|
||||||
}
|
}
|
||||||
|
@ -267,6 +272,7 @@ public virtual void OnNodeUpdate()
|
||||||
tempStartPos.Offset(InputManager.MouseVelocity);
|
tempStartPos.Offset(InputManager.MouseVelocity);
|
||||||
tempEndPos.Offset(InputManager.MouseVelocity);
|
tempEndPos.Offset(InputManager.MouseVelocity);
|
||||||
tempNodePos.Offset(InputManager.MouseVelocity);
|
tempNodePos.Offset(InputManager.MouseVelocity);
|
||||||
|
tempRectangle.LocationOffset(InputManager.MouseVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point pos = InputManager.ClientMousePosition;
|
Point pos = InputManager.ClientMousePosition;
|
||||||
|
@ -313,24 +319,54 @@ public virtual void OnNodeUpdate()
|
||||||
if (Manager.IsProportionalResizing)
|
if (Manager.IsProportionalResizing)
|
||||||
{
|
{
|
||||||
double ratio = Math.Min(Rectangle.Width / (double)InitialSize.Width, Rectangle.Height / (double)InitialSize.Height);
|
double ratio = Math.Min(Rectangle.Width / (double)InitialSize.Width, Rectangle.Height / (double)InitialSize.Height);
|
||||||
int width = (int)Math.Round(ratio * InitialSize.Width);
|
int newWidth = (int)Math.Round(InitialSize.Width * ratio);
|
||||||
int height = (int)Math.Round(ratio * InitialSize.Height);
|
int newHeight = (int)Math.Round(InitialSize.Height * ratio);
|
||||||
|
|
||||||
|
Point anchor = new Point();
|
||||||
|
|
||||||
|
switch (nodePosition)
|
||||||
|
{
|
||||||
|
case NodePosition.TopLeft:
|
||||||
|
case NodePosition.Left:
|
||||||
|
case NodePosition.BottomLeft:
|
||||||
|
anchor.X = tempRectangle.Right - 1;
|
||||||
|
break;
|
||||||
|
case NodePosition.TopRight:
|
||||||
|
case NodePosition.Right:
|
||||||
|
case NodePosition.BottomRight:
|
||||||
|
anchor.X = tempRectangle.X;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (nodePosition)
|
||||||
|
{
|
||||||
|
case NodePosition.TopLeft:
|
||||||
|
case NodePosition.Top:
|
||||||
|
case NodePosition.TopRight:
|
||||||
|
anchor.Y = tempRectangle.Bottom - 1;
|
||||||
|
break;
|
||||||
|
case NodePosition.BottomLeft:
|
||||||
|
case NodePosition.Bottom:
|
||||||
|
case NodePosition.BottomRight:
|
||||||
|
anchor.Y = tempRectangle.Y;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle newRect = Rectangle;
|
Rectangle newRect = Rectangle;
|
||||||
|
|
||||||
if (pos.X < tempStartPos.X)
|
if (pos.X < anchor.X)
|
||||||
{
|
{
|
||||||
newRect.X = newRect.Right - width;
|
newRect.X = newRect.Right - newWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
newRect.Width = width;
|
newRect.Width = newWidth;
|
||||||
|
|
||||||
if (pos.Y < tempStartPos.Y)
|
if (pos.Y < anchor.Y)
|
||||||
{
|
{
|
||||||
newRect.Y = newRect.Bottom - height;
|
newRect.Y = newRect.Bottom - newHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
newRect.Height = height;
|
newRect.Height = newHeight;
|
||||||
|
|
||||||
Rectangle = newRect;
|
Rectangle = newRect;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ public override void OnCreating()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
OnCreated();
|
||||||
ShowNodes();
|
ShowNodes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,10 @@ public override void OnCreated()
|
||||||
{
|
{
|
||||||
Remove();
|
Remove();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base.OnCreated();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
|
|
|
@ -111,6 +111,7 @@ public override void OnCreating()
|
||||||
public override void OnCreated()
|
public override void OnCreated()
|
||||||
{
|
{
|
||||||
AutoSize(true);
|
AutoSize(true);
|
||||||
|
base.OnCreated();
|
||||||
ShowNodes();
|
ShowNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,7 @@ public virtual void OnDrawFinal(Graphics g, Bitmap bmp)
|
||||||
|
|
||||||
public override void OnCreated()
|
public override void OnCreated()
|
||||||
{
|
{
|
||||||
|
base.OnCreated();
|
||||||
CacheEffect();
|
CacheEffect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue