ShareX/ShareX.ScreenCaptureLib/Shapes/Drawing/StepDrawingShape.cs

129 lines
4.6 KiB
C#
Raw Normal View History

2016-05-23 07:19:25 +12:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2019-01-02 20:43:52 +13:00
Copyright (c) 2007-2019 ShareX Team
2016-05-23 07:19:25 +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)
2016-11-30 08:47:53 +13:00
using ShareX.HelpersLib;
2016-05-23 07:19:25 +12:00
using System;
using System.Drawing;
using System.Drawing.Text;
namespace ShareX.ScreenCaptureLib
{
2016-11-30 08:47:53 +13:00
public class StepDrawingShape : EllipseDrawingShape
2016-05-23 07:19:25 +12:00
{
2016-05-24 03:31:22 +12:00
private const int DefaultSize = 30;
2016-05-23 07:19:25 +12:00
public override ShapeType ShapeType { get; } = ShapeType.DrawingStep;
2017-12-08 09:17:36 +13:00
public int FontSize { get; set; }
2016-05-23 07:19:25 +12:00
public int Number { get; set; }
2017-12-28 03:48:51 +13:00
public bool UseLetters { get; set; }
2016-05-23 07:19:25 +12:00
public StepDrawingShape()
{
Rectangle = new Rectangle(0, 0, DefaultSize, DefaultSize);
}
public override void ShowNodes()
{
}
2016-08-24 01:03:48 +12:00
public override void OnCreating()
{
Manager.IsMoving = true;
2017-11-07 05:01:02 +13:00
Point pos = InputManager.ClientMousePosition;
Rectangle = new Rectangle(new Point(pos.X - (Rectangle.Width / 2), pos.Y - (Rectangle.Height / 2)), Rectangle.Size);
2016-08-24 01:03:48 +12:00
}
public override void OnConfigLoad()
2016-05-24 03:31:22 +12:00
{
BorderColor = AnnotationOptions.StepBorderColor;
BorderSize = AnnotationOptions.StepBorderSize;
FillColor = AnnotationOptions.StepFillColor;
Shadow = AnnotationOptions.Shadow;
2018-01-31 06:14:28 +13:00
ShadowColor = AnnotationOptions.ShadowColor;
ShadowOffset = AnnotationOptions.ShadowOffset;
2017-12-08 09:17:36 +13:00
FontSize = AnnotationOptions.StepFontSize;
2017-12-28 03:48:51 +13:00
UseLetters = AnnotationOptions.StepUseLetters;
2016-05-24 03:31:22 +12:00
}
public override void OnConfigSave()
2016-05-24 03:31:22 +12:00
{
AnnotationOptions.StepBorderColor = BorderColor;
AnnotationOptions.StepBorderSize = BorderSize;
AnnotationOptions.StepFillColor = FillColor;
AnnotationOptions.Shadow = Shadow;
2018-01-31 06:14:28 +13:00
AnnotationOptions.ShadowColor = ShadowColor;
AnnotationOptions.ShadowOffset = ShadowOffset;
2017-12-08 09:17:36 +13:00
AnnotationOptions.StepFontSize = FontSize;
2017-12-28 03:48:51 +13:00
AnnotationOptions.StepUseLetters = UseLetters;
2016-05-24 03:31:22 +12:00
}
2016-05-23 07:19:25 +12:00
public override void OnDraw(Graphics g)
{
DrawNumber(g);
}
2016-05-23 07:19:25 +12:00
protected void DrawNumber(Graphics g)
{
2017-12-28 03:48:51 +13:00
string text = UseLetters ? Helpers.NumberToLetters(Number) : Number.ToString();
2017-12-08 09:21:55 +13:00
using (Font font = new Font(FontFamily.GenericSansSerif, FontSize, FontStyle.Bold))
2016-05-23 07:19:25 +12:00
{
2017-12-28 03:48:51 +13:00
Size textSize = g.MeasureString(text, font).ToSize();
2017-12-08 09:17:36 +13:00
int maxSize = Math.Max(textSize.Width, textSize.Height);
int padding = 3;
2016-05-23 07:19:25 +12:00
2017-12-08 09:17:36 +13:00
Point center = Rectangle.Center();
Rectangle = new Rectangle(center.X - (maxSize / 2) - padding, center.Y - (maxSize / 2) - padding, maxSize + (padding * 2), maxSize + (padding * 2));
2017-12-08 09:17:36 +13:00
DrawEllipse(g);
2016-05-23 07:19:25 +12:00
2017-12-08 09:17:36 +13:00
if (Shadow)
2016-05-23 11:53:10 +12:00
{
2017-12-28 03:48:51 +13:00
DrawNumber(g, text, font, ShadowColor, Rectangle.LocationOffset(ShadowOffset));
2016-05-23 11:53:10 +12:00
}
2017-12-28 03:48:51 +13:00
DrawNumber(g, text, font, BorderColor, Rectangle);
2017-12-08 09:17:36 +13:00
}
}
2016-05-23 11:53:10 +12:00
2017-12-28 03:48:51 +13:00
protected void DrawNumber(Graphics g, string text, Font font, Color textColor, Rectangle rect)
2017-12-08 09:17:36 +13:00
{
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
using (Brush textBrush = new SolidBrush(textColor))
{
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
rect = rect.LocationOffset(0, 1);
2017-12-28 03:48:51 +13:00
g.DrawString(text, font, textBrush, rect, sf);
2017-12-08 09:17:36 +13:00
g.TextRenderingHint = TextRenderingHint.SystemDefault;
2016-05-23 07:19:25 +12:00
}
}
public override void Resize(int x, int y, bool fromBottomRight)
{
Move(x, y);
}
2016-05-23 07:19:25 +12:00
}
}