mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-05 20:54:31 +13:00
Added UpdateShapeConfig method so shapes can update their own config
This commit is contained in:
parent
428dabe972
commit
55c3087892
12 changed files with 62 additions and 89 deletions
|
@ -222,7 +222,7 @@ protected override void Draw(Graphics g)
|
||||||
{
|
{
|
||||||
using (GraphicsPath hoverDrawPath = new GraphicsPath { FillMode = FillMode.Winding })
|
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(borderPen, hoverDrawPath);
|
||||||
g.DrawPath(borderDotPen, 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
|
// Add hover area to list so rectangle info can be shown
|
||||||
if (ShapeManager.IsCurrentShapeTypeRegion && ShapeManager.IsCurrentHoverAreaValid && areas.All(area => area.Rectangle != ShapeManager.CurrentHoverRectangle))
|
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);
|
areas.Add(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -875,7 +875,7 @@ private void RegionSelection(Point location)
|
||||||
rect = new Rectangle(location, new Size(1, 1));
|
rect = new Rectangle(location, new Size(1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
AddRegionShape(rect);
|
AddShape(rect);
|
||||||
|
|
||||||
CurrentShape.StartPosition = PositionOnClick;
|
CurrentShape.StartPosition = PositionOnClick;
|
||||||
}
|
}
|
||||||
|
@ -917,7 +917,7 @@ private void EndRegionSelection()
|
||||||
|
|
||||||
if (!CurrentHoverRectangle.IsEmpty)
|
if (!CurrentHoverRectangle.IsEmpty)
|
||||||
{
|
{
|
||||||
AddRegionShape(CurrentHoverRectangle);
|
AddShape(CurrentHoverRectangle);
|
||||||
|
|
||||||
if (Config.QuickCrop && IsCurrentShapeTypeRegion)
|
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);
|
Shapes.Add(shape);
|
||||||
CurrentShape = shape;
|
CurrentShape = shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseShape CreateRegionShape(Rectangle rect)
|
public BaseShape CreateShape(Rectangle rect)
|
||||||
{
|
{
|
||||||
BaseShape shape;
|
BaseShape shape;
|
||||||
|
|
||||||
|
@ -991,54 +991,14 @@ public BaseShape CreateRegionShape(Rectangle rect)
|
||||||
shape.Manager = this;
|
shape.Manager = this;
|
||||||
shape.Rectangle = rect;
|
shape.Rectangle = rect;
|
||||||
|
|
||||||
UpdateShape(shape);
|
shape.UpdateShapeConfig();
|
||||||
|
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateCurrentShape()
|
private void UpdateCurrentShape()
|
||||||
{
|
{
|
||||||
UpdateShape(CurrentShape);
|
CurrentShape.UpdateShapeConfig();
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image RenderOutputImage(Image img)
|
public Image RenderOutputImage(Image img)
|
||||||
|
|
|
@ -39,6 +39,14 @@ public abstract class BaseShape
|
||||||
|
|
||||||
public ShapeManager Manager { get; set; }
|
public ShapeManager Manager { get; set; }
|
||||||
|
|
||||||
|
protected SurfaceOptions Config
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Manager.Config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Point startPosition;
|
private Point startPosition;
|
||||||
|
|
||||||
public Point StartPosition
|
public Point StartPosition
|
||||||
|
@ -87,6 +95,10 @@ public void AddShapePath(GraphicsPath gp, int sizeOffset)
|
||||||
AddShapePath(gp, rect);
|
AddShapePath(gp, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void UpdateShapeConfig()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void OnShapeCreated()
|
public virtual void OnShapeCreated()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,13 @@ public abstract class BaseDrawingShape : BaseShape
|
||||||
public Color FillColor { get; set; }
|
public Color FillColor { get; set; }
|
||||||
public int BorderSize { 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)
|
public virtual void Draw(Graphics g)
|
||||||
{
|
{
|
||||||
using (Pen borderPen = new Pen(Color.Black))
|
using (Pen borderPen = new Pen(Color.Black))
|
||||||
|
|
|
@ -33,12 +33,17 @@ You should have received a copy of the GNU General Public License
|
||||||
|
|
||||||
namespace ShareX.ScreenCaptureLib
|
namespace ShareX.ScreenCaptureLib
|
||||||
{
|
{
|
||||||
public class RoundedRectangleDrawingShape : BaseDrawingShape, IRoundedRectangleShape
|
public class RoundedRectangleDrawingShape : BaseDrawingShape
|
||||||
{
|
{
|
||||||
public override ShapeType ShapeType { get; } = ShapeType.DrawingRoundedRectangle;
|
public override ShapeType ShapeType { get; } = ShapeType.DrawingRoundedRectangle;
|
||||||
|
|
||||||
public float Radius { get; set; }
|
public float Radius { get; set; }
|
||||||
|
|
||||||
|
public override void UpdateShapeConfig()
|
||||||
|
{
|
||||||
|
Radius = Config.ShapeRoundedRectangleRadius;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Draw(Graphics g)
|
public override void Draw(Graphics g)
|
||||||
{
|
{
|
||||||
Brush brush = null;
|
Brush brush = null;
|
||||||
|
|
|
@ -42,14 +42,16 @@ public class TextDrawingShape : BaseDrawingShape
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
public TextDrawingOptions Options { get; set; } = new TextDrawingOptions();
|
public TextDrawingOptions Options { get; set; } = new TextDrawingOptions();
|
||||||
|
|
||||||
|
public override void UpdateShapeConfig()
|
||||||
|
{
|
||||||
|
Options = Config.ShapeTextOptions.Copy();
|
||||||
|
}
|
||||||
|
|
||||||
public override void Draw(Graphics g)
|
public override void Draw(Graphics g)
|
||||||
{
|
{
|
||||||
base.Draw(g);
|
base.Draw(g);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Text))
|
DrawFinal(g, null);
|
||||||
{
|
|
||||||
DrawText(g);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawFinal(Graphics g, Bitmap bmp)
|
public override void DrawFinal(Graphics g, Bitmap bmp)
|
||||||
|
@ -80,7 +82,7 @@ private void UpdateText()
|
||||||
{
|
{
|
||||||
inputBox.ShowDialog();
|
inputBox.ShowDialog();
|
||||||
Text = inputBox.InputText;
|
Text = inputBox.InputText;
|
||||||
Manager.Config.ShapeTextOptions = Options;
|
Config.ShapeTextOptions = Options;
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager.ResumeForm();
|
Manager.ResumeForm();
|
||||||
|
|
|
@ -40,6 +40,11 @@ public class BlurEffectShape : BaseEffectShape
|
||||||
|
|
||||||
public int BlurRadius { get; set; }
|
public int BlurRadius { get; set; }
|
||||||
|
|
||||||
|
public override void UpdateShapeConfig()
|
||||||
|
{
|
||||||
|
BlurRadius = Config.ShapeBlurRadius;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Draw(Graphics g)
|
public override void Draw(Graphics g)
|
||||||
{
|
{
|
||||||
if (BlurRadius > 1)
|
if (BlurRadius > 1)
|
||||||
|
|
|
@ -40,6 +40,11 @@ public class HighlightEffectShape : BaseEffectShape
|
||||||
|
|
||||||
public Color HighlightColor { get; set; }
|
public Color HighlightColor { get; set; }
|
||||||
|
|
||||||
|
public override void UpdateShapeConfig()
|
||||||
|
{
|
||||||
|
HighlightColor = Config.ShapeHighlightColor;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Draw(Graphics g)
|
public override void Draw(Graphics g)
|
||||||
{
|
{
|
||||||
using (Brush brush = new SolidBrush(Color.FromArgb(100, HighlightColor)))
|
using (Brush brush = new SolidBrush(Color.FromArgb(100, HighlightColor)))
|
||||||
|
|
|
@ -40,6 +40,11 @@ public class PixelateEffectShape : BaseEffectShape
|
||||||
|
|
||||||
public int PixelSize { get; set; }
|
public int PixelSize { get; set; }
|
||||||
|
|
||||||
|
public override void UpdateShapeConfig()
|
||||||
|
{
|
||||||
|
PixelSize = Config.ShapePixelateSize;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Draw(Graphics g)
|
public override void Draw(Graphics g)
|
||||||
{
|
{
|
||||||
if (PixelSize > 1)
|
if (PixelSize > 1)
|
||||||
|
|
|
@ -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; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -33,12 +33,17 @@ You should have received a copy of the GNU General Public License
|
||||||
|
|
||||||
namespace ShareX.ScreenCaptureLib
|
namespace ShareX.ScreenCaptureLib
|
||||||
{
|
{
|
||||||
public class RoundedRectangleRegionShape : BaseRegionShape, IRoundedRectangleShape
|
public class RoundedRectangleRegionShape : BaseRegionShape
|
||||||
{
|
{
|
||||||
public override ShapeType ShapeType { get; } = ShapeType.RegionRoundedRectangle;
|
public override ShapeType ShapeType { get; } = ShapeType.RegionRoundedRectangle;
|
||||||
|
|
||||||
public float Radius { get; set; }
|
public float Radius { get; set; }
|
||||||
|
|
||||||
|
public override void UpdateShapeConfig()
|
||||||
|
{
|
||||||
|
Radius = Config.ShapeRoundedRectangleRadius;
|
||||||
|
}
|
||||||
|
|
||||||
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
|
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
|
||||||
{
|
{
|
||||||
gp.AddRoundedRectangle(rect, Radius);
|
gp.AddRoundedRectangle(rect, Radius);
|
||||||
|
|
|
@ -101,7 +101,6 @@
|
||||||
<Compile Include="Shapes\Drawing\RectangleDrawingShape.cs" />
|
<Compile Include="Shapes\Drawing\RectangleDrawingShape.cs" />
|
||||||
<Compile Include="Shapes\Drawing\RoundedRectangleDrawingShape.cs" />
|
<Compile Include="Shapes\Drawing\RoundedRectangleDrawingShape.cs" />
|
||||||
<Compile Include="Shapes\Effect\BaseEffectShape.cs" />
|
<Compile Include="Shapes\Effect\BaseEffectShape.cs" />
|
||||||
<Compile Include="Shapes\IRoundedRectangleShape.cs" />
|
|
||||||
<Compile Include="Shapes\Region\EllipseRegionShape.cs" />
|
<Compile Include="Shapes\Region\EllipseRegionShape.cs" />
|
||||||
<Compile Include="Shapes\Region\RectangleRegionShape.cs" />
|
<Compile Include="Shapes\Region\RectangleRegionShape.cs" />
|
||||||
<Compile Include="Shapes\Region\BaseRegionShape.cs" />
|
<Compile Include="Shapes\Region\BaseRegionShape.cs" />
|
||||||
|
|
Loading…
Reference in a new issue