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;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
public class TextDrawingShape : BaseDrawingShape
|
|
|
|
|
{
|
|
|
|
|
public override ShapeType ShapeType { get; } = ShapeType.DrawingText;
|
|
|
|
|
|
|
|
|
|
public string Text { get; set; }
|
2016-05-20 11:53:45 +12:00
|
|
|
|
public string TextFont { get; set; } = "Verdana";
|
2016-05-20 10:57:49 +12:00
|
|
|
|
public int TextSize { get; set; } = 18;
|
2016-05-20 11:53:45 +12:00
|
|
|
|
public bool TextBold { get; set; }
|
|
|
|
|
public bool TextItalic { get; set; }
|
|
|
|
|
public bool TextUnderline { get; set; }
|
2016-05-20 10:13:19 +12:00
|
|
|
|
|
|
|
|
|
public override void Draw(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
base.Draw(g);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Text))
|
|
|
|
|
{
|
|
|
|
|
DrawText(g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void DrawFinal(Graphics g, Bitmap bmp)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(Text))
|
|
|
|
|
{
|
|
|
|
|
DrawText(g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawText(Graphics g)
|
|
|
|
|
{
|
2016-05-20 11:53:45 +12:00
|
|
|
|
FontStyle fontStyle = FontStyle.Regular;
|
|
|
|
|
|
|
|
|
|
if (TextBold)
|
|
|
|
|
{
|
|
|
|
|
fontStyle |= FontStyle.Bold;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TextItalic)
|
|
|
|
|
{
|
|
|
|
|
fontStyle |= FontStyle.Italic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TextUnderline)
|
|
|
|
|
{
|
|
|
|
|
fontStyle |= FontStyle.Underline;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (Font font = new Font(TextFont, TextSize, fontStyle))
|
2016-05-20 10:13:19 +12:00
|
|
|
|
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
|
|
|
|
|
{
|
2016-05-20 10:30:20 +12:00
|
|
|
|
using (Brush textBrush = new SolidBrush(BorderColor))
|
|
|
|
|
{
|
|
|
|
|
g.DrawString(Text, font, textBrush, Rectangle, sf);
|
|
|
|
|
}
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateText()
|
|
|
|
|
{
|
2016-05-20 11:53:45 +12:00
|
|
|
|
Manager.PauseForm();
|
|
|
|
|
|
|
|
|
|
using (TextDrawingInputBox inputBox = new TextDrawingInputBox(Text, TextFont, BorderColor, TextSize))
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
2016-05-20 10:57:49 +12:00
|
|
|
|
if (inputBox.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
Text = inputBox.InputText;
|
|
|
|
|
BorderColor = inputBox.TextColor;
|
|
|
|
|
TextSize = inputBox.TextSize;
|
2016-05-20 11:53:45 +12:00
|
|
|
|
TextBold = inputBox.TextBold;
|
|
|
|
|
TextItalic = inputBox.TextItalic;
|
|
|
|
|
TextUnderline = inputBox.TextUnderline;
|
2016-05-20 10:57:49 +12:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnShapeCreated()
|
|
|
|
|
{
|
|
|
|
|
UpdateText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnShapeDoubleClicked()
|
|
|
|
|
{
|
|
|
|
|
UpdateText();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|