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
|
2020-02-05 20:19:48 +13:00
|
|
|
|
Copyright (c) 2007-2020 ShareX Team
|
2016-05-20 10:13:19 +12:00
|
|
|
|
|
|
|
|
|
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.Drawing;
|
2016-05-23 07:11:34 +12:00
|
|
|
|
using System.Drawing.Text;
|
2017-10-30 20:43:21 +13:00
|
|
|
|
using System.Windows.Forms;
|
2016-05-20 10:13:19 +12:00
|
|
|
|
|
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
|
|
|
|
{
|
2016-05-24 04:34:41 +12:00
|
|
|
|
public class TextDrawingShape : RectangleDrawingShape
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
2017-02-16 13:49:13 +13:00
|
|
|
|
public override ShapeType ShapeType { get; } = ShapeType.DrawingTextBackground;
|
2016-05-20 10:13:19 +12:00
|
|
|
|
|
2016-05-21 03:45:55 +12:00
|
|
|
|
public string Text { get; set; }
|
2016-08-24 05:33:48 +12:00
|
|
|
|
public TextDrawingOptions TextOptions { get; set; }
|
2018-06-19 01:53:59 +12:00
|
|
|
|
public virtual bool SupportGradient { get; }
|
2016-05-20 10:13:19 +12:00
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public override void OnConfigLoad()
|
2016-05-21 05:01:00 +12:00
|
|
|
|
{
|
2016-08-24 05:33:48 +12:00
|
|
|
|
TextOptions = AnnotationOptions.TextOptions.Copy();
|
2016-05-21 09:09:09 +12:00
|
|
|
|
BorderColor = AnnotationOptions.TextBorderColor;
|
|
|
|
|
BorderSize = AnnotationOptions.TextBorderSize;
|
|
|
|
|
FillColor = AnnotationOptions.TextFillColor;
|
2016-12-01 04:17:12 +13:00
|
|
|
|
CornerRadius = AnnotationOptions.DrawingCornerRadius;
|
2016-11-30 10:11:39 +13:00
|
|
|
|
Shadow = AnnotationOptions.Shadow;
|
2018-01-31 06:14:28 +13:00
|
|
|
|
ShadowColor = AnnotationOptions.ShadowColor;
|
|
|
|
|
ShadowOffset = AnnotationOptions.ShadowOffset;
|
2016-05-21 09:09:09 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public override void OnConfigSave()
|
2016-05-21 09:09:09 +12:00
|
|
|
|
{
|
2016-08-24 05:33:48 +12:00
|
|
|
|
AnnotationOptions.TextOptions = TextOptions;
|
2016-05-21 09:09:09 +12:00
|
|
|
|
AnnotationOptions.TextBorderColor = BorderColor;
|
|
|
|
|
AnnotationOptions.TextBorderSize = BorderSize;
|
|
|
|
|
AnnotationOptions.TextFillColor = FillColor;
|
2016-12-01 04:17:12 +13:00
|
|
|
|
AnnotationOptions.DrawingCornerRadius = CornerRadius;
|
2016-11-30 10:11:39 +13:00
|
|
|
|
AnnotationOptions.Shadow = Shadow;
|
2018-01-31 06:14:28 +13:00
|
|
|
|
AnnotationOptions.ShadowColor = ShadowColor;
|
|
|
|
|
AnnotationOptions.ShadowOffset = ShadowOffset;
|
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
|
|
|
|
{
|
2017-02-16 13:49:13 +13:00
|
|
|
|
DrawRectangle(g);
|
|
|
|
|
DrawText(g);
|
2016-11-30 09:06:54 +13:00
|
|
|
|
}
|
2016-05-21 09:09:31 +12:00
|
|
|
|
|
2016-11-30 09:06:54 +13:00
|
|
|
|
protected void DrawText(Graphics g)
|
|
|
|
|
{
|
2016-11-30 07:48:19 +13:00
|
|
|
|
if (Shadow)
|
|
|
|
|
{
|
|
|
|
|
DrawText(g, Text, ShadowColor, TextOptions, Rectangle.LocationOffset(ShadowOffset));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 09:06:54 +13:00
|
|
|
|
DrawText(g, Text, TextOptions, Rectangle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void DrawText(Graphics g, string text, TextDrawingOptions options, Rectangle rect)
|
|
|
|
|
{
|
|
|
|
|
DrawText(g, text, options.Color, options, rect);
|
2016-08-25 07:18:54 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 07:48:19 +13:00
|
|
|
|
protected void DrawText(Graphics g, string text, Color textColor, TextDrawingOptions options, Rectangle rect)
|
2016-08-25 07:18:54 +12:00
|
|
|
|
{
|
2016-11-30 07:48:19 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(text) && rect.Width > 10 && rect.Height > 10)
|
2016-05-21 09:09:31 +12:00
|
|
|
|
{
|
2016-11-30 07:48:19 +13:00
|
|
|
|
using (Font font = new Font(options.Font, options.Size, options.Style))
|
|
|
|
|
using (Brush textBrush = new SolidBrush(textColor))
|
|
|
|
|
using (StringFormat sf = new StringFormat { Alignment = options.AlignmentHorizontal, LineAlignment = options.AlignmentVertical })
|
2016-05-21 09:09:31 +12:00
|
|
|
|
{
|
2016-05-23 07:11:34 +12:00
|
|
|
|
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
2016-11-30 07:48:19 +13:00
|
|
|
|
g.DrawString(text, font, textBrush, rect, 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-08-24 10:04:48 +12:00
|
|
|
|
public override void OnCreating()
|
2016-05-22 00:26:49 +12:00
|
|
|
|
{
|
2017-11-16 19:36:21 +13:00
|
|
|
|
Point pos = InputManager.ClientMousePosition;
|
|
|
|
|
Rectangle = new Rectangle(pos.X, pos.Y, 1, 1);
|
2016-08-24 10:04:48 +12:00
|
|
|
|
|
2017-10-30 20:43:21 +13:00
|
|
|
|
if (ShowTextInputBox())
|
2016-08-24 10:04:48 +12:00
|
|
|
|
{
|
2017-10-30 20:43:21 +13:00
|
|
|
|
OnCreated();
|
2016-08-24 10:04:48 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-10-30 20:43:21 +13:00
|
|
|
|
Remove();
|
2016-08-24 10:04:48 +12:00
|
|
|
|
}
|
2016-05-22 00:26:49 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 03:34:02 +12:00
|
|
|
|
public override void OnCreated()
|
|
|
|
|
{
|
|
|
|
|
AutoSize(true);
|
2017-11-21 07:25:18 +13:00
|
|
|
|
base.OnCreated();
|
2016-08-25 03:34:02 +12:00
|
|
|
|
ShowNodes();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public override void OnDoubleClicked()
|
2016-05-22 00:26:49 +12:00
|
|
|
|
{
|
2016-08-24 10:04:48 +12:00
|
|
|
|
ShowTextInputBox();
|
2016-05-22 00:26:49 +12:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-30 20:43:21 +13:00
|
|
|
|
private bool ShowTextInputBox()
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
2017-10-30 20:43:21 +13:00
|
|
|
|
bool result;
|
|
|
|
|
|
2017-11-12 20:32:55 +13:00
|
|
|
|
Manager.Form.Pause();
|
2016-05-20 11:53:45 +12:00
|
|
|
|
|
2018-06-19 01:53:59 +12:00
|
|
|
|
using (TextDrawingInputBox inputBox = new TextDrawingInputBox(Text, TextOptions, SupportGradient))
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
2017-11-12 20:32:55 +13:00
|
|
|
|
result = inputBox.ShowDialog(Manager.Form) == DialogResult.OK;
|
2016-05-21 03:45:55 +12:00
|
|
|
|
Text = inputBox.InputText;
|
2016-08-03 17:35:34 +12:00
|
|
|
|
OnConfigSave();
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
2016-05-20 11:53:45 +12:00
|
|
|
|
|
2017-11-12 20:32:55 +13:00
|
|
|
|
Manager.Form.Resume();
|
2017-10-30 20:43:21 +13:00
|
|
|
|
|
|
|
|
|
return result;
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
2016-08-24 05:33:48 +12:00
|
|
|
|
|
2016-08-24 10:04:48 +12:00
|
|
|
|
public void AutoSize(bool center)
|
2016-08-24 05:33:48 +12:00
|
|
|
|
{
|
|
|
|
|
Size size;
|
|
|
|
|
|
2017-10-30 20:43:21 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(Text))
|
|
|
|
|
{
|
|
|
|
|
using (Font font = new Font(TextOptions.Font, TextOptions.Size, TextOptions.Style))
|
|
|
|
|
{
|
|
|
|
|
size = Helpers.MeasureText(Text, font).Offset(15, 20);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2016-08-24 05:33:48 +12:00
|
|
|
|
{
|
2017-10-30 20:43:21 +13:00
|
|
|
|
size = new Size(100, 60);
|
2016-08-24 05:33:48 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-24 06:02:52 +12:00
|
|
|
|
Point location;
|
|
|
|
|
|
2016-08-24 10:04:48 +12:00
|
|
|
|
if (center)
|
2016-08-24 06:02:52 +12:00
|
|
|
|
{
|
2018-05-17 01:27:11 +12:00
|
|
|
|
location = new Point(Rectangle.X - (size.Width / 2), Rectangle.Y - (size.Height / 2));
|
2016-08-24 06:02:52 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
location = Rectangle.Location;
|
|
|
|
|
}
|
2016-08-24 05:33:48 +12:00
|
|
|
|
|
2017-11-16 19:02:27 +13:00
|
|
|
|
Rectangle = new Rectangle(location, size);
|
2016-08-24 05:33:48 +12:00
|
|
|
|
}
|
2016-05-20 10:13:19 +12:00
|
|
|
|
}
|
|
|
|
|
}
|