mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-04 14:11:38 +12:00
Change SetImage method to allow centering image to cursor
This commit is contained in:
parent
8469f3065d
commit
59f0b43c18
|
@ -34,12 +34,7 @@ public class ImageDrawingShape : BaseDrawingShape
|
|||
|
||||
public Image Image { get; private set; }
|
||||
|
||||
public void SetImage(Image img)
|
||||
{
|
||||
SetImage(img, Rectangle.Location);
|
||||
}
|
||||
|
||||
public void SetImage(Image img, Point pos)
|
||||
public void SetImage(Image img, bool centerImage)
|
||||
{
|
||||
Dispose();
|
||||
|
||||
|
@ -47,11 +42,23 @@ public void SetImage(Image img, Point pos)
|
|||
|
||||
if (Image != null)
|
||||
{
|
||||
Rectangle = new Rectangle(pos, Image.Size);
|
||||
Point location;
|
||||
Size size = Image.Size;
|
||||
|
||||
if (centerImage)
|
||||
{
|
||||
location = new Point(Rectangle.X - size.Width / 2, Rectangle.Y - size.Height / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
location = Rectangle.Location;
|
||||
}
|
||||
|
||||
Rectangle = new Rectangle(location, size);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenImageDialog()
|
||||
public void OpenImageDialog(bool centerImage)
|
||||
{
|
||||
Manager.IsMoving = false;
|
||||
|
||||
|
@ -63,7 +70,7 @@ public void OpenImageDialog()
|
|||
|
||||
if (img != null)
|
||||
{
|
||||
SetImage(img);
|
||||
SetImage(img, centerImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,14 +83,16 @@ public override void OnDraw(Graphics g)
|
|||
}
|
||||
}
|
||||
|
||||
public override void OnCreated()
|
||||
public override void OnCreating()
|
||||
{
|
||||
OpenImageDialog();
|
||||
StartPosition = EndPosition = InputManager.MousePosition0Based;
|
||||
|
||||
OpenImageDialog(true);
|
||||
}
|
||||
|
||||
public override void OnDoubleClicked()
|
||||
{
|
||||
OpenImageDialog();
|
||||
OpenImageDialog(false);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
|
|
@ -35,6 +35,7 @@ public class StepDrawingShape : BaseDrawingShape
|
|||
private const int DefaultSize = 30;
|
||||
|
||||
public override ShapeType ShapeType { get; } = ShapeType.DrawingStep;
|
||||
|
||||
public override bool ShowResizeNodes { get; } = false;
|
||||
|
||||
public int Number { get; set; }
|
||||
|
|
|
@ -1700,9 +1700,8 @@ private void AddImageFromClipboard()
|
|||
{
|
||||
CurrentShapeType = ShapeType.DrawingImage;
|
||||
ImageDrawingShape shape = (ImageDrawingShape)CreateShape(ShapeType.DrawingImage);
|
||||
Point pos = InputManager.MousePosition0Based;
|
||||
Point shapePos = new Point(pos.X - img.Width / 2, pos.Y - img.Height / 2);
|
||||
shape.SetImage(img, shapePos);
|
||||
shape.StartPosition = shape.EndPosition = InputManager.MousePosition0Based;
|
||||
shape.SetImage(img, true);
|
||||
AddShape(shape);
|
||||
SelectCurrentShape();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue