From 9e35ee959102565a4f5e5b505b0bd23d7904cd15 Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 20 May 2016 20:34:45 +0300 Subject: [PATCH] Created AnnotationOptions class --- ShareX.ScreenCaptureLib/AnnotationOptions.cs | 45 ++++++++++++++++ .../RegionHelpers/ShapeManager.cs | 51 +++++++++++-------- ShareX.ScreenCaptureLib/Shapes/BaseShape.cs | 4 +- .../Shapes/Drawing/BaseDrawingShape.cs | 6 +-- .../Drawing/RoundedRectangleDrawingShape.cs | 2 +- .../Shapes/Drawing/TextDrawingShape.cs | 4 +- .../Shapes/Effect/BlurEffectShape.cs | 2 +- .../Shapes/Effect/HighlightEffectShape.cs | 2 +- .../Shapes/Effect/PixelateEffectShape.cs | 2 +- .../Region/RoundedRectangleRegionShape.cs | 2 +- .../ShareX.ScreenCaptureLib.csproj | 1 + ShareX.ScreenCaptureLib/SurfaceOptions.cs | 10 +--- 12 files changed, 88 insertions(+), 43 deletions(-) create mode 100644 ShareX.ScreenCaptureLib/AnnotationOptions.cs diff --git a/ShareX.ScreenCaptureLib/AnnotationOptions.cs b/ShareX.ScreenCaptureLib/AnnotationOptions.cs new file mode 100644 index 000000000..7e92488c0 --- /dev/null +++ b/ShareX.ScreenCaptureLib/AnnotationOptions.cs @@ -0,0 +1,45 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2016 ShareX Team + + 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 . +*/ + +#endregion License Information (GPL v3) + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; + +namespace ShareX.ScreenCaptureLib +{ + public class AnnotationOptions + { + public Color BorderColor { get; set; } = Color.Red; + public int BorderSize { get; set; } = 2; + public Color FillColor { get; set; } = Color.FromArgb(0, 0, 0, 0); + public int RoundedRectangleRadius { get; set; } = 15; + public TextDrawingOptions TextOptions { get; set; } = new TextDrawingOptions(); + public int BlurRadius { get; set; } = 15; + public int PixelateSize { get; set; } = 7; + public Color HighlightColor { get; set; } = Color.Yellow; + } +} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs index c016144fc..ccfaa56f5 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs @@ -63,7 +63,6 @@ public ShapeType CurrentShapeType private set { currentShapeType = value; - Config.CurrentShapeType = currentShapeType; DeselectShape(); OnCurrentShapeTypeChanged(currentShapeType); } @@ -165,6 +164,14 @@ public bool IsResizing public SurfaceOptions Config { get; private set; } + public AnnotationOptions AnnotationOptions + { + get + { + return Config.AnnotationOptions; + } + } + public event Action CurrentShapeChanged; public event Action CurrentShapeTypeChanged; @@ -191,7 +198,7 @@ public ShapeManager(RectangleRegionForm form) } CurrentShape = null; - CurrentShapeType = ShapeType.RegionRectangle; //config.CurrentShapeType; + CurrentShapeType = ShapeType.RegionRectangle; } private void CreateContextMenu() @@ -289,30 +296,30 @@ private void CreateContextMenu() { PauseForm(); - using (ColorPickerForm dialogColor = new ColorPickerForm(Config.ShapeBorderColor)) + using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.BorderColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { - Config.ShapeBorderColor = dialogColor.NewColor; + AnnotationOptions.BorderColor = dialogColor.NewColor; if (tsmiBorderColor.Image != null) tsmiBorderColor.Image.Dispose(); - tsmiBorderColor.Image = ImageHelpers.CreateColorPickerIcon(Config.ShapeBorderColor, new Rectangle(0, 0, 16, 16)); + tsmiBorderColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.BorderColor, new Rectangle(0, 0, 16, 16)); UpdateCurrentShape(); } } ResumeForm(); }; - tsmiBorderColor.Image = ImageHelpers.CreateColorPickerIcon(Config.ShapeBorderColor, new Rectangle(0, 0, 16, 16)); + tsmiBorderColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.BorderColor, new Rectangle(0, 0, 16, 16)); cmsContextMenu.Items.Add(tsmiBorderColor); ToolStripLabeledNumericUpDown tslnudBorderSize = new ToolStripLabeledNumericUpDown(); tslnudBorderSize.LabeledNumericUpDownControl.Text = "Border size:"; tslnudBorderSize.LabeledNumericUpDownControl.Minimum = 0; tslnudBorderSize.LabeledNumericUpDownControl.Maximum = 20; - tslnudBorderSize.LabeledNumericUpDownControl.Value = Config.ShapeBorderSize; + tslnudBorderSize.LabeledNumericUpDownControl.Value = AnnotationOptions.BorderSize; tslnudBorderSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) => { - Config.ShapeBorderSize = (int)tslnudBorderSize.LabeledNumericUpDownControl.Value; + AnnotationOptions.BorderSize = (int)tslnudBorderSize.LabeledNumericUpDownControl.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudBorderSize); @@ -322,20 +329,20 @@ private void CreateContextMenu() { PauseForm(); - using (ColorPickerForm dialogColor = new ColorPickerForm(Config.ShapeFillColor)) + using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.FillColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { - Config.ShapeFillColor = dialogColor.NewColor; + AnnotationOptions.FillColor = dialogColor.NewColor; if (tsmiFillColor.Image != null) tsmiFillColor.Image.Dispose(); - tsmiFillColor.Image = ImageHelpers.CreateColorPickerIcon(Config.ShapeFillColor, new Rectangle(0, 0, 16, 16)); + tsmiFillColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.FillColor, new Rectangle(0, 0, 16, 16)); UpdateCurrentShape(); } } ResumeForm(); }; - tsmiFillColor.Image = ImageHelpers.CreateColorPickerIcon(Config.ShapeFillColor, new Rectangle(0, 0, 16, 16)); + tsmiFillColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.FillColor, new Rectangle(0, 0, 16, 16)); cmsContextMenu.Items.Add(tsmiFillColor); ToolStripLabeledNumericUpDown tslnudRoundedRectangleRadius = new ToolStripLabeledNumericUpDown(); @@ -343,10 +350,10 @@ private void CreateContextMenu() tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Minimum = 0; tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Maximum = 150; tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Increment = 3; - tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value = Config.ShapeRoundedRectangleRadius; + tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value = AnnotationOptions.RoundedRectangleRadius; tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) => { - Config.ShapeRoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value; + AnnotationOptions.RoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudRoundedRectangleRadius); @@ -355,10 +362,10 @@ private void CreateContextMenu() tslnudBlurRadius.LabeledNumericUpDownControl.Text = "Blur radius:"; tslnudBlurRadius.LabeledNumericUpDownControl.Minimum = 2; tslnudBlurRadius.LabeledNumericUpDownControl.Maximum = 100; - tslnudBlurRadius.LabeledNumericUpDownControl.Value = Config.ShapeBlurRadius; + tslnudBlurRadius.LabeledNumericUpDownControl.Value = AnnotationOptions.BlurRadius; tslnudBlurRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) => { - Config.ShapeBlurRadius = (int)tslnudBlurRadius.LabeledNumericUpDownControl.Value; + AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.LabeledNumericUpDownControl.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudBlurRadius); @@ -367,10 +374,10 @@ private void CreateContextMenu() tslnudPixelateSize.LabeledNumericUpDownControl.Text = "Pixel size:"; tslnudPixelateSize.LabeledNumericUpDownControl.Minimum = 2; tslnudPixelateSize.LabeledNumericUpDownControl.Maximum = 100; - tslnudPixelateSize.LabeledNumericUpDownControl.Value = Config.ShapeRoundedRectangleRadius; + tslnudPixelateSize.LabeledNumericUpDownControl.Value = AnnotationOptions.RoundedRectangleRadius; tslnudPixelateSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) => { - Config.ShapePixelateSize = (int)tslnudPixelateSize.LabeledNumericUpDownControl.Value; + AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.LabeledNumericUpDownControl.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudPixelateSize); @@ -380,20 +387,20 @@ private void CreateContextMenu() { PauseForm(); - using (ColorPickerForm dialogColor = new ColorPickerForm(Config.ShapeHighlightColor)) + using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { - Config.ShapeHighlightColor = dialogColor.NewColor; + AnnotationOptions.HighlightColor = dialogColor.NewColor; if (tsmiHighlightColor.Image != null) tsmiHighlightColor.Image.Dispose(); - tsmiHighlightColor.Image = ImageHelpers.CreateColorPickerIcon(Config.ShapeHighlightColor, new Rectangle(0, 0, 16, 16)); + tsmiHighlightColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.HighlightColor, new Rectangle(0, 0, 16, 16)); UpdateCurrentShape(); } } ResumeForm(); }; - tsmiHighlightColor.Image = ImageHelpers.CreateColorPickerIcon(Config.ShapeHighlightColor, new Rectangle(0, 0, 16, 16)); + tsmiHighlightColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.HighlightColor, new Rectangle(0, 0, 16, 16)); cmsContextMenu.Items.Add(tsmiHighlightColor); cmsContextMenu.Items.Add(new ToolStripSeparator()); diff --git a/ShareX.ScreenCaptureLib/Shapes/BaseShape.cs b/ShareX.ScreenCaptureLib/Shapes/BaseShape.cs index b46f4ebd8..4bd628c0f 100644 --- a/ShareX.ScreenCaptureLib/Shapes/BaseShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/BaseShape.cs @@ -39,11 +39,11 @@ public abstract class BaseShape public ShapeManager Manager { get; set; } - protected SurfaceOptions Config + protected AnnotationOptions AnnotationOptions { get { - return Manager.Config; + return Manager.Config.AnnotationOptions; } } diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs index 9f4d53aee..018f17b3b 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs @@ -41,9 +41,9 @@ public abstract class BaseDrawingShape : BaseShape public override void UpdateShapeConfig() { - BorderColor = Config.ShapeBorderColor; - BorderSize = Config.ShapeBorderSize; - FillColor = Config.ShapeFillColor; + BorderColor = AnnotationOptions.BorderColor; + BorderSize = AnnotationOptions.BorderSize; + FillColor = AnnotationOptions.FillColor; } public virtual void Draw(Graphics g) diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/RoundedRectangleDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/RoundedRectangleDrawingShape.cs index 0d2cd1056..990ef94b8 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/RoundedRectangleDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/RoundedRectangleDrawingShape.cs @@ -41,7 +41,7 @@ public class RoundedRectangleDrawingShape : BaseDrawingShape public override void UpdateShapeConfig() { - Radius = Config.ShapeRoundedRectangleRadius; + Radius = AnnotationOptions.RoundedRectangleRadius; } public override void Draw(Graphics g) diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/TextDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/TextDrawingShape.cs index 2e86ba92f..ba6bd87ab 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/TextDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/TextDrawingShape.cs @@ -44,7 +44,7 @@ public class TextDrawingShape : BaseDrawingShape public override void UpdateShapeConfig() { - Options = Config.ShapeTextOptions.Copy(); + Options = AnnotationOptions.TextOptions.Copy(); } public override void Draw(Graphics g) @@ -82,7 +82,7 @@ private void UpdateText() { inputBox.ShowDialog(); Text = inputBox.InputText; - Config.ShapeTextOptions = Options; + AnnotationOptions.TextOptions = Options; } Manager.ResumeForm(); diff --git a/ShareX.ScreenCaptureLib/Shapes/Effect/BlurEffectShape.cs b/ShareX.ScreenCaptureLib/Shapes/Effect/BlurEffectShape.cs index ed5a7bb12..899a1b71f 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Effect/BlurEffectShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Effect/BlurEffectShape.cs @@ -42,7 +42,7 @@ public class BlurEffectShape : BaseEffectShape public override void UpdateShapeConfig() { - BlurRadius = Config.ShapeBlurRadius; + BlurRadius = AnnotationOptions.BlurRadius; } public override void Draw(Graphics g) diff --git a/ShareX.ScreenCaptureLib/Shapes/Effect/HighlightEffectShape.cs b/ShareX.ScreenCaptureLib/Shapes/Effect/HighlightEffectShape.cs index bbda4d95d..9b8062e8b 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Effect/HighlightEffectShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Effect/HighlightEffectShape.cs @@ -42,7 +42,7 @@ public class HighlightEffectShape : BaseEffectShape public override void UpdateShapeConfig() { - HighlightColor = Config.ShapeHighlightColor; + HighlightColor = AnnotationOptions.HighlightColor; } public override void Draw(Graphics g) diff --git a/ShareX.ScreenCaptureLib/Shapes/Effect/PixelateEffectShape.cs b/ShareX.ScreenCaptureLib/Shapes/Effect/PixelateEffectShape.cs index f7952ed63..fb1cc3176 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Effect/PixelateEffectShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Effect/PixelateEffectShape.cs @@ -42,7 +42,7 @@ public class PixelateEffectShape : BaseEffectShape public override void UpdateShapeConfig() { - PixelSize = Config.ShapePixelateSize; + PixelSize = AnnotationOptions.PixelateSize; } public override void Draw(Graphics g) diff --git a/ShareX.ScreenCaptureLib/Shapes/Region/RoundedRectangleRegionShape.cs b/ShareX.ScreenCaptureLib/Shapes/Region/RoundedRectangleRegionShape.cs index 064ca606a..e98fe24d2 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Region/RoundedRectangleRegionShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Region/RoundedRectangleRegionShape.cs @@ -41,7 +41,7 @@ public class RoundedRectangleRegionShape : BaseRegionShape public override void UpdateShapeConfig() { - Radius = Config.ShapeRoundedRectangleRadius; + Radius = AnnotationOptions.RoundedRectangleRadius; } public override void AddShapePath(GraphicsPath gp, Rectangle rect) diff --git a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj index f8a6f9e1a..aa7bbf706 100644 --- a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj +++ b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj @@ -59,6 +59,7 @@ + Form diff --git a/ShareX.ScreenCaptureLib/SurfaceOptions.cs b/ShareX.ScreenCaptureLib/SurfaceOptions.cs index dab619071..6f7d7ba45 100644 --- a/ShareX.ScreenCaptureLib/SurfaceOptions.cs +++ b/ShareX.ScreenCaptureLib/SurfaceOptions.cs @@ -100,15 +100,7 @@ public class SurfaceOptions public bool ShowMenuTip = true; - public ShapeType CurrentShapeType = ShapeType.RegionRectangle; - public Color ShapeBorderColor = Color.Red; - public int ShapeBorderSize = 2; - public Color ShapeFillColor = Color.FromArgb(0, 0, 0, 0); - public int ShapeRoundedRectangleRadius = 15; - public TextDrawingOptions ShapeTextOptions = new TextDrawingOptions(); - public int ShapeBlurRadius = 15; - public int ShapePixelateSize = 7; - public Color ShapeHighlightColor = Color.Yellow; + public AnnotationOptions AnnotationOptions = new AnnotationOptions(); public SurfaceOptions() {