From b784ebe0c7fafec0349cbaf7d4fabc83f92748bd Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Wed, 17 Aug 2022 21:46:45 +0200 Subject: [PATCH] Add GUI configuration for cut out tool --- .../Properties/Resources.Designer.cs | 18 +++++++++++ .../Properties/Resources.resx | 6 ++++ .../Shapes/AnnotationOptions.cs | 4 +++ .../Shapes/ShapeManager.cs | 4 +-- .../Shapes/ShapeManagerMenu.cs | 31 +++++++++++++++++-- 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs b/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs index 5f0ad7767..8403c6deb 100644 --- a/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs +++ b/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs @@ -284,6 +284,24 @@ internal class Resources { } } + /// + /// Looks up a localized string similar to Cut cut effect size. + /// + internal static string CutOutEffectSize { + get { + return ResourceManager.GetString("CutOutEffectSize", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cut out effect. + /// + internal static string CutOutEffectType { + get { + return ResourceManager.GetString("CutOutEffectType", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/ShareX.ScreenCaptureLib/Properties/Resources.resx b/ShareX.ScreenCaptureLib/Properties/Resources.resx index b53dc11d1..80a4af0c3 100644 --- a/ShareX.ScreenCaptureLib/Properties/Resources.resx +++ b/ShareX.ScreenCaptureLib/Properties/Resources.resx @@ -805,4 +805,10 @@ X: {4} Y: {5} CRF: @Invariant + + Cut cut effect size + + + Cut out effect + \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Shapes/AnnotationOptions.cs b/ShareX.ScreenCaptureLib/Shapes/AnnotationOptions.cs index 2a269f585..1dbbf1c09 100644 --- a/ShareX.ScreenCaptureLib/Shapes/AnnotationOptions.cs +++ b/ShareX.ScreenCaptureLib/Shapes/AnnotationOptions.cs @@ -106,5 +106,9 @@ public class AnnotationOptions // Highlight effect public Color HighlightColor { get; set; } = Color.Yellow; + + // Cut Out tool + public CutOutEffectType CutOutEffectType { get; set; } = CutOutEffectType.None; + public int CutOutEffectSize { get; set; } = 5; } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs index 114fa0c38..297c5261b 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs @@ -1929,12 +1929,12 @@ public void CutOut(RectangleF rect) if (isHorizontal && cropRect.Width > 0) { CollapseAllHorizontal(rect.X, rect.Width); - UpdateCanvas(ImageHelpers.CutOutBitmapMiddle(Form.Canvas, Orientation.Horizontal, cropRect.X, cropRect.Width, CutOutEffectType.ZigZag, 5)); + UpdateCanvas(ImageHelpers.CutOutBitmapMiddle(Form.Canvas, Orientation.Horizontal, cropRect.X, cropRect.Width, AnnotationOptions.CutOutEffectType, AnnotationOptions.CutOutEffectSize)); } else if (!isHorizontal && cropRect.Height > 0) { CollapseAllVertical(rect.Y, rect.Height); - UpdateCanvas(ImageHelpers.CutOutBitmapMiddle(Form.Canvas, Orientation.Vertical, cropRect.Y, cropRect.Height, CutOutEffectType.ZigZag, 5)); + UpdateCanvas(ImageHelpers.CutOutBitmapMiddle(Form.Canvas, Orientation.Vertical, cropRect.Y, cropRect.Height, AnnotationOptions.CutOutEffectType, AnnotationOptions.CutOutEffectSize)); } } diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs index effb600cc..eb85204df 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs @@ -51,9 +51,9 @@ internal partial class ShapeManager private ToolStripMenuItem tsmiShadow, tsmiShadowColor, tsmiUndo, tsmiDuplicate, tsmiDelete, tsmiDeleteAll, tsmiMoveTop, tsmiMoveUp, tsmiMoveDown, tsmiMoveBottom, tsmiRegionCapture, tsmiQuickCrop, tsmiShowMagnifier; private ToolStripLabeledNumericUpDown tslnudBorderSize, tslnudCornerRadius, tslnudCenterPoints, tslnudBlurRadius, tslnudPixelateSize, tslnudStepFontSize, - tslnudMagnifierPixelCount, tslnudStartingStepValue, tslnudMagnifyStrength; + tslnudMagnifierPixelCount, tslnudStartingStepValue, tslnudMagnifyStrength, tslnudCutOutEffectSize; private ToolStripLabel tslDragLeft, tslDragRight; - private ToolStripLabeledComboBox tscbBorderStyle, tscbArrowHeadDirection, tscbImageInterpolationMode, tscbCursorTypes, tscbStepType; + private ToolStripLabeledComboBox tscbBorderStyle, tscbArrowHeadDirection, tscbImageInterpolationMode, tscbCursorTypes, tscbStepType, tscbCutOutEffectType; internal void CreateToolbar() { @@ -642,6 +642,26 @@ internal void CreateToolbar() }; tsddbShapeOptions.DropDownItems.Add(tsmiShadowColor); + tscbCutOutEffectType = new ToolStripLabeledComboBox(Resources.CutOutEffectType); + tscbCutOutEffectType.Content.AddRange(Helpers.GetLocalizedEnumDescriptions()); + tscbCutOutEffectType.Content.SelectedIndexChanged += (sender, e) => + { + AnnotationOptions.CutOutEffectType = (CutOutEffectType)tscbCutOutEffectType.Content.SelectedIndex; + tscbCutOutEffectType.Invalidate(); + UpdateCurrentShape(); + }; + tsddbShapeOptions.DropDownItems.Add(tscbCutOutEffectType); + + tslnudCutOutEffectSize = new ToolStripLabeledNumericUpDown(Resources.CutOutEffectSize); + tslnudCutOutEffectSize.Content.Minimum = 3; + tslnudCutOutEffectSize.Content.Maximum = 100; + tslnudCutOutEffectSize.Content.ValueChanged = (sender, e) => + { + AnnotationOptions.CutOutEffectSize = (int)tslnudCutOutEffectSize.Content.Value; + UpdateCurrentShape(); + }; + tsddbShapeOptions.DropDownItems.Add(tslnudCutOutEffectSize); + // In dropdown menu if only last item is visible then menu opens at 0, 0 position on first open, so need to add dummy item to solve this weird bug... tsddbShapeOptions.DropDownItems.Add(new ToolStripSeparator() { Visible = false }); @@ -1456,6 +1476,10 @@ private void UpdateMenu() tscbArrowHeadDirection.Content.SelectedIndex = (int)AnnotationOptions.ArrowHeadDirection; + tscbCutOutEffectType.Content.SelectedIndex = (int)AnnotationOptions.CutOutEffectType; + + tslnudCutOutEffectSize.Content.Value = AnnotationOptions.CutOutEffectSize; + switch (shapeType) { default: @@ -1477,6 +1501,7 @@ private void UpdateMenu() case ShapeType.DrawingCursor: case ShapeType.EffectBlur: case ShapeType.EffectPixelate: + case ShapeType.ToolCutOut: tsddbShapeOptions.Visible = true; break; } @@ -1561,6 +1586,8 @@ private void UpdateMenu() tslnudBlurRadius.Visible = shapeType == ShapeType.EffectBlur; tslnudPixelateSize.Visible = shapeType == ShapeType.EffectPixelate; tsbHighlightColor.Visible = shapeType == ShapeType.EffectHighlight; + tscbCutOutEffectType.Visible = shapeType == ShapeType.ToolCutOut; + tslnudCutOutEffectSize.Visible = shapeType == ShapeType.ToolCutOut; if (tsmiRegionCapture != null) {