mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Added centerText parameter to SetText method
This commit is contained in:
parent
f432754b87
commit
a3b8eb88a8
3 changed files with 20 additions and 7 deletions
|
@ -158,7 +158,12 @@ public static Point Add(this Point point, Point offset)
|
||||||
|
|
||||||
public static Size Offset(this Size size, int 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)
|
public static Rectangle Offset(this Rectangle rect, int offset)
|
||||||
|
|
|
@ -93,18 +93,26 @@ private void UpdateText()
|
||||||
Manager.ResumeForm();
|
Manager.ResumeForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTextWithAutoSize(string text)
|
public void SetTextWithAutoSize(string text, bool centerText)
|
||||||
{
|
{
|
||||||
Point pos = InputManager.MousePosition0Based;
|
|
||||||
|
|
||||||
Size size;
|
Size size;
|
||||||
|
|
||||||
using (Font font = new Font(TextOptions.Font, TextOptions.Size, TextOptions.Style))
|
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);
|
Rectangle = new Rectangle(location, size);
|
||||||
Text = text;
|
Text = text;
|
||||||
|
|
|
@ -1714,7 +1714,7 @@ private void PasteFromClipboard()
|
||||||
{
|
{
|
||||||
CurrentShapeType = ShapeType.DrawingText;
|
CurrentShapeType = ShapeType.DrawingText;
|
||||||
TextDrawingShape shape = (TextDrawingShape)CreateShape(ShapeType.DrawingText);
|
TextDrawingShape shape = (TextDrawingShape)CreateShape(ShapeType.DrawingText);
|
||||||
shape.SetTextWithAutoSize(text.Trim());
|
shape.SetTextWithAutoSize(text.Trim(), true);
|
||||||
AddShape(shape);
|
AddShape(shape);
|
||||||
SelectCurrentShape();
|
SelectCurrentShape();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue