In text tool automatically resize rectangle to fit text so won't need to drag rectangle, when text input box is canceled remove shape

This commit is contained in:
Jaex 2016-08-24 01:04:48 +03:00
parent a3b8eb88a8
commit b454f2e7f7
3 changed files with 25 additions and 12 deletions

View file

@ -69,17 +69,28 @@ public override void OnDraw(Graphics g)
}
}
public override void OnCreated()
public override void OnCreating()
{
UpdateText();
StartPosition = EndPosition = InputManager.MousePosition0Based;
ShowTextInputBox();
if (string.IsNullOrEmpty(Text))
{
Remove();
}
else
{
AutoSize(true);
}
}
public override void OnDoubleClicked()
{
UpdateText();
ShowTextInputBox();
}
private void UpdateText()
private void ShowTextInputBox()
{
Manager.PauseForm();
@ -93,21 +104,20 @@ private void UpdateText()
Manager.ResumeForm();
}
public void SetTextWithAutoSize(string text, bool centerText)
public void AutoSize(bool center)
{
Size size;
using (Font font = new Font(TextOptions.Font, TextOptions.Size, TextOptions.Style))
{
size = Helpers.MeasureText(text, font).Offset(10, 20);
size = Helpers.MeasureText(Text, font).Offset(10, 15);
}
Point location;
if (centerText)
if (center)
{
Point pos = InputManager.MousePosition0Based;
location = new Point(pos.X - size.Width / 2, pos.Y - size.Height / 2);
location = new Point(Rectangle.X - size.Width / 2, Rectangle.Y - size.Height / 2);
}
else
{
@ -115,7 +125,6 @@ public void SetTextWithAutoSize(string text, bool centerText)
}
Rectangle = new Rectangle(location, size);
Text = text;
}
}
}

View file

@ -1406,7 +1406,9 @@ private void CheckHover()
case ShapeType.DrawingFreehand:
case ShapeType.DrawingLine:
case ShapeType.DrawingArrow:
case ShapeType.DrawingText:
case ShapeType.DrawingStep:
case ShapeType.DrawingImage:
return;
}
@ -1714,7 +1716,9 @@ private void PasteFromClipboard()
{
CurrentShapeType = ShapeType.DrawingText;
TextDrawingShape shape = (TextDrawingShape)CreateShape(ShapeType.DrawingText);
shape.SetTextWithAutoSize(text.Trim(), true);
shape.StartPosition = shape.EndPosition = InputManager.MousePosition0Based;
shape.Text = text.Trim();
shape.AutoSize(true);
AddShape(shape);
SelectCurrentShape();
}

View file

@ -30,7 +30,7 @@ namespace ShareX.ScreenCaptureLib
public class TextDrawingOptions
{
public string Font { get; set; } = "Arial";
public int Size { get; set; } = 20;
public int Size { get; set; } = 18;
public Color Color { get; set; } = Color.White;
public bool Bold { get; set; } = false;
public bool Italic { get; set; } = false;