mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-02 21:20:28 +12:00
Added centerText parameter to SetText method
This commit is contained in:
parent
f432754b87
commit
a3b8eb88a8
|
@ -158,7 +158,12 @@ public static Point Add(this Point point, Point offset)
|
|||
|
||||
public static Size Offset(this Size size, int offset)
|
||||
{
|
||||
return new Size(size.Width + offset, size.Height + offset);
|
||||
return size.Offset(offset, offset);
|
||||
}
|
||||
|
||||
public static Size Offset(this Size size, int width, int height)
|
||||
{
|
||||
return new Size(size.Width + width, size.Height + height);
|
||||
}
|
||||
|
||||
public static Rectangle Offset(this Rectangle rect, int offset)
|
||||
|
|
|
@ -93,18 +93,26 @@ private void UpdateText()
|
|||
Manager.ResumeForm();
|
||||
}
|
||||
|
||||
public void SetTextWithAutoSize(string text)
|
||||
public void SetTextWithAutoSize(string text, bool centerText)
|
||||
{
|
||||
Point pos = InputManager.MousePosition0Based;
|
||||
|
||||
Size size;
|
||||
|
||||
using (Font font = new Font(TextOptions.Font, TextOptions.Size, TextOptions.Style))
|
||||
{
|
||||
size = Helpers.MeasureText(text, font).Offset(30);
|
||||
size = Helpers.MeasureText(text, font).Offset(10, 20);
|
||||
}
|
||||
|
||||
Point location = new Point(pos.X - size.Width / 2, pos.Y - size.Height / 2);
|
||||
Point location;
|
||||
|
||||
if (centerText)
|
||||
{
|
||||
Point pos = InputManager.MousePosition0Based;
|
||||
location = new Point(pos.X - size.Width / 2, pos.Y - size.Height / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
location = Rectangle.Location;
|
||||
}
|
||||
|
||||
Rectangle = new Rectangle(location, size);
|
||||
Text = text;
|
||||
|
|
|
@ -1714,7 +1714,7 @@ private void PasteFromClipboard()
|
|||
{
|
||||
CurrentShapeType = ShapeType.DrawingText;
|
||||
TextDrawingShape shape = (TextDrawingShape)CreateShape(ShapeType.DrawingText);
|
||||
shape.SetTextWithAutoSize(text.Trim());
|
||||
shape.SetTextWithAutoSize(text.Trim(), true);
|
||||
AddShape(shape);
|
||||
SelectCurrentShape();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue