Added centerText parameter to SetText method

This commit is contained in:
Jaex 2016-08-23 21:02:52 +03:00
parent f432754b87
commit a3b8eb88a8
3 changed files with 20 additions and 7 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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();
}