2016-05-20 10:13:19 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
using ShareX.HelpersLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
2016-05-23 07:11:34 +12:00
|
|
|
|
using System.Drawing.Text;
|
2016-05-20 10:13:19 +12:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2016-05-20 11:53:45 +12:00
|
|
|
|
using System.Threading;
|
2016-05-20 10:13:19 +12:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
|
|
|
|
{
|
2016-05-24 04:34:41 +12:00
|
|
|
|
public class TextDrawingShape : RectangleDrawingShape
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
|
|
|
|
public override ShapeType ShapeType { get; } = ShapeType.DrawingText;
|
|
|
|
|
|
2016-05-21 03:45:55 +12:00
|
|
|
|
public string Text { get; set; }
|
2016-05-21 08:19:07 +12:00
|
|
|
|
public TextDrawingOptions Options { get; set; }
|
2016-05-20 10:13:19 +12:00
|
|
|
|
|
2016-05-21 05:01:00 +12:00
|
|
|
|
public override void UpdateShapeConfig()
|
|
|
|
|
{
|
2016-05-21 05:34:45 +12:00
|
|
|
|
Options = AnnotationOptions.TextOptions.Copy();
|
2016-05-21 09:09:09 +12:00
|
|
|
|
BorderColor = AnnotationOptions.TextBorderColor;
|
|
|
|
|
BorderSize = AnnotationOptions.TextBorderSize;
|
|
|
|
|
FillColor = AnnotationOptions.TextFillColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ApplyShapeConfig()
|
|
|
|
|
{
|
|
|
|
|
AnnotationOptions.TextOptions = Options;
|
|
|
|
|
AnnotationOptions.TextBorderColor = BorderColor;
|
|
|
|
|
AnnotationOptions.TextBorderSize = BorderSize;
|
|
|
|
|
AnnotationOptions.TextFillColor = FillColor;
|
2016-05-21 05:01:00 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-22 00:26:49 +12:00
|
|
|
|
public override void OnDraw(Graphics g)
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
2016-05-24 04:34:41 +12:00
|
|
|
|
base.OnDraw(g);
|
2016-05-21 09:09:31 +12:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Text) && Rectangle.Width > 10 && Rectangle.Height > 10)
|
|
|
|
|
{
|
|
|
|
|
using (Font font = new Font(Options.Font, Options.Size, Options.Style))
|
|
|
|
|
using (Brush textBrush = new SolidBrush(Options.Color))
|
|
|
|
|
using (StringFormat sf = new StringFormat { Alignment = Options.AlignmentHorizontal, LineAlignment = Options.AlignmentVertical })
|
|
|
|
|
{
|
2016-05-23 07:11:34 +12:00
|
|
|
|
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
2016-05-21 09:09:31 +12:00
|
|
|
|
g.DrawString(Text, font, textBrush, Rectangle, sf);
|
2016-05-23 07:11:34 +12:00
|
|
|
|
g.TextRenderingHint = TextRenderingHint.SystemDefault;
|
2016-05-21 09:09:31 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-22 00:26:49 +12:00
|
|
|
|
public override void OnShapeCreated()
|
|
|
|
|
{
|
|
|
|
|
UpdateText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnShapeDoubleClicked()
|
|
|
|
|
{
|
|
|
|
|
UpdateText();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-20 10:13:19 +12:00
|
|
|
|
private void UpdateText()
|
|
|
|
|
{
|
2016-05-20 11:53:45 +12:00
|
|
|
|
Manager.PauseForm();
|
|
|
|
|
|
2016-05-21 03:45:55 +12:00
|
|
|
|
using (TextDrawingInputBox inputBox = new TextDrawingInputBox(Text, Options))
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
2016-05-21 02:11:48 +12:00
|
|
|
|
inputBox.ShowDialog();
|
2016-05-21 03:45:55 +12:00
|
|
|
|
Text = inputBox.InputText;
|
2016-05-21 09:09:09 +12:00
|
|
|
|
ApplyShapeConfig();
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
2016-05-20 11:53:45 +12:00
|
|
|
|
|
|
|
|
|
Manager.ResumeForm();
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|