mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Added corner radius setting to rectangle and text drawing, dynamic pixel offset mode depending on border size to fix anti aliasing issues
This commit is contained in:
parent
9726a35f4c
commit
c483491611
5 changed files with 106 additions and 21 deletions
|
@ -144,5 +144,10 @@ public static string ToBase(this int value, int radix, string digits)
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool IsEvenNumber(this int num)
|
||||
{
|
||||
return num % 2 == 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,6 +34,9 @@ public class AnnotationOptions
|
|||
public int BorderSize { get; set; } = 2;
|
||||
public Color FillColor { get; set; } = Color.FromArgb(0, 0, 0, 0);
|
||||
|
||||
// Rectangle
|
||||
public int RectangleCornerRadius { get; set; } = 0;
|
||||
|
||||
// Rounded rectangle region, rounded rectangle drawing
|
||||
public int RoundedRectangleRadius { get; set; } = 15;
|
||||
|
||||
|
@ -42,6 +45,7 @@ public class AnnotationOptions
|
|||
public Color TextBorderColor { get; set; } = Color.White;
|
||||
public int TextBorderSize { get; set; } = 0;
|
||||
public Color TextFillColor { get; set; } = Color.FromArgb(150, Color.Black);
|
||||
public int TextCornerRadius { get; set; } = 0;
|
||||
|
||||
// Step drawing
|
||||
public Color StepBorderColor { get; set; } = Color.White;
|
||||
|
|
|
@ -33,24 +33,56 @@ public class RectangleDrawingShape : BaseDrawingShape
|
|||
{
|
||||
public override ShapeType ShapeType { get; } = ShapeType.DrawingRectangle;
|
||||
|
||||
public float CornerRadius { get; set; }
|
||||
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
base.OnConfigLoad();
|
||||
CornerRadius = AnnotationOptions.RectangleCornerRadius;
|
||||
}
|
||||
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
base.OnConfigSave();
|
||||
AnnotationOptions.RectangleCornerRadius = (int)CornerRadius;
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
{
|
||||
if (FillColor.A > 0)
|
||||
Brush brush = null;
|
||||
Pen pen = null;
|
||||
|
||||
try
|
||||
{
|
||||
using (Brush brush = new SolidBrush(FillColor))
|
||||
if (FillColor.A > 0)
|
||||
{
|
||||
g.FillRectangle(brush, Rectangle);
|
||||
brush = new SolidBrush(FillColor);
|
||||
}
|
||||
|
||||
if (BorderSize > 0 && BorderColor.A > 0)
|
||||
{
|
||||
pen = new Pen(BorderColor, BorderSize);
|
||||
}
|
||||
|
||||
if (CornerRadius > 0)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
|
||||
if (BorderSize.IsEvenNumber())
|
||||
{
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
}
|
||||
}
|
||||
|
||||
g.DrawRoundedRectangle(brush, pen, Rectangle, CornerRadius);
|
||||
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Default;
|
||||
}
|
||||
|
||||
if (BorderSize > 0 && BorderColor.A > 0)
|
||||
finally
|
||||
{
|
||||
Rectangle rect = Rectangle.Offset(BorderSize - 1);
|
||||
|
||||
using (Pen pen = new Pen(BorderColor, BorderSize) { Alignment = PenAlignment.Inset })
|
||||
{
|
||||
g.DrawRectangleProper(pen, rect);
|
||||
}
|
||||
if (brush != null) brush.Dispose();
|
||||
if (pen != null) pen.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ public override void OnConfigLoad()
|
|||
BorderColor = AnnotationOptions.TextBorderColor;
|
||||
BorderSize = AnnotationOptions.TextBorderSize;
|
||||
FillColor = AnnotationOptions.TextFillColor;
|
||||
CornerRadius = AnnotationOptions.TextCornerRadius;
|
||||
}
|
||||
|
||||
public override void OnConfigSave()
|
||||
|
@ -50,6 +51,7 @@ public override void OnConfigSave()
|
|||
AnnotationOptions.TextBorderColor = BorderColor;
|
||||
AnnotationOptions.TextBorderSize = BorderSize;
|
||||
AnnotationOptions.TextFillColor = FillColor;
|
||||
AnnotationOptions.TextCornerRadius = (int)CornerRadius;
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
|
|
|
@ -194,7 +194,7 @@ public bool NodesVisible
|
|||
private ContextMenuStrip cmsContextMenu;
|
||||
private ToolStripSeparator tssObjectOptions, tssShapeOptions;
|
||||
private ToolStripMenuItem tsmiDeleteSelected, tsmiDeleteAll, tsmiBorderColor, tsmiFillColor, tsmiHighlightColor, tsmiQuickCrop;
|
||||
private ToolStripLabeledNumericUpDown tslnudBorderSize, tslnudRoundedRectangleRadius, tslnudBlurRadius, tslnudPixelateSize;
|
||||
private ToolStripLabeledNumericUpDown tslnudBorderSize, tslnudCornerRadius, tslnudBlurRadius, tslnudPixelateSize;
|
||||
private bool isLeftPressed, isRightPressed, isUpPressed, isDownPressed;
|
||||
|
||||
public ShapeManager(RectangleRegionForm form)
|
||||
|
@ -499,16 +499,30 @@ private void CreateContextMenu()
|
|||
};
|
||||
cmsContextMenu.Items.Add(tsmiFillColor);
|
||||
|
||||
tslnudRoundedRectangleRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Corner_radius_);
|
||||
tslnudRoundedRectangleRadius.Content.Minimum = 0;
|
||||
tslnudRoundedRectangleRadius.Content.Maximum = 150;
|
||||
tslnudRoundedRectangleRadius.Content.Increment = 3;
|
||||
tslnudRoundedRectangleRadius.Content.ValueChanged = (sender, e) =>
|
||||
tslnudCornerRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Corner_radius_);
|
||||
tslnudCornerRadius.Content.Minimum = 0;
|
||||
tslnudCornerRadius.Content.Maximum = 150;
|
||||
tslnudCornerRadius.Content.Increment = 3;
|
||||
tslnudCornerRadius.Content.ValueChanged = (sender, e) =>
|
||||
{
|
||||
AnnotationOptions.RoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.Content.Value;
|
||||
ShapeType shapeType = CurrentShapeType;
|
||||
|
||||
if (shapeType == ShapeType.RegionRoundedRectangle || shapeType == ShapeType.DrawingRoundedRectangle)
|
||||
{
|
||||
AnnotationOptions.RoundedRectangleRadius = (int)tslnudCornerRadius.Content.Value;
|
||||
}
|
||||
else if (shapeType == ShapeType.DrawingRectangle)
|
||||
{
|
||||
AnnotationOptions.RectangleCornerRadius = (int)tslnudCornerRadius.Content.Value;
|
||||
}
|
||||
else if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon)
|
||||
{
|
||||
AnnotationOptions.TextCornerRadius = (int)tslnudCornerRadius.Content.Value;
|
||||
}
|
||||
|
||||
UpdateCurrentShape();
|
||||
};
|
||||
cmsContextMenu.Items.Add(tslnudRoundedRectangleRadius);
|
||||
cmsContextMenu.Items.Add(tslnudCornerRadius);
|
||||
|
||||
tslnudBlurRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Blur_radius_);
|
||||
tslnudBlurRadius.Content.Minimum = 2;
|
||||
|
@ -746,7 +760,22 @@ private void UpdateContextMenu()
|
|||
if (tsmiFillColor.Image != null) tsmiFillColor.Image.Dispose();
|
||||
tsmiFillColor.Image = ImageHelpers.CreateColorPickerIcon(fillColor, new Rectangle(0, 0, 16, 16));
|
||||
|
||||
tslnudRoundedRectangleRadius.Content.Value = AnnotationOptions.RoundedRectangleRadius;
|
||||
int cornerRadius = 0;
|
||||
|
||||
if (shapeType == ShapeType.RegionRoundedRectangle || shapeType == ShapeType.DrawingRoundedRectangle)
|
||||
{
|
||||
cornerRadius = AnnotationOptions.RoundedRectangleRadius;
|
||||
}
|
||||
else if (shapeType == ShapeType.DrawingRectangle)
|
||||
{
|
||||
cornerRadius = AnnotationOptions.RectangleCornerRadius;
|
||||
}
|
||||
else if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon)
|
||||
{
|
||||
cornerRadius = AnnotationOptions.TextCornerRadius;
|
||||
}
|
||||
|
||||
tslnudCornerRadius.Content.Value = cornerRadius;
|
||||
|
||||
tslnudBlurRadius.Content.Value = AnnotationOptions.BlurRadius;
|
||||
|
||||
|
@ -812,7 +841,20 @@ private void UpdateContextMenu()
|
|||
break;
|
||||
}
|
||||
|
||||
tslnudRoundedRectangleRadius.Visible = shapeType == ShapeType.RegionRoundedRectangle || shapeType == ShapeType.DrawingRoundedRectangle;
|
||||
switch (shapeType)
|
||||
{
|
||||
default:
|
||||
tslnudCornerRadius.Visible = false;
|
||||
break;
|
||||
case ShapeType.RegionRoundedRectangle:
|
||||
case ShapeType.DrawingRoundedRectangle:
|
||||
case ShapeType.DrawingRectangle:
|
||||
case ShapeType.DrawingText:
|
||||
case ShapeType.DrawingSpeechBalloon:
|
||||
tslnudCornerRadius.Visible = true;
|
||||
break;
|
||||
}
|
||||
|
||||
tslnudBlurRadius.Visible = shapeType == ShapeType.EffectBlur;
|
||||
tslnudPixelateSize.Visible = shapeType == ShapeType.EffectPixelate;
|
||||
tsmiHighlightColor.Visible = shapeType == ShapeType.EffectHighlight;
|
||||
|
|
Loading…
Reference in a new issue