Created AnnotationOptions class

This commit is contained in:
Jaex 2016-05-20 20:34:45 +03:00
parent 55c3087892
commit 9e35ee9591
12 changed files with 88 additions and 43 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}
}

View file

@ -63,7 +63,6 @@ public ShapeType CurrentShapeType
private set private set
{ {
currentShapeType = value; currentShapeType = value;
Config.CurrentShapeType = currentShapeType;
DeselectShape(); DeselectShape();
OnCurrentShapeTypeChanged(currentShapeType); OnCurrentShapeTypeChanged(currentShapeType);
} }
@ -165,6 +164,14 @@ public bool IsResizing
public SurfaceOptions Config { get; private set; } public SurfaceOptions Config { get; private set; }
public AnnotationOptions AnnotationOptions
{
get
{
return Config.AnnotationOptions;
}
}
public event Action<BaseShape> CurrentShapeChanged; public event Action<BaseShape> CurrentShapeChanged;
public event Action<ShapeType> CurrentShapeTypeChanged; public event Action<ShapeType> CurrentShapeTypeChanged;
@ -191,7 +198,7 @@ public ShapeManager(RectangleRegionForm form)
} }
CurrentShape = null; CurrentShape = null;
CurrentShapeType = ShapeType.RegionRectangle; //config.CurrentShapeType; CurrentShapeType = ShapeType.RegionRectangle;
} }
private void CreateContextMenu() private void CreateContextMenu()
@ -289,30 +296,30 @@ private void CreateContextMenu()
{ {
PauseForm(); PauseForm();
using (ColorPickerForm dialogColor = new ColorPickerForm(Config.ShapeBorderColor)) using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.BorderColor))
{ {
if (dialogColor.ShowDialog() == DialogResult.OK) if (dialogColor.ShowDialog() == DialogResult.OK)
{ {
Config.ShapeBorderColor = dialogColor.NewColor; AnnotationOptions.BorderColor = dialogColor.NewColor;
if (tsmiBorderColor.Image != null) tsmiBorderColor.Image.Dispose(); 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(); UpdateCurrentShape();
} }
} }
ResumeForm(); 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); cmsContextMenu.Items.Add(tsmiBorderColor);
ToolStripLabeledNumericUpDown tslnudBorderSize = new ToolStripLabeledNumericUpDown(); ToolStripLabeledNumericUpDown tslnudBorderSize = new ToolStripLabeledNumericUpDown();
tslnudBorderSize.LabeledNumericUpDownControl.Text = "Border size:"; tslnudBorderSize.LabeledNumericUpDownControl.Text = "Border size:";
tslnudBorderSize.LabeledNumericUpDownControl.Minimum = 0; tslnudBorderSize.LabeledNumericUpDownControl.Minimum = 0;
tslnudBorderSize.LabeledNumericUpDownControl.Maximum = 20; tslnudBorderSize.LabeledNumericUpDownControl.Maximum = 20;
tslnudBorderSize.LabeledNumericUpDownControl.Value = Config.ShapeBorderSize; tslnudBorderSize.LabeledNumericUpDownControl.Value = AnnotationOptions.BorderSize;
tslnudBorderSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) => tslnudBorderSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
{ {
Config.ShapeBorderSize = (int)tslnudBorderSize.LabeledNumericUpDownControl.Value; AnnotationOptions.BorderSize = (int)tslnudBorderSize.LabeledNumericUpDownControl.Value;
UpdateCurrentShape(); UpdateCurrentShape();
}; };
cmsContextMenu.Items.Add(tslnudBorderSize); cmsContextMenu.Items.Add(tslnudBorderSize);
@ -322,20 +329,20 @@ private void CreateContextMenu()
{ {
PauseForm(); PauseForm();
using (ColorPickerForm dialogColor = new ColorPickerForm(Config.ShapeFillColor)) using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.FillColor))
{ {
if (dialogColor.ShowDialog() == DialogResult.OK) if (dialogColor.ShowDialog() == DialogResult.OK)
{ {
Config.ShapeFillColor = dialogColor.NewColor; AnnotationOptions.FillColor = dialogColor.NewColor;
if (tsmiFillColor.Image != null) tsmiFillColor.Image.Dispose(); 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(); UpdateCurrentShape();
} }
} }
ResumeForm(); 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); cmsContextMenu.Items.Add(tsmiFillColor);
ToolStripLabeledNumericUpDown tslnudRoundedRectangleRadius = new ToolStripLabeledNumericUpDown(); ToolStripLabeledNumericUpDown tslnudRoundedRectangleRadius = new ToolStripLabeledNumericUpDown();
@ -343,10 +350,10 @@ private void CreateContextMenu()
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Minimum = 0; tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Minimum = 0;
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Maximum = 150; tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Maximum = 150;
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Increment = 3; tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Increment = 3;
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value = Config.ShapeRoundedRectangleRadius; tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value = AnnotationOptions.RoundedRectangleRadius;
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) => tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
{ {
Config.ShapeRoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value; AnnotationOptions.RoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value;
UpdateCurrentShape(); UpdateCurrentShape();
}; };
cmsContextMenu.Items.Add(tslnudRoundedRectangleRadius); cmsContextMenu.Items.Add(tslnudRoundedRectangleRadius);
@ -355,10 +362,10 @@ private void CreateContextMenu()
tslnudBlurRadius.LabeledNumericUpDownControl.Text = "Blur radius:"; tslnudBlurRadius.LabeledNumericUpDownControl.Text = "Blur radius:";
tslnudBlurRadius.LabeledNumericUpDownControl.Minimum = 2; tslnudBlurRadius.LabeledNumericUpDownControl.Minimum = 2;
tslnudBlurRadius.LabeledNumericUpDownControl.Maximum = 100; tslnudBlurRadius.LabeledNumericUpDownControl.Maximum = 100;
tslnudBlurRadius.LabeledNumericUpDownControl.Value = Config.ShapeBlurRadius; tslnudBlurRadius.LabeledNumericUpDownControl.Value = AnnotationOptions.BlurRadius;
tslnudBlurRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) => tslnudBlurRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
{ {
Config.ShapeBlurRadius = (int)tslnudBlurRadius.LabeledNumericUpDownControl.Value; AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.LabeledNumericUpDownControl.Value;
UpdateCurrentShape(); UpdateCurrentShape();
}; };
cmsContextMenu.Items.Add(tslnudBlurRadius); cmsContextMenu.Items.Add(tslnudBlurRadius);
@ -367,10 +374,10 @@ private void CreateContextMenu()
tslnudPixelateSize.LabeledNumericUpDownControl.Text = "Pixel size:"; tslnudPixelateSize.LabeledNumericUpDownControl.Text = "Pixel size:";
tslnudPixelateSize.LabeledNumericUpDownControl.Minimum = 2; tslnudPixelateSize.LabeledNumericUpDownControl.Minimum = 2;
tslnudPixelateSize.LabeledNumericUpDownControl.Maximum = 100; tslnudPixelateSize.LabeledNumericUpDownControl.Maximum = 100;
tslnudPixelateSize.LabeledNumericUpDownControl.Value = Config.ShapeRoundedRectangleRadius; tslnudPixelateSize.LabeledNumericUpDownControl.Value = AnnotationOptions.RoundedRectangleRadius;
tslnudPixelateSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) => tslnudPixelateSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
{ {
Config.ShapePixelateSize = (int)tslnudPixelateSize.LabeledNumericUpDownControl.Value; AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.LabeledNumericUpDownControl.Value;
UpdateCurrentShape(); UpdateCurrentShape();
}; };
cmsContextMenu.Items.Add(tslnudPixelateSize); cmsContextMenu.Items.Add(tslnudPixelateSize);
@ -380,20 +387,20 @@ private void CreateContextMenu()
{ {
PauseForm(); PauseForm();
using (ColorPickerForm dialogColor = new ColorPickerForm(Config.ShapeHighlightColor)) using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor))
{ {
if (dialogColor.ShowDialog() == DialogResult.OK) if (dialogColor.ShowDialog() == DialogResult.OK)
{ {
Config.ShapeHighlightColor = dialogColor.NewColor; AnnotationOptions.HighlightColor = dialogColor.NewColor;
if (tsmiHighlightColor.Image != null) tsmiHighlightColor.Image.Dispose(); 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(); UpdateCurrentShape();
} }
} }
ResumeForm(); 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(tsmiHighlightColor);
cmsContextMenu.Items.Add(new ToolStripSeparator()); cmsContextMenu.Items.Add(new ToolStripSeparator());

View file

@ -39,11 +39,11 @@ public abstract class BaseShape
public ShapeManager Manager { get; set; } public ShapeManager Manager { get; set; }
protected SurfaceOptions Config protected AnnotationOptions AnnotationOptions
{ {
get get
{ {
return Manager.Config; return Manager.Config.AnnotationOptions;
} }
} }

View file

@ -41,9 +41,9 @@ public abstract class BaseDrawingShape : BaseShape
public override void UpdateShapeConfig() public override void UpdateShapeConfig()
{ {
BorderColor = Config.ShapeBorderColor; BorderColor = AnnotationOptions.BorderColor;
BorderSize = Config.ShapeBorderSize; BorderSize = AnnotationOptions.BorderSize;
FillColor = Config.ShapeFillColor; FillColor = AnnotationOptions.FillColor;
} }
public virtual void Draw(Graphics g) public virtual void Draw(Graphics g)

View file

@ -41,7 +41,7 @@ public class RoundedRectangleDrawingShape : BaseDrawingShape
public override void UpdateShapeConfig() public override void UpdateShapeConfig()
{ {
Radius = Config.ShapeRoundedRectangleRadius; Radius = AnnotationOptions.RoundedRectangleRadius;
} }
public override void Draw(Graphics g) public override void Draw(Graphics g)

View file

@ -44,7 +44,7 @@ public class TextDrawingShape : BaseDrawingShape
public override void UpdateShapeConfig() public override void UpdateShapeConfig()
{ {
Options = Config.ShapeTextOptions.Copy(); Options = AnnotationOptions.TextOptions.Copy();
} }
public override void Draw(Graphics g) public override void Draw(Graphics g)
@ -82,7 +82,7 @@ private void UpdateText()
{ {
inputBox.ShowDialog(); inputBox.ShowDialog();
Text = inputBox.InputText; Text = inputBox.InputText;
Config.ShapeTextOptions = Options; AnnotationOptions.TextOptions = Options;
} }
Manager.ResumeForm(); Manager.ResumeForm();

View file

@ -42,7 +42,7 @@ public class BlurEffectShape : BaseEffectShape
public override void UpdateShapeConfig() public override void UpdateShapeConfig()
{ {
BlurRadius = Config.ShapeBlurRadius; BlurRadius = AnnotationOptions.BlurRadius;
} }
public override void Draw(Graphics g) public override void Draw(Graphics g)

View file

@ -42,7 +42,7 @@ public class HighlightEffectShape : BaseEffectShape
public override void UpdateShapeConfig() public override void UpdateShapeConfig()
{ {
HighlightColor = Config.ShapeHighlightColor; HighlightColor = AnnotationOptions.HighlightColor;
} }
public override void Draw(Graphics g) public override void Draw(Graphics g)

View file

@ -42,7 +42,7 @@ public class PixelateEffectShape : BaseEffectShape
public override void UpdateShapeConfig() public override void UpdateShapeConfig()
{ {
PixelSize = Config.ShapePixelateSize; PixelSize = AnnotationOptions.PixelateSize;
} }
public override void Draw(Graphics g) public override void Draw(Graphics g)

View file

@ -41,7 +41,7 @@ public class RoundedRectangleRegionShape : BaseRegionShape
public override void UpdateShapeConfig() public override void UpdateShapeConfig()
{ {
Radius = Config.ShapeRoundedRectangleRadius; Radius = AnnotationOptions.RoundedRectangleRadius;
} }
public override void AddShapePath(GraphicsPath gp, Rectangle rect) public override void AddShapePath(GraphicsPath gp, Rectangle rect)

View file

@ -59,6 +59,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AnnotationOptions.cs" />
<Compile Include="Enums.cs" /> <Compile Include="Enums.cs" />
<Compile Include="Forms\RectangleRegionAnnotateForm.cs"> <Compile Include="Forms\RectangleRegionAnnotateForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>

View file

@ -100,15 +100,7 @@ public class SurfaceOptions
public bool ShowMenuTip = true; public bool ShowMenuTip = true;
public ShapeType CurrentShapeType = ShapeType.RegionRectangle; public AnnotationOptions AnnotationOptions = new AnnotationOptions();
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 SurfaceOptions() public SurfaceOptions()
{ {