Added UpdateShapeConfig method so shapes can update their own config

This commit is contained in:
Jaex 2016-05-20 20:01:00 +03:00
parent 428dabe972
commit 55c3087892
12 changed files with 62 additions and 89 deletions

View file

@ -222,7 +222,7 @@ protected override void Draw(Graphics g)
{
using (GraphicsPath hoverDrawPath = new GraphicsPath { FillMode = FillMode.Winding })
{
ShapeManager.CreateRegionShape(ShapeManager.CurrentHoverRectangle).AddShapePath(hoverDrawPath, -1);
ShapeManager.CreateShape(ShapeManager.CurrentHoverRectangle).AddShapePath(hoverDrawPath, -1);
g.DrawPath(borderPen, hoverDrawPath);
g.DrawPath(borderDotPen, hoverDrawPath);
@ -253,7 +253,7 @@ protected override void Draw(Graphics g)
// Add hover area to list so rectangle info can be shown
if (ShapeManager.IsCurrentShapeTypeRegion && ShapeManager.IsCurrentHoverAreaValid && areas.All(area => area.Rectangle != ShapeManager.CurrentHoverRectangle))
{
BaseShape shape = ShapeManager.CreateRegionShape(ShapeManager.CurrentHoverRectangle);
BaseShape shape = ShapeManager.CreateShape(ShapeManager.CurrentHoverRectangle);
areas.Add(shape);
}

View file

@ -875,7 +875,7 @@ private void RegionSelection(Point location)
rect = new Rectangle(location, new Size(1, 1));
}
AddRegionShape(rect);
AddShape(rect);
CurrentShape.StartPosition = PositionOnClick;
}
@ -917,7 +917,7 @@ private void EndRegionSelection()
if (!CurrentHoverRectangle.IsEmpty)
{
AddRegionShape(CurrentHoverRectangle);
AddShape(CurrentHoverRectangle);
if (Config.QuickCrop && IsCurrentShapeTypeRegion)
{
@ -936,14 +936,14 @@ private void EndRegionSelection()
}
}
private void AddRegionShape(Rectangle rect)
private void AddShape(Rectangle rect)
{
BaseShape shape = CreateRegionShape(rect);
BaseShape shape = CreateShape(rect);
Shapes.Add(shape);
CurrentShape = shape;
}
public BaseShape CreateRegionShape(Rectangle rect)
public BaseShape CreateShape(Rectangle rect)
{
BaseShape shape;
@ -991,54 +991,14 @@ public BaseShape CreateRegionShape(Rectangle rect)
shape.Manager = this;
shape.Rectangle = rect;
UpdateShape(shape);
shape.UpdateShapeConfig();
return shape;
}
private void UpdateCurrentShape()
{
UpdateShape(CurrentShape);
}
private void UpdateShape(BaseShape shape)
{
if (shape != null)
{
if (shape is BaseDrawingShape)
{
BaseDrawingShape baseDrawingShape = (BaseDrawingShape)shape;
baseDrawingShape.BorderColor = Config.ShapeBorderColor;
baseDrawingShape.BorderSize = Config.ShapeBorderSize;
baseDrawingShape.FillColor = Config.ShapeFillColor;
}
if (shape is IRoundedRectangleShape)
{
IRoundedRectangleShape roundedRectangleShape = (IRoundedRectangleShape)shape;
roundedRectangleShape.Radius = Config.ShapeRoundedRectangleRadius;
}
else if (shape is TextDrawingShape)
{
TextDrawingShape textDrawingShape = (TextDrawingShape)shape;
textDrawingShape.Options = Config.ShapeTextOptions.Copy();
}
else if (shape is BlurEffectShape)
{
BlurEffectShape blurEffectShape = (BlurEffectShape)shape;
blurEffectShape.BlurRadius = Config.ShapeBlurRadius;
}
else if (shape is PixelateEffectShape)
{
PixelateEffectShape pixelateEffectShape = (PixelateEffectShape)shape;
pixelateEffectShape.PixelSize = Config.ShapePixelateSize;
}
else if (shape is HighlightEffectShape)
{
HighlightEffectShape highlightEffectShape = (HighlightEffectShape)shape;
highlightEffectShape.HighlightColor = Config.ShapeHighlightColor;
}
}
CurrentShape.UpdateShapeConfig();
}
public Image RenderOutputImage(Image img)

View file

@ -39,6 +39,14 @@ public abstract class BaseShape
public ShapeManager Manager { get; set; }
protected SurfaceOptions Config
{
get
{
return Manager.Config;
}
}
private Point startPosition;
public Point StartPosition
@ -87,6 +95,10 @@ public void AddShapePath(GraphicsPath gp, int sizeOffset)
AddShapePath(gp, rect);
}
public virtual void UpdateShapeConfig()
{
}
public virtual void OnShapeCreated()
{
}

View file

@ -39,6 +39,13 @@ public abstract class BaseDrawingShape : BaseShape
public Color FillColor { get; set; }
public int BorderSize { get; set; }
public override void UpdateShapeConfig()
{
BorderColor = Config.ShapeBorderColor;
BorderSize = Config.ShapeBorderSize;
FillColor = Config.ShapeFillColor;
}
public virtual void Draw(Graphics g)
{
using (Pen borderPen = new Pen(Color.Black))

View file

@ -33,12 +33,17 @@
namespace ShareX.ScreenCaptureLib
{
public class RoundedRectangleDrawingShape : BaseDrawingShape, IRoundedRectangleShape
public class RoundedRectangleDrawingShape : BaseDrawingShape
{
public override ShapeType ShapeType { get; } = ShapeType.DrawingRoundedRectangle;
public float Radius { get; set; }
public override void UpdateShapeConfig()
{
Radius = Config.ShapeRoundedRectangleRadius;
}
public override void Draw(Graphics g)
{
Brush brush = null;

View file

@ -42,14 +42,16 @@ public class TextDrawingShape : BaseDrawingShape
public string Text { get; set; }
public TextDrawingOptions Options { get; set; } = new TextDrawingOptions();
public override void UpdateShapeConfig()
{
Options = Config.ShapeTextOptions.Copy();
}
public override void Draw(Graphics g)
{
base.Draw(g);
if (!string.IsNullOrEmpty(Text))
{
DrawText(g);
}
DrawFinal(g, null);
}
public override void DrawFinal(Graphics g, Bitmap bmp)
@ -80,7 +82,7 @@ private void UpdateText()
{
inputBox.ShowDialog();
Text = inputBox.InputText;
Manager.Config.ShapeTextOptions = Options;
Config.ShapeTextOptions = Options;
}
Manager.ResumeForm();

View file

@ -40,6 +40,11 @@ public class BlurEffectShape : BaseEffectShape
public int BlurRadius { get; set; }
public override void UpdateShapeConfig()
{
BlurRadius = Config.ShapeBlurRadius;
}
public override void Draw(Graphics g)
{
if (BlurRadius > 1)

View file

@ -40,6 +40,11 @@ public class HighlightEffectShape : BaseEffectShape
public Color HighlightColor { get; set; }
public override void UpdateShapeConfig()
{
HighlightColor = Config.ShapeHighlightColor;
}
public override void Draw(Graphics g)
{
using (Brush brush = new SolidBrush(Color.FromArgb(100, HighlightColor)))

View file

@ -40,6 +40,11 @@ public class PixelateEffectShape : BaseEffectShape
public int PixelSize { get; set; }
public override void UpdateShapeConfig()
{
PixelSize = Config.ShapePixelateSize;
}
public override void Draw(Graphics g)
{
if (PixelSize > 1)

View file

@ -1,32 +0,0 @@
#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)
namespace ShareX.ScreenCaptureLib
{
public interface IRoundedRectangleShape
{
float Radius { get; set; }
}
}

View file

@ -33,12 +33,17 @@
namespace ShareX.ScreenCaptureLib
{
public class RoundedRectangleRegionShape : BaseRegionShape, IRoundedRectangleShape
public class RoundedRectangleRegionShape : BaseRegionShape
{
public override ShapeType ShapeType { get; } = ShapeType.RegionRoundedRectangle;
public float Radius { get; set; }
public override void UpdateShapeConfig()
{
Radius = Config.ShapeRoundedRectangleRadius;
}
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
{
gp.AddRoundedRectangle(rect, Radius);

View file

@ -101,7 +101,6 @@
<Compile Include="Shapes\Drawing\RectangleDrawingShape.cs" />
<Compile Include="Shapes\Drawing\RoundedRectangleDrawingShape.cs" />
<Compile Include="Shapes\Effect\BaseEffectShape.cs" />
<Compile Include="Shapes\IRoundedRectangleShape.cs" />
<Compile Include="Shapes\Region\EllipseRegionShape.cs" />
<Compile Include="Shapes\Region\RectangleRegionShape.cs" />
<Compile Include="Shapes\Region\BaseRegionShape.cs" />