mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-07 07:26:05 +12:00
Adding text drawing outline mode
This commit is contained in:
parent
b57227c335
commit
d6755cd1f9
|
@ -25,6 +25,7 @@
|
|||
|
||||
using ShareX.HelpersLib;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Text;
|
||||
|
||||
namespace ShareX.ScreenCaptureLib
|
||||
|
@ -35,6 +36,7 @@ public class TextDrawingShape : RectangleDrawingShape
|
|||
|
||||
public string Text { get; set; }
|
||||
public TextDrawingOptions TextOptions { get; set; }
|
||||
public bool OutlineMode { get; set; }
|
||||
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
|
@ -57,10 +59,17 @@ public override void OnConfigSave()
|
|||
}
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
{
|
||||
if (OutlineMode)
|
||||
{
|
||||
DrawTextWithOutline(g, Text, TextOptions, TextOptions.Color, BorderColor, BorderSize, Rectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawRectangle(g);
|
||||
DrawText(g);
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawText(Graphics g)
|
||||
{
|
||||
|
@ -92,6 +101,56 @@ protected void DrawText(Graphics g, string text, Color textColor, TextDrawingOpt
|
|||
}
|
||||
}
|
||||
|
||||
protected void DrawTextWithOutline(Graphics g, string text, TextDrawingOptions options, Color textColor, Color borderColor, int borderSize, Rectangle rect)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(text) && rect.Width > 10 && rect.Height > 10)
|
||||
{
|
||||
using (GraphicsPath gp = new GraphicsPath())
|
||||
{
|
||||
using (Font font = new Font(options.Font, options.Size, options.Style))
|
||||
using (StringFormat sf = new StringFormat { Alignment = options.AlignmentHorizontal, LineAlignment = options.AlignmentVertical })
|
||||
{
|
||||
gp.AddString(text, font.FontFamily, (int)font.Style, font.Size, rect, sf);
|
||||
}
|
||||
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
|
||||
if (IsBorderVisible)
|
||||
{
|
||||
if (Shadow)
|
||||
{
|
||||
using (Matrix matrix = new Matrix())
|
||||
{
|
||||
matrix.Translate(ShadowOffset.X, ShadowOffset.Y);
|
||||
gp.Transform(matrix);
|
||||
|
||||
using (Pen shadowPen = new Pen(ShadowColor, borderSize) { LineJoin = LineJoin.Round })
|
||||
{
|
||||
g.DrawPath(shadowPen, gp);
|
||||
}
|
||||
|
||||
matrix.Reset();
|
||||
matrix.Translate(-ShadowOffset.X, -ShadowOffset.Y);
|
||||
gp.Transform(matrix);
|
||||
}
|
||||
}
|
||||
|
||||
using (Pen borderPen = new Pen(borderColor, borderSize) { LineJoin = LineJoin.Round })
|
||||
{
|
||||
g.DrawPath(borderPen, gp);
|
||||
}
|
||||
}
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textColor))
|
||||
{
|
||||
g.FillPath(textBrush, gp);
|
||||
}
|
||||
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCreating()
|
||||
{
|
||||
StartPosition = EndPosition = InputManager.MousePosition0Based;
|
||||
|
|
Loading…
Reference in a new issue